blob: b8d06921f23500c841755e4f8239201ca3c25cbe [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
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001090 private void sleepPress(KeyEvent event) {
1091 switch (mShortPressOnSleepBehavior) {
1092 case SHORT_PRESS_SLEEP_GO_TO_SLEEP:
1093 mPowerManager.goToSleep(event.getEventTime(),
1094 PowerManager.GO_TO_SLEEP_REASON_SLEEP_BUTTON, 0);
1095 break;
1096 case SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME:
Bryce Lee662ed802015-04-10 20:11:39 +00001097 launchHomeFromHotKey(false /* awakenDreams */, true /*respectKeyguard*/);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001098 mPowerManager.goToSleep(event.getEventTime(),
1099 PowerManager.GO_TO_SLEEP_REASON_SLEEP_BUTTON, 0);
1100 break;
1101 }
1102 }
1103
Jeff Brown13f00f02014-10-31 14:45:50 -07001104 private int getResolvedLongPressOnPowerBehavior() {
1105 if (FactoryTest.isLongPressOnPowerOffEnabled()) {
1106 return LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM;
1107 }
1108 return mLongPressOnPowerBehavior;
1109 }
1110
1111 private boolean hasLongPressOnPowerBehavior() {
1112 return getResolvedLongPressOnPowerBehavior() != LONG_PRESS_POWER_NOTHING;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001113 }
1114
1115 private void interceptScreenshotChord() {
Christopher Tatee90585f2012-03-05 18:56:25 -08001116 if (mScreenshotChordEnabled
Jeff Brown13f00f02014-10-31 14:45:50 -07001117 && mScreenshotChordVolumeDownKeyTriggered && mScreenshotChordPowerKeyTriggered
1118 && !mScreenshotChordVolumeUpKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001119 final long now = SystemClock.uptimeMillis();
Jeff Brown13f00f02014-10-31 14:45:50 -07001120 if (now <= mScreenshotChordVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS
1121 && now <= mScreenshotChordPowerKeyTime
1122 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) {
1123 mScreenshotChordVolumeDownKeyConsumed = true;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001124 cancelPendingPowerKeyAction();
1125
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001126 mHandler.postDelayed(mScreenshotRunnable, getScreenshotChordLongPressDelay());
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001127 }
1128 }
1129 }
1130
Winson Chung1cea2f32012-10-08 20:42:01 -07001131 private long getScreenshotChordLongPressDelay() {
Jim Miller5ecd8112013-01-09 18:50:26 -08001132 if (mKeyguardDelegate.isShowing()) {
Winson Chung1cea2f32012-10-08 20:42:01 -07001133 // Double the time it takes to take a screenshot from the keyguard
1134 return (long) (KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER *
Justin Kohfeabd2c2014-05-02 10:02:44 -07001135 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Winson Chung1cea2f32012-10-08 20:42:01 -07001136 }
Justin Kohfeabd2c2014-05-02 10:02:44 -07001137 return ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout();
Winson Chung1cea2f32012-10-08 20:42:01 -07001138 }
1139
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001140 private void cancelPendingScreenshotChordAction() {
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001141 mHandler.removeCallbacks(mScreenshotRunnable);
Jeff Brown4d396052010-10-29 21:50:21 -07001142 }
1143
Jeff Brown13f00f02014-10-31 14:45:50 -07001144 private final Runnable mEndCallLongPress = new Runnable() {
Craig Mautnerf1b67412012-09-19 13:18:29 -07001145 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001146 public void run() {
Jeff Brown13f00f02014-10-31 14:45:50 -07001147 mEndCallKeyHandled = true;
1148 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
1149 performAuditoryFeedbackForAccessibilityIfNeed();
Joe Onoratod208e702010-10-08 16:22:43 -04001150 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001151 showGlobalActionsInternal();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001152 }
1153 };
1154
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001155 private final Runnable mScreenshotRunnable = new Runnable() {
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001156 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001157 public void run() {
1158 takeScreenshot();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001159 }
1160 };
1161
Alan Viverettee34560b22014-07-10 14:50:06 -07001162 @Override
1163 public void showGlobalActions() {
1164 mHandler.removeMessages(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
1165 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
1166 }
1167
1168 void showGlobalActionsInternal() {
1169 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001170 if (mGlobalActions == null) {
Jeff Brown7304c342012-05-11 18:42:42 -07001171 mGlobalActions = new GlobalActions(mContext, mWindowManagerFuncs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001172 }
Jim Millerab954542014-10-10 18:21:49 -07001173 final boolean keyguardShowing = isKeyguardShowingAndNotOccluded();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001174 mGlobalActions.showDialog(keyguardShowing, isDeviceProvisioned());
1175 if (keyguardShowing) {
1176 // since it took two seconds of long press to bring this up,
1177 // poke the wake lock so they have some time to see the dialog.
Jim Miller25190572013-02-28 17:36:24 -08001178 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001179 }
1180 }
1181
1182 boolean isDeviceProvisioned() {
Jeff Brownbf6f6f92012-09-25 15:03:20 -07001183 return Settings.Global.getInt(
1184 mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001185 }
1186
Maurice Lam99c6e072014-04-28 18:24:28 -07001187 boolean isUserSetupComplete() {
1188 return Settings.Secure.getIntForUser(mContext.getContentResolver(),
1189 Settings.Secure.USER_SETUP_COMPLETE, 0, UserHandle.USER_CURRENT) != 0;
1190 }
1191
Jeff Brown13f00f02014-10-31 14:45:50 -07001192 private void handleShortPressOnHome() {
1193 // If there's a dream running then use home to escape the dream
1194 // but don't actually go home.
1195 if (mDreamManagerInternal != null && mDreamManagerInternal.isDreaming()) {
1196 mDreamManagerInternal.stopDream(false /*immediate*/);
1197 return;
1198 }
1199
1200 // Go home!
1201 launchHomeFromHotKey();
1202 }
1203
Patrick Dubroyece94522011-02-23 18:35:01 -08001204 private void handleLongPressOnHome() {
Joe Onorato46b0d682010-11-22 17:37:27 -08001205 if (mLongPressOnHomeBehavior != LONG_PRESS_HOME_NOTHING) {
Jeff Browncaca8812013-05-09 13:34:33 -07001206 mHomeConsumed = true;
Joe Onorato46b0d682010-11-22 17:37:27 -08001207 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
Patrick Dubroyece94522011-02-23 18:35:01 -08001208
Jeff Browncaca8812013-05-09 13:34:33 -07001209 if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI) {
1210 toggleRecentApps();
1211 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_ASSIST) {
1212 launchAssistAction();
Jim Millere6ad1a82010-08-20 19:25:39 -07001213 }
1214 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001215 }
Patrick Dubroyece94522011-02-23 18:35:01 -08001216
Jeff Browncaca8812013-05-09 13:34:33 -07001217 private void handleDoubleTapOnHome() {
1218 if (mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1219 mHomeConsumed = true;
1220 toggleRecentApps();
1221 }
1222 }
1223
1224 private final Runnable mHomeDoubleTapTimeoutRunnable = new Runnable() {
1225 @Override
1226 public void run() {
1227 if (mHomeDoubleTapPending) {
1228 mHomeDoubleTapPending = false;
Jeff Brown13f00f02014-10-31 14:45:50 -07001229 handleShortPressOnHome();
Jeff Browncaca8812013-05-09 13:34:33 -07001230 }
1231 }
1232 };
1233
Mark Renoufc1256912015-03-11 14:38:23 -04001234 private boolean isRoundWindow() {
Adam Powell01f280d2015-05-18 16:07:42 -07001235 return mContext.getResources().getConfiguration().isScreenRound();
Mark Renoufc1256912015-03-11 14:38:23 -04001236 }
1237
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001238 /** {@inheritDoc} */
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001239 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001240 public void init(Context context, IWindowManager windowManager,
Jeff Brown96307042012-07-27 15:51:34 -07001241 WindowManagerFuncs windowManagerFuncs) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001242 mContext = context;
1243 mWindowManager = windowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -07001244 mWindowManagerFuncs = windowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -07001245 mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class);
Jeff Brown061ea992015-04-17 19:55:47 -07001246 mActivityManagerInternal = LocalServices.getService(ActivityManagerInternal.class);
Jose Lima9546b202014-07-02 17:21:51 -07001247 mDreamManagerInternal = LocalServices.getService(DreamManagerInternal.class);
Mark Renoufc1256912015-03-11 14:38:23 -04001248
1249 // Init display burn-in protection
1250 boolean burnInProtectionEnabled = context.getResources().getBoolean(
1251 com.android.internal.R.bool.config_enableBurnInProtection);
1252 // Allow a system property to override this. Used by developer settings.
1253 boolean burnInProtectionDevMode =
1254 SystemProperties.getBoolean("persist.debug.force_burn_in", false);
1255 if (burnInProtectionEnabled || burnInProtectionDevMode) {
1256 final int minHorizontal;
1257 final int maxHorizontal;
1258 final int minVertical;
1259 final int maxVertical;
1260 final int maxRadius;
1261 if (burnInProtectionDevMode) {
1262 minHorizontal = -8;
1263 maxHorizontal = 8;
1264 minVertical = -8;
1265 maxVertical = -4;
1266 maxRadius = (isRoundWindow()) ? 6 : -1;
1267 } else {
1268 Resources resources = context.getResources();
1269 minHorizontal = resources.getInteger(
1270 com.android.internal.R.integer.config_burnInProtectionMinHorizontalOffset);
1271 maxHorizontal = resources.getInteger(
1272 com.android.internal.R.integer.config_burnInProtectionMaxHorizontalOffset);
1273 minVertical = resources.getInteger(
1274 com.android.internal.R.integer.config_burnInProtectionMinVerticalOffset);
1275 maxVertical = resources.getInteger(
1276 com.android.internal.R.integer.config_burnInProtectionMaxVerticalOffset);
1277 maxRadius = resources.getInteger(
1278 com.android.internal.R.integer.config_burnInProtectionMaxRadius);
1279 }
1280 mBurnInProtectionHelper = new BurnInProtectionHelper(
1281 context, minHorizontal, maxHorizontal, minVertical, maxVertical, maxRadius);
Filip Gruszczynskicfb31852015-02-25 21:47:12 +00001282 }
Craig Mautner8a0da012014-05-31 15:13:37 -07001283
Jeff Brown70825162012-03-28 17:27:48 -07001284 mHandler = new PolicyHandler();
Jeff Browna20dda42014-05-27 20:57:24 -07001285 mWakeGestureListener = new MyWakeGestureListener(mContext, mHandler);
Craig Mautnereee29c42013-01-17 14:44:34 -08001286 mOrientationListener = new MyOrientationListener(mContext, mHandler);
Jeff Brownc0347aa2011-09-23 17:26:09 -07001287 try {
1288 mOrientationListener.setCurrentRotation(windowManager.getRotation());
1289 } catch (RemoteException ex) { }
Christopher Tate5e08af02012-09-21 17:17:22 -07001290 mSettingsObserver = new SettingsObserver(mHandler);
1291 mSettingsObserver.observe();
Svetoslav683914b2015-01-15 14:22:26 -08001292 mShortcutManager = new ShortcutManager(context);
Daniel Sandler6396c722013-04-16 20:19:09 -04001293 mUiMode = context.getResources().getInteger(
1294 com.android.internal.R.integer.config_defaultUiModeType);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001295 mHomeIntent = new Intent(Intent.ACTION_MAIN, null);
1296 mHomeIntent.addCategory(Intent.CATEGORY_HOME);
1297 mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1298 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07001299 mCarDockIntent = new Intent(Intent.ACTION_MAIN, null);
1300 mCarDockIntent.addCategory(Intent.CATEGORY_CAR_DOCK);
1301 mCarDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1302 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
1303 mDeskDockIntent = new Intent(Intent.ACTION_MAIN, null);
1304 mDeskDockIntent.addCategory(Intent.CATEGORY_DESK_DOCK);
1305 mDeskDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1306 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Jim Millere6ad1a82010-08-20 19:25:39 -07001307
Jeff Brown96307042012-07-27 15:51:34 -07001308 mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
1309 mBroadcastWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001310 "PhoneWindowManager.mBroadcastWakeLock");
Jeff Brown13f00f02014-10-31 14:45:50 -07001311 mPowerKeyWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
1312 "PhoneWindowManager.mPowerKeyWakeLock");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001313 mEnableShiftMenuBugReports = "1".equals(SystemProperties.get("ro.debuggable"));
Jeff Brownbcdfc622014-03-06 19:13:04 -08001314 mSupportAutoRotation = mContext.getResources().getBoolean(
1315 com.android.internal.R.bool.config_supportAutoRotation);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001316 mLidOpenRotation = readRotation(
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001317 com.android.internal.R.integer.config_lidOpenRotation);
1318 mCarDockRotation = readRotation(
1319 com.android.internal.R.integer.config_carDockRotation);
1320 mDeskDockRotation = readRotation(
1321 com.android.internal.R.integer.config_deskDockRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001322 mUndockedHdmiRotation = readRotation(
1323 com.android.internal.R.integer.config_undockedHdmiRotation);
Mike Lockwoode9867d22009-09-20 01:59:02 -04001324 mCarDockEnablesAccelerometer = mContext.getResources().getBoolean(
1325 com.android.internal.R.bool.config_carDockEnablesAccelerometer);
1326 mDeskDockEnablesAccelerometer = mContext.getResources().getBoolean(
1327 com.android.internal.R.bool.config_deskDockEnablesAccelerometer);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001328 mLidKeyboardAccessibility = mContext.getResources().getInteger(
1329 com.android.internal.R.integer.config_lidKeyboardAccessibility);
1330 mLidNavigationAccessibility = mContext.getResources().getInteger(
1331 com.android.internal.R.integer.config_lidNavigationAccessibility);
Jeff Brownc458ce92012-04-30 14:58:40 -07001332 mLidControlsSleep = mContext.getResources().getBoolean(
1333 com.android.internal.R.bool.config_lidControlsSleep);
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04001334 mTranslucentDecorEnabled = mContext.getResources().getBoolean(
1335 com.android.internal.R.bool.config_enableTranslucentDecor);
Bryce Lee584a4452014-10-21 15:55:55 -07001336
1337 mAllowTheaterModeWakeFromKey = mContext.getResources().getBoolean(
1338 com.android.internal.R.bool.config_allowTheaterModeWakeFromKey);
1339 mAllowTheaterModeWakeFromPowerKey = mAllowTheaterModeWakeFromKey
1340 || mContext.getResources().getBoolean(
1341 com.android.internal.R.bool.config_allowTheaterModeWakeFromPowerKey);
1342 mAllowTheaterModeWakeFromMotion = mContext.getResources().getBoolean(
1343 com.android.internal.R.bool.config_allowTheaterModeWakeFromMotion);
Bryce Lee812d7022014-11-10 13:33:28 -08001344 mAllowTheaterModeWakeFromMotionWhenNotDreaming = mContext.getResources().getBoolean(
1345 com.android.internal.R.bool.config_allowTheaterModeWakeFromMotionWhenNotDreaming);
Bryce Lee584a4452014-10-21 15:55:55 -07001346 mAllowTheaterModeWakeFromCameraLens = mContext.getResources().getBoolean(
1347 com.android.internal.R.bool.config_allowTheaterModeWakeFromCameraLens);
1348 mAllowTheaterModeWakeFromLidSwitch = mContext.getResources().getBoolean(
1349 com.android.internal.R.bool.config_allowTheaterModeWakeFromLidSwitch);
1350 mAllowTheaterModeWakeFromWakeGesture = mContext.getResources().getBoolean(
1351 com.android.internal.R.bool.config_allowTheaterModeWakeFromGesture);
1352
Bryce Lee55e846d2014-11-04 12:43:44 -08001353 mGoToSleepOnButtonPressTheaterMode = mContext.getResources().getBoolean(
1354 com.android.internal.R.bool.config_goToSleepOnButtonPressTheaterMode);
1355
Bryce Leed3b28402015-03-09 15:49:13 +00001356 mSupportLongPressPowerWhenNonInteractive = mContext.getResources().getBoolean(
1357 com.android.internal.R.bool.config_supportLongPressPowerWhenNonInteractive);
1358
Jeff Brown13f00f02014-10-31 14:45:50 -07001359 mShortPressOnPowerBehavior = mContext.getResources().getInteger(
1360 com.android.internal.R.integer.config_shortPressOnPowerBehavior);
1361 mLongPressOnPowerBehavior = mContext.getResources().getInteger(
1362 com.android.internal.R.integer.config_longPressOnPowerBehavior);
1363 mDoublePressOnPowerBehavior = mContext.getResources().getInteger(
1364 com.android.internal.R.integer.config_doublePressOnPowerBehavior);
1365 mTriplePressOnPowerBehavior = mContext.getResources().getInteger(
1366 com.android.internal.R.integer.config_triplePressOnPowerBehavior);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001367 mShortPressOnSleepBehavior = mContext.getResources().getInteger(
1368 com.android.internal.R.integer.config_shortPressOnSleepBehavior);
Jeff Brown13f00f02014-10-31 14:45:50 -07001369
John Spurlock61560172015-02-06 19:46:04 -05001370 mUseTvRouting = AudioSystem.getPlatformType(mContext) == AudioSystem.PLATFORM_TELEVISION;
RoboErik001c59c2015-01-26 15:53:51 -08001371
Jeff Brownf71343d2013-05-31 17:59:11 -07001372 readConfigurationDependentBehaviors();
Jeff Browncaca8812013-05-09 13:34:33 -07001373
Svetoslav8e3feb12014-02-24 13:46:47 -08001374 mAccessibilityManager = (AccessibilityManager) context.getSystemService(
1375 Context.ACCESSIBILITY_SERVICE);
1376
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001377 // register for dock events
Dianne Hackborn78968392010-03-04 20:47:56 -08001378 IntentFilter filter = new IntentFilter();
1379 filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE);
1380 filter.addAction(UiModeManager.ACTION_EXIT_CAR_MODE);
1381 filter.addAction(UiModeManager.ACTION_ENTER_DESK_MODE);
1382 filter.addAction(UiModeManager.ACTION_EXIT_DESK_MODE);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001383 filter.addAction(Intent.ACTION_DOCK_EVENT);
1384 Intent intent = context.registerReceiver(mDockReceiver, filter);
1385 if (intent != null) {
1386 // Retrieve current sticky dock event broadcast.
1387 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
1388 Intent.EXTRA_DOCK_STATE_UNDOCKED);
1389 }
Daniel Sandler7e37df52011-11-16 22:08:23 -08001390
Jeff Brown6aaf2952012-10-05 16:01:08 -07001391 // register for dream-related broadcasts
1392 filter = new IntentFilter();
1393 filter.addAction(Intent.ACTION_DREAMING_STARTED);
1394 filter.addAction(Intent.ACTION_DREAMING_STOPPED);
1395 context.registerReceiver(mDreamReceiver, filter);
1396
Christopher Tate5e08af02012-09-21 17:17:22 -07001397 // register for multiuser-relevant broadcasts
1398 filter = new IntentFilter(Intent.ACTION_USER_SWITCHED);
1399 context.registerReceiver(mMultiuserReceiver, filter);
1400
John Spurlock57306e62013-04-22 09:48:49 -04001401 // monitor for system gestures
Craig Mautner037aa8d2013-06-07 10:35:44 -07001402 mSystemGestures = new SystemGesturesPointerEventListener(context,
1403 new SystemGesturesPointerEventListener.Callbacks() {
John Spurlock57306e62013-04-22 09:48:49 -04001404 @Override
1405 public void onSwipeFromTop() {
John Spurlock04db1762013-05-13 12:46:41 -04001406 if (mStatusBar != null) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001407 requestTransientBars(mStatusBar);
John Spurlock04db1762013-05-13 12:46:41 -04001408 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04001409 }
1410 @Override
1411 public void onSwipeFromBottom() {
John Spurlock04db1762013-05-13 12:46:41 -04001412 if (mNavigationBar != null && mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001413 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001414 }
1415 }
1416 @Override
1417 public void onSwipeFromRight() {
John Spurlock04db1762013-05-13 12:46:41 -04001418 if (mNavigationBar != null && !mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001419 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001420 }
1421 }
1422 @Override
1423 public void onDebug() {
John Spurlockd67ec252013-09-05 11:31:54 -04001424 // no-op
John Spurlockad3e6cb2013-04-30 08:47:43 -04001425 }
Adrian Roos3595be42015-03-05 16:31:15 +01001426 @Override
1427 public void onDown() {
1428 mOrientationListener.onTouchStart();
1429 }
1430 @Override
1431 public void onUpOrCancel() {
1432 mOrientationListener.onTouchEnd();
1433 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04001434 });
John Spurlockf1a36642013-10-12 17:50:42 -04001435 mImmersiveModeConfirmation = new ImmersiveModeConfirmation(mContext);
Craig Mautner037aa8d2013-06-07 10:35:44 -07001436 mWindowManagerFuncs.registerPointerEventListener(mSystemGestures);
John Spurlock32beb2c2013-03-11 10:16:47 -04001437
Jeff Brownc2346132012-04-13 01:55:38 -07001438 mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001439 mLongPressVibePattern = getLongIntArray(mContext.getResources(),
1440 com.android.internal.R.array.config_longPressVibePattern);
1441 mVirtualKeyVibePattern = getLongIntArray(mContext.getResources(),
1442 com.android.internal.R.array.config_virtualKeyVibePattern);
Amith Yamasanic33cb712010-02-10 15:21:49 -08001443 mKeyboardTapVibePattern = getLongIntArray(mContext.getResources(),
1444 com.android.internal.R.array.config_keyboardTapVibePattern);
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07001445 mClockTickVibePattern = getLongIntArray(mContext.getResources(),
1446 com.android.internal.R.array.config_clockTickVibePattern);
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07001447 mCalendarDateVibePattern = getLongIntArray(mContext.getResources(),
1448 com.android.internal.R.array.config_calendarDateVibePattern);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001449 mSafeModeDisabledVibePattern = getLongIntArray(mContext.getResources(),
1450 com.android.internal.R.array.config_safeModeDisabledVibePattern);
1451 mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(),
1452 com.android.internal.R.array.config_safeModeEnabledVibePattern);
Mady Mellore82067b2015-04-30 09:58:35 -07001453 mStylusButtonPressVibePattern = getLongIntArray(mContext.getResources(),
1454 com.android.internal.R.array.config_stylusButtonPressVibePattern);
Daniel Sandler40427442010-07-16 11:44:52 -04001455
Christopher Tatee90585f2012-03-05 18:56:25 -08001456 mScreenshotChordEnabled = mContext.getResources().getBoolean(
1457 com.android.internal.R.bool.config_enableScreenshotChord);
1458
Justin Kohd378ad72013-04-01 12:18:26 -07001459 mGlobalKeyManager = new GlobalKeyManager(mContext);
1460
Joe Onoratoea495d42011-04-06 11:41:11 -07001461 // Controls rotation and the like.
1462 initializeHdmiState();
Dianne Hackborn40011092011-09-22 13:37:48 -07001463
1464 // Match current screen state.
Craig Mautnera631d492014-08-05 15:16:01 -07001465 if (!mPowerManager.isInteractive()) {
Jeff Brown416c49c2015-05-26 19:50:18 -07001466 startedGoingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
1467 finishedGoingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
Dianne Hackborn40011092011-09-22 13:37:48 -07001468 }
Jorim Jaggi24bec7c2015-02-04 12:40:14 +01001469
1470 mWindowManagerInternal.registerAppTransitionListener(
1471 mStatusBarController.getAppTransitionListener());
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001472 }
1473
Jeff Brownf71343d2013-05-31 17:59:11 -07001474 /**
1475 * Read values from config.xml that may be overridden depending on
1476 * the configuration of the device.
1477 * eg. Disable long press on home goes to recents on sw600dp.
1478 */
1479 private void readConfigurationDependentBehaviors() {
1480 mLongPressOnHomeBehavior = mContext.getResources().getInteger(
1481 com.android.internal.R.integer.config_longPressOnHomeBehavior);
1482 if (mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING ||
1483 mLongPressOnHomeBehavior > LONG_PRESS_HOME_ASSIST) {
1484 mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1485 }
1486
1487 mDoubleTapOnHomeBehavior = mContext.getResources().getInteger(
1488 com.android.internal.R.integer.config_doubleTapOnHomeBehavior);
1489 if (mDoubleTapOnHomeBehavior < DOUBLE_TAP_HOME_NOTHING ||
1490 mDoubleTapOnHomeBehavior > DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1491 mDoubleTapOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1492 }
1493 }
1494
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001495 @Override
Dianne Hackborndde331c2012-08-03 14:01:57 -07001496 public void setInitialDisplaySize(Display display, int width, int height, int density) {
Jeff Brownef981a42013-08-07 14:13:37 -07001497 // This method might be called before the policy has been fully initialized
1498 // or for other displays we don't care about.
1499 if (mContext == null || display.getDisplayId() != Display.DEFAULT_DISPLAY) {
1500 return;
Dianne Hackbornc652de82013-02-15 16:32:56 -08001501 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001502 mDisplay = display;
1503
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001504 final Resources res = mContext.getResources();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001505 int shortSize, longSize;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001506 if (width > height) {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001507 shortSize = height;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001508 longSize = width;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001509 mLandscapeRotation = Surface.ROTATION_0;
1510 mSeascapeRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001511 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001512 mPortraitRotation = Surface.ROTATION_90;
1513 mUpsideDownRotation = Surface.ROTATION_270;
1514 } else {
1515 mPortraitRotation = Surface.ROTATION_270;
1516 mUpsideDownRotation = Surface.ROTATION_90;
1517 }
1518 } else {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001519 shortSize = width;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001520 longSize = height;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001521 mPortraitRotation = Surface.ROTATION_0;
1522 mUpsideDownRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001523 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001524 mLandscapeRotation = Surface.ROTATION_270;
1525 mSeascapeRotation = Surface.ROTATION_90;
1526 } else {
1527 mLandscapeRotation = Surface.ROTATION_90;
1528 mSeascapeRotation = Surface.ROTATION_270;
1529 }
1530 }
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001531
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001532 mStatusBarHeight =
1533 res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001534
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001535 // Height of the navigation bar when presented horizontally at bottom
1536 mNavigationBarHeightForRotation[mPortraitRotation] =
1537 mNavigationBarHeightForRotation[mUpsideDownRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001538 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_height);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001539 mNavigationBarHeightForRotation[mLandscapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001540 mNavigationBarHeightForRotation[mSeascapeRotation] = res.getDimensionPixelSize(
1541 com.android.internal.R.dimen.navigation_bar_height_landscape);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001542
1543 // Width of the navigation bar when presented vertically along one side
1544 mNavigationBarWidthForRotation[mPortraitRotation] =
1545 mNavigationBarWidthForRotation[mUpsideDownRotation] =
1546 mNavigationBarWidthForRotation[mLandscapeRotation] =
1547 mNavigationBarWidthForRotation[mSeascapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001548 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_width);
Daniel Sandler4a066c52012-04-20 14:49:13 -04001549
1550 // SystemUI (status bar) layout policy
Dianne Hackborndde331c2012-08-03 14:01:57 -07001551 int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / density;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001552 int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / density;
Daniel Sandler4a066c52012-04-20 14:49:13 -04001553
Devin Kimd7b12b42014-05-05 14:34:58 -07001554 // Allow the navigation bar to move on non-square small devices (phones).
1555 mNavigationBarCanMove = width != height && shortSizeDp < 600;
Daniel Sandler36412a72011-08-04 09:35:13 -04001556
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001557 mHasNavigationBar = res.getBoolean(com.android.internal.R.bool.config_showNavigationBar);
John Spurlock80f00c12013-06-13 11:10:51 -04001558 // Allow a system property to override this. Used by the emulator.
1559 // See also hasNavigationBar().
1560 String navBarOverride = SystemProperties.get("qemu.hw.mainkeys");
1561 if ("1".equals(navBarOverride)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001562 mHasNavigationBar = false;
John Spurlock80f00c12013-06-13 11:10:51 -04001563 } else if ("0".equals(navBarOverride)) {
1564 mHasNavigationBar = true;
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04001565 }
1566
Jeff Brown27f1d672012-10-17 18:32:34 -07001567 // For demo purposes, allow the rotation of the HDMI display to be controlled.
1568 // By default, HDMI locks rotation to landscape.
Erik Gilling9a41ef82011-09-26 19:21:03 -07001569 if ("portrait".equals(SystemProperties.get("persist.demo.hdmirotation"))) {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001570 mDemoHdmiRotation = mPortraitRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001571 } else {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001572 mDemoHdmiRotation = mLandscapeRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001573 }
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001574 mDemoHdmiRotationLock = SystemProperties.getBoolean("persist.demo.hdmirotationlock", false);
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001575
Chong Zhangae6119ff2014-11-11 18:54:39 -08001576 // For demo purposes, allow the rotation of the remote display to be controlled.
1577 // By default, remote display locks rotation to landscape.
1578 if ("portrait".equals(SystemProperties.get("persist.demo.remoterotation"))) {
1579 mDemoRotation = mPortraitRotation;
1580 } else {
1581 mDemoRotation = mLandscapeRotation;
1582 }
1583 mDemoRotationLock = SystemProperties.getBoolean(
1584 "persist.demo.rotationlock", false);
1585
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001586 // Only force the default orientation if the screen is xlarge, at least 960dp x 720dp, per
1587 // http://developer.android.com/guide/practices/screens_support.html#range
1588 mForceDefaultOrientation = longSizeDp >= 960 && shortSizeDp >= 720 &&
1589 res.getBoolean(com.android.internal.R.bool.config_forceDefaultOrientation) &&
1590 // For debug purposes the next line turns this feature off with:
1591 // $ adb shell setprop config.override_forced_orient true
1592 // $ adb shell wm size reset
1593 !"true".equals(SystemProperties.get("config.override_forced_orient"));
1594 }
1595
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001596 /**
1597 * @return whether the navigation bar can be hidden, e.g. the device has a
1598 * navigation bar and touch exploration is not enabled
1599 */
1600 private boolean canHideNavigationBar() {
Svetoslav8e3feb12014-02-24 13:46:47 -08001601 return mHasNavigationBar
1602 && !mAccessibilityManager.isTouchExplorationEnabled();
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001603 }
1604
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001605 @Override
1606 public boolean isDefaultOrientationForced() {
1607 return mForceDefaultOrientation;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001608 }
1609
Dianne Hackbornc652de82013-02-15 16:32:56 -08001610 @Override
1611 public void setDisplayOverscan(Display display, int left, int top, int right, int bottom) {
1612 if (display.getDisplayId() == Display.DEFAULT_DISPLAY) {
1613 mOverscanLeft = left;
1614 mOverscanTop = top;
1615 mOverscanRight = right;
1616 mOverscanBottom = bottom;
1617 }
1618 }
1619
Dianne Hackbornc777e072010-02-12 13:07:59 -08001620 public void updateSettings() {
1621 ContentResolver resolver = mContext.getContentResolver();
1622 boolean updateRotation = false;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001623 synchronized (mLock) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001624 mEndcallBehavior = Settings.System.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001625 Settings.System.END_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001626 Settings.System.END_BUTTON_BEHAVIOR_DEFAULT,
1627 UserHandle.USER_CURRENT);
1628 mIncallPowerBehavior = Settings.Secure.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001629 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001630 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT,
1631 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001632
Jeff Browna20dda42014-05-27 20:57:24 -07001633 // Configure wake gesture.
1634 boolean wakeGestureEnabledSetting = Settings.Secure.getIntForUser(resolver,
1635 Settings.Secure.WAKE_GESTURE_ENABLED, 0,
1636 UserHandle.USER_CURRENT) != 0;
1637 if (mWakeGestureEnabledSetting != wakeGestureEnabledSetting) {
1638 mWakeGestureEnabledSetting = wakeGestureEnabledSetting;
1639 updateWakeGestureListenerLp();
1640 }
1641
Jeff Brown207673cd2012-06-05 17:47:11 -07001642 // Configure rotation lock.
Christopher Tate5e08af02012-09-21 17:17:22 -07001643 int userRotation = Settings.System.getIntForUser(resolver,
1644 Settings.System.USER_ROTATION, Surface.ROTATION_0,
1645 UserHandle.USER_CURRENT);
Jeff Brown207673cd2012-06-05 17:47:11 -07001646 if (mUserRotation != userRotation) {
1647 mUserRotation = userRotation;
1648 updateRotation = true;
1649 }
Christopher Tate5e08af02012-09-21 17:17:22 -07001650 int userRotationMode = Settings.System.getIntForUser(resolver,
1651 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
Jeff Brown207673cd2012-06-05 17:47:11 -07001652 WindowManagerPolicy.USER_ROTATION_FREE :
1653 WindowManagerPolicy.USER_ROTATION_LOCKED;
1654 if (mUserRotationMode != userRotationMode) {
1655 mUserRotationMode = userRotationMode;
1656 updateRotation = true;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001657 updateOrientationListenerLp();
1658 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001659
Dianne Hackbornc777e072010-02-12 13:07:59 -08001660 if (mSystemReady) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001661 int pointerLocation = Settings.System.getIntForUser(resolver,
1662 Settings.System.POINTER_LOCATION, 0, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001663 if (mPointerLocationMode != pointerLocation) {
1664 mPointerLocationMode = pointerLocation;
Jeff Brown70825162012-03-28 17:27:48 -07001665 mHandler.sendEmptyMessage(pointerLocation != 0 ?
1666 MSG_ENABLE_POINTER_LOCATION : MSG_DISABLE_POINTER_LOCATION);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001667 }
1668 }
1669 // use screen off timeout setting as the timeout for the lockscreen
Christopher Tate5e08af02012-09-21 17:17:22 -07001670 mLockScreenTimeout = Settings.System.getIntForUser(resolver,
1671 Settings.System.SCREEN_OFF_TIMEOUT, 0, UserHandle.USER_CURRENT);
1672 String imId = Settings.Secure.getStringForUser(resolver,
1673 Settings.Secure.DEFAULT_INPUT_METHOD, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001674 boolean hasSoftInput = imId != null && imId.length() > 0;
1675 if (mHasSoftInput != hasSoftInput) {
1676 mHasSoftInput = hasSoftInput;
1677 updateRotation = true;
1678 }
John Spurlockf1a36642013-10-12 17:50:42 -04001679 if (mImmersiveModeConfirmation != null) {
John Spurlock4355a532014-02-19 09:49:25 -05001680 mImmersiveModeConfirmation.loadSetting(mCurrentUserId);
John Spurlockd67ec252013-09-05 11:31:54 -04001681 }
John Spurlockc6d1c602014-01-17 15:22:06 -05001682 PolicyControl.reloadFromSetting(mContext);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001683 }
1684 if (updateRotation) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07001685 updateRotation(true);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001686 }
Jeff Brown70825162012-03-28 17:27:48 -07001687 }
1688
Jeff Browna20dda42014-05-27 20:57:24 -07001689 private void updateWakeGestureListenerLp() {
1690 if (shouldEnableWakeGestureLp()) {
1691 mWakeGestureListener.requestWakeUpTrigger();
1692 } else {
1693 mWakeGestureListener.cancelWakeUpTrigger();
1694 }
1695 }
1696
1697 private boolean shouldEnableWakeGestureLp() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07001698 return mWakeGestureEnabledSetting && !mAwake
Jeff Browna20dda42014-05-27 20:57:24 -07001699 && (!mLidControlsSleep || mLidState != LID_CLOSED)
1700 && mWakeGestureListener.isSupported();
1701 }
1702
Jeff Brown70825162012-03-28 17:27:48 -07001703 private void enablePointerLocation() {
1704 if (mPointerLocationView == null) {
1705 mPointerLocationView = new PointerLocationView(mContext);
1706 mPointerLocationView.setPrintCoords(false);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001707 WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
1708 WindowManager.LayoutParams.MATCH_PARENT,
1709 WindowManager.LayoutParams.MATCH_PARENT);
Jeff Brown3b2b3542010-10-15 00:54:27 -07001710 lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001711 lp.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN
1712 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
1713 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1714 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
Jeff Brown90fc9052012-10-01 14:44:24 -07001715 if (ActivityManager.isHighEndGfx()) {
1716 lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
1717 lp.privateFlags |=
1718 WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED;
1719 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001720 lp.format = PixelFormat.TRANSLUCENT;
1721 lp.setTitle("PointerLocation");
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001722 WindowManager wm = (WindowManager)
Dianne Hackbornc777e072010-02-12 13:07:59 -08001723 mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Browncc4f7db2011-08-30 20:34:48 -07001724 lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL;
Jeff Brown70825162012-03-28 17:27:48 -07001725 wm.addView(mPointerLocationView, lp);
Michael Wrightc9c487e2013-11-07 18:55:09 -08001726 mWindowManagerFuncs.registerPointerEventListener(mPointerLocationView);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001727 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001728 }
Jeff Brown70825162012-03-28 17:27:48 -07001729
1730 private void disablePointerLocation() {
Jeff Brown70825162012-03-28 17:27:48 -07001731 if (mPointerLocationView != null) {
Michael Wrightc9c487e2013-11-07 18:55:09 -08001732 mWindowManagerFuncs.unregisterPointerEventListener(mPointerLocationView);
1733 WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Brown70825162012-03-28 17:27:48 -07001734 wm.removeView(mPointerLocationView);
1735 mPointerLocationView = null;
1736 }
1737 }
1738
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001739 private int readRotation(int resID) {
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001740 try {
1741 int rotation = mContext.getResources().getInteger(resID);
1742 switch (rotation) {
1743 case 0:
1744 return Surface.ROTATION_0;
1745 case 90:
1746 return Surface.ROTATION_90;
1747 case 180:
1748 return Surface.ROTATION_180;
1749 case 270:
1750 return Surface.ROTATION_270;
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001751 }
1752 } catch (Resources.NotFoundException e) {
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001753 // fall through
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001754 }
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001755 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001756 }
1757
1758 /** {@inheritDoc} */
Craig Mautner88400d32012-09-30 12:35:45 -07001759 @Override
Dianne Hackbornc2293022013-02-06 23:14:49 -08001760 public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001761 int type = attrs.type;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001762
1763 outAppOp[0] = AppOpsManager.OP_NONE;
1764
Wale Ogunwale74bf0652015-01-12 10:24:36 -08001765 if (!((type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW)
1766 || (type >= FIRST_SUB_WINDOW && type <= LAST_SUB_WINDOW)
1767 || (type >= FIRST_SYSTEM_WINDOW && type <= LAST_SYSTEM_WINDOW))) {
1768 return WindowManagerGlobal.ADD_INVALID_TYPE;
1769 }
1770
1771 if (type < FIRST_SYSTEM_WINDOW || type > LAST_SYSTEM_WINDOW) {
1772 // Window manager will make sure these are okay.
Jeff Brown98365d72012-08-19 20:30:52 -07001773 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001774 }
1775 String permission = null;
1776 switch (type) {
1777 case TYPE_TOAST:
1778 // XXX right now the app process has complete control over
1779 // this... should introduce a token to let the system
1780 // monitor/control what they are doing.
Jason Monk1c7c3192014-06-26 12:52:18 -04001781 outAppOp[0] = AppOpsManager.OP_TOAST_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001782 break;
Daniel Sandler7d276c32012-01-30 14:33:52 -05001783 case TYPE_DREAM:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001784 case TYPE_INPUT_METHOD:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001785 case TYPE_WALLPAPER:
keunyounga446bf02013-06-21 19:07:57 -07001786 case TYPE_PRIVATE_PRESENTATION:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001787 case TYPE_VOICE_INTERACTION:
Svetoslav3a5c7212014-10-14 09:54:26 -07001788 case TYPE_ACCESSIBILITY_OVERLAY:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001789 // The window manager will check these.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001790 break;
1791 case TYPE_PHONE:
1792 case TYPE_PRIORITY_PHONE:
1793 case TYPE_SYSTEM_ALERT:
1794 case TYPE_SYSTEM_ERROR:
1795 case TYPE_SYSTEM_OVERLAY:
1796 permission = android.Manifest.permission.SYSTEM_ALERT_WINDOW;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001797 outAppOp[0] = AppOpsManager.OP_SYSTEM_ALERT_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001798 break;
1799 default:
1800 permission = android.Manifest.permission.INTERNAL_SYSTEM_WINDOW;
1801 }
1802 if (permission != null) {
1803 if (mContext.checkCallingOrSelfPermission(permission)
1804 != PackageManager.PERMISSION_GRANTED) {
Jeff Brown98365d72012-08-19 20:30:52 -07001805 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001806 }
1807 }
Jeff Brown98365d72012-08-19 20:30:52 -07001808 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001809 }
Craig Mautner88400d32012-09-30 12:35:45 -07001810
1811 @Override
1812 public boolean checkShowToOwnerOnly(WindowManager.LayoutParams attrs) {
1813
1814 // If this switch statement is modified, modify the comment in the declarations of
1815 // the type in {@link WindowManager.LayoutParams} as well.
1816 switch (attrs.type) {
1817 default:
1818 // These are the windows that by default are shown only to the user that created
1819 // them. If this needs to be overridden, set
1820 // {@link WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS} in
1821 // {@link WindowManager.LayoutParams}. Note that permission
1822 // {@link android.Manifest.permission.INTERNAL_SYSTEM_WINDOW} is required as well.
1823 if ((attrs.privateFlags & PRIVATE_FLAG_SHOW_FOR_ALL_USERS) == 0) {
1824 return true;
1825 }
1826 break;
1827
1828 // These are the windows that by default are shown to all users. However, to
1829 // protect against spoofing, check permissions below.
1830 case TYPE_APPLICATION_STARTING:
1831 case TYPE_BOOT_PROGRESS:
1832 case TYPE_DISPLAY_OVERLAY:
Selim Cinekf83e8242015-05-19 18:08:14 -07001833 case TYPE_INPUT_CONSUMER:
Jim Miller5ecd8112013-01-09 18:50:26 -08001834 case TYPE_KEYGUARD_SCRIM:
Craig Mautner88400d32012-09-30 12:35:45 -07001835 case TYPE_KEYGUARD_DIALOG:
1836 case TYPE_MAGNIFICATION_OVERLAY:
1837 case TYPE_NAVIGATION_BAR:
1838 case TYPE_NAVIGATION_BAR_PANEL:
1839 case TYPE_PHONE:
1840 case TYPE_POINTER:
1841 case TYPE_PRIORITY_PHONE:
Craig Mautner88400d32012-09-30 12:35:45 -07001842 case TYPE_SEARCH_BAR:
1843 case TYPE_STATUS_BAR:
1844 case TYPE_STATUS_BAR_PANEL:
1845 case TYPE_STATUS_BAR_SUB_PANEL:
1846 case TYPE_SYSTEM_DIALOG:
Craig Mautner88400d32012-09-30 12:35:45 -07001847 case TYPE_VOLUME_OVERLAY:
keunyounga446bf02013-06-21 19:07:57 -07001848 case TYPE_PRIVATE_PRESENTATION:
Craig Mautner88400d32012-09-30 12:35:45 -07001849 break;
1850 }
1851
1852 // Check if third party app has set window to system window type.
1853 return mContext.checkCallingOrSelfPermission(
1854 android.Manifest.permission.INTERNAL_SYSTEM_WINDOW)
1855 != PackageManager.PERMISSION_GRANTED;
1856 }
1857
Craig Mautner967212c2013-04-13 21:10:58 -07001858 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001859 public void adjustWindowParamsLw(WindowManager.LayoutParams attrs) {
1860 switch (attrs.type) {
1861 case TYPE_SYSTEM_OVERLAY:
Jeff Brown3b2b3542010-10-15 00:54:27 -07001862 case TYPE_SECURE_SYSTEM_OVERLAY:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001863 // These types of windows can't receive input events.
1864 attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1865 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001866 attrs.flags &= ~WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001867 break;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001868 case TYPE_STATUS_BAR:
1869
1870 // If the Keyguard is in a hidden state (occluded by another window), we force to
1871 // remove the wallpaper and keyguard flag so that any change in-flight after setting
1872 // the keyguard as occluded wouldn't set these flags again.
1873 // See {@link #processKeyguardSetHiddenResultLw}.
1874 if (mKeyguardHidden) {
1875 attrs.flags &= ~WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
1876 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
1877 }
1878 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001879 }
Adrian Roos38502112014-04-09 21:04:11 +02001880
1881 if (attrs.type != TYPE_STATUS_BAR) {
1882 // The status bar is the only window allowed to exhibit keyguard behavior.
1883 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
1884 }
Adrian Roosea562512014-05-05 13:33:03 +02001885
1886 if (ActivityManager.isHighEndGfx()
1887 && (attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0) {
Adrian Roosf5e9b5c2014-09-10 15:27:41 +02001888 attrs.subtreeSystemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
Adrian Roosea562512014-05-05 13:33:03 +02001889 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
1890 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001891 }
RoboErik8a2cfc32014-05-16 11:19:38 -07001892
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001893 void readLidState() {
Jeff Brown2e7760e2012-04-11 15:14:55 -07001894 mLidState = mWindowManagerFuncs.getLidState();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001895 }
RoboErik8a2cfc32014-05-16 11:19:38 -07001896
Michael Wright3818c922014-09-02 13:59:07 -07001897 private void readCameraLensCoverState() {
1898 mCameraLensCoverState = mWindowManagerFuncs.getCameraLensCoverState();
1899 }
1900
Jeff Browndaa37532012-05-01 15:54:03 -07001901 private boolean isHidden(int accessibilityMode) {
1902 switch (accessibilityMode) {
1903 case 1:
1904 return mLidState == LID_CLOSED;
1905 case 2:
1906 return mLidState == LID_OPEN;
1907 default:
1908 return false;
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001909 }
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001910 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001911
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001912 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07001913 @Override
Jeff Browndaa37532012-05-01 15:54:03 -07001914 public void adjustConfigurationLw(Configuration config, int keyboardPresence,
1915 int navigationPresence) {
1916 mHaveBuiltInKeyboard = (keyboardPresence & PRESENCE_INTERNAL) != 0;
1917
Jeff Brownf71343d2013-05-31 17:59:11 -07001918 readConfigurationDependentBehaviors();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001919 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07001920 applyLidSwitchState();
Jeff Brownd04a88c2011-01-16 14:05:47 -08001921
Jeff Browndaa37532012-05-01 15:54:03 -07001922 if (config.keyboard == Configuration.KEYBOARD_NOKEYS
1923 || (keyboardPresence == PRESENCE_INTERNAL
1924 && isHidden(mLidKeyboardAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001925 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_YES;
Jeff Browndaa37532012-05-01 15:54:03 -07001926 if (!mHasSoftInput) {
1927 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_YES;
1928 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001929 }
1930
Jeff Browndaa37532012-05-01 15:54:03 -07001931 if (config.navigation == Configuration.NAVIGATION_NONAV
1932 || (navigationPresence == PRESENCE_INTERNAL
1933 && isHidden(mLidNavigationAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001934 config.navigationHidden = Configuration.NAVIGATIONHIDDEN_YES;
Jeff Brownd04a88c2011-01-16 14:05:47 -08001935 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001936 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001937
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001938 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07001939 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001940 public int windowTypeToLayerLw(int type) {
1941 if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001942 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001943 }
1944 switch (type) {
keunyounga446bf02013-06-21 19:07:57 -07001945 case TYPE_PRIVATE_PRESENTATION:
1946 return 2;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001947 case TYPE_WALLPAPER:
1948 // wallpaper is at the bottom, though the window manager may move it.
1949 return 2;
1950 case TYPE_PHONE:
1951 return 3;
1952 case TYPE_SEARCH_BAR:
Jorim Jaggi225d3b52015-04-01 11:18:57 -07001953 case TYPE_VOICE_INTERACTION_STARTING:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001954 return 4;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001955 case TYPE_VOICE_INTERACTION:
1956 // voice interaction layer is almost immediately above apps.
1957 return 5;
Selim Cinekf83e8242015-05-19 18:08:14 -07001958 case TYPE_INPUT_CONSUMER:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001959 return 6;
Selim Cinekf83e8242015-05-19 18:08:14 -07001960 case TYPE_SYSTEM_DIALOG:
1961 return 7;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001962 case TYPE_TOAST:
1963 // toasts and the plugged-in battery thing
Selim Cinekf83e8242015-05-19 18:08:14 -07001964 return 8;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001965 case TYPE_PRIORITY_PHONE:
1966 // SIM errors and unlock. Not sure if this really should be in a high layer.
Selim Cinekf83e8242015-05-19 18:08:14 -07001967 return 9;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001968 case TYPE_DREAM:
1969 // used for Dreams (screensavers with TYPE_DREAM windows)
Selim Cinekf83e8242015-05-19 18:08:14 -07001970 return 10;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001971 case TYPE_SYSTEM_ALERT:
1972 // like the ANR / app crashed dialogs
Selim Cinekf83e8242015-05-19 18:08:14 -07001973 return 11;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001974 case TYPE_INPUT_METHOD:
1975 // on-screen keyboards and other such input method user interfaces go here.
Selim Cinekf83e8242015-05-19 18:08:14 -07001976 return 12;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001977 case TYPE_INPUT_METHOD_DIALOG:
1978 // on-screen keyboards and other such input method user interfaces go here.
Selim Cinekf83e8242015-05-19 18:08:14 -07001979 return 13;
Jim Miller5ecd8112013-01-09 18:50:26 -08001980 case TYPE_KEYGUARD_SCRIM:
1981 // the safety window that shows behind keyguard while keyguard is starting
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001982 return 14;
Selim Cinekf83e8242015-05-19 18:08:14 -07001983 case TYPE_STATUS_BAR_SUB_PANEL:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001984 return 15;
Selim Cinekf83e8242015-05-19 18:08:14 -07001985 case TYPE_STATUS_BAR:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001986 return 16;
Selim Cinekf83e8242015-05-19 18:08:14 -07001987 case TYPE_STATUS_BAR_PANEL:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001988 return 17;
Selim Cinekf83e8242015-05-19 18:08:14 -07001989 case TYPE_KEYGUARD_DIALOG:
1990 return 18;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001991 case TYPE_VOLUME_OVERLAY:
1992 // the on-screen volume indicator and controller shown when the user
1993 // changes the device volume
Selim Cinekf83e8242015-05-19 18:08:14 -07001994 return 19;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001995 case TYPE_SYSTEM_OVERLAY:
1996 // the on-screen volume indicator and controller shown when the user
1997 // changes the device volume
Selim Cinekf83e8242015-05-19 18:08:14 -07001998 return 20;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001999 case TYPE_NAVIGATION_BAR:
2000 // the navigation bar, if available, shows atop most things
Selim Cinekf83e8242015-05-19 18:08:14 -07002001 return 21;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002002 case TYPE_NAVIGATION_BAR_PANEL:
2003 // some panels (e.g. search) need to show on top of the navigation bar
Selim Cinekf83e8242015-05-19 18:08:14 -07002004 return 22;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002005 case TYPE_SYSTEM_ERROR:
2006 // system-level error dialogs
Selim Cinekf83e8242015-05-19 18:08:14 -07002007 return 23;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002008 case TYPE_MAGNIFICATION_OVERLAY:
2009 // used to highlight the magnified portion of a display
Selim Cinekf83e8242015-05-19 18:08:14 -07002010 return 24;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002011 case TYPE_DISPLAY_OVERLAY:
2012 // used to simulate secondary display devices
Selim Cinekf83e8242015-05-19 18:08:14 -07002013 return 25;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002014 case TYPE_DRAG:
2015 // the drag layer: input for drag-and-drop is associated with this window,
2016 // which sits above all other focusable windows
Selim Cinekf83e8242015-05-19 18:08:14 -07002017 return 26;
Svetoslav3a5c7212014-10-14 09:54:26 -07002018 case TYPE_ACCESSIBILITY_OVERLAY:
2019 // overlay put by accessibility services to intercept user interaction
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002020 return 27;
Selim Cinekf83e8242015-05-19 18:08:14 -07002021 case TYPE_SECURE_SYSTEM_OVERLAY:
Svetoslav3a5c7212014-10-14 09:54:26 -07002022 return 28;
Selim Cinekf83e8242015-05-19 18:08:14 -07002023 case TYPE_BOOT_PROGRESS:
2024 return 29;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002025 case TYPE_POINTER:
2026 // the (mouse) pointer layer
Svetoslav3a5c7212014-10-14 09:54:26 -07002027 return 30;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002028 }
2029 Log.e(TAG, "Unknown window type: " + type);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002030 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002031 }
2032
2033 /** {@inheritDoc} */
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002034 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002035 public int subWindowTypeToLayerLw(int type) {
2036 switch (type) {
2037 case TYPE_APPLICATION_PANEL:
2038 case TYPE_APPLICATION_ATTACHED_DIALOG:
2039 return APPLICATION_PANEL_SUBLAYER;
2040 case TYPE_APPLICATION_MEDIA:
2041 return APPLICATION_MEDIA_SUBLAYER;
Dianne Hackborn5cb8d792009-05-21 17:34:15 -07002042 case TYPE_APPLICATION_MEDIA_OVERLAY:
2043 return APPLICATION_MEDIA_OVERLAY_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002044 case TYPE_APPLICATION_SUB_PANEL:
2045 return APPLICATION_SUB_PANEL_SUBLAYER;
Wale Ogunwale0a4dc222015-04-14 12:58:42 -07002046 case TYPE_APPLICATION_ABOVE_SUB_PANEL:
2047 return APPLICATION_ABOVE_SUB_PANEL_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002048 }
2049 Log.e(TAG, "Unknown sub-window type: " + type);
2050 return 0;
2051 }
2052
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002053 @Override
Dianne Hackbornabe0da02009-09-18 01:55:39 -07002054 public int getMaxWallpaperLayer() {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002055 return windowTypeToLayerLw(TYPE_STATUS_BAR);
Dianne Hackbornabe0da02009-09-18 01:55:39 -07002056 }
2057
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002058 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002059 public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07002060 if (mHasNavigationBar) {
2061 // For a basic navigation bar, when we are in landscape mode we place
2062 // the navigation bar to the side.
Daniel Sandler4a066c52012-04-20 14:49:13 -04002063 if (mNavigationBarCanMove && fullWidth > fullHeight) {
2064 return fullWidth - mNavigationBarWidthForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07002065 }
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002066 }
2067 return fullWidth;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002068 }
2069
Jose Lima9546b202014-07-02 17:21:51 -07002070 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002071 public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07002072 if (mHasNavigationBar) {
2073 // For a basic navigation bar, when we are in portrait mode we place
2074 // the navigation bar to the bottom.
Daniel Sandler4a066c52012-04-20 14:49:13 -04002075 if (!mNavigationBarCanMove || fullWidth < fullHeight) {
2076 return fullHeight - mNavigationBarHeightForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07002077 }
2078 }
2079 return fullHeight;
Dianne Hackborn69cb8752011-05-19 18:13:32 -07002080 }
2081
Jose Lima9546b202014-07-02 17:21:51 -07002082 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002083 public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation) {
2084 return getNonDecorDisplayWidth(fullWidth, fullHeight, rotation);
Dianne Hackborn69cb8752011-05-19 18:13:32 -07002085 }
2086
Jose Lima9546b202014-07-02 17:21:51 -07002087 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002088 public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation) {
John Spurlock80f00c12013-06-13 11:10:51 -04002089 // There is a separate status bar at the top of the display. We don't count that as part
2090 // of the fixed decor, since it can hide; however, for purposes of configurations,
Dianne Hackborn077ee852012-04-09 16:27:07 -07002091 // we do want to exclude it since applications can't generally use that part
2092 // of the screen.
John Spurlock80f00c12013-06-13 11:10:51 -04002093 return getNonDecorDisplayHeight(fullWidth, fullHeight, rotation) - mStatusBarHeight;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002094 }
2095
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002096 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07002097 public boolean isForceHiding(WindowManager.LayoutParams attrs) {
2098 return (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 ||
Jim Millerab954542014-10-10 18:21:49 -07002099 (isKeyguardHostWindow(attrs) &&
2100 (mKeyguardDelegate != null && mKeyguardDelegate.isShowing())) ||
Adrian Roos69e510d2014-07-13 14:57:59 +02002101 (attrs.type == TYPE_KEYGUARD_SCRIM);
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002102 }
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002103
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002104 @Override
Jorim Jaggi0d674622014-05-21 01:34:15 +02002105 public boolean isKeyguardHostWindow(WindowManager.LayoutParams attrs) {
2106 return attrs.type == TYPE_STATUS_BAR;
2107 }
2108
2109 @Override
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002110 public boolean canBeForceHidden(WindowState win, WindowManager.LayoutParams attrs) {
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002111 switch (attrs.type) {
2112 case TYPE_STATUS_BAR:
2113 case TYPE_NAVIGATION_BAR:
2114 case TYPE_WALLPAPER:
2115 case TYPE_DREAM:
Jim Miller5ecd8112013-01-09 18:50:26 -08002116 case TYPE_KEYGUARD_SCRIM:
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002117 return false;
2118 default:
2119 return true;
2120 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002121 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002122
Craig Mautner7d7808f2014-09-11 18:02:38 -07002123 @Override
2124 public WindowState getWinShowWhenLockedLw() {
2125 return mWinShowWhenLocked;
2126 }
2127
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002128 /** {@inheritDoc} */
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002129 @Override
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07002130 public View addStartingWindow(IBinder appToken, String packageName, int theme,
2131 CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes,
Adam Powell04fe6eb2013-05-31 14:39:48 -07002132 int icon, int logo, int windowFlags) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002133 if (!SHOW_STARTING_ANIMATIONS) {
2134 return null;
2135 }
2136 if (packageName == null) {
2137 return null;
2138 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002139
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002140 WindowManager wm = null;
2141 View view = null;
2142
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002143 try {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002144 Context context = mContext;
Craig Mautner6fbda632012-07-03 09:26:39 -07002145 if (DEBUG_STARTING_WINDOW) Slog.d(TAG, "addStartingWindow " + packageName
2146 + ": nonLocalizedLabel=" + nonLocalizedLabel + " theme="
2147 + Integer.toHexString(theme));
Dianne Hackborn247fe742011-01-08 17:25:57 -08002148 if (theme != context.getThemeResId() || labelRes != 0) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002149 try {
2150 context = context.createPackageContext(packageName, 0);
Dianne Hackborn247fe742011-01-08 17:25:57 -08002151 context.setTheme(theme);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002152 } catch (PackageManager.NameNotFoundException e) {
2153 // Ignore
2154 }
2155 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002156
Jorim Jaggia16cc152015-06-01 16:55:05 -07002157 PhoneWindow win = new PhoneWindow(context);
2158 win.setIsStartingWindow(true);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002159 final TypedArray ta = win.getWindowStyle();
2160 if (ta.getBoolean(
2161 com.android.internal.R.styleable.Window_windowDisablePreview, false)
2162 || ta.getBoolean(
2163 com.android.internal.R.styleable.Window_windowShowWallpaper,false)) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002164 return null;
2165 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002166
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002167 Resources r = context.getResources();
2168 win.setTitle(r.getText(labelRes, nonLocalizedLabel));
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002169
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002170 win.setType(
2171 WindowManager.LayoutParams.TYPE_APPLICATION_STARTING);
Adrian Roos602c68e2015-04-24 16:03:47 -07002172
2173 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
2174 // Assumes it's safe to show starting windows of launched apps while
2175 // the keyguard is being hidden. This is okay because starting windows never show
2176 // secret information.
2177 if (mKeyguardHidden) {
2178 windowFlags |= FLAG_SHOW_WHEN_LOCKED;
2179 }
2180 }
2181
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002182 // Force the window flags: this is a fake window, so it is not really
2183 // touchable or focusable by the user. We also add in the ALT_FOCUSABLE_IM
2184 // flag because we do know that the next window will take input
2185 // focus, so we want to get the IME window up on top of us right away.
2186 win.setFlags(
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08002187 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002188 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
2189 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
2190 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08002191 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002192 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
2193 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
2194 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002195
Adam Powell04fe6eb2013-05-31 14:39:48 -07002196 win.setDefaultIcon(icon);
2197 win.setDefaultLogo(logo);
2198
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002199 win.setLayout(WindowManager.LayoutParams.MATCH_PARENT,
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07002200 WindowManager.LayoutParams.MATCH_PARENT);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002201
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002202 final WindowManager.LayoutParams params = win.getAttributes();
2203 params.token = appToken;
2204 params.packageName = packageName;
2205 params.windowAnimations = win.getWindowStyle().getResourceId(
2206 com.android.internal.R.styleable.Window_windowAnimationStyle, 0);
John Reck61375a82014-09-18 19:27:48 +00002207 params.privateFlags |=
2208 WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED;
Craig Mautner88400d32012-09-30 12:35:45 -07002209 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
Adam Lesinski95c42972013-10-02 10:13:27 -07002210
2211 if (!compatInfo.supportsScreen()) {
2212 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
2213 }
2214
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002215 params.setTitle("Starting " + packageName);
2216
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002217 wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
2218 view = win.getDecorView();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002219
2220 if (win.isFloating()) {
2221 // Whoops, there is no way to display an animation/preview
2222 // of such a thing! After all that work... let's skip it.
2223 // (Note that we must do this here because it is in
2224 // getDecorView() where the theme is evaluated... maybe
2225 // we should peek the floating attribute from the theme
2226 // earlier.)
2227 return null;
2228 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002229
Craig Mautner6fbda632012-07-03 09:26:39 -07002230 if (DEBUG_STARTING_WINDOW) Slog.d(
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002231 TAG, "Adding starting window for " + packageName
2232 + " / " + appToken + ": "
2233 + (view.getParent() != null ? view : null));
2234
2235 wm.addView(view, params);
2236
2237 // Only return the view if it was successfully added to the
2238 // window manager... which we can tell by it having a parent.
2239 return view.getParent() != null ? view : null;
Jeff Brown98365d72012-08-19 20:30:52 -07002240 } catch (WindowManager.BadTokenException e) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002241 // ignore
Craig Mautner42bf39e2014-02-21 16:46:22 -08002242 Log.w(TAG, appToken + " already running, starting window not displayed. " +
2243 e.getMessage());
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002244 } catch (RuntimeException e) {
2245 // don't crash if something else bad happens, for example a
2246 // failure loading resources because we are loading from an app
2247 // on external storage that has been unmounted.
2248 Log.w(TAG, appToken + " failed creating starting window", e);
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002249 } finally {
2250 if (view != null && view.getParent() == null) {
2251 Log.w(TAG, "view not successfully added to wm, removing view");
2252 wm.removeViewImmediate(view);
2253 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002254 }
2255
2256 return null;
2257 }
2258
2259 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07002260 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002261 public void removeStartingWindow(IBinder appToken, View window) {
Craig Mautner276a6eb2014-11-04 15:32:57 -08002262 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Removing starting window for " + appToken + ": "
2263 + window + " Callers=" + Debug.getCallers(4));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002264
2265 if (window != null) {
Dianne Hackborn5fd21692011-06-07 14:09:47 -07002266 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002267 wm.removeView(window);
2268 }
2269 }
2270
2271 /**
2272 * Preflight adding a window to the system.
RoboErik8a2cfc32014-05-16 11:19:38 -07002273 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002274 * Currently enforces that three window types are singletons:
2275 * <ul>
2276 * <li>STATUS_BAR_TYPE</li>
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002277 * <li>KEYGUARD_TYPE</li>
2278 * </ul>
RoboErik8a2cfc32014-05-16 11:19:38 -07002279 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002280 * @param win The window to be added
2281 * @param attrs Information about the window to be added
RoboErik8a2cfc32014-05-16 11:19:38 -07002282 *
Jeff Brown98365d72012-08-19 20:30:52 -07002283 * @return If ok, WindowManagerImpl.ADD_OKAY. If too many singletons,
2284 * WindowManagerImpl.ADD_MULTIPLE_SINGLETON
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002285 */
Jose Lima9546b202014-07-02 17:21:51 -07002286 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002287 public int prepareAddWindowLw(WindowState win, WindowManager.LayoutParams attrs) {
2288 switch (attrs.type) {
2289 case TYPE_STATUS_BAR:
Joe Onorato8bc6c512010-06-04 16:21:12 -04002290 mContext.enforceCallingOrSelfPermission(
2291 android.Manifest.permission.STATUS_BAR_SERVICE,
2292 "PhoneWindowManager");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002293 if (mStatusBar != null) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002294 if (mStatusBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07002295 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002296 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002297 }
2298 mStatusBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04002299 mStatusBarController.setWindow(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002300 break;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002301 case TYPE_NAVIGATION_BAR:
2302 mContext.enforceCallingOrSelfPermission(
2303 android.Manifest.permission.STATUS_BAR_SERVICE,
2304 "PhoneWindowManager");
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002305 if (mNavigationBar != null) {
2306 if (mNavigationBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07002307 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002308 }
2309 }
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002310 mNavigationBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04002311 mNavigationBarController.setWindow(win);
Craig Mautnereda67292013-04-28 13:50:14 -07002312 if (DEBUG_LAYOUT) Slog.i(TAG, "NAVIGATION BAR: " + mNavigationBar);
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002313 break;
Jim Millere898ac52012-04-06 17:10:57 -07002314 case TYPE_NAVIGATION_BAR_PANEL:
Dianne Hackborn08743722009-12-21 12:16:51 -08002315 case TYPE_STATUS_BAR_PANEL:
Joe Onorato29fc2c92010-11-24 10:26:50 -08002316 case TYPE_STATUS_BAR_SUB_PANEL:
Jorim Jaggi225d3b52015-04-01 11:18:57 -07002317 case TYPE_VOICE_INTERACTION_STARTING:
Joe Onorato29fc2c92010-11-24 10:26:50 -08002318 mContext.enforceCallingOrSelfPermission(
2319 android.Manifest.permission.STATUS_BAR_SERVICE,
2320 "PhoneWindowManager");
Joe Onorato29fc2c92010-11-24 10:26:50 -08002321 break;
Jim Miller5ecd8112013-01-09 18:50:26 -08002322 case TYPE_KEYGUARD_SCRIM:
Jim Miller25190572013-02-28 17:36:24 -08002323 if (mKeyguardScrim != null) {
2324 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
2325 }
Jim Miller5ecd8112013-01-09 18:50:26 -08002326 mKeyguardScrim = win;
2327 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002328 }
Jeff Brown98365d72012-08-19 20:30:52 -07002329 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002330 }
2331
2332 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07002333 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002334 public void removeWindowLw(WindowState win) {
2335 if (mStatusBar == win) {
2336 mStatusBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04002337 mStatusBarController.setWindow(null);
Jim Millerc0b676d2013-03-22 16:11:08 -07002338 mKeyguardDelegate.showScrim();
Jim Miller5ecd8112013-01-09 18:50:26 -08002339 } else if (mKeyguardScrim == win) {
2340 Log.v(TAG, "Removing keyguard scrim");
2341 mKeyguardScrim = null;
2342 } if (mNavigationBar == win) {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002343 mNavigationBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04002344 mNavigationBarController.setWindow(null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002345 }
2346 }
2347
2348 static final boolean PRINT_ANIM = false;
RoboErik8a2cfc32014-05-16 11:19:38 -07002349
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002350 /** {@inheritDoc} */
Craig Mautner4b71aa12012-12-27 17:20:01 -08002351 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002352 public int selectAnimationLw(WindowState win, int transit) {
2353 if (PRINT_ANIM) Log.i(TAG, "selectAnimation in " + win
2354 + ": transit=" + transit);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002355 if (win == mStatusBar) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002356 boolean isKeyguard = (win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002357 if (transit == TRANSIT_EXIT
2358 || transit == TRANSIT_HIDE) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002359 return isKeyguard ? -1 : R.anim.dock_top_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002360 } else if (transit == TRANSIT_ENTER
2361 || transit == TRANSIT_SHOW) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002362 return isKeyguard ? -1 : R.anim.dock_top_enter;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002363 }
2364 } else if (win == mNavigationBar) {
2365 // This can be on either the bottom or the right.
2366 if (mNavigationBarOnBottom) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08002367 if (transit == TRANSIT_EXIT
2368 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002369 return R.anim.dock_bottom_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002370 } else if (transit == TRANSIT_ENTER
2371 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002372 return R.anim.dock_bottom_enter;
2373 }
2374 } else {
Craig Mautner4b71aa12012-12-27 17:20:01 -08002375 if (transit == TRANSIT_EXIT
2376 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002377 return R.anim.dock_right_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002378 } else if (transit == TRANSIT_ENTER
2379 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002380 return R.anim.dock_right_enter;
2381 }
2382 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08002383 }
2384
2385 if (transit == TRANSIT_PREVIEW_DONE) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002386 if (win.hasAppShownWindows()) {
2387 if (PRINT_ANIM) Log.i(TAG, "**** STARTING EXIT");
2388 return com.android.internal.R.anim.app_starting_exit;
2389 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07002390 } else if (win.getAttrs().type == TYPE_DREAM && mDreamingLockscreen
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002391 && transit == TRANSIT_ENTER) {
2392 // Special case: we are animating in a dream, while the keyguard
2393 // is shown. We don't want an animation on the dream, because
2394 // we need it shown immediately with the keyguard animating away
2395 // to reveal it.
2396 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002397 }
2398
2399 return 0;
2400 }
2401
Craig Mautner3c174372013-02-21 17:54:37 -08002402 @Override
2403 public void selectRotationAnimationLw(int anim[]) {
2404 if (PRINT_ANIM) Slog.i(TAG, "selectRotationAnimation mTopFullscreen="
2405 + mTopFullscreenOpaqueWindowState + " rotationAnimation="
2406 + (mTopFullscreenOpaqueWindowState == null ?
2407 "0" : mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation));
2408 if (mTopFullscreenOpaqueWindowState != null && mTopIsFullscreen) {
2409 switch (mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation) {
2410 case ROTATION_ANIMATION_CROSSFADE:
2411 anim[0] = R.anim.rotation_animation_xfade_exit;
2412 anim[1] = R.anim.rotation_animation_enter;
2413 break;
2414 case ROTATION_ANIMATION_JUMPCUT:
2415 anim[0] = R.anim.rotation_animation_jump_exit;
2416 anim[1] = R.anim.rotation_animation_enter;
2417 break;
2418 case ROTATION_ANIMATION_ROTATE:
2419 default:
2420 anim[0] = anim[1] = 0;
2421 break;
2422 }
2423 } else {
2424 anim[0] = anim[1] = 0;
2425 }
2426 }
2427
2428 @Override
2429 public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId,
2430 boolean forceDefault) {
2431 switch (exitAnimId) {
2432 case R.anim.rotation_animation_xfade_exit:
2433 case R.anim.rotation_animation_jump_exit:
2434 // These are the only cases that matter.
2435 if (forceDefault) {
2436 return false;
2437 }
2438 int anim[] = new int[2];
2439 selectRotationAnimationLw(anim);
2440 return (exitAnimId == anim[0] && enterAnimId == anim[1]);
2441 default:
2442 return true;
2443 }
2444 }
2445
2446 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002447 public Animation createForceHideEnterAnimation(boolean onWallpaper,
2448 boolean goingToNotificationShade) {
2449 if (goingToNotificationShade) {
2450 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_behind_enter_fade_in);
Craig Mautnerb8340802014-11-04 15:32:57 -08002451 }
Craig Mautner276a6eb2014-11-04 15:32:57 -08002452
2453 AnimationSet set = (AnimationSet) AnimationUtils.loadAnimation(mContext, onWallpaper ?
2454 R.anim.lock_screen_behind_enter_wallpaper :
2455 R.anim.lock_screen_behind_enter);
2456
2457 // TODO: Use XML interpolators when we have log interpolators available in XML.
2458 final List<Animation> animations = set.getAnimations();
2459 for (int i = animations.size() - 1; i >= 0; --i) {
2460 animations.get(i).setInterpolator(mLogDecelerateInterpolator);
2461 }
2462
2463 return set;
Jorim Jaggi76a16232014-08-08 17:00:47 +02002464 }
2465
2466
2467 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002468 public Animation createForceHideWallpaperExitAnimation(boolean goingToNotificationShade) {
2469 if (goingToNotificationShade) {
2470 return null;
2471 } else {
2472 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_wallpaper_exit);
2473 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002474 }
John Spurlockc8b46ca2013-04-08 12:59:26 -04002475
2476 private static void awakenDreams() {
2477 IDreamManager dreamManager = getDreamManager();
2478 if (dreamManager != null) {
2479 try {
2480 dreamManager.awaken();
2481 } catch (RemoteException e) {
2482 // fine, stay asleep then
2483 }
2484 }
2485 }
2486
2487 static IDreamManager getDreamManager() {
2488 return IDreamManager.Stub.asInterface(
2489 ServiceManager.checkService(DreamService.DREAM_SERVICE));
2490 }
2491
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002492 TelecomManager getTelecommService() {
2493 return (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002494 }
2495
Jeff Brown4d396052010-10-29 21:50:21 -07002496 static IAudioService getAudioService() {
2497 IAudioService audioService = IAudioService.Stub.asInterface(
2498 ServiceManager.checkService(Context.AUDIO_SERVICE));
2499 if (audioService == null) {
2500 Log.w(TAG, "Unable to find IAudioService interface.");
2501 }
2502 return audioService;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002503 }
2504
2505 boolean keyguardOn() {
Jim Millerab954542014-10-10 18:21:49 -07002506 return isKeyguardShowingAndNotOccluded() || inKeyguardRestrictedKeyInputMode();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002507 }
2508
2509 private static final int[] WINDOW_TYPES_WHERE_HOME_DOESNT_WORK = {
2510 WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
2511 WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
2512 };
2513
2514 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002515 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002516 public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002517 final boolean keyguardOn = keyguardOn();
Jeff Brown1f245102010-11-18 20:53:46 -08002518 final int keyCode = event.getKeyCode();
2519 final int repeatCount = event.getRepeatCount();
2520 final int metaState = event.getMetaState();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002521 final int flags = event.getFlags();
Jeff Brown1f245102010-11-18 20:53:46 -08002522 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
2523 final boolean canceled = event.isCanceled();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002524
Jeff Brown40013652012-05-16 21:22:36 -07002525 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002526 Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount="
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002527 + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed
2528 + " canceled=" + canceled);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002529 }
2530
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002531 // If we think we might have a volume down & power key chord on the way
2532 // but we're not sure, then tell the dispatcher to wait a little while and
2533 // try again later before dispatching.
Christopher Tatee90585f2012-03-05 18:56:25 -08002534 if (mScreenshotChordEnabled && (flags & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07002535 if (mScreenshotChordVolumeDownKeyTriggered && !mScreenshotChordPowerKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002536 final long now = SystemClock.uptimeMillis();
Jeff Brown13f00f02014-10-31 14:45:50 -07002537 final long timeoutTime = mScreenshotChordVolumeDownKeyTime
2538 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002539 if (now < timeoutTime) {
2540 return timeoutTime - now;
2541 }
2542 }
2543 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
Jeff Brown13f00f02014-10-31 14:45:50 -07002544 && mScreenshotChordVolumeDownKeyConsumed) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002545 if (!down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07002546 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002547 }
2548 return -1;
2549 }
2550 }
2551
Michael Wright6a62e552014-06-03 19:19:48 -07002552 // Cancel any pending meta actions if we see any other keys being pressed between the down
2553 // of the meta key and its corresponding up.
Michael Wright251e35d2014-08-22 15:40:27 -07002554 if (mPendingMetaAction && !KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07002555 mPendingMetaAction = false;
2556 }
2557
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002558 // First we always handle the home key here, so applications
2559 // can never break it, although if keyguard is on, we do let
2560 // it handle it, because that gives us the correct 5 second
2561 // timeout.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002562 if (keyCode == KeyEvent.KEYCODE_HOME) {
Michael Jurka7f2668c2012-03-27 07:49:52 -07002563
Jeff Brown49ed71d2010-12-06 17:13:33 -08002564 // If we have released the home key, and didn't do anything else
2565 // while it was pressed, then it is time to go home!
Michael Jurka7f2668c2012-03-27 07:49:52 -07002566 if (!down) {
Jeff Browncaca8812013-05-09 13:34:33 -07002567 cancelPreloadRecentApps();
2568
Jeff Brown49ed71d2010-12-06 17:13:33 -08002569 mHomePressed = false;
Jeff Browncaca8812013-05-09 13:34:33 -07002570 if (mHomeConsumed) {
2571 mHomeConsumed = false;
Michael Jurka7f2668c2012-03-27 07:49:52 -07002572 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002573 }
Jeff Browncaca8812013-05-09 13:34:33 -07002574
2575 if (canceled) {
2576 Log.i(TAG, "Ignoring HOME; event canceled.");
2577 return -1;
2578 }
2579
Yorke Lee4f803242014-12-15 23:22:06 +00002580 // If an incoming call is ringing, HOME is totally disabled.
2581 // (The user is already on the InCallUI at this point,
2582 // and his ONLY options are to answer or reject the call.)
2583 TelecomManager telecomManager = getTelecommService();
2584 if (telecomManager != null && telecomManager.isRinging()) {
2585 Log.i(TAG, "Ignoring HOME; there's a ringing incoming call.");
2586 return -1;
2587 }
2588
Jeff Browncaca8812013-05-09 13:34:33 -07002589 // Delay handling home if a double-tap is possible.
2590 if (mDoubleTapOnHomeBehavior != DOUBLE_TAP_HOME_NOTHING) {
2591 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); // just in case
2592 mHomeDoubleTapPending = true;
2593 mHandler.postDelayed(mHomeDoubleTapTimeoutRunnable,
2594 ViewConfiguration.getDoubleTapTimeout());
2595 return -1;
2596 }
2597
Jeff Brown13f00f02014-10-31 14:45:50 -07002598 handleShortPressOnHome();
Jeff Browncaca8812013-05-09 13:34:33 -07002599 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002600 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002601
2602 // If a system window has focus, then it doesn't make sense
2603 // right now to interact with applications.
2604 WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null;
2605 if (attrs != null) {
2606 final int type = attrs.type;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002607 if (type == WindowManager.LayoutParams.TYPE_KEYGUARD_SCRIM
2608 || type == WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG
2609 || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002610 // the "app" is keyguard, so give it the key
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002611 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002612 }
2613 final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length;
2614 for (int i=0; i<typeCount; i++) {
2615 if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) {
2616 // don't do anything, but also don't pass it to the app
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002617 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002618 }
2619 }
2620 }
Jeff Browncaca8812013-05-09 13:34:33 -07002621
2622 // Remember that home is pressed and handle special actions.
2623 if (repeatCount == 0) {
2624 mHomePressed = true;
2625 if (mHomeDoubleTapPending) {
2626 mHomeDoubleTapPending = false;
2627 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable);
2628 handleDoubleTapOnHome();
2629 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI
2630 || mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
2631 preloadRecentApps();
Michael Jurka7f2668c2012-03-27 07:49:52 -07002632 }
Jeff Browncaca8812013-05-09 13:34:33 -07002633 } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) {
2634 if (!keyguardOn) {
2635 handleLongPressOnHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002636 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002637 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002638 return -1;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002639 } else if (keyCode == KeyEvent.KEYCODE_MENU) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002640 // Hijack modified menu keys for debugging features
2641 final int chordBug = KeyEvent.META_SHIFT_ON;
2642
2643 if (down && repeatCount == 0) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002644 if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002645 Intent intent = new Intent(Intent.ACTION_BUG_REPORT);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002646 mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT,
2647 null, null, null, 0, null, null);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002648 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002649 } else if (SHOW_PROCESSES_ON_ALT_MENU &&
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002650 (metaState & KeyEvent.META_ALT_ON) == KeyEvent.META_ALT_ON) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002651 Intent service = new Intent();
2652 service.setClassName(mContext, "com.android.server.LoadAverageService");
2653 ContentResolver res = mContext.getContentResolver();
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002654 boolean shown = Settings.Global.getInt(
2655 res, Settings.Global.SHOW_PROCESSES, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002656 if (!shown) {
2657 mContext.startService(service);
2658 } else {
2659 mContext.stopService(service);
2660 }
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002661 Settings.Global.putInt(
2662 res, Settings.Global.SHOW_PROCESSES, shown ? 0 : 1);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002663 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002664 }
2665 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002666 } else if (keyCode == KeyEvent.KEYCODE_SEARCH) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002667 if (down) {
2668 if (repeatCount == 0) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002669 mSearchKeyShortcutPending = true;
2670 mConsumeSearchKeyUp = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002671 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002672 } else {
2673 mSearchKeyShortcutPending = false;
2674 if (mConsumeSearchKeyUp) {
2675 mConsumeSearchKeyUp = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002676 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002677 }
2678 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002679 return 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002680 } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) {
Michael Wrightc9ebea72013-01-16 19:25:02 -08002681 if (!keyguardOn) {
Jeff Browncaca8812013-05-09 13:34:33 -07002682 if (down && repeatCount == 0) {
2683 preloadRecentApps();
2684 } else if (!down) {
2685 toggleRecentApps();
Michael Wrightc9ebea72013-01-16 19:25:02 -08002686 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002687 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002688 return -1;
Jun Mukaid21b3c82015-04-23 14:09:34 -07002689 } else if (keyCode == KeyEvent.KEYCODE_N && event.isMetaPressed()) {
2690 if (down) {
2691 IStatusBarService service = getStatusBarService();
2692 if (service != null) {
2693 try {
2694 service.expandNotificationsPanel();
2695 } catch (RemoteException e) {
2696 // do nothing.
2697 }
2698 }
2699 }
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002700 } else if (keyCode == KeyEvent.KEYCODE_ASSIST) {
2701 if (down) {
2702 if (repeatCount == 0) {
2703 mAssistKeyLongPressed = false;
2704 } else if (repeatCount == 1) {
2705 mAssistKeyLongPressed = true;
2706 if (!keyguardOn) {
2707 launchAssistLongPressAction();
2708 }
2709 }
2710 } else {
2711 if (mAssistKeyLongPressed) {
2712 mAssistKeyLongPressed = false;
2713 } else {
2714 if (!keyguardOn) {
2715 launchAssistAction();
2716 }
2717 }
2718 }
2719 return -1;
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002720 } else if (keyCode == KeyEvent.KEYCODE_VOICE_ASSIST) {
2721 if (!down) {
2722 Intent voiceIntent;
Michael Wright869a67c2014-08-26 19:33:06 -07002723 if (!keyguardOn) {
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002724 voiceIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
2725 } else {
2726 voiceIntent = new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
Michael Wright869a67c2014-08-26 19:33:06 -07002727 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, true);
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002728 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00002729 startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002730 }
Jeff Sharkey2991fa32012-12-05 18:06:43 -08002731 } else if (keyCode == KeyEvent.KEYCODE_SYSRQ) {
2732 if (down && repeatCount == 0) {
2733 mHandler.post(mScreenshotRunnable);
2734 }
2735 return -1;
Michael Wrightb854e242013-02-05 17:54:02 -08002736 } else if (keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP
2737 || keyCode == KeyEvent.KEYCODE_BRIGHTNESS_DOWN) {
2738 if (down) {
2739 int direction = keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP ? 1 : -1;
2740
2741 // Disable autobrightness if it's on
2742 int auto = Settings.System.getIntForUser(
2743 mContext.getContentResolver(),
2744 Settings.System.SCREEN_BRIGHTNESS_MODE,
2745 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2746 UserHandle.USER_CURRENT_OR_SELF);
2747 if (auto != 0) {
2748 Settings.System.putIntForUser(mContext.getContentResolver(),
2749 Settings.System.SCREEN_BRIGHTNESS_MODE,
2750 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2751 UserHandle.USER_CURRENT_OR_SELF);
2752 }
2753
2754 int min = mPowerManager.getMinimumScreenBrightnessSetting();
2755 int max = mPowerManager.getMaximumScreenBrightnessSetting();
2756 int step = (max - min + BRIGHTNESS_STEPS - 1) / BRIGHTNESS_STEPS * direction;
2757 int brightness = Settings.System.getIntForUser(mContext.getContentResolver(),
2758 Settings.System.SCREEN_BRIGHTNESS,
2759 mPowerManager.getDefaultScreenBrightnessSetting(),
2760 UserHandle.USER_CURRENT_OR_SELF);
2761 brightness += step;
2762 // Make sure we don't go beyond the limits.
2763 brightness = Math.min(max, brightness);
2764 brightness = Math.max(min, brightness);
2765
2766 Settings.System.putIntForUser(mContext.getContentResolver(),
2767 Settings.System.SCREEN_BRIGHTNESS, brightness,
2768 UserHandle.USER_CURRENT_OR_SELF);
Bart Sears8b1c27c2015-03-18 23:51:02 +00002769 startActivityAsUser(new Intent(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG),
Alan Viverette5a399492014-07-14 16:19:38 -07002770 UserHandle.CURRENT_OR_SELF);
Michael Wrightb854e242013-02-05 17:54:02 -08002771 }
2772 return -1;
Michael Wrightce0c13a2014-07-30 10:49:21 -07002773 } else if (KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07002774 if (down) {
2775 mPendingMetaAction = true;
2776 } else if (mPendingMetaAction) {
Michael Wright8ab940a2014-09-01 11:01:27 -07002777 launchAssistAction(Intent.EXTRA_ASSIST_INPUT_HINT_KEYBOARD);
Michael Wright6a62e552014-06-03 19:19:48 -07002778 }
2779 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002780 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002781
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002782 // Shortcuts are invoked through Search+key, so intercept those here
Jeff Browncaab4d02010-12-09 22:13:41 -08002783 // Any printing key that is chorded with Search should be consumed
2784 // even if no shortcut was invoked. This prevents text from being
2785 // inadvertently inserted when using a keyboard that has built-in macro
2786 // shortcut keys (that emit Search+x) and some of them are not registered.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002787 if (mSearchKeyShortcutPending) {
Jeff Browncaab4d02010-12-09 22:13:41 -08002788 final KeyCharacterMap kcm = event.getKeyCharacterMap();
2789 if (kcm.isPrintingKey(keyCode)) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002790 mConsumeSearchKeyUp = true;
2791 mSearchKeyShortcutPending = false;
Jeff Browncaab4d02010-12-09 22:13:41 -08002792 if (down && repeatCount == 0 && !keyguardOn) {
2793 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState);
2794 if (shortcutIntent != null) {
2795 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002796 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00002797 startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002798 } catch (ActivityNotFoundException ex) {
2799 Slog.w(TAG, "Dropping shortcut key combination because "
2800 + "the activity to which it is registered was not found: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002801 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode), ex);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002802 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002803 } else {
2804 Slog.i(TAG, "Dropping unregistered shortcut key combination: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002805 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002806 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002807 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002808 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002809 }
2810 }
2811
Jeff Brown68b909d2011-12-07 16:36:01 -08002812 // Invoke shortcuts using Meta.
Jeff Brown602ab322012-05-16 13:33:47 -07002813 if (down && repeatCount == 0 && !keyguardOn
Jeff Brown68b909d2011-12-07 16:36:01 -08002814 && (metaState & KeyEvent.META_META_ON) != 0) {
2815 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brown602ab322012-05-16 13:33:47 -07002816 if (kcm.isPrintingKey(keyCode)) {
2817 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode,
2818 metaState & ~(KeyEvent.META_META_ON
2819 | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON));
2820 if (shortcutIntent != null) {
2821 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2822 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00002823 startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brown602ab322012-05-16 13:33:47 -07002824 } catch (ActivityNotFoundException ex) {
2825 Slog.w(TAG, "Dropping shortcut key combination because "
2826 + "the activity to which it is registered was not found: "
2827 + "META+" + KeyEvent.keyCodeToString(keyCode), ex);
2828 }
2829 return -1;
Jeff Brown68b909d2011-12-07 16:36:01 -08002830 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002831 }
2832 }
2833
Jeff Brown6651a632011-11-28 12:59:11 -08002834 // Handle application launch keys.
Jeff Brown602ab322012-05-16 13:33:47 -07002835 if (down && repeatCount == 0 && !keyguardOn) {
Jeff Brown6651a632011-11-28 12:59:11 -08002836 String category = sApplicationLaunchKeyCategories.get(keyCode);
2837 if (category != null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -08002838 Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category);
Jeff Brown6651a632011-11-28 12:59:11 -08002839 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2840 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00002841 startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brown6651a632011-11-28 12:59:11 -08002842 } catch (ActivityNotFoundException ex) {
2843 Slog.w(TAG, "Dropping application launch key because "
2844 + "the activity to which it is registered was not found: "
2845 + "keyCode=" + keyCode + ", category=" + category, ex);
2846 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002847 return -1;
Jeff Brown6651a632011-11-28 12:59:11 -08002848 }
2849 }
2850
Michael Wright61c46752014-08-21 16:57:33 -07002851 // Display task switcher for ALT-TAB.
Jeff Brown68b909d2011-12-07 16:36:01 -08002852 if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_TAB) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002853 if (mRecentAppsHeldModifiers == 0 && !keyguardOn) {
Jeff Brown68b909d2011-12-07 16:36:01 -08002854 final int shiftlessModifiers = event.getModifiers() & ~KeyEvent.META_SHIFT_MASK;
Michael Wright61c46752014-08-21 16:57:33 -07002855 if (KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_ALT_ON)) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002856 mRecentAppsHeldModifiers = shiftlessModifiers;
2857 showRecentApps(true);
Jeff Brown68b909d2011-12-07 16:36:01 -08002858 return -1;
2859 }
2860 }
Winson Chung1e8d71b2014-05-16 17:05:22 -07002861 } else if (!down && mRecentAppsHeldModifiers != 0
2862 && (metaState & mRecentAppsHeldModifiers) == 0) {
2863 mRecentAppsHeldModifiers = 0;
Winson Chungcdcd4872014-08-05 18:00:13 -07002864 hideRecentApps(true, false);
Jeff Brown68b909d2011-12-07 16:36:01 -08002865 }
2866
Jeff Browncf39bdf2012-05-18 14:41:19 -07002867 // Handle keyboard language switching.
2868 if (down && repeatCount == 0
2869 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2870 || (keyCode == KeyEvent.KEYCODE_SPACE
2871 && (metaState & KeyEvent.META_CTRL_MASK) != 0))) {
2872 int direction = (metaState & KeyEvent.META_SHIFT_MASK) != 0 ? -1 : 1;
2873 mWindowManagerFuncs.switchKeyboardLayout(event.getDeviceId(), direction);
2874 return -1;
2875 }
2876 if (mLanguageSwitchKeyPressed && !down
2877 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2878 || keyCode == KeyEvent.KEYCODE_SPACE)) {
2879 mLanguageSwitchKeyPressed = false;
2880 return -1;
2881 }
2882
Jeff Brown13f00f02014-10-31 14:45:50 -07002883 if (isValidGlobalKey(keyCode)
2884 && mGlobalKeyManager.handleGlobalKey(mContext, keyCode, event)) {
Justin Kohd378ad72013-04-01 12:18:26 -07002885 return -1;
2886 }
2887
Michael Wright6a62e552014-06-03 19:19:48 -07002888 // Reserve all the META modifier combos for system behavior
Michael Wrightce0c13a2014-07-30 10:49:21 -07002889 if ((metaState & KeyEvent.META_META_ON) != 0) {
Michael Wright6a62e552014-06-03 19:19:48 -07002890 return -1;
2891 }
2892
Jeff Brown68b909d2011-12-07 16:36:01 -08002893 // Let the application handle the key.
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002894 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002895 }
2896
Jeff Brown3915bb82010-11-05 15:02:16 -07002897 /** {@inheritDoc} */
2898 @Override
Jeff Brown49ed71d2010-12-06 17:13:33 -08002899 public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown54875002011-04-06 15:33:01 -07002900 // Note: This method is only called if the initial down was unhandled.
Jeff Brown40013652012-05-16 21:22:36 -07002901 if (DEBUG_INPUT) {
Jeff Brown1f245102010-11-18 20:53:46 -08002902 Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction()
2903 + ", flags=" + event.getFlags()
2904 + ", keyCode=" + event.getKeyCode()
2905 + ", scanCode=" + event.getScanCode()
2906 + ", metaState=" + event.getMetaState()
2907 + ", repeatCount=" + event.getRepeatCount()
2908 + ", policyFlags=" + policyFlags);
Jeff Brown3915bb82010-11-05 15:02:16 -07002909 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002910
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002911 KeyEvent fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002912 if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
2913 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002914 final int keyCode = event.getKeyCode();
2915 final int metaState = event.getMetaState();
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002916 final boolean initialDown = event.getAction() == KeyEvent.ACTION_DOWN
2917 && event.getRepeatCount() == 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002918
Jeff Brown54875002011-04-06 15:33:01 -07002919 // Check for fallback actions specified by the key character map.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002920 final FallbackAction fallbackAction;
2921 if (initialDown) {
2922 fallbackAction = kcm.getFallbackAction(keyCode, metaState);
2923 } else {
2924 fallbackAction = mFallbackActions.get(keyCode);
2925 }
2926
2927 if (fallbackAction != null) {
Jeff Brown40013652012-05-16 21:22:36 -07002928 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002929 Slog.d(TAG, "Fallback: keyCode=" + fallbackAction.keyCode
2930 + " metaState=" + Integer.toHexString(fallbackAction.metaState));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002931 }
2932
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002933 final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK;
2934 fallbackEvent = KeyEvent.obtain(
Jeff Brown49ed71d2010-12-06 17:13:33 -08002935 event.getDownTime(), event.getEventTime(),
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002936 event.getAction(), fallbackAction.keyCode,
2937 event.getRepeatCount(), fallbackAction.metaState,
Jeff Brown49ed71d2010-12-06 17:13:33 -08002938 event.getDeviceId(), event.getScanCode(),
2939 flags, event.getSource(), null);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002940
2941 if (!interceptFallback(win, fallbackEvent, policyFlags)) {
2942 fallbackEvent.recycle();
2943 fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002944 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002945
2946 if (initialDown) {
2947 mFallbackActions.put(keyCode, fallbackAction);
2948 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2949 mFallbackActions.remove(keyCode);
2950 fallbackAction.recycle();
2951 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002952 }
2953 }
2954
Jeff Brown40013652012-05-16 21:22:36 -07002955 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002956 if (fallbackEvent == null) {
2957 Slog.d(TAG, "No fallback.");
2958 } else {
2959 Slog.d(TAG, "Performing fallback: " + fallbackEvent);
2960 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002961 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002962 return fallbackEvent;
Jeff Brown3915bb82010-11-05 15:02:16 -07002963 }
2964
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002965 private boolean interceptFallback(WindowState win, KeyEvent fallbackEvent, int policyFlags) {
Jeff Brown037c33e2014-04-09 00:31:55 -07002966 int actions = interceptKeyBeforeQueueing(fallbackEvent, policyFlags);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002967 if ((actions & ACTION_PASS_TO_USER) != 0) {
2968 long delayMillis = interceptKeyBeforeDispatching(
2969 win, fallbackEvent, policyFlags);
2970 if (delayMillis == 0) {
2971 return true;
2972 }
2973 }
2974 return false;
Jeff Brown6f2fba42011-02-19 01:08:02 -08002975 }
2976
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002977 private void launchAssistLongPressAction() {
2978 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
2979 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
2980
2981 // launch the search activity
2982 Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS);
2983 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2984 try {
RoboErik8a2cfc32014-05-16 11:19:38 -07002985 // TODO: This only stops the factory-installed search manager.
Jim Miller45308b12012-06-18 19:23:39 -07002986 // Need to formalize an API to handle others
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002987 SearchManager searchManager = getSearchManager();
2988 if (searchManager != null) {
2989 searchManager.stopSearch();
2990 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00002991 startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002992 } catch (ActivityNotFoundException e) {
2993 Slog.w(TAG, "No activity to handle assist long press action.", e);
2994 }
2995 }
2996
2997 private void launchAssistAction() {
Michael Wright8ab940a2014-09-01 11:01:27 -07002998 launchAssistAction(null);
2999 }
3000
3001 private void launchAssistAction(String hint) {
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003002 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
Amith Yamasanic1d07a42012-08-14 09:32:02 -07003003 Intent intent = ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE))
Dianne Hackbornf9c5e0f2013-01-23 14:39:13 -08003004 .getAssistIntent(mContext, true, UserHandle.USER_CURRENT);
Jim Miller45308b12012-06-18 19:23:39 -07003005 if (intent != null) {
Michael Wright8ab940a2014-09-01 11:01:27 -07003006 if (hint != null) {
3007 intent.putExtra(hint, true);
3008 }
Jim Miller45308b12012-06-18 19:23:39 -07003009 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
3010 | Intent.FLAG_ACTIVITY_SINGLE_TOP
3011 | Intent.FLAG_ACTIVITY_CLEAR_TOP);
3012 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00003013 startActivityAsUser(intent, UserHandle.CURRENT);
Jim Miller45308b12012-06-18 19:23:39 -07003014 } catch (ActivityNotFoundException e) {
3015 Slog.w(TAG, "No activity to handle assist action.", e);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003016 }
3017 }
3018 }
3019
Bart Sears8b1c27c2015-03-18 23:51:02 +00003020 private void startActivityAsUser(Intent intent, UserHandle handle) {
3021 if (isUserSetupComplete()) {
3022 mContext.startActivityAsUser(intent, handle);
3023 } else {
3024 Slog.i(TAG, "Not starting activity because user setup is in progress: " + intent);
3025 }
3026 }
3027
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003028 private SearchManager getSearchManager() {
3029 if (mSearchManager == null) {
3030 mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
3031 }
3032 return mSearchManager;
3033 }
3034
Jeff Browncaca8812013-05-09 13:34:33 -07003035 private void preloadRecentApps() {
3036 mPreloadedRecentApps = true;
3037 try {
3038 IStatusBarService statusbar = getStatusBarService();
3039 if (statusbar != null) {
3040 statusbar.preloadRecentApps();
3041 }
3042 } catch (RemoteException e) {
3043 Slog.e(TAG, "RemoteException when preloading recent apps", e);
3044 // re-acquire status bar service next time it is needed.
3045 mStatusBarService = null;
3046 }
3047 }
3048
3049 private void cancelPreloadRecentApps() {
3050 if (mPreloadedRecentApps) {
3051 mPreloadedRecentApps = false;
3052 try {
3053 IStatusBarService statusbar = getStatusBarService();
3054 if (statusbar != null) {
3055 statusbar.cancelPreloadRecentApps();
3056 }
3057 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003058 Slog.e(TAG, "RemoteException when cancelling recent apps preload", e);
Jeff Browncaca8812013-05-09 13:34:33 -07003059 // re-acquire status bar service next time it is needed.
3060 mStatusBarService = null;
3061 }
3062 }
3063 }
3064
3065 private void toggleRecentApps() {
3066 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
Jeff Browncaca8812013-05-09 13:34:33 -07003067 try {
3068 IStatusBarService statusbar = getStatusBarService();
3069 if (statusbar != null) {
3070 statusbar.toggleRecentApps();
3071 }
3072 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003073 Slog.e(TAG, "RemoteException when toggling recent apps", e);
3074 // re-acquire status bar service next time it is needed.
3075 mStatusBarService = null;
3076 }
3077 }
3078
Craig Mautner84984fa2014-06-19 11:19:20 -07003079 @Override
3080 public void showRecentApps() {
3081 mHandler.removeMessages(MSG_DISPATCH_SHOW_RECENTS);
3082 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_RECENTS);
3083 }
3084
Winson Chung1e8d71b2014-05-16 17:05:22 -07003085 private void showRecentApps(boolean triggeredFromAltTab) {
3086 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
3087 try {
3088 IStatusBarService statusbar = getStatusBarService();
3089 if (statusbar != null) {
3090 statusbar.showRecentApps(triggeredFromAltTab);
3091 }
3092 } catch (RemoteException e) {
Jeff Browncaca8812013-05-09 13:34:33 -07003093 Slog.e(TAG, "RemoteException when showing recent apps", e);
3094 // re-acquire status bar service next time it is needed.
3095 mStatusBarService = null;
3096 }
3097 }
3098
Winson Chungcdcd4872014-08-05 18:00:13 -07003099 private void hideRecentApps(boolean triggeredFromAltTab, boolean triggeredFromHome) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003100 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
3101 try {
3102 IStatusBarService statusbar = getStatusBarService();
3103 if (statusbar != null) {
Winson Chungcdcd4872014-08-05 18:00:13 -07003104 statusbar.hideRecentApps(triggeredFromAltTab, triggeredFromHome);
Winson Chung1e8d71b2014-05-16 17:05:22 -07003105 }
3106 } catch (RemoteException e) {
3107 Slog.e(TAG, "RemoteException when closing recent apps", e);
3108 // re-acquire status bar service next time it is needed.
3109 mStatusBarService = null;
3110 }
3111 }
3112
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00003113 void launchHomeFromHotKey() {
Bryce Lee662ed802015-04-10 20:11:39 +00003114 launchHomeFromHotKey(true /* awakenFromDreams */, true /*respectKeyguard*/);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00003115 }
3116
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003117 /**
3118 * A home key -> launch home action was detected. Take the appropriate action
3119 * given the situation with the keyguard.
3120 */
Bryce Lee662ed802015-04-10 20:11:39 +00003121 void launchHomeFromHotKey(final boolean awakenFromDreams, final boolean respectKeyguard) {
3122 if (respectKeyguard) {
3123 if (isKeyguardShowingAndNotOccluded()) {
3124 // don't launch home if keyguard showing
3125 return;
3126 }
3127
3128 if (!mHideLockScreen && mKeyguardDelegate.isInputRestricted()) {
3129 // when in keyguard restricted mode, must first verify unlock
3130 // before launching home
3131 mKeyguardDelegate.verifyUnlock(new OnKeyguardExitResult() {
3132 @Override
3133 public void onKeyguardExitResult(boolean success) {
3134 if (success) {
3135 try {
3136 ActivityManagerNative.getDefault().stopAppSwitches();
3137 } catch (RemoteException e) {
3138 }
3139 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3140 startDockOrHome(true /*fromHomeKey*/, awakenFromDreams);
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07003141 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003142 }
Bryce Lee662ed802015-04-10 20:11:39 +00003143 });
3144 return;
3145 }
3146 }
3147
3148 // no keyguard stuff to worry about, just launch home!
3149 try {
3150 ActivityManagerNative.getDefault().stopAppSwitches();
3151 } catch (RemoteException e) {
3152 }
3153 if (mRecentsVisible) {
3154 // Hide Recents and notify it to launch Home
3155 if (awakenFromDreams) {
3156 awakenDreams();
3157 }
3158 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3159 hideRecentApps(false, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003160 } else {
Bryce Lee662ed802015-04-10 20:11:39 +00003161 // Otherwise, just launch Home
3162 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3163 startDockOrHome(true /*fromHomeKey*/, awakenFromDreams);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003164 }
3165 }
3166
John Spurlock04db1762013-05-13 12:46:41 -04003167 private final Runnable mClearHideNavigationFlag = new Runnable() {
3168 @Override
3169 public void run() {
3170 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
3171 // Clear flags.
3172 mForceClearedSystemUiFlags &=
3173 ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
3174 }
3175 mWindowManagerFuncs.reevaluateStatusBarVisibility();
Dianne Hackborne26ab702011-10-16 13:21:33 -07003176 }
3177 };
3178
3179 /**
3180 * Input handler used while nav bar is hidden. Captures any touch on the screen,
3181 * to determine when the nav bar should be shown and prevent applications from
3182 * receiving those touches.
3183 */
Jeff Brown32cbc38552011-12-01 14:01:49 -08003184 final class HideNavInputEventReceiver extends InputEventReceiver {
3185 public HideNavInputEventReceiver(InputChannel inputChannel, Looper looper) {
3186 super(inputChannel, looper);
3187 }
3188
Dianne Hackborndf89e652011-10-06 22:35:11 -07003189 @Override
Jeff Brown32cbc38552011-12-01 14:01:49 -08003190 public void onInputEvent(InputEvent event) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003191 boolean handled = false;
3192 try {
Jeff Brown4952dfd2011-11-30 19:23:22 -08003193 if (event instanceof MotionEvent
3194 && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
3195 final MotionEvent motionEvent = (MotionEvent)event;
3196 if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003197 // When the user taps down, we re-show the nav bar.
3198 boolean changed = false;
John Spurlock04db1762013-05-13 12:46:41 -04003199 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003200 // Any user activity always causes us to show the
3201 // navigation controls, if they had been hidden.
3202 // We also clear the low profile and only content
3203 // flags so that tapping on the screen will atomically
3204 // restore all currently hidden screen decorations.
3205 int newVal = mResettingSystemUiFlags |
3206 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
3207 View.SYSTEM_UI_FLAG_LOW_PROFILE |
3208 View.SYSTEM_UI_FLAG_FULLSCREEN;
Dianne Hackborne26ab702011-10-16 13:21:33 -07003209 if (mResettingSystemUiFlags != newVal) {
3210 mResettingSystemUiFlags = newVal;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003211 changed = true;
3212 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003213 // We don't allow the system's nav bar to be hidden
3214 // again for 1 second, to prevent applications from
3215 // spamming us and keeping it from being shown.
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003216 newVal = mForceClearedSystemUiFlags |
3217 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
Dianne Hackborne26ab702011-10-16 13:21:33 -07003218 if (mForceClearedSystemUiFlags != newVal) {
3219 mForceClearedSystemUiFlags = newVal;
3220 changed = true;
John Spurlock04db1762013-05-13 12:46:41 -04003221 mHandler.postDelayed(mClearHideNavigationFlag, 1000);
Dianne Hackborne26ab702011-10-16 13:21:33 -07003222 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07003223 }
3224 if (changed) {
3225 mWindowManagerFuncs.reevaluateStatusBarVisibility();
3226 }
3227 }
3228 }
3229 } finally {
Jeff Brown32cbc38552011-12-01 14:01:49 -08003230 finishInputEvent(event, handled);
Dianne Hackborndf89e652011-10-06 22:35:11 -07003231 }
3232 }
Jeff Brown32cbc38552011-12-01 14:01:49 -08003233 }
3234 final InputEventReceiver.Factory mHideNavInputEventReceiverFactory =
3235 new InputEventReceiver.Factory() {
3236 @Override
3237 public InputEventReceiver createInputEventReceiver(
3238 InputChannel inputChannel, Looper looper) {
3239 return new HideNavInputEventReceiver(inputChannel, looper);
3240 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07003241 };
3242
3243 @Override
3244 public int adjustSystemUiVisibilityLw(int visibility) {
John Spurlock5b9145b2013-08-20 15:13:47 -04003245 mStatusBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
3246 mNavigationBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
Winson Chungd42a6cf2014-06-03 16:24:04 -07003247 mRecentsVisible = (visibility & View.RECENT_APPS_VISIBLE) > 0;
John Spurlock27735a42013-08-14 17:57:38 -04003248
Dianne Hackborndf89e652011-10-06 22:35:11 -07003249 // Reset any bits in mForceClearingStatusBarVisibility that
3250 // are now clear.
Dianne Hackborne26ab702011-10-16 13:21:33 -07003251 mResettingSystemUiFlags &= visibility;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003252 // Clear any bits in the new visibility that are currently being
3253 // force cleared, before reporting it.
Dianne Hackborne26ab702011-10-16 13:21:33 -07003254 return visibility & ~mResettingSystemUiFlags
3255 & ~mForceClearedSystemUiFlags;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003256 }
3257
Craig Mautner69b08182012-09-05 13:07:13 -07003258 @Override
Adrian Roos37d7a682014-11-06 18:15:16 +01003259 public void getInsetHintLw(WindowManager.LayoutParams attrs, Rect outContentInsets,
3260 Rect outStableInsets) {
John Spurlockc6d1c602014-01-17 15:22:06 -05003261 final int fl = PolicyControl.getWindowFlags(null, attrs);
John Spurlock1db8b682014-02-18 11:18:59 -05003262 final int sysuiVis = PolicyControl.getSystemUiVisibility(null, attrs);
3263 final int systemUiVisibility = (sysuiVis | attrs.subtreeSystemUiVisibility);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003264
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003265 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003266 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003267 int availRight, availBottom;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003268 if (canHideNavigationBar() &&
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003269 (systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003270 availRight = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3271 availBottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
3272 } else {
3273 availRight = mRestrictedScreenLeft + mRestrictedScreenWidth;
3274 availBottom = mRestrictedScreenTop + mRestrictedScreenHeight;
3275 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003276 if ((systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
3277 if ((fl & FLAG_FULLSCREEN) != 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003278 outContentInsets.set(mStableFullscreenLeft, mStableFullscreenTop,
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003279 availRight - mStableFullscreenRight,
3280 availBottom - mStableFullscreenBottom);
3281 } else {
Adrian Roos37d7a682014-11-06 18:15:16 +01003282 outContentInsets.set(mStableLeft, mStableTop,
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003283 availRight - mStableRight, availBottom - mStableBottom);
3284 }
Dianne Hackbornc652de82013-02-15 16:32:56 -08003285 } else if ((fl & FLAG_FULLSCREEN) != 0 || (fl & FLAG_LAYOUT_IN_OVERSCAN) != 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003286 outContentInsets.setEmpty();
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003287 } else if ((systemUiVisibility & (View.SYSTEM_UI_FLAG_FULLSCREEN
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003288 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)) == 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003289 outContentInsets.set(mCurLeft, mCurTop,
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003290 availRight - mCurRight, availBottom - mCurBottom);
3291 } else {
Adrian Roos37d7a682014-11-06 18:15:16 +01003292 outContentInsets.set(mCurLeft, mCurTop,
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003293 availRight - mCurRight, availBottom - mCurBottom);
3294 }
Adrian Roos37d7a682014-11-06 18:15:16 +01003295
3296 outStableInsets.set(mStableLeft, mStableTop,
3297 availRight - mStableRight, availBottom - mStableBottom);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003298 return;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003299 }
Adrian Roos37d7a682014-11-06 18:15:16 +01003300 outContentInsets.setEmpty();
3301 outStableInsets.setEmpty();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003302 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003303
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003304 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07003305 @Override
3306 public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight,
3307 int displayRotation) {
Dianne Hackbornc652de82013-02-15 16:32:56 -08003308 final int overscanLeft, overscanTop, overscanRight, overscanBottom;
3309 if (isDefaultDisplay) {
3310 switch (displayRotation) {
3311 case Surface.ROTATION_90:
3312 overscanLeft = mOverscanTop;
3313 overscanTop = mOverscanRight;
3314 overscanRight = mOverscanBottom;
3315 overscanBottom = mOverscanLeft;
3316 break;
3317 case Surface.ROTATION_180:
3318 overscanLeft = mOverscanRight;
3319 overscanTop = mOverscanBottom;
3320 overscanRight = mOverscanLeft;
3321 overscanBottom = mOverscanTop;
3322 break;
3323 case Surface.ROTATION_270:
3324 overscanLeft = mOverscanBottom;
3325 overscanTop = mOverscanLeft;
3326 overscanRight = mOverscanTop;
3327 overscanBottom = mOverscanRight;
3328 break;
3329 default:
3330 overscanLeft = mOverscanLeft;
3331 overscanTop = mOverscanTop;
3332 overscanRight = mOverscanRight;
3333 overscanBottom = mOverscanBottom;
3334 break;
3335 }
3336 } else {
3337 overscanLeft = 0;
3338 overscanTop = 0;
3339 overscanRight = 0;
3340 overscanBottom = 0;
3341 }
Dianne Hackborn313440842013-02-19 19:22:59 -08003342 mOverscanScreenLeft = mRestrictedOverscanScreenLeft = 0;
3343 mOverscanScreenTop = mRestrictedOverscanScreenTop = 0;
3344 mOverscanScreenWidth = mRestrictedOverscanScreenWidth = displayWidth;
3345 mOverscanScreenHeight = mRestrictedOverscanScreenHeight = displayHeight;
Dianne Hackbornc652de82013-02-15 16:32:56 -08003346 mSystemLeft = 0;
3347 mSystemTop = 0;
3348 mSystemRight = displayWidth;
3349 mSystemBottom = displayHeight;
3350 mUnrestrictedScreenLeft = overscanLeft;
3351 mUnrestrictedScreenTop = overscanTop;
3352 mUnrestrictedScreenWidth = displayWidth - overscanLeft - overscanRight;
3353 mUnrestrictedScreenHeight = displayHeight - overscanTop - overscanBottom;
3354 mRestrictedScreenLeft = mUnrestrictedScreenLeft;
3355 mRestrictedScreenTop = mUnrestrictedScreenTop;
John Spurlockad3e6cb2013-04-30 08:47:43 -04003356 mRestrictedScreenWidth = mSystemGestures.screenWidth = mUnrestrictedScreenWidth;
3357 mRestrictedScreenHeight = mSystemGestures.screenHeight = mUnrestrictedScreenHeight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003358 mDockLeft = mContentLeft = mVoiceContentLeft = mStableLeft = mStableFullscreenLeft
Dianne Hackbornc652de82013-02-15 16:32:56 -08003359 = mCurLeft = mUnrestrictedScreenLeft;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003360 mDockTop = mContentTop = mVoiceContentTop = mStableTop = mStableFullscreenTop
Dianne Hackbornc652de82013-02-15 16:32:56 -08003361 = mCurTop = mUnrestrictedScreenTop;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003362 mDockRight = mContentRight = mVoiceContentRight = mStableRight = mStableFullscreenRight
Dianne Hackbornc652de82013-02-15 16:32:56 -08003363 = mCurRight = displayWidth - overscanRight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003364 mDockBottom = mContentBottom = mVoiceContentBottom = mStableBottom = mStableFullscreenBottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003365 = mCurBottom = displayHeight - overscanBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003366 mDockLayer = 0x10000000;
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003367 mStatusBarLayer = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003368
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003369 // start with the current dock rect, which will be (0,0,displayWidth,displayHeight)
3370 final Rect pf = mTmpParentFrame;
3371 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003372 final Rect of = mTmpOverscanFrame;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003373 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04003374 final Rect dcf = mTmpDecorFrame;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003375 final Rect osf = mTmpOutsetFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003376 pf.left = df.left = of.left = vf.left = mDockLeft;
3377 pf.top = df.top = of.top = vf.top = mDockTop;
3378 pf.right = df.right = of.right = vf.right = mDockRight;
3379 pf.bottom = df.bottom = of.bottom = vf.bottom = mDockBottom;
John Spurlock46646232013-09-30 22:32:42 -04003380 dcf.setEmpty(); // Decor frame N/A for system bars.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003381
Craig Mautner69b08182012-09-05 13:07:13 -07003382 if (isDefaultDisplay) {
3383 // For purposes of putting out fake window up to steal focus, we will
3384 // drive nav being hidden only by whether it is requested.
John Spurlocke1f366f2013-08-05 12:22:40 -04003385 final int sysui = mLastSystemUiFlags;
3386 boolean navVisible = (sysui & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0;
Adrian Roosea562512014-05-05 13:33:03 +02003387 boolean navTranslucent = (sysui
3388 & (View.NAVIGATION_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04003389 boolean immersive = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
3390 boolean immersiveSticky = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
3391 boolean navAllowedHidden = immersive || immersiveSticky;
3392 navTranslucent &= !immersiveSticky; // transient trumps translucent
Adrian Roos4fb3ee32014-08-22 19:29:09 +02003393 boolean isKeyguardShowing = isStatusBarKeyguard() && !mHideLockScreen;
3394 if (!isKeyguardShowing) {
3395 navTranslucent &= areTranslucentBarsAllowed();
3396 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003397
Craig Mautner69b08182012-09-05 13:07:13 -07003398 // When the navigation bar isn't visible, we put up a fake
3399 // input window to catch all touch events. This way we can
3400 // detect when the user presses anywhere to bring back the nav
3401 // bar and ensure the application doesn't see the event.
John Spurlockf1a36642013-10-12 17:50:42 -04003402 if (navVisible || navAllowedHidden) {
Selim Cinekf83e8242015-05-19 18:08:14 -07003403 if (mInputConsumer != null) {
3404 mInputConsumer.dismiss();
3405 mInputConsumer = null;
Craig Mautner69b08182012-09-05 13:07:13 -07003406 }
Selim Cinekf83e8242015-05-19 18:08:14 -07003407 } else if (mInputConsumer == null) {
3408 mInputConsumer = mWindowManagerFuncs.addInputConsumer(mHandler.getLooper(),
3409 mHideNavInputEventReceiverFactory);
Dianne Hackborne26ab702011-10-16 13:21:33 -07003410 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003411
Craig Mautner69b08182012-09-05 13:07:13 -07003412 // For purposes of positioning and showing the nav bar, if we have
3413 // decided that it can't be hidden (because of the screen aspect ratio),
3414 // then take that into account.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003415 navVisible |= !canHideNavigationBar();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003416
John Spurlockad3e6cb2013-04-30 08:47:43 -04003417 boolean updateSysUiVisibility = false;
Craig Mautner69b08182012-09-05 13:07:13 -07003418 if (mNavigationBar != null) {
John Spurlock27735a42013-08-14 17:57:38 -04003419 boolean transientNavBarShowing = mNavigationBarController.isTransientShowing();
Craig Mautner69b08182012-09-05 13:07:13 -07003420 // Force the navigation bar to its appropriate place and
3421 // size. We need to do this directly, instead of relying on
3422 // it to bubble up from the nav bar, because this needs to
3423 // change atomically with screen rotations.
3424 mNavigationBarOnBottom = (!mNavigationBarCanMove || displayWidth < displayHeight);
3425 if (mNavigationBarOnBottom) {
3426 // It's a system nav bar or a portrait screen; nav bar goes on bottom.
Dianne Hackbornc652de82013-02-15 16:32:56 -08003427 int top = displayHeight - overscanBottom
3428 - mNavigationBarHeightForRotation[displayRotation];
3429 mTmpNavigationFrame.set(0, top, displayWidth, displayHeight - overscanBottom);
Craig Mautner69b08182012-09-05 13:07:13 -07003430 mStableBottom = mStableFullscreenBottom = mTmpNavigationFrame.top;
John Spurlockf95b89a2013-10-10 22:10:42 -04003431 if (transientNavBarShowing) {
John Spurlock27735a42013-08-14 17:57:38 -04003432 mNavigationBarController.setBarShowingLw(true);
John Spurlockad3e6cb2013-04-30 08:47:43 -04003433 } else if (navVisible) {
John Spurlock27735a42013-08-14 17:57:38 -04003434 mNavigationBarController.setBarShowingLw(true);
Craig Mautner69b08182012-09-05 13:07:13 -07003435 mDockBottom = mTmpNavigationFrame.top;
Dianne Hackborn313440842013-02-19 19:22:59 -08003436 mRestrictedScreenHeight = mDockBottom - mRestrictedScreenTop;
3437 mRestrictedOverscanScreenHeight = mDockBottom - mRestrictedOverscanScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07003438 } else {
3439 // We currently want to hide the navigation UI.
John Spurlock27735a42013-08-14 17:57:38 -04003440 mNavigationBarController.setBarShowingLw(false);
Craig Mautner69b08182012-09-05 13:07:13 -07003441 }
John Spurlockc6d1c602014-01-17 15:22:06 -05003442 if (navVisible && !navTranslucent && !navAllowedHidden
3443 && !mNavigationBar.isAnimatingLw()
John Spurlockbd957402013-10-03 11:38:39 -04003444 && !mNavigationBarController.wasRecentlyTranslucent()) {
John Spurlocke1f366f2013-08-05 12:22:40 -04003445 // If the opaque nav bar is currently requested to be visible,
Craig Mautner69b08182012-09-05 13:07:13 -07003446 // and not in the process of animating on or off, then
3447 // we can tell the app that it is covered by it.
3448 mSystemBottom = mTmpNavigationFrame.top;
3449 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003450 } else {
Craig Mautner69b08182012-09-05 13:07:13 -07003451 // Landscape screen; nav bar goes to the right.
Dianne Hackbornc652de82013-02-15 16:32:56 -08003452 int left = displayWidth - overscanRight
3453 - mNavigationBarWidthForRotation[displayRotation];
3454 mTmpNavigationFrame.set(left, 0, displayWidth - overscanRight, displayHeight);
Craig Mautner69b08182012-09-05 13:07:13 -07003455 mStableRight = mStableFullscreenRight = mTmpNavigationFrame.left;
John Spurlockf95b89a2013-10-10 22:10:42 -04003456 if (transientNavBarShowing) {
John Spurlock27735a42013-08-14 17:57:38 -04003457 mNavigationBarController.setBarShowingLw(true);
John Spurlockad3e6cb2013-04-30 08:47:43 -04003458 } else if (navVisible) {
John Spurlock27735a42013-08-14 17:57:38 -04003459 mNavigationBarController.setBarShowingLw(true);
Craig Mautner69b08182012-09-05 13:07:13 -07003460 mDockRight = mTmpNavigationFrame.left;
Dianne Hackborn313440842013-02-19 19:22:59 -08003461 mRestrictedScreenWidth = mDockRight - mRestrictedScreenLeft;
3462 mRestrictedOverscanScreenWidth = mDockRight - mRestrictedOverscanScreenLeft;
Craig Mautner69b08182012-09-05 13:07:13 -07003463 } else {
3464 // We currently want to hide the navigation UI.
John Spurlock27735a42013-08-14 17:57:38 -04003465 mNavigationBarController.setBarShowingLw(false);
Craig Mautner69b08182012-09-05 13:07:13 -07003466 }
John Spurlockbd957402013-10-03 11:38:39 -04003467 if (navVisible && !navTranslucent && !mNavigationBar.isAnimatingLw()
3468 && !mNavigationBarController.wasRecentlyTranslucent()) {
Craig Mautner69b08182012-09-05 13:07:13 -07003469 // If the nav bar is currently requested to be visible,
3470 // and not in the process of animating on or off, then
3471 // we can tell the app that it is covered by it.
3472 mSystemRight = mTmpNavigationFrame.left;
3473 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003474 }
Craig Mautner69b08182012-09-05 13:07:13 -07003475 // Make sure the content and current rectangles are updated to
3476 // account for the restrictions from the navigation bar.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003477 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3478 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3479 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3480 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
Craig Mautner69b08182012-09-05 13:07:13 -07003481 mStatusBarLayer = mNavigationBar.getSurfaceLayer();
3482 // And compute the final frame.
3483 mNavigationBar.computeFrameLw(mTmpNavigationFrame, mTmpNavigationFrame,
Adrian Roosfa104232014-06-20 16:10:14 -07003484 mTmpNavigationFrame, mTmpNavigationFrame, mTmpNavigationFrame, dcf,
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003485 mTmpNavigationFrame, mTmpNavigationFrame);
Craig Mautnereda67292013-04-28 13:50:14 -07003486 if (DEBUG_LAYOUT) Slog.i(TAG, "mNavigationBar frame: " + mTmpNavigationFrame);
John Spurlock27735a42013-08-14 17:57:38 -04003487 if (mNavigationBarController.checkHiddenLw()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04003488 updateSysUiVisibility = true;
3489 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003490 }
Craig Mautnereda67292013-04-28 13:50:14 -07003491 if (DEBUG_LAYOUT) Slog.i(TAG, String.format("mDock rect: (%d,%d - %d,%d)",
Craig Mautner69b08182012-09-05 13:07:13 -07003492 mDockLeft, mDockTop, mDockRight, mDockBottom));
3493
3494 // decide where the status bar goes ahead of time
3495 if (mStatusBar != null) {
3496 // apply any navigation bar insets
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003497 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3498 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3499 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
3500 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight
3501 + mUnrestrictedScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07003502 vf.left = mStableLeft;
3503 vf.top = mStableTop;
3504 vf.right = mStableRight;
3505 vf.bottom = mStableBottom;
3506
3507 mStatusBarLayer = mStatusBar.getSurfaceLayer();
3508
3509 // Let the status bar determine its size.
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003510 mStatusBar.computeFrameLw(pf /* parentFrame */, df /* displayFrame */,
3511 vf /* overlayFrame */, vf /* contentFrame */, vf /* visibleFrame */,
3512 dcf /* decorFrame */, vf /* stableFrame */, vf /* outsetFrame */);
Craig Mautner69b08182012-09-05 13:07:13 -07003513
3514 // For layout, the status bar is always at the top with our fixed height.
3515 mStableTop = mUnrestrictedScreenTop + mStatusBarHeight;
3516
John Spurlocke1f366f2013-08-05 12:22:40 -04003517 boolean statusBarTransient = (sysui & View.STATUS_BAR_TRANSIENT) != 0;
Adrian Roosea562512014-05-05 13:33:03 +02003518 boolean statusBarTranslucent = (sysui
3519 & (View.STATUS_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0;
Adrian Roos4fb3ee32014-08-22 19:29:09 +02003520 if (!isKeyguardShowing) {
3521 statusBarTranslucent &= areTranslucentBarsAllowed();
3522 }
John Spurlock32beb2c2013-03-11 10:16:47 -04003523
Craig Mautner69b08182012-09-05 13:07:13 -07003524 // If the status bar is hidden, we don't want to cause
3525 // windows behind it to scroll.
John Spurlockeda1f692013-09-16 11:38:44 -04003526 if (mStatusBar.isVisibleLw() && !statusBarTransient) {
Craig Mautner69b08182012-09-05 13:07:13 -07003527 // Status bar may go away, so the screen area it occupies
3528 // is available to apps but just covering them when the
3529 // status bar is visible.
3530 mDockTop = mUnrestrictedScreenTop + mStatusBarHeight;
3531
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003532 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3533 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3534 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3535 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
Craig Mautner69b08182012-09-05 13:07:13 -07003536
Craig Mautnereda67292013-04-28 13:50:14 -07003537 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar: " +
Craig Mautner69b08182012-09-05 13:07:13 -07003538 String.format(
3539 "dock=[%d,%d][%d,%d] content=[%d,%d][%d,%d] cur=[%d,%d][%d,%d]",
3540 mDockLeft, mDockTop, mDockRight, mDockBottom,
3541 mContentLeft, mContentTop, mContentRight, mContentBottom,
3542 mCurLeft, mCurTop, mCurRight, mCurBottom));
3543 }
John Spurlocke1f366f2013-08-05 12:22:40 -04003544 if (mStatusBar.isVisibleLw() && !mStatusBar.isAnimatingLw()
John Spurlockbd957402013-10-03 11:38:39 -04003545 && !statusBarTransient && !statusBarTranslucent
3546 && !mStatusBarController.wasRecentlyTranslucent()) {
John Spurlocke1f366f2013-08-05 12:22:40 -04003547 // If the opaque status bar is currently requested to be visible,
Craig Mautner69b08182012-09-05 13:07:13 -07003548 // and not in the process of animating on or off, then
3549 // we can tell the app that it is covered by it.
3550 mSystemTop = mUnrestrictedScreenTop + mStatusBarHeight;
3551 }
John Spurlock27735a42013-08-14 17:57:38 -04003552 if (mStatusBarController.checkHiddenLw()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04003553 updateSysUiVisibility = true;
John Spurlock32beb2c2013-03-11 10:16:47 -04003554 }
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003555 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04003556 if (updateSysUiVisibility) {
3557 updateSystemUiVisibilityLw();
3558 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003559 }
3560 }
3561
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003562 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07003563 @Override
John Spurlock46646232013-09-30 22:32:42 -04003564 public int getSystemDecorLayerLw() {
Bryce Lee2ed3e5f2015-04-01 22:09:19 +00003565 if (mStatusBar != null && mStatusBar.isVisibleLw()) {
3566 return mStatusBar.getSurfaceLayer();
3567 }
3568
3569 if (mNavigationBar != null && mNavigationBar.isVisibleLw()) {
3570 return mNavigationBar.getSurfaceLayer();
3571 }
3572
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003573 return 0;
3574 }
3575
Craig Mautner967212c2013-04-13 21:10:58 -07003576 @Override
3577 public void getContentRectLw(Rect r) {
3578 r.set(mContentLeft, mContentTop, mContentRight, mContentBottom);
3579 }
3580
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003581 void setAttachedWindowFrames(WindowState win, int fl, int adjust, WindowState attached,
3582 boolean insetDecors, Rect pf, Rect df, Rect of, Rect cf, Rect vf) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003583 if (win.getSurfaceLayer() > mDockLayer && attached.getSurfaceLayer() < mDockLayer) {
3584 // Here's a special case: if this attached window is a panel that is
3585 // above the dock window, and the window it is attached to is below
3586 // the dock window, then the frames we computed for the window it is
3587 // attached to can not be used because the dock is effectively part
3588 // of the underlying window and the attached window is floating on top
3589 // of the whole thing. So, we ignore the attached window and explicitly
3590 // compute the frames that would be appropriate without the dock.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003591 df.left = of.left = cf.left = vf.left = mDockLeft;
3592 df.top = of.top = cf.top = vf.top = mDockTop;
3593 df.right = of.right = cf.right = vf.right = mDockRight;
3594 df.bottom = of.bottom = cf.bottom = vf.bottom = mDockBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003595 } else {
3596 // The effective display frame of the attached window depends on
3597 // whether it is taking care of insetting its content. If not,
3598 // we need to use the parent's content frame so that the entire
3599 // window is positioned within that content. Otherwise we can use
Wale Ogunwale393b1c12014-10-18 16:22:01 -07003600 // the overscan frame and let the attached window take care of
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003601 // positioning its content appropriately.
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003602 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Wale Ogunwale393b1c12014-10-18 16:22:01 -07003603 // Set the content frame of the attached window to the parent's decor frame
3604 // (same as content frame when IME isn't present) if specifically requested by
3605 // setting {@link WindowManager.LayoutParams#FLAG_LAYOUT_ATTACHED_IN_DECOR} flag.
3606 // Otherwise, use the overscan frame.
3607 cf.set((fl & FLAG_LAYOUT_ATTACHED_IN_DECOR) != 0
3608 ? attached.getContentFrameLw() : attached.getOverscanFrameLw());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003609 } else {
3610 // If the window is resizing, then we want to base the content
3611 // frame on our attached content frame to resize... however,
3612 // things can be tricky if the attached window is NOT in resize
3613 // mode, in which case its content frame will be larger.
3614 // Ungh. So to deal with that, make sure the content frame
3615 // we end up using is not covering the IM dock.
3616 cf.set(attached.getContentFrameLw());
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003617 if (attached.isVoiceInteraction()) {
3618 if (cf.left < mVoiceContentLeft) cf.left = mVoiceContentLeft;
3619 if (cf.top < mVoiceContentTop) cf.top = mVoiceContentTop;
3620 if (cf.right > mVoiceContentRight) cf.right = mVoiceContentRight;
3621 if (cf.bottom > mVoiceContentBottom) cf.bottom = mVoiceContentBottom;
3622 } else if (attached.getSurfaceLayer() < mDockLayer) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003623 if (cf.left < mContentLeft) cf.left = mContentLeft;
3624 if (cf.top < mContentTop) cf.top = mContentTop;
3625 if (cf.right > mContentRight) cf.right = mContentRight;
3626 if (cf.bottom > mContentBottom) cf.bottom = mContentBottom;
3627 }
3628 }
3629 df.set(insetDecors ? attached.getDisplayFrameLw() : cf);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003630 of.set(insetDecors ? attached.getOverscanFrameLw() : cf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003631 vf.set(attached.getVisibleFrameLw());
3632 }
3633 // The LAYOUT_IN_SCREEN flag is used to determine whether the attached
3634 // window should be positioned relative to its parent or the entire
3635 // screen.
3636 pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0
3637 ? attached.getFrameLw() : df);
3638 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003639
3640 private void applyStableConstraints(int sysui, int fl, Rect r) {
3641 if ((sysui & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
3642 // If app is requesting a stable layout, don't let the
3643 // content insets go below the stable values.
3644 if ((fl & FLAG_FULLSCREEN) != 0) {
3645 if (r.left < mStableFullscreenLeft) r.left = mStableFullscreenLeft;
3646 if (r.top < mStableFullscreenTop) r.top = mStableFullscreenTop;
3647 if (r.right > mStableFullscreenRight) r.right = mStableFullscreenRight;
3648 if (r.bottom > mStableFullscreenBottom) r.bottom = mStableFullscreenBottom;
3649 } else {
3650 if (r.left < mStableLeft) r.left = mStableLeft;
3651 if (r.top < mStableTop) r.top = mStableTop;
3652 if (r.right > mStableRight) r.right = mStableRight;
3653 if (r.bottom > mStableBottom) r.bottom = mStableBottom;
3654 }
3655 }
3656 }
3657
Jorim Jaggiaa806142015-05-20 18:04:16 -07003658 private boolean canReceiveInput(WindowState win) {
3659 boolean notFocusable =
3660 (win.getAttrs().flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0;
3661 boolean altFocusableIm =
3662 (win.getAttrs().flags & WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM) != 0;
3663 boolean notFocusableForIm = notFocusable ^ altFocusableIm;
3664 return !notFocusableForIm;
3665 }
3666
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003667 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07003668 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003669 public void layoutWindowLw(WindowState win, WindowState attached) {
Jorim Jaggiaa806142015-05-20 18:04:16 -07003670 // We've already done the navigation bar and status bar. If the status bar can receive
3671 // input, we need to layout it again to accomodate for the IME window.
3672 if ((win == mStatusBar && !canReceiveInput(win)) || win == mNavigationBar) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003673 return;
3674 }
Jorim Jaggiaa806142015-05-20 18:04:16 -07003675 final WindowManager.LayoutParams attrs = win.getAttrs();
Craig Mautner69b08182012-09-05 13:07:13 -07003676 final boolean isDefaultDisplay = win.isDefaultDisplay();
3677 final boolean needsToOffsetInputMethodTarget = isDefaultDisplay &&
satok1bc0a492012-04-25 22:47:12 +09003678 (win == mLastInputMethodTargetWindow && mLastInputMethodWindow != null);
3679 if (needsToOffsetInputMethodTarget) {
Craig Mautnereda67292013-04-28 13:50:14 -07003680 if (DEBUG_LAYOUT) Slog.i(TAG, "Offset ime target window by the last ime window state");
satok1bc0a492012-04-25 22:47:12 +09003681 offsetInputMethodWindowLw(mLastInputMethodWindow);
3682 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003683
John Spurlockc6d1c602014-01-17 15:22:06 -05003684 final int fl = PolicyControl.getWindowFlags(win, attrs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003685 final int sim = attrs.softInputMode;
John Spurlock1db8b682014-02-18 11:18:59 -05003686 final int sysUiFl = PolicyControl.getSystemUiVisibility(win, null);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003687
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003688 final Rect pf = mTmpParentFrame;
3689 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003690 final Rect of = mTmpOverscanFrame;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003691 final Rect cf = mTmpContentFrame;
3692 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04003693 final Rect dcf = mTmpDecorFrame;
Adrian Roosfa104232014-06-20 16:10:14 -07003694 final Rect sf = mTmpStableFrame;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003695 Rect osf = null;
John Spurlock46646232013-09-30 22:32:42 -04003696 dcf.setEmpty();
Craig Mautner69b08182012-09-05 13:07:13 -07003697
3698 final boolean hasNavBar = (isDefaultDisplay && mHasNavigationBar
Daniel Sandler36412a72011-08-04 09:35:13 -04003699 && mNavigationBar != null && mNavigationBar.isVisibleLw());
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003700
Craig Mautnerf683b562012-10-02 11:10:57 -07003701 final int adjust = sim & SOFT_INPUT_MASK_ADJUST;
3702
Adrian Roosfa104232014-06-20 16:10:14 -07003703 if (isDefaultDisplay) {
3704 sf.set(mStableLeft, mStableTop, mStableRight, mStableBottom);
3705 } else {
3706 sf.set(mOverscanLeft, mOverscanTop, mOverscanRight, mOverscanBottom);
3707 }
3708
Craig Mautner69b08182012-09-05 13:07:13 -07003709 if (!isDefaultDisplay) {
3710 if (attached != null) {
3711 // If this window is attached to another, our display
3712 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003713 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07003714 } else {
3715 // Give the window full screen.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003716 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3717 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3718 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08003719 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003720 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003721 = mOverscanScreenTop + mOverscanScreenHeight;
Craig Mautner69b08182012-09-05 13:07:13 -07003722 }
Jorim Jaggi225d3b52015-04-01 11:18:57 -07003723 } else if (attrs.type == TYPE_INPUT_METHOD) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003724 pf.left = df.left = of.left = cf.left = vf.left = mDockLeft;
3725 pf.top = df.top = of.top = cf.top = vf.top = mDockTop;
3726 pf.right = df.right = of.right = cf.right = vf.right = mDockRight;
John Spurlockc68d5772013-10-08 11:47:58 -04003727 // IM dock windows layout below the nav bar...
John Spurlock57beb3b2013-10-10 10:27:44 -04003728 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlockc68d5772013-10-08 11:47:58 -04003729 // ...with content insets above the nav bar
3730 cf.bottom = vf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003731 // IM dock windows always go to the bottom of the screen.
3732 attrs.gravity = Gravity.BOTTOM;
3733 mDockLayer = win.getSurfaceLayer();
Jorim Jaggi225d3b52015-04-01 11:18:57 -07003734 } else if (attrs.type == TYPE_VOICE_INTERACTION) {
3735 pf.left = df.left = of.left = cf.left = vf.left = mUnrestrictedScreenLeft;
3736 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3737 pf.right = df.right = of.right = cf.right = vf.right = mUnrestrictedScreenLeft
3738 + mUnrestrictedScreenWidth;
3739 pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop
3740 + mUnrestrictedScreenHeight;
3741 cf.bottom = vf.bottom = mStableBottom;
3742 cf.top = vf.top = mStableTop;
Jorim Jaggiaa806142015-05-20 18:04:16 -07003743 } else if (win == mStatusBar) {
Jorim Jaggie0700182014-08-21 01:12:37 +02003744 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3745 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3746 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
3747 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight + mUnrestrictedScreenTop;
3748 cf.left = vf.left = mStableLeft;
3749 cf.top = vf.top = mStableTop;
3750 cf.right = vf.right = mStableRight;
3751 vf.bottom = mStableBottom;
3752 cf.bottom = mContentBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003753 } else {
John Spurlock46646232013-09-30 22:32:42 -04003754
3755 // Default policy decor for the default display
3756 dcf.left = mSystemLeft;
3757 dcf.top = mSystemTop;
3758 dcf.right = mSystemRight;
3759 dcf.bottom = mSystemBottom;
John Spurlockbd957402013-10-03 11:38:39 -04003760 final boolean inheritTranslucentDecor = (attrs.privateFlags
3761 & WindowManager.LayoutParams.PRIVATE_FLAG_INHERIT_TRANSLUCENT_DECOR) != 0;
John Spurlock65567d42013-10-08 10:08:32 -04003762 final boolean isAppWindow =
3763 attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW &&
3764 attrs.type <= WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
3765 final boolean topAtRest =
3766 win == mTopFullscreenOpaqueWindowState && !win.isAnimatingLw();
3767 if (isAppWindow && !inheritTranslucentDecor && !topAtRest) {
John Spurlockbd957402013-10-03 11:38:39 -04003768 if ((sysUiFl & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0
3769 && (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0
Adrian Roosea562512014-05-05 13:33:03 +02003770 && (fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) == 0
3771 && (fl & WindowManager.LayoutParams.
3772 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04003773 // Ensure policy decor includes status bar
3774 dcf.top = mStableTop;
3775 }
John Spurlockbd957402013-10-03 11:38:39 -04003776 if ((fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) == 0
Adrian Roosea562512014-05-05 13:33:03 +02003777 && (sysUiFl & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0
3778 && (fl & WindowManager.LayoutParams.
3779 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04003780 // Ensure policy decor includes navigation bar
3781 dcf.bottom = mStableBottom;
3782 dcf.right = mStableRight;
3783 }
3784 }
3785
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003786 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
3787 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
RoboErik8a2cfc32014-05-16 11:19:38 -07003788 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003789 + "): IN_SCREEN, INSET_DECOR");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003790 // This is the case for a normal activity window: we want it
3791 // to cover all of the screen space, and it can take care of
3792 // moving its contents to account for screen decorations that
3793 // intrude into that space.
3794 if (attached != null) {
3795 // If this window is attached to another, our display
3796 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003797 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003798 } else {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003799 if (attrs.type == TYPE_STATUS_BAR_PANEL
3800 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Joe Onorato29fc2c92010-11-24 10:26:50 -08003801 // Status bar panels are the only windows who can go on top of
3802 // the status bar. They are protected by the STATUS_BAR_SERVICE
3803 // permission, so they have the same privileges as the status
3804 // bar itself.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003805 //
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003806 // However, they should still dodge the navigation bar if it exists.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003807
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003808 pf.left = df.left = of.left = hasNavBar
3809 ? mDockLeft : mUnrestrictedScreenLeft;
3810 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3811 pf.right = df.right = of.right = hasNavBar
3812 ? mRestrictedScreenLeft+mRestrictedScreenWidth
3813 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3814 pf.bottom = df.bottom = of.bottom = hasNavBar
3815 ? mRestrictedScreenTop+mRestrictedScreenHeight
3816 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003817
Craig Mautnereda67292013-04-28 13:50:14 -07003818 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003819 "Laying out status bar window: (%d,%d - %d,%d)",
3820 pf.left, pf.top, pf.right, pf.bottom));
John Spurlock46646232013-09-30 22:32:42 -04003821 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08003822 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3823 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3824 // Asking to layout into the overscan region, so give it that pure
3825 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003826 pf.left = df.left = of.left = mOverscanScreenLeft;
3827 pf.top = df.top = of.top = mOverscanScreenTop;
3828 pf.right = df.right = of.right = mOverscanScreenLeft + mOverscanScreenWidth;
3829 pf.bottom = df.bottom = of.bottom = mOverscanScreenTop
3830 + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003831 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003832 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003833 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3834 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003835 // Asking for layout as if the nav bar is hidden, lets the
Dianne Hackbornc652de82013-02-15 16:32:56 -08003836 // application extend into the unrestricted overscan screen area. We
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003837 // only do this for application windows to ensure no window that
3838 // can be above the nav bar can do this.
Dianne Hackborn313440842013-02-19 19:22:59 -08003839 pf.left = df.left = mOverscanScreenLeft;
3840 pf.top = df.top = mOverscanScreenTop;
3841 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
3842 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003843 // We need to tell the app about where the frame inside the overscan
3844 // is, so it can inset its content by that amount -- it didn't ask
3845 // to actually extend itself into the overscan region.
3846 of.left = mUnrestrictedScreenLeft;
3847 of.top = mUnrestrictedScreenTop;
3848 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3849 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003850 } else {
Dianne Hackborn313440842013-02-19 19:22:59 -08003851 pf.left = df.left = mRestrictedOverscanScreenLeft;
3852 pf.top = df.top = mRestrictedOverscanScreenTop;
3853 pf.right = df.right = mRestrictedOverscanScreenLeft
3854 + mRestrictedOverscanScreenWidth;
3855 pf.bottom = df.bottom = mRestrictedOverscanScreenTop
3856 + mRestrictedOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003857 // We need to tell the app about where the frame inside the overscan
3858 // is, so it can inset its content by that amount -- it didn't ask
3859 // to actually extend itself into the overscan region.
3860 of.left = mUnrestrictedScreenLeft;
3861 of.top = mUnrestrictedScreenTop;
3862 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3863 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003864 }
Craig Mautner69b08182012-09-05 13:07:13 -07003865
John Spurlock46646232013-09-30 22:32:42 -04003866 if ((fl & FLAG_FULLSCREEN) == 0) {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003867 if (win.isVoiceInteraction()) {
3868 cf.left = mVoiceContentLeft;
3869 cf.top = mVoiceContentTop;
3870 cf.right = mVoiceContentRight;
3871 cf.bottom = mVoiceContentBottom;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003872 } else {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003873 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
3874 cf.left = mDockLeft;
3875 cf.top = mDockTop;
3876 cf.right = mDockRight;
3877 cf.bottom = mDockBottom;
3878 } else {
3879 cf.left = mContentLeft;
3880 cf.top = mContentTop;
3881 cf.right = mContentRight;
3882 cf.bottom = mContentBottom;
3883 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003884 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003885 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003886 // Full screen windows are always given a layout that is as if the
3887 // status bar and other transient decors are gone. This is to avoid
3888 // bad states when moving from a window that is not hding the
3889 // status bar to one that is.
3890 cf.left = mRestrictedScreenLeft;
3891 cf.top = mRestrictedScreenTop;
3892 cf.right = mRestrictedScreenLeft + mRestrictedScreenWidth;
3893 cf.bottom = mRestrictedScreenTop + mRestrictedScreenHeight;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003894 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003895 applyStableConstraints(sysUiFl, fl, cf);
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003896 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3897 vf.left = mCurLeft;
3898 vf.top = mCurTop;
3899 vf.right = mCurRight;
3900 vf.bottom = mCurBottom;
3901 } else {
3902 vf.set(cf);
3903 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003904 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003905 } else if ((fl & FLAG_LAYOUT_IN_SCREEN) != 0 || (sysUiFl
3906 & (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
3907 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)) != 0) {
Craig Mautnereda67292013-04-28 13:50:14 -07003908 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3909 "): IN_SCREEN");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003910 // A window that has requested to fill the entire screen just
3911 // gets everything, period.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003912 if (attrs.type == TYPE_STATUS_BAR_PANEL
3913 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003914 pf.left = df.left = of.left = cf.left = hasNavBar
3915 ? mDockLeft : mUnrestrictedScreenLeft;
3916 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
3917 pf.right = df.right = of.right = cf.right = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003918 ? mRestrictedScreenLeft+mRestrictedScreenWidth
Dianne Hackbornc652de82013-02-15 16:32:56 -08003919 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003920 pf.bottom = df.bottom = of.bottom = cf.bottom = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003921 ? mRestrictedScreenTop+mRestrictedScreenHeight
Dianne Hackbornc652de82013-02-15 16:32:56 -08003922 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07003923 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler36412a72011-08-04 09:35:13 -04003924 "Laying out IN_SCREEN status bar window: (%d,%d - %d,%d)",
3925 pf.left, pf.top, pf.right, pf.bottom));
Jim Millere898ac52012-04-06 17:10:57 -07003926 } else if (attrs.type == TYPE_NAVIGATION_BAR
3927 || attrs.type == TYPE_NAVIGATION_BAR_PANEL) {
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003928 // The navigation bar has Real Ultimate Power.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003929 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3930 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3931 pf.right = df.right = of.right = mUnrestrictedScreenLeft
3932 + mUnrestrictedScreenWidth;
3933 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop
3934 + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07003935 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003936 "Laying out navigation bar window: (%d,%d - %d,%d)",
3937 pf.left, pf.top, pf.right, pf.bottom));
Dianne Hackborn01011c32012-02-21 13:54:21 -08003938 } else if ((attrs.type == TYPE_SECURE_SYSTEM_OVERLAY
3939 || attrs.type == TYPE_BOOT_PROGRESS)
Jeff Brownbfcb60a2011-09-08 18:51:14 -07003940 && ((fl & FLAG_FULLSCREEN) != 0)) {
3941 // Fullscreen secure system overlays get what they ask for.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003942 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3943 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3944 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
3945 + mOverscanScreenWidth;
3946 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
3947 + mOverscanScreenHeight;
Craig Mautner165be0c2015-01-27 15:16:58 -08003948 } else if (attrs.type == TYPE_BOOT_PROGRESS) {
Dianne Hackborn01011c32012-02-21 13:54:21 -08003949 // Boot progress screen always covers entire display.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003950 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3951 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3952 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
3953 + mOverscanScreenWidth;
3954 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
3955 + mOverscanScreenHeight;
John Spurlockef4adae2013-08-26 17:58:58 -04003956 } else if (attrs.type == TYPE_WALLPAPER) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07003957 // The wallpaper also has Real Ultimate Power, but we want to tell
3958 // it about the overscan area.
3959 pf.left = df.left = mOverscanScreenLeft;
3960 pf.top = df.top = mOverscanScreenTop;
3961 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
3962 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
3963 of.left = cf.left = mUnrestrictedScreenLeft;
3964 of.top = cf.top = mUnrestrictedScreenTop;
3965 of.right = cf.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3966 of.bottom = cf.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlock46646232013-09-30 22:32:42 -04003967 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08003968 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3969 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3970 // Asking to layout into the overscan region, so give it that pure
3971 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003972 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3973 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3974 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08003975 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003976 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003977 = mOverscanScreenTop + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003978 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003979 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Craig Mautnerbeac1062014-06-03 14:38:57 -07003980 && (attrs.type == TYPE_STATUS_BAR
3981 || attrs.type == TYPE_TOAST
Jorim Jaggi2fdeeab2015-04-01 15:13:03 -07003982 || attrs.type == TYPE_VOICE_INTERACTION_STARTING
John Spurlock34e13d92013-08-10 06:52:28 -04003983 || (attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3984 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW))) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003985 // Asking for layout as if the nav bar is hidden, lets the
3986 // application extend into the unrestricted screen area. We
John Spurlock34e13d92013-08-10 06:52:28 -04003987 // only do this for application windows (or toasts) to ensure no window that
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003988 // can be above the nav bar can do this.
3989 // XXX This assumes that an app asking for this will also
3990 // ask for layout in only content. We can't currently figure out
3991 // what the screen would be if only laying out to hide the nav bar.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003992 pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft;
3993 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
3994 pf.right = df.right = of.right = cf.right = mUnrestrictedScreenLeft
3995 + mUnrestrictedScreenWidth;
3996 pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop
3997 + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003998 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003999 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
4000 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
4001 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
4002 + mRestrictedScreenWidth;
4003 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
4004 + mRestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08004005 }
Craig Mautner69b08182012-09-05 13:07:13 -07004006
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07004007 applyStableConstraints(sysUiFl, fl, cf);
Craig Mautner69b08182012-09-05 13:07:13 -07004008
Dianne Hackborndea3ef72010-10-28 14:24:22 -07004009 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
4010 vf.left = mCurLeft;
4011 vf.top = mCurTop;
4012 vf.right = mCurRight;
4013 vf.bottom = mCurBottom;
4014 } else {
4015 vf.set(cf);
4016 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004017 } else if (attached != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07004018 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
4019 "): attached to " + attached);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004020 // A child window should be placed inside of the same visible
4021 // frame that its parent had.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004022 setAttachedWindowFrames(win, fl, adjust, attached, false, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004023 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07004024 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
4025 "): normal window");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004026 // Otherwise, a normal window must be placed inside the content
4027 // of all screen decorations.
Dianne Hackborna239c842011-06-01 12:28:20 -07004028 if (attrs.type == TYPE_STATUS_BAR_PANEL) {
4029 // Status bar panels are the only windows who can go on top of
4030 // the status bar. They are protected by the STATUS_BAR_SERVICE
4031 // permission, so they have the same privileges as the status
4032 // bar itself.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004033 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
4034 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
4035 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
4036 + mRestrictedScreenWidth;
4037 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
4038 + mRestrictedScreenHeight;
John Spurlock414c1f02013-12-04 13:47:36 -05004039 } else if (attrs.type == TYPE_TOAST || attrs.type == TYPE_SYSTEM_ALERT
4040 || attrs.type == TYPE_VOLUME_OVERLAY) {
4041 // These dialogs are stable to interim decor changes.
John Spurlockbd957402013-10-03 11:38:39 -04004042 pf.left = df.left = of.left = cf.left = mStableLeft;
4043 pf.top = df.top = of.top = cf.top = mStableTop;
4044 pf.right = df.right = of.right = cf.right = mStableRight;
4045 pf.bottom = df.bottom = of.bottom = cf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004046 } else {
Dianne Hackborna239c842011-06-01 12:28:20 -07004047 pf.left = mContentLeft;
4048 pf.top = mContentTop;
4049 pf.right = mContentRight;
4050 pf.bottom = mContentBottom;
Dianne Hackborn20d94742014-05-29 18:35:45 -07004051 if (win.isVoiceInteraction()) {
4052 df.left = of.left = cf.left = mVoiceContentLeft;
4053 df.top = of.top = cf.top = mVoiceContentTop;
4054 df.right = of.right = cf.right = mVoiceContentRight;
4055 df.bottom = of.bottom = cf.bottom = mVoiceContentBottom;
4056 } else if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004057 df.left = of.left = cf.left = mDockLeft;
4058 df.top = of.top = cf.top = mDockTop;
4059 df.right = of.right = cf.right = mDockRight;
4060 df.bottom = of.bottom = cf.bottom = mDockBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07004061 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004062 df.left = of.left = cf.left = mContentLeft;
4063 df.top = of.top = cf.top = mContentTop;
4064 df.right = of.right = cf.right = mContentRight;
4065 df.bottom = of.bottom = cf.bottom = mContentBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07004066 }
4067 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
4068 vf.left = mCurLeft;
4069 vf.top = mCurTop;
4070 vf.right = mCurRight;
4071 vf.bottom = mCurBottom;
4072 } else {
4073 vf.set(cf);
4074 }
Dianne Hackborndea3ef72010-10-28 14:24:22 -07004075 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004076 }
4077 }
Craig Mautner69b08182012-09-05 13:07:13 -07004078
Craig Mautnerb816bed2013-07-23 10:26:17 -07004079 // TYPE_SYSTEM_ERROR is above the NavigationBar so it can't be allowed to extend over it.
4080 if ((fl & FLAG_LAYOUT_NO_LIMITS) != 0 && attrs.type != TYPE_SYSTEM_ERROR) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07004081 df.left = df.top = -10000;
4082 df.right = df.bottom = 10000;
4083 if (attrs.type != TYPE_WALLPAPER) {
4084 of.left = of.top = cf.left = cf.top = vf.left = vf.top = -10000;
4085 of.right = of.bottom = cf.right = cf.bottom = vf.right = vf.bottom = 10000;
4086 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004087 }
4088
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004089 // If the device has a chin (e.g. some watches), a dead area at the bottom of the screen we
4090 // need to provide information to the clients that want to pretend that you can draw there.
4091 if (isDefaultDisplay && (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0) {
4092 osf = mTmpOutsetFrame;
4093 osf.set(cf.left, cf.top, cf.right, cf.bottom);
4094 int outset = ScreenShapeHelper.getWindowOutsetBottomPx(mContext.getResources());
4095 if (outset > 0) {
4096 int rotation = Surface.ROTATION_0;
4097 try {
4098 rotation = mWindowManager.getRotation();
4099 } catch (RemoteException e) {
4100 }
4101 if (rotation == Surface.ROTATION_0) {
4102 osf.bottom += outset;
4103 } else if (rotation == Surface.ROTATION_90) {
4104 osf.right += outset;
4105 } else if (rotation == Surface.ROTATION_180) {
4106 osf.top -= outset;
4107 } else if (rotation == Surface.ROTATION_270) {
4108 osf.left -= outset;
4109 }
4110 if (DEBUG_LAYOUT) Slog.v(TAG, "applying bottom outset of " + outset
4111 + " with rotation " + rotation + ", result: " + osf);
4112 }
4113 }
4114
Craig Mautnereda67292013-04-28 13:50:14 -07004115 if (DEBUG_LAYOUT) Slog.v(TAG, "Compute frame " + attrs.getTitle()
The Android Open Source Project11267662009-03-18 17:39:47 -07004116 + ": sim=#" + Integer.toHexString(sim)
RoboErik8a2cfc32014-05-16 11:19:38 -07004117 + " attach=" + attached + " type=" + attrs.type
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004118 + String.format(" flags=0x%08x", fl)
The Android Open Source Project11267662009-03-18 17:39:47 -07004119 + " pf=" + pf.toShortString() + " df=" + df.toShortString()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004120 + " of=" + of.toShortString()
John Spurlock46646232013-09-30 22:32:42 -04004121 + " cf=" + cf.toShortString() + " vf=" + vf.toShortString()
Adrian Roosfa104232014-06-20 16:10:14 -07004122 + " dcf=" + dcf.toShortString()
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004123 + " sf=" + sf.toShortString()
4124 + " osf=" + (osf == null ? "null" : osf.toShortString()));
Craig Mautner69b08182012-09-05 13:07:13 -07004125
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004126 win.computeFrameLw(pf, df, of, cf, vf, dcf, sf, osf);
Craig Mautner69b08182012-09-05 13:07:13 -07004127
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004128 // Dock windows carve out the bottom of the screen, so normal windows
4129 // can't appear underneath them.
Craig Mautner8bd206b2012-10-03 10:32:02 -07004130 if (attrs.type == TYPE_INPUT_METHOD && win.isVisibleOrBehindKeyguardLw()
4131 && !win.getGivenInsetsPendingLw()) {
satok1bc0a492012-04-25 22:47:12 +09004132 setLastInputMethodWindowLw(null, null);
4133 offsetInputMethodWindowLw(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004134 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004135 if (attrs.type == TYPE_VOICE_INTERACTION && win.isVisibleOrBehindKeyguardLw()
4136 && !win.getGivenInsetsPendingLw()) {
4137 offsetVoiceInputWindowLw(win);
4138 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004139 }
4140
satok1bc0a492012-04-25 22:47:12 +09004141 private void offsetInputMethodWindowLw(WindowState win) {
Craig Mautner4774f6a2015-03-23 11:42:55 -07004142 int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top);
satok1bc0a492012-04-25 22:47:12 +09004143 top += win.getGivenContentInsetsLw().top;
4144 if (mContentBottom > top) {
4145 mContentBottom = top;
4146 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004147 if (mVoiceContentBottom > top) {
4148 mVoiceContentBottom = top;
4149 }
satok1bc0a492012-04-25 22:47:12 +09004150 top = win.getVisibleFrameLw().top;
4151 top += win.getGivenVisibleInsetsLw().top;
4152 if (mCurBottom > top) {
4153 mCurBottom = top;
4154 }
Craig Mautnereda67292013-04-28 13:50:14 -07004155 if (DEBUG_LAYOUT) Slog.v(TAG, "Input method: mDockBottom="
satok1bc0a492012-04-25 22:47:12 +09004156 + mDockBottom + " mContentBottom="
4157 + mContentBottom + " mCurBottom=" + mCurBottom);
4158 }
4159
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004160 private void offsetVoiceInputWindowLw(WindowState win) {
Craig Mautner4774f6a2015-03-23 11:42:55 -07004161 int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08004162 top += win.getGivenContentInsetsLw().top;
4163 if (mVoiceContentBottom > top) {
4164 mVoiceContentBottom = top;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004165 }
4166 }
4167
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004168 /** {@inheritDoc} */
Craig Mautner61ac6bb2012-02-02 17:29:33 -08004169 @Override
4170 public void finishLayoutLw() {
4171 return;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004172 }
4173
4174 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004175 @Override
Craig Mautner39834192012-09-02 07:47:24 -07004176 public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) {
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004177 mTopFullscreenOpaqueWindowState = null;
Adrian Rooscd3884d2015-02-18 17:25:23 +01004178 mTopFullscreenOpaqueOrDimmingWindowState = null;
Craig Mautner2bc789b2014-03-19 19:48:38 -07004179 mAppsToBeHidden.clear();
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004180 mAppsThatDismissKeyguard.clear();
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004181 mForceStatusBar = false;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004182 mForceStatusBarFromKeyguard = false;
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004183 mForceStatusBarTransparent = false;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08004184 mForcingShowNavBar = false;
4185 mForcingShowNavBarLayer = -1;
RoboErik8a2cfc32014-05-16 11:19:38 -07004186
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004187 mHideLockScreen = false;
4188 mAllowLockscreenWhenOn = false;
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004189 mDismissKeyguard = DISMISS_KEYGUARD_NONE;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004190 mShowingLockscreen = false;
4191 mShowingDream = false;
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004192 mWinShowWhenLocked = null;
Jim Millerab954542014-10-10 18:21:49 -07004193 mKeyguardSecure = isKeyguardSecure();
4194 mKeyguardSecureIncludingHidden = mKeyguardSecure
4195 && (mKeyguardDelegate != null && mKeyguardDelegate.isShowing());
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004196 }
4197
4198 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004199 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004200 public void applyPostLayoutPolicyLw(WindowState win, WindowManager.LayoutParams attrs) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004201 if (DEBUG_LAYOUT) Slog.i(TAG, "Win " + win + ": isVisibleOrBehindKeyguardLw="
4202 + win.isVisibleOrBehindKeyguardLw());
John Spurlockc6d1c602014-01-17 15:22:06 -05004203 final int fl = PolicyControl.getWindowFlags(win, attrs);
John Spurlock414c1f02013-12-04 13:47:36 -05004204 if (mTopFullscreenOpaqueWindowState == null
4205 && win.isVisibleLw() && attrs.type == TYPE_INPUT_METHOD) {
4206 mForcingShowNavBar = true;
4207 mForcingShowNavBarLayer = win.getSurfaceLayer();
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08004208 }
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004209 if (attrs.type == TYPE_STATUS_BAR) {
4210 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
4211 mForceStatusBarFromKeyguard = true;
4212 }
4213 if ((attrs.privateFlags & PRIVATE_FLAG_FORCE_STATUS_BAR_VISIBLE_TRANSPARENT) != 0) {
4214 mForceStatusBarTransparent = true;
4215 }
Jorim Jaggiafd4a552014-04-08 15:13:05 +02004216 }
Adrian Roos602c68e2015-04-24 16:03:47 -07004217
4218 boolean appWindow = attrs.type >= FIRST_APPLICATION_WINDOW
4219 && attrs.type < FIRST_SYSTEM_WINDOW;
4220 final boolean showWhenLocked = (fl & FLAG_SHOW_WHEN_LOCKED) != 0;
4221 final boolean dismissKeyguard = (fl & FLAG_DISMISS_KEYGUARD) != 0;
4222
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004223 if (mTopFullscreenOpaqueWindowState == null &&
Dianne Hackborn01b02a72012-01-12 14:05:03 -08004224 win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()) {
John Spurlockc6d1c602014-01-17 15:22:06 -05004225 if ((fl & FLAG_FORCE_NOT_FULLSCREEN) != 0) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004226 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004227 mForceStatusBarFromKeyguard = true;
4228 } else {
4229 mForceStatusBar = true;
4230 }
4231 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004232 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004233 mShowingLockscreen = true;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004234 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004235 if (attrs.type == TYPE_DREAM) {
Jeff Brownc8018eb2012-10-29 21:33:27 -07004236 // If the lockscreen was showing when the dream started then wait
4237 // for the dream to draw before hiding the lockscreen.
4238 if (!mDreamingLockscreen
4239 || (win.isVisibleLw() && win.hasDrawnLw())) {
4240 mShowingDream = true;
Craig Mautnerab55e522014-03-03 13:26:03 -08004241 appWindow = true;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004242 }
4243 }
Craig Mautnerab55e522014-03-03 13:26:03 -08004244
Craig Mautnerab55e522014-03-03 13:26:03 -08004245 if (appWindow) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004246 final IApplicationToken appToken = win.getAppToken();
4247 if (showWhenLocked) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004248 // Remove any previous windows with the same appToken.
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004249 mAppsToBeHidden.remove(appToken);
4250 mAppsThatDismissKeyguard.remove(appToken);
Craig Mautnerca0a1242014-12-02 12:25:14 -08004251 if (mAppsToBeHidden.isEmpty()) {
Craig Mautner192d6042014-12-02 23:24:48 -08004252 if (dismissKeyguard && !mKeyguardSecure) {
4253 mAppsThatDismissKeyguard.add(appToken);
4254 } else {
Craig Mautnerca0a1242014-12-02 12:25:14 -08004255 mWinShowWhenLocked = win;
4256 mHideLockScreen = true;
4257 mForceStatusBarFromKeyguard = false;
Craig Mautnerca0a1242014-12-02 12:25:14 -08004258 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004259 }
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004260 } else if (dismissKeyguard) {
Jim Millerab954542014-10-10 18:21:49 -07004261 if (mKeyguardSecure) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004262 mAppsToBeHidden.add(appToken);
4263 } else {
4264 mAppsToBeHidden.remove(appToken);
4265 }
4266 mAppsThatDismissKeyguard.add(appToken);
Craig Mautner2bc789b2014-03-19 19:48:38 -07004267 } else {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004268 mAppsToBeHidden.add(appToken);
Craig Mautner2bc789b2014-03-19 19:48:38 -07004269 }
Craig Mautnerab55e522014-03-03 13:26:03 -08004270 if (attrs.x == 0 && attrs.y == 0
4271 && attrs.width == WindowManager.LayoutParams.MATCH_PARENT
4272 && attrs.height == WindowManager.LayoutParams.MATCH_PARENT) {
4273 if (DEBUG_LAYOUT) Slog.v(TAG, "Fullscreen window: " + win);
4274 mTopFullscreenOpaqueWindowState = win;
Adrian Rooscd3884d2015-02-18 17:25:23 +01004275 if (mTopFullscreenOpaqueOrDimmingWindowState == null) {
4276 mTopFullscreenOpaqueOrDimmingWindowState = win;
4277 }
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004278 if (!mAppsThatDismissKeyguard.isEmpty() &&
4279 mDismissKeyguard == DISMISS_KEYGUARD_NONE) {
4280 if (DEBUG_LAYOUT) Slog.v(TAG,
4281 "Setting mDismissKeyguard true by win " + win);
tingna_sunge785ffa2015-05-12 13:23:15 +08004282 mDismissKeyguard = (mWinDismissingKeyguard == win
4283 && mSecureDismissingKeyguard == mKeyguardSecure)
4284 ? DISMISS_KEYGUARD_CONTINUE : DISMISS_KEYGUARD_START;
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004285 mWinDismissingKeyguard = win;
tingna_sunge785ffa2015-05-12 13:23:15 +08004286 mSecureDismissingKeyguard = mKeyguardSecure;
Jim Millerab954542014-10-10 18:21:49 -07004287 mForceStatusBarFromKeyguard = mShowingLockscreen && mKeyguardSecure;
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004288 } else if (mAppsToBeHidden.isEmpty() && showWhenLocked) {
4289 if (DEBUG_LAYOUT) Slog.v(TAG,
4290 "Setting mHideLockScreen to true by win " + win);
4291 mHideLockScreen = true;
4292 mForceStatusBarFromKeyguard = false;
Craig Mautnerab55e522014-03-03 13:26:03 -08004293 }
Craig Mautner00156ec2014-03-06 22:29:02 -08004294 if ((fl & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) {
Craig Mautnerab55e522014-03-03 13:26:03 -08004295 mAllowLockscreenWhenOn = true;
4296 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004297 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004298
4299 if (mWinShowWhenLocked != null &&
Adrian Roos602c68e2015-04-24 16:03:47 -07004300 mWinShowWhenLocked.getAppToken() != win.getAppToken() &&
4301 (attrs.flags & FLAG_SHOW_WHEN_LOCKED) == 0) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004302 win.hideLw(false);
4303 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004304 }
Adrian Roos602c68e2015-04-24 16:03:47 -07004305 } else if (mTopFullscreenOpaqueWindowState == null && mWinShowWhenLocked == null) {
4306 // No TopFullscreenOpaqueWindow is showing, but we found a SHOW_WHEN_LOCKED window
4307 // that is being hidden in an animation - keep the
4308 // keyguard hidden until the new window shows up and
4309 // we know whether to show the keyguard or not.
Adrian Roosb85e1ec2015-05-29 15:23:18 -07004310 if (win.isAnimatingLw() && appWindow && showWhenLocked && mKeyguardHidden) {
Adrian Roos602c68e2015-04-24 16:03:47 -07004311 mHideLockScreen = true;
4312 mWinShowWhenLocked = win;
4313 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004314 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01004315 if (mTopFullscreenOpaqueOrDimmingWindowState == null
4316 && win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()
4317 && win.isDimming()) {
4318 mTopFullscreenOpaqueOrDimmingWindowState = win;
4319 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004320 }
4321
4322 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004323 @Override
Craig Mautner39834192012-09-02 07:47:24 -07004324 public int finishPostLayoutPolicyLw() {
Craig Mautnerc5e73bf2015-04-21 15:41:26 +00004325 if (mWinShowWhenLocked != null && mTopFullscreenOpaqueWindowState != null &&
4326 mWinShowWhenLocked.getAppToken() != mTopFullscreenOpaqueWindowState.getAppToken()
4327 && isKeyguardLocked()) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004328 // A dialog is dismissing the keyguard. Put the wallpaper behind it and hide the
4329 // fullscreen window.
4330 // TODO: Make sure FLAG_SHOW_WALLPAPER is restored when dialog is dismissed. Or not.
4331 mWinShowWhenLocked.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
4332 mTopFullscreenOpaqueWindowState.hideLw(false);
4333 mTopFullscreenOpaqueWindowState = mWinShowWhenLocked;
4334 }
4335
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004336 int changes = 0;
Joe Onorato93056472010-09-10 10:30:46 -04004337 boolean topIsFullscreen = false;
Daniel Sandlere02d8082010-10-08 15:13:22 -04004338
4339 final WindowManager.LayoutParams lp = (mTopFullscreenOpaqueWindowState != null)
4340 ? mTopFullscreenOpaqueWindowState.getAttrs()
4341 : null;
4342
Jeff Brownc8018eb2012-10-29 21:33:27 -07004343 // If we are not currently showing a dream then remember the current
4344 // lockscreen state. We will use this to determine whether the dream
4345 // started while the lockscreen was showing and remember this state
4346 // while the dream is showing.
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004347 if (!mShowingDream) {
4348 mDreamingLockscreen = mShowingLockscreen;
Jeff Brown061ea992015-04-17 19:55:47 -07004349 if (mDreamingSleepTokenNeeded) {
4350 mDreamingSleepTokenNeeded = false;
4351 mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 0, 1).sendToTarget();
4352 }
4353 } else {
4354 if (!mDreamingSleepTokenNeeded) {
4355 mDreamingSleepTokenNeeded = true;
4356 mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 1, 1).sendToTarget();
4357 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004358 }
4359
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004360 if (mStatusBar != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07004361 if (DEBUG_LAYOUT) Slog.i(TAG, "force=" + mForceStatusBar
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004362 + " forcefkg=" + mForceStatusBarFromKeyguard
Dianne Hackbornd70bc2f2009-10-06 23:25:51 -07004363 + " top=" + mTopFullscreenOpaqueWindowState);
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004364 boolean shouldBeTransparent = mForceStatusBarTransparent
4365 && !mForceStatusBar
4366 && !mForceStatusBarFromKeyguard;
4367 if (!shouldBeTransparent) {
4368 mStatusBarController.setShowTransparent(false /* transparent */);
4369 } else if (!mStatusBar.isVisibleLw()) {
4370 mStatusBarController.setShowTransparent(true /* transparent */);
4371 }
4372 if (mForceStatusBar || mForceStatusBarFromKeyguard || mForceStatusBarTransparent) {
Craig Mautnereda67292013-04-28 13:50:14 -07004373 if (DEBUG_LAYOUT) Slog.v(TAG, "Showing status bar: forced");
John Spurlock27735a42013-08-14 17:57:38 -04004374 if (mStatusBarController.setBarShowingLw(true)) {
4375 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4376 }
Craig Mautner81defc72013-10-29 11:10:42 -07004377 // Maintain fullscreen layout until incoming animation is complete.
4378 topIsFullscreen = mTopIsFullscreen && mStatusBar.isAnimatingLw();
John Spurlockf92b6162013-11-11 15:01:16 -05004379 // Transient status bar on the lockscreen is not allowed
4380 if (mForceStatusBarFromKeyguard && mStatusBarController.isTransientShowing()) {
4381 mStatusBarController.updateVisibilityLw(false /*transientAllowed*/,
4382 mLastSystemUiFlags, mLastSystemUiFlags);
4383 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004384 } else if (mTopFullscreenOpaqueWindowState != null) {
John Spurlockc6d1c602014-01-17 15:22:06 -05004385 final int fl = PolicyControl.getWindowFlags(null, lp);
Joe Onorato93056472010-09-10 10:30:46 -04004386 if (localLOGV) {
Craig Mautnereda67292013-04-28 13:50:14 -07004387 Slog.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw()
Joe Onorato93056472010-09-10 10:30:46 -04004388 + " shown frame: " + mTopFullscreenOpaqueWindowState.getShownFrameLw());
Craig Mautnereda67292013-04-28 13:50:14 -07004389 Slog.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs()
John Spurlockc6d1c602014-01-17 15:22:06 -05004390 + " lp.flags=0x" + Integer.toHexString(fl));
Joe Onorato93056472010-09-10 10:30:46 -04004391 }
John Spurlockc6d1c602014-01-17 15:22:06 -05004392 topIsFullscreen = (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004393 || (mLastSystemUiFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
Joe Onorato93056472010-09-10 10:30:46 -04004394 // The subtle difference between the window for mTopFullscreenOpaqueWindowState
Mark Dolinerd0646dc2014-08-27 16:04:02 -07004395 // and mTopIsFullscreen is that mTopIsFullscreen is set only if the window
Joe Onorato93056472010-09-10 10:30:46 -04004396 // has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the
4397 // case though.
John Spurlock27735a42013-08-14 17:57:38 -04004398 if (mStatusBarController.isTransientShowing()) {
4399 if (mStatusBarController.setBarShowingLw(true)) {
John Spurlock32beb2c2013-03-11 10:16:47 -04004400 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4401 }
4402 } else if (topIsFullscreen) {
Craig Mautnereda67292013-04-28 13:50:14 -07004403 if (DEBUG_LAYOUT) Slog.v(TAG, "** HIDING status bar");
John Spurlock27735a42013-08-14 17:57:38 -04004404 if (mStatusBarController.setBarShowingLw(false)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004405 changes |= FINISH_LAYOUT_REDO_LAYOUT;
Craig Mautnereda67292013-04-28 13:50:14 -07004406 } else {
Craig Mautnerc5a6e442013-06-05 17:22:35 -07004407 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar already hiding");
Daniel Sandler40427442010-07-16 11:44:52 -04004408 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004409 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07004410 if (DEBUG_LAYOUT) Slog.v(TAG, "** SHOWING status bar: top is not fullscreen");
John Spurlock27735a42013-08-14 17:57:38 -04004411 if (mStatusBarController.setBarShowingLw(true)) {
4412 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4413 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004414 }
4415 }
4416 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04004417
Craig Mautner81defc72013-10-29 11:10:42 -07004418 if (mTopIsFullscreen != topIsFullscreen) {
4419 if (!topIsFullscreen) {
4420 // Force another layout when status bar becomes fully shown.
4421 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4422 }
4423 mTopIsFullscreen = topIsFullscreen;
4424 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04004425
Craig Mautner39834192012-09-02 07:47:24 -07004426 // Hide the key guard if a visible window explicitly specifies that it wants to be
4427 // displayed when the screen is locked.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004428 if (mKeyguardDelegate != null && mStatusBar != null) {
4429 if (localLOGV) Slog.v(TAG, "finishPostLayoutPolicyLw: mHideKeyguard="
4430 + mHideLockScreen);
Jim Millerab954542014-10-10 18:21:49 -07004431 if (mDismissKeyguard != DISMISS_KEYGUARD_NONE && !mKeyguardSecure) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004432 mKeyguardHidden = true;
Jim Millerab954542014-10-10 18:21:49 -07004433 if (setKeyguardOccludedLw(true)) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004434 changes |= FINISH_LAYOUT_REDO_LAYOUT
4435 | FINISH_LAYOUT_REDO_CONFIG
4436 | FINISH_LAYOUT_REDO_WALLPAPER;
4437 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004438 if (mKeyguardDelegate.isShowing()) {
4439 mHandler.post(new Runnable() {
4440 @Override
4441 public void run() {
4442 mKeyguardDelegate.keyguardDone(false, false);
4443 }
4444 });
4445 }
4446 } else if (mHideLockScreen) {
4447 mKeyguardHidden = true;
Jorim Jaggi7d85ea92015-05-20 17:20:40 -07004448 mWinDismissingKeyguard = null;
Jim Millerab954542014-10-10 18:21:49 -07004449 if (setKeyguardOccludedLw(true)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004450 changes |= FINISH_LAYOUT_REDO_LAYOUT
4451 | FINISH_LAYOUT_REDO_CONFIG
4452 | FINISH_LAYOUT_REDO_WALLPAPER;
4453 }
4454 } else if (mDismissKeyguard != DISMISS_KEYGUARD_NONE) {
Jorim Jaggi7d85ea92015-05-20 17:20:40 -07004455 mKeyguardHidden = false;
4456 if (setKeyguardOccludedLw(false)) {
4457 changes |= FINISH_LAYOUT_REDO_LAYOUT
4458 | FINISH_LAYOUT_REDO_CONFIG
4459 | FINISH_LAYOUT_REDO_WALLPAPER;
4460 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004461 if (mDismissKeyguard == DISMISS_KEYGUARD_START) {
4462 // Only launch the next keyguard unlock window once per window.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004463 mHandler.post(new Runnable() {
4464 @Override
4465 public void run() {
4466 mKeyguardDelegate.dismiss();
4467 }
4468 });
4469 }
4470 } else {
4471 mWinDismissingKeyguard = null;
tingna_sunge785ffa2015-05-12 13:23:15 +08004472 mSecureDismissingKeyguard = false;
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004473 mKeyguardHidden = false;
Jim Millerab954542014-10-10 18:21:49 -07004474 if (setKeyguardOccludedLw(false)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004475 changes |= FINISH_LAYOUT_REDO_LAYOUT
4476 | FINISH_LAYOUT_REDO_CONFIG
4477 | FINISH_LAYOUT_REDO_WALLPAPER;
4478 }
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -07004479 }
4480 }
Joe Onorato664644d2011-01-23 17:53:23 -08004481
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004482 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004483 // If the navigation bar has been hidden or shown, we need to do another
4484 // layout pass to update that window.
4485 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4486 }
Joe Onorato664644d2011-01-23 17:53:23 -08004487
Mike Lockwood28569302010-01-28 11:54:40 -05004488 // update since mAllowLockscreenWhenOn might have changed
4489 updateLockScreenTimeout();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004490 return changes;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004491 }
4492
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004493 /**
Jim Millerab954542014-10-10 18:21:49 -07004494 * Updates the occluded state of the Keyguard.
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004495 *
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004496 * @return Whether the flags have changed and we have to redo the layout.
4497 */
Jim Millerab954542014-10-10 18:21:49 -07004498 private boolean setKeyguardOccludedLw(boolean isOccluded) {
4499 boolean wasOccluded = mKeyguardOccluded;
4500 boolean showing = mKeyguardDelegate.isShowing();
4501 if (wasOccluded && !isOccluded && showing) {
4502 mKeyguardOccluded = false;
4503 mKeyguardDelegate.setOccluded(false);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004504 mStatusBar.getAttrs().privateFlags |= PRIVATE_FLAG_KEYGUARD;
4505 mStatusBar.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
4506 return true;
Jim Millerab954542014-10-10 18:21:49 -07004507 } else if (!wasOccluded && isOccluded && showing) {
4508 mKeyguardOccluded = true;
4509 mKeyguardDelegate.setOccluded(true);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004510 mStatusBar.getAttrs().privateFlags &= ~PRIVATE_FLAG_KEYGUARD;
4511 mStatusBar.getAttrs().flags &= ~FLAG_SHOW_WALLPAPER;
4512 return true;
4513 } else {
4514 return false;
4515 }
4516 }
4517
4518 private boolean isStatusBarKeyguard() {
4519 return mStatusBar != null
4520 && (mStatusBar.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
4521 }
4522
Jose Lima9546b202014-07-02 17:21:51 -07004523 @Override
Dianne Hackborn08743722009-12-21 12:16:51 -08004524 public boolean allowAppAnimationsLw() {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004525 if (isStatusBarKeyguard() || mShowingDream) {
Craig Mautner28816302013-10-10 20:31:00 -07004526 // If keyguard or dreams is currently visible, no reason to animate behind it.
Dianne Hackborn08743722009-12-21 12:16:51 -08004527 return false;
4528 }
Dianne Hackborn08743722009-12-21 12:16:51 -08004529 return true;
4530 }
4531
Jose Lima9546b202014-07-02 17:21:51 -07004532 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07004533 public int focusChangedLw(WindowState lastFocus, WindowState newFocus) {
Joe Onorato664644d2011-01-23 17:53:23 -08004534 mFocusedWindow = newFocus;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004535 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004536 // If the navigation bar has been hidden or shown, we need to do another
4537 // layout pass to update that window.
4538 return FINISH_LAYOUT_REDO_LAYOUT;
4539 }
4540 return 0;
Joe Onorato664644d2011-01-23 17:53:23 -08004541 }
4542
Dianne Hackborn0ecadf72009-03-31 18:00:37 -07004543 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07004544 @Override
Jeff Brown46b9ac02010-04-22 18:58:52 -07004545 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
4546 // lid changed state
Jeff Brownc458ce92012-04-30 14:58:40 -07004547 final int newLidState = lidOpen ? LID_OPEN : LID_CLOSED;
4548 if (newLidState == mLidState) {
4549 return;
4550 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004551
Jeff Brownc458ce92012-04-30 14:58:40 -07004552 mLidState = newLidState;
4553 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07004554 updateRotation(true);
Jeff Brownc458ce92012-04-30 14:58:40 -07004555
4556 if (lidOpen) {
Bryce Lee584a4452014-10-21 15:55:55 -07004557 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromLidSwitch);
Jeff Brownc458ce92012-04-30 14:58:40 -07004558 } else if (!mLidControlsSleep) {
Jeff Brown96307042012-07-27 15:51:34 -07004559 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
Jeff Brown46b9ac02010-04-22 18:58:52 -07004560 }
4561 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004562
Michael Wright3818c922014-09-02 13:59:07 -07004563 @Override
4564 public void notifyCameraLensCoverSwitchChanged(long whenNanos, boolean lensCovered) {
4565 int lensCoverState = lensCovered ? CAMERA_LENS_COVERED : CAMERA_LENS_UNCOVERED;
4566 if (mCameraLensCoverState == lensCoverState) {
4567 return;
4568 }
4569 if (mCameraLensCoverState == CAMERA_LENS_COVERED &&
4570 lensCoverState == CAMERA_LENS_UNCOVERED) {
4571 Intent intent;
4572 final boolean keyguardActive = mKeyguardDelegate == null ? false :
4573 mKeyguardDelegate.isShowing();
4574 if (keyguardActive) {
4575 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE);
4576 } else {
4577 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
4578 }
Bryce Lee584a4452014-10-21 15:55:55 -07004579 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromCameraLens);
Bart Sears8b1c27c2015-03-18 23:51:02 +00004580 startActivityAsUser(intent, UserHandle.CURRENT_OR_SELF);
Michael Wright3818c922014-09-02 13:59:07 -07004581 }
4582 mCameraLensCoverState = lensCoverState;
4583 }
4584
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004585 void setHdmiPlugged(boolean plugged) {
4586 if (mHdmiPlugged != plugged) {
4587 mHdmiPlugged = plugged;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004588 updateRotation(true, true);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004589 Intent intent = new Intent(ACTION_HDMI_PLUGGED);
Joe Onoratodc100302011-01-11 17:07:41 -08004590 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004591 intent.putExtra(EXTRA_HDMI_PLUGGED_STATE, plugged);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07004592 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004593 }
4594 }
4595
Joe Onoratoea495d42011-04-06 11:41:11 -07004596 void initializeHdmiState() {
Joe Onorato7ba631f2011-05-04 15:28:00 -07004597 boolean plugged = false;
Joe Onoratoea495d42011-04-06 11:41:11 -07004598 // watch for HDMI plug messages if the hdmi switch exists
4599 if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) {
4600 mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi");
4601
Joe Onoratoea495d42011-04-06 11:41:11 -07004602 final String filename = "/sys/class/switch/hdmi/state";
4603 FileReader reader = null;
4604 try {
4605 reader = new FileReader(filename);
4606 char[] buf = new char[15];
4607 int n = reader.read(buf);
4608 if (n > 1) {
4609 plugged = 0 != Integer.parseInt(new String(buf, 0, n-1));
4610 }
4611 } catch (IOException ex) {
4612 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
4613 } catch (NumberFormatException ex) {
4614 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
4615 } finally {
4616 if (reader != null) {
4617 try {
4618 reader.close();
4619 } catch (IOException ex) {
4620 }
Joe Onoratodc100302011-01-11 17:07:41 -08004621 }
4622 }
4623 }
Joe Onorato7ba631f2011-05-04 15:28:00 -07004624 // This dance forces the code in setHdmiPlugged to run.
4625 // Always do this so the sticky intent is stuck (to false) if there is no hdmi.
4626 mHdmiPlugged = !plugged;
4627 setHdmiPlugged(!mHdmiPlugged);
Joe Onoratodc100302011-01-11 17:07:41 -08004628 }
4629
Dianne Hackbornc0e3f242011-08-19 14:19:10 -07004630 final Object mScreenshotLock = new Object();
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004631 ServiceConnection mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004632
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004633 final Runnable mScreenshotTimeout = new Runnable() {
4634 @Override public void run() {
4635 synchronized (mScreenshotLock) {
4636 if (mScreenshotConnection != null) {
4637 mContext.unbindService(mScreenshotConnection);
4638 mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004639 }
Winson Chung9112ec32011-06-27 13:15:32 -07004640 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004641 }
4642 };
4643
4644 // Assume this is called from the Handler thread.
4645 private void takeScreenshot() {
4646 synchronized (mScreenshotLock) {
4647 if (mScreenshotConnection != null) {
4648 return;
4649 }
4650 ComponentName cn = new ComponentName("com.android.systemui",
4651 "com.android.systemui.screenshot.TakeScreenshotService");
4652 Intent intent = new Intent();
4653 intent.setComponent(cn);
4654 ServiceConnection conn = new ServiceConnection() {
4655 @Override
4656 public void onServiceConnected(ComponentName name, IBinder service) {
4657 synchronized (mScreenshotLock) {
4658 if (mScreenshotConnection != this) {
4659 return;
4660 }
4661 Messenger messenger = new Messenger(service);
4662 Message msg = Message.obtain(null, 1);
4663 final ServiceConnection myConn = this;
4664 Handler h = new Handler(mHandler.getLooper()) {
4665 @Override
4666 public void handleMessage(Message msg) {
4667 synchronized (mScreenshotLock) {
4668 if (mScreenshotConnection == myConn) {
4669 mContext.unbindService(mScreenshotConnection);
4670 mScreenshotConnection = null;
4671 mHandler.removeCallbacks(mScreenshotTimeout);
4672 }
4673 }
4674 }
4675 };
4676 msg.replyTo = new Messenger(h);
Winson Chunga63bb842011-10-17 10:26:28 -07004677 msg.arg1 = msg.arg2 = 0;
4678 if (mStatusBar != null && mStatusBar.isVisibleLw())
4679 msg.arg1 = 1;
4680 if (mNavigationBar != null && mNavigationBar.isVisibleLw())
4681 msg.arg2 = 1;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004682 try {
4683 messenger.send(msg);
4684 } catch (RemoteException e) {
4685 }
4686 }
4687 }
4688 @Override
4689 public void onServiceDisconnected(ComponentName name) {}
4690 };
Amith Yamasani27b89e62013-01-16 12:30:11 -08004691 if (mContext.bindServiceAsUser(
4692 intent, conn, Context.BIND_AUTO_CREATE, UserHandle.CURRENT)) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004693 mScreenshotConnection = conn;
4694 mHandler.postDelayed(mScreenshotTimeout, 10000);
4695 }
4696 }
Winson Chung9112ec32011-06-27 13:15:32 -07004697 }
4698
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004699 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004700 @Override
Jeff Brown037c33e2014-04-09 00:31:55 -07004701 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) {
Jeff Brown96307042012-07-27 15:51:34 -07004702 if (!mSystemBooted) {
4703 // If we have not yet booted, don't let key events do anything.
4704 return 0;
4705 }
4706
Jeff Brown037c33e2014-04-09 00:31:55 -07004707 final boolean interactive = (policyFlags & FLAG_INTERACTIVE) != 0;
Jeff Brown1f245102010-11-18 20:53:46 -08004708 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
4709 final boolean canceled = event.isCanceled();
4710 final int keyCode = event.getKeyCode();
Jeff Browne20c9e02010-10-11 14:20:19 -07004711
Jeff Brown3122e442010-10-11 23:32:49 -07004712 final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0;
Jeff Brown3122e442010-10-11 23:32:49 -07004713
Mike Lockwoodc72b15f2009-11-28 20:58:22 -05004714 // If screen is off then we treat the case where the keyguard is open but hidden
4715 // the same as if it were open and in front.
4716 // This will prevent any keys other than the power button from waking the screen
4717 // when the keyguard is hidden by another activity.
Jim Miller5ecd8112013-01-09 18:50:26 -08004718 final boolean keyguardActive = (mKeyguardDelegate == null ? false :
Jeff Brown037c33e2014-04-09 00:31:55 -07004719 (interactive ?
Jim Millerab954542014-10-10 18:21:49 -07004720 isKeyguardShowingAndNotOccluded() :
Jim Miller5ecd8112013-01-09 18:50:26 -08004721 mKeyguardDelegate.isShowing()));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004722
Jeff Brown40013652012-05-16 21:22:36 -07004723 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004724 Log.d(TAG, "interceptKeyTq keycode=" + keyCode
Jeff Brown037c33e2014-04-09 00:31:55 -07004725 + " interactive=" + interactive + " keyguardActive=" + keyguardActive
Jeff Brown26875502014-01-30 21:47:47 -08004726 + " policyFlags=" + Integer.toHexString(policyFlags));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004727 }
4728
Jeff Brown037c33e2014-04-09 00:31:55 -07004729 // Basic policy based on interactive state.
Jeff Brown4d396052010-10-29 21:50:21 -07004730 int result;
Michael Wright337d9d22014-04-22 15:03:48 -07004731 boolean isWakeKey = (policyFlags & WindowManagerPolicy.FLAG_WAKE) != 0
4732 || event.isWakeKey();
Michael Wrightfc01f042014-09-08 14:12:24 -07004733 if (interactive || (isInjected && !isWakeKey)) {
RoboErikde9ba392014-09-26 12:51:01 -07004734 // When the device is interactive or the key is injected pass the
4735 // key to the application.
Jeff Brown4d396052010-10-29 21:50:21 -07004736 result = ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07004737 isWakeKey = false;
Michael Wrightfc01f042014-09-08 14:12:24 -07004738 } else if (!interactive && shouldDispatchInputWhenNonInteractive()) {
4739 // If we're currently dozing with the screen on and the keyguard showing, pass the key
4740 // to the application but preserve its wake key status to make sure we still move
4741 // from dozing to fully interactive if we would normally go from off to fully
4742 // interactive.
4743 result = ACTION_PASS_TO_USER;
Jeff Brown4d396052010-10-29 21:50:21 -07004744 } else {
4745 // When the screen is off and the key is not injected, determine whether
4746 // to wake the device but don't pass the key to the application.
4747 result = 0;
Jeff Brown26875502014-01-30 21:47:47 -08004748 if (isWakeKey && (!down || !isWakeKeyWhenScreenOff(keyCode))) {
4749 isWakeKey = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004750 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004751 }
4752
Justin Kohd378ad72013-04-01 12:18:26 -07004753 // If the key would be handled globally, just return the result, don't worry about special
4754 // key processing.
Jeff Brown13f00f02014-10-31 14:45:50 -07004755 if (isValidGlobalKey(keyCode)
4756 && mGlobalKeyManager.shouldHandleGlobalKey(keyCode, event)) {
Michael Wright85b1af62014-06-04 14:51:58 -07004757 if (isWakeKey) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004758 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey);
Michael Wright85b1af62014-06-04 14:51:58 -07004759 }
Justin Kohd378ad72013-04-01 12:18:26 -07004760 return result;
4761 }
4762
Jeff Brownbae8e772014-06-12 19:59:45 -07004763 boolean useHapticFeedback = down
4764 && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0
4765 && event.getRepeatCount() == 0;
4766
Jeff Brown4d396052010-10-29 21:50:21 -07004767 // Handle special keys.
4768 switch (keyCode) {
4769 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jeff Brownb0418da2010-11-01 15:24:01 -07004770 case KeyEvent.KEYCODE_VOLUME_UP:
4771 case KeyEvent.KEYCODE_VOLUME_MUTE: {
RoboErik001c59c2015-01-26 15:53:51 -08004772 if (mUseTvRouting) {
4773 // On TVs volume keys never go to the foreground app
4774 result &= ~ACTION_PASS_TO_USER;
4775 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004776 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
4777 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004778 if (interactive && !mScreenshotChordVolumeDownKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004779 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004780 mScreenshotChordVolumeDownKeyTriggered = true;
4781 mScreenshotChordVolumeDownKeyTime = event.getDownTime();
4782 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004783 cancelPendingPowerKeyAction();
4784 interceptScreenshotChord();
4785 }
4786 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004787 mScreenshotChordVolumeDownKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004788 cancelPendingScreenshotChordAction();
4789 }
4790 } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
4791 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004792 if (interactive && !mScreenshotChordVolumeUpKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004793 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004794 mScreenshotChordVolumeUpKeyTriggered = true;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004795 cancelPendingPowerKeyAction();
4796 cancelPendingScreenshotChordAction();
4797 }
4798 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004799 mScreenshotChordVolumeUpKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004800 cancelPendingScreenshotChordAction();
4801 }
4802 }
Jeff Brown4d396052010-10-29 21:50:21 -07004803 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004804 TelecomManager telecomManager = getTelecommService();
4805 if (telecomManager != null) {
4806 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07004807 // If an incoming call is ringing, either VOLUME key means
4808 // "silence ringer". We handle these keys here, rather than
4809 // in the InCallScreen, to make sure we'll respond to them
4810 // even if the InCallScreen hasn't come to the foreground yet.
4811 // Look for the DOWN event here, to agree with the "fallback"
4812 // behavior in the InCallScreen.
4813 Log.i(TAG, "interceptKeyBeforeQueueing:"
4814 + " VOLUME key-down while ringing: Silence ringer!");
Jeff Brown4d396052010-10-29 21:50:21 -07004815
Santos Cordon6848f722014-05-21 15:22:12 -07004816 // Silence the ringer. (It's safe to call this
4817 // even if the ringer has already been silenced.)
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004818 telecomManager.silenceRinger();
Jeff Brown4d396052010-10-29 21:50:21 -07004819
Santos Cordon6848f722014-05-21 15:22:12 -07004820 // And *don't* pass this key thru to the current activity
4821 // (which is probably the InCallScreen.)
4822 result &= ~ACTION_PASS_TO_USER;
4823 break;
4824 }
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004825 if (telecomManager.isInCall()
Santos Cordon6848f722014-05-21 15:22:12 -07004826 && (result & ACTION_PASS_TO_USER) == 0) {
4827 // If we are in call but we decided not to pass the key to
RoboErik430fc482014-06-12 15:49:20 -07004828 // the application, just pass it to the session service.
4829
4830 MediaSessionLegacyHelper.getHelper(mContext)
RoboErik3c45c292014-07-08 16:47:31 -07004831 .sendVolumeKeyEvent(event, false);
Santos Cordon6848f722014-05-21 15:22:12 -07004832 break;
Jeff Brown4d396052010-10-29 21:50:21 -07004833 }
4834 }
4835
RoboErik430fc482014-06-12 15:49:20 -07004836 if ((result & ACTION_PASS_TO_USER) == 0) {
RoboErik001c59c2015-01-26 15:53:51 -08004837 if (mUseTvRouting) {
4838 dispatchDirectAudioEvent(event);
4839 } else {
4840 // If we aren't passing to the user and no one else
4841 // handled it send it to the session manager to
4842 // figure out.
4843 MediaSessionLegacyHelper.getHelper(mContext)
4844 .sendVolumeKeyEvent(event, true);
4845 }
Jeff Brown4d396052010-10-29 21:50:21 -07004846 break;
4847 }
4848 }
4849 break;
4850 }
4851
4852 case KeyEvent.KEYCODE_ENDCALL: {
4853 result &= ~ACTION_PASS_TO_USER;
4854 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004855 TelecomManager telecomManager = getTelecommService();
Jeff Brown4d396052010-10-29 21:50:21 -07004856 boolean hungUp = false;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004857 if (telecomManager != null) {
4858 hungUp = telecomManager.endCall();
Jeff Brown4d396052010-10-29 21:50:21 -07004859 }
Jeff Brown13f00f02014-10-31 14:45:50 -07004860 if (interactive && !hungUp) {
4861 mEndCallKeyHandled = false;
4862 mHandler.postDelayed(mEndCallLongPress,
4863 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
4864 } else {
4865 mEndCallKeyHandled = true;
4866 }
Jeff Brown4d396052010-10-29 21:50:21 -07004867 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004868 if (!mEndCallKeyHandled) {
4869 mHandler.removeCallbacks(mEndCallLongPress);
4870 if (!canceled) {
4871 if ((mEndcallBehavior
4872 & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) {
4873 if (goHome()) {
4874 break;
4875 }
Dianne Hackborn0041e972009-07-24 17:14:43 -07004876 }
Jeff Brown13f00f02014-10-31 14:45:50 -07004877 if ((mEndcallBehavior
4878 & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) {
4879 mPowerManager.goToSleep(event.getEventTime(),
4880 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
4881 isWakeKey = false;
4882 }
Jeff Brown4d396052010-10-29 21:50:21 -07004883 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004884 }
Jeff Brown4d396052010-10-29 21:50:21 -07004885 }
4886 break;
4887 }
4888
4889 case KeyEvent.KEYCODE_POWER: {
4890 result &= ~ACTION_PASS_TO_USER;
Jeff Brown13f00f02014-10-31 14:45:50 -07004891 isWakeKey = false; // wake-up will be handled separately
Jeff Brown4d396052010-10-29 21:50:21 -07004892 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004893 interceptPowerKeyDown(event, interactive);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004894 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004895 interceptPowerKeyUp(event, interactive, canceled);
Jeff Brown4d396052010-10-29 21:50:21 -07004896 }
4897 break;
4898 }
4899
Jeff Brown6212a492014-03-07 13:58:47 -08004900 case KeyEvent.KEYCODE_SLEEP: {
4901 result &= ~ACTION_PASS_TO_USER;
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00004902 isWakeKey = false;
Jeff Brownbae8e772014-06-12 19:59:45 -07004903 if (!mPowerManager.isInteractive()) {
4904 useHapticFeedback = false; // suppress feedback if already non-interactive
4905 }
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00004906 sleepPress(event);
Jeff Brown6212a492014-03-07 13:58:47 -08004907 break;
4908 }
4909
4910 case KeyEvent.KEYCODE_WAKEUP: {
4911 result &= ~ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07004912 isWakeKey = true;
Jeff Brown6212a492014-03-07 13:58:47 -08004913 break;
4914 }
4915
Jeff Brown4d396052010-10-29 21:50:21 -07004916 case KeyEvent.KEYCODE_MEDIA_PLAY:
4917 case KeyEvent.KEYCODE_MEDIA_PAUSE:
4918 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
Jeff Brown4d396052010-10-29 21:50:21 -07004919 case KeyEvent.KEYCODE_HEADSETHOOK:
4920 case KeyEvent.KEYCODE_MUTE:
4921 case KeyEvent.KEYCODE_MEDIA_STOP:
4922 case KeyEvent.KEYCODE_MEDIA_NEXT:
4923 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
4924 case KeyEvent.KEYCODE_MEDIA_REWIND:
4925 case KeyEvent.KEYCODE_MEDIA_RECORD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09004926 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
4927 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: {
RoboErikde9ba392014-09-26 12:51:01 -07004928 if (MediaSessionLegacyHelper.getHelper(mContext).isGlobalPriorityActive()) {
4929 // If the global session is active pass all media keys to it
4930 // instead of the active window.
4931 result &= ~ACTION_PASS_TO_USER;
4932 }
Jeff Brown4d396052010-10-29 21:50:21 -07004933 if ((result & ACTION_PASS_TO_USER) == 0) {
4934 // Only do this if we would otherwise not pass it to the user. In that
4935 // case, the PhoneWindow class will do the same thing, except it will
4936 // only do it if the showing app doesn't process the key on its own.
Jeff Brown40013652012-05-16 21:22:36 -07004937 // Note that we need to make a copy of the key event here because the
4938 // original key event will be recycled when we return.
Jeff Brown4d396052010-10-29 21:50:21 -07004939 mBroadcastWakeLock.acquire();
Jeff Brown40013652012-05-16 21:22:36 -07004940 Message msg = mHandler.obtainMessage(MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK,
4941 new KeyEvent(event));
4942 msg.setAsynchronous(true);
4943 msg.sendToTarget();
Jeff Brown4d396052010-10-29 21:50:21 -07004944 }
4945 break;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004946 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004947
Jeff Brown4d396052010-10-29 21:50:21 -07004948 case KeyEvent.KEYCODE_CALL: {
4949 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004950 TelecomManager telecomManager = getTelecommService();
4951 if (telecomManager != null) {
4952 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07004953 Log.i(TAG, "interceptKeyBeforeQueueing:"
4954 + " CALL key-down while ringing: Answer the call!");
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004955 telecomManager.acceptRingingCall();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004956
Santos Cordon6848f722014-05-21 15:22:12 -07004957 // And *don't* pass this key thru to the current activity
4958 // (which is presumably the InCallScreen.)
4959 result &= ~ACTION_PASS_TO_USER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004960 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004961 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004962 }
Jeff Brown4d396052010-10-29 21:50:21 -07004963 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004964 }
Michael Wright869a67c2014-08-26 19:33:06 -07004965 case KeyEvent.KEYCODE_VOICE_ASSIST: {
4966 // Only do this if we would otherwise not pass it to the user. In that case,
4967 // interceptKeyBeforeDispatching would apply a similar but different policy in
4968 // order to invoke voice assist actions. Note that we need to make a copy of the
4969 // key event here because the original key event will be recycled when we return.
4970 if ((result & ACTION_PASS_TO_USER) == 0 && !down) {
4971 mBroadcastWakeLock.acquire();
4972 Message msg = mHandler.obtainMessage(MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK,
4973 keyguardActive ? 1 : 0, 0);
4974 msg.setAsynchronous(true);
4975 msg.sendToTarget();
4976 }
4977 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004978 }
Jeff Brown26875502014-01-30 21:47:47 -08004979
Jeff Brownbae8e772014-06-12 19:59:45 -07004980 if (useHapticFeedback) {
4981 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
4982 }
4983
Jeff Brown26875502014-01-30 21:47:47 -08004984 if (isWakeKey) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004985 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey);
Jeff Brown26875502014-01-30 21:47:47 -08004986 }
Bryce Lee584a4452014-10-21 15:55:55 -07004987
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004988 return result;
4989 }
4990
Jeff Brown1c2e4942012-11-06 16:32:01 -08004991 /**
Jeff Brown13f00f02014-10-31 14:45:50 -07004992 * Returns true if the key can have global actions attached to it.
4993 * We reserve all power management keys for the system since they require
4994 * very careful handling.
4995 */
4996 private static boolean isValidGlobalKey(int keyCode) {
4997 switch (keyCode) {
4998 case KeyEvent.KEYCODE_POWER:
4999 case KeyEvent.KEYCODE_WAKEUP:
5000 case KeyEvent.KEYCODE_SLEEP:
5001 return false;
5002 default:
5003 return true;
5004 }
5005 }
5006
5007 /**
Jeff Brown1c2e4942012-11-06 16:32:01 -08005008 * When the screen is off we ignore some keys that might otherwise typically
5009 * be considered wake keys. We filter them out here.
5010 *
5011 * {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it
5012 * is always considered a wake key.
5013 */
5014 private boolean isWakeKeyWhenScreenOff(int keyCode) {
5015 switch (keyCode) {
5016 // ignore volume keys unless docked
5017 case KeyEvent.KEYCODE_VOLUME_UP:
5018 case KeyEvent.KEYCODE_VOLUME_DOWN:
5019 case KeyEvent.KEYCODE_VOLUME_MUTE:
5020 return mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED;
5021
5022 // ignore media and camera keys
5023 case KeyEvent.KEYCODE_MUTE:
5024 case KeyEvent.KEYCODE_HEADSETHOOK:
5025 case KeyEvent.KEYCODE_MEDIA_PLAY:
5026 case KeyEvent.KEYCODE_MEDIA_PAUSE:
5027 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
5028 case KeyEvent.KEYCODE_MEDIA_STOP:
5029 case KeyEvent.KEYCODE_MEDIA_NEXT:
5030 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
5031 case KeyEvent.KEYCODE_MEDIA_REWIND:
5032 case KeyEvent.KEYCODE_MEDIA_RECORD:
5033 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09005034 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK:
Jeff Brown1c2e4942012-11-06 16:32:01 -08005035 case KeyEvent.KEYCODE_CAMERA:
5036 return false;
5037 }
5038 return true;
5039 }
5040
5041
Jeff Brown56194eb2011-03-02 19:23:13 -08005042 /** {@inheritDoc} */
5043 @Override
Michael Wright70af00a2014-09-03 19:30:20 -07005044 public int interceptMotionBeforeQueueingNonInteractive(long whenNanos, int policyFlags) {
5045 if ((policyFlags & FLAG_WAKE) != 0) {
Bryce Lee5c138322014-11-03 08:26:09 -08005046 if (wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotion)) {
5047 return 0;
5048 }
Michael Wright70af00a2014-09-03 19:30:20 -07005049 }
Bryce Lee5c138322014-11-03 08:26:09 -08005050
Michael Wright70af00a2014-09-03 19:30:20 -07005051 if (shouldDispatchInputWhenNonInteractive()) {
5052 return ACTION_PASS_TO_USER;
5053 }
Bryce Lee5c138322014-11-03 08:26:09 -08005054
Bryce Lee812d7022014-11-10 13:33:28 -08005055 // If we have not passed the action up and we are in theater mode without dreaming,
5056 // there will be no dream to intercept the touch and wake into ambient. The device should
5057 // wake up in this case.
5058 if (isTheaterModeEnabled() && (policyFlags & FLAG_WAKE) != 0) {
5059 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotionWhenNotDreaming);
5060 }
5061
Jeff Brown037c33e2014-04-09 00:31:55 -07005062 return 0;
Jeff Brown56194eb2011-03-02 19:23:13 -08005063 }
5064
Michael Wright70af00a2014-09-03 19:30:20 -07005065 private boolean shouldDispatchInputWhenNonInteractive() {
Bryce Lee5c138322014-11-03 08:26:09 -08005066 // Send events to keyguard while the screen is on.
Jim Millerab954542014-10-10 18:21:49 -07005067 if (isKeyguardShowingAndNotOccluded() && mDisplay != null
5068 && mDisplay.getState() != Display.STATE_OFF) {
Bryce Lee5c138322014-11-03 08:26:09 -08005069 return true;
5070 }
5071
5072 // Send events to a dozing dream even if the screen is off since the dream
5073 // is in control of the state of the screen.
5074 IDreamManager dreamManager = getDreamManager();
5075
5076 try {
5077 if (dreamManager != null && dreamManager.isDreaming()) {
5078 return true;
5079 }
5080 } catch (RemoteException e) {
5081 Slog.e(TAG, "RemoteException when checking if dreaming", e);
5082 }
5083
5084 // Otherwise, consume events since the user can't see what is being
5085 // interacted with.
5086 return false;
Michael Wright70af00a2014-09-03 19:30:20 -07005087 }
5088
RoboErik001c59c2015-01-26 15:53:51 -08005089 private void dispatchDirectAudioEvent(KeyEvent event) {
5090 if (event.getAction() != KeyEvent.ACTION_DOWN) {
5091 return;
5092 }
5093 int keyCode = event.getKeyCode();
John Spurlockb94f2d62015-03-17 14:11:57 -04005094 int flags = AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_PLAY_SOUND
5095 | AudioManager.FLAG_FROM_KEY;
RoboErik001c59c2015-01-26 15:53:51 -08005096 String pkgName = mContext.getOpPackageName();
5097 switch (keyCode) {
5098 case KeyEvent.KEYCODE_VOLUME_UP:
5099 try {
John Spurlockee5ad722015-03-03 16:17:21 -05005100 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_RAISE,
John Spurlock90874332015-03-10 16:00:54 -04005101 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005102 } catch (RemoteException e) {
5103 Log.e(TAG, "Error dispatching volume up in dispatchTvAudioEvent.", e);
5104 }
5105 break;
5106 case KeyEvent.KEYCODE_VOLUME_DOWN:
5107 try {
John Spurlockee5ad722015-03-03 16:17:21 -05005108 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_LOWER,
John Spurlock90874332015-03-10 16:00:54 -04005109 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005110 } catch (RemoteException e) {
5111 Log.e(TAG, "Error dispatching volume down in dispatchTvAudioEvent.", e);
5112 }
5113 break;
5114 case KeyEvent.KEYCODE_VOLUME_MUTE:
5115 try {
5116 if (event.getRepeatCount() == 0) {
John Spurlockee5ad722015-03-03 16:17:21 -05005117 getAudioService().adjustSuggestedStreamVolume(
5118 AudioManager.ADJUST_TOGGLE_MUTE,
John Spurlock90874332015-03-10 16:00:54 -04005119 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005120 }
5121 } catch (RemoteException e) {
5122 Log.e(TAG, "Error dispatching mute in dispatchTvAudioEvent.", e);
5123 }
5124 break;
5125 }
5126 }
5127
Jeff Brown40013652012-05-16 21:22:36 -07005128 void dispatchMediaKeyWithWakeLock(KeyEvent event) {
5129 if (DEBUG_INPUT) {
5130 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: " + event);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005131 }
5132
Jeff Brown40013652012-05-16 21:22:36 -07005133 if (mHavePendingMediaKeyRepeatWithWakeLock) {
5134 if (DEBUG_INPUT) {
5135 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: canceled repeat");
5136 }
5137
5138 mHandler.removeMessages(MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK);
5139 mHavePendingMediaKeyRepeatWithWakeLock = false;
5140 mBroadcastWakeLock.release(); // pending repeat was holding onto the wake lock
5141 }
5142
5143 dispatchMediaKeyWithWakeLockToAudioService(event);
5144
5145 if (event.getAction() == KeyEvent.ACTION_DOWN
5146 && event.getRepeatCount() == 0) {
5147 mHavePendingMediaKeyRepeatWithWakeLock = true;
5148
5149 Message msg = mHandler.obtainMessage(
5150 MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK, event);
5151 msg.setAsynchronous(true);
5152 mHandler.sendMessageDelayed(msg, ViewConfiguration.getKeyRepeatTimeout());
5153 } else {
5154 mBroadcastWakeLock.release();
5155 }
5156 }
5157
5158 void dispatchMediaKeyRepeatWithWakeLock(KeyEvent event) {
5159 mHavePendingMediaKeyRepeatWithWakeLock = false;
5160
5161 KeyEvent repeatEvent = KeyEvent.changeTimeRepeat(event,
5162 SystemClock.uptimeMillis(), 1, event.getFlags() | KeyEvent.FLAG_LONG_PRESS);
5163 if (DEBUG_INPUT) {
5164 Slog.d(TAG, "dispatchMediaKeyRepeatWithWakeLock: " + repeatEvent);
5165 }
5166
5167 dispatchMediaKeyWithWakeLockToAudioService(repeatEvent);
5168 mBroadcastWakeLock.release();
5169 }
5170
5171 void dispatchMediaKeyWithWakeLockToAudioService(KeyEvent event) {
5172 if (ActivityManagerNative.isSystemReady()) {
RoboErik430fc482014-06-12 15:49:20 -07005173 MediaSessionLegacyHelper.getHelper(mContext).sendMediaButtonEvent(event, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005174 }
5175 }
5176
Michael Wright869a67c2014-08-26 19:33:06 -07005177 void launchVoiceAssistWithWakeLock(boolean keyguardActive) {
5178 Intent voiceIntent =
5179 new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
5180 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, keyguardActive);
Bart Sears8b1c27c2015-03-18 23:51:02 +00005181 startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
Michael Wright869a67c2014-08-26 19:33:06 -07005182 mBroadcastWakeLock.release();
5183 }
5184
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005185 BroadcastReceiver mDockReceiver = new BroadcastReceiver() {
Craig Mautnereee29c42013-01-17 14:44:34 -08005186 @Override
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005187 public void onReceive(Context context, Intent intent) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07005188 if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) {
5189 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
5190 Intent.EXTRA_DOCK_STATE_UNDOCKED);
Daniel Sandler6396c722013-04-16 20:19:09 -04005191 } else {
5192 try {
5193 IUiModeManager uiModeService = IUiModeManager.Stub.asInterface(
5194 ServiceManager.getService(Context.UI_MODE_SERVICE));
5195 mUiMode = uiModeService.getCurrentModeType();
5196 } catch (RemoteException e) {
5197 }
Dianne Hackborn80fa1662009-10-07 14:02:10 -07005198 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005199 updateRotation(true);
Craig Mautnereee29c42013-01-17 14:44:34 -08005200 synchronized (mLock) {
5201 updateOrientationListenerLp();
5202 }
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005203 }
5204 };
5205
Jeff Brown6aaf2952012-10-05 16:01:08 -07005206 BroadcastReceiver mDreamReceiver = new BroadcastReceiver() {
5207 @Override
5208 public void onReceive(Context context, Intent intent) {
5209 if (Intent.ACTION_DREAMING_STARTED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005210 if (mKeyguardDelegate != null) {
5211 mKeyguardDelegate.onDreamingStarted();
Jeff Brown6aaf2952012-10-05 16:01:08 -07005212 }
5213 } else if (Intent.ACTION_DREAMING_STOPPED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005214 if (mKeyguardDelegate != null) {
5215 mKeyguardDelegate.onDreamingStopped();
Jeff Brown6aaf2952012-10-05 16:01:08 -07005216 }
5217 }
5218 }
5219 };
5220
Christopher Tate5e08af02012-09-21 17:17:22 -07005221 BroadcastReceiver mMultiuserReceiver = new BroadcastReceiver() {
5222 @Override
5223 public void onReceive(Context context, Intent intent) {
5224 if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) {
5225 // tickle the settings observer: this first ensures that we're
5226 // observing the relevant settings for the newly-active user,
5227 // and then updates our own bookkeeping based on the now-
5228 // current user.
5229 mSettingsObserver.onChange(false);
John Spurlockce479d82012-11-29 09:52:21 -05005230
5231 // force a re-application of focused window sysui visibility.
5232 // the window may never have been shown for this user
5233 // e.g. the keyguard when going through the new-user setup flow
John Spurlock04db1762013-05-13 12:46:41 -04005234 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
John Spurlockce479d82012-11-29 09:52:21 -05005235 mLastSystemUiFlags = 0;
5236 updateSystemUiVisibilityLw();
5237 }
Christopher Tate5e08af02012-09-21 17:17:22 -07005238 }
5239 }
5240 };
5241
Adrian Roosddc8b272015-05-21 16:28:27 -07005242 private final Runnable mHiddenNavPanic = new Runnable() {
John Spurlockd9b70bd2014-02-06 17:02:44 -05005243 @Override
5244 public void run() {
Adrian Roosddc8b272015-05-21 16:28:27 -07005245 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
5246 if (!isUserSetupComplete()) {
5247 // Swipe-up for navigation bar is disabled during setup
5248 return;
5249 }
5250 mPendingPanicGestureUptime = SystemClock.uptimeMillis();
5251 mNavigationBarController.showTransient();
5252 }
John Spurlockd9b70bd2014-02-06 17:02:44 -05005253 }
5254 };
5255
John Spurlocke1f366f2013-08-05 12:22:40 -04005256 private void requestTransientBars(WindowState swipeTarget) {
John Spurlock04db1762013-05-13 12:46:41 -04005257 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Maurice Lam99c6e072014-04-28 18:24:28 -07005258 if (!isUserSetupComplete()) {
5259 // Swipe-up for navigation bar is disabled during setup
5260 return;
5261 }
John Spurlock27735a42013-08-14 17:57:38 -04005262 boolean sb = mStatusBarController.checkShowTransientBarLw();
5263 boolean nb = mNavigationBarController.checkShowTransientBarLw();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005264 if (sb || nb) {
Adrian Roos62b65e42015-02-25 18:05:34 +01005265 // Don't show status bar when swiping on already visible navigation bar
5266 if (!nb && swipeTarget == mNavigationBar) {
John Spurlocke1f366f2013-08-05 12:22:40 -04005267 if (DEBUG) Slog.d(TAG, "Not showing transient bar, wrong swipe target");
John Spurlockad3e6cb2013-04-30 08:47:43 -04005268 return;
5269 }
John Spurlock27735a42013-08-14 17:57:38 -04005270 if (sb) mStatusBarController.showTransient();
5271 if (nb) mNavigationBarController.showTransient();
John Spurlockf1a36642013-10-12 17:50:42 -04005272 mImmersiveModeConfirmation.confirmCurrentPrompt();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005273 updateSystemUiVisibilityLw();
John Spurlock32beb2c2013-03-11 10:16:47 -04005274 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04005275 }
5276 }
5277
Jeff Brown3ee549c2014-09-22 20:14:39 -07005278 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07005279 @Override
Jeff Brown416c49c2015-05-26 19:50:18 -07005280 public void startedGoingToSleep(int why) {
5281 if (DEBUG_WAKEUP) Slog.i(TAG, "Started going to sleep... (why=" + why + ")");
Jorim Jaggid175b6c2015-05-27 15:39:09 -07005282 if (mKeyguardDelegate != null) {
5283 mKeyguardDelegate.onStartedGoingToSleep(why);
5284 }
Jeff Brown416c49c2015-05-26 19:50:18 -07005285 }
5286
5287 // Called on the PowerManager's Notifier thread.
5288 @Override
5289 public void finishedGoingToSleep(int why) {
Dianne Hackborn74489012009-03-24 20:50:09 -07005290 EventLog.writeEvent(70000, 0);
Jeff Brown416c49c2015-05-26 19:50:18 -07005291 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished going to sleep... (why=" + why + ")");
Jeff Brown3ee549c2014-09-22 20:14:39 -07005292
5293 // We must get this work done here because the power manager will drop
5294 // the wake lock and let the system suspend once this function returns.
The Android Open Source Project0727d222009-03-11 12:11:58 -07005295 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005296 mAwake = false;
5297 mKeyguardDrawComplete = false;
Jeff Browna20dda42014-05-27 20:57:24 -07005298 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005299 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05005300 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005301 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005302 if (mKeyguardDelegate != null) {
Jorim Jaggid175b6c2015-05-27 15:39:09 -07005303 mKeyguardDelegate.onFinishedGoingToSleep(why);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005304 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005305 }
5306
Jeff Brown3ee549c2014-09-22 20:14:39 -07005307 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07005308 @Override
Jeff Brown416c49c2015-05-26 19:50:18 -07005309 public void startedWakingUp() {
Dianne Hackborn74489012009-03-24 20:50:09 -07005310 EventLog.writeEvent(70000, 1);
Jeff Brown416c49c2015-05-26 19:50:18 -07005311 if (DEBUG_WAKEUP) Slog.i(TAG, "Started waking up...");
Craig Mautner8a0da012014-05-31 15:13:37 -07005312
Jeff Brown3ee549c2014-09-22 20:14:39 -07005313 // Since goToSleep performs these functions synchronously, we must
5314 // do the same here. We cannot post this work to a handler because
5315 // that might cause it to become reordered with respect to what
5316 // may happen in a future call to goToSleep.
The Android Open Source Project0727d222009-03-11 12:11:58 -07005317 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005318 mAwake = true;
5319 mKeyguardDrawComplete = false;
5320 if (mKeyguardDelegate != null) {
5321 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
5322 mHandler.sendEmptyMessageDelayed(MSG_KEYGUARD_DRAWN_TIMEOUT, 1000);
5323 }
5324
Jeff Browna20dda42014-05-27 20:57:24 -07005325 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005326 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05005327 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005328 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005329
Jim Miller5ecd8112013-01-09 18:50:26 -08005330 if (mKeyguardDelegate != null) {
Jorim Jaggid175b6c2015-05-27 15:39:09 -07005331 mKeyguardDelegate.onStartedWakingUp(mKeyguardDelegateCallback);
Jeff Brown36c4db82014-09-19 12:05:31 -07005332 // ... eventually calls finishKeyguardDrawn
Jeff Brownc38c9be2012-10-04 13:16:19 -07005333 } else {
Craig Mautner8a0da012014-05-31 15:13:37 -07005334 if (DEBUG_WAKEUP) Slog.d(TAG, "null mKeyguardDelegate: setting mKeyguardDrawComplete.");
Jeff Brown36c4db82014-09-19 12:05:31 -07005335 finishKeyguardDrawn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07005336 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005337 }
5338
Jeff Brown416c49c2015-05-26 19:50:18 -07005339 // Called on the PowerManager's Notifier thread.
5340 @Override
5341 public void finishedWakingUp() {
5342 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished waking up...");
5343 }
5344
5345 private void wakeUpFromPowerKey(long eventTime) {
5346 wakeUp(eventTime, mAllowTheaterModeWakeFromPowerKey);
5347 }
5348
5349 private boolean wakeUp(long wakeTime, boolean wakeInTheaterMode) {
5350 if (!wakeInTheaterMode && isTheaterModeEnabled()) {
5351 return false;
5352 }
5353
5354 mPowerManager.wakeUp(wakeTime);
5355 return true;
5356 }
5357
Jeff Brown36c4db82014-09-19 12:05:31 -07005358 private void finishKeyguardDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005359 synchronized (mLock) {
5360 if (!mAwake || mKeyguardDrawComplete) {
5361 return; // spurious
5362 }
5363
Jeff Brown36c4db82014-09-19 12:05:31 -07005364 mKeyguardDrawComplete = true;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005365 if (mKeyguardDelegate != null) {
5366 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
5367 }
5368 }
5369
5370 finishScreenTurningOn();
5371 }
5372
5373 // Called on the DisplayManager's DisplayPowerController thread.
5374 @Override
5375 public void screenTurnedOff() {
5376 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turned off...");
5377
5378 synchronized (mLock) {
5379 mScreenOnEarly = false;
5380 mScreenOnFully = false;
5381 mWindowManagerDrawComplete = false;
5382 mScreenOnListener = null;
5383 updateOrientationListenerLp();
Jeff Brown36c4db82014-09-19 12:05:31 -07005384 }
5385 }
5386
Jeff Brown3ee549c2014-09-22 20:14:39 -07005387 // Called on the DisplayManager's DisplayPowerController thread.
Jeff Brown36c4db82014-09-19 12:05:31 -07005388 @Override
5389 public void screenTurningOn(final ScreenOnListener screenOnListener) {
Jeff Brown36c4db82014-09-19 12:05:31 -07005390 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turning on...");
Jeff Brown36c4db82014-09-19 12:05:31 -07005391
Jeff Brown3ee549c2014-09-22 20:14:39 -07005392 synchronized (mLock) {
5393 mScreenOnEarly = true;
5394 mScreenOnFully = false;
5395 mWindowManagerDrawComplete = false;
5396 mScreenOnListener = screenOnListener;
5397 updateOrientationListenerLp();
5398 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005399
Craig Mautnerc3daedd2014-09-13 11:17:23 -07005400 mWindowManagerInternal.waitForAllWindowsDrawn(mWindowManagerDrawCallback,
5401 WAITING_FOR_DRAWN_TIMEOUT);
Jeff Brown36c4db82014-09-19 12:05:31 -07005402 // ... eventually calls finishWindowsDrawn
5403 }
5404
Jeff Brown36c4db82014-09-19 12:05:31 -07005405 private void finishWindowsDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005406 synchronized (mLock) {
5407 if (!mScreenOnEarly || mWindowManagerDrawComplete) {
5408 return; // spurious
5409 }
5410
Jeff Brown36c4db82014-09-19 12:05:31 -07005411 mWindowManagerDrawComplete = true;
Jeff Brown36c4db82014-09-19 12:05:31 -07005412 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005413
5414 finishScreenTurningOn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07005415 }
5416
Craig Mautner8a0da012014-05-31 15:13:37 -07005417 private void finishScreenTurningOn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005418 final ScreenOnListener listener;
5419 final boolean enableScreen;
Jeff Brown36c4db82014-09-19 12:05:31 -07005420 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005421 if (DEBUG_WAKEUP) Slog.d(TAG,
5422 "finishScreenTurningOn: mAwake=" + mAwake
5423 + ", mScreenOnEarly=" + mScreenOnEarly
5424 + ", mScreenOnFully=" + mScreenOnFully
5425 + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete
5426 + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete);
5427
5428 if (mScreenOnFully || !mScreenOnEarly || !mWindowManagerDrawComplete
5429 || (mAwake && !mKeyguardDrawComplete)) {
5430 return; // spurious or not ready yet
Jeff Brown36c4db82014-09-19 12:05:31 -07005431 }
5432
Jeff Brown3ee549c2014-09-22 20:14:39 -07005433 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished screen turning on...");
5434 listener = mScreenOnListener;
Craig Mautner13f6ea72014-06-23 14:57:02 -07005435 mScreenOnListener = null;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005436 mScreenOnFully = true;
5437
5438 // Remember the first time we draw the keyguard so we know when we're done with
5439 // the main part of booting and can enable the screen and hide boot messages.
5440 if (!mKeyguardDrawnOnce && mAwake) {
5441 mKeyguardDrawnOnce = true;
5442 enableScreen = true;
5443 if (mBootMessageNeedsHiding) {
5444 mBootMessageNeedsHiding = false;
5445 hideBootMessages();
5446 }
5447 } else {
5448 enableScreen = false;
5449 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005450 }
5451
Jeff Brown3ee549c2014-09-22 20:14:39 -07005452 if (listener != null) {
5453 listener.onScreenOn();
5454 }
Jeff Brown4fc45272012-10-10 18:28:14 -07005455
Jeff Brown3ee549c2014-09-22 20:14:39 -07005456 if (enableScreen) {
5457 try {
5458 mWindowManager.enableScreenIfNeeded();
5459 } catch (RemoteException unhandled) {
Jeff Brown36c4db82014-09-19 12:05:31 -07005460 }
Craig Mautnera631d492014-08-05 15:16:01 -07005461 }
5462 }
5463
5464 private void handleHideBootMessage() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005465 synchronized (mLock) {
5466 if (!mKeyguardDrawnOnce) {
5467 mBootMessageNeedsHiding = true;
5468 return; // keyguard hasn't drawn the first time yet, not done booting
5469 }
Craig Mautnera631d492014-08-05 15:16:01 -07005470 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005471
5472 if (mBootMsgDialog != null) {
5473 if (DEBUG_WAKEUP) Slog.d(TAG, "handleHideBootMessage: dismissing");
5474 mBootMsgDialog.dismiss();
5475 mBootMsgDialog = null;
Craig Mautnera631d492014-08-05 15:16:01 -07005476 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005477 }
5478
5479 @Override
Jeff Brown3ee549c2014-09-22 20:14:39 -07005480 public boolean isScreenOn() {
5481 return mScreenOnFully;
Dianne Hackborn08743722009-12-21 12:16:51 -08005482 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005483
Dianne Hackborn08743722009-12-21 12:16:51 -08005484 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005485 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005486 public void enableKeyguard(boolean enabled) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005487 if (mKeyguardDelegate != null) {
5488 mKeyguardDelegate.setKeyguardEnabled(enabled);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005489 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005490 }
5491
5492 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005493 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005494 public void exitKeyguardSecurely(OnKeyguardExitResult callback) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005495 if (mKeyguardDelegate != null) {
5496 mKeyguardDelegate.verifyUnlock(callback);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005497 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005498 }
5499
Jim Millerab954542014-10-10 18:21:49 -07005500 private boolean isKeyguardShowingAndNotOccluded() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005501 if (mKeyguardDelegate == null) return false;
Jim Millerab954542014-10-10 18:21:49 -07005502 return mKeyguardDelegate.isShowing() && !mKeyguardOccluded;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005503 }
5504
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005505 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005506 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005507 public boolean isKeyguardLocked() {
5508 return keyguardOn();
5509 }
5510
5511 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005512 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005513 public boolean isKeyguardSecure() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005514 if (mKeyguardDelegate == null) return false;
5515 return mKeyguardDelegate.isSecure();
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005516 }
5517
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005518 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005519 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005520 public boolean inKeyguardRestrictedKeyInputMode() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005521 if (mKeyguardDelegate == null) return false;
5522 return mKeyguardDelegate.isInputRestricted();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005523 }
5524
Jose Lima9546b202014-07-02 17:21:51 -07005525 @Override
Dianne Hackborn90c52de2011-09-23 12:57:44 -07005526 public void dismissKeyguardLw() {
RoboErik8a2cfc32014-05-16 11:19:38 -07005527 if (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()) {
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07005528 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.dismissKeyguardLw");
Daniel Sandler1ce804392012-11-07 15:07:12 -05005529 mHandler.post(new Runnable() {
Jose Lima9546b202014-07-02 17:21:51 -07005530 @Override
Daniel Sandler1ce804392012-11-07 15:07:12 -05005531 public void run() {
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02005532 // ask the keyguard to prompt the user to authenticate if necessary
5533 mKeyguardDelegate.dismiss();
5534 }
5535 });
5536 }
5537 }
5538
5539 public void notifyActivityDrawnForKeyguardLw() {
5540 if (mKeyguardDelegate != null) {
5541 mHandler.post(new Runnable() {
5542 @Override
5543 public void run() {
5544 mKeyguardDelegate.onActivityDrawn();
Daniel Sandler1ce804392012-11-07 15:07:12 -05005545 }
5546 });
Dianne Hackborn90c52de2011-09-23 12:57:44 -07005547 }
5548 }
5549
Jorim Jaggicff0acb2014-03-31 16:35:15 +02005550 @Override
5551 public boolean isKeyguardDrawnLw() {
5552 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005553 return mKeyguardDrawnOnce;
Jorim Jaggicff0acb2014-03-31 16:35:15 +02005554 }
5555 }
5556
Jorim Jaggi0d674622014-05-21 01:34:15 +02005557 @Override
Jorim Jaggie29b2db2014-05-30 23:17:03 +02005558 public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) {
Jorim Jaggi0d674622014-05-21 01:34:15 +02005559 if (mKeyguardDelegate != null) {
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07005560 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.startKeyguardExitAnimation");
Jorim Jaggie29b2db2014-05-30 23:17:03 +02005561 mKeyguardDelegate.startKeyguardExitAnimation(startTime, fadeoutDuration);
Jorim Jaggi0d674622014-05-21 01:34:15 +02005562 }
5563 }
5564
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005565 void sendCloseSystemWindows() {
Jorim Jaggib10e33f2015-02-04 21:57:40 +01005566 PhoneWindow.sendCloseSystemWindows(mContext, null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005567 }
5568
5569 void sendCloseSystemWindows(String reason) {
Jorim Jaggib10e33f2015-02-04 21:57:40 +01005570 PhoneWindow.sendCloseSystemWindows(mContext, reason);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005571 }
Mitsuru Oshima831d0d92009-06-16 18:27:18 -07005572
Jeff Brown01a98dd2011-09-20 15:08:29 -07005573 @Override
5574 public int rotationForOrientationLw(int orientation, int lastRotation) {
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005575 if (false) {
5576 Slog.v(TAG, "rotationForOrientationLw(orient="
5577 + orientation + ", last=" + lastRotation
5578 + "); user=" + mUserRotation + " "
5579 + ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED)
5580 ? "USER_ROTATION_LOCKED" : "")
5581 );
5582 }
5583
Craig Mautner46ac6fa2013-08-01 10:06:34 -07005584 if (mForceDefaultOrientation) {
5585 return Surface.ROTATION_0;
5586 }
5587
The Android Open Source Project0727d222009-03-11 12:11:58 -07005588 synchronized (mLock) {
Jeff Brownc0347aa2011-09-23 17:26:09 -07005589 int sensorRotation = mOrientationListener.getProposedRotation(); // may be -1
5590 if (sensorRotation < 0) {
Jeff Brown0f862b42012-09-27 21:11:01 -07005591 sensorRotation = lastRotation;
Jeff Brownc0347aa2011-09-23 17:26:09 -07005592 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005593
Jeff Browndec6cf42011-11-15 14:08:20 -08005594 final int preferredRotation;
Jeff Brown2e7760e2012-04-11 15:14:55 -07005595 if (mLidState == LID_OPEN && mLidOpenRotation >= 0) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005596 // Ignore sensor when lid switch is open and rotation is forced.
5597 preferredRotation = mLidOpenRotation;
5598 } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR
Jeff Brownc0347aa2011-09-23 17:26:09 -07005599 && (mCarDockEnablesAccelerometer || mCarDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005600 // Ignore sensor when in car dock unless explicitly enabled.
5601 // This case can override the behavior of NOSENSOR, and can also
5602 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07005603 preferredRotation = mCarDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07005604 ? sensorRotation : mCarDockRotation;
Jeff Brown1a693182011-11-08 14:44:16 -08005605 } else if ((mDockMode == Intent.EXTRA_DOCK_STATE_DESK
5606 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
5607 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK)
Jeff Brownc0347aa2011-09-23 17:26:09 -07005608 && (mDeskDockEnablesAccelerometer || mDeskDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005609 // Ignore sensor when in desk dock unless explicitly enabled.
5610 // This case can override the behavior of NOSENSOR, and can also
5611 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07005612 preferredRotation = mDeskDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07005613 ? sensorRotation : mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -07005614 } else if (mHdmiPlugged && mDemoHdmiRotationLock) {
5615 // Ignore sensor when plugged into HDMI when demo HDMI rotation lock enabled.
Jeff Browneb3e4b92011-12-06 19:54:24 -08005616 // Note that the dock orientation overrides the HDMI orientation.
Jeff Brownc82c89ed2013-04-17 17:18:15 -07005617 preferredRotation = mDemoHdmiRotation;
5618 } else if (mHdmiPlugged && mDockMode == Intent.EXTRA_DOCK_STATE_UNDOCKED
5619 && mUndockedHdmiRotation >= 0) {
5620 // Ignore sensor when plugged into HDMI and an undocked orientation has
5621 // been specified in the configuration (only for legacy devices without
5622 // full multi-display support).
5623 // Note that the dock orientation overrides the HDMI orientation.
5624 preferredRotation = mUndockedHdmiRotation;
Chong Zhangae6119ff2014-11-11 18:54:39 -08005625 } else if (mDemoRotationLock) {
5626 // Ignore sensor when demo rotation lock is enabled.
5627 // Note that the dock orientation and HDMI rotation lock override this.
5628 preferredRotation = mDemoRotation;
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005629 } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED) {
5630 // Application just wants to remain locked in the last rotation.
5631 preferredRotation = lastRotation;
Jeff Brownbcdfc622014-03-06 19:13:04 -08005632 } else if (!mSupportAutoRotation) {
5633 // If we don't support auto-rotation then bail out here and ignore
5634 // the sensor and any rotation lock settings.
5635 preferredRotation = -1;
Jeff Brown207673cd2012-06-05 17:47:11 -07005636 } else if ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE
Jeff Brown01a98dd2011-09-20 15:08:29 -07005637 && (orientation == ActivityInfo.SCREEN_ORIENTATION_USER
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005638 || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
5639 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
5640 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
5641 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER))
Jeff Brown01a98dd2011-09-20 15:08:29 -07005642 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
5643 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
5644 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
5645 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) {
5646 // Otherwise, use sensor only if requested by the application or enabled
5647 // by default for USER or UNSPECIFIED modes. Does not apply to NOSENSOR.
Jeff Brownd3187e32011-09-21 19:26:44 -07005648 if (mAllowAllRotations < 0) {
5649 // Can't read this during init() because the context doesn't
5650 // have display metrics at that time so we cannot determine
5651 // tablet vs. phone then.
5652 mAllowAllRotations = mContext.getResources().getBoolean(
5653 com.android.internal.R.bool.config_allowAllRotations) ? 1 : 0;
5654 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005655 if (sensorRotation != Surface.ROTATION_180
Jeff Brownd3187e32011-09-21 19:26:44 -07005656 || mAllowAllRotations == 1
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005657 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
5658 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005659 preferredRotation = sensorRotation;
5660 } else {
5661 preferredRotation = lastRotation;
5662 }
Jeff Brown207673cd2012-06-05 17:47:11 -07005663 } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED
5664 && orientation != ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) {
5665 // Apply rotation lock. Does not apply to NOSENSOR.
5666 // The idea is that the user rotation expresses a weak preference for the direction
5667 // of gravity and as NOSENSOR is never affected by gravity, then neither should
5668 // NOSENSOR be affected by rotation lock (although it will be affected by docks).
Jeff Brown4dfce202011-10-05 12:00:10 -07005669 preferredRotation = mUserRotation;
Jeff Browndec6cf42011-11-15 14:08:20 -08005670 } else {
5671 // No overriding preference.
5672 // We will do exactly what the application asked us to do.
5673 preferredRotation = -1;
Jeff Brown01a98dd2011-09-20 15:08:29 -07005674 }
5675
Dianne Hackborne5439f22010-10-02 16:53:50 -07005676 switch (orientation) {
5677 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08005678 // Return portrait unless overridden.
5679 if (isAnyPortrait(preferredRotation)) {
5680 return preferredRotation;
5681 }
Dianne Hackborne5439f22010-10-02 16:53:50 -07005682 return mPortraitRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005683
Jeff Brown01a98dd2011-09-20 15:08:29 -07005684 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08005685 // Return landscape unless overridden.
5686 if (isLandscapeOrSeascape(preferredRotation)) {
5687 return preferredRotation;
5688 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005689 return mLandscapeRotation;
5690
5691 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08005692 // Return reverse portrait unless overridden.
5693 if (isAnyPortrait(preferredRotation)) {
5694 return preferredRotation;
5695 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005696 return mUpsideDownRotation;
5697
5698 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08005699 // Return seascape unless overridden.
5700 if (isLandscapeOrSeascape(preferredRotation)) {
5701 return preferredRotation;
5702 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005703 return mSeascapeRotation;
5704
5705 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005706 case ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE:
Jeff Brown01a98dd2011-09-20 15:08:29 -07005707 // Return either landscape rotation.
5708 if (isLandscapeOrSeascape(preferredRotation)) {
5709 return preferredRotation;
5710 }
5711 if (isLandscapeOrSeascape(lastRotation)) {
Jeff Brown4519f072011-01-23 13:16:01 -08005712 return lastRotation;
5713 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005714 return mLandscapeRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005715
Jeff Brown01a98dd2011-09-20 15:08:29 -07005716 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005717 case ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT:
Jeff Brown01a98dd2011-09-20 15:08:29 -07005718 // Return either portrait rotation.
5719 if (isAnyPortrait(preferredRotation)) {
5720 return preferredRotation;
5721 }
5722 if (isAnyPortrait(lastRotation)) {
5723 return lastRotation;
5724 }
5725 return mPortraitRotation;
5726
5727 default:
Jeff Brown4dfce202011-10-05 12:00:10 -07005728 // For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR,
5729 // just return the preferred orientation we already calculated.
Jeff Brown01a98dd2011-09-20 15:08:29 -07005730 if (preferredRotation >= 0) {
5731 return preferredRotation;
5732 }
Dianne Hackborndacea8c2011-04-21 17:26:39 -07005733 return Surface.ROTATION_0;
Daniel Sandlere7e5ac22011-02-22 16:10:21 -05005734 }
5735 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07005736 }
5737
Jeff Brown01a98dd2011-09-20 15:08:29 -07005738 @Override
5739 public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation) {
5740 switch (orientation) {
5741 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
5742 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
5743 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
5744 return isAnyPortrait(rotation);
5745
5746 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
5747 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
5748 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
5749 return isLandscapeOrSeascape(rotation);
5750
5751 default:
5752 return true;
5753 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07005754 }
5755
Jeff Brownc0347aa2011-09-23 17:26:09 -07005756 @Override
5757 public void setRotationLw(int rotation) {
5758 mOrientationListener.setCurrentRotation(rotation);
5759 }
5760
Jeff Brown01a98dd2011-09-20 15:08:29 -07005761 private boolean isLandscapeOrSeascape(int rotation) {
5762 return rotation == mLandscapeRotation || rotation == mSeascapeRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005763 }
5764
Jeff Brown01a98dd2011-09-20 15:08:29 -07005765 private boolean isAnyPortrait(int rotation) {
5766 return rotation == mPortraitRotation || rotation == mUpsideDownRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005767 }
5768
Jose Lima9546b202014-07-02 17:21:51 -07005769 @Override
Svetoslav Ganov80943d82013-01-02 10:25:37 -08005770 public int getUserRotationMode() {
5771 return Settings.System.getIntForUser(mContext.getContentResolver(),
Brett Chabot7e55c402013-05-16 19:38:08 -07005772 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
5773 WindowManagerPolicy.USER_ROTATION_FREE :
5774 WindowManagerPolicy.USER_ROTATION_LOCKED;
Svetoslav Ganov80943d82013-01-02 10:25:37 -08005775 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005776
5777 // User rotation: to be used when all else fails in assigning an orientation to the device
Jose Lima9546b202014-07-02 17:21:51 -07005778 @Override
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005779 public void setUserRotationMode(int mode, int rot) {
5780 ContentResolver res = mContext.getContentResolver();
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005781
5782 // mUserRotationMode and mUserRotation will be assigned by the content observer
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005783 if (mode == WindowManagerPolicy.USER_ROTATION_LOCKED) {
Christopher Tate5e08af02012-09-21 17:17:22 -07005784 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005785 Settings.System.USER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005786 rot,
5787 UserHandle.USER_CURRENT);
5788 Settings.System.putIntForUser(res,
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005789 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005790 0,
5791 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005792 } else {
Christopher Tate5e08af02012-09-21 17:17:22 -07005793 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005794 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005795 1,
5796 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005797 }
5798 }
5799
Jose Lima9546b202014-07-02 17:21:51 -07005800 @Override
Jeff Brownac143512012-04-05 18:57:33 -07005801 public void setSafeMode(boolean safeMode) {
5802 mSafeMode = safeMode;
5803 performHapticFeedbackLw(null, safeMode
5804 ? HapticFeedbackConstants.SAFE_MODE_ENABLED
5805 : HapticFeedbackConstants.SAFE_MODE_DISABLED, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005806 }
Craig Mautnereda67292013-04-28 13:50:14 -07005807
Dianne Hackborn181ceb52009-08-27 22:16:40 -07005808 static long[] getLongIntArray(Resources r, int resid) {
5809 int[] ar = r.getIntArray(resid);
5810 if (ar == null) {
5811 return null;
5812 }
5813 long[] out = new long[ar.length];
5814 for (int i=0; i<ar.length; i++) {
5815 out[i] = ar[i];
5816 }
5817 return out;
5818 }
Craig Mautnereda67292013-04-28 13:50:14 -07005819
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005820 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07005821 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005822 public void systemReady() {
Jim Millerab954542014-10-10 18:21:49 -07005823 mKeyguardDelegate = new KeyguardServiceDelegate(mContext);
Mike Lockwooded8902d2013-11-15 11:01:47 -08005824 mKeyguardDelegate.onSystemReady();
5825
Michael Wright3818c922014-09-02 13:59:07 -07005826 readCameraLensCoverState();
Jeff Brown4f5fa282014-06-12 19:19:15 -07005827 updateUiMode();
Dianne Hackbornb1a79802009-09-29 15:18:31 -07005828 synchronized (mLock) {
5829 updateOrientationListenerLp();
Dianne Hackbornc777e072010-02-12 13:07:59 -08005830 mSystemReady = true;
5831 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07005832 @Override
Dianne Hackbornc777e072010-02-12 13:07:59 -08005833 public void run() {
5834 updateSettings();
5835 }
5836 });
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005837 }
5838 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07005839
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005840 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005841 @Override
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005842 public void systemBooted() {
Jim Millere5f910a2013-10-16 18:15:46 -07005843 if (mKeyguardDelegate != null) {
Jason Monk5eeebf52014-09-26 12:36:51 -04005844 mKeyguardDelegate.bindService(mContext);
Jim Millere5f910a2013-10-16 18:15:46 -07005845 mKeyguardDelegate.onBootCompleted();
5846 }
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005847 synchronized (mLock) {
5848 mSystemBooted = true;
5849 }
Jeff Brown416c49c2015-05-26 19:50:18 -07005850 startedWakingUp();
Jeff Brown36c4db82014-09-19 12:05:31 -07005851 screenTurningOn(null);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005852 }
5853
Dianne Hackborn661cd522011-08-22 00:26:20 -07005854 ProgressDialog mBootMsgDialog = null;
5855
5856 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005857 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07005858 public void showBootMessage(final CharSequence msg, final boolean always) {
5859 mHandler.post(new Runnable() {
5860 @Override public void run() {
5861 if (mBootMsgDialog == null) {
Craig Stout4c0cb8a2014-04-04 13:03:10 -07005862 int theme;
5863 if (mContext.getPackageManager().hasSystemFeature(
5864 PackageManager.FEATURE_WATCH)) {
5865 theme = com.android.internal.R.style.Theme_Micro_Dialog_Alert;
5866 } else if (mContext.getPackageManager().hasSystemFeature(
5867 PackageManager.FEATURE_TELEVISION)) {
5868 theme = com.android.internal.R.style.Theme_Leanback_Dialog_Alert;
5869 } else {
5870 theme = 0;
5871 }
Vinod Krishnanfa8fc412014-04-18 14:35:53 -07005872
5873 mBootMsgDialog = new ProgressDialog(mContext, theme) {
Dianne Hackborn295e3c22011-08-25 13:19:08 -07005874 // This dialog will consume all events coming in to
5875 // it, to avoid it trying to do things too early in boot.
5876 @Override public boolean dispatchKeyEvent(KeyEvent event) {
5877 return true;
5878 }
5879 @Override public boolean dispatchKeyShortcutEvent(KeyEvent event) {
5880 return true;
5881 }
5882 @Override public boolean dispatchTouchEvent(MotionEvent ev) {
5883 return true;
5884 }
5885 @Override public boolean dispatchTrackballEvent(MotionEvent ev) {
5886 return true;
5887 }
5888 @Override public boolean dispatchGenericMotionEvent(MotionEvent ev) {
5889 return true;
5890 }
5891 @Override public boolean dispatchPopulateAccessibilityEvent(
5892 AccessibilityEvent event) {
5893 return true;
5894 }
5895 };
Jeff Hao9f60c082014-10-28 18:51:07 -07005896 if (mContext.getPackageManager().isUpgrade()) {
5897 mBootMsgDialog.setTitle(R.string.android_upgrading_title);
5898 } else {
5899 mBootMsgDialog.setTitle(R.string.android_start_title);
5900 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07005901 mBootMsgDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
5902 mBootMsgDialog.setIndeterminate(true);
5903 mBootMsgDialog.getWindow().setType(
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07005904 WindowManager.LayoutParams.TYPE_BOOT_PROGRESS);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005905 mBootMsgDialog.getWindow().addFlags(
5906 WindowManager.LayoutParams.FLAG_DIM_BEHIND
5907 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
5908 mBootMsgDialog.getWindow().setDimAmount(1);
Dianne Hackbornd9efb952011-12-07 14:56:51 -08005909 WindowManager.LayoutParams lp = mBootMsgDialog.getWindow().getAttributes();
5910 lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
5911 mBootMsgDialog.getWindow().setAttributes(lp);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005912 mBootMsgDialog.setCancelable(false);
5913 mBootMsgDialog.show();
5914 }
5915 mBootMsgDialog.setMessage(msg);
5916 }
5917 });
5918 }
5919
5920 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005921 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07005922 public void hideBootMessages() {
Craig Mautnera631d492014-08-05 15:16:01 -07005923 mHandler.sendEmptyMessage(MSG_HIDE_BOOT_MESSAGE);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005924 }
5925
Mike Lockwood28569302010-01-28 11:54:40 -05005926 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005927 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05005928 public void userActivity() {
Dianne Hackborndf89e652011-10-06 22:35:11 -07005929 // ***************************************
5930 // NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
5931 // ***************************************
5932 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
5933 // WITH ITS LOCKS HELD.
5934 //
5935 // This code must be VERY careful about the locks
5936 // it acquires.
5937 // In fact, the current code acquires way too many,
5938 // and probably has lurking deadlocks.
5939
Mike Lockwood28569302010-01-28 11:54:40 -05005940 synchronized (mScreenLockTimeout) {
5941 if (mLockScreenTimerActive) {
5942 // reset the timer
5943 mHandler.removeCallbacks(mScreenLockTimeout);
5944 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
5945 }
5946 }
Daniel Sandler0601eb72011-04-13 01:01:32 -04005947 }
5948
Adam Cohenf7522022012-10-03 20:03:18 -07005949 class ScreenLockTimeout implements Runnable {
5950 Bundle options;
5951
5952 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05005953 public void run() {
5954 synchronized (this) {
5955 if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard");
Jim Miller5ecd8112013-01-09 18:50:26 -08005956 if (mKeyguardDelegate != null) {
5957 mKeyguardDelegate.doKeyguardTimeout(options);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005958 }
Mike Lockwood28569302010-01-28 11:54:40 -05005959 mLockScreenTimerActive = false;
Adam Cohenf7522022012-10-03 20:03:18 -07005960 options = null;
Mike Lockwood28569302010-01-28 11:54:40 -05005961 }
5962 }
Mike Lockwood28569302010-01-28 11:54:40 -05005963
Adam Cohenf7522022012-10-03 20:03:18 -07005964 public void setLockOptions(Bundle options) {
5965 this.options = options;
5966 }
5967 }
5968
5969 ScreenLockTimeout mScreenLockTimeout = new ScreenLockTimeout();
5970
Jose Lima9546b202014-07-02 17:21:51 -07005971 @Override
Adam Cohenf7522022012-10-03 20:03:18 -07005972 public void lockNow(Bundle options) {
Jim Miller93c518e2012-01-17 15:55:31 -08005973 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null);
5974 mHandler.removeCallbacks(mScreenLockTimeout);
Adam Cohenf7522022012-10-03 20:03:18 -07005975 if (options != null) {
5976 // In case multiple calls are made to lockNow, we don't wipe out the options
5977 // until the runnable actually executes.
5978 mScreenLockTimeout.setLockOptions(options);
5979 }
Jim Miller93c518e2012-01-17 15:55:31 -08005980 mHandler.post(mScreenLockTimeout);
5981 }
5982
Mike Lockwood28569302010-01-28 11:54:40 -05005983 private void updateLockScreenTimeout() {
5984 synchronized (mScreenLockTimeout) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005985 boolean enable = (mAllowLockscreenWhenOn && mAwake &&
Jim Miller5ecd8112013-01-09 18:50:26 -08005986 mKeyguardDelegate != null && mKeyguardDelegate.isSecure());
Mike Lockwood28569302010-01-28 11:54:40 -05005987 if (mLockScreenTimerActive != enable) {
5988 if (enable) {
5989 if (localLOGV) Log.v(TAG, "setting lockscreen timer");
5990 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
5991 } else {
5992 if (localLOGV) Log.v(TAG, "clearing lockscreen timer");
5993 mHandler.removeCallbacks(mScreenLockTimeout);
5994 }
5995 mLockScreenTimerActive = enable;
5996 }
5997 }
5998 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005999
Jeff Brown061ea992015-04-17 19:55:47 -07006000 private void updateDreamingSleepToken(boolean acquire) {
6001 if (acquire) {
6002 if (mDreamingSleepToken == null) {
6003 mDreamingSleepToken = mActivityManagerInternal.acquireSleepToken("Dream");
6004 }
6005 } else {
6006 if (mDreamingSleepToken != null) {
6007 mDreamingSleepToken.release();
6008 }
6009 }
6010 }
6011
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006012 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07006013 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006014 public void enableScreenAfterBoot() {
6015 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07006016 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07006017 updateRotation(true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006018 }
Dianne Hackbornf54c8f92009-09-19 14:03:57 -07006019
Jeff Brownc458ce92012-04-30 14:58:40 -07006020 private void applyLidSwitchState() {
Jeff Brownc458ce92012-04-30 14:58:40 -07006021 if (mLidState == LID_CLOSED && mLidControlsSleep) {
Jeff Brown6d8fd272014-05-20 21:24:38 -07006022 mPowerManager.goToSleep(SystemClock.uptimeMillis(),
Jeff Brownc12035c2014-08-13 18:52:25 -07006023 PowerManager.GO_TO_SLEEP_REASON_LID_SWITCH,
Jeff Brown6d8fd272014-05-20 21:24:38 -07006024 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
Jeff Brownc458ce92012-04-30 14:58:40 -07006025 }
Jeff Browna20dda42014-05-27 20:57:24 -07006026
6027 synchronized (mLock) {
6028 updateWakeGestureListenerLp();
6029 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006030 }
6031
Jeff Brown4f5fa282014-06-12 19:19:15 -07006032 void updateUiMode() {
6033 if (mUiModeManager == null) {
6034 mUiModeManager = IUiModeManager.Stub.asInterface(
6035 ServiceManager.getService(Context.UI_MODE_SERVICE));
6036 }
6037 try {
6038 mUiMode = mUiModeManager.getCurrentModeType();
6039 } catch (RemoteException e) {
6040 }
6041 }
6042
Jeff Brown01a98dd2011-09-20 15:08:29 -07006043 void updateRotation(boolean alwaysSendConfiguration) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006044 try {
6045 //set orientation on WindowManager
Dianne Hackbornf87d1962012-04-04 12:48:24 -07006046 mWindowManager.updateRotation(alwaysSendConfiguration, false);
6047 } catch (RemoteException e) {
6048 // Ignore
6049 }
6050 }
6051
6052 void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) {
6053 try {
6054 //set orientation on WindowManager
6055 mWindowManager.updateRotation(alwaysSendConfiguration, forceRelayout);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006056 } catch (RemoteException e) {
6057 // Ignore
6058 }
6059 }
6060
Daniel Sandler6396c722013-04-16 20:19:09 -04006061 /**
6062 * Return an Intent to launch the currently active dock app as home. Returns
6063 * null if the standard home should be launched, which is the case if any of the following is
6064 * true:
6065 * <ul>
6066 * <li>The device is not in either car mode or desk mode
6067 * <li>The device is in car mode but ENABLE_CAR_DOCK_HOME_CAPTURE is false
6068 * <li>The device is in desk mode but ENABLE_DESK_DOCK_HOME_CAPTURE is false
6069 * <li>The device is in car mode but there's no CAR_DOCK app with METADATA_DOCK_HOME
6070 * <li>The device is in desk mode but there's no DESK_DOCK app with METADATA_DOCK_HOME
6071 * </ul>
Craig Mautnereda67292013-04-28 13:50:14 -07006072 * @return A dock intent.
Daniel Sandler6396c722013-04-16 20:19:09 -04006073 */
6074 Intent createHomeDockIntent() {
6075 Intent intent = null;
6076
6077 // What home does is based on the mode, not the dock state. That
6078 // is, when in car mode you should be taken to car home regardless
6079 // of whether we are actually in a car dock.
6080 if (mUiMode == Configuration.UI_MODE_TYPE_CAR) {
6081 if (ENABLE_CAR_DOCK_HOME_CAPTURE) {
6082 intent = mCarDockIntent;
6083 }
6084 } else if (mUiMode == Configuration.UI_MODE_TYPE_DESK) {
6085 if (ENABLE_DESK_DOCK_HOME_CAPTURE) {
6086 intent = mDeskDockIntent;
6087 }
Jeff Brown4f5fa282014-06-12 19:19:15 -07006088 } else if (mUiMode == Configuration.UI_MODE_TYPE_WATCH
6089 && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
6090 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK
6091 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK)) {
6092 // Always launch dock home from home when watch is docked, if it exists.
6093 intent = mDeskDockIntent;
Daniel Sandler6396c722013-04-16 20:19:09 -04006094 }
6095
6096 if (intent == null) {
6097 return null;
6098 }
6099
6100 ActivityInfo ai = null;
6101 ResolveInfo info = mContext.getPackageManager().resolveActivityAsUser(
6102 intent,
John Spurlockf56bef12013-07-09 09:51:46 -04006103 PackageManager.MATCH_DEFAULT_ONLY | PackageManager.GET_META_DATA,
Craig Mautnerd625ab22013-09-06 13:40:31 -07006104 mCurrentUserId);
Daniel Sandler6396c722013-04-16 20:19:09 -04006105 if (info != null) {
6106 ai = info.activityInfo;
6107 }
6108 if (ai != null
6109 && ai.metaData != null
6110 && ai.metaData.getBoolean(Intent.METADATA_DOCK_HOME)) {
6111 intent = new Intent(intent);
6112 intent.setClassName(ai.packageName, ai.name);
6113 return intent;
6114 }
6115
6116 return null;
6117 }
6118
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00006119 void startDockOrHome(boolean fromHomeKey, boolean awakenFromDreams) {
6120 if (awakenFromDreams) {
6121 awakenDreams();
6122 }
Daniel Sandler6396c722013-04-16 20:19:09 -04006123
6124 Intent dock = createHomeDockIntent();
6125 if (dock != null) {
6126 try {
Bryce Lee01b0c5f2015-02-05 18:24:04 -08006127 if (fromHomeKey) {
6128 dock.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
6129 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00006130 startActivityAsUser(dock, UserHandle.CURRENT);
Daniel Sandler6396c722013-04-16 20:19:09 -04006131 return;
6132 } catch (ActivityNotFoundException e) {
6133 }
6134 }
6135
Bryce Lee01b0c5f2015-02-05 18:24:04 -08006136 Intent intent;
6137
6138 if (fromHomeKey) {
6139 intent = new Intent(mHomeIntent);
6140 intent.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
6141 } else {
6142 intent = mHomeIntent;
6143 }
6144
Bryce Lee9fc0b6f2015-03-19 21:37:45 +00006145 startActivityAsUser(intent, UserHandle.CURRENT);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006146 }
Craig Mautnereda67292013-04-28 13:50:14 -07006147
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006148 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006149 * goes to the home screen
6150 * @return whether it did anything
6151 */
6152 boolean goHome() {
Bart Sears8b1c27c2015-03-18 23:51:02 +00006153 if (!isUserSetupComplete()) {
6154 Slog.i(TAG, "Not going home because user setup is in progress.");
6155 return false;
6156 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006157 if (false) {
6158 // This code always brings home to the front.
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07006159 try {
6160 ActivityManagerNative.getDefault().stopAppSwitches();
6161 } catch (RemoteException e) {
6162 }
Dianne Hackborn94a679d2009-07-28 17:51:07 -07006163 sendCloseSystemWindows();
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00006164 startDockOrHome(false /*fromHomeKey*/, true /* awakenFromDreams */);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006165 } else {
6166 // This code brings home to the front or, if it is already
6167 // at the front, puts the device to sleep.
6168 try {
Wink Savilled2e6a332010-02-12 12:12:06 -08006169 if (SystemProperties.getInt("persist.sys.uts-test-mode", 0) == 1) {
6170 /// Roll back EndcallBehavior as the cupcake design to pass P1 lab entry.
6171 Log.d(TAG, "UTS-TEST-MODE");
6172 } else {
6173 ActivityManagerNative.getDefault().stopAppSwitches();
6174 sendCloseSystemWindows();
Daniel Sandler6396c722013-04-16 20:19:09 -04006175 Intent dock = createHomeDockIntent();
6176 if (dock != null) {
6177 int result = ActivityManagerNative.getDefault()
6178 .startActivityAsUser(null, null, dock,
6179 dock.resolveTypeIfNeeded(mContext.getContentResolver()),
6180 null, null, 0,
6181 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07006182 null, null, UserHandle.USER_CURRENT);
Daniel Sandler6396c722013-04-16 20:19:09 -04006183 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
6184 return false;
6185 }
6186 }
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006187 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006188 int result = ActivityManagerNative.getDefault()
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006189 .startActivityAsUser(null, null, mHomeIntent,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006190 mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()),
Dianne Hackborna4972e92012-03-14 10:38:05 -07006191 null, null, 0,
6192 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07006193 null, null, UserHandle.USER_CURRENT);
Dianne Hackborna4972e92012-03-14 10:38:05 -07006194 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006195 return false;
6196 }
6197 } catch (RemoteException ex) {
6198 // bummer, the activity manager, which is in this process, is dead
6199 }
6200 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006201 return true;
6202 }
Craig Mautnereda67292013-04-28 13:50:14 -07006203
6204 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07006205 public void setCurrentOrientationLw(int newOrientation) {
6206 synchronized (mLock) {
6207 if (newOrientation != mCurrentAppOrientation) {
6208 mCurrentAppOrientation = newOrientation;
6209 updateOrientationListenerLp();
6210 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006211 }
6212 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006213
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07006214 private void performAuditoryFeedbackForAccessibilityIfNeed() {
6215 if (!isGlobalAccessibilityGestureEnabled()) {
6216 return;
6217 }
6218 AudioManager audioManager = (AudioManager) mContext.getSystemService(
6219 Context.AUDIO_SERVICE);
6220 if (audioManager.isSilentMode()) {
6221 return;
6222 }
6223 Ringtone ringTone = RingtoneManager.getRingtone(mContext,
6224 Settings.System.DEFAULT_NOTIFICATION_URI);
6225 ringTone.setStreamType(AudioManager.STREAM_MUSIC);
6226 ringTone.play();
6227 }
Craig Mautnereda67292013-04-28 13:50:14 -07006228
Bryce Lee584a4452014-10-21 15:55:55 -07006229 private boolean isTheaterModeEnabled() {
6230 return Settings.Global.getInt(mContext.getContentResolver(),
6231 Settings.Global.THEATER_MODE_ON, 0) == 1;
6232 }
6233
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07006234 private boolean isGlobalAccessibilityGestureEnabled() {
6235 return Settings.Global.getInt(mContext.getContentResolver(),
6236 Settings.Global.ENABLE_ACCESSIBILITY_GLOBAL_GESTURE_ENABLED, 0) == 1;
6237 }
6238
Craig Mautnereda67292013-04-28 13:50:14 -07006239 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07006240 public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) {
Svetoslav Ganov96179212012-10-10 14:17:45 -07006241 if (!mVibrator.hasVibrator()) {
6242 return false;
6243 }
Christopher Tate5e08af02012-09-21 17:17:22 -07006244 final boolean hapticsDisabled = Settings.System.getIntForUser(mContext.getContentResolver(),
6245 Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) == 0;
Jeff Brown82379ba2014-07-25 19:03:28 -07006246 if (hapticsDisabled && !always) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006247 return false;
6248 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006249 long[] pattern = null;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006250 switch (effectId) {
6251 case HapticFeedbackConstants.LONG_PRESS:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006252 pattern = mLongPressVibePattern;
6253 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006254 case HapticFeedbackConstants.VIRTUAL_KEY:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006255 pattern = mVirtualKeyVibePattern;
6256 break;
6257 case HapticFeedbackConstants.KEYBOARD_TAP:
6258 pattern = mKeyboardTapVibePattern;
6259 break;
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07006260 case HapticFeedbackConstants.CLOCK_TICK:
6261 pattern = mClockTickVibePattern;
6262 break;
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07006263 case HapticFeedbackConstants.CALENDAR_DATE:
6264 pattern = mCalendarDateVibePattern;
6265 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006266 case HapticFeedbackConstants.SAFE_MODE_DISABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006267 pattern = mSafeModeDisabledVibePattern;
6268 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006269 case HapticFeedbackConstants.SAFE_MODE_ENABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006270 pattern = mSafeModeEnabledVibePattern;
6271 break;
Mady Mellore82067b2015-04-30 09:58:35 -07006272 case HapticFeedbackConstants.STYLUS_BUTTON_PRESS:
6273 pattern = mStylusButtonPressVibePattern;
6274 break;
Amith Yamasanic33cb712010-02-10 15:21:49 -08006275 default:
6276 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006277 }
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006278 int owningUid;
6279 String owningPackage;
6280 if (win != null) {
6281 owningUid = win.getOwningUid();
6282 owningPackage = win.getOwningPackage();
6283 } else {
6284 owningUid = android.os.Process.myUid();
Dianne Hackborn95d78532013-09-11 09:51:14 -07006285 owningPackage = mContext.getOpPackageName();
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006286 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006287 if (pattern.length == 1) {
6288 // One-shot vibration
John Spurlock7b414672014-07-18 13:02:39 -04006289 mVibrator.vibrate(owningUid, owningPackage, pattern[0], VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08006290 } else {
6291 // Pattern vibration
John Spurlock7b414672014-07-18 13:02:39 -04006292 mVibrator.vibrate(owningUid, owningPackage, pattern, -1, VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08006293 }
6294 return true;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006295 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07006296
6297 @Override
6298 public void keepScreenOnStartedLw() {
Daniel Sandler0601eb72011-04-13 01:01:32 -04006299 }
6300
Jeff Brownc38c9be2012-10-04 13:16:19 -07006301 @Override
6302 public void keepScreenOnStoppedLw() {
Jim Millerab954542014-10-10 18:21:49 -07006303 if (isKeyguardShowingAndNotOccluded()) {
Jim Miller25190572013-02-28 17:36:24 -08006304 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006305 }
6306 }
Mike Lockwoodfcb39242009-10-21 23:01:07 -04006307
Dianne Hackborndf89e652011-10-06 22:35:11 -07006308 private int updateSystemUiVisibilityLw() {
Joe Onorato664644d2011-01-23 17:53:23 -08006309 // If there is no window focused, there will be nobody to handle the events
6310 // anyway, so just hang on in whatever state we're in until things settle down.
Adrian Roos53f28ec2014-10-29 17:26:12 +01006311 final WindowState win = mFocusedWindow != null ? mFocusedWindow
6312 : mTopFullscreenOpaqueWindowState;
John Spurlock79da8332013-09-20 12:04:47 -04006313 if (win == null) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006314 return 0;
6315 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01006316 if ((win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 && mHideLockScreen == true) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07006317 // We are updating at a point where the keyguard has gotten
6318 // focus, but we were last in a state where the top window is
6319 // hiding it. This is probably because the keyguard as been
6320 // shown while the top window was displayed, so we want to ignore
6321 // it here because this is just a very transient change and it
6322 // will quickly lose focus once it correctly gets hidden.
6323 return 0;
6324 }
John Spurlock32beb2c2013-03-11 10:16:47 -04006325
John Spurlock1db8b682014-02-18 11:18:59 -05006326 int tmpVisibility = PolicyControl.getSystemUiVisibility(win, null)
Dianne Hackborne26ab702011-10-16 13:21:33 -07006327 & ~mResettingSystemUiFlags
6328 & ~mForceClearedSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04006329 if (mForcingShowNavBar && win.getSurfaceLayer() < mForcingShowNavBarLayer) {
John Spurlockc6d1c602014-01-17 15:22:06 -05006330 tmpVisibility &= ~PolicyControl.adjustClearableFlags(win, View.SYSTEM_UI_CLEARABLE_FLAGS);
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08006331 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01006332 tmpVisibility = updateLightStatusBarLw(tmpVisibility);
John Spurlock79da8332013-09-20 12:04:47 -04006333 final int visibility = updateSystemBarsLw(win, mLastSystemUiFlags, tmpVisibility);
John Spurlockad3e6cb2013-04-30 08:47:43 -04006334 final int diff = visibility ^ mLastSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04006335 final boolean needsMenu = win.getNeedsMenuLw(mTopFullscreenOpaqueWindowState);
Dianne Hackborne0f085d2011-11-30 18:41:15 -08006336 if (diff == 0 && mLastFocusNeedsMenu == needsMenu
John Spurlock79da8332013-09-20 12:04:47 -04006337 && mFocusedApp == win.getAppToken()) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006338 return 0;
6339 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07006340 mLastSystemUiFlags = visibility;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08006341 mLastFocusNeedsMenu = needsMenu;
John Spurlock79da8332013-09-20 12:04:47 -04006342 mFocusedApp = win.getAppToken();
Dianne Hackborndf89e652011-10-06 22:35:11 -07006343 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07006344 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07006345 public void run() {
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006346 try {
6347 IStatusBarService statusbar = getStatusBarService();
6348 if (statusbar != null) {
Adrian Roos53f28ec2014-10-29 17:26:12 +01006349 statusbar.setSystemUiVisibility(visibility, 0xffffffff, win.toString());
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006350 statusbar.topAppWindowChanged(needsMenu);
Joe Onorato664644d2011-01-23 17:53:23 -08006351 }
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006352 } catch (RemoteException e) {
6353 // re-acquire status bar service next time it is needed.
6354 mStatusBarService = null;
Joe Onorato664644d2011-01-23 17:53:23 -08006355 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07006356 }
6357 });
6358 return diff;
Joe Onorato664644d2011-01-23 17:53:23 -08006359 }
6360
Adrian Rooscd3884d2015-02-18 17:25:23 +01006361 private int updateLightStatusBarLw(int vis) {
6362 WindowState statusColorWin = isStatusBarKeyguard() && !mHideLockScreen
6363 ? mStatusBar
6364 : mTopFullscreenOpaqueOrDimmingWindowState;
6365
6366 if (statusColorWin != null) {
6367 if (statusColorWin == mTopFullscreenOpaqueWindowState) {
6368 // If the top fullscreen-or-dimming window is also the top fullscreen, respect
6369 // its light flag.
6370 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6371 vis |= PolicyControl.getSystemUiVisibility(statusColorWin, null)
6372 & View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6373 } else if (statusColorWin != null && statusColorWin.isDimming()) {
6374 // Otherwise if it's dimming, clear the light flag.
6375 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6376 }
6377 }
6378 return vis;
6379 }
6380
John Spurlock79da8332013-09-20 12:04:47 -04006381 private int updateSystemBarsLw(WindowState win, int oldVis, int vis) {
John Spurlockbd957402013-10-03 11:38:39 -04006382 // apply translucent bar vis flags
Jorim Jaggi380ecb82014-03-14 17:25:20 +01006383 WindowState transWin = isStatusBarKeyguard() && !mHideLockScreen
6384 ? mStatusBar
John Spurlockbd957402013-10-03 11:38:39 -04006385 : mTopFullscreenOpaqueWindowState;
6386 vis = mStatusBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
6387 vis = mNavigationBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
6388
John Spurlock27735a42013-08-14 17:57:38 -04006389 // prevent status bar interaction from clearing certain flags
Selim Cinekf83e8242015-05-19 18:08:14 -07006390 int type = win.getAttrs().type;
6391 boolean statusBarHasFocus = type == TYPE_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04006392 if (statusBarHasFocus && !isStatusBarKeyguard()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04006393 int flags = View.SYSTEM_UI_FLAG_FULLSCREEN
6394 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlockcfc359a2013-09-05 10:42:03 -04006395 | View.SYSTEM_UI_FLAG_IMMERSIVE
Jorim Jaggi73fef8d2015-02-16 17:32:28 +01006396 | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
6397 | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04006398 if (mHideLockScreen) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01006399 flags |= View.STATUS_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSLUCENT;
6400 }
John Spurlockbd957402013-10-03 11:38:39 -04006401 vis = (vis & ~flags) | (oldVis & flags);
John Spurlockad3e6cb2013-04-30 08:47:43 -04006402 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04006403
Adrian Roos4fb3ee32014-08-22 19:29:09 +02006404 if (!areTranslucentBarsAllowed() && transWin != mStatusBar) {
Adrian Roosea562512014-05-05 13:33:03 +02006405 vis &= ~(View.NAVIGATION_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSLUCENT
6406 | View.SYSTEM_UI_TRANSPARENT);
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006407 }
6408
John Spurlock27735a42013-08-14 17:57:38 -04006409 // update status bar
John Spurlockf1a36642013-10-12 17:50:42 -04006410 boolean immersiveSticky =
6411 (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
John Spurlock27735a42013-08-14 17:57:38 -04006412 boolean hideStatusBarWM =
John Spurlockbd957402013-10-03 11:38:39 -04006413 mTopFullscreenOpaqueWindowState != null &&
John Spurlockc6d1c602014-01-17 15:22:06 -05006414 (PolicyControl.getWindowFlags(mTopFullscreenOpaqueWindowState, null)
John Spurlock27735a42013-08-14 17:57:38 -04006415 & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0;
6416 boolean hideStatusBarSysui =
6417 (vis & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04006418 boolean hideNavBarSysui =
6419 (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006420
John Spurlock27735a42013-08-14 17:57:38 -04006421 boolean transientStatusBarAllowed =
6422 mStatusBar != null && (
6423 hideStatusBarWM
John Spurlockf1a36642013-10-12 17:50:42 -04006424 || (hideStatusBarSysui && immersiveSticky)
John Spurlock27735a42013-08-14 17:57:38 -04006425 || statusBarHasFocus);
6426
John Spurlockf1a36642013-10-12 17:50:42 -04006427 boolean transientNavBarAllowed =
6428 mNavigationBar != null &&
6429 hideNavBarSysui && immersiveSticky;
6430
Adrian Roosddc8b272015-05-21 16:28:27 -07006431 final long now = SystemClock.uptimeMillis();
6432 final boolean pendingPanic = mPendingPanicGestureUptime != 0
6433 && now - mPendingPanicGestureUptime <= PANIC_GESTURE_EXPIRATION;
6434 if (pendingPanic && hideNavBarSysui && !isStatusBarKeyguard() && mKeyguardDrawComplete) {
6435 // The user performed the panic gesture recently, we're about to hide the bars,
6436 // we're no longer on the Keyguard and the screen is ready. We can now request the bars.
6437 mPendingPanicGestureUptime = 0;
6438 mStatusBarController.showTransient();
6439 mNavigationBarController.showTransient();
6440 }
6441
John Spurlockf25706f2013-11-07 18:02:43 -05006442 boolean denyTransientStatus = mStatusBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04006443 && !transientStatusBarAllowed && hideStatusBarSysui;
John Spurlockf25706f2013-11-07 18:02:43 -05006444 boolean denyTransientNav = mNavigationBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04006445 && !transientNavBarAllowed;
6446 if (denyTransientStatus || denyTransientNav) {
John Spurlock27735a42013-08-14 17:57:38 -04006447 // clear the clearable flags instead
John Spurlockf1a36642013-10-12 17:50:42 -04006448 clearClearableFlagsLw();
tiger_huangc58d7562014-10-23 20:24:19 +08006449 vis &= ~View.SYSTEM_UI_CLEARABLE_FLAGS;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006450 }
John Spurlock27735a42013-08-14 17:57:38 -04006451
Selim Cinekf98702e2015-05-20 22:48:40 -07006452 final boolean immersive = (vis & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
6453 immersiveSticky = (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
6454 final boolean navAllowedHidden = immersive || immersiveSticky;
6455
Selim Cinekd6623612015-05-22 18:56:22 -07006456 if (hideNavBarSysui && !navAllowedHidden && windowTypeToLayerLw(win.getBaseType())
6457 > windowTypeToLayerLw(TYPE_INPUT_CONSUMER)) {
Selim Cinekf98702e2015-05-20 22:48:40 -07006458 // We can't hide the navbar from this window otherwise the input consumer would not get
6459 // the input events.
6460 vis = (vis & ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
6461 }
6462
John Spurlock27735a42013-08-14 17:57:38 -04006463 vis = mStatusBarController.updateVisibilityLw(transientStatusBarAllowed, oldVis, vis);
6464
6465 // update navigation bar
John Spurlockf1a36642013-10-12 17:50:42 -04006466 boolean oldImmersiveMode = isImmersiveMode(oldVis);
6467 boolean newImmersiveMode = isImmersiveMode(vis);
6468 if (win != null && oldImmersiveMode != newImmersiveMode) {
John Spurlock79da8332013-09-20 12:04:47 -04006469 final String pkg = win.getOwningPackage();
Maurice Lam99c6e072014-04-28 18:24:28 -07006470 mImmersiveModeConfirmation.immersiveModeChanged(pkg, newImmersiveMode,
6471 isUserSetupComplete());
John Spurlock34e13d92013-08-10 06:52:28 -04006472 }
John Spurlock27735a42013-08-14 17:57:38 -04006473
John Spurlockf1a36642013-10-12 17:50:42 -04006474 vis = mNavigationBarController.updateVisibilityLw(transientNavBarAllowed, oldVis, vis);
6475
John Spurlocke1f366f2013-08-05 12:22:40 -04006476 return vis;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006477 }
6478
John Spurlockf1a36642013-10-12 17:50:42 -04006479 private void clearClearableFlagsLw() {
6480 int newVal = mResettingSystemUiFlags | View.SYSTEM_UI_CLEARABLE_FLAGS;
6481 if (newVal != mResettingSystemUiFlags) {
6482 mResettingSystemUiFlags = newVal;
6483 mWindowManagerFuncs.reevaluateStatusBarVisibility();
6484 }
6485 }
6486
6487 private boolean isImmersiveMode(int vis) {
6488 final int flags = View.SYSTEM_UI_FLAG_IMMERSIVE | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
John Spurlock34e13d92013-08-10 06:52:28 -04006489 return mNavigationBar != null
6490 && (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0
Daniel Sandler900ece52013-10-18 15:53:27 -04006491 && (vis & flags) != 0
6492 && canHideNavigationBar();
John Spurlock34e13d92013-08-10 06:52:28 -04006493 }
6494
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006495 /**
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04006496 * @return whether the navigation or status bar can be made translucent
6497 *
6498 * This should return true unless touch exploration is not enabled or
6499 * R.boolean.config_enableTranslucentDecor is false.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006500 */
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04006501 private boolean areTranslucentBarsAllowed() {
Svetoslav8e3feb12014-02-24 13:46:47 -08006502 return mTranslucentDecorEnabled
6503 && !mAccessibilityManager.isTouchExplorationEnabled();
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006504 }
6505
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04006506 // Use this instead of checking config_showNavigationBar so that it can be consistently
6507 // overridden by qemu.hw.mainkeys in the emulator.
Craig Mautnereda67292013-04-28 13:50:14 -07006508 @Override
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04006509 public boolean hasNavigationBar() {
6510 return mHasNavigationBar;
6511 }
6512
satok1bc0a492012-04-25 22:47:12 +09006513 @Override
6514 public void setLastInputMethodWindowLw(WindowState ime, WindowState target) {
6515 mLastInputMethodWindow = ime;
6516 mLastInputMethodTargetWindow = target;
6517 }
6518
Craig Mautnerf1b67412012-09-19 13:18:29 -07006519 @Override
Satoshi Kataoka658c7b82013-10-10 17:03:51 +09006520 public int getInputMethodWindowVisibleHeightLw() {
6521 return mDockBottom - mCurBottom;
6522 }
6523
6524 @Override
Craig Mautnerf1b67412012-09-19 13:18:29 -07006525 public void setCurrentUserLw(int newUserId) {
Craig Mautnerd625ab22013-09-06 13:40:31 -07006526 mCurrentUserId = newUserId;
Jim Miller5ecd8112013-01-09 18:50:26 -08006527 if (mKeyguardDelegate != null) {
6528 mKeyguardDelegate.setCurrentUser(newUserId);
Craig Mautnerf1b67412012-09-19 13:18:29 -07006529 }
John Spurlock13451a22012-09-28 14:40:41 -04006530 if (mStatusBarService != null) {
6531 try {
6532 mStatusBarService.setCurrentUser(newUserId);
6533 } catch (RemoteException e) {
6534 // oh well
6535 }
6536 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006537 setLastInputMethodWindowLw(null, null);
Craig Mautnerf1b67412012-09-19 13:18:29 -07006538 }
6539
6540 @Override
Svetoslav Ganov545252f2012-12-10 18:29:24 -08006541 public boolean canMagnifyWindow(int windowType) {
6542 switch (windowType) {
6543 case WindowManager.LayoutParams.TYPE_INPUT_METHOD:
6544 case WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG:
6545 case WindowManager.LayoutParams.TYPE_NAVIGATION_BAR:
6546 case WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY: {
6547 return false;
6548 }
6549 }
6550 return true;
6551 }
6552
6553 @Override
6554 public boolean isTopLevelWindow(int windowType) {
6555 if (windowType >= WindowManager.LayoutParams.FIRST_SUB_WINDOW
6556 && windowType <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
6557 return (windowType == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG);
6558 }
6559 return true;
6560 }
6561
Jim Miller4eeb4f62012-11-08 00:04:29 -08006562 @Override
Jeff Brownd7a04de2012-06-17 14:17:52 -07006563 public void dump(String prefix, PrintWriter pw, String[] args) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006564 pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07006565 pw.print(" mSystemReady="); pw.print(mSystemReady);
6566 pw.print(" mSystemBooted="); pw.println(mSystemBooted);
Jeff Brown2e7760e2012-04-11 15:14:55 -07006567 pw.print(prefix); pw.print("mLidState="); pw.print(mLidState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006568 pw.print(" mLidOpenRotation="); pw.print(mLidOpenRotation);
Michael Wright3818c922014-09-02 13:59:07 -07006569 pw.print(" mCameraLensCoverState="); pw.print(mCameraLensCoverState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006570 pw.print(" mHdmiPlugged="); pw.println(mHdmiPlugged);
Dianne Hackborne26ab702011-10-16 13:21:33 -07006571 if (mLastSystemUiFlags != 0 || mResettingSystemUiFlags != 0
6572 || mForceClearedSystemUiFlags != 0) {
6573 pw.print(prefix); pw.print("mLastSystemUiFlags=0x");
6574 pw.print(Integer.toHexString(mLastSystemUiFlags));
6575 pw.print(" mResettingSystemUiFlags=0x");
6576 pw.print(Integer.toHexString(mResettingSystemUiFlags));
6577 pw.print(" mForceClearedSystemUiFlags=0x");
6578 pw.println(Integer.toHexString(mForceClearedSystemUiFlags));
Dianne Hackborndf89e652011-10-06 22:35:11 -07006579 }
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08006580 if (mLastFocusNeedsMenu) {
6581 pw.print(prefix); pw.print("mLastFocusNeedsMenu=");
6582 pw.println(mLastFocusNeedsMenu);
6583 }
Jeff Browna20dda42014-05-27 20:57:24 -07006584 pw.print(prefix); pw.print("mWakeGestureEnabledSetting=");
6585 pw.println(mWakeGestureEnabledSetting);
6586
Jeff Brownbcdfc622014-03-06 19:13:04 -08006587 pw.print(prefix); pw.print("mSupportAutoRotation="); pw.println(mSupportAutoRotation);
Daniel Sandler6396c722013-04-16 20:19:09 -04006588 pw.print(prefix); pw.print("mUiMode="); pw.print(mUiMode);
6589 pw.print(" mDockMode="); pw.print(mDockMode);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006590 pw.print(" mCarDockRotation="); pw.print(mCarDockRotation);
6591 pw.print(" mDeskDockRotation="); pw.println(mDeskDockRotation);
6592 pw.print(prefix); pw.print("mUserRotationMode="); pw.print(mUserRotationMode);
6593 pw.print(" mUserRotation="); pw.print(mUserRotation);
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05006594 pw.print(" mAllowAllRotations="); pw.println(mAllowAllRotations);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07006595 pw.print(prefix); pw.print("mCurrentAppOrientation="); pw.println(mCurrentAppOrientation);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006596 pw.print(prefix); pw.print("mCarDockEnablesAccelerometer=");
6597 pw.print(mCarDockEnablesAccelerometer);
6598 pw.print(" mDeskDockEnablesAccelerometer=");
6599 pw.println(mDeskDockEnablesAccelerometer);
6600 pw.print(prefix); pw.print("mLidKeyboardAccessibility=");
6601 pw.print(mLidKeyboardAccessibility);
6602 pw.print(" mLidNavigationAccessibility="); pw.print(mLidNavigationAccessibility);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07006603 pw.print(" mLidControlsSleep="); pw.println(mLidControlsSleep);
Jeff Brown6d8fd272014-05-20 21:24:38 -07006604 pw.print(prefix);
6605 pw.print("mShortPressOnPowerBehavior="); pw.print(mShortPressOnPowerBehavior);
6606 pw.print(" mLongPressOnPowerBehavior="); pw.println(mLongPressOnPowerBehavior);
Jeff Brown13f00f02014-10-31 14:45:50 -07006607 pw.print(prefix);
6608 pw.print("mDoublePressOnPowerBehavior="); pw.print(mDoublePressOnPowerBehavior);
6609 pw.print(" mTriplePressOnPowerBehavior="); pw.println(mTriplePressOnPowerBehavior);
Jeff Brown6d8fd272014-05-20 21:24:38 -07006610 pw.print(prefix); pw.print("mHasSoftInput="); pw.println(mHasSoftInput);
Jeff Brown3ee549c2014-09-22 20:14:39 -07006611 pw.print(prefix); pw.print("mAwake="); pw.println(mAwake);
6612 pw.print(prefix); pw.print("mScreenOnEarly="); pw.print(mScreenOnEarly);
6613 pw.print(" mScreenOnFully="); pw.println(mScreenOnFully);
6614 pw.print(prefix); pw.print("mKeyguardDrawComplete="); pw.print(mKeyguardDrawComplete);
6615 pw.print(" mWindowManagerDrawComplete="); pw.println(mWindowManagerDrawComplete);
6616 pw.print(prefix); pw.print("mOrientationSensorEnabled=");
6617 pw.println(mOrientationSensorEnabled);
Dianne Hackbornc652de82013-02-15 16:32:56 -08006618 pw.print(prefix); pw.print("mOverscanScreen=("); pw.print(mOverscanScreenLeft);
6619 pw.print(","); pw.print(mOverscanScreenTop);
6620 pw.print(") "); pw.print(mOverscanScreenWidth);
6621 pw.print("x"); pw.println(mOverscanScreenHeight);
6622 if (mOverscanLeft != 0 || mOverscanTop != 0
6623 || mOverscanRight != 0 || mOverscanBottom != 0) {
6624 pw.print(prefix); pw.print("mOverscan left="); pw.print(mOverscanLeft);
6625 pw.print(" top="); pw.print(mOverscanTop);
6626 pw.print(" right="); pw.print(mOverscanRight);
6627 pw.print(" bottom="); pw.println(mOverscanBottom);
6628 }
Dianne Hackborn313440842013-02-19 19:22:59 -08006629 pw.print(prefix); pw.print("mRestrictedOverscanScreen=(");
6630 pw.print(mRestrictedOverscanScreenLeft);
6631 pw.print(","); pw.print(mRestrictedOverscanScreenTop);
6632 pw.print(") "); pw.print(mRestrictedOverscanScreenWidth);
6633 pw.print("x"); pw.println(mRestrictedOverscanScreenHeight);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006634 pw.print(prefix); pw.print("mUnrestrictedScreen=("); pw.print(mUnrestrictedScreenLeft);
6635 pw.print(","); pw.print(mUnrestrictedScreenTop);
6636 pw.print(") "); pw.print(mUnrestrictedScreenWidth);
6637 pw.print("x"); pw.println(mUnrestrictedScreenHeight);
6638 pw.print(prefix); pw.print("mRestrictedScreen=("); pw.print(mRestrictedScreenLeft);
6639 pw.print(","); pw.print(mRestrictedScreenTop);
6640 pw.print(") "); pw.print(mRestrictedScreenWidth);
6641 pw.print("x"); pw.println(mRestrictedScreenHeight);
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07006642 pw.print(prefix); pw.print("mStableFullscreen=("); pw.print(mStableFullscreenLeft);
6643 pw.print(","); pw.print(mStableFullscreenTop);
6644 pw.print(")-("); pw.print(mStableFullscreenRight);
6645 pw.print(","); pw.print(mStableFullscreenBottom); pw.println(")");
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07006646 pw.print(prefix); pw.print("mStable=("); pw.print(mStableLeft);
6647 pw.print(","); pw.print(mStableTop);
6648 pw.print(")-("); pw.print(mStableRight);
6649 pw.print(","); pw.print(mStableBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07006650 pw.print(prefix); pw.print("mSystem=("); pw.print(mSystemLeft);
6651 pw.print(","); pw.print(mSystemTop);
6652 pw.print(")-("); pw.print(mSystemRight);
6653 pw.print(","); pw.print(mSystemBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006654 pw.print(prefix); pw.print("mCur=("); pw.print(mCurLeft);
6655 pw.print(","); pw.print(mCurTop);
6656 pw.print(")-("); pw.print(mCurRight);
6657 pw.print(","); pw.print(mCurBottom); pw.println(")");
6658 pw.print(prefix); pw.print("mContent=("); pw.print(mContentLeft);
6659 pw.print(","); pw.print(mContentTop);
6660 pw.print(")-("); pw.print(mContentRight);
6661 pw.print(","); pw.print(mContentBottom); pw.println(")");
Dianne Hackborne30e02f2014-05-27 18:24:45 -07006662 pw.print(prefix); pw.print("mVoiceContent=("); pw.print(mVoiceContentLeft);
6663 pw.print(","); pw.print(mVoiceContentTop);
6664 pw.print(")-("); pw.print(mVoiceContentRight);
6665 pw.print(","); pw.print(mVoiceContentBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006666 pw.print(prefix); pw.print("mDock=("); pw.print(mDockLeft);
6667 pw.print(","); pw.print(mDockTop);
6668 pw.print(")-("); pw.print(mDockRight);
6669 pw.print(","); pw.print(mDockBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07006670 pw.print(prefix); pw.print("mDockLayer="); pw.print(mDockLayer);
6671 pw.print(" mStatusBarLayer="); pw.println(mStatusBarLayer);
Dianne Hackborn7ad44382012-10-18 17:46:00 -07006672 pw.print(prefix); pw.print("mShowingLockscreen="); pw.print(mShowingLockscreen);
6673 pw.print(" mShowingDream="); pw.print(mShowingDream);
Jeff Brown061ea992015-04-17 19:55:47 -07006674 pw.print(" mDreamingLockscreen="); pw.print(mDreamingLockscreen);
6675 pw.print(" mDreamingSleepToken="); pw.println(mDreamingSleepToken);
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006676 if (mLastInputMethodWindow != null) {
6677 pw.print(prefix); pw.print("mLastInputMethodWindow=");
6678 pw.println(mLastInputMethodWindow);
6679 }
6680 if (mLastInputMethodTargetWindow != null) {
6681 pw.print(prefix); pw.print("mLastInputMethodTargetWindow=");
6682 pw.println(mLastInputMethodTargetWindow);
6683 }
6684 if (mStatusBar != null) {
6685 pw.print(prefix); pw.print("mStatusBar=");
Dianne Hackbornae6688b2015-02-11 17:02:41 -08006686 pw.print(mStatusBar); pw.print(" isStatusBarKeyguard=");
6687 pw.println(isStatusBarKeyguard());
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006688 }
6689 if (mNavigationBar != null) {
6690 pw.print(prefix); pw.print("mNavigationBar=");
6691 pw.println(mNavigationBar);
6692 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006693 if (mFocusedWindow != null) {
6694 pw.print(prefix); pw.print("mFocusedWindow=");
6695 pw.println(mFocusedWindow);
6696 }
6697 if (mFocusedApp != null) {
6698 pw.print(prefix); pw.print("mFocusedApp=");
6699 pw.println(mFocusedApp);
6700 }
6701 if (mWinDismissingKeyguard != null) {
6702 pw.print(prefix); pw.print("mWinDismissingKeyguard=");
6703 pw.println(mWinDismissingKeyguard);
6704 }
6705 if (mTopFullscreenOpaqueWindowState != null) {
6706 pw.print(prefix); pw.print("mTopFullscreenOpaqueWindowState=");
6707 pw.println(mTopFullscreenOpaqueWindowState);
6708 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01006709 if (mTopFullscreenOpaqueOrDimmingWindowState != null) {
6710 pw.print(prefix); pw.print("mTopFullscreenOpaqueOrDimmingWindowState=");
6711 pw.println(mTopFullscreenOpaqueOrDimmingWindowState);
6712 }
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08006713 if (mForcingShowNavBar) {
6714 pw.print(prefix); pw.print("mForcingShowNavBar=");
6715 pw.println(mForcingShowNavBar); pw.print( "mForcingShowNavBarLayer=");
6716 pw.println(mForcingShowNavBarLayer);
6717 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07006718 pw.print(prefix); pw.print("mTopIsFullscreen="); pw.print(mTopIsFullscreen);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006719 pw.print(" mHideLockScreen="); pw.println(mHideLockScreen);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07006720 pw.print(prefix); pw.print("mForceStatusBar="); pw.print(mForceStatusBar);
6721 pw.print(" mForceStatusBarFromKeyguard=");
6722 pw.println(mForceStatusBarFromKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006723 pw.print(prefix); pw.print("mDismissKeyguard="); pw.print(mDismissKeyguard);
Craig Mautnerad09bcc2012-10-08 13:33:11 -07006724 pw.print(" mWinDismissingKeyguard="); pw.print(mWinDismissingKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006725 pw.print(" mHomePressed="); pw.println(mHomePressed);
6726 pw.print(prefix); pw.print("mAllowLockscreenWhenOn="); pw.print(mAllowLockscreenWhenOn);
6727 pw.print(" mLockScreenTimeout="); pw.print(mLockScreenTimeout);
6728 pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive);
6729 pw.print(prefix); pw.print("mEndcallBehavior="); pw.print(mEndcallBehavior);
6730 pw.print(" mIncallPowerBehavior="); pw.print(mIncallPowerBehavior);
6731 pw.print(" mLongPressOnHomeBehavior="); pw.println(mLongPressOnHomeBehavior);
6732 pw.print(prefix); pw.print("mLandscapeRotation="); pw.print(mLandscapeRotation);
6733 pw.print(" mSeascapeRotation="); pw.println(mSeascapeRotation);
6734 pw.print(prefix); pw.print("mPortraitRotation="); pw.print(mPortraitRotation);
6735 pw.print(" mUpsideDownRotation="); pw.println(mUpsideDownRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07006736 pw.print(prefix); pw.print("mDemoHdmiRotation="); pw.print(mDemoHdmiRotation);
6737 pw.print(" mDemoHdmiRotationLock="); pw.println(mDemoHdmiRotationLock);
6738 pw.print(prefix); pw.print("mUndockedHdmiRotation="); pw.println(mUndockedHdmiRotation);
Jeff Brown600f0032014-05-22 17:06:00 -07006739
Tim Kilbournd7c0c2e2014-05-29 16:08:10 -07006740 mGlobalKeyManager.dump(prefix, pw);
John Spurlock27735a42013-08-14 17:57:38 -04006741 mStatusBarController.dump(pw, prefix);
6742 mNavigationBarController.dump(pw, prefix);
John Spurlockc6d1c602014-01-17 15:22:06 -05006743 PolicyControl.dump(prefix, pw);
Jeff Brown600f0032014-05-22 17:06:00 -07006744
Jeff Browna20dda42014-05-27 20:57:24 -07006745 if (mWakeGestureListener != null) {
6746 mWakeGestureListener.dump(pw, prefix);
6747 }
Jeff Brown600f0032014-05-22 17:06:00 -07006748 if (mOrientationListener != null) {
6749 mOrientationListener.dump(pw, prefix);
6750 }
Filip Gruszczynskicfb31852015-02-25 21:47:12 +00006751 if (mBurnInProtectionHelper != null) {
6752 mBurnInProtectionHelper.dump(prefix, pw);
6753 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006754 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006755}