blob: af4483376720ab02beeca1e912783fc23ca61aa3 [file] [log] [blame]
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001/*
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
Jorim Jaggib10e33f2015-02-04 21:57:40 +010016package com.android.server.policy;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080017
Dianne Hackborna4972e92012-03-14 10:38:05 -070018import android.app.ActivityManager;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080019import android.app.ActivityManagerNative;
Dianne Hackbornc2293022013-02-06 23:14:49 -080020import android.app.AppOpsManager;
Daniel Sandler6396c722013-04-16 20:19:09 -040021import android.app.IUiModeManager;
Dianne Hackborn661cd522011-08-22 00:26:20 -070022import android.app.ProgressDialog;
Jeff Brownde7a8ea2012-06-13 18:28:57 -070023import android.app.SearchManager;
John Spurlock97642182013-07-29 17:58:39 -040024import android.app.StatusBarManager;
Dianne Hackborn78968392010-03-04 20:47:56 -080025import android.app.UiModeManager;
Dianne Hackborn39c2d712009-09-22 11:41:31 -070026import android.content.ActivityNotFoundException;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080027import android.content.BroadcastReceiver;
Daniel Sandler0601eb72011-04-13 01:01:32 -040028import android.content.ComponentName;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080029import android.content.ContentResolver;
30import android.content.Context;
31import android.content.Intent;
Mike Lockwood1753f7f2009-08-24 14:49:07 -070032import android.content.IntentFilter;
Winson Chung9112ec32011-06-27 13:15:32 -070033import android.content.ServiceConnection;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080034import android.content.pm.ActivityInfo;
35import android.content.pm.PackageManager;
Daniel Sandler6396c722013-04-16 20:19:09 -040036import android.content.pm.ResolveInfo;
Dianne Hackborn2f0b1752011-05-31 17:59:49 -070037import android.content.res.CompatibilityInfo;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080038import android.content.res.Configuration;
39import android.content.res.Resources;
Craig Mautner8e4df6c2012-05-23 16:57:23 -070040import android.content.res.TypedArray;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080041import android.database.ContentObserver;
Dianne Hackbornc777e072010-02-12 13:07:59 -080042import android.graphics.PixelFormat;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080043import android.graphics.Rect;
John Spurlock7b414672014-07-18 13:02:39 -040044import android.media.AudioAttributes;
Michael Jurka7a348952012-02-27 13:07:58 -080045import android.media.AudioManager;
John Spurlock61560172015-02-06 19:46:04 -050046import android.media.AudioSystem;
Michael Jurka7a348952012-02-27 13:07:58 -080047import android.media.IAudioService;
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -070048import android.media.Ringtone;
49import android.media.RingtoneManager;
RoboErik8a2cfc32014-05-16 11:19:38 -070050import android.media.session.MediaSessionLegacyHelper;
Dianne Hackborn38e29a62011-09-18 14:43:08 -070051import android.os.Bundle;
Craig Mautner276a6eb2014-11-04 15:32:57 -080052import android.os.Debug;
Jeff Brown9a538ee2012-08-20 14:56:57 -070053import android.os.FactoryTest;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080054import android.os.Handler;
55import android.os.IBinder;
Jeff Brown32cbc38552011-12-01 14:01:49 -080056import android.os.Looper;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -070057import android.os.Message;
58import android.os.Messenger;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080059import android.os.PowerManager;
60import android.os.RemoteException;
61import android.os.ServiceManager;
62import android.os.SystemClock;
63import android.os.SystemProperties;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -080064import android.os.UEventObserver;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -070065import android.os.UserHandle;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080066import android.os.Vibrator;
Michael Wright3818c922014-09-02 13:59:07 -070067import android.provider.MediaStore;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080068import android.provider.Settings;
Jose Lima9546b202014-07-02 17:21:51 -070069import android.service.dreams.DreamManagerInternal;
John Spurlockc8b46ca2013-04-08 12:59:26 -040070import android.service.dreams.DreamService;
71import android.service.dreams.IDreamManager;
Michael Wrightdc63f7b2014-08-21 19:05:21 -070072import android.speech.RecognizerIntent;
Tyler Gunnef9f6f92014-09-12 22:16:17 -070073import android.telecom.TelecomManager;
Dianne Hackborn81e56d52011-05-26 00:55:58 -070074import android.util.DisplayMetrics;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080075import android.util.EventLog;
76import android.util.Log;
Jorim Jaggi24bec7c2015-02-04 12:40:14 +010077import android.util.Pair;
Jeff Browna41ca772010-08-11 14:46:32 -070078import android.util.Slog;
Jeff Brown6651a632011-11-28 12:59:11 -080079import android.util.SparseArray;
Dianne Hackbornf87d1962012-04-04 12:48:24 -070080import android.view.Display;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080081import android.view.Gravity;
82import android.view.HapticFeedbackConstants;
Dianne Hackborne0f085d2011-11-30 18:41:15 -080083import android.view.IApplicationToken;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080084import android.view.IWindowManager;
Jeff Browna41ca772010-08-11 14:46:32 -070085import android.view.InputChannel;
Jeff Brown4d396052010-10-29 21:50:21 -070086import android.view.InputDevice;
Jeff Brown4952dfd2011-11-30 19:23:22 -080087import android.view.InputEvent;
Jeff Brown32cbc38552011-12-01 14:01:49 -080088import android.view.InputEventReceiver;
Jeff Brown6b53e8d2010-11-10 16:03:06 -080089import android.view.KeyCharacterMap;
Craig Mautnerae446592012-12-06 19:05:05 -080090import android.view.KeyCharacterMap.FallbackAction;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080091import android.view.KeyEvent;
92import android.view.MotionEvent;
Jorim Jaggib10e33f2015-02-04 21:57:40 +010093import android.view.PhoneWindow;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080094import android.view.Surface;
95import android.view.View;
96import android.view.ViewConfiguration;
97import android.view.Window;
98import android.view.WindowManager;
Craig Mautnerae446592012-12-06 19:05:05 -080099import android.view.WindowManagerGlobal;
Craig Mautner8a0da012014-05-31 15:13:37 -0700100import android.view.WindowManagerInternal;
Craig Mautnerae446592012-12-06 19:05:05 -0800101import android.view.WindowManagerPolicy;
Craig Mautnerae446592012-12-06 19:05:05 -0800102import android.view.accessibility.AccessibilityEvent;
Svetoslav8e3feb12014-02-24 13:46:47 -0800103import android.view.accessibility.AccessibilityManager;
Craig Mautnerae446592012-12-06 19:05:05 -0800104import android.view.animation.Animation;
Jorim Jaggi76a16232014-08-08 17:00:47 +0200105import android.view.animation.AnimationSet;
Craig Mautnerae446592012-12-06 19:05:05 -0800106import android.view.animation.AnimationUtils;
Jorim Jaggi24bec7c2015-02-04 12:40:14 +0100107import android.view.animation.Interpolator;
108import android.view.animation.TranslateAnimation;
Craig Mautnerae446592012-12-06 19:05:05 -0800109
110import com.android.internal.R;
Craig Mautnerae446592012-12-06 19:05:05 -0800111import com.android.internal.statusbar.IStatusBarService;
Craig Mautnerae446592012-12-06 19:05:05 -0800112import com.android.internal.widget.PointerLocationView;
Craig Mautner8a0da012014-05-31 15:13:37 -0700113import com.android.server.LocalServices;
Jorim Jaggib10e33f2015-02-04 21:57:40 +0100114import com.android.server.policy.keyguard.KeyguardServiceDelegate;
115import com.android.server.policy.keyguard.KeyguardServiceDelegate.ShowListener;
Craig Mautnerae446592012-12-06 19:05:05 -0800116
117import java.io.File;
118import java.io.FileReader;
119import java.io.IOException;
120import java.io.PrintWriter;
Craig Mautner2bc789b2014-03-19 19:48:38 -0700121import java.util.HashSet;
Craig Mautner276a6eb2014-11-04 15:32:57 -0800122import java.util.List;
Craig Mautnerae446592012-12-06 19:05:05 -0800123
Dianne Hackbornc652de82013-02-15 16:32:56 -0800124import static android.view.WindowManager.LayoutParams.*;
Jeff Brownac143512012-04-05 18:57:33 -0700125import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_ABSENT;
126import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_OPEN;
127import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_CLOSED;
Michael Wright3818c922014-09-02 13:59:07 -0700128import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVER_ABSENT;
129import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_UNCOVERED;
130import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVERED;
Dianne Hackborn08743722009-12-21 12:16:51 -0800131
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800132/**
The Android Open Source Project0727d222009-03-11 12:11:58 -0700133 * WindowManagerPolicy implementation for the Android phone UI. This
134 * introduces a new method suffix, Lp, for an internal lock of the
135 * PhoneWindowManager. This is used to protect some internal state, and
John Spurlock04db1762013-05-13 12:46:41 -0400136 * can be acquired with either the Lw and Li lock held, so has the restrictions
The Android Open Source Project0727d222009-03-11 12:11:58 -0700137 * of both of those when held.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800138 */
139public class PhoneWindowManager implements WindowManagerPolicy {
140 static final String TAG = "WindowManager";
141 static final boolean DEBUG = false;
Joe Onorato43a17652011-04-06 19:22:23 -0700142 static final boolean localLOGV = false;
Jeff Brown40013652012-05-16 21:22:36 -0700143 static final boolean DEBUG_INPUT = false;
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -0700144 static final boolean DEBUG_KEYGUARD = false;
145 static final boolean DEBUG_LAYOUT = false;
Craig Mautner6fbda632012-07-03 09:26:39 -0700146 static final boolean DEBUG_STARTING_WINDOW = false;
Craig Mautner8a0da012014-05-31 15:13:37 -0700147 static final boolean DEBUG_WAKEUP = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800148 static final boolean SHOW_STARTING_ANIMATIONS = true;
149 static final boolean SHOW_PROCESSES_ON_ALT_MENU = false;
Joe Onoratod208e702010-10-08 16:22:43 -0400150
Daniel Sandler6396c722013-04-16 20:19:09 -0400151 // Whether to allow dock apps with METADATA_DOCK_HOME to temporarily take over the Home key.
152 // No longer recommended for desk docks; still useful in car docks.
153 static final boolean ENABLE_CAR_DOCK_HOME_CAPTURE = true;
154 static final boolean ENABLE_DESK_DOCK_HOME_CAPTURE = false;
155
Jeff Brown6d8fd272014-05-20 21:24:38 -0700156 static final int SHORT_PRESS_POWER_NOTHING = 0;
157 static final int SHORT_PRESS_POWER_GO_TO_SLEEP = 1;
158 static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP = 2;
159 static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME = 3;
Bryce Lee01b0c5f2015-02-05 18:24:04 -0800160 static final int SHORT_PRESS_POWER_GO_HOME = 4;
Jeff Brown6d8fd272014-05-20 21:24:38 -0700161
Joe Onoratod208e702010-10-08 16:22:43 -0400162 static final int LONG_PRESS_POWER_NOTHING = 0;
163 static final int LONG_PRESS_POWER_GLOBAL_ACTIONS = 1;
164 static final int LONG_PRESS_POWER_SHUT_OFF = 2;
Jeff Brown9a538ee2012-08-20 14:56:57 -0700165 static final int LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM = 3;
Michael Jurka3b1fc472011-06-13 10:54:40 -0700166
Jeff Brown13f00f02014-10-31 14:45:50 -0700167 static final int MULTI_PRESS_POWER_NOTHING = 0;
168 static final int MULTI_PRESS_POWER_THEATER_MODE = 1;
169 static final int MULTI_PRESS_POWER_BRIGHTNESS_BOOST = 2;
170
Michael Jurka3b1fc472011-06-13 10:54:40 -0700171 // These need to match the documentation/constant in
172 // core/res/res/values/config.xml
Joe Onorato46b0d682010-11-22 17:37:27 -0800173 static final int LONG_PRESS_HOME_NOTHING = 0;
Michael Wrightc9ebea72013-01-16 19:25:02 -0800174 static final int LONG_PRESS_HOME_RECENT_SYSTEM_UI = 1;
Jeff Browncaca8812013-05-09 13:34:33 -0700175 static final int LONG_PRESS_HOME_ASSIST = 2;
176
177 static final int DOUBLE_TAP_HOME_NOTHING = 0;
178 static final int DOUBLE_TAP_HOME_RECENT_SYSTEM_UI = 1;
Joe Onorato46b0d682010-11-22 17:37:27 -0800179
Dianne Hackborn5cb8d792009-05-21 17:34:15 -0700180 static final int APPLICATION_MEDIA_SUBLAYER = -2;
181 static final int APPLICATION_MEDIA_OVERLAY_SUBLAYER = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800182 static final int APPLICATION_PANEL_SUBLAYER = 1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800183 static final int APPLICATION_SUB_PANEL_SUBLAYER = 2;
Craig Mautner88400d32012-09-30 12:35:45 -0700184
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800185 static public final String SYSTEM_DIALOG_REASON_KEY = "reason";
186 static public final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions";
187 static public final String SYSTEM_DIALOG_REASON_RECENT_APPS = "recentapps";
Joe Onoratof275f0c2009-11-24 16:11:13 -0500188 static public final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey";
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700189 static public final String SYSTEM_DIALOG_REASON_ASSIST = "assist";
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800190
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700191 /**
192 * These are the system UI flags that, when changing, can cause the layout
193 * of the screen to change.
194 */
195 static final int SYSTEM_UI_CHANGING_LAYOUT =
John Spurlocke1f366f2013-08-05 12:22:40 -0400196 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlock7f4820a2013-10-08 12:54:35 -0400197 | View.SYSTEM_UI_FLAG_FULLSCREEN
198 | View.STATUS_BAR_TRANSLUCENT
Adrian Roosea562512014-05-05 13:33:03 +0200199 | View.NAVIGATION_BAR_TRANSLUCENT
200 | View.SYSTEM_UI_TRANSPARENT;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700201
John Spurlock7b414672014-07-18 13:02:39 -0400202 private static final AudioAttributes VIBRATION_ATTRIBUTES = new AudioAttributes.Builder()
203 .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
204 .setUsage(AudioAttributes.USAGE_ASSISTANCE_SONIFICATION)
205 .build();
206
Jim Miller5ecd8112013-01-09 18:50:26 -0800207 /**
208 * Keyguard stuff
209 */
210 private WindowState mKeyguardScrim;
Jorim Jaggi380ecb82014-03-14 17:25:20 +0100211 private boolean mKeyguardHidden;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700212 private boolean mKeyguardDrawnOnce;
Jim Miller5ecd8112013-01-09 18:50:26 -0800213
Jeff Brown6651a632011-11-28 12:59:11 -0800214 /* Table of Application Launch keys. Maps from key codes to intent categories.
215 *
216 * These are special keys that are used to launch particular kinds of applications,
217 * such as a web browser. HID defines nearly a hundred of them in the Consumer (0x0C)
218 * usage page. We don't support quite that many yet...
219 */
220 static SparseArray<String> sApplicationLaunchKeyCategories;
221 static {
222 sApplicationLaunchKeyCategories = new SparseArray<String>();
223 sApplicationLaunchKeyCategories.append(
224 KeyEvent.KEYCODE_EXPLORER, Intent.CATEGORY_APP_BROWSER);
225 sApplicationLaunchKeyCategories.append(
226 KeyEvent.KEYCODE_ENVELOPE, Intent.CATEGORY_APP_EMAIL);
227 sApplicationLaunchKeyCategories.append(
228 KeyEvent.KEYCODE_CONTACTS, Intent.CATEGORY_APP_CONTACTS);
229 sApplicationLaunchKeyCategories.append(
230 KeyEvent.KEYCODE_CALENDAR, Intent.CATEGORY_APP_CALENDAR);
231 sApplicationLaunchKeyCategories.append(
232 KeyEvent.KEYCODE_MUSIC, Intent.CATEGORY_APP_MUSIC);
233 sApplicationLaunchKeyCategories.append(
234 KeyEvent.KEYCODE_CALCULATOR, Intent.CATEGORY_APP_CALCULATOR);
235 }
236
Craig Mautnerc3daedd2014-09-13 11:17:23 -0700237 /** Amount of time (in milliseconds) to wait for windows drawn before powering on. */
238 static final int WAITING_FOR_DRAWN_TIMEOUT = 1000;
239
Dianne Hackborndf89e652011-10-06 22:35:11 -0700240 /**
241 * Lock protecting internal state. Must not call out into window
242 * manager with lock held. (This lock will be acquired in places
243 * where the window manager is calling in with its own lock held.)
244 */
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800245 private final Object mLock = new Object();
Dianne Hackborndf89e652011-10-06 22:35:11 -0700246
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800247 Context mContext;
248 IWindowManager mWindowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700249 WindowManagerFuncs mWindowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -0700250 WindowManagerInternal mWindowManagerInternal;
Jeff Brown96307042012-07-27 15:51:34 -0700251 PowerManager mPowerManager;
Jose Lima9546b202014-07-02 17:21:51 -0700252 DreamManagerInternal mDreamManagerInternal;
Joe Onorato93056472010-09-10 10:30:46 -0400253 IStatusBarService mStatusBarService;
Jeff Browncaca8812013-05-09 13:34:33 -0700254 boolean mPreloadedRecentApps;
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700255 final Object mServiceAquireLock = new Object();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800256 Vibrator mVibrator; // Vibrator for giving feedback of orientation changes
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700257 SearchManager mSearchManager;
Svetoslav8e3feb12014-02-24 13:46:47 -0800258 AccessibilityManager mAccessibilityManager;
Filip Gruszczynskicfb31852015-02-25 21:47:12 +0000259 BurnInProtectionHelper mBurnInProtectionHelper;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800260
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700261 // Vibrator pattern for haptic feedback of a long press.
262 long[] mLongPressVibePattern;
Craig Mautner88400d32012-09-30 12:35:45 -0700263
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700264 // Vibrator pattern for haptic feedback of virtual key press.
265 long[] mVirtualKeyVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700266
Amith Yamasanic33cb712010-02-10 15:21:49 -0800267 // Vibrator pattern for a short vibration.
268 long[] mKeyboardTapVibePattern;
269
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -0700270 // Vibrator pattern for a short vibration when tapping on an hour/minute tick of a Clock.
271 long[] mClockTickVibePattern;
272
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -0700273 // Vibrator pattern for a short vibration when tapping on a day/month/year date of a Calendar.
274 long[] mCalendarDateVibePattern;
275
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700276 // Vibrator pattern for haptic feedback during boot when safe mode is disabled.
277 long[] mSafeModeDisabledVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700278
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700279 // Vibrator pattern for haptic feedback during boot when safe mode is enabled.
280 long[] mSafeModeEnabledVibePattern;
Romain Guy8154cd32010-03-29 14:41:15 -0700281
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800282 /** If true, hitting shift & menu will broadcast Intent.ACTION_BUG_REPORT */
283 boolean mEnableShiftMenuBugReports = false;
Mike Lockwoodd747dc82011-09-13 16:28:22 -0400284
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800285 boolean mSafeMode;
286 WindowState mStatusBar = null;
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700287 int mStatusBarHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400288 WindowState mNavigationBar = null;
Daniel Sandler36412a72011-08-04 09:35:13 -0400289 boolean mHasNavigationBar = false;
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700290 boolean mCanHideNavigationBar = false;
Daniel Sandler4a066c52012-04-20 14:49:13 -0400291 boolean mNavigationBarCanMove = false; // can the navigation bar ever move to the side?
292 boolean mNavigationBarOnBottom = true; // is the navigation bar on the bottom *right now*?
293 int[] mNavigationBarHeightForRotation = new int[4];
294 int[] mNavigationBarWidthForRotation = new int[4];
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400295
Craig Mautnera631d492014-08-05 15:16:01 -0700296 boolean mBootMessageNeedsHiding;
Jim Miller5ecd8112013-01-09 18:50:26 -0800297 KeyguardServiceDelegate mKeyguardDelegate;
Craig Mautner13f6ea72014-06-23 14:57:02 -0700298 final Runnable mWindowManagerDrawCallback = new Runnable() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700299 @Override
Craig Mautner13f6ea72014-06-23 14:57:02 -0700300 public void run() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700301 if (DEBUG_WAKEUP) Slog.i(TAG, "All windows ready for display!");
302 mHandler.sendEmptyMessage(MSG_WINDOW_MANAGER_DRAWN_COMPLETE);
303 }
304 };
305 final ShowListener mKeyguardDelegateCallback = new ShowListener() {
306 @Override
307 public void onShown(IBinder windowToken) {
308 if (DEBUG_WAKEUP) Slog.d(TAG, "mKeyguardDelegate.ShowListener.onShown.");
309 mHandler.sendEmptyMessage(MSG_KEYGUARD_DRAWN_COMPLETE);
310 }
311 };
312
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800313 GlobalActions mGlobalActions;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800314 Handler mHandler;
satok1bc0a492012-04-25 22:47:12 +0900315 WindowState mLastInputMethodWindow = null;
316 WindowState mLastInputMethodTargetWindow = null;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800317
Jeff Brown13f00f02014-10-31 14:45:50 -0700318 // FIXME This state is shared between the input reader and handler thread.
319 // Technically it's broken and buggy but it has been like this for many years
320 // and we have not yet seen any problems. Someday we'll rewrite this logic
321 // so that only one thread is involved in handling input policy. Unfortunately
322 // it's on a critical path for power management so we can't just post the work to the
323 // handler thread. We'll need to resolve this someday by teaching the input dispatcher
324 // to hold wakelocks during dispatch and eliminating the critical path.
325 volatile boolean mPowerKeyHandled;
Bryce Leed9268e32014-11-17 17:40:59 -0800326 volatile boolean mBeganFromNonInteractive;
Jeff Brown13f00f02014-10-31 14:45:50 -0700327 volatile int mPowerKeyPressCounter;
328 volatile boolean mEndCallKeyHandled;
329
Winson Chungd42a6cf2014-06-03 16:24:04 -0700330 boolean mRecentsVisible;
Winson Chung1e8d71b2014-05-16 17:05:22 -0700331 int mRecentAppsHeldModifiers;
Jeff Browncf39bdf2012-05-18 14:41:19 -0700332 boolean mLanguageSwitchKeyPressed;
Jeff Brown68b909d2011-12-07 16:36:01 -0800333
Jeff Brown2e7760e2012-04-11 15:14:55 -0700334 int mLidState = LID_ABSENT;
Michael Wright3818c922014-09-02 13:59:07 -0700335 int mCameraLensCoverState = CAMERA_LENS_COVER_ABSENT;
Jeff Browndaa37532012-05-01 15:54:03 -0700336 boolean mHaveBuiltInKeyboard;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800337
Dianne Hackbornc777e072010-02-12 13:07:59 -0800338 boolean mSystemReady;
Dianne Hackbornba24e4d2011-09-01 11:17:06 -0700339 boolean mSystemBooted;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800340 boolean mHdmiPlugged;
Jeff Brown4f5fa282014-06-12 19:19:15 -0700341 IUiModeManager mUiModeManager;
Daniel Sandler6396c722013-04-16 20:19:09 -0400342 int mUiMode;
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700343 int mDockMode = Intent.EXTRA_DOCK_STATE_UNDOCKED;
Mike Lockwood1753f7f2009-08-24 14:49:07 -0700344 int mLidOpenRotation;
Mike Lockwood2d1efbd2009-09-16 12:15:53 -0400345 int mCarDockRotation;
346 int mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -0700347 int mUndockedHdmiRotation;
348 int mDemoHdmiRotation;
349 boolean mDemoHdmiRotationLock;
Chong Zhangae6119ff2014-11-11 18:54:39 -0800350 int mDemoRotation;
351 boolean mDemoRotationLock;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400352
Jeff Browna20dda42014-05-27 20:57:24 -0700353 boolean mWakeGestureEnabledSetting;
354 MyWakeGestureListener mWakeGestureListener;
355
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700356 // Default display does not rotate, apps that require non-default orientation will have to
357 // have the orientation emulated.
358 private boolean mForceDefaultOrientation = false;
359
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400360 int mUserRotationMode = WindowManagerPolicy.USER_ROTATION_FREE;
361 int mUserRotation = Surface.ROTATION_0;
Jeff Brown207673cd2012-06-05 17:47:11 -0700362 boolean mAccelerometerDefault;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400363
Jeff Brownbcdfc622014-03-06 19:13:04 -0800364 boolean mSupportAutoRotation;
Jeff Brownd3187e32011-09-21 19:26:44 -0700365 int mAllowAllRotations = -1;
Mike Lockwoode9867d22009-09-20 01:59:02 -0400366 boolean mCarDockEnablesAccelerometer;
367 boolean mDeskDockEnablesAccelerometer;
Dianne Hackborn2862fff2009-09-15 22:56:29 -0700368 int mLidKeyboardAccessibility;
369 int mLidNavigationAccessibility;
Jeff Brownc458ce92012-04-30 14:58:40 -0700370 boolean mLidControlsSleep;
Jeff Brown13f00f02014-10-31 14:45:50 -0700371 int mShortPressOnPowerBehavior;
372 int mLongPressOnPowerBehavior;
373 int mDoublePressOnPowerBehavior;
374 int mTriplePressOnPowerBehavior;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700375 boolean mAwake;
376 boolean mScreenOnEarly;
377 boolean mScreenOnFully;
378 ScreenOnListener mScreenOnListener;
379 boolean mKeyguardDrawComplete;
380 boolean mWindowManagerDrawComplete;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800381 boolean mOrientationSensorEnabled = false;
382 int mCurrentAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800383 boolean mHasSoftInput = false;
Daniel Sandlerdd73ee42013-10-11 22:19:59 -0400384 boolean mTranslucentDecorEnabled = true;
RoboErik001c59c2015-01-26 15:53:51 -0800385 boolean mUseTvRouting;
386 boolean mUseMasterVolume;
Craig Mautner967212c2013-04-13 21:10:58 -0700387
Jeff Brown70825162012-03-28 17:27:48 -0700388 int mPointerLocationMode = 0; // guarded by mLock
Joe Onorato664644d2011-01-23 17:53:23 -0800389
390 // The last window we were told about in focusChanged.
391 WindowState mFocusedWindow;
Dianne Hackborne0f085d2011-11-30 18:41:15 -0800392 IApplicationToken mFocusedApp;
Joe Onorato664644d2011-01-23 17:53:23 -0800393
Jeff Brown70825162012-03-28 17:27:48 -0700394 PointerLocationView mPointerLocationView;
Jeff Brown32cbc38552011-12-01 14:01:49 -0800395
Dianne Hackbornc652de82013-02-15 16:32:56 -0800396 // The current size of the screen; really; extends into the overscan area of
397 // the screen and doesn't account for any system elements like the status bar.
398 int mOverscanScreenLeft, mOverscanScreenTop;
399 int mOverscanScreenWidth, mOverscanScreenHeight;
400 // The current visible size of the screen; really; (ir)regardless of whether the status
401 // bar can be hidden but not extending into the overscan area.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800402 int mUnrestrictedScreenLeft, mUnrestrictedScreenTop;
403 int mUnrestrictedScreenWidth, mUnrestrictedScreenHeight;
Dianne Hackborn313440842013-02-19 19:22:59 -0800404 // Like mOverscanScreen*, but allowed to move into the overscan region where appropriate.
405 int mRestrictedOverscanScreenLeft, mRestrictedOverscanScreenTop;
406 int mRestrictedOverscanScreenWidth, mRestrictedOverscanScreenHeight;
Dianne Hackborn82de1ae2010-10-28 11:28:39 -0700407 // The current size of the screen; these may be different than (0,0)-(dw,dh)
408 // if the status bar can't be hidden; in that case it effectively carves out
409 // that area of the display from all other windows.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800410 int mRestrictedScreenLeft, mRestrictedScreenTop;
411 int mRestrictedScreenWidth, mRestrictedScreenHeight;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700412 // During layout, the current screen borders accounting for any currently
413 // visible system UI elements.
414 int mSystemLeft, mSystemTop, mSystemRight, mSystemBottom;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700415 // For applications requesting stable content insets, these are them.
416 int mStableLeft, mStableTop, mStableRight, mStableBottom;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -0700417 // For applications requesting stable content insets but have also set the
418 // fullscreen window flag, these are the stable dimensions without the status bar.
419 int mStableFullscreenLeft, mStableFullscreenTop;
420 int mStableFullscreenRight, mStableFullscreenBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800421 // During layout, the current screen borders with all outer decoration
422 // (status bar, input method dock) accounted for.
423 int mCurLeft, mCurTop, mCurRight, mCurBottom;
424 // During layout, the frame in which content should be displayed
425 // to the user, accounting for all screen decoration except for any
426 // space they deem as available for other content. This is usually
427 // the same as mCur*, but may be larger if the screen decor has supplied
428 // content insets.
429 int mContentLeft, mContentTop, mContentRight, mContentBottom;
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700430 // During layout, the frame in which voice content should be displayed
431 // to the user, accounting for all screen decoration except for any
432 // space they deem as available for other content.
433 int mVoiceContentLeft, mVoiceContentTop, mVoiceContentRight, mVoiceContentBottom;
Dianne Hackborn8e11ef02010-11-18 19:47:42 -0800434 // During layout, the current screen borders along which input method
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800435 // windows are placed.
436 int mDockLeft, mDockTop, mDockRight, mDockBottom;
437 // During layout, the layer at which the doc window is placed.
438 int mDockLayer;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700439 // During layout, this is the layer of the status bar.
440 int mStatusBarLayer;
Dianne Hackborne26ab702011-10-16 13:21:33 -0700441 int mLastSystemUiFlags;
442 // Bits that we are in the process of clearing, so we want to prevent
443 // them from being set by applications until everything has been updated
444 // to have them clear.
445 int mResettingSystemUiFlags = 0;
446 // Bits that we are currently always keeping cleared.
447 int mForceClearedSystemUiFlags = 0;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -0800448 // What we last reported to system UI about whether the compatibility
449 // menu needs to be displayed.
450 boolean mLastFocusNeedsMenu = false;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700451
452 FakeWindow mHideNavFakeWindow = null;
453
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800454 static final Rect mTmpParentFrame = new Rect();
455 static final Rect mTmpDisplayFrame = new Rect();
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800456 static final Rect mTmpOverscanFrame = new Rect();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800457 static final Rect mTmpContentFrame = new Rect();
458 static final Rect mTmpVisibleFrame = new Rect();
John Spurlock46646232013-09-30 22:32:42 -0400459 static final Rect mTmpDecorFrame = new Rect();
Adrian Roosfa104232014-06-20 16:10:14 -0700460 static final Rect mTmpStableFrame = new Rect();
Dianne Hackborn1f903c32011-09-13 19:18:06 -0700461 static final Rect mTmpNavigationFrame = new Rect();
Craig Mautner967212c2013-04-13 21:10:58 -0700462
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800463 WindowState mTopFullscreenOpaqueWindowState;
Adrian Rooscd3884d2015-02-18 17:25:23 +0100464 WindowState mTopFullscreenOpaqueOrDimmingWindowState;
Craig Mautner2bc789b2014-03-19 19:48:38 -0700465 HashSet<IApplicationToken> mAppsToBeHidden = new HashSet<IApplicationToken>();
Jorim Jaggic13fcac2014-09-11 17:36:57 +0200466 HashSet<IApplicationToken> mAppsThatDismissKeyguard = new HashSet<IApplicationToken>();
Joe Onorato93056472010-09-10 10:30:46 -0400467 boolean mTopIsFullscreen;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800468 boolean mForceStatusBar;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -0700469 boolean mForceStatusBarFromKeyguard;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700470 boolean mHideLockScreen;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -0800471 boolean mForcingShowNavBar;
472 int mForcingShowNavBarLayer;
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700473
474 // States of keyguard dismiss.
475 private static final int DISMISS_KEYGUARD_NONE = 0; // Keyguard not being dismissed.
476 private static final int DISMISS_KEYGUARD_START = 1; // Keyguard needs to be dismissed.
477 private static final int DISMISS_KEYGUARD_CONTINUE = 2; // Keyguard has been dismissed.
478 int mDismissKeyguard = DISMISS_KEYGUARD_NONE;
479
480 /** The window that is currently dismissing the keyguard. Dismissing the keyguard must only
481 * be done once per window. */
482 private WindowState mWinDismissingKeyguard;
483
Craig Mautnerc9457fa2014-06-06 14:27:48 -0700484 /** The window that is currently showing "over" the keyguard. If there is an app window
485 * belonging to another app on top of this the keyguard shows. If there is a fullscreen
486 * app window under this, still dismiss the keyguard but don't show the app underneath. Show
487 * the wallpaper. */
488 private WindowState mWinShowWhenLocked;
489
Dianne Hackborn7ad44382012-10-18 17:46:00 -0700490 boolean mShowingLockscreen;
491 boolean mShowingDream;
492 boolean mDreamingLockscreen;
Jim Millerab954542014-10-10 18:21:49 -0700493 boolean mKeyguardSecure;
494 boolean mKeyguardSecureIncludingHidden;
495 volatile boolean mKeyguardOccluded;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800496 boolean mHomePressed;
Jeff Browncaca8812013-05-09 13:34:33 -0700497 boolean mHomeConsumed;
498 boolean mHomeDoubleTapPending;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800499 Intent mHomeIntent;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700500 Intent mCarDockIntent;
501 Intent mDeskDockIntent;
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700502 boolean mSearchKeyShortcutPending;
503 boolean mConsumeSearchKeyUp;
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700504 boolean mAssistKeyLongPressed;
Michael Wright6a62e552014-06-03 19:19:48 -0700505 boolean mPendingMetaAction;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800506
Mike Lockwood28569302010-01-28 11:54:40 -0500507 // support for activating the lock screen while the screen is on
508 boolean mAllowLockscreenWhenOn;
509 int mLockScreenTimeout;
510 boolean mLockScreenTimerActive;
511
David Brownbaf8d092010-03-08 21:52:59 -0800512 // Behavior of ENDCALL Button. (See Settings.System.END_BUTTON_BEHAVIOR.)
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800513 int mEndcallBehavior;
David Brownbaf8d092010-03-08 21:52:59 -0800514
515 // Behavior of POWER button while in-call and screen on.
516 // (See Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR.)
517 int mIncallPowerBehavior;
518
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700519 Display mDisplay;
520
Dianne Hackborn9d132642011-04-21 17:26:39 -0700521 int mLandscapeRotation = 0; // default landscape rotation
522 int mSeascapeRotation = 0; // "other" landscape rotation, 180 degrees from mLandscapeRotation
523 int mPortraitRotation = 0; // default portrait rotation
524 int mUpsideDownRotation = 0; // "other" portrait rotation
Mitsuru Oshima831d0d92009-06-16 18:27:18 -0700525
Dianne Hackbornc652de82013-02-15 16:32:56 -0800526 int mOverscanLeft = 0;
527 int mOverscanTop = 0;
528 int mOverscanRight = 0;
529 int mOverscanBottom = 0;
530
Joe Onorato46b0d682010-11-22 17:37:27 -0800531 // What we do when the user long presses on home
Jeff Browncaca8812013-05-09 13:34:33 -0700532 private int mLongPressOnHomeBehavior;
533
534 // What we do when the user double-taps on home
535 private int mDoubleTapOnHomeBehavior;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800536
Bryce Lee584a4452014-10-21 15:55:55 -0700537 // Allowed theater mode wake actions
538 private boolean mAllowTheaterModeWakeFromKey;
539 private boolean mAllowTheaterModeWakeFromPowerKey;
540 private boolean mAllowTheaterModeWakeFromMotion;
Bryce Lee812d7022014-11-10 13:33:28 -0800541 private boolean mAllowTheaterModeWakeFromMotionWhenNotDreaming;
Bryce Lee584a4452014-10-21 15:55:55 -0700542 private boolean mAllowTheaterModeWakeFromCameraLens;
543 private boolean mAllowTheaterModeWakeFromLidSwitch;
544 private boolean mAllowTheaterModeWakeFromWakeGesture;
545
Bryce Lee55e846d2014-11-04 12:43:44 -0800546 // Whether to go to sleep entering theater mode from power button
547 private boolean mGoToSleepOnButtonPressTheaterMode;
548
Winson Chung9112ec32011-06-27 13:15:32 -0700549 // Screenshot trigger states
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700550 // Time to volume and power must be pressed within this interval of each other.
551 private static final long SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS = 150;
Winson Chung1cea2f32012-10-08 20:42:01 -0700552 // Increase the chord delay when taking a screenshot from the keyguard
553 private static final float KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER = 2.5f;
Christopher Tatee90585f2012-03-05 18:56:25 -0800554 private boolean mScreenshotChordEnabled;
Jeff Brown13f00f02014-10-31 14:45:50 -0700555 private boolean mScreenshotChordVolumeDownKeyTriggered;
556 private long mScreenshotChordVolumeDownKeyTime;
557 private boolean mScreenshotChordVolumeDownKeyConsumed;
558 private boolean mScreenshotChordVolumeUpKeyTriggered;
559 private boolean mScreenshotChordPowerKeyTriggered;
560 private long mScreenshotChordPowerKeyTime;
Winson Chung9112ec32011-06-27 13:15:32 -0700561
Michael Wrightb854e242013-02-05 17:54:02 -0800562 /* The number of steps between min and max brightness */
563 private static final int BRIGHTNESS_STEPS = 10;
564
Christopher Tate5e08af02012-09-21 17:17:22 -0700565 SettingsObserver mSettingsObserver;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800566 ShortcutManager mShortcutManager;
567 PowerManager.WakeLock mBroadcastWakeLock;
Jeff Brown13f00f02014-10-31 14:45:50 -0700568 PowerManager.WakeLock mPowerKeyWakeLock;
Jeff Brown40013652012-05-16 21:22:36 -0700569 boolean mHavePendingMediaKeyRepeatWithWakeLock;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800570
Craig Mautnerd625ab22013-09-06 13:40:31 -0700571 private int mCurrentUserId;
572
Justin Kohd378ad72013-04-01 12:18:26 -0700573 // Maps global key codes to the components that will handle them.
574 private GlobalKeyManager mGlobalKeyManager;
575
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700576 // Fallback actions by key code.
577 private final SparseArray<KeyCharacterMap.FallbackAction> mFallbackActions =
578 new SparseArray<KeyCharacterMap.FallbackAction>();
Jeff Brown49ed71d2010-12-06 17:13:33 -0800579
Jorim Jaggi76a16232014-08-08 17:00:47 +0200580 private final LogDecelerateInterpolator mLogDecelerateInterpolator
581 = new LogDecelerateInterpolator(100, 0);
582
Jeff Brown70825162012-03-28 17:27:48 -0700583 private static final int MSG_ENABLE_POINTER_LOCATION = 1;
584 private static final int MSG_DISABLE_POINTER_LOCATION = 2;
Jeff Brown40013652012-05-16 21:22:36 -0700585 private static final int MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK = 3;
586 private static final int MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK = 4;
Craig Mautner8a0da012014-05-31 15:13:37 -0700587 private static final int MSG_KEYGUARD_DRAWN_COMPLETE = 5;
588 private static final int MSG_KEYGUARD_DRAWN_TIMEOUT = 6;
589 private static final int MSG_WINDOW_MANAGER_DRAWN_COMPLETE = 7;
Craig Mautner84984fa2014-06-19 11:19:20 -0700590 private static final int MSG_DISPATCH_SHOW_RECENTS = 9;
Alan Viverettee34560b22014-07-10 14:50:06 -0700591 private static final int MSG_DISPATCH_SHOW_GLOBAL_ACTIONS = 10;
Craig Mautnera631d492014-08-05 15:16:01 -0700592 private static final int MSG_HIDE_BOOT_MESSAGE = 11;
Michael Wright869a67c2014-08-26 19:33:06 -0700593 private static final int MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK = 12;
Jeff Brown13f00f02014-10-31 14:45:50 -0700594 private static final int MSG_POWER_DELAYED_PRESS = 13;
595 private static final int MSG_POWER_LONG_PRESS = 14;
Jeff Brown70825162012-03-28 17:27:48 -0700596
597 private class PolicyHandler extends Handler {
598 @Override
599 public void handleMessage(Message msg) {
600 switch (msg.what) {
601 case MSG_ENABLE_POINTER_LOCATION:
602 enablePointerLocation();
603 break;
604 case MSG_DISABLE_POINTER_LOCATION:
605 disablePointerLocation();
606 break;
Jeff Brown40013652012-05-16 21:22:36 -0700607 case MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK:
608 dispatchMediaKeyWithWakeLock((KeyEvent)msg.obj);
609 break;
610 case MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK:
611 dispatchMediaKeyRepeatWithWakeLock((KeyEvent)msg.obj);
612 break;
Craig Mautner84984fa2014-06-19 11:19:20 -0700613 case MSG_DISPATCH_SHOW_RECENTS:
614 showRecentApps(false);
615 break;
Alan Viverettee34560b22014-07-10 14:50:06 -0700616 case MSG_DISPATCH_SHOW_GLOBAL_ACTIONS:
617 showGlobalActionsInternal();
618 break;
Craig Mautner8a0da012014-05-31 15:13:37 -0700619 case MSG_KEYGUARD_DRAWN_COMPLETE:
620 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mKeyguardDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700621 finishKeyguardDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700622 break;
623 case MSG_KEYGUARD_DRAWN_TIMEOUT:
624 Slog.w(TAG, "Keyguard drawn timeout. Setting mKeyguardDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700625 finishKeyguardDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700626 break;
627 case MSG_WINDOW_MANAGER_DRAWN_COMPLETE:
628 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mWindowManagerDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700629 finishWindowsDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700630 break;
Craig Mautnera631d492014-08-05 15:16:01 -0700631 case MSG_HIDE_BOOT_MESSAGE:
632 handleHideBootMessage();
633 break;
Michael Wright869a67c2014-08-26 19:33:06 -0700634 case MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK:
635 launchVoiceAssistWithWakeLock(msg.arg1 != 0);
636 break;
Jeff Brown13f00f02014-10-31 14:45:50 -0700637 case MSG_POWER_DELAYED_PRESS:
638 powerPress((Long)msg.obj, msg.arg1 != 0, msg.arg2);
639 finishPowerKeyPress();
640 break;
641 case MSG_POWER_LONG_PRESS:
642 powerLongPress();
643 break;
Jeff Brown70825162012-03-28 17:27:48 -0700644 }
645 }
646 }
647
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800648 private UEventObserver mHDMIObserver = new UEventObserver() {
649 @Override
650 public void onUEvent(UEventObserver.UEvent event) {
651 setHdmiPlugged("1".equals(event.get("SWITCH_STATE")));
652 }
653 };
654
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800655 class SettingsObserver extends ContentObserver {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800656 SettingsObserver(Handler handler) {
657 super(handler);
658 }
David Brownbaf8d092010-03-08 21:52:59 -0800659
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800660 void observe() {
Christopher Tate5e08af02012-09-21 17:17:22 -0700661 // Observe all users' changes
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800662 ContentResolver resolver = mContext.getContentResolver();
663 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700664 Settings.System.END_BUTTON_BEHAVIOR), false, this,
665 UserHandle.USER_ALL);
David Brownbaf8d092010-03-08 21:52:59 -0800666 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700667 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR), false, this,
668 UserHandle.USER_ALL);
Jeff Browna20dda42014-05-27 20:57:24 -0700669 resolver.registerContentObserver(Settings.Secure.getUriFor(
670 Settings.Secure.WAKE_GESTURE_ENABLED), false, this,
671 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800672 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700673 Settings.System.ACCELEROMETER_ROTATION), false, this,
674 UserHandle.USER_ALL);
Mike Lockwood28569302010-01-28 11:54:40 -0500675 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700676 Settings.System.USER_ROTATION), false, this,
677 UserHandle.USER_ALL);
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400678 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700679 Settings.System.SCREEN_OFF_TIMEOUT), false, this,
680 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800681 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700682 Settings.System.POINTER_LOCATION), false, this,
683 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800684 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700685 Settings.Secure.DEFAULT_INPUT_METHOD), false, this,
686 UserHandle.USER_ALL);
John Spurlockd9b70bd2014-02-06 17:02:44 -0500687 resolver.registerContentObserver(Settings.Secure.getUriFor(
John Spurlockf1a36642013-10-12 17:50:42 -0400688 Settings.Secure.IMMERSIVE_MODE_CONFIRMATIONS), false, this,
Christopher Tate5e08af02012-09-21 17:17:22 -0700689 UserHandle.USER_ALL);
John Spurlockc6d1c602014-01-17 15:22:06 -0500690 resolver.registerContentObserver(Settings.Global.getUriFor(
691 Settings.Global.POLICY_CONTROL), false, this,
692 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800693 updateSettings();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800694 }
695
696 @Override public void onChange(boolean selfChange) {
Dianne Hackbornc777e072010-02-12 13:07:59 -0800697 updateSettings();
Jeff Brown01a98dd2011-09-20 15:08:29 -0700698 updateRotation(false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800699 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800700 }
Craig Mautner967212c2013-04-13 21:10:58 -0700701
Jeff Browna20dda42014-05-27 20:57:24 -0700702 class MyWakeGestureListener extends WakeGestureListener {
703 MyWakeGestureListener(Context context, Handler handler) {
704 super(context, handler);
705 }
706
707 @Override
708 public void onWakeUp() {
709 synchronized (mLock) {
710 if (shouldEnableWakeGestureLp()) {
Jeff Browne07b94b2014-06-18 15:56:27 -0700711 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
Bryce Lee584a4452014-10-21 15:55:55 -0700712 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromWakeGesture);
Jeff Browna20dda42014-05-27 20:57:24 -0700713 }
714 }
715 }
716 }
717
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800718 class MyOrientationListener extends WindowOrientationListener {
Craig Mautnereee29c42013-01-17 14:44:34 -0800719 MyOrientationListener(Context context, Handler handler) {
720 super(context, handler);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800721 }
Craig Mautner967212c2013-04-13 21:10:58 -0700722
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800723 @Override
Jeff Brownc0347aa2011-09-23 17:26:09 -0700724 public void onProposedRotationChanged(int rotation) {
Craig Mautnereda67292013-04-28 13:50:14 -0700725 if (localLOGV) Slog.v(TAG, "onProposedRotationChanged, rotation=" + rotation);
Jeff Brown01a98dd2011-09-20 15:08:29 -0700726 updateRotation(false);
727 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800728 }
729 MyOrientationListener mOrientationListener;
730
Jorim Jaggi24bec7c2015-02-04 12:40:14 +0100731 private final StatusBarController mStatusBarController = new StatusBarController();
John Spurlock5b9145b2013-08-20 15:13:47 -0400732
John Spurlock27735a42013-08-14 17:57:38 -0400733 private final BarController mNavigationBarController = new BarController("NavigationBar",
John Spurlock5b9145b2013-08-20 15:13:47 -0400734 View.NAVIGATION_BAR_TRANSIENT,
735 View.NAVIGATION_BAR_UNHIDE,
John Spurlockbd957402013-10-03 11:38:39 -0400736 View.NAVIGATION_BAR_TRANSLUCENT,
737 StatusBarManager.WINDOW_NAVIGATION_BAR,
738 WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
John Spurlock5b9145b2013-08-20 15:13:47 -0400739
John Spurlockf1a36642013-10-12 17:50:42 -0400740 private ImmersiveModeConfirmation mImmersiveModeConfirmation;
John Spurlock32beb2c2013-03-11 10:16:47 -0400741
Craig Mautner037aa8d2013-06-07 10:35:44 -0700742 private SystemGesturesPointerEventListener mSystemGestures;
John Spurlock32beb2c2013-03-11 10:16:47 -0400743
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700744 IStatusBarService getStatusBarService() {
745 synchronized (mServiceAquireLock) {
746 if (mStatusBarService == null) {
747 mStatusBarService = IStatusBarService.Stub.asInterface(
748 ServiceManager.getService("statusbar"));
749 }
750 return mStatusBarService;
751 }
752 }
753
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700754 /*
755 * We always let the sensor be switched on by default except when
756 * the user has explicitly disabled sensor based rotation or when the
757 * screen is switched off.
758 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700759 boolean needSensorRunningLp() {
Jeff Brownbcdfc622014-03-06 19:13:04 -0800760 if (mSupportAutoRotation) {
761 if (mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
762 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
763 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT
764 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) {
765 // If the application has explicitly requested to follow the
766 // orientation, then we need to turn the sensor on.
767 return true;
768 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800769 }
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700770 if ((mCarDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_CAR) ||
Jeff Brown1a693182011-11-08 14:44:16 -0800771 (mDeskDockEnablesAccelerometer && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
772 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
773 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK))) {
Mike Lockwoode9867d22009-09-20 01:59:02 -0400774 // enable accelerometer if we are docked in a dock that enables accelerometer
775 // orientation management,
776 return true;
777 }
Jeff Brown207673cd2012-06-05 17:47:11 -0700778 if (mUserRotationMode == USER_ROTATION_LOCKED) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800779 // If the setting for using the sensor by default is enabled, then
780 // we will always leave it on. Note that the user could go to
781 // a window that forces an orientation that does not use the
782 // sensor and in theory we could turn it off... however, when next
783 // turning it on we won't have a good value for the current
784 // orientation for a little bit, which can cause orientation
785 // changes to lag, so we'd like to keep it always on. (It will
786 // still be turned off when the screen is off.)
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700787 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800788 }
Jeff Brownbcdfc622014-03-06 19:13:04 -0800789 return mSupportAutoRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800790 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700791
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800792 /*
793 * Various use cases for invoking this function
794 * screen turning off, should always disable listeners if already enabled
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700795 * screen turned on and current app has sensor based orientation, enable listeners
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800796 * if not already enabled
797 * screen turned on and current app does not have sensor orientation, disable listeners if
798 * already enabled
799 * screen turning on and current app has sensor based orientation, enable listeners if needed
800 * screen turning on and current app has nosensor based orientation, do nothing
801 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700802 void updateOrientationListenerLp() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800803 if (!mOrientationListener.canDetectOrientation()) {
804 // If sensor is turned off or nonexistent for some reason
805 return;
806 }
807 //Could have been invoked due to screen turning on or off or
808 //change of the currently visible window's orientation
Jeff Brown3ee549c2014-09-22 20:14:39 -0700809 if (localLOGV) Slog.v(TAG, "mScreenOnEarly=" + mScreenOnEarly
810 + ", mAwake=" + mAwake + ", mCurrentAppOrientation=" + mCurrentAppOrientation
811 + ", mOrientationSensorEnabled=" + mOrientationSensorEnabled);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800812 boolean disable = true;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700813 if (mScreenOnEarly && mAwake) {
The Android Open Source Project0727d222009-03-11 12:11:58 -0700814 if (needSensorRunningLp()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800815 disable = false;
816 //enable listener if not already enabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700817 if (!mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800818 mOrientationListener.enable();
Craig Mautnereda67292013-04-28 13:50:14 -0700819 if(localLOGV) Slog.v(TAG, "Enabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800820 mOrientationSensorEnabled = true;
821 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700822 }
823 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800824 //check if sensors need to be disabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700825 if (disable && mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800826 mOrientationListener.disable();
Craig Mautnereda67292013-04-28 13:50:14 -0700827 if(localLOGV) Slog.v(TAG, "Disabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800828 mOrientationSensorEnabled = false;
829 }
830 }
831
Jeff Brown13f00f02014-10-31 14:45:50 -0700832 private void interceptPowerKeyDown(KeyEvent event, boolean interactive) {
833 // Hold a wake lock until the power key is released.
834 if (!mPowerKeyWakeLock.isHeld()) {
835 mPowerKeyWakeLock.acquire();
836 }
837
838 // Cancel multi-press detection timeout.
839 if (mPowerKeyPressCounter != 0) {
840 mHandler.removeMessages(MSG_POWER_DELAYED_PRESS);
841 }
842
843 // Detect user pressing the power button in panic when an application has
844 // taken over the whole screen.
845 boolean panic = mImmersiveModeConfirmation.onPowerKeyDown(interactive,
Craig Mautner0124980e92014-11-30 21:15:34 -0800846 SystemClock.elapsedRealtime(), isImmersiveMode(mLastSystemUiFlags));
Jeff Brown13f00f02014-10-31 14:45:50 -0700847 if (panic) {
848 mHandler.post(mRequestTransientNav);
849 }
850
851 // Latch power key state to detect screenshot chord.
852 if (interactive && !mScreenshotChordPowerKeyTriggered
853 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
854 mScreenshotChordPowerKeyTriggered = true;
855 mScreenshotChordPowerKeyTime = event.getDownTime();
856 interceptScreenshotChord();
857 }
858
859 // Stop ringing or end call if configured to do so when power is pressed.
860 TelecomManager telecomManager = getTelecommService();
861 boolean hungUp = false;
862 if (telecomManager != null) {
863 if (telecomManager.isRinging()) {
864 // Pressing Power while there's a ringing incoming
865 // call should silence the ringer.
866 telecomManager.silenceRinger();
867 } else if ((mIncallPowerBehavior
868 & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0
869 && telecomManager.isInCall() && interactive) {
870 // Otherwise, if "Power button ends call" is enabled,
871 // the Power button will hang up any current active call.
872 hungUp = telecomManager.endCall();
873 }
874 }
875
876 // If the power key has still not yet been handled, then detect short
877 // press, long press, or multi press and decide what to do.
878 mPowerKeyHandled = hungUp || mScreenshotChordVolumeDownKeyTriggered
879 || mScreenshotChordVolumeUpKeyTriggered;
880 if (!mPowerKeyHandled) {
881 if (interactive) {
882 // When interactive, we're already awake.
883 // Wait for a long press or for the button to be released to decide what to do.
884 if (hasLongPressOnPowerBehavior()) {
885 Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS);
886 msg.setAsynchronous(true);
887 mHandler.sendMessageDelayed(msg,
888 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
889 }
890 } else {
Bryce Leed9268e32014-11-17 17:40:59 -0800891 wakeUpFromPowerKey(event.getDownTime());
Jeff Brown13f00f02014-10-31 14:45:50 -0700892 final int maxCount = getMaxMultiPressPowerCount();
Bryce Leed9268e32014-11-17 17:40:59 -0800893
Jeff Brown13f00f02014-10-31 14:45:50 -0700894 if (maxCount <= 1) {
Jeff Brown13f00f02014-10-31 14:45:50 -0700895 mPowerKeyHandled = true;
Bryce Leed9268e32014-11-17 17:40:59 -0800896 } else {
897 mBeganFromNonInteractive = true;
Jeff Brown13f00f02014-10-31 14:45:50 -0700898 }
899 }
Jeff Brown4d396052010-10-29 21:50:21 -0700900 }
901 }
902
Jeff Brown13f00f02014-10-31 14:45:50 -0700903 private void interceptPowerKeyUp(KeyEvent event, boolean interactive, boolean canceled) {
904 final boolean handled = canceled || mPowerKeyHandled;
905 mScreenshotChordPowerKeyTriggered = false;
906 cancelPendingScreenshotChordAction();
907 cancelPendingPowerKeyAction();
908
909 if (!handled) {
910 // Figure out how to handle the key now that it has been released.
911 mPowerKeyPressCounter += 1;
912
913 final int maxCount = getMaxMultiPressPowerCount();
914 final long eventTime = event.getDownTime();
915 if (mPowerKeyPressCounter < maxCount) {
916 // This could be a multi-press. Wait a little bit longer to confirm.
917 // Continue holding the wake lock.
918 Message msg = mHandler.obtainMessage(MSG_POWER_DELAYED_PRESS,
919 interactive ? 1 : 0, mPowerKeyPressCounter, eventTime);
920 msg.setAsynchronous(true);
921 mHandler.sendMessageDelayed(msg, ViewConfiguration.getDoubleTapTimeout());
922 return;
923 }
924
925 // No other actions. Handle it immediately.
926 powerPress(eventTime, interactive, mPowerKeyPressCounter);
Jeff Brown4d396052010-10-29 21:50:21 -0700927 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700928
929 // Done. Reset our state.
930 finishPowerKeyPress();
931 }
932
933 private void finishPowerKeyPress() {
Bryce Leed9268e32014-11-17 17:40:59 -0800934 mBeganFromNonInteractive = false;
Jeff Brown13f00f02014-10-31 14:45:50 -0700935 mPowerKeyPressCounter = 0;
936 if (mPowerKeyWakeLock.isHeld()) {
937 mPowerKeyWakeLock.release();
938 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700939 }
940
941 private void cancelPendingPowerKeyAction() {
942 if (!mPowerKeyHandled) {
Jeff Brown13f00f02014-10-31 14:45:50 -0700943 mPowerKeyHandled = true;
944 mHandler.removeMessages(MSG_POWER_LONG_PRESS);
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700945 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700946 }
947
948 private void powerPress(long eventTime, boolean interactive, int count) {
949 if (mScreenOnEarly && !mScreenOnFully) {
950 Slog.i(TAG, "Suppressed redundant power key press while "
951 + "already in the process of turning the screen on.");
952 return;
Jeff Brownff204712011-10-25 21:27:54 -0700953 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700954
955 if (count == 2) {
956 powerMultiPressAction(eventTime, interactive, mDoublePressOnPowerBehavior);
957 } else if (count == 3) {
958 powerMultiPressAction(eventTime, interactive, mTriplePressOnPowerBehavior);
Bryce Leed9268e32014-11-17 17:40:59 -0800959 } else if (interactive && !mBeganFromNonInteractive) {
Jeff Brown13f00f02014-10-31 14:45:50 -0700960 switch (mShortPressOnPowerBehavior) {
961 case SHORT_PRESS_POWER_NOTHING:
962 break;
963 case SHORT_PRESS_POWER_GO_TO_SLEEP:
964 mPowerManager.goToSleep(eventTime,
965 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
966 break;
967 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP:
968 mPowerManager.goToSleep(eventTime,
969 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
970 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
971 break;
972 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME:
973 mPowerManager.goToSleep(eventTime,
974 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
975 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
976 launchHomeFromHotKey();
977 break;
Bryce Lee01b0c5f2015-02-05 18:24:04 -0800978 case SHORT_PRESS_POWER_GO_HOME:
979 launchHomeFromHotKey();
980 break;
Jeff Brown13f00f02014-10-31 14:45:50 -0700981 }
982 }
983 }
984
985 private void powerMultiPressAction(long eventTime, boolean interactive, int behavior) {
986 switch (behavior) {
987 case MULTI_PRESS_POWER_NOTHING:
988 break;
989 case MULTI_PRESS_POWER_THEATER_MODE:
990 if (isTheaterModeEnabled()) {
991 Slog.i(TAG, "Toggling theater mode off.");
992 Settings.Global.putInt(mContext.getContentResolver(),
993 Settings.Global.THEATER_MODE_ON, 0);
994 if (!interactive) {
995 wakeUpFromPowerKey(eventTime);
996 }
997 } else {
998 Slog.i(TAG, "Toggling theater mode on.");
999 Settings.Global.putInt(mContext.getContentResolver(),
1000 Settings.Global.THEATER_MODE_ON, 1);
Bryce Lee55e846d2014-11-04 12:43:44 -08001001
1002 if (mGoToSleepOnButtonPressTheaterMode && interactive) {
Jeff Brown13f00f02014-10-31 14:45:50 -07001003 mPowerManager.goToSleep(eventTime,
1004 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
1005 }
1006 }
1007 break;
1008 case MULTI_PRESS_POWER_BRIGHTNESS_BOOST:
Jeff Brown7b5be5e2014-11-12 18:45:31 -08001009 Slog.i(TAG, "Starting brightness boost.");
1010 if (!interactive) {
1011 wakeUpFromPowerKey(eventTime);
1012 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001013 mPowerManager.boostScreenBrightness(eventTime);
1014 break;
1015 }
1016 }
1017
1018 private int getMaxMultiPressPowerCount() {
1019 if (mTriplePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) {
1020 return 3;
1021 }
1022 if (mDoublePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) {
1023 return 2;
1024 }
1025 return 1;
1026 }
1027
1028 private void powerLongPress() {
1029 final int behavior = getResolvedLongPressOnPowerBehavior();
1030 switch (behavior) {
1031 case LONG_PRESS_POWER_NOTHING:
1032 break;
1033 case LONG_PRESS_POWER_GLOBAL_ACTIONS:
1034 mPowerKeyHandled = true;
1035 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
1036 performAuditoryFeedbackForAccessibilityIfNeed();
1037 }
1038 showGlobalActionsInternal();
1039 break;
1040 case LONG_PRESS_POWER_SHUT_OFF:
1041 case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM:
1042 mPowerKeyHandled = true;
1043 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
1044 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
1045 mWindowManagerFuncs.shutdown(behavior == LONG_PRESS_POWER_SHUT_OFF);
1046 break;
1047 }
1048 }
1049
1050 private int getResolvedLongPressOnPowerBehavior() {
1051 if (FactoryTest.isLongPressOnPowerOffEnabled()) {
1052 return LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM;
1053 }
1054 return mLongPressOnPowerBehavior;
1055 }
1056
1057 private boolean hasLongPressOnPowerBehavior() {
1058 return getResolvedLongPressOnPowerBehavior() != LONG_PRESS_POWER_NOTHING;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001059 }
1060
1061 private void interceptScreenshotChord() {
Christopher Tatee90585f2012-03-05 18:56:25 -08001062 if (mScreenshotChordEnabled
Jeff Brown13f00f02014-10-31 14:45:50 -07001063 && mScreenshotChordVolumeDownKeyTriggered && mScreenshotChordPowerKeyTriggered
1064 && !mScreenshotChordVolumeUpKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001065 final long now = SystemClock.uptimeMillis();
Jeff Brown13f00f02014-10-31 14:45:50 -07001066 if (now <= mScreenshotChordVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS
1067 && now <= mScreenshotChordPowerKeyTime
1068 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) {
1069 mScreenshotChordVolumeDownKeyConsumed = true;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001070 cancelPendingPowerKeyAction();
1071
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001072 mHandler.postDelayed(mScreenshotRunnable, getScreenshotChordLongPressDelay());
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001073 }
1074 }
1075 }
1076
Winson Chung1cea2f32012-10-08 20:42:01 -07001077 private long getScreenshotChordLongPressDelay() {
Jim Miller5ecd8112013-01-09 18:50:26 -08001078 if (mKeyguardDelegate.isShowing()) {
Winson Chung1cea2f32012-10-08 20:42:01 -07001079 // Double the time it takes to take a screenshot from the keyguard
1080 return (long) (KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER *
Justin Kohfeabd2c2014-05-02 10:02:44 -07001081 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Winson Chung1cea2f32012-10-08 20:42:01 -07001082 }
Justin Kohfeabd2c2014-05-02 10:02:44 -07001083 return ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout();
Winson Chung1cea2f32012-10-08 20:42:01 -07001084 }
1085
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001086 private void cancelPendingScreenshotChordAction() {
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001087 mHandler.removeCallbacks(mScreenshotRunnable);
Jeff Brown4d396052010-10-29 21:50:21 -07001088 }
1089
Jeff Brown13f00f02014-10-31 14:45:50 -07001090 private final Runnable mEndCallLongPress = new Runnable() {
Craig Mautnerf1b67412012-09-19 13:18:29 -07001091 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001092 public void run() {
Jeff Brown13f00f02014-10-31 14:45:50 -07001093 mEndCallKeyHandled = true;
1094 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
1095 performAuditoryFeedbackForAccessibilityIfNeed();
Joe Onoratod208e702010-10-08 16:22:43 -04001096 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001097 showGlobalActionsInternal();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001098 }
1099 };
1100
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001101 private final Runnable mScreenshotRunnable = new Runnable() {
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001102 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001103 public void run() {
1104 takeScreenshot();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001105 }
1106 };
1107
Alan Viverettee34560b22014-07-10 14:50:06 -07001108 @Override
1109 public void showGlobalActions() {
1110 mHandler.removeMessages(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
1111 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
1112 }
1113
1114 void showGlobalActionsInternal() {
1115 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001116 if (mGlobalActions == null) {
Jeff Brown7304c342012-05-11 18:42:42 -07001117 mGlobalActions = new GlobalActions(mContext, mWindowManagerFuncs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001118 }
Jim Millerab954542014-10-10 18:21:49 -07001119 final boolean keyguardShowing = isKeyguardShowingAndNotOccluded();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001120 mGlobalActions.showDialog(keyguardShowing, isDeviceProvisioned());
1121 if (keyguardShowing) {
1122 // since it took two seconds of long press to bring this up,
1123 // poke the wake lock so they have some time to see the dialog.
Jim Miller25190572013-02-28 17:36:24 -08001124 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001125 }
1126 }
1127
1128 boolean isDeviceProvisioned() {
Jeff Brownbf6f6f92012-09-25 15:03:20 -07001129 return Settings.Global.getInt(
1130 mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001131 }
1132
Maurice Lam99c6e072014-04-28 18:24:28 -07001133 boolean isUserSetupComplete() {
1134 return Settings.Secure.getIntForUser(mContext.getContentResolver(),
1135 Settings.Secure.USER_SETUP_COMPLETE, 0, UserHandle.USER_CURRENT) != 0;
1136 }
1137
Jeff Brown13f00f02014-10-31 14:45:50 -07001138 private void handleShortPressOnHome() {
1139 // If there's a dream running then use home to escape the dream
1140 // but don't actually go home.
1141 if (mDreamManagerInternal != null && mDreamManagerInternal.isDreaming()) {
1142 mDreamManagerInternal.stopDream(false /*immediate*/);
1143 return;
1144 }
1145
1146 // Go home!
1147 launchHomeFromHotKey();
1148 }
1149
Patrick Dubroyece94522011-02-23 18:35:01 -08001150 private void handleLongPressOnHome() {
Joe Onorato46b0d682010-11-22 17:37:27 -08001151 if (mLongPressOnHomeBehavior != LONG_PRESS_HOME_NOTHING) {
Jeff Browncaca8812013-05-09 13:34:33 -07001152 mHomeConsumed = true;
Joe Onorato46b0d682010-11-22 17:37:27 -08001153 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
Patrick Dubroyece94522011-02-23 18:35:01 -08001154
Jeff Browncaca8812013-05-09 13:34:33 -07001155 if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI) {
1156 toggleRecentApps();
1157 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_ASSIST) {
1158 launchAssistAction();
Jim Millere6ad1a82010-08-20 19:25:39 -07001159 }
1160 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001161 }
Patrick Dubroyece94522011-02-23 18:35:01 -08001162
Jeff Browncaca8812013-05-09 13:34:33 -07001163 private void handleDoubleTapOnHome() {
1164 if (mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1165 mHomeConsumed = true;
1166 toggleRecentApps();
1167 }
1168 }
1169
1170 private final Runnable mHomeDoubleTapTimeoutRunnable = new Runnable() {
1171 @Override
1172 public void run() {
1173 if (mHomeDoubleTapPending) {
1174 mHomeDoubleTapPending = false;
Jeff Brown13f00f02014-10-31 14:45:50 -07001175 handleShortPressOnHome();
Jeff Browncaca8812013-05-09 13:34:33 -07001176 }
1177 }
1178 };
1179
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001180 /** {@inheritDoc} */
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001181 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001182 public void init(Context context, IWindowManager windowManager,
Jeff Brown96307042012-07-27 15:51:34 -07001183 WindowManagerFuncs windowManagerFuncs) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001184 mContext = context;
1185 mWindowManager = windowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -07001186 mWindowManagerFuncs = windowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -07001187 mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class);
Jose Lima9546b202014-07-02 17:21:51 -07001188 mDreamManagerInternal = LocalServices.getService(DreamManagerInternal.class);
Filip Gruszczynskicfb31852015-02-25 21:47:12 +00001189 if (context.getResources().getBoolean(
1190 com.android.internal.R.bool.config_enableBurnInProtection)){
1191 mBurnInProtectionHelper = new BurnInProtectionHelper(context);
1192 }
Craig Mautner8a0da012014-05-31 15:13:37 -07001193
Jeff Brown70825162012-03-28 17:27:48 -07001194 mHandler = new PolicyHandler();
Jeff Browna20dda42014-05-27 20:57:24 -07001195 mWakeGestureListener = new MyWakeGestureListener(mContext, mHandler);
Craig Mautnereee29c42013-01-17 14:44:34 -08001196 mOrientationListener = new MyOrientationListener(mContext, mHandler);
Jeff Brownc0347aa2011-09-23 17:26:09 -07001197 try {
1198 mOrientationListener.setCurrentRotation(windowManager.getRotation());
1199 } catch (RemoteException ex) { }
Christopher Tate5e08af02012-09-21 17:17:22 -07001200 mSettingsObserver = new SettingsObserver(mHandler);
1201 mSettingsObserver.observe();
Svetoslav683914b2015-01-15 14:22:26 -08001202 mShortcutManager = new ShortcutManager(context);
Daniel Sandler6396c722013-04-16 20:19:09 -04001203 mUiMode = context.getResources().getInteger(
1204 com.android.internal.R.integer.config_defaultUiModeType);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001205 mHomeIntent = new Intent(Intent.ACTION_MAIN, null);
1206 mHomeIntent.addCategory(Intent.CATEGORY_HOME);
1207 mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1208 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07001209 mCarDockIntent = new Intent(Intent.ACTION_MAIN, null);
1210 mCarDockIntent.addCategory(Intent.CATEGORY_CAR_DOCK);
1211 mCarDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1212 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
1213 mDeskDockIntent = new Intent(Intent.ACTION_MAIN, null);
1214 mDeskDockIntent.addCategory(Intent.CATEGORY_DESK_DOCK);
1215 mDeskDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1216 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Jim Millere6ad1a82010-08-20 19:25:39 -07001217
Jeff Brown96307042012-07-27 15:51:34 -07001218 mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
1219 mBroadcastWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001220 "PhoneWindowManager.mBroadcastWakeLock");
Jeff Brown13f00f02014-10-31 14:45:50 -07001221 mPowerKeyWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
1222 "PhoneWindowManager.mPowerKeyWakeLock");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001223 mEnableShiftMenuBugReports = "1".equals(SystemProperties.get("ro.debuggable"));
Jeff Brownbcdfc622014-03-06 19:13:04 -08001224 mSupportAutoRotation = mContext.getResources().getBoolean(
1225 com.android.internal.R.bool.config_supportAutoRotation);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001226 mLidOpenRotation = readRotation(
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001227 com.android.internal.R.integer.config_lidOpenRotation);
1228 mCarDockRotation = readRotation(
1229 com.android.internal.R.integer.config_carDockRotation);
1230 mDeskDockRotation = readRotation(
1231 com.android.internal.R.integer.config_deskDockRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001232 mUndockedHdmiRotation = readRotation(
1233 com.android.internal.R.integer.config_undockedHdmiRotation);
Mike Lockwoode9867d22009-09-20 01:59:02 -04001234 mCarDockEnablesAccelerometer = mContext.getResources().getBoolean(
1235 com.android.internal.R.bool.config_carDockEnablesAccelerometer);
1236 mDeskDockEnablesAccelerometer = mContext.getResources().getBoolean(
1237 com.android.internal.R.bool.config_deskDockEnablesAccelerometer);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001238 mLidKeyboardAccessibility = mContext.getResources().getInteger(
1239 com.android.internal.R.integer.config_lidKeyboardAccessibility);
1240 mLidNavigationAccessibility = mContext.getResources().getInteger(
1241 com.android.internal.R.integer.config_lidNavigationAccessibility);
Jeff Brownc458ce92012-04-30 14:58:40 -07001242 mLidControlsSleep = mContext.getResources().getBoolean(
1243 com.android.internal.R.bool.config_lidControlsSleep);
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04001244 mTranslucentDecorEnabled = mContext.getResources().getBoolean(
1245 com.android.internal.R.bool.config_enableTranslucentDecor);
Bryce Lee584a4452014-10-21 15:55:55 -07001246
1247 mAllowTheaterModeWakeFromKey = mContext.getResources().getBoolean(
1248 com.android.internal.R.bool.config_allowTheaterModeWakeFromKey);
1249 mAllowTheaterModeWakeFromPowerKey = mAllowTheaterModeWakeFromKey
1250 || mContext.getResources().getBoolean(
1251 com.android.internal.R.bool.config_allowTheaterModeWakeFromPowerKey);
1252 mAllowTheaterModeWakeFromMotion = mContext.getResources().getBoolean(
1253 com.android.internal.R.bool.config_allowTheaterModeWakeFromMotion);
Bryce Lee812d7022014-11-10 13:33:28 -08001254 mAllowTheaterModeWakeFromMotionWhenNotDreaming = mContext.getResources().getBoolean(
1255 com.android.internal.R.bool.config_allowTheaterModeWakeFromMotionWhenNotDreaming);
Bryce Lee584a4452014-10-21 15:55:55 -07001256 mAllowTheaterModeWakeFromCameraLens = mContext.getResources().getBoolean(
1257 com.android.internal.R.bool.config_allowTheaterModeWakeFromCameraLens);
1258 mAllowTheaterModeWakeFromLidSwitch = mContext.getResources().getBoolean(
1259 com.android.internal.R.bool.config_allowTheaterModeWakeFromLidSwitch);
1260 mAllowTheaterModeWakeFromWakeGesture = mContext.getResources().getBoolean(
1261 com.android.internal.R.bool.config_allowTheaterModeWakeFromGesture);
1262
Bryce Lee55e846d2014-11-04 12:43:44 -08001263 mGoToSleepOnButtonPressTheaterMode = mContext.getResources().getBoolean(
1264 com.android.internal.R.bool.config_goToSleepOnButtonPressTheaterMode);
1265
Jeff Brown13f00f02014-10-31 14:45:50 -07001266 mShortPressOnPowerBehavior = mContext.getResources().getInteger(
1267 com.android.internal.R.integer.config_shortPressOnPowerBehavior);
1268 mLongPressOnPowerBehavior = mContext.getResources().getInteger(
1269 com.android.internal.R.integer.config_longPressOnPowerBehavior);
1270 mDoublePressOnPowerBehavior = mContext.getResources().getInteger(
1271 com.android.internal.R.integer.config_doublePressOnPowerBehavior);
1272 mTriplePressOnPowerBehavior = mContext.getResources().getInteger(
1273 com.android.internal.R.integer.config_triplePressOnPowerBehavior);
1274
John Spurlock61560172015-02-06 19:46:04 -05001275 mUseTvRouting = AudioSystem.getPlatformType(mContext) == AudioSystem.PLATFORM_TELEVISION;
RoboErik001c59c2015-01-26 15:53:51 -08001276 mUseMasterVolume = mContext.getResources().getBoolean(
1277 com.android.internal.R.bool.config_useMasterVolume);
1278
Jeff Brownf71343d2013-05-31 17:59:11 -07001279 readConfigurationDependentBehaviors();
Jeff Browncaca8812013-05-09 13:34:33 -07001280
Svetoslav8e3feb12014-02-24 13:46:47 -08001281 mAccessibilityManager = (AccessibilityManager) context.getSystemService(
1282 Context.ACCESSIBILITY_SERVICE);
1283
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001284 // register for dock events
Dianne Hackborn78968392010-03-04 20:47:56 -08001285 IntentFilter filter = new IntentFilter();
1286 filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE);
1287 filter.addAction(UiModeManager.ACTION_EXIT_CAR_MODE);
1288 filter.addAction(UiModeManager.ACTION_ENTER_DESK_MODE);
1289 filter.addAction(UiModeManager.ACTION_EXIT_DESK_MODE);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001290 filter.addAction(Intent.ACTION_DOCK_EVENT);
1291 Intent intent = context.registerReceiver(mDockReceiver, filter);
1292 if (intent != null) {
1293 // Retrieve current sticky dock event broadcast.
1294 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
1295 Intent.EXTRA_DOCK_STATE_UNDOCKED);
1296 }
Daniel Sandler7e37df52011-11-16 22:08:23 -08001297
Jeff Brown6aaf2952012-10-05 16:01:08 -07001298 // register for dream-related broadcasts
1299 filter = new IntentFilter();
1300 filter.addAction(Intent.ACTION_DREAMING_STARTED);
1301 filter.addAction(Intent.ACTION_DREAMING_STOPPED);
1302 context.registerReceiver(mDreamReceiver, filter);
1303
Christopher Tate5e08af02012-09-21 17:17:22 -07001304 // register for multiuser-relevant broadcasts
1305 filter = new IntentFilter(Intent.ACTION_USER_SWITCHED);
1306 context.registerReceiver(mMultiuserReceiver, filter);
1307
John Spurlock57306e62013-04-22 09:48:49 -04001308 // monitor for system gestures
Craig Mautner037aa8d2013-06-07 10:35:44 -07001309 mSystemGestures = new SystemGesturesPointerEventListener(context,
1310 new SystemGesturesPointerEventListener.Callbacks() {
John Spurlock57306e62013-04-22 09:48:49 -04001311 @Override
1312 public void onSwipeFromTop() {
John Spurlock04db1762013-05-13 12:46:41 -04001313 if (mStatusBar != null) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001314 requestTransientBars(mStatusBar);
John Spurlock04db1762013-05-13 12:46:41 -04001315 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04001316 }
1317 @Override
1318 public void onSwipeFromBottom() {
John Spurlock04db1762013-05-13 12:46:41 -04001319 if (mNavigationBar != null && mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001320 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001321 }
1322 }
1323 @Override
1324 public void onSwipeFromRight() {
John Spurlock04db1762013-05-13 12:46:41 -04001325 if (mNavigationBar != null && !mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001326 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001327 }
1328 }
1329 @Override
1330 public void onDebug() {
John Spurlockd67ec252013-09-05 11:31:54 -04001331 // no-op
John Spurlockad3e6cb2013-04-30 08:47:43 -04001332 }
1333 });
John Spurlockf1a36642013-10-12 17:50:42 -04001334 mImmersiveModeConfirmation = new ImmersiveModeConfirmation(mContext);
Craig Mautner037aa8d2013-06-07 10:35:44 -07001335 mWindowManagerFuncs.registerPointerEventListener(mSystemGestures);
John Spurlock32beb2c2013-03-11 10:16:47 -04001336
Jeff Brownc2346132012-04-13 01:55:38 -07001337 mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001338 mLongPressVibePattern = getLongIntArray(mContext.getResources(),
1339 com.android.internal.R.array.config_longPressVibePattern);
1340 mVirtualKeyVibePattern = getLongIntArray(mContext.getResources(),
1341 com.android.internal.R.array.config_virtualKeyVibePattern);
Amith Yamasanic33cb712010-02-10 15:21:49 -08001342 mKeyboardTapVibePattern = getLongIntArray(mContext.getResources(),
1343 com.android.internal.R.array.config_keyboardTapVibePattern);
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07001344 mClockTickVibePattern = getLongIntArray(mContext.getResources(),
1345 com.android.internal.R.array.config_clockTickVibePattern);
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07001346 mCalendarDateVibePattern = getLongIntArray(mContext.getResources(),
1347 com.android.internal.R.array.config_calendarDateVibePattern);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001348 mSafeModeDisabledVibePattern = getLongIntArray(mContext.getResources(),
1349 com.android.internal.R.array.config_safeModeDisabledVibePattern);
1350 mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(),
1351 com.android.internal.R.array.config_safeModeEnabledVibePattern);
Daniel Sandler40427442010-07-16 11:44:52 -04001352
Christopher Tatee90585f2012-03-05 18:56:25 -08001353 mScreenshotChordEnabled = mContext.getResources().getBoolean(
1354 com.android.internal.R.bool.config_enableScreenshotChord);
1355
Justin Kohd378ad72013-04-01 12:18:26 -07001356 mGlobalKeyManager = new GlobalKeyManager(mContext);
1357
Joe Onoratoea495d42011-04-06 11:41:11 -07001358 // Controls rotation and the like.
1359 initializeHdmiState();
Dianne Hackborn40011092011-09-22 13:37:48 -07001360
1361 // Match current screen state.
Craig Mautnera631d492014-08-05 15:16:01 -07001362 if (!mPowerManager.isInteractive()) {
Jeff Brown140ffc72014-05-01 15:18:00 -07001363 goingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
Dianne Hackborn40011092011-09-22 13:37:48 -07001364 }
Jorim Jaggi24bec7c2015-02-04 12:40:14 +01001365
1366 mWindowManagerInternal.registerAppTransitionListener(
1367 mStatusBarController.getAppTransitionListener());
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001368 }
1369
Jeff Brownf71343d2013-05-31 17:59:11 -07001370 /**
1371 * Read values from config.xml that may be overridden depending on
1372 * the configuration of the device.
1373 * eg. Disable long press on home goes to recents on sw600dp.
1374 */
1375 private void readConfigurationDependentBehaviors() {
1376 mLongPressOnHomeBehavior = mContext.getResources().getInteger(
1377 com.android.internal.R.integer.config_longPressOnHomeBehavior);
1378 if (mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING ||
1379 mLongPressOnHomeBehavior > LONG_PRESS_HOME_ASSIST) {
1380 mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1381 }
1382
1383 mDoubleTapOnHomeBehavior = mContext.getResources().getInteger(
1384 com.android.internal.R.integer.config_doubleTapOnHomeBehavior);
1385 if (mDoubleTapOnHomeBehavior < DOUBLE_TAP_HOME_NOTHING ||
1386 mDoubleTapOnHomeBehavior > DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1387 mDoubleTapOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1388 }
1389 }
1390
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001391 @Override
Dianne Hackborndde331c2012-08-03 14:01:57 -07001392 public void setInitialDisplaySize(Display display, int width, int height, int density) {
Jeff Brownef981a42013-08-07 14:13:37 -07001393 // This method might be called before the policy has been fully initialized
1394 // or for other displays we don't care about.
1395 if (mContext == null || display.getDisplayId() != Display.DEFAULT_DISPLAY) {
1396 return;
Dianne Hackbornc652de82013-02-15 16:32:56 -08001397 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001398 mDisplay = display;
1399
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001400 final Resources res = mContext.getResources();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001401 int shortSize, longSize;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001402 if (width > height) {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001403 shortSize = height;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001404 longSize = width;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001405 mLandscapeRotation = Surface.ROTATION_0;
1406 mSeascapeRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001407 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001408 mPortraitRotation = Surface.ROTATION_90;
1409 mUpsideDownRotation = Surface.ROTATION_270;
1410 } else {
1411 mPortraitRotation = Surface.ROTATION_270;
1412 mUpsideDownRotation = Surface.ROTATION_90;
1413 }
1414 } else {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001415 shortSize = width;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001416 longSize = height;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001417 mPortraitRotation = Surface.ROTATION_0;
1418 mUpsideDownRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001419 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001420 mLandscapeRotation = Surface.ROTATION_270;
1421 mSeascapeRotation = Surface.ROTATION_90;
1422 } else {
1423 mLandscapeRotation = Surface.ROTATION_90;
1424 mSeascapeRotation = Surface.ROTATION_270;
1425 }
1426 }
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001427
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001428 mStatusBarHeight =
1429 res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001430
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001431 // Height of the navigation bar when presented horizontally at bottom
1432 mNavigationBarHeightForRotation[mPortraitRotation] =
1433 mNavigationBarHeightForRotation[mUpsideDownRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001434 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_height);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001435 mNavigationBarHeightForRotation[mLandscapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001436 mNavigationBarHeightForRotation[mSeascapeRotation] = res.getDimensionPixelSize(
1437 com.android.internal.R.dimen.navigation_bar_height_landscape);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001438
1439 // Width of the navigation bar when presented vertically along one side
1440 mNavigationBarWidthForRotation[mPortraitRotation] =
1441 mNavigationBarWidthForRotation[mUpsideDownRotation] =
1442 mNavigationBarWidthForRotation[mLandscapeRotation] =
1443 mNavigationBarWidthForRotation[mSeascapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001444 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_width);
Daniel Sandler4a066c52012-04-20 14:49:13 -04001445
1446 // SystemUI (status bar) layout policy
Dianne Hackborndde331c2012-08-03 14:01:57 -07001447 int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / density;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001448 int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / density;
Daniel Sandler4a066c52012-04-20 14:49:13 -04001449
Devin Kimd7b12b42014-05-05 14:34:58 -07001450 // Allow the navigation bar to move on non-square small devices (phones).
1451 mNavigationBarCanMove = width != height && shortSizeDp < 600;
Daniel Sandler36412a72011-08-04 09:35:13 -04001452
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001453 mHasNavigationBar = res.getBoolean(com.android.internal.R.bool.config_showNavigationBar);
John Spurlock80f00c12013-06-13 11:10:51 -04001454 // Allow a system property to override this. Used by the emulator.
1455 // See also hasNavigationBar().
1456 String navBarOverride = SystemProperties.get("qemu.hw.mainkeys");
1457 if ("1".equals(navBarOverride)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001458 mHasNavigationBar = false;
John Spurlock80f00c12013-06-13 11:10:51 -04001459 } else if ("0".equals(navBarOverride)) {
1460 mHasNavigationBar = true;
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04001461 }
1462
Jeff Brown27f1d672012-10-17 18:32:34 -07001463 // For demo purposes, allow the rotation of the HDMI display to be controlled.
1464 // By default, HDMI locks rotation to landscape.
Erik Gilling9a41ef82011-09-26 19:21:03 -07001465 if ("portrait".equals(SystemProperties.get("persist.demo.hdmirotation"))) {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001466 mDemoHdmiRotation = mPortraitRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001467 } else {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001468 mDemoHdmiRotation = mLandscapeRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001469 }
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001470 mDemoHdmiRotationLock = SystemProperties.getBoolean("persist.demo.hdmirotationlock", false);
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001471
Chong Zhangae6119ff2014-11-11 18:54:39 -08001472 // For demo purposes, allow the rotation of the remote display to be controlled.
1473 // By default, remote display locks rotation to landscape.
1474 if ("portrait".equals(SystemProperties.get("persist.demo.remoterotation"))) {
1475 mDemoRotation = mPortraitRotation;
1476 } else {
1477 mDemoRotation = mLandscapeRotation;
1478 }
1479 mDemoRotationLock = SystemProperties.getBoolean(
1480 "persist.demo.rotationlock", false);
1481
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001482 // Only force the default orientation if the screen is xlarge, at least 960dp x 720dp, per
1483 // http://developer.android.com/guide/practices/screens_support.html#range
1484 mForceDefaultOrientation = longSizeDp >= 960 && shortSizeDp >= 720 &&
1485 res.getBoolean(com.android.internal.R.bool.config_forceDefaultOrientation) &&
1486 // For debug purposes the next line turns this feature off with:
1487 // $ adb shell setprop config.override_forced_orient true
1488 // $ adb shell wm size reset
1489 !"true".equals(SystemProperties.get("config.override_forced_orient"));
1490 }
1491
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001492 /**
1493 * @return whether the navigation bar can be hidden, e.g. the device has a
1494 * navigation bar and touch exploration is not enabled
1495 */
1496 private boolean canHideNavigationBar() {
Svetoslav8e3feb12014-02-24 13:46:47 -08001497 return mHasNavigationBar
1498 && !mAccessibilityManager.isTouchExplorationEnabled();
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001499 }
1500
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001501 @Override
1502 public boolean isDefaultOrientationForced() {
1503 return mForceDefaultOrientation;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001504 }
1505
Dianne Hackbornc652de82013-02-15 16:32:56 -08001506 @Override
1507 public void setDisplayOverscan(Display display, int left, int top, int right, int bottom) {
1508 if (display.getDisplayId() == Display.DEFAULT_DISPLAY) {
1509 mOverscanLeft = left;
1510 mOverscanTop = top;
1511 mOverscanRight = right;
1512 mOverscanBottom = bottom;
1513 }
1514 }
1515
Dianne Hackbornc777e072010-02-12 13:07:59 -08001516 public void updateSettings() {
1517 ContentResolver resolver = mContext.getContentResolver();
1518 boolean updateRotation = false;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001519 synchronized (mLock) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001520 mEndcallBehavior = Settings.System.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001521 Settings.System.END_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001522 Settings.System.END_BUTTON_BEHAVIOR_DEFAULT,
1523 UserHandle.USER_CURRENT);
1524 mIncallPowerBehavior = Settings.Secure.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001525 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001526 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT,
1527 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001528
Jeff Browna20dda42014-05-27 20:57:24 -07001529 // Configure wake gesture.
1530 boolean wakeGestureEnabledSetting = Settings.Secure.getIntForUser(resolver,
1531 Settings.Secure.WAKE_GESTURE_ENABLED, 0,
1532 UserHandle.USER_CURRENT) != 0;
1533 if (mWakeGestureEnabledSetting != wakeGestureEnabledSetting) {
1534 mWakeGestureEnabledSetting = wakeGestureEnabledSetting;
1535 updateWakeGestureListenerLp();
1536 }
1537
Jeff Brown207673cd2012-06-05 17:47:11 -07001538 // Configure rotation lock.
Christopher Tate5e08af02012-09-21 17:17:22 -07001539 int userRotation = Settings.System.getIntForUser(resolver,
1540 Settings.System.USER_ROTATION, Surface.ROTATION_0,
1541 UserHandle.USER_CURRENT);
Jeff Brown207673cd2012-06-05 17:47:11 -07001542 if (mUserRotation != userRotation) {
1543 mUserRotation = userRotation;
1544 updateRotation = true;
1545 }
Christopher Tate5e08af02012-09-21 17:17:22 -07001546 int userRotationMode = Settings.System.getIntForUser(resolver,
1547 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
Jeff Brown207673cd2012-06-05 17:47:11 -07001548 WindowManagerPolicy.USER_ROTATION_FREE :
1549 WindowManagerPolicy.USER_ROTATION_LOCKED;
1550 if (mUserRotationMode != userRotationMode) {
1551 mUserRotationMode = userRotationMode;
1552 updateRotation = true;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001553 updateOrientationListenerLp();
1554 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001555
Dianne Hackbornc777e072010-02-12 13:07:59 -08001556 if (mSystemReady) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001557 int pointerLocation = Settings.System.getIntForUser(resolver,
1558 Settings.System.POINTER_LOCATION, 0, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001559 if (mPointerLocationMode != pointerLocation) {
1560 mPointerLocationMode = pointerLocation;
Jeff Brown70825162012-03-28 17:27:48 -07001561 mHandler.sendEmptyMessage(pointerLocation != 0 ?
1562 MSG_ENABLE_POINTER_LOCATION : MSG_DISABLE_POINTER_LOCATION);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001563 }
1564 }
1565 // use screen off timeout setting as the timeout for the lockscreen
Christopher Tate5e08af02012-09-21 17:17:22 -07001566 mLockScreenTimeout = Settings.System.getIntForUser(resolver,
1567 Settings.System.SCREEN_OFF_TIMEOUT, 0, UserHandle.USER_CURRENT);
1568 String imId = Settings.Secure.getStringForUser(resolver,
1569 Settings.Secure.DEFAULT_INPUT_METHOD, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001570 boolean hasSoftInput = imId != null && imId.length() > 0;
1571 if (mHasSoftInput != hasSoftInput) {
1572 mHasSoftInput = hasSoftInput;
1573 updateRotation = true;
1574 }
John Spurlockf1a36642013-10-12 17:50:42 -04001575 if (mImmersiveModeConfirmation != null) {
John Spurlock4355a532014-02-19 09:49:25 -05001576 mImmersiveModeConfirmation.loadSetting(mCurrentUserId);
John Spurlockd67ec252013-09-05 11:31:54 -04001577 }
John Spurlockc6d1c602014-01-17 15:22:06 -05001578 PolicyControl.reloadFromSetting(mContext);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001579 }
1580 if (updateRotation) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07001581 updateRotation(true);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001582 }
Jeff Brown70825162012-03-28 17:27:48 -07001583 }
1584
Jeff Browna20dda42014-05-27 20:57:24 -07001585 private void updateWakeGestureListenerLp() {
1586 if (shouldEnableWakeGestureLp()) {
1587 mWakeGestureListener.requestWakeUpTrigger();
1588 } else {
1589 mWakeGestureListener.cancelWakeUpTrigger();
1590 }
1591 }
1592
1593 private boolean shouldEnableWakeGestureLp() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07001594 return mWakeGestureEnabledSetting && !mAwake
Jeff Browna20dda42014-05-27 20:57:24 -07001595 && (!mLidControlsSleep || mLidState != LID_CLOSED)
1596 && mWakeGestureListener.isSupported();
1597 }
1598
Jeff Brown70825162012-03-28 17:27:48 -07001599 private void enablePointerLocation() {
1600 if (mPointerLocationView == null) {
1601 mPointerLocationView = new PointerLocationView(mContext);
1602 mPointerLocationView.setPrintCoords(false);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001603 WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
1604 WindowManager.LayoutParams.MATCH_PARENT,
1605 WindowManager.LayoutParams.MATCH_PARENT);
Jeff Brown3b2b3542010-10-15 00:54:27 -07001606 lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001607 lp.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN
1608 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
1609 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1610 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
Jeff Brown90fc9052012-10-01 14:44:24 -07001611 if (ActivityManager.isHighEndGfx()) {
1612 lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
1613 lp.privateFlags |=
1614 WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED;
1615 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001616 lp.format = PixelFormat.TRANSLUCENT;
1617 lp.setTitle("PointerLocation");
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001618 WindowManager wm = (WindowManager)
Dianne Hackbornc777e072010-02-12 13:07:59 -08001619 mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Browncc4f7db2011-08-30 20:34:48 -07001620 lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL;
Jeff Brown70825162012-03-28 17:27:48 -07001621 wm.addView(mPointerLocationView, lp);
Michael Wrightc9c487e2013-11-07 18:55:09 -08001622 mWindowManagerFuncs.registerPointerEventListener(mPointerLocationView);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001623 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001624 }
Jeff Brown70825162012-03-28 17:27:48 -07001625
1626 private void disablePointerLocation() {
Jeff Brown70825162012-03-28 17:27:48 -07001627 if (mPointerLocationView != null) {
Michael Wrightc9c487e2013-11-07 18:55:09 -08001628 mWindowManagerFuncs.unregisterPointerEventListener(mPointerLocationView);
1629 WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Brown70825162012-03-28 17:27:48 -07001630 wm.removeView(mPointerLocationView);
1631 mPointerLocationView = null;
1632 }
1633 }
1634
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001635 private int readRotation(int resID) {
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001636 try {
1637 int rotation = mContext.getResources().getInteger(resID);
1638 switch (rotation) {
1639 case 0:
1640 return Surface.ROTATION_0;
1641 case 90:
1642 return Surface.ROTATION_90;
1643 case 180:
1644 return Surface.ROTATION_180;
1645 case 270:
1646 return Surface.ROTATION_270;
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001647 }
1648 } catch (Resources.NotFoundException e) {
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001649 // fall through
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001650 }
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001651 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001652 }
1653
1654 /** {@inheritDoc} */
Craig Mautner88400d32012-09-30 12:35:45 -07001655 @Override
Dianne Hackbornc2293022013-02-06 23:14:49 -08001656 public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001657 int type = attrs.type;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001658
1659 outAppOp[0] = AppOpsManager.OP_NONE;
1660
Wale Ogunwale74bf0652015-01-12 10:24:36 -08001661 if (!((type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW)
1662 || (type >= FIRST_SUB_WINDOW && type <= LAST_SUB_WINDOW)
1663 || (type >= FIRST_SYSTEM_WINDOW && type <= LAST_SYSTEM_WINDOW))) {
1664 return WindowManagerGlobal.ADD_INVALID_TYPE;
1665 }
1666
1667 if (type < FIRST_SYSTEM_WINDOW || type > LAST_SYSTEM_WINDOW) {
1668 // Window manager will make sure these are okay.
Jeff Brown98365d72012-08-19 20:30:52 -07001669 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001670 }
1671 String permission = null;
1672 switch (type) {
1673 case TYPE_TOAST:
1674 // XXX right now the app process has complete control over
1675 // this... should introduce a token to let the system
1676 // monitor/control what they are doing.
Jason Monk1c7c3192014-06-26 12:52:18 -04001677 outAppOp[0] = AppOpsManager.OP_TOAST_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001678 break;
Daniel Sandler7d276c32012-01-30 14:33:52 -05001679 case TYPE_DREAM:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001680 case TYPE_INPUT_METHOD:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001681 case TYPE_WALLPAPER:
keunyounga446bf02013-06-21 19:07:57 -07001682 case TYPE_PRIVATE_PRESENTATION:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001683 case TYPE_VOICE_INTERACTION:
Svetoslav3a5c7212014-10-14 09:54:26 -07001684 case TYPE_ACCESSIBILITY_OVERLAY:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001685 // The window manager will check these.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001686 break;
1687 case TYPE_PHONE:
1688 case TYPE_PRIORITY_PHONE:
1689 case TYPE_SYSTEM_ALERT:
1690 case TYPE_SYSTEM_ERROR:
1691 case TYPE_SYSTEM_OVERLAY:
1692 permission = android.Manifest.permission.SYSTEM_ALERT_WINDOW;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001693 outAppOp[0] = AppOpsManager.OP_SYSTEM_ALERT_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001694 break;
1695 default:
1696 permission = android.Manifest.permission.INTERNAL_SYSTEM_WINDOW;
1697 }
1698 if (permission != null) {
1699 if (mContext.checkCallingOrSelfPermission(permission)
1700 != PackageManager.PERMISSION_GRANTED) {
Jeff Brown98365d72012-08-19 20:30:52 -07001701 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001702 }
1703 }
Jeff Brown98365d72012-08-19 20:30:52 -07001704 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001705 }
Craig Mautner88400d32012-09-30 12:35:45 -07001706
1707 @Override
1708 public boolean checkShowToOwnerOnly(WindowManager.LayoutParams attrs) {
1709
1710 // If this switch statement is modified, modify the comment in the declarations of
1711 // the type in {@link WindowManager.LayoutParams} as well.
1712 switch (attrs.type) {
1713 default:
1714 // These are the windows that by default are shown only to the user that created
1715 // them. If this needs to be overridden, set
1716 // {@link WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS} in
1717 // {@link WindowManager.LayoutParams}. Note that permission
1718 // {@link android.Manifest.permission.INTERNAL_SYSTEM_WINDOW} is required as well.
1719 if ((attrs.privateFlags & PRIVATE_FLAG_SHOW_FOR_ALL_USERS) == 0) {
1720 return true;
1721 }
1722 break;
1723
1724 // These are the windows that by default are shown to all users. However, to
1725 // protect against spoofing, check permissions below.
1726 case TYPE_APPLICATION_STARTING:
1727 case TYPE_BOOT_PROGRESS:
1728 case TYPE_DISPLAY_OVERLAY:
1729 case TYPE_HIDDEN_NAV_CONSUMER:
Jim Miller5ecd8112013-01-09 18:50:26 -08001730 case TYPE_KEYGUARD_SCRIM:
Craig Mautner88400d32012-09-30 12:35:45 -07001731 case TYPE_KEYGUARD_DIALOG:
1732 case TYPE_MAGNIFICATION_OVERLAY:
1733 case TYPE_NAVIGATION_BAR:
1734 case TYPE_NAVIGATION_BAR_PANEL:
1735 case TYPE_PHONE:
1736 case TYPE_POINTER:
1737 case TYPE_PRIORITY_PHONE:
Craig Mautner88400d32012-09-30 12:35:45 -07001738 case TYPE_SEARCH_BAR:
1739 case TYPE_STATUS_BAR:
1740 case TYPE_STATUS_BAR_PANEL:
1741 case TYPE_STATUS_BAR_SUB_PANEL:
1742 case TYPE_SYSTEM_DIALOG:
Craig Mautner88400d32012-09-30 12:35:45 -07001743 case TYPE_VOLUME_OVERLAY:
keunyounga446bf02013-06-21 19:07:57 -07001744 case TYPE_PRIVATE_PRESENTATION:
Craig Mautner88400d32012-09-30 12:35:45 -07001745 break;
1746 }
1747
1748 // Check if third party app has set window to system window type.
1749 return mContext.checkCallingOrSelfPermission(
1750 android.Manifest.permission.INTERNAL_SYSTEM_WINDOW)
1751 != PackageManager.PERMISSION_GRANTED;
1752 }
1753
Craig Mautner967212c2013-04-13 21:10:58 -07001754 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001755 public void adjustWindowParamsLw(WindowManager.LayoutParams attrs) {
1756 switch (attrs.type) {
1757 case TYPE_SYSTEM_OVERLAY:
Jeff Brown3b2b3542010-10-15 00:54:27 -07001758 case TYPE_SECURE_SYSTEM_OVERLAY:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001759 // These types of windows can't receive input events.
1760 attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1761 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001762 attrs.flags &= ~WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001763 break;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001764 case TYPE_STATUS_BAR:
1765
1766 // If the Keyguard is in a hidden state (occluded by another window), we force to
1767 // remove the wallpaper and keyguard flag so that any change in-flight after setting
1768 // the keyguard as occluded wouldn't set these flags again.
1769 // See {@link #processKeyguardSetHiddenResultLw}.
1770 if (mKeyguardHidden) {
1771 attrs.flags &= ~WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
1772 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
1773 }
1774 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001775 }
Adrian Roos38502112014-04-09 21:04:11 +02001776
1777 if (attrs.type != TYPE_STATUS_BAR) {
1778 // The status bar is the only window allowed to exhibit keyguard behavior.
1779 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
1780 }
Adrian Roosea562512014-05-05 13:33:03 +02001781
1782 if (ActivityManager.isHighEndGfx()
1783 && (attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0) {
Adrian Roosf5e9b5c2014-09-10 15:27:41 +02001784 attrs.subtreeSystemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
Adrian Roosea562512014-05-05 13:33:03 +02001785 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
1786 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001787 }
RoboErik8a2cfc32014-05-16 11:19:38 -07001788
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001789 void readLidState() {
Jeff Brown2e7760e2012-04-11 15:14:55 -07001790 mLidState = mWindowManagerFuncs.getLidState();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001791 }
RoboErik8a2cfc32014-05-16 11:19:38 -07001792
Michael Wright3818c922014-09-02 13:59:07 -07001793 private void readCameraLensCoverState() {
1794 mCameraLensCoverState = mWindowManagerFuncs.getCameraLensCoverState();
1795 }
1796
Jeff Browndaa37532012-05-01 15:54:03 -07001797 private boolean isHidden(int accessibilityMode) {
1798 switch (accessibilityMode) {
1799 case 1:
1800 return mLidState == LID_CLOSED;
1801 case 2:
1802 return mLidState == LID_OPEN;
1803 default:
1804 return false;
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001805 }
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001806 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001807
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001808 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07001809 @Override
Jeff Browndaa37532012-05-01 15:54:03 -07001810 public void adjustConfigurationLw(Configuration config, int keyboardPresence,
1811 int navigationPresence) {
1812 mHaveBuiltInKeyboard = (keyboardPresence & PRESENCE_INTERNAL) != 0;
1813
Jeff Brownf71343d2013-05-31 17:59:11 -07001814 readConfigurationDependentBehaviors();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001815 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07001816 applyLidSwitchState();
Jeff Brownd04a88c2011-01-16 14:05:47 -08001817
Jeff Browndaa37532012-05-01 15:54:03 -07001818 if (config.keyboard == Configuration.KEYBOARD_NOKEYS
1819 || (keyboardPresence == PRESENCE_INTERNAL
1820 && isHidden(mLidKeyboardAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001821 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_YES;
Jeff Browndaa37532012-05-01 15:54:03 -07001822 if (!mHasSoftInput) {
1823 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_YES;
1824 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001825 }
1826
Jeff Browndaa37532012-05-01 15:54:03 -07001827 if (config.navigation == Configuration.NAVIGATION_NONAV
1828 || (navigationPresence == PRESENCE_INTERNAL
1829 && isHidden(mLidNavigationAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001830 config.navigationHidden = Configuration.NAVIGATIONHIDDEN_YES;
Jeff Brownd04a88c2011-01-16 14:05:47 -08001831 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001832 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001833
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001834 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07001835 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001836 public int windowTypeToLayerLw(int type) {
1837 if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001838 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001839 }
1840 switch (type) {
keunyounga446bf02013-06-21 19:07:57 -07001841 case TYPE_PRIVATE_PRESENTATION:
1842 return 2;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001843 case TYPE_WALLPAPER:
1844 // wallpaper is at the bottom, though the window manager may move it.
1845 return 2;
1846 case TYPE_PHONE:
1847 return 3;
1848 case TYPE_SEARCH_BAR:
1849 return 4;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001850 case TYPE_VOICE_INTERACTION:
1851 // voice interaction layer is almost immediately above apps.
1852 return 5;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001853 case TYPE_SYSTEM_DIALOG:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001854 return 6;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001855 case TYPE_TOAST:
1856 // toasts and the plugged-in battery thing
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001857 return 7;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001858 case TYPE_PRIORITY_PHONE:
1859 // SIM errors and unlock. Not sure if this really should be in a high layer.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001860 return 8;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001861 case TYPE_DREAM:
1862 // used for Dreams (screensavers with TYPE_DREAM windows)
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001863 return 9;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001864 case TYPE_SYSTEM_ALERT:
1865 // like the ANR / app crashed dialogs
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001866 return 10;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001867 case TYPE_INPUT_METHOD:
1868 // on-screen keyboards and other such input method user interfaces go here.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001869 return 11;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001870 case TYPE_INPUT_METHOD_DIALOG:
1871 // on-screen keyboards and other such input method user interfaces go here.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001872 return 12;
Jim Miller5ecd8112013-01-09 18:50:26 -08001873 case TYPE_KEYGUARD_SCRIM:
1874 // the safety window that shows behind keyguard while keyguard is starting
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001875 return 13;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001876 case TYPE_STATUS_BAR_SUB_PANEL:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001877 return 14;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001878 case TYPE_STATUS_BAR:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001879 return 15;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001880 case TYPE_STATUS_BAR_PANEL:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001881 return 16;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001882 case TYPE_KEYGUARD_DIALOG:
1883 return 17;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001884 case TYPE_VOLUME_OVERLAY:
1885 // the on-screen volume indicator and controller shown when the user
1886 // changes the device volume
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001887 return 18;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001888 case TYPE_SYSTEM_OVERLAY:
1889 // the on-screen volume indicator and controller shown when the user
1890 // changes the device volume
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001891 return 19;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001892 case TYPE_NAVIGATION_BAR:
1893 // the navigation bar, if available, shows atop most things
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001894 return 20;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001895 case TYPE_NAVIGATION_BAR_PANEL:
1896 // some panels (e.g. search) need to show on top of the navigation bar
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001897 return 21;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001898 case TYPE_SYSTEM_ERROR:
1899 // system-level error dialogs
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001900 return 22;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001901 case TYPE_MAGNIFICATION_OVERLAY:
1902 // used to highlight the magnified portion of a display
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001903 return 23;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001904 case TYPE_DISPLAY_OVERLAY:
1905 // used to simulate secondary display devices
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001906 return 24;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001907 case TYPE_DRAG:
1908 // the drag layer: input for drag-and-drop is associated with this window,
1909 // which sits above all other focusable windows
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001910 return 25;
Svetoslav3a5c7212014-10-14 09:54:26 -07001911 case TYPE_ACCESSIBILITY_OVERLAY:
1912 // overlay put by accessibility services to intercept user interaction
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001913 return 26;
Svetoslav3a5c7212014-10-14 09:54:26 -07001914 case TYPE_SECURE_SYSTEM_OVERLAY:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001915 return 27;
Svetoslav3a5c7212014-10-14 09:54:26 -07001916 case TYPE_BOOT_PROGRESS:
1917 return 28;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001918 case TYPE_POINTER:
1919 // the (mouse) pointer layer
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001920 return 29;
Svetoslav3a5c7212014-10-14 09:54:26 -07001921 case TYPE_HIDDEN_NAV_CONSUMER:
1922 return 30;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001923 }
1924 Log.e(TAG, "Unknown window type: " + type);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001925 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001926 }
1927
1928 /** {@inheritDoc} */
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001929 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001930 public int subWindowTypeToLayerLw(int type) {
1931 switch (type) {
1932 case TYPE_APPLICATION_PANEL:
1933 case TYPE_APPLICATION_ATTACHED_DIALOG:
1934 return APPLICATION_PANEL_SUBLAYER;
1935 case TYPE_APPLICATION_MEDIA:
1936 return APPLICATION_MEDIA_SUBLAYER;
Dianne Hackborn5cb8d792009-05-21 17:34:15 -07001937 case TYPE_APPLICATION_MEDIA_OVERLAY:
1938 return APPLICATION_MEDIA_OVERLAY_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001939 case TYPE_APPLICATION_SUB_PANEL:
1940 return APPLICATION_SUB_PANEL_SUBLAYER;
1941 }
1942 Log.e(TAG, "Unknown sub-window type: " + type);
1943 return 0;
1944 }
1945
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001946 @Override
Dianne Hackbornabe0da02009-09-18 01:55:39 -07001947 public int getMaxWallpaperLayer() {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001948 return windowTypeToLayerLw(TYPE_STATUS_BAR);
Dianne Hackbornabe0da02009-09-18 01:55:39 -07001949 }
1950
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001951 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001952 public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07001953 if (mHasNavigationBar) {
1954 // For a basic navigation bar, when we are in landscape mode we place
1955 // the navigation bar to the side.
Daniel Sandler4a066c52012-04-20 14:49:13 -04001956 if (mNavigationBarCanMove && fullWidth > fullHeight) {
1957 return fullWidth - mNavigationBarWidthForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07001958 }
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001959 }
1960 return fullWidth;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001961 }
1962
Jose Lima9546b202014-07-02 17:21:51 -07001963 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001964 public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07001965 if (mHasNavigationBar) {
1966 // For a basic navigation bar, when we are in portrait mode we place
1967 // the navigation bar to the bottom.
Daniel Sandler4a066c52012-04-20 14:49:13 -04001968 if (!mNavigationBarCanMove || fullWidth < fullHeight) {
1969 return fullHeight - mNavigationBarHeightForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07001970 }
1971 }
1972 return fullHeight;
Dianne Hackborn69cb8752011-05-19 18:13:32 -07001973 }
1974
Jose Lima9546b202014-07-02 17:21:51 -07001975 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001976 public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation) {
1977 return getNonDecorDisplayWidth(fullWidth, fullHeight, rotation);
Dianne Hackborn69cb8752011-05-19 18:13:32 -07001978 }
1979
Jose Lima9546b202014-07-02 17:21:51 -07001980 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001981 public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation) {
John Spurlock80f00c12013-06-13 11:10:51 -04001982 // There is a separate status bar at the top of the display. We don't count that as part
1983 // of the fixed decor, since it can hide; however, for purposes of configurations,
Dianne Hackborn077ee852012-04-09 16:27:07 -07001984 // we do want to exclude it since applications can't generally use that part
1985 // of the screen.
John Spurlock80f00c12013-06-13 11:10:51 -04001986 return getNonDecorDisplayHeight(fullWidth, fullHeight, rotation) - mStatusBarHeight;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001987 }
1988
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001989 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07001990 public boolean isForceHiding(WindowManager.LayoutParams attrs) {
1991 return (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 ||
Jim Millerab954542014-10-10 18:21:49 -07001992 (isKeyguardHostWindow(attrs) &&
1993 (mKeyguardDelegate != null && mKeyguardDelegate.isShowing())) ||
Adrian Roos69e510d2014-07-13 14:57:59 +02001994 (attrs.type == TYPE_KEYGUARD_SCRIM);
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07001995 }
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001996
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001997 @Override
Jorim Jaggi0d674622014-05-21 01:34:15 +02001998 public boolean isKeyguardHostWindow(WindowManager.LayoutParams attrs) {
1999 return attrs.type == TYPE_STATUS_BAR;
2000 }
2001
2002 @Override
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002003 public boolean canBeForceHidden(WindowState win, WindowManager.LayoutParams attrs) {
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002004 switch (attrs.type) {
2005 case TYPE_STATUS_BAR:
2006 case TYPE_NAVIGATION_BAR:
2007 case TYPE_WALLPAPER:
2008 case TYPE_DREAM:
Jim Miller5ecd8112013-01-09 18:50:26 -08002009 case TYPE_KEYGUARD_SCRIM:
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002010 return false;
2011 default:
2012 return true;
2013 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002014 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002015
Craig Mautner7d7808f2014-09-11 18:02:38 -07002016 @Override
2017 public WindowState getWinShowWhenLockedLw() {
2018 return mWinShowWhenLocked;
2019 }
2020
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002021 /** {@inheritDoc} */
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002022 @Override
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07002023 public View addStartingWindow(IBinder appToken, String packageName, int theme,
2024 CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes,
Adam Powell04fe6eb2013-05-31 14:39:48 -07002025 int icon, int logo, int windowFlags) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002026 if (!SHOW_STARTING_ANIMATIONS) {
2027 return null;
2028 }
2029 if (packageName == null) {
2030 return null;
2031 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002032
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002033 WindowManager wm = null;
2034 View view = null;
2035
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002036 try {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002037 Context context = mContext;
Craig Mautner6fbda632012-07-03 09:26:39 -07002038 if (DEBUG_STARTING_WINDOW) Slog.d(TAG, "addStartingWindow " + packageName
2039 + ": nonLocalizedLabel=" + nonLocalizedLabel + " theme="
2040 + Integer.toHexString(theme));
Dianne Hackborn247fe742011-01-08 17:25:57 -08002041 if (theme != context.getThemeResId() || labelRes != 0) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002042 try {
2043 context = context.createPackageContext(packageName, 0);
Dianne Hackborn247fe742011-01-08 17:25:57 -08002044 context.setTheme(theme);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002045 } catch (PackageManager.NameNotFoundException e) {
2046 // Ignore
2047 }
2048 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002049
Jorim Jaggib10e33f2015-02-04 21:57:40 +01002050 Window win = new PhoneWindow(context);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002051 final TypedArray ta = win.getWindowStyle();
2052 if (ta.getBoolean(
2053 com.android.internal.R.styleable.Window_windowDisablePreview, false)
2054 || ta.getBoolean(
2055 com.android.internal.R.styleable.Window_windowShowWallpaper,false)) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002056 return null;
2057 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002058
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002059 Resources r = context.getResources();
2060 win.setTitle(r.getText(labelRes, nonLocalizedLabel));
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002061
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002062 win.setType(
2063 WindowManager.LayoutParams.TYPE_APPLICATION_STARTING);
2064 // Force the window flags: this is a fake window, so it is not really
2065 // touchable or focusable by the user. We also add in the ALT_FOCUSABLE_IM
2066 // flag because we do know that the next window will take input
2067 // focus, so we want to get the IME window up on top of us right away.
2068 win.setFlags(
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08002069 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002070 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
2071 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
2072 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08002073 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002074 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
2075 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
2076 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002077
Adam Powell04fe6eb2013-05-31 14:39:48 -07002078 win.setDefaultIcon(icon);
2079 win.setDefaultLogo(logo);
2080
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002081 win.setLayout(WindowManager.LayoutParams.MATCH_PARENT,
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07002082 WindowManager.LayoutParams.MATCH_PARENT);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002083
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002084 final WindowManager.LayoutParams params = win.getAttributes();
2085 params.token = appToken;
2086 params.packageName = packageName;
2087 params.windowAnimations = win.getWindowStyle().getResourceId(
2088 com.android.internal.R.styleable.Window_windowAnimationStyle, 0);
John Reck61375a82014-09-18 19:27:48 +00002089 params.privateFlags |=
2090 WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED;
Craig Mautner88400d32012-09-30 12:35:45 -07002091 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
Adam Lesinski95c42972013-10-02 10:13:27 -07002092
2093 if (!compatInfo.supportsScreen()) {
2094 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
2095 }
2096
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002097 params.setTitle("Starting " + packageName);
2098
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002099 wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
2100 view = win.getDecorView();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002101
2102 if (win.isFloating()) {
2103 // Whoops, there is no way to display an animation/preview
2104 // of such a thing! After all that work... let's skip it.
2105 // (Note that we must do this here because it is in
2106 // getDecorView() where the theme is evaluated... maybe
2107 // we should peek the floating attribute from the theme
2108 // earlier.)
2109 return null;
2110 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002111
Craig Mautner6fbda632012-07-03 09:26:39 -07002112 if (DEBUG_STARTING_WINDOW) Slog.d(
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002113 TAG, "Adding starting window for " + packageName
2114 + " / " + appToken + ": "
2115 + (view.getParent() != null ? view : null));
2116
2117 wm.addView(view, params);
2118
2119 // Only return the view if it was successfully added to the
2120 // window manager... which we can tell by it having a parent.
2121 return view.getParent() != null ? view : null;
Jeff Brown98365d72012-08-19 20:30:52 -07002122 } catch (WindowManager.BadTokenException e) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002123 // ignore
Craig Mautner42bf39e2014-02-21 16:46:22 -08002124 Log.w(TAG, appToken + " already running, starting window not displayed. " +
2125 e.getMessage());
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002126 } catch (RuntimeException e) {
2127 // don't crash if something else bad happens, for example a
2128 // failure loading resources because we are loading from an app
2129 // on external storage that has been unmounted.
2130 Log.w(TAG, appToken + " failed creating starting window", e);
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002131 } finally {
2132 if (view != null && view.getParent() == null) {
2133 Log.w(TAG, "view not successfully added to wm, removing view");
2134 wm.removeViewImmediate(view);
2135 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002136 }
2137
2138 return null;
2139 }
2140
2141 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07002142 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002143 public void removeStartingWindow(IBinder appToken, View window) {
Craig Mautner276a6eb2014-11-04 15:32:57 -08002144 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Removing starting window for " + appToken + ": "
2145 + window + " Callers=" + Debug.getCallers(4));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002146
2147 if (window != null) {
Dianne Hackborn5fd21692011-06-07 14:09:47 -07002148 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002149 wm.removeView(window);
2150 }
2151 }
2152
2153 /**
2154 * Preflight adding a window to the system.
RoboErik8a2cfc32014-05-16 11:19:38 -07002155 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002156 * Currently enforces that three window types are singletons:
2157 * <ul>
2158 * <li>STATUS_BAR_TYPE</li>
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002159 * <li>KEYGUARD_TYPE</li>
2160 * </ul>
RoboErik8a2cfc32014-05-16 11:19:38 -07002161 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002162 * @param win The window to be added
2163 * @param attrs Information about the window to be added
RoboErik8a2cfc32014-05-16 11:19:38 -07002164 *
Jeff Brown98365d72012-08-19 20:30:52 -07002165 * @return If ok, WindowManagerImpl.ADD_OKAY. If too many singletons,
2166 * WindowManagerImpl.ADD_MULTIPLE_SINGLETON
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002167 */
Jose Lima9546b202014-07-02 17:21:51 -07002168 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002169 public int prepareAddWindowLw(WindowState win, WindowManager.LayoutParams attrs) {
2170 switch (attrs.type) {
2171 case TYPE_STATUS_BAR:
Joe Onorato8bc6c512010-06-04 16:21:12 -04002172 mContext.enforceCallingOrSelfPermission(
2173 android.Manifest.permission.STATUS_BAR_SERVICE,
2174 "PhoneWindowManager");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002175 if (mStatusBar != null) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002176 if (mStatusBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07002177 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002178 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002179 }
2180 mStatusBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04002181 mStatusBarController.setWindow(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002182 break;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002183 case TYPE_NAVIGATION_BAR:
2184 mContext.enforceCallingOrSelfPermission(
2185 android.Manifest.permission.STATUS_BAR_SERVICE,
2186 "PhoneWindowManager");
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002187 if (mNavigationBar != null) {
2188 if (mNavigationBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07002189 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002190 }
2191 }
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002192 mNavigationBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04002193 mNavigationBarController.setWindow(win);
Craig Mautnereda67292013-04-28 13:50:14 -07002194 if (DEBUG_LAYOUT) Slog.i(TAG, "NAVIGATION BAR: " + mNavigationBar);
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002195 break;
Jim Millere898ac52012-04-06 17:10:57 -07002196 case TYPE_NAVIGATION_BAR_PANEL:
2197 mContext.enforceCallingOrSelfPermission(
2198 android.Manifest.permission.STATUS_BAR_SERVICE,
2199 "PhoneWindowManager");
2200 break;
Dianne Hackborn08743722009-12-21 12:16:51 -08002201 case TYPE_STATUS_BAR_PANEL:
Joe Onorato8bc6c512010-06-04 16:21:12 -04002202 mContext.enforceCallingOrSelfPermission(
2203 android.Manifest.permission.STATUS_BAR_SERVICE,
2204 "PhoneWindowManager");
Dianne Hackborn08743722009-12-21 12:16:51 -08002205 break;
Joe Onorato29fc2c92010-11-24 10:26:50 -08002206 case TYPE_STATUS_BAR_SUB_PANEL:
2207 mContext.enforceCallingOrSelfPermission(
2208 android.Manifest.permission.STATUS_BAR_SERVICE,
2209 "PhoneWindowManager");
Joe Onorato29fc2c92010-11-24 10:26:50 -08002210 break;
Jim Miller5ecd8112013-01-09 18:50:26 -08002211 case TYPE_KEYGUARD_SCRIM:
Jim Miller25190572013-02-28 17:36:24 -08002212 if (mKeyguardScrim != null) {
2213 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
2214 }
Jim Miller5ecd8112013-01-09 18:50:26 -08002215 mKeyguardScrim = win;
2216 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002217 }
Jeff Brown98365d72012-08-19 20:30:52 -07002218 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002219 }
2220
2221 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07002222 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002223 public void removeWindowLw(WindowState win) {
2224 if (mStatusBar == win) {
2225 mStatusBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04002226 mStatusBarController.setWindow(null);
Jim Millerc0b676d2013-03-22 16:11:08 -07002227 mKeyguardDelegate.showScrim();
Jim Miller5ecd8112013-01-09 18:50:26 -08002228 } else if (mKeyguardScrim == win) {
2229 Log.v(TAG, "Removing keyguard scrim");
2230 mKeyguardScrim = null;
2231 } if (mNavigationBar == win) {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002232 mNavigationBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04002233 mNavigationBarController.setWindow(null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002234 }
2235 }
2236
2237 static final boolean PRINT_ANIM = false;
RoboErik8a2cfc32014-05-16 11:19:38 -07002238
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002239 /** {@inheritDoc} */
Craig Mautner4b71aa12012-12-27 17:20:01 -08002240 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002241 public int selectAnimationLw(WindowState win, int transit) {
2242 if (PRINT_ANIM) Log.i(TAG, "selectAnimation in " + win
2243 + ": transit=" + transit);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002244 if (win == mStatusBar) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002245 boolean isKeyguard = (win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002246 if (transit == TRANSIT_EXIT
2247 || transit == TRANSIT_HIDE) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002248 return isKeyguard ? -1 : R.anim.dock_top_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002249 } else if (transit == TRANSIT_ENTER
2250 || transit == TRANSIT_SHOW) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002251 return isKeyguard ? -1 : R.anim.dock_top_enter;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002252 }
2253 } else if (win == mNavigationBar) {
2254 // This can be on either the bottom or the right.
2255 if (mNavigationBarOnBottom) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08002256 if (transit == TRANSIT_EXIT
2257 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002258 return R.anim.dock_bottom_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002259 } else if (transit == TRANSIT_ENTER
2260 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002261 return R.anim.dock_bottom_enter;
2262 }
2263 } else {
Craig Mautner4b71aa12012-12-27 17:20:01 -08002264 if (transit == TRANSIT_EXIT
2265 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002266 return R.anim.dock_right_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002267 } else if (transit == TRANSIT_ENTER
2268 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002269 return R.anim.dock_right_enter;
2270 }
2271 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08002272 }
2273
2274 if (transit == TRANSIT_PREVIEW_DONE) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002275 if (win.hasAppShownWindows()) {
2276 if (PRINT_ANIM) Log.i(TAG, "**** STARTING EXIT");
2277 return com.android.internal.R.anim.app_starting_exit;
2278 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07002279 } else if (win.getAttrs().type == TYPE_DREAM && mDreamingLockscreen
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002280 && transit == TRANSIT_ENTER) {
2281 // Special case: we are animating in a dream, while the keyguard
2282 // is shown. We don't want an animation on the dream, because
2283 // we need it shown immediately with the keyguard animating away
2284 // to reveal it.
2285 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002286 }
2287
2288 return 0;
2289 }
2290
Craig Mautner3c174372013-02-21 17:54:37 -08002291 @Override
2292 public void selectRotationAnimationLw(int anim[]) {
2293 if (PRINT_ANIM) Slog.i(TAG, "selectRotationAnimation mTopFullscreen="
2294 + mTopFullscreenOpaqueWindowState + " rotationAnimation="
2295 + (mTopFullscreenOpaqueWindowState == null ?
2296 "0" : mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation));
2297 if (mTopFullscreenOpaqueWindowState != null && mTopIsFullscreen) {
2298 switch (mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation) {
2299 case ROTATION_ANIMATION_CROSSFADE:
2300 anim[0] = R.anim.rotation_animation_xfade_exit;
2301 anim[1] = R.anim.rotation_animation_enter;
2302 break;
2303 case ROTATION_ANIMATION_JUMPCUT:
2304 anim[0] = R.anim.rotation_animation_jump_exit;
2305 anim[1] = R.anim.rotation_animation_enter;
2306 break;
2307 case ROTATION_ANIMATION_ROTATE:
2308 default:
2309 anim[0] = anim[1] = 0;
2310 break;
2311 }
2312 } else {
2313 anim[0] = anim[1] = 0;
2314 }
2315 }
2316
2317 @Override
2318 public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId,
2319 boolean forceDefault) {
2320 switch (exitAnimId) {
2321 case R.anim.rotation_animation_xfade_exit:
2322 case R.anim.rotation_animation_jump_exit:
2323 // These are the only cases that matter.
2324 if (forceDefault) {
2325 return false;
2326 }
2327 int anim[] = new int[2];
2328 selectRotationAnimationLw(anim);
2329 return (exitAnimId == anim[0] && enterAnimId == anim[1]);
2330 default:
2331 return true;
2332 }
2333 }
2334
2335 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002336 public Animation createForceHideEnterAnimation(boolean onWallpaper,
2337 boolean goingToNotificationShade) {
2338 if (goingToNotificationShade) {
2339 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_behind_enter_fade_in);
Craig Mautnerb8340802014-11-04 15:32:57 -08002340 }
Craig Mautner276a6eb2014-11-04 15:32:57 -08002341
2342 AnimationSet set = (AnimationSet) AnimationUtils.loadAnimation(mContext, onWallpaper ?
2343 R.anim.lock_screen_behind_enter_wallpaper :
2344 R.anim.lock_screen_behind_enter);
2345
2346 // TODO: Use XML interpolators when we have log interpolators available in XML.
2347 final List<Animation> animations = set.getAnimations();
2348 for (int i = animations.size() - 1; i >= 0; --i) {
2349 animations.get(i).setInterpolator(mLogDecelerateInterpolator);
2350 }
2351
2352 return set;
Jorim Jaggi76a16232014-08-08 17:00:47 +02002353 }
2354
2355
2356 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002357 public Animation createForceHideWallpaperExitAnimation(boolean goingToNotificationShade) {
2358 if (goingToNotificationShade) {
2359 return null;
2360 } else {
2361 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_wallpaper_exit);
2362 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002363 }
John Spurlockc8b46ca2013-04-08 12:59:26 -04002364
2365 private static void awakenDreams() {
2366 IDreamManager dreamManager = getDreamManager();
2367 if (dreamManager != null) {
2368 try {
2369 dreamManager.awaken();
2370 } catch (RemoteException e) {
2371 // fine, stay asleep then
2372 }
2373 }
2374 }
2375
2376 static IDreamManager getDreamManager() {
2377 return IDreamManager.Stub.asInterface(
2378 ServiceManager.checkService(DreamService.DREAM_SERVICE));
2379 }
2380
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002381 TelecomManager getTelecommService() {
2382 return (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002383 }
2384
Jeff Brown4d396052010-10-29 21:50:21 -07002385 static IAudioService getAudioService() {
2386 IAudioService audioService = IAudioService.Stub.asInterface(
2387 ServiceManager.checkService(Context.AUDIO_SERVICE));
2388 if (audioService == null) {
2389 Log.w(TAG, "Unable to find IAudioService interface.");
2390 }
2391 return audioService;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002392 }
2393
2394 boolean keyguardOn() {
Jim Millerab954542014-10-10 18:21:49 -07002395 return isKeyguardShowingAndNotOccluded() || inKeyguardRestrictedKeyInputMode();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002396 }
2397
2398 private static final int[] WINDOW_TYPES_WHERE_HOME_DOESNT_WORK = {
2399 WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
2400 WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
2401 };
2402
2403 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002404 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002405 public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002406 final boolean keyguardOn = keyguardOn();
Jeff Brown1f245102010-11-18 20:53:46 -08002407 final int keyCode = event.getKeyCode();
2408 final int repeatCount = event.getRepeatCount();
2409 final int metaState = event.getMetaState();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002410 final int flags = event.getFlags();
Jeff Brown1f245102010-11-18 20:53:46 -08002411 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
2412 final boolean canceled = event.isCanceled();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002413
Jeff Brown40013652012-05-16 21:22:36 -07002414 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002415 Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount="
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002416 + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed
2417 + " canceled=" + canceled);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002418 }
2419
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002420 // If we think we might have a volume down & power key chord on the way
2421 // but we're not sure, then tell the dispatcher to wait a little while and
2422 // try again later before dispatching.
Christopher Tatee90585f2012-03-05 18:56:25 -08002423 if (mScreenshotChordEnabled && (flags & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07002424 if (mScreenshotChordVolumeDownKeyTriggered && !mScreenshotChordPowerKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002425 final long now = SystemClock.uptimeMillis();
Jeff Brown13f00f02014-10-31 14:45:50 -07002426 final long timeoutTime = mScreenshotChordVolumeDownKeyTime
2427 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002428 if (now < timeoutTime) {
2429 return timeoutTime - now;
2430 }
2431 }
2432 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
Jeff Brown13f00f02014-10-31 14:45:50 -07002433 && mScreenshotChordVolumeDownKeyConsumed) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002434 if (!down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07002435 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002436 }
2437 return -1;
2438 }
2439 }
2440
Michael Wright6a62e552014-06-03 19:19:48 -07002441 // Cancel any pending meta actions if we see any other keys being pressed between the down
2442 // of the meta key and its corresponding up.
Michael Wright251e35d2014-08-22 15:40:27 -07002443 if (mPendingMetaAction && !KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07002444 mPendingMetaAction = false;
2445 }
2446
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002447 // First we always handle the home key here, so applications
2448 // can never break it, although if keyguard is on, we do let
2449 // it handle it, because that gives us the correct 5 second
2450 // timeout.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002451 if (keyCode == KeyEvent.KEYCODE_HOME) {
Michael Jurka7f2668c2012-03-27 07:49:52 -07002452
Jeff Brown49ed71d2010-12-06 17:13:33 -08002453 // If we have released the home key, and didn't do anything else
2454 // while it was pressed, then it is time to go home!
Michael Jurka7f2668c2012-03-27 07:49:52 -07002455 if (!down) {
Jeff Browncaca8812013-05-09 13:34:33 -07002456 cancelPreloadRecentApps();
2457
Jeff Brown49ed71d2010-12-06 17:13:33 -08002458 mHomePressed = false;
Jeff Browncaca8812013-05-09 13:34:33 -07002459 if (mHomeConsumed) {
2460 mHomeConsumed = false;
Michael Jurka7f2668c2012-03-27 07:49:52 -07002461 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002462 }
Jeff Browncaca8812013-05-09 13:34:33 -07002463
2464 if (canceled) {
2465 Log.i(TAG, "Ignoring HOME; event canceled.");
2466 return -1;
2467 }
2468
Yorke Lee4f803242014-12-15 23:22:06 +00002469 // If an incoming call is ringing, HOME is totally disabled.
2470 // (The user is already on the InCallUI at this point,
2471 // and his ONLY options are to answer or reject the call.)
2472 TelecomManager telecomManager = getTelecommService();
2473 if (telecomManager != null && telecomManager.isRinging()) {
2474 Log.i(TAG, "Ignoring HOME; there's a ringing incoming call.");
2475 return -1;
2476 }
2477
Jeff Browncaca8812013-05-09 13:34:33 -07002478 // Delay handling home if a double-tap is possible.
2479 if (mDoubleTapOnHomeBehavior != DOUBLE_TAP_HOME_NOTHING) {
2480 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); // just in case
2481 mHomeDoubleTapPending = true;
2482 mHandler.postDelayed(mHomeDoubleTapTimeoutRunnable,
2483 ViewConfiguration.getDoubleTapTimeout());
2484 return -1;
2485 }
2486
Jeff Brown13f00f02014-10-31 14:45:50 -07002487 handleShortPressOnHome();
Jeff Browncaca8812013-05-09 13:34:33 -07002488 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002489 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002490
2491 // If a system window has focus, then it doesn't make sense
2492 // right now to interact with applications.
2493 WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null;
2494 if (attrs != null) {
2495 final int type = attrs.type;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002496 if (type == WindowManager.LayoutParams.TYPE_KEYGUARD_SCRIM
2497 || type == WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG
2498 || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002499 // the "app" is keyguard, so give it the key
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002500 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002501 }
2502 final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length;
2503 for (int i=0; i<typeCount; i++) {
2504 if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) {
2505 // don't do anything, but also don't pass it to the app
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002506 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002507 }
2508 }
2509 }
Jeff Browncaca8812013-05-09 13:34:33 -07002510
2511 // Remember that home is pressed and handle special actions.
2512 if (repeatCount == 0) {
2513 mHomePressed = true;
2514 if (mHomeDoubleTapPending) {
2515 mHomeDoubleTapPending = false;
2516 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable);
2517 handleDoubleTapOnHome();
2518 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI
2519 || mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
2520 preloadRecentApps();
Michael Jurka7f2668c2012-03-27 07:49:52 -07002521 }
Jeff Browncaca8812013-05-09 13:34:33 -07002522 } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) {
2523 if (!keyguardOn) {
2524 handleLongPressOnHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002525 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002526 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002527 return -1;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002528 } else if (keyCode == KeyEvent.KEYCODE_MENU) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002529 // Hijack modified menu keys for debugging features
2530 final int chordBug = KeyEvent.META_SHIFT_ON;
2531
2532 if (down && repeatCount == 0) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002533 if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002534 Intent intent = new Intent(Intent.ACTION_BUG_REPORT);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002535 mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT,
2536 null, null, null, 0, null, null);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002537 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002538 } else if (SHOW_PROCESSES_ON_ALT_MENU &&
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002539 (metaState & KeyEvent.META_ALT_ON) == KeyEvent.META_ALT_ON) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002540 Intent service = new Intent();
2541 service.setClassName(mContext, "com.android.server.LoadAverageService");
2542 ContentResolver res = mContext.getContentResolver();
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002543 boolean shown = Settings.Global.getInt(
2544 res, Settings.Global.SHOW_PROCESSES, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002545 if (!shown) {
2546 mContext.startService(service);
2547 } else {
2548 mContext.stopService(service);
2549 }
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002550 Settings.Global.putInt(
2551 res, Settings.Global.SHOW_PROCESSES, shown ? 0 : 1);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002552 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002553 }
2554 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002555 } else if (keyCode == KeyEvent.KEYCODE_SEARCH) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002556 if (down) {
2557 if (repeatCount == 0) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002558 mSearchKeyShortcutPending = true;
2559 mConsumeSearchKeyUp = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002560 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002561 } else {
2562 mSearchKeyShortcutPending = false;
2563 if (mConsumeSearchKeyUp) {
2564 mConsumeSearchKeyUp = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002565 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002566 }
2567 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002568 return 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002569 } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) {
Michael Wrightc9ebea72013-01-16 19:25:02 -08002570 if (!keyguardOn) {
Jeff Browncaca8812013-05-09 13:34:33 -07002571 if (down && repeatCount == 0) {
2572 preloadRecentApps();
2573 } else if (!down) {
2574 toggleRecentApps();
Michael Wrightc9ebea72013-01-16 19:25:02 -08002575 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002576 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002577 return -1;
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002578 } else if (keyCode == KeyEvent.KEYCODE_ASSIST) {
2579 if (down) {
2580 if (repeatCount == 0) {
2581 mAssistKeyLongPressed = false;
2582 } else if (repeatCount == 1) {
2583 mAssistKeyLongPressed = true;
2584 if (!keyguardOn) {
2585 launchAssistLongPressAction();
2586 }
2587 }
2588 } else {
2589 if (mAssistKeyLongPressed) {
2590 mAssistKeyLongPressed = false;
2591 } else {
2592 if (!keyguardOn) {
2593 launchAssistAction();
2594 }
2595 }
2596 }
2597 return -1;
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002598 } else if (keyCode == KeyEvent.KEYCODE_VOICE_ASSIST) {
2599 if (!down) {
2600 Intent voiceIntent;
Michael Wright869a67c2014-08-26 19:33:06 -07002601 if (!keyguardOn) {
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002602 voiceIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
2603 } else {
2604 voiceIntent = new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
Michael Wright869a67c2014-08-26 19:33:06 -07002605 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, true);
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002606 }
2607 mContext.startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
2608 }
Jeff Sharkey2991fa32012-12-05 18:06:43 -08002609 } else if (keyCode == KeyEvent.KEYCODE_SYSRQ) {
2610 if (down && repeatCount == 0) {
2611 mHandler.post(mScreenshotRunnable);
2612 }
2613 return -1;
Michael Wrightb854e242013-02-05 17:54:02 -08002614 } else if (keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP
2615 || keyCode == KeyEvent.KEYCODE_BRIGHTNESS_DOWN) {
2616 if (down) {
2617 int direction = keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP ? 1 : -1;
2618
2619 // Disable autobrightness if it's on
2620 int auto = Settings.System.getIntForUser(
2621 mContext.getContentResolver(),
2622 Settings.System.SCREEN_BRIGHTNESS_MODE,
2623 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2624 UserHandle.USER_CURRENT_OR_SELF);
2625 if (auto != 0) {
2626 Settings.System.putIntForUser(mContext.getContentResolver(),
2627 Settings.System.SCREEN_BRIGHTNESS_MODE,
2628 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2629 UserHandle.USER_CURRENT_OR_SELF);
2630 }
2631
2632 int min = mPowerManager.getMinimumScreenBrightnessSetting();
2633 int max = mPowerManager.getMaximumScreenBrightnessSetting();
2634 int step = (max - min + BRIGHTNESS_STEPS - 1) / BRIGHTNESS_STEPS * direction;
2635 int brightness = Settings.System.getIntForUser(mContext.getContentResolver(),
2636 Settings.System.SCREEN_BRIGHTNESS,
2637 mPowerManager.getDefaultScreenBrightnessSetting(),
2638 UserHandle.USER_CURRENT_OR_SELF);
2639 brightness += step;
2640 // Make sure we don't go beyond the limits.
2641 brightness = Math.min(max, brightness);
2642 brightness = Math.max(min, brightness);
2643
2644 Settings.System.putIntForUser(mContext.getContentResolver(),
2645 Settings.System.SCREEN_BRIGHTNESS, brightness,
2646 UserHandle.USER_CURRENT_OR_SELF);
Alan Viverette5a399492014-07-14 16:19:38 -07002647 mContext.startActivityAsUser(new Intent(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG),
2648 UserHandle.CURRENT_OR_SELF);
Michael Wrightb854e242013-02-05 17:54:02 -08002649 }
2650 return -1;
Michael Wrightce0c13a2014-07-30 10:49:21 -07002651 } else if (KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07002652 if (down) {
2653 mPendingMetaAction = true;
2654 } else if (mPendingMetaAction) {
Michael Wright8ab940a2014-09-01 11:01:27 -07002655 launchAssistAction(Intent.EXTRA_ASSIST_INPUT_HINT_KEYBOARD);
Michael Wright6a62e552014-06-03 19:19:48 -07002656 }
2657 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002658 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002659
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002660 // Shortcuts are invoked through Search+key, so intercept those here
Jeff Browncaab4d02010-12-09 22:13:41 -08002661 // Any printing key that is chorded with Search should be consumed
2662 // even if no shortcut was invoked. This prevents text from being
2663 // inadvertently inserted when using a keyboard that has built-in macro
2664 // shortcut keys (that emit Search+x) and some of them are not registered.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002665 if (mSearchKeyShortcutPending) {
Jeff Browncaab4d02010-12-09 22:13:41 -08002666 final KeyCharacterMap kcm = event.getKeyCharacterMap();
2667 if (kcm.isPrintingKey(keyCode)) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002668 mConsumeSearchKeyUp = true;
2669 mSearchKeyShortcutPending = false;
Jeff Browncaab4d02010-12-09 22:13:41 -08002670 if (down && repeatCount == 0 && !keyguardOn) {
2671 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState);
2672 if (shortcutIntent != null) {
2673 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002674 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002675 mContext.startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002676 } catch (ActivityNotFoundException ex) {
2677 Slog.w(TAG, "Dropping shortcut key combination because "
2678 + "the activity to which it is registered was not found: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002679 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode), ex);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002680 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002681 } else {
2682 Slog.i(TAG, "Dropping unregistered shortcut key combination: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002683 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002684 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002685 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002686 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002687 }
2688 }
2689
Jeff Brown68b909d2011-12-07 16:36:01 -08002690 // Invoke shortcuts using Meta.
Jeff Brown602ab322012-05-16 13:33:47 -07002691 if (down && repeatCount == 0 && !keyguardOn
Jeff Brown68b909d2011-12-07 16:36:01 -08002692 && (metaState & KeyEvent.META_META_ON) != 0) {
2693 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brown602ab322012-05-16 13:33:47 -07002694 if (kcm.isPrintingKey(keyCode)) {
2695 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode,
2696 metaState & ~(KeyEvent.META_META_ON
2697 | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON));
2698 if (shortcutIntent != null) {
2699 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2700 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002701 mContext.startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brown602ab322012-05-16 13:33:47 -07002702 } catch (ActivityNotFoundException ex) {
2703 Slog.w(TAG, "Dropping shortcut key combination because "
2704 + "the activity to which it is registered was not found: "
2705 + "META+" + KeyEvent.keyCodeToString(keyCode), ex);
2706 }
2707 return -1;
Jeff Brown68b909d2011-12-07 16:36:01 -08002708 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002709 }
2710 }
2711
Jeff Brown6651a632011-11-28 12:59:11 -08002712 // Handle application launch keys.
Jeff Brown602ab322012-05-16 13:33:47 -07002713 if (down && repeatCount == 0 && !keyguardOn) {
Jeff Brown6651a632011-11-28 12:59:11 -08002714 String category = sApplicationLaunchKeyCategories.get(keyCode);
2715 if (category != null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -08002716 Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category);
Jeff Brown6651a632011-11-28 12:59:11 -08002717 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2718 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002719 mContext.startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brown6651a632011-11-28 12:59:11 -08002720 } catch (ActivityNotFoundException ex) {
2721 Slog.w(TAG, "Dropping application launch key because "
2722 + "the activity to which it is registered was not found: "
2723 + "keyCode=" + keyCode + ", category=" + category, ex);
2724 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002725 return -1;
Jeff Brown6651a632011-11-28 12:59:11 -08002726 }
2727 }
2728
Michael Wright61c46752014-08-21 16:57:33 -07002729 // Display task switcher for ALT-TAB.
Jeff Brown68b909d2011-12-07 16:36:01 -08002730 if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_TAB) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002731 if (mRecentAppsHeldModifiers == 0 && !keyguardOn) {
Jeff Brown68b909d2011-12-07 16:36:01 -08002732 final int shiftlessModifiers = event.getModifiers() & ~KeyEvent.META_SHIFT_MASK;
Michael Wright61c46752014-08-21 16:57:33 -07002733 if (KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_ALT_ON)) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002734 mRecentAppsHeldModifiers = shiftlessModifiers;
2735 showRecentApps(true);
Jeff Brown68b909d2011-12-07 16:36:01 -08002736 return -1;
2737 }
2738 }
Winson Chung1e8d71b2014-05-16 17:05:22 -07002739 } else if (!down && mRecentAppsHeldModifiers != 0
2740 && (metaState & mRecentAppsHeldModifiers) == 0) {
2741 mRecentAppsHeldModifiers = 0;
Winson Chungcdcd4872014-08-05 18:00:13 -07002742 hideRecentApps(true, false);
Jeff Brown68b909d2011-12-07 16:36:01 -08002743 }
2744
Jeff Browncf39bdf2012-05-18 14:41:19 -07002745 // Handle keyboard language switching.
2746 if (down && repeatCount == 0
2747 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2748 || (keyCode == KeyEvent.KEYCODE_SPACE
2749 && (metaState & KeyEvent.META_CTRL_MASK) != 0))) {
2750 int direction = (metaState & KeyEvent.META_SHIFT_MASK) != 0 ? -1 : 1;
2751 mWindowManagerFuncs.switchKeyboardLayout(event.getDeviceId(), direction);
2752 return -1;
2753 }
2754 if (mLanguageSwitchKeyPressed && !down
2755 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2756 || keyCode == KeyEvent.KEYCODE_SPACE)) {
2757 mLanguageSwitchKeyPressed = false;
2758 return -1;
2759 }
2760
Jeff Brown13f00f02014-10-31 14:45:50 -07002761 if (isValidGlobalKey(keyCode)
2762 && mGlobalKeyManager.handleGlobalKey(mContext, keyCode, event)) {
Justin Kohd378ad72013-04-01 12:18:26 -07002763 return -1;
2764 }
2765
Michael Wright6a62e552014-06-03 19:19:48 -07002766 // Reserve all the META modifier combos for system behavior
Michael Wrightce0c13a2014-07-30 10:49:21 -07002767 if ((metaState & KeyEvent.META_META_ON) != 0) {
Michael Wright6a62e552014-06-03 19:19:48 -07002768 return -1;
2769 }
2770
Jeff Brown68b909d2011-12-07 16:36:01 -08002771 // Let the application handle the key.
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002772 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002773 }
2774
Jeff Brown3915bb82010-11-05 15:02:16 -07002775 /** {@inheritDoc} */
2776 @Override
Jeff Brown49ed71d2010-12-06 17:13:33 -08002777 public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown54875002011-04-06 15:33:01 -07002778 // Note: This method is only called if the initial down was unhandled.
Jeff Brown40013652012-05-16 21:22:36 -07002779 if (DEBUG_INPUT) {
Jeff Brown1f245102010-11-18 20:53:46 -08002780 Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction()
2781 + ", flags=" + event.getFlags()
2782 + ", keyCode=" + event.getKeyCode()
2783 + ", scanCode=" + event.getScanCode()
2784 + ", metaState=" + event.getMetaState()
2785 + ", repeatCount=" + event.getRepeatCount()
2786 + ", policyFlags=" + policyFlags);
Jeff Brown3915bb82010-11-05 15:02:16 -07002787 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002788
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002789 KeyEvent fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002790 if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
2791 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002792 final int keyCode = event.getKeyCode();
2793 final int metaState = event.getMetaState();
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002794 final boolean initialDown = event.getAction() == KeyEvent.ACTION_DOWN
2795 && event.getRepeatCount() == 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002796
Jeff Brown54875002011-04-06 15:33:01 -07002797 // Check for fallback actions specified by the key character map.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002798 final FallbackAction fallbackAction;
2799 if (initialDown) {
2800 fallbackAction = kcm.getFallbackAction(keyCode, metaState);
2801 } else {
2802 fallbackAction = mFallbackActions.get(keyCode);
2803 }
2804
2805 if (fallbackAction != null) {
Jeff Brown40013652012-05-16 21:22:36 -07002806 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002807 Slog.d(TAG, "Fallback: keyCode=" + fallbackAction.keyCode
2808 + " metaState=" + Integer.toHexString(fallbackAction.metaState));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002809 }
2810
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002811 final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK;
2812 fallbackEvent = KeyEvent.obtain(
Jeff Brown49ed71d2010-12-06 17:13:33 -08002813 event.getDownTime(), event.getEventTime(),
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002814 event.getAction(), fallbackAction.keyCode,
2815 event.getRepeatCount(), fallbackAction.metaState,
Jeff Brown49ed71d2010-12-06 17:13:33 -08002816 event.getDeviceId(), event.getScanCode(),
2817 flags, event.getSource(), null);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002818
2819 if (!interceptFallback(win, fallbackEvent, policyFlags)) {
2820 fallbackEvent.recycle();
2821 fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002822 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002823
2824 if (initialDown) {
2825 mFallbackActions.put(keyCode, fallbackAction);
2826 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2827 mFallbackActions.remove(keyCode);
2828 fallbackAction.recycle();
2829 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002830 }
2831 }
2832
Jeff Brown40013652012-05-16 21:22:36 -07002833 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002834 if (fallbackEvent == null) {
2835 Slog.d(TAG, "No fallback.");
2836 } else {
2837 Slog.d(TAG, "Performing fallback: " + fallbackEvent);
2838 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002839 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002840 return fallbackEvent;
Jeff Brown3915bb82010-11-05 15:02:16 -07002841 }
2842
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002843 private boolean interceptFallback(WindowState win, KeyEvent fallbackEvent, int policyFlags) {
Jeff Brown037c33e2014-04-09 00:31:55 -07002844 int actions = interceptKeyBeforeQueueing(fallbackEvent, policyFlags);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002845 if ((actions & ACTION_PASS_TO_USER) != 0) {
2846 long delayMillis = interceptKeyBeforeDispatching(
2847 win, fallbackEvent, policyFlags);
2848 if (delayMillis == 0) {
2849 return true;
2850 }
2851 }
2852 return false;
Jeff Brown6f2fba42011-02-19 01:08:02 -08002853 }
2854
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002855 private void launchAssistLongPressAction() {
2856 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
2857 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
2858
2859 // launch the search activity
2860 Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS);
2861 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2862 try {
RoboErik8a2cfc32014-05-16 11:19:38 -07002863 // TODO: This only stops the factory-installed search manager.
Jim Miller45308b12012-06-18 19:23:39 -07002864 // Need to formalize an API to handle others
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002865 SearchManager searchManager = getSearchManager();
2866 if (searchManager != null) {
2867 searchManager.stopSearch();
2868 }
Michael Wright43e27f72013-04-10 14:06:48 -07002869 mContext.startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002870 } catch (ActivityNotFoundException e) {
2871 Slog.w(TAG, "No activity to handle assist long press action.", e);
2872 }
2873 }
2874
2875 private void launchAssistAction() {
Michael Wright8ab940a2014-09-01 11:01:27 -07002876 launchAssistAction(null);
2877 }
2878
2879 private void launchAssistAction(String hint) {
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002880 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
Amith Yamasanic1d07a42012-08-14 09:32:02 -07002881 Intent intent = ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE))
Dianne Hackbornf9c5e0f2013-01-23 14:39:13 -08002882 .getAssistIntent(mContext, true, UserHandle.USER_CURRENT);
Jim Miller45308b12012-06-18 19:23:39 -07002883 if (intent != null) {
Michael Wright8ab940a2014-09-01 11:01:27 -07002884 if (hint != null) {
2885 intent.putExtra(hint, true);
2886 }
Jim Miller45308b12012-06-18 19:23:39 -07002887 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
2888 | Intent.FLAG_ACTIVITY_SINGLE_TOP
2889 | Intent.FLAG_ACTIVITY_CLEAR_TOP);
2890 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002891 mContext.startActivityAsUser(intent, UserHandle.CURRENT);
Jim Miller45308b12012-06-18 19:23:39 -07002892 } catch (ActivityNotFoundException e) {
2893 Slog.w(TAG, "No activity to handle assist action.", e);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002894 }
2895 }
2896 }
2897
2898 private SearchManager getSearchManager() {
2899 if (mSearchManager == null) {
2900 mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
2901 }
2902 return mSearchManager;
2903 }
2904
Jeff Browncaca8812013-05-09 13:34:33 -07002905 private void preloadRecentApps() {
2906 mPreloadedRecentApps = true;
2907 try {
2908 IStatusBarService statusbar = getStatusBarService();
2909 if (statusbar != null) {
2910 statusbar.preloadRecentApps();
2911 }
2912 } catch (RemoteException e) {
2913 Slog.e(TAG, "RemoteException when preloading recent apps", e);
2914 // re-acquire status bar service next time it is needed.
2915 mStatusBarService = null;
2916 }
2917 }
2918
2919 private void cancelPreloadRecentApps() {
2920 if (mPreloadedRecentApps) {
2921 mPreloadedRecentApps = false;
2922 try {
2923 IStatusBarService statusbar = getStatusBarService();
2924 if (statusbar != null) {
2925 statusbar.cancelPreloadRecentApps();
2926 }
2927 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002928 Slog.e(TAG, "RemoteException when cancelling recent apps preload", e);
Jeff Browncaca8812013-05-09 13:34:33 -07002929 // re-acquire status bar service next time it is needed.
2930 mStatusBarService = null;
2931 }
2932 }
2933 }
2934
2935 private void toggleRecentApps() {
2936 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
Jeff Browncaca8812013-05-09 13:34:33 -07002937 try {
2938 IStatusBarService statusbar = getStatusBarService();
2939 if (statusbar != null) {
2940 statusbar.toggleRecentApps();
2941 }
2942 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002943 Slog.e(TAG, "RemoteException when toggling recent apps", e);
2944 // re-acquire status bar service next time it is needed.
2945 mStatusBarService = null;
2946 }
2947 }
2948
Craig Mautner84984fa2014-06-19 11:19:20 -07002949 @Override
2950 public void showRecentApps() {
2951 mHandler.removeMessages(MSG_DISPATCH_SHOW_RECENTS);
2952 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_RECENTS);
2953 }
2954
Winson Chung1e8d71b2014-05-16 17:05:22 -07002955 private void showRecentApps(boolean triggeredFromAltTab) {
2956 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
2957 try {
2958 IStatusBarService statusbar = getStatusBarService();
2959 if (statusbar != null) {
2960 statusbar.showRecentApps(triggeredFromAltTab);
2961 }
2962 } catch (RemoteException e) {
Jeff Browncaca8812013-05-09 13:34:33 -07002963 Slog.e(TAG, "RemoteException when showing recent apps", e);
2964 // re-acquire status bar service next time it is needed.
2965 mStatusBarService = null;
2966 }
2967 }
2968
Winson Chungcdcd4872014-08-05 18:00:13 -07002969 private void hideRecentApps(boolean triggeredFromAltTab, boolean triggeredFromHome) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002970 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
2971 try {
2972 IStatusBarService statusbar = getStatusBarService();
2973 if (statusbar != null) {
Winson Chungcdcd4872014-08-05 18:00:13 -07002974 statusbar.hideRecentApps(triggeredFromAltTab, triggeredFromHome);
Winson Chung1e8d71b2014-05-16 17:05:22 -07002975 }
2976 } catch (RemoteException e) {
2977 Slog.e(TAG, "RemoteException when closing recent apps", e);
2978 // re-acquire status bar service next time it is needed.
2979 mStatusBarService = null;
2980 }
2981 }
2982
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002983 /**
2984 * A home key -> launch home action was detected. Take the appropriate action
2985 * given the situation with the keyguard.
2986 */
2987 void launchHomeFromHotKey() {
Jim Millerab954542014-10-10 18:21:49 -07002988 if (isKeyguardShowingAndNotOccluded()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002989 // don't launch home if keyguard showing
Jim Miller5ecd8112013-01-09 18:50:26 -08002990 } else if (!mHideLockScreen && mKeyguardDelegate.isInputRestricted()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002991 // when in keyguard restricted mode, must first verify unlock
2992 // before launching home
Jim Miller5ecd8112013-01-09 18:50:26 -08002993 mKeyguardDelegate.verifyUnlock(new OnKeyguardExitResult() {
Jose Lima9546b202014-07-02 17:21:51 -07002994 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002995 public void onKeyguardExitResult(boolean success) {
2996 if (success) {
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07002997 try {
2998 ActivityManagerNative.getDefault().stopAppSwitches();
2999 } catch (RemoteException e) {
3000 }
Joe Onoratof275f0c2009-11-24 16:11:13 -05003001 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
Bryce Lee01b0c5f2015-02-05 18:24:04 -08003002 startDockOrHome(true /*fromHomeKey*/);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003003 }
3004 }
3005 });
3006 } else {
3007 // no keyguard stuff to worry about, just launch home!
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07003008 try {
3009 ActivityManagerNative.getDefault().stopAppSwitches();
3010 } catch (RemoteException e) {
3011 }
Winson Chungd543c1b2014-06-23 15:06:45 -07003012 if (mRecentsVisible) {
3013 // Hide Recents and notify it to launch Home
3014 awakenDreams();
3015 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
Winson Chungcdcd4872014-08-05 18:00:13 -07003016 hideRecentApps(false, true);
Winson Chungd543c1b2014-06-23 15:06:45 -07003017 } else {
3018 // Otherwise, just launch Home
3019 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
Bryce Lee01b0c5f2015-02-05 18:24:04 -08003020 startDockOrHome(true /*fromHomeKey*/);
Winson Chungd543c1b2014-06-23 15:06:45 -07003021 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003022 }
3023 }
3024
John Spurlock04db1762013-05-13 12:46:41 -04003025 private final Runnable mClearHideNavigationFlag = new Runnable() {
3026 @Override
3027 public void run() {
3028 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
3029 // Clear flags.
3030 mForceClearedSystemUiFlags &=
3031 ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
3032 }
3033 mWindowManagerFuncs.reevaluateStatusBarVisibility();
Dianne Hackborne26ab702011-10-16 13:21:33 -07003034 }
3035 };
3036
3037 /**
3038 * Input handler used while nav bar is hidden. Captures any touch on the screen,
3039 * to determine when the nav bar should be shown and prevent applications from
3040 * receiving those touches.
3041 */
Jeff Brown32cbc38552011-12-01 14:01:49 -08003042 final class HideNavInputEventReceiver extends InputEventReceiver {
3043 public HideNavInputEventReceiver(InputChannel inputChannel, Looper looper) {
3044 super(inputChannel, looper);
3045 }
3046
Dianne Hackborndf89e652011-10-06 22:35:11 -07003047 @Override
Jeff Brown32cbc38552011-12-01 14:01:49 -08003048 public void onInputEvent(InputEvent event) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003049 boolean handled = false;
3050 try {
Jeff Brown4952dfd2011-11-30 19:23:22 -08003051 if (event instanceof MotionEvent
3052 && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
3053 final MotionEvent motionEvent = (MotionEvent)event;
3054 if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003055 // When the user taps down, we re-show the nav bar.
3056 boolean changed = false;
John Spurlock04db1762013-05-13 12:46:41 -04003057 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003058 // Any user activity always causes us to show the
3059 // navigation controls, if they had been hidden.
3060 // We also clear the low profile and only content
3061 // flags so that tapping on the screen will atomically
3062 // restore all currently hidden screen decorations.
3063 int newVal = mResettingSystemUiFlags |
3064 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
3065 View.SYSTEM_UI_FLAG_LOW_PROFILE |
3066 View.SYSTEM_UI_FLAG_FULLSCREEN;
Dianne Hackborne26ab702011-10-16 13:21:33 -07003067 if (mResettingSystemUiFlags != newVal) {
3068 mResettingSystemUiFlags = newVal;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003069 changed = true;
3070 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003071 // We don't allow the system's nav bar to be hidden
3072 // again for 1 second, to prevent applications from
3073 // spamming us and keeping it from being shown.
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003074 newVal = mForceClearedSystemUiFlags |
3075 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
Dianne Hackborne26ab702011-10-16 13:21:33 -07003076 if (mForceClearedSystemUiFlags != newVal) {
3077 mForceClearedSystemUiFlags = newVal;
3078 changed = true;
John Spurlock04db1762013-05-13 12:46:41 -04003079 mHandler.postDelayed(mClearHideNavigationFlag, 1000);
Dianne Hackborne26ab702011-10-16 13:21:33 -07003080 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07003081 }
3082 if (changed) {
3083 mWindowManagerFuncs.reevaluateStatusBarVisibility();
3084 }
3085 }
3086 }
3087 } finally {
Jeff Brown32cbc38552011-12-01 14:01:49 -08003088 finishInputEvent(event, handled);
Dianne Hackborndf89e652011-10-06 22:35:11 -07003089 }
3090 }
Jeff Brown32cbc38552011-12-01 14:01:49 -08003091 }
3092 final InputEventReceiver.Factory mHideNavInputEventReceiverFactory =
3093 new InputEventReceiver.Factory() {
3094 @Override
3095 public InputEventReceiver createInputEventReceiver(
3096 InputChannel inputChannel, Looper looper) {
3097 return new HideNavInputEventReceiver(inputChannel, looper);
3098 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07003099 };
3100
3101 @Override
3102 public int adjustSystemUiVisibilityLw(int visibility) {
John Spurlock5b9145b2013-08-20 15:13:47 -04003103 mStatusBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
3104 mNavigationBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
Winson Chungd42a6cf2014-06-03 16:24:04 -07003105 mRecentsVisible = (visibility & View.RECENT_APPS_VISIBLE) > 0;
John Spurlock27735a42013-08-14 17:57:38 -04003106
Dianne Hackborndf89e652011-10-06 22:35:11 -07003107 // Reset any bits in mForceClearingStatusBarVisibility that
3108 // are now clear.
Dianne Hackborne26ab702011-10-16 13:21:33 -07003109 mResettingSystemUiFlags &= visibility;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003110 // Clear any bits in the new visibility that are currently being
3111 // force cleared, before reporting it.
Dianne Hackborne26ab702011-10-16 13:21:33 -07003112 return visibility & ~mResettingSystemUiFlags
3113 & ~mForceClearedSystemUiFlags;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003114 }
3115
Craig Mautner69b08182012-09-05 13:07:13 -07003116 @Override
Adrian Roos37d7a682014-11-06 18:15:16 +01003117 public void getInsetHintLw(WindowManager.LayoutParams attrs, Rect outContentInsets,
3118 Rect outStableInsets) {
John Spurlockc6d1c602014-01-17 15:22:06 -05003119 final int fl = PolicyControl.getWindowFlags(null, attrs);
John Spurlock1db8b682014-02-18 11:18:59 -05003120 final int sysuiVis = PolicyControl.getSystemUiVisibility(null, attrs);
3121 final int systemUiVisibility = (sysuiVis | attrs.subtreeSystemUiVisibility);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003122
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003123 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003124 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003125 int availRight, availBottom;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003126 if (canHideNavigationBar() &&
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003127 (systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003128 availRight = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3129 availBottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
3130 } else {
3131 availRight = mRestrictedScreenLeft + mRestrictedScreenWidth;
3132 availBottom = mRestrictedScreenTop + mRestrictedScreenHeight;
3133 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003134 if ((systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
3135 if ((fl & FLAG_FULLSCREEN) != 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003136 outContentInsets.set(mStableFullscreenLeft, mStableFullscreenTop,
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003137 availRight - mStableFullscreenRight,
3138 availBottom - mStableFullscreenBottom);
3139 } else {
Adrian Roos37d7a682014-11-06 18:15:16 +01003140 outContentInsets.set(mStableLeft, mStableTop,
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003141 availRight - mStableRight, availBottom - mStableBottom);
3142 }
Dianne Hackbornc652de82013-02-15 16:32:56 -08003143 } else if ((fl & FLAG_FULLSCREEN) != 0 || (fl & FLAG_LAYOUT_IN_OVERSCAN) != 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003144 outContentInsets.setEmpty();
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003145 } else if ((systemUiVisibility & (View.SYSTEM_UI_FLAG_FULLSCREEN
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003146 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)) == 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003147 outContentInsets.set(mCurLeft, mCurTop,
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003148 availRight - mCurRight, availBottom - mCurBottom);
3149 } else {
Adrian Roos37d7a682014-11-06 18:15:16 +01003150 outContentInsets.set(mCurLeft, mCurTop,
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003151 availRight - mCurRight, availBottom - mCurBottom);
3152 }
Adrian Roos37d7a682014-11-06 18:15:16 +01003153
3154 outStableInsets.set(mStableLeft, mStableTop,
3155 availRight - mStableRight, availBottom - mStableBottom);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003156 return;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003157 }
Adrian Roos37d7a682014-11-06 18:15:16 +01003158 outContentInsets.setEmpty();
3159 outStableInsets.setEmpty();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003160 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003161
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003162 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07003163 @Override
3164 public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight,
3165 int displayRotation) {
Dianne Hackbornc652de82013-02-15 16:32:56 -08003166 final int overscanLeft, overscanTop, overscanRight, overscanBottom;
3167 if (isDefaultDisplay) {
3168 switch (displayRotation) {
3169 case Surface.ROTATION_90:
3170 overscanLeft = mOverscanTop;
3171 overscanTop = mOverscanRight;
3172 overscanRight = mOverscanBottom;
3173 overscanBottom = mOverscanLeft;
3174 break;
3175 case Surface.ROTATION_180:
3176 overscanLeft = mOverscanRight;
3177 overscanTop = mOverscanBottom;
3178 overscanRight = mOverscanLeft;
3179 overscanBottom = mOverscanTop;
3180 break;
3181 case Surface.ROTATION_270:
3182 overscanLeft = mOverscanBottom;
3183 overscanTop = mOverscanLeft;
3184 overscanRight = mOverscanTop;
3185 overscanBottom = mOverscanRight;
3186 break;
3187 default:
3188 overscanLeft = mOverscanLeft;
3189 overscanTop = mOverscanTop;
3190 overscanRight = mOverscanRight;
3191 overscanBottom = mOverscanBottom;
3192 break;
3193 }
3194 } else {
3195 overscanLeft = 0;
3196 overscanTop = 0;
3197 overscanRight = 0;
3198 overscanBottom = 0;
3199 }
Dianne Hackborn313440842013-02-19 19:22:59 -08003200 mOverscanScreenLeft = mRestrictedOverscanScreenLeft = 0;
3201 mOverscanScreenTop = mRestrictedOverscanScreenTop = 0;
3202 mOverscanScreenWidth = mRestrictedOverscanScreenWidth = displayWidth;
3203 mOverscanScreenHeight = mRestrictedOverscanScreenHeight = displayHeight;
Dianne Hackbornc652de82013-02-15 16:32:56 -08003204 mSystemLeft = 0;
3205 mSystemTop = 0;
3206 mSystemRight = displayWidth;
3207 mSystemBottom = displayHeight;
3208 mUnrestrictedScreenLeft = overscanLeft;
3209 mUnrestrictedScreenTop = overscanTop;
3210 mUnrestrictedScreenWidth = displayWidth - overscanLeft - overscanRight;
3211 mUnrestrictedScreenHeight = displayHeight - overscanTop - overscanBottom;
3212 mRestrictedScreenLeft = mUnrestrictedScreenLeft;
3213 mRestrictedScreenTop = mUnrestrictedScreenTop;
John Spurlockad3e6cb2013-04-30 08:47:43 -04003214 mRestrictedScreenWidth = mSystemGestures.screenWidth = mUnrestrictedScreenWidth;
3215 mRestrictedScreenHeight = mSystemGestures.screenHeight = mUnrestrictedScreenHeight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003216 mDockLeft = mContentLeft = mVoiceContentLeft = mStableLeft = mStableFullscreenLeft
Dianne Hackbornc652de82013-02-15 16:32:56 -08003217 = mCurLeft = mUnrestrictedScreenLeft;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003218 mDockTop = mContentTop = mVoiceContentTop = mStableTop = mStableFullscreenTop
Dianne Hackbornc652de82013-02-15 16:32:56 -08003219 = mCurTop = mUnrestrictedScreenTop;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003220 mDockRight = mContentRight = mVoiceContentRight = mStableRight = mStableFullscreenRight
Dianne Hackbornc652de82013-02-15 16:32:56 -08003221 = mCurRight = displayWidth - overscanRight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003222 mDockBottom = mContentBottom = mVoiceContentBottom = mStableBottom = mStableFullscreenBottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003223 = mCurBottom = displayHeight - overscanBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003224 mDockLayer = 0x10000000;
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003225 mStatusBarLayer = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003226
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003227 // start with the current dock rect, which will be (0,0,displayWidth,displayHeight)
3228 final Rect pf = mTmpParentFrame;
3229 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003230 final Rect of = mTmpOverscanFrame;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003231 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04003232 final Rect dcf = mTmpDecorFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003233 pf.left = df.left = of.left = vf.left = mDockLeft;
3234 pf.top = df.top = of.top = vf.top = mDockTop;
3235 pf.right = df.right = of.right = vf.right = mDockRight;
3236 pf.bottom = df.bottom = of.bottom = vf.bottom = mDockBottom;
John Spurlock46646232013-09-30 22:32:42 -04003237 dcf.setEmpty(); // Decor frame N/A for system bars.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003238
Craig Mautner69b08182012-09-05 13:07:13 -07003239 if (isDefaultDisplay) {
3240 // For purposes of putting out fake window up to steal focus, we will
3241 // drive nav being hidden only by whether it is requested.
John Spurlocke1f366f2013-08-05 12:22:40 -04003242 final int sysui = mLastSystemUiFlags;
3243 boolean navVisible = (sysui & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0;
Adrian Roosea562512014-05-05 13:33:03 +02003244 boolean navTranslucent = (sysui
3245 & (View.NAVIGATION_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04003246 boolean immersive = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
3247 boolean immersiveSticky = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
3248 boolean navAllowedHidden = immersive || immersiveSticky;
3249 navTranslucent &= !immersiveSticky; // transient trumps translucent
Adrian Roos4fb3ee32014-08-22 19:29:09 +02003250 boolean isKeyguardShowing = isStatusBarKeyguard() && !mHideLockScreen;
3251 if (!isKeyguardShowing) {
3252 navTranslucent &= areTranslucentBarsAllowed();
3253 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003254
Craig Mautner69b08182012-09-05 13:07:13 -07003255 // When the navigation bar isn't visible, we put up a fake
3256 // input window to catch all touch events. This way we can
3257 // detect when the user presses anywhere to bring back the nav
3258 // bar and ensure the application doesn't see the event.
John Spurlockf1a36642013-10-12 17:50:42 -04003259 if (navVisible || navAllowedHidden) {
Craig Mautner69b08182012-09-05 13:07:13 -07003260 if (mHideNavFakeWindow != null) {
3261 mHideNavFakeWindow.dismiss();
3262 mHideNavFakeWindow = null;
3263 }
3264 } else if (mHideNavFakeWindow == null) {
3265 mHideNavFakeWindow = mWindowManagerFuncs.addFakeWindow(
3266 mHandler.getLooper(), mHideNavInputEventReceiverFactory,
Adam Lesinski95c42972013-10-02 10:13:27 -07003267 "hidden nav", WindowManager.LayoutParams.TYPE_HIDDEN_NAV_CONSUMER, 0,
Craig Mautner69b08182012-09-05 13:07:13 -07003268 0, false, false, true);
Dianne Hackborne26ab702011-10-16 13:21:33 -07003269 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003270
Craig Mautner69b08182012-09-05 13:07:13 -07003271 // For purposes of positioning and showing the nav bar, if we have
3272 // decided that it can't be hidden (because of the screen aspect ratio),
3273 // then take that into account.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003274 navVisible |= !canHideNavigationBar();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003275
John Spurlockad3e6cb2013-04-30 08:47:43 -04003276 boolean updateSysUiVisibility = false;
Craig Mautner69b08182012-09-05 13:07:13 -07003277 if (mNavigationBar != null) {
John Spurlock27735a42013-08-14 17:57:38 -04003278 boolean transientNavBarShowing = mNavigationBarController.isTransientShowing();
Craig Mautner69b08182012-09-05 13:07:13 -07003279 // Force the navigation bar to its appropriate place and
3280 // size. We need to do this directly, instead of relying on
3281 // it to bubble up from the nav bar, because this needs to
3282 // change atomically with screen rotations.
3283 mNavigationBarOnBottom = (!mNavigationBarCanMove || displayWidth < displayHeight);
3284 if (mNavigationBarOnBottom) {
3285 // It's a system nav bar or a portrait screen; nav bar goes on bottom.
Dianne Hackbornc652de82013-02-15 16:32:56 -08003286 int top = displayHeight - overscanBottom
3287 - mNavigationBarHeightForRotation[displayRotation];
3288 mTmpNavigationFrame.set(0, top, displayWidth, displayHeight - overscanBottom);
Craig Mautner69b08182012-09-05 13:07:13 -07003289 mStableBottom = mStableFullscreenBottom = mTmpNavigationFrame.top;
John Spurlockf95b89a2013-10-10 22:10:42 -04003290 if (transientNavBarShowing) {
John Spurlock27735a42013-08-14 17:57:38 -04003291 mNavigationBarController.setBarShowingLw(true);
John Spurlockad3e6cb2013-04-30 08:47:43 -04003292 } else if (navVisible) {
John Spurlock27735a42013-08-14 17:57:38 -04003293 mNavigationBarController.setBarShowingLw(true);
Craig Mautner69b08182012-09-05 13:07:13 -07003294 mDockBottom = mTmpNavigationFrame.top;
Dianne Hackborn313440842013-02-19 19:22:59 -08003295 mRestrictedScreenHeight = mDockBottom - mRestrictedScreenTop;
3296 mRestrictedOverscanScreenHeight = mDockBottom - mRestrictedOverscanScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07003297 } else {
3298 // We currently want to hide the navigation UI.
John Spurlock27735a42013-08-14 17:57:38 -04003299 mNavigationBarController.setBarShowingLw(false);
Craig Mautner69b08182012-09-05 13:07:13 -07003300 }
John Spurlockc6d1c602014-01-17 15:22:06 -05003301 if (navVisible && !navTranslucent && !navAllowedHidden
3302 && !mNavigationBar.isAnimatingLw()
John Spurlockbd957402013-10-03 11:38:39 -04003303 && !mNavigationBarController.wasRecentlyTranslucent()) {
John Spurlocke1f366f2013-08-05 12:22:40 -04003304 // If the opaque nav bar is currently requested to be visible,
Craig Mautner69b08182012-09-05 13:07:13 -07003305 // and not in the process of animating on or off, then
3306 // we can tell the app that it is covered by it.
3307 mSystemBottom = mTmpNavigationFrame.top;
3308 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003309 } else {
Craig Mautner69b08182012-09-05 13:07:13 -07003310 // Landscape screen; nav bar goes to the right.
Dianne Hackbornc652de82013-02-15 16:32:56 -08003311 int left = displayWidth - overscanRight
3312 - mNavigationBarWidthForRotation[displayRotation];
3313 mTmpNavigationFrame.set(left, 0, displayWidth - overscanRight, displayHeight);
Craig Mautner69b08182012-09-05 13:07:13 -07003314 mStableRight = mStableFullscreenRight = mTmpNavigationFrame.left;
John Spurlockf95b89a2013-10-10 22:10:42 -04003315 if (transientNavBarShowing) {
John Spurlock27735a42013-08-14 17:57:38 -04003316 mNavigationBarController.setBarShowingLw(true);
John Spurlockad3e6cb2013-04-30 08:47:43 -04003317 } else if (navVisible) {
John Spurlock27735a42013-08-14 17:57:38 -04003318 mNavigationBarController.setBarShowingLw(true);
Craig Mautner69b08182012-09-05 13:07:13 -07003319 mDockRight = mTmpNavigationFrame.left;
Dianne Hackborn313440842013-02-19 19:22:59 -08003320 mRestrictedScreenWidth = mDockRight - mRestrictedScreenLeft;
3321 mRestrictedOverscanScreenWidth = mDockRight - mRestrictedOverscanScreenLeft;
Craig Mautner69b08182012-09-05 13:07:13 -07003322 } else {
3323 // We currently want to hide the navigation UI.
John Spurlock27735a42013-08-14 17:57:38 -04003324 mNavigationBarController.setBarShowingLw(false);
Craig Mautner69b08182012-09-05 13:07:13 -07003325 }
John Spurlockbd957402013-10-03 11:38:39 -04003326 if (navVisible && !navTranslucent && !mNavigationBar.isAnimatingLw()
3327 && !mNavigationBarController.wasRecentlyTranslucent()) {
Craig Mautner69b08182012-09-05 13:07:13 -07003328 // If the nav bar is currently requested to be visible,
3329 // and not in the process of animating on or off, then
3330 // we can tell the app that it is covered by it.
3331 mSystemRight = mTmpNavigationFrame.left;
3332 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003333 }
Craig Mautner69b08182012-09-05 13:07:13 -07003334 // Make sure the content and current rectangles are updated to
3335 // account for the restrictions from the navigation bar.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003336 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3337 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3338 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3339 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
Craig Mautner69b08182012-09-05 13:07:13 -07003340 mStatusBarLayer = mNavigationBar.getSurfaceLayer();
3341 // And compute the final frame.
3342 mNavigationBar.computeFrameLw(mTmpNavigationFrame, mTmpNavigationFrame,
Adrian Roosfa104232014-06-20 16:10:14 -07003343 mTmpNavigationFrame, mTmpNavigationFrame, mTmpNavigationFrame, dcf,
3344 mTmpNavigationFrame);
Craig Mautnereda67292013-04-28 13:50:14 -07003345 if (DEBUG_LAYOUT) Slog.i(TAG, "mNavigationBar frame: " + mTmpNavigationFrame);
John Spurlock27735a42013-08-14 17:57:38 -04003346 if (mNavigationBarController.checkHiddenLw()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04003347 updateSysUiVisibility = true;
3348 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003349 }
Craig Mautnereda67292013-04-28 13:50:14 -07003350 if (DEBUG_LAYOUT) Slog.i(TAG, String.format("mDock rect: (%d,%d - %d,%d)",
Craig Mautner69b08182012-09-05 13:07:13 -07003351 mDockLeft, mDockTop, mDockRight, mDockBottom));
3352
3353 // decide where the status bar goes ahead of time
3354 if (mStatusBar != null) {
3355 // apply any navigation bar insets
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003356 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3357 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3358 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
3359 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight
3360 + mUnrestrictedScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07003361 vf.left = mStableLeft;
3362 vf.top = mStableTop;
3363 vf.right = mStableRight;
3364 vf.bottom = mStableBottom;
3365
3366 mStatusBarLayer = mStatusBar.getSurfaceLayer();
3367
3368 // Let the status bar determine its size.
Adrian Roosfa104232014-06-20 16:10:14 -07003369 mStatusBar.computeFrameLw(pf, df, vf, vf, vf, dcf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07003370
3371 // For layout, the status bar is always at the top with our fixed height.
3372 mStableTop = mUnrestrictedScreenTop + mStatusBarHeight;
3373
John Spurlocke1f366f2013-08-05 12:22:40 -04003374 boolean statusBarTransient = (sysui & View.STATUS_BAR_TRANSIENT) != 0;
Adrian Roosea562512014-05-05 13:33:03 +02003375 boolean statusBarTranslucent = (sysui
3376 & (View.STATUS_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0;
Adrian Roos4fb3ee32014-08-22 19:29:09 +02003377 if (!isKeyguardShowing) {
3378 statusBarTranslucent &= areTranslucentBarsAllowed();
3379 }
John Spurlock32beb2c2013-03-11 10:16:47 -04003380
Craig Mautner69b08182012-09-05 13:07:13 -07003381 // If the status bar is hidden, we don't want to cause
3382 // windows behind it to scroll.
John Spurlockeda1f692013-09-16 11:38:44 -04003383 if (mStatusBar.isVisibleLw() && !statusBarTransient) {
Craig Mautner69b08182012-09-05 13:07:13 -07003384 // Status bar may go away, so the screen area it occupies
3385 // is available to apps but just covering them when the
3386 // status bar is visible.
3387 mDockTop = mUnrestrictedScreenTop + mStatusBarHeight;
3388
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003389 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3390 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3391 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3392 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
Craig Mautner69b08182012-09-05 13:07:13 -07003393
Craig Mautnereda67292013-04-28 13:50:14 -07003394 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar: " +
Craig Mautner69b08182012-09-05 13:07:13 -07003395 String.format(
3396 "dock=[%d,%d][%d,%d] content=[%d,%d][%d,%d] cur=[%d,%d][%d,%d]",
3397 mDockLeft, mDockTop, mDockRight, mDockBottom,
3398 mContentLeft, mContentTop, mContentRight, mContentBottom,
3399 mCurLeft, mCurTop, mCurRight, mCurBottom));
3400 }
John Spurlocke1f366f2013-08-05 12:22:40 -04003401 if (mStatusBar.isVisibleLw() && !mStatusBar.isAnimatingLw()
John Spurlockbd957402013-10-03 11:38:39 -04003402 && !statusBarTransient && !statusBarTranslucent
3403 && !mStatusBarController.wasRecentlyTranslucent()) {
John Spurlocke1f366f2013-08-05 12:22:40 -04003404 // If the opaque status bar is currently requested to be visible,
Craig Mautner69b08182012-09-05 13:07:13 -07003405 // and not in the process of animating on or off, then
3406 // we can tell the app that it is covered by it.
3407 mSystemTop = mUnrestrictedScreenTop + mStatusBarHeight;
3408 }
John Spurlock27735a42013-08-14 17:57:38 -04003409 if (mStatusBarController.checkHiddenLw()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04003410 updateSysUiVisibility = true;
John Spurlock32beb2c2013-03-11 10:16:47 -04003411 }
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003412 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04003413 if (updateSysUiVisibility) {
3414 updateSystemUiVisibilityLw();
3415 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003416 }
3417 }
3418
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003419 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07003420 @Override
John Spurlock46646232013-09-30 22:32:42 -04003421 public int getSystemDecorLayerLw() {
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003422 if (mStatusBar != null) return mStatusBar.getSurfaceLayer();
3423 if (mNavigationBar != null) return mNavigationBar.getSurfaceLayer();
3424 return 0;
3425 }
3426
Craig Mautner967212c2013-04-13 21:10:58 -07003427 @Override
3428 public void getContentRectLw(Rect r) {
3429 r.set(mContentLeft, mContentTop, mContentRight, mContentBottom);
3430 }
3431
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003432 void setAttachedWindowFrames(WindowState win, int fl, int adjust, WindowState attached,
3433 boolean insetDecors, Rect pf, Rect df, Rect of, Rect cf, Rect vf) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003434 if (win.getSurfaceLayer() > mDockLayer && attached.getSurfaceLayer() < mDockLayer) {
3435 // Here's a special case: if this attached window is a panel that is
3436 // above the dock window, and the window it is attached to is below
3437 // the dock window, then the frames we computed for the window it is
3438 // attached to can not be used because the dock is effectively part
3439 // of the underlying window and the attached window is floating on top
3440 // of the whole thing. So, we ignore the attached window and explicitly
3441 // compute the frames that would be appropriate without the dock.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003442 df.left = of.left = cf.left = vf.left = mDockLeft;
3443 df.top = of.top = cf.top = vf.top = mDockTop;
3444 df.right = of.right = cf.right = vf.right = mDockRight;
3445 df.bottom = of.bottom = cf.bottom = vf.bottom = mDockBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003446 } else {
3447 // The effective display frame of the attached window depends on
3448 // whether it is taking care of insetting its content. If not,
3449 // we need to use the parent's content frame so that the entire
3450 // window is positioned within that content. Otherwise we can use
Wale Ogunwale393b1c12014-10-18 16:22:01 -07003451 // the overscan frame and let the attached window take care of
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003452 // positioning its content appropriately.
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003453 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Wale Ogunwale393b1c12014-10-18 16:22:01 -07003454 // Set the content frame of the attached window to the parent's decor frame
3455 // (same as content frame when IME isn't present) if specifically requested by
3456 // setting {@link WindowManager.LayoutParams#FLAG_LAYOUT_ATTACHED_IN_DECOR} flag.
3457 // Otherwise, use the overscan frame.
3458 cf.set((fl & FLAG_LAYOUT_ATTACHED_IN_DECOR) != 0
3459 ? attached.getContentFrameLw() : attached.getOverscanFrameLw());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003460 } else {
3461 // If the window is resizing, then we want to base the content
3462 // frame on our attached content frame to resize... however,
3463 // things can be tricky if the attached window is NOT in resize
3464 // mode, in which case its content frame will be larger.
3465 // Ungh. So to deal with that, make sure the content frame
3466 // we end up using is not covering the IM dock.
3467 cf.set(attached.getContentFrameLw());
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003468 if (attached.isVoiceInteraction()) {
3469 if (cf.left < mVoiceContentLeft) cf.left = mVoiceContentLeft;
3470 if (cf.top < mVoiceContentTop) cf.top = mVoiceContentTop;
3471 if (cf.right > mVoiceContentRight) cf.right = mVoiceContentRight;
3472 if (cf.bottom > mVoiceContentBottom) cf.bottom = mVoiceContentBottom;
3473 } else if (attached.getSurfaceLayer() < mDockLayer) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003474 if (cf.left < mContentLeft) cf.left = mContentLeft;
3475 if (cf.top < mContentTop) cf.top = mContentTop;
3476 if (cf.right > mContentRight) cf.right = mContentRight;
3477 if (cf.bottom > mContentBottom) cf.bottom = mContentBottom;
3478 }
3479 }
3480 df.set(insetDecors ? attached.getDisplayFrameLw() : cf);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003481 of.set(insetDecors ? attached.getOverscanFrameLw() : cf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003482 vf.set(attached.getVisibleFrameLw());
3483 }
3484 // The LAYOUT_IN_SCREEN flag is used to determine whether the attached
3485 // window should be positioned relative to its parent or the entire
3486 // screen.
3487 pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0
3488 ? attached.getFrameLw() : df);
3489 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003490
3491 private void applyStableConstraints(int sysui, int fl, Rect r) {
3492 if ((sysui & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
3493 // If app is requesting a stable layout, don't let the
3494 // content insets go below the stable values.
3495 if ((fl & FLAG_FULLSCREEN) != 0) {
3496 if (r.left < mStableFullscreenLeft) r.left = mStableFullscreenLeft;
3497 if (r.top < mStableFullscreenTop) r.top = mStableFullscreenTop;
3498 if (r.right > mStableFullscreenRight) r.right = mStableFullscreenRight;
3499 if (r.bottom > mStableFullscreenBottom) r.bottom = mStableFullscreenBottom;
3500 } else {
3501 if (r.left < mStableLeft) r.left = mStableLeft;
3502 if (r.top < mStableTop) r.top = mStableTop;
3503 if (r.right > mStableRight) r.right = mStableRight;
3504 if (r.bottom > mStableBottom) r.bottom = mStableBottom;
3505 }
3506 }
3507 }
3508
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003509 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07003510 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003511 public void layoutWindowLw(WindowState win, WindowState attached) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003512 // we've already done the status bar
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003513 final WindowManager.LayoutParams attrs = win.getAttrs();
3514 if ((win == mStatusBar && (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) == 0) ||
3515 win == mNavigationBar) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003516 return;
3517 }
Craig Mautner69b08182012-09-05 13:07:13 -07003518 final boolean isDefaultDisplay = win.isDefaultDisplay();
3519 final boolean needsToOffsetInputMethodTarget = isDefaultDisplay &&
satok1bc0a492012-04-25 22:47:12 +09003520 (win == mLastInputMethodTargetWindow && mLastInputMethodWindow != null);
3521 if (needsToOffsetInputMethodTarget) {
Craig Mautnereda67292013-04-28 13:50:14 -07003522 if (DEBUG_LAYOUT) Slog.i(TAG, "Offset ime target window by the last ime window state");
satok1bc0a492012-04-25 22:47:12 +09003523 offsetInputMethodWindowLw(mLastInputMethodWindow);
3524 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003525
John Spurlockc6d1c602014-01-17 15:22:06 -05003526 final int fl = PolicyControl.getWindowFlags(win, attrs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003527 final int sim = attrs.softInputMode;
John Spurlock1db8b682014-02-18 11:18:59 -05003528 final int sysUiFl = PolicyControl.getSystemUiVisibility(win, null);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003529
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003530 final Rect pf = mTmpParentFrame;
3531 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003532 final Rect of = mTmpOverscanFrame;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003533 final Rect cf = mTmpContentFrame;
3534 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04003535 final Rect dcf = mTmpDecorFrame;
Adrian Roosfa104232014-06-20 16:10:14 -07003536 final Rect sf = mTmpStableFrame;
John Spurlock46646232013-09-30 22:32:42 -04003537 dcf.setEmpty();
Craig Mautner69b08182012-09-05 13:07:13 -07003538
3539 final boolean hasNavBar = (isDefaultDisplay && mHasNavigationBar
Daniel Sandler36412a72011-08-04 09:35:13 -04003540 && mNavigationBar != null && mNavigationBar.isVisibleLw());
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003541
Craig Mautnerf683b562012-10-02 11:10:57 -07003542 final int adjust = sim & SOFT_INPUT_MASK_ADJUST;
3543
Adrian Roosfa104232014-06-20 16:10:14 -07003544 if (isDefaultDisplay) {
3545 sf.set(mStableLeft, mStableTop, mStableRight, mStableBottom);
3546 } else {
3547 sf.set(mOverscanLeft, mOverscanTop, mOverscanRight, mOverscanBottom);
3548 }
3549
Craig Mautner69b08182012-09-05 13:07:13 -07003550 if (!isDefaultDisplay) {
3551 if (attached != null) {
3552 // If this window is attached to another, our display
3553 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003554 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07003555 } else {
3556 // Give the window full screen.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003557 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3558 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3559 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08003560 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003561 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003562 = mOverscanScreenTop + mOverscanScreenHeight;
Craig Mautner69b08182012-09-05 13:07:13 -07003563 }
Dianne Hackbornae6688b2015-02-11 17:02:41 -08003564 } else if (attrs.type == TYPE_INPUT_METHOD || attrs.type == TYPE_VOICE_INTERACTION) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003565 pf.left = df.left = of.left = cf.left = vf.left = mDockLeft;
3566 pf.top = df.top = of.top = cf.top = vf.top = mDockTop;
3567 pf.right = df.right = of.right = cf.right = vf.right = mDockRight;
John Spurlockc68d5772013-10-08 11:47:58 -04003568 // IM dock windows layout below the nav bar...
John Spurlock57beb3b2013-10-10 10:27:44 -04003569 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlockc68d5772013-10-08 11:47:58 -04003570 // ...with content insets above the nav bar
3571 cf.bottom = vf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003572 // IM dock windows always go to the bottom of the screen.
3573 attrs.gravity = Gravity.BOTTOM;
3574 mDockLayer = win.getSurfaceLayer();
Jorim Jaggie0700182014-08-21 01:12:37 +02003575 } else if (win == mStatusBar && (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
3576 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3577 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3578 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
3579 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight + mUnrestrictedScreenTop;
3580 cf.left = vf.left = mStableLeft;
3581 cf.top = vf.top = mStableTop;
3582 cf.right = vf.right = mStableRight;
3583 vf.bottom = mStableBottom;
3584 cf.bottom = mContentBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003585 } else {
John Spurlock46646232013-09-30 22:32:42 -04003586
3587 // Default policy decor for the default display
3588 dcf.left = mSystemLeft;
3589 dcf.top = mSystemTop;
3590 dcf.right = mSystemRight;
3591 dcf.bottom = mSystemBottom;
John Spurlockbd957402013-10-03 11:38:39 -04003592 final boolean inheritTranslucentDecor = (attrs.privateFlags
3593 & WindowManager.LayoutParams.PRIVATE_FLAG_INHERIT_TRANSLUCENT_DECOR) != 0;
John Spurlock65567d42013-10-08 10:08:32 -04003594 final boolean isAppWindow =
3595 attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW &&
3596 attrs.type <= WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
3597 final boolean topAtRest =
3598 win == mTopFullscreenOpaqueWindowState && !win.isAnimatingLw();
3599 if (isAppWindow && !inheritTranslucentDecor && !topAtRest) {
John Spurlockbd957402013-10-03 11:38:39 -04003600 if ((sysUiFl & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0
3601 && (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0
Adrian Roosea562512014-05-05 13:33:03 +02003602 && (fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) == 0
3603 && (fl & WindowManager.LayoutParams.
3604 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04003605 // Ensure policy decor includes status bar
3606 dcf.top = mStableTop;
3607 }
John Spurlockbd957402013-10-03 11:38:39 -04003608 if ((fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) == 0
Adrian Roosea562512014-05-05 13:33:03 +02003609 && (sysUiFl & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0
3610 && (fl & WindowManager.LayoutParams.
3611 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04003612 // Ensure policy decor includes navigation bar
3613 dcf.bottom = mStableBottom;
3614 dcf.right = mStableRight;
3615 }
3616 }
3617
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003618 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
3619 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
RoboErik8a2cfc32014-05-16 11:19:38 -07003620 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003621 + "): IN_SCREEN, INSET_DECOR");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003622 // This is the case for a normal activity window: we want it
3623 // to cover all of the screen space, and it can take care of
3624 // moving its contents to account for screen decorations that
3625 // intrude into that space.
3626 if (attached != null) {
3627 // If this window is attached to another, our display
3628 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003629 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003630 } else {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003631 if (attrs.type == TYPE_STATUS_BAR_PANEL
3632 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Joe Onorato29fc2c92010-11-24 10:26:50 -08003633 // Status bar panels are the only windows who can go on top of
3634 // the status bar. They are protected by the STATUS_BAR_SERVICE
3635 // permission, so they have the same privileges as the status
3636 // bar itself.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003637 //
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003638 // However, they should still dodge the navigation bar if it exists.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003639
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003640 pf.left = df.left = of.left = hasNavBar
3641 ? mDockLeft : mUnrestrictedScreenLeft;
3642 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3643 pf.right = df.right = of.right = hasNavBar
3644 ? mRestrictedScreenLeft+mRestrictedScreenWidth
3645 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3646 pf.bottom = df.bottom = of.bottom = hasNavBar
3647 ? mRestrictedScreenTop+mRestrictedScreenHeight
3648 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003649
Craig Mautnereda67292013-04-28 13:50:14 -07003650 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003651 "Laying out status bar window: (%d,%d - %d,%d)",
3652 pf.left, pf.top, pf.right, pf.bottom));
John Spurlock46646232013-09-30 22:32:42 -04003653 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08003654 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3655 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3656 // Asking to layout into the overscan region, so give it that pure
3657 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003658 pf.left = df.left = of.left = mOverscanScreenLeft;
3659 pf.top = df.top = of.top = mOverscanScreenTop;
3660 pf.right = df.right = of.right = mOverscanScreenLeft + mOverscanScreenWidth;
3661 pf.bottom = df.bottom = of.bottom = mOverscanScreenTop
3662 + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003663 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003664 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003665 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3666 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003667 // Asking for layout as if the nav bar is hidden, lets the
Dianne Hackbornc652de82013-02-15 16:32:56 -08003668 // application extend into the unrestricted overscan screen area. We
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003669 // only do this for application windows to ensure no window that
3670 // can be above the nav bar can do this.
Dianne Hackborn313440842013-02-19 19:22:59 -08003671 pf.left = df.left = mOverscanScreenLeft;
3672 pf.top = df.top = mOverscanScreenTop;
3673 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
3674 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003675 // We need to tell the app about where the frame inside the overscan
3676 // is, so it can inset its content by that amount -- it didn't ask
3677 // to actually extend itself into the overscan region.
3678 of.left = mUnrestrictedScreenLeft;
3679 of.top = mUnrestrictedScreenTop;
3680 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3681 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003682 } else {
Dianne Hackborn313440842013-02-19 19:22:59 -08003683 pf.left = df.left = mRestrictedOverscanScreenLeft;
3684 pf.top = df.top = mRestrictedOverscanScreenTop;
3685 pf.right = df.right = mRestrictedOverscanScreenLeft
3686 + mRestrictedOverscanScreenWidth;
3687 pf.bottom = df.bottom = mRestrictedOverscanScreenTop
3688 + mRestrictedOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003689 // We need to tell the app about where the frame inside the overscan
3690 // is, so it can inset its content by that amount -- it didn't ask
3691 // to actually extend itself into the overscan region.
3692 of.left = mUnrestrictedScreenLeft;
3693 of.top = mUnrestrictedScreenTop;
3694 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3695 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003696 }
Craig Mautner69b08182012-09-05 13:07:13 -07003697
John Spurlock46646232013-09-30 22:32:42 -04003698 if ((fl & FLAG_FULLSCREEN) == 0) {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003699 if (win.isVoiceInteraction()) {
3700 cf.left = mVoiceContentLeft;
3701 cf.top = mVoiceContentTop;
3702 cf.right = mVoiceContentRight;
3703 cf.bottom = mVoiceContentBottom;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003704 } else {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003705 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
3706 cf.left = mDockLeft;
3707 cf.top = mDockTop;
3708 cf.right = mDockRight;
3709 cf.bottom = mDockBottom;
3710 } else {
3711 cf.left = mContentLeft;
3712 cf.top = mContentTop;
3713 cf.right = mContentRight;
3714 cf.bottom = mContentBottom;
3715 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003716 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003717 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003718 // Full screen windows are always given a layout that is as if the
3719 // status bar and other transient decors are gone. This is to avoid
3720 // bad states when moving from a window that is not hding the
3721 // status bar to one that is.
3722 cf.left = mRestrictedScreenLeft;
3723 cf.top = mRestrictedScreenTop;
3724 cf.right = mRestrictedScreenLeft + mRestrictedScreenWidth;
3725 cf.bottom = mRestrictedScreenTop + mRestrictedScreenHeight;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003726 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003727 applyStableConstraints(sysUiFl, fl, cf);
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003728 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3729 vf.left = mCurLeft;
3730 vf.top = mCurTop;
3731 vf.right = mCurRight;
3732 vf.bottom = mCurBottom;
3733 } else {
3734 vf.set(cf);
3735 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003736 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003737 } else if ((fl & FLAG_LAYOUT_IN_SCREEN) != 0 || (sysUiFl
3738 & (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
3739 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)) != 0) {
Craig Mautnereda67292013-04-28 13:50:14 -07003740 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3741 "): IN_SCREEN");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003742 // A window that has requested to fill the entire screen just
3743 // gets everything, period.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003744 if (attrs.type == TYPE_STATUS_BAR_PANEL
3745 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003746 pf.left = df.left = of.left = cf.left = hasNavBar
3747 ? mDockLeft : mUnrestrictedScreenLeft;
3748 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
3749 pf.right = df.right = of.right = cf.right = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003750 ? mRestrictedScreenLeft+mRestrictedScreenWidth
Dianne Hackbornc652de82013-02-15 16:32:56 -08003751 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003752 pf.bottom = df.bottom = of.bottom = cf.bottom = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003753 ? mRestrictedScreenTop+mRestrictedScreenHeight
Dianne Hackbornc652de82013-02-15 16:32:56 -08003754 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07003755 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler36412a72011-08-04 09:35:13 -04003756 "Laying out IN_SCREEN status bar window: (%d,%d - %d,%d)",
3757 pf.left, pf.top, pf.right, pf.bottom));
Jim Millere898ac52012-04-06 17:10:57 -07003758 } else if (attrs.type == TYPE_NAVIGATION_BAR
3759 || attrs.type == TYPE_NAVIGATION_BAR_PANEL) {
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003760 // The navigation bar has Real Ultimate Power.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003761 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3762 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3763 pf.right = df.right = of.right = mUnrestrictedScreenLeft
3764 + mUnrestrictedScreenWidth;
3765 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop
3766 + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07003767 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003768 "Laying out navigation bar window: (%d,%d - %d,%d)",
3769 pf.left, pf.top, pf.right, pf.bottom));
Dianne Hackborn01011c32012-02-21 13:54:21 -08003770 } else if ((attrs.type == TYPE_SECURE_SYSTEM_OVERLAY
3771 || attrs.type == TYPE_BOOT_PROGRESS)
Jeff Brownbfcb60a2011-09-08 18:51:14 -07003772 && ((fl & FLAG_FULLSCREEN) != 0)) {
3773 // Fullscreen secure system overlays get what they ask for.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003774 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3775 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3776 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
3777 + mOverscanScreenWidth;
3778 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
3779 + mOverscanScreenHeight;
Craig Mautner165be0c2015-01-27 15:16:58 -08003780 } else if (attrs.type == TYPE_BOOT_PROGRESS) {
Dianne Hackborn01011c32012-02-21 13:54:21 -08003781 // Boot progress screen always covers entire display.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003782 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3783 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3784 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
3785 + mOverscanScreenWidth;
3786 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
3787 + mOverscanScreenHeight;
John Spurlockef4adae2013-08-26 17:58:58 -04003788 } else if (attrs.type == TYPE_WALLPAPER) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07003789 // The wallpaper also has Real Ultimate Power, but we want to tell
3790 // it about the overscan area.
3791 pf.left = df.left = mOverscanScreenLeft;
3792 pf.top = df.top = mOverscanScreenTop;
3793 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
3794 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
3795 of.left = cf.left = mUnrestrictedScreenLeft;
3796 of.top = cf.top = mUnrestrictedScreenTop;
3797 of.right = cf.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3798 of.bottom = cf.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlock46646232013-09-30 22:32:42 -04003799 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08003800 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3801 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3802 // Asking to layout into the overscan region, so give it that pure
3803 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003804 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3805 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3806 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08003807 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003808 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003809 = mOverscanScreenTop + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003810 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003811 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Craig Mautnerbeac1062014-06-03 14:38:57 -07003812 && (attrs.type == TYPE_STATUS_BAR
3813 || attrs.type == TYPE_TOAST
John Spurlock34e13d92013-08-10 06:52:28 -04003814 || (attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3815 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW))) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003816 // Asking for layout as if the nav bar is hidden, lets the
3817 // application extend into the unrestricted screen area. We
John Spurlock34e13d92013-08-10 06:52:28 -04003818 // only do this for application windows (or toasts) to ensure no window that
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003819 // can be above the nav bar can do this.
3820 // XXX This assumes that an app asking for this will also
3821 // ask for layout in only content. We can't currently figure out
3822 // what the screen would be if only laying out to hide the nav bar.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003823 pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft;
3824 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
3825 pf.right = df.right = of.right = cf.right = mUnrestrictedScreenLeft
3826 + mUnrestrictedScreenWidth;
3827 pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop
3828 + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003829 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003830 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
3831 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
3832 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
3833 + mRestrictedScreenWidth;
3834 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
3835 + mRestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003836 }
Craig Mautner69b08182012-09-05 13:07:13 -07003837
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003838 applyStableConstraints(sysUiFl, fl, cf);
Craig Mautner69b08182012-09-05 13:07:13 -07003839
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003840 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3841 vf.left = mCurLeft;
3842 vf.top = mCurTop;
3843 vf.right = mCurRight;
3844 vf.bottom = mCurBottom;
3845 } else {
3846 vf.set(cf);
3847 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003848 } else if (attached != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07003849 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3850 "): attached to " + attached);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003851 // A child window should be placed inside of the same visible
3852 // frame that its parent had.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003853 setAttachedWindowFrames(win, fl, adjust, attached, false, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003854 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07003855 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3856 "): normal window");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003857 // Otherwise, a normal window must be placed inside the content
3858 // of all screen decorations.
Dianne Hackborna239c842011-06-01 12:28:20 -07003859 if (attrs.type == TYPE_STATUS_BAR_PANEL) {
3860 // Status bar panels are the only windows who can go on top of
3861 // the status bar. They are protected by the STATUS_BAR_SERVICE
3862 // permission, so they have the same privileges as the status
3863 // bar itself.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003864 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
3865 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
3866 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
3867 + mRestrictedScreenWidth;
3868 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
3869 + mRestrictedScreenHeight;
John Spurlock414c1f02013-12-04 13:47:36 -05003870 } else if (attrs.type == TYPE_TOAST || attrs.type == TYPE_SYSTEM_ALERT
3871 || attrs.type == TYPE_VOLUME_OVERLAY) {
3872 // These dialogs are stable to interim decor changes.
John Spurlockbd957402013-10-03 11:38:39 -04003873 pf.left = df.left = of.left = cf.left = mStableLeft;
3874 pf.top = df.top = of.top = cf.top = mStableTop;
3875 pf.right = df.right = of.right = cf.right = mStableRight;
3876 pf.bottom = df.bottom = of.bottom = cf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003877 } else {
Dianne Hackborna239c842011-06-01 12:28:20 -07003878 pf.left = mContentLeft;
3879 pf.top = mContentTop;
3880 pf.right = mContentRight;
3881 pf.bottom = mContentBottom;
Dianne Hackborn20d94742014-05-29 18:35:45 -07003882 if (win.isVoiceInteraction()) {
3883 df.left = of.left = cf.left = mVoiceContentLeft;
3884 df.top = of.top = cf.top = mVoiceContentTop;
3885 df.right = of.right = cf.right = mVoiceContentRight;
3886 df.bottom = of.bottom = cf.bottom = mVoiceContentBottom;
3887 } else if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003888 df.left = of.left = cf.left = mDockLeft;
3889 df.top = of.top = cf.top = mDockTop;
3890 df.right = of.right = cf.right = mDockRight;
3891 df.bottom = of.bottom = cf.bottom = mDockBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07003892 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003893 df.left = of.left = cf.left = mContentLeft;
3894 df.top = of.top = cf.top = mContentTop;
3895 df.right = of.right = cf.right = mContentRight;
3896 df.bottom = of.bottom = cf.bottom = mContentBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07003897 }
3898 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3899 vf.left = mCurLeft;
3900 vf.top = mCurTop;
3901 vf.right = mCurRight;
3902 vf.bottom = mCurBottom;
3903 } else {
3904 vf.set(cf);
3905 }
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003906 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003907 }
3908 }
Craig Mautner69b08182012-09-05 13:07:13 -07003909
Craig Mautnerb816bed2013-07-23 10:26:17 -07003910 // TYPE_SYSTEM_ERROR is above the NavigationBar so it can't be allowed to extend over it.
3911 if ((fl & FLAG_LAYOUT_NO_LIMITS) != 0 && attrs.type != TYPE_SYSTEM_ERROR) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07003912 df.left = df.top = -10000;
3913 df.right = df.bottom = 10000;
3914 if (attrs.type != TYPE_WALLPAPER) {
3915 of.left = of.top = cf.left = cf.top = vf.left = vf.top = -10000;
3916 of.right = of.bottom = cf.right = cf.bottom = vf.right = vf.bottom = 10000;
3917 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003918 }
3919
Craig Mautnereda67292013-04-28 13:50:14 -07003920 if (DEBUG_LAYOUT) Slog.v(TAG, "Compute frame " + attrs.getTitle()
The Android Open Source Project11267662009-03-18 17:39:47 -07003921 + ": sim=#" + Integer.toHexString(sim)
RoboErik8a2cfc32014-05-16 11:19:38 -07003922 + " attach=" + attached + " type=" + attrs.type
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003923 + String.format(" flags=0x%08x", fl)
The Android Open Source Project11267662009-03-18 17:39:47 -07003924 + " pf=" + pf.toShortString() + " df=" + df.toShortString()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003925 + " of=" + of.toShortString()
John Spurlock46646232013-09-30 22:32:42 -04003926 + " cf=" + cf.toShortString() + " vf=" + vf.toShortString()
Adrian Roosfa104232014-06-20 16:10:14 -07003927 + " dcf=" + dcf.toShortString()
3928 + " sf=" + sf.toShortString());
Craig Mautner69b08182012-09-05 13:07:13 -07003929
Adrian Roosfa104232014-06-20 16:10:14 -07003930 win.computeFrameLw(pf, df, of, cf, vf, dcf, sf);
Craig Mautner69b08182012-09-05 13:07:13 -07003931
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003932 // Dock windows carve out the bottom of the screen, so normal windows
3933 // can't appear underneath them.
Craig Mautner8bd206b2012-10-03 10:32:02 -07003934 if (attrs.type == TYPE_INPUT_METHOD && win.isVisibleOrBehindKeyguardLw()
3935 && !win.getGivenInsetsPendingLw()) {
satok1bc0a492012-04-25 22:47:12 +09003936 setLastInputMethodWindowLw(null, null);
3937 offsetInputMethodWindowLw(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003938 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003939 if (attrs.type == TYPE_VOICE_INTERACTION && win.isVisibleOrBehindKeyguardLw()
3940 && !win.getGivenInsetsPendingLw()) {
3941 offsetVoiceInputWindowLw(win);
3942 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003943 }
3944
satok1bc0a492012-04-25 22:47:12 +09003945 private void offsetInputMethodWindowLw(WindowState win) {
Dianne Hackbornae6688b2015-02-11 17:02:41 -08003946 int top = win.getDisplayFrameLw().top;
satok1bc0a492012-04-25 22:47:12 +09003947 top += win.getGivenContentInsetsLw().top;
3948 if (mContentBottom > top) {
3949 mContentBottom = top;
3950 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003951 if (mVoiceContentBottom > top) {
3952 mVoiceContentBottom = top;
3953 }
satok1bc0a492012-04-25 22:47:12 +09003954 top = win.getVisibleFrameLw().top;
3955 top += win.getGivenVisibleInsetsLw().top;
3956 if (mCurBottom > top) {
3957 mCurBottom = top;
3958 }
Craig Mautnereda67292013-04-28 13:50:14 -07003959 if (DEBUG_LAYOUT) Slog.v(TAG, "Input method: mDockBottom="
satok1bc0a492012-04-25 22:47:12 +09003960 + mDockBottom + " mContentBottom="
3961 + mContentBottom + " mCurBottom=" + mCurBottom);
3962 }
3963
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003964 private void offsetVoiceInputWindowLw(WindowState win) {
Dianne Hackbornae6688b2015-02-11 17:02:41 -08003965 int top = win.getDisplayFrameLw().top;
3966 top += win.getGivenContentInsetsLw().top;
3967 if (mVoiceContentBottom > top) {
3968 mVoiceContentBottom = top;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003969 }
3970 }
3971
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003972 /** {@inheritDoc} */
Craig Mautner61ac6bb2012-02-02 17:29:33 -08003973 @Override
3974 public void finishLayoutLw() {
3975 return;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003976 }
3977
3978 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003979 @Override
Craig Mautner39834192012-09-02 07:47:24 -07003980 public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) {
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003981 mTopFullscreenOpaqueWindowState = null;
Adrian Rooscd3884d2015-02-18 17:25:23 +01003982 mTopFullscreenOpaqueOrDimmingWindowState = null;
Craig Mautner2bc789b2014-03-19 19:48:38 -07003983 mAppsToBeHidden.clear();
Jorim Jaggic13fcac2014-09-11 17:36:57 +02003984 mAppsThatDismissKeyguard.clear();
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003985 mForceStatusBar = false;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003986 mForceStatusBarFromKeyguard = false;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08003987 mForcingShowNavBar = false;
3988 mForcingShowNavBarLayer = -1;
RoboErik8a2cfc32014-05-16 11:19:38 -07003989
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003990 mHideLockScreen = false;
3991 mAllowLockscreenWhenOn = false;
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003992 mDismissKeyguard = DISMISS_KEYGUARD_NONE;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003993 mShowingLockscreen = false;
3994 mShowingDream = false;
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003995 mWinShowWhenLocked = null;
Jim Millerab954542014-10-10 18:21:49 -07003996 mKeyguardSecure = isKeyguardSecure();
3997 mKeyguardSecureIncludingHidden = mKeyguardSecure
3998 && (mKeyguardDelegate != null && mKeyguardDelegate.isShowing());
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003999 }
4000
4001 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004002 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004003 public void applyPostLayoutPolicyLw(WindowState win, WindowManager.LayoutParams attrs) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004004 if (DEBUG_LAYOUT) Slog.i(TAG, "Win " + win + ": isVisibleOrBehindKeyguardLw="
4005 + win.isVisibleOrBehindKeyguardLw());
John Spurlockc6d1c602014-01-17 15:22:06 -05004006 final int fl = PolicyControl.getWindowFlags(win, attrs);
John Spurlock414c1f02013-12-04 13:47:36 -05004007 if (mTopFullscreenOpaqueWindowState == null
4008 && win.isVisibleLw() && attrs.type == TYPE_INPUT_METHOD) {
4009 mForcingShowNavBar = true;
4010 mForcingShowNavBarLayer = win.getSurfaceLayer();
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08004011 }
Jorim Jaggiafd4a552014-04-08 15:13:05 +02004012 if (attrs.type == TYPE_STATUS_BAR && (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Jorim Jaggiafd4a552014-04-08 15:13:05 +02004013 mForceStatusBarFromKeyguard = true;
4014 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004015 if (mTopFullscreenOpaqueWindowState == null &&
Dianne Hackborn01b02a72012-01-12 14:05:03 -08004016 win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()) {
John Spurlockc6d1c602014-01-17 15:22:06 -05004017 if ((fl & FLAG_FORCE_NOT_FULLSCREEN) != 0) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004018 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004019 mForceStatusBarFromKeyguard = true;
4020 } else {
4021 mForceStatusBar = true;
4022 }
4023 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004024 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004025 mShowingLockscreen = true;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004026 }
Craig Mautnerab55e522014-03-03 13:26:03 -08004027 boolean appWindow = attrs.type >= FIRST_APPLICATION_WINDOW
Craig Mautner7d7808f2014-09-11 18:02:38 -07004028 && attrs.type < FIRST_SYSTEM_WINDOW;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004029 if (attrs.type == TYPE_DREAM) {
Jeff Brownc8018eb2012-10-29 21:33:27 -07004030 // If the lockscreen was showing when the dream started then wait
4031 // for the dream to draw before hiding the lockscreen.
4032 if (!mDreamingLockscreen
4033 || (win.isVisibleLw() && win.hasDrawnLw())) {
4034 mShowingDream = true;
Craig Mautnerab55e522014-03-03 13:26:03 -08004035 appWindow = true;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004036 }
4037 }
Craig Mautnerab55e522014-03-03 13:26:03 -08004038
Craig Mautner00156ec2014-03-06 22:29:02 -08004039 final boolean showWhenLocked = (fl & FLAG_SHOW_WHEN_LOCKED) != 0;
Craig Mautner74ee9382014-04-01 15:20:16 -07004040 final boolean dismissKeyguard = (fl & FLAG_DISMISS_KEYGUARD) != 0;
Craig Mautnerab55e522014-03-03 13:26:03 -08004041 if (appWindow) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004042 final IApplicationToken appToken = win.getAppToken();
4043 if (showWhenLocked) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004044 // Remove any previous windows with the same appToken.
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004045 mAppsToBeHidden.remove(appToken);
4046 mAppsThatDismissKeyguard.remove(appToken);
Craig Mautnerca0a1242014-12-02 12:25:14 -08004047 if (mAppsToBeHidden.isEmpty()) {
Craig Mautner192d6042014-12-02 23:24:48 -08004048 if (dismissKeyguard && !mKeyguardSecure) {
4049 mAppsThatDismissKeyguard.add(appToken);
4050 } else {
Craig Mautnerca0a1242014-12-02 12:25:14 -08004051 mWinShowWhenLocked = win;
4052 mHideLockScreen = true;
4053 mForceStatusBarFromKeyguard = false;
Craig Mautnerca0a1242014-12-02 12:25:14 -08004054 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004055 }
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004056 } else if (dismissKeyguard) {
Jim Millerab954542014-10-10 18:21:49 -07004057 if (mKeyguardSecure) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004058 mAppsToBeHidden.add(appToken);
4059 } else {
4060 mAppsToBeHidden.remove(appToken);
4061 }
4062 mAppsThatDismissKeyguard.add(appToken);
Craig Mautner2bc789b2014-03-19 19:48:38 -07004063 } else {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004064 mAppsToBeHidden.add(appToken);
Craig Mautner2bc789b2014-03-19 19:48:38 -07004065 }
Craig Mautnerab55e522014-03-03 13:26:03 -08004066 if (attrs.x == 0 && attrs.y == 0
4067 && attrs.width == WindowManager.LayoutParams.MATCH_PARENT
4068 && attrs.height == WindowManager.LayoutParams.MATCH_PARENT) {
4069 if (DEBUG_LAYOUT) Slog.v(TAG, "Fullscreen window: " + win);
4070 mTopFullscreenOpaqueWindowState = win;
Adrian Rooscd3884d2015-02-18 17:25:23 +01004071 if (mTopFullscreenOpaqueOrDimmingWindowState == null) {
4072 mTopFullscreenOpaqueOrDimmingWindowState = win;
4073 }
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004074 if (!mAppsThatDismissKeyguard.isEmpty() &&
4075 mDismissKeyguard == DISMISS_KEYGUARD_NONE) {
4076 if (DEBUG_LAYOUT) Slog.v(TAG,
4077 "Setting mDismissKeyguard true by win " + win);
4078 mDismissKeyguard = mWinDismissingKeyguard == win ?
4079 DISMISS_KEYGUARD_CONTINUE : DISMISS_KEYGUARD_START;
4080 mWinDismissingKeyguard = win;
Jim Millerab954542014-10-10 18:21:49 -07004081 mForceStatusBarFromKeyguard = mShowingLockscreen && mKeyguardSecure;
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004082 } else if (mAppsToBeHidden.isEmpty() && showWhenLocked) {
4083 if (DEBUG_LAYOUT) Slog.v(TAG,
4084 "Setting mHideLockScreen to true by win " + win);
4085 mHideLockScreen = true;
4086 mForceStatusBarFromKeyguard = false;
Craig Mautnerab55e522014-03-03 13:26:03 -08004087 }
Craig Mautner00156ec2014-03-06 22:29:02 -08004088 if ((fl & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) {
Craig Mautnerab55e522014-03-03 13:26:03 -08004089 mAllowLockscreenWhenOn = true;
4090 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004091 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004092
4093 if (mWinShowWhenLocked != null &&
4094 mWinShowWhenLocked.getAppToken() != win.getAppToken()) {
4095 win.hideLw(false);
4096 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004097 }
4098 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01004099 if (mTopFullscreenOpaqueOrDimmingWindowState == null
4100 && win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()
4101 && win.isDimming()) {
4102 mTopFullscreenOpaqueOrDimmingWindowState = win;
4103 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004104 }
4105
4106 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004107 @Override
Craig Mautner39834192012-09-02 07:47:24 -07004108 public int finishPostLayoutPolicyLw() {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004109 if (mWinShowWhenLocked != null &&
4110 mWinShowWhenLocked != mTopFullscreenOpaqueWindowState) {
4111 // A dialog is dismissing the keyguard. Put the wallpaper behind it and hide the
4112 // fullscreen window.
4113 // TODO: Make sure FLAG_SHOW_WALLPAPER is restored when dialog is dismissed. Or not.
4114 mWinShowWhenLocked.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
4115 mTopFullscreenOpaqueWindowState.hideLw(false);
4116 mTopFullscreenOpaqueWindowState = mWinShowWhenLocked;
4117 }
4118
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004119 int changes = 0;
Joe Onorato93056472010-09-10 10:30:46 -04004120 boolean topIsFullscreen = false;
Daniel Sandlere02d8082010-10-08 15:13:22 -04004121
4122 final WindowManager.LayoutParams lp = (mTopFullscreenOpaqueWindowState != null)
4123 ? mTopFullscreenOpaqueWindowState.getAttrs()
4124 : null;
4125
Jeff Brownc8018eb2012-10-29 21:33:27 -07004126 // If we are not currently showing a dream then remember the current
4127 // lockscreen state. We will use this to determine whether the dream
4128 // started while the lockscreen was showing and remember this state
4129 // while the dream is showing.
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004130 if (!mShowingDream) {
4131 mDreamingLockscreen = mShowingLockscreen;
4132 }
4133
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004134 if (mStatusBar != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07004135 if (DEBUG_LAYOUT) Slog.i(TAG, "force=" + mForceStatusBar
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004136 + " forcefkg=" + mForceStatusBarFromKeyguard
Dianne Hackbornd70bc2f2009-10-06 23:25:51 -07004137 + " top=" + mTopFullscreenOpaqueWindowState);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004138 if (mForceStatusBar || mForceStatusBarFromKeyguard) {
Craig Mautnereda67292013-04-28 13:50:14 -07004139 if (DEBUG_LAYOUT) Slog.v(TAG, "Showing status bar: forced");
John Spurlock27735a42013-08-14 17:57:38 -04004140 if (mStatusBarController.setBarShowingLw(true)) {
4141 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4142 }
Craig Mautner81defc72013-10-29 11:10:42 -07004143 // Maintain fullscreen layout until incoming animation is complete.
4144 topIsFullscreen = mTopIsFullscreen && mStatusBar.isAnimatingLw();
John Spurlockf92b6162013-11-11 15:01:16 -05004145 // Transient status bar on the lockscreen is not allowed
4146 if (mForceStatusBarFromKeyguard && mStatusBarController.isTransientShowing()) {
4147 mStatusBarController.updateVisibilityLw(false /*transientAllowed*/,
4148 mLastSystemUiFlags, mLastSystemUiFlags);
4149 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004150 } else if (mTopFullscreenOpaqueWindowState != null) {
John Spurlockc6d1c602014-01-17 15:22:06 -05004151 final int fl = PolicyControl.getWindowFlags(null, lp);
Joe Onorato93056472010-09-10 10:30:46 -04004152 if (localLOGV) {
Craig Mautnereda67292013-04-28 13:50:14 -07004153 Slog.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw()
Joe Onorato93056472010-09-10 10:30:46 -04004154 + " shown frame: " + mTopFullscreenOpaqueWindowState.getShownFrameLw());
Craig Mautnereda67292013-04-28 13:50:14 -07004155 Slog.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs()
John Spurlockc6d1c602014-01-17 15:22:06 -05004156 + " lp.flags=0x" + Integer.toHexString(fl));
Joe Onorato93056472010-09-10 10:30:46 -04004157 }
John Spurlockc6d1c602014-01-17 15:22:06 -05004158 topIsFullscreen = (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004159 || (mLastSystemUiFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
Joe Onorato93056472010-09-10 10:30:46 -04004160 // The subtle difference between the window for mTopFullscreenOpaqueWindowState
Mark Dolinerd0646dc2014-08-27 16:04:02 -07004161 // and mTopIsFullscreen is that mTopIsFullscreen is set only if the window
Joe Onorato93056472010-09-10 10:30:46 -04004162 // has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the
4163 // case though.
John Spurlock27735a42013-08-14 17:57:38 -04004164 if (mStatusBarController.isTransientShowing()) {
4165 if (mStatusBarController.setBarShowingLw(true)) {
John Spurlock32beb2c2013-03-11 10:16:47 -04004166 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4167 }
4168 } else if (topIsFullscreen) {
Craig Mautnereda67292013-04-28 13:50:14 -07004169 if (DEBUG_LAYOUT) Slog.v(TAG, "** HIDING status bar");
John Spurlock27735a42013-08-14 17:57:38 -04004170 if (mStatusBarController.setBarShowingLw(false)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004171 changes |= FINISH_LAYOUT_REDO_LAYOUT;
Craig Mautnereda67292013-04-28 13:50:14 -07004172 } else {
Craig Mautnerc5a6e442013-06-05 17:22:35 -07004173 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar already hiding");
Daniel Sandler40427442010-07-16 11:44:52 -04004174 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004175 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07004176 if (DEBUG_LAYOUT) Slog.v(TAG, "** SHOWING status bar: top is not fullscreen");
John Spurlock27735a42013-08-14 17:57:38 -04004177 if (mStatusBarController.setBarShowingLw(true)) {
4178 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4179 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004180 }
4181 }
4182 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04004183
Craig Mautner81defc72013-10-29 11:10:42 -07004184 if (mTopIsFullscreen != topIsFullscreen) {
4185 if (!topIsFullscreen) {
4186 // Force another layout when status bar becomes fully shown.
4187 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4188 }
4189 mTopIsFullscreen = topIsFullscreen;
4190 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04004191
Craig Mautner39834192012-09-02 07:47:24 -07004192 // Hide the key guard if a visible window explicitly specifies that it wants to be
4193 // displayed when the screen is locked.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004194 if (mKeyguardDelegate != null && mStatusBar != null) {
4195 if (localLOGV) Slog.v(TAG, "finishPostLayoutPolicyLw: mHideKeyguard="
4196 + mHideLockScreen);
Jim Millerab954542014-10-10 18:21:49 -07004197 if (mDismissKeyguard != DISMISS_KEYGUARD_NONE && !mKeyguardSecure) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004198 mKeyguardHidden = true;
Jim Millerab954542014-10-10 18:21:49 -07004199 if (setKeyguardOccludedLw(true)) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004200 changes |= FINISH_LAYOUT_REDO_LAYOUT
4201 | FINISH_LAYOUT_REDO_CONFIG
4202 | FINISH_LAYOUT_REDO_WALLPAPER;
4203 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004204 if (mKeyguardDelegate.isShowing()) {
4205 mHandler.post(new Runnable() {
4206 @Override
4207 public void run() {
4208 mKeyguardDelegate.keyguardDone(false, false);
4209 }
4210 });
4211 }
4212 } else if (mHideLockScreen) {
4213 mKeyguardHidden = true;
Jim Millerab954542014-10-10 18:21:49 -07004214 if (setKeyguardOccludedLw(true)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004215 changes |= FINISH_LAYOUT_REDO_LAYOUT
4216 | FINISH_LAYOUT_REDO_CONFIG
4217 | FINISH_LAYOUT_REDO_WALLPAPER;
4218 }
4219 } else if (mDismissKeyguard != DISMISS_KEYGUARD_NONE) {
4220 // This is the case of keyguard isSecure() and not mHideLockScreen.
4221 if (mDismissKeyguard == DISMISS_KEYGUARD_START) {
4222 // Only launch the next keyguard unlock window once per window.
4223 mKeyguardHidden = false;
Jim Millerab954542014-10-10 18:21:49 -07004224 if (setKeyguardOccludedLw(false)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004225 changes |= FINISH_LAYOUT_REDO_LAYOUT
4226 | FINISH_LAYOUT_REDO_CONFIG
4227 | FINISH_LAYOUT_REDO_WALLPAPER;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004228 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004229 mHandler.post(new Runnable() {
4230 @Override
4231 public void run() {
4232 mKeyguardDelegate.dismiss();
4233 }
4234 });
4235 }
4236 } else {
4237 mWinDismissingKeyguard = null;
4238 mKeyguardHidden = false;
Jim Millerab954542014-10-10 18:21:49 -07004239 if (setKeyguardOccludedLw(false)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004240 changes |= FINISH_LAYOUT_REDO_LAYOUT
4241 | FINISH_LAYOUT_REDO_CONFIG
4242 | FINISH_LAYOUT_REDO_WALLPAPER;
4243 }
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -07004244 }
4245 }
Joe Onorato664644d2011-01-23 17:53:23 -08004246
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004247 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004248 // If the navigation bar has been hidden or shown, we need to do another
4249 // layout pass to update that window.
4250 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4251 }
Joe Onorato664644d2011-01-23 17:53:23 -08004252
Mike Lockwood28569302010-01-28 11:54:40 -05004253 // update since mAllowLockscreenWhenOn might have changed
4254 updateLockScreenTimeout();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004255 return changes;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004256 }
4257
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004258 /**
Jim Millerab954542014-10-10 18:21:49 -07004259 * Updates the occluded state of the Keyguard.
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004260 *
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004261 * @return Whether the flags have changed and we have to redo the layout.
4262 */
Jim Millerab954542014-10-10 18:21:49 -07004263 private boolean setKeyguardOccludedLw(boolean isOccluded) {
4264 boolean wasOccluded = mKeyguardOccluded;
4265 boolean showing = mKeyguardDelegate.isShowing();
4266 if (wasOccluded && !isOccluded && showing) {
4267 mKeyguardOccluded = false;
4268 mKeyguardDelegate.setOccluded(false);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004269 mStatusBar.getAttrs().privateFlags |= PRIVATE_FLAG_KEYGUARD;
4270 mStatusBar.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
4271 return true;
Jim Millerab954542014-10-10 18:21:49 -07004272 } else if (!wasOccluded && isOccluded && showing) {
4273 mKeyguardOccluded = true;
4274 mKeyguardDelegate.setOccluded(true);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004275 mStatusBar.getAttrs().privateFlags &= ~PRIVATE_FLAG_KEYGUARD;
4276 mStatusBar.getAttrs().flags &= ~FLAG_SHOW_WALLPAPER;
4277 return true;
4278 } else {
4279 return false;
4280 }
4281 }
4282
4283 private boolean isStatusBarKeyguard() {
4284 return mStatusBar != null
4285 && (mStatusBar.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
4286 }
4287
Jose Lima9546b202014-07-02 17:21:51 -07004288 @Override
Dianne Hackborn08743722009-12-21 12:16:51 -08004289 public boolean allowAppAnimationsLw() {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004290 if (isStatusBarKeyguard() || mShowingDream) {
Craig Mautner28816302013-10-10 20:31:00 -07004291 // If keyguard or dreams is currently visible, no reason to animate behind it.
Dianne Hackborn08743722009-12-21 12:16:51 -08004292 return false;
4293 }
Dianne Hackborn08743722009-12-21 12:16:51 -08004294 return true;
4295 }
4296
Jose Lima9546b202014-07-02 17:21:51 -07004297 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07004298 public int focusChangedLw(WindowState lastFocus, WindowState newFocus) {
Joe Onorato664644d2011-01-23 17:53:23 -08004299 mFocusedWindow = newFocus;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004300 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004301 // If the navigation bar has been hidden or shown, we need to do another
4302 // layout pass to update that window.
4303 return FINISH_LAYOUT_REDO_LAYOUT;
4304 }
4305 return 0;
Joe Onorato664644d2011-01-23 17:53:23 -08004306 }
4307
Dianne Hackborn0ecadf72009-03-31 18:00:37 -07004308 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07004309 @Override
Jeff Brown46b9ac02010-04-22 18:58:52 -07004310 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
4311 // lid changed state
Jeff Brownc458ce92012-04-30 14:58:40 -07004312 final int newLidState = lidOpen ? LID_OPEN : LID_CLOSED;
4313 if (newLidState == mLidState) {
4314 return;
4315 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004316
Jeff Brownc458ce92012-04-30 14:58:40 -07004317 mLidState = newLidState;
4318 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07004319 updateRotation(true);
Jeff Brownc458ce92012-04-30 14:58:40 -07004320
4321 if (lidOpen) {
Bryce Lee584a4452014-10-21 15:55:55 -07004322 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromLidSwitch);
Jeff Brownc458ce92012-04-30 14:58:40 -07004323 } else if (!mLidControlsSleep) {
Jeff Brown96307042012-07-27 15:51:34 -07004324 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
Jeff Brown46b9ac02010-04-22 18:58:52 -07004325 }
4326 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004327
Michael Wright3818c922014-09-02 13:59:07 -07004328 @Override
4329 public void notifyCameraLensCoverSwitchChanged(long whenNanos, boolean lensCovered) {
4330 int lensCoverState = lensCovered ? CAMERA_LENS_COVERED : CAMERA_LENS_UNCOVERED;
4331 if (mCameraLensCoverState == lensCoverState) {
4332 return;
4333 }
4334 if (mCameraLensCoverState == CAMERA_LENS_COVERED &&
4335 lensCoverState == CAMERA_LENS_UNCOVERED) {
4336 Intent intent;
4337 final boolean keyguardActive = mKeyguardDelegate == null ? false :
4338 mKeyguardDelegate.isShowing();
4339 if (keyguardActive) {
4340 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE);
4341 } else {
4342 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
4343 }
Bryce Lee584a4452014-10-21 15:55:55 -07004344 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromCameraLens);
Michael Wright3818c922014-09-02 13:59:07 -07004345 mContext.startActivityAsUser(intent, UserHandle.CURRENT_OR_SELF);
4346 }
4347 mCameraLensCoverState = lensCoverState;
4348 }
4349
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004350 void setHdmiPlugged(boolean plugged) {
4351 if (mHdmiPlugged != plugged) {
4352 mHdmiPlugged = plugged;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004353 updateRotation(true, true);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004354 Intent intent = new Intent(ACTION_HDMI_PLUGGED);
Joe Onoratodc100302011-01-11 17:07:41 -08004355 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004356 intent.putExtra(EXTRA_HDMI_PLUGGED_STATE, plugged);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07004357 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004358 }
4359 }
4360
Joe Onoratoea495d42011-04-06 11:41:11 -07004361 void initializeHdmiState() {
Joe Onorato7ba631f2011-05-04 15:28:00 -07004362 boolean plugged = false;
Joe Onoratoea495d42011-04-06 11:41:11 -07004363 // watch for HDMI plug messages if the hdmi switch exists
4364 if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) {
4365 mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi");
4366
Joe Onoratoea495d42011-04-06 11:41:11 -07004367 final String filename = "/sys/class/switch/hdmi/state";
4368 FileReader reader = null;
4369 try {
4370 reader = new FileReader(filename);
4371 char[] buf = new char[15];
4372 int n = reader.read(buf);
4373 if (n > 1) {
4374 plugged = 0 != Integer.parseInt(new String(buf, 0, n-1));
4375 }
4376 } catch (IOException ex) {
4377 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
4378 } catch (NumberFormatException ex) {
4379 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
4380 } finally {
4381 if (reader != null) {
4382 try {
4383 reader.close();
4384 } catch (IOException ex) {
4385 }
Joe Onoratodc100302011-01-11 17:07:41 -08004386 }
4387 }
4388 }
Joe Onorato7ba631f2011-05-04 15:28:00 -07004389 // This dance forces the code in setHdmiPlugged to run.
4390 // Always do this so the sticky intent is stuck (to false) if there is no hdmi.
4391 mHdmiPlugged = !plugged;
4392 setHdmiPlugged(!mHdmiPlugged);
Joe Onoratodc100302011-01-11 17:07:41 -08004393 }
4394
Dianne Hackbornc0e3f242011-08-19 14:19:10 -07004395 final Object mScreenshotLock = new Object();
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004396 ServiceConnection mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004397
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004398 final Runnable mScreenshotTimeout = new Runnable() {
4399 @Override public void run() {
4400 synchronized (mScreenshotLock) {
4401 if (mScreenshotConnection != null) {
4402 mContext.unbindService(mScreenshotConnection);
4403 mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004404 }
Winson Chung9112ec32011-06-27 13:15:32 -07004405 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004406 }
4407 };
4408
4409 // Assume this is called from the Handler thread.
4410 private void takeScreenshot() {
4411 synchronized (mScreenshotLock) {
4412 if (mScreenshotConnection != null) {
4413 return;
4414 }
4415 ComponentName cn = new ComponentName("com.android.systemui",
4416 "com.android.systemui.screenshot.TakeScreenshotService");
4417 Intent intent = new Intent();
4418 intent.setComponent(cn);
4419 ServiceConnection conn = new ServiceConnection() {
4420 @Override
4421 public void onServiceConnected(ComponentName name, IBinder service) {
4422 synchronized (mScreenshotLock) {
4423 if (mScreenshotConnection != this) {
4424 return;
4425 }
4426 Messenger messenger = new Messenger(service);
4427 Message msg = Message.obtain(null, 1);
4428 final ServiceConnection myConn = this;
4429 Handler h = new Handler(mHandler.getLooper()) {
4430 @Override
4431 public void handleMessage(Message msg) {
4432 synchronized (mScreenshotLock) {
4433 if (mScreenshotConnection == myConn) {
4434 mContext.unbindService(mScreenshotConnection);
4435 mScreenshotConnection = null;
4436 mHandler.removeCallbacks(mScreenshotTimeout);
4437 }
4438 }
4439 }
4440 };
4441 msg.replyTo = new Messenger(h);
Winson Chunga63bb842011-10-17 10:26:28 -07004442 msg.arg1 = msg.arg2 = 0;
4443 if (mStatusBar != null && mStatusBar.isVisibleLw())
4444 msg.arg1 = 1;
4445 if (mNavigationBar != null && mNavigationBar.isVisibleLw())
4446 msg.arg2 = 1;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004447 try {
4448 messenger.send(msg);
4449 } catch (RemoteException e) {
4450 }
4451 }
4452 }
4453 @Override
4454 public void onServiceDisconnected(ComponentName name) {}
4455 };
Amith Yamasani27b89e62013-01-16 12:30:11 -08004456 if (mContext.bindServiceAsUser(
4457 intent, conn, Context.BIND_AUTO_CREATE, UserHandle.CURRENT)) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004458 mScreenshotConnection = conn;
4459 mHandler.postDelayed(mScreenshotTimeout, 10000);
4460 }
4461 }
Winson Chung9112ec32011-06-27 13:15:32 -07004462 }
4463
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004464 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004465 @Override
Jeff Brown037c33e2014-04-09 00:31:55 -07004466 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) {
Jeff Brown96307042012-07-27 15:51:34 -07004467 if (!mSystemBooted) {
4468 // If we have not yet booted, don't let key events do anything.
4469 return 0;
4470 }
4471
Jeff Brown037c33e2014-04-09 00:31:55 -07004472 final boolean interactive = (policyFlags & FLAG_INTERACTIVE) != 0;
Jeff Brown1f245102010-11-18 20:53:46 -08004473 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
4474 final boolean canceled = event.isCanceled();
4475 final int keyCode = event.getKeyCode();
Jeff Browne20c9e02010-10-11 14:20:19 -07004476
Jeff Brown3122e442010-10-11 23:32:49 -07004477 final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0;
Jeff Brown3122e442010-10-11 23:32:49 -07004478
Mike Lockwoodc72b15f2009-11-28 20:58:22 -05004479 // If screen is off then we treat the case where the keyguard is open but hidden
4480 // the same as if it were open and in front.
4481 // This will prevent any keys other than the power button from waking the screen
4482 // when the keyguard is hidden by another activity.
Jim Miller5ecd8112013-01-09 18:50:26 -08004483 final boolean keyguardActive = (mKeyguardDelegate == null ? false :
Jeff Brown037c33e2014-04-09 00:31:55 -07004484 (interactive ?
Jim Millerab954542014-10-10 18:21:49 -07004485 isKeyguardShowingAndNotOccluded() :
Jim Miller5ecd8112013-01-09 18:50:26 -08004486 mKeyguardDelegate.isShowing()));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004487
Jeff Brown40013652012-05-16 21:22:36 -07004488 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004489 Log.d(TAG, "interceptKeyTq keycode=" + keyCode
Jeff Brown037c33e2014-04-09 00:31:55 -07004490 + " interactive=" + interactive + " keyguardActive=" + keyguardActive
Jeff Brown26875502014-01-30 21:47:47 -08004491 + " policyFlags=" + Integer.toHexString(policyFlags));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004492 }
4493
Jeff Brown037c33e2014-04-09 00:31:55 -07004494 // Basic policy based on interactive state.
Jeff Brown4d396052010-10-29 21:50:21 -07004495 int result;
Michael Wright337d9d22014-04-22 15:03:48 -07004496 boolean isWakeKey = (policyFlags & WindowManagerPolicy.FLAG_WAKE) != 0
4497 || event.isWakeKey();
Michael Wrightfc01f042014-09-08 14:12:24 -07004498 if (interactive || (isInjected && !isWakeKey)) {
RoboErikde9ba392014-09-26 12:51:01 -07004499 // When the device is interactive or the key is injected pass the
4500 // key to the application.
Jeff Brown4d396052010-10-29 21:50:21 -07004501 result = ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07004502 isWakeKey = false;
Michael Wrightfc01f042014-09-08 14:12:24 -07004503 } else if (!interactive && shouldDispatchInputWhenNonInteractive()) {
4504 // If we're currently dozing with the screen on and the keyguard showing, pass the key
4505 // to the application but preserve its wake key status to make sure we still move
4506 // from dozing to fully interactive if we would normally go from off to fully
4507 // interactive.
4508 result = ACTION_PASS_TO_USER;
Jeff Brown4d396052010-10-29 21:50:21 -07004509 } else {
4510 // When the screen is off and the key is not injected, determine whether
4511 // to wake the device but don't pass the key to the application.
4512 result = 0;
Jeff Brown26875502014-01-30 21:47:47 -08004513 if (isWakeKey && (!down || !isWakeKeyWhenScreenOff(keyCode))) {
4514 isWakeKey = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004515 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004516 }
4517
Justin Kohd378ad72013-04-01 12:18:26 -07004518 // If the key would be handled globally, just return the result, don't worry about special
4519 // key processing.
Jeff Brown13f00f02014-10-31 14:45:50 -07004520 if (isValidGlobalKey(keyCode)
4521 && mGlobalKeyManager.shouldHandleGlobalKey(keyCode, event)) {
Michael Wright85b1af62014-06-04 14:51:58 -07004522 if (isWakeKey) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004523 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey);
Michael Wright85b1af62014-06-04 14:51:58 -07004524 }
Justin Kohd378ad72013-04-01 12:18:26 -07004525 return result;
4526 }
4527
Jeff Brownbae8e772014-06-12 19:59:45 -07004528 boolean useHapticFeedback = down
4529 && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0
4530 && event.getRepeatCount() == 0;
4531
Jeff Brown4d396052010-10-29 21:50:21 -07004532 // Handle special keys.
4533 switch (keyCode) {
4534 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jeff Brownb0418da2010-11-01 15:24:01 -07004535 case KeyEvent.KEYCODE_VOLUME_UP:
4536 case KeyEvent.KEYCODE_VOLUME_MUTE: {
RoboErik001c59c2015-01-26 15:53:51 -08004537 if (mUseTvRouting) {
4538 // On TVs volume keys never go to the foreground app
4539 result &= ~ACTION_PASS_TO_USER;
4540 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004541 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
4542 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004543 if (interactive && !mScreenshotChordVolumeDownKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004544 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004545 mScreenshotChordVolumeDownKeyTriggered = true;
4546 mScreenshotChordVolumeDownKeyTime = event.getDownTime();
4547 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004548 cancelPendingPowerKeyAction();
4549 interceptScreenshotChord();
4550 }
4551 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004552 mScreenshotChordVolumeDownKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004553 cancelPendingScreenshotChordAction();
4554 }
4555 } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
4556 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004557 if (interactive && !mScreenshotChordVolumeUpKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004558 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004559 mScreenshotChordVolumeUpKeyTriggered = true;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004560 cancelPendingPowerKeyAction();
4561 cancelPendingScreenshotChordAction();
4562 }
4563 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004564 mScreenshotChordVolumeUpKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004565 cancelPendingScreenshotChordAction();
4566 }
4567 }
Jeff Brown4d396052010-10-29 21:50:21 -07004568 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004569 TelecomManager telecomManager = getTelecommService();
4570 if (telecomManager != null) {
4571 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07004572 // If an incoming call is ringing, either VOLUME key means
4573 // "silence ringer". We handle these keys here, rather than
4574 // in the InCallScreen, to make sure we'll respond to them
4575 // even if the InCallScreen hasn't come to the foreground yet.
4576 // Look for the DOWN event here, to agree with the "fallback"
4577 // behavior in the InCallScreen.
4578 Log.i(TAG, "interceptKeyBeforeQueueing:"
4579 + " VOLUME key-down while ringing: Silence ringer!");
Jeff Brown4d396052010-10-29 21:50:21 -07004580
Santos Cordon6848f722014-05-21 15:22:12 -07004581 // Silence the ringer. (It's safe to call this
4582 // even if the ringer has already been silenced.)
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004583 telecomManager.silenceRinger();
Jeff Brown4d396052010-10-29 21:50:21 -07004584
Santos Cordon6848f722014-05-21 15:22:12 -07004585 // And *don't* pass this key thru to the current activity
4586 // (which is probably the InCallScreen.)
4587 result &= ~ACTION_PASS_TO_USER;
4588 break;
4589 }
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004590 if (telecomManager.isInCall()
Santos Cordon6848f722014-05-21 15:22:12 -07004591 && (result & ACTION_PASS_TO_USER) == 0) {
4592 // If we are in call but we decided not to pass the key to
RoboErik430fc482014-06-12 15:49:20 -07004593 // the application, just pass it to the session service.
4594
4595 MediaSessionLegacyHelper.getHelper(mContext)
RoboErik3c45c292014-07-08 16:47:31 -07004596 .sendVolumeKeyEvent(event, false);
Santos Cordon6848f722014-05-21 15:22:12 -07004597 break;
Jeff Brown4d396052010-10-29 21:50:21 -07004598 }
4599 }
4600
RoboErik430fc482014-06-12 15:49:20 -07004601 if ((result & ACTION_PASS_TO_USER) == 0) {
RoboErik001c59c2015-01-26 15:53:51 -08004602 if (mUseTvRouting) {
4603 dispatchDirectAudioEvent(event);
4604 } else {
4605 // If we aren't passing to the user and no one else
4606 // handled it send it to the session manager to
4607 // figure out.
4608 MediaSessionLegacyHelper.getHelper(mContext)
4609 .sendVolumeKeyEvent(event, true);
4610 }
Jeff Brown4d396052010-10-29 21:50:21 -07004611 break;
4612 }
4613 }
4614 break;
4615 }
4616
4617 case KeyEvent.KEYCODE_ENDCALL: {
4618 result &= ~ACTION_PASS_TO_USER;
4619 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004620 TelecomManager telecomManager = getTelecommService();
Jeff Brown4d396052010-10-29 21:50:21 -07004621 boolean hungUp = false;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004622 if (telecomManager != null) {
4623 hungUp = telecomManager.endCall();
Jeff Brown4d396052010-10-29 21:50:21 -07004624 }
Jeff Brown13f00f02014-10-31 14:45:50 -07004625 if (interactive && !hungUp) {
4626 mEndCallKeyHandled = false;
4627 mHandler.postDelayed(mEndCallLongPress,
4628 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
4629 } else {
4630 mEndCallKeyHandled = true;
4631 }
Jeff Brown4d396052010-10-29 21:50:21 -07004632 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004633 if (!mEndCallKeyHandled) {
4634 mHandler.removeCallbacks(mEndCallLongPress);
4635 if (!canceled) {
4636 if ((mEndcallBehavior
4637 & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) {
4638 if (goHome()) {
4639 break;
4640 }
Dianne Hackborn0041e972009-07-24 17:14:43 -07004641 }
Jeff Brown13f00f02014-10-31 14:45:50 -07004642 if ((mEndcallBehavior
4643 & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) {
4644 mPowerManager.goToSleep(event.getEventTime(),
4645 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
4646 isWakeKey = false;
4647 }
Jeff Brown4d396052010-10-29 21:50:21 -07004648 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004649 }
Jeff Brown4d396052010-10-29 21:50:21 -07004650 }
4651 break;
4652 }
4653
4654 case KeyEvent.KEYCODE_POWER: {
4655 result &= ~ACTION_PASS_TO_USER;
Jeff Brown13f00f02014-10-31 14:45:50 -07004656 isWakeKey = false; // wake-up will be handled separately
Jeff Brown4d396052010-10-29 21:50:21 -07004657 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004658 interceptPowerKeyDown(event, interactive);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004659 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004660 interceptPowerKeyUp(event, interactive, canceled);
Jeff Brown4d396052010-10-29 21:50:21 -07004661 }
4662 break;
4663 }
4664
Jeff Brown6212a492014-03-07 13:58:47 -08004665 case KeyEvent.KEYCODE_SLEEP: {
4666 result &= ~ACTION_PASS_TO_USER;
Jeff Brownbae8e772014-06-12 19:59:45 -07004667 if (!mPowerManager.isInteractive()) {
4668 useHapticFeedback = false; // suppress feedback if already non-interactive
4669 }
Jeff Brownc12035c2014-08-13 18:52:25 -07004670 mPowerManager.goToSleep(event.getEventTime(),
4671 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
Jeff Brown6212a492014-03-07 13:58:47 -08004672 isWakeKey = false;
4673 break;
4674 }
4675
4676 case KeyEvent.KEYCODE_WAKEUP: {
4677 result &= ~ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07004678 isWakeKey = true;
Jeff Brown6212a492014-03-07 13:58:47 -08004679 break;
4680 }
4681
Jeff Brown4d396052010-10-29 21:50:21 -07004682 case KeyEvent.KEYCODE_MEDIA_PLAY:
4683 case KeyEvent.KEYCODE_MEDIA_PAUSE:
4684 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
Jeff Brown4d396052010-10-29 21:50:21 -07004685 case KeyEvent.KEYCODE_HEADSETHOOK:
4686 case KeyEvent.KEYCODE_MUTE:
4687 case KeyEvent.KEYCODE_MEDIA_STOP:
4688 case KeyEvent.KEYCODE_MEDIA_NEXT:
4689 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
4690 case KeyEvent.KEYCODE_MEDIA_REWIND:
4691 case KeyEvent.KEYCODE_MEDIA_RECORD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09004692 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
4693 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: {
RoboErikde9ba392014-09-26 12:51:01 -07004694 if (MediaSessionLegacyHelper.getHelper(mContext).isGlobalPriorityActive()) {
4695 // If the global session is active pass all media keys to it
4696 // instead of the active window.
4697 result &= ~ACTION_PASS_TO_USER;
4698 }
Jeff Brown4d396052010-10-29 21:50:21 -07004699 if ((result & ACTION_PASS_TO_USER) == 0) {
4700 // Only do this if we would otherwise not pass it to the user. In that
4701 // case, the PhoneWindow class will do the same thing, except it will
4702 // only do it if the showing app doesn't process the key on its own.
Jeff Brown40013652012-05-16 21:22:36 -07004703 // Note that we need to make a copy of the key event here because the
4704 // original key event will be recycled when we return.
Jeff Brown4d396052010-10-29 21:50:21 -07004705 mBroadcastWakeLock.acquire();
Jeff Brown40013652012-05-16 21:22:36 -07004706 Message msg = mHandler.obtainMessage(MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK,
4707 new KeyEvent(event));
4708 msg.setAsynchronous(true);
4709 msg.sendToTarget();
Jeff Brown4d396052010-10-29 21:50:21 -07004710 }
4711 break;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004712 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004713
Jeff Brown4d396052010-10-29 21:50:21 -07004714 case KeyEvent.KEYCODE_CALL: {
4715 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004716 TelecomManager telecomManager = getTelecommService();
4717 if (telecomManager != null) {
4718 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07004719 Log.i(TAG, "interceptKeyBeforeQueueing:"
4720 + " CALL key-down while ringing: Answer the call!");
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004721 telecomManager.acceptRingingCall();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004722
Santos Cordon6848f722014-05-21 15:22:12 -07004723 // And *don't* pass this key thru to the current activity
4724 // (which is presumably the InCallScreen.)
4725 result &= ~ACTION_PASS_TO_USER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004726 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004727 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004728 }
Jeff Brown4d396052010-10-29 21:50:21 -07004729 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004730 }
Michael Wright869a67c2014-08-26 19:33:06 -07004731 case KeyEvent.KEYCODE_VOICE_ASSIST: {
4732 // Only do this if we would otherwise not pass it to the user. In that case,
4733 // interceptKeyBeforeDispatching would apply a similar but different policy in
4734 // order to invoke voice assist actions. Note that we need to make a copy of the
4735 // key event here because the original key event will be recycled when we return.
4736 if ((result & ACTION_PASS_TO_USER) == 0 && !down) {
4737 mBroadcastWakeLock.acquire();
4738 Message msg = mHandler.obtainMessage(MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK,
4739 keyguardActive ? 1 : 0, 0);
4740 msg.setAsynchronous(true);
4741 msg.sendToTarget();
4742 }
4743 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004744 }
Jeff Brown26875502014-01-30 21:47:47 -08004745
Jeff Brownbae8e772014-06-12 19:59:45 -07004746 if (useHapticFeedback) {
4747 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
4748 }
4749
Jeff Brown26875502014-01-30 21:47:47 -08004750 if (isWakeKey) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004751 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey);
Jeff Brown26875502014-01-30 21:47:47 -08004752 }
Bryce Lee584a4452014-10-21 15:55:55 -07004753
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004754 return result;
4755 }
4756
Jeff Brown1c2e4942012-11-06 16:32:01 -08004757 /**
Jeff Brown13f00f02014-10-31 14:45:50 -07004758 * Returns true if the key can have global actions attached to it.
4759 * We reserve all power management keys for the system since they require
4760 * very careful handling.
4761 */
4762 private static boolean isValidGlobalKey(int keyCode) {
4763 switch (keyCode) {
4764 case KeyEvent.KEYCODE_POWER:
4765 case KeyEvent.KEYCODE_WAKEUP:
4766 case KeyEvent.KEYCODE_SLEEP:
4767 return false;
4768 default:
4769 return true;
4770 }
4771 }
4772
4773 /**
Jeff Brown1c2e4942012-11-06 16:32:01 -08004774 * When the screen is off we ignore some keys that might otherwise typically
4775 * be considered wake keys. We filter them out here.
4776 *
4777 * {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it
4778 * is always considered a wake key.
4779 */
4780 private boolean isWakeKeyWhenScreenOff(int keyCode) {
4781 switch (keyCode) {
4782 // ignore volume keys unless docked
4783 case KeyEvent.KEYCODE_VOLUME_UP:
4784 case KeyEvent.KEYCODE_VOLUME_DOWN:
4785 case KeyEvent.KEYCODE_VOLUME_MUTE:
4786 return mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED;
4787
4788 // ignore media and camera keys
4789 case KeyEvent.KEYCODE_MUTE:
4790 case KeyEvent.KEYCODE_HEADSETHOOK:
4791 case KeyEvent.KEYCODE_MEDIA_PLAY:
4792 case KeyEvent.KEYCODE_MEDIA_PAUSE:
4793 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
4794 case KeyEvent.KEYCODE_MEDIA_STOP:
4795 case KeyEvent.KEYCODE_MEDIA_NEXT:
4796 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
4797 case KeyEvent.KEYCODE_MEDIA_REWIND:
4798 case KeyEvent.KEYCODE_MEDIA_RECORD:
4799 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09004800 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK:
Jeff Brown1c2e4942012-11-06 16:32:01 -08004801 case KeyEvent.KEYCODE_CAMERA:
4802 return false;
4803 }
4804 return true;
4805 }
4806
4807
Jeff Brown56194eb2011-03-02 19:23:13 -08004808 /** {@inheritDoc} */
4809 @Override
Michael Wright70af00a2014-09-03 19:30:20 -07004810 public int interceptMotionBeforeQueueingNonInteractive(long whenNanos, int policyFlags) {
4811 if ((policyFlags & FLAG_WAKE) != 0) {
Bryce Lee5c138322014-11-03 08:26:09 -08004812 if (wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotion)) {
4813 return 0;
4814 }
Michael Wright70af00a2014-09-03 19:30:20 -07004815 }
Bryce Lee5c138322014-11-03 08:26:09 -08004816
Michael Wright70af00a2014-09-03 19:30:20 -07004817 if (shouldDispatchInputWhenNonInteractive()) {
4818 return ACTION_PASS_TO_USER;
4819 }
Bryce Lee5c138322014-11-03 08:26:09 -08004820
Bryce Lee812d7022014-11-10 13:33:28 -08004821 // If we have not passed the action up and we are in theater mode without dreaming,
4822 // there will be no dream to intercept the touch and wake into ambient. The device should
4823 // wake up in this case.
4824 if (isTheaterModeEnabled() && (policyFlags & FLAG_WAKE) != 0) {
4825 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotionWhenNotDreaming);
4826 }
4827
Jeff Brown037c33e2014-04-09 00:31:55 -07004828 return 0;
Jeff Brown56194eb2011-03-02 19:23:13 -08004829 }
4830
Michael Wright70af00a2014-09-03 19:30:20 -07004831 private boolean shouldDispatchInputWhenNonInteractive() {
Bryce Lee5c138322014-11-03 08:26:09 -08004832 // Send events to keyguard while the screen is on.
Jim Millerab954542014-10-10 18:21:49 -07004833 if (isKeyguardShowingAndNotOccluded() && mDisplay != null
4834 && mDisplay.getState() != Display.STATE_OFF) {
Bryce Lee5c138322014-11-03 08:26:09 -08004835 return true;
4836 }
4837
4838 // Send events to a dozing dream even if the screen is off since the dream
4839 // is in control of the state of the screen.
4840 IDreamManager dreamManager = getDreamManager();
4841
4842 try {
4843 if (dreamManager != null && dreamManager.isDreaming()) {
4844 return true;
4845 }
4846 } catch (RemoteException e) {
4847 Slog.e(TAG, "RemoteException when checking if dreaming", e);
4848 }
4849
4850 // Otherwise, consume events since the user can't see what is being
4851 // interacted with.
4852 return false;
Michael Wright70af00a2014-09-03 19:30:20 -07004853 }
4854
RoboErik001c59c2015-01-26 15:53:51 -08004855 private void dispatchDirectAudioEvent(KeyEvent event) {
4856 if (event.getAction() != KeyEvent.ACTION_DOWN) {
4857 return;
4858 }
4859 int keyCode = event.getKeyCode();
4860 int flags = AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_PLAY_SOUND;
4861 String pkgName = mContext.getOpPackageName();
4862 switch (keyCode) {
4863 case KeyEvent.KEYCODE_VOLUME_UP:
4864 try {
4865 if (mUseMasterVolume) {
4866 getAudioService().adjustMasterVolume(AudioManager.ADJUST_RAISE, flags,
4867 pkgName);
4868 } else {
4869 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_RAISE,
4870 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName);
4871 }
4872 } catch (RemoteException e) {
4873 Log.e(TAG, "Error dispatching volume up in dispatchTvAudioEvent.", e);
4874 }
4875 break;
4876 case KeyEvent.KEYCODE_VOLUME_DOWN:
4877 try {
4878 if (mUseMasterVolume) {
4879 getAudioService().adjustMasterVolume(AudioManager.ADJUST_LOWER, flags,
4880 pkgName);
4881 } else {
4882 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_LOWER,
4883 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName);
4884 }
4885 } catch (RemoteException e) {
4886 Log.e(TAG, "Error dispatching volume down in dispatchTvAudioEvent.", e);
4887 }
4888 break;
4889 case KeyEvent.KEYCODE_VOLUME_MUTE:
4890 try {
4891 if (event.getRepeatCount() == 0) {
4892 if (mUseMasterVolume) {
4893 getAudioService().adjustMasterVolume(AudioManager.ADJUST_TOGGLE_MUTE,
4894 flags, pkgName);
4895 } else {
4896 getAudioService().adjustSuggestedStreamVolume(
4897 AudioManager.ADJUST_TOGGLE_MUTE,
4898 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName);
4899 }
4900 }
4901 } catch (RemoteException e) {
4902 Log.e(TAG, "Error dispatching mute in dispatchTvAudioEvent.", e);
4903 }
4904 break;
4905 }
4906 }
4907
Jeff Brown40013652012-05-16 21:22:36 -07004908 void dispatchMediaKeyWithWakeLock(KeyEvent event) {
4909 if (DEBUG_INPUT) {
4910 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: " + event);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004911 }
4912
Jeff Brown40013652012-05-16 21:22:36 -07004913 if (mHavePendingMediaKeyRepeatWithWakeLock) {
4914 if (DEBUG_INPUT) {
4915 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: canceled repeat");
4916 }
4917
4918 mHandler.removeMessages(MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK);
4919 mHavePendingMediaKeyRepeatWithWakeLock = false;
4920 mBroadcastWakeLock.release(); // pending repeat was holding onto the wake lock
4921 }
4922
4923 dispatchMediaKeyWithWakeLockToAudioService(event);
4924
4925 if (event.getAction() == KeyEvent.ACTION_DOWN
4926 && event.getRepeatCount() == 0) {
4927 mHavePendingMediaKeyRepeatWithWakeLock = true;
4928
4929 Message msg = mHandler.obtainMessage(
4930 MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK, event);
4931 msg.setAsynchronous(true);
4932 mHandler.sendMessageDelayed(msg, ViewConfiguration.getKeyRepeatTimeout());
4933 } else {
4934 mBroadcastWakeLock.release();
4935 }
4936 }
4937
4938 void dispatchMediaKeyRepeatWithWakeLock(KeyEvent event) {
4939 mHavePendingMediaKeyRepeatWithWakeLock = false;
4940
4941 KeyEvent repeatEvent = KeyEvent.changeTimeRepeat(event,
4942 SystemClock.uptimeMillis(), 1, event.getFlags() | KeyEvent.FLAG_LONG_PRESS);
4943 if (DEBUG_INPUT) {
4944 Slog.d(TAG, "dispatchMediaKeyRepeatWithWakeLock: " + repeatEvent);
4945 }
4946
4947 dispatchMediaKeyWithWakeLockToAudioService(repeatEvent);
4948 mBroadcastWakeLock.release();
4949 }
4950
4951 void dispatchMediaKeyWithWakeLockToAudioService(KeyEvent event) {
4952 if (ActivityManagerNative.isSystemReady()) {
RoboErik430fc482014-06-12 15:49:20 -07004953 MediaSessionLegacyHelper.getHelper(mContext).sendMediaButtonEvent(event, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004954 }
4955 }
4956
Michael Wright869a67c2014-08-26 19:33:06 -07004957 void launchVoiceAssistWithWakeLock(boolean keyguardActive) {
4958 Intent voiceIntent =
4959 new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
4960 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, keyguardActive);
4961 mContext.startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
4962 mBroadcastWakeLock.release();
4963 }
4964
Mike Lockwood1753f7f2009-08-24 14:49:07 -07004965 BroadcastReceiver mDockReceiver = new BroadcastReceiver() {
Craig Mautnereee29c42013-01-17 14:44:34 -08004966 @Override
Mike Lockwood1753f7f2009-08-24 14:49:07 -07004967 public void onReceive(Context context, Intent intent) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07004968 if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) {
4969 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
4970 Intent.EXTRA_DOCK_STATE_UNDOCKED);
Daniel Sandler6396c722013-04-16 20:19:09 -04004971 } else {
4972 try {
4973 IUiModeManager uiModeService = IUiModeManager.Stub.asInterface(
4974 ServiceManager.getService(Context.UI_MODE_SERVICE));
4975 mUiMode = uiModeService.getCurrentModeType();
4976 } catch (RemoteException e) {
4977 }
Dianne Hackborn80fa1662009-10-07 14:02:10 -07004978 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004979 updateRotation(true);
Craig Mautnereee29c42013-01-17 14:44:34 -08004980 synchronized (mLock) {
4981 updateOrientationListenerLp();
4982 }
Mike Lockwood1753f7f2009-08-24 14:49:07 -07004983 }
4984 };
4985
Jeff Brown6aaf2952012-10-05 16:01:08 -07004986 BroadcastReceiver mDreamReceiver = new BroadcastReceiver() {
4987 @Override
4988 public void onReceive(Context context, Intent intent) {
4989 if (Intent.ACTION_DREAMING_STARTED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004990 if (mKeyguardDelegate != null) {
4991 mKeyguardDelegate.onDreamingStarted();
Jeff Brown6aaf2952012-10-05 16:01:08 -07004992 }
4993 } else if (Intent.ACTION_DREAMING_STOPPED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004994 if (mKeyguardDelegate != null) {
4995 mKeyguardDelegate.onDreamingStopped();
Jeff Brown6aaf2952012-10-05 16:01:08 -07004996 }
4997 }
4998 }
4999 };
5000
Christopher Tate5e08af02012-09-21 17:17:22 -07005001 BroadcastReceiver mMultiuserReceiver = new BroadcastReceiver() {
5002 @Override
5003 public void onReceive(Context context, Intent intent) {
5004 if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) {
5005 // tickle the settings observer: this first ensures that we're
5006 // observing the relevant settings for the newly-active user,
5007 // and then updates our own bookkeeping based on the now-
5008 // current user.
5009 mSettingsObserver.onChange(false);
John Spurlockce479d82012-11-29 09:52:21 -05005010
5011 // force a re-application of focused window sysui visibility.
5012 // the window may never have been shown for this user
5013 // e.g. the keyguard when going through the new-user setup flow
John Spurlock04db1762013-05-13 12:46:41 -04005014 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
John Spurlockce479d82012-11-29 09:52:21 -05005015 mLastSystemUiFlags = 0;
5016 updateSystemUiVisibilityLw();
5017 }
Christopher Tate5e08af02012-09-21 17:17:22 -07005018 }
5019 }
5020 };
5021
John Spurlockd9b70bd2014-02-06 17:02:44 -05005022 private final Runnable mRequestTransientNav = new Runnable() {
5023 @Override
5024 public void run() {
5025 requestTransientBars(mNavigationBar);
5026 }
5027 };
5028
John Spurlocke1f366f2013-08-05 12:22:40 -04005029 private void requestTransientBars(WindowState swipeTarget) {
John Spurlock04db1762013-05-13 12:46:41 -04005030 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Maurice Lam99c6e072014-04-28 18:24:28 -07005031 if (!isUserSetupComplete()) {
5032 // Swipe-up for navigation bar is disabled during setup
5033 return;
5034 }
John Spurlock27735a42013-08-14 17:57:38 -04005035 boolean sb = mStatusBarController.checkShowTransientBarLw();
5036 boolean nb = mNavigationBarController.checkShowTransientBarLw();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005037 if (sb || nb) {
John Spurlocke1f366f2013-08-05 12:22:40 -04005038 WindowState barTarget = sb ? mStatusBar : mNavigationBar;
5039 if (sb ^ nb && barTarget != swipeTarget) {
5040 if (DEBUG) Slog.d(TAG, "Not showing transient bar, wrong swipe target");
John Spurlockad3e6cb2013-04-30 08:47:43 -04005041 return;
5042 }
John Spurlock27735a42013-08-14 17:57:38 -04005043 if (sb) mStatusBarController.showTransient();
5044 if (nb) mNavigationBarController.showTransient();
John Spurlockf1a36642013-10-12 17:50:42 -04005045 mImmersiveModeConfirmation.confirmCurrentPrompt();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005046 updateSystemUiVisibilityLw();
John Spurlock32beb2c2013-03-11 10:16:47 -04005047 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04005048 }
5049 }
5050
Jeff Brown3ee549c2014-09-22 20:14:39 -07005051 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07005052 @Override
Jeff Brown140ffc72014-05-01 15:18:00 -07005053 public void goingToSleep(int why) {
Dianne Hackborn74489012009-03-24 20:50:09 -07005054 EventLog.writeEvent(70000, 0);
Jeff Brown36c4db82014-09-19 12:05:31 -07005055 if (DEBUG_WAKEUP) Slog.i(TAG, "Going to sleep...");
Jeff Brown3ee549c2014-09-22 20:14:39 -07005056
5057 // We must get this work done here because the power manager will drop
5058 // the wake lock and let the system suspend once this function returns.
The Android Open Source Project0727d222009-03-11 12:11:58 -07005059 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005060 mAwake = false;
5061 mKeyguardDrawComplete = false;
Jeff Browna20dda42014-05-27 20:57:24 -07005062 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005063 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05005064 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005065 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005066
5067 if (mKeyguardDelegate != null) {
5068 mKeyguardDelegate.onScreenTurnedOff(why);
5069 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005070 }
5071
Jeff Brown13f00f02014-10-31 14:45:50 -07005072 private void wakeUpFromPowerKey(long eventTime) {
5073 wakeUp(eventTime, mAllowTheaterModeWakeFromPowerKey);
5074 }
5075
Bryce Lee5c138322014-11-03 08:26:09 -08005076 private boolean wakeUp(long wakeTime, boolean wakeInTheaterMode) {
Bryce Lee584a4452014-10-21 15:55:55 -07005077 if (!wakeInTheaterMode && isTheaterModeEnabled()) {
Bryce Lee5c138322014-11-03 08:26:09 -08005078 return false;
Bryce Lee584a4452014-10-21 15:55:55 -07005079 }
5080
5081 mPowerManager.wakeUp(wakeTime);
Bryce Lee5c138322014-11-03 08:26:09 -08005082 return true;
Bryce Lee584a4452014-10-21 15:55:55 -07005083 }
5084
Jeff Brown3ee549c2014-09-22 20:14:39 -07005085 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07005086 @Override
Jeff Brown36c4db82014-09-19 12:05:31 -07005087 public void wakingUp() {
Dianne Hackborn74489012009-03-24 20:50:09 -07005088 EventLog.writeEvent(70000, 1);
Jeff Brown36c4db82014-09-19 12:05:31 -07005089 if (DEBUG_WAKEUP) Slog.i(TAG, "Waking up...");
Craig Mautner8a0da012014-05-31 15:13:37 -07005090
Jeff Brown3ee549c2014-09-22 20:14:39 -07005091 // Since goToSleep performs these functions synchronously, we must
5092 // do the same here. We cannot post this work to a handler because
5093 // that might cause it to become reordered with respect to what
5094 // may happen in a future call to goToSleep.
The Android Open Source Project0727d222009-03-11 12:11:58 -07005095 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005096 mAwake = true;
5097 mKeyguardDrawComplete = false;
5098 if (mKeyguardDelegate != null) {
5099 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
5100 mHandler.sendEmptyMessageDelayed(MSG_KEYGUARD_DRAWN_TIMEOUT, 1000);
5101 }
5102
Jeff Browna20dda42014-05-27 20:57:24 -07005103 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005104 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05005105 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005106 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005107
Jim Miller5ecd8112013-01-09 18:50:26 -08005108 if (mKeyguardDelegate != null) {
Craig Mautner8a0da012014-05-31 15:13:37 -07005109 mKeyguardDelegate.onScreenTurnedOn(mKeyguardDelegateCallback);
Jeff Brown36c4db82014-09-19 12:05:31 -07005110 // ... eventually calls finishKeyguardDrawn
Jeff Brownc38c9be2012-10-04 13:16:19 -07005111 } else {
Craig Mautner8a0da012014-05-31 15:13:37 -07005112 if (DEBUG_WAKEUP) Slog.d(TAG, "null mKeyguardDelegate: setting mKeyguardDrawComplete.");
Jeff Brown36c4db82014-09-19 12:05:31 -07005113 finishKeyguardDrawn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07005114 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005115 }
5116
Jeff Brown36c4db82014-09-19 12:05:31 -07005117 private void finishKeyguardDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005118 synchronized (mLock) {
5119 if (!mAwake || mKeyguardDrawComplete) {
5120 return; // spurious
5121 }
5122
Jeff Brown36c4db82014-09-19 12:05:31 -07005123 mKeyguardDrawComplete = true;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005124 if (mKeyguardDelegate != null) {
5125 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
5126 }
5127 }
5128
5129 finishScreenTurningOn();
5130 }
5131
5132 // Called on the DisplayManager's DisplayPowerController thread.
5133 @Override
5134 public void screenTurnedOff() {
5135 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turned off...");
5136
5137 synchronized (mLock) {
5138 mScreenOnEarly = false;
5139 mScreenOnFully = false;
5140 mWindowManagerDrawComplete = false;
5141 mScreenOnListener = null;
5142 updateOrientationListenerLp();
Jeff Brown36c4db82014-09-19 12:05:31 -07005143 }
5144 }
5145
Jeff Brown3ee549c2014-09-22 20:14:39 -07005146 // Called on the DisplayManager's DisplayPowerController thread.
Jeff Brown36c4db82014-09-19 12:05:31 -07005147 @Override
5148 public void screenTurningOn(final ScreenOnListener screenOnListener) {
Jeff Brown36c4db82014-09-19 12:05:31 -07005149 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turning on...");
Jeff Brown36c4db82014-09-19 12:05:31 -07005150
Jeff Brown3ee549c2014-09-22 20:14:39 -07005151 synchronized (mLock) {
5152 mScreenOnEarly = true;
5153 mScreenOnFully = false;
5154 mWindowManagerDrawComplete = false;
5155 mScreenOnListener = screenOnListener;
5156 updateOrientationListenerLp();
5157 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005158
Craig Mautnerc3daedd2014-09-13 11:17:23 -07005159 mWindowManagerInternal.waitForAllWindowsDrawn(mWindowManagerDrawCallback,
5160 WAITING_FOR_DRAWN_TIMEOUT);
Jeff Brown36c4db82014-09-19 12:05:31 -07005161 // ... eventually calls finishWindowsDrawn
5162 }
5163
Jeff Brown36c4db82014-09-19 12:05:31 -07005164 private void finishWindowsDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005165 synchronized (mLock) {
5166 if (!mScreenOnEarly || mWindowManagerDrawComplete) {
5167 return; // spurious
5168 }
5169
Jeff Brown36c4db82014-09-19 12:05:31 -07005170 mWindowManagerDrawComplete = true;
Jeff Brown36c4db82014-09-19 12:05:31 -07005171 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005172
5173 finishScreenTurningOn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07005174 }
5175
Craig Mautner8a0da012014-05-31 15:13:37 -07005176 private void finishScreenTurningOn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005177 final ScreenOnListener listener;
5178 final boolean enableScreen;
Jeff Brown36c4db82014-09-19 12:05:31 -07005179 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005180 if (DEBUG_WAKEUP) Slog.d(TAG,
5181 "finishScreenTurningOn: mAwake=" + mAwake
5182 + ", mScreenOnEarly=" + mScreenOnEarly
5183 + ", mScreenOnFully=" + mScreenOnFully
5184 + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete
5185 + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete);
5186
5187 if (mScreenOnFully || !mScreenOnEarly || !mWindowManagerDrawComplete
5188 || (mAwake && !mKeyguardDrawComplete)) {
5189 return; // spurious or not ready yet
Jeff Brown36c4db82014-09-19 12:05:31 -07005190 }
5191
Jeff Brown3ee549c2014-09-22 20:14:39 -07005192 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished screen turning on...");
5193 listener = mScreenOnListener;
Craig Mautner13f6ea72014-06-23 14:57:02 -07005194 mScreenOnListener = null;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005195 mScreenOnFully = true;
5196
5197 // Remember the first time we draw the keyguard so we know when we're done with
5198 // the main part of booting and can enable the screen and hide boot messages.
5199 if (!mKeyguardDrawnOnce && mAwake) {
5200 mKeyguardDrawnOnce = true;
5201 enableScreen = true;
5202 if (mBootMessageNeedsHiding) {
5203 mBootMessageNeedsHiding = false;
5204 hideBootMessages();
5205 }
5206 } else {
5207 enableScreen = false;
5208 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005209 }
5210
Jeff Brown3ee549c2014-09-22 20:14:39 -07005211 if (listener != null) {
5212 listener.onScreenOn();
5213 }
Jeff Brown4fc45272012-10-10 18:28:14 -07005214
Jeff Brown3ee549c2014-09-22 20:14:39 -07005215 if (enableScreen) {
5216 try {
5217 mWindowManager.enableScreenIfNeeded();
5218 } catch (RemoteException unhandled) {
Jeff Brown36c4db82014-09-19 12:05:31 -07005219 }
Craig Mautnera631d492014-08-05 15:16:01 -07005220 }
5221 }
5222
5223 private void handleHideBootMessage() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005224 synchronized (mLock) {
5225 if (!mKeyguardDrawnOnce) {
5226 mBootMessageNeedsHiding = true;
5227 return; // keyguard hasn't drawn the first time yet, not done booting
5228 }
Craig Mautnera631d492014-08-05 15:16:01 -07005229 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005230
5231 if (mBootMsgDialog != null) {
5232 if (DEBUG_WAKEUP) Slog.d(TAG, "handleHideBootMessage: dismissing");
5233 mBootMsgDialog.dismiss();
5234 mBootMsgDialog = null;
Craig Mautnera631d492014-08-05 15:16:01 -07005235 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005236 }
5237
5238 @Override
Jeff Brown3ee549c2014-09-22 20:14:39 -07005239 public boolean isScreenOn() {
5240 return mScreenOnFully;
Dianne Hackborn08743722009-12-21 12:16:51 -08005241 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005242
Dianne Hackborn08743722009-12-21 12:16:51 -08005243 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005244 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005245 public void enableKeyguard(boolean enabled) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005246 if (mKeyguardDelegate != null) {
5247 mKeyguardDelegate.setKeyguardEnabled(enabled);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005248 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005249 }
5250
5251 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005252 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005253 public void exitKeyguardSecurely(OnKeyguardExitResult callback) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005254 if (mKeyguardDelegate != null) {
5255 mKeyguardDelegate.verifyUnlock(callback);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005256 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005257 }
5258
Jim Millerab954542014-10-10 18:21:49 -07005259 private boolean isKeyguardShowingAndNotOccluded() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005260 if (mKeyguardDelegate == null) return false;
Jim Millerab954542014-10-10 18:21:49 -07005261 return mKeyguardDelegate.isShowing() && !mKeyguardOccluded;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005262 }
5263
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005264 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005265 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005266 public boolean isKeyguardLocked() {
5267 return keyguardOn();
5268 }
5269
5270 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005271 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005272 public boolean isKeyguardSecure() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005273 if (mKeyguardDelegate == null) return false;
5274 return mKeyguardDelegate.isSecure();
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005275 }
5276
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005277 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005278 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005279 public boolean inKeyguardRestrictedKeyInputMode() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005280 if (mKeyguardDelegate == null) return false;
5281 return mKeyguardDelegate.isInputRestricted();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005282 }
5283
Jose Lima9546b202014-07-02 17:21:51 -07005284 @Override
Dianne Hackborn90c52de2011-09-23 12:57:44 -07005285 public void dismissKeyguardLw() {
RoboErik8a2cfc32014-05-16 11:19:38 -07005286 if (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()) {
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07005287 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.dismissKeyguardLw");
Daniel Sandler1ce804392012-11-07 15:07:12 -05005288 mHandler.post(new Runnable() {
Jose Lima9546b202014-07-02 17:21:51 -07005289 @Override
Daniel Sandler1ce804392012-11-07 15:07:12 -05005290 public void run() {
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02005291 // ask the keyguard to prompt the user to authenticate if necessary
5292 mKeyguardDelegate.dismiss();
5293 }
5294 });
5295 }
5296 }
5297
5298 public void notifyActivityDrawnForKeyguardLw() {
5299 if (mKeyguardDelegate != null) {
5300 mHandler.post(new Runnable() {
5301 @Override
5302 public void run() {
5303 mKeyguardDelegate.onActivityDrawn();
Daniel Sandler1ce804392012-11-07 15:07:12 -05005304 }
5305 });
Dianne Hackborn90c52de2011-09-23 12:57:44 -07005306 }
5307 }
5308
Jorim Jaggicff0acb2014-03-31 16:35:15 +02005309 @Override
5310 public boolean isKeyguardDrawnLw() {
5311 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005312 return mKeyguardDrawnOnce;
Jorim Jaggicff0acb2014-03-31 16:35:15 +02005313 }
5314 }
5315
Jorim Jaggi0d674622014-05-21 01:34:15 +02005316 @Override
Jorim Jaggie29b2db2014-05-30 23:17:03 +02005317 public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) {
Jorim Jaggi0d674622014-05-21 01:34:15 +02005318 if (mKeyguardDelegate != null) {
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07005319 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.startKeyguardExitAnimation");
Jorim Jaggie29b2db2014-05-30 23:17:03 +02005320 mKeyguardDelegate.startKeyguardExitAnimation(startTime, fadeoutDuration);
Jorim Jaggi0d674622014-05-21 01:34:15 +02005321 }
5322 }
5323
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005324 void sendCloseSystemWindows() {
Jorim Jaggib10e33f2015-02-04 21:57:40 +01005325 PhoneWindow.sendCloseSystemWindows(mContext, null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005326 }
5327
5328 void sendCloseSystemWindows(String reason) {
Jorim Jaggib10e33f2015-02-04 21:57:40 +01005329 PhoneWindow.sendCloseSystemWindows(mContext, reason);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005330 }
Mitsuru Oshima831d0d92009-06-16 18:27:18 -07005331
Jeff Brown01a98dd2011-09-20 15:08:29 -07005332 @Override
5333 public int rotationForOrientationLw(int orientation, int lastRotation) {
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005334 if (false) {
5335 Slog.v(TAG, "rotationForOrientationLw(orient="
5336 + orientation + ", last=" + lastRotation
5337 + "); user=" + mUserRotation + " "
5338 + ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED)
5339 ? "USER_ROTATION_LOCKED" : "")
5340 );
5341 }
5342
Craig Mautner46ac6fa2013-08-01 10:06:34 -07005343 if (mForceDefaultOrientation) {
5344 return Surface.ROTATION_0;
5345 }
5346
The Android Open Source Project0727d222009-03-11 12:11:58 -07005347 synchronized (mLock) {
Jeff Brownc0347aa2011-09-23 17:26:09 -07005348 int sensorRotation = mOrientationListener.getProposedRotation(); // may be -1
5349 if (sensorRotation < 0) {
Jeff Brown0f862b42012-09-27 21:11:01 -07005350 sensorRotation = lastRotation;
Jeff Brownc0347aa2011-09-23 17:26:09 -07005351 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005352
Jeff Browndec6cf42011-11-15 14:08:20 -08005353 final int preferredRotation;
Jeff Brown2e7760e2012-04-11 15:14:55 -07005354 if (mLidState == LID_OPEN && mLidOpenRotation >= 0) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005355 // Ignore sensor when lid switch is open and rotation is forced.
5356 preferredRotation = mLidOpenRotation;
5357 } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR
Jeff Brownc0347aa2011-09-23 17:26:09 -07005358 && (mCarDockEnablesAccelerometer || mCarDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005359 // Ignore sensor when in car dock unless explicitly enabled.
5360 // This case can override the behavior of NOSENSOR, and can also
5361 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07005362 preferredRotation = mCarDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07005363 ? sensorRotation : mCarDockRotation;
Jeff Brown1a693182011-11-08 14:44:16 -08005364 } else if ((mDockMode == Intent.EXTRA_DOCK_STATE_DESK
5365 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
5366 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK)
Jeff Brownc0347aa2011-09-23 17:26:09 -07005367 && (mDeskDockEnablesAccelerometer || mDeskDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005368 // Ignore sensor when in desk dock unless explicitly enabled.
5369 // This case can override the behavior of NOSENSOR, and can also
5370 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07005371 preferredRotation = mDeskDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07005372 ? sensorRotation : mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -07005373 } else if (mHdmiPlugged && mDemoHdmiRotationLock) {
5374 // Ignore sensor when plugged into HDMI when demo HDMI rotation lock enabled.
Jeff Browneb3e4b92011-12-06 19:54:24 -08005375 // Note that the dock orientation overrides the HDMI orientation.
Jeff Brownc82c89ed2013-04-17 17:18:15 -07005376 preferredRotation = mDemoHdmiRotation;
5377 } else if (mHdmiPlugged && mDockMode == Intent.EXTRA_DOCK_STATE_UNDOCKED
5378 && mUndockedHdmiRotation >= 0) {
5379 // Ignore sensor when plugged into HDMI and an undocked orientation has
5380 // been specified in the configuration (only for legacy devices without
5381 // full multi-display support).
5382 // Note that the dock orientation overrides the HDMI orientation.
5383 preferredRotation = mUndockedHdmiRotation;
Chong Zhangae6119ff2014-11-11 18:54:39 -08005384 } else if (mDemoRotationLock) {
5385 // Ignore sensor when demo rotation lock is enabled.
5386 // Note that the dock orientation and HDMI rotation lock override this.
5387 preferredRotation = mDemoRotation;
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005388 } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED) {
5389 // Application just wants to remain locked in the last rotation.
5390 preferredRotation = lastRotation;
Jeff Brownbcdfc622014-03-06 19:13:04 -08005391 } else if (!mSupportAutoRotation) {
5392 // If we don't support auto-rotation then bail out here and ignore
5393 // the sensor and any rotation lock settings.
5394 preferredRotation = -1;
Jeff Brown207673cd2012-06-05 17:47:11 -07005395 } else if ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE
Jeff Brown01a98dd2011-09-20 15:08:29 -07005396 && (orientation == ActivityInfo.SCREEN_ORIENTATION_USER
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005397 || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
5398 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
5399 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
5400 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER))
Jeff Brown01a98dd2011-09-20 15:08:29 -07005401 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
5402 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
5403 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
5404 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) {
5405 // Otherwise, use sensor only if requested by the application or enabled
5406 // by default for USER or UNSPECIFIED modes. Does not apply to NOSENSOR.
Jeff Brownd3187e32011-09-21 19:26:44 -07005407 if (mAllowAllRotations < 0) {
5408 // Can't read this during init() because the context doesn't
5409 // have display metrics at that time so we cannot determine
5410 // tablet vs. phone then.
5411 mAllowAllRotations = mContext.getResources().getBoolean(
5412 com.android.internal.R.bool.config_allowAllRotations) ? 1 : 0;
5413 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005414 if (sensorRotation != Surface.ROTATION_180
Jeff Brownd3187e32011-09-21 19:26:44 -07005415 || mAllowAllRotations == 1
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005416 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
5417 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005418 preferredRotation = sensorRotation;
5419 } else {
5420 preferredRotation = lastRotation;
5421 }
Jeff Brown207673cd2012-06-05 17:47:11 -07005422 } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED
5423 && orientation != ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) {
5424 // Apply rotation lock. Does not apply to NOSENSOR.
5425 // The idea is that the user rotation expresses a weak preference for the direction
5426 // of gravity and as NOSENSOR is never affected by gravity, then neither should
5427 // NOSENSOR be affected by rotation lock (although it will be affected by docks).
Jeff Brown4dfce202011-10-05 12:00:10 -07005428 preferredRotation = mUserRotation;
Jeff Browndec6cf42011-11-15 14:08:20 -08005429 } else {
5430 // No overriding preference.
5431 // We will do exactly what the application asked us to do.
5432 preferredRotation = -1;
Jeff Brown01a98dd2011-09-20 15:08:29 -07005433 }
5434
Dianne Hackborne5439f22010-10-02 16:53:50 -07005435 switch (orientation) {
5436 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08005437 // Return portrait unless overridden.
5438 if (isAnyPortrait(preferredRotation)) {
5439 return preferredRotation;
5440 }
Dianne Hackborne5439f22010-10-02 16:53:50 -07005441 return mPortraitRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005442
Jeff Brown01a98dd2011-09-20 15:08:29 -07005443 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08005444 // Return landscape unless overridden.
5445 if (isLandscapeOrSeascape(preferredRotation)) {
5446 return preferredRotation;
5447 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005448 return mLandscapeRotation;
5449
5450 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08005451 // Return reverse portrait unless overridden.
5452 if (isAnyPortrait(preferredRotation)) {
5453 return preferredRotation;
5454 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005455 return mUpsideDownRotation;
5456
5457 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08005458 // Return seascape unless overridden.
5459 if (isLandscapeOrSeascape(preferredRotation)) {
5460 return preferredRotation;
5461 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005462 return mSeascapeRotation;
5463
5464 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005465 case ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE:
Jeff Brown01a98dd2011-09-20 15:08:29 -07005466 // Return either landscape rotation.
5467 if (isLandscapeOrSeascape(preferredRotation)) {
5468 return preferredRotation;
5469 }
5470 if (isLandscapeOrSeascape(lastRotation)) {
Jeff Brown4519f072011-01-23 13:16:01 -08005471 return lastRotation;
5472 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005473 return mLandscapeRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005474
Jeff Brown01a98dd2011-09-20 15:08:29 -07005475 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005476 case ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT:
Jeff Brown01a98dd2011-09-20 15:08:29 -07005477 // Return either portrait rotation.
5478 if (isAnyPortrait(preferredRotation)) {
5479 return preferredRotation;
5480 }
5481 if (isAnyPortrait(lastRotation)) {
5482 return lastRotation;
5483 }
5484 return mPortraitRotation;
5485
5486 default:
Jeff Brown4dfce202011-10-05 12:00:10 -07005487 // For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR,
5488 // just return the preferred orientation we already calculated.
Jeff Brown01a98dd2011-09-20 15:08:29 -07005489 if (preferredRotation >= 0) {
5490 return preferredRotation;
5491 }
Dianne Hackborndacea8c2011-04-21 17:26:39 -07005492 return Surface.ROTATION_0;
Daniel Sandlere7e5ac22011-02-22 16:10:21 -05005493 }
5494 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07005495 }
5496
Jeff Brown01a98dd2011-09-20 15:08:29 -07005497 @Override
5498 public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation) {
5499 switch (orientation) {
5500 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
5501 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
5502 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
5503 return isAnyPortrait(rotation);
5504
5505 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
5506 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
5507 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
5508 return isLandscapeOrSeascape(rotation);
5509
5510 default:
5511 return true;
5512 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07005513 }
5514
Jeff Brownc0347aa2011-09-23 17:26:09 -07005515 @Override
5516 public void setRotationLw(int rotation) {
5517 mOrientationListener.setCurrentRotation(rotation);
5518 }
5519
Jeff Brown01a98dd2011-09-20 15:08:29 -07005520 private boolean isLandscapeOrSeascape(int rotation) {
5521 return rotation == mLandscapeRotation || rotation == mSeascapeRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005522 }
5523
Jeff Brown01a98dd2011-09-20 15:08:29 -07005524 private boolean isAnyPortrait(int rotation) {
5525 return rotation == mPortraitRotation || rotation == mUpsideDownRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005526 }
5527
Jose Lima9546b202014-07-02 17:21:51 -07005528 @Override
Svetoslav Ganov80943d82013-01-02 10:25:37 -08005529 public int getUserRotationMode() {
5530 return Settings.System.getIntForUser(mContext.getContentResolver(),
Brett Chabot7e55c402013-05-16 19:38:08 -07005531 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
5532 WindowManagerPolicy.USER_ROTATION_FREE :
5533 WindowManagerPolicy.USER_ROTATION_LOCKED;
Svetoslav Ganov80943d82013-01-02 10:25:37 -08005534 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005535
5536 // User rotation: to be used when all else fails in assigning an orientation to the device
Jose Lima9546b202014-07-02 17:21:51 -07005537 @Override
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005538 public void setUserRotationMode(int mode, int rot) {
5539 ContentResolver res = mContext.getContentResolver();
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005540
5541 // mUserRotationMode and mUserRotation will be assigned by the content observer
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005542 if (mode == WindowManagerPolicy.USER_ROTATION_LOCKED) {
Christopher Tate5e08af02012-09-21 17:17:22 -07005543 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005544 Settings.System.USER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005545 rot,
5546 UserHandle.USER_CURRENT);
5547 Settings.System.putIntForUser(res,
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005548 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005549 0,
5550 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005551 } else {
Christopher Tate5e08af02012-09-21 17:17:22 -07005552 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005553 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005554 1,
5555 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005556 }
5557 }
5558
Jose Lima9546b202014-07-02 17:21:51 -07005559 @Override
Jeff Brownac143512012-04-05 18:57:33 -07005560 public void setSafeMode(boolean safeMode) {
5561 mSafeMode = safeMode;
5562 performHapticFeedbackLw(null, safeMode
5563 ? HapticFeedbackConstants.SAFE_MODE_ENABLED
5564 : HapticFeedbackConstants.SAFE_MODE_DISABLED, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005565 }
Craig Mautnereda67292013-04-28 13:50:14 -07005566
Dianne Hackborn181ceb52009-08-27 22:16:40 -07005567 static long[] getLongIntArray(Resources r, int resid) {
5568 int[] ar = r.getIntArray(resid);
5569 if (ar == null) {
5570 return null;
5571 }
5572 long[] out = new long[ar.length];
5573 for (int i=0; i<ar.length; i++) {
5574 out[i] = ar[i];
5575 }
5576 return out;
5577 }
Craig Mautnereda67292013-04-28 13:50:14 -07005578
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005579 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07005580 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005581 public void systemReady() {
Jim Millerab954542014-10-10 18:21:49 -07005582 mKeyguardDelegate = new KeyguardServiceDelegate(mContext);
Mike Lockwooded8902d2013-11-15 11:01:47 -08005583 mKeyguardDelegate.onSystemReady();
5584
Michael Wright3818c922014-09-02 13:59:07 -07005585 readCameraLensCoverState();
Jeff Brown4f5fa282014-06-12 19:19:15 -07005586 updateUiMode();
Dianne Hackbornb1a79802009-09-29 15:18:31 -07005587 synchronized (mLock) {
5588 updateOrientationListenerLp();
Dianne Hackbornc777e072010-02-12 13:07:59 -08005589 mSystemReady = true;
5590 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07005591 @Override
Dianne Hackbornc777e072010-02-12 13:07:59 -08005592 public void run() {
5593 updateSettings();
5594 }
5595 });
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005596 }
5597 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07005598
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005599 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005600 @Override
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005601 public void systemBooted() {
Jim Millere5f910a2013-10-16 18:15:46 -07005602 if (mKeyguardDelegate != null) {
Jason Monk5eeebf52014-09-26 12:36:51 -04005603 mKeyguardDelegate.bindService(mContext);
Jim Millere5f910a2013-10-16 18:15:46 -07005604 mKeyguardDelegate.onBootCompleted();
5605 }
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005606 synchronized (mLock) {
5607 mSystemBooted = true;
5608 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005609 wakingUp();
5610 screenTurningOn(null);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005611 }
5612
Dianne Hackborn661cd522011-08-22 00:26:20 -07005613 ProgressDialog mBootMsgDialog = null;
5614
5615 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005616 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07005617 public void showBootMessage(final CharSequence msg, final boolean always) {
5618 mHandler.post(new Runnable() {
5619 @Override public void run() {
5620 if (mBootMsgDialog == null) {
Craig Stout4c0cb8a2014-04-04 13:03:10 -07005621 int theme;
5622 if (mContext.getPackageManager().hasSystemFeature(
5623 PackageManager.FEATURE_WATCH)) {
5624 theme = com.android.internal.R.style.Theme_Micro_Dialog_Alert;
5625 } else if (mContext.getPackageManager().hasSystemFeature(
5626 PackageManager.FEATURE_TELEVISION)) {
5627 theme = com.android.internal.R.style.Theme_Leanback_Dialog_Alert;
5628 } else {
5629 theme = 0;
5630 }
Vinod Krishnanfa8fc412014-04-18 14:35:53 -07005631
5632 mBootMsgDialog = new ProgressDialog(mContext, theme) {
Dianne Hackborn295e3c22011-08-25 13:19:08 -07005633 // This dialog will consume all events coming in to
5634 // it, to avoid it trying to do things too early in boot.
5635 @Override public boolean dispatchKeyEvent(KeyEvent event) {
5636 return true;
5637 }
5638 @Override public boolean dispatchKeyShortcutEvent(KeyEvent event) {
5639 return true;
5640 }
5641 @Override public boolean dispatchTouchEvent(MotionEvent ev) {
5642 return true;
5643 }
5644 @Override public boolean dispatchTrackballEvent(MotionEvent ev) {
5645 return true;
5646 }
5647 @Override public boolean dispatchGenericMotionEvent(MotionEvent ev) {
5648 return true;
5649 }
5650 @Override public boolean dispatchPopulateAccessibilityEvent(
5651 AccessibilityEvent event) {
5652 return true;
5653 }
5654 };
Jeff Hao9f60c082014-10-28 18:51:07 -07005655 if (mContext.getPackageManager().isUpgrade()) {
5656 mBootMsgDialog.setTitle(R.string.android_upgrading_title);
5657 } else {
5658 mBootMsgDialog.setTitle(R.string.android_start_title);
5659 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07005660 mBootMsgDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
5661 mBootMsgDialog.setIndeterminate(true);
5662 mBootMsgDialog.getWindow().setType(
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07005663 WindowManager.LayoutParams.TYPE_BOOT_PROGRESS);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005664 mBootMsgDialog.getWindow().addFlags(
5665 WindowManager.LayoutParams.FLAG_DIM_BEHIND
5666 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
5667 mBootMsgDialog.getWindow().setDimAmount(1);
Dianne Hackbornd9efb952011-12-07 14:56:51 -08005668 WindowManager.LayoutParams lp = mBootMsgDialog.getWindow().getAttributes();
5669 lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
5670 mBootMsgDialog.getWindow().setAttributes(lp);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005671 mBootMsgDialog.setCancelable(false);
5672 mBootMsgDialog.show();
5673 }
5674 mBootMsgDialog.setMessage(msg);
5675 }
5676 });
5677 }
5678
5679 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005680 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07005681 public void hideBootMessages() {
Craig Mautnera631d492014-08-05 15:16:01 -07005682 mHandler.sendEmptyMessage(MSG_HIDE_BOOT_MESSAGE);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005683 }
5684
Mike Lockwood28569302010-01-28 11:54:40 -05005685 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005686 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05005687 public void userActivity() {
Dianne Hackborndf89e652011-10-06 22:35:11 -07005688 // ***************************************
5689 // NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
5690 // ***************************************
5691 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
5692 // WITH ITS LOCKS HELD.
5693 //
5694 // This code must be VERY careful about the locks
5695 // it acquires.
5696 // In fact, the current code acquires way too many,
5697 // and probably has lurking deadlocks.
5698
Mike Lockwood28569302010-01-28 11:54:40 -05005699 synchronized (mScreenLockTimeout) {
5700 if (mLockScreenTimerActive) {
5701 // reset the timer
5702 mHandler.removeCallbacks(mScreenLockTimeout);
5703 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
5704 }
5705 }
Daniel Sandler0601eb72011-04-13 01:01:32 -04005706 }
5707
Adam Cohenf7522022012-10-03 20:03:18 -07005708 class ScreenLockTimeout implements Runnable {
5709 Bundle options;
5710
5711 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05005712 public void run() {
5713 synchronized (this) {
5714 if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard");
Jim Miller5ecd8112013-01-09 18:50:26 -08005715 if (mKeyguardDelegate != null) {
5716 mKeyguardDelegate.doKeyguardTimeout(options);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005717 }
Mike Lockwood28569302010-01-28 11:54:40 -05005718 mLockScreenTimerActive = false;
Adam Cohenf7522022012-10-03 20:03:18 -07005719 options = null;
Mike Lockwood28569302010-01-28 11:54:40 -05005720 }
5721 }
Mike Lockwood28569302010-01-28 11:54:40 -05005722
Adam Cohenf7522022012-10-03 20:03:18 -07005723 public void setLockOptions(Bundle options) {
5724 this.options = options;
5725 }
5726 }
5727
5728 ScreenLockTimeout mScreenLockTimeout = new ScreenLockTimeout();
5729
Jose Lima9546b202014-07-02 17:21:51 -07005730 @Override
Adam Cohenf7522022012-10-03 20:03:18 -07005731 public void lockNow(Bundle options) {
Jim Miller93c518e2012-01-17 15:55:31 -08005732 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null);
5733 mHandler.removeCallbacks(mScreenLockTimeout);
Adam Cohenf7522022012-10-03 20:03:18 -07005734 if (options != null) {
5735 // In case multiple calls are made to lockNow, we don't wipe out the options
5736 // until the runnable actually executes.
5737 mScreenLockTimeout.setLockOptions(options);
5738 }
Jim Miller93c518e2012-01-17 15:55:31 -08005739 mHandler.post(mScreenLockTimeout);
5740 }
5741
Mike Lockwood28569302010-01-28 11:54:40 -05005742 private void updateLockScreenTimeout() {
5743 synchronized (mScreenLockTimeout) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005744 boolean enable = (mAllowLockscreenWhenOn && mAwake &&
Jim Miller5ecd8112013-01-09 18:50:26 -08005745 mKeyguardDelegate != null && mKeyguardDelegate.isSecure());
Mike Lockwood28569302010-01-28 11:54:40 -05005746 if (mLockScreenTimerActive != enable) {
5747 if (enable) {
5748 if (localLOGV) Log.v(TAG, "setting lockscreen timer");
5749 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
5750 } else {
5751 if (localLOGV) Log.v(TAG, "clearing lockscreen timer");
5752 mHandler.removeCallbacks(mScreenLockTimeout);
5753 }
5754 mLockScreenTimerActive = enable;
5755 }
5756 }
5757 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005758
5759 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07005760 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005761 public void enableScreenAfterBoot() {
5762 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07005763 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07005764 updateRotation(true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005765 }
Dianne Hackbornf54c8f92009-09-19 14:03:57 -07005766
Jeff Brownc458ce92012-04-30 14:58:40 -07005767 private void applyLidSwitchState() {
Jeff Brownc458ce92012-04-30 14:58:40 -07005768 if (mLidState == LID_CLOSED && mLidControlsSleep) {
Jeff Brown6d8fd272014-05-20 21:24:38 -07005769 mPowerManager.goToSleep(SystemClock.uptimeMillis(),
Jeff Brownc12035c2014-08-13 18:52:25 -07005770 PowerManager.GO_TO_SLEEP_REASON_LID_SWITCH,
Jeff Brown6d8fd272014-05-20 21:24:38 -07005771 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
Jeff Brownc458ce92012-04-30 14:58:40 -07005772 }
Jeff Browna20dda42014-05-27 20:57:24 -07005773
5774 synchronized (mLock) {
5775 updateWakeGestureListenerLp();
5776 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005777 }
5778
Jeff Brown4f5fa282014-06-12 19:19:15 -07005779 void updateUiMode() {
5780 if (mUiModeManager == null) {
5781 mUiModeManager = IUiModeManager.Stub.asInterface(
5782 ServiceManager.getService(Context.UI_MODE_SERVICE));
5783 }
5784 try {
5785 mUiMode = mUiModeManager.getCurrentModeType();
5786 } catch (RemoteException e) {
5787 }
5788 }
5789
Jeff Brown01a98dd2011-09-20 15:08:29 -07005790 void updateRotation(boolean alwaysSendConfiguration) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005791 try {
5792 //set orientation on WindowManager
Dianne Hackbornf87d1962012-04-04 12:48:24 -07005793 mWindowManager.updateRotation(alwaysSendConfiguration, false);
5794 } catch (RemoteException e) {
5795 // Ignore
5796 }
5797 }
5798
5799 void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) {
5800 try {
5801 //set orientation on WindowManager
5802 mWindowManager.updateRotation(alwaysSendConfiguration, forceRelayout);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005803 } catch (RemoteException e) {
5804 // Ignore
5805 }
5806 }
5807
Daniel Sandler6396c722013-04-16 20:19:09 -04005808 /**
5809 * Return an Intent to launch the currently active dock app as home. Returns
5810 * null if the standard home should be launched, which is the case if any of the following is
5811 * true:
5812 * <ul>
5813 * <li>The device is not in either car mode or desk mode
5814 * <li>The device is in car mode but ENABLE_CAR_DOCK_HOME_CAPTURE is false
5815 * <li>The device is in desk mode but ENABLE_DESK_DOCK_HOME_CAPTURE is false
5816 * <li>The device is in car mode but there's no CAR_DOCK app with METADATA_DOCK_HOME
5817 * <li>The device is in desk mode but there's no DESK_DOCK app with METADATA_DOCK_HOME
5818 * </ul>
Craig Mautnereda67292013-04-28 13:50:14 -07005819 * @return A dock intent.
Daniel Sandler6396c722013-04-16 20:19:09 -04005820 */
5821 Intent createHomeDockIntent() {
5822 Intent intent = null;
5823
5824 // What home does is based on the mode, not the dock state. That
5825 // is, when in car mode you should be taken to car home regardless
5826 // of whether we are actually in a car dock.
5827 if (mUiMode == Configuration.UI_MODE_TYPE_CAR) {
5828 if (ENABLE_CAR_DOCK_HOME_CAPTURE) {
5829 intent = mCarDockIntent;
5830 }
5831 } else if (mUiMode == Configuration.UI_MODE_TYPE_DESK) {
5832 if (ENABLE_DESK_DOCK_HOME_CAPTURE) {
5833 intent = mDeskDockIntent;
5834 }
Jeff Brown4f5fa282014-06-12 19:19:15 -07005835 } else if (mUiMode == Configuration.UI_MODE_TYPE_WATCH
5836 && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
5837 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK
5838 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK)) {
5839 // Always launch dock home from home when watch is docked, if it exists.
5840 intent = mDeskDockIntent;
Daniel Sandler6396c722013-04-16 20:19:09 -04005841 }
5842
5843 if (intent == null) {
5844 return null;
5845 }
5846
5847 ActivityInfo ai = null;
5848 ResolveInfo info = mContext.getPackageManager().resolveActivityAsUser(
5849 intent,
John Spurlockf56bef12013-07-09 09:51:46 -04005850 PackageManager.MATCH_DEFAULT_ONLY | PackageManager.GET_META_DATA,
Craig Mautnerd625ab22013-09-06 13:40:31 -07005851 mCurrentUserId);
Daniel Sandler6396c722013-04-16 20:19:09 -04005852 if (info != null) {
5853 ai = info.activityInfo;
5854 }
5855 if (ai != null
5856 && ai.metaData != null
5857 && ai.metaData.getBoolean(Intent.METADATA_DOCK_HOME)) {
5858 intent = new Intent(intent);
5859 intent.setClassName(ai.packageName, ai.name);
5860 return intent;
5861 }
5862
5863 return null;
5864 }
5865
Bryce Lee01b0c5f2015-02-05 18:24:04 -08005866 void startDockOrHome(boolean fromHomeKey) {
John Spurlockc8b46ca2013-04-08 12:59:26 -04005867 awakenDreams();
Daniel Sandler6396c722013-04-16 20:19:09 -04005868
5869 Intent dock = createHomeDockIntent();
5870 if (dock != null) {
5871 try {
Bryce Lee01b0c5f2015-02-05 18:24:04 -08005872 if (fromHomeKey) {
5873 dock.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
5874 }
Daniel Sandler6396c722013-04-16 20:19:09 -04005875 mContext.startActivityAsUser(dock, UserHandle.CURRENT);
5876 return;
5877 } catch (ActivityNotFoundException e) {
5878 }
5879 }
5880
Bryce Lee01b0c5f2015-02-05 18:24:04 -08005881 Intent intent;
5882
5883 if (fromHomeKey) {
5884 intent = new Intent(mHomeIntent);
5885 intent.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
5886 } else {
5887 intent = mHomeIntent;
5888 }
5889
5890 mContext.startActivityAsUser(intent, UserHandle.CURRENT);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005891 }
Craig Mautnereda67292013-04-28 13:50:14 -07005892
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005893 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005894 * goes to the home screen
5895 * @return whether it did anything
5896 */
5897 boolean goHome() {
5898 if (false) {
5899 // This code always brings home to the front.
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07005900 try {
5901 ActivityManagerNative.getDefault().stopAppSwitches();
5902 } catch (RemoteException e) {
5903 }
Dianne Hackborn94a679d2009-07-28 17:51:07 -07005904 sendCloseSystemWindows();
Bryce Lee01b0c5f2015-02-05 18:24:04 -08005905 startDockOrHome(false /*fromHomeKey*/);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005906 } else {
5907 // This code brings home to the front or, if it is already
5908 // at the front, puts the device to sleep.
5909 try {
Wink Savilled2e6a332010-02-12 12:12:06 -08005910 if (SystemProperties.getInt("persist.sys.uts-test-mode", 0) == 1) {
5911 /// Roll back EndcallBehavior as the cupcake design to pass P1 lab entry.
5912 Log.d(TAG, "UTS-TEST-MODE");
5913 } else {
5914 ActivityManagerNative.getDefault().stopAppSwitches();
5915 sendCloseSystemWindows();
Daniel Sandler6396c722013-04-16 20:19:09 -04005916 Intent dock = createHomeDockIntent();
5917 if (dock != null) {
5918 int result = ActivityManagerNative.getDefault()
5919 .startActivityAsUser(null, null, dock,
5920 dock.resolveTypeIfNeeded(mContext.getContentResolver()),
5921 null, null, 0,
5922 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07005923 null, null, UserHandle.USER_CURRENT);
Daniel Sandler6396c722013-04-16 20:19:09 -04005924 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
5925 return false;
5926 }
5927 }
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005928 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005929 int result = ActivityManagerNative.getDefault()
Dianne Hackbornf265ea92013-01-31 15:00:51 -08005930 .startActivityAsUser(null, null, mHomeIntent,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005931 mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()),
Dianne Hackborna4972e92012-03-14 10:38:05 -07005932 null, null, 0,
5933 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07005934 null, null, UserHandle.USER_CURRENT);
Dianne Hackborna4972e92012-03-14 10:38:05 -07005935 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005936 return false;
5937 }
5938 } catch (RemoteException ex) {
5939 // bummer, the activity manager, which is in this process, is dead
5940 }
5941 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005942 return true;
5943 }
Craig Mautnereda67292013-04-28 13:50:14 -07005944
5945 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07005946 public void setCurrentOrientationLw(int newOrientation) {
5947 synchronized (mLock) {
5948 if (newOrientation != mCurrentAppOrientation) {
5949 mCurrentAppOrientation = newOrientation;
5950 updateOrientationListenerLp();
5951 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005952 }
5953 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08005954
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07005955 private void performAuditoryFeedbackForAccessibilityIfNeed() {
5956 if (!isGlobalAccessibilityGestureEnabled()) {
5957 return;
5958 }
5959 AudioManager audioManager = (AudioManager) mContext.getSystemService(
5960 Context.AUDIO_SERVICE);
5961 if (audioManager.isSilentMode()) {
5962 return;
5963 }
5964 Ringtone ringTone = RingtoneManager.getRingtone(mContext,
5965 Settings.System.DEFAULT_NOTIFICATION_URI);
5966 ringTone.setStreamType(AudioManager.STREAM_MUSIC);
5967 ringTone.play();
5968 }
Craig Mautnereda67292013-04-28 13:50:14 -07005969
Bryce Lee584a4452014-10-21 15:55:55 -07005970 private boolean isTheaterModeEnabled() {
5971 return Settings.Global.getInt(mContext.getContentResolver(),
5972 Settings.Global.THEATER_MODE_ON, 0) == 1;
5973 }
5974
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07005975 private boolean isGlobalAccessibilityGestureEnabled() {
5976 return Settings.Global.getInt(mContext.getContentResolver(),
5977 Settings.Global.ENABLE_ACCESSIBILITY_GLOBAL_GESTURE_ENABLED, 0) == 1;
5978 }
5979
Craig Mautnereda67292013-04-28 13:50:14 -07005980 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07005981 public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) {
Svetoslav Ganov96179212012-10-10 14:17:45 -07005982 if (!mVibrator.hasVibrator()) {
5983 return false;
5984 }
Christopher Tate5e08af02012-09-21 17:17:22 -07005985 final boolean hapticsDisabled = Settings.System.getIntForUser(mContext.getContentResolver(),
5986 Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) == 0;
Jeff Brown82379ba2014-07-25 19:03:28 -07005987 if (hapticsDisabled && !always) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005988 return false;
5989 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08005990 long[] pattern = null;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005991 switch (effectId) {
5992 case HapticFeedbackConstants.LONG_PRESS:
Amith Yamasanic33cb712010-02-10 15:21:49 -08005993 pattern = mLongPressVibePattern;
5994 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07005995 case HapticFeedbackConstants.VIRTUAL_KEY:
Amith Yamasanic33cb712010-02-10 15:21:49 -08005996 pattern = mVirtualKeyVibePattern;
5997 break;
5998 case HapticFeedbackConstants.KEYBOARD_TAP:
5999 pattern = mKeyboardTapVibePattern;
6000 break;
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07006001 case HapticFeedbackConstants.CLOCK_TICK:
6002 pattern = mClockTickVibePattern;
6003 break;
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07006004 case HapticFeedbackConstants.CALENDAR_DATE:
6005 pattern = mCalendarDateVibePattern;
6006 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006007 case HapticFeedbackConstants.SAFE_MODE_DISABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006008 pattern = mSafeModeDisabledVibePattern;
6009 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006010 case HapticFeedbackConstants.SAFE_MODE_ENABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006011 pattern = mSafeModeEnabledVibePattern;
6012 break;
Amith Yamasanic33cb712010-02-10 15:21:49 -08006013 default:
6014 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006015 }
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006016 int owningUid;
6017 String owningPackage;
6018 if (win != null) {
6019 owningUid = win.getOwningUid();
6020 owningPackage = win.getOwningPackage();
6021 } else {
6022 owningUid = android.os.Process.myUid();
Dianne Hackborn95d78532013-09-11 09:51:14 -07006023 owningPackage = mContext.getOpPackageName();
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006024 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006025 if (pattern.length == 1) {
6026 // One-shot vibration
John Spurlock7b414672014-07-18 13:02:39 -04006027 mVibrator.vibrate(owningUid, owningPackage, pattern[0], VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08006028 } else {
6029 // Pattern vibration
John Spurlock7b414672014-07-18 13:02:39 -04006030 mVibrator.vibrate(owningUid, owningPackage, pattern, -1, VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08006031 }
6032 return true;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006033 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07006034
6035 @Override
6036 public void keepScreenOnStartedLw() {
Daniel Sandler0601eb72011-04-13 01:01:32 -04006037 }
6038
Jeff Brownc38c9be2012-10-04 13:16:19 -07006039 @Override
6040 public void keepScreenOnStoppedLw() {
Jim Millerab954542014-10-10 18:21:49 -07006041 if (isKeyguardShowingAndNotOccluded()) {
Jim Miller25190572013-02-28 17:36:24 -08006042 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006043 }
6044 }
Mike Lockwoodfcb39242009-10-21 23:01:07 -04006045
Dianne Hackborndf89e652011-10-06 22:35:11 -07006046 private int updateSystemUiVisibilityLw() {
Joe Onorato664644d2011-01-23 17:53:23 -08006047 // If there is no window focused, there will be nobody to handle the events
6048 // anyway, so just hang on in whatever state we're in until things settle down.
Adrian Roos53f28ec2014-10-29 17:26:12 +01006049 final WindowState win = mFocusedWindow != null ? mFocusedWindow
6050 : mTopFullscreenOpaqueWindowState;
John Spurlock79da8332013-09-20 12:04:47 -04006051 if (win == null) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006052 return 0;
6053 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01006054 if ((win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 && mHideLockScreen == true) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07006055 // We are updating at a point where the keyguard has gotten
6056 // focus, but we were last in a state where the top window is
6057 // hiding it. This is probably because the keyguard as been
6058 // shown while the top window was displayed, so we want to ignore
6059 // it here because this is just a very transient change and it
6060 // will quickly lose focus once it correctly gets hidden.
6061 return 0;
6062 }
John Spurlock32beb2c2013-03-11 10:16:47 -04006063
John Spurlock1db8b682014-02-18 11:18:59 -05006064 int tmpVisibility = PolicyControl.getSystemUiVisibility(win, null)
Dianne Hackborne26ab702011-10-16 13:21:33 -07006065 & ~mResettingSystemUiFlags
6066 & ~mForceClearedSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04006067 if (mForcingShowNavBar && win.getSurfaceLayer() < mForcingShowNavBarLayer) {
John Spurlockc6d1c602014-01-17 15:22:06 -05006068 tmpVisibility &= ~PolicyControl.adjustClearableFlags(win, View.SYSTEM_UI_CLEARABLE_FLAGS);
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08006069 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01006070 tmpVisibility = updateLightStatusBarLw(tmpVisibility);
John Spurlock79da8332013-09-20 12:04:47 -04006071 final int visibility = updateSystemBarsLw(win, mLastSystemUiFlags, tmpVisibility);
John Spurlockad3e6cb2013-04-30 08:47:43 -04006072 final int diff = visibility ^ mLastSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04006073 final boolean needsMenu = win.getNeedsMenuLw(mTopFullscreenOpaqueWindowState);
Dianne Hackborne0f085d2011-11-30 18:41:15 -08006074 if (diff == 0 && mLastFocusNeedsMenu == needsMenu
John Spurlock79da8332013-09-20 12:04:47 -04006075 && mFocusedApp == win.getAppToken()) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006076 return 0;
6077 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07006078 mLastSystemUiFlags = visibility;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08006079 mLastFocusNeedsMenu = needsMenu;
John Spurlock79da8332013-09-20 12:04:47 -04006080 mFocusedApp = win.getAppToken();
Dianne Hackborndf89e652011-10-06 22:35:11 -07006081 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07006082 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07006083 public void run() {
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006084 try {
6085 IStatusBarService statusbar = getStatusBarService();
6086 if (statusbar != null) {
Adrian Roos53f28ec2014-10-29 17:26:12 +01006087 statusbar.setSystemUiVisibility(visibility, 0xffffffff, win.toString());
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006088 statusbar.topAppWindowChanged(needsMenu);
Joe Onorato664644d2011-01-23 17:53:23 -08006089 }
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006090 } catch (RemoteException e) {
6091 // re-acquire status bar service next time it is needed.
6092 mStatusBarService = null;
Joe Onorato664644d2011-01-23 17:53:23 -08006093 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07006094 }
6095 });
6096 return diff;
Joe Onorato664644d2011-01-23 17:53:23 -08006097 }
6098
Adrian Rooscd3884d2015-02-18 17:25:23 +01006099 private int updateLightStatusBarLw(int vis) {
6100 WindowState statusColorWin = isStatusBarKeyguard() && !mHideLockScreen
6101 ? mStatusBar
6102 : mTopFullscreenOpaqueOrDimmingWindowState;
6103
6104 if (statusColorWin != null) {
6105 if (statusColorWin == mTopFullscreenOpaqueWindowState) {
6106 // If the top fullscreen-or-dimming window is also the top fullscreen, respect
6107 // its light flag.
6108 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6109 vis |= PolicyControl.getSystemUiVisibility(statusColorWin, null)
6110 & View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6111 } else if (statusColorWin != null && statusColorWin.isDimming()) {
6112 // Otherwise if it's dimming, clear the light flag.
6113 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6114 }
6115 }
6116 return vis;
6117 }
6118
John Spurlock79da8332013-09-20 12:04:47 -04006119 private int updateSystemBarsLw(WindowState win, int oldVis, int vis) {
John Spurlockbd957402013-10-03 11:38:39 -04006120 // apply translucent bar vis flags
Jorim Jaggi380ecb82014-03-14 17:25:20 +01006121 WindowState transWin = isStatusBarKeyguard() && !mHideLockScreen
6122 ? mStatusBar
John Spurlockbd957402013-10-03 11:38:39 -04006123 : mTopFullscreenOpaqueWindowState;
6124 vis = mStatusBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
6125 vis = mNavigationBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
6126
John Spurlock27735a42013-08-14 17:57:38 -04006127 // prevent status bar interaction from clearing certain flags
John Spurlock79da8332013-09-20 12:04:47 -04006128 boolean statusBarHasFocus = win.getAttrs().type == TYPE_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04006129 if (statusBarHasFocus && !isStatusBarKeyguard()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04006130 int flags = View.SYSTEM_UI_FLAG_FULLSCREEN
6131 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlockcfc359a2013-09-05 10:42:03 -04006132 | View.SYSTEM_UI_FLAG_IMMERSIVE
Jorim Jaggi73fef8d2015-02-16 17:32:28 +01006133 | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
6134 | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04006135 if (mHideLockScreen) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01006136 flags |= View.STATUS_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSLUCENT;
6137 }
John Spurlockbd957402013-10-03 11:38:39 -04006138 vis = (vis & ~flags) | (oldVis & flags);
John Spurlockad3e6cb2013-04-30 08:47:43 -04006139 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04006140
Adrian Roos4fb3ee32014-08-22 19:29:09 +02006141 if (!areTranslucentBarsAllowed() && transWin != mStatusBar) {
Adrian Roosea562512014-05-05 13:33:03 +02006142 vis &= ~(View.NAVIGATION_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSLUCENT
6143 | View.SYSTEM_UI_TRANSPARENT);
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006144 }
6145
John Spurlock27735a42013-08-14 17:57:38 -04006146 // update status bar
John Spurlockf1a36642013-10-12 17:50:42 -04006147 boolean immersiveSticky =
6148 (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
John Spurlock27735a42013-08-14 17:57:38 -04006149 boolean hideStatusBarWM =
John Spurlockbd957402013-10-03 11:38:39 -04006150 mTopFullscreenOpaqueWindowState != null &&
John Spurlockc6d1c602014-01-17 15:22:06 -05006151 (PolicyControl.getWindowFlags(mTopFullscreenOpaqueWindowState, null)
John Spurlock27735a42013-08-14 17:57:38 -04006152 & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0;
6153 boolean hideStatusBarSysui =
6154 (vis & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04006155 boolean hideNavBarSysui =
6156 (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006157
John Spurlock27735a42013-08-14 17:57:38 -04006158 boolean transientStatusBarAllowed =
6159 mStatusBar != null && (
6160 hideStatusBarWM
John Spurlockf1a36642013-10-12 17:50:42 -04006161 || (hideStatusBarSysui && immersiveSticky)
John Spurlock27735a42013-08-14 17:57:38 -04006162 || statusBarHasFocus);
6163
John Spurlockf1a36642013-10-12 17:50:42 -04006164 boolean transientNavBarAllowed =
6165 mNavigationBar != null &&
6166 hideNavBarSysui && immersiveSticky;
6167
John Spurlockf25706f2013-11-07 18:02:43 -05006168 boolean denyTransientStatus = mStatusBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04006169 && !transientStatusBarAllowed && hideStatusBarSysui;
John Spurlockf25706f2013-11-07 18:02:43 -05006170 boolean denyTransientNav = mNavigationBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04006171 && !transientNavBarAllowed;
6172 if (denyTransientStatus || denyTransientNav) {
John Spurlock27735a42013-08-14 17:57:38 -04006173 // clear the clearable flags instead
John Spurlockf1a36642013-10-12 17:50:42 -04006174 clearClearableFlagsLw();
tiger_huangc58d7562014-10-23 20:24:19 +08006175 vis &= ~View.SYSTEM_UI_CLEARABLE_FLAGS;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006176 }
John Spurlock27735a42013-08-14 17:57:38 -04006177
6178 vis = mStatusBarController.updateVisibilityLw(transientStatusBarAllowed, oldVis, vis);
6179
6180 // update navigation bar
John Spurlockf1a36642013-10-12 17:50:42 -04006181 boolean oldImmersiveMode = isImmersiveMode(oldVis);
6182 boolean newImmersiveMode = isImmersiveMode(vis);
6183 if (win != null && oldImmersiveMode != newImmersiveMode) {
John Spurlock79da8332013-09-20 12:04:47 -04006184 final String pkg = win.getOwningPackage();
Maurice Lam99c6e072014-04-28 18:24:28 -07006185 mImmersiveModeConfirmation.immersiveModeChanged(pkg, newImmersiveMode,
6186 isUserSetupComplete());
John Spurlock34e13d92013-08-10 06:52:28 -04006187 }
John Spurlock27735a42013-08-14 17:57:38 -04006188
John Spurlockf1a36642013-10-12 17:50:42 -04006189 vis = mNavigationBarController.updateVisibilityLw(transientNavBarAllowed, oldVis, vis);
6190
John Spurlocke1f366f2013-08-05 12:22:40 -04006191 return vis;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006192 }
6193
John Spurlockf1a36642013-10-12 17:50:42 -04006194 private void clearClearableFlagsLw() {
6195 int newVal = mResettingSystemUiFlags | View.SYSTEM_UI_CLEARABLE_FLAGS;
6196 if (newVal != mResettingSystemUiFlags) {
6197 mResettingSystemUiFlags = newVal;
6198 mWindowManagerFuncs.reevaluateStatusBarVisibility();
6199 }
6200 }
6201
6202 private boolean isImmersiveMode(int vis) {
6203 final int flags = View.SYSTEM_UI_FLAG_IMMERSIVE | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
John Spurlock34e13d92013-08-10 06:52:28 -04006204 return mNavigationBar != null
6205 && (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0
Daniel Sandler900ece52013-10-18 15:53:27 -04006206 && (vis & flags) != 0
6207 && canHideNavigationBar();
John Spurlock34e13d92013-08-10 06:52:28 -04006208 }
6209
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006210 /**
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04006211 * @return whether the navigation or status bar can be made translucent
6212 *
6213 * This should return true unless touch exploration is not enabled or
6214 * R.boolean.config_enableTranslucentDecor is false.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006215 */
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04006216 private boolean areTranslucentBarsAllowed() {
Svetoslav8e3feb12014-02-24 13:46:47 -08006217 return mTranslucentDecorEnabled
6218 && !mAccessibilityManager.isTouchExplorationEnabled();
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006219 }
6220
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04006221 // Use this instead of checking config_showNavigationBar so that it can be consistently
6222 // overridden by qemu.hw.mainkeys in the emulator.
Craig Mautnereda67292013-04-28 13:50:14 -07006223 @Override
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04006224 public boolean hasNavigationBar() {
6225 return mHasNavigationBar;
6226 }
6227
satok1bc0a492012-04-25 22:47:12 +09006228 @Override
6229 public void setLastInputMethodWindowLw(WindowState ime, WindowState target) {
6230 mLastInputMethodWindow = ime;
6231 mLastInputMethodTargetWindow = target;
6232 }
6233
Craig Mautnerf1b67412012-09-19 13:18:29 -07006234 @Override
Satoshi Kataoka658c7b82013-10-10 17:03:51 +09006235 public int getInputMethodWindowVisibleHeightLw() {
6236 return mDockBottom - mCurBottom;
6237 }
6238
6239 @Override
Craig Mautnerf1b67412012-09-19 13:18:29 -07006240 public void setCurrentUserLw(int newUserId) {
Craig Mautnerd625ab22013-09-06 13:40:31 -07006241 mCurrentUserId = newUserId;
Jim Miller5ecd8112013-01-09 18:50:26 -08006242 if (mKeyguardDelegate != null) {
6243 mKeyguardDelegate.setCurrentUser(newUserId);
Craig Mautnerf1b67412012-09-19 13:18:29 -07006244 }
John Spurlock13451a22012-09-28 14:40:41 -04006245 if (mStatusBarService != null) {
6246 try {
6247 mStatusBarService.setCurrentUser(newUserId);
6248 } catch (RemoteException e) {
6249 // oh well
6250 }
6251 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006252 setLastInputMethodWindowLw(null, null);
Craig Mautnerf1b67412012-09-19 13:18:29 -07006253 }
6254
6255 @Override
Svetoslav Ganov545252f2012-12-10 18:29:24 -08006256 public boolean canMagnifyWindow(int windowType) {
6257 switch (windowType) {
6258 case WindowManager.LayoutParams.TYPE_INPUT_METHOD:
6259 case WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG:
6260 case WindowManager.LayoutParams.TYPE_NAVIGATION_BAR:
6261 case WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY: {
6262 return false;
6263 }
6264 }
6265 return true;
6266 }
6267
6268 @Override
6269 public boolean isTopLevelWindow(int windowType) {
6270 if (windowType >= WindowManager.LayoutParams.FIRST_SUB_WINDOW
6271 && windowType <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
6272 return (windowType == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG);
6273 }
6274 return true;
6275 }
6276
Jim Miller4eeb4f62012-11-08 00:04:29 -08006277 @Override
Jeff Brownd7a04de2012-06-17 14:17:52 -07006278 public void dump(String prefix, PrintWriter pw, String[] args) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006279 pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07006280 pw.print(" mSystemReady="); pw.print(mSystemReady);
6281 pw.print(" mSystemBooted="); pw.println(mSystemBooted);
Jeff Brown2e7760e2012-04-11 15:14:55 -07006282 pw.print(prefix); pw.print("mLidState="); pw.print(mLidState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006283 pw.print(" mLidOpenRotation="); pw.print(mLidOpenRotation);
Michael Wright3818c922014-09-02 13:59:07 -07006284 pw.print(" mCameraLensCoverState="); pw.print(mCameraLensCoverState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006285 pw.print(" mHdmiPlugged="); pw.println(mHdmiPlugged);
Dianne Hackborne26ab702011-10-16 13:21:33 -07006286 if (mLastSystemUiFlags != 0 || mResettingSystemUiFlags != 0
6287 || mForceClearedSystemUiFlags != 0) {
6288 pw.print(prefix); pw.print("mLastSystemUiFlags=0x");
6289 pw.print(Integer.toHexString(mLastSystemUiFlags));
6290 pw.print(" mResettingSystemUiFlags=0x");
6291 pw.print(Integer.toHexString(mResettingSystemUiFlags));
6292 pw.print(" mForceClearedSystemUiFlags=0x");
6293 pw.println(Integer.toHexString(mForceClearedSystemUiFlags));
Dianne Hackborndf89e652011-10-06 22:35:11 -07006294 }
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08006295 if (mLastFocusNeedsMenu) {
6296 pw.print(prefix); pw.print("mLastFocusNeedsMenu=");
6297 pw.println(mLastFocusNeedsMenu);
6298 }
Jeff Browna20dda42014-05-27 20:57:24 -07006299 pw.print(prefix); pw.print("mWakeGestureEnabledSetting=");
6300 pw.println(mWakeGestureEnabledSetting);
6301
Jeff Brownbcdfc622014-03-06 19:13:04 -08006302 pw.print(prefix); pw.print("mSupportAutoRotation="); pw.println(mSupportAutoRotation);
Daniel Sandler6396c722013-04-16 20:19:09 -04006303 pw.print(prefix); pw.print("mUiMode="); pw.print(mUiMode);
6304 pw.print(" mDockMode="); pw.print(mDockMode);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006305 pw.print(" mCarDockRotation="); pw.print(mCarDockRotation);
6306 pw.print(" mDeskDockRotation="); pw.println(mDeskDockRotation);
6307 pw.print(prefix); pw.print("mUserRotationMode="); pw.print(mUserRotationMode);
6308 pw.print(" mUserRotation="); pw.print(mUserRotation);
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05006309 pw.print(" mAllowAllRotations="); pw.println(mAllowAllRotations);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07006310 pw.print(prefix); pw.print("mCurrentAppOrientation="); pw.println(mCurrentAppOrientation);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006311 pw.print(prefix); pw.print("mCarDockEnablesAccelerometer=");
6312 pw.print(mCarDockEnablesAccelerometer);
6313 pw.print(" mDeskDockEnablesAccelerometer=");
6314 pw.println(mDeskDockEnablesAccelerometer);
6315 pw.print(prefix); pw.print("mLidKeyboardAccessibility=");
6316 pw.print(mLidKeyboardAccessibility);
6317 pw.print(" mLidNavigationAccessibility="); pw.print(mLidNavigationAccessibility);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07006318 pw.print(" mLidControlsSleep="); pw.println(mLidControlsSleep);
Jeff Brown6d8fd272014-05-20 21:24:38 -07006319 pw.print(prefix);
6320 pw.print("mShortPressOnPowerBehavior="); pw.print(mShortPressOnPowerBehavior);
6321 pw.print(" mLongPressOnPowerBehavior="); pw.println(mLongPressOnPowerBehavior);
Jeff Brown13f00f02014-10-31 14:45:50 -07006322 pw.print(prefix);
6323 pw.print("mDoublePressOnPowerBehavior="); pw.print(mDoublePressOnPowerBehavior);
6324 pw.print(" mTriplePressOnPowerBehavior="); pw.println(mTriplePressOnPowerBehavior);
Jeff Brown6d8fd272014-05-20 21:24:38 -07006325 pw.print(prefix); pw.print("mHasSoftInput="); pw.println(mHasSoftInput);
Jeff Brown3ee549c2014-09-22 20:14:39 -07006326 pw.print(prefix); pw.print("mAwake="); pw.println(mAwake);
6327 pw.print(prefix); pw.print("mScreenOnEarly="); pw.print(mScreenOnEarly);
6328 pw.print(" mScreenOnFully="); pw.println(mScreenOnFully);
6329 pw.print(prefix); pw.print("mKeyguardDrawComplete="); pw.print(mKeyguardDrawComplete);
6330 pw.print(" mWindowManagerDrawComplete="); pw.println(mWindowManagerDrawComplete);
6331 pw.print(prefix); pw.print("mOrientationSensorEnabled=");
6332 pw.println(mOrientationSensorEnabled);
Dianne Hackbornc652de82013-02-15 16:32:56 -08006333 pw.print(prefix); pw.print("mOverscanScreen=("); pw.print(mOverscanScreenLeft);
6334 pw.print(","); pw.print(mOverscanScreenTop);
6335 pw.print(") "); pw.print(mOverscanScreenWidth);
6336 pw.print("x"); pw.println(mOverscanScreenHeight);
6337 if (mOverscanLeft != 0 || mOverscanTop != 0
6338 || mOverscanRight != 0 || mOverscanBottom != 0) {
6339 pw.print(prefix); pw.print("mOverscan left="); pw.print(mOverscanLeft);
6340 pw.print(" top="); pw.print(mOverscanTop);
6341 pw.print(" right="); pw.print(mOverscanRight);
6342 pw.print(" bottom="); pw.println(mOverscanBottom);
6343 }
Dianne Hackborn313440842013-02-19 19:22:59 -08006344 pw.print(prefix); pw.print("mRestrictedOverscanScreen=(");
6345 pw.print(mRestrictedOverscanScreenLeft);
6346 pw.print(","); pw.print(mRestrictedOverscanScreenTop);
6347 pw.print(") "); pw.print(mRestrictedOverscanScreenWidth);
6348 pw.print("x"); pw.println(mRestrictedOverscanScreenHeight);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006349 pw.print(prefix); pw.print("mUnrestrictedScreen=("); pw.print(mUnrestrictedScreenLeft);
6350 pw.print(","); pw.print(mUnrestrictedScreenTop);
6351 pw.print(") "); pw.print(mUnrestrictedScreenWidth);
6352 pw.print("x"); pw.println(mUnrestrictedScreenHeight);
6353 pw.print(prefix); pw.print("mRestrictedScreen=("); pw.print(mRestrictedScreenLeft);
6354 pw.print(","); pw.print(mRestrictedScreenTop);
6355 pw.print(") "); pw.print(mRestrictedScreenWidth);
6356 pw.print("x"); pw.println(mRestrictedScreenHeight);
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07006357 pw.print(prefix); pw.print("mStableFullscreen=("); pw.print(mStableFullscreenLeft);
6358 pw.print(","); pw.print(mStableFullscreenTop);
6359 pw.print(")-("); pw.print(mStableFullscreenRight);
6360 pw.print(","); pw.print(mStableFullscreenBottom); pw.println(")");
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07006361 pw.print(prefix); pw.print("mStable=("); pw.print(mStableLeft);
6362 pw.print(","); pw.print(mStableTop);
6363 pw.print(")-("); pw.print(mStableRight);
6364 pw.print(","); pw.print(mStableBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07006365 pw.print(prefix); pw.print("mSystem=("); pw.print(mSystemLeft);
6366 pw.print(","); pw.print(mSystemTop);
6367 pw.print(")-("); pw.print(mSystemRight);
6368 pw.print(","); pw.print(mSystemBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006369 pw.print(prefix); pw.print("mCur=("); pw.print(mCurLeft);
6370 pw.print(","); pw.print(mCurTop);
6371 pw.print(")-("); pw.print(mCurRight);
6372 pw.print(","); pw.print(mCurBottom); pw.println(")");
6373 pw.print(prefix); pw.print("mContent=("); pw.print(mContentLeft);
6374 pw.print(","); pw.print(mContentTop);
6375 pw.print(")-("); pw.print(mContentRight);
6376 pw.print(","); pw.print(mContentBottom); pw.println(")");
Dianne Hackborne30e02f2014-05-27 18:24:45 -07006377 pw.print(prefix); pw.print("mVoiceContent=("); pw.print(mVoiceContentLeft);
6378 pw.print(","); pw.print(mVoiceContentTop);
6379 pw.print(")-("); pw.print(mVoiceContentRight);
6380 pw.print(","); pw.print(mVoiceContentBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006381 pw.print(prefix); pw.print("mDock=("); pw.print(mDockLeft);
6382 pw.print(","); pw.print(mDockTop);
6383 pw.print(")-("); pw.print(mDockRight);
6384 pw.print(","); pw.print(mDockBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07006385 pw.print(prefix); pw.print("mDockLayer="); pw.print(mDockLayer);
6386 pw.print(" mStatusBarLayer="); pw.println(mStatusBarLayer);
Dianne Hackborn7ad44382012-10-18 17:46:00 -07006387 pw.print(prefix); pw.print("mShowingLockscreen="); pw.print(mShowingLockscreen);
6388 pw.print(" mShowingDream="); pw.print(mShowingDream);
6389 pw.print(" mDreamingLockscreen="); pw.println(mDreamingLockscreen);
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006390 if (mLastInputMethodWindow != null) {
6391 pw.print(prefix); pw.print("mLastInputMethodWindow=");
6392 pw.println(mLastInputMethodWindow);
6393 }
6394 if (mLastInputMethodTargetWindow != null) {
6395 pw.print(prefix); pw.print("mLastInputMethodTargetWindow=");
6396 pw.println(mLastInputMethodTargetWindow);
6397 }
6398 if (mStatusBar != null) {
6399 pw.print(prefix); pw.print("mStatusBar=");
Dianne Hackbornae6688b2015-02-11 17:02:41 -08006400 pw.print(mStatusBar); pw.print(" isStatusBarKeyguard=");
6401 pw.println(isStatusBarKeyguard());
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006402 }
6403 if (mNavigationBar != null) {
6404 pw.print(prefix); pw.print("mNavigationBar=");
6405 pw.println(mNavigationBar);
6406 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006407 if (mFocusedWindow != null) {
6408 pw.print(prefix); pw.print("mFocusedWindow=");
6409 pw.println(mFocusedWindow);
6410 }
6411 if (mFocusedApp != null) {
6412 pw.print(prefix); pw.print("mFocusedApp=");
6413 pw.println(mFocusedApp);
6414 }
6415 if (mWinDismissingKeyguard != null) {
6416 pw.print(prefix); pw.print("mWinDismissingKeyguard=");
6417 pw.println(mWinDismissingKeyguard);
6418 }
6419 if (mTopFullscreenOpaqueWindowState != null) {
6420 pw.print(prefix); pw.print("mTopFullscreenOpaqueWindowState=");
6421 pw.println(mTopFullscreenOpaqueWindowState);
6422 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01006423 if (mTopFullscreenOpaqueOrDimmingWindowState != null) {
6424 pw.print(prefix); pw.print("mTopFullscreenOpaqueOrDimmingWindowState=");
6425 pw.println(mTopFullscreenOpaqueOrDimmingWindowState);
6426 }
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08006427 if (mForcingShowNavBar) {
6428 pw.print(prefix); pw.print("mForcingShowNavBar=");
6429 pw.println(mForcingShowNavBar); pw.print( "mForcingShowNavBarLayer=");
6430 pw.println(mForcingShowNavBarLayer);
6431 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07006432 pw.print(prefix); pw.print("mTopIsFullscreen="); pw.print(mTopIsFullscreen);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006433 pw.print(" mHideLockScreen="); pw.println(mHideLockScreen);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07006434 pw.print(prefix); pw.print("mForceStatusBar="); pw.print(mForceStatusBar);
6435 pw.print(" mForceStatusBarFromKeyguard=");
6436 pw.println(mForceStatusBarFromKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006437 pw.print(prefix); pw.print("mDismissKeyguard="); pw.print(mDismissKeyguard);
Craig Mautnerad09bcc2012-10-08 13:33:11 -07006438 pw.print(" mWinDismissingKeyguard="); pw.print(mWinDismissingKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006439 pw.print(" mHomePressed="); pw.println(mHomePressed);
6440 pw.print(prefix); pw.print("mAllowLockscreenWhenOn="); pw.print(mAllowLockscreenWhenOn);
6441 pw.print(" mLockScreenTimeout="); pw.print(mLockScreenTimeout);
6442 pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive);
6443 pw.print(prefix); pw.print("mEndcallBehavior="); pw.print(mEndcallBehavior);
6444 pw.print(" mIncallPowerBehavior="); pw.print(mIncallPowerBehavior);
6445 pw.print(" mLongPressOnHomeBehavior="); pw.println(mLongPressOnHomeBehavior);
6446 pw.print(prefix); pw.print("mLandscapeRotation="); pw.print(mLandscapeRotation);
6447 pw.print(" mSeascapeRotation="); pw.println(mSeascapeRotation);
6448 pw.print(prefix); pw.print("mPortraitRotation="); pw.print(mPortraitRotation);
6449 pw.print(" mUpsideDownRotation="); pw.println(mUpsideDownRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07006450 pw.print(prefix); pw.print("mDemoHdmiRotation="); pw.print(mDemoHdmiRotation);
6451 pw.print(" mDemoHdmiRotationLock="); pw.println(mDemoHdmiRotationLock);
6452 pw.print(prefix); pw.print("mUndockedHdmiRotation="); pw.println(mUndockedHdmiRotation);
Jeff Brown600f0032014-05-22 17:06:00 -07006453
Tim Kilbournd7c0c2e2014-05-29 16:08:10 -07006454 mGlobalKeyManager.dump(prefix, pw);
John Spurlock27735a42013-08-14 17:57:38 -04006455 mStatusBarController.dump(pw, prefix);
6456 mNavigationBarController.dump(pw, prefix);
John Spurlockc6d1c602014-01-17 15:22:06 -05006457 PolicyControl.dump(prefix, pw);
Jeff Brown600f0032014-05-22 17:06:00 -07006458
Jeff Browna20dda42014-05-27 20:57:24 -07006459 if (mWakeGestureListener != null) {
6460 mWakeGestureListener.dump(pw, prefix);
6461 }
Jeff Brown600f0032014-05-22 17:06:00 -07006462 if (mOrientationListener != null) {
6463 mOrientationListener.dump(pw, prefix);
6464 }
Filip Gruszczynskicfb31852015-02-25 21:47:12 +00006465 if (mBurnInProtectionHelper != null) {
6466 mBurnInProtectionHelper.dump(prefix, pw);
6467 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006468 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006469}