blob: b668bba9ab2a474452c95ccd009ec2aef4751d04 [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 Mellore82067b2015-04-30 09:58:35 -0700291 // Vibrator pattern for haptic feedback of a stylus button press.
292 long[] mStylusButtonPressVibePattern;
293
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;
Jim Millerab954542014-10-10 18:21:49 -0700517 boolean mKeyguardSecure;
518 boolean mKeyguardSecureIncludingHidden;
519 volatile boolean mKeyguardOccluded;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800520 boolean mHomePressed;
Jeff Browncaca8812013-05-09 13:34:33 -0700521 boolean mHomeConsumed;
522 boolean mHomeDoubleTapPending;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800523 Intent mHomeIntent;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700524 Intent mCarDockIntent;
525 Intent mDeskDockIntent;
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700526 boolean mSearchKeyShortcutPending;
527 boolean mConsumeSearchKeyUp;
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700528 boolean mAssistKeyLongPressed;
Michael Wright6a62e552014-06-03 19:19:48 -0700529 boolean mPendingMetaAction;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800530
Mike Lockwood28569302010-01-28 11:54:40 -0500531 // support for activating the lock screen while the screen is on
532 boolean mAllowLockscreenWhenOn;
533 int mLockScreenTimeout;
534 boolean mLockScreenTimerActive;
535
David Brownbaf8d092010-03-08 21:52:59 -0800536 // Behavior of ENDCALL Button. (See Settings.System.END_BUTTON_BEHAVIOR.)
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800537 int mEndcallBehavior;
David Brownbaf8d092010-03-08 21:52:59 -0800538
539 // Behavior of POWER button while in-call and screen on.
540 // (See Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR.)
541 int mIncallPowerBehavior;
542
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700543 Display mDisplay;
544
Dianne Hackborn9d132642011-04-21 17:26:39 -0700545 int mLandscapeRotation = 0; // default landscape rotation
546 int mSeascapeRotation = 0; // "other" landscape rotation, 180 degrees from mLandscapeRotation
547 int mPortraitRotation = 0; // default portrait rotation
548 int mUpsideDownRotation = 0; // "other" portrait rotation
Mitsuru Oshima831d0d92009-06-16 18:27:18 -0700549
Dianne Hackbornc652de82013-02-15 16:32:56 -0800550 int mOverscanLeft = 0;
551 int mOverscanTop = 0;
552 int mOverscanRight = 0;
553 int mOverscanBottom = 0;
554
Joe Onorato46b0d682010-11-22 17:37:27 -0800555 // What we do when the user long presses on home
Jeff Browncaca8812013-05-09 13:34:33 -0700556 private int mLongPressOnHomeBehavior;
557
558 // What we do when the user double-taps on home
559 private int mDoubleTapOnHomeBehavior;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800560
Bryce Lee584a4452014-10-21 15:55:55 -0700561 // Allowed theater mode wake actions
562 private boolean mAllowTheaterModeWakeFromKey;
563 private boolean mAllowTheaterModeWakeFromPowerKey;
564 private boolean mAllowTheaterModeWakeFromMotion;
Bryce Lee812d7022014-11-10 13:33:28 -0800565 private boolean mAllowTheaterModeWakeFromMotionWhenNotDreaming;
Bryce Lee584a4452014-10-21 15:55:55 -0700566 private boolean mAllowTheaterModeWakeFromCameraLens;
567 private boolean mAllowTheaterModeWakeFromLidSwitch;
568 private boolean mAllowTheaterModeWakeFromWakeGesture;
569
Bryce Leed3b28402015-03-09 15:49:13 +0000570 // Whether to support long press from power button in non-interactive mode
571 private boolean mSupportLongPressPowerWhenNonInteractive;
572
Bryce Lee55e846d2014-11-04 12:43:44 -0800573 // Whether to go to sleep entering theater mode from power button
574 private boolean mGoToSleepOnButtonPressTheaterMode;
575
Winson Chung9112ec32011-06-27 13:15:32 -0700576 // Screenshot trigger states
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700577 // Time to volume and power must be pressed within this interval of each other.
578 private static final long SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS = 150;
Winson Chung1cea2f32012-10-08 20:42:01 -0700579 // Increase the chord delay when taking a screenshot from the keyguard
580 private static final float KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER = 2.5f;
Christopher Tatee90585f2012-03-05 18:56:25 -0800581 private boolean mScreenshotChordEnabled;
Jeff Brown13f00f02014-10-31 14:45:50 -0700582 private boolean mScreenshotChordVolumeDownKeyTriggered;
583 private long mScreenshotChordVolumeDownKeyTime;
584 private boolean mScreenshotChordVolumeDownKeyConsumed;
585 private boolean mScreenshotChordVolumeUpKeyTriggered;
586 private boolean mScreenshotChordPowerKeyTriggered;
587 private long mScreenshotChordPowerKeyTime;
Winson Chung9112ec32011-06-27 13:15:32 -0700588
Michael Wrightb854e242013-02-05 17:54:02 -0800589 /* The number of steps between min and max brightness */
590 private static final int BRIGHTNESS_STEPS = 10;
591
Christopher Tate5e08af02012-09-21 17:17:22 -0700592 SettingsObserver mSettingsObserver;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800593 ShortcutManager mShortcutManager;
594 PowerManager.WakeLock mBroadcastWakeLock;
Jeff Brown13f00f02014-10-31 14:45:50 -0700595 PowerManager.WakeLock mPowerKeyWakeLock;
Jeff Brown40013652012-05-16 21:22:36 -0700596 boolean mHavePendingMediaKeyRepeatWithWakeLock;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800597
Craig Mautnerd625ab22013-09-06 13:40:31 -0700598 private int mCurrentUserId;
599
Justin Kohd378ad72013-04-01 12:18:26 -0700600 // Maps global key codes to the components that will handle them.
601 private GlobalKeyManager mGlobalKeyManager;
602
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700603 // Fallback actions by key code.
604 private final SparseArray<KeyCharacterMap.FallbackAction> mFallbackActions =
605 new SparseArray<KeyCharacterMap.FallbackAction>();
Jeff Brown49ed71d2010-12-06 17:13:33 -0800606
Jorim Jaggi76a16232014-08-08 17:00:47 +0200607 private final LogDecelerateInterpolator mLogDecelerateInterpolator
608 = new LogDecelerateInterpolator(100, 0);
609
Jeff Brown70825162012-03-28 17:27:48 -0700610 private static final int MSG_ENABLE_POINTER_LOCATION = 1;
611 private static final int MSG_DISABLE_POINTER_LOCATION = 2;
Jeff Brown40013652012-05-16 21:22:36 -0700612 private static final int MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK = 3;
613 private static final int MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK = 4;
Craig Mautner8a0da012014-05-31 15:13:37 -0700614 private static final int MSG_KEYGUARD_DRAWN_COMPLETE = 5;
615 private static final int MSG_KEYGUARD_DRAWN_TIMEOUT = 6;
616 private static final int MSG_WINDOW_MANAGER_DRAWN_COMPLETE = 7;
Craig Mautner84984fa2014-06-19 11:19:20 -0700617 private static final int MSG_DISPATCH_SHOW_RECENTS = 9;
Alan Viverettee34560b22014-07-10 14:50:06 -0700618 private static final int MSG_DISPATCH_SHOW_GLOBAL_ACTIONS = 10;
Craig Mautnera631d492014-08-05 15:16:01 -0700619 private static final int MSG_HIDE_BOOT_MESSAGE = 11;
Michael Wright869a67c2014-08-26 19:33:06 -0700620 private static final int MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK = 12;
Jeff Brown13f00f02014-10-31 14:45:50 -0700621 private static final int MSG_POWER_DELAYED_PRESS = 13;
622 private static final int MSG_POWER_LONG_PRESS = 14;
Jeff Brown061ea992015-04-17 19:55:47 -0700623 private static final int MSG_UPDATE_DREAMING_SLEEP_TOKEN = 15;
Jeff Brown70825162012-03-28 17:27:48 -0700624
625 private class PolicyHandler extends Handler {
626 @Override
627 public void handleMessage(Message msg) {
628 switch (msg.what) {
629 case MSG_ENABLE_POINTER_LOCATION:
630 enablePointerLocation();
631 break;
632 case MSG_DISABLE_POINTER_LOCATION:
633 disablePointerLocation();
634 break;
Jeff Brown40013652012-05-16 21:22:36 -0700635 case MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK:
636 dispatchMediaKeyWithWakeLock((KeyEvent)msg.obj);
637 break;
638 case MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK:
639 dispatchMediaKeyRepeatWithWakeLock((KeyEvent)msg.obj);
640 break;
Craig Mautner84984fa2014-06-19 11:19:20 -0700641 case MSG_DISPATCH_SHOW_RECENTS:
642 showRecentApps(false);
643 break;
Alan Viverettee34560b22014-07-10 14:50:06 -0700644 case MSG_DISPATCH_SHOW_GLOBAL_ACTIONS:
645 showGlobalActionsInternal();
646 break;
Craig Mautner8a0da012014-05-31 15:13:37 -0700647 case MSG_KEYGUARD_DRAWN_COMPLETE:
648 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mKeyguardDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700649 finishKeyguardDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700650 break;
651 case MSG_KEYGUARD_DRAWN_TIMEOUT:
652 Slog.w(TAG, "Keyguard drawn timeout. Setting mKeyguardDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700653 finishKeyguardDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700654 break;
655 case MSG_WINDOW_MANAGER_DRAWN_COMPLETE:
656 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mWindowManagerDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700657 finishWindowsDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700658 break;
Craig Mautnera631d492014-08-05 15:16:01 -0700659 case MSG_HIDE_BOOT_MESSAGE:
660 handleHideBootMessage();
661 break;
Michael Wright869a67c2014-08-26 19:33:06 -0700662 case MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK:
663 launchVoiceAssistWithWakeLock(msg.arg1 != 0);
664 break;
Jeff Brown13f00f02014-10-31 14:45:50 -0700665 case MSG_POWER_DELAYED_PRESS:
666 powerPress((Long)msg.obj, msg.arg1 != 0, msg.arg2);
667 finishPowerKeyPress();
668 break;
669 case MSG_POWER_LONG_PRESS:
670 powerLongPress();
671 break;
Jeff Brown061ea992015-04-17 19:55:47 -0700672 case MSG_UPDATE_DREAMING_SLEEP_TOKEN:
673 updateDreamingSleepToken(msg.arg1 != 0);
674 break;
Jeff Brown70825162012-03-28 17:27:48 -0700675 }
676 }
677 }
678
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800679 private UEventObserver mHDMIObserver = new UEventObserver() {
680 @Override
681 public void onUEvent(UEventObserver.UEvent event) {
682 setHdmiPlugged("1".equals(event.get("SWITCH_STATE")));
683 }
684 };
685
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800686 class SettingsObserver extends ContentObserver {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800687 SettingsObserver(Handler handler) {
688 super(handler);
689 }
David Brownbaf8d092010-03-08 21:52:59 -0800690
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800691 void observe() {
Christopher Tate5e08af02012-09-21 17:17:22 -0700692 // Observe all users' changes
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800693 ContentResolver resolver = mContext.getContentResolver();
694 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700695 Settings.System.END_BUTTON_BEHAVIOR), false, this,
696 UserHandle.USER_ALL);
David Brownbaf8d092010-03-08 21:52:59 -0800697 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700698 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR), false, this,
699 UserHandle.USER_ALL);
Jeff Browna20dda42014-05-27 20:57:24 -0700700 resolver.registerContentObserver(Settings.Secure.getUriFor(
701 Settings.Secure.WAKE_GESTURE_ENABLED), false, this,
702 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800703 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700704 Settings.System.ACCELEROMETER_ROTATION), false, this,
705 UserHandle.USER_ALL);
Mike Lockwood28569302010-01-28 11:54:40 -0500706 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700707 Settings.System.USER_ROTATION), false, this,
708 UserHandle.USER_ALL);
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400709 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700710 Settings.System.SCREEN_OFF_TIMEOUT), false, this,
711 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800712 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700713 Settings.System.POINTER_LOCATION), false, this,
714 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800715 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700716 Settings.Secure.DEFAULT_INPUT_METHOD), false, this,
717 UserHandle.USER_ALL);
John Spurlockd9b70bd2014-02-06 17:02:44 -0500718 resolver.registerContentObserver(Settings.Secure.getUriFor(
John Spurlockf1a36642013-10-12 17:50:42 -0400719 Settings.Secure.IMMERSIVE_MODE_CONFIRMATIONS), false, this,
Christopher Tate5e08af02012-09-21 17:17:22 -0700720 UserHandle.USER_ALL);
John Spurlockc6d1c602014-01-17 15:22:06 -0500721 resolver.registerContentObserver(Settings.Global.getUriFor(
722 Settings.Global.POLICY_CONTROL), false, this,
723 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800724 updateSettings();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800725 }
726
727 @Override public void onChange(boolean selfChange) {
Dianne Hackbornc777e072010-02-12 13:07:59 -0800728 updateSettings();
Jeff Brown01a98dd2011-09-20 15:08:29 -0700729 updateRotation(false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800730 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800731 }
Craig Mautner967212c2013-04-13 21:10:58 -0700732
Jeff Browna20dda42014-05-27 20:57:24 -0700733 class MyWakeGestureListener extends WakeGestureListener {
734 MyWakeGestureListener(Context context, Handler handler) {
735 super(context, handler);
736 }
737
738 @Override
739 public void onWakeUp() {
740 synchronized (mLock) {
741 if (shouldEnableWakeGestureLp()) {
Jeff Browne07b94b2014-06-18 15:56:27 -0700742 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
Bryce Lee584a4452014-10-21 15:55:55 -0700743 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromWakeGesture);
Jeff Browna20dda42014-05-27 20:57:24 -0700744 }
745 }
746 }
747 }
748
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800749 class MyOrientationListener extends WindowOrientationListener {
Craig Mautnereee29c42013-01-17 14:44:34 -0800750 MyOrientationListener(Context context, Handler handler) {
751 super(context, handler);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800752 }
Craig Mautner967212c2013-04-13 21:10:58 -0700753
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800754 @Override
Jeff Brownc0347aa2011-09-23 17:26:09 -0700755 public void onProposedRotationChanged(int rotation) {
Craig Mautnereda67292013-04-28 13:50:14 -0700756 if (localLOGV) Slog.v(TAG, "onProposedRotationChanged, rotation=" + rotation);
Jeff Brown01a98dd2011-09-20 15:08:29 -0700757 updateRotation(false);
758 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800759 }
760 MyOrientationListener mOrientationListener;
761
Jorim Jaggi24bec7c2015-02-04 12:40:14 +0100762 private final StatusBarController mStatusBarController = new StatusBarController();
John Spurlock5b9145b2013-08-20 15:13:47 -0400763
John Spurlock27735a42013-08-14 17:57:38 -0400764 private final BarController mNavigationBarController = new BarController("NavigationBar",
John Spurlock5b9145b2013-08-20 15:13:47 -0400765 View.NAVIGATION_BAR_TRANSIENT,
766 View.NAVIGATION_BAR_UNHIDE,
John Spurlockbd957402013-10-03 11:38:39 -0400767 View.NAVIGATION_BAR_TRANSLUCENT,
768 StatusBarManager.WINDOW_NAVIGATION_BAR,
769 WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
John Spurlock5b9145b2013-08-20 15:13:47 -0400770
John Spurlockf1a36642013-10-12 17:50:42 -0400771 private ImmersiveModeConfirmation mImmersiveModeConfirmation;
John Spurlock32beb2c2013-03-11 10:16:47 -0400772
Craig Mautner037aa8d2013-06-07 10:35:44 -0700773 private SystemGesturesPointerEventListener mSystemGestures;
John Spurlock32beb2c2013-03-11 10:16:47 -0400774
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700775 IStatusBarService getStatusBarService() {
776 synchronized (mServiceAquireLock) {
777 if (mStatusBarService == null) {
778 mStatusBarService = IStatusBarService.Stub.asInterface(
779 ServiceManager.getService("statusbar"));
780 }
781 return mStatusBarService;
782 }
783 }
784
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700785 /*
786 * We always let the sensor be switched on by default except when
787 * the user has explicitly disabled sensor based rotation or when the
788 * screen is switched off.
789 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700790 boolean needSensorRunningLp() {
Jeff Brownbcdfc622014-03-06 19:13:04 -0800791 if (mSupportAutoRotation) {
792 if (mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
793 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
794 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT
795 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) {
796 // If the application has explicitly requested to follow the
797 // orientation, then we need to turn the sensor on.
798 return true;
799 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800800 }
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700801 if ((mCarDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_CAR) ||
Jeff Brown1a693182011-11-08 14:44:16 -0800802 (mDeskDockEnablesAccelerometer && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
803 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
804 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK))) {
Mike Lockwoode9867d22009-09-20 01:59:02 -0400805 // enable accelerometer if we are docked in a dock that enables accelerometer
806 // orientation management,
807 return true;
808 }
Jeff Brown207673cd2012-06-05 17:47:11 -0700809 if (mUserRotationMode == USER_ROTATION_LOCKED) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800810 // If the setting for using the sensor by default is enabled, then
811 // we will always leave it on. Note that the user could go to
812 // a window that forces an orientation that does not use the
813 // sensor and in theory we could turn it off... however, when next
814 // turning it on we won't have a good value for the current
815 // orientation for a little bit, which can cause orientation
816 // changes to lag, so we'd like to keep it always on. (It will
817 // still be turned off when the screen is off.)
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700818 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800819 }
Jeff Brownbcdfc622014-03-06 19:13:04 -0800820 return mSupportAutoRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800821 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700822
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800823 /*
824 * Various use cases for invoking this function
825 * screen turning off, should always disable listeners if already enabled
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700826 * screen turned on and current app has sensor based orientation, enable listeners
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800827 * if not already enabled
828 * screen turned on and current app does not have sensor orientation, disable listeners if
829 * already enabled
830 * screen turning on and current app has sensor based orientation, enable listeners if needed
831 * screen turning on and current app has nosensor based orientation, do nothing
832 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700833 void updateOrientationListenerLp() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800834 if (!mOrientationListener.canDetectOrientation()) {
835 // If sensor is turned off or nonexistent for some reason
836 return;
837 }
838 //Could have been invoked due to screen turning on or off or
839 //change of the currently visible window's orientation
Jeff Brown3ee549c2014-09-22 20:14:39 -0700840 if (localLOGV) Slog.v(TAG, "mScreenOnEarly=" + mScreenOnEarly
841 + ", mAwake=" + mAwake + ", mCurrentAppOrientation=" + mCurrentAppOrientation
842 + ", mOrientationSensorEnabled=" + mOrientationSensorEnabled);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800843 boolean disable = true;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700844 if (mScreenOnEarly && mAwake) {
The Android Open Source Project0727d222009-03-11 12:11:58 -0700845 if (needSensorRunningLp()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800846 disable = false;
847 //enable listener if not already enabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700848 if (!mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800849 mOrientationListener.enable();
Craig Mautnereda67292013-04-28 13:50:14 -0700850 if(localLOGV) Slog.v(TAG, "Enabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800851 mOrientationSensorEnabled = true;
852 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700853 }
854 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800855 //check if sensors need to be disabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700856 if (disable && mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800857 mOrientationListener.disable();
Craig Mautnereda67292013-04-28 13:50:14 -0700858 if(localLOGV) Slog.v(TAG, "Disabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800859 mOrientationSensorEnabled = false;
860 }
861 }
862
Jeff Brown13f00f02014-10-31 14:45:50 -0700863 private void interceptPowerKeyDown(KeyEvent event, boolean interactive) {
864 // Hold a wake lock until the power key is released.
865 if (!mPowerKeyWakeLock.isHeld()) {
866 mPowerKeyWakeLock.acquire();
867 }
868
869 // Cancel multi-press detection timeout.
870 if (mPowerKeyPressCounter != 0) {
871 mHandler.removeMessages(MSG_POWER_DELAYED_PRESS);
872 }
873
874 // Detect user pressing the power button in panic when an application has
875 // taken over the whole screen.
876 boolean panic = mImmersiveModeConfirmation.onPowerKeyDown(interactive,
Craig Mautner0124980e92014-11-30 21:15:34 -0800877 SystemClock.elapsedRealtime(), isImmersiveMode(mLastSystemUiFlags));
Jeff Brown13f00f02014-10-31 14:45:50 -0700878 if (panic) {
Adrian Roosddc8b272015-05-21 16:28:27 -0700879 mHandler.post(mHiddenNavPanic);
Jeff Brown13f00f02014-10-31 14:45:50 -0700880 }
881
882 // Latch power key state to detect screenshot chord.
883 if (interactive && !mScreenshotChordPowerKeyTriggered
884 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
885 mScreenshotChordPowerKeyTriggered = true;
886 mScreenshotChordPowerKeyTime = event.getDownTime();
887 interceptScreenshotChord();
888 }
889
890 // Stop ringing or end call if configured to do so when power is pressed.
891 TelecomManager telecomManager = getTelecommService();
892 boolean hungUp = false;
893 if (telecomManager != null) {
894 if (telecomManager.isRinging()) {
895 // Pressing Power while there's a ringing incoming
896 // call should silence the ringer.
897 telecomManager.silenceRinger();
898 } else if ((mIncallPowerBehavior
899 & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0
900 && telecomManager.isInCall() && interactive) {
901 // Otherwise, if "Power button ends call" is enabled,
902 // the Power button will hang up any current active call.
903 hungUp = telecomManager.endCall();
904 }
905 }
906
907 // If the power key has still not yet been handled, then detect short
908 // press, long press, or multi press and decide what to do.
909 mPowerKeyHandled = hungUp || mScreenshotChordVolumeDownKeyTriggered
910 || mScreenshotChordVolumeUpKeyTriggered;
911 if (!mPowerKeyHandled) {
912 if (interactive) {
913 // When interactive, we're already awake.
914 // Wait for a long press or for the button to be released to decide what to do.
915 if (hasLongPressOnPowerBehavior()) {
916 Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS);
917 msg.setAsynchronous(true);
918 mHandler.sendMessageDelayed(msg,
919 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
920 }
921 } else {
Bryce Leed9268e32014-11-17 17:40:59 -0800922 wakeUpFromPowerKey(event.getDownTime());
Bryce Leed9268e32014-11-17 17:40:59 -0800923
Bryce Leed3b28402015-03-09 15:49:13 +0000924 if (mSupportLongPressPowerWhenNonInteractive && hasLongPressOnPowerBehavior()) {
925 Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS);
926 msg.setAsynchronous(true);
927 mHandler.sendMessageDelayed(msg,
928 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Bryce Leed9268e32014-11-17 17:40:59 -0800929 mBeganFromNonInteractive = true;
Bryce Leed3b28402015-03-09 15:49:13 +0000930 } else {
931 final int maxCount = getMaxMultiPressPowerCount();
932
933 if (maxCount <= 1) {
934 mPowerKeyHandled = true;
935 } else {
936 mBeganFromNonInteractive = true;
937 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700938 }
939 }
Jeff Brown4d396052010-10-29 21:50:21 -0700940 }
941 }
942
Jeff Brown13f00f02014-10-31 14:45:50 -0700943 private void interceptPowerKeyUp(KeyEvent event, boolean interactive, boolean canceled) {
944 final boolean handled = canceled || mPowerKeyHandled;
945 mScreenshotChordPowerKeyTriggered = false;
946 cancelPendingScreenshotChordAction();
947 cancelPendingPowerKeyAction();
948
949 if (!handled) {
950 // Figure out how to handle the key now that it has been released.
951 mPowerKeyPressCounter += 1;
952
953 final int maxCount = getMaxMultiPressPowerCount();
954 final long eventTime = event.getDownTime();
955 if (mPowerKeyPressCounter < maxCount) {
956 // This could be a multi-press. Wait a little bit longer to confirm.
957 // Continue holding the wake lock.
958 Message msg = mHandler.obtainMessage(MSG_POWER_DELAYED_PRESS,
959 interactive ? 1 : 0, mPowerKeyPressCounter, eventTime);
960 msg.setAsynchronous(true);
961 mHandler.sendMessageDelayed(msg, ViewConfiguration.getDoubleTapTimeout());
962 return;
963 }
964
965 // No other actions. Handle it immediately.
966 powerPress(eventTime, interactive, mPowerKeyPressCounter);
Jeff Brown4d396052010-10-29 21:50:21 -0700967 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700968
969 // Done. Reset our state.
970 finishPowerKeyPress();
971 }
972
973 private void finishPowerKeyPress() {
Bryce Leed9268e32014-11-17 17:40:59 -0800974 mBeganFromNonInteractive = false;
Jeff Brown13f00f02014-10-31 14:45:50 -0700975 mPowerKeyPressCounter = 0;
976 if (mPowerKeyWakeLock.isHeld()) {
977 mPowerKeyWakeLock.release();
978 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700979 }
980
981 private void cancelPendingPowerKeyAction() {
982 if (!mPowerKeyHandled) {
Jeff Brown13f00f02014-10-31 14:45:50 -0700983 mPowerKeyHandled = true;
984 mHandler.removeMessages(MSG_POWER_LONG_PRESS);
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700985 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700986 }
987
988 private void powerPress(long eventTime, boolean interactive, int count) {
989 if (mScreenOnEarly && !mScreenOnFully) {
990 Slog.i(TAG, "Suppressed redundant power key press while "
991 + "already in the process of turning the screen on.");
992 return;
Jeff Brownff204712011-10-25 21:27:54 -0700993 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700994
995 if (count == 2) {
996 powerMultiPressAction(eventTime, interactive, mDoublePressOnPowerBehavior);
997 } else if (count == 3) {
998 powerMultiPressAction(eventTime, interactive, mTriplePressOnPowerBehavior);
Bryce Leed9268e32014-11-17 17:40:59 -0800999 } else if (interactive && !mBeganFromNonInteractive) {
Jeff Brown13f00f02014-10-31 14:45:50 -07001000 switch (mShortPressOnPowerBehavior) {
1001 case SHORT_PRESS_POWER_NOTHING:
1002 break;
1003 case SHORT_PRESS_POWER_GO_TO_SLEEP:
1004 mPowerManager.goToSleep(eventTime,
1005 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
1006 break;
1007 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP:
1008 mPowerManager.goToSleep(eventTime,
1009 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
1010 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
1011 break;
1012 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME:
1013 mPowerManager.goToSleep(eventTime,
1014 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
1015 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
1016 launchHomeFromHotKey();
1017 break;
Bryce Lee01b0c5f2015-02-05 18:24:04 -08001018 case SHORT_PRESS_POWER_GO_HOME:
Bryce Lee662ed802015-04-10 20:11:39 +00001019 launchHomeFromHotKey(true /* awakenFromDreams */, false /*respectKeyguard*/);
Bryce Lee01b0c5f2015-02-05 18:24:04 -08001020 break;
Jeff Brown13f00f02014-10-31 14:45:50 -07001021 }
1022 }
1023 }
1024
1025 private void powerMultiPressAction(long eventTime, boolean interactive, int behavior) {
1026 switch (behavior) {
1027 case MULTI_PRESS_POWER_NOTHING:
1028 break;
1029 case MULTI_PRESS_POWER_THEATER_MODE:
1030 if (isTheaterModeEnabled()) {
1031 Slog.i(TAG, "Toggling theater mode off.");
1032 Settings.Global.putInt(mContext.getContentResolver(),
1033 Settings.Global.THEATER_MODE_ON, 0);
1034 if (!interactive) {
1035 wakeUpFromPowerKey(eventTime);
1036 }
1037 } else {
1038 Slog.i(TAG, "Toggling theater mode on.");
1039 Settings.Global.putInt(mContext.getContentResolver(),
1040 Settings.Global.THEATER_MODE_ON, 1);
Bryce Lee55e846d2014-11-04 12:43:44 -08001041
1042 if (mGoToSleepOnButtonPressTheaterMode && interactive) {
Jeff Brown13f00f02014-10-31 14:45:50 -07001043 mPowerManager.goToSleep(eventTime,
1044 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
1045 }
1046 }
1047 break;
1048 case MULTI_PRESS_POWER_BRIGHTNESS_BOOST:
Jeff Brown7b5be5e2014-11-12 18:45:31 -08001049 Slog.i(TAG, "Starting brightness boost.");
1050 if (!interactive) {
1051 wakeUpFromPowerKey(eventTime);
1052 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001053 mPowerManager.boostScreenBrightness(eventTime);
1054 break;
1055 }
1056 }
1057
1058 private int getMaxMultiPressPowerCount() {
1059 if (mTriplePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) {
1060 return 3;
1061 }
1062 if (mDoublePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) {
1063 return 2;
1064 }
1065 return 1;
1066 }
1067
1068 private void powerLongPress() {
1069 final int behavior = getResolvedLongPressOnPowerBehavior();
1070 switch (behavior) {
1071 case LONG_PRESS_POWER_NOTHING:
1072 break;
1073 case LONG_PRESS_POWER_GLOBAL_ACTIONS:
1074 mPowerKeyHandled = true;
1075 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
1076 performAuditoryFeedbackForAccessibilityIfNeed();
1077 }
1078 showGlobalActionsInternal();
1079 break;
1080 case LONG_PRESS_POWER_SHUT_OFF:
1081 case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM:
1082 mPowerKeyHandled = true;
1083 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
1084 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
1085 mWindowManagerFuncs.shutdown(behavior == LONG_PRESS_POWER_SHUT_OFF);
1086 break;
1087 }
1088 }
1089
Nick Vaccarob593a812015-05-15 11:23:05 -07001090 private void sleepPress(long eventTime) {
1091 if (mShortPressOnSleepBehavior == SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME) {
1092 launchHomeFromHotKey(false /* awakenDreams */, true /*respectKeyguard*/);
1093 }
1094 }
1095
1096 private void sleepRelease(long eventTime) {
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001097 switch (mShortPressOnSleepBehavior) {
1098 case SHORT_PRESS_SLEEP_GO_TO_SLEEP:
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001099 case SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME:
Nick Vaccarob593a812015-05-15 11:23:05 -07001100 Slog.i(TAG, "sleepRelease() calling goToSleep(GO_TO_SLEEP_REASON_SLEEP_BUTTON)");
1101 mPowerManager.goToSleep(eventTime,
1102 PowerManager.GO_TO_SLEEP_REASON_SLEEP_BUTTON, 0);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001103 break;
1104 }
1105 }
1106
Jeff Brown13f00f02014-10-31 14:45:50 -07001107 private int getResolvedLongPressOnPowerBehavior() {
1108 if (FactoryTest.isLongPressOnPowerOffEnabled()) {
1109 return LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM;
1110 }
1111 return mLongPressOnPowerBehavior;
1112 }
1113
1114 private boolean hasLongPressOnPowerBehavior() {
1115 return getResolvedLongPressOnPowerBehavior() != LONG_PRESS_POWER_NOTHING;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001116 }
1117
1118 private void interceptScreenshotChord() {
Christopher Tatee90585f2012-03-05 18:56:25 -08001119 if (mScreenshotChordEnabled
Jeff Brown13f00f02014-10-31 14:45:50 -07001120 && mScreenshotChordVolumeDownKeyTriggered && mScreenshotChordPowerKeyTriggered
1121 && !mScreenshotChordVolumeUpKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001122 final long now = SystemClock.uptimeMillis();
Jeff Brown13f00f02014-10-31 14:45:50 -07001123 if (now <= mScreenshotChordVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS
1124 && now <= mScreenshotChordPowerKeyTime
1125 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) {
1126 mScreenshotChordVolumeDownKeyConsumed = true;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001127 cancelPendingPowerKeyAction();
1128
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001129 mHandler.postDelayed(mScreenshotRunnable, getScreenshotChordLongPressDelay());
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001130 }
1131 }
1132 }
1133
Winson Chung1cea2f32012-10-08 20:42:01 -07001134 private long getScreenshotChordLongPressDelay() {
Jim Miller5ecd8112013-01-09 18:50:26 -08001135 if (mKeyguardDelegate.isShowing()) {
Winson Chung1cea2f32012-10-08 20:42:01 -07001136 // Double the time it takes to take a screenshot from the keyguard
1137 return (long) (KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER *
Justin Kohfeabd2c2014-05-02 10:02:44 -07001138 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Winson Chung1cea2f32012-10-08 20:42:01 -07001139 }
Justin Kohfeabd2c2014-05-02 10:02:44 -07001140 return ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout();
Winson Chung1cea2f32012-10-08 20:42:01 -07001141 }
1142
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001143 private void cancelPendingScreenshotChordAction() {
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001144 mHandler.removeCallbacks(mScreenshotRunnable);
Jeff Brown4d396052010-10-29 21:50:21 -07001145 }
1146
Jeff Brown13f00f02014-10-31 14:45:50 -07001147 private final Runnable mEndCallLongPress = new Runnable() {
Craig Mautnerf1b67412012-09-19 13:18:29 -07001148 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001149 public void run() {
Jeff Brown13f00f02014-10-31 14:45:50 -07001150 mEndCallKeyHandled = true;
1151 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
1152 performAuditoryFeedbackForAccessibilityIfNeed();
Joe Onoratod208e702010-10-08 16:22:43 -04001153 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001154 showGlobalActionsInternal();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001155 }
1156 };
1157
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001158 private final Runnable mScreenshotRunnable = new Runnable() {
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001159 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001160 public void run() {
1161 takeScreenshot();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001162 }
1163 };
1164
Alan Viverettee34560b22014-07-10 14:50:06 -07001165 @Override
1166 public void showGlobalActions() {
1167 mHandler.removeMessages(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
1168 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
1169 }
1170
1171 void showGlobalActionsInternal() {
1172 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001173 if (mGlobalActions == null) {
Jeff Brown7304c342012-05-11 18:42:42 -07001174 mGlobalActions = new GlobalActions(mContext, mWindowManagerFuncs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001175 }
Jim Millerab954542014-10-10 18:21:49 -07001176 final boolean keyguardShowing = isKeyguardShowingAndNotOccluded();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001177 mGlobalActions.showDialog(keyguardShowing, isDeviceProvisioned());
1178 if (keyguardShowing) {
1179 // since it took two seconds of long press to bring this up,
1180 // poke the wake lock so they have some time to see the dialog.
Jim Miller25190572013-02-28 17:36:24 -08001181 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001182 }
1183 }
1184
1185 boolean isDeviceProvisioned() {
Jeff Brownbf6f6f92012-09-25 15:03:20 -07001186 return Settings.Global.getInt(
1187 mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001188 }
1189
Maurice Lam99c6e072014-04-28 18:24:28 -07001190 boolean isUserSetupComplete() {
1191 return Settings.Secure.getIntForUser(mContext.getContentResolver(),
1192 Settings.Secure.USER_SETUP_COMPLETE, 0, UserHandle.USER_CURRENT) != 0;
1193 }
1194
Jeff Brown13f00f02014-10-31 14:45:50 -07001195 private void handleShortPressOnHome() {
1196 // If there's a dream running then use home to escape the dream
1197 // but don't actually go home.
1198 if (mDreamManagerInternal != null && mDreamManagerInternal.isDreaming()) {
1199 mDreamManagerInternal.stopDream(false /*immediate*/);
1200 return;
1201 }
1202
1203 // Go home!
1204 launchHomeFromHotKey();
1205 }
1206
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07001207 private void handleLongPressOnHome(int deviceId) {
Joe Onorato46b0d682010-11-22 17:37:27 -08001208 if (mLongPressOnHomeBehavior != LONG_PRESS_HOME_NOTHING) {
Jeff Browncaca8812013-05-09 13:34:33 -07001209 mHomeConsumed = true;
Joe Onorato46b0d682010-11-22 17:37:27 -08001210 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
Patrick Dubroyece94522011-02-23 18:35:01 -08001211
Jeff Browncaca8812013-05-09 13:34:33 -07001212 if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI) {
1213 toggleRecentApps();
1214 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_ASSIST) {
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07001215 launchAssistAction(null, deviceId);
Jim Millere6ad1a82010-08-20 19:25:39 -07001216 }
1217 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001218 }
Patrick Dubroyece94522011-02-23 18:35:01 -08001219
Jeff Browncaca8812013-05-09 13:34:33 -07001220 private void handleDoubleTapOnHome() {
1221 if (mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1222 mHomeConsumed = true;
1223 toggleRecentApps();
1224 }
1225 }
1226
1227 private final Runnable mHomeDoubleTapTimeoutRunnable = new Runnable() {
1228 @Override
1229 public void run() {
1230 if (mHomeDoubleTapPending) {
1231 mHomeDoubleTapPending = false;
Jeff Brown13f00f02014-10-31 14:45:50 -07001232 handleShortPressOnHome();
Jeff Browncaca8812013-05-09 13:34:33 -07001233 }
1234 }
1235 };
1236
Mark Renoufc1256912015-03-11 14:38:23 -04001237 private boolean isRoundWindow() {
Adam Powell01f280d2015-05-18 16:07:42 -07001238 return mContext.getResources().getConfiguration().isScreenRound();
Mark Renoufc1256912015-03-11 14:38:23 -04001239 }
1240
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001241 /** {@inheritDoc} */
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001242 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001243 public void init(Context context, IWindowManager windowManager,
Jeff Brown96307042012-07-27 15:51:34 -07001244 WindowManagerFuncs windowManagerFuncs) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001245 mContext = context;
1246 mWindowManager = windowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -07001247 mWindowManagerFuncs = windowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -07001248 mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class);
Jeff Brown061ea992015-04-17 19:55:47 -07001249 mActivityManagerInternal = LocalServices.getService(ActivityManagerInternal.class);
Jose Lima9546b202014-07-02 17:21:51 -07001250 mDreamManagerInternal = LocalServices.getService(DreamManagerInternal.class);
Mark Renoufc1256912015-03-11 14:38:23 -04001251
1252 // Init display burn-in protection
1253 boolean burnInProtectionEnabled = context.getResources().getBoolean(
1254 com.android.internal.R.bool.config_enableBurnInProtection);
1255 // Allow a system property to override this. Used by developer settings.
1256 boolean burnInProtectionDevMode =
1257 SystemProperties.getBoolean("persist.debug.force_burn_in", false);
1258 if (burnInProtectionEnabled || burnInProtectionDevMode) {
1259 final int minHorizontal;
1260 final int maxHorizontal;
1261 final int minVertical;
1262 final int maxVertical;
1263 final int maxRadius;
1264 if (burnInProtectionDevMode) {
1265 minHorizontal = -8;
1266 maxHorizontal = 8;
1267 minVertical = -8;
1268 maxVertical = -4;
1269 maxRadius = (isRoundWindow()) ? 6 : -1;
1270 } else {
1271 Resources resources = context.getResources();
1272 minHorizontal = resources.getInteger(
1273 com.android.internal.R.integer.config_burnInProtectionMinHorizontalOffset);
1274 maxHorizontal = resources.getInteger(
1275 com.android.internal.R.integer.config_burnInProtectionMaxHorizontalOffset);
1276 minVertical = resources.getInteger(
1277 com.android.internal.R.integer.config_burnInProtectionMinVerticalOffset);
1278 maxVertical = resources.getInteger(
1279 com.android.internal.R.integer.config_burnInProtectionMaxVerticalOffset);
1280 maxRadius = resources.getInteger(
1281 com.android.internal.R.integer.config_burnInProtectionMaxRadius);
1282 }
1283 mBurnInProtectionHelper = new BurnInProtectionHelper(
1284 context, minHorizontal, maxHorizontal, minVertical, maxVertical, maxRadius);
Filip Gruszczynskicfb31852015-02-25 21:47:12 +00001285 }
Craig Mautner8a0da012014-05-31 15:13:37 -07001286
Jeff Brown70825162012-03-28 17:27:48 -07001287 mHandler = new PolicyHandler();
Jeff Browna20dda42014-05-27 20:57:24 -07001288 mWakeGestureListener = new MyWakeGestureListener(mContext, mHandler);
Craig Mautnereee29c42013-01-17 14:44:34 -08001289 mOrientationListener = new MyOrientationListener(mContext, mHandler);
Jeff Brownc0347aa2011-09-23 17:26:09 -07001290 try {
1291 mOrientationListener.setCurrentRotation(windowManager.getRotation());
1292 } catch (RemoteException ex) { }
Christopher Tate5e08af02012-09-21 17:17:22 -07001293 mSettingsObserver = new SettingsObserver(mHandler);
1294 mSettingsObserver.observe();
Svetoslav683914b2015-01-15 14:22:26 -08001295 mShortcutManager = new ShortcutManager(context);
Daniel Sandler6396c722013-04-16 20:19:09 -04001296 mUiMode = context.getResources().getInteger(
1297 com.android.internal.R.integer.config_defaultUiModeType);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001298 mHomeIntent = new Intent(Intent.ACTION_MAIN, null);
1299 mHomeIntent.addCategory(Intent.CATEGORY_HOME);
1300 mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1301 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07001302 mCarDockIntent = new Intent(Intent.ACTION_MAIN, null);
1303 mCarDockIntent.addCategory(Intent.CATEGORY_CAR_DOCK);
1304 mCarDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1305 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
1306 mDeskDockIntent = new Intent(Intent.ACTION_MAIN, null);
1307 mDeskDockIntent.addCategory(Intent.CATEGORY_DESK_DOCK);
1308 mDeskDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1309 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Jim Millere6ad1a82010-08-20 19:25:39 -07001310
Jeff Brown96307042012-07-27 15:51:34 -07001311 mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
1312 mBroadcastWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001313 "PhoneWindowManager.mBroadcastWakeLock");
Jeff Brown13f00f02014-10-31 14:45:50 -07001314 mPowerKeyWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
1315 "PhoneWindowManager.mPowerKeyWakeLock");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001316 mEnableShiftMenuBugReports = "1".equals(SystemProperties.get("ro.debuggable"));
Jeff Brownbcdfc622014-03-06 19:13:04 -08001317 mSupportAutoRotation = mContext.getResources().getBoolean(
1318 com.android.internal.R.bool.config_supportAutoRotation);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001319 mLidOpenRotation = readRotation(
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001320 com.android.internal.R.integer.config_lidOpenRotation);
1321 mCarDockRotation = readRotation(
1322 com.android.internal.R.integer.config_carDockRotation);
1323 mDeskDockRotation = readRotation(
1324 com.android.internal.R.integer.config_deskDockRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001325 mUndockedHdmiRotation = readRotation(
1326 com.android.internal.R.integer.config_undockedHdmiRotation);
Mike Lockwoode9867d22009-09-20 01:59:02 -04001327 mCarDockEnablesAccelerometer = mContext.getResources().getBoolean(
1328 com.android.internal.R.bool.config_carDockEnablesAccelerometer);
1329 mDeskDockEnablesAccelerometer = mContext.getResources().getBoolean(
1330 com.android.internal.R.bool.config_deskDockEnablesAccelerometer);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001331 mLidKeyboardAccessibility = mContext.getResources().getInteger(
1332 com.android.internal.R.integer.config_lidKeyboardAccessibility);
1333 mLidNavigationAccessibility = mContext.getResources().getInteger(
1334 com.android.internal.R.integer.config_lidNavigationAccessibility);
Jeff Brownc458ce92012-04-30 14:58:40 -07001335 mLidControlsSleep = mContext.getResources().getBoolean(
1336 com.android.internal.R.bool.config_lidControlsSleep);
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04001337 mTranslucentDecorEnabled = mContext.getResources().getBoolean(
1338 com.android.internal.R.bool.config_enableTranslucentDecor);
Bryce Lee584a4452014-10-21 15:55:55 -07001339
1340 mAllowTheaterModeWakeFromKey = mContext.getResources().getBoolean(
1341 com.android.internal.R.bool.config_allowTheaterModeWakeFromKey);
1342 mAllowTheaterModeWakeFromPowerKey = mAllowTheaterModeWakeFromKey
1343 || mContext.getResources().getBoolean(
1344 com.android.internal.R.bool.config_allowTheaterModeWakeFromPowerKey);
1345 mAllowTheaterModeWakeFromMotion = mContext.getResources().getBoolean(
1346 com.android.internal.R.bool.config_allowTheaterModeWakeFromMotion);
Bryce Lee812d7022014-11-10 13:33:28 -08001347 mAllowTheaterModeWakeFromMotionWhenNotDreaming = mContext.getResources().getBoolean(
1348 com.android.internal.R.bool.config_allowTheaterModeWakeFromMotionWhenNotDreaming);
Bryce Lee584a4452014-10-21 15:55:55 -07001349 mAllowTheaterModeWakeFromCameraLens = mContext.getResources().getBoolean(
1350 com.android.internal.R.bool.config_allowTheaterModeWakeFromCameraLens);
1351 mAllowTheaterModeWakeFromLidSwitch = mContext.getResources().getBoolean(
1352 com.android.internal.R.bool.config_allowTheaterModeWakeFromLidSwitch);
1353 mAllowTheaterModeWakeFromWakeGesture = mContext.getResources().getBoolean(
1354 com.android.internal.R.bool.config_allowTheaterModeWakeFromGesture);
1355
Bryce Lee55e846d2014-11-04 12:43:44 -08001356 mGoToSleepOnButtonPressTheaterMode = mContext.getResources().getBoolean(
1357 com.android.internal.R.bool.config_goToSleepOnButtonPressTheaterMode);
1358
Bryce Leed3b28402015-03-09 15:49:13 +00001359 mSupportLongPressPowerWhenNonInteractive = mContext.getResources().getBoolean(
1360 com.android.internal.R.bool.config_supportLongPressPowerWhenNonInteractive);
1361
Jeff Brown13f00f02014-10-31 14:45:50 -07001362 mShortPressOnPowerBehavior = mContext.getResources().getInteger(
1363 com.android.internal.R.integer.config_shortPressOnPowerBehavior);
1364 mLongPressOnPowerBehavior = mContext.getResources().getInteger(
1365 com.android.internal.R.integer.config_longPressOnPowerBehavior);
1366 mDoublePressOnPowerBehavior = mContext.getResources().getInteger(
1367 com.android.internal.R.integer.config_doublePressOnPowerBehavior);
1368 mTriplePressOnPowerBehavior = mContext.getResources().getInteger(
1369 com.android.internal.R.integer.config_triplePressOnPowerBehavior);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001370 mShortPressOnSleepBehavior = mContext.getResources().getInteger(
1371 com.android.internal.R.integer.config_shortPressOnSleepBehavior);
Jeff Brown13f00f02014-10-31 14:45:50 -07001372
John Spurlock61560172015-02-06 19:46:04 -05001373 mUseTvRouting = AudioSystem.getPlatformType(mContext) == AudioSystem.PLATFORM_TELEVISION;
RoboErik001c59c2015-01-26 15:53:51 -08001374
Jeff Brownf71343d2013-05-31 17:59:11 -07001375 readConfigurationDependentBehaviors();
Jeff Browncaca8812013-05-09 13:34:33 -07001376
Svetoslav8e3feb12014-02-24 13:46:47 -08001377 mAccessibilityManager = (AccessibilityManager) context.getSystemService(
1378 Context.ACCESSIBILITY_SERVICE);
1379
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001380 // register for dock events
Dianne Hackborn78968392010-03-04 20:47:56 -08001381 IntentFilter filter = new IntentFilter();
1382 filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE);
1383 filter.addAction(UiModeManager.ACTION_EXIT_CAR_MODE);
1384 filter.addAction(UiModeManager.ACTION_ENTER_DESK_MODE);
1385 filter.addAction(UiModeManager.ACTION_EXIT_DESK_MODE);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001386 filter.addAction(Intent.ACTION_DOCK_EVENT);
1387 Intent intent = context.registerReceiver(mDockReceiver, filter);
1388 if (intent != null) {
1389 // Retrieve current sticky dock event broadcast.
1390 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
1391 Intent.EXTRA_DOCK_STATE_UNDOCKED);
1392 }
Daniel Sandler7e37df52011-11-16 22:08:23 -08001393
Jeff Brown6aaf2952012-10-05 16:01:08 -07001394 // register for dream-related broadcasts
1395 filter = new IntentFilter();
1396 filter.addAction(Intent.ACTION_DREAMING_STARTED);
1397 filter.addAction(Intent.ACTION_DREAMING_STOPPED);
1398 context.registerReceiver(mDreamReceiver, filter);
1399
Christopher Tate5e08af02012-09-21 17:17:22 -07001400 // register for multiuser-relevant broadcasts
1401 filter = new IntentFilter(Intent.ACTION_USER_SWITCHED);
1402 context.registerReceiver(mMultiuserReceiver, filter);
1403
John Spurlock57306e62013-04-22 09:48:49 -04001404 // monitor for system gestures
Craig Mautner037aa8d2013-06-07 10:35:44 -07001405 mSystemGestures = new SystemGesturesPointerEventListener(context,
1406 new SystemGesturesPointerEventListener.Callbacks() {
John Spurlock57306e62013-04-22 09:48:49 -04001407 @Override
1408 public void onSwipeFromTop() {
John Spurlock04db1762013-05-13 12:46:41 -04001409 if (mStatusBar != null) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001410 requestTransientBars(mStatusBar);
John Spurlock04db1762013-05-13 12:46:41 -04001411 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04001412 }
1413 @Override
1414 public void onSwipeFromBottom() {
John Spurlock04db1762013-05-13 12:46:41 -04001415 if (mNavigationBar != null && mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001416 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001417 }
1418 }
1419 @Override
1420 public void onSwipeFromRight() {
John Spurlock04db1762013-05-13 12:46:41 -04001421 if (mNavigationBar != null && !mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001422 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001423 }
1424 }
1425 @Override
1426 public void onDebug() {
John Spurlockd67ec252013-09-05 11:31:54 -04001427 // no-op
John Spurlockad3e6cb2013-04-30 08:47:43 -04001428 }
Adrian Roos3595be42015-03-05 16:31:15 +01001429 @Override
1430 public void onDown() {
1431 mOrientationListener.onTouchStart();
1432 }
1433 @Override
1434 public void onUpOrCancel() {
1435 mOrientationListener.onTouchEnd();
1436 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04001437 });
John Spurlockf1a36642013-10-12 17:50:42 -04001438 mImmersiveModeConfirmation = new ImmersiveModeConfirmation(mContext);
Craig Mautner037aa8d2013-06-07 10:35:44 -07001439 mWindowManagerFuncs.registerPointerEventListener(mSystemGestures);
John Spurlock32beb2c2013-03-11 10:16:47 -04001440
Jeff Brownc2346132012-04-13 01:55:38 -07001441 mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001442 mLongPressVibePattern = getLongIntArray(mContext.getResources(),
1443 com.android.internal.R.array.config_longPressVibePattern);
1444 mVirtualKeyVibePattern = getLongIntArray(mContext.getResources(),
1445 com.android.internal.R.array.config_virtualKeyVibePattern);
Amith Yamasanic33cb712010-02-10 15:21:49 -08001446 mKeyboardTapVibePattern = getLongIntArray(mContext.getResources(),
1447 com.android.internal.R.array.config_keyboardTapVibePattern);
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07001448 mClockTickVibePattern = getLongIntArray(mContext.getResources(),
1449 com.android.internal.R.array.config_clockTickVibePattern);
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07001450 mCalendarDateVibePattern = getLongIntArray(mContext.getResources(),
1451 com.android.internal.R.array.config_calendarDateVibePattern);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001452 mSafeModeDisabledVibePattern = getLongIntArray(mContext.getResources(),
1453 com.android.internal.R.array.config_safeModeDisabledVibePattern);
1454 mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(),
1455 com.android.internal.R.array.config_safeModeEnabledVibePattern);
Mady Mellore82067b2015-04-30 09:58:35 -07001456 mStylusButtonPressVibePattern = getLongIntArray(mContext.getResources(),
1457 com.android.internal.R.array.config_stylusButtonPressVibePattern);
Daniel Sandler40427442010-07-16 11:44:52 -04001458
Christopher Tatee90585f2012-03-05 18:56:25 -08001459 mScreenshotChordEnabled = mContext.getResources().getBoolean(
1460 com.android.internal.R.bool.config_enableScreenshotChord);
1461
Justin Kohd378ad72013-04-01 12:18:26 -07001462 mGlobalKeyManager = new GlobalKeyManager(mContext);
1463
Joe Onoratoea495d42011-04-06 11:41:11 -07001464 // Controls rotation and the like.
1465 initializeHdmiState();
Dianne Hackborn40011092011-09-22 13:37:48 -07001466
1467 // Match current screen state.
Craig Mautnera631d492014-08-05 15:16:01 -07001468 if (!mPowerManager.isInteractive()) {
Jeff Brown416c49c2015-05-26 19:50:18 -07001469 startedGoingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
1470 finishedGoingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
Dianne Hackborn40011092011-09-22 13:37:48 -07001471 }
Jorim Jaggi24bec7c2015-02-04 12:40:14 +01001472
1473 mWindowManagerInternal.registerAppTransitionListener(
1474 mStatusBarController.getAppTransitionListener());
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001475 }
1476
Jeff Brownf71343d2013-05-31 17:59:11 -07001477 /**
1478 * Read values from config.xml that may be overridden depending on
1479 * the configuration of the device.
1480 * eg. Disable long press on home goes to recents on sw600dp.
1481 */
1482 private void readConfigurationDependentBehaviors() {
1483 mLongPressOnHomeBehavior = mContext.getResources().getInteger(
1484 com.android.internal.R.integer.config_longPressOnHomeBehavior);
1485 if (mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING ||
1486 mLongPressOnHomeBehavior > LONG_PRESS_HOME_ASSIST) {
1487 mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1488 }
1489
1490 mDoubleTapOnHomeBehavior = mContext.getResources().getInteger(
1491 com.android.internal.R.integer.config_doubleTapOnHomeBehavior);
1492 if (mDoubleTapOnHomeBehavior < DOUBLE_TAP_HOME_NOTHING ||
1493 mDoubleTapOnHomeBehavior > DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1494 mDoubleTapOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1495 }
1496 }
1497
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001498 @Override
Dianne Hackborndde331c2012-08-03 14:01:57 -07001499 public void setInitialDisplaySize(Display display, int width, int height, int density) {
Jeff Brownef981a42013-08-07 14:13:37 -07001500 // This method might be called before the policy has been fully initialized
1501 // or for other displays we don't care about.
1502 if (mContext == null || display.getDisplayId() != Display.DEFAULT_DISPLAY) {
1503 return;
Dianne Hackbornc652de82013-02-15 16:32:56 -08001504 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001505 mDisplay = display;
1506
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001507 final Resources res = mContext.getResources();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001508 int shortSize, longSize;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001509 if (width > height) {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001510 shortSize = height;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001511 longSize = width;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001512 mLandscapeRotation = Surface.ROTATION_0;
1513 mSeascapeRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001514 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001515 mPortraitRotation = Surface.ROTATION_90;
1516 mUpsideDownRotation = Surface.ROTATION_270;
1517 } else {
1518 mPortraitRotation = Surface.ROTATION_270;
1519 mUpsideDownRotation = Surface.ROTATION_90;
1520 }
1521 } else {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001522 shortSize = width;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001523 longSize = height;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001524 mPortraitRotation = Surface.ROTATION_0;
1525 mUpsideDownRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001526 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001527 mLandscapeRotation = Surface.ROTATION_270;
1528 mSeascapeRotation = Surface.ROTATION_90;
1529 } else {
1530 mLandscapeRotation = Surface.ROTATION_90;
1531 mSeascapeRotation = Surface.ROTATION_270;
1532 }
1533 }
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001534
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001535 mStatusBarHeight =
1536 res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001537
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001538 // Height of the navigation bar when presented horizontally at bottom
1539 mNavigationBarHeightForRotation[mPortraitRotation] =
1540 mNavigationBarHeightForRotation[mUpsideDownRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001541 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_height);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001542 mNavigationBarHeightForRotation[mLandscapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001543 mNavigationBarHeightForRotation[mSeascapeRotation] = res.getDimensionPixelSize(
1544 com.android.internal.R.dimen.navigation_bar_height_landscape);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001545
1546 // Width of the navigation bar when presented vertically along one side
1547 mNavigationBarWidthForRotation[mPortraitRotation] =
1548 mNavigationBarWidthForRotation[mUpsideDownRotation] =
1549 mNavigationBarWidthForRotation[mLandscapeRotation] =
1550 mNavigationBarWidthForRotation[mSeascapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001551 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_width);
Daniel Sandler4a066c52012-04-20 14:49:13 -04001552
1553 // SystemUI (status bar) layout policy
Dianne Hackborndde331c2012-08-03 14:01:57 -07001554 int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / density;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001555 int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / density;
Daniel Sandler4a066c52012-04-20 14:49:13 -04001556
Devin Kimd7b12b42014-05-05 14:34:58 -07001557 // Allow the navigation bar to move on non-square small devices (phones).
1558 mNavigationBarCanMove = width != height && shortSizeDp < 600;
Daniel Sandler36412a72011-08-04 09:35:13 -04001559
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001560 mHasNavigationBar = res.getBoolean(com.android.internal.R.bool.config_showNavigationBar);
John Spurlock80f00c12013-06-13 11:10:51 -04001561 // Allow a system property to override this. Used by the emulator.
1562 // See also hasNavigationBar().
1563 String navBarOverride = SystemProperties.get("qemu.hw.mainkeys");
1564 if ("1".equals(navBarOverride)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001565 mHasNavigationBar = false;
John Spurlock80f00c12013-06-13 11:10:51 -04001566 } else if ("0".equals(navBarOverride)) {
1567 mHasNavigationBar = true;
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04001568 }
1569
Jeff Brown27f1d672012-10-17 18:32:34 -07001570 // For demo purposes, allow the rotation of the HDMI display to be controlled.
1571 // By default, HDMI locks rotation to landscape.
Erik Gilling9a41ef82011-09-26 19:21:03 -07001572 if ("portrait".equals(SystemProperties.get("persist.demo.hdmirotation"))) {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001573 mDemoHdmiRotation = mPortraitRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001574 } else {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001575 mDemoHdmiRotation = mLandscapeRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001576 }
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001577 mDemoHdmiRotationLock = SystemProperties.getBoolean("persist.demo.hdmirotationlock", false);
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001578
Chong Zhangae6119ff2014-11-11 18:54:39 -08001579 // For demo purposes, allow the rotation of the remote display to be controlled.
1580 // By default, remote display locks rotation to landscape.
1581 if ("portrait".equals(SystemProperties.get("persist.demo.remoterotation"))) {
1582 mDemoRotation = mPortraitRotation;
1583 } else {
1584 mDemoRotation = mLandscapeRotation;
1585 }
1586 mDemoRotationLock = SystemProperties.getBoolean(
1587 "persist.demo.rotationlock", false);
1588
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001589 // Only force the default orientation if the screen is xlarge, at least 960dp x 720dp, per
1590 // http://developer.android.com/guide/practices/screens_support.html#range
1591 mForceDefaultOrientation = longSizeDp >= 960 && shortSizeDp >= 720 &&
1592 res.getBoolean(com.android.internal.R.bool.config_forceDefaultOrientation) &&
1593 // For debug purposes the next line turns this feature off with:
1594 // $ adb shell setprop config.override_forced_orient true
1595 // $ adb shell wm size reset
1596 !"true".equals(SystemProperties.get("config.override_forced_orient"));
1597 }
1598
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001599 /**
1600 * @return whether the navigation bar can be hidden, e.g. the device has a
1601 * navigation bar and touch exploration is not enabled
1602 */
1603 private boolean canHideNavigationBar() {
Svetoslav8e3feb12014-02-24 13:46:47 -08001604 return mHasNavigationBar
1605 && !mAccessibilityManager.isTouchExplorationEnabled();
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001606 }
1607
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001608 @Override
1609 public boolean isDefaultOrientationForced() {
1610 return mForceDefaultOrientation;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001611 }
1612
Dianne Hackbornc652de82013-02-15 16:32:56 -08001613 @Override
1614 public void setDisplayOverscan(Display display, int left, int top, int right, int bottom) {
1615 if (display.getDisplayId() == Display.DEFAULT_DISPLAY) {
1616 mOverscanLeft = left;
1617 mOverscanTop = top;
1618 mOverscanRight = right;
1619 mOverscanBottom = bottom;
1620 }
1621 }
1622
Dianne Hackbornc777e072010-02-12 13:07:59 -08001623 public void updateSettings() {
1624 ContentResolver resolver = mContext.getContentResolver();
1625 boolean updateRotation = false;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001626 synchronized (mLock) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001627 mEndcallBehavior = Settings.System.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001628 Settings.System.END_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001629 Settings.System.END_BUTTON_BEHAVIOR_DEFAULT,
1630 UserHandle.USER_CURRENT);
1631 mIncallPowerBehavior = Settings.Secure.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001632 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001633 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT,
1634 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001635
Jeff Browna20dda42014-05-27 20:57:24 -07001636 // Configure wake gesture.
1637 boolean wakeGestureEnabledSetting = Settings.Secure.getIntForUser(resolver,
1638 Settings.Secure.WAKE_GESTURE_ENABLED, 0,
1639 UserHandle.USER_CURRENT) != 0;
1640 if (mWakeGestureEnabledSetting != wakeGestureEnabledSetting) {
1641 mWakeGestureEnabledSetting = wakeGestureEnabledSetting;
1642 updateWakeGestureListenerLp();
1643 }
1644
Jeff Brown207673cd2012-06-05 17:47:11 -07001645 // Configure rotation lock.
Christopher Tate5e08af02012-09-21 17:17:22 -07001646 int userRotation = Settings.System.getIntForUser(resolver,
1647 Settings.System.USER_ROTATION, Surface.ROTATION_0,
1648 UserHandle.USER_CURRENT);
Jeff Brown207673cd2012-06-05 17:47:11 -07001649 if (mUserRotation != userRotation) {
1650 mUserRotation = userRotation;
1651 updateRotation = true;
1652 }
Christopher Tate5e08af02012-09-21 17:17:22 -07001653 int userRotationMode = Settings.System.getIntForUser(resolver,
1654 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
Jeff Brown207673cd2012-06-05 17:47:11 -07001655 WindowManagerPolicy.USER_ROTATION_FREE :
1656 WindowManagerPolicy.USER_ROTATION_LOCKED;
1657 if (mUserRotationMode != userRotationMode) {
1658 mUserRotationMode = userRotationMode;
1659 updateRotation = true;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001660 updateOrientationListenerLp();
1661 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001662
Dianne Hackbornc777e072010-02-12 13:07:59 -08001663 if (mSystemReady) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001664 int pointerLocation = Settings.System.getIntForUser(resolver,
1665 Settings.System.POINTER_LOCATION, 0, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001666 if (mPointerLocationMode != pointerLocation) {
1667 mPointerLocationMode = pointerLocation;
Jeff Brown70825162012-03-28 17:27:48 -07001668 mHandler.sendEmptyMessage(pointerLocation != 0 ?
1669 MSG_ENABLE_POINTER_LOCATION : MSG_DISABLE_POINTER_LOCATION);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001670 }
1671 }
1672 // use screen off timeout setting as the timeout for the lockscreen
Christopher Tate5e08af02012-09-21 17:17:22 -07001673 mLockScreenTimeout = Settings.System.getIntForUser(resolver,
1674 Settings.System.SCREEN_OFF_TIMEOUT, 0, UserHandle.USER_CURRENT);
1675 String imId = Settings.Secure.getStringForUser(resolver,
1676 Settings.Secure.DEFAULT_INPUT_METHOD, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001677 boolean hasSoftInput = imId != null && imId.length() > 0;
1678 if (mHasSoftInput != hasSoftInput) {
1679 mHasSoftInput = hasSoftInput;
1680 updateRotation = true;
1681 }
John Spurlockf1a36642013-10-12 17:50:42 -04001682 if (mImmersiveModeConfirmation != null) {
John Spurlock4355a532014-02-19 09:49:25 -05001683 mImmersiveModeConfirmation.loadSetting(mCurrentUserId);
John Spurlockd67ec252013-09-05 11:31:54 -04001684 }
John Spurlockc6d1c602014-01-17 15:22:06 -05001685 PolicyControl.reloadFromSetting(mContext);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001686 }
1687 if (updateRotation) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07001688 updateRotation(true);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001689 }
Jeff Brown70825162012-03-28 17:27:48 -07001690 }
1691
Jeff Browna20dda42014-05-27 20:57:24 -07001692 private void updateWakeGestureListenerLp() {
1693 if (shouldEnableWakeGestureLp()) {
1694 mWakeGestureListener.requestWakeUpTrigger();
1695 } else {
1696 mWakeGestureListener.cancelWakeUpTrigger();
1697 }
1698 }
1699
1700 private boolean shouldEnableWakeGestureLp() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07001701 return mWakeGestureEnabledSetting && !mAwake
Jeff Browna20dda42014-05-27 20:57:24 -07001702 && (!mLidControlsSleep || mLidState != LID_CLOSED)
1703 && mWakeGestureListener.isSupported();
1704 }
1705
Jeff Brown70825162012-03-28 17:27:48 -07001706 private void enablePointerLocation() {
1707 if (mPointerLocationView == null) {
1708 mPointerLocationView = new PointerLocationView(mContext);
1709 mPointerLocationView.setPrintCoords(false);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001710 WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
1711 WindowManager.LayoutParams.MATCH_PARENT,
1712 WindowManager.LayoutParams.MATCH_PARENT);
Jeff Brown3b2b3542010-10-15 00:54:27 -07001713 lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001714 lp.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN
1715 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
1716 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1717 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
Jeff Brown90fc9052012-10-01 14:44:24 -07001718 if (ActivityManager.isHighEndGfx()) {
1719 lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
1720 lp.privateFlags |=
1721 WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED;
1722 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001723 lp.format = PixelFormat.TRANSLUCENT;
1724 lp.setTitle("PointerLocation");
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001725 WindowManager wm = (WindowManager)
Dianne Hackbornc777e072010-02-12 13:07:59 -08001726 mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Browncc4f7db2011-08-30 20:34:48 -07001727 lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL;
Jeff Brown70825162012-03-28 17:27:48 -07001728 wm.addView(mPointerLocationView, lp);
Michael Wrightc9c487e2013-11-07 18:55:09 -08001729 mWindowManagerFuncs.registerPointerEventListener(mPointerLocationView);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001730 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001731 }
Jeff Brown70825162012-03-28 17:27:48 -07001732
1733 private void disablePointerLocation() {
Jeff Brown70825162012-03-28 17:27:48 -07001734 if (mPointerLocationView != null) {
Michael Wrightc9c487e2013-11-07 18:55:09 -08001735 mWindowManagerFuncs.unregisterPointerEventListener(mPointerLocationView);
1736 WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Brown70825162012-03-28 17:27:48 -07001737 wm.removeView(mPointerLocationView);
1738 mPointerLocationView = null;
1739 }
1740 }
1741
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001742 private int readRotation(int resID) {
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001743 try {
1744 int rotation = mContext.getResources().getInteger(resID);
1745 switch (rotation) {
1746 case 0:
1747 return Surface.ROTATION_0;
1748 case 90:
1749 return Surface.ROTATION_90;
1750 case 180:
1751 return Surface.ROTATION_180;
1752 case 270:
1753 return Surface.ROTATION_270;
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001754 }
1755 } catch (Resources.NotFoundException e) {
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001756 // fall through
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001757 }
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001758 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001759 }
1760
1761 /** {@inheritDoc} */
Craig Mautner88400d32012-09-30 12:35:45 -07001762 @Override
Dianne Hackbornc2293022013-02-06 23:14:49 -08001763 public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001764 int type = attrs.type;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001765
1766 outAppOp[0] = AppOpsManager.OP_NONE;
1767
Wale Ogunwale74bf0652015-01-12 10:24:36 -08001768 if (!((type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW)
1769 || (type >= FIRST_SUB_WINDOW && type <= LAST_SUB_WINDOW)
1770 || (type >= FIRST_SYSTEM_WINDOW && type <= LAST_SYSTEM_WINDOW))) {
1771 return WindowManagerGlobal.ADD_INVALID_TYPE;
1772 }
1773
1774 if (type < FIRST_SYSTEM_WINDOW || type > LAST_SYSTEM_WINDOW) {
1775 // Window manager will make sure these are okay.
Jeff Brown98365d72012-08-19 20:30:52 -07001776 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001777 }
1778 String permission = null;
1779 switch (type) {
1780 case TYPE_TOAST:
1781 // XXX right now the app process has complete control over
1782 // this... should introduce a token to let the system
1783 // monitor/control what they are doing.
Jason Monk1c7c3192014-06-26 12:52:18 -04001784 outAppOp[0] = AppOpsManager.OP_TOAST_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001785 break;
Daniel Sandler7d276c32012-01-30 14:33:52 -05001786 case TYPE_DREAM:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001787 case TYPE_INPUT_METHOD:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001788 case TYPE_WALLPAPER:
keunyounga446bf02013-06-21 19:07:57 -07001789 case TYPE_PRIVATE_PRESENTATION:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001790 case TYPE_VOICE_INTERACTION:
Svetoslav3a5c7212014-10-14 09:54:26 -07001791 case TYPE_ACCESSIBILITY_OVERLAY:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001792 // The window manager will check these.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001793 break;
1794 case TYPE_PHONE:
1795 case TYPE_PRIORITY_PHONE:
1796 case TYPE_SYSTEM_ALERT:
1797 case TYPE_SYSTEM_ERROR:
1798 case TYPE_SYSTEM_OVERLAY:
1799 permission = android.Manifest.permission.SYSTEM_ALERT_WINDOW;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001800 outAppOp[0] = AppOpsManager.OP_SYSTEM_ALERT_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001801 break;
1802 default:
1803 permission = android.Manifest.permission.INTERNAL_SYSTEM_WINDOW;
1804 }
1805 if (permission != null) {
1806 if (mContext.checkCallingOrSelfPermission(permission)
1807 != PackageManager.PERMISSION_GRANTED) {
Jeff Brown98365d72012-08-19 20:30:52 -07001808 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001809 }
1810 }
Jeff Brown98365d72012-08-19 20:30:52 -07001811 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001812 }
Craig Mautner88400d32012-09-30 12:35:45 -07001813
1814 @Override
1815 public boolean checkShowToOwnerOnly(WindowManager.LayoutParams attrs) {
1816
1817 // If this switch statement is modified, modify the comment in the declarations of
1818 // the type in {@link WindowManager.LayoutParams} as well.
1819 switch (attrs.type) {
1820 default:
1821 // These are the windows that by default are shown only to the user that created
1822 // them. If this needs to be overridden, set
1823 // {@link WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS} in
1824 // {@link WindowManager.LayoutParams}. Note that permission
1825 // {@link android.Manifest.permission.INTERNAL_SYSTEM_WINDOW} is required as well.
1826 if ((attrs.privateFlags & PRIVATE_FLAG_SHOW_FOR_ALL_USERS) == 0) {
1827 return true;
1828 }
1829 break;
1830
1831 // These are the windows that by default are shown to all users. However, to
1832 // protect against spoofing, check permissions below.
1833 case TYPE_APPLICATION_STARTING:
1834 case TYPE_BOOT_PROGRESS:
1835 case TYPE_DISPLAY_OVERLAY:
Selim Cinekf83e8242015-05-19 18:08:14 -07001836 case TYPE_INPUT_CONSUMER:
Jim Miller5ecd8112013-01-09 18:50:26 -08001837 case TYPE_KEYGUARD_SCRIM:
Craig Mautner88400d32012-09-30 12:35:45 -07001838 case TYPE_KEYGUARD_DIALOG:
1839 case TYPE_MAGNIFICATION_OVERLAY:
1840 case TYPE_NAVIGATION_BAR:
1841 case TYPE_NAVIGATION_BAR_PANEL:
1842 case TYPE_PHONE:
1843 case TYPE_POINTER:
1844 case TYPE_PRIORITY_PHONE:
Craig Mautner88400d32012-09-30 12:35:45 -07001845 case TYPE_SEARCH_BAR:
1846 case TYPE_STATUS_BAR:
1847 case TYPE_STATUS_BAR_PANEL:
1848 case TYPE_STATUS_BAR_SUB_PANEL:
1849 case TYPE_SYSTEM_DIALOG:
Craig Mautner88400d32012-09-30 12:35:45 -07001850 case TYPE_VOLUME_OVERLAY:
keunyounga446bf02013-06-21 19:07:57 -07001851 case TYPE_PRIVATE_PRESENTATION:
Craig Mautner88400d32012-09-30 12:35:45 -07001852 break;
1853 }
1854
1855 // Check if third party app has set window to system window type.
1856 return mContext.checkCallingOrSelfPermission(
1857 android.Manifest.permission.INTERNAL_SYSTEM_WINDOW)
1858 != PackageManager.PERMISSION_GRANTED;
1859 }
1860
Craig Mautner967212c2013-04-13 21:10:58 -07001861 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001862 public void adjustWindowParamsLw(WindowManager.LayoutParams attrs) {
1863 switch (attrs.type) {
1864 case TYPE_SYSTEM_OVERLAY:
Jeff Brown3b2b3542010-10-15 00:54:27 -07001865 case TYPE_SECURE_SYSTEM_OVERLAY:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001866 // These types of windows can't receive input events.
1867 attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1868 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001869 attrs.flags &= ~WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001870 break;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001871 case TYPE_STATUS_BAR:
1872
1873 // If the Keyguard is in a hidden state (occluded by another window), we force to
1874 // remove the wallpaper and keyguard flag so that any change in-flight after setting
1875 // the keyguard as occluded wouldn't set these flags again.
1876 // See {@link #processKeyguardSetHiddenResultLw}.
1877 if (mKeyguardHidden) {
1878 attrs.flags &= ~WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
1879 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
1880 }
1881 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001882 }
Adrian Roos38502112014-04-09 21:04:11 +02001883
1884 if (attrs.type != TYPE_STATUS_BAR) {
1885 // The status bar is the only window allowed to exhibit keyguard behavior.
1886 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
1887 }
Adrian Roosea562512014-05-05 13:33:03 +02001888
1889 if (ActivityManager.isHighEndGfx()
1890 && (attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0) {
Adrian Roosf5e9b5c2014-09-10 15:27:41 +02001891 attrs.subtreeSystemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
Adrian Roosea562512014-05-05 13:33:03 +02001892 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
1893 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001894 }
RoboErik8a2cfc32014-05-16 11:19:38 -07001895
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001896 void readLidState() {
Jeff Brown2e7760e2012-04-11 15:14:55 -07001897 mLidState = mWindowManagerFuncs.getLidState();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001898 }
RoboErik8a2cfc32014-05-16 11:19:38 -07001899
Michael Wright3818c922014-09-02 13:59:07 -07001900 private void readCameraLensCoverState() {
1901 mCameraLensCoverState = mWindowManagerFuncs.getCameraLensCoverState();
1902 }
1903
Jeff Browndaa37532012-05-01 15:54:03 -07001904 private boolean isHidden(int accessibilityMode) {
1905 switch (accessibilityMode) {
1906 case 1:
1907 return mLidState == LID_CLOSED;
1908 case 2:
1909 return mLidState == LID_OPEN;
1910 default:
1911 return false;
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001912 }
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001913 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001914
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001915 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07001916 @Override
Jeff Browndaa37532012-05-01 15:54:03 -07001917 public void adjustConfigurationLw(Configuration config, int keyboardPresence,
1918 int navigationPresence) {
1919 mHaveBuiltInKeyboard = (keyboardPresence & PRESENCE_INTERNAL) != 0;
1920
Jeff Brownf71343d2013-05-31 17:59:11 -07001921 readConfigurationDependentBehaviors();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001922 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07001923 applyLidSwitchState();
Jeff Brownd04a88c2011-01-16 14:05:47 -08001924
Jeff Browndaa37532012-05-01 15:54:03 -07001925 if (config.keyboard == Configuration.KEYBOARD_NOKEYS
1926 || (keyboardPresence == PRESENCE_INTERNAL
1927 && isHidden(mLidKeyboardAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001928 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_YES;
Jeff Browndaa37532012-05-01 15:54:03 -07001929 if (!mHasSoftInput) {
1930 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_YES;
1931 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001932 }
1933
Jeff Browndaa37532012-05-01 15:54:03 -07001934 if (config.navigation == Configuration.NAVIGATION_NONAV
1935 || (navigationPresence == PRESENCE_INTERNAL
1936 && isHidden(mLidNavigationAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001937 config.navigationHidden = Configuration.NAVIGATIONHIDDEN_YES;
Jeff Brownd04a88c2011-01-16 14:05:47 -08001938 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001939 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001940
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001941 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07001942 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001943 public int windowTypeToLayerLw(int type) {
1944 if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001945 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001946 }
1947 switch (type) {
keunyounga446bf02013-06-21 19:07:57 -07001948 case TYPE_PRIVATE_PRESENTATION:
1949 return 2;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001950 case TYPE_WALLPAPER:
1951 // wallpaper is at the bottom, though the window manager may move it.
1952 return 2;
1953 case TYPE_PHONE:
1954 return 3;
1955 case TYPE_SEARCH_BAR:
Jorim Jaggi225d3b52015-04-01 11:18:57 -07001956 case TYPE_VOICE_INTERACTION_STARTING:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001957 return 4;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001958 case TYPE_VOICE_INTERACTION:
1959 // voice interaction layer is almost immediately above apps.
1960 return 5;
Selim Cinekf83e8242015-05-19 18:08:14 -07001961 case TYPE_INPUT_CONSUMER:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001962 return 6;
Selim Cinekf83e8242015-05-19 18:08:14 -07001963 case TYPE_SYSTEM_DIALOG:
1964 return 7;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001965 case TYPE_TOAST:
1966 // toasts and the plugged-in battery thing
Selim Cinekf83e8242015-05-19 18:08:14 -07001967 return 8;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001968 case TYPE_PRIORITY_PHONE:
1969 // SIM errors and unlock. Not sure if this really should be in a high layer.
Selim Cinekf83e8242015-05-19 18:08:14 -07001970 return 9;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001971 case TYPE_DREAM:
1972 // used for Dreams (screensavers with TYPE_DREAM windows)
Selim Cinekf83e8242015-05-19 18:08:14 -07001973 return 10;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001974 case TYPE_SYSTEM_ALERT:
1975 // like the ANR / app crashed dialogs
Selim Cinekf83e8242015-05-19 18:08:14 -07001976 return 11;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001977 case TYPE_INPUT_METHOD:
1978 // on-screen keyboards and other such input method user interfaces go here.
Selim Cinekf83e8242015-05-19 18:08:14 -07001979 return 12;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001980 case TYPE_INPUT_METHOD_DIALOG:
1981 // on-screen keyboards and other such input method user interfaces go here.
Selim Cinekf83e8242015-05-19 18:08:14 -07001982 return 13;
Jim Miller5ecd8112013-01-09 18:50:26 -08001983 case TYPE_KEYGUARD_SCRIM:
1984 // the safety window that shows behind keyguard while keyguard is starting
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001985 return 14;
Selim Cinekf83e8242015-05-19 18:08:14 -07001986 case TYPE_STATUS_BAR_SUB_PANEL:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001987 return 15;
Selim Cinekf83e8242015-05-19 18:08:14 -07001988 case TYPE_STATUS_BAR:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001989 return 16;
Selim Cinekf83e8242015-05-19 18:08:14 -07001990 case TYPE_STATUS_BAR_PANEL:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001991 return 17;
Selim Cinekf83e8242015-05-19 18:08:14 -07001992 case TYPE_KEYGUARD_DIALOG:
1993 return 18;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001994 case TYPE_VOLUME_OVERLAY:
1995 // the on-screen volume indicator and controller shown when the user
1996 // changes the device volume
Selim Cinekf83e8242015-05-19 18:08:14 -07001997 return 19;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001998 case TYPE_SYSTEM_OVERLAY:
1999 // the on-screen volume indicator and controller shown when the user
2000 // changes the device volume
Selim Cinekf83e8242015-05-19 18:08:14 -07002001 return 20;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002002 case TYPE_NAVIGATION_BAR:
2003 // the navigation bar, if available, shows atop most things
Selim Cinekf83e8242015-05-19 18:08:14 -07002004 return 21;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002005 case TYPE_NAVIGATION_BAR_PANEL:
2006 // some panels (e.g. search) need to show on top of the navigation bar
Selim Cinekf83e8242015-05-19 18:08:14 -07002007 return 22;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002008 case TYPE_SYSTEM_ERROR:
2009 // system-level error dialogs
Selim Cinekf83e8242015-05-19 18:08:14 -07002010 return 23;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002011 case TYPE_MAGNIFICATION_OVERLAY:
2012 // used to highlight the magnified portion of a display
Selim Cinekf83e8242015-05-19 18:08:14 -07002013 return 24;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002014 case TYPE_DISPLAY_OVERLAY:
2015 // used to simulate secondary display devices
Selim Cinekf83e8242015-05-19 18:08:14 -07002016 return 25;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002017 case TYPE_DRAG:
2018 // the drag layer: input for drag-and-drop is associated with this window,
2019 // which sits above all other focusable windows
Selim Cinekf83e8242015-05-19 18:08:14 -07002020 return 26;
Svetoslav3a5c7212014-10-14 09:54:26 -07002021 case TYPE_ACCESSIBILITY_OVERLAY:
2022 // overlay put by accessibility services to intercept user interaction
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002023 return 27;
Selim Cinekf83e8242015-05-19 18:08:14 -07002024 case TYPE_SECURE_SYSTEM_OVERLAY:
Svetoslav3a5c7212014-10-14 09:54:26 -07002025 return 28;
Selim Cinekf83e8242015-05-19 18:08:14 -07002026 case TYPE_BOOT_PROGRESS:
2027 return 29;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002028 case TYPE_POINTER:
2029 // the (mouse) pointer layer
Svetoslav3a5c7212014-10-14 09:54:26 -07002030 return 30;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002031 }
2032 Log.e(TAG, "Unknown window type: " + type);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002033 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002034 }
2035
2036 /** {@inheritDoc} */
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002037 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002038 public int subWindowTypeToLayerLw(int type) {
2039 switch (type) {
2040 case TYPE_APPLICATION_PANEL:
2041 case TYPE_APPLICATION_ATTACHED_DIALOG:
2042 return APPLICATION_PANEL_SUBLAYER;
2043 case TYPE_APPLICATION_MEDIA:
2044 return APPLICATION_MEDIA_SUBLAYER;
Dianne Hackborn5cb8d792009-05-21 17:34:15 -07002045 case TYPE_APPLICATION_MEDIA_OVERLAY:
2046 return APPLICATION_MEDIA_OVERLAY_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002047 case TYPE_APPLICATION_SUB_PANEL:
2048 return APPLICATION_SUB_PANEL_SUBLAYER;
Wale Ogunwale0a4dc222015-04-14 12:58:42 -07002049 case TYPE_APPLICATION_ABOVE_SUB_PANEL:
2050 return APPLICATION_ABOVE_SUB_PANEL_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002051 }
2052 Log.e(TAG, "Unknown sub-window type: " + type);
2053 return 0;
2054 }
2055
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002056 @Override
Dianne Hackbornabe0da02009-09-18 01:55:39 -07002057 public int getMaxWallpaperLayer() {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002058 return windowTypeToLayerLw(TYPE_STATUS_BAR);
Dianne Hackbornabe0da02009-09-18 01:55:39 -07002059 }
2060
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002061 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002062 public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07002063 if (mHasNavigationBar) {
2064 // For a basic navigation bar, when we are in landscape mode we place
2065 // the navigation bar to the side.
Daniel Sandler4a066c52012-04-20 14:49:13 -04002066 if (mNavigationBarCanMove && fullWidth > fullHeight) {
2067 return fullWidth - mNavigationBarWidthForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07002068 }
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002069 }
2070 return fullWidth;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002071 }
2072
Jose Lima9546b202014-07-02 17:21:51 -07002073 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002074 public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07002075 if (mHasNavigationBar) {
2076 // For a basic navigation bar, when we are in portrait mode we place
2077 // the navigation bar to the bottom.
Daniel Sandler4a066c52012-04-20 14:49:13 -04002078 if (!mNavigationBarCanMove || fullWidth < fullHeight) {
2079 return fullHeight - mNavigationBarHeightForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07002080 }
2081 }
2082 return fullHeight;
Dianne Hackborn69cb8752011-05-19 18:13:32 -07002083 }
2084
Jose Lima9546b202014-07-02 17:21:51 -07002085 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002086 public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation) {
2087 return getNonDecorDisplayWidth(fullWidth, fullHeight, rotation);
Dianne Hackborn69cb8752011-05-19 18:13:32 -07002088 }
2089
Jose Lima9546b202014-07-02 17:21:51 -07002090 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002091 public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation) {
John Spurlock80f00c12013-06-13 11:10:51 -04002092 // There is a separate status bar at the top of the display. We don't count that as part
2093 // of the fixed decor, since it can hide; however, for purposes of configurations,
Dianne Hackborn077ee852012-04-09 16:27:07 -07002094 // we do want to exclude it since applications can't generally use that part
2095 // of the screen.
John Spurlock80f00c12013-06-13 11:10:51 -04002096 return getNonDecorDisplayHeight(fullWidth, fullHeight, rotation) - mStatusBarHeight;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002097 }
2098
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002099 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07002100 public boolean isForceHiding(WindowManager.LayoutParams attrs) {
2101 return (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 ||
Jim Millerab954542014-10-10 18:21:49 -07002102 (isKeyguardHostWindow(attrs) &&
2103 (mKeyguardDelegate != null && mKeyguardDelegate.isShowing())) ||
Adrian Roos69e510d2014-07-13 14:57:59 +02002104 (attrs.type == TYPE_KEYGUARD_SCRIM);
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002105 }
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002106
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002107 @Override
Jorim Jaggi0d674622014-05-21 01:34:15 +02002108 public boolean isKeyguardHostWindow(WindowManager.LayoutParams attrs) {
2109 return attrs.type == TYPE_STATUS_BAR;
2110 }
2111
2112 @Override
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002113 public boolean canBeForceHidden(WindowState win, WindowManager.LayoutParams attrs) {
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002114 switch (attrs.type) {
2115 case TYPE_STATUS_BAR:
2116 case TYPE_NAVIGATION_BAR:
2117 case TYPE_WALLPAPER:
2118 case TYPE_DREAM:
Jim Miller5ecd8112013-01-09 18:50:26 -08002119 case TYPE_KEYGUARD_SCRIM:
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002120 return false;
2121 default:
Adrian Roos461829d2015-06-03 14:41:18 -07002122 // Hide only windows below the keyguard host window.
2123 return windowTypeToLayerLw(win.getBaseType())
2124 < windowTypeToLayerLw(TYPE_STATUS_BAR);
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002125 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002126 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002127
Craig Mautner7d7808f2014-09-11 18:02:38 -07002128 @Override
2129 public WindowState getWinShowWhenLockedLw() {
2130 return mWinShowWhenLocked;
2131 }
2132
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002133 /** {@inheritDoc} */
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002134 @Override
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07002135 public View addStartingWindow(IBinder appToken, String packageName, int theme,
2136 CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes,
Adam Powell04fe6eb2013-05-31 14:39:48 -07002137 int icon, int logo, int windowFlags) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002138 if (!SHOW_STARTING_ANIMATIONS) {
2139 return null;
2140 }
2141 if (packageName == null) {
2142 return null;
2143 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002144
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002145 WindowManager wm = null;
2146 View view = null;
2147
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002148 try {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002149 Context context = mContext;
Craig Mautner6fbda632012-07-03 09:26:39 -07002150 if (DEBUG_STARTING_WINDOW) Slog.d(TAG, "addStartingWindow " + packageName
2151 + ": nonLocalizedLabel=" + nonLocalizedLabel + " theme="
2152 + Integer.toHexString(theme));
Dianne Hackborn247fe742011-01-08 17:25:57 -08002153 if (theme != context.getThemeResId() || labelRes != 0) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002154 try {
2155 context = context.createPackageContext(packageName, 0);
Dianne Hackborn247fe742011-01-08 17:25:57 -08002156 context.setTheme(theme);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002157 } catch (PackageManager.NameNotFoundException e) {
2158 // Ignore
2159 }
2160 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002161
Jorim Jaggia16cc152015-06-01 16:55:05 -07002162 PhoneWindow win = new PhoneWindow(context);
2163 win.setIsStartingWindow(true);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002164 final TypedArray ta = win.getWindowStyle();
2165 if (ta.getBoolean(
2166 com.android.internal.R.styleable.Window_windowDisablePreview, false)
2167 || ta.getBoolean(
2168 com.android.internal.R.styleable.Window_windowShowWallpaper,false)) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002169 return null;
2170 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002171
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002172 Resources r = context.getResources();
2173 win.setTitle(r.getText(labelRes, nonLocalizedLabel));
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002174
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002175 win.setType(
2176 WindowManager.LayoutParams.TYPE_APPLICATION_STARTING);
Adrian Roos602c68e2015-04-24 16:03:47 -07002177
2178 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
2179 // Assumes it's safe to show starting windows of launched apps while
2180 // the keyguard is being hidden. This is okay because starting windows never show
2181 // secret information.
2182 if (mKeyguardHidden) {
2183 windowFlags |= FLAG_SHOW_WHEN_LOCKED;
2184 }
2185 }
2186
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002187 // Force the window flags: this is a fake window, so it is not really
2188 // touchable or focusable by the user. We also add in the ALT_FOCUSABLE_IM
2189 // flag because we do know that the next window will take input
2190 // focus, so we want to get the IME window up on top of us right away.
2191 win.setFlags(
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08002192 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002193 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
2194 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
2195 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08002196 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002197 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
2198 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
2199 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002200
Adam Powell04fe6eb2013-05-31 14:39:48 -07002201 win.setDefaultIcon(icon);
2202 win.setDefaultLogo(logo);
2203
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002204 win.setLayout(WindowManager.LayoutParams.MATCH_PARENT,
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07002205 WindowManager.LayoutParams.MATCH_PARENT);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002206
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002207 final WindowManager.LayoutParams params = win.getAttributes();
2208 params.token = appToken;
2209 params.packageName = packageName;
2210 params.windowAnimations = win.getWindowStyle().getResourceId(
2211 com.android.internal.R.styleable.Window_windowAnimationStyle, 0);
John Reck61375a82014-09-18 19:27:48 +00002212 params.privateFlags |=
2213 WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED;
Craig Mautner88400d32012-09-30 12:35:45 -07002214 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
Adam Lesinski95c42972013-10-02 10:13:27 -07002215
2216 if (!compatInfo.supportsScreen()) {
2217 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
2218 }
2219
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002220 params.setTitle("Starting " + packageName);
2221
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002222 wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
2223 view = win.getDecorView();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002224
2225 if (win.isFloating()) {
2226 // Whoops, there is no way to display an animation/preview
2227 // of such a thing! After all that work... let's skip it.
2228 // (Note that we must do this here because it is in
2229 // getDecorView() where the theme is evaluated... maybe
2230 // we should peek the floating attribute from the theme
2231 // earlier.)
2232 return null;
2233 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002234
Craig Mautner6fbda632012-07-03 09:26:39 -07002235 if (DEBUG_STARTING_WINDOW) Slog.d(
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002236 TAG, "Adding starting window for " + packageName
2237 + " / " + appToken + ": "
2238 + (view.getParent() != null ? view : null));
2239
2240 wm.addView(view, params);
2241
2242 // Only return the view if it was successfully added to the
2243 // window manager... which we can tell by it having a parent.
2244 return view.getParent() != null ? view : null;
Jeff Brown98365d72012-08-19 20:30:52 -07002245 } catch (WindowManager.BadTokenException e) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002246 // ignore
Craig Mautner42bf39e2014-02-21 16:46:22 -08002247 Log.w(TAG, appToken + " already running, starting window not displayed. " +
2248 e.getMessage());
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002249 } catch (RuntimeException e) {
2250 // don't crash if something else bad happens, for example a
2251 // failure loading resources because we are loading from an app
2252 // on external storage that has been unmounted.
2253 Log.w(TAG, appToken + " failed creating starting window", e);
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002254 } finally {
2255 if (view != null && view.getParent() == null) {
2256 Log.w(TAG, "view not successfully added to wm, removing view");
2257 wm.removeViewImmediate(view);
2258 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002259 }
2260
2261 return null;
2262 }
2263
2264 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07002265 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002266 public void removeStartingWindow(IBinder appToken, View window) {
Craig Mautner276a6eb2014-11-04 15:32:57 -08002267 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Removing starting window for " + appToken + ": "
2268 + window + " Callers=" + Debug.getCallers(4));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002269
2270 if (window != null) {
Dianne Hackborn5fd21692011-06-07 14:09:47 -07002271 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002272 wm.removeView(window);
2273 }
2274 }
2275
2276 /**
2277 * Preflight adding a window to the system.
RoboErik8a2cfc32014-05-16 11:19:38 -07002278 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002279 * Currently enforces that three window types are singletons:
2280 * <ul>
2281 * <li>STATUS_BAR_TYPE</li>
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002282 * <li>KEYGUARD_TYPE</li>
2283 * </ul>
RoboErik8a2cfc32014-05-16 11:19:38 -07002284 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002285 * @param win The window to be added
2286 * @param attrs Information about the window to be added
RoboErik8a2cfc32014-05-16 11:19:38 -07002287 *
Jeff Brown98365d72012-08-19 20:30:52 -07002288 * @return If ok, WindowManagerImpl.ADD_OKAY. If too many singletons,
2289 * WindowManagerImpl.ADD_MULTIPLE_SINGLETON
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002290 */
Jose Lima9546b202014-07-02 17:21:51 -07002291 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002292 public int prepareAddWindowLw(WindowState win, WindowManager.LayoutParams attrs) {
2293 switch (attrs.type) {
2294 case TYPE_STATUS_BAR:
Joe Onorato8bc6c512010-06-04 16:21:12 -04002295 mContext.enforceCallingOrSelfPermission(
2296 android.Manifest.permission.STATUS_BAR_SERVICE,
2297 "PhoneWindowManager");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002298 if (mStatusBar != null) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002299 if (mStatusBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07002300 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002301 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002302 }
2303 mStatusBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04002304 mStatusBarController.setWindow(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002305 break;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002306 case TYPE_NAVIGATION_BAR:
2307 mContext.enforceCallingOrSelfPermission(
2308 android.Manifest.permission.STATUS_BAR_SERVICE,
2309 "PhoneWindowManager");
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002310 if (mNavigationBar != null) {
2311 if (mNavigationBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07002312 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002313 }
2314 }
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002315 mNavigationBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04002316 mNavigationBarController.setWindow(win);
Craig Mautnereda67292013-04-28 13:50:14 -07002317 if (DEBUG_LAYOUT) Slog.i(TAG, "NAVIGATION BAR: " + mNavigationBar);
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002318 break;
Jim Millere898ac52012-04-06 17:10:57 -07002319 case TYPE_NAVIGATION_BAR_PANEL:
Dianne Hackborn08743722009-12-21 12:16:51 -08002320 case TYPE_STATUS_BAR_PANEL:
Joe Onorato29fc2c92010-11-24 10:26:50 -08002321 case TYPE_STATUS_BAR_SUB_PANEL:
Jorim Jaggi225d3b52015-04-01 11:18:57 -07002322 case TYPE_VOICE_INTERACTION_STARTING:
Joe Onorato29fc2c92010-11-24 10:26:50 -08002323 mContext.enforceCallingOrSelfPermission(
2324 android.Manifest.permission.STATUS_BAR_SERVICE,
2325 "PhoneWindowManager");
Joe Onorato29fc2c92010-11-24 10:26:50 -08002326 break;
Jim Miller5ecd8112013-01-09 18:50:26 -08002327 case TYPE_KEYGUARD_SCRIM:
Jim Miller25190572013-02-28 17:36:24 -08002328 if (mKeyguardScrim != null) {
2329 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
2330 }
Jim Miller5ecd8112013-01-09 18:50:26 -08002331 mKeyguardScrim = win;
2332 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002333 }
Jeff Brown98365d72012-08-19 20:30:52 -07002334 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002335 }
2336
2337 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07002338 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002339 public void removeWindowLw(WindowState win) {
2340 if (mStatusBar == win) {
2341 mStatusBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04002342 mStatusBarController.setWindow(null);
Jim Millerc0b676d2013-03-22 16:11:08 -07002343 mKeyguardDelegate.showScrim();
Jim Miller5ecd8112013-01-09 18:50:26 -08002344 } else if (mKeyguardScrim == win) {
2345 Log.v(TAG, "Removing keyguard scrim");
2346 mKeyguardScrim = null;
2347 } if (mNavigationBar == win) {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002348 mNavigationBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04002349 mNavigationBarController.setWindow(null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002350 }
2351 }
2352
2353 static final boolean PRINT_ANIM = false;
RoboErik8a2cfc32014-05-16 11:19:38 -07002354
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002355 /** {@inheritDoc} */
Craig Mautner4b71aa12012-12-27 17:20:01 -08002356 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002357 public int selectAnimationLw(WindowState win, int transit) {
2358 if (PRINT_ANIM) Log.i(TAG, "selectAnimation in " + win
2359 + ": transit=" + transit);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002360 if (win == mStatusBar) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002361 boolean isKeyguard = (win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002362 if (transit == TRANSIT_EXIT
2363 || transit == TRANSIT_HIDE) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002364 return isKeyguard ? -1 : R.anim.dock_top_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002365 } else if (transit == TRANSIT_ENTER
2366 || transit == TRANSIT_SHOW) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002367 return isKeyguard ? -1 : R.anim.dock_top_enter;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002368 }
2369 } else if (win == mNavigationBar) {
2370 // This can be on either the bottom or the right.
2371 if (mNavigationBarOnBottom) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08002372 if (transit == TRANSIT_EXIT
2373 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002374 return R.anim.dock_bottom_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002375 } else if (transit == TRANSIT_ENTER
2376 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002377 return R.anim.dock_bottom_enter;
2378 }
2379 } else {
Craig Mautner4b71aa12012-12-27 17:20:01 -08002380 if (transit == TRANSIT_EXIT
2381 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002382 return R.anim.dock_right_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002383 } else if (transit == TRANSIT_ENTER
2384 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002385 return R.anim.dock_right_enter;
2386 }
2387 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08002388 }
2389
2390 if (transit == TRANSIT_PREVIEW_DONE) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002391 if (win.hasAppShownWindows()) {
2392 if (PRINT_ANIM) Log.i(TAG, "**** STARTING EXIT");
2393 return com.android.internal.R.anim.app_starting_exit;
2394 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07002395 } else if (win.getAttrs().type == TYPE_DREAM && mDreamingLockscreen
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002396 && transit == TRANSIT_ENTER) {
2397 // Special case: we are animating in a dream, while the keyguard
2398 // is shown. We don't want an animation on the dream, because
2399 // we need it shown immediately with the keyguard animating away
2400 // to reveal it.
2401 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002402 }
2403
2404 return 0;
2405 }
2406
Craig Mautner3c174372013-02-21 17:54:37 -08002407 @Override
2408 public void selectRotationAnimationLw(int anim[]) {
2409 if (PRINT_ANIM) Slog.i(TAG, "selectRotationAnimation mTopFullscreen="
2410 + mTopFullscreenOpaqueWindowState + " rotationAnimation="
2411 + (mTopFullscreenOpaqueWindowState == null ?
2412 "0" : mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation));
2413 if (mTopFullscreenOpaqueWindowState != null && mTopIsFullscreen) {
2414 switch (mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation) {
2415 case ROTATION_ANIMATION_CROSSFADE:
2416 anim[0] = R.anim.rotation_animation_xfade_exit;
2417 anim[1] = R.anim.rotation_animation_enter;
2418 break;
2419 case ROTATION_ANIMATION_JUMPCUT:
2420 anim[0] = R.anim.rotation_animation_jump_exit;
2421 anim[1] = R.anim.rotation_animation_enter;
2422 break;
2423 case ROTATION_ANIMATION_ROTATE:
2424 default:
2425 anim[0] = anim[1] = 0;
2426 break;
2427 }
2428 } else {
2429 anim[0] = anim[1] = 0;
2430 }
2431 }
2432
2433 @Override
2434 public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId,
2435 boolean forceDefault) {
2436 switch (exitAnimId) {
2437 case R.anim.rotation_animation_xfade_exit:
2438 case R.anim.rotation_animation_jump_exit:
2439 // These are the only cases that matter.
2440 if (forceDefault) {
2441 return false;
2442 }
2443 int anim[] = new int[2];
2444 selectRotationAnimationLw(anim);
2445 return (exitAnimId == anim[0] && enterAnimId == anim[1]);
2446 default:
2447 return true;
2448 }
2449 }
2450
2451 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002452 public Animation createForceHideEnterAnimation(boolean onWallpaper,
2453 boolean goingToNotificationShade) {
2454 if (goingToNotificationShade) {
2455 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_behind_enter_fade_in);
Craig Mautnerb8340802014-11-04 15:32:57 -08002456 }
Craig Mautner276a6eb2014-11-04 15:32:57 -08002457
2458 AnimationSet set = (AnimationSet) AnimationUtils.loadAnimation(mContext, onWallpaper ?
2459 R.anim.lock_screen_behind_enter_wallpaper :
2460 R.anim.lock_screen_behind_enter);
2461
2462 // TODO: Use XML interpolators when we have log interpolators available in XML.
2463 final List<Animation> animations = set.getAnimations();
2464 for (int i = animations.size() - 1; i >= 0; --i) {
2465 animations.get(i).setInterpolator(mLogDecelerateInterpolator);
2466 }
2467
2468 return set;
Jorim Jaggi76a16232014-08-08 17:00:47 +02002469 }
2470
2471
2472 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002473 public Animation createForceHideWallpaperExitAnimation(boolean goingToNotificationShade) {
2474 if (goingToNotificationShade) {
2475 return null;
2476 } else {
2477 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_wallpaper_exit);
2478 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002479 }
John Spurlockc8b46ca2013-04-08 12:59:26 -04002480
2481 private static void awakenDreams() {
2482 IDreamManager dreamManager = getDreamManager();
2483 if (dreamManager != null) {
2484 try {
2485 dreamManager.awaken();
2486 } catch (RemoteException e) {
2487 // fine, stay asleep then
2488 }
2489 }
2490 }
2491
2492 static IDreamManager getDreamManager() {
2493 return IDreamManager.Stub.asInterface(
2494 ServiceManager.checkService(DreamService.DREAM_SERVICE));
2495 }
2496
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002497 TelecomManager getTelecommService() {
2498 return (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002499 }
2500
Jeff Brown4d396052010-10-29 21:50:21 -07002501 static IAudioService getAudioService() {
2502 IAudioService audioService = IAudioService.Stub.asInterface(
2503 ServiceManager.checkService(Context.AUDIO_SERVICE));
2504 if (audioService == null) {
2505 Log.w(TAG, "Unable to find IAudioService interface.");
2506 }
2507 return audioService;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002508 }
2509
2510 boolean keyguardOn() {
Jim Millerab954542014-10-10 18:21:49 -07002511 return isKeyguardShowingAndNotOccluded() || inKeyguardRestrictedKeyInputMode();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002512 }
2513
2514 private static final int[] WINDOW_TYPES_WHERE_HOME_DOESNT_WORK = {
2515 WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
2516 WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
2517 };
2518
2519 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002520 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002521 public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002522 final boolean keyguardOn = keyguardOn();
Jeff Brown1f245102010-11-18 20:53:46 -08002523 final int keyCode = event.getKeyCode();
2524 final int repeatCount = event.getRepeatCount();
2525 final int metaState = event.getMetaState();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002526 final int flags = event.getFlags();
Jeff Brown1f245102010-11-18 20:53:46 -08002527 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
2528 final boolean canceled = event.isCanceled();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002529
Jeff Brown40013652012-05-16 21:22:36 -07002530 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002531 Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount="
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002532 + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed
2533 + " canceled=" + canceled);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002534 }
2535
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002536 // If we think we might have a volume down & power key chord on the way
2537 // but we're not sure, then tell the dispatcher to wait a little while and
2538 // try again later before dispatching.
Christopher Tatee90585f2012-03-05 18:56:25 -08002539 if (mScreenshotChordEnabled && (flags & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07002540 if (mScreenshotChordVolumeDownKeyTriggered && !mScreenshotChordPowerKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002541 final long now = SystemClock.uptimeMillis();
Jeff Brown13f00f02014-10-31 14:45:50 -07002542 final long timeoutTime = mScreenshotChordVolumeDownKeyTime
2543 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002544 if (now < timeoutTime) {
2545 return timeoutTime - now;
2546 }
2547 }
2548 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
Jeff Brown13f00f02014-10-31 14:45:50 -07002549 && mScreenshotChordVolumeDownKeyConsumed) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002550 if (!down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07002551 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002552 }
2553 return -1;
2554 }
2555 }
2556
Michael Wright6a62e552014-06-03 19:19:48 -07002557 // Cancel any pending meta actions if we see any other keys being pressed between the down
2558 // of the meta key and its corresponding up.
Michael Wright251e35d2014-08-22 15:40:27 -07002559 if (mPendingMetaAction && !KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07002560 mPendingMetaAction = false;
2561 }
2562
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002563 // First we always handle the home key here, so applications
2564 // can never break it, although if keyguard is on, we do let
2565 // it handle it, because that gives us the correct 5 second
2566 // timeout.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002567 if (keyCode == KeyEvent.KEYCODE_HOME) {
Michael Jurka7f2668c2012-03-27 07:49:52 -07002568
Jeff Brown49ed71d2010-12-06 17:13:33 -08002569 // If we have released the home key, and didn't do anything else
2570 // while it was pressed, then it is time to go home!
Michael Jurka7f2668c2012-03-27 07:49:52 -07002571 if (!down) {
Jeff Browncaca8812013-05-09 13:34:33 -07002572 cancelPreloadRecentApps();
2573
Jeff Brown49ed71d2010-12-06 17:13:33 -08002574 mHomePressed = false;
Jeff Browncaca8812013-05-09 13:34:33 -07002575 if (mHomeConsumed) {
2576 mHomeConsumed = false;
Michael Jurka7f2668c2012-03-27 07:49:52 -07002577 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002578 }
Jeff Browncaca8812013-05-09 13:34:33 -07002579
2580 if (canceled) {
2581 Log.i(TAG, "Ignoring HOME; event canceled.");
2582 return -1;
2583 }
2584
Yorke Lee4f803242014-12-15 23:22:06 +00002585 // If an incoming call is ringing, HOME is totally disabled.
2586 // (The user is already on the InCallUI at this point,
2587 // and his ONLY options are to answer or reject the call.)
2588 TelecomManager telecomManager = getTelecommService();
2589 if (telecomManager != null && telecomManager.isRinging()) {
2590 Log.i(TAG, "Ignoring HOME; there's a ringing incoming call.");
2591 return -1;
2592 }
2593
Jeff Browncaca8812013-05-09 13:34:33 -07002594 // Delay handling home if a double-tap is possible.
2595 if (mDoubleTapOnHomeBehavior != DOUBLE_TAP_HOME_NOTHING) {
2596 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); // just in case
2597 mHomeDoubleTapPending = true;
2598 mHandler.postDelayed(mHomeDoubleTapTimeoutRunnable,
2599 ViewConfiguration.getDoubleTapTimeout());
2600 return -1;
2601 }
2602
Jeff Brown13f00f02014-10-31 14:45:50 -07002603 handleShortPressOnHome();
Jeff Browncaca8812013-05-09 13:34:33 -07002604 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002605 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002606
2607 // If a system window has focus, then it doesn't make sense
2608 // right now to interact with applications.
2609 WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null;
2610 if (attrs != null) {
2611 final int type = attrs.type;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002612 if (type == WindowManager.LayoutParams.TYPE_KEYGUARD_SCRIM
2613 || type == WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG
2614 || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002615 // the "app" is keyguard, so give it the key
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002616 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002617 }
2618 final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length;
2619 for (int i=0; i<typeCount; i++) {
2620 if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) {
2621 // don't do anything, but also don't pass it to the app
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002622 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002623 }
2624 }
2625 }
Jeff Browncaca8812013-05-09 13:34:33 -07002626
2627 // Remember that home is pressed and handle special actions.
2628 if (repeatCount == 0) {
2629 mHomePressed = true;
2630 if (mHomeDoubleTapPending) {
2631 mHomeDoubleTapPending = false;
2632 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable);
2633 handleDoubleTapOnHome();
2634 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI
2635 || mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
2636 preloadRecentApps();
Michael Jurka7f2668c2012-03-27 07:49:52 -07002637 }
Jeff Browncaca8812013-05-09 13:34:33 -07002638 } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) {
2639 if (!keyguardOn) {
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07002640 handleLongPressOnHome(event.getDeviceId());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002641 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002642 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002643 return -1;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002644 } else if (keyCode == KeyEvent.KEYCODE_MENU) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002645 // Hijack modified menu keys for debugging features
2646 final int chordBug = KeyEvent.META_SHIFT_ON;
2647
2648 if (down && repeatCount == 0) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002649 if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002650 Intent intent = new Intent(Intent.ACTION_BUG_REPORT);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002651 mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT,
2652 null, null, null, 0, null, null);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002653 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002654 } else if (SHOW_PROCESSES_ON_ALT_MENU &&
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002655 (metaState & KeyEvent.META_ALT_ON) == KeyEvent.META_ALT_ON) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002656 Intent service = new Intent();
2657 service.setClassName(mContext, "com.android.server.LoadAverageService");
2658 ContentResolver res = mContext.getContentResolver();
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002659 boolean shown = Settings.Global.getInt(
2660 res, Settings.Global.SHOW_PROCESSES, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002661 if (!shown) {
2662 mContext.startService(service);
2663 } else {
2664 mContext.stopService(service);
2665 }
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002666 Settings.Global.putInt(
2667 res, Settings.Global.SHOW_PROCESSES, shown ? 0 : 1);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002668 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002669 }
2670 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002671 } else if (keyCode == KeyEvent.KEYCODE_SEARCH) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002672 if (down) {
2673 if (repeatCount == 0) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002674 mSearchKeyShortcutPending = true;
2675 mConsumeSearchKeyUp = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002676 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002677 } else {
2678 mSearchKeyShortcutPending = false;
2679 if (mConsumeSearchKeyUp) {
2680 mConsumeSearchKeyUp = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002681 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002682 }
2683 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002684 return 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002685 } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) {
Michael Wrightc9ebea72013-01-16 19:25:02 -08002686 if (!keyguardOn) {
Jeff Browncaca8812013-05-09 13:34:33 -07002687 if (down && repeatCount == 0) {
2688 preloadRecentApps();
2689 } else if (!down) {
2690 toggleRecentApps();
Michael Wrightc9ebea72013-01-16 19:25:02 -08002691 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002692 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002693 return -1;
Jun Mukaid21b3c82015-04-23 14:09:34 -07002694 } else if (keyCode == KeyEvent.KEYCODE_N && event.isMetaPressed()) {
2695 if (down) {
2696 IStatusBarService service = getStatusBarService();
2697 if (service != null) {
2698 try {
2699 service.expandNotificationsPanel();
2700 } catch (RemoteException e) {
2701 // do nothing.
2702 }
2703 }
2704 }
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002705 } else if (keyCode == KeyEvent.KEYCODE_ASSIST) {
2706 if (down) {
2707 if (repeatCount == 0) {
2708 mAssistKeyLongPressed = false;
2709 } else if (repeatCount == 1) {
2710 mAssistKeyLongPressed = true;
2711 if (!keyguardOn) {
2712 launchAssistLongPressAction();
2713 }
2714 }
2715 } else {
2716 if (mAssistKeyLongPressed) {
2717 mAssistKeyLongPressed = false;
2718 } else {
2719 if (!keyguardOn) {
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07002720 launchAssistAction(null, event.getDeviceId());
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002721 }
2722 }
2723 }
2724 return -1;
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002725 } else if (keyCode == KeyEvent.KEYCODE_VOICE_ASSIST) {
2726 if (!down) {
2727 Intent voiceIntent;
Michael Wright869a67c2014-08-26 19:33:06 -07002728 if (!keyguardOn) {
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002729 voiceIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
2730 } else {
2731 voiceIntent = new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
Michael Wright869a67c2014-08-26 19:33:06 -07002732 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, true);
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002733 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00002734 startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002735 }
Jeff Sharkey2991fa32012-12-05 18:06:43 -08002736 } else if (keyCode == KeyEvent.KEYCODE_SYSRQ) {
2737 if (down && repeatCount == 0) {
2738 mHandler.post(mScreenshotRunnable);
2739 }
2740 return -1;
Michael Wrightb854e242013-02-05 17:54:02 -08002741 } else if (keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP
2742 || keyCode == KeyEvent.KEYCODE_BRIGHTNESS_DOWN) {
2743 if (down) {
2744 int direction = keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP ? 1 : -1;
2745
2746 // Disable autobrightness if it's on
2747 int auto = Settings.System.getIntForUser(
2748 mContext.getContentResolver(),
2749 Settings.System.SCREEN_BRIGHTNESS_MODE,
2750 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2751 UserHandle.USER_CURRENT_OR_SELF);
2752 if (auto != 0) {
2753 Settings.System.putIntForUser(mContext.getContentResolver(),
2754 Settings.System.SCREEN_BRIGHTNESS_MODE,
2755 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2756 UserHandle.USER_CURRENT_OR_SELF);
2757 }
2758
2759 int min = mPowerManager.getMinimumScreenBrightnessSetting();
2760 int max = mPowerManager.getMaximumScreenBrightnessSetting();
2761 int step = (max - min + BRIGHTNESS_STEPS - 1) / BRIGHTNESS_STEPS * direction;
2762 int brightness = Settings.System.getIntForUser(mContext.getContentResolver(),
2763 Settings.System.SCREEN_BRIGHTNESS,
2764 mPowerManager.getDefaultScreenBrightnessSetting(),
2765 UserHandle.USER_CURRENT_OR_SELF);
2766 brightness += step;
2767 // Make sure we don't go beyond the limits.
2768 brightness = Math.min(max, brightness);
2769 brightness = Math.max(min, brightness);
2770
2771 Settings.System.putIntForUser(mContext.getContentResolver(),
2772 Settings.System.SCREEN_BRIGHTNESS, brightness,
2773 UserHandle.USER_CURRENT_OR_SELF);
Bart Sears8b1c27c2015-03-18 23:51:02 +00002774 startActivityAsUser(new Intent(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG),
Alan Viverette5a399492014-07-14 16:19:38 -07002775 UserHandle.CURRENT_OR_SELF);
Michael Wrightb854e242013-02-05 17:54:02 -08002776 }
2777 return -1;
Michael Wrightce0c13a2014-07-30 10:49:21 -07002778 } else if (KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07002779 if (down) {
2780 mPendingMetaAction = true;
2781 } else if (mPendingMetaAction) {
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07002782 launchAssistAction(Intent.EXTRA_ASSIST_INPUT_HINT_KEYBOARD, event.getDeviceId());
Michael Wright6a62e552014-06-03 19:19:48 -07002783 }
2784 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002785 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002786
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002787 // Shortcuts are invoked through Search+key, so intercept those here
Jeff Browncaab4d02010-12-09 22:13:41 -08002788 // Any printing key that is chorded with Search should be consumed
2789 // even if no shortcut was invoked. This prevents text from being
2790 // inadvertently inserted when using a keyboard that has built-in macro
2791 // shortcut keys (that emit Search+x) and some of them are not registered.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002792 if (mSearchKeyShortcutPending) {
Jeff Browncaab4d02010-12-09 22:13:41 -08002793 final KeyCharacterMap kcm = event.getKeyCharacterMap();
2794 if (kcm.isPrintingKey(keyCode)) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002795 mConsumeSearchKeyUp = true;
2796 mSearchKeyShortcutPending = false;
Jeff Browncaab4d02010-12-09 22:13:41 -08002797 if (down && repeatCount == 0 && !keyguardOn) {
2798 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState);
2799 if (shortcutIntent != null) {
2800 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002801 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00002802 startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002803 } catch (ActivityNotFoundException ex) {
2804 Slog.w(TAG, "Dropping shortcut key combination because "
2805 + "the activity to which it is registered was not found: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002806 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode), ex);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002807 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002808 } else {
2809 Slog.i(TAG, "Dropping unregistered shortcut key combination: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002810 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002811 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002812 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002813 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002814 }
2815 }
2816
Jeff Brown68b909d2011-12-07 16:36:01 -08002817 // Invoke shortcuts using Meta.
Jeff Brown602ab322012-05-16 13:33:47 -07002818 if (down && repeatCount == 0 && !keyguardOn
Jeff Brown68b909d2011-12-07 16:36:01 -08002819 && (metaState & KeyEvent.META_META_ON) != 0) {
2820 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brown602ab322012-05-16 13:33:47 -07002821 if (kcm.isPrintingKey(keyCode)) {
2822 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode,
2823 metaState & ~(KeyEvent.META_META_ON
2824 | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON));
2825 if (shortcutIntent != null) {
2826 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2827 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00002828 startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brown602ab322012-05-16 13:33:47 -07002829 } catch (ActivityNotFoundException ex) {
2830 Slog.w(TAG, "Dropping shortcut key combination because "
2831 + "the activity to which it is registered was not found: "
2832 + "META+" + KeyEvent.keyCodeToString(keyCode), ex);
2833 }
2834 return -1;
Jeff Brown68b909d2011-12-07 16:36:01 -08002835 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002836 }
2837 }
2838
Jeff Brown6651a632011-11-28 12:59:11 -08002839 // Handle application launch keys.
Jeff Brown602ab322012-05-16 13:33:47 -07002840 if (down && repeatCount == 0 && !keyguardOn) {
Jeff Brown6651a632011-11-28 12:59:11 -08002841 String category = sApplicationLaunchKeyCategories.get(keyCode);
2842 if (category != null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -08002843 Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category);
Jeff Brown6651a632011-11-28 12:59:11 -08002844 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2845 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00002846 startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brown6651a632011-11-28 12:59:11 -08002847 } catch (ActivityNotFoundException ex) {
2848 Slog.w(TAG, "Dropping application launch key because "
2849 + "the activity to which it is registered was not found: "
2850 + "keyCode=" + keyCode + ", category=" + category, ex);
2851 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002852 return -1;
Jeff Brown6651a632011-11-28 12:59:11 -08002853 }
2854 }
2855
Michael Wright61c46752014-08-21 16:57:33 -07002856 // Display task switcher for ALT-TAB.
Jeff Brown68b909d2011-12-07 16:36:01 -08002857 if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_TAB) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002858 if (mRecentAppsHeldModifiers == 0 && !keyguardOn) {
Jeff Brown68b909d2011-12-07 16:36:01 -08002859 final int shiftlessModifiers = event.getModifiers() & ~KeyEvent.META_SHIFT_MASK;
Michael Wright61c46752014-08-21 16:57:33 -07002860 if (KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_ALT_ON)) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002861 mRecentAppsHeldModifiers = shiftlessModifiers;
2862 showRecentApps(true);
Jeff Brown68b909d2011-12-07 16:36:01 -08002863 return -1;
2864 }
2865 }
Winson Chung1e8d71b2014-05-16 17:05:22 -07002866 } else if (!down && mRecentAppsHeldModifiers != 0
2867 && (metaState & mRecentAppsHeldModifiers) == 0) {
2868 mRecentAppsHeldModifiers = 0;
Winson Chungcdcd4872014-08-05 18:00:13 -07002869 hideRecentApps(true, false);
Jeff Brown68b909d2011-12-07 16:36:01 -08002870 }
2871
Jeff Browncf39bdf2012-05-18 14:41:19 -07002872 // Handle keyboard language switching.
2873 if (down && repeatCount == 0
2874 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2875 || (keyCode == KeyEvent.KEYCODE_SPACE
2876 && (metaState & KeyEvent.META_CTRL_MASK) != 0))) {
2877 int direction = (metaState & KeyEvent.META_SHIFT_MASK) != 0 ? -1 : 1;
2878 mWindowManagerFuncs.switchKeyboardLayout(event.getDeviceId(), direction);
2879 return -1;
2880 }
2881 if (mLanguageSwitchKeyPressed && !down
2882 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2883 || keyCode == KeyEvent.KEYCODE_SPACE)) {
2884 mLanguageSwitchKeyPressed = false;
2885 return -1;
2886 }
2887
Jeff Brown13f00f02014-10-31 14:45:50 -07002888 if (isValidGlobalKey(keyCode)
2889 && mGlobalKeyManager.handleGlobalKey(mContext, keyCode, event)) {
Justin Kohd378ad72013-04-01 12:18:26 -07002890 return -1;
2891 }
2892
Michael Wright6a62e552014-06-03 19:19:48 -07002893 // Reserve all the META modifier combos for system behavior
Michael Wrightce0c13a2014-07-30 10:49:21 -07002894 if ((metaState & KeyEvent.META_META_ON) != 0) {
Michael Wright6a62e552014-06-03 19:19:48 -07002895 return -1;
2896 }
2897
Jeff Brown68b909d2011-12-07 16:36:01 -08002898 // Let the application handle the key.
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002899 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002900 }
2901
Jeff Brown3915bb82010-11-05 15:02:16 -07002902 /** {@inheritDoc} */
2903 @Override
Jeff Brown49ed71d2010-12-06 17:13:33 -08002904 public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown54875002011-04-06 15:33:01 -07002905 // Note: This method is only called if the initial down was unhandled.
Jeff Brown40013652012-05-16 21:22:36 -07002906 if (DEBUG_INPUT) {
Jeff Brown1f245102010-11-18 20:53:46 -08002907 Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction()
2908 + ", flags=" + event.getFlags()
2909 + ", keyCode=" + event.getKeyCode()
2910 + ", scanCode=" + event.getScanCode()
2911 + ", metaState=" + event.getMetaState()
2912 + ", repeatCount=" + event.getRepeatCount()
2913 + ", policyFlags=" + policyFlags);
Jeff Brown3915bb82010-11-05 15:02:16 -07002914 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002915
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002916 KeyEvent fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002917 if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
2918 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002919 final int keyCode = event.getKeyCode();
2920 final int metaState = event.getMetaState();
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002921 final boolean initialDown = event.getAction() == KeyEvent.ACTION_DOWN
2922 && event.getRepeatCount() == 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002923
Jeff Brown54875002011-04-06 15:33:01 -07002924 // Check for fallback actions specified by the key character map.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002925 final FallbackAction fallbackAction;
2926 if (initialDown) {
2927 fallbackAction = kcm.getFallbackAction(keyCode, metaState);
2928 } else {
2929 fallbackAction = mFallbackActions.get(keyCode);
2930 }
2931
2932 if (fallbackAction != null) {
Jeff Brown40013652012-05-16 21:22:36 -07002933 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002934 Slog.d(TAG, "Fallback: keyCode=" + fallbackAction.keyCode
2935 + " metaState=" + Integer.toHexString(fallbackAction.metaState));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002936 }
2937
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002938 final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK;
2939 fallbackEvent = KeyEvent.obtain(
Jeff Brown49ed71d2010-12-06 17:13:33 -08002940 event.getDownTime(), event.getEventTime(),
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002941 event.getAction(), fallbackAction.keyCode,
2942 event.getRepeatCount(), fallbackAction.metaState,
Jeff Brown49ed71d2010-12-06 17:13:33 -08002943 event.getDeviceId(), event.getScanCode(),
2944 flags, event.getSource(), null);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002945
2946 if (!interceptFallback(win, fallbackEvent, policyFlags)) {
2947 fallbackEvent.recycle();
2948 fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002949 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002950
2951 if (initialDown) {
2952 mFallbackActions.put(keyCode, fallbackAction);
2953 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2954 mFallbackActions.remove(keyCode);
2955 fallbackAction.recycle();
2956 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002957 }
2958 }
2959
Jeff Brown40013652012-05-16 21:22:36 -07002960 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002961 if (fallbackEvent == null) {
2962 Slog.d(TAG, "No fallback.");
2963 } else {
2964 Slog.d(TAG, "Performing fallback: " + fallbackEvent);
2965 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002966 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002967 return fallbackEvent;
Jeff Brown3915bb82010-11-05 15:02:16 -07002968 }
2969
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002970 private boolean interceptFallback(WindowState win, KeyEvent fallbackEvent, int policyFlags) {
Jeff Brown037c33e2014-04-09 00:31:55 -07002971 int actions = interceptKeyBeforeQueueing(fallbackEvent, policyFlags);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002972 if ((actions & ACTION_PASS_TO_USER) != 0) {
2973 long delayMillis = interceptKeyBeforeDispatching(
2974 win, fallbackEvent, policyFlags);
2975 if (delayMillis == 0) {
2976 return true;
2977 }
2978 }
2979 return false;
Jeff Brown6f2fba42011-02-19 01:08:02 -08002980 }
2981
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002982 private void launchAssistLongPressAction() {
2983 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
2984 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
2985
2986 // launch the search activity
2987 Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS);
2988 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2989 try {
RoboErik8a2cfc32014-05-16 11:19:38 -07002990 // TODO: This only stops the factory-installed search manager.
Jim Miller45308b12012-06-18 19:23:39 -07002991 // Need to formalize an API to handle others
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002992 SearchManager searchManager = getSearchManager();
2993 if (searchManager != null) {
2994 searchManager.stopSearch();
2995 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00002996 startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002997 } catch (ActivityNotFoundException e) {
2998 Slog.w(TAG, "No activity to handle assist long press action.", e);
2999 }
3000 }
3001
3002 private void launchAssistAction() {
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07003003 launchAssistAction(null, Integer.MIN_VALUE);
Michael Wright8ab940a2014-09-01 11:01:27 -07003004 }
3005
3006 private void launchAssistAction(String hint) {
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07003007 launchAssistAction(hint, Integer.MIN_VALUE);
3008 }
3009
3010 private void launchAssistAction(String hint, int deviceId) {
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003011 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07003012 Bundle args = null;
3013 if (deviceId > Integer.MIN_VALUE) {
3014 args = new Bundle();
3015 args.putInt(Intent.EXTRA_ASSIST_INPUT_DEVICE_ID, deviceId);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003016 }
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07003017 ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE))
3018 .launchAssistAction(hint, UserHandle.myUserId(), args);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003019 }
3020
Bart Sears8b1c27c2015-03-18 23:51:02 +00003021 private void startActivityAsUser(Intent intent, UserHandle handle) {
3022 if (isUserSetupComplete()) {
3023 mContext.startActivityAsUser(intent, handle);
3024 } else {
3025 Slog.i(TAG, "Not starting activity because user setup is in progress: " + intent);
3026 }
3027 }
3028
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003029 private SearchManager getSearchManager() {
3030 if (mSearchManager == null) {
3031 mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
3032 }
3033 return mSearchManager;
3034 }
3035
Jeff Browncaca8812013-05-09 13:34:33 -07003036 private void preloadRecentApps() {
3037 mPreloadedRecentApps = true;
3038 try {
3039 IStatusBarService statusbar = getStatusBarService();
3040 if (statusbar != null) {
3041 statusbar.preloadRecentApps();
3042 }
3043 } catch (RemoteException e) {
3044 Slog.e(TAG, "RemoteException when preloading recent apps", e);
3045 // re-acquire status bar service next time it is needed.
3046 mStatusBarService = null;
3047 }
3048 }
3049
3050 private void cancelPreloadRecentApps() {
3051 if (mPreloadedRecentApps) {
3052 mPreloadedRecentApps = false;
3053 try {
3054 IStatusBarService statusbar = getStatusBarService();
3055 if (statusbar != null) {
3056 statusbar.cancelPreloadRecentApps();
3057 }
3058 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003059 Slog.e(TAG, "RemoteException when cancelling recent apps preload", e);
Jeff Browncaca8812013-05-09 13:34:33 -07003060 // re-acquire status bar service next time it is needed.
3061 mStatusBarService = null;
3062 }
3063 }
3064 }
3065
3066 private void toggleRecentApps() {
3067 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
Jeff Browncaca8812013-05-09 13:34:33 -07003068 try {
3069 IStatusBarService statusbar = getStatusBarService();
3070 if (statusbar != null) {
3071 statusbar.toggleRecentApps();
3072 }
3073 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003074 Slog.e(TAG, "RemoteException when toggling recent apps", e);
3075 // re-acquire status bar service next time it is needed.
3076 mStatusBarService = null;
3077 }
3078 }
3079
Craig Mautner84984fa2014-06-19 11:19:20 -07003080 @Override
3081 public void showRecentApps() {
3082 mHandler.removeMessages(MSG_DISPATCH_SHOW_RECENTS);
3083 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_RECENTS);
3084 }
3085
Winson Chung1e8d71b2014-05-16 17:05:22 -07003086 private void showRecentApps(boolean triggeredFromAltTab) {
3087 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
3088 try {
3089 IStatusBarService statusbar = getStatusBarService();
3090 if (statusbar != null) {
3091 statusbar.showRecentApps(triggeredFromAltTab);
3092 }
3093 } catch (RemoteException e) {
Jeff Browncaca8812013-05-09 13:34:33 -07003094 Slog.e(TAG, "RemoteException when showing recent apps", e);
3095 // re-acquire status bar service next time it is needed.
3096 mStatusBarService = null;
3097 }
3098 }
3099
Winson Chungcdcd4872014-08-05 18:00:13 -07003100 private void hideRecentApps(boolean triggeredFromAltTab, boolean triggeredFromHome) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003101 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
3102 try {
3103 IStatusBarService statusbar = getStatusBarService();
3104 if (statusbar != null) {
Winson Chungcdcd4872014-08-05 18:00:13 -07003105 statusbar.hideRecentApps(triggeredFromAltTab, triggeredFromHome);
Winson Chung1e8d71b2014-05-16 17:05:22 -07003106 }
3107 } catch (RemoteException e) {
3108 Slog.e(TAG, "RemoteException when closing recent apps", e);
3109 // re-acquire status bar service next time it is needed.
3110 mStatusBarService = null;
3111 }
3112 }
3113
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00003114 void launchHomeFromHotKey() {
Bryce Lee662ed802015-04-10 20:11:39 +00003115 launchHomeFromHotKey(true /* awakenFromDreams */, true /*respectKeyguard*/);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00003116 }
3117
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003118 /**
3119 * A home key -> launch home action was detected. Take the appropriate action
3120 * given the situation with the keyguard.
3121 */
Bryce Lee662ed802015-04-10 20:11:39 +00003122 void launchHomeFromHotKey(final boolean awakenFromDreams, final boolean respectKeyguard) {
3123 if (respectKeyguard) {
3124 if (isKeyguardShowingAndNotOccluded()) {
3125 // don't launch home if keyguard showing
3126 return;
3127 }
3128
3129 if (!mHideLockScreen && mKeyguardDelegate.isInputRestricted()) {
3130 // when in keyguard restricted mode, must first verify unlock
3131 // before launching home
3132 mKeyguardDelegate.verifyUnlock(new OnKeyguardExitResult() {
3133 @Override
3134 public void onKeyguardExitResult(boolean success) {
3135 if (success) {
3136 try {
3137 ActivityManagerNative.getDefault().stopAppSwitches();
3138 } catch (RemoteException e) {
3139 }
3140 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3141 startDockOrHome(true /*fromHomeKey*/, awakenFromDreams);
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07003142 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003143 }
Bryce Lee662ed802015-04-10 20:11:39 +00003144 });
3145 return;
3146 }
3147 }
3148
3149 // no keyguard stuff to worry about, just launch home!
3150 try {
3151 ActivityManagerNative.getDefault().stopAppSwitches();
3152 } catch (RemoteException e) {
3153 }
3154 if (mRecentsVisible) {
3155 // Hide Recents and notify it to launch Home
3156 if (awakenFromDreams) {
3157 awakenDreams();
3158 }
3159 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3160 hideRecentApps(false, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003161 } else {
Bryce Lee662ed802015-04-10 20:11:39 +00003162 // Otherwise, just launch Home
3163 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3164 startDockOrHome(true /*fromHomeKey*/, awakenFromDreams);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003165 }
3166 }
3167
John Spurlock04db1762013-05-13 12:46:41 -04003168 private final Runnable mClearHideNavigationFlag = new Runnable() {
3169 @Override
3170 public void run() {
3171 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
3172 // Clear flags.
3173 mForceClearedSystemUiFlags &=
3174 ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
3175 }
3176 mWindowManagerFuncs.reevaluateStatusBarVisibility();
Dianne Hackborne26ab702011-10-16 13:21:33 -07003177 }
3178 };
3179
3180 /**
3181 * Input handler used while nav bar is hidden. Captures any touch on the screen,
3182 * to determine when the nav bar should be shown and prevent applications from
3183 * receiving those touches.
3184 */
Jeff Brown32cbc38552011-12-01 14:01:49 -08003185 final class HideNavInputEventReceiver extends InputEventReceiver {
3186 public HideNavInputEventReceiver(InputChannel inputChannel, Looper looper) {
3187 super(inputChannel, looper);
3188 }
3189
Dianne Hackborndf89e652011-10-06 22:35:11 -07003190 @Override
Jeff Brown32cbc38552011-12-01 14:01:49 -08003191 public void onInputEvent(InputEvent event) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003192 boolean handled = false;
3193 try {
Jeff Brown4952dfd2011-11-30 19:23:22 -08003194 if (event instanceof MotionEvent
3195 && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
3196 final MotionEvent motionEvent = (MotionEvent)event;
3197 if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003198 // When the user taps down, we re-show the nav bar.
3199 boolean changed = false;
John Spurlock04db1762013-05-13 12:46:41 -04003200 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003201 // Any user activity always causes us to show the
3202 // navigation controls, if they had been hidden.
3203 // We also clear the low profile and only content
3204 // flags so that tapping on the screen will atomically
3205 // restore all currently hidden screen decorations.
3206 int newVal = mResettingSystemUiFlags |
3207 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
3208 View.SYSTEM_UI_FLAG_LOW_PROFILE |
3209 View.SYSTEM_UI_FLAG_FULLSCREEN;
Dianne Hackborne26ab702011-10-16 13:21:33 -07003210 if (mResettingSystemUiFlags != newVal) {
3211 mResettingSystemUiFlags = newVal;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003212 changed = true;
3213 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003214 // We don't allow the system's nav bar to be hidden
3215 // again for 1 second, to prevent applications from
3216 // spamming us and keeping it from being shown.
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003217 newVal = mForceClearedSystemUiFlags |
3218 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
Dianne Hackborne26ab702011-10-16 13:21:33 -07003219 if (mForceClearedSystemUiFlags != newVal) {
3220 mForceClearedSystemUiFlags = newVal;
3221 changed = true;
John Spurlock04db1762013-05-13 12:46:41 -04003222 mHandler.postDelayed(mClearHideNavigationFlag, 1000);
Dianne Hackborne26ab702011-10-16 13:21:33 -07003223 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07003224 }
3225 if (changed) {
3226 mWindowManagerFuncs.reevaluateStatusBarVisibility();
3227 }
3228 }
3229 }
3230 } finally {
Jeff Brown32cbc38552011-12-01 14:01:49 -08003231 finishInputEvent(event, handled);
Dianne Hackborndf89e652011-10-06 22:35:11 -07003232 }
3233 }
Jeff Brown32cbc38552011-12-01 14:01:49 -08003234 }
3235 final InputEventReceiver.Factory mHideNavInputEventReceiverFactory =
3236 new InputEventReceiver.Factory() {
3237 @Override
3238 public InputEventReceiver createInputEventReceiver(
3239 InputChannel inputChannel, Looper looper) {
3240 return new HideNavInputEventReceiver(inputChannel, looper);
3241 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07003242 };
3243
3244 @Override
3245 public int adjustSystemUiVisibilityLw(int visibility) {
John Spurlock5b9145b2013-08-20 15:13:47 -04003246 mStatusBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
3247 mNavigationBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
Winson Chungd42a6cf2014-06-03 16:24:04 -07003248 mRecentsVisible = (visibility & View.RECENT_APPS_VISIBLE) > 0;
John Spurlock27735a42013-08-14 17:57:38 -04003249
Dianne Hackborndf89e652011-10-06 22:35:11 -07003250 // Reset any bits in mForceClearingStatusBarVisibility that
3251 // are now clear.
Dianne Hackborne26ab702011-10-16 13:21:33 -07003252 mResettingSystemUiFlags &= visibility;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003253 // Clear any bits in the new visibility that are currently being
3254 // force cleared, before reporting it.
Dianne Hackborne26ab702011-10-16 13:21:33 -07003255 return visibility & ~mResettingSystemUiFlags
3256 & ~mForceClearedSystemUiFlags;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003257 }
3258
Craig Mautner69b08182012-09-05 13:07:13 -07003259 @Override
Adrian Roos37d7a682014-11-06 18:15:16 +01003260 public void getInsetHintLw(WindowManager.LayoutParams attrs, Rect outContentInsets,
3261 Rect outStableInsets) {
John Spurlockc6d1c602014-01-17 15:22:06 -05003262 final int fl = PolicyControl.getWindowFlags(null, attrs);
John Spurlock1db8b682014-02-18 11:18:59 -05003263 final int sysuiVis = PolicyControl.getSystemUiVisibility(null, attrs);
3264 final int systemUiVisibility = (sysuiVis | attrs.subtreeSystemUiVisibility);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003265
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003266 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003267 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003268 int availRight, availBottom;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003269 if (canHideNavigationBar() &&
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003270 (systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003271 availRight = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3272 availBottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
3273 } else {
3274 availRight = mRestrictedScreenLeft + mRestrictedScreenWidth;
3275 availBottom = mRestrictedScreenTop + mRestrictedScreenHeight;
3276 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003277 if ((systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
3278 if ((fl & FLAG_FULLSCREEN) != 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003279 outContentInsets.set(mStableFullscreenLeft, mStableFullscreenTop,
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003280 availRight - mStableFullscreenRight,
3281 availBottom - mStableFullscreenBottom);
3282 } else {
Adrian Roos37d7a682014-11-06 18:15:16 +01003283 outContentInsets.set(mStableLeft, mStableTop,
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003284 availRight - mStableRight, availBottom - mStableBottom);
3285 }
Dianne Hackbornc652de82013-02-15 16:32:56 -08003286 } else if ((fl & FLAG_FULLSCREEN) != 0 || (fl & FLAG_LAYOUT_IN_OVERSCAN) != 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003287 outContentInsets.setEmpty();
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003288 } else if ((systemUiVisibility & (View.SYSTEM_UI_FLAG_FULLSCREEN
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003289 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)) == 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003290 outContentInsets.set(mCurLeft, mCurTop,
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003291 availRight - mCurRight, availBottom - mCurBottom);
3292 } else {
Adrian Roos37d7a682014-11-06 18:15:16 +01003293 outContentInsets.set(mCurLeft, mCurTop,
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003294 availRight - mCurRight, availBottom - mCurBottom);
3295 }
Adrian Roos37d7a682014-11-06 18:15:16 +01003296
3297 outStableInsets.set(mStableLeft, mStableTop,
3298 availRight - mStableRight, availBottom - mStableBottom);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003299 return;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003300 }
Adrian Roos37d7a682014-11-06 18:15:16 +01003301 outContentInsets.setEmpty();
3302 outStableInsets.setEmpty();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003303 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003304
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003305 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07003306 @Override
3307 public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight,
3308 int displayRotation) {
Dianne Hackbornc652de82013-02-15 16:32:56 -08003309 final int overscanLeft, overscanTop, overscanRight, overscanBottom;
3310 if (isDefaultDisplay) {
3311 switch (displayRotation) {
3312 case Surface.ROTATION_90:
3313 overscanLeft = mOverscanTop;
3314 overscanTop = mOverscanRight;
3315 overscanRight = mOverscanBottom;
3316 overscanBottom = mOverscanLeft;
3317 break;
3318 case Surface.ROTATION_180:
3319 overscanLeft = mOverscanRight;
3320 overscanTop = mOverscanBottom;
3321 overscanRight = mOverscanLeft;
3322 overscanBottom = mOverscanTop;
3323 break;
3324 case Surface.ROTATION_270:
3325 overscanLeft = mOverscanBottom;
3326 overscanTop = mOverscanLeft;
3327 overscanRight = mOverscanTop;
3328 overscanBottom = mOverscanRight;
3329 break;
3330 default:
3331 overscanLeft = mOverscanLeft;
3332 overscanTop = mOverscanTop;
3333 overscanRight = mOverscanRight;
3334 overscanBottom = mOverscanBottom;
3335 break;
3336 }
3337 } else {
3338 overscanLeft = 0;
3339 overscanTop = 0;
3340 overscanRight = 0;
3341 overscanBottom = 0;
3342 }
Dianne Hackborn313440842013-02-19 19:22:59 -08003343 mOverscanScreenLeft = mRestrictedOverscanScreenLeft = 0;
3344 mOverscanScreenTop = mRestrictedOverscanScreenTop = 0;
3345 mOverscanScreenWidth = mRestrictedOverscanScreenWidth = displayWidth;
3346 mOverscanScreenHeight = mRestrictedOverscanScreenHeight = displayHeight;
Dianne Hackbornc652de82013-02-15 16:32:56 -08003347 mSystemLeft = 0;
3348 mSystemTop = 0;
3349 mSystemRight = displayWidth;
3350 mSystemBottom = displayHeight;
3351 mUnrestrictedScreenLeft = overscanLeft;
3352 mUnrestrictedScreenTop = overscanTop;
3353 mUnrestrictedScreenWidth = displayWidth - overscanLeft - overscanRight;
3354 mUnrestrictedScreenHeight = displayHeight - overscanTop - overscanBottom;
3355 mRestrictedScreenLeft = mUnrestrictedScreenLeft;
3356 mRestrictedScreenTop = mUnrestrictedScreenTop;
John Spurlockad3e6cb2013-04-30 08:47:43 -04003357 mRestrictedScreenWidth = mSystemGestures.screenWidth = mUnrestrictedScreenWidth;
3358 mRestrictedScreenHeight = mSystemGestures.screenHeight = mUnrestrictedScreenHeight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003359 mDockLeft = mContentLeft = mVoiceContentLeft = mStableLeft = mStableFullscreenLeft
Dianne Hackbornc652de82013-02-15 16:32:56 -08003360 = mCurLeft = mUnrestrictedScreenLeft;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003361 mDockTop = mContentTop = mVoiceContentTop = mStableTop = mStableFullscreenTop
Dianne Hackbornc652de82013-02-15 16:32:56 -08003362 = mCurTop = mUnrestrictedScreenTop;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003363 mDockRight = mContentRight = mVoiceContentRight = mStableRight = mStableFullscreenRight
Dianne Hackbornc652de82013-02-15 16:32:56 -08003364 = mCurRight = displayWidth - overscanRight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003365 mDockBottom = mContentBottom = mVoiceContentBottom = mStableBottom = mStableFullscreenBottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003366 = mCurBottom = displayHeight - overscanBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003367 mDockLayer = 0x10000000;
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003368 mStatusBarLayer = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003369
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003370 // start with the current dock rect, which will be (0,0,displayWidth,displayHeight)
3371 final Rect pf = mTmpParentFrame;
3372 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003373 final Rect of = mTmpOverscanFrame;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003374 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04003375 final Rect dcf = mTmpDecorFrame;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003376 final Rect osf = mTmpOutsetFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003377 pf.left = df.left = of.left = vf.left = mDockLeft;
3378 pf.top = df.top = of.top = vf.top = mDockTop;
3379 pf.right = df.right = of.right = vf.right = mDockRight;
3380 pf.bottom = df.bottom = of.bottom = vf.bottom = mDockBottom;
John Spurlock46646232013-09-30 22:32:42 -04003381 dcf.setEmpty(); // Decor frame N/A for system bars.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003382
Craig Mautner69b08182012-09-05 13:07:13 -07003383 if (isDefaultDisplay) {
3384 // For purposes of putting out fake window up to steal focus, we will
3385 // drive nav being hidden only by whether it is requested.
John Spurlocke1f366f2013-08-05 12:22:40 -04003386 final int sysui = mLastSystemUiFlags;
3387 boolean navVisible = (sysui & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0;
Adrian Roosea562512014-05-05 13:33:03 +02003388 boolean navTranslucent = (sysui
3389 & (View.NAVIGATION_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04003390 boolean immersive = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
3391 boolean immersiveSticky = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
3392 boolean navAllowedHidden = immersive || immersiveSticky;
3393 navTranslucent &= !immersiveSticky; // transient trumps translucent
Adrian Roos4fb3ee32014-08-22 19:29:09 +02003394 boolean isKeyguardShowing = isStatusBarKeyguard() && !mHideLockScreen;
3395 if (!isKeyguardShowing) {
3396 navTranslucent &= areTranslucentBarsAllowed();
3397 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003398
Craig Mautner69b08182012-09-05 13:07:13 -07003399 // When the navigation bar isn't visible, we put up a fake
3400 // input window to catch all touch events. This way we can
3401 // detect when the user presses anywhere to bring back the nav
3402 // bar and ensure the application doesn't see the event.
John Spurlockf1a36642013-10-12 17:50:42 -04003403 if (navVisible || navAllowedHidden) {
Selim Cinekf83e8242015-05-19 18:08:14 -07003404 if (mInputConsumer != null) {
3405 mInputConsumer.dismiss();
3406 mInputConsumer = null;
Craig Mautner69b08182012-09-05 13:07:13 -07003407 }
Selim Cinekf83e8242015-05-19 18:08:14 -07003408 } else if (mInputConsumer == null) {
3409 mInputConsumer = mWindowManagerFuncs.addInputConsumer(mHandler.getLooper(),
3410 mHideNavInputEventReceiverFactory);
Dianne Hackborne26ab702011-10-16 13:21:33 -07003411 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003412
Craig Mautner69b08182012-09-05 13:07:13 -07003413 // For purposes of positioning and showing the nav bar, if we have
3414 // decided that it can't be hidden (because of the screen aspect ratio),
3415 // then take that into account.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003416 navVisible |= !canHideNavigationBar();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003417
John Spurlockad3e6cb2013-04-30 08:47:43 -04003418 boolean updateSysUiVisibility = false;
Craig Mautner69b08182012-09-05 13:07:13 -07003419 if (mNavigationBar != null) {
John Spurlock27735a42013-08-14 17:57:38 -04003420 boolean transientNavBarShowing = mNavigationBarController.isTransientShowing();
Craig Mautner69b08182012-09-05 13:07:13 -07003421 // Force the navigation bar to its appropriate place and
3422 // size. We need to do this directly, instead of relying on
3423 // it to bubble up from the nav bar, because this needs to
3424 // change atomically with screen rotations.
3425 mNavigationBarOnBottom = (!mNavigationBarCanMove || displayWidth < displayHeight);
3426 if (mNavigationBarOnBottom) {
3427 // It's a system nav bar or a portrait screen; nav bar goes on bottom.
Dianne Hackbornc652de82013-02-15 16:32:56 -08003428 int top = displayHeight - overscanBottom
3429 - mNavigationBarHeightForRotation[displayRotation];
3430 mTmpNavigationFrame.set(0, top, displayWidth, displayHeight - overscanBottom);
Craig Mautner69b08182012-09-05 13:07:13 -07003431 mStableBottom = mStableFullscreenBottom = mTmpNavigationFrame.top;
John Spurlockf95b89a2013-10-10 22:10:42 -04003432 if (transientNavBarShowing) {
John Spurlock27735a42013-08-14 17:57:38 -04003433 mNavigationBarController.setBarShowingLw(true);
John Spurlockad3e6cb2013-04-30 08:47:43 -04003434 } else if (navVisible) {
John Spurlock27735a42013-08-14 17:57:38 -04003435 mNavigationBarController.setBarShowingLw(true);
Craig Mautner69b08182012-09-05 13:07:13 -07003436 mDockBottom = mTmpNavigationFrame.top;
Dianne Hackborn313440842013-02-19 19:22:59 -08003437 mRestrictedScreenHeight = mDockBottom - mRestrictedScreenTop;
3438 mRestrictedOverscanScreenHeight = mDockBottom - mRestrictedOverscanScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07003439 } else {
3440 // We currently want to hide the navigation UI.
John Spurlock27735a42013-08-14 17:57:38 -04003441 mNavigationBarController.setBarShowingLw(false);
Craig Mautner69b08182012-09-05 13:07:13 -07003442 }
John Spurlockc6d1c602014-01-17 15:22:06 -05003443 if (navVisible && !navTranslucent && !navAllowedHidden
3444 && !mNavigationBar.isAnimatingLw()
John Spurlockbd957402013-10-03 11:38:39 -04003445 && !mNavigationBarController.wasRecentlyTranslucent()) {
John Spurlocke1f366f2013-08-05 12:22:40 -04003446 // If the opaque nav bar is currently requested to be visible,
Craig Mautner69b08182012-09-05 13:07:13 -07003447 // and not in the process of animating on or off, then
3448 // we can tell the app that it is covered by it.
3449 mSystemBottom = mTmpNavigationFrame.top;
3450 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003451 } else {
Craig Mautner69b08182012-09-05 13:07:13 -07003452 // Landscape screen; nav bar goes to the right.
Dianne Hackbornc652de82013-02-15 16:32:56 -08003453 int left = displayWidth - overscanRight
3454 - mNavigationBarWidthForRotation[displayRotation];
3455 mTmpNavigationFrame.set(left, 0, displayWidth - overscanRight, displayHeight);
Craig Mautner69b08182012-09-05 13:07:13 -07003456 mStableRight = mStableFullscreenRight = mTmpNavigationFrame.left;
John Spurlockf95b89a2013-10-10 22:10:42 -04003457 if (transientNavBarShowing) {
John Spurlock27735a42013-08-14 17:57:38 -04003458 mNavigationBarController.setBarShowingLw(true);
John Spurlockad3e6cb2013-04-30 08:47:43 -04003459 } else if (navVisible) {
John Spurlock27735a42013-08-14 17:57:38 -04003460 mNavigationBarController.setBarShowingLw(true);
Craig Mautner69b08182012-09-05 13:07:13 -07003461 mDockRight = mTmpNavigationFrame.left;
Dianne Hackborn313440842013-02-19 19:22:59 -08003462 mRestrictedScreenWidth = mDockRight - mRestrictedScreenLeft;
3463 mRestrictedOverscanScreenWidth = mDockRight - mRestrictedOverscanScreenLeft;
Craig Mautner69b08182012-09-05 13:07:13 -07003464 } else {
3465 // We currently want to hide the navigation UI.
John Spurlock27735a42013-08-14 17:57:38 -04003466 mNavigationBarController.setBarShowingLw(false);
Craig Mautner69b08182012-09-05 13:07:13 -07003467 }
John Spurlockbd957402013-10-03 11:38:39 -04003468 if (navVisible && !navTranslucent && !mNavigationBar.isAnimatingLw()
3469 && !mNavigationBarController.wasRecentlyTranslucent()) {
Craig Mautner69b08182012-09-05 13:07:13 -07003470 // If the nav bar is currently requested to be visible,
3471 // and not in the process of animating on or off, then
3472 // we can tell the app that it is covered by it.
3473 mSystemRight = mTmpNavigationFrame.left;
3474 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003475 }
Craig Mautner69b08182012-09-05 13:07:13 -07003476 // Make sure the content and current rectangles are updated to
3477 // account for the restrictions from the navigation bar.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003478 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3479 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3480 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3481 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
Craig Mautner69b08182012-09-05 13:07:13 -07003482 mStatusBarLayer = mNavigationBar.getSurfaceLayer();
3483 // And compute the final frame.
3484 mNavigationBar.computeFrameLw(mTmpNavigationFrame, mTmpNavigationFrame,
Adrian Roosfa104232014-06-20 16:10:14 -07003485 mTmpNavigationFrame, mTmpNavigationFrame, mTmpNavigationFrame, dcf,
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003486 mTmpNavigationFrame, mTmpNavigationFrame);
Craig Mautnereda67292013-04-28 13:50:14 -07003487 if (DEBUG_LAYOUT) Slog.i(TAG, "mNavigationBar frame: " + mTmpNavigationFrame);
John Spurlock27735a42013-08-14 17:57:38 -04003488 if (mNavigationBarController.checkHiddenLw()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04003489 updateSysUiVisibility = true;
3490 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003491 }
Craig Mautnereda67292013-04-28 13:50:14 -07003492 if (DEBUG_LAYOUT) Slog.i(TAG, String.format("mDock rect: (%d,%d - %d,%d)",
Craig Mautner69b08182012-09-05 13:07:13 -07003493 mDockLeft, mDockTop, mDockRight, mDockBottom));
3494
3495 // decide where the status bar goes ahead of time
3496 if (mStatusBar != null) {
3497 // apply any navigation bar insets
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003498 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3499 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3500 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
3501 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight
3502 + mUnrestrictedScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07003503 vf.left = mStableLeft;
3504 vf.top = mStableTop;
3505 vf.right = mStableRight;
3506 vf.bottom = mStableBottom;
3507
3508 mStatusBarLayer = mStatusBar.getSurfaceLayer();
3509
3510 // Let the status bar determine its size.
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003511 mStatusBar.computeFrameLw(pf /* parentFrame */, df /* displayFrame */,
3512 vf /* overlayFrame */, vf /* contentFrame */, vf /* visibleFrame */,
3513 dcf /* decorFrame */, vf /* stableFrame */, vf /* outsetFrame */);
Craig Mautner69b08182012-09-05 13:07:13 -07003514
3515 // For layout, the status bar is always at the top with our fixed height.
3516 mStableTop = mUnrestrictedScreenTop + mStatusBarHeight;
3517
John Spurlocke1f366f2013-08-05 12:22:40 -04003518 boolean statusBarTransient = (sysui & View.STATUS_BAR_TRANSIENT) != 0;
Adrian Roosea562512014-05-05 13:33:03 +02003519 boolean statusBarTranslucent = (sysui
3520 & (View.STATUS_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0;
Adrian Roos4fb3ee32014-08-22 19:29:09 +02003521 if (!isKeyguardShowing) {
3522 statusBarTranslucent &= areTranslucentBarsAllowed();
3523 }
John Spurlock32beb2c2013-03-11 10:16:47 -04003524
Craig Mautner69b08182012-09-05 13:07:13 -07003525 // If the status bar is hidden, we don't want to cause
3526 // windows behind it to scroll.
John Spurlockeda1f692013-09-16 11:38:44 -04003527 if (mStatusBar.isVisibleLw() && !statusBarTransient) {
Craig Mautner69b08182012-09-05 13:07:13 -07003528 // Status bar may go away, so the screen area it occupies
3529 // is available to apps but just covering them when the
3530 // status bar is visible.
3531 mDockTop = mUnrestrictedScreenTop + mStatusBarHeight;
3532
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003533 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3534 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3535 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3536 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
Craig Mautner69b08182012-09-05 13:07:13 -07003537
Craig Mautnereda67292013-04-28 13:50:14 -07003538 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar: " +
Craig Mautner69b08182012-09-05 13:07:13 -07003539 String.format(
3540 "dock=[%d,%d][%d,%d] content=[%d,%d][%d,%d] cur=[%d,%d][%d,%d]",
3541 mDockLeft, mDockTop, mDockRight, mDockBottom,
3542 mContentLeft, mContentTop, mContentRight, mContentBottom,
3543 mCurLeft, mCurTop, mCurRight, mCurBottom));
3544 }
John Spurlocke1f366f2013-08-05 12:22:40 -04003545 if (mStatusBar.isVisibleLw() && !mStatusBar.isAnimatingLw()
John Spurlockbd957402013-10-03 11:38:39 -04003546 && !statusBarTransient && !statusBarTranslucent
3547 && !mStatusBarController.wasRecentlyTranslucent()) {
John Spurlocke1f366f2013-08-05 12:22:40 -04003548 // If the opaque status bar is currently requested to be visible,
Craig Mautner69b08182012-09-05 13:07:13 -07003549 // and not in the process of animating on or off, then
3550 // we can tell the app that it is covered by it.
3551 mSystemTop = mUnrestrictedScreenTop + mStatusBarHeight;
3552 }
John Spurlock27735a42013-08-14 17:57:38 -04003553 if (mStatusBarController.checkHiddenLw()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04003554 updateSysUiVisibility = true;
John Spurlock32beb2c2013-03-11 10:16:47 -04003555 }
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003556 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04003557 if (updateSysUiVisibility) {
3558 updateSystemUiVisibilityLw();
3559 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003560 }
3561 }
3562
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003563 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07003564 @Override
John Spurlock46646232013-09-30 22:32:42 -04003565 public int getSystemDecorLayerLw() {
Bryce Lee2ed3e5f2015-04-01 22:09:19 +00003566 if (mStatusBar != null && mStatusBar.isVisibleLw()) {
3567 return mStatusBar.getSurfaceLayer();
3568 }
3569
3570 if (mNavigationBar != null && mNavigationBar.isVisibleLw()) {
3571 return mNavigationBar.getSurfaceLayer();
3572 }
3573
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003574 return 0;
3575 }
3576
Craig Mautner967212c2013-04-13 21:10:58 -07003577 @Override
3578 public void getContentRectLw(Rect r) {
3579 r.set(mContentLeft, mContentTop, mContentRight, mContentBottom);
3580 }
3581
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003582 void setAttachedWindowFrames(WindowState win, int fl, int adjust, WindowState attached,
3583 boolean insetDecors, Rect pf, Rect df, Rect of, Rect cf, Rect vf) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003584 if (win.getSurfaceLayer() > mDockLayer && attached.getSurfaceLayer() < mDockLayer) {
3585 // Here's a special case: if this attached window is a panel that is
3586 // above the dock window, and the window it is attached to is below
3587 // the dock window, then the frames we computed for the window it is
3588 // attached to can not be used because the dock is effectively part
3589 // of the underlying window and the attached window is floating on top
3590 // of the whole thing. So, we ignore the attached window and explicitly
3591 // compute the frames that would be appropriate without the dock.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003592 df.left = of.left = cf.left = vf.left = mDockLeft;
3593 df.top = of.top = cf.top = vf.top = mDockTop;
3594 df.right = of.right = cf.right = vf.right = mDockRight;
3595 df.bottom = of.bottom = cf.bottom = vf.bottom = mDockBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003596 } else {
3597 // The effective display frame of the attached window depends on
3598 // whether it is taking care of insetting its content. If not,
3599 // we need to use the parent's content frame so that the entire
3600 // window is positioned within that content. Otherwise we can use
Wale Ogunwale393b1c12014-10-18 16:22:01 -07003601 // the overscan frame and let the attached window take care of
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003602 // positioning its content appropriately.
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003603 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Wale Ogunwale393b1c12014-10-18 16:22:01 -07003604 // Set the content frame of the attached window to the parent's decor frame
3605 // (same as content frame when IME isn't present) if specifically requested by
3606 // setting {@link WindowManager.LayoutParams#FLAG_LAYOUT_ATTACHED_IN_DECOR} flag.
3607 // Otherwise, use the overscan frame.
3608 cf.set((fl & FLAG_LAYOUT_ATTACHED_IN_DECOR) != 0
3609 ? attached.getContentFrameLw() : attached.getOverscanFrameLw());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003610 } else {
3611 // If the window is resizing, then we want to base the content
3612 // frame on our attached content frame to resize... however,
3613 // things can be tricky if the attached window is NOT in resize
3614 // mode, in which case its content frame will be larger.
3615 // Ungh. So to deal with that, make sure the content frame
3616 // we end up using is not covering the IM dock.
3617 cf.set(attached.getContentFrameLw());
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003618 if (attached.isVoiceInteraction()) {
3619 if (cf.left < mVoiceContentLeft) cf.left = mVoiceContentLeft;
3620 if (cf.top < mVoiceContentTop) cf.top = mVoiceContentTop;
3621 if (cf.right > mVoiceContentRight) cf.right = mVoiceContentRight;
3622 if (cf.bottom > mVoiceContentBottom) cf.bottom = mVoiceContentBottom;
3623 } else if (attached.getSurfaceLayer() < mDockLayer) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003624 if (cf.left < mContentLeft) cf.left = mContentLeft;
3625 if (cf.top < mContentTop) cf.top = mContentTop;
3626 if (cf.right > mContentRight) cf.right = mContentRight;
3627 if (cf.bottom > mContentBottom) cf.bottom = mContentBottom;
3628 }
3629 }
3630 df.set(insetDecors ? attached.getDisplayFrameLw() : cf);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003631 of.set(insetDecors ? attached.getOverscanFrameLw() : cf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003632 vf.set(attached.getVisibleFrameLw());
3633 }
3634 // The LAYOUT_IN_SCREEN flag is used to determine whether the attached
3635 // window should be positioned relative to its parent or the entire
3636 // screen.
3637 pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0
3638 ? attached.getFrameLw() : df);
3639 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003640
3641 private void applyStableConstraints(int sysui, int fl, Rect r) {
3642 if ((sysui & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
3643 // If app is requesting a stable layout, don't let the
3644 // content insets go below the stable values.
3645 if ((fl & FLAG_FULLSCREEN) != 0) {
3646 if (r.left < mStableFullscreenLeft) r.left = mStableFullscreenLeft;
3647 if (r.top < mStableFullscreenTop) r.top = mStableFullscreenTop;
3648 if (r.right > mStableFullscreenRight) r.right = mStableFullscreenRight;
3649 if (r.bottom > mStableFullscreenBottom) r.bottom = mStableFullscreenBottom;
3650 } else {
3651 if (r.left < mStableLeft) r.left = mStableLeft;
3652 if (r.top < mStableTop) r.top = mStableTop;
3653 if (r.right > mStableRight) r.right = mStableRight;
3654 if (r.bottom > mStableBottom) r.bottom = mStableBottom;
3655 }
3656 }
3657 }
3658
Jorim Jaggiaa806142015-05-20 18:04:16 -07003659 private boolean canReceiveInput(WindowState win) {
3660 boolean notFocusable =
3661 (win.getAttrs().flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0;
3662 boolean altFocusableIm =
3663 (win.getAttrs().flags & WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM) != 0;
3664 boolean notFocusableForIm = notFocusable ^ altFocusableIm;
3665 return !notFocusableForIm;
3666 }
3667
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003668 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07003669 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003670 public void layoutWindowLw(WindowState win, WindowState attached) {
Jorim Jaggiaa806142015-05-20 18:04:16 -07003671 // We've already done the navigation bar and status bar. If the status bar can receive
3672 // input, we need to layout it again to accomodate for the IME window.
3673 if ((win == mStatusBar && !canReceiveInput(win)) || win == mNavigationBar) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003674 return;
3675 }
Jorim Jaggiaa806142015-05-20 18:04:16 -07003676 final WindowManager.LayoutParams attrs = win.getAttrs();
Craig Mautner69b08182012-09-05 13:07:13 -07003677 final boolean isDefaultDisplay = win.isDefaultDisplay();
3678 final boolean needsToOffsetInputMethodTarget = isDefaultDisplay &&
satok1bc0a492012-04-25 22:47:12 +09003679 (win == mLastInputMethodTargetWindow && mLastInputMethodWindow != null);
3680 if (needsToOffsetInputMethodTarget) {
Craig Mautnereda67292013-04-28 13:50:14 -07003681 if (DEBUG_LAYOUT) Slog.i(TAG, "Offset ime target window by the last ime window state");
satok1bc0a492012-04-25 22:47:12 +09003682 offsetInputMethodWindowLw(mLastInputMethodWindow);
3683 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003684
John Spurlockc6d1c602014-01-17 15:22:06 -05003685 final int fl = PolicyControl.getWindowFlags(win, attrs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003686 final int sim = attrs.softInputMode;
John Spurlock1db8b682014-02-18 11:18:59 -05003687 final int sysUiFl = PolicyControl.getSystemUiVisibility(win, null);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003688
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003689 final Rect pf = mTmpParentFrame;
3690 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003691 final Rect of = mTmpOverscanFrame;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003692 final Rect cf = mTmpContentFrame;
3693 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04003694 final Rect dcf = mTmpDecorFrame;
Adrian Roosfa104232014-06-20 16:10:14 -07003695 final Rect sf = mTmpStableFrame;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003696 Rect osf = null;
John Spurlock46646232013-09-30 22:32:42 -04003697 dcf.setEmpty();
Craig Mautner69b08182012-09-05 13:07:13 -07003698
3699 final boolean hasNavBar = (isDefaultDisplay && mHasNavigationBar
Daniel Sandler36412a72011-08-04 09:35:13 -04003700 && mNavigationBar != null && mNavigationBar.isVisibleLw());
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003701
Craig Mautnerf683b562012-10-02 11:10:57 -07003702 final int adjust = sim & SOFT_INPUT_MASK_ADJUST;
3703
Adrian Roosfa104232014-06-20 16:10:14 -07003704 if (isDefaultDisplay) {
3705 sf.set(mStableLeft, mStableTop, mStableRight, mStableBottom);
3706 } else {
3707 sf.set(mOverscanLeft, mOverscanTop, mOverscanRight, mOverscanBottom);
3708 }
3709
Craig Mautner69b08182012-09-05 13:07:13 -07003710 if (!isDefaultDisplay) {
3711 if (attached != null) {
3712 // If this window is attached to another, our display
3713 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003714 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07003715 } else {
3716 // Give the window full screen.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003717 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3718 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3719 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08003720 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003721 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003722 = mOverscanScreenTop + mOverscanScreenHeight;
Craig Mautner69b08182012-09-05 13:07:13 -07003723 }
Jorim Jaggi225d3b52015-04-01 11:18:57 -07003724 } else if (attrs.type == TYPE_INPUT_METHOD) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003725 pf.left = df.left = of.left = cf.left = vf.left = mDockLeft;
3726 pf.top = df.top = of.top = cf.top = vf.top = mDockTop;
3727 pf.right = df.right = of.right = cf.right = vf.right = mDockRight;
John Spurlockc68d5772013-10-08 11:47:58 -04003728 // IM dock windows layout below the nav bar...
John Spurlock57beb3b2013-10-10 10:27:44 -04003729 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlockc68d5772013-10-08 11:47:58 -04003730 // ...with content insets above the nav bar
3731 cf.bottom = vf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003732 // IM dock windows always go to the bottom of the screen.
3733 attrs.gravity = Gravity.BOTTOM;
3734 mDockLayer = win.getSurfaceLayer();
Jorim Jaggi225d3b52015-04-01 11:18:57 -07003735 } else if (attrs.type == TYPE_VOICE_INTERACTION) {
3736 pf.left = df.left = of.left = cf.left = vf.left = mUnrestrictedScreenLeft;
3737 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3738 pf.right = df.right = of.right = cf.right = vf.right = mUnrestrictedScreenLeft
3739 + mUnrestrictedScreenWidth;
3740 pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop
3741 + mUnrestrictedScreenHeight;
3742 cf.bottom = vf.bottom = mStableBottom;
3743 cf.top = vf.top = mStableTop;
Jorim Jaggiaa806142015-05-20 18:04:16 -07003744 } else if (win == mStatusBar) {
Jorim Jaggie0700182014-08-21 01:12:37 +02003745 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3746 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3747 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
3748 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight + mUnrestrictedScreenTop;
3749 cf.left = vf.left = mStableLeft;
3750 cf.top = vf.top = mStableTop;
3751 cf.right = vf.right = mStableRight;
3752 vf.bottom = mStableBottom;
3753 cf.bottom = mContentBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003754 } else {
John Spurlock46646232013-09-30 22:32:42 -04003755
3756 // Default policy decor for the default display
3757 dcf.left = mSystemLeft;
3758 dcf.top = mSystemTop;
3759 dcf.right = mSystemRight;
3760 dcf.bottom = mSystemBottom;
John Spurlockbd957402013-10-03 11:38:39 -04003761 final boolean inheritTranslucentDecor = (attrs.privateFlags
3762 & WindowManager.LayoutParams.PRIVATE_FLAG_INHERIT_TRANSLUCENT_DECOR) != 0;
John Spurlock65567d42013-10-08 10:08:32 -04003763 final boolean isAppWindow =
3764 attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW &&
3765 attrs.type <= WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
3766 final boolean topAtRest =
3767 win == mTopFullscreenOpaqueWindowState && !win.isAnimatingLw();
3768 if (isAppWindow && !inheritTranslucentDecor && !topAtRest) {
John Spurlockbd957402013-10-03 11:38:39 -04003769 if ((sysUiFl & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0
3770 && (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0
Adrian Roosea562512014-05-05 13:33:03 +02003771 && (fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) == 0
3772 && (fl & WindowManager.LayoutParams.
3773 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04003774 // Ensure policy decor includes status bar
3775 dcf.top = mStableTop;
3776 }
John Spurlockbd957402013-10-03 11:38:39 -04003777 if ((fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) == 0
Adrian Roosea562512014-05-05 13:33:03 +02003778 && (sysUiFl & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0
3779 && (fl & WindowManager.LayoutParams.
3780 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04003781 // Ensure policy decor includes navigation bar
3782 dcf.bottom = mStableBottom;
3783 dcf.right = mStableRight;
3784 }
3785 }
3786
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003787 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
3788 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
RoboErik8a2cfc32014-05-16 11:19:38 -07003789 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003790 + "): IN_SCREEN, INSET_DECOR");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003791 // This is the case for a normal activity window: we want it
3792 // to cover all of the screen space, and it can take care of
3793 // moving its contents to account for screen decorations that
3794 // intrude into that space.
3795 if (attached != null) {
3796 // If this window is attached to another, our display
3797 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003798 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003799 } else {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003800 if (attrs.type == TYPE_STATUS_BAR_PANEL
3801 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Joe Onorato29fc2c92010-11-24 10:26:50 -08003802 // Status bar panels are the only windows who can go on top of
3803 // the status bar. They are protected by the STATUS_BAR_SERVICE
3804 // permission, so they have the same privileges as the status
3805 // bar itself.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003806 //
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003807 // However, they should still dodge the navigation bar if it exists.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003808
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003809 pf.left = df.left = of.left = hasNavBar
3810 ? mDockLeft : mUnrestrictedScreenLeft;
3811 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3812 pf.right = df.right = of.right = hasNavBar
3813 ? mRestrictedScreenLeft+mRestrictedScreenWidth
3814 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3815 pf.bottom = df.bottom = of.bottom = hasNavBar
3816 ? mRestrictedScreenTop+mRestrictedScreenHeight
3817 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003818
Craig Mautnereda67292013-04-28 13:50:14 -07003819 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003820 "Laying out status bar window: (%d,%d - %d,%d)",
3821 pf.left, pf.top, pf.right, pf.bottom));
John Spurlock46646232013-09-30 22:32:42 -04003822 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08003823 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3824 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3825 // Asking to layout into the overscan region, so give it that pure
3826 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003827 pf.left = df.left = of.left = mOverscanScreenLeft;
3828 pf.top = df.top = of.top = mOverscanScreenTop;
3829 pf.right = df.right = of.right = mOverscanScreenLeft + mOverscanScreenWidth;
3830 pf.bottom = df.bottom = of.bottom = mOverscanScreenTop
3831 + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003832 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003833 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003834 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3835 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003836 // Asking for layout as if the nav bar is hidden, lets the
Dianne Hackbornc652de82013-02-15 16:32:56 -08003837 // application extend into the unrestricted overscan screen area. We
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003838 // only do this for application windows to ensure no window that
3839 // can be above the nav bar can do this.
Dianne Hackborn313440842013-02-19 19:22:59 -08003840 pf.left = df.left = mOverscanScreenLeft;
3841 pf.top = df.top = mOverscanScreenTop;
3842 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
3843 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003844 // We need to tell the app about where the frame inside the overscan
3845 // is, so it can inset its content by that amount -- it didn't ask
3846 // to actually extend itself into the overscan region.
3847 of.left = mUnrestrictedScreenLeft;
3848 of.top = mUnrestrictedScreenTop;
3849 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3850 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003851 } else {
Dianne Hackborn313440842013-02-19 19:22:59 -08003852 pf.left = df.left = mRestrictedOverscanScreenLeft;
3853 pf.top = df.top = mRestrictedOverscanScreenTop;
3854 pf.right = df.right = mRestrictedOverscanScreenLeft
3855 + mRestrictedOverscanScreenWidth;
3856 pf.bottom = df.bottom = mRestrictedOverscanScreenTop
3857 + mRestrictedOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003858 // We need to tell the app about where the frame inside the overscan
3859 // is, so it can inset its content by that amount -- it didn't ask
3860 // to actually extend itself into the overscan region.
3861 of.left = mUnrestrictedScreenLeft;
3862 of.top = mUnrestrictedScreenTop;
3863 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3864 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003865 }
Craig Mautner69b08182012-09-05 13:07:13 -07003866
John Spurlock46646232013-09-30 22:32:42 -04003867 if ((fl & FLAG_FULLSCREEN) == 0) {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003868 if (win.isVoiceInteraction()) {
3869 cf.left = mVoiceContentLeft;
3870 cf.top = mVoiceContentTop;
3871 cf.right = mVoiceContentRight;
3872 cf.bottom = mVoiceContentBottom;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003873 } else {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003874 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
3875 cf.left = mDockLeft;
3876 cf.top = mDockTop;
3877 cf.right = mDockRight;
3878 cf.bottom = mDockBottom;
3879 } else {
3880 cf.left = mContentLeft;
3881 cf.top = mContentTop;
3882 cf.right = mContentRight;
3883 cf.bottom = mContentBottom;
3884 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003885 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003886 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003887 // Full screen windows are always given a layout that is as if the
3888 // status bar and other transient decors are gone. This is to avoid
3889 // bad states when moving from a window that is not hding the
3890 // status bar to one that is.
3891 cf.left = mRestrictedScreenLeft;
3892 cf.top = mRestrictedScreenTop;
3893 cf.right = mRestrictedScreenLeft + mRestrictedScreenWidth;
3894 cf.bottom = mRestrictedScreenTop + mRestrictedScreenHeight;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003895 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003896 applyStableConstraints(sysUiFl, fl, cf);
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003897 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3898 vf.left = mCurLeft;
3899 vf.top = mCurTop;
3900 vf.right = mCurRight;
3901 vf.bottom = mCurBottom;
3902 } else {
3903 vf.set(cf);
3904 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003905 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003906 } else if ((fl & FLAG_LAYOUT_IN_SCREEN) != 0 || (sysUiFl
3907 & (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
3908 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)) != 0) {
Craig Mautnereda67292013-04-28 13:50:14 -07003909 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3910 "): IN_SCREEN");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003911 // A window that has requested to fill the entire screen just
3912 // gets everything, period.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003913 if (attrs.type == TYPE_STATUS_BAR_PANEL
3914 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003915 pf.left = df.left = of.left = cf.left = hasNavBar
3916 ? mDockLeft : mUnrestrictedScreenLeft;
3917 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
3918 pf.right = df.right = of.right = cf.right = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003919 ? mRestrictedScreenLeft+mRestrictedScreenWidth
Dianne Hackbornc652de82013-02-15 16:32:56 -08003920 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003921 pf.bottom = df.bottom = of.bottom = cf.bottom = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003922 ? mRestrictedScreenTop+mRestrictedScreenHeight
Dianne Hackbornc652de82013-02-15 16:32:56 -08003923 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07003924 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler36412a72011-08-04 09:35:13 -04003925 "Laying out IN_SCREEN status bar window: (%d,%d - %d,%d)",
3926 pf.left, pf.top, pf.right, pf.bottom));
Jim Millere898ac52012-04-06 17:10:57 -07003927 } else if (attrs.type == TYPE_NAVIGATION_BAR
3928 || attrs.type == TYPE_NAVIGATION_BAR_PANEL) {
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003929 // The navigation bar has Real Ultimate Power.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003930 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3931 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3932 pf.right = df.right = of.right = mUnrestrictedScreenLeft
3933 + mUnrestrictedScreenWidth;
3934 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop
3935 + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07003936 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003937 "Laying out navigation bar window: (%d,%d - %d,%d)",
3938 pf.left, pf.top, pf.right, pf.bottom));
Dianne Hackborn01011c32012-02-21 13:54:21 -08003939 } else if ((attrs.type == TYPE_SECURE_SYSTEM_OVERLAY
3940 || attrs.type == TYPE_BOOT_PROGRESS)
Jeff Brownbfcb60a2011-09-08 18:51:14 -07003941 && ((fl & FLAG_FULLSCREEN) != 0)) {
3942 // Fullscreen secure system overlays get what they ask for.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003943 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3944 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3945 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
3946 + mOverscanScreenWidth;
3947 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
3948 + mOverscanScreenHeight;
Craig Mautner165be0c2015-01-27 15:16:58 -08003949 } else if (attrs.type == TYPE_BOOT_PROGRESS) {
Dianne Hackborn01011c32012-02-21 13:54:21 -08003950 // Boot progress screen always covers entire display.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003951 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3952 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3953 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
3954 + mOverscanScreenWidth;
3955 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
3956 + mOverscanScreenHeight;
John Spurlockef4adae2013-08-26 17:58:58 -04003957 } else if (attrs.type == TYPE_WALLPAPER) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07003958 // The wallpaper also has Real Ultimate Power, but we want to tell
3959 // it about the overscan area.
3960 pf.left = df.left = mOverscanScreenLeft;
3961 pf.top = df.top = mOverscanScreenTop;
3962 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
3963 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
3964 of.left = cf.left = mUnrestrictedScreenLeft;
3965 of.top = cf.top = mUnrestrictedScreenTop;
3966 of.right = cf.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3967 of.bottom = cf.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlock46646232013-09-30 22:32:42 -04003968 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08003969 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3970 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3971 // Asking to layout into the overscan region, so give it that pure
3972 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003973 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3974 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3975 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08003976 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003977 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003978 = mOverscanScreenTop + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003979 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003980 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Craig Mautnerbeac1062014-06-03 14:38:57 -07003981 && (attrs.type == TYPE_STATUS_BAR
3982 || attrs.type == TYPE_TOAST
Jorim Jaggi2fdeeab2015-04-01 15:13:03 -07003983 || attrs.type == TYPE_VOICE_INTERACTION_STARTING
John Spurlock34e13d92013-08-10 06:52:28 -04003984 || (attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3985 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW))) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003986 // Asking for layout as if the nav bar is hidden, lets the
3987 // application extend into the unrestricted screen area. We
John Spurlock34e13d92013-08-10 06:52:28 -04003988 // only do this for application windows (or toasts) to ensure no window that
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003989 // can be above the nav bar can do this.
3990 // XXX This assumes that an app asking for this will also
3991 // ask for layout in only content. We can't currently figure out
3992 // what the screen would be if only laying out to hide the nav bar.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003993 pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft;
3994 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
3995 pf.right = df.right = of.right = cf.right = mUnrestrictedScreenLeft
3996 + mUnrestrictedScreenWidth;
3997 pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop
3998 + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003999 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004000 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
4001 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
4002 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
4003 + mRestrictedScreenWidth;
4004 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
4005 + mRestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08004006 }
Craig Mautner69b08182012-09-05 13:07:13 -07004007
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07004008 applyStableConstraints(sysUiFl, fl, cf);
Craig Mautner69b08182012-09-05 13:07:13 -07004009
Dianne Hackborndea3ef72010-10-28 14:24:22 -07004010 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
4011 vf.left = mCurLeft;
4012 vf.top = mCurTop;
4013 vf.right = mCurRight;
4014 vf.bottom = mCurBottom;
4015 } else {
4016 vf.set(cf);
4017 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004018 } else if (attached != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07004019 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
4020 "): attached to " + attached);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004021 // A child window should be placed inside of the same visible
4022 // frame that its parent had.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004023 setAttachedWindowFrames(win, fl, adjust, attached, false, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004024 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07004025 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
4026 "): normal window");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004027 // Otherwise, a normal window must be placed inside the content
4028 // of all screen decorations.
Dianne Hackborna239c842011-06-01 12:28:20 -07004029 if (attrs.type == TYPE_STATUS_BAR_PANEL) {
4030 // Status bar panels are the only windows who can go on top of
4031 // the status bar. They are protected by the STATUS_BAR_SERVICE
4032 // permission, so they have the same privileges as the status
4033 // bar itself.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004034 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
4035 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
4036 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
4037 + mRestrictedScreenWidth;
4038 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
4039 + mRestrictedScreenHeight;
John Spurlock414c1f02013-12-04 13:47:36 -05004040 } else if (attrs.type == TYPE_TOAST || attrs.type == TYPE_SYSTEM_ALERT
4041 || attrs.type == TYPE_VOLUME_OVERLAY) {
4042 // These dialogs are stable to interim decor changes.
John Spurlockbd957402013-10-03 11:38:39 -04004043 pf.left = df.left = of.left = cf.left = mStableLeft;
4044 pf.top = df.top = of.top = cf.top = mStableTop;
4045 pf.right = df.right = of.right = cf.right = mStableRight;
4046 pf.bottom = df.bottom = of.bottom = cf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004047 } else {
Dianne Hackborna239c842011-06-01 12:28:20 -07004048 pf.left = mContentLeft;
4049 pf.top = mContentTop;
4050 pf.right = mContentRight;
4051 pf.bottom = mContentBottom;
Dianne Hackborn20d94742014-05-29 18:35:45 -07004052 if (win.isVoiceInteraction()) {
4053 df.left = of.left = cf.left = mVoiceContentLeft;
4054 df.top = of.top = cf.top = mVoiceContentTop;
4055 df.right = of.right = cf.right = mVoiceContentRight;
4056 df.bottom = of.bottom = cf.bottom = mVoiceContentBottom;
4057 } else if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004058 df.left = of.left = cf.left = mDockLeft;
4059 df.top = of.top = cf.top = mDockTop;
4060 df.right = of.right = cf.right = mDockRight;
4061 df.bottom = of.bottom = cf.bottom = mDockBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07004062 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004063 df.left = of.left = cf.left = mContentLeft;
4064 df.top = of.top = cf.top = mContentTop;
4065 df.right = of.right = cf.right = mContentRight;
4066 df.bottom = of.bottom = cf.bottom = mContentBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07004067 }
4068 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
4069 vf.left = mCurLeft;
4070 vf.top = mCurTop;
4071 vf.right = mCurRight;
4072 vf.bottom = mCurBottom;
4073 } else {
4074 vf.set(cf);
4075 }
Dianne Hackborndea3ef72010-10-28 14:24:22 -07004076 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004077 }
4078 }
Craig Mautner69b08182012-09-05 13:07:13 -07004079
Craig Mautnerb816bed2013-07-23 10:26:17 -07004080 // TYPE_SYSTEM_ERROR is above the NavigationBar so it can't be allowed to extend over it.
4081 if ((fl & FLAG_LAYOUT_NO_LIMITS) != 0 && attrs.type != TYPE_SYSTEM_ERROR) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07004082 df.left = df.top = -10000;
4083 df.right = df.bottom = 10000;
4084 if (attrs.type != TYPE_WALLPAPER) {
4085 of.left = of.top = cf.left = cf.top = vf.left = vf.top = -10000;
4086 of.right = of.bottom = cf.right = cf.bottom = vf.right = vf.bottom = 10000;
4087 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004088 }
4089
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004090 // If the device has a chin (e.g. some watches), a dead area at the bottom of the screen we
4091 // need to provide information to the clients that want to pretend that you can draw there.
4092 if (isDefaultDisplay && (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0) {
4093 osf = mTmpOutsetFrame;
4094 osf.set(cf.left, cf.top, cf.right, cf.bottom);
4095 int outset = ScreenShapeHelper.getWindowOutsetBottomPx(mContext.getResources());
4096 if (outset > 0) {
4097 int rotation = Surface.ROTATION_0;
4098 try {
4099 rotation = mWindowManager.getRotation();
4100 } catch (RemoteException e) {
4101 }
4102 if (rotation == Surface.ROTATION_0) {
4103 osf.bottom += outset;
4104 } else if (rotation == Surface.ROTATION_90) {
4105 osf.right += outset;
4106 } else if (rotation == Surface.ROTATION_180) {
4107 osf.top -= outset;
4108 } else if (rotation == Surface.ROTATION_270) {
4109 osf.left -= outset;
4110 }
4111 if (DEBUG_LAYOUT) Slog.v(TAG, "applying bottom outset of " + outset
4112 + " with rotation " + rotation + ", result: " + osf);
4113 }
4114 }
4115
Craig Mautnereda67292013-04-28 13:50:14 -07004116 if (DEBUG_LAYOUT) Slog.v(TAG, "Compute frame " + attrs.getTitle()
The Android Open Source Project11267662009-03-18 17:39:47 -07004117 + ": sim=#" + Integer.toHexString(sim)
RoboErik8a2cfc32014-05-16 11:19:38 -07004118 + " attach=" + attached + " type=" + attrs.type
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004119 + String.format(" flags=0x%08x", fl)
The Android Open Source Project11267662009-03-18 17:39:47 -07004120 + " pf=" + pf.toShortString() + " df=" + df.toShortString()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004121 + " of=" + of.toShortString()
John Spurlock46646232013-09-30 22:32:42 -04004122 + " cf=" + cf.toShortString() + " vf=" + vf.toShortString()
Adrian Roosfa104232014-06-20 16:10:14 -07004123 + " dcf=" + dcf.toShortString()
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004124 + " sf=" + sf.toShortString()
4125 + " osf=" + (osf == null ? "null" : osf.toShortString()));
Craig Mautner69b08182012-09-05 13:07:13 -07004126
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004127 win.computeFrameLw(pf, df, of, cf, vf, dcf, sf, osf);
Craig Mautner69b08182012-09-05 13:07:13 -07004128
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004129 // Dock windows carve out the bottom of the screen, so normal windows
4130 // can't appear underneath them.
Craig Mautner8bd206b2012-10-03 10:32:02 -07004131 if (attrs.type == TYPE_INPUT_METHOD && win.isVisibleOrBehindKeyguardLw()
4132 && !win.getGivenInsetsPendingLw()) {
satok1bc0a492012-04-25 22:47:12 +09004133 setLastInputMethodWindowLw(null, null);
4134 offsetInputMethodWindowLw(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004135 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004136 if (attrs.type == TYPE_VOICE_INTERACTION && win.isVisibleOrBehindKeyguardLw()
4137 && !win.getGivenInsetsPendingLw()) {
4138 offsetVoiceInputWindowLw(win);
4139 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004140 }
4141
satok1bc0a492012-04-25 22:47:12 +09004142 private void offsetInputMethodWindowLw(WindowState win) {
Craig Mautner4774f6a2015-03-23 11:42:55 -07004143 int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top);
satok1bc0a492012-04-25 22:47:12 +09004144 top += win.getGivenContentInsetsLw().top;
4145 if (mContentBottom > top) {
4146 mContentBottom = top;
4147 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004148 if (mVoiceContentBottom > top) {
4149 mVoiceContentBottom = top;
4150 }
satok1bc0a492012-04-25 22:47:12 +09004151 top = win.getVisibleFrameLw().top;
4152 top += win.getGivenVisibleInsetsLw().top;
4153 if (mCurBottom > top) {
4154 mCurBottom = top;
4155 }
Craig Mautnereda67292013-04-28 13:50:14 -07004156 if (DEBUG_LAYOUT) Slog.v(TAG, "Input method: mDockBottom="
satok1bc0a492012-04-25 22:47:12 +09004157 + mDockBottom + " mContentBottom="
4158 + mContentBottom + " mCurBottom=" + mCurBottom);
4159 }
4160
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004161 private void offsetVoiceInputWindowLw(WindowState win) {
Craig Mautner4774f6a2015-03-23 11:42:55 -07004162 int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08004163 top += win.getGivenContentInsetsLw().top;
4164 if (mVoiceContentBottom > top) {
4165 mVoiceContentBottom = top;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004166 }
4167 }
4168
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004169 /** {@inheritDoc} */
Craig Mautner61ac6bb2012-02-02 17:29:33 -08004170 @Override
4171 public void finishLayoutLw() {
4172 return;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004173 }
4174
4175 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004176 @Override
Craig Mautner39834192012-09-02 07:47:24 -07004177 public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) {
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004178 mTopFullscreenOpaqueWindowState = null;
Adrian Rooscd3884d2015-02-18 17:25:23 +01004179 mTopFullscreenOpaqueOrDimmingWindowState = null;
Craig Mautner2bc789b2014-03-19 19:48:38 -07004180 mAppsToBeHidden.clear();
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004181 mAppsThatDismissKeyguard.clear();
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004182 mForceStatusBar = false;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004183 mForceStatusBarFromKeyguard = false;
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004184 mForceStatusBarTransparent = false;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08004185 mForcingShowNavBar = false;
4186 mForcingShowNavBarLayer = -1;
RoboErik8a2cfc32014-05-16 11:19:38 -07004187
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004188 mHideLockScreen = false;
4189 mAllowLockscreenWhenOn = false;
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004190 mDismissKeyguard = DISMISS_KEYGUARD_NONE;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004191 mShowingLockscreen = false;
4192 mShowingDream = false;
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004193 mWinShowWhenLocked = null;
Jim Millerab954542014-10-10 18:21:49 -07004194 mKeyguardSecure = isKeyguardSecure();
4195 mKeyguardSecureIncludingHidden = mKeyguardSecure
4196 && (mKeyguardDelegate != null && mKeyguardDelegate.isShowing());
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004197 }
4198
4199 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004200 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004201 public void applyPostLayoutPolicyLw(WindowState win, WindowManager.LayoutParams attrs) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004202 if (DEBUG_LAYOUT) Slog.i(TAG, "Win " + win + ": isVisibleOrBehindKeyguardLw="
4203 + win.isVisibleOrBehindKeyguardLw());
John Spurlockc6d1c602014-01-17 15:22:06 -05004204 final int fl = PolicyControl.getWindowFlags(win, attrs);
John Spurlock414c1f02013-12-04 13:47:36 -05004205 if (mTopFullscreenOpaqueWindowState == null
4206 && win.isVisibleLw() && attrs.type == TYPE_INPUT_METHOD) {
4207 mForcingShowNavBar = true;
4208 mForcingShowNavBarLayer = win.getSurfaceLayer();
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08004209 }
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004210 if (attrs.type == TYPE_STATUS_BAR) {
4211 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
4212 mForceStatusBarFromKeyguard = true;
4213 }
4214 if ((attrs.privateFlags & PRIVATE_FLAG_FORCE_STATUS_BAR_VISIBLE_TRANSPARENT) != 0) {
4215 mForceStatusBarTransparent = true;
4216 }
Jorim Jaggiafd4a552014-04-08 15:13:05 +02004217 }
Adrian Roos602c68e2015-04-24 16:03:47 -07004218
4219 boolean appWindow = attrs.type >= FIRST_APPLICATION_WINDOW
4220 && attrs.type < FIRST_SYSTEM_WINDOW;
4221 final boolean showWhenLocked = (fl & FLAG_SHOW_WHEN_LOCKED) != 0;
4222 final boolean dismissKeyguard = (fl & FLAG_DISMISS_KEYGUARD) != 0;
4223
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004224 if (mTopFullscreenOpaqueWindowState == null &&
Dianne Hackborn01b02a72012-01-12 14:05:03 -08004225 win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()) {
John Spurlockc6d1c602014-01-17 15:22:06 -05004226 if ((fl & FLAG_FORCE_NOT_FULLSCREEN) != 0) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004227 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004228 mForceStatusBarFromKeyguard = true;
4229 } else {
4230 mForceStatusBar = true;
4231 }
4232 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004233 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004234 mShowingLockscreen = true;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004235 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004236 if (attrs.type == TYPE_DREAM) {
Jeff Brownc8018eb2012-10-29 21:33:27 -07004237 // If the lockscreen was showing when the dream started then wait
4238 // for the dream to draw before hiding the lockscreen.
4239 if (!mDreamingLockscreen
4240 || (win.isVisibleLw() && win.hasDrawnLw())) {
4241 mShowingDream = true;
Craig Mautnerab55e522014-03-03 13:26:03 -08004242 appWindow = true;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004243 }
4244 }
Craig Mautnerab55e522014-03-03 13:26:03 -08004245
Craig Mautnerab55e522014-03-03 13:26:03 -08004246 if (appWindow) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004247 final IApplicationToken appToken = win.getAppToken();
4248 if (showWhenLocked) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004249 // Remove any previous windows with the same appToken.
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004250 mAppsToBeHidden.remove(appToken);
4251 mAppsThatDismissKeyguard.remove(appToken);
Craig Mautnerca0a1242014-12-02 12:25:14 -08004252 if (mAppsToBeHidden.isEmpty()) {
Craig Mautner192d6042014-12-02 23:24:48 -08004253 if (dismissKeyguard && !mKeyguardSecure) {
4254 mAppsThatDismissKeyguard.add(appToken);
4255 } else {
Craig Mautnerca0a1242014-12-02 12:25:14 -08004256 mWinShowWhenLocked = win;
4257 mHideLockScreen = true;
4258 mForceStatusBarFromKeyguard = false;
Craig Mautnerca0a1242014-12-02 12:25:14 -08004259 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004260 }
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004261 } else if (dismissKeyguard) {
Jim Millerab954542014-10-10 18:21:49 -07004262 if (mKeyguardSecure) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004263 mAppsToBeHidden.add(appToken);
4264 } else {
4265 mAppsToBeHidden.remove(appToken);
4266 }
4267 mAppsThatDismissKeyguard.add(appToken);
Craig Mautner2bc789b2014-03-19 19:48:38 -07004268 } else {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004269 mAppsToBeHidden.add(appToken);
Craig Mautner2bc789b2014-03-19 19:48:38 -07004270 }
Craig Mautnerab55e522014-03-03 13:26:03 -08004271 if (attrs.x == 0 && attrs.y == 0
4272 && attrs.width == WindowManager.LayoutParams.MATCH_PARENT
4273 && attrs.height == WindowManager.LayoutParams.MATCH_PARENT) {
4274 if (DEBUG_LAYOUT) Slog.v(TAG, "Fullscreen window: " + win);
4275 mTopFullscreenOpaqueWindowState = win;
Adrian Rooscd3884d2015-02-18 17:25:23 +01004276 if (mTopFullscreenOpaqueOrDimmingWindowState == null) {
4277 mTopFullscreenOpaqueOrDimmingWindowState = win;
4278 }
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004279 if (!mAppsThatDismissKeyguard.isEmpty() &&
4280 mDismissKeyguard == DISMISS_KEYGUARD_NONE) {
4281 if (DEBUG_LAYOUT) Slog.v(TAG,
4282 "Setting mDismissKeyguard true by win " + win);
tingna_sunge785ffa2015-05-12 13:23:15 +08004283 mDismissKeyguard = (mWinDismissingKeyguard == win
4284 && mSecureDismissingKeyguard == mKeyguardSecure)
4285 ? DISMISS_KEYGUARD_CONTINUE : DISMISS_KEYGUARD_START;
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004286 mWinDismissingKeyguard = win;
tingna_sunge785ffa2015-05-12 13:23:15 +08004287 mSecureDismissingKeyguard = mKeyguardSecure;
Jim Millerab954542014-10-10 18:21:49 -07004288 mForceStatusBarFromKeyguard = mShowingLockscreen && mKeyguardSecure;
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004289 } else if (mAppsToBeHidden.isEmpty() && showWhenLocked) {
4290 if (DEBUG_LAYOUT) Slog.v(TAG,
4291 "Setting mHideLockScreen to true by win " + win);
4292 mHideLockScreen = true;
4293 mForceStatusBarFromKeyguard = false;
Craig Mautnerab55e522014-03-03 13:26:03 -08004294 }
Craig Mautner00156ec2014-03-06 22:29:02 -08004295 if ((fl & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) {
Craig Mautnerab55e522014-03-03 13:26:03 -08004296 mAllowLockscreenWhenOn = true;
4297 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004298 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004299
4300 if (mWinShowWhenLocked != null &&
Adrian Roos602c68e2015-04-24 16:03:47 -07004301 mWinShowWhenLocked.getAppToken() != win.getAppToken() &&
4302 (attrs.flags & FLAG_SHOW_WHEN_LOCKED) == 0) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004303 win.hideLw(false);
4304 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004305 }
Adrian Roos602c68e2015-04-24 16:03:47 -07004306 } else if (mTopFullscreenOpaqueWindowState == null && mWinShowWhenLocked == null) {
4307 // No TopFullscreenOpaqueWindow is showing, but we found a SHOW_WHEN_LOCKED window
4308 // that is being hidden in an animation - keep the
4309 // keyguard hidden until the new window shows up and
4310 // we know whether to show the keyguard or not.
Adrian Roosb85e1ec2015-05-29 15:23:18 -07004311 if (win.isAnimatingLw() && appWindow && showWhenLocked && mKeyguardHidden) {
Adrian Roos602c68e2015-04-24 16:03:47 -07004312 mHideLockScreen = true;
4313 mWinShowWhenLocked = win;
4314 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004315 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01004316 if (mTopFullscreenOpaqueOrDimmingWindowState == null
4317 && win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()
4318 && win.isDimming()) {
4319 mTopFullscreenOpaqueOrDimmingWindowState = win;
4320 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004321 }
4322
4323 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004324 @Override
Craig Mautner39834192012-09-02 07:47:24 -07004325 public int finishPostLayoutPolicyLw() {
Craig Mautnerc5e73bf2015-04-21 15:41:26 +00004326 if (mWinShowWhenLocked != null && mTopFullscreenOpaqueWindowState != null &&
4327 mWinShowWhenLocked.getAppToken() != mTopFullscreenOpaqueWindowState.getAppToken()
4328 && isKeyguardLocked()) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004329 // A dialog is dismissing the keyguard. Put the wallpaper behind it and hide the
4330 // fullscreen window.
4331 // TODO: Make sure FLAG_SHOW_WALLPAPER is restored when dialog is dismissed. Or not.
4332 mWinShowWhenLocked.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
4333 mTopFullscreenOpaqueWindowState.hideLw(false);
4334 mTopFullscreenOpaqueWindowState = mWinShowWhenLocked;
4335 }
4336
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004337 int changes = 0;
Joe Onorato93056472010-09-10 10:30:46 -04004338 boolean topIsFullscreen = false;
Daniel Sandlere02d8082010-10-08 15:13:22 -04004339
4340 final WindowManager.LayoutParams lp = (mTopFullscreenOpaqueWindowState != null)
4341 ? mTopFullscreenOpaqueWindowState.getAttrs()
4342 : null;
4343
Jeff Brownc8018eb2012-10-29 21:33:27 -07004344 // If we are not currently showing a dream then remember the current
4345 // lockscreen state. We will use this to determine whether the dream
4346 // started while the lockscreen was showing and remember this state
4347 // while the dream is showing.
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004348 if (!mShowingDream) {
4349 mDreamingLockscreen = mShowingLockscreen;
Jeff Brown061ea992015-04-17 19:55:47 -07004350 if (mDreamingSleepTokenNeeded) {
4351 mDreamingSleepTokenNeeded = false;
4352 mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 0, 1).sendToTarget();
4353 }
4354 } else {
4355 if (!mDreamingSleepTokenNeeded) {
4356 mDreamingSleepTokenNeeded = true;
4357 mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 1, 1).sendToTarget();
4358 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004359 }
4360
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004361 if (mStatusBar != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07004362 if (DEBUG_LAYOUT) Slog.i(TAG, "force=" + mForceStatusBar
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004363 + " forcefkg=" + mForceStatusBarFromKeyguard
Dianne Hackbornd70bc2f2009-10-06 23:25:51 -07004364 + " top=" + mTopFullscreenOpaqueWindowState);
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004365 boolean shouldBeTransparent = mForceStatusBarTransparent
4366 && !mForceStatusBar
4367 && !mForceStatusBarFromKeyguard;
4368 if (!shouldBeTransparent) {
4369 mStatusBarController.setShowTransparent(false /* transparent */);
4370 } else if (!mStatusBar.isVisibleLw()) {
4371 mStatusBarController.setShowTransparent(true /* transparent */);
4372 }
4373 if (mForceStatusBar || mForceStatusBarFromKeyguard || mForceStatusBarTransparent) {
Craig Mautnereda67292013-04-28 13:50:14 -07004374 if (DEBUG_LAYOUT) Slog.v(TAG, "Showing status bar: forced");
John Spurlock27735a42013-08-14 17:57:38 -04004375 if (mStatusBarController.setBarShowingLw(true)) {
4376 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4377 }
Craig Mautner81defc72013-10-29 11:10:42 -07004378 // Maintain fullscreen layout until incoming animation is complete.
4379 topIsFullscreen = mTopIsFullscreen && mStatusBar.isAnimatingLw();
John Spurlockf92b6162013-11-11 15:01:16 -05004380 // Transient status bar on the lockscreen is not allowed
4381 if (mForceStatusBarFromKeyguard && mStatusBarController.isTransientShowing()) {
4382 mStatusBarController.updateVisibilityLw(false /*transientAllowed*/,
4383 mLastSystemUiFlags, mLastSystemUiFlags);
4384 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004385 } else if (mTopFullscreenOpaqueWindowState != null) {
John Spurlockc6d1c602014-01-17 15:22:06 -05004386 final int fl = PolicyControl.getWindowFlags(null, lp);
Joe Onorato93056472010-09-10 10:30:46 -04004387 if (localLOGV) {
Craig Mautnereda67292013-04-28 13:50:14 -07004388 Slog.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw()
Joe Onorato93056472010-09-10 10:30:46 -04004389 + " shown frame: " + mTopFullscreenOpaqueWindowState.getShownFrameLw());
Craig Mautnereda67292013-04-28 13:50:14 -07004390 Slog.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs()
John Spurlockc6d1c602014-01-17 15:22:06 -05004391 + " lp.flags=0x" + Integer.toHexString(fl));
Joe Onorato93056472010-09-10 10:30:46 -04004392 }
John Spurlockc6d1c602014-01-17 15:22:06 -05004393 topIsFullscreen = (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004394 || (mLastSystemUiFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
Joe Onorato93056472010-09-10 10:30:46 -04004395 // The subtle difference between the window for mTopFullscreenOpaqueWindowState
Mark Dolinerd0646dc2014-08-27 16:04:02 -07004396 // and mTopIsFullscreen is that mTopIsFullscreen is set only if the window
Joe Onorato93056472010-09-10 10:30:46 -04004397 // has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the
4398 // case though.
John Spurlock27735a42013-08-14 17:57:38 -04004399 if (mStatusBarController.isTransientShowing()) {
4400 if (mStatusBarController.setBarShowingLw(true)) {
John Spurlock32beb2c2013-03-11 10:16:47 -04004401 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4402 }
4403 } else if (topIsFullscreen) {
Craig Mautnereda67292013-04-28 13:50:14 -07004404 if (DEBUG_LAYOUT) Slog.v(TAG, "** HIDING status bar");
John Spurlock27735a42013-08-14 17:57:38 -04004405 if (mStatusBarController.setBarShowingLw(false)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004406 changes |= FINISH_LAYOUT_REDO_LAYOUT;
Craig Mautnereda67292013-04-28 13:50:14 -07004407 } else {
Craig Mautnerc5a6e442013-06-05 17:22:35 -07004408 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar already hiding");
Daniel Sandler40427442010-07-16 11:44:52 -04004409 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004410 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07004411 if (DEBUG_LAYOUT) Slog.v(TAG, "** SHOWING status bar: top is not fullscreen");
John Spurlock27735a42013-08-14 17:57:38 -04004412 if (mStatusBarController.setBarShowingLw(true)) {
4413 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4414 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004415 }
4416 }
4417 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04004418
Craig Mautner81defc72013-10-29 11:10:42 -07004419 if (mTopIsFullscreen != topIsFullscreen) {
4420 if (!topIsFullscreen) {
4421 // Force another layout when status bar becomes fully shown.
4422 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4423 }
4424 mTopIsFullscreen = topIsFullscreen;
4425 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04004426
Craig Mautner39834192012-09-02 07:47:24 -07004427 // Hide the key guard if a visible window explicitly specifies that it wants to be
4428 // displayed when the screen is locked.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004429 if (mKeyguardDelegate != null && mStatusBar != null) {
4430 if (localLOGV) Slog.v(TAG, "finishPostLayoutPolicyLw: mHideKeyguard="
4431 + mHideLockScreen);
Jim Millerab954542014-10-10 18:21:49 -07004432 if (mDismissKeyguard != DISMISS_KEYGUARD_NONE && !mKeyguardSecure) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004433 mKeyguardHidden = true;
Jim Millerab954542014-10-10 18:21:49 -07004434 if (setKeyguardOccludedLw(true)) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004435 changes |= FINISH_LAYOUT_REDO_LAYOUT
4436 | FINISH_LAYOUT_REDO_CONFIG
4437 | FINISH_LAYOUT_REDO_WALLPAPER;
4438 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004439 if (mKeyguardDelegate.isShowing()) {
4440 mHandler.post(new Runnable() {
4441 @Override
4442 public void run() {
4443 mKeyguardDelegate.keyguardDone(false, false);
4444 }
4445 });
4446 }
4447 } else if (mHideLockScreen) {
4448 mKeyguardHidden = true;
Jorim Jaggi7d85ea92015-05-20 17:20:40 -07004449 mWinDismissingKeyguard = null;
Jim Millerab954542014-10-10 18:21:49 -07004450 if (setKeyguardOccludedLw(true)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004451 changes |= FINISH_LAYOUT_REDO_LAYOUT
4452 | FINISH_LAYOUT_REDO_CONFIG
4453 | FINISH_LAYOUT_REDO_WALLPAPER;
4454 }
4455 } else if (mDismissKeyguard != DISMISS_KEYGUARD_NONE) {
Jorim Jaggi7d85ea92015-05-20 17:20:40 -07004456 mKeyguardHidden = false;
4457 if (setKeyguardOccludedLw(false)) {
4458 changes |= FINISH_LAYOUT_REDO_LAYOUT
4459 | FINISH_LAYOUT_REDO_CONFIG
4460 | FINISH_LAYOUT_REDO_WALLPAPER;
4461 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004462 if (mDismissKeyguard == DISMISS_KEYGUARD_START) {
4463 // Only launch the next keyguard unlock window once per window.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004464 mHandler.post(new Runnable() {
4465 @Override
4466 public void run() {
4467 mKeyguardDelegate.dismiss();
4468 }
4469 });
4470 }
4471 } else {
4472 mWinDismissingKeyguard = null;
tingna_sunge785ffa2015-05-12 13:23:15 +08004473 mSecureDismissingKeyguard = false;
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004474 mKeyguardHidden = false;
Jim Millerab954542014-10-10 18:21:49 -07004475 if (setKeyguardOccludedLw(false)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004476 changes |= FINISH_LAYOUT_REDO_LAYOUT
4477 | FINISH_LAYOUT_REDO_CONFIG
4478 | FINISH_LAYOUT_REDO_WALLPAPER;
4479 }
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -07004480 }
4481 }
Joe Onorato664644d2011-01-23 17:53:23 -08004482
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004483 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004484 // If the navigation bar has been hidden or shown, we need to do another
4485 // layout pass to update that window.
4486 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4487 }
Joe Onorato664644d2011-01-23 17:53:23 -08004488
Mike Lockwood28569302010-01-28 11:54:40 -05004489 // update since mAllowLockscreenWhenOn might have changed
4490 updateLockScreenTimeout();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004491 return changes;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004492 }
4493
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004494 /**
Jim Millerab954542014-10-10 18:21:49 -07004495 * Updates the occluded state of the Keyguard.
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004496 *
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004497 * @return Whether the flags have changed and we have to redo the layout.
4498 */
Jim Millerab954542014-10-10 18:21:49 -07004499 private boolean setKeyguardOccludedLw(boolean isOccluded) {
4500 boolean wasOccluded = mKeyguardOccluded;
4501 boolean showing = mKeyguardDelegate.isShowing();
4502 if (wasOccluded && !isOccluded && showing) {
4503 mKeyguardOccluded = false;
4504 mKeyguardDelegate.setOccluded(false);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004505 mStatusBar.getAttrs().privateFlags |= PRIVATE_FLAG_KEYGUARD;
4506 mStatusBar.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
4507 return true;
Jim Millerab954542014-10-10 18:21:49 -07004508 } else if (!wasOccluded && isOccluded && showing) {
4509 mKeyguardOccluded = true;
4510 mKeyguardDelegate.setOccluded(true);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004511 mStatusBar.getAttrs().privateFlags &= ~PRIVATE_FLAG_KEYGUARD;
4512 mStatusBar.getAttrs().flags &= ~FLAG_SHOW_WALLPAPER;
4513 return true;
4514 } else {
4515 return false;
4516 }
4517 }
4518
4519 private boolean isStatusBarKeyguard() {
4520 return mStatusBar != null
4521 && (mStatusBar.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
4522 }
4523
Jose Lima9546b202014-07-02 17:21:51 -07004524 @Override
Dianne Hackborn08743722009-12-21 12:16:51 -08004525 public boolean allowAppAnimationsLw() {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004526 if (isStatusBarKeyguard() || mShowingDream) {
Craig Mautner28816302013-10-10 20:31:00 -07004527 // If keyguard or dreams is currently visible, no reason to animate behind it.
Dianne Hackborn08743722009-12-21 12:16:51 -08004528 return false;
4529 }
Dianne Hackborn08743722009-12-21 12:16:51 -08004530 return true;
4531 }
4532
Jose Lima9546b202014-07-02 17:21:51 -07004533 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07004534 public int focusChangedLw(WindowState lastFocus, WindowState newFocus) {
Joe Onorato664644d2011-01-23 17:53:23 -08004535 mFocusedWindow = newFocus;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004536 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004537 // If the navigation bar has been hidden or shown, we need to do another
4538 // layout pass to update that window.
4539 return FINISH_LAYOUT_REDO_LAYOUT;
4540 }
4541 return 0;
Joe Onorato664644d2011-01-23 17:53:23 -08004542 }
4543
Dianne Hackborn0ecadf72009-03-31 18:00:37 -07004544 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07004545 @Override
Jeff Brown46b9ac02010-04-22 18:58:52 -07004546 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
4547 // lid changed state
Jeff Brownc458ce92012-04-30 14:58:40 -07004548 final int newLidState = lidOpen ? LID_OPEN : LID_CLOSED;
4549 if (newLidState == mLidState) {
4550 return;
4551 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004552
Jeff Brownc458ce92012-04-30 14:58:40 -07004553 mLidState = newLidState;
4554 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07004555 updateRotation(true);
Jeff Brownc458ce92012-04-30 14:58:40 -07004556
4557 if (lidOpen) {
Bryce Lee584a4452014-10-21 15:55:55 -07004558 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromLidSwitch);
Jeff Brownc458ce92012-04-30 14:58:40 -07004559 } else if (!mLidControlsSleep) {
Jeff Brown96307042012-07-27 15:51:34 -07004560 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
Jeff Brown46b9ac02010-04-22 18:58:52 -07004561 }
4562 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004563
Michael Wright3818c922014-09-02 13:59:07 -07004564 @Override
4565 public void notifyCameraLensCoverSwitchChanged(long whenNanos, boolean lensCovered) {
4566 int lensCoverState = lensCovered ? CAMERA_LENS_COVERED : CAMERA_LENS_UNCOVERED;
4567 if (mCameraLensCoverState == lensCoverState) {
4568 return;
4569 }
4570 if (mCameraLensCoverState == CAMERA_LENS_COVERED &&
4571 lensCoverState == CAMERA_LENS_UNCOVERED) {
4572 Intent intent;
4573 final boolean keyguardActive = mKeyguardDelegate == null ? false :
4574 mKeyguardDelegate.isShowing();
4575 if (keyguardActive) {
4576 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE);
4577 } else {
4578 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
4579 }
Bryce Lee584a4452014-10-21 15:55:55 -07004580 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromCameraLens);
Bart Sears8b1c27c2015-03-18 23:51:02 +00004581 startActivityAsUser(intent, UserHandle.CURRENT_OR_SELF);
Michael Wright3818c922014-09-02 13:59:07 -07004582 }
4583 mCameraLensCoverState = lensCoverState;
4584 }
4585
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004586 void setHdmiPlugged(boolean plugged) {
4587 if (mHdmiPlugged != plugged) {
4588 mHdmiPlugged = plugged;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004589 updateRotation(true, true);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004590 Intent intent = new Intent(ACTION_HDMI_PLUGGED);
Joe Onoratodc100302011-01-11 17:07:41 -08004591 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004592 intent.putExtra(EXTRA_HDMI_PLUGGED_STATE, plugged);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07004593 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004594 }
4595 }
4596
Joe Onoratoea495d42011-04-06 11:41:11 -07004597 void initializeHdmiState() {
Joe Onorato7ba631f2011-05-04 15:28:00 -07004598 boolean plugged = false;
Joe Onoratoea495d42011-04-06 11:41:11 -07004599 // watch for HDMI plug messages if the hdmi switch exists
4600 if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) {
4601 mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi");
4602
Joe Onoratoea495d42011-04-06 11:41:11 -07004603 final String filename = "/sys/class/switch/hdmi/state";
4604 FileReader reader = null;
4605 try {
4606 reader = new FileReader(filename);
4607 char[] buf = new char[15];
4608 int n = reader.read(buf);
4609 if (n > 1) {
4610 plugged = 0 != Integer.parseInt(new String(buf, 0, n-1));
4611 }
4612 } catch (IOException ex) {
4613 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
4614 } catch (NumberFormatException ex) {
4615 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
4616 } finally {
4617 if (reader != null) {
4618 try {
4619 reader.close();
4620 } catch (IOException ex) {
4621 }
Joe Onoratodc100302011-01-11 17:07:41 -08004622 }
4623 }
4624 }
Joe Onorato7ba631f2011-05-04 15:28:00 -07004625 // This dance forces the code in setHdmiPlugged to run.
4626 // Always do this so the sticky intent is stuck (to false) if there is no hdmi.
4627 mHdmiPlugged = !plugged;
4628 setHdmiPlugged(!mHdmiPlugged);
Joe Onoratodc100302011-01-11 17:07:41 -08004629 }
4630
Dianne Hackbornc0e3f242011-08-19 14:19:10 -07004631 final Object mScreenshotLock = new Object();
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004632 ServiceConnection mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004633
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004634 final Runnable mScreenshotTimeout = new Runnable() {
4635 @Override public void run() {
4636 synchronized (mScreenshotLock) {
4637 if (mScreenshotConnection != null) {
4638 mContext.unbindService(mScreenshotConnection);
4639 mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004640 }
Winson Chung9112ec32011-06-27 13:15:32 -07004641 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004642 }
4643 };
4644
4645 // Assume this is called from the Handler thread.
4646 private void takeScreenshot() {
4647 synchronized (mScreenshotLock) {
4648 if (mScreenshotConnection != null) {
4649 return;
4650 }
4651 ComponentName cn = new ComponentName("com.android.systemui",
4652 "com.android.systemui.screenshot.TakeScreenshotService");
4653 Intent intent = new Intent();
4654 intent.setComponent(cn);
4655 ServiceConnection conn = new ServiceConnection() {
4656 @Override
4657 public void onServiceConnected(ComponentName name, IBinder service) {
4658 synchronized (mScreenshotLock) {
4659 if (mScreenshotConnection != this) {
4660 return;
4661 }
4662 Messenger messenger = new Messenger(service);
4663 Message msg = Message.obtain(null, 1);
4664 final ServiceConnection myConn = this;
4665 Handler h = new Handler(mHandler.getLooper()) {
4666 @Override
4667 public void handleMessage(Message msg) {
4668 synchronized (mScreenshotLock) {
4669 if (mScreenshotConnection == myConn) {
4670 mContext.unbindService(mScreenshotConnection);
4671 mScreenshotConnection = null;
4672 mHandler.removeCallbacks(mScreenshotTimeout);
4673 }
4674 }
4675 }
4676 };
4677 msg.replyTo = new Messenger(h);
Winson Chunga63bb842011-10-17 10:26:28 -07004678 msg.arg1 = msg.arg2 = 0;
4679 if (mStatusBar != null && mStatusBar.isVisibleLw())
4680 msg.arg1 = 1;
4681 if (mNavigationBar != null && mNavigationBar.isVisibleLw())
4682 msg.arg2 = 1;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004683 try {
4684 messenger.send(msg);
4685 } catch (RemoteException e) {
4686 }
4687 }
4688 }
4689 @Override
4690 public void onServiceDisconnected(ComponentName name) {}
4691 };
Amith Yamasani27b89e62013-01-16 12:30:11 -08004692 if (mContext.bindServiceAsUser(
4693 intent, conn, Context.BIND_AUTO_CREATE, UserHandle.CURRENT)) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004694 mScreenshotConnection = conn;
4695 mHandler.postDelayed(mScreenshotTimeout, 10000);
4696 }
4697 }
Winson Chung9112ec32011-06-27 13:15:32 -07004698 }
4699
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004700 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004701 @Override
Jeff Brown037c33e2014-04-09 00:31:55 -07004702 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) {
Jeff Brown96307042012-07-27 15:51:34 -07004703 if (!mSystemBooted) {
4704 // If we have not yet booted, don't let key events do anything.
4705 return 0;
4706 }
4707
Jeff Brown037c33e2014-04-09 00:31:55 -07004708 final boolean interactive = (policyFlags & FLAG_INTERACTIVE) != 0;
Jeff Brown1f245102010-11-18 20:53:46 -08004709 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
4710 final boolean canceled = event.isCanceled();
4711 final int keyCode = event.getKeyCode();
Jeff Browne20c9e02010-10-11 14:20:19 -07004712
Jeff Brown3122e442010-10-11 23:32:49 -07004713 final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0;
Jeff Brown3122e442010-10-11 23:32:49 -07004714
Mike Lockwoodc72b15f2009-11-28 20:58:22 -05004715 // If screen is off then we treat the case where the keyguard is open but hidden
4716 // the same as if it were open and in front.
4717 // This will prevent any keys other than the power button from waking the screen
4718 // when the keyguard is hidden by another activity.
Jim Miller5ecd8112013-01-09 18:50:26 -08004719 final boolean keyguardActive = (mKeyguardDelegate == null ? false :
Jeff Brown037c33e2014-04-09 00:31:55 -07004720 (interactive ?
Jim Millerab954542014-10-10 18:21:49 -07004721 isKeyguardShowingAndNotOccluded() :
Jim Miller5ecd8112013-01-09 18:50:26 -08004722 mKeyguardDelegate.isShowing()));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004723
Jeff Brown40013652012-05-16 21:22:36 -07004724 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004725 Log.d(TAG, "interceptKeyTq keycode=" + keyCode
Jeff Brown037c33e2014-04-09 00:31:55 -07004726 + " interactive=" + interactive + " keyguardActive=" + keyguardActive
Jeff Brown26875502014-01-30 21:47:47 -08004727 + " policyFlags=" + Integer.toHexString(policyFlags));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004728 }
4729
Jeff Brown037c33e2014-04-09 00:31:55 -07004730 // Basic policy based on interactive state.
Jeff Brown4d396052010-10-29 21:50:21 -07004731 int result;
Michael Wright337d9d22014-04-22 15:03:48 -07004732 boolean isWakeKey = (policyFlags & WindowManagerPolicy.FLAG_WAKE) != 0
4733 || event.isWakeKey();
Michael Wrightfc01f042014-09-08 14:12:24 -07004734 if (interactive || (isInjected && !isWakeKey)) {
RoboErikde9ba392014-09-26 12:51:01 -07004735 // When the device is interactive or the key is injected pass the
4736 // key to the application.
Jeff Brown4d396052010-10-29 21:50:21 -07004737 result = ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07004738 isWakeKey = false;
Michael Wrightfc01f042014-09-08 14:12:24 -07004739 } else if (!interactive && shouldDispatchInputWhenNonInteractive()) {
4740 // If we're currently dozing with the screen on and the keyguard showing, pass the key
4741 // to the application but preserve its wake key status to make sure we still move
4742 // from dozing to fully interactive if we would normally go from off to fully
4743 // interactive.
4744 result = ACTION_PASS_TO_USER;
Jeff Brown4d396052010-10-29 21:50:21 -07004745 } else {
4746 // When the screen is off and the key is not injected, determine whether
4747 // to wake the device but don't pass the key to the application.
4748 result = 0;
Jeff Brown26875502014-01-30 21:47:47 -08004749 if (isWakeKey && (!down || !isWakeKeyWhenScreenOff(keyCode))) {
4750 isWakeKey = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004751 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004752 }
4753
Justin Kohd378ad72013-04-01 12:18:26 -07004754 // If the key would be handled globally, just return the result, don't worry about special
4755 // key processing.
Jeff Brown13f00f02014-10-31 14:45:50 -07004756 if (isValidGlobalKey(keyCode)
4757 && mGlobalKeyManager.shouldHandleGlobalKey(keyCode, event)) {
Michael Wright85b1af62014-06-04 14:51:58 -07004758 if (isWakeKey) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004759 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey);
Michael Wright85b1af62014-06-04 14:51:58 -07004760 }
Justin Kohd378ad72013-04-01 12:18:26 -07004761 return result;
4762 }
4763
Jeff Brownbae8e772014-06-12 19:59:45 -07004764 boolean useHapticFeedback = down
4765 && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0
4766 && event.getRepeatCount() == 0;
4767
Jeff Brown4d396052010-10-29 21:50:21 -07004768 // Handle special keys.
4769 switch (keyCode) {
4770 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jeff Brownb0418da2010-11-01 15:24:01 -07004771 case KeyEvent.KEYCODE_VOLUME_UP:
4772 case KeyEvent.KEYCODE_VOLUME_MUTE: {
RoboErik001c59c2015-01-26 15:53:51 -08004773 if (mUseTvRouting) {
4774 // On TVs volume keys never go to the foreground app
4775 result &= ~ACTION_PASS_TO_USER;
4776 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004777 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
4778 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004779 if (interactive && !mScreenshotChordVolumeDownKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004780 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004781 mScreenshotChordVolumeDownKeyTriggered = true;
4782 mScreenshotChordVolumeDownKeyTime = event.getDownTime();
4783 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004784 cancelPendingPowerKeyAction();
4785 interceptScreenshotChord();
4786 }
4787 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004788 mScreenshotChordVolumeDownKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004789 cancelPendingScreenshotChordAction();
4790 }
4791 } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
4792 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004793 if (interactive && !mScreenshotChordVolumeUpKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004794 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004795 mScreenshotChordVolumeUpKeyTriggered = true;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004796 cancelPendingPowerKeyAction();
4797 cancelPendingScreenshotChordAction();
4798 }
4799 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004800 mScreenshotChordVolumeUpKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004801 cancelPendingScreenshotChordAction();
4802 }
4803 }
Jeff Brown4d396052010-10-29 21:50:21 -07004804 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004805 TelecomManager telecomManager = getTelecommService();
4806 if (telecomManager != null) {
4807 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07004808 // If an incoming call is ringing, either VOLUME key means
4809 // "silence ringer". We handle these keys here, rather than
4810 // in the InCallScreen, to make sure we'll respond to them
4811 // even if the InCallScreen hasn't come to the foreground yet.
4812 // Look for the DOWN event here, to agree with the "fallback"
4813 // behavior in the InCallScreen.
4814 Log.i(TAG, "interceptKeyBeforeQueueing:"
4815 + " VOLUME key-down while ringing: Silence ringer!");
Jeff Brown4d396052010-10-29 21:50:21 -07004816
Santos Cordon6848f722014-05-21 15:22:12 -07004817 // Silence the ringer. (It's safe to call this
4818 // even if the ringer has already been silenced.)
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004819 telecomManager.silenceRinger();
Jeff Brown4d396052010-10-29 21:50:21 -07004820
Santos Cordon6848f722014-05-21 15:22:12 -07004821 // And *don't* pass this key thru to the current activity
4822 // (which is probably the InCallScreen.)
4823 result &= ~ACTION_PASS_TO_USER;
4824 break;
4825 }
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004826 if (telecomManager.isInCall()
Santos Cordon6848f722014-05-21 15:22:12 -07004827 && (result & ACTION_PASS_TO_USER) == 0) {
4828 // If we are in call but we decided not to pass the key to
RoboErik430fc482014-06-12 15:49:20 -07004829 // the application, just pass it to the session service.
4830
4831 MediaSessionLegacyHelper.getHelper(mContext)
RoboErik3c45c292014-07-08 16:47:31 -07004832 .sendVolumeKeyEvent(event, false);
Santos Cordon6848f722014-05-21 15:22:12 -07004833 break;
Jeff Brown4d396052010-10-29 21:50:21 -07004834 }
4835 }
4836
RoboErik430fc482014-06-12 15:49:20 -07004837 if ((result & ACTION_PASS_TO_USER) == 0) {
RoboErik001c59c2015-01-26 15:53:51 -08004838 if (mUseTvRouting) {
4839 dispatchDirectAudioEvent(event);
4840 } else {
4841 // If we aren't passing to the user and no one else
4842 // handled it send it to the session manager to
4843 // figure out.
4844 MediaSessionLegacyHelper.getHelper(mContext)
4845 .sendVolumeKeyEvent(event, true);
4846 }
Jeff Brown4d396052010-10-29 21:50:21 -07004847 break;
4848 }
4849 }
4850 break;
4851 }
4852
4853 case KeyEvent.KEYCODE_ENDCALL: {
4854 result &= ~ACTION_PASS_TO_USER;
4855 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004856 TelecomManager telecomManager = getTelecommService();
Jeff Brown4d396052010-10-29 21:50:21 -07004857 boolean hungUp = false;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004858 if (telecomManager != null) {
4859 hungUp = telecomManager.endCall();
Jeff Brown4d396052010-10-29 21:50:21 -07004860 }
Jeff Brown13f00f02014-10-31 14:45:50 -07004861 if (interactive && !hungUp) {
4862 mEndCallKeyHandled = false;
4863 mHandler.postDelayed(mEndCallLongPress,
4864 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
4865 } else {
4866 mEndCallKeyHandled = true;
4867 }
Jeff Brown4d396052010-10-29 21:50:21 -07004868 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004869 if (!mEndCallKeyHandled) {
4870 mHandler.removeCallbacks(mEndCallLongPress);
4871 if (!canceled) {
4872 if ((mEndcallBehavior
4873 & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) {
4874 if (goHome()) {
4875 break;
4876 }
Dianne Hackborn0041e972009-07-24 17:14:43 -07004877 }
Jeff Brown13f00f02014-10-31 14:45:50 -07004878 if ((mEndcallBehavior
4879 & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) {
4880 mPowerManager.goToSleep(event.getEventTime(),
4881 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
4882 isWakeKey = false;
4883 }
Jeff Brown4d396052010-10-29 21:50:21 -07004884 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004885 }
Jeff Brown4d396052010-10-29 21:50:21 -07004886 }
4887 break;
4888 }
4889
4890 case KeyEvent.KEYCODE_POWER: {
4891 result &= ~ACTION_PASS_TO_USER;
Jeff Brown13f00f02014-10-31 14:45:50 -07004892 isWakeKey = false; // wake-up will be handled separately
Jeff Brown4d396052010-10-29 21:50:21 -07004893 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004894 interceptPowerKeyDown(event, interactive);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004895 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004896 interceptPowerKeyUp(event, interactive, canceled);
Jeff Brown4d396052010-10-29 21:50:21 -07004897 }
4898 break;
4899 }
4900
Jeff Brown6212a492014-03-07 13:58:47 -08004901 case KeyEvent.KEYCODE_SLEEP: {
4902 result &= ~ACTION_PASS_TO_USER;
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00004903 isWakeKey = false;
Jeff Brownbae8e772014-06-12 19:59:45 -07004904 if (!mPowerManager.isInteractive()) {
4905 useHapticFeedback = false; // suppress feedback if already non-interactive
4906 }
Nick Vaccarob593a812015-05-15 11:23:05 -07004907 if (down) {
4908 sleepPress(event.getEventTime());
4909 } else {
4910 sleepRelease(event.getEventTime());
4911 }
Jeff Brown6212a492014-03-07 13:58:47 -08004912 break;
4913 }
4914
4915 case KeyEvent.KEYCODE_WAKEUP: {
4916 result &= ~ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07004917 isWakeKey = true;
Jeff Brown6212a492014-03-07 13:58:47 -08004918 break;
4919 }
4920
Jeff Brown4d396052010-10-29 21:50:21 -07004921 case KeyEvent.KEYCODE_MEDIA_PLAY:
4922 case KeyEvent.KEYCODE_MEDIA_PAUSE:
4923 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
Jeff Brown4d396052010-10-29 21:50:21 -07004924 case KeyEvent.KEYCODE_HEADSETHOOK:
4925 case KeyEvent.KEYCODE_MUTE:
4926 case KeyEvent.KEYCODE_MEDIA_STOP:
4927 case KeyEvent.KEYCODE_MEDIA_NEXT:
4928 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
4929 case KeyEvent.KEYCODE_MEDIA_REWIND:
4930 case KeyEvent.KEYCODE_MEDIA_RECORD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09004931 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
4932 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: {
RoboErikde9ba392014-09-26 12:51:01 -07004933 if (MediaSessionLegacyHelper.getHelper(mContext).isGlobalPriorityActive()) {
4934 // If the global session is active pass all media keys to it
4935 // instead of the active window.
4936 result &= ~ACTION_PASS_TO_USER;
4937 }
Jeff Brown4d396052010-10-29 21:50:21 -07004938 if ((result & ACTION_PASS_TO_USER) == 0) {
4939 // Only do this if we would otherwise not pass it to the user. In that
4940 // case, the PhoneWindow class will do the same thing, except it will
4941 // only do it if the showing app doesn't process the key on its own.
Jeff Brown40013652012-05-16 21:22:36 -07004942 // Note that we need to make a copy of the key event here because the
4943 // original key event will be recycled when we return.
Jeff Brown4d396052010-10-29 21:50:21 -07004944 mBroadcastWakeLock.acquire();
Jeff Brown40013652012-05-16 21:22:36 -07004945 Message msg = mHandler.obtainMessage(MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK,
4946 new KeyEvent(event));
4947 msg.setAsynchronous(true);
4948 msg.sendToTarget();
Jeff Brown4d396052010-10-29 21:50:21 -07004949 }
4950 break;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004951 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004952
Jeff Brown4d396052010-10-29 21:50:21 -07004953 case KeyEvent.KEYCODE_CALL: {
4954 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004955 TelecomManager telecomManager = getTelecommService();
4956 if (telecomManager != null) {
4957 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07004958 Log.i(TAG, "interceptKeyBeforeQueueing:"
4959 + " CALL key-down while ringing: Answer the call!");
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004960 telecomManager.acceptRingingCall();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004961
Santos Cordon6848f722014-05-21 15:22:12 -07004962 // And *don't* pass this key thru to the current activity
4963 // (which is presumably the InCallScreen.)
4964 result &= ~ACTION_PASS_TO_USER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004965 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004966 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004967 }
Jeff Brown4d396052010-10-29 21:50:21 -07004968 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004969 }
Michael Wright869a67c2014-08-26 19:33:06 -07004970 case KeyEvent.KEYCODE_VOICE_ASSIST: {
4971 // Only do this if we would otherwise not pass it to the user. In that case,
4972 // interceptKeyBeforeDispatching would apply a similar but different policy in
4973 // order to invoke voice assist actions. Note that we need to make a copy of the
4974 // key event here because the original key event will be recycled when we return.
4975 if ((result & ACTION_PASS_TO_USER) == 0 && !down) {
4976 mBroadcastWakeLock.acquire();
4977 Message msg = mHandler.obtainMessage(MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK,
4978 keyguardActive ? 1 : 0, 0);
4979 msg.setAsynchronous(true);
4980 msg.sendToTarget();
4981 }
4982 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004983 }
Jeff Brown26875502014-01-30 21:47:47 -08004984
Jeff Brownbae8e772014-06-12 19:59:45 -07004985 if (useHapticFeedback) {
4986 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
4987 }
4988
Jeff Brown26875502014-01-30 21:47:47 -08004989 if (isWakeKey) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004990 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey);
Jeff Brown26875502014-01-30 21:47:47 -08004991 }
Bryce Lee584a4452014-10-21 15:55:55 -07004992
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004993 return result;
4994 }
4995
Jeff Brown1c2e4942012-11-06 16:32:01 -08004996 /**
Jeff Brown13f00f02014-10-31 14:45:50 -07004997 * Returns true if the key can have global actions attached to it.
4998 * We reserve all power management keys for the system since they require
4999 * very careful handling.
5000 */
5001 private static boolean isValidGlobalKey(int keyCode) {
5002 switch (keyCode) {
5003 case KeyEvent.KEYCODE_POWER:
5004 case KeyEvent.KEYCODE_WAKEUP:
5005 case KeyEvent.KEYCODE_SLEEP:
5006 return false;
5007 default:
5008 return true;
5009 }
5010 }
5011
5012 /**
Jeff Brown1c2e4942012-11-06 16:32:01 -08005013 * When the screen is off we ignore some keys that might otherwise typically
5014 * be considered wake keys. We filter them out here.
5015 *
5016 * {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it
5017 * is always considered a wake key.
5018 */
5019 private boolean isWakeKeyWhenScreenOff(int keyCode) {
5020 switch (keyCode) {
5021 // ignore volume keys unless docked
5022 case KeyEvent.KEYCODE_VOLUME_UP:
5023 case KeyEvent.KEYCODE_VOLUME_DOWN:
5024 case KeyEvent.KEYCODE_VOLUME_MUTE:
5025 return mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED;
5026
5027 // ignore media and camera keys
5028 case KeyEvent.KEYCODE_MUTE:
5029 case KeyEvent.KEYCODE_HEADSETHOOK:
5030 case KeyEvent.KEYCODE_MEDIA_PLAY:
5031 case KeyEvent.KEYCODE_MEDIA_PAUSE:
5032 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
5033 case KeyEvent.KEYCODE_MEDIA_STOP:
5034 case KeyEvent.KEYCODE_MEDIA_NEXT:
5035 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
5036 case KeyEvent.KEYCODE_MEDIA_REWIND:
5037 case KeyEvent.KEYCODE_MEDIA_RECORD:
5038 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09005039 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK:
Jeff Brown1c2e4942012-11-06 16:32:01 -08005040 case KeyEvent.KEYCODE_CAMERA:
5041 return false;
5042 }
5043 return true;
5044 }
5045
5046
Jeff Brown56194eb2011-03-02 19:23:13 -08005047 /** {@inheritDoc} */
5048 @Override
Michael Wright70af00a2014-09-03 19:30:20 -07005049 public int interceptMotionBeforeQueueingNonInteractive(long whenNanos, int policyFlags) {
5050 if ((policyFlags & FLAG_WAKE) != 0) {
Bryce Lee5c138322014-11-03 08:26:09 -08005051 if (wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotion)) {
5052 return 0;
5053 }
Michael Wright70af00a2014-09-03 19:30:20 -07005054 }
Bryce Lee5c138322014-11-03 08:26:09 -08005055
Michael Wright70af00a2014-09-03 19:30:20 -07005056 if (shouldDispatchInputWhenNonInteractive()) {
5057 return ACTION_PASS_TO_USER;
5058 }
Bryce Lee5c138322014-11-03 08:26:09 -08005059
Bryce Lee812d7022014-11-10 13:33:28 -08005060 // If we have not passed the action up and we are in theater mode without dreaming,
5061 // there will be no dream to intercept the touch and wake into ambient. The device should
5062 // wake up in this case.
5063 if (isTheaterModeEnabled() && (policyFlags & FLAG_WAKE) != 0) {
5064 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotionWhenNotDreaming);
5065 }
5066
Jeff Brown037c33e2014-04-09 00:31:55 -07005067 return 0;
Jeff Brown56194eb2011-03-02 19:23:13 -08005068 }
5069
Michael Wright70af00a2014-09-03 19:30:20 -07005070 private boolean shouldDispatchInputWhenNonInteractive() {
Bryce Lee5c138322014-11-03 08:26:09 -08005071 // Send events to keyguard while the screen is on.
Jim Millerab954542014-10-10 18:21:49 -07005072 if (isKeyguardShowingAndNotOccluded() && mDisplay != null
5073 && mDisplay.getState() != Display.STATE_OFF) {
Bryce Lee5c138322014-11-03 08:26:09 -08005074 return true;
5075 }
5076
5077 // Send events to a dozing dream even if the screen is off since the dream
5078 // is in control of the state of the screen.
5079 IDreamManager dreamManager = getDreamManager();
5080
5081 try {
5082 if (dreamManager != null && dreamManager.isDreaming()) {
5083 return true;
5084 }
5085 } catch (RemoteException e) {
5086 Slog.e(TAG, "RemoteException when checking if dreaming", e);
5087 }
5088
5089 // Otherwise, consume events since the user can't see what is being
5090 // interacted with.
5091 return false;
Michael Wright70af00a2014-09-03 19:30:20 -07005092 }
5093
RoboErik001c59c2015-01-26 15:53:51 -08005094 private void dispatchDirectAudioEvent(KeyEvent event) {
5095 if (event.getAction() != KeyEvent.ACTION_DOWN) {
5096 return;
5097 }
5098 int keyCode = event.getKeyCode();
John Spurlockb94f2d62015-03-17 14:11:57 -04005099 int flags = AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_PLAY_SOUND
5100 | AudioManager.FLAG_FROM_KEY;
RoboErik001c59c2015-01-26 15:53:51 -08005101 String pkgName = mContext.getOpPackageName();
5102 switch (keyCode) {
5103 case KeyEvent.KEYCODE_VOLUME_UP:
5104 try {
John Spurlockee5ad722015-03-03 16:17:21 -05005105 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_RAISE,
John Spurlock90874332015-03-10 16:00:54 -04005106 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005107 } catch (RemoteException e) {
5108 Log.e(TAG, "Error dispatching volume up in dispatchTvAudioEvent.", e);
5109 }
5110 break;
5111 case KeyEvent.KEYCODE_VOLUME_DOWN:
5112 try {
John Spurlockee5ad722015-03-03 16:17:21 -05005113 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_LOWER,
John Spurlock90874332015-03-10 16:00:54 -04005114 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005115 } catch (RemoteException e) {
5116 Log.e(TAG, "Error dispatching volume down in dispatchTvAudioEvent.", e);
5117 }
5118 break;
5119 case KeyEvent.KEYCODE_VOLUME_MUTE:
5120 try {
5121 if (event.getRepeatCount() == 0) {
John Spurlockee5ad722015-03-03 16:17:21 -05005122 getAudioService().adjustSuggestedStreamVolume(
5123 AudioManager.ADJUST_TOGGLE_MUTE,
John Spurlock90874332015-03-10 16:00:54 -04005124 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005125 }
5126 } catch (RemoteException e) {
5127 Log.e(TAG, "Error dispatching mute in dispatchTvAudioEvent.", e);
5128 }
5129 break;
5130 }
5131 }
5132
Jeff Brown40013652012-05-16 21:22:36 -07005133 void dispatchMediaKeyWithWakeLock(KeyEvent event) {
5134 if (DEBUG_INPUT) {
5135 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: " + event);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005136 }
5137
Jeff Brown40013652012-05-16 21:22:36 -07005138 if (mHavePendingMediaKeyRepeatWithWakeLock) {
5139 if (DEBUG_INPUT) {
5140 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: canceled repeat");
5141 }
5142
5143 mHandler.removeMessages(MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK);
5144 mHavePendingMediaKeyRepeatWithWakeLock = false;
5145 mBroadcastWakeLock.release(); // pending repeat was holding onto the wake lock
5146 }
5147
5148 dispatchMediaKeyWithWakeLockToAudioService(event);
5149
5150 if (event.getAction() == KeyEvent.ACTION_DOWN
5151 && event.getRepeatCount() == 0) {
5152 mHavePendingMediaKeyRepeatWithWakeLock = true;
5153
5154 Message msg = mHandler.obtainMessage(
5155 MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK, event);
5156 msg.setAsynchronous(true);
5157 mHandler.sendMessageDelayed(msg, ViewConfiguration.getKeyRepeatTimeout());
5158 } else {
5159 mBroadcastWakeLock.release();
5160 }
5161 }
5162
5163 void dispatchMediaKeyRepeatWithWakeLock(KeyEvent event) {
5164 mHavePendingMediaKeyRepeatWithWakeLock = false;
5165
5166 KeyEvent repeatEvent = KeyEvent.changeTimeRepeat(event,
5167 SystemClock.uptimeMillis(), 1, event.getFlags() | KeyEvent.FLAG_LONG_PRESS);
5168 if (DEBUG_INPUT) {
5169 Slog.d(TAG, "dispatchMediaKeyRepeatWithWakeLock: " + repeatEvent);
5170 }
5171
5172 dispatchMediaKeyWithWakeLockToAudioService(repeatEvent);
5173 mBroadcastWakeLock.release();
5174 }
5175
5176 void dispatchMediaKeyWithWakeLockToAudioService(KeyEvent event) {
5177 if (ActivityManagerNative.isSystemReady()) {
RoboErik430fc482014-06-12 15:49:20 -07005178 MediaSessionLegacyHelper.getHelper(mContext).sendMediaButtonEvent(event, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005179 }
5180 }
5181
Michael Wright869a67c2014-08-26 19:33:06 -07005182 void launchVoiceAssistWithWakeLock(boolean keyguardActive) {
5183 Intent voiceIntent =
5184 new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
5185 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, keyguardActive);
Bart Sears8b1c27c2015-03-18 23:51:02 +00005186 startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
Michael Wright869a67c2014-08-26 19:33:06 -07005187 mBroadcastWakeLock.release();
5188 }
5189
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005190 BroadcastReceiver mDockReceiver = new BroadcastReceiver() {
Craig Mautnereee29c42013-01-17 14:44:34 -08005191 @Override
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005192 public void onReceive(Context context, Intent intent) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07005193 if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) {
5194 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
5195 Intent.EXTRA_DOCK_STATE_UNDOCKED);
Daniel Sandler6396c722013-04-16 20:19:09 -04005196 } else {
5197 try {
5198 IUiModeManager uiModeService = IUiModeManager.Stub.asInterface(
5199 ServiceManager.getService(Context.UI_MODE_SERVICE));
5200 mUiMode = uiModeService.getCurrentModeType();
5201 } catch (RemoteException e) {
5202 }
Dianne Hackborn80fa1662009-10-07 14:02:10 -07005203 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005204 updateRotation(true);
Craig Mautnereee29c42013-01-17 14:44:34 -08005205 synchronized (mLock) {
5206 updateOrientationListenerLp();
5207 }
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005208 }
5209 };
5210
Jeff Brown6aaf2952012-10-05 16:01:08 -07005211 BroadcastReceiver mDreamReceiver = new BroadcastReceiver() {
5212 @Override
5213 public void onReceive(Context context, Intent intent) {
5214 if (Intent.ACTION_DREAMING_STARTED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005215 if (mKeyguardDelegate != null) {
5216 mKeyguardDelegate.onDreamingStarted();
Jeff Brown6aaf2952012-10-05 16:01:08 -07005217 }
5218 } else if (Intent.ACTION_DREAMING_STOPPED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005219 if (mKeyguardDelegate != null) {
5220 mKeyguardDelegate.onDreamingStopped();
Jeff Brown6aaf2952012-10-05 16:01:08 -07005221 }
5222 }
5223 }
5224 };
5225
Christopher Tate5e08af02012-09-21 17:17:22 -07005226 BroadcastReceiver mMultiuserReceiver = new BroadcastReceiver() {
5227 @Override
5228 public void onReceive(Context context, Intent intent) {
5229 if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) {
5230 // tickle the settings observer: this first ensures that we're
5231 // observing the relevant settings for the newly-active user,
5232 // and then updates our own bookkeeping based on the now-
5233 // current user.
5234 mSettingsObserver.onChange(false);
John Spurlockce479d82012-11-29 09:52:21 -05005235
5236 // force a re-application of focused window sysui visibility.
5237 // the window may never have been shown for this user
5238 // e.g. the keyguard when going through the new-user setup flow
John Spurlock04db1762013-05-13 12:46:41 -04005239 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
John Spurlockce479d82012-11-29 09:52:21 -05005240 mLastSystemUiFlags = 0;
5241 updateSystemUiVisibilityLw();
5242 }
Christopher Tate5e08af02012-09-21 17:17:22 -07005243 }
5244 }
5245 };
5246
Adrian Roosddc8b272015-05-21 16:28:27 -07005247 private final Runnable mHiddenNavPanic = new Runnable() {
John Spurlockd9b70bd2014-02-06 17:02:44 -05005248 @Override
5249 public void run() {
Adrian Roosddc8b272015-05-21 16:28:27 -07005250 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
5251 if (!isUserSetupComplete()) {
5252 // Swipe-up for navigation bar is disabled during setup
5253 return;
5254 }
5255 mPendingPanicGestureUptime = SystemClock.uptimeMillis();
5256 mNavigationBarController.showTransient();
5257 }
John Spurlockd9b70bd2014-02-06 17:02:44 -05005258 }
5259 };
5260
John Spurlocke1f366f2013-08-05 12:22:40 -04005261 private void requestTransientBars(WindowState swipeTarget) {
John Spurlock04db1762013-05-13 12:46:41 -04005262 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Maurice Lam99c6e072014-04-28 18:24:28 -07005263 if (!isUserSetupComplete()) {
5264 // Swipe-up for navigation bar is disabled during setup
5265 return;
5266 }
John Spurlock27735a42013-08-14 17:57:38 -04005267 boolean sb = mStatusBarController.checkShowTransientBarLw();
5268 boolean nb = mNavigationBarController.checkShowTransientBarLw();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005269 if (sb || nb) {
Adrian Roos62b65e42015-02-25 18:05:34 +01005270 // Don't show status bar when swiping on already visible navigation bar
5271 if (!nb && swipeTarget == mNavigationBar) {
John Spurlocke1f366f2013-08-05 12:22:40 -04005272 if (DEBUG) Slog.d(TAG, "Not showing transient bar, wrong swipe target");
John Spurlockad3e6cb2013-04-30 08:47:43 -04005273 return;
5274 }
John Spurlock27735a42013-08-14 17:57:38 -04005275 if (sb) mStatusBarController.showTransient();
5276 if (nb) mNavigationBarController.showTransient();
John Spurlockf1a36642013-10-12 17:50:42 -04005277 mImmersiveModeConfirmation.confirmCurrentPrompt();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005278 updateSystemUiVisibilityLw();
John Spurlock32beb2c2013-03-11 10:16:47 -04005279 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04005280 }
5281 }
5282
Jeff Brown3ee549c2014-09-22 20:14:39 -07005283 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07005284 @Override
Jeff Brown416c49c2015-05-26 19:50:18 -07005285 public void startedGoingToSleep(int why) {
5286 if (DEBUG_WAKEUP) Slog.i(TAG, "Started going to sleep... (why=" + why + ")");
Jorim Jaggid175b6c2015-05-27 15:39:09 -07005287 if (mKeyguardDelegate != null) {
5288 mKeyguardDelegate.onStartedGoingToSleep(why);
5289 }
Jeff Brown416c49c2015-05-26 19:50:18 -07005290 }
5291
5292 // Called on the PowerManager's Notifier thread.
5293 @Override
5294 public void finishedGoingToSleep(int why) {
Dianne Hackborn74489012009-03-24 20:50:09 -07005295 EventLog.writeEvent(70000, 0);
Jeff Brown416c49c2015-05-26 19:50:18 -07005296 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished going to sleep... (why=" + why + ")");
Jeff Brown3ee549c2014-09-22 20:14:39 -07005297
5298 // We must get this work done here because the power manager will drop
5299 // the wake lock and let the system suspend once this function returns.
The Android Open Source Project0727d222009-03-11 12:11:58 -07005300 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005301 mAwake = false;
5302 mKeyguardDrawComplete = false;
Jeff Browna20dda42014-05-27 20:57:24 -07005303 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005304 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05005305 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005306 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005307 if (mKeyguardDelegate != null) {
Jorim Jaggid175b6c2015-05-27 15:39:09 -07005308 mKeyguardDelegate.onFinishedGoingToSleep(why);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005309 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005310 }
5311
Jeff Brown3ee549c2014-09-22 20:14:39 -07005312 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07005313 @Override
Jeff Brown416c49c2015-05-26 19:50:18 -07005314 public void startedWakingUp() {
Dianne Hackborn74489012009-03-24 20:50:09 -07005315 EventLog.writeEvent(70000, 1);
Jeff Brown416c49c2015-05-26 19:50:18 -07005316 if (DEBUG_WAKEUP) Slog.i(TAG, "Started waking up...");
Craig Mautner8a0da012014-05-31 15:13:37 -07005317
Jeff Brown3ee549c2014-09-22 20:14:39 -07005318 // Since goToSleep performs these functions synchronously, we must
5319 // do the same here. We cannot post this work to a handler because
5320 // that might cause it to become reordered with respect to what
5321 // may happen in a future call to goToSleep.
The Android Open Source Project0727d222009-03-11 12:11:58 -07005322 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005323 mAwake = true;
5324 mKeyguardDrawComplete = false;
5325 if (mKeyguardDelegate != null) {
5326 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
5327 mHandler.sendEmptyMessageDelayed(MSG_KEYGUARD_DRAWN_TIMEOUT, 1000);
5328 }
5329
Jeff Browna20dda42014-05-27 20:57:24 -07005330 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005331 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05005332 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005333 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005334
Jim Miller5ecd8112013-01-09 18:50:26 -08005335 if (mKeyguardDelegate != null) {
Jorim Jaggid175b6c2015-05-27 15:39:09 -07005336 mKeyguardDelegate.onStartedWakingUp(mKeyguardDelegateCallback);
Jeff Brown36c4db82014-09-19 12:05:31 -07005337 // ... eventually calls finishKeyguardDrawn
Jeff Brownc38c9be2012-10-04 13:16:19 -07005338 } else {
Craig Mautner8a0da012014-05-31 15:13:37 -07005339 if (DEBUG_WAKEUP) Slog.d(TAG, "null mKeyguardDelegate: setting mKeyguardDrawComplete.");
Jeff Brown36c4db82014-09-19 12:05:31 -07005340 finishKeyguardDrawn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07005341 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005342 }
5343
Jeff Brown416c49c2015-05-26 19:50:18 -07005344 // Called on the PowerManager's Notifier thread.
5345 @Override
5346 public void finishedWakingUp() {
5347 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished waking up...");
5348 }
5349
5350 private void wakeUpFromPowerKey(long eventTime) {
5351 wakeUp(eventTime, mAllowTheaterModeWakeFromPowerKey);
5352 }
5353
5354 private boolean wakeUp(long wakeTime, boolean wakeInTheaterMode) {
5355 if (!wakeInTheaterMode && isTheaterModeEnabled()) {
5356 return false;
5357 }
5358
5359 mPowerManager.wakeUp(wakeTime);
5360 return true;
5361 }
5362
Jeff Brown36c4db82014-09-19 12:05:31 -07005363 private void finishKeyguardDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005364 synchronized (mLock) {
5365 if (!mAwake || mKeyguardDrawComplete) {
5366 return; // spurious
5367 }
5368
Jeff Brown36c4db82014-09-19 12:05:31 -07005369 mKeyguardDrawComplete = true;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005370 if (mKeyguardDelegate != null) {
5371 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
5372 }
5373 }
5374
5375 finishScreenTurningOn();
5376 }
5377
5378 // Called on the DisplayManager's DisplayPowerController thread.
5379 @Override
5380 public void screenTurnedOff() {
5381 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turned off...");
5382
5383 synchronized (mLock) {
5384 mScreenOnEarly = false;
5385 mScreenOnFully = false;
5386 mWindowManagerDrawComplete = false;
5387 mScreenOnListener = null;
5388 updateOrientationListenerLp();
Jeff Brown36c4db82014-09-19 12:05:31 -07005389 }
5390 }
5391
Jeff Brown3ee549c2014-09-22 20:14:39 -07005392 // Called on the DisplayManager's DisplayPowerController thread.
Jeff Brown36c4db82014-09-19 12:05:31 -07005393 @Override
5394 public void screenTurningOn(final ScreenOnListener screenOnListener) {
Jeff Brown36c4db82014-09-19 12:05:31 -07005395 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turning on...");
Jeff Brown36c4db82014-09-19 12:05:31 -07005396
Jeff Brown3ee549c2014-09-22 20:14:39 -07005397 synchronized (mLock) {
5398 mScreenOnEarly = true;
5399 mScreenOnFully = false;
5400 mWindowManagerDrawComplete = false;
5401 mScreenOnListener = screenOnListener;
5402 updateOrientationListenerLp();
5403 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005404
Craig Mautnerc3daedd2014-09-13 11:17:23 -07005405 mWindowManagerInternal.waitForAllWindowsDrawn(mWindowManagerDrawCallback,
5406 WAITING_FOR_DRAWN_TIMEOUT);
Jeff Brown36c4db82014-09-19 12:05:31 -07005407 // ... eventually calls finishWindowsDrawn
5408 }
5409
Jeff Brown36c4db82014-09-19 12:05:31 -07005410 private void finishWindowsDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005411 synchronized (mLock) {
5412 if (!mScreenOnEarly || mWindowManagerDrawComplete) {
5413 return; // spurious
5414 }
5415
Jeff Brown36c4db82014-09-19 12:05:31 -07005416 mWindowManagerDrawComplete = true;
Jeff Brown36c4db82014-09-19 12:05:31 -07005417 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005418
5419 finishScreenTurningOn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07005420 }
5421
Craig Mautner8a0da012014-05-31 15:13:37 -07005422 private void finishScreenTurningOn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005423 final ScreenOnListener listener;
5424 final boolean enableScreen;
Jeff Brown36c4db82014-09-19 12:05:31 -07005425 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005426 if (DEBUG_WAKEUP) Slog.d(TAG,
5427 "finishScreenTurningOn: mAwake=" + mAwake
5428 + ", mScreenOnEarly=" + mScreenOnEarly
5429 + ", mScreenOnFully=" + mScreenOnFully
5430 + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete
5431 + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete);
5432
5433 if (mScreenOnFully || !mScreenOnEarly || !mWindowManagerDrawComplete
5434 || (mAwake && !mKeyguardDrawComplete)) {
5435 return; // spurious or not ready yet
Jeff Brown36c4db82014-09-19 12:05:31 -07005436 }
5437
Jeff Brown3ee549c2014-09-22 20:14:39 -07005438 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished screen turning on...");
5439 listener = mScreenOnListener;
Craig Mautner13f6ea72014-06-23 14:57:02 -07005440 mScreenOnListener = null;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005441 mScreenOnFully = true;
5442
5443 // Remember the first time we draw the keyguard so we know when we're done with
5444 // the main part of booting and can enable the screen and hide boot messages.
5445 if (!mKeyguardDrawnOnce && mAwake) {
5446 mKeyguardDrawnOnce = true;
5447 enableScreen = true;
5448 if (mBootMessageNeedsHiding) {
5449 mBootMessageNeedsHiding = false;
5450 hideBootMessages();
5451 }
5452 } else {
5453 enableScreen = false;
5454 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005455 }
5456
Jeff Brown3ee549c2014-09-22 20:14:39 -07005457 if (listener != null) {
5458 listener.onScreenOn();
5459 }
Jeff Brown4fc45272012-10-10 18:28:14 -07005460
Jeff Brown3ee549c2014-09-22 20:14:39 -07005461 if (enableScreen) {
5462 try {
5463 mWindowManager.enableScreenIfNeeded();
5464 } catch (RemoteException unhandled) {
Jeff Brown36c4db82014-09-19 12:05:31 -07005465 }
Craig Mautnera631d492014-08-05 15:16:01 -07005466 }
5467 }
5468
5469 private void handleHideBootMessage() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005470 synchronized (mLock) {
5471 if (!mKeyguardDrawnOnce) {
5472 mBootMessageNeedsHiding = true;
5473 return; // keyguard hasn't drawn the first time yet, not done booting
5474 }
Craig Mautnera631d492014-08-05 15:16:01 -07005475 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005476
5477 if (mBootMsgDialog != null) {
5478 if (DEBUG_WAKEUP) Slog.d(TAG, "handleHideBootMessage: dismissing");
5479 mBootMsgDialog.dismiss();
5480 mBootMsgDialog = null;
Craig Mautnera631d492014-08-05 15:16:01 -07005481 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005482 }
5483
5484 @Override
Jeff Brown3ee549c2014-09-22 20:14:39 -07005485 public boolean isScreenOn() {
5486 return mScreenOnFully;
Dianne Hackborn08743722009-12-21 12:16:51 -08005487 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005488
Dianne Hackborn08743722009-12-21 12:16:51 -08005489 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005490 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005491 public void enableKeyguard(boolean enabled) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005492 if (mKeyguardDelegate != null) {
5493 mKeyguardDelegate.setKeyguardEnabled(enabled);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005494 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005495 }
5496
5497 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005498 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005499 public void exitKeyguardSecurely(OnKeyguardExitResult callback) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005500 if (mKeyguardDelegate != null) {
5501 mKeyguardDelegate.verifyUnlock(callback);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005502 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005503 }
5504
Jim Millerab954542014-10-10 18:21:49 -07005505 private boolean isKeyguardShowingAndNotOccluded() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005506 if (mKeyguardDelegate == null) return false;
Jim Millerab954542014-10-10 18:21:49 -07005507 return mKeyguardDelegate.isShowing() && !mKeyguardOccluded;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005508 }
5509
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005510 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005511 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005512 public boolean isKeyguardLocked() {
5513 return keyguardOn();
5514 }
5515
5516 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005517 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005518 public boolean isKeyguardSecure() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005519 if (mKeyguardDelegate == null) return false;
5520 return mKeyguardDelegate.isSecure();
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005521 }
5522
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005523 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005524 @Override
Adrian Roos461829d2015-06-03 14:41:18 -07005525 public boolean isKeyguardShowingOrOccluded() {
5526 return mKeyguardDelegate == null ? false : mKeyguardDelegate.isShowing();
5527 }
5528
5529 /** {@inheritDoc} */
5530 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005531 public boolean inKeyguardRestrictedKeyInputMode() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005532 if (mKeyguardDelegate == null) return false;
5533 return mKeyguardDelegate.isInputRestricted();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005534 }
5535
Jose Lima9546b202014-07-02 17:21:51 -07005536 @Override
Dianne Hackborn90c52de2011-09-23 12:57:44 -07005537 public void dismissKeyguardLw() {
RoboErik8a2cfc32014-05-16 11:19:38 -07005538 if (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()) {
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07005539 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.dismissKeyguardLw");
Daniel Sandler1ce804392012-11-07 15:07:12 -05005540 mHandler.post(new Runnable() {
Jose Lima9546b202014-07-02 17:21:51 -07005541 @Override
Daniel Sandler1ce804392012-11-07 15:07:12 -05005542 public void run() {
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02005543 // ask the keyguard to prompt the user to authenticate if necessary
5544 mKeyguardDelegate.dismiss();
5545 }
5546 });
5547 }
5548 }
5549
5550 public void notifyActivityDrawnForKeyguardLw() {
5551 if (mKeyguardDelegate != null) {
5552 mHandler.post(new Runnable() {
5553 @Override
5554 public void run() {
5555 mKeyguardDelegate.onActivityDrawn();
Daniel Sandler1ce804392012-11-07 15:07:12 -05005556 }
5557 });
Dianne Hackborn90c52de2011-09-23 12:57:44 -07005558 }
5559 }
5560
Jorim Jaggicff0acb2014-03-31 16:35:15 +02005561 @Override
5562 public boolean isKeyguardDrawnLw() {
5563 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005564 return mKeyguardDrawnOnce;
Jorim Jaggicff0acb2014-03-31 16:35:15 +02005565 }
5566 }
5567
Jorim Jaggi0d674622014-05-21 01:34:15 +02005568 @Override
Jorim Jaggie29b2db2014-05-30 23:17:03 +02005569 public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) {
Jorim Jaggi0d674622014-05-21 01:34:15 +02005570 if (mKeyguardDelegate != null) {
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07005571 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.startKeyguardExitAnimation");
Jorim Jaggie29b2db2014-05-30 23:17:03 +02005572 mKeyguardDelegate.startKeyguardExitAnimation(startTime, fadeoutDuration);
Jorim Jaggi0d674622014-05-21 01:34:15 +02005573 }
5574 }
5575
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005576 void sendCloseSystemWindows() {
Jorim Jaggib10e33f2015-02-04 21:57:40 +01005577 PhoneWindow.sendCloseSystemWindows(mContext, null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005578 }
5579
5580 void sendCloseSystemWindows(String reason) {
Jorim Jaggib10e33f2015-02-04 21:57:40 +01005581 PhoneWindow.sendCloseSystemWindows(mContext, reason);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005582 }
Mitsuru Oshima831d0d92009-06-16 18:27:18 -07005583
Jeff Brown01a98dd2011-09-20 15:08:29 -07005584 @Override
5585 public int rotationForOrientationLw(int orientation, int lastRotation) {
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005586 if (false) {
5587 Slog.v(TAG, "rotationForOrientationLw(orient="
5588 + orientation + ", last=" + lastRotation
5589 + "); user=" + mUserRotation + " "
5590 + ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED)
5591 ? "USER_ROTATION_LOCKED" : "")
5592 );
5593 }
5594
Craig Mautner46ac6fa2013-08-01 10:06:34 -07005595 if (mForceDefaultOrientation) {
5596 return Surface.ROTATION_0;
5597 }
5598
The Android Open Source Project0727d222009-03-11 12:11:58 -07005599 synchronized (mLock) {
Jeff Brownc0347aa2011-09-23 17:26:09 -07005600 int sensorRotation = mOrientationListener.getProposedRotation(); // may be -1
5601 if (sensorRotation < 0) {
Jeff Brown0f862b42012-09-27 21:11:01 -07005602 sensorRotation = lastRotation;
Jeff Brownc0347aa2011-09-23 17:26:09 -07005603 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005604
Jeff Browndec6cf42011-11-15 14:08:20 -08005605 final int preferredRotation;
Jeff Brown2e7760e2012-04-11 15:14:55 -07005606 if (mLidState == LID_OPEN && mLidOpenRotation >= 0) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005607 // Ignore sensor when lid switch is open and rotation is forced.
5608 preferredRotation = mLidOpenRotation;
5609 } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR
Jeff Brownc0347aa2011-09-23 17:26:09 -07005610 && (mCarDockEnablesAccelerometer || mCarDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005611 // Ignore sensor when in car dock unless explicitly enabled.
5612 // This case can override the behavior of NOSENSOR, and can also
5613 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07005614 preferredRotation = mCarDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07005615 ? sensorRotation : mCarDockRotation;
Jeff Brown1a693182011-11-08 14:44:16 -08005616 } else if ((mDockMode == Intent.EXTRA_DOCK_STATE_DESK
5617 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
5618 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK)
Jeff Brownc0347aa2011-09-23 17:26:09 -07005619 && (mDeskDockEnablesAccelerometer || mDeskDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005620 // Ignore sensor when in desk dock unless explicitly enabled.
5621 // This case can override the behavior of NOSENSOR, and can also
5622 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07005623 preferredRotation = mDeskDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07005624 ? sensorRotation : mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -07005625 } else if (mHdmiPlugged && mDemoHdmiRotationLock) {
5626 // Ignore sensor when plugged into HDMI when demo HDMI rotation lock enabled.
Jeff Browneb3e4b92011-12-06 19:54:24 -08005627 // Note that the dock orientation overrides the HDMI orientation.
Jeff Brownc82c89ed2013-04-17 17:18:15 -07005628 preferredRotation = mDemoHdmiRotation;
5629 } else if (mHdmiPlugged && mDockMode == Intent.EXTRA_DOCK_STATE_UNDOCKED
5630 && mUndockedHdmiRotation >= 0) {
5631 // Ignore sensor when plugged into HDMI and an undocked orientation has
5632 // been specified in the configuration (only for legacy devices without
5633 // full multi-display support).
5634 // Note that the dock orientation overrides the HDMI orientation.
5635 preferredRotation = mUndockedHdmiRotation;
Chong Zhangae6119ff2014-11-11 18:54:39 -08005636 } else if (mDemoRotationLock) {
5637 // Ignore sensor when demo rotation lock is enabled.
5638 // Note that the dock orientation and HDMI rotation lock override this.
5639 preferredRotation = mDemoRotation;
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005640 } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED) {
5641 // Application just wants to remain locked in the last rotation.
5642 preferredRotation = lastRotation;
Jeff Brownbcdfc622014-03-06 19:13:04 -08005643 } else if (!mSupportAutoRotation) {
5644 // If we don't support auto-rotation then bail out here and ignore
5645 // the sensor and any rotation lock settings.
5646 preferredRotation = -1;
Jeff Brown207673cd2012-06-05 17:47:11 -07005647 } else if ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE
Jeff Brown01a98dd2011-09-20 15:08:29 -07005648 && (orientation == ActivityInfo.SCREEN_ORIENTATION_USER
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005649 || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
5650 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
5651 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
5652 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER))
Jeff Brown01a98dd2011-09-20 15:08:29 -07005653 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
5654 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
5655 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
5656 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) {
5657 // Otherwise, use sensor only if requested by the application or enabled
5658 // by default for USER or UNSPECIFIED modes. Does not apply to NOSENSOR.
Jeff Brownd3187e32011-09-21 19:26:44 -07005659 if (mAllowAllRotations < 0) {
5660 // Can't read this during init() because the context doesn't
5661 // have display metrics at that time so we cannot determine
5662 // tablet vs. phone then.
5663 mAllowAllRotations = mContext.getResources().getBoolean(
5664 com.android.internal.R.bool.config_allowAllRotations) ? 1 : 0;
5665 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005666 if (sensorRotation != Surface.ROTATION_180
Jeff Brownd3187e32011-09-21 19:26:44 -07005667 || mAllowAllRotations == 1
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005668 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
5669 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005670 preferredRotation = sensorRotation;
5671 } else {
5672 preferredRotation = lastRotation;
5673 }
Jeff Brown207673cd2012-06-05 17:47:11 -07005674 } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED
5675 && orientation != ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) {
5676 // Apply rotation lock. Does not apply to NOSENSOR.
5677 // The idea is that the user rotation expresses a weak preference for the direction
5678 // of gravity and as NOSENSOR is never affected by gravity, then neither should
5679 // NOSENSOR be affected by rotation lock (although it will be affected by docks).
Jeff Brown4dfce202011-10-05 12:00:10 -07005680 preferredRotation = mUserRotation;
Jeff Browndec6cf42011-11-15 14:08:20 -08005681 } else {
5682 // No overriding preference.
5683 // We will do exactly what the application asked us to do.
5684 preferredRotation = -1;
Jeff Brown01a98dd2011-09-20 15:08:29 -07005685 }
5686
Dianne Hackborne5439f22010-10-02 16:53:50 -07005687 switch (orientation) {
5688 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08005689 // Return portrait unless overridden.
5690 if (isAnyPortrait(preferredRotation)) {
5691 return preferredRotation;
5692 }
Dianne Hackborne5439f22010-10-02 16:53:50 -07005693 return mPortraitRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005694
Jeff Brown01a98dd2011-09-20 15:08:29 -07005695 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08005696 // Return landscape unless overridden.
5697 if (isLandscapeOrSeascape(preferredRotation)) {
5698 return preferredRotation;
5699 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005700 return mLandscapeRotation;
5701
5702 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08005703 // Return reverse portrait unless overridden.
5704 if (isAnyPortrait(preferredRotation)) {
5705 return preferredRotation;
5706 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005707 return mUpsideDownRotation;
5708
5709 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08005710 // Return seascape unless overridden.
5711 if (isLandscapeOrSeascape(preferredRotation)) {
5712 return preferredRotation;
5713 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005714 return mSeascapeRotation;
5715
5716 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005717 case ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE:
Jeff Brown01a98dd2011-09-20 15:08:29 -07005718 // Return either landscape rotation.
5719 if (isLandscapeOrSeascape(preferredRotation)) {
5720 return preferredRotation;
5721 }
5722 if (isLandscapeOrSeascape(lastRotation)) {
Jeff Brown4519f072011-01-23 13:16:01 -08005723 return lastRotation;
5724 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005725 return mLandscapeRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005726
Jeff Brown01a98dd2011-09-20 15:08:29 -07005727 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005728 case ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT:
Jeff Brown01a98dd2011-09-20 15:08:29 -07005729 // Return either portrait rotation.
5730 if (isAnyPortrait(preferredRotation)) {
5731 return preferredRotation;
5732 }
5733 if (isAnyPortrait(lastRotation)) {
5734 return lastRotation;
5735 }
5736 return mPortraitRotation;
5737
5738 default:
Jeff Brown4dfce202011-10-05 12:00:10 -07005739 // For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR,
5740 // just return the preferred orientation we already calculated.
Jeff Brown01a98dd2011-09-20 15:08:29 -07005741 if (preferredRotation >= 0) {
5742 return preferredRotation;
5743 }
Dianne Hackborndacea8c2011-04-21 17:26:39 -07005744 return Surface.ROTATION_0;
Daniel Sandlere7e5ac22011-02-22 16:10:21 -05005745 }
5746 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07005747 }
5748
Jeff Brown01a98dd2011-09-20 15:08:29 -07005749 @Override
5750 public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation) {
5751 switch (orientation) {
5752 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
5753 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
5754 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
5755 return isAnyPortrait(rotation);
5756
5757 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
5758 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
5759 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
5760 return isLandscapeOrSeascape(rotation);
5761
5762 default:
5763 return true;
5764 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07005765 }
5766
Jeff Brownc0347aa2011-09-23 17:26:09 -07005767 @Override
5768 public void setRotationLw(int rotation) {
5769 mOrientationListener.setCurrentRotation(rotation);
5770 }
5771
Jeff Brown01a98dd2011-09-20 15:08:29 -07005772 private boolean isLandscapeOrSeascape(int rotation) {
5773 return rotation == mLandscapeRotation || rotation == mSeascapeRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005774 }
5775
Jeff Brown01a98dd2011-09-20 15:08:29 -07005776 private boolean isAnyPortrait(int rotation) {
5777 return rotation == mPortraitRotation || rotation == mUpsideDownRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005778 }
5779
Jose Lima9546b202014-07-02 17:21:51 -07005780 @Override
Svetoslav Ganov80943d82013-01-02 10:25:37 -08005781 public int getUserRotationMode() {
5782 return Settings.System.getIntForUser(mContext.getContentResolver(),
Brett Chabot7e55c402013-05-16 19:38:08 -07005783 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
5784 WindowManagerPolicy.USER_ROTATION_FREE :
5785 WindowManagerPolicy.USER_ROTATION_LOCKED;
Svetoslav Ganov80943d82013-01-02 10:25:37 -08005786 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005787
5788 // User rotation: to be used when all else fails in assigning an orientation to the device
Jose Lima9546b202014-07-02 17:21:51 -07005789 @Override
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005790 public void setUserRotationMode(int mode, int rot) {
5791 ContentResolver res = mContext.getContentResolver();
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005792
5793 // mUserRotationMode and mUserRotation will be assigned by the content observer
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005794 if (mode == WindowManagerPolicy.USER_ROTATION_LOCKED) {
Christopher Tate5e08af02012-09-21 17:17:22 -07005795 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005796 Settings.System.USER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005797 rot,
5798 UserHandle.USER_CURRENT);
5799 Settings.System.putIntForUser(res,
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005800 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005801 0,
5802 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005803 } else {
Christopher Tate5e08af02012-09-21 17:17:22 -07005804 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005805 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005806 1,
5807 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005808 }
5809 }
5810
Jose Lima9546b202014-07-02 17:21:51 -07005811 @Override
Jeff Brownac143512012-04-05 18:57:33 -07005812 public void setSafeMode(boolean safeMode) {
5813 mSafeMode = safeMode;
5814 performHapticFeedbackLw(null, safeMode
5815 ? HapticFeedbackConstants.SAFE_MODE_ENABLED
5816 : HapticFeedbackConstants.SAFE_MODE_DISABLED, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005817 }
Craig Mautnereda67292013-04-28 13:50:14 -07005818
Dianne Hackborn181ceb52009-08-27 22:16:40 -07005819 static long[] getLongIntArray(Resources r, int resid) {
5820 int[] ar = r.getIntArray(resid);
5821 if (ar == null) {
5822 return null;
5823 }
5824 long[] out = new long[ar.length];
5825 for (int i=0; i<ar.length; i++) {
5826 out[i] = ar[i];
5827 }
5828 return out;
5829 }
Craig Mautnereda67292013-04-28 13:50:14 -07005830
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005831 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07005832 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005833 public void systemReady() {
Jim Millerab954542014-10-10 18:21:49 -07005834 mKeyguardDelegate = new KeyguardServiceDelegate(mContext);
Mike Lockwooded8902d2013-11-15 11:01:47 -08005835 mKeyguardDelegate.onSystemReady();
5836
Michael Wright3818c922014-09-02 13:59:07 -07005837 readCameraLensCoverState();
Jeff Brown4f5fa282014-06-12 19:19:15 -07005838 updateUiMode();
Dianne Hackbornb1a79802009-09-29 15:18:31 -07005839 synchronized (mLock) {
5840 updateOrientationListenerLp();
Dianne Hackbornc777e072010-02-12 13:07:59 -08005841 mSystemReady = true;
5842 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07005843 @Override
Dianne Hackbornc777e072010-02-12 13:07:59 -08005844 public void run() {
5845 updateSettings();
5846 }
5847 });
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005848 }
5849 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07005850
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005851 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005852 @Override
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005853 public void systemBooted() {
Jim Millere5f910a2013-10-16 18:15:46 -07005854 if (mKeyguardDelegate != null) {
Jason Monk5eeebf52014-09-26 12:36:51 -04005855 mKeyguardDelegate.bindService(mContext);
Jim Millere5f910a2013-10-16 18:15:46 -07005856 mKeyguardDelegate.onBootCompleted();
5857 }
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005858 synchronized (mLock) {
5859 mSystemBooted = true;
5860 }
Jeff Brown416c49c2015-05-26 19:50:18 -07005861 startedWakingUp();
Jeff Brown36c4db82014-09-19 12:05:31 -07005862 screenTurningOn(null);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005863 }
5864
Dianne Hackborn661cd522011-08-22 00:26:20 -07005865 ProgressDialog mBootMsgDialog = null;
5866
5867 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005868 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07005869 public void showBootMessage(final CharSequence msg, final boolean always) {
5870 mHandler.post(new Runnable() {
5871 @Override public void run() {
5872 if (mBootMsgDialog == null) {
Craig Stout4c0cb8a2014-04-04 13:03:10 -07005873 int theme;
5874 if (mContext.getPackageManager().hasSystemFeature(
5875 PackageManager.FEATURE_WATCH)) {
5876 theme = com.android.internal.R.style.Theme_Micro_Dialog_Alert;
5877 } else if (mContext.getPackageManager().hasSystemFeature(
5878 PackageManager.FEATURE_TELEVISION)) {
5879 theme = com.android.internal.R.style.Theme_Leanback_Dialog_Alert;
5880 } else {
5881 theme = 0;
5882 }
Vinod Krishnanfa8fc412014-04-18 14:35:53 -07005883
5884 mBootMsgDialog = new ProgressDialog(mContext, theme) {
Dianne Hackborn295e3c22011-08-25 13:19:08 -07005885 // This dialog will consume all events coming in to
5886 // it, to avoid it trying to do things too early in boot.
5887 @Override public boolean dispatchKeyEvent(KeyEvent event) {
5888 return true;
5889 }
5890 @Override public boolean dispatchKeyShortcutEvent(KeyEvent event) {
5891 return true;
5892 }
5893 @Override public boolean dispatchTouchEvent(MotionEvent ev) {
5894 return true;
5895 }
5896 @Override public boolean dispatchTrackballEvent(MotionEvent ev) {
5897 return true;
5898 }
5899 @Override public boolean dispatchGenericMotionEvent(MotionEvent ev) {
5900 return true;
5901 }
5902 @Override public boolean dispatchPopulateAccessibilityEvent(
5903 AccessibilityEvent event) {
5904 return true;
5905 }
5906 };
Jeff Hao9f60c082014-10-28 18:51:07 -07005907 if (mContext.getPackageManager().isUpgrade()) {
5908 mBootMsgDialog.setTitle(R.string.android_upgrading_title);
5909 } else {
5910 mBootMsgDialog.setTitle(R.string.android_start_title);
5911 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07005912 mBootMsgDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
5913 mBootMsgDialog.setIndeterminate(true);
5914 mBootMsgDialog.getWindow().setType(
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07005915 WindowManager.LayoutParams.TYPE_BOOT_PROGRESS);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005916 mBootMsgDialog.getWindow().addFlags(
5917 WindowManager.LayoutParams.FLAG_DIM_BEHIND
5918 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
5919 mBootMsgDialog.getWindow().setDimAmount(1);
Dianne Hackbornd9efb952011-12-07 14:56:51 -08005920 WindowManager.LayoutParams lp = mBootMsgDialog.getWindow().getAttributes();
5921 lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
5922 mBootMsgDialog.getWindow().setAttributes(lp);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005923 mBootMsgDialog.setCancelable(false);
5924 mBootMsgDialog.show();
5925 }
5926 mBootMsgDialog.setMessage(msg);
5927 }
5928 });
5929 }
5930
5931 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005932 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07005933 public void hideBootMessages() {
Craig Mautnera631d492014-08-05 15:16:01 -07005934 mHandler.sendEmptyMessage(MSG_HIDE_BOOT_MESSAGE);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005935 }
5936
Mike Lockwood28569302010-01-28 11:54:40 -05005937 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005938 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05005939 public void userActivity() {
Dianne Hackborndf89e652011-10-06 22:35:11 -07005940 // ***************************************
5941 // NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
5942 // ***************************************
5943 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
5944 // WITH ITS LOCKS HELD.
5945 //
5946 // This code must be VERY careful about the locks
5947 // it acquires.
5948 // In fact, the current code acquires way too many,
5949 // and probably has lurking deadlocks.
5950
Mike Lockwood28569302010-01-28 11:54:40 -05005951 synchronized (mScreenLockTimeout) {
5952 if (mLockScreenTimerActive) {
5953 // reset the timer
5954 mHandler.removeCallbacks(mScreenLockTimeout);
5955 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
5956 }
5957 }
Daniel Sandler0601eb72011-04-13 01:01:32 -04005958 }
5959
Adam Cohenf7522022012-10-03 20:03:18 -07005960 class ScreenLockTimeout implements Runnable {
5961 Bundle options;
5962
5963 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05005964 public void run() {
5965 synchronized (this) {
5966 if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard");
Jim Miller5ecd8112013-01-09 18:50:26 -08005967 if (mKeyguardDelegate != null) {
5968 mKeyguardDelegate.doKeyguardTimeout(options);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005969 }
Mike Lockwood28569302010-01-28 11:54:40 -05005970 mLockScreenTimerActive = false;
Adam Cohenf7522022012-10-03 20:03:18 -07005971 options = null;
Mike Lockwood28569302010-01-28 11:54:40 -05005972 }
5973 }
Mike Lockwood28569302010-01-28 11:54:40 -05005974
Adam Cohenf7522022012-10-03 20:03:18 -07005975 public void setLockOptions(Bundle options) {
5976 this.options = options;
5977 }
5978 }
5979
5980 ScreenLockTimeout mScreenLockTimeout = new ScreenLockTimeout();
5981
Jose Lima9546b202014-07-02 17:21:51 -07005982 @Override
Adam Cohenf7522022012-10-03 20:03:18 -07005983 public void lockNow(Bundle options) {
Jim Miller93c518e2012-01-17 15:55:31 -08005984 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null);
5985 mHandler.removeCallbacks(mScreenLockTimeout);
Adam Cohenf7522022012-10-03 20:03:18 -07005986 if (options != null) {
5987 // In case multiple calls are made to lockNow, we don't wipe out the options
5988 // until the runnable actually executes.
5989 mScreenLockTimeout.setLockOptions(options);
5990 }
Jim Miller93c518e2012-01-17 15:55:31 -08005991 mHandler.post(mScreenLockTimeout);
5992 }
5993
Mike Lockwood28569302010-01-28 11:54:40 -05005994 private void updateLockScreenTimeout() {
5995 synchronized (mScreenLockTimeout) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005996 boolean enable = (mAllowLockscreenWhenOn && mAwake &&
Jim Miller5ecd8112013-01-09 18:50:26 -08005997 mKeyguardDelegate != null && mKeyguardDelegate.isSecure());
Mike Lockwood28569302010-01-28 11:54:40 -05005998 if (mLockScreenTimerActive != enable) {
5999 if (enable) {
6000 if (localLOGV) Log.v(TAG, "setting lockscreen timer");
6001 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
6002 } else {
6003 if (localLOGV) Log.v(TAG, "clearing lockscreen timer");
6004 mHandler.removeCallbacks(mScreenLockTimeout);
6005 }
6006 mLockScreenTimerActive = enable;
6007 }
6008 }
6009 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006010
Jeff Brown061ea992015-04-17 19:55:47 -07006011 private void updateDreamingSleepToken(boolean acquire) {
6012 if (acquire) {
6013 if (mDreamingSleepToken == null) {
6014 mDreamingSleepToken = mActivityManagerInternal.acquireSleepToken("Dream");
6015 }
6016 } else {
6017 if (mDreamingSleepToken != null) {
6018 mDreamingSleepToken.release();
6019 }
6020 }
6021 }
6022
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006023 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07006024 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006025 public void enableScreenAfterBoot() {
6026 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07006027 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07006028 updateRotation(true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006029 }
Dianne Hackbornf54c8f92009-09-19 14:03:57 -07006030
Jeff Brownc458ce92012-04-30 14:58:40 -07006031 private void applyLidSwitchState() {
Jeff Brownc458ce92012-04-30 14:58:40 -07006032 if (mLidState == LID_CLOSED && mLidControlsSleep) {
Jeff Brown6d8fd272014-05-20 21:24:38 -07006033 mPowerManager.goToSleep(SystemClock.uptimeMillis(),
Jeff Brownc12035c2014-08-13 18:52:25 -07006034 PowerManager.GO_TO_SLEEP_REASON_LID_SWITCH,
Jeff Brown6d8fd272014-05-20 21:24:38 -07006035 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
Jeff Brownc458ce92012-04-30 14:58:40 -07006036 }
Jeff Browna20dda42014-05-27 20:57:24 -07006037
6038 synchronized (mLock) {
6039 updateWakeGestureListenerLp();
6040 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006041 }
6042
Jeff Brown4f5fa282014-06-12 19:19:15 -07006043 void updateUiMode() {
6044 if (mUiModeManager == null) {
6045 mUiModeManager = IUiModeManager.Stub.asInterface(
6046 ServiceManager.getService(Context.UI_MODE_SERVICE));
6047 }
6048 try {
6049 mUiMode = mUiModeManager.getCurrentModeType();
6050 } catch (RemoteException e) {
6051 }
6052 }
6053
Jeff Brown01a98dd2011-09-20 15:08:29 -07006054 void updateRotation(boolean alwaysSendConfiguration) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006055 try {
6056 //set orientation on WindowManager
Dianne Hackbornf87d1962012-04-04 12:48:24 -07006057 mWindowManager.updateRotation(alwaysSendConfiguration, false);
6058 } catch (RemoteException e) {
6059 // Ignore
6060 }
6061 }
6062
6063 void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) {
6064 try {
6065 //set orientation on WindowManager
6066 mWindowManager.updateRotation(alwaysSendConfiguration, forceRelayout);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006067 } catch (RemoteException e) {
6068 // Ignore
6069 }
6070 }
6071
Daniel Sandler6396c722013-04-16 20:19:09 -04006072 /**
6073 * Return an Intent to launch the currently active dock app as home. Returns
6074 * null if the standard home should be launched, which is the case if any of the following is
6075 * true:
6076 * <ul>
6077 * <li>The device is not in either car mode or desk mode
6078 * <li>The device is in car mode but ENABLE_CAR_DOCK_HOME_CAPTURE is false
6079 * <li>The device is in desk mode but ENABLE_DESK_DOCK_HOME_CAPTURE is false
6080 * <li>The device is in car mode but there's no CAR_DOCK app with METADATA_DOCK_HOME
6081 * <li>The device is in desk mode but there's no DESK_DOCK app with METADATA_DOCK_HOME
6082 * </ul>
Craig Mautnereda67292013-04-28 13:50:14 -07006083 * @return A dock intent.
Daniel Sandler6396c722013-04-16 20:19:09 -04006084 */
6085 Intent createHomeDockIntent() {
6086 Intent intent = null;
6087
6088 // What home does is based on the mode, not the dock state. That
6089 // is, when in car mode you should be taken to car home regardless
6090 // of whether we are actually in a car dock.
6091 if (mUiMode == Configuration.UI_MODE_TYPE_CAR) {
6092 if (ENABLE_CAR_DOCK_HOME_CAPTURE) {
6093 intent = mCarDockIntent;
6094 }
6095 } else if (mUiMode == Configuration.UI_MODE_TYPE_DESK) {
6096 if (ENABLE_DESK_DOCK_HOME_CAPTURE) {
6097 intent = mDeskDockIntent;
6098 }
Jeff Brown4f5fa282014-06-12 19:19:15 -07006099 } else if (mUiMode == Configuration.UI_MODE_TYPE_WATCH
6100 && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
6101 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK
6102 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK)) {
6103 // Always launch dock home from home when watch is docked, if it exists.
6104 intent = mDeskDockIntent;
Daniel Sandler6396c722013-04-16 20:19:09 -04006105 }
6106
6107 if (intent == null) {
6108 return null;
6109 }
6110
6111 ActivityInfo ai = null;
6112 ResolveInfo info = mContext.getPackageManager().resolveActivityAsUser(
6113 intent,
John Spurlockf56bef12013-07-09 09:51:46 -04006114 PackageManager.MATCH_DEFAULT_ONLY | PackageManager.GET_META_DATA,
Craig Mautnerd625ab22013-09-06 13:40:31 -07006115 mCurrentUserId);
Daniel Sandler6396c722013-04-16 20:19:09 -04006116 if (info != null) {
6117 ai = info.activityInfo;
6118 }
6119 if (ai != null
6120 && ai.metaData != null
6121 && ai.metaData.getBoolean(Intent.METADATA_DOCK_HOME)) {
6122 intent = new Intent(intent);
6123 intent.setClassName(ai.packageName, ai.name);
6124 return intent;
6125 }
6126
6127 return null;
6128 }
6129
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00006130 void startDockOrHome(boolean fromHomeKey, boolean awakenFromDreams) {
6131 if (awakenFromDreams) {
6132 awakenDreams();
6133 }
Daniel Sandler6396c722013-04-16 20:19:09 -04006134
6135 Intent dock = createHomeDockIntent();
6136 if (dock != null) {
6137 try {
Bryce Lee01b0c5f2015-02-05 18:24:04 -08006138 if (fromHomeKey) {
6139 dock.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
6140 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00006141 startActivityAsUser(dock, UserHandle.CURRENT);
Daniel Sandler6396c722013-04-16 20:19:09 -04006142 return;
6143 } catch (ActivityNotFoundException e) {
6144 }
6145 }
6146
Bryce Lee01b0c5f2015-02-05 18:24:04 -08006147 Intent intent;
6148
6149 if (fromHomeKey) {
6150 intent = new Intent(mHomeIntent);
6151 intent.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
6152 } else {
6153 intent = mHomeIntent;
6154 }
6155
Bryce Lee9fc0b6f2015-03-19 21:37:45 +00006156 startActivityAsUser(intent, UserHandle.CURRENT);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006157 }
Craig Mautnereda67292013-04-28 13:50:14 -07006158
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006159 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006160 * goes to the home screen
6161 * @return whether it did anything
6162 */
6163 boolean goHome() {
Bart Sears8b1c27c2015-03-18 23:51:02 +00006164 if (!isUserSetupComplete()) {
6165 Slog.i(TAG, "Not going home because user setup is in progress.");
6166 return false;
6167 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006168 if (false) {
6169 // This code always brings home to the front.
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07006170 try {
6171 ActivityManagerNative.getDefault().stopAppSwitches();
6172 } catch (RemoteException e) {
6173 }
Dianne Hackborn94a679d2009-07-28 17:51:07 -07006174 sendCloseSystemWindows();
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00006175 startDockOrHome(false /*fromHomeKey*/, true /* awakenFromDreams */);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006176 } else {
6177 // This code brings home to the front or, if it is already
6178 // at the front, puts the device to sleep.
6179 try {
Wink Savilled2e6a332010-02-12 12:12:06 -08006180 if (SystemProperties.getInt("persist.sys.uts-test-mode", 0) == 1) {
6181 /// Roll back EndcallBehavior as the cupcake design to pass P1 lab entry.
6182 Log.d(TAG, "UTS-TEST-MODE");
6183 } else {
6184 ActivityManagerNative.getDefault().stopAppSwitches();
6185 sendCloseSystemWindows();
Daniel Sandler6396c722013-04-16 20:19:09 -04006186 Intent dock = createHomeDockIntent();
6187 if (dock != null) {
6188 int result = ActivityManagerNative.getDefault()
6189 .startActivityAsUser(null, null, dock,
6190 dock.resolveTypeIfNeeded(mContext.getContentResolver()),
6191 null, null, 0,
6192 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07006193 null, null, UserHandle.USER_CURRENT);
Daniel Sandler6396c722013-04-16 20:19:09 -04006194 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
6195 return false;
6196 }
6197 }
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006198 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006199 int result = ActivityManagerNative.getDefault()
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006200 .startActivityAsUser(null, null, mHomeIntent,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006201 mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()),
Dianne Hackborna4972e92012-03-14 10:38:05 -07006202 null, null, 0,
6203 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07006204 null, null, UserHandle.USER_CURRENT);
Dianne Hackborna4972e92012-03-14 10:38:05 -07006205 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006206 return false;
6207 }
6208 } catch (RemoteException ex) {
6209 // bummer, the activity manager, which is in this process, is dead
6210 }
6211 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006212 return true;
6213 }
Craig Mautnereda67292013-04-28 13:50:14 -07006214
6215 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07006216 public void setCurrentOrientationLw(int newOrientation) {
6217 synchronized (mLock) {
6218 if (newOrientation != mCurrentAppOrientation) {
6219 mCurrentAppOrientation = newOrientation;
6220 updateOrientationListenerLp();
6221 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006222 }
6223 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006224
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07006225 private void performAuditoryFeedbackForAccessibilityIfNeed() {
6226 if (!isGlobalAccessibilityGestureEnabled()) {
6227 return;
6228 }
6229 AudioManager audioManager = (AudioManager) mContext.getSystemService(
6230 Context.AUDIO_SERVICE);
6231 if (audioManager.isSilentMode()) {
6232 return;
6233 }
6234 Ringtone ringTone = RingtoneManager.getRingtone(mContext,
6235 Settings.System.DEFAULT_NOTIFICATION_URI);
6236 ringTone.setStreamType(AudioManager.STREAM_MUSIC);
6237 ringTone.play();
6238 }
Craig Mautnereda67292013-04-28 13:50:14 -07006239
Bryce Lee584a4452014-10-21 15:55:55 -07006240 private boolean isTheaterModeEnabled() {
6241 return Settings.Global.getInt(mContext.getContentResolver(),
6242 Settings.Global.THEATER_MODE_ON, 0) == 1;
6243 }
6244
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07006245 private boolean isGlobalAccessibilityGestureEnabled() {
6246 return Settings.Global.getInt(mContext.getContentResolver(),
6247 Settings.Global.ENABLE_ACCESSIBILITY_GLOBAL_GESTURE_ENABLED, 0) == 1;
6248 }
6249
Craig Mautnereda67292013-04-28 13:50:14 -07006250 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07006251 public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) {
Svetoslav Ganov96179212012-10-10 14:17:45 -07006252 if (!mVibrator.hasVibrator()) {
6253 return false;
6254 }
Christopher Tate5e08af02012-09-21 17:17:22 -07006255 final boolean hapticsDisabled = Settings.System.getIntForUser(mContext.getContentResolver(),
6256 Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) == 0;
Jeff Brown82379ba2014-07-25 19:03:28 -07006257 if (hapticsDisabled && !always) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006258 return false;
6259 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006260 long[] pattern = null;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006261 switch (effectId) {
6262 case HapticFeedbackConstants.LONG_PRESS:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006263 pattern = mLongPressVibePattern;
6264 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006265 case HapticFeedbackConstants.VIRTUAL_KEY:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006266 pattern = mVirtualKeyVibePattern;
6267 break;
6268 case HapticFeedbackConstants.KEYBOARD_TAP:
6269 pattern = mKeyboardTapVibePattern;
6270 break;
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07006271 case HapticFeedbackConstants.CLOCK_TICK:
6272 pattern = mClockTickVibePattern;
6273 break;
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07006274 case HapticFeedbackConstants.CALENDAR_DATE:
6275 pattern = mCalendarDateVibePattern;
6276 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006277 case HapticFeedbackConstants.SAFE_MODE_DISABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006278 pattern = mSafeModeDisabledVibePattern;
6279 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006280 case HapticFeedbackConstants.SAFE_MODE_ENABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006281 pattern = mSafeModeEnabledVibePattern;
6282 break;
Mady Mellore82067b2015-04-30 09:58:35 -07006283 case HapticFeedbackConstants.STYLUS_BUTTON_PRESS:
6284 pattern = mStylusButtonPressVibePattern;
6285 break;
Amith Yamasanic33cb712010-02-10 15:21:49 -08006286 default:
6287 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006288 }
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006289 int owningUid;
6290 String owningPackage;
6291 if (win != null) {
6292 owningUid = win.getOwningUid();
6293 owningPackage = win.getOwningPackage();
6294 } else {
6295 owningUid = android.os.Process.myUid();
Dianne Hackborn95d78532013-09-11 09:51:14 -07006296 owningPackage = mContext.getOpPackageName();
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006297 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006298 if (pattern.length == 1) {
6299 // One-shot vibration
John Spurlock7b414672014-07-18 13:02:39 -04006300 mVibrator.vibrate(owningUid, owningPackage, pattern[0], VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08006301 } else {
6302 // Pattern vibration
John Spurlock7b414672014-07-18 13:02:39 -04006303 mVibrator.vibrate(owningUid, owningPackage, pattern, -1, VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08006304 }
6305 return true;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006306 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07006307
6308 @Override
6309 public void keepScreenOnStartedLw() {
Daniel Sandler0601eb72011-04-13 01:01:32 -04006310 }
6311
Jeff Brownc38c9be2012-10-04 13:16:19 -07006312 @Override
6313 public void keepScreenOnStoppedLw() {
Jim Millerab954542014-10-10 18:21:49 -07006314 if (isKeyguardShowingAndNotOccluded()) {
Jim Miller25190572013-02-28 17:36:24 -08006315 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006316 }
6317 }
Mike Lockwoodfcb39242009-10-21 23:01:07 -04006318
Dianne Hackborndf89e652011-10-06 22:35:11 -07006319 private int updateSystemUiVisibilityLw() {
Joe Onorato664644d2011-01-23 17:53:23 -08006320 // If there is no window focused, there will be nobody to handle the events
6321 // anyway, so just hang on in whatever state we're in until things settle down.
Adrian Roos53f28ec2014-10-29 17:26:12 +01006322 final WindowState win = mFocusedWindow != null ? mFocusedWindow
6323 : mTopFullscreenOpaqueWindowState;
John Spurlock79da8332013-09-20 12:04:47 -04006324 if (win == null) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006325 return 0;
6326 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01006327 if ((win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 && mHideLockScreen == true) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07006328 // We are updating at a point where the keyguard has gotten
6329 // focus, but we were last in a state where the top window is
6330 // hiding it. This is probably because the keyguard as been
6331 // shown while the top window was displayed, so we want to ignore
6332 // it here because this is just a very transient change and it
6333 // will quickly lose focus once it correctly gets hidden.
6334 return 0;
6335 }
John Spurlock32beb2c2013-03-11 10:16:47 -04006336
John Spurlock1db8b682014-02-18 11:18:59 -05006337 int tmpVisibility = PolicyControl.getSystemUiVisibility(win, null)
Dianne Hackborne26ab702011-10-16 13:21:33 -07006338 & ~mResettingSystemUiFlags
6339 & ~mForceClearedSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04006340 if (mForcingShowNavBar && win.getSurfaceLayer() < mForcingShowNavBarLayer) {
John Spurlockc6d1c602014-01-17 15:22:06 -05006341 tmpVisibility &= ~PolicyControl.adjustClearableFlags(win, View.SYSTEM_UI_CLEARABLE_FLAGS);
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08006342 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01006343 tmpVisibility = updateLightStatusBarLw(tmpVisibility);
John Spurlock79da8332013-09-20 12:04:47 -04006344 final int visibility = updateSystemBarsLw(win, mLastSystemUiFlags, tmpVisibility);
John Spurlockad3e6cb2013-04-30 08:47:43 -04006345 final int diff = visibility ^ mLastSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04006346 final boolean needsMenu = win.getNeedsMenuLw(mTopFullscreenOpaqueWindowState);
Dianne Hackborne0f085d2011-11-30 18:41:15 -08006347 if (diff == 0 && mLastFocusNeedsMenu == needsMenu
John Spurlock79da8332013-09-20 12:04:47 -04006348 && mFocusedApp == win.getAppToken()) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006349 return 0;
6350 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07006351 mLastSystemUiFlags = visibility;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08006352 mLastFocusNeedsMenu = needsMenu;
John Spurlock79da8332013-09-20 12:04:47 -04006353 mFocusedApp = win.getAppToken();
Dianne Hackborndf89e652011-10-06 22:35:11 -07006354 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07006355 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07006356 public void run() {
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006357 try {
6358 IStatusBarService statusbar = getStatusBarService();
6359 if (statusbar != null) {
Adrian Roos53f28ec2014-10-29 17:26:12 +01006360 statusbar.setSystemUiVisibility(visibility, 0xffffffff, win.toString());
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006361 statusbar.topAppWindowChanged(needsMenu);
Joe Onorato664644d2011-01-23 17:53:23 -08006362 }
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006363 } catch (RemoteException e) {
6364 // re-acquire status bar service next time it is needed.
6365 mStatusBarService = null;
Joe Onorato664644d2011-01-23 17:53:23 -08006366 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07006367 }
6368 });
6369 return diff;
Joe Onorato664644d2011-01-23 17:53:23 -08006370 }
6371
Adrian Rooscd3884d2015-02-18 17:25:23 +01006372 private int updateLightStatusBarLw(int vis) {
6373 WindowState statusColorWin = isStatusBarKeyguard() && !mHideLockScreen
6374 ? mStatusBar
6375 : mTopFullscreenOpaqueOrDimmingWindowState;
6376
6377 if (statusColorWin != null) {
6378 if (statusColorWin == mTopFullscreenOpaqueWindowState) {
6379 // If the top fullscreen-or-dimming window is also the top fullscreen, respect
6380 // its light flag.
6381 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6382 vis |= PolicyControl.getSystemUiVisibility(statusColorWin, null)
6383 & View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6384 } else if (statusColorWin != null && statusColorWin.isDimming()) {
6385 // Otherwise if it's dimming, clear the light flag.
6386 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6387 }
6388 }
6389 return vis;
6390 }
6391
John Spurlock79da8332013-09-20 12:04:47 -04006392 private int updateSystemBarsLw(WindowState win, int oldVis, int vis) {
John Spurlockbd957402013-10-03 11:38:39 -04006393 // apply translucent bar vis flags
Jorim Jaggi380ecb82014-03-14 17:25:20 +01006394 WindowState transWin = isStatusBarKeyguard() && !mHideLockScreen
6395 ? mStatusBar
John Spurlockbd957402013-10-03 11:38:39 -04006396 : mTopFullscreenOpaqueWindowState;
6397 vis = mStatusBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
6398 vis = mNavigationBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
6399
John Spurlock27735a42013-08-14 17:57:38 -04006400 // prevent status bar interaction from clearing certain flags
Selim Cinekf83e8242015-05-19 18:08:14 -07006401 int type = win.getAttrs().type;
6402 boolean statusBarHasFocus = type == TYPE_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04006403 if (statusBarHasFocus && !isStatusBarKeyguard()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04006404 int flags = View.SYSTEM_UI_FLAG_FULLSCREEN
6405 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlockcfc359a2013-09-05 10:42:03 -04006406 | View.SYSTEM_UI_FLAG_IMMERSIVE
Jorim Jaggi73fef8d2015-02-16 17:32:28 +01006407 | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
6408 | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04006409 if (mHideLockScreen) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01006410 flags |= View.STATUS_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSLUCENT;
6411 }
John Spurlockbd957402013-10-03 11:38:39 -04006412 vis = (vis & ~flags) | (oldVis & flags);
John Spurlockad3e6cb2013-04-30 08:47:43 -04006413 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04006414
Adrian Roos4fb3ee32014-08-22 19:29:09 +02006415 if (!areTranslucentBarsAllowed() && transWin != mStatusBar) {
Adrian Roosea562512014-05-05 13:33:03 +02006416 vis &= ~(View.NAVIGATION_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSLUCENT
6417 | View.SYSTEM_UI_TRANSPARENT);
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006418 }
6419
John Spurlock27735a42013-08-14 17:57:38 -04006420 // update status bar
John Spurlockf1a36642013-10-12 17:50:42 -04006421 boolean immersiveSticky =
6422 (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
John Spurlock27735a42013-08-14 17:57:38 -04006423 boolean hideStatusBarWM =
John Spurlockbd957402013-10-03 11:38:39 -04006424 mTopFullscreenOpaqueWindowState != null &&
John Spurlockc6d1c602014-01-17 15:22:06 -05006425 (PolicyControl.getWindowFlags(mTopFullscreenOpaqueWindowState, null)
John Spurlock27735a42013-08-14 17:57:38 -04006426 & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0;
6427 boolean hideStatusBarSysui =
6428 (vis & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04006429 boolean hideNavBarSysui =
6430 (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006431
John Spurlock27735a42013-08-14 17:57:38 -04006432 boolean transientStatusBarAllowed =
6433 mStatusBar != null && (
6434 hideStatusBarWM
John Spurlockf1a36642013-10-12 17:50:42 -04006435 || (hideStatusBarSysui && immersiveSticky)
John Spurlock27735a42013-08-14 17:57:38 -04006436 || statusBarHasFocus);
6437
John Spurlockf1a36642013-10-12 17:50:42 -04006438 boolean transientNavBarAllowed =
6439 mNavigationBar != null &&
6440 hideNavBarSysui && immersiveSticky;
6441
Adrian Roosddc8b272015-05-21 16:28:27 -07006442 final long now = SystemClock.uptimeMillis();
6443 final boolean pendingPanic = mPendingPanicGestureUptime != 0
6444 && now - mPendingPanicGestureUptime <= PANIC_GESTURE_EXPIRATION;
6445 if (pendingPanic && hideNavBarSysui && !isStatusBarKeyguard() && mKeyguardDrawComplete) {
6446 // The user performed the panic gesture recently, we're about to hide the bars,
6447 // we're no longer on the Keyguard and the screen is ready. We can now request the bars.
6448 mPendingPanicGestureUptime = 0;
6449 mStatusBarController.showTransient();
6450 mNavigationBarController.showTransient();
6451 }
6452
John Spurlockf25706f2013-11-07 18:02:43 -05006453 boolean denyTransientStatus = mStatusBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04006454 && !transientStatusBarAllowed && hideStatusBarSysui;
John Spurlockf25706f2013-11-07 18:02:43 -05006455 boolean denyTransientNav = mNavigationBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04006456 && !transientNavBarAllowed;
6457 if (denyTransientStatus || denyTransientNav) {
John Spurlock27735a42013-08-14 17:57:38 -04006458 // clear the clearable flags instead
John Spurlockf1a36642013-10-12 17:50:42 -04006459 clearClearableFlagsLw();
tiger_huangc58d7562014-10-23 20:24:19 +08006460 vis &= ~View.SYSTEM_UI_CLEARABLE_FLAGS;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006461 }
John Spurlock27735a42013-08-14 17:57:38 -04006462
Selim Cinekf98702e2015-05-20 22:48:40 -07006463 final boolean immersive = (vis & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
6464 immersiveSticky = (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
6465 final boolean navAllowedHidden = immersive || immersiveSticky;
6466
Selim Cinekd6623612015-05-22 18:56:22 -07006467 if (hideNavBarSysui && !navAllowedHidden && windowTypeToLayerLw(win.getBaseType())
6468 > windowTypeToLayerLw(TYPE_INPUT_CONSUMER)) {
Selim Cinekf98702e2015-05-20 22:48:40 -07006469 // We can't hide the navbar from this window otherwise the input consumer would not get
6470 // the input events.
6471 vis = (vis & ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
6472 }
6473
John Spurlock27735a42013-08-14 17:57:38 -04006474 vis = mStatusBarController.updateVisibilityLw(transientStatusBarAllowed, oldVis, vis);
6475
6476 // update navigation bar
John Spurlockf1a36642013-10-12 17:50:42 -04006477 boolean oldImmersiveMode = isImmersiveMode(oldVis);
6478 boolean newImmersiveMode = isImmersiveMode(vis);
6479 if (win != null && oldImmersiveMode != newImmersiveMode) {
John Spurlock79da8332013-09-20 12:04:47 -04006480 final String pkg = win.getOwningPackage();
Maurice Lam99c6e072014-04-28 18:24:28 -07006481 mImmersiveModeConfirmation.immersiveModeChanged(pkg, newImmersiveMode,
6482 isUserSetupComplete());
John Spurlock34e13d92013-08-10 06:52:28 -04006483 }
John Spurlock27735a42013-08-14 17:57:38 -04006484
John Spurlockf1a36642013-10-12 17:50:42 -04006485 vis = mNavigationBarController.updateVisibilityLw(transientNavBarAllowed, oldVis, vis);
6486
John Spurlocke1f366f2013-08-05 12:22:40 -04006487 return vis;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006488 }
6489
John Spurlockf1a36642013-10-12 17:50:42 -04006490 private void clearClearableFlagsLw() {
6491 int newVal = mResettingSystemUiFlags | View.SYSTEM_UI_CLEARABLE_FLAGS;
6492 if (newVal != mResettingSystemUiFlags) {
6493 mResettingSystemUiFlags = newVal;
6494 mWindowManagerFuncs.reevaluateStatusBarVisibility();
6495 }
6496 }
6497
6498 private boolean isImmersiveMode(int vis) {
6499 final int flags = View.SYSTEM_UI_FLAG_IMMERSIVE | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
John Spurlock34e13d92013-08-10 06:52:28 -04006500 return mNavigationBar != null
6501 && (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0
Daniel Sandler900ece52013-10-18 15:53:27 -04006502 && (vis & flags) != 0
6503 && canHideNavigationBar();
John Spurlock34e13d92013-08-10 06:52:28 -04006504 }
6505
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006506 /**
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04006507 * @return whether the navigation or status bar can be made translucent
6508 *
6509 * This should return true unless touch exploration is not enabled or
6510 * R.boolean.config_enableTranslucentDecor is false.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006511 */
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04006512 private boolean areTranslucentBarsAllowed() {
Svetoslav8e3feb12014-02-24 13:46:47 -08006513 return mTranslucentDecorEnabled
6514 && !mAccessibilityManager.isTouchExplorationEnabled();
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006515 }
6516
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04006517 // Use this instead of checking config_showNavigationBar so that it can be consistently
6518 // overridden by qemu.hw.mainkeys in the emulator.
Craig Mautnereda67292013-04-28 13:50:14 -07006519 @Override
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04006520 public boolean hasNavigationBar() {
6521 return mHasNavigationBar;
6522 }
6523
satok1bc0a492012-04-25 22:47:12 +09006524 @Override
6525 public void setLastInputMethodWindowLw(WindowState ime, WindowState target) {
6526 mLastInputMethodWindow = ime;
6527 mLastInputMethodTargetWindow = target;
6528 }
6529
Craig Mautnerf1b67412012-09-19 13:18:29 -07006530 @Override
Satoshi Kataoka658c7b82013-10-10 17:03:51 +09006531 public int getInputMethodWindowVisibleHeightLw() {
6532 return mDockBottom - mCurBottom;
6533 }
6534
6535 @Override
Craig Mautnerf1b67412012-09-19 13:18:29 -07006536 public void setCurrentUserLw(int newUserId) {
Craig Mautnerd625ab22013-09-06 13:40:31 -07006537 mCurrentUserId = newUserId;
Jim Miller5ecd8112013-01-09 18:50:26 -08006538 if (mKeyguardDelegate != null) {
6539 mKeyguardDelegate.setCurrentUser(newUserId);
Craig Mautnerf1b67412012-09-19 13:18:29 -07006540 }
John Spurlock13451a22012-09-28 14:40:41 -04006541 if (mStatusBarService != null) {
6542 try {
6543 mStatusBarService.setCurrentUser(newUserId);
6544 } catch (RemoteException e) {
6545 // oh well
6546 }
6547 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006548 setLastInputMethodWindowLw(null, null);
Craig Mautnerf1b67412012-09-19 13:18:29 -07006549 }
6550
6551 @Override
Svetoslav Ganov545252f2012-12-10 18:29:24 -08006552 public boolean canMagnifyWindow(int windowType) {
6553 switch (windowType) {
6554 case WindowManager.LayoutParams.TYPE_INPUT_METHOD:
6555 case WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG:
6556 case WindowManager.LayoutParams.TYPE_NAVIGATION_BAR:
6557 case WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY: {
6558 return false;
6559 }
6560 }
6561 return true;
6562 }
6563
6564 @Override
6565 public boolean isTopLevelWindow(int windowType) {
6566 if (windowType >= WindowManager.LayoutParams.FIRST_SUB_WINDOW
6567 && windowType <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
6568 return (windowType == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG);
6569 }
6570 return true;
6571 }
6572
Jim Miller4eeb4f62012-11-08 00:04:29 -08006573 @Override
Jeff Brownd7a04de2012-06-17 14:17:52 -07006574 public void dump(String prefix, PrintWriter pw, String[] args) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006575 pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07006576 pw.print(" mSystemReady="); pw.print(mSystemReady);
6577 pw.print(" mSystemBooted="); pw.println(mSystemBooted);
Jeff Brown2e7760e2012-04-11 15:14:55 -07006578 pw.print(prefix); pw.print("mLidState="); pw.print(mLidState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006579 pw.print(" mLidOpenRotation="); pw.print(mLidOpenRotation);
Michael Wright3818c922014-09-02 13:59:07 -07006580 pw.print(" mCameraLensCoverState="); pw.print(mCameraLensCoverState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006581 pw.print(" mHdmiPlugged="); pw.println(mHdmiPlugged);
Dianne Hackborne26ab702011-10-16 13:21:33 -07006582 if (mLastSystemUiFlags != 0 || mResettingSystemUiFlags != 0
6583 || mForceClearedSystemUiFlags != 0) {
6584 pw.print(prefix); pw.print("mLastSystemUiFlags=0x");
6585 pw.print(Integer.toHexString(mLastSystemUiFlags));
6586 pw.print(" mResettingSystemUiFlags=0x");
6587 pw.print(Integer.toHexString(mResettingSystemUiFlags));
6588 pw.print(" mForceClearedSystemUiFlags=0x");
6589 pw.println(Integer.toHexString(mForceClearedSystemUiFlags));
Dianne Hackborndf89e652011-10-06 22:35:11 -07006590 }
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08006591 if (mLastFocusNeedsMenu) {
6592 pw.print(prefix); pw.print("mLastFocusNeedsMenu=");
6593 pw.println(mLastFocusNeedsMenu);
6594 }
Jeff Browna20dda42014-05-27 20:57:24 -07006595 pw.print(prefix); pw.print("mWakeGestureEnabledSetting=");
6596 pw.println(mWakeGestureEnabledSetting);
6597
Jeff Brownbcdfc622014-03-06 19:13:04 -08006598 pw.print(prefix); pw.print("mSupportAutoRotation="); pw.println(mSupportAutoRotation);
Daniel Sandler6396c722013-04-16 20:19:09 -04006599 pw.print(prefix); pw.print("mUiMode="); pw.print(mUiMode);
6600 pw.print(" mDockMode="); pw.print(mDockMode);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006601 pw.print(" mCarDockRotation="); pw.print(mCarDockRotation);
6602 pw.print(" mDeskDockRotation="); pw.println(mDeskDockRotation);
6603 pw.print(prefix); pw.print("mUserRotationMode="); pw.print(mUserRotationMode);
6604 pw.print(" mUserRotation="); pw.print(mUserRotation);
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05006605 pw.print(" mAllowAllRotations="); pw.println(mAllowAllRotations);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07006606 pw.print(prefix); pw.print("mCurrentAppOrientation="); pw.println(mCurrentAppOrientation);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006607 pw.print(prefix); pw.print("mCarDockEnablesAccelerometer=");
6608 pw.print(mCarDockEnablesAccelerometer);
6609 pw.print(" mDeskDockEnablesAccelerometer=");
6610 pw.println(mDeskDockEnablesAccelerometer);
6611 pw.print(prefix); pw.print("mLidKeyboardAccessibility=");
6612 pw.print(mLidKeyboardAccessibility);
6613 pw.print(" mLidNavigationAccessibility="); pw.print(mLidNavigationAccessibility);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07006614 pw.print(" mLidControlsSleep="); pw.println(mLidControlsSleep);
Jeff Brown6d8fd272014-05-20 21:24:38 -07006615 pw.print(prefix);
6616 pw.print("mShortPressOnPowerBehavior="); pw.print(mShortPressOnPowerBehavior);
6617 pw.print(" mLongPressOnPowerBehavior="); pw.println(mLongPressOnPowerBehavior);
Jeff Brown13f00f02014-10-31 14:45:50 -07006618 pw.print(prefix);
6619 pw.print("mDoublePressOnPowerBehavior="); pw.print(mDoublePressOnPowerBehavior);
6620 pw.print(" mTriplePressOnPowerBehavior="); pw.println(mTriplePressOnPowerBehavior);
Jeff Brown6d8fd272014-05-20 21:24:38 -07006621 pw.print(prefix); pw.print("mHasSoftInput="); pw.println(mHasSoftInput);
Jeff Brown3ee549c2014-09-22 20:14:39 -07006622 pw.print(prefix); pw.print("mAwake="); pw.println(mAwake);
6623 pw.print(prefix); pw.print("mScreenOnEarly="); pw.print(mScreenOnEarly);
6624 pw.print(" mScreenOnFully="); pw.println(mScreenOnFully);
6625 pw.print(prefix); pw.print("mKeyguardDrawComplete="); pw.print(mKeyguardDrawComplete);
6626 pw.print(" mWindowManagerDrawComplete="); pw.println(mWindowManagerDrawComplete);
6627 pw.print(prefix); pw.print("mOrientationSensorEnabled=");
6628 pw.println(mOrientationSensorEnabled);
Dianne Hackbornc652de82013-02-15 16:32:56 -08006629 pw.print(prefix); pw.print("mOverscanScreen=("); pw.print(mOverscanScreenLeft);
6630 pw.print(","); pw.print(mOverscanScreenTop);
6631 pw.print(") "); pw.print(mOverscanScreenWidth);
6632 pw.print("x"); pw.println(mOverscanScreenHeight);
6633 if (mOverscanLeft != 0 || mOverscanTop != 0
6634 || mOverscanRight != 0 || mOverscanBottom != 0) {
6635 pw.print(prefix); pw.print("mOverscan left="); pw.print(mOverscanLeft);
6636 pw.print(" top="); pw.print(mOverscanTop);
6637 pw.print(" right="); pw.print(mOverscanRight);
6638 pw.print(" bottom="); pw.println(mOverscanBottom);
6639 }
Dianne Hackborn313440842013-02-19 19:22:59 -08006640 pw.print(prefix); pw.print("mRestrictedOverscanScreen=(");
6641 pw.print(mRestrictedOverscanScreenLeft);
6642 pw.print(","); pw.print(mRestrictedOverscanScreenTop);
6643 pw.print(") "); pw.print(mRestrictedOverscanScreenWidth);
6644 pw.print("x"); pw.println(mRestrictedOverscanScreenHeight);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006645 pw.print(prefix); pw.print("mUnrestrictedScreen=("); pw.print(mUnrestrictedScreenLeft);
6646 pw.print(","); pw.print(mUnrestrictedScreenTop);
6647 pw.print(") "); pw.print(mUnrestrictedScreenWidth);
6648 pw.print("x"); pw.println(mUnrestrictedScreenHeight);
6649 pw.print(prefix); pw.print("mRestrictedScreen=("); pw.print(mRestrictedScreenLeft);
6650 pw.print(","); pw.print(mRestrictedScreenTop);
6651 pw.print(") "); pw.print(mRestrictedScreenWidth);
6652 pw.print("x"); pw.println(mRestrictedScreenHeight);
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07006653 pw.print(prefix); pw.print("mStableFullscreen=("); pw.print(mStableFullscreenLeft);
6654 pw.print(","); pw.print(mStableFullscreenTop);
6655 pw.print(")-("); pw.print(mStableFullscreenRight);
6656 pw.print(","); pw.print(mStableFullscreenBottom); pw.println(")");
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07006657 pw.print(prefix); pw.print("mStable=("); pw.print(mStableLeft);
6658 pw.print(","); pw.print(mStableTop);
6659 pw.print(")-("); pw.print(mStableRight);
6660 pw.print(","); pw.print(mStableBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07006661 pw.print(prefix); pw.print("mSystem=("); pw.print(mSystemLeft);
6662 pw.print(","); pw.print(mSystemTop);
6663 pw.print(")-("); pw.print(mSystemRight);
6664 pw.print(","); pw.print(mSystemBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006665 pw.print(prefix); pw.print("mCur=("); pw.print(mCurLeft);
6666 pw.print(","); pw.print(mCurTop);
6667 pw.print(")-("); pw.print(mCurRight);
6668 pw.print(","); pw.print(mCurBottom); pw.println(")");
6669 pw.print(prefix); pw.print("mContent=("); pw.print(mContentLeft);
6670 pw.print(","); pw.print(mContentTop);
6671 pw.print(")-("); pw.print(mContentRight);
6672 pw.print(","); pw.print(mContentBottom); pw.println(")");
Dianne Hackborne30e02f2014-05-27 18:24:45 -07006673 pw.print(prefix); pw.print("mVoiceContent=("); pw.print(mVoiceContentLeft);
6674 pw.print(","); pw.print(mVoiceContentTop);
6675 pw.print(")-("); pw.print(mVoiceContentRight);
6676 pw.print(","); pw.print(mVoiceContentBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006677 pw.print(prefix); pw.print("mDock=("); pw.print(mDockLeft);
6678 pw.print(","); pw.print(mDockTop);
6679 pw.print(")-("); pw.print(mDockRight);
6680 pw.print(","); pw.print(mDockBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07006681 pw.print(prefix); pw.print("mDockLayer="); pw.print(mDockLayer);
6682 pw.print(" mStatusBarLayer="); pw.println(mStatusBarLayer);
Dianne Hackborn7ad44382012-10-18 17:46:00 -07006683 pw.print(prefix); pw.print("mShowingLockscreen="); pw.print(mShowingLockscreen);
6684 pw.print(" mShowingDream="); pw.print(mShowingDream);
Jeff Brown061ea992015-04-17 19:55:47 -07006685 pw.print(" mDreamingLockscreen="); pw.print(mDreamingLockscreen);
6686 pw.print(" mDreamingSleepToken="); pw.println(mDreamingSleepToken);
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006687 if (mLastInputMethodWindow != null) {
6688 pw.print(prefix); pw.print("mLastInputMethodWindow=");
6689 pw.println(mLastInputMethodWindow);
6690 }
6691 if (mLastInputMethodTargetWindow != null) {
6692 pw.print(prefix); pw.print("mLastInputMethodTargetWindow=");
6693 pw.println(mLastInputMethodTargetWindow);
6694 }
6695 if (mStatusBar != null) {
6696 pw.print(prefix); pw.print("mStatusBar=");
Dianne Hackbornae6688b2015-02-11 17:02:41 -08006697 pw.print(mStatusBar); pw.print(" isStatusBarKeyguard=");
6698 pw.println(isStatusBarKeyguard());
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006699 }
6700 if (mNavigationBar != null) {
6701 pw.print(prefix); pw.print("mNavigationBar=");
6702 pw.println(mNavigationBar);
6703 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006704 if (mFocusedWindow != null) {
6705 pw.print(prefix); pw.print("mFocusedWindow=");
6706 pw.println(mFocusedWindow);
6707 }
6708 if (mFocusedApp != null) {
6709 pw.print(prefix); pw.print("mFocusedApp=");
6710 pw.println(mFocusedApp);
6711 }
6712 if (mWinDismissingKeyguard != null) {
6713 pw.print(prefix); pw.print("mWinDismissingKeyguard=");
6714 pw.println(mWinDismissingKeyguard);
6715 }
6716 if (mTopFullscreenOpaqueWindowState != null) {
6717 pw.print(prefix); pw.print("mTopFullscreenOpaqueWindowState=");
6718 pw.println(mTopFullscreenOpaqueWindowState);
6719 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01006720 if (mTopFullscreenOpaqueOrDimmingWindowState != null) {
6721 pw.print(prefix); pw.print("mTopFullscreenOpaqueOrDimmingWindowState=");
6722 pw.println(mTopFullscreenOpaqueOrDimmingWindowState);
6723 }
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08006724 if (mForcingShowNavBar) {
6725 pw.print(prefix); pw.print("mForcingShowNavBar=");
6726 pw.println(mForcingShowNavBar); pw.print( "mForcingShowNavBarLayer=");
6727 pw.println(mForcingShowNavBarLayer);
6728 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07006729 pw.print(prefix); pw.print("mTopIsFullscreen="); pw.print(mTopIsFullscreen);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006730 pw.print(" mHideLockScreen="); pw.println(mHideLockScreen);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07006731 pw.print(prefix); pw.print("mForceStatusBar="); pw.print(mForceStatusBar);
6732 pw.print(" mForceStatusBarFromKeyguard=");
6733 pw.println(mForceStatusBarFromKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006734 pw.print(prefix); pw.print("mDismissKeyguard="); pw.print(mDismissKeyguard);
Craig Mautnerad09bcc2012-10-08 13:33:11 -07006735 pw.print(" mWinDismissingKeyguard="); pw.print(mWinDismissingKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006736 pw.print(" mHomePressed="); pw.println(mHomePressed);
6737 pw.print(prefix); pw.print("mAllowLockscreenWhenOn="); pw.print(mAllowLockscreenWhenOn);
6738 pw.print(" mLockScreenTimeout="); pw.print(mLockScreenTimeout);
6739 pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive);
6740 pw.print(prefix); pw.print("mEndcallBehavior="); pw.print(mEndcallBehavior);
6741 pw.print(" mIncallPowerBehavior="); pw.print(mIncallPowerBehavior);
6742 pw.print(" mLongPressOnHomeBehavior="); pw.println(mLongPressOnHomeBehavior);
6743 pw.print(prefix); pw.print("mLandscapeRotation="); pw.print(mLandscapeRotation);
6744 pw.print(" mSeascapeRotation="); pw.println(mSeascapeRotation);
6745 pw.print(prefix); pw.print("mPortraitRotation="); pw.print(mPortraitRotation);
6746 pw.print(" mUpsideDownRotation="); pw.println(mUpsideDownRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07006747 pw.print(prefix); pw.print("mDemoHdmiRotation="); pw.print(mDemoHdmiRotation);
6748 pw.print(" mDemoHdmiRotationLock="); pw.println(mDemoHdmiRotationLock);
6749 pw.print(prefix); pw.print("mUndockedHdmiRotation="); pw.println(mUndockedHdmiRotation);
Jeff Brown600f0032014-05-22 17:06:00 -07006750
Tim Kilbournd7c0c2e2014-05-29 16:08:10 -07006751 mGlobalKeyManager.dump(prefix, pw);
John Spurlock27735a42013-08-14 17:57:38 -04006752 mStatusBarController.dump(pw, prefix);
6753 mNavigationBarController.dump(pw, prefix);
John Spurlockc6d1c602014-01-17 15:22:06 -05006754 PolicyControl.dump(prefix, pw);
Jeff Brown600f0032014-05-22 17:06:00 -07006755
Jeff Browna20dda42014-05-27 20:57:24 -07006756 if (mWakeGestureListener != null) {
6757 mWakeGestureListener.dump(pw, prefix);
6758 }
Jeff Brown600f0032014-05-22 17:06:00 -07006759 if (mOrientationListener != null) {
6760 mOrientationListener.dump(pw, prefix);
6761 }
Filip Gruszczynskicfb31852015-02-25 21:47:12 +00006762 if (mBurnInProtectionHelper != null) {
6763 mBurnInProtectionHelper.dump(prefix, pw);
6764 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006765 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006766}