blob: 1198110087e58d6497efa5bbf6dbea6d78cbc34b [file] [log] [blame]
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001/*
Jeff Brown37df39a92015-02-25 15:42:31 -08002 * Copyright (C) 2006 The Android Open Source Project
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Jorim Jaggib10e33f2015-02-04 21:57:40 +010017package com.android.server.policy;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080018
Dianne Hackborna4972e92012-03-14 10:38:05 -070019import android.app.ActivityManager;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080020import android.app.ActivityManagerNative;
Dianne Hackbornc2293022013-02-06 23:14:49 -080021import android.app.AppOpsManager;
Daniel Sandler6396c722013-04-16 20:19:09 -040022import android.app.IUiModeManager;
Dianne Hackborn661cd522011-08-22 00:26:20 -070023import android.app.ProgressDialog;
Jeff Brownde7a8ea2012-06-13 18:28:57 -070024import android.app.SearchManager;
John Spurlock97642182013-07-29 17:58:39 -040025import android.app.StatusBarManager;
Dianne Hackborn78968392010-03-04 20:47:56 -080026import android.app.UiModeManager;
Dianne Hackborn39c2d712009-09-22 11:41:31 -070027import android.content.ActivityNotFoundException;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080028import android.content.BroadcastReceiver;
Daniel Sandler0601eb72011-04-13 01:01:32 -040029import android.content.ComponentName;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080030import android.content.ContentResolver;
31import android.content.Context;
32import android.content.Intent;
Mike Lockwood1753f7f2009-08-24 14:49:07 -070033import android.content.IntentFilter;
Winson Chung9112ec32011-06-27 13:15:32 -070034import android.content.ServiceConnection;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080035import android.content.pm.ActivityInfo;
36import android.content.pm.PackageManager;
Daniel Sandler6396c722013-04-16 20:19:09 -040037import android.content.pm.ResolveInfo;
Dianne Hackborn2f0b1752011-05-31 17:59:49 -070038import android.content.res.CompatibilityInfo;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080039import android.content.res.Configuration;
40import android.content.res.Resources;
Craig Mautner8e4df6c2012-05-23 16:57:23 -070041import android.content.res.TypedArray;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080042import android.database.ContentObserver;
Dianne Hackbornc777e072010-02-12 13:07:59 -080043import android.graphics.PixelFormat;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080044import android.graphics.Rect;
John Spurlock7b414672014-07-18 13:02:39 -040045import android.media.AudioAttributes;
Michael Jurka7a348952012-02-27 13:07:58 -080046import android.media.AudioManager;
John Spurlock61560172015-02-06 19:46:04 -050047import android.media.AudioSystem;
Michael Jurka7a348952012-02-27 13:07:58 -080048import android.media.IAudioService;
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -070049import android.media.Ringtone;
50import android.media.RingtoneManager;
RoboErik8a2cfc32014-05-16 11:19:38 -070051import android.media.session.MediaSessionLegacyHelper;
Dianne Hackborn38e29a62011-09-18 14:43:08 -070052import android.os.Bundle;
Craig Mautner276a6eb2014-11-04 15:32:57 -080053import android.os.Debug;
Jeff Brown9a538ee2012-08-20 14:56:57 -070054import android.os.FactoryTest;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080055import android.os.Handler;
56import android.os.IBinder;
Jeff Brown32cbc38552011-12-01 14:01:49 -080057import android.os.Looper;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -070058import android.os.Message;
59import android.os.Messenger;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080060import android.os.PowerManager;
61import android.os.RemoteException;
62import android.os.ServiceManager;
63import android.os.SystemClock;
64import android.os.SystemProperties;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -080065import android.os.UEventObserver;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -070066import android.os.UserHandle;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080067import android.os.Vibrator;
Michael Wright3818c922014-09-02 13:59:07 -070068import android.provider.MediaStore;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080069import android.provider.Settings;
Jose Lima9546b202014-07-02 17:21:51 -070070import android.service.dreams.DreamManagerInternal;
John Spurlockc8b46ca2013-04-08 12:59:26 -040071import android.service.dreams.DreamService;
72import android.service.dreams.IDreamManager;
Michael Wrightdc63f7b2014-08-21 19:05:21 -070073import android.speech.RecognizerIntent;
Tyler Gunnef9f6f92014-09-12 22:16:17 -070074import android.telecom.TelecomManager;
Dianne Hackborn81e56d52011-05-26 00:55:58 -070075import android.util.DisplayMetrics;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080076import android.util.EventLog;
77import android.util.Log;
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;
Craig Mautnerae446592012-12-06 19:05:05 -0800107import com.android.internal.R;
Craig Mautnerae446592012-12-06 19:05:05 -0800108import com.android.internal.statusbar.IStatusBarService;
Craig Mautnerae446592012-12-06 19:05:05 -0800109import com.android.internal.widget.PointerLocationView;
Craig Mautner8a0da012014-05-31 15:13:37 -0700110import com.android.server.LocalServices;
Jorim Jaggib10e33f2015-02-04 21:57:40 +0100111import com.android.server.policy.keyguard.KeyguardServiceDelegate;
112import com.android.server.policy.keyguard.KeyguardServiceDelegate.ShowListener;
Craig Mautnerae446592012-12-06 19:05:05 -0800113
114import java.io.File;
115import java.io.FileReader;
116import java.io.IOException;
117import java.io.PrintWriter;
Craig Mautner2bc789b2014-03-19 19:48:38 -0700118import java.util.HashSet;
Craig Mautner276a6eb2014-11-04 15:32:57 -0800119import java.util.List;
Craig Mautnerae446592012-12-06 19:05:05 -0800120
Dianne Hackbornc652de82013-02-15 16:32:56 -0800121import static android.view.WindowManager.LayoutParams.*;
Jeff Brownac143512012-04-05 18:57:33 -0700122import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_ABSENT;
123import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_OPEN;
124import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_CLOSED;
Michael Wright3818c922014-09-02 13:59:07 -0700125import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVER_ABSENT;
126import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_UNCOVERED;
127import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVERED;
Dianne Hackborn08743722009-12-21 12:16:51 -0800128
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800129/**
The Android Open Source Project0727d222009-03-11 12:11:58 -0700130 * WindowManagerPolicy implementation for the Android phone UI. This
131 * introduces a new method suffix, Lp, for an internal lock of the
132 * PhoneWindowManager. This is used to protect some internal state, and
John Spurlock04db1762013-05-13 12:46:41 -0400133 * 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 -0700134 * of both of those when held.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800135 */
136public class PhoneWindowManager implements WindowManagerPolicy {
137 static final String TAG = "WindowManager";
138 static final boolean DEBUG = false;
Joe Onorato43a17652011-04-06 19:22:23 -0700139 static final boolean localLOGV = false;
Jeff Brown40013652012-05-16 21:22:36 -0700140 static final boolean DEBUG_INPUT = false;
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -0700141 static final boolean DEBUG_KEYGUARD = false;
142 static final boolean DEBUG_LAYOUT = false;
Craig Mautner6fbda632012-07-03 09:26:39 -0700143 static final boolean DEBUG_STARTING_WINDOW = false;
Craig Mautner8a0da012014-05-31 15:13:37 -0700144 static final boolean DEBUG_WAKEUP = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800145 static final boolean SHOW_STARTING_ANIMATIONS = true;
146 static final boolean SHOW_PROCESSES_ON_ALT_MENU = false;
Joe Onoratod208e702010-10-08 16:22:43 -0400147
Daniel Sandler6396c722013-04-16 20:19:09 -0400148 // Whether to allow dock apps with METADATA_DOCK_HOME to temporarily take over the Home key.
149 // No longer recommended for desk docks; still useful in car docks.
150 static final boolean ENABLE_CAR_DOCK_HOME_CAPTURE = true;
151 static final boolean ENABLE_DESK_DOCK_HOME_CAPTURE = false;
152
Jeff Brown6d8fd272014-05-20 21:24:38 -0700153 static final int SHORT_PRESS_POWER_NOTHING = 0;
154 static final int SHORT_PRESS_POWER_GO_TO_SLEEP = 1;
155 static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP = 2;
156 static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME = 3;
Bryce Lee01b0c5f2015-02-05 18:24:04 -0800157 static final int SHORT_PRESS_POWER_GO_HOME = 4;
Jeff Brown6d8fd272014-05-20 21:24:38 -0700158
Joe Onoratod208e702010-10-08 16:22:43 -0400159 static final int LONG_PRESS_POWER_NOTHING = 0;
160 static final int LONG_PRESS_POWER_GLOBAL_ACTIONS = 1;
161 static final int LONG_PRESS_POWER_SHUT_OFF = 2;
Jeff Brown9a538ee2012-08-20 14:56:57 -0700162 static final int LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM = 3;
Michael Jurka3b1fc472011-06-13 10:54:40 -0700163
Jeff Brown13f00f02014-10-31 14:45:50 -0700164 static final int MULTI_PRESS_POWER_NOTHING = 0;
165 static final int MULTI_PRESS_POWER_THEATER_MODE = 1;
166 static final int MULTI_PRESS_POWER_BRIGHTNESS_BOOST = 2;
167
Michael Jurka3b1fc472011-06-13 10:54:40 -0700168 // These need to match the documentation/constant in
169 // core/res/res/values/config.xml
Joe Onorato46b0d682010-11-22 17:37:27 -0800170 static final int LONG_PRESS_HOME_NOTHING = 0;
Michael Wrightc9ebea72013-01-16 19:25:02 -0800171 static final int LONG_PRESS_HOME_RECENT_SYSTEM_UI = 1;
Jeff Browncaca8812013-05-09 13:34:33 -0700172 static final int LONG_PRESS_HOME_ASSIST = 2;
173
174 static final int DOUBLE_TAP_HOME_NOTHING = 0;
175 static final int DOUBLE_TAP_HOME_RECENT_SYSTEM_UI = 1;
Joe Onorato46b0d682010-11-22 17:37:27 -0800176
Dianne Hackborn5cb8d792009-05-21 17:34:15 -0700177 static final int APPLICATION_MEDIA_SUBLAYER = -2;
178 static final int APPLICATION_MEDIA_OVERLAY_SUBLAYER = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800179 static final int APPLICATION_PANEL_SUBLAYER = 1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800180 static final int APPLICATION_SUB_PANEL_SUBLAYER = 2;
Craig Mautner88400d32012-09-30 12:35:45 -0700181
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800182 static public final String SYSTEM_DIALOG_REASON_KEY = "reason";
183 static public final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions";
184 static public final String SYSTEM_DIALOG_REASON_RECENT_APPS = "recentapps";
Joe Onoratof275f0c2009-11-24 16:11:13 -0500185 static public final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey";
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700186 static public final String SYSTEM_DIALOG_REASON_ASSIST = "assist";
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800187
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700188 /**
189 * These are the system UI flags that, when changing, can cause the layout
190 * of the screen to change.
191 */
192 static final int SYSTEM_UI_CHANGING_LAYOUT =
John Spurlocke1f366f2013-08-05 12:22:40 -0400193 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlock7f4820a2013-10-08 12:54:35 -0400194 | View.SYSTEM_UI_FLAG_FULLSCREEN
195 | View.STATUS_BAR_TRANSLUCENT
Adrian Roosea562512014-05-05 13:33:03 +0200196 | View.NAVIGATION_BAR_TRANSLUCENT
197 | View.SYSTEM_UI_TRANSPARENT;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700198
John Spurlock7b414672014-07-18 13:02:39 -0400199 private static final AudioAttributes VIBRATION_ATTRIBUTES = new AudioAttributes.Builder()
200 .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
201 .setUsage(AudioAttributes.USAGE_ASSISTANCE_SONIFICATION)
202 .build();
203
Jim Miller5ecd8112013-01-09 18:50:26 -0800204 /**
205 * Keyguard stuff
206 */
207 private WindowState mKeyguardScrim;
Jorim Jaggi380ecb82014-03-14 17:25:20 +0100208 private boolean mKeyguardHidden;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700209 private boolean mKeyguardDrawnOnce;
Jim Miller5ecd8112013-01-09 18:50:26 -0800210
Jeff Brown6651a632011-11-28 12:59:11 -0800211 /* Table of Application Launch keys. Maps from key codes to intent categories.
212 *
213 * These are special keys that are used to launch particular kinds of applications,
214 * such as a web browser. HID defines nearly a hundred of them in the Consumer (0x0C)
215 * usage page. We don't support quite that many yet...
216 */
217 static SparseArray<String> sApplicationLaunchKeyCategories;
218 static {
219 sApplicationLaunchKeyCategories = new SparseArray<String>();
220 sApplicationLaunchKeyCategories.append(
221 KeyEvent.KEYCODE_EXPLORER, Intent.CATEGORY_APP_BROWSER);
222 sApplicationLaunchKeyCategories.append(
223 KeyEvent.KEYCODE_ENVELOPE, Intent.CATEGORY_APP_EMAIL);
224 sApplicationLaunchKeyCategories.append(
225 KeyEvent.KEYCODE_CONTACTS, Intent.CATEGORY_APP_CONTACTS);
226 sApplicationLaunchKeyCategories.append(
227 KeyEvent.KEYCODE_CALENDAR, Intent.CATEGORY_APP_CALENDAR);
228 sApplicationLaunchKeyCategories.append(
229 KeyEvent.KEYCODE_MUSIC, Intent.CATEGORY_APP_MUSIC);
230 sApplicationLaunchKeyCategories.append(
231 KeyEvent.KEYCODE_CALCULATOR, Intent.CATEGORY_APP_CALCULATOR);
232 }
233
Craig Mautnerc3daedd2014-09-13 11:17:23 -0700234 /** Amount of time (in milliseconds) to wait for windows drawn before powering on. */
235 static final int WAITING_FOR_DRAWN_TIMEOUT = 1000;
236
Dianne Hackborndf89e652011-10-06 22:35:11 -0700237 /**
238 * Lock protecting internal state. Must not call out into window
239 * manager with lock held. (This lock will be acquired in places
240 * where the window manager is calling in with its own lock held.)
241 */
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800242 private final Object mLock = new Object();
Dianne Hackborndf89e652011-10-06 22:35:11 -0700243
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800244 Context mContext;
245 IWindowManager mWindowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700246 WindowManagerFuncs mWindowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -0700247 WindowManagerInternal mWindowManagerInternal;
Jeff Brown96307042012-07-27 15:51:34 -0700248 PowerManager mPowerManager;
Jose Lima9546b202014-07-02 17:21:51 -0700249 DreamManagerInternal mDreamManagerInternal;
Joe Onorato93056472010-09-10 10:30:46 -0400250 IStatusBarService mStatusBarService;
Jeff Browncaca8812013-05-09 13:34:33 -0700251 boolean mPreloadedRecentApps;
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700252 final Object mServiceAquireLock = new Object();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800253 Vibrator mVibrator; // Vibrator for giving feedback of orientation changes
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700254 SearchManager mSearchManager;
Svetoslav8e3feb12014-02-24 13:46:47 -0800255 AccessibilityManager mAccessibilityManager;
Filip Gruszczynskicfb31852015-02-25 21:47:12 +0000256 BurnInProtectionHelper mBurnInProtectionHelper;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800257
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700258 // Vibrator pattern for haptic feedback of a long press.
259 long[] mLongPressVibePattern;
Craig Mautner88400d32012-09-30 12:35:45 -0700260
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700261 // Vibrator pattern for haptic feedback of virtual key press.
262 long[] mVirtualKeyVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700263
Amith Yamasanic33cb712010-02-10 15:21:49 -0800264 // Vibrator pattern for a short vibration.
265 long[] mKeyboardTapVibePattern;
266
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -0700267 // Vibrator pattern for a short vibration when tapping on an hour/minute tick of a Clock.
268 long[] mClockTickVibePattern;
269
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -0700270 // Vibrator pattern for a short vibration when tapping on a day/month/year date of a Calendar.
271 long[] mCalendarDateVibePattern;
272
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700273 // Vibrator pattern for haptic feedback during boot when safe mode is disabled.
274 long[] mSafeModeDisabledVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700275
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700276 // Vibrator pattern for haptic feedback during boot when safe mode is enabled.
277 long[] mSafeModeEnabledVibePattern;
Romain Guy8154cd32010-03-29 14:41:15 -0700278
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800279 /** If true, hitting shift & menu will broadcast Intent.ACTION_BUG_REPORT */
280 boolean mEnableShiftMenuBugReports = false;
Mike Lockwoodd747dc82011-09-13 16:28:22 -0400281
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800282 boolean mSafeMode;
283 WindowState mStatusBar = null;
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700284 int mStatusBarHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400285 WindowState mNavigationBar = null;
Daniel Sandler36412a72011-08-04 09:35:13 -0400286 boolean mHasNavigationBar = false;
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700287 boolean mCanHideNavigationBar = false;
Daniel Sandler4a066c52012-04-20 14:49:13 -0400288 boolean mNavigationBarCanMove = false; // can the navigation bar ever move to the side?
289 boolean mNavigationBarOnBottom = true; // is the navigation bar on the bottom *right now*?
290 int[] mNavigationBarHeightForRotation = new int[4];
291 int[] mNavigationBarWidthForRotation = new int[4];
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400292
Craig Mautnera631d492014-08-05 15:16:01 -0700293 boolean mBootMessageNeedsHiding;
Jim Miller5ecd8112013-01-09 18:50:26 -0800294 KeyguardServiceDelegate mKeyguardDelegate;
Craig Mautner13f6ea72014-06-23 14:57:02 -0700295 final Runnable mWindowManagerDrawCallback = new Runnable() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700296 @Override
Craig Mautner13f6ea72014-06-23 14:57:02 -0700297 public void run() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700298 if (DEBUG_WAKEUP) Slog.i(TAG, "All windows ready for display!");
299 mHandler.sendEmptyMessage(MSG_WINDOW_MANAGER_DRAWN_COMPLETE);
300 }
301 };
302 final ShowListener mKeyguardDelegateCallback = new ShowListener() {
303 @Override
304 public void onShown(IBinder windowToken) {
305 if (DEBUG_WAKEUP) Slog.d(TAG, "mKeyguardDelegate.ShowListener.onShown.");
306 mHandler.sendEmptyMessage(MSG_KEYGUARD_DRAWN_COMPLETE);
307 }
308 };
309
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800310 GlobalActions mGlobalActions;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800311 Handler mHandler;
satok1bc0a492012-04-25 22:47:12 +0900312 WindowState mLastInputMethodWindow = null;
313 WindowState mLastInputMethodTargetWindow = null;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800314
Jeff Brown13f00f02014-10-31 14:45:50 -0700315 // FIXME This state is shared between the input reader and handler thread.
316 // Technically it's broken and buggy but it has been like this for many years
317 // and we have not yet seen any problems. Someday we'll rewrite this logic
318 // so that only one thread is involved in handling input policy. Unfortunately
319 // it's on a critical path for power management so we can't just post the work to the
320 // handler thread. We'll need to resolve this someday by teaching the input dispatcher
321 // to hold wakelocks during dispatch and eliminating the critical path.
322 volatile boolean mPowerKeyHandled;
Bryce Leed9268e32014-11-17 17:40:59 -0800323 volatile boolean mBeganFromNonInteractive;
Jeff Brown13f00f02014-10-31 14:45:50 -0700324 volatile int mPowerKeyPressCounter;
325 volatile boolean mEndCallKeyHandled;
326
Winson Chungd42a6cf2014-06-03 16:24:04 -0700327 boolean mRecentsVisible;
Winson Chung1e8d71b2014-05-16 17:05:22 -0700328 int mRecentAppsHeldModifiers;
Jeff Browncf39bdf2012-05-18 14:41:19 -0700329 boolean mLanguageSwitchKeyPressed;
Jeff Brown68b909d2011-12-07 16:36:01 -0800330
Jeff Brown2e7760e2012-04-11 15:14:55 -0700331 int mLidState = LID_ABSENT;
Michael Wright3818c922014-09-02 13:59:07 -0700332 int mCameraLensCoverState = CAMERA_LENS_COVER_ABSENT;
Jeff Browndaa37532012-05-01 15:54:03 -0700333 boolean mHaveBuiltInKeyboard;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800334
Dianne Hackbornc777e072010-02-12 13:07:59 -0800335 boolean mSystemReady;
Dianne Hackbornba24e4d2011-09-01 11:17:06 -0700336 boolean mSystemBooted;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800337 boolean mHdmiPlugged;
Jeff Brown4f5fa282014-06-12 19:19:15 -0700338 IUiModeManager mUiModeManager;
Daniel Sandler6396c722013-04-16 20:19:09 -0400339 int mUiMode;
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700340 int mDockMode = Intent.EXTRA_DOCK_STATE_UNDOCKED;
Mike Lockwood1753f7f2009-08-24 14:49:07 -0700341 int mLidOpenRotation;
Mike Lockwood2d1efbd2009-09-16 12:15:53 -0400342 int mCarDockRotation;
343 int mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -0700344 int mUndockedHdmiRotation;
345 int mDemoHdmiRotation;
346 boolean mDemoHdmiRotationLock;
Chong Zhangae6119ff2014-11-11 18:54:39 -0800347 int mDemoRotation;
348 boolean mDemoRotationLock;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400349
Jeff Browna20dda42014-05-27 20:57:24 -0700350 boolean mWakeGestureEnabledSetting;
351 MyWakeGestureListener mWakeGestureListener;
352
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700353 // Default display does not rotate, apps that require non-default orientation will have to
354 // have the orientation emulated.
355 private boolean mForceDefaultOrientation = false;
356
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400357 int mUserRotationMode = WindowManagerPolicy.USER_ROTATION_FREE;
358 int mUserRotation = Surface.ROTATION_0;
Jeff Brown207673cd2012-06-05 17:47:11 -0700359 boolean mAccelerometerDefault;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400360
Jeff Brownbcdfc622014-03-06 19:13:04 -0800361 boolean mSupportAutoRotation;
Jeff Brownd3187e32011-09-21 19:26:44 -0700362 int mAllowAllRotations = -1;
Mike Lockwoode9867d22009-09-20 01:59:02 -0400363 boolean mCarDockEnablesAccelerometer;
364 boolean mDeskDockEnablesAccelerometer;
Dianne Hackborn2862fff2009-09-15 22:56:29 -0700365 int mLidKeyboardAccessibility;
366 int mLidNavigationAccessibility;
Jeff Brownc458ce92012-04-30 14:58:40 -0700367 boolean mLidControlsSleep;
Jeff Brown13f00f02014-10-31 14:45:50 -0700368 int mShortPressOnPowerBehavior;
369 int mLongPressOnPowerBehavior;
370 int mDoublePressOnPowerBehavior;
371 int mTriplePressOnPowerBehavior;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700372 boolean mAwake;
373 boolean mScreenOnEarly;
374 boolean mScreenOnFully;
375 ScreenOnListener mScreenOnListener;
376 boolean mKeyguardDrawComplete;
377 boolean mWindowManagerDrawComplete;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800378 boolean mOrientationSensorEnabled = false;
379 int mCurrentAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800380 boolean mHasSoftInput = false;
Daniel Sandlerdd73ee42013-10-11 22:19:59 -0400381 boolean mTranslucentDecorEnabled = true;
RoboErik001c59c2015-01-26 15:53:51 -0800382 boolean mUseTvRouting;
Craig Mautner967212c2013-04-13 21:10:58 -0700383
Jeff Brown70825162012-03-28 17:27:48 -0700384 int mPointerLocationMode = 0; // guarded by mLock
Joe Onorato664644d2011-01-23 17:53:23 -0800385
386 // The last window we were told about in focusChanged.
387 WindowState mFocusedWindow;
Dianne Hackborne0f085d2011-11-30 18:41:15 -0800388 IApplicationToken mFocusedApp;
Joe Onorato664644d2011-01-23 17:53:23 -0800389
Jeff Brown70825162012-03-28 17:27:48 -0700390 PointerLocationView mPointerLocationView;
Jeff Brown32cbc38552011-12-01 14:01:49 -0800391
Dianne Hackbornc652de82013-02-15 16:32:56 -0800392 // The current size of the screen; really; extends into the overscan area of
393 // the screen and doesn't account for any system elements like the status bar.
394 int mOverscanScreenLeft, mOverscanScreenTop;
395 int mOverscanScreenWidth, mOverscanScreenHeight;
396 // The current visible size of the screen; really; (ir)regardless of whether the status
397 // bar can be hidden but not extending into the overscan area.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800398 int mUnrestrictedScreenLeft, mUnrestrictedScreenTop;
399 int mUnrestrictedScreenWidth, mUnrestrictedScreenHeight;
Dianne Hackborn313440842013-02-19 19:22:59 -0800400 // Like mOverscanScreen*, but allowed to move into the overscan region where appropriate.
401 int mRestrictedOverscanScreenLeft, mRestrictedOverscanScreenTop;
402 int mRestrictedOverscanScreenWidth, mRestrictedOverscanScreenHeight;
Dianne Hackborn82de1ae2010-10-28 11:28:39 -0700403 // The current size of the screen; these may be different than (0,0)-(dw,dh)
404 // if the status bar can't be hidden; in that case it effectively carves out
405 // that area of the display from all other windows.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800406 int mRestrictedScreenLeft, mRestrictedScreenTop;
407 int mRestrictedScreenWidth, mRestrictedScreenHeight;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700408 // During layout, the current screen borders accounting for any currently
409 // visible system UI elements.
410 int mSystemLeft, mSystemTop, mSystemRight, mSystemBottom;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700411 // For applications requesting stable content insets, these are them.
412 int mStableLeft, mStableTop, mStableRight, mStableBottom;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -0700413 // For applications requesting stable content insets but have also set the
414 // fullscreen window flag, these are the stable dimensions without the status bar.
415 int mStableFullscreenLeft, mStableFullscreenTop;
416 int mStableFullscreenRight, mStableFullscreenBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800417 // During layout, the current screen borders with all outer decoration
418 // (status bar, input method dock) accounted for.
419 int mCurLeft, mCurTop, mCurRight, mCurBottom;
420 // During layout, the frame in which content should be displayed
421 // to the user, accounting for all screen decoration except for any
422 // space they deem as available for other content. This is usually
423 // the same as mCur*, but may be larger if the screen decor has supplied
424 // content insets.
425 int mContentLeft, mContentTop, mContentRight, mContentBottom;
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700426 // During layout, the frame in which voice content should be displayed
427 // to the user, accounting for all screen decoration except for any
428 // space they deem as available for other content.
429 int mVoiceContentLeft, mVoiceContentTop, mVoiceContentRight, mVoiceContentBottom;
Dianne Hackborn8e11ef02010-11-18 19:47:42 -0800430 // During layout, the current screen borders along which input method
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800431 // windows are placed.
432 int mDockLeft, mDockTop, mDockRight, mDockBottom;
433 // During layout, the layer at which the doc window is placed.
434 int mDockLayer;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700435 // During layout, this is the layer of the status bar.
436 int mStatusBarLayer;
Dianne Hackborne26ab702011-10-16 13:21:33 -0700437 int mLastSystemUiFlags;
438 // Bits that we are in the process of clearing, so we want to prevent
439 // them from being set by applications until everything has been updated
440 // to have them clear.
441 int mResettingSystemUiFlags = 0;
442 // Bits that we are currently always keeping cleared.
443 int mForceClearedSystemUiFlags = 0;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -0800444 // What we last reported to system UI about whether the compatibility
445 // menu needs to be displayed.
446 boolean mLastFocusNeedsMenu = false;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700447
448 FakeWindow mHideNavFakeWindow = null;
449
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800450 static final Rect mTmpParentFrame = new Rect();
451 static final Rect mTmpDisplayFrame = new Rect();
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800452 static final Rect mTmpOverscanFrame = new Rect();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800453 static final Rect mTmpContentFrame = new Rect();
454 static final Rect mTmpVisibleFrame = new Rect();
John Spurlock46646232013-09-30 22:32:42 -0400455 static final Rect mTmpDecorFrame = new Rect();
Adrian Roosfa104232014-06-20 16:10:14 -0700456 static final Rect mTmpStableFrame = new Rect();
Dianne Hackborn1f903c32011-09-13 19:18:06 -0700457 static final Rect mTmpNavigationFrame = new Rect();
Craig Mautner967212c2013-04-13 21:10:58 -0700458
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800459 WindowState mTopFullscreenOpaqueWindowState;
Adrian Rooscd3884d2015-02-18 17:25:23 +0100460 WindowState mTopFullscreenOpaqueOrDimmingWindowState;
Craig Mautner2bc789b2014-03-19 19:48:38 -0700461 HashSet<IApplicationToken> mAppsToBeHidden = new HashSet<IApplicationToken>();
Jorim Jaggic13fcac2014-09-11 17:36:57 +0200462 HashSet<IApplicationToken> mAppsThatDismissKeyguard = new HashSet<IApplicationToken>();
Joe Onorato93056472010-09-10 10:30:46 -0400463 boolean mTopIsFullscreen;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800464 boolean mForceStatusBar;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -0700465 boolean mForceStatusBarFromKeyguard;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700466 boolean mHideLockScreen;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -0800467 boolean mForcingShowNavBar;
468 int mForcingShowNavBarLayer;
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700469
470 // States of keyguard dismiss.
471 private static final int DISMISS_KEYGUARD_NONE = 0; // Keyguard not being dismissed.
472 private static final int DISMISS_KEYGUARD_START = 1; // Keyguard needs to be dismissed.
473 private static final int DISMISS_KEYGUARD_CONTINUE = 2; // Keyguard has been dismissed.
474 int mDismissKeyguard = DISMISS_KEYGUARD_NONE;
475
476 /** The window that is currently dismissing the keyguard. Dismissing the keyguard must only
477 * be done once per window. */
478 private WindowState mWinDismissingKeyguard;
479
Craig Mautnerc9457fa2014-06-06 14:27:48 -0700480 /** The window that is currently showing "over" the keyguard. If there is an app window
481 * belonging to another app on top of this the keyguard shows. If there is a fullscreen
482 * app window under this, still dismiss the keyguard but don't show the app underneath. Show
483 * the wallpaper. */
484 private WindowState mWinShowWhenLocked;
485
Dianne Hackborn7ad44382012-10-18 17:46:00 -0700486 boolean mShowingLockscreen;
487 boolean mShowingDream;
488 boolean mDreamingLockscreen;
Jim Millerab954542014-10-10 18:21:49 -0700489 boolean mKeyguardSecure;
490 boolean mKeyguardSecureIncludingHidden;
491 volatile boolean mKeyguardOccluded;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800492 boolean mHomePressed;
Jeff Browncaca8812013-05-09 13:34:33 -0700493 boolean mHomeConsumed;
494 boolean mHomeDoubleTapPending;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800495 Intent mHomeIntent;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700496 Intent mCarDockIntent;
497 Intent mDeskDockIntent;
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700498 boolean mSearchKeyShortcutPending;
499 boolean mConsumeSearchKeyUp;
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700500 boolean mAssistKeyLongPressed;
Michael Wright6a62e552014-06-03 19:19:48 -0700501 boolean mPendingMetaAction;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800502
Mike Lockwood28569302010-01-28 11:54:40 -0500503 // support for activating the lock screen while the screen is on
504 boolean mAllowLockscreenWhenOn;
505 int mLockScreenTimeout;
506 boolean mLockScreenTimerActive;
507
David Brownbaf8d092010-03-08 21:52:59 -0800508 // Behavior of ENDCALL Button. (See Settings.System.END_BUTTON_BEHAVIOR.)
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800509 int mEndcallBehavior;
David Brownbaf8d092010-03-08 21:52:59 -0800510
511 // Behavior of POWER button while in-call and screen on.
512 // (See Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR.)
513 int mIncallPowerBehavior;
514
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700515 Display mDisplay;
516
Dianne Hackborn9d132642011-04-21 17:26:39 -0700517 int mLandscapeRotation = 0; // default landscape rotation
518 int mSeascapeRotation = 0; // "other" landscape rotation, 180 degrees from mLandscapeRotation
519 int mPortraitRotation = 0; // default portrait rotation
520 int mUpsideDownRotation = 0; // "other" portrait rotation
Mitsuru Oshima831d0d92009-06-16 18:27:18 -0700521
Dianne Hackbornc652de82013-02-15 16:32:56 -0800522 int mOverscanLeft = 0;
523 int mOverscanTop = 0;
524 int mOverscanRight = 0;
525 int mOverscanBottom = 0;
526
Joe Onorato46b0d682010-11-22 17:37:27 -0800527 // What we do when the user long presses on home
Jeff Browncaca8812013-05-09 13:34:33 -0700528 private int mLongPressOnHomeBehavior;
529
530 // What we do when the user double-taps on home
531 private int mDoubleTapOnHomeBehavior;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800532
Bryce Lee584a4452014-10-21 15:55:55 -0700533 // Allowed theater mode wake actions
534 private boolean mAllowTheaterModeWakeFromKey;
535 private boolean mAllowTheaterModeWakeFromPowerKey;
536 private boolean mAllowTheaterModeWakeFromMotion;
Bryce Lee812d7022014-11-10 13:33:28 -0800537 private boolean mAllowTheaterModeWakeFromMotionWhenNotDreaming;
Bryce Lee584a4452014-10-21 15:55:55 -0700538 private boolean mAllowTheaterModeWakeFromCameraLens;
539 private boolean mAllowTheaterModeWakeFromLidSwitch;
540 private boolean mAllowTheaterModeWakeFromWakeGesture;
541
Bryce Lee55e846d2014-11-04 12:43:44 -0800542 // Whether to go to sleep entering theater mode from power button
543 private boolean mGoToSleepOnButtonPressTheaterMode;
544
Winson Chung9112ec32011-06-27 13:15:32 -0700545 // Screenshot trigger states
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700546 // Time to volume and power must be pressed within this interval of each other.
547 private static final long SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS = 150;
Winson Chung1cea2f32012-10-08 20:42:01 -0700548 // Increase the chord delay when taking a screenshot from the keyguard
549 private static final float KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER = 2.5f;
Christopher Tatee90585f2012-03-05 18:56:25 -0800550 private boolean mScreenshotChordEnabled;
Jeff Brown13f00f02014-10-31 14:45:50 -0700551 private boolean mScreenshotChordVolumeDownKeyTriggered;
552 private long mScreenshotChordVolumeDownKeyTime;
553 private boolean mScreenshotChordVolumeDownKeyConsumed;
554 private boolean mScreenshotChordVolumeUpKeyTriggered;
555 private boolean mScreenshotChordPowerKeyTriggered;
556 private long mScreenshotChordPowerKeyTime;
Winson Chung9112ec32011-06-27 13:15:32 -0700557
Michael Wrightb854e242013-02-05 17:54:02 -0800558 /* The number of steps between min and max brightness */
559 private static final int BRIGHTNESS_STEPS = 10;
560
Christopher Tate5e08af02012-09-21 17:17:22 -0700561 SettingsObserver mSettingsObserver;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800562 ShortcutManager mShortcutManager;
563 PowerManager.WakeLock mBroadcastWakeLock;
Jeff Brown13f00f02014-10-31 14:45:50 -0700564 PowerManager.WakeLock mPowerKeyWakeLock;
Jeff Brown40013652012-05-16 21:22:36 -0700565 boolean mHavePendingMediaKeyRepeatWithWakeLock;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800566
Craig Mautnerd625ab22013-09-06 13:40:31 -0700567 private int mCurrentUserId;
568
Justin Kohd378ad72013-04-01 12:18:26 -0700569 // Maps global key codes to the components that will handle them.
570 private GlobalKeyManager mGlobalKeyManager;
571
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700572 // Fallback actions by key code.
573 private final SparseArray<KeyCharacterMap.FallbackAction> mFallbackActions =
574 new SparseArray<KeyCharacterMap.FallbackAction>();
Jeff Brown49ed71d2010-12-06 17:13:33 -0800575
Jorim Jaggi76a16232014-08-08 17:00:47 +0200576 private final LogDecelerateInterpolator mLogDecelerateInterpolator
577 = new LogDecelerateInterpolator(100, 0);
578
Jeff Brown70825162012-03-28 17:27:48 -0700579 private static final int MSG_ENABLE_POINTER_LOCATION = 1;
580 private static final int MSG_DISABLE_POINTER_LOCATION = 2;
Jeff Brown40013652012-05-16 21:22:36 -0700581 private static final int MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK = 3;
582 private static final int MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK = 4;
Craig Mautner8a0da012014-05-31 15:13:37 -0700583 private static final int MSG_KEYGUARD_DRAWN_COMPLETE = 5;
584 private static final int MSG_KEYGUARD_DRAWN_TIMEOUT = 6;
585 private static final int MSG_WINDOW_MANAGER_DRAWN_COMPLETE = 7;
Craig Mautner84984fa2014-06-19 11:19:20 -0700586 private static final int MSG_DISPATCH_SHOW_RECENTS = 9;
Alan Viverettee34560b22014-07-10 14:50:06 -0700587 private static final int MSG_DISPATCH_SHOW_GLOBAL_ACTIONS = 10;
Craig Mautnera631d492014-08-05 15:16:01 -0700588 private static final int MSG_HIDE_BOOT_MESSAGE = 11;
Michael Wright869a67c2014-08-26 19:33:06 -0700589 private static final int MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK = 12;
Jeff Brown13f00f02014-10-31 14:45:50 -0700590 private static final int MSG_POWER_DELAYED_PRESS = 13;
591 private static final int MSG_POWER_LONG_PRESS = 14;
Jeff Brown70825162012-03-28 17:27:48 -0700592
593 private class PolicyHandler extends Handler {
594 @Override
595 public void handleMessage(Message msg) {
596 switch (msg.what) {
597 case MSG_ENABLE_POINTER_LOCATION:
598 enablePointerLocation();
599 break;
600 case MSG_DISABLE_POINTER_LOCATION:
601 disablePointerLocation();
602 break;
Jeff Brown40013652012-05-16 21:22:36 -0700603 case MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK:
604 dispatchMediaKeyWithWakeLock((KeyEvent)msg.obj);
605 break;
606 case MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK:
607 dispatchMediaKeyRepeatWithWakeLock((KeyEvent)msg.obj);
608 break;
Craig Mautner84984fa2014-06-19 11:19:20 -0700609 case MSG_DISPATCH_SHOW_RECENTS:
610 showRecentApps(false);
611 break;
Alan Viverettee34560b22014-07-10 14:50:06 -0700612 case MSG_DISPATCH_SHOW_GLOBAL_ACTIONS:
613 showGlobalActionsInternal();
614 break;
Craig Mautner8a0da012014-05-31 15:13:37 -0700615 case MSG_KEYGUARD_DRAWN_COMPLETE:
616 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mKeyguardDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700617 finishKeyguardDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700618 break;
619 case MSG_KEYGUARD_DRAWN_TIMEOUT:
620 Slog.w(TAG, "Keyguard drawn timeout. Setting mKeyguardDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700621 finishKeyguardDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700622 break;
623 case MSG_WINDOW_MANAGER_DRAWN_COMPLETE:
624 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mWindowManagerDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700625 finishWindowsDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700626 break;
Craig Mautnera631d492014-08-05 15:16:01 -0700627 case MSG_HIDE_BOOT_MESSAGE:
628 handleHideBootMessage();
629 break;
Michael Wright869a67c2014-08-26 19:33:06 -0700630 case MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK:
631 launchVoiceAssistWithWakeLock(msg.arg1 != 0);
632 break;
Jeff Brown13f00f02014-10-31 14:45:50 -0700633 case MSG_POWER_DELAYED_PRESS:
634 powerPress((Long)msg.obj, msg.arg1 != 0, msg.arg2);
635 finishPowerKeyPress();
636 break;
637 case MSG_POWER_LONG_PRESS:
638 powerLongPress();
639 break;
Jeff Brown70825162012-03-28 17:27:48 -0700640 }
641 }
642 }
643
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800644 private UEventObserver mHDMIObserver = new UEventObserver() {
645 @Override
646 public void onUEvent(UEventObserver.UEvent event) {
647 setHdmiPlugged("1".equals(event.get("SWITCH_STATE")));
648 }
649 };
650
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800651 class SettingsObserver extends ContentObserver {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800652 SettingsObserver(Handler handler) {
653 super(handler);
654 }
David Brownbaf8d092010-03-08 21:52:59 -0800655
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800656 void observe() {
Christopher Tate5e08af02012-09-21 17:17:22 -0700657 // Observe all users' changes
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800658 ContentResolver resolver = mContext.getContentResolver();
659 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700660 Settings.System.END_BUTTON_BEHAVIOR), false, this,
661 UserHandle.USER_ALL);
David Brownbaf8d092010-03-08 21:52:59 -0800662 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700663 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR), false, this,
664 UserHandle.USER_ALL);
Jeff Browna20dda42014-05-27 20:57:24 -0700665 resolver.registerContentObserver(Settings.Secure.getUriFor(
666 Settings.Secure.WAKE_GESTURE_ENABLED), false, this,
667 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800668 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700669 Settings.System.ACCELEROMETER_ROTATION), false, this,
670 UserHandle.USER_ALL);
Mike Lockwood28569302010-01-28 11:54:40 -0500671 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700672 Settings.System.USER_ROTATION), false, this,
673 UserHandle.USER_ALL);
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400674 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700675 Settings.System.SCREEN_OFF_TIMEOUT), false, this,
676 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800677 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700678 Settings.System.POINTER_LOCATION), false, this,
679 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800680 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700681 Settings.Secure.DEFAULT_INPUT_METHOD), false, this,
682 UserHandle.USER_ALL);
John Spurlockd9b70bd2014-02-06 17:02:44 -0500683 resolver.registerContentObserver(Settings.Secure.getUriFor(
John Spurlockf1a36642013-10-12 17:50:42 -0400684 Settings.Secure.IMMERSIVE_MODE_CONFIRMATIONS), false, this,
Christopher Tate5e08af02012-09-21 17:17:22 -0700685 UserHandle.USER_ALL);
John Spurlockc6d1c602014-01-17 15:22:06 -0500686 resolver.registerContentObserver(Settings.Global.getUriFor(
687 Settings.Global.POLICY_CONTROL), false, this,
688 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800689 updateSettings();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800690 }
691
692 @Override public void onChange(boolean selfChange) {
Dianne Hackbornc777e072010-02-12 13:07:59 -0800693 updateSettings();
Jeff Brown01a98dd2011-09-20 15:08:29 -0700694 updateRotation(false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800695 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800696 }
Craig Mautner967212c2013-04-13 21:10:58 -0700697
Jeff Browna20dda42014-05-27 20:57:24 -0700698 class MyWakeGestureListener extends WakeGestureListener {
699 MyWakeGestureListener(Context context, Handler handler) {
700 super(context, handler);
701 }
702
703 @Override
704 public void onWakeUp() {
705 synchronized (mLock) {
706 if (shouldEnableWakeGestureLp()) {
Jeff Browne07b94b2014-06-18 15:56:27 -0700707 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
Bryce Lee584a4452014-10-21 15:55:55 -0700708 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromWakeGesture);
Jeff Browna20dda42014-05-27 20:57:24 -0700709 }
710 }
711 }
712 }
713
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800714 class MyOrientationListener extends WindowOrientationListener {
Craig Mautnereee29c42013-01-17 14:44:34 -0800715 MyOrientationListener(Context context, Handler handler) {
716 super(context, handler);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800717 }
Craig Mautner967212c2013-04-13 21:10:58 -0700718
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800719 @Override
Jeff Brownc0347aa2011-09-23 17:26:09 -0700720 public void onProposedRotationChanged(int rotation) {
Craig Mautnereda67292013-04-28 13:50:14 -0700721 if (localLOGV) Slog.v(TAG, "onProposedRotationChanged, rotation=" + rotation);
Jeff Brown01a98dd2011-09-20 15:08:29 -0700722 updateRotation(false);
723 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800724 }
725 MyOrientationListener mOrientationListener;
726
Jorim Jaggi24bec7c2015-02-04 12:40:14 +0100727 private final StatusBarController mStatusBarController = new StatusBarController();
John Spurlock5b9145b2013-08-20 15:13:47 -0400728
John Spurlock27735a42013-08-14 17:57:38 -0400729 private final BarController mNavigationBarController = new BarController("NavigationBar",
John Spurlock5b9145b2013-08-20 15:13:47 -0400730 View.NAVIGATION_BAR_TRANSIENT,
731 View.NAVIGATION_BAR_UNHIDE,
John Spurlockbd957402013-10-03 11:38:39 -0400732 View.NAVIGATION_BAR_TRANSLUCENT,
733 StatusBarManager.WINDOW_NAVIGATION_BAR,
734 WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
John Spurlock5b9145b2013-08-20 15:13:47 -0400735
John Spurlockf1a36642013-10-12 17:50:42 -0400736 private ImmersiveModeConfirmation mImmersiveModeConfirmation;
John Spurlock32beb2c2013-03-11 10:16:47 -0400737
Craig Mautner037aa8d2013-06-07 10:35:44 -0700738 private SystemGesturesPointerEventListener mSystemGestures;
John Spurlock32beb2c2013-03-11 10:16:47 -0400739
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700740 IStatusBarService getStatusBarService() {
741 synchronized (mServiceAquireLock) {
742 if (mStatusBarService == null) {
743 mStatusBarService = IStatusBarService.Stub.asInterface(
744 ServiceManager.getService("statusbar"));
745 }
746 return mStatusBarService;
747 }
748 }
749
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700750 /*
751 * We always let the sensor be switched on by default except when
752 * the user has explicitly disabled sensor based rotation or when the
753 * screen is switched off.
754 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700755 boolean needSensorRunningLp() {
Jeff Brownbcdfc622014-03-06 19:13:04 -0800756 if (mSupportAutoRotation) {
757 if (mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
758 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
759 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT
760 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) {
761 // If the application has explicitly requested to follow the
762 // orientation, then we need to turn the sensor on.
763 return true;
764 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800765 }
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700766 if ((mCarDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_CAR) ||
Jeff Brown1a693182011-11-08 14:44:16 -0800767 (mDeskDockEnablesAccelerometer && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
768 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
769 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK))) {
Mike Lockwoode9867d22009-09-20 01:59:02 -0400770 // enable accelerometer if we are docked in a dock that enables accelerometer
771 // orientation management,
772 return true;
773 }
Jeff Brown207673cd2012-06-05 17:47:11 -0700774 if (mUserRotationMode == USER_ROTATION_LOCKED) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800775 // If the setting for using the sensor by default is enabled, then
776 // we will always leave it on. Note that the user could go to
777 // a window that forces an orientation that does not use the
778 // sensor and in theory we could turn it off... however, when next
779 // turning it on we won't have a good value for the current
780 // orientation for a little bit, which can cause orientation
781 // changes to lag, so we'd like to keep it always on. (It will
782 // still be turned off when the screen is off.)
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700783 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800784 }
Jeff Brownbcdfc622014-03-06 19:13:04 -0800785 return mSupportAutoRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800786 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700787
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800788 /*
789 * Various use cases for invoking this function
790 * screen turning off, should always disable listeners if already enabled
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700791 * screen turned on and current app has sensor based orientation, enable listeners
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800792 * if not already enabled
793 * screen turned on and current app does not have sensor orientation, disable listeners if
794 * already enabled
795 * screen turning on and current app has sensor based orientation, enable listeners if needed
796 * screen turning on and current app has nosensor based orientation, do nothing
797 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700798 void updateOrientationListenerLp() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800799 if (!mOrientationListener.canDetectOrientation()) {
800 // If sensor is turned off or nonexistent for some reason
801 return;
802 }
803 //Could have been invoked due to screen turning on or off or
804 //change of the currently visible window's orientation
Jeff Brown3ee549c2014-09-22 20:14:39 -0700805 if (localLOGV) Slog.v(TAG, "mScreenOnEarly=" + mScreenOnEarly
806 + ", mAwake=" + mAwake + ", mCurrentAppOrientation=" + mCurrentAppOrientation
807 + ", mOrientationSensorEnabled=" + mOrientationSensorEnabled);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800808 boolean disable = true;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700809 if (mScreenOnEarly && mAwake) {
The Android Open Source Project0727d222009-03-11 12:11:58 -0700810 if (needSensorRunningLp()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800811 disable = false;
812 //enable listener if not already enabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700813 if (!mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800814 mOrientationListener.enable();
Craig Mautnereda67292013-04-28 13:50:14 -0700815 if(localLOGV) Slog.v(TAG, "Enabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800816 mOrientationSensorEnabled = true;
817 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700818 }
819 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800820 //check if sensors need to be disabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700821 if (disable && mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800822 mOrientationListener.disable();
Craig Mautnereda67292013-04-28 13:50:14 -0700823 if(localLOGV) Slog.v(TAG, "Disabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800824 mOrientationSensorEnabled = false;
825 }
826 }
827
Jeff Brown13f00f02014-10-31 14:45:50 -0700828 private void interceptPowerKeyDown(KeyEvent event, boolean interactive) {
829 // Hold a wake lock until the power key is released.
830 if (!mPowerKeyWakeLock.isHeld()) {
831 mPowerKeyWakeLock.acquire();
832 }
833
834 // Cancel multi-press detection timeout.
835 if (mPowerKeyPressCounter != 0) {
836 mHandler.removeMessages(MSG_POWER_DELAYED_PRESS);
837 }
838
839 // Detect user pressing the power button in panic when an application has
840 // taken over the whole screen.
841 boolean panic = mImmersiveModeConfirmation.onPowerKeyDown(interactive,
Craig Mautner0124980e92014-11-30 21:15:34 -0800842 SystemClock.elapsedRealtime(), isImmersiveMode(mLastSystemUiFlags));
Jeff Brown13f00f02014-10-31 14:45:50 -0700843 if (panic) {
844 mHandler.post(mRequestTransientNav);
845 }
846
847 // Latch power key state to detect screenshot chord.
848 if (interactive && !mScreenshotChordPowerKeyTriggered
849 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
850 mScreenshotChordPowerKeyTriggered = true;
851 mScreenshotChordPowerKeyTime = event.getDownTime();
852 interceptScreenshotChord();
853 }
854
855 // Stop ringing or end call if configured to do so when power is pressed.
856 TelecomManager telecomManager = getTelecommService();
857 boolean hungUp = false;
858 if (telecomManager != null) {
859 if (telecomManager.isRinging()) {
860 // Pressing Power while there's a ringing incoming
861 // call should silence the ringer.
862 telecomManager.silenceRinger();
863 } else if ((mIncallPowerBehavior
864 & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0
865 && telecomManager.isInCall() && interactive) {
866 // Otherwise, if "Power button ends call" is enabled,
867 // the Power button will hang up any current active call.
868 hungUp = telecomManager.endCall();
869 }
870 }
871
872 // If the power key has still not yet been handled, then detect short
873 // press, long press, or multi press and decide what to do.
874 mPowerKeyHandled = hungUp || mScreenshotChordVolumeDownKeyTriggered
875 || mScreenshotChordVolumeUpKeyTriggered;
876 if (!mPowerKeyHandled) {
877 if (interactive) {
878 // When interactive, we're already awake.
879 // Wait for a long press or for the button to be released to decide what to do.
880 if (hasLongPressOnPowerBehavior()) {
881 Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS);
882 msg.setAsynchronous(true);
883 mHandler.sendMessageDelayed(msg,
884 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
885 }
886 } else {
Bryce Leed9268e32014-11-17 17:40:59 -0800887 wakeUpFromPowerKey(event.getDownTime());
Jeff Brown13f00f02014-10-31 14:45:50 -0700888 final int maxCount = getMaxMultiPressPowerCount();
Bryce Leed9268e32014-11-17 17:40:59 -0800889
Jeff Brown13f00f02014-10-31 14:45:50 -0700890 if (maxCount <= 1) {
Jeff Brown13f00f02014-10-31 14:45:50 -0700891 mPowerKeyHandled = true;
Bryce Leed9268e32014-11-17 17:40:59 -0800892 } else {
893 mBeganFromNonInteractive = true;
Jeff Brown13f00f02014-10-31 14:45:50 -0700894 }
895 }
Jeff Brown4d396052010-10-29 21:50:21 -0700896 }
897 }
898
Jeff Brown13f00f02014-10-31 14:45:50 -0700899 private void interceptPowerKeyUp(KeyEvent event, boolean interactive, boolean canceled) {
900 final boolean handled = canceled || mPowerKeyHandled;
901 mScreenshotChordPowerKeyTriggered = false;
902 cancelPendingScreenshotChordAction();
903 cancelPendingPowerKeyAction();
904
905 if (!handled) {
906 // Figure out how to handle the key now that it has been released.
907 mPowerKeyPressCounter += 1;
908
909 final int maxCount = getMaxMultiPressPowerCount();
910 final long eventTime = event.getDownTime();
911 if (mPowerKeyPressCounter < maxCount) {
912 // This could be a multi-press. Wait a little bit longer to confirm.
913 // Continue holding the wake lock.
914 Message msg = mHandler.obtainMessage(MSG_POWER_DELAYED_PRESS,
915 interactive ? 1 : 0, mPowerKeyPressCounter, eventTime);
916 msg.setAsynchronous(true);
917 mHandler.sendMessageDelayed(msg, ViewConfiguration.getDoubleTapTimeout());
918 return;
919 }
920
921 // No other actions. Handle it immediately.
922 powerPress(eventTime, interactive, mPowerKeyPressCounter);
Jeff Brown4d396052010-10-29 21:50:21 -0700923 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700924
925 // Done. Reset our state.
926 finishPowerKeyPress();
927 }
928
929 private void finishPowerKeyPress() {
Bryce Leed9268e32014-11-17 17:40:59 -0800930 mBeganFromNonInteractive = false;
Jeff Brown13f00f02014-10-31 14:45:50 -0700931 mPowerKeyPressCounter = 0;
932 if (mPowerKeyWakeLock.isHeld()) {
933 mPowerKeyWakeLock.release();
934 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700935 }
936
937 private void cancelPendingPowerKeyAction() {
938 if (!mPowerKeyHandled) {
Jeff Brown13f00f02014-10-31 14:45:50 -0700939 mPowerKeyHandled = true;
940 mHandler.removeMessages(MSG_POWER_LONG_PRESS);
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700941 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700942 }
943
944 private void powerPress(long eventTime, boolean interactive, int count) {
945 if (mScreenOnEarly && !mScreenOnFully) {
946 Slog.i(TAG, "Suppressed redundant power key press while "
947 + "already in the process of turning the screen on.");
948 return;
Jeff Brownff204712011-10-25 21:27:54 -0700949 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700950
951 if (count == 2) {
952 powerMultiPressAction(eventTime, interactive, mDoublePressOnPowerBehavior);
953 } else if (count == 3) {
954 powerMultiPressAction(eventTime, interactive, mTriplePressOnPowerBehavior);
Bryce Leed9268e32014-11-17 17:40:59 -0800955 } else if (interactive && !mBeganFromNonInteractive) {
Jeff Brown13f00f02014-10-31 14:45:50 -0700956 switch (mShortPressOnPowerBehavior) {
957 case SHORT_PRESS_POWER_NOTHING:
958 break;
959 case SHORT_PRESS_POWER_GO_TO_SLEEP:
960 mPowerManager.goToSleep(eventTime,
961 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
962 break;
963 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP:
964 mPowerManager.goToSleep(eventTime,
965 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
966 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
967 break;
968 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME:
969 mPowerManager.goToSleep(eventTime,
970 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
971 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
972 launchHomeFromHotKey();
973 break;
Bryce Lee01b0c5f2015-02-05 18:24:04 -0800974 case SHORT_PRESS_POWER_GO_HOME:
975 launchHomeFromHotKey();
976 break;
Jeff Brown13f00f02014-10-31 14:45:50 -0700977 }
978 }
979 }
980
981 private void powerMultiPressAction(long eventTime, boolean interactive, int behavior) {
982 switch (behavior) {
983 case MULTI_PRESS_POWER_NOTHING:
984 break;
985 case MULTI_PRESS_POWER_THEATER_MODE:
986 if (isTheaterModeEnabled()) {
987 Slog.i(TAG, "Toggling theater mode off.");
988 Settings.Global.putInt(mContext.getContentResolver(),
989 Settings.Global.THEATER_MODE_ON, 0);
990 if (!interactive) {
991 wakeUpFromPowerKey(eventTime);
992 }
993 } else {
994 Slog.i(TAG, "Toggling theater mode on.");
995 Settings.Global.putInt(mContext.getContentResolver(),
996 Settings.Global.THEATER_MODE_ON, 1);
Bryce Lee55e846d2014-11-04 12:43:44 -0800997
998 if (mGoToSleepOnButtonPressTheaterMode && interactive) {
Jeff Brown13f00f02014-10-31 14:45:50 -0700999 mPowerManager.goToSleep(eventTime,
1000 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
1001 }
1002 }
1003 break;
1004 case MULTI_PRESS_POWER_BRIGHTNESS_BOOST:
Jeff Brown7b5be5e2014-11-12 18:45:31 -08001005 Slog.i(TAG, "Starting brightness boost.");
1006 if (!interactive) {
1007 wakeUpFromPowerKey(eventTime);
1008 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001009 mPowerManager.boostScreenBrightness(eventTime);
1010 break;
1011 }
1012 }
1013
1014 private int getMaxMultiPressPowerCount() {
1015 if (mTriplePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) {
1016 return 3;
1017 }
1018 if (mDoublePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) {
1019 return 2;
1020 }
1021 return 1;
1022 }
1023
1024 private void powerLongPress() {
1025 final int behavior = getResolvedLongPressOnPowerBehavior();
1026 switch (behavior) {
1027 case LONG_PRESS_POWER_NOTHING:
1028 break;
1029 case LONG_PRESS_POWER_GLOBAL_ACTIONS:
1030 mPowerKeyHandled = true;
1031 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
1032 performAuditoryFeedbackForAccessibilityIfNeed();
1033 }
1034 showGlobalActionsInternal();
1035 break;
1036 case LONG_PRESS_POWER_SHUT_OFF:
1037 case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM:
1038 mPowerKeyHandled = true;
1039 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
1040 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
1041 mWindowManagerFuncs.shutdown(behavior == LONG_PRESS_POWER_SHUT_OFF);
1042 break;
1043 }
1044 }
1045
1046 private int getResolvedLongPressOnPowerBehavior() {
1047 if (FactoryTest.isLongPressOnPowerOffEnabled()) {
1048 return LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM;
1049 }
1050 return mLongPressOnPowerBehavior;
1051 }
1052
1053 private boolean hasLongPressOnPowerBehavior() {
1054 return getResolvedLongPressOnPowerBehavior() != LONG_PRESS_POWER_NOTHING;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001055 }
1056
1057 private void interceptScreenshotChord() {
Christopher Tatee90585f2012-03-05 18:56:25 -08001058 if (mScreenshotChordEnabled
Jeff Brown13f00f02014-10-31 14:45:50 -07001059 && mScreenshotChordVolumeDownKeyTriggered && mScreenshotChordPowerKeyTriggered
1060 && !mScreenshotChordVolumeUpKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001061 final long now = SystemClock.uptimeMillis();
Jeff Brown13f00f02014-10-31 14:45:50 -07001062 if (now <= mScreenshotChordVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS
1063 && now <= mScreenshotChordPowerKeyTime
1064 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) {
1065 mScreenshotChordVolumeDownKeyConsumed = true;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001066 cancelPendingPowerKeyAction();
1067
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001068 mHandler.postDelayed(mScreenshotRunnable, getScreenshotChordLongPressDelay());
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001069 }
1070 }
1071 }
1072
Winson Chung1cea2f32012-10-08 20:42:01 -07001073 private long getScreenshotChordLongPressDelay() {
Jim Miller5ecd8112013-01-09 18:50:26 -08001074 if (mKeyguardDelegate.isShowing()) {
Winson Chung1cea2f32012-10-08 20:42:01 -07001075 // Double the time it takes to take a screenshot from the keyguard
1076 return (long) (KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER *
Justin Kohfeabd2c2014-05-02 10:02:44 -07001077 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Winson Chung1cea2f32012-10-08 20:42:01 -07001078 }
Justin Kohfeabd2c2014-05-02 10:02:44 -07001079 return ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout();
Winson Chung1cea2f32012-10-08 20:42:01 -07001080 }
1081
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001082 private void cancelPendingScreenshotChordAction() {
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001083 mHandler.removeCallbacks(mScreenshotRunnable);
Jeff Brown4d396052010-10-29 21:50:21 -07001084 }
1085
Jeff Brown13f00f02014-10-31 14:45:50 -07001086 private final Runnable mEndCallLongPress = new Runnable() {
Craig Mautnerf1b67412012-09-19 13:18:29 -07001087 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001088 public void run() {
Jeff Brown13f00f02014-10-31 14:45:50 -07001089 mEndCallKeyHandled = true;
1090 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
1091 performAuditoryFeedbackForAccessibilityIfNeed();
Joe Onoratod208e702010-10-08 16:22:43 -04001092 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001093 showGlobalActionsInternal();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001094 }
1095 };
1096
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001097 private final Runnable mScreenshotRunnable = new Runnable() {
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001098 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001099 public void run() {
1100 takeScreenshot();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001101 }
1102 };
1103
Alan Viverettee34560b22014-07-10 14:50:06 -07001104 @Override
1105 public void showGlobalActions() {
1106 mHandler.removeMessages(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
1107 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
1108 }
1109
1110 void showGlobalActionsInternal() {
1111 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001112 if (mGlobalActions == null) {
Jeff Brown7304c342012-05-11 18:42:42 -07001113 mGlobalActions = new GlobalActions(mContext, mWindowManagerFuncs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001114 }
Jim Millerab954542014-10-10 18:21:49 -07001115 final boolean keyguardShowing = isKeyguardShowingAndNotOccluded();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001116 mGlobalActions.showDialog(keyguardShowing, isDeviceProvisioned());
1117 if (keyguardShowing) {
1118 // since it took two seconds of long press to bring this up,
1119 // poke the wake lock so they have some time to see the dialog.
Jim Miller25190572013-02-28 17:36:24 -08001120 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001121 }
1122 }
1123
1124 boolean isDeviceProvisioned() {
Jeff Brownbf6f6f92012-09-25 15:03:20 -07001125 return Settings.Global.getInt(
1126 mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001127 }
1128
Maurice Lam99c6e072014-04-28 18:24:28 -07001129 boolean isUserSetupComplete() {
1130 return Settings.Secure.getIntForUser(mContext.getContentResolver(),
1131 Settings.Secure.USER_SETUP_COMPLETE, 0, UserHandle.USER_CURRENT) != 0;
1132 }
1133
Jeff Brown13f00f02014-10-31 14:45:50 -07001134 private void handleShortPressOnHome() {
1135 // If there's a dream running then use home to escape the dream
1136 // but don't actually go home.
1137 if (mDreamManagerInternal != null && mDreamManagerInternal.isDreaming()) {
1138 mDreamManagerInternal.stopDream(false /*immediate*/);
1139 return;
1140 }
1141
1142 // Go home!
1143 launchHomeFromHotKey();
1144 }
1145
Patrick Dubroyece94522011-02-23 18:35:01 -08001146 private void handleLongPressOnHome() {
Joe Onorato46b0d682010-11-22 17:37:27 -08001147 if (mLongPressOnHomeBehavior != LONG_PRESS_HOME_NOTHING) {
Jeff Browncaca8812013-05-09 13:34:33 -07001148 mHomeConsumed = true;
Joe Onorato46b0d682010-11-22 17:37:27 -08001149 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
Patrick Dubroyece94522011-02-23 18:35:01 -08001150
Jeff Browncaca8812013-05-09 13:34:33 -07001151 if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI) {
1152 toggleRecentApps();
1153 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_ASSIST) {
1154 launchAssistAction();
Jim Millere6ad1a82010-08-20 19:25:39 -07001155 }
1156 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001157 }
Patrick Dubroyece94522011-02-23 18:35:01 -08001158
Jeff Browncaca8812013-05-09 13:34:33 -07001159 private void handleDoubleTapOnHome() {
1160 if (mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1161 mHomeConsumed = true;
1162 toggleRecentApps();
1163 }
1164 }
1165
1166 private final Runnable mHomeDoubleTapTimeoutRunnable = new Runnable() {
1167 @Override
1168 public void run() {
1169 if (mHomeDoubleTapPending) {
1170 mHomeDoubleTapPending = false;
Jeff Brown13f00f02014-10-31 14:45:50 -07001171 handleShortPressOnHome();
Jeff Browncaca8812013-05-09 13:34:33 -07001172 }
1173 }
1174 };
1175
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001176 /** {@inheritDoc} */
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001177 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001178 public void init(Context context, IWindowManager windowManager,
Jeff Brown96307042012-07-27 15:51:34 -07001179 WindowManagerFuncs windowManagerFuncs) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001180 mContext = context;
1181 mWindowManager = windowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -07001182 mWindowManagerFuncs = windowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -07001183 mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class);
Jose Lima9546b202014-07-02 17:21:51 -07001184 mDreamManagerInternal = LocalServices.getService(DreamManagerInternal.class);
Filip Gruszczynskicfb31852015-02-25 21:47:12 +00001185 if (context.getResources().getBoolean(
1186 com.android.internal.R.bool.config_enableBurnInProtection)){
1187 mBurnInProtectionHelper = new BurnInProtectionHelper(context);
1188 }
Craig Mautner8a0da012014-05-31 15:13:37 -07001189
Jeff Brown70825162012-03-28 17:27:48 -07001190 mHandler = new PolicyHandler();
Jeff Browna20dda42014-05-27 20:57:24 -07001191 mWakeGestureListener = new MyWakeGestureListener(mContext, mHandler);
Craig Mautnereee29c42013-01-17 14:44:34 -08001192 mOrientationListener = new MyOrientationListener(mContext, mHandler);
Jeff Brownc0347aa2011-09-23 17:26:09 -07001193 try {
1194 mOrientationListener.setCurrentRotation(windowManager.getRotation());
1195 } catch (RemoteException ex) { }
Christopher Tate5e08af02012-09-21 17:17:22 -07001196 mSettingsObserver = new SettingsObserver(mHandler);
1197 mSettingsObserver.observe();
Svetoslav683914b2015-01-15 14:22:26 -08001198 mShortcutManager = new ShortcutManager(context);
Daniel Sandler6396c722013-04-16 20:19:09 -04001199 mUiMode = context.getResources().getInteger(
1200 com.android.internal.R.integer.config_defaultUiModeType);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001201 mHomeIntent = new Intent(Intent.ACTION_MAIN, null);
1202 mHomeIntent.addCategory(Intent.CATEGORY_HOME);
1203 mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1204 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07001205 mCarDockIntent = new Intent(Intent.ACTION_MAIN, null);
1206 mCarDockIntent.addCategory(Intent.CATEGORY_CAR_DOCK);
1207 mCarDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1208 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
1209 mDeskDockIntent = new Intent(Intent.ACTION_MAIN, null);
1210 mDeskDockIntent.addCategory(Intent.CATEGORY_DESK_DOCK);
1211 mDeskDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1212 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Jim Millere6ad1a82010-08-20 19:25:39 -07001213
Jeff Brown96307042012-07-27 15:51:34 -07001214 mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
1215 mBroadcastWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001216 "PhoneWindowManager.mBroadcastWakeLock");
Jeff Brown13f00f02014-10-31 14:45:50 -07001217 mPowerKeyWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
1218 "PhoneWindowManager.mPowerKeyWakeLock");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001219 mEnableShiftMenuBugReports = "1".equals(SystemProperties.get("ro.debuggable"));
Jeff Brownbcdfc622014-03-06 19:13:04 -08001220 mSupportAutoRotation = mContext.getResources().getBoolean(
1221 com.android.internal.R.bool.config_supportAutoRotation);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001222 mLidOpenRotation = readRotation(
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001223 com.android.internal.R.integer.config_lidOpenRotation);
1224 mCarDockRotation = readRotation(
1225 com.android.internal.R.integer.config_carDockRotation);
1226 mDeskDockRotation = readRotation(
1227 com.android.internal.R.integer.config_deskDockRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001228 mUndockedHdmiRotation = readRotation(
1229 com.android.internal.R.integer.config_undockedHdmiRotation);
Mike Lockwoode9867d22009-09-20 01:59:02 -04001230 mCarDockEnablesAccelerometer = mContext.getResources().getBoolean(
1231 com.android.internal.R.bool.config_carDockEnablesAccelerometer);
1232 mDeskDockEnablesAccelerometer = mContext.getResources().getBoolean(
1233 com.android.internal.R.bool.config_deskDockEnablesAccelerometer);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001234 mLidKeyboardAccessibility = mContext.getResources().getInteger(
1235 com.android.internal.R.integer.config_lidKeyboardAccessibility);
1236 mLidNavigationAccessibility = mContext.getResources().getInteger(
1237 com.android.internal.R.integer.config_lidNavigationAccessibility);
Jeff Brownc458ce92012-04-30 14:58:40 -07001238 mLidControlsSleep = mContext.getResources().getBoolean(
1239 com.android.internal.R.bool.config_lidControlsSleep);
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04001240 mTranslucentDecorEnabled = mContext.getResources().getBoolean(
1241 com.android.internal.R.bool.config_enableTranslucentDecor);
Bryce Lee584a4452014-10-21 15:55:55 -07001242
1243 mAllowTheaterModeWakeFromKey = mContext.getResources().getBoolean(
1244 com.android.internal.R.bool.config_allowTheaterModeWakeFromKey);
1245 mAllowTheaterModeWakeFromPowerKey = mAllowTheaterModeWakeFromKey
1246 || mContext.getResources().getBoolean(
1247 com.android.internal.R.bool.config_allowTheaterModeWakeFromPowerKey);
1248 mAllowTheaterModeWakeFromMotion = mContext.getResources().getBoolean(
1249 com.android.internal.R.bool.config_allowTheaterModeWakeFromMotion);
Bryce Lee812d7022014-11-10 13:33:28 -08001250 mAllowTheaterModeWakeFromMotionWhenNotDreaming = mContext.getResources().getBoolean(
1251 com.android.internal.R.bool.config_allowTheaterModeWakeFromMotionWhenNotDreaming);
Bryce Lee584a4452014-10-21 15:55:55 -07001252 mAllowTheaterModeWakeFromCameraLens = mContext.getResources().getBoolean(
1253 com.android.internal.R.bool.config_allowTheaterModeWakeFromCameraLens);
1254 mAllowTheaterModeWakeFromLidSwitch = mContext.getResources().getBoolean(
1255 com.android.internal.R.bool.config_allowTheaterModeWakeFromLidSwitch);
1256 mAllowTheaterModeWakeFromWakeGesture = mContext.getResources().getBoolean(
1257 com.android.internal.R.bool.config_allowTheaterModeWakeFromGesture);
1258
Bryce Lee55e846d2014-11-04 12:43:44 -08001259 mGoToSleepOnButtonPressTheaterMode = mContext.getResources().getBoolean(
1260 com.android.internal.R.bool.config_goToSleepOnButtonPressTheaterMode);
1261
Jeff Brown13f00f02014-10-31 14:45:50 -07001262 mShortPressOnPowerBehavior = mContext.getResources().getInteger(
1263 com.android.internal.R.integer.config_shortPressOnPowerBehavior);
1264 mLongPressOnPowerBehavior = mContext.getResources().getInteger(
1265 com.android.internal.R.integer.config_longPressOnPowerBehavior);
1266 mDoublePressOnPowerBehavior = mContext.getResources().getInteger(
1267 com.android.internal.R.integer.config_doublePressOnPowerBehavior);
1268 mTriplePressOnPowerBehavior = mContext.getResources().getInteger(
1269 com.android.internal.R.integer.config_triplePressOnPowerBehavior);
1270
John Spurlock61560172015-02-06 19:46:04 -05001271 mUseTvRouting = AudioSystem.getPlatformType(mContext) == AudioSystem.PLATFORM_TELEVISION;
RoboErik001c59c2015-01-26 15:53:51 -08001272
Jeff Brownf71343d2013-05-31 17:59:11 -07001273 readConfigurationDependentBehaviors();
Jeff Browncaca8812013-05-09 13:34:33 -07001274
Svetoslav8e3feb12014-02-24 13:46:47 -08001275 mAccessibilityManager = (AccessibilityManager) context.getSystemService(
1276 Context.ACCESSIBILITY_SERVICE);
1277
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001278 // register for dock events
Dianne Hackborn78968392010-03-04 20:47:56 -08001279 IntentFilter filter = new IntentFilter();
1280 filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE);
1281 filter.addAction(UiModeManager.ACTION_EXIT_CAR_MODE);
1282 filter.addAction(UiModeManager.ACTION_ENTER_DESK_MODE);
1283 filter.addAction(UiModeManager.ACTION_EXIT_DESK_MODE);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001284 filter.addAction(Intent.ACTION_DOCK_EVENT);
1285 Intent intent = context.registerReceiver(mDockReceiver, filter);
1286 if (intent != null) {
1287 // Retrieve current sticky dock event broadcast.
1288 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
1289 Intent.EXTRA_DOCK_STATE_UNDOCKED);
1290 }
Daniel Sandler7e37df52011-11-16 22:08:23 -08001291
Jeff Brown6aaf2952012-10-05 16:01:08 -07001292 // register for dream-related broadcasts
1293 filter = new IntentFilter();
1294 filter.addAction(Intent.ACTION_DREAMING_STARTED);
1295 filter.addAction(Intent.ACTION_DREAMING_STOPPED);
1296 context.registerReceiver(mDreamReceiver, filter);
1297
Christopher Tate5e08af02012-09-21 17:17:22 -07001298 // register for multiuser-relevant broadcasts
1299 filter = new IntentFilter(Intent.ACTION_USER_SWITCHED);
1300 context.registerReceiver(mMultiuserReceiver, filter);
1301
John Spurlock57306e62013-04-22 09:48:49 -04001302 // monitor for system gestures
Craig Mautner037aa8d2013-06-07 10:35:44 -07001303 mSystemGestures = new SystemGesturesPointerEventListener(context,
1304 new SystemGesturesPointerEventListener.Callbacks() {
John Spurlock57306e62013-04-22 09:48:49 -04001305 @Override
1306 public void onSwipeFromTop() {
John Spurlock04db1762013-05-13 12:46:41 -04001307 if (mStatusBar != null) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001308 requestTransientBars(mStatusBar);
John Spurlock04db1762013-05-13 12:46:41 -04001309 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04001310 }
1311 @Override
1312 public void onSwipeFromBottom() {
John Spurlock04db1762013-05-13 12:46:41 -04001313 if (mNavigationBar != null && mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001314 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001315 }
1316 }
1317 @Override
1318 public void onSwipeFromRight() {
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 onDebug() {
John Spurlockd67ec252013-09-05 11:31:54 -04001325 // no-op
John Spurlockad3e6cb2013-04-30 08:47:43 -04001326 }
1327 });
John Spurlockf1a36642013-10-12 17:50:42 -04001328 mImmersiveModeConfirmation = new ImmersiveModeConfirmation(mContext);
Craig Mautner037aa8d2013-06-07 10:35:44 -07001329 mWindowManagerFuncs.registerPointerEventListener(mSystemGestures);
John Spurlock32beb2c2013-03-11 10:16:47 -04001330
Jeff Brownc2346132012-04-13 01:55:38 -07001331 mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001332 mLongPressVibePattern = getLongIntArray(mContext.getResources(),
1333 com.android.internal.R.array.config_longPressVibePattern);
1334 mVirtualKeyVibePattern = getLongIntArray(mContext.getResources(),
1335 com.android.internal.R.array.config_virtualKeyVibePattern);
Amith Yamasanic33cb712010-02-10 15:21:49 -08001336 mKeyboardTapVibePattern = getLongIntArray(mContext.getResources(),
1337 com.android.internal.R.array.config_keyboardTapVibePattern);
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07001338 mClockTickVibePattern = getLongIntArray(mContext.getResources(),
1339 com.android.internal.R.array.config_clockTickVibePattern);
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07001340 mCalendarDateVibePattern = getLongIntArray(mContext.getResources(),
1341 com.android.internal.R.array.config_calendarDateVibePattern);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001342 mSafeModeDisabledVibePattern = getLongIntArray(mContext.getResources(),
1343 com.android.internal.R.array.config_safeModeDisabledVibePattern);
1344 mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(),
1345 com.android.internal.R.array.config_safeModeEnabledVibePattern);
Daniel Sandler40427442010-07-16 11:44:52 -04001346
Christopher Tatee90585f2012-03-05 18:56:25 -08001347 mScreenshotChordEnabled = mContext.getResources().getBoolean(
1348 com.android.internal.R.bool.config_enableScreenshotChord);
1349
Justin Kohd378ad72013-04-01 12:18:26 -07001350 mGlobalKeyManager = new GlobalKeyManager(mContext);
1351
Joe Onoratoea495d42011-04-06 11:41:11 -07001352 // Controls rotation and the like.
1353 initializeHdmiState();
Dianne Hackborn40011092011-09-22 13:37:48 -07001354
1355 // Match current screen state.
Craig Mautnera631d492014-08-05 15:16:01 -07001356 if (!mPowerManager.isInteractive()) {
Jeff Brown140ffc72014-05-01 15:18:00 -07001357 goingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
Dianne Hackborn40011092011-09-22 13:37:48 -07001358 }
Jorim Jaggi24bec7c2015-02-04 12:40:14 +01001359
1360 mWindowManagerInternal.registerAppTransitionListener(
1361 mStatusBarController.getAppTransitionListener());
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001362 }
1363
Jeff Brownf71343d2013-05-31 17:59:11 -07001364 /**
1365 * Read values from config.xml that may be overridden depending on
1366 * the configuration of the device.
1367 * eg. Disable long press on home goes to recents on sw600dp.
1368 */
1369 private void readConfigurationDependentBehaviors() {
1370 mLongPressOnHomeBehavior = mContext.getResources().getInteger(
1371 com.android.internal.R.integer.config_longPressOnHomeBehavior);
1372 if (mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING ||
1373 mLongPressOnHomeBehavior > LONG_PRESS_HOME_ASSIST) {
1374 mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1375 }
1376
1377 mDoubleTapOnHomeBehavior = mContext.getResources().getInteger(
1378 com.android.internal.R.integer.config_doubleTapOnHomeBehavior);
1379 if (mDoubleTapOnHomeBehavior < DOUBLE_TAP_HOME_NOTHING ||
1380 mDoubleTapOnHomeBehavior > DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1381 mDoubleTapOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1382 }
1383 }
1384
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001385 @Override
Dianne Hackborndde331c2012-08-03 14:01:57 -07001386 public void setInitialDisplaySize(Display display, int width, int height, int density) {
Jeff Brownef981a42013-08-07 14:13:37 -07001387 // This method might be called before the policy has been fully initialized
1388 // or for other displays we don't care about.
1389 if (mContext == null || display.getDisplayId() != Display.DEFAULT_DISPLAY) {
1390 return;
Dianne Hackbornc652de82013-02-15 16:32:56 -08001391 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001392 mDisplay = display;
1393
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001394 final Resources res = mContext.getResources();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001395 int shortSize, longSize;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001396 if (width > height) {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001397 shortSize = height;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001398 longSize = width;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001399 mLandscapeRotation = Surface.ROTATION_0;
1400 mSeascapeRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001401 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001402 mPortraitRotation = Surface.ROTATION_90;
1403 mUpsideDownRotation = Surface.ROTATION_270;
1404 } else {
1405 mPortraitRotation = Surface.ROTATION_270;
1406 mUpsideDownRotation = Surface.ROTATION_90;
1407 }
1408 } else {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001409 shortSize = width;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001410 longSize = height;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001411 mPortraitRotation = Surface.ROTATION_0;
1412 mUpsideDownRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001413 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001414 mLandscapeRotation = Surface.ROTATION_270;
1415 mSeascapeRotation = Surface.ROTATION_90;
1416 } else {
1417 mLandscapeRotation = Surface.ROTATION_90;
1418 mSeascapeRotation = Surface.ROTATION_270;
1419 }
1420 }
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001421
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001422 mStatusBarHeight =
1423 res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001424
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001425 // Height of the navigation bar when presented horizontally at bottom
1426 mNavigationBarHeightForRotation[mPortraitRotation] =
1427 mNavigationBarHeightForRotation[mUpsideDownRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001428 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_height);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001429 mNavigationBarHeightForRotation[mLandscapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001430 mNavigationBarHeightForRotation[mSeascapeRotation] = res.getDimensionPixelSize(
1431 com.android.internal.R.dimen.navigation_bar_height_landscape);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001432
1433 // Width of the navigation bar when presented vertically along one side
1434 mNavigationBarWidthForRotation[mPortraitRotation] =
1435 mNavigationBarWidthForRotation[mUpsideDownRotation] =
1436 mNavigationBarWidthForRotation[mLandscapeRotation] =
1437 mNavigationBarWidthForRotation[mSeascapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001438 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_width);
Daniel Sandler4a066c52012-04-20 14:49:13 -04001439
1440 // SystemUI (status bar) layout policy
Dianne Hackborndde331c2012-08-03 14:01:57 -07001441 int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / density;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001442 int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / density;
Daniel Sandler4a066c52012-04-20 14:49:13 -04001443
Devin Kimd7b12b42014-05-05 14:34:58 -07001444 // Allow the navigation bar to move on non-square small devices (phones).
1445 mNavigationBarCanMove = width != height && shortSizeDp < 600;
Daniel Sandler36412a72011-08-04 09:35:13 -04001446
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001447 mHasNavigationBar = res.getBoolean(com.android.internal.R.bool.config_showNavigationBar);
John Spurlock80f00c12013-06-13 11:10:51 -04001448 // Allow a system property to override this. Used by the emulator.
1449 // See also hasNavigationBar().
1450 String navBarOverride = SystemProperties.get("qemu.hw.mainkeys");
1451 if ("1".equals(navBarOverride)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001452 mHasNavigationBar = false;
John Spurlock80f00c12013-06-13 11:10:51 -04001453 } else if ("0".equals(navBarOverride)) {
1454 mHasNavigationBar = true;
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04001455 }
1456
Jeff Brown27f1d672012-10-17 18:32:34 -07001457 // For demo purposes, allow the rotation of the HDMI display to be controlled.
1458 // By default, HDMI locks rotation to landscape.
Erik Gilling9a41ef82011-09-26 19:21:03 -07001459 if ("portrait".equals(SystemProperties.get("persist.demo.hdmirotation"))) {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001460 mDemoHdmiRotation = mPortraitRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001461 } else {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001462 mDemoHdmiRotation = mLandscapeRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001463 }
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001464 mDemoHdmiRotationLock = SystemProperties.getBoolean("persist.demo.hdmirotationlock", false);
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001465
Chong Zhangae6119ff2014-11-11 18:54:39 -08001466 // For demo purposes, allow the rotation of the remote display to be controlled.
1467 // By default, remote display locks rotation to landscape.
1468 if ("portrait".equals(SystemProperties.get("persist.demo.remoterotation"))) {
1469 mDemoRotation = mPortraitRotation;
1470 } else {
1471 mDemoRotation = mLandscapeRotation;
1472 }
1473 mDemoRotationLock = SystemProperties.getBoolean(
1474 "persist.demo.rotationlock", false);
1475
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001476 // Only force the default orientation if the screen is xlarge, at least 960dp x 720dp, per
1477 // http://developer.android.com/guide/practices/screens_support.html#range
1478 mForceDefaultOrientation = longSizeDp >= 960 && shortSizeDp >= 720 &&
1479 res.getBoolean(com.android.internal.R.bool.config_forceDefaultOrientation) &&
1480 // For debug purposes the next line turns this feature off with:
1481 // $ adb shell setprop config.override_forced_orient true
1482 // $ adb shell wm size reset
1483 !"true".equals(SystemProperties.get("config.override_forced_orient"));
1484 }
1485
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001486 /**
1487 * @return whether the navigation bar can be hidden, e.g. the device has a
1488 * navigation bar and touch exploration is not enabled
1489 */
1490 private boolean canHideNavigationBar() {
Svetoslav8e3feb12014-02-24 13:46:47 -08001491 return mHasNavigationBar
1492 && !mAccessibilityManager.isTouchExplorationEnabled();
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001493 }
1494
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001495 @Override
1496 public boolean isDefaultOrientationForced() {
1497 return mForceDefaultOrientation;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001498 }
1499
Dianne Hackbornc652de82013-02-15 16:32:56 -08001500 @Override
1501 public void setDisplayOverscan(Display display, int left, int top, int right, int bottom) {
1502 if (display.getDisplayId() == Display.DEFAULT_DISPLAY) {
1503 mOverscanLeft = left;
1504 mOverscanTop = top;
1505 mOverscanRight = right;
1506 mOverscanBottom = bottom;
1507 }
1508 }
1509
Dianne Hackbornc777e072010-02-12 13:07:59 -08001510 public void updateSettings() {
1511 ContentResolver resolver = mContext.getContentResolver();
1512 boolean updateRotation = false;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001513 synchronized (mLock) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001514 mEndcallBehavior = Settings.System.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001515 Settings.System.END_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001516 Settings.System.END_BUTTON_BEHAVIOR_DEFAULT,
1517 UserHandle.USER_CURRENT);
1518 mIncallPowerBehavior = Settings.Secure.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001519 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001520 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT,
1521 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001522
Jeff Browna20dda42014-05-27 20:57:24 -07001523 // Configure wake gesture.
1524 boolean wakeGestureEnabledSetting = Settings.Secure.getIntForUser(resolver,
1525 Settings.Secure.WAKE_GESTURE_ENABLED, 0,
1526 UserHandle.USER_CURRENT) != 0;
1527 if (mWakeGestureEnabledSetting != wakeGestureEnabledSetting) {
1528 mWakeGestureEnabledSetting = wakeGestureEnabledSetting;
1529 updateWakeGestureListenerLp();
1530 }
1531
Jeff Brown207673cd2012-06-05 17:47:11 -07001532 // Configure rotation lock.
Christopher Tate5e08af02012-09-21 17:17:22 -07001533 int userRotation = Settings.System.getIntForUser(resolver,
1534 Settings.System.USER_ROTATION, Surface.ROTATION_0,
1535 UserHandle.USER_CURRENT);
Jeff Brown207673cd2012-06-05 17:47:11 -07001536 if (mUserRotation != userRotation) {
1537 mUserRotation = userRotation;
1538 updateRotation = true;
1539 }
Christopher Tate5e08af02012-09-21 17:17:22 -07001540 int userRotationMode = Settings.System.getIntForUser(resolver,
1541 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
Jeff Brown207673cd2012-06-05 17:47:11 -07001542 WindowManagerPolicy.USER_ROTATION_FREE :
1543 WindowManagerPolicy.USER_ROTATION_LOCKED;
1544 if (mUserRotationMode != userRotationMode) {
1545 mUserRotationMode = userRotationMode;
1546 updateRotation = true;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001547 updateOrientationListenerLp();
1548 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001549
Dianne Hackbornc777e072010-02-12 13:07:59 -08001550 if (mSystemReady) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001551 int pointerLocation = Settings.System.getIntForUser(resolver,
1552 Settings.System.POINTER_LOCATION, 0, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001553 if (mPointerLocationMode != pointerLocation) {
1554 mPointerLocationMode = pointerLocation;
Jeff Brown70825162012-03-28 17:27:48 -07001555 mHandler.sendEmptyMessage(pointerLocation != 0 ?
1556 MSG_ENABLE_POINTER_LOCATION : MSG_DISABLE_POINTER_LOCATION);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001557 }
1558 }
1559 // use screen off timeout setting as the timeout for the lockscreen
Christopher Tate5e08af02012-09-21 17:17:22 -07001560 mLockScreenTimeout = Settings.System.getIntForUser(resolver,
1561 Settings.System.SCREEN_OFF_TIMEOUT, 0, UserHandle.USER_CURRENT);
1562 String imId = Settings.Secure.getStringForUser(resolver,
1563 Settings.Secure.DEFAULT_INPUT_METHOD, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001564 boolean hasSoftInput = imId != null && imId.length() > 0;
1565 if (mHasSoftInput != hasSoftInput) {
1566 mHasSoftInput = hasSoftInput;
1567 updateRotation = true;
1568 }
John Spurlockf1a36642013-10-12 17:50:42 -04001569 if (mImmersiveModeConfirmation != null) {
John Spurlock4355a532014-02-19 09:49:25 -05001570 mImmersiveModeConfirmation.loadSetting(mCurrentUserId);
John Spurlockd67ec252013-09-05 11:31:54 -04001571 }
John Spurlockc6d1c602014-01-17 15:22:06 -05001572 PolicyControl.reloadFromSetting(mContext);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001573 }
1574 if (updateRotation) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07001575 updateRotation(true);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001576 }
Jeff Brown70825162012-03-28 17:27:48 -07001577 }
1578
Jeff Browna20dda42014-05-27 20:57:24 -07001579 private void updateWakeGestureListenerLp() {
1580 if (shouldEnableWakeGestureLp()) {
1581 mWakeGestureListener.requestWakeUpTrigger();
1582 } else {
1583 mWakeGestureListener.cancelWakeUpTrigger();
1584 }
1585 }
1586
1587 private boolean shouldEnableWakeGestureLp() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07001588 return mWakeGestureEnabledSetting && !mAwake
Jeff Browna20dda42014-05-27 20:57:24 -07001589 && (!mLidControlsSleep || mLidState != LID_CLOSED)
1590 && mWakeGestureListener.isSupported();
1591 }
1592
Jeff Brown70825162012-03-28 17:27:48 -07001593 private void enablePointerLocation() {
1594 if (mPointerLocationView == null) {
1595 mPointerLocationView = new PointerLocationView(mContext);
1596 mPointerLocationView.setPrintCoords(false);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001597 WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
1598 WindowManager.LayoutParams.MATCH_PARENT,
1599 WindowManager.LayoutParams.MATCH_PARENT);
Jeff Brown3b2b3542010-10-15 00:54:27 -07001600 lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001601 lp.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN
1602 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
1603 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1604 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
Jeff Brown90fc9052012-10-01 14:44:24 -07001605 if (ActivityManager.isHighEndGfx()) {
1606 lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
1607 lp.privateFlags |=
1608 WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED;
1609 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001610 lp.format = PixelFormat.TRANSLUCENT;
1611 lp.setTitle("PointerLocation");
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001612 WindowManager wm = (WindowManager)
Dianne Hackbornc777e072010-02-12 13:07:59 -08001613 mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Browncc4f7db2011-08-30 20:34:48 -07001614 lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL;
Jeff Brown70825162012-03-28 17:27:48 -07001615 wm.addView(mPointerLocationView, lp);
Michael Wrightc9c487e2013-11-07 18:55:09 -08001616 mWindowManagerFuncs.registerPointerEventListener(mPointerLocationView);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001617 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001618 }
Jeff Brown70825162012-03-28 17:27:48 -07001619
1620 private void disablePointerLocation() {
Jeff Brown70825162012-03-28 17:27:48 -07001621 if (mPointerLocationView != null) {
Michael Wrightc9c487e2013-11-07 18:55:09 -08001622 mWindowManagerFuncs.unregisterPointerEventListener(mPointerLocationView);
1623 WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Brown70825162012-03-28 17:27:48 -07001624 wm.removeView(mPointerLocationView);
1625 mPointerLocationView = null;
1626 }
1627 }
1628
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001629 private int readRotation(int resID) {
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001630 try {
1631 int rotation = mContext.getResources().getInteger(resID);
1632 switch (rotation) {
1633 case 0:
1634 return Surface.ROTATION_0;
1635 case 90:
1636 return Surface.ROTATION_90;
1637 case 180:
1638 return Surface.ROTATION_180;
1639 case 270:
1640 return Surface.ROTATION_270;
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001641 }
1642 } catch (Resources.NotFoundException e) {
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001643 // fall through
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001644 }
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001645 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001646 }
1647
1648 /** {@inheritDoc} */
Craig Mautner88400d32012-09-30 12:35:45 -07001649 @Override
Dianne Hackbornc2293022013-02-06 23:14:49 -08001650 public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001651 int type = attrs.type;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001652
1653 outAppOp[0] = AppOpsManager.OP_NONE;
1654
Wale Ogunwale74bf0652015-01-12 10:24:36 -08001655 if (!((type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW)
1656 || (type >= FIRST_SUB_WINDOW && type <= LAST_SUB_WINDOW)
1657 || (type >= FIRST_SYSTEM_WINDOW && type <= LAST_SYSTEM_WINDOW))) {
1658 return WindowManagerGlobal.ADD_INVALID_TYPE;
1659 }
1660
1661 if (type < FIRST_SYSTEM_WINDOW || type > LAST_SYSTEM_WINDOW) {
1662 // Window manager will make sure these are okay.
Jeff Brown98365d72012-08-19 20:30:52 -07001663 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001664 }
1665 String permission = null;
1666 switch (type) {
1667 case TYPE_TOAST:
1668 // XXX right now the app process has complete control over
1669 // this... should introduce a token to let the system
1670 // monitor/control what they are doing.
Jason Monk1c7c3192014-06-26 12:52:18 -04001671 outAppOp[0] = AppOpsManager.OP_TOAST_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001672 break;
Daniel Sandler7d276c32012-01-30 14:33:52 -05001673 case TYPE_DREAM:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001674 case TYPE_INPUT_METHOD:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001675 case TYPE_WALLPAPER:
keunyounga446bf02013-06-21 19:07:57 -07001676 case TYPE_PRIVATE_PRESENTATION:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001677 case TYPE_VOICE_INTERACTION:
Svetoslav3a5c7212014-10-14 09:54:26 -07001678 case TYPE_ACCESSIBILITY_OVERLAY:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001679 // The window manager will check these.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001680 break;
1681 case TYPE_PHONE:
1682 case TYPE_PRIORITY_PHONE:
1683 case TYPE_SYSTEM_ALERT:
1684 case TYPE_SYSTEM_ERROR:
1685 case TYPE_SYSTEM_OVERLAY:
1686 permission = android.Manifest.permission.SYSTEM_ALERT_WINDOW;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001687 outAppOp[0] = AppOpsManager.OP_SYSTEM_ALERT_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001688 break;
1689 default:
1690 permission = android.Manifest.permission.INTERNAL_SYSTEM_WINDOW;
1691 }
1692 if (permission != null) {
1693 if (mContext.checkCallingOrSelfPermission(permission)
1694 != PackageManager.PERMISSION_GRANTED) {
Jeff Brown98365d72012-08-19 20:30:52 -07001695 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001696 }
1697 }
Jeff Brown98365d72012-08-19 20:30:52 -07001698 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001699 }
Craig Mautner88400d32012-09-30 12:35:45 -07001700
1701 @Override
1702 public boolean checkShowToOwnerOnly(WindowManager.LayoutParams attrs) {
1703
1704 // If this switch statement is modified, modify the comment in the declarations of
1705 // the type in {@link WindowManager.LayoutParams} as well.
1706 switch (attrs.type) {
1707 default:
1708 // These are the windows that by default are shown only to the user that created
1709 // them. If this needs to be overridden, set
1710 // {@link WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS} in
1711 // {@link WindowManager.LayoutParams}. Note that permission
1712 // {@link android.Manifest.permission.INTERNAL_SYSTEM_WINDOW} is required as well.
1713 if ((attrs.privateFlags & PRIVATE_FLAG_SHOW_FOR_ALL_USERS) == 0) {
1714 return true;
1715 }
1716 break;
1717
1718 // These are the windows that by default are shown to all users. However, to
1719 // protect against spoofing, check permissions below.
1720 case TYPE_APPLICATION_STARTING:
1721 case TYPE_BOOT_PROGRESS:
1722 case TYPE_DISPLAY_OVERLAY:
1723 case TYPE_HIDDEN_NAV_CONSUMER:
Jim Miller5ecd8112013-01-09 18:50:26 -08001724 case TYPE_KEYGUARD_SCRIM:
Craig Mautner88400d32012-09-30 12:35:45 -07001725 case TYPE_KEYGUARD_DIALOG:
1726 case TYPE_MAGNIFICATION_OVERLAY:
1727 case TYPE_NAVIGATION_BAR:
1728 case TYPE_NAVIGATION_BAR_PANEL:
1729 case TYPE_PHONE:
1730 case TYPE_POINTER:
1731 case TYPE_PRIORITY_PHONE:
Craig Mautner88400d32012-09-30 12:35:45 -07001732 case TYPE_SEARCH_BAR:
1733 case TYPE_STATUS_BAR:
1734 case TYPE_STATUS_BAR_PANEL:
1735 case TYPE_STATUS_BAR_SUB_PANEL:
1736 case TYPE_SYSTEM_DIALOG:
Craig Mautner88400d32012-09-30 12:35:45 -07001737 case TYPE_VOLUME_OVERLAY:
keunyounga446bf02013-06-21 19:07:57 -07001738 case TYPE_PRIVATE_PRESENTATION:
Craig Mautner88400d32012-09-30 12:35:45 -07001739 break;
1740 }
1741
1742 // Check if third party app has set window to system window type.
1743 return mContext.checkCallingOrSelfPermission(
1744 android.Manifest.permission.INTERNAL_SYSTEM_WINDOW)
1745 != PackageManager.PERMISSION_GRANTED;
1746 }
1747
Craig Mautner967212c2013-04-13 21:10:58 -07001748 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001749 public void adjustWindowParamsLw(WindowManager.LayoutParams attrs) {
1750 switch (attrs.type) {
1751 case TYPE_SYSTEM_OVERLAY:
Jeff Brown3b2b3542010-10-15 00:54:27 -07001752 case TYPE_SECURE_SYSTEM_OVERLAY:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001753 // These types of windows can't receive input events.
1754 attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1755 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001756 attrs.flags &= ~WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001757 break;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001758 case TYPE_STATUS_BAR:
1759
1760 // If the Keyguard is in a hidden state (occluded by another window), we force to
1761 // remove the wallpaper and keyguard flag so that any change in-flight after setting
1762 // the keyguard as occluded wouldn't set these flags again.
1763 // See {@link #processKeyguardSetHiddenResultLw}.
1764 if (mKeyguardHidden) {
1765 attrs.flags &= ~WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
1766 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
1767 }
1768 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001769 }
Adrian Roos38502112014-04-09 21:04:11 +02001770
1771 if (attrs.type != TYPE_STATUS_BAR) {
1772 // The status bar is the only window allowed to exhibit keyguard behavior.
1773 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
1774 }
Adrian Roosea562512014-05-05 13:33:03 +02001775
1776 if (ActivityManager.isHighEndGfx()
1777 && (attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0) {
Adrian Roosf5e9b5c2014-09-10 15:27:41 +02001778 attrs.subtreeSystemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
Adrian Roosea562512014-05-05 13:33:03 +02001779 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
1780 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001781 }
RoboErik8a2cfc32014-05-16 11:19:38 -07001782
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001783 void readLidState() {
Jeff Brown2e7760e2012-04-11 15:14:55 -07001784 mLidState = mWindowManagerFuncs.getLidState();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001785 }
RoboErik8a2cfc32014-05-16 11:19:38 -07001786
Michael Wright3818c922014-09-02 13:59:07 -07001787 private void readCameraLensCoverState() {
1788 mCameraLensCoverState = mWindowManagerFuncs.getCameraLensCoverState();
1789 }
1790
Jeff Browndaa37532012-05-01 15:54:03 -07001791 private boolean isHidden(int accessibilityMode) {
1792 switch (accessibilityMode) {
1793 case 1:
1794 return mLidState == LID_CLOSED;
1795 case 2:
1796 return mLidState == LID_OPEN;
1797 default:
1798 return false;
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001799 }
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001800 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001801
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001802 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07001803 @Override
Jeff Browndaa37532012-05-01 15:54:03 -07001804 public void adjustConfigurationLw(Configuration config, int keyboardPresence,
1805 int navigationPresence) {
1806 mHaveBuiltInKeyboard = (keyboardPresence & PRESENCE_INTERNAL) != 0;
1807
Jeff Brownf71343d2013-05-31 17:59:11 -07001808 readConfigurationDependentBehaviors();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001809 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07001810 applyLidSwitchState();
Jeff Brownd04a88c2011-01-16 14:05:47 -08001811
Jeff Browndaa37532012-05-01 15:54:03 -07001812 if (config.keyboard == Configuration.KEYBOARD_NOKEYS
1813 || (keyboardPresence == PRESENCE_INTERNAL
1814 && isHidden(mLidKeyboardAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001815 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_YES;
Jeff Browndaa37532012-05-01 15:54:03 -07001816 if (!mHasSoftInput) {
1817 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_YES;
1818 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001819 }
1820
Jeff Browndaa37532012-05-01 15:54:03 -07001821 if (config.navigation == Configuration.NAVIGATION_NONAV
1822 || (navigationPresence == PRESENCE_INTERNAL
1823 && isHidden(mLidNavigationAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001824 config.navigationHidden = Configuration.NAVIGATIONHIDDEN_YES;
Jeff Brownd04a88c2011-01-16 14:05:47 -08001825 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001826 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001827
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001828 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07001829 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001830 public int windowTypeToLayerLw(int type) {
1831 if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001832 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001833 }
1834 switch (type) {
keunyounga446bf02013-06-21 19:07:57 -07001835 case TYPE_PRIVATE_PRESENTATION:
1836 return 2;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001837 case TYPE_WALLPAPER:
1838 // wallpaper is at the bottom, though the window manager may move it.
1839 return 2;
1840 case TYPE_PHONE:
1841 return 3;
1842 case TYPE_SEARCH_BAR:
1843 return 4;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001844 case TYPE_VOICE_INTERACTION:
1845 // voice interaction layer is almost immediately above apps.
1846 return 5;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001847 case TYPE_SYSTEM_DIALOG:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001848 return 6;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001849 case TYPE_TOAST:
1850 // toasts and the plugged-in battery thing
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001851 return 7;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001852 case TYPE_PRIORITY_PHONE:
1853 // SIM errors and unlock. Not sure if this really should be in a high layer.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001854 return 8;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001855 case TYPE_DREAM:
1856 // used for Dreams (screensavers with TYPE_DREAM windows)
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001857 return 9;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001858 case TYPE_SYSTEM_ALERT:
1859 // like the ANR / app crashed dialogs
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001860 return 10;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001861 case TYPE_INPUT_METHOD:
1862 // on-screen keyboards and other such input method user interfaces go here.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001863 return 11;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001864 case TYPE_INPUT_METHOD_DIALOG:
1865 // on-screen keyboards and other such input method user interfaces go here.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001866 return 12;
Jim Miller5ecd8112013-01-09 18:50:26 -08001867 case TYPE_KEYGUARD_SCRIM:
1868 // the safety window that shows behind keyguard while keyguard is starting
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001869 return 13;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001870 case TYPE_STATUS_BAR_SUB_PANEL:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001871 return 14;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001872 case TYPE_STATUS_BAR:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001873 return 15;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001874 case TYPE_STATUS_BAR_PANEL:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001875 return 16;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001876 case TYPE_KEYGUARD_DIALOG:
1877 return 17;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001878 case TYPE_VOLUME_OVERLAY:
1879 // the on-screen volume indicator and controller shown when the user
1880 // changes the device volume
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001881 return 18;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001882 case TYPE_SYSTEM_OVERLAY:
1883 // the on-screen volume indicator and controller shown when the user
1884 // changes the device volume
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001885 return 19;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001886 case TYPE_NAVIGATION_BAR:
1887 // the navigation bar, if available, shows atop most things
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001888 return 20;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001889 case TYPE_NAVIGATION_BAR_PANEL:
1890 // some panels (e.g. search) need to show on top of the navigation bar
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001891 return 21;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001892 case TYPE_SYSTEM_ERROR:
1893 // system-level error dialogs
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001894 return 22;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001895 case TYPE_MAGNIFICATION_OVERLAY:
1896 // used to highlight the magnified portion of a display
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001897 return 23;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001898 case TYPE_DISPLAY_OVERLAY:
1899 // used to simulate secondary display devices
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001900 return 24;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001901 case TYPE_DRAG:
1902 // the drag layer: input for drag-and-drop is associated with this window,
1903 // which sits above all other focusable windows
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001904 return 25;
Svetoslav3a5c7212014-10-14 09:54:26 -07001905 case TYPE_ACCESSIBILITY_OVERLAY:
1906 // overlay put by accessibility services to intercept user interaction
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001907 return 26;
Svetoslav3a5c7212014-10-14 09:54:26 -07001908 case TYPE_SECURE_SYSTEM_OVERLAY:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001909 return 27;
Svetoslav3a5c7212014-10-14 09:54:26 -07001910 case TYPE_BOOT_PROGRESS:
1911 return 28;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001912 case TYPE_POINTER:
1913 // the (mouse) pointer layer
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001914 return 29;
Svetoslav3a5c7212014-10-14 09:54:26 -07001915 case TYPE_HIDDEN_NAV_CONSUMER:
1916 return 30;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001917 }
1918 Log.e(TAG, "Unknown window type: " + type);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001919 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001920 }
1921
1922 /** {@inheritDoc} */
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001923 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001924 public int subWindowTypeToLayerLw(int type) {
1925 switch (type) {
1926 case TYPE_APPLICATION_PANEL:
1927 case TYPE_APPLICATION_ATTACHED_DIALOG:
1928 return APPLICATION_PANEL_SUBLAYER;
1929 case TYPE_APPLICATION_MEDIA:
1930 return APPLICATION_MEDIA_SUBLAYER;
Dianne Hackborn5cb8d792009-05-21 17:34:15 -07001931 case TYPE_APPLICATION_MEDIA_OVERLAY:
1932 return APPLICATION_MEDIA_OVERLAY_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001933 case TYPE_APPLICATION_SUB_PANEL:
1934 return APPLICATION_SUB_PANEL_SUBLAYER;
1935 }
1936 Log.e(TAG, "Unknown sub-window type: " + type);
1937 return 0;
1938 }
1939
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001940 @Override
Dianne Hackbornabe0da02009-09-18 01:55:39 -07001941 public int getMaxWallpaperLayer() {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001942 return windowTypeToLayerLw(TYPE_STATUS_BAR);
Dianne Hackbornabe0da02009-09-18 01:55:39 -07001943 }
1944
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001945 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001946 public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07001947 if (mHasNavigationBar) {
1948 // For a basic navigation bar, when we are in landscape mode we place
1949 // the navigation bar to the side.
Daniel Sandler4a066c52012-04-20 14:49:13 -04001950 if (mNavigationBarCanMove && fullWidth > fullHeight) {
1951 return fullWidth - mNavigationBarWidthForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07001952 }
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001953 }
1954 return fullWidth;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001955 }
1956
Jose Lima9546b202014-07-02 17:21:51 -07001957 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001958 public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07001959 if (mHasNavigationBar) {
1960 // For a basic navigation bar, when we are in portrait mode we place
1961 // the navigation bar to the bottom.
Daniel Sandler4a066c52012-04-20 14:49:13 -04001962 if (!mNavigationBarCanMove || fullWidth < fullHeight) {
1963 return fullHeight - mNavigationBarHeightForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07001964 }
1965 }
1966 return fullHeight;
Dianne Hackborn69cb8752011-05-19 18:13:32 -07001967 }
1968
Jose Lima9546b202014-07-02 17:21:51 -07001969 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001970 public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation) {
1971 return getNonDecorDisplayWidth(fullWidth, fullHeight, rotation);
Dianne Hackborn69cb8752011-05-19 18:13:32 -07001972 }
1973
Jose Lima9546b202014-07-02 17:21:51 -07001974 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001975 public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation) {
John Spurlock80f00c12013-06-13 11:10:51 -04001976 // There is a separate status bar at the top of the display. We don't count that as part
1977 // of the fixed decor, since it can hide; however, for purposes of configurations,
Dianne Hackborn077ee852012-04-09 16:27:07 -07001978 // we do want to exclude it since applications can't generally use that part
1979 // of the screen.
John Spurlock80f00c12013-06-13 11:10:51 -04001980 return getNonDecorDisplayHeight(fullWidth, fullHeight, rotation) - mStatusBarHeight;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001981 }
1982
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001983 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07001984 public boolean isForceHiding(WindowManager.LayoutParams attrs) {
1985 return (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 ||
Jim Millerab954542014-10-10 18:21:49 -07001986 (isKeyguardHostWindow(attrs) &&
1987 (mKeyguardDelegate != null && mKeyguardDelegate.isShowing())) ||
Adrian Roos69e510d2014-07-13 14:57:59 +02001988 (attrs.type == TYPE_KEYGUARD_SCRIM);
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07001989 }
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001990
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001991 @Override
Jorim Jaggi0d674622014-05-21 01:34:15 +02001992 public boolean isKeyguardHostWindow(WindowManager.LayoutParams attrs) {
1993 return attrs.type == TYPE_STATUS_BAR;
1994 }
1995
1996 @Override
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07001997 public boolean canBeForceHidden(WindowState win, WindowManager.LayoutParams attrs) {
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001998 switch (attrs.type) {
1999 case TYPE_STATUS_BAR:
2000 case TYPE_NAVIGATION_BAR:
2001 case TYPE_WALLPAPER:
2002 case TYPE_DREAM:
Jim Miller5ecd8112013-01-09 18:50:26 -08002003 case TYPE_KEYGUARD_SCRIM:
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002004 return false;
2005 default:
2006 return true;
2007 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002008 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002009
Craig Mautner7d7808f2014-09-11 18:02:38 -07002010 @Override
2011 public WindowState getWinShowWhenLockedLw() {
2012 return mWinShowWhenLocked;
2013 }
2014
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002015 /** {@inheritDoc} */
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002016 @Override
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07002017 public View addStartingWindow(IBinder appToken, String packageName, int theme,
2018 CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes,
Adam Powell04fe6eb2013-05-31 14:39:48 -07002019 int icon, int logo, int windowFlags) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002020 if (!SHOW_STARTING_ANIMATIONS) {
2021 return null;
2022 }
2023 if (packageName == null) {
2024 return null;
2025 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002026
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002027 WindowManager wm = null;
2028 View view = null;
2029
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002030 try {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002031 Context context = mContext;
Craig Mautner6fbda632012-07-03 09:26:39 -07002032 if (DEBUG_STARTING_WINDOW) Slog.d(TAG, "addStartingWindow " + packageName
2033 + ": nonLocalizedLabel=" + nonLocalizedLabel + " theme="
2034 + Integer.toHexString(theme));
Dianne Hackborn247fe742011-01-08 17:25:57 -08002035 if (theme != context.getThemeResId() || labelRes != 0) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002036 try {
2037 context = context.createPackageContext(packageName, 0);
Dianne Hackborn247fe742011-01-08 17:25:57 -08002038 context.setTheme(theme);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002039 } catch (PackageManager.NameNotFoundException e) {
2040 // Ignore
2041 }
2042 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002043
Jorim Jaggib10e33f2015-02-04 21:57:40 +01002044 Window win = new PhoneWindow(context);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002045 final TypedArray ta = win.getWindowStyle();
2046 if (ta.getBoolean(
2047 com.android.internal.R.styleable.Window_windowDisablePreview, false)
2048 || ta.getBoolean(
2049 com.android.internal.R.styleable.Window_windowShowWallpaper,false)) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002050 return null;
2051 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002052
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002053 Resources r = context.getResources();
2054 win.setTitle(r.getText(labelRes, nonLocalizedLabel));
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002055
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002056 win.setType(
2057 WindowManager.LayoutParams.TYPE_APPLICATION_STARTING);
2058 // Force the window flags: this is a fake window, so it is not really
2059 // touchable or focusable by the user. We also add in the ALT_FOCUSABLE_IM
2060 // flag because we do know that the next window will take input
2061 // focus, so we want to get the IME window up on top of us right away.
2062 win.setFlags(
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08002063 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002064 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
2065 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
2066 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08002067 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002068 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
2069 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
2070 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002071
Adam Powell04fe6eb2013-05-31 14:39:48 -07002072 win.setDefaultIcon(icon);
2073 win.setDefaultLogo(logo);
2074
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002075 win.setLayout(WindowManager.LayoutParams.MATCH_PARENT,
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07002076 WindowManager.LayoutParams.MATCH_PARENT);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002077
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002078 final WindowManager.LayoutParams params = win.getAttributes();
2079 params.token = appToken;
2080 params.packageName = packageName;
2081 params.windowAnimations = win.getWindowStyle().getResourceId(
2082 com.android.internal.R.styleable.Window_windowAnimationStyle, 0);
John Reck61375a82014-09-18 19:27:48 +00002083 params.privateFlags |=
2084 WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED;
Craig Mautner88400d32012-09-30 12:35:45 -07002085 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
Adam Lesinski95c42972013-10-02 10:13:27 -07002086
2087 if (!compatInfo.supportsScreen()) {
2088 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
2089 }
2090
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002091 params.setTitle("Starting " + packageName);
2092
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002093 wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
2094 view = win.getDecorView();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002095
2096 if (win.isFloating()) {
2097 // Whoops, there is no way to display an animation/preview
2098 // of such a thing! After all that work... let's skip it.
2099 // (Note that we must do this here because it is in
2100 // getDecorView() where the theme is evaluated... maybe
2101 // we should peek the floating attribute from the theme
2102 // earlier.)
2103 return null;
2104 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002105
Craig Mautner6fbda632012-07-03 09:26:39 -07002106 if (DEBUG_STARTING_WINDOW) Slog.d(
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002107 TAG, "Adding starting window for " + packageName
2108 + " / " + appToken + ": "
2109 + (view.getParent() != null ? view : null));
2110
2111 wm.addView(view, params);
2112
2113 // Only return the view if it was successfully added to the
2114 // window manager... which we can tell by it having a parent.
2115 return view.getParent() != null ? view : null;
Jeff Brown98365d72012-08-19 20:30:52 -07002116 } catch (WindowManager.BadTokenException e) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002117 // ignore
Craig Mautner42bf39e2014-02-21 16:46:22 -08002118 Log.w(TAG, appToken + " already running, starting window not displayed. " +
2119 e.getMessage());
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002120 } catch (RuntimeException e) {
2121 // don't crash if something else bad happens, for example a
2122 // failure loading resources because we are loading from an app
2123 // on external storage that has been unmounted.
2124 Log.w(TAG, appToken + " failed creating starting window", e);
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002125 } finally {
2126 if (view != null && view.getParent() == null) {
2127 Log.w(TAG, "view not successfully added to wm, removing view");
2128 wm.removeViewImmediate(view);
2129 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002130 }
2131
2132 return null;
2133 }
2134
2135 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07002136 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002137 public void removeStartingWindow(IBinder appToken, View window) {
Craig Mautner276a6eb2014-11-04 15:32:57 -08002138 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Removing starting window for " + appToken + ": "
2139 + window + " Callers=" + Debug.getCallers(4));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002140
2141 if (window != null) {
Dianne Hackborn5fd21692011-06-07 14:09:47 -07002142 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002143 wm.removeView(window);
2144 }
2145 }
2146
2147 /**
2148 * Preflight adding a window to the system.
RoboErik8a2cfc32014-05-16 11:19:38 -07002149 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002150 * Currently enforces that three window types are singletons:
2151 * <ul>
2152 * <li>STATUS_BAR_TYPE</li>
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002153 * <li>KEYGUARD_TYPE</li>
2154 * </ul>
RoboErik8a2cfc32014-05-16 11:19:38 -07002155 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002156 * @param win The window to be added
2157 * @param attrs Information about the window to be added
RoboErik8a2cfc32014-05-16 11:19:38 -07002158 *
Jeff Brown98365d72012-08-19 20:30:52 -07002159 * @return If ok, WindowManagerImpl.ADD_OKAY. If too many singletons,
2160 * WindowManagerImpl.ADD_MULTIPLE_SINGLETON
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002161 */
Jose Lima9546b202014-07-02 17:21:51 -07002162 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002163 public int prepareAddWindowLw(WindowState win, WindowManager.LayoutParams attrs) {
2164 switch (attrs.type) {
2165 case TYPE_STATUS_BAR:
Joe Onorato8bc6c512010-06-04 16:21:12 -04002166 mContext.enforceCallingOrSelfPermission(
2167 android.Manifest.permission.STATUS_BAR_SERVICE,
2168 "PhoneWindowManager");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002169 if (mStatusBar != null) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002170 if (mStatusBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07002171 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002172 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002173 }
2174 mStatusBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04002175 mStatusBarController.setWindow(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002176 break;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002177 case TYPE_NAVIGATION_BAR:
2178 mContext.enforceCallingOrSelfPermission(
2179 android.Manifest.permission.STATUS_BAR_SERVICE,
2180 "PhoneWindowManager");
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002181 if (mNavigationBar != null) {
2182 if (mNavigationBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07002183 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002184 }
2185 }
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002186 mNavigationBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04002187 mNavigationBarController.setWindow(win);
Craig Mautnereda67292013-04-28 13:50:14 -07002188 if (DEBUG_LAYOUT) Slog.i(TAG, "NAVIGATION BAR: " + mNavigationBar);
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002189 break;
Jim Millere898ac52012-04-06 17:10:57 -07002190 case TYPE_NAVIGATION_BAR_PANEL:
2191 mContext.enforceCallingOrSelfPermission(
2192 android.Manifest.permission.STATUS_BAR_SERVICE,
2193 "PhoneWindowManager");
2194 break;
Dianne Hackborn08743722009-12-21 12:16:51 -08002195 case TYPE_STATUS_BAR_PANEL:
Joe Onorato8bc6c512010-06-04 16:21:12 -04002196 mContext.enforceCallingOrSelfPermission(
2197 android.Manifest.permission.STATUS_BAR_SERVICE,
2198 "PhoneWindowManager");
Dianne Hackborn08743722009-12-21 12:16:51 -08002199 break;
Joe Onorato29fc2c92010-11-24 10:26:50 -08002200 case TYPE_STATUS_BAR_SUB_PANEL:
2201 mContext.enforceCallingOrSelfPermission(
2202 android.Manifest.permission.STATUS_BAR_SERVICE,
2203 "PhoneWindowManager");
Joe Onorato29fc2c92010-11-24 10:26:50 -08002204 break;
Jim Miller5ecd8112013-01-09 18:50:26 -08002205 case TYPE_KEYGUARD_SCRIM:
Jim Miller25190572013-02-28 17:36:24 -08002206 if (mKeyguardScrim != null) {
2207 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
2208 }
Jim Miller5ecd8112013-01-09 18:50:26 -08002209 mKeyguardScrim = win;
2210 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002211 }
Jeff Brown98365d72012-08-19 20:30:52 -07002212 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002213 }
2214
2215 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07002216 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002217 public void removeWindowLw(WindowState win) {
2218 if (mStatusBar == win) {
2219 mStatusBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04002220 mStatusBarController.setWindow(null);
Jim Millerc0b676d2013-03-22 16:11:08 -07002221 mKeyguardDelegate.showScrim();
Jim Miller5ecd8112013-01-09 18:50:26 -08002222 } else if (mKeyguardScrim == win) {
2223 Log.v(TAG, "Removing keyguard scrim");
2224 mKeyguardScrim = null;
2225 } if (mNavigationBar == win) {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002226 mNavigationBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04002227 mNavigationBarController.setWindow(null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002228 }
2229 }
2230
2231 static final boolean PRINT_ANIM = false;
RoboErik8a2cfc32014-05-16 11:19:38 -07002232
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002233 /** {@inheritDoc} */
Craig Mautner4b71aa12012-12-27 17:20:01 -08002234 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002235 public int selectAnimationLw(WindowState win, int transit) {
2236 if (PRINT_ANIM) Log.i(TAG, "selectAnimation in " + win
2237 + ": transit=" + transit);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002238 if (win == mStatusBar) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002239 boolean isKeyguard = (win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002240 if (transit == TRANSIT_EXIT
2241 || transit == TRANSIT_HIDE) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002242 return isKeyguard ? -1 : R.anim.dock_top_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002243 } else if (transit == TRANSIT_ENTER
2244 || transit == TRANSIT_SHOW) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002245 return isKeyguard ? -1 : R.anim.dock_top_enter;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002246 }
2247 } else if (win == mNavigationBar) {
2248 // This can be on either the bottom or the right.
2249 if (mNavigationBarOnBottom) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08002250 if (transit == TRANSIT_EXIT
2251 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002252 return R.anim.dock_bottom_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002253 } else if (transit == TRANSIT_ENTER
2254 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002255 return R.anim.dock_bottom_enter;
2256 }
2257 } else {
Craig Mautner4b71aa12012-12-27 17:20:01 -08002258 if (transit == TRANSIT_EXIT
2259 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002260 return R.anim.dock_right_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002261 } else if (transit == TRANSIT_ENTER
2262 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002263 return R.anim.dock_right_enter;
2264 }
2265 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08002266 }
2267
2268 if (transit == TRANSIT_PREVIEW_DONE) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002269 if (win.hasAppShownWindows()) {
2270 if (PRINT_ANIM) Log.i(TAG, "**** STARTING EXIT");
2271 return com.android.internal.R.anim.app_starting_exit;
2272 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07002273 } else if (win.getAttrs().type == TYPE_DREAM && mDreamingLockscreen
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002274 && transit == TRANSIT_ENTER) {
2275 // Special case: we are animating in a dream, while the keyguard
2276 // is shown. We don't want an animation on the dream, because
2277 // we need it shown immediately with the keyguard animating away
2278 // to reveal it.
2279 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002280 }
2281
2282 return 0;
2283 }
2284
Craig Mautner3c174372013-02-21 17:54:37 -08002285 @Override
2286 public void selectRotationAnimationLw(int anim[]) {
2287 if (PRINT_ANIM) Slog.i(TAG, "selectRotationAnimation mTopFullscreen="
2288 + mTopFullscreenOpaqueWindowState + " rotationAnimation="
2289 + (mTopFullscreenOpaqueWindowState == null ?
2290 "0" : mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation));
2291 if (mTopFullscreenOpaqueWindowState != null && mTopIsFullscreen) {
2292 switch (mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation) {
2293 case ROTATION_ANIMATION_CROSSFADE:
2294 anim[0] = R.anim.rotation_animation_xfade_exit;
2295 anim[1] = R.anim.rotation_animation_enter;
2296 break;
2297 case ROTATION_ANIMATION_JUMPCUT:
2298 anim[0] = R.anim.rotation_animation_jump_exit;
2299 anim[1] = R.anim.rotation_animation_enter;
2300 break;
2301 case ROTATION_ANIMATION_ROTATE:
2302 default:
2303 anim[0] = anim[1] = 0;
2304 break;
2305 }
2306 } else {
2307 anim[0] = anim[1] = 0;
2308 }
2309 }
2310
2311 @Override
2312 public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId,
2313 boolean forceDefault) {
2314 switch (exitAnimId) {
2315 case R.anim.rotation_animation_xfade_exit:
2316 case R.anim.rotation_animation_jump_exit:
2317 // These are the only cases that matter.
2318 if (forceDefault) {
2319 return false;
2320 }
2321 int anim[] = new int[2];
2322 selectRotationAnimationLw(anim);
2323 return (exitAnimId == anim[0] && enterAnimId == anim[1]);
2324 default:
2325 return true;
2326 }
2327 }
2328
2329 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002330 public Animation createForceHideEnterAnimation(boolean onWallpaper,
2331 boolean goingToNotificationShade) {
2332 if (goingToNotificationShade) {
2333 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_behind_enter_fade_in);
Craig Mautnerb8340802014-11-04 15:32:57 -08002334 }
Craig Mautner276a6eb2014-11-04 15:32:57 -08002335
2336 AnimationSet set = (AnimationSet) AnimationUtils.loadAnimation(mContext, onWallpaper ?
2337 R.anim.lock_screen_behind_enter_wallpaper :
2338 R.anim.lock_screen_behind_enter);
2339
2340 // TODO: Use XML interpolators when we have log interpolators available in XML.
2341 final List<Animation> animations = set.getAnimations();
2342 for (int i = animations.size() - 1; i >= 0; --i) {
2343 animations.get(i).setInterpolator(mLogDecelerateInterpolator);
2344 }
2345
2346 return set;
Jorim Jaggi76a16232014-08-08 17:00:47 +02002347 }
2348
2349
2350 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002351 public Animation createForceHideWallpaperExitAnimation(boolean goingToNotificationShade) {
2352 if (goingToNotificationShade) {
2353 return null;
2354 } else {
2355 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_wallpaper_exit);
2356 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002357 }
John Spurlockc8b46ca2013-04-08 12:59:26 -04002358
2359 private static void awakenDreams() {
2360 IDreamManager dreamManager = getDreamManager();
2361 if (dreamManager != null) {
2362 try {
2363 dreamManager.awaken();
2364 } catch (RemoteException e) {
2365 // fine, stay asleep then
2366 }
2367 }
2368 }
2369
2370 static IDreamManager getDreamManager() {
2371 return IDreamManager.Stub.asInterface(
2372 ServiceManager.checkService(DreamService.DREAM_SERVICE));
2373 }
2374
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002375 TelecomManager getTelecommService() {
2376 return (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002377 }
2378
Jeff Brown4d396052010-10-29 21:50:21 -07002379 static IAudioService getAudioService() {
2380 IAudioService audioService = IAudioService.Stub.asInterface(
2381 ServiceManager.checkService(Context.AUDIO_SERVICE));
2382 if (audioService == null) {
2383 Log.w(TAG, "Unable to find IAudioService interface.");
2384 }
2385 return audioService;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002386 }
2387
2388 boolean keyguardOn() {
Jim Millerab954542014-10-10 18:21:49 -07002389 return isKeyguardShowingAndNotOccluded() || inKeyguardRestrictedKeyInputMode();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002390 }
2391
2392 private static final int[] WINDOW_TYPES_WHERE_HOME_DOESNT_WORK = {
2393 WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
2394 WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
2395 };
2396
2397 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002398 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002399 public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002400 final boolean keyguardOn = keyguardOn();
Jeff Brown1f245102010-11-18 20:53:46 -08002401 final int keyCode = event.getKeyCode();
2402 final int repeatCount = event.getRepeatCount();
2403 final int metaState = event.getMetaState();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002404 final int flags = event.getFlags();
Jeff Brown1f245102010-11-18 20:53:46 -08002405 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
2406 final boolean canceled = event.isCanceled();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002407
Jeff Brown40013652012-05-16 21:22:36 -07002408 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002409 Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount="
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002410 + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed
2411 + " canceled=" + canceled);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002412 }
2413
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002414 // If we think we might have a volume down & power key chord on the way
2415 // but we're not sure, then tell the dispatcher to wait a little while and
2416 // try again later before dispatching.
Christopher Tatee90585f2012-03-05 18:56:25 -08002417 if (mScreenshotChordEnabled && (flags & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07002418 if (mScreenshotChordVolumeDownKeyTriggered && !mScreenshotChordPowerKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002419 final long now = SystemClock.uptimeMillis();
Jeff Brown13f00f02014-10-31 14:45:50 -07002420 final long timeoutTime = mScreenshotChordVolumeDownKeyTime
2421 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002422 if (now < timeoutTime) {
2423 return timeoutTime - now;
2424 }
2425 }
2426 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
Jeff Brown13f00f02014-10-31 14:45:50 -07002427 && mScreenshotChordVolumeDownKeyConsumed) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002428 if (!down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07002429 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002430 }
2431 return -1;
2432 }
2433 }
2434
Michael Wright6a62e552014-06-03 19:19:48 -07002435 // Cancel any pending meta actions if we see any other keys being pressed between the down
2436 // of the meta key and its corresponding up.
Michael Wright251e35d2014-08-22 15:40:27 -07002437 if (mPendingMetaAction && !KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07002438 mPendingMetaAction = false;
2439 }
2440
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002441 // First we always handle the home key here, so applications
2442 // can never break it, although if keyguard is on, we do let
2443 // it handle it, because that gives us the correct 5 second
2444 // timeout.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002445 if (keyCode == KeyEvent.KEYCODE_HOME) {
Michael Jurka7f2668c2012-03-27 07:49:52 -07002446
Jeff Brown49ed71d2010-12-06 17:13:33 -08002447 // If we have released the home key, and didn't do anything else
2448 // while it was pressed, then it is time to go home!
Michael Jurka7f2668c2012-03-27 07:49:52 -07002449 if (!down) {
Jeff Browncaca8812013-05-09 13:34:33 -07002450 cancelPreloadRecentApps();
2451
Jeff Brown49ed71d2010-12-06 17:13:33 -08002452 mHomePressed = false;
Jeff Browncaca8812013-05-09 13:34:33 -07002453 if (mHomeConsumed) {
2454 mHomeConsumed = false;
Michael Jurka7f2668c2012-03-27 07:49:52 -07002455 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002456 }
Jeff Browncaca8812013-05-09 13:34:33 -07002457
2458 if (canceled) {
2459 Log.i(TAG, "Ignoring HOME; event canceled.");
2460 return -1;
2461 }
2462
Yorke Lee4f803242014-12-15 23:22:06 +00002463 // If an incoming call is ringing, HOME is totally disabled.
2464 // (The user is already on the InCallUI at this point,
2465 // and his ONLY options are to answer or reject the call.)
2466 TelecomManager telecomManager = getTelecommService();
2467 if (telecomManager != null && telecomManager.isRinging()) {
2468 Log.i(TAG, "Ignoring HOME; there's a ringing incoming call.");
2469 return -1;
2470 }
2471
Jeff Browncaca8812013-05-09 13:34:33 -07002472 // Delay handling home if a double-tap is possible.
2473 if (mDoubleTapOnHomeBehavior != DOUBLE_TAP_HOME_NOTHING) {
2474 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); // just in case
2475 mHomeDoubleTapPending = true;
2476 mHandler.postDelayed(mHomeDoubleTapTimeoutRunnable,
2477 ViewConfiguration.getDoubleTapTimeout());
2478 return -1;
2479 }
2480
Jeff Brown13f00f02014-10-31 14:45:50 -07002481 handleShortPressOnHome();
Jeff Browncaca8812013-05-09 13:34:33 -07002482 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002483 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002484
2485 // If a system window has focus, then it doesn't make sense
2486 // right now to interact with applications.
2487 WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null;
2488 if (attrs != null) {
2489 final int type = attrs.type;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002490 if (type == WindowManager.LayoutParams.TYPE_KEYGUARD_SCRIM
2491 || type == WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG
2492 || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002493 // the "app" is keyguard, so give it the key
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002494 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002495 }
2496 final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length;
2497 for (int i=0; i<typeCount; i++) {
2498 if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) {
2499 // don't do anything, but also don't pass it to the app
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002500 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002501 }
2502 }
2503 }
Jeff Browncaca8812013-05-09 13:34:33 -07002504
2505 // Remember that home is pressed and handle special actions.
2506 if (repeatCount == 0) {
2507 mHomePressed = true;
2508 if (mHomeDoubleTapPending) {
2509 mHomeDoubleTapPending = false;
2510 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable);
2511 handleDoubleTapOnHome();
2512 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI
2513 || mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
2514 preloadRecentApps();
Michael Jurka7f2668c2012-03-27 07:49:52 -07002515 }
Jeff Browncaca8812013-05-09 13:34:33 -07002516 } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) {
2517 if (!keyguardOn) {
2518 handleLongPressOnHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002519 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002520 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002521 return -1;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002522 } else if (keyCode == KeyEvent.KEYCODE_MENU) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002523 // Hijack modified menu keys for debugging features
2524 final int chordBug = KeyEvent.META_SHIFT_ON;
2525
2526 if (down && repeatCount == 0) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002527 if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002528 Intent intent = new Intent(Intent.ACTION_BUG_REPORT);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002529 mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT,
2530 null, null, null, 0, null, null);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002531 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002532 } else if (SHOW_PROCESSES_ON_ALT_MENU &&
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002533 (metaState & KeyEvent.META_ALT_ON) == KeyEvent.META_ALT_ON) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002534 Intent service = new Intent();
2535 service.setClassName(mContext, "com.android.server.LoadAverageService");
2536 ContentResolver res = mContext.getContentResolver();
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002537 boolean shown = Settings.Global.getInt(
2538 res, Settings.Global.SHOW_PROCESSES, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002539 if (!shown) {
2540 mContext.startService(service);
2541 } else {
2542 mContext.stopService(service);
2543 }
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002544 Settings.Global.putInt(
2545 res, Settings.Global.SHOW_PROCESSES, shown ? 0 : 1);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002546 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002547 }
2548 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002549 } else if (keyCode == KeyEvent.KEYCODE_SEARCH) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002550 if (down) {
2551 if (repeatCount == 0) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002552 mSearchKeyShortcutPending = true;
2553 mConsumeSearchKeyUp = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002554 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002555 } else {
2556 mSearchKeyShortcutPending = false;
2557 if (mConsumeSearchKeyUp) {
2558 mConsumeSearchKeyUp = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002559 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002560 }
2561 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002562 return 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002563 } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) {
Michael Wrightc9ebea72013-01-16 19:25:02 -08002564 if (!keyguardOn) {
Jeff Browncaca8812013-05-09 13:34:33 -07002565 if (down && repeatCount == 0) {
2566 preloadRecentApps();
2567 } else if (!down) {
2568 toggleRecentApps();
Michael Wrightc9ebea72013-01-16 19:25:02 -08002569 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002570 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002571 return -1;
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002572 } else if (keyCode == KeyEvent.KEYCODE_ASSIST) {
2573 if (down) {
2574 if (repeatCount == 0) {
2575 mAssistKeyLongPressed = false;
2576 } else if (repeatCount == 1) {
2577 mAssistKeyLongPressed = true;
2578 if (!keyguardOn) {
2579 launchAssistLongPressAction();
2580 }
2581 }
2582 } else {
2583 if (mAssistKeyLongPressed) {
2584 mAssistKeyLongPressed = false;
2585 } else {
2586 if (!keyguardOn) {
2587 launchAssistAction();
2588 }
2589 }
2590 }
2591 return -1;
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002592 } else if (keyCode == KeyEvent.KEYCODE_VOICE_ASSIST) {
2593 if (!down) {
2594 Intent voiceIntent;
Michael Wright869a67c2014-08-26 19:33:06 -07002595 if (!keyguardOn) {
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002596 voiceIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
2597 } else {
2598 voiceIntent = new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
Michael Wright869a67c2014-08-26 19:33:06 -07002599 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, true);
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002600 }
2601 mContext.startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
2602 }
Jeff Sharkey2991fa32012-12-05 18:06:43 -08002603 } else if (keyCode == KeyEvent.KEYCODE_SYSRQ) {
2604 if (down && repeatCount == 0) {
2605 mHandler.post(mScreenshotRunnable);
2606 }
2607 return -1;
Michael Wrightb854e242013-02-05 17:54:02 -08002608 } else if (keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP
2609 || keyCode == KeyEvent.KEYCODE_BRIGHTNESS_DOWN) {
2610 if (down) {
2611 int direction = keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP ? 1 : -1;
2612
2613 // Disable autobrightness if it's on
2614 int auto = Settings.System.getIntForUser(
2615 mContext.getContentResolver(),
2616 Settings.System.SCREEN_BRIGHTNESS_MODE,
2617 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2618 UserHandle.USER_CURRENT_OR_SELF);
2619 if (auto != 0) {
2620 Settings.System.putIntForUser(mContext.getContentResolver(),
2621 Settings.System.SCREEN_BRIGHTNESS_MODE,
2622 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2623 UserHandle.USER_CURRENT_OR_SELF);
2624 }
2625
2626 int min = mPowerManager.getMinimumScreenBrightnessSetting();
2627 int max = mPowerManager.getMaximumScreenBrightnessSetting();
2628 int step = (max - min + BRIGHTNESS_STEPS - 1) / BRIGHTNESS_STEPS * direction;
2629 int brightness = Settings.System.getIntForUser(mContext.getContentResolver(),
2630 Settings.System.SCREEN_BRIGHTNESS,
2631 mPowerManager.getDefaultScreenBrightnessSetting(),
2632 UserHandle.USER_CURRENT_OR_SELF);
2633 brightness += step;
2634 // Make sure we don't go beyond the limits.
2635 brightness = Math.min(max, brightness);
2636 brightness = Math.max(min, brightness);
2637
2638 Settings.System.putIntForUser(mContext.getContentResolver(),
2639 Settings.System.SCREEN_BRIGHTNESS, brightness,
2640 UserHandle.USER_CURRENT_OR_SELF);
Alan Viverette5a399492014-07-14 16:19:38 -07002641 mContext.startActivityAsUser(new Intent(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG),
2642 UserHandle.CURRENT_OR_SELF);
Michael Wrightb854e242013-02-05 17:54:02 -08002643 }
2644 return -1;
Michael Wrightce0c13a2014-07-30 10:49:21 -07002645 } else if (KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07002646 if (down) {
2647 mPendingMetaAction = true;
2648 } else if (mPendingMetaAction) {
Michael Wright8ab940a2014-09-01 11:01:27 -07002649 launchAssistAction(Intent.EXTRA_ASSIST_INPUT_HINT_KEYBOARD);
Michael Wright6a62e552014-06-03 19:19:48 -07002650 }
2651 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002652 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002653
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002654 // Shortcuts are invoked through Search+key, so intercept those here
Jeff Browncaab4d02010-12-09 22:13:41 -08002655 // Any printing key that is chorded with Search should be consumed
2656 // even if no shortcut was invoked. This prevents text from being
2657 // inadvertently inserted when using a keyboard that has built-in macro
2658 // shortcut keys (that emit Search+x) and some of them are not registered.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002659 if (mSearchKeyShortcutPending) {
Jeff Browncaab4d02010-12-09 22:13:41 -08002660 final KeyCharacterMap kcm = event.getKeyCharacterMap();
2661 if (kcm.isPrintingKey(keyCode)) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002662 mConsumeSearchKeyUp = true;
2663 mSearchKeyShortcutPending = false;
Jeff Browncaab4d02010-12-09 22:13:41 -08002664 if (down && repeatCount == 0 && !keyguardOn) {
2665 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState);
2666 if (shortcutIntent != null) {
2667 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002668 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002669 mContext.startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002670 } catch (ActivityNotFoundException ex) {
2671 Slog.w(TAG, "Dropping shortcut key combination because "
2672 + "the activity to which it is registered was not found: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002673 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode), ex);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002674 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002675 } else {
2676 Slog.i(TAG, "Dropping unregistered shortcut key combination: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002677 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002678 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002679 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002680 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002681 }
2682 }
2683
Jeff Brown68b909d2011-12-07 16:36:01 -08002684 // Invoke shortcuts using Meta.
Jeff Brown602ab322012-05-16 13:33:47 -07002685 if (down && repeatCount == 0 && !keyguardOn
Jeff Brown68b909d2011-12-07 16:36:01 -08002686 && (metaState & KeyEvent.META_META_ON) != 0) {
2687 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brown602ab322012-05-16 13:33:47 -07002688 if (kcm.isPrintingKey(keyCode)) {
2689 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode,
2690 metaState & ~(KeyEvent.META_META_ON
2691 | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON));
2692 if (shortcutIntent != null) {
2693 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2694 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002695 mContext.startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brown602ab322012-05-16 13:33:47 -07002696 } catch (ActivityNotFoundException ex) {
2697 Slog.w(TAG, "Dropping shortcut key combination because "
2698 + "the activity to which it is registered was not found: "
2699 + "META+" + KeyEvent.keyCodeToString(keyCode), ex);
2700 }
2701 return -1;
Jeff Brown68b909d2011-12-07 16:36:01 -08002702 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002703 }
2704 }
2705
Jeff Brown6651a632011-11-28 12:59:11 -08002706 // Handle application launch keys.
Jeff Brown602ab322012-05-16 13:33:47 -07002707 if (down && repeatCount == 0 && !keyguardOn) {
Jeff Brown6651a632011-11-28 12:59:11 -08002708 String category = sApplicationLaunchKeyCategories.get(keyCode);
2709 if (category != null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -08002710 Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category);
Jeff Brown6651a632011-11-28 12:59:11 -08002711 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2712 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002713 mContext.startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brown6651a632011-11-28 12:59:11 -08002714 } catch (ActivityNotFoundException ex) {
2715 Slog.w(TAG, "Dropping application launch key because "
2716 + "the activity to which it is registered was not found: "
2717 + "keyCode=" + keyCode + ", category=" + category, ex);
2718 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002719 return -1;
Jeff Brown6651a632011-11-28 12:59:11 -08002720 }
2721 }
2722
Michael Wright61c46752014-08-21 16:57:33 -07002723 // Display task switcher for ALT-TAB.
Jeff Brown68b909d2011-12-07 16:36:01 -08002724 if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_TAB) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002725 if (mRecentAppsHeldModifiers == 0 && !keyguardOn) {
Jeff Brown68b909d2011-12-07 16:36:01 -08002726 final int shiftlessModifiers = event.getModifiers() & ~KeyEvent.META_SHIFT_MASK;
Michael Wright61c46752014-08-21 16:57:33 -07002727 if (KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_ALT_ON)) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002728 mRecentAppsHeldModifiers = shiftlessModifiers;
2729 showRecentApps(true);
Jeff Brown68b909d2011-12-07 16:36:01 -08002730 return -1;
2731 }
2732 }
Winson Chung1e8d71b2014-05-16 17:05:22 -07002733 } else if (!down && mRecentAppsHeldModifiers != 0
2734 && (metaState & mRecentAppsHeldModifiers) == 0) {
2735 mRecentAppsHeldModifiers = 0;
Winson Chungcdcd4872014-08-05 18:00:13 -07002736 hideRecentApps(true, false);
Jeff Brown68b909d2011-12-07 16:36:01 -08002737 }
2738
Jeff Browncf39bdf2012-05-18 14:41:19 -07002739 // Handle keyboard language switching.
2740 if (down && repeatCount == 0
2741 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2742 || (keyCode == KeyEvent.KEYCODE_SPACE
2743 && (metaState & KeyEvent.META_CTRL_MASK) != 0))) {
2744 int direction = (metaState & KeyEvent.META_SHIFT_MASK) != 0 ? -1 : 1;
2745 mWindowManagerFuncs.switchKeyboardLayout(event.getDeviceId(), direction);
2746 return -1;
2747 }
2748 if (mLanguageSwitchKeyPressed && !down
2749 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2750 || keyCode == KeyEvent.KEYCODE_SPACE)) {
2751 mLanguageSwitchKeyPressed = false;
2752 return -1;
2753 }
2754
Jeff Brown13f00f02014-10-31 14:45:50 -07002755 if (isValidGlobalKey(keyCode)
2756 && mGlobalKeyManager.handleGlobalKey(mContext, keyCode, event)) {
Justin Kohd378ad72013-04-01 12:18:26 -07002757 return -1;
2758 }
2759
Michael Wright6a62e552014-06-03 19:19:48 -07002760 // Reserve all the META modifier combos for system behavior
Michael Wrightce0c13a2014-07-30 10:49:21 -07002761 if ((metaState & KeyEvent.META_META_ON) != 0) {
Michael Wright6a62e552014-06-03 19:19:48 -07002762 return -1;
2763 }
2764
Jeff Brown68b909d2011-12-07 16:36:01 -08002765 // Let the application handle the key.
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002766 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002767 }
2768
Jeff Brown3915bb82010-11-05 15:02:16 -07002769 /** {@inheritDoc} */
2770 @Override
Jeff Brown49ed71d2010-12-06 17:13:33 -08002771 public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown54875002011-04-06 15:33:01 -07002772 // Note: This method is only called if the initial down was unhandled.
Jeff Brown40013652012-05-16 21:22:36 -07002773 if (DEBUG_INPUT) {
Jeff Brown1f245102010-11-18 20:53:46 -08002774 Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction()
2775 + ", flags=" + event.getFlags()
2776 + ", keyCode=" + event.getKeyCode()
2777 + ", scanCode=" + event.getScanCode()
2778 + ", metaState=" + event.getMetaState()
2779 + ", repeatCount=" + event.getRepeatCount()
2780 + ", policyFlags=" + policyFlags);
Jeff Brown3915bb82010-11-05 15:02:16 -07002781 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002782
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002783 KeyEvent fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002784 if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
2785 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002786 final int keyCode = event.getKeyCode();
2787 final int metaState = event.getMetaState();
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002788 final boolean initialDown = event.getAction() == KeyEvent.ACTION_DOWN
2789 && event.getRepeatCount() == 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002790
Jeff Brown54875002011-04-06 15:33:01 -07002791 // Check for fallback actions specified by the key character map.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002792 final FallbackAction fallbackAction;
2793 if (initialDown) {
2794 fallbackAction = kcm.getFallbackAction(keyCode, metaState);
2795 } else {
2796 fallbackAction = mFallbackActions.get(keyCode);
2797 }
2798
2799 if (fallbackAction != null) {
Jeff Brown40013652012-05-16 21:22:36 -07002800 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002801 Slog.d(TAG, "Fallback: keyCode=" + fallbackAction.keyCode
2802 + " metaState=" + Integer.toHexString(fallbackAction.metaState));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002803 }
2804
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002805 final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK;
2806 fallbackEvent = KeyEvent.obtain(
Jeff Brown49ed71d2010-12-06 17:13:33 -08002807 event.getDownTime(), event.getEventTime(),
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002808 event.getAction(), fallbackAction.keyCode,
2809 event.getRepeatCount(), fallbackAction.metaState,
Jeff Brown49ed71d2010-12-06 17:13:33 -08002810 event.getDeviceId(), event.getScanCode(),
2811 flags, event.getSource(), null);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002812
2813 if (!interceptFallback(win, fallbackEvent, policyFlags)) {
2814 fallbackEvent.recycle();
2815 fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002816 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002817
2818 if (initialDown) {
2819 mFallbackActions.put(keyCode, fallbackAction);
2820 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2821 mFallbackActions.remove(keyCode);
2822 fallbackAction.recycle();
2823 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002824 }
2825 }
2826
Jeff Brown40013652012-05-16 21:22:36 -07002827 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002828 if (fallbackEvent == null) {
2829 Slog.d(TAG, "No fallback.");
2830 } else {
2831 Slog.d(TAG, "Performing fallback: " + fallbackEvent);
2832 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002833 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002834 return fallbackEvent;
Jeff Brown3915bb82010-11-05 15:02:16 -07002835 }
2836
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002837 private boolean interceptFallback(WindowState win, KeyEvent fallbackEvent, int policyFlags) {
Jeff Brown037c33e2014-04-09 00:31:55 -07002838 int actions = interceptKeyBeforeQueueing(fallbackEvent, policyFlags);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002839 if ((actions & ACTION_PASS_TO_USER) != 0) {
2840 long delayMillis = interceptKeyBeforeDispatching(
2841 win, fallbackEvent, policyFlags);
2842 if (delayMillis == 0) {
2843 return true;
2844 }
2845 }
2846 return false;
Jeff Brown6f2fba42011-02-19 01:08:02 -08002847 }
2848
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002849 private void launchAssistLongPressAction() {
2850 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
2851 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
2852
2853 // launch the search activity
2854 Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS);
2855 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2856 try {
RoboErik8a2cfc32014-05-16 11:19:38 -07002857 // TODO: This only stops the factory-installed search manager.
Jim Miller45308b12012-06-18 19:23:39 -07002858 // Need to formalize an API to handle others
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002859 SearchManager searchManager = getSearchManager();
2860 if (searchManager != null) {
2861 searchManager.stopSearch();
2862 }
Michael Wright43e27f72013-04-10 14:06:48 -07002863 mContext.startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002864 } catch (ActivityNotFoundException e) {
2865 Slog.w(TAG, "No activity to handle assist long press action.", e);
2866 }
2867 }
2868
2869 private void launchAssistAction() {
Michael Wright8ab940a2014-09-01 11:01:27 -07002870 launchAssistAction(null);
2871 }
2872
2873 private void launchAssistAction(String hint) {
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002874 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
Amith Yamasanic1d07a42012-08-14 09:32:02 -07002875 Intent intent = ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE))
Dianne Hackbornf9c5e0f2013-01-23 14:39:13 -08002876 .getAssistIntent(mContext, true, UserHandle.USER_CURRENT);
Jim Miller45308b12012-06-18 19:23:39 -07002877 if (intent != null) {
Michael Wright8ab940a2014-09-01 11:01:27 -07002878 if (hint != null) {
2879 intent.putExtra(hint, true);
2880 }
Jim Miller45308b12012-06-18 19:23:39 -07002881 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
2882 | Intent.FLAG_ACTIVITY_SINGLE_TOP
2883 | Intent.FLAG_ACTIVITY_CLEAR_TOP);
2884 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002885 mContext.startActivityAsUser(intent, UserHandle.CURRENT);
Jim Miller45308b12012-06-18 19:23:39 -07002886 } catch (ActivityNotFoundException e) {
2887 Slog.w(TAG, "No activity to handle assist action.", e);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002888 }
2889 }
2890 }
2891
2892 private SearchManager getSearchManager() {
2893 if (mSearchManager == null) {
2894 mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
2895 }
2896 return mSearchManager;
2897 }
2898
Jeff Browncaca8812013-05-09 13:34:33 -07002899 private void preloadRecentApps() {
2900 mPreloadedRecentApps = true;
2901 try {
2902 IStatusBarService statusbar = getStatusBarService();
2903 if (statusbar != null) {
2904 statusbar.preloadRecentApps();
2905 }
2906 } catch (RemoteException e) {
2907 Slog.e(TAG, "RemoteException when preloading recent apps", e);
2908 // re-acquire status bar service next time it is needed.
2909 mStatusBarService = null;
2910 }
2911 }
2912
2913 private void cancelPreloadRecentApps() {
2914 if (mPreloadedRecentApps) {
2915 mPreloadedRecentApps = false;
2916 try {
2917 IStatusBarService statusbar = getStatusBarService();
2918 if (statusbar != null) {
2919 statusbar.cancelPreloadRecentApps();
2920 }
2921 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002922 Slog.e(TAG, "RemoteException when cancelling recent apps preload", e);
Jeff Browncaca8812013-05-09 13:34:33 -07002923 // re-acquire status bar service next time it is needed.
2924 mStatusBarService = null;
2925 }
2926 }
2927 }
2928
2929 private void toggleRecentApps() {
2930 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
Jeff Browncaca8812013-05-09 13:34:33 -07002931 try {
2932 IStatusBarService statusbar = getStatusBarService();
2933 if (statusbar != null) {
2934 statusbar.toggleRecentApps();
2935 }
2936 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002937 Slog.e(TAG, "RemoteException when toggling recent apps", e);
2938 // re-acquire status bar service next time it is needed.
2939 mStatusBarService = null;
2940 }
2941 }
2942
Craig Mautner84984fa2014-06-19 11:19:20 -07002943 @Override
2944 public void showRecentApps() {
2945 mHandler.removeMessages(MSG_DISPATCH_SHOW_RECENTS);
2946 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_RECENTS);
2947 }
2948
Winson Chung1e8d71b2014-05-16 17:05:22 -07002949 private void showRecentApps(boolean triggeredFromAltTab) {
2950 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
2951 try {
2952 IStatusBarService statusbar = getStatusBarService();
2953 if (statusbar != null) {
2954 statusbar.showRecentApps(triggeredFromAltTab);
2955 }
2956 } catch (RemoteException e) {
Jeff Browncaca8812013-05-09 13:34:33 -07002957 Slog.e(TAG, "RemoteException when showing recent apps", e);
2958 // re-acquire status bar service next time it is needed.
2959 mStatusBarService = null;
2960 }
2961 }
2962
Winson Chungcdcd4872014-08-05 18:00:13 -07002963 private void hideRecentApps(boolean triggeredFromAltTab, boolean triggeredFromHome) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002964 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
2965 try {
2966 IStatusBarService statusbar = getStatusBarService();
2967 if (statusbar != null) {
Winson Chungcdcd4872014-08-05 18:00:13 -07002968 statusbar.hideRecentApps(triggeredFromAltTab, triggeredFromHome);
Winson Chung1e8d71b2014-05-16 17:05:22 -07002969 }
2970 } catch (RemoteException e) {
2971 Slog.e(TAG, "RemoteException when closing recent apps", e);
2972 // re-acquire status bar service next time it is needed.
2973 mStatusBarService = null;
2974 }
2975 }
2976
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002977 /**
2978 * A home key -> launch home action was detected. Take the appropriate action
2979 * given the situation with the keyguard.
2980 */
2981 void launchHomeFromHotKey() {
Jim Millerab954542014-10-10 18:21:49 -07002982 if (isKeyguardShowingAndNotOccluded()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002983 // don't launch home if keyguard showing
Jim Miller5ecd8112013-01-09 18:50:26 -08002984 } else if (!mHideLockScreen && mKeyguardDelegate.isInputRestricted()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002985 // when in keyguard restricted mode, must first verify unlock
2986 // before launching home
Jim Miller5ecd8112013-01-09 18:50:26 -08002987 mKeyguardDelegate.verifyUnlock(new OnKeyguardExitResult() {
Jose Lima9546b202014-07-02 17:21:51 -07002988 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002989 public void onKeyguardExitResult(boolean success) {
2990 if (success) {
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07002991 try {
2992 ActivityManagerNative.getDefault().stopAppSwitches();
2993 } catch (RemoteException e) {
2994 }
Joe Onoratof275f0c2009-11-24 16:11:13 -05002995 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
Bryce Lee01b0c5f2015-02-05 18:24:04 -08002996 startDockOrHome(true /*fromHomeKey*/);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002997 }
2998 }
2999 });
3000 } else {
3001 // no keyguard stuff to worry about, just launch home!
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07003002 try {
3003 ActivityManagerNative.getDefault().stopAppSwitches();
3004 } catch (RemoteException e) {
3005 }
Winson Chungd543c1b2014-06-23 15:06:45 -07003006 if (mRecentsVisible) {
3007 // Hide Recents and notify it to launch Home
3008 awakenDreams();
3009 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
Winson Chungcdcd4872014-08-05 18:00:13 -07003010 hideRecentApps(false, true);
Winson Chungd543c1b2014-06-23 15:06:45 -07003011 } else {
3012 // Otherwise, just launch Home
3013 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
Bryce Lee01b0c5f2015-02-05 18:24:04 -08003014 startDockOrHome(true /*fromHomeKey*/);
Winson Chungd543c1b2014-06-23 15:06:45 -07003015 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003016 }
3017 }
3018
John Spurlock04db1762013-05-13 12:46:41 -04003019 private final Runnable mClearHideNavigationFlag = new Runnable() {
3020 @Override
3021 public void run() {
3022 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
3023 // Clear flags.
3024 mForceClearedSystemUiFlags &=
3025 ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
3026 }
3027 mWindowManagerFuncs.reevaluateStatusBarVisibility();
Dianne Hackborne26ab702011-10-16 13:21:33 -07003028 }
3029 };
3030
3031 /**
3032 * Input handler used while nav bar is hidden. Captures any touch on the screen,
3033 * to determine when the nav bar should be shown and prevent applications from
3034 * receiving those touches.
3035 */
Jeff Brown32cbc38552011-12-01 14:01:49 -08003036 final class HideNavInputEventReceiver extends InputEventReceiver {
3037 public HideNavInputEventReceiver(InputChannel inputChannel, Looper looper) {
3038 super(inputChannel, looper);
3039 }
3040
Dianne Hackborndf89e652011-10-06 22:35:11 -07003041 @Override
Jeff Brown32cbc38552011-12-01 14:01:49 -08003042 public void onInputEvent(InputEvent event) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003043 boolean handled = false;
3044 try {
Jeff Brown4952dfd2011-11-30 19:23:22 -08003045 if (event instanceof MotionEvent
3046 && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
3047 final MotionEvent motionEvent = (MotionEvent)event;
3048 if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003049 // When the user taps down, we re-show the nav bar.
3050 boolean changed = false;
John Spurlock04db1762013-05-13 12:46:41 -04003051 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003052 // Any user activity always causes us to show the
3053 // navigation controls, if they had been hidden.
3054 // We also clear the low profile and only content
3055 // flags so that tapping on the screen will atomically
3056 // restore all currently hidden screen decorations.
3057 int newVal = mResettingSystemUiFlags |
3058 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
3059 View.SYSTEM_UI_FLAG_LOW_PROFILE |
3060 View.SYSTEM_UI_FLAG_FULLSCREEN;
Dianne Hackborne26ab702011-10-16 13:21:33 -07003061 if (mResettingSystemUiFlags != newVal) {
3062 mResettingSystemUiFlags = newVal;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003063 changed = true;
3064 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003065 // We don't allow the system's nav bar to be hidden
3066 // again for 1 second, to prevent applications from
3067 // spamming us and keeping it from being shown.
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003068 newVal = mForceClearedSystemUiFlags |
3069 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
Dianne Hackborne26ab702011-10-16 13:21:33 -07003070 if (mForceClearedSystemUiFlags != newVal) {
3071 mForceClearedSystemUiFlags = newVal;
3072 changed = true;
John Spurlock04db1762013-05-13 12:46:41 -04003073 mHandler.postDelayed(mClearHideNavigationFlag, 1000);
Dianne Hackborne26ab702011-10-16 13:21:33 -07003074 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07003075 }
3076 if (changed) {
3077 mWindowManagerFuncs.reevaluateStatusBarVisibility();
3078 }
3079 }
3080 }
3081 } finally {
Jeff Brown32cbc38552011-12-01 14:01:49 -08003082 finishInputEvent(event, handled);
Dianne Hackborndf89e652011-10-06 22:35:11 -07003083 }
3084 }
Jeff Brown32cbc38552011-12-01 14:01:49 -08003085 }
3086 final InputEventReceiver.Factory mHideNavInputEventReceiverFactory =
3087 new InputEventReceiver.Factory() {
3088 @Override
3089 public InputEventReceiver createInputEventReceiver(
3090 InputChannel inputChannel, Looper looper) {
3091 return new HideNavInputEventReceiver(inputChannel, looper);
3092 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07003093 };
3094
3095 @Override
3096 public int adjustSystemUiVisibilityLw(int visibility) {
John Spurlock5b9145b2013-08-20 15:13:47 -04003097 mStatusBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
3098 mNavigationBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
Winson Chungd42a6cf2014-06-03 16:24:04 -07003099 mRecentsVisible = (visibility & View.RECENT_APPS_VISIBLE) > 0;
John Spurlock27735a42013-08-14 17:57:38 -04003100
Dianne Hackborndf89e652011-10-06 22:35:11 -07003101 // Reset any bits in mForceClearingStatusBarVisibility that
3102 // are now clear.
Dianne Hackborne26ab702011-10-16 13:21:33 -07003103 mResettingSystemUiFlags &= visibility;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003104 // Clear any bits in the new visibility that are currently being
3105 // force cleared, before reporting it.
Dianne Hackborne26ab702011-10-16 13:21:33 -07003106 return visibility & ~mResettingSystemUiFlags
3107 & ~mForceClearedSystemUiFlags;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003108 }
3109
Craig Mautner69b08182012-09-05 13:07:13 -07003110 @Override
Adrian Roos37d7a682014-11-06 18:15:16 +01003111 public void getInsetHintLw(WindowManager.LayoutParams attrs, Rect outContentInsets,
3112 Rect outStableInsets) {
John Spurlockc6d1c602014-01-17 15:22:06 -05003113 final int fl = PolicyControl.getWindowFlags(null, attrs);
John Spurlock1db8b682014-02-18 11:18:59 -05003114 final int sysuiVis = PolicyControl.getSystemUiVisibility(null, attrs);
3115 final int systemUiVisibility = (sysuiVis | attrs.subtreeSystemUiVisibility);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003116
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003117 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003118 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003119 int availRight, availBottom;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003120 if (canHideNavigationBar() &&
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003121 (systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003122 availRight = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3123 availBottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
3124 } else {
3125 availRight = mRestrictedScreenLeft + mRestrictedScreenWidth;
3126 availBottom = mRestrictedScreenTop + mRestrictedScreenHeight;
3127 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003128 if ((systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
3129 if ((fl & FLAG_FULLSCREEN) != 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003130 outContentInsets.set(mStableFullscreenLeft, mStableFullscreenTop,
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003131 availRight - mStableFullscreenRight,
3132 availBottom - mStableFullscreenBottom);
3133 } else {
Adrian Roos37d7a682014-11-06 18:15:16 +01003134 outContentInsets.set(mStableLeft, mStableTop,
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003135 availRight - mStableRight, availBottom - mStableBottom);
3136 }
Dianne Hackbornc652de82013-02-15 16:32:56 -08003137 } else if ((fl & FLAG_FULLSCREEN) != 0 || (fl & FLAG_LAYOUT_IN_OVERSCAN) != 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003138 outContentInsets.setEmpty();
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003139 } else if ((systemUiVisibility & (View.SYSTEM_UI_FLAG_FULLSCREEN
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003140 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)) == 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003141 outContentInsets.set(mCurLeft, mCurTop,
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003142 availRight - mCurRight, availBottom - mCurBottom);
3143 } else {
Adrian Roos37d7a682014-11-06 18:15:16 +01003144 outContentInsets.set(mCurLeft, mCurTop,
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003145 availRight - mCurRight, availBottom - mCurBottom);
3146 }
Adrian Roos37d7a682014-11-06 18:15:16 +01003147
3148 outStableInsets.set(mStableLeft, mStableTop,
3149 availRight - mStableRight, availBottom - mStableBottom);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003150 return;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003151 }
Adrian Roos37d7a682014-11-06 18:15:16 +01003152 outContentInsets.setEmpty();
3153 outStableInsets.setEmpty();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003154 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003155
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003156 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07003157 @Override
3158 public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight,
3159 int displayRotation) {
Dianne Hackbornc652de82013-02-15 16:32:56 -08003160 final int overscanLeft, overscanTop, overscanRight, overscanBottom;
3161 if (isDefaultDisplay) {
3162 switch (displayRotation) {
3163 case Surface.ROTATION_90:
3164 overscanLeft = mOverscanTop;
3165 overscanTop = mOverscanRight;
3166 overscanRight = mOverscanBottom;
3167 overscanBottom = mOverscanLeft;
3168 break;
3169 case Surface.ROTATION_180:
3170 overscanLeft = mOverscanRight;
3171 overscanTop = mOverscanBottom;
3172 overscanRight = mOverscanLeft;
3173 overscanBottom = mOverscanTop;
3174 break;
3175 case Surface.ROTATION_270:
3176 overscanLeft = mOverscanBottom;
3177 overscanTop = mOverscanLeft;
3178 overscanRight = mOverscanTop;
3179 overscanBottom = mOverscanRight;
3180 break;
3181 default:
3182 overscanLeft = mOverscanLeft;
3183 overscanTop = mOverscanTop;
3184 overscanRight = mOverscanRight;
3185 overscanBottom = mOverscanBottom;
3186 break;
3187 }
3188 } else {
3189 overscanLeft = 0;
3190 overscanTop = 0;
3191 overscanRight = 0;
3192 overscanBottom = 0;
3193 }
Dianne Hackborn313440842013-02-19 19:22:59 -08003194 mOverscanScreenLeft = mRestrictedOverscanScreenLeft = 0;
3195 mOverscanScreenTop = mRestrictedOverscanScreenTop = 0;
3196 mOverscanScreenWidth = mRestrictedOverscanScreenWidth = displayWidth;
3197 mOverscanScreenHeight = mRestrictedOverscanScreenHeight = displayHeight;
Dianne Hackbornc652de82013-02-15 16:32:56 -08003198 mSystemLeft = 0;
3199 mSystemTop = 0;
3200 mSystemRight = displayWidth;
3201 mSystemBottom = displayHeight;
3202 mUnrestrictedScreenLeft = overscanLeft;
3203 mUnrestrictedScreenTop = overscanTop;
3204 mUnrestrictedScreenWidth = displayWidth - overscanLeft - overscanRight;
3205 mUnrestrictedScreenHeight = displayHeight - overscanTop - overscanBottom;
3206 mRestrictedScreenLeft = mUnrestrictedScreenLeft;
3207 mRestrictedScreenTop = mUnrestrictedScreenTop;
John Spurlockad3e6cb2013-04-30 08:47:43 -04003208 mRestrictedScreenWidth = mSystemGestures.screenWidth = mUnrestrictedScreenWidth;
3209 mRestrictedScreenHeight = mSystemGestures.screenHeight = mUnrestrictedScreenHeight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003210 mDockLeft = mContentLeft = mVoiceContentLeft = mStableLeft = mStableFullscreenLeft
Dianne Hackbornc652de82013-02-15 16:32:56 -08003211 = mCurLeft = mUnrestrictedScreenLeft;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003212 mDockTop = mContentTop = mVoiceContentTop = mStableTop = mStableFullscreenTop
Dianne Hackbornc652de82013-02-15 16:32:56 -08003213 = mCurTop = mUnrestrictedScreenTop;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003214 mDockRight = mContentRight = mVoiceContentRight = mStableRight = mStableFullscreenRight
Dianne Hackbornc652de82013-02-15 16:32:56 -08003215 = mCurRight = displayWidth - overscanRight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003216 mDockBottom = mContentBottom = mVoiceContentBottom = mStableBottom = mStableFullscreenBottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003217 = mCurBottom = displayHeight - overscanBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003218 mDockLayer = 0x10000000;
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003219 mStatusBarLayer = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003220
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003221 // start with the current dock rect, which will be (0,0,displayWidth,displayHeight)
3222 final Rect pf = mTmpParentFrame;
3223 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003224 final Rect of = mTmpOverscanFrame;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003225 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04003226 final Rect dcf = mTmpDecorFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003227 pf.left = df.left = of.left = vf.left = mDockLeft;
3228 pf.top = df.top = of.top = vf.top = mDockTop;
3229 pf.right = df.right = of.right = vf.right = mDockRight;
3230 pf.bottom = df.bottom = of.bottom = vf.bottom = mDockBottom;
John Spurlock46646232013-09-30 22:32:42 -04003231 dcf.setEmpty(); // Decor frame N/A for system bars.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003232
Craig Mautner69b08182012-09-05 13:07:13 -07003233 if (isDefaultDisplay) {
3234 // For purposes of putting out fake window up to steal focus, we will
3235 // drive nav being hidden only by whether it is requested.
John Spurlocke1f366f2013-08-05 12:22:40 -04003236 final int sysui = mLastSystemUiFlags;
3237 boolean navVisible = (sysui & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0;
Adrian Roosea562512014-05-05 13:33:03 +02003238 boolean navTranslucent = (sysui
3239 & (View.NAVIGATION_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04003240 boolean immersive = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
3241 boolean immersiveSticky = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
3242 boolean navAllowedHidden = immersive || immersiveSticky;
3243 navTranslucent &= !immersiveSticky; // transient trumps translucent
Adrian Roos4fb3ee32014-08-22 19:29:09 +02003244 boolean isKeyguardShowing = isStatusBarKeyguard() && !mHideLockScreen;
3245 if (!isKeyguardShowing) {
3246 navTranslucent &= areTranslucentBarsAllowed();
3247 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003248
Craig Mautner69b08182012-09-05 13:07:13 -07003249 // When the navigation bar isn't visible, we put up a fake
3250 // input window to catch all touch events. This way we can
3251 // detect when the user presses anywhere to bring back the nav
3252 // bar and ensure the application doesn't see the event.
John Spurlockf1a36642013-10-12 17:50:42 -04003253 if (navVisible || navAllowedHidden) {
Craig Mautner69b08182012-09-05 13:07:13 -07003254 if (mHideNavFakeWindow != null) {
3255 mHideNavFakeWindow.dismiss();
3256 mHideNavFakeWindow = null;
3257 }
3258 } else if (mHideNavFakeWindow == null) {
3259 mHideNavFakeWindow = mWindowManagerFuncs.addFakeWindow(
3260 mHandler.getLooper(), mHideNavInputEventReceiverFactory,
Adam Lesinski95c42972013-10-02 10:13:27 -07003261 "hidden nav", WindowManager.LayoutParams.TYPE_HIDDEN_NAV_CONSUMER, 0,
Craig Mautner69b08182012-09-05 13:07:13 -07003262 0, false, false, true);
Dianne Hackborne26ab702011-10-16 13:21:33 -07003263 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003264
Craig Mautner69b08182012-09-05 13:07:13 -07003265 // For purposes of positioning and showing the nav bar, if we have
3266 // decided that it can't be hidden (because of the screen aspect ratio),
3267 // then take that into account.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003268 navVisible |= !canHideNavigationBar();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003269
John Spurlockad3e6cb2013-04-30 08:47:43 -04003270 boolean updateSysUiVisibility = false;
Craig Mautner69b08182012-09-05 13:07:13 -07003271 if (mNavigationBar != null) {
John Spurlock27735a42013-08-14 17:57:38 -04003272 boolean transientNavBarShowing = mNavigationBarController.isTransientShowing();
Craig Mautner69b08182012-09-05 13:07:13 -07003273 // Force the navigation bar to its appropriate place and
3274 // size. We need to do this directly, instead of relying on
3275 // it to bubble up from the nav bar, because this needs to
3276 // change atomically with screen rotations.
3277 mNavigationBarOnBottom = (!mNavigationBarCanMove || displayWidth < displayHeight);
3278 if (mNavigationBarOnBottom) {
3279 // It's a system nav bar or a portrait screen; nav bar goes on bottom.
Dianne Hackbornc652de82013-02-15 16:32:56 -08003280 int top = displayHeight - overscanBottom
3281 - mNavigationBarHeightForRotation[displayRotation];
3282 mTmpNavigationFrame.set(0, top, displayWidth, displayHeight - overscanBottom);
Craig Mautner69b08182012-09-05 13:07:13 -07003283 mStableBottom = mStableFullscreenBottom = mTmpNavigationFrame.top;
John Spurlockf95b89a2013-10-10 22:10:42 -04003284 if (transientNavBarShowing) {
John Spurlock27735a42013-08-14 17:57:38 -04003285 mNavigationBarController.setBarShowingLw(true);
John Spurlockad3e6cb2013-04-30 08:47:43 -04003286 } else if (navVisible) {
John Spurlock27735a42013-08-14 17:57:38 -04003287 mNavigationBarController.setBarShowingLw(true);
Craig Mautner69b08182012-09-05 13:07:13 -07003288 mDockBottom = mTmpNavigationFrame.top;
Dianne Hackborn313440842013-02-19 19:22:59 -08003289 mRestrictedScreenHeight = mDockBottom - mRestrictedScreenTop;
3290 mRestrictedOverscanScreenHeight = mDockBottom - mRestrictedOverscanScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07003291 } else {
3292 // We currently want to hide the navigation UI.
John Spurlock27735a42013-08-14 17:57:38 -04003293 mNavigationBarController.setBarShowingLw(false);
Craig Mautner69b08182012-09-05 13:07:13 -07003294 }
John Spurlockc6d1c602014-01-17 15:22:06 -05003295 if (navVisible && !navTranslucent && !navAllowedHidden
3296 && !mNavigationBar.isAnimatingLw()
John Spurlockbd957402013-10-03 11:38:39 -04003297 && !mNavigationBarController.wasRecentlyTranslucent()) {
John Spurlocke1f366f2013-08-05 12:22:40 -04003298 // If the opaque nav bar is currently requested to be visible,
Craig Mautner69b08182012-09-05 13:07:13 -07003299 // and not in the process of animating on or off, then
3300 // we can tell the app that it is covered by it.
3301 mSystemBottom = mTmpNavigationFrame.top;
3302 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003303 } else {
Craig Mautner69b08182012-09-05 13:07:13 -07003304 // Landscape screen; nav bar goes to the right.
Dianne Hackbornc652de82013-02-15 16:32:56 -08003305 int left = displayWidth - overscanRight
3306 - mNavigationBarWidthForRotation[displayRotation];
3307 mTmpNavigationFrame.set(left, 0, displayWidth - overscanRight, displayHeight);
Craig Mautner69b08182012-09-05 13:07:13 -07003308 mStableRight = mStableFullscreenRight = mTmpNavigationFrame.left;
John Spurlockf95b89a2013-10-10 22:10:42 -04003309 if (transientNavBarShowing) {
John Spurlock27735a42013-08-14 17:57:38 -04003310 mNavigationBarController.setBarShowingLw(true);
John Spurlockad3e6cb2013-04-30 08:47:43 -04003311 } else if (navVisible) {
John Spurlock27735a42013-08-14 17:57:38 -04003312 mNavigationBarController.setBarShowingLw(true);
Craig Mautner69b08182012-09-05 13:07:13 -07003313 mDockRight = mTmpNavigationFrame.left;
Dianne Hackborn313440842013-02-19 19:22:59 -08003314 mRestrictedScreenWidth = mDockRight - mRestrictedScreenLeft;
3315 mRestrictedOverscanScreenWidth = mDockRight - mRestrictedOverscanScreenLeft;
Craig Mautner69b08182012-09-05 13:07:13 -07003316 } else {
3317 // We currently want to hide the navigation UI.
John Spurlock27735a42013-08-14 17:57:38 -04003318 mNavigationBarController.setBarShowingLw(false);
Craig Mautner69b08182012-09-05 13:07:13 -07003319 }
John Spurlockbd957402013-10-03 11:38:39 -04003320 if (navVisible && !navTranslucent && !mNavigationBar.isAnimatingLw()
3321 && !mNavigationBarController.wasRecentlyTranslucent()) {
Craig Mautner69b08182012-09-05 13:07:13 -07003322 // If the nav bar is currently requested to be visible,
3323 // and not in the process of animating on or off, then
3324 // we can tell the app that it is covered by it.
3325 mSystemRight = mTmpNavigationFrame.left;
3326 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003327 }
Craig Mautner69b08182012-09-05 13:07:13 -07003328 // Make sure the content and current rectangles are updated to
3329 // account for the restrictions from the navigation bar.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003330 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3331 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3332 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3333 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
Craig Mautner69b08182012-09-05 13:07:13 -07003334 mStatusBarLayer = mNavigationBar.getSurfaceLayer();
3335 // And compute the final frame.
3336 mNavigationBar.computeFrameLw(mTmpNavigationFrame, mTmpNavigationFrame,
Adrian Roosfa104232014-06-20 16:10:14 -07003337 mTmpNavigationFrame, mTmpNavigationFrame, mTmpNavigationFrame, dcf,
3338 mTmpNavigationFrame);
Craig Mautnereda67292013-04-28 13:50:14 -07003339 if (DEBUG_LAYOUT) Slog.i(TAG, "mNavigationBar frame: " + mTmpNavigationFrame);
John Spurlock27735a42013-08-14 17:57:38 -04003340 if (mNavigationBarController.checkHiddenLw()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04003341 updateSysUiVisibility = true;
3342 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003343 }
Craig Mautnereda67292013-04-28 13:50:14 -07003344 if (DEBUG_LAYOUT) Slog.i(TAG, String.format("mDock rect: (%d,%d - %d,%d)",
Craig Mautner69b08182012-09-05 13:07:13 -07003345 mDockLeft, mDockTop, mDockRight, mDockBottom));
3346
3347 // decide where the status bar goes ahead of time
3348 if (mStatusBar != null) {
3349 // apply any navigation bar insets
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003350 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3351 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3352 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
3353 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight
3354 + mUnrestrictedScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07003355 vf.left = mStableLeft;
3356 vf.top = mStableTop;
3357 vf.right = mStableRight;
3358 vf.bottom = mStableBottom;
3359
3360 mStatusBarLayer = mStatusBar.getSurfaceLayer();
3361
3362 // Let the status bar determine its size.
Adrian Roosfa104232014-06-20 16:10:14 -07003363 mStatusBar.computeFrameLw(pf, df, vf, vf, vf, dcf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07003364
3365 // For layout, the status bar is always at the top with our fixed height.
3366 mStableTop = mUnrestrictedScreenTop + mStatusBarHeight;
3367
John Spurlocke1f366f2013-08-05 12:22:40 -04003368 boolean statusBarTransient = (sysui & View.STATUS_BAR_TRANSIENT) != 0;
Adrian Roosea562512014-05-05 13:33:03 +02003369 boolean statusBarTranslucent = (sysui
3370 & (View.STATUS_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0;
Adrian Roos4fb3ee32014-08-22 19:29:09 +02003371 if (!isKeyguardShowing) {
3372 statusBarTranslucent &= areTranslucentBarsAllowed();
3373 }
John Spurlock32beb2c2013-03-11 10:16:47 -04003374
Craig Mautner69b08182012-09-05 13:07:13 -07003375 // If the status bar is hidden, we don't want to cause
3376 // windows behind it to scroll.
John Spurlockeda1f692013-09-16 11:38:44 -04003377 if (mStatusBar.isVisibleLw() && !statusBarTransient) {
Craig Mautner69b08182012-09-05 13:07:13 -07003378 // Status bar may go away, so the screen area it occupies
3379 // is available to apps but just covering them when the
3380 // status bar is visible.
3381 mDockTop = mUnrestrictedScreenTop + mStatusBarHeight;
3382
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003383 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3384 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3385 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3386 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
Craig Mautner69b08182012-09-05 13:07:13 -07003387
Craig Mautnereda67292013-04-28 13:50:14 -07003388 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar: " +
Craig Mautner69b08182012-09-05 13:07:13 -07003389 String.format(
3390 "dock=[%d,%d][%d,%d] content=[%d,%d][%d,%d] cur=[%d,%d][%d,%d]",
3391 mDockLeft, mDockTop, mDockRight, mDockBottom,
3392 mContentLeft, mContentTop, mContentRight, mContentBottom,
3393 mCurLeft, mCurTop, mCurRight, mCurBottom));
3394 }
John Spurlocke1f366f2013-08-05 12:22:40 -04003395 if (mStatusBar.isVisibleLw() && !mStatusBar.isAnimatingLw()
John Spurlockbd957402013-10-03 11:38:39 -04003396 && !statusBarTransient && !statusBarTranslucent
3397 && !mStatusBarController.wasRecentlyTranslucent()) {
John Spurlocke1f366f2013-08-05 12:22:40 -04003398 // If the opaque status bar is currently requested to be visible,
Craig Mautner69b08182012-09-05 13:07:13 -07003399 // and not in the process of animating on or off, then
3400 // we can tell the app that it is covered by it.
3401 mSystemTop = mUnrestrictedScreenTop + mStatusBarHeight;
3402 }
John Spurlock27735a42013-08-14 17:57:38 -04003403 if (mStatusBarController.checkHiddenLw()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04003404 updateSysUiVisibility = true;
John Spurlock32beb2c2013-03-11 10:16:47 -04003405 }
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003406 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04003407 if (updateSysUiVisibility) {
3408 updateSystemUiVisibilityLw();
3409 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003410 }
3411 }
3412
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003413 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07003414 @Override
John Spurlock46646232013-09-30 22:32:42 -04003415 public int getSystemDecorLayerLw() {
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003416 if (mStatusBar != null) return mStatusBar.getSurfaceLayer();
3417 if (mNavigationBar != null) return mNavigationBar.getSurfaceLayer();
3418 return 0;
3419 }
3420
Craig Mautner967212c2013-04-13 21:10:58 -07003421 @Override
3422 public void getContentRectLw(Rect r) {
3423 r.set(mContentLeft, mContentTop, mContentRight, mContentBottom);
3424 }
3425
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003426 void setAttachedWindowFrames(WindowState win, int fl, int adjust, WindowState attached,
3427 boolean insetDecors, Rect pf, Rect df, Rect of, Rect cf, Rect vf) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003428 if (win.getSurfaceLayer() > mDockLayer && attached.getSurfaceLayer() < mDockLayer) {
3429 // Here's a special case: if this attached window is a panel that is
3430 // above the dock window, and the window it is attached to is below
3431 // the dock window, then the frames we computed for the window it is
3432 // attached to can not be used because the dock is effectively part
3433 // of the underlying window and the attached window is floating on top
3434 // of the whole thing. So, we ignore the attached window and explicitly
3435 // compute the frames that would be appropriate without the dock.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003436 df.left = of.left = cf.left = vf.left = mDockLeft;
3437 df.top = of.top = cf.top = vf.top = mDockTop;
3438 df.right = of.right = cf.right = vf.right = mDockRight;
3439 df.bottom = of.bottom = cf.bottom = vf.bottom = mDockBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003440 } else {
3441 // The effective display frame of the attached window depends on
3442 // whether it is taking care of insetting its content. If not,
3443 // we need to use the parent's content frame so that the entire
3444 // window is positioned within that content. Otherwise we can use
Wale Ogunwale393b1c12014-10-18 16:22:01 -07003445 // the overscan frame and let the attached window take care of
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003446 // positioning its content appropriately.
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003447 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Wale Ogunwale393b1c12014-10-18 16:22:01 -07003448 // Set the content frame of the attached window to the parent's decor frame
3449 // (same as content frame when IME isn't present) if specifically requested by
3450 // setting {@link WindowManager.LayoutParams#FLAG_LAYOUT_ATTACHED_IN_DECOR} flag.
3451 // Otherwise, use the overscan frame.
3452 cf.set((fl & FLAG_LAYOUT_ATTACHED_IN_DECOR) != 0
3453 ? attached.getContentFrameLw() : attached.getOverscanFrameLw());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003454 } else {
3455 // If the window is resizing, then we want to base the content
3456 // frame on our attached content frame to resize... however,
3457 // things can be tricky if the attached window is NOT in resize
3458 // mode, in which case its content frame will be larger.
3459 // Ungh. So to deal with that, make sure the content frame
3460 // we end up using is not covering the IM dock.
3461 cf.set(attached.getContentFrameLw());
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003462 if (attached.isVoiceInteraction()) {
3463 if (cf.left < mVoiceContentLeft) cf.left = mVoiceContentLeft;
3464 if (cf.top < mVoiceContentTop) cf.top = mVoiceContentTop;
3465 if (cf.right > mVoiceContentRight) cf.right = mVoiceContentRight;
3466 if (cf.bottom > mVoiceContentBottom) cf.bottom = mVoiceContentBottom;
3467 } else if (attached.getSurfaceLayer() < mDockLayer) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003468 if (cf.left < mContentLeft) cf.left = mContentLeft;
3469 if (cf.top < mContentTop) cf.top = mContentTop;
3470 if (cf.right > mContentRight) cf.right = mContentRight;
3471 if (cf.bottom > mContentBottom) cf.bottom = mContentBottom;
3472 }
3473 }
3474 df.set(insetDecors ? attached.getDisplayFrameLw() : cf);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003475 of.set(insetDecors ? attached.getOverscanFrameLw() : cf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003476 vf.set(attached.getVisibleFrameLw());
3477 }
3478 // The LAYOUT_IN_SCREEN flag is used to determine whether the attached
3479 // window should be positioned relative to its parent or the entire
3480 // screen.
3481 pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0
3482 ? attached.getFrameLw() : df);
3483 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003484
3485 private void applyStableConstraints(int sysui, int fl, Rect r) {
3486 if ((sysui & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
3487 // If app is requesting a stable layout, don't let the
3488 // content insets go below the stable values.
3489 if ((fl & FLAG_FULLSCREEN) != 0) {
3490 if (r.left < mStableFullscreenLeft) r.left = mStableFullscreenLeft;
3491 if (r.top < mStableFullscreenTop) r.top = mStableFullscreenTop;
3492 if (r.right > mStableFullscreenRight) r.right = mStableFullscreenRight;
3493 if (r.bottom > mStableFullscreenBottom) r.bottom = mStableFullscreenBottom;
3494 } else {
3495 if (r.left < mStableLeft) r.left = mStableLeft;
3496 if (r.top < mStableTop) r.top = mStableTop;
3497 if (r.right > mStableRight) r.right = mStableRight;
3498 if (r.bottom > mStableBottom) r.bottom = mStableBottom;
3499 }
3500 }
3501 }
3502
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003503 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07003504 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003505 public void layoutWindowLw(WindowState win, WindowState attached) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003506 // we've already done the status bar
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003507 final WindowManager.LayoutParams attrs = win.getAttrs();
3508 if ((win == mStatusBar && (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) == 0) ||
3509 win == mNavigationBar) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003510 return;
3511 }
Craig Mautner69b08182012-09-05 13:07:13 -07003512 final boolean isDefaultDisplay = win.isDefaultDisplay();
3513 final boolean needsToOffsetInputMethodTarget = isDefaultDisplay &&
satok1bc0a492012-04-25 22:47:12 +09003514 (win == mLastInputMethodTargetWindow && mLastInputMethodWindow != null);
3515 if (needsToOffsetInputMethodTarget) {
Craig Mautnereda67292013-04-28 13:50:14 -07003516 if (DEBUG_LAYOUT) Slog.i(TAG, "Offset ime target window by the last ime window state");
satok1bc0a492012-04-25 22:47:12 +09003517 offsetInputMethodWindowLw(mLastInputMethodWindow);
3518 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003519
John Spurlockc6d1c602014-01-17 15:22:06 -05003520 final int fl = PolicyControl.getWindowFlags(win, attrs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003521 final int sim = attrs.softInputMode;
John Spurlock1db8b682014-02-18 11:18:59 -05003522 final int sysUiFl = PolicyControl.getSystemUiVisibility(win, null);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003523
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003524 final Rect pf = mTmpParentFrame;
3525 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003526 final Rect of = mTmpOverscanFrame;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003527 final Rect cf = mTmpContentFrame;
3528 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04003529 final Rect dcf = mTmpDecorFrame;
Adrian Roosfa104232014-06-20 16:10:14 -07003530 final Rect sf = mTmpStableFrame;
John Spurlock46646232013-09-30 22:32:42 -04003531 dcf.setEmpty();
Craig Mautner69b08182012-09-05 13:07:13 -07003532
3533 final boolean hasNavBar = (isDefaultDisplay && mHasNavigationBar
Daniel Sandler36412a72011-08-04 09:35:13 -04003534 && mNavigationBar != null && mNavigationBar.isVisibleLw());
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003535
Craig Mautnerf683b562012-10-02 11:10:57 -07003536 final int adjust = sim & SOFT_INPUT_MASK_ADJUST;
3537
Adrian Roosfa104232014-06-20 16:10:14 -07003538 if (isDefaultDisplay) {
3539 sf.set(mStableLeft, mStableTop, mStableRight, mStableBottom);
3540 } else {
3541 sf.set(mOverscanLeft, mOverscanTop, mOverscanRight, mOverscanBottom);
3542 }
3543
Craig Mautner69b08182012-09-05 13:07:13 -07003544 if (!isDefaultDisplay) {
3545 if (attached != null) {
3546 // If this window is attached to another, our display
3547 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003548 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07003549 } else {
3550 // Give the window full screen.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003551 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3552 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3553 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08003554 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003555 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003556 = mOverscanScreenTop + mOverscanScreenHeight;
Craig Mautner69b08182012-09-05 13:07:13 -07003557 }
Dianne Hackbornae6688b2015-02-11 17:02:41 -08003558 } else if (attrs.type == TYPE_INPUT_METHOD || attrs.type == TYPE_VOICE_INTERACTION) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003559 pf.left = df.left = of.left = cf.left = vf.left = mDockLeft;
3560 pf.top = df.top = of.top = cf.top = vf.top = mDockTop;
3561 pf.right = df.right = of.right = cf.right = vf.right = mDockRight;
John Spurlockc68d5772013-10-08 11:47:58 -04003562 // IM dock windows layout below the nav bar...
John Spurlock57beb3b2013-10-10 10:27:44 -04003563 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlockc68d5772013-10-08 11:47:58 -04003564 // ...with content insets above the nav bar
3565 cf.bottom = vf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003566 // IM dock windows always go to the bottom of the screen.
3567 attrs.gravity = Gravity.BOTTOM;
3568 mDockLayer = win.getSurfaceLayer();
Jorim Jaggie0700182014-08-21 01:12:37 +02003569 } else if (win == mStatusBar && (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
3570 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3571 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3572 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
3573 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight + mUnrestrictedScreenTop;
3574 cf.left = vf.left = mStableLeft;
3575 cf.top = vf.top = mStableTop;
3576 cf.right = vf.right = mStableRight;
3577 vf.bottom = mStableBottom;
3578 cf.bottom = mContentBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003579 } else {
John Spurlock46646232013-09-30 22:32:42 -04003580
3581 // Default policy decor for the default display
3582 dcf.left = mSystemLeft;
3583 dcf.top = mSystemTop;
3584 dcf.right = mSystemRight;
3585 dcf.bottom = mSystemBottom;
John Spurlockbd957402013-10-03 11:38:39 -04003586 final boolean inheritTranslucentDecor = (attrs.privateFlags
3587 & WindowManager.LayoutParams.PRIVATE_FLAG_INHERIT_TRANSLUCENT_DECOR) != 0;
John Spurlock65567d42013-10-08 10:08:32 -04003588 final boolean isAppWindow =
3589 attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW &&
3590 attrs.type <= WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
3591 final boolean topAtRest =
3592 win == mTopFullscreenOpaqueWindowState && !win.isAnimatingLw();
3593 if (isAppWindow && !inheritTranslucentDecor && !topAtRest) {
John Spurlockbd957402013-10-03 11:38:39 -04003594 if ((sysUiFl & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0
3595 && (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0
Adrian Roosea562512014-05-05 13:33:03 +02003596 && (fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) == 0
3597 && (fl & WindowManager.LayoutParams.
3598 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04003599 // Ensure policy decor includes status bar
3600 dcf.top = mStableTop;
3601 }
John Spurlockbd957402013-10-03 11:38:39 -04003602 if ((fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) == 0
Adrian Roosea562512014-05-05 13:33:03 +02003603 && (sysUiFl & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0
3604 && (fl & WindowManager.LayoutParams.
3605 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04003606 // Ensure policy decor includes navigation bar
3607 dcf.bottom = mStableBottom;
3608 dcf.right = mStableRight;
3609 }
3610 }
3611
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003612 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
3613 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
RoboErik8a2cfc32014-05-16 11:19:38 -07003614 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003615 + "): IN_SCREEN, INSET_DECOR");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003616 // This is the case for a normal activity window: we want it
3617 // to cover all of the screen space, and it can take care of
3618 // moving its contents to account for screen decorations that
3619 // intrude into that space.
3620 if (attached != null) {
3621 // If this window is attached to another, our display
3622 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003623 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003624 } else {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003625 if (attrs.type == TYPE_STATUS_BAR_PANEL
3626 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Joe Onorato29fc2c92010-11-24 10:26:50 -08003627 // Status bar panels are the only windows who can go on top of
3628 // the status bar. They are protected by the STATUS_BAR_SERVICE
3629 // permission, so they have the same privileges as the status
3630 // bar itself.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003631 //
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003632 // However, they should still dodge the navigation bar if it exists.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003633
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003634 pf.left = df.left = of.left = hasNavBar
3635 ? mDockLeft : mUnrestrictedScreenLeft;
3636 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3637 pf.right = df.right = of.right = hasNavBar
3638 ? mRestrictedScreenLeft+mRestrictedScreenWidth
3639 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3640 pf.bottom = df.bottom = of.bottom = hasNavBar
3641 ? mRestrictedScreenTop+mRestrictedScreenHeight
3642 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003643
Craig Mautnereda67292013-04-28 13:50:14 -07003644 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003645 "Laying out status bar window: (%d,%d - %d,%d)",
3646 pf.left, pf.top, pf.right, pf.bottom));
John Spurlock46646232013-09-30 22:32:42 -04003647 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08003648 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3649 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3650 // Asking to layout into the overscan region, so give it that pure
3651 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003652 pf.left = df.left = of.left = mOverscanScreenLeft;
3653 pf.top = df.top = of.top = mOverscanScreenTop;
3654 pf.right = df.right = of.right = mOverscanScreenLeft + mOverscanScreenWidth;
3655 pf.bottom = df.bottom = of.bottom = mOverscanScreenTop
3656 + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003657 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003658 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003659 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3660 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003661 // Asking for layout as if the nav bar is hidden, lets the
Dianne Hackbornc652de82013-02-15 16:32:56 -08003662 // application extend into the unrestricted overscan screen area. We
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003663 // only do this for application windows to ensure no window that
3664 // can be above the nav bar can do this.
Dianne Hackborn313440842013-02-19 19:22:59 -08003665 pf.left = df.left = mOverscanScreenLeft;
3666 pf.top = df.top = mOverscanScreenTop;
3667 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
3668 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003669 // We need to tell the app about where the frame inside the overscan
3670 // is, so it can inset its content by that amount -- it didn't ask
3671 // to actually extend itself into the overscan region.
3672 of.left = mUnrestrictedScreenLeft;
3673 of.top = mUnrestrictedScreenTop;
3674 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3675 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003676 } else {
Dianne Hackborn313440842013-02-19 19:22:59 -08003677 pf.left = df.left = mRestrictedOverscanScreenLeft;
3678 pf.top = df.top = mRestrictedOverscanScreenTop;
3679 pf.right = df.right = mRestrictedOverscanScreenLeft
3680 + mRestrictedOverscanScreenWidth;
3681 pf.bottom = df.bottom = mRestrictedOverscanScreenTop
3682 + mRestrictedOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003683 // We need to tell the app about where the frame inside the overscan
3684 // is, so it can inset its content by that amount -- it didn't ask
3685 // to actually extend itself into the overscan region.
3686 of.left = mUnrestrictedScreenLeft;
3687 of.top = mUnrestrictedScreenTop;
3688 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3689 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003690 }
Craig Mautner69b08182012-09-05 13:07:13 -07003691
John Spurlock46646232013-09-30 22:32:42 -04003692 if ((fl & FLAG_FULLSCREEN) == 0) {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003693 if (win.isVoiceInteraction()) {
3694 cf.left = mVoiceContentLeft;
3695 cf.top = mVoiceContentTop;
3696 cf.right = mVoiceContentRight;
3697 cf.bottom = mVoiceContentBottom;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003698 } else {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003699 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
3700 cf.left = mDockLeft;
3701 cf.top = mDockTop;
3702 cf.right = mDockRight;
3703 cf.bottom = mDockBottom;
3704 } else {
3705 cf.left = mContentLeft;
3706 cf.top = mContentTop;
3707 cf.right = mContentRight;
3708 cf.bottom = mContentBottom;
3709 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003710 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003711 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003712 // Full screen windows are always given a layout that is as if the
3713 // status bar and other transient decors are gone. This is to avoid
3714 // bad states when moving from a window that is not hding the
3715 // status bar to one that is.
3716 cf.left = mRestrictedScreenLeft;
3717 cf.top = mRestrictedScreenTop;
3718 cf.right = mRestrictedScreenLeft + mRestrictedScreenWidth;
3719 cf.bottom = mRestrictedScreenTop + mRestrictedScreenHeight;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003720 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003721 applyStableConstraints(sysUiFl, fl, cf);
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003722 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3723 vf.left = mCurLeft;
3724 vf.top = mCurTop;
3725 vf.right = mCurRight;
3726 vf.bottom = mCurBottom;
3727 } else {
3728 vf.set(cf);
3729 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003730 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003731 } else if ((fl & FLAG_LAYOUT_IN_SCREEN) != 0 || (sysUiFl
3732 & (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
3733 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)) != 0) {
Craig Mautnereda67292013-04-28 13:50:14 -07003734 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3735 "): IN_SCREEN");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003736 // A window that has requested to fill the entire screen just
3737 // gets everything, period.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003738 if (attrs.type == TYPE_STATUS_BAR_PANEL
3739 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003740 pf.left = df.left = of.left = cf.left = hasNavBar
3741 ? mDockLeft : mUnrestrictedScreenLeft;
3742 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
3743 pf.right = df.right = of.right = cf.right = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003744 ? mRestrictedScreenLeft+mRestrictedScreenWidth
Dianne Hackbornc652de82013-02-15 16:32:56 -08003745 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003746 pf.bottom = df.bottom = of.bottom = cf.bottom = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003747 ? mRestrictedScreenTop+mRestrictedScreenHeight
Dianne Hackbornc652de82013-02-15 16:32:56 -08003748 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07003749 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler36412a72011-08-04 09:35:13 -04003750 "Laying out IN_SCREEN status bar window: (%d,%d - %d,%d)",
3751 pf.left, pf.top, pf.right, pf.bottom));
Jim Millere898ac52012-04-06 17:10:57 -07003752 } else if (attrs.type == TYPE_NAVIGATION_BAR
3753 || attrs.type == TYPE_NAVIGATION_BAR_PANEL) {
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003754 // The navigation bar has Real Ultimate Power.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003755 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3756 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3757 pf.right = df.right = of.right = mUnrestrictedScreenLeft
3758 + mUnrestrictedScreenWidth;
3759 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop
3760 + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07003761 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003762 "Laying out navigation bar window: (%d,%d - %d,%d)",
3763 pf.left, pf.top, pf.right, pf.bottom));
Dianne Hackborn01011c32012-02-21 13:54:21 -08003764 } else if ((attrs.type == TYPE_SECURE_SYSTEM_OVERLAY
3765 || attrs.type == TYPE_BOOT_PROGRESS)
Jeff Brownbfcb60a2011-09-08 18:51:14 -07003766 && ((fl & FLAG_FULLSCREEN) != 0)) {
3767 // Fullscreen secure system overlays get what they ask for.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003768 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3769 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3770 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
3771 + mOverscanScreenWidth;
3772 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
3773 + mOverscanScreenHeight;
Craig Mautner165be0c2015-01-27 15:16:58 -08003774 } else if (attrs.type == TYPE_BOOT_PROGRESS) {
Dianne Hackborn01011c32012-02-21 13:54:21 -08003775 // Boot progress screen always covers entire display.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003776 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3777 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3778 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
3779 + mOverscanScreenWidth;
3780 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
3781 + mOverscanScreenHeight;
John Spurlockef4adae2013-08-26 17:58:58 -04003782 } else if (attrs.type == TYPE_WALLPAPER) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07003783 // The wallpaper also has Real Ultimate Power, but we want to tell
3784 // it about the overscan area.
3785 pf.left = df.left = mOverscanScreenLeft;
3786 pf.top = df.top = mOverscanScreenTop;
3787 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
3788 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
3789 of.left = cf.left = mUnrestrictedScreenLeft;
3790 of.top = cf.top = mUnrestrictedScreenTop;
3791 of.right = cf.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3792 of.bottom = cf.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlock46646232013-09-30 22:32:42 -04003793 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08003794 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3795 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3796 // Asking to layout into the overscan region, so give it that pure
3797 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003798 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3799 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3800 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08003801 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003802 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003803 = mOverscanScreenTop + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003804 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003805 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Craig Mautnerbeac1062014-06-03 14:38:57 -07003806 && (attrs.type == TYPE_STATUS_BAR
3807 || attrs.type == TYPE_TOAST
John Spurlock34e13d92013-08-10 06:52:28 -04003808 || (attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3809 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW))) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003810 // Asking for layout as if the nav bar is hidden, lets the
3811 // application extend into the unrestricted screen area. We
John Spurlock34e13d92013-08-10 06:52:28 -04003812 // only do this for application windows (or toasts) to ensure no window that
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003813 // can be above the nav bar can do this.
3814 // XXX This assumes that an app asking for this will also
3815 // ask for layout in only content. We can't currently figure out
3816 // what the screen would be if only laying out to hide the nav bar.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003817 pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft;
3818 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
3819 pf.right = df.right = of.right = cf.right = mUnrestrictedScreenLeft
3820 + mUnrestrictedScreenWidth;
3821 pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop
3822 + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003823 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003824 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
3825 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
3826 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
3827 + mRestrictedScreenWidth;
3828 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
3829 + mRestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003830 }
Craig Mautner69b08182012-09-05 13:07:13 -07003831
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003832 applyStableConstraints(sysUiFl, fl, cf);
Craig Mautner69b08182012-09-05 13:07:13 -07003833
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003834 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3835 vf.left = mCurLeft;
3836 vf.top = mCurTop;
3837 vf.right = mCurRight;
3838 vf.bottom = mCurBottom;
3839 } else {
3840 vf.set(cf);
3841 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003842 } else if (attached != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07003843 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3844 "): attached to " + attached);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003845 // A child window should be placed inside of the same visible
3846 // frame that its parent had.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003847 setAttachedWindowFrames(win, fl, adjust, attached, false, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003848 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07003849 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3850 "): normal window");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003851 // Otherwise, a normal window must be placed inside the content
3852 // of all screen decorations.
Dianne Hackborna239c842011-06-01 12:28:20 -07003853 if (attrs.type == TYPE_STATUS_BAR_PANEL) {
3854 // Status bar panels are the only windows who can go on top of
3855 // the status bar. They are protected by the STATUS_BAR_SERVICE
3856 // permission, so they have the same privileges as the status
3857 // bar itself.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003858 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
3859 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
3860 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
3861 + mRestrictedScreenWidth;
3862 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
3863 + mRestrictedScreenHeight;
John Spurlock414c1f02013-12-04 13:47:36 -05003864 } else if (attrs.type == TYPE_TOAST || attrs.type == TYPE_SYSTEM_ALERT
3865 || attrs.type == TYPE_VOLUME_OVERLAY) {
3866 // These dialogs are stable to interim decor changes.
John Spurlockbd957402013-10-03 11:38:39 -04003867 pf.left = df.left = of.left = cf.left = mStableLeft;
3868 pf.top = df.top = of.top = cf.top = mStableTop;
3869 pf.right = df.right = of.right = cf.right = mStableRight;
3870 pf.bottom = df.bottom = of.bottom = cf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003871 } else {
Dianne Hackborna239c842011-06-01 12:28:20 -07003872 pf.left = mContentLeft;
3873 pf.top = mContentTop;
3874 pf.right = mContentRight;
3875 pf.bottom = mContentBottom;
Dianne Hackborn20d94742014-05-29 18:35:45 -07003876 if (win.isVoiceInteraction()) {
3877 df.left = of.left = cf.left = mVoiceContentLeft;
3878 df.top = of.top = cf.top = mVoiceContentTop;
3879 df.right = of.right = cf.right = mVoiceContentRight;
3880 df.bottom = of.bottom = cf.bottom = mVoiceContentBottom;
3881 } else if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003882 df.left = of.left = cf.left = mDockLeft;
3883 df.top = of.top = cf.top = mDockTop;
3884 df.right = of.right = cf.right = mDockRight;
3885 df.bottom = of.bottom = cf.bottom = mDockBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07003886 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003887 df.left = of.left = cf.left = mContentLeft;
3888 df.top = of.top = cf.top = mContentTop;
3889 df.right = of.right = cf.right = mContentRight;
3890 df.bottom = of.bottom = cf.bottom = mContentBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07003891 }
3892 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3893 vf.left = mCurLeft;
3894 vf.top = mCurTop;
3895 vf.right = mCurRight;
3896 vf.bottom = mCurBottom;
3897 } else {
3898 vf.set(cf);
3899 }
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003900 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003901 }
3902 }
Craig Mautner69b08182012-09-05 13:07:13 -07003903
Craig Mautnerb816bed2013-07-23 10:26:17 -07003904 // TYPE_SYSTEM_ERROR is above the NavigationBar so it can't be allowed to extend over it.
3905 if ((fl & FLAG_LAYOUT_NO_LIMITS) != 0 && attrs.type != TYPE_SYSTEM_ERROR) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07003906 df.left = df.top = -10000;
3907 df.right = df.bottom = 10000;
3908 if (attrs.type != TYPE_WALLPAPER) {
3909 of.left = of.top = cf.left = cf.top = vf.left = vf.top = -10000;
3910 of.right = of.bottom = cf.right = cf.bottom = vf.right = vf.bottom = 10000;
3911 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003912 }
3913
Craig Mautnereda67292013-04-28 13:50:14 -07003914 if (DEBUG_LAYOUT) Slog.v(TAG, "Compute frame " + attrs.getTitle()
The Android Open Source Project11267662009-03-18 17:39:47 -07003915 + ": sim=#" + Integer.toHexString(sim)
RoboErik8a2cfc32014-05-16 11:19:38 -07003916 + " attach=" + attached + " type=" + attrs.type
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003917 + String.format(" flags=0x%08x", fl)
The Android Open Source Project11267662009-03-18 17:39:47 -07003918 + " pf=" + pf.toShortString() + " df=" + df.toShortString()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003919 + " of=" + of.toShortString()
John Spurlock46646232013-09-30 22:32:42 -04003920 + " cf=" + cf.toShortString() + " vf=" + vf.toShortString()
Adrian Roosfa104232014-06-20 16:10:14 -07003921 + " dcf=" + dcf.toShortString()
3922 + " sf=" + sf.toShortString());
Craig Mautner69b08182012-09-05 13:07:13 -07003923
Adrian Roosfa104232014-06-20 16:10:14 -07003924 win.computeFrameLw(pf, df, of, cf, vf, dcf, sf);
Craig Mautner69b08182012-09-05 13:07:13 -07003925
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003926 // Dock windows carve out the bottom of the screen, so normal windows
3927 // can't appear underneath them.
Craig Mautner8bd206b2012-10-03 10:32:02 -07003928 if (attrs.type == TYPE_INPUT_METHOD && win.isVisibleOrBehindKeyguardLw()
3929 && !win.getGivenInsetsPendingLw()) {
satok1bc0a492012-04-25 22:47:12 +09003930 setLastInputMethodWindowLw(null, null);
3931 offsetInputMethodWindowLw(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003932 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003933 if (attrs.type == TYPE_VOICE_INTERACTION && win.isVisibleOrBehindKeyguardLw()
3934 && !win.getGivenInsetsPendingLw()) {
3935 offsetVoiceInputWindowLw(win);
3936 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003937 }
3938
satok1bc0a492012-04-25 22:47:12 +09003939 private void offsetInputMethodWindowLw(WindowState win) {
Dianne Hackbornae6688b2015-02-11 17:02:41 -08003940 int top = win.getDisplayFrameLw().top;
satok1bc0a492012-04-25 22:47:12 +09003941 top += win.getGivenContentInsetsLw().top;
3942 if (mContentBottom > top) {
3943 mContentBottom = top;
3944 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003945 if (mVoiceContentBottom > top) {
3946 mVoiceContentBottom = top;
3947 }
satok1bc0a492012-04-25 22:47:12 +09003948 top = win.getVisibleFrameLw().top;
3949 top += win.getGivenVisibleInsetsLw().top;
3950 if (mCurBottom > top) {
3951 mCurBottom = top;
3952 }
Craig Mautnereda67292013-04-28 13:50:14 -07003953 if (DEBUG_LAYOUT) Slog.v(TAG, "Input method: mDockBottom="
satok1bc0a492012-04-25 22:47:12 +09003954 + mDockBottom + " mContentBottom="
3955 + mContentBottom + " mCurBottom=" + mCurBottom);
3956 }
3957
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003958 private void offsetVoiceInputWindowLw(WindowState win) {
Dianne Hackbornae6688b2015-02-11 17:02:41 -08003959 int top = win.getDisplayFrameLw().top;
3960 top += win.getGivenContentInsetsLw().top;
3961 if (mVoiceContentBottom > top) {
3962 mVoiceContentBottom = top;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003963 }
3964 }
3965
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003966 /** {@inheritDoc} */
Craig Mautner61ac6bb2012-02-02 17:29:33 -08003967 @Override
3968 public void finishLayoutLw() {
3969 return;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003970 }
3971
3972 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003973 @Override
Craig Mautner39834192012-09-02 07:47:24 -07003974 public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) {
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003975 mTopFullscreenOpaqueWindowState = null;
Adrian Rooscd3884d2015-02-18 17:25:23 +01003976 mTopFullscreenOpaqueOrDimmingWindowState = null;
Craig Mautner2bc789b2014-03-19 19:48:38 -07003977 mAppsToBeHidden.clear();
Jorim Jaggic13fcac2014-09-11 17:36:57 +02003978 mAppsThatDismissKeyguard.clear();
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003979 mForceStatusBar = false;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003980 mForceStatusBarFromKeyguard = false;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08003981 mForcingShowNavBar = false;
3982 mForcingShowNavBarLayer = -1;
RoboErik8a2cfc32014-05-16 11:19:38 -07003983
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003984 mHideLockScreen = false;
3985 mAllowLockscreenWhenOn = false;
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003986 mDismissKeyguard = DISMISS_KEYGUARD_NONE;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003987 mShowingLockscreen = false;
3988 mShowingDream = false;
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003989 mWinShowWhenLocked = null;
Jim Millerab954542014-10-10 18:21:49 -07003990 mKeyguardSecure = isKeyguardSecure();
3991 mKeyguardSecureIncludingHidden = mKeyguardSecure
3992 && (mKeyguardDelegate != null && mKeyguardDelegate.isShowing());
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003993 }
3994
3995 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003996 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003997 public void applyPostLayoutPolicyLw(WindowState win, WindowManager.LayoutParams attrs) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07003998 if (DEBUG_LAYOUT) Slog.i(TAG, "Win " + win + ": isVisibleOrBehindKeyguardLw="
3999 + win.isVisibleOrBehindKeyguardLw());
John Spurlockc6d1c602014-01-17 15:22:06 -05004000 final int fl = PolicyControl.getWindowFlags(win, attrs);
John Spurlock414c1f02013-12-04 13:47:36 -05004001 if (mTopFullscreenOpaqueWindowState == null
4002 && win.isVisibleLw() && attrs.type == TYPE_INPUT_METHOD) {
4003 mForcingShowNavBar = true;
4004 mForcingShowNavBarLayer = win.getSurfaceLayer();
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08004005 }
Jorim Jaggiafd4a552014-04-08 15:13:05 +02004006 if (attrs.type == TYPE_STATUS_BAR && (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Jorim Jaggiafd4a552014-04-08 15:13:05 +02004007 mForceStatusBarFromKeyguard = true;
4008 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004009 if (mTopFullscreenOpaqueWindowState == null &&
Dianne Hackborn01b02a72012-01-12 14:05:03 -08004010 win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()) {
John Spurlockc6d1c602014-01-17 15:22:06 -05004011 if ((fl & FLAG_FORCE_NOT_FULLSCREEN) != 0) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004012 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004013 mForceStatusBarFromKeyguard = true;
4014 } else {
4015 mForceStatusBar = true;
4016 }
4017 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004018 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004019 mShowingLockscreen = true;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004020 }
Craig Mautnerab55e522014-03-03 13:26:03 -08004021 boolean appWindow = attrs.type >= FIRST_APPLICATION_WINDOW
Craig Mautner7d7808f2014-09-11 18:02:38 -07004022 && attrs.type < FIRST_SYSTEM_WINDOW;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004023 if (attrs.type == TYPE_DREAM) {
Jeff Brownc8018eb2012-10-29 21:33:27 -07004024 // If the lockscreen was showing when the dream started then wait
4025 // for the dream to draw before hiding the lockscreen.
4026 if (!mDreamingLockscreen
4027 || (win.isVisibleLw() && win.hasDrawnLw())) {
4028 mShowingDream = true;
Craig Mautnerab55e522014-03-03 13:26:03 -08004029 appWindow = true;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004030 }
4031 }
Craig Mautnerab55e522014-03-03 13:26:03 -08004032
Craig Mautner00156ec2014-03-06 22:29:02 -08004033 final boolean showWhenLocked = (fl & FLAG_SHOW_WHEN_LOCKED) != 0;
Craig Mautner74ee9382014-04-01 15:20:16 -07004034 final boolean dismissKeyguard = (fl & FLAG_DISMISS_KEYGUARD) != 0;
Craig Mautnerab55e522014-03-03 13:26:03 -08004035 if (appWindow) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004036 final IApplicationToken appToken = win.getAppToken();
4037 if (showWhenLocked) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004038 // Remove any previous windows with the same appToken.
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004039 mAppsToBeHidden.remove(appToken);
4040 mAppsThatDismissKeyguard.remove(appToken);
Craig Mautnerca0a1242014-12-02 12:25:14 -08004041 if (mAppsToBeHidden.isEmpty()) {
Craig Mautner192d6042014-12-02 23:24:48 -08004042 if (dismissKeyguard && !mKeyguardSecure) {
4043 mAppsThatDismissKeyguard.add(appToken);
4044 } else {
Craig Mautnerca0a1242014-12-02 12:25:14 -08004045 mWinShowWhenLocked = win;
4046 mHideLockScreen = true;
4047 mForceStatusBarFromKeyguard = false;
Craig Mautnerca0a1242014-12-02 12:25:14 -08004048 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004049 }
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004050 } else if (dismissKeyguard) {
Jim Millerab954542014-10-10 18:21:49 -07004051 if (mKeyguardSecure) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004052 mAppsToBeHidden.add(appToken);
4053 } else {
4054 mAppsToBeHidden.remove(appToken);
4055 }
4056 mAppsThatDismissKeyguard.add(appToken);
Craig Mautner2bc789b2014-03-19 19:48:38 -07004057 } else {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004058 mAppsToBeHidden.add(appToken);
Craig Mautner2bc789b2014-03-19 19:48:38 -07004059 }
Craig Mautnerab55e522014-03-03 13:26:03 -08004060 if (attrs.x == 0 && attrs.y == 0
4061 && attrs.width == WindowManager.LayoutParams.MATCH_PARENT
4062 && attrs.height == WindowManager.LayoutParams.MATCH_PARENT) {
4063 if (DEBUG_LAYOUT) Slog.v(TAG, "Fullscreen window: " + win);
4064 mTopFullscreenOpaqueWindowState = win;
Adrian Rooscd3884d2015-02-18 17:25:23 +01004065 if (mTopFullscreenOpaqueOrDimmingWindowState == null) {
4066 mTopFullscreenOpaqueOrDimmingWindowState = win;
4067 }
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004068 if (!mAppsThatDismissKeyguard.isEmpty() &&
4069 mDismissKeyguard == DISMISS_KEYGUARD_NONE) {
4070 if (DEBUG_LAYOUT) Slog.v(TAG,
4071 "Setting mDismissKeyguard true by win " + win);
4072 mDismissKeyguard = mWinDismissingKeyguard == win ?
4073 DISMISS_KEYGUARD_CONTINUE : DISMISS_KEYGUARD_START;
4074 mWinDismissingKeyguard = win;
Jim Millerab954542014-10-10 18:21:49 -07004075 mForceStatusBarFromKeyguard = mShowingLockscreen && mKeyguardSecure;
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004076 } else if (mAppsToBeHidden.isEmpty() && showWhenLocked) {
4077 if (DEBUG_LAYOUT) Slog.v(TAG,
4078 "Setting mHideLockScreen to true by win " + win);
4079 mHideLockScreen = true;
4080 mForceStatusBarFromKeyguard = false;
Craig Mautnerab55e522014-03-03 13:26:03 -08004081 }
Craig Mautner00156ec2014-03-06 22:29:02 -08004082 if ((fl & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) {
Craig Mautnerab55e522014-03-03 13:26:03 -08004083 mAllowLockscreenWhenOn = true;
4084 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004085 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004086
4087 if (mWinShowWhenLocked != null &&
4088 mWinShowWhenLocked.getAppToken() != win.getAppToken()) {
4089 win.hideLw(false);
4090 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004091 }
4092 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01004093 if (mTopFullscreenOpaqueOrDimmingWindowState == null
4094 && win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()
4095 && win.isDimming()) {
4096 mTopFullscreenOpaqueOrDimmingWindowState = win;
4097 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004098 }
4099
4100 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004101 @Override
Craig Mautner39834192012-09-02 07:47:24 -07004102 public int finishPostLayoutPolicyLw() {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004103 if (mWinShowWhenLocked != null &&
4104 mWinShowWhenLocked != mTopFullscreenOpaqueWindowState) {
4105 // A dialog is dismissing the keyguard. Put the wallpaper behind it and hide the
4106 // fullscreen window.
4107 // TODO: Make sure FLAG_SHOW_WALLPAPER is restored when dialog is dismissed. Or not.
4108 mWinShowWhenLocked.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
4109 mTopFullscreenOpaqueWindowState.hideLw(false);
4110 mTopFullscreenOpaqueWindowState = mWinShowWhenLocked;
4111 }
4112
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004113 int changes = 0;
Joe Onorato93056472010-09-10 10:30:46 -04004114 boolean topIsFullscreen = false;
Daniel Sandlere02d8082010-10-08 15:13:22 -04004115
4116 final WindowManager.LayoutParams lp = (mTopFullscreenOpaqueWindowState != null)
4117 ? mTopFullscreenOpaqueWindowState.getAttrs()
4118 : null;
4119
Jeff Brownc8018eb2012-10-29 21:33:27 -07004120 // If we are not currently showing a dream then remember the current
4121 // lockscreen state. We will use this to determine whether the dream
4122 // started while the lockscreen was showing and remember this state
4123 // while the dream is showing.
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004124 if (!mShowingDream) {
4125 mDreamingLockscreen = mShowingLockscreen;
4126 }
4127
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004128 if (mStatusBar != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07004129 if (DEBUG_LAYOUT) Slog.i(TAG, "force=" + mForceStatusBar
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004130 + " forcefkg=" + mForceStatusBarFromKeyguard
Dianne Hackbornd70bc2f2009-10-06 23:25:51 -07004131 + " top=" + mTopFullscreenOpaqueWindowState);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004132 if (mForceStatusBar || mForceStatusBarFromKeyguard) {
Craig Mautnereda67292013-04-28 13:50:14 -07004133 if (DEBUG_LAYOUT) Slog.v(TAG, "Showing status bar: forced");
John Spurlock27735a42013-08-14 17:57:38 -04004134 if (mStatusBarController.setBarShowingLw(true)) {
4135 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4136 }
Craig Mautner81defc72013-10-29 11:10:42 -07004137 // Maintain fullscreen layout until incoming animation is complete.
4138 topIsFullscreen = mTopIsFullscreen && mStatusBar.isAnimatingLw();
John Spurlockf92b6162013-11-11 15:01:16 -05004139 // Transient status bar on the lockscreen is not allowed
4140 if (mForceStatusBarFromKeyguard && mStatusBarController.isTransientShowing()) {
4141 mStatusBarController.updateVisibilityLw(false /*transientAllowed*/,
4142 mLastSystemUiFlags, mLastSystemUiFlags);
4143 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004144 } else if (mTopFullscreenOpaqueWindowState != null) {
John Spurlockc6d1c602014-01-17 15:22:06 -05004145 final int fl = PolicyControl.getWindowFlags(null, lp);
Joe Onorato93056472010-09-10 10:30:46 -04004146 if (localLOGV) {
Craig Mautnereda67292013-04-28 13:50:14 -07004147 Slog.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw()
Joe Onorato93056472010-09-10 10:30:46 -04004148 + " shown frame: " + mTopFullscreenOpaqueWindowState.getShownFrameLw());
Craig Mautnereda67292013-04-28 13:50:14 -07004149 Slog.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs()
John Spurlockc6d1c602014-01-17 15:22:06 -05004150 + " lp.flags=0x" + Integer.toHexString(fl));
Joe Onorato93056472010-09-10 10:30:46 -04004151 }
John Spurlockc6d1c602014-01-17 15:22:06 -05004152 topIsFullscreen = (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004153 || (mLastSystemUiFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
Joe Onorato93056472010-09-10 10:30:46 -04004154 // The subtle difference between the window for mTopFullscreenOpaqueWindowState
Mark Dolinerd0646dc2014-08-27 16:04:02 -07004155 // and mTopIsFullscreen is that mTopIsFullscreen is set only if the window
Joe Onorato93056472010-09-10 10:30:46 -04004156 // has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the
4157 // case though.
John Spurlock27735a42013-08-14 17:57:38 -04004158 if (mStatusBarController.isTransientShowing()) {
4159 if (mStatusBarController.setBarShowingLw(true)) {
John Spurlock32beb2c2013-03-11 10:16:47 -04004160 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4161 }
4162 } else if (topIsFullscreen) {
Craig Mautnereda67292013-04-28 13:50:14 -07004163 if (DEBUG_LAYOUT) Slog.v(TAG, "** HIDING status bar");
John Spurlock27735a42013-08-14 17:57:38 -04004164 if (mStatusBarController.setBarShowingLw(false)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004165 changes |= FINISH_LAYOUT_REDO_LAYOUT;
Craig Mautnereda67292013-04-28 13:50:14 -07004166 } else {
Craig Mautnerc5a6e442013-06-05 17:22:35 -07004167 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar already hiding");
Daniel Sandler40427442010-07-16 11:44:52 -04004168 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004169 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07004170 if (DEBUG_LAYOUT) Slog.v(TAG, "** SHOWING status bar: top is not fullscreen");
John Spurlock27735a42013-08-14 17:57:38 -04004171 if (mStatusBarController.setBarShowingLw(true)) {
4172 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4173 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004174 }
4175 }
4176 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04004177
Craig Mautner81defc72013-10-29 11:10:42 -07004178 if (mTopIsFullscreen != topIsFullscreen) {
4179 if (!topIsFullscreen) {
4180 // Force another layout when status bar becomes fully shown.
4181 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4182 }
4183 mTopIsFullscreen = topIsFullscreen;
4184 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04004185
Craig Mautner39834192012-09-02 07:47:24 -07004186 // Hide the key guard if a visible window explicitly specifies that it wants to be
4187 // displayed when the screen is locked.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004188 if (mKeyguardDelegate != null && mStatusBar != null) {
4189 if (localLOGV) Slog.v(TAG, "finishPostLayoutPolicyLw: mHideKeyguard="
4190 + mHideLockScreen);
Jim Millerab954542014-10-10 18:21:49 -07004191 if (mDismissKeyguard != DISMISS_KEYGUARD_NONE && !mKeyguardSecure) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004192 mKeyguardHidden = true;
Jim Millerab954542014-10-10 18:21:49 -07004193 if (setKeyguardOccludedLw(true)) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004194 changes |= FINISH_LAYOUT_REDO_LAYOUT
4195 | FINISH_LAYOUT_REDO_CONFIG
4196 | FINISH_LAYOUT_REDO_WALLPAPER;
4197 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004198 if (mKeyguardDelegate.isShowing()) {
4199 mHandler.post(new Runnable() {
4200 @Override
4201 public void run() {
4202 mKeyguardDelegate.keyguardDone(false, false);
4203 }
4204 });
4205 }
4206 } else if (mHideLockScreen) {
4207 mKeyguardHidden = true;
Jim Millerab954542014-10-10 18:21:49 -07004208 if (setKeyguardOccludedLw(true)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004209 changes |= FINISH_LAYOUT_REDO_LAYOUT
4210 | FINISH_LAYOUT_REDO_CONFIG
4211 | FINISH_LAYOUT_REDO_WALLPAPER;
4212 }
4213 } else if (mDismissKeyguard != DISMISS_KEYGUARD_NONE) {
4214 // This is the case of keyguard isSecure() and not mHideLockScreen.
4215 if (mDismissKeyguard == DISMISS_KEYGUARD_START) {
4216 // Only launch the next keyguard unlock window once per window.
4217 mKeyguardHidden = false;
Jim Millerab954542014-10-10 18:21:49 -07004218 if (setKeyguardOccludedLw(false)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004219 changes |= FINISH_LAYOUT_REDO_LAYOUT
4220 | FINISH_LAYOUT_REDO_CONFIG
4221 | FINISH_LAYOUT_REDO_WALLPAPER;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004222 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004223 mHandler.post(new Runnable() {
4224 @Override
4225 public void run() {
4226 mKeyguardDelegate.dismiss();
4227 }
4228 });
4229 }
4230 } else {
4231 mWinDismissingKeyguard = null;
4232 mKeyguardHidden = false;
Jim Millerab954542014-10-10 18:21:49 -07004233 if (setKeyguardOccludedLw(false)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004234 changes |= FINISH_LAYOUT_REDO_LAYOUT
4235 | FINISH_LAYOUT_REDO_CONFIG
4236 | FINISH_LAYOUT_REDO_WALLPAPER;
4237 }
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -07004238 }
4239 }
Joe Onorato664644d2011-01-23 17:53:23 -08004240
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004241 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004242 // If the navigation bar has been hidden or shown, we need to do another
4243 // layout pass to update that window.
4244 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4245 }
Joe Onorato664644d2011-01-23 17:53:23 -08004246
Mike Lockwood28569302010-01-28 11:54:40 -05004247 // update since mAllowLockscreenWhenOn might have changed
4248 updateLockScreenTimeout();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004249 return changes;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004250 }
4251
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004252 /**
Jim Millerab954542014-10-10 18:21:49 -07004253 * Updates the occluded state of the Keyguard.
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004254 *
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004255 * @return Whether the flags have changed and we have to redo the layout.
4256 */
Jim Millerab954542014-10-10 18:21:49 -07004257 private boolean setKeyguardOccludedLw(boolean isOccluded) {
4258 boolean wasOccluded = mKeyguardOccluded;
4259 boolean showing = mKeyguardDelegate.isShowing();
4260 if (wasOccluded && !isOccluded && showing) {
4261 mKeyguardOccluded = false;
4262 mKeyguardDelegate.setOccluded(false);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004263 mStatusBar.getAttrs().privateFlags |= PRIVATE_FLAG_KEYGUARD;
4264 mStatusBar.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
4265 return true;
Jim Millerab954542014-10-10 18:21:49 -07004266 } else if (!wasOccluded && isOccluded && showing) {
4267 mKeyguardOccluded = true;
4268 mKeyguardDelegate.setOccluded(true);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004269 mStatusBar.getAttrs().privateFlags &= ~PRIVATE_FLAG_KEYGUARD;
4270 mStatusBar.getAttrs().flags &= ~FLAG_SHOW_WALLPAPER;
4271 return true;
4272 } else {
4273 return false;
4274 }
4275 }
4276
4277 private boolean isStatusBarKeyguard() {
4278 return mStatusBar != null
4279 && (mStatusBar.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
4280 }
4281
Jose Lima9546b202014-07-02 17:21:51 -07004282 @Override
Dianne Hackborn08743722009-12-21 12:16:51 -08004283 public boolean allowAppAnimationsLw() {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004284 if (isStatusBarKeyguard() || mShowingDream) {
Craig Mautner28816302013-10-10 20:31:00 -07004285 // If keyguard or dreams is currently visible, no reason to animate behind it.
Dianne Hackborn08743722009-12-21 12:16:51 -08004286 return false;
4287 }
Dianne Hackborn08743722009-12-21 12:16:51 -08004288 return true;
4289 }
4290
Jose Lima9546b202014-07-02 17:21:51 -07004291 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07004292 public int focusChangedLw(WindowState lastFocus, WindowState newFocus) {
Joe Onorato664644d2011-01-23 17:53:23 -08004293 mFocusedWindow = newFocus;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004294 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004295 // If the navigation bar has been hidden or shown, we need to do another
4296 // layout pass to update that window.
4297 return FINISH_LAYOUT_REDO_LAYOUT;
4298 }
4299 return 0;
Joe Onorato664644d2011-01-23 17:53:23 -08004300 }
4301
Dianne Hackborn0ecadf72009-03-31 18:00:37 -07004302 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07004303 @Override
Jeff Brown46b9ac02010-04-22 18:58:52 -07004304 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
4305 // lid changed state
Jeff Brownc458ce92012-04-30 14:58:40 -07004306 final int newLidState = lidOpen ? LID_OPEN : LID_CLOSED;
4307 if (newLidState == mLidState) {
4308 return;
4309 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004310
Jeff Brownc458ce92012-04-30 14:58:40 -07004311 mLidState = newLidState;
4312 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07004313 updateRotation(true);
Jeff Brownc458ce92012-04-30 14:58:40 -07004314
4315 if (lidOpen) {
Bryce Lee584a4452014-10-21 15:55:55 -07004316 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromLidSwitch);
Jeff Brownc458ce92012-04-30 14:58:40 -07004317 } else if (!mLidControlsSleep) {
Jeff Brown96307042012-07-27 15:51:34 -07004318 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
Jeff Brown46b9ac02010-04-22 18:58:52 -07004319 }
4320 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004321
Michael Wright3818c922014-09-02 13:59:07 -07004322 @Override
4323 public void notifyCameraLensCoverSwitchChanged(long whenNanos, boolean lensCovered) {
4324 int lensCoverState = lensCovered ? CAMERA_LENS_COVERED : CAMERA_LENS_UNCOVERED;
4325 if (mCameraLensCoverState == lensCoverState) {
4326 return;
4327 }
4328 if (mCameraLensCoverState == CAMERA_LENS_COVERED &&
4329 lensCoverState == CAMERA_LENS_UNCOVERED) {
4330 Intent intent;
4331 final boolean keyguardActive = mKeyguardDelegate == null ? false :
4332 mKeyguardDelegate.isShowing();
4333 if (keyguardActive) {
4334 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE);
4335 } else {
4336 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
4337 }
Bryce Lee584a4452014-10-21 15:55:55 -07004338 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromCameraLens);
Michael Wright3818c922014-09-02 13:59:07 -07004339 mContext.startActivityAsUser(intent, UserHandle.CURRENT_OR_SELF);
4340 }
4341 mCameraLensCoverState = lensCoverState;
4342 }
4343
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004344 void setHdmiPlugged(boolean plugged) {
4345 if (mHdmiPlugged != plugged) {
4346 mHdmiPlugged = plugged;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004347 updateRotation(true, true);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004348 Intent intent = new Intent(ACTION_HDMI_PLUGGED);
Joe Onoratodc100302011-01-11 17:07:41 -08004349 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004350 intent.putExtra(EXTRA_HDMI_PLUGGED_STATE, plugged);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07004351 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004352 }
4353 }
4354
Joe Onoratoea495d42011-04-06 11:41:11 -07004355 void initializeHdmiState() {
Joe Onorato7ba631f2011-05-04 15:28:00 -07004356 boolean plugged = false;
Joe Onoratoea495d42011-04-06 11:41:11 -07004357 // watch for HDMI plug messages if the hdmi switch exists
4358 if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) {
4359 mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi");
4360
Joe Onoratoea495d42011-04-06 11:41:11 -07004361 final String filename = "/sys/class/switch/hdmi/state";
4362 FileReader reader = null;
4363 try {
4364 reader = new FileReader(filename);
4365 char[] buf = new char[15];
4366 int n = reader.read(buf);
4367 if (n > 1) {
4368 plugged = 0 != Integer.parseInt(new String(buf, 0, n-1));
4369 }
4370 } catch (IOException ex) {
4371 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
4372 } catch (NumberFormatException ex) {
4373 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
4374 } finally {
4375 if (reader != null) {
4376 try {
4377 reader.close();
4378 } catch (IOException ex) {
4379 }
Joe Onoratodc100302011-01-11 17:07:41 -08004380 }
4381 }
4382 }
Joe Onorato7ba631f2011-05-04 15:28:00 -07004383 // This dance forces the code in setHdmiPlugged to run.
4384 // Always do this so the sticky intent is stuck (to false) if there is no hdmi.
4385 mHdmiPlugged = !plugged;
4386 setHdmiPlugged(!mHdmiPlugged);
Joe Onoratodc100302011-01-11 17:07:41 -08004387 }
4388
Dianne Hackbornc0e3f242011-08-19 14:19:10 -07004389 final Object mScreenshotLock = new Object();
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004390 ServiceConnection mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004391
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004392 final Runnable mScreenshotTimeout = new Runnable() {
4393 @Override public void run() {
4394 synchronized (mScreenshotLock) {
4395 if (mScreenshotConnection != null) {
4396 mContext.unbindService(mScreenshotConnection);
4397 mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004398 }
Winson Chung9112ec32011-06-27 13:15:32 -07004399 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004400 }
4401 };
4402
4403 // Assume this is called from the Handler thread.
4404 private void takeScreenshot() {
4405 synchronized (mScreenshotLock) {
4406 if (mScreenshotConnection != null) {
4407 return;
4408 }
4409 ComponentName cn = new ComponentName("com.android.systemui",
4410 "com.android.systemui.screenshot.TakeScreenshotService");
4411 Intent intent = new Intent();
4412 intent.setComponent(cn);
4413 ServiceConnection conn = new ServiceConnection() {
4414 @Override
4415 public void onServiceConnected(ComponentName name, IBinder service) {
4416 synchronized (mScreenshotLock) {
4417 if (mScreenshotConnection != this) {
4418 return;
4419 }
4420 Messenger messenger = new Messenger(service);
4421 Message msg = Message.obtain(null, 1);
4422 final ServiceConnection myConn = this;
4423 Handler h = new Handler(mHandler.getLooper()) {
4424 @Override
4425 public void handleMessage(Message msg) {
4426 synchronized (mScreenshotLock) {
4427 if (mScreenshotConnection == myConn) {
4428 mContext.unbindService(mScreenshotConnection);
4429 mScreenshotConnection = null;
4430 mHandler.removeCallbacks(mScreenshotTimeout);
4431 }
4432 }
4433 }
4434 };
4435 msg.replyTo = new Messenger(h);
Winson Chunga63bb842011-10-17 10:26:28 -07004436 msg.arg1 = msg.arg2 = 0;
4437 if (mStatusBar != null && mStatusBar.isVisibleLw())
4438 msg.arg1 = 1;
4439 if (mNavigationBar != null && mNavigationBar.isVisibleLw())
4440 msg.arg2 = 1;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004441 try {
4442 messenger.send(msg);
4443 } catch (RemoteException e) {
4444 }
4445 }
4446 }
4447 @Override
4448 public void onServiceDisconnected(ComponentName name) {}
4449 };
Amith Yamasani27b89e62013-01-16 12:30:11 -08004450 if (mContext.bindServiceAsUser(
4451 intent, conn, Context.BIND_AUTO_CREATE, UserHandle.CURRENT)) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004452 mScreenshotConnection = conn;
4453 mHandler.postDelayed(mScreenshotTimeout, 10000);
4454 }
4455 }
Winson Chung9112ec32011-06-27 13:15:32 -07004456 }
4457
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004458 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004459 @Override
Jeff Brown037c33e2014-04-09 00:31:55 -07004460 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) {
Jeff Brown96307042012-07-27 15:51:34 -07004461 if (!mSystemBooted) {
4462 // If we have not yet booted, don't let key events do anything.
4463 return 0;
4464 }
4465
Jeff Brown037c33e2014-04-09 00:31:55 -07004466 final boolean interactive = (policyFlags & FLAG_INTERACTIVE) != 0;
Jeff Brown1f245102010-11-18 20:53:46 -08004467 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
4468 final boolean canceled = event.isCanceled();
4469 final int keyCode = event.getKeyCode();
Jeff Browne20c9e02010-10-11 14:20:19 -07004470
Jeff Brown3122e442010-10-11 23:32:49 -07004471 final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0;
Jeff Brown3122e442010-10-11 23:32:49 -07004472
Mike Lockwoodc72b15f2009-11-28 20:58:22 -05004473 // If screen is off then we treat the case where the keyguard is open but hidden
4474 // the same as if it were open and in front.
4475 // This will prevent any keys other than the power button from waking the screen
4476 // when the keyguard is hidden by another activity.
Jim Miller5ecd8112013-01-09 18:50:26 -08004477 final boolean keyguardActive = (mKeyguardDelegate == null ? false :
Jeff Brown037c33e2014-04-09 00:31:55 -07004478 (interactive ?
Jim Millerab954542014-10-10 18:21:49 -07004479 isKeyguardShowingAndNotOccluded() :
Jim Miller5ecd8112013-01-09 18:50:26 -08004480 mKeyguardDelegate.isShowing()));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004481
Jeff Brown40013652012-05-16 21:22:36 -07004482 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004483 Log.d(TAG, "interceptKeyTq keycode=" + keyCode
Jeff Brown037c33e2014-04-09 00:31:55 -07004484 + " interactive=" + interactive + " keyguardActive=" + keyguardActive
Jeff Brown26875502014-01-30 21:47:47 -08004485 + " policyFlags=" + Integer.toHexString(policyFlags));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004486 }
4487
Jeff Brown037c33e2014-04-09 00:31:55 -07004488 // Basic policy based on interactive state.
Jeff Brown4d396052010-10-29 21:50:21 -07004489 int result;
Michael Wright337d9d22014-04-22 15:03:48 -07004490 boolean isWakeKey = (policyFlags & WindowManagerPolicy.FLAG_WAKE) != 0
4491 || event.isWakeKey();
Michael Wrightfc01f042014-09-08 14:12:24 -07004492 if (interactive || (isInjected && !isWakeKey)) {
RoboErikde9ba392014-09-26 12:51:01 -07004493 // When the device is interactive or the key is injected pass the
4494 // key to the application.
Jeff Brown4d396052010-10-29 21:50:21 -07004495 result = ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07004496 isWakeKey = false;
Michael Wrightfc01f042014-09-08 14:12:24 -07004497 } else if (!interactive && shouldDispatchInputWhenNonInteractive()) {
4498 // If we're currently dozing with the screen on and the keyguard showing, pass the key
4499 // to the application but preserve its wake key status to make sure we still move
4500 // from dozing to fully interactive if we would normally go from off to fully
4501 // interactive.
4502 result = ACTION_PASS_TO_USER;
Jeff Brown4d396052010-10-29 21:50:21 -07004503 } else {
4504 // When the screen is off and the key is not injected, determine whether
4505 // to wake the device but don't pass the key to the application.
4506 result = 0;
Jeff Brown26875502014-01-30 21:47:47 -08004507 if (isWakeKey && (!down || !isWakeKeyWhenScreenOff(keyCode))) {
4508 isWakeKey = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004509 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004510 }
4511
Justin Kohd378ad72013-04-01 12:18:26 -07004512 // If the key would be handled globally, just return the result, don't worry about special
4513 // key processing.
Jeff Brown13f00f02014-10-31 14:45:50 -07004514 if (isValidGlobalKey(keyCode)
4515 && mGlobalKeyManager.shouldHandleGlobalKey(keyCode, event)) {
Michael Wright85b1af62014-06-04 14:51:58 -07004516 if (isWakeKey) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004517 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey);
Michael Wright85b1af62014-06-04 14:51:58 -07004518 }
Justin Kohd378ad72013-04-01 12:18:26 -07004519 return result;
4520 }
4521
Jeff Brownbae8e772014-06-12 19:59:45 -07004522 boolean useHapticFeedback = down
4523 && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0
4524 && event.getRepeatCount() == 0;
4525
Jeff Brown4d396052010-10-29 21:50:21 -07004526 // Handle special keys.
4527 switch (keyCode) {
4528 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jeff Brownb0418da2010-11-01 15:24:01 -07004529 case KeyEvent.KEYCODE_VOLUME_UP:
4530 case KeyEvent.KEYCODE_VOLUME_MUTE: {
RoboErik001c59c2015-01-26 15:53:51 -08004531 if (mUseTvRouting) {
4532 // On TVs volume keys never go to the foreground app
4533 result &= ~ACTION_PASS_TO_USER;
4534 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004535 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
4536 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004537 if (interactive && !mScreenshotChordVolumeDownKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004538 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004539 mScreenshotChordVolumeDownKeyTriggered = true;
4540 mScreenshotChordVolumeDownKeyTime = event.getDownTime();
4541 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004542 cancelPendingPowerKeyAction();
4543 interceptScreenshotChord();
4544 }
4545 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004546 mScreenshotChordVolumeDownKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004547 cancelPendingScreenshotChordAction();
4548 }
4549 } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
4550 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004551 if (interactive && !mScreenshotChordVolumeUpKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004552 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004553 mScreenshotChordVolumeUpKeyTriggered = true;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004554 cancelPendingPowerKeyAction();
4555 cancelPendingScreenshotChordAction();
4556 }
4557 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004558 mScreenshotChordVolumeUpKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004559 cancelPendingScreenshotChordAction();
4560 }
4561 }
Jeff Brown4d396052010-10-29 21:50:21 -07004562 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004563 TelecomManager telecomManager = getTelecommService();
4564 if (telecomManager != null) {
4565 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07004566 // If an incoming call is ringing, either VOLUME key means
4567 // "silence ringer". We handle these keys here, rather than
4568 // in the InCallScreen, to make sure we'll respond to them
4569 // even if the InCallScreen hasn't come to the foreground yet.
4570 // Look for the DOWN event here, to agree with the "fallback"
4571 // behavior in the InCallScreen.
4572 Log.i(TAG, "interceptKeyBeforeQueueing:"
4573 + " VOLUME key-down while ringing: Silence ringer!");
Jeff Brown4d396052010-10-29 21:50:21 -07004574
Santos Cordon6848f722014-05-21 15:22:12 -07004575 // Silence the ringer. (It's safe to call this
4576 // even if the ringer has already been silenced.)
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004577 telecomManager.silenceRinger();
Jeff Brown4d396052010-10-29 21:50:21 -07004578
Santos Cordon6848f722014-05-21 15:22:12 -07004579 // And *don't* pass this key thru to the current activity
4580 // (which is probably the InCallScreen.)
4581 result &= ~ACTION_PASS_TO_USER;
4582 break;
4583 }
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004584 if (telecomManager.isInCall()
Santos Cordon6848f722014-05-21 15:22:12 -07004585 && (result & ACTION_PASS_TO_USER) == 0) {
4586 // If we are in call but we decided not to pass the key to
RoboErik430fc482014-06-12 15:49:20 -07004587 // the application, just pass it to the session service.
4588
4589 MediaSessionLegacyHelper.getHelper(mContext)
RoboErik3c45c292014-07-08 16:47:31 -07004590 .sendVolumeKeyEvent(event, false);
Santos Cordon6848f722014-05-21 15:22:12 -07004591 break;
Jeff Brown4d396052010-10-29 21:50:21 -07004592 }
4593 }
4594
RoboErik430fc482014-06-12 15:49:20 -07004595 if ((result & ACTION_PASS_TO_USER) == 0) {
RoboErik001c59c2015-01-26 15:53:51 -08004596 if (mUseTvRouting) {
4597 dispatchDirectAudioEvent(event);
4598 } else {
4599 // If we aren't passing to the user and no one else
4600 // handled it send it to the session manager to
4601 // figure out.
4602 MediaSessionLegacyHelper.getHelper(mContext)
4603 .sendVolumeKeyEvent(event, true);
4604 }
Jeff Brown4d396052010-10-29 21:50:21 -07004605 break;
4606 }
4607 }
4608 break;
4609 }
4610
4611 case KeyEvent.KEYCODE_ENDCALL: {
4612 result &= ~ACTION_PASS_TO_USER;
4613 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004614 TelecomManager telecomManager = getTelecommService();
Jeff Brown4d396052010-10-29 21:50:21 -07004615 boolean hungUp = false;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004616 if (telecomManager != null) {
4617 hungUp = telecomManager.endCall();
Jeff Brown4d396052010-10-29 21:50:21 -07004618 }
Jeff Brown13f00f02014-10-31 14:45:50 -07004619 if (interactive && !hungUp) {
4620 mEndCallKeyHandled = false;
4621 mHandler.postDelayed(mEndCallLongPress,
4622 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
4623 } else {
4624 mEndCallKeyHandled = true;
4625 }
Jeff Brown4d396052010-10-29 21:50:21 -07004626 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004627 if (!mEndCallKeyHandled) {
4628 mHandler.removeCallbacks(mEndCallLongPress);
4629 if (!canceled) {
4630 if ((mEndcallBehavior
4631 & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) {
4632 if (goHome()) {
4633 break;
4634 }
Dianne Hackborn0041e972009-07-24 17:14:43 -07004635 }
Jeff Brown13f00f02014-10-31 14:45:50 -07004636 if ((mEndcallBehavior
4637 & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) {
4638 mPowerManager.goToSleep(event.getEventTime(),
4639 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
4640 isWakeKey = false;
4641 }
Jeff Brown4d396052010-10-29 21:50:21 -07004642 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004643 }
Jeff Brown4d396052010-10-29 21:50:21 -07004644 }
4645 break;
4646 }
4647
4648 case KeyEvent.KEYCODE_POWER: {
4649 result &= ~ACTION_PASS_TO_USER;
Jeff Brown13f00f02014-10-31 14:45:50 -07004650 isWakeKey = false; // wake-up will be handled separately
Jeff Brown4d396052010-10-29 21:50:21 -07004651 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004652 interceptPowerKeyDown(event, interactive);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004653 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004654 interceptPowerKeyUp(event, interactive, canceled);
Jeff Brown4d396052010-10-29 21:50:21 -07004655 }
4656 break;
4657 }
4658
Jeff Brown6212a492014-03-07 13:58:47 -08004659 case KeyEvent.KEYCODE_SLEEP: {
4660 result &= ~ACTION_PASS_TO_USER;
Jeff Brownbae8e772014-06-12 19:59:45 -07004661 if (!mPowerManager.isInteractive()) {
4662 useHapticFeedback = false; // suppress feedback if already non-interactive
4663 }
Jeff Brownc12035c2014-08-13 18:52:25 -07004664 mPowerManager.goToSleep(event.getEventTime(),
4665 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
Jeff Brown6212a492014-03-07 13:58:47 -08004666 isWakeKey = false;
4667 break;
4668 }
4669
4670 case KeyEvent.KEYCODE_WAKEUP: {
4671 result &= ~ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07004672 isWakeKey = true;
Jeff Brown6212a492014-03-07 13:58:47 -08004673 break;
4674 }
4675
Jeff Brown4d396052010-10-29 21:50:21 -07004676 case KeyEvent.KEYCODE_MEDIA_PLAY:
4677 case KeyEvent.KEYCODE_MEDIA_PAUSE:
4678 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
Jeff Brown4d396052010-10-29 21:50:21 -07004679 case KeyEvent.KEYCODE_HEADSETHOOK:
4680 case KeyEvent.KEYCODE_MUTE:
4681 case KeyEvent.KEYCODE_MEDIA_STOP:
4682 case KeyEvent.KEYCODE_MEDIA_NEXT:
4683 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
4684 case KeyEvent.KEYCODE_MEDIA_REWIND:
4685 case KeyEvent.KEYCODE_MEDIA_RECORD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09004686 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
4687 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: {
RoboErikde9ba392014-09-26 12:51:01 -07004688 if (MediaSessionLegacyHelper.getHelper(mContext).isGlobalPriorityActive()) {
4689 // If the global session is active pass all media keys to it
4690 // instead of the active window.
4691 result &= ~ACTION_PASS_TO_USER;
4692 }
Jeff Brown4d396052010-10-29 21:50:21 -07004693 if ((result & ACTION_PASS_TO_USER) == 0) {
4694 // Only do this if we would otherwise not pass it to the user. In that
4695 // case, the PhoneWindow class will do the same thing, except it will
4696 // only do it if the showing app doesn't process the key on its own.
Jeff Brown40013652012-05-16 21:22:36 -07004697 // Note that we need to make a copy of the key event here because the
4698 // original key event will be recycled when we return.
Jeff Brown4d396052010-10-29 21:50:21 -07004699 mBroadcastWakeLock.acquire();
Jeff Brown40013652012-05-16 21:22:36 -07004700 Message msg = mHandler.obtainMessage(MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK,
4701 new KeyEvent(event));
4702 msg.setAsynchronous(true);
4703 msg.sendToTarget();
Jeff Brown4d396052010-10-29 21:50:21 -07004704 }
4705 break;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004706 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004707
Jeff Brown4d396052010-10-29 21:50:21 -07004708 case KeyEvent.KEYCODE_CALL: {
4709 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004710 TelecomManager telecomManager = getTelecommService();
4711 if (telecomManager != null) {
4712 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07004713 Log.i(TAG, "interceptKeyBeforeQueueing:"
4714 + " CALL key-down while ringing: Answer the call!");
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004715 telecomManager.acceptRingingCall();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004716
Santos Cordon6848f722014-05-21 15:22:12 -07004717 // And *don't* pass this key thru to the current activity
4718 // (which is presumably the InCallScreen.)
4719 result &= ~ACTION_PASS_TO_USER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004720 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004721 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004722 }
Jeff Brown4d396052010-10-29 21:50:21 -07004723 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004724 }
Michael Wright869a67c2014-08-26 19:33:06 -07004725 case KeyEvent.KEYCODE_VOICE_ASSIST: {
4726 // Only do this if we would otherwise not pass it to the user. In that case,
4727 // interceptKeyBeforeDispatching would apply a similar but different policy in
4728 // order to invoke voice assist actions. Note that we need to make a copy of the
4729 // key event here because the original key event will be recycled when we return.
4730 if ((result & ACTION_PASS_TO_USER) == 0 && !down) {
4731 mBroadcastWakeLock.acquire();
4732 Message msg = mHandler.obtainMessage(MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK,
4733 keyguardActive ? 1 : 0, 0);
4734 msg.setAsynchronous(true);
4735 msg.sendToTarget();
4736 }
4737 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004738 }
Jeff Brown26875502014-01-30 21:47:47 -08004739
Jeff Brownbae8e772014-06-12 19:59:45 -07004740 if (useHapticFeedback) {
4741 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
4742 }
4743
Jeff Brown26875502014-01-30 21:47:47 -08004744 if (isWakeKey) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004745 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey);
Jeff Brown26875502014-01-30 21:47:47 -08004746 }
Bryce Lee584a4452014-10-21 15:55:55 -07004747
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004748 return result;
4749 }
4750
Jeff Brown1c2e4942012-11-06 16:32:01 -08004751 /**
Jeff Brown13f00f02014-10-31 14:45:50 -07004752 * Returns true if the key can have global actions attached to it.
4753 * We reserve all power management keys for the system since they require
4754 * very careful handling.
4755 */
4756 private static boolean isValidGlobalKey(int keyCode) {
4757 switch (keyCode) {
4758 case KeyEvent.KEYCODE_POWER:
4759 case KeyEvent.KEYCODE_WAKEUP:
4760 case KeyEvent.KEYCODE_SLEEP:
4761 return false;
4762 default:
4763 return true;
4764 }
4765 }
4766
4767 /**
Jeff Brown1c2e4942012-11-06 16:32:01 -08004768 * When the screen is off we ignore some keys that might otherwise typically
4769 * be considered wake keys. We filter them out here.
4770 *
4771 * {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it
4772 * is always considered a wake key.
4773 */
4774 private boolean isWakeKeyWhenScreenOff(int keyCode) {
4775 switch (keyCode) {
4776 // ignore volume keys unless docked
4777 case KeyEvent.KEYCODE_VOLUME_UP:
4778 case KeyEvent.KEYCODE_VOLUME_DOWN:
4779 case KeyEvent.KEYCODE_VOLUME_MUTE:
4780 return mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED;
4781
4782 // ignore media and camera keys
4783 case KeyEvent.KEYCODE_MUTE:
4784 case KeyEvent.KEYCODE_HEADSETHOOK:
4785 case KeyEvent.KEYCODE_MEDIA_PLAY:
4786 case KeyEvent.KEYCODE_MEDIA_PAUSE:
4787 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
4788 case KeyEvent.KEYCODE_MEDIA_STOP:
4789 case KeyEvent.KEYCODE_MEDIA_NEXT:
4790 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
4791 case KeyEvent.KEYCODE_MEDIA_REWIND:
4792 case KeyEvent.KEYCODE_MEDIA_RECORD:
4793 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09004794 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK:
Jeff Brown1c2e4942012-11-06 16:32:01 -08004795 case KeyEvent.KEYCODE_CAMERA:
4796 return false;
4797 }
4798 return true;
4799 }
4800
4801
Jeff Brown56194eb2011-03-02 19:23:13 -08004802 /** {@inheritDoc} */
4803 @Override
Michael Wright70af00a2014-09-03 19:30:20 -07004804 public int interceptMotionBeforeQueueingNonInteractive(long whenNanos, int policyFlags) {
4805 if ((policyFlags & FLAG_WAKE) != 0) {
Bryce Lee5c138322014-11-03 08:26:09 -08004806 if (wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotion)) {
4807 return 0;
4808 }
Michael Wright70af00a2014-09-03 19:30:20 -07004809 }
Bryce Lee5c138322014-11-03 08:26:09 -08004810
Michael Wright70af00a2014-09-03 19:30:20 -07004811 if (shouldDispatchInputWhenNonInteractive()) {
4812 return ACTION_PASS_TO_USER;
4813 }
Bryce Lee5c138322014-11-03 08:26:09 -08004814
Bryce Lee812d7022014-11-10 13:33:28 -08004815 // If we have not passed the action up and we are in theater mode without dreaming,
4816 // there will be no dream to intercept the touch and wake into ambient. The device should
4817 // wake up in this case.
4818 if (isTheaterModeEnabled() && (policyFlags & FLAG_WAKE) != 0) {
4819 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotionWhenNotDreaming);
4820 }
4821
Jeff Brown037c33e2014-04-09 00:31:55 -07004822 return 0;
Jeff Brown56194eb2011-03-02 19:23:13 -08004823 }
4824
Michael Wright70af00a2014-09-03 19:30:20 -07004825 private boolean shouldDispatchInputWhenNonInteractive() {
Bryce Lee5c138322014-11-03 08:26:09 -08004826 // Send events to keyguard while the screen is on.
Jim Millerab954542014-10-10 18:21:49 -07004827 if (isKeyguardShowingAndNotOccluded() && mDisplay != null
4828 && mDisplay.getState() != Display.STATE_OFF) {
Bryce Lee5c138322014-11-03 08:26:09 -08004829 return true;
4830 }
4831
4832 // Send events to a dozing dream even if the screen is off since the dream
4833 // is in control of the state of the screen.
4834 IDreamManager dreamManager = getDreamManager();
4835
4836 try {
4837 if (dreamManager != null && dreamManager.isDreaming()) {
4838 return true;
4839 }
4840 } catch (RemoteException e) {
4841 Slog.e(TAG, "RemoteException when checking if dreaming", e);
4842 }
4843
4844 // Otherwise, consume events since the user can't see what is being
4845 // interacted with.
4846 return false;
Michael Wright70af00a2014-09-03 19:30:20 -07004847 }
4848
RoboErik001c59c2015-01-26 15:53:51 -08004849 private void dispatchDirectAudioEvent(KeyEvent event) {
4850 if (event.getAction() != KeyEvent.ACTION_DOWN) {
4851 return;
4852 }
4853 int keyCode = event.getKeyCode();
4854 int flags = AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_PLAY_SOUND;
4855 String pkgName = mContext.getOpPackageName();
4856 switch (keyCode) {
4857 case KeyEvent.KEYCODE_VOLUME_UP:
4858 try {
John Spurlockee5ad722015-03-03 16:17:21 -05004859 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_RAISE,
4860 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName);
RoboErik001c59c2015-01-26 15:53:51 -08004861 } catch (RemoteException e) {
4862 Log.e(TAG, "Error dispatching volume up in dispatchTvAudioEvent.", e);
4863 }
4864 break;
4865 case KeyEvent.KEYCODE_VOLUME_DOWN:
4866 try {
John Spurlockee5ad722015-03-03 16:17:21 -05004867 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_LOWER,
4868 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName);
RoboErik001c59c2015-01-26 15:53:51 -08004869 } catch (RemoteException e) {
4870 Log.e(TAG, "Error dispatching volume down in dispatchTvAudioEvent.", e);
4871 }
4872 break;
4873 case KeyEvent.KEYCODE_VOLUME_MUTE:
4874 try {
4875 if (event.getRepeatCount() == 0) {
John Spurlockee5ad722015-03-03 16:17:21 -05004876 getAudioService().adjustSuggestedStreamVolume(
4877 AudioManager.ADJUST_TOGGLE_MUTE,
4878 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName);
RoboErik001c59c2015-01-26 15:53:51 -08004879 }
4880 } catch (RemoteException e) {
4881 Log.e(TAG, "Error dispatching mute in dispatchTvAudioEvent.", e);
4882 }
4883 break;
4884 }
4885 }
4886
Jeff Brown40013652012-05-16 21:22:36 -07004887 void dispatchMediaKeyWithWakeLock(KeyEvent event) {
4888 if (DEBUG_INPUT) {
4889 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: " + event);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004890 }
4891
Jeff Brown40013652012-05-16 21:22:36 -07004892 if (mHavePendingMediaKeyRepeatWithWakeLock) {
4893 if (DEBUG_INPUT) {
4894 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: canceled repeat");
4895 }
4896
4897 mHandler.removeMessages(MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK);
4898 mHavePendingMediaKeyRepeatWithWakeLock = false;
4899 mBroadcastWakeLock.release(); // pending repeat was holding onto the wake lock
4900 }
4901
4902 dispatchMediaKeyWithWakeLockToAudioService(event);
4903
4904 if (event.getAction() == KeyEvent.ACTION_DOWN
4905 && event.getRepeatCount() == 0) {
4906 mHavePendingMediaKeyRepeatWithWakeLock = true;
4907
4908 Message msg = mHandler.obtainMessage(
4909 MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK, event);
4910 msg.setAsynchronous(true);
4911 mHandler.sendMessageDelayed(msg, ViewConfiguration.getKeyRepeatTimeout());
4912 } else {
4913 mBroadcastWakeLock.release();
4914 }
4915 }
4916
4917 void dispatchMediaKeyRepeatWithWakeLock(KeyEvent event) {
4918 mHavePendingMediaKeyRepeatWithWakeLock = false;
4919
4920 KeyEvent repeatEvent = KeyEvent.changeTimeRepeat(event,
4921 SystemClock.uptimeMillis(), 1, event.getFlags() | KeyEvent.FLAG_LONG_PRESS);
4922 if (DEBUG_INPUT) {
4923 Slog.d(TAG, "dispatchMediaKeyRepeatWithWakeLock: " + repeatEvent);
4924 }
4925
4926 dispatchMediaKeyWithWakeLockToAudioService(repeatEvent);
4927 mBroadcastWakeLock.release();
4928 }
4929
4930 void dispatchMediaKeyWithWakeLockToAudioService(KeyEvent event) {
4931 if (ActivityManagerNative.isSystemReady()) {
RoboErik430fc482014-06-12 15:49:20 -07004932 MediaSessionLegacyHelper.getHelper(mContext).sendMediaButtonEvent(event, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004933 }
4934 }
4935
Michael Wright869a67c2014-08-26 19:33:06 -07004936 void launchVoiceAssistWithWakeLock(boolean keyguardActive) {
4937 Intent voiceIntent =
4938 new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
4939 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, keyguardActive);
4940 mContext.startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
4941 mBroadcastWakeLock.release();
4942 }
4943
Mike Lockwood1753f7f2009-08-24 14:49:07 -07004944 BroadcastReceiver mDockReceiver = new BroadcastReceiver() {
Craig Mautnereee29c42013-01-17 14:44:34 -08004945 @Override
Mike Lockwood1753f7f2009-08-24 14:49:07 -07004946 public void onReceive(Context context, Intent intent) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07004947 if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) {
4948 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
4949 Intent.EXTRA_DOCK_STATE_UNDOCKED);
Daniel Sandler6396c722013-04-16 20:19:09 -04004950 } else {
4951 try {
4952 IUiModeManager uiModeService = IUiModeManager.Stub.asInterface(
4953 ServiceManager.getService(Context.UI_MODE_SERVICE));
4954 mUiMode = uiModeService.getCurrentModeType();
4955 } catch (RemoteException e) {
4956 }
Dianne Hackborn80fa1662009-10-07 14:02:10 -07004957 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004958 updateRotation(true);
Craig Mautnereee29c42013-01-17 14:44:34 -08004959 synchronized (mLock) {
4960 updateOrientationListenerLp();
4961 }
Mike Lockwood1753f7f2009-08-24 14:49:07 -07004962 }
4963 };
4964
Jeff Brown6aaf2952012-10-05 16:01:08 -07004965 BroadcastReceiver mDreamReceiver = new BroadcastReceiver() {
4966 @Override
4967 public void onReceive(Context context, Intent intent) {
4968 if (Intent.ACTION_DREAMING_STARTED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004969 if (mKeyguardDelegate != null) {
4970 mKeyguardDelegate.onDreamingStarted();
Jeff Brown6aaf2952012-10-05 16:01:08 -07004971 }
4972 } else if (Intent.ACTION_DREAMING_STOPPED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004973 if (mKeyguardDelegate != null) {
4974 mKeyguardDelegate.onDreamingStopped();
Jeff Brown6aaf2952012-10-05 16:01:08 -07004975 }
4976 }
4977 }
4978 };
4979
Christopher Tate5e08af02012-09-21 17:17:22 -07004980 BroadcastReceiver mMultiuserReceiver = new BroadcastReceiver() {
4981 @Override
4982 public void onReceive(Context context, Intent intent) {
4983 if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) {
4984 // tickle the settings observer: this first ensures that we're
4985 // observing the relevant settings for the newly-active user,
4986 // and then updates our own bookkeeping based on the now-
4987 // current user.
4988 mSettingsObserver.onChange(false);
John Spurlockce479d82012-11-29 09:52:21 -05004989
4990 // force a re-application of focused window sysui visibility.
4991 // the window may never have been shown for this user
4992 // e.g. the keyguard when going through the new-user setup flow
John Spurlock04db1762013-05-13 12:46:41 -04004993 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
John Spurlockce479d82012-11-29 09:52:21 -05004994 mLastSystemUiFlags = 0;
4995 updateSystemUiVisibilityLw();
4996 }
Christopher Tate5e08af02012-09-21 17:17:22 -07004997 }
4998 }
4999 };
5000
John Spurlockd9b70bd2014-02-06 17:02:44 -05005001 private final Runnable mRequestTransientNav = new Runnable() {
5002 @Override
5003 public void run() {
5004 requestTransientBars(mNavigationBar);
5005 }
5006 };
5007
John Spurlocke1f366f2013-08-05 12:22:40 -04005008 private void requestTransientBars(WindowState swipeTarget) {
John Spurlock04db1762013-05-13 12:46:41 -04005009 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Maurice Lam99c6e072014-04-28 18:24:28 -07005010 if (!isUserSetupComplete()) {
5011 // Swipe-up for navigation bar is disabled during setup
5012 return;
5013 }
John Spurlock27735a42013-08-14 17:57:38 -04005014 boolean sb = mStatusBarController.checkShowTransientBarLw();
5015 boolean nb = mNavigationBarController.checkShowTransientBarLw();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005016 if (sb || nb) {
John Spurlocke1f366f2013-08-05 12:22:40 -04005017 WindowState barTarget = sb ? mStatusBar : mNavigationBar;
5018 if (sb ^ nb && barTarget != swipeTarget) {
5019 if (DEBUG) Slog.d(TAG, "Not showing transient bar, wrong swipe target");
John Spurlockad3e6cb2013-04-30 08:47:43 -04005020 return;
5021 }
John Spurlock27735a42013-08-14 17:57:38 -04005022 if (sb) mStatusBarController.showTransient();
5023 if (nb) mNavigationBarController.showTransient();
John Spurlockf1a36642013-10-12 17:50:42 -04005024 mImmersiveModeConfirmation.confirmCurrentPrompt();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005025 updateSystemUiVisibilityLw();
John Spurlock32beb2c2013-03-11 10:16:47 -04005026 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04005027 }
5028 }
5029
Jeff Brown3ee549c2014-09-22 20:14:39 -07005030 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07005031 @Override
Jeff Brown140ffc72014-05-01 15:18:00 -07005032 public void goingToSleep(int why) {
Dianne Hackborn74489012009-03-24 20:50:09 -07005033 EventLog.writeEvent(70000, 0);
Jeff Brown36c4db82014-09-19 12:05:31 -07005034 if (DEBUG_WAKEUP) Slog.i(TAG, "Going to sleep...");
Jeff Brown3ee549c2014-09-22 20:14:39 -07005035
5036 // We must get this work done here because the power manager will drop
5037 // the wake lock and let the system suspend once this function returns.
The Android Open Source Project0727d222009-03-11 12:11:58 -07005038 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005039 mAwake = false;
5040 mKeyguardDrawComplete = false;
Jeff Browna20dda42014-05-27 20:57:24 -07005041 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005042 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05005043 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005044 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005045
5046 if (mKeyguardDelegate != null) {
5047 mKeyguardDelegate.onScreenTurnedOff(why);
5048 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005049 }
5050
Jeff Brown13f00f02014-10-31 14:45:50 -07005051 private void wakeUpFromPowerKey(long eventTime) {
5052 wakeUp(eventTime, mAllowTheaterModeWakeFromPowerKey);
5053 }
5054
Bryce Lee5c138322014-11-03 08:26:09 -08005055 private boolean wakeUp(long wakeTime, boolean wakeInTheaterMode) {
Bryce Lee584a4452014-10-21 15:55:55 -07005056 if (!wakeInTheaterMode && isTheaterModeEnabled()) {
Bryce Lee5c138322014-11-03 08:26:09 -08005057 return false;
Bryce Lee584a4452014-10-21 15:55:55 -07005058 }
5059
5060 mPowerManager.wakeUp(wakeTime);
Bryce Lee5c138322014-11-03 08:26:09 -08005061 return true;
Bryce Lee584a4452014-10-21 15:55:55 -07005062 }
5063
Jeff Brown3ee549c2014-09-22 20:14:39 -07005064 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07005065 @Override
Jeff Brown36c4db82014-09-19 12:05:31 -07005066 public void wakingUp() {
Dianne Hackborn74489012009-03-24 20:50:09 -07005067 EventLog.writeEvent(70000, 1);
Jeff Brown36c4db82014-09-19 12:05:31 -07005068 if (DEBUG_WAKEUP) Slog.i(TAG, "Waking up...");
Craig Mautner8a0da012014-05-31 15:13:37 -07005069
Jeff Brown3ee549c2014-09-22 20:14:39 -07005070 // Since goToSleep performs these functions synchronously, we must
5071 // do the same here. We cannot post this work to a handler because
5072 // that might cause it to become reordered with respect to what
5073 // may happen in a future call to goToSleep.
The Android Open Source Project0727d222009-03-11 12:11:58 -07005074 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005075 mAwake = true;
5076 mKeyguardDrawComplete = false;
5077 if (mKeyguardDelegate != null) {
5078 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
5079 mHandler.sendEmptyMessageDelayed(MSG_KEYGUARD_DRAWN_TIMEOUT, 1000);
5080 }
5081
Jeff Browna20dda42014-05-27 20:57:24 -07005082 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005083 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05005084 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005085 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005086
Jim Miller5ecd8112013-01-09 18:50:26 -08005087 if (mKeyguardDelegate != null) {
Craig Mautner8a0da012014-05-31 15:13:37 -07005088 mKeyguardDelegate.onScreenTurnedOn(mKeyguardDelegateCallback);
Jeff Brown36c4db82014-09-19 12:05:31 -07005089 // ... eventually calls finishKeyguardDrawn
Jeff Brownc38c9be2012-10-04 13:16:19 -07005090 } else {
Craig Mautner8a0da012014-05-31 15:13:37 -07005091 if (DEBUG_WAKEUP) Slog.d(TAG, "null mKeyguardDelegate: setting mKeyguardDrawComplete.");
Jeff Brown36c4db82014-09-19 12:05:31 -07005092 finishKeyguardDrawn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07005093 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005094 }
5095
Jeff Brown36c4db82014-09-19 12:05:31 -07005096 private void finishKeyguardDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005097 synchronized (mLock) {
5098 if (!mAwake || mKeyguardDrawComplete) {
5099 return; // spurious
5100 }
5101
Jeff Brown36c4db82014-09-19 12:05:31 -07005102 mKeyguardDrawComplete = true;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005103 if (mKeyguardDelegate != null) {
5104 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
5105 }
5106 }
5107
5108 finishScreenTurningOn();
5109 }
5110
5111 // Called on the DisplayManager's DisplayPowerController thread.
5112 @Override
5113 public void screenTurnedOff() {
5114 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turned off...");
5115
5116 synchronized (mLock) {
5117 mScreenOnEarly = false;
5118 mScreenOnFully = false;
5119 mWindowManagerDrawComplete = false;
5120 mScreenOnListener = null;
5121 updateOrientationListenerLp();
Jeff Brown36c4db82014-09-19 12:05:31 -07005122 }
5123 }
5124
Jeff Brown3ee549c2014-09-22 20:14:39 -07005125 // Called on the DisplayManager's DisplayPowerController thread.
Jeff Brown36c4db82014-09-19 12:05:31 -07005126 @Override
5127 public void screenTurningOn(final ScreenOnListener screenOnListener) {
Jeff Brown36c4db82014-09-19 12:05:31 -07005128 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turning on...");
Jeff Brown36c4db82014-09-19 12:05:31 -07005129
Jeff Brown3ee549c2014-09-22 20:14:39 -07005130 synchronized (mLock) {
5131 mScreenOnEarly = true;
5132 mScreenOnFully = false;
5133 mWindowManagerDrawComplete = false;
5134 mScreenOnListener = screenOnListener;
5135 updateOrientationListenerLp();
5136 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005137
Craig Mautnerc3daedd2014-09-13 11:17:23 -07005138 mWindowManagerInternal.waitForAllWindowsDrawn(mWindowManagerDrawCallback,
5139 WAITING_FOR_DRAWN_TIMEOUT);
Jeff Brown36c4db82014-09-19 12:05:31 -07005140 // ... eventually calls finishWindowsDrawn
5141 }
5142
Jeff Brown36c4db82014-09-19 12:05:31 -07005143 private void finishWindowsDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005144 synchronized (mLock) {
5145 if (!mScreenOnEarly || mWindowManagerDrawComplete) {
5146 return; // spurious
5147 }
5148
Jeff Brown36c4db82014-09-19 12:05:31 -07005149 mWindowManagerDrawComplete = true;
Jeff Brown36c4db82014-09-19 12:05:31 -07005150 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005151
5152 finishScreenTurningOn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07005153 }
5154
Craig Mautner8a0da012014-05-31 15:13:37 -07005155 private void finishScreenTurningOn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005156 final ScreenOnListener listener;
5157 final boolean enableScreen;
Jeff Brown36c4db82014-09-19 12:05:31 -07005158 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005159 if (DEBUG_WAKEUP) Slog.d(TAG,
5160 "finishScreenTurningOn: mAwake=" + mAwake
5161 + ", mScreenOnEarly=" + mScreenOnEarly
5162 + ", mScreenOnFully=" + mScreenOnFully
5163 + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete
5164 + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete);
5165
5166 if (mScreenOnFully || !mScreenOnEarly || !mWindowManagerDrawComplete
5167 || (mAwake && !mKeyguardDrawComplete)) {
5168 return; // spurious or not ready yet
Jeff Brown36c4db82014-09-19 12:05:31 -07005169 }
5170
Jeff Brown3ee549c2014-09-22 20:14:39 -07005171 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished screen turning on...");
5172 listener = mScreenOnListener;
Craig Mautner13f6ea72014-06-23 14:57:02 -07005173 mScreenOnListener = null;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005174 mScreenOnFully = true;
5175
5176 // Remember the first time we draw the keyguard so we know when we're done with
5177 // the main part of booting and can enable the screen and hide boot messages.
5178 if (!mKeyguardDrawnOnce && mAwake) {
5179 mKeyguardDrawnOnce = true;
5180 enableScreen = true;
5181 if (mBootMessageNeedsHiding) {
5182 mBootMessageNeedsHiding = false;
5183 hideBootMessages();
5184 }
5185 } else {
5186 enableScreen = false;
5187 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005188 }
5189
Jeff Brown3ee549c2014-09-22 20:14:39 -07005190 if (listener != null) {
5191 listener.onScreenOn();
5192 }
Jeff Brown4fc45272012-10-10 18:28:14 -07005193
Jeff Brown3ee549c2014-09-22 20:14:39 -07005194 if (enableScreen) {
5195 try {
5196 mWindowManager.enableScreenIfNeeded();
5197 } catch (RemoteException unhandled) {
Jeff Brown36c4db82014-09-19 12:05:31 -07005198 }
Craig Mautnera631d492014-08-05 15:16:01 -07005199 }
5200 }
5201
5202 private void handleHideBootMessage() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005203 synchronized (mLock) {
5204 if (!mKeyguardDrawnOnce) {
5205 mBootMessageNeedsHiding = true;
5206 return; // keyguard hasn't drawn the first time yet, not done booting
5207 }
Craig Mautnera631d492014-08-05 15:16:01 -07005208 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005209
5210 if (mBootMsgDialog != null) {
5211 if (DEBUG_WAKEUP) Slog.d(TAG, "handleHideBootMessage: dismissing");
5212 mBootMsgDialog.dismiss();
5213 mBootMsgDialog = null;
Craig Mautnera631d492014-08-05 15:16:01 -07005214 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005215 }
5216
5217 @Override
Jeff Brown3ee549c2014-09-22 20:14:39 -07005218 public boolean isScreenOn() {
5219 return mScreenOnFully;
Dianne Hackborn08743722009-12-21 12:16:51 -08005220 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005221
Dianne Hackborn08743722009-12-21 12:16:51 -08005222 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005223 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005224 public void enableKeyguard(boolean enabled) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005225 if (mKeyguardDelegate != null) {
5226 mKeyguardDelegate.setKeyguardEnabled(enabled);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005227 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005228 }
5229
5230 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005231 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005232 public void exitKeyguardSecurely(OnKeyguardExitResult callback) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005233 if (mKeyguardDelegate != null) {
5234 mKeyguardDelegate.verifyUnlock(callback);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005235 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005236 }
5237
Jim Millerab954542014-10-10 18:21:49 -07005238 private boolean isKeyguardShowingAndNotOccluded() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005239 if (mKeyguardDelegate == null) return false;
Jim Millerab954542014-10-10 18:21:49 -07005240 return mKeyguardDelegate.isShowing() && !mKeyguardOccluded;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005241 }
5242
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005243 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005244 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005245 public boolean isKeyguardLocked() {
5246 return keyguardOn();
5247 }
5248
5249 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005250 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005251 public boolean isKeyguardSecure() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005252 if (mKeyguardDelegate == null) return false;
5253 return mKeyguardDelegate.isSecure();
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005254 }
5255
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005256 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005257 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005258 public boolean inKeyguardRestrictedKeyInputMode() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005259 if (mKeyguardDelegate == null) return false;
5260 return mKeyguardDelegate.isInputRestricted();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005261 }
5262
Jose Lima9546b202014-07-02 17:21:51 -07005263 @Override
Dianne Hackborn90c52de2011-09-23 12:57:44 -07005264 public void dismissKeyguardLw() {
RoboErik8a2cfc32014-05-16 11:19:38 -07005265 if (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()) {
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07005266 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.dismissKeyguardLw");
Daniel Sandler1ce804392012-11-07 15:07:12 -05005267 mHandler.post(new Runnable() {
Jose Lima9546b202014-07-02 17:21:51 -07005268 @Override
Daniel Sandler1ce804392012-11-07 15:07:12 -05005269 public void run() {
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02005270 // ask the keyguard to prompt the user to authenticate if necessary
5271 mKeyguardDelegate.dismiss();
5272 }
5273 });
5274 }
5275 }
5276
5277 public void notifyActivityDrawnForKeyguardLw() {
5278 if (mKeyguardDelegate != null) {
5279 mHandler.post(new Runnable() {
5280 @Override
5281 public void run() {
5282 mKeyguardDelegate.onActivityDrawn();
Daniel Sandler1ce804392012-11-07 15:07:12 -05005283 }
5284 });
Dianne Hackborn90c52de2011-09-23 12:57:44 -07005285 }
5286 }
5287
Jorim Jaggicff0acb2014-03-31 16:35:15 +02005288 @Override
5289 public boolean isKeyguardDrawnLw() {
5290 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005291 return mKeyguardDrawnOnce;
Jorim Jaggicff0acb2014-03-31 16:35:15 +02005292 }
5293 }
5294
Jorim Jaggi0d674622014-05-21 01:34:15 +02005295 @Override
Jorim Jaggie29b2db2014-05-30 23:17:03 +02005296 public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) {
Jorim Jaggi0d674622014-05-21 01:34:15 +02005297 if (mKeyguardDelegate != null) {
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07005298 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.startKeyguardExitAnimation");
Jorim Jaggie29b2db2014-05-30 23:17:03 +02005299 mKeyguardDelegate.startKeyguardExitAnimation(startTime, fadeoutDuration);
Jorim Jaggi0d674622014-05-21 01:34:15 +02005300 }
5301 }
5302
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005303 void sendCloseSystemWindows() {
Jorim Jaggib10e33f2015-02-04 21:57:40 +01005304 PhoneWindow.sendCloseSystemWindows(mContext, null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005305 }
5306
5307 void sendCloseSystemWindows(String reason) {
Jorim Jaggib10e33f2015-02-04 21:57:40 +01005308 PhoneWindow.sendCloseSystemWindows(mContext, reason);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005309 }
Mitsuru Oshima831d0d92009-06-16 18:27:18 -07005310
Jeff Brown01a98dd2011-09-20 15:08:29 -07005311 @Override
5312 public int rotationForOrientationLw(int orientation, int lastRotation) {
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005313 if (false) {
5314 Slog.v(TAG, "rotationForOrientationLw(orient="
5315 + orientation + ", last=" + lastRotation
5316 + "); user=" + mUserRotation + " "
5317 + ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED)
5318 ? "USER_ROTATION_LOCKED" : "")
5319 );
5320 }
5321
Craig Mautner46ac6fa2013-08-01 10:06:34 -07005322 if (mForceDefaultOrientation) {
5323 return Surface.ROTATION_0;
5324 }
5325
The Android Open Source Project0727d222009-03-11 12:11:58 -07005326 synchronized (mLock) {
Jeff Brownc0347aa2011-09-23 17:26:09 -07005327 int sensorRotation = mOrientationListener.getProposedRotation(); // may be -1
5328 if (sensorRotation < 0) {
Jeff Brown0f862b42012-09-27 21:11:01 -07005329 sensorRotation = lastRotation;
Jeff Brownc0347aa2011-09-23 17:26:09 -07005330 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005331
Jeff Browndec6cf42011-11-15 14:08:20 -08005332 final int preferredRotation;
Jeff Brown2e7760e2012-04-11 15:14:55 -07005333 if (mLidState == LID_OPEN && mLidOpenRotation >= 0) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005334 // Ignore sensor when lid switch is open and rotation is forced.
5335 preferredRotation = mLidOpenRotation;
5336 } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR
Jeff Brownc0347aa2011-09-23 17:26:09 -07005337 && (mCarDockEnablesAccelerometer || mCarDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005338 // Ignore sensor when in car dock unless explicitly enabled.
5339 // This case can override the behavior of NOSENSOR, and can also
5340 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07005341 preferredRotation = mCarDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07005342 ? sensorRotation : mCarDockRotation;
Jeff Brown1a693182011-11-08 14:44:16 -08005343 } else if ((mDockMode == Intent.EXTRA_DOCK_STATE_DESK
5344 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
5345 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK)
Jeff Brownc0347aa2011-09-23 17:26:09 -07005346 && (mDeskDockEnablesAccelerometer || mDeskDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005347 // Ignore sensor when in desk dock unless explicitly enabled.
5348 // This case can override the behavior of NOSENSOR, and can also
5349 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07005350 preferredRotation = mDeskDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07005351 ? sensorRotation : mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -07005352 } else if (mHdmiPlugged && mDemoHdmiRotationLock) {
5353 // Ignore sensor when plugged into HDMI when demo HDMI rotation lock enabled.
Jeff Browneb3e4b92011-12-06 19:54:24 -08005354 // Note that the dock orientation overrides the HDMI orientation.
Jeff Brownc82c89ed2013-04-17 17:18:15 -07005355 preferredRotation = mDemoHdmiRotation;
5356 } else if (mHdmiPlugged && mDockMode == Intent.EXTRA_DOCK_STATE_UNDOCKED
5357 && mUndockedHdmiRotation >= 0) {
5358 // Ignore sensor when plugged into HDMI and an undocked orientation has
5359 // been specified in the configuration (only for legacy devices without
5360 // full multi-display support).
5361 // Note that the dock orientation overrides the HDMI orientation.
5362 preferredRotation = mUndockedHdmiRotation;
Chong Zhangae6119ff2014-11-11 18:54:39 -08005363 } else if (mDemoRotationLock) {
5364 // Ignore sensor when demo rotation lock is enabled.
5365 // Note that the dock orientation and HDMI rotation lock override this.
5366 preferredRotation = mDemoRotation;
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005367 } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED) {
5368 // Application just wants to remain locked in the last rotation.
5369 preferredRotation = lastRotation;
Jeff Brownbcdfc622014-03-06 19:13:04 -08005370 } else if (!mSupportAutoRotation) {
5371 // If we don't support auto-rotation then bail out here and ignore
5372 // the sensor and any rotation lock settings.
5373 preferredRotation = -1;
Jeff Brown207673cd2012-06-05 17:47:11 -07005374 } else if ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE
Jeff Brown01a98dd2011-09-20 15:08:29 -07005375 && (orientation == ActivityInfo.SCREEN_ORIENTATION_USER
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005376 || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
5377 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
5378 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
5379 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER))
Jeff Brown01a98dd2011-09-20 15:08:29 -07005380 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
5381 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
5382 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
5383 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) {
5384 // Otherwise, use sensor only if requested by the application or enabled
5385 // by default for USER or UNSPECIFIED modes. Does not apply to NOSENSOR.
Jeff Brownd3187e32011-09-21 19:26:44 -07005386 if (mAllowAllRotations < 0) {
5387 // Can't read this during init() because the context doesn't
5388 // have display metrics at that time so we cannot determine
5389 // tablet vs. phone then.
5390 mAllowAllRotations = mContext.getResources().getBoolean(
5391 com.android.internal.R.bool.config_allowAllRotations) ? 1 : 0;
5392 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005393 if (sensorRotation != Surface.ROTATION_180
Jeff Brownd3187e32011-09-21 19:26:44 -07005394 || mAllowAllRotations == 1
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005395 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
5396 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005397 preferredRotation = sensorRotation;
5398 } else {
5399 preferredRotation = lastRotation;
5400 }
Jeff Brown207673cd2012-06-05 17:47:11 -07005401 } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED
5402 && orientation != ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) {
5403 // Apply rotation lock. Does not apply to NOSENSOR.
5404 // The idea is that the user rotation expresses a weak preference for the direction
5405 // of gravity and as NOSENSOR is never affected by gravity, then neither should
5406 // NOSENSOR be affected by rotation lock (although it will be affected by docks).
Jeff Brown4dfce202011-10-05 12:00:10 -07005407 preferredRotation = mUserRotation;
Jeff Browndec6cf42011-11-15 14:08:20 -08005408 } else {
5409 // No overriding preference.
5410 // We will do exactly what the application asked us to do.
5411 preferredRotation = -1;
Jeff Brown01a98dd2011-09-20 15:08:29 -07005412 }
5413
Dianne Hackborne5439f22010-10-02 16:53:50 -07005414 switch (orientation) {
5415 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08005416 // Return portrait unless overridden.
5417 if (isAnyPortrait(preferredRotation)) {
5418 return preferredRotation;
5419 }
Dianne Hackborne5439f22010-10-02 16:53:50 -07005420 return mPortraitRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005421
Jeff Brown01a98dd2011-09-20 15:08:29 -07005422 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08005423 // Return landscape unless overridden.
5424 if (isLandscapeOrSeascape(preferredRotation)) {
5425 return preferredRotation;
5426 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005427 return mLandscapeRotation;
5428
5429 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08005430 // Return reverse portrait unless overridden.
5431 if (isAnyPortrait(preferredRotation)) {
5432 return preferredRotation;
5433 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005434 return mUpsideDownRotation;
5435
5436 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08005437 // Return seascape unless overridden.
5438 if (isLandscapeOrSeascape(preferredRotation)) {
5439 return preferredRotation;
5440 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005441 return mSeascapeRotation;
5442
5443 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005444 case ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE:
Jeff Brown01a98dd2011-09-20 15:08:29 -07005445 // Return either landscape rotation.
5446 if (isLandscapeOrSeascape(preferredRotation)) {
5447 return preferredRotation;
5448 }
5449 if (isLandscapeOrSeascape(lastRotation)) {
Jeff Brown4519f072011-01-23 13:16:01 -08005450 return lastRotation;
5451 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005452 return mLandscapeRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005453
Jeff Brown01a98dd2011-09-20 15:08:29 -07005454 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005455 case ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT:
Jeff Brown01a98dd2011-09-20 15:08:29 -07005456 // Return either portrait rotation.
5457 if (isAnyPortrait(preferredRotation)) {
5458 return preferredRotation;
5459 }
5460 if (isAnyPortrait(lastRotation)) {
5461 return lastRotation;
5462 }
5463 return mPortraitRotation;
5464
5465 default:
Jeff Brown4dfce202011-10-05 12:00:10 -07005466 // For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR,
5467 // just return the preferred orientation we already calculated.
Jeff Brown01a98dd2011-09-20 15:08:29 -07005468 if (preferredRotation >= 0) {
5469 return preferredRotation;
5470 }
Dianne Hackborndacea8c2011-04-21 17:26:39 -07005471 return Surface.ROTATION_0;
Daniel Sandlere7e5ac22011-02-22 16:10:21 -05005472 }
5473 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07005474 }
5475
Jeff Brown01a98dd2011-09-20 15:08:29 -07005476 @Override
5477 public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation) {
5478 switch (orientation) {
5479 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
5480 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
5481 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
5482 return isAnyPortrait(rotation);
5483
5484 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
5485 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
5486 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
5487 return isLandscapeOrSeascape(rotation);
5488
5489 default:
5490 return true;
5491 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07005492 }
5493
Jeff Brownc0347aa2011-09-23 17:26:09 -07005494 @Override
5495 public void setRotationLw(int rotation) {
5496 mOrientationListener.setCurrentRotation(rotation);
5497 }
5498
Jeff Brown01a98dd2011-09-20 15:08:29 -07005499 private boolean isLandscapeOrSeascape(int rotation) {
5500 return rotation == mLandscapeRotation || rotation == mSeascapeRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005501 }
5502
Jeff Brown01a98dd2011-09-20 15:08:29 -07005503 private boolean isAnyPortrait(int rotation) {
5504 return rotation == mPortraitRotation || rotation == mUpsideDownRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005505 }
5506
Jose Lima9546b202014-07-02 17:21:51 -07005507 @Override
Svetoslav Ganov80943d82013-01-02 10:25:37 -08005508 public int getUserRotationMode() {
5509 return Settings.System.getIntForUser(mContext.getContentResolver(),
Brett Chabot7e55c402013-05-16 19:38:08 -07005510 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
5511 WindowManagerPolicy.USER_ROTATION_FREE :
5512 WindowManagerPolicy.USER_ROTATION_LOCKED;
Svetoslav Ganov80943d82013-01-02 10:25:37 -08005513 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005514
5515 // User rotation: to be used when all else fails in assigning an orientation to the device
Jose Lima9546b202014-07-02 17:21:51 -07005516 @Override
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005517 public void setUserRotationMode(int mode, int rot) {
5518 ContentResolver res = mContext.getContentResolver();
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005519
5520 // mUserRotationMode and mUserRotation will be assigned by the content observer
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005521 if (mode == WindowManagerPolicy.USER_ROTATION_LOCKED) {
Christopher Tate5e08af02012-09-21 17:17:22 -07005522 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005523 Settings.System.USER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005524 rot,
5525 UserHandle.USER_CURRENT);
5526 Settings.System.putIntForUser(res,
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005527 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005528 0,
5529 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005530 } else {
Christopher Tate5e08af02012-09-21 17:17:22 -07005531 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005532 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005533 1,
5534 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005535 }
5536 }
5537
Jose Lima9546b202014-07-02 17:21:51 -07005538 @Override
Jeff Brownac143512012-04-05 18:57:33 -07005539 public void setSafeMode(boolean safeMode) {
5540 mSafeMode = safeMode;
5541 performHapticFeedbackLw(null, safeMode
5542 ? HapticFeedbackConstants.SAFE_MODE_ENABLED
5543 : HapticFeedbackConstants.SAFE_MODE_DISABLED, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005544 }
Craig Mautnereda67292013-04-28 13:50:14 -07005545
Dianne Hackborn181ceb52009-08-27 22:16:40 -07005546 static long[] getLongIntArray(Resources r, int resid) {
5547 int[] ar = r.getIntArray(resid);
5548 if (ar == null) {
5549 return null;
5550 }
5551 long[] out = new long[ar.length];
5552 for (int i=0; i<ar.length; i++) {
5553 out[i] = ar[i];
5554 }
5555 return out;
5556 }
Craig Mautnereda67292013-04-28 13:50:14 -07005557
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005558 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07005559 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005560 public void systemReady() {
Jim Millerab954542014-10-10 18:21:49 -07005561 mKeyguardDelegate = new KeyguardServiceDelegate(mContext);
Mike Lockwooded8902d2013-11-15 11:01:47 -08005562 mKeyguardDelegate.onSystemReady();
5563
Michael Wright3818c922014-09-02 13:59:07 -07005564 readCameraLensCoverState();
Jeff Brown4f5fa282014-06-12 19:19:15 -07005565 updateUiMode();
Dianne Hackbornb1a79802009-09-29 15:18:31 -07005566 synchronized (mLock) {
5567 updateOrientationListenerLp();
Dianne Hackbornc777e072010-02-12 13:07:59 -08005568 mSystemReady = true;
5569 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07005570 @Override
Dianne Hackbornc777e072010-02-12 13:07:59 -08005571 public void run() {
5572 updateSettings();
5573 }
5574 });
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005575 }
5576 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07005577
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005578 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005579 @Override
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005580 public void systemBooted() {
Jim Millere5f910a2013-10-16 18:15:46 -07005581 if (mKeyguardDelegate != null) {
Jason Monk5eeebf52014-09-26 12:36:51 -04005582 mKeyguardDelegate.bindService(mContext);
Jim Millere5f910a2013-10-16 18:15:46 -07005583 mKeyguardDelegate.onBootCompleted();
5584 }
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005585 synchronized (mLock) {
5586 mSystemBooted = true;
5587 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005588 wakingUp();
5589 screenTurningOn(null);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005590 }
5591
Dianne Hackborn661cd522011-08-22 00:26:20 -07005592 ProgressDialog mBootMsgDialog = null;
5593
5594 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005595 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07005596 public void showBootMessage(final CharSequence msg, final boolean always) {
5597 mHandler.post(new Runnable() {
5598 @Override public void run() {
5599 if (mBootMsgDialog == null) {
Craig Stout4c0cb8a2014-04-04 13:03:10 -07005600 int theme;
5601 if (mContext.getPackageManager().hasSystemFeature(
5602 PackageManager.FEATURE_WATCH)) {
5603 theme = com.android.internal.R.style.Theme_Micro_Dialog_Alert;
5604 } else if (mContext.getPackageManager().hasSystemFeature(
5605 PackageManager.FEATURE_TELEVISION)) {
5606 theme = com.android.internal.R.style.Theme_Leanback_Dialog_Alert;
5607 } else {
5608 theme = 0;
5609 }
Vinod Krishnanfa8fc412014-04-18 14:35:53 -07005610
5611 mBootMsgDialog = new ProgressDialog(mContext, theme) {
Dianne Hackborn295e3c22011-08-25 13:19:08 -07005612 // This dialog will consume all events coming in to
5613 // it, to avoid it trying to do things too early in boot.
5614 @Override public boolean dispatchKeyEvent(KeyEvent event) {
5615 return true;
5616 }
5617 @Override public boolean dispatchKeyShortcutEvent(KeyEvent event) {
5618 return true;
5619 }
5620 @Override public boolean dispatchTouchEvent(MotionEvent ev) {
5621 return true;
5622 }
5623 @Override public boolean dispatchTrackballEvent(MotionEvent ev) {
5624 return true;
5625 }
5626 @Override public boolean dispatchGenericMotionEvent(MotionEvent ev) {
5627 return true;
5628 }
5629 @Override public boolean dispatchPopulateAccessibilityEvent(
5630 AccessibilityEvent event) {
5631 return true;
5632 }
5633 };
Jeff Hao9f60c082014-10-28 18:51:07 -07005634 if (mContext.getPackageManager().isUpgrade()) {
5635 mBootMsgDialog.setTitle(R.string.android_upgrading_title);
5636 } else {
5637 mBootMsgDialog.setTitle(R.string.android_start_title);
5638 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07005639 mBootMsgDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
5640 mBootMsgDialog.setIndeterminate(true);
5641 mBootMsgDialog.getWindow().setType(
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07005642 WindowManager.LayoutParams.TYPE_BOOT_PROGRESS);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005643 mBootMsgDialog.getWindow().addFlags(
5644 WindowManager.LayoutParams.FLAG_DIM_BEHIND
5645 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
5646 mBootMsgDialog.getWindow().setDimAmount(1);
Dianne Hackbornd9efb952011-12-07 14:56:51 -08005647 WindowManager.LayoutParams lp = mBootMsgDialog.getWindow().getAttributes();
5648 lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
5649 mBootMsgDialog.getWindow().setAttributes(lp);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005650 mBootMsgDialog.setCancelable(false);
5651 mBootMsgDialog.show();
5652 }
5653 mBootMsgDialog.setMessage(msg);
5654 }
5655 });
5656 }
5657
5658 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005659 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07005660 public void hideBootMessages() {
Craig Mautnera631d492014-08-05 15:16:01 -07005661 mHandler.sendEmptyMessage(MSG_HIDE_BOOT_MESSAGE);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005662 }
5663
Mike Lockwood28569302010-01-28 11:54:40 -05005664 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005665 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05005666 public void userActivity() {
Dianne Hackborndf89e652011-10-06 22:35:11 -07005667 // ***************************************
5668 // NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
5669 // ***************************************
5670 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
5671 // WITH ITS LOCKS HELD.
5672 //
5673 // This code must be VERY careful about the locks
5674 // it acquires.
5675 // In fact, the current code acquires way too many,
5676 // and probably has lurking deadlocks.
5677
Mike Lockwood28569302010-01-28 11:54:40 -05005678 synchronized (mScreenLockTimeout) {
5679 if (mLockScreenTimerActive) {
5680 // reset the timer
5681 mHandler.removeCallbacks(mScreenLockTimeout);
5682 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
5683 }
5684 }
Daniel Sandler0601eb72011-04-13 01:01:32 -04005685 }
5686
Adam Cohenf7522022012-10-03 20:03:18 -07005687 class ScreenLockTimeout implements Runnable {
5688 Bundle options;
5689
5690 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05005691 public void run() {
5692 synchronized (this) {
5693 if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard");
Jim Miller5ecd8112013-01-09 18:50:26 -08005694 if (mKeyguardDelegate != null) {
5695 mKeyguardDelegate.doKeyguardTimeout(options);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005696 }
Mike Lockwood28569302010-01-28 11:54:40 -05005697 mLockScreenTimerActive = false;
Adam Cohenf7522022012-10-03 20:03:18 -07005698 options = null;
Mike Lockwood28569302010-01-28 11:54:40 -05005699 }
5700 }
Mike Lockwood28569302010-01-28 11:54:40 -05005701
Adam Cohenf7522022012-10-03 20:03:18 -07005702 public void setLockOptions(Bundle options) {
5703 this.options = options;
5704 }
5705 }
5706
5707 ScreenLockTimeout mScreenLockTimeout = new ScreenLockTimeout();
5708
Jose Lima9546b202014-07-02 17:21:51 -07005709 @Override
Adam Cohenf7522022012-10-03 20:03:18 -07005710 public void lockNow(Bundle options) {
Jim Miller93c518e2012-01-17 15:55:31 -08005711 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null);
5712 mHandler.removeCallbacks(mScreenLockTimeout);
Adam Cohenf7522022012-10-03 20:03:18 -07005713 if (options != null) {
5714 // In case multiple calls are made to lockNow, we don't wipe out the options
5715 // until the runnable actually executes.
5716 mScreenLockTimeout.setLockOptions(options);
5717 }
Jim Miller93c518e2012-01-17 15:55:31 -08005718 mHandler.post(mScreenLockTimeout);
5719 }
5720
Mike Lockwood28569302010-01-28 11:54:40 -05005721 private void updateLockScreenTimeout() {
5722 synchronized (mScreenLockTimeout) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005723 boolean enable = (mAllowLockscreenWhenOn && mAwake &&
Jim Miller5ecd8112013-01-09 18:50:26 -08005724 mKeyguardDelegate != null && mKeyguardDelegate.isSecure());
Mike Lockwood28569302010-01-28 11:54:40 -05005725 if (mLockScreenTimerActive != enable) {
5726 if (enable) {
5727 if (localLOGV) Log.v(TAG, "setting lockscreen timer");
5728 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
5729 } else {
5730 if (localLOGV) Log.v(TAG, "clearing lockscreen timer");
5731 mHandler.removeCallbacks(mScreenLockTimeout);
5732 }
5733 mLockScreenTimerActive = enable;
5734 }
5735 }
5736 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005737
5738 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07005739 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005740 public void enableScreenAfterBoot() {
5741 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07005742 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07005743 updateRotation(true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005744 }
Dianne Hackbornf54c8f92009-09-19 14:03:57 -07005745
Jeff Brownc458ce92012-04-30 14:58:40 -07005746 private void applyLidSwitchState() {
Jeff Brownc458ce92012-04-30 14:58:40 -07005747 if (mLidState == LID_CLOSED && mLidControlsSleep) {
Jeff Brown6d8fd272014-05-20 21:24:38 -07005748 mPowerManager.goToSleep(SystemClock.uptimeMillis(),
Jeff Brownc12035c2014-08-13 18:52:25 -07005749 PowerManager.GO_TO_SLEEP_REASON_LID_SWITCH,
Jeff Brown6d8fd272014-05-20 21:24:38 -07005750 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
Jeff Brownc458ce92012-04-30 14:58:40 -07005751 }
Jeff Browna20dda42014-05-27 20:57:24 -07005752
5753 synchronized (mLock) {
5754 updateWakeGestureListenerLp();
5755 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005756 }
5757
Jeff Brown4f5fa282014-06-12 19:19:15 -07005758 void updateUiMode() {
5759 if (mUiModeManager == null) {
5760 mUiModeManager = IUiModeManager.Stub.asInterface(
5761 ServiceManager.getService(Context.UI_MODE_SERVICE));
5762 }
5763 try {
5764 mUiMode = mUiModeManager.getCurrentModeType();
5765 } catch (RemoteException e) {
5766 }
5767 }
5768
Jeff Brown01a98dd2011-09-20 15:08:29 -07005769 void updateRotation(boolean alwaysSendConfiguration) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005770 try {
5771 //set orientation on WindowManager
Dianne Hackbornf87d1962012-04-04 12:48:24 -07005772 mWindowManager.updateRotation(alwaysSendConfiguration, false);
5773 } catch (RemoteException e) {
5774 // Ignore
5775 }
5776 }
5777
5778 void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) {
5779 try {
5780 //set orientation on WindowManager
5781 mWindowManager.updateRotation(alwaysSendConfiguration, forceRelayout);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005782 } catch (RemoteException e) {
5783 // Ignore
5784 }
5785 }
5786
Daniel Sandler6396c722013-04-16 20:19:09 -04005787 /**
5788 * Return an Intent to launch the currently active dock app as home. Returns
5789 * null if the standard home should be launched, which is the case if any of the following is
5790 * true:
5791 * <ul>
5792 * <li>The device is not in either car mode or desk mode
5793 * <li>The device is in car mode but ENABLE_CAR_DOCK_HOME_CAPTURE is false
5794 * <li>The device is in desk mode but ENABLE_DESK_DOCK_HOME_CAPTURE is false
5795 * <li>The device is in car mode but there's no CAR_DOCK app with METADATA_DOCK_HOME
5796 * <li>The device is in desk mode but there's no DESK_DOCK app with METADATA_DOCK_HOME
5797 * </ul>
Craig Mautnereda67292013-04-28 13:50:14 -07005798 * @return A dock intent.
Daniel Sandler6396c722013-04-16 20:19:09 -04005799 */
5800 Intent createHomeDockIntent() {
5801 Intent intent = null;
5802
5803 // What home does is based on the mode, not the dock state. That
5804 // is, when in car mode you should be taken to car home regardless
5805 // of whether we are actually in a car dock.
5806 if (mUiMode == Configuration.UI_MODE_TYPE_CAR) {
5807 if (ENABLE_CAR_DOCK_HOME_CAPTURE) {
5808 intent = mCarDockIntent;
5809 }
5810 } else if (mUiMode == Configuration.UI_MODE_TYPE_DESK) {
5811 if (ENABLE_DESK_DOCK_HOME_CAPTURE) {
5812 intent = mDeskDockIntent;
5813 }
Jeff Brown4f5fa282014-06-12 19:19:15 -07005814 } else if (mUiMode == Configuration.UI_MODE_TYPE_WATCH
5815 && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
5816 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK
5817 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK)) {
5818 // Always launch dock home from home when watch is docked, if it exists.
5819 intent = mDeskDockIntent;
Daniel Sandler6396c722013-04-16 20:19:09 -04005820 }
5821
5822 if (intent == null) {
5823 return null;
5824 }
5825
5826 ActivityInfo ai = null;
5827 ResolveInfo info = mContext.getPackageManager().resolveActivityAsUser(
5828 intent,
John Spurlockf56bef12013-07-09 09:51:46 -04005829 PackageManager.MATCH_DEFAULT_ONLY | PackageManager.GET_META_DATA,
Craig Mautnerd625ab22013-09-06 13:40:31 -07005830 mCurrentUserId);
Daniel Sandler6396c722013-04-16 20:19:09 -04005831 if (info != null) {
5832 ai = info.activityInfo;
5833 }
5834 if (ai != null
5835 && ai.metaData != null
5836 && ai.metaData.getBoolean(Intent.METADATA_DOCK_HOME)) {
5837 intent = new Intent(intent);
5838 intent.setClassName(ai.packageName, ai.name);
5839 return intent;
5840 }
5841
5842 return null;
5843 }
5844
Bryce Lee01b0c5f2015-02-05 18:24:04 -08005845 void startDockOrHome(boolean fromHomeKey) {
John Spurlockc8b46ca2013-04-08 12:59:26 -04005846 awakenDreams();
Daniel Sandler6396c722013-04-16 20:19:09 -04005847
5848 Intent dock = createHomeDockIntent();
5849 if (dock != null) {
5850 try {
Bryce Lee01b0c5f2015-02-05 18:24:04 -08005851 if (fromHomeKey) {
5852 dock.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
5853 }
Daniel Sandler6396c722013-04-16 20:19:09 -04005854 mContext.startActivityAsUser(dock, UserHandle.CURRENT);
5855 return;
5856 } catch (ActivityNotFoundException e) {
5857 }
5858 }
5859
Bryce Lee01b0c5f2015-02-05 18:24:04 -08005860 Intent intent;
5861
5862 if (fromHomeKey) {
5863 intent = new Intent(mHomeIntent);
5864 intent.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
5865 } else {
5866 intent = mHomeIntent;
5867 }
5868
5869 mContext.startActivityAsUser(intent, UserHandle.CURRENT);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005870 }
Craig Mautnereda67292013-04-28 13:50:14 -07005871
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005872 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005873 * goes to the home screen
5874 * @return whether it did anything
5875 */
5876 boolean goHome() {
5877 if (false) {
5878 // This code always brings home to the front.
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07005879 try {
5880 ActivityManagerNative.getDefault().stopAppSwitches();
5881 } catch (RemoteException e) {
5882 }
Dianne Hackborn94a679d2009-07-28 17:51:07 -07005883 sendCloseSystemWindows();
Bryce Lee01b0c5f2015-02-05 18:24:04 -08005884 startDockOrHome(false /*fromHomeKey*/);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005885 } else {
5886 // This code brings home to the front or, if it is already
5887 // at the front, puts the device to sleep.
5888 try {
Wink Savilled2e6a332010-02-12 12:12:06 -08005889 if (SystemProperties.getInt("persist.sys.uts-test-mode", 0) == 1) {
5890 /// Roll back EndcallBehavior as the cupcake design to pass P1 lab entry.
5891 Log.d(TAG, "UTS-TEST-MODE");
5892 } else {
5893 ActivityManagerNative.getDefault().stopAppSwitches();
5894 sendCloseSystemWindows();
Daniel Sandler6396c722013-04-16 20:19:09 -04005895 Intent dock = createHomeDockIntent();
5896 if (dock != null) {
5897 int result = ActivityManagerNative.getDefault()
5898 .startActivityAsUser(null, null, dock,
5899 dock.resolveTypeIfNeeded(mContext.getContentResolver()),
5900 null, null, 0,
5901 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07005902 null, null, UserHandle.USER_CURRENT);
Daniel Sandler6396c722013-04-16 20:19:09 -04005903 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
5904 return false;
5905 }
5906 }
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005907 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005908 int result = ActivityManagerNative.getDefault()
Dianne Hackbornf265ea92013-01-31 15:00:51 -08005909 .startActivityAsUser(null, null, mHomeIntent,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005910 mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()),
Dianne Hackborna4972e92012-03-14 10:38:05 -07005911 null, null, 0,
5912 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07005913 null, null, UserHandle.USER_CURRENT);
Dianne Hackborna4972e92012-03-14 10:38:05 -07005914 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005915 return false;
5916 }
5917 } catch (RemoteException ex) {
5918 // bummer, the activity manager, which is in this process, is dead
5919 }
5920 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005921 return true;
5922 }
Craig Mautnereda67292013-04-28 13:50:14 -07005923
5924 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07005925 public void setCurrentOrientationLw(int newOrientation) {
5926 synchronized (mLock) {
5927 if (newOrientation != mCurrentAppOrientation) {
5928 mCurrentAppOrientation = newOrientation;
5929 updateOrientationListenerLp();
5930 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005931 }
5932 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08005933
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07005934 private void performAuditoryFeedbackForAccessibilityIfNeed() {
5935 if (!isGlobalAccessibilityGestureEnabled()) {
5936 return;
5937 }
5938 AudioManager audioManager = (AudioManager) mContext.getSystemService(
5939 Context.AUDIO_SERVICE);
5940 if (audioManager.isSilentMode()) {
5941 return;
5942 }
5943 Ringtone ringTone = RingtoneManager.getRingtone(mContext,
5944 Settings.System.DEFAULT_NOTIFICATION_URI);
5945 ringTone.setStreamType(AudioManager.STREAM_MUSIC);
5946 ringTone.play();
5947 }
Craig Mautnereda67292013-04-28 13:50:14 -07005948
Bryce Lee584a4452014-10-21 15:55:55 -07005949 private boolean isTheaterModeEnabled() {
5950 return Settings.Global.getInt(mContext.getContentResolver(),
5951 Settings.Global.THEATER_MODE_ON, 0) == 1;
5952 }
5953
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07005954 private boolean isGlobalAccessibilityGestureEnabled() {
5955 return Settings.Global.getInt(mContext.getContentResolver(),
5956 Settings.Global.ENABLE_ACCESSIBILITY_GLOBAL_GESTURE_ENABLED, 0) == 1;
5957 }
5958
Craig Mautnereda67292013-04-28 13:50:14 -07005959 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07005960 public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) {
Svetoslav Ganov96179212012-10-10 14:17:45 -07005961 if (!mVibrator.hasVibrator()) {
5962 return false;
5963 }
Christopher Tate5e08af02012-09-21 17:17:22 -07005964 final boolean hapticsDisabled = Settings.System.getIntForUser(mContext.getContentResolver(),
5965 Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) == 0;
Jeff Brown82379ba2014-07-25 19:03:28 -07005966 if (hapticsDisabled && !always) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005967 return false;
5968 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08005969 long[] pattern = null;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005970 switch (effectId) {
5971 case HapticFeedbackConstants.LONG_PRESS:
Amith Yamasanic33cb712010-02-10 15:21:49 -08005972 pattern = mLongPressVibePattern;
5973 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07005974 case HapticFeedbackConstants.VIRTUAL_KEY:
Amith Yamasanic33cb712010-02-10 15:21:49 -08005975 pattern = mVirtualKeyVibePattern;
5976 break;
5977 case HapticFeedbackConstants.KEYBOARD_TAP:
5978 pattern = mKeyboardTapVibePattern;
5979 break;
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07005980 case HapticFeedbackConstants.CLOCK_TICK:
5981 pattern = mClockTickVibePattern;
5982 break;
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07005983 case HapticFeedbackConstants.CALENDAR_DATE:
5984 pattern = mCalendarDateVibePattern;
5985 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07005986 case HapticFeedbackConstants.SAFE_MODE_DISABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08005987 pattern = mSafeModeDisabledVibePattern;
5988 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07005989 case HapticFeedbackConstants.SAFE_MODE_ENABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08005990 pattern = mSafeModeEnabledVibePattern;
5991 break;
Amith Yamasanic33cb712010-02-10 15:21:49 -08005992 default:
5993 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005994 }
Dianne Hackbornf265ea92013-01-31 15:00:51 -08005995 int owningUid;
5996 String owningPackage;
5997 if (win != null) {
5998 owningUid = win.getOwningUid();
5999 owningPackage = win.getOwningPackage();
6000 } else {
6001 owningUid = android.os.Process.myUid();
Dianne Hackborn95d78532013-09-11 09:51:14 -07006002 owningPackage = mContext.getOpPackageName();
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006003 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006004 if (pattern.length == 1) {
6005 // One-shot vibration
John Spurlock7b414672014-07-18 13:02:39 -04006006 mVibrator.vibrate(owningUid, owningPackage, pattern[0], VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08006007 } else {
6008 // Pattern vibration
John Spurlock7b414672014-07-18 13:02:39 -04006009 mVibrator.vibrate(owningUid, owningPackage, pattern, -1, VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08006010 }
6011 return true;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006012 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07006013
6014 @Override
6015 public void keepScreenOnStartedLw() {
Daniel Sandler0601eb72011-04-13 01:01:32 -04006016 }
6017
Jeff Brownc38c9be2012-10-04 13:16:19 -07006018 @Override
6019 public void keepScreenOnStoppedLw() {
Jim Millerab954542014-10-10 18:21:49 -07006020 if (isKeyguardShowingAndNotOccluded()) {
Jim Miller25190572013-02-28 17:36:24 -08006021 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006022 }
6023 }
Mike Lockwoodfcb39242009-10-21 23:01:07 -04006024
Dianne Hackborndf89e652011-10-06 22:35:11 -07006025 private int updateSystemUiVisibilityLw() {
Joe Onorato664644d2011-01-23 17:53:23 -08006026 // If there is no window focused, there will be nobody to handle the events
6027 // anyway, so just hang on in whatever state we're in until things settle down.
Adrian Roos53f28ec2014-10-29 17:26:12 +01006028 final WindowState win = mFocusedWindow != null ? mFocusedWindow
6029 : mTopFullscreenOpaqueWindowState;
John Spurlock79da8332013-09-20 12:04:47 -04006030 if (win == null) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006031 return 0;
6032 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01006033 if ((win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 && mHideLockScreen == true) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07006034 // We are updating at a point where the keyguard has gotten
6035 // focus, but we were last in a state where the top window is
6036 // hiding it. This is probably because the keyguard as been
6037 // shown while the top window was displayed, so we want to ignore
6038 // it here because this is just a very transient change and it
6039 // will quickly lose focus once it correctly gets hidden.
6040 return 0;
6041 }
John Spurlock32beb2c2013-03-11 10:16:47 -04006042
John Spurlock1db8b682014-02-18 11:18:59 -05006043 int tmpVisibility = PolicyControl.getSystemUiVisibility(win, null)
Dianne Hackborne26ab702011-10-16 13:21:33 -07006044 & ~mResettingSystemUiFlags
6045 & ~mForceClearedSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04006046 if (mForcingShowNavBar && win.getSurfaceLayer() < mForcingShowNavBarLayer) {
John Spurlockc6d1c602014-01-17 15:22:06 -05006047 tmpVisibility &= ~PolicyControl.adjustClearableFlags(win, View.SYSTEM_UI_CLEARABLE_FLAGS);
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08006048 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01006049 tmpVisibility = updateLightStatusBarLw(tmpVisibility);
John Spurlock79da8332013-09-20 12:04:47 -04006050 final int visibility = updateSystemBarsLw(win, mLastSystemUiFlags, tmpVisibility);
John Spurlockad3e6cb2013-04-30 08:47:43 -04006051 final int diff = visibility ^ mLastSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04006052 final boolean needsMenu = win.getNeedsMenuLw(mTopFullscreenOpaqueWindowState);
Dianne Hackborne0f085d2011-11-30 18:41:15 -08006053 if (diff == 0 && mLastFocusNeedsMenu == needsMenu
John Spurlock79da8332013-09-20 12:04:47 -04006054 && mFocusedApp == win.getAppToken()) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006055 return 0;
6056 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07006057 mLastSystemUiFlags = visibility;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08006058 mLastFocusNeedsMenu = needsMenu;
John Spurlock79da8332013-09-20 12:04:47 -04006059 mFocusedApp = win.getAppToken();
Dianne Hackborndf89e652011-10-06 22:35:11 -07006060 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07006061 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07006062 public void run() {
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006063 try {
6064 IStatusBarService statusbar = getStatusBarService();
6065 if (statusbar != null) {
Adrian Roos53f28ec2014-10-29 17:26:12 +01006066 statusbar.setSystemUiVisibility(visibility, 0xffffffff, win.toString());
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006067 statusbar.topAppWindowChanged(needsMenu);
Joe Onorato664644d2011-01-23 17:53:23 -08006068 }
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006069 } catch (RemoteException e) {
6070 // re-acquire status bar service next time it is needed.
6071 mStatusBarService = null;
Joe Onorato664644d2011-01-23 17:53:23 -08006072 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07006073 }
6074 });
6075 return diff;
Joe Onorato664644d2011-01-23 17:53:23 -08006076 }
6077
Adrian Rooscd3884d2015-02-18 17:25:23 +01006078 private int updateLightStatusBarLw(int vis) {
6079 WindowState statusColorWin = isStatusBarKeyguard() && !mHideLockScreen
6080 ? mStatusBar
6081 : mTopFullscreenOpaqueOrDimmingWindowState;
6082
6083 if (statusColorWin != null) {
6084 if (statusColorWin == mTopFullscreenOpaqueWindowState) {
6085 // If the top fullscreen-or-dimming window is also the top fullscreen, respect
6086 // its light flag.
6087 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6088 vis |= PolicyControl.getSystemUiVisibility(statusColorWin, null)
6089 & View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6090 } else if (statusColorWin != null && statusColorWin.isDimming()) {
6091 // Otherwise if it's dimming, clear the light flag.
6092 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6093 }
6094 }
6095 return vis;
6096 }
6097
John Spurlock79da8332013-09-20 12:04:47 -04006098 private int updateSystemBarsLw(WindowState win, int oldVis, int vis) {
John Spurlockbd957402013-10-03 11:38:39 -04006099 // apply translucent bar vis flags
Jorim Jaggi380ecb82014-03-14 17:25:20 +01006100 WindowState transWin = isStatusBarKeyguard() && !mHideLockScreen
6101 ? mStatusBar
John Spurlockbd957402013-10-03 11:38:39 -04006102 : mTopFullscreenOpaqueWindowState;
6103 vis = mStatusBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
6104 vis = mNavigationBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
6105
John Spurlock27735a42013-08-14 17:57:38 -04006106 // prevent status bar interaction from clearing certain flags
John Spurlock79da8332013-09-20 12:04:47 -04006107 boolean statusBarHasFocus = win.getAttrs().type == TYPE_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04006108 if (statusBarHasFocus && !isStatusBarKeyguard()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04006109 int flags = View.SYSTEM_UI_FLAG_FULLSCREEN
6110 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlockcfc359a2013-09-05 10:42:03 -04006111 | View.SYSTEM_UI_FLAG_IMMERSIVE
Jorim Jaggi73fef8d2015-02-16 17:32:28 +01006112 | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
6113 | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04006114 if (mHideLockScreen) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01006115 flags |= View.STATUS_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSLUCENT;
6116 }
John Spurlockbd957402013-10-03 11:38:39 -04006117 vis = (vis & ~flags) | (oldVis & flags);
John Spurlockad3e6cb2013-04-30 08:47:43 -04006118 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04006119
Adrian Roos4fb3ee32014-08-22 19:29:09 +02006120 if (!areTranslucentBarsAllowed() && transWin != mStatusBar) {
Adrian Roosea562512014-05-05 13:33:03 +02006121 vis &= ~(View.NAVIGATION_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSLUCENT
6122 | View.SYSTEM_UI_TRANSPARENT);
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006123 }
6124
John Spurlock27735a42013-08-14 17:57:38 -04006125 // update status bar
John Spurlockf1a36642013-10-12 17:50:42 -04006126 boolean immersiveSticky =
6127 (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
John Spurlock27735a42013-08-14 17:57:38 -04006128 boolean hideStatusBarWM =
John Spurlockbd957402013-10-03 11:38:39 -04006129 mTopFullscreenOpaqueWindowState != null &&
John Spurlockc6d1c602014-01-17 15:22:06 -05006130 (PolicyControl.getWindowFlags(mTopFullscreenOpaqueWindowState, null)
John Spurlock27735a42013-08-14 17:57:38 -04006131 & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0;
6132 boolean hideStatusBarSysui =
6133 (vis & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04006134 boolean hideNavBarSysui =
6135 (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006136
John Spurlock27735a42013-08-14 17:57:38 -04006137 boolean transientStatusBarAllowed =
6138 mStatusBar != null && (
6139 hideStatusBarWM
John Spurlockf1a36642013-10-12 17:50:42 -04006140 || (hideStatusBarSysui && immersiveSticky)
John Spurlock27735a42013-08-14 17:57:38 -04006141 || statusBarHasFocus);
6142
John Spurlockf1a36642013-10-12 17:50:42 -04006143 boolean transientNavBarAllowed =
6144 mNavigationBar != null &&
6145 hideNavBarSysui && immersiveSticky;
6146
John Spurlockf25706f2013-11-07 18:02:43 -05006147 boolean denyTransientStatus = mStatusBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04006148 && !transientStatusBarAllowed && hideStatusBarSysui;
John Spurlockf25706f2013-11-07 18:02:43 -05006149 boolean denyTransientNav = mNavigationBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04006150 && !transientNavBarAllowed;
6151 if (denyTransientStatus || denyTransientNav) {
John Spurlock27735a42013-08-14 17:57:38 -04006152 // clear the clearable flags instead
John Spurlockf1a36642013-10-12 17:50:42 -04006153 clearClearableFlagsLw();
tiger_huangc58d7562014-10-23 20:24:19 +08006154 vis &= ~View.SYSTEM_UI_CLEARABLE_FLAGS;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006155 }
John Spurlock27735a42013-08-14 17:57:38 -04006156
6157 vis = mStatusBarController.updateVisibilityLw(transientStatusBarAllowed, oldVis, vis);
6158
6159 // update navigation bar
John Spurlockf1a36642013-10-12 17:50:42 -04006160 boolean oldImmersiveMode = isImmersiveMode(oldVis);
6161 boolean newImmersiveMode = isImmersiveMode(vis);
6162 if (win != null && oldImmersiveMode != newImmersiveMode) {
John Spurlock79da8332013-09-20 12:04:47 -04006163 final String pkg = win.getOwningPackage();
Maurice Lam99c6e072014-04-28 18:24:28 -07006164 mImmersiveModeConfirmation.immersiveModeChanged(pkg, newImmersiveMode,
6165 isUserSetupComplete());
John Spurlock34e13d92013-08-10 06:52:28 -04006166 }
John Spurlock27735a42013-08-14 17:57:38 -04006167
John Spurlockf1a36642013-10-12 17:50:42 -04006168 vis = mNavigationBarController.updateVisibilityLw(transientNavBarAllowed, oldVis, vis);
6169
John Spurlocke1f366f2013-08-05 12:22:40 -04006170 return vis;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006171 }
6172
John Spurlockf1a36642013-10-12 17:50:42 -04006173 private void clearClearableFlagsLw() {
6174 int newVal = mResettingSystemUiFlags | View.SYSTEM_UI_CLEARABLE_FLAGS;
6175 if (newVal != mResettingSystemUiFlags) {
6176 mResettingSystemUiFlags = newVal;
6177 mWindowManagerFuncs.reevaluateStatusBarVisibility();
6178 }
6179 }
6180
6181 private boolean isImmersiveMode(int vis) {
6182 final int flags = View.SYSTEM_UI_FLAG_IMMERSIVE | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
John Spurlock34e13d92013-08-10 06:52:28 -04006183 return mNavigationBar != null
6184 && (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0
Daniel Sandler900ece52013-10-18 15:53:27 -04006185 && (vis & flags) != 0
6186 && canHideNavigationBar();
John Spurlock34e13d92013-08-10 06:52:28 -04006187 }
6188
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006189 /**
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04006190 * @return whether the navigation or status bar can be made translucent
6191 *
6192 * This should return true unless touch exploration is not enabled or
6193 * R.boolean.config_enableTranslucentDecor is false.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006194 */
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04006195 private boolean areTranslucentBarsAllowed() {
Svetoslav8e3feb12014-02-24 13:46:47 -08006196 return mTranslucentDecorEnabled
6197 && !mAccessibilityManager.isTouchExplorationEnabled();
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006198 }
6199
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04006200 // Use this instead of checking config_showNavigationBar so that it can be consistently
6201 // overridden by qemu.hw.mainkeys in the emulator.
Craig Mautnereda67292013-04-28 13:50:14 -07006202 @Override
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04006203 public boolean hasNavigationBar() {
6204 return mHasNavigationBar;
6205 }
6206
satok1bc0a492012-04-25 22:47:12 +09006207 @Override
6208 public void setLastInputMethodWindowLw(WindowState ime, WindowState target) {
6209 mLastInputMethodWindow = ime;
6210 mLastInputMethodTargetWindow = target;
6211 }
6212
Craig Mautnerf1b67412012-09-19 13:18:29 -07006213 @Override
Satoshi Kataoka658c7b82013-10-10 17:03:51 +09006214 public int getInputMethodWindowVisibleHeightLw() {
6215 return mDockBottom - mCurBottom;
6216 }
6217
6218 @Override
Craig Mautnerf1b67412012-09-19 13:18:29 -07006219 public void setCurrentUserLw(int newUserId) {
Craig Mautnerd625ab22013-09-06 13:40:31 -07006220 mCurrentUserId = newUserId;
Jim Miller5ecd8112013-01-09 18:50:26 -08006221 if (mKeyguardDelegate != null) {
6222 mKeyguardDelegate.setCurrentUser(newUserId);
Craig Mautnerf1b67412012-09-19 13:18:29 -07006223 }
John Spurlock13451a22012-09-28 14:40:41 -04006224 if (mStatusBarService != null) {
6225 try {
6226 mStatusBarService.setCurrentUser(newUserId);
6227 } catch (RemoteException e) {
6228 // oh well
6229 }
6230 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006231 setLastInputMethodWindowLw(null, null);
Craig Mautnerf1b67412012-09-19 13:18:29 -07006232 }
6233
6234 @Override
Svetoslav Ganov545252f2012-12-10 18:29:24 -08006235 public boolean canMagnifyWindow(int windowType) {
6236 switch (windowType) {
6237 case WindowManager.LayoutParams.TYPE_INPUT_METHOD:
6238 case WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG:
6239 case WindowManager.LayoutParams.TYPE_NAVIGATION_BAR:
6240 case WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY: {
6241 return false;
6242 }
6243 }
6244 return true;
6245 }
6246
6247 @Override
6248 public boolean isTopLevelWindow(int windowType) {
6249 if (windowType >= WindowManager.LayoutParams.FIRST_SUB_WINDOW
6250 && windowType <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
6251 return (windowType == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG);
6252 }
6253 return true;
6254 }
6255
Jim Miller4eeb4f62012-11-08 00:04:29 -08006256 @Override
Jeff Brownd7a04de2012-06-17 14:17:52 -07006257 public void dump(String prefix, PrintWriter pw, String[] args) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006258 pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07006259 pw.print(" mSystemReady="); pw.print(mSystemReady);
6260 pw.print(" mSystemBooted="); pw.println(mSystemBooted);
Jeff Brown2e7760e2012-04-11 15:14:55 -07006261 pw.print(prefix); pw.print("mLidState="); pw.print(mLidState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006262 pw.print(" mLidOpenRotation="); pw.print(mLidOpenRotation);
Michael Wright3818c922014-09-02 13:59:07 -07006263 pw.print(" mCameraLensCoverState="); pw.print(mCameraLensCoverState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006264 pw.print(" mHdmiPlugged="); pw.println(mHdmiPlugged);
Dianne Hackborne26ab702011-10-16 13:21:33 -07006265 if (mLastSystemUiFlags != 0 || mResettingSystemUiFlags != 0
6266 || mForceClearedSystemUiFlags != 0) {
6267 pw.print(prefix); pw.print("mLastSystemUiFlags=0x");
6268 pw.print(Integer.toHexString(mLastSystemUiFlags));
6269 pw.print(" mResettingSystemUiFlags=0x");
6270 pw.print(Integer.toHexString(mResettingSystemUiFlags));
6271 pw.print(" mForceClearedSystemUiFlags=0x");
6272 pw.println(Integer.toHexString(mForceClearedSystemUiFlags));
Dianne Hackborndf89e652011-10-06 22:35:11 -07006273 }
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08006274 if (mLastFocusNeedsMenu) {
6275 pw.print(prefix); pw.print("mLastFocusNeedsMenu=");
6276 pw.println(mLastFocusNeedsMenu);
6277 }
Jeff Browna20dda42014-05-27 20:57:24 -07006278 pw.print(prefix); pw.print("mWakeGestureEnabledSetting=");
6279 pw.println(mWakeGestureEnabledSetting);
6280
Jeff Brownbcdfc622014-03-06 19:13:04 -08006281 pw.print(prefix); pw.print("mSupportAutoRotation="); pw.println(mSupportAutoRotation);
Daniel Sandler6396c722013-04-16 20:19:09 -04006282 pw.print(prefix); pw.print("mUiMode="); pw.print(mUiMode);
6283 pw.print(" mDockMode="); pw.print(mDockMode);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006284 pw.print(" mCarDockRotation="); pw.print(mCarDockRotation);
6285 pw.print(" mDeskDockRotation="); pw.println(mDeskDockRotation);
6286 pw.print(prefix); pw.print("mUserRotationMode="); pw.print(mUserRotationMode);
6287 pw.print(" mUserRotation="); pw.print(mUserRotation);
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05006288 pw.print(" mAllowAllRotations="); pw.println(mAllowAllRotations);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07006289 pw.print(prefix); pw.print("mCurrentAppOrientation="); pw.println(mCurrentAppOrientation);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006290 pw.print(prefix); pw.print("mCarDockEnablesAccelerometer=");
6291 pw.print(mCarDockEnablesAccelerometer);
6292 pw.print(" mDeskDockEnablesAccelerometer=");
6293 pw.println(mDeskDockEnablesAccelerometer);
6294 pw.print(prefix); pw.print("mLidKeyboardAccessibility=");
6295 pw.print(mLidKeyboardAccessibility);
6296 pw.print(" mLidNavigationAccessibility="); pw.print(mLidNavigationAccessibility);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07006297 pw.print(" mLidControlsSleep="); pw.println(mLidControlsSleep);
Jeff Brown6d8fd272014-05-20 21:24:38 -07006298 pw.print(prefix);
6299 pw.print("mShortPressOnPowerBehavior="); pw.print(mShortPressOnPowerBehavior);
6300 pw.print(" mLongPressOnPowerBehavior="); pw.println(mLongPressOnPowerBehavior);
Jeff Brown13f00f02014-10-31 14:45:50 -07006301 pw.print(prefix);
6302 pw.print("mDoublePressOnPowerBehavior="); pw.print(mDoublePressOnPowerBehavior);
6303 pw.print(" mTriplePressOnPowerBehavior="); pw.println(mTriplePressOnPowerBehavior);
Jeff Brown6d8fd272014-05-20 21:24:38 -07006304 pw.print(prefix); pw.print("mHasSoftInput="); pw.println(mHasSoftInput);
Jeff Brown3ee549c2014-09-22 20:14:39 -07006305 pw.print(prefix); pw.print("mAwake="); pw.println(mAwake);
6306 pw.print(prefix); pw.print("mScreenOnEarly="); pw.print(mScreenOnEarly);
6307 pw.print(" mScreenOnFully="); pw.println(mScreenOnFully);
6308 pw.print(prefix); pw.print("mKeyguardDrawComplete="); pw.print(mKeyguardDrawComplete);
6309 pw.print(" mWindowManagerDrawComplete="); pw.println(mWindowManagerDrawComplete);
6310 pw.print(prefix); pw.print("mOrientationSensorEnabled=");
6311 pw.println(mOrientationSensorEnabled);
Dianne Hackbornc652de82013-02-15 16:32:56 -08006312 pw.print(prefix); pw.print("mOverscanScreen=("); pw.print(mOverscanScreenLeft);
6313 pw.print(","); pw.print(mOverscanScreenTop);
6314 pw.print(") "); pw.print(mOverscanScreenWidth);
6315 pw.print("x"); pw.println(mOverscanScreenHeight);
6316 if (mOverscanLeft != 0 || mOverscanTop != 0
6317 || mOverscanRight != 0 || mOverscanBottom != 0) {
6318 pw.print(prefix); pw.print("mOverscan left="); pw.print(mOverscanLeft);
6319 pw.print(" top="); pw.print(mOverscanTop);
6320 pw.print(" right="); pw.print(mOverscanRight);
6321 pw.print(" bottom="); pw.println(mOverscanBottom);
6322 }
Dianne Hackborn313440842013-02-19 19:22:59 -08006323 pw.print(prefix); pw.print("mRestrictedOverscanScreen=(");
6324 pw.print(mRestrictedOverscanScreenLeft);
6325 pw.print(","); pw.print(mRestrictedOverscanScreenTop);
6326 pw.print(") "); pw.print(mRestrictedOverscanScreenWidth);
6327 pw.print("x"); pw.println(mRestrictedOverscanScreenHeight);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006328 pw.print(prefix); pw.print("mUnrestrictedScreen=("); pw.print(mUnrestrictedScreenLeft);
6329 pw.print(","); pw.print(mUnrestrictedScreenTop);
6330 pw.print(") "); pw.print(mUnrestrictedScreenWidth);
6331 pw.print("x"); pw.println(mUnrestrictedScreenHeight);
6332 pw.print(prefix); pw.print("mRestrictedScreen=("); pw.print(mRestrictedScreenLeft);
6333 pw.print(","); pw.print(mRestrictedScreenTop);
6334 pw.print(") "); pw.print(mRestrictedScreenWidth);
6335 pw.print("x"); pw.println(mRestrictedScreenHeight);
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07006336 pw.print(prefix); pw.print("mStableFullscreen=("); pw.print(mStableFullscreenLeft);
6337 pw.print(","); pw.print(mStableFullscreenTop);
6338 pw.print(")-("); pw.print(mStableFullscreenRight);
6339 pw.print(","); pw.print(mStableFullscreenBottom); pw.println(")");
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07006340 pw.print(prefix); pw.print("mStable=("); pw.print(mStableLeft);
6341 pw.print(","); pw.print(mStableTop);
6342 pw.print(")-("); pw.print(mStableRight);
6343 pw.print(","); pw.print(mStableBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07006344 pw.print(prefix); pw.print("mSystem=("); pw.print(mSystemLeft);
6345 pw.print(","); pw.print(mSystemTop);
6346 pw.print(")-("); pw.print(mSystemRight);
6347 pw.print(","); pw.print(mSystemBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006348 pw.print(prefix); pw.print("mCur=("); pw.print(mCurLeft);
6349 pw.print(","); pw.print(mCurTop);
6350 pw.print(")-("); pw.print(mCurRight);
6351 pw.print(","); pw.print(mCurBottom); pw.println(")");
6352 pw.print(prefix); pw.print("mContent=("); pw.print(mContentLeft);
6353 pw.print(","); pw.print(mContentTop);
6354 pw.print(")-("); pw.print(mContentRight);
6355 pw.print(","); pw.print(mContentBottom); pw.println(")");
Dianne Hackborne30e02f2014-05-27 18:24:45 -07006356 pw.print(prefix); pw.print("mVoiceContent=("); pw.print(mVoiceContentLeft);
6357 pw.print(","); pw.print(mVoiceContentTop);
6358 pw.print(")-("); pw.print(mVoiceContentRight);
6359 pw.print(","); pw.print(mVoiceContentBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006360 pw.print(prefix); pw.print("mDock=("); pw.print(mDockLeft);
6361 pw.print(","); pw.print(mDockTop);
6362 pw.print(")-("); pw.print(mDockRight);
6363 pw.print(","); pw.print(mDockBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07006364 pw.print(prefix); pw.print("mDockLayer="); pw.print(mDockLayer);
6365 pw.print(" mStatusBarLayer="); pw.println(mStatusBarLayer);
Dianne Hackborn7ad44382012-10-18 17:46:00 -07006366 pw.print(prefix); pw.print("mShowingLockscreen="); pw.print(mShowingLockscreen);
6367 pw.print(" mShowingDream="); pw.print(mShowingDream);
6368 pw.print(" mDreamingLockscreen="); pw.println(mDreamingLockscreen);
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006369 if (mLastInputMethodWindow != null) {
6370 pw.print(prefix); pw.print("mLastInputMethodWindow=");
6371 pw.println(mLastInputMethodWindow);
6372 }
6373 if (mLastInputMethodTargetWindow != null) {
6374 pw.print(prefix); pw.print("mLastInputMethodTargetWindow=");
6375 pw.println(mLastInputMethodTargetWindow);
6376 }
6377 if (mStatusBar != null) {
6378 pw.print(prefix); pw.print("mStatusBar=");
Dianne Hackbornae6688b2015-02-11 17:02:41 -08006379 pw.print(mStatusBar); pw.print(" isStatusBarKeyguard=");
6380 pw.println(isStatusBarKeyguard());
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006381 }
6382 if (mNavigationBar != null) {
6383 pw.print(prefix); pw.print("mNavigationBar=");
6384 pw.println(mNavigationBar);
6385 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006386 if (mFocusedWindow != null) {
6387 pw.print(prefix); pw.print("mFocusedWindow=");
6388 pw.println(mFocusedWindow);
6389 }
6390 if (mFocusedApp != null) {
6391 pw.print(prefix); pw.print("mFocusedApp=");
6392 pw.println(mFocusedApp);
6393 }
6394 if (mWinDismissingKeyguard != null) {
6395 pw.print(prefix); pw.print("mWinDismissingKeyguard=");
6396 pw.println(mWinDismissingKeyguard);
6397 }
6398 if (mTopFullscreenOpaqueWindowState != null) {
6399 pw.print(prefix); pw.print("mTopFullscreenOpaqueWindowState=");
6400 pw.println(mTopFullscreenOpaqueWindowState);
6401 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01006402 if (mTopFullscreenOpaqueOrDimmingWindowState != null) {
6403 pw.print(prefix); pw.print("mTopFullscreenOpaqueOrDimmingWindowState=");
6404 pw.println(mTopFullscreenOpaqueOrDimmingWindowState);
6405 }
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08006406 if (mForcingShowNavBar) {
6407 pw.print(prefix); pw.print("mForcingShowNavBar=");
6408 pw.println(mForcingShowNavBar); pw.print( "mForcingShowNavBarLayer=");
6409 pw.println(mForcingShowNavBarLayer);
6410 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07006411 pw.print(prefix); pw.print("mTopIsFullscreen="); pw.print(mTopIsFullscreen);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006412 pw.print(" mHideLockScreen="); pw.println(mHideLockScreen);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07006413 pw.print(prefix); pw.print("mForceStatusBar="); pw.print(mForceStatusBar);
6414 pw.print(" mForceStatusBarFromKeyguard=");
6415 pw.println(mForceStatusBarFromKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006416 pw.print(prefix); pw.print("mDismissKeyguard="); pw.print(mDismissKeyguard);
Craig Mautnerad09bcc2012-10-08 13:33:11 -07006417 pw.print(" mWinDismissingKeyguard="); pw.print(mWinDismissingKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006418 pw.print(" mHomePressed="); pw.println(mHomePressed);
6419 pw.print(prefix); pw.print("mAllowLockscreenWhenOn="); pw.print(mAllowLockscreenWhenOn);
6420 pw.print(" mLockScreenTimeout="); pw.print(mLockScreenTimeout);
6421 pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive);
6422 pw.print(prefix); pw.print("mEndcallBehavior="); pw.print(mEndcallBehavior);
6423 pw.print(" mIncallPowerBehavior="); pw.print(mIncallPowerBehavior);
6424 pw.print(" mLongPressOnHomeBehavior="); pw.println(mLongPressOnHomeBehavior);
6425 pw.print(prefix); pw.print("mLandscapeRotation="); pw.print(mLandscapeRotation);
6426 pw.print(" mSeascapeRotation="); pw.println(mSeascapeRotation);
6427 pw.print(prefix); pw.print("mPortraitRotation="); pw.print(mPortraitRotation);
6428 pw.print(" mUpsideDownRotation="); pw.println(mUpsideDownRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07006429 pw.print(prefix); pw.print("mDemoHdmiRotation="); pw.print(mDemoHdmiRotation);
6430 pw.print(" mDemoHdmiRotationLock="); pw.println(mDemoHdmiRotationLock);
6431 pw.print(prefix); pw.print("mUndockedHdmiRotation="); pw.println(mUndockedHdmiRotation);
Jeff Brown600f0032014-05-22 17:06:00 -07006432
Tim Kilbournd7c0c2e2014-05-29 16:08:10 -07006433 mGlobalKeyManager.dump(prefix, pw);
John Spurlock27735a42013-08-14 17:57:38 -04006434 mStatusBarController.dump(pw, prefix);
6435 mNavigationBarController.dump(pw, prefix);
John Spurlockc6d1c602014-01-17 15:22:06 -05006436 PolicyControl.dump(prefix, pw);
Jeff Brown600f0032014-05-22 17:06:00 -07006437
Jeff Browna20dda42014-05-27 20:57:24 -07006438 if (mWakeGestureListener != null) {
6439 mWakeGestureListener.dump(pw, prefix);
6440 }
Jeff Brown600f0032014-05-22 17:06:00 -07006441 if (mOrientationListener != null) {
6442 mOrientationListener.dump(pw, prefix);
6443 }
Filip Gruszczynskicfb31852015-02-25 21:47:12 +00006444 if (mBurnInProtectionHelper != null) {
6445 mBurnInProtectionHelper.dump(prefix, pw);
6446 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006447 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006448}