blob: f691b4eca8085ccbd64e708c4609d9ec8157d1eb [file] [log] [blame]
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001/*
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
Jorim Jaggib10e33f2015-02-04 21:57:40 +010016package com.android.server.policy;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080017
Dianne Hackborna4972e92012-03-14 10:38:05 -070018import android.app.ActivityManager;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080019import android.app.ActivityManagerNative;
Dianne Hackbornc2293022013-02-06 23:14:49 -080020import android.app.AppOpsManager;
Daniel Sandler6396c722013-04-16 20:19:09 -040021import android.app.IUiModeManager;
Dianne Hackborn661cd522011-08-22 00:26:20 -070022import android.app.ProgressDialog;
Jeff Brownde7a8ea2012-06-13 18:28:57 -070023import android.app.SearchManager;
John Spurlock97642182013-07-29 17:58:39 -040024import android.app.StatusBarManager;
Dianne Hackborn78968392010-03-04 20:47:56 -080025import android.app.UiModeManager;
Dianne Hackborn39c2d712009-09-22 11:41:31 -070026import android.content.ActivityNotFoundException;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080027import android.content.BroadcastReceiver;
Daniel Sandler0601eb72011-04-13 01:01:32 -040028import android.content.ComponentName;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080029import android.content.ContentResolver;
30import android.content.Context;
31import android.content.Intent;
Mike Lockwood1753f7f2009-08-24 14:49:07 -070032import android.content.IntentFilter;
Winson Chung9112ec32011-06-27 13:15:32 -070033import android.content.ServiceConnection;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080034import android.content.pm.ActivityInfo;
35import android.content.pm.PackageManager;
Daniel Sandler6396c722013-04-16 20:19:09 -040036import android.content.pm.ResolveInfo;
Dianne Hackborn2f0b1752011-05-31 17:59:49 -070037import android.content.res.CompatibilityInfo;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080038import android.content.res.Configuration;
39import android.content.res.Resources;
Craig Mautner8e4df6c2012-05-23 16:57:23 -070040import android.content.res.TypedArray;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080041import android.database.ContentObserver;
Dianne Hackbornc777e072010-02-12 13:07:59 -080042import android.graphics.PixelFormat;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080043import android.graphics.Rect;
John Spurlock7b414672014-07-18 13:02:39 -040044import android.media.AudioAttributes;
Michael Jurka7a348952012-02-27 13:07:58 -080045import android.media.AudioManager;
John Spurlock61560172015-02-06 19:46:04 -050046import android.media.AudioSystem;
Michael Jurka7a348952012-02-27 13:07:58 -080047import android.media.IAudioService;
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -070048import android.media.Ringtone;
49import android.media.RingtoneManager;
RoboErik8a2cfc32014-05-16 11:19:38 -070050import android.media.session.MediaSessionLegacyHelper;
Dianne Hackborn38e29a62011-09-18 14:43:08 -070051import android.os.Bundle;
Craig Mautner276a6eb2014-11-04 15:32:57 -080052import android.os.Debug;
Jeff Brown9a538ee2012-08-20 14:56:57 -070053import android.os.FactoryTest;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080054import android.os.Handler;
55import android.os.IBinder;
Jeff Brown32cbc38552011-12-01 14:01:49 -080056import android.os.Looper;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -070057import android.os.Message;
58import android.os.Messenger;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080059import android.os.PowerManager;
60import android.os.RemoteException;
61import android.os.ServiceManager;
62import android.os.SystemClock;
63import android.os.SystemProperties;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -080064import android.os.UEventObserver;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -070065import android.os.UserHandle;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080066import android.os.Vibrator;
Michael Wright3818c922014-09-02 13:59:07 -070067import android.provider.MediaStore;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080068import android.provider.Settings;
Jose Lima9546b202014-07-02 17:21:51 -070069import android.service.dreams.DreamManagerInternal;
John Spurlockc8b46ca2013-04-08 12:59:26 -040070import android.service.dreams.DreamService;
71import android.service.dreams.IDreamManager;
Michael Wrightdc63f7b2014-08-21 19:05:21 -070072import android.speech.RecognizerIntent;
Tyler Gunnef9f6f92014-09-12 22:16:17 -070073import android.telecom.TelecomManager;
Dianne Hackborn81e56d52011-05-26 00:55:58 -070074import android.util.DisplayMetrics;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080075import android.util.EventLog;
76import android.util.Log;
Jorim Jaggi24bec7c2015-02-04 12:40:14 +010077import android.util.Pair;
Jeff Browna41ca772010-08-11 14:46:32 -070078import android.util.Slog;
Jeff Brown6651a632011-11-28 12:59:11 -080079import android.util.SparseArray;
Dianne Hackbornf87d1962012-04-04 12:48:24 -070080import android.view.Display;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080081import android.view.Gravity;
82import android.view.HapticFeedbackConstants;
Dianne Hackborne0f085d2011-11-30 18:41:15 -080083import android.view.IApplicationToken;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080084import android.view.IWindowManager;
Jeff Browna41ca772010-08-11 14:46:32 -070085import android.view.InputChannel;
Jeff Brown4d396052010-10-29 21:50:21 -070086import android.view.InputDevice;
Jeff Brown4952dfd2011-11-30 19:23:22 -080087import android.view.InputEvent;
Jeff Brown32cbc38552011-12-01 14:01:49 -080088import android.view.InputEventReceiver;
Jeff Brown6b53e8d2010-11-10 16:03:06 -080089import android.view.KeyCharacterMap;
Craig Mautnerae446592012-12-06 19:05:05 -080090import android.view.KeyCharacterMap.FallbackAction;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080091import android.view.KeyEvent;
92import android.view.MotionEvent;
Jorim Jaggib10e33f2015-02-04 21:57:40 +010093import android.view.PhoneWindow;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080094import android.view.Surface;
95import android.view.View;
96import android.view.ViewConfiguration;
97import android.view.Window;
98import android.view.WindowManager;
Craig Mautnerae446592012-12-06 19:05:05 -080099import android.view.WindowManagerGlobal;
Craig Mautner8a0da012014-05-31 15:13:37 -0700100import android.view.WindowManagerInternal;
Craig Mautnerae446592012-12-06 19:05:05 -0800101import android.view.WindowManagerPolicy;
Craig Mautnerae446592012-12-06 19:05:05 -0800102import android.view.accessibility.AccessibilityEvent;
Svetoslav8e3feb12014-02-24 13:46:47 -0800103import android.view.accessibility.AccessibilityManager;
Craig Mautnerae446592012-12-06 19:05:05 -0800104import android.view.animation.Animation;
Jorim Jaggi76a16232014-08-08 17:00:47 +0200105import android.view.animation.AnimationSet;
Craig Mautnerae446592012-12-06 19:05:05 -0800106import android.view.animation.AnimationUtils;
Jorim Jaggi24bec7c2015-02-04 12:40:14 +0100107import android.view.animation.Interpolator;
108import android.view.animation.TranslateAnimation;
Craig Mautnerae446592012-12-06 19:05:05 -0800109
110import com.android.internal.R;
Craig Mautnerae446592012-12-06 19:05:05 -0800111import com.android.internal.statusbar.IStatusBarService;
Craig Mautnerae446592012-12-06 19:05:05 -0800112import com.android.internal.widget.PointerLocationView;
Craig Mautner8a0da012014-05-31 15:13:37 -0700113import com.android.server.LocalServices;
Jorim Jaggib10e33f2015-02-04 21:57:40 +0100114import com.android.server.policy.keyguard.KeyguardServiceDelegate;
115import com.android.server.policy.keyguard.KeyguardServiceDelegate.ShowListener;
Craig Mautnerae446592012-12-06 19:05:05 -0800116
117import java.io.File;
118import java.io.FileReader;
119import java.io.IOException;
120import java.io.PrintWriter;
Craig Mautner2bc789b2014-03-19 19:48:38 -0700121import java.util.HashSet;
Craig Mautner276a6eb2014-11-04 15:32:57 -0800122import java.util.List;
Craig Mautnerae446592012-12-06 19:05:05 -0800123
Dianne Hackbornc652de82013-02-15 16:32:56 -0800124import static android.view.WindowManager.LayoutParams.*;
Jeff Brownac143512012-04-05 18:57:33 -0700125import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_ABSENT;
126import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_OPEN;
127import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_CLOSED;
Michael Wright3818c922014-09-02 13:59:07 -0700128import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVER_ABSENT;
129import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_UNCOVERED;
130import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVERED;
Dianne Hackborn08743722009-12-21 12:16:51 -0800131
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800132/**
The Android Open Source Project0727d222009-03-11 12:11:58 -0700133 * WindowManagerPolicy implementation for the Android phone UI. This
134 * introduces a new method suffix, Lp, for an internal lock of the
135 * PhoneWindowManager. This is used to protect some internal state, and
John Spurlock04db1762013-05-13 12:46:41 -0400136 * can be acquired with either the Lw and Li lock held, so has the restrictions
The Android Open Source Project0727d222009-03-11 12:11:58 -0700137 * of both of those when held.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800138 */
139public class PhoneWindowManager implements WindowManagerPolicy {
140 static final String TAG = "WindowManager";
141 static final boolean DEBUG = false;
Joe Onorato43a17652011-04-06 19:22:23 -0700142 static final boolean localLOGV = false;
Jeff Brown40013652012-05-16 21:22:36 -0700143 static final boolean DEBUG_INPUT = false;
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -0700144 static final boolean DEBUG_KEYGUARD = false;
145 static final boolean DEBUG_LAYOUT = false;
Craig Mautner6fbda632012-07-03 09:26:39 -0700146 static final boolean DEBUG_STARTING_WINDOW = false;
Craig Mautner8a0da012014-05-31 15:13:37 -0700147 static final boolean DEBUG_WAKEUP = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800148 static final boolean SHOW_STARTING_ANIMATIONS = true;
149 static final boolean SHOW_PROCESSES_ON_ALT_MENU = false;
Joe Onoratod208e702010-10-08 16:22:43 -0400150
Daniel Sandler6396c722013-04-16 20:19:09 -0400151 // Whether to allow dock apps with METADATA_DOCK_HOME to temporarily take over the Home key.
152 // No longer recommended for desk docks; still useful in car docks.
153 static final boolean ENABLE_CAR_DOCK_HOME_CAPTURE = true;
154 static final boolean ENABLE_DESK_DOCK_HOME_CAPTURE = false;
155
Jeff Brown6d8fd272014-05-20 21:24:38 -0700156 static final int SHORT_PRESS_POWER_NOTHING = 0;
157 static final int SHORT_PRESS_POWER_GO_TO_SLEEP = 1;
158 static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP = 2;
159 static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME = 3;
Bryce Lee01b0c5f2015-02-05 18:24:04 -0800160 static final int SHORT_PRESS_POWER_GO_HOME = 4;
Jeff Brown6d8fd272014-05-20 21:24:38 -0700161
Joe Onoratod208e702010-10-08 16:22:43 -0400162 static final int LONG_PRESS_POWER_NOTHING = 0;
163 static final int LONG_PRESS_POWER_GLOBAL_ACTIONS = 1;
164 static final int LONG_PRESS_POWER_SHUT_OFF = 2;
Jeff Brown9a538ee2012-08-20 14:56:57 -0700165 static final int LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM = 3;
Michael Jurka3b1fc472011-06-13 10:54:40 -0700166
Jeff Brown13f00f02014-10-31 14:45:50 -0700167 static final int MULTI_PRESS_POWER_NOTHING = 0;
168 static final int MULTI_PRESS_POWER_THEATER_MODE = 1;
169 static final int MULTI_PRESS_POWER_BRIGHTNESS_BOOST = 2;
170
Michael Jurka3b1fc472011-06-13 10:54:40 -0700171 // These need to match the documentation/constant in
172 // core/res/res/values/config.xml
Joe Onorato46b0d682010-11-22 17:37:27 -0800173 static final int LONG_PRESS_HOME_NOTHING = 0;
Michael Wrightc9ebea72013-01-16 19:25:02 -0800174 static final int LONG_PRESS_HOME_RECENT_SYSTEM_UI = 1;
Jeff Browncaca8812013-05-09 13:34:33 -0700175 static final int LONG_PRESS_HOME_ASSIST = 2;
176
177 static final int DOUBLE_TAP_HOME_NOTHING = 0;
178 static final int DOUBLE_TAP_HOME_RECENT_SYSTEM_UI = 1;
Joe Onorato46b0d682010-11-22 17:37:27 -0800179
Dianne Hackborn5cb8d792009-05-21 17:34:15 -0700180 static final int APPLICATION_MEDIA_SUBLAYER = -2;
181 static final int APPLICATION_MEDIA_OVERLAY_SUBLAYER = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800182 static final int APPLICATION_PANEL_SUBLAYER = 1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800183 static final int APPLICATION_SUB_PANEL_SUBLAYER = 2;
Craig Mautner88400d32012-09-30 12:35:45 -0700184
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800185 static public final String SYSTEM_DIALOG_REASON_KEY = "reason";
186 static public final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions";
187 static public final String SYSTEM_DIALOG_REASON_RECENT_APPS = "recentapps";
Joe Onoratof275f0c2009-11-24 16:11:13 -0500188 static public final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey";
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700189 static public final String SYSTEM_DIALOG_REASON_ASSIST = "assist";
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800190
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700191 /**
192 * These are the system UI flags that, when changing, can cause the layout
193 * of the screen to change.
194 */
195 static final int SYSTEM_UI_CHANGING_LAYOUT =
John Spurlocke1f366f2013-08-05 12:22:40 -0400196 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlock7f4820a2013-10-08 12:54:35 -0400197 | View.SYSTEM_UI_FLAG_FULLSCREEN
198 | View.STATUS_BAR_TRANSLUCENT
Adrian Roosea562512014-05-05 13:33:03 +0200199 | View.NAVIGATION_BAR_TRANSLUCENT
200 | View.SYSTEM_UI_TRANSPARENT;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700201
John Spurlock7b414672014-07-18 13:02:39 -0400202 private static final AudioAttributes VIBRATION_ATTRIBUTES = new AudioAttributes.Builder()
203 .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
204 .setUsage(AudioAttributes.USAGE_ASSISTANCE_SONIFICATION)
205 .build();
206
Jim Miller5ecd8112013-01-09 18:50:26 -0800207 /**
208 * Keyguard stuff
209 */
210 private WindowState mKeyguardScrim;
Jorim Jaggi380ecb82014-03-14 17:25:20 +0100211 private boolean mKeyguardHidden;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700212 private boolean mKeyguardDrawnOnce;
Jim Miller5ecd8112013-01-09 18:50:26 -0800213
Jeff Brown6651a632011-11-28 12:59:11 -0800214 /* Table of Application Launch keys. Maps from key codes to intent categories.
215 *
216 * These are special keys that are used to launch particular kinds of applications,
217 * such as a web browser. HID defines nearly a hundred of them in the Consumer (0x0C)
218 * usage page. We don't support quite that many yet...
219 */
220 static SparseArray<String> sApplicationLaunchKeyCategories;
221 static {
222 sApplicationLaunchKeyCategories = new SparseArray<String>();
223 sApplicationLaunchKeyCategories.append(
224 KeyEvent.KEYCODE_EXPLORER, Intent.CATEGORY_APP_BROWSER);
225 sApplicationLaunchKeyCategories.append(
226 KeyEvent.KEYCODE_ENVELOPE, Intent.CATEGORY_APP_EMAIL);
227 sApplicationLaunchKeyCategories.append(
228 KeyEvent.KEYCODE_CONTACTS, Intent.CATEGORY_APP_CONTACTS);
229 sApplicationLaunchKeyCategories.append(
230 KeyEvent.KEYCODE_CALENDAR, Intent.CATEGORY_APP_CALENDAR);
231 sApplicationLaunchKeyCategories.append(
232 KeyEvent.KEYCODE_MUSIC, Intent.CATEGORY_APP_MUSIC);
233 sApplicationLaunchKeyCategories.append(
234 KeyEvent.KEYCODE_CALCULATOR, Intent.CATEGORY_APP_CALCULATOR);
235 }
236
Craig Mautnerc3daedd2014-09-13 11:17:23 -0700237 /** Amount of time (in milliseconds) to wait for windows drawn before powering on. */
238 static final int WAITING_FOR_DRAWN_TIMEOUT = 1000;
239
Dianne Hackborndf89e652011-10-06 22:35:11 -0700240 /**
241 * Lock protecting internal state. Must not call out into window
242 * manager with lock held. (This lock will be acquired in places
243 * where the window manager is calling in with its own lock held.)
244 */
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800245 private final Object mLock = new Object();
Dianne Hackborndf89e652011-10-06 22:35:11 -0700246
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800247 Context mContext;
248 IWindowManager mWindowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700249 WindowManagerFuncs mWindowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -0700250 WindowManagerInternal mWindowManagerInternal;
Jeff Brown96307042012-07-27 15:51:34 -0700251 PowerManager mPowerManager;
Jose Lima9546b202014-07-02 17:21:51 -0700252 DreamManagerInternal mDreamManagerInternal;
Joe Onorato93056472010-09-10 10:30:46 -0400253 IStatusBarService mStatusBarService;
Jeff Browncaca8812013-05-09 13:34:33 -0700254 boolean mPreloadedRecentApps;
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700255 final Object mServiceAquireLock = new Object();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800256 Vibrator mVibrator; // Vibrator for giving feedback of orientation changes
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700257 SearchManager mSearchManager;
Svetoslav8e3feb12014-02-24 13:46:47 -0800258 AccessibilityManager mAccessibilityManager;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800259
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700260 // Vibrator pattern for haptic feedback of a long press.
261 long[] mLongPressVibePattern;
Craig Mautner88400d32012-09-30 12:35:45 -0700262
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700263 // Vibrator pattern for haptic feedback of virtual key press.
264 long[] mVirtualKeyVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700265
Amith Yamasanic33cb712010-02-10 15:21:49 -0800266 // Vibrator pattern for a short vibration.
267 long[] mKeyboardTapVibePattern;
268
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -0700269 // Vibrator pattern for a short vibration when tapping on an hour/minute tick of a Clock.
270 long[] mClockTickVibePattern;
271
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -0700272 // Vibrator pattern for a short vibration when tapping on a day/month/year date of a Calendar.
273 long[] mCalendarDateVibePattern;
274
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700275 // Vibrator pattern for haptic feedback during boot when safe mode is disabled.
276 long[] mSafeModeDisabledVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700277
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700278 // Vibrator pattern for haptic feedback during boot when safe mode is enabled.
279 long[] mSafeModeEnabledVibePattern;
Romain Guy8154cd32010-03-29 14:41:15 -0700280
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800281 /** If true, hitting shift & menu will broadcast Intent.ACTION_BUG_REPORT */
282 boolean mEnableShiftMenuBugReports = false;
Mike Lockwoodd747dc82011-09-13 16:28:22 -0400283
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800284 boolean mSafeMode;
285 WindowState mStatusBar = null;
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700286 int mStatusBarHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400287 WindowState mNavigationBar = null;
Daniel Sandler36412a72011-08-04 09:35:13 -0400288 boolean mHasNavigationBar = false;
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700289 boolean mCanHideNavigationBar = false;
Daniel Sandler4a066c52012-04-20 14:49:13 -0400290 boolean mNavigationBarCanMove = false; // can the navigation bar ever move to the side?
291 boolean mNavigationBarOnBottom = true; // is the navigation bar on the bottom *right now*?
292 int[] mNavigationBarHeightForRotation = new int[4];
293 int[] mNavigationBarWidthForRotation = new int[4];
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400294
Craig Mautnera631d492014-08-05 15:16:01 -0700295 boolean mBootMessageNeedsHiding;
Jim Miller5ecd8112013-01-09 18:50:26 -0800296 KeyguardServiceDelegate mKeyguardDelegate;
Craig Mautner13f6ea72014-06-23 14:57:02 -0700297 final Runnable mWindowManagerDrawCallback = new Runnable() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700298 @Override
Craig Mautner13f6ea72014-06-23 14:57:02 -0700299 public void run() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700300 if (DEBUG_WAKEUP) Slog.i(TAG, "All windows ready for display!");
301 mHandler.sendEmptyMessage(MSG_WINDOW_MANAGER_DRAWN_COMPLETE);
302 }
303 };
304 final ShowListener mKeyguardDelegateCallback = new ShowListener() {
305 @Override
306 public void onShown(IBinder windowToken) {
307 if (DEBUG_WAKEUP) Slog.d(TAG, "mKeyguardDelegate.ShowListener.onShown.");
308 mHandler.sendEmptyMessage(MSG_KEYGUARD_DRAWN_COMPLETE);
309 }
310 };
311
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800312 GlobalActions mGlobalActions;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800313 Handler mHandler;
satok1bc0a492012-04-25 22:47:12 +0900314 WindowState mLastInputMethodWindow = null;
315 WindowState mLastInputMethodTargetWindow = null;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800316
Jeff Brown13f00f02014-10-31 14:45:50 -0700317 // FIXME This state is shared between the input reader and handler thread.
318 // Technically it's broken and buggy but it has been like this for many years
319 // and we have not yet seen any problems. Someday we'll rewrite this logic
320 // so that only one thread is involved in handling input policy. Unfortunately
321 // it's on a critical path for power management so we can't just post the work to the
322 // handler thread. We'll need to resolve this someday by teaching the input dispatcher
323 // to hold wakelocks during dispatch and eliminating the critical path.
324 volatile boolean mPowerKeyHandled;
Bryce Leed9268e32014-11-17 17:40:59 -0800325 volatile boolean mBeganFromNonInteractive;
Jeff Brown13f00f02014-10-31 14:45:50 -0700326 volatile int mPowerKeyPressCounter;
327 volatile boolean mEndCallKeyHandled;
328
Winson Chungd42a6cf2014-06-03 16:24:04 -0700329 boolean mRecentsVisible;
Winson Chung1e8d71b2014-05-16 17:05:22 -0700330 int mRecentAppsHeldModifiers;
Jeff Browncf39bdf2012-05-18 14:41:19 -0700331 boolean mLanguageSwitchKeyPressed;
Jeff Brown68b909d2011-12-07 16:36:01 -0800332
Jeff Brown2e7760e2012-04-11 15:14:55 -0700333 int mLidState = LID_ABSENT;
Michael Wright3818c922014-09-02 13:59:07 -0700334 int mCameraLensCoverState = CAMERA_LENS_COVER_ABSENT;
Jeff Browndaa37532012-05-01 15:54:03 -0700335 boolean mHaveBuiltInKeyboard;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800336
Dianne Hackbornc777e072010-02-12 13:07:59 -0800337 boolean mSystemReady;
Dianne Hackbornba24e4d2011-09-01 11:17:06 -0700338 boolean mSystemBooted;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800339 boolean mHdmiPlugged;
Jeff Brown4f5fa282014-06-12 19:19:15 -0700340 IUiModeManager mUiModeManager;
Daniel Sandler6396c722013-04-16 20:19:09 -0400341 int mUiMode;
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700342 int mDockMode = Intent.EXTRA_DOCK_STATE_UNDOCKED;
Mike Lockwood1753f7f2009-08-24 14:49:07 -0700343 int mLidOpenRotation;
Mike Lockwood2d1efbd2009-09-16 12:15:53 -0400344 int mCarDockRotation;
345 int mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -0700346 int mUndockedHdmiRotation;
347 int mDemoHdmiRotation;
348 boolean mDemoHdmiRotationLock;
Chong Zhangae6119ff2014-11-11 18:54:39 -0800349 int mDemoRotation;
350 boolean mDemoRotationLock;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400351
Jeff Browna20dda42014-05-27 20:57:24 -0700352 boolean mWakeGestureEnabledSetting;
353 MyWakeGestureListener mWakeGestureListener;
354
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700355 // Default display does not rotate, apps that require non-default orientation will have to
356 // have the orientation emulated.
357 private boolean mForceDefaultOrientation = false;
358
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400359 int mUserRotationMode = WindowManagerPolicy.USER_ROTATION_FREE;
360 int mUserRotation = Surface.ROTATION_0;
Jeff Brown207673cd2012-06-05 17:47:11 -0700361 boolean mAccelerometerDefault;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400362
Jeff Brownbcdfc622014-03-06 19:13:04 -0800363 boolean mSupportAutoRotation;
Jeff Brownd3187e32011-09-21 19:26:44 -0700364 int mAllowAllRotations = -1;
Mike Lockwoode9867d22009-09-20 01:59:02 -0400365 boolean mCarDockEnablesAccelerometer;
366 boolean mDeskDockEnablesAccelerometer;
Dianne Hackborn2862fff2009-09-15 22:56:29 -0700367 int mLidKeyboardAccessibility;
368 int mLidNavigationAccessibility;
Jeff Brownc458ce92012-04-30 14:58:40 -0700369 boolean mLidControlsSleep;
Jeff Brown13f00f02014-10-31 14:45:50 -0700370 int mShortPressOnPowerBehavior;
371 int mLongPressOnPowerBehavior;
372 int mDoublePressOnPowerBehavior;
373 int mTriplePressOnPowerBehavior;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700374 boolean mAwake;
375 boolean mScreenOnEarly;
376 boolean mScreenOnFully;
377 ScreenOnListener mScreenOnListener;
378 boolean mKeyguardDrawComplete;
379 boolean mWindowManagerDrawComplete;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800380 boolean mOrientationSensorEnabled = false;
381 int mCurrentAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800382 boolean mHasSoftInput = false;
Daniel Sandlerdd73ee42013-10-11 22:19:59 -0400383 boolean mTranslucentDecorEnabled = true;
RoboErik001c59c2015-01-26 15:53:51 -0800384 boolean mUseTvRouting;
385 boolean mUseMasterVolume;
Craig Mautner967212c2013-04-13 21:10:58 -0700386
Jeff Brown70825162012-03-28 17:27:48 -0700387 int mPointerLocationMode = 0; // guarded by mLock
Joe Onorato664644d2011-01-23 17:53:23 -0800388
389 // The last window we were told about in focusChanged.
390 WindowState mFocusedWindow;
Dianne Hackborne0f085d2011-11-30 18:41:15 -0800391 IApplicationToken mFocusedApp;
Joe Onorato664644d2011-01-23 17:53:23 -0800392
Jeff Brown70825162012-03-28 17:27:48 -0700393 PointerLocationView mPointerLocationView;
Jeff Brown32cbc38552011-12-01 14:01:49 -0800394
Dianne Hackbornc652de82013-02-15 16:32:56 -0800395 // The current size of the screen; really; extends into the overscan area of
396 // the screen and doesn't account for any system elements like the status bar.
397 int mOverscanScreenLeft, mOverscanScreenTop;
398 int mOverscanScreenWidth, mOverscanScreenHeight;
399 // The current visible size of the screen; really; (ir)regardless of whether the status
400 // bar can be hidden but not extending into the overscan area.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800401 int mUnrestrictedScreenLeft, mUnrestrictedScreenTop;
402 int mUnrestrictedScreenWidth, mUnrestrictedScreenHeight;
Dianne Hackborn313440842013-02-19 19:22:59 -0800403 // Like mOverscanScreen*, but allowed to move into the overscan region where appropriate.
404 int mRestrictedOverscanScreenLeft, mRestrictedOverscanScreenTop;
405 int mRestrictedOverscanScreenWidth, mRestrictedOverscanScreenHeight;
Dianne Hackborn82de1ae2010-10-28 11:28:39 -0700406 // The current size of the screen; these may be different than (0,0)-(dw,dh)
407 // if the status bar can't be hidden; in that case it effectively carves out
408 // that area of the display from all other windows.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800409 int mRestrictedScreenLeft, mRestrictedScreenTop;
410 int mRestrictedScreenWidth, mRestrictedScreenHeight;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700411 // During layout, the current screen borders accounting for any currently
412 // visible system UI elements.
413 int mSystemLeft, mSystemTop, mSystemRight, mSystemBottom;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700414 // For applications requesting stable content insets, these are them.
415 int mStableLeft, mStableTop, mStableRight, mStableBottom;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -0700416 // For applications requesting stable content insets but have also set the
417 // fullscreen window flag, these are the stable dimensions without the status bar.
418 int mStableFullscreenLeft, mStableFullscreenTop;
419 int mStableFullscreenRight, mStableFullscreenBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800420 // During layout, the current screen borders with all outer decoration
421 // (status bar, input method dock) accounted for.
422 int mCurLeft, mCurTop, mCurRight, mCurBottom;
423 // During layout, the frame in which content should be displayed
424 // to the user, accounting for all screen decoration except for any
425 // space they deem as available for other content. This is usually
426 // the same as mCur*, but may be larger if the screen decor has supplied
427 // content insets.
428 int mContentLeft, mContentTop, mContentRight, mContentBottom;
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700429 // During layout, the frame in which voice content should be displayed
430 // to the user, accounting for all screen decoration except for any
431 // space they deem as available for other content.
432 int mVoiceContentLeft, mVoiceContentTop, mVoiceContentRight, mVoiceContentBottom;
Dianne Hackborn8e11ef02010-11-18 19:47:42 -0800433 // During layout, the current screen borders along which input method
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800434 // windows are placed.
435 int mDockLeft, mDockTop, mDockRight, mDockBottom;
436 // During layout, the layer at which the doc window is placed.
437 int mDockLayer;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700438 // During layout, this is the layer of the status bar.
439 int mStatusBarLayer;
Dianne Hackborne26ab702011-10-16 13:21:33 -0700440 int mLastSystemUiFlags;
441 // Bits that we are in the process of clearing, so we want to prevent
442 // them from being set by applications until everything has been updated
443 // to have them clear.
444 int mResettingSystemUiFlags = 0;
445 // Bits that we are currently always keeping cleared.
446 int mForceClearedSystemUiFlags = 0;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -0800447 // What we last reported to system UI about whether the compatibility
448 // menu needs to be displayed.
449 boolean mLastFocusNeedsMenu = false;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700450
451 FakeWindow mHideNavFakeWindow = null;
452
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800453 static final Rect mTmpParentFrame = new Rect();
454 static final Rect mTmpDisplayFrame = new Rect();
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800455 static final Rect mTmpOverscanFrame = new Rect();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800456 static final Rect mTmpContentFrame = new Rect();
457 static final Rect mTmpVisibleFrame = new Rect();
John Spurlock46646232013-09-30 22:32:42 -0400458 static final Rect mTmpDecorFrame = new Rect();
Adrian Roosfa104232014-06-20 16:10:14 -0700459 static final Rect mTmpStableFrame = new Rect();
Dianne Hackborn1f903c32011-09-13 19:18:06 -0700460 static final Rect mTmpNavigationFrame = new Rect();
Craig Mautner967212c2013-04-13 21:10:58 -0700461
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800462 WindowState mTopFullscreenOpaqueWindowState;
Adrian Rooscd3884d2015-02-18 17:25:23 +0100463 WindowState mTopFullscreenOpaqueOrDimmingWindowState;
Craig Mautner2bc789b2014-03-19 19:48:38 -0700464 HashSet<IApplicationToken> mAppsToBeHidden = new HashSet<IApplicationToken>();
Jorim Jaggic13fcac2014-09-11 17:36:57 +0200465 HashSet<IApplicationToken> mAppsThatDismissKeyguard = new HashSet<IApplicationToken>();
Joe Onorato93056472010-09-10 10:30:46 -0400466 boolean mTopIsFullscreen;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800467 boolean mForceStatusBar;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -0700468 boolean mForceStatusBarFromKeyguard;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700469 boolean mHideLockScreen;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -0800470 boolean mForcingShowNavBar;
471 int mForcingShowNavBarLayer;
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700472
473 // States of keyguard dismiss.
474 private static final int DISMISS_KEYGUARD_NONE = 0; // Keyguard not being dismissed.
475 private static final int DISMISS_KEYGUARD_START = 1; // Keyguard needs to be dismissed.
476 private static final int DISMISS_KEYGUARD_CONTINUE = 2; // Keyguard has been dismissed.
477 int mDismissKeyguard = DISMISS_KEYGUARD_NONE;
478
479 /** The window that is currently dismissing the keyguard. Dismissing the keyguard must only
480 * be done once per window. */
481 private WindowState mWinDismissingKeyguard;
482
Craig Mautnerc9457fa2014-06-06 14:27:48 -0700483 /** The window that is currently showing "over" the keyguard. If there is an app window
484 * belonging to another app on top of this the keyguard shows. If there is a fullscreen
485 * app window under this, still dismiss the keyguard but don't show the app underneath. Show
486 * the wallpaper. */
487 private WindowState mWinShowWhenLocked;
488
Dianne Hackborn7ad44382012-10-18 17:46:00 -0700489 boolean mShowingLockscreen;
490 boolean mShowingDream;
491 boolean mDreamingLockscreen;
Jim Millerab954542014-10-10 18:21:49 -0700492 boolean mKeyguardSecure;
493 boolean mKeyguardSecureIncludingHidden;
494 volatile boolean mKeyguardOccluded;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800495 boolean mHomePressed;
Jeff Browncaca8812013-05-09 13:34:33 -0700496 boolean mHomeConsumed;
497 boolean mHomeDoubleTapPending;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800498 Intent mHomeIntent;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700499 Intent mCarDockIntent;
500 Intent mDeskDockIntent;
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700501 boolean mSearchKeyShortcutPending;
502 boolean mConsumeSearchKeyUp;
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700503 boolean mAssistKeyLongPressed;
Michael Wright6a62e552014-06-03 19:19:48 -0700504 boolean mPendingMetaAction;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800505
Mike Lockwood28569302010-01-28 11:54:40 -0500506 // support for activating the lock screen while the screen is on
507 boolean mAllowLockscreenWhenOn;
508 int mLockScreenTimeout;
509 boolean mLockScreenTimerActive;
510
David Brownbaf8d092010-03-08 21:52:59 -0800511 // Behavior of ENDCALL Button. (See Settings.System.END_BUTTON_BEHAVIOR.)
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800512 int mEndcallBehavior;
David Brownbaf8d092010-03-08 21:52:59 -0800513
514 // Behavior of POWER button while in-call and screen on.
515 // (See Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR.)
516 int mIncallPowerBehavior;
517
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700518 Display mDisplay;
519
Dianne Hackborn9d132642011-04-21 17:26:39 -0700520 int mLandscapeRotation = 0; // default landscape rotation
521 int mSeascapeRotation = 0; // "other" landscape rotation, 180 degrees from mLandscapeRotation
522 int mPortraitRotation = 0; // default portrait rotation
523 int mUpsideDownRotation = 0; // "other" portrait rotation
Mitsuru Oshima831d0d92009-06-16 18:27:18 -0700524
Dianne Hackbornc652de82013-02-15 16:32:56 -0800525 int mOverscanLeft = 0;
526 int mOverscanTop = 0;
527 int mOverscanRight = 0;
528 int mOverscanBottom = 0;
529
Joe Onorato46b0d682010-11-22 17:37:27 -0800530 // What we do when the user long presses on home
Jeff Browncaca8812013-05-09 13:34:33 -0700531 private int mLongPressOnHomeBehavior;
532
533 // What we do when the user double-taps on home
534 private int mDoubleTapOnHomeBehavior;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800535
Bryce Lee584a4452014-10-21 15:55:55 -0700536 // Allowed theater mode wake actions
537 private boolean mAllowTheaterModeWakeFromKey;
538 private boolean mAllowTheaterModeWakeFromPowerKey;
539 private boolean mAllowTheaterModeWakeFromMotion;
Bryce Lee812d7022014-11-10 13:33:28 -0800540 private boolean mAllowTheaterModeWakeFromMotionWhenNotDreaming;
Bryce Lee584a4452014-10-21 15:55:55 -0700541 private boolean mAllowTheaterModeWakeFromCameraLens;
542 private boolean mAllowTheaterModeWakeFromLidSwitch;
543 private boolean mAllowTheaterModeWakeFromWakeGesture;
544
Bryce Lee55e846d2014-11-04 12:43:44 -0800545 // Whether to go to sleep entering theater mode from power button
546 private boolean mGoToSleepOnButtonPressTheaterMode;
547
Winson Chung9112ec32011-06-27 13:15:32 -0700548 // Screenshot trigger states
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700549 // Time to volume and power must be pressed within this interval of each other.
550 private static final long SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS = 150;
Winson Chung1cea2f32012-10-08 20:42:01 -0700551 // Increase the chord delay when taking a screenshot from the keyguard
552 private static final float KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER = 2.5f;
Christopher Tatee90585f2012-03-05 18:56:25 -0800553 private boolean mScreenshotChordEnabled;
Jeff Brown13f00f02014-10-31 14:45:50 -0700554 private boolean mScreenshotChordVolumeDownKeyTriggered;
555 private long mScreenshotChordVolumeDownKeyTime;
556 private boolean mScreenshotChordVolumeDownKeyConsumed;
557 private boolean mScreenshotChordVolumeUpKeyTriggered;
558 private boolean mScreenshotChordPowerKeyTriggered;
559 private long mScreenshotChordPowerKeyTime;
Winson Chung9112ec32011-06-27 13:15:32 -0700560
Michael Wrightb854e242013-02-05 17:54:02 -0800561 /* The number of steps between min and max brightness */
562 private static final int BRIGHTNESS_STEPS = 10;
563
Christopher Tate5e08af02012-09-21 17:17:22 -0700564 SettingsObserver mSettingsObserver;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800565 ShortcutManager mShortcutManager;
566 PowerManager.WakeLock mBroadcastWakeLock;
Jeff Brown13f00f02014-10-31 14:45:50 -0700567 PowerManager.WakeLock mPowerKeyWakeLock;
Jeff Brown40013652012-05-16 21:22:36 -0700568 boolean mHavePendingMediaKeyRepeatWithWakeLock;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800569
Craig Mautnerd625ab22013-09-06 13:40:31 -0700570 private int mCurrentUserId;
571
Justin Kohd378ad72013-04-01 12:18:26 -0700572 // Maps global key codes to the components that will handle them.
573 private GlobalKeyManager mGlobalKeyManager;
574
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700575 // Fallback actions by key code.
576 private final SparseArray<KeyCharacterMap.FallbackAction> mFallbackActions =
577 new SparseArray<KeyCharacterMap.FallbackAction>();
Jeff Brown49ed71d2010-12-06 17:13:33 -0800578
Jorim Jaggi76a16232014-08-08 17:00:47 +0200579 private final LogDecelerateInterpolator mLogDecelerateInterpolator
580 = new LogDecelerateInterpolator(100, 0);
581
Jeff Brown70825162012-03-28 17:27:48 -0700582 private static final int MSG_ENABLE_POINTER_LOCATION = 1;
583 private static final int MSG_DISABLE_POINTER_LOCATION = 2;
Jeff Brown40013652012-05-16 21:22:36 -0700584 private static final int MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK = 3;
585 private static final int MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK = 4;
Craig Mautner8a0da012014-05-31 15:13:37 -0700586 private static final int MSG_KEYGUARD_DRAWN_COMPLETE = 5;
587 private static final int MSG_KEYGUARD_DRAWN_TIMEOUT = 6;
588 private static final int MSG_WINDOW_MANAGER_DRAWN_COMPLETE = 7;
Craig Mautner84984fa2014-06-19 11:19:20 -0700589 private static final int MSG_DISPATCH_SHOW_RECENTS = 9;
Alan Viverettee34560b22014-07-10 14:50:06 -0700590 private static final int MSG_DISPATCH_SHOW_GLOBAL_ACTIONS = 10;
Craig Mautnera631d492014-08-05 15:16:01 -0700591 private static final int MSG_HIDE_BOOT_MESSAGE = 11;
Michael Wright869a67c2014-08-26 19:33:06 -0700592 private static final int MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK = 12;
Jeff Brown13f00f02014-10-31 14:45:50 -0700593 private static final int MSG_POWER_DELAYED_PRESS = 13;
594 private static final int MSG_POWER_LONG_PRESS = 14;
Jeff Brown70825162012-03-28 17:27:48 -0700595
596 private class PolicyHandler extends Handler {
597 @Override
598 public void handleMessage(Message msg) {
599 switch (msg.what) {
600 case MSG_ENABLE_POINTER_LOCATION:
601 enablePointerLocation();
602 break;
603 case MSG_DISABLE_POINTER_LOCATION:
604 disablePointerLocation();
605 break;
Jeff Brown40013652012-05-16 21:22:36 -0700606 case MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK:
607 dispatchMediaKeyWithWakeLock((KeyEvent)msg.obj);
608 break;
609 case MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK:
610 dispatchMediaKeyRepeatWithWakeLock((KeyEvent)msg.obj);
611 break;
Craig Mautner84984fa2014-06-19 11:19:20 -0700612 case MSG_DISPATCH_SHOW_RECENTS:
613 showRecentApps(false);
614 break;
Alan Viverettee34560b22014-07-10 14:50:06 -0700615 case MSG_DISPATCH_SHOW_GLOBAL_ACTIONS:
616 showGlobalActionsInternal();
617 break;
Craig Mautner8a0da012014-05-31 15:13:37 -0700618 case MSG_KEYGUARD_DRAWN_COMPLETE:
619 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mKeyguardDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700620 finishKeyguardDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700621 break;
622 case MSG_KEYGUARD_DRAWN_TIMEOUT:
623 Slog.w(TAG, "Keyguard drawn timeout. Setting mKeyguardDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700624 finishKeyguardDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700625 break;
626 case MSG_WINDOW_MANAGER_DRAWN_COMPLETE:
627 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mWindowManagerDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700628 finishWindowsDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700629 break;
Craig Mautnera631d492014-08-05 15:16:01 -0700630 case MSG_HIDE_BOOT_MESSAGE:
631 handleHideBootMessage();
632 break;
Michael Wright869a67c2014-08-26 19:33:06 -0700633 case MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK:
634 launchVoiceAssistWithWakeLock(msg.arg1 != 0);
635 break;
Jeff Brown13f00f02014-10-31 14:45:50 -0700636 case MSG_POWER_DELAYED_PRESS:
637 powerPress((Long)msg.obj, msg.arg1 != 0, msg.arg2);
638 finishPowerKeyPress();
639 break;
640 case MSG_POWER_LONG_PRESS:
641 powerLongPress();
642 break;
Jeff Brown70825162012-03-28 17:27:48 -0700643 }
644 }
645 }
646
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800647 private UEventObserver mHDMIObserver = new UEventObserver() {
648 @Override
649 public void onUEvent(UEventObserver.UEvent event) {
650 setHdmiPlugged("1".equals(event.get("SWITCH_STATE")));
651 }
652 };
653
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800654 class SettingsObserver extends ContentObserver {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800655 SettingsObserver(Handler handler) {
656 super(handler);
657 }
David Brownbaf8d092010-03-08 21:52:59 -0800658
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800659 void observe() {
Christopher Tate5e08af02012-09-21 17:17:22 -0700660 // Observe all users' changes
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800661 ContentResolver resolver = mContext.getContentResolver();
662 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700663 Settings.System.END_BUTTON_BEHAVIOR), false, this,
664 UserHandle.USER_ALL);
David Brownbaf8d092010-03-08 21:52:59 -0800665 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700666 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR), false, this,
667 UserHandle.USER_ALL);
Jeff Browna20dda42014-05-27 20:57:24 -0700668 resolver.registerContentObserver(Settings.Secure.getUriFor(
669 Settings.Secure.WAKE_GESTURE_ENABLED), false, this,
670 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800671 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700672 Settings.System.ACCELEROMETER_ROTATION), false, this,
673 UserHandle.USER_ALL);
Mike Lockwood28569302010-01-28 11:54:40 -0500674 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700675 Settings.System.USER_ROTATION), false, this,
676 UserHandle.USER_ALL);
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400677 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700678 Settings.System.SCREEN_OFF_TIMEOUT), false, this,
679 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800680 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700681 Settings.System.POINTER_LOCATION), false, this,
682 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800683 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700684 Settings.Secure.DEFAULT_INPUT_METHOD), false, this,
685 UserHandle.USER_ALL);
John Spurlockd9b70bd2014-02-06 17:02:44 -0500686 resolver.registerContentObserver(Settings.Secure.getUriFor(
John Spurlockf1a36642013-10-12 17:50:42 -0400687 Settings.Secure.IMMERSIVE_MODE_CONFIRMATIONS), false, this,
Christopher Tate5e08af02012-09-21 17:17:22 -0700688 UserHandle.USER_ALL);
John Spurlockc6d1c602014-01-17 15:22:06 -0500689 resolver.registerContentObserver(Settings.Global.getUriFor(
690 Settings.Global.POLICY_CONTROL), false, this,
691 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800692 updateSettings();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800693 }
694
695 @Override public void onChange(boolean selfChange) {
Dianne Hackbornc777e072010-02-12 13:07:59 -0800696 updateSettings();
Jeff Brown01a98dd2011-09-20 15:08:29 -0700697 updateRotation(false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800698 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800699 }
Craig Mautner967212c2013-04-13 21:10:58 -0700700
Jeff Browna20dda42014-05-27 20:57:24 -0700701 class MyWakeGestureListener extends WakeGestureListener {
702 MyWakeGestureListener(Context context, Handler handler) {
703 super(context, handler);
704 }
705
706 @Override
707 public void onWakeUp() {
708 synchronized (mLock) {
709 if (shouldEnableWakeGestureLp()) {
Jeff Browne07b94b2014-06-18 15:56:27 -0700710 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
Bryce Lee584a4452014-10-21 15:55:55 -0700711 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromWakeGesture);
Jeff Browna20dda42014-05-27 20:57:24 -0700712 }
713 }
714 }
715 }
716
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800717 class MyOrientationListener extends WindowOrientationListener {
Craig Mautnereee29c42013-01-17 14:44:34 -0800718 MyOrientationListener(Context context, Handler handler) {
719 super(context, handler);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800720 }
Craig Mautner967212c2013-04-13 21:10:58 -0700721
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800722 @Override
Jeff Brownc0347aa2011-09-23 17:26:09 -0700723 public void onProposedRotationChanged(int rotation) {
Craig Mautnereda67292013-04-28 13:50:14 -0700724 if (localLOGV) Slog.v(TAG, "onProposedRotationChanged, rotation=" + rotation);
Jeff Brown01a98dd2011-09-20 15:08:29 -0700725 updateRotation(false);
726 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800727 }
728 MyOrientationListener mOrientationListener;
729
Jorim Jaggi24bec7c2015-02-04 12:40:14 +0100730 private final StatusBarController mStatusBarController = new StatusBarController();
John Spurlock5b9145b2013-08-20 15:13:47 -0400731
John Spurlock27735a42013-08-14 17:57:38 -0400732 private final BarController mNavigationBarController = new BarController("NavigationBar",
John Spurlock5b9145b2013-08-20 15:13:47 -0400733 View.NAVIGATION_BAR_TRANSIENT,
734 View.NAVIGATION_BAR_UNHIDE,
John Spurlockbd957402013-10-03 11:38:39 -0400735 View.NAVIGATION_BAR_TRANSLUCENT,
736 StatusBarManager.WINDOW_NAVIGATION_BAR,
737 WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
John Spurlock5b9145b2013-08-20 15:13:47 -0400738
John Spurlockf1a36642013-10-12 17:50:42 -0400739 private ImmersiveModeConfirmation mImmersiveModeConfirmation;
John Spurlock32beb2c2013-03-11 10:16:47 -0400740
Craig Mautner037aa8d2013-06-07 10:35:44 -0700741 private SystemGesturesPointerEventListener mSystemGestures;
John Spurlock32beb2c2013-03-11 10:16:47 -0400742
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700743 IStatusBarService getStatusBarService() {
744 synchronized (mServiceAquireLock) {
745 if (mStatusBarService == null) {
746 mStatusBarService = IStatusBarService.Stub.asInterface(
747 ServiceManager.getService("statusbar"));
748 }
749 return mStatusBarService;
750 }
751 }
752
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700753 /*
754 * We always let the sensor be switched on by default except when
755 * the user has explicitly disabled sensor based rotation or when the
756 * screen is switched off.
757 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700758 boolean needSensorRunningLp() {
Jeff Brownbcdfc622014-03-06 19:13:04 -0800759 if (mSupportAutoRotation) {
760 if (mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
761 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
762 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT
763 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) {
764 // If the application has explicitly requested to follow the
765 // orientation, then we need to turn the sensor on.
766 return true;
767 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800768 }
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700769 if ((mCarDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_CAR) ||
Jeff Brown1a693182011-11-08 14:44:16 -0800770 (mDeskDockEnablesAccelerometer && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
771 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
772 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK))) {
Mike Lockwoode9867d22009-09-20 01:59:02 -0400773 // enable accelerometer if we are docked in a dock that enables accelerometer
774 // orientation management,
775 return true;
776 }
Jeff Brown207673cd2012-06-05 17:47:11 -0700777 if (mUserRotationMode == USER_ROTATION_LOCKED) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800778 // If the setting for using the sensor by default is enabled, then
779 // we will always leave it on. Note that the user could go to
780 // a window that forces an orientation that does not use the
781 // sensor and in theory we could turn it off... however, when next
782 // turning it on we won't have a good value for the current
783 // orientation for a little bit, which can cause orientation
784 // changes to lag, so we'd like to keep it always on. (It will
785 // still be turned off when the screen is off.)
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700786 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800787 }
Jeff Brownbcdfc622014-03-06 19:13:04 -0800788 return mSupportAutoRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800789 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700790
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800791 /*
792 * Various use cases for invoking this function
793 * screen turning off, should always disable listeners if already enabled
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700794 * screen turned on and current app has sensor based orientation, enable listeners
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800795 * if not already enabled
796 * screen turned on and current app does not have sensor orientation, disable listeners if
797 * already enabled
798 * screen turning on and current app has sensor based orientation, enable listeners if needed
799 * screen turning on and current app has nosensor based orientation, do nothing
800 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700801 void updateOrientationListenerLp() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800802 if (!mOrientationListener.canDetectOrientation()) {
803 // If sensor is turned off or nonexistent for some reason
804 return;
805 }
806 //Could have been invoked due to screen turning on or off or
807 //change of the currently visible window's orientation
Jeff Brown3ee549c2014-09-22 20:14:39 -0700808 if (localLOGV) Slog.v(TAG, "mScreenOnEarly=" + mScreenOnEarly
809 + ", mAwake=" + mAwake + ", mCurrentAppOrientation=" + mCurrentAppOrientation
810 + ", mOrientationSensorEnabled=" + mOrientationSensorEnabled);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800811 boolean disable = true;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700812 if (mScreenOnEarly && mAwake) {
The Android Open Source Project0727d222009-03-11 12:11:58 -0700813 if (needSensorRunningLp()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800814 disable = false;
815 //enable listener if not already enabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700816 if (!mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800817 mOrientationListener.enable();
Craig Mautnereda67292013-04-28 13:50:14 -0700818 if(localLOGV) Slog.v(TAG, "Enabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800819 mOrientationSensorEnabled = true;
820 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700821 }
822 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800823 //check if sensors need to be disabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700824 if (disable && mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800825 mOrientationListener.disable();
Craig Mautnereda67292013-04-28 13:50:14 -0700826 if(localLOGV) Slog.v(TAG, "Disabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800827 mOrientationSensorEnabled = false;
828 }
829 }
830
Jeff Brown13f00f02014-10-31 14:45:50 -0700831 private void interceptPowerKeyDown(KeyEvent event, boolean interactive) {
832 // Hold a wake lock until the power key is released.
833 if (!mPowerKeyWakeLock.isHeld()) {
834 mPowerKeyWakeLock.acquire();
835 }
836
837 // Cancel multi-press detection timeout.
838 if (mPowerKeyPressCounter != 0) {
839 mHandler.removeMessages(MSG_POWER_DELAYED_PRESS);
840 }
841
842 // Detect user pressing the power button in panic when an application has
843 // taken over the whole screen.
844 boolean panic = mImmersiveModeConfirmation.onPowerKeyDown(interactive,
Craig Mautner0124980e92014-11-30 21:15:34 -0800845 SystemClock.elapsedRealtime(), isImmersiveMode(mLastSystemUiFlags));
Jeff Brown13f00f02014-10-31 14:45:50 -0700846 if (panic) {
847 mHandler.post(mRequestTransientNav);
848 }
849
850 // Latch power key state to detect screenshot chord.
851 if (interactive && !mScreenshotChordPowerKeyTriggered
852 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
853 mScreenshotChordPowerKeyTriggered = true;
854 mScreenshotChordPowerKeyTime = event.getDownTime();
855 interceptScreenshotChord();
856 }
857
858 // Stop ringing or end call if configured to do so when power is pressed.
859 TelecomManager telecomManager = getTelecommService();
860 boolean hungUp = false;
861 if (telecomManager != null) {
862 if (telecomManager.isRinging()) {
863 // Pressing Power while there's a ringing incoming
864 // call should silence the ringer.
865 telecomManager.silenceRinger();
866 } else if ((mIncallPowerBehavior
867 & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0
868 && telecomManager.isInCall() && interactive) {
869 // Otherwise, if "Power button ends call" is enabled,
870 // the Power button will hang up any current active call.
871 hungUp = telecomManager.endCall();
872 }
873 }
874
875 // If the power key has still not yet been handled, then detect short
876 // press, long press, or multi press and decide what to do.
877 mPowerKeyHandled = hungUp || mScreenshotChordVolumeDownKeyTriggered
878 || mScreenshotChordVolumeUpKeyTriggered;
879 if (!mPowerKeyHandled) {
880 if (interactive) {
881 // When interactive, we're already awake.
882 // Wait for a long press or for the button to be released to decide what to do.
883 if (hasLongPressOnPowerBehavior()) {
884 Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS);
885 msg.setAsynchronous(true);
886 mHandler.sendMessageDelayed(msg,
887 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
888 }
889 } else {
Bryce Leed9268e32014-11-17 17:40:59 -0800890 wakeUpFromPowerKey(event.getDownTime());
Jeff Brown13f00f02014-10-31 14:45:50 -0700891 final int maxCount = getMaxMultiPressPowerCount();
Bryce Leed9268e32014-11-17 17:40:59 -0800892
Jeff Brown13f00f02014-10-31 14:45:50 -0700893 if (maxCount <= 1) {
Jeff Brown13f00f02014-10-31 14:45:50 -0700894 mPowerKeyHandled = true;
Bryce Leed9268e32014-11-17 17:40:59 -0800895 } else {
896 mBeganFromNonInteractive = true;
Jeff Brown13f00f02014-10-31 14:45:50 -0700897 }
898 }
Jeff Brown4d396052010-10-29 21:50:21 -0700899 }
900 }
901
Jeff Brown13f00f02014-10-31 14:45:50 -0700902 private void interceptPowerKeyUp(KeyEvent event, boolean interactive, boolean canceled) {
903 final boolean handled = canceled || mPowerKeyHandled;
904 mScreenshotChordPowerKeyTriggered = false;
905 cancelPendingScreenshotChordAction();
906 cancelPendingPowerKeyAction();
907
908 if (!handled) {
909 // Figure out how to handle the key now that it has been released.
910 mPowerKeyPressCounter += 1;
911
912 final int maxCount = getMaxMultiPressPowerCount();
913 final long eventTime = event.getDownTime();
914 if (mPowerKeyPressCounter < maxCount) {
915 // This could be a multi-press. Wait a little bit longer to confirm.
916 // Continue holding the wake lock.
917 Message msg = mHandler.obtainMessage(MSG_POWER_DELAYED_PRESS,
918 interactive ? 1 : 0, mPowerKeyPressCounter, eventTime);
919 msg.setAsynchronous(true);
920 mHandler.sendMessageDelayed(msg, ViewConfiguration.getDoubleTapTimeout());
921 return;
922 }
923
924 // No other actions. Handle it immediately.
925 powerPress(eventTime, interactive, mPowerKeyPressCounter);
Jeff Brown4d396052010-10-29 21:50:21 -0700926 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700927
928 // Done. Reset our state.
929 finishPowerKeyPress();
930 }
931
932 private void finishPowerKeyPress() {
Bryce Leed9268e32014-11-17 17:40:59 -0800933 mBeganFromNonInteractive = false;
Jeff Brown13f00f02014-10-31 14:45:50 -0700934 mPowerKeyPressCounter = 0;
935 if (mPowerKeyWakeLock.isHeld()) {
936 mPowerKeyWakeLock.release();
937 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700938 }
939
940 private void cancelPendingPowerKeyAction() {
941 if (!mPowerKeyHandled) {
Jeff Brown13f00f02014-10-31 14:45:50 -0700942 mPowerKeyHandled = true;
943 mHandler.removeMessages(MSG_POWER_LONG_PRESS);
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700944 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700945 }
946
947 private void powerPress(long eventTime, boolean interactive, int count) {
948 if (mScreenOnEarly && !mScreenOnFully) {
949 Slog.i(TAG, "Suppressed redundant power key press while "
950 + "already in the process of turning the screen on.");
951 return;
Jeff Brownff204712011-10-25 21:27:54 -0700952 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700953
954 if (count == 2) {
955 powerMultiPressAction(eventTime, interactive, mDoublePressOnPowerBehavior);
956 } else if (count == 3) {
957 powerMultiPressAction(eventTime, interactive, mTriplePressOnPowerBehavior);
Bryce Leed9268e32014-11-17 17:40:59 -0800958 } else if (interactive && !mBeganFromNonInteractive) {
Jeff Brown13f00f02014-10-31 14:45:50 -0700959 switch (mShortPressOnPowerBehavior) {
960 case SHORT_PRESS_POWER_NOTHING:
961 break;
962 case SHORT_PRESS_POWER_GO_TO_SLEEP:
963 mPowerManager.goToSleep(eventTime,
964 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
965 break;
966 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP:
967 mPowerManager.goToSleep(eventTime,
968 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
969 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
970 break;
971 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME:
972 mPowerManager.goToSleep(eventTime,
973 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
974 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
975 launchHomeFromHotKey();
976 break;
Bryce Lee01b0c5f2015-02-05 18:24:04 -0800977 case SHORT_PRESS_POWER_GO_HOME:
978 launchHomeFromHotKey();
979 break;
Jeff Brown13f00f02014-10-31 14:45:50 -0700980 }
981 }
982 }
983
984 private void powerMultiPressAction(long eventTime, boolean interactive, int behavior) {
985 switch (behavior) {
986 case MULTI_PRESS_POWER_NOTHING:
987 break;
988 case MULTI_PRESS_POWER_THEATER_MODE:
989 if (isTheaterModeEnabled()) {
990 Slog.i(TAG, "Toggling theater mode off.");
991 Settings.Global.putInt(mContext.getContentResolver(),
992 Settings.Global.THEATER_MODE_ON, 0);
993 if (!interactive) {
994 wakeUpFromPowerKey(eventTime);
995 }
996 } else {
997 Slog.i(TAG, "Toggling theater mode on.");
998 Settings.Global.putInt(mContext.getContentResolver(),
999 Settings.Global.THEATER_MODE_ON, 1);
Bryce Lee55e846d2014-11-04 12:43:44 -08001000
1001 if (mGoToSleepOnButtonPressTheaterMode && interactive) {
Jeff Brown13f00f02014-10-31 14:45:50 -07001002 mPowerManager.goToSleep(eventTime,
1003 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
1004 }
1005 }
1006 break;
1007 case MULTI_PRESS_POWER_BRIGHTNESS_BOOST:
Jeff Brown7b5be5e2014-11-12 18:45:31 -08001008 Slog.i(TAG, "Starting brightness boost.");
1009 if (!interactive) {
1010 wakeUpFromPowerKey(eventTime);
1011 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001012 mPowerManager.boostScreenBrightness(eventTime);
1013 break;
1014 }
1015 }
1016
1017 private int getMaxMultiPressPowerCount() {
1018 if (mTriplePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) {
1019 return 3;
1020 }
1021 if (mDoublePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) {
1022 return 2;
1023 }
1024 return 1;
1025 }
1026
1027 private void powerLongPress() {
1028 final int behavior = getResolvedLongPressOnPowerBehavior();
1029 switch (behavior) {
1030 case LONG_PRESS_POWER_NOTHING:
1031 break;
1032 case LONG_PRESS_POWER_GLOBAL_ACTIONS:
1033 mPowerKeyHandled = true;
1034 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
1035 performAuditoryFeedbackForAccessibilityIfNeed();
1036 }
1037 showGlobalActionsInternal();
1038 break;
1039 case LONG_PRESS_POWER_SHUT_OFF:
1040 case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM:
1041 mPowerKeyHandled = true;
1042 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
1043 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
1044 mWindowManagerFuncs.shutdown(behavior == LONG_PRESS_POWER_SHUT_OFF);
1045 break;
1046 }
1047 }
1048
1049 private int getResolvedLongPressOnPowerBehavior() {
1050 if (FactoryTest.isLongPressOnPowerOffEnabled()) {
1051 return LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM;
1052 }
1053 return mLongPressOnPowerBehavior;
1054 }
1055
1056 private boolean hasLongPressOnPowerBehavior() {
1057 return getResolvedLongPressOnPowerBehavior() != LONG_PRESS_POWER_NOTHING;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001058 }
1059
1060 private void interceptScreenshotChord() {
Christopher Tatee90585f2012-03-05 18:56:25 -08001061 if (mScreenshotChordEnabled
Jeff Brown13f00f02014-10-31 14:45:50 -07001062 && mScreenshotChordVolumeDownKeyTriggered && mScreenshotChordPowerKeyTriggered
1063 && !mScreenshotChordVolumeUpKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001064 final long now = SystemClock.uptimeMillis();
Jeff Brown13f00f02014-10-31 14:45:50 -07001065 if (now <= mScreenshotChordVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS
1066 && now <= mScreenshotChordPowerKeyTime
1067 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) {
1068 mScreenshotChordVolumeDownKeyConsumed = true;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001069 cancelPendingPowerKeyAction();
1070
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001071 mHandler.postDelayed(mScreenshotRunnable, getScreenshotChordLongPressDelay());
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001072 }
1073 }
1074 }
1075
Winson Chung1cea2f32012-10-08 20:42:01 -07001076 private long getScreenshotChordLongPressDelay() {
Jim Miller5ecd8112013-01-09 18:50:26 -08001077 if (mKeyguardDelegate.isShowing()) {
Winson Chung1cea2f32012-10-08 20:42:01 -07001078 // Double the time it takes to take a screenshot from the keyguard
1079 return (long) (KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER *
Justin Kohfeabd2c2014-05-02 10:02:44 -07001080 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Winson Chung1cea2f32012-10-08 20:42:01 -07001081 }
Justin Kohfeabd2c2014-05-02 10:02:44 -07001082 return ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout();
Winson Chung1cea2f32012-10-08 20:42:01 -07001083 }
1084
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001085 private void cancelPendingScreenshotChordAction() {
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001086 mHandler.removeCallbacks(mScreenshotRunnable);
Jeff Brown4d396052010-10-29 21:50:21 -07001087 }
1088
Jeff Brown13f00f02014-10-31 14:45:50 -07001089 private final Runnable mEndCallLongPress = new Runnable() {
Craig Mautnerf1b67412012-09-19 13:18:29 -07001090 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001091 public void run() {
Jeff Brown13f00f02014-10-31 14:45:50 -07001092 mEndCallKeyHandled = true;
1093 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
1094 performAuditoryFeedbackForAccessibilityIfNeed();
Joe Onoratod208e702010-10-08 16:22:43 -04001095 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001096 showGlobalActionsInternal();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001097 }
1098 };
1099
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001100 private final Runnable mScreenshotRunnable = new Runnable() {
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001101 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001102 public void run() {
1103 takeScreenshot();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001104 }
1105 };
1106
Alan Viverettee34560b22014-07-10 14:50:06 -07001107 @Override
1108 public void showGlobalActions() {
1109 mHandler.removeMessages(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
1110 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
1111 }
1112
1113 void showGlobalActionsInternal() {
1114 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001115 if (mGlobalActions == null) {
Jeff Brown7304c342012-05-11 18:42:42 -07001116 mGlobalActions = new GlobalActions(mContext, mWindowManagerFuncs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001117 }
Jim Millerab954542014-10-10 18:21:49 -07001118 final boolean keyguardShowing = isKeyguardShowingAndNotOccluded();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001119 mGlobalActions.showDialog(keyguardShowing, isDeviceProvisioned());
1120 if (keyguardShowing) {
1121 // since it took two seconds of long press to bring this up,
1122 // poke the wake lock so they have some time to see the dialog.
Jim Miller25190572013-02-28 17:36:24 -08001123 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001124 }
1125 }
1126
1127 boolean isDeviceProvisioned() {
Jeff Brownbf6f6f92012-09-25 15:03:20 -07001128 return Settings.Global.getInt(
1129 mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001130 }
1131
Maurice Lam99c6e072014-04-28 18:24:28 -07001132 boolean isUserSetupComplete() {
1133 return Settings.Secure.getIntForUser(mContext.getContentResolver(),
1134 Settings.Secure.USER_SETUP_COMPLETE, 0, UserHandle.USER_CURRENT) != 0;
1135 }
1136
Jeff Brown13f00f02014-10-31 14:45:50 -07001137 private void handleShortPressOnHome() {
1138 // If there's a dream running then use home to escape the dream
1139 // but don't actually go home.
1140 if (mDreamManagerInternal != null && mDreamManagerInternal.isDreaming()) {
1141 mDreamManagerInternal.stopDream(false /*immediate*/);
1142 return;
1143 }
1144
1145 // Go home!
1146 launchHomeFromHotKey();
1147 }
1148
Patrick Dubroyece94522011-02-23 18:35:01 -08001149 private void handleLongPressOnHome() {
Joe Onorato46b0d682010-11-22 17:37:27 -08001150 if (mLongPressOnHomeBehavior != LONG_PRESS_HOME_NOTHING) {
Jeff Browncaca8812013-05-09 13:34:33 -07001151 mHomeConsumed = true;
Joe Onorato46b0d682010-11-22 17:37:27 -08001152 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
Patrick Dubroyece94522011-02-23 18:35:01 -08001153
Jeff Browncaca8812013-05-09 13:34:33 -07001154 if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI) {
1155 toggleRecentApps();
1156 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_ASSIST) {
1157 launchAssistAction();
Jim Millere6ad1a82010-08-20 19:25:39 -07001158 }
1159 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001160 }
Patrick Dubroyece94522011-02-23 18:35:01 -08001161
Jeff Browncaca8812013-05-09 13:34:33 -07001162 private void handleDoubleTapOnHome() {
1163 if (mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1164 mHomeConsumed = true;
1165 toggleRecentApps();
1166 }
1167 }
1168
1169 private final Runnable mHomeDoubleTapTimeoutRunnable = new Runnable() {
1170 @Override
1171 public void run() {
1172 if (mHomeDoubleTapPending) {
1173 mHomeDoubleTapPending = false;
Jeff Brown13f00f02014-10-31 14:45:50 -07001174 handleShortPressOnHome();
Jeff Browncaca8812013-05-09 13:34:33 -07001175 }
1176 }
1177 };
1178
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001179 /** {@inheritDoc} */
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001180 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001181 public void init(Context context, IWindowManager windowManager,
Jeff Brown96307042012-07-27 15:51:34 -07001182 WindowManagerFuncs windowManagerFuncs) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001183 mContext = context;
1184 mWindowManager = windowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -07001185 mWindowManagerFuncs = windowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -07001186 mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class);
Jose Lima9546b202014-07-02 17:21:51 -07001187 mDreamManagerInternal = LocalServices.getService(DreamManagerInternal.class);
Craig Mautner8a0da012014-05-31 15:13:37 -07001188
Jeff Brown70825162012-03-28 17:27:48 -07001189 mHandler = new PolicyHandler();
Jeff Browna20dda42014-05-27 20:57:24 -07001190 mWakeGestureListener = new MyWakeGestureListener(mContext, mHandler);
Craig Mautnereee29c42013-01-17 14:44:34 -08001191 mOrientationListener = new MyOrientationListener(mContext, mHandler);
Jeff Brownc0347aa2011-09-23 17:26:09 -07001192 try {
1193 mOrientationListener.setCurrentRotation(windowManager.getRotation());
1194 } catch (RemoteException ex) { }
Christopher Tate5e08af02012-09-21 17:17:22 -07001195 mSettingsObserver = new SettingsObserver(mHandler);
1196 mSettingsObserver.observe();
Svetoslav683914b2015-01-15 14:22:26 -08001197 mShortcutManager = new ShortcutManager(context);
Daniel Sandler6396c722013-04-16 20:19:09 -04001198 mUiMode = context.getResources().getInteger(
1199 com.android.internal.R.integer.config_defaultUiModeType);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001200 mHomeIntent = new Intent(Intent.ACTION_MAIN, null);
1201 mHomeIntent.addCategory(Intent.CATEGORY_HOME);
1202 mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1203 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07001204 mCarDockIntent = new Intent(Intent.ACTION_MAIN, null);
1205 mCarDockIntent.addCategory(Intent.CATEGORY_CAR_DOCK);
1206 mCarDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1207 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
1208 mDeskDockIntent = new Intent(Intent.ACTION_MAIN, null);
1209 mDeskDockIntent.addCategory(Intent.CATEGORY_DESK_DOCK);
1210 mDeskDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1211 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Jim Millere6ad1a82010-08-20 19:25:39 -07001212
Jeff Brown96307042012-07-27 15:51:34 -07001213 mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
1214 mBroadcastWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001215 "PhoneWindowManager.mBroadcastWakeLock");
Jeff Brown13f00f02014-10-31 14:45:50 -07001216 mPowerKeyWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
1217 "PhoneWindowManager.mPowerKeyWakeLock");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001218 mEnableShiftMenuBugReports = "1".equals(SystemProperties.get("ro.debuggable"));
Jeff Brownbcdfc622014-03-06 19:13:04 -08001219 mSupportAutoRotation = mContext.getResources().getBoolean(
1220 com.android.internal.R.bool.config_supportAutoRotation);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001221 mLidOpenRotation = readRotation(
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001222 com.android.internal.R.integer.config_lidOpenRotation);
1223 mCarDockRotation = readRotation(
1224 com.android.internal.R.integer.config_carDockRotation);
1225 mDeskDockRotation = readRotation(
1226 com.android.internal.R.integer.config_deskDockRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001227 mUndockedHdmiRotation = readRotation(
1228 com.android.internal.R.integer.config_undockedHdmiRotation);
Mike Lockwoode9867d22009-09-20 01:59:02 -04001229 mCarDockEnablesAccelerometer = mContext.getResources().getBoolean(
1230 com.android.internal.R.bool.config_carDockEnablesAccelerometer);
1231 mDeskDockEnablesAccelerometer = mContext.getResources().getBoolean(
1232 com.android.internal.R.bool.config_deskDockEnablesAccelerometer);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001233 mLidKeyboardAccessibility = mContext.getResources().getInteger(
1234 com.android.internal.R.integer.config_lidKeyboardAccessibility);
1235 mLidNavigationAccessibility = mContext.getResources().getInteger(
1236 com.android.internal.R.integer.config_lidNavigationAccessibility);
Jeff Brownc458ce92012-04-30 14:58:40 -07001237 mLidControlsSleep = mContext.getResources().getBoolean(
1238 com.android.internal.R.bool.config_lidControlsSleep);
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04001239 mTranslucentDecorEnabled = mContext.getResources().getBoolean(
1240 com.android.internal.R.bool.config_enableTranslucentDecor);
Bryce Lee584a4452014-10-21 15:55:55 -07001241
1242 mAllowTheaterModeWakeFromKey = mContext.getResources().getBoolean(
1243 com.android.internal.R.bool.config_allowTheaterModeWakeFromKey);
1244 mAllowTheaterModeWakeFromPowerKey = mAllowTheaterModeWakeFromKey
1245 || mContext.getResources().getBoolean(
1246 com.android.internal.R.bool.config_allowTheaterModeWakeFromPowerKey);
1247 mAllowTheaterModeWakeFromMotion = mContext.getResources().getBoolean(
1248 com.android.internal.R.bool.config_allowTheaterModeWakeFromMotion);
Bryce Lee812d7022014-11-10 13:33:28 -08001249 mAllowTheaterModeWakeFromMotionWhenNotDreaming = mContext.getResources().getBoolean(
1250 com.android.internal.R.bool.config_allowTheaterModeWakeFromMotionWhenNotDreaming);
Bryce Lee584a4452014-10-21 15:55:55 -07001251 mAllowTheaterModeWakeFromCameraLens = mContext.getResources().getBoolean(
1252 com.android.internal.R.bool.config_allowTheaterModeWakeFromCameraLens);
1253 mAllowTheaterModeWakeFromLidSwitch = mContext.getResources().getBoolean(
1254 com.android.internal.R.bool.config_allowTheaterModeWakeFromLidSwitch);
1255 mAllowTheaterModeWakeFromWakeGesture = mContext.getResources().getBoolean(
1256 com.android.internal.R.bool.config_allowTheaterModeWakeFromGesture);
1257
Bryce Lee55e846d2014-11-04 12:43:44 -08001258 mGoToSleepOnButtonPressTheaterMode = mContext.getResources().getBoolean(
1259 com.android.internal.R.bool.config_goToSleepOnButtonPressTheaterMode);
1260
Jeff Brown13f00f02014-10-31 14:45:50 -07001261 mShortPressOnPowerBehavior = mContext.getResources().getInteger(
1262 com.android.internal.R.integer.config_shortPressOnPowerBehavior);
1263 mLongPressOnPowerBehavior = mContext.getResources().getInteger(
1264 com.android.internal.R.integer.config_longPressOnPowerBehavior);
1265 mDoublePressOnPowerBehavior = mContext.getResources().getInteger(
1266 com.android.internal.R.integer.config_doublePressOnPowerBehavior);
1267 mTriplePressOnPowerBehavior = mContext.getResources().getInteger(
1268 com.android.internal.R.integer.config_triplePressOnPowerBehavior);
1269
John Spurlock61560172015-02-06 19:46:04 -05001270 mUseTvRouting = AudioSystem.getPlatformType(mContext) == AudioSystem.PLATFORM_TELEVISION;
RoboErik001c59c2015-01-26 15:53:51 -08001271 mUseMasterVolume = mContext.getResources().getBoolean(
1272 com.android.internal.R.bool.config_useMasterVolume);
1273
Jeff Brownf71343d2013-05-31 17:59:11 -07001274 readConfigurationDependentBehaviors();
Jeff Browncaca8812013-05-09 13:34:33 -07001275
Svetoslav8e3feb12014-02-24 13:46:47 -08001276 mAccessibilityManager = (AccessibilityManager) context.getSystemService(
1277 Context.ACCESSIBILITY_SERVICE);
1278
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001279 // register for dock events
Dianne Hackborn78968392010-03-04 20:47:56 -08001280 IntentFilter filter = new IntentFilter();
1281 filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE);
1282 filter.addAction(UiModeManager.ACTION_EXIT_CAR_MODE);
1283 filter.addAction(UiModeManager.ACTION_ENTER_DESK_MODE);
1284 filter.addAction(UiModeManager.ACTION_EXIT_DESK_MODE);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001285 filter.addAction(Intent.ACTION_DOCK_EVENT);
1286 Intent intent = context.registerReceiver(mDockReceiver, filter);
1287 if (intent != null) {
1288 // Retrieve current sticky dock event broadcast.
1289 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
1290 Intent.EXTRA_DOCK_STATE_UNDOCKED);
1291 }
Daniel Sandler7e37df52011-11-16 22:08:23 -08001292
Jeff Brown6aaf2952012-10-05 16:01:08 -07001293 // register for dream-related broadcasts
1294 filter = new IntentFilter();
1295 filter.addAction(Intent.ACTION_DREAMING_STARTED);
1296 filter.addAction(Intent.ACTION_DREAMING_STOPPED);
1297 context.registerReceiver(mDreamReceiver, filter);
1298
Christopher Tate5e08af02012-09-21 17:17:22 -07001299 // register for multiuser-relevant broadcasts
1300 filter = new IntentFilter(Intent.ACTION_USER_SWITCHED);
1301 context.registerReceiver(mMultiuserReceiver, filter);
1302
John Spurlock57306e62013-04-22 09:48:49 -04001303 // monitor for system gestures
Craig Mautner037aa8d2013-06-07 10:35:44 -07001304 mSystemGestures = new SystemGesturesPointerEventListener(context,
1305 new SystemGesturesPointerEventListener.Callbacks() {
John Spurlock57306e62013-04-22 09:48:49 -04001306 @Override
1307 public void onSwipeFromTop() {
John Spurlock04db1762013-05-13 12:46:41 -04001308 if (mStatusBar != null) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001309 requestTransientBars(mStatusBar);
John Spurlock04db1762013-05-13 12:46:41 -04001310 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04001311 }
1312 @Override
1313 public void onSwipeFromBottom() {
John Spurlock04db1762013-05-13 12:46:41 -04001314 if (mNavigationBar != null && mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001315 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001316 }
1317 }
1318 @Override
1319 public void onSwipeFromRight() {
John Spurlock04db1762013-05-13 12:46:41 -04001320 if (mNavigationBar != null && !mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001321 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001322 }
1323 }
1324 @Override
1325 public void onDebug() {
John Spurlockd67ec252013-09-05 11:31:54 -04001326 // no-op
John Spurlockad3e6cb2013-04-30 08:47:43 -04001327 }
1328 });
John Spurlockf1a36642013-10-12 17:50:42 -04001329 mImmersiveModeConfirmation = new ImmersiveModeConfirmation(mContext);
Craig Mautner037aa8d2013-06-07 10:35:44 -07001330 mWindowManagerFuncs.registerPointerEventListener(mSystemGestures);
John Spurlock32beb2c2013-03-11 10:16:47 -04001331
Jeff Brownc2346132012-04-13 01:55:38 -07001332 mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001333 mLongPressVibePattern = getLongIntArray(mContext.getResources(),
1334 com.android.internal.R.array.config_longPressVibePattern);
1335 mVirtualKeyVibePattern = getLongIntArray(mContext.getResources(),
1336 com.android.internal.R.array.config_virtualKeyVibePattern);
Amith Yamasanic33cb712010-02-10 15:21:49 -08001337 mKeyboardTapVibePattern = getLongIntArray(mContext.getResources(),
1338 com.android.internal.R.array.config_keyboardTapVibePattern);
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07001339 mClockTickVibePattern = getLongIntArray(mContext.getResources(),
1340 com.android.internal.R.array.config_clockTickVibePattern);
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07001341 mCalendarDateVibePattern = getLongIntArray(mContext.getResources(),
1342 com.android.internal.R.array.config_calendarDateVibePattern);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001343 mSafeModeDisabledVibePattern = getLongIntArray(mContext.getResources(),
1344 com.android.internal.R.array.config_safeModeDisabledVibePattern);
1345 mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(),
1346 com.android.internal.R.array.config_safeModeEnabledVibePattern);
Daniel Sandler40427442010-07-16 11:44:52 -04001347
Christopher Tatee90585f2012-03-05 18:56:25 -08001348 mScreenshotChordEnabled = mContext.getResources().getBoolean(
1349 com.android.internal.R.bool.config_enableScreenshotChord);
1350
Justin Kohd378ad72013-04-01 12:18:26 -07001351 mGlobalKeyManager = new GlobalKeyManager(mContext);
1352
Joe Onoratoea495d42011-04-06 11:41:11 -07001353 // Controls rotation and the like.
1354 initializeHdmiState();
Dianne Hackborn40011092011-09-22 13:37:48 -07001355
1356 // Match current screen state.
Craig Mautnera631d492014-08-05 15:16:01 -07001357 if (!mPowerManager.isInteractive()) {
Jeff Brown140ffc72014-05-01 15:18:00 -07001358 goingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
Dianne Hackborn40011092011-09-22 13:37:48 -07001359 }
Jorim Jaggi24bec7c2015-02-04 12:40:14 +01001360
1361 mWindowManagerInternal.registerAppTransitionListener(
1362 mStatusBarController.getAppTransitionListener());
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001363 }
1364
Jeff Brownf71343d2013-05-31 17:59:11 -07001365 /**
1366 * Read values from config.xml that may be overridden depending on
1367 * the configuration of the device.
1368 * eg. Disable long press on home goes to recents on sw600dp.
1369 */
1370 private void readConfigurationDependentBehaviors() {
1371 mLongPressOnHomeBehavior = mContext.getResources().getInteger(
1372 com.android.internal.R.integer.config_longPressOnHomeBehavior);
1373 if (mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING ||
1374 mLongPressOnHomeBehavior > LONG_PRESS_HOME_ASSIST) {
1375 mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1376 }
1377
1378 mDoubleTapOnHomeBehavior = mContext.getResources().getInteger(
1379 com.android.internal.R.integer.config_doubleTapOnHomeBehavior);
1380 if (mDoubleTapOnHomeBehavior < DOUBLE_TAP_HOME_NOTHING ||
1381 mDoubleTapOnHomeBehavior > DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1382 mDoubleTapOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1383 }
1384 }
1385
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001386 @Override
Dianne Hackborndde331c2012-08-03 14:01:57 -07001387 public void setInitialDisplaySize(Display display, int width, int height, int density) {
Jeff Brownef981a42013-08-07 14:13:37 -07001388 // This method might be called before the policy has been fully initialized
1389 // or for other displays we don't care about.
1390 if (mContext == null || display.getDisplayId() != Display.DEFAULT_DISPLAY) {
1391 return;
Dianne Hackbornc652de82013-02-15 16:32:56 -08001392 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001393 mDisplay = display;
1394
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001395 final Resources res = mContext.getResources();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001396 int shortSize, longSize;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001397 if (width > height) {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001398 shortSize = height;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001399 longSize = width;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001400 mLandscapeRotation = Surface.ROTATION_0;
1401 mSeascapeRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001402 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001403 mPortraitRotation = Surface.ROTATION_90;
1404 mUpsideDownRotation = Surface.ROTATION_270;
1405 } else {
1406 mPortraitRotation = Surface.ROTATION_270;
1407 mUpsideDownRotation = Surface.ROTATION_90;
1408 }
1409 } else {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001410 shortSize = width;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001411 longSize = height;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001412 mPortraitRotation = Surface.ROTATION_0;
1413 mUpsideDownRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001414 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001415 mLandscapeRotation = Surface.ROTATION_270;
1416 mSeascapeRotation = Surface.ROTATION_90;
1417 } else {
1418 mLandscapeRotation = Surface.ROTATION_90;
1419 mSeascapeRotation = Surface.ROTATION_270;
1420 }
1421 }
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001422
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001423 mStatusBarHeight =
1424 res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001425
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001426 // Height of the navigation bar when presented horizontally at bottom
1427 mNavigationBarHeightForRotation[mPortraitRotation] =
1428 mNavigationBarHeightForRotation[mUpsideDownRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001429 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_height);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001430 mNavigationBarHeightForRotation[mLandscapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001431 mNavigationBarHeightForRotation[mSeascapeRotation] = res.getDimensionPixelSize(
1432 com.android.internal.R.dimen.navigation_bar_height_landscape);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001433
1434 // Width of the navigation bar when presented vertically along one side
1435 mNavigationBarWidthForRotation[mPortraitRotation] =
1436 mNavigationBarWidthForRotation[mUpsideDownRotation] =
1437 mNavigationBarWidthForRotation[mLandscapeRotation] =
1438 mNavigationBarWidthForRotation[mSeascapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001439 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_width);
Daniel Sandler4a066c52012-04-20 14:49:13 -04001440
1441 // SystemUI (status bar) layout policy
Dianne Hackborndde331c2012-08-03 14:01:57 -07001442 int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / density;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001443 int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / density;
Daniel Sandler4a066c52012-04-20 14:49:13 -04001444
Devin Kimd7b12b42014-05-05 14:34:58 -07001445 // Allow the navigation bar to move on non-square small devices (phones).
1446 mNavigationBarCanMove = width != height && shortSizeDp < 600;
Daniel Sandler36412a72011-08-04 09:35:13 -04001447
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001448 mHasNavigationBar = res.getBoolean(com.android.internal.R.bool.config_showNavigationBar);
John Spurlock80f00c12013-06-13 11:10:51 -04001449 // Allow a system property to override this. Used by the emulator.
1450 // See also hasNavigationBar().
1451 String navBarOverride = SystemProperties.get("qemu.hw.mainkeys");
1452 if ("1".equals(navBarOverride)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001453 mHasNavigationBar = false;
John Spurlock80f00c12013-06-13 11:10:51 -04001454 } else if ("0".equals(navBarOverride)) {
1455 mHasNavigationBar = true;
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04001456 }
1457
Jeff Brown27f1d672012-10-17 18:32:34 -07001458 // For demo purposes, allow the rotation of the HDMI display to be controlled.
1459 // By default, HDMI locks rotation to landscape.
Erik Gilling9a41ef82011-09-26 19:21:03 -07001460 if ("portrait".equals(SystemProperties.get("persist.demo.hdmirotation"))) {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001461 mDemoHdmiRotation = mPortraitRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001462 } else {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001463 mDemoHdmiRotation = mLandscapeRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001464 }
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001465 mDemoHdmiRotationLock = SystemProperties.getBoolean("persist.demo.hdmirotationlock", false);
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001466
Chong Zhangae6119ff2014-11-11 18:54:39 -08001467 // For demo purposes, allow the rotation of the remote display to be controlled.
1468 // By default, remote display locks rotation to landscape.
1469 if ("portrait".equals(SystemProperties.get("persist.demo.remoterotation"))) {
1470 mDemoRotation = mPortraitRotation;
1471 } else {
1472 mDemoRotation = mLandscapeRotation;
1473 }
1474 mDemoRotationLock = SystemProperties.getBoolean(
1475 "persist.demo.rotationlock", false);
1476
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001477 // Only force the default orientation if the screen is xlarge, at least 960dp x 720dp, per
1478 // http://developer.android.com/guide/practices/screens_support.html#range
1479 mForceDefaultOrientation = longSizeDp >= 960 && shortSizeDp >= 720 &&
1480 res.getBoolean(com.android.internal.R.bool.config_forceDefaultOrientation) &&
1481 // For debug purposes the next line turns this feature off with:
1482 // $ adb shell setprop config.override_forced_orient true
1483 // $ adb shell wm size reset
1484 !"true".equals(SystemProperties.get("config.override_forced_orient"));
1485 }
1486
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001487 /**
1488 * @return whether the navigation bar can be hidden, e.g. the device has a
1489 * navigation bar and touch exploration is not enabled
1490 */
1491 private boolean canHideNavigationBar() {
Svetoslav8e3feb12014-02-24 13:46:47 -08001492 return mHasNavigationBar
1493 && !mAccessibilityManager.isTouchExplorationEnabled();
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001494 }
1495
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001496 @Override
1497 public boolean isDefaultOrientationForced() {
1498 return mForceDefaultOrientation;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001499 }
1500
Dianne Hackbornc652de82013-02-15 16:32:56 -08001501 @Override
1502 public void setDisplayOverscan(Display display, int left, int top, int right, int bottom) {
1503 if (display.getDisplayId() == Display.DEFAULT_DISPLAY) {
1504 mOverscanLeft = left;
1505 mOverscanTop = top;
1506 mOverscanRight = right;
1507 mOverscanBottom = bottom;
1508 }
1509 }
1510
Dianne Hackbornc777e072010-02-12 13:07:59 -08001511 public void updateSettings() {
1512 ContentResolver resolver = mContext.getContentResolver();
1513 boolean updateRotation = false;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001514 synchronized (mLock) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001515 mEndcallBehavior = Settings.System.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001516 Settings.System.END_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001517 Settings.System.END_BUTTON_BEHAVIOR_DEFAULT,
1518 UserHandle.USER_CURRENT);
1519 mIncallPowerBehavior = Settings.Secure.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001520 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001521 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT,
1522 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001523
Jeff Browna20dda42014-05-27 20:57:24 -07001524 // Configure wake gesture.
1525 boolean wakeGestureEnabledSetting = Settings.Secure.getIntForUser(resolver,
1526 Settings.Secure.WAKE_GESTURE_ENABLED, 0,
1527 UserHandle.USER_CURRENT) != 0;
1528 if (mWakeGestureEnabledSetting != wakeGestureEnabledSetting) {
1529 mWakeGestureEnabledSetting = wakeGestureEnabledSetting;
1530 updateWakeGestureListenerLp();
1531 }
1532
Jeff Brown207673cd2012-06-05 17:47:11 -07001533 // Configure rotation lock.
Christopher Tate5e08af02012-09-21 17:17:22 -07001534 int userRotation = Settings.System.getIntForUser(resolver,
1535 Settings.System.USER_ROTATION, Surface.ROTATION_0,
1536 UserHandle.USER_CURRENT);
Jeff Brown207673cd2012-06-05 17:47:11 -07001537 if (mUserRotation != userRotation) {
1538 mUserRotation = userRotation;
1539 updateRotation = true;
1540 }
Christopher Tate5e08af02012-09-21 17:17:22 -07001541 int userRotationMode = Settings.System.getIntForUser(resolver,
1542 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
Jeff Brown207673cd2012-06-05 17:47:11 -07001543 WindowManagerPolicy.USER_ROTATION_FREE :
1544 WindowManagerPolicy.USER_ROTATION_LOCKED;
1545 if (mUserRotationMode != userRotationMode) {
1546 mUserRotationMode = userRotationMode;
1547 updateRotation = true;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001548 updateOrientationListenerLp();
1549 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001550
Dianne Hackbornc777e072010-02-12 13:07:59 -08001551 if (mSystemReady) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001552 int pointerLocation = Settings.System.getIntForUser(resolver,
1553 Settings.System.POINTER_LOCATION, 0, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001554 if (mPointerLocationMode != pointerLocation) {
1555 mPointerLocationMode = pointerLocation;
Jeff Brown70825162012-03-28 17:27:48 -07001556 mHandler.sendEmptyMessage(pointerLocation != 0 ?
1557 MSG_ENABLE_POINTER_LOCATION : MSG_DISABLE_POINTER_LOCATION);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001558 }
1559 }
1560 // use screen off timeout setting as the timeout for the lockscreen
Christopher Tate5e08af02012-09-21 17:17:22 -07001561 mLockScreenTimeout = Settings.System.getIntForUser(resolver,
1562 Settings.System.SCREEN_OFF_TIMEOUT, 0, UserHandle.USER_CURRENT);
1563 String imId = Settings.Secure.getStringForUser(resolver,
1564 Settings.Secure.DEFAULT_INPUT_METHOD, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001565 boolean hasSoftInput = imId != null && imId.length() > 0;
1566 if (mHasSoftInput != hasSoftInput) {
1567 mHasSoftInput = hasSoftInput;
1568 updateRotation = true;
1569 }
John Spurlockf1a36642013-10-12 17:50:42 -04001570 if (mImmersiveModeConfirmation != null) {
John Spurlock4355a532014-02-19 09:49:25 -05001571 mImmersiveModeConfirmation.loadSetting(mCurrentUserId);
John Spurlockd67ec252013-09-05 11:31:54 -04001572 }
John Spurlockc6d1c602014-01-17 15:22:06 -05001573 PolicyControl.reloadFromSetting(mContext);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001574 }
1575 if (updateRotation) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07001576 updateRotation(true);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001577 }
Jeff Brown70825162012-03-28 17:27:48 -07001578 }
1579
Jeff Browna20dda42014-05-27 20:57:24 -07001580 private void updateWakeGestureListenerLp() {
1581 if (shouldEnableWakeGestureLp()) {
1582 mWakeGestureListener.requestWakeUpTrigger();
1583 } else {
1584 mWakeGestureListener.cancelWakeUpTrigger();
1585 }
1586 }
1587
1588 private boolean shouldEnableWakeGestureLp() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07001589 return mWakeGestureEnabledSetting && !mAwake
Jeff Browna20dda42014-05-27 20:57:24 -07001590 && (!mLidControlsSleep || mLidState != LID_CLOSED)
1591 && mWakeGestureListener.isSupported();
1592 }
1593
Jeff Brown70825162012-03-28 17:27:48 -07001594 private void enablePointerLocation() {
1595 if (mPointerLocationView == null) {
1596 mPointerLocationView = new PointerLocationView(mContext);
1597 mPointerLocationView.setPrintCoords(false);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001598 WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
1599 WindowManager.LayoutParams.MATCH_PARENT,
1600 WindowManager.LayoutParams.MATCH_PARENT);
Jeff Brown3b2b3542010-10-15 00:54:27 -07001601 lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001602 lp.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN
1603 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
1604 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1605 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
Jeff Brown90fc9052012-10-01 14:44:24 -07001606 if (ActivityManager.isHighEndGfx()) {
1607 lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
1608 lp.privateFlags |=
1609 WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED;
1610 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001611 lp.format = PixelFormat.TRANSLUCENT;
1612 lp.setTitle("PointerLocation");
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001613 WindowManager wm = (WindowManager)
Dianne Hackbornc777e072010-02-12 13:07:59 -08001614 mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Browncc4f7db2011-08-30 20:34:48 -07001615 lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL;
Jeff Brown70825162012-03-28 17:27:48 -07001616 wm.addView(mPointerLocationView, lp);
Michael Wrightc9c487e2013-11-07 18:55:09 -08001617 mWindowManagerFuncs.registerPointerEventListener(mPointerLocationView);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001618 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001619 }
Jeff Brown70825162012-03-28 17:27:48 -07001620
1621 private void disablePointerLocation() {
Jeff Brown70825162012-03-28 17:27:48 -07001622 if (mPointerLocationView != null) {
Michael Wrightc9c487e2013-11-07 18:55:09 -08001623 mWindowManagerFuncs.unregisterPointerEventListener(mPointerLocationView);
1624 WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Brown70825162012-03-28 17:27:48 -07001625 wm.removeView(mPointerLocationView);
1626 mPointerLocationView = null;
1627 }
1628 }
1629
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001630 private int readRotation(int resID) {
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001631 try {
1632 int rotation = mContext.getResources().getInteger(resID);
1633 switch (rotation) {
1634 case 0:
1635 return Surface.ROTATION_0;
1636 case 90:
1637 return Surface.ROTATION_90;
1638 case 180:
1639 return Surface.ROTATION_180;
1640 case 270:
1641 return Surface.ROTATION_270;
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001642 }
1643 } catch (Resources.NotFoundException e) {
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001644 // fall through
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001645 }
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001646 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001647 }
1648
1649 /** {@inheritDoc} */
Craig Mautner88400d32012-09-30 12:35:45 -07001650 @Override
Dianne Hackbornc2293022013-02-06 23:14:49 -08001651 public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001652 int type = attrs.type;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001653
1654 outAppOp[0] = AppOpsManager.OP_NONE;
1655
Wale Ogunwale74bf0652015-01-12 10:24:36 -08001656 if (!((type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW)
1657 || (type >= FIRST_SUB_WINDOW && type <= LAST_SUB_WINDOW)
1658 || (type >= FIRST_SYSTEM_WINDOW && type <= LAST_SYSTEM_WINDOW))) {
1659 return WindowManagerGlobal.ADD_INVALID_TYPE;
1660 }
1661
1662 if (type < FIRST_SYSTEM_WINDOW || type > LAST_SYSTEM_WINDOW) {
1663 // Window manager will make sure these are okay.
Jeff Brown98365d72012-08-19 20:30:52 -07001664 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001665 }
1666 String permission = null;
1667 switch (type) {
1668 case TYPE_TOAST:
1669 // XXX right now the app process has complete control over
1670 // this... should introduce a token to let the system
1671 // monitor/control what they are doing.
Jason Monk1c7c3192014-06-26 12:52:18 -04001672 outAppOp[0] = AppOpsManager.OP_TOAST_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001673 break;
Daniel Sandler7d276c32012-01-30 14:33:52 -05001674 case TYPE_DREAM:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001675 case TYPE_INPUT_METHOD:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001676 case TYPE_WALLPAPER:
keunyounga446bf02013-06-21 19:07:57 -07001677 case TYPE_PRIVATE_PRESENTATION:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001678 case TYPE_VOICE_INTERACTION:
Svetoslav3a5c7212014-10-14 09:54:26 -07001679 case TYPE_ACCESSIBILITY_OVERLAY:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001680 // The window manager will check these.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001681 break;
1682 case TYPE_PHONE:
1683 case TYPE_PRIORITY_PHONE:
1684 case TYPE_SYSTEM_ALERT:
1685 case TYPE_SYSTEM_ERROR:
1686 case TYPE_SYSTEM_OVERLAY:
1687 permission = android.Manifest.permission.SYSTEM_ALERT_WINDOW;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001688 outAppOp[0] = AppOpsManager.OP_SYSTEM_ALERT_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001689 break;
1690 default:
1691 permission = android.Manifest.permission.INTERNAL_SYSTEM_WINDOW;
1692 }
1693 if (permission != null) {
1694 if (mContext.checkCallingOrSelfPermission(permission)
1695 != PackageManager.PERMISSION_GRANTED) {
Jeff Brown98365d72012-08-19 20:30:52 -07001696 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001697 }
1698 }
Jeff Brown98365d72012-08-19 20:30:52 -07001699 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001700 }
Craig Mautner88400d32012-09-30 12:35:45 -07001701
1702 @Override
1703 public boolean checkShowToOwnerOnly(WindowManager.LayoutParams attrs) {
1704
1705 // If this switch statement is modified, modify the comment in the declarations of
1706 // the type in {@link WindowManager.LayoutParams} as well.
1707 switch (attrs.type) {
1708 default:
1709 // These are the windows that by default are shown only to the user that created
1710 // them. If this needs to be overridden, set
1711 // {@link WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS} in
1712 // {@link WindowManager.LayoutParams}. Note that permission
1713 // {@link android.Manifest.permission.INTERNAL_SYSTEM_WINDOW} is required as well.
1714 if ((attrs.privateFlags & PRIVATE_FLAG_SHOW_FOR_ALL_USERS) == 0) {
1715 return true;
1716 }
1717 break;
1718
1719 // These are the windows that by default are shown to all users. However, to
1720 // protect against spoofing, check permissions below.
1721 case TYPE_APPLICATION_STARTING:
1722 case TYPE_BOOT_PROGRESS:
1723 case TYPE_DISPLAY_OVERLAY:
1724 case TYPE_HIDDEN_NAV_CONSUMER:
Jim Miller5ecd8112013-01-09 18:50:26 -08001725 case TYPE_KEYGUARD_SCRIM:
Craig Mautner88400d32012-09-30 12:35:45 -07001726 case TYPE_KEYGUARD_DIALOG:
1727 case TYPE_MAGNIFICATION_OVERLAY:
1728 case TYPE_NAVIGATION_BAR:
1729 case TYPE_NAVIGATION_BAR_PANEL:
1730 case TYPE_PHONE:
1731 case TYPE_POINTER:
1732 case TYPE_PRIORITY_PHONE:
Craig Mautner88400d32012-09-30 12:35:45 -07001733 case TYPE_SEARCH_BAR:
1734 case TYPE_STATUS_BAR:
1735 case TYPE_STATUS_BAR_PANEL:
1736 case TYPE_STATUS_BAR_SUB_PANEL:
1737 case TYPE_SYSTEM_DIALOG:
Craig Mautner88400d32012-09-30 12:35:45 -07001738 case TYPE_VOLUME_OVERLAY:
keunyounga446bf02013-06-21 19:07:57 -07001739 case TYPE_PRIVATE_PRESENTATION:
Craig Mautner88400d32012-09-30 12:35:45 -07001740 break;
1741 }
1742
1743 // Check if third party app has set window to system window type.
1744 return mContext.checkCallingOrSelfPermission(
1745 android.Manifest.permission.INTERNAL_SYSTEM_WINDOW)
1746 != PackageManager.PERMISSION_GRANTED;
1747 }
1748
Craig Mautner967212c2013-04-13 21:10:58 -07001749 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001750 public void adjustWindowParamsLw(WindowManager.LayoutParams attrs) {
1751 switch (attrs.type) {
1752 case TYPE_SYSTEM_OVERLAY:
Jeff Brown3b2b3542010-10-15 00:54:27 -07001753 case TYPE_SECURE_SYSTEM_OVERLAY:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001754 // These types of windows can't receive input events.
1755 attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1756 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001757 attrs.flags &= ~WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001758 break;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001759 case TYPE_STATUS_BAR:
1760
1761 // If the Keyguard is in a hidden state (occluded by another window), we force to
1762 // remove the wallpaper and keyguard flag so that any change in-flight after setting
1763 // the keyguard as occluded wouldn't set these flags again.
1764 // See {@link #processKeyguardSetHiddenResultLw}.
1765 if (mKeyguardHidden) {
1766 attrs.flags &= ~WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
1767 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
1768 }
1769 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001770 }
Adrian Roos38502112014-04-09 21:04:11 +02001771
1772 if (attrs.type != TYPE_STATUS_BAR) {
1773 // The status bar is the only window allowed to exhibit keyguard behavior.
1774 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
1775 }
Adrian Roosea562512014-05-05 13:33:03 +02001776
1777 if (ActivityManager.isHighEndGfx()
1778 && (attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0) {
Adrian Roosf5e9b5c2014-09-10 15:27:41 +02001779 attrs.subtreeSystemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
Adrian Roosea562512014-05-05 13:33:03 +02001780 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
1781 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001782 }
RoboErik8a2cfc32014-05-16 11:19:38 -07001783
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001784 void readLidState() {
Jeff Brown2e7760e2012-04-11 15:14:55 -07001785 mLidState = mWindowManagerFuncs.getLidState();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001786 }
RoboErik8a2cfc32014-05-16 11:19:38 -07001787
Michael Wright3818c922014-09-02 13:59:07 -07001788 private void readCameraLensCoverState() {
1789 mCameraLensCoverState = mWindowManagerFuncs.getCameraLensCoverState();
1790 }
1791
Jeff Browndaa37532012-05-01 15:54:03 -07001792 private boolean isHidden(int accessibilityMode) {
1793 switch (accessibilityMode) {
1794 case 1:
1795 return mLidState == LID_CLOSED;
1796 case 2:
1797 return mLidState == LID_OPEN;
1798 default:
1799 return false;
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001800 }
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001801 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001802
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001803 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07001804 @Override
Jeff Browndaa37532012-05-01 15:54:03 -07001805 public void adjustConfigurationLw(Configuration config, int keyboardPresence,
1806 int navigationPresence) {
1807 mHaveBuiltInKeyboard = (keyboardPresence & PRESENCE_INTERNAL) != 0;
1808
Jeff Brownf71343d2013-05-31 17:59:11 -07001809 readConfigurationDependentBehaviors();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001810 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07001811 applyLidSwitchState();
Jeff Brownd04a88c2011-01-16 14:05:47 -08001812
Jeff Browndaa37532012-05-01 15:54:03 -07001813 if (config.keyboard == Configuration.KEYBOARD_NOKEYS
1814 || (keyboardPresence == PRESENCE_INTERNAL
1815 && isHidden(mLidKeyboardAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001816 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_YES;
Jeff Browndaa37532012-05-01 15:54:03 -07001817 if (!mHasSoftInput) {
1818 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_YES;
1819 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001820 }
1821
Jeff Browndaa37532012-05-01 15:54:03 -07001822 if (config.navigation == Configuration.NAVIGATION_NONAV
1823 || (navigationPresence == PRESENCE_INTERNAL
1824 && isHidden(mLidNavigationAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001825 config.navigationHidden = Configuration.NAVIGATIONHIDDEN_YES;
Jeff Brownd04a88c2011-01-16 14:05:47 -08001826 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001827 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001828
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001829 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07001830 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001831 public int windowTypeToLayerLw(int type) {
1832 if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001833 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001834 }
1835 switch (type) {
keunyounga446bf02013-06-21 19:07:57 -07001836 case TYPE_PRIVATE_PRESENTATION:
1837 return 2;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001838 case TYPE_WALLPAPER:
1839 // wallpaper is at the bottom, though the window manager may move it.
1840 return 2;
1841 case TYPE_PHONE:
1842 return 3;
1843 case TYPE_SEARCH_BAR:
1844 return 4;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001845 case TYPE_VOICE_INTERACTION:
1846 // voice interaction layer is almost immediately above apps.
1847 return 5;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001848 case TYPE_SYSTEM_DIALOG:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001849 return 6;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001850 case TYPE_TOAST:
1851 // toasts and the plugged-in battery thing
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001852 return 7;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001853 case TYPE_PRIORITY_PHONE:
1854 // SIM errors and unlock. Not sure if this really should be in a high layer.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001855 return 8;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001856 case TYPE_DREAM:
1857 // used for Dreams (screensavers with TYPE_DREAM windows)
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001858 return 9;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001859 case TYPE_SYSTEM_ALERT:
1860 // like the ANR / app crashed dialogs
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001861 return 10;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001862 case TYPE_INPUT_METHOD:
1863 // on-screen keyboards and other such input method user interfaces go here.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001864 return 11;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001865 case TYPE_INPUT_METHOD_DIALOG:
1866 // on-screen keyboards and other such input method user interfaces go here.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001867 return 12;
Jim Miller5ecd8112013-01-09 18:50:26 -08001868 case TYPE_KEYGUARD_SCRIM:
1869 // the safety window that shows behind keyguard while keyguard is starting
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001870 return 13;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001871 case TYPE_STATUS_BAR_SUB_PANEL:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001872 return 14;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001873 case TYPE_STATUS_BAR:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001874 return 15;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001875 case TYPE_STATUS_BAR_PANEL:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001876 return 16;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001877 case TYPE_KEYGUARD_DIALOG:
1878 return 17;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001879 case TYPE_VOLUME_OVERLAY:
1880 // the on-screen volume indicator and controller shown when the user
1881 // changes the device volume
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001882 return 18;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001883 case TYPE_SYSTEM_OVERLAY:
1884 // the on-screen volume indicator and controller shown when the user
1885 // changes the device volume
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001886 return 19;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001887 case TYPE_NAVIGATION_BAR:
1888 // the navigation bar, if available, shows atop most things
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001889 return 20;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001890 case TYPE_NAVIGATION_BAR_PANEL:
1891 // some panels (e.g. search) need to show on top of the navigation bar
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001892 return 21;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001893 case TYPE_SYSTEM_ERROR:
1894 // system-level error dialogs
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001895 return 22;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001896 case TYPE_MAGNIFICATION_OVERLAY:
1897 // used to highlight the magnified portion of a display
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001898 return 23;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001899 case TYPE_DISPLAY_OVERLAY:
1900 // used to simulate secondary display devices
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001901 return 24;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001902 case TYPE_DRAG:
1903 // the drag layer: input for drag-and-drop is associated with this window,
1904 // which sits above all other focusable windows
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001905 return 25;
Svetoslav3a5c7212014-10-14 09:54:26 -07001906 case TYPE_ACCESSIBILITY_OVERLAY:
1907 // overlay put by accessibility services to intercept user interaction
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001908 return 26;
Svetoslav3a5c7212014-10-14 09:54:26 -07001909 case TYPE_SECURE_SYSTEM_OVERLAY:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001910 return 27;
Svetoslav3a5c7212014-10-14 09:54:26 -07001911 case TYPE_BOOT_PROGRESS:
1912 return 28;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001913 case TYPE_POINTER:
1914 // the (mouse) pointer layer
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001915 return 29;
Svetoslav3a5c7212014-10-14 09:54:26 -07001916 case TYPE_HIDDEN_NAV_CONSUMER:
1917 return 30;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001918 }
1919 Log.e(TAG, "Unknown window type: " + type);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001920 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001921 }
1922
1923 /** {@inheritDoc} */
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001924 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001925 public int subWindowTypeToLayerLw(int type) {
1926 switch (type) {
1927 case TYPE_APPLICATION_PANEL:
1928 case TYPE_APPLICATION_ATTACHED_DIALOG:
1929 return APPLICATION_PANEL_SUBLAYER;
1930 case TYPE_APPLICATION_MEDIA:
1931 return APPLICATION_MEDIA_SUBLAYER;
Dianne Hackborn5cb8d792009-05-21 17:34:15 -07001932 case TYPE_APPLICATION_MEDIA_OVERLAY:
1933 return APPLICATION_MEDIA_OVERLAY_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001934 case TYPE_APPLICATION_SUB_PANEL:
1935 return APPLICATION_SUB_PANEL_SUBLAYER;
1936 }
1937 Log.e(TAG, "Unknown sub-window type: " + type);
1938 return 0;
1939 }
1940
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001941 @Override
Dianne Hackbornabe0da02009-09-18 01:55:39 -07001942 public int getMaxWallpaperLayer() {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001943 return windowTypeToLayerLw(TYPE_STATUS_BAR);
Dianne Hackbornabe0da02009-09-18 01:55:39 -07001944 }
1945
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001946 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001947 public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07001948 if (mHasNavigationBar) {
1949 // For a basic navigation bar, when we are in landscape mode we place
1950 // the navigation bar to the side.
Daniel Sandler4a066c52012-04-20 14:49:13 -04001951 if (mNavigationBarCanMove && fullWidth > fullHeight) {
1952 return fullWidth - mNavigationBarWidthForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07001953 }
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001954 }
1955 return fullWidth;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001956 }
1957
Jose Lima9546b202014-07-02 17:21:51 -07001958 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001959 public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07001960 if (mHasNavigationBar) {
1961 // For a basic navigation bar, when we are in portrait mode we place
1962 // the navigation bar to the bottom.
Daniel Sandler4a066c52012-04-20 14:49:13 -04001963 if (!mNavigationBarCanMove || fullWidth < fullHeight) {
1964 return fullHeight - mNavigationBarHeightForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07001965 }
1966 }
1967 return fullHeight;
Dianne Hackborn69cb8752011-05-19 18:13:32 -07001968 }
1969
Jose Lima9546b202014-07-02 17:21:51 -07001970 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001971 public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation) {
1972 return getNonDecorDisplayWidth(fullWidth, fullHeight, rotation);
Dianne Hackborn69cb8752011-05-19 18:13:32 -07001973 }
1974
Jose Lima9546b202014-07-02 17:21:51 -07001975 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001976 public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation) {
John Spurlock80f00c12013-06-13 11:10:51 -04001977 // There is a separate status bar at the top of the display. We don't count that as part
1978 // of the fixed decor, since it can hide; however, for purposes of configurations,
Dianne Hackborn077ee852012-04-09 16:27:07 -07001979 // we do want to exclude it since applications can't generally use that part
1980 // of the screen.
John Spurlock80f00c12013-06-13 11:10:51 -04001981 return getNonDecorDisplayHeight(fullWidth, fullHeight, rotation) - mStatusBarHeight;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001982 }
1983
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001984 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07001985 public boolean isForceHiding(WindowManager.LayoutParams attrs) {
1986 return (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 ||
Jim Millerab954542014-10-10 18:21:49 -07001987 (isKeyguardHostWindow(attrs) &&
1988 (mKeyguardDelegate != null && mKeyguardDelegate.isShowing())) ||
Adrian Roos69e510d2014-07-13 14:57:59 +02001989 (attrs.type == TYPE_KEYGUARD_SCRIM);
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07001990 }
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001991
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001992 @Override
Jorim Jaggi0d674622014-05-21 01:34:15 +02001993 public boolean isKeyguardHostWindow(WindowManager.LayoutParams attrs) {
1994 return attrs.type == TYPE_STATUS_BAR;
1995 }
1996
1997 @Override
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07001998 public boolean canBeForceHidden(WindowState win, WindowManager.LayoutParams attrs) {
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001999 switch (attrs.type) {
2000 case TYPE_STATUS_BAR:
2001 case TYPE_NAVIGATION_BAR:
2002 case TYPE_WALLPAPER:
2003 case TYPE_DREAM:
Jim Miller5ecd8112013-01-09 18:50:26 -08002004 case TYPE_KEYGUARD_SCRIM:
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002005 return false;
2006 default:
2007 return true;
2008 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002009 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002010
Craig Mautner7d7808f2014-09-11 18:02:38 -07002011 @Override
2012 public WindowState getWinShowWhenLockedLw() {
2013 return mWinShowWhenLocked;
2014 }
2015
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002016 /** {@inheritDoc} */
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002017 @Override
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07002018 public View addStartingWindow(IBinder appToken, String packageName, int theme,
2019 CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes,
Adam Powell04fe6eb2013-05-31 14:39:48 -07002020 int icon, int logo, int windowFlags) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002021 if (!SHOW_STARTING_ANIMATIONS) {
2022 return null;
2023 }
2024 if (packageName == null) {
2025 return null;
2026 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002027
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002028 WindowManager wm = null;
2029 View view = null;
2030
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002031 try {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002032 Context context = mContext;
Craig Mautner6fbda632012-07-03 09:26:39 -07002033 if (DEBUG_STARTING_WINDOW) Slog.d(TAG, "addStartingWindow " + packageName
2034 + ": nonLocalizedLabel=" + nonLocalizedLabel + " theme="
2035 + Integer.toHexString(theme));
Dianne Hackborn247fe742011-01-08 17:25:57 -08002036 if (theme != context.getThemeResId() || labelRes != 0) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002037 try {
2038 context = context.createPackageContext(packageName, 0);
Dianne Hackborn247fe742011-01-08 17:25:57 -08002039 context.setTheme(theme);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002040 } catch (PackageManager.NameNotFoundException e) {
2041 // Ignore
2042 }
2043 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002044
Jorim Jaggib10e33f2015-02-04 21:57:40 +01002045 Window win = new PhoneWindow(context);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002046 final TypedArray ta = win.getWindowStyle();
2047 if (ta.getBoolean(
2048 com.android.internal.R.styleable.Window_windowDisablePreview, false)
2049 || ta.getBoolean(
2050 com.android.internal.R.styleable.Window_windowShowWallpaper,false)) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002051 return null;
2052 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002053
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002054 Resources r = context.getResources();
2055 win.setTitle(r.getText(labelRes, nonLocalizedLabel));
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002056
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002057 win.setType(
2058 WindowManager.LayoutParams.TYPE_APPLICATION_STARTING);
2059 // Force the window flags: this is a fake window, so it is not really
2060 // touchable or focusable by the user. We also add in the ALT_FOCUSABLE_IM
2061 // flag because we do know that the next window will take input
2062 // focus, so we want to get the IME window up on top of us right away.
2063 win.setFlags(
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08002064 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002065 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
2066 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
2067 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08002068 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002069 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
2070 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
2071 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002072
Adam Powell04fe6eb2013-05-31 14:39:48 -07002073 win.setDefaultIcon(icon);
2074 win.setDefaultLogo(logo);
2075
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002076 win.setLayout(WindowManager.LayoutParams.MATCH_PARENT,
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07002077 WindowManager.LayoutParams.MATCH_PARENT);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002078
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002079 final WindowManager.LayoutParams params = win.getAttributes();
2080 params.token = appToken;
2081 params.packageName = packageName;
2082 params.windowAnimations = win.getWindowStyle().getResourceId(
2083 com.android.internal.R.styleable.Window_windowAnimationStyle, 0);
John Reck61375a82014-09-18 19:27:48 +00002084 params.privateFlags |=
2085 WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED;
Craig Mautner88400d32012-09-30 12:35:45 -07002086 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
Adam Lesinski95c42972013-10-02 10:13:27 -07002087
2088 if (!compatInfo.supportsScreen()) {
2089 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
2090 }
2091
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002092 params.setTitle("Starting " + packageName);
2093
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002094 wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
2095 view = win.getDecorView();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002096
2097 if (win.isFloating()) {
2098 // Whoops, there is no way to display an animation/preview
2099 // of such a thing! After all that work... let's skip it.
2100 // (Note that we must do this here because it is in
2101 // getDecorView() where the theme is evaluated... maybe
2102 // we should peek the floating attribute from the theme
2103 // earlier.)
2104 return null;
2105 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002106
Craig Mautner6fbda632012-07-03 09:26:39 -07002107 if (DEBUG_STARTING_WINDOW) Slog.d(
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002108 TAG, "Adding starting window for " + packageName
2109 + " / " + appToken + ": "
2110 + (view.getParent() != null ? view : null));
2111
2112 wm.addView(view, params);
2113
2114 // Only return the view if it was successfully added to the
2115 // window manager... which we can tell by it having a parent.
2116 return view.getParent() != null ? view : null;
Jeff Brown98365d72012-08-19 20:30:52 -07002117 } catch (WindowManager.BadTokenException e) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002118 // ignore
Craig Mautner42bf39e2014-02-21 16:46:22 -08002119 Log.w(TAG, appToken + " already running, starting window not displayed. " +
2120 e.getMessage());
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002121 } catch (RuntimeException e) {
2122 // don't crash if something else bad happens, for example a
2123 // failure loading resources because we are loading from an app
2124 // on external storage that has been unmounted.
2125 Log.w(TAG, appToken + " failed creating starting window", e);
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002126 } finally {
2127 if (view != null && view.getParent() == null) {
2128 Log.w(TAG, "view not successfully added to wm, removing view");
2129 wm.removeViewImmediate(view);
2130 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002131 }
2132
2133 return null;
2134 }
2135
2136 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07002137 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002138 public void removeStartingWindow(IBinder appToken, View window) {
Craig Mautner276a6eb2014-11-04 15:32:57 -08002139 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Removing starting window for " + appToken + ": "
2140 + window + " Callers=" + Debug.getCallers(4));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002141
2142 if (window != null) {
Dianne Hackborn5fd21692011-06-07 14:09:47 -07002143 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002144 wm.removeView(window);
2145 }
2146 }
2147
2148 /**
2149 * Preflight adding a window to the system.
RoboErik8a2cfc32014-05-16 11:19:38 -07002150 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002151 * Currently enforces that three window types are singletons:
2152 * <ul>
2153 * <li>STATUS_BAR_TYPE</li>
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002154 * <li>KEYGUARD_TYPE</li>
2155 * </ul>
RoboErik8a2cfc32014-05-16 11:19:38 -07002156 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002157 * @param win The window to be added
2158 * @param attrs Information about the window to be added
RoboErik8a2cfc32014-05-16 11:19:38 -07002159 *
Jeff Brown98365d72012-08-19 20:30:52 -07002160 * @return If ok, WindowManagerImpl.ADD_OKAY. If too many singletons,
2161 * WindowManagerImpl.ADD_MULTIPLE_SINGLETON
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002162 */
Jose Lima9546b202014-07-02 17:21:51 -07002163 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002164 public int prepareAddWindowLw(WindowState win, WindowManager.LayoutParams attrs) {
2165 switch (attrs.type) {
2166 case TYPE_STATUS_BAR:
Joe Onorato8bc6c512010-06-04 16:21:12 -04002167 mContext.enforceCallingOrSelfPermission(
2168 android.Manifest.permission.STATUS_BAR_SERVICE,
2169 "PhoneWindowManager");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002170 if (mStatusBar != null) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002171 if (mStatusBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07002172 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002173 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002174 }
2175 mStatusBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04002176 mStatusBarController.setWindow(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002177 break;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002178 case TYPE_NAVIGATION_BAR:
2179 mContext.enforceCallingOrSelfPermission(
2180 android.Manifest.permission.STATUS_BAR_SERVICE,
2181 "PhoneWindowManager");
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002182 if (mNavigationBar != null) {
2183 if (mNavigationBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07002184 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002185 }
2186 }
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002187 mNavigationBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04002188 mNavigationBarController.setWindow(win);
Craig Mautnereda67292013-04-28 13:50:14 -07002189 if (DEBUG_LAYOUT) Slog.i(TAG, "NAVIGATION BAR: " + mNavigationBar);
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002190 break;
Jim Millere898ac52012-04-06 17:10:57 -07002191 case TYPE_NAVIGATION_BAR_PANEL:
2192 mContext.enforceCallingOrSelfPermission(
2193 android.Manifest.permission.STATUS_BAR_SERVICE,
2194 "PhoneWindowManager");
2195 break;
Dianne Hackborn08743722009-12-21 12:16:51 -08002196 case TYPE_STATUS_BAR_PANEL:
Joe Onorato8bc6c512010-06-04 16:21:12 -04002197 mContext.enforceCallingOrSelfPermission(
2198 android.Manifest.permission.STATUS_BAR_SERVICE,
2199 "PhoneWindowManager");
Dianne Hackborn08743722009-12-21 12:16:51 -08002200 break;
Joe Onorato29fc2c92010-11-24 10:26:50 -08002201 case TYPE_STATUS_BAR_SUB_PANEL:
2202 mContext.enforceCallingOrSelfPermission(
2203 android.Manifest.permission.STATUS_BAR_SERVICE,
2204 "PhoneWindowManager");
Joe Onorato29fc2c92010-11-24 10:26:50 -08002205 break;
Jim Miller5ecd8112013-01-09 18:50:26 -08002206 case TYPE_KEYGUARD_SCRIM:
Jim Miller25190572013-02-28 17:36:24 -08002207 if (mKeyguardScrim != null) {
2208 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
2209 }
Jim Miller5ecd8112013-01-09 18:50:26 -08002210 mKeyguardScrim = win;
2211 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002212 }
Jeff Brown98365d72012-08-19 20:30:52 -07002213 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002214 }
2215
2216 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07002217 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002218 public void removeWindowLw(WindowState win) {
2219 if (mStatusBar == win) {
2220 mStatusBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04002221 mStatusBarController.setWindow(null);
Jim Millerc0b676d2013-03-22 16:11:08 -07002222 mKeyguardDelegate.showScrim();
Jim Miller5ecd8112013-01-09 18:50:26 -08002223 } else if (mKeyguardScrim == win) {
2224 Log.v(TAG, "Removing keyguard scrim");
2225 mKeyguardScrim = null;
2226 } if (mNavigationBar == win) {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002227 mNavigationBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04002228 mNavigationBarController.setWindow(null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002229 }
2230 }
2231
2232 static final boolean PRINT_ANIM = false;
RoboErik8a2cfc32014-05-16 11:19:38 -07002233
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002234 /** {@inheritDoc} */
Craig Mautner4b71aa12012-12-27 17:20:01 -08002235 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002236 public int selectAnimationLw(WindowState win, int transit) {
2237 if (PRINT_ANIM) Log.i(TAG, "selectAnimation in " + win
2238 + ": transit=" + transit);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002239 if (win == mStatusBar) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002240 boolean isKeyguard = (win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002241 if (transit == TRANSIT_EXIT
2242 || transit == TRANSIT_HIDE) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002243 return isKeyguard ? -1 : R.anim.dock_top_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002244 } else if (transit == TRANSIT_ENTER
2245 || transit == TRANSIT_SHOW) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002246 return isKeyguard ? -1 : R.anim.dock_top_enter;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002247 }
2248 } else if (win == mNavigationBar) {
2249 // This can be on either the bottom or the right.
2250 if (mNavigationBarOnBottom) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08002251 if (transit == TRANSIT_EXIT
2252 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002253 return R.anim.dock_bottom_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002254 } else if (transit == TRANSIT_ENTER
2255 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002256 return R.anim.dock_bottom_enter;
2257 }
2258 } else {
Craig Mautner4b71aa12012-12-27 17:20:01 -08002259 if (transit == TRANSIT_EXIT
2260 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002261 return R.anim.dock_right_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002262 } else if (transit == TRANSIT_ENTER
2263 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002264 return R.anim.dock_right_enter;
2265 }
2266 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08002267 }
2268
2269 if (transit == TRANSIT_PREVIEW_DONE) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002270 if (win.hasAppShownWindows()) {
2271 if (PRINT_ANIM) Log.i(TAG, "**** STARTING EXIT");
2272 return com.android.internal.R.anim.app_starting_exit;
2273 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07002274 } else if (win.getAttrs().type == TYPE_DREAM && mDreamingLockscreen
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002275 && transit == TRANSIT_ENTER) {
2276 // Special case: we are animating in a dream, while the keyguard
2277 // is shown. We don't want an animation on the dream, because
2278 // we need it shown immediately with the keyguard animating away
2279 // to reveal it.
2280 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002281 }
2282
2283 return 0;
2284 }
2285
Craig Mautner3c174372013-02-21 17:54:37 -08002286 @Override
2287 public void selectRotationAnimationLw(int anim[]) {
2288 if (PRINT_ANIM) Slog.i(TAG, "selectRotationAnimation mTopFullscreen="
2289 + mTopFullscreenOpaqueWindowState + " rotationAnimation="
2290 + (mTopFullscreenOpaqueWindowState == null ?
2291 "0" : mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation));
2292 if (mTopFullscreenOpaqueWindowState != null && mTopIsFullscreen) {
2293 switch (mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation) {
2294 case ROTATION_ANIMATION_CROSSFADE:
2295 anim[0] = R.anim.rotation_animation_xfade_exit;
2296 anim[1] = R.anim.rotation_animation_enter;
2297 break;
2298 case ROTATION_ANIMATION_JUMPCUT:
2299 anim[0] = R.anim.rotation_animation_jump_exit;
2300 anim[1] = R.anim.rotation_animation_enter;
2301 break;
2302 case ROTATION_ANIMATION_ROTATE:
2303 default:
2304 anim[0] = anim[1] = 0;
2305 break;
2306 }
2307 } else {
2308 anim[0] = anim[1] = 0;
2309 }
2310 }
2311
2312 @Override
2313 public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId,
2314 boolean forceDefault) {
2315 switch (exitAnimId) {
2316 case R.anim.rotation_animation_xfade_exit:
2317 case R.anim.rotation_animation_jump_exit:
2318 // These are the only cases that matter.
2319 if (forceDefault) {
2320 return false;
2321 }
2322 int anim[] = new int[2];
2323 selectRotationAnimationLw(anim);
2324 return (exitAnimId == anim[0] && enterAnimId == anim[1]);
2325 default:
2326 return true;
2327 }
2328 }
2329
2330 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002331 public Animation createForceHideEnterAnimation(boolean onWallpaper,
2332 boolean goingToNotificationShade) {
2333 if (goingToNotificationShade) {
2334 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_behind_enter_fade_in);
Craig Mautnerb8340802014-11-04 15:32:57 -08002335 }
Craig Mautner276a6eb2014-11-04 15:32:57 -08002336
2337 AnimationSet set = (AnimationSet) AnimationUtils.loadAnimation(mContext, onWallpaper ?
2338 R.anim.lock_screen_behind_enter_wallpaper :
2339 R.anim.lock_screen_behind_enter);
2340
2341 // TODO: Use XML interpolators when we have log interpolators available in XML.
2342 final List<Animation> animations = set.getAnimations();
2343 for (int i = animations.size() - 1; i >= 0; --i) {
2344 animations.get(i).setInterpolator(mLogDecelerateInterpolator);
2345 }
2346
2347 return set;
Jorim Jaggi76a16232014-08-08 17:00:47 +02002348 }
2349
2350
2351 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002352 public Animation createForceHideWallpaperExitAnimation(boolean goingToNotificationShade) {
2353 if (goingToNotificationShade) {
2354 return null;
2355 } else {
2356 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_wallpaper_exit);
2357 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002358 }
John Spurlockc8b46ca2013-04-08 12:59:26 -04002359
2360 private static void awakenDreams() {
2361 IDreamManager dreamManager = getDreamManager();
2362 if (dreamManager != null) {
2363 try {
2364 dreamManager.awaken();
2365 } catch (RemoteException e) {
2366 // fine, stay asleep then
2367 }
2368 }
2369 }
2370
2371 static IDreamManager getDreamManager() {
2372 return IDreamManager.Stub.asInterface(
2373 ServiceManager.checkService(DreamService.DREAM_SERVICE));
2374 }
2375
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002376 TelecomManager getTelecommService() {
2377 return (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002378 }
2379
Jeff Brown4d396052010-10-29 21:50:21 -07002380 static IAudioService getAudioService() {
2381 IAudioService audioService = IAudioService.Stub.asInterface(
2382 ServiceManager.checkService(Context.AUDIO_SERVICE));
2383 if (audioService == null) {
2384 Log.w(TAG, "Unable to find IAudioService interface.");
2385 }
2386 return audioService;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002387 }
2388
2389 boolean keyguardOn() {
Jim Millerab954542014-10-10 18:21:49 -07002390 return isKeyguardShowingAndNotOccluded() || inKeyguardRestrictedKeyInputMode();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002391 }
2392
2393 private static final int[] WINDOW_TYPES_WHERE_HOME_DOESNT_WORK = {
2394 WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
2395 WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
2396 };
2397
2398 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002399 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002400 public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002401 final boolean keyguardOn = keyguardOn();
Jeff Brown1f245102010-11-18 20:53:46 -08002402 final int keyCode = event.getKeyCode();
2403 final int repeatCount = event.getRepeatCount();
2404 final int metaState = event.getMetaState();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002405 final int flags = event.getFlags();
Jeff Brown1f245102010-11-18 20:53:46 -08002406 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
2407 final boolean canceled = event.isCanceled();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002408
Jeff Brown40013652012-05-16 21:22:36 -07002409 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002410 Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount="
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002411 + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed
2412 + " canceled=" + canceled);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002413 }
2414
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002415 // If we think we might have a volume down & power key chord on the way
2416 // but we're not sure, then tell the dispatcher to wait a little while and
2417 // try again later before dispatching.
Christopher Tatee90585f2012-03-05 18:56:25 -08002418 if (mScreenshotChordEnabled && (flags & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07002419 if (mScreenshotChordVolumeDownKeyTriggered && !mScreenshotChordPowerKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002420 final long now = SystemClock.uptimeMillis();
Jeff Brown13f00f02014-10-31 14:45:50 -07002421 final long timeoutTime = mScreenshotChordVolumeDownKeyTime
2422 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002423 if (now < timeoutTime) {
2424 return timeoutTime - now;
2425 }
2426 }
2427 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
Jeff Brown13f00f02014-10-31 14:45:50 -07002428 && mScreenshotChordVolumeDownKeyConsumed) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002429 if (!down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07002430 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002431 }
2432 return -1;
2433 }
2434 }
2435
Michael Wright6a62e552014-06-03 19:19:48 -07002436 // Cancel any pending meta actions if we see any other keys being pressed between the down
2437 // of the meta key and its corresponding up.
Michael Wright251e35d2014-08-22 15:40:27 -07002438 if (mPendingMetaAction && !KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07002439 mPendingMetaAction = false;
2440 }
2441
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002442 // First we always handle the home key here, so applications
2443 // can never break it, although if keyguard is on, we do let
2444 // it handle it, because that gives us the correct 5 second
2445 // timeout.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002446 if (keyCode == KeyEvent.KEYCODE_HOME) {
Michael Jurka7f2668c2012-03-27 07:49:52 -07002447
Jeff Brown49ed71d2010-12-06 17:13:33 -08002448 // If we have released the home key, and didn't do anything else
2449 // while it was pressed, then it is time to go home!
Michael Jurka7f2668c2012-03-27 07:49:52 -07002450 if (!down) {
Jeff Browncaca8812013-05-09 13:34:33 -07002451 cancelPreloadRecentApps();
2452
Jeff Brown49ed71d2010-12-06 17:13:33 -08002453 mHomePressed = false;
Jeff Browncaca8812013-05-09 13:34:33 -07002454 if (mHomeConsumed) {
2455 mHomeConsumed = false;
Michael Jurka7f2668c2012-03-27 07:49:52 -07002456 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002457 }
Jeff Browncaca8812013-05-09 13:34:33 -07002458
2459 if (canceled) {
2460 Log.i(TAG, "Ignoring HOME; event canceled.");
2461 return -1;
2462 }
2463
Yorke Lee4f803242014-12-15 23:22:06 +00002464 // If an incoming call is ringing, HOME is totally disabled.
2465 // (The user is already on the InCallUI at this point,
2466 // and his ONLY options are to answer or reject the call.)
2467 TelecomManager telecomManager = getTelecommService();
2468 if (telecomManager != null && telecomManager.isRinging()) {
2469 Log.i(TAG, "Ignoring HOME; there's a ringing incoming call.");
2470 return -1;
2471 }
2472
Jeff Browncaca8812013-05-09 13:34:33 -07002473 // Delay handling home if a double-tap is possible.
2474 if (mDoubleTapOnHomeBehavior != DOUBLE_TAP_HOME_NOTHING) {
2475 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); // just in case
2476 mHomeDoubleTapPending = true;
2477 mHandler.postDelayed(mHomeDoubleTapTimeoutRunnable,
2478 ViewConfiguration.getDoubleTapTimeout());
2479 return -1;
2480 }
2481
Jeff Brown13f00f02014-10-31 14:45:50 -07002482 handleShortPressOnHome();
Jeff Browncaca8812013-05-09 13:34:33 -07002483 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002484 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002485
2486 // If a system window has focus, then it doesn't make sense
2487 // right now to interact with applications.
2488 WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null;
2489 if (attrs != null) {
2490 final int type = attrs.type;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002491 if (type == WindowManager.LayoutParams.TYPE_KEYGUARD_SCRIM
2492 || type == WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG
2493 || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002494 // the "app" is keyguard, so give it the key
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002495 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002496 }
2497 final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length;
2498 for (int i=0; i<typeCount; i++) {
2499 if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) {
2500 // don't do anything, but also don't pass it to the app
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002501 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002502 }
2503 }
2504 }
Jeff Browncaca8812013-05-09 13:34:33 -07002505
2506 // Remember that home is pressed and handle special actions.
2507 if (repeatCount == 0) {
2508 mHomePressed = true;
2509 if (mHomeDoubleTapPending) {
2510 mHomeDoubleTapPending = false;
2511 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable);
2512 handleDoubleTapOnHome();
2513 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI
2514 || mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
2515 preloadRecentApps();
Michael Jurka7f2668c2012-03-27 07:49:52 -07002516 }
Jeff Browncaca8812013-05-09 13:34:33 -07002517 } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) {
2518 if (!keyguardOn) {
2519 handleLongPressOnHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002520 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002521 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002522 return -1;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002523 } else if (keyCode == KeyEvent.KEYCODE_MENU) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002524 // Hijack modified menu keys for debugging features
2525 final int chordBug = KeyEvent.META_SHIFT_ON;
2526
2527 if (down && repeatCount == 0) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002528 if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002529 Intent intent = new Intent(Intent.ACTION_BUG_REPORT);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002530 mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT,
2531 null, null, null, 0, null, null);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002532 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002533 } else if (SHOW_PROCESSES_ON_ALT_MENU &&
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002534 (metaState & KeyEvent.META_ALT_ON) == KeyEvent.META_ALT_ON) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002535 Intent service = new Intent();
2536 service.setClassName(mContext, "com.android.server.LoadAverageService");
2537 ContentResolver res = mContext.getContentResolver();
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002538 boolean shown = Settings.Global.getInt(
2539 res, Settings.Global.SHOW_PROCESSES, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002540 if (!shown) {
2541 mContext.startService(service);
2542 } else {
2543 mContext.stopService(service);
2544 }
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002545 Settings.Global.putInt(
2546 res, Settings.Global.SHOW_PROCESSES, shown ? 0 : 1);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002547 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002548 }
2549 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002550 } else if (keyCode == KeyEvent.KEYCODE_SEARCH) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002551 if (down) {
2552 if (repeatCount == 0) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002553 mSearchKeyShortcutPending = true;
2554 mConsumeSearchKeyUp = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002555 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002556 } else {
2557 mSearchKeyShortcutPending = false;
2558 if (mConsumeSearchKeyUp) {
2559 mConsumeSearchKeyUp = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002560 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002561 }
2562 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002563 return 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002564 } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) {
Michael Wrightc9ebea72013-01-16 19:25:02 -08002565 if (!keyguardOn) {
Jeff Browncaca8812013-05-09 13:34:33 -07002566 if (down && repeatCount == 0) {
2567 preloadRecentApps();
2568 } else if (!down) {
2569 toggleRecentApps();
Michael Wrightc9ebea72013-01-16 19:25:02 -08002570 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002571 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002572 return -1;
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002573 } else if (keyCode == KeyEvent.KEYCODE_ASSIST) {
2574 if (down) {
2575 if (repeatCount == 0) {
2576 mAssistKeyLongPressed = false;
2577 } else if (repeatCount == 1) {
2578 mAssistKeyLongPressed = true;
2579 if (!keyguardOn) {
2580 launchAssistLongPressAction();
2581 }
2582 }
2583 } else {
2584 if (mAssistKeyLongPressed) {
2585 mAssistKeyLongPressed = false;
2586 } else {
2587 if (!keyguardOn) {
2588 launchAssistAction();
2589 }
2590 }
2591 }
2592 return -1;
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002593 } else if (keyCode == KeyEvent.KEYCODE_VOICE_ASSIST) {
2594 if (!down) {
2595 Intent voiceIntent;
Michael Wright869a67c2014-08-26 19:33:06 -07002596 if (!keyguardOn) {
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002597 voiceIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
2598 } else {
2599 voiceIntent = new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
Michael Wright869a67c2014-08-26 19:33:06 -07002600 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, true);
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002601 }
2602 mContext.startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
2603 }
Jeff Sharkey2991fa32012-12-05 18:06:43 -08002604 } else if (keyCode == KeyEvent.KEYCODE_SYSRQ) {
2605 if (down && repeatCount == 0) {
2606 mHandler.post(mScreenshotRunnable);
2607 }
2608 return -1;
Michael Wrightb854e242013-02-05 17:54:02 -08002609 } else if (keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP
2610 || keyCode == KeyEvent.KEYCODE_BRIGHTNESS_DOWN) {
2611 if (down) {
2612 int direction = keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP ? 1 : -1;
2613
2614 // Disable autobrightness if it's on
2615 int auto = Settings.System.getIntForUser(
2616 mContext.getContentResolver(),
2617 Settings.System.SCREEN_BRIGHTNESS_MODE,
2618 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2619 UserHandle.USER_CURRENT_OR_SELF);
2620 if (auto != 0) {
2621 Settings.System.putIntForUser(mContext.getContentResolver(),
2622 Settings.System.SCREEN_BRIGHTNESS_MODE,
2623 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2624 UserHandle.USER_CURRENT_OR_SELF);
2625 }
2626
2627 int min = mPowerManager.getMinimumScreenBrightnessSetting();
2628 int max = mPowerManager.getMaximumScreenBrightnessSetting();
2629 int step = (max - min + BRIGHTNESS_STEPS - 1) / BRIGHTNESS_STEPS * direction;
2630 int brightness = Settings.System.getIntForUser(mContext.getContentResolver(),
2631 Settings.System.SCREEN_BRIGHTNESS,
2632 mPowerManager.getDefaultScreenBrightnessSetting(),
2633 UserHandle.USER_CURRENT_OR_SELF);
2634 brightness += step;
2635 // Make sure we don't go beyond the limits.
2636 brightness = Math.min(max, brightness);
2637 brightness = Math.max(min, brightness);
2638
2639 Settings.System.putIntForUser(mContext.getContentResolver(),
2640 Settings.System.SCREEN_BRIGHTNESS, brightness,
2641 UserHandle.USER_CURRENT_OR_SELF);
Alan Viverette5a399492014-07-14 16:19:38 -07002642 mContext.startActivityAsUser(new Intent(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG),
2643 UserHandle.CURRENT_OR_SELF);
Michael Wrightb854e242013-02-05 17:54:02 -08002644 }
2645 return -1;
Michael Wrightce0c13a2014-07-30 10:49:21 -07002646 } else if (KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07002647 if (down) {
2648 mPendingMetaAction = true;
2649 } else if (mPendingMetaAction) {
Michael Wright8ab940a2014-09-01 11:01:27 -07002650 launchAssistAction(Intent.EXTRA_ASSIST_INPUT_HINT_KEYBOARD);
Michael Wright6a62e552014-06-03 19:19:48 -07002651 }
2652 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002653 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002654
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002655 // Shortcuts are invoked through Search+key, so intercept those here
Jeff Browncaab4d02010-12-09 22:13:41 -08002656 // Any printing key that is chorded with Search should be consumed
2657 // even if no shortcut was invoked. This prevents text from being
2658 // inadvertently inserted when using a keyboard that has built-in macro
2659 // shortcut keys (that emit Search+x) and some of them are not registered.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002660 if (mSearchKeyShortcutPending) {
Jeff Browncaab4d02010-12-09 22:13:41 -08002661 final KeyCharacterMap kcm = event.getKeyCharacterMap();
2662 if (kcm.isPrintingKey(keyCode)) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002663 mConsumeSearchKeyUp = true;
2664 mSearchKeyShortcutPending = false;
Jeff Browncaab4d02010-12-09 22:13:41 -08002665 if (down && repeatCount == 0 && !keyguardOn) {
2666 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState);
2667 if (shortcutIntent != null) {
2668 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002669 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002670 mContext.startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002671 } catch (ActivityNotFoundException ex) {
2672 Slog.w(TAG, "Dropping shortcut key combination because "
2673 + "the activity to which it is registered was not found: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002674 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode), ex);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002675 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002676 } else {
2677 Slog.i(TAG, "Dropping unregistered shortcut key combination: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002678 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002679 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002680 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002681 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002682 }
2683 }
2684
Jeff Brown68b909d2011-12-07 16:36:01 -08002685 // Invoke shortcuts using Meta.
Jeff Brown602ab322012-05-16 13:33:47 -07002686 if (down && repeatCount == 0 && !keyguardOn
Jeff Brown68b909d2011-12-07 16:36:01 -08002687 && (metaState & KeyEvent.META_META_ON) != 0) {
2688 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brown602ab322012-05-16 13:33:47 -07002689 if (kcm.isPrintingKey(keyCode)) {
2690 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode,
2691 metaState & ~(KeyEvent.META_META_ON
2692 | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON));
2693 if (shortcutIntent != null) {
2694 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2695 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002696 mContext.startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brown602ab322012-05-16 13:33:47 -07002697 } catch (ActivityNotFoundException ex) {
2698 Slog.w(TAG, "Dropping shortcut key combination because "
2699 + "the activity to which it is registered was not found: "
2700 + "META+" + KeyEvent.keyCodeToString(keyCode), ex);
2701 }
2702 return -1;
Jeff Brown68b909d2011-12-07 16:36:01 -08002703 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002704 }
2705 }
2706
Jeff Brown6651a632011-11-28 12:59:11 -08002707 // Handle application launch keys.
Jeff Brown602ab322012-05-16 13:33:47 -07002708 if (down && repeatCount == 0 && !keyguardOn) {
Jeff Brown6651a632011-11-28 12:59:11 -08002709 String category = sApplicationLaunchKeyCategories.get(keyCode);
2710 if (category != null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -08002711 Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category);
Jeff Brown6651a632011-11-28 12:59:11 -08002712 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2713 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002714 mContext.startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brown6651a632011-11-28 12:59:11 -08002715 } catch (ActivityNotFoundException ex) {
2716 Slog.w(TAG, "Dropping application launch key because "
2717 + "the activity to which it is registered was not found: "
2718 + "keyCode=" + keyCode + ", category=" + category, ex);
2719 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002720 return -1;
Jeff Brown6651a632011-11-28 12:59:11 -08002721 }
2722 }
2723
Michael Wright61c46752014-08-21 16:57:33 -07002724 // Display task switcher for ALT-TAB.
Jeff Brown68b909d2011-12-07 16:36:01 -08002725 if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_TAB) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002726 if (mRecentAppsHeldModifiers == 0 && !keyguardOn) {
Jeff Brown68b909d2011-12-07 16:36:01 -08002727 final int shiftlessModifiers = event.getModifiers() & ~KeyEvent.META_SHIFT_MASK;
Michael Wright61c46752014-08-21 16:57:33 -07002728 if (KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_ALT_ON)) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002729 mRecentAppsHeldModifiers = shiftlessModifiers;
2730 showRecentApps(true);
Jeff Brown68b909d2011-12-07 16:36:01 -08002731 return -1;
2732 }
2733 }
Winson Chung1e8d71b2014-05-16 17:05:22 -07002734 } else if (!down && mRecentAppsHeldModifiers != 0
2735 && (metaState & mRecentAppsHeldModifiers) == 0) {
2736 mRecentAppsHeldModifiers = 0;
Winson Chungcdcd4872014-08-05 18:00:13 -07002737 hideRecentApps(true, false);
Jeff Brown68b909d2011-12-07 16:36:01 -08002738 }
2739
Jeff Browncf39bdf2012-05-18 14:41:19 -07002740 // Handle keyboard language switching.
2741 if (down && repeatCount == 0
2742 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2743 || (keyCode == KeyEvent.KEYCODE_SPACE
2744 && (metaState & KeyEvent.META_CTRL_MASK) != 0))) {
2745 int direction = (metaState & KeyEvent.META_SHIFT_MASK) != 0 ? -1 : 1;
2746 mWindowManagerFuncs.switchKeyboardLayout(event.getDeviceId(), direction);
2747 return -1;
2748 }
2749 if (mLanguageSwitchKeyPressed && !down
2750 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2751 || keyCode == KeyEvent.KEYCODE_SPACE)) {
2752 mLanguageSwitchKeyPressed = false;
2753 return -1;
2754 }
2755
Jeff Brown13f00f02014-10-31 14:45:50 -07002756 if (isValidGlobalKey(keyCode)
2757 && mGlobalKeyManager.handleGlobalKey(mContext, keyCode, event)) {
Justin Kohd378ad72013-04-01 12:18:26 -07002758 return -1;
2759 }
2760
Michael Wright6a62e552014-06-03 19:19:48 -07002761 // Reserve all the META modifier combos for system behavior
Michael Wrightce0c13a2014-07-30 10:49:21 -07002762 if ((metaState & KeyEvent.META_META_ON) != 0) {
Michael Wright6a62e552014-06-03 19:19:48 -07002763 return -1;
2764 }
2765
Jeff Brown68b909d2011-12-07 16:36:01 -08002766 // Let the application handle the key.
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002767 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002768 }
2769
Jeff Brown3915bb82010-11-05 15:02:16 -07002770 /** {@inheritDoc} */
2771 @Override
Jeff Brown49ed71d2010-12-06 17:13:33 -08002772 public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown54875002011-04-06 15:33:01 -07002773 // Note: This method is only called if the initial down was unhandled.
Jeff Brown40013652012-05-16 21:22:36 -07002774 if (DEBUG_INPUT) {
Jeff Brown1f245102010-11-18 20:53:46 -08002775 Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction()
2776 + ", flags=" + event.getFlags()
2777 + ", keyCode=" + event.getKeyCode()
2778 + ", scanCode=" + event.getScanCode()
2779 + ", metaState=" + event.getMetaState()
2780 + ", repeatCount=" + event.getRepeatCount()
2781 + ", policyFlags=" + policyFlags);
Jeff Brown3915bb82010-11-05 15:02:16 -07002782 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002783
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002784 KeyEvent fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002785 if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
2786 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002787 final int keyCode = event.getKeyCode();
2788 final int metaState = event.getMetaState();
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002789 final boolean initialDown = event.getAction() == KeyEvent.ACTION_DOWN
2790 && event.getRepeatCount() == 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002791
Jeff Brown54875002011-04-06 15:33:01 -07002792 // Check for fallback actions specified by the key character map.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002793 final FallbackAction fallbackAction;
2794 if (initialDown) {
2795 fallbackAction = kcm.getFallbackAction(keyCode, metaState);
2796 } else {
2797 fallbackAction = mFallbackActions.get(keyCode);
2798 }
2799
2800 if (fallbackAction != null) {
Jeff Brown40013652012-05-16 21:22:36 -07002801 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002802 Slog.d(TAG, "Fallback: keyCode=" + fallbackAction.keyCode
2803 + " metaState=" + Integer.toHexString(fallbackAction.metaState));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002804 }
2805
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002806 final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK;
2807 fallbackEvent = KeyEvent.obtain(
Jeff Brown49ed71d2010-12-06 17:13:33 -08002808 event.getDownTime(), event.getEventTime(),
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002809 event.getAction(), fallbackAction.keyCode,
2810 event.getRepeatCount(), fallbackAction.metaState,
Jeff Brown49ed71d2010-12-06 17:13:33 -08002811 event.getDeviceId(), event.getScanCode(),
2812 flags, event.getSource(), null);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002813
2814 if (!interceptFallback(win, fallbackEvent, policyFlags)) {
2815 fallbackEvent.recycle();
2816 fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002817 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002818
2819 if (initialDown) {
2820 mFallbackActions.put(keyCode, fallbackAction);
2821 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2822 mFallbackActions.remove(keyCode);
2823 fallbackAction.recycle();
2824 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002825 }
2826 }
2827
Jeff Brown40013652012-05-16 21:22:36 -07002828 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002829 if (fallbackEvent == null) {
2830 Slog.d(TAG, "No fallback.");
2831 } else {
2832 Slog.d(TAG, "Performing fallback: " + fallbackEvent);
2833 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002834 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002835 return fallbackEvent;
Jeff Brown3915bb82010-11-05 15:02:16 -07002836 }
2837
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002838 private boolean interceptFallback(WindowState win, KeyEvent fallbackEvent, int policyFlags) {
Jeff Brown037c33e2014-04-09 00:31:55 -07002839 int actions = interceptKeyBeforeQueueing(fallbackEvent, policyFlags);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002840 if ((actions & ACTION_PASS_TO_USER) != 0) {
2841 long delayMillis = interceptKeyBeforeDispatching(
2842 win, fallbackEvent, policyFlags);
2843 if (delayMillis == 0) {
2844 return true;
2845 }
2846 }
2847 return false;
Jeff Brown6f2fba42011-02-19 01:08:02 -08002848 }
2849
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002850 private void launchAssistLongPressAction() {
2851 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
2852 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
2853
2854 // launch the search activity
2855 Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS);
2856 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2857 try {
RoboErik8a2cfc32014-05-16 11:19:38 -07002858 // TODO: This only stops the factory-installed search manager.
Jim Miller45308b12012-06-18 19:23:39 -07002859 // Need to formalize an API to handle others
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002860 SearchManager searchManager = getSearchManager();
2861 if (searchManager != null) {
2862 searchManager.stopSearch();
2863 }
Michael Wright43e27f72013-04-10 14:06:48 -07002864 mContext.startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002865 } catch (ActivityNotFoundException e) {
2866 Slog.w(TAG, "No activity to handle assist long press action.", e);
2867 }
2868 }
2869
2870 private void launchAssistAction() {
Michael Wright8ab940a2014-09-01 11:01:27 -07002871 launchAssistAction(null);
2872 }
2873
2874 private void launchAssistAction(String hint) {
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002875 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
Amith Yamasanic1d07a42012-08-14 09:32:02 -07002876 Intent intent = ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE))
Dianne Hackbornf9c5e0f2013-01-23 14:39:13 -08002877 .getAssistIntent(mContext, true, UserHandle.USER_CURRENT);
Jim Miller45308b12012-06-18 19:23:39 -07002878 if (intent != null) {
Michael Wright8ab940a2014-09-01 11:01:27 -07002879 if (hint != null) {
2880 intent.putExtra(hint, true);
2881 }
Jim Miller45308b12012-06-18 19:23:39 -07002882 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
2883 | Intent.FLAG_ACTIVITY_SINGLE_TOP
2884 | Intent.FLAG_ACTIVITY_CLEAR_TOP);
2885 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002886 mContext.startActivityAsUser(intent, UserHandle.CURRENT);
Jim Miller45308b12012-06-18 19:23:39 -07002887 } catch (ActivityNotFoundException e) {
2888 Slog.w(TAG, "No activity to handle assist action.", e);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002889 }
2890 }
2891 }
2892
2893 private SearchManager getSearchManager() {
2894 if (mSearchManager == null) {
2895 mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
2896 }
2897 return mSearchManager;
2898 }
2899
Jeff Browncaca8812013-05-09 13:34:33 -07002900 private void preloadRecentApps() {
2901 mPreloadedRecentApps = true;
2902 try {
2903 IStatusBarService statusbar = getStatusBarService();
2904 if (statusbar != null) {
2905 statusbar.preloadRecentApps();
2906 }
2907 } catch (RemoteException e) {
2908 Slog.e(TAG, "RemoteException when preloading recent apps", e);
2909 // re-acquire status bar service next time it is needed.
2910 mStatusBarService = null;
2911 }
2912 }
2913
2914 private void cancelPreloadRecentApps() {
2915 if (mPreloadedRecentApps) {
2916 mPreloadedRecentApps = false;
2917 try {
2918 IStatusBarService statusbar = getStatusBarService();
2919 if (statusbar != null) {
2920 statusbar.cancelPreloadRecentApps();
2921 }
2922 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002923 Slog.e(TAG, "RemoteException when cancelling recent apps preload", e);
Jeff Browncaca8812013-05-09 13:34:33 -07002924 // re-acquire status bar service next time it is needed.
2925 mStatusBarService = null;
2926 }
2927 }
2928 }
2929
2930 private void toggleRecentApps() {
2931 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
Jeff Browncaca8812013-05-09 13:34:33 -07002932 try {
2933 IStatusBarService statusbar = getStatusBarService();
2934 if (statusbar != null) {
2935 statusbar.toggleRecentApps();
2936 }
2937 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002938 Slog.e(TAG, "RemoteException when toggling recent apps", e);
2939 // re-acquire status bar service next time it is needed.
2940 mStatusBarService = null;
2941 }
2942 }
2943
Craig Mautner84984fa2014-06-19 11:19:20 -07002944 @Override
2945 public void showRecentApps() {
2946 mHandler.removeMessages(MSG_DISPATCH_SHOW_RECENTS);
2947 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_RECENTS);
2948 }
2949
Winson Chung1e8d71b2014-05-16 17:05:22 -07002950 private void showRecentApps(boolean triggeredFromAltTab) {
2951 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
2952 try {
2953 IStatusBarService statusbar = getStatusBarService();
2954 if (statusbar != null) {
2955 statusbar.showRecentApps(triggeredFromAltTab);
2956 }
2957 } catch (RemoteException e) {
Jeff Browncaca8812013-05-09 13:34:33 -07002958 Slog.e(TAG, "RemoteException when showing recent apps", e);
2959 // re-acquire status bar service next time it is needed.
2960 mStatusBarService = null;
2961 }
2962 }
2963
Winson Chungcdcd4872014-08-05 18:00:13 -07002964 private void hideRecentApps(boolean triggeredFromAltTab, boolean triggeredFromHome) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002965 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
2966 try {
2967 IStatusBarService statusbar = getStatusBarService();
2968 if (statusbar != null) {
Winson Chungcdcd4872014-08-05 18:00:13 -07002969 statusbar.hideRecentApps(triggeredFromAltTab, triggeredFromHome);
Winson Chung1e8d71b2014-05-16 17:05:22 -07002970 }
2971 } catch (RemoteException e) {
2972 Slog.e(TAG, "RemoteException when closing recent apps", e);
2973 // re-acquire status bar service next time it is needed.
2974 mStatusBarService = null;
2975 }
2976 }
2977
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002978 /**
2979 * A home key -> launch home action was detected. Take the appropriate action
2980 * given the situation with the keyguard.
2981 */
2982 void launchHomeFromHotKey() {
Jim Millerab954542014-10-10 18:21:49 -07002983 if (isKeyguardShowingAndNotOccluded()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002984 // don't launch home if keyguard showing
Jim Miller5ecd8112013-01-09 18:50:26 -08002985 } else if (!mHideLockScreen && mKeyguardDelegate.isInputRestricted()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002986 // when in keyguard restricted mode, must first verify unlock
2987 // before launching home
Jim Miller5ecd8112013-01-09 18:50:26 -08002988 mKeyguardDelegate.verifyUnlock(new OnKeyguardExitResult() {
Jose Lima9546b202014-07-02 17:21:51 -07002989 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002990 public void onKeyguardExitResult(boolean success) {
2991 if (success) {
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07002992 try {
2993 ActivityManagerNative.getDefault().stopAppSwitches();
2994 } catch (RemoteException e) {
2995 }
Joe Onoratof275f0c2009-11-24 16:11:13 -05002996 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
Bryce Lee01b0c5f2015-02-05 18:24:04 -08002997 startDockOrHome(true /*fromHomeKey*/);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002998 }
2999 }
3000 });
3001 } else {
3002 // no keyguard stuff to worry about, just launch home!
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07003003 try {
3004 ActivityManagerNative.getDefault().stopAppSwitches();
3005 } catch (RemoteException e) {
3006 }
Winson Chungd543c1b2014-06-23 15:06:45 -07003007 if (mRecentsVisible) {
3008 // Hide Recents and notify it to launch Home
3009 awakenDreams();
3010 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
Winson Chungcdcd4872014-08-05 18:00:13 -07003011 hideRecentApps(false, true);
Winson Chungd543c1b2014-06-23 15:06:45 -07003012 } else {
3013 // Otherwise, just launch Home
3014 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
Bryce Lee01b0c5f2015-02-05 18:24:04 -08003015 startDockOrHome(true /*fromHomeKey*/);
Winson Chungd543c1b2014-06-23 15:06:45 -07003016 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003017 }
3018 }
3019
John Spurlock04db1762013-05-13 12:46:41 -04003020 private final Runnable mClearHideNavigationFlag = new Runnable() {
3021 @Override
3022 public void run() {
3023 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
3024 // Clear flags.
3025 mForceClearedSystemUiFlags &=
3026 ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
3027 }
3028 mWindowManagerFuncs.reevaluateStatusBarVisibility();
Dianne Hackborne26ab702011-10-16 13:21:33 -07003029 }
3030 };
3031
3032 /**
3033 * Input handler used while nav bar is hidden. Captures any touch on the screen,
3034 * to determine when the nav bar should be shown and prevent applications from
3035 * receiving those touches.
3036 */
Jeff Brown32cbc38552011-12-01 14:01:49 -08003037 final class HideNavInputEventReceiver extends InputEventReceiver {
3038 public HideNavInputEventReceiver(InputChannel inputChannel, Looper looper) {
3039 super(inputChannel, looper);
3040 }
3041
Dianne Hackborndf89e652011-10-06 22:35:11 -07003042 @Override
Jeff Brown32cbc38552011-12-01 14:01:49 -08003043 public void onInputEvent(InputEvent event) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003044 boolean handled = false;
3045 try {
Jeff Brown4952dfd2011-11-30 19:23:22 -08003046 if (event instanceof MotionEvent
3047 && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
3048 final MotionEvent motionEvent = (MotionEvent)event;
3049 if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003050 // When the user taps down, we re-show the nav bar.
3051 boolean changed = false;
John Spurlock04db1762013-05-13 12:46:41 -04003052 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003053 // Any user activity always causes us to show the
3054 // navigation controls, if they had been hidden.
3055 // We also clear the low profile and only content
3056 // flags so that tapping on the screen will atomically
3057 // restore all currently hidden screen decorations.
3058 int newVal = mResettingSystemUiFlags |
3059 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
3060 View.SYSTEM_UI_FLAG_LOW_PROFILE |
3061 View.SYSTEM_UI_FLAG_FULLSCREEN;
Dianne Hackborne26ab702011-10-16 13:21:33 -07003062 if (mResettingSystemUiFlags != newVal) {
3063 mResettingSystemUiFlags = newVal;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003064 changed = true;
3065 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003066 // We don't allow the system's nav bar to be hidden
3067 // again for 1 second, to prevent applications from
3068 // spamming us and keeping it from being shown.
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003069 newVal = mForceClearedSystemUiFlags |
3070 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
Dianne Hackborne26ab702011-10-16 13:21:33 -07003071 if (mForceClearedSystemUiFlags != newVal) {
3072 mForceClearedSystemUiFlags = newVal;
3073 changed = true;
John Spurlock04db1762013-05-13 12:46:41 -04003074 mHandler.postDelayed(mClearHideNavigationFlag, 1000);
Dianne Hackborne26ab702011-10-16 13:21:33 -07003075 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07003076 }
3077 if (changed) {
3078 mWindowManagerFuncs.reevaluateStatusBarVisibility();
3079 }
3080 }
3081 }
3082 } finally {
Jeff Brown32cbc38552011-12-01 14:01:49 -08003083 finishInputEvent(event, handled);
Dianne Hackborndf89e652011-10-06 22:35:11 -07003084 }
3085 }
Jeff Brown32cbc38552011-12-01 14:01:49 -08003086 }
3087 final InputEventReceiver.Factory mHideNavInputEventReceiverFactory =
3088 new InputEventReceiver.Factory() {
3089 @Override
3090 public InputEventReceiver createInputEventReceiver(
3091 InputChannel inputChannel, Looper looper) {
3092 return new HideNavInputEventReceiver(inputChannel, looper);
3093 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07003094 };
3095
3096 @Override
3097 public int adjustSystemUiVisibilityLw(int visibility) {
John Spurlock5b9145b2013-08-20 15:13:47 -04003098 mStatusBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
3099 mNavigationBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
Winson Chungd42a6cf2014-06-03 16:24:04 -07003100 mRecentsVisible = (visibility & View.RECENT_APPS_VISIBLE) > 0;
John Spurlock27735a42013-08-14 17:57:38 -04003101
Dianne Hackborndf89e652011-10-06 22:35:11 -07003102 // Reset any bits in mForceClearingStatusBarVisibility that
3103 // are now clear.
Dianne Hackborne26ab702011-10-16 13:21:33 -07003104 mResettingSystemUiFlags &= visibility;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003105 // Clear any bits in the new visibility that are currently being
3106 // force cleared, before reporting it.
Dianne Hackborne26ab702011-10-16 13:21:33 -07003107 return visibility & ~mResettingSystemUiFlags
3108 & ~mForceClearedSystemUiFlags;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003109 }
3110
Craig Mautner69b08182012-09-05 13:07:13 -07003111 @Override
Adrian Roos37d7a682014-11-06 18:15:16 +01003112 public void getInsetHintLw(WindowManager.LayoutParams attrs, Rect outContentInsets,
3113 Rect outStableInsets) {
John Spurlockc6d1c602014-01-17 15:22:06 -05003114 final int fl = PolicyControl.getWindowFlags(null, attrs);
John Spurlock1db8b682014-02-18 11:18:59 -05003115 final int sysuiVis = PolicyControl.getSystemUiVisibility(null, attrs);
3116 final int systemUiVisibility = (sysuiVis | attrs.subtreeSystemUiVisibility);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003117
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003118 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003119 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003120 int availRight, availBottom;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003121 if (canHideNavigationBar() &&
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003122 (systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003123 availRight = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3124 availBottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
3125 } else {
3126 availRight = mRestrictedScreenLeft + mRestrictedScreenWidth;
3127 availBottom = mRestrictedScreenTop + mRestrictedScreenHeight;
3128 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003129 if ((systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
3130 if ((fl & FLAG_FULLSCREEN) != 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003131 outContentInsets.set(mStableFullscreenLeft, mStableFullscreenTop,
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003132 availRight - mStableFullscreenRight,
3133 availBottom - mStableFullscreenBottom);
3134 } else {
Adrian Roos37d7a682014-11-06 18:15:16 +01003135 outContentInsets.set(mStableLeft, mStableTop,
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003136 availRight - mStableRight, availBottom - mStableBottom);
3137 }
Dianne Hackbornc652de82013-02-15 16:32:56 -08003138 } else if ((fl & FLAG_FULLSCREEN) != 0 || (fl & FLAG_LAYOUT_IN_OVERSCAN) != 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003139 outContentInsets.setEmpty();
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003140 } else if ((systemUiVisibility & (View.SYSTEM_UI_FLAG_FULLSCREEN
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003141 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)) == 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003142 outContentInsets.set(mCurLeft, mCurTop,
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003143 availRight - mCurRight, availBottom - mCurBottom);
3144 } else {
Adrian Roos37d7a682014-11-06 18:15:16 +01003145 outContentInsets.set(mCurLeft, mCurTop,
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003146 availRight - mCurRight, availBottom - mCurBottom);
3147 }
Adrian Roos37d7a682014-11-06 18:15:16 +01003148
3149 outStableInsets.set(mStableLeft, mStableTop,
3150 availRight - mStableRight, availBottom - mStableBottom);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003151 return;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003152 }
Adrian Roos37d7a682014-11-06 18:15:16 +01003153 outContentInsets.setEmpty();
3154 outStableInsets.setEmpty();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003155 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003156
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003157 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07003158 @Override
3159 public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight,
3160 int displayRotation) {
Dianne Hackbornc652de82013-02-15 16:32:56 -08003161 final int overscanLeft, overscanTop, overscanRight, overscanBottom;
3162 if (isDefaultDisplay) {
3163 switch (displayRotation) {
3164 case Surface.ROTATION_90:
3165 overscanLeft = mOverscanTop;
3166 overscanTop = mOverscanRight;
3167 overscanRight = mOverscanBottom;
3168 overscanBottom = mOverscanLeft;
3169 break;
3170 case Surface.ROTATION_180:
3171 overscanLeft = mOverscanRight;
3172 overscanTop = mOverscanBottom;
3173 overscanRight = mOverscanLeft;
3174 overscanBottom = mOverscanTop;
3175 break;
3176 case Surface.ROTATION_270:
3177 overscanLeft = mOverscanBottom;
3178 overscanTop = mOverscanLeft;
3179 overscanRight = mOverscanTop;
3180 overscanBottom = mOverscanRight;
3181 break;
3182 default:
3183 overscanLeft = mOverscanLeft;
3184 overscanTop = mOverscanTop;
3185 overscanRight = mOverscanRight;
3186 overscanBottom = mOverscanBottom;
3187 break;
3188 }
3189 } else {
3190 overscanLeft = 0;
3191 overscanTop = 0;
3192 overscanRight = 0;
3193 overscanBottom = 0;
3194 }
Dianne Hackborn313440842013-02-19 19:22:59 -08003195 mOverscanScreenLeft = mRestrictedOverscanScreenLeft = 0;
3196 mOverscanScreenTop = mRestrictedOverscanScreenTop = 0;
3197 mOverscanScreenWidth = mRestrictedOverscanScreenWidth = displayWidth;
3198 mOverscanScreenHeight = mRestrictedOverscanScreenHeight = displayHeight;
Dianne Hackbornc652de82013-02-15 16:32:56 -08003199 mSystemLeft = 0;
3200 mSystemTop = 0;
3201 mSystemRight = displayWidth;
3202 mSystemBottom = displayHeight;
3203 mUnrestrictedScreenLeft = overscanLeft;
3204 mUnrestrictedScreenTop = overscanTop;
3205 mUnrestrictedScreenWidth = displayWidth - overscanLeft - overscanRight;
3206 mUnrestrictedScreenHeight = displayHeight - overscanTop - overscanBottom;
3207 mRestrictedScreenLeft = mUnrestrictedScreenLeft;
3208 mRestrictedScreenTop = mUnrestrictedScreenTop;
John Spurlockad3e6cb2013-04-30 08:47:43 -04003209 mRestrictedScreenWidth = mSystemGestures.screenWidth = mUnrestrictedScreenWidth;
3210 mRestrictedScreenHeight = mSystemGestures.screenHeight = mUnrestrictedScreenHeight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003211 mDockLeft = mContentLeft = mVoiceContentLeft = mStableLeft = mStableFullscreenLeft
Dianne Hackbornc652de82013-02-15 16:32:56 -08003212 = mCurLeft = mUnrestrictedScreenLeft;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003213 mDockTop = mContentTop = mVoiceContentTop = mStableTop = mStableFullscreenTop
Dianne Hackbornc652de82013-02-15 16:32:56 -08003214 = mCurTop = mUnrestrictedScreenTop;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003215 mDockRight = mContentRight = mVoiceContentRight = mStableRight = mStableFullscreenRight
Dianne Hackbornc652de82013-02-15 16:32:56 -08003216 = mCurRight = displayWidth - overscanRight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003217 mDockBottom = mContentBottom = mVoiceContentBottom = mStableBottom = mStableFullscreenBottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003218 = mCurBottom = displayHeight - overscanBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003219 mDockLayer = 0x10000000;
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003220 mStatusBarLayer = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003221
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003222 // start with the current dock rect, which will be (0,0,displayWidth,displayHeight)
3223 final Rect pf = mTmpParentFrame;
3224 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003225 final Rect of = mTmpOverscanFrame;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003226 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04003227 final Rect dcf = mTmpDecorFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003228 pf.left = df.left = of.left = vf.left = mDockLeft;
3229 pf.top = df.top = of.top = vf.top = mDockTop;
3230 pf.right = df.right = of.right = vf.right = mDockRight;
3231 pf.bottom = df.bottom = of.bottom = vf.bottom = mDockBottom;
John Spurlock46646232013-09-30 22:32:42 -04003232 dcf.setEmpty(); // Decor frame N/A for system bars.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003233
Craig Mautner69b08182012-09-05 13:07:13 -07003234 if (isDefaultDisplay) {
3235 // For purposes of putting out fake window up to steal focus, we will
3236 // drive nav being hidden only by whether it is requested.
John Spurlocke1f366f2013-08-05 12:22:40 -04003237 final int sysui = mLastSystemUiFlags;
3238 boolean navVisible = (sysui & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0;
Adrian Roosea562512014-05-05 13:33:03 +02003239 boolean navTranslucent = (sysui
3240 & (View.NAVIGATION_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04003241 boolean immersive = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
3242 boolean immersiveSticky = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
3243 boolean navAllowedHidden = immersive || immersiveSticky;
3244 navTranslucent &= !immersiveSticky; // transient trumps translucent
Adrian Roos4fb3ee32014-08-22 19:29:09 +02003245 boolean isKeyguardShowing = isStatusBarKeyguard() && !mHideLockScreen;
3246 if (!isKeyguardShowing) {
3247 navTranslucent &= areTranslucentBarsAllowed();
3248 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003249
Craig Mautner69b08182012-09-05 13:07:13 -07003250 // When the navigation bar isn't visible, we put up a fake
3251 // input window to catch all touch events. This way we can
3252 // detect when the user presses anywhere to bring back the nav
3253 // bar and ensure the application doesn't see the event.
John Spurlockf1a36642013-10-12 17:50:42 -04003254 if (navVisible || navAllowedHidden) {
Craig Mautner69b08182012-09-05 13:07:13 -07003255 if (mHideNavFakeWindow != null) {
3256 mHideNavFakeWindow.dismiss();
3257 mHideNavFakeWindow = null;
3258 }
3259 } else if (mHideNavFakeWindow == null) {
3260 mHideNavFakeWindow = mWindowManagerFuncs.addFakeWindow(
3261 mHandler.getLooper(), mHideNavInputEventReceiverFactory,
Adam Lesinski95c42972013-10-02 10:13:27 -07003262 "hidden nav", WindowManager.LayoutParams.TYPE_HIDDEN_NAV_CONSUMER, 0,
Craig Mautner69b08182012-09-05 13:07:13 -07003263 0, false, false, true);
Dianne Hackborne26ab702011-10-16 13:21:33 -07003264 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003265
Craig Mautner69b08182012-09-05 13:07:13 -07003266 // For purposes of positioning and showing the nav bar, if we have
3267 // decided that it can't be hidden (because of the screen aspect ratio),
3268 // then take that into account.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003269 navVisible |= !canHideNavigationBar();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003270
John Spurlockad3e6cb2013-04-30 08:47:43 -04003271 boolean updateSysUiVisibility = false;
Craig Mautner69b08182012-09-05 13:07:13 -07003272 if (mNavigationBar != null) {
John Spurlock27735a42013-08-14 17:57:38 -04003273 boolean transientNavBarShowing = mNavigationBarController.isTransientShowing();
Craig Mautner69b08182012-09-05 13:07:13 -07003274 // Force the navigation bar to its appropriate place and
3275 // size. We need to do this directly, instead of relying on
3276 // it to bubble up from the nav bar, because this needs to
3277 // change atomically with screen rotations.
3278 mNavigationBarOnBottom = (!mNavigationBarCanMove || displayWidth < displayHeight);
3279 if (mNavigationBarOnBottom) {
3280 // It's a system nav bar or a portrait screen; nav bar goes on bottom.
Dianne Hackbornc652de82013-02-15 16:32:56 -08003281 int top = displayHeight - overscanBottom
3282 - mNavigationBarHeightForRotation[displayRotation];
3283 mTmpNavigationFrame.set(0, top, displayWidth, displayHeight - overscanBottom);
Craig Mautner69b08182012-09-05 13:07:13 -07003284 mStableBottom = mStableFullscreenBottom = mTmpNavigationFrame.top;
John Spurlockf95b89a2013-10-10 22:10:42 -04003285 if (transientNavBarShowing) {
John Spurlock27735a42013-08-14 17:57:38 -04003286 mNavigationBarController.setBarShowingLw(true);
John Spurlockad3e6cb2013-04-30 08:47:43 -04003287 } else if (navVisible) {
John Spurlock27735a42013-08-14 17:57:38 -04003288 mNavigationBarController.setBarShowingLw(true);
Craig Mautner69b08182012-09-05 13:07:13 -07003289 mDockBottom = mTmpNavigationFrame.top;
Dianne Hackborn313440842013-02-19 19:22:59 -08003290 mRestrictedScreenHeight = mDockBottom - mRestrictedScreenTop;
3291 mRestrictedOverscanScreenHeight = mDockBottom - mRestrictedOverscanScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07003292 } else {
3293 // We currently want to hide the navigation UI.
John Spurlock27735a42013-08-14 17:57:38 -04003294 mNavigationBarController.setBarShowingLw(false);
Craig Mautner69b08182012-09-05 13:07:13 -07003295 }
John Spurlockc6d1c602014-01-17 15:22:06 -05003296 if (navVisible && !navTranslucent && !navAllowedHidden
3297 && !mNavigationBar.isAnimatingLw()
John Spurlockbd957402013-10-03 11:38:39 -04003298 && !mNavigationBarController.wasRecentlyTranslucent()) {
John Spurlocke1f366f2013-08-05 12:22:40 -04003299 // If the opaque nav bar is currently requested to be visible,
Craig Mautner69b08182012-09-05 13:07:13 -07003300 // and not in the process of animating on or off, then
3301 // we can tell the app that it is covered by it.
3302 mSystemBottom = mTmpNavigationFrame.top;
3303 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003304 } else {
Craig Mautner69b08182012-09-05 13:07:13 -07003305 // Landscape screen; nav bar goes to the right.
Dianne Hackbornc652de82013-02-15 16:32:56 -08003306 int left = displayWidth - overscanRight
3307 - mNavigationBarWidthForRotation[displayRotation];
3308 mTmpNavigationFrame.set(left, 0, displayWidth - overscanRight, displayHeight);
Craig Mautner69b08182012-09-05 13:07:13 -07003309 mStableRight = mStableFullscreenRight = mTmpNavigationFrame.left;
John Spurlockf95b89a2013-10-10 22:10:42 -04003310 if (transientNavBarShowing) {
John Spurlock27735a42013-08-14 17:57:38 -04003311 mNavigationBarController.setBarShowingLw(true);
John Spurlockad3e6cb2013-04-30 08:47:43 -04003312 } else if (navVisible) {
John Spurlock27735a42013-08-14 17:57:38 -04003313 mNavigationBarController.setBarShowingLw(true);
Craig Mautner69b08182012-09-05 13:07:13 -07003314 mDockRight = mTmpNavigationFrame.left;
Dianne Hackborn313440842013-02-19 19:22:59 -08003315 mRestrictedScreenWidth = mDockRight - mRestrictedScreenLeft;
3316 mRestrictedOverscanScreenWidth = mDockRight - mRestrictedOverscanScreenLeft;
Craig Mautner69b08182012-09-05 13:07:13 -07003317 } else {
3318 // We currently want to hide the navigation UI.
John Spurlock27735a42013-08-14 17:57:38 -04003319 mNavigationBarController.setBarShowingLw(false);
Craig Mautner69b08182012-09-05 13:07:13 -07003320 }
John Spurlockbd957402013-10-03 11:38:39 -04003321 if (navVisible && !navTranslucent && !mNavigationBar.isAnimatingLw()
3322 && !mNavigationBarController.wasRecentlyTranslucent()) {
Craig Mautner69b08182012-09-05 13:07:13 -07003323 // If the nav bar is currently requested to be visible,
3324 // and not in the process of animating on or off, then
3325 // we can tell the app that it is covered by it.
3326 mSystemRight = mTmpNavigationFrame.left;
3327 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003328 }
Craig Mautner69b08182012-09-05 13:07:13 -07003329 // Make sure the content and current rectangles are updated to
3330 // account for the restrictions from the navigation bar.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003331 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3332 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3333 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3334 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
Craig Mautner69b08182012-09-05 13:07:13 -07003335 mStatusBarLayer = mNavigationBar.getSurfaceLayer();
3336 // And compute the final frame.
3337 mNavigationBar.computeFrameLw(mTmpNavigationFrame, mTmpNavigationFrame,
Adrian Roosfa104232014-06-20 16:10:14 -07003338 mTmpNavigationFrame, mTmpNavigationFrame, mTmpNavigationFrame, dcf,
3339 mTmpNavigationFrame);
Craig Mautnereda67292013-04-28 13:50:14 -07003340 if (DEBUG_LAYOUT) Slog.i(TAG, "mNavigationBar frame: " + mTmpNavigationFrame);
John Spurlock27735a42013-08-14 17:57:38 -04003341 if (mNavigationBarController.checkHiddenLw()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04003342 updateSysUiVisibility = true;
3343 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003344 }
Craig Mautnereda67292013-04-28 13:50:14 -07003345 if (DEBUG_LAYOUT) Slog.i(TAG, String.format("mDock rect: (%d,%d - %d,%d)",
Craig Mautner69b08182012-09-05 13:07:13 -07003346 mDockLeft, mDockTop, mDockRight, mDockBottom));
3347
3348 // decide where the status bar goes ahead of time
3349 if (mStatusBar != null) {
3350 // apply any navigation bar insets
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003351 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3352 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3353 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
3354 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight
3355 + mUnrestrictedScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07003356 vf.left = mStableLeft;
3357 vf.top = mStableTop;
3358 vf.right = mStableRight;
3359 vf.bottom = mStableBottom;
3360
3361 mStatusBarLayer = mStatusBar.getSurfaceLayer();
3362
3363 // Let the status bar determine its size.
Adrian Roosfa104232014-06-20 16:10:14 -07003364 mStatusBar.computeFrameLw(pf, df, vf, vf, vf, dcf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07003365
3366 // For layout, the status bar is always at the top with our fixed height.
3367 mStableTop = mUnrestrictedScreenTop + mStatusBarHeight;
3368
John Spurlocke1f366f2013-08-05 12:22:40 -04003369 boolean statusBarTransient = (sysui & View.STATUS_BAR_TRANSIENT) != 0;
Adrian Roosea562512014-05-05 13:33:03 +02003370 boolean statusBarTranslucent = (sysui
3371 & (View.STATUS_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0;
Adrian Roos4fb3ee32014-08-22 19:29:09 +02003372 if (!isKeyguardShowing) {
3373 statusBarTranslucent &= areTranslucentBarsAllowed();
3374 }
John Spurlock32beb2c2013-03-11 10:16:47 -04003375
Craig Mautner69b08182012-09-05 13:07:13 -07003376 // If the status bar is hidden, we don't want to cause
3377 // windows behind it to scroll.
John Spurlockeda1f692013-09-16 11:38:44 -04003378 if (mStatusBar.isVisibleLw() && !statusBarTransient) {
Craig Mautner69b08182012-09-05 13:07:13 -07003379 // Status bar may go away, so the screen area it occupies
3380 // is available to apps but just covering them when the
3381 // status bar is visible.
3382 mDockTop = mUnrestrictedScreenTop + mStatusBarHeight;
3383
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003384 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3385 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3386 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3387 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
Craig Mautner69b08182012-09-05 13:07:13 -07003388
Craig Mautnereda67292013-04-28 13:50:14 -07003389 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar: " +
Craig Mautner69b08182012-09-05 13:07:13 -07003390 String.format(
3391 "dock=[%d,%d][%d,%d] content=[%d,%d][%d,%d] cur=[%d,%d][%d,%d]",
3392 mDockLeft, mDockTop, mDockRight, mDockBottom,
3393 mContentLeft, mContentTop, mContentRight, mContentBottom,
3394 mCurLeft, mCurTop, mCurRight, mCurBottom));
3395 }
John Spurlocke1f366f2013-08-05 12:22:40 -04003396 if (mStatusBar.isVisibleLw() && !mStatusBar.isAnimatingLw()
John Spurlockbd957402013-10-03 11:38:39 -04003397 && !statusBarTransient && !statusBarTranslucent
3398 && !mStatusBarController.wasRecentlyTranslucent()) {
John Spurlocke1f366f2013-08-05 12:22:40 -04003399 // If the opaque status bar is currently requested to be visible,
Craig Mautner69b08182012-09-05 13:07:13 -07003400 // and not in the process of animating on or off, then
3401 // we can tell the app that it is covered by it.
3402 mSystemTop = mUnrestrictedScreenTop + mStatusBarHeight;
3403 }
John Spurlock27735a42013-08-14 17:57:38 -04003404 if (mStatusBarController.checkHiddenLw()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04003405 updateSysUiVisibility = true;
John Spurlock32beb2c2013-03-11 10:16:47 -04003406 }
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003407 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04003408 if (updateSysUiVisibility) {
3409 updateSystemUiVisibilityLw();
3410 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003411 }
3412 }
3413
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003414 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07003415 @Override
John Spurlock46646232013-09-30 22:32:42 -04003416 public int getSystemDecorLayerLw() {
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003417 if (mStatusBar != null) return mStatusBar.getSurfaceLayer();
3418 if (mNavigationBar != null) return mNavigationBar.getSurfaceLayer();
3419 return 0;
3420 }
3421
Craig Mautner967212c2013-04-13 21:10:58 -07003422 @Override
3423 public void getContentRectLw(Rect r) {
3424 r.set(mContentLeft, mContentTop, mContentRight, mContentBottom);
3425 }
3426
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003427 void setAttachedWindowFrames(WindowState win, int fl, int adjust, WindowState attached,
3428 boolean insetDecors, Rect pf, Rect df, Rect of, Rect cf, Rect vf) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003429 if (win.getSurfaceLayer() > mDockLayer && attached.getSurfaceLayer() < mDockLayer) {
3430 // Here's a special case: if this attached window is a panel that is
3431 // above the dock window, and the window it is attached to is below
3432 // the dock window, then the frames we computed for the window it is
3433 // attached to can not be used because the dock is effectively part
3434 // of the underlying window and the attached window is floating on top
3435 // of the whole thing. So, we ignore the attached window and explicitly
3436 // compute the frames that would be appropriate without the dock.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003437 df.left = of.left = cf.left = vf.left = mDockLeft;
3438 df.top = of.top = cf.top = vf.top = mDockTop;
3439 df.right = of.right = cf.right = vf.right = mDockRight;
3440 df.bottom = of.bottom = cf.bottom = vf.bottom = mDockBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003441 } else {
3442 // The effective display frame of the attached window depends on
3443 // whether it is taking care of insetting its content. If not,
3444 // we need to use the parent's content frame so that the entire
3445 // window is positioned within that content. Otherwise we can use
Wale Ogunwale393b1c12014-10-18 16:22:01 -07003446 // the overscan frame and let the attached window take care of
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003447 // positioning its content appropriately.
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003448 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Wale Ogunwale393b1c12014-10-18 16:22:01 -07003449 // Set the content frame of the attached window to the parent's decor frame
3450 // (same as content frame when IME isn't present) if specifically requested by
3451 // setting {@link WindowManager.LayoutParams#FLAG_LAYOUT_ATTACHED_IN_DECOR} flag.
3452 // Otherwise, use the overscan frame.
3453 cf.set((fl & FLAG_LAYOUT_ATTACHED_IN_DECOR) != 0
3454 ? attached.getContentFrameLw() : attached.getOverscanFrameLw());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003455 } else {
3456 // If the window is resizing, then we want to base the content
3457 // frame on our attached content frame to resize... however,
3458 // things can be tricky if the attached window is NOT in resize
3459 // mode, in which case its content frame will be larger.
3460 // Ungh. So to deal with that, make sure the content frame
3461 // we end up using is not covering the IM dock.
3462 cf.set(attached.getContentFrameLw());
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003463 if (attached.isVoiceInteraction()) {
3464 if (cf.left < mVoiceContentLeft) cf.left = mVoiceContentLeft;
3465 if (cf.top < mVoiceContentTop) cf.top = mVoiceContentTop;
3466 if (cf.right > mVoiceContentRight) cf.right = mVoiceContentRight;
3467 if (cf.bottom > mVoiceContentBottom) cf.bottom = mVoiceContentBottom;
3468 } else if (attached.getSurfaceLayer() < mDockLayer) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003469 if (cf.left < mContentLeft) cf.left = mContentLeft;
3470 if (cf.top < mContentTop) cf.top = mContentTop;
3471 if (cf.right > mContentRight) cf.right = mContentRight;
3472 if (cf.bottom > mContentBottom) cf.bottom = mContentBottom;
3473 }
3474 }
3475 df.set(insetDecors ? attached.getDisplayFrameLw() : cf);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003476 of.set(insetDecors ? attached.getOverscanFrameLw() : cf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003477 vf.set(attached.getVisibleFrameLw());
3478 }
3479 // The LAYOUT_IN_SCREEN flag is used to determine whether the attached
3480 // window should be positioned relative to its parent or the entire
3481 // screen.
3482 pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0
3483 ? attached.getFrameLw() : df);
3484 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003485
3486 private void applyStableConstraints(int sysui, int fl, Rect r) {
3487 if ((sysui & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
3488 // If app is requesting a stable layout, don't let the
3489 // content insets go below the stable values.
3490 if ((fl & FLAG_FULLSCREEN) != 0) {
3491 if (r.left < mStableFullscreenLeft) r.left = mStableFullscreenLeft;
3492 if (r.top < mStableFullscreenTop) r.top = mStableFullscreenTop;
3493 if (r.right > mStableFullscreenRight) r.right = mStableFullscreenRight;
3494 if (r.bottom > mStableFullscreenBottom) r.bottom = mStableFullscreenBottom;
3495 } else {
3496 if (r.left < mStableLeft) r.left = mStableLeft;
3497 if (r.top < mStableTop) r.top = mStableTop;
3498 if (r.right > mStableRight) r.right = mStableRight;
3499 if (r.bottom > mStableBottom) r.bottom = mStableBottom;
3500 }
3501 }
3502 }
3503
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003504 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07003505 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003506 public void layoutWindowLw(WindowState win, WindowState attached) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003507 // we've already done the status bar
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003508 final WindowManager.LayoutParams attrs = win.getAttrs();
3509 if ((win == mStatusBar && (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) == 0) ||
3510 win == mNavigationBar) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003511 return;
3512 }
Craig Mautner69b08182012-09-05 13:07:13 -07003513 final boolean isDefaultDisplay = win.isDefaultDisplay();
3514 final boolean needsToOffsetInputMethodTarget = isDefaultDisplay &&
satok1bc0a492012-04-25 22:47:12 +09003515 (win == mLastInputMethodTargetWindow && mLastInputMethodWindow != null);
3516 if (needsToOffsetInputMethodTarget) {
Craig Mautnereda67292013-04-28 13:50:14 -07003517 if (DEBUG_LAYOUT) Slog.i(TAG, "Offset ime target window by the last ime window state");
satok1bc0a492012-04-25 22:47:12 +09003518 offsetInputMethodWindowLw(mLastInputMethodWindow);
3519 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003520
John Spurlockc6d1c602014-01-17 15:22:06 -05003521 final int fl = PolicyControl.getWindowFlags(win, attrs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003522 final int sim = attrs.softInputMode;
John Spurlock1db8b682014-02-18 11:18:59 -05003523 final int sysUiFl = PolicyControl.getSystemUiVisibility(win, null);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003524
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003525 final Rect pf = mTmpParentFrame;
3526 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003527 final Rect of = mTmpOverscanFrame;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003528 final Rect cf = mTmpContentFrame;
3529 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04003530 final Rect dcf = mTmpDecorFrame;
Adrian Roosfa104232014-06-20 16:10:14 -07003531 final Rect sf = mTmpStableFrame;
John Spurlock46646232013-09-30 22:32:42 -04003532 dcf.setEmpty();
Craig Mautner69b08182012-09-05 13:07:13 -07003533
3534 final boolean hasNavBar = (isDefaultDisplay && mHasNavigationBar
Daniel Sandler36412a72011-08-04 09:35:13 -04003535 && mNavigationBar != null && mNavigationBar.isVisibleLw());
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003536
Craig Mautnerf683b562012-10-02 11:10:57 -07003537 final int adjust = sim & SOFT_INPUT_MASK_ADJUST;
3538
Adrian Roosfa104232014-06-20 16:10:14 -07003539 if (isDefaultDisplay) {
3540 sf.set(mStableLeft, mStableTop, mStableRight, mStableBottom);
3541 } else {
3542 sf.set(mOverscanLeft, mOverscanTop, mOverscanRight, mOverscanBottom);
3543 }
3544
Craig Mautner69b08182012-09-05 13:07:13 -07003545 if (!isDefaultDisplay) {
3546 if (attached != null) {
3547 // If this window is attached to another, our display
3548 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003549 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07003550 } else {
3551 // Give the window full screen.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003552 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3553 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3554 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08003555 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003556 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003557 = mOverscanScreenTop + mOverscanScreenHeight;
Craig Mautner69b08182012-09-05 13:07:13 -07003558 }
Dianne Hackbornae6688b2015-02-11 17:02:41 -08003559 } else if (attrs.type == TYPE_INPUT_METHOD || attrs.type == TYPE_VOICE_INTERACTION) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003560 pf.left = df.left = of.left = cf.left = vf.left = mDockLeft;
3561 pf.top = df.top = of.top = cf.top = vf.top = mDockTop;
3562 pf.right = df.right = of.right = cf.right = vf.right = mDockRight;
John Spurlockc68d5772013-10-08 11:47:58 -04003563 // IM dock windows layout below the nav bar...
John Spurlock57beb3b2013-10-10 10:27:44 -04003564 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlockc68d5772013-10-08 11:47:58 -04003565 // ...with content insets above the nav bar
3566 cf.bottom = vf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003567 // IM dock windows always go to the bottom of the screen.
3568 attrs.gravity = Gravity.BOTTOM;
3569 mDockLayer = win.getSurfaceLayer();
Jorim Jaggie0700182014-08-21 01:12:37 +02003570 } else if (win == mStatusBar && (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
3571 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3572 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3573 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
3574 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight + mUnrestrictedScreenTop;
3575 cf.left = vf.left = mStableLeft;
3576 cf.top = vf.top = mStableTop;
3577 cf.right = vf.right = mStableRight;
3578 vf.bottom = mStableBottom;
3579 cf.bottom = mContentBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003580 } else {
John Spurlock46646232013-09-30 22:32:42 -04003581
3582 // Default policy decor for the default display
3583 dcf.left = mSystemLeft;
3584 dcf.top = mSystemTop;
3585 dcf.right = mSystemRight;
3586 dcf.bottom = mSystemBottom;
John Spurlockbd957402013-10-03 11:38:39 -04003587 final boolean inheritTranslucentDecor = (attrs.privateFlags
3588 & WindowManager.LayoutParams.PRIVATE_FLAG_INHERIT_TRANSLUCENT_DECOR) != 0;
John Spurlock65567d42013-10-08 10:08:32 -04003589 final boolean isAppWindow =
3590 attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW &&
3591 attrs.type <= WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
3592 final boolean topAtRest =
3593 win == mTopFullscreenOpaqueWindowState && !win.isAnimatingLw();
3594 if (isAppWindow && !inheritTranslucentDecor && !topAtRest) {
John Spurlockbd957402013-10-03 11:38:39 -04003595 if ((sysUiFl & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0
3596 && (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0
Adrian Roosea562512014-05-05 13:33:03 +02003597 && (fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) == 0
3598 && (fl & WindowManager.LayoutParams.
3599 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04003600 // Ensure policy decor includes status bar
3601 dcf.top = mStableTop;
3602 }
John Spurlockbd957402013-10-03 11:38:39 -04003603 if ((fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) == 0
Adrian Roosea562512014-05-05 13:33:03 +02003604 && (sysUiFl & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0
3605 && (fl & WindowManager.LayoutParams.
3606 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04003607 // Ensure policy decor includes navigation bar
3608 dcf.bottom = mStableBottom;
3609 dcf.right = mStableRight;
3610 }
3611 }
3612
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003613 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
3614 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
RoboErik8a2cfc32014-05-16 11:19:38 -07003615 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003616 + "): IN_SCREEN, INSET_DECOR");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003617 // This is the case for a normal activity window: we want it
3618 // to cover all of the screen space, and it can take care of
3619 // moving its contents to account for screen decorations that
3620 // intrude into that space.
3621 if (attached != null) {
3622 // If this window is attached to another, our display
3623 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003624 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003625 } else {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003626 if (attrs.type == TYPE_STATUS_BAR_PANEL
3627 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Joe Onorato29fc2c92010-11-24 10:26:50 -08003628 // Status bar panels are the only windows who can go on top of
3629 // the status bar. They are protected by the STATUS_BAR_SERVICE
3630 // permission, so they have the same privileges as the status
3631 // bar itself.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003632 //
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003633 // However, they should still dodge the navigation bar if it exists.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003634
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003635 pf.left = df.left = of.left = hasNavBar
3636 ? mDockLeft : mUnrestrictedScreenLeft;
3637 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3638 pf.right = df.right = of.right = hasNavBar
3639 ? mRestrictedScreenLeft+mRestrictedScreenWidth
3640 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3641 pf.bottom = df.bottom = of.bottom = hasNavBar
3642 ? mRestrictedScreenTop+mRestrictedScreenHeight
3643 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003644
Craig Mautnereda67292013-04-28 13:50:14 -07003645 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003646 "Laying out status bar window: (%d,%d - %d,%d)",
3647 pf.left, pf.top, pf.right, pf.bottom));
John Spurlock46646232013-09-30 22:32:42 -04003648 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08003649 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3650 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3651 // Asking to layout into the overscan region, so give it that pure
3652 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003653 pf.left = df.left = of.left = mOverscanScreenLeft;
3654 pf.top = df.top = of.top = mOverscanScreenTop;
3655 pf.right = df.right = of.right = mOverscanScreenLeft + mOverscanScreenWidth;
3656 pf.bottom = df.bottom = of.bottom = mOverscanScreenTop
3657 + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003658 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003659 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003660 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3661 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003662 // Asking for layout as if the nav bar is hidden, lets the
Dianne Hackbornc652de82013-02-15 16:32:56 -08003663 // application extend into the unrestricted overscan screen area. We
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003664 // only do this for application windows to ensure no window that
3665 // can be above the nav bar can do this.
Dianne Hackborn313440842013-02-19 19:22:59 -08003666 pf.left = df.left = mOverscanScreenLeft;
3667 pf.top = df.top = mOverscanScreenTop;
3668 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
3669 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003670 // We need to tell the app about where the frame inside the overscan
3671 // is, so it can inset its content by that amount -- it didn't ask
3672 // to actually extend itself into the overscan region.
3673 of.left = mUnrestrictedScreenLeft;
3674 of.top = mUnrestrictedScreenTop;
3675 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3676 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003677 } else {
Dianne Hackborn313440842013-02-19 19:22:59 -08003678 pf.left = df.left = mRestrictedOverscanScreenLeft;
3679 pf.top = df.top = mRestrictedOverscanScreenTop;
3680 pf.right = df.right = mRestrictedOverscanScreenLeft
3681 + mRestrictedOverscanScreenWidth;
3682 pf.bottom = df.bottom = mRestrictedOverscanScreenTop
3683 + mRestrictedOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003684 // We need to tell the app about where the frame inside the overscan
3685 // is, so it can inset its content by that amount -- it didn't ask
3686 // to actually extend itself into the overscan region.
3687 of.left = mUnrestrictedScreenLeft;
3688 of.top = mUnrestrictedScreenTop;
3689 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3690 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003691 }
Craig Mautner69b08182012-09-05 13:07:13 -07003692
John Spurlock46646232013-09-30 22:32:42 -04003693 if ((fl & FLAG_FULLSCREEN) == 0) {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003694 if (win.isVoiceInteraction()) {
3695 cf.left = mVoiceContentLeft;
3696 cf.top = mVoiceContentTop;
3697 cf.right = mVoiceContentRight;
3698 cf.bottom = mVoiceContentBottom;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003699 } else {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003700 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
3701 cf.left = mDockLeft;
3702 cf.top = mDockTop;
3703 cf.right = mDockRight;
3704 cf.bottom = mDockBottom;
3705 } else {
3706 cf.left = mContentLeft;
3707 cf.top = mContentTop;
3708 cf.right = mContentRight;
3709 cf.bottom = mContentBottom;
3710 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003711 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003712 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003713 // Full screen windows are always given a layout that is as if the
3714 // status bar and other transient decors are gone. This is to avoid
3715 // bad states when moving from a window that is not hding the
3716 // status bar to one that is.
3717 cf.left = mRestrictedScreenLeft;
3718 cf.top = mRestrictedScreenTop;
3719 cf.right = mRestrictedScreenLeft + mRestrictedScreenWidth;
3720 cf.bottom = mRestrictedScreenTop + mRestrictedScreenHeight;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003721 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003722 applyStableConstraints(sysUiFl, fl, cf);
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003723 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3724 vf.left = mCurLeft;
3725 vf.top = mCurTop;
3726 vf.right = mCurRight;
3727 vf.bottom = mCurBottom;
3728 } else {
3729 vf.set(cf);
3730 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003731 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003732 } else if ((fl & FLAG_LAYOUT_IN_SCREEN) != 0 || (sysUiFl
3733 & (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
3734 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)) != 0) {
Craig Mautnereda67292013-04-28 13:50:14 -07003735 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3736 "): IN_SCREEN");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003737 // A window that has requested to fill the entire screen just
3738 // gets everything, period.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003739 if (attrs.type == TYPE_STATUS_BAR_PANEL
3740 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003741 pf.left = df.left = of.left = cf.left = hasNavBar
3742 ? mDockLeft : mUnrestrictedScreenLeft;
3743 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
3744 pf.right = df.right = of.right = cf.right = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003745 ? mRestrictedScreenLeft+mRestrictedScreenWidth
Dianne Hackbornc652de82013-02-15 16:32:56 -08003746 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003747 pf.bottom = df.bottom = of.bottom = cf.bottom = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003748 ? mRestrictedScreenTop+mRestrictedScreenHeight
Dianne Hackbornc652de82013-02-15 16:32:56 -08003749 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07003750 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler36412a72011-08-04 09:35:13 -04003751 "Laying out IN_SCREEN status bar window: (%d,%d - %d,%d)",
3752 pf.left, pf.top, pf.right, pf.bottom));
Jim Millere898ac52012-04-06 17:10:57 -07003753 } else if (attrs.type == TYPE_NAVIGATION_BAR
3754 || attrs.type == TYPE_NAVIGATION_BAR_PANEL) {
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003755 // The navigation bar has Real Ultimate Power.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003756 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3757 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3758 pf.right = df.right = of.right = mUnrestrictedScreenLeft
3759 + mUnrestrictedScreenWidth;
3760 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop
3761 + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07003762 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003763 "Laying out navigation bar window: (%d,%d - %d,%d)",
3764 pf.left, pf.top, pf.right, pf.bottom));
Dianne Hackborn01011c32012-02-21 13:54:21 -08003765 } else if ((attrs.type == TYPE_SECURE_SYSTEM_OVERLAY
3766 || attrs.type == TYPE_BOOT_PROGRESS)
Jeff Brownbfcb60a2011-09-08 18:51:14 -07003767 && ((fl & FLAG_FULLSCREEN) != 0)) {
3768 // Fullscreen secure system overlays get what they ask for.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003769 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3770 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3771 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
3772 + mOverscanScreenWidth;
3773 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
3774 + mOverscanScreenHeight;
Craig Mautner165be0c2015-01-27 15:16:58 -08003775 } else if (attrs.type == TYPE_BOOT_PROGRESS) {
Dianne Hackborn01011c32012-02-21 13:54:21 -08003776 // Boot progress screen always covers entire display.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003777 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3778 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3779 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
3780 + mOverscanScreenWidth;
3781 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
3782 + mOverscanScreenHeight;
John Spurlockef4adae2013-08-26 17:58:58 -04003783 } else if (attrs.type == TYPE_WALLPAPER) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07003784 // The wallpaper also has Real Ultimate Power, but we want to tell
3785 // it about the overscan area.
3786 pf.left = df.left = mOverscanScreenLeft;
3787 pf.top = df.top = mOverscanScreenTop;
3788 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
3789 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
3790 of.left = cf.left = mUnrestrictedScreenLeft;
3791 of.top = cf.top = mUnrestrictedScreenTop;
3792 of.right = cf.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3793 of.bottom = cf.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlock46646232013-09-30 22:32:42 -04003794 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08003795 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3796 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3797 // Asking to layout into the overscan region, so give it that pure
3798 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003799 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3800 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3801 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08003802 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003803 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003804 = mOverscanScreenTop + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003805 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003806 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Craig Mautnerbeac1062014-06-03 14:38:57 -07003807 && (attrs.type == TYPE_STATUS_BAR
3808 || attrs.type == TYPE_TOAST
John Spurlock34e13d92013-08-10 06:52:28 -04003809 || (attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3810 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW))) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003811 // Asking for layout as if the nav bar is hidden, lets the
3812 // application extend into the unrestricted screen area. We
John Spurlock34e13d92013-08-10 06:52:28 -04003813 // only do this for application windows (or toasts) to ensure no window that
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003814 // can be above the nav bar can do this.
3815 // XXX This assumes that an app asking for this will also
3816 // ask for layout in only content. We can't currently figure out
3817 // what the screen would be if only laying out to hide the nav bar.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003818 pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft;
3819 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
3820 pf.right = df.right = of.right = cf.right = mUnrestrictedScreenLeft
3821 + mUnrestrictedScreenWidth;
3822 pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop
3823 + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003824 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003825 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
3826 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
3827 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
3828 + mRestrictedScreenWidth;
3829 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
3830 + mRestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003831 }
Craig Mautner69b08182012-09-05 13:07:13 -07003832
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003833 applyStableConstraints(sysUiFl, fl, cf);
Craig Mautner69b08182012-09-05 13:07:13 -07003834
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003835 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3836 vf.left = mCurLeft;
3837 vf.top = mCurTop;
3838 vf.right = mCurRight;
3839 vf.bottom = mCurBottom;
3840 } else {
3841 vf.set(cf);
3842 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003843 } else if (attached != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07003844 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3845 "): attached to " + attached);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003846 // A child window should be placed inside of the same visible
3847 // frame that its parent had.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003848 setAttachedWindowFrames(win, fl, adjust, attached, false, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003849 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07003850 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3851 "): normal window");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003852 // Otherwise, a normal window must be placed inside the content
3853 // of all screen decorations.
Dianne Hackborna239c842011-06-01 12:28:20 -07003854 if (attrs.type == TYPE_STATUS_BAR_PANEL) {
3855 // Status bar panels are the only windows who can go on top of
3856 // the status bar. They are protected by the STATUS_BAR_SERVICE
3857 // permission, so they have the same privileges as the status
3858 // bar itself.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003859 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
3860 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
3861 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
3862 + mRestrictedScreenWidth;
3863 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
3864 + mRestrictedScreenHeight;
John Spurlock414c1f02013-12-04 13:47:36 -05003865 } else if (attrs.type == TYPE_TOAST || attrs.type == TYPE_SYSTEM_ALERT
3866 || attrs.type == TYPE_VOLUME_OVERLAY) {
3867 // These dialogs are stable to interim decor changes.
John Spurlockbd957402013-10-03 11:38:39 -04003868 pf.left = df.left = of.left = cf.left = mStableLeft;
3869 pf.top = df.top = of.top = cf.top = mStableTop;
3870 pf.right = df.right = of.right = cf.right = mStableRight;
3871 pf.bottom = df.bottom = of.bottom = cf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003872 } else {
Dianne Hackborna239c842011-06-01 12:28:20 -07003873 pf.left = mContentLeft;
3874 pf.top = mContentTop;
3875 pf.right = mContentRight;
3876 pf.bottom = mContentBottom;
Dianne Hackborn20d94742014-05-29 18:35:45 -07003877 if (win.isVoiceInteraction()) {
3878 df.left = of.left = cf.left = mVoiceContentLeft;
3879 df.top = of.top = cf.top = mVoiceContentTop;
3880 df.right = of.right = cf.right = mVoiceContentRight;
3881 df.bottom = of.bottom = cf.bottom = mVoiceContentBottom;
3882 } else if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003883 df.left = of.left = cf.left = mDockLeft;
3884 df.top = of.top = cf.top = mDockTop;
3885 df.right = of.right = cf.right = mDockRight;
3886 df.bottom = of.bottom = cf.bottom = mDockBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07003887 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003888 df.left = of.left = cf.left = mContentLeft;
3889 df.top = of.top = cf.top = mContentTop;
3890 df.right = of.right = cf.right = mContentRight;
3891 df.bottom = of.bottom = cf.bottom = mContentBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07003892 }
3893 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3894 vf.left = mCurLeft;
3895 vf.top = mCurTop;
3896 vf.right = mCurRight;
3897 vf.bottom = mCurBottom;
3898 } else {
3899 vf.set(cf);
3900 }
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003901 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003902 }
3903 }
Craig Mautner69b08182012-09-05 13:07:13 -07003904
Craig Mautnerb816bed2013-07-23 10:26:17 -07003905 // TYPE_SYSTEM_ERROR is above the NavigationBar so it can't be allowed to extend over it.
3906 if ((fl & FLAG_LAYOUT_NO_LIMITS) != 0 && attrs.type != TYPE_SYSTEM_ERROR) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07003907 df.left = df.top = -10000;
3908 df.right = df.bottom = 10000;
3909 if (attrs.type != TYPE_WALLPAPER) {
3910 of.left = of.top = cf.left = cf.top = vf.left = vf.top = -10000;
3911 of.right = of.bottom = cf.right = cf.bottom = vf.right = vf.bottom = 10000;
3912 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003913 }
3914
Craig Mautnereda67292013-04-28 13:50:14 -07003915 if (DEBUG_LAYOUT) Slog.v(TAG, "Compute frame " + attrs.getTitle()
The Android Open Source Project11267662009-03-18 17:39:47 -07003916 + ": sim=#" + Integer.toHexString(sim)
RoboErik8a2cfc32014-05-16 11:19:38 -07003917 + " attach=" + attached + " type=" + attrs.type
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003918 + String.format(" flags=0x%08x", fl)
The Android Open Source Project11267662009-03-18 17:39:47 -07003919 + " pf=" + pf.toShortString() + " df=" + df.toShortString()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003920 + " of=" + of.toShortString()
John Spurlock46646232013-09-30 22:32:42 -04003921 + " cf=" + cf.toShortString() + " vf=" + vf.toShortString()
Adrian Roosfa104232014-06-20 16:10:14 -07003922 + " dcf=" + dcf.toShortString()
3923 + " sf=" + sf.toShortString());
Craig Mautner69b08182012-09-05 13:07:13 -07003924
Adrian Roosfa104232014-06-20 16:10:14 -07003925 win.computeFrameLw(pf, df, of, cf, vf, dcf, sf);
Craig Mautner69b08182012-09-05 13:07:13 -07003926
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003927 // Dock windows carve out the bottom of the screen, so normal windows
3928 // can't appear underneath them.
Craig Mautner8bd206b2012-10-03 10:32:02 -07003929 if (attrs.type == TYPE_INPUT_METHOD && win.isVisibleOrBehindKeyguardLw()
3930 && !win.getGivenInsetsPendingLw()) {
satok1bc0a492012-04-25 22:47:12 +09003931 setLastInputMethodWindowLw(null, null);
3932 offsetInputMethodWindowLw(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003933 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003934 if (attrs.type == TYPE_VOICE_INTERACTION && win.isVisibleOrBehindKeyguardLw()
3935 && !win.getGivenInsetsPendingLw()) {
3936 offsetVoiceInputWindowLw(win);
3937 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003938 }
3939
satok1bc0a492012-04-25 22:47:12 +09003940 private void offsetInputMethodWindowLw(WindowState win) {
Dianne Hackbornae6688b2015-02-11 17:02:41 -08003941 int top = win.getDisplayFrameLw().top;
satok1bc0a492012-04-25 22:47:12 +09003942 top += win.getGivenContentInsetsLw().top;
3943 if (mContentBottom > top) {
3944 mContentBottom = top;
3945 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003946 if (mVoiceContentBottom > top) {
3947 mVoiceContentBottom = top;
3948 }
satok1bc0a492012-04-25 22:47:12 +09003949 top = win.getVisibleFrameLw().top;
3950 top += win.getGivenVisibleInsetsLw().top;
3951 if (mCurBottom > top) {
3952 mCurBottom = top;
3953 }
Craig Mautnereda67292013-04-28 13:50:14 -07003954 if (DEBUG_LAYOUT) Slog.v(TAG, "Input method: mDockBottom="
satok1bc0a492012-04-25 22:47:12 +09003955 + mDockBottom + " mContentBottom="
3956 + mContentBottom + " mCurBottom=" + mCurBottom);
3957 }
3958
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003959 private void offsetVoiceInputWindowLw(WindowState win) {
Dianne Hackbornae6688b2015-02-11 17:02:41 -08003960 int top = win.getDisplayFrameLw().top;
3961 top += win.getGivenContentInsetsLw().top;
3962 if (mVoiceContentBottom > top) {
3963 mVoiceContentBottom = top;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003964 }
3965 }
3966
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003967 /** {@inheritDoc} */
Craig Mautner61ac6bb2012-02-02 17:29:33 -08003968 @Override
3969 public void finishLayoutLw() {
3970 return;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003971 }
3972
3973 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003974 @Override
Craig Mautner39834192012-09-02 07:47:24 -07003975 public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) {
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003976 mTopFullscreenOpaqueWindowState = null;
Adrian Rooscd3884d2015-02-18 17:25:23 +01003977 mTopFullscreenOpaqueOrDimmingWindowState = null;
Craig Mautner2bc789b2014-03-19 19:48:38 -07003978 mAppsToBeHidden.clear();
Jorim Jaggic13fcac2014-09-11 17:36:57 +02003979 mAppsThatDismissKeyguard.clear();
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003980 mForceStatusBar = false;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003981 mForceStatusBarFromKeyguard = false;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08003982 mForcingShowNavBar = false;
3983 mForcingShowNavBarLayer = -1;
RoboErik8a2cfc32014-05-16 11:19:38 -07003984
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003985 mHideLockScreen = false;
3986 mAllowLockscreenWhenOn = false;
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003987 mDismissKeyguard = DISMISS_KEYGUARD_NONE;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003988 mShowingLockscreen = false;
3989 mShowingDream = false;
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003990 mWinShowWhenLocked = null;
Jim Millerab954542014-10-10 18:21:49 -07003991 mKeyguardSecure = isKeyguardSecure();
3992 mKeyguardSecureIncludingHidden = mKeyguardSecure
3993 && (mKeyguardDelegate != null && mKeyguardDelegate.isShowing());
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003994 }
3995
3996 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003997 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003998 public void applyPostLayoutPolicyLw(WindowState win, WindowManager.LayoutParams attrs) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07003999 if (DEBUG_LAYOUT) Slog.i(TAG, "Win " + win + ": isVisibleOrBehindKeyguardLw="
4000 + win.isVisibleOrBehindKeyguardLw());
John Spurlockc6d1c602014-01-17 15:22:06 -05004001 final int fl = PolicyControl.getWindowFlags(win, attrs);
John Spurlock414c1f02013-12-04 13:47:36 -05004002 if (mTopFullscreenOpaqueWindowState == null
4003 && win.isVisibleLw() && attrs.type == TYPE_INPUT_METHOD) {
4004 mForcingShowNavBar = true;
4005 mForcingShowNavBarLayer = win.getSurfaceLayer();
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08004006 }
Jorim Jaggiafd4a552014-04-08 15:13:05 +02004007 if (attrs.type == TYPE_STATUS_BAR && (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Jorim Jaggiafd4a552014-04-08 15:13:05 +02004008 mForceStatusBarFromKeyguard = true;
4009 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004010 if (mTopFullscreenOpaqueWindowState == null &&
Dianne Hackborn01b02a72012-01-12 14:05:03 -08004011 win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()) {
John Spurlockc6d1c602014-01-17 15:22:06 -05004012 if ((fl & FLAG_FORCE_NOT_FULLSCREEN) != 0) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004013 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004014 mForceStatusBarFromKeyguard = true;
4015 } else {
4016 mForceStatusBar = true;
4017 }
4018 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004019 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004020 mShowingLockscreen = true;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004021 }
Craig Mautnerab55e522014-03-03 13:26:03 -08004022 boolean appWindow = attrs.type >= FIRST_APPLICATION_WINDOW
Craig Mautner7d7808f2014-09-11 18:02:38 -07004023 && attrs.type < FIRST_SYSTEM_WINDOW;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004024 if (attrs.type == TYPE_DREAM) {
Jeff Brownc8018eb2012-10-29 21:33:27 -07004025 // If the lockscreen was showing when the dream started then wait
4026 // for the dream to draw before hiding the lockscreen.
4027 if (!mDreamingLockscreen
4028 || (win.isVisibleLw() && win.hasDrawnLw())) {
4029 mShowingDream = true;
Craig Mautnerab55e522014-03-03 13:26:03 -08004030 appWindow = true;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004031 }
4032 }
Craig Mautnerab55e522014-03-03 13:26:03 -08004033
Craig Mautner00156ec2014-03-06 22:29:02 -08004034 final boolean showWhenLocked = (fl & FLAG_SHOW_WHEN_LOCKED) != 0;
Craig Mautner74ee9382014-04-01 15:20:16 -07004035 final boolean dismissKeyguard = (fl & FLAG_DISMISS_KEYGUARD) != 0;
Craig Mautnerab55e522014-03-03 13:26:03 -08004036 if (appWindow) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004037 final IApplicationToken appToken = win.getAppToken();
4038 if (showWhenLocked) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004039 // Remove any previous windows with the same appToken.
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004040 mAppsToBeHidden.remove(appToken);
4041 mAppsThatDismissKeyguard.remove(appToken);
Craig Mautnerca0a1242014-12-02 12:25:14 -08004042 if (mAppsToBeHidden.isEmpty()) {
Craig Mautner192d6042014-12-02 23:24:48 -08004043 if (dismissKeyguard && !mKeyguardSecure) {
4044 mAppsThatDismissKeyguard.add(appToken);
4045 } else {
Craig Mautnerca0a1242014-12-02 12:25:14 -08004046 mWinShowWhenLocked = win;
4047 mHideLockScreen = true;
4048 mForceStatusBarFromKeyguard = false;
Craig Mautnerca0a1242014-12-02 12:25:14 -08004049 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004050 }
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004051 } else if (dismissKeyguard) {
Jim Millerab954542014-10-10 18:21:49 -07004052 if (mKeyguardSecure) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004053 mAppsToBeHidden.add(appToken);
4054 } else {
4055 mAppsToBeHidden.remove(appToken);
4056 }
4057 mAppsThatDismissKeyguard.add(appToken);
Craig Mautner2bc789b2014-03-19 19:48:38 -07004058 } else {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004059 mAppsToBeHidden.add(appToken);
Craig Mautner2bc789b2014-03-19 19:48:38 -07004060 }
Craig Mautnerab55e522014-03-03 13:26:03 -08004061 if (attrs.x == 0 && attrs.y == 0
4062 && attrs.width == WindowManager.LayoutParams.MATCH_PARENT
4063 && attrs.height == WindowManager.LayoutParams.MATCH_PARENT) {
4064 if (DEBUG_LAYOUT) Slog.v(TAG, "Fullscreen window: " + win);
4065 mTopFullscreenOpaqueWindowState = win;
Adrian Rooscd3884d2015-02-18 17:25:23 +01004066 if (mTopFullscreenOpaqueOrDimmingWindowState == null) {
4067 mTopFullscreenOpaqueOrDimmingWindowState = win;
4068 }
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004069 if (!mAppsThatDismissKeyguard.isEmpty() &&
4070 mDismissKeyguard == DISMISS_KEYGUARD_NONE) {
4071 if (DEBUG_LAYOUT) Slog.v(TAG,
4072 "Setting mDismissKeyguard true by win " + win);
4073 mDismissKeyguard = mWinDismissingKeyguard == win ?
4074 DISMISS_KEYGUARD_CONTINUE : DISMISS_KEYGUARD_START;
4075 mWinDismissingKeyguard = win;
Jim Millerab954542014-10-10 18:21:49 -07004076 mForceStatusBarFromKeyguard = mShowingLockscreen && mKeyguardSecure;
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004077 } else if (mAppsToBeHidden.isEmpty() && showWhenLocked) {
4078 if (DEBUG_LAYOUT) Slog.v(TAG,
4079 "Setting mHideLockScreen to true by win " + win);
4080 mHideLockScreen = true;
4081 mForceStatusBarFromKeyguard = false;
Craig Mautnerab55e522014-03-03 13:26:03 -08004082 }
Craig Mautner00156ec2014-03-06 22:29:02 -08004083 if ((fl & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) {
Craig Mautnerab55e522014-03-03 13:26:03 -08004084 mAllowLockscreenWhenOn = true;
4085 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004086 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004087
4088 if (mWinShowWhenLocked != null &&
4089 mWinShowWhenLocked.getAppToken() != win.getAppToken()) {
4090 win.hideLw(false);
4091 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004092 }
4093 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01004094 if (mTopFullscreenOpaqueOrDimmingWindowState == null
4095 && win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()
4096 && win.isDimming()) {
4097 mTopFullscreenOpaqueOrDimmingWindowState = win;
4098 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004099 }
4100
4101 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004102 @Override
Craig Mautner39834192012-09-02 07:47:24 -07004103 public int finishPostLayoutPolicyLw() {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004104 if (mWinShowWhenLocked != null &&
4105 mWinShowWhenLocked != mTopFullscreenOpaqueWindowState) {
4106 // A dialog is dismissing the keyguard. Put the wallpaper behind it and hide the
4107 // fullscreen window.
4108 // TODO: Make sure FLAG_SHOW_WALLPAPER is restored when dialog is dismissed. Or not.
4109 mWinShowWhenLocked.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
4110 mTopFullscreenOpaqueWindowState.hideLw(false);
4111 mTopFullscreenOpaqueWindowState = mWinShowWhenLocked;
4112 }
4113
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004114 int changes = 0;
Joe Onorato93056472010-09-10 10:30:46 -04004115 boolean topIsFullscreen = false;
Daniel Sandlere02d8082010-10-08 15:13:22 -04004116
4117 final WindowManager.LayoutParams lp = (mTopFullscreenOpaqueWindowState != null)
4118 ? mTopFullscreenOpaqueWindowState.getAttrs()
4119 : null;
4120
Jeff Brownc8018eb2012-10-29 21:33:27 -07004121 // If we are not currently showing a dream then remember the current
4122 // lockscreen state. We will use this to determine whether the dream
4123 // started while the lockscreen was showing and remember this state
4124 // while the dream is showing.
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004125 if (!mShowingDream) {
4126 mDreamingLockscreen = mShowingLockscreen;
4127 }
4128
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004129 if (mStatusBar != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07004130 if (DEBUG_LAYOUT) Slog.i(TAG, "force=" + mForceStatusBar
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004131 + " forcefkg=" + mForceStatusBarFromKeyguard
Dianne Hackbornd70bc2f2009-10-06 23:25:51 -07004132 + " top=" + mTopFullscreenOpaqueWindowState);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004133 if (mForceStatusBar || mForceStatusBarFromKeyguard) {
Craig Mautnereda67292013-04-28 13:50:14 -07004134 if (DEBUG_LAYOUT) Slog.v(TAG, "Showing status bar: forced");
John Spurlock27735a42013-08-14 17:57:38 -04004135 if (mStatusBarController.setBarShowingLw(true)) {
4136 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4137 }
Craig Mautner81defc72013-10-29 11:10:42 -07004138 // Maintain fullscreen layout until incoming animation is complete.
4139 topIsFullscreen = mTopIsFullscreen && mStatusBar.isAnimatingLw();
John Spurlockf92b6162013-11-11 15:01:16 -05004140 // Transient status bar on the lockscreen is not allowed
4141 if (mForceStatusBarFromKeyguard && mStatusBarController.isTransientShowing()) {
4142 mStatusBarController.updateVisibilityLw(false /*transientAllowed*/,
4143 mLastSystemUiFlags, mLastSystemUiFlags);
4144 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004145 } else if (mTopFullscreenOpaqueWindowState != null) {
John Spurlockc6d1c602014-01-17 15:22:06 -05004146 final int fl = PolicyControl.getWindowFlags(null, lp);
Joe Onorato93056472010-09-10 10:30:46 -04004147 if (localLOGV) {
Craig Mautnereda67292013-04-28 13:50:14 -07004148 Slog.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw()
Joe Onorato93056472010-09-10 10:30:46 -04004149 + " shown frame: " + mTopFullscreenOpaqueWindowState.getShownFrameLw());
Craig Mautnereda67292013-04-28 13:50:14 -07004150 Slog.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs()
John Spurlockc6d1c602014-01-17 15:22:06 -05004151 + " lp.flags=0x" + Integer.toHexString(fl));
Joe Onorato93056472010-09-10 10:30:46 -04004152 }
John Spurlockc6d1c602014-01-17 15:22:06 -05004153 topIsFullscreen = (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004154 || (mLastSystemUiFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
Joe Onorato93056472010-09-10 10:30:46 -04004155 // The subtle difference between the window for mTopFullscreenOpaqueWindowState
Mark Dolinerd0646dc2014-08-27 16:04:02 -07004156 // and mTopIsFullscreen is that mTopIsFullscreen is set only if the window
Joe Onorato93056472010-09-10 10:30:46 -04004157 // has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the
4158 // case though.
John Spurlock27735a42013-08-14 17:57:38 -04004159 if (mStatusBarController.isTransientShowing()) {
4160 if (mStatusBarController.setBarShowingLw(true)) {
John Spurlock32beb2c2013-03-11 10:16:47 -04004161 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4162 }
4163 } else if (topIsFullscreen) {
Craig Mautnereda67292013-04-28 13:50:14 -07004164 if (DEBUG_LAYOUT) Slog.v(TAG, "** HIDING status bar");
John Spurlock27735a42013-08-14 17:57:38 -04004165 if (mStatusBarController.setBarShowingLw(false)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004166 changes |= FINISH_LAYOUT_REDO_LAYOUT;
Craig Mautnereda67292013-04-28 13:50:14 -07004167 } else {
Craig Mautnerc5a6e442013-06-05 17:22:35 -07004168 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar already hiding");
Daniel Sandler40427442010-07-16 11:44:52 -04004169 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004170 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07004171 if (DEBUG_LAYOUT) Slog.v(TAG, "** SHOWING status bar: top is not fullscreen");
John Spurlock27735a42013-08-14 17:57:38 -04004172 if (mStatusBarController.setBarShowingLw(true)) {
4173 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4174 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004175 }
4176 }
4177 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04004178
Craig Mautner81defc72013-10-29 11:10:42 -07004179 if (mTopIsFullscreen != topIsFullscreen) {
4180 if (!topIsFullscreen) {
4181 // Force another layout when status bar becomes fully shown.
4182 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4183 }
4184 mTopIsFullscreen = topIsFullscreen;
4185 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04004186
Craig Mautner39834192012-09-02 07:47:24 -07004187 // Hide the key guard if a visible window explicitly specifies that it wants to be
4188 // displayed when the screen is locked.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004189 if (mKeyguardDelegate != null && mStatusBar != null) {
4190 if (localLOGV) Slog.v(TAG, "finishPostLayoutPolicyLw: mHideKeyguard="
4191 + mHideLockScreen);
Jim Millerab954542014-10-10 18:21:49 -07004192 if (mDismissKeyguard != DISMISS_KEYGUARD_NONE && !mKeyguardSecure) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004193 mKeyguardHidden = true;
Jim Millerab954542014-10-10 18:21:49 -07004194 if (setKeyguardOccludedLw(true)) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004195 changes |= FINISH_LAYOUT_REDO_LAYOUT
4196 | FINISH_LAYOUT_REDO_CONFIG
4197 | FINISH_LAYOUT_REDO_WALLPAPER;
4198 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004199 if (mKeyguardDelegate.isShowing()) {
4200 mHandler.post(new Runnable() {
4201 @Override
4202 public void run() {
4203 mKeyguardDelegate.keyguardDone(false, false);
4204 }
4205 });
4206 }
4207 } else if (mHideLockScreen) {
4208 mKeyguardHidden = true;
Jim Millerab954542014-10-10 18:21:49 -07004209 if (setKeyguardOccludedLw(true)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004210 changes |= FINISH_LAYOUT_REDO_LAYOUT
4211 | FINISH_LAYOUT_REDO_CONFIG
4212 | FINISH_LAYOUT_REDO_WALLPAPER;
4213 }
4214 } else if (mDismissKeyguard != DISMISS_KEYGUARD_NONE) {
4215 // This is the case of keyguard isSecure() and not mHideLockScreen.
4216 if (mDismissKeyguard == DISMISS_KEYGUARD_START) {
4217 // Only launch the next keyguard unlock window once per window.
4218 mKeyguardHidden = false;
Jim Millerab954542014-10-10 18:21:49 -07004219 if (setKeyguardOccludedLw(false)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004220 changes |= FINISH_LAYOUT_REDO_LAYOUT
4221 | FINISH_LAYOUT_REDO_CONFIG
4222 | FINISH_LAYOUT_REDO_WALLPAPER;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004223 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004224 mHandler.post(new Runnable() {
4225 @Override
4226 public void run() {
4227 mKeyguardDelegate.dismiss();
4228 }
4229 });
4230 }
4231 } else {
4232 mWinDismissingKeyguard = null;
4233 mKeyguardHidden = false;
Jim Millerab954542014-10-10 18:21:49 -07004234 if (setKeyguardOccludedLw(false)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004235 changes |= FINISH_LAYOUT_REDO_LAYOUT
4236 | FINISH_LAYOUT_REDO_CONFIG
4237 | FINISH_LAYOUT_REDO_WALLPAPER;
4238 }
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -07004239 }
4240 }
Joe Onorato664644d2011-01-23 17:53:23 -08004241
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004242 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004243 // If the navigation bar has been hidden or shown, we need to do another
4244 // layout pass to update that window.
4245 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4246 }
Joe Onorato664644d2011-01-23 17:53:23 -08004247
Mike Lockwood28569302010-01-28 11:54:40 -05004248 // update since mAllowLockscreenWhenOn might have changed
4249 updateLockScreenTimeout();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004250 return changes;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004251 }
4252
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004253 /**
Jim Millerab954542014-10-10 18:21:49 -07004254 * Updates the occluded state of the Keyguard.
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004255 *
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004256 * @return Whether the flags have changed and we have to redo the layout.
4257 */
Jim Millerab954542014-10-10 18:21:49 -07004258 private boolean setKeyguardOccludedLw(boolean isOccluded) {
4259 boolean wasOccluded = mKeyguardOccluded;
4260 boolean showing = mKeyguardDelegate.isShowing();
4261 if (wasOccluded && !isOccluded && showing) {
4262 mKeyguardOccluded = false;
4263 mKeyguardDelegate.setOccluded(false);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004264 mStatusBar.getAttrs().privateFlags |= PRIVATE_FLAG_KEYGUARD;
4265 mStatusBar.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
4266 return true;
Jim Millerab954542014-10-10 18:21:49 -07004267 } else if (!wasOccluded && isOccluded && showing) {
4268 mKeyguardOccluded = true;
4269 mKeyguardDelegate.setOccluded(true);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004270 mStatusBar.getAttrs().privateFlags &= ~PRIVATE_FLAG_KEYGUARD;
4271 mStatusBar.getAttrs().flags &= ~FLAG_SHOW_WALLPAPER;
4272 return true;
4273 } else {
4274 return false;
4275 }
4276 }
4277
4278 private boolean isStatusBarKeyguard() {
4279 return mStatusBar != null
4280 && (mStatusBar.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
4281 }
4282
Jose Lima9546b202014-07-02 17:21:51 -07004283 @Override
Dianne Hackborn08743722009-12-21 12:16:51 -08004284 public boolean allowAppAnimationsLw() {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004285 if (isStatusBarKeyguard() || mShowingDream) {
Craig Mautner28816302013-10-10 20:31:00 -07004286 // If keyguard or dreams is currently visible, no reason to animate behind it.
Dianne Hackborn08743722009-12-21 12:16:51 -08004287 return false;
4288 }
Dianne Hackborn08743722009-12-21 12:16:51 -08004289 return true;
4290 }
4291
Jose Lima9546b202014-07-02 17:21:51 -07004292 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07004293 public int focusChangedLw(WindowState lastFocus, WindowState newFocus) {
Joe Onorato664644d2011-01-23 17:53:23 -08004294 mFocusedWindow = newFocus;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004295 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004296 // If the navigation bar has been hidden or shown, we need to do another
4297 // layout pass to update that window.
4298 return FINISH_LAYOUT_REDO_LAYOUT;
4299 }
4300 return 0;
Joe Onorato664644d2011-01-23 17:53:23 -08004301 }
4302
Dianne Hackborn0ecadf72009-03-31 18:00:37 -07004303 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07004304 @Override
Jeff Brown46b9ac02010-04-22 18:58:52 -07004305 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
4306 // lid changed state
Jeff Brownc458ce92012-04-30 14:58:40 -07004307 final int newLidState = lidOpen ? LID_OPEN : LID_CLOSED;
4308 if (newLidState == mLidState) {
4309 return;
4310 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004311
Jeff Brownc458ce92012-04-30 14:58:40 -07004312 mLidState = newLidState;
4313 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07004314 updateRotation(true);
Jeff Brownc458ce92012-04-30 14:58:40 -07004315
4316 if (lidOpen) {
Bryce Lee584a4452014-10-21 15:55:55 -07004317 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromLidSwitch);
Jeff Brownc458ce92012-04-30 14:58:40 -07004318 } else if (!mLidControlsSleep) {
Jeff Brown96307042012-07-27 15:51:34 -07004319 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
Jeff Brown46b9ac02010-04-22 18:58:52 -07004320 }
4321 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004322
Michael Wright3818c922014-09-02 13:59:07 -07004323 @Override
4324 public void notifyCameraLensCoverSwitchChanged(long whenNanos, boolean lensCovered) {
4325 int lensCoverState = lensCovered ? CAMERA_LENS_COVERED : CAMERA_LENS_UNCOVERED;
4326 if (mCameraLensCoverState == lensCoverState) {
4327 return;
4328 }
4329 if (mCameraLensCoverState == CAMERA_LENS_COVERED &&
4330 lensCoverState == CAMERA_LENS_UNCOVERED) {
4331 Intent intent;
4332 final boolean keyguardActive = mKeyguardDelegate == null ? false :
4333 mKeyguardDelegate.isShowing();
4334 if (keyguardActive) {
4335 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE);
4336 } else {
4337 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
4338 }
Bryce Lee584a4452014-10-21 15:55:55 -07004339 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromCameraLens);
Michael Wright3818c922014-09-02 13:59:07 -07004340 mContext.startActivityAsUser(intent, UserHandle.CURRENT_OR_SELF);
4341 }
4342 mCameraLensCoverState = lensCoverState;
4343 }
4344
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004345 void setHdmiPlugged(boolean plugged) {
4346 if (mHdmiPlugged != plugged) {
4347 mHdmiPlugged = plugged;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004348 updateRotation(true, true);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004349 Intent intent = new Intent(ACTION_HDMI_PLUGGED);
Joe Onoratodc100302011-01-11 17:07:41 -08004350 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004351 intent.putExtra(EXTRA_HDMI_PLUGGED_STATE, plugged);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07004352 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004353 }
4354 }
4355
Joe Onoratoea495d42011-04-06 11:41:11 -07004356 void initializeHdmiState() {
Joe Onorato7ba631f2011-05-04 15:28:00 -07004357 boolean plugged = false;
Joe Onoratoea495d42011-04-06 11:41:11 -07004358 // watch for HDMI plug messages if the hdmi switch exists
4359 if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) {
4360 mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi");
4361
Joe Onoratoea495d42011-04-06 11:41:11 -07004362 final String filename = "/sys/class/switch/hdmi/state";
4363 FileReader reader = null;
4364 try {
4365 reader = new FileReader(filename);
4366 char[] buf = new char[15];
4367 int n = reader.read(buf);
4368 if (n > 1) {
4369 plugged = 0 != Integer.parseInt(new String(buf, 0, n-1));
4370 }
4371 } catch (IOException ex) {
4372 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
4373 } catch (NumberFormatException ex) {
4374 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
4375 } finally {
4376 if (reader != null) {
4377 try {
4378 reader.close();
4379 } catch (IOException ex) {
4380 }
Joe Onoratodc100302011-01-11 17:07:41 -08004381 }
4382 }
4383 }
Joe Onorato7ba631f2011-05-04 15:28:00 -07004384 // This dance forces the code in setHdmiPlugged to run.
4385 // Always do this so the sticky intent is stuck (to false) if there is no hdmi.
4386 mHdmiPlugged = !plugged;
4387 setHdmiPlugged(!mHdmiPlugged);
Joe Onoratodc100302011-01-11 17:07:41 -08004388 }
4389
Dianne Hackbornc0e3f242011-08-19 14:19:10 -07004390 final Object mScreenshotLock = new Object();
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004391 ServiceConnection mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004392
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004393 final Runnable mScreenshotTimeout = new Runnable() {
4394 @Override public void run() {
4395 synchronized (mScreenshotLock) {
4396 if (mScreenshotConnection != null) {
4397 mContext.unbindService(mScreenshotConnection);
4398 mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004399 }
Winson Chung9112ec32011-06-27 13:15:32 -07004400 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004401 }
4402 };
4403
4404 // Assume this is called from the Handler thread.
4405 private void takeScreenshot() {
4406 synchronized (mScreenshotLock) {
4407 if (mScreenshotConnection != null) {
4408 return;
4409 }
4410 ComponentName cn = new ComponentName("com.android.systemui",
4411 "com.android.systemui.screenshot.TakeScreenshotService");
4412 Intent intent = new Intent();
4413 intent.setComponent(cn);
4414 ServiceConnection conn = new ServiceConnection() {
4415 @Override
4416 public void onServiceConnected(ComponentName name, IBinder service) {
4417 synchronized (mScreenshotLock) {
4418 if (mScreenshotConnection != this) {
4419 return;
4420 }
4421 Messenger messenger = new Messenger(service);
4422 Message msg = Message.obtain(null, 1);
4423 final ServiceConnection myConn = this;
4424 Handler h = new Handler(mHandler.getLooper()) {
4425 @Override
4426 public void handleMessage(Message msg) {
4427 synchronized (mScreenshotLock) {
4428 if (mScreenshotConnection == myConn) {
4429 mContext.unbindService(mScreenshotConnection);
4430 mScreenshotConnection = null;
4431 mHandler.removeCallbacks(mScreenshotTimeout);
4432 }
4433 }
4434 }
4435 };
4436 msg.replyTo = new Messenger(h);
Winson Chunga63bb842011-10-17 10:26:28 -07004437 msg.arg1 = msg.arg2 = 0;
4438 if (mStatusBar != null && mStatusBar.isVisibleLw())
4439 msg.arg1 = 1;
4440 if (mNavigationBar != null && mNavigationBar.isVisibleLw())
4441 msg.arg2 = 1;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004442 try {
4443 messenger.send(msg);
4444 } catch (RemoteException e) {
4445 }
4446 }
4447 }
4448 @Override
4449 public void onServiceDisconnected(ComponentName name) {}
4450 };
Amith Yamasani27b89e62013-01-16 12:30:11 -08004451 if (mContext.bindServiceAsUser(
4452 intent, conn, Context.BIND_AUTO_CREATE, UserHandle.CURRENT)) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004453 mScreenshotConnection = conn;
4454 mHandler.postDelayed(mScreenshotTimeout, 10000);
4455 }
4456 }
Winson Chung9112ec32011-06-27 13:15:32 -07004457 }
4458
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004459 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004460 @Override
Jeff Brown037c33e2014-04-09 00:31:55 -07004461 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) {
Jeff Brown96307042012-07-27 15:51:34 -07004462 if (!mSystemBooted) {
4463 // If we have not yet booted, don't let key events do anything.
4464 return 0;
4465 }
4466
Jeff Brown037c33e2014-04-09 00:31:55 -07004467 final boolean interactive = (policyFlags & FLAG_INTERACTIVE) != 0;
Jeff Brown1f245102010-11-18 20:53:46 -08004468 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
4469 final boolean canceled = event.isCanceled();
4470 final int keyCode = event.getKeyCode();
Jeff Browne20c9e02010-10-11 14:20:19 -07004471
Jeff Brown3122e442010-10-11 23:32:49 -07004472 final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0;
Jeff Brown3122e442010-10-11 23:32:49 -07004473
Mike Lockwoodc72b15f2009-11-28 20:58:22 -05004474 // If screen is off then we treat the case where the keyguard is open but hidden
4475 // the same as if it were open and in front.
4476 // This will prevent any keys other than the power button from waking the screen
4477 // when the keyguard is hidden by another activity.
Jim Miller5ecd8112013-01-09 18:50:26 -08004478 final boolean keyguardActive = (mKeyguardDelegate == null ? false :
Jeff Brown037c33e2014-04-09 00:31:55 -07004479 (interactive ?
Jim Millerab954542014-10-10 18:21:49 -07004480 isKeyguardShowingAndNotOccluded() :
Jim Miller5ecd8112013-01-09 18:50:26 -08004481 mKeyguardDelegate.isShowing()));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004482
Jeff Brown40013652012-05-16 21:22:36 -07004483 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004484 Log.d(TAG, "interceptKeyTq keycode=" + keyCode
Jeff Brown037c33e2014-04-09 00:31:55 -07004485 + " interactive=" + interactive + " keyguardActive=" + keyguardActive
Jeff Brown26875502014-01-30 21:47:47 -08004486 + " policyFlags=" + Integer.toHexString(policyFlags));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004487 }
4488
Jeff Brown037c33e2014-04-09 00:31:55 -07004489 // Basic policy based on interactive state.
Jeff Brown4d396052010-10-29 21:50:21 -07004490 int result;
Michael Wright337d9d22014-04-22 15:03:48 -07004491 boolean isWakeKey = (policyFlags & WindowManagerPolicy.FLAG_WAKE) != 0
4492 || event.isWakeKey();
Michael Wrightfc01f042014-09-08 14:12:24 -07004493 if (interactive || (isInjected && !isWakeKey)) {
RoboErikde9ba392014-09-26 12:51:01 -07004494 // When the device is interactive or the key is injected pass the
4495 // key to the application.
Jeff Brown4d396052010-10-29 21:50:21 -07004496 result = ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07004497 isWakeKey = false;
Michael Wrightfc01f042014-09-08 14:12:24 -07004498 } else if (!interactive && shouldDispatchInputWhenNonInteractive()) {
4499 // If we're currently dozing with the screen on and the keyguard showing, pass the key
4500 // to the application but preserve its wake key status to make sure we still move
4501 // from dozing to fully interactive if we would normally go from off to fully
4502 // interactive.
4503 result = ACTION_PASS_TO_USER;
Jeff Brown4d396052010-10-29 21:50:21 -07004504 } else {
4505 // When the screen is off and the key is not injected, determine whether
4506 // to wake the device but don't pass the key to the application.
4507 result = 0;
Jeff Brown26875502014-01-30 21:47:47 -08004508 if (isWakeKey && (!down || !isWakeKeyWhenScreenOff(keyCode))) {
4509 isWakeKey = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004510 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004511 }
4512
Justin Kohd378ad72013-04-01 12:18:26 -07004513 // If the key would be handled globally, just return the result, don't worry about special
4514 // key processing.
Jeff Brown13f00f02014-10-31 14:45:50 -07004515 if (isValidGlobalKey(keyCode)
4516 && mGlobalKeyManager.shouldHandleGlobalKey(keyCode, event)) {
Michael Wright85b1af62014-06-04 14:51:58 -07004517 if (isWakeKey) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004518 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey);
Michael Wright85b1af62014-06-04 14:51:58 -07004519 }
Justin Kohd378ad72013-04-01 12:18:26 -07004520 return result;
4521 }
4522
Jeff Brownbae8e772014-06-12 19:59:45 -07004523 boolean useHapticFeedback = down
4524 && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0
4525 && event.getRepeatCount() == 0;
4526
Jeff Brown4d396052010-10-29 21:50:21 -07004527 // Handle special keys.
4528 switch (keyCode) {
4529 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jeff Brownb0418da2010-11-01 15:24:01 -07004530 case KeyEvent.KEYCODE_VOLUME_UP:
4531 case KeyEvent.KEYCODE_VOLUME_MUTE: {
RoboErik001c59c2015-01-26 15:53:51 -08004532 if (mUseTvRouting) {
4533 // On TVs volume keys never go to the foreground app
4534 result &= ~ACTION_PASS_TO_USER;
4535 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004536 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
4537 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004538 if (interactive && !mScreenshotChordVolumeDownKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004539 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004540 mScreenshotChordVolumeDownKeyTriggered = true;
4541 mScreenshotChordVolumeDownKeyTime = event.getDownTime();
4542 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004543 cancelPendingPowerKeyAction();
4544 interceptScreenshotChord();
4545 }
4546 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004547 mScreenshotChordVolumeDownKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004548 cancelPendingScreenshotChordAction();
4549 }
4550 } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
4551 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004552 if (interactive && !mScreenshotChordVolumeUpKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004553 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004554 mScreenshotChordVolumeUpKeyTriggered = true;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004555 cancelPendingPowerKeyAction();
4556 cancelPendingScreenshotChordAction();
4557 }
4558 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004559 mScreenshotChordVolumeUpKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004560 cancelPendingScreenshotChordAction();
4561 }
4562 }
Jeff Brown4d396052010-10-29 21:50:21 -07004563 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004564 TelecomManager telecomManager = getTelecommService();
4565 if (telecomManager != null) {
4566 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07004567 // If an incoming call is ringing, either VOLUME key means
4568 // "silence ringer". We handle these keys here, rather than
4569 // in the InCallScreen, to make sure we'll respond to them
4570 // even if the InCallScreen hasn't come to the foreground yet.
4571 // Look for the DOWN event here, to agree with the "fallback"
4572 // behavior in the InCallScreen.
4573 Log.i(TAG, "interceptKeyBeforeQueueing:"
4574 + " VOLUME key-down while ringing: Silence ringer!");
Jeff Brown4d396052010-10-29 21:50:21 -07004575
Santos Cordon6848f722014-05-21 15:22:12 -07004576 // Silence the ringer. (It's safe to call this
4577 // even if the ringer has already been silenced.)
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004578 telecomManager.silenceRinger();
Jeff Brown4d396052010-10-29 21:50:21 -07004579
Santos Cordon6848f722014-05-21 15:22:12 -07004580 // And *don't* pass this key thru to the current activity
4581 // (which is probably the InCallScreen.)
4582 result &= ~ACTION_PASS_TO_USER;
4583 break;
4584 }
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004585 if (telecomManager.isInCall()
Santos Cordon6848f722014-05-21 15:22:12 -07004586 && (result & ACTION_PASS_TO_USER) == 0) {
4587 // If we are in call but we decided not to pass the key to
RoboErik430fc482014-06-12 15:49:20 -07004588 // the application, just pass it to the session service.
4589
4590 MediaSessionLegacyHelper.getHelper(mContext)
RoboErik3c45c292014-07-08 16:47:31 -07004591 .sendVolumeKeyEvent(event, false);
Santos Cordon6848f722014-05-21 15:22:12 -07004592 break;
Jeff Brown4d396052010-10-29 21:50:21 -07004593 }
4594 }
4595
RoboErik430fc482014-06-12 15:49:20 -07004596 if ((result & ACTION_PASS_TO_USER) == 0) {
RoboErik001c59c2015-01-26 15:53:51 -08004597 if (mUseTvRouting) {
4598 dispatchDirectAudioEvent(event);
4599 } else {
4600 // If we aren't passing to the user and no one else
4601 // handled it send it to the session manager to
4602 // figure out.
4603 MediaSessionLegacyHelper.getHelper(mContext)
4604 .sendVolumeKeyEvent(event, true);
4605 }
Jeff Brown4d396052010-10-29 21:50:21 -07004606 break;
4607 }
4608 }
4609 break;
4610 }
4611
4612 case KeyEvent.KEYCODE_ENDCALL: {
4613 result &= ~ACTION_PASS_TO_USER;
4614 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004615 TelecomManager telecomManager = getTelecommService();
Jeff Brown4d396052010-10-29 21:50:21 -07004616 boolean hungUp = false;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004617 if (telecomManager != null) {
4618 hungUp = telecomManager.endCall();
Jeff Brown4d396052010-10-29 21:50:21 -07004619 }
Jeff Brown13f00f02014-10-31 14:45:50 -07004620 if (interactive && !hungUp) {
4621 mEndCallKeyHandled = false;
4622 mHandler.postDelayed(mEndCallLongPress,
4623 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
4624 } else {
4625 mEndCallKeyHandled = true;
4626 }
Jeff Brown4d396052010-10-29 21:50:21 -07004627 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004628 if (!mEndCallKeyHandled) {
4629 mHandler.removeCallbacks(mEndCallLongPress);
4630 if (!canceled) {
4631 if ((mEndcallBehavior
4632 & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) {
4633 if (goHome()) {
4634 break;
4635 }
Dianne Hackborn0041e972009-07-24 17:14:43 -07004636 }
Jeff Brown13f00f02014-10-31 14:45:50 -07004637 if ((mEndcallBehavior
4638 & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) {
4639 mPowerManager.goToSleep(event.getEventTime(),
4640 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
4641 isWakeKey = false;
4642 }
Jeff Brown4d396052010-10-29 21:50:21 -07004643 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004644 }
Jeff Brown4d396052010-10-29 21:50:21 -07004645 }
4646 break;
4647 }
4648
4649 case KeyEvent.KEYCODE_POWER: {
4650 result &= ~ACTION_PASS_TO_USER;
Jeff Brown13f00f02014-10-31 14:45:50 -07004651 isWakeKey = false; // wake-up will be handled separately
Jeff Brown4d396052010-10-29 21:50:21 -07004652 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004653 interceptPowerKeyDown(event, interactive);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004654 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004655 interceptPowerKeyUp(event, interactive, canceled);
Jeff Brown4d396052010-10-29 21:50:21 -07004656 }
4657 break;
4658 }
4659
Jeff Brown6212a492014-03-07 13:58:47 -08004660 case KeyEvent.KEYCODE_SLEEP: {
4661 result &= ~ACTION_PASS_TO_USER;
Jeff Brownbae8e772014-06-12 19:59:45 -07004662 if (!mPowerManager.isInteractive()) {
4663 useHapticFeedback = false; // suppress feedback if already non-interactive
4664 }
Jeff Brownc12035c2014-08-13 18:52:25 -07004665 mPowerManager.goToSleep(event.getEventTime(),
4666 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
Jeff Brown6212a492014-03-07 13:58:47 -08004667 isWakeKey = false;
4668 break;
4669 }
4670
4671 case KeyEvent.KEYCODE_WAKEUP: {
4672 result &= ~ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07004673 isWakeKey = true;
Jeff Brown6212a492014-03-07 13:58:47 -08004674 break;
4675 }
4676
Jeff Brown4d396052010-10-29 21:50:21 -07004677 case KeyEvent.KEYCODE_MEDIA_PLAY:
4678 case KeyEvent.KEYCODE_MEDIA_PAUSE:
4679 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
Jeff Brown4d396052010-10-29 21:50:21 -07004680 case KeyEvent.KEYCODE_HEADSETHOOK:
4681 case KeyEvent.KEYCODE_MUTE:
4682 case KeyEvent.KEYCODE_MEDIA_STOP:
4683 case KeyEvent.KEYCODE_MEDIA_NEXT:
4684 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
4685 case KeyEvent.KEYCODE_MEDIA_REWIND:
4686 case KeyEvent.KEYCODE_MEDIA_RECORD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09004687 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
4688 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: {
RoboErikde9ba392014-09-26 12:51:01 -07004689 if (MediaSessionLegacyHelper.getHelper(mContext).isGlobalPriorityActive()) {
4690 // If the global session is active pass all media keys to it
4691 // instead of the active window.
4692 result &= ~ACTION_PASS_TO_USER;
4693 }
Jeff Brown4d396052010-10-29 21:50:21 -07004694 if ((result & ACTION_PASS_TO_USER) == 0) {
4695 // Only do this if we would otherwise not pass it to the user. In that
4696 // case, the PhoneWindow class will do the same thing, except it will
4697 // only do it if the showing app doesn't process the key on its own.
Jeff Brown40013652012-05-16 21:22:36 -07004698 // Note that we need to make a copy of the key event here because the
4699 // original key event will be recycled when we return.
Jeff Brown4d396052010-10-29 21:50:21 -07004700 mBroadcastWakeLock.acquire();
Jeff Brown40013652012-05-16 21:22:36 -07004701 Message msg = mHandler.obtainMessage(MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK,
4702 new KeyEvent(event));
4703 msg.setAsynchronous(true);
4704 msg.sendToTarget();
Jeff Brown4d396052010-10-29 21:50:21 -07004705 }
4706 break;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004707 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004708
Jeff Brown4d396052010-10-29 21:50:21 -07004709 case KeyEvent.KEYCODE_CALL: {
4710 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004711 TelecomManager telecomManager = getTelecommService();
4712 if (telecomManager != null) {
4713 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07004714 Log.i(TAG, "interceptKeyBeforeQueueing:"
4715 + " CALL key-down while ringing: Answer the call!");
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004716 telecomManager.acceptRingingCall();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004717
Santos Cordon6848f722014-05-21 15:22:12 -07004718 // And *don't* pass this key thru to the current activity
4719 // (which is presumably the InCallScreen.)
4720 result &= ~ACTION_PASS_TO_USER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004721 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004722 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004723 }
Jeff Brown4d396052010-10-29 21:50:21 -07004724 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004725 }
Michael Wright869a67c2014-08-26 19:33:06 -07004726 case KeyEvent.KEYCODE_VOICE_ASSIST: {
4727 // Only do this if we would otherwise not pass it to the user. In that case,
4728 // interceptKeyBeforeDispatching would apply a similar but different policy in
4729 // order to invoke voice assist actions. Note that we need to make a copy of the
4730 // key event here because the original key event will be recycled when we return.
4731 if ((result & ACTION_PASS_TO_USER) == 0 && !down) {
4732 mBroadcastWakeLock.acquire();
4733 Message msg = mHandler.obtainMessage(MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK,
4734 keyguardActive ? 1 : 0, 0);
4735 msg.setAsynchronous(true);
4736 msg.sendToTarget();
4737 }
4738 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004739 }
Jeff Brown26875502014-01-30 21:47:47 -08004740
Jeff Brownbae8e772014-06-12 19:59:45 -07004741 if (useHapticFeedback) {
4742 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
4743 }
4744
Jeff Brown26875502014-01-30 21:47:47 -08004745 if (isWakeKey) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004746 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey);
Jeff Brown26875502014-01-30 21:47:47 -08004747 }
Bryce Lee584a4452014-10-21 15:55:55 -07004748
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004749 return result;
4750 }
4751
Jeff Brown1c2e4942012-11-06 16:32:01 -08004752 /**
Jeff Brown13f00f02014-10-31 14:45:50 -07004753 * Returns true if the key can have global actions attached to it.
4754 * We reserve all power management keys for the system since they require
4755 * very careful handling.
4756 */
4757 private static boolean isValidGlobalKey(int keyCode) {
4758 switch (keyCode) {
4759 case KeyEvent.KEYCODE_POWER:
4760 case KeyEvent.KEYCODE_WAKEUP:
4761 case KeyEvent.KEYCODE_SLEEP:
4762 return false;
4763 default:
4764 return true;
4765 }
4766 }
4767
4768 /**
Jeff Brown1c2e4942012-11-06 16:32:01 -08004769 * When the screen is off we ignore some keys that might otherwise typically
4770 * be considered wake keys. We filter them out here.
4771 *
4772 * {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it
4773 * is always considered a wake key.
4774 */
4775 private boolean isWakeKeyWhenScreenOff(int keyCode) {
4776 switch (keyCode) {
4777 // ignore volume keys unless docked
4778 case KeyEvent.KEYCODE_VOLUME_UP:
4779 case KeyEvent.KEYCODE_VOLUME_DOWN:
4780 case KeyEvent.KEYCODE_VOLUME_MUTE:
4781 return mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED;
4782
4783 // ignore media and camera keys
4784 case KeyEvent.KEYCODE_MUTE:
4785 case KeyEvent.KEYCODE_HEADSETHOOK:
4786 case KeyEvent.KEYCODE_MEDIA_PLAY:
4787 case KeyEvent.KEYCODE_MEDIA_PAUSE:
4788 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
4789 case KeyEvent.KEYCODE_MEDIA_STOP:
4790 case KeyEvent.KEYCODE_MEDIA_NEXT:
4791 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
4792 case KeyEvent.KEYCODE_MEDIA_REWIND:
4793 case KeyEvent.KEYCODE_MEDIA_RECORD:
4794 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09004795 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK:
Jeff Brown1c2e4942012-11-06 16:32:01 -08004796 case KeyEvent.KEYCODE_CAMERA:
4797 return false;
4798 }
4799 return true;
4800 }
4801
4802
Jeff Brown56194eb2011-03-02 19:23:13 -08004803 /** {@inheritDoc} */
4804 @Override
Michael Wright70af00a2014-09-03 19:30:20 -07004805 public int interceptMotionBeforeQueueingNonInteractive(long whenNanos, int policyFlags) {
4806 if ((policyFlags & FLAG_WAKE) != 0) {
Bryce Lee5c138322014-11-03 08:26:09 -08004807 if (wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotion)) {
4808 return 0;
4809 }
Michael Wright70af00a2014-09-03 19:30:20 -07004810 }
Bryce Lee5c138322014-11-03 08:26:09 -08004811
Michael Wright70af00a2014-09-03 19:30:20 -07004812 if (shouldDispatchInputWhenNonInteractive()) {
4813 return ACTION_PASS_TO_USER;
4814 }
Bryce Lee5c138322014-11-03 08:26:09 -08004815
Bryce Lee812d7022014-11-10 13:33:28 -08004816 // If we have not passed the action up and we are in theater mode without dreaming,
4817 // there will be no dream to intercept the touch and wake into ambient. The device should
4818 // wake up in this case.
4819 if (isTheaterModeEnabled() && (policyFlags & FLAG_WAKE) != 0) {
4820 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotionWhenNotDreaming);
4821 }
4822
Jeff Brown037c33e2014-04-09 00:31:55 -07004823 return 0;
Jeff Brown56194eb2011-03-02 19:23:13 -08004824 }
4825
Michael Wright70af00a2014-09-03 19:30:20 -07004826 private boolean shouldDispatchInputWhenNonInteractive() {
Bryce Lee5c138322014-11-03 08:26:09 -08004827 // Send events to keyguard while the screen is on.
Jim Millerab954542014-10-10 18:21:49 -07004828 if (isKeyguardShowingAndNotOccluded() && mDisplay != null
4829 && mDisplay.getState() != Display.STATE_OFF) {
Bryce Lee5c138322014-11-03 08:26:09 -08004830 return true;
4831 }
4832
4833 // Send events to a dozing dream even if the screen is off since the dream
4834 // is in control of the state of the screen.
4835 IDreamManager dreamManager = getDreamManager();
4836
4837 try {
4838 if (dreamManager != null && dreamManager.isDreaming()) {
4839 return true;
4840 }
4841 } catch (RemoteException e) {
4842 Slog.e(TAG, "RemoteException when checking if dreaming", e);
4843 }
4844
4845 // Otherwise, consume events since the user can't see what is being
4846 // interacted with.
4847 return false;
Michael Wright70af00a2014-09-03 19:30:20 -07004848 }
4849
RoboErik001c59c2015-01-26 15:53:51 -08004850 private void dispatchDirectAudioEvent(KeyEvent event) {
4851 if (event.getAction() != KeyEvent.ACTION_DOWN) {
4852 return;
4853 }
4854 int keyCode = event.getKeyCode();
4855 int flags = AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_PLAY_SOUND;
4856 String pkgName = mContext.getOpPackageName();
4857 switch (keyCode) {
4858 case KeyEvent.KEYCODE_VOLUME_UP:
4859 try {
4860 if (mUseMasterVolume) {
4861 getAudioService().adjustMasterVolume(AudioManager.ADJUST_RAISE, flags,
4862 pkgName);
4863 } else {
4864 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_RAISE,
4865 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName);
4866 }
4867 } catch (RemoteException e) {
4868 Log.e(TAG, "Error dispatching volume up in dispatchTvAudioEvent.", e);
4869 }
4870 break;
4871 case KeyEvent.KEYCODE_VOLUME_DOWN:
4872 try {
4873 if (mUseMasterVolume) {
4874 getAudioService().adjustMasterVolume(AudioManager.ADJUST_LOWER, flags,
4875 pkgName);
4876 } else {
4877 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_LOWER,
4878 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName);
4879 }
4880 } catch (RemoteException e) {
4881 Log.e(TAG, "Error dispatching volume down in dispatchTvAudioEvent.", e);
4882 }
4883 break;
4884 case KeyEvent.KEYCODE_VOLUME_MUTE:
4885 try {
4886 if (event.getRepeatCount() == 0) {
4887 if (mUseMasterVolume) {
4888 getAudioService().adjustMasterVolume(AudioManager.ADJUST_TOGGLE_MUTE,
4889 flags, pkgName);
4890 } else {
4891 getAudioService().adjustSuggestedStreamVolume(
4892 AudioManager.ADJUST_TOGGLE_MUTE,
4893 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName);
4894 }
4895 }
4896 } catch (RemoteException e) {
4897 Log.e(TAG, "Error dispatching mute in dispatchTvAudioEvent.", e);
4898 }
4899 break;
4900 }
4901 }
4902
Jeff Brown40013652012-05-16 21:22:36 -07004903 void dispatchMediaKeyWithWakeLock(KeyEvent event) {
4904 if (DEBUG_INPUT) {
4905 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: " + event);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004906 }
4907
Jeff Brown40013652012-05-16 21:22:36 -07004908 if (mHavePendingMediaKeyRepeatWithWakeLock) {
4909 if (DEBUG_INPUT) {
4910 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: canceled repeat");
4911 }
4912
4913 mHandler.removeMessages(MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK);
4914 mHavePendingMediaKeyRepeatWithWakeLock = false;
4915 mBroadcastWakeLock.release(); // pending repeat was holding onto the wake lock
4916 }
4917
4918 dispatchMediaKeyWithWakeLockToAudioService(event);
4919
4920 if (event.getAction() == KeyEvent.ACTION_DOWN
4921 && event.getRepeatCount() == 0) {
4922 mHavePendingMediaKeyRepeatWithWakeLock = true;
4923
4924 Message msg = mHandler.obtainMessage(
4925 MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK, event);
4926 msg.setAsynchronous(true);
4927 mHandler.sendMessageDelayed(msg, ViewConfiguration.getKeyRepeatTimeout());
4928 } else {
4929 mBroadcastWakeLock.release();
4930 }
4931 }
4932
4933 void dispatchMediaKeyRepeatWithWakeLock(KeyEvent event) {
4934 mHavePendingMediaKeyRepeatWithWakeLock = false;
4935
4936 KeyEvent repeatEvent = KeyEvent.changeTimeRepeat(event,
4937 SystemClock.uptimeMillis(), 1, event.getFlags() | KeyEvent.FLAG_LONG_PRESS);
4938 if (DEBUG_INPUT) {
4939 Slog.d(TAG, "dispatchMediaKeyRepeatWithWakeLock: " + repeatEvent);
4940 }
4941
4942 dispatchMediaKeyWithWakeLockToAudioService(repeatEvent);
4943 mBroadcastWakeLock.release();
4944 }
4945
4946 void dispatchMediaKeyWithWakeLockToAudioService(KeyEvent event) {
4947 if (ActivityManagerNative.isSystemReady()) {
RoboErik430fc482014-06-12 15:49:20 -07004948 MediaSessionLegacyHelper.getHelper(mContext).sendMediaButtonEvent(event, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004949 }
4950 }
4951
Michael Wright869a67c2014-08-26 19:33:06 -07004952 void launchVoiceAssistWithWakeLock(boolean keyguardActive) {
4953 Intent voiceIntent =
4954 new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
4955 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, keyguardActive);
4956 mContext.startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
4957 mBroadcastWakeLock.release();
4958 }
4959
Mike Lockwood1753f7f2009-08-24 14:49:07 -07004960 BroadcastReceiver mDockReceiver = new BroadcastReceiver() {
Craig Mautnereee29c42013-01-17 14:44:34 -08004961 @Override
Mike Lockwood1753f7f2009-08-24 14:49:07 -07004962 public void onReceive(Context context, Intent intent) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07004963 if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) {
4964 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
4965 Intent.EXTRA_DOCK_STATE_UNDOCKED);
Daniel Sandler6396c722013-04-16 20:19:09 -04004966 } else {
4967 try {
4968 IUiModeManager uiModeService = IUiModeManager.Stub.asInterface(
4969 ServiceManager.getService(Context.UI_MODE_SERVICE));
4970 mUiMode = uiModeService.getCurrentModeType();
4971 } catch (RemoteException e) {
4972 }
Dianne Hackborn80fa1662009-10-07 14:02:10 -07004973 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004974 updateRotation(true);
Craig Mautnereee29c42013-01-17 14:44:34 -08004975 synchronized (mLock) {
4976 updateOrientationListenerLp();
4977 }
Mike Lockwood1753f7f2009-08-24 14:49:07 -07004978 }
4979 };
4980
Jeff Brown6aaf2952012-10-05 16:01:08 -07004981 BroadcastReceiver mDreamReceiver = new BroadcastReceiver() {
4982 @Override
4983 public void onReceive(Context context, Intent intent) {
4984 if (Intent.ACTION_DREAMING_STARTED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004985 if (mKeyguardDelegate != null) {
4986 mKeyguardDelegate.onDreamingStarted();
Jeff Brown6aaf2952012-10-05 16:01:08 -07004987 }
4988 } else if (Intent.ACTION_DREAMING_STOPPED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004989 if (mKeyguardDelegate != null) {
4990 mKeyguardDelegate.onDreamingStopped();
Jeff Brown6aaf2952012-10-05 16:01:08 -07004991 }
4992 }
4993 }
4994 };
4995
Christopher Tate5e08af02012-09-21 17:17:22 -07004996 BroadcastReceiver mMultiuserReceiver = new BroadcastReceiver() {
4997 @Override
4998 public void onReceive(Context context, Intent intent) {
4999 if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) {
5000 // tickle the settings observer: this first ensures that we're
5001 // observing the relevant settings for the newly-active user,
5002 // and then updates our own bookkeeping based on the now-
5003 // current user.
5004 mSettingsObserver.onChange(false);
John Spurlockce479d82012-11-29 09:52:21 -05005005
5006 // force a re-application of focused window sysui visibility.
5007 // the window may never have been shown for this user
5008 // e.g. the keyguard when going through the new-user setup flow
John Spurlock04db1762013-05-13 12:46:41 -04005009 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
John Spurlockce479d82012-11-29 09:52:21 -05005010 mLastSystemUiFlags = 0;
5011 updateSystemUiVisibilityLw();
5012 }
Christopher Tate5e08af02012-09-21 17:17:22 -07005013 }
5014 }
5015 };
5016
John Spurlockd9b70bd2014-02-06 17:02:44 -05005017 private final Runnable mRequestTransientNav = new Runnable() {
5018 @Override
5019 public void run() {
5020 requestTransientBars(mNavigationBar);
5021 }
5022 };
5023
John Spurlocke1f366f2013-08-05 12:22:40 -04005024 private void requestTransientBars(WindowState swipeTarget) {
John Spurlock04db1762013-05-13 12:46:41 -04005025 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Maurice Lam99c6e072014-04-28 18:24:28 -07005026 if (!isUserSetupComplete()) {
5027 // Swipe-up for navigation bar is disabled during setup
5028 return;
5029 }
John Spurlock27735a42013-08-14 17:57:38 -04005030 boolean sb = mStatusBarController.checkShowTransientBarLw();
5031 boolean nb = mNavigationBarController.checkShowTransientBarLw();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005032 if (sb || nb) {
John Spurlocke1f366f2013-08-05 12:22:40 -04005033 WindowState barTarget = sb ? mStatusBar : mNavigationBar;
5034 if (sb ^ nb && barTarget != swipeTarget) {
5035 if (DEBUG) Slog.d(TAG, "Not showing transient bar, wrong swipe target");
John Spurlockad3e6cb2013-04-30 08:47:43 -04005036 return;
5037 }
John Spurlock27735a42013-08-14 17:57:38 -04005038 if (sb) mStatusBarController.showTransient();
5039 if (nb) mNavigationBarController.showTransient();
John Spurlockf1a36642013-10-12 17:50:42 -04005040 mImmersiveModeConfirmation.confirmCurrentPrompt();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005041 updateSystemUiVisibilityLw();
John Spurlock32beb2c2013-03-11 10:16:47 -04005042 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04005043 }
5044 }
5045
Jeff Brown3ee549c2014-09-22 20:14:39 -07005046 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07005047 @Override
Jeff Brown140ffc72014-05-01 15:18:00 -07005048 public void goingToSleep(int why) {
Dianne Hackborn74489012009-03-24 20:50:09 -07005049 EventLog.writeEvent(70000, 0);
Jeff Brown36c4db82014-09-19 12:05:31 -07005050 if (DEBUG_WAKEUP) Slog.i(TAG, "Going to sleep...");
Jeff Brown3ee549c2014-09-22 20:14:39 -07005051
5052 // We must get this work done here because the power manager will drop
5053 // the wake lock and let the system suspend once this function returns.
The Android Open Source Project0727d222009-03-11 12:11:58 -07005054 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005055 mAwake = false;
5056 mKeyguardDrawComplete = false;
Jeff Browna20dda42014-05-27 20:57:24 -07005057 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005058 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05005059 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005060 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005061
5062 if (mKeyguardDelegate != null) {
5063 mKeyguardDelegate.onScreenTurnedOff(why);
5064 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005065 }
5066
Jeff Brown13f00f02014-10-31 14:45:50 -07005067 private void wakeUpFromPowerKey(long eventTime) {
5068 wakeUp(eventTime, mAllowTheaterModeWakeFromPowerKey);
5069 }
5070
Bryce Lee5c138322014-11-03 08:26:09 -08005071 private boolean wakeUp(long wakeTime, boolean wakeInTheaterMode) {
Bryce Lee584a4452014-10-21 15:55:55 -07005072 if (!wakeInTheaterMode && isTheaterModeEnabled()) {
Bryce Lee5c138322014-11-03 08:26:09 -08005073 return false;
Bryce Lee584a4452014-10-21 15:55:55 -07005074 }
5075
5076 mPowerManager.wakeUp(wakeTime);
Bryce Lee5c138322014-11-03 08:26:09 -08005077 return true;
Bryce Lee584a4452014-10-21 15:55:55 -07005078 }
5079
Jeff Brown3ee549c2014-09-22 20:14:39 -07005080 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07005081 @Override
Jeff Brown36c4db82014-09-19 12:05:31 -07005082 public void wakingUp() {
Dianne Hackborn74489012009-03-24 20:50:09 -07005083 EventLog.writeEvent(70000, 1);
Jeff Brown36c4db82014-09-19 12:05:31 -07005084 if (DEBUG_WAKEUP) Slog.i(TAG, "Waking up...");
Craig Mautner8a0da012014-05-31 15:13:37 -07005085
Jeff Brown3ee549c2014-09-22 20:14:39 -07005086 // Since goToSleep performs these functions synchronously, we must
5087 // do the same here. We cannot post this work to a handler because
5088 // that might cause it to become reordered with respect to what
5089 // may happen in a future call to goToSleep.
The Android Open Source Project0727d222009-03-11 12:11:58 -07005090 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005091 mAwake = true;
5092 mKeyguardDrawComplete = false;
5093 if (mKeyguardDelegate != null) {
5094 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
5095 mHandler.sendEmptyMessageDelayed(MSG_KEYGUARD_DRAWN_TIMEOUT, 1000);
5096 }
5097
Jeff Browna20dda42014-05-27 20:57:24 -07005098 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005099 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05005100 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005101 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005102
Jim Miller5ecd8112013-01-09 18:50:26 -08005103 if (mKeyguardDelegate != null) {
Craig Mautner8a0da012014-05-31 15:13:37 -07005104 mKeyguardDelegate.onScreenTurnedOn(mKeyguardDelegateCallback);
Jeff Brown36c4db82014-09-19 12:05:31 -07005105 // ... eventually calls finishKeyguardDrawn
Jeff Brownc38c9be2012-10-04 13:16:19 -07005106 } else {
Craig Mautner8a0da012014-05-31 15:13:37 -07005107 if (DEBUG_WAKEUP) Slog.d(TAG, "null mKeyguardDelegate: setting mKeyguardDrawComplete.");
Jeff Brown36c4db82014-09-19 12:05:31 -07005108 finishKeyguardDrawn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07005109 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005110 }
5111
Jeff Brown36c4db82014-09-19 12:05:31 -07005112 private void finishKeyguardDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005113 synchronized (mLock) {
5114 if (!mAwake || mKeyguardDrawComplete) {
5115 return; // spurious
5116 }
5117
Jeff Brown36c4db82014-09-19 12:05:31 -07005118 mKeyguardDrawComplete = true;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005119 if (mKeyguardDelegate != null) {
5120 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
5121 }
5122 }
5123
5124 finishScreenTurningOn();
5125 }
5126
5127 // Called on the DisplayManager's DisplayPowerController thread.
5128 @Override
5129 public void screenTurnedOff() {
5130 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turned off...");
5131
5132 synchronized (mLock) {
5133 mScreenOnEarly = false;
5134 mScreenOnFully = false;
5135 mWindowManagerDrawComplete = false;
5136 mScreenOnListener = null;
5137 updateOrientationListenerLp();
Jeff Brown36c4db82014-09-19 12:05:31 -07005138 }
5139 }
5140
Jeff Brown3ee549c2014-09-22 20:14:39 -07005141 // Called on the DisplayManager's DisplayPowerController thread.
Jeff Brown36c4db82014-09-19 12:05:31 -07005142 @Override
5143 public void screenTurningOn(final ScreenOnListener screenOnListener) {
Jeff Brown36c4db82014-09-19 12:05:31 -07005144 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turning on...");
Jeff Brown36c4db82014-09-19 12:05:31 -07005145
Jeff Brown3ee549c2014-09-22 20:14:39 -07005146 synchronized (mLock) {
5147 mScreenOnEarly = true;
5148 mScreenOnFully = false;
5149 mWindowManagerDrawComplete = false;
5150 mScreenOnListener = screenOnListener;
5151 updateOrientationListenerLp();
5152 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005153
Craig Mautnerc3daedd2014-09-13 11:17:23 -07005154 mWindowManagerInternal.waitForAllWindowsDrawn(mWindowManagerDrawCallback,
5155 WAITING_FOR_DRAWN_TIMEOUT);
Jeff Brown36c4db82014-09-19 12:05:31 -07005156 // ... eventually calls finishWindowsDrawn
5157 }
5158
Jeff Brown36c4db82014-09-19 12:05:31 -07005159 private void finishWindowsDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005160 synchronized (mLock) {
5161 if (!mScreenOnEarly || mWindowManagerDrawComplete) {
5162 return; // spurious
5163 }
5164
Jeff Brown36c4db82014-09-19 12:05:31 -07005165 mWindowManagerDrawComplete = true;
Jeff Brown36c4db82014-09-19 12:05:31 -07005166 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005167
5168 finishScreenTurningOn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07005169 }
5170
Craig Mautner8a0da012014-05-31 15:13:37 -07005171 private void finishScreenTurningOn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005172 final ScreenOnListener listener;
5173 final boolean enableScreen;
Jeff Brown36c4db82014-09-19 12:05:31 -07005174 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005175 if (DEBUG_WAKEUP) Slog.d(TAG,
5176 "finishScreenTurningOn: mAwake=" + mAwake
5177 + ", mScreenOnEarly=" + mScreenOnEarly
5178 + ", mScreenOnFully=" + mScreenOnFully
5179 + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete
5180 + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete);
5181
5182 if (mScreenOnFully || !mScreenOnEarly || !mWindowManagerDrawComplete
5183 || (mAwake && !mKeyguardDrawComplete)) {
5184 return; // spurious or not ready yet
Jeff Brown36c4db82014-09-19 12:05:31 -07005185 }
5186
Jeff Brown3ee549c2014-09-22 20:14:39 -07005187 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished screen turning on...");
5188 listener = mScreenOnListener;
Craig Mautner13f6ea72014-06-23 14:57:02 -07005189 mScreenOnListener = null;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005190 mScreenOnFully = true;
5191
5192 // Remember the first time we draw the keyguard so we know when we're done with
5193 // the main part of booting and can enable the screen and hide boot messages.
5194 if (!mKeyguardDrawnOnce && mAwake) {
5195 mKeyguardDrawnOnce = true;
5196 enableScreen = true;
5197 if (mBootMessageNeedsHiding) {
5198 mBootMessageNeedsHiding = false;
5199 hideBootMessages();
5200 }
5201 } else {
5202 enableScreen = false;
5203 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005204 }
5205
Jeff Brown3ee549c2014-09-22 20:14:39 -07005206 if (listener != null) {
5207 listener.onScreenOn();
5208 }
Jeff Brown4fc45272012-10-10 18:28:14 -07005209
Jeff Brown3ee549c2014-09-22 20:14:39 -07005210 if (enableScreen) {
5211 try {
5212 mWindowManager.enableScreenIfNeeded();
5213 } catch (RemoteException unhandled) {
Jeff Brown36c4db82014-09-19 12:05:31 -07005214 }
Craig Mautnera631d492014-08-05 15:16:01 -07005215 }
5216 }
5217
5218 private void handleHideBootMessage() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005219 synchronized (mLock) {
5220 if (!mKeyguardDrawnOnce) {
5221 mBootMessageNeedsHiding = true;
5222 return; // keyguard hasn't drawn the first time yet, not done booting
5223 }
Craig Mautnera631d492014-08-05 15:16:01 -07005224 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005225
5226 if (mBootMsgDialog != null) {
5227 if (DEBUG_WAKEUP) Slog.d(TAG, "handleHideBootMessage: dismissing");
5228 mBootMsgDialog.dismiss();
5229 mBootMsgDialog = null;
Craig Mautnera631d492014-08-05 15:16:01 -07005230 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005231 }
5232
5233 @Override
Jeff Brown3ee549c2014-09-22 20:14:39 -07005234 public boolean isScreenOn() {
5235 return mScreenOnFully;
Dianne Hackborn08743722009-12-21 12:16:51 -08005236 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005237
Dianne Hackborn08743722009-12-21 12:16:51 -08005238 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005239 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005240 public void enableKeyguard(boolean enabled) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005241 if (mKeyguardDelegate != null) {
5242 mKeyguardDelegate.setKeyguardEnabled(enabled);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005243 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005244 }
5245
5246 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005247 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005248 public void exitKeyguardSecurely(OnKeyguardExitResult callback) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005249 if (mKeyguardDelegate != null) {
5250 mKeyguardDelegate.verifyUnlock(callback);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005251 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005252 }
5253
Jim Millerab954542014-10-10 18:21:49 -07005254 private boolean isKeyguardShowingAndNotOccluded() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005255 if (mKeyguardDelegate == null) return false;
Jim Millerab954542014-10-10 18:21:49 -07005256 return mKeyguardDelegate.isShowing() && !mKeyguardOccluded;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005257 }
5258
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005259 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005260 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005261 public boolean isKeyguardLocked() {
5262 return keyguardOn();
5263 }
5264
5265 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005266 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005267 public boolean isKeyguardSecure() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005268 if (mKeyguardDelegate == null) return false;
5269 return mKeyguardDelegate.isSecure();
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005270 }
5271
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005272 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005273 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005274 public boolean inKeyguardRestrictedKeyInputMode() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005275 if (mKeyguardDelegate == null) return false;
5276 return mKeyguardDelegate.isInputRestricted();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005277 }
5278
Jose Lima9546b202014-07-02 17:21:51 -07005279 @Override
Dianne Hackborn90c52de2011-09-23 12:57:44 -07005280 public void dismissKeyguardLw() {
RoboErik8a2cfc32014-05-16 11:19:38 -07005281 if (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()) {
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07005282 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.dismissKeyguardLw");
Daniel Sandler1ce804392012-11-07 15:07:12 -05005283 mHandler.post(new Runnable() {
Jose Lima9546b202014-07-02 17:21:51 -07005284 @Override
Daniel Sandler1ce804392012-11-07 15:07:12 -05005285 public void run() {
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02005286 // ask the keyguard to prompt the user to authenticate if necessary
5287 mKeyguardDelegate.dismiss();
5288 }
5289 });
5290 }
5291 }
5292
5293 public void notifyActivityDrawnForKeyguardLw() {
5294 if (mKeyguardDelegate != null) {
5295 mHandler.post(new Runnable() {
5296 @Override
5297 public void run() {
5298 mKeyguardDelegate.onActivityDrawn();
Daniel Sandler1ce804392012-11-07 15:07:12 -05005299 }
5300 });
Dianne Hackborn90c52de2011-09-23 12:57:44 -07005301 }
5302 }
5303
Jorim Jaggicff0acb2014-03-31 16:35:15 +02005304 @Override
5305 public boolean isKeyguardDrawnLw() {
5306 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005307 return mKeyguardDrawnOnce;
Jorim Jaggicff0acb2014-03-31 16:35:15 +02005308 }
5309 }
5310
Jorim Jaggi0d674622014-05-21 01:34:15 +02005311 @Override
Jorim Jaggie29b2db2014-05-30 23:17:03 +02005312 public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) {
Jorim Jaggi0d674622014-05-21 01:34:15 +02005313 if (mKeyguardDelegate != null) {
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07005314 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.startKeyguardExitAnimation");
Jorim Jaggie29b2db2014-05-30 23:17:03 +02005315 mKeyguardDelegate.startKeyguardExitAnimation(startTime, fadeoutDuration);
Jorim Jaggi0d674622014-05-21 01:34:15 +02005316 }
5317 }
5318
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005319 void sendCloseSystemWindows() {
Jorim Jaggib10e33f2015-02-04 21:57:40 +01005320 PhoneWindow.sendCloseSystemWindows(mContext, null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005321 }
5322
5323 void sendCloseSystemWindows(String reason) {
Jorim Jaggib10e33f2015-02-04 21:57:40 +01005324 PhoneWindow.sendCloseSystemWindows(mContext, reason);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005325 }
Mitsuru Oshima831d0d92009-06-16 18:27:18 -07005326
Jeff Brown01a98dd2011-09-20 15:08:29 -07005327 @Override
5328 public int rotationForOrientationLw(int orientation, int lastRotation) {
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005329 if (false) {
5330 Slog.v(TAG, "rotationForOrientationLw(orient="
5331 + orientation + ", last=" + lastRotation
5332 + "); user=" + mUserRotation + " "
5333 + ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED)
5334 ? "USER_ROTATION_LOCKED" : "")
5335 );
5336 }
5337
Craig Mautner46ac6fa2013-08-01 10:06:34 -07005338 if (mForceDefaultOrientation) {
5339 return Surface.ROTATION_0;
5340 }
5341
The Android Open Source Project0727d222009-03-11 12:11:58 -07005342 synchronized (mLock) {
Jeff Brownc0347aa2011-09-23 17:26:09 -07005343 int sensorRotation = mOrientationListener.getProposedRotation(); // may be -1
5344 if (sensorRotation < 0) {
Jeff Brown0f862b42012-09-27 21:11:01 -07005345 sensorRotation = lastRotation;
Jeff Brownc0347aa2011-09-23 17:26:09 -07005346 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005347
Jeff Browndec6cf42011-11-15 14:08:20 -08005348 final int preferredRotation;
Jeff Brown2e7760e2012-04-11 15:14:55 -07005349 if (mLidState == LID_OPEN && mLidOpenRotation >= 0) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005350 // Ignore sensor when lid switch is open and rotation is forced.
5351 preferredRotation = mLidOpenRotation;
5352 } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR
Jeff Brownc0347aa2011-09-23 17:26:09 -07005353 && (mCarDockEnablesAccelerometer || mCarDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005354 // Ignore sensor when in car dock unless explicitly enabled.
5355 // This case can override the behavior of NOSENSOR, and can also
5356 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07005357 preferredRotation = mCarDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07005358 ? sensorRotation : mCarDockRotation;
Jeff Brown1a693182011-11-08 14:44:16 -08005359 } else if ((mDockMode == Intent.EXTRA_DOCK_STATE_DESK
5360 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
5361 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK)
Jeff Brownc0347aa2011-09-23 17:26:09 -07005362 && (mDeskDockEnablesAccelerometer || mDeskDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005363 // Ignore sensor when in desk dock unless explicitly enabled.
5364 // This case can override the behavior of NOSENSOR, and can also
5365 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07005366 preferredRotation = mDeskDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07005367 ? sensorRotation : mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -07005368 } else if (mHdmiPlugged && mDemoHdmiRotationLock) {
5369 // Ignore sensor when plugged into HDMI when demo HDMI rotation lock enabled.
Jeff Browneb3e4b92011-12-06 19:54:24 -08005370 // Note that the dock orientation overrides the HDMI orientation.
Jeff Brownc82c89ed2013-04-17 17:18:15 -07005371 preferredRotation = mDemoHdmiRotation;
5372 } else if (mHdmiPlugged && mDockMode == Intent.EXTRA_DOCK_STATE_UNDOCKED
5373 && mUndockedHdmiRotation >= 0) {
5374 // Ignore sensor when plugged into HDMI and an undocked orientation has
5375 // been specified in the configuration (only for legacy devices without
5376 // full multi-display support).
5377 // Note that the dock orientation overrides the HDMI orientation.
5378 preferredRotation = mUndockedHdmiRotation;
Chong Zhangae6119ff2014-11-11 18:54:39 -08005379 } else if (mDemoRotationLock) {
5380 // Ignore sensor when demo rotation lock is enabled.
5381 // Note that the dock orientation and HDMI rotation lock override this.
5382 preferredRotation = mDemoRotation;
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005383 } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED) {
5384 // Application just wants to remain locked in the last rotation.
5385 preferredRotation = lastRotation;
Jeff Brownbcdfc622014-03-06 19:13:04 -08005386 } else if (!mSupportAutoRotation) {
5387 // If we don't support auto-rotation then bail out here and ignore
5388 // the sensor and any rotation lock settings.
5389 preferredRotation = -1;
Jeff Brown207673cd2012-06-05 17:47:11 -07005390 } else if ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE
Jeff Brown01a98dd2011-09-20 15:08:29 -07005391 && (orientation == ActivityInfo.SCREEN_ORIENTATION_USER
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005392 || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
5393 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
5394 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
5395 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER))
Jeff Brown01a98dd2011-09-20 15:08:29 -07005396 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
5397 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
5398 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
5399 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) {
5400 // Otherwise, use sensor only if requested by the application or enabled
5401 // by default for USER or UNSPECIFIED modes. Does not apply to NOSENSOR.
Jeff Brownd3187e32011-09-21 19:26:44 -07005402 if (mAllowAllRotations < 0) {
5403 // Can't read this during init() because the context doesn't
5404 // have display metrics at that time so we cannot determine
5405 // tablet vs. phone then.
5406 mAllowAllRotations = mContext.getResources().getBoolean(
5407 com.android.internal.R.bool.config_allowAllRotations) ? 1 : 0;
5408 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005409 if (sensorRotation != Surface.ROTATION_180
Jeff Brownd3187e32011-09-21 19:26:44 -07005410 || mAllowAllRotations == 1
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005411 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
5412 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005413 preferredRotation = sensorRotation;
5414 } else {
5415 preferredRotation = lastRotation;
5416 }
Jeff Brown207673cd2012-06-05 17:47:11 -07005417 } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED
5418 && orientation != ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) {
5419 // Apply rotation lock. Does not apply to NOSENSOR.
5420 // The idea is that the user rotation expresses a weak preference for the direction
5421 // of gravity and as NOSENSOR is never affected by gravity, then neither should
5422 // NOSENSOR be affected by rotation lock (although it will be affected by docks).
Jeff Brown4dfce202011-10-05 12:00:10 -07005423 preferredRotation = mUserRotation;
Jeff Browndec6cf42011-11-15 14:08:20 -08005424 } else {
5425 // No overriding preference.
5426 // We will do exactly what the application asked us to do.
5427 preferredRotation = -1;
Jeff Brown01a98dd2011-09-20 15:08:29 -07005428 }
5429
Dianne Hackborne5439f22010-10-02 16:53:50 -07005430 switch (orientation) {
5431 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08005432 // Return portrait unless overridden.
5433 if (isAnyPortrait(preferredRotation)) {
5434 return preferredRotation;
5435 }
Dianne Hackborne5439f22010-10-02 16:53:50 -07005436 return mPortraitRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005437
Jeff Brown01a98dd2011-09-20 15:08:29 -07005438 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08005439 // Return landscape unless overridden.
5440 if (isLandscapeOrSeascape(preferredRotation)) {
5441 return preferredRotation;
5442 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005443 return mLandscapeRotation;
5444
5445 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08005446 // Return reverse portrait unless overridden.
5447 if (isAnyPortrait(preferredRotation)) {
5448 return preferredRotation;
5449 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005450 return mUpsideDownRotation;
5451
5452 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08005453 // Return seascape unless overridden.
5454 if (isLandscapeOrSeascape(preferredRotation)) {
5455 return preferredRotation;
5456 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005457 return mSeascapeRotation;
5458
5459 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005460 case ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE:
Jeff Brown01a98dd2011-09-20 15:08:29 -07005461 // Return either landscape rotation.
5462 if (isLandscapeOrSeascape(preferredRotation)) {
5463 return preferredRotation;
5464 }
5465 if (isLandscapeOrSeascape(lastRotation)) {
Jeff Brown4519f072011-01-23 13:16:01 -08005466 return lastRotation;
5467 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005468 return mLandscapeRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005469
Jeff Brown01a98dd2011-09-20 15:08:29 -07005470 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005471 case ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT:
Jeff Brown01a98dd2011-09-20 15:08:29 -07005472 // Return either portrait rotation.
5473 if (isAnyPortrait(preferredRotation)) {
5474 return preferredRotation;
5475 }
5476 if (isAnyPortrait(lastRotation)) {
5477 return lastRotation;
5478 }
5479 return mPortraitRotation;
5480
5481 default:
Jeff Brown4dfce202011-10-05 12:00:10 -07005482 // For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR,
5483 // just return the preferred orientation we already calculated.
Jeff Brown01a98dd2011-09-20 15:08:29 -07005484 if (preferredRotation >= 0) {
5485 return preferredRotation;
5486 }
Dianne Hackborndacea8c2011-04-21 17:26:39 -07005487 return Surface.ROTATION_0;
Daniel Sandlere7e5ac22011-02-22 16:10:21 -05005488 }
5489 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07005490 }
5491
Jeff Brown01a98dd2011-09-20 15:08:29 -07005492 @Override
5493 public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation) {
5494 switch (orientation) {
5495 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
5496 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
5497 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
5498 return isAnyPortrait(rotation);
5499
5500 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
5501 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
5502 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
5503 return isLandscapeOrSeascape(rotation);
5504
5505 default:
5506 return true;
5507 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07005508 }
5509
Jeff Brownc0347aa2011-09-23 17:26:09 -07005510 @Override
5511 public void setRotationLw(int rotation) {
5512 mOrientationListener.setCurrentRotation(rotation);
5513 }
5514
Jeff Brown01a98dd2011-09-20 15:08:29 -07005515 private boolean isLandscapeOrSeascape(int rotation) {
5516 return rotation == mLandscapeRotation || rotation == mSeascapeRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005517 }
5518
Jeff Brown01a98dd2011-09-20 15:08:29 -07005519 private boolean isAnyPortrait(int rotation) {
5520 return rotation == mPortraitRotation || rotation == mUpsideDownRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005521 }
5522
Jose Lima9546b202014-07-02 17:21:51 -07005523 @Override
Svetoslav Ganov80943d82013-01-02 10:25:37 -08005524 public int getUserRotationMode() {
5525 return Settings.System.getIntForUser(mContext.getContentResolver(),
Brett Chabot7e55c402013-05-16 19:38:08 -07005526 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
5527 WindowManagerPolicy.USER_ROTATION_FREE :
5528 WindowManagerPolicy.USER_ROTATION_LOCKED;
Svetoslav Ganov80943d82013-01-02 10:25:37 -08005529 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005530
5531 // User rotation: to be used when all else fails in assigning an orientation to the device
Jose Lima9546b202014-07-02 17:21:51 -07005532 @Override
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005533 public void setUserRotationMode(int mode, int rot) {
5534 ContentResolver res = mContext.getContentResolver();
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005535
5536 // mUserRotationMode and mUserRotation will be assigned by the content observer
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005537 if (mode == WindowManagerPolicy.USER_ROTATION_LOCKED) {
Christopher Tate5e08af02012-09-21 17:17:22 -07005538 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005539 Settings.System.USER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005540 rot,
5541 UserHandle.USER_CURRENT);
5542 Settings.System.putIntForUser(res,
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005543 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005544 0,
5545 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005546 } else {
Christopher Tate5e08af02012-09-21 17:17:22 -07005547 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005548 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005549 1,
5550 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005551 }
5552 }
5553
Jose Lima9546b202014-07-02 17:21:51 -07005554 @Override
Jeff Brownac143512012-04-05 18:57:33 -07005555 public void setSafeMode(boolean safeMode) {
5556 mSafeMode = safeMode;
5557 performHapticFeedbackLw(null, safeMode
5558 ? HapticFeedbackConstants.SAFE_MODE_ENABLED
5559 : HapticFeedbackConstants.SAFE_MODE_DISABLED, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005560 }
Craig Mautnereda67292013-04-28 13:50:14 -07005561
Dianne Hackborn181ceb52009-08-27 22:16:40 -07005562 static long[] getLongIntArray(Resources r, int resid) {
5563 int[] ar = r.getIntArray(resid);
5564 if (ar == null) {
5565 return null;
5566 }
5567 long[] out = new long[ar.length];
5568 for (int i=0; i<ar.length; i++) {
5569 out[i] = ar[i];
5570 }
5571 return out;
5572 }
Craig Mautnereda67292013-04-28 13:50:14 -07005573
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005574 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07005575 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005576 public void systemReady() {
Jim Millerab954542014-10-10 18:21:49 -07005577 mKeyguardDelegate = new KeyguardServiceDelegate(mContext);
Mike Lockwooded8902d2013-11-15 11:01:47 -08005578 mKeyguardDelegate.onSystemReady();
5579
Michael Wright3818c922014-09-02 13:59:07 -07005580 readCameraLensCoverState();
Jeff Brown4f5fa282014-06-12 19:19:15 -07005581 updateUiMode();
Dianne Hackbornb1a79802009-09-29 15:18:31 -07005582 synchronized (mLock) {
5583 updateOrientationListenerLp();
Dianne Hackbornc777e072010-02-12 13:07:59 -08005584 mSystemReady = true;
5585 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07005586 @Override
Dianne Hackbornc777e072010-02-12 13:07:59 -08005587 public void run() {
5588 updateSettings();
5589 }
5590 });
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005591 }
5592 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07005593
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005594 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005595 @Override
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005596 public void systemBooted() {
Jim Millere5f910a2013-10-16 18:15:46 -07005597 if (mKeyguardDelegate != null) {
Jason Monk5eeebf52014-09-26 12:36:51 -04005598 mKeyguardDelegate.bindService(mContext);
Jim Millere5f910a2013-10-16 18:15:46 -07005599 mKeyguardDelegate.onBootCompleted();
5600 }
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005601 synchronized (mLock) {
5602 mSystemBooted = true;
5603 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005604 wakingUp();
5605 screenTurningOn(null);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005606 }
5607
Dianne Hackborn661cd522011-08-22 00:26:20 -07005608 ProgressDialog mBootMsgDialog = null;
5609
5610 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005611 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07005612 public void showBootMessage(final CharSequence msg, final boolean always) {
5613 mHandler.post(new Runnable() {
5614 @Override public void run() {
5615 if (mBootMsgDialog == null) {
Craig Stout4c0cb8a2014-04-04 13:03:10 -07005616 int theme;
5617 if (mContext.getPackageManager().hasSystemFeature(
5618 PackageManager.FEATURE_WATCH)) {
5619 theme = com.android.internal.R.style.Theme_Micro_Dialog_Alert;
5620 } else if (mContext.getPackageManager().hasSystemFeature(
5621 PackageManager.FEATURE_TELEVISION)) {
5622 theme = com.android.internal.R.style.Theme_Leanback_Dialog_Alert;
5623 } else {
5624 theme = 0;
5625 }
Vinod Krishnanfa8fc412014-04-18 14:35:53 -07005626
5627 mBootMsgDialog = new ProgressDialog(mContext, theme) {
Dianne Hackborn295e3c22011-08-25 13:19:08 -07005628 // This dialog will consume all events coming in to
5629 // it, to avoid it trying to do things too early in boot.
5630 @Override public boolean dispatchKeyEvent(KeyEvent event) {
5631 return true;
5632 }
5633 @Override public boolean dispatchKeyShortcutEvent(KeyEvent event) {
5634 return true;
5635 }
5636 @Override public boolean dispatchTouchEvent(MotionEvent ev) {
5637 return true;
5638 }
5639 @Override public boolean dispatchTrackballEvent(MotionEvent ev) {
5640 return true;
5641 }
5642 @Override public boolean dispatchGenericMotionEvent(MotionEvent ev) {
5643 return true;
5644 }
5645 @Override public boolean dispatchPopulateAccessibilityEvent(
5646 AccessibilityEvent event) {
5647 return true;
5648 }
5649 };
Jeff Hao9f60c082014-10-28 18:51:07 -07005650 if (mContext.getPackageManager().isUpgrade()) {
5651 mBootMsgDialog.setTitle(R.string.android_upgrading_title);
5652 } else {
5653 mBootMsgDialog.setTitle(R.string.android_start_title);
5654 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07005655 mBootMsgDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
5656 mBootMsgDialog.setIndeterminate(true);
5657 mBootMsgDialog.getWindow().setType(
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07005658 WindowManager.LayoutParams.TYPE_BOOT_PROGRESS);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005659 mBootMsgDialog.getWindow().addFlags(
5660 WindowManager.LayoutParams.FLAG_DIM_BEHIND
5661 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
5662 mBootMsgDialog.getWindow().setDimAmount(1);
Dianne Hackbornd9efb952011-12-07 14:56:51 -08005663 WindowManager.LayoutParams lp = mBootMsgDialog.getWindow().getAttributes();
5664 lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
5665 mBootMsgDialog.getWindow().setAttributes(lp);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005666 mBootMsgDialog.setCancelable(false);
5667 mBootMsgDialog.show();
5668 }
5669 mBootMsgDialog.setMessage(msg);
5670 }
5671 });
5672 }
5673
5674 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005675 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07005676 public void hideBootMessages() {
Craig Mautnera631d492014-08-05 15:16:01 -07005677 mHandler.sendEmptyMessage(MSG_HIDE_BOOT_MESSAGE);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005678 }
5679
Mike Lockwood28569302010-01-28 11:54:40 -05005680 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005681 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05005682 public void userActivity() {
Dianne Hackborndf89e652011-10-06 22:35:11 -07005683 // ***************************************
5684 // NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
5685 // ***************************************
5686 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
5687 // WITH ITS LOCKS HELD.
5688 //
5689 // This code must be VERY careful about the locks
5690 // it acquires.
5691 // In fact, the current code acquires way too many,
5692 // and probably has lurking deadlocks.
5693
Mike Lockwood28569302010-01-28 11:54:40 -05005694 synchronized (mScreenLockTimeout) {
5695 if (mLockScreenTimerActive) {
5696 // reset the timer
5697 mHandler.removeCallbacks(mScreenLockTimeout);
5698 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
5699 }
5700 }
Daniel Sandler0601eb72011-04-13 01:01:32 -04005701 }
5702
Adam Cohenf7522022012-10-03 20:03:18 -07005703 class ScreenLockTimeout implements Runnable {
5704 Bundle options;
5705
5706 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05005707 public void run() {
5708 synchronized (this) {
5709 if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard");
Jim Miller5ecd8112013-01-09 18:50:26 -08005710 if (mKeyguardDelegate != null) {
5711 mKeyguardDelegate.doKeyguardTimeout(options);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005712 }
Mike Lockwood28569302010-01-28 11:54:40 -05005713 mLockScreenTimerActive = false;
Adam Cohenf7522022012-10-03 20:03:18 -07005714 options = null;
Mike Lockwood28569302010-01-28 11:54:40 -05005715 }
5716 }
Mike Lockwood28569302010-01-28 11:54:40 -05005717
Adam Cohenf7522022012-10-03 20:03:18 -07005718 public void setLockOptions(Bundle options) {
5719 this.options = options;
5720 }
5721 }
5722
5723 ScreenLockTimeout mScreenLockTimeout = new ScreenLockTimeout();
5724
Jose Lima9546b202014-07-02 17:21:51 -07005725 @Override
Adam Cohenf7522022012-10-03 20:03:18 -07005726 public void lockNow(Bundle options) {
Jim Miller93c518e2012-01-17 15:55:31 -08005727 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null);
5728 mHandler.removeCallbacks(mScreenLockTimeout);
Adam Cohenf7522022012-10-03 20:03:18 -07005729 if (options != null) {
5730 // In case multiple calls are made to lockNow, we don't wipe out the options
5731 // until the runnable actually executes.
5732 mScreenLockTimeout.setLockOptions(options);
5733 }
Jim Miller93c518e2012-01-17 15:55:31 -08005734 mHandler.post(mScreenLockTimeout);
5735 }
5736
Mike Lockwood28569302010-01-28 11:54:40 -05005737 private void updateLockScreenTimeout() {
5738 synchronized (mScreenLockTimeout) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005739 boolean enable = (mAllowLockscreenWhenOn && mAwake &&
Jim Miller5ecd8112013-01-09 18:50:26 -08005740 mKeyguardDelegate != null && mKeyguardDelegate.isSecure());
Mike Lockwood28569302010-01-28 11:54:40 -05005741 if (mLockScreenTimerActive != enable) {
5742 if (enable) {
5743 if (localLOGV) Log.v(TAG, "setting lockscreen timer");
5744 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
5745 } else {
5746 if (localLOGV) Log.v(TAG, "clearing lockscreen timer");
5747 mHandler.removeCallbacks(mScreenLockTimeout);
5748 }
5749 mLockScreenTimerActive = enable;
5750 }
5751 }
5752 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005753
5754 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07005755 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005756 public void enableScreenAfterBoot() {
5757 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07005758 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07005759 updateRotation(true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005760 }
Dianne Hackbornf54c8f92009-09-19 14:03:57 -07005761
Jeff Brownc458ce92012-04-30 14:58:40 -07005762 private void applyLidSwitchState() {
Jeff Brownc458ce92012-04-30 14:58:40 -07005763 if (mLidState == LID_CLOSED && mLidControlsSleep) {
Jeff Brown6d8fd272014-05-20 21:24:38 -07005764 mPowerManager.goToSleep(SystemClock.uptimeMillis(),
Jeff Brownc12035c2014-08-13 18:52:25 -07005765 PowerManager.GO_TO_SLEEP_REASON_LID_SWITCH,
Jeff Brown6d8fd272014-05-20 21:24:38 -07005766 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
Jeff Brownc458ce92012-04-30 14:58:40 -07005767 }
Jeff Browna20dda42014-05-27 20:57:24 -07005768
5769 synchronized (mLock) {
5770 updateWakeGestureListenerLp();
5771 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005772 }
5773
Jeff Brown4f5fa282014-06-12 19:19:15 -07005774 void updateUiMode() {
5775 if (mUiModeManager == null) {
5776 mUiModeManager = IUiModeManager.Stub.asInterface(
5777 ServiceManager.getService(Context.UI_MODE_SERVICE));
5778 }
5779 try {
5780 mUiMode = mUiModeManager.getCurrentModeType();
5781 } catch (RemoteException e) {
5782 }
5783 }
5784
Jeff Brown01a98dd2011-09-20 15:08:29 -07005785 void updateRotation(boolean alwaysSendConfiguration) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005786 try {
5787 //set orientation on WindowManager
Dianne Hackbornf87d1962012-04-04 12:48:24 -07005788 mWindowManager.updateRotation(alwaysSendConfiguration, false);
5789 } catch (RemoteException e) {
5790 // Ignore
5791 }
5792 }
5793
5794 void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) {
5795 try {
5796 //set orientation on WindowManager
5797 mWindowManager.updateRotation(alwaysSendConfiguration, forceRelayout);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005798 } catch (RemoteException e) {
5799 // Ignore
5800 }
5801 }
5802
Daniel Sandler6396c722013-04-16 20:19:09 -04005803 /**
5804 * Return an Intent to launch the currently active dock app as home. Returns
5805 * null if the standard home should be launched, which is the case if any of the following is
5806 * true:
5807 * <ul>
5808 * <li>The device is not in either car mode or desk mode
5809 * <li>The device is in car mode but ENABLE_CAR_DOCK_HOME_CAPTURE is false
5810 * <li>The device is in desk mode but ENABLE_DESK_DOCK_HOME_CAPTURE is false
5811 * <li>The device is in car mode but there's no CAR_DOCK app with METADATA_DOCK_HOME
5812 * <li>The device is in desk mode but there's no DESK_DOCK app with METADATA_DOCK_HOME
5813 * </ul>
Craig Mautnereda67292013-04-28 13:50:14 -07005814 * @return A dock intent.
Daniel Sandler6396c722013-04-16 20:19:09 -04005815 */
5816 Intent createHomeDockIntent() {
5817 Intent intent = null;
5818
5819 // What home does is based on the mode, not the dock state. That
5820 // is, when in car mode you should be taken to car home regardless
5821 // of whether we are actually in a car dock.
5822 if (mUiMode == Configuration.UI_MODE_TYPE_CAR) {
5823 if (ENABLE_CAR_DOCK_HOME_CAPTURE) {
5824 intent = mCarDockIntent;
5825 }
5826 } else if (mUiMode == Configuration.UI_MODE_TYPE_DESK) {
5827 if (ENABLE_DESK_DOCK_HOME_CAPTURE) {
5828 intent = mDeskDockIntent;
5829 }
Jeff Brown4f5fa282014-06-12 19:19:15 -07005830 } else if (mUiMode == Configuration.UI_MODE_TYPE_WATCH
5831 && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
5832 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK
5833 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK)) {
5834 // Always launch dock home from home when watch is docked, if it exists.
5835 intent = mDeskDockIntent;
Daniel Sandler6396c722013-04-16 20:19:09 -04005836 }
5837
5838 if (intent == null) {
5839 return null;
5840 }
5841
5842 ActivityInfo ai = null;
5843 ResolveInfo info = mContext.getPackageManager().resolveActivityAsUser(
5844 intent,
John Spurlockf56bef12013-07-09 09:51:46 -04005845 PackageManager.MATCH_DEFAULT_ONLY | PackageManager.GET_META_DATA,
Craig Mautnerd625ab22013-09-06 13:40:31 -07005846 mCurrentUserId);
Daniel Sandler6396c722013-04-16 20:19:09 -04005847 if (info != null) {
5848 ai = info.activityInfo;
5849 }
5850 if (ai != null
5851 && ai.metaData != null
5852 && ai.metaData.getBoolean(Intent.METADATA_DOCK_HOME)) {
5853 intent = new Intent(intent);
5854 intent.setClassName(ai.packageName, ai.name);
5855 return intent;
5856 }
5857
5858 return null;
5859 }
5860
Bryce Lee01b0c5f2015-02-05 18:24:04 -08005861 void startDockOrHome(boolean fromHomeKey) {
John Spurlockc8b46ca2013-04-08 12:59:26 -04005862 awakenDreams();
Daniel Sandler6396c722013-04-16 20:19:09 -04005863
5864 Intent dock = createHomeDockIntent();
5865 if (dock != null) {
5866 try {
Bryce Lee01b0c5f2015-02-05 18:24:04 -08005867 if (fromHomeKey) {
5868 dock.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
5869 }
Daniel Sandler6396c722013-04-16 20:19:09 -04005870 mContext.startActivityAsUser(dock, UserHandle.CURRENT);
5871 return;
5872 } catch (ActivityNotFoundException e) {
5873 }
5874 }
5875
Bryce Lee01b0c5f2015-02-05 18:24:04 -08005876 Intent intent;
5877
5878 if (fromHomeKey) {
5879 intent = new Intent(mHomeIntent);
5880 intent.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
5881 } else {
5882 intent = mHomeIntent;
5883 }
5884
5885 mContext.startActivityAsUser(intent, UserHandle.CURRENT);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005886 }
Craig Mautnereda67292013-04-28 13:50:14 -07005887
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005888 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005889 * goes to the home screen
5890 * @return whether it did anything
5891 */
5892 boolean goHome() {
5893 if (false) {
5894 // This code always brings home to the front.
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07005895 try {
5896 ActivityManagerNative.getDefault().stopAppSwitches();
5897 } catch (RemoteException e) {
5898 }
Dianne Hackborn94a679d2009-07-28 17:51:07 -07005899 sendCloseSystemWindows();
Bryce Lee01b0c5f2015-02-05 18:24:04 -08005900 startDockOrHome(false /*fromHomeKey*/);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005901 } else {
5902 // This code brings home to the front or, if it is already
5903 // at the front, puts the device to sleep.
5904 try {
Wink Savilled2e6a332010-02-12 12:12:06 -08005905 if (SystemProperties.getInt("persist.sys.uts-test-mode", 0) == 1) {
5906 /// Roll back EndcallBehavior as the cupcake design to pass P1 lab entry.
5907 Log.d(TAG, "UTS-TEST-MODE");
5908 } else {
5909 ActivityManagerNative.getDefault().stopAppSwitches();
5910 sendCloseSystemWindows();
Daniel Sandler6396c722013-04-16 20:19:09 -04005911 Intent dock = createHomeDockIntent();
5912 if (dock != null) {
5913 int result = ActivityManagerNative.getDefault()
5914 .startActivityAsUser(null, null, dock,
5915 dock.resolveTypeIfNeeded(mContext.getContentResolver()),
5916 null, null, 0,
5917 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07005918 null, null, UserHandle.USER_CURRENT);
Daniel Sandler6396c722013-04-16 20:19:09 -04005919 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
5920 return false;
5921 }
5922 }
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005923 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005924 int result = ActivityManagerNative.getDefault()
Dianne Hackbornf265ea92013-01-31 15:00:51 -08005925 .startActivityAsUser(null, null, mHomeIntent,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005926 mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()),
Dianne Hackborna4972e92012-03-14 10:38:05 -07005927 null, null, 0,
5928 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07005929 null, null, UserHandle.USER_CURRENT);
Dianne Hackborna4972e92012-03-14 10:38:05 -07005930 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005931 return false;
5932 }
5933 } catch (RemoteException ex) {
5934 // bummer, the activity manager, which is in this process, is dead
5935 }
5936 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005937 return true;
5938 }
Craig Mautnereda67292013-04-28 13:50:14 -07005939
5940 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07005941 public void setCurrentOrientationLw(int newOrientation) {
5942 synchronized (mLock) {
5943 if (newOrientation != mCurrentAppOrientation) {
5944 mCurrentAppOrientation = newOrientation;
5945 updateOrientationListenerLp();
5946 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005947 }
5948 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08005949
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07005950 private void performAuditoryFeedbackForAccessibilityIfNeed() {
5951 if (!isGlobalAccessibilityGestureEnabled()) {
5952 return;
5953 }
5954 AudioManager audioManager = (AudioManager) mContext.getSystemService(
5955 Context.AUDIO_SERVICE);
5956 if (audioManager.isSilentMode()) {
5957 return;
5958 }
5959 Ringtone ringTone = RingtoneManager.getRingtone(mContext,
5960 Settings.System.DEFAULT_NOTIFICATION_URI);
5961 ringTone.setStreamType(AudioManager.STREAM_MUSIC);
5962 ringTone.play();
5963 }
Craig Mautnereda67292013-04-28 13:50:14 -07005964
Bryce Lee584a4452014-10-21 15:55:55 -07005965 private boolean isTheaterModeEnabled() {
5966 return Settings.Global.getInt(mContext.getContentResolver(),
5967 Settings.Global.THEATER_MODE_ON, 0) == 1;
5968 }
5969
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07005970 private boolean isGlobalAccessibilityGestureEnabled() {
5971 return Settings.Global.getInt(mContext.getContentResolver(),
5972 Settings.Global.ENABLE_ACCESSIBILITY_GLOBAL_GESTURE_ENABLED, 0) == 1;
5973 }
5974
Craig Mautnereda67292013-04-28 13:50:14 -07005975 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07005976 public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) {
Svetoslav Ganov96179212012-10-10 14:17:45 -07005977 if (!mVibrator.hasVibrator()) {
5978 return false;
5979 }
Christopher Tate5e08af02012-09-21 17:17:22 -07005980 final boolean hapticsDisabled = Settings.System.getIntForUser(mContext.getContentResolver(),
5981 Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) == 0;
Jeff Brown82379ba2014-07-25 19:03:28 -07005982 if (hapticsDisabled && !always) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005983 return false;
5984 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08005985 long[] pattern = null;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005986 switch (effectId) {
5987 case HapticFeedbackConstants.LONG_PRESS:
Amith Yamasanic33cb712010-02-10 15:21:49 -08005988 pattern = mLongPressVibePattern;
5989 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07005990 case HapticFeedbackConstants.VIRTUAL_KEY:
Amith Yamasanic33cb712010-02-10 15:21:49 -08005991 pattern = mVirtualKeyVibePattern;
5992 break;
5993 case HapticFeedbackConstants.KEYBOARD_TAP:
5994 pattern = mKeyboardTapVibePattern;
5995 break;
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07005996 case HapticFeedbackConstants.CLOCK_TICK:
5997 pattern = mClockTickVibePattern;
5998 break;
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07005999 case HapticFeedbackConstants.CALENDAR_DATE:
6000 pattern = mCalendarDateVibePattern;
6001 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006002 case HapticFeedbackConstants.SAFE_MODE_DISABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006003 pattern = mSafeModeDisabledVibePattern;
6004 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006005 case HapticFeedbackConstants.SAFE_MODE_ENABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006006 pattern = mSafeModeEnabledVibePattern;
6007 break;
Amith Yamasanic33cb712010-02-10 15:21:49 -08006008 default:
6009 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006010 }
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006011 int owningUid;
6012 String owningPackage;
6013 if (win != null) {
6014 owningUid = win.getOwningUid();
6015 owningPackage = win.getOwningPackage();
6016 } else {
6017 owningUid = android.os.Process.myUid();
Dianne Hackborn95d78532013-09-11 09:51:14 -07006018 owningPackage = mContext.getOpPackageName();
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006019 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006020 if (pattern.length == 1) {
6021 // One-shot vibration
John Spurlock7b414672014-07-18 13:02:39 -04006022 mVibrator.vibrate(owningUid, owningPackage, pattern[0], VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08006023 } else {
6024 // Pattern vibration
John Spurlock7b414672014-07-18 13:02:39 -04006025 mVibrator.vibrate(owningUid, owningPackage, pattern, -1, VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08006026 }
6027 return true;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006028 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07006029
6030 @Override
6031 public void keepScreenOnStartedLw() {
Daniel Sandler0601eb72011-04-13 01:01:32 -04006032 }
6033
Jeff Brownc38c9be2012-10-04 13:16:19 -07006034 @Override
6035 public void keepScreenOnStoppedLw() {
Jim Millerab954542014-10-10 18:21:49 -07006036 if (isKeyguardShowingAndNotOccluded()) {
Jim Miller25190572013-02-28 17:36:24 -08006037 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006038 }
6039 }
Mike Lockwoodfcb39242009-10-21 23:01:07 -04006040
Dianne Hackborndf89e652011-10-06 22:35:11 -07006041 private int updateSystemUiVisibilityLw() {
Joe Onorato664644d2011-01-23 17:53:23 -08006042 // If there is no window focused, there will be nobody to handle the events
6043 // anyway, so just hang on in whatever state we're in until things settle down.
Adrian Roos53f28ec2014-10-29 17:26:12 +01006044 final WindowState win = mFocusedWindow != null ? mFocusedWindow
6045 : mTopFullscreenOpaqueWindowState;
John Spurlock79da8332013-09-20 12:04:47 -04006046 if (win == null) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006047 return 0;
6048 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01006049 if ((win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 && mHideLockScreen == true) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07006050 // We are updating at a point where the keyguard has gotten
6051 // focus, but we were last in a state where the top window is
6052 // hiding it. This is probably because the keyguard as been
6053 // shown while the top window was displayed, so we want to ignore
6054 // it here because this is just a very transient change and it
6055 // will quickly lose focus once it correctly gets hidden.
6056 return 0;
6057 }
John Spurlock32beb2c2013-03-11 10:16:47 -04006058
John Spurlock1db8b682014-02-18 11:18:59 -05006059 int tmpVisibility = PolicyControl.getSystemUiVisibility(win, null)
Dianne Hackborne26ab702011-10-16 13:21:33 -07006060 & ~mResettingSystemUiFlags
6061 & ~mForceClearedSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04006062 if (mForcingShowNavBar && win.getSurfaceLayer() < mForcingShowNavBarLayer) {
John Spurlockc6d1c602014-01-17 15:22:06 -05006063 tmpVisibility &= ~PolicyControl.adjustClearableFlags(win, View.SYSTEM_UI_CLEARABLE_FLAGS);
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08006064 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01006065 tmpVisibility = updateLightStatusBarLw(tmpVisibility);
John Spurlock79da8332013-09-20 12:04:47 -04006066 final int visibility = updateSystemBarsLw(win, mLastSystemUiFlags, tmpVisibility);
John Spurlockad3e6cb2013-04-30 08:47:43 -04006067 final int diff = visibility ^ mLastSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04006068 final boolean needsMenu = win.getNeedsMenuLw(mTopFullscreenOpaqueWindowState);
Dianne Hackborne0f085d2011-11-30 18:41:15 -08006069 if (diff == 0 && mLastFocusNeedsMenu == needsMenu
John Spurlock79da8332013-09-20 12:04:47 -04006070 && mFocusedApp == win.getAppToken()) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006071 return 0;
6072 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07006073 mLastSystemUiFlags = visibility;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08006074 mLastFocusNeedsMenu = needsMenu;
John Spurlock79da8332013-09-20 12:04:47 -04006075 mFocusedApp = win.getAppToken();
Dianne Hackborndf89e652011-10-06 22:35:11 -07006076 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07006077 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07006078 public void run() {
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006079 try {
6080 IStatusBarService statusbar = getStatusBarService();
6081 if (statusbar != null) {
Adrian Roos53f28ec2014-10-29 17:26:12 +01006082 statusbar.setSystemUiVisibility(visibility, 0xffffffff, win.toString());
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006083 statusbar.topAppWindowChanged(needsMenu);
Joe Onorato664644d2011-01-23 17:53:23 -08006084 }
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006085 } catch (RemoteException e) {
6086 // re-acquire status bar service next time it is needed.
6087 mStatusBarService = null;
Joe Onorato664644d2011-01-23 17:53:23 -08006088 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07006089 }
6090 });
6091 return diff;
Joe Onorato664644d2011-01-23 17:53:23 -08006092 }
6093
Adrian Rooscd3884d2015-02-18 17:25:23 +01006094 private int updateLightStatusBarLw(int vis) {
6095 WindowState statusColorWin = isStatusBarKeyguard() && !mHideLockScreen
6096 ? mStatusBar
6097 : mTopFullscreenOpaqueOrDimmingWindowState;
6098
6099 if (statusColorWin != null) {
6100 if (statusColorWin == mTopFullscreenOpaqueWindowState) {
6101 // If the top fullscreen-or-dimming window is also the top fullscreen, respect
6102 // its light flag.
6103 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6104 vis |= PolicyControl.getSystemUiVisibility(statusColorWin, null)
6105 & View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6106 } else if (statusColorWin != null && statusColorWin.isDimming()) {
6107 // Otherwise if it's dimming, clear the light flag.
6108 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6109 }
6110 }
6111 return vis;
6112 }
6113
John Spurlock79da8332013-09-20 12:04:47 -04006114 private int updateSystemBarsLw(WindowState win, int oldVis, int vis) {
John Spurlockbd957402013-10-03 11:38:39 -04006115 // apply translucent bar vis flags
Jorim Jaggi380ecb82014-03-14 17:25:20 +01006116 WindowState transWin = isStatusBarKeyguard() && !mHideLockScreen
6117 ? mStatusBar
John Spurlockbd957402013-10-03 11:38:39 -04006118 : mTopFullscreenOpaqueWindowState;
6119 vis = mStatusBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
6120 vis = mNavigationBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
6121
John Spurlock27735a42013-08-14 17:57:38 -04006122 // prevent status bar interaction from clearing certain flags
John Spurlock79da8332013-09-20 12:04:47 -04006123 boolean statusBarHasFocus = win.getAttrs().type == TYPE_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04006124 if (statusBarHasFocus && !isStatusBarKeyguard()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04006125 int flags = View.SYSTEM_UI_FLAG_FULLSCREEN
6126 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlockcfc359a2013-09-05 10:42:03 -04006127 | View.SYSTEM_UI_FLAG_IMMERSIVE
Jorim Jaggi73fef8d2015-02-16 17:32:28 +01006128 | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
6129 | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04006130 if (mHideLockScreen) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01006131 flags |= View.STATUS_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSLUCENT;
6132 }
John Spurlockbd957402013-10-03 11:38:39 -04006133 vis = (vis & ~flags) | (oldVis & flags);
John Spurlockad3e6cb2013-04-30 08:47:43 -04006134 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04006135
Adrian Roos4fb3ee32014-08-22 19:29:09 +02006136 if (!areTranslucentBarsAllowed() && transWin != mStatusBar) {
Adrian Roosea562512014-05-05 13:33:03 +02006137 vis &= ~(View.NAVIGATION_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSLUCENT
6138 | View.SYSTEM_UI_TRANSPARENT);
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006139 }
6140
John Spurlock27735a42013-08-14 17:57:38 -04006141 // update status bar
John Spurlockf1a36642013-10-12 17:50:42 -04006142 boolean immersiveSticky =
6143 (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
John Spurlock27735a42013-08-14 17:57:38 -04006144 boolean hideStatusBarWM =
John Spurlockbd957402013-10-03 11:38:39 -04006145 mTopFullscreenOpaqueWindowState != null &&
John Spurlockc6d1c602014-01-17 15:22:06 -05006146 (PolicyControl.getWindowFlags(mTopFullscreenOpaqueWindowState, null)
John Spurlock27735a42013-08-14 17:57:38 -04006147 & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0;
6148 boolean hideStatusBarSysui =
6149 (vis & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04006150 boolean hideNavBarSysui =
6151 (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006152
John Spurlock27735a42013-08-14 17:57:38 -04006153 boolean transientStatusBarAllowed =
6154 mStatusBar != null && (
6155 hideStatusBarWM
John Spurlockf1a36642013-10-12 17:50:42 -04006156 || (hideStatusBarSysui && immersiveSticky)
John Spurlock27735a42013-08-14 17:57:38 -04006157 || statusBarHasFocus);
6158
John Spurlockf1a36642013-10-12 17:50:42 -04006159 boolean transientNavBarAllowed =
6160 mNavigationBar != null &&
6161 hideNavBarSysui && immersiveSticky;
6162
John Spurlockf25706f2013-11-07 18:02:43 -05006163 boolean denyTransientStatus = mStatusBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04006164 && !transientStatusBarAllowed && hideStatusBarSysui;
John Spurlockf25706f2013-11-07 18:02:43 -05006165 boolean denyTransientNav = mNavigationBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04006166 && !transientNavBarAllowed;
6167 if (denyTransientStatus || denyTransientNav) {
John Spurlock27735a42013-08-14 17:57:38 -04006168 // clear the clearable flags instead
John Spurlockf1a36642013-10-12 17:50:42 -04006169 clearClearableFlagsLw();
tiger_huangc58d7562014-10-23 20:24:19 +08006170 vis &= ~View.SYSTEM_UI_CLEARABLE_FLAGS;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006171 }
John Spurlock27735a42013-08-14 17:57:38 -04006172
6173 vis = mStatusBarController.updateVisibilityLw(transientStatusBarAllowed, oldVis, vis);
6174
6175 // update navigation bar
John Spurlockf1a36642013-10-12 17:50:42 -04006176 boolean oldImmersiveMode = isImmersiveMode(oldVis);
6177 boolean newImmersiveMode = isImmersiveMode(vis);
6178 if (win != null && oldImmersiveMode != newImmersiveMode) {
John Spurlock79da8332013-09-20 12:04:47 -04006179 final String pkg = win.getOwningPackage();
Maurice Lam99c6e072014-04-28 18:24:28 -07006180 mImmersiveModeConfirmation.immersiveModeChanged(pkg, newImmersiveMode,
6181 isUserSetupComplete());
John Spurlock34e13d92013-08-10 06:52:28 -04006182 }
John Spurlock27735a42013-08-14 17:57:38 -04006183
John Spurlockf1a36642013-10-12 17:50:42 -04006184 vis = mNavigationBarController.updateVisibilityLw(transientNavBarAllowed, oldVis, vis);
6185
John Spurlocke1f366f2013-08-05 12:22:40 -04006186 return vis;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006187 }
6188
John Spurlockf1a36642013-10-12 17:50:42 -04006189 private void clearClearableFlagsLw() {
6190 int newVal = mResettingSystemUiFlags | View.SYSTEM_UI_CLEARABLE_FLAGS;
6191 if (newVal != mResettingSystemUiFlags) {
6192 mResettingSystemUiFlags = newVal;
6193 mWindowManagerFuncs.reevaluateStatusBarVisibility();
6194 }
6195 }
6196
6197 private boolean isImmersiveMode(int vis) {
6198 final int flags = View.SYSTEM_UI_FLAG_IMMERSIVE | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
John Spurlock34e13d92013-08-10 06:52:28 -04006199 return mNavigationBar != null
6200 && (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0
Daniel Sandler900ece52013-10-18 15:53:27 -04006201 && (vis & flags) != 0
6202 && canHideNavigationBar();
John Spurlock34e13d92013-08-10 06:52:28 -04006203 }
6204
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006205 /**
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04006206 * @return whether the navigation or status bar can be made translucent
6207 *
6208 * This should return true unless touch exploration is not enabled or
6209 * R.boolean.config_enableTranslucentDecor is false.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006210 */
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04006211 private boolean areTranslucentBarsAllowed() {
Svetoslav8e3feb12014-02-24 13:46:47 -08006212 return mTranslucentDecorEnabled
6213 && !mAccessibilityManager.isTouchExplorationEnabled();
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006214 }
6215
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04006216 // Use this instead of checking config_showNavigationBar so that it can be consistently
6217 // overridden by qemu.hw.mainkeys in the emulator.
Craig Mautnereda67292013-04-28 13:50:14 -07006218 @Override
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04006219 public boolean hasNavigationBar() {
6220 return mHasNavigationBar;
6221 }
6222
satok1bc0a492012-04-25 22:47:12 +09006223 @Override
6224 public void setLastInputMethodWindowLw(WindowState ime, WindowState target) {
6225 mLastInputMethodWindow = ime;
6226 mLastInputMethodTargetWindow = target;
6227 }
6228
Craig Mautnerf1b67412012-09-19 13:18:29 -07006229 @Override
Satoshi Kataoka658c7b82013-10-10 17:03:51 +09006230 public int getInputMethodWindowVisibleHeightLw() {
6231 return mDockBottom - mCurBottom;
6232 }
6233
6234 @Override
Craig Mautnerf1b67412012-09-19 13:18:29 -07006235 public void setCurrentUserLw(int newUserId) {
Craig Mautnerd625ab22013-09-06 13:40:31 -07006236 mCurrentUserId = newUserId;
Jim Miller5ecd8112013-01-09 18:50:26 -08006237 if (mKeyguardDelegate != null) {
6238 mKeyguardDelegate.setCurrentUser(newUserId);
Craig Mautnerf1b67412012-09-19 13:18:29 -07006239 }
John Spurlock13451a22012-09-28 14:40:41 -04006240 if (mStatusBarService != null) {
6241 try {
6242 mStatusBarService.setCurrentUser(newUserId);
6243 } catch (RemoteException e) {
6244 // oh well
6245 }
6246 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006247 setLastInputMethodWindowLw(null, null);
Craig Mautnerf1b67412012-09-19 13:18:29 -07006248 }
6249
6250 @Override
Svetoslav Ganov545252f2012-12-10 18:29:24 -08006251 public boolean canMagnifyWindow(int windowType) {
6252 switch (windowType) {
6253 case WindowManager.LayoutParams.TYPE_INPUT_METHOD:
6254 case WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG:
6255 case WindowManager.LayoutParams.TYPE_NAVIGATION_BAR:
6256 case WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY: {
6257 return false;
6258 }
6259 }
6260 return true;
6261 }
6262
6263 @Override
6264 public boolean isTopLevelWindow(int windowType) {
6265 if (windowType >= WindowManager.LayoutParams.FIRST_SUB_WINDOW
6266 && windowType <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
6267 return (windowType == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG);
6268 }
6269 return true;
6270 }
6271
Jim Miller4eeb4f62012-11-08 00:04:29 -08006272 @Override
Jeff Brownd7a04de2012-06-17 14:17:52 -07006273 public void dump(String prefix, PrintWriter pw, String[] args) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006274 pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07006275 pw.print(" mSystemReady="); pw.print(mSystemReady);
6276 pw.print(" mSystemBooted="); pw.println(mSystemBooted);
Jeff Brown2e7760e2012-04-11 15:14:55 -07006277 pw.print(prefix); pw.print("mLidState="); pw.print(mLidState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006278 pw.print(" mLidOpenRotation="); pw.print(mLidOpenRotation);
Michael Wright3818c922014-09-02 13:59:07 -07006279 pw.print(" mCameraLensCoverState="); pw.print(mCameraLensCoverState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006280 pw.print(" mHdmiPlugged="); pw.println(mHdmiPlugged);
Dianne Hackborne26ab702011-10-16 13:21:33 -07006281 if (mLastSystemUiFlags != 0 || mResettingSystemUiFlags != 0
6282 || mForceClearedSystemUiFlags != 0) {
6283 pw.print(prefix); pw.print("mLastSystemUiFlags=0x");
6284 pw.print(Integer.toHexString(mLastSystemUiFlags));
6285 pw.print(" mResettingSystemUiFlags=0x");
6286 pw.print(Integer.toHexString(mResettingSystemUiFlags));
6287 pw.print(" mForceClearedSystemUiFlags=0x");
6288 pw.println(Integer.toHexString(mForceClearedSystemUiFlags));
Dianne Hackborndf89e652011-10-06 22:35:11 -07006289 }
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08006290 if (mLastFocusNeedsMenu) {
6291 pw.print(prefix); pw.print("mLastFocusNeedsMenu=");
6292 pw.println(mLastFocusNeedsMenu);
6293 }
Jeff Browna20dda42014-05-27 20:57:24 -07006294 pw.print(prefix); pw.print("mWakeGestureEnabledSetting=");
6295 pw.println(mWakeGestureEnabledSetting);
6296
Jeff Brownbcdfc622014-03-06 19:13:04 -08006297 pw.print(prefix); pw.print("mSupportAutoRotation="); pw.println(mSupportAutoRotation);
Daniel Sandler6396c722013-04-16 20:19:09 -04006298 pw.print(prefix); pw.print("mUiMode="); pw.print(mUiMode);
6299 pw.print(" mDockMode="); pw.print(mDockMode);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006300 pw.print(" mCarDockRotation="); pw.print(mCarDockRotation);
6301 pw.print(" mDeskDockRotation="); pw.println(mDeskDockRotation);
6302 pw.print(prefix); pw.print("mUserRotationMode="); pw.print(mUserRotationMode);
6303 pw.print(" mUserRotation="); pw.print(mUserRotation);
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05006304 pw.print(" mAllowAllRotations="); pw.println(mAllowAllRotations);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07006305 pw.print(prefix); pw.print("mCurrentAppOrientation="); pw.println(mCurrentAppOrientation);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006306 pw.print(prefix); pw.print("mCarDockEnablesAccelerometer=");
6307 pw.print(mCarDockEnablesAccelerometer);
6308 pw.print(" mDeskDockEnablesAccelerometer=");
6309 pw.println(mDeskDockEnablesAccelerometer);
6310 pw.print(prefix); pw.print("mLidKeyboardAccessibility=");
6311 pw.print(mLidKeyboardAccessibility);
6312 pw.print(" mLidNavigationAccessibility="); pw.print(mLidNavigationAccessibility);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07006313 pw.print(" mLidControlsSleep="); pw.println(mLidControlsSleep);
Jeff Brown6d8fd272014-05-20 21:24:38 -07006314 pw.print(prefix);
6315 pw.print("mShortPressOnPowerBehavior="); pw.print(mShortPressOnPowerBehavior);
6316 pw.print(" mLongPressOnPowerBehavior="); pw.println(mLongPressOnPowerBehavior);
Jeff Brown13f00f02014-10-31 14:45:50 -07006317 pw.print(prefix);
6318 pw.print("mDoublePressOnPowerBehavior="); pw.print(mDoublePressOnPowerBehavior);
6319 pw.print(" mTriplePressOnPowerBehavior="); pw.println(mTriplePressOnPowerBehavior);
Jeff Brown6d8fd272014-05-20 21:24:38 -07006320 pw.print(prefix); pw.print("mHasSoftInput="); pw.println(mHasSoftInput);
Jeff Brown3ee549c2014-09-22 20:14:39 -07006321 pw.print(prefix); pw.print("mAwake="); pw.println(mAwake);
6322 pw.print(prefix); pw.print("mScreenOnEarly="); pw.print(mScreenOnEarly);
6323 pw.print(" mScreenOnFully="); pw.println(mScreenOnFully);
6324 pw.print(prefix); pw.print("mKeyguardDrawComplete="); pw.print(mKeyguardDrawComplete);
6325 pw.print(" mWindowManagerDrawComplete="); pw.println(mWindowManagerDrawComplete);
6326 pw.print(prefix); pw.print("mOrientationSensorEnabled=");
6327 pw.println(mOrientationSensorEnabled);
Dianne Hackbornc652de82013-02-15 16:32:56 -08006328 pw.print(prefix); pw.print("mOverscanScreen=("); pw.print(mOverscanScreenLeft);
6329 pw.print(","); pw.print(mOverscanScreenTop);
6330 pw.print(") "); pw.print(mOverscanScreenWidth);
6331 pw.print("x"); pw.println(mOverscanScreenHeight);
6332 if (mOverscanLeft != 0 || mOverscanTop != 0
6333 || mOverscanRight != 0 || mOverscanBottom != 0) {
6334 pw.print(prefix); pw.print("mOverscan left="); pw.print(mOverscanLeft);
6335 pw.print(" top="); pw.print(mOverscanTop);
6336 pw.print(" right="); pw.print(mOverscanRight);
6337 pw.print(" bottom="); pw.println(mOverscanBottom);
6338 }
Dianne Hackborn313440842013-02-19 19:22:59 -08006339 pw.print(prefix); pw.print("mRestrictedOverscanScreen=(");
6340 pw.print(mRestrictedOverscanScreenLeft);
6341 pw.print(","); pw.print(mRestrictedOverscanScreenTop);
6342 pw.print(") "); pw.print(mRestrictedOverscanScreenWidth);
6343 pw.print("x"); pw.println(mRestrictedOverscanScreenHeight);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006344 pw.print(prefix); pw.print("mUnrestrictedScreen=("); pw.print(mUnrestrictedScreenLeft);
6345 pw.print(","); pw.print(mUnrestrictedScreenTop);
6346 pw.print(") "); pw.print(mUnrestrictedScreenWidth);
6347 pw.print("x"); pw.println(mUnrestrictedScreenHeight);
6348 pw.print(prefix); pw.print("mRestrictedScreen=("); pw.print(mRestrictedScreenLeft);
6349 pw.print(","); pw.print(mRestrictedScreenTop);
6350 pw.print(") "); pw.print(mRestrictedScreenWidth);
6351 pw.print("x"); pw.println(mRestrictedScreenHeight);
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07006352 pw.print(prefix); pw.print("mStableFullscreen=("); pw.print(mStableFullscreenLeft);
6353 pw.print(","); pw.print(mStableFullscreenTop);
6354 pw.print(")-("); pw.print(mStableFullscreenRight);
6355 pw.print(","); pw.print(mStableFullscreenBottom); pw.println(")");
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07006356 pw.print(prefix); pw.print("mStable=("); pw.print(mStableLeft);
6357 pw.print(","); pw.print(mStableTop);
6358 pw.print(")-("); pw.print(mStableRight);
6359 pw.print(","); pw.print(mStableBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07006360 pw.print(prefix); pw.print("mSystem=("); pw.print(mSystemLeft);
6361 pw.print(","); pw.print(mSystemTop);
6362 pw.print(")-("); pw.print(mSystemRight);
6363 pw.print(","); pw.print(mSystemBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006364 pw.print(prefix); pw.print("mCur=("); pw.print(mCurLeft);
6365 pw.print(","); pw.print(mCurTop);
6366 pw.print(")-("); pw.print(mCurRight);
6367 pw.print(","); pw.print(mCurBottom); pw.println(")");
6368 pw.print(prefix); pw.print("mContent=("); pw.print(mContentLeft);
6369 pw.print(","); pw.print(mContentTop);
6370 pw.print(")-("); pw.print(mContentRight);
6371 pw.print(","); pw.print(mContentBottom); pw.println(")");
Dianne Hackborne30e02f2014-05-27 18:24:45 -07006372 pw.print(prefix); pw.print("mVoiceContent=("); pw.print(mVoiceContentLeft);
6373 pw.print(","); pw.print(mVoiceContentTop);
6374 pw.print(")-("); pw.print(mVoiceContentRight);
6375 pw.print(","); pw.print(mVoiceContentBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006376 pw.print(prefix); pw.print("mDock=("); pw.print(mDockLeft);
6377 pw.print(","); pw.print(mDockTop);
6378 pw.print(")-("); pw.print(mDockRight);
6379 pw.print(","); pw.print(mDockBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07006380 pw.print(prefix); pw.print("mDockLayer="); pw.print(mDockLayer);
6381 pw.print(" mStatusBarLayer="); pw.println(mStatusBarLayer);
Dianne Hackborn7ad44382012-10-18 17:46:00 -07006382 pw.print(prefix); pw.print("mShowingLockscreen="); pw.print(mShowingLockscreen);
6383 pw.print(" mShowingDream="); pw.print(mShowingDream);
6384 pw.print(" mDreamingLockscreen="); pw.println(mDreamingLockscreen);
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006385 if (mLastInputMethodWindow != null) {
6386 pw.print(prefix); pw.print("mLastInputMethodWindow=");
6387 pw.println(mLastInputMethodWindow);
6388 }
6389 if (mLastInputMethodTargetWindow != null) {
6390 pw.print(prefix); pw.print("mLastInputMethodTargetWindow=");
6391 pw.println(mLastInputMethodTargetWindow);
6392 }
6393 if (mStatusBar != null) {
6394 pw.print(prefix); pw.print("mStatusBar=");
Dianne Hackbornae6688b2015-02-11 17:02:41 -08006395 pw.print(mStatusBar); pw.print(" isStatusBarKeyguard=");
6396 pw.println(isStatusBarKeyguard());
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006397 }
6398 if (mNavigationBar != null) {
6399 pw.print(prefix); pw.print("mNavigationBar=");
6400 pw.println(mNavigationBar);
6401 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006402 if (mFocusedWindow != null) {
6403 pw.print(prefix); pw.print("mFocusedWindow=");
6404 pw.println(mFocusedWindow);
6405 }
6406 if (mFocusedApp != null) {
6407 pw.print(prefix); pw.print("mFocusedApp=");
6408 pw.println(mFocusedApp);
6409 }
6410 if (mWinDismissingKeyguard != null) {
6411 pw.print(prefix); pw.print("mWinDismissingKeyguard=");
6412 pw.println(mWinDismissingKeyguard);
6413 }
6414 if (mTopFullscreenOpaqueWindowState != null) {
6415 pw.print(prefix); pw.print("mTopFullscreenOpaqueWindowState=");
6416 pw.println(mTopFullscreenOpaqueWindowState);
6417 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01006418 if (mTopFullscreenOpaqueOrDimmingWindowState != null) {
6419 pw.print(prefix); pw.print("mTopFullscreenOpaqueOrDimmingWindowState=");
6420 pw.println(mTopFullscreenOpaqueOrDimmingWindowState);
6421 }
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08006422 if (mForcingShowNavBar) {
6423 pw.print(prefix); pw.print("mForcingShowNavBar=");
6424 pw.println(mForcingShowNavBar); pw.print( "mForcingShowNavBarLayer=");
6425 pw.println(mForcingShowNavBarLayer);
6426 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07006427 pw.print(prefix); pw.print("mTopIsFullscreen="); pw.print(mTopIsFullscreen);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006428 pw.print(" mHideLockScreen="); pw.println(mHideLockScreen);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07006429 pw.print(prefix); pw.print("mForceStatusBar="); pw.print(mForceStatusBar);
6430 pw.print(" mForceStatusBarFromKeyguard=");
6431 pw.println(mForceStatusBarFromKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006432 pw.print(prefix); pw.print("mDismissKeyguard="); pw.print(mDismissKeyguard);
Craig Mautnerad09bcc2012-10-08 13:33:11 -07006433 pw.print(" mWinDismissingKeyguard="); pw.print(mWinDismissingKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006434 pw.print(" mHomePressed="); pw.println(mHomePressed);
6435 pw.print(prefix); pw.print("mAllowLockscreenWhenOn="); pw.print(mAllowLockscreenWhenOn);
6436 pw.print(" mLockScreenTimeout="); pw.print(mLockScreenTimeout);
6437 pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive);
6438 pw.print(prefix); pw.print("mEndcallBehavior="); pw.print(mEndcallBehavior);
6439 pw.print(" mIncallPowerBehavior="); pw.print(mIncallPowerBehavior);
6440 pw.print(" mLongPressOnHomeBehavior="); pw.println(mLongPressOnHomeBehavior);
6441 pw.print(prefix); pw.print("mLandscapeRotation="); pw.print(mLandscapeRotation);
6442 pw.print(" mSeascapeRotation="); pw.println(mSeascapeRotation);
6443 pw.print(prefix); pw.print("mPortraitRotation="); pw.print(mPortraitRotation);
6444 pw.print(" mUpsideDownRotation="); pw.println(mUpsideDownRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07006445 pw.print(prefix); pw.print("mDemoHdmiRotation="); pw.print(mDemoHdmiRotation);
6446 pw.print(" mDemoHdmiRotationLock="); pw.println(mDemoHdmiRotationLock);
6447 pw.print(prefix); pw.print("mUndockedHdmiRotation="); pw.println(mUndockedHdmiRotation);
Jeff Brown600f0032014-05-22 17:06:00 -07006448
Tim Kilbournd7c0c2e2014-05-29 16:08:10 -07006449 mGlobalKeyManager.dump(prefix, pw);
John Spurlock27735a42013-08-14 17:57:38 -04006450 mStatusBarController.dump(pw, prefix);
6451 mNavigationBarController.dump(pw, prefix);
John Spurlockc6d1c602014-01-17 15:22:06 -05006452 PolicyControl.dump(prefix, pw);
Jeff Brown600f0032014-05-22 17:06:00 -07006453
Jeff Browna20dda42014-05-27 20:57:24 -07006454 if (mWakeGestureListener != null) {
6455 mWakeGestureListener.dump(pw, prefix);
6456 }
Jeff Brown600f0032014-05-22 17:06:00 -07006457 if (mOrientationListener != null) {
6458 mOrientationListener.dump(pw, prefix);
6459 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006460 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006461}