blob: 271ec759b57eeaa00881056be3c59c08b8970b9f [file] [log] [blame]
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001/*
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
Jorim Jaggib10e33f2015-02-04 21:57:40 +010016package com.android.server.policy;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080017
Dianne Hackborna4972e92012-03-14 10:38:05 -070018import android.app.ActivityManager;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080019import android.app.ActivityManagerNative;
Dianne Hackbornc2293022013-02-06 23:14:49 -080020import android.app.AppOpsManager;
Daniel Sandler6396c722013-04-16 20:19:09 -040021import android.app.IUiModeManager;
Dianne Hackborn661cd522011-08-22 00:26:20 -070022import android.app.ProgressDialog;
Jeff Brownde7a8ea2012-06-13 18:28:57 -070023import android.app.SearchManager;
John Spurlock97642182013-07-29 17:58:39 -040024import android.app.StatusBarManager;
Dianne Hackborn78968392010-03-04 20:47:56 -080025import android.app.UiModeManager;
Dianne Hackborn39c2d712009-09-22 11:41:31 -070026import android.content.ActivityNotFoundException;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080027import android.content.BroadcastReceiver;
Daniel Sandler0601eb72011-04-13 01:01:32 -040028import android.content.ComponentName;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080029import android.content.ContentResolver;
30import android.content.Context;
31import android.content.Intent;
Mike Lockwood1753f7f2009-08-24 14:49:07 -070032import android.content.IntentFilter;
Winson Chung9112ec32011-06-27 13:15:32 -070033import android.content.ServiceConnection;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080034import android.content.pm.ActivityInfo;
35import android.content.pm.PackageManager;
Daniel Sandler6396c722013-04-16 20:19:09 -040036import android.content.pm.ResolveInfo;
Dianne Hackborn2f0b1752011-05-31 17:59:49 -070037import android.content.res.CompatibilityInfo;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080038import android.content.res.Configuration;
39import android.content.res.Resources;
Craig Mautner8e4df6c2012-05-23 16:57:23 -070040import android.content.res.TypedArray;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080041import android.database.ContentObserver;
Dianne Hackbornc777e072010-02-12 13:07:59 -080042import android.graphics.PixelFormat;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080043import android.graphics.Rect;
John Spurlock7b414672014-07-18 13:02:39 -040044import android.media.AudioAttributes;
Michael Jurka7a348952012-02-27 13:07:58 -080045import android.media.AudioManager;
John Spurlock61560172015-02-06 19:46:04 -050046import android.media.AudioSystem;
Michael Jurka7a348952012-02-27 13:07:58 -080047import android.media.IAudioService;
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -070048import android.media.Ringtone;
49import android.media.RingtoneManager;
RoboErik8a2cfc32014-05-16 11:19:38 -070050import android.media.session.MediaSessionLegacyHelper;
Dianne Hackborn38e29a62011-09-18 14:43:08 -070051import android.os.Bundle;
Craig Mautner276a6eb2014-11-04 15:32:57 -080052import android.os.Debug;
Jeff Brown9a538ee2012-08-20 14:56:57 -070053import android.os.FactoryTest;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080054import android.os.Handler;
55import android.os.IBinder;
Jeff Brown32cbc38552011-12-01 14:01:49 -080056import android.os.Looper;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -070057import android.os.Message;
58import android.os.Messenger;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080059import android.os.PowerManager;
60import android.os.RemoteException;
61import android.os.ServiceManager;
62import android.os.SystemClock;
63import android.os.SystemProperties;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -080064import android.os.UEventObserver;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -070065import android.os.UserHandle;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080066import android.os.Vibrator;
Michael Wright3818c922014-09-02 13:59:07 -070067import android.provider.MediaStore;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080068import android.provider.Settings;
Jose Lima9546b202014-07-02 17:21:51 -070069import android.service.dreams.DreamManagerInternal;
John Spurlockc8b46ca2013-04-08 12:59:26 -040070import android.service.dreams.DreamService;
71import android.service.dreams.IDreamManager;
Michael Wrightdc63f7b2014-08-21 19:05:21 -070072import android.speech.RecognizerIntent;
Tyler Gunnef9f6f92014-09-12 22:16:17 -070073import android.telecom.TelecomManager;
Dianne Hackborn81e56d52011-05-26 00:55:58 -070074import android.util.DisplayMetrics;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080075import android.util.EventLog;
76import android.util.Log;
Jeff Browna41ca772010-08-11 14:46:32 -070077import android.util.Slog;
Jeff Brown6651a632011-11-28 12:59:11 -080078import android.util.SparseArray;
Dianne Hackbornf87d1962012-04-04 12:48:24 -070079import android.view.Display;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080080import android.view.Gravity;
81import android.view.HapticFeedbackConstants;
Dianne Hackborne0f085d2011-11-30 18:41:15 -080082import android.view.IApplicationToken;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080083import android.view.IWindowManager;
Jeff Browna41ca772010-08-11 14:46:32 -070084import android.view.InputChannel;
Jeff Brown4d396052010-10-29 21:50:21 -070085import android.view.InputDevice;
Jeff Brown4952dfd2011-11-30 19:23:22 -080086import android.view.InputEvent;
Jeff Brown32cbc38552011-12-01 14:01:49 -080087import android.view.InputEventReceiver;
Jeff Brown6b53e8d2010-11-10 16:03:06 -080088import android.view.KeyCharacterMap;
Craig Mautnerae446592012-12-06 19:05:05 -080089import android.view.KeyCharacterMap.FallbackAction;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080090import android.view.KeyEvent;
91import android.view.MotionEvent;
Jorim Jaggib10e33f2015-02-04 21:57:40 +010092import android.view.PhoneWindow;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080093import android.view.Surface;
94import android.view.View;
95import android.view.ViewConfiguration;
96import android.view.Window;
97import android.view.WindowManager;
Craig Mautnerae446592012-12-06 19:05:05 -080098import android.view.WindowManagerGlobal;
Craig Mautner8a0da012014-05-31 15:13:37 -070099import android.view.WindowManagerInternal;
Craig Mautnerae446592012-12-06 19:05:05 -0800100import android.view.WindowManagerPolicy;
Craig Mautnerae446592012-12-06 19:05:05 -0800101import android.view.accessibility.AccessibilityEvent;
Svetoslav8e3feb12014-02-24 13:46:47 -0800102import android.view.accessibility.AccessibilityManager;
Craig Mautnerae446592012-12-06 19:05:05 -0800103import android.view.animation.Animation;
Jorim Jaggi76a16232014-08-08 17:00:47 +0200104import android.view.animation.AnimationSet;
Craig Mautnerae446592012-12-06 19:05:05 -0800105import android.view.animation.AnimationUtils;
106
107import 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;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800256
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700257 // Vibrator pattern for haptic feedback of a long press.
258 long[] mLongPressVibePattern;
Craig Mautner88400d32012-09-30 12:35:45 -0700259
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700260 // Vibrator pattern for haptic feedback of virtual key press.
261 long[] mVirtualKeyVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700262
Amith Yamasanic33cb712010-02-10 15:21:49 -0800263 // Vibrator pattern for a short vibration.
264 long[] mKeyboardTapVibePattern;
265
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -0700266 // Vibrator pattern for a short vibration when tapping on an hour/minute tick of a Clock.
267 long[] mClockTickVibePattern;
268
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -0700269 // Vibrator pattern for a short vibration when tapping on a day/month/year date of a Calendar.
270 long[] mCalendarDateVibePattern;
271
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700272 // Vibrator pattern for haptic feedback during boot when safe mode is disabled.
273 long[] mSafeModeDisabledVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700274
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700275 // Vibrator pattern for haptic feedback during boot when safe mode is enabled.
276 long[] mSafeModeEnabledVibePattern;
Romain Guy8154cd32010-03-29 14:41:15 -0700277
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800278 /** If true, hitting shift & menu will broadcast Intent.ACTION_BUG_REPORT */
279 boolean mEnableShiftMenuBugReports = false;
Mike Lockwoodd747dc82011-09-13 16:28:22 -0400280
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800281 boolean mSafeMode;
282 WindowState mStatusBar = null;
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700283 int mStatusBarHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400284 WindowState mNavigationBar = null;
Daniel Sandler36412a72011-08-04 09:35:13 -0400285 boolean mHasNavigationBar = false;
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700286 boolean mCanHideNavigationBar = false;
Daniel Sandler4a066c52012-04-20 14:49:13 -0400287 boolean mNavigationBarCanMove = false; // can the navigation bar ever move to the side?
288 boolean mNavigationBarOnBottom = true; // is the navigation bar on the bottom *right now*?
289 int[] mNavigationBarHeightForRotation = new int[4];
290 int[] mNavigationBarWidthForRotation = new int[4];
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400291
Craig Mautnera631d492014-08-05 15:16:01 -0700292 boolean mBootMessageNeedsHiding;
Jim Miller5ecd8112013-01-09 18:50:26 -0800293 KeyguardServiceDelegate mKeyguardDelegate;
Craig Mautner13f6ea72014-06-23 14:57:02 -0700294 final Runnable mWindowManagerDrawCallback = new Runnable() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700295 @Override
Craig Mautner13f6ea72014-06-23 14:57:02 -0700296 public void run() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700297 if (DEBUG_WAKEUP) Slog.i(TAG, "All windows ready for display!");
298 mHandler.sendEmptyMessage(MSG_WINDOW_MANAGER_DRAWN_COMPLETE);
299 }
300 };
301 final ShowListener mKeyguardDelegateCallback = new ShowListener() {
302 @Override
303 public void onShown(IBinder windowToken) {
304 if (DEBUG_WAKEUP) Slog.d(TAG, "mKeyguardDelegate.ShowListener.onShown.");
305 mHandler.sendEmptyMessage(MSG_KEYGUARD_DRAWN_COMPLETE);
306 }
307 };
308
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800309 GlobalActions mGlobalActions;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800310 Handler mHandler;
satok1bc0a492012-04-25 22:47:12 +0900311 WindowState mLastInputMethodWindow = null;
312 WindowState mLastInputMethodTargetWindow = null;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800313
Jeff Brown13f00f02014-10-31 14:45:50 -0700314 // FIXME This state is shared between the input reader and handler thread.
315 // Technically it's broken and buggy but it has been like this for many years
316 // and we have not yet seen any problems. Someday we'll rewrite this logic
317 // so that only one thread is involved in handling input policy. Unfortunately
318 // it's on a critical path for power management so we can't just post the work to the
319 // handler thread. We'll need to resolve this someday by teaching the input dispatcher
320 // to hold wakelocks during dispatch and eliminating the critical path.
321 volatile boolean mPowerKeyHandled;
Bryce Leed9268e32014-11-17 17:40:59 -0800322 volatile boolean mBeganFromNonInteractive;
Jeff Brown13f00f02014-10-31 14:45:50 -0700323 volatile int mPowerKeyPressCounter;
324 volatile boolean mEndCallKeyHandled;
325
Winson Chungd42a6cf2014-06-03 16:24:04 -0700326 boolean mRecentsVisible;
Winson Chung1e8d71b2014-05-16 17:05:22 -0700327 int mRecentAppsHeldModifiers;
Jeff Browncf39bdf2012-05-18 14:41:19 -0700328 boolean mLanguageSwitchKeyPressed;
Jeff Brown68b909d2011-12-07 16:36:01 -0800329
Jeff Brown2e7760e2012-04-11 15:14:55 -0700330 int mLidState = LID_ABSENT;
Michael Wright3818c922014-09-02 13:59:07 -0700331 int mCameraLensCoverState = CAMERA_LENS_COVER_ABSENT;
Jeff Browndaa37532012-05-01 15:54:03 -0700332 boolean mHaveBuiltInKeyboard;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800333
Dianne Hackbornc777e072010-02-12 13:07:59 -0800334 boolean mSystemReady;
Dianne Hackbornba24e4d2011-09-01 11:17:06 -0700335 boolean mSystemBooted;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800336 boolean mHdmiPlugged;
Jeff Brown4f5fa282014-06-12 19:19:15 -0700337 IUiModeManager mUiModeManager;
Daniel Sandler6396c722013-04-16 20:19:09 -0400338 int mUiMode;
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700339 int mDockMode = Intent.EXTRA_DOCK_STATE_UNDOCKED;
Mike Lockwood1753f7f2009-08-24 14:49:07 -0700340 int mLidOpenRotation;
Mike Lockwood2d1efbd2009-09-16 12:15:53 -0400341 int mCarDockRotation;
342 int mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -0700343 int mUndockedHdmiRotation;
344 int mDemoHdmiRotation;
345 boolean mDemoHdmiRotationLock;
Chong Zhangae6119ff2014-11-11 18:54:39 -0800346 int mDemoRotation;
347 boolean mDemoRotationLock;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400348
Jeff Browna20dda42014-05-27 20:57:24 -0700349 boolean mWakeGestureEnabledSetting;
350 MyWakeGestureListener mWakeGestureListener;
351
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700352 // Default display does not rotate, apps that require non-default orientation will have to
353 // have the orientation emulated.
354 private boolean mForceDefaultOrientation = false;
355
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400356 int mUserRotationMode = WindowManagerPolicy.USER_ROTATION_FREE;
357 int mUserRotation = Surface.ROTATION_0;
Jeff Brown207673cd2012-06-05 17:47:11 -0700358 boolean mAccelerometerDefault;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400359
Jeff Brownbcdfc622014-03-06 19:13:04 -0800360 boolean mSupportAutoRotation;
Jeff Brownd3187e32011-09-21 19:26:44 -0700361 int mAllowAllRotations = -1;
Mike Lockwoode9867d22009-09-20 01:59:02 -0400362 boolean mCarDockEnablesAccelerometer;
363 boolean mDeskDockEnablesAccelerometer;
Dianne Hackborn2862fff2009-09-15 22:56:29 -0700364 int mLidKeyboardAccessibility;
365 int mLidNavigationAccessibility;
Jeff Brownc458ce92012-04-30 14:58:40 -0700366 boolean mLidControlsSleep;
Jeff Brown13f00f02014-10-31 14:45:50 -0700367 int mShortPressOnPowerBehavior;
368 int mLongPressOnPowerBehavior;
369 int mDoublePressOnPowerBehavior;
370 int mTriplePressOnPowerBehavior;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700371 boolean mAwake;
372 boolean mScreenOnEarly;
373 boolean mScreenOnFully;
374 ScreenOnListener mScreenOnListener;
375 boolean mKeyguardDrawComplete;
376 boolean mWindowManagerDrawComplete;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800377 boolean mOrientationSensorEnabled = false;
378 int mCurrentAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800379 boolean mHasSoftInput = false;
Daniel Sandlerdd73ee42013-10-11 22:19:59 -0400380 boolean mTranslucentDecorEnabled = true;
RoboErik001c59c2015-01-26 15:53:51 -0800381 boolean mUseTvRouting;
382 boolean mUseMasterVolume;
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;
Craig Mautner2bc789b2014-03-19 19:48:38 -0700460 HashSet<IApplicationToken> mAppsToBeHidden = new HashSet<IApplicationToken>();
Jorim Jaggic13fcac2014-09-11 17:36:57 +0200461 HashSet<IApplicationToken> mAppsThatDismissKeyguard = new HashSet<IApplicationToken>();
Joe Onorato93056472010-09-10 10:30:46 -0400462 boolean mTopIsFullscreen;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800463 boolean mForceStatusBar;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -0700464 boolean mForceStatusBarFromKeyguard;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700465 boolean mHideLockScreen;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -0800466 boolean mForcingShowNavBar;
467 int mForcingShowNavBarLayer;
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700468
469 // States of keyguard dismiss.
470 private static final int DISMISS_KEYGUARD_NONE = 0; // Keyguard not being dismissed.
471 private static final int DISMISS_KEYGUARD_START = 1; // Keyguard needs to be dismissed.
472 private static final int DISMISS_KEYGUARD_CONTINUE = 2; // Keyguard has been dismissed.
473 int mDismissKeyguard = DISMISS_KEYGUARD_NONE;
474
475 /** The window that is currently dismissing the keyguard. Dismissing the keyguard must only
476 * be done once per window. */
477 private WindowState mWinDismissingKeyguard;
478
Craig Mautnerc9457fa2014-06-06 14:27:48 -0700479 /** The window that is currently showing "over" the keyguard. If there is an app window
480 * belonging to another app on top of this the keyguard shows. If there is a fullscreen
481 * app window under this, still dismiss the keyguard but don't show the app underneath. Show
482 * the wallpaper. */
483 private WindowState mWinShowWhenLocked;
484
Dianne Hackborn7ad44382012-10-18 17:46:00 -0700485 boolean mShowingLockscreen;
486 boolean mShowingDream;
487 boolean mDreamingLockscreen;
Jim Millerab954542014-10-10 18:21:49 -0700488 boolean mKeyguardSecure;
489 boolean mKeyguardSecureIncludingHidden;
490 volatile boolean mKeyguardOccluded;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800491 boolean mHomePressed;
Jeff Browncaca8812013-05-09 13:34:33 -0700492 boolean mHomeConsumed;
493 boolean mHomeDoubleTapPending;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800494 Intent mHomeIntent;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700495 Intent mCarDockIntent;
496 Intent mDeskDockIntent;
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700497 boolean mSearchKeyShortcutPending;
498 boolean mConsumeSearchKeyUp;
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700499 boolean mAssistKeyLongPressed;
Michael Wright6a62e552014-06-03 19:19:48 -0700500 boolean mPendingMetaAction;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800501
Mike Lockwood28569302010-01-28 11:54:40 -0500502 // support for activating the lock screen while the screen is on
503 boolean mAllowLockscreenWhenOn;
504 int mLockScreenTimeout;
505 boolean mLockScreenTimerActive;
506
David Brownbaf8d092010-03-08 21:52:59 -0800507 // Behavior of ENDCALL Button. (See Settings.System.END_BUTTON_BEHAVIOR.)
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800508 int mEndcallBehavior;
David Brownbaf8d092010-03-08 21:52:59 -0800509
510 // Behavior of POWER button while in-call and screen on.
511 // (See Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR.)
512 int mIncallPowerBehavior;
513
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700514 Display mDisplay;
515
Dianne Hackborn9d132642011-04-21 17:26:39 -0700516 int mLandscapeRotation = 0; // default landscape rotation
517 int mSeascapeRotation = 0; // "other" landscape rotation, 180 degrees from mLandscapeRotation
518 int mPortraitRotation = 0; // default portrait rotation
519 int mUpsideDownRotation = 0; // "other" portrait rotation
Mitsuru Oshima831d0d92009-06-16 18:27:18 -0700520
Dianne Hackbornc652de82013-02-15 16:32:56 -0800521 int mOverscanLeft = 0;
522 int mOverscanTop = 0;
523 int mOverscanRight = 0;
524 int mOverscanBottom = 0;
525
Joe Onorato46b0d682010-11-22 17:37:27 -0800526 // What we do when the user long presses on home
Jeff Browncaca8812013-05-09 13:34:33 -0700527 private int mLongPressOnHomeBehavior;
528
529 // What we do when the user double-taps on home
530 private int mDoubleTapOnHomeBehavior;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800531
Bryce Lee584a4452014-10-21 15:55:55 -0700532 // Allowed theater mode wake actions
533 private boolean mAllowTheaterModeWakeFromKey;
534 private boolean mAllowTheaterModeWakeFromPowerKey;
535 private boolean mAllowTheaterModeWakeFromMotion;
Bryce Lee812d7022014-11-10 13:33:28 -0800536 private boolean mAllowTheaterModeWakeFromMotionWhenNotDreaming;
Bryce Lee584a4452014-10-21 15:55:55 -0700537 private boolean mAllowTheaterModeWakeFromCameraLens;
538 private boolean mAllowTheaterModeWakeFromLidSwitch;
539 private boolean mAllowTheaterModeWakeFromWakeGesture;
540
Bryce Lee55e846d2014-11-04 12:43:44 -0800541 // Whether to go to sleep entering theater mode from power button
542 private boolean mGoToSleepOnButtonPressTheaterMode;
543
Winson Chung9112ec32011-06-27 13:15:32 -0700544 // Screenshot trigger states
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700545 // Time to volume and power must be pressed within this interval of each other.
546 private static final long SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS = 150;
Winson Chung1cea2f32012-10-08 20:42:01 -0700547 // Increase the chord delay when taking a screenshot from the keyguard
548 private static final float KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER = 2.5f;
Christopher Tatee90585f2012-03-05 18:56:25 -0800549 private boolean mScreenshotChordEnabled;
Jeff Brown13f00f02014-10-31 14:45:50 -0700550 private boolean mScreenshotChordVolumeDownKeyTriggered;
551 private long mScreenshotChordVolumeDownKeyTime;
552 private boolean mScreenshotChordVolumeDownKeyConsumed;
553 private boolean mScreenshotChordVolumeUpKeyTriggered;
554 private boolean mScreenshotChordPowerKeyTriggered;
555 private long mScreenshotChordPowerKeyTime;
Winson Chung9112ec32011-06-27 13:15:32 -0700556
Michael Wrightb854e242013-02-05 17:54:02 -0800557 /* The number of steps between min and max brightness */
558 private static final int BRIGHTNESS_STEPS = 10;
559
Christopher Tate5e08af02012-09-21 17:17:22 -0700560 SettingsObserver mSettingsObserver;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800561 ShortcutManager mShortcutManager;
562 PowerManager.WakeLock mBroadcastWakeLock;
Jeff Brown13f00f02014-10-31 14:45:50 -0700563 PowerManager.WakeLock mPowerKeyWakeLock;
Jeff Brown40013652012-05-16 21:22:36 -0700564 boolean mHavePendingMediaKeyRepeatWithWakeLock;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800565
Craig Mautnerd625ab22013-09-06 13:40:31 -0700566 private int mCurrentUserId;
567
Justin Kohd378ad72013-04-01 12:18:26 -0700568 // Maps global key codes to the components that will handle them.
569 private GlobalKeyManager mGlobalKeyManager;
570
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700571 // Fallback actions by key code.
572 private final SparseArray<KeyCharacterMap.FallbackAction> mFallbackActions =
573 new SparseArray<KeyCharacterMap.FallbackAction>();
Jeff Brown49ed71d2010-12-06 17:13:33 -0800574
Jorim Jaggi76a16232014-08-08 17:00:47 +0200575 private final LogDecelerateInterpolator mLogDecelerateInterpolator
576 = new LogDecelerateInterpolator(100, 0);
577
Jeff Brown70825162012-03-28 17:27:48 -0700578 private static final int MSG_ENABLE_POINTER_LOCATION = 1;
579 private static final int MSG_DISABLE_POINTER_LOCATION = 2;
Jeff Brown40013652012-05-16 21:22:36 -0700580 private static final int MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK = 3;
581 private static final int MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK = 4;
Craig Mautner8a0da012014-05-31 15:13:37 -0700582 private static final int MSG_KEYGUARD_DRAWN_COMPLETE = 5;
583 private static final int MSG_KEYGUARD_DRAWN_TIMEOUT = 6;
584 private static final int MSG_WINDOW_MANAGER_DRAWN_COMPLETE = 7;
Craig Mautner84984fa2014-06-19 11:19:20 -0700585 private static final int MSG_DISPATCH_SHOW_RECENTS = 9;
Alan Viverettee34560b22014-07-10 14:50:06 -0700586 private static final int MSG_DISPATCH_SHOW_GLOBAL_ACTIONS = 10;
Craig Mautnera631d492014-08-05 15:16:01 -0700587 private static final int MSG_HIDE_BOOT_MESSAGE = 11;
Michael Wright869a67c2014-08-26 19:33:06 -0700588 private static final int MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK = 12;
Jeff Brown13f00f02014-10-31 14:45:50 -0700589 private static final int MSG_POWER_DELAYED_PRESS = 13;
590 private static final int MSG_POWER_LONG_PRESS = 14;
Jeff Brown70825162012-03-28 17:27:48 -0700591
592 private class PolicyHandler extends Handler {
593 @Override
594 public void handleMessage(Message msg) {
595 switch (msg.what) {
596 case MSG_ENABLE_POINTER_LOCATION:
597 enablePointerLocation();
598 break;
599 case MSG_DISABLE_POINTER_LOCATION:
600 disablePointerLocation();
601 break;
Jeff Brown40013652012-05-16 21:22:36 -0700602 case MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK:
603 dispatchMediaKeyWithWakeLock((KeyEvent)msg.obj);
604 break;
605 case MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK:
606 dispatchMediaKeyRepeatWithWakeLock((KeyEvent)msg.obj);
607 break;
Craig Mautner84984fa2014-06-19 11:19:20 -0700608 case MSG_DISPATCH_SHOW_RECENTS:
609 showRecentApps(false);
610 break;
Alan Viverettee34560b22014-07-10 14:50:06 -0700611 case MSG_DISPATCH_SHOW_GLOBAL_ACTIONS:
612 showGlobalActionsInternal();
613 break;
Craig Mautner8a0da012014-05-31 15:13:37 -0700614 case MSG_KEYGUARD_DRAWN_COMPLETE:
615 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mKeyguardDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700616 finishKeyguardDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700617 break;
618 case MSG_KEYGUARD_DRAWN_TIMEOUT:
619 Slog.w(TAG, "Keyguard drawn timeout. Setting mKeyguardDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700620 finishKeyguardDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700621 break;
622 case MSG_WINDOW_MANAGER_DRAWN_COMPLETE:
623 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mWindowManagerDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700624 finishWindowsDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700625 break;
Craig Mautnera631d492014-08-05 15:16:01 -0700626 case MSG_HIDE_BOOT_MESSAGE:
627 handleHideBootMessage();
628 break;
Michael Wright869a67c2014-08-26 19:33:06 -0700629 case MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK:
630 launchVoiceAssistWithWakeLock(msg.arg1 != 0);
631 break;
Jeff Brown13f00f02014-10-31 14:45:50 -0700632 case MSG_POWER_DELAYED_PRESS:
633 powerPress((Long)msg.obj, msg.arg1 != 0, msg.arg2);
634 finishPowerKeyPress();
635 break;
636 case MSG_POWER_LONG_PRESS:
637 powerLongPress();
638 break;
Jeff Brown70825162012-03-28 17:27:48 -0700639 }
640 }
641 }
642
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800643 private UEventObserver mHDMIObserver = new UEventObserver() {
644 @Override
645 public void onUEvent(UEventObserver.UEvent event) {
646 setHdmiPlugged("1".equals(event.get("SWITCH_STATE")));
647 }
648 };
649
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800650 class SettingsObserver extends ContentObserver {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800651 SettingsObserver(Handler handler) {
652 super(handler);
653 }
David Brownbaf8d092010-03-08 21:52:59 -0800654
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800655 void observe() {
Christopher Tate5e08af02012-09-21 17:17:22 -0700656 // Observe all users' changes
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800657 ContentResolver resolver = mContext.getContentResolver();
658 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700659 Settings.System.END_BUTTON_BEHAVIOR), false, this,
660 UserHandle.USER_ALL);
David Brownbaf8d092010-03-08 21:52:59 -0800661 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700662 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR), false, this,
663 UserHandle.USER_ALL);
Jeff Browna20dda42014-05-27 20:57:24 -0700664 resolver.registerContentObserver(Settings.Secure.getUriFor(
665 Settings.Secure.WAKE_GESTURE_ENABLED), false, this,
666 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800667 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700668 Settings.System.ACCELEROMETER_ROTATION), false, this,
669 UserHandle.USER_ALL);
Mike Lockwood28569302010-01-28 11:54:40 -0500670 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700671 Settings.System.USER_ROTATION), false, this,
672 UserHandle.USER_ALL);
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400673 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700674 Settings.System.SCREEN_OFF_TIMEOUT), false, this,
675 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800676 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700677 Settings.System.POINTER_LOCATION), false, this,
678 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800679 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700680 Settings.Secure.DEFAULT_INPUT_METHOD), false, this,
681 UserHandle.USER_ALL);
John Spurlockd9b70bd2014-02-06 17:02:44 -0500682 resolver.registerContentObserver(Settings.Secure.getUriFor(
John Spurlockf1a36642013-10-12 17:50:42 -0400683 Settings.Secure.IMMERSIVE_MODE_CONFIRMATIONS), false, this,
Christopher Tate5e08af02012-09-21 17:17:22 -0700684 UserHandle.USER_ALL);
John Spurlockc6d1c602014-01-17 15:22:06 -0500685 resolver.registerContentObserver(Settings.Global.getUriFor(
686 Settings.Global.POLICY_CONTROL), false, this,
687 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800688 updateSettings();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800689 }
690
691 @Override public void onChange(boolean selfChange) {
Dianne Hackbornc777e072010-02-12 13:07:59 -0800692 updateSettings();
Jeff Brown01a98dd2011-09-20 15:08:29 -0700693 updateRotation(false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800694 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800695 }
Craig Mautner967212c2013-04-13 21:10:58 -0700696
Jeff Browna20dda42014-05-27 20:57:24 -0700697 class MyWakeGestureListener extends WakeGestureListener {
698 MyWakeGestureListener(Context context, Handler handler) {
699 super(context, handler);
700 }
701
702 @Override
703 public void onWakeUp() {
704 synchronized (mLock) {
705 if (shouldEnableWakeGestureLp()) {
Jeff Browne07b94b2014-06-18 15:56:27 -0700706 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
Bryce Lee584a4452014-10-21 15:55:55 -0700707 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromWakeGesture);
Jeff Browna20dda42014-05-27 20:57:24 -0700708 }
709 }
710 }
711 }
712
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800713 class MyOrientationListener extends WindowOrientationListener {
Craig Mautnereee29c42013-01-17 14:44:34 -0800714 MyOrientationListener(Context context, Handler handler) {
715 super(context, handler);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800716 }
Craig Mautner967212c2013-04-13 21:10:58 -0700717
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800718 @Override
Jeff Brownc0347aa2011-09-23 17:26:09 -0700719 public void onProposedRotationChanged(int rotation) {
Craig Mautnereda67292013-04-28 13:50:14 -0700720 if (localLOGV) Slog.v(TAG, "onProposedRotationChanged, rotation=" + rotation);
Jeff Brown01a98dd2011-09-20 15:08:29 -0700721 updateRotation(false);
722 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800723 }
724 MyOrientationListener mOrientationListener;
725
John Spurlock27735a42013-08-14 17:57:38 -0400726 private final BarController mStatusBarController = new BarController("StatusBar",
John Spurlock5b9145b2013-08-20 15:13:47 -0400727 View.STATUS_BAR_TRANSIENT,
728 View.STATUS_BAR_UNHIDE,
John Spurlockbd957402013-10-03 11:38:39 -0400729 View.STATUS_BAR_TRANSLUCENT,
730 StatusBarManager.WINDOW_STATUS_BAR,
731 WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
John Spurlock5b9145b2013-08-20 15:13:47 -0400732
John Spurlock27735a42013-08-14 17:57:38 -0400733 private final BarController mNavigationBarController = new BarController("NavigationBar",
John Spurlock5b9145b2013-08-20 15:13:47 -0400734 View.NAVIGATION_BAR_TRANSIENT,
735 View.NAVIGATION_BAR_UNHIDE,
John Spurlockbd957402013-10-03 11:38:39 -0400736 View.NAVIGATION_BAR_TRANSLUCENT,
737 StatusBarManager.WINDOW_NAVIGATION_BAR,
738 WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
John Spurlock5b9145b2013-08-20 15:13:47 -0400739
John Spurlockf1a36642013-10-12 17:50:42 -0400740 private ImmersiveModeConfirmation mImmersiveModeConfirmation;
John Spurlock32beb2c2013-03-11 10:16:47 -0400741
Craig Mautner037aa8d2013-06-07 10:35:44 -0700742 private SystemGesturesPointerEventListener mSystemGestures;
John Spurlock32beb2c2013-03-11 10:16:47 -0400743
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700744 IStatusBarService getStatusBarService() {
745 synchronized (mServiceAquireLock) {
746 if (mStatusBarService == null) {
747 mStatusBarService = IStatusBarService.Stub.asInterface(
748 ServiceManager.getService("statusbar"));
749 }
750 return mStatusBarService;
751 }
752 }
753
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700754 /*
755 * We always let the sensor be switched on by default except when
756 * the user has explicitly disabled sensor based rotation or when the
757 * screen is switched off.
758 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700759 boolean needSensorRunningLp() {
Jeff Brownbcdfc622014-03-06 19:13:04 -0800760 if (mSupportAutoRotation) {
761 if (mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
762 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
763 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT
764 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) {
765 // If the application has explicitly requested to follow the
766 // orientation, then we need to turn the sensor on.
767 return true;
768 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800769 }
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700770 if ((mCarDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_CAR) ||
Jeff Brown1a693182011-11-08 14:44:16 -0800771 (mDeskDockEnablesAccelerometer && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
772 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
773 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK))) {
Mike Lockwoode9867d22009-09-20 01:59:02 -0400774 // enable accelerometer if we are docked in a dock that enables accelerometer
775 // orientation management,
776 return true;
777 }
Jeff Brown207673cd2012-06-05 17:47:11 -0700778 if (mUserRotationMode == USER_ROTATION_LOCKED) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800779 // If the setting for using the sensor by default is enabled, then
780 // we will always leave it on. Note that the user could go to
781 // a window that forces an orientation that does not use the
782 // sensor and in theory we could turn it off... however, when next
783 // turning it on we won't have a good value for the current
784 // orientation for a little bit, which can cause orientation
785 // changes to lag, so we'd like to keep it always on. (It will
786 // still be turned off when the screen is off.)
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700787 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800788 }
Jeff Brownbcdfc622014-03-06 19:13:04 -0800789 return mSupportAutoRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800790 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700791
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800792 /*
793 * Various use cases for invoking this function
794 * screen turning off, should always disable listeners if already enabled
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700795 * screen turned on and current app has sensor based orientation, enable listeners
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800796 * if not already enabled
797 * screen turned on and current app does not have sensor orientation, disable listeners if
798 * already enabled
799 * screen turning on and current app has sensor based orientation, enable listeners if needed
800 * screen turning on and current app has nosensor based orientation, do nothing
801 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700802 void updateOrientationListenerLp() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800803 if (!mOrientationListener.canDetectOrientation()) {
804 // If sensor is turned off or nonexistent for some reason
805 return;
806 }
807 //Could have been invoked due to screen turning on or off or
808 //change of the currently visible window's orientation
Jeff Brown3ee549c2014-09-22 20:14:39 -0700809 if (localLOGV) Slog.v(TAG, "mScreenOnEarly=" + mScreenOnEarly
810 + ", mAwake=" + mAwake + ", mCurrentAppOrientation=" + mCurrentAppOrientation
811 + ", mOrientationSensorEnabled=" + mOrientationSensorEnabled);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800812 boolean disable = true;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700813 if (mScreenOnEarly && mAwake) {
The Android Open Source Project0727d222009-03-11 12:11:58 -0700814 if (needSensorRunningLp()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800815 disable = false;
816 //enable listener if not already enabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700817 if (!mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800818 mOrientationListener.enable();
Craig Mautnereda67292013-04-28 13:50:14 -0700819 if(localLOGV) Slog.v(TAG, "Enabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800820 mOrientationSensorEnabled = true;
821 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700822 }
823 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800824 //check if sensors need to be disabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700825 if (disable && mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800826 mOrientationListener.disable();
Craig Mautnereda67292013-04-28 13:50:14 -0700827 if(localLOGV) Slog.v(TAG, "Disabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800828 mOrientationSensorEnabled = false;
829 }
830 }
831
Jeff Brown13f00f02014-10-31 14:45:50 -0700832 private void interceptPowerKeyDown(KeyEvent event, boolean interactive) {
833 // Hold a wake lock until the power key is released.
834 if (!mPowerKeyWakeLock.isHeld()) {
835 mPowerKeyWakeLock.acquire();
836 }
837
838 // Cancel multi-press detection timeout.
839 if (mPowerKeyPressCounter != 0) {
840 mHandler.removeMessages(MSG_POWER_DELAYED_PRESS);
841 }
842
843 // Detect user pressing the power button in panic when an application has
844 // taken over the whole screen.
845 boolean panic = mImmersiveModeConfirmation.onPowerKeyDown(interactive,
Craig Mautner0124980e92014-11-30 21:15:34 -0800846 SystemClock.elapsedRealtime(), isImmersiveMode(mLastSystemUiFlags));
Jeff Brown13f00f02014-10-31 14:45:50 -0700847 if (panic) {
848 mHandler.post(mRequestTransientNav);
849 }
850
851 // Latch power key state to detect screenshot chord.
852 if (interactive && !mScreenshotChordPowerKeyTriggered
853 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
854 mScreenshotChordPowerKeyTriggered = true;
855 mScreenshotChordPowerKeyTime = event.getDownTime();
856 interceptScreenshotChord();
857 }
858
859 // Stop ringing or end call if configured to do so when power is pressed.
860 TelecomManager telecomManager = getTelecommService();
861 boolean hungUp = false;
862 if (telecomManager != null) {
863 if (telecomManager.isRinging()) {
864 // Pressing Power while there's a ringing incoming
865 // call should silence the ringer.
866 telecomManager.silenceRinger();
867 } else if ((mIncallPowerBehavior
868 & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0
869 && telecomManager.isInCall() && interactive) {
870 // Otherwise, if "Power button ends call" is enabled,
871 // the Power button will hang up any current active call.
872 hungUp = telecomManager.endCall();
873 }
874 }
875
876 // If the power key has still not yet been handled, then detect short
877 // press, long press, or multi press and decide what to do.
878 mPowerKeyHandled = hungUp || mScreenshotChordVolumeDownKeyTriggered
879 || mScreenshotChordVolumeUpKeyTriggered;
880 if (!mPowerKeyHandled) {
881 if (interactive) {
882 // When interactive, we're already awake.
883 // Wait for a long press or for the button to be released to decide what to do.
884 if (hasLongPressOnPowerBehavior()) {
885 Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS);
886 msg.setAsynchronous(true);
887 mHandler.sendMessageDelayed(msg,
888 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
889 }
890 } else {
Bryce Leed9268e32014-11-17 17:40:59 -0800891 wakeUpFromPowerKey(event.getDownTime());
Jeff Brown13f00f02014-10-31 14:45:50 -0700892 final int maxCount = getMaxMultiPressPowerCount();
Bryce Leed9268e32014-11-17 17:40:59 -0800893
Jeff Brown13f00f02014-10-31 14:45:50 -0700894 if (maxCount <= 1) {
Jeff Brown13f00f02014-10-31 14:45:50 -0700895 mPowerKeyHandled = true;
Bryce Leed9268e32014-11-17 17:40:59 -0800896 } else {
897 mBeganFromNonInteractive = true;
Jeff Brown13f00f02014-10-31 14:45:50 -0700898 }
899 }
Jeff Brown4d396052010-10-29 21:50:21 -0700900 }
901 }
902
Jeff Brown13f00f02014-10-31 14:45:50 -0700903 private void interceptPowerKeyUp(KeyEvent event, boolean interactive, boolean canceled) {
904 final boolean handled = canceled || mPowerKeyHandled;
905 mScreenshotChordPowerKeyTriggered = false;
906 cancelPendingScreenshotChordAction();
907 cancelPendingPowerKeyAction();
908
909 if (!handled) {
910 // Figure out how to handle the key now that it has been released.
911 mPowerKeyPressCounter += 1;
912
913 final int maxCount = getMaxMultiPressPowerCount();
914 final long eventTime = event.getDownTime();
915 if (mPowerKeyPressCounter < maxCount) {
916 // This could be a multi-press. Wait a little bit longer to confirm.
917 // Continue holding the wake lock.
918 Message msg = mHandler.obtainMessage(MSG_POWER_DELAYED_PRESS,
919 interactive ? 1 : 0, mPowerKeyPressCounter, eventTime);
920 msg.setAsynchronous(true);
921 mHandler.sendMessageDelayed(msg, ViewConfiguration.getDoubleTapTimeout());
922 return;
923 }
924
925 // No other actions. Handle it immediately.
926 powerPress(eventTime, interactive, mPowerKeyPressCounter);
Jeff Brown4d396052010-10-29 21:50:21 -0700927 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700928
929 // Done. Reset our state.
930 finishPowerKeyPress();
931 }
932
933 private void finishPowerKeyPress() {
Bryce Leed9268e32014-11-17 17:40:59 -0800934 mBeganFromNonInteractive = false;
Jeff Brown13f00f02014-10-31 14:45:50 -0700935 mPowerKeyPressCounter = 0;
936 if (mPowerKeyWakeLock.isHeld()) {
937 mPowerKeyWakeLock.release();
938 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700939 }
940
941 private void cancelPendingPowerKeyAction() {
942 if (!mPowerKeyHandled) {
Jeff Brown13f00f02014-10-31 14:45:50 -0700943 mPowerKeyHandled = true;
944 mHandler.removeMessages(MSG_POWER_LONG_PRESS);
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700945 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700946 }
947
948 private void powerPress(long eventTime, boolean interactive, int count) {
949 if (mScreenOnEarly && !mScreenOnFully) {
950 Slog.i(TAG, "Suppressed redundant power key press while "
951 + "already in the process of turning the screen on.");
952 return;
Jeff Brownff204712011-10-25 21:27:54 -0700953 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700954
955 if (count == 2) {
956 powerMultiPressAction(eventTime, interactive, mDoublePressOnPowerBehavior);
957 } else if (count == 3) {
958 powerMultiPressAction(eventTime, interactive, mTriplePressOnPowerBehavior);
Bryce Leed9268e32014-11-17 17:40:59 -0800959 } else if (interactive && !mBeganFromNonInteractive) {
Jeff Brown13f00f02014-10-31 14:45:50 -0700960 switch (mShortPressOnPowerBehavior) {
961 case SHORT_PRESS_POWER_NOTHING:
962 break;
963 case SHORT_PRESS_POWER_GO_TO_SLEEP:
964 mPowerManager.goToSleep(eventTime,
965 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
966 break;
967 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP:
968 mPowerManager.goToSleep(eventTime,
969 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
970 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
971 break;
972 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME:
973 mPowerManager.goToSleep(eventTime,
974 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
975 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
976 launchHomeFromHotKey();
977 break;
Bryce Lee01b0c5f2015-02-05 18:24:04 -0800978 case SHORT_PRESS_POWER_GO_HOME:
979 launchHomeFromHotKey();
980 break;
Jeff Brown13f00f02014-10-31 14:45:50 -0700981 }
982 }
983 }
984
985 private void powerMultiPressAction(long eventTime, boolean interactive, int behavior) {
986 switch (behavior) {
987 case MULTI_PRESS_POWER_NOTHING:
988 break;
989 case MULTI_PRESS_POWER_THEATER_MODE:
990 if (isTheaterModeEnabled()) {
991 Slog.i(TAG, "Toggling theater mode off.");
992 Settings.Global.putInt(mContext.getContentResolver(),
993 Settings.Global.THEATER_MODE_ON, 0);
994 if (!interactive) {
995 wakeUpFromPowerKey(eventTime);
996 }
997 } else {
998 Slog.i(TAG, "Toggling theater mode on.");
999 Settings.Global.putInt(mContext.getContentResolver(),
1000 Settings.Global.THEATER_MODE_ON, 1);
Bryce Lee55e846d2014-11-04 12:43:44 -08001001
1002 if (mGoToSleepOnButtonPressTheaterMode && interactive) {
Jeff Brown13f00f02014-10-31 14:45:50 -07001003 mPowerManager.goToSleep(eventTime,
1004 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
1005 }
1006 }
1007 break;
1008 case MULTI_PRESS_POWER_BRIGHTNESS_BOOST:
Jeff Brown7b5be5e2014-11-12 18:45:31 -08001009 Slog.i(TAG, "Starting brightness boost.");
1010 if (!interactive) {
1011 wakeUpFromPowerKey(eventTime);
1012 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001013 mPowerManager.boostScreenBrightness(eventTime);
1014 break;
1015 }
1016 }
1017
1018 private int getMaxMultiPressPowerCount() {
1019 if (mTriplePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) {
1020 return 3;
1021 }
1022 if (mDoublePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) {
1023 return 2;
1024 }
1025 return 1;
1026 }
1027
1028 private void powerLongPress() {
1029 final int behavior = getResolvedLongPressOnPowerBehavior();
1030 switch (behavior) {
1031 case LONG_PRESS_POWER_NOTHING:
1032 break;
1033 case LONG_PRESS_POWER_GLOBAL_ACTIONS:
1034 mPowerKeyHandled = true;
1035 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
1036 performAuditoryFeedbackForAccessibilityIfNeed();
1037 }
1038 showGlobalActionsInternal();
1039 break;
1040 case LONG_PRESS_POWER_SHUT_OFF:
1041 case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM:
1042 mPowerKeyHandled = true;
1043 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
1044 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
1045 mWindowManagerFuncs.shutdown(behavior == LONG_PRESS_POWER_SHUT_OFF);
1046 break;
1047 }
1048 }
1049
1050 private int getResolvedLongPressOnPowerBehavior() {
1051 if (FactoryTest.isLongPressOnPowerOffEnabled()) {
1052 return LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM;
1053 }
1054 return mLongPressOnPowerBehavior;
1055 }
1056
1057 private boolean hasLongPressOnPowerBehavior() {
1058 return getResolvedLongPressOnPowerBehavior() != LONG_PRESS_POWER_NOTHING;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001059 }
1060
1061 private void interceptScreenshotChord() {
Christopher Tatee90585f2012-03-05 18:56:25 -08001062 if (mScreenshotChordEnabled
Jeff Brown13f00f02014-10-31 14:45:50 -07001063 && mScreenshotChordVolumeDownKeyTriggered && mScreenshotChordPowerKeyTriggered
1064 && !mScreenshotChordVolumeUpKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001065 final long now = SystemClock.uptimeMillis();
Jeff Brown13f00f02014-10-31 14:45:50 -07001066 if (now <= mScreenshotChordVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS
1067 && now <= mScreenshotChordPowerKeyTime
1068 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) {
1069 mScreenshotChordVolumeDownKeyConsumed = true;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001070 cancelPendingPowerKeyAction();
1071
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001072 mHandler.postDelayed(mScreenshotRunnable, getScreenshotChordLongPressDelay());
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001073 }
1074 }
1075 }
1076
Winson Chung1cea2f32012-10-08 20:42:01 -07001077 private long getScreenshotChordLongPressDelay() {
Jim Miller5ecd8112013-01-09 18:50:26 -08001078 if (mKeyguardDelegate.isShowing()) {
Winson Chung1cea2f32012-10-08 20:42:01 -07001079 // Double the time it takes to take a screenshot from the keyguard
1080 return (long) (KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER *
Justin Kohfeabd2c2014-05-02 10:02:44 -07001081 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Winson Chung1cea2f32012-10-08 20:42:01 -07001082 }
Justin Kohfeabd2c2014-05-02 10:02:44 -07001083 return ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout();
Winson Chung1cea2f32012-10-08 20:42:01 -07001084 }
1085
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001086 private void cancelPendingScreenshotChordAction() {
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001087 mHandler.removeCallbacks(mScreenshotRunnable);
Jeff Brown4d396052010-10-29 21:50:21 -07001088 }
1089
Jeff Brown13f00f02014-10-31 14:45:50 -07001090 private final Runnable mEndCallLongPress = new Runnable() {
Craig Mautnerf1b67412012-09-19 13:18:29 -07001091 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001092 public void run() {
Jeff Brown13f00f02014-10-31 14:45:50 -07001093 mEndCallKeyHandled = true;
1094 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
1095 performAuditoryFeedbackForAccessibilityIfNeed();
Joe Onoratod208e702010-10-08 16:22:43 -04001096 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001097 showGlobalActionsInternal();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001098 }
1099 };
1100
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001101 private final Runnable mScreenshotRunnable = new Runnable() {
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001102 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001103 public void run() {
1104 takeScreenshot();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001105 }
1106 };
1107
Alan Viverettee34560b22014-07-10 14:50:06 -07001108 @Override
1109 public void showGlobalActions() {
1110 mHandler.removeMessages(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
1111 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
1112 }
1113
1114 void showGlobalActionsInternal() {
1115 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001116 if (mGlobalActions == null) {
Jeff Brown7304c342012-05-11 18:42:42 -07001117 mGlobalActions = new GlobalActions(mContext, mWindowManagerFuncs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001118 }
Jim Millerab954542014-10-10 18:21:49 -07001119 final boolean keyguardShowing = isKeyguardShowingAndNotOccluded();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001120 mGlobalActions.showDialog(keyguardShowing, isDeviceProvisioned());
1121 if (keyguardShowing) {
1122 // since it took two seconds of long press to bring this up,
1123 // poke the wake lock so they have some time to see the dialog.
Jim Miller25190572013-02-28 17:36:24 -08001124 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001125 }
1126 }
1127
1128 boolean isDeviceProvisioned() {
Jeff Brownbf6f6f92012-09-25 15:03:20 -07001129 return Settings.Global.getInt(
1130 mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001131 }
1132
Maurice Lam99c6e072014-04-28 18:24:28 -07001133 boolean isUserSetupComplete() {
1134 return Settings.Secure.getIntForUser(mContext.getContentResolver(),
1135 Settings.Secure.USER_SETUP_COMPLETE, 0, UserHandle.USER_CURRENT) != 0;
1136 }
1137
Jeff Brown13f00f02014-10-31 14:45:50 -07001138 private void handleShortPressOnHome() {
1139 // If there's a dream running then use home to escape the dream
1140 // but don't actually go home.
1141 if (mDreamManagerInternal != null && mDreamManagerInternal.isDreaming()) {
1142 mDreamManagerInternal.stopDream(false /*immediate*/);
1143 return;
1144 }
1145
1146 // Go home!
1147 launchHomeFromHotKey();
1148 }
1149
Patrick Dubroyece94522011-02-23 18:35:01 -08001150 private void handleLongPressOnHome() {
Joe Onorato46b0d682010-11-22 17:37:27 -08001151 if (mLongPressOnHomeBehavior != LONG_PRESS_HOME_NOTHING) {
Jeff Browncaca8812013-05-09 13:34:33 -07001152 mHomeConsumed = true;
Joe Onorato46b0d682010-11-22 17:37:27 -08001153 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
Patrick Dubroyece94522011-02-23 18:35:01 -08001154
Jeff Browncaca8812013-05-09 13:34:33 -07001155 if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI) {
1156 toggleRecentApps();
1157 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_ASSIST) {
1158 launchAssistAction();
Jim Millere6ad1a82010-08-20 19:25:39 -07001159 }
1160 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001161 }
Patrick Dubroyece94522011-02-23 18:35:01 -08001162
Jeff Browncaca8812013-05-09 13:34:33 -07001163 private void handleDoubleTapOnHome() {
1164 if (mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1165 mHomeConsumed = true;
1166 toggleRecentApps();
1167 }
1168 }
1169
1170 private final Runnable mHomeDoubleTapTimeoutRunnable = new Runnable() {
1171 @Override
1172 public void run() {
1173 if (mHomeDoubleTapPending) {
1174 mHomeDoubleTapPending = false;
Jeff Brown13f00f02014-10-31 14:45:50 -07001175 handleShortPressOnHome();
Jeff Browncaca8812013-05-09 13:34:33 -07001176 }
1177 }
1178 };
1179
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001180 /** {@inheritDoc} */
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001181 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001182 public void init(Context context, IWindowManager windowManager,
Jeff Brown96307042012-07-27 15:51:34 -07001183 WindowManagerFuncs windowManagerFuncs) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001184 mContext = context;
1185 mWindowManager = windowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -07001186 mWindowManagerFuncs = windowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -07001187 mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class);
Jose Lima9546b202014-07-02 17:21:51 -07001188 mDreamManagerInternal = LocalServices.getService(DreamManagerInternal.class);
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 mUseMasterVolume = mContext.getResources().getBoolean(
1273 com.android.internal.R.bool.config_useMasterVolume);
1274
Jeff Brownf71343d2013-05-31 17:59:11 -07001275 readConfigurationDependentBehaviors();
Jeff Browncaca8812013-05-09 13:34:33 -07001276
Svetoslav8e3feb12014-02-24 13:46:47 -08001277 mAccessibilityManager = (AccessibilityManager) context.getSystemService(
1278 Context.ACCESSIBILITY_SERVICE);
1279
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001280 // register for dock events
Dianne Hackborn78968392010-03-04 20:47:56 -08001281 IntentFilter filter = new IntentFilter();
1282 filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE);
1283 filter.addAction(UiModeManager.ACTION_EXIT_CAR_MODE);
1284 filter.addAction(UiModeManager.ACTION_ENTER_DESK_MODE);
1285 filter.addAction(UiModeManager.ACTION_EXIT_DESK_MODE);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001286 filter.addAction(Intent.ACTION_DOCK_EVENT);
1287 Intent intent = context.registerReceiver(mDockReceiver, filter);
1288 if (intent != null) {
1289 // Retrieve current sticky dock event broadcast.
1290 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
1291 Intent.EXTRA_DOCK_STATE_UNDOCKED);
1292 }
Daniel Sandler7e37df52011-11-16 22:08:23 -08001293
Jeff Brown6aaf2952012-10-05 16:01:08 -07001294 // register for dream-related broadcasts
1295 filter = new IntentFilter();
1296 filter.addAction(Intent.ACTION_DREAMING_STARTED);
1297 filter.addAction(Intent.ACTION_DREAMING_STOPPED);
1298 context.registerReceiver(mDreamReceiver, filter);
1299
Christopher Tate5e08af02012-09-21 17:17:22 -07001300 // register for multiuser-relevant broadcasts
1301 filter = new IntentFilter(Intent.ACTION_USER_SWITCHED);
1302 context.registerReceiver(mMultiuserReceiver, filter);
1303
John Spurlock57306e62013-04-22 09:48:49 -04001304 // monitor for system gestures
Craig Mautner037aa8d2013-06-07 10:35:44 -07001305 mSystemGestures = new SystemGesturesPointerEventListener(context,
1306 new SystemGesturesPointerEventListener.Callbacks() {
John Spurlock57306e62013-04-22 09:48:49 -04001307 @Override
1308 public void onSwipeFromTop() {
John Spurlock04db1762013-05-13 12:46:41 -04001309 if (mStatusBar != null) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001310 requestTransientBars(mStatusBar);
John Spurlock04db1762013-05-13 12:46:41 -04001311 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04001312 }
1313 @Override
1314 public void onSwipeFromBottom() {
John Spurlock04db1762013-05-13 12:46:41 -04001315 if (mNavigationBar != null && mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001316 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001317 }
1318 }
1319 @Override
1320 public void onSwipeFromRight() {
John Spurlock04db1762013-05-13 12:46:41 -04001321 if (mNavigationBar != null && !mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001322 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001323 }
1324 }
1325 @Override
1326 public void onDebug() {
John Spurlockd67ec252013-09-05 11:31:54 -04001327 // no-op
John Spurlockad3e6cb2013-04-30 08:47:43 -04001328 }
1329 });
John Spurlockf1a36642013-10-12 17:50:42 -04001330 mImmersiveModeConfirmation = new ImmersiveModeConfirmation(mContext);
Craig Mautner037aa8d2013-06-07 10:35:44 -07001331 mWindowManagerFuncs.registerPointerEventListener(mSystemGestures);
John Spurlock32beb2c2013-03-11 10:16:47 -04001332
Jeff Brownc2346132012-04-13 01:55:38 -07001333 mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001334 mLongPressVibePattern = getLongIntArray(mContext.getResources(),
1335 com.android.internal.R.array.config_longPressVibePattern);
1336 mVirtualKeyVibePattern = getLongIntArray(mContext.getResources(),
1337 com.android.internal.R.array.config_virtualKeyVibePattern);
Amith Yamasanic33cb712010-02-10 15:21:49 -08001338 mKeyboardTapVibePattern = getLongIntArray(mContext.getResources(),
1339 com.android.internal.R.array.config_keyboardTapVibePattern);
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07001340 mClockTickVibePattern = getLongIntArray(mContext.getResources(),
1341 com.android.internal.R.array.config_clockTickVibePattern);
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07001342 mCalendarDateVibePattern = getLongIntArray(mContext.getResources(),
1343 com.android.internal.R.array.config_calendarDateVibePattern);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001344 mSafeModeDisabledVibePattern = getLongIntArray(mContext.getResources(),
1345 com.android.internal.R.array.config_safeModeDisabledVibePattern);
1346 mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(),
1347 com.android.internal.R.array.config_safeModeEnabledVibePattern);
Daniel Sandler40427442010-07-16 11:44:52 -04001348
Christopher Tatee90585f2012-03-05 18:56:25 -08001349 mScreenshotChordEnabled = mContext.getResources().getBoolean(
1350 com.android.internal.R.bool.config_enableScreenshotChord);
1351
Justin Kohd378ad72013-04-01 12:18:26 -07001352 mGlobalKeyManager = new GlobalKeyManager(mContext);
1353
Joe Onoratoea495d42011-04-06 11:41:11 -07001354 // Controls rotation and the like.
1355 initializeHdmiState();
Dianne Hackborn40011092011-09-22 13:37:48 -07001356
1357 // Match current screen state.
Craig Mautnera631d492014-08-05 15:16:01 -07001358 if (!mPowerManager.isInteractive()) {
Jeff Brown140ffc72014-05-01 15:18:00 -07001359 goingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
Dianne Hackborn40011092011-09-22 13:37:48 -07001360 }
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001361 }
1362
Jeff Brownf71343d2013-05-31 17:59:11 -07001363 /**
1364 * Read values from config.xml that may be overridden depending on
1365 * the configuration of the device.
1366 * eg. Disable long press on home goes to recents on sw600dp.
1367 */
1368 private void readConfigurationDependentBehaviors() {
1369 mLongPressOnHomeBehavior = mContext.getResources().getInteger(
1370 com.android.internal.R.integer.config_longPressOnHomeBehavior);
1371 if (mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING ||
1372 mLongPressOnHomeBehavior > LONG_PRESS_HOME_ASSIST) {
1373 mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1374 }
1375
1376 mDoubleTapOnHomeBehavior = mContext.getResources().getInteger(
1377 com.android.internal.R.integer.config_doubleTapOnHomeBehavior);
1378 if (mDoubleTapOnHomeBehavior < DOUBLE_TAP_HOME_NOTHING ||
1379 mDoubleTapOnHomeBehavior > DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1380 mDoubleTapOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1381 }
1382 }
1383
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001384 @Override
Dianne Hackborndde331c2012-08-03 14:01:57 -07001385 public void setInitialDisplaySize(Display display, int width, int height, int density) {
Jeff Brownef981a42013-08-07 14:13:37 -07001386 // This method might be called before the policy has been fully initialized
1387 // or for other displays we don't care about.
1388 if (mContext == null || display.getDisplayId() != Display.DEFAULT_DISPLAY) {
1389 return;
Dianne Hackbornc652de82013-02-15 16:32:56 -08001390 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001391 mDisplay = display;
1392
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001393 final Resources res = mContext.getResources();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001394 int shortSize, longSize;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001395 if (width > height) {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001396 shortSize = height;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001397 longSize = width;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001398 mLandscapeRotation = Surface.ROTATION_0;
1399 mSeascapeRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001400 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001401 mPortraitRotation = Surface.ROTATION_90;
1402 mUpsideDownRotation = Surface.ROTATION_270;
1403 } else {
1404 mPortraitRotation = Surface.ROTATION_270;
1405 mUpsideDownRotation = Surface.ROTATION_90;
1406 }
1407 } else {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001408 shortSize = width;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001409 longSize = height;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001410 mPortraitRotation = Surface.ROTATION_0;
1411 mUpsideDownRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001412 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001413 mLandscapeRotation = Surface.ROTATION_270;
1414 mSeascapeRotation = Surface.ROTATION_90;
1415 } else {
1416 mLandscapeRotation = Surface.ROTATION_90;
1417 mSeascapeRotation = Surface.ROTATION_270;
1418 }
1419 }
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001420
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001421 mStatusBarHeight =
1422 res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001423
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001424 // Height of the navigation bar when presented horizontally at bottom
1425 mNavigationBarHeightForRotation[mPortraitRotation] =
1426 mNavigationBarHeightForRotation[mUpsideDownRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001427 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_height);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001428 mNavigationBarHeightForRotation[mLandscapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001429 mNavigationBarHeightForRotation[mSeascapeRotation] = res.getDimensionPixelSize(
1430 com.android.internal.R.dimen.navigation_bar_height_landscape);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001431
1432 // Width of the navigation bar when presented vertically along one side
1433 mNavigationBarWidthForRotation[mPortraitRotation] =
1434 mNavigationBarWidthForRotation[mUpsideDownRotation] =
1435 mNavigationBarWidthForRotation[mLandscapeRotation] =
1436 mNavigationBarWidthForRotation[mSeascapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001437 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_width);
Daniel Sandler4a066c52012-04-20 14:49:13 -04001438
1439 // SystemUI (status bar) layout policy
Dianne Hackborndde331c2012-08-03 14:01:57 -07001440 int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / density;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001441 int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / density;
Daniel Sandler4a066c52012-04-20 14:49:13 -04001442
Devin Kimd7b12b42014-05-05 14:34:58 -07001443 // Allow the navigation bar to move on non-square small devices (phones).
1444 mNavigationBarCanMove = width != height && shortSizeDp < 600;
Daniel Sandler36412a72011-08-04 09:35:13 -04001445
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001446 mHasNavigationBar = res.getBoolean(com.android.internal.R.bool.config_showNavigationBar);
John Spurlock80f00c12013-06-13 11:10:51 -04001447 // Allow a system property to override this. Used by the emulator.
1448 // See also hasNavigationBar().
1449 String navBarOverride = SystemProperties.get("qemu.hw.mainkeys");
1450 if ("1".equals(navBarOverride)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001451 mHasNavigationBar = false;
John Spurlock80f00c12013-06-13 11:10:51 -04001452 } else if ("0".equals(navBarOverride)) {
1453 mHasNavigationBar = true;
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04001454 }
1455
Jeff Brown27f1d672012-10-17 18:32:34 -07001456 // For demo purposes, allow the rotation of the HDMI display to be controlled.
1457 // By default, HDMI locks rotation to landscape.
Erik Gilling9a41ef82011-09-26 19:21:03 -07001458 if ("portrait".equals(SystemProperties.get("persist.demo.hdmirotation"))) {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001459 mDemoHdmiRotation = mPortraitRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001460 } else {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001461 mDemoHdmiRotation = mLandscapeRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001462 }
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001463 mDemoHdmiRotationLock = SystemProperties.getBoolean("persist.demo.hdmirotationlock", false);
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001464
Chong Zhangae6119ff2014-11-11 18:54:39 -08001465 // For demo purposes, allow the rotation of the remote display to be controlled.
1466 // By default, remote display locks rotation to landscape.
1467 if ("portrait".equals(SystemProperties.get("persist.demo.remoterotation"))) {
1468 mDemoRotation = mPortraitRotation;
1469 } else {
1470 mDemoRotation = mLandscapeRotation;
1471 }
1472 mDemoRotationLock = SystemProperties.getBoolean(
1473 "persist.demo.rotationlock", false);
1474
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001475 // Only force the default orientation if the screen is xlarge, at least 960dp x 720dp, per
1476 // http://developer.android.com/guide/practices/screens_support.html#range
1477 mForceDefaultOrientation = longSizeDp >= 960 && shortSizeDp >= 720 &&
1478 res.getBoolean(com.android.internal.R.bool.config_forceDefaultOrientation) &&
1479 // For debug purposes the next line turns this feature off with:
1480 // $ adb shell setprop config.override_forced_orient true
1481 // $ adb shell wm size reset
1482 !"true".equals(SystemProperties.get("config.override_forced_orient"));
1483 }
1484
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001485 /**
1486 * @return whether the navigation bar can be hidden, e.g. the device has a
1487 * navigation bar and touch exploration is not enabled
1488 */
1489 private boolean canHideNavigationBar() {
Svetoslav8e3feb12014-02-24 13:46:47 -08001490 return mHasNavigationBar
1491 && !mAccessibilityManager.isTouchExplorationEnabled();
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001492 }
1493
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001494 @Override
1495 public boolean isDefaultOrientationForced() {
1496 return mForceDefaultOrientation;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001497 }
1498
Dianne Hackbornc652de82013-02-15 16:32:56 -08001499 @Override
1500 public void setDisplayOverscan(Display display, int left, int top, int right, int bottom) {
1501 if (display.getDisplayId() == Display.DEFAULT_DISPLAY) {
1502 mOverscanLeft = left;
1503 mOverscanTop = top;
1504 mOverscanRight = right;
1505 mOverscanBottom = bottom;
1506 }
1507 }
1508
Dianne Hackbornc777e072010-02-12 13:07:59 -08001509 public void updateSettings() {
1510 ContentResolver resolver = mContext.getContentResolver();
1511 boolean updateRotation = false;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001512 synchronized (mLock) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001513 mEndcallBehavior = Settings.System.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001514 Settings.System.END_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001515 Settings.System.END_BUTTON_BEHAVIOR_DEFAULT,
1516 UserHandle.USER_CURRENT);
1517 mIncallPowerBehavior = Settings.Secure.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001518 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001519 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT,
1520 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001521
Jeff Browna20dda42014-05-27 20:57:24 -07001522 // Configure wake gesture.
1523 boolean wakeGestureEnabledSetting = Settings.Secure.getIntForUser(resolver,
1524 Settings.Secure.WAKE_GESTURE_ENABLED, 0,
1525 UserHandle.USER_CURRENT) != 0;
1526 if (mWakeGestureEnabledSetting != wakeGestureEnabledSetting) {
1527 mWakeGestureEnabledSetting = wakeGestureEnabledSetting;
1528 updateWakeGestureListenerLp();
1529 }
1530
Jeff Brown207673cd2012-06-05 17:47:11 -07001531 // Configure rotation lock.
Christopher Tate5e08af02012-09-21 17:17:22 -07001532 int userRotation = Settings.System.getIntForUser(resolver,
1533 Settings.System.USER_ROTATION, Surface.ROTATION_0,
1534 UserHandle.USER_CURRENT);
Jeff Brown207673cd2012-06-05 17:47:11 -07001535 if (mUserRotation != userRotation) {
1536 mUserRotation = userRotation;
1537 updateRotation = true;
1538 }
Christopher Tate5e08af02012-09-21 17:17:22 -07001539 int userRotationMode = Settings.System.getIntForUser(resolver,
1540 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
Jeff Brown207673cd2012-06-05 17:47:11 -07001541 WindowManagerPolicy.USER_ROTATION_FREE :
1542 WindowManagerPolicy.USER_ROTATION_LOCKED;
1543 if (mUserRotationMode != userRotationMode) {
1544 mUserRotationMode = userRotationMode;
1545 updateRotation = true;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001546 updateOrientationListenerLp();
1547 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001548
Dianne Hackbornc777e072010-02-12 13:07:59 -08001549 if (mSystemReady) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001550 int pointerLocation = Settings.System.getIntForUser(resolver,
1551 Settings.System.POINTER_LOCATION, 0, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001552 if (mPointerLocationMode != pointerLocation) {
1553 mPointerLocationMode = pointerLocation;
Jeff Brown70825162012-03-28 17:27:48 -07001554 mHandler.sendEmptyMessage(pointerLocation != 0 ?
1555 MSG_ENABLE_POINTER_LOCATION : MSG_DISABLE_POINTER_LOCATION);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001556 }
1557 }
1558 // use screen off timeout setting as the timeout for the lockscreen
Christopher Tate5e08af02012-09-21 17:17:22 -07001559 mLockScreenTimeout = Settings.System.getIntForUser(resolver,
1560 Settings.System.SCREEN_OFF_TIMEOUT, 0, UserHandle.USER_CURRENT);
1561 String imId = Settings.Secure.getStringForUser(resolver,
1562 Settings.Secure.DEFAULT_INPUT_METHOD, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001563 boolean hasSoftInput = imId != null && imId.length() > 0;
1564 if (mHasSoftInput != hasSoftInput) {
1565 mHasSoftInput = hasSoftInput;
1566 updateRotation = true;
1567 }
John Spurlockf1a36642013-10-12 17:50:42 -04001568 if (mImmersiveModeConfirmation != null) {
John Spurlock4355a532014-02-19 09:49:25 -05001569 mImmersiveModeConfirmation.loadSetting(mCurrentUserId);
John Spurlockd67ec252013-09-05 11:31:54 -04001570 }
John Spurlockc6d1c602014-01-17 15:22:06 -05001571 PolicyControl.reloadFromSetting(mContext);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001572 }
1573 if (updateRotation) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07001574 updateRotation(true);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001575 }
Jeff Brown70825162012-03-28 17:27:48 -07001576 }
1577
Jeff Browna20dda42014-05-27 20:57:24 -07001578 private void updateWakeGestureListenerLp() {
1579 if (shouldEnableWakeGestureLp()) {
1580 mWakeGestureListener.requestWakeUpTrigger();
1581 } else {
1582 mWakeGestureListener.cancelWakeUpTrigger();
1583 }
1584 }
1585
1586 private boolean shouldEnableWakeGestureLp() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07001587 return mWakeGestureEnabledSetting && !mAwake
Jeff Browna20dda42014-05-27 20:57:24 -07001588 && (!mLidControlsSleep || mLidState != LID_CLOSED)
1589 && mWakeGestureListener.isSupported();
1590 }
1591
Jeff Brown70825162012-03-28 17:27:48 -07001592 private void enablePointerLocation() {
1593 if (mPointerLocationView == null) {
1594 mPointerLocationView = new PointerLocationView(mContext);
1595 mPointerLocationView.setPrintCoords(false);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001596 WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
1597 WindowManager.LayoutParams.MATCH_PARENT,
1598 WindowManager.LayoutParams.MATCH_PARENT);
Jeff Brown3b2b3542010-10-15 00:54:27 -07001599 lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001600 lp.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN
1601 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
1602 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1603 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
Jeff Brown90fc9052012-10-01 14:44:24 -07001604 if (ActivityManager.isHighEndGfx()) {
1605 lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
1606 lp.privateFlags |=
1607 WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED;
1608 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001609 lp.format = PixelFormat.TRANSLUCENT;
1610 lp.setTitle("PointerLocation");
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001611 WindowManager wm = (WindowManager)
Dianne Hackbornc777e072010-02-12 13:07:59 -08001612 mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Browncc4f7db2011-08-30 20:34:48 -07001613 lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL;
Jeff Brown70825162012-03-28 17:27:48 -07001614 wm.addView(mPointerLocationView, lp);
Michael Wrightc9c487e2013-11-07 18:55:09 -08001615 mWindowManagerFuncs.registerPointerEventListener(mPointerLocationView);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001616 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001617 }
Jeff Brown70825162012-03-28 17:27:48 -07001618
1619 private void disablePointerLocation() {
Jeff Brown70825162012-03-28 17:27:48 -07001620 if (mPointerLocationView != null) {
Michael Wrightc9c487e2013-11-07 18:55:09 -08001621 mWindowManagerFuncs.unregisterPointerEventListener(mPointerLocationView);
1622 WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Brown70825162012-03-28 17:27:48 -07001623 wm.removeView(mPointerLocationView);
1624 mPointerLocationView = null;
1625 }
1626 }
1627
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001628 private int readRotation(int resID) {
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001629 try {
1630 int rotation = mContext.getResources().getInteger(resID);
1631 switch (rotation) {
1632 case 0:
1633 return Surface.ROTATION_0;
1634 case 90:
1635 return Surface.ROTATION_90;
1636 case 180:
1637 return Surface.ROTATION_180;
1638 case 270:
1639 return Surface.ROTATION_270;
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001640 }
1641 } catch (Resources.NotFoundException e) {
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001642 // fall through
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001643 }
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001644 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001645 }
1646
1647 /** {@inheritDoc} */
Craig Mautner88400d32012-09-30 12:35:45 -07001648 @Override
Dianne Hackbornc2293022013-02-06 23:14:49 -08001649 public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001650 int type = attrs.type;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001651
1652 outAppOp[0] = AppOpsManager.OP_NONE;
1653
Wale Ogunwale74bf0652015-01-12 10:24:36 -08001654 if (!((type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW)
1655 || (type >= FIRST_SUB_WINDOW && type <= LAST_SUB_WINDOW)
1656 || (type >= FIRST_SYSTEM_WINDOW && type <= LAST_SYSTEM_WINDOW))) {
1657 return WindowManagerGlobal.ADD_INVALID_TYPE;
1658 }
1659
1660 if (type < FIRST_SYSTEM_WINDOW || type > LAST_SYSTEM_WINDOW) {
1661 // Window manager will make sure these are okay.
Jeff Brown98365d72012-08-19 20:30:52 -07001662 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001663 }
1664 String permission = null;
1665 switch (type) {
1666 case TYPE_TOAST:
1667 // XXX right now the app process has complete control over
1668 // this... should introduce a token to let the system
1669 // monitor/control what they are doing.
Jason Monk1c7c3192014-06-26 12:52:18 -04001670 outAppOp[0] = AppOpsManager.OP_TOAST_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001671 break;
Daniel Sandler7d276c32012-01-30 14:33:52 -05001672 case TYPE_DREAM:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001673 case TYPE_INPUT_METHOD:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001674 case TYPE_WALLPAPER:
keunyounga446bf02013-06-21 19:07:57 -07001675 case TYPE_PRIVATE_PRESENTATION:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001676 case TYPE_VOICE_INTERACTION:
Svetoslav3a5c7212014-10-14 09:54:26 -07001677 case TYPE_ACCESSIBILITY_OVERLAY:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001678 // The window manager will check these.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001679 break;
1680 case TYPE_PHONE:
1681 case TYPE_PRIORITY_PHONE:
1682 case TYPE_SYSTEM_ALERT:
1683 case TYPE_SYSTEM_ERROR:
1684 case TYPE_SYSTEM_OVERLAY:
1685 permission = android.Manifest.permission.SYSTEM_ALERT_WINDOW;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001686 outAppOp[0] = AppOpsManager.OP_SYSTEM_ALERT_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001687 break;
1688 default:
1689 permission = android.Manifest.permission.INTERNAL_SYSTEM_WINDOW;
1690 }
1691 if (permission != null) {
1692 if (mContext.checkCallingOrSelfPermission(permission)
1693 != PackageManager.PERMISSION_GRANTED) {
Jeff Brown98365d72012-08-19 20:30:52 -07001694 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001695 }
1696 }
Jeff Brown98365d72012-08-19 20:30:52 -07001697 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001698 }
Craig Mautner88400d32012-09-30 12:35:45 -07001699
1700 @Override
1701 public boolean checkShowToOwnerOnly(WindowManager.LayoutParams attrs) {
1702
1703 // If this switch statement is modified, modify the comment in the declarations of
1704 // the type in {@link WindowManager.LayoutParams} as well.
1705 switch (attrs.type) {
1706 default:
1707 // These are the windows that by default are shown only to the user that created
1708 // them. If this needs to be overridden, set
1709 // {@link WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS} in
1710 // {@link WindowManager.LayoutParams}. Note that permission
1711 // {@link android.Manifest.permission.INTERNAL_SYSTEM_WINDOW} is required as well.
1712 if ((attrs.privateFlags & PRIVATE_FLAG_SHOW_FOR_ALL_USERS) == 0) {
1713 return true;
1714 }
1715 break;
1716
1717 // These are the windows that by default are shown to all users. However, to
1718 // protect against spoofing, check permissions below.
1719 case TYPE_APPLICATION_STARTING:
1720 case TYPE_BOOT_PROGRESS:
1721 case TYPE_DISPLAY_OVERLAY:
1722 case TYPE_HIDDEN_NAV_CONSUMER:
Jim Miller5ecd8112013-01-09 18:50:26 -08001723 case TYPE_KEYGUARD_SCRIM:
Craig Mautner88400d32012-09-30 12:35:45 -07001724 case TYPE_KEYGUARD_DIALOG:
1725 case TYPE_MAGNIFICATION_OVERLAY:
1726 case TYPE_NAVIGATION_BAR:
1727 case TYPE_NAVIGATION_BAR_PANEL:
1728 case TYPE_PHONE:
1729 case TYPE_POINTER:
1730 case TYPE_PRIORITY_PHONE:
Craig Mautner88400d32012-09-30 12:35:45 -07001731 case TYPE_SEARCH_BAR:
1732 case TYPE_STATUS_BAR:
1733 case TYPE_STATUS_BAR_PANEL:
1734 case TYPE_STATUS_BAR_SUB_PANEL:
1735 case TYPE_SYSTEM_DIALOG:
Craig Mautner88400d32012-09-30 12:35:45 -07001736 case TYPE_VOLUME_OVERLAY:
keunyounga446bf02013-06-21 19:07:57 -07001737 case TYPE_PRIVATE_PRESENTATION:
Craig Mautner88400d32012-09-30 12:35:45 -07001738 break;
1739 }
1740
1741 // Check if third party app has set window to system window type.
1742 return mContext.checkCallingOrSelfPermission(
1743 android.Manifest.permission.INTERNAL_SYSTEM_WINDOW)
1744 != PackageManager.PERMISSION_GRANTED;
1745 }
1746
Craig Mautner967212c2013-04-13 21:10:58 -07001747 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001748 public void adjustWindowParamsLw(WindowManager.LayoutParams attrs) {
1749 switch (attrs.type) {
1750 case TYPE_SYSTEM_OVERLAY:
Jeff Brown3b2b3542010-10-15 00:54:27 -07001751 case TYPE_SECURE_SYSTEM_OVERLAY:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001752 // These types of windows can't receive input events.
1753 attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1754 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001755 attrs.flags &= ~WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001756 break;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001757 case TYPE_STATUS_BAR:
1758
1759 // If the Keyguard is in a hidden state (occluded by another window), we force to
1760 // remove the wallpaper and keyguard flag so that any change in-flight after setting
1761 // the keyguard as occluded wouldn't set these flags again.
1762 // See {@link #processKeyguardSetHiddenResultLw}.
1763 if (mKeyguardHidden) {
1764 attrs.flags &= ~WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
1765 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
1766 }
1767 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001768 }
Adrian Roos38502112014-04-09 21:04:11 +02001769
1770 if (attrs.type != TYPE_STATUS_BAR) {
1771 // The status bar is the only window allowed to exhibit keyguard behavior.
1772 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
1773 }
Adrian Roosea562512014-05-05 13:33:03 +02001774
1775 if (ActivityManager.isHighEndGfx()
1776 && (attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0) {
Adrian Roosf5e9b5c2014-09-10 15:27:41 +02001777 attrs.subtreeSystemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
Adrian Roosea562512014-05-05 13:33:03 +02001778 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
1779 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001780 }
RoboErik8a2cfc32014-05-16 11:19:38 -07001781
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001782 void readLidState() {
Jeff Brown2e7760e2012-04-11 15:14:55 -07001783 mLidState = mWindowManagerFuncs.getLidState();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001784 }
RoboErik8a2cfc32014-05-16 11:19:38 -07001785
Michael Wright3818c922014-09-02 13:59:07 -07001786 private void readCameraLensCoverState() {
1787 mCameraLensCoverState = mWindowManagerFuncs.getCameraLensCoverState();
1788 }
1789
Jeff Browndaa37532012-05-01 15:54:03 -07001790 private boolean isHidden(int accessibilityMode) {
1791 switch (accessibilityMode) {
1792 case 1:
1793 return mLidState == LID_CLOSED;
1794 case 2:
1795 return mLidState == LID_OPEN;
1796 default:
1797 return false;
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001798 }
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001799 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001800
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001801 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07001802 @Override
Jeff Browndaa37532012-05-01 15:54:03 -07001803 public void adjustConfigurationLw(Configuration config, int keyboardPresence,
1804 int navigationPresence) {
1805 mHaveBuiltInKeyboard = (keyboardPresence & PRESENCE_INTERNAL) != 0;
1806
Jeff Brownf71343d2013-05-31 17:59:11 -07001807 readConfigurationDependentBehaviors();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001808 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07001809 applyLidSwitchState();
Jeff Brownd04a88c2011-01-16 14:05:47 -08001810
Jeff Browndaa37532012-05-01 15:54:03 -07001811 if (config.keyboard == Configuration.KEYBOARD_NOKEYS
1812 || (keyboardPresence == PRESENCE_INTERNAL
1813 && isHidden(mLidKeyboardAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001814 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_YES;
Jeff Browndaa37532012-05-01 15:54:03 -07001815 if (!mHasSoftInput) {
1816 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_YES;
1817 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001818 }
1819
Jeff Browndaa37532012-05-01 15:54:03 -07001820 if (config.navigation == Configuration.NAVIGATION_NONAV
1821 || (navigationPresence == PRESENCE_INTERNAL
1822 && isHidden(mLidNavigationAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001823 config.navigationHidden = Configuration.NAVIGATIONHIDDEN_YES;
Jeff Brownd04a88c2011-01-16 14:05:47 -08001824 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001825 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001826
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001827 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07001828 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001829 public int windowTypeToLayerLw(int type) {
1830 if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001831 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001832 }
1833 switch (type) {
keunyounga446bf02013-06-21 19:07:57 -07001834 case TYPE_PRIVATE_PRESENTATION:
1835 return 2;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001836 case TYPE_WALLPAPER:
1837 // wallpaper is at the bottom, though the window manager may move it.
1838 return 2;
1839 case TYPE_PHONE:
1840 return 3;
1841 case TYPE_SEARCH_BAR:
1842 return 4;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001843 case TYPE_VOICE_INTERACTION:
1844 // voice interaction layer is almost immediately above apps.
1845 return 5;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001846 case TYPE_SYSTEM_DIALOG:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001847 return 6;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001848 case TYPE_TOAST:
1849 // toasts and the plugged-in battery thing
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001850 return 7;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001851 case TYPE_PRIORITY_PHONE:
1852 // SIM errors and unlock. Not sure if this really should be in a high layer.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001853 return 8;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001854 case TYPE_DREAM:
1855 // used for Dreams (screensavers with TYPE_DREAM windows)
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001856 return 9;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001857 case TYPE_SYSTEM_ALERT:
1858 // like the ANR / app crashed dialogs
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001859 return 10;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001860 case TYPE_INPUT_METHOD:
1861 // on-screen keyboards and other such input method user interfaces go here.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001862 return 11;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001863 case TYPE_INPUT_METHOD_DIALOG:
1864 // on-screen keyboards and other such input method user interfaces go here.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001865 return 12;
Jim Miller5ecd8112013-01-09 18:50:26 -08001866 case TYPE_KEYGUARD_SCRIM:
1867 // the safety window that shows behind keyguard while keyguard is starting
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001868 return 13;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001869 case TYPE_STATUS_BAR_SUB_PANEL:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001870 return 14;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001871 case TYPE_STATUS_BAR:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001872 return 15;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001873 case TYPE_STATUS_BAR_PANEL:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001874 return 16;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001875 case TYPE_KEYGUARD_DIALOG:
1876 return 17;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001877 case TYPE_VOLUME_OVERLAY:
1878 // the on-screen volume indicator and controller shown when the user
1879 // changes the device volume
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001880 return 18;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001881 case TYPE_SYSTEM_OVERLAY:
1882 // the on-screen volume indicator and controller shown when the user
1883 // changes the device volume
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001884 return 19;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001885 case TYPE_NAVIGATION_BAR:
1886 // the navigation bar, if available, shows atop most things
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001887 return 20;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001888 case TYPE_NAVIGATION_BAR_PANEL:
1889 // some panels (e.g. search) need to show on top of the navigation bar
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001890 return 21;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001891 case TYPE_SYSTEM_ERROR:
1892 // system-level error dialogs
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001893 return 22;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001894 case TYPE_MAGNIFICATION_OVERLAY:
1895 // used to highlight the magnified portion of a display
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001896 return 23;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001897 case TYPE_DISPLAY_OVERLAY:
1898 // used to simulate secondary display devices
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001899 return 24;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001900 case TYPE_DRAG:
1901 // the drag layer: input for drag-and-drop is associated with this window,
1902 // which sits above all other focusable windows
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001903 return 25;
Svetoslav3a5c7212014-10-14 09:54:26 -07001904 case TYPE_ACCESSIBILITY_OVERLAY:
1905 // overlay put by accessibility services to intercept user interaction
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001906 return 26;
Svetoslav3a5c7212014-10-14 09:54:26 -07001907 case TYPE_SECURE_SYSTEM_OVERLAY:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001908 return 27;
Svetoslav3a5c7212014-10-14 09:54:26 -07001909 case TYPE_BOOT_PROGRESS:
1910 return 28;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001911 case TYPE_POINTER:
1912 // the (mouse) pointer layer
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001913 return 29;
Svetoslav3a5c7212014-10-14 09:54:26 -07001914 case TYPE_HIDDEN_NAV_CONSUMER:
1915 return 30;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001916 }
1917 Log.e(TAG, "Unknown window type: " + type);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001918 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001919 }
1920
1921 /** {@inheritDoc} */
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001922 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001923 public int subWindowTypeToLayerLw(int type) {
1924 switch (type) {
1925 case TYPE_APPLICATION_PANEL:
1926 case TYPE_APPLICATION_ATTACHED_DIALOG:
1927 return APPLICATION_PANEL_SUBLAYER;
1928 case TYPE_APPLICATION_MEDIA:
1929 return APPLICATION_MEDIA_SUBLAYER;
Dianne Hackborn5cb8d792009-05-21 17:34:15 -07001930 case TYPE_APPLICATION_MEDIA_OVERLAY:
1931 return APPLICATION_MEDIA_OVERLAY_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001932 case TYPE_APPLICATION_SUB_PANEL:
1933 return APPLICATION_SUB_PANEL_SUBLAYER;
1934 }
1935 Log.e(TAG, "Unknown sub-window type: " + type);
1936 return 0;
1937 }
1938
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001939 @Override
Dianne Hackbornabe0da02009-09-18 01:55:39 -07001940 public int getMaxWallpaperLayer() {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001941 return windowTypeToLayerLw(TYPE_STATUS_BAR);
Dianne Hackbornabe0da02009-09-18 01:55:39 -07001942 }
1943
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001944 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001945 public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07001946 if (mHasNavigationBar) {
1947 // For a basic navigation bar, when we are in landscape mode we place
1948 // the navigation bar to the side.
Daniel Sandler4a066c52012-04-20 14:49:13 -04001949 if (mNavigationBarCanMove && fullWidth > fullHeight) {
1950 return fullWidth - mNavigationBarWidthForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07001951 }
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001952 }
1953 return fullWidth;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001954 }
1955
Jose Lima9546b202014-07-02 17:21:51 -07001956 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001957 public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07001958 if (mHasNavigationBar) {
1959 // For a basic navigation bar, when we are in portrait mode we place
1960 // the navigation bar to the bottom.
Daniel Sandler4a066c52012-04-20 14:49:13 -04001961 if (!mNavigationBarCanMove || fullWidth < fullHeight) {
1962 return fullHeight - mNavigationBarHeightForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07001963 }
1964 }
1965 return fullHeight;
Dianne Hackborn69cb8752011-05-19 18:13:32 -07001966 }
1967
Jose Lima9546b202014-07-02 17:21:51 -07001968 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001969 public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation) {
1970 return getNonDecorDisplayWidth(fullWidth, fullHeight, rotation);
Dianne Hackborn69cb8752011-05-19 18:13:32 -07001971 }
1972
Jose Lima9546b202014-07-02 17:21:51 -07001973 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001974 public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation) {
John Spurlock80f00c12013-06-13 11:10:51 -04001975 // There is a separate status bar at the top of the display. We don't count that as part
1976 // of the fixed decor, since it can hide; however, for purposes of configurations,
Dianne Hackborn077ee852012-04-09 16:27:07 -07001977 // we do want to exclude it since applications can't generally use that part
1978 // of the screen.
John Spurlock80f00c12013-06-13 11:10:51 -04001979 return getNonDecorDisplayHeight(fullWidth, fullHeight, rotation) - mStatusBarHeight;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001980 }
1981
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001982 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07001983 public boolean isForceHiding(WindowManager.LayoutParams attrs) {
1984 return (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 ||
Jim Millerab954542014-10-10 18:21:49 -07001985 (isKeyguardHostWindow(attrs) &&
1986 (mKeyguardDelegate != null && mKeyguardDelegate.isShowing())) ||
Adrian Roos69e510d2014-07-13 14:57:59 +02001987 (attrs.type == TYPE_KEYGUARD_SCRIM);
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07001988 }
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001989
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001990 @Override
Jorim Jaggi0d674622014-05-21 01:34:15 +02001991 public boolean isKeyguardHostWindow(WindowManager.LayoutParams attrs) {
1992 return attrs.type == TYPE_STATUS_BAR;
1993 }
1994
1995 @Override
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07001996 public boolean canBeForceHidden(WindowState win, WindowManager.LayoutParams attrs) {
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001997 switch (attrs.type) {
1998 case TYPE_STATUS_BAR:
1999 case TYPE_NAVIGATION_BAR:
2000 case TYPE_WALLPAPER:
2001 case TYPE_DREAM:
Jim Miller5ecd8112013-01-09 18:50:26 -08002002 case TYPE_KEYGUARD_SCRIM:
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002003 return false;
2004 default:
2005 return true;
2006 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002007 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002008
Craig Mautner7d7808f2014-09-11 18:02:38 -07002009 @Override
2010 public WindowState getWinShowWhenLockedLw() {
2011 return mWinShowWhenLocked;
2012 }
2013
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002014 /** {@inheritDoc} */
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002015 @Override
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07002016 public View addStartingWindow(IBinder appToken, String packageName, int theme,
2017 CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes,
Adam Powell04fe6eb2013-05-31 14:39:48 -07002018 int icon, int logo, int windowFlags) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002019 if (!SHOW_STARTING_ANIMATIONS) {
2020 return null;
2021 }
2022 if (packageName == null) {
2023 return null;
2024 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002025
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002026 WindowManager wm = null;
2027 View view = null;
2028
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002029 try {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002030 Context context = mContext;
Craig Mautner6fbda632012-07-03 09:26:39 -07002031 if (DEBUG_STARTING_WINDOW) Slog.d(TAG, "addStartingWindow " + packageName
2032 + ": nonLocalizedLabel=" + nonLocalizedLabel + " theme="
2033 + Integer.toHexString(theme));
Dianne Hackborn247fe742011-01-08 17:25:57 -08002034 if (theme != context.getThemeResId() || labelRes != 0) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002035 try {
2036 context = context.createPackageContext(packageName, 0);
Dianne Hackborn247fe742011-01-08 17:25:57 -08002037 context.setTheme(theme);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002038 } catch (PackageManager.NameNotFoundException e) {
2039 // Ignore
2040 }
2041 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002042
Jorim Jaggib10e33f2015-02-04 21:57:40 +01002043 Window win = new PhoneWindow(context);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002044 final TypedArray ta = win.getWindowStyle();
2045 if (ta.getBoolean(
2046 com.android.internal.R.styleable.Window_windowDisablePreview, false)
2047 || ta.getBoolean(
2048 com.android.internal.R.styleable.Window_windowShowWallpaper,false)) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002049 return null;
2050 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002051
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002052 Resources r = context.getResources();
2053 win.setTitle(r.getText(labelRes, nonLocalizedLabel));
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002054
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002055 win.setType(
2056 WindowManager.LayoutParams.TYPE_APPLICATION_STARTING);
2057 // Force the window flags: this is a fake window, so it is not really
2058 // touchable or focusable by the user. We also add in the ALT_FOCUSABLE_IM
2059 // flag because we do know that the next window will take input
2060 // focus, so we want to get the IME window up on top of us right away.
2061 win.setFlags(
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08002062 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002063 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
2064 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
2065 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08002066 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002067 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
2068 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
2069 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002070
Adam Powell04fe6eb2013-05-31 14:39:48 -07002071 win.setDefaultIcon(icon);
2072 win.setDefaultLogo(logo);
2073
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002074 win.setLayout(WindowManager.LayoutParams.MATCH_PARENT,
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07002075 WindowManager.LayoutParams.MATCH_PARENT);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002076
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002077 final WindowManager.LayoutParams params = win.getAttributes();
2078 params.token = appToken;
2079 params.packageName = packageName;
2080 params.windowAnimations = win.getWindowStyle().getResourceId(
2081 com.android.internal.R.styleable.Window_windowAnimationStyle, 0);
John Reck61375a82014-09-18 19:27:48 +00002082 params.privateFlags |=
2083 WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED;
Craig Mautner88400d32012-09-30 12:35:45 -07002084 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
Adam Lesinski95c42972013-10-02 10:13:27 -07002085
2086 if (!compatInfo.supportsScreen()) {
2087 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
2088 }
2089
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002090 params.setTitle("Starting " + packageName);
2091
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002092 wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
2093 view = win.getDecorView();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002094
2095 if (win.isFloating()) {
2096 // Whoops, there is no way to display an animation/preview
2097 // of such a thing! After all that work... let's skip it.
2098 // (Note that we must do this here because it is in
2099 // getDecorView() where the theme is evaluated... maybe
2100 // we should peek the floating attribute from the theme
2101 // earlier.)
2102 return null;
2103 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002104
Craig Mautner6fbda632012-07-03 09:26:39 -07002105 if (DEBUG_STARTING_WINDOW) Slog.d(
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002106 TAG, "Adding starting window for " + packageName
2107 + " / " + appToken + ": "
2108 + (view.getParent() != null ? view : null));
2109
2110 wm.addView(view, params);
2111
2112 // Only return the view if it was successfully added to the
2113 // window manager... which we can tell by it having a parent.
2114 return view.getParent() != null ? view : null;
Jeff Brown98365d72012-08-19 20:30:52 -07002115 } catch (WindowManager.BadTokenException e) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002116 // ignore
Craig Mautner42bf39e2014-02-21 16:46:22 -08002117 Log.w(TAG, appToken + " already running, starting window not displayed. " +
2118 e.getMessage());
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002119 } catch (RuntimeException e) {
2120 // don't crash if something else bad happens, for example a
2121 // failure loading resources because we are loading from an app
2122 // on external storage that has been unmounted.
2123 Log.w(TAG, appToken + " failed creating starting window", e);
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002124 } finally {
2125 if (view != null && view.getParent() == null) {
2126 Log.w(TAG, "view not successfully added to wm, removing view");
2127 wm.removeViewImmediate(view);
2128 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002129 }
2130
2131 return null;
2132 }
2133
2134 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07002135 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002136 public void removeStartingWindow(IBinder appToken, View window) {
Craig Mautner276a6eb2014-11-04 15:32:57 -08002137 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Removing starting window for " + appToken + ": "
2138 + window + " Callers=" + Debug.getCallers(4));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002139
2140 if (window != null) {
Dianne Hackborn5fd21692011-06-07 14:09:47 -07002141 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002142 wm.removeView(window);
2143 }
2144 }
2145
2146 /**
2147 * Preflight adding a window to the system.
RoboErik8a2cfc32014-05-16 11:19:38 -07002148 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002149 * Currently enforces that three window types are singletons:
2150 * <ul>
2151 * <li>STATUS_BAR_TYPE</li>
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002152 * <li>KEYGUARD_TYPE</li>
2153 * </ul>
RoboErik8a2cfc32014-05-16 11:19:38 -07002154 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002155 * @param win The window to be added
2156 * @param attrs Information about the window to be added
RoboErik8a2cfc32014-05-16 11:19:38 -07002157 *
Jeff Brown98365d72012-08-19 20:30:52 -07002158 * @return If ok, WindowManagerImpl.ADD_OKAY. If too many singletons,
2159 * WindowManagerImpl.ADD_MULTIPLE_SINGLETON
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002160 */
Jose Lima9546b202014-07-02 17:21:51 -07002161 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002162 public int prepareAddWindowLw(WindowState win, WindowManager.LayoutParams attrs) {
2163 switch (attrs.type) {
2164 case TYPE_STATUS_BAR:
Joe Onorato8bc6c512010-06-04 16:21:12 -04002165 mContext.enforceCallingOrSelfPermission(
2166 android.Manifest.permission.STATUS_BAR_SERVICE,
2167 "PhoneWindowManager");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002168 if (mStatusBar != null) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002169 if (mStatusBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07002170 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002171 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002172 }
2173 mStatusBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04002174 mStatusBarController.setWindow(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002175 break;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002176 case TYPE_NAVIGATION_BAR:
2177 mContext.enforceCallingOrSelfPermission(
2178 android.Manifest.permission.STATUS_BAR_SERVICE,
2179 "PhoneWindowManager");
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002180 if (mNavigationBar != null) {
2181 if (mNavigationBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07002182 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002183 }
2184 }
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002185 mNavigationBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04002186 mNavigationBarController.setWindow(win);
Craig Mautnereda67292013-04-28 13:50:14 -07002187 if (DEBUG_LAYOUT) Slog.i(TAG, "NAVIGATION BAR: " + mNavigationBar);
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002188 break;
Jim Millere898ac52012-04-06 17:10:57 -07002189 case TYPE_NAVIGATION_BAR_PANEL:
2190 mContext.enforceCallingOrSelfPermission(
2191 android.Manifest.permission.STATUS_BAR_SERVICE,
2192 "PhoneWindowManager");
2193 break;
Dianne Hackborn08743722009-12-21 12:16:51 -08002194 case TYPE_STATUS_BAR_PANEL:
Joe Onorato8bc6c512010-06-04 16:21:12 -04002195 mContext.enforceCallingOrSelfPermission(
2196 android.Manifest.permission.STATUS_BAR_SERVICE,
2197 "PhoneWindowManager");
Dianne Hackborn08743722009-12-21 12:16:51 -08002198 break;
Joe Onorato29fc2c92010-11-24 10:26:50 -08002199 case TYPE_STATUS_BAR_SUB_PANEL:
2200 mContext.enforceCallingOrSelfPermission(
2201 android.Manifest.permission.STATUS_BAR_SERVICE,
2202 "PhoneWindowManager");
Joe Onorato29fc2c92010-11-24 10:26:50 -08002203 break;
Jim Miller5ecd8112013-01-09 18:50:26 -08002204 case TYPE_KEYGUARD_SCRIM:
Jim Miller25190572013-02-28 17:36:24 -08002205 if (mKeyguardScrim != null) {
2206 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
2207 }
Jim Miller5ecd8112013-01-09 18:50:26 -08002208 mKeyguardScrim = win;
2209 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002210 }
Jeff Brown98365d72012-08-19 20:30:52 -07002211 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002212 }
2213
2214 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07002215 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002216 public void removeWindowLw(WindowState win) {
2217 if (mStatusBar == win) {
2218 mStatusBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04002219 mStatusBarController.setWindow(null);
Jim Millerc0b676d2013-03-22 16:11:08 -07002220 mKeyguardDelegate.showScrim();
Jim Miller5ecd8112013-01-09 18:50:26 -08002221 } else if (mKeyguardScrim == win) {
2222 Log.v(TAG, "Removing keyguard scrim");
2223 mKeyguardScrim = null;
2224 } if (mNavigationBar == win) {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002225 mNavigationBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04002226 mNavigationBarController.setWindow(null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002227 }
2228 }
2229
2230 static final boolean PRINT_ANIM = false;
RoboErik8a2cfc32014-05-16 11:19:38 -07002231
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002232 /** {@inheritDoc} */
Craig Mautner4b71aa12012-12-27 17:20:01 -08002233 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002234 public int selectAnimationLw(WindowState win, int transit) {
2235 if (PRINT_ANIM) Log.i(TAG, "selectAnimation in " + win
2236 + ": transit=" + transit);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002237 if (win == mStatusBar) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002238 boolean isKeyguard = (win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002239 if (transit == TRANSIT_EXIT
2240 || transit == TRANSIT_HIDE) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002241 return isKeyguard ? -1 : R.anim.dock_top_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002242 } else if (transit == TRANSIT_ENTER
2243 || transit == TRANSIT_SHOW) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002244 return isKeyguard ? -1 : R.anim.dock_top_enter;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002245 }
2246 } else if (win == mNavigationBar) {
2247 // This can be on either the bottom or the right.
2248 if (mNavigationBarOnBottom) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08002249 if (transit == TRANSIT_EXIT
2250 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002251 return R.anim.dock_bottom_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002252 } else if (transit == TRANSIT_ENTER
2253 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002254 return R.anim.dock_bottom_enter;
2255 }
2256 } else {
Craig Mautner4b71aa12012-12-27 17:20:01 -08002257 if (transit == TRANSIT_EXIT
2258 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002259 return R.anim.dock_right_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002260 } else if (transit == TRANSIT_ENTER
2261 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002262 return R.anim.dock_right_enter;
2263 }
2264 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08002265 }
2266
2267 if (transit == TRANSIT_PREVIEW_DONE) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002268 if (win.hasAppShownWindows()) {
2269 if (PRINT_ANIM) Log.i(TAG, "**** STARTING EXIT");
2270 return com.android.internal.R.anim.app_starting_exit;
2271 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07002272 } else if (win.getAttrs().type == TYPE_DREAM && mDreamingLockscreen
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002273 && transit == TRANSIT_ENTER) {
2274 // Special case: we are animating in a dream, while the keyguard
2275 // is shown. We don't want an animation on the dream, because
2276 // we need it shown immediately with the keyguard animating away
2277 // to reveal it.
2278 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002279 }
2280
2281 return 0;
2282 }
2283
Craig Mautner3c174372013-02-21 17:54:37 -08002284 @Override
2285 public void selectRotationAnimationLw(int anim[]) {
2286 if (PRINT_ANIM) Slog.i(TAG, "selectRotationAnimation mTopFullscreen="
2287 + mTopFullscreenOpaqueWindowState + " rotationAnimation="
2288 + (mTopFullscreenOpaqueWindowState == null ?
2289 "0" : mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation));
2290 if (mTopFullscreenOpaqueWindowState != null && mTopIsFullscreen) {
2291 switch (mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation) {
2292 case ROTATION_ANIMATION_CROSSFADE:
2293 anim[0] = R.anim.rotation_animation_xfade_exit;
2294 anim[1] = R.anim.rotation_animation_enter;
2295 break;
2296 case ROTATION_ANIMATION_JUMPCUT:
2297 anim[0] = R.anim.rotation_animation_jump_exit;
2298 anim[1] = R.anim.rotation_animation_enter;
2299 break;
2300 case ROTATION_ANIMATION_ROTATE:
2301 default:
2302 anim[0] = anim[1] = 0;
2303 break;
2304 }
2305 } else {
2306 anim[0] = anim[1] = 0;
2307 }
2308 }
2309
2310 @Override
2311 public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId,
2312 boolean forceDefault) {
2313 switch (exitAnimId) {
2314 case R.anim.rotation_animation_xfade_exit:
2315 case R.anim.rotation_animation_jump_exit:
2316 // These are the only cases that matter.
2317 if (forceDefault) {
2318 return false;
2319 }
2320 int anim[] = new int[2];
2321 selectRotationAnimationLw(anim);
2322 return (exitAnimId == anim[0] && enterAnimId == anim[1]);
2323 default:
2324 return true;
2325 }
2326 }
2327
2328 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002329 public Animation createForceHideEnterAnimation(boolean onWallpaper,
2330 boolean goingToNotificationShade) {
2331 if (goingToNotificationShade) {
2332 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_behind_enter_fade_in);
Craig Mautnerb8340802014-11-04 15:32:57 -08002333 }
Craig Mautner276a6eb2014-11-04 15:32:57 -08002334
2335 AnimationSet set = (AnimationSet) AnimationUtils.loadAnimation(mContext, onWallpaper ?
2336 R.anim.lock_screen_behind_enter_wallpaper :
2337 R.anim.lock_screen_behind_enter);
2338
2339 // TODO: Use XML interpolators when we have log interpolators available in XML.
2340 final List<Animation> animations = set.getAnimations();
2341 for (int i = animations.size() - 1; i >= 0; --i) {
2342 animations.get(i).setInterpolator(mLogDecelerateInterpolator);
2343 }
2344
2345 return set;
Jorim Jaggi76a16232014-08-08 17:00:47 +02002346 }
2347
2348
2349 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002350 public Animation createForceHideWallpaperExitAnimation(boolean goingToNotificationShade) {
2351 if (goingToNotificationShade) {
2352 return null;
2353 } else {
2354 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_wallpaper_exit);
2355 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002356 }
John Spurlockc8b46ca2013-04-08 12:59:26 -04002357
2358 private static void awakenDreams() {
2359 IDreamManager dreamManager = getDreamManager();
2360 if (dreamManager != null) {
2361 try {
2362 dreamManager.awaken();
2363 } catch (RemoteException e) {
2364 // fine, stay asleep then
2365 }
2366 }
2367 }
2368
2369 static IDreamManager getDreamManager() {
2370 return IDreamManager.Stub.asInterface(
2371 ServiceManager.checkService(DreamService.DREAM_SERVICE));
2372 }
2373
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002374 TelecomManager getTelecommService() {
2375 return (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002376 }
2377
Jeff Brown4d396052010-10-29 21:50:21 -07002378 static IAudioService getAudioService() {
2379 IAudioService audioService = IAudioService.Stub.asInterface(
2380 ServiceManager.checkService(Context.AUDIO_SERVICE));
2381 if (audioService == null) {
2382 Log.w(TAG, "Unable to find IAudioService interface.");
2383 }
2384 return audioService;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002385 }
2386
2387 boolean keyguardOn() {
Jim Millerab954542014-10-10 18:21:49 -07002388 return isKeyguardShowingAndNotOccluded() || inKeyguardRestrictedKeyInputMode();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002389 }
2390
2391 private static final int[] WINDOW_TYPES_WHERE_HOME_DOESNT_WORK = {
2392 WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
2393 WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
2394 };
2395
2396 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002397 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002398 public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002399 final boolean keyguardOn = keyguardOn();
Jeff Brown1f245102010-11-18 20:53:46 -08002400 final int keyCode = event.getKeyCode();
2401 final int repeatCount = event.getRepeatCount();
2402 final int metaState = event.getMetaState();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002403 final int flags = event.getFlags();
Jeff Brown1f245102010-11-18 20:53:46 -08002404 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
2405 final boolean canceled = event.isCanceled();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002406
Jeff Brown40013652012-05-16 21:22:36 -07002407 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002408 Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount="
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002409 + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed
2410 + " canceled=" + canceled);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002411 }
2412
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002413 // If we think we might have a volume down & power key chord on the way
2414 // but we're not sure, then tell the dispatcher to wait a little while and
2415 // try again later before dispatching.
Christopher Tatee90585f2012-03-05 18:56:25 -08002416 if (mScreenshotChordEnabled && (flags & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07002417 if (mScreenshotChordVolumeDownKeyTriggered && !mScreenshotChordPowerKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002418 final long now = SystemClock.uptimeMillis();
Jeff Brown13f00f02014-10-31 14:45:50 -07002419 final long timeoutTime = mScreenshotChordVolumeDownKeyTime
2420 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002421 if (now < timeoutTime) {
2422 return timeoutTime - now;
2423 }
2424 }
2425 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
Jeff Brown13f00f02014-10-31 14:45:50 -07002426 && mScreenshotChordVolumeDownKeyConsumed) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002427 if (!down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07002428 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002429 }
2430 return -1;
2431 }
2432 }
2433
Michael Wright6a62e552014-06-03 19:19:48 -07002434 // Cancel any pending meta actions if we see any other keys being pressed between the down
2435 // of the meta key and its corresponding up.
Michael Wright251e35d2014-08-22 15:40:27 -07002436 if (mPendingMetaAction && !KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07002437 mPendingMetaAction = false;
2438 }
2439
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002440 // First we always handle the home key here, so applications
2441 // can never break it, although if keyguard is on, we do let
2442 // it handle it, because that gives us the correct 5 second
2443 // timeout.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002444 if (keyCode == KeyEvent.KEYCODE_HOME) {
Michael Jurka7f2668c2012-03-27 07:49:52 -07002445
Jeff Brown49ed71d2010-12-06 17:13:33 -08002446 // If we have released the home key, and didn't do anything else
2447 // while it was pressed, then it is time to go home!
Michael Jurka7f2668c2012-03-27 07:49:52 -07002448 if (!down) {
Jeff Browncaca8812013-05-09 13:34:33 -07002449 cancelPreloadRecentApps();
2450
Jeff Brown49ed71d2010-12-06 17:13:33 -08002451 mHomePressed = false;
Jeff Browncaca8812013-05-09 13:34:33 -07002452 if (mHomeConsumed) {
2453 mHomeConsumed = false;
Michael Jurka7f2668c2012-03-27 07:49:52 -07002454 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002455 }
Jeff Browncaca8812013-05-09 13:34:33 -07002456
2457 if (canceled) {
2458 Log.i(TAG, "Ignoring HOME; event canceled.");
2459 return -1;
2460 }
2461
Yorke Lee4f803242014-12-15 23:22:06 +00002462 // If an incoming call is ringing, HOME is totally disabled.
2463 // (The user is already on the InCallUI at this point,
2464 // and his ONLY options are to answer or reject the call.)
2465 TelecomManager telecomManager = getTelecommService();
2466 if (telecomManager != null && telecomManager.isRinging()) {
2467 Log.i(TAG, "Ignoring HOME; there's a ringing incoming call.");
2468 return -1;
2469 }
2470
Jeff Browncaca8812013-05-09 13:34:33 -07002471 // Delay handling home if a double-tap is possible.
2472 if (mDoubleTapOnHomeBehavior != DOUBLE_TAP_HOME_NOTHING) {
2473 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); // just in case
2474 mHomeDoubleTapPending = true;
2475 mHandler.postDelayed(mHomeDoubleTapTimeoutRunnable,
2476 ViewConfiguration.getDoubleTapTimeout());
2477 return -1;
2478 }
2479
Jeff Brown13f00f02014-10-31 14:45:50 -07002480 handleShortPressOnHome();
Jeff Browncaca8812013-05-09 13:34:33 -07002481 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002482 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002483
2484 // If a system window has focus, then it doesn't make sense
2485 // right now to interact with applications.
2486 WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null;
2487 if (attrs != null) {
2488 final int type = attrs.type;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002489 if (type == WindowManager.LayoutParams.TYPE_KEYGUARD_SCRIM
2490 || type == WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG
2491 || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002492 // the "app" is keyguard, so give it the key
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002493 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002494 }
2495 final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length;
2496 for (int i=0; i<typeCount; i++) {
2497 if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) {
2498 // don't do anything, but also don't pass it to the app
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002499 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002500 }
2501 }
2502 }
Jeff Browncaca8812013-05-09 13:34:33 -07002503
2504 // Remember that home is pressed and handle special actions.
2505 if (repeatCount == 0) {
2506 mHomePressed = true;
2507 if (mHomeDoubleTapPending) {
2508 mHomeDoubleTapPending = false;
2509 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable);
2510 handleDoubleTapOnHome();
2511 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI
2512 || mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
2513 preloadRecentApps();
Michael Jurka7f2668c2012-03-27 07:49:52 -07002514 }
Jeff Browncaca8812013-05-09 13:34:33 -07002515 } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) {
2516 if (!keyguardOn) {
2517 handleLongPressOnHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002518 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002519 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002520 return -1;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002521 } else if (keyCode == KeyEvent.KEYCODE_MENU) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002522 // Hijack modified menu keys for debugging features
2523 final int chordBug = KeyEvent.META_SHIFT_ON;
2524
2525 if (down && repeatCount == 0) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002526 if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002527 Intent intent = new Intent(Intent.ACTION_BUG_REPORT);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002528 mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT,
2529 null, null, null, 0, null, null);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002530 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002531 } else if (SHOW_PROCESSES_ON_ALT_MENU &&
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002532 (metaState & KeyEvent.META_ALT_ON) == KeyEvent.META_ALT_ON) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002533 Intent service = new Intent();
2534 service.setClassName(mContext, "com.android.server.LoadAverageService");
2535 ContentResolver res = mContext.getContentResolver();
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002536 boolean shown = Settings.Global.getInt(
2537 res, Settings.Global.SHOW_PROCESSES, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002538 if (!shown) {
2539 mContext.startService(service);
2540 } else {
2541 mContext.stopService(service);
2542 }
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002543 Settings.Global.putInt(
2544 res, Settings.Global.SHOW_PROCESSES, shown ? 0 : 1);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002545 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002546 }
2547 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002548 } else if (keyCode == KeyEvent.KEYCODE_SEARCH) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002549 if (down) {
2550 if (repeatCount == 0) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002551 mSearchKeyShortcutPending = true;
2552 mConsumeSearchKeyUp = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002553 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002554 } else {
2555 mSearchKeyShortcutPending = false;
2556 if (mConsumeSearchKeyUp) {
2557 mConsumeSearchKeyUp = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002558 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002559 }
2560 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002561 return 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002562 } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) {
Michael Wrightc9ebea72013-01-16 19:25:02 -08002563 if (!keyguardOn) {
Jeff Browncaca8812013-05-09 13:34:33 -07002564 if (down && repeatCount == 0) {
2565 preloadRecentApps();
2566 } else if (!down) {
2567 toggleRecentApps();
Michael Wrightc9ebea72013-01-16 19:25:02 -08002568 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002569 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002570 return -1;
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002571 } else if (keyCode == KeyEvent.KEYCODE_ASSIST) {
2572 if (down) {
2573 if (repeatCount == 0) {
2574 mAssistKeyLongPressed = false;
2575 } else if (repeatCount == 1) {
2576 mAssistKeyLongPressed = true;
2577 if (!keyguardOn) {
2578 launchAssistLongPressAction();
2579 }
2580 }
2581 } else {
2582 if (mAssistKeyLongPressed) {
2583 mAssistKeyLongPressed = false;
2584 } else {
2585 if (!keyguardOn) {
2586 launchAssistAction();
2587 }
2588 }
2589 }
2590 return -1;
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002591 } else if (keyCode == KeyEvent.KEYCODE_VOICE_ASSIST) {
2592 if (!down) {
2593 Intent voiceIntent;
Michael Wright869a67c2014-08-26 19:33:06 -07002594 if (!keyguardOn) {
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002595 voiceIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
2596 } else {
2597 voiceIntent = new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
Michael Wright869a67c2014-08-26 19:33:06 -07002598 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, true);
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002599 }
2600 mContext.startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
2601 }
Jeff Sharkey2991fa32012-12-05 18:06:43 -08002602 } else if (keyCode == KeyEvent.KEYCODE_SYSRQ) {
2603 if (down && repeatCount == 0) {
2604 mHandler.post(mScreenshotRunnable);
2605 }
2606 return -1;
Michael Wrightb854e242013-02-05 17:54:02 -08002607 } else if (keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP
2608 || keyCode == KeyEvent.KEYCODE_BRIGHTNESS_DOWN) {
2609 if (down) {
2610 int direction = keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP ? 1 : -1;
2611
2612 // Disable autobrightness if it's on
2613 int auto = Settings.System.getIntForUser(
2614 mContext.getContentResolver(),
2615 Settings.System.SCREEN_BRIGHTNESS_MODE,
2616 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2617 UserHandle.USER_CURRENT_OR_SELF);
2618 if (auto != 0) {
2619 Settings.System.putIntForUser(mContext.getContentResolver(),
2620 Settings.System.SCREEN_BRIGHTNESS_MODE,
2621 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2622 UserHandle.USER_CURRENT_OR_SELF);
2623 }
2624
2625 int min = mPowerManager.getMinimumScreenBrightnessSetting();
2626 int max = mPowerManager.getMaximumScreenBrightnessSetting();
2627 int step = (max - min + BRIGHTNESS_STEPS - 1) / BRIGHTNESS_STEPS * direction;
2628 int brightness = Settings.System.getIntForUser(mContext.getContentResolver(),
2629 Settings.System.SCREEN_BRIGHTNESS,
2630 mPowerManager.getDefaultScreenBrightnessSetting(),
2631 UserHandle.USER_CURRENT_OR_SELF);
2632 brightness += step;
2633 // Make sure we don't go beyond the limits.
2634 brightness = Math.min(max, brightness);
2635 brightness = Math.max(min, brightness);
2636
2637 Settings.System.putIntForUser(mContext.getContentResolver(),
2638 Settings.System.SCREEN_BRIGHTNESS, brightness,
2639 UserHandle.USER_CURRENT_OR_SELF);
Alan Viverette5a399492014-07-14 16:19:38 -07002640 mContext.startActivityAsUser(new Intent(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG),
2641 UserHandle.CURRENT_OR_SELF);
Michael Wrightb854e242013-02-05 17:54:02 -08002642 }
2643 return -1;
Michael Wrightce0c13a2014-07-30 10:49:21 -07002644 } else if (KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07002645 if (down) {
2646 mPendingMetaAction = true;
2647 } else if (mPendingMetaAction) {
Michael Wright8ab940a2014-09-01 11:01:27 -07002648 launchAssistAction(Intent.EXTRA_ASSIST_INPUT_HINT_KEYBOARD);
Michael Wright6a62e552014-06-03 19:19:48 -07002649 }
2650 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002651 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002652
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002653 // Shortcuts are invoked through Search+key, so intercept those here
Jeff Browncaab4d02010-12-09 22:13:41 -08002654 // Any printing key that is chorded with Search should be consumed
2655 // even if no shortcut was invoked. This prevents text from being
2656 // inadvertently inserted when using a keyboard that has built-in macro
2657 // shortcut keys (that emit Search+x) and some of them are not registered.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002658 if (mSearchKeyShortcutPending) {
Jeff Browncaab4d02010-12-09 22:13:41 -08002659 final KeyCharacterMap kcm = event.getKeyCharacterMap();
2660 if (kcm.isPrintingKey(keyCode)) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002661 mConsumeSearchKeyUp = true;
2662 mSearchKeyShortcutPending = false;
Jeff Browncaab4d02010-12-09 22:13:41 -08002663 if (down && repeatCount == 0 && !keyguardOn) {
2664 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState);
2665 if (shortcutIntent != null) {
2666 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002667 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002668 mContext.startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002669 } catch (ActivityNotFoundException ex) {
2670 Slog.w(TAG, "Dropping shortcut key combination because "
2671 + "the activity to which it is registered was not found: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002672 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode), ex);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002673 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002674 } else {
2675 Slog.i(TAG, "Dropping unregistered shortcut key combination: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002676 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002677 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002678 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002679 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002680 }
2681 }
2682
Jeff Brown68b909d2011-12-07 16:36:01 -08002683 // Invoke shortcuts using Meta.
Jeff Brown602ab322012-05-16 13:33:47 -07002684 if (down && repeatCount == 0 && !keyguardOn
Jeff Brown68b909d2011-12-07 16:36:01 -08002685 && (metaState & KeyEvent.META_META_ON) != 0) {
2686 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brown602ab322012-05-16 13:33:47 -07002687 if (kcm.isPrintingKey(keyCode)) {
2688 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode,
2689 metaState & ~(KeyEvent.META_META_ON
2690 | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON));
2691 if (shortcutIntent != null) {
2692 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2693 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002694 mContext.startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brown602ab322012-05-16 13:33:47 -07002695 } catch (ActivityNotFoundException ex) {
2696 Slog.w(TAG, "Dropping shortcut key combination because "
2697 + "the activity to which it is registered was not found: "
2698 + "META+" + KeyEvent.keyCodeToString(keyCode), ex);
2699 }
2700 return -1;
Jeff Brown68b909d2011-12-07 16:36:01 -08002701 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002702 }
2703 }
2704
Jeff Brown6651a632011-11-28 12:59:11 -08002705 // Handle application launch keys.
Jeff Brown602ab322012-05-16 13:33:47 -07002706 if (down && repeatCount == 0 && !keyguardOn) {
Jeff Brown6651a632011-11-28 12:59:11 -08002707 String category = sApplicationLaunchKeyCategories.get(keyCode);
2708 if (category != null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -08002709 Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category);
Jeff Brown6651a632011-11-28 12:59:11 -08002710 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2711 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002712 mContext.startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brown6651a632011-11-28 12:59:11 -08002713 } catch (ActivityNotFoundException ex) {
2714 Slog.w(TAG, "Dropping application launch key because "
2715 + "the activity to which it is registered was not found: "
2716 + "keyCode=" + keyCode + ", category=" + category, ex);
2717 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002718 return -1;
Jeff Brown6651a632011-11-28 12:59:11 -08002719 }
2720 }
2721
Michael Wright61c46752014-08-21 16:57:33 -07002722 // Display task switcher for ALT-TAB.
Jeff Brown68b909d2011-12-07 16:36:01 -08002723 if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_TAB) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002724 if (mRecentAppsHeldModifiers == 0 && !keyguardOn) {
Jeff Brown68b909d2011-12-07 16:36:01 -08002725 final int shiftlessModifiers = event.getModifiers() & ~KeyEvent.META_SHIFT_MASK;
Michael Wright61c46752014-08-21 16:57:33 -07002726 if (KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_ALT_ON)) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002727 mRecentAppsHeldModifiers = shiftlessModifiers;
2728 showRecentApps(true);
Jeff Brown68b909d2011-12-07 16:36:01 -08002729 return -1;
2730 }
2731 }
Winson Chung1e8d71b2014-05-16 17:05:22 -07002732 } else if (!down && mRecentAppsHeldModifiers != 0
2733 && (metaState & mRecentAppsHeldModifiers) == 0) {
2734 mRecentAppsHeldModifiers = 0;
Winson Chungcdcd4872014-08-05 18:00:13 -07002735 hideRecentApps(true, false);
Jeff Brown68b909d2011-12-07 16:36:01 -08002736 }
2737
Jeff Browncf39bdf2012-05-18 14:41:19 -07002738 // Handle keyboard language switching.
2739 if (down && repeatCount == 0
2740 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2741 || (keyCode == KeyEvent.KEYCODE_SPACE
2742 && (metaState & KeyEvent.META_CTRL_MASK) != 0))) {
2743 int direction = (metaState & KeyEvent.META_SHIFT_MASK) != 0 ? -1 : 1;
2744 mWindowManagerFuncs.switchKeyboardLayout(event.getDeviceId(), direction);
2745 return -1;
2746 }
2747 if (mLanguageSwitchKeyPressed && !down
2748 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2749 || keyCode == KeyEvent.KEYCODE_SPACE)) {
2750 mLanguageSwitchKeyPressed = false;
2751 return -1;
2752 }
2753
Jeff Brown13f00f02014-10-31 14:45:50 -07002754 if (isValidGlobalKey(keyCode)
2755 && mGlobalKeyManager.handleGlobalKey(mContext, keyCode, event)) {
Justin Kohd378ad72013-04-01 12:18:26 -07002756 return -1;
2757 }
2758
Michael Wright6a62e552014-06-03 19:19:48 -07002759 // Reserve all the META modifier combos for system behavior
Michael Wrightce0c13a2014-07-30 10:49:21 -07002760 if ((metaState & KeyEvent.META_META_ON) != 0) {
Michael Wright6a62e552014-06-03 19:19:48 -07002761 return -1;
2762 }
2763
Jeff Brown68b909d2011-12-07 16:36:01 -08002764 // Let the application handle the key.
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002765 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002766 }
2767
Jeff Brown3915bb82010-11-05 15:02:16 -07002768 /** {@inheritDoc} */
2769 @Override
Jeff Brown49ed71d2010-12-06 17:13:33 -08002770 public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown54875002011-04-06 15:33:01 -07002771 // Note: This method is only called if the initial down was unhandled.
Jeff Brown40013652012-05-16 21:22:36 -07002772 if (DEBUG_INPUT) {
Jeff Brown1f245102010-11-18 20:53:46 -08002773 Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction()
2774 + ", flags=" + event.getFlags()
2775 + ", keyCode=" + event.getKeyCode()
2776 + ", scanCode=" + event.getScanCode()
2777 + ", metaState=" + event.getMetaState()
2778 + ", repeatCount=" + event.getRepeatCount()
2779 + ", policyFlags=" + policyFlags);
Jeff Brown3915bb82010-11-05 15:02:16 -07002780 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002781
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002782 KeyEvent fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002783 if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
2784 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002785 final int keyCode = event.getKeyCode();
2786 final int metaState = event.getMetaState();
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002787 final boolean initialDown = event.getAction() == KeyEvent.ACTION_DOWN
2788 && event.getRepeatCount() == 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002789
Jeff Brown54875002011-04-06 15:33:01 -07002790 // Check for fallback actions specified by the key character map.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002791 final FallbackAction fallbackAction;
2792 if (initialDown) {
2793 fallbackAction = kcm.getFallbackAction(keyCode, metaState);
2794 } else {
2795 fallbackAction = mFallbackActions.get(keyCode);
2796 }
2797
2798 if (fallbackAction != null) {
Jeff Brown40013652012-05-16 21:22:36 -07002799 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002800 Slog.d(TAG, "Fallback: keyCode=" + fallbackAction.keyCode
2801 + " metaState=" + Integer.toHexString(fallbackAction.metaState));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002802 }
2803
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002804 final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK;
2805 fallbackEvent = KeyEvent.obtain(
Jeff Brown49ed71d2010-12-06 17:13:33 -08002806 event.getDownTime(), event.getEventTime(),
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002807 event.getAction(), fallbackAction.keyCode,
2808 event.getRepeatCount(), fallbackAction.metaState,
Jeff Brown49ed71d2010-12-06 17:13:33 -08002809 event.getDeviceId(), event.getScanCode(),
2810 flags, event.getSource(), null);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002811
2812 if (!interceptFallback(win, fallbackEvent, policyFlags)) {
2813 fallbackEvent.recycle();
2814 fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002815 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002816
2817 if (initialDown) {
2818 mFallbackActions.put(keyCode, fallbackAction);
2819 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2820 mFallbackActions.remove(keyCode);
2821 fallbackAction.recycle();
2822 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002823 }
2824 }
2825
Jeff Brown40013652012-05-16 21:22:36 -07002826 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002827 if (fallbackEvent == null) {
2828 Slog.d(TAG, "No fallback.");
2829 } else {
2830 Slog.d(TAG, "Performing fallback: " + fallbackEvent);
2831 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002832 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002833 return fallbackEvent;
Jeff Brown3915bb82010-11-05 15:02:16 -07002834 }
2835
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002836 private boolean interceptFallback(WindowState win, KeyEvent fallbackEvent, int policyFlags) {
Jeff Brown037c33e2014-04-09 00:31:55 -07002837 int actions = interceptKeyBeforeQueueing(fallbackEvent, policyFlags);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002838 if ((actions & ACTION_PASS_TO_USER) != 0) {
2839 long delayMillis = interceptKeyBeforeDispatching(
2840 win, fallbackEvent, policyFlags);
2841 if (delayMillis == 0) {
2842 return true;
2843 }
2844 }
2845 return false;
Jeff Brown6f2fba42011-02-19 01:08:02 -08002846 }
2847
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002848 private void launchAssistLongPressAction() {
2849 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
2850 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
2851
2852 // launch the search activity
2853 Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS);
2854 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2855 try {
RoboErik8a2cfc32014-05-16 11:19:38 -07002856 // TODO: This only stops the factory-installed search manager.
Jim Miller45308b12012-06-18 19:23:39 -07002857 // Need to formalize an API to handle others
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002858 SearchManager searchManager = getSearchManager();
2859 if (searchManager != null) {
2860 searchManager.stopSearch();
2861 }
Michael Wright43e27f72013-04-10 14:06:48 -07002862 mContext.startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002863 } catch (ActivityNotFoundException e) {
2864 Slog.w(TAG, "No activity to handle assist long press action.", e);
2865 }
2866 }
2867
2868 private void launchAssistAction() {
Michael Wright8ab940a2014-09-01 11:01:27 -07002869 launchAssistAction(null);
2870 }
2871
2872 private void launchAssistAction(String hint) {
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002873 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
Amith Yamasanic1d07a42012-08-14 09:32:02 -07002874 Intent intent = ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE))
Dianne Hackbornf9c5e0f2013-01-23 14:39:13 -08002875 .getAssistIntent(mContext, true, UserHandle.USER_CURRENT);
Jim Miller45308b12012-06-18 19:23:39 -07002876 if (intent != null) {
Michael Wright8ab940a2014-09-01 11:01:27 -07002877 if (hint != null) {
2878 intent.putExtra(hint, true);
2879 }
Jim Miller45308b12012-06-18 19:23:39 -07002880 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
2881 | Intent.FLAG_ACTIVITY_SINGLE_TOP
2882 | Intent.FLAG_ACTIVITY_CLEAR_TOP);
2883 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002884 mContext.startActivityAsUser(intent, UserHandle.CURRENT);
Jim Miller45308b12012-06-18 19:23:39 -07002885 } catch (ActivityNotFoundException e) {
2886 Slog.w(TAG, "No activity to handle assist action.", e);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002887 }
2888 }
2889 }
2890
2891 private SearchManager getSearchManager() {
2892 if (mSearchManager == null) {
2893 mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
2894 }
2895 return mSearchManager;
2896 }
2897
Jeff Browncaca8812013-05-09 13:34:33 -07002898 private void preloadRecentApps() {
2899 mPreloadedRecentApps = true;
2900 try {
2901 IStatusBarService statusbar = getStatusBarService();
2902 if (statusbar != null) {
2903 statusbar.preloadRecentApps();
2904 }
2905 } catch (RemoteException e) {
2906 Slog.e(TAG, "RemoteException when preloading recent apps", e);
2907 // re-acquire status bar service next time it is needed.
2908 mStatusBarService = null;
2909 }
2910 }
2911
2912 private void cancelPreloadRecentApps() {
2913 if (mPreloadedRecentApps) {
2914 mPreloadedRecentApps = false;
2915 try {
2916 IStatusBarService statusbar = getStatusBarService();
2917 if (statusbar != null) {
2918 statusbar.cancelPreloadRecentApps();
2919 }
2920 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002921 Slog.e(TAG, "RemoteException when cancelling recent apps preload", e);
Jeff Browncaca8812013-05-09 13:34:33 -07002922 // re-acquire status bar service next time it is needed.
2923 mStatusBarService = null;
2924 }
2925 }
2926 }
2927
2928 private void toggleRecentApps() {
2929 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
Jeff Browncaca8812013-05-09 13:34:33 -07002930 try {
2931 IStatusBarService statusbar = getStatusBarService();
2932 if (statusbar != null) {
2933 statusbar.toggleRecentApps();
2934 }
2935 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002936 Slog.e(TAG, "RemoteException when toggling recent apps", e);
2937 // re-acquire status bar service next time it is needed.
2938 mStatusBarService = null;
2939 }
2940 }
2941
Craig Mautner84984fa2014-06-19 11:19:20 -07002942 @Override
2943 public void showRecentApps() {
2944 mHandler.removeMessages(MSG_DISPATCH_SHOW_RECENTS);
2945 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_RECENTS);
2946 }
2947
Winson Chung1e8d71b2014-05-16 17:05:22 -07002948 private void showRecentApps(boolean triggeredFromAltTab) {
2949 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
2950 try {
2951 IStatusBarService statusbar = getStatusBarService();
2952 if (statusbar != null) {
2953 statusbar.showRecentApps(triggeredFromAltTab);
2954 }
2955 } catch (RemoteException e) {
Jeff Browncaca8812013-05-09 13:34:33 -07002956 Slog.e(TAG, "RemoteException when showing recent apps", e);
2957 // re-acquire status bar service next time it is needed.
2958 mStatusBarService = null;
2959 }
2960 }
2961
Winson Chungcdcd4872014-08-05 18:00:13 -07002962 private void hideRecentApps(boolean triggeredFromAltTab, boolean triggeredFromHome) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002963 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
2964 try {
2965 IStatusBarService statusbar = getStatusBarService();
2966 if (statusbar != null) {
Winson Chungcdcd4872014-08-05 18:00:13 -07002967 statusbar.hideRecentApps(triggeredFromAltTab, triggeredFromHome);
Winson Chung1e8d71b2014-05-16 17:05:22 -07002968 }
2969 } catch (RemoteException e) {
2970 Slog.e(TAG, "RemoteException when closing recent apps", e);
2971 // re-acquire status bar service next time it is needed.
2972 mStatusBarService = null;
2973 }
2974 }
2975
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002976 /**
2977 * A home key -> launch home action was detected. Take the appropriate action
2978 * given the situation with the keyguard.
2979 */
2980 void launchHomeFromHotKey() {
Jim Millerab954542014-10-10 18:21:49 -07002981 if (isKeyguardShowingAndNotOccluded()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002982 // don't launch home if keyguard showing
Jim Miller5ecd8112013-01-09 18:50:26 -08002983 } else if (!mHideLockScreen && mKeyguardDelegate.isInputRestricted()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002984 // when in keyguard restricted mode, must first verify unlock
2985 // before launching home
Jim Miller5ecd8112013-01-09 18:50:26 -08002986 mKeyguardDelegate.verifyUnlock(new OnKeyguardExitResult() {
Jose Lima9546b202014-07-02 17:21:51 -07002987 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002988 public void onKeyguardExitResult(boolean success) {
2989 if (success) {
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07002990 try {
2991 ActivityManagerNative.getDefault().stopAppSwitches();
2992 } catch (RemoteException e) {
2993 }
Joe Onoratof275f0c2009-11-24 16:11:13 -05002994 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
Bryce Lee01b0c5f2015-02-05 18:24:04 -08002995 startDockOrHome(true /*fromHomeKey*/);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002996 }
2997 }
2998 });
2999 } else {
3000 // no keyguard stuff to worry about, just launch home!
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07003001 try {
3002 ActivityManagerNative.getDefault().stopAppSwitches();
3003 } catch (RemoteException e) {
3004 }
Winson Chungd543c1b2014-06-23 15:06:45 -07003005 if (mRecentsVisible) {
3006 // Hide Recents and notify it to launch Home
3007 awakenDreams();
3008 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
Winson Chungcdcd4872014-08-05 18:00:13 -07003009 hideRecentApps(false, true);
Winson Chungd543c1b2014-06-23 15:06:45 -07003010 } else {
3011 // Otherwise, just launch Home
3012 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
Bryce Lee01b0c5f2015-02-05 18:24:04 -08003013 startDockOrHome(true /*fromHomeKey*/);
Winson Chungd543c1b2014-06-23 15:06:45 -07003014 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003015 }
3016 }
3017
John Spurlock04db1762013-05-13 12:46:41 -04003018 private final Runnable mClearHideNavigationFlag = new Runnable() {
3019 @Override
3020 public void run() {
3021 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
3022 // Clear flags.
3023 mForceClearedSystemUiFlags &=
3024 ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
3025 }
3026 mWindowManagerFuncs.reevaluateStatusBarVisibility();
Dianne Hackborne26ab702011-10-16 13:21:33 -07003027 }
3028 };
3029
3030 /**
3031 * Input handler used while nav bar is hidden. Captures any touch on the screen,
3032 * to determine when the nav bar should be shown and prevent applications from
3033 * receiving those touches.
3034 */
Jeff Brown32cbc38552011-12-01 14:01:49 -08003035 final class HideNavInputEventReceiver extends InputEventReceiver {
3036 public HideNavInputEventReceiver(InputChannel inputChannel, Looper looper) {
3037 super(inputChannel, looper);
3038 }
3039
Dianne Hackborndf89e652011-10-06 22:35:11 -07003040 @Override
Jeff Brown32cbc38552011-12-01 14:01:49 -08003041 public void onInputEvent(InputEvent event) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003042 boolean handled = false;
3043 try {
Jeff Brown4952dfd2011-11-30 19:23:22 -08003044 if (event instanceof MotionEvent
3045 && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
3046 final MotionEvent motionEvent = (MotionEvent)event;
3047 if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003048 // When the user taps down, we re-show the nav bar.
3049 boolean changed = false;
John Spurlock04db1762013-05-13 12:46:41 -04003050 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003051 // Any user activity always causes us to show the
3052 // navigation controls, if they had been hidden.
3053 // We also clear the low profile and only content
3054 // flags so that tapping on the screen will atomically
3055 // restore all currently hidden screen decorations.
3056 int newVal = mResettingSystemUiFlags |
3057 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
3058 View.SYSTEM_UI_FLAG_LOW_PROFILE |
3059 View.SYSTEM_UI_FLAG_FULLSCREEN;
Dianne Hackborne26ab702011-10-16 13:21:33 -07003060 if (mResettingSystemUiFlags != newVal) {
3061 mResettingSystemUiFlags = newVal;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003062 changed = true;
3063 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003064 // We don't allow the system's nav bar to be hidden
3065 // again for 1 second, to prevent applications from
3066 // spamming us and keeping it from being shown.
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003067 newVal = mForceClearedSystemUiFlags |
3068 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
Dianne Hackborne26ab702011-10-16 13:21:33 -07003069 if (mForceClearedSystemUiFlags != newVal) {
3070 mForceClearedSystemUiFlags = newVal;
3071 changed = true;
John Spurlock04db1762013-05-13 12:46:41 -04003072 mHandler.postDelayed(mClearHideNavigationFlag, 1000);
Dianne Hackborne26ab702011-10-16 13:21:33 -07003073 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07003074 }
3075 if (changed) {
3076 mWindowManagerFuncs.reevaluateStatusBarVisibility();
3077 }
3078 }
3079 }
3080 } finally {
Jeff Brown32cbc38552011-12-01 14:01:49 -08003081 finishInputEvent(event, handled);
Dianne Hackborndf89e652011-10-06 22:35:11 -07003082 }
3083 }
Jeff Brown32cbc38552011-12-01 14:01:49 -08003084 }
3085 final InputEventReceiver.Factory mHideNavInputEventReceiverFactory =
3086 new InputEventReceiver.Factory() {
3087 @Override
3088 public InputEventReceiver createInputEventReceiver(
3089 InputChannel inputChannel, Looper looper) {
3090 return new HideNavInputEventReceiver(inputChannel, looper);
3091 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07003092 };
3093
3094 @Override
3095 public int adjustSystemUiVisibilityLw(int visibility) {
John Spurlock5b9145b2013-08-20 15:13:47 -04003096 mStatusBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
3097 mNavigationBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
Winson Chungd42a6cf2014-06-03 16:24:04 -07003098 mRecentsVisible = (visibility & View.RECENT_APPS_VISIBLE) > 0;
John Spurlock27735a42013-08-14 17:57:38 -04003099
Dianne Hackborndf89e652011-10-06 22:35:11 -07003100 // Reset any bits in mForceClearingStatusBarVisibility that
3101 // are now clear.
Dianne Hackborne26ab702011-10-16 13:21:33 -07003102 mResettingSystemUiFlags &= visibility;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003103 // Clear any bits in the new visibility that are currently being
3104 // force cleared, before reporting it.
Dianne Hackborne26ab702011-10-16 13:21:33 -07003105 return visibility & ~mResettingSystemUiFlags
3106 & ~mForceClearedSystemUiFlags;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003107 }
3108
Craig Mautner69b08182012-09-05 13:07:13 -07003109 @Override
Adrian Roos37d7a682014-11-06 18:15:16 +01003110 public void getInsetHintLw(WindowManager.LayoutParams attrs, Rect outContentInsets,
3111 Rect outStableInsets) {
John Spurlockc6d1c602014-01-17 15:22:06 -05003112 final int fl = PolicyControl.getWindowFlags(null, attrs);
John Spurlock1db8b682014-02-18 11:18:59 -05003113 final int sysuiVis = PolicyControl.getSystemUiVisibility(null, attrs);
3114 final int systemUiVisibility = (sysuiVis | attrs.subtreeSystemUiVisibility);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003115
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003116 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003117 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003118 int availRight, availBottom;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003119 if (canHideNavigationBar() &&
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003120 (systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003121 availRight = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3122 availBottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
3123 } else {
3124 availRight = mRestrictedScreenLeft + mRestrictedScreenWidth;
3125 availBottom = mRestrictedScreenTop + mRestrictedScreenHeight;
3126 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003127 if ((systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
3128 if ((fl & FLAG_FULLSCREEN) != 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003129 outContentInsets.set(mStableFullscreenLeft, mStableFullscreenTop,
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003130 availRight - mStableFullscreenRight,
3131 availBottom - mStableFullscreenBottom);
3132 } else {
Adrian Roos37d7a682014-11-06 18:15:16 +01003133 outContentInsets.set(mStableLeft, mStableTop,
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003134 availRight - mStableRight, availBottom - mStableBottom);
3135 }
Dianne Hackbornc652de82013-02-15 16:32:56 -08003136 } else if ((fl & FLAG_FULLSCREEN) != 0 || (fl & FLAG_LAYOUT_IN_OVERSCAN) != 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003137 outContentInsets.setEmpty();
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003138 } else if ((systemUiVisibility & (View.SYSTEM_UI_FLAG_FULLSCREEN
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003139 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)) == 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003140 outContentInsets.set(mCurLeft, mCurTop,
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003141 availRight - mCurRight, availBottom - mCurBottom);
3142 } else {
Adrian Roos37d7a682014-11-06 18:15:16 +01003143 outContentInsets.set(mCurLeft, mCurTop,
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003144 availRight - mCurRight, availBottom - mCurBottom);
3145 }
Adrian Roos37d7a682014-11-06 18:15:16 +01003146
3147 outStableInsets.set(mStableLeft, mStableTop,
3148 availRight - mStableRight, availBottom - mStableBottom);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003149 return;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003150 }
Adrian Roos37d7a682014-11-06 18:15:16 +01003151 outContentInsets.setEmpty();
3152 outStableInsets.setEmpty();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003153 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003154
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003155 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07003156 @Override
3157 public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight,
3158 int displayRotation) {
Dianne Hackbornc652de82013-02-15 16:32:56 -08003159 final int overscanLeft, overscanTop, overscanRight, overscanBottom;
3160 if (isDefaultDisplay) {
3161 switch (displayRotation) {
3162 case Surface.ROTATION_90:
3163 overscanLeft = mOverscanTop;
3164 overscanTop = mOverscanRight;
3165 overscanRight = mOverscanBottom;
3166 overscanBottom = mOverscanLeft;
3167 break;
3168 case Surface.ROTATION_180:
3169 overscanLeft = mOverscanRight;
3170 overscanTop = mOverscanBottom;
3171 overscanRight = mOverscanLeft;
3172 overscanBottom = mOverscanTop;
3173 break;
3174 case Surface.ROTATION_270:
3175 overscanLeft = mOverscanBottom;
3176 overscanTop = mOverscanLeft;
3177 overscanRight = mOverscanTop;
3178 overscanBottom = mOverscanRight;
3179 break;
3180 default:
3181 overscanLeft = mOverscanLeft;
3182 overscanTop = mOverscanTop;
3183 overscanRight = mOverscanRight;
3184 overscanBottom = mOverscanBottom;
3185 break;
3186 }
3187 } else {
3188 overscanLeft = 0;
3189 overscanTop = 0;
3190 overscanRight = 0;
3191 overscanBottom = 0;
3192 }
Dianne Hackborn313440842013-02-19 19:22:59 -08003193 mOverscanScreenLeft = mRestrictedOverscanScreenLeft = 0;
3194 mOverscanScreenTop = mRestrictedOverscanScreenTop = 0;
3195 mOverscanScreenWidth = mRestrictedOverscanScreenWidth = displayWidth;
3196 mOverscanScreenHeight = mRestrictedOverscanScreenHeight = displayHeight;
Dianne Hackbornc652de82013-02-15 16:32:56 -08003197 mSystemLeft = 0;
3198 mSystemTop = 0;
3199 mSystemRight = displayWidth;
3200 mSystemBottom = displayHeight;
3201 mUnrestrictedScreenLeft = overscanLeft;
3202 mUnrestrictedScreenTop = overscanTop;
3203 mUnrestrictedScreenWidth = displayWidth - overscanLeft - overscanRight;
3204 mUnrestrictedScreenHeight = displayHeight - overscanTop - overscanBottom;
3205 mRestrictedScreenLeft = mUnrestrictedScreenLeft;
3206 mRestrictedScreenTop = mUnrestrictedScreenTop;
John Spurlockad3e6cb2013-04-30 08:47:43 -04003207 mRestrictedScreenWidth = mSystemGestures.screenWidth = mUnrestrictedScreenWidth;
3208 mRestrictedScreenHeight = mSystemGestures.screenHeight = mUnrestrictedScreenHeight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003209 mDockLeft = mContentLeft = mVoiceContentLeft = mStableLeft = mStableFullscreenLeft
Dianne Hackbornc652de82013-02-15 16:32:56 -08003210 = mCurLeft = mUnrestrictedScreenLeft;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003211 mDockTop = mContentTop = mVoiceContentTop = mStableTop = mStableFullscreenTop
Dianne Hackbornc652de82013-02-15 16:32:56 -08003212 = mCurTop = mUnrestrictedScreenTop;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003213 mDockRight = mContentRight = mVoiceContentRight = mStableRight = mStableFullscreenRight
Dianne Hackbornc652de82013-02-15 16:32:56 -08003214 = mCurRight = displayWidth - overscanRight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003215 mDockBottom = mContentBottom = mVoiceContentBottom = mStableBottom = mStableFullscreenBottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003216 = mCurBottom = displayHeight - overscanBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003217 mDockLayer = 0x10000000;
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003218 mStatusBarLayer = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003219
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003220 // start with the current dock rect, which will be (0,0,displayWidth,displayHeight)
3221 final Rect pf = mTmpParentFrame;
3222 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003223 final Rect of = mTmpOverscanFrame;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003224 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04003225 final Rect dcf = mTmpDecorFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003226 pf.left = df.left = of.left = vf.left = mDockLeft;
3227 pf.top = df.top = of.top = vf.top = mDockTop;
3228 pf.right = df.right = of.right = vf.right = mDockRight;
3229 pf.bottom = df.bottom = of.bottom = vf.bottom = mDockBottom;
John Spurlock46646232013-09-30 22:32:42 -04003230 dcf.setEmpty(); // Decor frame N/A for system bars.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003231
Craig Mautner69b08182012-09-05 13:07:13 -07003232 if (isDefaultDisplay) {
3233 // For purposes of putting out fake window up to steal focus, we will
3234 // drive nav being hidden only by whether it is requested.
John Spurlocke1f366f2013-08-05 12:22:40 -04003235 final int sysui = mLastSystemUiFlags;
3236 boolean navVisible = (sysui & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0;
Adrian Roosea562512014-05-05 13:33:03 +02003237 boolean navTranslucent = (sysui
3238 & (View.NAVIGATION_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04003239 boolean immersive = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
3240 boolean immersiveSticky = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
3241 boolean navAllowedHidden = immersive || immersiveSticky;
3242 navTranslucent &= !immersiveSticky; // transient trumps translucent
Adrian Roos4fb3ee32014-08-22 19:29:09 +02003243 boolean isKeyguardShowing = isStatusBarKeyguard() && !mHideLockScreen;
3244 if (!isKeyguardShowing) {
3245 navTranslucent &= areTranslucentBarsAllowed();
3246 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003247
Craig Mautner69b08182012-09-05 13:07:13 -07003248 // When the navigation bar isn't visible, we put up a fake
3249 // input window to catch all touch events. This way we can
3250 // detect when the user presses anywhere to bring back the nav
3251 // bar and ensure the application doesn't see the event.
John Spurlockf1a36642013-10-12 17:50:42 -04003252 if (navVisible || navAllowedHidden) {
Craig Mautner69b08182012-09-05 13:07:13 -07003253 if (mHideNavFakeWindow != null) {
3254 mHideNavFakeWindow.dismiss();
3255 mHideNavFakeWindow = null;
3256 }
3257 } else if (mHideNavFakeWindow == null) {
3258 mHideNavFakeWindow = mWindowManagerFuncs.addFakeWindow(
3259 mHandler.getLooper(), mHideNavInputEventReceiverFactory,
Adam Lesinski95c42972013-10-02 10:13:27 -07003260 "hidden nav", WindowManager.LayoutParams.TYPE_HIDDEN_NAV_CONSUMER, 0,
Craig Mautner69b08182012-09-05 13:07:13 -07003261 0, false, false, true);
Dianne Hackborne26ab702011-10-16 13:21:33 -07003262 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003263
Craig Mautner69b08182012-09-05 13:07:13 -07003264 // For purposes of positioning and showing the nav bar, if we have
3265 // decided that it can't be hidden (because of the screen aspect ratio),
3266 // then take that into account.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003267 navVisible |= !canHideNavigationBar();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003268
John Spurlockad3e6cb2013-04-30 08:47:43 -04003269 boolean updateSysUiVisibility = false;
Craig Mautner69b08182012-09-05 13:07:13 -07003270 if (mNavigationBar != null) {
John Spurlock27735a42013-08-14 17:57:38 -04003271 boolean transientNavBarShowing = mNavigationBarController.isTransientShowing();
Craig Mautner69b08182012-09-05 13:07:13 -07003272 // Force the navigation bar to its appropriate place and
3273 // size. We need to do this directly, instead of relying on
3274 // it to bubble up from the nav bar, because this needs to
3275 // change atomically with screen rotations.
3276 mNavigationBarOnBottom = (!mNavigationBarCanMove || displayWidth < displayHeight);
3277 if (mNavigationBarOnBottom) {
3278 // It's a system nav bar or a portrait screen; nav bar goes on bottom.
Dianne Hackbornc652de82013-02-15 16:32:56 -08003279 int top = displayHeight - overscanBottom
3280 - mNavigationBarHeightForRotation[displayRotation];
3281 mTmpNavigationFrame.set(0, top, displayWidth, displayHeight - overscanBottom);
Craig Mautner69b08182012-09-05 13:07:13 -07003282 mStableBottom = mStableFullscreenBottom = mTmpNavigationFrame.top;
John Spurlockf95b89a2013-10-10 22:10:42 -04003283 if (transientNavBarShowing) {
John Spurlock27735a42013-08-14 17:57:38 -04003284 mNavigationBarController.setBarShowingLw(true);
John Spurlockad3e6cb2013-04-30 08:47:43 -04003285 } else if (navVisible) {
John Spurlock27735a42013-08-14 17:57:38 -04003286 mNavigationBarController.setBarShowingLw(true);
Craig Mautner69b08182012-09-05 13:07:13 -07003287 mDockBottom = mTmpNavigationFrame.top;
Dianne Hackborn313440842013-02-19 19:22:59 -08003288 mRestrictedScreenHeight = mDockBottom - mRestrictedScreenTop;
3289 mRestrictedOverscanScreenHeight = mDockBottom - mRestrictedOverscanScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07003290 } else {
3291 // We currently want to hide the navigation UI.
John Spurlock27735a42013-08-14 17:57:38 -04003292 mNavigationBarController.setBarShowingLw(false);
Craig Mautner69b08182012-09-05 13:07:13 -07003293 }
John Spurlockc6d1c602014-01-17 15:22:06 -05003294 if (navVisible && !navTranslucent && !navAllowedHidden
3295 && !mNavigationBar.isAnimatingLw()
John Spurlockbd957402013-10-03 11:38:39 -04003296 && !mNavigationBarController.wasRecentlyTranslucent()) {
John Spurlocke1f366f2013-08-05 12:22:40 -04003297 // If the opaque nav bar is currently requested to be visible,
Craig Mautner69b08182012-09-05 13:07:13 -07003298 // and not in the process of animating on or off, then
3299 // we can tell the app that it is covered by it.
3300 mSystemBottom = mTmpNavigationFrame.top;
3301 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003302 } else {
Craig Mautner69b08182012-09-05 13:07:13 -07003303 // Landscape screen; nav bar goes to the right.
Dianne Hackbornc652de82013-02-15 16:32:56 -08003304 int left = displayWidth - overscanRight
3305 - mNavigationBarWidthForRotation[displayRotation];
3306 mTmpNavigationFrame.set(left, 0, displayWidth - overscanRight, displayHeight);
Craig Mautner69b08182012-09-05 13:07:13 -07003307 mStableRight = mStableFullscreenRight = mTmpNavigationFrame.left;
John Spurlockf95b89a2013-10-10 22:10:42 -04003308 if (transientNavBarShowing) {
John Spurlock27735a42013-08-14 17:57:38 -04003309 mNavigationBarController.setBarShowingLw(true);
John Spurlockad3e6cb2013-04-30 08:47:43 -04003310 } else if (navVisible) {
John Spurlock27735a42013-08-14 17:57:38 -04003311 mNavigationBarController.setBarShowingLw(true);
Craig Mautner69b08182012-09-05 13:07:13 -07003312 mDockRight = mTmpNavigationFrame.left;
Dianne Hackborn313440842013-02-19 19:22:59 -08003313 mRestrictedScreenWidth = mDockRight - mRestrictedScreenLeft;
3314 mRestrictedOverscanScreenWidth = mDockRight - mRestrictedOverscanScreenLeft;
Craig Mautner69b08182012-09-05 13:07:13 -07003315 } else {
3316 // We currently want to hide the navigation UI.
John Spurlock27735a42013-08-14 17:57:38 -04003317 mNavigationBarController.setBarShowingLw(false);
Craig Mautner69b08182012-09-05 13:07:13 -07003318 }
John Spurlockbd957402013-10-03 11:38:39 -04003319 if (navVisible && !navTranslucent && !mNavigationBar.isAnimatingLw()
3320 && !mNavigationBarController.wasRecentlyTranslucent()) {
Craig Mautner69b08182012-09-05 13:07:13 -07003321 // If the nav bar is currently requested to be visible,
3322 // and not in the process of animating on or off, then
3323 // we can tell the app that it is covered by it.
3324 mSystemRight = mTmpNavigationFrame.left;
3325 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003326 }
Craig Mautner69b08182012-09-05 13:07:13 -07003327 // Make sure the content and current rectangles are updated to
3328 // account for the restrictions from the navigation bar.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003329 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3330 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3331 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3332 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
Craig Mautner69b08182012-09-05 13:07:13 -07003333 mStatusBarLayer = mNavigationBar.getSurfaceLayer();
3334 // And compute the final frame.
3335 mNavigationBar.computeFrameLw(mTmpNavigationFrame, mTmpNavigationFrame,
Adrian Roosfa104232014-06-20 16:10:14 -07003336 mTmpNavigationFrame, mTmpNavigationFrame, mTmpNavigationFrame, dcf,
3337 mTmpNavigationFrame);
Craig Mautnereda67292013-04-28 13:50:14 -07003338 if (DEBUG_LAYOUT) Slog.i(TAG, "mNavigationBar frame: " + mTmpNavigationFrame);
John Spurlock27735a42013-08-14 17:57:38 -04003339 if (mNavigationBarController.checkHiddenLw()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04003340 updateSysUiVisibility = true;
3341 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003342 }
Craig Mautnereda67292013-04-28 13:50:14 -07003343 if (DEBUG_LAYOUT) Slog.i(TAG, String.format("mDock rect: (%d,%d - %d,%d)",
Craig Mautner69b08182012-09-05 13:07:13 -07003344 mDockLeft, mDockTop, mDockRight, mDockBottom));
3345
3346 // decide where the status bar goes ahead of time
3347 if (mStatusBar != null) {
3348 // apply any navigation bar insets
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003349 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3350 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3351 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
3352 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight
3353 + mUnrestrictedScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07003354 vf.left = mStableLeft;
3355 vf.top = mStableTop;
3356 vf.right = mStableRight;
3357 vf.bottom = mStableBottom;
3358
3359 mStatusBarLayer = mStatusBar.getSurfaceLayer();
3360
3361 // Let the status bar determine its size.
Adrian Roosfa104232014-06-20 16:10:14 -07003362 mStatusBar.computeFrameLw(pf, df, vf, vf, vf, dcf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07003363
3364 // For layout, the status bar is always at the top with our fixed height.
3365 mStableTop = mUnrestrictedScreenTop + mStatusBarHeight;
3366
John Spurlocke1f366f2013-08-05 12:22:40 -04003367 boolean statusBarTransient = (sysui & View.STATUS_BAR_TRANSIENT) != 0;
Adrian Roosea562512014-05-05 13:33:03 +02003368 boolean statusBarTranslucent = (sysui
3369 & (View.STATUS_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0;
Adrian Roos4fb3ee32014-08-22 19:29:09 +02003370 if (!isKeyguardShowing) {
3371 statusBarTranslucent &= areTranslucentBarsAllowed();
3372 }
John Spurlock32beb2c2013-03-11 10:16:47 -04003373
Craig Mautner69b08182012-09-05 13:07:13 -07003374 // If the status bar is hidden, we don't want to cause
3375 // windows behind it to scroll.
John Spurlockeda1f692013-09-16 11:38:44 -04003376 if (mStatusBar.isVisibleLw() && !statusBarTransient) {
Craig Mautner69b08182012-09-05 13:07:13 -07003377 // Status bar may go away, so the screen area it occupies
3378 // is available to apps but just covering them when the
3379 // status bar is visible.
3380 mDockTop = mUnrestrictedScreenTop + mStatusBarHeight;
3381
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003382 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3383 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3384 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3385 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
Craig Mautner69b08182012-09-05 13:07:13 -07003386
Craig Mautnereda67292013-04-28 13:50:14 -07003387 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar: " +
Craig Mautner69b08182012-09-05 13:07:13 -07003388 String.format(
3389 "dock=[%d,%d][%d,%d] content=[%d,%d][%d,%d] cur=[%d,%d][%d,%d]",
3390 mDockLeft, mDockTop, mDockRight, mDockBottom,
3391 mContentLeft, mContentTop, mContentRight, mContentBottom,
3392 mCurLeft, mCurTop, mCurRight, mCurBottom));
3393 }
John Spurlocke1f366f2013-08-05 12:22:40 -04003394 if (mStatusBar.isVisibleLw() && !mStatusBar.isAnimatingLw()
John Spurlockbd957402013-10-03 11:38:39 -04003395 && !statusBarTransient && !statusBarTranslucent
3396 && !mStatusBarController.wasRecentlyTranslucent()) {
John Spurlocke1f366f2013-08-05 12:22:40 -04003397 // If the opaque status bar is currently requested to be visible,
Craig Mautner69b08182012-09-05 13:07:13 -07003398 // and not in the process of animating on or off, then
3399 // we can tell the app that it is covered by it.
3400 mSystemTop = mUnrestrictedScreenTop + mStatusBarHeight;
3401 }
John Spurlock27735a42013-08-14 17:57:38 -04003402 if (mStatusBarController.checkHiddenLw()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04003403 updateSysUiVisibility = true;
John Spurlock32beb2c2013-03-11 10:16:47 -04003404 }
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003405 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04003406 if (updateSysUiVisibility) {
3407 updateSystemUiVisibilityLw();
3408 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003409 }
3410 }
3411
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003412 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07003413 @Override
John Spurlock46646232013-09-30 22:32:42 -04003414 public int getSystemDecorLayerLw() {
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003415 if (mStatusBar != null) return mStatusBar.getSurfaceLayer();
3416 if (mNavigationBar != null) return mNavigationBar.getSurfaceLayer();
3417 return 0;
3418 }
3419
Craig Mautner967212c2013-04-13 21:10:58 -07003420 @Override
3421 public void getContentRectLw(Rect r) {
3422 r.set(mContentLeft, mContentTop, mContentRight, mContentBottom);
3423 }
3424
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003425 void setAttachedWindowFrames(WindowState win, int fl, int adjust, WindowState attached,
3426 boolean insetDecors, Rect pf, Rect df, Rect of, Rect cf, Rect vf) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003427 if (win.getSurfaceLayer() > mDockLayer && attached.getSurfaceLayer() < mDockLayer) {
3428 // Here's a special case: if this attached window is a panel that is
3429 // above the dock window, and the window it is attached to is below
3430 // the dock window, then the frames we computed for the window it is
3431 // attached to can not be used because the dock is effectively part
3432 // of the underlying window and the attached window is floating on top
3433 // of the whole thing. So, we ignore the attached window and explicitly
3434 // compute the frames that would be appropriate without the dock.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003435 df.left = of.left = cf.left = vf.left = mDockLeft;
3436 df.top = of.top = cf.top = vf.top = mDockTop;
3437 df.right = of.right = cf.right = vf.right = mDockRight;
3438 df.bottom = of.bottom = cf.bottom = vf.bottom = mDockBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003439 } else {
3440 // The effective display frame of the attached window depends on
3441 // whether it is taking care of insetting its content. If not,
3442 // we need to use the parent's content frame so that the entire
3443 // window is positioned within that content. Otherwise we can use
Wale Ogunwale393b1c12014-10-18 16:22:01 -07003444 // the overscan frame and let the attached window take care of
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003445 // positioning its content appropriately.
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003446 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Wale Ogunwale393b1c12014-10-18 16:22:01 -07003447 // Set the content frame of the attached window to the parent's decor frame
3448 // (same as content frame when IME isn't present) if specifically requested by
3449 // setting {@link WindowManager.LayoutParams#FLAG_LAYOUT_ATTACHED_IN_DECOR} flag.
3450 // Otherwise, use the overscan frame.
3451 cf.set((fl & FLAG_LAYOUT_ATTACHED_IN_DECOR) != 0
3452 ? attached.getContentFrameLw() : attached.getOverscanFrameLw());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003453 } else {
3454 // If the window is resizing, then we want to base the content
3455 // frame on our attached content frame to resize... however,
3456 // things can be tricky if the attached window is NOT in resize
3457 // mode, in which case its content frame will be larger.
3458 // Ungh. So to deal with that, make sure the content frame
3459 // we end up using is not covering the IM dock.
3460 cf.set(attached.getContentFrameLw());
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003461 if (attached.isVoiceInteraction()) {
3462 if (cf.left < mVoiceContentLeft) cf.left = mVoiceContentLeft;
3463 if (cf.top < mVoiceContentTop) cf.top = mVoiceContentTop;
3464 if (cf.right > mVoiceContentRight) cf.right = mVoiceContentRight;
3465 if (cf.bottom > mVoiceContentBottom) cf.bottom = mVoiceContentBottom;
3466 } else if (attached.getSurfaceLayer() < mDockLayer) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003467 if (cf.left < mContentLeft) cf.left = mContentLeft;
3468 if (cf.top < mContentTop) cf.top = mContentTop;
3469 if (cf.right > mContentRight) cf.right = mContentRight;
3470 if (cf.bottom > mContentBottom) cf.bottom = mContentBottom;
3471 }
3472 }
3473 df.set(insetDecors ? attached.getDisplayFrameLw() : cf);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003474 of.set(insetDecors ? attached.getOverscanFrameLw() : cf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003475 vf.set(attached.getVisibleFrameLw());
3476 }
3477 // The LAYOUT_IN_SCREEN flag is used to determine whether the attached
3478 // window should be positioned relative to its parent or the entire
3479 // screen.
3480 pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0
3481 ? attached.getFrameLw() : df);
3482 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003483
3484 private void applyStableConstraints(int sysui, int fl, Rect r) {
3485 if ((sysui & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
3486 // If app is requesting a stable layout, don't let the
3487 // content insets go below the stable values.
3488 if ((fl & FLAG_FULLSCREEN) != 0) {
3489 if (r.left < mStableFullscreenLeft) r.left = mStableFullscreenLeft;
3490 if (r.top < mStableFullscreenTop) r.top = mStableFullscreenTop;
3491 if (r.right > mStableFullscreenRight) r.right = mStableFullscreenRight;
3492 if (r.bottom > mStableFullscreenBottom) r.bottom = mStableFullscreenBottom;
3493 } else {
3494 if (r.left < mStableLeft) r.left = mStableLeft;
3495 if (r.top < mStableTop) r.top = mStableTop;
3496 if (r.right > mStableRight) r.right = mStableRight;
3497 if (r.bottom > mStableBottom) r.bottom = mStableBottom;
3498 }
3499 }
3500 }
3501
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003502 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07003503 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003504 public void layoutWindowLw(WindowState win, WindowState attached) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003505 // we've already done the status bar
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003506 final WindowManager.LayoutParams attrs = win.getAttrs();
3507 if ((win == mStatusBar && (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) == 0) ||
3508 win == mNavigationBar) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003509 return;
3510 }
Craig Mautner69b08182012-09-05 13:07:13 -07003511 final boolean isDefaultDisplay = win.isDefaultDisplay();
3512 final boolean needsToOffsetInputMethodTarget = isDefaultDisplay &&
satok1bc0a492012-04-25 22:47:12 +09003513 (win == mLastInputMethodTargetWindow && mLastInputMethodWindow != null);
3514 if (needsToOffsetInputMethodTarget) {
Craig Mautnereda67292013-04-28 13:50:14 -07003515 if (DEBUG_LAYOUT) Slog.i(TAG, "Offset ime target window by the last ime window state");
satok1bc0a492012-04-25 22:47:12 +09003516 offsetInputMethodWindowLw(mLastInputMethodWindow);
3517 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003518
John Spurlockc6d1c602014-01-17 15:22:06 -05003519 final int fl = PolicyControl.getWindowFlags(win, attrs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003520 final int sim = attrs.softInputMode;
John Spurlock1db8b682014-02-18 11:18:59 -05003521 final int sysUiFl = PolicyControl.getSystemUiVisibility(win, null);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003522
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003523 final Rect pf = mTmpParentFrame;
3524 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003525 final Rect of = mTmpOverscanFrame;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003526 final Rect cf = mTmpContentFrame;
3527 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04003528 final Rect dcf = mTmpDecorFrame;
Adrian Roosfa104232014-06-20 16:10:14 -07003529 final Rect sf = mTmpStableFrame;
John Spurlock46646232013-09-30 22:32:42 -04003530 dcf.setEmpty();
Craig Mautner69b08182012-09-05 13:07:13 -07003531
3532 final boolean hasNavBar = (isDefaultDisplay && mHasNavigationBar
Daniel Sandler36412a72011-08-04 09:35:13 -04003533 && mNavigationBar != null && mNavigationBar.isVisibleLw());
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003534
Craig Mautnerf683b562012-10-02 11:10:57 -07003535 final int adjust = sim & SOFT_INPUT_MASK_ADJUST;
3536
Adrian Roosfa104232014-06-20 16:10:14 -07003537 if (isDefaultDisplay) {
3538 sf.set(mStableLeft, mStableTop, mStableRight, mStableBottom);
3539 } else {
3540 sf.set(mOverscanLeft, mOverscanTop, mOverscanRight, mOverscanBottom);
3541 }
3542
Craig Mautner69b08182012-09-05 13:07:13 -07003543 if (!isDefaultDisplay) {
3544 if (attached != null) {
3545 // If this window is attached to another, our display
3546 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003547 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07003548 } else {
3549 // Give the window full screen.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003550 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3551 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3552 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08003553 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003554 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003555 = mOverscanScreenTop + mOverscanScreenHeight;
Craig Mautner69b08182012-09-05 13:07:13 -07003556 }
Dianne Hackbornae6688b2015-02-11 17:02:41 -08003557 } else if (attrs.type == TYPE_INPUT_METHOD || attrs.type == TYPE_VOICE_INTERACTION) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003558 pf.left = df.left = of.left = cf.left = vf.left = mDockLeft;
3559 pf.top = df.top = of.top = cf.top = vf.top = mDockTop;
3560 pf.right = df.right = of.right = cf.right = vf.right = mDockRight;
John Spurlockc68d5772013-10-08 11:47:58 -04003561 // IM dock windows layout below the nav bar...
John Spurlock57beb3b2013-10-10 10:27:44 -04003562 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlockc68d5772013-10-08 11:47:58 -04003563 // ...with content insets above the nav bar
3564 cf.bottom = vf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003565 // IM dock windows always go to the bottom of the screen.
3566 attrs.gravity = Gravity.BOTTOM;
3567 mDockLayer = win.getSurfaceLayer();
Jorim Jaggie0700182014-08-21 01:12:37 +02003568 } else if (win == mStatusBar && (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
3569 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3570 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3571 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
3572 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight + mUnrestrictedScreenTop;
3573 cf.left = vf.left = mStableLeft;
3574 cf.top = vf.top = mStableTop;
3575 cf.right = vf.right = mStableRight;
3576 vf.bottom = mStableBottom;
3577 cf.bottom = mContentBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003578 } else {
John Spurlock46646232013-09-30 22:32:42 -04003579
3580 // Default policy decor for the default display
3581 dcf.left = mSystemLeft;
3582 dcf.top = mSystemTop;
3583 dcf.right = mSystemRight;
3584 dcf.bottom = mSystemBottom;
John Spurlockbd957402013-10-03 11:38:39 -04003585 final boolean inheritTranslucentDecor = (attrs.privateFlags
3586 & WindowManager.LayoutParams.PRIVATE_FLAG_INHERIT_TRANSLUCENT_DECOR) != 0;
John Spurlock65567d42013-10-08 10:08:32 -04003587 final boolean isAppWindow =
3588 attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW &&
3589 attrs.type <= WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
3590 final boolean topAtRest =
3591 win == mTopFullscreenOpaqueWindowState && !win.isAnimatingLw();
3592 if (isAppWindow && !inheritTranslucentDecor && !topAtRest) {
John Spurlockbd957402013-10-03 11:38:39 -04003593 if ((sysUiFl & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0
3594 && (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0
Adrian Roosea562512014-05-05 13:33:03 +02003595 && (fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) == 0
3596 && (fl & WindowManager.LayoutParams.
3597 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04003598 // Ensure policy decor includes status bar
3599 dcf.top = mStableTop;
3600 }
John Spurlockbd957402013-10-03 11:38:39 -04003601 if ((fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) == 0
Adrian Roosea562512014-05-05 13:33:03 +02003602 && (sysUiFl & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0
3603 && (fl & WindowManager.LayoutParams.
3604 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04003605 // Ensure policy decor includes navigation bar
3606 dcf.bottom = mStableBottom;
3607 dcf.right = mStableRight;
3608 }
3609 }
3610
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003611 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
3612 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
RoboErik8a2cfc32014-05-16 11:19:38 -07003613 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003614 + "): IN_SCREEN, INSET_DECOR");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003615 // This is the case for a normal activity window: we want it
3616 // to cover all of the screen space, and it can take care of
3617 // moving its contents to account for screen decorations that
3618 // intrude into that space.
3619 if (attached != null) {
3620 // If this window is attached to another, our display
3621 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003622 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003623 } else {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003624 if (attrs.type == TYPE_STATUS_BAR_PANEL
3625 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Joe Onorato29fc2c92010-11-24 10:26:50 -08003626 // Status bar panels are the only windows who can go on top of
3627 // the status bar. They are protected by the STATUS_BAR_SERVICE
3628 // permission, so they have the same privileges as the status
3629 // bar itself.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003630 //
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003631 // However, they should still dodge the navigation bar if it exists.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003632
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003633 pf.left = df.left = of.left = hasNavBar
3634 ? mDockLeft : mUnrestrictedScreenLeft;
3635 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3636 pf.right = df.right = of.right = hasNavBar
3637 ? mRestrictedScreenLeft+mRestrictedScreenWidth
3638 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3639 pf.bottom = df.bottom = of.bottom = hasNavBar
3640 ? mRestrictedScreenTop+mRestrictedScreenHeight
3641 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003642
Craig Mautnereda67292013-04-28 13:50:14 -07003643 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003644 "Laying out status bar window: (%d,%d - %d,%d)",
3645 pf.left, pf.top, pf.right, pf.bottom));
John Spurlock46646232013-09-30 22:32:42 -04003646 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08003647 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3648 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3649 // Asking to layout into the overscan region, so give it that pure
3650 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003651 pf.left = df.left = of.left = mOverscanScreenLeft;
3652 pf.top = df.top = of.top = mOverscanScreenTop;
3653 pf.right = df.right = of.right = mOverscanScreenLeft + mOverscanScreenWidth;
3654 pf.bottom = df.bottom = of.bottom = mOverscanScreenTop
3655 + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003656 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003657 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003658 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3659 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003660 // Asking for layout as if the nav bar is hidden, lets the
Dianne Hackbornc652de82013-02-15 16:32:56 -08003661 // application extend into the unrestricted overscan screen area. We
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003662 // only do this for application windows to ensure no window that
3663 // can be above the nav bar can do this.
Dianne Hackborn313440842013-02-19 19:22:59 -08003664 pf.left = df.left = mOverscanScreenLeft;
3665 pf.top = df.top = mOverscanScreenTop;
3666 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
3667 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003668 // We need to tell the app about where the frame inside the overscan
3669 // is, so it can inset its content by that amount -- it didn't ask
3670 // to actually extend itself into the overscan region.
3671 of.left = mUnrestrictedScreenLeft;
3672 of.top = mUnrestrictedScreenTop;
3673 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3674 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003675 } else {
Dianne Hackborn313440842013-02-19 19:22:59 -08003676 pf.left = df.left = mRestrictedOverscanScreenLeft;
3677 pf.top = df.top = mRestrictedOverscanScreenTop;
3678 pf.right = df.right = mRestrictedOverscanScreenLeft
3679 + mRestrictedOverscanScreenWidth;
3680 pf.bottom = df.bottom = mRestrictedOverscanScreenTop
3681 + mRestrictedOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003682 // We need to tell the app about where the frame inside the overscan
3683 // is, so it can inset its content by that amount -- it didn't ask
3684 // to actually extend itself into the overscan region.
3685 of.left = mUnrestrictedScreenLeft;
3686 of.top = mUnrestrictedScreenTop;
3687 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3688 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003689 }
Craig Mautner69b08182012-09-05 13:07:13 -07003690
John Spurlock46646232013-09-30 22:32:42 -04003691 if ((fl & FLAG_FULLSCREEN) == 0) {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003692 if (win.isVoiceInteraction()) {
3693 cf.left = mVoiceContentLeft;
3694 cf.top = mVoiceContentTop;
3695 cf.right = mVoiceContentRight;
3696 cf.bottom = mVoiceContentBottom;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003697 } else {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003698 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
3699 cf.left = mDockLeft;
3700 cf.top = mDockTop;
3701 cf.right = mDockRight;
3702 cf.bottom = mDockBottom;
3703 } else {
3704 cf.left = mContentLeft;
3705 cf.top = mContentTop;
3706 cf.right = mContentRight;
3707 cf.bottom = mContentBottom;
3708 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003709 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003710 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003711 // Full screen windows are always given a layout that is as if the
3712 // status bar and other transient decors are gone. This is to avoid
3713 // bad states when moving from a window that is not hding the
3714 // status bar to one that is.
3715 cf.left = mRestrictedScreenLeft;
3716 cf.top = mRestrictedScreenTop;
3717 cf.right = mRestrictedScreenLeft + mRestrictedScreenWidth;
3718 cf.bottom = mRestrictedScreenTop + mRestrictedScreenHeight;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003719 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003720 applyStableConstraints(sysUiFl, fl, cf);
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003721 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3722 vf.left = mCurLeft;
3723 vf.top = mCurTop;
3724 vf.right = mCurRight;
3725 vf.bottom = mCurBottom;
3726 } else {
3727 vf.set(cf);
3728 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003729 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003730 } else if ((fl & FLAG_LAYOUT_IN_SCREEN) != 0 || (sysUiFl
3731 & (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
3732 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)) != 0) {
Craig Mautnereda67292013-04-28 13:50:14 -07003733 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3734 "): IN_SCREEN");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003735 // A window that has requested to fill the entire screen just
3736 // gets everything, period.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003737 if (attrs.type == TYPE_STATUS_BAR_PANEL
3738 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003739 pf.left = df.left = of.left = cf.left = hasNavBar
3740 ? mDockLeft : mUnrestrictedScreenLeft;
3741 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
3742 pf.right = df.right = of.right = cf.right = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003743 ? mRestrictedScreenLeft+mRestrictedScreenWidth
Dianne Hackbornc652de82013-02-15 16:32:56 -08003744 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003745 pf.bottom = df.bottom = of.bottom = cf.bottom = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003746 ? mRestrictedScreenTop+mRestrictedScreenHeight
Dianne Hackbornc652de82013-02-15 16:32:56 -08003747 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07003748 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler36412a72011-08-04 09:35:13 -04003749 "Laying out IN_SCREEN status bar window: (%d,%d - %d,%d)",
3750 pf.left, pf.top, pf.right, pf.bottom));
Jim Millere898ac52012-04-06 17:10:57 -07003751 } else if (attrs.type == TYPE_NAVIGATION_BAR
3752 || attrs.type == TYPE_NAVIGATION_BAR_PANEL) {
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003753 // The navigation bar has Real Ultimate Power.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003754 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3755 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3756 pf.right = df.right = of.right = mUnrestrictedScreenLeft
3757 + mUnrestrictedScreenWidth;
3758 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop
3759 + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07003760 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003761 "Laying out navigation bar window: (%d,%d - %d,%d)",
3762 pf.left, pf.top, pf.right, pf.bottom));
Dianne Hackborn01011c32012-02-21 13:54:21 -08003763 } else if ((attrs.type == TYPE_SECURE_SYSTEM_OVERLAY
3764 || attrs.type == TYPE_BOOT_PROGRESS)
Jeff Brownbfcb60a2011-09-08 18:51:14 -07003765 && ((fl & FLAG_FULLSCREEN) != 0)) {
3766 // Fullscreen secure system overlays get what they ask for.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003767 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3768 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3769 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
3770 + mOverscanScreenWidth;
3771 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
3772 + mOverscanScreenHeight;
Craig Mautner165be0c2015-01-27 15:16:58 -08003773 } else if (attrs.type == TYPE_BOOT_PROGRESS) {
Dianne Hackborn01011c32012-02-21 13:54:21 -08003774 // Boot progress screen always covers entire display.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003775 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3776 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3777 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
3778 + mOverscanScreenWidth;
3779 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
3780 + mOverscanScreenHeight;
John Spurlockef4adae2013-08-26 17:58:58 -04003781 } else if (attrs.type == TYPE_WALLPAPER) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07003782 // The wallpaper also has Real Ultimate Power, but we want to tell
3783 // it about the overscan area.
3784 pf.left = df.left = mOverscanScreenLeft;
3785 pf.top = df.top = mOverscanScreenTop;
3786 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
3787 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
3788 of.left = cf.left = mUnrestrictedScreenLeft;
3789 of.top = cf.top = mUnrestrictedScreenTop;
3790 of.right = cf.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3791 of.bottom = cf.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlock46646232013-09-30 22:32:42 -04003792 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08003793 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3794 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3795 // Asking to layout into the overscan region, so give it that pure
3796 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003797 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3798 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3799 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08003800 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003801 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003802 = mOverscanScreenTop + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003803 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003804 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Craig Mautnerbeac1062014-06-03 14:38:57 -07003805 && (attrs.type == TYPE_STATUS_BAR
3806 || attrs.type == TYPE_TOAST
John Spurlock34e13d92013-08-10 06:52:28 -04003807 || (attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3808 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW))) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003809 // Asking for layout as if the nav bar is hidden, lets the
3810 // application extend into the unrestricted screen area. We
John Spurlock34e13d92013-08-10 06:52:28 -04003811 // only do this for application windows (or toasts) to ensure no window that
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003812 // can be above the nav bar can do this.
3813 // XXX This assumes that an app asking for this will also
3814 // ask for layout in only content. We can't currently figure out
3815 // what the screen would be if only laying out to hide the nav bar.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003816 pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft;
3817 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
3818 pf.right = df.right = of.right = cf.right = mUnrestrictedScreenLeft
3819 + mUnrestrictedScreenWidth;
3820 pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop
3821 + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003822 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003823 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
3824 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
3825 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
3826 + mRestrictedScreenWidth;
3827 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
3828 + mRestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003829 }
Craig Mautner69b08182012-09-05 13:07:13 -07003830
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003831 applyStableConstraints(sysUiFl, fl, cf);
Craig Mautner69b08182012-09-05 13:07:13 -07003832
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003833 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3834 vf.left = mCurLeft;
3835 vf.top = mCurTop;
3836 vf.right = mCurRight;
3837 vf.bottom = mCurBottom;
3838 } else {
3839 vf.set(cf);
3840 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003841 } else if (attached != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07003842 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3843 "): attached to " + attached);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003844 // A child window should be placed inside of the same visible
3845 // frame that its parent had.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003846 setAttachedWindowFrames(win, fl, adjust, attached, false, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003847 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07003848 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3849 "): normal window");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003850 // Otherwise, a normal window must be placed inside the content
3851 // of all screen decorations.
Dianne Hackborna239c842011-06-01 12:28:20 -07003852 if (attrs.type == TYPE_STATUS_BAR_PANEL) {
3853 // Status bar panels are the only windows who can go on top of
3854 // the status bar. They are protected by the STATUS_BAR_SERVICE
3855 // permission, so they have the same privileges as the status
3856 // bar itself.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003857 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
3858 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
3859 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
3860 + mRestrictedScreenWidth;
3861 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
3862 + mRestrictedScreenHeight;
John Spurlock414c1f02013-12-04 13:47:36 -05003863 } else if (attrs.type == TYPE_TOAST || attrs.type == TYPE_SYSTEM_ALERT
3864 || attrs.type == TYPE_VOLUME_OVERLAY) {
3865 // These dialogs are stable to interim decor changes.
John Spurlockbd957402013-10-03 11:38:39 -04003866 pf.left = df.left = of.left = cf.left = mStableLeft;
3867 pf.top = df.top = of.top = cf.top = mStableTop;
3868 pf.right = df.right = of.right = cf.right = mStableRight;
3869 pf.bottom = df.bottom = of.bottom = cf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003870 } else {
Dianne Hackborna239c842011-06-01 12:28:20 -07003871 pf.left = mContentLeft;
3872 pf.top = mContentTop;
3873 pf.right = mContentRight;
3874 pf.bottom = mContentBottom;
Dianne Hackborn20d94742014-05-29 18:35:45 -07003875 if (win.isVoiceInteraction()) {
3876 df.left = of.left = cf.left = mVoiceContentLeft;
3877 df.top = of.top = cf.top = mVoiceContentTop;
3878 df.right = of.right = cf.right = mVoiceContentRight;
3879 df.bottom = of.bottom = cf.bottom = mVoiceContentBottom;
3880 } else if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003881 df.left = of.left = cf.left = mDockLeft;
3882 df.top = of.top = cf.top = mDockTop;
3883 df.right = of.right = cf.right = mDockRight;
3884 df.bottom = of.bottom = cf.bottom = mDockBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07003885 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003886 df.left = of.left = cf.left = mContentLeft;
3887 df.top = of.top = cf.top = mContentTop;
3888 df.right = of.right = cf.right = mContentRight;
3889 df.bottom = of.bottom = cf.bottom = mContentBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07003890 }
3891 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3892 vf.left = mCurLeft;
3893 vf.top = mCurTop;
3894 vf.right = mCurRight;
3895 vf.bottom = mCurBottom;
3896 } else {
3897 vf.set(cf);
3898 }
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003899 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003900 }
3901 }
Craig Mautner69b08182012-09-05 13:07:13 -07003902
Craig Mautnerb816bed2013-07-23 10:26:17 -07003903 // TYPE_SYSTEM_ERROR is above the NavigationBar so it can't be allowed to extend over it.
3904 if ((fl & FLAG_LAYOUT_NO_LIMITS) != 0 && attrs.type != TYPE_SYSTEM_ERROR) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07003905 df.left = df.top = -10000;
3906 df.right = df.bottom = 10000;
3907 if (attrs.type != TYPE_WALLPAPER) {
3908 of.left = of.top = cf.left = cf.top = vf.left = vf.top = -10000;
3909 of.right = of.bottom = cf.right = cf.bottom = vf.right = vf.bottom = 10000;
3910 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003911 }
3912
Craig Mautnereda67292013-04-28 13:50:14 -07003913 if (DEBUG_LAYOUT) Slog.v(TAG, "Compute frame " + attrs.getTitle()
The Android Open Source Project11267662009-03-18 17:39:47 -07003914 + ": sim=#" + Integer.toHexString(sim)
RoboErik8a2cfc32014-05-16 11:19:38 -07003915 + " attach=" + attached + " type=" + attrs.type
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003916 + String.format(" flags=0x%08x", fl)
The Android Open Source Project11267662009-03-18 17:39:47 -07003917 + " pf=" + pf.toShortString() + " df=" + df.toShortString()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003918 + " of=" + of.toShortString()
John Spurlock46646232013-09-30 22:32:42 -04003919 + " cf=" + cf.toShortString() + " vf=" + vf.toShortString()
Adrian Roosfa104232014-06-20 16:10:14 -07003920 + " dcf=" + dcf.toShortString()
3921 + " sf=" + sf.toShortString());
Craig Mautner69b08182012-09-05 13:07:13 -07003922
Adrian Roosfa104232014-06-20 16:10:14 -07003923 win.computeFrameLw(pf, df, of, cf, vf, dcf, sf);
Craig Mautner69b08182012-09-05 13:07:13 -07003924
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003925 // Dock windows carve out the bottom of the screen, so normal windows
3926 // can't appear underneath them.
Craig Mautner8bd206b2012-10-03 10:32:02 -07003927 if (attrs.type == TYPE_INPUT_METHOD && win.isVisibleOrBehindKeyguardLw()
3928 && !win.getGivenInsetsPendingLw()) {
satok1bc0a492012-04-25 22:47:12 +09003929 setLastInputMethodWindowLw(null, null);
3930 offsetInputMethodWindowLw(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003931 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003932 if (attrs.type == TYPE_VOICE_INTERACTION && win.isVisibleOrBehindKeyguardLw()
3933 && !win.getGivenInsetsPendingLw()) {
3934 offsetVoiceInputWindowLw(win);
3935 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003936 }
3937
satok1bc0a492012-04-25 22:47:12 +09003938 private void offsetInputMethodWindowLw(WindowState win) {
Dianne Hackbornae6688b2015-02-11 17:02:41 -08003939 int top = win.getDisplayFrameLw().top;
satok1bc0a492012-04-25 22:47:12 +09003940 top += win.getGivenContentInsetsLw().top;
3941 if (mContentBottom > top) {
3942 mContentBottom = top;
3943 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003944 if (mVoiceContentBottom > top) {
3945 mVoiceContentBottom = top;
3946 }
satok1bc0a492012-04-25 22:47:12 +09003947 top = win.getVisibleFrameLw().top;
3948 top += win.getGivenVisibleInsetsLw().top;
3949 if (mCurBottom > top) {
3950 mCurBottom = top;
3951 }
Craig Mautnereda67292013-04-28 13:50:14 -07003952 if (DEBUG_LAYOUT) Slog.v(TAG, "Input method: mDockBottom="
satok1bc0a492012-04-25 22:47:12 +09003953 + mDockBottom + " mContentBottom="
3954 + mContentBottom + " mCurBottom=" + mCurBottom);
3955 }
3956
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003957 private void offsetVoiceInputWindowLw(WindowState win) {
Dianne Hackbornae6688b2015-02-11 17:02:41 -08003958 int top = win.getDisplayFrameLw().top;
3959 top += win.getGivenContentInsetsLw().top;
3960 if (mVoiceContentBottom > top) {
3961 mVoiceContentBottom = top;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003962 }
3963 }
3964
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003965 /** {@inheritDoc} */
Craig Mautner61ac6bb2012-02-02 17:29:33 -08003966 @Override
3967 public void finishLayoutLw() {
3968 return;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003969 }
3970
3971 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003972 @Override
Craig Mautner39834192012-09-02 07:47:24 -07003973 public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) {
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003974 mTopFullscreenOpaqueWindowState = null;
Craig Mautner2bc789b2014-03-19 19:48:38 -07003975 mAppsToBeHidden.clear();
Jorim Jaggic13fcac2014-09-11 17:36:57 +02003976 mAppsThatDismissKeyguard.clear();
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003977 mForceStatusBar = false;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003978 mForceStatusBarFromKeyguard = false;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08003979 mForcingShowNavBar = false;
3980 mForcingShowNavBarLayer = -1;
RoboErik8a2cfc32014-05-16 11:19:38 -07003981
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003982 mHideLockScreen = false;
3983 mAllowLockscreenWhenOn = false;
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003984 mDismissKeyguard = DISMISS_KEYGUARD_NONE;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003985 mShowingLockscreen = false;
3986 mShowingDream = false;
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003987 mWinShowWhenLocked = null;
Jim Millerab954542014-10-10 18:21:49 -07003988 mKeyguardSecure = isKeyguardSecure();
3989 mKeyguardSecureIncludingHidden = mKeyguardSecure
3990 && (mKeyguardDelegate != null && mKeyguardDelegate.isShowing());
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003991 }
3992
3993 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003994 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003995 public void applyPostLayoutPolicyLw(WindowState win, WindowManager.LayoutParams attrs) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07003996 if (DEBUG_LAYOUT) Slog.i(TAG, "Win " + win + ": isVisibleOrBehindKeyguardLw="
3997 + win.isVisibleOrBehindKeyguardLw());
John Spurlockc6d1c602014-01-17 15:22:06 -05003998 final int fl = PolicyControl.getWindowFlags(win, attrs);
John Spurlock414c1f02013-12-04 13:47:36 -05003999 if (mTopFullscreenOpaqueWindowState == null
4000 && win.isVisibleLw() && attrs.type == TYPE_INPUT_METHOD) {
4001 mForcingShowNavBar = true;
4002 mForcingShowNavBarLayer = win.getSurfaceLayer();
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08004003 }
Jorim Jaggiafd4a552014-04-08 15:13:05 +02004004 if (attrs.type == TYPE_STATUS_BAR && (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Jorim Jaggiafd4a552014-04-08 15:13:05 +02004005 mForceStatusBarFromKeyguard = true;
4006 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004007 if (mTopFullscreenOpaqueWindowState == null &&
Dianne Hackborn01b02a72012-01-12 14:05:03 -08004008 win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()) {
John Spurlockc6d1c602014-01-17 15:22:06 -05004009 if ((fl & FLAG_FORCE_NOT_FULLSCREEN) != 0) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004010 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004011 mForceStatusBarFromKeyguard = true;
4012 } else {
4013 mForceStatusBar = true;
4014 }
4015 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004016 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004017 mShowingLockscreen = true;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004018 }
Craig Mautnerab55e522014-03-03 13:26:03 -08004019 boolean appWindow = attrs.type >= FIRST_APPLICATION_WINDOW
Craig Mautner7d7808f2014-09-11 18:02:38 -07004020 && attrs.type < FIRST_SYSTEM_WINDOW;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004021 if (attrs.type == TYPE_DREAM) {
Jeff Brownc8018eb2012-10-29 21:33:27 -07004022 // If the lockscreen was showing when the dream started then wait
4023 // for the dream to draw before hiding the lockscreen.
4024 if (!mDreamingLockscreen
4025 || (win.isVisibleLw() && win.hasDrawnLw())) {
4026 mShowingDream = true;
Craig Mautnerab55e522014-03-03 13:26:03 -08004027 appWindow = true;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004028 }
4029 }
Craig Mautnerab55e522014-03-03 13:26:03 -08004030
Craig Mautner00156ec2014-03-06 22:29:02 -08004031 final boolean showWhenLocked = (fl & FLAG_SHOW_WHEN_LOCKED) != 0;
Craig Mautner74ee9382014-04-01 15:20:16 -07004032 final boolean dismissKeyguard = (fl & FLAG_DISMISS_KEYGUARD) != 0;
Craig Mautnerab55e522014-03-03 13:26:03 -08004033 if (appWindow) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004034 final IApplicationToken appToken = win.getAppToken();
4035 if (showWhenLocked) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004036 // Remove any previous windows with the same appToken.
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004037 mAppsToBeHidden.remove(appToken);
4038 mAppsThatDismissKeyguard.remove(appToken);
Craig Mautnerca0a1242014-12-02 12:25:14 -08004039 if (mAppsToBeHidden.isEmpty()) {
Craig Mautner192d6042014-12-02 23:24:48 -08004040 if (dismissKeyguard && !mKeyguardSecure) {
4041 mAppsThatDismissKeyguard.add(appToken);
4042 } else {
Craig Mautnerca0a1242014-12-02 12:25:14 -08004043 mWinShowWhenLocked = win;
4044 mHideLockScreen = true;
4045 mForceStatusBarFromKeyguard = false;
Craig Mautnerca0a1242014-12-02 12:25:14 -08004046 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004047 }
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004048 } else if (dismissKeyguard) {
Jim Millerab954542014-10-10 18:21:49 -07004049 if (mKeyguardSecure) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004050 mAppsToBeHidden.add(appToken);
4051 } else {
4052 mAppsToBeHidden.remove(appToken);
4053 }
4054 mAppsThatDismissKeyguard.add(appToken);
Craig Mautner2bc789b2014-03-19 19:48:38 -07004055 } else {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004056 mAppsToBeHidden.add(appToken);
Craig Mautner2bc789b2014-03-19 19:48:38 -07004057 }
Craig Mautnerab55e522014-03-03 13:26:03 -08004058 if (attrs.x == 0 && attrs.y == 0
4059 && attrs.width == WindowManager.LayoutParams.MATCH_PARENT
4060 && attrs.height == WindowManager.LayoutParams.MATCH_PARENT) {
4061 if (DEBUG_LAYOUT) Slog.v(TAG, "Fullscreen window: " + win);
4062 mTopFullscreenOpaqueWindowState = win;
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004063 if (!mAppsThatDismissKeyguard.isEmpty() &&
4064 mDismissKeyguard == DISMISS_KEYGUARD_NONE) {
4065 if (DEBUG_LAYOUT) Slog.v(TAG,
4066 "Setting mDismissKeyguard true by win " + win);
4067 mDismissKeyguard = mWinDismissingKeyguard == win ?
4068 DISMISS_KEYGUARD_CONTINUE : DISMISS_KEYGUARD_START;
4069 mWinDismissingKeyguard = win;
Jim Millerab954542014-10-10 18:21:49 -07004070 mForceStatusBarFromKeyguard = mShowingLockscreen && mKeyguardSecure;
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004071 } else if (mAppsToBeHidden.isEmpty() && showWhenLocked) {
4072 if (DEBUG_LAYOUT) Slog.v(TAG,
4073 "Setting mHideLockScreen to true by win " + win);
4074 mHideLockScreen = true;
4075 mForceStatusBarFromKeyguard = false;
Craig Mautnerab55e522014-03-03 13:26:03 -08004076 }
Craig Mautner00156ec2014-03-06 22:29:02 -08004077 if ((fl & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) {
Craig Mautnerab55e522014-03-03 13:26:03 -08004078 mAllowLockscreenWhenOn = true;
4079 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004080 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004081
4082 if (mWinShowWhenLocked != null &&
4083 mWinShowWhenLocked.getAppToken() != win.getAppToken()) {
4084 win.hideLw(false);
4085 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004086 }
4087 }
4088 }
4089
4090 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004091 @Override
Craig Mautner39834192012-09-02 07:47:24 -07004092 public int finishPostLayoutPolicyLw() {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004093 if (mWinShowWhenLocked != null &&
4094 mWinShowWhenLocked != mTopFullscreenOpaqueWindowState) {
4095 // A dialog is dismissing the keyguard. Put the wallpaper behind it and hide the
4096 // fullscreen window.
4097 // TODO: Make sure FLAG_SHOW_WALLPAPER is restored when dialog is dismissed. Or not.
4098 mWinShowWhenLocked.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
4099 mTopFullscreenOpaqueWindowState.hideLw(false);
4100 mTopFullscreenOpaqueWindowState = mWinShowWhenLocked;
4101 }
4102
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004103 int changes = 0;
Joe Onorato93056472010-09-10 10:30:46 -04004104 boolean topIsFullscreen = false;
Daniel Sandlere02d8082010-10-08 15:13:22 -04004105
4106 final WindowManager.LayoutParams lp = (mTopFullscreenOpaqueWindowState != null)
4107 ? mTopFullscreenOpaqueWindowState.getAttrs()
4108 : null;
4109
Jeff Brownc8018eb2012-10-29 21:33:27 -07004110 // If we are not currently showing a dream then remember the current
4111 // lockscreen state. We will use this to determine whether the dream
4112 // started while the lockscreen was showing and remember this state
4113 // while the dream is showing.
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004114 if (!mShowingDream) {
4115 mDreamingLockscreen = mShowingLockscreen;
4116 }
4117
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004118 if (mStatusBar != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07004119 if (DEBUG_LAYOUT) Slog.i(TAG, "force=" + mForceStatusBar
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004120 + " forcefkg=" + mForceStatusBarFromKeyguard
Dianne Hackbornd70bc2f2009-10-06 23:25:51 -07004121 + " top=" + mTopFullscreenOpaqueWindowState);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004122 if (mForceStatusBar || mForceStatusBarFromKeyguard) {
Craig Mautnereda67292013-04-28 13:50:14 -07004123 if (DEBUG_LAYOUT) Slog.v(TAG, "Showing status bar: forced");
John Spurlock27735a42013-08-14 17:57:38 -04004124 if (mStatusBarController.setBarShowingLw(true)) {
4125 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4126 }
Craig Mautner81defc72013-10-29 11:10:42 -07004127 // Maintain fullscreen layout until incoming animation is complete.
4128 topIsFullscreen = mTopIsFullscreen && mStatusBar.isAnimatingLw();
John Spurlockf92b6162013-11-11 15:01:16 -05004129 // Transient status bar on the lockscreen is not allowed
4130 if (mForceStatusBarFromKeyguard && mStatusBarController.isTransientShowing()) {
4131 mStatusBarController.updateVisibilityLw(false /*transientAllowed*/,
4132 mLastSystemUiFlags, mLastSystemUiFlags);
4133 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004134 } else if (mTopFullscreenOpaqueWindowState != null) {
John Spurlockc6d1c602014-01-17 15:22:06 -05004135 final int fl = PolicyControl.getWindowFlags(null, lp);
Joe Onorato93056472010-09-10 10:30:46 -04004136 if (localLOGV) {
Craig Mautnereda67292013-04-28 13:50:14 -07004137 Slog.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw()
Joe Onorato93056472010-09-10 10:30:46 -04004138 + " shown frame: " + mTopFullscreenOpaqueWindowState.getShownFrameLw());
Craig Mautnereda67292013-04-28 13:50:14 -07004139 Slog.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs()
John Spurlockc6d1c602014-01-17 15:22:06 -05004140 + " lp.flags=0x" + Integer.toHexString(fl));
Joe Onorato93056472010-09-10 10:30:46 -04004141 }
John Spurlockc6d1c602014-01-17 15:22:06 -05004142 topIsFullscreen = (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004143 || (mLastSystemUiFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
Joe Onorato93056472010-09-10 10:30:46 -04004144 // The subtle difference between the window for mTopFullscreenOpaqueWindowState
Mark Dolinerd0646dc2014-08-27 16:04:02 -07004145 // and mTopIsFullscreen is that mTopIsFullscreen is set only if the window
Joe Onorato93056472010-09-10 10:30:46 -04004146 // has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the
4147 // case though.
John Spurlock27735a42013-08-14 17:57:38 -04004148 if (mStatusBarController.isTransientShowing()) {
4149 if (mStatusBarController.setBarShowingLw(true)) {
John Spurlock32beb2c2013-03-11 10:16:47 -04004150 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4151 }
4152 } else if (topIsFullscreen) {
Craig Mautnereda67292013-04-28 13:50:14 -07004153 if (DEBUG_LAYOUT) Slog.v(TAG, "** HIDING status bar");
John Spurlock27735a42013-08-14 17:57:38 -04004154 if (mStatusBarController.setBarShowingLw(false)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004155 changes |= FINISH_LAYOUT_REDO_LAYOUT;
Craig Mautnereda67292013-04-28 13:50:14 -07004156 } else {
Craig Mautnerc5a6e442013-06-05 17:22:35 -07004157 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar already hiding");
Daniel Sandler40427442010-07-16 11:44:52 -04004158 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004159 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07004160 if (DEBUG_LAYOUT) Slog.v(TAG, "** SHOWING status bar: top is not fullscreen");
John Spurlock27735a42013-08-14 17:57:38 -04004161 if (mStatusBarController.setBarShowingLw(true)) {
4162 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4163 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004164 }
4165 }
4166 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04004167
Craig Mautner81defc72013-10-29 11:10:42 -07004168 if (mTopIsFullscreen != topIsFullscreen) {
4169 if (!topIsFullscreen) {
4170 // Force another layout when status bar becomes fully shown.
4171 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4172 }
4173 mTopIsFullscreen = topIsFullscreen;
4174 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04004175
Craig Mautner39834192012-09-02 07:47:24 -07004176 // Hide the key guard if a visible window explicitly specifies that it wants to be
4177 // displayed when the screen is locked.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004178 if (mKeyguardDelegate != null && mStatusBar != null) {
4179 if (localLOGV) Slog.v(TAG, "finishPostLayoutPolicyLw: mHideKeyguard="
4180 + mHideLockScreen);
Jim Millerab954542014-10-10 18:21:49 -07004181 if (mDismissKeyguard != DISMISS_KEYGUARD_NONE && !mKeyguardSecure) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004182 mKeyguardHidden = true;
Jim Millerab954542014-10-10 18:21:49 -07004183 if (setKeyguardOccludedLw(true)) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004184 changes |= FINISH_LAYOUT_REDO_LAYOUT
4185 | FINISH_LAYOUT_REDO_CONFIG
4186 | FINISH_LAYOUT_REDO_WALLPAPER;
4187 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004188 if (mKeyguardDelegate.isShowing()) {
4189 mHandler.post(new Runnable() {
4190 @Override
4191 public void run() {
4192 mKeyguardDelegate.keyguardDone(false, false);
4193 }
4194 });
4195 }
4196 } else if (mHideLockScreen) {
4197 mKeyguardHidden = true;
Jim Millerab954542014-10-10 18:21:49 -07004198 if (setKeyguardOccludedLw(true)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004199 changes |= FINISH_LAYOUT_REDO_LAYOUT
4200 | FINISH_LAYOUT_REDO_CONFIG
4201 | FINISH_LAYOUT_REDO_WALLPAPER;
4202 }
4203 } else if (mDismissKeyguard != DISMISS_KEYGUARD_NONE) {
4204 // This is the case of keyguard isSecure() and not mHideLockScreen.
4205 if (mDismissKeyguard == DISMISS_KEYGUARD_START) {
4206 // Only launch the next keyguard unlock window once per window.
4207 mKeyguardHidden = false;
Jim Millerab954542014-10-10 18:21:49 -07004208 if (setKeyguardOccludedLw(false)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004209 changes |= FINISH_LAYOUT_REDO_LAYOUT
4210 | FINISH_LAYOUT_REDO_CONFIG
4211 | FINISH_LAYOUT_REDO_WALLPAPER;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004212 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004213 mHandler.post(new Runnable() {
4214 @Override
4215 public void run() {
4216 mKeyguardDelegate.dismiss();
4217 }
4218 });
4219 }
4220 } else {
4221 mWinDismissingKeyguard = null;
4222 mKeyguardHidden = false;
Jim Millerab954542014-10-10 18:21:49 -07004223 if (setKeyguardOccludedLw(false)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004224 changes |= FINISH_LAYOUT_REDO_LAYOUT
4225 | FINISH_LAYOUT_REDO_CONFIG
4226 | FINISH_LAYOUT_REDO_WALLPAPER;
4227 }
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -07004228 }
4229 }
Joe Onorato664644d2011-01-23 17:53:23 -08004230
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004231 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004232 // If the navigation bar has been hidden or shown, we need to do another
4233 // layout pass to update that window.
4234 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4235 }
Joe Onorato664644d2011-01-23 17:53:23 -08004236
Mike Lockwood28569302010-01-28 11:54:40 -05004237 // update since mAllowLockscreenWhenOn might have changed
4238 updateLockScreenTimeout();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004239 return changes;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004240 }
4241
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004242 /**
Jim Millerab954542014-10-10 18:21:49 -07004243 * Updates the occluded state of the Keyguard.
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004244 *
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004245 * @return Whether the flags have changed and we have to redo the layout.
4246 */
Jim Millerab954542014-10-10 18:21:49 -07004247 private boolean setKeyguardOccludedLw(boolean isOccluded) {
4248 boolean wasOccluded = mKeyguardOccluded;
4249 boolean showing = mKeyguardDelegate.isShowing();
4250 if (wasOccluded && !isOccluded && showing) {
4251 mKeyguardOccluded = false;
4252 mKeyguardDelegate.setOccluded(false);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004253 mStatusBar.getAttrs().privateFlags |= PRIVATE_FLAG_KEYGUARD;
4254 mStatusBar.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
4255 return true;
Jim Millerab954542014-10-10 18:21:49 -07004256 } else if (!wasOccluded && isOccluded && showing) {
4257 mKeyguardOccluded = true;
4258 mKeyguardDelegate.setOccluded(true);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004259 mStatusBar.getAttrs().privateFlags &= ~PRIVATE_FLAG_KEYGUARD;
4260 mStatusBar.getAttrs().flags &= ~FLAG_SHOW_WALLPAPER;
4261 return true;
4262 } else {
4263 return false;
4264 }
4265 }
4266
4267 private boolean isStatusBarKeyguard() {
4268 return mStatusBar != null
4269 && (mStatusBar.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
4270 }
4271
Jose Lima9546b202014-07-02 17:21:51 -07004272 @Override
Dianne Hackborn08743722009-12-21 12:16:51 -08004273 public boolean allowAppAnimationsLw() {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004274 if (isStatusBarKeyguard() || mShowingDream) {
Craig Mautner28816302013-10-10 20:31:00 -07004275 // If keyguard or dreams is currently visible, no reason to animate behind it.
Dianne Hackborn08743722009-12-21 12:16:51 -08004276 return false;
4277 }
Dianne Hackborn08743722009-12-21 12:16:51 -08004278 return true;
4279 }
4280
Jose Lima9546b202014-07-02 17:21:51 -07004281 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07004282 public int focusChangedLw(WindowState lastFocus, WindowState newFocus) {
Joe Onorato664644d2011-01-23 17:53:23 -08004283 mFocusedWindow = newFocus;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004284 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004285 // If the navigation bar has been hidden or shown, we need to do another
4286 // layout pass to update that window.
4287 return FINISH_LAYOUT_REDO_LAYOUT;
4288 }
4289 return 0;
Joe Onorato664644d2011-01-23 17:53:23 -08004290 }
4291
Dianne Hackborn0ecadf72009-03-31 18:00:37 -07004292 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07004293 @Override
Jeff Brown46b9ac02010-04-22 18:58:52 -07004294 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
4295 // lid changed state
Jeff Brownc458ce92012-04-30 14:58:40 -07004296 final int newLidState = lidOpen ? LID_OPEN : LID_CLOSED;
4297 if (newLidState == mLidState) {
4298 return;
4299 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004300
Jeff Brownc458ce92012-04-30 14:58:40 -07004301 mLidState = newLidState;
4302 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07004303 updateRotation(true);
Jeff Brownc458ce92012-04-30 14:58:40 -07004304
4305 if (lidOpen) {
Bryce Lee584a4452014-10-21 15:55:55 -07004306 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromLidSwitch);
Jeff Brownc458ce92012-04-30 14:58:40 -07004307 } else if (!mLidControlsSleep) {
Jeff Brown96307042012-07-27 15:51:34 -07004308 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
Jeff Brown46b9ac02010-04-22 18:58:52 -07004309 }
4310 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004311
Michael Wright3818c922014-09-02 13:59:07 -07004312 @Override
4313 public void notifyCameraLensCoverSwitchChanged(long whenNanos, boolean lensCovered) {
4314 int lensCoverState = lensCovered ? CAMERA_LENS_COVERED : CAMERA_LENS_UNCOVERED;
4315 if (mCameraLensCoverState == lensCoverState) {
4316 return;
4317 }
4318 if (mCameraLensCoverState == CAMERA_LENS_COVERED &&
4319 lensCoverState == CAMERA_LENS_UNCOVERED) {
4320 Intent intent;
4321 final boolean keyguardActive = mKeyguardDelegate == null ? false :
4322 mKeyguardDelegate.isShowing();
4323 if (keyguardActive) {
4324 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE);
4325 } else {
4326 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
4327 }
Bryce Lee584a4452014-10-21 15:55:55 -07004328 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromCameraLens);
Michael Wright3818c922014-09-02 13:59:07 -07004329 mContext.startActivityAsUser(intent, UserHandle.CURRENT_OR_SELF);
4330 }
4331 mCameraLensCoverState = lensCoverState;
4332 }
4333
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004334 void setHdmiPlugged(boolean plugged) {
4335 if (mHdmiPlugged != plugged) {
4336 mHdmiPlugged = plugged;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004337 updateRotation(true, true);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004338 Intent intent = new Intent(ACTION_HDMI_PLUGGED);
Joe Onoratodc100302011-01-11 17:07:41 -08004339 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004340 intent.putExtra(EXTRA_HDMI_PLUGGED_STATE, plugged);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07004341 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004342 }
4343 }
4344
Joe Onoratoea495d42011-04-06 11:41:11 -07004345 void initializeHdmiState() {
Joe Onorato7ba631f2011-05-04 15:28:00 -07004346 boolean plugged = false;
Joe Onoratoea495d42011-04-06 11:41:11 -07004347 // watch for HDMI plug messages if the hdmi switch exists
4348 if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) {
4349 mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi");
4350
Joe Onoratoea495d42011-04-06 11:41:11 -07004351 final String filename = "/sys/class/switch/hdmi/state";
4352 FileReader reader = null;
4353 try {
4354 reader = new FileReader(filename);
4355 char[] buf = new char[15];
4356 int n = reader.read(buf);
4357 if (n > 1) {
4358 plugged = 0 != Integer.parseInt(new String(buf, 0, n-1));
4359 }
4360 } catch (IOException ex) {
4361 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
4362 } catch (NumberFormatException ex) {
4363 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
4364 } finally {
4365 if (reader != null) {
4366 try {
4367 reader.close();
4368 } catch (IOException ex) {
4369 }
Joe Onoratodc100302011-01-11 17:07:41 -08004370 }
4371 }
4372 }
Joe Onorato7ba631f2011-05-04 15:28:00 -07004373 // This dance forces the code in setHdmiPlugged to run.
4374 // Always do this so the sticky intent is stuck (to false) if there is no hdmi.
4375 mHdmiPlugged = !plugged;
4376 setHdmiPlugged(!mHdmiPlugged);
Joe Onoratodc100302011-01-11 17:07:41 -08004377 }
4378
Dianne Hackbornc0e3f242011-08-19 14:19:10 -07004379 final Object mScreenshotLock = new Object();
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004380 ServiceConnection mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004381
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004382 final Runnable mScreenshotTimeout = new Runnable() {
4383 @Override public void run() {
4384 synchronized (mScreenshotLock) {
4385 if (mScreenshotConnection != null) {
4386 mContext.unbindService(mScreenshotConnection);
4387 mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004388 }
Winson Chung9112ec32011-06-27 13:15:32 -07004389 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004390 }
4391 };
4392
4393 // Assume this is called from the Handler thread.
4394 private void takeScreenshot() {
4395 synchronized (mScreenshotLock) {
4396 if (mScreenshotConnection != null) {
4397 return;
4398 }
4399 ComponentName cn = new ComponentName("com.android.systemui",
4400 "com.android.systemui.screenshot.TakeScreenshotService");
4401 Intent intent = new Intent();
4402 intent.setComponent(cn);
4403 ServiceConnection conn = new ServiceConnection() {
4404 @Override
4405 public void onServiceConnected(ComponentName name, IBinder service) {
4406 synchronized (mScreenshotLock) {
4407 if (mScreenshotConnection != this) {
4408 return;
4409 }
4410 Messenger messenger = new Messenger(service);
4411 Message msg = Message.obtain(null, 1);
4412 final ServiceConnection myConn = this;
4413 Handler h = new Handler(mHandler.getLooper()) {
4414 @Override
4415 public void handleMessage(Message msg) {
4416 synchronized (mScreenshotLock) {
4417 if (mScreenshotConnection == myConn) {
4418 mContext.unbindService(mScreenshotConnection);
4419 mScreenshotConnection = null;
4420 mHandler.removeCallbacks(mScreenshotTimeout);
4421 }
4422 }
4423 }
4424 };
4425 msg.replyTo = new Messenger(h);
Winson Chunga63bb842011-10-17 10:26:28 -07004426 msg.arg1 = msg.arg2 = 0;
4427 if (mStatusBar != null && mStatusBar.isVisibleLw())
4428 msg.arg1 = 1;
4429 if (mNavigationBar != null && mNavigationBar.isVisibleLw())
4430 msg.arg2 = 1;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004431 try {
4432 messenger.send(msg);
4433 } catch (RemoteException e) {
4434 }
4435 }
4436 }
4437 @Override
4438 public void onServiceDisconnected(ComponentName name) {}
4439 };
Amith Yamasani27b89e62013-01-16 12:30:11 -08004440 if (mContext.bindServiceAsUser(
4441 intent, conn, Context.BIND_AUTO_CREATE, UserHandle.CURRENT)) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004442 mScreenshotConnection = conn;
4443 mHandler.postDelayed(mScreenshotTimeout, 10000);
4444 }
4445 }
Winson Chung9112ec32011-06-27 13:15:32 -07004446 }
4447
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004448 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004449 @Override
Jeff Brown037c33e2014-04-09 00:31:55 -07004450 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) {
Jeff Brown96307042012-07-27 15:51:34 -07004451 if (!mSystemBooted) {
4452 // If we have not yet booted, don't let key events do anything.
4453 return 0;
4454 }
4455
Jeff Brown037c33e2014-04-09 00:31:55 -07004456 final boolean interactive = (policyFlags & FLAG_INTERACTIVE) != 0;
Jeff Brown1f245102010-11-18 20:53:46 -08004457 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
4458 final boolean canceled = event.isCanceled();
4459 final int keyCode = event.getKeyCode();
Jeff Browne20c9e02010-10-11 14:20:19 -07004460
Jeff Brown3122e442010-10-11 23:32:49 -07004461 final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0;
Jeff Brown3122e442010-10-11 23:32:49 -07004462
Mike Lockwoodc72b15f2009-11-28 20:58:22 -05004463 // If screen is off then we treat the case where the keyguard is open but hidden
4464 // the same as if it were open and in front.
4465 // This will prevent any keys other than the power button from waking the screen
4466 // when the keyguard is hidden by another activity.
Jim Miller5ecd8112013-01-09 18:50:26 -08004467 final boolean keyguardActive = (mKeyguardDelegate == null ? false :
Jeff Brown037c33e2014-04-09 00:31:55 -07004468 (interactive ?
Jim Millerab954542014-10-10 18:21:49 -07004469 isKeyguardShowingAndNotOccluded() :
Jim Miller5ecd8112013-01-09 18:50:26 -08004470 mKeyguardDelegate.isShowing()));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004471
Jeff Brown40013652012-05-16 21:22:36 -07004472 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004473 Log.d(TAG, "interceptKeyTq keycode=" + keyCode
Jeff Brown037c33e2014-04-09 00:31:55 -07004474 + " interactive=" + interactive + " keyguardActive=" + keyguardActive
Jeff Brown26875502014-01-30 21:47:47 -08004475 + " policyFlags=" + Integer.toHexString(policyFlags));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004476 }
4477
Jeff Brown037c33e2014-04-09 00:31:55 -07004478 // Basic policy based on interactive state.
Jeff Brown4d396052010-10-29 21:50:21 -07004479 int result;
Michael Wright337d9d22014-04-22 15:03:48 -07004480 boolean isWakeKey = (policyFlags & WindowManagerPolicy.FLAG_WAKE) != 0
4481 || event.isWakeKey();
Michael Wrightfc01f042014-09-08 14:12:24 -07004482 if (interactive || (isInjected && !isWakeKey)) {
RoboErikde9ba392014-09-26 12:51:01 -07004483 // When the device is interactive or the key is injected pass the
4484 // key to the application.
Jeff Brown4d396052010-10-29 21:50:21 -07004485 result = ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07004486 isWakeKey = false;
Michael Wrightfc01f042014-09-08 14:12:24 -07004487 } else if (!interactive && shouldDispatchInputWhenNonInteractive()) {
4488 // If we're currently dozing with the screen on and the keyguard showing, pass the key
4489 // to the application but preserve its wake key status to make sure we still move
4490 // from dozing to fully interactive if we would normally go from off to fully
4491 // interactive.
4492 result = ACTION_PASS_TO_USER;
Jeff Brown4d396052010-10-29 21:50:21 -07004493 } else {
4494 // When the screen is off and the key is not injected, determine whether
4495 // to wake the device but don't pass the key to the application.
4496 result = 0;
Jeff Brown26875502014-01-30 21:47:47 -08004497 if (isWakeKey && (!down || !isWakeKeyWhenScreenOff(keyCode))) {
4498 isWakeKey = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004499 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004500 }
4501
Justin Kohd378ad72013-04-01 12:18:26 -07004502 // If the key would be handled globally, just return the result, don't worry about special
4503 // key processing.
Jeff Brown13f00f02014-10-31 14:45:50 -07004504 if (isValidGlobalKey(keyCode)
4505 && mGlobalKeyManager.shouldHandleGlobalKey(keyCode, event)) {
Michael Wright85b1af62014-06-04 14:51:58 -07004506 if (isWakeKey) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004507 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey);
Michael Wright85b1af62014-06-04 14:51:58 -07004508 }
Justin Kohd378ad72013-04-01 12:18:26 -07004509 return result;
4510 }
4511
Jeff Brownbae8e772014-06-12 19:59:45 -07004512 boolean useHapticFeedback = down
4513 && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0
4514 && event.getRepeatCount() == 0;
4515
Jeff Brown4d396052010-10-29 21:50:21 -07004516 // Handle special keys.
4517 switch (keyCode) {
4518 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jeff Brownb0418da2010-11-01 15:24:01 -07004519 case KeyEvent.KEYCODE_VOLUME_UP:
4520 case KeyEvent.KEYCODE_VOLUME_MUTE: {
RoboErik001c59c2015-01-26 15:53:51 -08004521 if (mUseTvRouting) {
4522 // On TVs volume keys never go to the foreground app
4523 result &= ~ACTION_PASS_TO_USER;
4524 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004525 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
4526 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004527 if (interactive && !mScreenshotChordVolumeDownKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004528 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004529 mScreenshotChordVolumeDownKeyTriggered = true;
4530 mScreenshotChordVolumeDownKeyTime = event.getDownTime();
4531 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004532 cancelPendingPowerKeyAction();
4533 interceptScreenshotChord();
4534 }
4535 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004536 mScreenshotChordVolumeDownKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004537 cancelPendingScreenshotChordAction();
4538 }
4539 } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
4540 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004541 if (interactive && !mScreenshotChordVolumeUpKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004542 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004543 mScreenshotChordVolumeUpKeyTriggered = true;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004544 cancelPendingPowerKeyAction();
4545 cancelPendingScreenshotChordAction();
4546 }
4547 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004548 mScreenshotChordVolumeUpKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004549 cancelPendingScreenshotChordAction();
4550 }
4551 }
Jeff Brown4d396052010-10-29 21:50:21 -07004552 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004553 TelecomManager telecomManager = getTelecommService();
4554 if (telecomManager != null) {
4555 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07004556 // If an incoming call is ringing, either VOLUME key means
4557 // "silence ringer". We handle these keys here, rather than
4558 // in the InCallScreen, to make sure we'll respond to them
4559 // even if the InCallScreen hasn't come to the foreground yet.
4560 // Look for the DOWN event here, to agree with the "fallback"
4561 // behavior in the InCallScreen.
4562 Log.i(TAG, "interceptKeyBeforeQueueing:"
4563 + " VOLUME key-down while ringing: Silence ringer!");
Jeff Brown4d396052010-10-29 21:50:21 -07004564
Santos Cordon6848f722014-05-21 15:22:12 -07004565 // Silence the ringer. (It's safe to call this
4566 // even if the ringer has already been silenced.)
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004567 telecomManager.silenceRinger();
Jeff Brown4d396052010-10-29 21:50:21 -07004568
Santos Cordon6848f722014-05-21 15:22:12 -07004569 // And *don't* pass this key thru to the current activity
4570 // (which is probably the InCallScreen.)
4571 result &= ~ACTION_PASS_TO_USER;
4572 break;
4573 }
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004574 if (telecomManager.isInCall()
Santos Cordon6848f722014-05-21 15:22:12 -07004575 && (result & ACTION_PASS_TO_USER) == 0) {
4576 // If we are in call but we decided not to pass the key to
RoboErik430fc482014-06-12 15:49:20 -07004577 // the application, just pass it to the session service.
4578
4579 MediaSessionLegacyHelper.getHelper(mContext)
RoboErik3c45c292014-07-08 16:47:31 -07004580 .sendVolumeKeyEvent(event, false);
Santos Cordon6848f722014-05-21 15:22:12 -07004581 break;
Jeff Brown4d396052010-10-29 21:50:21 -07004582 }
4583 }
4584
RoboErik430fc482014-06-12 15:49:20 -07004585 if ((result & ACTION_PASS_TO_USER) == 0) {
RoboErik001c59c2015-01-26 15:53:51 -08004586 if (mUseTvRouting) {
4587 dispatchDirectAudioEvent(event);
4588 } else {
4589 // If we aren't passing to the user and no one else
4590 // handled it send it to the session manager to
4591 // figure out.
4592 MediaSessionLegacyHelper.getHelper(mContext)
4593 .sendVolumeKeyEvent(event, true);
4594 }
Jeff Brown4d396052010-10-29 21:50:21 -07004595 break;
4596 }
4597 }
4598 break;
4599 }
4600
4601 case KeyEvent.KEYCODE_ENDCALL: {
4602 result &= ~ACTION_PASS_TO_USER;
4603 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004604 TelecomManager telecomManager = getTelecommService();
Jeff Brown4d396052010-10-29 21:50:21 -07004605 boolean hungUp = false;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004606 if (telecomManager != null) {
4607 hungUp = telecomManager.endCall();
Jeff Brown4d396052010-10-29 21:50:21 -07004608 }
Jeff Brown13f00f02014-10-31 14:45:50 -07004609 if (interactive && !hungUp) {
4610 mEndCallKeyHandled = false;
4611 mHandler.postDelayed(mEndCallLongPress,
4612 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
4613 } else {
4614 mEndCallKeyHandled = true;
4615 }
Jeff Brown4d396052010-10-29 21:50:21 -07004616 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004617 if (!mEndCallKeyHandled) {
4618 mHandler.removeCallbacks(mEndCallLongPress);
4619 if (!canceled) {
4620 if ((mEndcallBehavior
4621 & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) {
4622 if (goHome()) {
4623 break;
4624 }
Dianne Hackborn0041e972009-07-24 17:14:43 -07004625 }
Jeff Brown13f00f02014-10-31 14:45:50 -07004626 if ((mEndcallBehavior
4627 & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) {
4628 mPowerManager.goToSleep(event.getEventTime(),
4629 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
4630 isWakeKey = false;
4631 }
Jeff Brown4d396052010-10-29 21:50:21 -07004632 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004633 }
Jeff Brown4d396052010-10-29 21:50:21 -07004634 }
4635 break;
4636 }
4637
4638 case KeyEvent.KEYCODE_POWER: {
4639 result &= ~ACTION_PASS_TO_USER;
Jeff Brown13f00f02014-10-31 14:45:50 -07004640 isWakeKey = false; // wake-up will be handled separately
Jeff Brown4d396052010-10-29 21:50:21 -07004641 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004642 interceptPowerKeyDown(event, interactive);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004643 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004644 interceptPowerKeyUp(event, interactive, canceled);
Jeff Brown4d396052010-10-29 21:50:21 -07004645 }
4646 break;
4647 }
4648
Jeff Brown6212a492014-03-07 13:58:47 -08004649 case KeyEvent.KEYCODE_SLEEP: {
4650 result &= ~ACTION_PASS_TO_USER;
Jeff Brownbae8e772014-06-12 19:59:45 -07004651 if (!mPowerManager.isInteractive()) {
4652 useHapticFeedback = false; // suppress feedback if already non-interactive
4653 }
Jeff Brownc12035c2014-08-13 18:52:25 -07004654 mPowerManager.goToSleep(event.getEventTime(),
4655 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
Jeff Brown6212a492014-03-07 13:58:47 -08004656 isWakeKey = false;
4657 break;
4658 }
4659
4660 case KeyEvent.KEYCODE_WAKEUP: {
4661 result &= ~ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07004662 isWakeKey = true;
Jeff Brown6212a492014-03-07 13:58:47 -08004663 break;
4664 }
4665
Jeff Brown4d396052010-10-29 21:50:21 -07004666 case KeyEvent.KEYCODE_MEDIA_PLAY:
4667 case KeyEvent.KEYCODE_MEDIA_PAUSE:
4668 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
Jeff Brown4d396052010-10-29 21:50:21 -07004669 case KeyEvent.KEYCODE_HEADSETHOOK:
4670 case KeyEvent.KEYCODE_MUTE:
4671 case KeyEvent.KEYCODE_MEDIA_STOP:
4672 case KeyEvent.KEYCODE_MEDIA_NEXT:
4673 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
4674 case KeyEvent.KEYCODE_MEDIA_REWIND:
4675 case KeyEvent.KEYCODE_MEDIA_RECORD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09004676 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
4677 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: {
RoboErikde9ba392014-09-26 12:51:01 -07004678 if (MediaSessionLegacyHelper.getHelper(mContext).isGlobalPriorityActive()) {
4679 // If the global session is active pass all media keys to it
4680 // instead of the active window.
4681 result &= ~ACTION_PASS_TO_USER;
4682 }
Jeff Brown4d396052010-10-29 21:50:21 -07004683 if ((result & ACTION_PASS_TO_USER) == 0) {
4684 // Only do this if we would otherwise not pass it to the user. In that
4685 // case, the PhoneWindow class will do the same thing, except it will
4686 // only do it if the showing app doesn't process the key on its own.
Jeff Brown40013652012-05-16 21:22:36 -07004687 // Note that we need to make a copy of the key event here because the
4688 // original key event will be recycled when we return.
Jeff Brown4d396052010-10-29 21:50:21 -07004689 mBroadcastWakeLock.acquire();
Jeff Brown40013652012-05-16 21:22:36 -07004690 Message msg = mHandler.obtainMessage(MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK,
4691 new KeyEvent(event));
4692 msg.setAsynchronous(true);
4693 msg.sendToTarget();
Jeff Brown4d396052010-10-29 21:50:21 -07004694 }
4695 break;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004696 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004697
Jeff Brown4d396052010-10-29 21:50:21 -07004698 case KeyEvent.KEYCODE_CALL: {
4699 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004700 TelecomManager telecomManager = getTelecommService();
4701 if (telecomManager != null) {
4702 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07004703 Log.i(TAG, "interceptKeyBeforeQueueing:"
4704 + " CALL key-down while ringing: Answer the call!");
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004705 telecomManager.acceptRingingCall();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004706
Santos Cordon6848f722014-05-21 15:22:12 -07004707 // And *don't* pass this key thru to the current activity
4708 // (which is presumably the InCallScreen.)
4709 result &= ~ACTION_PASS_TO_USER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004710 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004711 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004712 }
Jeff Brown4d396052010-10-29 21:50:21 -07004713 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004714 }
Michael Wright869a67c2014-08-26 19:33:06 -07004715 case KeyEvent.KEYCODE_VOICE_ASSIST: {
4716 // Only do this if we would otherwise not pass it to the user. In that case,
4717 // interceptKeyBeforeDispatching would apply a similar but different policy in
4718 // order to invoke voice assist actions. Note that we need to make a copy of the
4719 // key event here because the original key event will be recycled when we return.
4720 if ((result & ACTION_PASS_TO_USER) == 0 && !down) {
4721 mBroadcastWakeLock.acquire();
4722 Message msg = mHandler.obtainMessage(MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK,
4723 keyguardActive ? 1 : 0, 0);
4724 msg.setAsynchronous(true);
4725 msg.sendToTarget();
4726 }
4727 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004728 }
Jeff Brown26875502014-01-30 21:47:47 -08004729
Jeff Brownbae8e772014-06-12 19:59:45 -07004730 if (useHapticFeedback) {
4731 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
4732 }
4733
Jeff Brown26875502014-01-30 21:47:47 -08004734 if (isWakeKey) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004735 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey);
Jeff Brown26875502014-01-30 21:47:47 -08004736 }
Bryce Lee584a4452014-10-21 15:55:55 -07004737
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004738 return result;
4739 }
4740
Jeff Brown1c2e4942012-11-06 16:32:01 -08004741 /**
Jeff Brown13f00f02014-10-31 14:45:50 -07004742 * Returns true if the key can have global actions attached to it.
4743 * We reserve all power management keys for the system since they require
4744 * very careful handling.
4745 */
4746 private static boolean isValidGlobalKey(int keyCode) {
4747 switch (keyCode) {
4748 case KeyEvent.KEYCODE_POWER:
4749 case KeyEvent.KEYCODE_WAKEUP:
4750 case KeyEvent.KEYCODE_SLEEP:
4751 return false;
4752 default:
4753 return true;
4754 }
4755 }
4756
4757 /**
Jeff Brown1c2e4942012-11-06 16:32:01 -08004758 * When the screen is off we ignore some keys that might otherwise typically
4759 * be considered wake keys. We filter them out here.
4760 *
4761 * {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it
4762 * is always considered a wake key.
4763 */
4764 private boolean isWakeKeyWhenScreenOff(int keyCode) {
4765 switch (keyCode) {
4766 // ignore volume keys unless docked
4767 case KeyEvent.KEYCODE_VOLUME_UP:
4768 case KeyEvent.KEYCODE_VOLUME_DOWN:
4769 case KeyEvent.KEYCODE_VOLUME_MUTE:
4770 return mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED;
4771
4772 // ignore media and camera keys
4773 case KeyEvent.KEYCODE_MUTE:
4774 case KeyEvent.KEYCODE_HEADSETHOOK:
4775 case KeyEvent.KEYCODE_MEDIA_PLAY:
4776 case KeyEvent.KEYCODE_MEDIA_PAUSE:
4777 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
4778 case KeyEvent.KEYCODE_MEDIA_STOP:
4779 case KeyEvent.KEYCODE_MEDIA_NEXT:
4780 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
4781 case KeyEvent.KEYCODE_MEDIA_REWIND:
4782 case KeyEvent.KEYCODE_MEDIA_RECORD:
4783 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09004784 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK:
Jeff Brown1c2e4942012-11-06 16:32:01 -08004785 case KeyEvent.KEYCODE_CAMERA:
4786 return false;
4787 }
4788 return true;
4789 }
4790
4791
Jeff Brown56194eb2011-03-02 19:23:13 -08004792 /** {@inheritDoc} */
4793 @Override
Michael Wright70af00a2014-09-03 19:30:20 -07004794 public int interceptMotionBeforeQueueingNonInteractive(long whenNanos, int policyFlags) {
4795 if ((policyFlags & FLAG_WAKE) != 0) {
Bryce Lee5c138322014-11-03 08:26:09 -08004796 if (wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotion)) {
4797 return 0;
4798 }
Michael Wright70af00a2014-09-03 19:30:20 -07004799 }
Bryce Lee5c138322014-11-03 08:26:09 -08004800
Michael Wright70af00a2014-09-03 19:30:20 -07004801 if (shouldDispatchInputWhenNonInteractive()) {
4802 return ACTION_PASS_TO_USER;
4803 }
Bryce Lee5c138322014-11-03 08:26:09 -08004804
Bryce Lee812d7022014-11-10 13:33:28 -08004805 // If we have not passed the action up and we are in theater mode without dreaming,
4806 // there will be no dream to intercept the touch and wake into ambient. The device should
4807 // wake up in this case.
4808 if (isTheaterModeEnabled() && (policyFlags & FLAG_WAKE) != 0) {
4809 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotionWhenNotDreaming);
4810 }
4811
Jeff Brown037c33e2014-04-09 00:31:55 -07004812 return 0;
Jeff Brown56194eb2011-03-02 19:23:13 -08004813 }
4814
Michael Wright70af00a2014-09-03 19:30:20 -07004815 private boolean shouldDispatchInputWhenNonInteractive() {
Bryce Lee5c138322014-11-03 08:26:09 -08004816 // Send events to keyguard while the screen is on.
Jim Millerab954542014-10-10 18:21:49 -07004817 if (isKeyguardShowingAndNotOccluded() && mDisplay != null
4818 && mDisplay.getState() != Display.STATE_OFF) {
Bryce Lee5c138322014-11-03 08:26:09 -08004819 return true;
4820 }
4821
4822 // Send events to a dozing dream even if the screen is off since the dream
4823 // is in control of the state of the screen.
4824 IDreamManager dreamManager = getDreamManager();
4825
4826 try {
4827 if (dreamManager != null && dreamManager.isDreaming()) {
4828 return true;
4829 }
4830 } catch (RemoteException e) {
4831 Slog.e(TAG, "RemoteException when checking if dreaming", e);
4832 }
4833
4834 // Otherwise, consume events since the user can't see what is being
4835 // interacted with.
4836 return false;
Michael Wright70af00a2014-09-03 19:30:20 -07004837 }
4838
RoboErik001c59c2015-01-26 15:53:51 -08004839 private void dispatchDirectAudioEvent(KeyEvent event) {
4840 if (event.getAction() != KeyEvent.ACTION_DOWN) {
4841 return;
4842 }
4843 int keyCode = event.getKeyCode();
4844 int flags = AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_PLAY_SOUND;
4845 String pkgName = mContext.getOpPackageName();
4846 switch (keyCode) {
4847 case KeyEvent.KEYCODE_VOLUME_UP:
4848 try {
4849 if (mUseMasterVolume) {
4850 getAudioService().adjustMasterVolume(AudioManager.ADJUST_RAISE, flags,
4851 pkgName);
4852 } else {
4853 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_RAISE,
4854 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName);
4855 }
4856 } catch (RemoteException e) {
4857 Log.e(TAG, "Error dispatching volume up in dispatchTvAudioEvent.", e);
4858 }
4859 break;
4860 case KeyEvent.KEYCODE_VOLUME_DOWN:
4861 try {
4862 if (mUseMasterVolume) {
4863 getAudioService().adjustMasterVolume(AudioManager.ADJUST_LOWER, flags,
4864 pkgName);
4865 } else {
4866 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_LOWER,
4867 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName);
4868 }
4869 } 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) {
4876 if (mUseMasterVolume) {
4877 getAudioService().adjustMasterVolume(AudioManager.ADJUST_TOGGLE_MUTE,
4878 flags, pkgName);
4879 } else {
4880 getAudioService().adjustSuggestedStreamVolume(
4881 AudioManager.ADJUST_TOGGLE_MUTE,
4882 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName);
4883 }
4884 }
4885 } catch (RemoteException e) {
4886 Log.e(TAG, "Error dispatching mute in dispatchTvAudioEvent.", e);
4887 }
4888 break;
4889 }
4890 }
4891
Jeff Brown40013652012-05-16 21:22:36 -07004892 void dispatchMediaKeyWithWakeLock(KeyEvent event) {
4893 if (DEBUG_INPUT) {
4894 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: " + event);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004895 }
4896
Jeff Brown40013652012-05-16 21:22:36 -07004897 if (mHavePendingMediaKeyRepeatWithWakeLock) {
4898 if (DEBUG_INPUT) {
4899 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: canceled repeat");
4900 }
4901
4902 mHandler.removeMessages(MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK);
4903 mHavePendingMediaKeyRepeatWithWakeLock = false;
4904 mBroadcastWakeLock.release(); // pending repeat was holding onto the wake lock
4905 }
4906
4907 dispatchMediaKeyWithWakeLockToAudioService(event);
4908
4909 if (event.getAction() == KeyEvent.ACTION_DOWN
4910 && event.getRepeatCount() == 0) {
4911 mHavePendingMediaKeyRepeatWithWakeLock = true;
4912
4913 Message msg = mHandler.obtainMessage(
4914 MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK, event);
4915 msg.setAsynchronous(true);
4916 mHandler.sendMessageDelayed(msg, ViewConfiguration.getKeyRepeatTimeout());
4917 } else {
4918 mBroadcastWakeLock.release();
4919 }
4920 }
4921
4922 void dispatchMediaKeyRepeatWithWakeLock(KeyEvent event) {
4923 mHavePendingMediaKeyRepeatWithWakeLock = false;
4924
4925 KeyEvent repeatEvent = KeyEvent.changeTimeRepeat(event,
4926 SystemClock.uptimeMillis(), 1, event.getFlags() | KeyEvent.FLAG_LONG_PRESS);
4927 if (DEBUG_INPUT) {
4928 Slog.d(TAG, "dispatchMediaKeyRepeatWithWakeLock: " + repeatEvent);
4929 }
4930
4931 dispatchMediaKeyWithWakeLockToAudioService(repeatEvent);
4932 mBroadcastWakeLock.release();
4933 }
4934
4935 void dispatchMediaKeyWithWakeLockToAudioService(KeyEvent event) {
4936 if (ActivityManagerNative.isSystemReady()) {
RoboErik430fc482014-06-12 15:49:20 -07004937 MediaSessionLegacyHelper.getHelper(mContext).sendMediaButtonEvent(event, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004938 }
4939 }
4940
Michael Wright869a67c2014-08-26 19:33:06 -07004941 void launchVoiceAssistWithWakeLock(boolean keyguardActive) {
4942 Intent voiceIntent =
4943 new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
4944 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, keyguardActive);
4945 mContext.startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
4946 mBroadcastWakeLock.release();
4947 }
4948
Mike Lockwood1753f7f2009-08-24 14:49:07 -07004949 BroadcastReceiver mDockReceiver = new BroadcastReceiver() {
Craig Mautnereee29c42013-01-17 14:44:34 -08004950 @Override
Mike Lockwood1753f7f2009-08-24 14:49:07 -07004951 public void onReceive(Context context, Intent intent) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07004952 if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) {
4953 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
4954 Intent.EXTRA_DOCK_STATE_UNDOCKED);
Daniel Sandler6396c722013-04-16 20:19:09 -04004955 } else {
4956 try {
4957 IUiModeManager uiModeService = IUiModeManager.Stub.asInterface(
4958 ServiceManager.getService(Context.UI_MODE_SERVICE));
4959 mUiMode = uiModeService.getCurrentModeType();
4960 } catch (RemoteException e) {
4961 }
Dianne Hackborn80fa1662009-10-07 14:02:10 -07004962 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004963 updateRotation(true);
Craig Mautnereee29c42013-01-17 14:44:34 -08004964 synchronized (mLock) {
4965 updateOrientationListenerLp();
4966 }
Mike Lockwood1753f7f2009-08-24 14:49:07 -07004967 }
4968 };
4969
Jeff Brown6aaf2952012-10-05 16:01:08 -07004970 BroadcastReceiver mDreamReceiver = new BroadcastReceiver() {
4971 @Override
4972 public void onReceive(Context context, Intent intent) {
4973 if (Intent.ACTION_DREAMING_STARTED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004974 if (mKeyguardDelegate != null) {
4975 mKeyguardDelegate.onDreamingStarted();
Jeff Brown6aaf2952012-10-05 16:01:08 -07004976 }
4977 } else if (Intent.ACTION_DREAMING_STOPPED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004978 if (mKeyguardDelegate != null) {
4979 mKeyguardDelegate.onDreamingStopped();
Jeff Brown6aaf2952012-10-05 16:01:08 -07004980 }
4981 }
4982 }
4983 };
4984
Christopher Tate5e08af02012-09-21 17:17:22 -07004985 BroadcastReceiver mMultiuserReceiver = new BroadcastReceiver() {
4986 @Override
4987 public void onReceive(Context context, Intent intent) {
4988 if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) {
4989 // tickle the settings observer: this first ensures that we're
4990 // observing the relevant settings for the newly-active user,
4991 // and then updates our own bookkeeping based on the now-
4992 // current user.
4993 mSettingsObserver.onChange(false);
John Spurlockce479d82012-11-29 09:52:21 -05004994
4995 // force a re-application of focused window sysui visibility.
4996 // the window may never have been shown for this user
4997 // e.g. the keyguard when going through the new-user setup flow
John Spurlock04db1762013-05-13 12:46:41 -04004998 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
John Spurlockce479d82012-11-29 09:52:21 -05004999 mLastSystemUiFlags = 0;
5000 updateSystemUiVisibilityLw();
5001 }
Christopher Tate5e08af02012-09-21 17:17:22 -07005002 }
5003 }
5004 };
5005
John Spurlockd9b70bd2014-02-06 17:02:44 -05005006 private final Runnable mRequestTransientNav = new Runnable() {
5007 @Override
5008 public void run() {
5009 requestTransientBars(mNavigationBar);
5010 }
5011 };
5012
John Spurlocke1f366f2013-08-05 12:22:40 -04005013 private void requestTransientBars(WindowState swipeTarget) {
John Spurlock04db1762013-05-13 12:46:41 -04005014 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Maurice Lam99c6e072014-04-28 18:24:28 -07005015 if (!isUserSetupComplete()) {
5016 // Swipe-up for navigation bar is disabled during setup
5017 return;
5018 }
John Spurlock27735a42013-08-14 17:57:38 -04005019 boolean sb = mStatusBarController.checkShowTransientBarLw();
5020 boolean nb = mNavigationBarController.checkShowTransientBarLw();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005021 if (sb || nb) {
John Spurlocke1f366f2013-08-05 12:22:40 -04005022 WindowState barTarget = sb ? mStatusBar : mNavigationBar;
5023 if (sb ^ nb && barTarget != swipeTarget) {
5024 if (DEBUG) Slog.d(TAG, "Not showing transient bar, wrong swipe target");
John Spurlockad3e6cb2013-04-30 08:47:43 -04005025 return;
5026 }
John Spurlock27735a42013-08-14 17:57:38 -04005027 if (sb) mStatusBarController.showTransient();
5028 if (nb) mNavigationBarController.showTransient();
John Spurlockf1a36642013-10-12 17:50:42 -04005029 mImmersiveModeConfirmation.confirmCurrentPrompt();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005030 updateSystemUiVisibilityLw();
John Spurlock32beb2c2013-03-11 10:16:47 -04005031 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04005032 }
5033 }
5034
Jeff Brown3ee549c2014-09-22 20:14:39 -07005035 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07005036 @Override
Jeff Brown140ffc72014-05-01 15:18:00 -07005037 public void goingToSleep(int why) {
Dianne Hackborn74489012009-03-24 20:50:09 -07005038 EventLog.writeEvent(70000, 0);
Jeff Brown36c4db82014-09-19 12:05:31 -07005039 if (DEBUG_WAKEUP) Slog.i(TAG, "Going to sleep...");
Jeff Brown3ee549c2014-09-22 20:14:39 -07005040
5041 // We must get this work done here because the power manager will drop
5042 // the wake lock and let the system suspend once this function returns.
The Android Open Source Project0727d222009-03-11 12:11:58 -07005043 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005044 mAwake = false;
5045 mKeyguardDrawComplete = false;
Jeff Browna20dda42014-05-27 20:57:24 -07005046 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005047 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05005048 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005049 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005050
5051 if (mKeyguardDelegate != null) {
5052 mKeyguardDelegate.onScreenTurnedOff(why);
5053 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005054 }
5055
Jeff Brown13f00f02014-10-31 14:45:50 -07005056 private void wakeUpFromPowerKey(long eventTime) {
5057 wakeUp(eventTime, mAllowTheaterModeWakeFromPowerKey);
5058 }
5059
Bryce Lee5c138322014-11-03 08:26:09 -08005060 private boolean wakeUp(long wakeTime, boolean wakeInTheaterMode) {
Bryce Lee584a4452014-10-21 15:55:55 -07005061 if (!wakeInTheaterMode && isTheaterModeEnabled()) {
Bryce Lee5c138322014-11-03 08:26:09 -08005062 return false;
Bryce Lee584a4452014-10-21 15:55:55 -07005063 }
5064
5065 mPowerManager.wakeUp(wakeTime);
Bryce Lee5c138322014-11-03 08:26:09 -08005066 return true;
Bryce Lee584a4452014-10-21 15:55:55 -07005067 }
5068
Jeff Brown3ee549c2014-09-22 20:14:39 -07005069 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07005070 @Override
Jeff Brown36c4db82014-09-19 12:05:31 -07005071 public void wakingUp() {
Dianne Hackborn74489012009-03-24 20:50:09 -07005072 EventLog.writeEvent(70000, 1);
Jeff Brown36c4db82014-09-19 12:05:31 -07005073 if (DEBUG_WAKEUP) Slog.i(TAG, "Waking up...");
Craig Mautner8a0da012014-05-31 15:13:37 -07005074
Jeff Brown3ee549c2014-09-22 20:14:39 -07005075 // Since goToSleep performs these functions synchronously, we must
5076 // do the same here. We cannot post this work to a handler because
5077 // that might cause it to become reordered with respect to what
5078 // may happen in a future call to goToSleep.
The Android Open Source Project0727d222009-03-11 12:11:58 -07005079 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005080 mAwake = true;
5081 mKeyguardDrawComplete = false;
5082 if (mKeyguardDelegate != null) {
5083 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
5084 mHandler.sendEmptyMessageDelayed(MSG_KEYGUARD_DRAWN_TIMEOUT, 1000);
5085 }
5086
Jeff Browna20dda42014-05-27 20:57:24 -07005087 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005088 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05005089 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005090 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005091
Jim Miller5ecd8112013-01-09 18:50:26 -08005092 if (mKeyguardDelegate != null) {
Craig Mautner8a0da012014-05-31 15:13:37 -07005093 mKeyguardDelegate.onScreenTurnedOn(mKeyguardDelegateCallback);
Jeff Brown36c4db82014-09-19 12:05:31 -07005094 // ... eventually calls finishKeyguardDrawn
Jeff Brownc38c9be2012-10-04 13:16:19 -07005095 } else {
Craig Mautner8a0da012014-05-31 15:13:37 -07005096 if (DEBUG_WAKEUP) Slog.d(TAG, "null mKeyguardDelegate: setting mKeyguardDrawComplete.");
Jeff Brown36c4db82014-09-19 12:05:31 -07005097 finishKeyguardDrawn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07005098 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005099 }
5100
Jeff Brown36c4db82014-09-19 12:05:31 -07005101 private void finishKeyguardDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005102 synchronized (mLock) {
5103 if (!mAwake || mKeyguardDrawComplete) {
5104 return; // spurious
5105 }
5106
Jeff Brown36c4db82014-09-19 12:05:31 -07005107 mKeyguardDrawComplete = true;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005108 if (mKeyguardDelegate != null) {
5109 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
5110 }
5111 }
5112
5113 finishScreenTurningOn();
5114 }
5115
5116 // Called on the DisplayManager's DisplayPowerController thread.
5117 @Override
5118 public void screenTurnedOff() {
5119 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turned off...");
5120
5121 synchronized (mLock) {
5122 mScreenOnEarly = false;
5123 mScreenOnFully = false;
5124 mWindowManagerDrawComplete = false;
5125 mScreenOnListener = null;
5126 updateOrientationListenerLp();
Jeff Brown36c4db82014-09-19 12:05:31 -07005127 }
5128 }
5129
Jeff Brown3ee549c2014-09-22 20:14:39 -07005130 // Called on the DisplayManager's DisplayPowerController thread.
Jeff Brown36c4db82014-09-19 12:05:31 -07005131 @Override
5132 public void screenTurningOn(final ScreenOnListener screenOnListener) {
Jeff Brown36c4db82014-09-19 12:05:31 -07005133 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turning on...");
Jeff Brown36c4db82014-09-19 12:05:31 -07005134
Jeff Brown3ee549c2014-09-22 20:14:39 -07005135 synchronized (mLock) {
5136 mScreenOnEarly = true;
5137 mScreenOnFully = false;
5138 mWindowManagerDrawComplete = false;
5139 mScreenOnListener = screenOnListener;
5140 updateOrientationListenerLp();
5141 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005142
Craig Mautnerc3daedd2014-09-13 11:17:23 -07005143 mWindowManagerInternal.waitForAllWindowsDrawn(mWindowManagerDrawCallback,
5144 WAITING_FOR_DRAWN_TIMEOUT);
Jeff Brown36c4db82014-09-19 12:05:31 -07005145 // ... eventually calls finishWindowsDrawn
5146 }
5147
Jeff Brown36c4db82014-09-19 12:05:31 -07005148 private void finishWindowsDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005149 synchronized (mLock) {
5150 if (!mScreenOnEarly || mWindowManagerDrawComplete) {
5151 return; // spurious
5152 }
5153
Jeff Brown36c4db82014-09-19 12:05:31 -07005154 mWindowManagerDrawComplete = true;
Jeff Brown36c4db82014-09-19 12:05:31 -07005155 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005156
5157 finishScreenTurningOn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07005158 }
5159
Craig Mautner8a0da012014-05-31 15:13:37 -07005160 private void finishScreenTurningOn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005161 final ScreenOnListener listener;
5162 final boolean enableScreen;
Jeff Brown36c4db82014-09-19 12:05:31 -07005163 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005164 if (DEBUG_WAKEUP) Slog.d(TAG,
5165 "finishScreenTurningOn: mAwake=" + mAwake
5166 + ", mScreenOnEarly=" + mScreenOnEarly
5167 + ", mScreenOnFully=" + mScreenOnFully
5168 + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete
5169 + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete);
5170
5171 if (mScreenOnFully || !mScreenOnEarly || !mWindowManagerDrawComplete
5172 || (mAwake && !mKeyguardDrawComplete)) {
5173 return; // spurious or not ready yet
Jeff Brown36c4db82014-09-19 12:05:31 -07005174 }
5175
Jeff Brown3ee549c2014-09-22 20:14:39 -07005176 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished screen turning on...");
5177 listener = mScreenOnListener;
Craig Mautner13f6ea72014-06-23 14:57:02 -07005178 mScreenOnListener = null;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005179 mScreenOnFully = true;
5180
5181 // Remember the first time we draw the keyguard so we know when we're done with
5182 // the main part of booting and can enable the screen and hide boot messages.
5183 if (!mKeyguardDrawnOnce && mAwake) {
5184 mKeyguardDrawnOnce = true;
5185 enableScreen = true;
5186 if (mBootMessageNeedsHiding) {
5187 mBootMessageNeedsHiding = false;
5188 hideBootMessages();
5189 }
5190 } else {
5191 enableScreen = false;
5192 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005193 }
5194
Jeff Brown3ee549c2014-09-22 20:14:39 -07005195 if (listener != null) {
5196 listener.onScreenOn();
5197 }
Jeff Brown4fc45272012-10-10 18:28:14 -07005198
Jeff Brown3ee549c2014-09-22 20:14:39 -07005199 if (enableScreen) {
5200 try {
5201 mWindowManager.enableScreenIfNeeded();
5202 } catch (RemoteException unhandled) {
Jeff Brown36c4db82014-09-19 12:05:31 -07005203 }
Craig Mautnera631d492014-08-05 15:16:01 -07005204 }
5205 }
5206
5207 private void handleHideBootMessage() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005208 synchronized (mLock) {
5209 if (!mKeyguardDrawnOnce) {
5210 mBootMessageNeedsHiding = true;
5211 return; // keyguard hasn't drawn the first time yet, not done booting
5212 }
Craig Mautnera631d492014-08-05 15:16:01 -07005213 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005214
5215 if (mBootMsgDialog != null) {
5216 if (DEBUG_WAKEUP) Slog.d(TAG, "handleHideBootMessage: dismissing");
5217 mBootMsgDialog.dismiss();
5218 mBootMsgDialog = null;
Craig Mautnera631d492014-08-05 15:16:01 -07005219 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005220 }
5221
5222 @Override
Jeff Brown3ee549c2014-09-22 20:14:39 -07005223 public boolean isScreenOn() {
5224 return mScreenOnFully;
Dianne Hackborn08743722009-12-21 12:16:51 -08005225 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005226
Dianne Hackborn08743722009-12-21 12:16:51 -08005227 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005228 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005229 public void enableKeyguard(boolean enabled) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005230 if (mKeyguardDelegate != null) {
5231 mKeyguardDelegate.setKeyguardEnabled(enabled);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005232 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005233 }
5234
5235 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005236 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005237 public void exitKeyguardSecurely(OnKeyguardExitResult callback) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005238 if (mKeyguardDelegate != null) {
5239 mKeyguardDelegate.verifyUnlock(callback);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005240 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005241 }
5242
Jim Millerab954542014-10-10 18:21:49 -07005243 private boolean isKeyguardShowingAndNotOccluded() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005244 if (mKeyguardDelegate == null) return false;
Jim Millerab954542014-10-10 18:21:49 -07005245 return mKeyguardDelegate.isShowing() && !mKeyguardOccluded;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005246 }
5247
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005248 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005249 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005250 public boolean isKeyguardLocked() {
5251 return keyguardOn();
5252 }
5253
5254 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005255 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005256 public boolean isKeyguardSecure() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005257 if (mKeyguardDelegate == null) return false;
5258 return mKeyguardDelegate.isSecure();
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005259 }
5260
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005261 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005262 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005263 public boolean inKeyguardRestrictedKeyInputMode() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005264 if (mKeyguardDelegate == null) return false;
5265 return mKeyguardDelegate.isInputRestricted();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005266 }
5267
Jose Lima9546b202014-07-02 17:21:51 -07005268 @Override
Dianne Hackborn90c52de2011-09-23 12:57:44 -07005269 public void dismissKeyguardLw() {
RoboErik8a2cfc32014-05-16 11:19:38 -07005270 if (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()) {
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07005271 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.dismissKeyguardLw");
Daniel Sandler1ce804392012-11-07 15:07:12 -05005272 mHandler.post(new Runnable() {
Jose Lima9546b202014-07-02 17:21:51 -07005273 @Override
Daniel Sandler1ce804392012-11-07 15:07:12 -05005274 public void run() {
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02005275 // ask the keyguard to prompt the user to authenticate if necessary
5276 mKeyguardDelegate.dismiss();
5277 }
5278 });
5279 }
5280 }
5281
5282 public void notifyActivityDrawnForKeyguardLw() {
5283 if (mKeyguardDelegate != null) {
5284 mHandler.post(new Runnable() {
5285 @Override
5286 public void run() {
5287 mKeyguardDelegate.onActivityDrawn();
Daniel Sandler1ce804392012-11-07 15:07:12 -05005288 }
5289 });
Dianne Hackborn90c52de2011-09-23 12:57:44 -07005290 }
5291 }
5292
Jorim Jaggicff0acb2014-03-31 16:35:15 +02005293 @Override
5294 public boolean isKeyguardDrawnLw() {
5295 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005296 return mKeyguardDrawnOnce;
Jorim Jaggicff0acb2014-03-31 16:35:15 +02005297 }
5298 }
5299
Jorim Jaggi0d674622014-05-21 01:34:15 +02005300 @Override
Jorim Jaggie29b2db2014-05-30 23:17:03 +02005301 public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) {
Jorim Jaggi0d674622014-05-21 01:34:15 +02005302 if (mKeyguardDelegate != null) {
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07005303 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.startKeyguardExitAnimation");
Jorim Jaggie29b2db2014-05-30 23:17:03 +02005304 mKeyguardDelegate.startKeyguardExitAnimation(startTime, fadeoutDuration);
Jorim Jaggi0d674622014-05-21 01:34:15 +02005305 }
5306 }
5307
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005308 void sendCloseSystemWindows() {
Jorim Jaggib10e33f2015-02-04 21:57:40 +01005309 PhoneWindow.sendCloseSystemWindows(mContext, null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005310 }
5311
5312 void sendCloseSystemWindows(String reason) {
Jorim Jaggib10e33f2015-02-04 21:57:40 +01005313 PhoneWindow.sendCloseSystemWindows(mContext, reason);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005314 }
Mitsuru Oshima831d0d92009-06-16 18:27:18 -07005315
Jeff Brown01a98dd2011-09-20 15:08:29 -07005316 @Override
5317 public int rotationForOrientationLw(int orientation, int lastRotation) {
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005318 if (false) {
5319 Slog.v(TAG, "rotationForOrientationLw(orient="
5320 + orientation + ", last=" + lastRotation
5321 + "); user=" + mUserRotation + " "
5322 + ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED)
5323 ? "USER_ROTATION_LOCKED" : "")
5324 );
5325 }
5326
Craig Mautner46ac6fa2013-08-01 10:06:34 -07005327 if (mForceDefaultOrientation) {
5328 return Surface.ROTATION_0;
5329 }
5330
The Android Open Source Project0727d222009-03-11 12:11:58 -07005331 synchronized (mLock) {
Jeff Brownc0347aa2011-09-23 17:26:09 -07005332 int sensorRotation = mOrientationListener.getProposedRotation(); // may be -1
5333 if (sensorRotation < 0) {
Jeff Brown0f862b42012-09-27 21:11:01 -07005334 sensorRotation = lastRotation;
Jeff Brownc0347aa2011-09-23 17:26:09 -07005335 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005336
Jeff Browndec6cf42011-11-15 14:08:20 -08005337 final int preferredRotation;
Jeff Brown2e7760e2012-04-11 15:14:55 -07005338 if (mLidState == LID_OPEN && mLidOpenRotation >= 0) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005339 // Ignore sensor when lid switch is open and rotation is forced.
5340 preferredRotation = mLidOpenRotation;
5341 } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR
Jeff Brownc0347aa2011-09-23 17:26:09 -07005342 && (mCarDockEnablesAccelerometer || mCarDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005343 // Ignore sensor when in car dock unless explicitly enabled.
5344 // This case can override the behavior of NOSENSOR, and can also
5345 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07005346 preferredRotation = mCarDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07005347 ? sensorRotation : mCarDockRotation;
Jeff Brown1a693182011-11-08 14:44:16 -08005348 } else if ((mDockMode == Intent.EXTRA_DOCK_STATE_DESK
5349 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
5350 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK)
Jeff Brownc0347aa2011-09-23 17:26:09 -07005351 && (mDeskDockEnablesAccelerometer || mDeskDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005352 // Ignore sensor when in desk dock unless explicitly enabled.
5353 // This case can override the behavior of NOSENSOR, and can also
5354 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07005355 preferredRotation = mDeskDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07005356 ? sensorRotation : mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -07005357 } else if (mHdmiPlugged && mDemoHdmiRotationLock) {
5358 // Ignore sensor when plugged into HDMI when demo HDMI rotation lock enabled.
Jeff Browneb3e4b92011-12-06 19:54:24 -08005359 // Note that the dock orientation overrides the HDMI orientation.
Jeff Brownc82c89ed2013-04-17 17:18:15 -07005360 preferredRotation = mDemoHdmiRotation;
5361 } else if (mHdmiPlugged && mDockMode == Intent.EXTRA_DOCK_STATE_UNDOCKED
5362 && mUndockedHdmiRotation >= 0) {
5363 // Ignore sensor when plugged into HDMI and an undocked orientation has
5364 // been specified in the configuration (only for legacy devices without
5365 // full multi-display support).
5366 // Note that the dock orientation overrides the HDMI orientation.
5367 preferredRotation = mUndockedHdmiRotation;
Chong Zhangae6119ff2014-11-11 18:54:39 -08005368 } else if (mDemoRotationLock) {
5369 // Ignore sensor when demo rotation lock is enabled.
5370 // Note that the dock orientation and HDMI rotation lock override this.
5371 preferredRotation = mDemoRotation;
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005372 } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED) {
5373 // Application just wants to remain locked in the last rotation.
5374 preferredRotation = lastRotation;
Jeff Brownbcdfc622014-03-06 19:13:04 -08005375 } else if (!mSupportAutoRotation) {
5376 // If we don't support auto-rotation then bail out here and ignore
5377 // the sensor and any rotation lock settings.
5378 preferredRotation = -1;
Jeff Brown207673cd2012-06-05 17:47:11 -07005379 } else if ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE
Jeff Brown01a98dd2011-09-20 15:08:29 -07005380 && (orientation == ActivityInfo.SCREEN_ORIENTATION_USER
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005381 || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
5382 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
5383 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
5384 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER))
Jeff Brown01a98dd2011-09-20 15:08:29 -07005385 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
5386 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
5387 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
5388 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) {
5389 // Otherwise, use sensor only if requested by the application or enabled
5390 // by default for USER or UNSPECIFIED modes. Does not apply to NOSENSOR.
Jeff Brownd3187e32011-09-21 19:26:44 -07005391 if (mAllowAllRotations < 0) {
5392 // Can't read this during init() because the context doesn't
5393 // have display metrics at that time so we cannot determine
5394 // tablet vs. phone then.
5395 mAllowAllRotations = mContext.getResources().getBoolean(
5396 com.android.internal.R.bool.config_allowAllRotations) ? 1 : 0;
5397 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005398 if (sensorRotation != Surface.ROTATION_180
Jeff Brownd3187e32011-09-21 19:26:44 -07005399 || mAllowAllRotations == 1
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005400 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
5401 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005402 preferredRotation = sensorRotation;
5403 } else {
5404 preferredRotation = lastRotation;
5405 }
Jeff Brown207673cd2012-06-05 17:47:11 -07005406 } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED
5407 && orientation != ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) {
5408 // Apply rotation lock. Does not apply to NOSENSOR.
5409 // The idea is that the user rotation expresses a weak preference for the direction
5410 // of gravity and as NOSENSOR is never affected by gravity, then neither should
5411 // NOSENSOR be affected by rotation lock (although it will be affected by docks).
Jeff Brown4dfce202011-10-05 12:00:10 -07005412 preferredRotation = mUserRotation;
Jeff Browndec6cf42011-11-15 14:08:20 -08005413 } else {
5414 // No overriding preference.
5415 // We will do exactly what the application asked us to do.
5416 preferredRotation = -1;
Jeff Brown01a98dd2011-09-20 15:08:29 -07005417 }
5418
Dianne Hackborne5439f22010-10-02 16:53:50 -07005419 switch (orientation) {
5420 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08005421 // Return portrait unless overridden.
5422 if (isAnyPortrait(preferredRotation)) {
5423 return preferredRotation;
5424 }
Dianne Hackborne5439f22010-10-02 16:53:50 -07005425 return mPortraitRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005426
Jeff Brown01a98dd2011-09-20 15:08:29 -07005427 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08005428 // Return landscape unless overridden.
5429 if (isLandscapeOrSeascape(preferredRotation)) {
5430 return preferredRotation;
5431 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005432 return mLandscapeRotation;
5433
5434 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08005435 // Return reverse portrait unless overridden.
5436 if (isAnyPortrait(preferredRotation)) {
5437 return preferredRotation;
5438 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005439 return mUpsideDownRotation;
5440
5441 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08005442 // Return seascape unless overridden.
5443 if (isLandscapeOrSeascape(preferredRotation)) {
5444 return preferredRotation;
5445 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005446 return mSeascapeRotation;
5447
5448 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005449 case ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE:
Jeff Brown01a98dd2011-09-20 15:08:29 -07005450 // Return either landscape rotation.
5451 if (isLandscapeOrSeascape(preferredRotation)) {
5452 return preferredRotation;
5453 }
5454 if (isLandscapeOrSeascape(lastRotation)) {
Jeff Brown4519f072011-01-23 13:16:01 -08005455 return lastRotation;
5456 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005457 return mLandscapeRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005458
Jeff Brown01a98dd2011-09-20 15:08:29 -07005459 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005460 case ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT:
Jeff Brown01a98dd2011-09-20 15:08:29 -07005461 // Return either portrait rotation.
5462 if (isAnyPortrait(preferredRotation)) {
5463 return preferredRotation;
5464 }
5465 if (isAnyPortrait(lastRotation)) {
5466 return lastRotation;
5467 }
5468 return mPortraitRotation;
5469
5470 default:
Jeff Brown4dfce202011-10-05 12:00:10 -07005471 // For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR,
5472 // just return the preferred orientation we already calculated.
Jeff Brown01a98dd2011-09-20 15:08:29 -07005473 if (preferredRotation >= 0) {
5474 return preferredRotation;
5475 }
Dianne Hackborndacea8c2011-04-21 17:26:39 -07005476 return Surface.ROTATION_0;
Daniel Sandlere7e5ac22011-02-22 16:10:21 -05005477 }
5478 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07005479 }
5480
Jeff Brown01a98dd2011-09-20 15:08:29 -07005481 @Override
5482 public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation) {
5483 switch (orientation) {
5484 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
5485 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
5486 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
5487 return isAnyPortrait(rotation);
5488
5489 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
5490 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
5491 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
5492 return isLandscapeOrSeascape(rotation);
5493
5494 default:
5495 return true;
5496 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07005497 }
5498
Jeff Brownc0347aa2011-09-23 17:26:09 -07005499 @Override
5500 public void setRotationLw(int rotation) {
5501 mOrientationListener.setCurrentRotation(rotation);
5502 }
5503
Jeff Brown01a98dd2011-09-20 15:08:29 -07005504 private boolean isLandscapeOrSeascape(int rotation) {
5505 return rotation == mLandscapeRotation || rotation == mSeascapeRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005506 }
5507
Jeff Brown01a98dd2011-09-20 15:08:29 -07005508 private boolean isAnyPortrait(int rotation) {
5509 return rotation == mPortraitRotation || rotation == mUpsideDownRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005510 }
5511
Jose Lima9546b202014-07-02 17:21:51 -07005512 @Override
Svetoslav Ganov80943d82013-01-02 10:25:37 -08005513 public int getUserRotationMode() {
5514 return Settings.System.getIntForUser(mContext.getContentResolver(),
Brett Chabot7e55c402013-05-16 19:38:08 -07005515 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
5516 WindowManagerPolicy.USER_ROTATION_FREE :
5517 WindowManagerPolicy.USER_ROTATION_LOCKED;
Svetoslav Ganov80943d82013-01-02 10:25:37 -08005518 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005519
5520 // User rotation: to be used when all else fails in assigning an orientation to the device
Jose Lima9546b202014-07-02 17:21:51 -07005521 @Override
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005522 public void setUserRotationMode(int mode, int rot) {
5523 ContentResolver res = mContext.getContentResolver();
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005524
5525 // mUserRotationMode and mUserRotation will be assigned by the content observer
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005526 if (mode == WindowManagerPolicy.USER_ROTATION_LOCKED) {
Christopher Tate5e08af02012-09-21 17:17:22 -07005527 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005528 Settings.System.USER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005529 rot,
5530 UserHandle.USER_CURRENT);
5531 Settings.System.putIntForUser(res,
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005532 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005533 0,
5534 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005535 } else {
Christopher Tate5e08af02012-09-21 17:17:22 -07005536 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005537 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005538 1,
5539 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005540 }
5541 }
5542
Jose Lima9546b202014-07-02 17:21:51 -07005543 @Override
Jeff Brownac143512012-04-05 18:57:33 -07005544 public void setSafeMode(boolean safeMode) {
5545 mSafeMode = safeMode;
5546 performHapticFeedbackLw(null, safeMode
5547 ? HapticFeedbackConstants.SAFE_MODE_ENABLED
5548 : HapticFeedbackConstants.SAFE_MODE_DISABLED, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005549 }
Craig Mautnereda67292013-04-28 13:50:14 -07005550
Dianne Hackborn181ceb52009-08-27 22:16:40 -07005551 static long[] getLongIntArray(Resources r, int resid) {
5552 int[] ar = r.getIntArray(resid);
5553 if (ar == null) {
5554 return null;
5555 }
5556 long[] out = new long[ar.length];
5557 for (int i=0; i<ar.length; i++) {
5558 out[i] = ar[i];
5559 }
5560 return out;
5561 }
Craig Mautnereda67292013-04-28 13:50:14 -07005562
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005563 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07005564 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005565 public void systemReady() {
Jim Millerab954542014-10-10 18:21:49 -07005566 mKeyguardDelegate = new KeyguardServiceDelegate(mContext);
Mike Lockwooded8902d2013-11-15 11:01:47 -08005567 mKeyguardDelegate.onSystemReady();
5568
Michael Wright3818c922014-09-02 13:59:07 -07005569 readCameraLensCoverState();
Jeff Brown4f5fa282014-06-12 19:19:15 -07005570 updateUiMode();
Dianne Hackbornb1a79802009-09-29 15:18:31 -07005571 synchronized (mLock) {
5572 updateOrientationListenerLp();
Dianne Hackbornc777e072010-02-12 13:07:59 -08005573 mSystemReady = true;
5574 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07005575 @Override
Dianne Hackbornc777e072010-02-12 13:07:59 -08005576 public void run() {
5577 updateSettings();
5578 }
5579 });
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005580 }
5581 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07005582
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005583 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005584 @Override
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005585 public void systemBooted() {
Jim Millere5f910a2013-10-16 18:15:46 -07005586 if (mKeyguardDelegate != null) {
Jason Monk5eeebf52014-09-26 12:36:51 -04005587 mKeyguardDelegate.bindService(mContext);
Jim Millere5f910a2013-10-16 18:15:46 -07005588 mKeyguardDelegate.onBootCompleted();
5589 }
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005590 synchronized (mLock) {
5591 mSystemBooted = true;
5592 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005593 wakingUp();
5594 screenTurningOn(null);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005595 }
5596
Dianne Hackborn661cd522011-08-22 00:26:20 -07005597 ProgressDialog mBootMsgDialog = null;
5598
5599 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005600 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07005601 public void showBootMessage(final CharSequence msg, final boolean always) {
5602 mHandler.post(new Runnable() {
5603 @Override public void run() {
5604 if (mBootMsgDialog == null) {
Craig Stout4c0cb8a2014-04-04 13:03:10 -07005605 int theme;
5606 if (mContext.getPackageManager().hasSystemFeature(
5607 PackageManager.FEATURE_WATCH)) {
5608 theme = com.android.internal.R.style.Theme_Micro_Dialog_Alert;
5609 } else if (mContext.getPackageManager().hasSystemFeature(
5610 PackageManager.FEATURE_TELEVISION)) {
5611 theme = com.android.internal.R.style.Theme_Leanback_Dialog_Alert;
5612 } else {
5613 theme = 0;
5614 }
Vinod Krishnanfa8fc412014-04-18 14:35:53 -07005615
5616 mBootMsgDialog = new ProgressDialog(mContext, theme) {
Dianne Hackborn295e3c22011-08-25 13:19:08 -07005617 // This dialog will consume all events coming in to
5618 // it, to avoid it trying to do things too early in boot.
5619 @Override public boolean dispatchKeyEvent(KeyEvent event) {
5620 return true;
5621 }
5622 @Override public boolean dispatchKeyShortcutEvent(KeyEvent event) {
5623 return true;
5624 }
5625 @Override public boolean dispatchTouchEvent(MotionEvent ev) {
5626 return true;
5627 }
5628 @Override public boolean dispatchTrackballEvent(MotionEvent ev) {
5629 return true;
5630 }
5631 @Override public boolean dispatchGenericMotionEvent(MotionEvent ev) {
5632 return true;
5633 }
5634 @Override public boolean dispatchPopulateAccessibilityEvent(
5635 AccessibilityEvent event) {
5636 return true;
5637 }
5638 };
Jeff Hao9f60c082014-10-28 18:51:07 -07005639 if (mContext.getPackageManager().isUpgrade()) {
5640 mBootMsgDialog.setTitle(R.string.android_upgrading_title);
5641 } else {
5642 mBootMsgDialog.setTitle(R.string.android_start_title);
5643 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07005644 mBootMsgDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
5645 mBootMsgDialog.setIndeterminate(true);
5646 mBootMsgDialog.getWindow().setType(
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07005647 WindowManager.LayoutParams.TYPE_BOOT_PROGRESS);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005648 mBootMsgDialog.getWindow().addFlags(
5649 WindowManager.LayoutParams.FLAG_DIM_BEHIND
5650 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
5651 mBootMsgDialog.getWindow().setDimAmount(1);
Dianne Hackbornd9efb952011-12-07 14:56:51 -08005652 WindowManager.LayoutParams lp = mBootMsgDialog.getWindow().getAttributes();
5653 lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
5654 mBootMsgDialog.getWindow().setAttributes(lp);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005655 mBootMsgDialog.setCancelable(false);
5656 mBootMsgDialog.show();
5657 }
5658 mBootMsgDialog.setMessage(msg);
5659 }
5660 });
5661 }
5662
5663 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005664 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07005665 public void hideBootMessages() {
Craig Mautnera631d492014-08-05 15:16:01 -07005666 mHandler.sendEmptyMessage(MSG_HIDE_BOOT_MESSAGE);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005667 }
5668
Mike Lockwood28569302010-01-28 11:54:40 -05005669 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005670 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05005671 public void userActivity() {
Dianne Hackborndf89e652011-10-06 22:35:11 -07005672 // ***************************************
5673 // NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
5674 // ***************************************
5675 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
5676 // WITH ITS LOCKS HELD.
5677 //
5678 // This code must be VERY careful about the locks
5679 // it acquires.
5680 // In fact, the current code acquires way too many,
5681 // and probably has lurking deadlocks.
5682
Mike Lockwood28569302010-01-28 11:54:40 -05005683 synchronized (mScreenLockTimeout) {
5684 if (mLockScreenTimerActive) {
5685 // reset the timer
5686 mHandler.removeCallbacks(mScreenLockTimeout);
5687 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
5688 }
5689 }
Daniel Sandler0601eb72011-04-13 01:01:32 -04005690 }
5691
Adam Cohenf7522022012-10-03 20:03:18 -07005692 class ScreenLockTimeout implements Runnable {
5693 Bundle options;
5694
5695 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05005696 public void run() {
5697 synchronized (this) {
5698 if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard");
Jim Miller5ecd8112013-01-09 18:50:26 -08005699 if (mKeyguardDelegate != null) {
5700 mKeyguardDelegate.doKeyguardTimeout(options);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005701 }
Mike Lockwood28569302010-01-28 11:54:40 -05005702 mLockScreenTimerActive = false;
Adam Cohenf7522022012-10-03 20:03:18 -07005703 options = null;
Mike Lockwood28569302010-01-28 11:54:40 -05005704 }
5705 }
Mike Lockwood28569302010-01-28 11:54:40 -05005706
Adam Cohenf7522022012-10-03 20:03:18 -07005707 public void setLockOptions(Bundle options) {
5708 this.options = options;
5709 }
5710 }
5711
5712 ScreenLockTimeout mScreenLockTimeout = new ScreenLockTimeout();
5713
Jose Lima9546b202014-07-02 17:21:51 -07005714 @Override
Adam Cohenf7522022012-10-03 20:03:18 -07005715 public void lockNow(Bundle options) {
Jim Miller93c518e2012-01-17 15:55:31 -08005716 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null);
5717 mHandler.removeCallbacks(mScreenLockTimeout);
Adam Cohenf7522022012-10-03 20:03:18 -07005718 if (options != null) {
5719 // In case multiple calls are made to lockNow, we don't wipe out the options
5720 // until the runnable actually executes.
5721 mScreenLockTimeout.setLockOptions(options);
5722 }
Jim Miller93c518e2012-01-17 15:55:31 -08005723 mHandler.post(mScreenLockTimeout);
5724 }
5725
Mike Lockwood28569302010-01-28 11:54:40 -05005726 private void updateLockScreenTimeout() {
5727 synchronized (mScreenLockTimeout) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005728 boolean enable = (mAllowLockscreenWhenOn && mAwake &&
Jim Miller5ecd8112013-01-09 18:50:26 -08005729 mKeyguardDelegate != null && mKeyguardDelegate.isSecure());
Mike Lockwood28569302010-01-28 11:54:40 -05005730 if (mLockScreenTimerActive != enable) {
5731 if (enable) {
5732 if (localLOGV) Log.v(TAG, "setting lockscreen timer");
5733 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
5734 } else {
5735 if (localLOGV) Log.v(TAG, "clearing lockscreen timer");
5736 mHandler.removeCallbacks(mScreenLockTimeout);
5737 }
5738 mLockScreenTimerActive = enable;
5739 }
5740 }
5741 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005742
5743 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07005744 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005745 public void enableScreenAfterBoot() {
5746 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07005747 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07005748 updateRotation(true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005749 }
Dianne Hackbornf54c8f92009-09-19 14:03:57 -07005750
Jeff Brownc458ce92012-04-30 14:58:40 -07005751 private void applyLidSwitchState() {
Jeff Brownc458ce92012-04-30 14:58:40 -07005752 if (mLidState == LID_CLOSED && mLidControlsSleep) {
Jeff Brown6d8fd272014-05-20 21:24:38 -07005753 mPowerManager.goToSleep(SystemClock.uptimeMillis(),
Jeff Brownc12035c2014-08-13 18:52:25 -07005754 PowerManager.GO_TO_SLEEP_REASON_LID_SWITCH,
Jeff Brown6d8fd272014-05-20 21:24:38 -07005755 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
Jeff Brownc458ce92012-04-30 14:58:40 -07005756 }
Jeff Browna20dda42014-05-27 20:57:24 -07005757
5758 synchronized (mLock) {
5759 updateWakeGestureListenerLp();
5760 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005761 }
5762
Jeff Brown4f5fa282014-06-12 19:19:15 -07005763 void updateUiMode() {
5764 if (mUiModeManager == null) {
5765 mUiModeManager = IUiModeManager.Stub.asInterface(
5766 ServiceManager.getService(Context.UI_MODE_SERVICE));
5767 }
5768 try {
5769 mUiMode = mUiModeManager.getCurrentModeType();
5770 } catch (RemoteException e) {
5771 }
5772 }
5773
Jeff Brown01a98dd2011-09-20 15:08:29 -07005774 void updateRotation(boolean alwaysSendConfiguration) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005775 try {
5776 //set orientation on WindowManager
Dianne Hackbornf87d1962012-04-04 12:48:24 -07005777 mWindowManager.updateRotation(alwaysSendConfiguration, false);
5778 } catch (RemoteException e) {
5779 // Ignore
5780 }
5781 }
5782
5783 void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) {
5784 try {
5785 //set orientation on WindowManager
5786 mWindowManager.updateRotation(alwaysSendConfiguration, forceRelayout);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005787 } catch (RemoteException e) {
5788 // Ignore
5789 }
5790 }
5791
Daniel Sandler6396c722013-04-16 20:19:09 -04005792 /**
5793 * Return an Intent to launch the currently active dock app as home. Returns
5794 * null if the standard home should be launched, which is the case if any of the following is
5795 * true:
5796 * <ul>
5797 * <li>The device is not in either car mode or desk mode
5798 * <li>The device is in car mode but ENABLE_CAR_DOCK_HOME_CAPTURE is false
5799 * <li>The device is in desk mode but ENABLE_DESK_DOCK_HOME_CAPTURE is false
5800 * <li>The device is in car mode but there's no CAR_DOCK app with METADATA_DOCK_HOME
5801 * <li>The device is in desk mode but there's no DESK_DOCK app with METADATA_DOCK_HOME
5802 * </ul>
Craig Mautnereda67292013-04-28 13:50:14 -07005803 * @return A dock intent.
Daniel Sandler6396c722013-04-16 20:19:09 -04005804 */
5805 Intent createHomeDockIntent() {
5806 Intent intent = null;
5807
5808 // What home does is based on the mode, not the dock state. That
5809 // is, when in car mode you should be taken to car home regardless
5810 // of whether we are actually in a car dock.
5811 if (mUiMode == Configuration.UI_MODE_TYPE_CAR) {
5812 if (ENABLE_CAR_DOCK_HOME_CAPTURE) {
5813 intent = mCarDockIntent;
5814 }
5815 } else if (mUiMode == Configuration.UI_MODE_TYPE_DESK) {
5816 if (ENABLE_DESK_DOCK_HOME_CAPTURE) {
5817 intent = mDeskDockIntent;
5818 }
Jeff Brown4f5fa282014-06-12 19:19:15 -07005819 } else if (mUiMode == Configuration.UI_MODE_TYPE_WATCH
5820 && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
5821 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK
5822 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK)) {
5823 // Always launch dock home from home when watch is docked, if it exists.
5824 intent = mDeskDockIntent;
Daniel Sandler6396c722013-04-16 20:19:09 -04005825 }
5826
5827 if (intent == null) {
5828 return null;
5829 }
5830
5831 ActivityInfo ai = null;
5832 ResolveInfo info = mContext.getPackageManager().resolveActivityAsUser(
5833 intent,
John Spurlockf56bef12013-07-09 09:51:46 -04005834 PackageManager.MATCH_DEFAULT_ONLY | PackageManager.GET_META_DATA,
Craig Mautnerd625ab22013-09-06 13:40:31 -07005835 mCurrentUserId);
Daniel Sandler6396c722013-04-16 20:19:09 -04005836 if (info != null) {
5837 ai = info.activityInfo;
5838 }
5839 if (ai != null
5840 && ai.metaData != null
5841 && ai.metaData.getBoolean(Intent.METADATA_DOCK_HOME)) {
5842 intent = new Intent(intent);
5843 intent.setClassName(ai.packageName, ai.name);
5844 return intent;
5845 }
5846
5847 return null;
5848 }
5849
Bryce Lee01b0c5f2015-02-05 18:24:04 -08005850 void startDockOrHome(boolean fromHomeKey) {
John Spurlockc8b46ca2013-04-08 12:59:26 -04005851 awakenDreams();
Daniel Sandler6396c722013-04-16 20:19:09 -04005852
5853 Intent dock = createHomeDockIntent();
5854 if (dock != null) {
5855 try {
Bryce Lee01b0c5f2015-02-05 18:24:04 -08005856 if (fromHomeKey) {
5857 dock.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
5858 }
Daniel Sandler6396c722013-04-16 20:19:09 -04005859 mContext.startActivityAsUser(dock, UserHandle.CURRENT);
5860 return;
5861 } catch (ActivityNotFoundException e) {
5862 }
5863 }
5864
Bryce Lee01b0c5f2015-02-05 18:24:04 -08005865 Intent intent;
5866
5867 if (fromHomeKey) {
5868 intent = new Intent(mHomeIntent);
5869 intent.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
5870 } else {
5871 intent = mHomeIntent;
5872 }
5873
5874 mContext.startActivityAsUser(intent, UserHandle.CURRENT);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005875 }
Craig Mautnereda67292013-04-28 13:50:14 -07005876
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005877 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005878 * goes to the home screen
5879 * @return whether it did anything
5880 */
5881 boolean goHome() {
5882 if (false) {
5883 // This code always brings home to the front.
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07005884 try {
5885 ActivityManagerNative.getDefault().stopAppSwitches();
5886 } catch (RemoteException e) {
5887 }
Dianne Hackborn94a679d2009-07-28 17:51:07 -07005888 sendCloseSystemWindows();
Bryce Lee01b0c5f2015-02-05 18:24:04 -08005889 startDockOrHome(false /*fromHomeKey*/);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005890 } else {
5891 // This code brings home to the front or, if it is already
5892 // at the front, puts the device to sleep.
5893 try {
Wink Savilled2e6a332010-02-12 12:12:06 -08005894 if (SystemProperties.getInt("persist.sys.uts-test-mode", 0) == 1) {
5895 /// Roll back EndcallBehavior as the cupcake design to pass P1 lab entry.
5896 Log.d(TAG, "UTS-TEST-MODE");
5897 } else {
5898 ActivityManagerNative.getDefault().stopAppSwitches();
5899 sendCloseSystemWindows();
Daniel Sandler6396c722013-04-16 20:19:09 -04005900 Intent dock = createHomeDockIntent();
5901 if (dock != null) {
5902 int result = ActivityManagerNative.getDefault()
5903 .startActivityAsUser(null, null, dock,
5904 dock.resolveTypeIfNeeded(mContext.getContentResolver()),
5905 null, null, 0,
5906 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07005907 null, null, UserHandle.USER_CURRENT);
Daniel Sandler6396c722013-04-16 20:19:09 -04005908 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
5909 return false;
5910 }
5911 }
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005912 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005913 int result = ActivityManagerNative.getDefault()
Dianne Hackbornf265ea92013-01-31 15:00:51 -08005914 .startActivityAsUser(null, null, mHomeIntent,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005915 mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()),
Dianne Hackborna4972e92012-03-14 10:38:05 -07005916 null, null, 0,
5917 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07005918 null, null, UserHandle.USER_CURRENT);
Dianne Hackborna4972e92012-03-14 10:38:05 -07005919 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005920 return false;
5921 }
5922 } catch (RemoteException ex) {
5923 // bummer, the activity manager, which is in this process, is dead
5924 }
5925 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005926 return true;
5927 }
Craig Mautnereda67292013-04-28 13:50:14 -07005928
5929 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07005930 public void setCurrentOrientationLw(int newOrientation) {
5931 synchronized (mLock) {
5932 if (newOrientation != mCurrentAppOrientation) {
5933 mCurrentAppOrientation = newOrientation;
5934 updateOrientationListenerLp();
5935 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005936 }
5937 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08005938
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07005939 private void performAuditoryFeedbackForAccessibilityIfNeed() {
5940 if (!isGlobalAccessibilityGestureEnabled()) {
5941 return;
5942 }
5943 AudioManager audioManager = (AudioManager) mContext.getSystemService(
5944 Context.AUDIO_SERVICE);
5945 if (audioManager.isSilentMode()) {
5946 return;
5947 }
5948 Ringtone ringTone = RingtoneManager.getRingtone(mContext,
5949 Settings.System.DEFAULT_NOTIFICATION_URI);
5950 ringTone.setStreamType(AudioManager.STREAM_MUSIC);
5951 ringTone.play();
5952 }
Craig Mautnereda67292013-04-28 13:50:14 -07005953
Bryce Lee584a4452014-10-21 15:55:55 -07005954 private boolean isTheaterModeEnabled() {
5955 return Settings.Global.getInt(mContext.getContentResolver(),
5956 Settings.Global.THEATER_MODE_ON, 0) == 1;
5957 }
5958
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07005959 private boolean isGlobalAccessibilityGestureEnabled() {
5960 return Settings.Global.getInt(mContext.getContentResolver(),
5961 Settings.Global.ENABLE_ACCESSIBILITY_GLOBAL_GESTURE_ENABLED, 0) == 1;
5962 }
5963
Craig Mautnereda67292013-04-28 13:50:14 -07005964 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07005965 public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) {
Svetoslav Ganov96179212012-10-10 14:17:45 -07005966 if (!mVibrator.hasVibrator()) {
5967 return false;
5968 }
Christopher Tate5e08af02012-09-21 17:17:22 -07005969 final boolean hapticsDisabled = Settings.System.getIntForUser(mContext.getContentResolver(),
5970 Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) == 0;
Jeff Brown82379ba2014-07-25 19:03:28 -07005971 if (hapticsDisabled && !always) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005972 return false;
5973 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08005974 long[] pattern = null;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005975 switch (effectId) {
5976 case HapticFeedbackConstants.LONG_PRESS:
Amith Yamasanic33cb712010-02-10 15:21:49 -08005977 pattern = mLongPressVibePattern;
5978 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07005979 case HapticFeedbackConstants.VIRTUAL_KEY:
Amith Yamasanic33cb712010-02-10 15:21:49 -08005980 pattern = mVirtualKeyVibePattern;
5981 break;
5982 case HapticFeedbackConstants.KEYBOARD_TAP:
5983 pattern = mKeyboardTapVibePattern;
5984 break;
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07005985 case HapticFeedbackConstants.CLOCK_TICK:
5986 pattern = mClockTickVibePattern;
5987 break;
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07005988 case HapticFeedbackConstants.CALENDAR_DATE:
5989 pattern = mCalendarDateVibePattern;
5990 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07005991 case HapticFeedbackConstants.SAFE_MODE_DISABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08005992 pattern = mSafeModeDisabledVibePattern;
5993 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07005994 case HapticFeedbackConstants.SAFE_MODE_ENABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08005995 pattern = mSafeModeEnabledVibePattern;
5996 break;
Amith Yamasanic33cb712010-02-10 15:21:49 -08005997 default:
5998 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005999 }
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006000 int owningUid;
6001 String owningPackage;
6002 if (win != null) {
6003 owningUid = win.getOwningUid();
6004 owningPackage = win.getOwningPackage();
6005 } else {
6006 owningUid = android.os.Process.myUid();
Dianne Hackborn95d78532013-09-11 09:51:14 -07006007 owningPackage = mContext.getOpPackageName();
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006008 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006009 if (pattern.length == 1) {
6010 // One-shot vibration
John Spurlock7b414672014-07-18 13:02:39 -04006011 mVibrator.vibrate(owningUid, owningPackage, pattern[0], VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08006012 } else {
6013 // Pattern vibration
John Spurlock7b414672014-07-18 13:02:39 -04006014 mVibrator.vibrate(owningUid, owningPackage, pattern, -1, VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08006015 }
6016 return true;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006017 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07006018
6019 @Override
6020 public void keepScreenOnStartedLw() {
Daniel Sandler0601eb72011-04-13 01:01:32 -04006021 }
6022
Jeff Brownc38c9be2012-10-04 13:16:19 -07006023 @Override
6024 public void keepScreenOnStoppedLw() {
Jim Millerab954542014-10-10 18:21:49 -07006025 if (isKeyguardShowingAndNotOccluded()) {
Jim Miller25190572013-02-28 17:36:24 -08006026 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006027 }
6028 }
Mike Lockwoodfcb39242009-10-21 23:01:07 -04006029
Dianne Hackborndf89e652011-10-06 22:35:11 -07006030 private int updateSystemUiVisibilityLw() {
Joe Onorato664644d2011-01-23 17:53:23 -08006031 // If there is no window focused, there will be nobody to handle the events
6032 // anyway, so just hang on in whatever state we're in until things settle down.
Adrian Roos53f28ec2014-10-29 17:26:12 +01006033 final WindowState win = mFocusedWindow != null ? mFocusedWindow
6034 : mTopFullscreenOpaqueWindowState;
John Spurlock79da8332013-09-20 12:04:47 -04006035 if (win == null) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006036 return 0;
6037 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01006038 if ((win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 && mHideLockScreen == true) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07006039 // We are updating at a point where the keyguard has gotten
6040 // focus, but we were last in a state where the top window is
6041 // hiding it. This is probably because the keyguard as been
6042 // shown while the top window was displayed, so we want to ignore
6043 // it here because this is just a very transient change and it
6044 // will quickly lose focus once it correctly gets hidden.
6045 return 0;
6046 }
John Spurlock32beb2c2013-03-11 10:16:47 -04006047
John Spurlock1db8b682014-02-18 11:18:59 -05006048 int tmpVisibility = PolicyControl.getSystemUiVisibility(win, null)
Dianne Hackborne26ab702011-10-16 13:21:33 -07006049 & ~mResettingSystemUiFlags
6050 & ~mForceClearedSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04006051 if (mForcingShowNavBar && win.getSurfaceLayer() < mForcingShowNavBarLayer) {
John Spurlockc6d1c602014-01-17 15:22:06 -05006052 tmpVisibility &= ~PolicyControl.adjustClearableFlags(win, View.SYSTEM_UI_CLEARABLE_FLAGS);
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08006053 }
John Spurlock79da8332013-09-20 12:04:47 -04006054 final int visibility = updateSystemBarsLw(win, mLastSystemUiFlags, tmpVisibility);
John Spurlockad3e6cb2013-04-30 08:47:43 -04006055 final int diff = visibility ^ mLastSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04006056 final boolean needsMenu = win.getNeedsMenuLw(mTopFullscreenOpaqueWindowState);
Dianne Hackborne0f085d2011-11-30 18:41:15 -08006057 if (diff == 0 && mLastFocusNeedsMenu == needsMenu
John Spurlock79da8332013-09-20 12:04:47 -04006058 && mFocusedApp == win.getAppToken()) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006059 return 0;
6060 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07006061 mLastSystemUiFlags = visibility;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08006062 mLastFocusNeedsMenu = needsMenu;
John Spurlock79da8332013-09-20 12:04:47 -04006063 mFocusedApp = win.getAppToken();
Dianne Hackborndf89e652011-10-06 22:35:11 -07006064 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07006065 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07006066 public void run() {
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006067 try {
6068 IStatusBarService statusbar = getStatusBarService();
6069 if (statusbar != null) {
Adrian Roos53f28ec2014-10-29 17:26:12 +01006070 statusbar.setSystemUiVisibility(visibility, 0xffffffff, win.toString());
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006071 statusbar.topAppWindowChanged(needsMenu);
Joe Onorato664644d2011-01-23 17:53:23 -08006072 }
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006073 } catch (RemoteException e) {
6074 // re-acquire status bar service next time it is needed.
6075 mStatusBarService = null;
Joe Onorato664644d2011-01-23 17:53:23 -08006076 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07006077 }
6078 });
6079 return diff;
Joe Onorato664644d2011-01-23 17:53:23 -08006080 }
6081
John Spurlock79da8332013-09-20 12:04:47 -04006082 private int updateSystemBarsLw(WindowState win, int oldVis, int vis) {
John Spurlockbd957402013-10-03 11:38:39 -04006083 // apply translucent bar vis flags
Jorim Jaggi380ecb82014-03-14 17:25:20 +01006084 WindowState transWin = isStatusBarKeyguard() && !mHideLockScreen
6085 ? mStatusBar
John Spurlockbd957402013-10-03 11:38:39 -04006086 : mTopFullscreenOpaqueWindowState;
6087 vis = mStatusBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
6088 vis = mNavigationBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
6089
John Spurlock27735a42013-08-14 17:57:38 -04006090 // prevent status bar interaction from clearing certain flags
John Spurlock79da8332013-09-20 12:04:47 -04006091 boolean statusBarHasFocus = win.getAttrs().type == TYPE_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04006092 if (statusBarHasFocus && !isStatusBarKeyguard()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04006093 int flags = View.SYSTEM_UI_FLAG_FULLSCREEN
6094 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlockcfc359a2013-09-05 10:42:03 -04006095 | View.SYSTEM_UI_FLAG_IMMERSIVE
Jorim Jaggi73fef8d2015-02-16 17:32:28 +01006096 | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
6097 | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04006098 if (mHideLockScreen) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01006099 flags |= View.STATUS_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSLUCENT;
6100 }
John Spurlockbd957402013-10-03 11:38:39 -04006101 vis = (vis & ~flags) | (oldVis & flags);
John Spurlockad3e6cb2013-04-30 08:47:43 -04006102 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04006103
Adrian Roos4fb3ee32014-08-22 19:29:09 +02006104 if (!areTranslucentBarsAllowed() && transWin != mStatusBar) {
Adrian Roosea562512014-05-05 13:33:03 +02006105 vis &= ~(View.NAVIGATION_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSLUCENT
6106 | View.SYSTEM_UI_TRANSPARENT);
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006107 }
6108
John Spurlock27735a42013-08-14 17:57:38 -04006109 // update status bar
John Spurlockf1a36642013-10-12 17:50:42 -04006110 boolean immersiveSticky =
6111 (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
John Spurlock27735a42013-08-14 17:57:38 -04006112 boolean hideStatusBarWM =
John Spurlockbd957402013-10-03 11:38:39 -04006113 mTopFullscreenOpaqueWindowState != null &&
John Spurlockc6d1c602014-01-17 15:22:06 -05006114 (PolicyControl.getWindowFlags(mTopFullscreenOpaqueWindowState, null)
John Spurlock27735a42013-08-14 17:57:38 -04006115 & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0;
6116 boolean hideStatusBarSysui =
6117 (vis & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04006118 boolean hideNavBarSysui =
6119 (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006120
John Spurlock27735a42013-08-14 17:57:38 -04006121 boolean transientStatusBarAllowed =
6122 mStatusBar != null && (
6123 hideStatusBarWM
John Spurlockf1a36642013-10-12 17:50:42 -04006124 || (hideStatusBarSysui && immersiveSticky)
John Spurlock27735a42013-08-14 17:57:38 -04006125 || statusBarHasFocus);
6126
John Spurlockf1a36642013-10-12 17:50:42 -04006127 boolean transientNavBarAllowed =
6128 mNavigationBar != null &&
6129 hideNavBarSysui && immersiveSticky;
6130
John Spurlockf25706f2013-11-07 18:02:43 -05006131 boolean denyTransientStatus = mStatusBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04006132 && !transientStatusBarAllowed && hideStatusBarSysui;
John Spurlockf25706f2013-11-07 18:02:43 -05006133 boolean denyTransientNav = mNavigationBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04006134 && !transientNavBarAllowed;
6135 if (denyTransientStatus || denyTransientNav) {
John Spurlock27735a42013-08-14 17:57:38 -04006136 // clear the clearable flags instead
John Spurlockf1a36642013-10-12 17:50:42 -04006137 clearClearableFlagsLw();
tiger_huangc58d7562014-10-23 20:24:19 +08006138 vis &= ~View.SYSTEM_UI_CLEARABLE_FLAGS;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006139 }
John Spurlock27735a42013-08-14 17:57:38 -04006140
6141 vis = mStatusBarController.updateVisibilityLw(transientStatusBarAllowed, oldVis, vis);
6142
6143 // update navigation bar
John Spurlockf1a36642013-10-12 17:50:42 -04006144 boolean oldImmersiveMode = isImmersiveMode(oldVis);
6145 boolean newImmersiveMode = isImmersiveMode(vis);
6146 if (win != null && oldImmersiveMode != newImmersiveMode) {
John Spurlock79da8332013-09-20 12:04:47 -04006147 final String pkg = win.getOwningPackage();
Maurice Lam99c6e072014-04-28 18:24:28 -07006148 mImmersiveModeConfirmation.immersiveModeChanged(pkg, newImmersiveMode,
6149 isUserSetupComplete());
John Spurlock34e13d92013-08-10 06:52:28 -04006150 }
John Spurlock27735a42013-08-14 17:57:38 -04006151
John Spurlockf1a36642013-10-12 17:50:42 -04006152 vis = mNavigationBarController.updateVisibilityLw(transientNavBarAllowed, oldVis, vis);
6153
John Spurlocke1f366f2013-08-05 12:22:40 -04006154 return vis;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006155 }
6156
John Spurlockf1a36642013-10-12 17:50:42 -04006157 private void clearClearableFlagsLw() {
6158 int newVal = mResettingSystemUiFlags | View.SYSTEM_UI_CLEARABLE_FLAGS;
6159 if (newVal != mResettingSystemUiFlags) {
6160 mResettingSystemUiFlags = newVal;
6161 mWindowManagerFuncs.reevaluateStatusBarVisibility();
6162 }
6163 }
6164
6165 private boolean isImmersiveMode(int vis) {
6166 final int flags = View.SYSTEM_UI_FLAG_IMMERSIVE | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
John Spurlock34e13d92013-08-10 06:52:28 -04006167 return mNavigationBar != null
6168 && (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0
Daniel Sandler900ece52013-10-18 15:53:27 -04006169 && (vis & flags) != 0
6170 && canHideNavigationBar();
John Spurlock34e13d92013-08-10 06:52:28 -04006171 }
6172
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006173 /**
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04006174 * @return whether the navigation or status bar can be made translucent
6175 *
6176 * This should return true unless touch exploration is not enabled or
6177 * R.boolean.config_enableTranslucentDecor is false.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006178 */
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04006179 private boolean areTranslucentBarsAllowed() {
Svetoslav8e3feb12014-02-24 13:46:47 -08006180 return mTranslucentDecorEnabled
6181 && !mAccessibilityManager.isTouchExplorationEnabled();
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006182 }
6183
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04006184 // Use this instead of checking config_showNavigationBar so that it can be consistently
6185 // overridden by qemu.hw.mainkeys in the emulator.
Craig Mautnereda67292013-04-28 13:50:14 -07006186 @Override
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04006187 public boolean hasNavigationBar() {
6188 return mHasNavigationBar;
6189 }
6190
satok1bc0a492012-04-25 22:47:12 +09006191 @Override
6192 public void setLastInputMethodWindowLw(WindowState ime, WindowState target) {
6193 mLastInputMethodWindow = ime;
6194 mLastInputMethodTargetWindow = target;
6195 }
6196
Craig Mautnerf1b67412012-09-19 13:18:29 -07006197 @Override
Satoshi Kataoka658c7b82013-10-10 17:03:51 +09006198 public int getInputMethodWindowVisibleHeightLw() {
6199 return mDockBottom - mCurBottom;
6200 }
6201
6202 @Override
Craig Mautnerf1b67412012-09-19 13:18:29 -07006203 public void setCurrentUserLw(int newUserId) {
Craig Mautnerd625ab22013-09-06 13:40:31 -07006204 mCurrentUserId = newUserId;
Jim Miller5ecd8112013-01-09 18:50:26 -08006205 if (mKeyguardDelegate != null) {
6206 mKeyguardDelegate.setCurrentUser(newUserId);
Craig Mautnerf1b67412012-09-19 13:18:29 -07006207 }
John Spurlock13451a22012-09-28 14:40:41 -04006208 if (mStatusBarService != null) {
6209 try {
6210 mStatusBarService.setCurrentUser(newUserId);
6211 } catch (RemoteException e) {
6212 // oh well
6213 }
6214 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006215 setLastInputMethodWindowLw(null, null);
Craig Mautnerf1b67412012-09-19 13:18:29 -07006216 }
6217
6218 @Override
Svetoslav Ganov545252f2012-12-10 18:29:24 -08006219 public boolean canMagnifyWindow(int windowType) {
6220 switch (windowType) {
6221 case WindowManager.LayoutParams.TYPE_INPUT_METHOD:
6222 case WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG:
6223 case WindowManager.LayoutParams.TYPE_NAVIGATION_BAR:
6224 case WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY: {
6225 return false;
6226 }
6227 }
6228 return true;
6229 }
6230
6231 @Override
6232 public boolean isTopLevelWindow(int windowType) {
6233 if (windowType >= WindowManager.LayoutParams.FIRST_SUB_WINDOW
6234 && windowType <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
6235 return (windowType == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG);
6236 }
6237 return true;
6238 }
6239
Jim Miller4eeb4f62012-11-08 00:04:29 -08006240 @Override
Jeff Brownd7a04de2012-06-17 14:17:52 -07006241 public void dump(String prefix, PrintWriter pw, String[] args) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006242 pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07006243 pw.print(" mSystemReady="); pw.print(mSystemReady);
6244 pw.print(" mSystemBooted="); pw.println(mSystemBooted);
Jeff Brown2e7760e2012-04-11 15:14:55 -07006245 pw.print(prefix); pw.print("mLidState="); pw.print(mLidState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006246 pw.print(" mLidOpenRotation="); pw.print(mLidOpenRotation);
Michael Wright3818c922014-09-02 13:59:07 -07006247 pw.print(" mCameraLensCoverState="); pw.print(mCameraLensCoverState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006248 pw.print(" mHdmiPlugged="); pw.println(mHdmiPlugged);
Dianne Hackborne26ab702011-10-16 13:21:33 -07006249 if (mLastSystemUiFlags != 0 || mResettingSystemUiFlags != 0
6250 || mForceClearedSystemUiFlags != 0) {
6251 pw.print(prefix); pw.print("mLastSystemUiFlags=0x");
6252 pw.print(Integer.toHexString(mLastSystemUiFlags));
6253 pw.print(" mResettingSystemUiFlags=0x");
6254 pw.print(Integer.toHexString(mResettingSystemUiFlags));
6255 pw.print(" mForceClearedSystemUiFlags=0x");
6256 pw.println(Integer.toHexString(mForceClearedSystemUiFlags));
Dianne Hackborndf89e652011-10-06 22:35:11 -07006257 }
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08006258 if (mLastFocusNeedsMenu) {
6259 pw.print(prefix); pw.print("mLastFocusNeedsMenu=");
6260 pw.println(mLastFocusNeedsMenu);
6261 }
Jeff Browna20dda42014-05-27 20:57:24 -07006262 pw.print(prefix); pw.print("mWakeGestureEnabledSetting=");
6263 pw.println(mWakeGestureEnabledSetting);
6264
Jeff Brownbcdfc622014-03-06 19:13:04 -08006265 pw.print(prefix); pw.print("mSupportAutoRotation="); pw.println(mSupportAutoRotation);
Daniel Sandler6396c722013-04-16 20:19:09 -04006266 pw.print(prefix); pw.print("mUiMode="); pw.print(mUiMode);
6267 pw.print(" mDockMode="); pw.print(mDockMode);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006268 pw.print(" mCarDockRotation="); pw.print(mCarDockRotation);
6269 pw.print(" mDeskDockRotation="); pw.println(mDeskDockRotation);
6270 pw.print(prefix); pw.print("mUserRotationMode="); pw.print(mUserRotationMode);
6271 pw.print(" mUserRotation="); pw.print(mUserRotation);
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05006272 pw.print(" mAllowAllRotations="); pw.println(mAllowAllRotations);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07006273 pw.print(prefix); pw.print("mCurrentAppOrientation="); pw.println(mCurrentAppOrientation);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006274 pw.print(prefix); pw.print("mCarDockEnablesAccelerometer=");
6275 pw.print(mCarDockEnablesAccelerometer);
6276 pw.print(" mDeskDockEnablesAccelerometer=");
6277 pw.println(mDeskDockEnablesAccelerometer);
6278 pw.print(prefix); pw.print("mLidKeyboardAccessibility=");
6279 pw.print(mLidKeyboardAccessibility);
6280 pw.print(" mLidNavigationAccessibility="); pw.print(mLidNavigationAccessibility);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07006281 pw.print(" mLidControlsSleep="); pw.println(mLidControlsSleep);
Jeff Brown6d8fd272014-05-20 21:24:38 -07006282 pw.print(prefix);
6283 pw.print("mShortPressOnPowerBehavior="); pw.print(mShortPressOnPowerBehavior);
6284 pw.print(" mLongPressOnPowerBehavior="); pw.println(mLongPressOnPowerBehavior);
Jeff Brown13f00f02014-10-31 14:45:50 -07006285 pw.print(prefix);
6286 pw.print("mDoublePressOnPowerBehavior="); pw.print(mDoublePressOnPowerBehavior);
6287 pw.print(" mTriplePressOnPowerBehavior="); pw.println(mTriplePressOnPowerBehavior);
Jeff Brown6d8fd272014-05-20 21:24:38 -07006288 pw.print(prefix); pw.print("mHasSoftInput="); pw.println(mHasSoftInput);
Jeff Brown3ee549c2014-09-22 20:14:39 -07006289 pw.print(prefix); pw.print("mAwake="); pw.println(mAwake);
6290 pw.print(prefix); pw.print("mScreenOnEarly="); pw.print(mScreenOnEarly);
6291 pw.print(" mScreenOnFully="); pw.println(mScreenOnFully);
6292 pw.print(prefix); pw.print("mKeyguardDrawComplete="); pw.print(mKeyguardDrawComplete);
6293 pw.print(" mWindowManagerDrawComplete="); pw.println(mWindowManagerDrawComplete);
6294 pw.print(prefix); pw.print("mOrientationSensorEnabled=");
6295 pw.println(mOrientationSensorEnabled);
Dianne Hackbornc652de82013-02-15 16:32:56 -08006296 pw.print(prefix); pw.print("mOverscanScreen=("); pw.print(mOverscanScreenLeft);
6297 pw.print(","); pw.print(mOverscanScreenTop);
6298 pw.print(") "); pw.print(mOverscanScreenWidth);
6299 pw.print("x"); pw.println(mOverscanScreenHeight);
6300 if (mOverscanLeft != 0 || mOverscanTop != 0
6301 || mOverscanRight != 0 || mOverscanBottom != 0) {
6302 pw.print(prefix); pw.print("mOverscan left="); pw.print(mOverscanLeft);
6303 pw.print(" top="); pw.print(mOverscanTop);
6304 pw.print(" right="); pw.print(mOverscanRight);
6305 pw.print(" bottom="); pw.println(mOverscanBottom);
6306 }
Dianne Hackborn313440842013-02-19 19:22:59 -08006307 pw.print(prefix); pw.print("mRestrictedOverscanScreen=(");
6308 pw.print(mRestrictedOverscanScreenLeft);
6309 pw.print(","); pw.print(mRestrictedOverscanScreenTop);
6310 pw.print(") "); pw.print(mRestrictedOverscanScreenWidth);
6311 pw.print("x"); pw.println(mRestrictedOverscanScreenHeight);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006312 pw.print(prefix); pw.print("mUnrestrictedScreen=("); pw.print(mUnrestrictedScreenLeft);
6313 pw.print(","); pw.print(mUnrestrictedScreenTop);
6314 pw.print(") "); pw.print(mUnrestrictedScreenWidth);
6315 pw.print("x"); pw.println(mUnrestrictedScreenHeight);
6316 pw.print(prefix); pw.print("mRestrictedScreen=("); pw.print(mRestrictedScreenLeft);
6317 pw.print(","); pw.print(mRestrictedScreenTop);
6318 pw.print(") "); pw.print(mRestrictedScreenWidth);
6319 pw.print("x"); pw.println(mRestrictedScreenHeight);
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07006320 pw.print(prefix); pw.print("mStableFullscreen=("); pw.print(mStableFullscreenLeft);
6321 pw.print(","); pw.print(mStableFullscreenTop);
6322 pw.print(")-("); pw.print(mStableFullscreenRight);
6323 pw.print(","); pw.print(mStableFullscreenBottom); pw.println(")");
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07006324 pw.print(prefix); pw.print("mStable=("); pw.print(mStableLeft);
6325 pw.print(","); pw.print(mStableTop);
6326 pw.print(")-("); pw.print(mStableRight);
6327 pw.print(","); pw.print(mStableBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07006328 pw.print(prefix); pw.print("mSystem=("); pw.print(mSystemLeft);
6329 pw.print(","); pw.print(mSystemTop);
6330 pw.print(")-("); pw.print(mSystemRight);
6331 pw.print(","); pw.print(mSystemBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006332 pw.print(prefix); pw.print("mCur=("); pw.print(mCurLeft);
6333 pw.print(","); pw.print(mCurTop);
6334 pw.print(")-("); pw.print(mCurRight);
6335 pw.print(","); pw.print(mCurBottom); pw.println(")");
6336 pw.print(prefix); pw.print("mContent=("); pw.print(mContentLeft);
6337 pw.print(","); pw.print(mContentTop);
6338 pw.print(")-("); pw.print(mContentRight);
6339 pw.print(","); pw.print(mContentBottom); pw.println(")");
Dianne Hackborne30e02f2014-05-27 18:24:45 -07006340 pw.print(prefix); pw.print("mVoiceContent=("); pw.print(mVoiceContentLeft);
6341 pw.print(","); pw.print(mVoiceContentTop);
6342 pw.print(")-("); pw.print(mVoiceContentRight);
6343 pw.print(","); pw.print(mVoiceContentBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006344 pw.print(prefix); pw.print("mDock=("); pw.print(mDockLeft);
6345 pw.print(","); pw.print(mDockTop);
6346 pw.print(")-("); pw.print(mDockRight);
6347 pw.print(","); pw.print(mDockBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07006348 pw.print(prefix); pw.print("mDockLayer="); pw.print(mDockLayer);
6349 pw.print(" mStatusBarLayer="); pw.println(mStatusBarLayer);
Dianne Hackborn7ad44382012-10-18 17:46:00 -07006350 pw.print(prefix); pw.print("mShowingLockscreen="); pw.print(mShowingLockscreen);
6351 pw.print(" mShowingDream="); pw.print(mShowingDream);
6352 pw.print(" mDreamingLockscreen="); pw.println(mDreamingLockscreen);
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006353 if (mLastInputMethodWindow != null) {
6354 pw.print(prefix); pw.print("mLastInputMethodWindow=");
6355 pw.println(mLastInputMethodWindow);
6356 }
6357 if (mLastInputMethodTargetWindow != null) {
6358 pw.print(prefix); pw.print("mLastInputMethodTargetWindow=");
6359 pw.println(mLastInputMethodTargetWindow);
6360 }
6361 if (mStatusBar != null) {
6362 pw.print(prefix); pw.print("mStatusBar=");
Dianne Hackbornae6688b2015-02-11 17:02:41 -08006363 pw.print(mStatusBar); pw.print(" isStatusBarKeyguard=");
6364 pw.println(isStatusBarKeyguard());
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006365 }
6366 if (mNavigationBar != null) {
6367 pw.print(prefix); pw.print("mNavigationBar=");
6368 pw.println(mNavigationBar);
6369 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006370 if (mFocusedWindow != null) {
6371 pw.print(prefix); pw.print("mFocusedWindow=");
6372 pw.println(mFocusedWindow);
6373 }
6374 if (mFocusedApp != null) {
6375 pw.print(prefix); pw.print("mFocusedApp=");
6376 pw.println(mFocusedApp);
6377 }
6378 if (mWinDismissingKeyguard != null) {
6379 pw.print(prefix); pw.print("mWinDismissingKeyguard=");
6380 pw.println(mWinDismissingKeyguard);
6381 }
6382 if (mTopFullscreenOpaqueWindowState != null) {
6383 pw.print(prefix); pw.print("mTopFullscreenOpaqueWindowState=");
6384 pw.println(mTopFullscreenOpaqueWindowState);
6385 }
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08006386 if (mForcingShowNavBar) {
6387 pw.print(prefix); pw.print("mForcingShowNavBar=");
6388 pw.println(mForcingShowNavBar); pw.print( "mForcingShowNavBarLayer=");
6389 pw.println(mForcingShowNavBarLayer);
6390 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07006391 pw.print(prefix); pw.print("mTopIsFullscreen="); pw.print(mTopIsFullscreen);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006392 pw.print(" mHideLockScreen="); pw.println(mHideLockScreen);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07006393 pw.print(prefix); pw.print("mForceStatusBar="); pw.print(mForceStatusBar);
6394 pw.print(" mForceStatusBarFromKeyguard=");
6395 pw.println(mForceStatusBarFromKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006396 pw.print(prefix); pw.print("mDismissKeyguard="); pw.print(mDismissKeyguard);
Craig Mautnerad09bcc2012-10-08 13:33:11 -07006397 pw.print(" mWinDismissingKeyguard="); pw.print(mWinDismissingKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006398 pw.print(" mHomePressed="); pw.println(mHomePressed);
6399 pw.print(prefix); pw.print("mAllowLockscreenWhenOn="); pw.print(mAllowLockscreenWhenOn);
6400 pw.print(" mLockScreenTimeout="); pw.print(mLockScreenTimeout);
6401 pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive);
6402 pw.print(prefix); pw.print("mEndcallBehavior="); pw.print(mEndcallBehavior);
6403 pw.print(" mIncallPowerBehavior="); pw.print(mIncallPowerBehavior);
6404 pw.print(" mLongPressOnHomeBehavior="); pw.println(mLongPressOnHomeBehavior);
6405 pw.print(prefix); pw.print("mLandscapeRotation="); pw.print(mLandscapeRotation);
6406 pw.print(" mSeascapeRotation="); pw.println(mSeascapeRotation);
6407 pw.print(prefix); pw.print("mPortraitRotation="); pw.print(mPortraitRotation);
6408 pw.print(" mUpsideDownRotation="); pw.println(mUpsideDownRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07006409 pw.print(prefix); pw.print("mDemoHdmiRotation="); pw.print(mDemoHdmiRotation);
6410 pw.print(" mDemoHdmiRotationLock="); pw.println(mDemoHdmiRotationLock);
6411 pw.print(prefix); pw.print("mUndockedHdmiRotation="); pw.println(mUndockedHdmiRotation);
Jeff Brown600f0032014-05-22 17:06:00 -07006412
Tim Kilbournd7c0c2e2014-05-29 16:08:10 -07006413 mGlobalKeyManager.dump(prefix, pw);
John Spurlock27735a42013-08-14 17:57:38 -04006414 mStatusBarController.dump(pw, prefix);
6415 mNavigationBarController.dump(pw, prefix);
John Spurlockc6d1c602014-01-17 15:22:06 -05006416 PolicyControl.dump(prefix, pw);
Jeff Brown600f0032014-05-22 17:06:00 -07006417
Jeff Browna20dda42014-05-27 20:57:24 -07006418 if (mWakeGestureListener != null) {
6419 mWakeGestureListener.dump(pw, prefix);
6420 }
Jeff Brown600f0032014-05-22 17:06:00 -07006421 if (mOrientationListener != null) {
6422 mOrientationListener.dump(pw, prefix);
6423 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006424 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006425}