blob: 25ca1671e161f67b180dcc3dc9bc3e7ff1e9628d [file] [log] [blame]
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001/*
Jeff Brown37df39a92015-02-25 15:42:31 -08002 * Copyright (C) 2006 The Android Open Source Project
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Jorim Jaggib10e33f2015-02-04 21:57:40 +010017package com.android.server.policy;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080018
Dianne Hackborna4972e92012-03-14 10:38:05 -070019import android.app.ActivityManager;
Jeff Brown061ea992015-04-17 19:55:47 -070020import android.app.ActivityManagerInternal;
21import android.app.ActivityManagerInternal.SleepToken;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080022import android.app.ActivityManagerNative;
Dianne Hackbornc2293022013-02-06 23:14:49 -080023import android.app.AppOpsManager;
Daniel Sandler6396c722013-04-16 20:19:09 -040024import android.app.IUiModeManager;
Dianne Hackborn661cd522011-08-22 00:26:20 -070025import android.app.ProgressDialog;
Jeff Brownde7a8ea2012-06-13 18:28:57 -070026import android.app.SearchManager;
John Spurlock97642182013-07-29 17:58:39 -040027import android.app.StatusBarManager;
Dianne Hackborn78968392010-03-04 20:47:56 -080028import android.app.UiModeManager;
Dianne Hackborn39c2d712009-09-22 11:41:31 -070029import android.content.ActivityNotFoundException;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080030import android.content.BroadcastReceiver;
Daniel Sandler0601eb72011-04-13 01:01:32 -040031import android.content.ComponentName;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080032import android.content.ContentResolver;
33import android.content.Context;
34import android.content.Intent;
Mike Lockwood1753f7f2009-08-24 14:49:07 -070035import android.content.IntentFilter;
Winson Chung9112ec32011-06-27 13:15:32 -070036import android.content.ServiceConnection;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080037import android.content.pm.ActivityInfo;
38import android.content.pm.PackageManager;
Daniel Sandler6396c722013-04-16 20:19:09 -040039import android.content.pm.ResolveInfo;
Dianne Hackborn2f0b1752011-05-31 17:59:49 -070040import android.content.res.CompatibilityInfo;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080041import android.content.res.Configuration;
42import android.content.res.Resources;
Craig Mautner8e4df6c2012-05-23 16:57:23 -070043import android.content.res.TypedArray;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080044import android.database.ContentObserver;
Dianne Hackbornc777e072010-02-12 13:07:59 -080045import android.graphics.PixelFormat;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080046import android.graphics.Rect;
John Spurlock7b414672014-07-18 13:02:39 -040047import android.media.AudioAttributes;
Michael Jurka7a348952012-02-27 13:07:58 -080048import android.media.AudioManager;
John Spurlock61560172015-02-06 19:46:04 -050049import android.media.AudioSystem;
Michael Jurka7a348952012-02-27 13:07:58 -080050import android.media.IAudioService;
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -070051import android.media.Ringtone;
52import android.media.RingtoneManager;
RoboErik8a2cfc32014-05-16 11:19:38 -070053import android.media.session.MediaSessionLegacyHelper;
Dianne Hackborn38e29a62011-09-18 14:43:08 -070054import android.os.Bundle;
Craig Mautner276a6eb2014-11-04 15:32:57 -080055import android.os.Debug;
Jeff Brown9a538ee2012-08-20 14:56:57 -070056import android.os.FactoryTest;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080057import android.os.Handler;
58import android.os.IBinder;
Jeff Brown32cbc38552011-12-01 14:01:49 -080059import android.os.Looper;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -070060import android.os.Message;
61import android.os.Messenger;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080062import android.os.PowerManager;
63import android.os.RemoteException;
64import android.os.ServiceManager;
65import android.os.SystemClock;
66import android.os.SystemProperties;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -080067import android.os.UEventObserver;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -070068import android.os.UserHandle;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080069import android.os.Vibrator;
Michael Wright3818c922014-09-02 13:59:07 -070070import android.provider.MediaStore;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080071import android.provider.Settings;
Jose Lima9546b202014-07-02 17:21:51 -070072import android.service.dreams.DreamManagerInternal;
John Spurlockc8b46ca2013-04-08 12:59:26 -040073import android.service.dreams.DreamService;
74import android.service.dreams.IDreamManager;
Michael Wrightdc63f7b2014-08-21 19:05:21 -070075import android.speech.RecognizerIntent;
Tyler Gunnef9f6f92014-09-12 22:16:17 -070076import android.telecom.TelecomManager;
Dianne Hackborn81e56d52011-05-26 00:55:58 -070077import android.util.DisplayMetrics;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080078import android.util.EventLog;
79import android.util.Log;
Jeff Browna41ca772010-08-11 14:46:32 -070080import android.util.Slog;
Jeff Brown6651a632011-11-28 12:59:11 -080081import android.util.SparseArray;
Dianne Hackbornf87d1962012-04-04 12:48:24 -070082import android.view.Display;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080083import android.view.Gravity;
84import android.view.HapticFeedbackConstants;
Dianne Hackborne0f085d2011-11-30 18:41:15 -080085import android.view.IApplicationToken;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080086import android.view.IWindowManager;
Jeff Browna41ca772010-08-11 14:46:32 -070087import android.view.InputChannel;
Jeff Brown4d396052010-10-29 21:50:21 -070088import android.view.InputDevice;
Jeff Brown4952dfd2011-11-30 19:23:22 -080089import android.view.InputEvent;
Jeff Brown32cbc38552011-12-01 14:01:49 -080090import android.view.InputEventReceiver;
Jeff Brown6b53e8d2010-11-10 16:03:06 -080091import android.view.KeyCharacterMap;
Craig Mautnerae446592012-12-06 19:05:05 -080092import android.view.KeyCharacterMap.FallbackAction;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080093import android.view.KeyEvent;
94import android.view.MotionEvent;
Adam Powell6711f3b2015-05-06 15:57:09 -070095import com.android.internal.policy.PhoneWindow;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080096import android.view.Surface;
97import android.view.View;
98import android.view.ViewConfiguration;
99import android.view.Window;
100import android.view.WindowManager;
Craig Mautnerae446592012-12-06 19:05:05 -0800101import android.view.WindowManagerGlobal;
Craig Mautner8a0da012014-05-31 15:13:37 -0700102import android.view.WindowManagerInternal;
Craig Mautnerae446592012-12-06 19:05:05 -0800103import android.view.WindowManagerPolicy;
Craig Mautnerae446592012-12-06 19:05:05 -0800104import android.view.accessibility.AccessibilityEvent;
Svetoslav8e3feb12014-02-24 13:46:47 -0800105import android.view.accessibility.AccessibilityManager;
Craig Mautnerae446592012-12-06 19:05:05 -0800106import android.view.animation.Animation;
Jorim Jaggi76a16232014-08-08 17:00:47 +0200107import android.view.animation.AnimationSet;
Craig Mautnerae446592012-12-06 19:05:05 -0800108import android.view.animation.AnimationUtils;
Craig Mautnerae446592012-12-06 19:05:05 -0800109import com.android.internal.R;
Craig Mautnerae446592012-12-06 19:05:05 -0800110import com.android.internal.statusbar.IStatusBarService;
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700111import com.android.internal.util.ScreenShapeHelper;
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
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +0000180 static final int SHORT_PRESS_SLEEP_GO_TO_SLEEP = 0;
181 static final int SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME = 1;
182
Dianne Hackborn5cb8d792009-05-21 17:34:15 -0700183 static final int APPLICATION_MEDIA_SUBLAYER = -2;
184 static final int APPLICATION_MEDIA_OVERLAY_SUBLAYER = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800185 static final int APPLICATION_PANEL_SUBLAYER = 1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800186 static final int APPLICATION_SUB_PANEL_SUBLAYER = 2;
Wale Ogunwale0a4dc222015-04-14 12:58:42 -0700187 static final int APPLICATION_ABOVE_SUB_PANEL_SUBLAYER = 3;
Craig Mautner88400d32012-09-30 12:35:45 -0700188
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800189 static public final String SYSTEM_DIALOG_REASON_KEY = "reason";
190 static public final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions";
191 static public final String SYSTEM_DIALOG_REASON_RECENT_APPS = "recentapps";
Joe Onoratof275f0c2009-11-24 16:11:13 -0500192 static public final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey";
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700193 static public final String SYSTEM_DIALOG_REASON_ASSIST = "assist";
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800194
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700195 /**
196 * These are the system UI flags that, when changing, can cause the layout
197 * of the screen to change.
198 */
199 static final int SYSTEM_UI_CHANGING_LAYOUT =
John Spurlocke1f366f2013-08-05 12:22:40 -0400200 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlock7f4820a2013-10-08 12:54:35 -0400201 | View.SYSTEM_UI_FLAG_FULLSCREEN
202 | View.STATUS_BAR_TRANSLUCENT
Adrian Roosea562512014-05-05 13:33:03 +0200203 | View.NAVIGATION_BAR_TRANSLUCENT
204 | View.SYSTEM_UI_TRANSPARENT;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700205
John Spurlock7b414672014-07-18 13:02:39 -0400206 private static final AudioAttributes VIBRATION_ATTRIBUTES = new AudioAttributes.Builder()
207 .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
208 .setUsage(AudioAttributes.USAGE_ASSISTANCE_SONIFICATION)
209 .build();
210
Adrian Roosddc8b272015-05-21 16:28:27 -0700211 // The panic gesture may become active only after the keyguard is dismissed and the immersive
212 // app shows again. If that doesn't happen for 30s we drop the gesture.
213 private static final long PANIC_GESTURE_EXPIRATION = 30000;
214
Jim Miller5ecd8112013-01-09 18:50:26 -0800215 /**
216 * Keyguard stuff
217 */
218 private WindowState mKeyguardScrim;
Jorim Jaggi380ecb82014-03-14 17:25:20 +0100219 private boolean mKeyguardHidden;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700220 private boolean mKeyguardDrawnOnce;
Jim Miller5ecd8112013-01-09 18:50:26 -0800221
Jeff Brown6651a632011-11-28 12:59:11 -0800222 /* Table of Application Launch keys. Maps from key codes to intent categories.
223 *
224 * These are special keys that are used to launch particular kinds of applications,
225 * such as a web browser. HID defines nearly a hundred of them in the Consumer (0x0C)
226 * usage page. We don't support quite that many yet...
227 */
228 static SparseArray<String> sApplicationLaunchKeyCategories;
229 static {
230 sApplicationLaunchKeyCategories = new SparseArray<String>();
231 sApplicationLaunchKeyCategories.append(
232 KeyEvent.KEYCODE_EXPLORER, Intent.CATEGORY_APP_BROWSER);
233 sApplicationLaunchKeyCategories.append(
234 KeyEvent.KEYCODE_ENVELOPE, Intent.CATEGORY_APP_EMAIL);
235 sApplicationLaunchKeyCategories.append(
236 KeyEvent.KEYCODE_CONTACTS, Intent.CATEGORY_APP_CONTACTS);
237 sApplicationLaunchKeyCategories.append(
238 KeyEvent.KEYCODE_CALENDAR, Intent.CATEGORY_APP_CALENDAR);
239 sApplicationLaunchKeyCategories.append(
240 KeyEvent.KEYCODE_MUSIC, Intent.CATEGORY_APP_MUSIC);
241 sApplicationLaunchKeyCategories.append(
242 KeyEvent.KEYCODE_CALCULATOR, Intent.CATEGORY_APP_CALCULATOR);
243 }
244
Craig Mautnerc3daedd2014-09-13 11:17:23 -0700245 /** Amount of time (in milliseconds) to wait for windows drawn before powering on. */
246 static final int WAITING_FOR_DRAWN_TIMEOUT = 1000;
247
Dianne Hackborndf89e652011-10-06 22:35:11 -0700248 /**
249 * Lock protecting internal state. Must not call out into window
250 * manager with lock held. (This lock will be acquired in places
251 * where the window manager is calling in with its own lock held.)
252 */
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800253 private final Object mLock = new Object();
Dianne Hackborndf89e652011-10-06 22:35:11 -0700254
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800255 Context mContext;
256 IWindowManager mWindowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700257 WindowManagerFuncs mWindowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -0700258 WindowManagerInternal mWindowManagerInternal;
Jeff Brown96307042012-07-27 15:51:34 -0700259 PowerManager mPowerManager;
Jeff Brown061ea992015-04-17 19:55:47 -0700260 ActivityManagerInternal mActivityManagerInternal;
Jose Lima9546b202014-07-02 17:21:51 -0700261 DreamManagerInternal mDreamManagerInternal;
Joe Onorato93056472010-09-10 10:30:46 -0400262 IStatusBarService mStatusBarService;
Jeff Browncaca8812013-05-09 13:34:33 -0700263 boolean mPreloadedRecentApps;
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700264 final Object mServiceAquireLock = new Object();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800265 Vibrator mVibrator; // Vibrator for giving feedback of orientation changes
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700266 SearchManager mSearchManager;
Svetoslav8e3feb12014-02-24 13:46:47 -0800267 AccessibilityManager mAccessibilityManager;
Filip Gruszczynskicfb31852015-02-25 21:47:12 +0000268 BurnInProtectionHelper mBurnInProtectionHelper;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800269
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700270 // Vibrator pattern for haptic feedback of a long press.
271 long[] mLongPressVibePattern;
Craig Mautner88400d32012-09-30 12:35:45 -0700272
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700273 // Vibrator pattern for haptic feedback of virtual key press.
274 long[] mVirtualKeyVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700275
Amith Yamasanic33cb712010-02-10 15:21:49 -0800276 // Vibrator pattern for a short vibration.
277 long[] mKeyboardTapVibePattern;
278
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -0700279 // Vibrator pattern for a short vibration when tapping on an hour/minute tick of a Clock.
280 long[] mClockTickVibePattern;
281
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -0700282 // Vibrator pattern for a short vibration when tapping on a day/month/year date of a Calendar.
283 long[] mCalendarDateVibePattern;
284
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700285 // Vibrator pattern for haptic feedback during boot when safe mode is disabled.
286 long[] mSafeModeDisabledVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700287
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700288 // Vibrator pattern for haptic feedback during boot when safe mode is enabled.
289 long[] mSafeModeEnabledVibePattern;
Romain Guy8154cd32010-03-29 14:41:15 -0700290
Mady Mellore8608912015-06-05 09:02:55 -0700291 // Vibrator pattern for haptic feedback of a context click.
292 long[] mContextClickVibePattern;
Mady Mellore82067b2015-04-30 09:58:35 -0700293
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800294 /** If true, hitting shift & menu will broadcast Intent.ACTION_BUG_REPORT */
295 boolean mEnableShiftMenuBugReports = false;
Mike Lockwoodd747dc82011-09-13 16:28:22 -0400296
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800297 boolean mSafeMode;
298 WindowState mStatusBar = null;
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700299 int mStatusBarHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400300 WindowState mNavigationBar = null;
Daniel Sandler36412a72011-08-04 09:35:13 -0400301 boolean mHasNavigationBar = false;
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700302 boolean mCanHideNavigationBar = false;
Daniel Sandler4a066c52012-04-20 14:49:13 -0400303 boolean mNavigationBarCanMove = false; // can the navigation bar ever move to the side?
304 boolean mNavigationBarOnBottom = true; // is the navigation bar on the bottom *right now*?
305 int[] mNavigationBarHeightForRotation = new int[4];
306 int[] mNavigationBarWidthForRotation = new int[4];
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400307
Craig Mautnera631d492014-08-05 15:16:01 -0700308 boolean mBootMessageNeedsHiding;
Jim Miller5ecd8112013-01-09 18:50:26 -0800309 KeyguardServiceDelegate mKeyguardDelegate;
Craig Mautner13f6ea72014-06-23 14:57:02 -0700310 final Runnable mWindowManagerDrawCallback = new Runnable() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700311 @Override
Craig Mautner13f6ea72014-06-23 14:57:02 -0700312 public void run() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700313 if (DEBUG_WAKEUP) Slog.i(TAG, "All windows ready for display!");
314 mHandler.sendEmptyMessage(MSG_WINDOW_MANAGER_DRAWN_COMPLETE);
315 }
316 };
317 final ShowListener mKeyguardDelegateCallback = new ShowListener() {
318 @Override
319 public void onShown(IBinder windowToken) {
320 if (DEBUG_WAKEUP) Slog.d(TAG, "mKeyguardDelegate.ShowListener.onShown.");
321 mHandler.sendEmptyMessage(MSG_KEYGUARD_DRAWN_COMPLETE);
322 }
323 };
324
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800325 GlobalActions mGlobalActions;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800326 Handler mHandler;
satok1bc0a492012-04-25 22:47:12 +0900327 WindowState mLastInputMethodWindow = null;
328 WindowState mLastInputMethodTargetWindow = null;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800329
Jeff Brown13f00f02014-10-31 14:45:50 -0700330 // FIXME This state is shared between the input reader and handler thread.
331 // Technically it's broken and buggy but it has been like this for many years
332 // and we have not yet seen any problems. Someday we'll rewrite this logic
333 // so that only one thread is involved in handling input policy. Unfortunately
334 // it's on a critical path for power management so we can't just post the work to the
335 // handler thread. We'll need to resolve this someday by teaching the input dispatcher
336 // to hold wakelocks during dispatch and eliminating the critical path.
337 volatile boolean mPowerKeyHandled;
Bryce Leed9268e32014-11-17 17:40:59 -0800338 volatile boolean mBeganFromNonInteractive;
Jeff Brown13f00f02014-10-31 14:45:50 -0700339 volatile int mPowerKeyPressCounter;
340 volatile boolean mEndCallKeyHandled;
341
Winson Chungd42a6cf2014-06-03 16:24:04 -0700342 boolean mRecentsVisible;
Winson Chung1e8d71b2014-05-16 17:05:22 -0700343 int mRecentAppsHeldModifiers;
Jeff Browncf39bdf2012-05-18 14:41:19 -0700344 boolean mLanguageSwitchKeyPressed;
Jeff Brown68b909d2011-12-07 16:36:01 -0800345
Jeff Brown2e7760e2012-04-11 15:14:55 -0700346 int mLidState = LID_ABSENT;
Michael Wright3818c922014-09-02 13:59:07 -0700347 int mCameraLensCoverState = CAMERA_LENS_COVER_ABSENT;
Jeff Browndaa37532012-05-01 15:54:03 -0700348 boolean mHaveBuiltInKeyboard;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800349
Dianne Hackbornc777e072010-02-12 13:07:59 -0800350 boolean mSystemReady;
Dianne Hackbornba24e4d2011-09-01 11:17:06 -0700351 boolean mSystemBooted;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800352 boolean mHdmiPlugged;
Jeff Brown4f5fa282014-06-12 19:19:15 -0700353 IUiModeManager mUiModeManager;
Daniel Sandler6396c722013-04-16 20:19:09 -0400354 int mUiMode;
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700355 int mDockMode = Intent.EXTRA_DOCK_STATE_UNDOCKED;
Mike Lockwood1753f7f2009-08-24 14:49:07 -0700356 int mLidOpenRotation;
Mike Lockwood2d1efbd2009-09-16 12:15:53 -0400357 int mCarDockRotation;
358 int mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -0700359 int mUndockedHdmiRotation;
360 int mDemoHdmiRotation;
361 boolean mDemoHdmiRotationLock;
Chong Zhangae6119ff2014-11-11 18:54:39 -0800362 int mDemoRotation;
363 boolean mDemoRotationLock;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400364
Jeff Browna20dda42014-05-27 20:57:24 -0700365 boolean mWakeGestureEnabledSetting;
366 MyWakeGestureListener mWakeGestureListener;
367
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700368 // Default display does not rotate, apps that require non-default orientation will have to
369 // have the orientation emulated.
370 private boolean mForceDefaultOrientation = false;
371
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400372 int mUserRotationMode = WindowManagerPolicy.USER_ROTATION_FREE;
373 int mUserRotation = Surface.ROTATION_0;
Jeff Brown207673cd2012-06-05 17:47:11 -0700374 boolean mAccelerometerDefault;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400375
Jeff Brownbcdfc622014-03-06 19:13:04 -0800376 boolean mSupportAutoRotation;
Jeff Brownd3187e32011-09-21 19:26:44 -0700377 int mAllowAllRotations = -1;
Mike Lockwoode9867d22009-09-20 01:59:02 -0400378 boolean mCarDockEnablesAccelerometer;
379 boolean mDeskDockEnablesAccelerometer;
Dianne Hackborn2862fff2009-09-15 22:56:29 -0700380 int mLidKeyboardAccessibility;
381 int mLidNavigationAccessibility;
Jeff Brownc458ce92012-04-30 14:58:40 -0700382 boolean mLidControlsSleep;
Jeff Brown13f00f02014-10-31 14:45:50 -0700383 int mShortPressOnPowerBehavior;
384 int mLongPressOnPowerBehavior;
385 int mDoublePressOnPowerBehavior;
386 int mTriplePressOnPowerBehavior;
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +0000387 int mShortPressOnSleepBehavior;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700388 boolean mAwake;
389 boolean mScreenOnEarly;
390 boolean mScreenOnFully;
391 ScreenOnListener mScreenOnListener;
392 boolean mKeyguardDrawComplete;
393 boolean mWindowManagerDrawComplete;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800394 boolean mOrientationSensorEnabled = false;
395 int mCurrentAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800396 boolean mHasSoftInput = false;
Daniel Sandlerdd73ee42013-10-11 22:19:59 -0400397 boolean mTranslucentDecorEnabled = true;
RoboErik001c59c2015-01-26 15:53:51 -0800398 boolean mUseTvRouting;
Craig Mautner967212c2013-04-13 21:10:58 -0700399
Jeff Brown70825162012-03-28 17:27:48 -0700400 int mPointerLocationMode = 0; // guarded by mLock
Joe Onorato664644d2011-01-23 17:53:23 -0800401
402 // The last window we were told about in focusChanged.
403 WindowState mFocusedWindow;
Dianne Hackborne0f085d2011-11-30 18:41:15 -0800404 IApplicationToken mFocusedApp;
Joe Onorato664644d2011-01-23 17:53:23 -0800405
Jeff Brown70825162012-03-28 17:27:48 -0700406 PointerLocationView mPointerLocationView;
Jeff Brown32cbc38552011-12-01 14:01:49 -0800407
Dianne Hackbornc652de82013-02-15 16:32:56 -0800408 // The current size of the screen; really; extends into the overscan area of
409 // the screen and doesn't account for any system elements like the status bar.
410 int mOverscanScreenLeft, mOverscanScreenTop;
411 int mOverscanScreenWidth, mOverscanScreenHeight;
412 // The current visible size of the screen; really; (ir)regardless of whether the status
413 // bar can be hidden but not extending into the overscan area.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800414 int mUnrestrictedScreenLeft, mUnrestrictedScreenTop;
415 int mUnrestrictedScreenWidth, mUnrestrictedScreenHeight;
Dianne Hackborn313440842013-02-19 19:22:59 -0800416 // Like mOverscanScreen*, but allowed to move into the overscan region where appropriate.
417 int mRestrictedOverscanScreenLeft, mRestrictedOverscanScreenTop;
418 int mRestrictedOverscanScreenWidth, mRestrictedOverscanScreenHeight;
Dianne Hackborn82de1ae2010-10-28 11:28:39 -0700419 // The current size of the screen; these may be different than (0,0)-(dw,dh)
420 // if the status bar can't be hidden; in that case it effectively carves out
421 // that area of the display from all other windows.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800422 int mRestrictedScreenLeft, mRestrictedScreenTop;
423 int mRestrictedScreenWidth, mRestrictedScreenHeight;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700424 // During layout, the current screen borders accounting for any currently
425 // visible system UI elements.
426 int mSystemLeft, mSystemTop, mSystemRight, mSystemBottom;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700427 // For applications requesting stable content insets, these are them.
428 int mStableLeft, mStableTop, mStableRight, mStableBottom;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -0700429 // For applications requesting stable content insets but have also set the
430 // fullscreen window flag, these are the stable dimensions without the status bar.
431 int mStableFullscreenLeft, mStableFullscreenTop;
432 int mStableFullscreenRight, mStableFullscreenBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800433 // During layout, the current screen borders with all outer decoration
434 // (status bar, input method dock) accounted for.
435 int mCurLeft, mCurTop, mCurRight, mCurBottom;
436 // During layout, the frame in which content should be displayed
437 // to the user, accounting for all screen decoration except for any
438 // space they deem as available for other content. This is usually
439 // the same as mCur*, but may be larger if the screen decor has supplied
440 // content insets.
441 int mContentLeft, mContentTop, mContentRight, mContentBottom;
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700442 // During layout, the frame in which voice content should be displayed
443 // to the user, accounting for all screen decoration except for any
444 // space they deem as available for other content.
445 int mVoiceContentLeft, mVoiceContentTop, mVoiceContentRight, mVoiceContentBottom;
Dianne Hackborn8e11ef02010-11-18 19:47:42 -0800446 // During layout, the current screen borders along which input method
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800447 // windows are placed.
448 int mDockLeft, mDockTop, mDockRight, mDockBottom;
449 // During layout, the layer at which the doc window is placed.
450 int mDockLayer;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700451 // During layout, this is the layer of the status bar.
452 int mStatusBarLayer;
Dianne Hackborne26ab702011-10-16 13:21:33 -0700453 int mLastSystemUiFlags;
454 // Bits that we are in the process of clearing, so we want to prevent
455 // them from being set by applications until everything has been updated
456 // to have them clear.
457 int mResettingSystemUiFlags = 0;
458 // Bits that we are currently always keeping cleared.
459 int mForceClearedSystemUiFlags = 0;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -0800460 // What we last reported to system UI about whether the compatibility
461 // menu needs to be displayed.
462 boolean mLastFocusNeedsMenu = false;
Adrian Roosddc8b272015-05-21 16:28:27 -0700463 // If nonzero, a panic gesture was performed at that time in uptime millis and is still pending.
464 private long mPendingPanicGestureUptime;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700465
Selim Cinekf83e8242015-05-19 18:08:14 -0700466 InputConsumer mInputConsumer = null;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700467
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800468 static final Rect mTmpParentFrame = new Rect();
469 static final Rect mTmpDisplayFrame = new Rect();
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800470 static final Rect mTmpOverscanFrame = new Rect();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800471 static final Rect mTmpContentFrame = new Rect();
472 static final Rect mTmpVisibleFrame = new Rect();
John Spurlock46646232013-09-30 22:32:42 -0400473 static final Rect mTmpDecorFrame = new Rect();
Adrian Roosfa104232014-06-20 16:10:14 -0700474 static final Rect mTmpStableFrame = new Rect();
Dianne Hackborn1f903c32011-09-13 19:18:06 -0700475 static final Rect mTmpNavigationFrame = new Rect();
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700476 static final Rect mTmpOutsetFrame = new Rect();
Craig Mautner967212c2013-04-13 21:10:58 -0700477
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800478 WindowState mTopFullscreenOpaqueWindowState;
Adrian Rooscd3884d2015-02-18 17:25:23 +0100479 WindowState mTopFullscreenOpaqueOrDimmingWindowState;
Craig Mautner2bc789b2014-03-19 19:48:38 -0700480 HashSet<IApplicationToken> mAppsToBeHidden = new HashSet<IApplicationToken>();
Jorim Jaggic13fcac2014-09-11 17:36:57 +0200481 HashSet<IApplicationToken> mAppsThatDismissKeyguard = new HashSet<IApplicationToken>();
Joe Onorato93056472010-09-10 10:30:46 -0400482 boolean mTopIsFullscreen;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800483 boolean mForceStatusBar;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -0700484 boolean mForceStatusBarFromKeyguard;
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -0700485 private boolean mForceStatusBarTransparent;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700486 boolean mHideLockScreen;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -0800487 boolean mForcingShowNavBar;
488 int mForcingShowNavBarLayer;
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700489
490 // States of keyguard dismiss.
491 private static final int DISMISS_KEYGUARD_NONE = 0; // Keyguard not being dismissed.
492 private static final int DISMISS_KEYGUARD_START = 1; // Keyguard needs to be dismissed.
493 private static final int DISMISS_KEYGUARD_CONTINUE = 2; // Keyguard has been dismissed.
494 int mDismissKeyguard = DISMISS_KEYGUARD_NONE;
495
496 /** The window that is currently dismissing the keyguard. Dismissing the keyguard must only
497 * be done once per window. */
498 private WindowState mWinDismissingKeyguard;
499
tingna_sunge785ffa2015-05-12 13:23:15 +0800500 /** When window is currently dismissing the keyguard, dismissing the keyguard must handle
501 * the keygaurd secure state change instantly case, e.g. the use case of inserting a PIN
502 * lock SIM card. This variable is used to record the previous keyguard secure state for
503 * monitoring secure state change on window dismissing keyguard. */
504 private boolean mSecureDismissingKeyguard;
505
Craig Mautnerc9457fa2014-06-06 14:27:48 -0700506 /** The window that is currently showing "over" the keyguard. If there is an app window
507 * belonging to another app on top of this the keyguard shows. If there is a fullscreen
508 * app window under this, still dismiss the keyguard but don't show the app underneath. Show
509 * the wallpaper. */
510 private WindowState mWinShowWhenLocked;
511
Dianne Hackborn7ad44382012-10-18 17:46:00 -0700512 boolean mShowingLockscreen;
513 boolean mShowingDream;
514 boolean mDreamingLockscreen;
Jeff Brown061ea992015-04-17 19:55:47 -0700515 boolean mDreamingSleepTokenNeeded;
516 SleepToken mDreamingSleepToken;
Jeff Brown48d1b142015-06-10 16:36:03 -0700517 SleepToken mScreenOffSleepToken;
Jim Millerab954542014-10-10 18:21:49 -0700518 boolean mKeyguardSecure;
519 boolean mKeyguardSecureIncludingHidden;
520 volatile boolean mKeyguardOccluded;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800521 boolean mHomePressed;
Jeff Browncaca8812013-05-09 13:34:33 -0700522 boolean mHomeConsumed;
523 boolean mHomeDoubleTapPending;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800524 Intent mHomeIntent;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700525 Intent mCarDockIntent;
526 Intent mDeskDockIntent;
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700527 boolean mSearchKeyShortcutPending;
528 boolean mConsumeSearchKeyUp;
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700529 boolean mAssistKeyLongPressed;
Michael Wright6a62e552014-06-03 19:19:48 -0700530 boolean mPendingMetaAction;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800531
Mike Lockwood28569302010-01-28 11:54:40 -0500532 // support for activating the lock screen while the screen is on
533 boolean mAllowLockscreenWhenOn;
534 int mLockScreenTimeout;
535 boolean mLockScreenTimerActive;
536
David Brownbaf8d092010-03-08 21:52:59 -0800537 // Behavior of ENDCALL Button. (See Settings.System.END_BUTTON_BEHAVIOR.)
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800538 int mEndcallBehavior;
David Brownbaf8d092010-03-08 21:52:59 -0800539
540 // Behavior of POWER button while in-call and screen on.
541 // (See Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR.)
542 int mIncallPowerBehavior;
543
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700544 Display mDisplay;
545
Dianne Hackborn9d132642011-04-21 17:26:39 -0700546 int mLandscapeRotation = 0; // default landscape rotation
547 int mSeascapeRotation = 0; // "other" landscape rotation, 180 degrees from mLandscapeRotation
548 int mPortraitRotation = 0; // default portrait rotation
549 int mUpsideDownRotation = 0; // "other" portrait rotation
Mitsuru Oshima831d0d92009-06-16 18:27:18 -0700550
Dianne Hackbornc652de82013-02-15 16:32:56 -0800551 int mOverscanLeft = 0;
552 int mOverscanTop = 0;
553 int mOverscanRight = 0;
554 int mOverscanBottom = 0;
555
Joe Onorato46b0d682010-11-22 17:37:27 -0800556 // What we do when the user long presses on home
Jeff Browncaca8812013-05-09 13:34:33 -0700557 private int mLongPressOnHomeBehavior;
558
559 // What we do when the user double-taps on home
560 private int mDoubleTapOnHomeBehavior;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800561
Bryce Lee584a4452014-10-21 15:55:55 -0700562 // Allowed theater mode wake actions
563 private boolean mAllowTheaterModeWakeFromKey;
564 private boolean mAllowTheaterModeWakeFromPowerKey;
565 private boolean mAllowTheaterModeWakeFromMotion;
Bryce Lee812d7022014-11-10 13:33:28 -0800566 private boolean mAllowTheaterModeWakeFromMotionWhenNotDreaming;
Bryce Lee584a4452014-10-21 15:55:55 -0700567 private boolean mAllowTheaterModeWakeFromCameraLens;
568 private boolean mAllowTheaterModeWakeFromLidSwitch;
569 private boolean mAllowTheaterModeWakeFromWakeGesture;
570
Bryce Leed3b28402015-03-09 15:49:13 +0000571 // Whether to support long press from power button in non-interactive mode
572 private boolean mSupportLongPressPowerWhenNonInteractive;
573
Bryce Lee55e846d2014-11-04 12:43:44 -0800574 // Whether to go to sleep entering theater mode from power button
575 private boolean mGoToSleepOnButtonPressTheaterMode;
576
Winson Chung9112ec32011-06-27 13:15:32 -0700577 // Screenshot trigger states
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700578 // Time to volume and power must be pressed within this interval of each other.
579 private static final long SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS = 150;
Winson Chung1cea2f32012-10-08 20:42:01 -0700580 // Increase the chord delay when taking a screenshot from the keyguard
581 private static final float KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER = 2.5f;
Christopher Tatee90585f2012-03-05 18:56:25 -0800582 private boolean mScreenshotChordEnabled;
Jeff Brown13f00f02014-10-31 14:45:50 -0700583 private boolean mScreenshotChordVolumeDownKeyTriggered;
584 private long mScreenshotChordVolumeDownKeyTime;
585 private boolean mScreenshotChordVolumeDownKeyConsumed;
586 private boolean mScreenshotChordVolumeUpKeyTriggered;
587 private boolean mScreenshotChordPowerKeyTriggered;
588 private long mScreenshotChordPowerKeyTime;
Winson Chung9112ec32011-06-27 13:15:32 -0700589
Michael Wrightb854e242013-02-05 17:54:02 -0800590 /* The number of steps between min and max brightness */
591 private static final int BRIGHTNESS_STEPS = 10;
592
Christopher Tate5e08af02012-09-21 17:17:22 -0700593 SettingsObserver mSettingsObserver;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800594 ShortcutManager mShortcutManager;
595 PowerManager.WakeLock mBroadcastWakeLock;
Jeff Brown13f00f02014-10-31 14:45:50 -0700596 PowerManager.WakeLock mPowerKeyWakeLock;
Jeff Brown40013652012-05-16 21:22:36 -0700597 boolean mHavePendingMediaKeyRepeatWithWakeLock;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800598
Craig Mautnerd625ab22013-09-06 13:40:31 -0700599 private int mCurrentUserId;
600
Justin Kohd378ad72013-04-01 12:18:26 -0700601 // Maps global key codes to the components that will handle them.
602 private GlobalKeyManager mGlobalKeyManager;
603
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700604 // Fallback actions by key code.
605 private final SparseArray<KeyCharacterMap.FallbackAction> mFallbackActions =
606 new SparseArray<KeyCharacterMap.FallbackAction>();
Jeff Brown49ed71d2010-12-06 17:13:33 -0800607
Jorim Jaggi76a16232014-08-08 17:00:47 +0200608 private final LogDecelerateInterpolator mLogDecelerateInterpolator
609 = new LogDecelerateInterpolator(100, 0);
610
Jeff Brown70825162012-03-28 17:27:48 -0700611 private static final int MSG_ENABLE_POINTER_LOCATION = 1;
612 private static final int MSG_DISABLE_POINTER_LOCATION = 2;
Jeff Brown40013652012-05-16 21:22:36 -0700613 private static final int MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK = 3;
614 private static final int MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK = 4;
Craig Mautner8a0da012014-05-31 15:13:37 -0700615 private static final int MSG_KEYGUARD_DRAWN_COMPLETE = 5;
616 private static final int MSG_KEYGUARD_DRAWN_TIMEOUT = 6;
617 private static final int MSG_WINDOW_MANAGER_DRAWN_COMPLETE = 7;
Craig Mautner84984fa2014-06-19 11:19:20 -0700618 private static final int MSG_DISPATCH_SHOW_RECENTS = 9;
Alan Viverettee34560b22014-07-10 14:50:06 -0700619 private static final int MSG_DISPATCH_SHOW_GLOBAL_ACTIONS = 10;
Craig Mautnera631d492014-08-05 15:16:01 -0700620 private static final int MSG_HIDE_BOOT_MESSAGE = 11;
Michael Wright869a67c2014-08-26 19:33:06 -0700621 private static final int MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK = 12;
Jeff Brown13f00f02014-10-31 14:45:50 -0700622 private static final int MSG_POWER_DELAYED_PRESS = 13;
623 private static final int MSG_POWER_LONG_PRESS = 14;
Jeff Brown061ea992015-04-17 19:55:47 -0700624 private static final int MSG_UPDATE_DREAMING_SLEEP_TOKEN = 15;
Jeff Brown70825162012-03-28 17:27:48 -0700625
626 private class PolicyHandler extends Handler {
627 @Override
628 public void handleMessage(Message msg) {
629 switch (msg.what) {
630 case MSG_ENABLE_POINTER_LOCATION:
631 enablePointerLocation();
632 break;
633 case MSG_DISABLE_POINTER_LOCATION:
634 disablePointerLocation();
635 break;
Jeff Brown40013652012-05-16 21:22:36 -0700636 case MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK:
637 dispatchMediaKeyWithWakeLock((KeyEvent)msg.obj);
638 break;
639 case MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK:
640 dispatchMediaKeyRepeatWithWakeLock((KeyEvent)msg.obj);
641 break;
Craig Mautner84984fa2014-06-19 11:19:20 -0700642 case MSG_DISPATCH_SHOW_RECENTS:
643 showRecentApps(false);
644 break;
Alan Viverettee34560b22014-07-10 14:50:06 -0700645 case MSG_DISPATCH_SHOW_GLOBAL_ACTIONS:
646 showGlobalActionsInternal();
647 break;
Craig Mautner8a0da012014-05-31 15:13:37 -0700648 case MSG_KEYGUARD_DRAWN_COMPLETE:
649 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mKeyguardDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700650 finishKeyguardDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700651 break;
652 case MSG_KEYGUARD_DRAWN_TIMEOUT:
653 Slog.w(TAG, "Keyguard drawn timeout. Setting mKeyguardDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700654 finishKeyguardDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700655 break;
656 case MSG_WINDOW_MANAGER_DRAWN_COMPLETE:
657 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mWindowManagerDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700658 finishWindowsDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700659 break;
Craig Mautnera631d492014-08-05 15:16:01 -0700660 case MSG_HIDE_BOOT_MESSAGE:
661 handleHideBootMessage();
662 break;
Michael Wright869a67c2014-08-26 19:33:06 -0700663 case MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK:
664 launchVoiceAssistWithWakeLock(msg.arg1 != 0);
665 break;
Jeff Brown13f00f02014-10-31 14:45:50 -0700666 case MSG_POWER_DELAYED_PRESS:
667 powerPress((Long)msg.obj, msg.arg1 != 0, msg.arg2);
668 finishPowerKeyPress();
669 break;
670 case MSG_POWER_LONG_PRESS:
671 powerLongPress();
672 break;
Jeff Brown061ea992015-04-17 19:55:47 -0700673 case MSG_UPDATE_DREAMING_SLEEP_TOKEN:
674 updateDreamingSleepToken(msg.arg1 != 0);
675 break;
Jeff Brown70825162012-03-28 17:27:48 -0700676 }
677 }
678 }
679
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800680 private UEventObserver mHDMIObserver = new UEventObserver() {
681 @Override
682 public void onUEvent(UEventObserver.UEvent event) {
683 setHdmiPlugged("1".equals(event.get("SWITCH_STATE")));
684 }
685 };
686
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800687 class SettingsObserver extends ContentObserver {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800688 SettingsObserver(Handler handler) {
689 super(handler);
690 }
David Brownbaf8d092010-03-08 21:52:59 -0800691
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800692 void observe() {
Christopher Tate5e08af02012-09-21 17:17:22 -0700693 // Observe all users' changes
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800694 ContentResolver resolver = mContext.getContentResolver();
695 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700696 Settings.System.END_BUTTON_BEHAVIOR), false, this,
697 UserHandle.USER_ALL);
David Brownbaf8d092010-03-08 21:52:59 -0800698 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700699 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR), false, this,
700 UserHandle.USER_ALL);
Jeff Browna20dda42014-05-27 20:57:24 -0700701 resolver.registerContentObserver(Settings.Secure.getUriFor(
702 Settings.Secure.WAKE_GESTURE_ENABLED), false, this,
703 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800704 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700705 Settings.System.ACCELEROMETER_ROTATION), false, this,
706 UserHandle.USER_ALL);
Mike Lockwood28569302010-01-28 11:54:40 -0500707 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700708 Settings.System.USER_ROTATION), false, this,
709 UserHandle.USER_ALL);
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400710 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700711 Settings.System.SCREEN_OFF_TIMEOUT), false, this,
712 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800713 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700714 Settings.System.POINTER_LOCATION), false, this,
715 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800716 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700717 Settings.Secure.DEFAULT_INPUT_METHOD), false, this,
718 UserHandle.USER_ALL);
John Spurlockd9b70bd2014-02-06 17:02:44 -0500719 resolver.registerContentObserver(Settings.Secure.getUriFor(
John Spurlockf1a36642013-10-12 17:50:42 -0400720 Settings.Secure.IMMERSIVE_MODE_CONFIRMATIONS), false, this,
Christopher Tate5e08af02012-09-21 17:17:22 -0700721 UserHandle.USER_ALL);
John Spurlockc6d1c602014-01-17 15:22:06 -0500722 resolver.registerContentObserver(Settings.Global.getUriFor(
723 Settings.Global.POLICY_CONTROL), false, this,
724 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800725 updateSettings();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800726 }
727
728 @Override public void onChange(boolean selfChange) {
Dianne Hackbornc777e072010-02-12 13:07:59 -0800729 updateSettings();
Jeff Brown01a98dd2011-09-20 15:08:29 -0700730 updateRotation(false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800731 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800732 }
Craig Mautner967212c2013-04-13 21:10:58 -0700733
Jeff Browna20dda42014-05-27 20:57:24 -0700734 class MyWakeGestureListener extends WakeGestureListener {
735 MyWakeGestureListener(Context context, Handler handler) {
736 super(context, handler);
737 }
738
739 @Override
740 public void onWakeUp() {
741 synchronized (mLock) {
742 if (shouldEnableWakeGestureLp()) {
Jeff Browne07b94b2014-06-18 15:56:27 -0700743 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
Bryce Lee584a4452014-10-21 15:55:55 -0700744 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromWakeGesture);
Jeff Browna20dda42014-05-27 20:57:24 -0700745 }
746 }
747 }
748 }
749
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800750 class MyOrientationListener extends WindowOrientationListener {
Craig Mautnereee29c42013-01-17 14:44:34 -0800751 MyOrientationListener(Context context, Handler handler) {
752 super(context, handler);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800753 }
Craig Mautner967212c2013-04-13 21:10:58 -0700754
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800755 @Override
Jeff Brownc0347aa2011-09-23 17:26:09 -0700756 public void onProposedRotationChanged(int rotation) {
Craig Mautnereda67292013-04-28 13:50:14 -0700757 if (localLOGV) Slog.v(TAG, "onProposedRotationChanged, rotation=" + rotation);
Jeff Brown01a98dd2011-09-20 15:08:29 -0700758 updateRotation(false);
759 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800760 }
761 MyOrientationListener mOrientationListener;
762
Jorim Jaggi24bec7c2015-02-04 12:40:14 +0100763 private final StatusBarController mStatusBarController = new StatusBarController();
John Spurlock5b9145b2013-08-20 15:13:47 -0400764
John Spurlock27735a42013-08-14 17:57:38 -0400765 private final BarController mNavigationBarController = new BarController("NavigationBar",
John Spurlock5b9145b2013-08-20 15:13:47 -0400766 View.NAVIGATION_BAR_TRANSIENT,
767 View.NAVIGATION_BAR_UNHIDE,
John Spurlockbd957402013-10-03 11:38:39 -0400768 View.NAVIGATION_BAR_TRANSLUCENT,
769 StatusBarManager.WINDOW_NAVIGATION_BAR,
770 WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
John Spurlock5b9145b2013-08-20 15:13:47 -0400771
John Spurlockf1a36642013-10-12 17:50:42 -0400772 private ImmersiveModeConfirmation mImmersiveModeConfirmation;
John Spurlock32beb2c2013-03-11 10:16:47 -0400773
Craig Mautner037aa8d2013-06-07 10:35:44 -0700774 private SystemGesturesPointerEventListener mSystemGestures;
John Spurlock32beb2c2013-03-11 10:16:47 -0400775
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700776 IStatusBarService getStatusBarService() {
777 synchronized (mServiceAquireLock) {
778 if (mStatusBarService == null) {
779 mStatusBarService = IStatusBarService.Stub.asInterface(
780 ServiceManager.getService("statusbar"));
781 }
782 return mStatusBarService;
783 }
784 }
785
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700786 /*
787 * We always let the sensor be switched on by default except when
788 * the user has explicitly disabled sensor based rotation or when the
789 * screen is switched off.
790 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700791 boolean needSensorRunningLp() {
Jeff Brownbcdfc622014-03-06 19:13:04 -0800792 if (mSupportAutoRotation) {
793 if (mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
794 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
795 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT
796 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) {
797 // If the application has explicitly requested to follow the
798 // orientation, then we need to turn the sensor on.
799 return true;
800 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800801 }
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700802 if ((mCarDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_CAR) ||
Jeff Brown1a693182011-11-08 14:44:16 -0800803 (mDeskDockEnablesAccelerometer && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
804 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
805 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK))) {
Mike Lockwoode9867d22009-09-20 01:59:02 -0400806 // enable accelerometer if we are docked in a dock that enables accelerometer
807 // orientation management,
808 return true;
809 }
Jeff Brown207673cd2012-06-05 17:47:11 -0700810 if (mUserRotationMode == USER_ROTATION_LOCKED) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800811 // If the setting for using the sensor by default is enabled, then
812 // we will always leave it on. Note that the user could go to
813 // a window that forces an orientation that does not use the
814 // sensor and in theory we could turn it off... however, when next
815 // turning it on we won't have a good value for the current
816 // orientation for a little bit, which can cause orientation
817 // changes to lag, so we'd like to keep it always on. (It will
818 // still be turned off when the screen is off.)
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700819 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800820 }
Jeff Brownbcdfc622014-03-06 19:13:04 -0800821 return mSupportAutoRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800822 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700823
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800824 /*
825 * Various use cases for invoking this function
826 * screen turning off, should always disable listeners if already enabled
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700827 * screen turned on and current app has sensor based orientation, enable listeners
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800828 * if not already enabled
829 * screen turned on and current app does not have sensor orientation, disable listeners if
830 * already enabled
831 * screen turning on and current app has sensor based orientation, enable listeners if needed
832 * screen turning on and current app has nosensor based orientation, do nothing
833 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700834 void updateOrientationListenerLp() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800835 if (!mOrientationListener.canDetectOrientation()) {
836 // If sensor is turned off or nonexistent for some reason
837 return;
838 }
839 //Could have been invoked due to screen turning on or off or
840 //change of the currently visible window's orientation
Jeff Brown3ee549c2014-09-22 20:14:39 -0700841 if (localLOGV) Slog.v(TAG, "mScreenOnEarly=" + mScreenOnEarly
842 + ", mAwake=" + mAwake + ", mCurrentAppOrientation=" + mCurrentAppOrientation
843 + ", mOrientationSensorEnabled=" + mOrientationSensorEnabled);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800844 boolean disable = true;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700845 if (mScreenOnEarly && mAwake) {
The Android Open Source Project0727d222009-03-11 12:11:58 -0700846 if (needSensorRunningLp()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800847 disable = false;
848 //enable listener if not already enabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700849 if (!mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800850 mOrientationListener.enable();
Craig Mautnereda67292013-04-28 13:50:14 -0700851 if(localLOGV) Slog.v(TAG, "Enabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800852 mOrientationSensorEnabled = true;
853 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700854 }
855 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800856 //check if sensors need to be disabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700857 if (disable && mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800858 mOrientationListener.disable();
Craig Mautnereda67292013-04-28 13:50:14 -0700859 if(localLOGV) Slog.v(TAG, "Disabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800860 mOrientationSensorEnabled = false;
861 }
862 }
863
Jeff Brown13f00f02014-10-31 14:45:50 -0700864 private void interceptPowerKeyDown(KeyEvent event, boolean interactive) {
865 // Hold a wake lock until the power key is released.
866 if (!mPowerKeyWakeLock.isHeld()) {
867 mPowerKeyWakeLock.acquire();
868 }
869
870 // Cancel multi-press detection timeout.
871 if (mPowerKeyPressCounter != 0) {
872 mHandler.removeMessages(MSG_POWER_DELAYED_PRESS);
873 }
874
875 // Detect user pressing the power button in panic when an application has
876 // taken over the whole screen.
877 boolean panic = mImmersiveModeConfirmation.onPowerKeyDown(interactive,
Craig Mautner0124980e92014-11-30 21:15:34 -0800878 SystemClock.elapsedRealtime(), isImmersiveMode(mLastSystemUiFlags));
Jeff Brown13f00f02014-10-31 14:45:50 -0700879 if (panic) {
Adrian Roosddc8b272015-05-21 16:28:27 -0700880 mHandler.post(mHiddenNavPanic);
Jeff Brown13f00f02014-10-31 14:45:50 -0700881 }
882
883 // Latch power key state to detect screenshot chord.
884 if (interactive && !mScreenshotChordPowerKeyTriggered
885 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
886 mScreenshotChordPowerKeyTriggered = true;
887 mScreenshotChordPowerKeyTime = event.getDownTime();
888 interceptScreenshotChord();
889 }
890
891 // Stop ringing or end call if configured to do so when power is pressed.
892 TelecomManager telecomManager = getTelecommService();
893 boolean hungUp = false;
894 if (telecomManager != null) {
895 if (telecomManager.isRinging()) {
896 // Pressing Power while there's a ringing incoming
897 // call should silence the ringer.
898 telecomManager.silenceRinger();
899 } else if ((mIncallPowerBehavior
900 & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0
901 && telecomManager.isInCall() && interactive) {
902 // Otherwise, if "Power button ends call" is enabled,
903 // the Power button will hang up any current active call.
904 hungUp = telecomManager.endCall();
905 }
906 }
907
908 // If the power key has still not yet been handled, then detect short
909 // press, long press, or multi press and decide what to do.
910 mPowerKeyHandled = hungUp || mScreenshotChordVolumeDownKeyTriggered
911 || mScreenshotChordVolumeUpKeyTriggered;
912 if (!mPowerKeyHandled) {
913 if (interactive) {
914 // When interactive, we're already awake.
915 // Wait for a long press or for the button to be released to decide what to do.
916 if (hasLongPressOnPowerBehavior()) {
917 Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS);
918 msg.setAsynchronous(true);
919 mHandler.sendMessageDelayed(msg,
920 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
921 }
922 } else {
Bryce Leed9268e32014-11-17 17:40:59 -0800923 wakeUpFromPowerKey(event.getDownTime());
Bryce Leed9268e32014-11-17 17:40:59 -0800924
Bryce Leed3b28402015-03-09 15:49:13 +0000925 if (mSupportLongPressPowerWhenNonInteractive && hasLongPressOnPowerBehavior()) {
926 Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS);
927 msg.setAsynchronous(true);
928 mHandler.sendMessageDelayed(msg,
929 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Bryce Leed9268e32014-11-17 17:40:59 -0800930 mBeganFromNonInteractive = true;
Bryce Leed3b28402015-03-09 15:49:13 +0000931 } else {
932 final int maxCount = getMaxMultiPressPowerCount();
933
934 if (maxCount <= 1) {
935 mPowerKeyHandled = true;
936 } else {
937 mBeganFromNonInteractive = true;
938 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700939 }
940 }
Jeff Brown4d396052010-10-29 21:50:21 -0700941 }
942 }
943
Jeff Brown13f00f02014-10-31 14:45:50 -0700944 private void interceptPowerKeyUp(KeyEvent event, boolean interactive, boolean canceled) {
945 final boolean handled = canceled || mPowerKeyHandled;
946 mScreenshotChordPowerKeyTriggered = false;
947 cancelPendingScreenshotChordAction();
948 cancelPendingPowerKeyAction();
949
950 if (!handled) {
951 // Figure out how to handle the key now that it has been released.
952 mPowerKeyPressCounter += 1;
953
954 final int maxCount = getMaxMultiPressPowerCount();
955 final long eventTime = event.getDownTime();
956 if (mPowerKeyPressCounter < maxCount) {
957 // This could be a multi-press. Wait a little bit longer to confirm.
958 // Continue holding the wake lock.
959 Message msg = mHandler.obtainMessage(MSG_POWER_DELAYED_PRESS,
960 interactive ? 1 : 0, mPowerKeyPressCounter, eventTime);
961 msg.setAsynchronous(true);
962 mHandler.sendMessageDelayed(msg, ViewConfiguration.getDoubleTapTimeout());
963 return;
964 }
965
966 // No other actions. Handle it immediately.
967 powerPress(eventTime, interactive, mPowerKeyPressCounter);
Jeff Brown4d396052010-10-29 21:50:21 -0700968 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700969
970 // Done. Reset our state.
971 finishPowerKeyPress();
972 }
973
974 private void finishPowerKeyPress() {
Bryce Leed9268e32014-11-17 17:40:59 -0800975 mBeganFromNonInteractive = false;
Jeff Brown13f00f02014-10-31 14:45:50 -0700976 mPowerKeyPressCounter = 0;
977 if (mPowerKeyWakeLock.isHeld()) {
978 mPowerKeyWakeLock.release();
979 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700980 }
981
982 private void cancelPendingPowerKeyAction() {
983 if (!mPowerKeyHandled) {
Jeff Brown13f00f02014-10-31 14:45:50 -0700984 mPowerKeyHandled = true;
985 mHandler.removeMessages(MSG_POWER_LONG_PRESS);
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700986 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700987 }
988
989 private void powerPress(long eventTime, boolean interactive, int count) {
990 if (mScreenOnEarly && !mScreenOnFully) {
991 Slog.i(TAG, "Suppressed redundant power key press while "
992 + "already in the process of turning the screen on.");
993 return;
Jeff Brownff204712011-10-25 21:27:54 -0700994 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700995
996 if (count == 2) {
997 powerMultiPressAction(eventTime, interactive, mDoublePressOnPowerBehavior);
998 } else if (count == 3) {
999 powerMultiPressAction(eventTime, interactive, mTriplePressOnPowerBehavior);
Bryce Leed9268e32014-11-17 17:40:59 -08001000 } else if (interactive && !mBeganFromNonInteractive) {
Jeff Brown13f00f02014-10-31 14:45:50 -07001001 switch (mShortPressOnPowerBehavior) {
1002 case SHORT_PRESS_POWER_NOTHING:
1003 break;
1004 case SHORT_PRESS_POWER_GO_TO_SLEEP:
1005 mPowerManager.goToSleep(eventTime,
1006 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
1007 break;
1008 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP:
1009 mPowerManager.goToSleep(eventTime,
1010 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
1011 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
1012 break;
1013 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME:
1014 mPowerManager.goToSleep(eventTime,
1015 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
1016 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
1017 launchHomeFromHotKey();
1018 break;
Bryce Lee01b0c5f2015-02-05 18:24:04 -08001019 case SHORT_PRESS_POWER_GO_HOME:
Bryce Lee662ed802015-04-10 20:11:39 +00001020 launchHomeFromHotKey(true /* awakenFromDreams */, false /*respectKeyguard*/);
Bryce Lee01b0c5f2015-02-05 18:24:04 -08001021 break;
Jeff Brown13f00f02014-10-31 14:45:50 -07001022 }
1023 }
1024 }
1025
1026 private void powerMultiPressAction(long eventTime, boolean interactive, int behavior) {
1027 switch (behavior) {
1028 case MULTI_PRESS_POWER_NOTHING:
1029 break;
1030 case MULTI_PRESS_POWER_THEATER_MODE:
1031 if (isTheaterModeEnabled()) {
1032 Slog.i(TAG, "Toggling theater mode off.");
1033 Settings.Global.putInt(mContext.getContentResolver(),
1034 Settings.Global.THEATER_MODE_ON, 0);
1035 if (!interactive) {
1036 wakeUpFromPowerKey(eventTime);
1037 }
1038 } else {
1039 Slog.i(TAG, "Toggling theater mode on.");
1040 Settings.Global.putInt(mContext.getContentResolver(),
1041 Settings.Global.THEATER_MODE_ON, 1);
Bryce Lee55e846d2014-11-04 12:43:44 -08001042
1043 if (mGoToSleepOnButtonPressTheaterMode && interactive) {
Jeff Brown13f00f02014-10-31 14:45:50 -07001044 mPowerManager.goToSleep(eventTime,
1045 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
1046 }
1047 }
1048 break;
1049 case MULTI_PRESS_POWER_BRIGHTNESS_BOOST:
Jeff Brown7b5be5e2014-11-12 18:45:31 -08001050 Slog.i(TAG, "Starting brightness boost.");
1051 if (!interactive) {
1052 wakeUpFromPowerKey(eventTime);
1053 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001054 mPowerManager.boostScreenBrightness(eventTime);
1055 break;
1056 }
1057 }
1058
1059 private int getMaxMultiPressPowerCount() {
1060 if (mTriplePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) {
1061 return 3;
1062 }
1063 if (mDoublePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) {
1064 return 2;
1065 }
1066 return 1;
1067 }
1068
1069 private void powerLongPress() {
1070 final int behavior = getResolvedLongPressOnPowerBehavior();
1071 switch (behavior) {
1072 case LONG_PRESS_POWER_NOTHING:
1073 break;
1074 case LONG_PRESS_POWER_GLOBAL_ACTIONS:
1075 mPowerKeyHandled = true;
1076 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
1077 performAuditoryFeedbackForAccessibilityIfNeed();
1078 }
1079 showGlobalActionsInternal();
1080 break;
1081 case LONG_PRESS_POWER_SHUT_OFF:
1082 case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM:
1083 mPowerKeyHandled = true;
1084 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
1085 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
1086 mWindowManagerFuncs.shutdown(behavior == LONG_PRESS_POWER_SHUT_OFF);
1087 break;
1088 }
1089 }
1090
Nick Vaccarob593a812015-05-15 11:23:05 -07001091 private void sleepPress(long eventTime) {
1092 if (mShortPressOnSleepBehavior == SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME) {
1093 launchHomeFromHotKey(false /* awakenDreams */, true /*respectKeyguard*/);
1094 }
1095 }
1096
1097 private void sleepRelease(long eventTime) {
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001098 switch (mShortPressOnSleepBehavior) {
1099 case SHORT_PRESS_SLEEP_GO_TO_SLEEP:
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001100 case SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME:
Nick Vaccarob593a812015-05-15 11:23:05 -07001101 Slog.i(TAG, "sleepRelease() calling goToSleep(GO_TO_SLEEP_REASON_SLEEP_BUTTON)");
1102 mPowerManager.goToSleep(eventTime,
1103 PowerManager.GO_TO_SLEEP_REASON_SLEEP_BUTTON, 0);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001104 break;
1105 }
1106 }
1107
Jeff Brown13f00f02014-10-31 14:45:50 -07001108 private int getResolvedLongPressOnPowerBehavior() {
1109 if (FactoryTest.isLongPressOnPowerOffEnabled()) {
1110 return LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM;
1111 }
1112 return mLongPressOnPowerBehavior;
1113 }
1114
1115 private boolean hasLongPressOnPowerBehavior() {
1116 return getResolvedLongPressOnPowerBehavior() != LONG_PRESS_POWER_NOTHING;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001117 }
1118
1119 private void interceptScreenshotChord() {
Christopher Tatee90585f2012-03-05 18:56:25 -08001120 if (mScreenshotChordEnabled
Jeff Brown13f00f02014-10-31 14:45:50 -07001121 && mScreenshotChordVolumeDownKeyTriggered && mScreenshotChordPowerKeyTriggered
1122 && !mScreenshotChordVolumeUpKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001123 final long now = SystemClock.uptimeMillis();
Jeff Brown13f00f02014-10-31 14:45:50 -07001124 if (now <= mScreenshotChordVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS
1125 && now <= mScreenshotChordPowerKeyTime
1126 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) {
1127 mScreenshotChordVolumeDownKeyConsumed = true;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001128 cancelPendingPowerKeyAction();
1129
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001130 mHandler.postDelayed(mScreenshotRunnable, getScreenshotChordLongPressDelay());
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001131 }
1132 }
1133 }
1134
Winson Chung1cea2f32012-10-08 20:42:01 -07001135 private long getScreenshotChordLongPressDelay() {
Jim Miller5ecd8112013-01-09 18:50:26 -08001136 if (mKeyguardDelegate.isShowing()) {
Winson Chung1cea2f32012-10-08 20:42:01 -07001137 // Double the time it takes to take a screenshot from the keyguard
1138 return (long) (KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER *
Justin Kohfeabd2c2014-05-02 10:02:44 -07001139 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Winson Chung1cea2f32012-10-08 20:42:01 -07001140 }
Justin Kohfeabd2c2014-05-02 10:02:44 -07001141 return ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout();
Winson Chung1cea2f32012-10-08 20:42:01 -07001142 }
1143
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001144 private void cancelPendingScreenshotChordAction() {
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001145 mHandler.removeCallbacks(mScreenshotRunnable);
Jeff Brown4d396052010-10-29 21:50:21 -07001146 }
1147
Jeff Brown13f00f02014-10-31 14:45:50 -07001148 private final Runnable mEndCallLongPress = new Runnable() {
Craig Mautnerf1b67412012-09-19 13:18:29 -07001149 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001150 public void run() {
Jeff Brown13f00f02014-10-31 14:45:50 -07001151 mEndCallKeyHandled = true;
1152 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
1153 performAuditoryFeedbackForAccessibilityIfNeed();
Joe Onoratod208e702010-10-08 16:22:43 -04001154 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001155 showGlobalActionsInternal();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001156 }
1157 };
1158
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001159 private final Runnable mScreenshotRunnable = new Runnable() {
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001160 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001161 public void run() {
1162 takeScreenshot();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001163 }
1164 };
1165
Alan Viverettee34560b22014-07-10 14:50:06 -07001166 @Override
1167 public void showGlobalActions() {
1168 mHandler.removeMessages(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
1169 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
1170 }
1171
1172 void showGlobalActionsInternal() {
1173 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001174 if (mGlobalActions == null) {
Jeff Brown7304c342012-05-11 18:42:42 -07001175 mGlobalActions = new GlobalActions(mContext, mWindowManagerFuncs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001176 }
Jim Millerab954542014-10-10 18:21:49 -07001177 final boolean keyguardShowing = isKeyguardShowingAndNotOccluded();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001178 mGlobalActions.showDialog(keyguardShowing, isDeviceProvisioned());
1179 if (keyguardShowing) {
1180 // since it took two seconds of long press to bring this up,
1181 // poke the wake lock so they have some time to see the dialog.
Jim Miller25190572013-02-28 17:36:24 -08001182 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001183 }
1184 }
1185
1186 boolean isDeviceProvisioned() {
Jeff Brownbf6f6f92012-09-25 15:03:20 -07001187 return Settings.Global.getInt(
1188 mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001189 }
1190
Maurice Lam99c6e072014-04-28 18:24:28 -07001191 boolean isUserSetupComplete() {
1192 return Settings.Secure.getIntForUser(mContext.getContentResolver(),
1193 Settings.Secure.USER_SETUP_COMPLETE, 0, UserHandle.USER_CURRENT) != 0;
1194 }
1195
Jeff Brown13f00f02014-10-31 14:45:50 -07001196 private void handleShortPressOnHome() {
1197 // If there's a dream running then use home to escape the dream
1198 // but don't actually go home.
1199 if (mDreamManagerInternal != null && mDreamManagerInternal.isDreaming()) {
1200 mDreamManagerInternal.stopDream(false /*immediate*/);
1201 return;
1202 }
1203
1204 // Go home!
1205 launchHomeFromHotKey();
1206 }
1207
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07001208 private void handleLongPressOnHome(int deviceId) {
Joe Onorato46b0d682010-11-22 17:37:27 -08001209 if (mLongPressOnHomeBehavior != LONG_PRESS_HOME_NOTHING) {
Jeff Browncaca8812013-05-09 13:34:33 -07001210 mHomeConsumed = true;
Joe Onorato46b0d682010-11-22 17:37:27 -08001211 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
Patrick Dubroyece94522011-02-23 18:35:01 -08001212
Jeff Browncaca8812013-05-09 13:34:33 -07001213 if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI) {
1214 toggleRecentApps();
1215 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_ASSIST) {
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07001216 launchAssistAction(null, deviceId);
Jim Millere6ad1a82010-08-20 19:25:39 -07001217 }
1218 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001219 }
Patrick Dubroyece94522011-02-23 18:35:01 -08001220
Jeff Browncaca8812013-05-09 13:34:33 -07001221 private void handleDoubleTapOnHome() {
1222 if (mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1223 mHomeConsumed = true;
1224 toggleRecentApps();
1225 }
1226 }
1227
1228 private final Runnable mHomeDoubleTapTimeoutRunnable = new Runnable() {
1229 @Override
1230 public void run() {
1231 if (mHomeDoubleTapPending) {
1232 mHomeDoubleTapPending = false;
Jeff Brown13f00f02014-10-31 14:45:50 -07001233 handleShortPressOnHome();
Jeff Browncaca8812013-05-09 13:34:33 -07001234 }
1235 }
1236 };
1237
Mark Renoufc1256912015-03-11 14:38:23 -04001238 private boolean isRoundWindow() {
Adam Powell01f280d2015-05-18 16:07:42 -07001239 return mContext.getResources().getConfiguration().isScreenRound();
Mark Renoufc1256912015-03-11 14:38:23 -04001240 }
1241
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001242 /** {@inheritDoc} */
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001243 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001244 public void init(Context context, IWindowManager windowManager,
Jeff Brown96307042012-07-27 15:51:34 -07001245 WindowManagerFuncs windowManagerFuncs) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001246 mContext = context;
1247 mWindowManager = windowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -07001248 mWindowManagerFuncs = windowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -07001249 mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class);
Jeff Brown061ea992015-04-17 19:55:47 -07001250 mActivityManagerInternal = LocalServices.getService(ActivityManagerInternal.class);
Jose Lima9546b202014-07-02 17:21:51 -07001251 mDreamManagerInternal = LocalServices.getService(DreamManagerInternal.class);
Mark Renoufc1256912015-03-11 14:38:23 -04001252
1253 // Init display burn-in protection
1254 boolean burnInProtectionEnabled = context.getResources().getBoolean(
1255 com.android.internal.R.bool.config_enableBurnInProtection);
1256 // Allow a system property to override this. Used by developer settings.
1257 boolean burnInProtectionDevMode =
1258 SystemProperties.getBoolean("persist.debug.force_burn_in", false);
1259 if (burnInProtectionEnabled || burnInProtectionDevMode) {
1260 final int minHorizontal;
1261 final int maxHorizontal;
1262 final int minVertical;
1263 final int maxVertical;
1264 final int maxRadius;
1265 if (burnInProtectionDevMode) {
1266 minHorizontal = -8;
1267 maxHorizontal = 8;
1268 minVertical = -8;
1269 maxVertical = -4;
1270 maxRadius = (isRoundWindow()) ? 6 : -1;
1271 } else {
1272 Resources resources = context.getResources();
1273 minHorizontal = resources.getInteger(
1274 com.android.internal.R.integer.config_burnInProtectionMinHorizontalOffset);
1275 maxHorizontal = resources.getInteger(
1276 com.android.internal.R.integer.config_burnInProtectionMaxHorizontalOffset);
1277 minVertical = resources.getInteger(
1278 com.android.internal.R.integer.config_burnInProtectionMinVerticalOffset);
1279 maxVertical = resources.getInteger(
1280 com.android.internal.R.integer.config_burnInProtectionMaxVerticalOffset);
1281 maxRadius = resources.getInteger(
1282 com.android.internal.R.integer.config_burnInProtectionMaxRadius);
1283 }
1284 mBurnInProtectionHelper = new BurnInProtectionHelper(
1285 context, minHorizontal, maxHorizontal, minVertical, maxVertical, maxRadius);
Filip Gruszczynskicfb31852015-02-25 21:47:12 +00001286 }
Craig Mautner8a0da012014-05-31 15:13:37 -07001287
Jeff Brown70825162012-03-28 17:27:48 -07001288 mHandler = new PolicyHandler();
Jeff Browna20dda42014-05-27 20:57:24 -07001289 mWakeGestureListener = new MyWakeGestureListener(mContext, mHandler);
Craig Mautnereee29c42013-01-17 14:44:34 -08001290 mOrientationListener = new MyOrientationListener(mContext, mHandler);
Jeff Brownc0347aa2011-09-23 17:26:09 -07001291 try {
1292 mOrientationListener.setCurrentRotation(windowManager.getRotation());
1293 } catch (RemoteException ex) { }
Christopher Tate5e08af02012-09-21 17:17:22 -07001294 mSettingsObserver = new SettingsObserver(mHandler);
1295 mSettingsObserver.observe();
Svetoslav683914b2015-01-15 14:22:26 -08001296 mShortcutManager = new ShortcutManager(context);
Daniel Sandler6396c722013-04-16 20:19:09 -04001297 mUiMode = context.getResources().getInteger(
1298 com.android.internal.R.integer.config_defaultUiModeType);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001299 mHomeIntent = new Intent(Intent.ACTION_MAIN, null);
1300 mHomeIntent.addCategory(Intent.CATEGORY_HOME);
1301 mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1302 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07001303 mCarDockIntent = new Intent(Intent.ACTION_MAIN, null);
1304 mCarDockIntent.addCategory(Intent.CATEGORY_CAR_DOCK);
1305 mCarDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1306 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
1307 mDeskDockIntent = new Intent(Intent.ACTION_MAIN, null);
1308 mDeskDockIntent.addCategory(Intent.CATEGORY_DESK_DOCK);
1309 mDeskDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1310 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Jim Millere6ad1a82010-08-20 19:25:39 -07001311
Jeff Brown96307042012-07-27 15:51:34 -07001312 mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
1313 mBroadcastWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001314 "PhoneWindowManager.mBroadcastWakeLock");
Jeff Brown13f00f02014-10-31 14:45:50 -07001315 mPowerKeyWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
1316 "PhoneWindowManager.mPowerKeyWakeLock");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001317 mEnableShiftMenuBugReports = "1".equals(SystemProperties.get("ro.debuggable"));
Jeff Brownbcdfc622014-03-06 19:13:04 -08001318 mSupportAutoRotation = mContext.getResources().getBoolean(
1319 com.android.internal.R.bool.config_supportAutoRotation);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001320 mLidOpenRotation = readRotation(
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001321 com.android.internal.R.integer.config_lidOpenRotation);
1322 mCarDockRotation = readRotation(
1323 com.android.internal.R.integer.config_carDockRotation);
1324 mDeskDockRotation = readRotation(
1325 com.android.internal.R.integer.config_deskDockRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001326 mUndockedHdmiRotation = readRotation(
1327 com.android.internal.R.integer.config_undockedHdmiRotation);
Mike Lockwoode9867d22009-09-20 01:59:02 -04001328 mCarDockEnablesAccelerometer = mContext.getResources().getBoolean(
1329 com.android.internal.R.bool.config_carDockEnablesAccelerometer);
1330 mDeskDockEnablesAccelerometer = mContext.getResources().getBoolean(
1331 com.android.internal.R.bool.config_deskDockEnablesAccelerometer);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001332 mLidKeyboardAccessibility = mContext.getResources().getInteger(
1333 com.android.internal.R.integer.config_lidKeyboardAccessibility);
1334 mLidNavigationAccessibility = mContext.getResources().getInteger(
1335 com.android.internal.R.integer.config_lidNavigationAccessibility);
Jeff Brownc458ce92012-04-30 14:58:40 -07001336 mLidControlsSleep = mContext.getResources().getBoolean(
1337 com.android.internal.R.bool.config_lidControlsSleep);
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04001338 mTranslucentDecorEnabled = mContext.getResources().getBoolean(
1339 com.android.internal.R.bool.config_enableTranslucentDecor);
Bryce Lee584a4452014-10-21 15:55:55 -07001340
1341 mAllowTheaterModeWakeFromKey = mContext.getResources().getBoolean(
1342 com.android.internal.R.bool.config_allowTheaterModeWakeFromKey);
1343 mAllowTheaterModeWakeFromPowerKey = mAllowTheaterModeWakeFromKey
1344 || mContext.getResources().getBoolean(
1345 com.android.internal.R.bool.config_allowTheaterModeWakeFromPowerKey);
1346 mAllowTheaterModeWakeFromMotion = mContext.getResources().getBoolean(
1347 com.android.internal.R.bool.config_allowTheaterModeWakeFromMotion);
Bryce Lee812d7022014-11-10 13:33:28 -08001348 mAllowTheaterModeWakeFromMotionWhenNotDreaming = mContext.getResources().getBoolean(
1349 com.android.internal.R.bool.config_allowTheaterModeWakeFromMotionWhenNotDreaming);
Bryce Lee584a4452014-10-21 15:55:55 -07001350 mAllowTheaterModeWakeFromCameraLens = mContext.getResources().getBoolean(
1351 com.android.internal.R.bool.config_allowTheaterModeWakeFromCameraLens);
1352 mAllowTheaterModeWakeFromLidSwitch = mContext.getResources().getBoolean(
1353 com.android.internal.R.bool.config_allowTheaterModeWakeFromLidSwitch);
1354 mAllowTheaterModeWakeFromWakeGesture = mContext.getResources().getBoolean(
1355 com.android.internal.R.bool.config_allowTheaterModeWakeFromGesture);
1356
Bryce Lee55e846d2014-11-04 12:43:44 -08001357 mGoToSleepOnButtonPressTheaterMode = mContext.getResources().getBoolean(
1358 com.android.internal.R.bool.config_goToSleepOnButtonPressTheaterMode);
1359
Bryce Leed3b28402015-03-09 15:49:13 +00001360 mSupportLongPressPowerWhenNonInteractive = mContext.getResources().getBoolean(
1361 com.android.internal.R.bool.config_supportLongPressPowerWhenNonInteractive);
1362
Jeff Brown13f00f02014-10-31 14:45:50 -07001363 mShortPressOnPowerBehavior = mContext.getResources().getInteger(
1364 com.android.internal.R.integer.config_shortPressOnPowerBehavior);
1365 mLongPressOnPowerBehavior = mContext.getResources().getInteger(
1366 com.android.internal.R.integer.config_longPressOnPowerBehavior);
1367 mDoublePressOnPowerBehavior = mContext.getResources().getInteger(
1368 com.android.internal.R.integer.config_doublePressOnPowerBehavior);
1369 mTriplePressOnPowerBehavior = mContext.getResources().getInteger(
1370 com.android.internal.R.integer.config_triplePressOnPowerBehavior);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001371 mShortPressOnSleepBehavior = mContext.getResources().getInteger(
1372 com.android.internal.R.integer.config_shortPressOnSleepBehavior);
Jeff Brown13f00f02014-10-31 14:45:50 -07001373
John Spurlock61560172015-02-06 19:46:04 -05001374 mUseTvRouting = AudioSystem.getPlatformType(mContext) == AudioSystem.PLATFORM_TELEVISION;
RoboErik001c59c2015-01-26 15:53:51 -08001375
Jeff Brownf71343d2013-05-31 17:59:11 -07001376 readConfigurationDependentBehaviors();
Jeff Browncaca8812013-05-09 13:34:33 -07001377
Svetoslav8e3feb12014-02-24 13:46:47 -08001378 mAccessibilityManager = (AccessibilityManager) context.getSystemService(
1379 Context.ACCESSIBILITY_SERVICE);
1380
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001381 // register for dock events
Dianne Hackborn78968392010-03-04 20:47:56 -08001382 IntentFilter filter = new IntentFilter();
1383 filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE);
1384 filter.addAction(UiModeManager.ACTION_EXIT_CAR_MODE);
1385 filter.addAction(UiModeManager.ACTION_ENTER_DESK_MODE);
1386 filter.addAction(UiModeManager.ACTION_EXIT_DESK_MODE);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001387 filter.addAction(Intent.ACTION_DOCK_EVENT);
1388 Intent intent = context.registerReceiver(mDockReceiver, filter);
1389 if (intent != null) {
1390 // Retrieve current sticky dock event broadcast.
1391 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
1392 Intent.EXTRA_DOCK_STATE_UNDOCKED);
1393 }
Daniel Sandler7e37df52011-11-16 22:08:23 -08001394
Jeff Brown6aaf2952012-10-05 16:01:08 -07001395 // register for dream-related broadcasts
1396 filter = new IntentFilter();
1397 filter.addAction(Intent.ACTION_DREAMING_STARTED);
1398 filter.addAction(Intent.ACTION_DREAMING_STOPPED);
1399 context.registerReceiver(mDreamReceiver, filter);
1400
Christopher Tate5e08af02012-09-21 17:17:22 -07001401 // register for multiuser-relevant broadcasts
1402 filter = new IntentFilter(Intent.ACTION_USER_SWITCHED);
1403 context.registerReceiver(mMultiuserReceiver, filter);
1404
John Spurlock57306e62013-04-22 09:48:49 -04001405 // monitor for system gestures
Craig Mautner037aa8d2013-06-07 10:35:44 -07001406 mSystemGestures = new SystemGesturesPointerEventListener(context,
1407 new SystemGesturesPointerEventListener.Callbacks() {
John Spurlock57306e62013-04-22 09:48:49 -04001408 @Override
1409 public void onSwipeFromTop() {
John Spurlock04db1762013-05-13 12:46:41 -04001410 if (mStatusBar != null) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001411 requestTransientBars(mStatusBar);
John Spurlock04db1762013-05-13 12:46:41 -04001412 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04001413 }
1414 @Override
1415 public void onSwipeFromBottom() {
John Spurlock04db1762013-05-13 12:46:41 -04001416 if (mNavigationBar != null && mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001417 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001418 }
1419 }
1420 @Override
1421 public void onSwipeFromRight() {
John Spurlock04db1762013-05-13 12:46:41 -04001422 if (mNavigationBar != null && !mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001423 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001424 }
1425 }
1426 @Override
1427 public void onDebug() {
John Spurlockd67ec252013-09-05 11:31:54 -04001428 // no-op
John Spurlockad3e6cb2013-04-30 08:47:43 -04001429 }
Adrian Roos3595be42015-03-05 16:31:15 +01001430 @Override
1431 public void onDown() {
1432 mOrientationListener.onTouchStart();
1433 }
1434 @Override
1435 public void onUpOrCancel() {
1436 mOrientationListener.onTouchEnd();
1437 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04001438 });
John Spurlockf1a36642013-10-12 17:50:42 -04001439 mImmersiveModeConfirmation = new ImmersiveModeConfirmation(mContext);
Craig Mautner037aa8d2013-06-07 10:35:44 -07001440 mWindowManagerFuncs.registerPointerEventListener(mSystemGestures);
John Spurlock32beb2c2013-03-11 10:16:47 -04001441
Jeff Brownc2346132012-04-13 01:55:38 -07001442 mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001443 mLongPressVibePattern = getLongIntArray(mContext.getResources(),
1444 com.android.internal.R.array.config_longPressVibePattern);
1445 mVirtualKeyVibePattern = getLongIntArray(mContext.getResources(),
1446 com.android.internal.R.array.config_virtualKeyVibePattern);
Amith Yamasanic33cb712010-02-10 15:21:49 -08001447 mKeyboardTapVibePattern = getLongIntArray(mContext.getResources(),
1448 com.android.internal.R.array.config_keyboardTapVibePattern);
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07001449 mClockTickVibePattern = getLongIntArray(mContext.getResources(),
1450 com.android.internal.R.array.config_clockTickVibePattern);
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07001451 mCalendarDateVibePattern = getLongIntArray(mContext.getResources(),
1452 com.android.internal.R.array.config_calendarDateVibePattern);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001453 mSafeModeDisabledVibePattern = getLongIntArray(mContext.getResources(),
1454 com.android.internal.R.array.config_safeModeDisabledVibePattern);
1455 mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(),
1456 com.android.internal.R.array.config_safeModeEnabledVibePattern);
Mady Mellore8608912015-06-05 09:02:55 -07001457 mContextClickVibePattern = getLongIntArray(mContext.getResources(),
1458 com.android.internal.R.array.config_contextClickVibePattern);
Daniel Sandler40427442010-07-16 11:44:52 -04001459
Christopher Tatee90585f2012-03-05 18:56:25 -08001460 mScreenshotChordEnabled = mContext.getResources().getBoolean(
1461 com.android.internal.R.bool.config_enableScreenshotChord);
1462
Justin Kohd378ad72013-04-01 12:18:26 -07001463 mGlobalKeyManager = new GlobalKeyManager(mContext);
1464
Joe Onoratoea495d42011-04-06 11:41:11 -07001465 // Controls rotation and the like.
1466 initializeHdmiState();
Dianne Hackborn40011092011-09-22 13:37:48 -07001467
1468 // Match current screen state.
Craig Mautnera631d492014-08-05 15:16:01 -07001469 if (!mPowerManager.isInteractive()) {
Jeff Brown416c49c2015-05-26 19:50:18 -07001470 startedGoingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
1471 finishedGoingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
Dianne Hackborn40011092011-09-22 13:37:48 -07001472 }
Jorim Jaggi24bec7c2015-02-04 12:40:14 +01001473
1474 mWindowManagerInternal.registerAppTransitionListener(
1475 mStatusBarController.getAppTransitionListener());
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001476 }
1477
Jeff Brownf71343d2013-05-31 17:59:11 -07001478 /**
1479 * Read values from config.xml that may be overridden depending on
1480 * the configuration of the device.
1481 * eg. Disable long press on home goes to recents on sw600dp.
1482 */
1483 private void readConfigurationDependentBehaviors() {
1484 mLongPressOnHomeBehavior = mContext.getResources().getInteger(
1485 com.android.internal.R.integer.config_longPressOnHomeBehavior);
1486 if (mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING ||
1487 mLongPressOnHomeBehavior > LONG_PRESS_HOME_ASSIST) {
1488 mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1489 }
1490
1491 mDoubleTapOnHomeBehavior = mContext.getResources().getInteger(
1492 com.android.internal.R.integer.config_doubleTapOnHomeBehavior);
1493 if (mDoubleTapOnHomeBehavior < DOUBLE_TAP_HOME_NOTHING ||
1494 mDoubleTapOnHomeBehavior > DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1495 mDoubleTapOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1496 }
1497 }
1498
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001499 @Override
Dianne Hackborndde331c2012-08-03 14:01:57 -07001500 public void setInitialDisplaySize(Display display, int width, int height, int density) {
Jeff Brownef981a42013-08-07 14:13:37 -07001501 // This method might be called before the policy has been fully initialized
1502 // or for other displays we don't care about.
1503 if (mContext == null || display.getDisplayId() != Display.DEFAULT_DISPLAY) {
1504 return;
Dianne Hackbornc652de82013-02-15 16:32:56 -08001505 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001506 mDisplay = display;
1507
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001508 final Resources res = mContext.getResources();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001509 int shortSize, longSize;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001510 if (width > height) {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001511 shortSize = height;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001512 longSize = width;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001513 mLandscapeRotation = Surface.ROTATION_0;
1514 mSeascapeRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001515 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001516 mPortraitRotation = Surface.ROTATION_90;
1517 mUpsideDownRotation = Surface.ROTATION_270;
1518 } else {
1519 mPortraitRotation = Surface.ROTATION_270;
1520 mUpsideDownRotation = Surface.ROTATION_90;
1521 }
1522 } else {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001523 shortSize = width;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001524 longSize = height;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001525 mPortraitRotation = Surface.ROTATION_0;
1526 mUpsideDownRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001527 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001528 mLandscapeRotation = Surface.ROTATION_270;
1529 mSeascapeRotation = Surface.ROTATION_90;
1530 } else {
1531 mLandscapeRotation = Surface.ROTATION_90;
1532 mSeascapeRotation = Surface.ROTATION_270;
1533 }
1534 }
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001535
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001536 mStatusBarHeight =
1537 res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001538
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001539 // Height of the navigation bar when presented horizontally at bottom
1540 mNavigationBarHeightForRotation[mPortraitRotation] =
1541 mNavigationBarHeightForRotation[mUpsideDownRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001542 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_height);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001543 mNavigationBarHeightForRotation[mLandscapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001544 mNavigationBarHeightForRotation[mSeascapeRotation] = res.getDimensionPixelSize(
1545 com.android.internal.R.dimen.navigation_bar_height_landscape);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001546
1547 // Width of the navigation bar when presented vertically along one side
1548 mNavigationBarWidthForRotation[mPortraitRotation] =
1549 mNavigationBarWidthForRotation[mUpsideDownRotation] =
1550 mNavigationBarWidthForRotation[mLandscapeRotation] =
1551 mNavigationBarWidthForRotation[mSeascapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001552 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_width);
Daniel Sandler4a066c52012-04-20 14:49:13 -04001553
1554 // SystemUI (status bar) layout policy
Dianne Hackborndde331c2012-08-03 14:01:57 -07001555 int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / density;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001556 int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / density;
Daniel Sandler4a066c52012-04-20 14:49:13 -04001557
Devin Kimd7b12b42014-05-05 14:34:58 -07001558 // Allow the navigation bar to move on non-square small devices (phones).
1559 mNavigationBarCanMove = width != height && shortSizeDp < 600;
Daniel Sandler36412a72011-08-04 09:35:13 -04001560
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001561 mHasNavigationBar = res.getBoolean(com.android.internal.R.bool.config_showNavigationBar);
John Spurlock80f00c12013-06-13 11:10:51 -04001562 // Allow a system property to override this. Used by the emulator.
1563 // See also hasNavigationBar().
1564 String navBarOverride = SystemProperties.get("qemu.hw.mainkeys");
1565 if ("1".equals(navBarOverride)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001566 mHasNavigationBar = false;
John Spurlock80f00c12013-06-13 11:10:51 -04001567 } else if ("0".equals(navBarOverride)) {
1568 mHasNavigationBar = true;
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04001569 }
1570
Jeff Brown27f1d672012-10-17 18:32:34 -07001571 // For demo purposes, allow the rotation of the HDMI display to be controlled.
1572 // By default, HDMI locks rotation to landscape.
Erik Gilling9a41ef82011-09-26 19:21:03 -07001573 if ("portrait".equals(SystemProperties.get("persist.demo.hdmirotation"))) {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001574 mDemoHdmiRotation = mPortraitRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001575 } else {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001576 mDemoHdmiRotation = mLandscapeRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001577 }
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001578 mDemoHdmiRotationLock = SystemProperties.getBoolean("persist.demo.hdmirotationlock", false);
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001579
Chong Zhangae6119ff2014-11-11 18:54:39 -08001580 // For demo purposes, allow the rotation of the remote display to be controlled.
1581 // By default, remote display locks rotation to landscape.
1582 if ("portrait".equals(SystemProperties.get("persist.demo.remoterotation"))) {
1583 mDemoRotation = mPortraitRotation;
1584 } else {
1585 mDemoRotation = mLandscapeRotation;
1586 }
1587 mDemoRotationLock = SystemProperties.getBoolean(
1588 "persist.demo.rotationlock", false);
1589
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001590 // Only force the default orientation if the screen is xlarge, at least 960dp x 720dp, per
1591 // http://developer.android.com/guide/practices/screens_support.html#range
1592 mForceDefaultOrientation = longSizeDp >= 960 && shortSizeDp >= 720 &&
1593 res.getBoolean(com.android.internal.R.bool.config_forceDefaultOrientation) &&
1594 // For debug purposes the next line turns this feature off with:
1595 // $ adb shell setprop config.override_forced_orient true
1596 // $ adb shell wm size reset
1597 !"true".equals(SystemProperties.get("config.override_forced_orient"));
1598 }
1599
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001600 /**
1601 * @return whether the navigation bar can be hidden, e.g. the device has a
1602 * navigation bar and touch exploration is not enabled
1603 */
1604 private boolean canHideNavigationBar() {
Svetoslav8e3feb12014-02-24 13:46:47 -08001605 return mHasNavigationBar
1606 && !mAccessibilityManager.isTouchExplorationEnabled();
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001607 }
1608
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001609 @Override
1610 public boolean isDefaultOrientationForced() {
1611 return mForceDefaultOrientation;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001612 }
1613
Dianne Hackbornc652de82013-02-15 16:32:56 -08001614 @Override
1615 public void setDisplayOverscan(Display display, int left, int top, int right, int bottom) {
1616 if (display.getDisplayId() == Display.DEFAULT_DISPLAY) {
1617 mOverscanLeft = left;
1618 mOverscanTop = top;
1619 mOverscanRight = right;
1620 mOverscanBottom = bottom;
1621 }
1622 }
1623
Dianne Hackbornc777e072010-02-12 13:07:59 -08001624 public void updateSettings() {
1625 ContentResolver resolver = mContext.getContentResolver();
1626 boolean updateRotation = false;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001627 synchronized (mLock) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001628 mEndcallBehavior = Settings.System.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001629 Settings.System.END_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001630 Settings.System.END_BUTTON_BEHAVIOR_DEFAULT,
1631 UserHandle.USER_CURRENT);
1632 mIncallPowerBehavior = Settings.Secure.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001633 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001634 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT,
1635 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001636
Jeff Browna20dda42014-05-27 20:57:24 -07001637 // Configure wake gesture.
1638 boolean wakeGestureEnabledSetting = Settings.Secure.getIntForUser(resolver,
1639 Settings.Secure.WAKE_GESTURE_ENABLED, 0,
1640 UserHandle.USER_CURRENT) != 0;
1641 if (mWakeGestureEnabledSetting != wakeGestureEnabledSetting) {
1642 mWakeGestureEnabledSetting = wakeGestureEnabledSetting;
1643 updateWakeGestureListenerLp();
1644 }
1645
Jeff Brown207673cd2012-06-05 17:47:11 -07001646 // Configure rotation lock.
Christopher Tate5e08af02012-09-21 17:17:22 -07001647 int userRotation = Settings.System.getIntForUser(resolver,
1648 Settings.System.USER_ROTATION, Surface.ROTATION_0,
1649 UserHandle.USER_CURRENT);
Jeff Brown207673cd2012-06-05 17:47:11 -07001650 if (mUserRotation != userRotation) {
1651 mUserRotation = userRotation;
1652 updateRotation = true;
1653 }
Christopher Tate5e08af02012-09-21 17:17:22 -07001654 int userRotationMode = Settings.System.getIntForUser(resolver,
1655 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
Jeff Brown207673cd2012-06-05 17:47:11 -07001656 WindowManagerPolicy.USER_ROTATION_FREE :
1657 WindowManagerPolicy.USER_ROTATION_LOCKED;
1658 if (mUserRotationMode != userRotationMode) {
1659 mUserRotationMode = userRotationMode;
1660 updateRotation = true;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001661 updateOrientationListenerLp();
1662 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001663
Dianne Hackbornc777e072010-02-12 13:07:59 -08001664 if (mSystemReady) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001665 int pointerLocation = Settings.System.getIntForUser(resolver,
1666 Settings.System.POINTER_LOCATION, 0, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001667 if (mPointerLocationMode != pointerLocation) {
1668 mPointerLocationMode = pointerLocation;
Jeff Brown70825162012-03-28 17:27:48 -07001669 mHandler.sendEmptyMessage(pointerLocation != 0 ?
1670 MSG_ENABLE_POINTER_LOCATION : MSG_DISABLE_POINTER_LOCATION);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001671 }
1672 }
1673 // use screen off timeout setting as the timeout for the lockscreen
Christopher Tate5e08af02012-09-21 17:17:22 -07001674 mLockScreenTimeout = Settings.System.getIntForUser(resolver,
1675 Settings.System.SCREEN_OFF_TIMEOUT, 0, UserHandle.USER_CURRENT);
1676 String imId = Settings.Secure.getStringForUser(resolver,
1677 Settings.Secure.DEFAULT_INPUT_METHOD, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001678 boolean hasSoftInput = imId != null && imId.length() > 0;
1679 if (mHasSoftInput != hasSoftInput) {
1680 mHasSoftInput = hasSoftInput;
1681 updateRotation = true;
1682 }
John Spurlockf1a36642013-10-12 17:50:42 -04001683 if (mImmersiveModeConfirmation != null) {
John Spurlock4355a532014-02-19 09:49:25 -05001684 mImmersiveModeConfirmation.loadSetting(mCurrentUserId);
John Spurlockd67ec252013-09-05 11:31:54 -04001685 }
John Spurlockc6d1c602014-01-17 15:22:06 -05001686 PolicyControl.reloadFromSetting(mContext);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001687 }
1688 if (updateRotation) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07001689 updateRotation(true);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001690 }
Jeff Brown70825162012-03-28 17:27:48 -07001691 }
1692
Jeff Browna20dda42014-05-27 20:57:24 -07001693 private void updateWakeGestureListenerLp() {
1694 if (shouldEnableWakeGestureLp()) {
1695 mWakeGestureListener.requestWakeUpTrigger();
1696 } else {
1697 mWakeGestureListener.cancelWakeUpTrigger();
1698 }
1699 }
1700
1701 private boolean shouldEnableWakeGestureLp() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07001702 return mWakeGestureEnabledSetting && !mAwake
Jeff Browna20dda42014-05-27 20:57:24 -07001703 && (!mLidControlsSleep || mLidState != LID_CLOSED)
1704 && mWakeGestureListener.isSupported();
1705 }
1706
Jeff Brown70825162012-03-28 17:27:48 -07001707 private void enablePointerLocation() {
1708 if (mPointerLocationView == null) {
1709 mPointerLocationView = new PointerLocationView(mContext);
1710 mPointerLocationView.setPrintCoords(false);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001711 WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
1712 WindowManager.LayoutParams.MATCH_PARENT,
1713 WindowManager.LayoutParams.MATCH_PARENT);
Jeff Brown3b2b3542010-10-15 00:54:27 -07001714 lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001715 lp.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN
1716 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
1717 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1718 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
Jeff Brown90fc9052012-10-01 14:44:24 -07001719 if (ActivityManager.isHighEndGfx()) {
1720 lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
1721 lp.privateFlags |=
1722 WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED;
1723 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001724 lp.format = PixelFormat.TRANSLUCENT;
1725 lp.setTitle("PointerLocation");
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001726 WindowManager wm = (WindowManager)
Dianne Hackbornc777e072010-02-12 13:07:59 -08001727 mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Browncc4f7db2011-08-30 20:34:48 -07001728 lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL;
Jeff Brown70825162012-03-28 17:27:48 -07001729 wm.addView(mPointerLocationView, lp);
Michael Wrightc9c487e2013-11-07 18:55:09 -08001730 mWindowManagerFuncs.registerPointerEventListener(mPointerLocationView);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001731 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001732 }
Jeff Brown70825162012-03-28 17:27:48 -07001733
1734 private void disablePointerLocation() {
Jeff Brown70825162012-03-28 17:27:48 -07001735 if (mPointerLocationView != null) {
Michael Wrightc9c487e2013-11-07 18:55:09 -08001736 mWindowManagerFuncs.unregisterPointerEventListener(mPointerLocationView);
1737 WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Brown70825162012-03-28 17:27:48 -07001738 wm.removeView(mPointerLocationView);
1739 mPointerLocationView = null;
1740 }
1741 }
1742
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001743 private int readRotation(int resID) {
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001744 try {
1745 int rotation = mContext.getResources().getInteger(resID);
1746 switch (rotation) {
1747 case 0:
1748 return Surface.ROTATION_0;
1749 case 90:
1750 return Surface.ROTATION_90;
1751 case 180:
1752 return Surface.ROTATION_180;
1753 case 270:
1754 return Surface.ROTATION_270;
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001755 }
1756 } catch (Resources.NotFoundException e) {
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001757 // fall through
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001758 }
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001759 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001760 }
1761
1762 /** {@inheritDoc} */
Craig Mautner88400d32012-09-30 12:35:45 -07001763 @Override
Dianne Hackbornc2293022013-02-06 23:14:49 -08001764 public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001765 int type = attrs.type;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001766
1767 outAppOp[0] = AppOpsManager.OP_NONE;
1768
Wale Ogunwale74bf0652015-01-12 10:24:36 -08001769 if (!((type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW)
1770 || (type >= FIRST_SUB_WINDOW && type <= LAST_SUB_WINDOW)
1771 || (type >= FIRST_SYSTEM_WINDOW && type <= LAST_SYSTEM_WINDOW))) {
1772 return WindowManagerGlobal.ADD_INVALID_TYPE;
1773 }
1774
1775 if (type < FIRST_SYSTEM_WINDOW || type > LAST_SYSTEM_WINDOW) {
1776 // Window manager will make sure these are okay.
Jeff Brown98365d72012-08-19 20:30:52 -07001777 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001778 }
1779 String permission = null;
1780 switch (type) {
1781 case TYPE_TOAST:
1782 // XXX right now the app process has complete control over
1783 // this... should introduce a token to let the system
1784 // monitor/control what they are doing.
Jason Monk1c7c3192014-06-26 12:52:18 -04001785 outAppOp[0] = AppOpsManager.OP_TOAST_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001786 break;
Daniel Sandler7d276c32012-01-30 14:33:52 -05001787 case TYPE_DREAM:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001788 case TYPE_INPUT_METHOD:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001789 case TYPE_WALLPAPER:
keunyounga446bf02013-06-21 19:07:57 -07001790 case TYPE_PRIVATE_PRESENTATION:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001791 case TYPE_VOICE_INTERACTION:
Svetoslav3a5c7212014-10-14 09:54:26 -07001792 case TYPE_ACCESSIBILITY_OVERLAY:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001793 // The window manager will check these.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001794 break;
1795 case TYPE_PHONE:
1796 case TYPE_PRIORITY_PHONE:
1797 case TYPE_SYSTEM_ALERT:
1798 case TYPE_SYSTEM_ERROR:
1799 case TYPE_SYSTEM_OVERLAY:
1800 permission = android.Manifest.permission.SYSTEM_ALERT_WINDOW;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001801 outAppOp[0] = AppOpsManager.OP_SYSTEM_ALERT_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001802 break;
1803 default:
1804 permission = android.Manifest.permission.INTERNAL_SYSTEM_WINDOW;
1805 }
1806 if (permission != null) {
1807 if (mContext.checkCallingOrSelfPermission(permission)
1808 != PackageManager.PERMISSION_GRANTED) {
Jeff Brown98365d72012-08-19 20:30:52 -07001809 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001810 }
1811 }
Jeff Brown98365d72012-08-19 20:30:52 -07001812 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001813 }
Craig Mautner88400d32012-09-30 12:35:45 -07001814
1815 @Override
1816 public boolean checkShowToOwnerOnly(WindowManager.LayoutParams attrs) {
1817
1818 // If this switch statement is modified, modify the comment in the declarations of
1819 // the type in {@link WindowManager.LayoutParams} as well.
1820 switch (attrs.type) {
1821 default:
1822 // These are the windows that by default are shown only to the user that created
1823 // them. If this needs to be overridden, set
1824 // {@link WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS} in
1825 // {@link WindowManager.LayoutParams}. Note that permission
1826 // {@link android.Manifest.permission.INTERNAL_SYSTEM_WINDOW} is required as well.
1827 if ((attrs.privateFlags & PRIVATE_FLAG_SHOW_FOR_ALL_USERS) == 0) {
1828 return true;
1829 }
1830 break;
1831
1832 // These are the windows that by default are shown to all users. However, to
1833 // protect against spoofing, check permissions below.
1834 case TYPE_APPLICATION_STARTING:
1835 case TYPE_BOOT_PROGRESS:
1836 case TYPE_DISPLAY_OVERLAY:
Selim Cinekf83e8242015-05-19 18:08:14 -07001837 case TYPE_INPUT_CONSUMER:
Jim Miller5ecd8112013-01-09 18:50:26 -08001838 case TYPE_KEYGUARD_SCRIM:
Craig Mautner88400d32012-09-30 12:35:45 -07001839 case TYPE_KEYGUARD_DIALOG:
1840 case TYPE_MAGNIFICATION_OVERLAY:
1841 case TYPE_NAVIGATION_BAR:
1842 case TYPE_NAVIGATION_BAR_PANEL:
1843 case TYPE_PHONE:
1844 case TYPE_POINTER:
1845 case TYPE_PRIORITY_PHONE:
Craig Mautner88400d32012-09-30 12:35:45 -07001846 case TYPE_SEARCH_BAR:
1847 case TYPE_STATUS_BAR:
1848 case TYPE_STATUS_BAR_PANEL:
1849 case TYPE_STATUS_BAR_SUB_PANEL:
1850 case TYPE_SYSTEM_DIALOG:
Craig Mautner88400d32012-09-30 12:35:45 -07001851 case TYPE_VOLUME_OVERLAY:
keunyounga446bf02013-06-21 19:07:57 -07001852 case TYPE_PRIVATE_PRESENTATION:
Craig Mautner88400d32012-09-30 12:35:45 -07001853 break;
1854 }
1855
1856 // Check if third party app has set window to system window type.
1857 return mContext.checkCallingOrSelfPermission(
1858 android.Manifest.permission.INTERNAL_SYSTEM_WINDOW)
1859 != PackageManager.PERMISSION_GRANTED;
1860 }
1861
Craig Mautner967212c2013-04-13 21:10:58 -07001862 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001863 public void adjustWindowParamsLw(WindowManager.LayoutParams attrs) {
1864 switch (attrs.type) {
1865 case TYPE_SYSTEM_OVERLAY:
Jeff Brown3b2b3542010-10-15 00:54:27 -07001866 case TYPE_SECURE_SYSTEM_OVERLAY:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001867 // These types of windows can't receive input events.
1868 attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1869 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001870 attrs.flags &= ~WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001871 break;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001872 case TYPE_STATUS_BAR:
1873
1874 // If the Keyguard is in a hidden state (occluded by another window), we force to
1875 // remove the wallpaper and keyguard flag so that any change in-flight after setting
1876 // the keyguard as occluded wouldn't set these flags again.
1877 // See {@link #processKeyguardSetHiddenResultLw}.
1878 if (mKeyguardHidden) {
1879 attrs.flags &= ~WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
1880 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
1881 }
1882 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001883 }
Adrian Roos38502112014-04-09 21:04:11 +02001884
1885 if (attrs.type != TYPE_STATUS_BAR) {
1886 // The status bar is the only window allowed to exhibit keyguard behavior.
1887 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
1888 }
Adrian Roosea562512014-05-05 13:33:03 +02001889
1890 if (ActivityManager.isHighEndGfx()
1891 && (attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0) {
Adrian Roosf5e9b5c2014-09-10 15:27:41 +02001892 attrs.subtreeSystemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
Adrian Roosea562512014-05-05 13:33:03 +02001893 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
1894 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001895 }
RoboErik8a2cfc32014-05-16 11:19:38 -07001896
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001897 void readLidState() {
Jeff Brown2e7760e2012-04-11 15:14:55 -07001898 mLidState = mWindowManagerFuncs.getLidState();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001899 }
RoboErik8a2cfc32014-05-16 11:19:38 -07001900
Michael Wright3818c922014-09-02 13:59:07 -07001901 private void readCameraLensCoverState() {
1902 mCameraLensCoverState = mWindowManagerFuncs.getCameraLensCoverState();
1903 }
1904
Jeff Browndaa37532012-05-01 15:54:03 -07001905 private boolean isHidden(int accessibilityMode) {
1906 switch (accessibilityMode) {
1907 case 1:
1908 return mLidState == LID_CLOSED;
1909 case 2:
1910 return mLidState == LID_OPEN;
1911 default:
1912 return false;
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001913 }
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001914 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001915
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001916 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07001917 @Override
Jeff Browndaa37532012-05-01 15:54:03 -07001918 public void adjustConfigurationLw(Configuration config, int keyboardPresence,
1919 int navigationPresence) {
1920 mHaveBuiltInKeyboard = (keyboardPresence & PRESENCE_INTERNAL) != 0;
1921
Jeff Brownf71343d2013-05-31 17:59:11 -07001922 readConfigurationDependentBehaviors();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001923 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07001924 applyLidSwitchState();
Jeff Brownd04a88c2011-01-16 14:05:47 -08001925
Jeff Browndaa37532012-05-01 15:54:03 -07001926 if (config.keyboard == Configuration.KEYBOARD_NOKEYS
1927 || (keyboardPresence == PRESENCE_INTERNAL
1928 && isHidden(mLidKeyboardAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001929 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_YES;
Jeff Browndaa37532012-05-01 15:54:03 -07001930 if (!mHasSoftInput) {
1931 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_YES;
1932 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001933 }
1934
Jeff Browndaa37532012-05-01 15:54:03 -07001935 if (config.navigation == Configuration.NAVIGATION_NONAV
1936 || (navigationPresence == PRESENCE_INTERNAL
1937 && isHidden(mLidNavigationAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001938 config.navigationHidden = Configuration.NAVIGATIONHIDDEN_YES;
Jeff Brownd04a88c2011-01-16 14:05:47 -08001939 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001940 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001941
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001942 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07001943 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001944 public int windowTypeToLayerLw(int type) {
1945 if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001946 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001947 }
1948 switch (type) {
keunyounga446bf02013-06-21 19:07:57 -07001949 case TYPE_PRIVATE_PRESENTATION:
1950 return 2;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001951 case TYPE_WALLPAPER:
1952 // wallpaper is at the bottom, though the window manager may move it.
1953 return 2;
1954 case TYPE_PHONE:
1955 return 3;
1956 case TYPE_SEARCH_BAR:
Jorim Jaggi225d3b52015-04-01 11:18:57 -07001957 case TYPE_VOICE_INTERACTION_STARTING:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001958 return 4;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001959 case TYPE_VOICE_INTERACTION:
1960 // voice interaction layer is almost immediately above apps.
1961 return 5;
Selim Cinekf83e8242015-05-19 18:08:14 -07001962 case TYPE_INPUT_CONSUMER:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001963 return 6;
Selim Cinekf83e8242015-05-19 18:08:14 -07001964 case TYPE_SYSTEM_DIALOG:
1965 return 7;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001966 case TYPE_TOAST:
1967 // toasts and the plugged-in battery thing
Selim Cinekf83e8242015-05-19 18:08:14 -07001968 return 8;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001969 case TYPE_PRIORITY_PHONE:
1970 // SIM errors and unlock. Not sure if this really should be in a high layer.
Selim Cinekf83e8242015-05-19 18:08:14 -07001971 return 9;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001972 case TYPE_DREAM:
1973 // used for Dreams (screensavers with TYPE_DREAM windows)
Selim Cinekf83e8242015-05-19 18:08:14 -07001974 return 10;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001975 case TYPE_SYSTEM_ALERT:
1976 // like the ANR / app crashed dialogs
Selim Cinekf83e8242015-05-19 18:08:14 -07001977 return 11;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001978 case TYPE_INPUT_METHOD:
1979 // on-screen keyboards and other such input method user interfaces go here.
Selim Cinekf83e8242015-05-19 18:08:14 -07001980 return 12;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001981 case TYPE_INPUT_METHOD_DIALOG:
1982 // on-screen keyboards and other such input method user interfaces go here.
Selim Cinekf83e8242015-05-19 18:08:14 -07001983 return 13;
Jim Miller5ecd8112013-01-09 18:50:26 -08001984 case TYPE_KEYGUARD_SCRIM:
1985 // the safety window that shows behind keyguard while keyguard is starting
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001986 return 14;
Selim Cinekf83e8242015-05-19 18:08:14 -07001987 case TYPE_STATUS_BAR_SUB_PANEL:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001988 return 15;
Selim Cinekf83e8242015-05-19 18:08:14 -07001989 case TYPE_STATUS_BAR:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001990 return 16;
Selim Cinekf83e8242015-05-19 18:08:14 -07001991 case TYPE_STATUS_BAR_PANEL:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001992 return 17;
Selim Cinekf83e8242015-05-19 18:08:14 -07001993 case TYPE_KEYGUARD_DIALOG:
1994 return 18;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001995 case TYPE_VOLUME_OVERLAY:
1996 // the on-screen volume indicator and controller shown when the user
1997 // changes the device volume
Selim Cinekf83e8242015-05-19 18:08:14 -07001998 return 19;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001999 case TYPE_SYSTEM_OVERLAY:
2000 // the on-screen volume indicator and controller shown when the user
2001 // changes the device volume
Selim Cinekf83e8242015-05-19 18:08:14 -07002002 return 20;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002003 case TYPE_NAVIGATION_BAR:
2004 // the navigation bar, if available, shows atop most things
Selim Cinekf83e8242015-05-19 18:08:14 -07002005 return 21;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002006 case TYPE_NAVIGATION_BAR_PANEL:
2007 // some panels (e.g. search) need to show on top of the navigation bar
Selim Cinekf83e8242015-05-19 18:08:14 -07002008 return 22;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002009 case TYPE_SYSTEM_ERROR:
2010 // system-level error dialogs
Selim Cinekf83e8242015-05-19 18:08:14 -07002011 return 23;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002012 case TYPE_MAGNIFICATION_OVERLAY:
2013 // used to highlight the magnified portion of a display
Selim Cinekf83e8242015-05-19 18:08:14 -07002014 return 24;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002015 case TYPE_DISPLAY_OVERLAY:
2016 // used to simulate secondary display devices
Selim Cinekf83e8242015-05-19 18:08:14 -07002017 return 25;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002018 case TYPE_DRAG:
2019 // the drag layer: input for drag-and-drop is associated with this window,
2020 // which sits above all other focusable windows
Selim Cinekf83e8242015-05-19 18:08:14 -07002021 return 26;
Svetoslav3a5c7212014-10-14 09:54:26 -07002022 case TYPE_ACCESSIBILITY_OVERLAY:
2023 // overlay put by accessibility services to intercept user interaction
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002024 return 27;
Selim Cinekf83e8242015-05-19 18:08:14 -07002025 case TYPE_SECURE_SYSTEM_OVERLAY:
Svetoslav3a5c7212014-10-14 09:54:26 -07002026 return 28;
Selim Cinekf83e8242015-05-19 18:08:14 -07002027 case TYPE_BOOT_PROGRESS:
2028 return 29;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002029 case TYPE_POINTER:
2030 // the (mouse) pointer layer
Svetoslav3a5c7212014-10-14 09:54:26 -07002031 return 30;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002032 }
2033 Log.e(TAG, "Unknown window type: " + type);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002034 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002035 }
2036
2037 /** {@inheritDoc} */
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002038 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002039 public int subWindowTypeToLayerLw(int type) {
2040 switch (type) {
2041 case TYPE_APPLICATION_PANEL:
2042 case TYPE_APPLICATION_ATTACHED_DIALOG:
2043 return APPLICATION_PANEL_SUBLAYER;
2044 case TYPE_APPLICATION_MEDIA:
2045 return APPLICATION_MEDIA_SUBLAYER;
Dianne Hackborn5cb8d792009-05-21 17:34:15 -07002046 case TYPE_APPLICATION_MEDIA_OVERLAY:
2047 return APPLICATION_MEDIA_OVERLAY_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002048 case TYPE_APPLICATION_SUB_PANEL:
2049 return APPLICATION_SUB_PANEL_SUBLAYER;
Wale Ogunwale0a4dc222015-04-14 12:58:42 -07002050 case TYPE_APPLICATION_ABOVE_SUB_PANEL:
2051 return APPLICATION_ABOVE_SUB_PANEL_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002052 }
2053 Log.e(TAG, "Unknown sub-window type: " + type);
2054 return 0;
2055 }
2056
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002057 @Override
Dianne Hackbornabe0da02009-09-18 01:55:39 -07002058 public int getMaxWallpaperLayer() {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002059 return windowTypeToLayerLw(TYPE_STATUS_BAR);
Dianne Hackbornabe0da02009-09-18 01:55:39 -07002060 }
2061
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002062 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002063 public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07002064 if (mHasNavigationBar) {
2065 // For a basic navigation bar, when we are in landscape mode we place
2066 // the navigation bar to the side.
Daniel Sandler4a066c52012-04-20 14:49:13 -04002067 if (mNavigationBarCanMove && fullWidth > fullHeight) {
2068 return fullWidth - mNavigationBarWidthForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07002069 }
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002070 }
2071 return fullWidth;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002072 }
2073
Jose Lima9546b202014-07-02 17:21:51 -07002074 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002075 public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07002076 if (mHasNavigationBar) {
2077 // For a basic navigation bar, when we are in portrait mode we place
2078 // the navigation bar to the bottom.
Daniel Sandler4a066c52012-04-20 14:49:13 -04002079 if (!mNavigationBarCanMove || fullWidth < fullHeight) {
2080 return fullHeight - mNavigationBarHeightForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07002081 }
2082 }
2083 return fullHeight;
Dianne Hackborn69cb8752011-05-19 18:13:32 -07002084 }
2085
Jose Lima9546b202014-07-02 17:21:51 -07002086 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002087 public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation) {
2088 return getNonDecorDisplayWidth(fullWidth, fullHeight, rotation);
Dianne Hackborn69cb8752011-05-19 18:13:32 -07002089 }
2090
Jose Lima9546b202014-07-02 17:21:51 -07002091 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002092 public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation) {
John Spurlock80f00c12013-06-13 11:10:51 -04002093 // There is a separate status bar at the top of the display. We don't count that as part
2094 // of the fixed decor, since it can hide; however, for purposes of configurations,
Dianne Hackborn077ee852012-04-09 16:27:07 -07002095 // we do want to exclude it since applications can't generally use that part
2096 // of the screen.
John Spurlock80f00c12013-06-13 11:10:51 -04002097 return getNonDecorDisplayHeight(fullWidth, fullHeight, rotation) - mStatusBarHeight;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002098 }
2099
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002100 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07002101 public boolean isForceHiding(WindowManager.LayoutParams attrs) {
2102 return (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 ||
Jim Millerab954542014-10-10 18:21:49 -07002103 (isKeyguardHostWindow(attrs) &&
2104 (mKeyguardDelegate != null && mKeyguardDelegate.isShowing())) ||
Adrian Roos69e510d2014-07-13 14:57:59 +02002105 (attrs.type == TYPE_KEYGUARD_SCRIM);
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002106 }
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002107
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002108 @Override
Jorim Jaggi0d674622014-05-21 01:34:15 +02002109 public boolean isKeyguardHostWindow(WindowManager.LayoutParams attrs) {
2110 return attrs.type == TYPE_STATUS_BAR;
2111 }
2112
2113 @Override
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002114 public boolean canBeForceHidden(WindowState win, WindowManager.LayoutParams attrs) {
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002115 switch (attrs.type) {
2116 case TYPE_STATUS_BAR:
2117 case TYPE_NAVIGATION_BAR:
2118 case TYPE_WALLPAPER:
2119 case TYPE_DREAM:
Jim Miller5ecd8112013-01-09 18:50:26 -08002120 case TYPE_KEYGUARD_SCRIM:
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002121 return false;
2122 default:
Adrian Roos461829d2015-06-03 14:41:18 -07002123 // Hide only windows below the keyguard host window.
2124 return windowTypeToLayerLw(win.getBaseType())
2125 < windowTypeToLayerLw(TYPE_STATUS_BAR);
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002126 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002127 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002128
Craig Mautner7d7808f2014-09-11 18:02:38 -07002129 @Override
2130 public WindowState getWinShowWhenLockedLw() {
2131 return mWinShowWhenLocked;
2132 }
2133
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002134 /** {@inheritDoc} */
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002135 @Override
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07002136 public View addStartingWindow(IBinder appToken, String packageName, int theme,
2137 CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes,
Adam Powell04fe6eb2013-05-31 14:39:48 -07002138 int icon, int logo, int windowFlags) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002139 if (!SHOW_STARTING_ANIMATIONS) {
2140 return null;
2141 }
2142 if (packageName == null) {
2143 return null;
2144 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002145
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002146 WindowManager wm = null;
2147 View view = null;
2148
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002149 try {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002150 Context context = mContext;
Craig Mautner6fbda632012-07-03 09:26:39 -07002151 if (DEBUG_STARTING_WINDOW) Slog.d(TAG, "addStartingWindow " + packageName
2152 + ": nonLocalizedLabel=" + nonLocalizedLabel + " theme="
2153 + Integer.toHexString(theme));
Dianne Hackborn247fe742011-01-08 17:25:57 -08002154 if (theme != context.getThemeResId() || labelRes != 0) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002155 try {
2156 context = context.createPackageContext(packageName, 0);
Dianne Hackborn247fe742011-01-08 17:25:57 -08002157 context.setTheme(theme);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002158 } catch (PackageManager.NameNotFoundException e) {
2159 // Ignore
2160 }
2161 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002162
Jorim Jaggia16cc152015-06-01 16:55:05 -07002163 PhoneWindow win = new PhoneWindow(context);
2164 win.setIsStartingWindow(true);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002165 final TypedArray ta = win.getWindowStyle();
2166 if (ta.getBoolean(
2167 com.android.internal.R.styleable.Window_windowDisablePreview, false)
2168 || ta.getBoolean(
2169 com.android.internal.R.styleable.Window_windowShowWallpaper,false)) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002170 return null;
2171 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002172
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002173 Resources r = context.getResources();
2174 win.setTitle(r.getText(labelRes, nonLocalizedLabel));
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002175
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002176 win.setType(
2177 WindowManager.LayoutParams.TYPE_APPLICATION_STARTING);
Adrian Roos602c68e2015-04-24 16:03:47 -07002178
2179 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
2180 // Assumes it's safe to show starting windows of launched apps while
2181 // the keyguard is being hidden. This is okay because starting windows never show
2182 // secret information.
2183 if (mKeyguardHidden) {
2184 windowFlags |= FLAG_SHOW_WHEN_LOCKED;
2185 }
2186 }
2187
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002188 // Force the window flags: this is a fake window, so it is not really
2189 // touchable or focusable by the user. We also add in the ALT_FOCUSABLE_IM
2190 // flag because we do know that the next window will take input
2191 // focus, so we want to get the IME window up on top of us right away.
2192 win.setFlags(
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08002193 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002194 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
2195 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
2196 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08002197 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002198 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
2199 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
2200 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002201
Adam Powell04fe6eb2013-05-31 14:39:48 -07002202 win.setDefaultIcon(icon);
2203 win.setDefaultLogo(logo);
2204
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002205 win.setLayout(WindowManager.LayoutParams.MATCH_PARENT,
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07002206 WindowManager.LayoutParams.MATCH_PARENT);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002207
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002208 final WindowManager.LayoutParams params = win.getAttributes();
2209 params.token = appToken;
2210 params.packageName = packageName;
2211 params.windowAnimations = win.getWindowStyle().getResourceId(
2212 com.android.internal.R.styleable.Window_windowAnimationStyle, 0);
John Reck61375a82014-09-18 19:27:48 +00002213 params.privateFlags |=
2214 WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED;
Craig Mautner88400d32012-09-30 12:35:45 -07002215 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
Adam Lesinski95c42972013-10-02 10:13:27 -07002216
2217 if (!compatInfo.supportsScreen()) {
2218 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
2219 }
2220
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002221 params.setTitle("Starting " + packageName);
2222
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002223 wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
2224 view = win.getDecorView();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002225
2226 if (win.isFloating()) {
2227 // Whoops, there is no way to display an animation/preview
2228 // of such a thing! After all that work... let's skip it.
2229 // (Note that we must do this here because it is in
2230 // getDecorView() where the theme is evaluated... maybe
2231 // we should peek the floating attribute from the theme
2232 // earlier.)
2233 return null;
2234 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002235
Craig Mautner6fbda632012-07-03 09:26:39 -07002236 if (DEBUG_STARTING_WINDOW) Slog.d(
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002237 TAG, "Adding starting window for " + packageName
2238 + " / " + appToken + ": "
2239 + (view.getParent() != null ? view : null));
2240
2241 wm.addView(view, params);
2242
2243 // Only return the view if it was successfully added to the
2244 // window manager... which we can tell by it having a parent.
2245 return view.getParent() != null ? view : null;
Jeff Brown98365d72012-08-19 20:30:52 -07002246 } catch (WindowManager.BadTokenException e) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002247 // ignore
Craig Mautner42bf39e2014-02-21 16:46:22 -08002248 Log.w(TAG, appToken + " already running, starting window not displayed. " +
2249 e.getMessage());
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002250 } catch (RuntimeException e) {
2251 // don't crash if something else bad happens, for example a
2252 // failure loading resources because we are loading from an app
2253 // on external storage that has been unmounted.
2254 Log.w(TAG, appToken + " failed creating starting window", e);
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002255 } finally {
2256 if (view != null && view.getParent() == null) {
2257 Log.w(TAG, "view not successfully added to wm, removing view");
2258 wm.removeViewImmediate(view);
2259 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002260 }
2261
2262 return null;
2263 }
2264
2265 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07002266 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002267 public void removeStartingWindow(IBinder appToken, View window) {
Craig Mautner276a6eb2014-11-04 15:32:57 -08002268 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Removing starting window for " + appToken + ": "
2269 + window + " Callers=" + Debug.getCallers(4));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002270
2271 if (window != null) {
Dianne Hackborn5fd21692011-06-07 14:09:47 -07002272 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002273 wm.removeView(window);
2274 }
2275 }
2276
2277 /**
2278 * Preflight adding a window to the system.
RoboErik8a2cfc32014-05-16 11:19:38 -07002279 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002280 * Currently enforces that three window types are singletons:
2281 * <ul>
2282 * <li>STATUS_BAR_TYPE</li>
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002283 * <li>KEYGUARD_TYPE</li>
2284 * </ul>
RoboErik8a2cfc32014-05-16 11:19:38 -07002285 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002286 * @param win The window to be added
2287 * @param attrs Information about the window to be added
RoboErik8a2cfc32014-05-16 11:19:38 -07002288 *
Jeff Brown98365d72012-08-19 20:30:52 -07002289 * @return If ok, WindowManagerImpl.ADD_OKAY. If too many singletons,
2290 * WindowManagerImpl.ADD_MULTIPLE_SINGLETON
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002291 */
Jose Lima9546b202014-07-02 17:21:51 -07002292 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002293 public int prepareAddWindowLw(WindowState win, WindowManager.LayoutParams attrs) {
2294 switch (attrs.type) {
2295 case TYPE_STATUS_BAR:
Joe Onorato8bc6c512010-06-04 16:21:12 -04002296 mContext.enforceCallingOrSelfPermission(
2297 android.Manifest.permission.STATUS_BAR_SERVICE,
2298 "PhoneWindowManager");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002299 if (mStatusBar != null) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002300 if (mStatusBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07002301 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002302 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002303 }
2304 mStatusBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04002305 mStatusBarController.setWindow(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002306 break;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002307 case TYPE_NAVIGATION_BAR:
2308 mContext.enforceCallingOrSelfPermission(
2309 android.Manifest.permission.STATUS_BAR_SERVICE,
2310 "PhoneWindowManager");
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002311 if (mNavigationBar != null) {
2312 if (mNavigationBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07002313 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002314 }
2315 }
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002316 mNavigationBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04002317 mNavigationBarController.setWindow(win);
Craig Mautnereda67292013-04-28 13:50:14 -07002318 if (DEBUG_LAYOUT) Slog.i(TAG, "NAVIGATION BAR: " + mNavigationBar);
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002319 break;
Jim Millere898ac52012-04-06 17:10:57 -07002320 case TYPE_NAVIGATION_BAR_PANEL:
Dianne Hackborn08743722009-12-21 12:16:51 -08002321 case TYPE_STATUS_BAR_PANEL:
Joe Onorato29fc2c92010-11-24 10:26:50 -08002322 case TYPE_STATUS_BAR_SUB_PANEL:
Jorim Jaggi225d3b52015-04-01 11:18:57 -07002323 case TYPE_VOICE_INTERACTION_STARTING:
Joe Onorato29fc2c92010-11-24 10:26:50 -08002324 mContext.enforceCallingOrSelfPermission(
2325 android.Manifest.permission.STATUS_BAR_SERVICE,
2326 "PhoneWindowManager");
Joe Onorato29fc2c92010-11-24 10:26:50 -08002327 break;
Jim Miller5ecd8112013-01-09 18:50:26 -08002328 case TYPE_KEYGUARD_SCRIM:
Jim Miller25190572013-02-28 17:36:24 -08002329 if (mKeyguardScrim != null) {
2330 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
2331 }
Jim Miller5ecd8112013-01-09 18:50:26 -08002332 mKeyguardScrim = win;
2333 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002334 }
Jeff Brown98365d72012-08-19 20:30:52 -07002335 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002336 }
2337
2338 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07002339 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002340 public void removeWindowLw(WindowState win) {
2341 if (mStatusBar == win) {
2342 mStatusBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04002343 mStatusBarController.setWindow(null);
Jim Millerc0b676d2013-03-22 16:11:08 -07002344 mKeyguardDelegate.showScrim();
Jim Miller5ecd8112013-01-09 18:50:26 -08002345 } else if (mKeyguardScrim == win) {
2346 Log.v(TAG, "Removing keyguard scrim");
2347 mKeyguardScrim = null;
2348 } if (mNavigationBar == win) {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002349 mNavigationBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04002350 mNavigationBarController.setWindow(null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002351 }
2352 }
2353
2354 static final boolean PRINT_ANIM = false;
RoboErik8a2cfc32014-05-16 11:19:38 -07002355
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002356 /** {@inheritDoc} */
Craig Mautner4b71aa12012-12-27 17:20:01 -08002357 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002358 public int selectAnimationLw(WindowState win, int transit) {
2359 if (PRINT_ANIM) Log.i(TAG, "selectAnimation in " + win
2360 + ": transit=" + transit);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002361 if (win == mStatusBar) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002362 boolean isKeyguard = (win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002363 if (transit == TRANSIT_EXIT
2364 || transit == TRANSIT_HIDE) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002365 return isKeyguard ? -1 : R.anim.dock_top_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002366 } else if (transit == TRANSIT_ENTER
2367 || transit == TRANSIT_SHOW) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002368 return isKeyguard ? -1 : R.anim.dock_top_enter;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002369 }
2370 } else if (win == mNavigationBar) {
2371 // This can be on either the bottom or the right.
2372 if (mNavigationBarOnBottom) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08002373 if (transit == TRANSIT_EXIT
2374 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002375 return R.anim.dock_bottom_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002376 } else if (transit == TRANSIT_ENTER
2377 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002378 return R.anim.dock_bottom_enter;
2379 }
2380 } else {
Craig Mautner4b71aa12012-12-27 17:20:01 -08002381 if (transit == TRANSIT_EXIT
2382 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002383 return R.anim.dock_right_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002384 } else if (transit == TRANSIT_ENTER
2385 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002386 return R.anim.dock_right_enter;
2387 }
2388 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08002389 }
2390
2391 if (transit == TRANSIT_PREVIEW_DONE) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002392 if (win.hasAppShownWindows()) {
2393 if (PRINT_ANIM) Log.i(TAG, "**** STARTING EXIT");
2394 return com.android.internal.R.anim.app_starting_exit;
2395 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07002396 } else if (win.getAttrs().type == TYPE_DREAM && mDreamingLockscreen
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002397 && transit == TRANSIT_ENTER) {
2398 // Special case: we are animating in a dream, while the keyguard
2399 // is shown. We don't want an animation on the dream, because
2400 // we need it shown immediately with the keyguard animating away
2401 // to reveal it.
2402 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002403 }
2404
2405 return 0;
2406 }
2407
Craig Mautner3c174372013-02-21 17:54:37 -08002408 @Override
2409 public void selectRotationAnimationLw(int anim[]) {
2410 if (PRINT_ANIM) Slog.i(TAG, "selectRotationAnimation mTopFullscreen="
2411 + mTopFullscreenOpaqueWindowState + " rotationAnimation="
2412 + (mTopFullscreenOpaqueWindowState == null ?
2413 "0" : mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation));
2414 if (mTopFullscreenOpaqueWindowState != null && mTopIsFullscreen) {
2415 switch (mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation) {
2416 case ROTATION_ANIMATION_CROSSFADE:
2417 anim[0] = R.anim.rotation_animation_xfade_exit;
2418 anim[1] = R.anim.rotation_animation_enter;
2419 break;
2420 case ROTATION_ANIMATION_JUMPCUT:
2421 anim[0] = R.anim.rotation_animation_jump_exit;
2422 anim[1] = R.anim.rotation_animation_enter;
2423 break;
2424 case ROTATION_ANIMATION_ROTATE:
2425 default:
2426 anim[0] = anim[1] = 0;
2427 break;
2428 }
2429 } else {
2430 anim[0] = anim[1] = 0;
2431 }
2432 }
2433
2434 @Override
2435 public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId,
2436 boolean forceDefault) {
2437 switch (exitAnimId) {
2438 case R.anim.rotation_animation_xfade_exit:
2439 case R.anim.rotation_animation_jump_exit:
2440 // These are the only cases that matter.
2441 if (forceDefault) {
2442 return false;
2443 }
2444 int anim[] = new int[2];
2445 selectRotationAnimationLw(anim);
2446 return (exitAnimId == anim[0] && enterAnimId == anim[1]);
2447 default:
2448 return true;
2449 }
2450 }
2451
2452 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002453 public Animation createForceHideEnterAnimation(boolean onWallpaper,
2454 boolean goingToNotificationShade) {
2455 if (goingToNotificationShade) {
2456 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_behind_enter_fade_in);
Craig Mautnerb8340802014-11-04 15:32:57 -08002457 }
Craig Mautner276a6eb2014-11-04 15:32:57 -08002458
2459 AnimationSet set = (AnimationSet) AnimationUtils.loadAnimation(mContext, onWallpaper ?
2460 R.anim.lock_screen_behind_enter_wallpaper :
2461 R.anim.lock_screen_behind_enter);
2462
2463 // TODO: Use XML interpolators when we have log interpolators available in XML.
2464 final List<Animation> animations = set.getAnimations();
2465 for (int i = animations.size() - 1; i >= 0; --i) {
2466 animations.get(i).setInterpolator(mLogDecelerateInterpolator);
2467 }
2468
2469 return set;
Jorim Jaggi76a16232014-08-08 17:00:47 +02002470 }
2471
2472
2473 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002474 public Animation createForceHideWallpaperExitAnimation(boolean goingToNotificationShade) {
2475 if (goingToNotificationShade) {
2476 return null;
2477 } else {
2478 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_wallpaper_exit);
2479 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002480 }
John Spurlockc8b46ca2013-04-08 12:59:26 -04002481
2482 private static void awakenDreams() {
2483 IDreamManager dreamManager = getDreamManager();
2484 if (dreamManager != null) {
2485 try {
2486 dreamManager.awaken();
2487 } catch (RemoteException e) {
2488 // fine, stay asleep then
2489 }
2490 }
2491 }
2492
2493 static IDreamManager getDreamManager() {
2494 return IDreamManager.Stub.asInterface(
2495 ServiceManager.checkService(DreamService.DREAM_SERVICE));
2496 }
2497
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002498 TelecomManager getTelecommService() {
2499 return (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002500 }
2501
Jeff Brown4d396052010-10-29 21:50:21 -07002502 static IAudioService getAudioService() {
2503 IAudioService audioService = IAudioService.Stub.asInterface(
2504 ServiceManager.checkService(Context.AUDIO_SERVICE));
2505 if (audioService == null) {
2506 Log.w(TAG, "Unable to find IAudioService interface.");
2507 }
2508 return audioService;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002509 }
2510
2511 boolean keyguardOn() {
Jim Millerab954542014-10-10 18:21:49 -07002512 return isKeyguardShowingAndNotOccluded() || inKeyguardRestrictedKeyInputMode();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002513 }
2514
2515 private static final int[] WINDOW_TYPES_WHERE_HOME_DOESNT_WORK = {
2516 WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
2517 WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
2518 };
2519
2520 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002521 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002522 public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002523 final boolean keyguardOn = keyguardOn();
Jeff Brown1f245102010-11-18 20:53:46 -08002524 final int keyCode = event.getKeyCode();
2525 final int repeatCount = event.getRepeatCount();
2526 final int metaState = event.getMetaState();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002527 final int flags = event.getFlags();
Jeff Brown1f245102010-11-18 20:53:46 -08002528 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
2529 final boolean canceled = event.isCanceled();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002530
Jeff Brown40013652012-05-16 21:22:36 -07002531 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002532 Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount="
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002533 + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed
2534 + " canceled=" + canceled);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002535 }
2536
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002537 // If we think we might have a volume down & power key chord on the way
2538 // but we're not sure, then tell the dispatcher to wait a little while and
2539 // try again later before dispatching.
Christopher Tatee90585f2012-03-05 18:56:25 -08002540 if (mScreenshotChordEnabled && (flags & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07002541 if (mScreenshotChordVolumeDownKeyTriggered && !mScreenshotChordPowerKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002542 final long now = SystemClock.uptimeMillis();
Jeff Brown13f00f02014-10-31 14:45:50 -07002543 final long timeoutTime = mScreenshotChordVolumeDownKeyTime
2544 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002545 if (now < timeoutTime) {
2546 return timeoutTime - now;
2547 }
2548 }
2549 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
Jeff Brown13f00f02014-10-31 14:45:50 -07002550 && mScreenshotChordVolumeDownKeyConsumed) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002551 if (!down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07002552 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002553 }
2554 return -1;
2555 }
2556 }
2557
Michael Wright6a62e552014-06-03 19:19:48 -07002558 // Cancel any pending meta actions if we see any other keys being pressed between the down
2559 // of the meta key and its corresponding up.
Michael Wright251e35d2014-08-22 15:40:27 -07002560 if (mPendingMetaAction && !KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07002561 mPendingMetaAction = false;
2562 }
2563
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002564 // First we always handle the home key here, so applications
2565 // can never break it, although if keyguard is on, we do let
2566 // it handle it, because that gives us the correct 5 second
2567 // timeout.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002568 if (keyCode == KeyEvent.KEYCODE_HOME) {
Michael Jurka7f2668c2012-03-27 07:49:52 -07002569
Jeff Brown49ed71d2010-12-06 17:13:33 -08002570 // If we have released the home key, and didn't do anything else
2571 // while it was pressed, then it is time to go home!
Michael Jurka7f2668c2012-03-27 07:49:52 -07002572 if (!down) {
Jeff Browncaca8812013-05-09 13:34:33 -07002573 cancelPreloadRecentApps();
2574
Jeff Brown49ed71d2010-12-06 17:13:33 -08002575 mHomePressed = false;
Jeff Browncaca8812013-05-09 13:34:33 -07002576 if (mHomeConsumed) {
2577 mHomeConsumed = false;
Michael Jurka7f2668c2012-03-27 07:49:52 -07002578 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002579 }
Jeff Browncaca8812013-05-09 13:34:33 -07002580
2581 if (canceled) {
2582 Log.i(TAG, "Ignoring HOME; event canceled.");
2583 return -1;
2584 }
2585
Yorke Lee4f803242014-12-15 23:22:06 +00002586 // If an incoming call is ringing, HOME is totally disabled.
2587 // (The user is already on the InCallUI at this point,
2588 // and his ONLY options are to answer or reject the call.)
2589 TelecomManager telecomManager = getTelecommService();
2590 if (telecomManager != null && telecomManager.isRinging()) {
2591 Log.i(TAG, "Ignoring HOME; there's a ringing incoming call.");
2592 return -1;
2593 }
2594
Jeff Browncaca8812013-05-09 13:34:33 -07002595 // Delay handling home if a double-tap is possible.
2596 if (mDoubleTapOnHomeBehavior != DOUBLE_TAP_HOME_NOTHING) {
2597 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); // just in case
2598 mHomeDoubleTapPending = true;
2599 mHandler.postDelayed(mHomeDoubleTapTimeoutRunnable,
2600 ViewConfiguration.getDoubleTapTimeout());
2601 return -1;
2602 }
2603
Jeff Brown13f00f02014-10-31 14:45:50 -07002604 handleShortPressOnHome();
Jeff Browncaca8812013-05-09 13:34:33 -07002605 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002606 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002607
2608 // If a system window has focus, then it doesn't make sense
2609 // right now to interact with applications.
2610 WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null;
2611 if (attrs != null) {
2612 final int type = attrs.type;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002613 if (type == WindowManager.LayoutParams.TYPE_KEYGUARD_SCRIM
2614 || type == WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG
2615 || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002616 // the "app" is keyguard, so give it the key
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002617 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002618 }
2619 final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length;
2620 for (int i=0; i<typeCount; i++) {
2621 if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) {
2622 // don't do anything, but also don't pass it to the app
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002623 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002624 }
2625 }
2626 }
Jeff Browncaca8812013-05-09 13:34:33 -07002627
2628 // Remember that home is pressed and handle special actions.
2629 if (repeatCount == 0) {
2630 mHomePressed = true;
2631 if (mHomeDoubleTapPending) {
2632 mHomeDoubleTapPending = false;
2633 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable);
2634 handleDoubleTapOnHome();
2635 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI
2636 || mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
2637 preloadRecentApps();
Michael Jurka7f2668c2012-03-27 07:49:52 -07002638 }
Jeff Browncaca8812013-05-09 13:34:33 -07002639 } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) {
2640 if (!keyguardOn) {
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07002641 handleLongPressOnHome(event.getDeviceId());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002642 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002643 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002644 return -1;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002645 } else if (keyCode == KeyEvent.KEYCODE_MENU) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002646 // Hijack modified menu keys for debugging features
2647 final int chordBug = KeyEvent.META_SHIFT_ON;
2648
2649 if (down && repeatCount == 0) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002650 if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002651 Intent intent = new Intent(Intent.ACTION_BUG_REPORT);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002652 mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT,
2653 null, null, null, 0, null, null);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002654 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002655 } else if (SHOW_PROCESSES_ON_ALT_MENU &&
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002656 (metaState & KeyEvent.META_ALT_ON) == KeyEvent.META_ALT_ON) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002657 Intent service = new Intent();
2658 service.setClassName(mContext, "com.android.server.LoadAverageService");
2659 ContentResolver res = mContext.getContentResolver();
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002660 boolean shown = Settings.Global.getInt(
2661 res, Settings.Global.SHOW_PROCESSES, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002662 if (!shown) {
2663 mContext.startService(service);
2664 } else {
2665 mContext.stopService(service);
2666 }
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002667 Settings.Global.putInt(
2668 res, Settings.Global.SHOW_PROCESSES, shown ? 0 : 1);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002669 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002670 }
2671 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002672 } else if (keyCode == KeyEvent.KEYCODE_SEARCH) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002673 if (down) {
2674 if (repeatCount == 0) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002675 mSearchKeyShortcutPending = true;
2676 mConsumeSearchKeyUp = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002677 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002678 } else {
2679 mSearchKeyShortcutPending = false;
2680 if (mConsumeSearchKeyUp) {
2681 mConsumeSearchKeyUp = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002682 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002683 }
2684 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002685 return 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002686 } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) {
Michael Wrightc9ebea72013-01-16 19:25:02 -08002687 if (!keyguardOn) {
Jeff Browncaca8812013-05-09 13:34:33 -07002688 if (down && repeatCount == 0) {
2689 preloadRecentApps();
2690 } else if (!down) {
2691 toggleRecentApps();
Michael Wrightc9ebea72013-01-16 19:25:02 -08002692 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002693 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002694 return -1;
Jun Mukaid21b3c82015-04-23 14:09:34 -07002695 } else if (keyCode == KeyEvent.KEYCODE_N && event.isMetaPressed()) {
2696 if (down) {
2697 IStatusBarService service = getStatusBarService();
2698 if (service != null) {
2699 try {
2700 service.expandNotificationsPanel();
2701 } catch (RemoteException e) {
2702 // do nothing.
2703 }
2704 }
2705 }
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002706 } else if (keyCode == KeyEvent.KEYCODE_ASSIST) {
2707 if (down) {
2708 if (repeatCount == 0) {
2709 mAssistKeyLongPressed = false;
2710 } else if (repeatCount == 1) {
2711 mAssistKeyLongPressed = true;
2712 if (!keyguardOn) {
2713 launchAssistLongPressAction();
2714 }
2715 }
2716 } else {
2717 if (mAssistKeyLongPressed) {
2718 mAssistKeyLongPressed = false;
2719 } else {
2720 if (!keyguardOn) {
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07002721 launchAssistAction(null, event.getDeviceId());
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002722 }
2723 }
2724 }
2725 return -1;
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002726 } else if (keyCode == KeyEvent.KEYCODE_VOICE_ASSIST) {
2727 if (!down) {
2728 Intent voiceIntent;
Michael Wright869a67c2014-08-26 19:33:06 -07002729 if (!keyguardOn) {
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002730 voiceIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
2731 } else {
2732 voiceIntent = new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
Michael Wright869a67c2014-08-26 19:33:06 -07002733 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, true);
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002734 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00002735 startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002736 }
Jeff Sharkey2991fa32012-12-05 18:06:43 -08002737 } else if (keyCode == KeyEvent.KEYCODE_SYSRQ) {
2738 if (down && repeatCount == 0) {
2739 mHandler.post(mScreenshotRunnable);
2740 }
2741 return -1;
Michael Wrightb854e242013-02-05 17:54:02 -08002742 } else if (keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP
2743 || keyCode == KeyEvent.KEYCODE_BRIGHTNESS_DOWN) {
2744 if (down) {
2745 int direction = keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP ? 1 : -1;
2746
2747 // Disable autobrightness if it's on
2748 int auto = Settings.System.getIntForUser(
2749 mContext.getContentResolver(),
2750 Settings.System.SCREEN_BRIGHTNESS_MODE,
2751 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2752 UserHandle.USER_CURRENT_OR_SELF);
2753 if (auto != 0) {
2754 Settings.System.putIntForUser(mContext.getContentResolver(),
2755 Settings.System.SCREEN_BRIGHTNESS_MODE,
2756 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2757 UserHandle.USER_CURRENT_OR_SELF);
2758 }
2759
2760 int min = mPowerManager.getMinimumScreenBrightnessSetting();
2761 int max = mPowerManager.getMaximumScreenBrightnessSetting();
2762 int step = (max - min + BRIGHTNESS_STEPS - 1) / BRIGHTNESS_STEPS * direction;
2763 int brightness = Settings.System.getIntForUser(mContext.getContentResolver(),
2764 Settings.System.SCREEN_BRIGHTNESS,
2765 mPowerManager.getDefaultScreenBrightnessSetting(),
2766 UserHandle.USER_CURRENT_OR_SELF);
2767 brightness += step;
2768 // Make sure we don't go beyond the limits.
2769 brightness = Math.min(max, brightness);
2770 brightness = Math.max(min, brightness);
2771
2772 Settings.System.putIntForUser(mContext.getContentResolver(),
2773 Settings.System.SCREEN_BRIGHTNESS, brightness,
2774 UserHandle.USER_CURRENT_OR_SELF);
Bart Sears8b1c27c2015-03-18 23:51:02 +00002775 startActivityAsUser(new Intent(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG),
Alan Viverette5a399492014-07-14 16:19:38 -07002776 UserHandle.CURRENT_OR_SELF);
Michael Wrightb854e242013-02-05 17:54:02 -08002777 }
2778 return -1;
Michael Wrightce0c13a2014-07-30 10:49:21 -07002779 } else if (KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07002780 if (down) {
2781 mPendingMetaAction = true;
2782 } else if (mPendingMetaAction) {
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07002783 launchAssistAction(Intent.EXTRA_ASSIST_INPUT_HINT_KEYBOARD, event.getDeviceId());
Michael Wright6a62e552014-06-03 19:19:48 -07002784 }
2785 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002786 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002787
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002788 // Shortcuts are invoked through Search+key, so intercept those here
Jeff Browncaab4d02010-12-09 22:13:41 -08002789 // Any printing key that is chorded with Search should be consumed
2790 // even if no shortcut was invoked. This prevents text from being
2791 // inadvertently inserted when using a keyboard that has built-in macro
2792 // shortcut keys (that emit Search+x) and some of them are not registered.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002793 if (mSearchKeyShortcutPending) {
Jeff Browncaab4d02010-12-09 22:13:41 -08002794 final KeyCharacterMap kcm = event.getKeyCharacterMap();
2795 if (kcm.isPrintingKey(keyCode)) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002796 mConsumeSearchKeyUp = true;
2797 mSearchKeyShortcutPending = false;
Jeff Browncaab4d02010-12-09 22:13:41 -08002798 if (down && repeatCount == 0 && !keyguardOn) {
2799 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState);
2800 if (shortcutIntent != null) {
2801 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002802 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00002803 startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002804 } catch (ActivityNotFoundException ex) {
2805 Slog.w(TAG, "Dropping shortcut key combination because "
2806 + "the activity to which it is registered was not found: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002807 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode), ex);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002808 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002809 } else {
2810 Slog.i(TAG, "Dropping unregistered shortcut key combination: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002811 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002812 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002813 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002814 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002815 }
2816 }
2817
Jeff Brown68b909d2011-12-07 16:36:01 -08002818 // Invoke shortcuts using Meta.
Jeff Brown602ab322012-05-16 13:33:47 -07002819 if (down && repeatCount == 0 && !keyguardOn
Jeff Brown68b909d2011-12-07 16:36:01 -08002820 && (metaState & KeyEvent.META_META_ON) != 0) {
2821 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brown602ab322012-05-16 13:33:47 -07002822 if (kcm.isPrintingKey(keyCode)) {
2823 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode,
2824 metaState & ~(KeyEvent.META_META_ON
2825 | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON));
2826 if (shortcutIntent != null) {
2827 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2828 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00002829 startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brown602ab322012-05-16 13:33:47 -07002830 } catch (ActivityNotFoundException ex) {
2831 Slog.w(TAG, "Dropping shortcut key combination because "
2832 + "the activity to which it is registered was not found: "
2833 + "META+" + KeyEvent.keyCodeToString(keyCode), ex);
2834 }
2835 return -1;
Jeff Brown68b909d2011-12-07 16:36:01 -08002836 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002837 }
2838 }
2839
Jeff Brown6651a632011-11-28 12:59:11 -08002840 // Handle application launch keys.
Jeff Brown602ab322012-05-16 13:33:47 -07002841 if (down && repeatCount == 0 && !keyguardOn) {
Jeff Brown6651a632011-11-28 12:59:11 -08002842 String category = sApplicationLaunchKeyCategories.get(keyCode);
2843 if (category != null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -08002844 Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category);
Jeff Brown6651a632011-11-28 12:59:11 -08002845 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2846 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00002847 startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brown6651a632011-11-28 12:59:11 -08002848 } catch (ActivityNotFoundException ex) {
2849 Slog.w(TAG, "Dropping application launch key because "
2850 + "the activity to which it is registered was not found: "
2851 + "keyCode=" + keyCode + ", category=" + category, ex);
2852 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002853 return -1;
Jeff Brown6651a632011-11-28 12:59:11 -08002854 }
2855 }
2856
Michael Wright61c46752014-08-21 16:57:33 -07002857 // Display task switcher for ALT-TAB.
Jeff Brown68b909d2011-12-07 16:36:01 -08002858 if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_TAB) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002859 if (mRecentAppsHeldModifiers == 0 && !keyguardOn) {
Jeff Brown68b909d2011-12-07 16:36:01 -08002860 final int shiftlessModifiers = event.getModifiers() & ~KeyEvent.META_SHIFT_MASK;
Michael Wright61c46752014-08-21 16:57:33 -07002861 if (KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_ALT_ON)) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002862 mRecentAppsHeldModifiers = shiftlessModifiers;
2863 showRecentApps(true);
Jeff Brown68b909d2011-12-07 16:36:01 -08002864 return -1;
2865 }
2866 }
Winson Chung1e8d71b2014-05-16 17:05:22 -07002867 } else if (!down && mRecentAppsHeldModifiers != 0
2868 && (metaState & mRecentAppsHeldModifiers) == 0) {
2869 mRecentAppsHeldModifiers = 0;
Winson Chungcdcd4872014-08-05 18:00:13 -07002870 hideRecentApps(true, false);
Jeff Brown68b909d2011-12-07 16:36:01 -08002871 }
2872
Jeff Browncf39bdf2012-05-18 14:41:19 -07002873 // Handle keyboard language switching.
2874 if (down && repeatCount == 0
2875 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2876 || (keyCode == KeyEvent.KEYCODE_SPACE
2877 && (metaState & KeyEvent.META_CTRL_MASK) != 0))) {
2878 int direction = (metaState & KeyEvent.META_SHIFT_MASK) != 0 ? -1 : 1;
2879 mWindowManagerFuncs.switchKeyboardLayout(event.getDeviceId(), direction);
2880 return -1;
2881 }
2882 if (mLanguageSwitchKeyPressed && !down
2883 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2884 || keyCode == KeyEvent.KEYCODE_SPACE)) {
2885 mLanguageSwitchKeyPressed = false;
2886 return -1;
2887 }
2888
Jeff Brown13f00f02014-10-31 14:45:50 -07002889 if (isValidGlobalKey(keyCode)
2890 && mGlobalKeyManager.handleGlobalKey(mContext, keyCode, event)) {
Justin Kohd378ad72013-04-01 12:18:26 -07002891 return -1;
2892 }
2893
Michael Wright6a62e552014-06-03 19:19:48 -07002894 // Reserve all the META modifier combos for system behavior
Michael Wrightce0c13a2014-07-30 10:49:21 -07002895 if ((metaState & KeyEvent.META_META_ON) != 0) {
Michael Wright6a62e552014-06-03 19:19:48 -07002896 return -1;
2897 }
2898
Jeff Brown68b909d2011-12-07 16:36:01 -08002899 // Let the application handle the key.
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002900 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002901 }
2902
Jeff Brown3915bb82010-11-05 15:02:16 -07002903 /** {@inheritDoc} */
2904 @Override
Jeff Brown49ed71d2010-12-06 17:13:33 -08002905 public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown54875002011-04-06 15:33:01 -07002906 // Note: This method is only called if the initial down was unhandled.
Jeff Brown40013652012-05-16 21:22:36 -07002907 if (DEBUG_INPUT) {
Jeff Brown1f245102010-11-18 20:53:46 -08002908 Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction()
2909 + ", flags=" + event.getFlags()
2910 + ", keyCode=" + event.getKeyCode()
2911 + ", scanCode=" + event.getScanCode()
2912 + ", metaState=" + event.getMetaState()
2913 + ", repeatCount=" + event.getRepeatCount()
2914 + ", policyFlags=" + policyFlags);
Jeff Brown3915bb82010-11-05 15:02:16 -07002915 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002916
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002917 KeyEvent fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002918 if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
2919 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002920 final int keyCode = event.getKeyCode();
2921 final int metaState = event.getMetaState();
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002922 final boolean initialDown = event.getAction() == KeyEvent.ACTION_DOWN
2923 && event.getRepeatCount() == 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002924
Jeff Brown54875002011-04-06 15:33:01 -07002925 // Check for fallback actions specified by the key character map.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002926 final FallbackAction fallbackAction;
2927 if (initialDown) {
2928 fallbackAction = kcm.getFallbackAction(keyCode, metaState);
2929 } else {
2930 fallbackAction = mFallbackActions.get(keyCode);
2931 }
2932
2933 if (fallbackAction != null) {
Jeff Brown40013652012-05-16 21:22:36 -07002934 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002935 Slog.d(TAG, "Fallback: keyCode=" + fallbackAction.keyCode
2936 + " metaState=" + Integer.toHexString(fallbackAction.metaState));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002937 }
2938
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002939 final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK;
2940 fallbackEvent = KeyEvent.obtain(
Jeff Brown49ed71d2010-12-06 17:13:33 -08002941 event.getDownTime(), event.getEventTime(),
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002942 event.getAction(), fallbackAction.keyCode,
2943 event.getRepeatCount(), fallbackAction.metaState,
Jeff Brown49ed71d2010-12-06 17:13:33 -08002944 event.getDeviceId(), event.getScanCode(),
2945 flags, event.getSource(), null);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002946
2947 if (!interceptFallback(win, fallbackEvent, policyFlags)) {
2948 fallbackEvent.recycle();
2949 fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002950 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002951
2952 if (initialDown) {
2953 mFallbackActions.put(keyCode, fallbackAction);
2954 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2955 mFallbackActions.remove(keyCode);
2956 fallbackAction.recycle();
2957 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002958 }
2959 }
2960
Jeff Brown40013652012-05-16 21:22:36 -07002961 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002962 if (fallbackEvent == null) {
2963 Slog.d(TAG, "No fallback.");
2964 } else {
2965 Slog.d(TAG, "Performing fallback: " + fallbackEvent);
2966 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002967 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002968 return fallbackEvent;
Jeff Brown3915bb82010-11-05 15:02:16 -07002969 }
2970
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002971 private boolean interceptFallback(WindowState win, KeyEvent fallbackEvent, int policyFlags) {
Jeff Brown037c33e2014-04-09 00:31:55 -07002972 int actions = interceptKeyBeforeQueueing(fallbackEvent, policyFlags);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002973 if ((actions & ACTION_PASS_TO_USER) != 0) {
2974 long delayMillis = interceptKeyBeforeDispatching(
2975 win, fallbackEvent, policyFlags);
2976 if (delayMillis == 0) {
2977 return true;
2978 }
2979 }
2980 return false;
Jeff Brown6f2fba42011-02-19 01:08:02 -08002981 }
2982
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002983 private void launchAssistLongPressAction() {
2984 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
2985 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
2986
2987 // launch the search activity
2988 Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS);
2989 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2990 try {
RoboErik8a2cfc32014-05-16 11:19:38 -07002991 // TODO: This only stops the factory-installed search manager.
Jim Miller45308b12012-06-18 19:23:39 -07002992 // Need to formalize an API to handle others
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002993 SearchManager searchManager = getSearchManager();
2994 if (searchManager != null) {
2995 searchManager.stopSearch();
2996 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00002997 startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002998 } catch (ActivityNotFoundException e) {
2999 Slog.w(TAG, "No activity to handle assist long press action.", e);
3000 }
3001 }
3002
3003 private void launchAssistAction() {
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07003004 launchAssistAction(null, Integer.MIN_VALUE);
Michael Wright8ab940a2014-09-01 11:01:27 -07003005 }
3006
3007 private void launchAssistAction(String hint) {
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07003008 launchAssistAction(hint, Integer.MIN_VALUE);
3009 }
3010
3011 private void launchAssistAction(String hint, int deviceId) {
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003012 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07003013 Bundle args = null;
3014 if (deviceId > Integer.MIN_VALUE) {
3015 args = new Bundle();
3016 args.putInt(Intent.EXTRA_ASSIST_INPUT_DEVICE_ID, deviceId);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003017 }
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07003018 ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE))
3019 .launchAssistAction(hint, UserHandle.myUserId(), args);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003020 }
3021
Bart Sears8b1c27c2015-03-18 23:51:02 +00003022 private void startActivityAsUser(Intent intent, UserHandle handle) {
3023 if (isUserSetupComplete()) {
3024 mContext.startActivityAsUser(intent, handle);
3025 } else {
3026 Slog.i(TAG, "Not starting activity because user setup is in progress: " + intent);
3027 }
3028 }
3029
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003030 private SearchManager getSearchManager() {
3031 if (mSearchManager == null) {
3032 mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
3033 }
3034 return mSearchManager;
3035 }
3036
Jeff Browncaca8812013-05-09 13:34:33 -07003037 private void preloadRecentApps() {
3038 mPreloadedRecentApps = true;
3039 try {
3040 IStatusBarService statusbar = getStatusBarService();
3041 if (statusbar != null) {
3042 statusbar.preloadRecentApps();
3043 }
3044 } catch (RemoteException e) {
3045 Slog.e(TAG, "RemoteException when preloading recent apps", e);
3046 // re-acquire status bar service next time it is needed.
3047 mStatusBarService = null;
3048 }
3049 }
3050
3051 private void cancelPreloadRecentApps() {
3052 if (mPreloadedRecentApps) {
3053 mPreloadedRecentApps = false;
3054 try {
3055 IStatusBarService statusbar = getStatusBarService();
3056 if (statusbar != null) {
3057 statusbar.cancelPreloadRecentApps();
3058 }
3059 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003060 Slog.e(TAG, "RemoteException when cancelling recent apps preload", e);
Jeff Browncaca8812013-05-09 13:34:33 -07003061 // re-acquire status bar service next time it is needed.
3062 mStatusBarService = null;
3063 }
3064 }
3065 }
3066
3067 private void toggleRecentApps() {
3068 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
Jeff Browncaca8812013-05-09 13:34:33 -07003069 try {
3070 IStatusBarService statusbar = getStatusBarService();
3071 if (statusbar != null) {
3072 statusbar.toggleRecentApps();
3073 }
3074 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003075 Slog.e(TAG, "RemoteException when toggling recent apps", e);
3076 // re-acquire status bar service next time it is needed.
3077 mStatusBarService = null;
3078 }
3079 }
3080
Craig Mautner84984fa2014-06-19 11:19:20 -07003081 @Override
3082 public void showRecentApps() {
3083 mHandler.removeMessages(MSG_DISPATCH_SHOW_RECENTS);
3084 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_RECENTS);
3085 }
3086
Winson Chung1e8d71b2014-05-16 17:05:22 -07003087 private void showRecentApps(boolean triggeredFromAltTab) {
3088 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
3089 try {
3090 IStatusBarService statusbar = getStatusBarService();
3091 if (statusbar != null) {
3092 statusbar.showRecentApps(triggeredFromAltTab);
3093 }
3094 } catch (RemoteException e) {
Jeff Browncaca8812013-05-09 13:34:33 -07003095 Slog.e(TAG, "RemoteException when showing recent apps", e);
3096 // re-acquire status bar service next time it is needed.
3097 mStatusBarService = null;
3098 }
3099 }
3100
Winson Chungcdcd4872014-08-05 18:00:13 -07003101 private void hideRecentApps(boolean triggeredFromAltTab, boolean triggeredFromHome) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003102 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
3103 try {
3104 IStatusBarService statusbar = getStatusBarService();
3105 if (statusbar != null) {
Winson Chungcdcd4872014-08-05 18:00:13 -07003106 statusbar.hideRecentApps(triggeredFromAltTab, triggeredFromHome);
Winson Chung1e8d71b2014-05-16 17:05:22 -07003107 }
3108 } catch (RemoteException e) {
3109 Slog.e(TAG, "RemoteException when closing recent apps", e);
3110 // re-acquire status bar service next time it is needed.
3111 mStatusBarService = null;
3112 }
3113 }
3114
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00003115 void launchHomeFromHotKey() {
Bryce Lee662ed802015-04-10 20:11:39 +00003116 launchHomeFromHotKey(true /* awakenFromDreams */, true /*respectKeyguard*/);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00003117 }
3118
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003119 /**
3120 * A home key -> launch home action was detected. Take the appropriate action
3121 * given the situation with the keyguard.
3122 */
Bryce Lee662ed802015-04-10 20:11:39 +00003123 void launchHomeFromHotKey(final boolean awakenFromDreams, final boolean respectKeyguard) {
3124 if (respectKeyguard) {
3125 if (isKeyguardShowingAndNotOccluded()) {
3126 // don't launch home if keyguard showing
3127 return;
3128 }
3129
3130 if (!mHideLockScreen && mKeyguardDelegate.isInputRestricted()) {
3131 // when in keyguard restricted mode, must first verify unlock
3132 // before launching home
3133 mKeyguardDelegate.verifyUnlock(new OnKeyguardExitResult() {
3134 @Override
3135 public void onKeyguardExitResult(boolean success) {
3136 if (success) {
3137 try {
3138 ActivityManagerNative.getDefault().stopAppSwitches();
3139 } catch (RemoteException e) {
3140 }
3141 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3142 startDockOrHome(true /*fromHomeKey*/, awakenFromDreams);
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07003143 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003144 }
Bryce Lee662ed802015-04-10 20:11:39 +00003145 });
3146 return;
3147 }
3148 }
3149
3150 // no keyguard stuff to worry about, just launch home!
3151 try {
3152 ActivityManagerNative.getDefault().stopAppSwitches();
3153 } catch (RemoteException e) {
3154 }
3155 if (mRecentsVisible) {
3156 // Hide Recents and notify it to launch Home
3157 if (awakenFromDreams) {
3158 awakenDreams();
3159 }
3160 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3161 hideRecentApps(false, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003162 } else {
Bryce Lee662ed802015-04-10 20:11:39 +00003163 // Otherwise, just launch Home
3164 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3165 startDockOrHome(true /*fromHomeKey*/, awakenFromDreams);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003166 }
3167 }
3168
John Spurlock04db1762013-05-13 12:46:41 -04003169 private final Runnable mClearHideNavigationFlag = new Runnable() {
3170 @Override
3171 public void run() {
3172 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
3173 // Clear flags.
3174 mForceClearedSystemUiFlags &=
3175 ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
3176 }
3177 mWindowManagerFuncs.reevaluateStatusBarVisibility();
Dianne Hackborne26ab702011-10-16 13:21:33 -07003178 }
3179 };
3180
3181 /**
3182 * Input handler used while nav bar is hidden. Captures any touch on the screen,
3183 * to determine when the nav bar should be shown and prevent applications from
3184 * receiving those touches.
3185 */
Jeff Brown32cbc38552011-12-01 14:01:49 -08003186 final class HideNavInputEventReceiver extends InputEventReceiver {
3187 public HideNavInputEventReceiver(InputChannel inputChannel, Looper looper) {
3188 super(inputChannel, looper);
3189 }
3190
Dianne Hackborndf89e652011-10-06 22:35:11 -07003191 @Override
Jeff Brown32cbc38552011-12-01 14:01:49 -08003192 public void onInputEvent(InputEvent event) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003193 boolean handled = false;
3194 try {
Jeff Brown4952dfd2011-11-30 19:23:22 -08003195 if (event instanceof MotionEvent
3196 && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
3197 final MotionEvent motionEvent = (MotionEvent)event;
3198 if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003199 // When the user taps down, we re-show the nav bar.
3200 boolean changed = false;
John Spurlock04db1762013-05-13 12:46:41 -04003201 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003202 // Any user activity always causes us to show the
3203 // navigation controls, if they had been hidden.
3204 // We also clear the low profile and only content
3205 // flags so that tapping on the screen will atomically
3206 // restore all currently hidden screen decorations.
3207 int newVal = mResettingSystemUiFlags |
3208 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
3209 View.SYSTEM_UI_FLAG_LOW_PROFILE |
3210 View.SYSTEM_UI_FLAG_FULLSCREEN;
Dianne Hackborne26ab702011-10-16 13:21:33 -07003211 if (mResettingSystemUiFlags != newVal) {
3212 mResettingSystemUiFlags = newVal;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003213 changed = true;
3214 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003215 // We don't allow the system's nav bar to be hidden
3216 // again for 1 second, to prevent applications from
3217 // spamming us and keeping it from being shown.
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003218 newVal = mForceClearedSystemUiFlags |
3219 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
Dianne Hackborne26ab702011-10-16 13:21:33 -07003220 if (mForceClearedSystemUiFlags != newVal) {
3221 mForceClearedSystemUiFlags = newVal;
3222 changed = true;
John Spurlock04db1762013-05-13 12:46:41 -04003223 mHandler.postDelayed(mClearHideNavigationFlag, 1000);
Dianne Hackborne26ab702011-10-16 13:21:33 -07003224 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07003225 }
3226 if (changed) {
3227 mWindowManagerFuncs.reevaluateStatusBarVisibility();
3228 }
3229 }
3230 }
3231 } finally {
Jeff Brown32cbc38552011-12-01 14:01:49 -08003232 finishInputEvent(event, handled);
Dianne Hackborndf89e652011-10-06 22:35:11 -07003233 }
3234 }
Jeff Brown32cbc38552011-12-01 14:01:49 -08003235 }
3236 final InputEventReceiver.Factory mHideNavInputEventReceiverFactory =
3237 new InputEventReceiver.Factory() {
3238 @Override
3239 public InputEventReceiver createInputEventReceiver(
3240 InputChannel inputChannel, Looper looper) {
3241 return new HideNavInputEventReceiver(inputChannel, looper);
3242 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07003243 };
3244
3245 @Override
3246 public int adjustSystemUiVisibilityLw(int visibility) {
John Spurlock5b9145b2013-08-20 15:13:47 -04003247 mStatusBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
3248 mNavigationBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
Winson Chungd42a6cf2014-06-03 16:24:04 -07003249 mRecentsVisible = (visibility & View.RECENT_APPS_VISIBLE) > 0;
John Spurlock27735a42013-08-14 17:57:38 -04003250
Dianne Hackborndf89e652011-10-06 22:35:11 -07003251 // Reset any bits in mForceClearingStatusBarVisibility that
3252 // are now clear.
Dianne Hackborne26ab702011-10-16 13:21:33 -07003253 mResettingSystemUiFlags &= visibility;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003254 // Clear any bits in the new visibility that are currently being
3255 // force cleared, before reporting it.
Dianne Hackborne26ab702011-10-16 13:21:33 -07003256 return visibility & ~mResettingSystemUiFlags
3257 & ~mForceClearedSystemUiFlags;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003258 }
3259
Craig Mautner69b08182012-09-05 13:07:13 -07003260 @Override
Adrian Roos37d7a682014-11-06 18:15:16 +01003261 public void getInsetHintLw(WindowManager.LayoutParams attrs, Rect outContentInsets,
3262 Rect outStableInsets) {
John Spurlockc6d1c602014-01-17 15:22:06 -05003263 final int fl = PolicyControl.getWindowFlags(null, attrs);
John Spurlock1db8b682014-02-18 11:18:59 -05003264 final int sysuiVis = PolicyControl.getSystemUiVisibility(null, attrs);
3265 final int systemUiVisibility = (sysuiVis | attrs.subtreeSystemUiVisibility);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003266
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003267 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003268 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003269 int availRight, availBottom;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003270 if (canHideNavigationBar() &&
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003271 (systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003272 availRight = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3273 availBottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
3274 } else {
3275 availRight = mRestrictedScreenLeft + mRestrictedScreenWidth;
3276 availBottom = mRestrictedScreenTop + mRestrictedScreenHeight;
3277 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003278 if ((systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
3279 if ((fl & FLAG_FULLSCREEN) != 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003280 outContentInsets.set(mStableFullscreenLeft, mStableFullscreenTop,
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003281 availRight - mStableFullscreenRight,
3282 availBottom - mStableFullscreenBottom);
3283 } else {
Adrian Roos37d7a682014-11-06 18:15:16 +01003284 outContentInsets.set(mStableLeft, mStableTop,
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003285 availRight - mStableRight, availBottom - mStableBottom);
3286 }
Dianne Hackbornc652de82013-02-15 16:32:56 -08003287 } else if ((fl & FLAG_FULLSCREEN) != 0 || (fl & FLAG_LAYOUT_IN_OVERSCAN) != 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003288 outContentInsets.setEmpty();
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003289 } else if ((systemUiVisibility & (View.SYSTEM_UI_FLAG_FULLSCREEN
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003290 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)) == 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003291 outContentInsets.set(mCurLeft, mCurTop,
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003292 availRight - mCurRight, availBottom - mCurBottom);
3293 } else {
Adrian Roos37d7a682014-11-06 18:15:16 +01003294 outContentInsets.set(mCurLeft, mCurTop,
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003295 availRight - mCurRight, availBottom - mCurBottom);
3296 }
Adrian Roos37d7a682014-11-06 18:15:16 +01003297
3298 outStableInsets.set(mStableLeft, mStableTop,
3299 availRight - mStableRight, availBottom - mStableBottom);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003300 return;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003301 }
Adrian Roos37d7a682014-11-06 18:15:16 +01003302 outContentInsets.setEmpty();
3303 outStableInsets.setEmpty();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003304 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003305
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003306 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07003307 @Override
3308 public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight,
3309 int displayRotation) {
Dianne Hackbornc652de82013-02-15 16:32:56 -08003310 final int overscanLeft, overscanTop, overscanRight, overscanBottom;
3311 if (isDefaultDisplay) {
3312 switch (displayRotation) {
3313 case Surface.ROTATION_90:
3314 overscanLeft = mOverscanTop;
3315 overscanTop = mOverscanRight;
3316 overscanRight = mOverscanBottom;
3317 overscanBottom = mOverscanLeft;
3318 break;
3319 case Surface.ROTATION_180:
3320 overscanLeft = mOverscanRight;
3321 overscanTop = mOverscanBottom;
3322 overscanRight = mOverscanLeft;
3323 overscanBottom = mOverscanTop;
3324 break;
3325 case Surface.ROTATION_270:
3326 overscanLeft = mOverscanBottom;
3327 overscanTop = mOverscanLeft;
3328 overscanRight = mOverscanTop;
3329 overscanBottom = mOverscanRight;
3330 break;
3331 default:
3332 overscanLeft = mOverscanLeft;
3333 overscanTop = mOverscanTop;
3334 overscanRight = mOverscanRight;
3335 overscanBottom = mOverscanBottom;
3336 break;
3337 }
3338 } else {
3339 overscanLeft = 0;
3340 overscanTop = 0;
3341 overscanRight = 0;
3342 overscanBottom = 0;
3343 }
Dianne Hackborn313440842013-02-19 19:22:59 -08003344 mOverscanScreenLeft = mRestrictedOverscanScreenLeft = 0;
3345 mOverscanScreenTop = mRestrictedOverscanScreenTop = 0;
3346 mOverscanScreenWidth = mRestrictedOverscanScreenWidth = displayWidth;
3347 mOverscanScreenHeight = mRestrictedOverscanScreenHeight = displayHeight;
Dianne Hackbornc652de82013-02-15 16:32:56 -08003348 mSystemLeft = 0;
3349 mSystemTop = 0;
3350 mSystemRight = displayWidth;
3351 mSystemBottom = displayHeight;
3352 mUnrestrictedScreenLeft = overscanLeft;
3353 mUnrestrictedScreenTop = overscanTop;
3354 mUnrestrictedScreenWidth = displayWidth - overscanLeft - overscanRight;
3355 mUnrestrictedScreenHeight = displayHeight - overscanTop - overscanBottom;
3356 mRestrictedScreenLeft = mUnrestrictedScreenLeft;
3357 mRestrictedScreenTop = mUnrestrictedScreenTop;
John Spurlockad3e6cb2013-04-30 08:47:43 -04003358 mRestrictedScreenWidth = mSystemGestures.screenWidth = mUnrestrictedScreenWidth;
3359 mRestrictedScreenHeight = mSystemGestures.screenHeight = mUnrestrictedScreenHeight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003360 mDockLeft = mContentLeft = mVoiceContentLeft = mStableLeft = mStableFullscreenLeft
Dianne Hackbornc652de82013-02-15 16:32:56 -08003361 = mCurLeft = mUnrestrictedScreenLeft;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003362 mDockTop = mContentTop = mVoiceContentTop = mStableTop = mStableFullscreenTop
Dianne Hackbornc652de82013-02-15 16:32:56 -08003363 = mCurTop = mUnrestrictedScreenTop;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003364 mDockRight = mContentRight = mVoiceContentRight = mStableRight = mStableFullscreenRight
Dianne Hackbornc652de82013-02-15 16:32:56 -08003365 = mCurRight = displayWidth - overscanRight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003366 mDockBottom = mContentBottom = mVoiceContentBottom = mStableBottom = mStableFullscreenBottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003367 = mCurBottom = displayHeight - overscanBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003368 mDockLayer = 0x10000000;
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003369 mStatusBarLayer = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003370
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003371 // start with the current dock rect, which will be (0,0,displayWidth,displayHeight)
3372 final Rect pf = mTmpParentFrame;
3373 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003374 final Rect of = mTmpOverscanFrame;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003375 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04003376 final Rect dcf = mTmpDecorFrame;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003377 final Rect osf = mTmpOutsetFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003378 pf.left = df.left = of.left = vf.left = mDockLeft;
3379 pf.top = df.top = of.top = vf.top = mDockTop;
3380 pf.right = df.right = of.right = vf.right = mDockRight;
3381 pf.bottom = df.bottom = of.bottom = vf.bottom = mDockBottom;
John Spurlock46646232013-09-30 22:32:42 -04003382 dcf.setEmpty(); // Decor frame N/A for system bars.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003383
Craig Mautner69b08182012-09-05 13:07:13 -07003384 if (isDefaultDisplay) {
3385 // For purposes of putting out fake window up to steal focus, we will
3386 // drive nav being hidden only by whether it is requested.
John Spurlocke1f366f2013-08-05 12:22:40 -04003387 final int sysui = mLastSystemUiFlags;
3388 boolean navVisible = (sysui & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0;
Adrian Roosea562512014-05-05 13:33:03 +02003389 boolean navTranslucent = (sysui
3390 & (View.NAVIGATION_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04003391 boolean immersive = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
3392 boolean immersiveSticky = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
3393 boolean navAllowedHidden = immersive || immersiveSticky;
3394 navTranslucent &= !immersiveSticky; // transient trumps translucent
Adrian Roos4fb3ee32014-08-22 19:29:09 +02003395 boolean isKeyguardShowing = isStatusBarKeyguard() && !mHideLockScreen;
3396 if (!isKeyguardShowing) {
3397 navTranslucent &= areTranslucentBarsAllowed();
3398 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003399
Craig Mautner69b08182012-09-05 13:07:13 -07003400 // When the navigation bar isn't visible, we put up a fake
3401 // input window to catch all touch events. This way we can
3402 // detect when the user presses anywhere to bring back the nav
3403 // bar and ensure the application doesn't see the event.
John Spurlockf1a36642013-10-12 17:50:42 -04003404 if (navVisible || navAllowedHidden) {
Selim Cinekf83e8242015-05-19 18:08:14 -07003405 if (mInputConsumer != null) {
3406 mInputConsumer.dismiss();
3407 mInputConsumer = null;
Craig Mautner69b08182012-09-05 13:07:13 -07003408 }
Selim Cinekf83e8242015-05-19 18:08:14 -07003409 } else if (mInputConsumer == null) {
3410 mInputConsumer = mWindowManagerFuncs.addInputConsumer(mHandler.getLooper(),
3411 mHideNavInputEventReceiverFactory);
Dianne Hackborne26ab702011-10-16 13:21:33 -07003412 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003413
Craig Mautner69b08182012-09-05 13:07:13 -07003414 // For purposes of positioning and showing the nav bar, if we have
3415 // decided that it can't be hidden (because of the screen aspect ratio),
3416 // then take that into account.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003417 navVisible |= !canHideNavigationBar();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003418
John Spurlockad3e6cb2013-04-30 08:47:43 -04003419 boolean updateSysUiVisibility = false;
Craig Mautner69b08182012-09-05 13:07:13 -07003420 if (mNavigationBar != null) {
John Spurlock27735a42013-08-14 17:57:38 -04003421 boolean transientNavBarShowing = mNavigationBarController.isTransientShowing();
Craig Mautner69b08182012-09-05 13:07:13 -07003422 // Force the navigation bar to its appropriate place and
3423 // size. We need to do this directly, instead of relying on
3424 // it to bubble up from the nav bar, because this needs to
3425 // change atomically with screen rotations.
3426 mNavigationBarOnBottom = (!mNavigationBarCanMove || displayWidth < displayHeight);
3427 if (mNavigationBarOnBottom) {
3428 // It's a system nav bar or a portrait screen; nav bar goes on bottom.
Dianne Hackbornc652de82013-02-15 16:32:56 -08003429 int top = displayHeight - overscanBottom
3430 - mNavigationBarHeightForRotation[displayRotation];
3431 mTmpNavigationFrame.set(0, top, displayWidth, displayHeight - overscanBottom);
Craig Mautner69b08182012-09-05 13:07:13 -07003432 mStableBottom = mStableFullscreenBottom = mTmpNavigationFrame.top;
John Spurlockf95b89a2013-10-10 22:10:42 -04003433 if (transientNavBarShowing) {
John Spurlock27735a42013-08-14 17:57:38 -04003434 mNavigationBarController.setBarShowingLw(true);
John Spurlockad3e6cb2013-04-30 08:47:43 -04003435 } else if (navVisible) {
John Spurlock27735a42013-08-14 17:57:38 -04003436 mNavigationBarController.setBarShowingLw(true);
Craig Mautner69b08182012-09-05 13:07:13 -07003437 mDockBottom = mTmpNavigationFrame.top;
Dianne Hackborn313440842013-02-19 19:22:59 -08003438 mRestrictedScreenHeight = mDockBottom - mRestrictedScreenTop;
3439 mRestrictedOverscanScreenHeight = mDockBottom - mRestrictedOverscanScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07003440 } else {
3441 // We currently want to hide the navigation UI.
John Spurlock27735a42013-08-14 17:57:38 -04003442 mNavigationBarController.setBarShowingLw(false);
Craig Mautner69b08182012-09-05 13:07:13 -07003443 }
John Spurlockc6d1c602014-01-17 15:22:06 -05003444 if (navVisible && !navTranslucent && !navAllowedHidden
3445 && !mNavigationBar.isAnimatingLw()
John Spurlockbd957402013-10-03 11:38:39 -04003446 && !mNavigationBarController.wasRecentlyTranslucent()) {
John Spurlocke1f366f2013-08-05 12:22:40 -04003447 // If the opaque nav bar is currently requested to be visible,
Craig Mautner69b08182012-09-05 13:07:13 -07003448 // and not in the process of animating on or off, then
3449 // we can tell the app that it is covered by it.
3450 mSystemBottom = mTmpNavigationFrame.top;
3451 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003452 } else {
Craig Mautner69b08182012-09-05 13:07:13 -07003453 // Landscape screen; nav bar goes to the right.
Dianne Hackbornc652de82013-02-15 16:32:56 -08003454 int left = displayWidth - overscanRight
3455 - mNavigationBarWidthForRotation[displayRotation];
3456 mTmpNavigationFrame.set(left, 0, displayWidth - overscanRight, displayHeight);
Craig Mautner69b08182012-09-05 13:07:13 -07003457 mStableRight = mStableFullscreenRight = mTmpNavigationFrame.left;
John Spurlockf95b89a2013-10-10 22:10:42 -04003458 if (transientNavBarShowing) {
John Spurlock27735a42013-08-14 17:57:38 -04003459 mNavigationBarController.setBarShowingLw(true);
John Spurlockad3e6cb2013-04-30 08:47:43 -04003460 } else if (navVisible) {
John Spurlock27735a42013-08-14 17:57:38 -04003461 mNavigationBarController.setBarShowingLw(true);
Craig Mautner69b08182012-09-05 13:07:13 -07003462 mDockRight = mTmpNavigationFrame.left;
Dianne Hackborn313440842013-02-19 19:22:59 -08003463 mRestrictedScreenWidth = mDockRight - mRestrictedScreenLeft;
3464 mRestrictedOverscanScreenWidth = mDockRight - mRestrictedOverscanScreenLeft;
Craig Mautner69b08182012-09-05 13:07:13 -07003465 } else {
3466 // We currently want to hide the navigation UI.
John Spurlock27735a42013-08-14 17:57:38 -04003467 mNavigationBarController.setBarShowingLw(false);
Craig Mautner69b08182012-09-05 13:07:13 -07003468 }
John Spurlockbd957402013-10-03 11:38:39 -04003469 if (navVisible && !navTranslucent && !mNavigationBar.isAnimatingLw()
3470 && !mNavigationBarController.wasRecentlyTranslucent()) {
Craig Mautner69b08182012-09-05 13:07:13 -07003471 // If the nav bar is currently requested to be visible,
3472 // and not in the process of animating on or off, then
3473 // we can tell the app that it is covered by it.
3474 mSystemRight = mTmpNavigationFrame.left;
3475 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003476 }
Craig Mautner69b08182012-09-05 13:07:13 -07003477 // Make sure the content and current rectangles are updated to
3478 // account for the restrictions from the navigation bar.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003479 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3480 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3481 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3482 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
Craig Mautner69b08182012-09-05 13:07:13 -07003483 mStatusBarLayer = mNavigationBar.getSurfaceLayer();
3484 // And compute the final frame.
3485 mNavigationBar.computeFrameLw(mTmpNavigationFrame, mTmpNavigationFrame,
Adrian Roosfa104232014-06-20 16:10:14 -07003486 mTmpNavigationFrame, mTmpNavigationFrame, mTmpNavigationFrame, dcf,
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003487 mTmpNavigationFrame, mTmpNavigationFrame);
Craig Mautnereda67292013-04-28 13:50:14 -07003488 if (DEBUG_LAYOUT) Slog.i(TAG, "mNavigationBar frame: " + mTmpNavigationFrame);
John Spurlock27735a42013-08-14 17:57:38 -04003489 if (mNavigationBarController.checkHiddenLw()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04003490 updateSysUiVisibility = true;
3491 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003492 }
Craig Mautnereda67292013-04-28 13:50:14 -07003493 if (DEBUG_LAYOUT) Slog.i(TAG, String.format("mDock rect: (%d,%d - %d,%d)",
Craig Mautner69b08182012-09-05 13:07:13 -07003494 mDockLeft, mDockTop, mDockRight, mDockBottom));
3495
3496 // decide where the status bar goes ahead of time
3497 if (mStatusBar != null) {
3498 // apply any navigation bar insets
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003499 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3500 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3501 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
3502 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight
3503 + mUnrestrictedScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07003504 vf.left = mStableLeft;
3505 vf.top = mStableTop;
3506 vf.right = mStableRight;
3507 vf.bottom = mStableBottom;
3508
3509 mStatusBarLayer = mStatusBar.getSurfaceLayer();
3510
3511 // Let the status bar determine its size.
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003512 mStatusBar.computeFrameLw(pf /* parentFrame */, df /* displayFrame */,
3513 vf /* overlayFrame */, vf /* contentFrame */, vf /* visibleFrame */,
3514 dcf /* decorFrame */, vf /* stableFrame */, vf /* outsetFrame */);
Craig Mautner69b08182012-09-05 13:07:13 -07003515
3516 // For layout, the status bar is always at the top with our fixed height.
3517 mStableTop = mUnrestrictedScreenTop + mStatusBarHeight;
3518
John Spurlocke1f366f2013-08-05 12:22:40 -04003519 boolean statusBarTransient = (sysui & View.STATUS_BAR_TRANSIENT) != 0;
Adrian Roosea562512014-05-05 13:33:03 +02003520 boolean statusBarTranslucent = (sysui
3521 & (View.STATUS_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0;
Adrian Roos4fb3ee32014-08-22 19:29:09 +02003522 if (!isKeyguardShowing) {
3523 statusBarTranslucent &= areTranslucentBarsAllowed();
3524 }
John Spurlock32beb2c2013-03-11 10:16:47 -04003525
Craig Mautner69b08182012-09-05 13:07:13 -07003526 // If the status bar is hidden, we don't want to cause
3527 // windows behind it to scroll.
John Spurlockeda1f692013-09-16 11:38:44 -04003528 if (mStatusBar.isVisibleLw() && !statusBarTransient) {
Craig Mautner69b08182012-09-05 13:07:13 -07003529 // Status bar may go away, so the screen area it occupies
3530 // is available to apps but just covering them when the
3531 // status bar is visible.
3532 mDockTop = mUnrestrictedScreenTop + mStatusBarHeight;
3533
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003534 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3535 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3536 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3537 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
Craig Mautner69b08182012-09-05 13:07:13 -07003538
Craig Mautnereda67292013-04-28 13:50:14 -07003539 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar: " +
Craig Mautner69b08182012-09-05 13:07:13 -07003540 String.format(
3541 "dock=[%d,%d][%d,%d] content=[%d,%d][%d,%d] cur=[%d,%d][%d,%d]",
3542 mDockLeft, mDockTop, mDockRight, mDockBottom,
3543 mContentLeft, mContentTop, mContentRight, mContentBottom,
3544 mCurLeft, mCurTop, mCurRight, mCurBottom));
3545 }
John Spurlocke1f366f2013-08-05 12:22:40 -04003546 if (mStatusBar.isVisibleLw() && !mStatusBar.isAnimatingLw()
John Spurlockbd957402013-10-03 11:38:39 -04003547 && !statusBarTransient && !statusBarTranslucent
3548 && !mStatusBarController.wasRecentlyTranslucent()) {
John Spurlocke1f366f2013-08-05 12:22:40 -04003549 // If the opaque status bar is currently requested to be visible,
Craig Mautner69b08182012-09-05 13:07:13 -07003550 // and not in the process of animating on or off, then
3551 // we can tell the app that it is covered by it.
3552 mSystemTop = mUnrestrictedScreenTop + mStatusBarHeight;
3553 }
John Spurlock27735a42013-08-14 17:57:38 -04003554 if (mStatusBarController.checkHiddenLw()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04003555 updateSysUiVisibility = true;
John Spurlock32beb2c2013-03-11 10:16:47 -04003556 }
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003557 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04003558 if (updateSysUiVisibility) {
3559 updateSystemUiVisibilityLw();
3560 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003561 }
3562 }
3563
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003564 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07003565 @Override
John Spurlock46646232013-09-30 22:32:42 -04003566 public int getSystemDecorLayerLw() {
Bryce Lee2ed3e5f2015-04-01 22:09:19 +00003567 if (mStatusBar != null && mStatusBar.isVisibleLw()) {
3568 return mStatusBar.getSurfaceLayer();
3569 }
3570
3571 if (mNavigationBar != null && mNavigationBar.isVisibleLw()) {
3572 return mNavigationBar.getSurfaceLayer();
3573 }
3574
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003575 return 0;
3576 }
3577
Craig Mautner967212c2013-04-13 21:10:58 -07003578 @Override
3579 public void getContentRectLw(Rect r) {
3580 r.set(mContentLeft, mContentTop, mContentRight, mContentBottom);
3581 }
3582
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003583 void setAttachedWindowFrames(WindowState win, int fl, int adjust, WindowState attached,
3584 boolean insetDecors, Rect pf, Rect df, Rect of, Rect cf, Rect vf) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003585 if (win.getSurfaceLayer() > mDockLayer && attached.getSurfaceLayer() < mDockLayer) {
3586 // Here's a special case: if this attached window is a panel that is
3587 // above the dock window, and the window it is attached to is below
3588 // the dock window, then the frames we computed for the window it is
3589 // attached to can not be used because the dock is effectively part
3590 // of the underlying window and the attached window is floating on top
3591 // of the whole thing. So, we ignore the attached window and explicitly
3592 // compute the frames that would be appropriate without the dock.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003593 df.left = of.left = cf.left = vf.left = mDockLeft;
3594 df.top = of.top = cf.top = vf.top = mDockTop;
3595 df.right = of.right = cf.right = vf.right = mDockRight;
3596 df.bottom = of.bottom = cf.bottom = vf.bottom = mDockBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003597 } else {
3598 // The effective display frame of the attached window depends on
3599 // whether it is taking care of insetting its content. If not,
3600 // we need to use the parent's content frame so that the entire
3601 // window is positioned within that content. Otherwise we can use
Wale Ogunwale393b1c12014-10-18 16:22:01 -07003602 // the overscan frame and let the attached window take care of
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003603 // positioning its content appropriately.
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003604 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Wale Ogunwale393b1c12014-10-18 16:22:01 -07003605 // Set the content frame of the attached window to the parent's decor frame
3606 // (same as content frame when IME isn't present) if specifically requested by
3607 // setting {@link WindowManager.LayoutParams#FLAG_LAYOUT_ATTACHED_IN_DECOR} flag.
3608 // Otherwise, use the overscan frame.
3609 cf.set((fl & FLAG_LAYOUT_ATTACHED_IN_DECOR) != 0
3610 ? attached.getContentFrameLw() : attached.getOverscanFrameLw());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003611 } else {
3612 // If the window is resizing, then we want to base the content
3613 // frame on our attached content frame to resize... however,
3614 // things can be tricky if the attached window is NOT in resize
3615 // mode, in which case its content frame will be larger.
3616 // Ungh. So to deal with that, make sure the content frame
3617 // we end up using is not covering the IM dock.
3618 cf.set(attached.getContentFrameLw());
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003619 if (attached.isVoiceInteraction()) {
3620 if (cf.left < mVoiceContentLeft) cf.left = mVoiceContentLeft;
3621 if (cf.top < mVoiceContentTop) cf.top = mVoiceContentTop;
3622 if (cf.right > mVoiceContentRight) cf.right = mVoiceContentRight;
3623 if (cf.bottom > mVoiceContentBottom) cf.bottom = mVoiceContentBottom;
3624 } else if (attached.getSurfaceLayer() < mDockLayer) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003625 if (cf.left < mContentLeft) cf.left = mContentLeft;
3626 if (cf.top < mContentTop) cf.top = mContentTop;
3627 if (cf.right > mContentRight) cf.right = mContentRight;
3628 if (cf.bottom > mContentBottom) cf.bottom = mContentBottom;
3629 }
3630 }
3631 df.set(insetDecors ? attached.getDisplayFrameLw() : cf);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003632 of.set(insetDecors ? attached.getOverscanFrameLw() : cf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003633 vf.set(attached.getVisibleFrameLw());
3634 }
3635 // The LAYOUT_IN_SCREEN flag is used to determine whether the attached
3636 // window should be positioned relative to its parent or the entire
3637 // screen.
3638 pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0
3639 ? attached.getFrameLw() : df);
3640 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003641
3642 private void applyStableConstraints(int sysui, int fl, Rect r) {
3643 if ((sysui & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
3644 // If app is requesting a stable layout, don't let the
3645 // content insets go below the stable values.
3646 if ((fl & FLAG_FULLSCREEN) != 0) {
3647 if (r.left < mStableFullscreenLeft) r.left = mStableFullscreenLeft;
3648 if (r.top < mStableFullscreenTop) r.top = mStableFullscreenTop;
3649 if (r.right > mStableFullscreenRight) r.right = mStableFullscreenRight;
3650 if (r.bottom > mStableFullscreenBottom) r.bottom = mStableFullscreenBottom;
3651 } else {
3652 if (r.left < mStableLeft) r.left = mStableLeft;
3653 if (r.top < mStableTop) r.top = mStableTop;
3654 if (r.right > mStableRight) r.right = mStableRight;
3655 if (r.bottom > mStableBottom) r.bottom = mStableBottom;
3656 }
3657 }
3658 }
3659
Jorim Jaggiaa806142015-05-20 18:04:16 -07003660 private boolean canReceiveInput(WindowState win) {
3661 boolean notFocusable =
3662 (win.getAttrs().flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0;
3663 boolean altFocusableIm =
3664 (win.getAttrs().flags & WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM) != 0;
3665 boolean notFocusableForIm = notFocusable ^ altFocusableIm;
3666 return !notFocusableForIm;
3667 }
3668
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003669 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07003670 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003671 public void layoutWindowLw(WindowState win, WindowState attached) {
Jorim Jaggiaa806142015-05-20 18:04:16 -07003672 // We've already done the navigation bar and status bar. If the status bar can receive
3673 // input, we need to layout it again to accomodate for the IME window.
3674 if ((win == mStatusBar && !canReceiveInput(win)) || win == mNavigationBar) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003675 return;
3676 }
Jorim Jaggiaa806142015-05-20 18:04:16 -07003677 final WindowManager.LayoutParams attrs = win.getAttrs();
Craig Mautner69b08182012-09-05 13:07:13 -07003678 final boolean isDefaultDisplay = win.isDefaultDisplay();
3679 final boolean needsToOffsetInputMethodTarget = isDefaultDisplay &&
satok1bc0a492012-04-25 22:47:12 +09003680 (win == mLastInputMethodTargetWindow && mLastInputMethodWindow != null);
3681 if (needsToOffsetInputMethodTarget) {
Craig Mautnereda67292013-04-28 13:50:14 -07003682 if (DEBUG_LAYOUT) Slog.i(TAG, "Offset ime target window by the last ime window state");
satok1bc0a492012-04-25 22:47:12 +09003683 offsetInputMethodWindowLw(mLastInputMethodWindow);
3684 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003685
John Spurlockc6d1c602014-01-17 15:22:06 -05003686 final int fl = PolicyControl.getWindowFlags(win, attrs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003687 final int sim = attrs.softInputMode;
John Spurlock1db8b682014-02-18 11:18:59 -05003688 final int sysUiFl = PolicyControl.getSystemUiVisibility(win, null);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003689
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003690 final Rect pf = mTmpParentFrame;
3691 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003692 final Rect of = mTmpOverscanFrame;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003693 final Rect cf = mTmpContentFrame;
3694 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04003695 final Rect dcf = mTmpDecorFrame;
Adrian Roosfa104232014-06-20 16:10:14 -07003696 final Rect sf = mTmpStableFrame;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003697 Rect osf = null;
John Spurlock46646232013-09-30 22:32:42 -04003698 dcf.setEmpty();
Craig Mautner69b08182012-09-05 13:07:13 -07003699
3700 final boolean hasNavBar = (isDefaultDisplay && mHasNavigationBar
Daniel Sandler36412a72011-08-04 09:35:13 -04003701 && mNavigationBar != null && mNavigationBar.isVisibleLw());
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003702
Craig Mautnerf683b562012-10-02 11:10:57 -07003703 final int adjust = sim & SOFT_INPUT_MASK_ADJUST;
3704
Adrian Roosfa104232014-06-20 16:10:14 -07003705 if (isDefaultDisplay) {
3706 sf.set(mStableLeft, mStableTop, mStableRight, mStableBottom);
3707 } else {
3708 sf.set(mOverscanLeft, mOverscanTop, mOverscanRight, mOverscanBottom);
3709 }
3710
Craig Mautner69b08182012-09-05 13:07:13 -07003711 if (!isDefaultDisplay) {
3712 if (attached != null) {
3713 // If this window is attached to another, our display
3714 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003715 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07003716 } else {
3717 // Give the window full screen.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003718 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3719 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3720 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08003721 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003722 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003723 = mOverscanScreenTop + mOverscanScreenHeight;
Craig Mautner69b08182012-09-05 13:07:13 -07003724 }
Jorim Jaggi225d3b52015-04-01 11:18:57 -07003725 } else if (attrs.type == TYPE_INPUT_METHOD) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003726 pf.left = df.left = of.left = cf.left = vf.left = mDockLeft;
3727 pf.top = df.top = of.top = cf.top = vf.top = mDockTop;
3728 pf.right = df.right = of.right = cf.right = vf.right = mDockRight;
John Spurlockc68d5772013-10-08 11:47:58 -04003729 // IM dock windows layout below the nav bar...
John Spurlock57beb3b2013-10-10 10:27:44 -04003730 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlockc68d5772013-10-08 11:47:58 -04003731 // ...with content insets above the nav bar
3732 cf.bottom = vf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003733 // IM dock windows always go to the bottom of the screen.
3734 attrs.gravity = Gravity.BOTTOM;
3735 mDockLayer = win.getSurfaceLayer();
Jorim Jaggi225d3b52015-04-01 11:18:57 -07003736 } else if (attrs.type == TYPE_VOICE_INTERACTION) {
3737 pf.left = df.left = of.left = cf.left = vf.left = mUnrestrictedScreenLeft;
3738 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3739 pf.right = df.right = of.right = cf.right = vf.right = mUnrestrictedScreenLeft
3740 + mUnrestrictedScreenWidth;
3741 pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop
3742 + mUnrestrictedScreenHeight;
3743 cf.bottom = vf.bottom = mStableBottom;
3744 cf.top = vf.top = mStableTop;
Jorim Jaggiaa806142015-05-20 18:04:16 -07003745 } else if (win == mStatusBar) {
Jorim Jaggie0700182014-08-21 01:12:37 +02003746 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3747 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3748 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
3749 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight + mUnrestrictedScreenTop;
3750 cf.left = vf.left = mStableLeft;
3751 cf.top = vf.top = mStableTop;
3752 cf.right = vf.right = mStableRight;
3753 vf.bottom = mStableBottom;
3754 cf.bottom = mContentBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003755 } else {
John Spurlock46646232013-09-30 22:32:42 -04003756
3757 // Default policy decor for the default display
3758 dcf.left = mSystemLeft;
3759 dcf.top = mSystemTop;
3760 dcf.right = mSystemRight;
3761 dcf.bottom = mSystemBottom;
John Spurlockbd957402013-10-03 11:38:39 -04003762 final boolean inheritTranslucentDecor = (attrs.privateFlags
3763 & WindowManager.LayoutParams.PRIVATE_FLAG_INHERIT_TRANSLUCENT_DECOR) != 0;
John Spurlock65567d42013-10-08 10:08:32 -04003764 final boolean isAppWindow =
3765 attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW &&
3766 attrs.type <= WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
3767 final boolean topAtRest =
3768 win == mTopFullscreenOpaqueWindowState && !win.isAnimatingLw();
3769 if (isAppWindow && !inheritTranslucentDecor && !topAtRest) {
John Spurlockbd957402013-10-03 11:38:39 -04003770 if ((sysUiFl & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0
3771 && (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0
Adrian Roosea562512014-05-05 13:33:03 +02003772 && (fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) == 0
3773 && (fl & WindowManager.LayoutParams.
3774 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04003775 // Ensure policy decor includes status bar
3776 dcf.top = mStableTop;
3777 }
John Spurlockbd957402013-10-03 11:38:39 -04003778 if ((fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) == 0
Adrian Roosea562512014-05-05 13:33:03 +02003779 && (sysUiFl & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0
3780 && (fl & WindowManager.LayoutParams.
3781 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04003782 // Ensure policy decor includes navigation bar
3783 dcf.bottom = mStableBottom;
3784 dcf.right = mStableRight;
3785 }
3786 }
3787
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003788 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
3789 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
RoboErik8a2cfc32014-05-16 11:19:38 -07003790 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003791 + "): IN_SCREEN, INSET_DECOR");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003792 // This is the case for a normal activity window: we want it
3793 // to cover all of the screen space, and it can take care of
3794 // moving its contents to account for screen decorations that
3795 // intrude into that space.
3796 if (attached != null) {
3797 // If this window is attached to another, our display
3798 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003799 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003800 } else {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003801 if (attrs.type == TYPE_STATUS_BAR_PANEL
3802 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Joe Onorato29fc2c92010-11-24 10:26:50 -08003803 // Status bar panels are the only windows who can go on top of
3804 // the status bar. They are protected by the STATUS_BAR_SERVICE
3805 // permission, so they have the same privileges as the status
3806 // bar itself.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003807 //
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003808 // However, they should still dodge the navigation bar if it exists.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003809
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003810 pf.left = df.left = of.left = hasNavBar
3811 ? mDockLeft : mUnrestrictedScreenLeft;
3812 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3813 pf.right = df.right = of.right = hasNavBar
3814 ? mRestrictedScreenLeft+mRestrictedScreenWidth
3815 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3816 pf.bottom = df.bottom = of.bottom = hasNavBar
3817 ? mRestrictedScreenTop+mRestrictedScreenHeight
3818 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003819
Craig Mautnereda67292013-04-28 13:50:14 -07003820 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003821 "Laying out status bar window: (%d,%d - %d,%d)",
3822 pf.left, pf.top, pf.right, pf.bottom));
John Spurlock46646232013-09-30 22:32:42 -04003823 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08003824 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3825 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3826 // Asking to layout into the overscan region, so give it that pure
3827 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003828 pf.left = df.left = of.left = mOverscanScreenLeft;
3829 pf.top = df.top = of.top = mOverscanScreenTop;
3830 pf.right = df.right = of.right = mOverscanScreenLeft + mOverscanScreenWidth;
3831 pf.bottom = df.bottom = of.bottom = mOverscanScreenTop
3832 + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003833 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003834 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003835 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3836 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003837 // Asking for layout as if the nav bar is hidden, lets the
Dianne Hackbornc652de82013-02-15 16:32:56 -08003838 // application extend into the unrestricted overscan screen area. We
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003839 // only do this for application windows to ensure no window that
3840 // can be above the nav bar can do this.
Dianne Hackborn313440842013-02-19 19:22:59 -08003841 pf.left = df.left = mOverscanScreenLeft;
3842 pf.top = df.top = mOverscanScreenTop;
3843 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
3844 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003845 // We need to tell the app about where the frame inside the overscan
3846 // is, so it can inset its content by that amount -- it didn't ask
3847 // to actually extend itself into the overscan region.
3848 of.left = mUnrestrictedScreenLeft;
3849 of.top = mUnrestrictedScreenTop;
3850 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3851 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003852 } else {
Dianne Hackborn313440842013-02-19 19:22:59 -08003853 pf.left = df.left = mRestrictedOverscanScreenLeft;
3854 pf.top = df.top = mRestrictedOverscanScreenTop;
3855 pf.right = df.right = mRestrictedOverscanScreenLeft
3856 + mRestrictedOverscanScreenWidth;
3857 pf.bottom = df.bottom = mRestrictedOverscanScreenTop
3858 + mRestrictedOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003859 // We need to tell the app about where the frame inside the overscan
3860 // is, so it can inset its content by that amount -- it didn't ask
3861 // to actually extend itself into the overscan region.
3862 of.left = mUnrestrictedScreenLeft;
3863 of.top = mUnrestrictedScreenTop;
3864 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3865 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003866 }
Craig Mautner69b08182012-09-05 13:07:13 -07003867
John Spurlock46646232013-09-30 22:32:42 -04003868 if ((fl & FLAG_FULLSCREEN) == 0) {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003869 if (win.isVoiceInteraction()) {
3870 cf.left = mVoiceContentLeft;
3871 cf.top = mVoiceContentTop;
3872 cf.right = mVoiceContentRight;
3873 cf.bottom = mVoiceContentBottom;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003874 } else {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003875 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
3876 cf.left = mDockLeft;
3877 cf.top = mDockTop;
3878 cf.right = mDockRight;
3879 cf.bottom = mDockBottom;
3880 } else {
3881 cf.left = mContentLeft;
3882 cf.top = mContentTop;
3883 cf.right = mContentRight;
3884 cf.bottom = mContentBottom;
3885 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003886 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003887 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003888 // Full screen windows are always given a layout that is as if the
3889 // status bar and other transient decors are gone. This is to avoid
3890 // bad states when moving from a window that is not hding the
3891 // status bar to one that is.
3892 cf.left = mRestrictedScreenLeft;
3893 cf.top = mRestrictedScreenTop;
3894 cf.right = mRestrictedScreenLeft + mRestrictedScreenWidth;
3895 cf.bottom = mRestrictedScreenTop + mRestrictedScreenHeight;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003896 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003897 applyStableConstraints(sysUiFl, fl, cf);
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003898 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3899 vf.left = mCurLeft;
3900 vf.top = mCurTop;
3901 vf.right = mCurRight;
3902 vf.bottom = mCurBottom;
3903 } else {
3904 vf.set(cf);
3905 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003906 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003907 } else if ((fl & FLAG_LAYOUT_IN_SCREEN) != 0 || (sysUiFl
3908 & (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
3909 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)) != 0) {
Craig Mautnereda67292013-04-28 13:50:14 -07003910 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3911 "): IN_SCREEN");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003912 // A window that has requested to fill the entire screen just
3913 // gets everything, period.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003914 if (attrs.type == TYPE_STATUS_BAR_PANEL
3915 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003916 pf.left = df.left = of.left = cf.left = hasNavBar
3917 ? mDockLeft : mUnrestrictedScreenLeft;
3918 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
3919 pf.right = df.right = of.right = cf.right = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003920 ? mRestrictedScreenLeft+mRestrictedScreenWidth
Dianne Hackbornc652de82013-02-15 16:32:56 -08003921 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003922 pf.bottom = df.bottom = of.bottom = cf.bottom = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003923 ? mRestrictedScreenTop+mRestrictedScreenHeight
Dianne Hackbornc652de82013-02-15 16:32:56 -08003924 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07003925 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler36412a72011-08-04 09:35:13 -04003926 "Laying out IN_SCREEN status bar window: (%d,%d - %d,%d)",
3927 pf.left, pf.top, pf.right, pf.bottom));
Jim Millere898ac52012-04-06 17:10:57 -07003928 } else if (attrs.type == TYPE_NAVIGATION_BAR
3929 || attrs.type == TYPE_NAVIGATION_BAR_PANEL) {
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003930 // The navigation bar has Real Ultimate Power.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003931 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3932 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3933 pf.right = df.right = of.right = mUnrestrictedScreenLeft
3934 + mUnrestrictedScreenWidth;
3935 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop
3936 + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07003937 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003938 "Laying out navigation bar window: (%d,%d - %d,%d)",
3939 pf.left, pf.top, pf.right, pf.bottom));
Dianne Hackborn01011c32012-02-21 13:54:21 -08003940 } else if ((attrs.type == TYPE_SECURE_SYSTEM_OVERLAY
3941 || attrs.type == TYPE_BOOT_PROGRESS)
Jeff Brownbfcb60a2011-09-08 18:51:14 -07003942 && ((fl & FLAG_FULLSCREEN) != 0)) {
3943 // Fullscreen secure system overlays get what they ask for.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003944 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3945 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3946 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
3947 + mOverscanScreenWidth;
3948 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
3949 + mOverscanScreenHeight;
Craig Mautner165be0c2015-01-27 15:16:58 -08003950 } else if (attrs.type == TYPE_BOOT_PROGRESS) {
Dianne Hackborn01011c32012-02-21 13:54:21 -08003951 // Boot progress screen always covers entire display.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003952 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3953 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3954 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
3955 + mOverscanScreenWidth;
3956 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
3957 + mOverscanScreenHeight;
John Spurlockef4adae2013-08-26 17:58:58 -04003958 } else if (attrs.type == TYPE_WALLPAPER) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07003959 // The wallpaper also has Real Ultimate Power, but we want to tell
3960 // it about the overscan area.
3961 pf.left = df.left = mOverscanScreenLeft;
3962 pf.top = df.top = mOverscanScreenTop;
3963 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
3964 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
3965 of.left = cf.left = mUnrestrictedScreenLeft;
3966 of.top = cf.top = mUnrestrictedScreenTop;
3967 of.right = cf.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3968 of.bottom = cf.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlock46646232013-09-30 22:32:42 -04003969 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08003970 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3971 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3972 // Asking to layout into the overscan region, so give it that pure
3973 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003974 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3975 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3976 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08003977 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003978 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003979 = mOverscanScreenTop + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003980 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003981 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Craig Mautnerbeac1062014-06-03 14:38:57 -07003982 && (attrs.type == TYPE_STATUS_BAR
3983 || attrs.type == TYPE_TOAST
Jorim Jaggi2fdeeab2015-04-01 15:13:03 -07003984 || attrs.type == TYPE_VOICE_INTERACTION_STARTING
John Spurlock34e13d92013-08-10 06:52:28 -04003985 || (attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3986 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW))) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003987 // Asking for layout as if the nav bar is hidden, lets the
3988 // application extend into the unrestricted screen area. We
John Spurlock34e13d92013-08-10 06:52:28 -04003989 // only do this for application windows (or toasts) to ensure no window that
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003990 // can be above the nav bar can do this.
3991 // XXX This assumes that an app asking for this will also
3992 // ask for layout in only content. We can't currently figure out
3993 // what the screen would be if only laying out to hide the nav bar.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003994 pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft;
3995 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
3996 pf.right = df.right = of.right = cf.right = mUnrestrictedScreenLeft
3997 + mUnrestrictedScreenWidth;
3998 pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop
3999 + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08004000 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004001 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
4002 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
4003 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
4004 + mRestrictedScreenWidth;
4005 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
4006 + mRestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08004007 }
Craig Mautner69b08182012-09-05 13:07:13 -07004008
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07004009 applyStableConstraints(sysUiFl, fl, cf);
Craig Mautner69b08182012-09-05 13:07:13 -07004010
Dianne Hackborndea3ef72010-10-28 14:24:22 -07004011 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
4012 vf.left = mCurLeft;
4013 vf.top = mCurTop;
4014 vf.right = mCurRight;
4015 vf.bottom = mCurBottom;
4016 } else {
4017 vf.set(cf);
4018 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004019 } else if (attached != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07004020 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
4021 "): attached to " + attached);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004022 // A child window should be placed inside of the same visible
4023 // frame that its parent had.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004024 setAttachedWindowFrames(win, fl, adjust, attached, false, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004025 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07004026 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
4027 "): normal window");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004028 // Otherwise, a normal window must be placed inside the content
4029 // of all screen decorations.
Dianne Hackborna239c842011-06-01 12:28:20 -07004030 if (attrs.type == TYPE_STATUS_BAR_PANEL) {
4031 // Status bar panels are the only windows who can go on top of
4032 // the status bar. They are protected by the STATUS_BAR_SERVICE
4033 // permission, so they have the same privileges as the status
4034 // bar itself.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004035 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
4036 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
4037 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
4038 + mRestrictedScreenWidth;
4039 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
4040 + mRestrictedScreenHeight;
John Spurlock414c1f02013-12-04 13:47:36 -05004041 } else if (attrs.type == TYPE_TOAST || attrs.type == TYPE_SYSTEM_ALERT
4042 || attrs.type == TYPE_VOLUME_OVERLAY) {
4043 // These dialogs are stable to interim decor changes.
John Spurlockbd957402013-10-03 11:38:39 -04004044 pf.left = df.left = of.left = cf.left = mStableLeft;
4045 pf.top = df.top = of.top = cf.top = mStableTop;
4046 pf.right = df.right = of.right = cf.right = mStableRight;
4047 pf.bottom = df.bottom = of.bottom = cf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004048 } else {
Dianne Hackborna239c842011-06-01 12:28:20 -07004049 pf.left = mContentLeft;
4050 pf.top = mContentTop;
4051 pf.right = mContentRight;
4052 pf.bottom = mContentBottom;
Dianne Hackborn20d94742014-05-29 18:35:45 -07004053 if (win.isVoiceInteraction()) {
4054 df.left = of.left = cf.left = mVoiceContentLeft;
4055 df.top = of.top = cf.top = mVoiceContentTop;
4056 df.right = of.right = cf.right = mVoiceContentRight;
4057 df.bottom = of.bottom = cf.bottom = mVoiceContentBottom;
4058 } else if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004059 df.left = of.left = cf.left = mDockLeft;
4060 df.top = of.top = cf.top = mDockTop;
4061 df.right = of.right = cf.right = mDockRight;
4062 df.bottom = of.bottom = cf.bottom = mDockBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07004063 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004064 df.left = of.left = cf.left = mContentLeft;
4065 df.top = of.top = cf.top = mContentTop;
4066 df.right = of.right = cf.right = mContentRight;
4067 df.bottom = of.bottom = cf.bottom = mContentBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07004068 }
4069 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
4070 vf.left = mCurLeft;
4071 vf.top = mCurTop;
4072 vf.right = mCurRight;
4073 vf.bottom = mCurBottom;
4074 } else {
4075 vf.set(cf);
4076 }
Dianne Hackborndea3ef72010-10-28 14:24:22 -07004077 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004078 }
4079 }
Craig Mautner69b08182012-09-05 13:07:13 -07004080
Craig Mautnerb816bed2013-07-23 10:26:17 -07004081 // TYPE_SYSTEM_ERROR is above the NavigationBar so it can't be allowed to extend over it.
4082 if ((fl & FLAG_LAYOUT_NO_LIMITS) != 0 && attrs.type != TYPE_SYSTEM_ERROR) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07004083 df.left = df.top = -10000;
4084 df.right = df.bottom = 10000;
4085 if (attrs.type != TYPE_WALLPAPER) {
4086 of.left = of.top = cf.left = cf.top = vf.left = vf.top = -10000;
4087 of.right = of.bottom = cf.right = cf.bottom = vf.right = vf.bottom = 10000;
4088 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004089 }
4090
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004091 // If the device has a chin (e.g. some watches), a dead area at the bottom of the screen we
4092 // need to provide information to the clients that want to pretend that you can draw there.
Filip Gruszczynskib0c673b2015-06-05 09:43:06 -07004093 // We only want to apply outsets to certain types of windows. For example, we never want to
4094 // apply the outsets to floating dialogs, because they wouldn't make sense there.
4095 final boolean useOutsets = attrs.type == TYPE_WALLPAPER
4096 || (fl & (WindowManager.LayoutParams.FLAG_FULLSCREEN
4097 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_OVERSCAN)) != 0;
4098 if (isDefaultDisplay && useOutsets) {
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004099 osf = mTmpOutsetFrame;
4100 osf.set(cf.left, cf.top, cf.right, cf.bottom);
4101 int outset = ScreenShapeHelper.getWindowOutsetBottomPx(mContext.getResources());
4102 if (outset > 0) {
4103 int rotation = Surface.ROTATION_0;
4104 try {
4105 rotation = mWindowManager.getRotation();
4106 } catch (RemoteException e) {
4107 }
4108 if (rotation == Surface.ROTATION_0) {
4109 osf.bottom += outset;
4110 } else if (rotation == Surface.ROTATION_90) {
4111 osf.right += outset;
4112 } else if (rotation == Surface.ROTATION_180) {
4113 osf.top -= outset;
4114 } else if (rotation == Surface.ROTATION_270) {
4115 osf.left -= outset;
4116 }
4117 if (DEBUG_LAYOUT) Slog.v(TAG, "applying bottom outset of " + outset
4118 + " with rotation " + rotation + ", result: " + osf);
4119 }
4120 }
4121
Craig Mautnereda67292013-04-28 13:50:14 -07004122 if (DEBUG_LAYOUT) Slog.v(TAG, "Compute frame " + attrs.getTitle()
The Android Open Source Project11267662009-03-18 17:39:47 -07004123 + ": sim=#" + Integer.toHexString(sim)
RoboErik8a2cfc32014-05-16 11:19:38 -07004124 + " attach=" + attached + " type=" + attrs.type
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004125 + String.format(" flags=0x%08x", fl)
The Android Open Source Project11267662009-03-18 17:39:47 -07004126 + " pf=" + pf.toShortString() + " df=" + df.toShortString()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004127 + " of=" + of.toShortString()
John Spurlock46646232013-09-30 22:32:42 -04004128 + " cf=" + cf.toShortString() + " vf=" + vf.toShortString()
Adrian Roosfa104232014-06-20 16:10:14 -07004129 + " dcf=" + dcf.toShortString()
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004130 + " sf=" + sf.toShortString()
4131 + " osf=" + (osf == null ? "null" : osf.toShortString()));
Craig Mautner69b08182012-09-05 13:07:13 -07004132
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004133 win.computeFrameLw(pf, df, of, cf, vf, dcf, sf, osf);
Craig Mautner69b08182012-09-05 13:07:13 -07004134
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004135 // Dock windows carve out the bottom of the screen, so normal windows
4136 // can't appear underneath them.
Craig Mautner8bd206b2012-10-03 10:32:02 -07004137 if (attrs.type == TYPE_INPUT_METHOD && win.isVisibleOrBehindKeyguardLw()
4138 && !win.getGivenInsetsPendingLw()) {
satok1bc0a492012-04-25 22:47:12 +09004139 setLastInputMethodWindowLw(null, null);
4140 offsetInputMethodWindowLw(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004141 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004142 if (attrs.type == TYPE_VOICE_INTERACTION && win.isVisibleOrBehindKeyguardLw()
4143 && !win.getGivenInsetsPendingLw()) {
4144 offsetVoiceInputWindowLw(win);
4145 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004146 }
4147
satok1bc0a492012-04-25 22:47:12 +09004148 private void offsetInputMethodWindowLw(WindowState win) {
Craig Mautner4774f6a2015-03-23 11:42:55 -07004149 int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top);
satok1bc0a492012-04-25 22:47:12 +09004150 top += win.getGivenContentInsetsLw().top;
4151 if (mContentBottom > top) {
4152 mContentBottom = top;
4153 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004154 if (mVoiceContentBottom > top) {
4155 mVoiceContentBottom = top;
4156 }
satok1bc0a492012-04-25 22:47:12 +09004157 top = win.getVisibleFrameLw().top;
4158 top += win.getGivenVisibleInsetsLw().top;
4159 if (mCurBottom > top) {
4160 mCurBottom = top;
4161 }
Craig Mautnereda67292013-04-28 13:50:14 -07004162 if (DEBUG_LAYOUT) Slog.v(TAG, "Input method: mDockBottom="
satok1bc0a492012-04-25 22:47:12 +09004163 + mDockBottom + " mContentBottom="
4164 + mContentBottom + " mCurBottom=" + mCurBottom);
4165 }
4166
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004167 private void offsetVoiceInputWindowLw(WindowState win) {
Craig Mautner4774f6a2015-03-23 11:42:55 -07004168 int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08004169 top += win.getGivenContentInsetsLw().top;
4170 if (mVoiceContentBottom > top) {
4171 mVoiceContentBottom = top;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004172 }
4173 }
4174
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004175 /** {@inheritDoc} */
Craig Mautner61ac6bb2012-02-02 17:29:33 -08004176 @Override
4177 public void finishLayoutLw() {
4178 return;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004179 }
4180
4181 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004182 @Override
Craig Mautner39834192012-09-02 07:47:24 -07004183 public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) {
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004184 mTopFullscreenOpaqueWindowState = null;
Adrian Rooscd3884d2015-02-18 17:25:23 +01004185 mTopFullscreenOpaqueOrDimmingWindowState = null;
Craig Mautner2bc789b2014-03-19 19:48:38 -07004186 mAppsToBeHidden.clear();
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004187 mAppsThatDismissKeyguard.clear();
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004188 mForceStatusBar = false;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004189 mForceStatusBarFromKeyguard = false;
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004190 mForceStatusBarTransparent = false;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08004191 mForcingShowNavBar = false;
4192 mForcingShowNavBarLayer = -1;
RoboErik8a2cfc32014-05-16 11:19:38 -07004193
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004194 mHideLockScreen = false;
4195 mAllowLockscreenWhenOn = false;
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004196 mDismissKeyguard = DISMISS_KEYGUARD_NONE;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004197 mShowingLockscreen = false;
4198 mShowingDream = false;
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004199 mWinShowWhenLocked = null;
Jim Millerab954542014-10-10 18:21:49 -07004200 mKeyguardSecure = isKeyguardSecure();
4201 mKeyguardSecureIncludingHidden = mKeyguardSecure
4202 && (mKeyguardDelegate != null && mKeyguardDelegate.isShowing());
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004203 }
4204
4205 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004206 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004207 public void applyPostLayoutPolicyLw(WindowState win, WindowManager.LayoutParams attrs) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004208 if (DEBUG_LAYOUT) Slog.i(TAG, "Win " + win + ": isVisibleOrBehindKeyguardLw="
4209 + win.isVisibleOrBehindKeyguardLw());
John Spurlockc6d1c602014-01-17 15:22:06 -05004210 final int fl = PolicyControl.getWindowFlags(win, attrs);
John Spurlock414c1f02013-12-04 13:47:36 -05004211 if (mTopFullscreenOpaqueWindowState == null
4212 && win.isVisibleLw() && attrs.type == TYPE_INPUT_METHOD) {
4213 mForcingShowNavBar = true;
4214 mForcingShowNavBarLayer = win.getSurfaceLayer();
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08004215 }
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004216 if (attrs.type == TYPE_STATUS_BAR) {
4217 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
4218 mForceStatusBarFromKeyguard = true;
4219 }
4220 if ((attrs.privateFlags & PRIVATE_FLAG_FORCE_STATUS_BAR_VISIBLE_TRANSPARENT) != 0) {
4221 mForceStatusBarTransparent = true;
4222 }
Jorim Jaggiafd4a552014-04-08 15:13:05 +02004223 }
Adrian Roos602c68e2015-04-24 16:03:47 -07004224
4225 boolean appWindow = attrs.type >= FIRST_APPLICATION_WINDOW
4226 && attrs.type < FIRST_SYSTEM_WINDOW;
4227 final boolean showWhenLocked = (fl & FLAG_SHOW_WHEN_LOCKED) != 0;
4228 final boolean dismissKeyguard = (fl & FLAG_DISMISS_KEYGUARD) != 0;
4229
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004230 if (mTopFullscreenOpaqueWindowState == null &&
Dianne Hackborn01b02a72012-01-12 14:05:03 -08004231 win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()) {
John Spurlockc6d1c602014-01-17 15:22:06 -05004232 if ((fl & FLAG_FORCE_NOT_FULLSCREEN) != 0) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004233 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004234 mForceStatusBarFromKeyguard = true;
4235 } else {
4236 mForceStatusBar = true;
4237 }
4238 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004239 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004240 mShowingLockscreen = true;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004241 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004242 if (attrs.type == TYPE_DREAM) {
Jeff Brownc8018eb2012-10-29 21:33:27 -07004243 // If the lockscreen was showing when the dream started then wait
4244 // for the dream to draw before hiding the lockscreen.
4245 if (!mDreamingLockscreen
4246 || (win.isVisibleLw() && win.hasDrawnLw())) {
4247 mShowingDream = true;
Craig Mautnerab55e522014-03-03 13:26:03 -08004248 appWindow = true;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004249 }
4250 }
Craig Mautnerab55e522014-03-03 13:26:03 -08004251
Craig Mautnerab55e522014-03-03 13:26:03 -08004252 if (appWindow) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004253 final IApplicationToken appToken = win.getAppToken();
4254 if (showWhenLocked) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004255 // Remove any previous windows with the same appToken.
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004256 mAppsToBeHidden.remove(appToken);
4257 mAppsThatDismissKeyguard.remove(appToken);
Craig Mautnerca0a1242014-12-02 12:25:14 -08004258 if (mAppsToBeHidden.isEmpty()) {
Craig Mautner192d6042014-12-02 23:24:48 -08004259 if (dismissKeyguard && !mKeyguardSecure) {
4260 mAppsThatDismissKeyguard.add(appToken);
4261 } else {
Craig Mautnerca0a1242014-12-02 12:25:14 -08004262 mWinShowWhenLocked = win;
4263 mHideLockScreen = true;
4264 mForceStatusBarFromKeyguard = false;
Craig Mautnerca0a1242014-12-02 12:25:14 -08004265 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004266 }
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004267 } else if (dismissKeyguard) {
Jim Millerab954542014-10-10 18:21:49 -07004268 if (mKeyguardSecure) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004269 mAppsToBeHidden.add(appToken);
4270 } else {
4271 mAppsToBeHidden.remove(appToken);
4272 }
4273 mAppsThatDismissKeyguard.add(appToken);
Craig Mautner2bc789b2014-03-19 19:48:38 -07004274 } else {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004275 mAppsToBeHidden.add(appToken);
Craig Mautner2bc789b2014-03-19 19:48:38 -07004276 }
Craig Mautnerab55e522014-03-03 13:26:03 -08004277 if (attrs.x == 0 && attrs.y == 0
4278 && attrs.width == WindowManager.LayoutParams.MATCH_PARENT
4279 && attrs.height == WindowManager.LayoutParams.MATCH_PARENT) {
4280 if (DEBUG_LAYOUT) Slog.v(TAG, "Fullscreen window: " + win);
4281 mTopFullscreenOpaqueWindowState = win;
Adrian Rooscd3884d2015-02-18 17:25:23 +01004282 if (mTopFullscreenOpaqueOrDimmingWindowState == null) {
4283 mTopFullscreenOpaqueOrDimmingWindowState = win;
4284 }
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004285 if (!mAppsThatDismissKeyguard.isEmpty() &&
4286 mDismissKeyguard == DISMISS_KEYGUARD_NONE) {
4287 if (DEBUG_LAYOUT) Slog.v(TAG,
4288 "Setting mDismissKeyguard true by win " + win);
tingna_sunge785ffa2015-05-12 13:23:15 +08004289 mDismissKeyguard = (mWinDismissingKeyguard == win
4290 && mSecureDismissingKeyguard == mKeyguardSecure)
4291 ? DISMISS_KEYGUARD_CONTINUE : DISMISS_KEYGUARD_START;
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004292 mWinDismissingKeyguard = win;
tingna_sunge785ffa2015-05-12 13:23:15 +08004293 mSecureDismissingKeyguard = mKeyguardSecure;
Jim Millerab954542014-10-10 18:21:49 -07004294 mForceStatusBarFromKeyguard = mShowingLockscreen && mKeyguardSecure;
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004295 } else if (mAppsToBeHidden.isEmpty() && showWhenLocked) {
4296 if (DEBUG_LAYOUT) Slog.v(TAG,
4297 "Setting mHideLockScreen to true by win " + win);
4298 mHideLockScreen = true;
4299 mForceStatusBarFromKeyguard = false;
Craig Mautnerab55e522014-03-03 13:26:03 -08004300 }
Craig Mautner00156ec2014-03-06 22:29:02 -08004301 if ((fl & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) {
Craig Mautnerab55e522014-03-03 13:26:03 -08004302 mAllowLockscreenWhenOn = true;
4303 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004304 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004305
4306 if (mWinShowWhenLocked != null &&
Adrian Roos602c68e2015-04-24 16:03:47 -07004307 mWinShowWhenLocked.getAppToken() != win.getAppToken() &&
4308 (attrs.flags & FLAG_SHOW_WHEN_LOCKED) == 0) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004309 win.hideLw(false);
4310 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004311 }
Adrian Roos602c68e2015-04-24 16:03:47 -07004312 } else if (mTopFullscreenOpaqueWindowState == null && mWinShowWhenLocked == null) {
4313 // No TopFullscreenOpaqueWindow is showing, but we found a SHOW_WHEN_LOCKED window
4314 // that is being hidden in an animation - keep the
4315 // keyguard hidden until the new window shows up and
4316 // we know whether to show the keyguard or not.
Adrian Roosb85e1ec2015-05-29 15:23:18 -07004317 if (win.isAnimatingLw() && appWindow && showWhenLocked && mKeyguardHidden) {
Adrian Roos602c68e2015-04-24 16:03:47 -07004318 mHideLockScreen = true;
4319 mWinShowWhenLocked = win;
4320 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004321 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01004322 if (mTopFullscreenOpaqueOrDimmingWindowState == null
4323 && win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()
4324 && win.isDimming()) {
4325 mTopFullscreenOpaqueOrDimmingWindowState = win;
4326 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004327 }
4328
4329 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004330 @Override
Craig Mautner39834192012-09-02 07:47:24 -07004331 public int finishPostLayoutPolicyLw() {
Craig Mautnerc5e73bf2015-04-21 15:41:26 +00004332 if (mWinShowWhenLocked != null && mTopFullscreenOpaqueWindowState != null &&
4333 mWinShowWhenLocked.getAppToken() != mTopFullscreenOpaqueWindowState.getAppToken()
4334 && isKeyguardLocked()) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004335 // A dialog is dismissing the keyguard. Put the wallpaper behind it and hide the
4336 // fullscreen window.
4337 // TODO: Make sure FLAG_SHOW_WALLPAPER is restored when dialog is dismissed. Or not.
4338 mWinShowWhenLocked.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
4339 mTopFullscreenOpaqueWindowState.hideLw(false);
4340 mTopFullscreenOpaqueWindowState = mWinShowWhenLocked;
4341 }
4342
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004343 int changes = 0;
Joe Onorato93056472010-09-10 10:30:46 -04004344 boolean topIsFullscreen = false;
Daniel Sandlere02d8082010-10-08 15:13:22 -04004345
4346 final WindowManager.LayoutParams lp = (mTopFullscreenOpaqueWindowState != null)
4347 ? mTopFullscreenOpaqueWindowState.getAttrs()
4348 : null;
4349
Jeff Brownc8018eb2012-10-29 21:33:27 -07004350 // If we are not currently showing a dream then remember the current
4351 // lockscreen state. We will use this to determine whether the dream
4352 // started while the lockscreen was showing and remember this state
4353 // while the dream is showing.
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004354 if (!mShowingDream) {
4355 mDreamingLockscreen = mShowingLockscreen;
Jeff Brown061ea992015-04-17 19:55:47 -07004356 if (mDreamingSleepTokenNeeded) {
4357 mDreamingSleepTokenNeeded = false;
4358 mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 0, 1).sendToTarget();
4359 }
4360 } else {
4361 if (!mDreamingSleepTokenNeeded) {
4362 mDreamingSleepTokenNeeded = true;
4363 mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 1, 1).sendToTarget();
4364 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004365 }
4366
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004367 if (mStatusBar != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07004368 if (DEBUG_LAYOUT) Slog.i(TAG, "force=" + mForceStatusBar
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004369 + " forcefkg=" + mForceStatusBarFromKeyguard
Dianne Hackbornd70bc2f2009-10-06 23:25:51 -07004370 + " top=" + mTopFullscreenOpaqueWindowState);
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004371 boolean shouldBeTransparent = mForceStatusBarTransparent
4372 && !mForceStatusBar
4373 && !mForceStatusBarFromKeyguard;
4374 if (!shouldBeTransparent) {
4375 mStatusBarController.setShowTransparent(false /* transparent */);
4376 } else if (!mStatusBar.isVisibleLw()) {
4377 mStatusBarController.setShowTransparent(true /* transparent */);
4378 }
4379 if (mForceStatusBar || mForceStatusBarFromKeyguard || mForceStatusBarTransparent) {
Craig Mautnereda67292013-04-28 13:50:14 -07004380 if (DEBUG_LAYOUT) Slog.v(TAG, "Showing status bar: forced");
John Spurlock27735a42013-08-14 17:57:38 -04004381 if (mStatusBarController.setBarShowingLw(true)) {
4382 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4383 }
Craig Mautner81defc72013-10-29 11:10:42 -07004384 // Maintain fullscreen layout until incoming animation is complete.
4385 topIsFullscreen = mTopIsFullscreen && mStatusBar.isAnimatingLw();
John Spurlockf92b6162013-11-11 15:01:16 -05004386 // Transient status bar on the lockscreen is not allowed
4387 if (mForceStatusBarFromKeyguard && mStatusBarController.isTransientShowing()) {
4388 mStatusBarController.updateVisibilityLw(false /*transientAllowed*/,
4389 mLastSystemUiFlags, mLastSystemUiFlags);
4390 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004391 } else if (mTopFullscreenOpaqueWindowState != null) {
John Spurlockc6d1c602014-01-17 15:22:06 -05004392 final int fl = PolicyControl.getWindowFlags(null, lp);
Joe Onorato93056472010-09-10 10:30:46 -04004393 if (localLOGV) {
Craig Mautnereda67292013-04-28 13:50:14 -07004394 Slog.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw()
Joe Onorato93056472010-09-10 10:30:46 -04004395 + " shown frame: " + mTopFullscreenOpaqueWindowState.getShownFrameLw());
Craig Mautnereda67292013-04-28 13:50:14 -07004396 Slog.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs()
John Spurlockc6d1c602014-01-17 15:22:06 -05004397 + " lp.flags=0x" + Integer.toHexString(fl));
Joe Onorato93056472010-09-10 10:30:46 -04004398 }
John Spurlockc6d1c602014-01-17 15:22:06 -05004399 topIsFullscreen = (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004400 || (mLastSystemUiFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
Joe Onorato93056472010-09-10 10:30:46 -04004401 // The subtle difference between the window for mTopFullscreenOpaqueWindowState
Mark Dolinerd0646dc2014-08-27 16:04:02 -07004402 // and mTopIsFullscreen is that mTopIsFullscreen is set only if the window
Joe Onorato93056472010-09-10 10:30:46 -04004403 // has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the
4404 // case though.
John Spurlock27735a42013-08-14 17:57:38 -04004405 if (mStatusBarController.isTransientShowing()) {
4406 if (mStatusBarController.setBarShowingLw(true)) {
John Spurlock32beb2c2013-03-11 10:16:47 -04004407 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4408 }
4409 } else if (topIsFullscreen) {
Craig Mautnereda67292013-04-28 13:50:14 -07004410 if (DEBUG_LAYOUT) Slog.v(TAG, "** HIDING status bar");
John Spurlock27735a42013-08-14 17:57:38 -04004411 if (mStatusBarController.setBarShowingLw(false)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004412 changes |= FINISH_LAYOUT_REDO_LAYOUT;
Craig Mautnereda67292013-04-28 13:50:14 -07004413 } else {
Craig Mautnerc5a6e442013-06-05 17:22:35 -07004414 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar already hiding");
Daniel Sandler40427442010-07-16 11:44:52 -04004415 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004416 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07004417 if (DEBUG_LAYOUT) Slog.v(TAG, "** SHOWING status bar: top is not fullscreen");
John Spurlock27735a42013-08-14 17:57:38 -04004418 if (mStatusBarController.setBarShowingLw(true)) {
4419 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4420 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004421 }
4422 }
4423 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04004424
Craig Mautner81defc72013-10-29 11:10:42 -07004425 if (mTopIsFullscreen != topIsFullscreen) {
4426 if (!topIsFullscreen) {
4427 // Force another layout when status bar becomes fully shown.
4428 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4429 }
4430 mTopIsFullscreen = topIsFullscreen;
4431 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04004432
Craig Mautner39834192012-09-02 07:47:24 -07004433 // Hide the key guard if a visible window explicitly specifies that it wants to be
4434 // displayed when the screen is locked.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004435 if (mKeyguardDelegate != null && mStatusBar != null) {
4436 if (localLOGV) Slog.v(TAG, "finishPostLayoutPolicyLw: mHideKeyguard="
4437 + mHideLockScreen);
Jim Millerab954542014-10-10 18:21:49 -07004438 if (mDismissKeyguard != DISMISS_KEYGUARD_NONE && !mKeyguardSecure) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004439 mKeyguardHidden = true;
Jim Millerab954542014-10-10 18:21:49 -07004440 if (setKeyguardOccludedLw(true)) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004441 changes |= FINISH_LAYOUT_REDO_LAYOUT
4442 | FINISH_LAYOUT_REDO_CONFIG
4443 | FINISH_LAYOUT_REDO_WALLPAPER;
4444 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004445 if (mKeyguardDelegate.isShowing()) {
4446 mHandler.post(new Runnable() {
4447 @Override
4448 public void run() {
4449 mKeyguardDelegate.keyguardDone(false, false);
4450 }
4451 });
4452 }
4453 } else if (mHideLockScreen) {
4454 mKeyguardHidden = true;
Jorim Jaggi7d85ea92015-05-20 17:20:40 -07004455 mWinDismissingKeyguard = null;
Jim Millerab954542014-10-10 18:21:49 -07004456 if (setKeyguardOccludedLw(true)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004457 changes |= FINISH_LAYOUT_REDO_LAYOUT
4458 | FINISH_LAYOUT_REDO_CONFIG
4459 | FINISH_LAYOUT_REDO_WALLPAPER;
4460 }
4461 } else if (mDismissKeyguard != DISMISS_KEYGUARD_NONE) {
Jorim Jaggi7d85ea92015-05-20 17:20:40 -07004462 mKeyguardHidden = false;
4463 if (setKeyguardOccludedLw(false)) {
4464 changes |= FINISH_LAYOUT_REDO_LAYOUT
4465 | FINISH_LAYOUT_REDO_CONFIG
4466 | FINISH_LAYOUT_REDO_WALLPAPER;
4467 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004468 if (mDismissKeyguard == DISMISS_KEYGUARD_START) {
4469 // Only launch the next keyguard unlock window once per window.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004470 mHandler.post(new Runnable() {
4471 @Override
4472 public void run() {
4473 mKeyguardDelegate.dismiss();
4474 }
4475 });
4476 }
4477 } else {
4478 mWinDismissingKeyguard = null;
tingna_sunge785ffa2015-05-12 13:23:15 +08004479 mSecureDismissingKeyguard = false;
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004480 mKeyguardHidden = false;
Jim Millerab954542014-10-10 18:21:49 -07004481 if (setKeyguardOccludedLw(false)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004482 changes |= FINISH_LAYOUT_REDO_LAYOUT
4483 | FINISH_LAYOUT_REDO_CONFIG
4484 | FINISH_LAYOUT_REDO_WALLPAPER;
4485 }
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -07004486 }
4487 }
Joe Onorato664644d2011-01-23 17:53:23 -08004488
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004489 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004490 // If the navigation bar has been hidden or shown, we need to do another
4491 // layout pass to update that window.
4492 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4493 }
Joe Onorato664644d2011-01-23 17:53:23 -08004494
Mike Lockwood28569302010-01-28 11:54:40 -05004495 // update since mAllowLockscreenWhenOn might have changed
4496 updateLockScreenTimeout();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004497 return changes;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004498 }
4499
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004500 /**
Jim Millerab954542014-10-10 18:21:49 -07004501 * Updates the occluded state of the Keyguard.
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004502 *
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004503 * @return Whether the flags have changed and we have to redo the layout.
4504 */
Jim Millerab954542014-10-10 18:21:49 -07004505 private boolean setKeyguardOccludedLw(boolean isOccluded) {
4506 boolean wasOccluded = mKeyguardOccluded;
4507 boolean showing = mKeyguardDelegate.isShowing();
4508 if (wasOccluded && !isOccluded && showing) {
4509 mKeyguardOccluded = false;
4510 mKeyguardDelegate.setOccluded(false);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004511 mStatusBar.getAttrs().privateFlags |= PRIVATE_FLAG_KEYGUARD;
4512 mStatusBar.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
4513 return true;
Jim Millerab954542014-10-10 18:21:49 -07004514 } else if (!wasOccluded && isOccluded && showing) {
4515 mKeyguardOccluded = true;
4516 mKeyguardDelegate.setOccluded(true);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004517 mStatusBar.getAttrs().privateFlags &= ~PRIVATE_FLAG_KEYGUARD;
4518 mStatusBar.getAttrs().flags &= ~FLAG_SHOW_WALLPAPER;
4519 return true;
4520 } else {
4521 return false;
4522 }
4523 }
4524
4525 private boolean isStatusBarKeyguard() {
4526 return mStatusBar != null
4527 && (mStatusBar.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
4528 }
4529
Jose Lima9546b202014-07-02 17:21:51 -07004530 @Override
Dianne Hackborn08743722009-12-21 12:16:51 -08004531 public boolean allowAppAnimationsLw() {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004532 if (isStatusBarKeyguard() || mShowingDream) {
Craig Mautner28816302013-10-10 20:31:00 -07004533 // If keyguard or dreams is currently visible, no reason to animate behind it.
Dianne Hackborn08743722009-12-21 12:16:51 -08004534 return false;
4535 }
Dianne Hackborn08743722009-12-21 12:16:51 -08004536 return true;
4537 }
4538
Jose Lima9546b202014-07-02 17:21:51 -07004539 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07004540 public int focusChangedLw(WindowState lastFocus, WindowState newFocus) {
Joe Onorato664644d2011-01-23 17:53:23 -08004541 mFocusedWindow = newFocus;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004542 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004543 // If the navigation bar has been hidden or shown, we need to do another
4544 // layout pass to update that window.
4545 return FINISH_LAYOUT_REDO_LAYOUT;
4546 }
4547 return 0;
Joe Onorato664644d2011-01-23 17:53:23 -08004548 }
4549
Dianne Hackborn0ecadf72009-03-31 18:00:37 -07004550 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07004551 @Override
Jeff Brown46b9ac02010-04-22 18:58:52 -07004552 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
4553 // lid changed state
Jeff Brownc458ce92012-04-30 14:58:40 -07004554 final int newLidState = lidOpen ? LID_OPEN : LID_CLOSED;
4555 if (newLidState == mLidState) {
4556 return;
4557 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004558
Jeff Brownc458ce92012-04-30 14:58:40 -07004559 mLidState = newLidState;
4560 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07004561 updateRotation(true);
Jeff Brownc458ce92012-04-30 14:58:40 -07004562
4563 if (lidOpen) {
Bryce Lee584a4452014-10-21 15:55:55 -07004564 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromLidSwitch);
Jeff Brownc458ce92012-04-30 14:58:40 -07004565 } else if (!mLidControlsSleep) {
Jeff Brown96307042012-07-27 15:51:34 -07004566 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
Jeff Brown46b9ac02010-04-22 18:58:52 -07004567 }
4568 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004569
Michael Wright3818c922014-09-02 13:59:07 -07004570 @Override
4571 public void notifyCameraLensCoverSwitchChanged(long whenNanos, boolean lensCovered) {
4572 int lensCoverState = lensCovered ? CAMERA_LENS_COVERED : CAMERA_LENS_UNCOVERED;
4573 if (mCameraLensCoverState == lensCoverState) {
4574 return;
4575 }
4576 if (mCameraLensCoverState == CAMERA_LENS_COVERED &&
4577 lensCoverState == CAMERA_LENS_UNCOVERED) {
4578 Intent intent;
4579 final boolean keyguardActive = mKeyguardDelegate == null ? false :
4580 mKeyguardDelegate.isShowing();
4581 if (keyguardActive) {
4582 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE);
4583 } else {
4584 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
4585 }
Bryce Lee584a4452014-10-21 15:55:55 -07004586 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromCameraLens);
Bart Sears8b1c27c2015-03-18 23:51:02 +00004587 startActivityAsUser(intent, UserHandle.CURRENT_OR_SELF);
Michael Wright3818c922014-09-02 13:59:07 -07004588 }
4589 mCameraLensCoverState = lensCoverState;
4590 }
4591
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004592 void setHdmiPlugged(boolean plugged) {
4593 if (mHdmiPlugged != plugged) {
4594 mHdmiPlugged = plugged;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004595 updateRotation(true, true);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004596 Intent intent = new Intent(ACTION_HDMI_PLUGGED);
Joe Onoratodc100302011-01-11 17:07:41 -08004597 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004598 intent.putExtra(EXTRA_HDMI_PLUGGED_STATE, plugged);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07004599 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004600 }
4601 }
4602
Joe Onoratoea495d42011-04-06 11:41:11 -07004603 void initializeHdmiState() {
Joe Onorato7ba631f2011-05-04 15:28:00 -07004604 boolean plugged = false;
Joe Onoratoea495d42011-04-06 11:41:11 -07004605 // watch for HDMI plug messages if the hdmi switch exists
4606 if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) {
4607 mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi");
4608
Joe Onoratoea495d42011-04-06 11:41:11 -07004609 final String filename = "/sys/class/switch/hdmi/state";
4610 FileReader reader = null;
4611 try {
4612 reader = new FileReader(filename);
4613 char[] buf = new char[15];
4614 int n = reader.read(buf);
4615 if (n > 1) {
4616 plugged = 0 != Integer.parseInt(new String(buf, 0, n-1));
4617 }
4618 } catch (IOException ex) {
4619 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
4620 } catch (NumberFormatException ex) {
4621 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
4622 } finally {
4623 if (reader != null) {
4624 try {
4625 reader.close();
4626 } catch (IOException ex) {
4627 }
Joe Onoratodc100302011-01-11 17:07:41 -08004628 }
4629 }
4630 }
Joe Onorato7ba631f2011-05-04 15:28:00 -07004631 // This dance forces the code in setHdmiPlugged to run.
4632 // Always do this so the sticky intent is stuck (to false) if there is no hdmi.
4633 mHdmiPlugged = !plugged;
4634 setHdmiPlugged(!mHdmiPlugged);
Joe Onoratodc100302011-01-11 17:07:41 -08004635 }
4636
Dianne Hackbornc0e3f242011-08-19 14:19:10 -07004637 final Object mScreenshotLock = new Object();
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004638 ServiceConnection mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004639
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004640 final Runnable mScreenshotTimeout = new Runnable() {
4641 @Override public void run() {
4642 synchronized (mScreenshotLock) {
4643 if (mScreenshotConnection != null) {
4644 mContext.unbindService(mScreenshotConnection);
4645 mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004646 }
Winson Chung9112ec32011-06-27 13:15:32 -07004647 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004648 }
4649 };
4650
4651 // Assume this is called from the Handler thread.
4652 private void takeScreenshot() {
4653 synchronized (mScreenshotLock) {
4654 if (mScreenshotConnection != null) {
4655 return;
4656 }
4657 ComponentName cn = new ComponentName("com.android.systemui",
4658 "com.android.systemui.screenshot.TakeScreenshotService");
4659 Intent intent = new Intent();
4660 intent.setComponent(cn);
4661 ServiceConnection conn = new ServiceConnection() {
4662 @Override
4663 public void onServiceConnected(ComponentName name, IBinder service) {
4664 synchronized (mScreenshotLock) {
4665 if (mScreenshotConnection != this) {
4666 return;
4667 }
4668 Messenger messenger = new Messenger(service);
4669 Message msg = Message.obtain(null, 1);
4670 final ServiceConnection myConn = this;
4671 Handler h = new Handler(mHandler.getLooper()) {
4672 @Override
4673 public void handleMessage(Message msg) {
4674 synchronized (mScreenshotLock) {
4675 if (mScreenshotConnection == myConn) {
4676 mContext.unbindService(mScreenshotConnection);
4677 mScreenshotConnection = null;
4678 mHandler.removeCallbacks(mScreenshotTimeout);
4679 }
4680 }
4681 }
4682 };
4683 msg.replyTo = new Messenger(h);
Winson Chunga63bb842011-10-17 10:26:28 -07004684 msg.arg1 = msg.arg2 = 0;
4685 if (mStatusBar != null && mStatusBar.isVisibleLw())
4686 msg.arg1 = 1;
4687 if (mNavigationBar != null && mNavigationBar.isVisibleLw())
4688 msg.arg2 = 1;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004689 try {
4690 messenger.send(msg);
4691 } catch (RemoteException e) {
4692 }
4693 }
4694 }
4695 @Override
4696 public void onServiceDisconnected(ComponentName name) {}
4697 };
Amith Yamasani27b89e62013-01-16 12:30:11 -08004698 if (mContext.bindServiceAsUser(
4699 intent, conn, Context.BIND_AUTO_CREATE, UserHandle.CURRENT)) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004700 mScreenshotConnection = conn;
4701 mHandler.postDelayed(mScreenshotTimeout, 10000);
4702 }
4703 }
Winson Chung9112ec32011-06-27 13:15:32 -07004704 }
4705
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004706 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004707 @Override
Jeff Brown037c33e2014-04-09 00:31:55 -07004708 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) {
Jeff Brown96307042012-07-27 15:51:34 -07004709 if (!mSystemBooted) {
4710 // If we have not yet booted, don't let key events do anything.
4711 return 0;
4712 }
4713
Jeff Brown037c33e2014-04-09 00:31:55 -07004714 final boolean interactive = (policyFlags & FLAG_INTERACTIVE) != 0;
Jeff Brown1f245102010-11-18 20:53:46 -08004715 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
4716 final boolean canceled = event.isCanceled();
4717 final int keyCode = event.getKeyCode();
Jeff Browne20c9e02010-10-11 14:20:19 -07004718
Jeff Brown3122e442010-10-11 23:32:49 -07004719 final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0;
Jeff Brown3122e442010-10-11 23:32:49 -07004720
Mike Lockwoodc72b15f2009-11-28 20:58:22 -05004721 // If screen is off then we treat the case where the keyguard is open but hidden
4722 // the same as if it were open and in front.
4723 // This will prevent any keys other than the power button from waking the screen
4724 // when the keyguard is hidden by another activity.
Jim Miller5ecd8112013-01-09 18:50:26 -08004725 final boolean keyguardActive = (mKeyguardDelegate == null ? false :
Jeff Brown037c33e2014-04-09 00:31:55 -07004726 (interactive ?
Jim Millerab954542014-10-10 18:21:49 -07004727 isKeyguardShowingAndNotOccluded() :
Jim Miller5ecd8112013-01-09 18:50:26 -08004728 mKeyguardDelegate.isShowing()));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004729
Jeff Brown40013652012-05-16 21:22:36 -07004730 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004731 Log.d(TAG, "interceptKeyTq keycode=" + keyCode
Jeff Brown037c33e2014-04-09 00:31:55 -07004732 + " interactive=" + interactive + " keyguardActive=" + keyguardActive
Jeff Brown26875502014-01-30 21:47:47 -08004733 + " policyFlags=" + Integer.toHexString(policyFlags));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004734 }
4735
Jeff Brown037c33e2014-04-09 00:31:55 -07004736 // Basic policy based on interactive state.
Jeff Brown4d396052010-10-29 21:50:21 -07004737 int result;
Michael Wright337d9d22014-04-22 15:03:48 -07004738 boolean isWakeKey = (policyFlags & WindowManagerPolicy.FLAG_WAKE) != 0
4739 || event.isWakeKey();
Michael Wrightfc01f042014-09-08 14:12:24 -07004740 if (interactive || (isInjected && !isWakeKey)) {
RoboErikde9ba392014-09-26 12:51:01 -07004741 // When the device is interactive or the key is injected pass the
4742 // key to the application.
Jeff Brown4d396052010-10-29 21:50:21 -07004743 result = ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07004744 isWakeKey = false;
Michael Wrightfc01f042014-09-08 14:12:24 -07004745 } else if (!interactive && shouldDispatchInputWhenNonInteractive()) {
4746 // If we're currently dozing with the screen on and the keyguard showing, pass the key
4747 // to the application but preserve its wake key status to make sure we still move
4748 // from dozing to fully interactive if we would normally go from off to fully
4749 // interactive.
4750 result = ACTION_PASS_TO_USER;
Jeff Brown4d396052010-10-29 21:50:21 -07004751 } else {
4752 // When the screen is off and the key is not injected, determine whether
4753 // to wake the device but don't pass the key to the application.
4754 result = 0;
Jeff Brown26875502014-01-30 21:47:47 -08004755 if (isWakeKey && (!down || !isWakeKeyWhenScreenOff(keyCode))) {
4756 isWakeKey = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004757 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004758 }
4759
Justin Kohd378ad72013-04-01 12:18:26 -07004760 // If the key would be handled globally, just return the result, don't worry about special
4761 // key processing.
Jeff Brown13f00f02014-10-31 14:45:50 -07004762 if (isValidGlobalKey(keyCode)
4763 && mGlobalKeyManager.shouldHandleGlobalKey(keyCode, event)) {
Michael Wright85b1af62014-06-04 14:51:58 -07004764 if (isWakeKey) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004765 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey);
Michael Wright85b1af62014-06-04 14:51:58 -07004766 }
Justin Kohd378ad72013-04-01 12:18:26 -07004767 return result;
4768 }
4769
Jeff Brownbae8e772014-06-12 19:59:45 -07004770 boolean useHapticFeedback = down
4771 && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0
4772 && event.getRepeatCount() == 0;
4773
Jeff Brown4d396052010-10-29 21:50:21 -07004774 // Handle special keys.
4775 switch (keyCode) {
4776 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jeff Brownb0418da2010-11-01 15:24:01 -07004777 case KeyEvent.KEYCODE_VOLUME_UP:
4778 case KeyEvent.KEYCODE_VOLUME_MUTE: {
RoboErik001c59c2015-01-26 15:53:51 -08004779 if (mUseTvRouting) {
4780 // On TVs volume keys never go to the foreground app
4781 result &= ~ACTION_PASS_TO_USER;
4782 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004783 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
4784 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004785 if (interactive && !mScreenshotChordVolumeDownKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004786 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004787 mScreenshotChordVolumeDownKeyTriggered = true;
4788 mScreenshotChordVolumeDownKeyTime = event.getDownTime();
4789 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004790 cancelPendingPowerKeyAction();
4791 interceptScreenshotChord();
4792 }
4793 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004794 mScreenshotChordVolumeDownKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004795 cancelPendingScreenshotChordAction();
4796 }
4797 } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
4798 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004799 if (interactive && !mScreenshotChordVolumeUpKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004800 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004801 mScreenshotChordVolumeUpKeyTriggered = true;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004802 cancelPendingPowerKeyAction();
4803 cancelPendingScreenshotChordAction();
4804 }
4805 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004806 mScreenshotChordVolumeUpKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004807 cancelPendingScreenshotChordAction();
4808 }
4809 }
Jeff Brown4d396052010-10-29 21:50:21 -07004810 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004811 TelecomManager telecomManager = getTelecommService();
4812 if (telecomManager != null) {
4813 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07004814 // If an incoming call is ringing, either VOLUME key means
4815 // "silence ringer". We handle these keys here, rather than
4816 // in the InCallScreen, to make sure we'll respond to them
4817 // even if the InCallScreen hasn't come to the foreground yet.
4818 // Look for the DOWN event here, to agree with the "fallback"
4819 // behavior in the InCallScreen.
4820 Log.i(TAG, "interceptKeyBeforeQueueing:"
4821 + " VOLUME key-down while ringing: Silence ringer!");
Jeff Brown4d396052010-10-29 21:50:21 -07004822
Santos Cordon6848f722014-05-21 15:22:12 -07004823 // Silence the ringer. (It's safe to call this
4824 // even if the ringer has already been silenced.)
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004825 telecomManager.silenceRinger();
Jeff Brown4d396052010-10-29 21:50:21 -07004826
Santos Cordon6848f722014-05-21 15:22:12 -07004827 // And *don't* pass this key thru to the current activity
4828 // (which is probably the InCallScreen.)
4829 result &= ~ACTION_PASS_TO_USER;
4830 break;
4831 }
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004832 if (telecomManager.isInCall()
Santos Cordon6848f722014-05-21 15:22:12 -07004833 && (result & ACTION_PASS_TO_USER) == 0) {
4834 // If we are in call but we decided not to pass the key to
RoboErik430fc482014-06-12 15:49:20 -07004835 // the application, just pass it to the session service.
4836
4837 MediaSessionLegacyHelper.getHelper(mContext)
RoboErik3c45c292014-07-08 16:47:31 -07004838 .sendVolumeKeyEvent(event, false);
Santos Cordon6848f722014-05-21 15:22:12 -07004839 break;
Jeff Brown4d396052010-10-29 21:50:21 -07004840 }
4841 }
4842
RoboErik430fc482014-06-12 15:49:20 -07004843 if ((result & ACTION_PASS_TO_USER) == 0) {
RoboErik001c59c2015-01-26 15:53:51 -08004844 if (mUseTvRouting) {
4845 dispatchDirectAudioEvent(event);
4846 } else {
4847 // If we aren't passing to the user and no one else
4848 // handled it send it to the session manager to
4849 // figure out.
4850 MediaSessionLegacyHelper.getHelper(mContext)
4851 .sendVolumeKeyEvent(event, true);
4852 }
Jeff Brown4d396052010-10-29 21:50:21 -07004853 break;
4854 }
4855 }
4856 break;
4857 }
4858
4859 case KeyEvent.KEYCODE_ENDCALL: {
4860 result &= ~ACTION_PASS_TO_USER;
4861 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004862 TelecomManager telecomManager = getTelecommService();
Jeff Brown4d396052010-10-29 21:50:21 -07004863 boolean hungUp = false;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004864 if (telecomManager != null) {
4865 hungUp = telecomManager.endCall();
Jeff Brown4d396052010-10-29 21:50:21 -07004866 }
Jeff Brown13f00f02014-10-31 14:45:50 -07004867 if (interactive && !hungUp) {
4868 mEndCallKeyHandled = false;
4869 mHandler.postDelayed(mEndCallLongPress,
4870 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
4871 } else {
4872 mEndCallKeyHandled = true;
4873 }
Jeff Brown4d396052010-10-29 21:50:21 -07004874 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004875 if (!mEndCallKeyHandled) {
4876 mHandler.removeCallbacks(mEndCallLongPress);
4877 if (!canceled) {
4878 if ((mEndcallBehavior
4879 & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) {
4880 if (goHome()) {
4881 break;
4882 }
Dianne Hackborn0041e972009-07-24 17:14:43 -07004883 }
Jeff Brown13f00f02014-10-31 14:45:50 -07004884 if ((mEndcallBehavior
4885 & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) {
4886 mPowerManager.goToSleep(event.getEventTime(),
4887 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
4888 isWakeKey = false;
4889 }
Jeff Brown4d396052010-10-29 21:50:21 -07004890 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004891 }
Jeff Brown4d396052010-10-29 21:50:21 -07004892 }
4893 break;
4894 }
4895
4896 case KeyEvent.KEYCODE_POWER: {
4897 result &= ~ACTION_PASS_TO_USER;
Jeff Brown13f00f02014-10-31 14:45:50 -07004898 isWakeKey = false; // wake-up will be handled separately
Jeff Brown4d396052010-10-29 21:50:21 -07004899 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004900 interceptPowerKeyDown(event, interactive);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004901 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004902 interceptPowerKeyUp(event, interactive, canceled);
Jeff Brown4d396052010-10-29 21:50:21 -07004903 }
4904 break;
4905 }
4906
Jeff Brown6212a492014-03-07 13:58:47 -08004907 case KeyEvent.KEYCODE_SLEEP: {
4908 result &= ~ACTION_PASS_TO_USER;
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00004909 isWakeKey = false;
Jeff Brownbae8e772014-06-12 19:59:45 -07004910 if (!mPowerManager.isInteractive()) {
4911 useHapticFeedback = false; // suppress feedback if already non-interactive
4912 }
Nick Vaccarob593a812015-05-15 11:23:05 -07004913 if (down) {
4914 sleepPress(event.getEventTime());
4915 } else {
4916 sleepRelease(event.getEventTime());
4917 }
Jeff Brown6212a492014-03-07 13:58:47 -08004918 break;
4919 }
4920
4921 case KeyEvent.KEYCODE_WAKEUP: {
4922 result &= ~ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07004923 isWakeKey = true;
Jeff Brown6212a492014-03-07 13:58:47 -08004924 break;
4925 }
4926
Jeff Brown4d396052010-10-29 21:50:21 -07004927 case KeyEvent.KEYCODE_MEDIA_PLAY:
4928 case KeyEvent.KEYCODE_MEDIA_PAUSE:
4929 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
Jeff Brown4d396052010-10-29 21:50:21 -07004930 case KeyEvent.KEYCODE_HEADSETHOOK:
4931 case KeyEvent.KEYCODE_MUTE:
4932 case KeyEvent.KEYCODE_MEDIA_STOP:
4933 case KeyEvent.KEYCODE_MEDIA_NEXT:
4934 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
4935 case KeyEvent.KEYCODE_MEDIA_REWIND:
4936 case KeyEvent.KEYCODE_MEDIA_RECORD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09004937 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
4938 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: {
RoboErikde9ba392014-09-26 12:51:01 -07004939 if (MediaSessionLegacyHelper.getHelper(mContext).isGlobalPriorityActive()) {
4940 // If the global session is active pass all media keys to it
4941 // instead of the active window.
4942 result &= ~ACTION_PASS_TO_USER;
4943 }
Jeff Brown4d396052010-10-29 21:50:21 -07004944 if ((result & ACTION_PASS_TO_USER) == 0) {
4945 // Only do this if we would otherwise not pass it to the user. In that
4946 // case, the PhoneWindow class will do the same thing, except it will
4947 // only do it if the showing app doesn't process the key on its own.
Jeff Brown40013652012-05-16 21:22:36 -07004948 // Note that we need to make a copy of the key event here because the
4949 // original key event will be recycled when we return.
Jeff Brown4d396052010-10-29 21:50:21 -07004950 mBroadcastWakeLock.acquire();
Jeff Brown40013652012-05-16 21:22:36 -07004951 Message msg = mHandler.obtainMessage(MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK,
4952 new KeyEvent(event));
4953 msg.setAsynchronous(true);
4954 msg.sendToTarget();
Jeff Brown4d396052010-10-29 21:50:21 -07004955 }
4956 break;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004957 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004958
Jeff Brown4d396052010-10-29 21:50:21 -07004959 case KeyEvent.KEYCODE_CALL: {
4960 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004961 TelecomManager telecomManager = getTelecommService();
4962 if (telecomManager != null) {
4963 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07004964 Log.i(TAG, "interceptKeyBeforeQueueing:"
4965 + " CALL key-down while ringing: Answer the call!");
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004966 telecomManager.acceptRingingCall();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004967
Santos Cordon6848f722014-05-21 15:22:12 -07004968 // And *don't* pass this key thru to the current activity
4969 // (which is presumably the InCallScreen.)
4970 result &= ~ACTION_PASS_TO_USER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004971 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004972 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004973 }
Jeff Brown4d396052010-10-29 21:50:21 -07004974 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004975 }
Michael Wright869a67c2014-08-26 19:33:06 -07004976 case KeyEvent.KEYCODE_VOICE_ASSIST: {
4977 // Only do this if we would otherwise not pass it to the user. In that case,
4978 // interceptKeyBeforeDispatching would apply a similar but different policy in
4979 // order to invoke voice assist actions. Note that we need to make a copy of the
4980 // key event here because the original key event will be recycled when we return.
4981 if ((result & ACTION_PASS_TO_USER) == 0 && !down) {
4982 mBroadcastWakeLock.acquire();
4983 Message msg = mHandler.obtainMessage(MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK,
4984 keyguardActive ? 1 : 0, 0);
4985 msg.setAsynchronous(true);
4986 msg.sendToTarget();
4987 }
4988 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004989 }
Jeff Brown26875502014-01-30 21:47:47 -08004990
Jeff Brownbae8e772014-06-12 19:59:45 -07004991 if (useHapticFeedback) {
4992 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
4993 }
4994
Jeff Brown26875502014-01-30 21:47:47 -08004995 if (isWakeKey) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004996 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey);
Jeff Brown26875502014-01-30 21:47:47 -08004997 }
Bryce Lee584a4452014-10-21 15:55:55 -07004998
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004999 return result;
5000 }
5001
Jeff Brown1c2e4942012-11-06 16:32:01 -08005002 /**
Jeff Brown13f00f02014-10-31 14:45:50 -07005003 * Returns true if the key can have global actions attached to it.
5004 * We reserve all power management keys for the system since they require
5005 * very careful handling.
5006 */
5007 private static boolean isValidGlobalKey(int keyCode) {
5008 switch (keyCode) {
5009 case KeyEvent.KEYCODE_POWER:
5010 case KeyEvent.KEYCODE_WAKEUP:
5011 case KeyEvent.KEYCODE_SLEEP:
5012 return false;
5013 default:
5014 return true;
5015 }
5016 }
5017
5018 /**
Jeff Brown1c2e4942012-11-06 16:32:01 -08005019 * When the screen is off we ignore some keys that might otherwise typically
5020 * be considered wake keys. We filter them out here.
5021 *
5022 * {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it
5023 * is always considered a wake key.
5024 */
5025 private boolean isWakeKeyWhenScreenOff(int keyCode) {
5026 switch (keyCode) {
5027 // ignore volume keys unless docked
5028 case KeyEvent.KEYCODE_VOLUME_UP:
5029 case KeyEvent.KEYCODE_VOLUME_DOWN:
5030 case KeyEvent.KEYCODE_VOLUME_MUTE:
5031 return mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED;
5032
5033 // ignore media and camera keys
5034 case KeyEvent.KEYCODE_MUTE:
5035 case KeyEvent.KEYCODE_HEADSETHOOK:
5036 case KeyEvent.KEYCODE_MEDIA_PLAY:
5037 case KeyEvent.KEYCODE_MEDIA_PAUSE:
5038 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
5039 case KeyEvent.KEYCODE_MEDIA_STOP:
5040 case KeyEvent.KEYCODE_MEDIA_NEXT:
5041 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
5042 case KeyEvent.KEYCODE_MEDIA_REWIND:
5043 case KeyEvent.KEYCODE_MEDIA_RECORD:
5044 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09005045 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK:
Jeff Brown1c2e4942012-11-06 16:32:01 -08005046 case KeyEvent.KEYCODE_CAMERA:
5047 return false;
5048 }
5049 return true;
5050 }
5051
5052
Jeff Brown56194eb2011-03-02 19:23:13 -08005053 /** {@inheritDoc} */
5054 @Override
Michael Wright70af00a2014-09-03 19:30:20 -07005055 public int interceptMotionBeforeQueueingNonInteractive(long whenNanos, int policyFlags) {
5056 if ((policyFlags & FLAG_WAKE) != 0) {
Bryce Lee5c138322014-11-03 08:26:09 -08005057 if (wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotion)) {
5058 return 0;
5059 }
Michael Wright70af00a2014-09-03 19:30:20 -07005060 }
Bryce Lee5c138322014-11-03 08:26:09 -08005061
Michael Wright70af00a2014-09-03 19:30:20 -07005062 if (shouldDispatchInputWhenNonInteractive()) {
5063 return ACTION_PASS_TO_USER;
5064 }
Bryce Lee5c138322014-11-03 08:26:09 -08005065
Bryce Lee812d7022014-11-10 13:33:28 -08005066 // If we have not passed the action up and we are in theater mode without dreaming,
5067 // there will be no dream to intercept the touch and wake into ambient. The device should
5068 // wake up in this case.
5069 if (isTheaterModeEnabled() && (policyFlags & FLAG_WAKE) != 0) {
5070 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotionWhenNotDreaming);
5071 }
5072
Jeff Brown037c33e2014-04-09 00:31:55 -07005073 return 0;
Jeff Brown56194eb2011-03-02 19:23:13 -08005074 }
5075
Michael Wright70af00a2014-09-03 19:30:20 -07005076 private boolean shouldDispatchInputWhenNonInteractive() {
Bryce Lee5c138322014-11-03 08:26:09 -08005077 // Send events to keyguard while the screen is on.
Jim Millerab954542014-10-10 18:21:49 -07005078 if (isKeyguardShowingAndNotOccluded() && mDisplay != null
5079 && mDisplay.getState() != Display.STATE_OFF) {
Bryce Lee5c138322014-11-03 08:26:09 -08005080 return true;
5081 }
5082
5083 // Send events to a dozing dream even if the screen is off since the dream
5084 // is in control of the state of the screen.
5085 IDreamManager dreamManager = getDreamManager();
5086
5087 try {
5088 if (dreamManager != null && dreamManager.isDreaming()) {
5089 return true;
5090 }
5091 } catch (RemoteException e) {
5092 Slog.e(TAG, "RemoteException when checking if dreaming", e);
5093 }
5094
5095 // Otherwise, consume events since the user can't see what is being
5096 // interacted with.
5097 return false;
Michael Wright70af00a2014-09-03 19:30:20 -07005098 }
5099
RoboErik001c59c2015-01-26 15:53:51 -08005100 private void dispatchDirectAudioEvent(KeyEvent event) {
5101 if (event.getAction() != KeyEvent.ACTION_DOWN) {
5102 return;
5103 }
5104 int keyCode = event.getKeyCode();
John Spurlockb94f2d62015-03-17 14:11:57 -04005105 int flags = AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_PLAY_SOUND
5106 | AudioManager.FLAG_FROM_KEY;
RoboErik001c59c2015-01-26 15:53:51 -08005107 String pkgName = mContext.getOpPackageName();
5108 switch (keyCode) {
5109 case KeyEvent.KEYCODE_VOLUME_UP:
5110 try {
John Spurlockee5ad722015-03-03 16:17:21 -05005111 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_RAISE,
John Spurlock90874332015-03-10 16:00:54 -04005112 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005113 } catch (RemoteException e) {
5114 Log.e(TAG, "Error dispatching volume up in dispatchTvAudioEvent.", e);
5115 }
5116 break;
5117 case KeyEvent.KEYCODE_VOLUME_DOWN:
5118 try {
John Spurlockee5ad722015-03-03 16:17:21 -05005119 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_LOWER,
John Spurlock90874332015-03-10 16:00:54 -04005120 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005121 } catch (RemoteException e) {
5122 Log.e(TAG, "Error dispatching volume down in dispatchTvAudioEvent.", e);
5123 }
5124 break;
5125 case KeyEvent.KEYCODE_VOLUME_MUTE:
5126 try {
5127 if (event.getRepeatCount() == 0) {
John Spurlockee5ad722015-03-03 16:17:21 -05005128 getAudioService().adjustSuggestedStreamVolume(
5129 AudioManager.ADJUST_TOGGLE_MUTE,
John Spurlock90874332015-03-10 16:00:54 -04005130 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005131 }
5132 } catch (RemoteException e) {
5133 Log.e(TAG, "Error dispatching mute in dispatchTvAudioEvent.", e);
5134 }
5135 break;
5136 }
5137 }
5138
Jeff Brown40013652012-05-16 21:22:36 -07005139 void dispatchMediaKeyWithWakeLock(KeyEvent event) {
5140 if (DEBUG_INPUT) {
5141 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: " + event);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005142 }
5143
Jeff Brown40013652012-05-16 21:22:36 -07005144 if (mHavePendingMediaKeyRepeatWithWakeLock) {
5145 if (DEBUG_INPUT) {
5146 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: canceled repeat");
5147 }
5148
5149 mHandler.removeMessages(MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK);
5150 mHavePendingMediaKeyRepeatWithWakeLock = false;
5151 mBroadcastWakeLock.release(); // pending repeat was holding onto the wake lock
5152 }
5153
5154 dispatchMediaKeyWithWakeLockToAudioService(event);
5155
5156 if (event.getAction() == KeyEvent.ACTION_DOWN
5157 && event.getRepeatCount() == 0) {
5158 mHavePendingMediaKeyRepeatWithWakeLock = true;
5159
5160 Message msg = mHandler.obtainMessage(
5161 MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK, event);
5162 msg.setAsynchronous(true);
5163 mHandler.sendMessageDelayed(msg, ViewConfiguration.getKeyRepeatTimeout());
5164 } else {
5165 mBroadcastWakeLock.release();
5166 }
5167 }
5168
5169 void dispatchMediaKeyRepeatWithWakeLock(KeyEvent event) {
5170 mHavePendingMediaKeyRepeatWithWakeLock = false;
5171
5172 KeyEvent repeatEvent = KeyEvent.changeTimeRepeat(event,
5173 SystemClock.uptimeMillis(), 1, event.getFlags() | KeyEvent.FLAG_LONG_PRESS);
5174 if (DEBUG_INPUT) {
5175 Slog.d(TAG, "dispatchMediaKeyRepeatWithWakeLock: " + repeatEvent);
5176 }
5177
5178 dispatchMediaKeyWithWakeLockToAudioService(repeatEvent);
5179 mBroadcastWakeLock.release();
5180 }
5181
5182 void dispatchMediaKeyWithWakeLockToAudioService(KeyEvent event) {
5183 if (ActivityManagerNative.isSystemReady()) {
RoboErik430fc482014-06-12 15:49:20 -07005184 MediaSessionLegacyHelper.getHelper(mContext).sendMediaButtonEvent(event, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005185 }
5186 }
5187
Michael Wright869a67c2014-08-26 19:33:06 -07005188 void launchVoiceAssistWithWakeLock(boolean keyguardActive) {
5189 Intent voiceIntent =
5190 new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
5191 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, keyguardActive);
Bart Sears8b1c27c2015-03-18 23:51:02 +00005192 startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
Michael Wright869a67c2014-08-26 19:33:06 -07005193 mBroadcastWakeLock.release();
5194 }
5195
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005196 BroadcastReceiver mDockReceiver = new BroadcastReceiver() {
Craig Mautnereee29c42013-01-17 14:44:34 -08005197 @Override
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005198 public void onReceive(Context context, Intent intent) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07005199 if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) {
5200 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
5201 Intent.EXTRA_DOCK_STATE_UNDOCKED);
Daniel Sandler6396c722013-04-16 20:19:09 -04005202 } else {
5203 try {
5204 IUiModeManager uiModeService = IUiModeManager.Stub.asInterface(
5205 ServiceManager.getService(Context.UI_MODE_SERVICE));
5206 mUiMode = uiModeService.getCurrentModeType();
5207 } catch (RemoteException e) {
5208 }
Dianne Hackborn80fa1662009-10-07 14:02:10 -07005209 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005210 updateRotation(true);
Craig Mautnereee29c42013-01-17 14:44:34 -08005211 synchronized (mLock) {
5212 updateOrientationListenerLp();
5213 }
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005214 }
5215 };
5216
Jeff Brown6aaf2952012-10-05 16:01:08 -07005217 BroadcastReceiver mDreamReceiver = new BroadcastReceiver() {
5218 @Override
5219 public void onReceive(Context context, Intent intent) {
5220 if (Intent.ACTION_DREAMING_STARTED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005221 if (mKeyguardDelegate != null) {
5222 mKeyguardDelegate.onDreamingStarted();
Jeff Brown6aaf2952012-10-05 16:01:08 -07005223 }
5224 } else if (Intent.ACTION_DREAMING_STOPPED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005225 if (mKeyguardDelegate != null) {
5226 mKeyguardDelegate.onDreamingStopped();
Jeff Brown6aaf2952012-10-05 16:01:08 -07005227 }
5228 }
5229 }
5230 };
5231
Christopher Tate5e08af02012-09-21 17:17:22 -07005232 BroadcastReceiver mMultiuserReceiver = new BroadcastReceiver() {
5233 @Override
5234 public void onReceive(Context context, Intent intent) {
5235 if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) {
5236 // tickle the settings observer: this first ensures that we're
5237 // observing the relevant settings for the newly-active user,
5238 // and then updates our own bookkeeping based on the now-
5239 // current user.
5240 mSettingsObserver.onChange(false);
John Spurlockce479d82012-11-29 09:52:21 -05005241
5242 // force a re-application of focused window sysui visibility.
5243 // the window may never have been shown for this user
5244 // e.g. the keyguard when going through the new-user setup flow
John Spurlock04db1762013-05-13 12:46:41 -04005245 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
John Spurlockce479d82012-11-29 09:52:21 -05005246 mLastSystemUiFlags = 0;
5247 updateSystemUiVisibilityLw();
5248 }
Christopher Tate5e08af02012-09-21 17:17:22 -07005249 }
5250 }
5251 };
5252
Adrian Roosddc8b272015-05-21 16:28:27 -07005253 private final Runnable mHiddenNavPanic = new Runnable() {
John Spurlockd9b70bd2014-02-06 17:02:44 -05005254 @Override
5255 public void run() {
Adrian Roosddc8b272015-05-21 16:28:27 -07005256 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
5257 if (!isUserSetupComplete()) {
5258 // Swipe-up for navigation bar is disabled during setup
5259 return;
5260 }
5261 mPendingPanicGestureUptime = SystemClock.uptimeMillis();
5262 mNavigationBarController.showTransient();
5263 }
John Spurlockd9b70bd2014-02-06 17:02:44 -05005264 }
5265 };
5266
John Spurlocke1f366f2013-08-05 12:22:40 -04005267 private void requestTransientBars(WindowState swipeTarget) {
John Spurlock04db1762013-05-13 12:46:41 -04005268 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Maurice Lam99c6e072014-04-28 18:24:28 -07005269 if (!isUserSetupComplete()) {
5270 // Swipe-up for navigation bar is disabled during setup
5271 return;
5272 }
John Spurlock27735a42013-08-14 17:57:38 -04005273 boolean sb = mStatusBarController.checkShowTransientBarLw();
5274 boolean nb = mNavigationBarController.checkShowTransientBarLw();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005275 if (sb || nb) {
Adrian Roos62b65e42015-02-25 18:05:34 +01005276 // Don't show status bar when swiping on already visible navigation bar
5277 if (!nb && swipeTarget == mNavigationBar) {
John Spurlocke1f366f2013-08-05 12:22:40 -04005278 if (DEBUG) Slog.d(TAG, "Not showing transient bar, wrong swipe target");
John Spurlockad3e6cb2013-04-30 08:47:43 -04005279 return;
5280 }
John Spurlock27735a42013-08-14 17:57:38 -04005281 if (sb) mStatusBarController.showTransient();
5282 if (nb) mNavigationBarController.showTransient();
John Spurlockf1a36642013-10-12 17:50:42 -04005283 mImmersiveModeConfirmation.confirmCurrentPrompt();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005284 updateSystemUiVisibilityLw();
John Spurlock32beb2c2013-03-11 10:16:47 -04005285 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04005286 }
5287 }
5288
Jeff Brown3ee549c2014-09-22 20:14:39 -07005289 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07005290 @Override
Jeff Brown416c49c2015-05-26 19:50:18 -07005291 public void startedGoingToSleep(int why) {
5292 if (DEBUG_WAKEUP) Slog.i(TAG, "Started going to sleep... (why=" + why + ")");
Jorim Jaggid175b6c2015-05-27 15:39:09 -07005293 if (mKeyguardDelegate != null) {
5294 mKeyguardDelegate.onStartedGoingToSleep(why);
5295 }
Jeff Brown416c49c2015-05-26 19:50:18 -07005296 }
5297
5298 // Called on the PowerManager's Notifier thread.
5299 @Override
5300 public void finishedGoingToSleep(int why) {
Dianne Hackborn74489012009-03-24 20:50:09 -07005301 EventLog.writeEvent(70000, 0);
Jeff Brown416c49c2015-05-26 19:50:18 -07005302 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished going to sleep... (why=" + why + ")");
Jeff Brown3ee549c2014-09-22 20:14:39 -07005303
5304 // We must get this work done here because the power manager will drop
5305 // the wake lock and let the system suspend once this function returns.
The Android Open Source Project0727d222009-03-11 12:11:58 -07005306 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005307 mAwake = false;
5308 mKeyguardDrawComplete = false;
Jeff Browna20dda42014-05-27 20:57:24 -07005309 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005310 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05005311 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005312 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005313 if (mKeyguardDelegate != null) {
Jorim Jaggid175b6c2015-05-27 15:39:09 -07005314 mKeyguardDelegate.onFinishedGoingToSleep(why);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005315 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005316 }
5317
Jeff Brown3ee549c2014-09-22 20:14:39 -07005318 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07005319 @Override
Jeff Brown416c49c2015-05-26 19:50:18 -07005320 public void startedWakingUp() {
Dianne Hackborn74489012009-03-24 20:50:09 -07005321 EventLog.writeEvent(70000, 1);
Jeff Brown416c49c2015-05-26 19:50:18 -07005322 if (DEBUG_WAKEUP) Slog.i(TAG, "Started waking up...");
Craig Mautner8a0da012014-05-31 15:13:37 -07005323
Jeff Brown3ee549c2014-09-22 20:14:39 -07005324 // Since goToSleep performs these functions synchronously, we must
5325 // do the same here. We cannot post this work to a handler because
5326 // that might cause it to become reordered with respect to what
5327 // may happen in a future call to goToSleep.
The Android Open Source Project0727d222009-03-11 12:11:58 -07005328 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005329 mAwake = true;
5330 mKeyguardDrawComplete = false;
5331 if (mKeyguardDelegate != null) {
5332 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
5333 mHandler.sendEmptyMessageDelayed(MSG_KEYGUARD_DRAWN_TIMEOUT, 1000);
5334 }
5335
Jeff Browna20dda42014-05-27 20:57:24 -07005336 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005337 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05005338 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005339 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005340
Jim Miller5ecd8112013-01-09 18:50:26 -08005341 if (mKeyguardDelegate != null) {
Jorim Jaggid175b6c2015-05-27 15:39:09 -07005342 mKeyguardDelegate.onStartedWakingUp(mKeyguardDelegateCallback);
Jeff Brown36c4db82014-09-19 12:05:31 -07005343 // ... eventually calls finishKeyguardDrawn
Jeff Brownc38c9be2012-10-04 13:16:19 -07005344 } else {
Craig Mautner8a0da012014-05-31 15:13:37 -07005345 if (DEBUG_WAKEUP) Slog.d(TAG, "null mKeyguardDelegate: setting mKeyguardDrawComplete.");
Jeff Brown36c4db82014-09-19 12:05:31 -07005346 finishKeyguardDrawn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07005347 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005348 }
5349
Jeff Brown416c49c2015-05-26 19:50:18 -07005350 // Called on the PowerManager's Notifier thread.
5351 @Override
5352 public void finishedWakingUp() {
5353 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished waking up...");
5354 }
5355
5356 private void wakeUpFromPowerKey(long eventTime) {
5357 wakeUp(eventTime, mAllowTheaterModeWakeFromPowerKey);
5358 }
5359
5360 private boolean wakeUp(long wakeTime, boolean wakeInTheaterMode) {
5361 if (!wakeInTheaterMode && isTheaterModeEnabled()) {
5362 return false;
5363 }
5364
5365 mPowerManager.wakeUp(wakeTime);
5366 return true;
5367 }
5368
Jeff Brown36c4db82014-09-19 12:05:31 -07005369 private void finishKeyguardDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005370 synchronized (mLock) {
5371 if (!mAwake || mKeyguardDrawComplete) {
5372 return; // spurious
5373 }
5374
Jeff Brown36c4db82014-09-19 12:05:31 -07005375 mKeyguardDrawComplete = true;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005376 if (mKeyguardDelegate != null) {
5377 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
5378 }
5379 }
5380
5381 finishScreenTurningOn();
5382 }
5383
5384 // Called on the DisplayManager's DisplayPowerController thread.
5385 @Override
5386 public void screenTurnedOff() {
5387 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turned off...");
5388
Jeff Brown48d1b142015-06-10 16:36:03 -07005389 updateScreenOffSleepToken(true);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005390 synchronized (mLock) {
5391 mScreenOnEarly = false;
5392 mScreenOnFully = false;
5393 mWindowManagerDrawComplete = false;
5394 mScreenOnListener = null;
5395 updateOrientationListenerLp();
Jeff Brown36c4db82014-09-19 12:05:31 -07005396 }
5397 }
5398
Jeff Brown3ee549c2014-09-22 20:14:39 -07005399 // Called on the DisplayManager's DisplayPowerController thread.
Jeff Brown36c4db82014-09-19 12:05:31 -07005400 @Override
5401 public void screenTurningOn(final ScreenOnListener screenOnListener) {
Jeff Brown36c4db82014-09-19 12:05:31 -07005402 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turning on...");
Jeff Brown36c4db82014-09-19 12:05:31 -07005403
Jeff Brown48d1b142015-06-10 16:36:03 -07005404 updateScreenOffSleepToken(false);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005405 synchronized (mLock) {
5406 mScreenOnEarly = true;
5407 mScreenOnFully = false;
5408 mWindowManagerDrawComplete = false;
5409 mScreenOnListener = screenOnListener;
5410 updateOrientationListenerLp();
5411 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005412
Craig Mautnerc3daedd2014-09-13 11:17:23 -07005413 mWindowManagerInternal.waitForAllWindowsDrawn(mWindowManagerDrawCallback,
5414 WAITING_FOR_DRAWN_TIMEOUT);
Jeff Brown36c4db82014-09-19 12:05:31 -07005415 // ... eventually calls finishWindowsDrawn
5416 }
5417
Jeff Brown36c4db82014-09-19 12:05:31 -07005418 private void finishWindowsDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005419 synchronized (mLock) {
5420 if (!mScreenOnEarly || mWindowManagerDrawComplete) {
5421 return; // spurious
5422 }
5423
Jeff Brown36c4db82014-09-19 12:05:31 -07005424 mWindowManagerDrawComplete = true;
Jeff Brown36c4db82014-09-19 12:05:31 -07005425 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005426
5427 finishScreenTurningOn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07005428 }
5429
Craig Mautner8a0da012014-05-31 15:13:37 -07005430 private void finishScreenTurningOn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005431 final ScreenOnListener listener;
5432 final boolean enableScreen;
Jeff Brown36c4db82014-09-19 12:05:31 -07005433 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005434 if (DEBUG_WAKEUP) Slog.d(TAG,
5435 "finishScreenTurningOn: mAwake=" + mAwake
5436 + ", mScreenOnEarly=" + mScreenOnEarly
5437 + ", mScreenOnFully=" + mScreenOnFully
5438 + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete
5439 + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete);
5440
5441 if (mScreenOnFully || !mScreenOnEarly || !mWindowManagerDrawComplete
5442 || (mAwake && !mKeyguardDrawComplete)) {
5443 return; // spurious or not ready yet
Jeff Brown36c4db82014-09-19 12:05:31 -07005444 }
5445
Jeff Brown3ee549c2014-09-22 20:14:39 -07005446 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished screen turning on...");
5447 listener = mScreenOnListener;
Craig Mautner13f6ea72014-06-23 14:57:02 -07005448 mScreenOnListener = null;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005449 mScreenOnFully = true;
5450
5451 // Remember the first time we draw the keyguard so we know when we're done with
5452 // the main part of booting and can enable the screen and hide boot messages.
5453 if (!mKeyguardDrawnOnce && mAwake) {
5454 mKeyguardDrawnOnce = true;
5455 enableScreen = true;
5456 if (mBootMessageNeedsHiding) {
5457 mBootMessageNeedsHiding = false;
5458 hideBootMessages();
5459 }
5460 } else {
5461 enableScreen = false;
5462 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005463 }
5464
Jeff Brown3ee549c2014-09-22 20:14:39 -07005465 if (listener != null) {
5466 listener.onScreenOn();
5467 }
Jeff Brown4fc45272012-10-10 18:28:14 -07005468
Jeff Brown3ee549c2014-09-22 20:14:39 -07005469 if (enableScreen) {
5470 try {
5471 mWindowManager.enableScreenIfNeeded();
5472 } catch (RemoteException unhandled) {
Jeff Brown36c4db82014-09-19 12:05:31 -07005473 }
Craig Mautnera631d492014-08-05 15:16:01 -07005474 }
5475 }
5476
5477 private void handleHideBootMessage() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005478 synchronized (mLock) {
5479 if (!mKeyguardDrawnOnce) {
5480 mBootMessageNeedsHiding = true;
5481 return; // keyguard hasn't drawn the first time yet, not done booting
5482 }
Craig Mautnera631d492014-08-05 15:16:01 -07005483 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005484
5485 if (mBootMsgDialog != null) {
5486 if (DEBUG_WAKEUP) Slog.d(TAG, "handleHideBootMessage: dismissing");
5487 mBootMsgDialog.dismiss();
5488 mBootMsgDialog = null;
Craig Mautnera631d492014-08-05 15:16:01 -07005489 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005490 }
5491
5492 @Override
Jeff Brown3ee549c2014-09-22 20:14:39 -07005493 public boolean isScreenOn() {
5494 return mScreenOnFully;
Dianne Hackborn08743722009-12-21 12:16:51 -08005495 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005496
Dianne Hackborn08743722009-12-21 12:16:51 -08005497 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005498 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005499 public void enableKeyguard(boolean enabled) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005500 if (mKeyguardDelegate != null) {
5501 mKeyguardDelegate.setKeyguardEnabled(enabled);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005502 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005503 }
5504
5505 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005506 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005507 public void exitKeyguardSecurely(OnKeyguardExitResult callback) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005508 if (mKeyguardDelegate != null) {
5509 mKeyguardDelegate.verifyUnlock(callback);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005510 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005511 }
5512
Jim Millerab954542014-10-10 18:21:49 -07005513 private boolean isKeyguardShowingAndNotOccluded() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005514 if (mKeyguardDelegate == null) return false;
Jim Millerab954542014-10-10 18:21:49 -07005515 return mKeyguardDelegate.isShowing() && !mKeyguardOccluded;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005516 }
5517
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005518 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005519 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005520 public boolean isKeyguardLocked() {
5521 return keyguardOn();
5522 }
5523
5524 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005525 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005526 public boolean isKeyguardSecure() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005527 if (mKeyguardDelegate == null) return false;
5528 return mKeyguardDelegate.isSecure();
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005529 }
5530
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005531 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005532 @Override
Adrian Roos461829d2015-06-03 14:41:18 -07005533 public boolean isKeyguardShowingOrOccluded() {
5534 return mKeyguardDelegate == null ? false : mKeyguardDelegate.isShowing();
5535 }
5536
5537 /** {@inheritDoc} */
5538 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005539 public boolean inKeyguardRestrictedKeyInputMode() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005540 if (mKeyguardDelegate == null) return false;
5541 return mKeyguardDelegate.isInputRestricted();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005542 }
5543
Jose Lima9546b202014-07-02 17:21:51 -07005544 @Override
Dianne Hackborn90c52de2011-09-23 12:57:44 -07005545 public void dismissKeyguardLw() {
RoboErik8a2cfc32014-05-16 11:19:38 -07005546 if (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()) {
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07005547 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.dismissKeyguardLw");
Daniel Sandler1ce804392012-11-07 15:07:12 -05005548 mHandler.post(new Runnable() {
Jose Lima9546b202014-07-02 17:21:51 -07005549 @Override
Daniel Sandler1ce804392012-11-07 15:07:12 -05005550 public void run() {
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02005551 // ask the keyguard to prompt the user to authenticate if necessary
5552 mKeyguardDelegate.dismiss();
5553 }
5554 });
5555 }
5556 }
5557
5558 public void notifyActivityDrawnForKeyguardLw() {
5559 if (mKeyguardDelegate != null) {
5560 mHandler.post(new Runnable() {
5561 @Override
5562 public void run() {
5563 mKeyguardDelegate.onActivityDrawn();
Daniel Sandler1ce804392012-11-07 15:07:12 -05005564 }
5565 });
Dianne Hackborn90c52de2011-09-23 12:57:44 -07005566 }
5567 }
5568
Jorim Jaggicff0acb2014-03-31 16:35:15 +02005569 @Override
5570 public boolean isKeyguardDrawnLw() {
5571 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005572 return mKeyguardDrawnOnce;
Jorim Jaggicff0acb2014-03-31 16:35:15 +02005573 }
5574 }
5575
Jorim Jaggi0d674622014-05-21 01:34:15 +02005576 @Override
Jorim Jaggie29b2db2014-05-30 23:17:03 +02005577 public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) {
Jorim Jaggi0d674622014-05-21 01:34:15 +02005578 if (mKeyguardDelegate != null) {
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07005579 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.startKeyguardExitAnimation");
Jorim Jaggie29b2db2014-05-30 23:17:03 +02005580 mKeyguardDelegate.startKeyguardExitAnimation(startTime, fadeoutDuration);
Jorim Jaggi0d674622014-05-21 01:34:15 +02005581 }
5582 }
5583
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005584 void sendCloseSystemWindows() {
Jorim Jaggib10e33f2015-02-04 21:57:40 +01005585 PhoneWindow.sendCloseSystemWindows(mContext, null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005586 }
5587
5588 void sendCloseSystemWindows(String reason) {
Jorim Jaggib10e33f2015-02-04 21:57:40 +01005589 PhoneWindow.sendCloseSystemWindows(mContext, reason);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005590 }
Mitsuru Oshima831d0d92009-06-16 18:27:18 -07005591
Jeff Brown01a98dd2011-09-20 15:08:29 -07005592 @Override
5593 public int rotationForOrientationLw(int orientation, int lastRotation) {
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005594 if (false) {
5595 Slog.v(TAG, "rotationForOrientationLw(orient="
5596 + orientation + ", last=" + lastRotation
5597 + "); user=" + mUserRotation + " "
5598 + ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED)
5599 ? "USER_ROTATION_LOCKED" : "")
5600 );
5601 }
5602
Craig Mautner46ac6fa2013-08-01 10:06:34 -07005603 if (mForceDefaultOrientation) {
5604 return Surface.ROTATION_0;
5605 }
5606
The Android Open Source Project0727d222009-03-11 12:11:58 -07005607 synchronized (mLock) {
Jeff Brownc0347aa2011-09-23 17:26:09 -07005608 int sensorRotation = mOrientationListener.getProposedRotation(); // may be -1
5609 if (sensorRotation < 0) {
Jeff Brown0f862b42012-09-27 21:11:01 -07005610 sensorRotation = lastRotation;
Jeff Brownc0347aa2011-09-23 17:26:09 -07005611 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005612
Jeff Browndec6cf42011-11-15 14:08:20 -08005613 final int preferredRotation;
Jeff Brown2e7760e2012-04-11 15:14:55 -07005614 if (mLidState == LID_OPEN && mLidOpenRotation >= 0) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005615 // Ignore sensor when lid switch is open and rotation is forced.
5616 preferredRotation = mLidOpenRotation;
5617 } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR
Jeff Brownc0347aa2011-09-23 17:26:09 -07005618 && (mCarDockEnablesAccelerometer || mCarDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005619 // Ignore sensor when in car dock unless explicitly enabled.
5620 // This case can override the behavior of NOSENSOR, and can also
5621 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07005622 preferredRotation = mCarDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07005623 ? sensorRotation : mCarDockRotation;
Jeff Brown1a693182011-11-08 14:44:16 -08005624 } else if ((mDockMode == Intent.EXTRA_DOCK_STATE_DESK
5625 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
5626 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK)
Jeff Brownc0347aa2011-09-23 17:26:09 -07005627 && (mDeskDockEnablesAccelerometer || mDeskDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005628 // Ignore sensor when in desk dock unless explicitly enabled.
5629 // This case can override the behavior of NOSENSOR, and can also
5630 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07005631 preferredRotation = mDeskDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07005632 ? sensorRotation : mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -07005633 } else if (mHdmiPlugged && mDemoHdmiRotationLock) {
5634 // Ignore sensor when plugged into HDMI when demo HDMI rotation lock enabled.
Jeff Browneb3e4b92011-12-06 19:54:24 -08005635 // Note that the dock orientation overrides the HDMI orientation.
Jeff Brownc82c89ed2013-04-17 17:18:15 -07005636 preferredRotation = mDemoHdmiRotation;
5637 } else if (mHdmiPlugged && mDockMode == Intent.EXTRA_DOCK_STATE_UNDOCKED
5638 && mUndockedHdmiRotation >= 0) {
5639 // Ignore sensor when plugged into HDMI and an undocked orientation has
5640 // been specified in the configuration (only for legacy devices without
5641 // full multi-display support).
5642 // Note that the dock orientation overrides the HDMI orientation.
5643 preferredRotation = mUndockedHdmiRotation;
Chong Zhangae6119ff2014-11-11 18:54:39 -08005644 } else if (mDemoRotationLock) {
5645 // Ignore sensor when demo rotation lock is enabled.
5646 // Note that the dock orientation and HDMI rotation lock override this.
5647 preferredRotation = mDemoRotation;
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005648 } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED) {
5649 // Application just wants to remain locked in the last rotation.
5650 preferredRotation = lastRotation;
Jeff Brownbcdfc622014-03-06 19:13:04 -08005651 } else if (!mSupportAutoRotation) {
5652 // If we don't support auto-rotation then bail out here and ignore
5653 // the sensor and any rotation lock settings.
5654 preferredRotation = -1;
Jeff Brown207673cd2012-06-05 17:47:11 -07005655 } else if ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE
Jeff Brown01a98dd2011-09-20 15:08:29 -07005656 && (orientation == ActivityInfo.SCREEN_ORIENTATION_USER
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005657 || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
5658 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
5659 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
5660 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER))
Jeff Brown01a98dd2011-09-20 15:08:29 -07005661 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
5662 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
5663 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
5664 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) {
5665 // Otherwise, use sensor only if requested by the application or enabled
5666 // by default for USER or UNSPECIFIED modes. Does not apply to NOSENSOR.
Jeff Brownd3187e32011-09-21 19:26:44 -07005667 if (mAllowAllRotations < 0) {
5668 // Can't read this during init() because the context doesn't
5669 // have display metrics at that time so we cannot determine
5670 // tablet vs. phone then.
5671 mAllowAllRotations = mContext.getResources().getBoolean(
5672 com.android.internal.R.bool.config_allowAllRotations) ? 1 : 0;
5673 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005674 if (sensorRotation != Surface.ROTATION_180
Jeff Brownd3187e32011-09-21 19:26:44 -07005675 || mAllowAllRotations == 1
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005676 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
5677 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005678 preferredRotation = sensorRotation;
5679 } else {
5680 preferredRotation = lastRotation;
5681 }
Jeff Brown207673cd2012-06-05 17:47:11 -07005682 } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED
5683 && orientation != ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) {
5684 // Apply rotation lock. Does not apply to NOSENSOR.
5685 // The idea is that the user rotation expresses a weak preference for the direction
5686 // of gravity and as NOSENSOR is never affected by gravity, then neither should
5687 // NOSENSOR be affected by rotation lock (although it will be affected by docks).
Jeff Brown4dfce202011-10-05 12:00:10 -07005688 preferredRotation = mUserRotation;
Jeff Browndec6cf42011-11-15 14:08:20 -08005689 } else {
5690 // No overriding preference.
5691 // We will do exactly what the application asked us to do.
5692 preferredRotation = -1;
Jeff Brown01a98dd2011-09-20 15:08:29 -07005693 }
5694
Dianne Hackborne5439f22010-10-02 16:53:50 -07005695 switch (orientation) {
5696 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08005697 // Return portrait unless overridden.
5698 if (isAnyPortrait(preferredRotation)) {
5699 return preferredRotation;
5700 }
Dianne Hackborne5439f22010-10-02 16:53:50 -07005701 return mPortraitRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005702
Jeff Brown01a98dd2011-09-20 15:08:29 -07005703 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08005704 // Return landscape unless overridden.
5705 if (isLandscapeOrSeascape(preferredRotation)) {
5706 return preferredRotation;
5707 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005708 return mLandscapeRotation;
5709
5710 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08005711 // Return reverse portrait unless overridden.
5712 if (isAnyPortrait(preferredRotation)) {
5713 return preferredRotation;
5714 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005715 return mUpsideDownRotation;
5716
5717 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08005718 // Return seascape unless overridden.
5719 if (isLandscapeOrSeascape(preferredRotation)) {
5720 return preferredRotation;
5721 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005722 return mSeascapeRotation;
5723
5724 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005725 case ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE:
Jeff Brown01a98dd2011-09-20 15:08:29 -07005726 // Return either landscape rotation.
5727 if (isLandscapeOrSeascape(preferredRotation)) {
5728 return preferredRotation;
5729 }
5730 if (isLandscapeOrSeascape(lastRotation)) {
Jeff Brown4519f072011-01-23 13:16:01 -08005731 return lastRotation;
5732 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005733 return mLandscapeRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005734
Jeff Brown01a98dd2011-09-20 15:08:29 -07005735 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005736 case ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT:
Jeff Brown01a98dd2011-09-20 15:08:29 -07005737 // Return either portrait rotation.
5738 if (isAnyPortrait(preferredRotation)) {
5739 return preferredRotation;
5740 }
5741 if (isAnyPortrait(lastRotation)) {
5742 return lastRotation;
5743 }
5744 return mPortraitRotation;
5745
5746 default:
Jeff Brown4dfce202011-10-05 12:00:10 -07005747 // For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR,
5748 // just return the preferred orientation we already calculated.
Jeff Brown01a98dd2011-09-20 15:08:29 -07005749 if (preferredRotation >= 0) {
5750 return preferredRotation;
5751 }
Dianne Hackborndacea8c2011-04-21 17:26:39 -07005752 return Surface.ROTATION_0;
Daniel Sandlere7e5ac22011-02-22 16:10:21 -05005753 }
5754 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07005755 }
5756
Jeff Brown01a98dd2011-09-20 15:08:29 -07005757 @Override
5758 public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation) {
5759 switch (orientation) {
5760 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
5761 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
5762 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
5763 return isAnyPortrait(rotation);
5764
5765 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
5766 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
5767 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
5768 return isLandscapeOrSeascape(rotation);
5769
5770 default:
5771 return true;
5772 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07005773 }
5774
Jeff Brownc0347aa2011-09-23 17:26:09 -07005775 @Override
5776 public void setRotationLw(int rotation) {
5777 mOrientationListener.setCurrentRotation(rotation);
5778 }
5779
Jeff Brown01a98dd2011-09-20 15:08:29 -07005780 private boolean isLandscapeOrSeascape(int rotation) {
5781 return rotation == mLandscapeRotation || rotation == mSeascapeRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005782 }
5783
Jeff Brown01a98dd2011-09-20 15:08:29 -07005784 private boolean isAnyPortrait(int rotation) {
5785 return rotation == mPortraitRotation || rotation == mUpsideDownRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005786 }
5787
Jose Lima9546b202014-07-02 17:21:51 -07005788 @Override
Svetoslav Ganov80943d82013-01-02 10:25:37 -08005789 public int getUserRotationMode() {
5790 return Settings.System.getIntForUser(mContext.getContentResolver(),
Brett Chabot7e55c402013-05-16 19:38:08 -07005791 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
5792 WindowManagerPolicy.USER_ROTATION_FREE :
5793 WindowManagerPolicy.USER_ROTATION_LOCKED;
Svetoslav Ganov80943d82013-01-02 10:25:37 -08005794 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005795
5796 // User rotation: to be used when all else fails in assigning an orientation to the device
Jose Lima9546b202014-07-02 17:21:51 -07005797 @Override
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005798 public void setUserRotationMode(int mode, int rot) {
5799 ContentResolver res = mContext.getContentResolver();
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005800
5801 // mUserRotationMode and mUserRotation will be assigned by the content observer
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005802 if (mode == WindowManagerPolicy.USER_ROTATION_LOCKED) {
Christopher Tate5e08af02012-09-21 17:17:22 -07005803 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005804 Settings.System.USER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005805 rot,
5806 UserHandle.USER_CURRENT);
5807 Settings.System.putIntForUser(res,
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005808 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005809 0,
5810 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005811 } else {
Christopher Tate5e08af02012-09-21 17:17:22 -07005812 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005813 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005814 1,
5815 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005816 }
5817 }
5818
Jose Lima9546b202014-07-02 17:21:51 -07005819 @Override
Jeff Brownac143512012-04-05 18:57:33 -07005820 public void setSafeMode(boolean safeMode) {
5821 mSafeMode = safeMode;
5822 performHapticFeedbackLw(null, safeMode
5823 ? HapticFeedbackConstants.SAFE_MODE_ENABLED
5824 : HapticFeedbackConstants.SAFE_MODE_DISABLED, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005825 }
Craig Mautnereda67292013-04-28 13:50:14 -07005826
Dianne Hackborn181ceb52009-08-27 22:16:40 -07005827 static long[] getLongIntArray(Resources r, int resid) {
5828 int[] ar = r.getIntArray(resid);
5829 if (ar == null) {
5830 return null;
5831 }
5832 long[] out = new long[ar.length];
5833 for (int i=0; i<ar.length; i++) {
5834 out[i] = ar[i];
5835 }
5836 return out;
5837 }
Craig Mautnereda67292013-04-28 13:50:14 -07005838
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005839 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07005840 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005841 public void systemReady() {
Jim Millerab954542014-10-10 18:21:49 -07005842 mKeyguardDelegate = new KeyguardServiceDelegate(mContext);
Mike Lockwooded8902d2013-11-15 11:01:47 -08005843 mKeyguardDelegate.onSystemReady();
5844
Michael Wright3818c922014-09-02 13:59:07 -07005845 readCameraLensCoverState();
Jeff Brown4f5fa282014-06-12 19:19:15 -07005846 updateUiMode();
Dianne Hackbornb1a79802009-09-29 15:18:31 -07005847 synchronized (mLock) {
5848 updateOrientationListenerLp();
Dianne Hackbornc777e072010-02-12 13:07:59 -08005849 mSystemReady = true;
5850 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07005851 @Override
Dianne Hackbornc777e072010-02-12 13:07:59 -08005852 public void run() {
5853 updateSettings();
5854 }
5855 });
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005856 }
5857 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07005858
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005859 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005860 @Override
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005861 public void systemBooted() {
Jim Millere5f910a2013-10-16 18:15:46 -07005862 if (mKeyguardDelegate != null) {
Jason Monk5eeebf52014-09-26 12:36:51 -04005863 mKeyguardDelegate.bindService(mContext);
Jim Millere5f910a2013-10-16 18:15:46 -07005864 mKeyguardDelegate.onBootCompleted();
5865 }
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005866 synchronized (mLock) {
5867 mSystemBooted = true;
5868 }
Jeff Brown416c49c2015-05-26 19:50:18 -07005869 startedWakingUp();
Jeff Brown36c4db82014-09-19 12:05:31 -07005870 screenTurningOn(null);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005871 }
5872
Dianne Hackborn661cd522011-08-22 00:26:20 -07005873 ProgressDialog mBootMsgDialog = null;
5874
5875 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005876 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07005877 public void showBootMessage(final CharSequence msg, final boolean always) {
5878 mHandler.post(new Runnable() {
5879 @Override public void run() {
5880 if (mBootMsgDialog == null) {
Craig Stout4c0cb8a2014-04-04 13:03:10 -07005881 int theme;
5882 if (mContext.getPackageManager().hasSystemFeature(
5883 PackageManager.FEATURE_WATCH)) {
5884 theme = com.android.internal.R.style.Theme_Micro_Dialog_Alert;
5885 } else if (mContext.getPackageManager().hasSystemFeature(
5886 PackageManager.FEATURE_TELEVISION)) {
5887 theme = com.android.internal.R.style.Theme_Leanback_Dialog_Alert;
5888 } else {
5889 theme = 0;
5890 }
Vinod Krishnanfa8fc412014-04-18 14:35:53 -07005891
5892 mBootMsgDialog = new ProgressDialog(mContext, theme) {
Dianne Hackborn295e3c22011-08-25 13:19:08 -07005893 // This dialog will consume all events coming in to
5894 // it, to avoid it trying to do things too early in boot.
5895 @Override public boolean dispatchKeyEvent(KeyEvent event) {
5896 return true;
5897 }
5898 @Override public boolean dispatchKeyShortcutEvent(KeyEvent event) {
5899 return true;
5900 }
5901 @Override public boolean dispatchTouchEvent(MotionEvent ev) {
5902 return true;
5903 }
5904 @Override public boolean dispatchTrackballEvent(MotionEvent ev) {
5905 return true;
5906 }
5907 @Override public boolean dispatchGenericMotionEvent(MotionEvent ev) {
5908 return true;
5909 }
5910 @Override public boolean dispatchPopulateAccessibilityEvent(
5911 AccessibilityEvent event) {
5912 return true;
5913 }
5914 };
Jeff Hao9f60c082014-10-28 18:51:07 -07005915 if (mContext.getPackageManager().isUpgrade()) {
5916 mBootMsgDialog.setTitle(R.string.android_upgrading_title);
5917 } else {
5918 mBootMsgDialog.setTitle(R.string.android_start_title);
5919 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07005920 mBootMsgDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
5921 mBootMsgDialog.setIndeterminate(true);
5922 mBootMsgDialog.getWindow().setType(
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07005923 WindowManager.LayoutParams.TYPE_BOOT_PROGRESS);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005924 mBootMsgDialog.getWindow().addFlags(
5925 WindowManager.LayoutParams.FLAG_DIM_BEHIND
5926 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
5927 mBootMsgDialog.getWindow().setDimAmount(1);
Dianne Hackbornd9efb952011-12-07 14:56:51 -08005928 WindowManager.LayoutParams lp = mBootMsgDialog.getWindow().getAttributes();
5929 lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
5930 mBootMsgDialog.getWindow().setAttributes(lp);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005931 mBootMsgDialog.setCancelable(false);
5932 mBootMsgDialog.show();
5933 }
5934 mBootMsgDialog.setMessage(msg);
5935 }
5936 });
5937 }
5938
5939 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005940 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07005941 public void hideBootMessages() {
Craig Mautnera631d492014-08-05 15:16:01 -07005942 mHandler.sendEmptyMessage(MSG_HIDE_BOOT_MESSAGE);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005943 }
5944
Mike Lockwood28569302010-01-28 11:54:40 -05005945 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005946 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05005947 public void userActivity() {
Dianne Hackborndf89e652011-10-06 22:35:11 -07005948 // ***************************************
5949 // NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
5950 // ***************************************
5951 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
5952 // WITH ITS LOCKS HELD.
5953 //
5954 // This code must be VERY careful about the locks
5955 // it acquires.
5956 // In fact, the current code acquires way too many,
5957 // and probably has lurking deadlocks.
5958
Mike Lockwood28569302010-01-28 11:54:40 -05005959 synchronized (mScreenLockTimeout) {
5960 if (mLockScreenTimerActive) {
5961 // reset the timer
5962 mHandler.removeCallbacks(mScreenLockTimeout);
5963 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
5964 }
5965 }
Daniel Sandler0601eb72011-04-13 01:01:32 -04005966 }
5967
Adam Cohenf7522022012-10-03 20:03:18 -07005968 class ScreenLockTimeout implements Runnable {
5969 Bundle options;
5970
5971 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05005972 public void run() {
5973 synchronized (this) {
5974 if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard");
Jim Miller5ecd8112013-01-09 18:50:26 -08005975 if (mKeyguardDelegate != null) {
5976 mKeyguardDelegate.doKeyguardTimeout(options);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005977 }
Mike Lockwood28569302010-01-28 11:54:40 -05005978 mLockScreenTimerActive = false;
Adam Cohenf7522022012-10-03 20:03:18 -07005979 options = null;
Mike Lockwood28569302010-01-28 11:54:40 -05005980 }
5981 }
Mike Lockwood28569302010-01-28 11:54:40 -05005982
Adam Cohenf7522022012-10-03 20:03:18 -07005983 public void setLockOptions(Bundle options) {
5984 this.options = options;
5985 }
5986 }
5987
5988 ScreenLockTimeout mScreenLockTimeout = new ScreenLockTimeout();
5989
Jose Lima9546b202014-07-02 17:21:51 -07005990 @Override
Adam Cohenf7522022012-10-03 20:03:18 -07005991 public void lockNow(Bundle options) {
Jim Miller93c518e2012-01-17 15:55:31 -08005992 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null);
5993 mHandler.removeCallbacks(mScreenLockTimeout);
Adam Cohenf7522022012-10-03 20:03:18 -07005994 if (options != null) {
5995 // In case multiple calls are made to lockNow, we don't wipe out the options
5996 // until the runnable actually executes.
5997 mScreenLockTimeout.setLockOptions(options);
5998 }
Jim Miller93c518e2012-01-17 15:55:31 -08005999 mHandler.post(mScreenLockTimeout);
6000 }
6001
Mike Lockwood28569302010-01-28 11:54:40 -05006002 private void updateLockScreenTimeout() {
6003 synchronized (mScreenLockTimeout) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07006004 boolean enable = (mAllowLockscreenWhenOn && mAwake &&
Jim Miller5ecd8112013-01-09 18:50:26 -08006005 mKeyguardDelegate != null && mKeyguardDelegate.isSecure());
Mike Lockwood28569302010-01-28 11:54:40 -05006006 if (mLockScreenTimerActive != enable) {
6007 if (enable) {
6008 if (localLOGV) Log.v(TAG, "setting lockscreen timer");
6009 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
6010 } else {
6011 if (localLOGV) Log.v(TAG, "clearing lockscreen timer");
6012 mHandler.removeCallbacks(mScreenLockTimeout);
6013 }
6014 mLockScreenTimerActive = enable;
6015 }
6016 }
6017 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006018
Jeff Brown061ea992015-04-17 19:55:47 -07006019 private void updateDreamingSleepToken(boolean acquire) {
6020 if (acquire) {
6021 if (mDreamingSleepToken == null) {
6022 mDreamingSleepToken = mActivityManagerInternal.acquireSleepToken("Dream");
6023 }
6024 } else {
6025 if (mDreamingSleepToken != null) {
6026 mDreamingSleepToken.release();
Jeff Brown48d1b142015-06-10 16:36:03 -07006027 mDreamingSleepToken = null;
6028 }
6029 }
6030 }
6031
6032 private void updateScreenOffSleepToken(boolean acquire) {
6033 if (acquire) {
6034 if (mScreenOffSleepToken == null) {
6035 mScreenOffSleepToken = mActivityManagerInternal.acquireSleepToken("ScreenOff");
6036 }
6037 } else {
6038 if (mScreenOffSleepToken != null) {
6039 mScreenOffSleepToken.release();
6040 mScreenOffSleepToken = null;
Jeff Brown061ea992015-04-17 19:55:47 -07006041 }
6042 }
6043 }
6044
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006045 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07006046 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006047 public void enableScreenAfterBoot() {
6048 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07006049 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07006050 updateRotation(true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006051 }
Dianne Hackbornf54c8f92009-09-19 14:03:57 -07006052
Jeff Brownc458ce92012-04-30 14:58:40 -07006053 private void applyLidSwitchState() {
Jeff Brownc458ce92012-04-30 14:58:40 -07006054 if (mLidState == LID_CLOSED && mLidControlsSleep) {
Jeff Brown6d8fd272014-05-20 21:24:38 -07006055 mPowerManager.goToSleep(SystemClock.uptimeMillis(),
Jeff Brownc12035c2014-08-13 18:52:25 -07006056 PowerManager.GO_TO_SLEEP_REASON_LID_SWITCH,
Jeff Brown6d8fd272014-05-20 21:24:38 -07006057 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
Jeff Brownc458ce92012-04-30 14:58:40 -07006058 }
Jeff Browna20dda42014-05-27 20:57:24 -07006059
6060 synchronized (mLock) {
6061 updateWakeGestureListenerLp();
6062 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006063 }
6064
Jeff Brown4f5fa282014-06-12 19:19:15 -07006065 void updateUiMode() {
6066 if (mUiModeManager == null) {
6067 mUiModeManager = IUiModeManager.Stub.asInterface(
6068 ServiceManager.getService(Context.UI_MODE_SERVICE));
6069 }
6070 try {
6071 mUiMode = mUiModeManager.getCurrentModeType();
6072 } catch (RemoteException e) {
6073 }
6074 }
6075
Jeff Brown01a98dd2011-09-20 15:08:29 -07006076 void updateRotation(boolean alwaysSendConfiguration) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006077 try {
6078 //set orientation on WindowManager
Dianne Hackbornf87d1962012-04-04 12:48:24 -07006079 mWindowManager.updateRotation(alwaysSendConfiguration, false);
6080 } catch (RemoteException e) {
6081 // Ignore
6082 }
6083 }
6084
6085 void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) {
6086 try {
6087 //set orientation on WindowManager
6088 mWindowManager.updateRotation(alwaysSendConfiguration, forceRelayout);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006089 } catch (RemoteException e) {
6090 // Ignore
6091 }
6092 }
6093
Daniel Sandler6396c722013-04-16 20:19:09 -04006094 /**
6095 * Return an Intent to launch the currently active dock app as home. Returns
6096 * null if the standard home should be launched, which is the case if any of the following is
6097 * true:
6098 * <ul>
6099 * <li>The device is not in either car mode or desk mode
6100 * <li>The device is in car mode but ENABLE_CAR_DOCK_HOME_CAPTURE is false
6101 * <li>The device is in desk mode but ENABLE_DESK_DOCK_HOME_CAPTURE is false
6102 * <li>The device is in car mode but there's no CAR_DOCK app with METADATA_DOCK_HOME
6103 * <li>The device is in desk mode but there's no DESK_DOCK app with METADATA_DOCK_HOME
6104 * </ul>
Craig Mautnereda67292013-04-28 13:50:14 -07006105 * @return A dock intent.
Daniel Sandler6396c722013-04-16 20:19:09 -04006106 */
6107 Intent createHomeDockIntent() {
6108 Intent intent = null;
6109
6110 // What home does is based on the mode, not the dock state. That
6111 // is, when in car mode you should be taken to car home regardless
6112 // of whether we are actually in a car dock.
6113 if (mUiMode == Configuration.UI_MODE_TYPE_CAR) {
6114 if (ENABLE_CAR_DOCK_HOME_CAPTURE) {
6115 intent = mCarDockIntent;
6116 }
6117 } else if (mUiMode == Configuration.UI_MODE_TYPE_DESK) {
6118 if (ENABLE_DESK_DOCK_HOME_CAPTURE) {
6119 intent = mDeskDockIntent;
6120 }
Jeff Brown4f5fa282014-06-12 19:19:15 -07006121 } else if (mUiMode == Configuration.UI_MODE_TYPE_WATCH
6122 && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
6123 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK
6124 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK)) {
6125 // Always launch dock home from home when watch is docked, if it exists.
6126 intent = mDeskDockIntent;
Daniel Sandler6396c722013-04-16 20:19:09 -04006127 }
6128
6129 if (intent == null) {
6130 return null;
6131 }
6132
6133 ActivityInfo ai = null;
6134 ResolveInfo info = mContext.getPackageManager().resolveActivityAsUser(
6135 intent,
John Spurlockf56bef12013-07-09 09:51:46 -04006136 PackageManager.MATCH_DEFAULT_ONLY | PackageManager.GET_META_DATA,
Craig Mautnerd625ab22013-09-06 13:40:31 -07006137 mCurrentUserId);
Daniel Sandler6396c722013-04-16 20:19:09 -04006138 if (info != null) {
6139 ai = info.activityInfo;
6140 }
6141 if (ai != null
6142 && ai.metaData != null
6143 && ai.metaData.getBoolean(Intent.METADATA_DOCK_HOME)) {
6144 intent = new Intent(intent);
6145 intent.setClassName(ai.packageName, ai.name);
6146 return intent;
6147 }
6148
6149 return null;
6150 }
6151
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00006152 void startDockOrHome(boolean fromHomeKey, boolean awakenFromDreams) {
6153 if (awakenFromDreams) {
6154 awakenDreams();
6155 }
Daniel Sandler6396c722013-04-16 20:19:09 -04006156
6157 Intent dock = createHomeDockIntent();
6158 if (dock != null) {
6159 try {
Bryce Lee01b0c5f2015-02-05 18:24:04 -08006160 if (fromHomeKey) {
6161 dock.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
6162 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00006163 startActivityAsUser(dock, UserHandle.CURRENT);
Daniel Sandler6396c722013-04-16 20:19:09 -04006164 return;
6165 } catch (ActivityNotFoundException e) {
6166 }
6167 }
6168
Bryce Lee01b0c5f2015-02-05 18:24:04 -08006169 Intent intent;
6170
6171 if (fromHomeKey) {
6172 intent = new Intent(mHomeIntent);
6173 intent.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
6174 } else {
6175 intent = mHomeIntent;
6176 }
6177
Bryce Lee9fc0b6f2015-03-19 21:37:45 +00006178 startActivityAsUser(intent, UserHandle.CURRENT);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006179 }
Craig Mautnereda67292013-04-28 13:50:14 -07006180
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006181 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006182 * goes to the home screen
6183 * @return whether it did anything
6184 */
6185 boolean goHome() {
Bart Sears8b1c27c2015-03-18 23:51:02 +00006186 if (!isUserSetupComplete()) {
6187 Slog.i(TAG, "Not going home because user setup is in progress.");
6188 return false;
6189 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006190 if (false) {
6191 // This code always brings home to the front.
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07006192 try {
6193 ActivityManagerNative.getDefault().stopAppSwitches();
6194 } catch (RemoteException e) {
6195 }
Dianne Hackborn94a679d2009-07-28 17:51:07 -07006196 sendCloseSystemWindows();
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00006197 startDockOrHome(false /*fromHomeKey*/, true /* awakenFromDreams */);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006198 } else {
6199 // This code brings home to the front or, if it is already
6200 // at the front, puts the device to sleep.
6201 try {
Wink Savilled2e6a332010-02-12 12:12:06 -08006202 if (SystemProperties.getInt("persist.sys.uts-test-mode", 0) == 1) {
6203 /// Roll back EndcallBehavior as the cupcake design to pass P1 lab entry.
6204 Log.d(TAG, "UTS-TEST-MODE");
6205 } else {
6206 ActivityManagerNative.getDefault().stopAppSwitches();
6207 sendCloseSystemWindows();
Daniel Sandler6396c722013-04-16 20:19:09 -04006208 Intent dock = createHomeDockIntent();
6209 if (dock != null) {
6210 int result = ActivityManagerNative.getDefault()
6211 .startActivityAsUser(null, null, dock,
6212 dock.resolveTypeIfNeeded(mContext.getContentResolver()),
6213 null, null, 0,
6214 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07006215 null, null, UserHandle.USER_CURRENT);
Daniel Sandler6396c722013-04-16 20:19:09 -04006216 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
6217 return false;
6218 }
6219 }
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006220 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006221 int result = ActivityManagerNative.getDefault()
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006222 .startActivityAsUser(null, null, mHomeIntent,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006223 mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()),
Dianne Hackborna4972e92012-03-14 10:38:05 -07006224 null, null, 0,
6225 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07006226 null, null, UserHandle.USER_CURRENT);
Dianne Hackborna4972e92012-03-14 10:38:05 -07006227 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006228 return false;
6229 }
6230 } catch (RemoteException ex) {
6231 // bummer, the activity manager, which is in this process, is dead
6232 }
6233 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006234 return true;
6235 }
Craig Mautnereda67292013-04-28 13:50:14 -07006236
6237 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07006238 public void setCurrentOrientationLw(int newOrientation) {
6239 synchronized (mLock) {
6240 if (newOrientation != mCurrentAppOrientation) {
6241 mCurrentAppOrientation = newOrientation;
6242 updateOrientationListenerLp();
6243 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006244 }
6245 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006246
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07006247 private void performAuditoryFeedbackForAccessibilityIfNeed() {
6248 if (!isGlobalAccessibilityGestureEnabled()) {
6249 return;
6250 }
6251 AudioManager audioManager = (AudioManager) mContext.getSystemService(
6252 Context.AUDIO_SERVICE);
6253 if (audioManager.isSilentMode()) {
6254 return;
6255 }
6256 Ringtone ringTone = RingtoneManager.getRingtone(mContext,
6257 Settings.System.DEFAULT_NOTIFICATION_URI);
6258 ringTone.setStreamType(AudioManager.STREAM_MUSIC);
6259 ringTone.play();
6260 }
Craig Mautnereda67292013-04-28 13:50:14 -07006261
Bryce Lee584a4452014-10-21 15:55:55 -07006262 private boolean isTheaterModeEnabled() {
6263 return Settings.Global.getInt(mContext.getContentResolver(),
6264 Settings.Global.THEATER_MODE_ON, 0) == 1;
6265 }
6266
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07006267 private boolean isGlobalAccessibilityGestureEnabled() {
6268 return Settings.Global.getInt(mContext.getContentResolver(),
6269 Settings.Global.ENABLE_ACCESSIBILITY_GLOBAL_GESTURE_ENABLED, 0) == 1;
6270 }
6271
Craig Mautnereda67292013-04-28 13:50:14 -07006272 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07006273 public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) {
Svetoslav Ganov96179212012-10-10 14:17:45 -07006274 if (!mVibrator.hasVibrator()) {
6275 return false;
6276 }
Christopher Tate5e08af02012-09-21 17:17:22 -07006277 final boolean hapticsDisabled = Settings.System.getIntForUser(mContext.getContentResolver(),
6278 Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) == 0;
Jeff Brown82379ba2014-07-25 19:03:28 -07006279 if (hapticsDisabled && !always) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006280 return false;
6281 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006282 long[] pattern = null;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006283 switch (effectId) {
6284 case HapticFeedbackConstants.LONG_PRESS:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006285 pattern = mLongPressVibePattern;
6286 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006287 case HapticFeedbackConstants.VIRTUAL_KEY:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006288 pattern = mVirtualKeyVibePattern;
6289 break;
6290 case HapticFeedbackConstants.KEYBOARD_TAP:
6291 pattern = mKeyboardTapVibePattern;
6292 break;
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07006293 case HapticFeedbackConstants.CLOCK_TICK:
6294 pattern = mClockTickVibePattern;
6295 break;
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07006296 case HapticFeedbackConstants.CALENDAR_DATE:
6297 pattern = mCalendarDateVibePattern;
6298 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006299 case HapticFeedbackConstants.SAFE_MODE_DISABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006300 pattern = mSafeModeDisabledVibePattern;
6301 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006302 case HapticFeedbackConstants.SAFE_MODE_ENABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006303 pattern = mSafeModeEnabledVibePattern;
6304 break;
Mady Mellore8608912015-06-05 09:02:55 -07006305 case HapticFeedbackConstants.CONTEXT_CLICK:
6306 pattern = mContextClickVibePattern;
Mady Mellore82067b2015-04-30 09:58:35 -07006307 break;
Amith Yamasanic33cb712010-02-10 15:21:49 -08006308 default:
6309 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006310 }
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006311 int owningUid;
6312 String owningPackage;
6313 if (win != null) {
6314 owningUid = win.getOwningUid();
6315 owningPackage = win.getOwningPackage();
6316 } else {
6317 owningUid = android.os.Process.myUid();
Dianne Hackborn95d78532013-09-11 09:51:14 -07006318 owningPackage = mContext.getOpPackageName();
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006319 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006320 if (pattern.length == 1) {
6321 // One-shot vibration
John Spurlock7b414672014-07-18 13:02:39 -04006322 mVibrator.vibrate(owningUid, owningPackage, pattern[0], VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08006323 } else {
6324 // Pattern vibration
John Spurlock7b414672014-07-18 13:02:39 -04006325 mVibrator.vibrate(owningUid, owningPackage, pattern, -1, VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08006326 }
6327 return true;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006328 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07006329
6330 @Override
6331 public void keepScreenOnStartedLw() {
Daniel Sandler0601eb72011-04-13 01:01:32 -04006332 }
6333
Jeff Brownc38c9be2012-10-04 13:16:19 -07006334 @Override
6335 public void keepScreenOnStoppedLw() {
Jim Millerab954542014-10-10 18:21:49 -07006336 if (isKeyguardShowingAndNotOccluded()) {
Jim Miller25190572013-02-28 17:36:24 -08006337 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006338 }
6339 }
Mike Lockwoodfcb39242009-10-21 23:01:07 -04006340
Dianne Hackborndf89e652011-10-06 22:35:11 -07006341 private int updateSystemUiVisibilityLw() {
Joe Onorato664644d2011-01-23 17:53:23 -08006342 // If there is no window focused, there will be nobody to handle the events
6343 // anyway, so just hang on in whatever state we're in until things settle down.
Adrian Roos53f28ec2014-10-29 17:26:12 +01006344 final WindowState win = mFocusedWindow != null ? mFocusedWindow
6345 : mTopFullscreenOpaqueWindowState;
John Spurlock79da8332013-09-20 12:04:47 -04006346 if (win == null) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006347 return 0;
6348 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01006349 if ((win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 && mHideLockScreen == true) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07006350 // We are updating at a point where the keyguard has gotten
6351 // focus, but we were last in a state where the top window is
6352 // hiding it. This is probably because the keyguard as been
6353 // shown while the top window was displayed, so we want to ignore
6354 // it here because this is just a very transient change and it
6355 // will quickly lose focus once it correctly gets hidden.
6356 return 0;
6357 }
John Spurlock32beb2c2013-03-11 10:16:47 -04006358
John Spurlock1db8b682014-02-18 11:18:59 -05006359 int tmpVisibility = PolicyControl.getSystemUiVisibility(win, null)
Dianne Hackborne26ab702011-10-16 13:21:33 -07006360 & ~mResettingSystemUiFlags
6361 & ~mForceClearedSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04006362 if (mForcingShowNavBar && win.getSurfaceLayer() < mForcingShowNavBarLayer) {
John Spurlockc6d1c602014-01-17 15:22:06 -05006363 tmpVisibility &= ~PolicyControl.adjustClearableFlags(win, View.SYSTEM_UI_CLEARABLE_FLAGS);
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08006364 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01006365 tmpVisibility = updateLightStatusBarLw(tmpVisibility);
John Spurlock79da8332013-09-20 12:04:47 -04006366 final int visibility = updateSystemBarsLw(win, mLastSystemUiFlags, tmpVisibility);
John Spurlockad3e6cb2013-04-30 08:47:43 -04006367 final int diff = visibility ^ mLastSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04006368 final boolean needsMenu = win.getNeedsMenuLw(mTopFullscreenOpaqueWindowState);
Dianne Hackborne0f085d2011-11-30 18:41:15 -08006369 if (diff == 0 && mLastFocusNeedsMenu == needsMenu
John Spurlock79da8332013-09-20 12:04:47 -04006370 && mFocusedApp == win.getAppToken()) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006371 return 0;
6372 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07006373 mLastSystemUiFlags = visibility;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08006374 mLastFocusNeedsMenu = needsMenu;
John Spurlock79da8332013-09-20 12:04:47 -04006375 mFocusedApp = win.getAppToken();
Dianne Hackborndf89e652011-10-06 22:35:11 -07006376 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07006377 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07006378 public void run() {
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006379 try {
6380 IStatusBarService statusbar = getStatusBarService();
6381 if (statusbar != null) {
Adrian Roos53f28ec2014-10-29 17:26:12 +01006382 statusbar.setSystemUiVisibility(visibility, 0xffffffff, win.toString());
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006383 statusbar.topAppWindowChanged(needsMenu);
Joe Onorato664644d2011-01-23 17:53:23 -08006384 }
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006385 } catch (RemoteException e) {
6386 // re-acquire status bar service next time it is needed.
6387 mStatusBarService = null;
Joe Onorato664644d2011-01-23 17:53:23 -08006388 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07006389 }
6390 });
6391 return diff;
Joe Onorato664644d2011-01-23 17:53:23 -08006392 }
6393
Adrian Rooscd3884d2015-02-18 17:25:23 +01006394 private int updateLightStatusBarLw(int vis) {
6395 WindowState statusColorWin = isStatusBarKeyguard() && !mHideLockScreen
6396 ? mStatusBar
6397 : mTopFullscreenOpaqueOrDimmingWindowState;
6398
6399 if (statusColorWin != null) {
6400 if (statusColorWin == mTopFullscreenOpaqueWindowState) {
6401 // If the top fullscreen-or-dimming window is also the top fullscreen, respect
6402 // its light flag.
6403 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6404 vis |= PolicyControl.getSystemUiVisibility(statusColorWin, null)
6405 & View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6406 } else if (statusColorWin != null && statusColorWin.isDimming()) {
6407 // Otherwise if it's dimming, clear the light flag.
6408 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6409 }
6410 }
6411 return vis;
6412 }
6413
John Spurlock79da8332013-09-20 12:04:47 -04006414 private int updateSystemBarsLw(WindowState win, int oldVis, int vis) {
John Spurlockbd957402013-10-03 11:38:39 -04006415 // apply translucent bar vis flags
Jorim Jaggi380ecb82014-03-14 17:25:20 +01006416 WindowState transWin = isStatusBarKeyguard() && !mHideLockScreen
6417 ? mStatusBar
John Spurlockbd957402013-10-03 11:38:39 -04006418 : mTopFullscreenOpaqueWindowState;
6419 vis = mStatusBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
6420 vis = mNavigationBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
6421
John Spurlock27735a42013-08-14 17:57:38 -04006422 // prevent status bar interaction from clearing certain flags
Selim Cinekf83e8242015-05-19 18:08:14 -07006423 int type = win.getAttrs().type;
6424 boolean statusBarHasFocus = type == TYPE_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04006425 if (statusBarHasFocus && !isStatusBarKeyguard()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04006426 int flags = View.SYSTEM_UI_FLAG_FULLSCREEN
6427 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlockcfc359a2013-09-05 10:42:03 -04006428 | View.SYSTEM_UI_FLAG_IMMERSIVE
Jorim Jaggi73fef8d2015-02-16 17:32:28 +01006429 | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
6430 | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04006431 if (mHideLockScreen) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01006432 flags |= View.STATUS_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSLUCENT;
6433 }
John Spurlockbd957402013-10-03 11:38:39 -04006434 vis = (vis & ~flags) | (oldVis & flags);
John Spurlockad3e6cb2013-04-30 08:47:43 -04006435 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04006436
Adrian Roos4fb3ee32014-08-22 19:29:09 +02006437 if (!areTranslucentBarsAllowed() && transWin != mStatusBar) {
Adrian Roosea562512014-05-05 13:33:03 +02006438 vis &= ~(View.NAVIGATION_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSLUCENT
6439 | View.SYSTEM_UI_TRANSPARENT);
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006440 }
6441
John Spurlock27735a42013-08-14 17:57:38 -04006442 // update status bar
John Spurlockf1a36642013-10-12 17:50:42 -04006443 boolean immersiveSticky =
6444 (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
John Spurlock27735a42013-08-14 17:57:38 -04006445 boolean hideStatusBarWM =
John Spurlockbd957402013-10-03 11:38:39 -04006446 mTopFullscreenOpaqueWindowState != null &&
John Spurlockc6d1c602014-01-17 15:22:06 -05006447 (PolicyControl.getWindowFlags(mTopFullscreenOpaqueWindowState, null)
John Spurlock27735a42013-08-14 17:57:38 -04006448 & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0;
6449 boolean hideStatusBarSysui =
6450 (vis & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04006451 boolean hideNavBarSysui =
6452 (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006453
John Spurlock27735a42013-08-14 17:57:38 -04006454 boolean transientStatusBarAllowed =
6455 mStatusBar != null && (
6456 hideStatusBarWM
John Spurlockf1a36642013-10-12 17:50:42 -04006457 || (hideStatusBarSysui && immersiveSticky)
John Spurlock27735a42013-08-14 17:57:38 -04006458 || statusBarHasFocus);
6459
John Spurlockf1a36642013-10-12 17:50:42 -04006460 boolean transientNavBarAllowed =
6461 mNavigationBar != null &&
6462 hideNavBarSysui && immersiveSticky;
6463
Adrian Roosddc8b272015-05-21 16:28:27 -07006464 final long now = SystemClock.uptimeMillis();
6465 final boolean pendingPanic = mPendingPanicGestureUptime != 0
6466 && now - mPendingPanicGestureUptime <= PANIC_GESTURE_EXPIRATION;
6467 if (pendingPanic && hideNavBarSysui && !isStatusBarKeyguard() && mKeyguardDrawComplete) {
6468 // The user performed the panic gesture recently, we're about to hide the bars,
6469 // we're no longer on the Keyguard and the screen is ready. We can now request the bars.
6470 mPendingPanicGestureUptime = 0;
6471 mStatusBarController.showTransient();
6472 mNavigationBarController.showTransient();
6473 }
6474
John Spurlockf25706f2013-11-07 18:02:43 -05006475 boolean denyTransientStatus = mStatusBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04006476 && !transientStatusBarAllowed && hideStatusBarSysui;
John Spurlockf25706f2013-11-07 18:02:43 -05006477 boolean denyTransientNav = mNavigationBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04006478 && !transientNavBarAllowed;
6479 if (denyTransientStatus || denyTransientNav) {
John Spurlock27735a42013-08-14 17:57:38 -04006480 // clear the clearable flags instead
John Spurlockf1a36642013-10-12 17:50:42 -04006481 clearClearableFlagsLw();
tiger_huangc58d7562014-10-23 20:24:19 +08006482 vis &= ~View.SYSTEM_UI_CLEARABLE_FLAGS;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006483 }
John Spurlock27735a42013-08-14 17:57:38 -04006484
Selim Cinekf98702e2015-05-20 22:48:40 -07006485 final boolean immersive = (vis & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
6486 immersiveSticky = (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
6487 final boolean navAllowedHidden = immersive || immersiveSticky;
6488
Selim Cinekd6623612015-05-22 18:56:22 -07006489 if (hideNavBarSysui && !navAllowedHidden && windowTypeToLayerLw(win.getBaseType())
6490 > windowTypeToLayerLw(TYPE_INPUT_CONSUMER)) {
Selim Cinekf98702e2015-05-20 22:48:40 -07006491 // We can't hide the navbar from this window otherwise the input consumer would not get
6492 // the input events.
6493 vis = (vis & ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
6494 }
6495
John Spurlock27735a42013-08-14 17:57:38 -04006496 vis = mStatusBarController.updateVisibilityLw(transientStatusBarAllowed, oldVis, vis);
6497
6498 // update navigation bar
John Spurlockf1a36642013-10-12 17:50:42 -04006499 boolean oldImmersiveMode = isImmersiveMode(oldVis);
6500 boolean newImmersiveMode = isImmersiveMode(vis);
6501 if (win != null && oldImmersiveMode != newImmersiveMode) {
John Spurlock79da8332013-09-20 12:04:47 -04006502 final String pkg = win.getOwningPackage();
Maurice Lam99c6e072014-04-28 18:24:28 -07006503 mImmersiveModeConfirmation.immersiveModeChanged(pkg, newImmersiveMode,
6504 isUserSetupComplete());
John Spurlock34e13d92013-08-10 06:52:28 -04006505 }
John Spurlock27735a42013-08-14 17:57:38 -04006506
John Spurlockf1a36642013-10-12 17:50:42 -04006507 vis = mNavigationBarController.updateVisibilityLw(transientNavBarAllowed, oldVis, vis);
6508
John Spurlocke1f366f2013-08-05 12:22:40 -04006509 return vis;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006510 }
6511
John Spurlockf1a36642013-10-12 17:50:42 -04006512 private void clearClearableFlagsLw() {
6513 int newVal = mResettingSystemUiFlags | View.SYSTEM_UI_CLEARABLE_FLAGS;
6514 if (newVal != mResettingSystemUiFlags) {
6515 mResettingSystemUiFlags = newVal;
6516 mWindowManagerFuncs.reevaluateStatusBarVisibility();
6517 }
6518 }
6519
6520 private boolean isImmersiveMode(int vis) {
6521 final int flags = View.SYSTEM_UI_FLAG_IMMERSIVE | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
John Spurlock34e13d92013-08-10 06:52:28 -04006522 return mNavigationBar != null
6523 && (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0
Daniel Sandler900ece52013-10-18 15:53:27 -04006524 && (vis & flags) != 0
6525 && canHideNavigationBar();
John Spurlock34e13d92013-08-10 06:52:28 -04006526 }
6527
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006528 /**
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04006529 * @return whether the navigation or status bar can be made translucent
6530 *
6531 * This should return true unless touch exploration is not enabled or
6532 * R.boolean.config_enableTranslucentDecor is false.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006533 */
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04006534 private boolean areTranslucentBarsAllowed() {
Svetoslav8e3feb12014-02-24 13:46:47 -08006535 return mTranslucentDecorEnabled
6536 && !mAccessibilityManager.isTouchExplorationEnabled();
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006537 }
6538
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04006539 // Use this instead of checking config_showNavigationBar so that it can be consistently
6540 // overridden by qemu.hw.mainkeys in the emulator.
Craig Mautnereda67292013-04-28 13:50:14 -07006541 @Override
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04006542 public boolean hasNavigationBar() {
6543 return mHasNavigationBar;
6544 }
6545
satok1bc0a492012-04-25 22:47:12 +09006546 @Override
6547 public void setLastInputMethodWindowLw(WindowState ime, WindowState target) {
6548 mLastInputMethodWindow = ime;
6549 mLastInputMethodTargetWindow = target;
6550 }
6551
Craig Mautnerf1b67412012-09-19 13:18:29 -07006552 @Override
Satoshi Kataoka658c7b82013-10-10 17:03:51 +09006553 public int getInputMethodWindowVisibleHeightLw() {
6554 return mDockBottom - mCurBottom;
6555 }
6556
6557 @Override
Craig Mautnerf1b67412012-09-19 13:18:29 -07006558 public void setCurrentUserLw(int newUserId) {
Craig Mautnerd625ab22013-09-06 13:40:31 -07006559 mCurrentUserId = newUserId;
Jim Miller5ecd8112013-01-09 18:50:26 -08006560 if (mKeyguardDelegate != null) {
6561 mKeyguardDelegate.setCurrentUser(newUserId);
Craig Mautnerf1b67412012-09-19 13:18:29 -07006562 }
John Spurlock13451a22012-09-28 14:40:41 -04006563 if (mStatusBarService != null) {
6564 try {
6565 mStatusBarService.setCurrentUser(newUserId);
6566 } catch (RemoteException e) {
6567 // oh well
6568 }
6569 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006570 setLastInputMethodWindowLw(null, null);
Craig Mautnerf1b67412012-09-19 13:18:29 -07006571 }
6572
6573 @Override
Svetoslav Ganov545252f2012-12-10 18:29:24 -08006574 public boolean canMagnifyWindow(int windowType) {
6575 switch (windowType) {
6576 case WindowManager.LayoutParams.TYPE_INPUT_METHOD:
6577 case WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG:
6578 case WindowManager.LayoutParams.TYPE_NAVIGATION_BAR:
6579 case WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY: {
6580 return false;
6581 }
6582 }
6583 return true;
6584 }
6585
6586 @Override
6587 public boolean isTopLevelWindow(int windowType) {
6588 if (windowType >= WindowManager.LayoutParams.FIRST_SUB_WINDOW
6589 && windowType <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
6590 return (windowType == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG);
6591 }
6592 return true;
6593 }
6594
Jim Miller4eeb4f62012-11-08 00:04:29 -08006595 @Override
Jeff Brownd7a04de2012-06-17 14:17:52 -07006596 public void dump(String prefix, PrintWriter pw, String[] args) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006597 pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07006598 pw.print(" mSystemReady="); pw.print(mSystemReady);
6599 pw.print(" mSystemBooted="); pw.println(mSystemBooted);
Jeff Brown2e7760e2012-04-11 15:14:55 -07006600 pw.print(prefix); pw.print("mLidState="); pw.print(mLidState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006601 pw.print(" mLidOpenRotation="); pw.print(mLidOpenRotation);
Michael Wright3818c922014-09-02 13:59:07 -07006602 pw.print(" mCameraLensCoverState="); pw.print(mCameraLensCoverState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006603 pw.print(" mHdmiPlugged="); pw.println(mHdmiPlugged);
Dianne Hackborne26ab702011-10-16 13:21:33 -07006604 if (mLastSystemUiFlags != 0 || mResettingSystemUiFlags != 0
6605 || mForceClearedSystemUiFlags != 0) {
6606 pw.print(prefix); pw.print("mLastSystemUiFlags=0x");
6607 pw.print(Integer.toHexString(mLastSystemUiFlags));
6608 pw.print(" mResettingSystemUiFlags=0x");
6609 pw.print(Integer.toHexString(mResettingSystemUiFlags));
6610 pw.print(" mForceClearedSystemUiFlags=0x");
6611 pw.println(Integer.toHexString(mForceClearedSystemUiFlags));
Dianne Hackborndf89e652011-10-06 22:35:11 -07006612 }
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08006613 if (mLastFocusNeedsMenu) {
6614 pw.print(prefix); pw.print("mLastFocusNeedsMenu=");
6615 pw.println(mLastFocusNeedsMenu);
6616 }
Jeff Browna20dda42014-05-27 20:57:24 -07006617 pw.print(prefix); pw.print("mWakeGestureEnabledSetting=");
6618 pw.println(mWakeGestureEnabledSetting);
6619
Jeff Brownbcdfc622014-03-06 19:13:04 -08006620 pw.print(prefix); pw.print("mSupportAutoRotation="); pw.println(mSupportAutoRotation);
Daniel Sandler6396c722013-04-16 20:19:09 -04006621 pw.print(prefix); pw.print("mUiMode="); pw.print(mUiMode);
6622 pw.print(" mDockMode="); pw.print(mDockMode);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006623 pw.print(" mCarDockRotation="); pw.print(mCarDockRotation);
6624 pw.print(" mDeskDockRotation="); pw.println(mDeskDockRotation);
6625 pw.print(prefix); pw.print("mUserRotationMode="); pw.print(mUserRotationMode);
6626 pw.print(" mUserRotation="); pw.print(mUserRotation);
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05006627 pw.print(" mAllowAllRotations="); pw.println(mAllowAllRotations);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07006628 pw.print(prefix); pw.print("mCurrentAppOrientation="); pw.println(mCurrentAppOrientation);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006629 pw.print(prefix); pw.print("mCarDockEnablesAccelerometer=");
6630 pw.print(mCarDockEnablesAccelerometer);
6631 pw.print(" mDeskDockEnablesAccelerometer=");
6632 pw.println(mDeskDockEnablesAccelerometer);
6633 pw.print(prefix); pw.print("mLidKeyboardAccessibility=");
6634 pw.print(mLidKeyboardAccessibility);
6635 pw.print(" mLidNavigationAccessibility="); pw.print(mLidNavigationAccessibility);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07006636 pw.print(" mLidControlsSleep="); pw.println(mLidControlsSleep);
Jeff Brown6d8fd272014-05-20 21:24:38 -07006637 pw.print(prefix);
6638 pw.print("mShortPressOnPowerBehavior="); pw.print(mShortPressOnPowerBehavior);
6639 pw.print(" mLongPressOnPowerBehavior="); pw.println(mLongPressOnPowerBehavior);
Jeff Brown13f00f02014-10-31 14:45:50 -07006640 pw.print(prefix);
6641 pw.print("mDoublePressOnPowerBehavior="); pw.print(mDoublePressOnPowerBehavior);
6642 pw.print(" mTriplePressOnPowerBehavior="); pw.println(mTriplePressOnPowerBehavior);
Jeff Brown6d8fd272014-05-20 21:24:38 -07006643 pw.print(prefix); pw.print("mHasSoftInput="); pw.println(mHasSoftInput);
Jeff Brown3ee549c2014-09-22 20:14:39 -07006644 pw.print(prefix); pw.print("mAwake="); pw.println(mAwake);
6645 pw.print(prefix); pw.print("mScreenOnEarly="); pw.print(mScreenOnEarly);
6646 pw.print(" mScreenOnFully="); pw.println(mScreenOnFully);
6647 pw.print(prefix); pw.print("mKeyguardDrawComplete="); pw.print(mKeyguardDrawComplete);
6648 pw.print(" mWindowManagerDrawComplete="); pw.println(mWindowManagerDrawComplete);
6649 pw.print(prefix); pw.print("mOrientationSensorEnabled=");
6650 pw.println(mOrientationSensorEnabled);
Dianne Hackbornc652de82013-02-15 16:32:56 -08006651 pw.print(prefix); pw.print("mOverscanScreen=("); pw.print(mOverscanScreenLeft);
6652 pw.print(","); pw.print(mOverscanScreenTop);
6653 pw.print(") "); pw.print(mOverscanScreenWidth);
6654 pw.print("x"); pw.println(mOverscanScreenHeight);
6655 if (mOverscanLeft != 0 || mOverscanTop != 0
6656 || mOverscanRight != 0 || mOverscanBottom != 0) {
6657 pw.print(prefix); pw.print("mOverscan left="); pw.print(mOverscanLeft);
6658 pw.print(" top="); pw.print(mOverscanTop);
6659 pw.print(" right="); pw.print(mOverscanRight);
6660 pw.print(" bottom="); pw.println(mOverscanBottom);
6661 }
Dianne Hackborn313440842013-02-19 19:22:59 -08006662 pw.print(prefix); pw.print("mRestrictedOverscanScreen=(");
6663 pw.print(mRestrictedOverscanScreenLeft);
6664 pw.print(","); pw.print(mRestrictedOverscanScreenTop);
6665 pw.print(") "); pw.print(mRestrictedOverscanScreenWidth);
6666 pw.print("x"); pw.println(mRestrictedOverscanScreenHeight);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006667 pw.print(prefix); pw.print("mUnrestrictedScreen=("); pw.print(mUnrestrictedScreenLeft);
6668 pw.print(","); pw.print(mUnrestrictedScreenTop);
6669 pw.print(") "); pw.print(mUnrestrictedScreenWidth);
6670 pw.print("x"); pw.println(mUnrestrictedScreenHeight);
6671 pw.print(prefix); pw.print("mRestrictedScreen=("); pw.print(mRestrictedScreenLeft);
6672 pw.print(","); pw.print(mRestrictedScreenTop);
6673 pw.print(") "); pw.print(mRestrictedScreenWidth);
6674 pw.print("x"); pw.println(mRestrictedScreenHeight);
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07006675 pw.print(prefix); pw.print("mStableFullscreen=("); pw.print(mStableFullscreenLeft);
6676 pw.print(","); pw.print(mStableFullscreenTop);
6677 pw.print(")-("); pw.print(mStableFullscreenRight);
6678 pw.print(","); pw.print(mStableFullscreenBottom); pw.println(")");
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07006679 pw.print(prefix); pw.print("mStable=("); pw.print(mStableLeft);
6680 pw.print(","); pw.print(mStableTop);
6681 pw.print(")-("); pw.print(mStableRight);
6682 pw.print(","); pw.print(mStableBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07006683 pw.print(prefix); pw.print("mSystem=("); pw.print(mSystemLeft);
6684 pw.print(","); pw.print(mSystemTop);
6685 pw.print(")-("); pw.print(mSystemRight);
6686 pw.print(","); pw.print(mSystemBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006687 pw.print(prefix); pw.print("mCur=("); pw.print(mCurLeft);
6688 pw.print(","); pw.print(mCurTop);
6689 pw.print(")-("); pw.print(mCurRight);
6690 pw.print(","); pw.print(mCurBottom); pw.println(")");
6691 pw.print(prefix); pw.print("mContent=("); pw.print(mContentLeft);
6692 pw.print(","); pw.print(mContentTop);
6693 pw.print(")-("); pw.print(mContentRight);
6694 pw.print(","); pw.print(mContentBottom); pw.println(")");
Dianne Hackborne30e02f2014-05-27 18:24:45 -07006695 pw.print(prefix); pw.print("mVoiceContent=("); pw.print(mVoiceContentLeft);
6696 pw.print(","); pw.print(mVoiceContentTop);
6697 pw.print(")-("); pw.print(mVoiceContentRight);
6698 pw.print(","); pw.print(mVoiceContentBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006699 pw.print(prefix); pw.print("mDock=("); pw.print(mDockLeft);
6700 pw.print(","); pw.print(mDockTop);
6701 pw.print(")-("); pw.print(mDockRight);
6702 pw.print(","); pw.print(mDockBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07006703 pw.print(prefix); pw.print("mDockLayer="); pw.print(mDockLayer);
6704 pw.print(" mStatusBarLayer="); pw.println(mStatusBarLayer);
Dianne Hackborn7ad44382012-10-18 17:46:00 -07006705 pw.print(prefix); pw.print("mShowingLockscreen="); pw.print(mShowingLockscreen);
6706 pw.print(" mShowingDream="); pw.print(mShowingDream);
Jeff Brown061ea992015-04-17 19:55:47 -07006707 pw.print(" mDreamingLockscreen="); pw.print(mDreamingLockscreen);
6708 pw.print(" mDreamingSleepToken="); pw.println(mDreamingSleepToken);
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006709 if (mLastInputMethodWindow != null) {
6710 pw.print(prefix); pw.print("mLastInputMethodWindow=");
6711 pw.println(mLastInputMethodWindow);
6712 }
6713 if (mLastInputMethodTargetWindow != null) {
6714 pw.print(prefix); pw.print("mLastInputMethodTargetWindow=");
6715 pw.println(mLastInputMethodTargetWindow);
6716 }
6717 if (mStatusBar != null) {
6718 pw.print(prefix); pw.print("mStatusBar=");
Dianne Hackbornae6688b2015-02-11 17:02:41 -08006719 pw.print(mStatusBar); pw.print(" isStatusBarKeyguard=");
6720 pw.println(isStatusBarKeyguard());
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006721 }
6722 if (mNavigationBar != null) {
6723 pw.print(prefix); pw.print("mNavigationBar=");
6724 pw.println(mNavigationBar);
6725 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006726 if (mFocusedWindow != null) {
6727 pw.print(prefix); pw.print("mFocusedWindow=");
6728 pw.println(mFocusedWindow);
6729 }
6730 if (mFocusedApp != null) {
6731 pw.print(prefix); pw.print("mFocusedApp=");
6732 pw.println(mFocusedApp);
6733 }
6734 if (mWinDismissingKeyguard != null) {
6735 pw.print(prefix); pw.print("mWinDismissingKeyguard=");
6736 pw.println(mWinDismissingKeyguard);
6737 }
6738 if (mTopFullscreenOpaqueWindowState != null) {
6739 pw.print(prefix); pw.print("mTopFullscreenOpaqueWindowState=");
6740 pw.println(mTopFullscreenOpaqueWindowState);
6741 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01006742 if (mTopFullscreenOpaqueOrDimmingWindowState != null) {
6743 pw.print(prefix); pw.print("mTopFullscreenOpaqueOrDimmingWindowState=");
6744 pw.println(mTopFullscreenOpaqueOrDimmingWindowState);
6745 }
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08006746 if (mForcingShowNavBar) {
6747 pw.print(prefix); pw.print("mForcingShowNavBar=");
6748 pw.println(mForcingShowNavBar); pw.print( "mForcingShowNavBarLayer=");
6749 pw.println(mForcingShowNavBarLayer);
6750 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07006751 pw.print(prefix); pw.print("mTopIsFullscreen="); pw.print(mTopIsFullscreen);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006752 pw.print(" mHideLockScreen="); pw.println(mHideLockScreen);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07006753 pw.print(prefix); pw.print("mForceStatusBar="); pw.print(mForceStatusBar);
6754 pw.print(" mForceStatusBarFromKeyguard=");
6755 pw.println(mForceStatusBarFromKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006756 pw.print(prefix); pw.print("mDismissKeyguard="); pw.print(mDismissKeyguard);
Craig Mautnerad09bcc2012-10-08 13:33:11 -07006757 pw.print(" mWinDismissingKeyguard="); pw.print(mWinDismissingKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006758 pw.print(" mHomePressed="); pw.println(mHomePressed);
6759 pw.print(prefix); pw.print("mAllowLockscreenWhenOn="); pw.print(mAllowLockscreenWhenOn);
6760 pw.print(" mLockScreenTimeout="); pw.print(mLockScreenTimeout);
6761 pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive);
6762 pw.print(prefix); pw.print("mEndcallBehavior="); pw.print(mEndcallBehavior);
6763 pw.print(" mIncallPowerBehavior="); pw.print(mIncallPowerBehavior);
6764 pw.print(" mLongPressOnHomeBehavior="); pw.println(mLongPressOnHomeBehavior);
6765 pw.print(prefix); pw.print("mLandscapeRotation="); pw.print(mLandscapeRotation);
6766 pw.print(" mSeascapeRotation="); pw.println(mSeascapeRotation);
6767 pw.print(prefix); pw.print("mPortraitRotation="); pw.print(mPortraitRotation);
6768 pw.print(" mUpsideDownRotation="); pw.println(mUpsideDownRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07006769 pw.print(prefix); pw.print("mDemoHdmiRotation="); pw.print(mDemoHdmiRotation);
6770 pw.print(" mDemoHdmiRotationLock="); pw.println(mDemoHdmiRotationLock);
6771 pw.print(prefix); pw.print("mUndockedHdmiRotation="); pw.println(mUndockedHdmiRotation);
Jeff Brown600f0032014-05-22 17:06:00 -07006772
Tim Kilbournd7c0c2e2014-05-29 16:08:10 -07006773 mGlobalKeyManager.dump(prefix, pw);
John Spurlock27735a42013-08-14 17:57:38 -04006774 mStatusBarController.dump(pw, prefix);
6775 mNavigationBarController.dump(pw, prefix);
John Spurlockc6d1c602014-01-17 15:22:06 -05006776 PolicyControl.dump(prefix, pw);
Jeff Brown600f0032014-05-22 17:06:00 -07006777
Jeff Browna20dda42014-05-27 20:57:24 -07006778 if (mWakeGestureListener != null) {
6779 mWakeGestureListener.dump(pw, prefix);
6780 }
Jeff Brown600f0032014-05-22 17:06:00 -07006781 if (mOrientationListener != null) {
6782 mOrientationListener.dump(pw, prefix);
6783 }
Filip Gruszczynskicfb31852015-02-25 21:47:12 +00006784 if (mBurnInProtectionHelper != null) {
6785 mBurnInProtectionHelper.dump(prefix, pw);
6786 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006787 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006788}