blob: 34f377df43017078381c6b3376762ec59401c9cf [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
Craig Mautnerc9457fa2014-06-06 14:27:48 -0700500 /** The window that is currently showing "over" the keyguard. If there is an app window
501 * belonging to another app on top of this the keyguard shows. If there is a fullscreen
502 * app window under this, still dismiss the keyguard but don't show the app underneath. Show
503 * the wallpaper. */
504 private WindowState mWinShowWhenLocked;
505
Dianne Hackborn7ad44382012-10-18 17:46:00 -0700506 boolean mShowingLockscreen;
507 boolean mShowingDream;
508 boolean mDreamingLockscreen;
Jeff Brown061ea992015-04-17 19:55:47 -0700509 boolean mDreamingSleepTokenNeeded;
510 SleepToken mDreamingSleepToken;
Jim Millerab954542014-10-10 18:21:49 -0700511 boolean mKeyguardSecure;
512 boolean mKeyguardSecureIncludingHidden;
513 volatile boolean mKeyguardOccluded;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800514 boolean mHomePressed;
Jeff Browncaca8812013-05-09 13:34:33 -0700515 boolean mHomeConsumed;
516 boolean mHomeDoubleTapPending;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800517 Intent mHomeIntent;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700518 Intent mCarDockIntent;
519 Intent mDeskDockIntent;
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700520 boolean mSearchKeyShortcutPending;
521 boolean mConsumeSearchKeyUp;
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700522 boolean mAssistKeyLongPressed;
Michael Wright6a62e552014-06-03 19:19:48 -0700523 boolean mPendingMetaAction;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800524
Mike Lockwood28569302010-01-28 11:54:40 -0500525 // support for activating the lock screen while the screen is on
526 boolean mAllowLockscreenWhenOn;
527 int mLockScreenTimeout;
528 boolean mLockScreenTimerActive;
529
David Brownbaf8d092010-03-08 21:52:59 -0800530 // Behavior of ENDCALL Button. (See Settings.System.END_BUTTON_BEHAVIOR.)
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800531 int mEndcallBehavior;
David Brownbaf8d092010-03-08 21:52:59 -0800532
533 // Behavior of POWER button while in-call and screen on.
534 // (See Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR.)
535 int mIncallPowerBehavior;
536
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700537 Display mDisplay;
538
Dianne Hackborn9d132642011-04-21 17:26:39 -0700539 int mLandscapeRotation = 0; // default landscape rotation
540 int mSeascapeRotation = 0; // "other" landscape rotation, 180 degrees from mLandscapeRotation
541 int mPortraitRotation = 0; // default portrait rotation
542 int mUpsideDownRotation = 0; // "other" portrait rotation
Mitsuru Oshima831d0d92009-06-16 18:27:18 -0700543
Dianne Hackbornc652de82013-02-15 16:32:56 -0800544 int mOverscanLeft = 0;
545 int mOverscanTop = 0;
546 int mOverscanRight = 0;
547 int mOverscanBottom = 0;
548
Joe Onorato46b0d682010-11-22 17:37:27 -0800549 // What we do when the user long presses on home
Jeff Browncaca8812013-05-09 13:34:33 -0700550 private int mLongPressOnHomeBehavior;
551
552 // What we do when the user double-taps on home
553 private int mDoubleTapOnHomeBehavior;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800554
Bryce Lee584a4452014-10-21 15:55:55 -0700555 // Allowed theater mode wake actions
556 private boolean mAllowTheaterModeWakeFromKey;
557 private boolean mAllowTheaterModeWakeFromPowerKey;
558 private boolean mAllowTheaterModeWakeFromMotion;
Bryce Lee812d7022014-11-10 13:33:28 -0800559 private boolean mAllowTheaterModeWakeFromMotionWhenNotDreaming;
Bryce Lee584a4452014-10-21 15:55:55 -0700560 private boolean mAllowTheaterModeWakeFromCameraLens;
561 private boolean mAllowTheaterModeWakeFromLidSwitch;
562 private boolean mAllowTheaterModeWakeFromWakeGesture;
563
Bryce Leed3b28402015-03-09 15:49:13 +0000564 // Whether to support long press from power button in non-interactive mode
565 private boolean mSupportLongPressPowerWhenNonInteractive;
566
Bryce Lee55e846d2014-11-04 12:43:44 -0800567 // Whether to go to sleep entering theater mode from power button
568 private boolean mGoToSleepOnButtonPressTheaterMode;
569
Winson Chung9112ec32011-06-27 13:15:32 -0700570 // Screenshot trigger states
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700571 // Time to volume and power must be pressed within this interval of each other.
572 private static final long SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS = 150;
Winson Chung1cea2f32012-10-08 20:42:01 -0700573 // Increase the chord delay when taking a screenshot from the keyguard
574 private static final float KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER = 2.5f;
Christopher Tatee90585f2012-03-05 18:56:25 -0800575 private boolean mScreenshotChordEnabled;
Jeff Brown13f00f02014-10-31 14:45:50 -0700576 private boolean mScreenshotChordVolumeDownKeyTriggered;
577 private long mScreenshotChordVolumeDownKeyTime;
578 private boolean mScreenshotChordVolumeDownKeyConsumed;
579 private boolean mScreenshotChordVolumeUpKeyTriggered;
580 private boolean mScreenshotChordPowerKeyTriggered;
581 private long mScreenshotChordPowerKeyTime;
Winson Chung9112ec32011-06-27 13:15:32 -0700582
Michael Wrightb854e242013-02-05 17:54:02 -0800583 /* The number of steps between min and max brightness */
584 private static final int BRIGHTNESS_STEPS = 10;
585
Christopher Tate5e08af02012-09-21 17:17:22 -0700586 SettingsObserver mSettingsObserver;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800587 ShortcutManager mShortcutManager;
588 PowerManager.WakeLock mBroadcastWakeLock;
Jeff Brown13f00f02014-10-31 14:45:50 -0700589 PowerManager.WakeLock mPowerKeyWakeLock;
Jeff Brown40013652012-05-16 21:22:36 -0700590 boolean mHavePendingMediaKeyRepeatWithWakeLock;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800591
Craig Mautnerd625ab22013-09-06 13:40:31 -0700592 private int mCurrentUserId;
593
Justin Kohd378ad72013-04-01 12:18:26 -0700594 // Maps global key codes to the components that will handle them.
595 private GlobalKeyManager mGlobalKeyManager;
596
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700597 // Fallback actions by key code.
598 private final SparseArray<KeyCharacterMap.FallbackAction> mFallbackActions =
599 new SparseArray<KeyCharacterMap.FallbackAction>();
Jeff Brown49ed71d2010-12-06 17:13:33 -0800600
Jorim Jaggi76a16232014-08-08 17:00:47 +0200601 private final LogDecelerateInterpolator mLogDecelerateInterpolator
602 = new LogDecelerateInterpolator(100, 0);
603
Jeff Brown70825162012-03-28 17:27:48 -0700604 private static final int MSG_ENABLE_POINTER_LOCATION = 1;
605 private static final int MSG_DISABLE_POINTER_LOCATION = 2;
Jeff Brown40013652012-05-16 21:22:36 -0700606 private static final int MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK = 3;
607 private static final int MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK = 4;
Craig Mautner8a0da012014-05-31 15:13:37 -0700608 private static final int MSG_KEYGUARD_DRAWN_COMPLETE = 5;
609 private static final int MSG_KEYGUARD_DRAWN_TIMEOUT = 6;
610 private static final int MSG_WINDOW_MANAGER_DRAWN_COMPLETE = 7;
Craig Mautner84984fa2014-06-19 11:19:20 -0700611 private static final int MSG_DISPATCH_SHOW_RECENTS = 9;
Alan Viverettee34560b22014-07-10 14:50:06 -0700612 private static final int MSG_DISPATCH_SHOW_GLOBAL_ACTIONS = 10;
Craig Mautnera631d492014-08-05 15:16:01 -0700613 private static final int MSG_HIDE_BOOT_MESSAGE = 11;
Michael Wright869a67c2014-08-26 19:33:06 -0700614 private static final int MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK = 12;
Jeff Brown13f00f02014-10-31 14:45:50 -0700615 private static final int MSG_POWER_DELAYED_PRESS = 13;
616 private static final int MSG_POWER_LONG_PRESS = 14;
Jeff Brown061ea992015-04-17 19:55:47 -0700617 private static final int MSG_UPDATE_DREAMING_SLEEP_TOKEN = 15;
Jeff Brown70825162012-03-28 17:27:48 -0700618
619 private class PolicyHandler extends Handler {
620 @Override
621 public void handleMessage(Message msg) {
622 switch (msg.what) {
623 case MSG_ENABLE_POINTER_LOCATION:
624 enablePointerLocation();
625 break;
626 case MSG_DISABLE_POINTER_LOCATION:
627 disablePointerLocation();
628 break;
Jeff Brown40013652012-05-16 21:22:36 -0700629 case MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK:
630 dispatchMediaKeyWithWakeLock((KeyEvent)msg.obj);
631 break;
632 case MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK:
633 dispatchMediaKeyRepeatWithWakeLock((KeyEvent)msg.obj);
634 break;
Craig Mautner84984fa2014-06-19 11:19:20 -0700635 case MSG_DISPATCH_SHOW_RECENTS:
636 showRecentApps(false);
637 break;
Alan Viverettee34560b22014-07-10 14:50:06 -0700638 case MSG_DISPATCH_SHOW_GLOBAL_ACTIONS:
639 showGlobalActionsInternal();
640 break;
Craig Mautner8a0da012014-05-31 15:13:37 -0700641 case MSG_KEYGUARD_DRAWN_COMPLETE:
642 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mKeyguardDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700643 finishKeyguardDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700644 break;
645 case MSG_KEYGUARD_DRAWN_TIMEOUT:
646 Slog.w(TAG, "Keyguard drawn timeout. Setting mKeyguardDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700647 finishKeyguardDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700648 break;
649 case MSG_WINDOW_MANAGER_DRAWN_COMPLETE:
650 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mWindowManagerDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700651 finishWindowsDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700652 break;
Craig Mautnera631d492014-08-05 15:16:01 -0700653 case MSG_HIDE_BOOT_MESSAGE:
654 handleHideBootMessage();
655 break;
Michael Wright869a67c2014-08-26 19:33:06 -0700656 case MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK:
657 launchVoiceAssistWithWakeLock(msg.arg1 != 0);
658 break;
Jeff Brown13f00f02014-10-31 14:45:50 -0700659 case MSG_POWER_DELAYED_PRESS:
660 powerPress((Long)msg.obj, msg.arg1 != 0, msg.arg2);
661 finishPowerKeyPress();
662 break;
663 case MSG_POWER_LONG_PRESS:
664 powerLongPress();
665 break;
Jeff Brown061ea992015-04-17 19:55:47 -0700666 case MSG_UPDATE_DREAMING_SLEEP_TOKEN:
667 updateDreamingSleepToken(msg.arg1 != 0);
668 break;
Jeff Brown70825162012-03-28 17:27:48 -0700669 }
670 }
671 }
672
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800673 private UEventObserver mHDMIObserver = new UEventObserver() {
674 @Override
675 public void onUEvent(UEventObserver.UEvent event) {
676 setHdmiPlugged("1".equals(event.get("SWITCH_STATE")));
677 }
678 };
679
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800680 class SettingsObserver extends ContentObserver {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800681 SettingsObserver(Handler handler) {
682 super(handler);
683 }
David Brownbaf8d092010-03-08 21:52:59 -0800684
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800685 void observe() {
Christopher Tate5e08af02012-09-21 17:17:22 -0700686 // Observe all users' changes
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800687 ContentResolver resolver = mContext.getContentResolver();
688 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700689 Settings.System.END_BUTTON_BEHAVIOR), false, this,
690 UserHandle.USER_ALL);
David Brownbaf8d092010-03-08 21:52:59 -0800691 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700692 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR), false, this,
693 UserHandle.USER_ALL);
Jeff Browna20dda42014-05-27 20:57:24 -0700694 resolver.registerContentObserver(Settings.Secure.getUriFor(
695 Settings.Secure.WAKE_GESTURE_ENABLED), false, this,
696 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800697 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700698 Settings.System.ACCELEROMETER_ROTATION), false, this,
699 UserHandle.USER_ALL);
Mike Lockwood28569302010-01-28 11:54:40 -0500700 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700701 Settings.System.USER_ROTATION), false, this,
702 UserHandle.USER_ALL);
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400703 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700704 Settings.System.SCREEN_OFF_TIMEOUT), false, this,
705 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800706 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700707 Settings.System.POINTER_LOCATION), false, this,
708 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800709 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700710 Settings.Secure.DEFAULT_INPUT_METHOD), false, this,
711 UserHandle.USER_ALL);
John Spurlockd9b70bd2014-02-06 17:02:44 -0500712 resolver.registerContentObserver(Settings.Secure.getUriFor(
John Spurlockf1a36642013-10-12 17:50:42 -0400713 Settings.Secure.IMMERSIVE_MODE_CONFIRMATIONS), false, this,
Christopher Tate5e08af02012-09-21 17:17:22 -0700714 UserHandle.USER_ALL);
John Spurlockc6d1c602014-01-17 15:22:06 -0500715 resolver.registerContentObserver(Settings.Global.getUriFor(
716 Settings.Global.POLICY_CONTROL), false, this,
717 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800718 updateSettings();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800719 }
720
721 @Override public void onChange(boolean selfChange) {
Dianne Hackbornc777e072010-02-12 13:07:59 -0800722 updateSettings();
Jeff Brown01a98dd2011-09-20 15:08:29 -0700723 updateRotation(false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800724 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800725 }
Craig Mautner967212c2013-04-13 21:10:58 -0700726
Jeff Browna20dda42014-05-27 20:57:24 -0700727 class MyWakeGestureListener extends WakeGestureListener {
728 MyWakeGestureListener(Context context, Handler handler) {
729 super(context, handler);
730 }
731
732 @Override
733 public void onWakeUp() {
734 synchronized (mLock) {
735 if (shouldEnableWakeGestureLp()) {
Jeff Browne07b94b2014-06-18 15:56:27 -0700736 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
Bryce Lee584a4452014-10-21 15:55:55 -0700737 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromWakeGesture);
Jeff Browna20dda42014-05-27 20:57:24 -0700738 }
739 }
740 }
741 }
742
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800743 class MyOrientationListener extends WindowOrientationListener {
Craig Mautnereee29c42013-01-17 14:44:34 -0800744 MyOrientationListener(Context context, Handler handler) {
745 super(context, handler);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800746 }
Craig Mautner967212c2013-04-13 21:10:58 -0700747
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800748 @Override
Jeff Brownc0347aa2011-09-23 17:26:09 -0700749 public void onProposedRotationChanged(int rotation) {
Craig Mautnereda67292013-04-28 13:50:14 -0700750 if (localLOGV) Slog.v(TAG, "onProposedRotationChanged, rotation=" + rotation);
Jeff Brown01a98dd2011-09-20 15:08:29 -0700751 updateRotation(false);
752 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800753 }
754 MyOrientationListener mOrientationListener;
755
Jorim Jaggi24bec7c2015-02-04 12:40:14 +0100756 private final StatusBarController mStatusBarController = new StatusBarController();
John Spurlock5b9145b2013-08-20 15:13:47 -0400757
John Spurlock27735a42013-08-14 17:57:38 -0400758 private final BarController mNavigationBarController = new BarController("NavigationBar",
John Spurlock5b9145b2013-08-20 15:13:47 -0400759 View.NAVIGATION_BAR_TRANSIENT,
760 View.NAVIGATION_BAR_UNHIDE,
John Spurlockbd957402013-10-03 11:38:39 -0400761 View.NAVIGATION_BAR_TRANSLUCENT,
762 StatusBarManager.WINDOW_NAVIGATION_BAR,
763 WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
John Spurlock5b9145b2013-08-20 15:13:47 -0400764
John Spurlockf1a36642013-10-12 17:50:42 -0400765 private ImmersiveModeConfirmation mImmersiveModeConfirmation;
John Spurlock32beb2c2013-03-11 10:16:47 -0400766
Craig Mautner037aa8d2013-06-07 10:35:44 -0700767 private SystemGesturesPointerEventListener mSystemGestures;
John Spurlock32beb2c2013-03-11 10:16:47 -0400768
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700769 IStatusBarService getStatusBarService() {
770 synchronized (mServiceAquireLock) {
771 if (mStatusBarService == null) {
772 mStatusBarService = IStatusBarService.Stub.asInterface(
773 ServiceManager.getService("statusbar"));
774 }
775 return mStatusBarService;
776 }
777 }
778
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700779 /*
780 * We always let the sensor be switched on by default except when
781 * the user has explicitly disabled sensor based rotation or when the
782 * screen is switched off.
783 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700784 boolean needSensorRunningLp() {
Jeff Brownbcdfc622014-03-06 19:13:04 -0800785 if (mSupportAutoRotation) {
786 if (mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
787 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
788 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT
789 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) {
790 // If the application has explicitly requested to follow the
791 // orientation, then we need to turn the sensor on.
792 return true;
793 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800794 }
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700795 if ((mCarDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_CAR) ||
Jeff Brown1a693182011-11-08 14:44:16 -0800796 (mDeskDockEnablesAccelerometer && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
797 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
798 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK))) {
Mike Lockwoode9867d22009-09-20 01:59:02 -0400799 // enable accelerometer if we are docked in a dock that enables accelerometer
800 // orientation management,
801 return true;
802 }
Jeff Brown207673cd2012-06-05 17:47:11 -0700803 if (mUserRotationMode == USER_ROTATION_LOCKED) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800804 // If the setting for using the sensor by default is enabled, then
805 // we will always leave it on. Note that the user could go to
806 // a window that forces an orientation that does not use the
807 // sensor and in theory we could turn it off... however, when next
808 // turning it on we won't have a good value for the current
809 // orientation for a little bit, which can cause orientation
810 // changes to lag, so we'd like to keep it always on. (It will
811 // still be turned off when the screen is off.)
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700812 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800813 }
Jeff Brownbcdfc622014-03-06 19:13:04 -0800814 return mSupportAutoRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800815 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700816
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800817 /*
818 * Various use cases for invoking this function
819 * screen turning off, should always disable listeners if already enabled
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700820 * screen turned on and current app has sensor based orientation, enable listeners
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800821 * if not already enabled
822 * screen turned on and current app does not have sensor orientation, disable listeners if
823 * already enabled
824 * screen turning on and current app has sensor based orientation, enable listeners if needed
825 * screen turning on and current app has nosensor based orientation, do nothing
826 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700827 void updateOrientationListenerLp() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800828 if (!mOrientationListener.canDetectOrientation()) {
829 // If sensor is turned off or nonexistent for some reason
830 return;
831 }
832 //Could have been invoked due to screen turning on or off or
833 //change of the currently visible window's orientation
Jeff Brown3ee549c2014-09-22 20:14:39 -0700834 if (localLOGV) Slog.v(TAG, "mScreenOnEarly=" + mScreenOnEarly
835 + ", mAwake=" + mAwake + ", mCurrentAppOrientation=" + mCurrentAppOrientation
836 + ", mOrientationSensorEnabled=" + mOrientationSensorEnabled);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800837 boolean disable = true;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700838 if (mScreenOnEarly && mAwake) {
The Android Open Source Project0727d222009-03-11 12:11:58 -0700839 if (needSensorRunningLp()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800840 disable = false;
841 //enable listener if not already enabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700842 if (!mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800843 mOrientationListener.enable();
Craig Mautnereda67292013-04-28 13:50:14 -0700844 if(localLOGV) Slog.v(TAG, "Enabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800845 mOrientationSensorEnabled = true;
846 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700847 }
848 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800849 //check if sensors need to be disabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700850 if (disable && mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800851 mOrientationListener.disable();
Craig Mautnereda67292013-04-28 13:50:14 -0700852 if(localLOGV) Slog.v(TAG, "Disabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800853 mOrientationSensorEnabled = false;
854 }
855 }
856
Jeff Brown13f00f02014-10-31 14:45:50 -0700857 private void interceptPowerKeyDown(KeyEvent event, boolean interactive) {
858 // Hold a wake lock until the power key is released.
859 if (!mPowerKeyWakeLock.isHeld()) {
860 mPowerKeyWakeLock.acquire();
861 }
862
863 // Cancel multi-press detection timeout.
864 if (mPowerKeyPressCounter != 0) {
865 mHandler.removeMessages(MSG_POWER_DELAYED_PRESS);
866 }
867
868 // Detect user pressing the power button in panic when an application has
869 // taken over the whole screen.
870 boolean panic = mImmersiveModeConfirmation.onPowerKeyDown(interactive,
Craig Mautner0124980e92014-11-30 21:15:34 -0800871 SystemClock.elapsedRealtime(), isImmersiveMode(mLastSystemUiFlags));
Jeff Brown13f00f02014-10-31 14:45:50 -0700872 if (panic) {
Adrian Roosddc8b272015-05-21 16:28:27 -0700873 mHandler.post(mHiddenNavPanic);
Jeff Brown13f00f02014-10-31 14:45:50 -0700874 }
875
876 // Latch power key state to detect screenshot chord.
877 if (interactive && !mScreenshotChordPowerKeyTriggered
878 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
879 mScreenshotChordPowerKeyTriggered = true;
880 mScreenshotChordPowerKeyTime = event.getDownTime();
881 interceptScreenshotChord();
882 }
883
884 // Stop ringing or end call if configured to do so when power is pressed.
885 TelecomManager telecomManager = getTelecommService();
886 boolean hungUp = false;
887 if (telecomManager != null) {
888 if (telecomManager.isRinging()) {
889 // Pressing Power while there's a ringing incoming
890 // call should silence the ringer.
891 telecomManager.silenceRinger();
892 } else if ((mIncallPowerBehavior
893 & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0
894 && telecomManager.isInCall() && interactive) {
895 // Otherwise, if "Power button ends call" is enabled,
896 // the Power button will hang up any current active call.
897 hungUp = telecomManager.endCall();
898 }
899 }
900
901 // If the power key has still not yet been handled, then detect short
902 // press, long press, or multi press and decide what to do.
903 mPowerKeyHandled = hungUp || mScreenshotChordVolumeDownKeyTriggered
904 || mScreenshotChordVolumeUpKeyTriggered;
905 if (!mPowerKeyHandled) {
906 if (interactive) {
907 // When interactive, we're already awake.
908 // Wait for a long press or for the button to be released to decide what to do.
909 if (hasLongPressOnPowerBehavior()) {
910 Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS);
911 msg.setAsynchronous(true);
912 mHandler.sendMessageDelayed(msg,
913 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
914 }
915 } else {
Bryce Leed9268e32014-11-17 17:40:59 -0800916 wakeUpFromPowerKey(event.getDownTime());
Bryce Leed9268e32014-11-17 17:40:59 -0800917
Bryce Leed3b28402015-03-09 15:49:13 +0000918 if (mSupportLongPressPowerWhenNonInteractive && hasLongPressOnPowerBehavior()) {
919 Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS);
920 msg.setAsynchronous(true);
921 mHandler.sendMessageDelayed(msg,
922 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Bryce Leed9268e32014-11-17 17:40:59 -0800923 mBeganFromNonInteractive = true;
Bryce Leed3b28402015-03-09 15:49:13 +0000924 } else {
925 final int maxCount = getMaxMultiPressPowerCount();
926
927 if (maxCount <= 1) {
928 mPowerKeyHandled = true;
929 } else {
930 mBeganFromNonInteractive = true;
931 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700932 }
933 }
Jeff Brown4d396052010-10-29 21:50:21 -0700934 }
935 }
936
Jeff Brown13f00f02014-10-31 14:45:50 -0700937 private void interceptPowerKeyUp(KeyEvent event, boolean interactive, boolean canceled) {
938 final boolean handled = canceled || mPowerKeyHandled;
939 mScreenshotChordPowerKeyTriggered = false;
940 cancelPendingScreenshotChordAction();
941 cancelPendingPowerKeyAction();
942
943 if (!handled) {
944 // Figure out how to handle the key now that it has been released.
945 mPowerKeyPressCounter += 1;
946
947 final int maxCount = getMaxMultiPressPowerCount();
948 final long eventTime = event.getDownTime();
949 if (mPowerKeyPressCounter < maxCount) {
950 // This could be a multi-press. Wait a little bit longer to confirm.
951 // Continue holding the wake lock.
952 Message msg = mHandler.obtainMessage(MSG_POWER_DELAYED_PRESS,
953 interactive ? 1 : 0, mPowerKeyPressCounter, eventTime);
954 msg.setAsynchronous(true);
955 mHandler.sendMessageDelayed(msg, ViewConfiguration.getDoubleTapTimeout());
956 return;
957 }
958
959 // No other actions. Handle it immediately.
960 powerPress(eventTime, interactive, mPowerKeyPressCounter);
Jeff Brown4d396052010-10-29 21:50:21 -0700961 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700962
963 // Done. Reset our state.
964 finishPowerKeyPress();
965 }
966
967 private void finishPowerKeyPress() {
Bryce Leed9268e32014-11-17 17:40:59 -0800968 mBeganFromNonInteractive = false;
Jeff Brown13f00f02014-10-31 14:45:50 -0700969 mPowerKeyPressCounter = 0;
970 if (mPowerKeyWakeLock.isHeld()) {
971 mPowerKeyWakeLock.release();
972 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700973 }
974
975 private void cancelPendingPowerKeyAction() {
976 if (!mPowerKeyHandled) {
Jeff Brown13f00f02014-10-31 14:45:50 -0700977 mPowerKeyHandled = true;
978 mHandler.removeMessages(MSG_POWER_LONG_PRESS);
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700979 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700980 }
981
982 private void powerPress(long eventTime, boolean interactive, int count) {
983 if (mScreenOnEarly && !mScreenOnFully) {
984 Slog.i(TAG, "Suppressed redundant power key press while "
985 + "already in the process of turning the screen on.");
986 return;
Jeff Brownff204712011-10-25 21:27:54 -0700987 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700988
989 if (count == 2) {
990 powerMultiPressAction(eventTime, interactive, mDoublePressOnPowerBehavior);
991 } else if (count == 3) {
992 powerMultiPressAction(eventTime, interactive, mTriplePressOnPowerBehavior);
Bryce Leed9268e32014-11-17 17:40:59 -0800993 } else if (interactive && !mBeganFromNonInteractive) {
Jeff Brown13f00f02014-10-31 14:45:50 -0700994 switch (mShortPressOnPowerBehavior) {
995 case SHORT_PRESS_POWER_NOTHING:
996 break;
997 case SHORT_PRESS_POWER_GO_TO_SLEEP:
998 mPowerManager.goToSleep(eventTime,
999 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
1000 break;
1001 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP:
1002 mPowerManager.goToSleep(eventTime,
1003 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
1004 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
1005 break;
1006 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME:
1007 mPowerManager.goToSleep(eventTime,
1008 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
1009 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
1010 launchHomeFromHotKey();
1011 break;
Bryce Lee01b0c5f2015-02-05 18:24:04 -08001012 case SHORT_PRESS_POWER_GO_HOME:
Bryce Lee662ed802015-04-10 20:11:39 +00001013 launchHomeFromHotKey(true /* awakenFromDreams */, false /*respectKeyguard*/);
Bryce Lee01b0c5f2015-02-05 18:24:04 -08001014 break;
Jeff Brown13f00f02014-10-31 14:45:50 -07001015 }
1016 }
1017 }
1018
1019 private void powerMultiPressAction(long eventTime, boolean interactive, int behavior) {
1020 switch (behavior) {
1021 case MULTI_PRESS_POWER_NOTHING:
1022 break;
1023 case MULTI_PRESS_POWER_THEATER_MODE:
1024 if (isTheaterModeEnabled()) {
1025 Slog.i(TAG, "Toggling theater mode off.");
1026 Settings.Global.putInt(mContext.getContentResolver(),
1027 Settings.Global.THEATER_MODE_ON, 0);
1028 if (!interactive) {
1029 wakeUpFromPowerKey(eventTime);
1030 }
1031 } else {
1032 Slog.i(TAG, "Toggling theater mode on.");
1033 Settings.Global.putInt(mContext.getContentResolver(),
1034 Settings.Global.THEATER_MODE_ON, 1);
Bryce Lee55e846d2014-11-04 12:43:44 -08001035
1036 if (mGoToSleepOnButtonPressTheaterMode && interactive) {
Jeff Brown13f00f02014-10-31 14:45:50 -07001037 mPowerManager.goToSleep(eventTime,
1038 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
1039 }
1040 }
1041 break;
1042 case MULTI_PRESS_POWER_BRIGHTNESS_BOOST:
Jeff Brown7b5be5e2014-11-12 18:45:31 -08001043 Slog.i(TAG, "Starting brightness boost.");
1044 if (!interactive) {
1045 wakeUpFromPowerKey(eventTime);
1046 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001047 mPowerManager.boostScreenBrightness(eventTime);
1048 break;
1049 }
1050 }
1051
1052 private int getMaxMultiPressPowerCount() {
1053 if (mTriplePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) {
1054 return 3;
1055 }
1056 if (mDoublePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) {
1057 return 2;
1058 }
1059 return 1;
1060 }
1061
1062 private void powerLongPress() {
1063 final int behavior = getResolvedLongPressOnPowerBehavior();
1064 switch (behavior) {
1065 case LONG_PRESS_POWER_NOTHING:
1066 break;
1067 case LONG_PRESS_POWER_GLOBAL_ACTIONS:
1068 mPowerKeyHandled = true;
1069 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
1070 performAuditoryFeedbackForAccessibilityIfNeed();
1071 }
1072 showGlobalActionsInternal();
1073 break;
1074 case LONG_PRESS_POWER_SHUT_OFF:
1075 case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM:
1076 mPowerKeyHandled = true;
1077 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
1078 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
1079 mWindowManagerFuncs.shutdown(behavior == LONG_PRESS_POWER_SHUT_OFF);
1080 break;
1081 }
1082 }
1083
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001084 private void sleepPress(KeyEvent event) {
1085 switch (mShortPressOnSleepBehavior) {
1086 case SHORT_PRESS_SLEEP_GO_TO_SLEEP:
1087 mPowerManager.goToSleep(event.getEventTime(),
1088 PowerManager.GO_TO_SLEEP_REASON_SLEEP_BUTTON, 0);
1089 break;
1090 case SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME:
Bryce Lee662ed802015-04-10 20:11:39 +00001091 launchHomeFromHotKey(false /* awakenDreams */, true /*respectKeyguard*/);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001092 mPowerManager.goToSleep(event.getEventTime(),
1093 PowerManager.GO_TO_SLEEP_REASON_SLEEP_BUTTON, 0);
1094 break;
1095 }
1096 }
1097
Jeff Brown13f00f02014-10-31 14:45:50 -07001098 private int getResolvedLongPressOnPowerBehavior() {
1099 if (FactoryTest.isLongPressOnPowerOffEnabled()) {
1100 return LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM;
1101 }
1102 return mLongPressOnPowerBehavior;
1103 }
1104
1105 private boolean hasLongPressOnPowerBehavior() {
1106 return getResolvedLongPressOnPowerBehavior() != LONG_PRESS_POWER_NOTHING;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001107 }
1108
1109 private void interceptScreenshotChord() {
Christopher Tatee90585f2012-03-05 18:56:25 -08001110 if (mScreenshotChordEnabled
Jeff Brown13f00f02014-10-31 14:45:50 -07001111 && mScreenshotChordVolumeDownKeyTriggered && mScreenshotChordPowerKeyTriggered
1112 && !mScreenshotChordVolumeUpKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001113 final long now = SystemClock.uptimeMillis();
Jeff Brown13f00f02014-10-31 14:45:50 -07001114 if (now <= mScreenshotChordVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS
1115 && now <= mScreenshotChordPowerKeyTime
1116 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) {
1117 mScreenshotChordVolumeDownKeyConsumed = true;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001118 cancelPendingPowerKeyAction();
1119
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001120 mHandler.postDelayed(mScreenshotRunnable, getScreenshotChordLongPressDelay());
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001121 }
1122 }
1123 }
1124
Winson Chung1cea2f32012-10-08 20:42:01 -07001125 private long getScreenshotChordLongPressDelay() {
Jim Miller5ecd8112013-01-09 18:50:26 -08001126 if (mKeyguardDelegate.isShowing()) {
Winson Chung1cea2f32012-10-08 20:42:01 -07001127 // Double the time it takes to take a screenshot from the keyguard
1128 return (long) (KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER *
Justin Kohfeabd2c2014-05-02 10:02:44 -07001129 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Winson Chung1cea2f32012-10-08 20:42:01 -07001130 }
Justin Kohfeabd2c2014-05-02 10:02:44 -07001131 return ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout();
Winson Chung1cea2f32012-10-08 20:42:01 -07001132 }
1133
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001134 private void cancelPendingScreenshotChordAction() {
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001135 mHandler.removeCallbacks(mScreenshotRunnable);
Jeff Brown4d396052010-10-29 21:50:21 -07001136 }
1137
Jeff Brown13f00f02014-10-31 14:45:50 -07001138 private final Runnable mEndCallLongPress = new Runnable() {
Craig Mautnerf1b67412012-09-19 13:18:29 -07001139 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001140 public void run() {
Jeff Brown13f00f02014-10-31 14:45:50 -07001141 mEndCallKeyHandled = true;
1142 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
1143 performAuditoryFeedbackForAccessibilityIfNeed();
Joe Onoratod208e702010-10-08 16:22:43 -04001144 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001145 showGlobalActionsInternal();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001146 }
1147 };
1148
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001149 private final Runnable mScreenshotRunnable = new Runnable() {
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001150 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001151 public void run() {
1152 takeScreenshot();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001153 }
1154 };
1155
Alan Viverettee34560b22014-07-10 14:50:06 -07001156 @Override
1157 public void showGlobalActions() {
1158 mHandler.removeMessages(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
1159 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
1160 }
1161
1162 void showGlobalActionsInternal() {
1163 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001164 if (mGlobalActions == null) {
Jeff Brown7304c342012-05-11 18:42:42 -07001165 mGlobalActions = new GlobalActions(mContext, mWindowManagerFuncs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001166 }
Jim Millerab954542014-10-10 18:21:49 -07001167 final boolean keyguardShowing = isKeyguardShowingAndNotOccluded();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001168 mGlobalActions.showDialog(keyguardShowing, isDeviceProvisioned());
1169 if (keyguardShowing) {
1170 // since it took two seconds of long press to bring this up,
1171 // poke the wake lock so they have some time to see the dialog.
Jim Miller25190572013-02-28 17:36:24 -08001172 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001173 }
1174 }
1175
1176 boolean isDeviceProvisioned() {
Jeff Brownbf6f6f92012-09-25 15:03:20 -07001177 return Settings.Global.getInt(
1178 mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001179 }
1180
Maurice Lam99c6e072014-04-28 18:24:28 -07001181 boolean isUserSetupComplete() {
1182 return Settings.Secure.getIntForUser(mContext.getContentResolver(),
1183 Settings.Secure.USER_SETUP_COMPLETE, 0, UserHandle.USER_CURRENT) != 0;
1184 }
1185
Jeff Brown13f00f02014-10-31 14:45:50 -07001186 private void handleShortPressOnHome() {
1187 // If there's a dream running then use home to escape the dream
1188 // but don't actually go home.
1189 if (mDreamManagerInternal != null && mDreamManagerInternal.isDreaming()) {
1190 mDreamManagerInternal.stopDream(false /*immediate*/);
1191 return;
1192 }
1193
1194 // Go home!
1195 launchHomeFromHotKey();
1196 }
1197
Patrick Dubroyece94522011-02-23 18:35:01 -08001198 private void handleLongPressOnHome() {
Joe Onorato46b0d682010-11-22 17:37:27 -08001199 if (mLongPressOnHomeBehavior != LONG_PRESS_HOME_NOTHING) {
Jeff Browncaca8812013-05-09 13:34:33 -07001200 mHomeConsumed = true;
Joe Onorato46b0d682010-11-22 17:37:27 -08001201 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
Patrick Dubroyece94522011-02-23 18:35:01 -08001202
Jeff Browncaca8812013-05-09 13:34:33 -07001203 if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI) {
1204 toggleRecentApps();
1205 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_ASSIST) {
1206 launchAssistAction();
Jim Millere6ad1a82010-08-20 19:25:39 -07001207 }
1208 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001209 }
Patrick Dubroyece94522011-02-23 18:35:01 -08001210
Jeff Browncaca8812013-05-09 13:34:33 -07001211 private void handleDoubleTapOnHome() {
1212 if (mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1213 mHomeConsumed = true;
1214 toggleRecentApps();
1215 }
1216 }
1217
1218 private final Runnable mHomeDoubleTapTimeoutRunnable = new Runnable() {
1219 @Override
1220 public void run() {
1221 if (mHomeDoubleTapPending) {
1222 mHomeDoubleTapPending = false;
Jeff Brown13f00f02014-10-31 14:45:50 -07001223 handleShortPressOnHome();
Jeff Browncaca8812013-05-09 13:34:33 -07001224 }
1225 }
1226 };
1227
Mark Renoufc1256912015-03-11 14:38:23 -04001228 private boolean isRoundWindow() {
Adam Powell01f280d2015-05-18 16:07:42 -07001229 return mContext.getResources().getConfiguration().isScreenRound();
Mark Renoufc1256912015-03-11 14:38:23 -04001230 }
1231
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001232 /** {@inheritDoc} */
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001233 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001234 public void init(Context context, IWindowManager windowManager,
Jeff Brown96307042012-07-27 15:51:34 -07001235 WindowManagerFuncs windowManagerFuncs) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001236 mContext = context;
1237 mWindowManager = windowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -07001238 mWindowManagerFuncs = windowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -07001239 mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class);
Jeff Brown061ea992015-04-17 19:55:47 -07001240 mActivityManagerInternal = LocalServices.getService(ActivityManagerInternal.class);
Jose Lima9546b202014-07-02 17:21:51 -07001241 mDreamManagerInternal = LocalServices.getService(DreamManagerInternal.class);
Mark Renoufc1256912015-03-11 14:38:23 -04001242
1243 // Init display burn-in protection
1244 boolean burnInProtectionEnabled = context.getResources().getBoolean(
1245 com.android.internal.R.bool.config_enableBurnInProtection);
1246 // Allow a system property to override this. Used by developer settings.
1247 boolean burnInProtectionDevMode =
1248 SystemProperties.getBoolean("persist.debug.force_burn_in", false);
1249 if (burnInProtectionEnabled || burnInProtectionDevMode) {
1250 final int minHorizontal;
1251 final int maxHorizontal;
1252 final int minVertical;
1253 final int maxVertical;
1254 final int maxRadius;
1255 if (burnInProtectionDevMode) {
1256 minHorizontal = -8;
1257 maxHorizontal = 8;
1258 minVertical = -8;
1259 maxVertical = -4;
1260 maxRadius = (isRoundWindow()) ? 6 : -1;
1261 } else {
1262 Resources resources = context.getResources();
1263 minHorizontal = resources.getInteger(
1264 com.android.internal.R.integer.config_burnInProtectionMinHorizontalOffset);
1265 maxHorizontal = resources.getInteger(
1266 com.android.internal.R.integer.config_burnInProtectionMaxHorizontalOffset);
1267 minVertical = resources.getInteger(
1268 com.android.internal.R.integer.config_burnInProtectionMinVerticalOffset);
1269 maxVertical = resources.getInteger(
1270 com.android.internal.R.integer.config_burnInProtectionMaxVerticalOffset);
1271 maxRadius = resources.getInteger(
1272 com.android.internal.R.integer.config_burnInProtectionMaxRadius);
1273 }
1274 mBurnInProtectionHelper = new BurnInProtectionHelper(
1275 context, minHorizontal, maxHorizontal, minVertical, maxVertical, maxRadius);
Filip Gruszczynskicfb31852015-02-25 21:47:12 +00001276 }
Craig Mautner8a0da012014-05-31 15:13:37 -07001277
Jeff Brown70825162012-03-28 17:27:48 -07001278 mHandler = new PolicyHandler();
Jeff Browna20dda42014-05-27 20:57:24 -07001279 mWakeGestureListener = new MyWakeGestureListener(mContext, mHandler);
Craig Mautnereee29c42013-01-17 14:44:34 -08001280 mOrientationListener = new MyOrientationListener(mContext, mHandler);
Jeff Brownc0347aa2011-09-23 17:26:09 -07001281 try {
1282 mOrientationListener.setCurrentRotation(windowManager.getRotation());
1283 } catch (RemoteException ex) { }
Christopher Tate5e08af02012-09-21 17:17:22 -07001284 mSettingsObserver = new SettingsObserver(mHandler);
1285 mSettingsObserver.observe();
Svetoslav683914b2015-01-15 14:22:26 -08001286 mShortcutManager = new ShortcutManager(context);
Daniel Sandler6396c722013-04-16 20:19:09 -04001287 mUiMode = context.getResources().getInteger(
1288 com.android.internal.R.integer.config_defaultUiModeType);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001289 mHomeIntent = new Intent(Intent.ACTION_MAIN, null);
1290 mHomeIntent.addCategory(Intent.CATEGORY_HOME);
1291 mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1292 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07001293 mCarDockIntent = new Intent(Intent.ACTION_MAIN, null);
1294 mCarDockIntent.addCategory(Intent.CATEGORY_CAR_DOCK);
1295 mCarDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1296 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
1297 mDeskDockIntent = new Intent(Intent.ACTION_MAIN, null);
1298 mDeskDockIntent.addCategory(Intent.CATEGORY_DESK_DOCK);
1299 mDeskDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1300 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Jim Millere6ad1a82010-08-20 19:25:39 -07001301
Jeff Brown96307042012-07-27 15:51:34 -07001302 mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
1303 mBroadcastWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001304 "PhoneWindowManager.mBroadcastWakeLock");
Jeff Brown13f00f02014-10-31 14:45:50 -07001305 mPowerKeyWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
1306 "PhoneWindowManager.mPowerKeyWakeLock");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001307 mEnableShiftMenuBugReports = "1".equals(SystemProperties.get("ro.debuggable"));
Jeff Brownbcdfc622014-03-06 19:13:04 -08001308 mSupportAutoRotation = mContext.getResources().getBoolean(
1309 com.android.internal.R.bool.config_supportAutoRotation);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001310 mLidOpenRotation = readRotation(
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001311 com.android.internal.R.integer.config_lidOpenRotation);
1312 mCarDockRotation = readRotation(
1313 com.android.internal.R.integer.config_carDockRotation);
1314 mDeskDockRotation = readRotation(
1315 com.android.internal.R.integer.config_deskDockRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001316 mUndockedHdmiRotation = readRotation(
1317 com.android.internal.R.integer.config_undockedHdmiRotation);
Mike Lockwoode9867d22009-09-20 01:59:02 -04001318 mCarDockEnablesAccelerometer = mContext.getResources().getBoolean(
1319 com.android.internal.R.bool.config_carDockEnablesAccelerometer);
1320 mDeskDockEnablesAccelerometer = mContext.getResources().getBoolean(
1321 com.android.internal.R.bool.config_deskDockEnablesAccelerometer);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001322 mLidKeyboardAccessibility = mContext.getResources().getInteger(
1323 com.android.internal.R.integer.config_lidKeyboardAccessibility);
1324 mLidNavigationAccessibility = mContext.getResources().getInteger(
1325 com.android.internal.R.integer.config_lidNavigationAccessibility);
Jeff Brownc458ce92012-04-30 14:58:40 -07001326 mLidControlsSleep = mContext.getResources().getBoolean(
1327 com.android.internal.R.bool.config_lidControlsSleep);
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04001328 mTranslucentDecorEnabled = mContext.getResources().getBoolean(
1329 com.android.internal.R.bool.config_enableTranslucentDecor);
Bryce Lee584a4452014-10-21 15:55:55 -07001330
1331 mAllowTheaterModeWakeFromKey = mContext.getResources().getBoolean(
1332 com.android.internal.R.bool.config_allowTheaterModeWakeFromKey);
1333 mAllowTheaterModeWakeFromPowerKey = mAllowTheaterModeWakeFromKey
1334 || mContext.getResources().getBoolean(
1335 com.android.internal.R.bool.config_allowTheaterModeWakeFromPowerKey);
1336 mAllowTheaterModeWakeFromMotion = mContext.getResources().getBoolean(
1337 com.android.internal.R.bool.config_allowTheaterModeWakeFromMotion);
Bryce Lee812d7022014-11-10 13:33:28 -08001338 mAllowTheaterModeWakeFromMotionWhenNotDreaming = mContext.getResources().getBoolean(
1339 com.android.internal.R.bool.config_allowTheaterModeWakeFromMotionWhenNotDreaming);
Bryce Lee584a4452014-10-21 15:55:55 -07001340 mAllowTheaterModeWakeFromCameraLens = mContext.getResources().getBoolean(
1341 com.android.internal.R.bool.config_allowTheaterModeWakeFromCameraLens);
1342 mAllowTheaterModeWakeFromLidSwitch = mContext.getResources().getBoolean(
1343 com.android.internal.R.bool.config_allowTheaterModeWakeFromLidSwitch);
1344 mAllowTheaterModeWakeFromWakeGesture = mContext.getResources().getBoolean(
1345 com.android.internal.R.bool.config_allowTheaterModeWakeFromGesture);
1346
Bryce Lee55e846d2014-11-04 12:43:44 -08001347 mGoToSleepOnButtonPressTheaterMode = mContext.getResources().getBoolean(
1348 com.android.internal.R.bool.config_goToSleepOnButtonPressTheaterMode);
1349
Bryce Leed3b28402015-03-09 15:49:13 +00001350 mSupportLongPressPowerWhenNonInteractive = mContext.getResources().getBoolean(
1351 com.android.internal.R.bool.config_supportLongPressPowerWhenNonInteractive);
1352
Jeff Brown13f00f02014-10-31 14:45:50 -07001353 mShortPressOnPowerBehavior = mContext.getResources().getInteger(
1354 com.android.internal.R.integer.config_shortPressOnPowerBehavior);
1355 mLongPressOnPowerBehavior = mContext.getResources().getInteger(
1356 com.android.internal.R.integer.config_longPressOnPowerBehavior);
1357 mDoublePressOnPowerBehavior = mContext.getResources().getInteger(
1358 com.android.internal.R.integer.config_doublePressOnPowerBehavior);
1359 mTriplePressOnPowerBehavior = mContext.getResources().getInteger(
1360 com.android.internal.R.integer.config_triplePressOnPowerBehavior);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001361 mShortPressOnSleepBehavior = mContext.getResources().getInteger(
1362 com.android.internal.R.integer.config_shortPressOnSleepBehavior);
Jeff Brown13f00f02014-10-31 14:45:50 -07001363
John Spurlock61560172015-02-06 19:46:04 -05001364 mUseTvRouting = AudioSystem.getPlatformType(mContext) == AudioSystem.PLATFORM_TELEVISION;
RoboErik001c59c2015-01-26 15:53:51 -08001365
Jeff Brownf71343d2013-05-31 17:59:11 -07001366 readConfigurationDependentBehaviors();
Jeff Browncaca8812013-05-09 13:34:33 -07001367
Svetoslav8e3feb12014-02-24 13:46:47 -08001368 mAccessibilityManager = (AccessibilityManager) context.getSystemService(
1369 Context.ACCESSIBILITY_SERVICE);
1370
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001371 // register for dock events
Dianne Hackborn78968392010-03-04 20:47:56 -08001372 IntentFilter filter = new IntentFilter();
1373 filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE);
1374 filter.addAction(UiModeManager.ACTION_EXIT_CAR_MODE);
1375 filter.addAction(UiModeManager.ACTION_ENTER_DESK_MODE);
1376 filter.addAction(UiModeManager.ACTION_EXIT_DESK_MODE);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001377 filter.addAction(Intent.ACTION_DOCK_EVENT);
1378 Intent intent = context.registerReceiver(mDockReceiver, filter);
1379 if (intent != null) {
1380 // Retrieve current sticky dock event broadcast.
1381 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
1382 Intent.EXTRA_DOCK_STATE_UNDOCKED);
1383 }
Daniel Sandler7e37df52011-11-16 22:08:23 -08001384
Jeff Brown6aaf2952012-10-05 16:01:08 -07001385 // register for dream-related broadcasts
1386 filter = new IntentFilter();
1387 filter.addAction(Intent.ACTION_DREAMING_STARTED);
1388 filter.addAction(Intent.ACTION_DREAMING_STOPPED);
1389 context.registerReceiver(mDreamReceiver, filter);
1390
Christopher Tate5e08af02012-09-21 17:17:22 -07001391 // register for multiuser-relevant broadcasts
1392 filter = new IntentFilter(Intent.ACTION_USER_SWITCHED);
1393 context.registerReceiver(mMultiuserReceiver, filter);
1394
John Spurlock57306e62013-04-22 09:48:49 -04001395 // monitor for system gestures
Craig Mautner037aa8d2013-06-07 10:35:44 -07001396 mSystemGestures = new SystemGesturesPointerEventListener(context,
1397 new SystemGesturesPointerEventListener.Callbacks() {
John Spurlock57306e62013-04-22 09:48:49 -04001398 @Override
1399 public void onSwipeFromTop() {
John Spurlock04db1762013-05-13 12:46:41 -04001400 if (mStatusBar != null) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001401 requestTransientBars(mStatusBar);
John Spurlock04db1762013-05-13 12:46:41 -04001402 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04001403 }
1404 @Override
1405 public void onSwipeFromBottom() {
John Spurlock04db1762013-05-13 12:46:41 -04001406 if (mNavigationBar != null && mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001407 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001408 }
1409 }
1410 @Override
1411 public void onSwipeFromRight() {
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 onDebug() {
John Spurlockd67ec252013-09-05 11:31:54 -04001418 // no-op
John Spurlockad3e6cb2013-04-30 08:47:43 -04001419 }
Adrian Roos3595be42015-03-05 16:31:15 +01001420 @Override
1421 public void onDown() {
1422 mOrientationListener.onTouchStart();
1423 }
1424 @Override
1425 public void onUpOrCancel() {
1426 mOrientationListener.onTouchEnd();
1427 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04001428 });
John Spurlockf1a36642013-10-12 17:50:42 -04001429 mImmersiveModeConfirmation = new ImmersiveModeConfirmation(mContext);
Craig Mautner037aa8d2013-06-07 10:35:44 -07001430 mWindowManagerFuncs.registerPointerEventListener(mSystemGestures);
John Spurlock32beb2c2013-03-11 10:16:47 -04001431
Jeff Brownc2346132012-04-13 01:55:38 -07001432 mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001433 mLongPressVibePattern = getLongIntArray(mContext.getResources(),
1434 com.android.internal.R.array.config_longPressVibePattern);
1435 mVirtualKeyVibePattern = getLongIntArray(mContext.getResources(),
1436 com.android.internal.R.array.config_virtualKeyVibePattern);
Amith Yamasanic33cb712010-02-10 15:21:49 -08001437 mKeyboardTapVibePattern = getLongIntArray(mContext.getResources(),
1438 com.android.internal.R.array.config_keyboardTapVibePattern);
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07001439 mClockTickVibePattern = getLongIntArray(mContext.getResources(),
1440 com.android.internal.R.array.config_clockTickVibePattern);
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07001441 mCalendarDateVibePattern = getLongIntArray(mContext.getResources(),
1442 com.android.internal.R.array.config_calendarDateVibePattern);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001443 mSafeModeDisabledVibePattern = getLongIntArray(mContext.getResources(),
1444 com.android.internal.R.array.config_safeModeDisabledVibePattern);
1445 mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(),
1446 com.android.internal.R.array.config_safeModeEnabledVibePattern);
Mady Mellore82067b2015-04-30 09:58:35 -07001447 mStylusButtonPressVibePattern = getLongIntArray(mContext.getResources(),
1448 com.android.internal.R.array.config_stylusButtonPressVibePattern);
Daniel Sandler40427442010-07-16 11:44:52 -04001449
Christopher Tatee90585f2012-03-05 18:56:25 -08001450 mScreenshotChordEnabled = mContext.getResources().getBoolean(
1451 com.android.internal.R.bool.config_enableScreenshotChord);
1452
Justin Kohd378ad72013-04-01 12:18:26 -07001453 mGlobalKeyManager = new GlobalKeyManager(mContext);
1454
Joe Onoratoea495d42011-04-06 11:41:11 -07001455 // Controls rotation and the like.
1456 initializeHdmiState();
Dianne Hackborn40011092011-09-22 13:37:48 -07001457
1458 // Match current screen state.
Craig Mautnera631d492014-08-05 15:16:01 -07001459 if (!mPowerManager.isInteractive()) {
Jeff Brown140ffc72014-05-01 15:18:00 -07001460 goingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
Dianne Hackborn40011092011-09-22 13:37:48 -07001461 }
Jorim Jaggi24bec7c2015-02-04 12:40:14 +01001462
1463 mWindowManagerInternal.registerAppTransitionListener(
1464 mStatusBarController.getAppTransitionListener());
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001465 }
1466
Jeff Brownf71343d2013-05-31 17:59:11 -07001467 /**
1468 * Read values from config.xml that may be overridden depending on
1469 * the configuration of the device.
1470 * eg. Disable long press on home goes to recents on sw600dp.
1471 */
1472 private void readConfigurationDependentBehaviors() {
1473 mLongPressOnHomeBehavior = mContext.getResources().getInteger(
1474 com.android.internal.R.integer.config_longPressOnHomeBehavior);
1475 if (mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING ||
1476 mLongPressOnHomeBehavior > LONG_PRESS_HOME_ASSIST) {
1477 mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1478 }
1479
1480 mDoubleTapOnHomeBehavior = mContext.getResources().getInteger(
1481 com.android.internal.R.integer.config_doubleTapOnHomeBehavior);
1482 if (mDoubleTapOnHomeBehavior < DOUBLE_TAP_HOME_NOTHING ||
1483 mDoubleTapOnHomeBehavior > DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1484 mDoubleTapOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1485 }
1486 }
1487
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001488 @Override
Dianne Hackborndde331c2012-08-03 14:01:57 -07001489 public void setInitialDisplaySize(Display display, int width, int height, int density) {
Jeff Brownef981a42013-08-07 14:13:37 -07001490 // This method might be called before the policy has been fully initialized
1491 // or for other displays we don't care about.
1492 if (mContext == null || display.getDisplayId() != Display.DEFAULT_DISPLAY) {
1493 return;
Dianne Hackbornc652de82013-02-15 16:32:56 -08001494 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001495 mDisplay = display;
1496
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001497 final Resources res = mContext.getResources();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001498 int shortSize, longSize;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001499 if (width > height) {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001500 shortSize = height;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001501 longSize = width;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001502 mLandscapeRotation = Surface.ROTATION_0;
1503 mSeascapeRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001504 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001505 mPortraitRotation = Surface.ROTATION_90;
1506 mUpsideDownRotation = Surface.ROTATION_270;
1507 } else {
1508 mPortraitRotation = Surface.ROTATION_270;
1509 mUpsideDownRotation = Surface.ROTATION_90;
1510 }
1511 } else {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001512 shortSize = width;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001513 longSize = height;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001514 mPortraitRotation = Surface.ROTATION_0;
1515 mUpsideDownRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001516 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001517 mLandscapeRotation = Surface.ROTATION_270;
1518 mSeascapeRotation = Surface.ROTATION_90;
1519 } else {
1520 mLandscapeRotation = Surface.ROTATION_90;
1521 mSeascapeRotation = Surface.ROTATION_270;
1522 }
1523 }
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001524
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001525 mStatusBarHeight =
1526 res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001527
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001528 // Height of the navigation bar when presented horizontally at bottom
1529 mNavigationBarHeightForRotation[mPortraitRotation] =
1530 mNavigationBarHeightForRotation[mUpsideDownRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001531 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_height);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001532 mNavigationBarHeightForRotation[mLandscapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001533 mNavigationBarHeightForRotation[mSeascapeRotation] = res.getDimensionPixelSize(
1534 com.android.internal.R.dimen.navigation_bar_height_landscape);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001535
1536 // Width of the navigation bar when presented vertically along one side
1537 mNavigationBarWidthForRotation[mPortraitRotation] =
1538 mNavigationBarWidthForRotation[mUpsideDownRotation] =
1539 mNavigationBarWidthForRotation[mLandscapeRotation] =
1540 mNavigationBarWidthForRotation[mSeascapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001541 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_width);
Daniel Sandler4a066c52012-04-20 14:49:13 -04001542
1543 // SystemUI (status bar) layout policy
Dianne Hackborndde331c2012-08-03 14:01:57 -07001544 int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / density;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001545 int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / density;
Daniel Sandler4a066c52012-04-20 14:49:13 -04001546
Devin Kimd7b12b42014-05-05 14:34:58 -07001547 // Allow the navigation bar to move on non-square small devices (phones).
1548 mNavigationBarCanMove = width != height && shortSizeDp < 600;
Daniel Sandler36412a72011-08-04 09:35:13 -04001549
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001550 mHasNavigationBar = res.getBoolean(com.android.internal.R.bool.config_showNavigationBar);
John Spurlock80f00c12013-06-13 11:10:51 -04001551 // Allow a system property to override this. Used by the emulator.
1552 // See also hasNavigationBar().
1553 String navBarOverride = SystemProperties.get("qemu.hw.mainkeys");
1554 if ("1".equals(navBarOverride)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001555 mHasNavigationBar = false;
John Spurlock80f00c12013-06-13 11:10:51 -04001556 } else if ("0".equals(navBarOverride)) {
1557 mHasNavigationBar = true;
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04001558 }
1559
Jeff Brown27f1d672012-10-17 18:32:34 -07001560 // For demo purposes, allow the rotation of the HDMI display to be controlled.
1561 // By default, HDMI locks rotation to landscape.
Erik Gilling9a41ef82011-09-26 19:21:03 -07001562 if ("portrait".equals(SystemProperties.get("persist.demo.hdmirotation"))) {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001563 mDemoHdmiRotation = mPortraitRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001564 } else {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001565 mDemoHdmiRotation = mLandscapeRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001566 }
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001567 mDemoHdmiRotationLock = SystemProperties.getBoolean("persist.demo.hdmirotationlock", false);
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001568
Chong Zhangae6119ff2014-11-11 18:54:39 -08001569 // For demo purposes, allow the rotation of the remote display to be controlled.
1570 // By default, remote display locks rotation to landscape.
1571 if ("portrait".equals(SystemProperties.get("persist.demo.remoterotation"))) {
1572 mDemoRotation = mPortraitRotation;
1573 } else {
1574 mDemoRotation = mLandscapeRotation;
1575 }
1576 mDemoRotationLock = SystemProperties.getBoolean(
1577 "persist.demo.rotationlock", false);
1578
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001579 // Only force the default orientation if the screen is xlarge, at least 960dp x 720dp, per
1580 // http://developer.android.com/guide/practices/screens_support.html#range
1581 mForceDefaultOrientation = longSizeDp >= 960 && shortSizeDp >= 720 &&
1582 res.getBoolean(com.android.internal.R.bool.config_forceDefaultOrientation) &&
1583 // For debug purposes the next line turns this feature off with:
1584 // $ adb shell setprop config.override_forced_orient true
1585 // $ adb shell wm size reset
1586 !"true".equals(SystemProperties.get("config.override_forced_orient"));
1587 }
1588
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001589 /**
1590 * @return whether the navigation bar can be hidden, e.g. the device has a
1591 * navigation bar and touch exploration is not enabled
1592 */
1593 private boolean canHideNavigationBar() {
Svetoslav8e3feb12014-02-24 13:46:47 -08001594 return mHasNavigationBar
1595 && !mAccessibilityManager.isTouchExplorationEnabled();
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001596 }
1597
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001598 @Override
1599 public boolean isDefaultOrientationForced() {
1600 return mForceDefaultOrientation;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001601 }
1602
Dianne Hackbornc652de82013-02-15 16:32:56 -08001603 @Override
1604 public void setDisplayOverscan(Display display, int left, int top, int right, int bottom) {
1605 if (display.getDisplayId() == Display.DEFAULT_DISPLAY) {
1606 mOverscanLeft = left;
1607 mOverscanTop = top;
1608 mOverscanRight = right;
1609 mOverscanBottom = bottom;
1610 }
1611 }
1612
Dianne Hackbornc777e072010-02-12 13:07:59 -08001613 public void updateSettings() {
1614 ContentResolver resolver = mContext.getContentResolver();
1615 boolean updateRotation = false;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001616 synchronized (mLock) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001617 mEndcallBehavior = Settings.System.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001618 Settings.System.END_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001619 Settings.System.END_BUTTON_BEHAVIOR_DEFAULT,
1620 UserHandle.USER_CURRENT);
1621 mIncallPowerBehavior = Settings.Secure.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001622 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001623 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT,
1624 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001625
Jeff Browna20dda42014-05-27 20:57:24 -07001626 // Configure wake gesture.
1627 boolean wakeGestureEnabledSetting = Settings.Secure.getIntForUser(resolver,
1628 Settings.Secure.WAKE_GESTURE_ENABLED, 0,
1629 UserHandle.USER_CURRENT) != 0;
1630 if (mWakeGestureEnabledSetting != wakeGestureEnabledSetting) {
1631 mWakeGestureEnabledSetting = wakeGestureEnabledSetting;
1632 updateWakeGestureListenerLp();
1633 }
1634
Jeff Brown207673cd2012-06-05 17:47:11 -07001635 // Configure rotation lock.
Christopher Tate5e08af02012-09-21 17:17:22 -07001636 int userRotation = Settings.System.getIntForUser(resolver,
1637 Settings.System.USER_ROTATION, Surface.ROTATION_0,
1638 UserHandle.USER_CURRENT);
Jeff Brown207673cd2012-06-05 17:47:11 -07001639 if (mUserRotation != userRotation) {
1640 mUserRotation = userRotation;
1641 updateRotation = true;
1642 }
Christopher Tate5e08af02012-09-21 17:17:22 -07001643 int userRotationMode = Settings.System.getIntForUser(resolver,
1644 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
Jeff Brown207673cd2012-06-05 17:47:11 -07001645 WindowManagerPolicy.USER_ROTATION_FREE :
1646 WindowManagerPolicy.USER_ROTATION_LOCKED;
1647 if (mUserRotationMode != userRotationMode) {
1648 mUserRotationMode = userRotationMode;
1649 updateRotation = true;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001650 updateOrientationListenerLp();
1651 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001652
Dianne Hackbornc777e072010-02-12 13:07:59 -08001653 if (mSystemReady) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001654 int pointerLocation = Settings.System.getIntForUser(resolver,
1655 Settings.System.POINTER_LOCATION, 0, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001656 if (mPointerLocationMode != pointerLocation) {
1657 mPointerLocationMode = pointerLocation;
Jeff Brown70825162012-03-28 17:27:48 -07001658 mHandler.sendEmptyMessage(pointerLocation != 0 ?
1659 MSG_ENABLE_POINTER_LOCATION : MSG_DISABLE_POINTER_LOCATION);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001660 }
1661 }
1662 // use screen off timeout setting as the timeout for the lockscreen
Christopher Tate5e08af02012-09-21 17:17:22 -07001663 mLockScreenTimeout = Settings.System.getIntForUser(resolver,
1664 Settings.System.SCREEN_OFF_TIMEOUT, 0, UserHandle.USER_CURRENT);
1665 String imId = Settings.Secure.getStringForUser(resolver,
1666 Settings.Secure.DEFAULT_INPUT_METHOD, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001667 boolean hasSoftInput = imId != null && imId.length() > 0;
1668 if (mHasSoftInput != hasSoftInput) {
1669 mHasSoftInput = hasSoftInput;
1670 updateRotation = true;
1671 }
John Spurlockf1a36642013-10-12 17:50:42 -04001672 if (mImmersiveModeConfirmation != null) {
John Spurlock4355a532014-02-19 09:49:25 -05001673 mImmersiveModeConfirmation.loadSetting(mCurrentUserId);
John Spurlockd67ec252013-09-05 11:31:54 -04001674 }
John Spurlockc6d1c602014-01-17 15:22:06 -05001675 PolicyControl.reloadFromSetting(mContext);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001676 }
1677 if (updateRotation) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07001678 updateRotation(true);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001679 }
Jeff Brown70825162012-03-28 17:27:48 -07001680 }
1681
Jeff Browna20dda42014-05-27 20:57:24 -07001682 private void updateWakeGestureListenerLp() {
1683 if (shouldEnableWakeGestureLp()) {
1684 mWakeGestureListener.requestWakeUpTrigger();
1685 } else {
1686 mWakeGestureListener.cancelWakeUpTrigger();
1687 }
1688 }
1689
1690 private boolean shouldEnableWakeGestureLp() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07001691 return mWakeGestureEnabledSetting && !mAwake
Jeff Browna20dda42014-05-27 20:57:24 -07001692 && (!mLidControlsSleep || mLidState != LID_CLOSED)
1693 && mWakeGestureListener.isSupported();
1694 }
1695
Jeff Brown70825162012-03-28 17:27:48 -07001696 private void enablePointerLocation() {
1697 if (mPointerLocationView == null) {
1698 mPointerLocationView = new PointerLocationView(mContext);
1699 mPointerLocationView.setPrintCoords(false);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001700 WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
1701 WindowManager.LayoutParams.MATCH_PARENT,
1702 WindowManager.LayoutParams.MATCH_PARENT);
Jeff Brown3b2b3542010-10-15 00:54:27 -07001703 lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001704 lp.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN
1705 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
1706 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1707 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
Jeff Brown90fc9052012-10-01 14:44:24 -07001708 if (ActivityManager.isHighEndGfx()) {
1709 lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
1710 lp.privateFlags |=
1711 WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED;
1712 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001713 lp.format = PixelFormat.TRANSLUCENT;
1714 lp.setTitle("PointerLocation");
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001715 WindowManager wm = (WindowManager)
Dianne Hackbornc777e072010-02-12 13:07:59 -08001716 mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Browncc4f7db2011-08-30 20:34:48 -07001717 lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL;
Jeff Brown70825162012-03-28 17:27:48 -07001718 wm.addView(mPointerLocationView, lp);
Michael Wrightc9c487e2013-11-07 18:55:09 -08001719 mWindowManagerFuncs.registerPointerEventListener(mPointerLocationView);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001720 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001721 }
Jeff Brown70825162012-03-28 17:27:48 -07001722
1723 private void disablePointerLocation() {
Jeff Brown70825162012-03-28 17:27:48 -07001724 if (mPointerLocationView != null) {
Michael Wrightc9c487e2013-11-07 18:55:09 -08001725 mWindowManagerFuncs.unregisterPointerEventListener(mPointerLocationView);
1726 WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Brown70825162012-03-28 17:27:48 -07001727 wm.removeView(mPointerLocationView);
1728 mPointerLocationView = null;
1729 }
1730 }
1731
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001732 private int readRotation(int resID) {
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001733 try {
1734 int rotation = mContext.getResources().getInteger(resID);
1735 switch (rotation) {
1736 case 0:
1737 return Surface.ROTATION_0;
1738 case 90:
1739 return Surface.ROTATION_90;
1740 case 180:
1741 return Surface.ROTATION_180;
1742 case 270:
1743 return Surface.ROTATION_270;
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001744 }
1745 } catch (Resources.NotFoundException e) {
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001746 // fall through
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001747 }
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001748 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001749 }
1750
1751 /** {@inheritDoc} */
Craig Mautner88400d32012-09-30 12:35:45 -07001752 @Override
Dianne Hackbornc2293022013-02-06 23:14:49 -08001753 public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001754 int type = attrs.type;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001755
1756 outAppOp[0] = AppOpsManager.OP_NONE;
1757
Wale Ogunwale74bf0652015-01-12 10:24:36 -08001758 if (!((type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW)
1759 || (type >= FIRST_SUB_WINDOW && type <= LAST_SUB_WINDOW)
1760 || (type >= FIRST_SYSTEM_WINDOW && type <= LAST_SYSTEM_WINDOW))) {
1761 return WindowManagerGlobal.ADD_INVALID_TYPE;
1762 }
1763
1764 if (type < FIRST_SYSTEM_WINDOW || type > LAST_SYSTEM_WINDOW) {
1765 // Window manager will make sure these are okay.
Jeff Brown98365d72012-08-19 20:30:52 -07001766 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001767 }
1768 String permission = null;
1769 switch (type) {
1770 case TYPE_TOAST:
1771 // XXX right now the app process has complete control over
1772 // this... should introduce a token to let the system
1773 // monitor/control what they are doing.
Jason Monk1c7c3192014-06-26 12:52:18 -04001774 outAppOp[0] = AppOpsManager.OP_TOAST_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001775 break;
Daniel Sandler7d276c32012-01-30 14:33:52 -05001776 case TYPE_DREAM:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001777 case TYPE_INPUT_METHOD:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001778 case TYPE_WALLPAPER:
keunyounga446bf02013-06-21 19:07:57 -07001779 case TYPE_PRIVATE_PRESENTATION:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001780 case TYPE_VOICE_INTERACTION:
Svetoslav3a5c7212014-10-14 09:54:26 -07001781 case TYPE_ACCESSIBILITY_OVERLAY:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001782 // The window manager will check these.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001783 break;
1784 case TYPE_PHONE:
1785 case TYPE_PRIORITY_PHONE:
1786 case TYPE_SYSTEM_ALERT:
1787 case TYPE_SYSTEM_ERROR:
1788 case TYPE_SYSTEM_OVERLAY:
1789 permission = android.Manifest.permission.SYSTEM_ALERT_WINDOW;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001790 outAppOp[0] = AppOpsManager.OP_SYSTEM_ALERT_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001791 break;
1792 default:
1793 permission = android.Manifest.permission.INTERNAL_SYSTEM_WINDOW;
1794 }
1795 if (permission != null) {
1796 if (mContext.checkCallingOrSelfPermission(permission)
1797 != PackageManager.PERMISSION_GRANTED) {
Jeff Brown98365d72012-08-19 20:30:52 -07001798 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001799 }
1800 }
Jeff Brown98365d72012-08-19 20:30:52 -07001801 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001802 }
Craig Mautner88400d32012-09-30 12:35:45 -07001803
1804 @Override
1805 public boolean checkShowToOwnerOnly(WindowManager.LayoutParams attrs) {
1806
1807 // If this switch statement is modified, modify the comment in the declarations of
1808 // the type in {@link WindowManager.LayoutParams} as well.
1809 switch (attrs.type) {
1810 default:
1811 // These are the windows that by default are shown only to the user that created
1812 // them. If this needs to be overridden, set
1813 // {@link WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS} in
1814 // {@link WindowManager.LayoutParams}. Note that permission
1815 // {@link android.Manifest.permission.INTERNAL_SYSTEM_WINDOW} is required as well.
1816 if ((attrs.privateFlags & PRIVATE_FLAG_SHOW_FOR_ALL_USERS) == 0) {
1817 return true;
1818 }
1819 break;
1820
1821 // These are the windows that by default are shown to all users. However, to
1822 // protect against spoofing, check permissions below.
1823 case TYPE_APPLICATION_STARTING:
1824 case TYPE_BOOT_PROGRESS:
1825 case TYPE_DISPLAY_OVERLAY:
Selim Cinekf83e8242015-05-19 18:08:14 -07001826 case TYPE_INPUT_CONSUMER:
Jim Miller5ecd8112013-01-09 18:50:26 -08001827 case TYPE_KEYGUARD_SCRIM:
Craig Mautner88400d32012-09-30 12:35:45 -07001828 case TYPE_KEYGUARD_DIALOG:
1829 case TYPE_MAGNIFICATION_OVERLAY:
1830 case TYPE_NAVIGATION_BAR:
1831 case TYPE_NAVIGATION_BAR_PANEL:
1832 case TYPE_PHONE:
1833 case TYPE_POINTER:
1834 case TYPE_PRIORITY_PHONE:
Craig Mautner88400d32012-09-30 12:35:45 -07001835 case TYPE_SEARCH_BAR:
1836 case TYPE_STATUS_BAR:
1837 case TYPE_STATUS_BAR_PANEL:
1838 case TYPE_STATUS_BAR_SUB_PANEL:
1839 case TYPE_SYSTEM_DIALOG:
Craig Mautner88400d32012-09-30 12:35:45 -07001840 case TYPE_VOLUME_OVERLAY:
keunyounga446bf02013-06-21 19:07:57 -07001841 case TYPE_PRIVATE_PRESENTATION:
Craig Mautner88400d32012-09-30 12:35:45 -07001842 break;
1843 }
1844
1845 // Check if third party app has set window to system window type.
1846 return mContext.checkCallingOrSelfPermission(
1847 android.Manifest.permission.INTERNAL_SYSTEM_WINDOW)
1848 != PackageManager.PERMISSION_GRANTED;
1849 }
1850
Craig Mautner967212c2013-04-13 21:10:58 -07001851 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001852 public void adjustWindowParamsLw(WindowManager.LayoutParams attrs) {
1853 switch (attrs.type) {
1854 case TYPE_SYSTEM_OVERLAY:
Jeff Brown3b2b3542010-10-15 00:54:27 -07001855 case TYPE_SECURE_SYSTEM_OVERLAY:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001856 // These types of windows can't receive input events.
1857 attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1858 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001859 attrs.flags &= ~WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001860 break;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001861 case TYPE_STATUS_BAR:
1862
1863 // If the Keyguard is in a hidden state (occluded by another window), we force to
1864 // remove the wallpaper and keyguard flag so that any change in-flight after setting
1865 // the keyguard as occluded wouldn't set these flags again.
1866 // See {@link #processKeyguardSetHiddenResultLw}.
1867 if (mKeyguardHidden) {
1868 attrs.flags &= ~WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
1869 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
1870 }
1871 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001872 }
Adrian Roos38502112014-04-09 21:04:11 +02001873
1874 if (attrs.type != TYPE_STATUS_BAR) {
1875 // The status bar is the only window allowed to exhibit keyguard behavior.
1876 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
1877 }
Adrian Roosea562512014-05-05 13:33:03 +02001878
1879 if (ActivityManager.isHighEndGfx()
1880 && (attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0) {
Adrian Roosf5e9b5c2014-09-10 15:27:41 +02001881 attrs.subtreeSystemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
Adrian Roosea562512014-05-05 13:33:03 +02001882 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
1883 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001884 }
RoboErik8a2cfc32014-05-16 11:19:38 -07001885
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001886 void readLidState() {
Jeff Brown2e7760e2012-04-11 15:14:55 -07001887 mLidState = mWindowManagerFuncs.getLidState();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001888 }
RoboErik8a2cfc32014-05-16 11:19:38 -07001889
Michael Wright3818c922014-09-02 13:59:07 -07001890 private void readCameraLensCoverState() {
1891 mCameraLensCoverState = mWindowManagerFuncs.getCameraLensCoverState();
1892 }
1893
Jeff Browndaa37532012-05-01 15:54:03 -07001894 private boolean isHidden(int accessibilityMode) {
1895 switch (accessibilityMode) {
1896 case 1:
1897 return mLidState == LID_CLOSED;
1898 case 2:
1899 return mLidState == LID_OPEN;
1900 default:
1901 return false;
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001902 }
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001903 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001904
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001905 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07001906 @Override
Jeff Browndaa37532012-05-01 15:54:03 -07001907 public void adjustConfigurationLw(Configuration config, int keyboardPresence,
1908 int navigationPresence) {
1909 mHaveBuiltInKeyboard = (keyboardPresence & PRESENCE_INTERNAL) != 0;
1910
Jeff Brownf71343d2013-05-31 17:59:11 -07001911 readConfigurationDependentBehaviors();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001912 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07001913 applyLidSwitchState();
Jeff Brownd04a88c2011-01-16 14:05:47 -08001914
Jeff Browndaa37532012-05-01 15:54:03 -07001915 if (config.keyboard == Configuration.KEYBOARD_NOKEYS
1916 || (keyboardPresence == PRESENCE_INTERNAL
1917 && isHidden(mLidKeyboardAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001918 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_YES;
Jeff Browndaa37532012-05-01 15:54:03 -07001919 if (!mHasSoftInput) {
1920 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_YES;
1921 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001922 }
1923
Jeff Browndaa37532012-05-01 15:54:03 -07001924 if (config.navigation == Configuration.NAVIGATION_NONAV
1925 || (navigationPresence == PRESENCE_INTERNAL
1926 && isHidden(mLidNavigationAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001927 config.navigationHidden = Configuration.NAVIGATIONHIDDEN_YES;
Jeff Brownd04a88c2011-01-16 14:05:47 -08001928 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001929 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001930
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001931 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07001932 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001933 public int windowTypeToLayerLw(int type) {
1934 if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001935 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001936 }
1937 switch (type) {
keunyounga446bf02013-06-21 19:07:57 -07001938 case TYPE_PRIVATE_PRESENTATION:
1939 return 2;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001940 case TYPE_WALLPAPER:
1941 // wallpaper is at the bottom, though the window manager may move it.
1942 return 2;
1943 case TYPE_PHONE:
1944 return 3;
1945 case TYPE_SEARCH_BAR:
Jorim Jaggi225d3b52015-04-01 11:18:57 -07001946 case TYPE_VOICE_INTERACTION_STARTING:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001947 return 4;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001948 case TYPE_VOICE_INTERACTION:
1949 // voice interaction layer is almost immediately above apps.
1950 return 5;
Selim Cinekf83e8242015-05-19 18:08:14 -07001951 case TYPE_INPUT_CONSUMER:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001952 return 6;
Selim Cinekf83e8242015-05-19 18:08:14 -07001953 case TYPE_SYSTEM_DIALOG:
1954 return 7;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001955 case TYPE_TOAST:
1956 // toasts and the plugged-in battery thing
Selim Cinekf83e8242015-05-19 18:08:14 -07001957 return 8;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001958 case TYPE_PRIORITY_PHONE:
1959 // SIM errors and unlock. Not sure if this really should be in a high layer.
Selim Cinekf83e8242015-05-19 18:08:14 -07001960 return 9;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001961 case TYPE_DREAM:
1962 // used for Dreams (screensavers with TYPE_DREAM windows)
Selim Cinekf83e8242015-05-19 18:08:14 -07001963 return 10;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001964 case TYPE_SYSTEM_ALERT:
1965 // like the ANR / app crashed dialogs
Selim Cinekf83e8242015-05-19 18:08:14 -07001966 return 11;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001967 case TYPE_INPUT_METHOD:
1968 // on-screen keyboards and other such input method user interfaces go here.
Selim Cinekf83e8242015-05-19 18:08:14 -07001969 return 12;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001970 case TYPE_INPUT_METHOD_DIALOG:
1971 // on-screen keyboards and other such input method user interfaces go here.
Selim Cinekf83e8242015-05-19 18:08:14 -07001972 return 13;
Jim Miller5ecd8112013-01-09 18:50:26 -08001973 case TYPE_KEYGUARD_SCRIM:
1974 // the safety window that shows behind keyguard while keyguard is starting
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001975 return 14;
Selim Cinekf83e8242015-05-19 18:08:14 -07001976 case TYPE_STATUS_BAR_SUB_PANEL:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001977 return 15;
Selim Cinekf83e8242015-05-19 18:08:14 -07001978 case TYPE_STATUS_BAR:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001979 return 16;
Selim Cinekf83e8242015-05-19 18:08:14 -07001980 case TYPE_STATUS_BAR_PANEL:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001981 return 17;
Selim Cinekf83e8242015-05-19 18:08:14 -07001982 case TYPE_KEYGUARD_DIALOG:
1983 return 18;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001984 case TYPE_VOLUME_OVERLAY:
1985 // the on-screen volume indicator and controller shown when the user
1986 // changes the device volume
Selim Cinekf83e8242015-05-19 18:08:14 -07001987 return 19;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001988 case TYPE_SYSTEM_OVERLAY:
1989 // the on-screen volume indicator and controller shown when the user
1990 // changes the device volume
Selim Cinekf83e8242015-05-19 18:08:14 -07001991 return 20;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001992 case TYPE_NAVIGATION_BAR:
1993 // the navigation bar, if available, shows atop most things
Selim Cinekf83e8242015-05-19 18:08:14 -07001994 return 21;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001995 case TYPE_NAVIGATION_BAR_PANEL:
1996 // some panels (e.g. search) need to show on top of the navigation bar
Selim Cinekf83e8242015-05-19 18:08:14 -07001997 return 22;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001998 case TYPE_SYSTEM_ERROR:
1999 // system-level error dialogs
Selim Cinekf83e8242015-05-19 18:08:14 -07002000 return 23;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002001 case TYPE_MAGNIFICATION_OVERLAY:
2002 // used to highlight the magnified portion of a display
Selim Cinekf83e8242015-05-19 18:08:14 -07002003 return 24;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002004 case TYPE_DISPLAY_OVERLAY:
2005 // used to simulate secondary display devices
Selim Cinekf83e8242015-05-19 18:08:14 -07002006 return 25;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002007 case TYPE_DRAG:
2008 // the drag layer: input for drag-and-drop is associated with this window,
2009 // which sits above all other focusable windows
Selim Cinekf83e8242015-05-19 18:08:14 -07002010 return 26;
Svetoslav3a5c7212014-10-14 09:54:26 -07002011 case TYPE_ACCESSIBILITY_OVERLAY:
2012 // overlay put by accessibility services to intercept user interaction
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002013 return 27;
Selim Cinekf83e8242015-05-19 18:08:14 -07002014 case TYPE_SECURE_SYSTEM_OVERLAY:
Svetoslav3a5c7212014-10-14 09:54:26 -07002015 return 28;
Selim Cinekf83e8242015-05-19 18:08:14 -07002016 case TYPE_BOOT_PROGRESS:
2017 return 29;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002018 case TYPE_POINTER:
2019 // the (mouse) pointer layer
Svetoslav3a5c7212014-10-14 09:54:26 -07002020 return 30;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002021 }
2022 Log.e(TAG, "Unknown window type: " + type);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002023 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002024 }
2025
2026 /** {@inheritDoc} */
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002027 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002028 public int subWindowTypeToLayerLw(int type) {
2029 switch (type) {
2030 case TYPE_APPLICATION_PANEL:
2031 case TYPE_APPLICATION_ATTACHED_DIALOG:
2032 return APPLICATION_PANEL_SUBLAYER;
2033 case TYPE_APPLICATION_MEDIA:
2034 return APPLICATION_MEDIA_SUBLAYER;
Dianne Hackborn5cb8d792009-05-21 17:34:15 -07002035 case TYPE_APPLICATION_MEDIA_OVERLAY:
2036 return APPLICATION_MEDIA_OVERLAY_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002037 case TYPE_APPLICATION_SUB_PANEL:
2038 return APPLICATION_SUB_PANEL_SUBLAYER;
Wale Ogunwale0a4dc222015-04-14 12:58:42 -07002039 case TYPE_APPLICATION_ABOVE_SUB_PANEL:
2040 return APPLICATION_ABOVE_SUB_PANEL_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002041 }
2042 Log.e(TAG, "Unknown sub-window type: " + type);
2043 return 0;
2044 }
2045
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002046 @Override
Dianne Hackbornabe0da02009-09-18 01:55:39 -07002047 public int getMaxWallpaperLayer() {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002048 return windowTypeToLayerLw(TYPE_STATUS_BAR);
Dianne Hackbornabe0da02009-09-18 01:55:39 -07002049 }
2050
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002051 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002052 public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07002053 if (mHasNavigationBar) {
2054 // For a basic navigation bar, when we are in landscape mode we place
2055 // the navigation bar to the side.
Daniel Sandler4a066c52012-04-20 14:49:13 -04002056 if (mNavigationBarCanMove && fullWidth > fullHeight) {
2057 return fullWidth - mNavigationBarWidthForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07002058 }
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002059 }
2060 return fullWidth;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002061 }
2062
Jose Lima9546b202014-07-02 17:21:51 -07002063 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002064 public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07002065 if (mHasNavigationBar) {
2066 // For a basic navigation bar, when we are in portrait mode we place
2067 // the navigation bar to the bottom.
Daniel Sandler4a066c52012-04-20 14:49:13 -04002068 if (!mNavigationBarCanMove || fullWidth < fullHeight) {
2069 return fullHeight - mNavigationBarHeightForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07002070 }
2071 }
2072 return fullHeight;
Dianne Hackborn69cb8752011-05-19 18:13:32 -07002073 }
2074
Jose Lima9546b202014-07-02 17:21:51 -07002075 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002076 public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation) {
2077 return getNonDecorDisplayWidth(fullWidth, fullHeight, rotation);
Dianne Hackborn69cb8752011-05-19 18:13:32 -07002078 }
2079
Jose Lima9546b202014-07-02 17:21:51 -07002080 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002081 public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation) {
John Spurlock80f00c12013-06-13 11:10:51 -04002082 // There is a separate status bar at the top of the display. We don't count that as part
2083 // of the fixed decor, since it can hide; however, for purposes of configurations,
Dianne Hackborn077ee852012-04-09 16:27:07 -07002084 // we do want to exclude it since applications can't generally use that part
2085 // of the screen.
John Spurlock80f00c12013-06-13 11:10:51 -04002086 return getNonDecorDisplayHeight(fullWidth, fullHeight, rotation) - mStatusBarHeight;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002087 }
2088
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002089 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07002090 public boolean isForceHiding(WindowManager.LayoutParams attrs) {
2091 return (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 ||
Jim Millerab954542014-10-10 18:21:49 -07002092 (isKeyguardHostWindow(attrs) &&
2093 (mKeyguardDelegate != null && mKeyguardDelegate.isShowing())) ||
Adrian Roos69e510d2014-07-13 14:57:59 +02002094 (attrs.type == TYPE_KEYGUARD_SCRIM);
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002095 }
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002096
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002097 @Override
Jorim Jaggi0d674622014-05-21 01:34:15 +02002098 public boolean isKeyguardHostWindow(WindowManager.LayoutParams attrs) {
2099 return attrs.type == TYPE_STATUS_BAR;
2100 }
2101
2102 @Override
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002103 public boolean canBeForceHidden(WindowState win, WindowManager.LayoutParams attrs) {
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002104 switch (attrs.type) {
2105 case TYPE_STATUS_BAR:
2106 case TYPE_NAVIGATION_BAR:
2107 case TYPE_WALLPAPER:
2108 case TYPE_DREAM:
Jim Miller5ecd8112013-01-09 18:50:26 -08002109 case TYPE_KEYGUARD_SCRIM:
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002110 return false;
2111 default:
2112 return true;
2113 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002114 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002115
Craig Mautner7d7808f2014-09-11 18:02:38 -07002116 @Override
2117 public WindowState getWinShowWhenLockedLw() {
2118 return mWinShowWhenLocked;
2119 }
2120
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002121 /** {@inheritDoc} */
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002122 @Override
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07002123 public View addStartingWindow(IBinder appToken, String packageName, int theme,
2124 CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes,
Adam Powell04fe6eb2013-05-31 14:39:48 -07002125 int icon, int logo, int windowFlags) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002126 if (!SHOW_STARTING_ANIMATIONS) {
2127 return null;
2128 }
2129 if (packageName == null) {
2130 return null;
2131 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002132
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002133 WindowManager wm = null;
2134 View view = null;
2135
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002136 try {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002137 Context context = mContext;
Craig Mautner6fbda632012-07-03 09:26:39 -07002138 if (DEBUG_STARTING_WINDOW) Slog.d(TAG, "addStartingWindow " + packageName
2139 + ": nonLocalizedLabel=" + nonLocalizedLabel + " theme="
2140 + Integer.toHexString(theme));
Dianne Hackborn247fe742011-01-08 17:25:57 -08002141 if (theme != context.getThemeResId() || labelRes != 0) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002142 try {
2143 context = context.createPackageContext(packageName, 0);
Dianne Hackborn247fe742011-01-08 17:25:57 -08002144 context.setTheme(theme);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002145 } catch (PackageManager.NameNotFoundException e) {
2146 // Ignore
2147 }
2148 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002149
Jorim Jaggib10e33f2015-02-04 21:57:40 +01002150 Window win = new PhoneWindow(context);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002151 final TypedArray ta = win.getWindowStyle();
2152 if (ta.getBoolean(
2153 com.android.internal.R.styleable.Window_windowDisablePreview, false)
2154 || ta.getBoolean(
2155 com.android.internal.R.styleable.Window_windowShowWallpaper,false)) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002156 return null;
2157 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002158
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002159 Resources r = context.getResources();
2160 win.setTitle(r.getText(labelRes, nonLocalizedLabel));
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002161
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002162 win.setType(
2163 WindowManager.LayoutParams.TYPE_APPLICATION_STARTING);
Adrian Roos602c68e2015-04-24 16:03:47 -07002164
2165 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
2166 // Assumes it's safe to show starting windows of launched apps while
2167 // the keyguard is being hidden. This is okay because starting windows never show
2168 // secret information.
2169 if (mKeyguardHidden) {
2170 windowFlags |= FLAG_SHOW_WHEN_LOCKED;
2171 }
2172 }
2173
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002174 // Force the window flags: this is a fake window, so it is not really
2175 // touchable or focusable by the user. We also add in the ALT_FOCUSABLE_IM
2176 // flag because we do know that the next window will take input
2177 // focus, so we want to get the IME window up on top of us right away.
2178 win.setFlags(
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08002179 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002180 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
2181 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
2182 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08002183 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002184 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
2185 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
2186 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002187
Adam Powell04fe6eb2013-05-31 14:39:48 -07002188 win.setDefaultIcon(icon);
2189 win.setDefaultLogo(logo);
2190
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002191 win.setLayout(WindowManager.LayoutParams.MATCH_PARENT,
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07002192 WindowManager.LayoutParams.MATCH_PARENT);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002193
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002194 final WindowManager.LayoutParams params = win.getAttributes();
2195 params.token = appToken;
2196 params.packageName = packageName;
2197 params.windowAnimations = win.getWindowStyle().getResourceId(
2198 com.android.internal.R.styleable.Window_windowAnimationStyle, 0);
John Reck61375a82014-09-18 19:27:48 +00002199 params.privateFlags |=
2200 WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED;
Craig Mautner88400d32012-09-30 12:35:45 -07002201 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
Adam Lesinski95c42972013-10-02 10:13:27 -07002202
2203 if (!compatInfo.supportsScreen()) {
2204 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
2205 }
2206
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002207 params.setTitle("Starting " + packageName);
2208
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002209 wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
2210 view = win.getDecorView();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002211
2212 if (win.isFloating()) {
2213 // Whoops, there is no way to display an animation/preview
2214 // of such a thing! After all that work... let's skip it.
2215 // (Note that we must do this here because it is in
2216 // getDecorView() where the theme is evaluated... maybe
2217 // we should peek the floating attribute from the theme
2218 // earlier.)
2219 return null;
2220 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002221
Craig Mautner6fbda632012-07-03 09:26:39 -07002222 if (DEBUG_STARTING_WINDOW) Slog.d(
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002223 TAG, "Adding starting window for " + packageName
2224 + " / " + appToken + ": "
2225 + (view.getParent() != null ? view : null));
2226
2227 wm.addView(view, params);
2228
2229 // Only return the view if it was successfully added to the
2230 // window manager... which we can tell by it having a parent.
2231 return view.getParent() != null ? view : null;
Jeff Brown98365d72012-08-19 20:30:52 -07002232 } catch (WindowManager.BadTokenException e) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002233 // ignore
Craig Mautner42bf39e2014-02-21 16:46:22 -08002234 Log.w(TAG, appToken + " already running, starting window not displayed. " +
2235 e.getMessage());
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002236 } catch (RuntimeException e) {
2237 // don't crash if something else bad happens, for example a
2238 // failure loading resources because we are loading from an app
2239 // on external storage that has been unmounted.
2240 Log.w(TAG, appToken + " failed creating starting window", e);
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002241 } finally {
2242 if (view != null && view.getParent() == null) {
2243 Log.w(TAG, "view not successfully added to wm, removing view");
2244 wm.removeViewImmediate(view);
2245 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002246 }
2247
2248 return null;
2249 }
2250
2251 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07002252 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002253 public void removeStartingWindow(IBinder appToken, View window) {
Craig Mautner276a6eb2014-11-04 15:32:57 -08002254 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Removing starting window for " + appToken + ": "
2255 + window + " Callers=" + Debug.getCallers(4));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002256
2257 if (window != null) {
Dianne Hackborn5fd21692011-06-07 14:09:47 -07002258 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002259 wm.removeView(window);
2260 }
2261 }
2262
2263 /**
2264 * Preflight adding a window to the system.
RoboErik8a2cfc32014-05-16 11:19:38 -07002265 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002266 * Currently enforces that three window types are singletons:
2267 * <ul>
2268 * <li>STATUS_BAR_TYPE</li>
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002269 * <li>KEYGUARD_TYPE</li>
2270 * </ul>
RoboErik8a2cfc32014-05-16 11:19:38 -07002271 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002272 * @param win The window to be added
2273 * @param attrs Information about the window to be added
RoboErik8a2cfc32014-05-16 11:19:38 -07002274 *
Jeff Brown98365d72012-08-19 20:30:52 -07002275 * @return If ok, WindowManagerImpl.ADD_OKAY. If too many singletons,
2276 * WindowManagerImpl.ADD_MULTIPLE_SINGLETON
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002277 */
Jose Lima9546b202014-07-02 17:21:51 -07002278 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002279 public int prepareAddWindowLw(WindowState win, WindowManager.LayoutParams attrs) {
2280 switch (attrs.type) {
2281 case TYPE_STATUS_BAR:
Joe Onorato8bc6c512010-06-04 16:21:12 -04002282 mContext.enforceCallingOrSelfPermission(
2283 android.Manifest.permission.STATUS_BAR_SERVICE,
2284 "PhoneWindowManager");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002285 if (mStatusBar != null) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002286 if (mStatusBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07002287 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002288 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002289 }
2290 mStatusBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04002291 mStatusBarController.setWindow(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002292 break;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002293 case TYPE_NAVIGATION_BAR:
2294 mContext.enforceCallingOrSelfPermission(
2295 android.Manifest.permission.STATUS_BAR_SERVICE,
2296 "PhoneWindowManager");
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002297 if (mNavigationBar != null) {
2298 if (mNavigationBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07002299 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002300 }
2301 }
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002302 mNavigationBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04002303 mNavigationBarController.setWindow(win);
Craig Mautnereda67292013-04-28 13:50:14 -07002304 if (DEBUG_LAYOUT) Slog.i(TAG, "NAVIGATION BAR: " + mNavigationBar);
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002305 break;
Jim Millere898ac52012-04-06 17:10:57 -07002306 case TYPE_NAVIGATION_BAR_PANEL:
Dianne Hackborn08743722009-12-21 12:16:51 -08002307 case TYPE_STATUS_BAR_PANEL:
Joe Onorato29fc2c92010-11-24 10:26:50 -08002308 case TYPE_STATUS_BAR_SUB_PANEL:
Jorim Jaggi225d3b52015-04-01 11:18:57 -07002309 case TYPE_VOICE_INTERACTION_STARTING:
Joe Onorato29fc2c92010-11-24 10:26:50 -08002310 mContext.enforceCallingOrSelfPermission(
2311 android.Manifest.permission.STATUS_BAR_SERVICE,
2312 "PhoneWindowManager");
Joe Onorato29fc2c92010-11-24 10:26:50 -08002313 break;
Jim Miller5ecd8112013-01-09 18:50:26 -08002314 case TYPE_KEYGUARD_SCRIM:
Jim Miller25190572013-02-28 17:36:24 -08002315 if (mKeyguardScrim != null) {
2316 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
2317 }
Jim Miller5ecd8112013-01-09 18:50:26 -08002318 mKeyguardScrim = win;
2319 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002320 }
Jeff Brown98365d72012-08-19 20:30:52 -07002321 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002322 }
2323
2324 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07002325 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002326 public void removeWindowLw(WindowState win) {
2327 if (mStatusBar == win) {
2328 mStatusBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04002329 mStatusBarController.setWindow(null);
Jim Millerc0b676d2013-03-22 16:11:08 -07002330 mKeyguardDelegate.showScrim();
Jim Miller5ecd8112013-01-09 18:50:26 -08002331 } else if (mKeyguardScrim == win) {
2332 Log.v(TAG, "Removing keyguard scrim");
2333 mKeyguardScrim = null;
2334 } if (mNavigationBar == win) {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002335 mNavigationBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04002336 mNavigationBarController.setWindow(null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002337 }
2338 }
2339
2340 static final boolean PRINT_ANIM = false;
RoboErik8a2cfc32014-05-16 11:19:38 -07002341
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002342 /** {@inheritDoc} */
Craig Mautner4b71aa12012-12-27 17:20:01 -08002343 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002344 public int selectAnimationLw(WindowState win, int transit) {
2345 if (PRINT_ANIM) Log.i(TAG, "selectAnimation in " + win
2346 + ": transit=" + transit);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002347 if (win == mStatusBar) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002348 boolean isKeyguard = (win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002349 if (transit == TRANSIT_EXIT
2350 || transit == TRANSIT_HIDE) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002351 return isKeyguard ? -1 : R.anim.dock_top_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002352 } else if (transit == TRANSIT_ENTER
2353 || transit == TRANSIT_SHOW) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002354 return isKeyguard ? -1 : R.anim.dock_top_enter;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002355 }
2356 } else if (win == mNavigationBar) {
2357 // This can be on either the bottom or the right.
2358 if (mNavigationBarOnBottom) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08002359 if (transit == TRANSIT_EXIT
2360 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002361 return R.anim.dock_bottom_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002362 } else if (transit == TRANSIT_ENTER
2363 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002364 return R.anim.dock_bottom_enter;
2365 }
2366 } else {
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_right_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_right_enter;
2373 }
2374 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08002375 }
2376
2377 if (transit == TRANSIT_PREVIEW_DONE) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002378 if (win.hasAppShownWindows()) {
2379 if (PRINT_ANIM) Log.i(TAG, "**** STARTING EXIT");
2380 return com.android.internal.R.anim.app_starting_exit;
2381 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07002382 } else if (win.getAttrs().type == TYPE_DREAM && mDreamingLockscreen
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002383 && transit == TRANSIT_ENTER) {
2384 // Special case: we are animating in a dream, while the keyguard
2385 // is shown. We don't want an animation on the dream, because
2386 // we need it shown immediately with the keyguard animating away
2387 // to reveal it.
2388 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002389 }
2390
2391 return 0;
2392 }
2393
Craig Mautner3c174372013-02-21 17:54:37 -08002394 @Override
2395 public void selectRotationAnimationLw(int anim[]) {
2396 if (PRINT_ANIM) Slog.i(TAG, "selectRotationAnimation mTopFullscreen="
2397 + mTopFullscreenOpaqueWindowState + " rotationAnimation="
2398 + (mTopFullscreenOpaqueWindowState == null ?
2399 "0" : mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation));
2400 if (mTopFullscreenOpaqueWindowState != null && mTopIsFullscreen) {
2401 switch (mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation) {
2402 case ROTATION_ANIMATION_CROSSFADE:
2403 anim[0] = R.anim.rotation_animation_xfade_exit;
2404 anim[1] = R.anim.rotation_animation_enter;
2405 break;
2406 case ROTATION_ANIMATION_JUMPCUT:
2407 anim[0] = R.anim.rotation_animation_jump_exit;
2408 anim[1] = R.anim.rotation_animation_enter;
2409 break;
2410 case ROTATION_ANIMATION_ROTATE:
2411 default:
2412 anim[0] = anim[1] = 0;
2413 break;
2414 }
2415 } else {
2416 anim[0] = anim[1] = 0;
2417 }
2418 }
2419
2420 @Override
2421 public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId,
2422 boolean forceDefault) {
2423 switch (exitAnimId) {
2424 case R.anim.rotation_animation_xfade_exit:
2425 case R.anim.rotation_animation_jump_exit:
2426 // These are the only cases that matter.
2427 if (forceDefault) {
2428 return false;
2429 }
2430 int anim[] = new int[2];
2431 selectRotationAnimationLw(anim);
2432 return (exitAnimId == anim[0] && enterAnimId == anim[1]);
2433 default:
2434 return true;
2435 }
2436 }
2437
2438 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002439 public Animation createForceHideEnterAnimation(boolean onWallpaper,
2440 boolean goingToNotificationShade) {
2441 if (goingToNotificationShade) {
2442 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_behind_enter_fade_in);
Craig Mautnerb8340802014-11-04 15:32:57 -08002443 }
Craig Mautner276a6eb2014-11-04 15:32:57 -08002444
2445 AnimationSet set = (AnimationSet) AnimationUtils.loadAnimation(mContext, onWallpaper ?
2446 R.anim.lock_screen_behind_enter_wallpaper :
2447 R.anim.lock_screen_behind_enter);
2448
2449 // TODO: Use XML interpolators when we have log interpolators available in XML.
2450 final List<Animation> animations = set.getAnimations();
2451 for (int i = animations.size() - 1; i >= 0; --i) {
2452 animations.get(i).setInterpolator(mLogDecelerateInterpolator);
2453 }
2454
2455 return set;
Jorim Jaggi76a16232014-08-08 17:00:47 +02002456 }
2457
2458
2459 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002460 public Animation createForceHideWallpaperExitAnimation(boolean goingToNotificationShade) {
2461 if (goingToNotificationShade) {
2462 return null;
2463 } else {
2464 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_wallpaper_exit);
2465 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002466 }
John Spurlockc8b46ca2013-04-08 12:59:26 -04002467
2468 private static void awakenDreams() {
2469 IDreamManager dreamManager = getDreamManager();
2470 if (dreamManager != null) {
2471 try {
2472 dreamManager.awaken();
2473 } catch (RemoteException e) {
2474 // fine, stay asleep then
2475 }
2476 }
2477 }
2478
2479 static IDreamManager getDreamManager() {
2480 return IDreamManager.Stub.asInterface(
2481 ServiceManager.checkService(DreamService.DREAM_SERVICE));
2482 }
2483
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002484 TelecomManager getTelecommService() {
2485 return (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002486 }
2487
Jeff Brown4d396052010-10-29 21:50:21 -07002488 static IAudioService getAudioService() {
2489 IAudioService audioService = IAudioService.Stub.asInterface(
2490 ServiceManager.checkService(Context.AUDIO_SERVICE));
2491 if (audioService == null) {
2492 Log.w(TAG, "Unable to find IAudioService interface.");
2493 }
2494 return audioService;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002495 }
2496
2497 boolean keyguardOn() {
Jim Millerab954542014-10-10 18:21:49 -07002498 return isKeyguardShowingAndNotOccluded() || inKeyguardRestrictedKeyInputMode();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002499 }
2500
2501 private static final int[] WINDOW_TYPES_WHERE_HOME_DOESNT_WORK = {
2502 WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
2503 WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
2504 };
2505
2506 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002507 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002508 public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002509 final boolean keyguardOn = keyguardOn();
Jeff Brown1f245102010-11-18 20:53:46 -08002510 final int keyCode = event.getKeyCode();
2511 final int repeatCount = event.getRepeatCount();
2512 final int metaState = event.getMetaState();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002513 final int flags = event.getFlags();
Jeff Brown1f245102010-11-18 20:53:46 -08002514 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
2515 final boolean canceled = event.isCanceled();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002516
Jeff Brown40013652012-05-16 21:22:36 -07002517 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002518 Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount="
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002519 + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed
2520 + " canceled=" + canceled);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002521 }
2522
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002523 // If we think we might have a volume down & power key chord on the way
2524 // but we're not sure, then tell the dispatcher to wait a little while and
2525 // try again later before dispatching.
Christopher Tatee90585f2012-03-05 18:56:25 -08002526 if (mScreenshotChordEnabled && (flags & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07002527 if (mScreenshotChordVolumeDownKeyTriggered && !mScreenshotChordPowerKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002528 final long now = SystemClock.uptimeMillis();
Jeff Brown13f00f02014-10-31 14:45:50 -07002529 final long timeoutTime = mScreenshotChordVolumeDownKeyTime
2530 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002531 if (now < timeoutTime) {
2532 return timeoutTime - now;
2533 }
2534 }
2535 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
Jeff Brown13f00f02014-10-31 14:45:50 -07002536 && mScreenshotChordVolumeDownKeyConsumed) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002537 if (!down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07002538 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002539 }
2540 return -1;
2541 }
2542 }
2543
Michael Wright6a62e552014-06-03 19:19:48 -07002544 // Cancel any pending meta actions if we see any other keys being pressed between the down
2545 // of the meta key and its corresponding up.
Michael Wright251e35d2014-08-22 15:40:27 -07002546 if (mPendingMetaAction && !KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07002547 mPendingMetaAction = false;
2548 }
2549
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002550 // First we always handle the home key here, so applications
2551 // can never break it, although if keyguard is on, we do let
2552 // it handle it, because that gives us the correct 5 second
2553 // timeout.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002554 if (keyCode == KeyEvent.KEYCODE_HOME) {
Michael Jurka7f2668c2012-03-27 07:49:52 -07002555
Jeff Brown49ed71d2010-12-06 17:13:33 -08002556 // If we have released the home key, and didn't do anything else
2557 // while it was pressed, then it is time to go home!
Michael Jurka7f2668c2012-03-27 07:49:52 -07002558 if (!down) {
Jeff Browncaca8812013-05-09 13:34:33 -07002559 cancelPreloadRecentApps();
2560
Jeff Brown49ed71d2010-12-06 17:13:33 -08002561 mHomePressed = false;
Jeff Browncaca8812013-05-09 13:34:33 -07002562 if (mHomeConsumed) {
2563 mHomeConsumed = false;
Michael Jurka7f2668c2012-03-27 07:49:52 -07002564 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002565 }
Jeff Browncaca8812013-05-09 13:34:33 -07002566
2567 if (canceled) {
2568 Log.i(TAG, "Ignoring HOME; event canceled.");
2569 return -1;
2570 }
2571
Yorke Lee4f803242014-12-15 23:22:06 +00002572 // If an incoming call is ringing, HOME is totally disabled.
2573 // (The user is already on the InCallUI at this point,
2574 // and his ONLY options are to answer or reject the call.)
2575 TelecomManager telecomManager = getTelecommService();
2576 if (telecomManager != null && telecomManager.isRinging()) {
2577 Log.i(TAG, "Ignoring HOME; there's a ringing incoming call.");
2578 return -1;
2579 }
2580
Jeff Browncaca8812013-05-09 13:34:33 -07002581 // Delay handling home if a double-tap is possible.
2582 if (mDoubleTapOnHomeBehavior != DOUBLE_TAP_HOME_NOTHING) {
2583 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); // just in case
2584 mHomeDoubleTapPending = true;
2585 mHandler.postDelayed(mHomeDoubleTapTimeoutRunnable,
2586 ViewConfiguration.getDoubleTapTimeout());
2587 return -1;
2588 }
2589
Jeff Brown13f00f02014-10-31 14:45:50 -07002590 handleShortPressOnHome();
Jeff Browncaca8812013-05-09 13:34:33 -07002591 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002592 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002593
2594 // If a system window has focus, then it doesn't make sense
2595 // right now to interact with applications.
2596 WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null;
2597 if (attrs != null) {
2598 final int type = attrs.type;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002599 if (type == WindowManager.LayoutParams.TYPE_KEYGUARD_SCRIM
2600 || type == WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG
2601 || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002602 // the "app" is keyguard, so give it the key
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002603 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002604 }
2605 final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length;
2606 for (int i=0; i<typeCount; i++) {
2607 if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) {
2608 // don't do anything, but also don't pass it to the app
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002609 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002610 }
2611 }
2612 }
Jeff Browncaca8812013-05-09 13:34:33 -07002613
2614 // Remember that home is pressed and handle special actions.
2615 if (repeatCount == 0) {
2616 mHomePressed = true;
2617 if (mHomeDoubleTapPending) {
2618 mHomeDoubleTapPending = false;
2619 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable);
2620 handleDoubleTapOnHome();
2621 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI
2622 || mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
2623 preloadRecentApps();
Michael Jurka7f2668c2012-03-27 07:49:52 -07002624 }
Jeff Browncaca8812013-05-09 13:34:33 -07002625 } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) {
2626 if (!keyguardOn) {
2627 handleLongPressOnHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002628 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002629 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002630 return -1;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002631 } else if (keyCode == KeyEvent.KEYCODE_MENU) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002632 // Hijack modified menu keys for debugging features
2633 final int chordBug = KeyEvent.META_SHIFT_ON;
2634
2635 if (down && repeatCount == 0) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002636 if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002637 Intent intent = new Intent(Intent.ACTION_BUG_REPORT);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002638 mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT,
2639 null, null, null, 0, null, null);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002640 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002641 } else if (SHOW_PROCESSES_ON_ALT_MENU &&
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002642 (metaState & KeyEvent.META_ALT_ON) == KeyEvent.META_ALT_ON) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002643 Intent service = new Intent();
2644 service.setClassName(mContext, "com.android.server.LoadAverageService");
2645 ContentResolver res = mContext.getContentResolver();
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002646 boolean shown = Settings.Global.getInt(
2647 res, Settings.Global.SHOW_PROCESSES, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002648 if (!shown) {
2649 mContext.startService(service);
2650 } else {
2651 mContext.stopService(service);
2652 }
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002653 Settings.Global.putInt(
2654 res, Settings.Global.SHOW_PROCESSES, shown ? 0 : 1);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002655 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002656 }
2657 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002658 } else if (keyCode == KeyEvent.KEYCODE_SEARCH) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002659 if (down) {
2660 if (repeatCount == 0) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002661 mSearchKeyShortcutPending = true;
2662 mConsumeSearchKeyUp = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002663 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002664 } else {
2665 mSearchKeyShortcutPending = false;
2666 if (mConsumeSearchKeyUp) {
2667 mConsumeSearchKeyUp = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002668 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002669 }
2670 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002671 return 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002672 } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) {
Michael Wrightc9ebea72013-01-16 19:25:02 -08002673 if (!keyguardOn) {
Jeff Browncaca8812013-05-09 13:34:33 -07002674 if (down && repeatCount == 0) {
2675 preloadRecentApps();
2676 } else if (!down) {
2677 toggleRecentApps();
Michael Wrightc9ebea72013-01-16 19:25:02 -08002678 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002679 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002680 return -1;
Jun Mukaid21b3c82015-04-23 14:09:34 -07002681 } else if (keyCode == KeyEvent.KEYCODE_N && event.isMetaPressed()) {
2682 if (down) {
2683 IStatusBarService service = getStatusBarService();
2684 if (service != null) {
2685 try {
2686 service.expandNotificationsPanel();
2687 } catch (RemoteException e) {
2688 // do nothing.
2689 }
2690 }
2691 }
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002692 } else if (keyCode == KeyEvent.KEYCODE_ASSIST) {
2693 if (down) {
2694 if (repeatCount == 0) {
2695 mAssistKeyLongPressed = false;
2696 } else if (repeatCount == 1) {
2697 mAssistKeyLongPressed = true;
2698 if (!keyguardOn) {
2699 launchAssistLongPressAction();
2700 }
2701 }
2702 } else {
2703 if (mAssistKeyLongPressed) {
2704 mAssistKeyLongPressed = false;
2705 } else {
2706 if (!keyguardOn) {
2707 launchAssistAction();
2708 }
2709 }
2710 }
2711 return -1;
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002712 } else if (keyCode == KeyEvent.KEYCODE_VOICE_ASSIST) {
2713 if (!down) {
2714 Intent voiceIntent;
Michael Wright869a67c2014-08-26 19:33:06 -07002715 if (!keyguardOn) {
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002716 voiceIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
2717 } else {
2718 voiceIntent = new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
Michael Wright869a67c2014-08-26 19:33:06 -07002719 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, true);
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002720 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00002721 startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002722 }
Jeff Sharkey2991fa32012-12-05 18:06:43 -08002723 } else if (keyCode == KeyEvent.KEYCODE_SYSRQ) {
2724 if (down && repeatCount == 0) {
2725 mHandler.post(mScreenshotRunnable);
2726 }
2727 return -1;
Michael Wrightb854e242013-02-05 17:54:02 -08002728 } else if (keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP
2729 || keyCode == KeyEvent.KEYCODE_BRIGHTNESS_DOWN) {
2730 if (down) {
2731 int direction = keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP ? 1 : -1;
2732
2733 // Disable autobrightness if it's on
2734 int auto = Settings.System.getIntForUser(
2735 mContext.getContentResolver(),
2736 Settings.System.SCREEN_BRIGHTNESS_MODE,
2737 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2738 UserHandle.USER_CURRENT_OR_SELF);
2739 if (auto != 0) {
2740 Settings.System.putIntForUser(mContext.getContentResolver(),
2741 Settings.System.SCREEN_BRIGHTNESS_MODE,
2742 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2743 UserHandle.USER_CURRENT_OR_SELF);
2744 }
2745
2746 int min = mPowerManager.getMinimumScreenBrightnessSetting();
2747 int max = mPowerManager.getMaximumScreenBrightnessSetting();
2748 int step = (max - min + BRIGHTNESS_STEPS - 1) / BRIGHTNESS_STEPS * direction;
2749 int brightness = Settings.System.getIntForUser(mContext.getContentResolver(),
2750 Settings.System.SCREEN_BRIGHTNESS,
2751 mPowerManager.getDefaultScreenBrightnessSetting(),
2752 UserHandle.USER_CURRENT_OR_SELF);
2753 brightness += step;
2754 // Make sure we don't go beyond the limits.
2755 brightness = Math.min(max, brightness);
2756 brightness = Math.max(min, brightness);
2757
2758 Settings.System.putIntForUser(mContext.getContentResolver(),
2759 Settings.System.SCREEN_BRIGHTNESS, brightness,
2760 UserHandle.USER_CURRENT_OR_SELF);
Bart Sears8b1c27c2015-03-18 23:51:02 +00002761 startActivityAsUser(new Intent(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG),
Alan Viverette5a399492014-07-14 16:19:38 -07002762 UserHandle.CURRENT_OR_SELF);
Michael Wrightb854e242013-02-05 17:54:02 -08002763 }
2764 return -1;
Michael Wrightce0c13a2014-07-30 10:49:21 -07002765 } else if (KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07002766 if (down) {
2767 mPendingMetaAction = true;
2768 } else if (mPendingMetaAction) {
Michael Wright8ab940a2014-09-01 11:01:27 -07002769 launchAssistAction(Intent.EXTRA_ASSIST_INPUT_HINT_KEYBOARD);
Michael Wright6a62e552014-06-03 19:19:48 -07002770 }
2771 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002772 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002773
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002774 // Shortcuts are invoked through Search+key, so intercept those here
Jeff Browncaab4d02010-12-09 22:13:41 -08002775 // Any printing key that is chorded with Search should be consumed
2776 // even if no shortcut was invoked. This prevents text from being
2777 // inadvertently inserted when using a keyboard that has built-in macro
2778 // shortcut keys (that emit Search+x) and some of them are not registered.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002779 if (mSearchKeyShortcutPending) {
Jeff Browncaab4d02010-12-09 22:13:41 -08002780 final KeyCharacterMap kcm = event.getKeyCharacterMap();
2781 if (kcm.isPrintingKey(keyCode)) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002782 mConsumeSearchKeyUp = true;
2783 mSearchKeyShortcutPending = false;
Jeff Browncaab4d02010-12-09 22:13:41 -08002784 if (down && repeatCount == 0 && !keyguardOn) {
2785 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState);
2786 if (shortcutIntent != null) {
2787 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002788 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00002789 startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002790 } catch (ActivityNotFoundException ex) {
2791 Slog.w(TAG, "Dropping shortcut key combination because "
2792 + "the activity to which it is registered was not found: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002793 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode), ex);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002794 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002795 } else {
2796 Slog.i(TAG, "Dropping unregistered shortcut key combination: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002797 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002798 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002799 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002800 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002801 }
2802 }
2803
Jeff Brown68b909d2011-12-07 16:36:01 -08002804 // Invoke shortcuts using Meta.
Jeff Brown602ab322012-05-16 13:33:47 -07002805 if (down && repeatCount == 0 && !keyguardOn
Jeff Brown68b909d2011-12-07 16:36:01 -08002806 && (metaState & KeyEvent.META_META_ON) != 0) {
2807 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brown602ab322012-05-16 13:33:47 -07002808 if (kcm.isPrintingKey(keyCode)) {
2809 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode,
2810 metaState & ~(KeyEvent.META_META_ON
2811 | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON));
2812 if (shortcutIntent != null) {
2813 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2814 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00002815 startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brown602ab322012-05-16 13:33:47 -07002816 } catch (ActivityNotFoundException ex) {
2817 Slog.w(TAG, "Dropping shortcut key combination because "
2818 + "the activity to which it is registered was not found: "
2819 + "META+" + KeyEvent.keyCodeToString(keyCode), ex);
2820 }
2821 return -1;
Jeff Brown68b909d2011-12-07 16:36:01 -08002822 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002823 }
2824 }
2825
Jeff Brown6651a632011-11-28 12:59:11 -08002826 // Handle application launch keys.
Jeff Brown602ab322012-05-16 13:33:47 -07002827 if (down && repeatCount == 0 && !keyguardOn) {
Jeff Brown6651a632011-11-28 12:59:11 -08002828 String category = sApplicationLaunchKeyCategories.get(keyCode);
2829 if (category != null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -08002830 Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category);
Jeff Brown6651a632011-11-28 12:59:11 -08002831 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2832 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00002833 startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brown6651a632011-11-28 12:59:11 -08002834 } catch (ActivityNotFoundException ex) {
2835 Slog.w(TAG, "Dropping application launch key because "
2836 + "the activity to which it is registered was not found: "
2837 + "keyCode=" + keyCode + ", category=" + category, ex);
2838 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002839 return -1;
Jeff Brown6651a632011-11-28 12:59:11 -08002840 }
2841 }
2842
Michael Wright61c46752014-08-21 16:57:33 -07002843 // Display task switcher for ALT-TAB.
Jeff Brown68b909d2011-12-07 16:36:01 -08002844 if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_TAB) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002845 if (mRecentAppsHeldModifiers == 0 && !keyguardOn) {
Jeff Brown68b909d2011-12-07 16:36:01 -08002846 final int shiftlessModifiers = event.getModifiers() & ~KeyEvent.META_SHIFT_MASK;
Michael Wright61c46752014-08-21 16:57:33 -07002847 if (KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_ALT_ON)) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002848 mRecentAppsHeldModifiers = shiftlessModifiers;
2849 showRecentApps(true);
Jeff Brown68b909d2011-12-07 16:36:01 -08002850 return -1;
2851 }
2852 }
Winson Chung1e8d71b2014-05-16 17:05:22 -07002853 } else if (!down && mRecentAppsHeldModifiers != 0
2854 && (metaState & mRecentAppsHeldModifiers) == 0) {
2855 mRecentAppsHeldModifiers = 0;
Winson Chungcdcd4872014-08-05 18:00:13 -07002856 hideRecentApps(true, false);
Jeff Brown68b909d2011-12-07 16:36:01 -08002857 }
2858
Jeff Browncf39bdf2012-05-18 14:41:19 -07002859 // Handle keyboard language switching.
2860 if (down && repeatCount == 0
2861 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2862 || (keyCode == KeyEvent.KEYCODE_SPACE
2863 && (metaState & KeyEvent.META_CTRL_MASK) != 0))) {
2864 int direction = (metaState & KeyEvent.META_SHIFT_MASK) != 0 ? -1 : 1;
2865 mWindowManagerFuncs.switchKeyboardLayout(event.getDeviceId(), direction);
2866 return -1;
2867 }
2868 if (mLanguageSwitchKeyPressed && !down
2869 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2870 || keyCode == KeyEvent.KEYCODE_SPACE)) {
2871 mLanguageSwitchKeyPressed = false;
2872 return -1;
2873 }
2874
Jeff Brown13f00f02014-10-31 14:45:50 -07002875 if (isValidGlobalKey(keyCode)
2876 && mGlobalKeyManager.handleGlobalKey(mContext, keyCode, event)) {
Justin Kohd378ad72013-04-01 12:18:26 -07002877 return -1;
2878 }
2879
Michael Wright6a62e552014-06-03 19:19:48 -07002880 // Reserve all the META modifier combos for system behavior
Michael Wrightce0c13a2014-07-30 10:49:21 -07002881 if ((metaState & KeyEvent.META_META_ON) != 0) {
Michael Wright6a62e552014-06-03 19:19:48 -07002882 return -1;
2883 }
2884
Jeff Brown68b909d2011-12-07 16:36:01 -08002885 // Let the application handle the key.
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002886 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002887 }
2888
Jeff Brown3915bb82010-11-05 15:02:16 -07002889 /** {@inheritDoc} */
2890 @Override
Jeff Brown49ed71d2010-12-06 17:13:33 -08002891 public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown54875002011-04-06 15:33:01 -07002892 // Note: This method is only called if the initial down was unhandled.
Jeff Brown40013652012-05-16 21:22:36 -07002893 if (DEBUG_INPUT) {
Jeff Brown1f245102010-11-18 20:53:46 -08002894 Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction()
2895 + ", flags=" + event.getFlags()
2896 + ", keyCode=" + event.getKeyCode()
2897 + ", scanCode=" + event.getScanCode()
2898 + ", metaState=" + event.getMetaState()
2899 + ", repeatCount=" + event.getRepeatCount()
2900 + ", policyFlags=" + policyFlags);
Jeff Brown3915bb82010-11-05 15:02:16 -07002901 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002902
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002903 KeyEvent fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002904 if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
2905 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002906 final int keyCode = event.getKeyCode();
2907 final int metaState = event.getMetaState();
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002908 final boolean initialDown = event.getAction() == KeyEvent.ACTION_DOWN
2909 && event.getRepeatCount() == 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002910
Jeff Brown54875002011-04-06 15:33:01 -07002911 // Check for fallback actions specified by the key character map.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002912 final FallbackAction fallbackAction;
2913 if (initialDown) {
2914 fallbackAction = kcm.getFallbackAction(keyCode, metaState);
2915 } else {
2916 fallbackAction = mFallbackActions.get(keyCode);
2917 }
2918
2919 if (fallbackAction != null) {
Jeff Brown40013652012-05-16 21:22:36 -07002920 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002921 Slog.d(TAG, "Fallback: keyCode=" + fallbackAction.keyCode
2922 + " metaState=" + Integer.toHexString(fallbackAction.metaState));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002923 }
2924
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002925 final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK;
2926 fallbackEvent = KeyEvent.obtain(
Jeff Brown49ed71d2010-12-06 17:13:33 -08002927 event.getDownTime(), event.getEventTime(),
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002928 event.getAction(), fallbackAction.keyCode,
2929 event.getRepeatCount(), fallbackAction.metaState,
Jeff Brown49ed71d2010-12-06 17:13:33 -08002930 event.getDeviceId(), event.getScanCode(),
2931 flags, event.getSource(), null);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002932
2933 if (!interceptFallback(win, fallbackEvent, policyFlags)) {
2934 fallbackEvent.recycle();
2935 fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002936 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002937
2938 if (initialDown) {
2939 mFallbackActions.put(keyCode, fallbackAction);
2940 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2941 mFallbackActions.remove(keyCode);
2942 fallbackAction.recycle();
2943 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002944 }
2945 }
2946
Jeff Brown40013652012-05-16 21:22:36 -07002947 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002948 if (fallbackEvent == null) {
2949 Slog.d(TAG, "No fallback.");
2950 } else {
2951 Slog.d(TAG, "Performing fallback: " + fallbackEvent);
2952 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002953 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002954 return fallbackEvent;
Jeff Brown3915bb82010-11-05 15:02:16 -07002955 }
2956
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002957 private boolean interceptFallback(WindowState win, KeyEvent fallbackEvent, int policyFlags) {
Jeff Brown037c33e2014-04-09 00:31:55 -07002958 int actions = interceptKeyBeforeQueueing(fallbackEvent, policyFlags);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002959 if ((actions & ACTION_PASS_TO_USER) != 0) {
2960 long delayMillis = interceptKeyBeforeDispatching(
2961 win, fallbackEvent, policyFlags);
2962 if (delayMillis == 0) {
2963 return true;
2964 }
2965 }
2966 return false;
Jeff Brown6f2fba42011-02-19 01:08:02 -08002967 }
2968
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002969 private void launchAssistLongPressAction() {
2970 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
2971 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
2972
2973 // launch the search activity
2974 Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS);
2975 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2976 try {
RoboErik8a2cfc32014-05-16 11:19:38 -07002977 // TODO: This only stops the factory-installed search manager.
Jim Miller45308b12012-06-18 19:23:39 -07002978 // Need to formalize an API to handle others
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002979 SearchManager searchManager = getSearchManager();
2980 if (searchManager != null) {
2981 searchManager.stopSearch();
2982 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00002983 startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002984 } catch (ActivityNotFoundException e) {
2985 Slog.w(TAG, "No activity to handle assist long press action.", e);
2986 }
2987 }
2988
2989 private void launchAssistAction() {
Michael Wright8ab940a2014-09-01 11:01:27 -07002990 launchAssistAction(null);
2991 }
2992
2993 private void launchAssistAction(String hint) {
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002994 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
Amith Yamasanic1d07a42012-08-14 09:32:02 -07002995 Intent intent = ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE))
Dianne Hackbornf9c5e0f2013-01-23 14:39:13 -08002996 .getAssistIntent(mContext, true, UserHandle.USER_CURRENT);
Jim Miller45308b12012-06-18 19:23:39 -07002997 if (intent != null) {
Michael Wright8ab940a2014-09-01 11:01:27 -07002998 if (hint != null) {
2999 intent.putExtra(hint, true);
3000 }
Jim Miller45308b12012-06-18 19:23:39 -07003001 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
3002 | Intent.FLAG_ACTIVITY_SINGLE_TOP
3003 | Intent.FLAG_ACTIVITY_CLEAR_TOP);
3004 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00003005 startActivityAsUser(intent, UserHandle.CURRENT);
Jim Miller45308b12012-06-18 19:23:39 -07003006 } catch (ActivityNotFoundException e) {
3007 Slog.w(TAG, "No activity to handle assist action.", e);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003008 }
3009 }
3010 }
3011
Bart Sears8b1c27c2015-03-18 23:51:02 +00003012 private void startActivityAsUser(Intent intent, UserHandle handle) {
3013 if (isUserSetupComplete()) {
3014 mContext.startActivityAsUser(intent, handle);
3015 } else {
3016 Slog.i(TAG, "Not starting activity because user setup is in progress: " + intent);
3017 }
3018 }
3019
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003020 private SearchManager getSearchManager() {
3021 if (mSearchManager == null) {
3022 mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
3023 }
3024 return mSearchManager;
3025 }
3026
Jeff Browncaca8812013-05-09 13:34:33 -07003027 private void preloadRecentApps() {
3028 mPreloadedRecentApps = true;
3029 try {
3030 IStatusBarService statusbar = getStatusBarService();
3031 if (statusbar != null) {
3032 statusbar.preloadRecentApps();
3033 }
3034 } catch (RemoteException e) {
3035 Slog.e(TAG, "RemoteException when preloading recent apps", e);
3036 // re-acquire status bar service next time it is needed.
3037 mStatusBarService = null;
3038 }
3039 }
3040
3041 private void cancelPreloadRecentApps() {
3042 if (mPreloadedRecentApps) {
3043 mPreloadedRecentApps = false;
3044 try {
3045 IStatusBarService statusbar = getStatusBarService();
3046 if (statusbar != null) {
3047 statusbar.cancelPreloadRecentApps();
3048 }
3049 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003050 Slog.e(TAG, "RemoteException when cancelling recent apps preload", e);
Jeff Browncaca8812013-05-09 13:34:33 -07003051 // re-acquire status bar service next time it is needed.
3052 mStatusBarService = null;
3053 }
3054 }
3055 }
3056
3057 private void toggleRecentApps() {
3058 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
Jeff Browncaca8812013-05-09 13:34:33 -07003059 try {
3060 IStatusBarService statusbar = getStatusBarService();
3061 if (statusbar != null) {
3062 statusbar.toggleRecentApps();
3063 }
3064 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003065 Slog.e(TAG, "RemoteException when toggling recent apps", e);
3066 // re-acquire status bar service next time it is needed.
3067 mStatusBarService = null;
3068 }
3069 }
3070
Craig Mautner84984fa2014-06-19 11:19:20 -07003071 @Override
3072 public void showRecentApps() {
3073 mHandler.removeMessages(MSG_DISPATCH_SHOW_RECENTS);
3074 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_RECENTS);
3075 }
3076
Winson Chung1e8d71b2014-05-16 17:05:22 -07003077 private void showRecentApps(boolean triggeredFromAltTab) {
3078 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
3079 try {
3080 IStatusBarService statusbar = getStatusBarService();
3081 if (statusbar != null) {
3082 statusbar.showRecentApps(triggeredFromAltTab);
3083 }
3084 } catch (RemoteException e) {
Jeff Browncaca8812013-05-09 13:34:33 -07003085 Slog.e(TAG, "RemoteException when showing recent apps", e);
3086 // re-acquire status bar service next time it is needed.
3087 mStatusBarService = null;
3088 }
3089 }
3090
Winson Chungcdcd4872014-08-05 18:00:13 -07003091 private void hideRecentApps(boolean triggeredFromAltTab, boolean triggeredFromHome) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003092 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
3093 try {
3094 IStatusBarService statusbar = getStatusBarService();
3095 if (statusbar != null) {
Winson Chungcdcd4872014-08-05 18:00:13 -07003096 statusbar.hideRecentApps(triggeredFromAltTab, triggeredFromHome);
Winson Chung1e8d71b2014-05-16 17:05:22 -07003097 }
3098 } catch (RemoteException e) {
3099 Slog.e(TAG, "RemoteException when closing recent apps", e);
3100 // re-acquire status bar service next time it is needed.
3101 mStatusBarService = null;
3102 }
3103 }
3104
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00003105 void launchHomeFromHotKey() {
Bryce Lee662ed802015-04-10 20:11:39 +00003106 launchHomeFromHotKey(true /* awakenFromDreams */, true /*respectKeyguard*/);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00003107 }
3108
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003109 /**
3110 * A home key -> launch home action was detected. Take the appropriate action
3111 * given the situation with the keyguard.
3112 */
Bryce Lee662ed802015-04-10 20:11:39 +00003113 void launchHomeFromHotKey(final boolean awakenFromDreams, final boolean respectKeyguard) {
3114 if (respectKeyguard) {
3115 if (isKeyguardShowingAndNotOccluded()) {
3116 // don't launch home if keyguard showing
3117 return;
3118 }
3119
3120 if (!mHideLockScreen && mKeyguardDelegate.isInputRestricted()) {
3121 // when in keyguard restricted mode, must first verify unlock
3122 // before launching home
3123 mKeyguardDelegate.verifyUnlock(new OnKeyguardExitResult() {
3124 @Override
3125 public void onKeyguardExitResult(boolean success) {
3126 if (success) {
3127 try {
3128 ActivityManagerNative.getDefault().stopAppSwitches();
3129 } catch (RemoteException e) {
3130 }
3131 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3132 startDockOrHome(true /*fromHomeKey*/, awakenFromDreams);
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07003133 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003134 }
Bryce Lee662ed802015-04-10 20:11:39 +00003135 });
3136 return;
3137 }
3138 }
3139
3140 // no keyguard stuff to worry about, just launch home!
3141 try {
3142 ActivityManagerNative.getDefault().stopAppSwitches();
3143 } catch (RemoteException e) {
3144 }
3145 if (mRecentsVisible) {
3146 // Hide Recents and notify it to launch Home
3147 if (awakenFromDreams) {
3148 awakenDreams();
3149 }
3150 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3151 hideRecentApps(false, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003152 } else {
Bryce Lee662ed802015-04-10 20:11:39 +00003153 // Otherwise, just launch Home
3154 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3155 startDockOrHome(true /*fromHomeKey*/, awakenFromDreams);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003156 }
3157 }
3158
John Spurlock04db1762013-05-13 12:46:41 -04003159 private final Runnable mClearHideNavigationFlag = new Runnable() {
3160 @Override
3161 public void run() {
3162 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
3163 // Clear flags.
3164 mForceClearedSystemUiFlags &=
3165 ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
3166 }
3167 mWindowManagerFuncs.reevaluateStatusBarVisibility();
Dianne Hackborne26ab702011-10-16 13:21:33 -07003168 }
3169 };
3170
3171 /**
3172 * Input handler used while nav bar is hidden. Captures any touch on the screen,
3173 * to determine when the nav bar should be shown and prevent applications from
3174 * receiving those touches.
3175 */
Jeff Brown32cbc38552011-12-01 14:01:49 -08003176 final class HideNavInputEventReceiver extends InputEventReceiver {
3177 public HideNavInputEventReceiver(InputChannel inputChannel, Looper looper) {
3178 super(inputChannel, looper);
3179 }
3180
Dianne Hackborndf89e652011-10-06 22:35:11 -07003181 @Override
Jeff Brown32cbc38552011-12-01 14:01:49 -08003182 public void onInputEvent(InputEvent event) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003183 boolean handled = false;
3184 try {
Jeff Brown4952dfd2011-11-30 19:23:22 -08003185 if (event instanceof MotionEvent
3186 && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
3187 final MotionEvent motionEvent = (MotionEvent)event;
3188 if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003189 // When the user taps down, we re-show the nav bar.
3190 boolean changed = false;
John Spurlock04db1762013-05-13 12:46:41 -04003191 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003192 // Any user activity always causes us to show the
3193 // navigation controls, if they had been hidden.
3194 // We also clear the low profile and only content
3195 // flags so that tapping on the screen will atomically
3196 // restore all currently hidden screen decorations.
3197 int newVal = mResettingSystemUiFlags |
3198 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
3199 View.SYSTEM_UI_FLAG_LOW_PROFILE |
3200 View.SYSTEM_UI_FLAG_FULLSCREEN;
Dianne Hackborne26ab702011-10-16 13:21:33 -07003201 if (mResettingSystemUiFlags != newVal) {
3202 mResettingSystemUiFlags = newVal;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003203 changed = true;
3204 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003205 // We don't allow the system's nav bar to be hidden
3206 // again for 1 second, to prevent applications from
3207 // spamming us and keeping it from being shown.
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003208 newVal = mForceClearedSystemUiFlags |
3209 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
Dianne Hackborne26ab702011-10-16 13:21:33 -07003210 if (mForceClearedSystemUiFlags != newVal) {
3211 mForceClearedSystemUiFlags = newVal;
3212 changed = true;
John Spurlock04db1762013-05-13 12:46:41 -04003213 mHandler.postDelayed(mClearHideNavigationFlag, 1000);
Dianne Hackborne26ab702011-10-16 13:21:33 -07003214 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07003215 }
3216 if (changed) {
3217 mWindowManagerFuncs.reevaluateStatusBarVisibility();
3218 }
3219 }
3220 }
3221 } finally {
Jeff Brown32cbc38552011-12-01 14:01:49 -08003222 finishInputEvent(event, handled);
Dianne Hackborndf89e652011-10-06 22:35:11 -07003223 }
3224 }
Jeff Brown32cbc38552011-12-01 14:01:49 -08003225 }
3226 final InputEventReceiver.Factory mHideNavInputEventReceiverFactory =
3227 new InputEventReceiver.Factory() {
3228 @Override
3229 public InputEventReceiver createInputEventReceiver(
3230 InputChannel inputChannel, Looper looper) {
3231 return new HideNavInputEventReceiver(inputChannel, looper);
3232 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07003233 };
3234
3235 @Override
3236 public int adjustSystemUiVisibilityLw(int visibility) {
John Spurlock5b9145b2013-08-20 15:13:47 -04003237 mStatusBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
3238 mNavigationBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
Winson Chungd42a6cf2014-06-03 16:24:04 -07003239 mRecentsVisible = (visibility & View.RECENT_APPS_VISIBLE) > 0;
John Spurlock27735a42013-08-14 17:57:38 -04003240
Dianne Hackborndf89e652011-10-06 22:35:11 -07003241 // Reset any bits in mForceClearingStatusBarVisibility that
3242 // are now clear.
Dianne Hackborne26ab702011-10-16 13:21:33 -07003243 mResettingSystemUiFlags &= visibility;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003244 // Clear any bits in the new visibility that are currently being
3245 // force cleared, before reporting it.
Dianne Hackborne26ab702011-10-16 13:21:33 -07003246 return visibility & ~mResettingSystemUiFlags
3247 & ~mForceClearedSystemUiFlags;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003248 }
3249
Craig Mautner69b08182012-09-05 13:07:13 -07003250 @Override
Adrian Roos37d7a682014-11-06 18:15:16 +01003251 public void getInsetHintLw(WindowManager.LayoutParams attrs, Rect outContentInsets,
3252 Rect outStableInsets) {
John Spurlockc6d1c602014-01-17 15:22:06 -05003253 final int fl = PolicyControl.getWindowFlags(null, attrs);
John Spurlock1db8b682014-02-18 11:18:59 -05003254 final int sysuiVis = PolicyControl.getSystemUiVisibility(null, attrs);
3255 final int systemUiVisibility = (sysuiVis | attrs.subtreeSystemUiVisibility);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003256
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003257 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003258 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003259 int availRight, availBottom;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003260 if (canHideNavigationBar() &&
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003261 (systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003262 availRight = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3263 availBottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
3264 } else {
3265 availRight = mRestrictedScreenLeft + mRestrictedScreenWidth;
3266 availBottom = mRestrictedScreenTop + mRestrictedScreenHeight;
3267 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003268 if ((systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
3269 if ((fl & FLAG_FULLSCREEN) != 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003270 outContentInsets.set(mStableFullscreenLeft, mStableFullscreenTop,
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003271 availRight - mStableFullscreenRight,
3272 availBottom - mStableFullscreenBottom);
3273 } else {
Adrian Roos37d7a682014-11-06 18:15:16 +01003274 outContentInsets.set(mStableLeft, mStableTop,
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003275 availRight - mStableRight, availBottom - mStableBottom);
3276 }
Dianne Hackbornc652de82013-02-15 16:32:56 -08003277 } else if ((fl & FLAG_FULLSCREEN) != 0 || (fl & FLAG_LAYOUT_IN_OVERSCAN) != 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003278 outContentInsets.setEmpty();
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003279 } else if ((systemUiVisibility & (View.SYSTEM_UI_FLAG_FULLSCREEN
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003280 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)) == 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003281 outContentInsets.set(mCurLeft, mCurTop,
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003282 availRight - mCurRight, availBottom - mCurBottom);
3283 } else {
Adrian Roos37d7a682014-11-06 18:15:16 +01003284 outContentInsets.set(mCurLeft, mCurTop,
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003285 availRight - mCurRight, availBottom - mCurBottom);
3286 }
Adrian Roos37d7a682014-11-06 18:15:16 +01003287
3288 outStableInsets.set(mStableLeft, mStableTop,
3289 availRight - mStableRight, availBottom - mStableBottom);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003290 return;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003291 }
Adrian Roos37d7a682014-11-06 18:15:16 +01003292 outContentInsets.setEmpty();
3293 outStableInsets.setEmpty();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003294 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003295
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003296 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07003297 @Override
3298 public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight,
3299 int displayRotation) {
Dianne Hackbornc652de82013-02-15 16:32:56 -08003300 final int overscanLeft, overscanTop, overscanRight, overscanBottom;
3301 if (isDefaultDisplay) {
3302 switch (displayRotation) {
3303 case Surface.ROTATION_90:
3304 overscanLeft = mOverscanTop;
3305 overscanTop = mOverscanRight;
3306 overscanRight = mOverscanBottom;
3307 overscanBottom = mOverscanLeft;
3308 break;
3309 case Surface.ROTATION_180:
3310 overscanLeft = mOverscanRight;
3311 overscanTop = mOverscanBottom;
3312 overscanRight = mOverscanLeft;
3313 overscanBottom = mOverscanTop;
3314 break;
3315 case Surface.ROTATION_270:
3316 overscanLeft = mOverscanBottom;
3317 overscanTop = mOverscanLeft;
3318 overscanRight = mOverscanTop;
3319 overscanBottom = mOverscanRight;
3320 break;
3321 default:
3322 overscanLeft = mOverscanLeft;
3323 overscanTop = mOverscanTop;
3324 overscanRight = mOverscanRight;
3325 overscanBottom = mOverscanBottom;
3326 break;
3327 }
3328 } else {
3329 overscanLeft = 0;
3330 overscanTop = 0;
3331 overscanRight = 0;
3332 overscanBottom = 0;
3333 }
Dianne Hackborn313440842013-02-19 19:22:59 -08003334 mOverscanScreenLeft = mRestrictedOverscanScreenLeft = 0;
3335 mOverscanScreenTop = mRestrictedOverscanScreenTop = 0;
3336 mOverscanScreenWidth = mRestrictedOverscanScreenWidth = displayWidth;
3337 mOverscanScreenHeight = mRestrictedOverscanScreenHeight = displayHeight;
Dianne Hackbornc652de82013-02-15 16:32:56 -08003338 mSystemLeft = 0;
3339 mSystemTop = 0;
3340 mSystemRight = displayWidth;
3341 mSystemBottom = displayHeight;
3342 mUnrestrictedScreenLeft = overscanLeft;
3343 mUnrestrictedScreenTop = overscanTop;
3344 mUnrestrictedScreenWidth = displayWidth - overscanLeft - overscanRight;
3345 mUnrestrictedScreenHeight = displayHeight - overscanTop - overscanBottom;
3346 mRestrictedScreenLeft = mUnrestrictedScreenLeft;
3347 mRestrictedScreenTop = mUnrestrictedScreenTop;
John Spurlockad3e6cb2013-04-30 08:47:43 -04003348 mRestrictedScreenWidth = mSystemGestures.screenWidth = mUnrestrictedScreenWidth;
3349 mRestrictedScreenHeight = mSystemGestures.screenHeight = mUnrestrictedScreenHeight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003350 mDockLeft = mContentLeft = mVoiceContentLeft = mStableLeft = mStableFullscreenLeft
Dianne Hackbornc652de82013-02-15 16:32:56 -08003351 = mCurLeft = mUnrestrictedScreenLeft;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003352 mDockTop = mContentTop = mVoiceContentTop = mStableTop = mStableFullscreenTop
Dianne Hackbornc652de82013-02-15 16:32:56 -08003353 = mCurTop = mUnrestrictedScreenTop;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003354 mDockRight = mContentRight = mVoiceContentRight = mStableRight = mStableFullscreenRight
Dianne Hackbornc652de82013-02-15 16:32:56 -08003355 = mCurRight = displayWidth - overscanRight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003356 mDockBottom = mContentBottom = mVoiceContentBottom = mStableBottom = mStableFullscreenBottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003357 = mCurBottom = displayHeight - overscanBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003358 mDockLayer = 0x10000000;
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003359 mStatusBarLayer = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003360
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003361 // start with the current dock rect, which will be (0,0,displayWidth,displayHeight)
3362 final Rect pf = mTmpParentFrame;
3363 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003364 final Rect of = mTmpOverscanFrame;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003365 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04003366 final Rect dcf = mTmpDecorFrame;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003367 final Rect osf = mTmpOutsetFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003368 pf.left = df.left = of.left = vf.left = mDockLeft;
3369 pf.top = df.top = of.top = vf.top = mDockTop;
3370 pf.right = df.right = of.right = vf.right = mDockRight;
3371 pf.bottom = df.bottom = of.bottom = vf.bottom = mDockBottom;
John Spurlock46646232013-09-30 22:32:42 -04003372 dcf.setEmpty(); // Decor frame N/A for system bars.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003373
Craig Mautner69b08182012-09-05 13:07:13 -07003374 if (isDefaultDisplay) {
3375 // For purposes of putting out fake window up to steal focus, we will
3376 // drive nav being hidden only by whether it is requested.
John Spurlocke1f366f2013-08-05 12:22:40 -04003377 final int sysui = mLastSystemUiFlags;
3378 boolean navVisible = (sysui & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0;
Adrian Roosea562512014-05-05 13:33:03 +02003379 boolean navTranslucent = (sysui
3380 & (View.NAVIGATION_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04003381 boolean immersive = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
3382 boolean immersiveSticky = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
3383 boolean navAllowedHidden = immersive || immersiveSticky;
3384 navTranslucent &= !immersiveSticky; // transient trumps translucent
Adrian Roos4fb3ee32014-08-22 19:29:09 +02003385 boolean isKeyguardShowing = isStatusBarKeyguard() && !mHideLockScreen;
3386 if (!isKeyguardShowing) {
3387 navTranslucent &= areTranslucentBarsAllowed();
3388 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003389
Craig Mautner69b08182012-09-05 13:07:13 -07003390 // When the navigation bar isn't visible, we put up a fake
3391 // input window to catch all touch events. This way we can
3392 // detect when the user presses anywhere to bring back the nav
3393 // bar and ensure the application doesn't see the event.
John Spurlockf1a36642013-10-12 17:50:42 -04003394 if (navVisible || navAllowedHidden) {
Selim Cinekf83e8242015-05-19 18:08:14 -07003395 if (mInputConsumer != null) {
3396 mInputConsumer.dismiss();
3397 mInputConsumer = null;
Craig Mautner69b08182012-09-05 13:07:13 -07003398 }
Selim Cinekf83e8242015-05-19 18:08:14 -07003399 } else if (mInputConsumer == null) {
3400 mInputConsumer = mWindowManagerFuncs.addInputConsumer(mHandler.getLooper(),
3401 mHideNavInputEventReceiverFactory);
Dianne Hackborne26ab702011-10-16 13:21:33 -07003402 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003403
Craig Mautner69b08182012-09-05 13:07:13 -07003404 // For purposes of positioning and showing the nav bar, if we have
3405 // decided that it can't be hidden (because of the screen aspect ratio),
3406 // then take that into account.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003407 navVisible |= !canHideNavigationBar();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003408
John Spurlockad3e6cb2013-04-30 08:47:43 -04003409 boolean updateSysUiVisibility = false;
Craig Mautner69b08182012-09-05 13:07:13 -07003410 if (mNavigationBar != null) {
John Spurlock27735a42013-08-14 17:57:38 -04003411 boolean transientNavBarShowing = mNavigationBarController.isTransientShowing();
Craig Mautner69b08182012-09-05 13:07:13 -07003412 // Force the navigation bar to its appropriate place and
3413 // size. We need to do this directly, instead of relying on
3414 // it to bubble up from the nav bar, because this needs to
3415 // change atomically with screen rotations.
3416 mNavigationBarOnBottom = (!mNavigationBarCanMove || displayWidth < displayHeight);
3417 if (mNavigationBarOnBottom) {
3418 // It's a system nav bar or a portrait screen; nav bar goes on bottom.
Dianne Hackbornc652de82013-02-15 16:32:56 -08003419 int top = displayHeight - overscanBottom
3420 - mNavigationBarHeightForRotation[displayRotation];
3421 mTmpNavigationFrame.set(0, top, displayWidth, displayHeight - overscanBottom);
Craig Mautner69b08182012-09-05 13:07:13 -07003422 mStableBottom = mStableFullscreenBottom = mTmpNavigationFrame.top;
John Spurlockf95b89a2013-10-10 22:10:42 -04003423 if (transientNavBarShowing) {
John Spurlock27735a42013-08-14 17:57:38 -04003424 mNavigationBarController.setBarShowingLw(true);
John Spurlockad3e6cb2013-04-30 08:47:43 -04003425 } else if (navVisible) {
John Spurlock27735a42013-08-14 17:57:38 -04003426 mNavigationBarController.setBarShowingLw(true);
Craig Mautner69b08182012-09-05 13:07:13 -07003427 mDockBottom = mTmpNavigationFrame.top;
Dianne Hackborn313440842013-02-19 19:22:59 -08003428 mRestrictedScreenHeight = mDockBottom - mRestrictedScreenTop;
3429 mRestrictedOverscanScreenHeight = mDockBottom - mRestrictedOverscanScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07003430 } else {
3431 // We currently want to hide the navigation UI.
John Spurlock27735a42013-08-14 17:57:38 -04003432 mNavigationBarController.setBarShowingLw(false);
Craig Mautner69b08182012-09-05 13:07:13 -07003433 }
John Spurlockc6d1c602014-01-17 15:22:06 -05003434 if (navVisible && !navTranslucent && !navAllowedHidden
3435 && !mNavigationBar.isAnimatingLw()
John Spurlockbd957402013-10-03 11:38:39 -04003436 && !mNavigationBarController.wasRecentlyTranslucent()) {
John Spurlocke1f366f2013-08-05 12:22:40 -04003437 // If the opaque nav bar is currently requested to be visible,
Craig Mautner69b08182012-09-05 13:07:13 -07003438 // and not in the process of animating on or off, then
3439 // we can tell the app that it is covered by it.
3440 mSystemBottom = mTmpNavigationFrame.top;
3441 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003442 } else {
Craig Mautner69b08182012-09-05 13:07:13 -07003443 // Landscape screen; nav bar goes to the right.
Dianne Hackbornc652de82013-02-15 16:32:56 -08003444 int left = displayWidth - overscanRight
3445 - mNavigationBarWidthForRotation[displayRotation];
3446 mTmpNavigationFrame.set(left, 0, displayWidth - overscanRight, displayHeight);
Craig Mautner69b08182012-09-05 13:07:13 -07003447 mStableRight = mStableFullscreenRight = mTmpNavigationFrame.left;
John Spurlockf95b89a2013-10-10 22:10:42 -04003448 if (transientNavBarShowing) {
John Spurlock27735a42013-08-14 17:57:38 -04003449 mNavigationBarController.setBarShowingLw(true);
John Spurlockad3e6cb2013-04-30 08:47:43 -04003450 } else if (navVisible) {
John Spurlock27735a42013-08-14 17:57:38 -04003451 mNavigationBarController.setBarShowingLw(true);
Craig Mautner69b08182012-09-05 13:07:13 -07003452 mDockRight = mTmpNavigationFrame.left;
Dianne Hackborn313440842013-02-19 19:22:59 -08003453 mRestrictedScreenWidth = mDockRight - mRestrictedScreenLeft;
3454 mRestrictedOverscanScreenWidth = mDockRight - mRestrictedOverscanScreenLeft;
Craig Mautner69b08182012-09-05 13:07:13 -07003455 } else {
3456 // We currently want to hide the navigation UI.
John Spurlock27735a42013-08-14 17:57:38 -04003457 mNavigationBarController.setBarShowingLw(false);
Craig Mautner69b08182012-09-05 13:07:13 -07003458 }
John Spurlockbd957402013-10-03 11:38:39 -04003459 if (navVisible && !navTranslucent && !mNavigationBar.isAnimatingLw()
3460 && !mNavigationBarController.wasRecentlyTranslucent()) {
Craig Mautner69b08182012-09-05 13:07:13 -07003461 // If the nav bar is currently requested to be visible,
3462 // and not in the process of animating on or off, then
3463 // we can tell the app that it is covered by it.
3464 mSystemRight = mTmpNavigationFrame.left;
3465 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003466 }
Craig Mautner69b08182012-09-05 13:07:13 -07003467 // Make sure the content and current rectangles are updated to
3468 // account for the restrictions from the navigation bar.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003469 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3470 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3471 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3472 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
Craig Mautner69b08182012-09-05 13:07:13 -07003473 mStatusBarLayer = mNavigationBar.getSurfaceLayer();
3474 // And compute the final frame.
3475 mNavigationBar.computeFrameLw(mTmpNavigationFrame, mTmpNavigationFrame,
Adrian Roosfa104232014-06-20 16:10:14 -07003476 mTmpNavigationFrame, mTmpNavigationFrame, mTmpNavigationFrame, dcf,
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003477 mTmpNavigationFrame, mTmpNavigationFrame);
Craig Mautnereda67292013-04-28 13:50:14 -07003478 if (DEBUG_LAYOUT) Slog.i(TAG, "mNavigationBar frame: " + mTmpNavigationFrame);
John Spurlock27735a42013-08-14 17:57:38 -04003479 if (mNavigationBarController.checkHiddenLw()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04003480 updateSysUiVisibility = true;
3481 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003482 }
Craig Mautnereda67292013-04-28 13:50:14 -07003483 if (DEBUG_LAYOUT) Slog.i(TAG, String.format("mDock rect: (%d,%d - %d,%d)",
Craig Mautner69b08182012-09-05 13:07:13 -07003484 mDockLeft, mDockTop, mDockRight, mDockBottom));
3485
3486 // decide where the status bar goes ahead of time
3487 if (mStatusBar != null) {
3488 // apply any navigation bar insets
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003489 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3490 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3491 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
3492 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight
3493 + mUnrestrictedScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07003494 vf.left = mStableLeft;
3495 vf.top = mStableTop;
3496 vf.right = mStableRight;
3497 vf.bottom = mStableBottom;
3498
3499 mStatusBarLayer = mStatusBar.getSurfaceLayer();
3500
3501 // Let the status bar determine its size.
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003502 mStatusBar.computeFrameLw(pf /* parentFrame */, df /* displayFrame */,
3503 vf /* overlayFrame */, vf /* contentFrame */, vf /* visibleFrame */,
3504 dcf /* decorFrame */, vf /* stableFrame */, vf /* outsetFrame */);
Craig Mautner69b08182012-09-05 13:07:13 -07003505
3506 // For layout, the status bar is always at the top with our fixed height.
3507 mStableTop = mUnrestrictedScreenTop + mStatusBarHeight;
3508
John Spurlocke1f366f2013-08-05 12:22:40 -04003509 boolean statusBarTransient = (sysui & View.STATUS_BAR_TRANSIENT) != 0;
Adrian Roosea562512014-05-05 13:33:03 +02003510 boolean statusBarTranslucent = (sysui
3511 & (View.STATUS_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0;
Adrian Roos4fb3ee32014-08-22 19:29:09 +02003512 if (!isKeyguardShowing) {
3513 statusBarTranslucent &= areTranslucentBarsAllowed();
3514 }
John Spurlock32beb2c2013-03-11 10:16:47 -04003515
Craig Mautner69b08182012-09-05 13:07:13 -07003516 // If the status bar is hidden, we don't want to cause
3517 // windows behind it to scroll.
John Spurlockeda1f692013-09-16 11:38:44 -04003518 if (mStatusBar.isVisibleLw() && !statusBarTransient) {
Craig Mautner69b08182012-09-05 13:07:13 -07003519 // Status bar may go away, so the screen area it occupies
3520 // is available to apps but just covering them when the
3521 // status bar is visible.
3522 mDockTop = mUnrestrictedScreenTop + mStatusBarHeight;
3523
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003524 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3525 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3526 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3527 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
Craig Mautner69b08182012-09-05 13:07:13 -07003528
Craig Mautnereda67292013-04-28 13:50:14 -07003529 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar: " +
Craig Mautner69b08182012-09-05 13:07:13 -07003530 String.format(
3531 "dock=[%d,%d][%d,%d] content=[%d,%d][%d,%d] cur=[%d,%d][%d,%d]",
3532 mDockLeft, mDockTop, mDockRight, mDockBottom,
3533 mContentLeft, mContentTop, mContentRight, mContentBottom,
3534 mCurLeft, mCurTop, mCurRight, mCurBottom));
3535 }
John Spurlocke1f366f2013-08-05 12:22:40 -04003536 if (mStatusBar.isVisibleLw() && !mStatusBar.isAnimatingLw()
John Spurlockbd957402013-10-03 11:38:39 -04003537 && !statusBarTransient && !statusBarTranslucent
3538 && !mStatusBarController.wasRecentlyTranslucent()) {
John Spurlocke1f366f2013-08-05 12:22:40 -04003539 // If the opaque status bar is currently requested to be visible,
Craig Mautner69b08182012-09-05 13:07:13 -07003540 // and not in the process of animating on or off, then
3541 // we can tell the app that it is covered by it.
3542 mSystemTop = mUnrestrictedScreenTop + mStatusBarHeight;
3543 }
John Spurlock27735a42013-08-14 17:57:38 -04003544 if (mStatusBarController.checkHiddenLw()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04003545 updateSysUiVisibility = true;
John Spurlock32beb2c2013-03-11 10:16:47 -04003546 }
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003547 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04003548 if (updateSysUiVisibility) {
3549 updateSystemUiVisibilityLw();
3550 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003551 }
3552 }
3553
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003554 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07003555 @Override
John Spurlock46646232013-09-30 22:32:42 -04003556 public int getSystemDecorLayerLw() {
Bryce Lee2ed3e5f2015-04-01 22:09:19 +00003557 if (mStatusBar != null && mStatusBar.isVisibleLw()) {
3558 return mStatusBar.getSurfaceLayer();
3559 }
3560
3561 if (mNavigationBar != null && mNavigationBar.isVisibleLw()) {
3562 return mNavigationBar.getSurfaceLayer();
3563 }
3564
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003565 return 0;
3566 }
3567
Craig Mautner967212c2013-04-13 21:10:58 -07003568 @Override
3569 public void getContentRectLw(Rect r) {
3570 r.set(mContentLeft, mContentTop, mContentRight, mContentBottom);
3571 }
3572
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003573 void setAttachedWindowFrames(WindowState win, int fl, int adjust, WindowState attached,
3574 boolean insetDecors, Rect pf, Rect df, Rect of, Rect cf, Rect vf) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003575 if (win.getSurfaceLayer() > mDockLayer && attached.getSurfaceLayer() < mDockLayer) {
3576 // Here's a special case: if this attached window is a panel that is
3577 // above the dock window, and the window it is attached to is below
3578 // the dock window, then the frames we computed for the window it is
3579 // attached to can not be used because the dock is effectively part
3580 // of the underlying window and the attached window is floating on top
3581 // of the whole thing. So, we ignore the attached window and explicitly
3582 // compute the frames that would be appropriate without the dock.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003583 df.left = of.left = cf.left = vf.left = mDockLeft;
3584 df.top = of.top = cf.top = vf.top = mDockTop;
3585 df.right = of.right = cf.right = vf.right = mDockRight;
3586 df.bottom = of.bottom = cf.bottom = vf.bottom = mDockBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003587 } else {
3588 // The effective display frame of the attached window depends on
3589 // whether it is taking care of insetting its content. If not,
3590 // we need to use the parent's content frame so that the entire
3591 // window is positioned within that content. Otherwise we can use
Wale Ogunwale393b1c12014-10-18 16:22:01 -07003592 // the overscan frame and let the attached window take care of
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003593 // positioning its content appropriately.
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003594 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Wale Ogunwale393b1c12014-10-18 16:22:01 -07003595 // Set the content frame of the attached window to the parent's decor frame
3596 // (same as content frame when IME isn't present) if specifically requested by
3597 // setting {@link WindowManager.LayoutParams#FLAG_LAYOUT_ATTACHED_IN_DECOR} flag.
3598 // Otherwise, use the overscan frame.
3599 cf.set((fl & FLAG_LAYOUT_ATTACHED_IN_DECOR) != 0
3600 ? attached.getContentFrameLw() : attached.getOverscanFrameLw());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003601 } else {
3602 // If the window is resizing, then we want to base the content
3603 // frame on our attached content frame to resize... however,
3604 // things can be tricky if the attached window is NOT in resize
3605 // mode, in which case its content frame will be larger.
3606 // Ungh. So to deal with that, make sure the content frame
3607 // we end up using is not covering the IM dock.
3608 cf.set(attached.getContentFrameLw());
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003609 if (attached.isVoiceInteraction()) {
3610 if (cf.left < mVoiceContentLeft) cf.left = mVoiceContentLeft;
3611 if (cf.top < mVoiceContentTop) cf.top = mVoiceContentTop;
3612 if (cf.right > mVoiceContentRight) cf.right = mVoiceContentRight;
3613 if (cf.bottom > mVoiceContentBottom) cf.bottom = mVoiceContentBottom;
3614 } else if (attached.getSurfaceLayer() < mDockLayer) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003615 if (cf.left < mContentLeft) cf.left = mContentLeft;
3616 if (cf.top < mContentTop) cf.top = mContentTop;
3617 if (cf.right > mContentRight) cf.right = mContentRight;
3618 if (cf.bottom > mContentBottom) cf.bottom = mContentBottom;
3619 }
3620 }
3621 df.set(insetDecors ? attached.getDisplayFrameLw() : cf);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003622 of.set(insetDecors ? attached.getOverscanFrameLw() : cf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003623 vf.set(attached.getVisibleFrameLw());
3624 }
3625 // The LAYOUT_IN_SCREEN flag is used to determine whether the attached
3626 // window should be positioned relative to its parent or the entire
3627 // screen.
3628 pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0
3629 ? attached.getFrameLw() : df);
3630 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003631
3632 private void applyStableConstraints(int sysui, int fl, Rect r) {
3633 if ((sysui & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
3634 // If app is requesting a stable layout, don't let the
3635 // content insets go below the stable values.
3636 if ((fl & FLAG_FULLSCREEN) != 0) {
3637 if (r.left < mStableFullscreenLeft) r.left = mStableFullscreenLeft;
3638 if (r.top < mStableFullscreenTop) r.top = mStableFullscreenTop;
3639 if (r.right > mStableFullscreenRight) r.right = mStableFullscreenRight;
3640 if (r.bottom > mStableFullscreenBottom) r.bottom = mStableFullscreenBottom;
3641 } else {
3642 if (r.left < mStableLeft) r.left = mStableLeft;
3643 if (r.top < mStableTop) r.top = mStableTop;
3644 if (r.right > mStableRight) r.right = mStableRight;
3645 if (r.bottom > mStableBottom) r.bottom = mStableBottom;
3646 }
3647 }
3648 }
3649
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003650 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07003651 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003652 public void layoutWindowLw(WindowState win, WindowState attached) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003653 // we've already done the status bar
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003654 final WindowManager.LayoutParams attrs = win.getAttrs();
3655 if ((win == mStatusBar && (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) == 0) ||
3656 win == mNavigationBar) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003657 return;
3658 }
Craig Mautner69b08182012-09-05 13:07:13 -07003659 final boolean isDefaultDisplay = win.isDefaultDisplay();
3660 final boolean needsToOffsetInputMethodTarget = isDefaultDisplay &&
satok1bc0a492012-04-25 22:47:12 +09003661 (win == mLastInputMethodTargetWindow && mLastInputMethodWindow != null);
3662 if (needsToOffsetInputMethodTarget) {
Craig Mautnereda67292013-04-28 13:50:14 -07003663 if (DEBUG_LAYOUT) Slog.i(TAG, "Offset ime target window by the last ime window state");
satok1bc0a492012-04-25 22:47:12 +09003664 offsetInputMethodWindowLw(mLastInputMethodWindow);
3665 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003666
John Spurlockc6d1c602014-01-17 15:22:06 -05003667 final int fl = PolicyControl.getWindowFlags(win, attrs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003668 final int sim = attrs.softInputMode;
John Spurlock1db8b682014-02-18 11:18:59 -05003669 final int sysUiFl = PolicyControl.getSystemUiVisibility(win, null);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003670
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003671 final Rect pf = mTmpParentFrame;
3672 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003673 final Rect of = mTmpOverscanFrame;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003674 final Rect cf = mTmpContentFrame;
3675 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04003676 final Rect dcf = mTmpDecorFrame;
Adrian Roosfa104232014-06-20 16:10:14 -07003677 final Rect sf = mTmpStableFrame;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003678 Rect osf = null;
John Spurlock46646232013-09-30 22:32:42 -04003679 dcf.setEmpty();
Craig Mautner69b08182012-09-05 13:07:13 -07003680
3681 final boolean hasNavBar = (isDefaultDisplay && mHasNavigationBar
Daniel Sandler36412a72011-08-04 09:35:13 -04003682 && mNavigationBar != null && mNavigationBar.isVisibleLw());
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003683
Craig Mautnerf683b562012-10-02 11:10:57 -07003684 final int adjust = sim & SOFT_INPUT_MASK_ADJUST;
3685
Adrian Roosfa104232014-06-20 16:10:14 -07003686 if (isDefaultDisplay) {
3687 sf.set(mStableLeft, mStableTop, mStableRight, mStableBottom);
3688 } else {
3689 sf.set(mOverscanLeft, mOverscanTop, mOverscanRight, mOverscanBottom);
3690 }
3691
Craig Mautner69b08182012-09-05 13:07:13 -07003692 if (!isDefaultDisplay) {
3693 if (attached != null) {
3694 // If this window is attached to another, our display
3695 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003696 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07003697 } else {
3698 // Give the window full screen.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003699 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3700 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3701 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08003702 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003703 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003704 = mOverscanScreenTop + mOverscanScreenHeight;
Craig Mautner69b08182012-09-05 13:07:13 -07003705 }
Jorim Jaggi225d3b52015-04-01 11:18:57 -07003706 } else if (attrs.type == TYPE_INPUT_METHOD) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003707 pf.left = df.left = of.left = cf.left = vf.left = mDockLeft;
3708 pf.top = df.top = of.top = cf.top = vf.top = mDockTop;
3709 pf.right = df.right = of.right = cf.right = vf.right = mDockRight;
John Spurlockc68d5772013-10-08 11:47:58 -04003710 // IM dock windows layout below the nav bar...
John Spurlock57beb3b2013-10-10 10:27:44 -04003711 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlockc68d5772013-10-08 11:47:58 -04003712 // ...with content insets above the nav bar
3713 cf.bottom = vf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003714 // IM dock windows always go to the bottom of the screen.
3715 attrs.gravity = Gravity.BOTTOM;
3716 mDockLayer = win.getSurfaceLayer();
Jorim Jaggi225d3b52015-04-01 11:18:57 -07003717 } else if (attrs.type == TYPE_VOICE_INTERACTION) {
3718 pf.left = df.left = of.left = cf.left = vf.left = mUnrestrictedScreenLeft;
3719 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3720 pf.right = df.right = of.right = cf.right = vf.right = mUnrestrictedScreenLeft
3721 + mUnrestrictedScreenWidth;
3722 pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop
3723 + mUnrestrictedScreenHeight;
3724 cf.bottom = vf.bottom = mStableBottom;
3725 cf.top = vf.top = mStableTop;
Jorim Jaggie0700182014-08-21 01:12:37 +02003726 } else if (win == mStatusBar && (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
3727 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3728 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3729 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
3730 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight + mUnrestrictedScreenTop;
3731 cf.left = vf.left = mStableLeft;
3732 cf.top = vf.top = mStableTop;
3733 cf.right = vf.right = mStableRight;
3734 vf.bottom = mStableBottom;
3735 cf.bottom = mContentBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003736 } else {
John Spurlock46646232013-09-30 22:32:42 -04003737
3738 // Default policy decor for the default display
3739 dcf.left = mSystemLeft;
3740 dcf.top = mSystemTop;
3741 dcf.right = mSystemRight;
3742 dcf.bottom = mSystemBottom;
John Spurlockbd957402013-10-03 11:38:39 -04003743 final boolean inheritTranslucentDecor = (attrs.privateFlags
3744 & WindowManager.LayoutParams.PRIVATE_FLAG_INHERIT_TRANSLUCENT_DECOR) != 0;
John Spurlock65567d42013-10-08 10:08:32 -04003745 final boolean isAppWindow =
3746 attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW &&
3747 attrs.type <= WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
3748 final boolean topAtRest =
3749 win == mTopFullscreenOpaqueWindowState && !win.isAnimatingLw();
3750 if (isAppWindow && !inheritTranslucentDecor && !topAtRest) {
John Spurlockbd957402013-10-03 11:38:39 -04003751 if ((sysUiFl & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0
3752 && (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0
Adrian Roosea562512014-05-05 13:33:03 +02003753 && (fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) == 0
3754 && (fl & WindowManager.LayoutParams.
3755 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04003756 // Ensure policy decor includes status bar
3757 dcf.top = mStableTop;
3758 }
John Spurlockbd957402013-10-03 11:38:39 -04003759 if ((fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) == 0
Adrian Roosea562512014-05-05 13:33:03 +02003760 && (sysUiFl & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0
3761 && (fl & WindowManager.LayoutParams.
3762 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04003763 // Ensure policy decor includes navigation bar
3764 dcf.bottom = mStableBottom;
3765 dcf.right = mStableRight;
3766 }
3767 }
3768
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003769 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
3770 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
RoboErik8a2cfc32014-05-16 11:19:38 -07003771 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003772 + "): IN_SCREEN, INSET_DECOR");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003773 // This is the case for a normal activity window: we want it
3774 // to cover all of the screen space, and it can take care of
3775 // moving its contents to account for screen decorations that
3776 // intrude into that space.
3777 if (attached != null) {
3778 // If this window is attached to another, our display
3779 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003780 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003781 } else {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003782 if (attrs.type == TYPE_STATUS_BAR_PANEL
3783 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Joe Onorato29fc2c92010-11-24 10:26:50 -08003784 // Status bar panels are the only windows who can go on top of
3785 // the status bar. They are protected by the STATUS_BAR_SERVICE
3786 // permission, so they have the same privileges as the status
3787 // bar itself.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003788 //
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003789 // However, they should still dodge the navigation bar if it exists.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003790
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003791 pf.left = df.left = of.left = hasNavBar
3792 ? mDockLeft : mUnrestrictedScreenLeft;
3793 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3794 pf.right = df.right = of.right = hasNavBar
3795 ? mRestrictedScreenLeft+mRestrictedScreenWidth
3796 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3797 pf.bottom = df.bottom = of.bottom = hasNavBar
3798 ? mRestrictedScreenTop+mRestrictedScreenHeight
3799 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003800
Craig Mautnereda67292013-04-28 13:50:14 -07003801 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003802 "Laying out status bar window: (%d,%d - %d,%d)",
3803 pf.left, pf.top, pf.right, pf.bottom));
John Spurlock46646232013-09-30 22:32:42 -04003804 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08003805 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3806 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3807 // Asking to layout into the overscan region, so give it that pure
3808 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003809 pf.left = df.left = of.left = mOverscanScreenLeft;
3810 pf.top = df.top = of.top = mOverscanScreenTop;
3811 pf.right = df.right = of.right = mOverscanScreenLeft + mOverscanScreenWidth;
3812 pf.bottom = df.bottom = of.bottom = mOverscanScreenTop
3813 + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003814 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003815 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003816 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3817 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003818 // Asking for layout as if the nav bar is hidden, lets the
Dianne Hackbornc652de82013-02-15 16:32:56 -08003819 // application extend into the unrestricted overscan screen area. We
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003820 // only do this for application windows to ensure no window that
3821 // can be above the nav bar can do this.
Dianne Hackborn313440842013-02-19 19:22:59 -08003822 pf.left = df.left = mOverscanScreenLeft;
3823 pf.top = df.top = mOverscanScreenTop;
3824 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
3825 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003826 // We need to tell the app about where the frame inside the overscan
3827 // is, so it can inset its content by that amount -- it didn't ask
3828 // to actually extend itself into the overscan region.
3829 of.left = mUnrestrictedScreenLeft;
3830 of.top = mUnrestrictedScreenTop;
3831 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3832 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003833 } else {
Dianne Hackborn313440842013-02-19 19:22:59 -08003834 pf.left = df.left = mRestrictedOverscanScreenLeft;
3835 pf.top = df.top = mRestrictedOverscanScreenTop;
3836 pf.right = df.right = mRestrictedOverscanScreenLeft
3837 + mRestrictedOverscanScreenWidth;
3838 pf.bottom = df.bottom = mRestrictedOverscanScreenTop
3839 + mRestrictedOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003840 // We need to tell the app about where the frame inside the overscan
3841 // is, so it can inset its content by that amount -- it didn't ask
3842 // to actually extend itself into the overscan region.
3843 of.left = mUnrestrictedScreenLeft;
3844 of.top = mUnrestrictedScreenTop;
3845 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3846 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003847 }
Craig Mautner69b08182012-09-05 13:07:13 -07003848
John Spurlock46646232013-09-30 22:32:42 -04003849 if ((fl & FLAG_FULLSCREEN) == 0) {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003850 if (win.isVoiceInteraction()) {
3851 cf.left = mVoiceContentLeft;
3852 cf.top = mVoiceContentTop;
3853 cf.right = mVoiceContentRight;
3854 cf.bottom = mVoiceContentBottom;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003855 } else {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003856 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
3857 cf.left = mDockLeft;
3858 cf.top = mDockTop;
3859 cf.right = mDockRight;
3860 cf.bottom = mDockBottom;
3861 } else {
3862 cf.left = mContentLeft;
3863 cf.top = mContentTop;
3864 cf.right = mContentRight;
3865 cf.bottom = mContentBottom;
3866 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003867 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003868 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003869 // Full screen windows are always given a layout that is as if the
3870 // status bar and other transient decors are gone. This is to avoid
3871 // bad states when moving from a window that is not hding the
3872 // status bar to one that is.
3873 cf.left = mRestrictedScreenLeft;
3874 cf.top = mRestrictedScreenTop;
3875 cf.right = mRestrictedScreenLeft + mRestrictedScreenWidth;
3876 cf.bottom = mRestrictedScreenTop + mRestrictedScreenHeight;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003877 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003878 applyStableConstraints(sysUiFl, fl, cf);
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003879 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3880 vf.left = mCurLeft;
3881 vf.top = mCurTop;
3882 vf.right = mCurRight;
3883 vf.bottom = mCurBottom;
3884 } else {
3885 vf.set(cf);
3886 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003887 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003888 } else if ((fl & FLAG_LAYOUT_IN_SCREEN) != 0 || (sysUiFl
3889 & (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
3890 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)) != 0) {
Craig Mautnereda67292013-04-28 13:50:14 -07003891 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3892 "): IN_SCREEN");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003893 // A window that has requested to fill the entire screen just
3894 // gets everything, period.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003895 if (attrs.type == TYPE_STATUS_BAR_PANEL
3896 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003897 pf.left = df.left = of.left = cf.left = hasNavBar
3898 ? mDockLeft : mUnrestrictedScreenLeft;
3899 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
3900 pf.right = df.right = of.right = cf.right = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003901 ? mRestrictedScreenLeft+mRestrictedScreenWidth
Dianne Hackbornc652de82013-02-15 16:32:56 -08003902 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003903 pf.bottom = df.bottom = of.bottom = cf.bottom = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003904 ? mRestrictedScreenTop+mRestrictedScreenHeight
Dianne Hackbornc652de82013-02-15 16:32:56 -08003905 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07003906 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler36412a72011-08-04 09:35:13 -04003907 "Laying out IN_SCREEN status bar window: (%d,%d - %d,%d)",
3908 pf.left, pf.top, pf.right, pf.bottom));
Jim Millere898ac52012-04-06 17:10:57 -07003909 } else if (attrs.type == TYPE_NAVIGATION_BAR
3910 || attrs.type == TYPE_NAVIGATION_BAR_PANEL) {
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003911 // The navigation bar has Real Ultimate Power.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003912 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3913 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3914 pf.right = df.right = of.right = mUnrestrictedScreenLeft
3915 + mUnrestrictedScreenWidth;
3916 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop
3917 + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07003918 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003919 "Laying out navigation bar window: (%d,%d - %d,%d)",
3920 pf.left, pf.top, pf.right, pf.bottom));
Dianne Hackborn01011c32012-02-21 13:54:21 -08003921 } else if ((attrs.type == TYPE_SECURE_SYSTEM_OVERLAY
3922 || attrs.type == TYPE_BOOT_PROGRESS)
Jeff Brownbfcb60a2011-09-08 18:51:14 -07003923 && ((fl & FLAG_FULLSCREEN) != 0)) {
3924 // Fullscreen secure system overlays get what they ask for.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003925 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3926 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3927 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
3928 + mOverscanScreenWidth;
3929 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
3930 + mOverscanScreenHeight;
Craig Mautner165be0c2015-01-27 15:16:58 -08003931 } else if (attrs.type == TYPE_BOOT_PROGRESS) {
Dianne Hackborn01011c32012-02-21 13:54:21 -08003932 // Boot progress screen always covers entire display.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003933 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3934 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3935 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
3936 + mOverscanScreenWidth;
3937 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
3938 + mOverscanScreenHeight;
John Spurlockef4adae2013-08-26 17:58:58 -04003939 } else if (attrs.type == TYPE_WALLPAPER) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07003940 // The wallpaper also has Real Ultimate Power, but we want to tell
3941 // it about the overscan area.
3942 pf.left = df.left = mOverscanScreenLeft;
3943 pf.top = df.top = mOverscanScreenTop;
3944 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
3945 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
3946 of.left = cf.left = mUnrestrictedScreenLeft;
3947 of.top = cf.top = mUnrestrictedScreenTop;
3948 of.right = cf.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3949 of.bottom = cf.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlock46646232013-09-30 22:32:42 -04003950 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08003951 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3952 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3953 // Asking to layout into the overscan region, so give it that pure
3954 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003955 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3956 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3957 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08003958 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003959 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003960 = mOverscanScreenTop + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003961 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003962 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Craig Mautnerbeac1062014-06-03 14:38:57 -07003963 && (attrs.type == TYPE_STATUS_BAR
3964 || attrs.type == TYPE_TOAST
Jorim Jaggi2fdeeab2015-04-01 15:13:03 -07003965 || attrs.type == TYPE_VOICE_INTERACTION_STARTING
John Spurlock34e13d92013-08-10 06:52:28 -04003966 || (attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3967 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW))) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003968 // Asking for layout as if the nav bar is hidden, lets the
3969 // application extend into the unrestricted screen area. We
John Spurlock34e13d92013-08-10 06:52:28 -04003970 // only do this for application windows (or toasts) to ensure no window that
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003971 // can be above the nav bar can do this.
3972 // XXX This assumes that an app asking for this will also
3973 // ask for layout in only content. We can't currently figure out
3974 // what the screen would be if only laying out to hide the nav bar.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003975 pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft;
3976 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
3977 pf.right = df.right = of.right = cf.right = mUnrestrictedScreenLeft
3978 + mUnrestrictedScreenWidth;
3979 pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop
3980 + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003981 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003982 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
3983 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
3984 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
3985 + mRestrictedScreenWidth;
3986 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
3987 + mRestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003988 }
Craig Mautner69b08182012-09-05 13:07:13 -07003989
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003990 applyStableConstraints(sysUiFl, fl, cf);
Craig Mautner69b08182012-09-05 13:07:13 -07003991
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003992 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3993 vf.left = mCurLeft;
3994 vf.top = mCurTop;
3995 vf.right = mCurRight;
3996 vf.bottom = mCurBottom;
3997 } else {
3998 vf.set(cf);
3999 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004000 } else if (attached != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07004001 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
4002 "): attached to " + attached);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004003 // A child window should be placed inside of the same visible
4004 // frame that its parent had.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004005 setAttachedWindowFrames(win, fl, adjust, attached, false, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004006 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07004007 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
4008 "): normal window");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004009 // Otherwise, a normal window must be placed inside the content
4010 // of all screen decorations.
Dianne Hackborna239c842011-06-01 12:28:20 -07004011 if (attrs.type == TYPE_STATUS_BAR_PANEL) {
4012 // Status bar panels are the only windows who can go on top of
4013 // the status bar. They are protected by the STATUS_BAR_SERVICE
4014 // permission, so they have the same privileges as the status
4015 // bar itself.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004016 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
4017 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
4018 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
4019 + mRestrictedScreenWidth;
4020 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
4021 + mRestrictedScreenHeight;
John Spurlock414c1f02013-12-04 13:47:36 -05004022 } else if (attrs.type == TYPE_TOAST || attrs.type == TYPE_SYSTEM_ALERT
4023 || attrs.type == TYPE_VOLUME_OVERLAY) {
4024 // These dialogs are stable to interim decor changes.
John Spurlockbd957402013-10-03 11:38:39 -04004025 pf.left = df.left = of.left = cf.left = mStableLeft;
4026 pf.top = df.top = of.top = cf.top = mStableTop;
4027 pf.right = df.right = of.right = cf.right = mStableRight;
4028 pf.bottom = df.bottom = of.bottom = cf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004029 } else {
Dianne Hackborna239c842011-06-01 12:28:20 -07004030 pf.left = mContentLeft;
4031 pf.top = mContentTop;
4032 pf.right = mContentRight;
4033 pf.bottom = mContentBottom;
Dianne Hackborn20d94742014-05-29 18:35:45 -07004034 if (win.isVoiceInteraction()) {
4035 df.left = of.left = cf.left = mVoiceContentLeft;
4036 df.top = of.top = cf.top = mVoiceContentTop;
4037 df.right = of.right = cf.right = mVoiceContentRight;
4038 df.bottom = of.bottom = cf.bottom = mVoiceContentBottom;
4039 } else if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004040 df.left = of.left = cf.left = mDockLeft;
4041 df.top = of.top = cf.top = mDockTop;
4042 df.right = of.right = cf.right = mDockRight;
4043 df.bottom = of.bottom = cf.bottom = mDockBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07004044 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004045 df.left = of.left = cf.left = mContentLeft;
4046 df.top = of.top = cf.top = mContentTop;
4047 df.right = of.right = cf.right = mContentRight;
4048 df.bottom = of.bottom = cf.bottom = mContentBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07004049 }
4050 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
4051 vf.left = mCurLeft;
4052 vf.top = mCurTop;
4053 vf.right = mCurRight;
4054 vf.bottom = mCurBottom;
4055 } else {
4056 vf.set(cf);
4057 }
Dianne Hackborndea3ef72010-10-28 14:24:22 -07004058 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004059 }
4060 }
Craig Mautner69b08182012-09-05 13:07:13 -07004061
Craig Mautnerb816bed2013-07-23 10:26:17 -07004062 // TYPE_SYSTEM_ERROR is above the NavigationBar so it can't be allowed to extend over it.
4063 if ((fl & FLAG_LAYOUT_NO_LIMITS) != 0 && attrs.type != TYPE_SYSTEM_ERROR) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07004064 df.left = df.top = -10000;
4065 df.right = df.bottom = 10000;
4066 if (attrs.type != TYPE_WALLPAPER) {
4067 of.left = of.top = cf.left = cf.top = vf.left = vf.top = -10000;
4068 of.right = of.bottom = cf.right = cf.bottom = vf.right = vf.bottom = 10000;
4069 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004070 }
4071
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004072 // If the device has a chin (e.g. some watches), a dead area at the bottom of the screen we
4073 // need to provide information to the clients that want to pretend that you can draw there.
4074 if (isDefaultDisplay && (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0) {
4075 osf = mTmpOutsetFrame;
4076 osf.set(cf.left, cf.top, cf.right, cf.bottom);
4077 int outset = ScreenShapeHelper.getWindowOutsetBottomPx(mContext.getResources());
4078 if (outset > 0) {
4079 int rotation = Surface.ROTATION_0;
4080 try {
4081 rotation = mWindowManager.getRotation();
4082 } catch (RemoteException e) {
4083 }
4084 if (rotation == Surface.ROTATION_0) {
4085 osf.bottom += outset;
4086 } else if (rotation == Surface.ROTATION_90) {
4087 osf.right += outset;
4088 } else if (rotation == Surface.ROTATION_180) {
4089 osf.top -= outset;
4090 } else if (rotation == Surface.ROTATION_270) {
4091 osf.left -= outset;
4092 }
4093 if (DEBUG_LAYOUT) Slog.v(TAG, "applying bottom outset of " + outset
4094 + " with rotation " + rotation + ", result: " + osf);
4095 }
4096 }
4097
Craig Mautnereda67292013-04-28 13:50:14 -07004098 if (DEBUG_LAYOUT) Slog.v(TAG, "Compute frame " + attrs.getTitle()
The Android Open Source Project11267662009-03-18 17:39:47 -07004099 + ": sim=#" + Integer.toHexString(sim)
RoboErik8a2cfc32014-05-16 11:19:38 -07004100 + " attach=" + attached + " type=" + attrs.type
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004101 + String.format(" flags=0x%08x", fl)
The Android Open Source Project11267662009-03-18 17:39:47 -07004102 + " pf=" + pf.toShortString() + " df=" + df.toShortString()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004103 + " of=" + of.toShortString()
John Spurlock46646232013-09-30 22:32:42 -04004104 + " cf=" + cf.toShortString() + " vf=" + vf.toShortString()
Adrian Roosfa104232014-06-20 16:10:14 -07004105 + " dcf=" + dcf.toShortString()
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004106 + " sf=" + sf.toShortString()
4107 + " osf=" + (osf == null ? "null" : osf.toShortString()));
Craig Mautner69b08182012-09-05 13:07:13 -07004108
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004109 win.computeFrameLw(pf, df, of, cf, vf, dcf, sf, osf);
Craig Mautner69b08182012-09-05 13:07:13 -07004110
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004111 // Dock windows carve out the bottom of the screen, so normal windows
4112 // can't appear underneath them.
Craig Mautner8bd206b2012-10-03 10:32:02 -07004113 if (attrs.type == TYPE_INPUT_METHOD && win.isVisibleOrBehindKeyguardLw()
4114 && !win.getGivenInsetsPendingLw()) {
satok1bc0a492012-04-25 22:47:12 +09004115 setLastInputMethodWindowLw(null, null);
4116 offsetInputMethodWindowLw(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004117 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004118 if (attrs.type == TYPE_VOICE_INTERACTION && win.isVisibleOrBehindKeyguardLw()
4119 && !win.getGivenInsetsPendingLw()) {
4120 offsetVoiceInputWindowLw(win);
4121 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004122 }
4123
satok1bc0a492012-04-25 22:47:12 +09004124 private void offsetInputMethodWindowLw(WindowState win) {
Craig Mautner4774f6a2015-03-23 11:42:55 -07004125 int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top);
satok1bc0a492012-04-25 22:47:12 +09004126 top += win.getGivenContentInsetsLw().top;
4127 if (mContentBottom > top) {
4128 mContentBottom = top;
4129 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004130 if (mVoiceContentBottom > top) {
4131 mVoiceContentBottom = top;
4132 }
satok1bc0a492012-04-25 22:47:12 +09004133 top = win.getVisibleFrameLw().top;
4134 top += win.getGivenVisibleInsetsLw().top;
4135 if (mCurBottom > top) {
4136 mCurBottom = top;
4137 }
Craig Mautnereda67292013-04-28 13:50:14 -07004138 if (DEBUG_LAYOUT) Slog.v(TAG, "Input method: mDockBottom="
satok1bc0a492012-04-25 22:47:12 +09004139 + mDockBottom + " mContentBottom="
4140 + mContentBottom + " mCurBottom=" + mCurBottom);
4141 }
4142
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004143 private void offsetVoiceInputWindowLw(WindowState win) {
Craig Mautner4774f6a2015-03-23 11:42:55 -07004144 int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08004145 top += win.getGivenContentInsetsLw().top;
4146 if (mVoiceContentBottom > top) {
4147 mVoiceContentBottom = top;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004148 }
4149 }
4150
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004151 /** {@inheritDoc} */
Craig Mautner61ac6bb2012-02-02 17:29:33 -08004152 @Override
4153 public void finishLayoutLw() {
4154 return;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004155 }
4156
4157 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004158 @Override
Craig Mautner39834192012-09-02 07:47:24 -07004159 public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) {
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004160 mTopFullscreenOpaqueWindowState = null;
Adrian Rooscd3884d2015-02-18 17:25:23 +01004161 mTopFullscreenOpaqueOrDimmingWindowState = null;
Craig Mautner2bc789b2014-03-19 19:48:38 -07004162 mAppsToBeHidden.clear();
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004163 mAppsThatDismissKeyguard.clear();
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004164 mForceStatusBar = false;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004165 mForceStatusBarFromKeyguard = false;
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004166 mForceStatusBarTransparent = false;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08004167 mForcingShowNavBar = false;
4168 mForcingShowNavBarLayer = -1;
RoboErik8a2cfc32014-05-16 11:19:38 -07004169
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004170 mHideLockScreen = false;
4171 mAllowLockscreenWhenOn = false;
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004172 mDismissKeyguard = DISMISS_KEYGUARD_NONE;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004173 mShowingLockscreen = false;
4174 mShowingDream = false;
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004175 mWinShowWhenLocked = null;
Jim Millerab954542014-10-10 18:21:49 -07004176 mKeyguardSecure = isKeyguardSecure();
4177 mKeyguardSecureIncludingHidden = mKeyguardSecure
4178 && (mKeyguardDelegate != null && mKeyguardDelegate.isShowing());
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004179 }
4180
4181 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004182 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004183 public void applyPostLayoutPolicyLw(WindowState win, WindowManager.LayoutParams attrs) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004184 if (DEBUG_LAYOUT) Slog.i(TAG, "Win " + win + ": isVisibleOrBehindKeyguardLw="
4185 + win.isVisibleOrBehindKeyguardLw());
John Spurlockc6d1c602014-01-17 15:22:06 -05004186 final int fl = PolicyControl.getWindowFlags(win, attrs);
John Spurlock414c1f02013-12-04 13:47:36 -05004187 if (mTopFullscreenOpaqueWindowState == null
4188 && win.isVisibleLw() && attrs.type == TYPE_INPUT_METHOD) {
4189 mForcingShowNavBar = true;
4190 mForcingShowNavBarLayer = win.getSurfaceLayer();
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08004191 }
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004192 if (attrs.type == TYPE_STATUS_BAR) {
4193 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
4194 mForceStatusBarFromKeyguard = true;
4195 }
4196 if ((attrs.privateFlags & PRIVATE_FLAG_FORCE_STATUS_BAR_VISIBLE_TRANSPARENT) != 0) {
4197 mForceStatusBarTransparent = true;
4198 }
Jorim Jaggiafd4a552014-04-08 15:13:05 +02004199 }
Adrian Roos602c68e2015-04-24 16:03:47 -07004200
4201 boolean appWindow = attrs.type >= FIRST_APPLICATION_WINDOW
4202 && attrs.type < FIRST_SYSTEM_WINDOW;
4203 final boolean showWhenLocked = (fl & FLAG_SHOW_WHEN_LOCKED) != 0;
4204 final boolean dismissKeyguard = (fl & FLAG_DISMISS_KEYGUARD) != 0;
4205
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004206 if (mTopFullscreenOpaqueWindowState == null &&
Dianne Hackborn01b02a72012-01-12 14:05:03 -08004207 win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()) {
John Spurlockc6d1c602014-01-17 15:22:06 -05004208 if ((fl & FLAG_FORCE_NOT_FULLSCREEN) != 0) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004209 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004210 mForceStatusBarFromKeyguard = true;
4211 } else {
4212 mForceStatusBar = true;
4213 }
4214 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004215 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004216 mShowingLockscreen = true;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004217 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004218 if (attrs.type == TYPE_DREAM) {
Jeff Brownc8018eb2012-10-29 21:33:27 -07004219 // If the lockscreen was showing when the dream started then wait
4220 // for the dream to draw before hiding the lockscreen.
4221 if (!mDreamingLockscreen
4222 || (win.isVisibleLw() && win.hasDrawnLw())) {
4223 mShowingDream = true;
Craig Mautnerab55e522014-03-03 13:26:03 -08004224 appWindow = true;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004225 }
4226 }
Craig Mautnerab55e522014-03-03 13:26:03 -08004227
Craig Mautnerab55e522014-03-03 13:26:03 -08004228 if (appWindow) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004229 final IApplicationToken appToken = win.getAppToken();
4230 if (showWhenLocked) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004231 // Remove any previous windows with the same appToken.
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004232 mAppsToBeHidden.remove(appToken);
4233 mAppsThatDismissKeyguard.remove(appToken);
Craig Mautnerca0a1242014-12-02 12:25:14 -08004234 if (mAppsToBeHidden.isEmpty()) {
Craig Mautner192d6042014-12-02 23:24:48 -08004235 if (dismissKeyguard && !mKeyguardSecure) {
4236 mAppsThatDismissKeyguard.add(appToken);
4237 } else {
Craig Mautnerca0a1242014-12-02 12:25:14 -08004238 mWinShowWhenLocked = win;
4239 mHideLockScreen = true;
4240 mForceStatusBarFromKeyguard = false;
Craig Mautnerca0a1242014-12-02 12:25:14 -08004241 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004242 }
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004243 } else if (dismissKeyguard) {
Jim Millerab954542014-10-10 18:21:49 -07004244 if (mKeyguardSecure) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004245 mAppsToBeHidden.add(appToken);
4246 } else {
4247 mAppsToBeHidden.remove(appToken);
4248 }
4249 mAppsThatDismissKeyguard.add(appToken);
Craig Mautner2bc789b2014-03-19 19:48:38 -07004250 } else {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004251 mAppsToBeHidden.add(appToken);
Craig Mautner2bc789b2014-03-19 19:48:38 -07004252 }
Craig Mautnerab55e522014-03-03 13:26:03 -08004253 if (attrs.x == 0 && attrs.y == 0
4254 && attrs.width == WindowManager.LayoutParams.MATCH_PARENT
4255 && attrs.height == WindowManager.LayoutParams.MATCH_PARENT) {
4256 if (DEBUG_LAYOUT) Slog.v(TAG, "Fullscreen window: " + win);
4257 mTopFullscreenOpaqueWindowState = win;
Adrian Rooscd3884d2015-02-18 17:25:23 +01004258 if (mTopFullscreenOpaqueOrDimmingWindowState == null) {
4259 mTopFullscreenOpaqueOrDimmingWindowState = win;
4260 }
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004261 if (!mAppsThatDismissKeyguard.isEmpty() &&
4262 mDismissKeyguard == DISMISS_KEYGUARD_NONE) {
4263 if (DEBUG_LAYOUT) Slog.v(TAG,
4264 "Setting mDismissKeyguard true by win " + win);
4265 mDismissKeyguard = mWinDismissingKeyguard == win ?
4266 DISMISS_KEYGUARD_CONTINUE : DISMISS_KEYGUARD_START;
4267 mWinDismissingKeyguard = win;
Jim Millerab954542014-10-10 18:21:49 -07004268 mForceStatusBarFromKeyguard = mShowingLockscreen && mKeyguardSecure;
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004269 } else if (mAppsToBeHidden.isEmpty() && showWhenLocked) {
4270 if (DEBUG_LAYOUT) Slog.v(TAG,
4271 "Setting mHideLockScreen to true by win " + win);
4272 mHideLockScreen = true;
4273 mForceStatusBarFromKeyguard = false;
Craig Mautnerab55e522014-03-03 13:26:03 -08004274 }
Craig Mautner00156ec2014-03-06 22:29:02 -08004275 if ((fl & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) {
Craig Mautnerab55e522014-03-03 13:26:03 -08004276 mAllowLockscreenWhenOn = true;
4277 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004278 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004279
4280 if (mWinShowWhenLocked != null &&
Adrian Roos602c68e2015-04-24 16:03:47 -07004281 mWinShowWhenLocked.getAppToken() != win.getAppToken() &&
4282 (attrs.flags & FLAG_SHOW_WHEN_LOCKED) == 0) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004283 win.hideLw(false);
4284 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004285 }
Adrian Roos602c68e2015-04-24 16:03:47 -07004286 } else if (mTopFullscreenOpaqueWindowState == null && mWinShowWhenLocked == null) {
4287 // No TopFullscreenOpaqueWindow is showing, but we found a SHOW_WHEN_LOCKED window
4288 // that is being hidden in an animation - keep the
4289 // keyguard hidden until the new window shows up and
4290 // we know whether to show the keyguard or not.
4291 if (win.isAnimatingLw() && appWindow && showWhenLocked) {
4292 mHideLockScreen = true;
4293 mWinShowWhenLocked = win;
4294 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004295 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01004296 if (mTopFullscreenOpaqueOrDimmingWindowState == null
4297 && win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()
4298 && win.isDimming()) {
4299 mTopFullscreenOpaqueOrDimmingWindowState = win;
4300 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004301 }
4302
4303 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004304 @Override
Craig Mautner39834192012-09-02 07:47:24 -07004305 public int finishPostLayoutPolicyLw() {
Craig Mautnerc5e73bf2015-04-21 15:41:26 +00004306 if (mWinShowWhenLocked != null && mTopFullscreenOpaqueWindowState != null &&
4307 mWinShowWhenLocked.getAppToken() != mTopFullscreenOpaqueWindowState.getAppToken()
4308 && isKeyguardLocked()) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004309 // A dialog is dismissing the keyguard. Put the wallpaper behind it and hide the
4310 // fullscreen window.
4311 // TODO: Make sure FLAG_SHOW_WALLPAPER is restored when dialog is dismissed. Or not.
4312 mWinShowWhenLocked.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
4313 mTopFullscreenOpaqueWindowState.hideLw(false);
4314 mTopFullscreenOpaqueWindowState = mWinShowWhenLocked;
4315 }
4316
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004317 int changes = 0;
Joe Onorato93056472010-09-10 10:30:46 -04004318 boolean topIsFullscreen = false;
Daniel Sandlere02d8082010-10-08 15:13:22 -04004319
4320 final WindowManager.LayoutParams lp = (mTopFullscreenOpaqueWindowState != null)
4321 ? mTopFullscreenOpaqueWindowState.getAttrs()
4322 : null;
4323
Jeff Brownc8018eb2012-10-29 21:33:27 -07004324 // If we are not currently showing a dream then remember the current
4325 // lockscreen state. We will use this to determine whether the dream
4326 // started while the lockscreen was showing and remember this state
4327 // while the dream is showing.
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004328 if (!mShowingDream) {
4329 mDreamingLockscreen = mShowingLockscreen;
Jeff Brown061ea992015-04-17 19:55:47 -07004330 if (mDreamingSleepTokenNeeded) {
4331 mDreamingSleepTokenNeeded = false;
4332 mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 0, 1).sendToTarget();
4333 }
4334 } else {
4335 if (!mDreamingSleepTokenNeeded) {
4336 mDreamingSleepTokenNeeded = true;
4337 mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 1, 1).sendToTarget();
4338 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004339 }
4340
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004341 if (mStatusBar != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07004342 if (DEBUG_LAYOUT) Slog.i(TAG, "force=" + mForceStatusBar
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004343 + " forcefkg=" + mForceStatusBarFromKeyguard
Dianne Hackbornd70bc2f2009-10-06 23:25:51 -07004344 + " top=" + mTopFullscreenOpaqueWindowState);
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004345 boolean shouldBeTransparent = mForceStatusBarTransparent
4346 && !mForceStatusBar
4347 && !mForceStatusBarFromKeyguard;
4348 if (!shouldBeTransparent) {
4349 mStatusBarController.setShowTransparent(false /* transparent */);
4350 } else if (!mStatusBar.isVisibleLw()) {
4351 mStatusBarController.setShowTransparent(true /* transparent */);
4352 }
4353 if (mForceStatusBar || mForceStatusBarFromKeyguard || mForceStatusBarTransparent) {
Craig Mautnereda67292013-04-28 13:50:14 -07004354 if (DEBUG_LAYOUT) Slog.v(TAG, "Showing status bar: forced");
John Spurlock27735a42013-08-14 17:57:38 -04004355 if (mStatusBarController.setBarShowingLw(true)) {
4356 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4357 }
Craig Mautner81defc72013-10-29 11:10:42 -07004358 // Maintain fullscreen layout until incoming animation is complete.
4359 topIsFullscreen = mTopIsFullscreen && mStatusBar.isAnimatingLw();
John Spurlockf92b6162013-11-11 15:01:16 -05004360 // Transient status bar on the lockscreen is not allowed
4361 if (mForceStatusBarFromKeyguard && mStatusBarController.isTransientShowing()) {
4362 mStatusBarController.updateVisibilityLw(false /*transientAllowed*/,
4363 mLastSystemUiFlags, mLastSystemUiFlags);
4364 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004365 } else if (mTopFullscreenOpaqueWindowState != null) {
John Spurlockc6d1c602014-01-17 15:22:06 -05004366 final int fl = PolicyControl.getWindowFlags(null, lp);
Joe Onorato93056472010-09-10 10:30:46 -04004367 if (localLOGV) {
Craig Mautnereda67292013-04-28 13:50:14 -07004368 Slog.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw()
Joe Onorato93056472010-09-10 10:30:46 -04004369 + " shown frame: " + mTopFullscreenOpaqueWindowState.getShownFrameLw());
Craig Mautnereda67292013-04-28 13:50:14 -07004370 Slog.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs()
John Spurlockc6d1c602014-01-17 15:22:06 -05004371 + " lp.flags=0x" + Integer.toHexString(fl));
Joe Onorato93056472010-09-10 10:30:46 -04004372 }
John Spurlockc6d1c602014-01-17 15:22:06 -05004373 topIsFullscreen = (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004374 || (mLastSystemUiFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
Joe Onorato93056472010-09-10 10:30:46 -04004375 // The subtle difference between the window for mTopFullscreenOpaqueWindowState
Mark Dolinerd0646dc2014-08-27 16:04:02 -07004376 // and mTopIsFullscreen is that mTopIsFullscreen is set only if the window
Joe Onorato93056472010-09-10 10:30:46 -04004377 // has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the
4378 // case though.
John Spurlock27735a42013-08-14 17:57:38 -04004379 if (mStatusBarController.isTransientShowing()) {
4380 if (mStatusBarController.setBarShowingLw(true)) {
John Spurlock32beb2c2013-03-11 10:16:47 -04004381 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4382 }
4383 } else if (topIsFullscreen) {
Craig Mautnereda67292013-04-28 13:50:14 -07004384 if (DEBUG_LAYOUT) Slog.v(TAG, "** HIDING status bar");
John Spurlock27735a42013-08-14 17:57:38 -04004385 if (mStatusBarController.setBarShowingLw(false)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004386 changes |= FINISH_LAYOUT_REDO_LAYOUT;
Craig Mautnereda67292013-04-28 13:50:14 -07004387 } else {
Craig Mautnerc5a6e442013-06-05 17:22:35 -07004388 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar already hiding");
Daniel Sandler40427442010-07-16 11:44:52 -04004389 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004390 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07004391 if (DEBUG_LAYOUT) Slog.v(TAG, "** SHOWING status bar: top is not fullscreen");
John Spurlock27735a42013-08-14 17:57:38 -04004392 if (mStatusBarController.setBarShowingLw(true)) {
4393 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4394 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004395 }
4396 }
4397 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04004398
Craig Mautner81defc72013-10-29 11:10:42 -07004399 if (mTopIsFullscreen != topIsFullscreen) {
4400 if (!topIsFullscreen) {
4401 // Force another layout when status bar becomes fully shown.
4402 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4403 }
4404 mTopIsFullscreen = topIsFullscreen;
4405 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04004406
Craig Mautner39834192012-09-02 07:47:24 -07004407 // Hide the key guard if a visible window explicitly specifies that it wants to be
4408 // displayed when the screen is locked.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004409 if (mKeyguardDelegate != null && mStatusBar != null) {
4410 if (localLOGV) Slog.v(TAG, "finishPostLayoutPolicyLw: mHideKeyguard="
4411 + mHideLockScreen);
Jim Millerab954542014-10-10 18:21:49 -07004412 if (mDismissKeyguard != DISMISS_KEYGUARD_NONE && !mKeyguardSecure) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004413 mKeyguardHidden = true;
Jim Millerab954542014-10-10 18:21:49 -07004414 if (setKeyguardOccludedLw(true)) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004415 changes |= FINISH_LAYOUT_REDO_LAYOUT
4416 | FINISH_LAYOUT_REDO_CONFIG
4417 | FINISH_LAYOUT_REDO_WALLPAPER;
4418 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004419 if (mKeyguardDelegate.isShowing()) {
4420 mHandler.post(new Runnable() {
4421 @Override
4422 public void run() {
4423 mKeyguardDelegate.keyguardDone(false, false);
4424 }
4425 });
4426 }
4427 } else if (mHideLockScreen) {
4428 mKeyguardHidden = true;
Jorim Jaggi7d85ea92015-05-20 17:20:40 -07004429 mWinDismissingKeyguard = null;
Jim Millerab954542014-10-10 18:21:49 -07004430 if (setKeyguardOccludedLw(true)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004431 changes |= FINISH_LAYOUT_REDO_LAYOUT
4432 | FINISH_LAYOUT_REDO_CONFIG
4433 | FINISH_LAYOUT_REDO_WALLPAPER;
4434 }
4435 } else if (mDismissKeyguard != DISMISS_KEYGUARD_NONE) {
Jorim Jaggi7d85ea92015-05-20 17:20:40 -07004436 mKeyguardHidden = false;
4437 if (setKeyguardOccludedLw(false)) {
4438 changes |= FINISH_LAYOUT_REDO_LAYOUT
4439 | FINISH_LAYOUT_REDO_CONFIG
4440 | FINISH_LAYOUT_REDO_WALLPAPER;
4441 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004442 if (mDismissKeyguard == DISMISS_KEYGUARD_START) {
4443 // Only launch the next keyguard unlock window once per window.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004444 mHandler.post(new Runnable() {
4445 @Override
4446 public void run() {
4447 mKeyguardDelegate.dismiss();
4448 }
4449 });
4450 }
4451 } else {
4452 mWinDismissingKeyguard = null;
4453 mKeyguardHidden = false;
Jim Millerab954542014-10-10 18:21:49 -07004454 if (setKeyguardOccludedLw(false)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004455 changes |= FINISH_LAYOUT_REDO_LAYOUT
4456 | FINISH_LAYOUT_REDO_CONFIG
4457 | FINISH_LAYOUT_REDO_WALLPAPER;
4458 }
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -07004459 }
4460 }
Joe Onorato664644d2011-01-23 17:53:23 -08004461
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004462 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004463 // If the navigation bar has been hidden or shown, we need to do another
4464 // layout pass to update that window.
4465 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4466 }
Joe Onorato664644d2011-01-23 17:53:23 -08004467
Mike Lockwood28569302010-01-28 11:54:40 -05004468 // update since mAllowLockscreenWhenOn might have changed
4469 updateLockScreenTimeout();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004470 return changes;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004471 }
4472
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004473 /**
Jim Millerab954542014-10-10 18:21:49 -07004474 * Updates the occluded state of the Keyguard.
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004475 *
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004476 * @return Whether the flags have changed and we have to redo the layout.
4477 */
Jim Millerab954542014-10-10 18:21:49 -07004478 private boolean setKeyguardOccludedLw(boolean isOccluded) {
4479 boolean wasOccluded = mKeyguardOccluded;
4480 boolean showing = mKeyguardDelegate.isShowing();
4481 if (wasOccluded && !isOccluded && showing) {
4482 mKeyguardOccluded = false;
4483 mKeyguardDelegate.setOccluded(false);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004484 mStatusBar.getAttrs().privateFlags |= PRIVATE_FLAG_KEYGUARD;
4485 mStatusBar.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
4486 return true;
Jim Millerab954542014-10-10 18:21:49 -07004487 } else if (!wasOccluded && isOccluded && showing) {
4488 mKeyguardOccluded = true;
4489 mKeyguardDelegate.setOccluded(true);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004490 mStatusBar.getAttrs().privateFlags &= ~PRIVATE_FLAG_KEYGUARD;
4491 mStatusBar.getAttrs().flags &= ~FLAG_SHOW_WALLPAPER;
4492 return true;
4493 } else {
4494 return false;
4495 }
4496 }
4497
4498 private boolean isStatusBarKeyguard() {
4499 return mStatusBar != null
4500 && (mStatusBar.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
4501 }
4502
Jose Lima9546b202014-07-02 17:21:51 -07004503 @Override
Dianne Hackborn08743722009-12-21 12:16:51 -08004504 public boolean allowAppAnimationsLw() {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004505 if (isStatusBarKeyguard() || mShowingDream) {
Craig Mautner28816302013-10-10 20:31:00 -07004506 // If keyguard or dreams is currently visible, no reason to animate behind it.
Dianne Hackborn08743722009-12-21 12:16:51 -08004507 return false;
4508 }
Dianne Hackborn08743722009-12-21 12:16:51 -08004509 return true;
4510 }
4511
Jose Lima9546b202014-07-02 17:21:51 -07004512 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07004513 public int focusChangedLw(WindowState lastFocus, WindowState newFocus) {
Joe Onorato664644d2011-01-23 17:53:23 -08004514 mFocusedWindow = newFocus;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004515 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004516 // If the navigation bar has been hidden or shown, we need to do another
4517 // layout pass to update that window.
4518 return FINISH_LAYOUT_REDO_LAYOUT;
4519 }
4520 return 0;
Joe Onorato664644d2011-01-23 17:53:23 -08004521 }
4522
Dianne Hackborn0ecadf72009-03-31 18:00:37 -07004523 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07004524 @Override
Jeff Brown46b9ac02010-04-22 18:58:52 -07004525 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
4526 // lid changed state
Jeff Brownc458ce92012-04-30 14:58:40 -07004527 final int newLidState = lidOpen ? LID_OPEN : LID_CLOSED;
4528 if (newLidState == mLidState) {
4529 return;
4530 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004531
Jeff Brownc458ce92012-04-30 14:58:40 -07004532 mLidState = newLidState;
4533 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07004534 updateRotation(true);
Jeff Brownc458ce92012-04-30 14:58:40 -07004535
4536 if (lidOpen) {
Bryce Lee584a4452014-10-21 15:55:55 -07004537 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromLidSwitch);
Jeff Brownc458ce92012-04-30 14:58:40 -07004538 } else if (!mLidControlsSleep) {
Jeff Brown96307042012-07-27 15:51:34 -07004539 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
Jeff Brown46b9ac02010-04-22 18:58:52 -07004540 }
4541 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004542
Michael Wright3818c922014-09-02 13:59:07 -07004543 @Override
4544 public void notifyCameraLensCoverSwitchChanged(long whenNanos, boolean lensCovered) {
4545 int lensCoverState = lensCovered ? CAMERA_LENS_COVERED : CAMERA_LENS_UNCOVERED;
4546 if (mCameraLensCoverState == lensCoverState) {
4547 return;
4548 }
4549 if (mCameraLensCoverState == CAMERA_LENS_COVERED &&
4550 lensCoverState == CAMERA_LENS_UNCOVERED) {
4551 Intent intent;
4552 final boolean keyguardActive = mKeyguardDelegate == null ? false :
4553 mKeyguardDelegate.isShowing();
4554 if (keyguardActive) {
4555 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE);
4556 } else {
4557 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
4558 }
Bryce Lee584a4452014-10-21 15:55:55 -07004559 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromCameraLens);
Bart Sears8b1c27c2015-03-18 23:51:02 +00004560 startActivityAsUser(intent, UserHandle.CURRENT_OR_SELF);
Michael Wright3818c922014-09-02 13:59:07 -07004561 }
4562 mCameraLensCoverState = lensCoverState;
4563 }
4564
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004565 void setHdmiPlugged(boolean plugged) {
4566 if (mHdmiPlugged != plugged) {
4567 mHdmiPlugged = plugged;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004568 updateRotation(true, true);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004569 Intent intent = new Intent(ACTION_HDMI_PLUGGED);
Joe Onoratodc100302011-01-11 17:07:41 -08004570 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004571 intent.putExtra(EXTRA_HDMI_PLUGGED_STATE, plugged);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07004572 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004573 }
4574 }
4575
Joe Onoratoea495d42011-04-06 11:41:11 -07004576 void initializeHdmiState() {
Joe Onorato7ba631f2011-05-04 15:28:00 -07004577 boolean plugged = false;
Joe Onoratoea495d42011-04-06 11:41:11 -07004578 // watch for HDMI plug messages if the hdmi switch exists
4579 if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) {
4580 mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi");
4581
Joe Onoratoea495d42011-04-06 11:41:11 -07004582 final String filename = "/sys/class/switch/hdmi/state";
4583 FileReader reader = null;
4584 try {
4585 reader = new FileReader(filename);
4586 char[] buf = new char[15];
4587 int n = reader.read(buf);
4588 if (n > 1) {
4589 plugged = 0 != Integer.parseInt(new String(buf, 0, n-1));
4590 }
4591 } catch (IOException ex) {
4592 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
4593 } catch (NumberFormatException ex) {
4594 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
4595 } finally {
4596 if (reader != null) {
4597 try {
4598 reader.close();
4599 } catch (IOException ex) {
4600 }
Joe Onoratodc100302011-01-11 17:07:41 -08004601 }
4602 }
4603 }
Joe Onorato7ba631f2011-05-04 15:28:00 -07004604 // This dance forces the code in setHdmiPlugged to run.
4605 // Always do this so the sticky intent is stuck (to false) if there is no hdmi.
4606 mHdmiPlugged = !plugged;
4607 setHdmiPlugged(!mHdmiPlugged);
Joe Onoratodc100302011-01-11 17:07:41 -08004608 }
4609
Dianne Hackbornc0e3f242011-08-19 14:19:10 -07004610 final Object mScreenshotLock = new Object();
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004611 ServiceConnection mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004612
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004613 final Runnable mScreenshotTimeout = new Runnable() {
4614 @Override public void run() {
4615 synchronized (mScreenshotLock) {
4616 if (mScreenshotConnection != null) {
4617 mContext.unbindService(mScreenshotConnection);
4618 mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004619 }
Winson Chung9112ec32011-06-27 13:15:32 -07004620 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004621 }
4622 };
4623
4624 // Assume this is called from the Handler thread.
4625 private void takeScreenshot() {
4626 synchronized (mScreenshotLock) {
4627 if (mScreenshotConnection != null) {
4628 return;
4629 }
4630 ComponentName cn = new ComponentName("com.android.systemui",
4631 "com.android.systemui.screenshot.TakeScreenshotService");
4632 Intent intent = new Intent();
4633 intent.setComponent(cn);
4634 ServiceConnection conn = new ServiceConnection() {
4635 @Override
4636 public void onServiceConnected(ComponentName name, IBinder service) {
4637 synchronized (mScreenshotLock) {
4638 if (mScreenshotConnection != this) {
4639 return;
4640 }
4641 Messenger messenger = new Messenger(service);
4642 Message msg = Message.obtain(null, 1);
4643 final ServiceConnection myConn = this;
4644 Handler h = new Handler(mHandler.getLooper()) {
4645 @Override
4646 public void handleMessage(Message msg) {
4647 synchronized (mScreenshotLock) {
4648 if (mScreenshotConnection == myConn) {
4649 mContext.unbindService(mScreenshotConnection);
4650 mScreenshotConnection = null;
4651 mHandler.removeCallbacks(mScreenshotTimeout);
4652 }
4653 }
4654 }
4655 };
4656 msg.replyTo = new Messenger(h);
Winson Chunga63bb842011-10-17 10:26:28 -07004657 msg.arg1 = msg.arg2 = 0;
4658 if (mStatusBar != null && mStatusBar.isVisibleLw())
4659 msg.arg1 = 1;
4660 if (mNavigationBar != null && mNavigationBar.isVisibleLw())
4661 msg.arg2 = 1;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004662 try {
4663 messenger.send(msg);
4664 } catch (RemoteException e) {
4665 }
4666 }
4667 }
4668 @Override
4669 public void onServiceDisconnected(ComponentName name) {}
4670 };
Amith Yamasani27b89e62013-01-16 12:30:11 -08004671 if (mContext.bindServiceAsUser(
4672 intent, conn, Context.BIND_AUTO_CREATE, UserHandle.CURRENT)) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004673 mScreenshotConnection = conn;
4674 mHandler.postDelayed(mScreenshotTimeout, 10000);
4675 }
4676 }
Winson Chung9112ec32011-06-27 13:15:32 -07004677 }
4678
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004679 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004680 @Override
Jeff Brown037c33e2014-04-09 00:31:55 -07004681 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) {
Jeff Brown96307042012-07-27 15:51:34 -07004682 if (!mSystemBooted) {
4683 // If we have not yet booted, don't let key events do anything.
4684 return 0;
4685 }
4686
Jeff Brown037c33e2014-04-09 00:31:55 -07004687 final boolean interactive = (policyFlags & FLAG_INTERACTIVE) != 0;
Jeff Brown1f245102010-11-18 20:53:46 -08004688 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
4689 final boolean canceled = event.isCanceled();
4690 final int keyCode = event.getKeyCode();
Jeff Browne20c9e02010-10-11 14:20:19 -07004691
Jeff Brown3122e442010-10-11 23:32:49 -07004692 final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0;
Jeff Brown3122e442010-10-11 23:32:49 -07004693
Mike Lockwoodc72b15f2009-11-28 20:58:22 -05004694 // If screen is off then we treat the case where the keyguard is open but hidden
4695 // the same as if it were open and in front.
4696 // This will prevent any keys other than the power button from waking the screen
4697 // when the keyguard is hidden by another activity.
Jim Miller5ecd8112013-01-09 18:50:26 -08004698 final boolean keyguardActive = (mKeyguardDelegate == null ? false :
Jeff Brown037c33e2014-04-09 00:31:55 -07004699 (interactive ?
Jim Millerab954542014-10-10 18:21:49 -07004700 isKeyguardShowingAndNotOccluded() :
Jim Miller5ecd8112013-01-09 18:50:26 -08004701 mKeyguardDelegate.isShowing()));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004702
Jeff Brown40013652012-05-16 21:22:36 -07004703 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004704 Log.d(TAG, "interceptKeyTq keycode=" + keyCode
Jeff Brown037c33e2014-04-09 00:31:55 -07004705 + " interactive=" + interactive + " keyguardActive=" + keyguardActive
Jeff Brown26875502014-01-30 21:47:47 -08004706 + " policyFlags=" + Integer.toHexString(policyFlags));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004707 }
4708
Jeff Brown037c33e2014-04-09 00:31:55 -07004709 // Basic policy based on interactive state.
Jeff Brown4d396052010-10-29 21:50:21 -07004710 int result;
Michael Wright337d9d22014-04-22 15:03:48 -07004711 boolean isWakeKey = (policyFlags & WindowManagerPolicy.FLAG_WAKE) != 0
4712 || event.isWakeKey();
Michael Wrightfc01f042014-09-08 14:12:24 -07004713 if (interactive || (isInjected && !isWakeKey)) {
RoboErikde9ba392014-09-26 12:51:01 -07004714 // When the device is interactive or the key is injected pass the
4715 // key to the application.
Jeff Brown4d396052010-10-29 21:50:21 -07004716 result = ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07004717 isWakeKey = false;
Michael Wrightfc01f042014-09-08 14:12:24 -07004718 } else if (!interactive && shouldDispatchInputWhenNonInteractive()) {
4719 // If we're currently dozing with the screen on and the keyguard showing, pass the key
4720 // to the application but preserve its wake key status to make sure we still move
4721 // from dozing to fully interactive if we would normally go from off to fully
4722 // interactive.
4723 result = ACTION_PASS_TO_USER;
Jeff Brown4d396052010-10-29 21:50:21 -07004724 } else {
4725 // When the screen is off and the key is not injected, determine whether
4726 // to wake the device but don't pass the key to the application.
4727 result = 0;
Jeff Brown26875502014-01-30 21:47:47 -08004728 if (isWakeKey && (!down || !isWakeKeyWhenScreenOff(keyCode))) {
4729 isWakeKey = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004730 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004731 }
4732
Justin Kohd378ad72013-04-01 12:18:26 -07004733 // If the key would be handled globally, just return the result, don't worry about special
4734 // key processing.
Jeff Brown13f00f02014-10-31 14:45:50 -07004735 if (isValidGlobalKey(keyCode)
4736 && mGlobalKeyManager.shouldHandleGlobalKey(keyCode, event)) {
Michael Wright85b1af62014-06-04 14:51:58 -07004737 if (isWakeKey) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004738 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey);
Michael Wright85b1af62014-06-04 14:51:58 -07004739 }
Justin Kohd378ad72013-04-01 12:18:26 -07004740 return result;
4741 }
4742
Jeff Brownbae8e772014-06-12 19:59:45 -07004743 boolean useHapticFeedback = down
4744 && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0
4745 && event.getRepeatCount() == 0;
4746
Jeff Brown4d396052010-10-29 21:50:21 -07004747 // Handle special keys.
4748 switch (keyCode) {
4749 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jeff Brownb0418da2010-11-01 15:24:01 -07004750 case KeyEvent.KEYCODE_VOLUME_UP:
4751 case KeyEvent.KEYCODE_VOLUME_MUTE: {
RoboErik001c59c2015-01-26 15:53:51 -08004752 if (mUseTvRouting) {
4753 // On TVs volume keys never go to the foreground app
4754 result &= ~ACTION_PASS_TO_USER;
4755 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004756 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
4757 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004758 if (interactive && !mScreenshotChordVolumeDownKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004759 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004760 mScreenshotChordVolumeDownKeyTriggered = true;
4761 mScreenshotChordVolumeDownKeyTime = event.getDownTime();
4762 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004763 cancelPendingPowerKeyAction();
4764 interceptScreenshotChord();
4765 }
4766 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004767 mScreenshotChordVolumeDownKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004768 cancelPendingScreenshotChordAction();
4769 }
4770 } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
4771 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004772 if (interactive && !mScreenshotChordVolumeUpKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004773 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004774 mScreenshotChordVolumeUpKeyTriggered = true;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004775 cancelPendingPowerKeyAction();
4776 cancelPendingScreenshotChordAction();
4777 }
4778 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004779 mScreenshotChordVolumeUpKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004780 cancelPendingScreenshotChordAction();
4781 }
4782 }
Jeff Brown4d396052010-10-29 21:50:21 -07004783 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004784 TelecomManager telecomManager = getTelecommService();
4785 if (telecomManager != null) {
4786 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07004787 // If an incoming call is ringing, either VOLUME key means
4788 // "silence ringer". We handle these keys here, rather than
4789 // in the InCallScreen, to make sure we'll respond to them
4790 // even if the InCallScreen hasn't come to the foreground yet.
4791 // Look for the DOWN event here, to agree with the "fallback"
4792 // behavior in the InCallScreen.
4793 Log.i(TAG, "interceptKeyBeforeQueueing:"
4794 + " VOLUME key-down while ringing: Silence ringer!");
Jeff Brown4d396052010-10-29 21:50:21 -07004795
Santos Cordon6848f722014-05-21 15:22:12 -07004796 // Silence the ringer. (It's safe to call this
4797 // even if the ringer has already been silenced.)
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004798 telecomManager.silenceRinger();
Jeff Brown4d396052010-10-29 21:50:21 -07004799
Santos Cordon6848f722014-05-21 15:22:12 -07004800 // And *don't* pass this key thru to the current activity
4801 // (which is probably the InCallScreen.)
4802 result &= ~ACTION_PASS_TO_USER;
4803 break;
4804 }
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004805 if (telecomManager.isInCall()
Santos Cordon6848f722014-05-21 15:22:12 -07004806 && (result & ACTION_PASS_TO_USER) == 0) {
4807 // If we are in call but we decided not to pass the key to
RoboErik430fc482014-06-12 15:49:20 -07004808 // the application, just pass it to the session service.
4809
4810 MediaSessionLegacyHelper.getHelper(mContext)
RoboErik3c45c292014-07-08 16:47:31 -07004811 .sendVolumeKeyEvent(event, false);
Santos Cordon6848f722014-05-21 15:22:12 -07004812 break;
Jeff Brown4d396052010-10-29 21:50:21 -07004813 }
4814 }
4815
RoboErik430fc482014-06-12 15:49:20 -07004816 if ((result & ACTION_PASS_TO_USER) == 0) {
RoboErik001c59c2015-01-26 15:53:51 -08004817 if (mUseTvRouting) {
4818 dispatchDirectAudioEvent(event);
4819 } else {
4820 // If we aren't passing to the user and no one else
4821 // handled it send it to the session manager to
4822 // figure out.
4823 MediaSessionLegacyHelper.getHelper(mContext)
4824 .sendVolumeKeyEvent(event, true);
4825 }
Jeff Brown4d396052010-10-29 21:50:21 -07004826 break;
4827 }
4828 }
4829 break;
4830 }
4831
4832 case KeyEvent.KEYCODE_ENDCALL: {
4833 result &= ~ACTION_PASS_TO_USER;
4834 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004835 TelecomManager telecomManager = getTelecommService();
Jeff Brown4d396052010-10-29 21:50:21 -07004836 boolean hungUp = false;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004837 if (telecomManager != null) {
4838 hungUp = telecomManager.endCall();
Jeff Brown4d396052010-10-29 21:50:21 -07004839 }
Jeff Brown13f00f02014-10-31 14:45:50 -07004840 if (interactive && !hungUp) {
4841 mEndCallKeyHandled = false;
4842 mHandler.postDelayed(mEndCallLongPress,
4843 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
4844 } else {
4845 mEndCallKeyHandled = true;
4846 }
Jeff Brown4d396052010-10-29 21:50:21 -07004847 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004848 if (!mEndCallKeyHandled) {
4849 mHandler.removeCallbacks(mEndCallLongPress);
4850 if (!canceled) {
4851 if ((mEndcallBehavior
4852 & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) {
4853 if (goHome()) {
4854 break;
4855 }
Dianne Hackborn0041e972009-07-24 17:14:43 -07004856 }
Jeff Brown13f00f02014-10-31 14:45:50 -07004857 if ((mEndcallBehavior
4858 & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) {
4859 mPowerManager.goToSleep(event.getEventTime(),
4860 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
4861 isWakeKey = false;
4862 }
Jeff Brown4d396052010-10-29 21:50:21 -07004863 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004864 }
Jeff Brown4d396052010-10-29 21:50:21 -07004865 }
4866 break;
4867 }
4868
4869 case KeyEvent.KEYCODE_POWER: {
4870 result &= ~ACTION_PASS_TO_USER;
Jeff Brown13f00f02014-10-31 14:45:50 -07004871 isWakeKey = false; // wake-up will be handled separately
Jeff Brown4d396052010-10-29 21:50:21 -07004872 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004873 interceptPowerKeyDown(event, interactive);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004874 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004875 interceptPowerKeyUp(event, interactive, canceled);
Jeff Brown4d396052010-10-29 21:50:21 -07004876 }
4877 break;
4878 }
4879
Jeff Brown6212a492014-03-07 13:58:47 -08004880 case KeyEvent.KEYCODE_SLEEP: {
4881 result &= ~ACTION_PASS_TO_USER;
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00004882 isWakeKey = false;
Jeff Brownbae8e772014-06-12 19:59:45 -07004883 if (!mPowerManager.isInteractive()) {
4884 useHapticFeedback = false; // suppress feedback if already non-interactive
4885 }
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00004886 sleepPress(event);
Jeff Brown6212a492014-03-07 13:58:47 -08004887 break;
4888 }
4889
4890 case KeyEvent.KEYCODE_WAKEUP: {
4891 result &= ~ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07004892 isWakeKey = true;
Jeff Brown6212a492014-03-07 13:58:47 -08004893 break;
4894 }
4895
Jeff Brown4d396052010-10-29 21:50:21 -07004896 case KeyEvent.KEYCODE_MEDIA_PLAY:
4897 case KeyEvent.KEYCODE_MEDIA_PAUSE:
4898 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
Jeff Brown4d396052010-10-29 21:50:21 -07004899 case KeyEvent.KEYCODE_HEADSETHOOK:
4900 case KeyEvent.KEYCODE_MUTE:
4901 case KeyEvent.KEYCODE_MEDIA_STOP:
4902 case KeyEvent.KEYCODE_MEDIA_NEXT:
4903 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
4904 case KeyEvent.KEYCODE_MEDIA_REWIND:
4905 case KeyEvent.KEYCODE_MEDIA_RECORD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09004906 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
4907 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: {
RoboErikde9ba392014-09-26 12:51:01 -07004908 if (MediaSessionLegacyHelper.getHelper(mContext).isGlobalPriorityActive()) {
4909 // If the global session is active pass all media keys to it
4910 // instead of the active window.
4911 result &= ~ACTION_PASS_TO_USER;
4912 }
Jeff Brown4d396052010-10-29 21:50:21 -07004913 if ((result & ACTION_PASS_TO_USER) == 0) {
4914 // Only do this if we would otherwise not pass it to the user. In that
4915 // case, the PhoneWindow class will do the same thing, except it will
4916 // only do it if the showing app doesn't process the key on its own.
Jeff Brown40013652012-05-16 21:22:36 -07004917 // Note that we need to make a copy of the key event here because the
4918 // original key event will be recycled when we return.
Jeff Brown4d396052010-10-29 21:50:21 -07004919 mBroadcastWakeLock.acquire();
Jeff Brown40013652012-05-16 21:22:36 -07004920 Message msg = mHandler.obtainMessage(MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK,
4921 new KeyEvent(event));
4922 msg.setAsynchronous(true);
4923 msg.sendToTarget();
Jeff Brown4d396052010-10-29 21:50:21 -07004924 }
4925 break;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004926 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004927
Jeff Brown4d396052010-10-29 21:50:21 -07004928 case KeyEvent.KEYCODE_CALL: {
4929 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004930 TelecomManager telecomManager = getTelecommService();
4931 if (telecomManager != null) {
4932 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07004933 Log.i(TAG, "interceptKeyBeforeQueueing:"
4934 + " CALL key-down while ringing: Answer the call!");
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004935 telecomManager.acceptRingingCall();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004936
Santos Cordon6848f722014-05-21 15:22:12 -07004937 // And *don't* pass this key thru to the current activity
4938 // (which is presumably the InCallScreen.)
4939 result &= ~ACTION_PASS_TO_USER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004940 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004941 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004942 }
Jeff Brown4d396052010-10-29 21:50:21 -07004943 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004944 }
Michael Wright869a67c2014-08-26 19:33:06 -07004945 case KeyEvent.KEYCODE_VOICE_ASSIST: {
4946 // Only do this if we would otherwise not pass it to the user. In that case,
4947 // interceptKeyBeforeDispatching would apply a similar but different policy in
4948 // order to invoke voice assist actions. Note that we need to make a copy of the
4949 // key event here because the original key event will be recycled when we return.
4950 if ((result & ACTION_PASS_TO_USER) == 0 && !down) {
4951 mBroadcastWakeLock.acquire();
4952 Message msg = mHandler.obtainMessage(MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK,
4953 keyguardActive ? 1 : 0, 0);
4954 msg.setAsynchronous(true);
4955 msg.sendToTarget();
4956 }
4957 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004958 }
Jeff Brown26875502014-01-30 21:47:47 -08004959
Jeff Brownbae8e772014-06-12 19:59:45 -07004960 if (useHapticFeedback) {
4961 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
4962 }
4963
Jeff Brown26875502014-01-30 21:47:47 -08004964 if (isWakeKey) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004965 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey);
Jeff Brown26875502014-01-30 21:47:47 -08004966 }
Bryce Lee584a4452014-10-21 15:55:55 -07004967
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004968 return result;
4969 }
4970
Jeff Brown1c2e4942012-11-06 16:32:01 -08004971 /**
Jeff Brown13f00f02014-10-31 14:45:50 -07004972 * Returns true if the key can have global actions attached to it.
4973 * We reserve all power management keys for the system since they require
4974 * very careful handling.
4975 */
4976 private static boolean isValidGlobalKey(int keyCode) {
4977 switch (keyCode) {
4978 case KeyEvent.KEYCODE_POWER:
4979 case KeyEvent.KEYCODE_WAKEUP:
4980 case KeyEvent.KEYCODE_SLEEP:
4981 return false;
4982 default:
4983 return true;
4984 }
4985 }
4986
4987 /**
Jeff Brown1c2e4942012-11-06 16:32:01 -08004988 * When the screen is off we ignore some keys that might otherwise typically
4989 * be considered wake keys. We filter them out here.
4990 *
4991 * {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it
4992 * is always considered a wake key.
4993 */
4994 private boolean isWakeKeyWhenScreenOff(int keyCode) {
4995 switch (keyCode) {
4996 // ignore volume keys unless docked
4997 case KeyEvent.KEYCODE_VOLUME_UP:
4998 case KeyEvent.KEYCODE_VOLUME_DOWN:
4999 case KeyEvent.KEYCODE_VOLUME_MUTE:
5000 return mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED;
5001
5002 // ignore media and camera keys
5003 case KeyEvent.KEYCODE_MUTE:
5004 case KeyEvent.KEYCODE_HEADSETHOOK:
5005 case KeyEvent.KEYCODE_MEDIA_PLAY:
5006 case KeyEvent.KEYCODE_MEDIA_PAUSE:
5007 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
5008 case KeyEvent.KEYCODE_MEDIA_STOP:
5009 case KeyEvent.KEYCODE_MEDIA_NEXT:
5010 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
5011 case KeyEvent.KEYCODE_MEDIA_REWIND:
5012 case KeyEvent.KEYCODE_MEDIA_RECORD:
5013 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09005014 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK:
Jeff Brown1c2e4942012-11-06 16:32:01 -08005015 case KeyEvent.KEYCODE_CAMERA:
5016 return false;
5017 }
5018 return true;
5019 }
5020
5021
Jeff Brown56194eb2011-03-02 19:23:13 -08005022 /** {@inheritDoc} */
5023 @Override
Michael Wright70af00a2014-09-03 19:30:20 -07005024 public int interceptMotionBeforeQueueingNonInteractive(long whenNanos, int policyFlags) {
5025 if ((policyFlags & FLAG_WAKE) != 0) {
Bryce Lee5c138322014-11-03 08:26:09 -08005026 if (wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotion)) {
5027 return 0;
5028 }
Michael Wright70af00a2014-09-03 19:30:20 -07005029 }
Bryce Lee5c138322014-11-03 08:26:09 -08005030
Michael Wright70af00a2014-09-03 19:30:20 -07005031 if (shouldDispatchInputWhenNonInteractive()) {
5032 return ACTION_PASS_TO_USER;
5033 }
Bryce Lee5c138322014-11-03 08:26:09 -08005034
Bryce Lee812d7022014-11-10 13:33:28 -08005035 // If we have not passed the action up and we are in theater mode without dreaming,
5036 // there will be no dream to intercept the touch and wake into ambient. The device should
5037 // wake up in this case.
5038 if (isTheaterModeEnabled() && (policyFlags & FLAG_WAKE) != 0) {
5039 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotionWhenNotDreaming);
5040 }
5041
Jeff Brown037c33e2014-04-09 00:31:55 -07005042 return 0;
Jeff Brown56194eb2011-03-02 19:23:13 -08005043 }
5044
Michael Wright70af00a2014-09-03 19:30:20 -07005045 private boolean shouldDispatchInputWhenNonInteractive() {
Bryce Lee5c138322014-11-03 08:26:09 -08005046 // Send events to keyguard while the screen is on.
Jim Millerab954542014-10-10 18:21:49 -07005047 if (isKeyguardShowingAndNotOccluded() && mDisplay != null
5048 && mDisplay.getState() != Display.STATE_OFF) {
Bryce Lee5c138322014-11-03 08:26:09 -08005049 return true;
5050 }
5051
5052 // Send events to a dozing dream even if the screen is off since the dream
5053 // is in control of the state of the screen.
5054 IDreamManager dreamManager = getDreamManager();
5055
5056 try {
5057 if (dreamManager != null && dreamManager.isDreaming()) {
5058 return true;
5059 }
5060 } catch (RemoteException e) {
5061 Slog.e(TAG, "RemoteException when checking if dreaming", e);
5062 }
5063
5064 // Otherwise, consume events since the user can't see what is being
5065 // interacted with.
5066 return false;
Michael Wright70af00a2014-09-03 19:30:20 -07005067 }
5068
RoboErik001c59c2015-01-26 15:53:51 -08005069 private void dispatchDirectAudioEvent(KeyEvent event) {
5070 if (event.getAction() != KeyEvent.ACTION_DOWN) {
5071 return;
5072 }
5073 int keyCode = event.getKeyCode();
John Spurlockb94f2d62015-03-17 14:11:57 -04005074 int flags = AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_PLAY_SOUND
5075 | AudioManager.FLAG_FROM_KEY;
RoboErik001c59c2015-01-26 15:53:51 -08005076 String pkgName = mContext.getOpPackageName();
5077 switch (keyCode) {
5078 case KeyEvent.KEYCODE_VOLUME_UP:
5079 try {
John Spurlockee5ad722015-03-03 16:17:21 -05005080 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_RAISE,
John Spurlock90874332015-03-10 16:00:54 -04005081 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005082 } catch (RemoteException e) {
5083 Log.e(TAG, "Error dispatching volume up in dispatchTvAudioEvent.", e);
5084 }
5085 break;
5086 case KeyEvent.KEYCODE_VOLUME_DOWN:
5087 try {
John Spurlockee5ad722015-03-03 16:17:21 -05005088 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_LOWER,
John Spurlock90874332015-03-10 16:00:54 -04005089 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005090 } catch (RemoteException e) {
5091 Log.e(TAG, "Error dispatching volume down in dispatchTvAudioEvent.", e);
5092 }
5093 break;
5094 case KeyEvent.KEYCODE_VOLUME_MUTE:
5095 try {
5096 if (event.getRepeatCount() == 0) {
John Spurlockee5ad722015-03-03 16:17:21 -05005097 getAudioService().adjustSuggestedStreamVolume(
5098 AudioManager.ADJUST_TOGGLE_MUTE,
John Spurlock90874332015-03-10 16:00:54 -04005099 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005100 }
5101 } catch (RemoteException e) {
5102 Log.e(TAG, "Error dispatching mute in dispatchTvAudioEvent.", e);
5103 }
5104 break;
5105 }
5106 }
5107
Jeff Brown40013652012-05-16 21:22:36 -07005108 void dispatchMediaKeyWithWakeLock(KeyEvent event) {
5109 if (DEBUG_INPUT) {
5110 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: " + event);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005111 }
5112
Jeff Brown40013652012-05-16 21:22:36 -07005113 if (mHavePendingMediaKeyRepeatWithWakeLock) {
5114 if (DEBUG_INPUT) {
5115 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: canceled repeat");
5116 }
5117
5118 mHandler.removeMessages(MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK);
5119 mHavePendingMediaKeyRepeatWithWakeLock = false;
5120 mBroadcastWakeLock.release(); // pending repeat was holding onto the wake lock
5121 }
5122
5123 dispatchMediaKeyWithWakeLockToAudioService(event);
5124
5125 if (event.getAction() == KeyEvent.ACTION_DOWN
5126 && event.getRepeatCount() == 0) {
5127 mHavePendingMediaKeyRepeatWithWakeLock = true;
5128
5129 Message msg = mHandler.obtainMessage(
5130 MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK, event);
5131 msg.setAsynchronous(true);
5132 mHandler.sendMessageDelayed(msg, ViewConfiguration.getKeyRepeatTimeout());
5133 } else {
5134 mBroadcastWakeLock.release();
5135 }
5136 }
5137
5138 void dispatchMediaKeyRepeatWithWakeLock(KeyEvent event) {
5139 mHavePendingMediaKeyRepeatWithWakeLock = false;
5140
5141 KeyEvent repeatEvent = KeyEvent.changeTimeRepeat(event,
5142 SystemClock.uptimeMillis(), 1, event.getFlags() | KeyEvent.FLAG_LONG_PRESS);
5143 if (DEBUG_INPUT) {
5144 Slog.d(TAG, "dispatchMediaKeyRepeatWithWakeLock: " + repeatEvent);
5145 }
5146
5147 dispatchMediaKeyWithWakeLockToAudioService(repeatEvent);
5148 mBroadcastWakeLock.release();
5149 }
5150
5151 void dispatchMediaKeyWithWakeLockToAudioService(KeyEvent event) {
5152 if (ActivityManagerNative.isSystemReady()) {
RoboErik430fc482014-06-12 15:49:20 -07005153 MediaSessionLegacyHelper.getHelper(mContext).sendMediaButtonEvent(event, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005154 }
5155 }
5156
Michael Wright869a67c2014-08-26 19:33:06 -07005157 void launchVoiceAssistWithWakeLock(boolean keyguardActive) {
5158 Intent voiceIntent =
5159 new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
5160 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, keyguardActive);
Bart Sears8b1c27c2015-03-18 23:51:02 +00005161 startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
Michael Wright869a67c2014-08-26 19:33:06 -07005162 mBroadcastWakeLock.release();
5163 }
5164
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005165 BroadcastReceiver mDockReceiver = new BroadcastReceiver() {
Craig Mautnereee29c42013-01-17 14:44:34 -08005166 @Override
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005167 public void onReceive(Context context, Intent intent) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07005168 if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) {
5169 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
5170 Intent.EXTRA_DOCK_STATE_UNDOCKED);
Daniel Sandler6396c722013-04-16 20:19:09 -04005171 } else {
5172 try {
5173 IUiModeManager uiModeService = IUiModeManager.Stub.asInterface(
5174 ServiceManager.getService(Context.UI_MODE_SERVICE));
5175 mUiMode = uiModeService.getCurrentModeType();
5176 } catch (RemoteException e) {
5177 }
Dianne Hackborn80fa1662009-10-07 14:02:10 -07005178 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005179 updateRotation(true);
Craig Mautnereee29c42013-01-17 14:44:34 -08005180 synchronized (mLock) {
5181 updateOrientationListenerLp();
5182 }
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005183 }
5184 };
5185
Jeff Brown6aaf2952012-10-05 16:01:08 -07005186 BroadcastReceiver mDreamReceiver = new BroadcastReceiver() {
5187 @Override
5188 public void onReceive(Context context, Intent intent) {
5189 if (Intent.ACTION_DREAMING_STARTED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005190 if (mKeyguardDelegate != null) {
5191 mKeyguardDelegate.onDreamingStarted();
Jeff Brown6aaf2952012-10-05 16:01:08 -07005192 }
5193 } else if (Intent.ACTION_DREAMING_STOPPED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005194 if (mKeyguardDelegate != null) {
5195 mKeyguardDelegate.onDreamingStopped();
Jeff Brown6aaf2952012-10-05 16:01:08 -07005196 }
5197 }
5198 }
5199 };
5200
Christopher Tate5e08af02012-09-21 17:17:22 -07005201 BroadcastReceiver mMultiuserReceiver = new BroadcastReceiver() {
5202 @Override
5203 public void onReceive(Context context, Intent intent) {
5204 if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) {
5205 // tickle the settings observer: this first ensures that we're
5206 // observing the relevant settings for the newly-active user,
5207 // and then updates our own bookkeeping based on the now-
5208 // current user.
5209 mSettingsObserver.onChange(false);
John Spurlockce479d82012-11-29 09:52:21 -05005210
5211 // force a re-application of focused window sysui visibility.
5212 // the window may never have been shown for this user
5213 // e.g. the keyguard when going through the new-user setup flow
John Spurlock04db1762013-05-13 12:46:41 -04005214 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
John Spurlockce479d82012-11-29 09:52:21 -05005215 mLastSystemUiFlags = 0;
5216 updateSystemUiVisibilityLw();
5217 }
Christopher Tate5e08af02012-09-21 17:17:22 -07005218 }
5219 }
5220 };
5221
Adrian Roosddc8b272015-05-21 16:28:27 -07005222 private final Runnable mHiddenNavPanic = new Runnable() {
John Spurlockd9b70bd2014-02-06 17:02:44 -05005223 @Override
5224 public void run() {
Adrian Roosddc8b272015-05-21 16:28:27 -07005225 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
5226 if (!isUserSetupComplete()) {
5227 // Swipe-up for navigation bar is disabled during setup
5228 return;
5229 }
5230 mPendingPanicGestureUptime = SystemClock.uptimeMillis();
5231 mNavigationBarController.showTransient();
5232 }
John Spurlockd9b70bd2014-02-06 17:02:44 -05005233 }
5234 };
5235
John Spurlocke1f366f2013-08-05 12:22:40 -04005236 private void requestTransientBars(WindowState swipeTarget) {
John Spurlock04db1762013-05-13 12:46:41 -04005237 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Maurice Lam99c6e072014-04-28 18:24:28 -07005238 if (!isUserSetupComplete()) {
5239 // Swipe-up for navigation bar is disabled during setup
5240 return;
5241 }
John Spurlock27735a42013-08-14 17:57:38 -04005242 boolean sb = mStatusBarController.checkShowTransientBarLw();
5243 boolean nb = mNavigationBarController.checkShowTransientBarLw();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005244 if (sb || nb) {
Adrian Roos62b65e42015-02-25 18:05:34 +01005245 // Don't show status bar when swiping on already visible navigation bar
5246 if (!nb && swipeTarget == mNavigationBar) {
John Spurlocke1f366f2013-08-05 12:22:40 -04005247 if (DEBUG) Slog.d(TAG, "Not showing transient bar, wrong swipe target");
John Spurlockad3e6cb2013-04-30 08:47:43 -04005248 return;
5249 }
John Spurlock27735a42013-08-14 17:57:38 -04005250 if (sb) mStatusBarController.showTransient();
5251 if (nb) mNavigationBarController.showTransient();
John Spurlockf1a36642013-10-12 17:50:42 -04005252 mImmersiveModeConfirmation.confirmCurrentPrompt();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005253 updateSystemUiVisibilityLw();
John Spurlock32beb2c2013-03-11 10:16:47 -04005254 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04005255 }
5256 }
5257
Jeff Brown3ee549c2014-09-22 20:14:39 -07005258 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07005259 @Override
Jeff Brown140ffc72014-05-01 15:18:00 -07005260 public void goingToSleep(int why) {
Dianne Hackborn74489012009-03-24 20:50:09 -07005261 EventLog.writeEvent(70000, 0);
Jeff Brown36c4db82014-09-19 12:05:31 -07005262 if (DEBUG_WAKEUP) Slog.i(TAG, "Going to sleep...");
Jeff Brown3ee549c2014-09-22 20:14:39 -07005263
5264 // We must get this work done here because the power manager will drop
5265 // the wake lock and let the system suspend once this function returns.
The Android Open Source Project0727d222009-03-11 12:11:58 -07005266 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005267 mAwake = false;
5268 mKeyguardDrawComplete = false;
Jeff Browna20dda42014-05-27 20:57:24 -07005269 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005270 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05005271 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005272 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005273
5274 if (mKeyguardDelegate != null) {
5275 mKeyguardDelegate.onScreenTurnedOff(why);
5276 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005277 }
5278
Jeff Brown13f00f02014-10-31 14:45:50 -07005279 private void wakeUpFromPowerKey(long eventTime) {
5280 wakeUp(eventTime, mAllowTheaterModeWakeFromPowerKey);
5281 }
5282
Bryce Lee5c138322014-11-03 08:26:09 -08005283 private boolean wakeUp(long wakeTime, boolean wakeInTheaterMode) {
Bryce Lee584a4452014-10-21 15:55:55 -07005284 if (!wakeInTheaterMode && isTheaterModeEnabled()) {
Bryce Lee5c138322014-11-03 08:26:09 -08005285 return false;
Bryce Lee584a4452014-10-21 15:55:55 -07005286 }
5287
5288 mPowerManager.wakeUp(wakeTime);
Bryce Lee5c138322014-11-03 08:26:09 -08005289 return true;
Bryce Lee584a4452014-10-21 15:55:55 -07005290 }
5291
Jeff Brown3ee549c2014-09-22 20:14:39 -07005292 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07005293 @Override
Jeff Brown36c4db82014-09-19 12:05:31 -07005294 public void wakingUp() {
Dianne Hackborn74489012009-03-24 20:50:09 -07005295 EventLog.writeEvent(70000, 1);
Jeff Brown36c4db82014-09-19 12:05:31 -07005296 if (DEBUG_WAKEUP) Slog.i(TAG, "Waking up...");
Craig Mautner8a0da012014-05-31 15:13:37 -07005297
Jeff Brown3ee549c2014-09-22 20:14:39 -07005298 // Since goToSleep performs these functions synchronously, we must
5299 // do the same here. We cannot post this work to a handler because
5300 // that might cause it to become reordered with respect to what
5301 // may happen in a future call to goToSleep.
The Android Open Source Project0727d222009-03-11 12:11:58 -07005302 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005303 mAwake = true;
5304 mKeyguardDrawComplete = false;
5305 if (mKeyguardDelegate != null) {
5306 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
5307 mHandler.sendEmptyMessageDelayed(MSG_KEYGUARD_DRAWN_TIMEOUT, 1000);
5308 }
5309
Jeff Browna20dda42014-05-27 20:57:24 -07005310 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005311 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05005312 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005313 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005314
Jim Miller5ecd8112013-01-09 18:50:26 -08005315 if (mKeyguardDelegate != null) {
Craig Mautner8a0da012014-05-31 15:13:37 -07005316 mKeyguardDelegate.onScreenTurnedOn(mKeyguardDelegateCallback);
Jeff Brown36c4db82014-09-19 12:05:31 -07005317 // ... eventually calls finishKeyguardDrawn
Jeff Brownc38c9be2012-10-04 13:16:19 -07005318 } else {
Craig Mautner8a0da012014-05-31 15:13:37 -07005319 if (DEBUG_WAKEUP) Slog.d(TAG, "null mKeyguardDelegate: setting mKeyguardDrawComplete.");
Jeff Brown36c4db82014-09-19 12:05:31 -07005320 finishKeyguardDrawn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07005321 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005322 }
5323
Jeff Brown36c4db82014-09-19 12:05:31 -07005324 private void finishKeyguardDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005325 synchronized (mLock) {
5326 if (!mAwake || mKeyguardDrawComplete) {
5327 return; // spurious
5328 }
5329
Jeff Brown36c4db82014-09-19 12:05:31 -07005330 mKeyguardDrawComplete = true;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005331 if (mKeyguardDelegate != null) {
5332 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
5333 }
5334 }
5335
5336 finishScreenTurningOn();
5337 }
5338
5339 // Called on the DisplayManager's DisplayPowerController thread.
5340 @Override
5341 public void screenTurnedOff() {
5342 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turned off...");
5343
5344 synchronized (mLock) {
5345 mScreenOnEarly = false;
5346 mScreenOnFully = false;
5347 mWindowManagerDrawComplete = false;
5348 mScreenOnListener = null;
5349 updateOrientationListenerLp();
Jeff Brown36c4db82014-09-19 12:05:31 -07005350 }
5351 }
5352
Jeff Brown3ee549c2014-09-22 20:14:39 -07005353 // Called on the DisplayManager's DisplayPowerController thread.
Jeff Brown36c4db82014-09-19 12:05:31 -07005354 @Override
5355 public void screenTurningOn(final ScreenOnListener screenOnListener) {
Jeff Brown36c4db82014-09-19 12:05:31 -07005356 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turning on...");
Jeff Brown36c4db82014-09-19 12:05:31 -07005357
Jeff Brown3ee549c2014-09-22 20:14:39 -07005358 synchronized (mLock) {
5359 mScreenOnEarly = true;
5360 mScreenOnFully = false;
5361 mWindowManagerDrawComplete = false;
5362 mScreenOnListener = screenOnListener;
5363 updateOrientationListenerLp();
5364 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005365
Craig Mautnerc3daedd2014-09-13 11:17:23 -07005366 mWindowManagerInternal.waitForAllWindowsDrawn(mWindowManagerDrawCallback,
5367 WAITING_FOR_DRAWN_TIMEOUT);
Jeff Brown36c4db82014-09-19 12:05:31 -07005368 // ... eventually calls finishWindowsDrawn
5369 }
5370
Jeff Brown36c4db82014-09-19 12:05:31 -07005371 private void finishWindowsDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005372 synchronized (mLock) {
5373 if (!mScreenOnEarly || mWindowManagerDrawComplete) {
5374 return; // spurious
5375 }
5376
Jeff Brown36c4db82014-09-19 12:05:31 -07005377 mWindowManagerDrawComplete = true;
Jeff Brown36c4db82014-09-19 12:05:31 -07005378 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005379
5380 finishScreenTurningOn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07005381 }
5382
Craig Mautner8a0da012014-05-31 15:13:37 -07005383 private void finishScreenTurningOn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005384 final ScreenOnListener listener;
5385 final boolean enableScreen;
Jeff Brown36c4db82014-09-19 12:05:31 -07005386 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005387 if (DEBUG_WAKEUP) Slog.d(TAG,
5388 "finishScreenTurningOn: mAwake=" + mAwake
5389 + ", mScreenOnEarly=" + mScreenOnEarly
5390 + ", mScreenOnFully=" + mScreenOnFully
5391 + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete
5392 + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete);
5393
5394 if (mScreenOnFully || !mScreenOnEarly || !mWindowManagerDrawComplete
5395 || (mAwake && !mKeyguardDrawComplete)) {
5396 return; // spurious or not ready yet
Jeff Brown36c4db82014-09-19 12:05:31 -07005397 }
5398
Jeff Brown3ee549c2014-09-22 20:14:39 -07005399 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished screen turning on...");
5400 listener = mScreenOnListener;
Craig Mautner13f6ea72014-06-23 14:57:02 -07005401 mScreenOnListener = null;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005402 mScreenOnFully = true;
5403
5404 // Remember the first time we draw the keyguard so we know when we're done with
5405 // the main part of booting and can enable the screen and hide boot messages.
5406 if (!mKeyguardDrawnOnce && mAwake) {
5407 mKeyguardDrawnOnce = true;
5408 enableScreen = true;
5409 if (mBootMessageNeedsHiding) {
5410 mBootMessageNeedsHiding = false;
5411 hideBootMessages();
5412 }
5413 } else {
5414 enableScreen = false;
5415 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005416 }
5417
Jeff Brown3ee549c2014-09-22 20:14:39 -07005418 if (listener != null) {
5419 listener.onScreenOn();
5420 }
Jeff Brown4fc45272012-10-10 18:28:14 -07005421
Jeff Brown3ee549c2014-09-22 20:14:39 -07005422 if (enableScreen) {
5423 try {
5424 mWindowManager.enableScreenIfNeeded();
5425 } catch (RemoteException unhandled) {
Jeff Brown36c4db82014-09-19 12:05:31 -07005426 }
Craig Mautnera631d492014-08-05 15:16:01 -07005427 }
5428 }
5429
5430 private void handleHideBootMessage() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005431 synchronized (mLock) {
5432 if (!mKeyguardDrawnOnce) {
5433 mBootMessageNeedsHiding = true;
5434 return; // keyguard hasn't drawn the first time yet, not done booting
5435 }
Craig Mautnera631d492014-08-05 15:16:01 -07005436 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005437
5438 if (mBootMsgDialog != null) {
5439 if (DEBUG_WAKEUP) Slog.d(TAG, "handleHideBootMessage: dismissing");
5440 mBootMsgDialog.dismiss();
5441 mBootMsgDialog = null;
Craig Mautnera631d492014-08-05 15:16:01 -07005442 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005443 }
5444
5445 @Override
Jeff Brown3ee549c2014-09-22 20:14:39 -07005446 public boolean isScreenOn() {
5447 return mScreenOnFully;
Dianne Hackborn08743722009-12-21 12:16:51 -08005448 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005449
Dianne Hackborn08743722009-12-21 12:16:51 -08005450 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005451 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005452 public void enableKeyguard(boolean enabled) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005453 if (mKeyguardDelegate != null) {
5454 mKeyguardDelegate.setKeyguardEnabled(enabled);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005455 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005456 }
5457
5458 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005459 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005460 public void exitKeyguardSecurely(OnKeyguardExitResult callback) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005461 if (mKeyguardDelegate != null) {
5462 mKeyguardDelegate.verifyUnlock(callback);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005463 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005464 }
5465
Jim Millerab954542014-10-10 18:21:49 -07005466 private boolean isKeyguardShowingAndNotOccluded() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005467 if (mKeyguardDelegate == null) return false;
Jim Millerab954542014-10-10 18:21:49 -07005468 return mKeyguardDelegate.isShowing() && !mKeyguardOccluded;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005469 }
5470
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005471 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005472 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005473 public boolean isKeyguardLocked() {
5474 return keyguardOn();
5475 }
5476
5477 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005478 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005479 public boolean isKeyguardSecure() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005480 if (mKeyguardDelegate == null) return false;
5481 return mKeyguardDelegate.isSecure();
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005482 }
5483
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005484 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005485 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005486 public boolean inKeyguardRestrictedKeyInputMode() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005487 if (mKeyguardDelegate == null) return false;
5488 return mKeyguardDelegate.isInputRestricted();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005489 }
5490
Jose Lima9546b202014-07-02 17:21:51 -07005491 @Override
Dianne Hackborn90c52de2011-09-23 12:57:44 -07005492 public void dismissKeyguardLw() {
RoboErik8a2cfc32014-05-16 11:19:38 -07005493 if (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()) {
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07005494 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.dismissKeyguardLw");
Daniel Sandler1ce804392012-11-07 15:07:12 -05005495 mHandler.post(new Runnable() {
Jose Lima9546b202014-07-02 17:21:51 -07005496 @Override
Daniel Sandler1ce804392012-11-07 15:07:12 -05005497 public void run() {
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02005498 // ask the keyguard to prompt the user to authenticate if necessary
5499 mKeyguardDelegate.dismiss();
5500 }
5501 });
5502 }
5503 }
5504
5505 public void notifyActivityDrawnForKeyguardLw() {
5506 if (mKeyguardDelegate != null) {
5507 mHandler.post(new Runnable() {
5508 @Override
5509 public void run() {
5510 mKeyguardDelegate.onActivityDrawn();
Daniel Sandler1ce804392012-11-07 15:07:12 -05005511 }
5512 });
Dianne Hackborn90c52de2011-09-23 12:57:44 -07005513 }
5514 }
5515
Jorim Jaggicff0acb2014-03-31 16:35:15 +02005516 @Override
5517 public boolean isKeyguardDrawnLw() {
5518 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005519 return mKeyguardDrawnOnce;
Jorim Jaggicff0acb2014-03-31 16:35:15 +02005520 }
5521 }
5522
Jorim Jaggi0d674622014-05-21 01:34:15 +02005523 @Override
Jorim Jaggie29b2db2014-05-30 23:17:03 +02005524 public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) {
Jorim Jaggi0d674622014-05-21 01:34:15 +02005525 if (mKeyguardDelegate != null) {
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07005526 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.startKeyguardExitAnimation");
Jorim Jaggie29b2db2014-05-30 23:17:03 +02005527 mKeyguardDelegate.startKeyguardExitAnimation(startTime, fadeoutDuration);
Jorim Jaggi0d674622014-05-21 01:34:15 +02005528 }
5529 }
5530
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005531 void sendCloseSystemWindows() {
Jorim Jaggib10e33f2015-02-04 21:57:40 +01005532 PhoneWindow.sendCloseSystemWindows(mContext, null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005533 }
5534
5535 void sendCloseSystemWindows(String reason) {
Jorim Jaggib10e33f2015-02-04 21:57:40 +01005536 PhoneWindow.sendCloseSystemWindows(mContext, reason);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005537 }
Mitsuru Oshima831d0d92009-06-16 18:27:18 -07005538
Jeff Brown01a98dd2011-09-20 15:08:29 -07005539 @Override
5540 public int rotationForOrientationLw(int orientation, int lastRotation) {
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005541 if (false) {
5542 Slog.v(TAG, "rotationForOrientationLw(orient="
5543 + orientation + ", last=" + lastRotation
5544 + "); user=" + mUserRotation + " "
5545 + ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED)
5546 ? "USER_ROTATION_LOCKED" : "")
5547 );
5548 }
5549
Craig Mautner46ac6fa2013-08-01 10:06:34 -07005550 if (mForceDefaultOrientation) {
5551 return Surface.ROTATION_0;
5552 }
5553
The Android Open Source Project0727d222009-03-11 12:11:58 -07005554 synchronized (mLock) {
Jeff Brownc0347aa2011-09-23 17:26:09 -07005555 int sensorRotation = mOrientationListener.getProposedRotation(); // may be -1
5556 if (sensorRotation < 0) {
Jeff Brown0f862b42012-09-27 21:11:01 -07005557 sensorRotation = lastRotation;
Jeff Brownc0347aa2011-09-23 17:26:09 -07005558 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005559
Jeff Browndec6cf42011-11-15 14:08:20 -08005560 final int preferredRotation;
Jeff Brown2e7760e2012-04-11 15:14:55 -07005561 if (mLidState == LID_OPEN && mLidOpenRotation >= 0) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005562 // Ignore sensor when lid switch is open and rotation is forced.
5563 preferredRotation = mLidOpenRotation;
5564 } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR
Jeff Brownc0347aa2011-09-23 17:26:09 -07005565 && (mCarDockEnablesAccelerometer || mCarDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005566 // Ignore sensor when in car dock unless explicitly enabled.
5567 // This case can override the behavior of NOSENSOR, and can also
5568 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07005569 preferredRotation = mCarDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07005570 ? sensorRotation : mCarDockRotation;
Jeff Brown1a693182011-11-08 14:44:16 -08005571 } else if ((mDockMode == Intent.EXTRA_DOCK_STATE_DESK
5572 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
5573 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK)
Jeff Brownc0347aa2011-09-23 17:26:09 -07005574 && (mDeskDockEnablesAccelerometer || mDeskDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005575 // Ignore sensor when in desk dock unless explicitly enabled.
5576 // This case can override the behavior of NOSENSOR, and can also
5577 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07005578 preferredRotation = mDeskDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07005579 ? sensorRotation : mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -07005580 } else if (mHdmiPlugged && mDemoHdmiRotationLock) {
5581 // Ignore sensor when plugged into HDMI when demo HDMI rotation lock enabled.
Jeff Browneb3e4b92011-12-06 19:54:24 -08005582 // Note that the dock orientation overrides the HDMI orientation.
Jeff Brownc82c89ed2013-04-17 17:18:15 -07005583 preferredRotation = mDemoHdmiRotation;
5584 } else if (mHdmiPlugged && mDockMode == Intent.EXTRA_DOCK_STATE_UNDOCKED
5585 && mUndockedHdmiRotation >= 0) {
5586 // Ignore sensor when plugged into HDMI and an undocked orientation has
5587 // been specified in the configuration (only for legacy devices without
5588 // full multi-display support).
5589 // Note that the dock orientation overrides the HDMI orientation.
5590 preferredRotation = mUndockedHdmiRotation;
Chong Zhangae6119ff2014-11-11 18:54:39 -08005591 } else if (mDemoRotationLock) {
5592 // Ignore sensor when demo rotation lock is enabled.
5593 // Note that the dock orientation and HDMI rotation lock override this.
5594 preferredRotation = mDemoRotation;
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005595 } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED) {
5596 // Application just wants to remain locked in the last rotation.
5597 preferredRotation = lastRotation;
Jeff Brownbcdfc622014-03-06 19:13:04 -08005598 } else if (!mSupportAutoRotation) {
5599 // If we don't support auto-rotation then bail out here and ignore
5600 // the sensor and any rotation lock settings.
5601 preferredRotation = -1;
Jeff Brown207673cd2012-06-05 17:47:11 -07005602 } else if ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE
Jeff Brown01a98dd2011-09-20 15:08:29 -07005603 && (orientation == ActivityInfo.SCREEN_ORIENTATION_USER
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005604 || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
5605 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
5606 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
5607 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER))
Jeff Brown01a98dd2011-09-20 15:08:29 -07005608 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
5609 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
5610 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
5611 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) {
5612 // Otherwise, use sensor only if requested by the application or enabled
5613 // by default for USER or UNSPECIFIED modes. Does not apply to NOSENSOR.
Jeff Brownd3187e32011-09-21 19:26:44 -07005614 if (mAllowAllRotations < 0) {
5615 // Can't read this during init() because the context doesn't
5616 // have display metrics at that time so we cannot determine
5617 // tablet vs. phone then.
5618 mAllowAllRotations = mContext.getResources().getBoolean(
5619 com.android.internal.R.bool.config_allowAllRotations) ? 1 : 0;
5620 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005621 if (sensorRotation != Surface.ROTATION_180
Jeff Brownd3187e32011-09-21 19:26:44 -07005622 || mAllowAllRotations == 1
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005623 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
5624 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005625 preferredRotation = sensorRotation;
5626 } else {
5627 preferredRotation = lastRotation;
5628 }
Jeff Brown207673cd2012-06-05 17:47:11 -07005629 } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED
5630 && orientation != ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) {
5631 // Apply rotation lock. Does not apply to NOSENSOR.
5632 // The idea is that the user rotation expresses a weak preference for the direction
5633 // of gravity and as NOSENSOR is never affected by gravity, then neither should
5634 // NOSENSOR be affected by rotation lock (although it will be affected by docks).
Jeff Brown4dfce202011-10-05 12:00:10 -07005635 preferredRotation = mUserRotation;
Jeff Browndec6cf42011-11-15 14:08:20 -08005636 } else {
5637 // No overriding preference.
5638 // We will do exactly what the application asked us to do.
5639 preferredRotation = -1;
Jeff Brown01a98dd2011-09-20 15:08:29 -07005640 }
5641
Dianne Hackborne5439f22010-10-02 16:53:50 -07005642 switch (orientation) {
5643 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08005644 // Return portrait unless overridden.
5645 if (isAnyPortrait(preferredRotation)) {
5646 return preferredRotation;
5647 }
Dianne Hackborne5439f22010-10-02 16:53:50 -07005648 return mPortraitRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005649
Jeff Brown01a98dd2011-09-20 15:08:29 -07005650 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08005651 // Return landscape unless overridden.
5652 if (isLandscapeOrSeascape(preferredRotation)) {
5653 return preferredRotation;
5654 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005655 return mLandscapeRotation;
5656
5657 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08005658 // Return reverse portrait unless overridden.
5659 if (isAnyPortrait(preferredRotation)) {
5660 return preferredRotation;
5661 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005662 return mUpsideDownRotation;
5663
5664 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08005665 // Return seascape unless overridden.
5666 if (isLandscapeOrSeascape(preferredRotation)) {
5667 return preferredRotation;
5668 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005669 return mSeascapeRotation;
5670
5671 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005672 case ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE:
Jeff Brown01a98dd2011-09-20 15:08:29 -07005673 // Return either landscape rotation.
5674 if (isLandscapeOrSeascape(preferredRotation)) {
5675 return preferredRotation;
5676 }
5677 if (isLandscapeOrSeascape(lastRotation)) {
Jeff Brown4519f072011-01-23 13:16:01 -08005678 return lastRotation;
5679 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005680 return mLandscapeRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005681
Jeff Brown01a98dd2011-09-20 15:08:29 -07005682 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005683 case ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT:
Jeff Brown01a98dd2011-09-20 15:08:29 -07005684 // Return either portrait rotation.
5685 if (isAnyPortrait(preferredRotation)) {
5686 return preferredRotation;
5687 }
5688 if (isAnyPortrait(lastRotation)) {
5689 return lastRotation;
5690 }
5691 return mPortraitRotation;
5692
5693 default:
Jeff Brown4dfce202011-10-05 12:00:10 -07005694 // For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR,
5695 // just return the preferred orientation we already calculated.
Jeff Brown01a98dd2011-09-20 15:08:29 -07005696 if (preferredRotation >= 0) {
5697 return preferredRotation;
5698 }
Dianne Hackborndacea8c2011-04-21 17:26:39 -07005699 return Surface.ROTATION_0;
Daniel Sandlere7e5ac22011-02-22 16:10:21 -05005700 }
5701 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07005702 }
5703
Jeff Brown01a98dd2011-09-20 15:08:29 -07005704 @Override
5705 public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation) {
5706 switch (orientation) {
5707 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
5708 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
5709 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
5710 return isAnyPortrait(rotation);
5711
5712 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
5713 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
5714 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
5715 return isLandscapeOrSeascape(rotation);
5716
5717 default:
5718 return true;
5719 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07005720 }
5721
Jeff Brownc0347aa2011-09-23 17:26:09 -07005722 @Override
5723 public void setRotationLw(int rotation) {
5724 mOrientationListener.setCurrentRotation(rotation);
5725 }
5726
Jeff Brown01a98dd2011-09-20 15:08:29 -07005727 private boolean isLandscapeOrSeascape(int rotation) {
5728 return rotation == mLandscapeRotation || rotation == mSeascapeRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005729 }
5730
Jeff Brown01a98dd2011-09-20 15:08:29 -07005731 private boolean isAnyPortrait(int rotation) {
5732 return rotation == mPortraitRotation || rotation == mUpsideDownRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005733 }
5734
Jose Lima9546b202014-07-02 17:21:51 -07005735 @Override
Svetoslav Ganov80943d82013-01-02 10:25:37 -08005736 public int getUserRotationMode() {
5737 return Settings.System.getIntForUser(mContext.getContentResolver(),
Brett Chabot7e55c402013-05-16 19:38:08 -07005738 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
5739 WindowManagerPolicy.USER_ROTATION_FREE :
5740 WindowManagerPolicy.USER_ROTATION_LOCKED;
Svetoslav Ganov80943d82013-01-02 10:25:37 -08005741 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005742
5743 // User rotation: to be used when all else fails in assigning an orientation to the device
Jose Lima9546b202014-07-02 17:21:51 -07005744 @Override
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005745 public void setUserRotationMode(int mode, int rot) {
5746 ContentResolver res = mContext.getContentResolver();
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005747
5748 // mUserRotationMode and mUserRotation will be assigned by the content observer
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005749 if (mode == WindowManagerPolicy.USER_ROTATION_LOCKED) {
Christopher Tate5e08af02012-09-21 17:17:22 -07005750 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005751 Settings.System.USER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005752 rot,
5753 UserHandle.USER_CURRENT);
5754 Settings.System.putIntForUser(res,
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005755 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005756 0,
5757 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005758 } else {
Christopher Tate5e08af02012-09-21 17:17:22 -07005759 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005760 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005761 1,
5762 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005763 }
5764 }
5765
Jose Lima9546b202014-07-02 17:21:51 -07005766 @Override
Jeff Brownac143512012-04-05 18:57:33 -07005767 public void setSafeMode(boolean safeMode) {
5768 mSafeMode = safeMode;
5769 performHapticFeedbackLw(null, safeMode
5770 ? HapticFeedbackConstants.SAFE_MODE_ENABLED
5771 : HapticFeedbackConstants.SAFE_MODE_DISABLED, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005772 }
Craig Mautnereda67292013-04-28 13:50:14 -07005773
Dianne Hackborn181ceb52009-08-27 22:16:40 -07005774 static long[] getLongIntArray(Resources r, int resid) {
5775 int[] ar = r.getIntArray(resid);
5776 if (ar == null) {
5777 return null;
5778 }
5779 long[] out = new long[ar.length];
5780 for (int i=0; i<ar.length; i++) {
5781 out[i] = ar[i];
5782 }
5783 return out;
5784 }
Craig Mautnereda67292013-04-28 13:50:14 -07005785
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005786 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07005787 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005788 public void systemReady() {
Jim Millerab954542014-10-10 18:21:49 -07005789 mKeyguardDelegate = new KeyguardServiceDelegate(mContext);
Mike Lockwooded8902d2013-11-15 11:01:47 -08005790 mKeyguardDelegate.onSystemReady();
5791
Michael Wright3818c922014-09-02 13:59:07 -07005792 readCameraLensCoverState();
Jeff Brown4f5fa282014-06-12 19:19:15 -07005793 updateUiMode();
Dianne Hackbornb1a79802009-09-29 15:18:31 -07005794 synchronized (mLock) {
5795 updateOrientationListenerLp();
Dianne Hackbornc777e072010-02-12 13:07:59 -08005796 mSystemReady = true;
5797 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07005798 @Override
Dianne Hackbornc777e072010-02-12 13:07:59 -08005799 public void run() {
5800 updateSettings();
5801 }
5802 });
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005803 }
5804 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07005805
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005806 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005807 @Override
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005808 public void systemBooted() {
Jim Millere5f910a2013-10-16 18:15:46 -07005809 if (mKeyguardDelegate != null) {
Jason Monk5eeebf52014-09-26 12:36:51 -04005810 mKeyguardDelegate.bindService(mContext);
Jim Millere5f910a2013-10-16 18:15:46 -07005811 mKeyguardDelegate.onBootCompleted();
5812 }
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005813 synchronized (mLock) {
5814 mSystemBooted = true;
5815 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005816 wakingUp();
5817 screenTurningOn(null);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005818 }
5819
Dianne Hackborn661cd522011-08-22 00:26:20 -07005820 ProgressDialog mBootMsgDialog = null;
5821
5822 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005823 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07005824 public void showBootMessage(final CharSequence msg, final boolean always) {
5825 mHandler.post(new Runnable() {
5826 @Override public void run() {
5827 if (mBootMsgDialog == null) {
Craig Stout4c0cb8a2014-04-04 13:03:10 -07005828 int theme;
5829 if (mContext.getPackageManager().hasSystemFeature(
5830 PackageManager.FEATURE_WATCH)) {
5831 theme = com.android.internal.R.style.Theme_Micro_Dialog_Alert;
5832 } else if (mContext.getPackageManager().hasSystemFeature(
5833 PackageManager.FEATURE_TELEVISION)) {
5834 theme = com.android.internal.R.style.Theme_Leanback_Dialog_Alert;
5835 } else {
5836 theme = 0;
5837 }
Vinod Krishnanfa8fc412014-04-18 14:35:53 -07005838
5839 mBootMsgDialog = new ProgressDialog(mContext, theme) {
Dianne Hackborn295e3c22011-08-25 13:19:08 -07005840 // This dialog will consume all events coming in to
5841 // it, to avoid it trying to do things too early in boot.
5842 @Override public boolean dispatchKeyEvent(KeyEvent event) {
5843 return true;
5844 }
5845 @Override public boolean dispatchKeyShortcutEvent(KeyEvent event) {
5846 return true;
5847 }
5848 @Override public boolean dispatchTouchEvent(MotionEvent ev) {
5849 return true;
5850 }
5851 @Override public boolean dispatchTrackballEvent(MotionEvent ev) {
5852 return true;
5853 }
5854 @Override public boolean dispatchGenericMotionEvent(MotionEvent ev) {
5855 return true;
5856 }
5857 @Override public boolean dispatchPopulateAccessibilityEvent(
5858 AccessibilityEvent event) {
5859 return true;
5860 }
5861 };
Jeff Hao9f60c082014-10-28 18:51:07 -07005862 if (mContext.getPackageManager().isUpgrade()) {
5863 mBootMsgDialog.setTitle(R.string.android_upgrading_title);
5864 } else {
5865 mBootMsgDialog.setTitle(R.string.android_start_title);
5866 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07005867 mBootMsgDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
5868 mBootMsgDialog.setIndeterminate(true);
5869 mBootMsgDialog.getWindow().setType(
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07005870 WindowManager.LayoutParams.TYPE_BOOT_PROGRESS);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005871 mBootMsgDialog.getWindow().addFlags(
5872 WindowManager.LayoutParams.FLAG_DIM_BEHIND
5873 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
5874 mBootMsgDialog.getWindow().setDimAmount(1);
Dianne Hackbornd9efb952011-12-07 14:56:51 -08005875 WindowManager.LayoutParams lp = mBootMsgDialog.getWindow().getAttributes();
5876 lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
5877 mBootMsgDialog.getWindow().setAttributes(lp);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005878 mBootMsgDialog.setCancelable(false);
5879 mBootMsgDialog.show();
5880 }
5881 mBootMsgDialog.setMessage(msg);
5882 }
5883 });
5884 }
5885
5886 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005887 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07005888 public void hideBootMessages() {
Craig Mautnera631d492014-08-05 15:16:01 -07005889 mHandler.sendEmptyMessage(MSG_HIDE_BOOT_MESSAGE);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005890 }
5891
Mike Lockwood28569302010-01-28 11:54:40 -05005892 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005893 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05005894 public void userActivity() {
Dianne Hackborndf89e652011-10-06 22:35:11 -07005895 // ***************************************
5896 // NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
5897 // ***************************************
5898 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
5899 // WITH ITS LOCKS HELD.
5900 //
5901 // This code must be VERY careful about the locks
5902 // it acquires.
5903 // In fact, the current code acquires way too many,
5904 // and probably has lurking deadlocks.
5905
Mike Lockwood28569302010-01-28 11:54:40 -05005906 synchronized (mScreenLockTimeout) {
5907 if (mLockScreenTimerActive) {
5908 // reset the timer
5909 mHandler.removeCallbacks(mScreenLockTimeout);
5910 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
5911 }
5912 }
Daniel Sandler0601eb72011-04-13 01:01:32 -04005913 }
5914
Adam Cohenf7522022012-10-03 20:03:18 -07005915 class ScreenLockTimeout implements Runnable {
5916 Bundle options;
5917
5918 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05005919 public void run() {
5920 synchronized (this) {
5921 if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard");
Jim Miller5ecd8112013-01-09 18:50:26 -08005922 if (mKeyguardDelegate != null) {
5923 mKeyguardDelegate.doKeyguardTimeout(options);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005924 }
Mike Lockwood28569302010-01-28 11:54:40 -05005925 mLockScreenTimerActive = false;
Adam Cohenf7522022012-10-03 20:03:18 -07005926 options = null;
Mike Lockwood28569302010-01-28 11:54:40 -05005927 }
5928 }
Mike Lockwood28569302010-01-28 11:54:40 -05005929
Adam Cohenf7522022012-10-03 20:03:18 -07005930 public void setLockOptions(Bundle options) {
5931 this.options = options;
5932 }
5933 }
5934
5935 ScreenLockTimeout mScreenLockTimeout = new ScreenLockTimeout();
5936
Jose Lima9546b202014-07-02 17:21:51 -07005937 @Override
Adam Cohenf7522022012-10-03 20:03:18 -07005938 public void lockNow(Bundle options) {
Jim Miller93c518e2012-01-17 15:55:31 -08005939 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null);
5940 mHandler.removeCallbacks(mScreenLockTimeout);
Adam Cohenf7522022012-10-03 20:03:18 -07005941 if (options != null) {
5942 // In case multiple calls are made to lockNow, we don't wipe out the options
5943 // until the runnable actually executes.
5944 mScreenLockTimeout.setLockOptions(options);
5945 }
Jim Miller93c518e2012-01-17 15:55:31 -08005946 mHandler.post(mScreenLockTimeout);
5947 }
5948
Mike Lockwood28569302010-01-28 11:54:40 -05005949 private void updateLockScreenTimeout() {
5950 synchronized (mScreenLockTimeout) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005951 boolean enable = (mAllowLockscreenWhenOn && mAwake &&
Jim Miller5ecd8112013-01-09 18:50:26 -08005952 mKeyguardDelegate != null && mKeyguardDelegate.isSecure());
Mike Lockwood28569302010-01-28 11:54:40 -05005953 if (mLockScreenTimerActive != enable) {
5954 if (enable) {
5955 if (localLOGV) Log.v(TAG, "setting lockscreen timer");
5956 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
5957 } else {
5958 if (localLOGV) Log.v(TAG, "clearing lockscreen timer");
5959 mHandler.removeCallbacks(mScreenLockTimeout);
5960 }
5961 mLockScreenTimerActive = enable;
5962 }
5963 }
5964 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005965
Jeff Brown061ea992015-04-17 19:55:47 -07005966 private void updateDreamingSleepToken(boolean acquire) {
5967 if (acquire) {
5968 if (mDreamingSleepToken == null) {
5969 mDreamingSleepToken = mActivityManagerInternal.acquireSleepToken("Dream");
5970 }
5971 } else {
5972 if (mDreamingSleepToken != null) {
5973 mDreamingSleepToken.release();
5974 }
5975 }
5976 }
5977
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005978 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07005979 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005980 public void enableScreenAfterBoot() {
5981 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07005982 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07005983 updateRotation(true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005984 }
Dianne Hackbornf54c8f92009-09-19 14:03:57 -07005985
Jeff Brownc458ce92012-04-30 14:58:40 -07005986 private void applyLidSwitchState() {
Jeff Brownc458ce92012-04-30 14:58:40 -07005987 if (mLidState == LID_CLOSED && mLidControlsSleep) {
Jeff Brown6d8fd272014-05-20 21:24:38 -07005988 mPowerManager.goToSleep(SystemClock.uptimeMillis(),
Jeff Brownc12035c2014-08-13 18:52:25 -07005989 PowerManager.GO_TO_SLEEP_REASON_LID_SWITCH,
Jeff Brown6d8fd272014-05-20 21:24:38 -07005990 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
Jeff Brownc458ce92012-04-30 14:58:40 -07005991 }
Jeff Browna20dda42014-05-27 20:57:24 -07005992
5993 synchronized (mLock) {
5994 updateWakeGestureListenerLp();
5995 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005996 }
5997
Jeff Brown4f5fa282014-06-12 19:19:15 -07005998 void updateUiMode() {
5999 if (mUiModeManager == null) {
6000 mUiModeManager = IUiModeManager.Stub.asInterface(
6001 ServiceManager.getService(Context.UI_MODE_SERVICE));
6002 }
6003 try {
6004 mUiMode = mUiModeManager.getCurrentModeType();
6005 } catch (RemoteException e) {
6006 }
6007 }
6008
Jeff Brown01a98dd2011-09-20 15:08:29 -07006009 void updateRotation(boolean alwaysSendConfiguration) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006010 try {
6011 //set orientation on WindowManager
Dianne Hackbornf87d1962012-04-04 12:48:24 -07006012 mWindowManager.updateRotation(alwaysSendConfiguration, false);
6013 } catch (RemoteException e) {
6014 // Ignore
6015 }
6016 }
6017
6018 void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) {
6019 try {
6020 //set orientation on WindowManager
6021 mWindowManager.updateRotation(alwaysSendConfiguration, forceRelayout);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006022 } catch (RemoteException e) {
6023 // Ignore
6024 }
6025 }
6026
Daniel Sandler6396c722013-04-16 20:19:09 -04006027 /**
6028 * Return an Intent to launch the currently active dock app as home. Returns
6029 * null if the standard home should be launched, which is the case if any of the following is
6030 * true:
6031 * <ul>
6032 * <li>The device is not in either car mode or desk mode
6033 * <li>The device is in car mode but ENABLE_CAR_DOCK_HOME_CAPTURE is false
6034 * <li>The device is in desk mode but ENABLE_DESK_DOCK_HOME_CAPTURE is false
6035 * <li>The device is in car mode but there's no CAR_DOCK app with METADATA_DOCK_HOME
6036 * <li>The device is in desk mode but there's no DESK_DOCK app with METADATA_DOCK_HOME
6037 * </ul>
Craig Mautnereda67292013-04-28 13:50:14 -07006038 * @return A dock intent.
Daniel Sandler6396c722013-04-16 20:19:09 -04006039 */
6040 Intent createHomeDockIntent() {
6041 Intent intent = null;
6042
6043 // What home does is based on the mode, not the dock state. That
6044 // is, when in car mode you should be taken to car home regardless
6045 // of whether we are actually in a car dock.
6046 if (mUiMode == Configuration.UI_MODE_TYPE_CAR) {
6047 if (ENABLE_CAR_DOCK_HOME_CAPTURE) {
6048 intent = mCarDockIntent;
6049 }
6050 } else if (mUiMode == Configuration.UI_MODE_TYPE_DESK) {
6051 if (ENABLE_DESK_DOCK_HOME_CAPTURE) {
6052 intent = mDeskDockIntent;
6053 }
Jeff Brown4f5fa282014-06-12 19:19:15 -07006054 } else if (mUiMode == Configuration.UI_MODE_TYPE_WATCH
6055 && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
6056 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK
6057 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK)) {
6058 // Always launch dock home from home when watch is docked, if it exists.
6059 intent = mDeskDockIntent;
Daniel Sandler6396c722013-04-16 20:19:09 -04006060 }
6061
6062 if (intent == null) {
6063 return null;
6064 }
6065
6066 ActivityInfo ai = null;
6067 ResolveInfo info = mContext.getPackageManager().resolveActivityAsUser(
6068 intent,
John Spurlockf56bef12013-07-09 09:51:46 -04006069 PackageManager.MATCH_DEFAULT_ONLY | PackageManager.GET_META_DATA,
Craig Mautnerd625ab22013-09-06 13:40:31 -07006070 mCurrentUserId);
Daniel Sandler6396c722013-04-16 20:19:09 -04006071 if (info != null) {
6072 ai = info.activityInfo;
6073 }
6074 if (ai != null
6075 && ai.metaData != null
6076 && ai.metaData.getBoolean(Intent.METADATA_DOCK_HOME)) {
6077 intent = new Intent(intent);
6078 intent.setClassName(ai.packageName, ai.name);
6079 return intent;
6080 }
6081
6082 return null;
6083 }
6084
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00006085 void startDockOrHome(boolean fromHomeKey, boolean awakenFromDreams) {
6086 if (awakenFromDreams) {
6087 awakenDreams();
6088 }
Daniel Sandler6396c722013-04-16 20:19:09 -04006089
6090 Intent dock = createHomeDockIntent();
6091 if (dock != null) {
6092 try {
Bryce Lee01b0c5f2015-02-05 18:24:04 -08006093 if (fromHomeKey) {
6094 dock.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
6095 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00006096 startActivityAsUser(dock, UserHandle.CURRENT);
Daniel Sandler6396c722013-04-16 20:19:09 -04006097 return;
6098 } catch (ActivityNotFoundException e) {
6099 }
6100 }
6101
Bryce Lee01b0c5f2015-02-05 18:24:04 -08006102 Intent intent;
6103
6104 if (fromHomeKey) {
6105 intent = new Intent(mHomeIntent);
6106 intent.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
6107 } else {
6108 intent = mHomeIntent;
6109 }
6110
Bryce Lee9fc0b6f2015-03-19 21:37:45 +00006111 startActivityAsUser(intent, UserHandle.CURRENT);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006112 }
Craig Mautnereda67292013-04-28 13:50:14 -07006113
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006114 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006115 * goes to the home screen
6116 * @return whether it did anything
6117 */
6118 boolean goHome() {
Bart Sears8b1c27c2015-03-18 23:51:02 +00006119 if (!isUserSetupComplete()) {
6120 Slog.i(TAG, "Not going home because user setup is in progress.");
6121 return false;
6122 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006123 if (false) {
6124 // This code always brings home to the front.
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07006125 try {
6126 ActivityManagerNative.getDefault().stopAppSwitches();
6127 } catch (RemoteException e) {
6128 }
Dianne Hackborn94a679d2009-07-28 17:51:07 -07006129 sendCloseSystemWindows();
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00006130 startDockOrHome(false /*fromHomeKey*/, true /* awakenFromDreams */);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006131 } else {
6132 // This code brings home to the front or, if it is already
6133 // at the front, puts the device to sleep.
6134 try {
Wink Savilled2e6a332010-02-12 12:12:06 -08006135 if (SystemProperties.getInt("persist.sys.uts-test-mode", 0) == 1) {
6136 /// Roll back EndcallBehavior as the cupcake design to pass P1 lab entry.
6137 Log.d(TAG, "UTS-TEST-MODE");
6138 } else {
6139 ActivityManagerNative.getDefault().stopAppSwitches();
6140 sendCloseSystemWindows();
Daniel Sandler6396c722013-04-16 20:19:09 -04006141 Intent dock = createHomeDockIntent();
6142 if (dock != null) {
6143 int result = ActivityManagerNative.getDefault()
6144 .startActivityAsUser(null, null, dock,
6145 dock.resolveTypeIfNeeded(mContext.getContentResolver()),
6146 null, null, 0,
6147 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07006148 null, null, UserHandle.USER_CURRENT);
Daniel Sandler6396c722013-04-16 20:19:09 -04006149 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
6150 return false;
6151 }
6152 }
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006153 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006154 int result = ActivityManagerNative.getDefault()
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006155 .startActivityAsUser(null, null, mHomeIntent,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006156 mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()),
Dianne Hackborna4972e92012-03-14 10:38:05 -07006157 null, null, 0,
6158 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07006159 null, null, UserHandle.USER_CURRENT);
Dianne Hackborna4972e92012-03-14 10:38:05 -07006160 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006161 return false;
6162 }
6163 } catch (RemoteException ex) {
6164 // bummer, the activity manager, which is in this process, is dead
6165 }
6166 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006167 return true;
6168 }
Craig Mautnereda67292013-04-28 13:50:14 -07006169
6170 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07006171 public void setCurrentOrientationLw(int newOrientation) {
6172 synchronized (mLock) {
6173 if (newOrientation != mCurrentAppOrientation) {
6174 mCurrentAppOrientation = newOrientation;
6175 updateOrientationListenerLp();
6176 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006177 }
6178 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006179
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07006180 private void performAuditoryFeedbackForAccessibilityIfNeed() {
6181 if (!isGlobalAccessibilityGestureEnabled()) {
6182 return;
6183 }
6184 AudioManager audioManager = (AudioManager) mContext.getSystemService(
6185 Context.AUDIO_SERVICE);
6186 if (audioManager.isSilentMode()) {
6187 return;
6188 }
6189 Ringtone ringTone = RingtoneManager.getRingtone(mContext,
6190 Settings.System.DEFAULT_NOTIFICATION_URI);
6191 ringTone.setStreamType(AudioManager.STREAM_MUSIC);
6192 ringTone.play();
6193 }
Craig Mautnereda67292013-04-28 13:50:14 -07006194
Bryce Lee584a4452014-10-21 15:55:55 -07006195 private boolean isTheaterModeEnabled() {
6196 return Settings.Global.getInt(mContext.getContentResolver(),
6197 Settings.Global.THEATER_MODE_ON, 0) == 1;
6198 }
6199
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07006200 private boolean isGlobalAccessibilityGestureEnabled() {
6201 return Settings.Global.getInt(mContext.getContentResolver(),
6202 Settings.Global.ENABLE_ACCESSIBILITY_GLOBAL_GESTURE_ENABLED, 0) == 1;
6203 }
6204
Craig Mautnereda67292013-04-28 13:50:14 -07006205 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07006206 public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) {
Svetoslav Ganov96179212012-10-10 14:17:45 -07006207 if (!mVibrator.hasVibrator()) {
6208 return false;
6209 }
Christopher Tate5e08af02012-09-21 17:17:22 -07006210 final boolean hapticsDisabled = Settings.System.getIntForUser(mContext.getContentResolver(),
6211 Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) == 0;
Jeff Brown82379ba2014-07-25 19:03:28 -07006212 if (hapticsDisabled && !always) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006213 return false;
6214 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006215 long[] pattern = null;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006216 switch (effectId) {
6217 case HapticFeedbackConstants.LONG_PRESS:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006218 pattern = mLongPressVibePattern;
6219 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006220 case HapticFeedbackConstants.VIRTUAL_KEY:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006221 pattern = mVirtualKeyVibePattern;
6222 break;
6223 case HapticFeedbackConstants.KEYBOARD_TAP:
6224 pattern = mKeyboardTapVibePattern;
6225 break;
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07006226 case HapticFeedbackConstants.CLOCK_TICK:
6227 pattern = mClockTickVibePattern;
6228 break;
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07006229 case HapticFeedbackConstants.CALENDAR_DATE:
6230 pattern = mCalendarDateVibePattern;
6231 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006232 case HapticFeedbackConstants.SAFE_MODE_DISABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006233 pattern = mSafeModeDisabledVibePattern;
6234 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006235 case HapticFeedbackConstants.SAFE_MODE_ENABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006236 pattern = mSafeModeEnabledVibePattern;
6237 break;
Mady Mellore82067b2015-04-30 09:58:35 -07006238 case HapticFeedbackConstants.STYLUS_BUTTON_PRESS:
6239 pattern = mStylusButtonPressVibePattern;
6240 break;
Amith Yamasanic33cb712010-02-10 15:21:49 -08006241 default:
6242 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006243 }
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006244 int owningUid;
6245 String owningPackage;
6246 if (win != null) {
6247 owningUid = win.getOwningUid();
6248 owningPackage = win.getOwningPackage();
6249 } else {
6250 owningUid = android.os.Process.myUid();
Dianne Hackborn95d78532013-09-11 09:51:14 -07006251 owningPackage = mContext.getOpPackageName();
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006252 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006253 if (pattern.length == 1) {
6254 // One-shot vibration
John Spurlock7b414672014-07-18 13:02:39 -04006255 mVibrator.vibrate(owningUid, owningPackage, pattern[0], VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08006256 } else {
6257 // Pattern vibration
John Spurlock7b414672014-07-18 13:02:39 -04006258 mVibrator.vibrate(owningUid, owningPackage, pattern, -1, VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08006259 }
6260 return true;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006261 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07006262
6263 @Override
6264 public void keepScreenOnStartedLw() {
Daniel Sandler0601eb72011-04-13 01:01:32 -04006265 }
6266
Jeff Brownc38c9be2012-10-04 13:16:19 -07006267 @Override
6268 public void keepScreenOnStoppedLw() {
Jim Millerab954542014-10-10 18:21:49 -07006269 if (isKeyguardShowingAndNotOccluded()) {
Jim Miller25190572013-02-28 17:36:24 -08006270 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006271 }
6272 }
Mike Lockwoodfcb39242009-10-21 23:01:07 -04006273
Dianne Hackborndf89e652011-10-06 22:35:11 -07006274 private int updateSystemUiVisibilityLw() {
Joe Onorato664644d2011-01-23 17:53:23 -08006275 // If there is no window focused, there will be nobody to handle the events
6276 // anyway, so just hang on in whatever state we're in until things settle down.
Adrian Roos53f28ec2014-10-29 17:26:12 +01006277 final WindowState win = mFocusedWindow != null ? mFocusedWindow
6278 : mTopFullscreenOpaqueWindowState;
John Spurlock79da8332013-09-20 12:04:47 -04006279 if (win == null) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006280 return 0;
6281 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01006282 if ((win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 && mHideLockScreen == true) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07006283 // We are updating at a point where the keyguard has gotten
6284 // focus, but we were last in a state where the top window is
6285 // hiding it. This is probably because the keyguard as been
6286 // shown while the top window was displayed, so we want to ignore
6287 // it here because this is just a very transient change and it
6288 // will quickly lose focus once it correctly gets hidden.
6289 return 0;
6290 }
John Spurlock32beb2c2013-03-11 10:16:47 -04006291
John Spurlock1db8b682014-02-18 11:18:59 -05006292 int tmpVisibility = PolicyControl.getSystemUiVisibility(win, null)
Dianne Hackborne26ab702011-10-16 13:21:33 -07006293 & ~mResettingSystemUiFlags
6294 & ~mForceClearedSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04006295 if (mForcingShowNavBar && win.getSurfaceLayer() < mForcingShowNavBarLayer) {
John Spurlockc6d1c602014-01-17 15:22:06 -05006296 tmpVisibility &= ~PolicyControl.adjustClearableFlags(win, View.SYSTEM_UI_CLEARABLE_FLAGS);
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08006297 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01006298 tmpVisibility = updateLightStatusBarLw(tmpVisibility);
John Spurlock79da8332013-09-20 12:04:47 -04006299 final int visibility = updateSystemBarsLw(win, mLastSystemUiFlags, tmpVisibility);
John Spurlockad3e6cb2013-04-30 08:47:43 -04006300 final int diff = visibility ^ mLastSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04006301 final boolean needsMenu = win.getNeedsMenuLw(mTopFullscreenOpaqueWindowState);
Dianne Hackborne0f085d2011-11-30 18:41:15 -08006302 if (diff == 0 && mLastFocusNeedsMenu == needsMenu
John Spurlock79da8332013-09-20 12:04:47 -04006303 && mFocusedApp == win.getAppToken()) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006304 return 0;
6305 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07006306 mLastSystemUiFlags = visibility;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08006307 mLastFocusNeedsMenu = needsMenu;
John Spurlock79da8332013-09-20 12:04:47 -04006308 mFocusedApp = win.getAppToken();
Dianne Hackborndf89e652011-10-06 22:35:11 -07006309 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07006310 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07006311 public void run() {
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006312 try {
6313 IStatusBarService statusbar = getStatusBarService();
6314 if (statusbar != null) {
Adrian Roos53f28ec2014-10-29 17:26:12 +01006315 statusbar.setSystemUiVisibility(visibility, 0xffffffff, win.toString());
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006316 statusbar.topAppWindowChanged(needsMenu);
Joe Onorato664644d2011-01-23 17:53:23 -08006317 }
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006318 } catch (RemoteException e) {
6319 // re-acquire status bar service next time it is needed.
6320 mStatusBarService = null;
Joe Onorato664644d2011-01-23 17:53:23 -08006321 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07006322 }
6323 });
6324 return diff;
Joe Onorato664644d2011-01-23 17:53:23 -08006325 }
6326
Adrian Rooscd3884d2015-02-18 17:25:23 +01006327 private int updateLightStatusBarLw(int vis) {
6328 WindowState statusColorWin = isStatusBarKeyguard() && !mHideLockScreen
6329 ? mStatusBar
6330 : mTopFullscreenOpaqueOrDimmingWindowState;
6331
6332 if (statusColorWin != null) {
6333 if (statusColorWin == mTopFullscreenOpaqueWindowState) {
6334 // If the top fullscreen-or-dimming window is also the top fullscreen, respect
6335 // its light flag.
6336 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6337 vis |= PolicyControl.getSystemUiVisibility(statusColorWin, null)
6338 & View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6339 } else if (statusColorWin != null && statusColorWin.isDimming()) {
6340 // Otherwise if it's dimming, clear the light flag.
6341 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6342 }
6343 }
6344 return vis;
6345 }
6346
John Spurlock79da8332013-09-20 12:04:47 -04006347 private int updateSystemBarsLw(WindowState win, int oldVis, int vis) {
John Spurlockbd957402013-10-03 11:38:39 -04006348 // apply translucent bar vis flags
Jorim Jaggi380ecb82014-03-14 17:25:20 +01006349 WindowState transWin = isStatusBarKeyguard() && !mHideLockScreen
6350 ? mStatusBar
John Spurlockbd957402013-10-03 11:38:39 -04006351 : mTopFullscreenOpaqueWindowState;
6352 vis = mStatusBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
6353 vis = mNavigationBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
6354
John Spurlock27735a42013-08-14 17:57:38 -04006355 // prevent status bar interaction from clearing certain flags
Selim Cinekf83e8242015-05-19 18:08:14 -07006356 int type = win.getAttrs().type;
6357 boolean statusBarHasFocus = type == TYPE_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04006358 if (statusBarHasFocus && !isStatusBarKeyguard()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04006359 int flags = View.SYSTEM_UI_FLAG_FULLSCREEN
6360 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlockcfc359a2013-09-05 10:42:03 -04006361 | View.SYSTEM_UI_FLAG_IMMERSIVE
Jorim Jaggi73fef8d2015-02-16 17:32:28 +01006362 | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
6363 | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04006364 if (mHideLockScreen) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01006365 flags |= View.STATUS_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSLUCENT;
6366 }
John Spurlockbd957402013-10-03 11:38:39 -04006367 vis = (vis & ~flags) | (oldVis & flags);
John Spurlockad3e6cb2013-04-30 08:47:43 -04006368 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04006369
Adrian Roos4fb3ee32014-08-22 19:29:09 +02006370 if (!areTranslucentBarsAllowed() && transWin != mStatusBar) {
Adrian Roosea562512014-05-05 13:33:03 +02006371 vis &= ~(View.NAVIGATION_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSLUCENT
6372 | View.SYSTEM_UI_TRANSPARENT);
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006373 }
6374
John Spurlock27735a42013-08-14 17:57:38 -04006375 // update status bar
John Spurlockf1a36642013-10-12 17:50:42 -04006376 boolean immersiveSticky =
6377 (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
John Spurlock27735a42013-08-14 17:57:38 -04006378 boolean hideStatusBarWM =
John Spurlockbd957402013-10-03 11:38:39 -04006379 mTopFullscreenOpaqueWindowState != null &&
John Spurlockc6d1c602014-01-17 15:22:06 -05006380 (PolicyControl.getWindowFlags(mTopFullscreenOpaqueWindowState, null)
John Spurlock27735a42013-08-14 17:57:38 -04006381 & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0;
6382 boolean hideStatusBarSysui =
6383 (vis & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04006384 boolean hideNavBarSysui =
6385 (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006386
John Spurlock27735a42013-08-14 17:57:38 -04006387 boolean transientStatusBarAllowed =
6388 mStatusBar != null && (
6389 hideStatusBarWM
John Spurlockf1a36642013-10-12 17:50:42 -04006390 || (hideStatusBarSysui && immersiveSticky)
John Spurlock27735a42013-08-14 17:57:38 -04006391 || statusBarHasFocus);
6392
John Spurlockf1a36642013-10-12 17:50:42 -04006393 boolean transientNavBarAllowed =
6394 mNavigationBar != null &&
6395 hideNavBarSysui && immersiveSticky;
6396
Adrian Roosddc8b272015-05-21 16:28:27 -07006397 final long now = SystemClock.uptimeMillis();
6398 final boolean pendingPanic = mPendingPanicGestureUptime != 0
6399 && now - mPendingPanicGestureUptime <= PANIC_GESTURE_EXPIRATION;
6400 if (pendingPanic && hideNavBarSysui && !isStatusBarKeyguard() && mKeyguardDrawComplete) {
6401 // The user performed the panic gesture recently, we're about to hide the bars,
6402 // we're no longer on the Keyguard and the screen is ready. We can now request the bars.
6403 mPendingPanicGestureUptime = 0;
6404 mStatusBarController.showTransient();
6405 mNavigationBarController.showTransient();
6406 }
6407
John Spurlockf25706f2013-11-07 18:02:43 -05006408 boolean denyTransientStatus = mStatusBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04006409 && !transientStatusBarAllowed && hideStatusBarSysui;
John Spurlockf25706f2013-11-07 18:02:43 -05006410 boolean denyTransientNav = mNavigationBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04006411 && !transientNavBarAllowed;
6412 if (denyTransientStatus || denyTransientNav) {
John Spurlock27735a42013-08-14 17:57:38 -04006413 // clear the clearable flags instead
John Spurlockf1a36642013-10-12 17:50:42 -04006414 clearClearableFlagsLw();
tiger_huangc58d7562014-10-23 20:24:19 +08006415 vis &= ~View.SYSTEM_UI_CLEARABLE_FLAGS;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006416 }
John Spurlock27735a42013-08-14 17:57:38 -04006417
Selim Cinekf98702e2015-05-20 22:48:40 -07006418 final boolean immersive = (vis & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
6419 immersiveSticky = (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
6420 final boolean navAllowedHidden = immersive || immersiveSticky;
6421
Selim Cinekd6623612015-05-22 18:56:22 -07006422 if (hideNavBarSysui && !navAllowedHidden && windowTypeToLayerLw(win.getBaseType())
6423 > windowTypeToLayerLw(TYPE_INPUT_CONSUMER)) {
Selim Cinekf98702e2015-05-20 22:48:40 -07006424 // We can't hide the navbar from this window otherwise the input consumer would not get
6425 // the input events.
6426 vis = (vis & ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
6427 }
6428
John Spurlock27735a42013-08-14 17:57:38 -04006429 vis = mStatusBarController.updateVisibilityLw(transientStatusBarAllowed, oldVis, vis);
6430
6431 // update navigation bar
John Spurlockf1a36642013-10-12 17:50:42 -04006432 boolean oldImmersiveMode = isImmersiveMode(oldVis);
6433 boolean newImmersiveMode = isImmersiveMode(vis);
6434 if (win != null && oldImmersiveMode != newImmersiveMode) {
John Spurlock79da8332013-09-20 12:04:47 -04006435 final String pkg = win.getOwningPackage();
Maurice Lam99c6e072014-04-28 18:24:28 -07006436 mImmersiveModeConfirmation.immersiveModeChanged(pkg, newImmersiveMode,
6437 isUserSetupComplete());
John Spurlock34e13d92013-08-10 06:52:28 -04006438 }
John Spurlock27735a42013-08-14 17:57:38 -04006439
John Spurlockf1a36642013-10-12 17:50:42 -04006440 vis = mNavigationBarController.updateVisibilityLw(transientNavBarAllowed, oldVis, vis);
6441
John Spurlocke1f366f2013-08-05 12:22:40 -04006442 return vis;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006443 }
6444
John Spurlockf1a36642013-10-12 17:50:42 -04006445 private void clearClearableFlagsLw() {
6446 int newVal = mResettingSystemUiFlags | View.SYSTEM_UI_CLEARABLE_FLAGS;
6447 if (newVal != mResettingSystemUiFlags) {
6448 mResettingSystemUiFlags = newVal;
6449 mWindowManagerFuncs.reevaluateStatusBarVisibility();
6450 }
6451 }
6452
6453 private boolean isImmersiveMode(int vis) {
6454 final int flags = View.SYSTEM_UI_FLAG_IMMERSIVE | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
John Spurlock34e13d92013-08-10 06:52:28 -04006455 return mNavigationBar != null
6456 && (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0
Daniel Sandler900ece52013-10-18 15:53:27 -04006457 && (vis & flags) != 0
6458 && canHideNavigationBar();
John Spurlock34e13d92013-08-10 06:52:28 -04006459 }
6460
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006461 /**
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04006462 * @return whether the navigation or status bar can be made translucent
6463 *
6464 * This should return true unless touch exploration is not enabled or
6465 * R.boolean.config_enableTranslucentDecor is false.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006466 */
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04006467 private boolean areTranslucentBarsAllowed() {
Svetoslav8e3feb12014-02-24 13:46:47 -08006468 return mTranslucentDecorEnabled
6469 && !mAccessibilityManager.isTouchExplorationEnabled();
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006470 }
6471
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04006472 // Use this instead of checking config_showNavigationBar so that it can be consistently
6473 // overridden by qemu.hw.mainkeys in the emulator.
Craig Mautnereda67292013-04-28 13:50:14 -07006474 @Override
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04006475 public boolean hasNavigationBar() {
6476 return mHasNavigationBar;
6477 }
6478
satok1bc0a492012-04-25 22:47:12 +09006479 @Override
6480 public void setLastInputMethodWindowLw(WindowState ime, WindowState target) {
6481 mLastInputMethodWindow = ime;
6482 mLastInputMethodTargetWindow = target;
6483 }
6484
Craig Mautnerf1b67412012-09-19 13:18:29 -07006485 @Override
Satoshi Kataoka658c7b82013-10-10 17:03:51 +09006486 public int getInputMethodWindowVisibleHeightLw() {
6487 return mDockBottom - mCurBottom;
6488 }
6489
6490 @Override
Craig Mautnerf1b67412012-09-19 13:18:29 -07006491 public void setCurrentUserLw(int newUserId) {
Craig Mautnerd625ab22013-09-06 13:40:31 -07006492 mCurrentUserId = newUserId;
Jim Miller5ecd8112013-01-09 18:50:26 -08006493 if (mKeyguardDelegate != null) {
6494 mKeyguardDelegate.setCurrentUser(newUserId);
Craig Mautnerf1b67412012-09-19 13:18:29 -07006495 }
John Spurlock13451a22012-09-28 14:40:41 -04006496 if (mStatusBarService != null) {
6497 try {
6498 mStatusBarService.setCurrentUser(newUserId);
6499 } catch (RemoteException e) {
6500 // oh well
6501 }
6502 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006503 setLastInputMethodWindowLw(null, null);
Craig Mautnerf1b67412012-09-19 13:18:29 -07006504 }
6505
6506 @Override
Svetoslav Ganov545252f2012-12-10 18:29:24 -08006507 public boolean canMagnifyWindow(int windowType) {
6508 switch (windowType) {
6509 case WindowManager.LayoutParams.TYPE_INPUT_METHOD:
6510 case WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG:
6511 case WindowManager.LayoutParams.TYPE_NAVIGATION_BAR:
6512 case WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY: {
6513 return false;
6514 }
6515 }
6516 return true;
6517 }
6518
6519 @Override
6520 public boolean isTopLevelWindow(int windowType) {
6521 if (windowType >= WindowManager.LayoutParams.FIRST_SUB_WINDOW
6522 && windowType <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
6523 return (windowType == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG);
6524 }
6525 return true;
6526 }
6527
Jim Miller4eeb4f62012-11-08 00:04:29 -08006528 @Override
Jeff Brownd7a04de2012-06-17 14:17:52 -07006529 public void dump(String prefix, PrintWriter pw, String[] args) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006530 pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07006531 pw.print(" mSystemReady="); pw.print(mSystemReady);
6532 pw.print(" mSystemBooted="); pw.println(mSystemBooted);
Jeff Brown2e7760e2012-04-11 15:14:55 -07006533 pw.print(prefix); pw.print("mLidState="); pw.print(mLidState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006534 pw.print(" mLidOpenRotation="); pw.print(mLidOpenRotation);
Michael Wright3818c922014-09-02 13:59:07 -07006535 pw.print(" mCameraLensCoverState="); pw.print(mCameraLensCoverState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006536 pw.print(" mHdmiPlugged="); pw.println(mHdmiPlugged);
Dianne Hackborne26ab702011-10-16 13:21:33 -07006537 if (mLastSystemUiFlags != 0 || mResettingSystemUiFlags != 0
6538 || mForceClearedSystemUiFlags != 0) {
6539 pw.print(prefix); pw.print("mLastSystemUiFlags=0x");
6540 pw.print(Integer.toHexString(mLastSystemUiFlags));
6541 pw.print(" mResettingSystemUiFlags=0x");
6542 pw.print(Integer.toHexString(mResettingSystemUiFlags));
6543 pw.print(" mForceClearedSystemUiFlags=0x");
6544 pw.println(Integer.toHexString(mForceClearedSystemUiFlags));
Dianne Hackborndf89e652011-10-06 22:35:11 -07006545 }
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08006546 if (mLastFocusNeedsMenu) {
6547 pw.print(prefix); pw.print("mLastFocusNeedsMenu=");
6548 pw.println(mLastFocusNeedsMenu);
6549 }
Jeff Browna20dda42014-05-27 20:57:24 -07006550 pw.print(prefix); pw.print("mWakeGestureEnabledSetting=");
6551 pw.println(mWakeGestureEnabledSetting);
6552
Jeff Brownbcdfc622014-03-06 19:13:04 -08006553 pw.print(prefix); pw.print("mSupportAutoRotation="); pw.println(mSupportAutoRotation);
Daniel Sandler6396c722013-04-16 20:19:09 -04006554 pw.print(prefix); pw.print("mUiMode="); pw.print(mUiMode);
6555 pw.print(" mDockMode="); pw.print(mDockMode);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006556 pw.print(" mCarDockRotation="); pw.print(mCarDockRotation);
6557 pw.print(" mDeskDockRotation="); pw.println(mDeskDockRotation);
6558 pw.print(prefix); pw.print("mUserRotationMode="); pw.print(mUserRotationMode);
6559 pw.print(" mUserRotation="); pw.print(mUserRotation);
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05006560 pw.print(" mAllowAllRotations="); pw.println(mAllowAllRotations);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07006561 pw.print(prefix); pw.print("mCurrentAppOrientation="); pw.println(mCurrentAppOrientation);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006562 pw.print(prefix); pw.print("mCarDockEnablesAccelerometer=");
6563 pw.print(mCarDockEnablesAccelerometer);
6564 pw.print(" mDeskDockEnablesAccelerometer=");
6565 pw.println(mDeskDockEnablesAccelerometer);
6566 pw.print(prefix); pw.print("mLidKeyboardAccessibility=");
6567 pw.print(mLidKeyboardAccessibility);
6568 pw.print(" mLidNavigationAccessibility="); pw.print(mLidNavigationAccessibility);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07006569 pw.print(" mLidControlsSleep="); pw.println(mLidControlsSleep);
Jeff Brown6d8fd272014-05-20 21:24:38 -07006570 pw.print(prefix);
6571 pw.print("mShortPressOnPowerBehavior="); pw.print(mShortPressOnPowerBehavior);
6572 pw.print(" mLongPressOnPowerBehavior="); pw.println(mLongPressOnPowerBehavior);
Jeff Brown13f00f02014-10-31 14:45:50 -07006573 pw.print(prefix);
6574 pw.print("mDoublePressOnPowerBehavior="); pw.print(mDoublePressOnPowerBehavior);
6575 pw.print(" mTriplePressOnPowerBehavior="); pw.println(mTriplePressOnPowerBehavior);
Jeff Brown6d8fd272014-05-20 21:24:38 -07006576 pw.print(prefix); pw.print("mHasSoftInput="); pw.println(mHasSoftInput);
Jeff Brown3ee549c2014-09-22 20:14:39 -07006577 pw.print(prefix); pw.print("mAwake="); pw.println(mAwake);
6578 pw.print(prefix); pw.print("mScreenOnEarly="); pw.print(mScreenOnEarly);
6579 pw.print(" mScreenOnFully="); pw.println(mScreenOnFully);
6580 pw.print(prefix); pw.print("mKeyguardDrawComplete="); pw.print(mKeyguardDrawComplete);
6581 pw.print(" mWindowManagerDrawComplete="); pw.println(mWindowManagerDrawComplete);
6582 pw.print(prefix); pw.print("mOrientationSensorEnabled=");
6583 pw.println(mOrientationSensorEnabled);
Dianne Hackbornc652de82013-02-15 16:32:56 -08006584 pw.print(prefix); pw.print("mOverscanScreen=("); pw.print(mOverscanScreenLeft);
6585 pw.print(","); pw.print(mOverscanScreenTop);
6586 pw.print(") "); pw.print(mOverscanScreenWidth);
6587 pw.print("x"); pw.println(mOverscanScreenHeight);
6588 if (mOverscanLeft != 0 || mOverscanTop != 0
6589 || mOverscanRight != 0 || mOverscanBottom != 0) {
6590 pw.print(prefix); pw.print("mOverscan left="); pw.print(mOverscanLeft);
6591 pw.print(" top="); pw.print(mOverscanTop);
6592 pw.print(" right="); pw.print(mOverscanRight);
6593 pw.print(" bottom="); pw.println(mOverscanBottom);
6594 }
Dianne Hackborn313440842013-02-19 19:22:59 -08006595 pw.print(prefix); pw.print("mRestrictedOverscanScreen=(");
6596 pw.print(mRestrictedOverscanScreenLeft);
6597 pw.print(","); pw.print(mRestrictedOverscanScreenTop);
6598 pw.print(") "); pw.print(mRestrictedOverscanScreenWidth);
6599 pw.print("x"); pw.println(mRestrictedOverscanScreenHeight);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006600 pw.print(prefix); pw.print("mUnrestrictedScreen=("); pw.print(mUnrestrictedScreenLeft);
6601 pw.print(","); pw.print(mUnrestrictedScreenTop);
6602 pw.print(") "); pw.print(mUnrestrictedScreenWidth);
6603 pw.print("x"); pw.println(mUnrestrictedScreenHeight);
6604 pw.print(prefix); pw.print("mRestrictedScreen=("); pw.print(mRestrictedScreenLeft);
6605 pw.print(","); pw.print(mRestrictedScreenTop);
6606 pw.print(") "); pw.print(mRestrictedScreenWidth);
6607 pw.print("x"); pw.println(mRestrictedScreenHeight);
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07006608 pw.print(prefix); pw.print("mStableFullscreen=("); pw.print(mStableFullscreenLeft);
6609 pw.print(","); pw.print(mStableFullscreenTop);
6610 pw.print(")-("); pw.print(mStableFullscreenRight);
6611 pw.print(","); pw.print(mStableFullscreenBottom); pw.println(")");
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07006612 pw.print(prefix); pw.print("mStable=("); pw.print(mStableLeft);
6613 pw.print(","); pw.print(mStableTop);
6614 pw.print(")-("); pw.print(mStableRight);
6615 pw.print(","); pw.print(mStableBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07006616 pw.print(prefix); pw.print("mSystem=("); pw.print(mSystemLeft);
6617 pw.print(","); pw.print(mSystemTop);
6618 pw.print(")-("); pw.print(mSystemRight);
6619 pw.print(","); pw.print(mSystemBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006620 pw.print(prefix); pw.print("mCur=("); pw.print(mCurLeft);
6621 pw.print(","); pw.print(mCurTop);
6622 pw.print(")-("); pw.print(mCurRight);
6623 pw.print(","); pw.print(mCurBottom); pw.println(")");
6624 pw.print(prefix); pw.print("mContent=("); pw.print(mContentLeft);
6625 pw.print(","); pw.print(mContentTop);
6626 pw.print(")-("); pw.print(mContentRight);
6627 pw.print(","); pw.print(mContentBottom); pw.println(")");
Dianne Hackborne30e02f2014-05-27 18:24:45 -07006628 pw.print(prefix); pw.print("mVoiceContent=("); pw.print(mVoiceContentLeft);
6629 pw.print(","); pw.print(mVoiceContentTop);
6630 pw.print(")-("); pw.print(mVoiceContentRight);
6631 pw.print(","); pw.print(mVoiceContentBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006632 pw.print(prefix); pw.print("mDock=("); pw.print(mDockLeft);
6633 pw.print(","); pw.print(mDockTop);
6634 pw.print(")-("); pw.print(mDockRight);
6635 pw.print(","); pw.print(mDockBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07006636 pw.print(prefix); pw.print("mDockLayer="); pw.print(mDockLayer);
6637 pw.print(" mStatusBarLayer="); pw.println(mStatusBarLayer);
Dianne Hackborn7ad44382012-10-18 17:46:00 -07006638 pw.print(prefix); pw.print("mShowingLockscreen="); pw.print(mShowingLockscreen);
6639 pw.print(" mShowingDream="); pw.print(mShowingDream);
Jeff Brown061ea992015-04-17 19:55:47 -07006640 pw.print(" mDreamingLockscreen="); pw.print(mDreamingLockscreen);
6641 pw.print(" mDreamingSleepToken="); pw.println(mDreamingSleepToken);
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006642 if (mLastInputMethodWindow != null) {
6643 pw.print(prefix); pw.print("mLastInputMethodWindow=");
6644 pw.println(mLastInputMethodWindow);
6645 }
6646 if (mLastInputMethodTargetWindow != null) {
6647 pw.print(prefix); pw.print("mLastInputMethodTargetWindow=");
6648 pw.println(mLastInputMethodTargetWindow);
6649 }
6650 if (mStatusBar != null) {
6651 pw.print(prefix); pw.print("mStatusBar=");
Dianne Hackbornae6688b2015-02-11 17:02:41 -08006652 pw.print(mStatusBar); pw.print(" isStatusBarKeyguard=");
6653 pw.println(isStatusBarKeyguard());
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006654 }
6655 if (mNavigationBar != null) {
6656 pw.print(prefix); pw.print("mNavigationBar=");
6657 pw.println(mNavigationBar);
6658 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006659 if (mFocusedWindow != null) {
6660 pw.print(prefix); pw.print("mFocusedWindow=");
6661 pw.println(mFocusedWindow);
6662 }
6663 if (mFocusedApp != null) {
6664 pw.print(prefix); pw.print("mFocusedApp=");
6665 pw.println(mFocusedApp);
6666 }
6667 if (mWinDismissingKeyguard != null) {
6668 pw.print(prefix); pw.print("mWinDismissingKeyguard=");
6669 pw.println(mWinDismissingKeyguard);
6670 }
6671 if (mTopFullscreenOpaqueWindowState != null) {
6672 pw.print(prefix); pw.print("mTopFullscreenOpaqueWindowState=");
6673 pw.println(mTopFullscreenOpaqueWindowState);
6674 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01006675 if (mTopFullscreenOpaqueOrDimmingWindowState != null) {
6676 pw.print(prefix); pw.print("mTopFullscreenOpaqueOrDimmingWindowState=");
6677 pw.println(mTopFullscreenOpaqueOrDimmingWindowState);
6678 }
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08006679 if (mForcingShowNavBar) {
6680 pw.print(prefix); pw.print("mForcingShowNavBar=");
6681 pw.println(mForcingShowNavBar); pw.print( "mForcingShowNavBarLayer=");
6682 pw.println(mForcingShowNavBarLayer);
6683 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07006684 pw.print(prefix); pw.print("mTopIsFullscreen="); pw.print(mTopIsFullscreen);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006685 pw.print(" mHideLockScreen="); pw.println(mHideLockScreen);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07006686 pw.print(prefix); pw.print("mForceStatusBar="); pw.print(mForceStatusBar);
6687 pw.print(" mForceStatusBarFromKeyguard=");
6688 pw.println(mForceStatusBarFromKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006689 pw.print(prefix); pw.print("mDismissKeyguard="); pw.print(mDismissKeyguard);
Craig Mautnerad09bcc2012-10-08 13:33:11 -07006690 pw.print(" mWinDismissingKeyguard="); pw.print(mWinDismissingKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006691 pw.print(" mHomePressed="); pw.println(mHomePressed);
6692 pw.print(prefix); pw.print("mAllowLockscreenWhenOn="); pw.print(mAllowLockscreenWhenOn);
6693 pw.print(" mLockScreenTimeout="); pw.print(mLockScreenTimeout);
6694 pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive);
6695 pw.print(prefix); pw.print("mEndcallBehavior="); pw.print(mEndcallBehavior);
6696 pw.print(" mIncallPowerBehavior="); pw.print(mIncallPowerBehavior);
6697 pw.print(" mLongPressOnHomeBehavior="); pw.println(mLongPressOnHomeBehavior);
6698 pw.print(prefix); pw.print("mLandscapeRotation="); pw.print(mLandscapeRotation);
6699 pw.print(" mSeascapeRotation="); pw.println(mSeascapeRotation);
6700 pw.print(prefix); pw.print("mPortraitRotation="); pw.print(mPortraitRotation);
6701 pw.print(" mUpsideDownRotation="); pw.println(mUpsideDownRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07006702 pw.print(prefix); pw.print("mDemoHdmiRotation="); pw.print(mDemoHdmiRotation);
6703 pw.print(" mDemoHdmiRotationLock="); pw.println(mDemoHdmiRotationLock);
6704 pw.print(prefix); pw.print("mUndockedHdmiRotation="); pw.println(mUndockedHdmiRotation);
Jeff Brown600f0032014-05-22 17:06:00 -07006705
Tim Kilbournd7c0c2e2014-05-29 16:08:10 -07006706 mGlobalKeyManager.dump(prefix, pw);
John Spurlock27735a42013-08-14 17:57:38 -04006707 mStatusBarController.dump(pw, prefix);
6708 mNavigationBarController.dump(pw, prefix);
John Spurlockc6d1c602014-01-17 15:22:06 -05006709 PolicyControl.dump(prefix, pw);
Jeff Brown600f0032014-05-22 17:06:00 -07006710
Jeff Browna20dda42014-05-27 20:57:24 -07006711 if (mWakeGestureListener != null) {
6712 mWakeGestureListener.dump(pw, prefix);
6713 }
Jeff Brown600f0032014-05-22 17:06:00 -07006714 if (mOrientationListener != null) {
6715 mOrientationListener.dump(pw, prefix);
6716 }
Filip Gruszczynskicfb31852015-02-25 21:47:12 +00006717 if (mBurnInProtectionHelper != null) {
6718 mBurnInProtectionHelper.dump(prefix, pw);
6719 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006720 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006721}