blob: b789d41b5070fe516b6bbeef08cbad9585f1b436 [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;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080020import android.app.ActivityManagerNative;
Dianne Hackbornc2293022013-02-06 23:14:49 -080021import android.app.AppOpsManager;
Daniel Sandler6396c722013-04-16 20:19:09 -040022import android.app.IUiModeManager;
Dianne Hackborn661cd522011-08-22 00:26:20 -070023import android.app.ProgressDialog;
Jeff Brownde7a8ea2012-06-13 18:28:57 -070024import android.app.SearchManager;
John Spurlock97642182013-07-29 17:58:39 -040025import android.app.StatusBarManager;
Dianne Hackborn78968392010-03-04 20:47:56 -080026import android.app.UiModeManager;
Dianne Hackborn39c2d712009-09-22 11:41:31 -070027import android.content.ActivityNotFoundException;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080028import android.content.BroadcastReceiver;
Daniel Sandler0601eb72011-04-13 01:01:32 -040029import android.content.ComponentName;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080030import android.content.ContentResolver;
31import android.content.Context;
32import android.content.Intent;
Mike Lockwood1753f7f2009-08-24 14:49:07 -070033import android.content.IntentFilter;
Winson Chung9112ec32011-06-27 13:15:32 -070034import android.content.ServiceConnection;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080035import android.content.pm.ActivityInfo;
36import android.content.pm.PackageManager;
Daniel Sandler6396c722013-04-16 20:19:09 -040037import android.content.pm.ResolveInfo;
Dianne Hackborn2f0b1752011-05-31 17:59:49 -070038import android.content.res.CompatibilityInfo;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080039import android.content.res.Configuration;
40import android.content.res.Resources;
Craig Mautner8e4df6c2012-05-23 16:57:23 -070041import android.content.res.TypedArray;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080042import android.database.ContentObserver;
Dianne Hackbornc777e072010-02-12 13:07:59 -080043import android.graphics.PixelFormat;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080044import android.graphics.Rect;
John Spurlock7b414672014-07-18 13:02:39 -040045import android.media.AudioAttributes;
Michael Jurka7a348952012-02-27 13:07:58 -080046import android.media.AudioManager;
John Spurlock61560172015-02-06 19:46:04 -050047import android.media.AudioSystem;
Michael Jurka7a348952012-02-27 13:07:58 -080048import android.media.IAudioService;
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -070049import android.media.Ringtone;
50import android.media.RingtoneManager;
RoboErik8a2cfc32014-05-16 11:19:38 -070051import android.media.session.MediaSessionLegacyHelper;
Mark Renoufc1256912015-03-11 14:38:23 -040052import android.os.Build;
Dianne Hackborn38e29a62011-09-18 14:43:08 -070053import android.os.Bundle;
Craig Mautner276a6eb2014-11-04 15:32:57 -080054import android.os.Debug;
Jeff Brown9a538ee2012-08-20 14:56:57 -070055import android.os.FactoryTest;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080056import android.os.Handler;
57import android.os.IBinder;
Jeff Brown32cbc38552011-12-01 14:01:49 -080058import android.os.Looper;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -070059import android.os.Message;
60import android.os.Messenger;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080061import android.os.PowerManager;
62import android.os.RemoteException;
63import android.os.ServiceManager;
64import android.os.SystemClock;
65import android.os.SystemProperties;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -080066import android.os.UEventObserver;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -070067import android.os.UserHandle;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080068import android.os.Vibrator;
Michael Wright3818c922014-09-02 13:59:07 -070069import android.provider.MediaStore;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080070import android.provider.Settings;
Jose Lima9546b202014-07-02 17:21:51 -070071import android.service.dreams.DreamManagerInternal;
John Spurlockc8b46ca2013-04-08 12:59:26 -040072import android.service.dreams.DreamService;
73import android.service.dreams.IDreamManager;
Michael Wrightdc63f7b2014-08-21 19:05:21 -070074import android.speech.RecognizerIntent;
Tyler Gunnef9f6f92014-09-12 22:16:17 -070075import android.telecom.TelecomManager;
Dianne Hackborn81e56d52011-05-26 00:55:58 -070076import android.util.DisplayMetrics;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080077import android.util.EventLog;
78import android.util.Log;
Jeff Browna41ca772010-08-11 14:46:32 -070079import android.util.Slog;
Jeff Brown6651a632011-11-28 12:59:11 -080080import android.util.SparseArray;
Dianne Hackbornf87d1962012-04-04 12:48:24 -070081import android.view.Display;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080082import android.view.Gravity;
83import android.view.HapticFeedbackConstants;
Dianne Hackborne0f085d2011-11-30 18:41:15 -080084import android.view.IApplicationToken;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080085import android.view.IWindowManager;
Jeff Browna41ca772010-08-11 14:46:32 -070086import android.view.InputChannel;
Jeff Brown4d396052010-10-29 21:50:21 -070087import android.view.InputDevice;
Jeff Brown4952dfd2011-11-30 19:23:22 -080088import android.view.InputEvent;
Jeff Brown32cbc38552011-12-01 14:01:49 -080089import android.view.InputEventReceiver;
Jeff Brown6b53e8d2010-11-10 16:03:06 -080090import android.view.KeyCharacterMap;
Craig Mautnerae446592012-12-06 19:05:05 -080091import android.view.KeyCharacterMap.FallbackAction;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080092import android.view.KeyEvent;
93import android.view.MotionEvent;
Jorim Jaggib10e33f2015-02-04 21:57:40 +010094import android.view.PhoneWindow;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080095import android.view.Surface;
96import android.view.View;
97import android.view.ViewConfiguration;
Mark Renoufc1256912015-03-11 14:38:23 -040098import android.view.ViewRootImpl;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080099import 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;
Craig Mautnerae446592012-12-06 19:05:05 -0800111import com.android.internal.widget.PointerLocationView;
Craig Mautner8a0da012014-05-31 15:13:37 -0700112import com.android.server.LocalServices;
Jorim Jaggib10e33f2015-02-04 21:57:40 +0100113import com.android.server.policy.keyguard.KeyguardServiceDelegate;
114import com.android.server.policy.keyguard.KeyguardServiceDelegate.ShowListener;
Craig Mautnerae446592012-12-06 19:05:05 -0800115
116import java.io.File;
117import java.io.FileReader;
118import java.io.IOException;
119import java.io.PrintWriter;
Craig Mautner2bc789b2014-03-19 19:48:38 -0700120import java.util.HashSet;
Craig Mautner276a6eb2014-11-04 15:32:57 -0800121import java.util.List;
Craig Mautnerae446592012-12-06 19:05:05 -0800122
Dianne Hackbornc652de82013-02-15 16:32:56 -0800123import static android.view.WindowManager.LayoutParams.*;
Jeff Brownac143512012-04-05 18:57:33 -0700124import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_ABSENT;
125import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_OPEN;
126import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_CLOSED;
Michael Wright3818c922014-09-02 13:59:07 -0700127import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVER_ABSENT;
128import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_UNCOVERED;
129import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVERED;
Dianne Hackborn08743722009-12-21 12:16:51 -0800130
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800131/**
The Android Open Source Project0727d222009-03-11 12:11:58 -0700132 * WindowManagerPolicy implementation for the Android phone UI. This
133 * introduces a new method suffix, Lp, for an internal lock of the
134 * PhoneWindowManager. This is used to protect some internal state, and
John Spurlock04db1762013-05-13 12:46:41 -0400135 * 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 -0700136 * of both of those when held.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800137 */
138public class PhoneWindowManager implements WindowManagerPolicy {
139 static final String TAG = "WindowManager";
140 static final boolean DEBUG = false;
Joe Onorato43a17652011-04-06 19:22:23 -0700141 static final boolean localLOGV = false;
Jeff Brown40013652012-05-16 21:22:36 -0700142 static final boolean DEBUG_INPUT = false;
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -0700143 static final boolean DEBUG_KEYGUARD = false;
144 static final boolean DEBUG_LAYOUT = false;
Craig Mautner6fbda632012-07-03 09:26:39 -0700145 static final boolean DEBUG_STARTING_WINDOW = false;
Craig Mautner8a0da012014-05-31 15:13:37 -0700146 static final boolean DEBUG_WAKEUP = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800147 static final boolean SHOW_STARTING_ANIMATIONS = true;
148 static final boolean SHOW_PROCESSES_ON_ALT_MENU = false;
Joe Onoratod208e702010-10-08 16:22:43 -0400149
Daniel Sandler6396c722013-04-16 20:19:09 -0400150 // Whether to allow dock apps with METADATA_DOCK_HOME to temporarily take over the Home key.
151 // No longer recommended for desk docks; still useful in car docks.
152 static final boolean ENABLE_CAR_DOCK_HOME_CAPTURE = true;
153 static final boolean ENABLE_DESK_DOCK_HOME_CAPTURE = false;
154
Jeff Brown6d8fd272014-05-20 21:24:38 -0700155 static final int SHORT_PRESS_POWER_NOTHING = 0;
156 static final int SHORT_PRESS_POWER_GO_TO_SLEEP = 1;
157 static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP = 2;
158 static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME = 3;
Bryce Lee01b0c5f2015-02-05 18:24:04 -0800159 static final int SHORT_PRESS_POWER_GO_HOME = 4;
Jeff Brown6d8fd272014-05-20 21:24:38 -0700160
Joe Onoratod208e702010-10-08 16:22:43 -0400161 static final int LONG_PRESS_POWER_NOTHING = 0;
162 static final int LONG_PRESS_POWER_GLOBAL_ACTIONS = 1;
163 static final int LONG_PRESS_POWER_SHUT_OFF = 2;
Jeff Brown9a538ee2012-08-20 14:56:57 -0700164 static final int LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM = 3;
Michael Jurka3b1fc472011-06-13 10:54:40 -0700165
Jeff Brown13f00f02014-10-31 14:45:50 -0700166 static final int MULTI_PRESS_POWER_NOTHING = 0;
167 static final int MULTI_PRESS_POWER_THEATER_MODE = 1;
168 static final int MULTI_PRESS_POWER_BRIGHTNESS_BOOST = 2;
169
Michael Jurka3b1fc472011-06-13 10:54:40 -0700170 // These need to match the documentation/constant in
171 // core/res/res/values/config.xml
Joe Onorato46b0d682010-11-22 17:37:27 -0800172 static final int LONG_PRESS_HOME_NOTHING = 0;
Michael Wrightc9ebea72013-01-16 19:25:02 -0800173 static final int LONG_PRESS_HOME_RECENT_SYSTEM_UI = 1;
Jeff Browncaca8812013-05-09 13:34:33 -0700174 static final int LONG_PRESS_HOME_ASSIST = 2;
175
176 static final int DOUBLE_TAP_HOME_NOTHING = 0;
177 static final int DOUBLE_TAP_HOME_RECENT_SYSTEM_UI = 1;
Joe Onorato46b0d682010-11-22 17:37:27 -0800178
Dianne Hackborn5cb8d792009-05-21 17:34:15 -0700179 static final int APPLICATION_MEDIA_SUBLAYER = -2;
180 static final int APPLICATION_MEDIA_OVERLAY_SUBLAYER = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800181 static final int APPLICATION_PANEL_SUBLAYER = 1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800182 static final int APPLICATION_SUB_PANEL_SUBLAYER = 2;
Craig Mautner88400d32012-09-30 12:35:45 -0700183
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800184 static public final String SYSTEM_DIALOG_REASON_KEY = "reason";
185 static public final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions";
186 static public final String SYSTEM_DIALOG_REASON_RECENT_APPS = "recentapps";
Joe Onoratof275f0c2009-11-24 16:11:13 -0500187 static public final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey";
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700188 static public final String SYSTEM_DIALOG_REASON_ASSIST = "assist";
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800189
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700190 /**
191 * These are the system UI flags that, when changing, can cause the layout
192 * of the screen to change.
193 */
194 static final int SYSTEM_UI_CHANGING_LAYOUT =
John Spurlocke1f366f2013-08-05 12:22:40 -0400195 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlock7f4820a2013-10-08 12:54:35 -0400196 | View.SYSTEM_UI_FLAG_FULLSCREEN
197 | View.STATUS_BAR_TRANSLUCENT
Adrian Roosea562512014-05-05 13:33:03 +0200198 | View.NAVIGATION_BAR_TRANSLUCENT
199 | View.SYSTEM_UI_TRANSPARENT;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700200
John Spurlock7b414672014-07-18 13:02:39 -0400201 private static final AudioAttributes VIBRATION_ATTRIBUTES = new AudioAttributes.Builder()
202 .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
203 .setUsage(AudioAttributes.USAGE_ASSISTANCE_SONIFICATION)
204 .build();
205
Jim Miller5ecd8112013-01-09 18:50:26 -0800206 /**
207 * Keyguard stuff
208 */
209 private WindowState mKeyguardScrim;
Jorim Jaggi380ecb82014-03-14 17:25:20 +0100210 private boolean mKeyguardHidden;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700211 private boolean mKeyguardDrawnOnce;
Jim Miller5ecd8112013-01-09 18:50:26 -0800212
Jeff Brown6651a632011-11-28 12:59:11 -0800213 /* Table of Application Launch keys. Maps from key codes to intent categories.
214 *
215 * These are special keys that are used to launch particular kinds of applications,
216 * such as a web browser. HID defines nearly a hundred of them in the Consumer (0x0C)
217 * usage page. We don't support quite that many yet...
218 */
219 static SparseArray<String> sApplicationLaunchKeyCategories;
220 static {
221 sApplicationLaunchKeyCategories = new SparseArray<String>();
222 sApplicationLaunchKeyCategories.append(
223 KeyEvent.KEYCODE_EXPLORER, Intent.CATEGORY_APP_BROWSER);
224 sApplicationLaunchKeyCategories.append(
225 KeyEvent.KEYCODE_ENVELOPE, Intent.CATEGORY_APP_EMAIL);
226 sApplicationLaunchKeyCategories.append(
227 KeyEvent.KEYCODE_CONTACTS, Intent.CATEGORY_APP_CONTACTS);
228 sApplicationLaunchKeyCategories.append(
229 KeyEvent.KEYCODE_CALENDAR, Intent.CATEGORY_APP_CALENDAR);
230 sApplicationLaunchKeyCategories.append(
231 KeyEvent.KEYCODE_MUSIC, Intent.CATEGORY_APP_MUSIC);
232 sApplicationLaunchKeyCategories.append(
233 KeyEvent.KEYCODE_CALCULATOR, Intent.CATEGORY_APP_CALCULATOR);
234 }
235
Craig Mautnerc3daedd2014-09-13 11:17:23 -0700236 /** Amount of time (in milliseconds) to wait for windows drawn before powering on. */
237 static final int WAITING_FOR_DRAWN_TIMEOUT = 1000;
238
Dianne Hackborndf89e652011-10-06 22:35:11 -0700239 /**
240 * Lock protecting internal state. Must not call out into window
241 * manager with lock held. (This lock will be acquired in places
242 * where the window manager is calling in with its own lock held.)
243 */
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800244 private final Object mLock = new Object();
Dianne Hackborndf89e652011-10-06 22:35:11 -0700245
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800246 Context mContext;
247 IWindowManager mWindowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700248 WindowManagerFuncs mWindowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -0700249 WindowManagerInternal mWindowManagerInternal;
Jeff Brown96307042012-07-27 15:51:34 -0700250 PowerManager mPowerManager;
Jose Lima9546b202014-07-02 17:21:51 -0700251 DreamManagerInternal mDreamManagerInternal;
Joe Onorato93056472010-09-10 10:30:46 -0400252 IStatusBarService mStatusBarService;
Jeff Browncaca8812013-05-09 13:34:33 -0700253 boolean mPreloadedRecentApps;
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700254 final Object mServiceAquireLock = new Object();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800255 Vibrator mVibrator; // Vibrator for giving feedback of orientation changes
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700256 SearchManager mSearchManager;
Svetoslav8e3feb12014-02-24 13:46:47 -0800257 AccessibilityManager mAccessibilityManager;
Filip Gruszczynskicfb31852015-02-25 21:47:12 +0000258 BurnInProtectionHelper mBurnInProtectionHelper;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800259
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700260 // Vibrator pattern for haptic feedback of a long press.
261 long[] mLongPressVibePattern;
Craig Mautner88400d32012-09-30 12:35:45 -0700262
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700263 // Vibrator pattern for haptic feedback of virtual key press.
264 long[] mVirtualKeyVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700265
Amith Yamasanic33cb712010-02-10 15:21:49 -0800266 // Vibrator pattern for a short vibration.
267 long[] mKeyboardTapVibePattern;
268
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -0700269 // Vibrator pattern for a short vibration when tapping on an hour/minute tick of a Clock.
270 long[] mClockTickVibePattern;
271
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -0700272 // Vibrator pattern for a short vibration when tapping on a day/month/year date of a Calendar.
273 long[] mCalendarDateVibePattern;
274
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700275 // Vibrator pattern for haptic feedback during boot when safe mode is disabled.
276 long[] mSafeModeDisabledVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700277
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700278 // Vibrator pattern for haptic feedback during boot when safe mode is enabled.
279 long[] mSafeModeEnabledVibePattern;
Romain Guy8154cd32010-03-29 14:41:15 -0700280
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800281 /** If true, hitting shift & menu will broadcast Intent.ACTION_BUG_REPORT */
282 boolean mEnableShiftMenuBugReports = false;
Mike Lockwoodd747dc82011-09-13 16:28:22 -0400283
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800284 boolean mSafeMode;
285 WindowState mStatusBar = null;
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700286 int mStatusBarHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400287 WindowState mNavigationBar = null;
Daniel Sandler36412a72011-08-04 09:35:13 -0400288 boolean mHasNavigationBar = false;
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700289 boolean mCanHideNavigationBar = false;
Daniel Sandler4a066c52012-04-20 14:49:13 -0400290 boolean mNavigationBarCanMove = false; // can the navigation bar ever move to the side?
291 boolean mNavigationBarOnBottom = true; // is the navigation bar on the bottom *right now*?
292 int[] mNavigationBarHeightForRotation = new int[4];
293 int[] mNavigationBarWidthForRotation = new int[4];
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400294
Craig Mautnera631d492014-08-05 15:16:01 -0700295 boolean mBootMessageNeedsHiding;
Jim Miller5ecd8112013-01-09 18:50:26 -0800296 KeyguardServiceDelegate mKeyguardDelegate;
Craig Mautner13f6ea72014-06-23 14:57:02 -0700297 final Runnable mWindowManagerDrawCallback = new Runnable() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700298 @Override
Craig Mautner13f6ea72014-06-23 14:57:02 -0700299 public void run() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700300 if (DEBUG_WAKEUP) Slog.i(TAG, "All windows ready for display!");
301 mHandler.sendEmptyMessage(MSG_WINDOW_MANAGER_DRAWN_COMPLETE);
302 }
303 };
304 final ShowListener mKeyguardDelegateCallback = new ShowListener() {
305 @Override
306 public void onShown(IBinder windowToken) {
307 if (DEBUG_WAKEUP) Slog.d(TAG, "mKeyguardDelegate.ShowListener.onShown.");
308 mHandler.sendEmptyMessage(MSG_KEYGUARD_DRAWN_COMPLETE);
309 }
310 };
311
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800312 GlobalActions mGlobalActions;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800313 Handler mHandler;
satok1bc0a492012-04-25 22:47:12 +0900314 WindowState mLastInputMethodWindow = null;
315 WindowState mLastInputMethodTargetWindow = null;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800316
Jeff Brown13f00f02014-10-31 14:45:50 -0700317 // FIXME This state is shared between the input reader and handler thread.
318 // Technically it's broken and buggy but it has been like this for many years
319 // and we have not yet seen any problems. Someday we'll rewrite this logic
320 // so that only one thread is involved in handling input policy. Unfortunately
321 // it's on a critical path for power management so we can't just post the work to the
322 // handler thread. We'll need to resolve this someday by teaching the input dispatcher
323 // to hold wakelocks during dispatch and eliminating the critical path.
324 volatile boolean mPowerKeyHandled;
Bryce Leed9268e32014-11-17 17:40:59 -0800325 volatile boolean mBeganFromNonInteractive;
Jeff Brown13f00f02014-10-31 14:45:50 -0700326 volatile int mPowerKeyPressCounter;
327 volatile boolean mEndCallKeyHandled;
328
Winson Chungd42a6cf2014-06-03 16:24:04 -0700329 boolean mRecentsVisible;
Winson Chung1e8d71b2014-05-16 17:05:22 -0700330 int mRecentAppsHeldModifiers;
Jeff Browncf39bdf2012-05-18 14:41:19 -0700331 boolean mLanguageSwitchKeyPressed;
Jeff Brown68b909d2011-12-07 16:36:01 -0800332
Jeff Brown2e7760e2012-04-11 15:14:55 -0700333 int mLidState = LID_ABSENT;
Michael Wright3818c922014-09-02 13:59:07 -0700334 int mCameraLensCoverState = CAMERA_LENS_COVER_ABSENT;
Jeff Browndaa37532012-05-01 15:54:03 -0700335 boolean mHaveBuiltInKeyboard;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800336
Dianne Hackbornc777e072010-02-12 13:07:59 -0800337 boolean mSystemReady;
Dianne Hackbornba24e4d2011-09-01 11:17:06 -0700338 boolean mSystemBooted;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800339 boolean mHdmiPlugged;
Jeff Brown4f5fa282014-06-12 19:19:15 -0700340 IUiModeManager mUiModeManager;
Daniel Sandler6396c722013-04-16 20:19:09 -0400341 int mUiMode;
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700342 int mDockMode = Intent.EXTRA_DOCK_STATE_UNDOCKED;
Mike Lockwood1753f7f2009-08-24 14:49:07 -0700343 int mLidOpenRotation;
Mike Lockwood2d1efbd2009-09-16 12:15:53 -0400344 int mCarDockRotation;
345 int mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -0700346 int mUndockedHdmiRotation;
347 int mDemoHdmiRotation;
348 boolean mDemoHdmiRotationLock;
Chong Zhangae6119ff2014-11-11 18:54:39 -0800349 int mDemoRotation;
350 boolean mDemoRotationLock;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400351
Jeff Browna20dda42014-05-27 20:57:24 -0700352 boolean mWakeGestureEnabledSetting;
353 MyWakeGestureListener mWakeGestureListener;
354
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700355 // Default display does not rotate, apps that require non-default orientation will have to
356 // have the orientation emulated.
357 private boolean mForceDefaultOrientation = false;
358
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400359 int mUserRotationMode = WindowManagerPolicy.USER_ROTATION_FREE;
360 int mUserRotation = Surface.ROTATION_0;
Jeff Brown207673cd2012-06-05 17:47:11 -0700361 boolean mAccelerometerDefault;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400362
Jeff Brownbcdfc622014-03-06 19:13:04 -0800363 boolean mSupportAutoRotation;
Jeff Brownd3187e32011-09-21 19:26:44 -0700364 int mAllowAllRotations = -1;
Mike Lockwoode9867d22009-09-20 01:59:02 -0400365 boolean mCarDockEnablesAccelerometer;
366 boolean mDeskDockEnablesAccelerometer;
Dianne Hackborn2862fff2009-09-15 22:56:29 -0700367 int mLidKeyboardAccessibility;
368 int mLidNavigationAccessibility;
Jeff Brownc458ce92012-04-30 14:58:40 -0700369 boolean mLidControlsSleep;
Jeff Brown13f00f02014-10-31 14:45:50 -0700370 int mShortPressOnPowerBehavior;
371 int mLongPressOnPowerBehavior;
372 int mDoublePressOnPowerBehavior;
373 int mTriplePressOnPowerBehavior;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700374 boolean mAwake;
375 boolean mScreenOnEarly;
376 boolean mScreenOnFully;
377 ScreenOnListener mScreenOnListener;
378 boolean mKeyguardDrawComplete;
379 boolean mWindowManagerDrawComplete;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800380 boolean mOrientationSensorEnabled = false;
381 int mCurrentAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800382 boolean mHasSoftInput = false;
Daniel Sandlerdd73ee42013-10-11 22:19:59 -0400383 boolean mTranslucentDecorEnabled = true;
RoboErik001c59c2015-01-26 15:53:51 -0800384 boolean mUseTvRouting;
Craig Mautner967212c2013-04-13 21:10:58 -0700385
Jeff Brown70825162012-03-28 17:27:48 -0700386 int mPointerLocationMode = 0; // guarded by mLock
Joe Onorato664644d2011-01-23 17:53:23 -0800387
388 // The last window we were told about in focusChanged.
389 WindowState mFocusedWindow;
Dianne Hackborne0f085d2011-11-30 18:41:15 -0800390 IApplicationToken mFocusedApp;
Joe Onorato664644d2011-01-23 17:53:23 -0800391
Jeff Brown70825162012-03-28 17:27:48 -0700392 PointerLocationView mPointerLocationView;
Jeff Brown32cbc38552011-12-01 14:01:49 -0800393
Dianne Hackbornc652de82013-02-15 16:32:56 -0800394 // The current size of the screen; really; extends into the overscan area of
395 // the screen and doesn't account for any system elements like the status bar.
396 int mOverscanScreenLeft, mOverscanScreenTop;
397 int mOverscanScreenWidth, mOverscanScreenHeight;
398 // The current visible size of the screen; really; (ir)regardless of whether the status
399 // bar can be hidden but not extending into the overscan area.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800400 int mUnrestrictedScreenLeft, mUnrestrictedScreenTop;
401 int mUnrestrictedScreenWidth, mUnrestrictedScreenHeight;
Dianne Hackborn313440842013-02-19 19:22:59 -0800402 // Like mOverscanScreen*, but allowed to move into the overscan region where appropriate.
403 int mRestrictedOverscanScreenLeft, mRestrictedOverscanScreenTop;
404 int mRestrictedOverscanScreenWidth, mRestrictedOverscanScreenHeight;
Dianne Hackborn82de1ae2010-10-28 11:28:39 -0700405 // The current size of the screen; these may be different than (0,0)-(dw,dh)
406 // if the status bar can't be hidden; in that case it effectively carves out
407 // that area of the display from all other windows.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800408 int mRestrictedScreenLeft, mRestrictedScreenTop;
409 int mRestrictedScreenWidth, mRestrictedScreenHeight;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700410 // During layout, the current screen borders accounting for any currently
411 // visible system UI elements.
412 int mSystemLeft, mSystemTop, mSystemRight, mSystemBottom;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700413 // For applications requesting stable content insets, these are them.
414 int mStableLeft, mStableTop, mStableRight, mStableBottom;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -0700415 // For applications requesting stable content insets but have also set the
416 // fullscreen window flag, these are the stable dimensions without the status bar.
417 int mStableFullscreenLeft, mStableFullscreenTop;
418 int mStableFullscreenRight, mStableFullscreenBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800419 // During layout, the current screen borders with all outer decoration
420 // (status bar, input method dock) accounted for.
421 int mCurLeft, mCurTop, mCurRight, mCurBottom;
422 // During layout, the frame in which content should be displayed
423 // to the user, accounting for all screen decoration except for any
424 // space they deem as available for other content. This is usually
425 // the same as mCur*, but may be larger if the screen decor has supplied
426 // content insets.
427 int mContentLeft, mContentTop, mContentRight, mContentBottom;
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700428 // During layout, the frame in which voice content should be displayed
429 // to the user, accounting for all screen decoration except for any
430 // space they deem as available for other content.
431 int mVoiceContentLeft, mVoiceContentTop, mVoiceContentRight, mVoiceContentBottom;
Dianne Hackborn8e11ef02010-11-18 19:47:42 -0800432 // During layout, the current screen borders along which input method
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800433 // windows are placed.
434 int mDockLeft, mDockTop, mDockRight, mDockBottom;
435 // During layout, the layer at which the doc window is placed.
436 int mDockLayer;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700437 // During layout, this is the layer of the status bar.
438 int mStatusBarLayer;
Dianne Hackborne26ab702011-10-16 13:21:33 -0700439 int mLastSystemUiFlags;
440 // Bits that we are in the process of clearing, so we want to prevent
441 // them from being set by applications until everything has been updated
442 // to have them clear.
443 int mResettingSystemUiFlags = 0;
444 // Bits that we are currently always keeping cleared.
445 int mForceClearedSystemUiFlags = 0;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -0800446 // What we last reported to system UI about whether the compatibility
447 // menu needs to be displayed.
448 boolean mLastFocusNeedsMenu = false;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700449
450 FakeWindow mHideNavFakeWindow = null;
451
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800452 static final Rect mTmpParentFrame = new Rect();
453 static final Rect mTmpDisplayFrame = new Rect();
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800454 static final Rect mTmpOverscanFrame = new Rect();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800455 static final Rect mTmpContentFrame = new Rect();
456 static final Rect mTmpVisibleFrame = new Rect();
John Spurlock46646232013-09-30 22:32:42 -0400457 static final Rect mTmpDecorFrame = new Rect();
Adrian Roosfa104232014-06-20 16:10:14 -0700458 static final Rect mTmpStableFrame = new Rect();
Dianne Hackborn1f903c32011-09-13 19:18:06 -0700459 static final Rect mTmpNavigationFrame = new Rect();
Craig Mautner967212c2013-04-13 21:10:58 -0700460
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800461 WindowState mTopFullscreenOpaqueWindowState;
Adrian Rooscd3884d2015-02-18 17:25:23 +0100462 WindowState mTopFullscreenOpaqueOrDimmingWindowState;
Craig Mautner2bc789b2014-03-19 19:48:38 -0700463 HashSet<IApplicationToken> mAppsToBeHidden = new HashSet<IApplicationToken>();
Jorim Jaggic13fcac2014-09-11 17:36:57 +0200464 HashSet<IApplicationToken> mAppsThatDismissKeyguard = new HashSet<IApplicationToken>();
Joe Onorato93056472010-09-10 10:30:46 -0400465 boolean mTopIsFullscreen;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800466 boolean mForceStatusBar;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -0700467 boolean mForceStatusBarFromKeyguard;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700468 boolean mHideLockScreen;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -0800469 boolean mForcingShowNavBar;
470 int mForcingShowNavBarLayer;
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700471
472 // States of keyguard dismiss.
473 private static final int DISMISS_KEYGUARD_NONE = 0; // Keyguard not being dismissed.
474 private static final int DISMISS_KEYGUARD_START = 1; // Keyguard needs to be dismissed.
475 private static final int DISMISS_KEYGUARD_CONTINUE = 2; // Keyguard has been dismissed.
476 int mDismissKeyguard = DISMISS_KEYGUARD_NONE;
477
478 /** The window that is currently dismissing the keyguard. Dismissing the keyguard must only
479 * be done once per window. */
480 private WindowState mWinDismissingKeyguard;
481
Craig Mautnerc9457fa2014-06-06 14:27:48 -0700482 /** The window that is currently showing "over" the keyguard. If there is an app window
483 * belonging to another app on top of this the keyguard shows. If there is a fullscreen
484 * app window under this, still dismiss the keyguard but don't show the app underneath. Show
485 * the wallpaper. */
486 private WindowState mWinShowWhenLocked;
487
Dianne Hackborn7ad44382012-10-18 17:46:00 -0700488 boolean mShowingLockscreen;
489 boolean mShowingDream;
490 boolean mDreamingLockscreen;
Jim Millerab954542014-10-10 18:21:49 -0700491 boolean mKeyguardSecure;
492 boolean mKeyguardSecureIncludingHidden;
493 volatile boolean mKeyguardOccluded;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800494 boolean mHomePressed;
Jeff Browncaca8812013-05-09 13:34:33 -0700495 boolean mHomeConsumed;
496 boolean mHomeDoubleTapPending;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800497 Intent mHomeIntent;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700498 Intent mCarDockIntent;
499 Intent mDeskDockIntent;
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700500 boolean mSearchKeyShortcutPending;
501 boolean mConsumeSearchKeyUp;
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700502 boolean mAssistKeyLongPressed;
Michael Wright6a62e552014-06-03 19:19:48 -0700503 boolean mPendingMetaAction;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800504
Mike Lockwood28569302010-01-28 11:54:40 -0500505 // support for activating the lock screen while the screen is on
506 boolean mAllowLockscreenWhenOn;
507 int mLockScreenTimeout;
508 boolean mLockScreenTimerActive;
509
David Brownbaf8d092010-03-08 21:52:59 -0800510 // Behavior of ENDCALL Button. (See Settings.System.END_BUTTON_BEHAVIOR.)
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800511 int mEndcallBehavior;
David Brownbaf8d092010-03-08 21:52:59 -0800512
513 // Behavior of POWER button while in-call and screen on.
514 // (See Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR.)
515 int mIncallPowerBehavior;
516
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700517 Display mDisplay;
518
Dianne Hackborn9d132642011-04-21 17:26:39 -0700519 int mLandscapeRotation = 0; // default landscape rotation
520 int mSeascapeRotation = 0; // "other" landscape rotation, 180 degrees from mLandscapeRotation
521 int mPortraitRotation = 0; // default portrait rotation
522 int mUpsideDownRotation = 0; // "other" portrait rotation
Mitsuru Oshima831d0d92009-06-16 18:27:18 -0700523
Dianne Hackbornc652de82013-02-15 16:32:56 -0800524 int mOverscanLeft = 0;
525 int mOverscanTop = 0;
526 int mOverscanRight = 0;
527 int mOverscanBottom = 0;
528
Joe Onorato46b0d682010-11-22 17:37:27 -0800529 // What we do when the user long presses on home
Jeff Browncaca8812013-05-09 13:34:33 -0700530 private int mLongPressOnHomeBehavior;
531
532 // What we do when the user double-taps on home
533 private int mDoubleTapOnHomeBehavior;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800534
Bryce Lee584a4452014-10-21 15:55:55 -0700535 // Allowed theater mode wake actions
536 private boolean mAllowTheaterModeWakeFromKey;
537 private boolean mAllowTheaterModeWakeFromPowerKey;
538 private boolean mAllowTheaterModeWakeFromMotion;
Bryce Lee812d7022014-11-10 13:33:28 -0800539 private boolean mAllowTheaterModeWakeFromMotionWhenNotDreaming;
Bryce Lee584a4452014-10-21 15:55:55 -0700540 private boolean mAllowTheaterModeWakeFromCameraLens;
541 private boolean mAllowTheaterModeWakeFromLidSwitch;
542 private boolean mAllowTheaterModeWakeFromWakeGesture;
543
Bryce Leed3b28402015-03-09 15:49:13 +0000544 // Whether to support long press from power button in non-interactive mode
545 private boolean mSupportLongPressPowerWhenNonInteractive;
546
Bryce Lee55e846d2014-11-04 12:43:44 -0800547 // Whether to go to sleep entering theater mode from power button
548 private boolean mGoToSleepOnButtonPressTheaterMode;
549
Winson Chung9112ec32011-06-27 13:15:32 -0700550 // Screenshot trigger states
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700551 // Time to volume and power must be pressed within this interval of each other.
552 private static final long SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS = 150;
Winson Chung1cea2f32012-10-08 20:42:01 -0700553 // Increase the chord delay when taking a screenshot from the keyguard
554 private static final float KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER = 2.5f;
Christopher Tatee90585f2012-03-05 18:56:25 -0800555 private boolean mScreenshotChordEnabled;
Jeff Brown13f00f02014-10-31 14:45:50 -0700556 private boolean mScreenshotChordVolumeDownKeyTriggered;
557 private long mScreenshotChordVolumeDownKeyTime;
558 private boolean mScreenshotChordVolumeDownKeyConsumed;
559 private boolean mScreenshotChordVolumeUpKeyTriggered;
560 private boolean mScreenshotChordPowerKeyTriggered;
561 private long mScreenshotChordPowerKeyTime;
Winson Chung9112ec32011-06-27 13:15:32 -0700562
Michael Wrightb854e242013-02-05 17:54:02 -0800563 /* The number of steps between min and max brightness */
564 private static final int BRIGHTNESS_STEPS = 10;
565
Christopher Tate5e08af02012-09-21 17:17:22 -0700566 SettingsObserver mSettingsObserver;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800567 ShortcutManager mShortcutManager;
568 PowerManager.WakeLock mBroadcastWakeLock;
Jeff Brown13f00f02014-10-31 14:45:50 -0700569 PowerManager.WakeLock mPowerKeyWakeLock;
Jeff Brown40013652012-05-16 21:22:36 -0700570 boolean mHavePendingMediaKeyRepeatWithWakeLock;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800571
Craig Mautnerd625ab22013-09-06 13:40:31 -0700572 private int mCurrentUserId;
573
Justin Kohd378ad72013-04-01 12:18:26 -0700574 // Maps global key codes to the components that will handle them.
575 private GlobalKeyManager mGlobalKeyManager;
576
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700577 // Fallback actions by key code.
578 private final SparseArray<KeyCharacterMap.FallbackAction> mFallbackActions =
579 new SparseArray<KeyCharacterMap.FallbackAction>();
Jeff Brown49ed71d2010-12-06 17:13:33 -0800580
Jorim Jaggi76a16232014-08-08 17:00:47 +0200581 private final LogDecelerateInterpolator mLogDecelerateInterpolator
582 = new LogDecelerateInterpolator(100, 0);
583
Jeff Brown70825162012-03-28 17:27:48 -0700584 private static final int MSG_ENABLE_POINTER_LOCATION = 1;
585 private static final int MSG_DISABLE_POINTER_LOCATION = 2;
Jeff Brown40013652012-05-16 21:22:36 -0700586 private static final int MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK = 3;
587 private static final int MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK = 4;
Craig Mautner8a0da012014-05-31 15:13:37 -0700588 private static final int MSG_KEYGUARD_DRAWN_COMPLETE = 5;
589 private static final int MSG_KEYGUARD_DRAWN_TIMEOUT = 6;
590 private static final int MSG_WINDOW_MANAGER_DRAWN_COMPLETE = 7;
Craig Mautner84984fa2014-06-19 11:19:20 -0700591 private static final int MSG_DISPATCH_SHOW_RECENTS = 9;
Alan Viverettee34560b22014-07-10 14:50:06 -0700592 private static final int MSG_DISPATCH_SHOW_GLOBAL_ACTIONS = 10;
Craig Mautnera631d492014-08-05 15:16:01 -0700593 private static final int MSG_HIDE_BOOT_MESSAGE = 11;
Michael Wright869a67c2014-08-26 19:33:06 -0700594 private static final int MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK = 12;
Jeff Brown13f00f02014-10-31 14:45:50 -0700595 private static final int MSG_POWER_DELAYED_PRESS = 13;
596 private static final int MSG_POWER_LONG_PRESS = 14;
Jeff Brown70825162012-03-28 17:27:48 -0700597
598 private class PolicyHandler extends Handler {
599 @Override
600 public void handleMessage(Message msg) {
601 switch (msg.what) {
602 case MSG_ENABLE_POINTER_LOCATION:
603 enablePointerLocation();
604 break;
605 case MSG_DISABLE_POINTER_LOCATION:
606 disablePointerLocation();
607 break;
Jeff Brown40013652012-05-16 21:22:36 -0700608 case MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK:
609 dispatchMediaKeyWithWakeLock((KeyEvent)msg.obj);
610 break;
611 case MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK:
612 dispatchMediaKeyRepeatWithWakeLock((KeyEvent)msg.obj);
613 break;
Craig Mautner84984fa2014-06-19 11:19:20 -0700614 case MSG_DISPATCH_SHOW_RECENTS:
615 showRecentApps(false);
616 break;
Alan Viverettee34560b22014-07-10 14:50:06 -0700617 case MSG_DISPATCH_SHOW_GLOBAL_ACTIONS:
618 showGlobalActionsInternal();
619 break;
Craig Mautner8a0da012014-05-31 15:13:37 -0700620 case MSG_KEYGUARD_DRAWN_COMPLETE:
621 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mKeyguardDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700622 finishKeyguardDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700623 break;
624 case MSG_KEYGUARD_DRAWN_TIMEOUT:
625 Slog.w(TAG, "Keyguard drawn timeout. Setting mKeyguardDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700626 finishKeyguardDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700627 break;
628 case MSG_WINDOW_MANAGER_DRAWN_COMPLETE:
629 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mWindowManagerDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700630 finishWindowsDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700631 break;
Craig Mautnera631d492014-08-05 15:16:01 -0700632 case MSG_HIDE_BOOT_MESSAGE:
633 handleHideBootMessage();
634 break;
Michael Wright869a67c2014-08-26 19:33:06 -0700635 case MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK:
636 launchVoiceAssistWithWakeLock(msg.arg1 != 0);
637 break;
Jeff Brown13f00f02014-10-31 14:45:50 -0700638 case MSG_POWER_DELAYED_PRESS:
639 powerPress((Long)msg.obj, msg.arg1 != 0, msg.arg2);
640 finishPowerKeyPress();
641 break;
642 case MSG_POWER_LONG_PRESS:
643 powerLongPress();
644 break;
Jeff Brown70825162012-03-28 17:27:48 -0700645 }
646 }
647 }
648
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800649 private UEventObserver mHDMIObserver = new UEventObserver() {
650 @Override
651 public void onUEvent(UEventObserver.UEvent event) {
652 setHdmiPlugged("1".equals(event.get("SWITCH_STATE")));
653 }
654 };
655
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800656 class SettingsObserver extends ContentObserver {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800657 SettingsObserver(Handler handler) {
658 super(handler);
659 }
David Brownbaf8d092010-03-08 21:52:59 -0800660
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800661 void observe() {
Christopher Tate5e08af02012-09-21 17:17:22 -0700662 // Observe all users' changes
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800663 ContentResolver resolver = mContext.getContentResolver();
664 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700665 Settings.System.END_BUTTON_BEHAVIOR), false, this,
666 UserHandle.USER_ALL);
David Brownbaf8d092010-03-08 21:52:59 -0800667 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700668 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR), false, this,
669 UserHandle.USER_ALL);
Jeff Browna20dda42014-05-27 20:57:24 -0700670 resolver.registerContentObserver(Settings.Secure.getUriFor(
671 Settings.Secure.WAKE_GESTURE_ENABLED), false, this,
672 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800673 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700674 Settings.System.ACCELEROMETER_ROTATION), false, this,
675 UserHandle.USER_ALL);
Mike Lockwood28569302010-01-28 11:54:40 -0500676 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700677 Settings.System.USER_ROTATION), false, this,
678 UserHandle.USER_ALL);
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400679 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700680 Settings.System.SCREEN_OFF_TIMEOUT), false, this,
681 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800682 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700683 Settings.System.POINTER_LOCATION), false, this,
684 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800685 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700686 Settings.Secure.DEFAULT_INPUT_METHOD), false, this,
687 UserHandle.USER_ALL);
John Spurlockd9b70bd2014-02-06 17:02:44 -0500688 resolver.registerContentObserver(Settings.Secure.getUriFor(
John Spurlockf1a36642013-10-12 17:50:42 -0400689 Settings.Secure.IMMERSIVE_MODE_CONFIRMATIONS), false, this,
Christopher Tate5e08af02012-09-21 17:17:22 -0700690 UserHandle.USER_ALL);
John Spurlockc6d1c602014-01-17 15:22:06 -0500691 resolver.registerContentObserver(Settings.Global.getUriFor(
692 Settings.Global.POLICY_CONTROL), false, this,
693 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800694 updateSettings();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800695 }
696
697 @Override public void onChange(boolean selfChange) {
Dianne Hackbornc777e072010-02-12 13:07:59 -0800698 updateSettings();
Jeff Brown01a98dd2011-09-20 15:08:29 -0700699 updateRotation(false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800700 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800701 }
Craig Mautner967212c2013-04-13 21:10:58 -0700702
Jeff Browna20dda42014-05-27 20:57:24 -0700703 class MyWakeGestureListener extends WakeGestureListener {
704 MyWakeGestureListener(Context context, Handler handler) {
705 super(context, handler);
706 }
707
708 @Override
709 public void onWakeUp() {
710 synchronized (mLock) {
711 if (shouldEnableWakeGestureLp()) {
Jeff Browne07b94b2014-06-18 15:56:27 -0700712 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
Bryce Lee584a4452014-10-21 15:55:55 -0700713 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromWakeGesture);
Jeff Browna20dda42014-05-27 20:57:24 -0700714 }
715 }
716 }
717 }
718
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800719 class MyOrientationListener extends WindowOrientationListener {
Craig Mautnereee29c42013-01-17 14:44:34 -0800720 MyOrientationListener(Context context, Handler handler) {
721 super(context, handler);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800722 }
Craig Mautner967212c2013-04-13 21:10:58 -0700723
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800724 @Override
Jeff Brownc0347aa2011-09-23 17:26:09 -0700725 public void onProposedRotationChanged(int rotation) {
Craig Mautnereda67292013-04-28 13:50:14 -0700726 if (localLOGV) Slog.v(TAG, "onProposedRotationChanged, rotation=" + rotation);
Jeff Brown01a98dd2011-09-20 15:08:29 -0700727 updateRotation(false);
728 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800729 }
730 MyOrientationListener mOrientationListener;
731
Jorim Jaggi24bec7c2015-02-04 12:40:14 +0100732 private final StatusBarController mStatusBarController = new StatusBarController();
John Spurlock5b9145b2013-08-20 15:13:47 -0400733
John Spurlock27735a42013-08-14 17:57:38 -0400734 private final BarController mNavigationBarController = new BarController("NavigationBar",
John Spurlock5b9145b2013-08-20 15:13:47 -0400735 View.NAVIGATION_BAR_TRANSIENT,
736 View.NAVIGATION_BAR_UNHIDE,
John Spurlockbd957402013-10-03 11:38:39 -0400737 View.NAVIGATION_BAR_TRANSLUCENT,
738 StatusBarManager.WINDOW_NAVIGATION_BAR,
739 WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
John Spurlock5b9145b2013-08-20 15:13:47 -0400740
John Spurlockf1a36642013-10-12 17:50:42 -0400741 private ImmersiveModeConfirmation mImmersiveModeConfirmation;
John Spurlock32beb2c2013-03-11 10:16:47 -0400742
Craig Mautner037aa8d2013-06-07 10:35:44 -0700743 private SystemGesturesPointerEventListener mSystemGestures;
John Spurlock32beb2c2013-03-11 10:16:47 -0400744
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700745 IStatusBarService getStatusBarService() {
746 synchronized (mServiceAquireLock) {
747 if (mStatusBarService == null) {
748 mStatusBarService = IStatusBarService.Stub.asInterface(
749 ServiceManager.getService("statusbar"));
750 }
751 return mStatusBarService;
752 }
753 }
754
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700755 /*
756 * We always let the sensor be switched on by default except when
757 * the user has explicitly disabled sensor based rotation or when the
758 * screen is switched off.
759 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700760 boolean needSensorRunningLp() {
Jeff Brownbcdfc622014-03-06 19:13:04 -0800761 if (mSupportAutoRotation) {
762 if (mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
763 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
764 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT
765 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) {
766 // If the application has explicitly requested to follow the
767 // orientation, then we need to turn the sensor on.
768 return true;
769 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800770 }
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700771 if ((mCarDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_CAR) ||
Jeff Brown1a693182011-11-08 14:44:16 -0800772 (mDeskDockEnablesAccelerometer && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
773 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
774 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK))) {
Mike Lockwoode9867d22009-09-20 01:59:02 -0400775 // enable accelerometer if we are docked in a dock that enables accelerometer
776 // orientation management,
777 return true;
778 }
Jeff Brown207673cd2012-06-05 17:47:11 -0700779 if (mUserRotationMode == USER_ROTATION_LOCKED) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800780 // If the setting for using the sensor by default is enabled, then
781 // we will always leave it on. Note that the user could go to
782 // a window that forces an orientation that does not use the
783 // sensor and in theory we could turn it off... however, when next
784 // turning it on we won't have a good value for the current
785 // orientation for a little bit, which can cause orientation
786 // changes to lag, so we'd like to keep it always on. (It will
787 // still be turned off when the screen is off.)
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700788 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800789 }
Jeff Brownbcdfc622014-03-06 19:13:04 -0800790 return mSupportAutoRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800791 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700792
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800793 /*
794 * Various use cases for invoking this function
795 * screen turning off, should always disable listeners if already enabled
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700796 * screen turned on and current app has sensor based orientation, enable listeners
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800797 * if not already enabled
798 * screen turned on and current app does not have sensor orientation, disable listeners if
799 * already enabled
800 * screen turning on and current app has sensor based orientation, enable listeners if needed
801 * screen turning on and current app has nosensor based orientation, do nothing
802 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700803 void updateOrientationListenerLp() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800804 if (!mOrientationListener.canDetectOrientation()) {
805 // If sensor is turned off or nonexistent for some reason
806 return;
807 }
808 //Could have been invoked due to screen turning on or off or
809 //change of the currently visible window's orientation
Jeff Brown3ee549c2014-09-22 20:14:39 -0700810 if (localLOGV) Slog.v(TAG, "mScreenOnEarly=" + mScreenOnEarly
811 + ", mAwake=" + mAwake + ", mCurrentAppOrientation=" + mCurrentAppOrientation
812 + ", mOrientationSensorEnabled=" + mOrientationSensorEnabled);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800813 boolean disable = true;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700814 if (mScreenOnEarly && mAwake) {
The Android Open Source Project0727d222009-03-11 12:11:58 -0700815 if (needSensorRunningLp()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800816 disable = false;
817 //enable listener if not already enabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700818 if (!mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800819 mOrientationListener.enable();
Craig Mautnereda67292013-04-28 13:50:14 -0700820 if(localLOGV) Slog.v(TAG, "Enabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800821 mOrientationSensorEnabled = true;
822 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700823 }
824 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800825 //check if sensors need to be disabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700826 if (disable && mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800827 mOrientationListener.disable();
Craig Mautnereda67292013-04-28 13:50:14 -0700828 if(localLOGV) Slog.v(TAG, "Disabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800829 mOrientationSensorEnabled = false;
830 }
831 }
832
Jeff Brown13f00f02014-10-31 14:45:50 -0700833 private void interceptPowerKeyDown(KeyEvent event, boolean interactive) {
834 // Hold a wake lock until the power key is released.
835 if (!mPowerKeyWakeLock.isHeld()) {
836 mPowerKeyWakeLock.acquire();
837 }
838
839 // Cancel multi-press detection timeout.
840 if (mPowerKeyPressCounter != 0) {
841 mHandler.removeMessages(MSG_POWER_DELAYED_PRESS);
842 }
843
844 // Detect user pressing the power button in panic when an application has
845 // taken over the whole screen.
846 boolean panic = mImmersiveModeConfirmation.onPowerKeyDown(interactive,
Craig Mautner0124980e92014-11-30 21:15:34 -0800847 SystemClock.elapsedRealtime(), isImmersiveMode(mLastSystemUiFlags));
Jeff Brown13f00f02014-10-31 14:45:50 -0700848 if (panic) {
849 mHandler.post(mRequestTransientNav);
850 }
851
852 // Latch power key state to detect screenshot chord.
853 if (interactive && !mScreenshotChordPowerKeyTriggered
854 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
855 mScreenshotChordPowerKeyTriggered = true;
856 mScreenshotChordPowerKeyTime = event.getDownTime();
857 interceptScreenshotChord();
858 }
859
860 // Stop ringing or end call if configured to do so when power is pressed.
861 TelecomManager telecomManager = getTelecommService();
862 boolean hungUp = false;
863 if (telecomManager != null) {
864 if (telecomManager.isRinging()) {
865 // Pressing Power while there's a ringing incoming
866 // call should silence the ringer.
867 telecomManager.silenceRinger();
868 } else if ((mIncallPowerBehavior
869 & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0
870 && telecomManager.isInCall() && interactive) {
871 // Otherwise, if "Power button ends call" is enabled,
872 // the Power button will hang up any current active call.
873 hungUp = telecomManager.endCall();
874 }
875 }
876
877 // If the power key has still not yet been handled, then detect short
878 // press, long press, or multi press and decide what to do.
879 mPowerKeyHandled = hungUp || mScreenshotChordVolumeDownKeyTriggered
880 || mScreenshotChordVolumeUpKeyTriggered;
881 if (!mPowerKeyHandled) {
882 if (interactive) {
883 // When interactive, we're already awake.
884 // Wait for a long press or for the button to be released to decide what to do.
885 if (hasLongPressOnPowerBehavior()) {
886 Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS);
887 msg.setAsynchronous(true);
888 mHandler.sendMessageDelayed(msg,
889 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
890 }
891 } else {
Bryce Leed9268e32014-11-17 17:40:59 -0800892 wakeUpFromPowerKey(event.getDownTime());
Bryce Leed9268e32014-11-17 17:40:59 -0800893
Bryce Leed3b28402015-03-09 15:49:13 +0000894 if (mSupportLongPressPowerWhenNonInteractive && hasLongPressOnPowerBehavior()) {
895 Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS);
896 msg.setAsynchronous(true);
897 mHandler.sendMessageDelayed(msg,
898 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Bryce Leed9268e32014-11-17 17:40:59 -0800899 mBeganFromNonInteractive = true;
Bryce Leed3b28402015-03-09 15:49:13 +0000900 } else {
901 final int maxCount = getMaxMultiPressPowerCount();
902
903 if (maxCount <= 1) {
904 mPowerKeyHandled = true;
905 } else {
906 mBeganFromNonInteractive = true;
907 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700908 }
909 }
Jeff Brown4d396052010-10-29 21:50:21 -0700910 }
911 }
912
Jeff Brown13f00f02014-10-31 14:45:50 -0700913 private void interceptPowerKeyUp(KeyEvent event, boolean interactive, boolean canceled) {
914 final boolean handled = canceled || mPowerKeyHandled;
915 mScreenshotChordPowerKeyTriggered = false;
916 cancelPendingScreenshotChordAction();
917 cancelPendingPowerKeyAction();
918
919 if (!handled) {
920 // Figure out how to handle the key now that it has been released.
921 mPowerKeyPressCounter += 1;
922
923 final int maxCount = getMaxMultiPressPowerCount();
924 final long eventTime = event.getDownTime();
925 if (mPowerKeyPressCounter < maxCount) {
926 // This could be a multi-press. Wait a little bit longer to confirm.
927 // Continue holding the wake lock.
928 Message msg = mHandler.obtainMessage(MSG_POWER_DELAYED_PRESS,
929 interactive ? 1 : 0, mPowerKeyPressCounter, eventTime);
930 msg.setAsynchronous(true);
931 mHandler.sendMessageDelayed(msg, ViewConfiguration.getDoubleTapTimeout());
932 return;
933 }
934
935 // No other actions. Handle it immediately.
936 powerPress(eventTime, interactive, mPowerKeyPressCounter);
Jeff Brown4d396052010-10-29 21:50:21 -0700937 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700938
939 // Done. Reset our state.
940 finishPowerKeyPress();
941 }
942
943 private void finishPowerKeyPress() {
Bryce Leed9268e32014-11-17 17:40:59 -0800944 mBeganFromNonInteractive = false;
Jeff Brown13f00f02014-10-31 14:45:50 -0700945 mPowerKeyPressCounter = 0;
946 if (mPowerKeyWakeLock.isHeld()) {
947 mPowerKeyWakeLock.release();
948 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700949 }
950
951 private void cancelPendingPowerKeyAction() {
952 if (!mPowerKeyHandled) {
Jeff Brown13f00f02014-10-31 14:45:50 -0700953 mPowerKeyHandled = true;
954 mHandler.removeMessages(MSG_POWER_LONG_PRESS);
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700955 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700956 }
957
958 private void powerPress(long eventTime, boolean interactive, int count) {
959 if (mScreenOnEarly && !mScreenOnFully) {
960 Slog.i(TAG, "Suppressed redundant power key press while "
961 + "already in the process of turning the screen on.");
962 return;
Jeff Brownff204712011-10-25 21:27:54 -0700963 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700964
965 if (count == 2) {
966 powerMultiPressAction(eventTime, interactive, mDoublePressOnPowerBehavior);
967 } else if (count == 3) {
968 powerMultiPressAction(eventTime, interactive, mTriplePressOnPowerBehavior);
Bryce Leed9268e32014-11-17 17:40:59 -0800969 } else if (interactive && !mBeganFromNonInteractive) {
Jeff Brown13f00f02014-10-31 14:45:50 -0700970 switch (mShortPressOnPowerBehavior) {
971 case SHORT_PRESS_POWER_NOTHING:
972 break;
973 case SHORT_PRESS_POWER_GO_TO_SLEEP:
974 mPowerManager.goToSleep(eventTime,
975 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
976 break;
977 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP:
978 mPowerManager.goToSleep(eventTime,
979 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
980 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
981 break;
982 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME:
983 mPowerManager.goToSleep(eventTime,
984 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
985 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
986 launchHomeFromHotKey();
987 break;
Bryce Lee01b0c5f2015-02-05 18:24:04 -0800988 case SHORT_PRESS_POWER_GO_HOME:
989 launchHomeFromHotKey();
990 break;
Jeff Brown13f00f02014-10-31 14:45:50 -0700991 }
992 }
993 }
994
995 private void powerMultiPressAction(long eventTime, boolean interactive, int behavior) {
996 switch (behavior) {
997 case MULTI_PRESS_POWER_NOTHING:
998 break;
999 case MULTI_PRESS_POWER_THEATER_MODE:
1000 if (isTheaterModeEnabled()) {
1001 Slog.i(TAG, "Toggling theater mode off.");
1002 Settings.Global.putInt(mContext.getContentResolver(),
1003 Settings.Global.THEATER_MODE_ON, 0);
1004 if (!interactive) {
1005 wakeUpFromPowerKey(eventTime);
1006 }
1007 } else {
1008 Slog.i(TAG, "Toggling theater mode on.");
1009 Settings.Global.putInt(mContext.getContentResolver(),
1010 Settings.Global.THEATER_MODE_ON, 1);
Bryce Lee55e846d2014-11-04 12:43:44 -08001011
1012 if (mGoToSleepOnButtonPressTheaterMode && interactive) {
Jeff Brown13f00f02014-10-31 14:45:50 -07001013 mPowerManager.goToSleep(eventTime,
1014 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
1015 }
1016 }
1017 break;
1018 case MULTI_PRESS_POWER_BRIGHTNESS_BOOST:
Jeff Brown7b5be5e2014-11-12 18:45:31 -08001019 Slog.i(TAG, "Starting brightness boost.");
1020 if (!interactive) {
1021 wakeUpFromPowerKey(eventTime);
1022 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001023 mPowerManager.boostScreenBrightness(eventTime);
1024 break;
1025 }
1026 }
1027
1028 private int getMaxMultiPressPowerCount() {
1029 if (mTriplePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) {
1030 return 3;
1031 }
1032 if (mDoublePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) {
1033 return 2;
1034 }
1035 return 1;
1036 }
1037
1038 private void powerLongPress() {
1039 final int behavior = getResolvedLongPressOnPowerBehavior();
1040 switch (behavior) {
1041 case LONG_PRESS_POWER_NOTHING:
1042 break;
1043 case LONG_PRESS_POWER_GLOBAL_ACTIONS:
1044 mPowerKeyHandled = true;
1045 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
1046 performAuditoryFeedbackForAccessibilityIfNeed();
1047 }
1048 showGlobalActionsInternal();
1049 break;
1050 case LONG_PRESS_POWER_SHUT_OFF:
1051 case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM:
1052 mPowerKeyHandled = true;
1053 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
1054 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
1055 mWindowManagerFuncs.shutdown(behavior == LONG_PRESS_POWER_SHUT_OFF);
1056 break;
1057 }
1058 }
1059
1060 private int getResolvedLongPressOnPowerBehavior() {
1061 if (FactoryTest.isLongPressOnPowerOffEnabled()) {
1062 return LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM;
1063 }
1064 return mLongPressOnPowerBehavior;
1065 }
1066
1067 private boolean hasLongPressOnPowerBehavior() {
1068 return getResolvedLongPressOnPowerBehavior() != LONG_PRESS_POWER_NOTHING;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001069 }
1070
1071 private void interceptScreenshotChord() {
Christopher Tatee90585f2012-03-05 18:56:25 -08001072 if (mScreenshotChordEnabled
Jeff Brown13f00f02014-10-31 14:45:50 -07001073 && mScreenshotChordVolumeDownKeyTriggered && mScreenshotChordPowerKeyTriggered
1074 && !mScreenshotChordVolumeUpKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001075 final long now = SystemClock.uptimeMillis();
Jeff Brown13f00f02014-10-31 14:45:50 -07001076 if (now <= mScreenshotChordVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS
1077 && now <= mScreenshotChordPowerKeyTime
1078 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) {
1079 mScreenshotChordVolumeDownKeyConsumed = true;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001080 cancelPendingPowerKeyAction();
1081
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001082 mHandler.postDelayed(mScreenshotRunnable, getScreenshotChordLongPressDelay());
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001083 }
1084 }
1085 }
1086
Winson Chung1cea2f32012-10-08 20:42:01 -07001087 private long getScreenshotChordLongPressDelay() {
Jim Miller5ecd8112013-01-09 18:50:26 -08001088 if (mKeyguardDelegate.isShowing()) {
Winson Chung1cea2f32012-10-08 20:42:01 -07001089 // Double the time it takes to take a screenshot from the keyguard
1090 return (long) (KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER *
Justin Kohfeabd2c2014-05-02 10:02:44 -07001091 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Winson Chung1cea2f32012-10-08 20:42:01 -07001092 }
Justin Kohfeabd2c2014-05-02 10:02:44 -07001093 return ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout();
Winson Chung1cea2f32012-10-08 20:42:01 -07001094 }
1095
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001096 private void cancelPendingScreenshotChordAction() {
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001097 mHandler.removeCallbacks(mScreenshotRunnable);
Jeff Brown4d396052010-10-29 21:50:21 -07001098 }
1099
Jeff Brown13f00f02014-10-31 14:45:50 -07001100 private final Runnable mEndCallLongPress = new Runnable() {
Craig Mautnerf1b67412012-09-19 13:18:29 -07001101 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001102 public void run() {
Jeff Brown13f00f02014-10-31 14:45:50 -07001103 mEndCallKeyHandled = true;
1104 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
1105 performAuditoryFeedbackForAccessibilityIfNeed();
Joe Onoratod208e702010-10-08 16:22:43 -04001106 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001107 showGlobalActionsInternal();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001108 }
1109 };
1110
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001111 private final Runnable mScreenshotRunnable = new Runnable() {
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001112 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001113 public void run() {
1114 takeScreenshot();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001115 }
1116 };
1117
Alan Viverettee34560b22014-07-10 14:50:06 -07001118 @Override
1119 public void showGlobalActions() {
1120 mHandler.removeMessages(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
1121 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
1122 }
1123
1124 void showGlobalActionsInternal() {
1125 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001126 if (mGlobalActions == null) {
Jeff Brown7304c342012-05-11 18:42:42 -07001127 mGlobalActions = new GlobalActions(mContext, mWindowManagerFuncs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001128 }
Jim Millerab954542014-10-10 18:21:49 -07001129 final boolean keyguardShowing = isKeyguardShowingAndNotOccluded();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001130 mGlobalActions.showDialog(keyguardShowing, isDeviceProvisioned());
1131 if (keyguardShowing) {
1132 // since it took two seconds of long press to bring this up,
1133 // poke the wake lock so they have some time to see the dialog.
Jim Miller25190572013-02-28 17:36:24 -08001134 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001135 }
1136 }
1137
1138 boolean isDeviceProvisioned() {
Jeff Brownbf6f6f92012-09-25 15:03:20 -07001139 return Settings.Global.getInt(
1140 mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001141 }
1142
Maurice Lam99c6e072014-04-28 18:24:28 -07001143 boolean isUserSetupComplete() {
1144 return Settings.Secure.getIntForUser(mContext.getContentResolver(),
1145 Settings.Secure.USER_SETUP_COMPLETE, 0, UserHandle.USER_CURRENT) != 0;
1146 }
1147
Jeff Brown13f00f02014-10-31 14:45:50 -07001148 private void handleShortPressOnHome() {
1149 // If there's a dream running then use home to escape the dream
1150 // but don't actually go home.
1151 if (mDreamManagerInternal != null && mDreamManagerInternal.isDreaming()) {
1152 mDreamManagerInternal.stopDream(false /*immediate*/);
1153 return;
1154 }
1155
1156 // Go home!
1157 launchHomeFromHotKey();
1158 }
1159
Patrick Dubroyece94522011-02-23 18:35:01 -08001160 private void handleLongPressOnHome() {
Joe Onorato46b0d682010-11-22 17:37:27 -08001161 if (mLongPressOnHomeBehavior != LONG_PRESS_HOME_NOTHING) {
Jeff Browncaca8812013-05-09 13:34:33 -07001162 mHomeConsumed = true;
Joe Onorato46b0d682010-11-22 17:37:27 -08001163 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
Patrick Dubroyece94522011-02-23 18:35:01 -08001164
Jeff Browncaca8812013-05-09 13:34:33 -07001165 if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI) {
1166 toggleRecentApps();
1167 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_ASSIST) {
1168 launchAssistAction();
Jim Millere6ad1a82010-08-20 19:25:39 -07001169 }
1170 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001171 }
Patrick Dubroyece94522011-02-23 18:35:01 -08001172
Jeff Browncaca8812013-05-09 13:34:33 -07001173 private void handleDoubleTapOnHome() {
1174 if (mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1175 mHomeConsumed = true;
1176 toggleRecentApps();
1177 }
1178 }
1179
1180 private final Runnable mHomeDoubleTapTimeoutRunnable = new Runnable() {
1181 @Override
1182 public void run() {
1183 if (mHomeDoubleTapPending) {
1184 mHomeDoubleTapPending = false;
Jeff Brown13f00f02014-10-31 14:45:50 -07001185 handleShortPressOnHome();
Jeff Browncaca8812013-05-09 13:34:33 -07001186 }
1187 }
1188 };
1189
Mark Renoufc1256912015-03-11 14:38:23 -04001190 private boolean isRoundWindow() {
1191 return mContext.getResources().getBoolean(com.android.internal.R.bool.config_windowIsRound)
1192 || (Build.HARDWARE.contains("goldfish")
1193 && SystemProperties.getBoolean(ViewRootImpl.PROPERTY_EMULATOR_CIRCULAR, false));
1194 }
1195
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001196 /** {@inheritDoc} */
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001197 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001198 public void init(Context context, IWindowManager windowManager,
Jeff Brown96307042012-07-27 15:51:34 -07001199 WindowManagerFuncs windowManagerFuncs) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001200 mContext = context;
1201 mWindowManager = windowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -07001202 mWindowManagerFuncs = windowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -07001203 mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class);
Jose Lima9546b202014-07-02 17:21:51 -07001204 mDreamManagerInternal = LocalServices.getService(DreamManagerInternal.class);
Mark Renoufc1256912015-03-11 14:38:23 -04001205
1206 // Init display burn-in protection
1207 boolean burnInProtectionEnabled = context.getResources().getBoolean(
1208 com.android.internal.R.bool.config_enableBurnInProtection);
1209 // Allow a system property to override this. Used by developer settings.
1210 boolean burnInProtectionDevMode =
1211 SystemProperties.getBoolean("persist.debug.force_burn_in", false);
1212 if (burnInProtectionEnabled || burnInProtectionDevMode) {
1213 final int minHorizontal;
1214 final int maxHorizontal;
1215 final int minVertical;
1216 final int maxVertical;
1217 final int maxRadius;
1218 if (burnInProtectionDevMode) {
1219 minHorizontal = -8;
1220 maxHorizontal = 8;
1221 minVertical = -8;
1222 maxVertical = -4;
1223 maxRadius = (isRoundWindow()) ? 6 : -1;
1224 } else {
1225 Resources resources = context.getResources();
1226 minHorizontal = resources.getInteger(
1227 com.android.internal.R.integer.config_burnInProtectionMinHorizontalOffset);
1228 maxHorizontal = resources.getInteger(
1229 com.android.internal.R.integer.config_burnInProtectionMaxHorizontalOffset);
1230 minVertical = resources.getInteger(
1231 com.android.internal.R.integer.config_burnInProtectionMinVerticalOffset);
1232 maxVertical = resources.getInteger(
1233 com.android.internal.R.integer.config_burnInProtectionMaxVerticalOffset);
1234 maxRadius = resources.getInteger(
1235 com.android.internal.R.integer.config_burnInProtectionMaxRadius);
1236 }
1237 mBurnInProtectionHelper = new BurnInProtectionHelper(
1238 context, minHorizontal, maxHorizontal, minVertical, maxVertical, maxRadius);
Filip Gruszczynskicfb31852015-02-25 21:47:12 +00001239 }
Craig Mautner8a0da012014-05-31 15:13:37 -07001240
Jeff Brown70825162012-03-28 17:27:48 -07001241 mHandler = new PolicyHandler();
Jeff Browna20dda42014-05-27 20:57:24 -07001242 mWakeGestureListener = new MyWakeGestureListener(mContext, mHandler);
Craig Mautnereee29c42013-01-17 14:44:34 -08001243 mOrientationListener = new MyOrientationListener(mContext, mHandler);
Jeff Brownc0347aa2011-09-23 17:26:09 -07001244 try {
1245 mOrientationListener.setCurrentRotation(windowManager.getRotation());
1246 } catch (RemoteException ex) { }
Christopher Tate5e08af02012-09-21 17:17:22 -07001247 mSettingsObserver = new SettingsObserver(mHandler);
1248 mSettingsObserver.observe();
Svetoslav683914b2015-01-15 14:22:26 -08001249 mShortcutManager = new ShortcutManager(context);
Daniel Sandler6396c722013-04-16 20:19:09 -04001250 mUiMode = context.getResources().getInteger(
1251 com.android.internal.R.integer.config_defaultUiModeType);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001252 mHomeIntent = new Intent(Intent.ACTION_MAIN, null);
1253 mHomeIntent.addCategory(Intent.CATEGORY_HOME);
1254 mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1255 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07001256 mCarDockIntent = new Intent(Intent.ACTION_MAIN, null);
1257 mCarDockIntent.addCategory(Intent.CATEGORY_CAR_DOCK);
1258 mCarDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1259 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
1260 mDeskDockIntent = new Intent(Intent.ACTION_MAIN, null);
1261 mDeskDockIntent.addCategory(Intent.CATEGORY_DESK_DOCK);
1262 mDeskDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1263 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Jim Millere6ad1a82010-08-20 19:25:39 -07001264
Jeff Brown96307042012-07-27 15:51:34 -07001265 mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
1266 mBroadcastWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001267 "PhoneWindowManager.mBroadcastWakeLock");
Jeff Brown13f00f02014-10-31 14:45:50 -07001268 mPowerKeyWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
1269 "PhoneWindowManager.mPowerKeyWakeLock");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001270 mEnableShiftMenuBugReports = "1".equals(SystemProperties.get("ro.debuggable"));
Jeff Brownbcdfc622014-03-06 19:13:04 -08001271 mSupportAutoRotation = mContext.getResources().getBoolean(
1272 com.android.internal.R.bool.config_supportAutoRotation);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001273 mLidOpenRotation = readRotation(
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001274 com.android.internal.R.integer.config_lidOpenRotation);
1275 mCarDockRotation = readRotation(
1276 com.android.internal.R.integer.config_carDockRotation);
1277 mDeskDockRotation = readRotation(
1278 com.android.internal.R.integer.config_deskDockRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001279 mUndockedHdmiRotation = readRotation(
1280 com.android.internal.R.integer.config_undockedHdmiRotation);
Mike Lockwoode9867d22009-09-20 01:59:02 -04001281 mCarDockEnablesAccelerometer = mContext.getResources().getBoolean(
1282 com.android.internal.R.bool.config_carDockEnablesAccelerometer);
1283 mDeskDockEnablesAccelerometer = mContext.getResources().getBoolean(
1284 com.android.internal.R.bool.config_deskDockEnablesAccelerometer);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001285 mLidKeyboardAccessibility = mContext.getResources().getInteger(
1286 com.android.internal.R.integer.config_lidKeyboardAccessibility);
1287 mLidNavigationAccessibility = mContext.getResources().getInteger(
1288 com.android.internal.R.integer.config_lidNavigationAccessibility);
Jeff Brownc458ce92012-04-30 14:58:40 -07001289 mLidControlsSleep = mContext.getResources().getBoolean(
1290 com.android.internal.R.bool.config_lidControlsSleep);
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04001291 mTranslucentDecorEnabled = mContext.getResources().getBoolean(
1292 com.android.internal.R.bool.config_enableTranslucentDecor);
Bryce Lee584a4452014-10-21 15:55:55 -07001293
1294 mAllowTheaterModeWakeFromKey = mContext.getResources().getBoolean(
1295 com.android.internal.R.bool.config_allowTheaterModeWakeFromKey);
1296 mAllowTheaterModeWakeFromPowerKey = mAllowTheaterModeWakeFromKey
1297 || mContext.getResources().getBoolean(
1298 com.android.internal.R.bool.config_allowTheaterModeWakeFromPowerKey);
1299 mAllowTheaterModeWakeFromMotion = mContext.getResources().getBoolean(
1300 com.android.internal.R.bool.config_allowTheaterModeWakeFromMotion);
Bryce Lee812d7022014-11-10 13:33:28 -08001301 mAllowTheaterModeWakeFromMotionWhenNotDreaming = mContext.getResources().getBoolean(
1302 com.android.internal.R.bool.config_allowTheaterModeWakeFromMotionWhenNotDreaming);
Bryce Lee584a4452014-10-21 15:55:55 -07001303 mAllowTheaterModeWakeFromCameraLens = mContext.getResources().getBoolean(
1304 com.android.internal.R.bool.config_allowTheaterModeWakeFromCameraLens);
1305 mAllowTheaterModeWakeFromLidSwitch = mContext.getResources().getBoolean(
1306 com.android.internal.R.bool.config_allowTheaterModeWakeFromLidSwitch);
1307 mAllowTheaterModeWakeFromWakeGesture = mContext.getResources().getBoolean(
1308 com.android.internal.R.bool.config_allowTheaterModeWakeFromGesture);
1309
Bryce Lee55e846d2014-11-04 12:43:44 -08001310 mGoToSleepOnButtonPressTheaterMode = mContext.getResources().getBoolean(
1311 com.android.internal.R.bool.config_goToSleepOnButtonPressTheaterMode);
1312
Bryce Leed3b28402015-03-09 15:49:13 +00001313 mSupportLongPressPowerWhenNonInteractive = mContext.getResources().getBoolean(
1314 com.android.internal.R.bool.config_supportLongPressPowerWhenNonInteractive);
1315
Jeff Brown13f00f02014-10-31 14:45:50 -07001316 mShortPressOnPowerBehavior = mContext.getResources().getInteger(
1317 com.android.internal.R.integer.config_shortPressOnPowerBehavior);
1318 mLongPressOnPowerBehavior = mContext.getResources().getInteger(
1319 com.android.internal.R.integer.config_longPressOnPowerBehavior);
1320 mDoublePressOnPowerBehavior = mContext.getResources().getInteger(
1321 com.android.internal.R.integer.config_doublePressOnPowerBehavior);
1322 mTriplePressOnPowerBehavior = mContext.getResources().getInteger(
1323 com.android.internal.R.integer.config_triplePressOnPowerBehavior);
1324
John Spurlock61560172015-02-06 19:46:04 -05001325 mUseTvRouting = AudioSystem.getPlatformType(mContext) == AudioSystem.PLATFORM_TELEVISION;
RoboErik001c59c2015-01-26 15:53:51 -08001326
Jeff Brownf71343d2013-05-31 17:59:11 -07001327 readConfigurationDependentBehaviors();
Jeff Browncaca8812013-05-09 13:34:33 -07001328
Svetoslav8e3feb12014-02-24 13:46:47 -08001329 mAccessibilityManager = (AccessibilityManager) context.getSystemService(
1330 Context.ACCESSIBILITY_SERVICE);
1331
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001332 // register for dock events
Dianne Hackborn78968392010-03-04 20:47:56 -08001333 IntentFilter filter = new IntentFilter();
1334 filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE);
1335 filter.addAction(UiModeManager.ACTION_EXIT_CAR_MODE);
1336 filter.addAction(UiModeManager.ACTION_ENTER_DESK_MODE);
1337 filter.addAction(UiModeManager.ACTION_EXIT_DESK_MODE);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001338 filter.addAction(Intent.ACTION_DOCK_EVENT);
1339 Intent intent = context.registerReceiver(mDockReceiver, filter);
1340 if (intent != null) {
1341 // Retrieve current sticky dock event broadcast.
1342 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
1343 Intent.EXTRA_DOCK_STATE_UNDOCKED);
1344 }
Daniel Sandler7e37df52011-11-16 22:08:23 -08001345
Jeff Brown6aaf2952012-10-05 16:01:08 -07001346 // register for dream-related broadcasts
1347 filter = new IntentFilter();
1348 filter.addAction(Intent.ACTION_DREAMING_STARTED);
1349 filter.addAction(Intent.ACTION_DREAMING_STOPPED);
1350 context.registerReceiver(mDreamReceiver, filter);
1351
Christopher Tate5e08af02012-09-21 17:17:22 -07001352 // register for multiuser-relevant broadcasts
1353 filter = new IntentFilter(Intent.ACTION_USER_SWITCHED);
1354 context.registerReceiver(mMultiuserReceiver, filter);
1355
John Spurlock57306e62013-04-22 09:48:49 -04001356 // monitor for system gestures
Craig Mautner037aa8d2013-06-07 10:35:44 -07001357 mSystemGestures = new SystemGesturesPointerEventListener(context,
1358 new SystemGesturesPointerEventListener.Callbacks() {
John Spurlock57306e62013-04-22 09:48:49 -04001359 @Override
1360 public void onSwipeFromTop() {
John Spurlock04db1762013-05-13 12:46:41 -04001361 if (mStatusBar != null) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001362 requestTransientBars(mStatusBar);
John Spurlock04db1762013-05-13 12:46:41 -04001363 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04001364 }
1365 @Override
1366 public void onSwipeFromBottom() {
John Spurlock04db1762013-05-13 12:46:41 -04001367 if (mNavigationBar != null && mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001368 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001369 }
1370 }
1371 @Override
1372 public void onSwipeFromRight() {
John Spurlock04db1762013-05-13 12:46:41 -04001373 if (mNavigationBar != null && !mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001374 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001375 }
1376 }
1377 @Override
1378 public void onDebug() {
John Spurlockd67ec252013-09-05 11:31:54 -04001379 // no-op
John Spurlockad3e6cb2013-04-30 08:47:43 -04001380 }
1381 });
John Spurlockf1a36642013-10-12 17:50:42 -04001382 mImmersiveModeConfirmation = new ImmersiveModeConfirmation(mContext);
Craig Mautner037aa8d2013-06-07 10:35:44 -07001383 mWindowManagerFuncs.registerPointerEventListener(mSystemGestures);
John Spurlock32beb2c2013-03-11 10:16:47 -04001384
Jeff Brownc2346132012-04-13 01:55:38 -07001385 mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001386 mLongPressVibePattern = getLongIntArray(mContext.getResources(),
1387 com.android.internal.R.array.config_longPressVibePattern);
1388 mVirtualKeyVibePattern = getLongIntArray(mContext.getResources(),
1389 com.android.internal.R.array.config_virtualKeyVibePattern);
Amith Yamasanic33cb712010-02-10 15:21:49 -08001390 mKeyboardTapVibePattern = getLongIntArray(mContext.getResources(),
1391 com.android.internal.R.array.config_keyboardTapVibePattern);
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07001392 mClockTickVibePattern = getLongIntArray(mContext.getResources(),
1393 com.android.internal.R.array.config_clockTickVibePattern);
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07001394 mCalendarDateVibePattern = getLongIntArray(mContext.getResources(),
1395 com.android.internal.R.array.config_calendarDateVibePattern);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001396 mSafeModeDisabledVibePattern = getLongIntArray(mContext.getResources(),
1397 com.android.internal.R.array.config_safeModeDisabledVibePattern);
1398 mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(),
1399 com.android.internal.R.array.config_safeModeEnabledVibePattern);
Daniel Sandler40427442010-07-16 11:44:52 -04001400
Christopher Tatee90585f2012-03-05 18:56:25 -08001401 mScreenshotChordEnabled = mContext.getResources().getBoolean(
1402 com.android.internal.R.bool.config_enableScreenshotChord);
1403
Justin Kohd378ad72013-04-01 12:18:26 -07001404 mGlobalKeyManager = new GlobalKeyManager(mContext);
1405
Joe Onoratoea495d42011-04-06 11:41:11 -07001406 // Controls rotation and the like.
1407 initializeHdmiState();
Dianne Hackborn40011092011-09-22 13:37:48 -07001408
1409 // Match current screen state.
Craig Mautnera631d492014-08-05 15:16:01 -07001410 if (!mPowerManager.isInteractive()) {
Jeff Brown140ffc72014-05-01 15:18:00 -07001411 goingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
Dianne Hackborn40011092011-09-22 13:37:48 -07001412 }
Jorim Jaggi24bec7c2015-02-04 12:40:14 +01001413
1414 mWindowManagerInternal.registerAppTransitionListener(
1415 mStatusBarController.getAppTransitionListener());
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001416 }
1417
Jeff Brownf71343d2013-05-31 17:59:11 -07001418 /**
1419 * Read values from config.xml that may be overridden depending on
1420 * the configuration of the device.
1421 * eg. Disable long press on home goes to recents on sw600dp.
1422 */
1423 private void readConfigurationDependentBehaviors() {
1424 mLongPressOnHomeBehavior = mContext.getResources().getInteger(
1425 com.android.internal.R.integer.config_longPressOnHomeBehavior);
1426 if (mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING ||
1427 mLongPressOnHomeBehavior > LONG_PRESS_HOME_ASSIST) {
1428 mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1429 }
1430
1431 mDoubleTapOnHomeBehavior = mContext.getResources().getInteger(
1432 com.android.internal.R.integer.config_doubleTapOnHomeBehavior);
1433 if (mDoubleTapOnHomeBehavior < DOUBLE_TAP_HOME_NOTHING ||
1434 mDoubleTapOnHomeBehavior > DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1435 mDoubleTapOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1436 }
1437 }
1438
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001439 @Override
Dianne Hackborndde331c2012-08-03 14:01:57 -07001440 public void setInitialDisplaySize(Display display, int width, int height, int density) {
Jeff Brownef981a42013-08-07 14:13:37 -07001441 // This method might be called before the policy has been fully initialized
1442 // or for other displays we don't care about.
1443 if (mContext == null || display.getDisplayId() != Display.DEFAULT_DISPLAY) {
1444 return;
Dianne Hackbornc652de82013-02-15 16:32:56 -08001445 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001446 mDisplay = display;
1447
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001448 final Resources res = mContext.getResources();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001449 int shortSize, longSize;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001450 if (width > height) {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001451 shortSize = height;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001452 longSize = width;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001453 mLandscapeRotation = Surface.ROTATION_0;
1454 mSeascapeRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001455 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001456 mPortraitRotation = Surface.ROTATION_90;
1457 mUpsideDownRotation = Surface.ROTATION_270;
1458 } else {
1459 mPortraitRotation = Surface.ROTATION_270;
1460 mUpsideDownRotation = Surface.ROTATION_90;
1461 }
1462 } else {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001463 shortSize = width;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001464 longSize = height;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001465 mPortraitRotation = Surface.ROTATION_0;
1466 mUpsideDownRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001467 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001468 mLandscapeRotation = Surface.ROTATION_270;
1469 mSeascapeRotation = Surface.ROTATION_90;
1470 } else {
1471 mLandscapeRotation = Surface.ROTATION_90;
1472 mSeascapeRotation = Surface.ROTATION_270;
1473 }
1474 }
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001475
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001476 mStatusBarHeight =
1477 res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001478
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001479 // Height of the navigation bar when presented horizontally at bottom
1480 mNavigationBarHeightForRotation[mPortraitRotation] =
1481 mNavigationBarHeightForRotation[mUpsideDownRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001482 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_height);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001483 mNavigationBarHeightForRotation[mLandscapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001484 mNavigationBarHeightForRotation[mSeascapeRotation] = res.getDimensionPixelSize(
1485 com.android.internal.R.dimen.navigation_bar_height_landscape);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001486
1487 // Width of the navigation bar when presented vertically along one side
1488 mNavigationBarWidthForRotation[mPortraitRotation] =
1489 mNavigationBarWidthForRotation[mUpsideDownRotation] =
1490 mNavigationBarWidthForRotation[mLandscapeRotation] =
1491 mNavigationBarWidthForRotation[mSeascapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001492 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_width);
Daniel Sandler4a066c52012-04-20 14:49:13 -04001493
1494 // SystemUI (status bar) layout policy
Dianne Hackborndde331c2012-08-03 14:01:57 -07001495 int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / density;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001496 int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / density;
Daniel Sandler4a066c52012-04-20 14:49:13 -04001497
Devin Kimd7b12b42014-05-05 14:34:58 -07001498 // Allow the navigation bar to move on non-square small devices (phones).
1499 mNavigationBarCanMove = width != height && shortSizeDp < 600;
Daniel Sandler36412a72011-08-04 09:35:13 -04001500
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001501 mHasNavigationBar = res.getBoolean(com.android.internal.R.bool.config_showNavigationBar);
John Spurlock80f00c12013-06-13 11:10:51 -04001502 // Allow a system property to override this. Used by the emulator.
1503 // See also hasNavigationBar().
1504 String navBarOverride = SystemProperties.get("qemu.hw.mainkeys");
1505 if ("1".equals(navBarOverride)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001506 mHasNavigationBar = false;
John Spurlock80f00c12013-06-13 11:10:51 -04001507 } else if ("0".equals(navBarOverride)) {
1508 mHasNavigationBar = true;
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04001509 }
1510
Jeff Brown27f1d672012-10-17 18:32:34 -07001511 // For demo purposes, allow the rotation of the HDMI display to be controlled.
1512 // By default, HDMI locks rotation to landscape.
Erik Gilling9a41ef82011-09-26 19:21:03 -07001513 if ("portrait".equals(SystemProperties.get("persist.demo.hdmirotation"))) {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001514 mDemoHdmiRotation = mPortraitRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001515 } else {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001516 mDemoHdmiRotation = mLandscapeRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001517 }
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001518 mDemoHdmiRotationLock = SystemProperties.getBoolean("persist.demo.hdmirotationlock", false);
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001519
Chong Zhangae6119ff2014-11-11 18:54:39 -08001520 // For demo purposes, allow the rotation of the remote display to be controlled.
1521 // By default, remote display locks rotation to landscape.
1522 if ("portrait".equals(SystemProperties.get("persist.demo.remoterotation"))) {
1523 mDemoRotation = mPortraitRotation;
1524 } else {
1525 mDemoRotation = mLandscapeRotation;
1526 }
1527 mDemoRotationLock = SystemProperties.getBoolean(
1528 "persist.demo.rotationlock", false);
1529
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001530 // Only force the default orientation if the screen is xlarge, at least 960dp x 720dp, per
1531 // http://developer.android.com/guide/practices/screens_support.html#range
1532 mForceDefaultOrientation = longSizeDp >= 960 && shortSizeDp >= 720 &&
1533 res.getBoolean(com.android.internal.R.bool.config_forceDefaultOrientation) &&
1534 // For debug purposes the next line turns this feature off with:
1535 // $ adb shell setprop config.override_forced_orient true
1536 // $ adb shell wm size reset
1537 !"true".equals(SystemProperties.get("config.override_forced_orient"));
1538 }
1539
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001540 /**
1541 * @return whether the navigation bar can be hidden, e.g. the device has a
1542 * navigation bar and touch exploration is not enabled
1543 */
1544 private boolean canHideNavigationBar() {
Svetoslav8e3feb12014-02-24 13:46:47 -08001545 return mHasNavigationBar
1546 && !mAccessibilityManager.isTouchExplorationEnabled();
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001547 }
1548
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001549 @Override
1550 public boolean isDefaultOrientationForced() {
1551 return mForceDefaultOrientation;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001552 }
1553
Dianne Hackbornc652de82013-02-15 16:32:56 -08001554 @Override
1555 public void setDisplayOverscan(Display display, int left, int top, int right, int bottom) {
1556 if (display.getDisplayId() == Display.DEFAULT_DISPLAY) {
1557 mOverscanLeft = left;
1558 mOverscanTop = top;
1559 mOverscanRight = right;
1560 mOverscanBottom = bottom;
1561 }
1562 }
1563
Dianne Hackbornc777e072010-02-12 13:07:59 -08001564 public void updateSettings() {
1565 ContentResolver resolver = mContext.getContentResolver();
1566 boolean updateRotation = false;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001567 synchronized (mLock) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001568 mEndcallBehavior = Settings.System.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001569 Settings.System.END_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001570 Settings.System.END_BUTTON_BEHAVIOR_DEFAULT,
1571 UserHandle.USER_CURRENT);
1572 mIncallPowerBehavior = Settings.Secure.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001573 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001574 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT,
1575 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001576
Jeff Browna20dda42014-05-27 20:57:24 -07001577 // Configure wake gesture.
1578 boolean wakeGestureEnabledSetting = Settings.Secure.getIntForUser(resolver,
1579 Settings.Secure.WAKE_GESTURE_ENABLED, 0,
1580 UserHandle.USER_CURRENT) != 0;
1581 if (mWakeGestureEnabledSetting != wakeGestureEnabledSetting) {
1582 mWakeGestureEnabledSetting = wakeGestureEnabledSetting;
1583 updateWakeGestureListenerLp();
1584 }
1585
Jeff Brown207673cd2012-06-05 17:47:11 -07001586 // Configure rotation lock.
Christopher Tate5e08af02012-09-21 17:17:22 -07001587 int userRotation = Settings.System.getIntForUser(resolver,
1588 Settings.System.USER_ROTATION, Surface.ROTATION_0,
1589 UserHandle.USER_CURRENT);
Jeff Brown207673cd2012-06-05 17:47:11 -07001590 if (mUserRotation != userRotation) {
1591 mUserRotation = userRotation;
1592 updateRotation = true;
1593 }
Christopher Tate5e08af02012-09-21 17:17:22 -07001594 int userRotationMode = Settings.System.getIntForUser(resolver,
1595 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
Jeff Brown207673cd2012-06-05 17:47:11 -07001596 WindowManagerPolicy.USER_ROTATION_FREE :
1597 WindowManagerPolicy.USER_ROTATION_LOCKED;
1598 if (mUserRotationMode != userRotationMode) {
1599 mUserRotationMode = userRotationMode;
1600 updateRotation = true;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001601 updateOrientationListenerLp();
1602 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001603
Dianne Hackbornc777e072010-02-12 13:07:59 -08001604 if (mSystemReady) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001605 int pointerLocation = Settings.System.getIntForUser(resolver,
1606 Settings.System.POINTER_LOCATION, 0, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001607 if (mPointerLocationMode != pointerLocation) {
1608 mPointerLocationMode = pointerLocation;
Jeff Brown70825162012-03-28 17:27:48 -07001609 mHandler.sendEmptyMessage(pointerLocation != 0 ?
1610 MSG_ENABLE_POINTER_LOCATION : MSG_DISABLE_POINTER_LOCATION);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001611 }
1612 }
1613 // use screen off timeout setting as the timeout for the lockscreen
Christopher Tate5e08af02012-09-21 17:17:22 -07001614 mLockScreenTimeout = Settings.System.getIntForUser(resolver,
1615 Settings.System.SCREEN_OFF_TIMEOUT, 0, UserHandle.USER_CURRENT);
1616 String imId = Settings.Secure.getStringForUser(resolver,
1617 Settings.Secure.DEFAULT_INPUT_METHOD, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001618 boolean hasSoftInput = imId != null && imId.length() > 0;
1619 if (mHasSoftInput != hasSoftInput) {
1620 mHasSoftInput = hasSoftInput;
1621 updateRotation = true;
1622 }
John Spurlockf1a36642013-10-12 17:50:42 -04001623 if (mImmersiveModeConfirmation != null) {
John Spurlock4355a532014-02-19 09:49:25 -05001624 mImmersiveModeConfirmation.loadSetting(mCurrentUserId);
John Spurlockd67ec252013-09-05 11:31:54 -04001625 }
John Spurlockc6d1c602014-01-17 15:22:06 -05001626 PolicyControl.reloadFromSetting(mContext);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001627 }
1628 if (updateRotation) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07001629 updateRotation(true);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001630 }
Jeff Brown70825162012-03-28 17:27:48 -07001631 }
1632
Jeff Browna20dda42014-05-27 20:57:24 -07001633 private void updateWakeGestureListenerLp() {
1634 if (shouldEnableWakeGestureLp()) {
1635 mWakeGestureListener.requestWakeUpTrigger();
1636 } else {
1637 mWakeGestureListener.cancelWakeUpTrigger();
1638 }
1639 }
1640
1641 private boolean shouldEnableWakeGestureLp() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07001642 return mWakeGestureEnabledSetting && !mAwake
Jeff Browna20dda42014-05-27 20:57:24 -07001643 && (!mLidControlsSleep || mLidState != LID_CLOSED)
1644 && mWakeGestureListener.isSupported();
1645 }
1646
Jeff Brown70825162012-03-28 17:27:48 -07001647 private void enablePointerLocation() {
1648 if (mPointerLocationView == null) {
1649 mPointerLocationView = new PointerLocationView(mContext);
1650 mPointerLocationView.setPrintCoords(false);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001651 WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
1652 WindowManager.LayoutParams.MATCH_PARENT,
1653 WindowManager.LayoutParams.MATCH_PARENT);
Jeff Brown3b2b3542010-10-15 00:54:27 -07001654 lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001655 lp.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN
1656 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
1657 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1658 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
Jeff Brown90fc9052012-10-01 14:44:24 -07001659 if (ActivityManager.isHighEndGfx()) {
1660 lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
1661 lp.privateFlags |=
1662 WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED;
1663 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001664 lp.format = PixelFormat.TRANSLUCENT;
1665 lp.setTitle("PointerLocation");
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001666 WindowManager wm = (WindowManager)
Dianne Hackbornc777e072010-02-12 13:07:59 -08001667 mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Browncc4f7db2011-08-30 20:34:48 -07001668 lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL;
Jeff Brown70825162012-03-28 17:27:48 -07001669 wm.addView(mPointerLocationView, lp);
Michael Wrightc9c487e2013-11-07 18:55:09 -08001670 mWindowManagerFuncs.registerPointerEventListener(mPointerLocationView);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001671 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001672 }
Jeff Brown70825162012-03-28 17:27:48 -07001673
1674 private void disablePointerLocation() {
Jeff Brown70825162012-03-28 17:27:48 -07001675 if (mPointerLocationView != null) {
Michael Wrightc9c487e2013-11-07 18:55:09 -08001676 mWindowManagerFuncs.unregisterPointerEventListener(mPointerLocationView);
1677 WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Brown70825162012-03-28 17:27:48 -07001678 wm.removeView(mPointerLocationView);
1679 mPointerLocationView = null;
1680 }
1681 }
1682
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001683 private int readRotation(int resID) {
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001684 try {
1685 int rotation = mContext.getResources().getInteger(resID);
1686 switch (rotation) {
1687 case 0:
1688 return Surface.ROTATION_0;
1689 case 90:
1690 return Surface.ROTATION_90;
1691 case 180:
1692 return Surface.ROTATION_180;
1693 case 270:
1694 return Surface.ROTATION_270;
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001695 }
1696 } catch (Resources.NotFoundException e) {
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001697 // fall through
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001698 }
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001699 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001700 }
1701
1702 /** {@inheritDoc} */
Craig Mautner88400d32012-09-30 12:35:45 -07001703 @Override
Dianne Hackbornc2293022013-02-06 23:14:49 -08001704 public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001705 int type = attrs.type;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001706
1707 outAppOp[0] = AppOpsManager.OP_NONE;
1708
Wale Ogunwale74bf0652015-01-12 10:24:36 -08001709 if (!((type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW)
1710 || (type >= FIRST_SUB_WINDOW && type <= LAST_SUB_WINDOW)
1711 || (type >= FIRST_SYSTEM_WINDOW && type <= LAST_SYSTEM_WINDOW))) {
1712 return WindowManagerGlobal.ADD_INVALID_TYPE;
1713 }
1714
1715 if (type < FIRST_SYSTEM_WINDOW || type > LAST_SYSTEM_WINDOW) {
1716 // Window manager will make sure these are okay.
Jeff Brown98365d72012-08-19 20:30:52 -07001717 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001718 }
1719 String permission = null;
1720 switch (type) {
1721 case TYPE_TOAST:
1722 // XXX right now the app process has complete control over
1723 // this... should introduce a token to let the system
1724 // monitor/control what they are doing.
Jason Monk1c7c3192014-06-26 12:52:18 -04001725 outAppOp[0] = AppOpsManager.OP_TOAST_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001726 break;
Daniel Sandler7d276c32012-01-30 14:33:52 -05001727 case TYPE_DREAM:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001728 case TYPE_INPUT_METHOD:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001729 case TYPE_WALLPAPER:
keunyounga446bf02013-06-21 19:07:57 -07001730 case TYPE_PRIVATE_PRESENTATION:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001731 case TYPE_VOICE_INTERACTION:
Svetoslav3a5c7212014-10-14 09:54:26 -07001732 case TYPE_ACCESSIBILITY_OVERLAY:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001733 // The window manager will check these.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001734 break;
1735 case TYPE_PHONE:
1736 case TYPE_PRIORITY_PHONE:
1737 case TYPE_SYSTEM_ALERT:
1738 case TYPE_SYSTEM_ERROR:
1739 case TYPE_SYSTEM_OVERLAY:
1740 permission = android.Manifest.permission.SYSTEM_ALERT_WINDOW;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001741 outAppOp[0] = AppOpsManager.OP_SYSTEM_ALERT_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001742 break;
1743 default:
1744 permission = android.Manifest.permission.INTERNAL_SYSTEM_WINDOW;
1745 }
1746 if (permission != null) {
1747 if (mContext.checkCallingOrSelfPermission(permission)
1748 != PackageManager.PERMISSION_GRANTED) {
Jeff Brown98365d72012-08-19 20:30:52 -07001749 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001750 }
1751 }
Jeff Brown98365d72012-08-19 20:30:52 -07001752 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001753 }
Craig Mautner88400d32012-09-30 12:35:45 -07001754
1755 @Override
1756 public boolean checkShowToOwnerOnly(WindowManager.LayoutParams attrs) {
1757
1758 // If this switch statement is modified, modify the comment in the declarations of
1759 // the type in {@link WindowManager.LayoutParams} as well.
1760 switch (attrs.type) {
1761 default:
1762 // These are the windows that by default are shown only to the user that created
1763 // them. If this needs to be overridden, set
1764 // {@link WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS} in
1765 // {@link WindowManager.LayoutParams}. Note that permission
1766 // {@link android.Manifest.permission.INTERNAL_SYSTEM_WINDOW} is required as well.
1767 if ((attrs.privateFlags & PRIVATE_FLAG_SHOW_FOR_ALL_USERS) == 0) {
1768 return true;
1769 }
1770 break;
1771
1772 // These are the windows that by default are shown to all users. However, to
1773 // protect against spoofing, check permissions below.
1774 case TYPE_APPLICATION_STARTING:
1775 case TYPE_BOOT_PROGRESS:
1776 case TYPE_DISPLAY_OVERLAY:
1777 case TYPE_HIDDEN_NAV_CONSUMER:
Jim Miller5ecd8112013-01-09 18:50:26 -08001778 case TYPE_KEYGUARD_SCRIM:
Craig Mautner88400d32012-09-30 12:35:45 -07001779 case TYPE_KEYGUARD_DIALOG:
1780 case TYPE_MAGNIFICATION_OVERLAY:
1781 case TYPE_NAVIGATION_BAR:
1782 case TYPE_NAVIGATION_BAR_PANEL:
1783 case TYPE_PHONE:
1784 case TYPE_POINTER:
1785 case TYPE_PRIORITY_PHONE:
Craig Mautner88400d32012-09-30 12:35:45 -07001786 case TYPE_SEARCH_BAR:
1787 case TYPE_STATUS_BAR:
1788 case TYPE_STATUS_BAR_PANEL:
1789 case TYPE_STATUS_BAR_SUB_PANEL:
1790 case TYPE_SYSTEM_DIALOG:
Craig Mautner88400d32012-09-30 12:35:45 -07001791 case TYPE_VOLUME_OVERLAY:
keunyounga446bf02013-06-21 19:07:57 -07001792 case TYPE_PRIVATE_PRESENTATION:
Craig Mautner88400d32012-09-30 12:35:45 -07001793 break;
1794 }
1795
1796 // Check if third party app has set window to system window type.
1797 return mContext.checkCallingOrSelfPermission(
1798 android.Manifest.permission.INTERNAL_SYSTEM_WINDOW)
1799 != PackageManager.PERMISSION_GRANTED;
1800 }
1801
Craig Mautner967212c2013-04-13 21:10:58 -07001802 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001803 public void adjustWindowParamsLw(WindowManager.LayoutParams attrs) {
1804 switch (attrs.type) {
1805 case TYPE_SYSTEM_OVERLAY:
Jeff Brown3b2b3542010-10-15 00:54:27 -07001806 case TYPE_SECURE_SYSTEM_OVERLAY:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001807 // These types of windows can't receive input events.
1808 attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1809 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001810 attrs.flags &= ~WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001811 break;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001812 case TYPE_STATUS_BAR:
1813
1814 // If the Keyguard is in a hidden state (occluded by another window), we force to
1815 // remove the wallpaper and keyguard flag so that any change in-flight after setting
1816 // the keyguard as occluded wouldn't set these flags again.
1817 // See {@link #processKeyguardSetHiddenResultLw}.
1818 if (mKeyguardHidden) {
1819 attrs.flags &= ~WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
1820 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
1821 }
1822 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001823 }
Adrian Roos38502112014-04-09 21:04:11 +02001824
1825 if (attrs.type != TYPE_STATUS_BAR) {
1826 // The status bar is the only window allowed to exhibit keyguard behavior.
1827 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
1828 }
Adrian Roosea562512014-05-05 13:33:03 +02001829
1830 if (ActivityManager.isHighEndGfx()
1831 && (attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0) {
Adrian Roosf5e9b5c2014-09-10 15:27:41 +02001832 attrs.subtreeSystemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
Adrian Roosea562512014-05-05 13:33:03 +02001833 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
1834 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001835 }
RoboErik8a2cfc32014-05-16 11:19:38 -07001836
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001837 void readLidState() {
Jeff Brown2e7760e2012-04-11 15:14:55 -07001838 mLidState = mWindowManagerFuncs.getLidState();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001839 }
RoboErik8a2cfc32014-05-16 11:19:38 -07001840
Michael Wright3818c922014-09-02 13:59:07 -07001841 private void readCameraLensCoverState() {
1842 mCameraLensCoverState = mWindowManagerFuncs.getCameraLensCoverState();
1843 }
1844
Jeff Browndaa37532012-05-01 15:54:03 -07001845 private boolean isHidden(int accessibilityMode) {
1846 switch (accessibilityMode) {
1847 case 1:
1848 return mLidState == LID_CLOSED;
1849 case 2:
1850 return mLidState == LID_OPEN;
1851 default:
1852 return false;
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001853 }
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001854 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001855
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001856 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07001857 @Override
Jeff Browndaa37532012-05-01 15:54:03 -07001858 public void adjustConfigurationLw(Configuration config, int keyboardPresence,
1859 int navigationPresence) {
1860 mHaveBuiltInKeyboard = (keyboardPresence & PRESENCE_INTERNAL) != 0;
1861
Jeff Brownf71343d2013-05-31 17:59:11 -07001862 readConfigurationDependentBehaviors();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001863 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07001864 applyLidSwitchState();
Jeff Brownd04a88c2011-01-16 14:05:47 -08001865
Jeff Browndaa37532012-05-01 15:54:03 -07001866 if (config.keyboard == Configuration.KEYBOARD_NOKEYS
1867 || (keyboardPresence == PRESENCE_INTERNAL
1868 && isHidden(mLidKeyboardAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001869 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_YES;
Jeff Browndaa37532012-05-01 15:54:03 -07001870 if (!mHasSoftInput) {
1871 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_YES;
1872 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001873 }
1874
Jeff Browndaa37532012-05-01 15:54:03 -07001875 if (config.navigation == Configuration.NAVIGATION_NONAV
1876 || (navigationPresence == PRESENCE_INTERNAL
1877 && isHidden(mLidNavigationAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001878 config.navigationHidden = Configuration.NAVIGATIONHIDDEN_YES;
Jeff Brownd04a88c2011-01-16 14:05:47 -08001879 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001880 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001881
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001882 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07001883 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001884 public int windowTypeToLayerLw(int type) {
1885 if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001886 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001887 }
1888 switch (type) {
keunyounga446bf02013-06-21 19:07:57 -07001889 case TYPE_PRIVATE_PRESENTATION:
1890 return 2;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001891 case TYPE_WALLPAPER:
1892 // wallpaper is at the bottom, though the window manager may move it.
1893 return 2;
1894 case TYPE_PHONE:
1895 return 3;
1896 case TYPE_SEARCH_BAR:
1897 return 4;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001898 case TYPE_VOICE_INTERACTION:
1899 // voice interaction layer is almost immediately above apps.
1900 return 5;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001901 case TYPE_SYSTEM_DIALOG:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001902 return 6;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001903 case TYPE_TOAST:
1904 // toasts and the plugged-in battery thing
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001905 return 7;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001906 case TYPE_PRIORITY_PHONE:
1907 // SIM errors and unlock. Not sure if this really should be in a high layer.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001908 return 8;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001909 case TYPE_DREAM:
1910 // used for Dreams (screensavers with TYPE_DREAM windows)
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001911 return 9;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001912 case TYPE_SYSTEM_ALERT:
1913 // like the ANR / app crashed dialogs
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001914 return 10;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001915 case TYPE_INPUT_METHOD:
1916 // on-screen keyboards and other such input method user interfaces go here.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001917 return 11;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001918 case TYPE_INPUT_METHOD_DIALOG:
1919 // on-screen keyboards and other such input method user interfaces go here.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001920 return 12;
Jim Miller5ecd8112013-01-09 18:50:26 -08001921 case TYPE_KEYGUARD_SCRIM:
1922 // the safety window that shows behind keyguard while keyguard is starting
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001923 return 13;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001924 case TYPE_STATUS_BAR_SUB_PANEL:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001925 return 14;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001926 case TYPE_STATUS_BAR:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001927 return 15;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001928 case TYPE_STATUS_BAR_PANEL:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001929 return 16;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001930 case TYPE_KEYGUARD_DIALOG:
1931 return 17;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001932 case TYPE_VOLUME_OVERLAY:
1933 // the on-screen volume indicator and controller shown when the user
1934 // changes the device volume
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001935 return 18;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001936 case TYPE_SYSTEM_OVERLAY:
1937 // the on-screen volume indicator and controller shown when the user
1938 // changes the device volume
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001939 return 19;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001940 case TYPE_NAVIGATION_BAR:
1941 // the navigation bar, if available, shows atop most things
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001942 return 20;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001943 case TYPE_NAVIGATION_BAR_PANEL:
1944 // some panels (e.g. search) need to show on top of the navigation bar
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001945 return 21;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001946 case TYPE_SYSTEM_ERROR:
1947 // system-level error dialogs
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001948 return 22;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001949 case TYPE_MAGNIFICATION_OVERLAY:
1950 // used to highlight the magnified portion of a display
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001951 return 23;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001952 case TYPE_DISPLAY_OVERLAY:
1953 // used to simulate secondary display devices
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001954 return 24;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001955 case TYPE_DRAG:
1956 // the drag layer: input for drag-and-drop is associated with this window,
1957 // which sits above all other focusable windows
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001958 return 25;
Svetoslav3a5c7212014-10-14 09:54:26 -07001959 case TYPE_ACCESSIBILITY_OVERLAY:
1960 // overlay put by accessibility services to intercept user interaction
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001961 return 26;
Svetoslav3a5c7212014-10-14 09:54:26 -07001962 case TYPE_SECURE_SYSTEM_OVERLAY:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001963 return 27;
Svetoslav3a5c7212014-10-14 09:54:26 -07001964 case TYPE_BOOT_PROGRESS:
1965 return 28;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001966 case TYPE_POINTER:
1967 // the (mouse) pointer layer
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001968 return 29;
Svetoslav3a5c7212014-10-14 09:54:26 -07001969 case TYPE_HIDDEN_NAV_CONSUMER:
1970 return 30;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001971 }
1972 Log.e(TAG, "Unknown window type: " + type);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001973 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001974 }
1975
1976 /** {@inheritDoc} */
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001977 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001978 public int subWindowTypeToLayerLw(int type) {
1979 switch (type) {
1980 case TYPE_APPLICATION_PANEL:
1981 case TYPE_APPLICATION_ATTACHED_DIALOG:
1982 return APPLICATION_PANEL_SUBLAYER;
1983 case TYPE_APPLICATION_MEDIA:
1984 return APPLICATION_MEDIA_SUBLAYER;
Dianne Hackborn5cb8d792009-05-21 17:34:15 -07001985 case TYPE_APPLICATION_MEDIA_OVERLAY:
1986 return APPLICATION_MEDIA_OVERLAY_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001987 case TYPE_APPLICATION_SUB_PANEL:
1988 return APPLICATION_SUB_PANEL_SUBLAYER;
1989 }
1990 Log.e(TAG, "Unknown sub-window type: " + type);
1991 return 0;
1992 }
1993
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001994 @Override
Dianne Hackbornabe0da02009-09-18 01:55:39 -07001995 public int getMaxWallpaperLayer() {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001996 return windowTypeToLayerLw(TYPE_STATUS_BAR);
Dianne Hackbornabe0da02009-09-18 01:55:39 -07001997 }
1998
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001999 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002000 public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07002001 if (mHasNavigationBar) {
2002 // For a basic navigation bar, when we are in landscape mode we place
2003 // the navigation bar to the side.
Daniel Sandler4a066c52012-04-20 14:49:13 -04002004 if (mNavigationBarCanMove && fullWidth > fullHeight) {
2005 return fullWidth - mNavigationBarWidthForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07002006 }
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002007 }
2008 return fullWidth;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002009 }
2010
Jose Lima9546b202014-07-02 17:21:51 -07002011 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002012 public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07002013 if (mHasNavigationBar) {
2014 // For a basic navigation bar, when we are in portrait mode we place
2015 // the navigation bar to the bottom.
Daniel Sandler4a066c52012-04-20 14:49:13 -04002016 if (!mNavigationBarCanMove || fullWidth < fullHeight) {
2017 return fullHeight - mNavigationBarHeightForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07002018 }
2019 }
2020 return fullHeight;
Dianne Hackborn69cb8752011-05-19 18:13:32 -07002021 }
2022
Jose Lima9546b202014-07-02 17:21:51 -07002023 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002024 public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation) {
2025 return getNonDecorDisplayWidth(fullWidth, fullHeight, rotation);
Dianne Hackborn69cb8752011-05-19 18:13:32 -07002026 }
2027
Jose Lima9546b202014-07-02 17:21:51 -07002028 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002029 public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation) {
John Spurlock80f00c12013-06-13 11:10:51 -04002030 // There is a separate status bar at the top of the display. We don't count that as part
2031 // of the fixed decor, since it can hide; however, for purposes of configurations,
Dianne Hackborn077ee852012-04-09 16:27:07 -07002032 // we do want to exclude it since applications can't generally use that part
2033 // of the screen.
John Spurlock80f00c12013-06-13 11:10:51 -04002034 return getNonDecorDisplayHeight(fullWidth, fullHeight, rotation) - mStatusBarHeight;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002035 }
2036
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002037 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07002038 public boolean isForceHiding(WindowManager.LayoutParams attrs) {
2039 return (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 ||
Jim Millerab954542014-10-10 18:21:49 -07002040 (isKeyguardHostWindow(attrs) &&
2041 (mKeyguardDelegate != null && mKeyguardDelegate.isShowing())) ||
Adrian Roos69e510d2014-07-13 14:57:59 +02002042 (attrs.type == TYPE_KEYGUARD_SCRIM);
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002043 }
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002044
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002045 @Override
Jorim Jaggi0d674622014-05-21 01:34:15 +02002046 public boolean isKeyguardHostWindow(WindowManager.LayoutParams attrs) {
2047 return attrs.type == TYPE_STATUS_BAR;
2048 }
2049
2050 @Override
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002051 public boolean canBeForceHidden(WindowState win, WindowManager.LayoutParams attrs) {
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002052 switch (attrs.type) {
2053 case TYPE_STATUS_BAR:
2054 case TYPE_NAVIGATION_BAR:
2055 case TYPE_WALLPAPER:
2056 case TYPE_DREAM:
Jim Miller5ecd8112013-01-09 18:50:26 -08002057 case TYPE_KEYGUARD_SCRIM:
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002058 return false;
2059 default:
2060 return true;
2061 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002062 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002063
Craig Mautner7d7808f2014-09-11 18:02:38 -07002064 @Override
2065 public WindowState getWinShowWhenLockedLw() {
2066 return mWinShowWhenLocked;
2067 }
2068
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002069 /** {@inheritDoc} */
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002070 @Override
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07002071 public View addStartingWindow(IBinder appToken, String packageName, int theme,
2072 CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes,
Adam Powell04fe6eb2013-05-31 14:39:48 -07002073 int icon, int logo, int windowFlags) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002074 if (!SHOW_STARTING_ANIMATIONS) {
2075 return null;
2076 }
2077 if (packageName == null) {
2078 return null;
2079 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002080
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002081 WindowManager wm = null;
2082 View view = null;
2083
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002084 try {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002085 Context context = mContext;
Craig Mautner6fbda632012-07-03 09:26:39 -07002086 if (DEBUG_STARTING_WINDOW) Slog.d(TAG, "addStartingWindow " + packageName
2087 + ": nonLocalizedLabel=" + nonLocalizedLabel + " theme="
2088 + Integer.toHexString(theme));
Dianne Hackborn247fe742011-01-08 17:25:57 -08002089 if (theme != context.getThemeResId() || labelRes != 0) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002090 try {
2091 context = context.createPackageContext(packageName, 0);
Dianne Hackborn247fe742011-01-08 17:25:57 -08002092 context.setTheme(theme);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002093 } catch (PackageManager.NameNotFoundException e) {
2094 // Ignore
2095 }
2096 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002097
Jorim Jaggib10e33f2015-02-04 21:57:40 +01002098 Window win = new PhoneWindow(context);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002099 final TypedArray ta = win.getWindowStyle();
2100 if (ta.getBoolean(
2101 com.android.internal.R.styleable.Window_windowDisablePreview, false)
2102 || ta.getBoolean(
2103 com.android.internal.R.styleable.Window_windowShowWallpaper,false)) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002104 return null;
2105 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002106
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002107 Resources r = context.getResources();
2108 win.setTitle(r.getText(labelRes, nonLocalizedLabel));
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002109
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002110 win.setType(
2111 WindowManager.LayoutParams.TYPE_APPLICATION_STARTING);
2112 // Force the window flags: this is a fake window, so it is not really
2113 // touchable or focusable by the user. We also add in the ALT_FOCUSABLE_IM
2114 // flag because we do know that the next window will take input
2115 // focus, so we want to get the IME window up on top of us right away.
2116 win.setFlags(
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08002117 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002118 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
2119 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
2120 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08002121 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002122 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
2123 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
2124 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002125
Adam Powell04fe6eb2013-05-31 14:39:48 -07002126 win.setDefaultIcon(icon);
2127 win.setDefaultLogo(logo);
2128
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002129 win.setLayout(WindowManager.LayoutParams.MATCH_PARENT,
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07002130 WindowManager.LayoutParams.MATCH_PARENT);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002131
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002132 final WindowManager.LayoutParams params = win.getAttributes();
2133 params.token = appToken;
2134 params.packageName = packageName;
2135 params.windowAnimations = win.getWindowStyle().getResourceId(
2136 com.android.internal.R.styleable.Window_windowAnimationStyle, 0);
John Reck61375a82014-09-18 19:27:48 +00002137 params.privateFlags |=
2138 WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED;
Craig Mautner88400d32012-09-30 12:35:45 -07002139 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
Adam Lesinski95c42972013-10-02 10:13:27 -07002140
2141 if (!compatInfo.supportsScreen()) {
2142 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
2143 }
2144
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002145 params.setTitle("Starting " + packageName);
2146
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002147 wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
2148 view = win.getDecorView();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002149
2150 if (win.isFloating()) {
2151 // Whoops, there is no way to display an animation/preview
2152 // of such a thing! After all that work... let's skip it.
2153 // (Note that we must do this here because it is in
2154 // getDecorView() where the theme is evaluated... maybe
2155 // we should peek the floating attribute from the theme
2156 // earlier.)
2157 return null;
2158 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002159
Craig Mautner6fbda632012-07-03 09:26:39 -07002160 if (DEBUG_STARTING_WINDOW) Slog.d(
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002161 TAG, "Adding starting window for " + packageName
2162 + " / " + appToken + ": "
2163 + (view.getParent() != null ? view : null));
2164
2165 wm.addView(view, params);
2166
2167 // Only return the view if it was successfully added to the
2168 // window manager... which we can tell by it having a parent.
2169 return view.getParent() != null ? view : null;
Jeff Brown98365d72012-08-19 20:30:52 -07002170 } catch (WindowManager.BadTokenException e) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002171 // ignore
Craig Mautner42bf39e2014-02-21 16:46:22 -08002172 Log.w(TAG, appToken + " already running, starting window not displayed. " +
2173 e.getMessage());
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002174 } catch (RuntimeException e) {
2175 // don't crash if something else bad happens, for example a
2176 // failure loading resources because we are loading from an app
2177 // on external storage that has been unmounted.
2178 Log.w(TAG, appToken + " failed creating starting window", e);
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002179 } finally {
2180 if (view != null && view.getParent() == null) {
2181 Log.w(TAG, "view not successfully added to wm, removing view");
2182 wm.removeViewImmediate(view);
2183 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002184 }
2185
2186 return null;
2187 }
2188
2189 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07002190 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002191 public void removeStartingWindow(IBinder appToken, View window) {
Craig Mautner276a6eb2014-11-04 15:32:57 -08002192 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Removing starting window for " + appToken + ": "
2193 + window + " Callers=" + Debug.getCallers(4));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002194
2195 if (window != null) {
Dianne Hackborn5fd21692011-06-07 14:09:47 -07002196 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002197 wm.removeView(window);
2198 }
2199 }
2200
2201 /**
2202 * Preflight adding a window to the system.
RoboErik8a2cfc32014-05-16 11:19:38 -07002203 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002204 * Currently enforces that three window types are singletons:
2205 * <ul>
2206 * <li>STATUS_BAR_TYPE</li>
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002207 * <li>KEYGUARD_TYPE</li>
2208 * </ul>
RoboErik8a2cfc32014-05-16 11:19:38 -07002209 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002210 * @param win The window to be added
2211 * @param attrs Information about the window to be added
RoboErik8a2cfc32014-05-16 11:19:38 -07002212 *
Jeff Brown98365d72012-08-19 20:30:52 -07002213 * @return If ok, WindowManagerImpl.ADD_OKAY. If too many singletons,
2214 * WindowManagerImpl.ADD_MULTIPLE_SINGLETON
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002215 */
Jose Lima9546b202014-07-02 17:21:51 -07002216 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002217 public int prepareAddWindowLw(WindowState win, WindowManager.LayoutParams attrs) {
2218 switch (attrs.type) {
2219 case TYPE_STATUS_BAR:
Joe Onorato8bc6c512010-06-04 16:21:12 -04002220 mContext.enforceCallingOrSelfPermission(
2221 android.Manifest.permission.STATUS_BAR_SERVICE,
2222 "PhoneWindowManager");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002223 if (mStatusBar != null) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002224 if (mStatusBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07002225 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002226 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002227 }
2228 mStatusBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04002229 mStatusBarController.setWindow(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002230 break;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002231 case TYPE_NAVIGATION_BAR:
2232 mContext.enforceCallingOrSelfPermission(
2233 android.Manifest.permission.STATUS_BAR_SERVICE,
2234 "PhoneWindowManager");
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002235 if (mNavigationBar != null) {
2236 if (mNavigationBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07002237 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002238 }
2239 }
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002240 mNavigationBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04002241 mNavigationBarController.setWindow(win);
Craig Mautnereda67292013-04-28 13:50:14 -07002242 if (DEBUG_LAYOUT) Slog.i(TAG, "NAVIGATION BAR: " + mNavigationBar);
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002243 break;
Jim Millere898ac52012-04-06 17:10:57 -07002244 case TYPE_NAVIGATION_BAR_PANEL:
2245 mContext.enforceCallingOrSelfPermission(
2246 android.Manifest.permission.STATUS_BAR_SERVICE,
2247 "PhoneWindowManager");
2248 break;
Dianne Hackborn08743722009-12-21 12:16:51 -08002249 case TYPE_STATUS_BAR_PANEL:
Joe Onorato8bc6c512010-06-04 16:21:12 -04002250 mContext.enforceCallingOrSelfPermission(
2251 android.Manifest.permission.STATUS_BAR_SERVICE,
2252 "PhoneWindowManager");
Dianne Hackborn08743722009-12-21 12:16:51 -08002253 break;
Joe Onorato29fc2c92010-11-24 10:26:50 -08002254 case TYPE_STATUS_BAR_SUB_PANEL:
2255 mContext.enforceCallingOrSelfPermission(
2256 android.Manifest.permission.STATUS_BAR_SERVICE,
2257 "PhoneWindowManager");
Joe Onorato29fc2c92010-11-24 10:26:50 -08002258 break;
Jim Miller5ecd8112013-01-09 18:50:26 -08002259 case TYPE_KEYGUARD_SCRIM:
Jim Miller25190572013-02-28 17:36:24 -08002260 if (mKeyguardScrim != null) {
2261 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
2262 }
Jim Miller5ecd8112013-01-09 18:50:26 -08002263 mKeyguardScrim = win;
2264 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002265 }
Jeff Brown98365d72012-08-19 20:30:52 -07002266 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002267 }
2268
2269 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07002270 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002271 public void removeWindowLw(WindowState win) {
2272 if (mStatusBar == win) {
2273 mStatusBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04002274 mStatusBarController.setWindow(null);
Jim Millerc0b676d2013-03-22 16:11:08 -07002275 mKeyguardDelegate.showScrim();
Jim Miller5ecd8112013-01-09 18:50:26 -08002276 } else if (mKeyguardScrim == win) {
2277 Log.v(TAG, "Removing keyguard scrim");
2278 mKeyguardScrim = null;
2279 } if (mNavigationBar == win) {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002280 mNavigationBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04002281 mNavigationBarController.setWindow(null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002282 }
2283 }
2284
2285 static final boolean PRINT_ANIM = false;
RoboErik8a2cfc32014-05-16 11:19:38 -07002286
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002287 /** {@inheritDoc} */
Craig Mautner4b71aa12012-12-27 17:20:01 -08002288 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002289 public int selectAnimationLw(WindowState win, int transit) {
2290 if (PRINT_ANIM) Log.i(TAG, "selectAnimation in " + win
2291 + ": transit=" + transit);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002292 if (win == mStatusBar) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002293 boolean isKeyguard = (win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002294 if (transit == TRANSIT_EXIT
2295 || transit == TRANSIT_HIDE) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002296 return isKeyguard ? -1 : R.anim.dock_top_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002297 } else if (transit == TRANSIT_ENTER
2298 || transit == TRANSIT_SHOW) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002299 return isKeyguard ? -1 : R.anim.dock_top_enter;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002300 }
2301 } else if (win == mNavigationBar) {
2302 // This can be on either the bottom or the right.
2303 if (mNavigationBarOnBottom) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08002304 if (transit == TRANSIT_EXIT
2305 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002306 return R.anim.dock_bottom_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002307 } else if (transit == TRANSIT_ENTER
2308 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002309 return R.anim.dock_bottom_enter;
2310 }
2311 } else {
Craig Mautner4b71aa12012-12-27 17:20:01 -08002312 if (transit == TRANSIT_EXIT
2313 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002314 return R.anim.dock_right_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002315 } else if (transit == TRANSIT_ENTER
2316 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002317 return R.anim.dock_right_enter;
2318 }
2319 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08002320 }
2321
2322 if (transit == TRANSIT_PREVIEW_DONE) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002323 if (win.hasAppShownWindows()) {
2324 if (PRINT_ANIM) Log.i(TAG, "**** STARTING EXIT");
2325 return com.android.internal.R.anim.app_starting_exit;
2326 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07002327 } else if (win.getAttrs().type == TYPE_DREAM && mDreamingLockscreen
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002328 && transit == TRANSIT_ENTER) {
2329 // Special case: we are animating in a dream, while the keyguard
2330 // is shown. We don't want an animation on the dream, because
2331 // we need it shown immediately with the keyguard animating away
2332 // to reveal it.
2333 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002334 }
2335
2336 return 0;
2337 }
2338
Craig Mautner3c174372013-02-21 17:54:37 -08002339 @Override
2340 public void selectRotationAnimationLw(int anim[]) {
2341 if (PRINT_ANIM) Slog.i(TAG, "selectRotationAnimation mTopFullscreen="
2342 + mTopFullscreenOpaqueWindowState + " rotationAnimation="
2343 + (mTopFullscreenOpaqueWindowState == null ?
2344 "0" : mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation));
2345 if (mTopFullscreenOpaqueWindowState != null && mTopIsFullscreen) {
2346 switch (mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation) {
2347 case ROTATION_ANIMATION_CROSSFADE:
2348 anim[0] = R.anim.rotation_animation_xfade_exit;
2349 anim[1] = R.anim.rotation_animation_enter;
2350 break;
2351 case ROTATION_ANIMATION_JUMPCUT:
2352 anim[0] = R.anim.rotation_animation_jump_exit;
2353 anim[1] = R.anim.rotation_animation_enter;
2354 break;
2355 case ROTATION_ANIMATION_ROTATE:
2356 default:
2357 anim[0] = anim[1] = 0;
2358 break;
2359 }
2360 } else {
2361 anim[0] = anim[1] = 0;
2362 }
2363 }
2364
2365 @Override
2366 public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId,
2367 boolean forceDefault) {
2368 switch (exitAnimId) {
2369 case R.anim.rotation_animation_xfade_exit:
2370 case R.anim.rotation_animation_jump_exit:
2371 // These are the only cases that matter.
2372 if (forceDefault) {
2373 return false;
2374 }
2375 int anim[] = new int[2];
2376 selectRotationAnimationLw(anim);
2377 return (exitAnimId == anim[0] && enterAnimId == anim[1]);
2378 default:
2379 return true;
2380 }
2381 }
2382
2383 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002384 public Animation createForceHideEnterAnimation(boolean onWallpaper,
2385 boolean goingToNotificationShade) {
2386 if (goingToNotificationShade) {
2387 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_behind_enter_fade_in);
Craig Mautnerb8340802014-11-04 15:32:57 -08002388 }
Craig Mautner276a6eb2014-11-04 15:32:57 -08002389
2390 AnimationSet set = (AnimationSet) AnimationUtils.loadAnimation(mContext, onWallpaper ?
2391 R.anim.lock_screen_behind_enter_wallpaper :
2392 R.anim.lock_screen_behind_enter);
2393
2394 // TODO: Use XML interpolators when we have log interpolators available in XML.
2395 final List<Animation> animations = set.getAnimations();
2396 for (int i = animations.size() - 1; i >= 0; --i) {
2397 animations.get(i).setInterpolator(mLogDecelerateInterpolator);
2398 }
2399
2400 return set;
Jorim Jaggi76a16232014-08-08 17:00:47 +02002401 }
2402
2403
2404 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002405 public Animation createForceHideWallpaperExitAnimation(boolean goingToNotificationShade) {
2406 if (goingToNotificationShade) {
2407 return null;
2408 } else {
2409 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_wallpaper_exit);
2410 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002411 }
John Spurlockc8b46ca2013-04-08 12:59:26 -04002412
2413 private static void awakenDreams() {
2414 IDreamManager dreamManager = getDreamManager();
2415 if (dreamManager != null) {
2416 try {
2417 dreamManager.awaken();
2418 } catch (RemoteException e) {
2419 // fine, stay asleep then
2420 }
2421 }
2422 }
2423
2424 static IDreamManager getDreamManager() {
2425 return IDreamManager.Stub.asInterface(
2426 ServiceManager.checkService(DreamService.DREAM_SERVICE));
2427 }
2428
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002429 TelecomManager getTelecommService() {
2430 return (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002431 }
2432
Jeff Brown4d396052010-10-29 21:50:21 -07002433 static IAudioService getAudioService() {
2434 IAudioService audioService = IAudioService.Stub.asInterface(
2435 ServiceManager.checkService(Context.AUDIO_SERVICE));
2436 if (audioService == null) {
2437 Log.w(TAG, "Unable to find IAudioService interface.");
2438 }
2439 return audioService;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002440 }
2441
2442 boolean keyguardOn() {
Jim Millerab954542014-10-10 18:21:49 -07002443 return isKeyguardShowingAndNotOccluded() || inKeyguardRestrictedKeyInputMode();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002444 }
2445
2446 private static final int[] WINDOW_TYPES_WHERE_HOME_DOESNT_WORK = {
2447 WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
2448 WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
2449 };
2450
2451 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002452 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002453 public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002454 final boolean keyguardOn = keyguardOn();
Jeff Brown1f245102010-11-18 20:53:46 -08002455 final int keyCode = event.getKeyCode();
2456 final int repeatCount = event.getRepeatCount();
2457 final int metaState = event.getMetaState();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002458 final int flags = event.getFlags();
Jeff Brown1f245102010-11-18 20:53:46 -08002459 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
2460 final boolean canceled = event.isCanceled();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002461
Jeff Brown40013652012-05-16 21:22:36 -07002462 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002463 Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount="
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002464 + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed
2465 + " canceled=" + canceled);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002466 }
2467
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002468 // If we think we might have a volume down & power key chord on the way
2469 // but we're not sure, then tell the dispatcher to wait a little while and
2470 // try again later before dispatching.
Christopher Tatee90585f2012-03-05 18:56:25 -08002471 if (mScreenshotChordEnabled && (flags & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07002472 if (mScreenshotChordVolumeDownKeyTriggered && !mScreenshotChordPowerKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002473 final long now = SystemClock.uptimeMillis();
Jeff Brown13f00f02014-10-31 14:45:50 -07002474 final long timeoutTime = mScreenshotChordVolumeDownKeyTime
2475 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002476 if (now < timeoutTime) {
2477 return timeoutTime - now;
2478 }
2479 }
2480 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
Jeff Brown13f00f02014-10-31 14:45:50 -07002481 && mScreenshotChordVolumeDownKeyConsumed) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002482 if (!down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07002483 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002484 }
2485 return -1;
2486 }
2487 }
2488
Michael Wright6a62e552014-06-03 19:19:48 -07002489 // Cancel any pending meta actions if we see any other keys being pressed between the down
2490 // of the meta key and its corresponding up.
Michael Wright251e35d2014-08-22 15:40:27 -07002491 if (mPendingMetaAction && !KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07002492 mPendingMetaAction = false;
2493 }
2494
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002495 // First we always handle the home key here, so applications
2496 // can never break it, although if keyguard is on, we do let
2497 // it handle it, because that gives us the correct 5 second
2498 // timeout.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002499 if (keyCode == KeyEvent.KEYCODE_HOME) {
Michael Jurka7f2668c2012-03-27 07:49:52 -07002500
Jeff Brown49ed71d2010-12-06 17:13:33 -08002501 // If we have released the home key, and didn't do anything else
2502 // while it was pressed, then it is time to go home!
Michael Jurka7f2668c2012-03-27 07:49:52 -07002503 if (!down) {
Jeff Browncaca8812013-05-09 13:34:33 -07002504 cancelPreloadRecentApps();
2505
Jeff Brown49ed71d2010-12-06 17:13:33 -08002506 mHomePressed = false;
Jeff Browncaca8812013-05-09 13:34:33 -07002507 if (mHomeConsumed) {
2508 mHomeConsumed = false;
Michael Jurka7f2668c2012-03-27 07:49:52 -07002509 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002510 }
Jeff Browncaca8812013-05-09 13:34:33 -07002511
2512 if (canceled) {
2513 Log.i(TAG, "Ignoring HOME; event canceled.");
2514 return -1;
2515 }
2516
Yorke Lee4f803242014-12-15 23:22:06 +00002517 // If an incoming call is ringing, HOME is totally disabled.
2518 // (The user is already on the InCallUI at this point,
2519 // and his ONLY options are to answer or reject the call.)
2520 TelecomManager telecomManager = getTelecommService();
2521 if (telecomManager != null && telecomManager.isRinging()) {
2522 Log.i(TAG, "Ignoring HOME; there's a ringing incoming call.");
2523 return -1;
2524 }
2525
Jeff Browncaca8812013-05-09 13:34:33 -07002526 // Delay handling home if a double-tap is possible.
2527 if (mDoubleTapOnHomeBehavior != DOUBLE_TAP_HOME_NOTHING) {
2528 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); // just in case
2529 mHomeDoubleTapPending = true;
2530 mHandler.postDelayed(mHomeDoubleTapTimeoutRunnable,
2531 ViewConfiguration.getDoubleTapTimeout());
2532 return -1;
2533 }
2534
Jeff Brown13f00f02014-10-31 14:45:50 -07002535 handleShortPressOnHome();
Jeff Browncaca8812013-05-09 13:34:33 -07002536 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002537 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002538
2539 // If a system window has focus, then it doesn't make sense
2540 // right now to interact with applications.
2541 WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null;
2542 if (attrs != null) {
2543 final int type = attrs.type;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002544 if (type == WindowManager.LayoutParams.TYPE_KEYGUARD_SCRIM
2545 || type == WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG
2546 || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002547 // the "app" is keyguard, so give it the key
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002548 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002549 }
2550 final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length;
2551 for (int i=0; i<typeCount; i++) {
2552 if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) {
2553 // don't do anything, but also don't pass it to the app
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002554 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002555 }
2556 }
2557 }
Jeff Browncaca8812013-05-09 13:34:33 -07002558
2559 // Remember that home is pressed and handle special actions.
2560 if (repeatCount == 0) {
2561 mHomePressed = true;
2562 if (mHomeDoubleTapPending) {
2563 mHomeDoubleTapPending = false;
2564 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable);
2565 handleDoubleTapOnHome();
2566 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI
2567 || mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
2568 preloadRecentApps();
Michael Jurka7f2668c2012-03-27 07:49:52 -07002569 }
Jeff Browncaca8812013-05-09 13:34:33 -07002570 } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) {
2571 if (!keyguardOn) {
2572 handleLongPressOnHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002573 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002574 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002575 return -1;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002576 } else if (keyCode == KeyEvent.KEYCODE_MENU) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002577 // Hijack modified menu keys for debugging features
2578 final int chordBug = KeyEvent.META_SHIFT_ON;
2579
2580 if (down && repeatCount == 0) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002581 if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002582 Intent intent = new Intent(Intent.ACTION_BUG_REPORT);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002583 mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT,
2584 null, null, null, 0, null, null);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002585 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002586 } else if (SHOW_PROCESSES_ON_ALT_MENU &&
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002587 (metaState & KeyEvent.META_ALT_ON) == KeyEvent.META_ALT_ON) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002588 Intent service = new Intent();
2589 service.setClassName(mContext, "com.android.server.LoadAverageService");
2590 ContentResolver res = mContext.getContentResolver();
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002591 boolean shown = Settings.Global.getInt(
2592 res, Settings.Global.SHOW_PROCESSES, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002593 if (!shown) {
2594 mContext.startService(service);
2595 } else {
2596 mContext.stopService(service);
2597 }
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002598 Settings.Global.putInt(
2599 res, Settings.Global.SHOW_PROCESSES, shown ? 0 : 1);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002600 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002601 }
2602 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002603 } else if (keyCode == KeyEvent.KEYCODE_SEARCH) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002604 if (down) {
2605 if (repeatCount == 0) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002606 mSearchKeyShortcutPending = true;
2607 mConsumeSearchKeyUp = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002608 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002609 } else {
2610 mSearchKeyShortcutPending = false;
2611 if (mConsumeSearchKeyUp) {
2612 mConsumeSearchKeyUp = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002613 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002614 }
2615 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002616 return 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002617 } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) {
Michael Wrightc9ebea72013-01-16 19:25:02 -08002618 if (!keyguardOn) {
Jeff Browncaca8812013-05-09 13:34:33 -07002619 if (down && repeatCount == 0) {
2620 preloadRecentApps();
2621 } else if (!down) {
2622 toggleRecentApps();
Michael Wrightc9ebea72013-01-16 19:25:02 -08002623 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002624 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002625 return -1;
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002626 } else if (keyCode == KeyEvent.KEYCODE_ASSIST) {
2627 if (down) {
2628 if (repeatCount == 0) {
2629 mAssistKeyLongPressed = false;
2630 } else if (repeatCount == 1) {
2631 mAssistKeyLongPressed = true;
2632 if (!keyguardOn) {
2633 launchAssistLongPressAction();
2634 }
2635 }
2636 } else {
2637 if (mAssistKeyLongPressed) {
2638 mAssistKeyLongPressed = false;
2639 } else {
2640 if (!keyguardOn) {
2641 launchAssistAction();
2642 }
2643 }
2644 }
2645 return -1;
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002646 } else if (keyCode == KeyEvent.KEYCODE_VOICE_ASSIST) {
2647 if (!down) {
2648 Intent voiceIntent;
Michael Wright869a67c2014-08-26 19:33:06 -07002649 if (!keyguardOn) {
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002650 voiceIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
2651 } else {
2652 voiceIntent = new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
Michael Wright869a67c2014-08-26 19:33:06 -07002653 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, true);
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002654 }
2655 mContext.startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
2656 }
Jeff Sharkey2991fa32012-12-05 18:06:43 -08002657 } else if (keyCode == KeyEvent.KEYCODE_SYSRQ) {
2658 if (down && repeatCount == 0) {
2659 mHandler.post(mScreenshotRunnable);
2660 }
2661 return -1;
Michael Wrightb854e242013-02-05 17:54:02 -08002662 } else if (keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP
2663 || keyCode == KeyEvent.KEYCODE_BRIGHTNESS_DOWN) {
2664 if (down) {
2665 int direction = keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP ? 1 : -1;
2666
2667 // Disable autobrightness if it's on
2668 int auto = Settings.System.getIntForUser(
2669 mContext.getContentResolver(),
2670 Settings.System.SCREEN_BRIGHTNESS_MODE,
2671 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2672 UserHandle.USER_CURRENT_OR_SELF);
2673 if (auto != 0) {
2674 Settings.System.putIntForUser(mContext.getContentResolver(),
2675 Settings.System.SCREEN_BRIGHTNESS_MODE,
2676 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2677 UserHandle.USER_CURRENT_OR_SELF);
2678 }
2679
2680 int min = mPowerManager.getMinimumScreenBrightnessSetting();
2681 int max = mPowerManager.getMaximumScreenBrightnessSetting();
2682 int step = (max - min + BRIGHTNESS_STEPS - 1) / BRIGHTNESS_STEPS * direction;
2683 int brightness = Settings.System.getIntForUser(mContext.getContentResolver(),
2684 Settings.System.SCREEN_BRIGHTNESS,
2685 mPowerManager.getDefaultScreenBrightnessSetting(),
2686 UserHandle.USER_CURRENT_OR_SELF);
2687 brightness += step;
2688 // Make sure we don't go beyond the limits.
2689 brightness = Math.min(max, brightness);
2690 brightness = Math.max(min, brightness);
2691
2692 Settings.System.putIntForUser(mContext.getContentResolver(),
2693 Settings.System.SCREEN_BRIGHTNESS, brightness,
2694 UserHandle.USER_CURRENT_OR_SELF);
Alan Viverette5a399492014-07-14 16:19:38 -07002695 mContext.startActivityAsUser(new Intent(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG),
2696 UserHandle.CURRENT_OR_SELF);
Michael Wrightb854e242013-02-05 17:54:02 -08002697 }
2698 return -1;
Michael Wrightce0c13a2014-07-30 10:49:21 -07002699 } else if (KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07002700 if (down) {
2701 mPendingMetaAction = true;
2702 } else if (mPendingMetaAction) {
Michael Wright8ab940a2014-09-01 11:01:27 -07002703 launchAssistAction(Intent.EXTRA_ASSIST_INPUT_HINT_KEYBOARD);
Michael Wright6a62e552014-06-03 19:19:48 -07002704 }
2705 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002706 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002707
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002708 // Shortcuts are invoked through Search+key, so intercept those here
Jeff Browncaab4d02010-12-09 22:13:41 -08002709 // Any printing key that is chorded with Search should be consumed
2710 // even if no shortcut was invoked. This prevents text from being
2711 // inadvertently inserted when using a keyboard that has built-in macro
2712 // shortcut keys (that emit Search+x) and some of them are not registered.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002713 if (mSearchKeyShortcutPending) {
Jeff Browncaab4d02010-12-09 22:13:41 -08002714 final KeyCharacterMap kcm = event.getKeyCharacterMap();
2715 if (kcm.isPrintingKey(keyCode)) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002716 mConsumeSearchKeyUp = true;
2717 mSearchKeyShortcutPending = false;
Jeff Browncaab4d02010-12-09 22:13:41 -08002718 if (down && repeatCount == 0 && !keyguardOn) {
2719 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState);
2720 if (shortcutIntent != null) {
2721 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002722 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002723 mContext.startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002724 } catch (ActivityNotFoundException ex) {
2725 Slog.w(TAG, "Dropping shortcut key combination because "
2726 + "the activity to which it is registered was not found: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002727 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode), ex);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002728 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002729 } else {
2730 Slog.i(TAG, "Dropping unregistered shortcut key combination: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002731 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002732 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002733 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002734 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002735 }
2736 }
2737
Jeff Brown68b909d2011-12-07 16:36:01 -08002738 // Invoke shortcuts using Meta.
Jeff Brown602ab322012-05-16 13:33:47 -07002739 if (down && repeatCount == 0 && !keyguardOn
Jeff Brown68b909d2011-12-07 16:36:01 -08002740 && (metaState & KeyEvent.META_META_ON) != 0) {
2741 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brown602ab322012-05-16 13:33:47 -07002742 if (kcm.isPrintingKey(keyCode)) {
2743 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode,
2744 metaState & ~(KeyEvent.META_META_ON
2745 | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON));
2746 if (shortcutIntent != null) {
2747 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2748 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002749 mContext.startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brown602ab322012-05-16 13:33:47 -07002750 } catch (ActivityNotFoundException ex) {
2751 Slog.w(TAG, "Dropping shortcut key combination because "
2752 + "the activity to which it is registered was not found: "
2753 + "META+" + KeyEvent.keyCodeToString(keyCode), ex);
2754 }
2755 return -1;
Jeff Brown68b909d2011-12-07 16:36:01 -08002756 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002757 }
2758 }
2759
Jeff Brown6651a632011-11-28 12:59:11 -08002760 // Handle application launch keys.
Jeff Brown602ab322012-05-16 13:33:47 -07002761 if (down && repeatCount == 0 && !keyguardOn) {
Jeff Brown6651a632011-11-28 12:59:11 -08002762 String category = sApplicationLaunchKeyCategories.get(keyCode);
2763 if (category != null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -08002764 Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category);
Jeff Brown6651a632011-11-28 12:59:11 -08002765 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2766 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002767 mContext.startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brown6651a632011-11-28 12:59:11 -08002768 } catch (ActivityNotFoundException ex) {
2769 Slog.w(TAG, "Dropping application launch key because "
2770 + "the activity to which it is registered was not found: "
2771 + "keyCode=" + keyCode + ", category=" + category, ex);
2772 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002773 return -1;
Jeff Brown6651a632011-11-28 12:59:11 -08002774 }
2775 }
2776
Michael Wright61c46752014-08-21 16:57:33 -07002777 // Display task switcher for ALT-TAB.
Jeff Brown68b909d2011-12-07 16:36:01 -08002778 if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_TAB) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002779 if (mRecentAppsHeldModifiers == 0 && !keyguardOn) {
Jeff Brown68b909d2011-12-07 16:36:01 -08002780 final int shiftlessModifiers = event.getModifiers() & ~KeyEvent.META_SHIFT_MASK;
Michael Wright61c46752014-08-21 16:57:33 -07002781 if (KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_ALT_ON)) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002782 mRecentAppsHeldModifiers = shiftlessModifiers;
2783 showRecentApps(true);
Jeff Brown68b909d2011-12-07 16:36:01 -08002784 return -1;
2785 }
2786 }
Winson Chung1e8d71b2014-05-16 17:05:22 -07002787 } else if (!down && mRecentAppsHeldModifiers != 0
2788 && (metaState & mRecentAppsHeldModifiers) == 0) {
2789 mRecentAppsHeldModifiers = 0;
Winson Chungcdcd4872014-08-05 18:00:13 -07002790 hideRecentApps(true, false);
Jeff Brown68b909d2011-12-07 16:36:01 -08002791 }
2792
Jeff Browncf39bdf2012-05-18 14:41:19 -07002793 // Handle keyboard language switching.
2794 if (down && repeatCount == 0
2795 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2796 || (keyCode == KeyEvent.KEYCODE_SPACE
2797 && (metaState & KeyEvent.META_CTRL_MASK) != 0))) {
2798 int direction = (metaState & KeyEvent.META_SHIFT_MASK) != 0 ? -1 : 1;
2799 mWindowManagerFuncs.switchKeyboardLayout(event.getDeviceId(), direction);
2800 return -1;
2801 }
2802 if (mLanguageSwitchKeyPressed && !down
2803 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2804 || keyCode == KeyEvent.KEYCODE_SPACE)) {
2805 mLanguageSwitchKeyPressed = false;
2806 return -1;
2807 }
2808
Jeff Brown13f00f02014-10-31 14:45:50 -07002809 if (isValidGlobalKey(keyCode)
2810 && mGlobalKeyManager.handleGlobalKey(mContext, keyCode, event)) {
Justin Kohd378ad72013-04-01 12:18:26 -07002811 return -1;
2812 }
2813
Michael Wright6a62e552014-06-03 19:19:48 -07002814 // Reserve all the META modifier combos for system behavior
Michael Wrightce0c13a2014-07-30 10:49:21 -07002815 if ((metaState & KeyEvent.META_META_ON) != 0) {
Michael Wright6a62e552014-06-03 19:19:48 -07002816 return -1;
2817 }
2818
Jeff Brown68b909d2011-12-07 16:36:01 -08002819 // Let the application handle the key.
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002820 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002821 }
2822
Jeff Brown3915bb82010-11-05 15:02:16 -07002823 /** {@inheritDoc} */
2824 @Override
Jeff Brown49ed71d2010-12-06 17:13:33 -08002825 public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown54875002011-04-06 15:33:01 -07002826 // Note: This method is only called if the initial down was unhandled.
Jeff Brown40013652012-05-16 21:22:36 -07002827 if (DEBUG_INPUT) {
Jeff Brown1f245102010-11-18 20:53:46 -08002828 Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction()
2829 + ", flags=" + event.getFlags()
2830 + ", keyCode=" + event.getKeyCode()
2831 + ", scanCode=" + event.getScanCode()
2832 + ", metaState=" + event.getMetaState()
2833 + ", repeatCount=" + event.getRepeatCount()
2834 + ", policyFlags=" + policyFlags);
Jeff Brown3915bb82010-11-05 15:02:16 -07002835 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002836
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002837 KeyEvent fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002838 if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
2839 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002840 final int keyCode = event.getKeyCode();
2841 final int metaState = event.getMetaState();
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002842 final boolean initialDown = event.getAction() == KeyEvent.ACTION_DOWN
2843 && event.getRepeatCount() == 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002844
Jeff Brown54875002011-04-06 15:33:01 -07002845 // Check for fallback actions specified by the key character map.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002846 final FallbackAction fallbackAction;
2847 if (initialDown) {
2848 fallbackAction = kcm.getFallbackAction(keyCode, metaState);
2849 } else {
2850 fallbackAction = mFallbackActions.get(keyCode);
2851 }
2852
2853 if (fallbackAction != null) {
Jeff Brown40013652012-05-16 21:22:36 -07002854 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002855 Slog.d(TAG, "Fallback: keyCode=" + fallbackAction.keyCode
2856 + " metaState=" + Integer.toHexString(fallbackAction.metaState));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002857 }
2858
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002859 final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK;
2860 fallbackEvent = KeyEvent.obtain(
Jeff Brown49ed71d2010-12-06 17:13:33 -08002861 event.getDownTime(), event.getEventTime(),
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002862 event.getAction(), fallbackAction.keyCode,
2863 event.getRepeatCount(), fallbackAction.metaState,
Jeff Brown49ed71d2010-12-06 17:13:33 -08002864 event.getDeviceId(), event.getScanCode(),
2865 flags, event.getSource(), null);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002866
2867 if (!interceptFallback(win, fallbackEvent, policyFlags)) {
2868 fallbackEvent.recycle();
2869 fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002870 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002871
2872 if (initialDown) {
2873 mFallbackActions.put(keyCode, fallbackAction);
2874 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2875 mFallbackActions.remove(keyCode);
2876 fallbackAction.recycle();
2877 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002878 }
2879 }
2880
Jeff Brown40013652012-05-16 21:22:36 -07002881 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002882 if (fallbackEvent == null) {
2883 Slog.d(TAG, "No fallback.");
2884 } else {
2885 Slog.d(TAG, "Performing fallback: " + fallbackEvent);
2886 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002887 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002888 return fallbackEvent;
Jeff Brown3915bb82010-11-05 15:02:16 -07002889 }
2890
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002891 private boolean interceptFallback(WindowState win, KeyEvent fallbackEvent, int policyFlags) {
Jeff Brown037c33e2014-04-09 00:31:55 -07002892 int actions = interceptKeyBeforeQueueing(fallbackEvent, policyFlags);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002893 if ((actions & ACTION_PASS_TO_USER) != 0) {
2894 long delayMillis = interceptKeyBeforeDispatching(
2895 win, fallbackEvent, policyFlags);
2896 if (delayMillis == 0) {
2897 return true;
2898 }
2899 }
2900 return false;
Jeff Brown6f2fba42011-02-19 01:08:02 -08002901 }
2902
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002903 private void launchAssistLongPressAction() {
2904 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
2905 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
2906
2907 // launch the search activity
2908 Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS);
2909 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2910 try {
RoboErik8a2cfc32014-05-16 11:19:38 -07002911 // TODO: This only stops the factory-installed search manager.
Jim Miller45308b12012-06-18 19:23:39 -07002912 // Need to formalize an API to handle others
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002913 SearchManager searchManager = getSearchManager();
2914 if (searchManager != null) {
2915 searchManager.stopSearch();
2916 }
Michael Wright43e27f72013-04-10 14:06:48 -07002917 mContext.startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002918 } catch (ActivityNotFoundException e) {
2919 Slog.w(TAG, "No activity to handle assist long press action.", e);
2920 }
2921 }
2922
2923 private void launchAssistAction() {
Michael Wright8ab940a2014-09-01 11:01:27 -07002924 launchAssistAction(null);
2925 }
2926
2927 private void launchAssistAction(String hint) {
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002928 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
Amith Yamasanic1d07a42012-08-14 09:32:02 -07002929 Intent intent = ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE))
Dianne Hackbornf9c5e0f2013-01-23 14:39:13 -08002930 .getAssistIntent(mContext, true, UserHandle.USER_CURRENT);
Jim Miller45308b12012-06-18 19:23:39 -07002931 if (intent != null) {
Michael Wright8ab940a2014-09-01 11:01:27 -07002932 if (hint != null) {
2933 intent.putExtra(hint, true);
2934 }
Jim Miller45308b12012-06-18 19:23:39 -07002935 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
2936 | Intent.FLAG_ACTIVITY_SINGLE_TOP
2937 | Intent.FLAG_ACTIVITY_CLEAR_TOP);
2938 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002939 mContext.startActivityAsUser(intent, UserHandle.CURRENT);
Jim Miller45308b12012-06-18 19:23:39 -07002940 } catch (ActivityNotFoundException e) {
2941 Slog.w(TAG, "No activity to handle assist action.", e);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002942 }
2943 }
2944 }
2945
2946 private SearchManager getSearchManager() {
2947 if (mSearchManager == null) {
2948 mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
2949 }
2950 return mSearchManager;
2951 }
2952
Jeff Browncaca8812013-05-09 13:34:33 -07002953 private void preloadRecentApps() {
2954 mPreloadedRecentApps = true;
2955 try {
2956 IStatusBarService statusbar = getStatusBarService();
2957 if (statusbar != null) {
2958 statusbar.preloadRecentApps();
2959 }
2960 } catch (RemoteException e) {
2961 Slog.e(TAG, "RemoteException when preloading recent apps", e);
2962 // re-acquire status bar service next time it is needed.
2963 mStatusBarService = null;
2964 }
2965 }
2966
2967 private void cancelPreloadRecentApps() {
2968 if (mPreloadedRecentApps) {
2969 mPreloadedRecentApps = false;
2970 try {
2971 IStatusBarService statusbar = getStatusBarService();
2972 if (statusbar != null) {
2973 statusbar.cancelPreloadRecentApps();
2974 }
2975 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002976 Slog.e(TAG, "RemoteException when cancelling recent apps preload", e);
Jeff Browncaca8812013-05-09 13:34:33 -07002977 // re-acquire status bar service next time it is needed.
2978 mStatusBarService = null;
2979 }
2980 }
2981 }
2982
2983 private void toggleRecentApps() {
2984 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
Jeff Browncaca8812013-05-09 13:34:33 -07002985 try {
2986 IStatusBarService statusbar = getStatusBarService();
2987 if (statusbar != null) {
2988 statusbar.toggleRecentApps();
2989 }
2990 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002991 Slog.e(TAG, "RemoteException when toggling recent apps", e);
2992 // re-acquire status bar service next time it is needed.
2993 mStatusBarService = null;
2994 }
2995 }
2996
Craig Mautner84984fa2014-06-19 11:19:20 -07002997 @Override
2998 public void showRecentApps() {
2999 mHandler.removeMessages(MSG_DISPATCH_SHOW_RECENTS);
3000 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_RECENTS);
3001 }
3002
Winson Chung1e8d71b2014-05-16 17:05:22 -07003003 private void showRecentApps(boolean triggeredFromAltTab) {
3004 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
3005 try {
3006 IStatusBarService statusbar = getStatusBarService();
3007 if (statusbar != null) {
3008 statusbar.showRecentApps(triggeredFromAltTab);
3009 }
3010 } catch (RemoteException e) {
Jeff Browncaca8812013-05-09 13:34:33 -07003011 Slog.e(TAG, "RemoteException when showing recent apps", e);
3012 // re-acquire status bar service next time it is needed.
3013 mStatusBarService = null;
3014 }
3015 }
3016
Winson Chungcdcd4872014-08-05 18:00:13 -07003017 private void hideRecentApps(boolean triggeredFromAltTab, boolean triggeredFromHome) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003018 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
3019 try {
3020 IStatusBarService statusbar = getStatusBarService();
3021 if (statusbar != null) {
Winson Chungcdcd4872014-08-05 18:00:13 -07003022 statusbar.hideRecentApps(triggeredFromAltTab, triggeredFromHome);
Winson Chung1e8d71b2014-05-16 17:05:22 -07003023 }
3024 } catch (RemoteException e) {
3025 Slog.e(TAG, "RemoteException when closing recent apps", e);
3026 // re-acquire status bar service next time it is needed.
3027 mStatusBarService = null;
3028 }
3029 }
3030
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003031 /**
3032 * A home key -> launch home action was detected. Take the appropriate action
3033 * given the situation with the keyguard.
3034 */
3035 void launchHomeFromHotKey() {
Jim Millerab954542014-10-10 18:21:49 -07003036 if (isKeyguardShowingAndNotOccluded()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003037 // don't launch home if keyguard showing
Jim Miller5ecd8112013-01-09 18:50:26 -08003038 } else if (!mHideLockScreen && mKeyguardDelegate.isInputRestricted()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003039 // when in keyguard restricted mode, must first verify unlock
3040 // before launching home
Jim Miller5ecd8112013-01-09 18:50:26 -08003041 mKeyguardDelegate.verifyUnlock(new OnKeyguardExitResult() {
Jose Lima9546b202014-07-02 17:21:51 -07003042 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003043 public void onKeyguardExitResult(boolean success) {
3044 if (success) {
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07003045 try {
3046 ActivityManagerNative.getDefault().stopAppSwitches();
3047 } catch (RemoteException e) {
3048 }
Joe Onoratof275f0c2009-11-24 16:11:13 -05003049 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
Bryce Lee01b0c5f2015-02-05 18:24:04 -08003050 startDockOrHome(true /*fromHomeKey*/);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003051 }
3052 }
3053 });
3054 } else {
3055 // no keyguard stuff to worry about, just launch home!
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07003056 try {
3057 ActivityManagerNative.getDefault().stopAppSwitches();
3058 } catch (RemoteException e) {
3059 }
Winson Chungd543c1b2014-06-23 15:06:45 -07003060 if (mRecentsVisible) {
3061 // Hide Recents and notify it to launch Home
3062 awakenDreams();
3063 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
Winson Chungcdcd4872014-08-05 18:00:13 -07003064 hideRecentApps(false, true);
Winson Chungd543c1b2014-06-23 15:06:45 -07003065 } else {
3066 // Otherwise, just launch Home
3067 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
Bryce Lee01b0c5f2015-02-05 18:24:04 -08003068 startDockOrHome(true /*fromHomeKey*/);
Winson Chungd543c1b2014-06-23 15:06:45 -07003069 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003070 }
3071 }
3072
John Spurlock04db1762013-05-13 12:46:41 -04003073 private final Runnable mClearHideNavigationFlag = new Runnable() {
3074 @Override
3075 public void run() {
3076 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
3077 // Clear flags.
3078 mForceClearedSystemUiFlags &=
3079 ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
3080 }
3081 mWindowManagerFuncs.reevaluateStatusBarVisibility();
Dianne Hackborne26ab702011-10-16 13:21:33 -07003082 }
3083 };
3084
3085 /**
3086 * Input handler used while nav bar is hidden. Captures any touch on the screen,
3087 * to determine when the nav bar should be shown and prevent applications from
3088 * receiving those touches.
3089 */
Jeff Brown32cbc38552011-12-01 14:01:49 -08003090 final class HideNavInputEventReceiver extends InputEventReceiver {
3091 public HideNavInputEventReceiver(InputChannel inputChannel, Looper looper) {
3092 super(inputChannel, looper);
3093 }
3094
Dianne Hackborndf89e652011-10-06 22:35:11 -07003095 @Override
Jeff Brown32cbc38552011-12-01 14:01:49 -08003096 public void onInputEvent(InputEvent event) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003097 boolean handled = false;
3098 try {
Jeff Brown4952dfd2011-11-30 19:23:22 -08003099 if (event instanceof MotionEvent
3100 && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
3101 final MotionEvent motionEvent = (MotionEvent)event;
3102 if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003103 // When the user taps down, we re-show the nav bar.
3104 boolean changed = false;
John Spurlock04db1762013-05-13 12:46:41 -04003105 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003106 // Any user activity always causes us to show the
3107 // navigation controls, if they had been hidden.
3108 // We also clear the low profile and only content
3109 // flags so that tapping on the screen will atomically
3110 // restore all currently hidden screen decorations.
3111 int newVal = mResettingSystemUiFlags |
3112 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
3113 View.SYSTEM_UI_FLAG_LOW_PROFILE |
3114 View.SYSTEM_UI_FLAG_FULLSCREEN;
Dianne Hackborne26ab702011-10-16 13:21:33 -07003115 if (mResettingSystemUiFlags != newVal) {
3116 mResettingSystemUiFlags = newVal;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003117 changed = true;
3118 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003119 // We don't allow the system's nav bar to be hidden
3120 // again for 1 second, to prevent applications from
3121 // spamming us and keeping it from being shown.
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003122 newVal = mForceClearedSystemUiFlags |
3123 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
Dianne Hackborne26ab702011-10-16 13:21:33 -07003124 if (mForceClearedSystemUiFlags != newVal) {
3125 mForceClearedSystemUiFlags = newVal;
3126 changed = true;
John Spurlock04db1762013-05-13 12:46:41 -04003127 mHandler.postDelayed(mClearHideNavigationFlag, 1000);
Dianne Hackborne26ab702011-10-16 13:21:33 -07003128 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07003129 }
3130 if (changed) {
3131 mWindowManagerFuncs.reevaluateStatusBarVisibility();
3132 }
3133 }
3134 }
3135 } finally {
Jeff Brown32cbc38552011-12-01 14:01:49 -08003136 finishInputEvent(event, handled);
Dianne Hackborndf89e652011-10-06 22:35:11 -07003137 }
3138 }
Jeff Brown32cbc38552011-12-01 14:01:49 -08003139 }
3140 final InputEventReceiver.Factory mHideNavInputEventReceiverFactory =
3141 new InputEventReceiver.Factory() {
3142 @Override
3143 public InputEventReceiver createInputEventReceiver(
3144 InputChannel inputChannel, Looper looper) {
3145 return new HideNavInputEventReceiver(inputChannel, looper);
3146 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07003147 };
3148
3149 @Override
3150 public int adjustSystemUiVisibilityLw(int visibility) {
John Spurlock5b9145b2013-08-20 15:13:47 -04003151 mStatusBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
3152 mNavigationBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
Winson Chungd42a6cf2014-06-03 16:24:04 -07003153 mRecentsVisible = (visibility & View.RECENT_APPS_VISIBLE) > 0;
John Spurlock27735a42013-08-14 17:57:38 -04003154
Dianne Hackborndf89e652011-10-06 22:35:11 -07003155 // Reset any bits in mForceClearingStatusBarVisibility that
3156 // are now clear.
Dianne Hackborne26ab702011-10-16 13:21:33 -07003157 mResettingSystemUiFlags &= visibility;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003158 // Clear any bits in the new visibility that are currently being
3159 // force cleared, before reporting it.
Dianne Hackborne26ab702011-10-16 13:21:33 -07003160 return visibility & ~mResettingSystemUiFlags
3161 & ~mForceClearedSystemUiFlags;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003162 }
3163
Craig Mautner69b08182012-09-05 13:07:13 -07003164 @Override
Adrian Roos37d7a682014-11-06 18:15:16 +01003165 public void getInsetHintLw(WindowManager.LayoutParams attrs, Rect outContentInsets,
3166 Rect outStableInsets) {
John Spurlockc6d1c602014-01-17 15:22:06 -05003167 final int fl = PolicyControl.getWindowFlags(null, attrs);
John Spurlock1db8b682014-02-18 11:18:59 -05003168 final int sysuiVis = PolicyControl.getSystemUiVisibility(null, attrs);
3169 final int systemUiVisibility = (sysuiVis | attrs.subtreeSystemUiVisibility);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003170
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003171 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003172 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003173 int availRight, availBottom;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003174 if (canHideNavigationBar() &&
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003175 (systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003176 availRight = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3177 availBottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
3178 } else {
3179 availRight = mRestrictedScreenLeft + mRestrictedScreenWidth;
3180 availBottom = mRestrictedScreenTop + mRestrictedScreenHeight;
3181 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003182 if ((systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
3183 if ((fl & FLAG_FULLSCREEN) != 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003184 outContentInsets.set(mStableFullscreenLeft, mStableFullscreenTop,
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003185 availRight - mStableFullscreenRight,
3186 availBottom - mStableFullscreenBottom);
3187 } else {
Adrian Roos37d7a682014-11-06 18:15:16 +01003188 outContentInsets.set(mStableLeft, mStableTop,
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003189 availRight - mStableRight, availBottom - mStableBottom);
3190 }
Dianne Hackbornc652de82013-02-15 16:32:56 -08003191 } else if ((fl & FLAG_FULLSCREEN) != 0 || (fl & FLAG_LAYOUT_IN_OVERSCAN) != 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003192 outContentInsets.setEmpty();
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003193 } else if ((systemUiVisibility & (View.SYSTEM_UI_FLAG_FULLSCREEN
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003194 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)) == 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003195 outContentInsets.set(mCurLeft, mCurTop,
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003196 availRight - mCurRight, availBottom - mCurBottom);
3197 } else {
Adrian Roos37d7a682014-11-06 18:15:16 +01003198 outContentInsets.set(mCurLeft, mCurTop,
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003199 availRight - mCurRight, availBottom - mCurBottom);
3200 }
Adrian Roos37d7a682014-11-06 18:15:16 +01003201
3202 outStableInsets.set(mStableLeft, mStableTop,
3203 availRight - mStableRight, availBottom - mStableBottom);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003204 return;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003205 }
Adrian Roos37d7a682014-11-06 18:15:16 +01003206 outContentInsets.setEmpty();
3207 outStableInsets.setEmpty();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003208 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003209
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003210 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07003211 @Override
3212 public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight,
3213 int displayRotation) {
Dianne Hackbornc652de82013-02-15 16:32:56 -08003214 final int overscanLeft, overscanTop, overscanRight, overscanBottom;
3215 if (isDefaultDisplay) {
3216 switch (displayRotation) {
3217 case Surface.ROTATION_90:
3218 overscanLeft = mOverscanTop;
3219 overscanTop = mOverscanRight;
3220 overscanRight = mOverscanBottom;
3221 overscanBottom = mOverscanLeft;
3222 break;
3223 case Surface.ROTATION_180:
3224 overscanLeft = mOverscanRight;
3225 overscanTop = mOverscanBottom;
3226 overscanRight = mOverscanLeft;
3227 overscanBottom = mOverscanTop;
3228 break;
3229 case Surface.ROTATION_270:
3230 overscanLeft = mOverscanBottom;
3231 overscanTop = mOverscanLeft;
3232 overscanRight = mOverscanTop;
3233 overscanBottom = mOverscanRight;
3234 break;
3235 default:
3236 overscanLeft = mOverscanLeft;
3237 overscanTop = mOverscanTop;
3238 overscanRight = mOverscanRight;
3239 overscanBottom = mOverscanBottom;
3240 break;
3241 }
3242 } else {
3243 overscanLeft = 0;
3244 overscanTop = 0;
3245 overscanRight = 0;
3246 overscanBottom = 0;
3247 }
Dianne Hackborn313440842013-02-19 19:22:59 -08003248 mOverscanScreenLeft = mRestrictedOverscanScreenLeft = 0;
3249 mOverscanScreenTop = mRestrictedOverscanScreenTop = 0;
3250 mOverscanScreenWidth = mRestrictedOverscanScreenWidth = displayWidth;
3251 mOverscanScreenHeight = mRestrictedOverscanScreenHeight = displayHeight;
Dianne Hackbornc652de82013-02-15 16:32:56 -08003252 mSystemLeft = 0;
3253 mSystemTop = 0;
3254 mSystemRight = displayWidth;
3255 mSystemBottom = displayHeight;
3256 mUnrestrictedScreenLeft = overscanLeft;
3257 mUnrestrictedScreenTop = overscanTop;
3258 mUnrestrictedScreenWidth = displayWidth - overscanLeft - overscanRight;
3259 mUnrestrictedScreenHeight = displayHeight - overscanTop - overscanBottom;
3260 mRestrictedScreenLeft = mUnrestrictedScreenLeft;
3261 mRestrictedScreenTop = mUnrestrictedScreenTop;
John Spurlockad3e6cb2013-04-30 08:47:43 -04003262 mRestrictedScreenWidth = mSystemGestures.screenWidth = mUnrestrictedScreenWidth;
3263 mRestrictedScreenHeight = mSystemGestures.screenHeight = mUnrestrictedScreenHeight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003264 mDockLeft = mContentLeft = mVoiceContentLeft = mStableLeft = mStableFullscreenLeft
Dianne Hackbornc652de82013-02-15 16:32:56 -08003265 = mCurLeft = mUnrestrictedScreenLeft;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003266 mDockTop = mContentTop = mVoiceContentTop = mStableTop = mStableFullscreenTop
Dianne Hackbornc652de82013-02-15 16:32:56 -08003267 = mCurTop = mUnrestrictedScreenTop;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003268 mDockRight = mContentRight = mVoiceContentRight = mStableRight = mStableFullscreenRight
Dianne Hackbornc652de82013-02-15 16:32:56 -08003269 = mCurRight = displayWidth - overscanRight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003270 mDockBottom = mContentBottom = mVoiceContentBottom = mStableBottom = mStableFullscreenBottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003271 = mCurBottom = displayHeight - overscanBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003272 mDockLayer = 0x10000000;
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003273 mStatusBarLayer = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003274
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003275 // start with the current dock rect, which will be (0,0,displayWidth,displayHeight)
3276 final Rect pf = mTmpParentFrame;
3277 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003278 final Rect of = mTmpOverscanFrame;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003279 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04003280 final Rect dcf = mTmpDecorFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003281 pf.left = df.left = of.left = vf.left = mDockLeft;
3282 pf.top = df.top = of.top = vf.top = mDockTop;
3283 pf.right = df.right = of.right = vf.right = mDockRight;
3284 pf.bottom = df.bottom = of.bottom = vf.bottom = mDockBottom;
John Spurlock46646232013-09-30 22:32:42 -04003285 dcf.setEmpty(); // Decor frame N/A for system bars.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003286
Craig Mautner69b08182012-09-05 13:07:13 -07003287 if (isDefaultDisplay) {
3288 // For purposes of putting out fake window up to steal focus, we will
3289 // drive nav being hidden only by whether it is requested.
John Spurlocke1f366f2013-08-05 12:22:40 -04003290 final int sysui = mLastSystemUiFlags;
3291 boolean navVisible = (sysui & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0;
Adrian Roosea562512014-05-05 13:33:03 +02003292 boolean navTranslucent = (sysui
3293 & (View.NAVIGATION_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04003294 boolean immersive = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
3295 boolean immersiveSticky = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
3296 boolean navAllowedHidden = immersive || immersiveSticky;
3297 navTranslucent &= !immersiveSticky; // transient trumps translucent
Adrian Roos4fb3ee32014-08-22 19:29:09 +02003298 boolean isKeyguardShowing = isStatusBarKeyguard() && !mHideLockScreen;
3299 if (!isKeyguardShowing) {
3300 navTranslucent &= areTranslucentBarsAllowed();
3301 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003302
Craig Mautner69b08182012-09-05 13:07:13 -07003303 // When the navigation bar isn't visible, we put up a fake
3304 // input window to catch all touch events. This way we can
3305 // detect when the user presses anywhere to bring back the nav
3306 // bar and ensure the application doesn't see the event.
John Spurlockf1a36642013-10-12 17:50:42 -04003307 if (navVisible || navAllowedHidden) {
Craig Mautner69b08182012-09-05 13:07:13 -07003308 if (mHideNavFakeWindow != null) {
3309 mHideNavFakeWindow.dismiss();
3310 mHideNavFakeWindow = null;
3311 }
3312 } else if (mHideNavFakeWindow == null) {
3313 mHideNavFakeWindow = mWindowManagerFuncs.addFakeWindow(
3314 mHandler.getLooper(), mHideNavInputEventReceiverFactory,
Adam Lesinski95c42972013-10-02 10:13:27 -07003315 "hidden nav", WindowManager.LayoutParams.TYPE_HIDDEN_NAV_CONSUMER, 0,
Craig Mautner69b08182012-09-05 13:07:13 -07003316 0, false, false, true);
Dianne Hackborne26ab702011-10-16 13:21:33 -07003317 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003318
Craig Mautner69b08182012-09-05 13:07:13 -07003319 // For purposes of positioning and showing the nav bar, if we have
3320 // decided that it can't be hidden (because of the screen aspect ratio),
3321 // then take that into account.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003322 navVisible |= !canHideNavigationBar();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003323
John Spurlockad3e6cb2013-04-30 08:47:43 -04003324 boolean updateSysUiVisibility = false;
Craig Mautner69b08182012-09-05 13:07:13 -07003325 if (mNavigationBar != null) {
John Spurlock27735a42013-08-14 17:57:38 -04003326 boolean transientNavBarShowing = mNavigationBarController.isTransientShowing();
Craig Mautner69b08182012-09-05 13:07:13 -07003327 // Force the navigation bar to its appropriate place and
3328 // size. We need to do this directly, instead of relying on
3329 // it to bubble up from the nav bar, because this needs to
3330 // change atomically with screen rotations.
3331 mNavigationBarOnBottom = (!mNavigationBarCanMove || displayWidth < displayHeight);
3332 if (mNavigationBarOnBottom) {
3333 // It's a system nav bar or a portrait screen; nav bar goes on bottom.
Dianne Hackbornc652de82013-02-15 16:32:56 -08003334 int top = displayHeight - overscanBottom
3335 - mNavigationBarHeightForRotation[displayRotation];
3336 mTmpNavigationFrame.set(0, top, displayWidth, displayHeight - overscanBottom);
Craig Mautner69b08182012-09-05 13:07:13 -07003337 mStableBottom = mStableFullscreenBottom = mTmpNavigationFrame.top;
John Spurlockf95b89a2013-10-10 22:10:42 -04003338 if (transientNavBarShowing) {
John Spurlock27735a42013-08-14 17:57:38 -04003339 mNavigationBarController.setBarShowingLw(true);
John Spurlockad3e6cb2013-04-30 08:47:43 -04003340 } else if (navVisible) {
John Spurlock27735a42013-08-14 17:57:38 -04003341 mNavigationBarController.setBarShowingLw(true);
Craig Mautner69b08182012-09-05 13:07:13 -07003342 mDockBottom = mTmpNavigationFrame.top;
Dianne Hackborn313440842013-02-19 19:22:59 -08003343 mRestrictedScreenHeight = mDockBottom - mRestrictedScreenTop;
3344 mRestrictedOverscanScreenHeight = mDockBottom - mRestrictedOverscanScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07003345 } else {
3346 // We currently want to hide the navigation UI.
John Spurlock27735a42013-08-14 17:57:38 -04003347 mNavigationBarController.setBarShowingLw(false);
Craig Mautner69b08182012-09-05 13:07:13 -07003348 }
John Spurlockc6d1c602014-01-17 15:22:06 -05003349 if (navVisible && !navTranslucent && !navAllowedHidden
3350 && !mNavigationBar.isAnimatingLw()
John Spurlockbd957402013-10-03 11:38:39 -04003351 && !mNavigationBarController.wasRecentlyTranslucent()) {
John Spurlocke1f366f2013-08-05 12:22:40 -04003352 // If the opaque nav bar is currently requested to be visible,
Craig Mautner69b08182012-09-05 13:07:13 -07003353 // and not in the process of animating on or off, then
3354 // we can tell the app that it is covered by it.
3355 mSystemBottom = mTmpNavigationFrame.top;
3356 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003357 } else {
Craig Mautner69b08182012-09-05 13:07:13 -07003358 // Landscape screen; nav bar goes to the right.
Dianne Hackbornc652de82013-02-15 16:32:56 -08003359 int left = displayWidth - overscanRight
3360 - mNavigationBarWidthForRotation[displayRotation];
3361 mTmpNavigationFrame.set(left, 0, displayWidth - overscanRight, displayHeight);
Craig Mautner69b08182012-09-05 13:07:13 -07003362 mStableRight = mStableFullscreenRight = mTmpNavigationFrame.left;
John Spurlockf95b89a2013-10-10 22:10:42 -04003363 if (transientNavBarShowing) {
John Spurlock27735a42013-08-14 17:57:38 -04003364 mNavigationBarController.setBarShowingLw(true);
John Spurlockad3e6cb2013-04-30 08:47:43 -04003365 } else if (navVisible) {
John Spurlock27735a42013-08-14 17:57:38 -04003366 mNavigationBarController.setBarShowingLw(true);
Craig Mautner69b08182012-09-05 13:07:13 -07003367 mDockRight = mTmpNavigationFrame.left;
Dianne Hackborn313440842013-02-19 19:22:59 -08003368 mRestrictedScreenWidth = mDockRight - mRestrictedScreenLeft;
3369 mRestrictedOverscanScreenWidth = mDockRight - mRestrictedOverscanScreenLeft;
Craig Mautner69b08182012-09-05 13:07:13 -07003370 } else {
3371 // We currently want to hide the navigation UI.
John Spurlock27735a42013-08-14 17:57:38 -04003372 mNavigationBarController.setBarShowingLw(false);
Craig Mautner69b08182012-09-05 13:07:13 -07003373 }
John Spurlockbd957402013-10-03 11:38:39 -04003374 if (navVisible && !navTranslucent && !mNavigationBar.isAnimatingLw()
3375 && !mNavigationBarController.wasRecentlyTranslucent()) {
Craig Mautner69b08182012-09-05 13:07:13 -07003376 // If the nav bar is currently requested to be visible,
3377 // and not in the process of animating on or off, then
3378 // we can tell the app that it is covered by it.
3379 mSystemRight = mTmpNavigationFrame.left;
3380 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003381 }
Craig Mautner69b08182012-09-05 13:07:13 -07003382 // Make sure the content and current rectangles are updated to
3383 // account for the restrictions from the navigation bar.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003384 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3385 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3386 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3387 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
Craig Mautner69b08182012-09-05 13:07:13 -07003388 mStatusBarLayer = mNavigationBar.getSurfaceLayer();
3389 // And compute the final frame.
3390 mNavigationBar.computeFrameLw(mTmpNavigationFrame, mTmpNavigationFrame,
Adrian Roosfa104232014-06-20 16:10:14 -07003391 mTmpNavigationFrame, mTmpNavigationFrame, mTmpNavigationFrame, dcf,
3392 mTmpNavigationFrame);
Craig Mautnereda67292013-04-28 13:50:14 -07003393 if (DEBUG_LAYOUT) Slog.i(TAG, "mNavigationBar frame: " + mTmpNavigationFrame);
John Spurlock27735a42013-08-14 17:57:38 -04003394 if (mNavigationBarController.checkHiddenLw()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04003395 updateSysUiVisibility = true;
3396 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003397 }
Craig Mautnereda67292013-04-28 13:50:14 -07003398 if (DEBUG_LAYOUT) Slog.i(TAG, String.format("mDock rect: (%d,%d - %d,%d)",
Craig Mautner69b08182012-09-05 13:07:13 -07003399 mDockLeft, mDockTop, mDockRight, mDockBottom));
3400
3401 // decide where the status bar goes ahead of time
3402 if (mStatusBar != null) {
3403 // apply any navigation bar insets
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003404 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3405 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3406 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
3407 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight
3408 + mUnrestrictedScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07003409 vf.left = mStableLeft;
3410 vf.top = mStableTop;
3411 vf.right = mStableRight;
3412 vf.bottom = mStableBottom;
3413
3414 mStatusBarLayer = mStatusBar.getSurfaceLayer();
3415
3416 // Let the status bar determine its size.
Adrian Roosfa104232014-06-20 16:10:14 -07003417 mStatusBar.computeFrameLw(pf, df, vf, vf, vf, dcf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07003418
3419 // For layout, the status bar is always at the top with our fixed height.
3420 mStableTop = mUnrestrictedScreenTop + mStatusBarHeight;
3421
John Spurlocke1f366f2013-08-05 12:22:40 -04003422 boolean statusBarTransient = (sysui & View.STATUS_BAR_TRANSIENT) != 0;
Adrian Roosea562512014-05-05 13:33:03 +02003423 boolean statusBarTranslucent = (sysui
3424 & (View.STATUS_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0;
Adrian Roos4fb3ee32014-08-22 19:29:09 +02003425 if (!isKeyguardShowing) {
3426 statusBarTranslucent &= areTranslucentBarsAllowed();
3427 }
John Spurlock32beb2c2013-03-11 10:16:47 -04003428
Craig Mautner69b08182012-09-05 13:07:13 -07003429 // If the status bar is hidden, we don't want to cause
3430 // windows behind it to scroll.
John Spurlockeda1f692013-09-16 11:38:44 -04003431 if (mStatusBar.isVisibleLw() && !statusBarTransient) {
Craig Mautner69b08182012-09-05 13:07:13 -07003432 // Status bar may go away, so the screen area it occupies
3433 // is available to apps but just covering them when the
3434 // status bar is visible.
3435 mDockTop = mUnrestrictedScreenTop + mStatusBarHeight;
3436
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003437 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3438 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3439 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3440 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
Craig Mautner69b08182012-09-05 13:07:13 -07003441
Craig Mautnereda67292013-04-28 13:50:14 -07003442 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar: " +
Craig Mautner69b08182012-09-05 13:07:13 -07003443 String.format(
3444 "dock=[%d,%d][%d,%d] content=[%d,%d][%d,%d] cur=[%d,%d][%d,%d]",
3445 mDockLeft, mDockTop, mDockRight, mDockBottom,
3446 mContentLeft, mContentTop, mContentRight, mContentBottom,
3447 mCurLeft, mCurTop, mCurRight, mCurBottom));
3448 }
John Spurlocke1f366f2013-08-05 12:22:40 -04003449 if (mStatusBar.isVisibleLw() && !mStatusBar.isAnimatingLw()
John Spurlockbd957402013-10-03 11:38:39 -04003450 && !statusBarTransient && !statusBarTranslucent
3451 && !mStatusBarController.wasRecentlyTranslucent()) {
John Spurlocke1f366f2013-08-05 12:22:40 -04003452 // If the opaque status bar is currently requested to be visible,
Craig Mautner69b08182012-09-05 13:07:13 -07003453 // and not in the process of animating on or off, then
3454 // we can tell the app that it is covered by it.
3455 mSystemTop = mUnrestrictedScreenTop + mStatusBarHeight;
3456 }
John Spurlock27735a42013-08-14 17:57:38 -04003457 if (mStatusBarController.checkHiddenLw()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04003458 updateSysUiVisibility = true;
John Spurlock32beb2c2013-03-11 10:16:47 -04003459 }
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003460 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04003461 if (updateSysUiVisibility) {
3462 updateSystemUiVisibilityLw();
3463 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003464 }
3465 }
3466
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003467 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07003468 @Override
John Spurlock46646232013-09-30 22:32:42 -04003469 public int getSystemDecorLayerLw() {
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003470 if (mStatusBar != null) return mStatusBar.getSurfaceLayer();
3471 if (mNavigationBar != null) return mNavigationBar.getSurfaceLayer();
3472 return 0;
3473 }
3474
Craig Mautner967212c2013-04-13 21:10:58 -07003475 @Override
3476 public void getContentRectLw(Rect r) {
3477 r.set(mContentLeft, mContentTop, mContentRight, mContentBottom);
3478 }
3479
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003480 void setAttachedWindowFrames(WindowState win, int fl, int adjust, WindowState attached,
3481 boolean insetDecors, Rect pf, Rect df, Rect of, Rect cf, Rect vf) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003482 if (win.getSurfaceLayer() > mDockLayer && attached.getSurfaceLayer() < mDockLayer) {
3483 // Here's a special case: if this attached window is a panel that is
3484 // above the dock window, and the window it is attached to is below
3485 // the dock window, then the frames we computed for the window it is
3486 // attached to can not be used because the dock is effectively part
3487 // of the underlying window and the attached window is floating on top
3488 // of the whole thing. So, we ignore the attached window and explicitly
3489 // compute the frames that would be appropriate without the dock.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003490 df.left = of.left = cf.left = vf.left = mDockLeft;
3491 df.top = of.top = cf.top = vf.top = mDockTop;
3492 df.right = of.right = cf.right = vf.right = mDockRight;
3493 df.bottom = of.bottom = cf.bottom = vf.bottom = mDockBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003494 } else {
3495 // The effective display frame of the attached window depends on
3496 // whether it is taking care of insetting its content. If not,
3497 // we need to use the parent's content frame so that the entire
3498 // window is positioned within that content. Otherwise we can use
Wale Ogunwale393b1c12014-10-18 16:22:01 -07003499 // the overscan frame and let the attached window take care of
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003500 // positioning its content appropriately.
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003501 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Wale Ogunwale393b1c12014-10-18 16:22:01 -07003502 // Set the content frame of the attached window to the parent's decor frame
3503 // (same as content frame when IME isn't present) if specifically requested by
3504 // setting {@link WindowManager.LayoutParams#FLAG_LAYOUT_ATTACHED_IN_DECOR} flag.
3505 // Otherwise, use the overscan frame.
3506 cf.set((fl & FLAG_LAYOUT_ATTACHED_IN_DECOR) != 0
3507 ? attached.getContentFrameLw() : attached.getOverscanFrameLw());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003508 } else {
3509 // If the window is resizing, then we want to base the content
3510 // frame on our attached content frame to resize... however,
3511 // things can be tricky if the attached window is NOT in resize
3512 // mode, in which case its content frame will be larger.
3513 // Ungh. So to deal with that, make sure the content frame
3514 // we end up using is not covering the IM dock.
3515 cf.set(attached.getContentFrameLw());
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003516 if (attached.isVoiceInteraction()) {
3517 if (cf.left < mVoiceContentLeft) cf.left = mVoiceContentLeft;
3518 if (cf.top < mVoiceContentTop) cf.top = mVoiceContentTop;
3519 if (cf.right > mVoiceContentRight) cf.right = mVoiceContentRight;
3520 if (cf.bottom > mVoiceContentBottom) cf.bottom = mVoiceContentBottom;
3521 } else if (attached.getSurfaceLayer() < mDockLayer) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003522 if (cf.left < mContentLeft) cf.left = mContentLeft;
3523 if (cf.top < mContentTop) cf.top = mContentTop;
3524 if (cf.right > mContentRight) cf.right = mContentRight;
3525 if (cf.bottom > mContentBottom) cf.bottom = mContentBottom;
3526 }
3527 }
3528 df.set(insetDecors ? attached.getDisplayFrameLw() : cf);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003529 of.set(insetDecors ? attached.getOverscanFrameLw() : cf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003530 vf.set(attached.getVisibleFrameLw());
3531 }
3532 // The LAYOUT_IN_SCREEN flag is used to determine whether the attached
3533 // window should be positioned relative to its parent or the entire
3534 // screen.
3535 pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0
3536 ? attached.getFrameLw() : df);
3537 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003538
3539 private void applyStableConstraints(int sysui, int fl, Rect r) {
3540 if ((sysui & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
3541 // If app is requesting a stable layout, don't let the
3542 // content insets go below the stable values.
3543 if ((fl & FLAG_FULLSCREEN) != 0) {
3544 if (r.left < mStableFullscreenLeft) r.left = mStableFullscreenLeft;
3545 if (r.top < mStableFullscreenTop) r.top = mStableFullscreenTop;
3546 if (r.right > mStableFullscreenRight) r.right = mStableFullscreenRight;
3547 if (r.bottom > mStableFullscreenBottom) r.bottom = mStableFullscreenBottom;
3548 } else {
3549 if (r.left < mStableLeft) r.left = mStableLeft;
3550 if (r.top < mStableTop) r.top = mStableTop;
3551 if (r.right > mStableRight) r.right = mStableRight;
3552 if (r.bottom > mStableBottom) r.bottom = mStableBottom;
3553 }
3554 }
3555 }
3556
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003557 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07003558 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003559 public void layoutWindowLw(WindowState win, WindowState attached) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003560 // we've already done the status bar
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003561 final WindowManager.LayoutParams attrs = win.getAttrs();
3562 if ((win == mStatusBar && (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) == 0) ||
3563 win == mNavigationBar) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003564 return;
3565 }
Craig Mautner69b08182012-09-05 13:07:13 -07003566 final boolean isDefaultDisplay = win.isDefaultDisplay();
3567 final boolean needsToOffsetInputMethodTarget = isDefaultDisplay &&
satok1bc0a492012-04-25 22:47:12 +09003568 (win == mLastInputMethodTargetWindow && mLastInputMethodWindow != null);
3569 if (needsToOffsetInputMethodTarget) {
Craig Mautnereda67292013-04-28 13:50:14 -07003570 if (DEBUG_LAYOUT) Slog.i(TAG, "Offset ime target window by the last ime window state");
satok1bc0a492012-04-25 22:47:12 +09003571 offsetInputMethodWindowLw(mLastInputMethodWindow);
3572 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003573
John Spurlockc6d1c602014-01-17 15:22:06 -05003574 final int fl = PolicyControl.getWindowFlags(win, attrs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003575 final int sim = attrs.softInputMode;
John Spurlock1db8b682014-02-18 11:18:59 -05003576 final int sysUiFl = PolicyControl.getSystemUiVisibility(win, null);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003577
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003578 final Rect pf = mTmpParentFrame;
3579 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003580 final Rect of = mTmpOverscanFrame;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003581 final Rect cf = mTmpContentFrame;
3582 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04003583 final Rect dcf = mTmpDecorFrame;
Adrian Roosfa104232014-06-20 16:10:14 -07003584 final Rect sf = mTmpStableFrame;
John Spurlock46646232013-09-30 22:32:42 -04003585 dcf.setEmpty();
Craig Mautner69b08182012-09-05 13:07:13 -07003586
3587 final boolean hasNavBar = (isDefaultDisplay && mHasNavigationBar
Daniel Sandler36412a72011-08-04 09:35:13 -04003588 && mNavigationBar != null && mNavigationBar.isVisibleLw());
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003589
Craig Mautnerf683b562012-10-02 11:10:57 -07003590 final int adjust = sim & SOFT_INPUT_MASK_ADJUST;
3591
Adrian Roosfa104232014-06-20 16:10:14 -07003592 if (isDefaultDisplay) {
3593 sf.set(mStableLeft, mStableTop, mStableRight, mStableBottom);
3594 } else {
3595 sf.set(mOverscanLeft, mOverscanTop, mOverscanRight, mOverscanBottom);
3596 }
3597
Craig Mautner69b08182012-09-05 13:07:13 -07003598 if (!isDefaultDisplay) {
3599 if (attached != null) {
3600 // If this window is attached to another, our display
3601 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003602 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07003603 } else {
3604 // Give the window full screen.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003605 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3606 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3607 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08003608 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003609 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003610 = mOverscanScreenTop + mOverscanScreenHeight;
Craig Mautner69b08182012-09-05 13:07:13 -07003611 }
Dianne Hackbornae6688b2015-02-11 17:02:41 -08003612 } else if (attrs.type == TYPE_INPUT_METHOD || attrs.type == TYPE_VOICE_INTERACTION) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003613 pf.left = df.left = of.left = cf.left = vf.left = mDockLeft;
3614 pf.top = df.top = of.top = cf.top = vf.top = mDockTop;
3615 pf.right = df.right = of.right = cf.right = vf.right = mDockRight;
John Spurlockc68d5772013-10-08 11:47:58 -04003616 // IM dock windows layout below the nav bar...
John Spurlock57beb3b2013-10-10 10:27:44 -04003617 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlockc68d5772013-10-08 11:47:58 -04003618 // ...with content insets above the nav bar
3619 cf.bottom = vf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003620 // IM dock windows always go to the bottom of the screen.
3621 attrs.gravity = Gravity.BOTTOM;
3622 mDockLayer = win.getSurfaceLayer();
Jorim Jaggie0700182014-08-21 01:12:37 +02003623 } else if (win == mStatusBar && (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
3624 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3625 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3626 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
3627 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight + mUnrestrictedScreenTop;
3628 cf.left = vf.left = mStableLeft;
3629 cf.top = vf.top = mStableTop;
3630 cf.right = vf.right = mStableRight;
3631 vf.bottom = mStableBottom;
3632 cf.bottom = mContentBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003633 } else {
John Spurlock46646232013-09-30 22:32:42 -04003634
3635 // Default policy decor for the default display
3636 dcf.left = mSystemLeft;
3637 dcf.top = mSystemTop;
3638 dcf.right = mSystemRight;
3639 dcf.bottom = mSystemBottom;
John Spurlockbd957402013-10-03 11:38:39 -04003640 final boolean inheritTranslucentDecor = (attrs.privateFlags
3641 & WindowManager.LayoutParams.PRIVATE_FLAG_INHERIT_TRANSLUCENT_DECOR) != 0;
John Spurlock65567d42013-10-08 10:08:32 -04003642 final boolean isAppWindow =
3643 attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW &&
3644 attrs.type <= WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
3645 final boolean topAtRest =
3646 win == mTopFullscreenOpaqueWindowState && !win.isAnimatingLw();
3647 if (isAppWindow && !inheritTranslucentDecor && !topAtRest) {
John Spurlockbd957402013-10-03 11:38:39 -04003648 if ((sysUiFl & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0
3649 && (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0
Adrian Roosea562512014-05-05 13:33:03 +02003650 && (fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) == 0
3651 && (fl & WindowManager.LayoutParams.
3652 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04003653 // Ensure policy decor includes status bar
3654 dcf.top = mStableTop;
3655 }
John Spurlockbd957402013-10-03 11:38:39 -04003656 if ((fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) == 0
Adrian Roosea562512014-05-05 13:33:03 +02003657 && (sysUiFl & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0
3658 && (fl & WindowManager.LayoutParams.
3659 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04003660 // Ensure policy decor includes navigation bar
3661 dcf.bottom = mStableBottom;
3662 dcf.right = mStableRight;
3663 }
3664 }
3665
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003666 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
3667 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
RoboErik8a2cfc32014-05-16 11:19:38 -07003668 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003669 + "): IN_SCREEN, INSET_DECOR");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003670 // This is the case for a normal activity window: we want it
3671 // to cover all of the screen space, and it can take care of
3672 // moving its contents to account for screen decorations that
3673 // intrude into that space.
3674 if (attached != null) {
3675 // If this window is attached to another, our display
3676 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003677 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003678 } else {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003679 if (attrs.type == TYPE_STATUS_BAR_PANEL
3680 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Joe Onorato29fc2c92010-11-24 10:26:50 -08003681 // Status bar panels are the only windows who can go on top of
3682 // the status bar. They are protected by the STATUS_BAR_SERVICE
3683 // permission, so they have the same privileges as the status
3684 // bar itself.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003685 //
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003686 // However, they should still dodge the navigation bar if it exists.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003687
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003688 pf.left = df.left = of.left = hasNavBar
3689 ? mDockLeft : mUnrestrictedScreenLeft;
3690 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3691 pf.right = df.right = of.right = hasNavBar
3692 ? mRestrictedScreenLeft+mRestrictedScreenWidth
3693 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3694 pf.bottom = df.bottom = of.bottom = hasNavBar
3695 ? mRestrictedScreenTop+mRestrictedScreenHeight
3696 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003697
Craig Mautnereda67292013-04-28 13:50:14 -07003698 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003699 "Laying out status bar window: (%d,%d - %d,%d)",
3700 pf.left, pf.top, pf.right, pf.bottom));
John Spurlock46646232013-09-30 22:32:42 -04003701 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08003702 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3703 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3704 // Asking to layout into the overscan region, so give it that pure
3705 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003706 pf.left = df.left = of.left = mOverscanScreenLeft;
3707 pf.top = df.top = of.top = mOverscanScreenTop;
3708 pf.right = df.right = of.right = mOverscanScreenLeft + mOverscanScreenWidth;
3709 pf.bottom = df.bottom = of.bottom = mOverscanScreenTop
3710 + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003711 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003712 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003713 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3714 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003715 // Asking for layout as if the nav bar is hidden, lets the
Dianne Hackbornc652de82013-02-15 16:32:56 -08003716 // application extend into the unrestricted overscan screen area. We
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003717 // only do this for application windows to ensure no window that
3718 // can be above the nav bar can do this.
Dianne Hackborn313440842013-02-19 19:22:59 -08003719 pf.left = df.left = mOverscanScreenLeft;
3720 pf.top = df.top = mOverscanScreenTop;
3721 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
3722 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003723 // We need to tell the app about where the frame inside the overscan
3724 // is, so it can inset its content by that amount -- it didn't ask
3725 // to actually extend itself into the overscan region.
3726 of.left = mUnrestrictedScreenLeft;
3727 of.top = mUnrestrictedScreenTop;
3728 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3729 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003730 } else {
Dianne Hackborn313440842013-02-19 19:22:59 -08003731 pf.left = df.left = mRestrictedOverscanScreenLeft;
3732 pf.top = df.top = mRestrictedOverscanScreenTop;
3733 pf.right = df.right = mRestrictedOverscanScreenLeft
3734 + mRestrictedOverscanScreenWidth;
3735 pf.bottom = df.bottom = mRestrictedOverscanScreenTop
3736 + mRestrictedOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003737 // We need to tell the app about where the frame inside the overscan
3738 // is, so it can inset its content by that amount -- it didn't ask
3739 // to actually extend itself into the overscan region.
3740 of.left = mUnrestrictedScreenLeft;
3741 of.top = mUnrestrictedScreenTop;
3742 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3743 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003744 }
Craig Mautner69b08182012-09-05 13:07:13 -07003745
John Spurlock46646232013-09-30 22:32:42 -04003746 if ((fl & FLAG_FULLSCREEN) == 0) {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003747 if (win.isVoiceInteraction()) {
3748 cf.left = mVoiceContentLeft;
3749 cf.top = mVoiceContentTop;
3750 cf.right = mVoiceContentRight;
3751 cf.bottom = mVoiceContentBottom;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003752 } else {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003753 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
3754 cf.left = mDockLeft;
3755 cf.top = mDockTop;
3756 cf.right = mDockRight;
3757 cf.bottom = mDockBottom;
3758 } else {
3759 cf.left = mContentLeft;
3760 cf.top = mContentTop;
3761 cf.right = mContentRight;
3762 cf.bottom = mContentBottom;
3763 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003764 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003765 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003766 // Full screen windows are always given a layout that is as if the
3767 // status bar and other transient decors are gone. This is to avoid
3768 // bad states when moving from a window that is not hding the
3769 // status bar to one that is.
3770 cf.left = mRestrictedScreenLeft;
3771 cf.top = mRestrictedScreenTop;
3772 cf.right = mRestrictedScreenLeft + mRestrictedScreenWidth;
3773 cf.bottom = mRestrictedScreenTop + mRestrictedScreenHeight;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003774 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003775 applyStableConstraints(sysUiFl, fl, cf);
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003776 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3777 vf.left = mCurLeft;
3778 vf.top = mCurTop;
3779 vf.right = mCurRight;
3780 vf.bottom = mCurBottom;
3781 } else {
3782 vf.set(cf);
3783 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003784 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003785 } else if ((fl & FLAG_LAYOUT_IN_SCREEN) != 0 || (sysUiFl
3786 & (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
3787 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)) != 0) {
Craig Mautnereda67292013-04-28 13:50:14 -07003788 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3789 "): IN_SCREEN");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003790 // A window that has requested to fill the entire screen just
3791 // gets everything, period.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003792 if (attrs.type == TYPE_STATUS_BAR_PANEL
3793 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003794 pf.left = df.left = of.left = cf.left = hasNavBar
3795 ? mDockLeft : mUnrestrictedScreenLeft;
3796 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
3797 pf.right = df.right = of.right = cf.right = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003798 ? mRestrictedScreenLeft+mRestrictedScreenWidth
Dianne Hackbornc652de82013-02-15 16:32:56 -08003799 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003800 pf.bottom = df.bottom = of.bottom = cf.bottom = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003801 ? mRestrictedScreenTop+mRestrictedScreenHeight
Dianne Hackbornc652de82013-02-15 16:32:56 -08003802 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07003803 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler36412a72011-08-04 09:35:13 -04003804 "Laying out IN_SCREEN status bar window: (%d,%d - %d,%d)",
3805 pf.left, pf.top, pf.right, pf.bottom));
Jim Millere898ac52012-04-06 17:10:57 -07003806 } else if (attrs.type == TYPE_NAVIGATION_BAR
3807 || attrs.type == TYPE_NAVIGATION_BAR_PANEL) {
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003808 // The navigation bar has Real Ultimate Power.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003809 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3810 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3811 pf.right = df.right = of.right = mUnrestrictedScreenLeft
3812 + mUnrestrictedScreenWidth;
3813 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop
3814 + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07003815 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003816 "Laying out navigation bar window: (%d,%d - %d,%d)",
3817 pf.left, pf.top, pf.right, pf.bottom));
Dianne Hackborn01011c32012-02-21 13:54:21 -08003818 } else if ((attrs.type == TYPE_SECURE_SYSTEM_OVERLAY
3819 || attrs.type == TYPE_BOOT_PROGRESS)
Jeff Brownbfcb60a2011-09-08 18:51:14 -07003820 && ((fl & FLAG_FULLSCREEN) != 0)) {
3821 // Fullscreen secure system overlays get what they ask for.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003822 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3823 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3824 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
3825 + mOverscanScreenWidth;
3826 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
3827 + mOverscanScreenHeight;
Craig Mautner165be0c2015-01-27 15:16:58 -08003828 } else if (attrs.type == TYPE_BOOT_PROGRESS) {
Dianne Hackborn01011c32012-02-21 13:54:21 -08003829 // Boot progress screen always covers entire display.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003830 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3831 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3832 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
3833 + mOverscanScreenWidth;
3834 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
3835 + mOverscanScreenHeight;
John Spurlockef4adae2013-08-26 17:58:58 -04003836 } else if (attrs.type == TYPE_WALLPAPER) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07003837 // The wallpaper also has Real Ultimate Power, but we want to tell
3838 // it about the overscan area.
3839 pf.left = df.left = mOverscanScreenLeft;
3840 pf.top = df.top = mOverscanScreenTop;
3841 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
3842 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
3843 of.left = cf.left = mUnrestrictedScreenLeft;
3844 of.top = cf.top = mUnrestrictedScreenTop;
3845 of.right = cf.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3846 of.bottom = cf.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlock46646232013-09-30 22:32:42 -04003847 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08003848 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3849 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3850 // Asking to layout into the overscan region, so give it that pure
3851 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003852 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3853 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3854 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08003855 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003856 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003857 = mOverscanScreenTop + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003858 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003859 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Craig Mautnerbeac1062014-06-03 14:38:57 -07003860 && (attrs.type == TYPE_STATUS_BAR
3861 || attrs.type == TYPE_TOAST
John Spurlock34e13d92013-08-10 06:52:28 -04003862 || (attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3863 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW))) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003864 // Asking for layout as if the nav bar is hidden, lets the
3865 // application extend into the unrestricted screen area. We
John Spurlock34e13d92013-08-10 06:52:28 -04003866 // only do this for application windows (or toasts) to ensure no window that
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003867 // can be above the nav bar can do this.
3868 // XXX This assumes that an app asking for this will also
3869 // ask for layout in only content. We can't currently figure out
3870 // what the screen would be if only laying out to hide the nav bar.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003871 pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft;
3872 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
3873 pf.right = df.right = of.right = cf.right = mUnrestrictedScreenLeft
3874 + mUnrestrictedScreenWidth;
3875 pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop
3876 + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003877 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003878 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
3879 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
3880 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
3881 + mRestrictedScreenWidth;
3882 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
3883 + mRestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003884 }
Craig Mautner69b08182012-09-05 13:07:13 -07003885
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003886 applyStableConstraints(sysUiFl, fl, cf);
Craig Mautner69b08182012-09-05 13:07:13 -07003887
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003888 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3889 vf.left = mCurLeft;
3890 vf.top = mCurTop;
3891 vf.right = mCurRight;
3892 vf.bottom = mCurBottom;
3893 } else {
3894 vf.set(cf);
3895 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003896 } else if (attached != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07003897 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3898 "): attached to " + attached);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003899 // A child window should be placed inside of the same visible
3900 // frame that its parent had.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003901 setAttachedWindowFrames(win, fl, adjust, attached, false, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003902 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07003903 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3904 "): normal window");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003905 // Otherwise, a normal window must be placed inside the content
3906 // of all screen decorations.
Dianne Hackborna239c842011-06-01 12:28:20 -07003907 if (attrs.type == TYPE_STATUS_BAR_PANEL) {
3908 // Status bar panels are the only windows who can go on top of
3909 // the status bar. They are protected by the STATUS_BAR_SERVICE
3910 // permission, so they have the same privileges as the status
3911 // bar itself.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003912 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
3913 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
3914 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
3915 + mRestrictedScreenWidth;
3916 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
3917 + mRestrictedScreenHeight;
John Spurlock414c1f02013-12-04 13:47:36 -05003918 } else if (attrs.type == TYPE_TOAST || attrs.type == TYPE_SYSTEM_ALERT
3919 || attrs.type == TYPE_VOLUME_OVERLAY) {
3920 // These dialogs are stable to interim decor changes.
John Spurlockbd957402013-10-03 11:38:39 -04003921 pf.left = df.left = of.left = cf.left = mStableLeft;
3922 pf.top = df.top = of.top = cf.top = mStableTop;
3923 pf.right = df.right = of.right = cf.right = mStableRight;
3924 pf.bottom = df.bottom = of.bottom = cf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003925 } else {
Dianne Hackborna239c842011-06-01 12:28:20 -07003926 pf.left = mContentLeft;
3927 pf.top = mContentTop;
3928 pf.right = mContentRight;
3929 pf.bottom = mContentBottom;
Dianne Hackborn20d94742014-05-29 18:35:45 -07003930 if (win.isVoiceInteraction()) {
3931 df.left = of.left = cf.left = mVoiceContentLeft;
3932 df.top = of.top = cf.top = mVoiceContentTop;
3933 df.right = of.right = cf.right = mVoiceContentRight;
3934 df.bottom = of.bottom = cf.bottom = mVoiceContentBottom;
3935 } else if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003936 df.left = of.left = cf.left = mDockLeft;
3937 df.top = of.top = cf.top = mDockTop;
3938 df.right = of.right = cf.right = mDockRight;
3939 df.bottom = of.bottom = cf.bottom = mDockBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07003940 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003941 df.left = of.left = cf.left = mContentLeft;
3942 df.top = of.top = cf.top = mContentTop;
3943 df.right = of.right = cf.right = mContentRight;
3944 df.bottom = of.bottom = cf.bottom = mContentBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07003945 }
3946 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3947 vf.left = mCurLeft;
3948 vf.top = mCurTop;
3949 vf.right = mCurRight;
3950 vf.bottom = mCurBottom;
3951 } else {
3952 vf.set(cf);
3953 }
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003954 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003955 }
3956 }
Craig Mautner69b08182012-09-05 13:07:13 -07003957
Craig Mautnerb816bed2013-07-23 10:26:17 -07003958 // TYPE_SYSTEM_ERROR is above the NavigationBar so it can't be allowed to extend over it.
3959 if ((fl & FLAG_LAYOUT_NO_LIMITS) != 0 && attrs.type != TYPE_SYSTEM_ERROR) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07003960 df.left = df.top = -10000;
3961 df.right = df.bottom = 10000;
3962 if (attrs.type != TYPE_WALLPAPER) {
3963 of.left = of.top = cf.left = cf.top = vf.left = vf.top = -10000;
3964 of.right = of.bottom = cf.right = cf.bottom = vf.right = vf.bottom = 10000;
3965 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003966 }
3967
Craig Mautnereda67292013-04-28 13:50:14 -07003968 if (DEBUG_LAYOUT) Slog.v(TAG, "Compute frame " + attrs.getTitle()
The Android Open Source Project11267662009-03-18 17:39:47 -07003969 + ": sim=#" + Integer.toHexString(sim)
RoboErik8a2cfc32014-05-16 11:19:38 -07003970 + " attach=" + attached + " type=" + attrs.type
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003971 + String.format(" flags=0x%08x", fl)
The Android Open Source Project11267662009-03-18 17:39:47 -07003972 + " pf=" + pf.toShortString() + " df=" + df.toShortString()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003973 + " of=" + of.toShortString()
John Spurlock46646232013-09-30 22:32:42 -04003974 + " cf=" + cf.toShortString() + " vf=" + vf.toShortString()
Adrian Roosfa104232014-06-20 16:10:14 -07003975 + " dcf=" + dcf.toShortString()
3976 + " sf=" + sf.toShortString());
Craig Mautner69b08182012-09-05 13:07:13 -07003977
Adrian Roosfa104232014-06-20 16:10:14 -07003978 win.computeFrameLw(pf, df, of, cf, vf, dcf, sf);
Craig Mautner69b08182012-09-05 13:07:13 -07003979
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003980 // Dock windows carve out the bottom of the screen, so normal windows
3981 // can't appear underneath them.
Craig Mautner8bd206b2012-10-03 10:32:02 -07003982 if (attrs.type == TYPE_INPUT_METHOD && win.isVisibleOrBehindKeyguardLw()
3983 && !win.getGivenInsetsPendingLw()) {
satok1bc0a492012-04-25 22:47:12 +09003984 setLastInputMethodWindowLw(null, null);
3985 offsetInputMethodWindowLw(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003986 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003987 if (attrs.type == TYPE_VOICE_INTERACTION && win.isVisibleOrBehindKeyguardLw()
3988 && !win.getGivenInsetsPendingLw()) {
3989 offsetVoiceInputWindowLw(win);
3990 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003991 }
3992
satok1bc0a492012-04-25 22:47:12 +09003993 private void offsetInputMethodWindowLw(WindowState win) {
Dianne Hackbornae6688b2015-02-11 17:02:41 -08003994 int top = win.getDisplayFrameLw().top;
satok1bc0a492012-04-25 22:47:12 +09003995 top += win.getGivenContentInsetsLw().top;
3996 if (mContentBottom > top) {
3997 mContentBottom = top;
3998 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003999 if (mVoiceContentBottom > top) {
4000 mVoiceContentBottom = top;
4001 }
satok1bc0a492012-04-25 22:47:12 +09004002 top = win.getVisibleFrameLw().top;
4003 top += win.getGivenVisibleInsetsLw().top;
4004 if (mCurBottom > top) {
4005 mCurBottom = top;
4006 }
Craig Mautnereda67292013-04-28 13:50:14 -07004007 if (DEBUG_LAYOUT) Slog.v(TAG, "Input method: mDockBottom="
satok1bc0a492012-04-25 22:47:12 +09004008 + mDockBottom + " mContentBottom="
4009 + mContentBottom + " mCurBottom=" + mCurBottom);
4010 }
4011
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004012 private void offsetVoiceInputWindowLw(WindowState win) {
Dianne Hackbornae6688b2015-02-11 17:02:41 -08004013 int top = win.getDisplayFrameLw().top;
4014 top += win.getGivenContentInsetsLw().top;
4015 if (mVoiceContentBottom > top) {
4016 mVoiceContentBottom = top;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004017 }
4018 }
4019
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004020 /** {@inheritDoc} */
Craig Mautner61ac6bb2012-02-02 17:29:33 -08004021 @Override
4022 public void finishLayoutLw() {
4023 return;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004024 }
4025
4026 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004027 @Override
Craig Mautner39834192012-09-02 07:47:24 -07004028 public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) {
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004029 mTopFullscreenOpaqueWindowState = null;
Adrian Rooscd3884d2015-02-18 17:25:23 +01004030 mTopFullscreenOpaqueOrDimmingWindowState = null;
Craig Mautner2bc789b2014-03-19 19:48:38 -07004031 mAppsToBeHidden.clear();
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004032 mAppsThatDismissKeyguard.clear();
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004033 mForceStatusBar = false;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004034 mForceStatusBarFromKeyguard = false;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08004035 mForcingShowNavBar = false;
4036 mForcingShowNavBarLayer = -1;
RoboErik8a2cfc32014-05-16 11:19:38 -07004037
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004038 mHideLockScreen = false;
4039 mAllowLockscreenWhenOn = false;
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004040 mDismissKeyguard = DISMISS_KEYGUARD_NONE;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004041 mShowingLockscreen = false;
4042 mShowingDream = false;
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004043 mWinShowWhenLocked = null;
Jim Millerab954542014-10-10 18:21:49 -07004044 mKeyguardSecure = isKeyguardSecure();
4045 mKeyguardSecureIncludingHidden = mKeyguardSecure
4046 && (mKeyguardDelegate != null && mKeyguardDelegate.isShowing());
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004047 }
4048
4049 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004050 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004051 public void applyPostLayoutPolicyLw(WindowState win, WindowManager.LayoutParams attrs) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004052 if (DEBUG_LAYOUT) Slog.i(TAG, "Win " + win + ": isVisibleOrBehindKeyguardLw="
4053 + win.isVisibleOrBehindKeyguardLw());
John Spurlockc6d1c602014-01-17 15:22:06 -05004054 final int fl = PolicyControl.getWindowFlags(win, attrs);
John Spurlock414c1f02013-12-04 13:47:36 -05004055 if (mTopFullscreenOpaqueWindowState == null
4056 && win.isVisibleLw() && attrs.type == TYPE_INPUT_METHOD) {
4057 mForcingShowNavBar = true;
4058 mForcingShowNavBarLayer = win.getSurfaceLayer();
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08004059 }
Jorim Jaggiafd4a552014-04-08 15:13:05 +02004060 if (attrs.type == TYPE_STATUS_BAR && (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Jorim Jaggiafd4a552014-04-08 15:13:05 +02004061 mForceStatusBarFromKeyguard = true;
4062 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004063 if (mTopFullscreenOpaqueWindowState == null &&
Dianne Hackborn01b02a72012-01-12 14:05:03 -08004064 win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()) {
John Spurlockc6d1c602014-01-17 15:22:06 -05004065 if ((fl & FLAG_FORCE_NOT_FULLSCREEN) != 0) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004066 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004067 mForceStatusBarFromKeyguard = true;
4068 } else {
4069 mForceStatusBar = true;
4070 }
4071 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004072 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004073 mShowingLockscreen = true;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004074 }
Craig Mautnerab55e522014-03-03 13:26:03 -08004075 boolean appWindow = attrs.type >= FIRST_APPLICATION_WINDOW
Craig Mautner7d7808f2014-09-11 18:02:38 -07004076 && attrs.type < FIRST_SYSTEM_WINDOW;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004077 if (attrs.type == TYPE_DREAM) {
Jeff Brownc8018eb2012-10-29 21:33:27 -07004078 // If the lockscreen was showing when the dream started then wait
4079 // for the dream to draw before hiding the lockscreen.
4080 if (!mDreamingLockscreen
4081 || (win.isVisibleLw() && win.hasDrawnLw())) {
4082 mShowingDream = true;
Craig Mautnerab55e522014-03-03 13:26:03 -08004083 appWindow = true;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004084 }
4085 }
Craig Mautnerab55e522014-03-03 13:26:03 -08004086
Craig Mautner00156ec2014-03-06 22:29:02 -08004087 final boolean showWhenLocked = (fl & FLAG_SHOW_WHEN_LOCKED) != 0;
Craig Mautner74ee9382014-04-01 15:20:16 -07004088 final boolean dismissKeyguard = (fl & FLAG_DISMISS_KEYGUARD) != 0;
Craig Mautnerab55e522014-03-03 13:26:03 -08004089 if (appWindow) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004090 final IApplicationToken appToken = win.getAppToken();
4091 if (showWhenLocked) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004092 // Remove any previous windows with the same appToken.
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004093 mAppsToBeHidden.remove(appToken);
4094 mAppsThatDismissKeyguard.remove(appToken);
Craig Mautnerca0a1242014-12-02 12:25:14 -08004095 if (mAppsToBeHidden.isEmpty()) {
Craig Mautner192d6042014-12-02 23:24:48 -08004096 if (dismissKeyguard && !mKeyguardSecure) {
4097 mAppsThatDismissKeyguard.add(appToken);
4098 } else {
Craig Mautnerca0a1242014-12-02 12:25:14 -08004099 mWinShowWhenLocked = win;
4100 mHideLockScreen = true;
4101 mForceStatusBarFromKeyguard = false;
Craig Mautnerca0a1242014-12-02 12:25:14 -08004102 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004103 }
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004104 } else if (dismissKeyguard) {
Jim Millerab954542014-10-10 18:21:49 -07004105 if (mKeyguardSecure) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004106 mAppsToBeHidden.add(appToken);
4107 } else {
4108 mAppsToBeHidden.remove(appToken);
4109 }
4110 mAppsThatDismissKeyguard.add(appToken);
Craig Mautner2bc789b2014-03-19 19:48:38 -07004111 } else {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004112 mAppsToBeHidden.add(appToken);
Craig Mautner2bc789b2014-03-19 19:48:38 -07004113 }
Craig Mautnerab55e522014-03-03 13:26:03 -08004114 if (attrs.x == 0 && attrs.y == 0
4115 && attrs.width == WindowManager.LayoutParams.MATCH_PARENT
4116 && attrs.height == WindowManager.LayoutParams.MATCH_PARENT) {
4117 if (DEBUG_LAYOUT) Slog.v(TAG, "Fullscreen window: " + win);
4118 mTopFullscreenOpaqueWindowState = win;
Adrian Rooscd3884d2015-02-18 17:25:23 +01004119 if (mTopFullscreenOpaqueOrDimmingWindowState == null) {
4120 mTopFullscreenOpaqueOrDimmingWindowState = win;
4121 }
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004122 if (!mAppsThatDismissKeyguard.isEmpty() &&
4123 mDismissKeyguard == DISMISS_KEYGUARD_NONE) {
4124 if (DEBUG_LAYOUT) Slog.v(TAG,
4125 "Setting mDismissKeyguard true by win " + win);
4126 mDismissKeyguard = mWinDismissingKeyguard == win ?
4127 DISMISS_KEYGUARD_CONTINUE : DISMISS_KEYGUARD_START;
4128 mWinDismissingKeyguard = win;
Jim Millerab954542014-10-10 18:21:49 -07004129 mForceStatusBarFromKeyguard = mShowingLockscreen && mKeyguardSecure;
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004130 } else if (mAppsToBeHidden.isEmpty() && showWhenLocked) {
4131 if (DEBUG_LAYOUT) Slog.v(TAG,
4132 "Setting mHideLockScreen to true by win " + win);
4133 mHideLockScreen = true;
4134 mForceStatusBarFromKeyguard = false;
Craig Mautnerab55e522014-03-03 13:26:03 -08004135 }
Craig Mautner00156ec2014-03-06 22:29:02 -08004136 if ((fl & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) {
Craig Mautnerab55e522014-03-03 13:26:03 -08004137 mAllowLockscreenWhenOn = true;
4138 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004139 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004140
4141 if (mWinShowWhenLocked != null &&
4142 mWinShowWhenLocked.getAppToken() != win.getAppToken()) {
4143 win.hideLw(false);
4144 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004145 }
4146 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01004147 if (mTopFullscreenOpaqueOrDimmingWindowState == null
4148 && win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()
4149 && win.isDimming()) {
4150 mTopFullscreenOpaqueOrDimmingWindowState = win;
4151 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004152 }
4153
4154 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004155 @Override
Craig Mautner39834192012-09-02 07:47:24 -07004156 public int finishPostLayoutPolicyLw() {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004157 if (mWinShowWhenLocked != null &&
4158 mWinShowWhenLocked != mTopFullscreenOpaqueWindowState) {
4159 // A dialog is dismissing the keyguard. Put the wallpaper behind it and hide the
4160 // fullscreen window.
4161 // TODO: Make sure FLAG_SHOW_WALLPAPER is restored when dialog is dismissed. Or not.
4162 mWinShowWhenLocked.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
4163 mTopFullscreenOpaqueWindowState.hideLw(false);
4164 mTopFullscreenOpaqueWindowState = mWinShowWhenLocked;
4165 }
4166
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004167 int changes = 0;
Joe Onorato93056472010-09-10 10:30:46 -04004168 boolean topIsFullscreen = false;
Daniel Sandlere02d8082010-10-08 15:13:22 -04004169
4170 final WindowManager.LayoutParams lp = (mTopFullscreenOpaqueWindowState != null)
4171 ? mTopFullscreenOpaqueWindowState.getAttrs()
4172 : null;
4173
Jeff Brownc8018eb2012-10-29 21:33:27 -07004174 // If we are not currently showing a dream then remember the current
4175 // lockscreen state. We will use this to determine whether the dream
4176 // started while the lockscreen was showing and remember this state
4177 // while the dream is showing.
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004178 if (!mShowingDream) {
4179 mDreamingLockscreen = mShowingLockscreen;
4180 }
4181
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004182 if (mStatusBar != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07004183 if (DEBUG_LAYOUT) Slog.i(TAG, "force=" + mForceStatusBar
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004184 + " forcefkg=" + mForceStatusBarFromKeyguard
Dianne Hackbornd70bc2f2009-10-06 23:25:51 -07004185 + " top=" + mTopFullscreenOpaqueWindowState);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004186 if (mForceStatusBar || mForceStatusBarFromKeyguard) {
Craig Mautnereda67292013-04-28 13:50:14 -07004187 if (DEBUG_LAYOUT) Slog.v(TAG, "Showing status bar: forced");
John Spurlock27735a42013-08-14 17:57:38 -04004188 if (mStatusBarController.setBarShowingLw(true)) {
4189 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4190 }
Craig Mautner81defc72013-10-29 11:10:42 -07004191 // Maintain fullscreen layout until incoming animation is complete.
4192 topIsFullscreen = mTopIsFullscreen && mStatusBar.isAnimatingLw();
John Spurlockf92b6162013-11-11 15:01:16 -05004193 // Transient status bar on the lockscreen is not allowed
4194 if (mForceStatusBarFromKeyguard && mStatusBarController.isTransientShowing()) {
4195 mStatusBarController.updateVisibilityLw(false /*transientAllowed*/,
4196 mLastSystemUiFlags, mLastSystemUiFlags);
4197 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004198 } else if (mTopFullscreenOpaqueWindowState != null) {
John Spurlockc6d1c602014-01-17 15:22:06 -05004199 final int fl = PolicyControl.getWindowFlags(null, lp);
Joe Onorato93056472010-09-10 10:30:46 -04004200 if (localLOGV) {
Craig Mautnereda67292013-04-28 13:50:14 -07004201 Slog.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw()
Joe Onorato93056472010-09-10 10:30:46 -04004202 + " shown frame: " + mTopFullscreenOpaqueWindowState.getShownFrameLw());
Craig Mautnereda67292013-04-28 13:50:14 -07004203 Slog.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs()
John Spurlockc6d1c602014-01-17 15:22:06 -05004204 + " lp.flags=0x" + Integer.toHexString(fl));
Joe Onorato93056472010-09-10 10:30:46 -04004205 }
John Spurlockc6d1c602014-01-17 15:22:06 -05004206 topIsFullscreen = (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004207 || (mLastSystemUiFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
Joe Onorato93056472010-09-10 10:30:46 -04004208 // The subtle difference between the window for mTopFullscreenOpaqueWindowState
Mark Dolinerd0646dc2014-08-27 16:04:02 -07004209 // and mTopIsFullscreen is that mTopIsFullscreen is set only if the window
Joe Onorato93056472010-09-10 10:30:46 -04004210 // has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the
4211 // case though.
John Spurlock27735a42013-08-14 17:57:38 -04004212 if (mStatusBarController.isTransientShowing()) {
4213 if (mStatusBarController.setBarShowingLw(true)) {
John Spurlock32beb2c2013-03-11 10:16:47 -04004214 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4215 }
4216 } else if (topIsFullscreen) {
Craig Mautnereda67292013-04-28 13:50:14 -07004217 if (DEBUG_LAYOUT) Slog.v(TAG, "** HIDING status bar");
John Spurlock27735a42013-08-14 17:57:38 -04004218 if (mStatusBarController.setBarShowingLw(false)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004219 changes |= FINISH_LAYOUT_REDO_LAYOUT;
Craig Mautnereda67292013-04-28 13:50:14 -07004220 } else {
Craig Mautnerc5a6e442013-06-05 17:22:35 -07004221 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar already hiding");
Daniel Sandler40427442010-07-16 11:44:52 -04004222 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004223 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07004224 if (DEBUG_LAYOUT) Slog.v(TAG, "** SHOWING status bar: top is not fullscreen");
John Spurlock27735a42013-08-14 17:57:38 -04004225 if (mStatusBarController.setBarShowingLw(true)) {
4226 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4227 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004228 }
4229 }
4230 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04004231
Craig Mautner81defc72013-10-29 11:10:42 -07004232 if (mTopIsFullscreen != topIsFullscreen) {
4233 if (!topIsFullscreen) {
4234 // Force another layout when status bar becomes fully shown.
4235 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4236 }
4237 mTopIsFullscreen = topIsFullscreen;
4238 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04004239
Craig Mautner39834192012-09-02 07:47:24 -07004240 // Hide the key guard if a visible window explicitly specifies that it wants to be
4241 // displayed when the screen is locked.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004242 if (mKeyguardDelegate != null && mStatusBar != null) {
4243 if (localLOGV) Slog.v(TAG, "finishPostLayoutPolicyLw: mHideKeyguard="
4244 + mHideLockScreen);
Jim Millerab954542014-10-10 18:21:49 -07004245 if (mDismissKeyguard != DISMISS_KEYGUARD_NONE && !mKeyguardSecure) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004246 mKeyguardHidden = true;
Jim Millerab954542014-10-10 18:21:49 -07004247 if (setKeyguardOccludedLw(true)) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004248 changes |= FINISH_LAYOUT_REDO_LAYOUT
4249 | FINISH_LAYOUT_REDO_CONFIG
4250 | FINISH_LAYOUT_REDO_WALLPAPER;
4251 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004252 if (mKeyguardDelegate.isShowing()) {
4253 mHandler.post(new Runnable() {
4254 @Override
4255 public void run() {
4256 mKeyguardDelegate.keyguardDone(false, false);
4257 }
4258 });
4259 }
4260 } else if (mHideLockScreen) {
4261 mKeyguardHidden = true;
Jim Millerab954542014-10-10 18:21:49 -07004262 if (setKeyguardOccludedLw(true)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004263 changes |= FINISH_LAYOUT_REDO_LAYOUT
4264 | FINISH_LAYOUT_REDO_CONFIG
4265 | FINISH_LAYOUT_REDO_WALLPAPER;
4266 }
4267 } else if (mDismissKeyguard != DISMISS_KEYGUARD_NONE) {
4268 // This is the case of keyguard isSecure() and not mHideLockScreen.
4269 if (mDismissKeyguard == DISMISS_KEYGUARD_START) {
4270 // Only launch the next keyguard unlock window once per window.
4271 mKeyguardHidden = false;
Jim Millerab954542014-10-10 18:21:49 -07004272 if (setKeyguardOccludedLw(false)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004273 changes |= FINISH_LAYOUT_REDO_LAYOUT
4274 | FINISH_LAYOUT_REDO_CONFIG
4275 | FINISH_LAYOUT_REDO_WALLPAPER;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004276 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004277 mHandler.post(new Runnable() {
4278 @Override
4279 public void run() {
4280 mKeyguardDelegate.dismiss();
4281 }
4282 });
4283 }
4284 } else {
4285 mWinDismissingKeyguard = null;
4286 mKeyguardHidden = false;
Jim Millerab954542014-10-10 18:21:49 -07004287 if (setKeyguardOccludedLw(false)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004288 changes |= FINISH_LAYOUT_REDO_LAYOUT
4289 | FINISH_LAYOUT_REDO_CONFIG
4290 | FINISH_LAYOUT_REDO_WALLPAPER;
4291 }
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -07004292 }
4293 }
Joe Onorato664644d2011-01-23 17:53:23 -08004294
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004295 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004296 // If the navigation bar has been hidden or shown, we need to do another
4297 // layout pass to update that window.
4298 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4299 }
Joe Onorato664644d2011-01-23 17:53:23 -08004300
Mike Lockwood28569302010-01-28 11:54:40 -05004301 // update since mAllowLockscreenWhenOn might have changed
4302 updateLockScreenTimeout();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004303 return changes;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004304 }
4305
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004306 /**
Jim Millerab954542014-10-10 18:21:49 -07004307 * Updates the occluded state of the Keyguard.
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004308 *
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004309 * @return Whether the flags have changed and we have to redo the layout.
4310 */
Jim Millerab954542014-10-10 18:21:49 -07004311 private boolean setKeyguardOccludedLw(boolean isOccluded) {
4312 boolean wasOccluded = mKeyguardOccluded;
4313 boolean showing = mKeyguardDelegate.isShowing();
4314 if (wasOccluded && !isOccluded && showing) {
4315 mKeyguardOccluded = false;
4316 mKeyguardDelegate.setOccluded(false);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004317 mStatusBar.getAttrs().privateFlags |= PRIVATE_FLAG_KEYGUARD;
4318 mStatusBar.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
4319 return true;
Jim Millerab954542014-10-10 18:21:49 -07004320 } else if (!wasOccluded && isOccluded && showing) {
4321 mKeyguardOccluded = true;
4322 mKeyguardDelegate.setOccluded(true);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004323 mStatusBar.getAttrs().privateFlags &= ~PRIVATE_FLAG_KEYGUARD;
4324 mStatusBar.getAttrs().flags &= ~FLAG_SHOW_WALLPAPER;
4325 return true;
4326 } else {
4327 return false;
4328 }
4329 }
4330
4331 private boolean isStatusBarKeyguard() {
4332 return mStatusBar != null
4333 && (mStatusBar.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
4334 }
4335
Jose Lima9546b202014-07-02 17:21:51 -07004336 @Override
Dianne Hackborn08743722009-12-21 12:16:51 -08004337 public boolean allowAppAnimationsLw() {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004338 if (isStatusBarKeyguard() || mShowingDream) {
Craig Mautner28816302013-10-10 20:31:00 -07004339 // If keyguard or dreams is currently visible, no reason to animate behind it.
Dianne Hackborn08743722009-12-21 12:16:51 -08004340 return false;
4341 }
Dianne Hackborn08743722009-12-21 12:16:51 -08004342 return true;
4343 }
4344
Jose Lima9546b202014-07-02 17:21:51 -07004345 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07004346 public int focusChangedLw(WindowState lastFocus, WindowState newFocus) {
Joe Onorato664644d2011-01-23 17:53:23 -08004347 mFocusedWindow = newFocus;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004348 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004349 // If the navigation bar has been hidden or shown, we need to do another
4350 // layout pass to update that window.
4351 return FINISH_LAYOUT_REDO_LAYOUT;
4352 }
4353 return 0;
Joe Onorato664644d2011-01-23 17:53:23 -08004354 }
4355
Dianne Hackborn0ecadf72009-03-31 18:00:37 -07004356 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07004357 @Override
Jeff Brown46b9ac02010-04-22 18:58:52 -07004358 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
4359 // lid changed state
Jeff Brownc458ce92012-04-30 14:58:40 -07004360 final int newLidState = lidOpen ? LID_OPEN : LID_CLOSED;
4361 if (newLidState == mLidState) {
4362 return;
4363 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004364
Jeff Brownc458ce92012-04-30 14:58:40 -07004365 mLidState = newLidState;
4366 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07004367 updateRotation(true);
Jeff Brownc458ce92012-04-30 14:58:40 -07004368
4369 if (lidOpen) {
Bryce Lee584a4452014-10-21 15:55:55 -07004370 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromLidSwitch);
Jeff Brownc458ce92012-04-30 14:58:40 -07004371 } else if (!mLidControlsSleep) {
Jeff Brown96307042012-07-27 15:51:34 -07004372 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
Jeff Brown46b9ac02010-04-22 18:58:52 -07004373 }
4374 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004375
Michael Wright3818c922014-09-02 13:59:07 -07004376 @Override
4377 public void notifyCameraLensCoverSwitchChanged(long whenNanos, boolean lensCovered) {
4378 int lensCoverState = lensCovered ? CAMERA_LENS_COVERED : CAMERA_LENS_UNCOVERED;
4379 if (mCameraLensCoverState == lensCoverState) {
4380 return;
4381 }
4382 if (mCameraLensCoverState == CAMERA_LENS_COVERED &&
4383 lensCoverState == CAMERA_LENS_UNCOVERED) {
4384 Intent intent;
4385 final boolean keyguardActive = mKeyguardDelegate == null ? false :
4386 mKeyguardDelegate.isShowing();
4387 if (keyguardActive) {
4388 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE);
4389 } else {
4390 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
4391 }
Bryce Lee584a4452014-10-21 15:55:55 -07004392 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromCameraLens);
Michael Wright3818c922014-09-02 13:59:07 -07004393 mContext.startActivityAsUser(intent, UserHandle.CURRENT_OR_SELF);
4394 }
4395 mCameraLensCoverState = lensCoverState;
4396 }
4397
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004398 void setHdmiPlugged(boolean plugged) {
4399 if (mHdmiPlugged != plugged) {
4400 mHdmiPlugged = plugged;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004401 updateRotation(true, true);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004402 Intent intent = new Intent(ACTION_HDMI_PLUGGED);
Joe Onoratodc100302011-01-11 17:07:41 -08004403 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004404 intent.putExtra(EXTRA_HDMI_PLUGGED_STATE, plugged);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07004405 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004406 }
4407 }
4408
Joe Onoratoea495d42011-04-06 11:41:11 -07004409 void initializeHdmiState() {
Joe Onorato7ba631f2011-05-04 15:28:00 -07004410 boolean plugged = false;
Joe Onoratoea495d42011-04-06 11:41:11 -07004411 // watch for HDMI plug messages if the hdmi switch exists
4412 if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) {
4413 mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi");
4414
Joe Onoratoea495d42011-04-06 11:41:11 -07004415 final String filename = "/sys/class/switch/hdmi/state";
4416 FileReader reader = null;
4417 try {
4418 reader = new FileReader(filename);
4419 char[] buf = new char[15];
4420 int n = reader.read(buf);
4421 if (n > 1) {
4422 plugged = 0 != Integer.parseInt(new String(buf, 0, n-1));
4423 }
4424 } catch (IOException ex) {
4425 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
4426 } catch (NumberFormatException ex) {
4427 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
4428 } finally {
4429 if (reader != null) {
4430 try {
4431 reader.close();
4432 } catch (IOException ex) {
4433 }
Joe Onoratodc100302011-01-11 17:07:41 -08004434 }
4435 }
4436 }
Joe Onorato7ba631f2011-05-04 15:28:00 -07004437 // This dance forces the code in setHdmiPlugged to run.
4438 // Always do this so the sticky intent is stuck (to false) if there is no hdmi.
4439 mHdmiPlugged = !plugged;
4440 setHdmiPlugged(!mHdmiPlugged);
Joe Onoratodc100302011-01-11 17:07:41 -08004441 }
4442
Dianne Hackbornc0e3f242011-08-19 14:19:10 -07004443 final Object mScreenshotLock = new Object();
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004444 ServiceConnection mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004445
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004446 final Runnable mScreenshotTimeout = new Runnable() {
4447 @Override public void run() {
4448 synchronized (mScreenshotLock) {
4449 if (mScreenshotConnection != null) {
4450 mContext.unbindService(mScreenshotConnection);
4451 mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004452 }
Winson Chung9112ec32011-06-27 13:15:32 -07004453 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004454 }
4455 };
4456
4457 // Assume this is called from the Handler thread.
4458 private void takeScreenshot() {
4459 synchronized (mScreenshotLock) {
4460 if (mScreenshotConnection != null) {
4461 return;
4462 }
4463 ComponentName cn = new ComponentName("com.android.systemui",
4464 "com.android.systemui.screenshot.TakeScreenshotService");
4465 Intent intent = new Intent();
4466 intent.setComponent(cn);
4467 ServiceConnection conn = new ServiceConnection() {
4468 @Override
4469 public void onServiceConnected(ComponentName name, IBinder service) {
4470 synchronized (mScreenshotLock) {
4471 if (mScreenshotConnection != this) {
4472 return;
4473 }
4474 Messenger messenger = new Messenger(service);
4475 Message msg = Message.obtain(null, 1);
4476 final ServiceConnection myConn = this;
4477 Handler h = new Handler(mHandler.getLooper()) {
4478 @Override
4479 public void handleMessage(Message msg) {
4480 synchronized (mScreenshotLock) {
4481 if (mScreenshotConnection == myConn) {
4482 mContext.unbindService(mScreenshotConnection);
4483 mScreenshotConnection = null;
4484 mHandler.removeCallbacks(mScreenshotTimeout);
4485 }
4486 }
4487 }
4488 };
4489 msg.replyTo = new Messenger(h);
Winson Chunga63bb842011-10-17 10:26:28 -07004490 msg.arg1 = msg.arg2 = 0;
4491 if (mStatusBar != null && mStatusBar.isVisibleLw())
4492 msg.arg1 = 1;
4493 if (mNavigationBar != null && mNavigationBar.isVisibleLw())
4494 msg.arg2 = 1;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004495 try {
4496 messenger.send(msg);
4497 } catch (RemoteException e) {
4498 }
4499 }
4500 }
4501 @Override
4502 public void onServiceDisconnected(ComponentName name) {}
4503 };
Amith Yamasani27b89e62013-01-16 12:30:11 -08004504 if (mContext.bindServiceAsUser(
4505 intent, conn, Context.BIND_AUTO_CREATE, UserHandle.CURRENT)) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004506 mScreenshotConnection = conn;
4507 mHandler.postDelayed(mScreenshotTimeout, 10000);
4508 }
4509 }
Winson Chung9112ec32011-06-27 13:15:32 -07004510 }
4511
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004512 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004513 @Override
Jeff Brown037c33e2014-04-09 00:31:55 -07004514 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) {
Jeff Brown96307042012-07-27 15:51:34 -07004515 if (!mSystemBooted) {
4516 // If we have not yet booted, don't let key events do anything.
4517 return 0;
4518 }
4519
Jeff Brown037c33e2014-04-09 00:31:55 -07004520 final boolean interactive = (policyFlags & FLAG_INTERACTIVE) != 0;
Jeff Brown1f245102010-11-18 20:53:46 -08004521 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
4522 final boolean canceled = event.isCanceled();
4523 final int keyCode = event.getKeyCode();
Jeff Browne20c9e02010-10-11 14:20:19 -07004524
Jeff Brown3122e442010-10-11 23:32:49 -07004525 final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0;
Jeff Brown3122e442010-10-11 23:32:49 -07004526
Mike Lockwoodc72b15f2009-11-28 20:58:22 -05004527 // If screen is off then we treat the case where the keyguard is open but hidden
4528 // the same as if it were open and in front.
4529 // This will prevent any keys other than the power button from waking the screen
4530 // when the keyguard is hidden by another activity.
Jim Miller5ecd8112013-01-09 18:50:26 -08004531 final boolean keyguardActive = (mKeyguardDelegate == null ? false :
Jeff Brown037c33e2014-04-09 00:31:55 -07004532 (interactive ?
Jim Millerab954542014-10-10 18:21:49 -07004533 isKeyguardShowingAndNotOccluded() :
Jim Miller5ecd8112013-01-09 18:50:26 -08004534 mKeyguardDelegate.isShowing()));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004535
Jeff Brown40013652012-05-16 21:22:36 -07004536 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004537 Log.d(TAG, "interceptKeyTq keycode=" + keyCode
Jeff Brown037c33e2014-04-09 00:31:55 -07004538 + " interactive=" + interactive + " keyguardActive=" + keyguardActive
Jeff Brown26875502014-01-30 21:47:47 -08004539 + " policyFlags=" + Integer.toHexString(policyFlags));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004540 }
4541
Jeff Brown037c33e2014-04-09 00:31:55 -07004542 // Basic policy based on interactive state.
Jeff Brown4d396052010-10-29 21:50:21 -07004543 int result;
Michael Wright337d9d22014-04-22 15:03:48 -07004544 boolean isWakeKey = (policyFlags & WindowManagerPolicy.FLAG_WAKE) != 0
4545 || event.isWakeKey();
Michael Wrightfc01f042014-09-08 14:12:24 -07004546 if (interactive || (isInjected && !isWakeKey)) {
RoboErikde9ba392014-09-26 12:51:01 -07004547 // When the device is interactive or the key is injected pass the
4548 // key to the application.
Jeff Brown4d396052010-10-29 21:50:21 -07004549 result = ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07004550 isWakeKey = false;
Michael Wrightfc01f042014-09-08 14:12:24 -07004551 } else if (!interactive && shouldDispatchInputWhenNonInteractive()) {
4552 // If we're currently dozing with the screen on and the keyguard showing, pass the key
4553 // to the application but preserve its wake key status to make sure we still move
4554 // from dozing to fully interactive if we would normally go from off to fully
4555 // interactive.
4556 result = ACTION_PASS_TO_USER;
Jeff Brown4d396052010-10-29 21:50:21 -07004557 } else {
4558 // When the screen is off and the key is not injected, determine whether
4559 // to wake the device but don't pass the key to the application.
4560 result = 0;
Jeff Brown26875502014-01-30 21:47:47 -08004561 if (isWakeKey && (!down || !isWakeKeyWhenScreenOff(keyCode))) {
4562 isWakeKey = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004563 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004564 }
4565
Justin Kohd378ad72013-04-01 12:18:26 -07004566 // If the key would be handled globally, just return the result, don't worry about special
4567 // key processing.
Jeff Brown13f00f02014-10-31 14:45:50 -07004568 if (isValidGlobalKey(keyCode)
4569 && mGlobalKeyManager.shouldHandleGlobalKey(keyCode, event)) {
Michael Wright85b1af62014-06-04 14:51:58 -07004570 if (isWakeKey) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004571 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey);
Michael Wright85b1af62014-06-04 14:51:58 -07004572 }
Justin Kohd378ad72013-04-01 12:18:26 -07004573 return result;
4574 }
4575
Jeff Brownbae8e772014-06-12 19:59:45 -07004576 boolean useHapticFeedback = down
4577 && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0
4578 && event.getRepeatCount() == 0;
4579
Jeff Brown4d396052010-10-29 21:50:21 -07004580 // Handle special keys.
4581 switch (keyCode) {
4582 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jeff Brownb0418da2010-11-01 15:24:01 -07004583 case KeyEvent.KEYCODE_VOLUME_UP:
4584 case KeyEvent.KEYCODE_VOLUME_MUTE: {
RoboErik001c59c2015-01-26 15:53:51 -08004585 if (mUseTvRouting) {
4586 // On TVs volume keys never go to the foreground app
4587 result &= ~ACTION_PASS_TO_USER;
4588 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004589 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
4590 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004591 if (interactive && !mScreenshotChordVolumeDownKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004592 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004593 mScreenshotChordVolumeDownKeyTriggered = true;
4594 mScreenshotChordVolumeDownKeyTime = event.getDownTime();
4595 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004596 cancelPendingPowerKeyAction();
4597 interceptScreenshotChord();
4598 }
4599 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004600 mScreenshotChordVolumeDownKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004601 cancelPendingScreenshotChordAction();
4602 }
4603 } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
4604 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004605 if (interactive && !mScreenshotChordVolumeUpKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004606 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004607 mScreenshotChordVolumeUpKeyTriggered = true;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004608 cancelPendingPowerKeyAction();
4609 cancelPendingScreenshotChordAction();
4610 }
4611 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004612 mScreenshotChordVolumeUpKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004613 cancelPendingScreenshotChordAction();
4614 }
4615 }
Jeff Brown4d396052010-10-29 21:50:21 -07004616 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004617 TelecomManager telecomManager = getTelecommService();
4618 if (telecomManager != null) {
4619 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07004620 // If an incoming call is ringing, either VOLUME key means
4621 // "silence ringer". We handle these keys here, rather than
4622 // in the InCallScreen, to make sure we'll respond to them
4623 // even if the InCallScreen hasn't come to the foreground yet.
4624 // Look for the DOWN event here, to agree with the "fallback"
4625 // behavior in the InCallScreen.
4626 Log.i(TAG, "interceptKeyBeforeQueueing:"
4627 + " VOLUME key-down while ringing: Silence ringer!");
Jeff Brown4d396052010-10-29 21:50:21 -07004628
Santos Cordon6848f722014-05-21 15:22:12 -07004629 // Silence the ringer. (It's safe to call this
4630 // even if the ringer has already been silenced.)
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004631 telecomManager.silenceRinger();
Jeff Brown4d396052010-10-29 21:50:21 -07004632
Santos Cordon6848f722014-05-21 15:22:12 -07004633 // And *don't* pass this key thru to the current activity
4634 // (which is probably the InCallScreen.)
4635 result &= ~ACTION_PASS_TO_USER;
4636 break;
4637 }
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004638 if (telecomManager.isInCall()
Santos Cordon6848f722014-05-21 15:22:12 -07004639 && (result & ACTION_PASS_TO_USER) == 0) {
4640 // If we are in call but we decided not to pass the key to
RoboErik430fc482014-06-12 15:49:20 -07004641 // the application, just pass it to the session service.
4642
4643 MediaSessionLegacyHelper.getHelper(mContext)
RoboErik3c45c292014-07-08 16:47:31 -07004644 .sendVolumeKeyEvent(event, false);
Santos Cordon6848f722014-05-21 15:22:12 -07004645 break;
Jeff Brown4d396052010-10-29 21:50:21 -07004646 }
4647 }
4648
RoboErik430fc482014-06-12 15:49:20 -07004649 if ((result & ACTION_PASS_TO_USER) == 0) {
RoboErik001c59c2015-01-26 15:53:51 -08004650 if (mUseTvRouting) {
4651 dispatchDirectAudioEvent(event);
4652 } else {
4653 // If we aren't passing to the user and no one else
4654 // handled it send it to the session manager to
4655 // figure out.
4656 MediaSessionLegacyHelper.getHelper(mContext)
4657 .sendVolumeKeyEvent(event, true);
4658 }
Jeff Brown4d396052010-10-29 21:50:21 -07004659 break;
4660 }
4661 }
4662 break;
4663 }
4664
4665 case KeyEvent.KEYCODE_ENDCALL: {
4666 result &= ~ACTION_PASS_TO_USER;
4667 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004668 TelecomManager telecomManager = getTelecommService();
Jeff Brown4d396052010-10-29 21:50:21 -07004669 boolean hungUp = false;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004670 if (telecomManager != null) {
4671 hungUp = telecomManager.endCall();
Jeff Brown4d396052010-10-29 21:50:21 -07004672 }
Jeff Brown13f00f02014-10-31 14:45:50 -07004673 if (interactive && !hungUp) {
4674 mEndCallKeyHandled = false;
4675 mHandler.postDelayed(mEndCallLongPress,
4676 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
4677 } else {
4678 mEndCallKeyHandled = true;
4679 }
Jeff Brown4d396052010-10-29 21:50:21 -07004680 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004681 if (!mEndCallKeyHandled) {
4682 mHandler.removeCallbacks(mEndCallLongPress);
4683 if (!canceled) {
4684 if ((mEndcallBehavior
4685 & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) {
4686 if (goHome()) {
4687 break;
4688 }
Dianne Hackborn0041e972009-07-24 17:14:43 -07004689 }
Jeff Brown13f00f02014-10-31 14:45:50 -07004690 if ((mEndcallBehavior
4691 & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) {
4692 mPowerManager.goToSleep(event.getEventTime(),
4693 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
4694 isWakeKey = false;
4695 }
Jeff Brown4d396052010-10-29 21:50:21 -07004696 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004697 }
Jeff Brown4d396052010-10-29 21:50:21 -07004698 }
4699 break;
4700 }
4701
4702 case KeyEvent.KEYCODE_POWER: {
4703 result &= ~ACTION_PASS_TO_USER;
Jeff Brown13f00f02014-10-31 14:45:50 -07004704 isWakeKey = false; // wake-up will be handled separately
Jeff Brown4d396052010-10-29 21:50:21 -07004705 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004706 interceptPowerKeyDown(event, interactive);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004707 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004708 interceptPowerKeyUp(event, interactive, canceled);
Jeff Brown4d396052010-10-29 21:50:21 -07004709 }
4710 break;
4711 }
4712
Jeff Brown6212a492014-03-07 13:58:47 -08004713 case KeyEvent.KEYCODE_SLEEP: {
4714 result &= ~ACTION_PASS_TO_USER;
Jeff Brownbae8e772014-06-12 19:59:45 -07004715 if (!mPowerManager.isInteractive()) {
4716 useHapticFeedback = false; // suppress feedback if already non-interactive
4717 }
Jeff Brownc12035c2014-08-13 18:52:25 -07004718 mPowerManager.goToSleep(event.getEventTime(),
4719 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
Jeff Brown6212a492014-03-07 13:58:47 -08004720 isWakeKey = false;
4721 break;
4722 }
4723
4724 case KeyEvent.KEYCODE_WAKEUP: {
4725 result &= ~ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07004726 isWakeKey = true;
Jeff Brown6212a492014-03-07 13:58:47 -08004727 break;
4728 }
4729
Jeff Brown4d396052010-10-29 21:50:21 -07004730 case KeyEvent.KEYCODE_MEDIA_PLAY:
4731 case KeyEvent.KEYCODE_MEDIA_PAUSE:
4732 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
Jeff Brown4d396052010-10-29 21:50:21 -07004733 case KeyEvent.KEYCODE_HEADSETHOOK:
4734 case KeyEvent.KEYCODE_MUTE:
4735 case KeyEvent.KEYCODE_MEDIA_STOP:
4736 case KeyEvent.KEYCODE_MEDIA_NEXT:
4737 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
4738 case KeyEvent.KEYCODE_MEDIA_REWIND:
4739 case KeyEvent.KEYCODE_MEDIA_RECORD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09004740 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
4741 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: {
RoboErikde9ba392014-09-26 12:51:01 -07004742 if (MediaSessionLegacyHelper.getHelper(mContext).isGlobalPriorityActive()) {
4743 // If the global session is active pass all media keys to it
4744 // instead of the active window.
4745 result &= ~ACTION_PASS_TO_USER;
4746 }
Jeff Brown4d396052010-10-29 21:50:21 -07004747 if ((result & ACTION_PASS_TO_USER) == 0) {
4748 // Only do this if we would otherwise not pass it to the user. In that
4749 // case, the PhoneWindow class will do the same thing, except it will
4750 // only do it if the showing app doesn't process the key on its own.
Jeff Brown40013652012-05-16 21:22:36 -07004751 // Note that we need to make a copy of the key event here because the
4752 // original key event will be recycled when we return.
Jeff Brown4d396052010-10-29 21:50:21 -07004753 mBroadcastWakeLock.acquire();
Jeff Brown40013652012-05-16 21:22:36 -07004754 Message msg = mHandler.obtainMessage(MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK,
4755 new KeyEvent(event));
4756 msg.setAsynchronous(true);
4757 msg.sendToTarget();
Jeff Brown4d396052010-10-29 21:50:21 -07004758 }
4759 break;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004760 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004761
Jeff Brown4d396052010-10-29 21:50:21 -07004762 case KeyEvent.KEYCODE_CALL: {
4763 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004764 TelecomManager telecomManager = getTelecommService();
4765 if (telecomManager != null) {
4766 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07004767 Log.i(TAG, "interceptKeyBeforeQueueing:"
4768 + " CALL key-down while ringing: Answer the call!");
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004769 telecomManager.acceptRingingCall();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004770
Santos Cordon6848f722014-05-21 15:22:12 -07004771 // And *don't* pass this key thru to the current activity
4772 // (which is presumably the InCallScreen.)
4773 result &= ~ACTION_PASS_TO_USER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004774 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004775 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004776 }
Jeff Brown4d396052010-10-29 21:50:21 -07004777 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004778 }
Michael Wright869a67c2014-08-26 19:33:06 -07004779 case KeyEvent.KEYCODE_VOICE_ASSIST: {
4780 // Only do this if we would otherwise not pass it to the user. In that case,
4781 // interceptKeyBeforeDispatching would apply a similar but different policy in
4782 // order to invoke voice assist actions. Note that we need to make a copy of the
4783 // key event here because the original key event will be recycled when we return.
4784 if ((result & ACTION_PASS_TO_USER) == 0 && !down) {
4785 mBroadcastWakeLock.acquire();
4786 Message msg = mHandler.obtainMessage(MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK,
4787 keyguardActive ? 1 : 0, 0);
4788 msg.setAsynchronous(true);
4789 msg.sendToTarget();
4790 }
4791 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004792 }
Jeff Brown26875502014-01-30 21:47:47 -08004793
Jeff Brownbae8e772014-06-12 19:59:45 -07004794 if (useHapticFeedback) {
4795 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
4796 }
4797
Jeff Brown26875502014-01-30 21:47:47 -08004798 if (isWakeKey) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004799 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey);
Jeff Brown26875502014-01-30 21:47:47 -08004800 }
Bryce Lee584a4452014-10-21 15:55:55 -07004801
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004802 return result;
4803 }
4804
Jeff Brown1c2e4942012-11-06 16:32:01 -08004805 /**
Jeff Brown13f00f02014-10-31 14:45:50 -07004806 * Returns true if the key can have global actions attached to it.
4807 * We reserve all power management keys for the system since they require
4808 * very careful handling.
4809 */
4810 private static boolean isValidGlobalKey(int keyCode) {
4811 switch (keyCode) {
4812 case KeyEvent.KEYCODE_POWER:
4813 case KeyEvent.KEYCODE_WAKEUP:
4814 case KeyEvent.KEYCODE_SLEEP:
4815 return false;
4816 default:
4817 return true;
4818 }
4819 }
4820
4821 /**
Jeff Brown1c2e4942012-11-06 16:32:01 -08004822 * When the screen is off we ignore some keys that might otherwise typically
4823 * be considered wake keys. We filter them out here.
4824 *
4825 * {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it
4826 * is always considered a wake key.
4827 */
4828 private boolean isWakeKeyWhenScreenOff(int keyCode) {
4829 switch (keyCode) {
4830 // ignore volume keys unless docked
4831 case KeyEvent.KEYCODE_VOLUME_UP:
4832 case KeyEvent.KEYCODE_VOLUME_DOWN:
4833 case KeyEvent.KEYCODE_VOLUME_MUTE:
4834 return mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED;
4835
4836 // ignore media and camera keys
4837 case KeyEvent.KEYCODE_MUTE:
4838 case KeyEvent.KEYCODE_HEADSETHOOK:
4839 case KeyEvent.KEYCODE_MEDIA_PLAY:
4840 case KeyEvent.KEYCODE_MEDIA_PAUSE:
4841 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
4842 case KeyEvent.KEYCODE_MEDIA_STOP:
4843 case KeyEvent.KEYCODE_MEDIA_NEXT:
4844 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
4845 case KeyEvent.KEYCODE_MEDIA_REWIND:
4846 case KeyEvent.KEYCODE_MEDIA_RECORD:
4847 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09004848 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK:
Jeff Brown1c2e4942012-11-06 16:32:01 -08004849 case KeyEvent.KEYCODE_CAMERA:
4850 return false;
4851 }
4852 return true;
4853 }
4854
4855
Jeff Brown56194eb2011-03-02 19:23:13 -08004856 /** {@inheritDoc} */
4857 @Override
Michael Wright70af00a2014-09-03 19:30:20 -07004858 public int interceptMotionBeforeQueueingNonInteractive(long whenNanos, int policyFlags) {
4859 if ((policyFlags & FLAG_WAKE) != 0) {
Bryce Lee5c138322014-11-03 08:26:09 -08004860 if (wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotion)) {
4861 return 0;
4862 }
Michael Wright70af00a2014-09-03 19:30:20 -07004863 }
Bryce Lee5c138322014-11-03 08:26:09 -08004864
Michael Wright70af00a2014-09-03 19:30:20 -07004865 if (shouldDispatchInputWhenNonInteractive()) {
4866 return ACTION_PASS_TO_USER;
4867 }
Bryce Lee5c138322014-11-03 08:26:09 -08004868
Bryce Lee812d7022014-11-10 13:33:28 -08004869 // If we have not passed the action up and we are in theater mode without dreaming,
4870 // there will be no dream to intercept the touch and wake into ambient. The device should
4871 // wake up in this case.
4872 if (isTheaterModeEnabled() && (policyFlags & FLAG_WAKE) != 0) {
4873 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotionWhenNotDreaming);
4874 }
4875
Jeff Brown037c33e2014-04-09 00:31:55 -07004876 return 0;
Jeff Brown56194eb2011-03-02 19:23:13 -08004877 }
4878
Michael Wright70af00a2014-09-03 19:30:20 -07004879 private boolean shouldDispatchInputWhenNonInteractive() {
Bryce Lee5c138322014-11-03 08:26:09 -08004880 // Send events to keyguard while the screen is on.
Jim Millerab954542014-10-10 18:21:49 -07004881 if (isKeyguardShowingAndNotOccluded() && mDisplay != null
4882 && mDisplay.getState() != Display.STATE_OFF) {
Bryce Lee5c138322014-11-03 08:26:09 -08004883 return true;
4884 }
4885
4886 // Send events to a dozing dream even if the screen is off since the dream
4887 // is in control of the state of the screen.
4888 IDreamManager dreamManager = getDreamManager();
4889
4890 try {
4891 if (dreamManager != null && dreamManager.isDreaming()) {
4892 return true;
4893 }
4894 } catch (RemoteException e) {
4895 Slog.e(TAG, "RemoteException when checking if dreaming", e);
4896 }
4897
4898 // Otherwise, consume events since the user can't see what is being
4899 // interacted with.
4900 return false;
Michael Wright70af00a2014-09-03 19:30:20 -07004901 }
4902
RoboErik001c59c2015-01-26 15:53:51 -08004903 private void dispatchDirectAudioEvent(KeyEvent event) {
4904 if (event.getAction() != KeyEvent.ACTION_DOWN) {
4905 return;
4906 }
4907 int keyCode = event.getKeyCode();
John Spurlockb94f2d62015-03-17 14:11:57 -04004908 int flags = AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_PLAY_SOUND
4909 | AudioManager.FLAG_FROM_KEY;
RoboErik001c59c2015-01-26 15:53:51 -08004910 String pkgName = mContext.getOpPackageName();
4911 switch (keyCode) {
4912 case KeyEvent.KEYCODE_VOLUME_UP:
4913 try {
John Spurlockee5ad722015-03-03 16:17:21 -05004914 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_RAISE,
John Spurlock90874332015-03-10 16:00:54 -04004915 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08004916 } catch (RemoteException e) {
4917 Log.e(TAG, "Error dispatching volume up in dispatchTvAudioEvent.", e);
4918 }
4919 break;
4920 case KeyEvent.KEYCODE_VOLUME_DOWN:
4921 try {
John Spurlockee5ad722015-03-03 16:17:21 -05004922 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_LOWER,
John Spurlock90874332015-03-10 16:00:54 -04004923 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08004924 } catch (RemoteException e) {
4925 Log.e(TAG, "Error dispatching volume down in dispatchTvAudioEvent.", e);
4926 }
4927 break;
4928 case KeyEvent.KEYCODE_VOLUME_MUTE:
4929 try {
4930 if (event.getRepeatCount() == 0) {
John Spurlockee5ad722015-03-03 16:17:21 -05004931 getAudioService().adjustSuggestedStreamVolume(
4932 AudioManager.ADJUST_TOGGLE_MUTE,
John Spurlock90874332015-03-10 16:00:54 -04004933 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08004934 }
4935 } catch (RemoteException e) {
4936 Log.e(TAG, "Error dispatching mute in dispatchTvAudioEvent.", e);
4937 }
4938 break;
4939 }
4940 }
4941
Jeff Brown40013652012-05-16 21:22:36 -07004942 void dispatchMediaKeyWithWakeLock(KeyEvent event) {
4943 if (DEBUG_INPUT) {
4944 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: " + event);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004945 }
4946
Jeff Brown40013652012-05-16 21:22:36 -07004947 if (mHavePendingMediaKeyRepeatWithWakeLock) {
4948 if (DEBUG_INPUT) {
4949 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: canceled repeat");
4950 }
4951
4952 mHandler.removeMessages(MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK);
4953 mHavePendingMediaKeyRepeatWithWakeLock = false;
4954 mBroadcastWakeLock.release(); // pending repeat was holding onto the wake lock
4955 }
4956
4957 dispatchMediaKeyWithWakeLockToAudioService(event);
4958
4959 if (event.getAction() == KeyEvent.ACTION_DOWN
4960 && event.getRepeatCount() == 0) {
4961 mHavePendingMediaKeyRepeatWithWakeLock = true;
4962
4963 Message msg = mHandler.obtainMessage(
4964 MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK, event);
4965 msg.setAsynchronous(true);
4966 mHandler.sendMessageDelayed(msg, ViewConfiguration.getKeyRepeatTimeout());
4967 } else {
4968 mBroadcastWakeLock.release();
4969 }
4970 }
4971
4972 void dispatchMediaKeyRepeatWithWakeLock(KeyEvent event) {
4973 mHavePendingMediaKeyRepeatWithWakeLock = false;
4974
4975 KeyEvent repeatEvent = KeyEvent.changeTimeRepeat(event,
4976 SystemClock.uptimeMillis(), 1, event.getFlags() | KeyEvent.FLAG_LONG_PRESS);
4977 if (DEBUG_INPUT) {
4978 Slog.d(TAG, "dispatchMediaKeyRepeatWithWakeLock: " + repeatEvent);
4979 }
4980
4981 dispatchMediaKeyWithWakeLockToAudioService(repeatEvent);
4982 mBroadcastWakeLock.release();
4983 }
4984
4985 void dispatchMediaKeyWithWakeLockToAudioService(KeyEvent event) {
4986 if (ActivityManagerNative.isSystemReady()) {
RoboErik430fc482014-06-12 15:49:20 -07004987 MediaSessionLegacyHelper.getHelper(mContext).sendMediaButtonEvent(event, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004988 }
4989 }
4990
Michael Wright869a67c2014-08-26 19:33:06 -07004991 void launchVoiceAssistWithWakeLock(boolean keyguardActive) {
4992 Intent voiceIntent =
4993 new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
4994 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, keyguardActive);
4995 mContext.startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
4996 mBroadcastWakeLock.release();
4997 }
4998
Mike Lockwood1753f7f2009-08-24 14:49:07 -07004999 BroadcastReceiver mDockReceiver = new BroadcastReceiver() {
Craig Mautnereee29c42013-01-17 14:44:34 -08005000 @Override
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005001 public void onReceive(Context context, Intent intent) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07005002 if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) {
5003 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
5004 Intent.EXTRA_DOCK_STATE_UNDOCKED);
Daniel Sandler6396c722013-04-16 20:19:09 -04005005 } else {
5006 try {
5007 IUiModeManager uiModeService = IUiModeManager.Stub.asInterface(
5008 ServiceManager.getService(Context.UI_MODE_SERVICE));
5009 mUiMode = uiModeService.getCurrentModeType();
5010 } catch (RemoteException e) {
5011 }
Dianne Hackborn80fa1662009-10-07 14:02:10 -07005012 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005013 updateRotation(true);
Craig Mautnereee29c42013-01-17 14:44:34 -08005014 synchronized (mLock) {
5015 updateOrientationListenerLp();
5016 }
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005017 }
5018 };
5019
Jeff Brown6aaf2952012-10-05 16:01:08 -07005020 BroadcastReceiver mDreamReceiver = new BroadcastReceiver() {
5021 @Override
5022 public void onReceive(Context context, Intent intent) {
5023 if (Intent.ACTION_DREAMING_STARTED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005024 if (mKeyguardDelegate != null) {
5025 mKeyguardDelegate.onDreamingStarted();
Jeff Brown6aaf2952012-10-05 16:01:08 -07005026 }
5027 } else if (Intent.ACTION_DREAMING_STOPPED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005028 if (mKeyguardDelegate != null) {
5029 mKeyguardDelegate.onDreamingStopped();
Jeff Brown6aaf2952012-10-05 16:01:08 -07005030 }
5031 }
5032 }
5033 };
5034
Christopher Tate5e08af02012-09-21 17:17:22 -07005035 BroadcastReceiver mMultiuserReceiver = new BroadcastReceiver() {
5036 @Override
5037 public void onReceive(Context context, Intent intent) {
5038 if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) {
5039 // tickle the settings observer: this first ensures that we're
5040 // observing the relevant settings for the newly-active user,
5041 // and then updates our own bookkeeping based on the now-
5042 // current user.
5043 mSettingsObserver.onChange(false);
John Spurlockce479d82012-11-29 09:52:21 -05005044
5045 // force a re-application of focused window sysui visibility.
5046 // the window may never have been shown for this user
5047 // e.g. the keyguard when going through the new-user setup flow
John Spurlock04db1762013-05-13 12:46:41 -04005048 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
John Spurlockce479d82012-11-29 09:52:21 -05005049 mLastSystemUiFlags = 0;
5050 updateSystemUiVisibilityLw();
5051 }
Christopher Tate5e08af02012-09-21 17:17:22 -07005052 }
5053 }
5054 };
5055
John Spurlockd9b70bd2014-02-06 17:02:44 -05005056 private final Runnable mRequestTransientNav = new Runnable() {
5057 @Override
5058 public void run() {
5059 requestTransientBars(mNavigationBar);
5060 }
5061 };
5062
John Spurlocke1f366f2013-08-05 12:22:40 -04005063 private void requestTransientBars(WindowState swipeTarget) {
John Spurlock04db1762013-05-13 12:46:41 -04005064 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Maurice Lam99c6e072014-04-28 18:24:28 -07005065 if (!isUserSetupComplete()) {
5066 // Swipe-up for navigation bar is disabled during setup
5067 return;
5068 }
John Spurlock27735a42013-08-14 17:57:38 -04005069 boolean sb = mStatusBarController.checkShowTransientBarLw();
5070 boolean nb = mNavigationBarController.checkShowTransientBarLw();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005071 if (sb || nb) {
Adrian Roos62b65e42015-02-25 18:05:34 +01005072 // Don't show status bar when swiping on already visible navigation bar
5073 if (!nb && swipeTarget == mNavigationBar) {
John Spurlocke1f366f2013-08-05 12:22:40 -04005074 if (DEBUG) Slog.d(TAG, "Not showing transient bar, wrong swipe target");
John Spurlockad3e6cb2013-04-30 08:47:43 -04005075 return;
5076 }
John Spurlock27735a42013-08-14 17:57:38 -04005077 if (sb) mStatusBarController.showTransient();
5078 if (nb) mNavigationBarController.showTransient();
John Spurlockf1a36642013-10-12 17:50:42 -04005079 mImmersiveModeConfirmation.confirmCurrentPrompt();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005080 updateSystemUiVisibilityLw();
John Spurlock32beb2c2013-03-11 10:16:47 -04005081 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04005082 }
5083 }
5084
Jeff Brown3ee549c2014-09-22 20:14:39 -07005085 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07005086 @Override
Jeff Brown140ffc72014-05-01 15:18:00 -07005087 public void goingToSleep(int why) {
Dianne Hackborn74489012009-03-24 20:50:09 -07005088 EventLog.writeEvent(70000, 0);
Jeff Brown36c4db82014-09-19 12:05:31 -07005089 if (DEBUG_WAKEUP) Slog.i(TAG, "Going to sleep...");
Jeff Brown3ee549c2014-09-22 20:14:39 -07005090
5091 // We must get this work done here because the power manager will drop
5092 // the wake lock and let the system suspend once this function returns.
The Android Open Source Project0727d222009-03-11 12:11:58 -07005093 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005094 mAwake = false;
5095 mKeyguardDrawComplete = false;
Jeff Browna20dda42014-05-27 20:57:24 -07005096 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005097 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05005098 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005099 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005100
5101 if (mKeyguardDelegate != null) {
5102 mKeyguardDelegate.onScreenTurnedOff(why);
5103 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005104 }
5105
Jeff Brown13f00f02014-10-31 14:45:50 -07005106 private void wakeUpFromPowerKey(long eventTime) {
5107 wakeUp(eventTime, mAllowTheaterModeWakeFromPowerKey);
5108 }
5109
Bryce Lee5c138322014-11-03 08:26:09 -08005110 private boolean wakeUp(long wakeTime, boolean wakeInTheaterMode) {
Bryce Lee584a4452014-10-21 15:55:55 -07005111 if (!wakeInTheaterMode && isTheaterModeEnabled()) {
Bryce Lee5c138322014-11-03 08:26:09 -08005112 return false;
Bryce Lee584a4452014-10-21 15:55:55 -07005113 }
5114
5115 mPowerManager.wakeUp(wakeTime);
Bryce Lee5c138322014-11-03 08:26:09 -08005116 return true;
Bryce Lee584a4452014-10-21 15:55:55 -07005117 }
5118
Jeff Brown3ee549c2014-09-22 20:14:39 -07005119 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07005120 @Override
Jeff Brown36c4db82014-09-19 12:05:31 -07005121 public void wakingUp() {
Dianne Hackborn74489012009-03-24 20:50:09 -07005122 EventLog.writeEvent(70000, 1);
Jeff Brown36c4db82014-09-19 12:05:31 -07005123 if (DEBUG_WAKEUP) Slog.i(TAG, "Waking up...");
Craig Mautner8a0da012014-05-31 15:13:37 -07005124
Jeff Brown3ee549c2014-09-22 20:14:39 -07005125 // Since goToSleep performs these functions synchronously, we must
5126 // do the same here. We cannot post this work to a handler because
5127 // that might cause it to become reordered with respect to what
5128 // may happen in a future call to goToSleep.
The Android Open Source Project0727d222009-03-11 12:11:58 -07005129 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005130 mAwake = true;
5131 mKeyguardDrawComplete = false;
5132 if (mKeyguardDelegate != null) {
5133 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
5134 mHandler.sendEmptyMessageDelayed(MSG_KEYGUARD_DRAWN_TIMEOUT, 1000);
5135 }
5136
Jeff Browna20dda42014-05-27 20:57:24 -07005137 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005138 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05005139 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005140 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005141
Jim Miller5ecd8112013-01-09 18:50:26 -08005142 if (mKeyguardDelegate != null) {
Craig Mautner8a0da012014-05-31 15:13:37 -07005143 mKeyguardDelegate.onScreenTurnedOn(mKeyguardDelegateCallback);
Jeff Brown36c4db82014-09-19 12:05:31 -07005144 // ... eventually calls finishKeyguardDrawn
Jeff Brownc38c9be2012-10-04 13:16:19 -07005145 } else {
Craig Mautner8a0da012014-05-31 15:13:37 -07005146 if (DEBUG_WAKEUP) Slog.d(TAG, "null mKeyguardDelegate: setting mKeyguardDrawComplete.");
Jeff Brown36c4db82014-09-19 12:05:31 -07005147 finishKeyguardDrawn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07005148 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005149 }
5150
Jeff Brown36c4db82014-09-19 12:05:31 -07005151 private void finishKeyguardDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005152 synchronized (mLock) {
5153 if (!mAwake || mKeyguardDrawComplete) {
5154 return; // spurious
5155 }
5156
Jeff Brown36c4db82014-09-19 12:05:31 -07005157 mKeyguardDrawComplete = true;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005158 if (mKeyguardDelegate != null) {
5159 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
5160 }
5161 }
5162
5163 finishScreenTurningOn();
5164 }
5165
5166 // Called on the DisplayManager's DisplayPowerController thread.
5167 @Override
5168 public void screenTurnedOff() {
5169 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turned off...");
5170
5171 synchronized (mLock) {
5172 mScreenOnEarly = false;
5173 mScreenOnFully = false;
5174 mWindowManagerDrawComplete = false;
5175 mScreenOnListener = null;
5176 updateOrientationListenerLp();
Jeff Brown36c4db82014-09-19 12:05:31 -07005177 }
5178 }
5179
Jeff Brown3ee549c2014-09-22 20:14:39 -07005180 // Called on the DisplayManager's DisplayPowerController thread.
Jeff Brown36c4db82014-09-19 12:05:31 -07005181 @Override
5182 public void screenTurningOn(final ScreenOnListener screenOnListener) {
Jeff Brown36c4db82014-09-19 12:05:31 -07005183 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turning on...");
Jeff Brown36c4db82014-09-19 12:05:31 -07005184
Jeff Brown3ee549c2014-09-22 20:14:39 -07005185 synchronized (mLock) {
5186 mScreenOnEarly = true;
5187 mScreenOnFully = false;
5188 mWindowManagerDrawComplete = false;
5189 mScreenOnListener = screenOnListener;
5190 updateOrientationListenerLp();
5191 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005192
Craig Mautnerc3daedd2014-09-13 11:17:23 -07005193 mWindowManagerInternal.waitForAllWindowsDrawn(mWindowManagerDrawCallback,
5194 WAITING_FOR_DRAWN_TIMEOUT);
Jeff Brown36c4db82014-09-19 12:05:31 -07005195 // ... eventually calls finishWindowsDrawn
5196 }
5197
Jeff Brown36c4db82014-09-19 12:05:31 -07005198 private void finishWindowsDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005199 synchronized (mLock) {
5200 if (!mScreenOnEarly || mWindowManagerDrawComplete) {
5201 return; // spurious
5202 }
5203
Jeff Brown36c4db82014-09-19 12:05:31 -07005204 mWindowManagerDrawComplete = true;
Jeff Brown36c4db82014-09-19 12:05:31 -07005205 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005206
5207 finishScreenTurningOn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07005208 }
5209
Craig Mautner8a0da012014-05-31 15:13:37 -07005210 private void finishScreenTurningOn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005211 final ScreenOnListener listener;
5212 final boolean enableScreen;
Jeff Brown36c4db82014-09-19 12:05:31 -07005213 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005214 if (DEBUG_WAKEUP) Slog.d(TAG,
5215 "finishScreenTurningOn: mAwake=" + mAwake
5216 + ", mScreenOnEarly=" + mScreenOnEarly
5217 + ", mScreenOnFully=" + mScreenOnFully
5218 + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete
5219 + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete);
5220
5221 if (mScreenOnFully || !mScreenOnEarly || !mWindowManagerDrawComplete
5222 || (mAwake && !mKeyguardDrawComplete)) {
5223 return; // spurious or not ready yet
Jeff Brown36c4db82014-09-19 12:05:31 -07005224 }
5225
Jeff Brown3ee549c2014-09-22 20:14:39 -07005226 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished screen turning on...");
5227 listener = mScreenOnListener;
Craig Mautner13f6ea72014-06-23 14:57:02 -07005228 mScreenOnListener = null;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005229 mScreenOnFully = true;
5230
5231 // Remember the first time we draw the keyguard so we know when we're done with
5232 // the main part of booting and can enable the screen and hide boot messages.
5233 if (!mKeyguardDrawnOnce && mAwake) {
5234 mKeyguardDrawnOnce = true;
5235 enableScreen = true;
5236 if (mBootMessageNeedsHiding) {
5237 mBootMessageNeedsHiding = false;
5238 hideBootMessages();
5239 }
5240 } else {
5241 enableScreen = false;
5242 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005243 }
5244
Jeff Brown3ee549c2014-09-22 20:14:39 -07005245 if (listener != null) {
5246 listener.onScreenOn();
5247 }
Jeff Brown4fc45272012-10-10 18:28:14 -07005248
Jeff Brown3ee549c2014-09-22 20:14:39 -07005249 if (enableScreen) {
5250 try {
5251 mWindowManager.enableScreenIfNeeded();
5252 } catch (RemoteException unhandled) {
Jeff Brown36c4db82014-09-19 12:05:31 -07005253 }
Craig Mautnera631d492014-08-05 15:16:01 -07005254 }
5255 }
5256
5257 private void handleHideBootMessage() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005258 synchronized (mLock) {
5259 if (!mKeyguardDrawnOnce) {
5260 mBootMessageNeedsHiding = true;
5261 return; // keyguard hasn't drawn the first time yet, not done booting
5262 }
Craig Mautnera631d492014-08-05 15:16:01 -07005263 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005264
5265 if (mBootMsgDialog != null) {
5266 if (DEBUG_WAKEUP) Slog.d(TAG, "handleHideBootMessage: dismissing");
5267 mBootMsgDialog.dismiss();
5268 mBootMsgDialog = null;
Craig Mautnera631d492014-08-05 15:16:01 -07005269 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005270 }
5271
5272 @Override
Jeff Brown3ee549c2014-09-22 20:14:39 -07005273 public boolean isScreenOn() {
5274 return mScreenOnFully;
Dianne Hackborn08743722009-12-21 12:16:51 -08005275 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005276
Dianne Hackborn08743722009-12-21 12:16:51 -08005277 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005278 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005279 public void enableKeyguard(boolean enabled) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005280 if (mKeyguardDelegate != null) {
5281 mKeyguardDelegate.setKeyguardEnabled(enabled);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005282 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005283 }
5284
5285 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005286 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005287 public void exitKeyguardSecurely(OnKeyguardExitResult callback) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005288 if (mKeyguardDelegate != null) {
5289 mKeyguardDelegate.verifyUnlock(callback);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005290 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005291 }
5292
Jim Millerab954542014-10-10 18:21:49 -07005293 private boolean isKeyguardShowingAndNotOccluded() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005294 if (mKeyguardDelegate == null) return false;
Jim Millerab954542014-10-10 18:21:49 -07005295 return mKeyguardDelegate.isShowing() && !mKeyguardOccluded;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005296 }
5297
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005298 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005299 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005300 public boolean isKeyguardLocked() {
5301 return keyguardOn();
5302 }
5303
5304 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005305 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005306 public boolean isKeyguardSecure() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005307 if (mKeyguardDelegate == null) return false;
5308 return mKeyguardDelegate.isSecure();
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005309 }
5310
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005311 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005312 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005313 public boolean inKeyguardRestrictedKeyInputMode() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005314 if (mKeyguardDelegate == null) return false;
5315 return mKeyguardDelegate.isInputRestricted();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005316 }
5317
Jose Lima9546b202014-07-02 17:21:51 -07005318 @Override
Dianne Hackborn90c52de2011-09-23 12:57:44 -07005319 public void dismissKeyguardLw() {
RoboErik8a2cfc32014-05-16 11:19:38 -07005320 if (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()) {
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07005321 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.dismissKeyguardLw");
Daniel Sandler1ce804392012-11-07 15:07:12 -05005322 mHandler.post(new Runnable() {
Jose Lima9546b202014-07-02 17:21:51 -07005323 @Override
Daniel Sandler1ce804392012-11-07 15:07:12 -05005324 public void run() {
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02005325 // ask the keyguard to prompt the user to authenticate if necessary
5326 mKeyguardDelegate.dismiss();
5327 }
5328 });
5329 }
5330 }
5331
5332 public void notifyActivityDrawnForKeyguardLw() {
5333 if (mKeyguardDelegate != null) {
5334 mHandler.post(new Runnable() {
5335 @Override
5336 public void run() {
5337 mKeyguardDelegate.onActivityDrawn();
Daniel Sandler1ce804392012-11-07 15:07:12 -05005338 }
5339 });
Dianne Hackborn90c52de2011-09-23 12:57:44 -07005340 }
5341 }
5342
Jorim Jaggicff0acb2014-03-31 16:35:15 +02005343 @Override
5344 public boolean isKeyguardDrawnLw() {
5345 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005346 return mKeyguardDrawnOnce;
Jorim Jaggicff0acb2014-03-31 16:35:15 +02005347 }
5348 }
5349
Jorim Jaggi0d674622014-05-21 01:34:15 +02005350 @Override
Jorim Jaggie29b2db2014-05-30 23:17:03 +02005351 public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) {
Jorim Jaggi0d674622014-05-21 01:34:15 +02005352 if (mKeyguardDelegate != null) {
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07005353 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.startKeyguardExitAnimation");
Jorim Jaggie29b2db2014-05-30 23:17:03 +02005354 mKeyguardDelegate.startKeyguardExitAnimation(startTime, fadeoutDuration);
Jorim Jaggi0d674622014-05-21 01:34:15 +02005355 }
5356 }
5357
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005358 void sendCloseSystemWindows() {
Jorim Jaggib10e33f2015-02-04 21:57:40 +01005359 PhoneWindow.sendCloseSystemWindows(mContext, null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005360 }
5361
5362 void sendCloseSystemWindows(String reason) {
Jorim Jaggib10e33f2015-02-04 21:57:40 +01005363 PhoneWindow.sendCloseSystemWindows(mContext, reason);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005364 }
Mitsuru Oshima831d0d92009-06-16 18:27:18 -07005365
Jeff Brown01a98dd2011-09-20 15:08:29 -07005366 @Override
5367 public int rotationForOrientationLw(int orientation, int lastRotation) {
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005368 if (false) {
5369 Slog.v(TAG, "rotationForOrientationLw(orient="
5370 + orientation + ", last=" + lastRotation
5371 + "); user=" + mUserRotation + " "
5372 + ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED)
5373 ? "USER_ROTATION_LOCKED" : "")
5374 );
5375 }
5376
Craig Mautner46ac6fa2013-08-01 10:06:34 -07005377 if (mForceDefaultOrientation) {
5378 return Surface.ROTATION_0;
5379 }
5380
The Android Open Source Project0727d222009-03-11 12:11:58 -07005381 synchronized (mLock) {
Jeff Brownc0347aa2011-09-23 17:26:09 -07005382 int sensorRotation = mOrientationListener.getProposedRotation(); // may be -1
5383 if (sensorRotation < 0) {
Jeff Brown0f862b42012-09-27 21:11:01 -07005384 sensorRotation = lastRotation;
Jeff Brownc0347aa2011-09-23 17:26:09 -07005385 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005386
Jeff Browndec6cf42011-11-15 14:08:20 -08005387 final int preferredRotation;
Jeff Brown2e7760e2012-04-11 15:14:55 -07005388 if (mLidState == LID_OPEN && mLidOpenRotation >= 0) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005389 // Ignore sensor when lid switch is open and rotation is forced.
5390 preferredRotation = mLidOpenRotation;
5391 } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR
Jeff Brownc0347aa2011-09-23 17:26:09 -07005392 && (mCarDockEnablesAccelerometer || mCarDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005393 // Ignore sensor when in car dock unless explicitly enabled.
5394 // This case can override the behavior of NOSENSOR, and can also
5395 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07005396 preferredRotation = mCarDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07005397 ? sensorRotation : mCarDockRotation;
Jeff Brown1a693182011-11-08 14:44:16 -08005398 } else if ((mDockMode == Intent.EXTRA_DOCK_STATE_DESK
5399 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
5400 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK)
Jeff Brownc0347aa2011-09-23 17:26:09 -07005401 && (mDeskDockEnablesAccelerometer || mDeskDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005402 // Ignore sensor when in desk dock unless explicitly enabled.
5403 // This case can override the behavior of NOSENSOR, and can also
5404 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07005405 preferredRotation = mDeskDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07005406 ? sensorRotation : mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -07005407 } else if (mHdmiPlugged && mDemoHdmiRotationLock) {
5408 // Ignore sensor when plugged into HDMI when demo HDMI rotation lock enabled.
Jeff Browneb3e4b92011-12-06 19:54:24 -08005409 // Note that the dock orientation overrides the HDMI orientation.
Jeff Brownc82c89ed2013-04-17 17:18:15 -07005410 preferredRotation = mDemoHdmiRotation;
5411 } else if (mHdmiPlugged && mDockMode == Intent.EXTRA_DOCK_STATE_UNDOCKED
5412 && mUndockedHdmiRotation >= 0) {
5413 // Ignore sensor when plugged into HDMI and an undocked orientation has
5414 // been specified in the configuration (only for legacy devices without
5415 // full multi-display support).
5416 // Note that the dock orientation overrides the HDMI orientation.
5417 preferredRotation = mUndockedHdmiRotation;
Chong Zhangae6119ff2014-11-11 18:54:39 -08005418 } else if (mDemoRotationLock) {
5419 // Ignore sensor when demo rotation lock is enabled.
5420 // Note that the dock orientation and HDMI rotation lock override this.
5421 preferredRotation = mDemoRotation;
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005422 } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED) {
5423 // Application just wants to remain locked in the last rotation.
5424 preferredRotation = lastRotation;
Jeff Brownbcdfc622014-03-06 19:13:04 -08005425 } else if (!mSupportAutoRotation) {
5426 // If we don't support auto-rotation then bail out here and ignore
5427 // the sensor and any rotation lock settings.
5428 preferredRotation = -1;
Jeff Brown207673cd2012-06-05 17:47:11 -07005429 } else if ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE
Jeff Brown01a98dd2011-09-20 15:08:29 -07005430 && (orientation == ActivityInfo.SCREEN_ORIENTATION_USER
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005431 || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
5432 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
5433 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
5434 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER))
Jeff Brown01a98dd2011-09-20 15:08:29 -07005435 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
5436 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
5437 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
5438 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) {
5439 // Otherwise, use sensor only if requested by the application or enabled
5440 // by default for USER or UNSPECIFIED modes. Does not apply to NOSENSOR.
Jeff Brownd3187e32011-09-21 19:26:44 -07005441 if (mAllowAllRotations < 0) {
5442 // Can't read this during init() because the context doesn't
5443 // have display metrics at that time so we cannot determine
5444 // tablet vs. phone then.
5445 mAllowAllRotations = mContext.getResources().getBoolean(
5446 com.android.internal.R.bool.config_allowAllRotations) ? 1 : 0;
5447 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005448 if (sensorRotation != Surface.ROTATION_180
Jeff Brownd3187e32011-09-21 19:26:44 -07005449 || mAllowAllRotations == 1
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005450 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
5451 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005452 preferredRotation = sensorRotation;
5453 } else {
5454 preferredRotation = lastRotation;
5455 }
Jeff Brown207673cd2012-06-05 17:47:11 -07005456 } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED
5457 && orientation != ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) {
5458 // Apply rotation lock. Does not apply to NOSENSOR.
5459 // The idea is that the user rotation expresses a weak preference for the direction
5460 // of gravity and as NOSENSOR is never affected by gravity, then neither should
5461 // NOSENSOR be affected by rotation lock (although it will be affected by docks).
Jeff Brown4dfce202011-10-05 12:00:10 -07005462 preferredRotation = mUserRotation;
Jeff Browndec6cf42011-11-15 14:08:20 -08005463 } else {
5464 // No overriding preference.
5465 // We will do exactly what the application asked us to do.
5466 preferredRotation = -1;
Jeff Brown01a98dd2011-09-20 15:08:29 -07005467 }
5468
Dianne Hackborne5439f22010-10-02 16:53:50 -07005469 switch (orientation) {
5470 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08005471 // Return portrait unless overridden.
5472 if (isAnyPortrait(preferredRotation)) {
5473 return preferredRotation;
5474 }
Dianne Hackborne5439f22010-10-02 16:53:50 -07005475 return mPortraitRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005476
Jeff Brown01a98dd2011-09-20 15:08:29 -07005477 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08005478 // Return landscape unless overridden.
5479 if (isLandscapeOrSeascape(preferredRotation)) {
5480 return preferredRotation;
5481 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005482 return mLandscapeRotation;
5483
5484 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08005485 // Return reverse portrait unless overridden.
5486 if (isAnyPortrait(preferredRotation)) {
5487 return preferredRotation;
5488 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005489 return mUpsideDownRotation;
5490
5491 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08005492 // Return seascape unless overridden.
5493 if (isLandscapeOrSeascape(preferredRotation)) {
5494 return preferredRotation;
5495 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005496 return mSeascapeRotation;
5497
5498 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005499 case ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE:
Jeff Brown01a98dd2011-09-20 15:08:29 -07005500 // Return either landscape rotation.
5501 if (isLandscapeOrSeascape(preferredRotation)) {
5502 return preferredRotation;
5503 }
5504 if (isLandscapeOrSeascape(lastRotation)) {
Jeff Brown4519f072011-01-23 13:16:01 -08005505 return lastRotation;
5506 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005507 return mLandscapeRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005508
Jeff Brown01a98dd2011-09-20 15:08:29 -07005509 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005510 case ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT:
Jeff Brown01a98dd2011-09-20 15:08:29 -07005511 // Return either portrait rotation.
5512 if (isAnyPortrait(preferredRotation)) {
5513 return preferredRotation;
5514 }
5515 if (isAnyPortrait(lastRotation)) {
5516 return lastRotation;
5517 }
5518 return mPortraitRotation;
5519
5520 default:
Jeff Brown4dfce202011-10-05 12:00:10 -07005521 // For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR,
5522 // just return the preferred orientation we already calculated.
Jeff Brown01a98dd2011-09-20 15:08:29 -07005523 if (preferredRotation >= 0) {
5524 return preferredRotation;
5525 }
Dianne Hackborndacea8c2011-04-21 17:26:39 -07005526 return Surface.ROTATION_0;
Daniel Sandlere7e5ac22011-02-22 16:10:21 -05005527 }
5528 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07005529 }
5530
Jeff Brown01a98dd2011-09-20 15:08:29 -07005531 @Override
5532 public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation) {
5533 switch (orientation) {
5534 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
5535 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
5536 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
5537 return isAnyPortrait(rotation);
5538
5539 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
5540 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
5541 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
5542 return isLandscapeOrSeascape(rotation);
5543
5544 default:
5545 return true;
5546 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07005547 }
5548
Jeff Brownc0347aa2011-09-23 17:26:09 -07005549 @Override
5550 public void setRotationLw(int rotation) {
5551 mOrientationListener.setCurrentRotation(rotation);
5552 }
5553
Jeff Brown01a98dd2011-09-20 15:08:29 -07005554 private boolean isLandscapeOrSeascape(int rotation) {
5555 return rotation == mLandscapeRotation || rotation == mSeascapeRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005556 }
5557
Jeff Brown01a98dd2011-09-20 15:08:29 -07005558 private boolean isAnyPortrait(int rotation) {
5559 return rotation == mPortraitRotation || rotation == mUpsideDownRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005560 }
5561
Jose Lima9546b202014-07-02 17:21:51 -07005562 @Override
Svetoslav Ganov80943d82013-01-02 10:25:37 -08005563 public int getUserRotationMode() {
5564 return Settings.System.getIntForUser(mContext.getContentResolver(),
Brett Chabot7e55c402013-05-16 19:38:08 -07005565 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
5566 WindowManagerPolicy.USER_ROTATION_FREE :
5567 WindowManagerPolicy.USER_ROTATION_LOCKED;
Svetoslav Ganov80943d82013-01-02 10:25:37 -08005568 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005569
5570 // User rotation: to be used when all else fails in assigning an orientation to the device
Jose Lima9546b202014-07-02 17:21:51 -07005571 @Override
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005572 public void setUserRotationMode(int mode, int rot) {
5573 ContentResolver res = mContext.getContentResolver();
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005574
5575 // mUserRotationMode and mUserRotation will be assigned by the content observer
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005576 if (mode == WindowManagerPolicy.USER_ROTATION_LOCKED) {
Christopher Tate5e08af02012-09-21 17:17:22 -07005577 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005578 Settings.System.USER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005579 rot,
5580 UserHandle.USER_CURRENT);
5581 Settings.System.putIntForUser(res,
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005582 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005583 0,
5584 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005585 } else {
Christopher Tate5e08af02012-09-21 17:17:22 -07005586 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005587 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005588 1,
5589 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005590 }
5591 }
5592
Jose Lima9546b202014-07-02 17:21:51 -07005593 @Override
Jeff Brownac143512012-04-05 18:57:33 -07005594 public void setSafeMode(boolean safeMode) {
5595 mSafeMode = safeMode;
5596 performHapticFeedbackLw(null, safeMode
5597 ? HapticFeedbackConstants.SAFE_MODE_ENABLED
5598 : HapticFeedbackConstants.SAFE_MODE_DISABLED, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005599 }
Craig Mautnereda67292013-04-28 13:50:14 -07005600
Dianne Hackborn181ceb52009-08-27 22:16:40 -07005601 static long[] getLongIntArray(Resources r, int resid) {
5602 int[] ar = r.getIntArray(resid);
5603 if (ar == null) {
5604 return null;
5605 }
5606 long[] out = new long[ar.length];
5607 for (int i=0; i<ar.length; i++) {
5608 out[i] = ar[i];
5609 }
5610 return out;
5611 }
Craig Mautnereda67292013-04-28 13:50:14 -07005612
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005613 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07005614 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005615 public void systemReady() {
Jim Millerab954542014-10-10 18:21:49 -07005616 mKeyguardDelegate = new KeyguardServiceDelegate(mContext);
Mike Lockwooded8902d2013-11-15 11:01:47 -08005617 mKeyguardDelegate.onSystemReady();
5618
Michael Wright3818c922014-09-02 13:59:07 -07005619 readCameraLensCoverState();
Jeff Brown4f5fa282014-06-12 19:19:15 -07005620 updateUiMode();
Dianne Hackbornb1a79802009-09-29 15:18:31 -07005621 synchronized (mLock) {
5622 updateOrientationListenerLp();
Dianne Hackbornc777e072010-02-12 13:07:59 -08005623 mSystemReady = true;
5624 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07005625 @Override
Dianne Hackbornc777e072010-02-12 13:07:59 -08005626 public void run() {
5627 updateSettings();
5628 }
5629 });
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005630 }
5631 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07005632
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005633 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005634 @Override
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005635 public void systemBooted() {
Jim Millere5f910a2013-10-16 18:15:46 -07005636 if (mKeyguardDelegate != null) {
Jason Monk5eeebf52014-09-26 12:36:51 -04005637 mKeyguardDelegate.bindService(mContext);
Jim Millere5f910a2013-10-16 18:15:46 -07005638 mKeyguardDelegate.onBootCompleted();
5639 }
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005640 synchronized (mLock) {
5641 mSystemBooted = true;
5642 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005643 wakingUp();
5644 screenTurningOn(null);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005645 }
5646
Dianne Hackborn661cd522011-08-22 00:26:20 -07005647 ProgressDialog mBootMsgDialog = null;
5648
5649 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005650 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07005651 public void showBootMessage(final CharSequence msg, final boolean always) {
5652 mHandler.post(new Runnable() {
5653 @Override public void run() {
5654 if (mBootMsgDialog == null) {
Craig Stout4c0cb8a2014-04-04 13:03:10 -07005655 int theme;
5656 if (mContext.getPackageManager().hasSystemFeature(
5657 PackageManager.FEATURE_WATCH)) {
5658 theme = com.android.internal.R.style.Theme_Micro_Dialog_Alert;
5659 } else if (mContext.getPackageManager().hasSystemFeature(
5660 PackageManager.FEATURE_TELEVISION)) {
5661 theme = com.android.internal.R.style.Theme_Leanback_Dialog_Alert;
5662 } else {
5663 theme = 0;
5664 }
Vinod Krishnanfa8fc412014-04-18 14:35:53 -07005665
5666 mBootMsgDialog = new ProgressDialog(mContext, theme) {
Dianne Hackborn295e3c22011-08-25 13:19:08 -07005667 // This dialog will consume all events coming in to
5668 // it, to avoid it trying to do things too early in boot.
5669 @Override public boolean dispatchKeyEvent(KeyEvent event) {
5670 return true;
5671 }
5672 @Override public boolean dispatchKeyShortcutEvent(KeyEvent event) {
5673 return true;
5674 }
5675 @Override public boolean dispatchTouchEvent(MotionEvent ev) {
5676 return true;
5677 }
5678 @Override public boolean dispatchTrackballEvent(MotionEvent ev) {
5679 return true;
5680 }
5681 @Override public boolean dispatchGenericMotionEvent(MotionEvent ev) {
5682 return true;
5683 }
5684 @Override public boolean dispatchPopulateAccessibilityEvent(
5685 AccessibilityEvent event) {
5686 return true;
5687 }
5688 };
Jeff Hao9f60c082014-10-28 18:51:07 -07005689 if (mContext.getPackageManager().isUpgrade()) {
5690 mBootMsgDialog.setTitle(R.string.android_upgrading_title);
5691 } else {
5692 mBootMsgDialog.setTitle(R.string.android_start_title);
5693 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07005694 mBootMsgDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
5695 mBootMsgDialog.setIndeterminate(true);
5696 mBootMsgDialog.getWindow().setType(
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07005697 WindowManager.LayoutParams.TYPE_BOOT_PROGRESS);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005698 mBootMsgDialog.getWindow().addFlags(
5699 WindowManager.LayoutParams.FLAG_DIM_BEHIND
5700 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
5701 mBootMsgDialog.getWindow().setDimAmount(1);
Dianne Hackbornd9efb952011-12-07 14:56:51 -08005702 WindowManager.LayoutParams lp = mBootMsgDialog.getWindow().getAttributes();
5703 lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
5704 mBootMsgDialog.getWindow().setAttributes(lp);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005705 mBootMsgDialog.setCancelable(false);
5706 mBootMsgDialog.show();
5707 }
5708 mBootMsgDialog.setMessage(msg);
5709 }
5710 });
5711 }
5712
5713 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005714 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07005715 public void hideBootMessages() {
Craig Mautnera631d492014-08-05 15:16:01 -07005716 mHandler.sendEmptyMessage(MSG_HIDE_BOOT_MESSAGE);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005717 }
5718
Mike Lockwood28569302010-01-28 11:54:40 -05005719 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005720 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05005721 public void userActivity() {
Dianne Hackborndf89e652011-10-06 22:35:11 -07005722 // ***************************************
5723 // NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
5724 // ***************************************
5725 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
5726 // WITH ITS LOCKS HELD.
5727 //
5728 // This code must be VERY careful about the locks
5729 // it acquires.
5730 // In fact, the current code acquires way too many,
5731 // and probably has lurking deadlocks.
5732
Mike Lockwood28569302010-01-28 11:54:40 -05005733 synchronized (mScreenLockTimeout) {
5734 if (mLockScreenTimerActive) {
5735 // reset the timer
5736 mHandler.removeCallbacks(mScreenLockTimeout);
5737 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
5738 }
5739 }
Daniel Sandler0601eb72011-04-13 01:01:32 -04005740 }
5741
Adam Cohenf7522022012-10-03 20:03:18 -07005742 class ScreenLockTimeout implements Runnable {
5743 Bundle options;
5744
5745 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05005746 public void run() {
5747 synchronized (this) {
5748 if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard");
Jim Miller5ecd8112013-01-09 18:50:26 -08005749 if (mKeyguardDelegate != null) {
5750 mKeyguardDelegate.doKeyguardTimeout(options);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005751 }
Mike Lockwood28569302010-01-28 11:54:40 -05005752 mLockScreenTimerActive = false;
Adam Cohenf7522022012-10-03 20:03:18 -07005753 options = null;
Mike Lockwood28569302010-01-28 11:54:40 -05005754 }
5755 }
Mike Lockwood28569302010-01-28 11:54:40 -05005756
Adam Cohenf7522022012-10-03 20:03:18 -07005757 public void setLockOptions(Bundle options) {
5758 this.options = options;
5759 }
5760 }
5761
5762 ScreenLockTimeout mScreenLockTimeout = new ScreenLockTimeout();
5763
Jose Lima9546b202014-07-02 17:21:51 -07005764 @Override
Adam Cohenf7522022012-10-03 20:03:18 -07005765 public void lockNow(Bundle options) {
Jim Miller93c518e2012-01-17 15:55:31 -08005766 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null);
5767 mHandler.removeCallbacks(mScreenLockTimeout);
Adam Cohenf7522022012-10-03 20:03:18 -07005768 if (options != null) {
5769 // In case multiple calls are made to lockNow, we don't wipe out the options
5770 // until the runnable actually executes.
5771 mScreenLockTimeout.setLockOptions(options);
5772 }
Jim Miller93c518e2012-01-17 15:55:31 -08005773 mHandler.post(mScreenLockTimeout);
5774 }
5775
Mike Lockwood28569302010-01-28 11:54:40 -05005776 private void updateLockScreenTimeout() {
5777 synchronized (mScreenLockTimeout) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005778 boolean enable = (mAllowLockscreenWhenOn && mAwake &&
Jim Miller5ecd8112013-01-09 18:50:26 -08005779 mKeyguardDelegate != null && mKeyguardDelegate.isSecure());
Mike Lockwood28569302010-01-28 11:54:40 -05005780 if (mLockScreenTimerActive != enable) {
5781 if (enable) {
5782 if (localLOGV) Log.v(TAG, "setting lockscreen timer");
5783 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
5784 } else {
5785 if (localLOGV) Log.v(TAG, "clearing lockscreen timer");
5786 mHandler.removeCallbacks(mScreenLockTimeout);
5787 }
5788 mLockScreenTimerActive = enable;
5789 }
5790 }
5791 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005792
5793 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07005794 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005795 public void enableScreenAfterBoot() {
5796 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07005797 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07005798 updateRotation(true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005799 }
Dianne Hackbornf54c8f92009-09-19 14:03:57 -07005800
Jeff Brownc458ce92012-04-30 14:58:40 -07005801 private void applyLidSwitchState() {
Jeff Brownc458ce92012-04-30 14:58:40 -07005802 if (mLidState == LID_CLOSED && mLidControlsSleep) {
Jeff Brown6d8fd272014-05-20 21:24:38 -07005803 mPowerManager.goToSleep(SystemClock.uptimeMillis(),
Jeff Brownc12035c2014-08-13 18:52:25 -07005804 PowerManager.GO_TO_SLEEP_REASON_LID_SWITCH,
Jeff Brown6d8fd272014-05-20 21:24:38 -07005805 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
Jeff Brownc458ce92012-04-30 14:58:40 -07005806 }
Jeff Browna20dda42014-05-27 20:57:24 -07005807
5808 synchronized (mLock) {
5809 updateWakeGestureListenerLp();
5810 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005811 }
5812
Jeff Brown4f5fa282014-06-12 19:19:15 -07005813 void updateUiMode() {
5814 if (mUiModeManager == null) {
5815 mUiModeManager = IUiModeManager.Stub.asInterface(
5816 ServiceManager.getService(Context.UI_MODE_SERVICE));
5817 }
5818 try {
5819 mUiMode = mUiModeManager.getCurrentModeType();
5820 } catch (RemoteException e) {
5821 }
5822 }
5823
Jeff Brown01a98dd2011-09-20 15:08:29 -07005824 void updateRotation(boolean alwaysSendConfiguration) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005825 try {
5826 //set orientation on WindowManager
Dianne Hackbornf87d1962012-04-04 12:48:24 -07005827 mWindowManager.updateRotation(alwaysSendConfiguration, false);
5828 } catch (RemoteException e) {
5829 // Ignore
5830 }
5831 }
5832
5833 void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) {
5834 try {
5835 //set orientation on WindowManager
5836 mWindowManager.updateRotation(alwaysSendConfiguration, forceRelayout);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005837 } catch (RemoteException e) {
5838 // Ignore
5839 }
5840 }
5841
Daniel Sandler6396c722013-04-16 20:19:09 -04005842 /**
5843 * Return an Intent to launch the currently active dock app as home. Returns
5844 * null if the standard home should be launched, which is the case if any of the following is
5845 * true:
5846 * <ul>
5847 * <li>The device is not in either car mode or desk mode
5848 * <li>The device is in car mode but ENABLE_CAR_DOCK_HOME_CAPTURE is false
5849 * <li>The device is in desk mode but ENABLE_DESK_DOCK_HOME_CAPTURE is false
5850 * <li>The device is in car mode but there's no CAR_DOCK app with METADATA_DOCK_HOME
5851 * <li>The device is in desk mode but there's no DESK_DOCK app with METADATA_DOCK_HOME
5852 * </ul>
Craig Mautnereda67292013-04-28 13:50:14 -07005853 * @return A dock intent.
Daniel Sandler6396c722013-04-16 20:19:09 -04005854 */
5855 Intent createHomeDockIntent() {
5856 Intent intent = null;
5857
5858 // What home does is based on the mode, not the dock state. That
5859 // is, when in car mode you should be taken to car home regardless
5860 // of whether we are actually in a car dock.
5861 if (mUiMode == Configuration.UI_MODE_TYPE_CAR) {
5862 if (ENABLE_CAR_DOCK_HOME_CAPTURE) {
5863 intent = mCarDockIntent;
5864 }
5865 } else if (mUiMode == Configuration.UI_MODE_TYPE_DESK) {
5866 if (ENABLE_DESK_DOCK_HOME_CAPTURE) {
5867 intent = mDeskDockIntent;
5868 }
Jeff Brown4f5fa282014-06-12 19:19:15 -07005869 } else if (mUiMode == Configuration.UI_MODE_TYPE_WATCH
5870 && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
5871 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK
5872 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK)) {
5873 // Always launch dock home from home when watch is docked, if it exists.
5874 intent = mDeskDockIntent;
Daniel Sandler6396c722013-04-16 20:19:09 -04005875 }
5876
5877 if (intent == null) {
5878 return null;
5879 }
5880
5881 ActivityInfo ai = null;
5882 ResolveInfo info = mContext.getPackageManager().resolveActivityAsUser(
5883 intent,
John Spurlockf56bef12013-07-09 09:51:46 -04005884 PackageManager.MATCH_DEFAULT_ONLY | PackageManager.GET_META_DATA,
Craig Mautnerd625ab22013-09-06 13:40:31 -07005885 mCurrentUserId);
Daniel Sandler6396c722013-04-16 20:19:09 -04005886 if (info != null) {
5887 ai = info.activityInfo;
5888 }
5889 if (ai != null
5890 && ai.metaData != null
5891 && ai.metaData.getBoolean(Intent.METADATA_DOCK_HOME)) {
5892 intent = new Intent(intent);
5893 intent.setClassName(ai.packageName, ai.name);
5894 return intent;
5895 }
5896
5897 return null;
5898 }
5899
Bryce Lee01b0c5f2015-02-05 18:24:04 -08005900 void startDockOrHome(boolean fromHomeKey) {
John Spurlockc8b46ca2013-04-08 12:59:26 -04005901 awakenDreams();
Daniel Sandler6396c722013-04-16 20:19:09 -04005902
5903 Intent dock = createHomeDockIntent();
5904 if (dock != null) {
5905 try {
Bryce Lee01b0c5f2015-02-05 18:24:04 -08005906 if (fromHomeKey) {
5907 dock.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
5908 }
Daniel Sandler6396c722013-04-16 20:19:09 -04005909 mContext.startActivityAsUser(dock, UserHandle.CURRENT);
5910 return;
5911 } catch (ActivityNotFoundException e) {
5912 }
5913 }
5914
Bryce Lee01b0c5f2015-02-05 18:24:04 -08005915 Intent intent;
5916
5917 if (fromHomeKey) {
5918 intent = new Intent(mHomeIntent);
5919 intent.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
5920 } else {
5921 intent = mHomeIntent;
5922 }
5923
5924 mContext.startActivityAsUser(intent, UserHandle.CURRENT);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005925 }
Craig Mautnereda67292013-04-28 13:50:14 -07005926
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005927 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005928 * goes to the home screen
5929 * @return whether it did anything
5930 */
5931 boolean goHome() {
5932 if (false) {
5933 // This code always brings home to the front.
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07005934 try {
5935 ActivityManagerNative.getDefault().stopAppSwitches();
5936 } catch (RemoteException e) {
5937 }
Dianne Hackborn94a679d2009-07-28 17:51:07 -07005938 sendCloseSystemWindows();
Bryce Lee01b0c5f2015-02-05 18:24:04 -08005939 startDockOrHome(false /*fromHomeKey*/);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005940 } else {
5941 // This code brings home to the front or, if it is already
5942 // at the front, puts the device to sleep.
5943 try {
Wink Savilled2e6a332010-02-12 12:12:06 -08005944 if (SystemProperties.getInt("persist.sys.uts-test-mode", 0) == 1) {
5945 /// Roll back EndcallBehavior as the cupcake design to pass P1 lab entry.
5946 Log.d(TAG, "UTS-TEST-MODE");
5947 } else {
5948 ActivityManagerNative.getDefault().stopAppSwitches();
5949 sendCloseSystemWindows();
Daniel Sandler6396c722013-04-16 20:19:09 -04005950 Intent dock = createHomeDockIntent();
5951 if (dock != null) {
5952 int result = ActivityManagerNative.getDefault()
5953 .startActivityAsUser(null, null, dock,
5954 dock.resolveTypeIfNeeded(mContext.getContentResolver()),
5955 null, null, 0,
5956 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07005957 null, null, UserHandle.USER_CURRENT);
Daniel Sandler6396c722013-04-16 20:19:09 -04005958 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
5959 return false;
5960 }
5961 }
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005962 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005963 int result = ActivityManagerNative.getDefault()
Dianne Hackbornf265ea92013-01-31 15:00:51 -08005964 .startActivityAsUser(null, null, mHomeIntent,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005965 mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()),
Dianne Hackborna4972e92012-03-14 10:38:05 -07005966 null, null, 0,
5967 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07005968 null, null, UserHandle.USER_CURRENT);
Dianne Hackborna4972e92012-03-14 10:38:05 -07005969 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005970 return false;
5971 }
5972 } catch (RemoteException ex) {
5973 // bummer, the activity manager, which is in this process, is dead
5974 }
5975 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005976 return true;
5977 }
Craig Mautnereda67292013-04-28 13:50:14 -07005978
5979 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07005980 public void setCurrentOrientationLw(int newOrientation) {
5981 synchronized (mLock) {
5982 if (newOrientation != mCurrentAppOrientation) {
5983 mCurrentAppOrientation = newOrientation;
5984 updateOrientationListenerLp();
5985 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005986 }
5987 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08005988
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07005989 private void performAuditoryFeedbackForAccessibilityIfNeed() {
5990 if (!isGlobalAccessibilityGestureEnabled()) {
5991 return;
5992 }
5993 AudioManager audioManager = (AudioManager) mContext.getSystemService(
5994 Context.AUDIO_SERVICE);
5995 if (audioManager.isSilentMode()) {
5996 return;
5997 }
5998 Ringtone ringTone = RingtoneManager.getRingtone(mContext,
5999 Settings.System.DEFAULT_NOTIFICATION_URI);
6000 ringTone.setStreamType(AudioManager.STREAM_MUSIC);
6001 ringTone.play();
6002 }
Craig Mautnereda67292013-04-28 13:50:14 -07006003
Bryce Lee584a4452014-10-21 15:55:55 -07006004 private boolean isTheaterModeEnabled() {
6005 return Settings.Global.getInt(mContext.getContentResolver(),
6006 Settings.Global.THEATER_MODE_ON, 0) == 1;
6007 }
6008
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07006009 private boolean isGlobalAccessibilityGestureEnabled() {
6010 return Settings.Global.getInt(mContext.getContentResolver(),
6011 Settings.Global.ENABLE_ACCESSIBILITY_GLOBAL_GESTURE_ENABLED, 0) == 1;
6012 }
6013
Craig Mautnereda67292013-04-28 13:50:14 -07006014 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07006015 public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) {
Svetoslav Ganov96179212012-10-10 14:17:45 -07006016 if (!mVibrator.hasVibrator()) {
6017 return false;
6018 }
Christopher Tate5e08af02012-09-21 17:17:22 -07006019 final boolean hapticsDisabled = Settings.System.getIntForUser(mContext.getContentResolver(),
6020 Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) == 0;
Jeff Brown82379ba2014-07-25 19:03:28 -07006021 if (hapticsDisabled && !always) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006022 return false;
6023 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006024 long[] pattern = null;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006025 switch (effectId) {
6026 case HapticFeedbackConstants.LONG_PRESS:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006027 pattern = mLongPressVibePattern;
6028 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006029 case HapticFeedbackConstants.VIRTUAL_KEY:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006030 pattern = mVirtualKeyVibePattern;
6031 break;
6032 case HapticFeedbackConstants.KEYBOARD_TAP:
6033 pattern = mKeyboardTapVibePattern;
6034 break;
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07006035 case HapticFeedbackConstants.CLOCK_TICK:
6036 pattern = mClockTickVibePattern;
6037 break;
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07006038 case HapticFeedbackConstants.CALENDAR_DATE:
6039 pattern = mCalendarDateVibePattern;
6040 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006041 case HapticFeedbackConstants.SAFE_MODE_DISABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006042 pattern = mSafeModeDisabledVibePattern;
6043 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006044 case HapticFeedbackConstants.SAFE_MODE_ENABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006045 pattern = mSafeModeEnabledVibePattern;
6046 break;
Amith Yamasanic33cb712010-02-10 15:21:49 -08006047 default:
6048 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006049 }
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006050 int owningUid;
6051 String owningPackage;
6052 if (win != null) {
6053 owningUid = win.getOwningUid();
6054 owningPackage = win.getOwningPackage();
6055 } else {
6056 owningUid = android.os.Process.myUid();
Dianne Hackborn95d78532013-09-11 09:51:14 -07006057 owningPackage = mContext.getOpPackageName();
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006058 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006059 if (pattern.length == 1) {
6060 // One-shot vibration
John Spurlock7b414672014-07-18 13:02:39 -04006061 mVibrator.vibrate(owningUid, owningPackage, pattern[0], VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08006062 } else {
6063 // Pattern vibration
John Spurlock7b414672014-07-18 13:02:39 -04006064 mVibrator.vibrate(owningUid, owningPackage, pattern, -1, VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08006065 }
6066 return true;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006067 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07006068
6069 @Override
6070 public void keepScreenOnStartedLw() {
Daniel Sandler0601eb72011-04-13 01:01:32 -04006071 }
6072
Jeff Brownc38c9be2012-10-04 13:16:19 -07006073 @Override
6074 public void keepScreenOnStoppedLw() {
Jim Millerab954542014-10-10 18:21:49 -07006075 if (isKeyguardShowingAndNotOccluded()) {
Jim Miller25190572013-02-28 17:36:24 -08006076 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006077 }
6078 }
Mike Lockwoodfcb39242009-10-21 23:01:07 -04006079
Dianne Hackborndf89e652011-10-06 22:35:11 -07006080 private int updateSystemUiVisibilityLw() {
Joe Onorato664644d2011-01-23 17:53:23 -08006081 // If there is no window focused, there will be nobody to handle the events
6082 // anyway, so just hang on in whatever state we're in until things settle down.
Adrian Roos53f28ec2014-10-29 17:26:12 +01006083 final WindowState win = mFocusedWindow != null ? mFocusedWindow
6084 : mTopFullscreenOpaqueWindowState;
John Spurlock79da8332013-09-20 12:04:47 -04006085 if (win == null) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006086 return 0;
6087 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01006088 if ((win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 && mHideLockScreen == true) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07006089 // We are updating at a point where the keyguard has gotten
6090 // focus, but we were last in a state where the top window is
6091 // hiding it. This is probably because the keyguard as been
6092 // shown while the top window was displayed, so we want to ignore
6093 // it here because this is just a very transient change and it
6094 // will quickly lose focus once it correctly gets hidden.
6095 return 0;
6096 }
John Spurlock32beb2c2013-03-11 10:16:47 -04006097
John Spurlock1db8b682014-02-18 11:18:59 -05006098 int tmpVisibility = PolicyControl.getSystemUiVisibility(win, null)
Dianne Hackborne26ab702011-10-16 13:21:33 -07006099 & ~mResettingSystemUiFlags
6100 & ~mForceClearedSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04006101 if (mForcingShowNavBar && win.getSurfaceLayer() < mForcingShowNavBarLayer) {
John Spurlockc6d1c602014-01-17 15:22:06 -05006102 tmpVisibility &= ~PolicyControl.adjustClearableFlags(win, View.SYSTEM_UI_CLEARABLE_FLAGS);
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08006103 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01006104 tmpVisibility = updateLightStatusBarLw(tmpVisibility);
John Spurlock79da8332013-09-20 12:04:47 -04006105 final int visibility = updateSystemBarsLw(win, mLastSystemUiFlags, tmpVisibility);
John Spurlockad3e6cb2013-04-30 08:47:43 -04006106 final int diff = visibility ^ mLastSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04006107 final boolean needsMenu = win.getNeedsMenuLw(mTopFullscreenOpaqueWindowState);
Dianne Hackborne0f085d2011-11-30 18:41:15 -08006108 if (diff == 0 && mLastFocusNeedsMenu == needsMenu
John Spurlock79da8332013-09-20 12:04:47 -04006109 && mFocusedApp == win.getAppToken()) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006110 return 0;
6111 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07006112 mLastSystemUiFlags = visibility;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08006113 mLastFocusNeedsMenu = needsMenu;
John Spurlock79da8332013-09-20 12:04:47 -04006114 mFocusedApp = win.getAppToken();
Dianne Hackborndf89e652011-10-06 22:35:11 -07006115 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07006116 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07006117 public void run() {
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006118 try {
6119 IStatusBarService statusbar = getStatusBarService();
6120 if (statusbar != null) {
Adrian Roos53f28ec2014-10-29 17:26:12 +01006121 statusbar.setSystemUiVisibility(visibility, 0xffffffff, win.toString());
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006122 statusbar.topAppWindowChanged(needsMenu);
Joe Onorato664644d2011-01-23 17:53:23 -08006123 }
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006124 } catch (RemoteException e) {
6125 // re-acquire status bar service next time it is needed.
6126 mStatusBarService = null;
Joe Onorato664644d2011-01-23 17:53:23 -08006127 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07006128 }
6129 });
6130 return diff;
Joe Onorato664644d2011-01-23 17:53:23 -08006131 }
6132
Adrian Rooscd3884d2015-02-18 17:25:23 +01006133 private int updateLightStatusBarLw(int vis) {
6134 WindowState statusColorWin = isStatusBarKeyguard() && !mHideLockScreen
6135 ? mStatusBar
6136 : mTopFullscreenOpaqueOrDimmingWindowState;
6137
6138 if (statusColorWin != null) {
6139 if (statusColorWin == mTopFullscreenOpaqueWindowState) {
6140 // If the top fullscreen-or-dimming window is also the top fullscreen, respect
6141 // its light flag.
6142 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6143 vis |= PolicyControl.getSystemUiVisibility(statusColorWin, null)
6144 & View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6145 } else if (statusColorWin != null && statusColorWin.isDimming()) {
6146 // Otherwise if it's dimming, clear the light flag.
6147 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6148 }
6149 }
6150 return vis;
6151 }
6152
John Spurlock79da8332013-09-20 12:04:47 -04006153 private int updateSystemBarsLw(WindowState win, int oldVis, int vis) {
John Spurlockbd957402013-10-03 11:38:39 -04006154 // apply translucent bar vis flags
Jorim Jaggi380ecb82014-03-14 17:25:20 +01006155 WindowState transWin = isStatusBarKeyguard() && !mHideLockScreen
6156 ? mStatusBar
John Spurlockbd957402013-10-03 11:38:39 -04006157 : mTopFullscreenOpaqueWindowState;
6158 vis = mStatusBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
6159 vis = mNavigationBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
6160
John Spurlock27735a42013-08-14 17:57:38 -04006161 // prevent status bar interaction from clearing certain flags
John Spurlock79da8332013-09-20 12:04:47 -04006162 boolean statusBarHasFocus = win.getAttrs().type == TYPE_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04006163 if (statusBarHasFocus && !isStatusBarKeyguard()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04006164 int flags = View.SYSTEM_UI_FLAG_FULLSCREEN
6165 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlockcfc359a2013-09-05 10:42:03 -04006166 | View.SYSTEM_UI_FLAG_IMMERSIVE
Jorim Jaggi73fef8d2015-02-16 17:32:28 +01006167 | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
6168 | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04006169 if (mHideLockScreen) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01006170 flags |= View.STATUS_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSLUCENT;
6171 }
John Spurlockbd957402013-10-03 11:38:39 -04006172 vis = (vis & ~flags) | (oldVis & flags);
John Spurlockad3e6cb2013-04-30 08:47:43 -04006173 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04006174
Adrian Roos4fb3ee32014-08-22 19:29:09 +02006175 if (!areTranslucentBarsAllowed() && transWin != mStatusBar) {
Adrian Roosea562512014-05-05 13:33:03 +02006176 vis &= ~(View.NAVIGATION_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSLUCENT
6177 | View.SYSTEM_UI_TRANSPARENT);
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006178 }
6179
John Spurlock27735a42013-08-14 17:57:38 -04006180 // update status bar
John Spurlockf1a36642013-10-12 17:50:42 -04006181 boolean immersiveSticky =
6182 (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
John Spurlock27735a42013-08-14 17:57:38 -04006183 boolean hideStatusBarWM =
John Spurlockbd957402013-10-03 11:38:39 -04006184 mTopFullscreenOpaqueWindowState != null &&
John Spurlockc6d1c602014-01-17 15:22:06 -05006185 (PolicyControl.getWindowFlags(mTopFullscreenOpaqueWindowState, null)
John Spurlock27735a42013-08-14 17:57:38 -04006186 & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0;
6187 boolean hideStatusBarSysui =
6188 (vis & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04006189 boolean hideNavBarSysui =
6190 (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006191
John Spurlock27735a42013-08-14 17:57:38 -04006192 boolean transientStatusBarAllowed =
6193 mStatusBar != null && (
6194 hideStatusBarWM
John Spurlockf1a36642013-10-12 17:50:42 -04006195 || (hideStatusBarSysui && immersiveSticky)
John Spurlock27735a42013-08-14 17:57:38 -04006196 || statusBarHasFocus);
6197
John Spurlockf1a36642013-10-12 17:50:42 -04006198 boolean transientNavBarAllowed =
6199 mNavigationBar != null &&
6200 hideNavBarSysui && immersiveSticky;
6201
John Spurlockf25706f2013-11-07 18:02:43 -05006202 boolean denyTransientStatus = mStatusBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04006203 && !transientStatusBarAllowed && hideStatusBarSysui;
John Spurlockf25706f2013-11-07 18:02:43 -05006204 boolean denyTransientNav = mNavigationBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04006205 && !transientNavBarAllowed;
6206 if (denyTransientStatus || denyTransientNav) {
John Spurlock27735a42013-08-14 17:57:38 -04006207 // clear the clearable flags instead
John Spurlockf1a36642013-10-12 17:50:42 -04006208 clearClearableFlagsLw();
tiger_huangc58d7562014-10-23 20:24:19 +08006209 vis &= ~View.SYSTEM_UI_CLEARABLE_FLAGS;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006210 }
John Spurlock27735a42013-08-14 17:57:38 -04006211
6212 vis = mStatusBarController.updateVisibilityLw(transientStatusBarAllowed, oldVis, vis);
6213
6214 // update navigation bar
John Spurlockf1a36642013-10-12 17:50:42 -04006215 boolean oldImmersiveMode = isImmersiveMode(oldVis);
6216 boolean newImmersiveMode = isImmersiveMode(vis);
6217 if (win != null && oldImmersiveMode != newImmersiveMode) {
John Spurlock79da8332013-09-20 12:04:47 -04006218 final String pkg = win.getOwningPackage();
Maurice Lam99c6e072014-04-28 18:24:28 -07006219 mImmersiveModeConfirmation.immersiveModeChanged(pkg, newImmersiveMode,
6220 isUserSetupComplete());
John Spurlock34e13d92013-08-10 06:52:28 -04006221 }
John Spurlock27735a42013-08-14 17:57:38 -04006222
John Spurlockf1a36642013-10-12 17:50:42 -04006223 vis = mNavigationBarController.updateVisibilityLw(transientNavBarAllowed, oldVis, vis);
6224
John Spurlocke1f366f2013-08-05 12:22:40 -04006225 return vis;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006226 }
6227
John Spurlockf1a36642013-10-12 17:50:42 -04006228 private void clearClearableFlagsLw() {
6229 int newVal = mResettingSystemUiFlags | View.SYSTEM_UI_CLEARABLE_FLAGS;
6230 if (newVal != mResettingSystemUiFlags) {
6231 mResettingSystemUiFlags = newVal;
6232 mWindowManagerFuncs.reevaluateStatusBarVisibility();
6233 }
6234 }
6235
6236 private boolean isImmersiveMode(int vis) {
6237 final int flags = View.SYSTEM_UI_FLAG_IMMERSIVE | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
John Spurlock34e13d92013-08-10 06:52:28 -04006238 return mNavigationBar != null
6239 && (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0
Daniel Sandler900ece52013-10-18 15:53:27 -04006240 && (vis & flags) != 0
6241 && canHideNavigationBar();
John Spurlock34e13d92013-08-10 06:52:28 -04006242 }
6243
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006244 /**
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04006245 * @return whether the navigation or status bar can be made translucent
6246 *
6247 * This should return true unless touch exploration is not enabled or
6248 * R.boolean.config_enableTranslucentDecor is false.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006249 */
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04006250 private boolean areTranslucentBarsAllowed() {
Svetoslav8e3feb12014-02-24 13:46:47 -08006251 return mTranslucentDecorEnabled
6252 && !mAccessibilityManager.isTouchExplorationEnabled();
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006253 }
6254
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04006255 // Use this instead of checking config_showNavigationBar so that it can be consistently
6256 // overridden by qemu.hw.mainkeys in the emulator.
Craig Mautnereda67292013-04-28 13:50:14 -07006257 @Override
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04006258 public boolean hasNavigationBar() {
6259 return mHasNavigationBar;
6260 }
6261
satok1bc0a492012-04-25 22:47:12 +09006262 @Override
6263 public void setLastInputMethodWindowLw(WindowState ime, WindowState target) {
6264 mLastInputMethodWindow = ime;
6265 mLastInputMethodTargetWindow = target;
6266 }
6267
Craig Mautnerf1b67412012-09-19 13:18:29 -07006268 @Override
Satoshi Kataoka658c7b82013-10-10 17:03:51 +09006269 public int getInputMethodWindowVisibleHeightLw() {
6270 return mDockBottom - mCurBottom;
6271 }
6272
6273 @Override
Craig Mautnerf1b67412012-09-19 13:18:29 -07006274 public void setCurrentUserLw(int newUserId) {
Craig Mautnerd625ab22013-09-06 13:40:31 -07006275 mCurrentUserId = newUserId;
Jim Miller5ecd8112013-01-09 18:50:26 -08006276 if (mKeyguardDelegate != null) {
6277 mKeyguardDelegate.setCurrentUser(newUserId);
Craig Mautnerf1b67412012-09-19 13:18:29 -07006278 }
John Spurlock13451a22012-09-28 14:40:41 -04006279 if (mStatusBarService != null) {
6280 try {
6281 mStatusBarService.setCurrentUser(newUserId);
6282 } catch (RemoteException e) {
6283 // oh well
6284 }
6285 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006286 setLastInputMethodWindowLw(null, null);
Craig Mautnerf1b67412012-09-19 13:18:29 -07006287 }
6288
6289 @Override
Svetoslav Ganov545252f2012-12-10 18:29:24 -08006290 public boolean canMagnifyWindow(int windowType) {
6291 switch (windowType) {
6292 case WindowManager.LayoutParams.TYPE_INPUT_METHOD:
6293 case WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG:
6294 case WindowManager.LayoutParams.TYPE_NAVIGATION_BAR:
6295 case WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY: {
6296 return false;
6297 }
6298 }
6299 return true;
6300 }
6301
6302 @Override
6303 public boolean isTopLevelWindow(int windowType) {
6304 if (windowType >= WindowManager.LayoutParams.FIRST_SUB_WINDOW
6305 && windowType <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
6306 return (windowType == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG);
6307 }
6308 return true;
6309 }
6310
Jim Miller4eeb4f62012-11-08 00:04:29 -08006311 @Override
Jeff Brownd7a04de2012-06-17 14:17:52 -07006312 public void dump(String prefix, PrintWriter pw, String[] args) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006313 pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07006314 pw.print(" mSystemReady="); pw.print(mSystemReady);
6315 pw.print(" mSystemBooted="); pw.println(mSystemBooted);
Jeff Brown2e7760e2012-04-11 15:14:55 -07006316 pw.print(prefix); pw.print("mLidState="); pw.print(mLidState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006317 pw.print(" mLidOpenRotation="); pw.print(mLidOpenRotation);
Michael Wright3818c922014-09-02 13:59:07 -07006318 pw.print(" mCameraLensCoverState="); pw.print(mCameraLensCoverState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006319 pw.print(" mHdmiPlugged="); pw.println(mHdmiPlugged);
Dianne Hackborne26ab702011-10-16 13:21:33 -07006320 if (mLastSystemUiFlags != 0 || mResettingSystemUiFlags != 0
6321 || mForceClearedSystemUiFlags != 0) {
6322 pw.print(prefix); pw.print("mLastSystemUiFlags=0x");
6323 pw.print(Integer.toHexString(mLastSystemUiFlags));
6324 pw.print(" mResettingSystemUiFlags=0x");
6325 pw.print(Integer.toHexString(mResettingSystemUiFlags));
6326 pw.print(" mForceClearedSystemUiFlags=0x");
6327 pw.println(Integer.toHexString(mForceClearedSystemUiFlags));
Dianne Hackborndf89e652011-10-06 22:35:11 -07006328 }
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08006329 if (mLastFocusNeedsMenu) {
6330 pw.print(prefix); pw.print("mLastFocusNeedsMenu=");
6331 pw.println(mLastFocusNeedsMenu);
6332 }
Jeff Browna20dda42014-05-27 20:57:24 -07006333 pw.print(prefix); pw.print("mWakeGestureEnabledSetting=");
6334 pw.println(mWakeGestureEnabledSetting);
6335
Jeff Brownbcdfc622014-03-06 19:13:04 -08006336 pw.print(prefix); pw.print("mSupportAutoRotation="); pw.println(mSupportAutoRotation);
Daniel Sandler6396c722013-04-16 20:19:09 -04006337 pw.print(prefix); pw.print("mUiMode="); pw.print(mUiMode);
6338 pw.print(" mDockMode="); pw.print(mDockMode);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006339 pw.print(" mCarDockRotation="); pw.print(mCarDockRotation);
6340 pw.print(" mDeskDockRotation="); pw.println(mDeskDockRotation);
6341 pw.print(prefix); pw.print("mUserRotationMode="); pw.print(mUserRotationMode);
6342 pw.print(" mUserRotation="); pw.print(mUserRotation);
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05006343 pw.print(" mAllowAllRotations="); pw.println(mAllowAllRotations);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07006344 pw.print(prefix); pw.print("mCurrentAppOrientation="); pw.println(mCurrentAppOrientation);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006345 pw.print(prefix); pw.print("mCarDockEnablesAccelerometer=");
6346 pw.print(mCarDockEnablesAccelerometer);
6347 pw.print(" mDeskDockEnablesAccelerometer=");
6348 pw.println(mDeskDockEnablesAccelerometer);
6349 pw.print(prefix); pw.print("mLidKeyboardAccessibility=");
6350 pw.print(mLidKeyboardAccessibility);
6351 pw.print(" mLidNavigationAccessibility="); pw.print(mLidNavigationAccessibility);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07006352 pw.print(" mLidControlsSleep="); pw.println(mLidControlsSleep);
Jeff Brown6d8fd272014-05-20 21:24:38 -07006353 pw.print(prefix);
6354 pw.print("mShortPressOnPowerBehavior="); pw.print(mShortPressOnPowerBehavior);
6355 pw.print(" mLongPressOnPowerBehavior="); pw.println(mLongPressOnPowerBehavior);
Jeff Brown13f00f02014-10-31 14:45:50 -07006356 pw.print(prefix);
6357 pw.print("mDoublePressOnPowerBehavior="); pw.print(mDoublePressOnPowerBehavior);
6358 pw.print(" mTriplePressOnPowerBehavior="); pw.println(mTriplePressOnPowerBehavior);
Jeff Brown6d8fd272014-05-20 21:24:38 -07006359 pw.print(prefix); pw.print("mHasSoftInput="); pw.println(mHasSoftInput);
Jeff Brown3ee549c2014-09-22 20:14:39 -07006360 pw.print(prefix); pw.print("mAwake="); pw.println(mAwake);
6361 pw.print(prefix); pw.print("mScreenOnEarly="); pw.print(mScreenOnEarly);
6362 pw.print(" mScreenOnFully="); pw.println(mScreenOnFully);
6363 pw.print(prefix); pw.print("mKeyguardDrawComplete="); pw.print(mKeyguardDrawComplete);
6364 pw.print(" mWindowManagerDrawComplete="); pw.println(mWindowManagerDrawComplete);
6365 pw.print(prefix); pw.print("mOrientationSensorEnabled=");
6366 pw.println(mOrientationSensorEnabled);
Dianne Hackbornc652de82013-02-15 16:32:56 -08006367 pw.print(prefix); pw.print("mOverscanScreen=("); pw.print(mOverscanScreenLeft);
6368 pw.print(","); pw.print(mOverscanScreenTop);
6369 pw.print(") "); pw.print(mOverscanScreenWidth);
6370 pw.print("x"); pw.println(mOverscanScreenHeight);
6371 if (mOverscanLeft != 0 || mOverscanTop != 0
6372 || mOverscanRight != 0 || mOverscanBottom != 0) {
6373 pw.print(prefix); pw.print("mOverscan left="); pw.print(mOverscanLeft);
6374 pw.print(" top="); pw.print(mOverscanTop);
6375 pw.print(" right="); pw.print(mOverscanRight);
6376 pw.print(" bottom="); pw.println(mOverscanBottom);
6377 }
Dianne Hackborn313440842013-02-19 19:22:59 -08006378 pw.print(prefix); pw.print("mRestrictedOverscanScreen=(");
6379 pw.print(mRestrictedOverscanScreenLeft);
6380 pw.print(","); pw.print(mRestrictedOverscanScreenTop);
6381 pw.print(") "); pw.print(mRestrictedOverscanScreenWidth);
6382 pw.print("x"); pw.println(mRestrictedOverscanScreenHeight);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006383 pw.print(prefix); pw.print("mUnrestrictedScreen=("); pw.print(mUnrestrictedScreenLeft);
6384 pw.print(","); pw.print(mUnrestrictedScreenTop);
6385 pw.print(") "); pw.print(mUnrestrictedScreenWidth);
6386 pw.print("x"); pw.println(mUnrestrictedScreenHeight);
6387 pw.print(prefix); pw.print("mRestrictedScreen=("); pw.print(mRestrictedScreenLeft);
6388 pw.print(","); pw.print(mRestrictedScreenTop);
6389 pw.print(") "); pw.print(mRestrictedScreenWidth);
6390 pw.print("x"); pw.println(mRestrictedScreenHeight);
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07006391 pw.print(prefix); pw.print("mStableFullscreen=("); pw.print(mStableFullscreenLeft);
6392 pw.print(","); pw.print(mStableFullscreenTop);
6393 pw.print(")-("); pw.print(mStableFullscreenRight);
6394 pw.print(","); pw.print(mStableFullscreenBottom); pw.println(")");
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07006395 pw.print(prefix); pw.print("mStable=("); pw.print(mStableLeft);
6396 pw.print(","); pw.print(mStableTop);
6397 pw.print(")-("); pw.print(mStableRight);
6398 pw.print(","); pw.print(mStableBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07006399 pw.print(prefix); pw.print("mSystem=("); pw.print(mSystemLeft);
6400 pw.print(","); pw.print(mSystemTop);
6401 pw.print(")-("); pw.print(mSystemRight);
6402 pw.print(","); pw.print(mSystemBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006403 pw.print(prefix); pw.print("mCur=("); pw.print(mCurLeft);
6404 pw.print(","); pw.print(mCurTop);
6405 pw.print(")-("); pw.print(mCurRight);
6406 pw.print(","); pw.print(mCurBottom); pw.println(")");
6407 pw.print(prefix); pw.print("mContent=("); pw.print(mContentLeft);
6408 pw.print(","); pw.print(mContentTop);
6409 pw.print(")-("); pw.print(mContentRight);
6410 pw.print(","); pw.print(mContentBottom); pw.println(")");
Dianne Hackborne30e02f2014-05-27 18:24:45 -07006411 pw.print(prefix); pw.print("mVoiceContent=("); pw.print(mVoiceContentLeft);
6412 pw.print(","); pw.print(mVoiceContentTop);
6413 pw.print(")-("); pw.print(mVoiceContentRight);
6414 pw.print(","); pw.print(mVoiceContentBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006415 pw.print(prefix); pw.print("mDock=("); pw.print(mDockLeft);
6416 pw.print(","); pw.print(mDockTop);
6417 pw.print(")-("); pw.print(mDockRight);
6418 pw.print(","); pw.print(mDockBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07006419 pw.print(prefix); pw.print("mDockLayer="); pw.print(mDockLayer);
6420 pw.print(" mStatusBarLayer="); pw.println(mStatusBarLayer);
Dianne Hackborn7ad44382012-10-18 17:46:00 -07006421 pw.print(prefix); pw.print("mShowingLockscreen="); pw.print(mShowingLockscreen);
6422 pw.print(" mShowingDream="); pw.print(mShowingDream);
6423 pw.print(" mDreamingLockscreen="); pw.println(mDreamingLockscreen);
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006424 if (mLastInputMethodWindow != null) {
6425 pw.print(prefix); pw.print("mLastInputMethodWindow=");
6426 pw.println(mLastInputMethodWindow);
6427 }
6428 if (mLastInputMethodTargetWindow != null) {
6429 pw.print(prefix); pw.print("mLastInputMethodTargetWindow=");
6430 pw.println(mLastInputMethodTargetWindow);
6431 }
6432 if (mStatusBar != null) {
6433 pw.print(prefix); pw.print("mStatusBar=");
Dianne Hackbornae6688b2015-02-11 17:02:41 -08006434 pw.print(mStatusBar); pw.print(" isStatusBarKeyguard=");
6435 pw.println(isStatusBarKeyguard());
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006436 }
6437 if (mNavigationBar != null) {
6438 pw.print(prefix); pw.print("mNavigationBar=");
6439 pw.println(mNavigationBar);
6440 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006441 if (mFocusedWindow != null) {
6442 pw.print(prefix); pw.print("mFocusedWindow=");
6443 pw.println(mFocusedWindow);
6444 }
6445 if (mFocusedApp != null) {
6446 pw.print(prefix); pw.print("mFocusedApp=");
6447 pw.println(mFocusedApp);
6448 }
6449 if (mWinDismissingKeyguard != null) {
6450 pw.print(prefix); pw.print("mWinDismissingKeyguard=");
6451 pw.println(mWinDismissingKeyguard);
6452 }
6453 if (mTopFullscreenOpaqueWindowState != null) {
6454 pw.print(prefix); pw.print("mTopFullscreenOpaqueWindowState=");
6455 pw.println(mTopFullscreenOpaqueWindowState);
6456 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01006457 if (mTopFullscreenOpaqueOrDimmingWindowState != null) {
6458 pw.print(prefix); pw.print("mTopFullscreenOpaqueOrDimmingWindowState=");
6459 pw.println(mTopFullscreenOpaqueOrDimmingWindowState);
6460 }
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08006461 if (mForcingShowNavBar) {
6462 pw.print(prefix); pw.print("mForcingShowNavBar=");
6463 pw.println(mForcingShowNavBar); pw.print( "mForcingShowNavBarLayer=");
6464 pw.println(mForcingShowNavBarLayer);
6465 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07006466 pw.print(prefix); pw.print("mTopIsFullscreen="); pw.print(mTopIsFullscreen);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006467 pw.print(" mHideLockScreen="); pw.println(mHideLockScreen);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07006468 pw.print(prefix); pw.print("mForceStatusBar="); pw.print(mForceStatusBar);
6469 pw.print(" mForceStatusBarFromKeyguard=");
6470 pw.println(mForceStatusBarFromKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006471 pw.print(prefix); pw.print("mDismissKeyguard="); pw.print(mDismissKeyguard);
Craig Mautnerad09bcc2012-10-08 13:33:11 -07006472 pw.print(" mWinDismissingKeyguard="); pw.print(mWinDismissingKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006473 pw.print(" mHomePressed="); pw.println(mHomePressed);
6474 pw.print(prefix); pw.print("mAllowLockscreenWhenOn="); pw.print(mAllowLockscreenWhenOn);
6475 pw.print(" mLockScreenTimeout="); pw.print(mLockScreenTimeout);
6476 pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive);
6477 pw.print(prefix); pw.print("mEndcallBehavior="); pw.print(mEndcallBehavior);
6478 pw.print(" mIncallPowerBehavior="); pw.print(mIncallPowerBehavior);
6479 pw.print(" mLongPressOnHomeBehavior="); pw.println(mLongPressOnHomeBehavior);
6480 pw.print(prefix); pw.print("mLandscapeRotation="); pw.print(mLandscapeRotation);
6481 pw.print(" mSeascapeRotation="); pw.println(mSeascapeRotation);
6482 pw.print(prefix); pw.print("mPortraitRotation="); pw.print(mPortraitRotation);
6483 pw.print(" mUpsideDownRotation="); pw.println(mUpsideDownRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07006484 pw.print(prefix); pw.print("mDemoHdmiRotation="); pw.print(mDemoHdmiRotation);
6485 pw.print(" mDemoHdmiRotationLock="); pw.println(mDemoHdmiRotationLock);
6486 pw.print(prefix); pw.print("mUndockedHdmiRotation="); pw.println(mUndockedHdmiRotation);
Jeff Brown600f0032014-05-22 17:06:00 -07006487
Tim Kilbournd7c0c2e2014-05-29 16:08:10 -07006488 mGlobalKeyManager.dump(prefix, pw);
John Spurlock27735a42013-08-14 17:57:38 -04006489 mStatusBarController.dump(pw, prefix);
6490 mNavigationBarController.dump(pw, prefix);
John Spurlockc6d1c602014-01-17 15:22:06 -05006491 PolicyControl.dump(prefix, pw);
Jeff Brown600f0032014-05-22 17:06:00 -07006492
Jeff Browna20dda42014-05-27 20:57:24 -07006493 if (mWakeGestureListener != null) {
6494 mWakeGestureListener.dump(pw, prefix);
6495 }
Jeff Brown600f0032014-05-22 17:06:00 -07006496 if (mOrientationListener != null) {
6497 mOrientationListener.dump(pw, prefix);
6498 }
Filip Gruszczynskicfb31852015-02-25 21:47:12 +00006499 if (mBurnInProtectionHelper != null) {
6500 mBurnInProtectionHelper.dump(prefix, pw);
6501 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006502 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006503}