blob: 153384ceac79b92de65da3000b6bebd46e3f33fd [file] [log] [blame]
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001/*
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16package com.android.internal.policy.impl;
17
Dianne Hackborna4972e92012-03-14 10:38:05 -070018import android.app.ActivityManager;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080019import android.app.ActivityManagerNative;
Dianne Hackbornc2293022013-02-06 23:14:49 -080020import android.app.AppOpsManager;
Daniel Sandler6396c722013-04-16 20:19:09 -040021import android.app.IUiModeManager;
Dianne Hackborn661cd522011-08-22 00:26:20 -070022import android.app.ProgressDialog;
Jeff Brownde7a8ea2012-06-13 18:28:57 -070023import android.app.SearchManager;
John Spurlock97642182013-07-29 17:58:39 -040024import android.app.StatusBarManager;
Dianne Hackborn78968392010-03-04 20:47:56 -080025import android.app.UiModeManager;
Dianne Hackborn39c2d712009-09-22 11:41:31 -070026import android.content.ActivityNotFoundException;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080027import android.content.BroadcastReceiver;
Daniel Sandler0601eb72011-04-13 01:01:32 -040028import android.content.ComponentName;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080029import android.content.ContentResolver;
30import android.content.Context;
31import android.content.Intent;
Mike Lockwood1753f7f2009-08-24 14:49:07 -070032import android.content.IntentFilter;
Winson Chung9112ec32011-06-27 13:15:32 -070033import android.content.ServiceConnection;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080034import android.content.pm.ActivityInfo;
35import android.content.pm.PackageManager;
Daniel Sandler6396c722013-04-16 20:19:09 -040036import android.content.pm.ResolveInfo;
Dianne Hackborn2f0b1752011-05-31 17:59:49 -070037import android.content.res.CompatibilityInfo;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080038import android.content.res.Configuration;
39import android.content.res.Resources;
Craig Mautner8e4df6c2012-05-23 16:57:23 -070040import android.content.res.TypedArray;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080041import android.database.ContentObserver;
Dianne Hackbornc777e072010-02-12 13:07:59 -080042import android.graphics.PixelFormat;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080043import android.graphics.Rect;
Michael Jurka7a348952012-02-27 13:07:58 -080044import android.media.AudioManager;
45import android.media.IAudioService;
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -070046import android.media.Ringtone;
47import android.media.RingtoneManager;
RoboErik3c45c292014-07-08 16:47:31 -070048import android.media.session.MediaController;
49import android.media.session.MediaSession;
RoboErik8a2cfc32014-05-16 11:19:38 -070050import android.media.session.MediaSessionLegacyHelper;
RoboErik3c45c292014-07-08 16:47:31 -070051import android.media.session.MediaSessionManager;
52import android.media.session.PlaybackState;
Dianne Hackborn38e29a62011-09-18 14:43:08 -070053import android.os.Bundle;
Jeff Brown9a538ee2012-08-20 14:56:57 -070054import android.os.FactoryTest;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080055import android.os.Handler;
56import android.os.IBinder;
Jeff Brown32cbc38552011-12-01 14:01:49 -080057import android.os.Looper;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -070058import android.os.Message;
59import android.os.Messenger;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080060import android.os.PowerManager;
61import android.os.RemoteException;
62import android.os.ServiceManager;
63import android.os.SystemClock;
64import android.os.SystemProperties;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -080065import android.os.UEventObserver;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -070066import android.os.UserHandle;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080067import android.os.Vibrator;
68import android.provider.Settings;
Jose Lima9546b202014-07-02 17:21:51 -070069import android.service.dreams.DreamManagerInternal;
John Spurlockc8b46ca2013-04-08 12:59:26 -040070import android.service.dreams.DreamService;
71import android.service.dreams.IDreamManager;
Santos Cordon9eb45932014-06-27 12:28:43 -070072import android.telecomm.TelecommManager;
Dianne Hackborn81e56d52011-05-26 00:55:58 -070073import android.util.DisplayMetrics;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080074import android.util.EventLog;
75import android.util.Log;
Jeff Browna41ca772010-08-11 14:46:32 -070076import android.util.Slog;
Jeff Brown6651a632011-11-28 12:59:11 -080077import android.util.SparseArray;
Dianne Hackbornf87d1962012-04-04 12:48:24 -070078import android.view.Display;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080079import android.view.Gravity;
80import android.view.HapticFeedbackConstants;
Dianne Hackborne0f085d2011-11-30 18:41:15 -080081import android.view.IApplicationToken;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080082import android.view.IWindowManager;
Jeff Browna41ca772010-08-11 14:46:32 -070083import android.view.InputChannel;
Jeff Brown4d396052010-10-29 21:50:21 -070084import android.view.InputDevice;
Jeff Brown4952dfd2011-11-30 19:23:22 -080085import android.view.InputEvent;
Jeff Brown32cbc38552011-12-01 14:01:49 -080086import android.view.InputEventReceiver;
Jeff Brown6b53e8d2010-11-10 16:03:06 -080087import android.view.KeyCharacterMap;
Craig Mautnerae446592012-12-06 19:05:05 -080088import android.view.KeyCharacterMap.FallbackAction;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080089import android.view.KeyEvent;
90import android.view.MotionEvent;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080091import android.view.Surface;
92import android.view.View;
93import android.view.ViewConfiguration;
94import android.view.Window;
95import android.view.WindowManager;
Craig Mautnerae446592012-12-06 19:05:05 -080096import android.view.WindowManagerGlobal;
Craig Mautner8a0da012014-05-31 15:13:37 -070097import android.view.WindowManagerInternal;
Craig Mautnerae446592012-12-06 19:05:05 -080098import android.view.WindowManagerPolicy;
Craig Mautnerae446592012-12-06 19:05:05 -080099import android.view.accessibility.AccessibilityEvent;
Svetoslav8e3feb12014-02-24 13:46:47 -0800100import android.view.accessibility.AccessibilityManager;
Craig Mautnerae446592012-12-06 19:05:05 -0800101import android.view.animation.Animation;
102import android.view.animation.AnimationUtils;
103
104import com.android.internal.R;
Jorim Jaggi380ecb82014-03-14 17:25:20 +0100105import com.android.internal.policy.IKeyguardService;
106import com.android.internal.policy.IKeyguardServiceConstants;
Craig Mautnerae446592012-12-06 19:05:05 -0800107import com.android.internal.policy.PolicyManager;
Jim Miller5ecd8112013-01-09 18:50:26 -0800108import com.android.internal.policy.impl.keyguard.KeyguardServiceDelegate;
Craig Mautner8a0da012014-05-31 15:13:37 -0700109import com.android.internal.policy.impl.keyguard.KeyguardServiceDelegate.ShowListener;
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;
Craig Mautnerae446592012-12-06 19:05:05 -0800113
114import java.io.File;
115import java.io.FileReader;
116import java.io.IOException;
117import java.io.PrintWriter;
Craig Mautner8a0da012014-05-31 15:13:37 -0700118import java.util.ArrayList;
Craig Mautner2bc789b2014-03-19 19:48:38 -0700119import java.util.HashSet;
RoboErik3c45c292014-07-08 16:47:31 -0700120import java.util.List;
Craig Mautnerae446592012-12-06 19:05:05 -0800121
Dianne Hackbornc652de82013-02-15 16:32:56 -0800122import static android.view.WindowManager.LayoutParams.*;
Jeff Brownac143512012-04-05 18:57:33 -0700123import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_ABSENT;
124import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_OPEN;
125import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_CLOSED;
Dianne Hackborn08743722009-12-21 12:16:51 -0800126
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800127/**
The Android Open Source Project0727d222009-03-11 12:11:58 -0700128 * WindowManagerPolicy implementation for the Android phone UI. This
129 * introduces a new method suffix, Lp, for an internal lock of the
130 * PhoneWindowManager. This is used to protect some internal state, and
John Spurlock04db1762013-05-13 12:46:41 -0400131 * 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 -0700132 * of both of those when held.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800133 */
134public class PhoneWindowManager implements WindowManagerPolicy {
135 static final String TAG = "WindowManager";
136 static final boolean DEBUG = false;
Joe Onorato43a17652011-04-06 19:22:23 -0700137 static final boolean localLOGV = false;
The Android Open Source Project11267662009-03-18 17:39:47 -0700138 static final boolean DEBUG_LAYOUT = false;
Jeff Brown40013652012-05-16 21:22:36 -0700139 static final boolean DEBUG_INPUT = false;
Craig Mautner6fbda632012-07-03 09:26:39 -0700140 static final boolean DEBUG_STARTING_WINDOW = false;
Craig Mautner8a0da012014-05-31 15:13:37 -0700141 static final boolean DEBUG_WAKEUP = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800142 static final boolean SHOW_STARTING_ANIMATIONS = true;
143 static final boolean SHOW_PROCESSES_ON_ALT_MENU = false;
Joe Onoratod208e702010-10-08 16:22:43 -0400144
Daniel Sandler6396c722013-04-16 20:19:09 -0400145 // Whether to allow dock apps with METADATA_DOCK_HOME to temporarily take over the Home key.
146 // No longer recommended for desk docks; still useful in car docks.
147 static final boolean ENABLE_CAR_DOCK_HOME_CAPTURE = true;
148 static final boolean ENABLE_DESK_DOCK_HOME_CAPTURE = false;
149
Jeff Brown6d8fd272014-05-20 21:24:38 -0700150 static final int SHORT_PRESS_POWER_NOTHING = 0;
151 static final int SHORT_PRESS_POWER_GO_TO_SLEEP = 1;
152 static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP = 2;
153 static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME = 3;
154
Joe Onoratod208e702010-10-08 16:22:43 -0400155 static final int LONG_PRESS_POWER_NOTHING = 0;
156 static final int LONG_PRESS_POWER_GLOBAL_ACTIONS = 1;
157 static final int LONG_PRESS_POWER_SHUT_OFF = 2;
Jeff Brown9a538ee2012-08-20 14:56:57 -0700158 static final int LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM = 3;
Michael Jurka3b1fc472011-06-13 10:54:40 -0700159
160 // These need to match the documentation/constant in
161 // core/res/res/values/config.xml
Joe Onorato46b0d682010-11-22 17:37:27 -0800162 static final int LONG_PRESS_HOME_NOTHING = 0;
Michael Wrightc9ebea72013-01-16 19:25:02 -0800163 static final int LONG_PRESS_HOME_RECENT_SYSTEM_UI = 1;
Jeff Browncaca8812013-05-09 13:34:33 -0700164 static final int LONG_PRESS_HOME_ASSIST = 2;
165
166 static final int DOUBLE_TAP_HOME_NOTHING = 0;
167 static final int DOUBLE_TAP_HOME_RECENT_SYSTEM_UI = 1;
Joe Onorato46b0d682010-11-22 17:37:27 -0800168
Dianne Hackborn5cb8d792009-05-21 17:34:15 -0700169 static final int APPLICATION_MEDIA_SUBLAYER = -2;
170 static final int APPLICATION_MEDIA_OVERLAY_SUBLAYER = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800171 static final int APPLICATION_PANEL_SUBLAYER = 1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800172 static final int APPLICATION_SUB_PANEL_SUBLAYER = 2;
Craig Mautner88400d32012-09-30 12:35:45 -0700173
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800174 static public final String SYSTEM_DIALOG_REASON_KEY = "reason";
175 static public final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions";
176 static public final String SYSTEM_DIALOG_REASON_RECENT_APPS = "recentapps";
Joe Onoratof275f0c2009-11-24 16:11:13 -0500177 static public final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey";
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700178 static public final String SYSTEM_DIALOG_REASON_ASSIST = "assist";
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800179
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700180 /**
181 * These are the system UI flags that, when changing, can cause the layout
182 * of the screen to change.
183 */
184 static final int SYSTEM_UI_CHANGING_LAYOUT =
John Spurlocke1f366f2013-08-05 12:22:40 -0400185 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlock7f4820a2013-10-08 12:54:35 -0400186 | View.SYSTEM_UI_FLAG_FULLSCREEN
187 | View.STATUS_BAR_TRANSLUCENT
Adrian Roosea562512014-05-05 13:33:03 +0200188 | View.NAVIGATION_BAR_TRANSLUCENT
189 | View.SYSTEM_UI_TRANSPARENT;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700190
Jim Miller5ecd8112013-01-09 18:50:26 -0800191 /**
192 * Keyguard stuff
193 */
194 private WindowState mKeyguardScrim;
Jorim Jaggi380ecb82014-03-14 17:25:20 +0100195 private boolean mKeyguardHidden;
Jorim Jaggicff0acb2014-03-31 16:35:15 +0200196 private boolean mKeyguardDrawn;
Jim Miller5ecd8112013-01-09 18:50:26 -0800197
Jeff Brown6651a632011-11-28 12:59:11 -0800198 /* Table of Application Launch keys. Maps from key codes to intent categories.
199 *
200 * These are special keys that are used to launch particular kinds of applications,
201 * such as a web browser. HID defines nearly a hundred of them in the Consumer (0x0C)
202 * usage page. We don't support quite that many yet...
203 */
204 static SparseArray<String> sApplicationLaunchKeyCategories;
205 static {
206 sApplicationLaunchKeyCategories = new SparseArray<String>();
207 sApplicationLaunchKeyCategories.append(
208 KeyEvent.KEYCODE_EXPLORER, Intent.CATEGORY_APP_BROWSER);
209 sApplicationLaunchKeyCategories.append(
210 KeyEvent.KEYCODE_ENVELOPE, Intent.CATEGORY_APP_EMAIL);
211 sApplicationLaunchKeyCategories.append(
212 KeyEvent.KEYCODE_CONTACTS, Intent.CATEGORY_APP_CONTACTS);
213 sApplicationLaunchKeyCategories.append(
214 KeyEvent.KEYCODE_CALENDAR, Intent.CATEGORY_APP_CALENDAR);
215 sApplicationLaunchKeyCategories.append(
216 KeyEvent.KEYCODE_MUSIC, Intent.CATEGORY_APP_MUSIC);
217 sApplicationLaunchKeyCategories.append(
218 KeyEvent.KEYCODE_CALCULATOR, Intent.CATEGORY_APP_CALCULATOR);
219 }
220
Dianne Hackborndf89e652011-10-06 22:35:11 -0700221 /**
222 * Lock protecting internal state. Must not call out into window
223 * manager with lock held. (This lock will be acquired in places
224 * where the window manager is calling in with its own lock held.)
225 */
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800226 private final Object mLock = new Object();
Dianne Hackborndf89e652011-10-06 22:35:11 -0700227
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800228 Context mContext;
229 IWindowManager mWindowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700230 WindowManagerFuncs mWindowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -0700231 WindowManagerInternal mWindowManagerInternal;
Jeff Brown96307042012-07-27 15:51:34 -0700232 PowerManager mPowerManager;
Jose Lima9546b202014-07-02 17:21:51 -0700233 DreamManagerInternal mDreamManagerInternal;
Joe Onorato93056472010-09-10 10:30:46 -0400234 IStatusBarService mStatusBarService;
Jeff Browncaca8812013-05-09 13:34:33 -0700235 boolean mPreloadedRecentApps;
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700236 final Object mServiceAquireLock = new Object();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800237 Vibrator mVibrator; // Vibrator for giving feedback of orientation changes
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700238 SearchManager mSearchManager;
Svetoslav8e3feb12014-02-24 13:46:47 -0800239 AccessibilityManager mAccessibilityManager;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800240
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700241 // Vibrator pattern for haptic feedback of a long press.
242 long[] mLongPressVibePattern;
Craig Mautner88400d32012-09-30 12:35:45 -0700243
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700244 // Vibrator pattern for haptic feedback of virtual key press.
245 long[] mVirtualKeyVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700246
Amith Yamasanic33cb712010-02-10 15:21:49 -0800247 // Vibrator pattern for a short vibration.
248 long[] mKeyboardTapVibePattern;
249
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -0700250 // Vibrator pattern for a short vibration when tapping on an hour/minute tick of a Clock.
251 long[] mClockTickVibePattern;
252
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700253 // Vibrator pattern for haptic feedback during boot when safe mode is disabled.
254 long[] mSafeModeDisabledVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700255
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700256 // Vibrator pattern for haptic feedback during boot when safe mode is enabled.
257 long[] mSafeModeEnabledVibePattern;
Romain Guy8154cd32010-03-29 14:41:15 -0700258
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800259 /** If true, hitting shift & menu will broadcast Intent.ACTION_BUG_REPORT */
260 boolean mEnableShiftMenuBugReports = false;
Mike Lockwoodd747dc82011-09-13 16:28:22 -0400261
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800262 boolean mSafeMode;
263 WindowState mStatusBar = null;
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700264 int mStatusBarHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400265 WindowState mNavigationBar = null;
Daniel Sandler36412a72011-08-04 09:35:13 -0400266 boolean mHasNavigationBar = false;
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700267 boolean mCanHideNavigationBar = false;
Daniel Sandler4a066c52012-04-20 14:49:13 -0400268 boolean mNavigationBarCanMove = false; // can the navigation bar ever move to the side?
269 boolean mNavigationBarOnBottom = true; // is the navigation bar on the bottom *right now*?
270 int[] mNavigationBarHeightForRotation = new int[4];
271 int[] mNavigationBarWidthForRotation = new int[4];
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400272
Jim Miller5ecd8112013-01-09 18:50:26 -0800273 KeyguardServiceDelegate mKeyguardDelegate;
Craig Mautner8a0da012014-05-31 15:13:37 -0700274 // The following are only accessed on the mHandler thread.
275 boolean mKeyguardDrawComplete;
276 boolean mWindowManagerDrawComplete;
Craig Mautner13f6ea72014-06-23 14:57:02 -0700277 ScreenOnListener mScreenOnListener;
278 final Runnable mWindowManagerDrawCallback = new Runnable() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700279 @Override
Craig Mautner13f6ea72014-06-23 14:57:02 -0700280 public void run() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700281 if (DEBUG_WAKEUP) Slog.i(TAG, "All windows ready for display!");
282 mHandler.sendEmptyMessage(MSG_WINDOW_MANAGER_DRAWN_COMPLETE);
283 }
284 };
285 final ShowListener mKeyguardDelegateCallback = new ShowListener() {
286 @Override
287 public void onShown(IBinder windowToken) {
288 if (DEBUG_WAKEUP) Slog.d(TAG, "mKeyguardDelegate.ShowListener.onShown.");
289 mHandler.sendEmptyMessage(MSG_KEYGUARD_DRAWN_COMPLETE);
290 }
291 };
292
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800293 GlobalActions mGlobalActions;
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700294 volatile boolean mPowerKeyHandled; // accessed from input reader and handler thread
295 boolean mPendingPowerKeyUpCanceled;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800296 Handler mHandler;
satok1bc0a492012-04-25 22:47:12 +0900297 WindowState mLastInputMethodWindow = null;
298 WindowState mLastInputMethodTargetWindow = null;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800299
Winson Chungd42a6cf2014-06-03 16:24:04 -0700300 boolean mRecentsVisible;
Winson Chung1e8d71b2014-05-16 17:05:22 -0700301 int mRecentAppsHeldModifiers;
Jeff Browncf39bdf2012-05-18 14:41:19 -0700302 boolean mLanguageSwitchKeyPressed;
Jeff Brown68b909d2011-12-07 16:36:01 -0800303
Jeff Brown2e7760e2012-04-11 15:14:55 -0700304 int mLidState = LID_ABSENT;
Jeff Browndaa37532012-05-01 15:54:03 -0700305 boolean mHaveBuiltInKeyboard;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800306
Dianne Hackbornc777e072010-02-12 13:07:59 -0800307 boolean mSystemReady;
Dianne Hackbornba24e4d2011-09-01 11:17:06 -0700308 boolean mSystemBooted;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800309 boolean mHdmiPlugged;
Jeff Brown4f5fa282014-06-12 19:19:15 -0700310 IUiModeManager mUiModeManager;
Daniel Sandler6396c722013-04-16 20:19:09 -0400311 int mUiMode;
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700312 int mDockMode = Intent.EXTRA_DOCK_STATE_UNDOCKED;
Mike Lockwood1753f7f2009-08-24 14:49:07 -0700313 int mLidOpenRotation;
Mike Lockwood2d1efbd2009-09-16 12:15:53 -0400314 int mCarDockRotation;
315 int mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -0700316 int mUndockedHdmiRotation;
317 int mDemoHdmiRotation;
318 boolean mDemoHdmiRotationLock;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400319
Jeff Browna20dda42014-05-27 20:57:24 -0700320 boolean mWakeGestureEnabledSetting;
321 MyWakeGestureListener mWakeGestureListener;
322
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700323 // Default display does not rotate, apps that require non-default orientation will have to
324 // have the orientation emulated.
325 private boolean mForceDefaultOrientation = false;
326
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400327 int mUserRotationMode = WindowManagerPolicy.USER_ROTATION_FREE;
328 int mUserRotation = Surface.ROTATION_0;
Jeff Brown207673cd2012-06-05 17:47:11 -0700329 boolean mAccelerometerDefault;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400330
Jeff Brownbcdfc622014-03-06 19:13:04 -0800331 boolean mSupportAutoRotation;
Jeff Brownd3187e32011-09-21 19:26:44 -0700332 int mAllowAllRotations = -1;
Mike Lockwoode9867d22009-09-20 01:59:02 -0400333 boolean mCarDockEnablesAccelerometer;
334 boolean mDeskDockEnablesAccelerometer;
Dianne Hackborn2862fff2009-09-15 22:56:29 -0700335 int mLidKeyboardAccessibility;
336 int mLidNavigationAccessibility;
Jeff Brownc458ce92012-04-30 14:58:40 -0700337 boolean mLidControlsSleep;
Jeff Brown6d8fd272014-05-20 21:24:38 -0700338 int mShortPressOnPowerBehavior = -1;
Joe Onoratod208e702010-10-08 16:22:43 -0400339 int mLongPressOnPowerBehavior = -1;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -0700340 boolean mScreenOnEarly = false;
341 boolean mScreenOnFully = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800342 boolean mOrientationSensorEnabled = false;
343 int mCurrentAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800344 boolean mHasSoftInput = false;
Daniel Sandlerdd73ee42013-10-11 22:19:59 -0400345 boolean mTranslucentDecorEnabled = true;
Craig Mautner967212c2013-04-13 21:10:58 -0700346
Jeff Brown70825162012-03-28 17:27:48 -0700347 int mPointerLocationMode = 0; // guarded by mLock
Joe Onorato664644d2011-01-23 17:53:23 -0800348
349 // The last window we were told about in focusChanged.
350 WindowState mFocusedWindow;
Dianne Hackborne0f085d2011-11-30 18:41:15 -0800351 IApplicationToken mFocusedApp;
Joe Onorato664644d2011-01-23 17:53:23 -0800352
Jeff Brown70825162012-03-28 17:27:48 -0700353 PointerLocationView mPointerLocationView;
Jeff Brown32cbc38552011-12-01 14:01:49 -0800354
Dianne Hackbornc652de82013-02-15 16:32:56 -0800355 // The current size of the screen; really; extends into the overscan area of
356 // the screen and doesn't account for any system elements like the status bar.
357 int mOverscanScreenLeft, mOverscanScreenTop;
358 int mOverscanScreenWidth, mOverscanScreenHeight;
359 // The current visible size of the screen; really; (ir)regardless of whether the status
360 // bar can be hidden but not extending into the overscan area.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800361 int mUnrestrictedScreenLeft, mUnrestrictedScreenTop;
362 int mUnrestrictedScreenWidth, mUnrestrictedScreenHeight;
Dianne Hackborn313440842013-02-19 19:22:59 -0800363 // Like mOverscanScreen*, but allowed to move into the overscan region where appropriate.
364 int mRestrictedOverscanScreenLeft, mRestrictedOverscanScreenTop;
365 int mRestrictedOverscanScreenWidth, mRestrictedOverscanScreenHeight;
Dianne Hackborn82de1ae2010-10-28 11:28:39 -0700366 // The current size of the screen; these may be different than (0,0)-(dw,dh)
367 // if the status bar can't be hidden; in that case it effectively carves out
368 // that area of the display from all other windows.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800369 int mRestrictedScreenLeft, mRestrictedScreenTop;
370 int mRestrictedScreenWidth, mRestrictedScreenHeight;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700371 // During layout, the current screen borders accounting for any currently
372 // visible system UI elements.
373 int mSystemLeft, mSystemTop, mSystemRight, mSystemBottom;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700374 // For applications requesting stable content insets, these are them.
375 int mStableLeft, mStableTop, mStableRight, mStableBottom;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -0700376 // For applications requesting stable content insets but have also set the
377 // fullscreen window flag, these are the stable dimensions without the status bar.
378 int mStableFullscreenLeft, mStableFullscreenTop;
379 int mStableFullscreenRight, mStableFullscreenBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800380 // During layout, the current screen borders with all outer decoration
381 // (status bar, input method dock) accounted for.
382 int mCurLeft, mCurTop, mCurRight, mCurBottom;
383 // During layout, the frame in which content should be displayed
384 // to the user, accounting for all screen decoration except for any
385 // space they deem as available for other content. This is usually
386 // the same as mCur*, but may be larger if the screen decor has supplied
387 // content insets.
388 int mContentLeft, mContentTop, mContentRight, mContentBottom;
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700389 // During layout, the frame in which voice content should be displayed
390 // to the user, accounting for all screen decoration except for any
391 // space they deem as available for other content.
392 int mVoiceContentLeft, mVoiceContentTop, mVoiceContentRight, mVoiceContentBottom;
Dianne Hackborn8e11ef02010-11-18 19:47:42 -0800393 // During layout, the current screen borders along which input method
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800394 // windows are placed.
395 int mDockLeft, mDockTop, mDockRight, mDockBottom;
396 // During layout, the layer at which the doc window is placed.
397 int mDockLayer;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700398 // During layout, this is the layer of the status bar.
399 int mStatusBarLayer;
Dianne Hackborne26ab702011-10-16 13:21:33 -0700400 int mLastSystemUiFlags;
401 // Bits that we are in the process of clearing, so we want to prevent
402 // them from being set by applications until everything has been updated
403 // to have them clear.
404 int mResettingSystemUiFlags = 0;
405 // Bits that we are currently always keeping cleared.
406 int mForceClearedSystemUiFlags = 0;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -0800407 // What we last reported to system UI about whether the compatibility
408 // menu needs to be displayed.
409 boolean mLastFocusNeedsMenu = false;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700410
411 FakeWindow mHideNavFakeWindow = null;
412
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800413 static final Rect mTmpParentFrame = new Rect();
414 static final Rect mTmpDisplayFrame = new Rect();
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800415 static final Rect mTmpOverscanFrame = new Rect();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800416 static final Rect mTmpContentFrame = new Rect();
417 static final Rect mTmpVisibleFrame = new Rect();
John Spurlock46646232013-09-30 22:32:42 -0400418 static final Rect mTmpDecorFrame = new Rect();
Adrian Roosfa104232014-06-20 16:10:14 -0700419 static final Rect mTmpStableFrame = new Rect();
Dianne Hackborn1f903c32011-09-13 19:18:06 -0700420 static final Rect mTmpNavigationFrame = new Rect();
Craig Mautner967212c2013-04-13 21:10:58 -0700421
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800422 WindowState mTopFullscreenOpaqueWindowState;
Craig Mautner2bc789b2014-03-19 19:48:38 -0700423 HashSet<IApplicationToken> mAppsToBeHidden = new HashSet<IApplicationToken>();
Joe Onorato93056472010-09-10 10:30:46 -0400424 boolean mTopIsFullscreen;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800425 boolean mForceStatusBar;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -0700426 boolean mForceStatusBarFromKeyguard;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700427 boolean mHideLockScreen;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -0800428 boolean mForcingShowNavBar;
429 int mForcingShowNavBarLayer;
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700430
431 // States of keyguard dismiss.
432 private static final int DISMISS_KEYGUARD_NONE = 0; // Keyguard not being dismissed.
433 private static final int DISMISS_KEYGUARD_START = 1; // Keyguard needs to be dismissed.
434 private static final int DISMISS_KEYGUARD_CONTINUE = 2; // Keyguard has been dismissed.
435 int mDismissKeyguard = DISMISS_KEYGUARD_NONE;
436
437 /** The window that is currently dismissing the keyguard. Dismissing the keyguard must only
438 * be done once per window. */
439 private WindowState mWinDismissingKeyguard;
440
Craig Mautnerc9457fa2014-06-06 14:27:48 -0700441 /** The window that is currently showing "over" the keyguard. If there is an app window
442 * belonging to another app on top of this the keyguard shows. If there is a fullscreen
443 * app window under this, still dismiss the keyguard but don't show the app underneath. Show
444 * the wallpaper. */
445 private WindowState mWinShowWhenLocked;
446
Dianne Hackborn7ad44382012-10-18 17:46:00 -0700447 boolean mShowingLockscreen;
448 boolean mShowingDream;
449 boolean mDreamingLockscreen;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800450 boolean mHomePressed;
Jeff Browncaca8812013-05-09 13:34:33 -0700451 boolean mHomeConsumed;
452 boolean mHomeDoubleTapPending;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800453 Intent mHomeIntent;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700454 Intent mCarDockIntent;
455 Intent mDeskDockIntent;
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700456 boolean mSearchKeyShortcutPending;
457 boolean mConsumeSearchKeyUp;
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700458 boolean mAssistKeyLongPressed;
Michael Wright6a62e552014-06-03 19:19:48 -0700459 boolean mPendingMetaAction;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800460
Mike Lockwood28569302010-01-28 11:54:40 -0500461 // support for activating the lock screen while the screen is on
462 boolean mAllowLockscreenWhenOn;
463 int mLockScreenTimeout;
464 boolean mLockScreenTimerActive;
465
David Brownbaf8d092010-03-08 21:52:59 -0800466 // Behavior of ENDCALL Button. (See Settings.System.END_BUTTON_BEHAVIOR.)
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800467 int mEndcallBehavior;
David Brownbaf8d092010-03-08 21:52:59 -0800468
469 // Behavior of POWER button while in-call and screen on.
470 // (See Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR.)
471 int mIncallPowerBehavior;
472
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700473 Display mDisplay;
474
Dianne Hackborn9d132642011-04-21 17:26:39 -0700475 int mLandscapeRotation = 0; // default landscape rotation
476 int mSeascapeRotation = 0; // "other" landscape rotation, 180 degrees from mLandscapeRotation
477 int mPortraitRotation = 0; // default portrait rotation
478 int mUpsideDownRotation = 0; // "other" portrait rotation
Mitsuru Oshima831d0d92009-06-16 18:27:18 -0700479
Dianne Hackbornc652de82013-02-15 16:32:56 -0800480 int mOverscanLeft = 0;
481 int mOverscanTop = 0;
482 int mOverscanRight = 0;
483 int mOverscanBottom = 0;
484
Joe Onorato46b0d682010-11-22 17:37:27 -0800485 // What we do when the user long presses on home
Jeff Browncaca8812013-05-09 13:34:33 -0700486 private int mLongPressOnHomeBehavior;
487
488 // What we do when the user double-taps on home
489 private int mDoubleTapOnHomeBehavior;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800490
Winson Chung9112ec32011-06-27 13:15:32 -0700491 // Screenshot trigger states
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700492 // Time to volume and power must be pressed within this interval of each other.
493 private static final long SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS = 150;
Winson Chung1cea2f32012-10-08 20:42:01 -0700494 // Increase the chord delay when taking a screenshot from the keyguard
495 private static final float KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER = 2.5f;
Christopher Tatee90585f2012-03-05 18:56:25 -0800496 private boolean mScreenshotChordEnabled;
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700497 private boolean mVolumeDownKeyTriggered;
498 private long mVolumeDownKeyTime;
499 private boolean mVolumeDownKeyConsumedByScreenshotChord;
500 private boolean mVolumeUpKeyTriggered;
501 private boolean mPowerKeyTriggered;
502 private long mPowerKeyTime;
Winson Chung9112ec32011-06-27 13:15:32 -0700503
Michael Wrightb854e242013-02-05 17:54:02 -0800504 /* The number of steps between min and max brightness */
505 private static final int BRIGHTNESS_STEPS = 10;
506
Christopher Tate5e08af02012-09-21 17:17:22 -0700507 SettingsObserver mSettingsObserver;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800508 ShortcutManager mShortcutManager;
509 PowerManager.WakeLock mBroadcastWakeLock;
Jeff Brown40013652012-05-16 21:22:36 -0700510 boolean mHavePendingMediaKeyRepeatWithWakeLock;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800511
Craig Mautnerd625ab22013-09-06 13:40:31 -0700512 private int mCurrentUserId;
513
Justin Kohd378ad72013-04-01 12:18:26 -0700514 // Maps global key codes to the components that will handle them.
515 private GlobalKeyManager mGlobalKeyManager;
516
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700517 // Fallback actions by key code.
518 private final SparseArray<KeyCharacterMap.FallbackAction> mFallbackActions =
519 new SparseArray<KeyCharacterMap.FallbackAction>();
Jeff Brown49ed71d2010-12-06 17:13:33 -0800520
Jeff Brown70825162012-03-28 17:27:48 -0700521 private static final int MSG_ENABLE_POINTER_LOCATION = 1;
522 private static final int MSG_DISABLE_POINTER_LOCATION = 2;
Jeff Brown40013652012-05-16 21:22:36 -0700523 private static final int MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK = 3;
524 private static final int MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK = 4;
Craig Mautner8a0da012014-05-31 15:13:37 -0700525 private static final int MSG_KEYGUARD_DRAWN_COMPLETE = 5;
526 private static final int MSG_KEYGUARD_DRAWN_TIMEOUT = 6;
527 private static final int MSG_WINDOW_MANAGER_DRAWN_COMPLETE = 7;
528 private static final int MSG_WAKING_UP = 8;
Craig Mautner84984fa2014-06-19 11:19:20 -0700529 private static final int MSG_DISPATCH_SHOW_RECENTS = 9;
Alan Viverettee34560b22014-07-10 14:50:06 -0700530 private static final int MSG_DISPATCH_SHOW_GLOBAL_ACTIONS = 10;
Jeff Brown70825162012-03-28 17:27:48 -0700531
532 private class PolicyHandler extends Handler {
533 @Override
534 public void handleMessage(Message msg) {
535 switch (msg.what) {
536 case MSG_ENABLE_POINTER_LOCATION:
537 enablePointerLocation();
538 break;
539 case MSG_DISABLE_POINTER_LOCATION:
540 disablePointerLocation();
541 break;
Jeff Brown40013652012-05-16 21:22:36 -0700542 case MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK:
543 dispatchMediaKeyWithWakeLock((KeyEvent)msg.obj);
544 break;
545 case MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK:
546 dispatchMediaKeyRepeatWithWakeLock((KeyEvent)msg.obj);
547 break;
Craig Mautner84984fa2014-06-19 11:19:20 -0700548 case MSG_DISPATCH_SHOW_RECENTS:
549 showRecentApps(false);
550 break;
Alan Viverettee34560b22014-07-10 14:50:06 -0700551 case MSG_DISPATCH_SHOW_GLOBAL_ACTIONS:
552 showGlobalActionsInternal();
553 break;
Craig Mautner8a0da012014-05-31 15:13:37 -0700554 case MSG_KEYGUARD_DRAWN_COMPLETE:
555 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mKeyguardDrawComplete");
556 mKeyguardDrawComplete = true;
557 finishScreenTurningOn();
558 break;
559 case MSG_KEYGUARD_DRAWN_TIMEOUT:
560 Slog.w(TAG, "Keyguard drawn timeout. Setting mKeyguardDrawComplete");
561 mKeyguardDrawComplete = true;
562 finishScreenTurningOn();
563 break;
564 case MSG_WINDOW_MANAGER_DRAWN_COMPLETE:
565 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mWindowManagerDrawComplete");
566 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
567 mWindowManagerDrawComplete = true;
568 finishScreenTurningOn();
569 break;
570 case MSG_WAKING_UP:
571 handleWakingUp((ScreenOnListener) msg.obj);
572 break;
Jeff Brown70825162012-03-28 17:27:48 -0700573 }
574 }
575 }
576
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800577 private UEventObserver mHDMIObserver = new UEventObserver() {
578 @Override
579 public void onUEvent(UEventObserver.UEvent event) {
580 setHdmiPlugged("1".equals(event.get("SWITCH_STATE")));
581 }
582 };
583
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800584 class SettingsObserver extends ContentObserver {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800585 SettingsObserver(Handler handler) {
586 super(handler);
587 }
David Brownbaf8d092010-03-08 21:52:59 -0800588
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800589 void observe() {
Christopher Tate5e08af02012-09-21 17:17:22 -0700590 // Observe all users' changes
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800591 ContentResolver resolver = mContext.getContentResolver();
592 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700593 Settings.System.END_BUTTON_BEHAVIOR), false, this,
594 UserHandle.USER_ALL);
David Brownbaf8d092010-03-08 21:52:59 -0800595 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700596 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR), false, this,
597 UserHandle.USER_ALL);
Jeff Browna20dda42014-05-27 20:57:24 -0700598 resolver.registerContentObserver(Settings.Secure.getUriFor(
599 Settings.Secure.WAKE_GESTURE_ENABLED), false, this,
600 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800601 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700602 Settings.System.ACCELEROMETER_ROTATION), false, this,
603 UserHandle.USER_ALL);
Mike Lockwood28569302010-01-28 11:54:40 -0500604 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700605 Settings.System.USER_ROTATION), false, this,
606 UserHandle.USER_ALL);
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400607 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700608 Settings.System.SCREEN_OFF_TIMEOUT), false, this,
609 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800610 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700611 Settings.System.POINTER_LOCATION), false, this,
612 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800613 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700614 Settings.Secure.DEFAULT_INPUT_METHOD), false, this,
615 UserHandle.USER_ALL);
John Spurlockd9b70bd2014-02-06 17:02:44 -0500616 resolver.registerContentObserver(Settings.Secure.getUriFor(
John Spurlockf1a36642013-10-12 17:50:42 -0400617 Settings.Secure.IMMERSIVE_MODE_CONFIRMATIONS), false, this,
Christopher Tate5e08af02012-09-21 17:17:22 -0700618 UserHandle.USER_ALL);
John Spurlockc6d1c602014-01-17 15:22:06 -0500619 resolver.registerContentObserver(Settings.Global.getUriFor(
620 Settings.Global.POLICY_CONTROL), false, this,
621 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800622 updateSettings();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800623 }
624
625 @Override public void onChange(boolean selfChange) {
Dianne Hackbornc777e072010-02-12 13:07:59 -0800626 updateSettings();
Jeff Brown01a98dd2011-09-20 15:08:29 -0700627 updateRotation(false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800628 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800629 }
Craig Mautner967212c2013-04-13 21:10:58 -0700630
Jeff Browna20dda42014-05-27 20:57:24 -0700631 class MyWakeGestureListener extends WakeGestureListener {
632 MyWakeGestureListener(Context context, Handler handler) {
633 super(context, handler);
634 }
635
636 @Override
637 public void onWakeUp() {
638 synchronized (mLock) {
639 if (shouldEnableWakeGestureLp()) {
Jeff Browne07b94b2014-06-18 15:56:27 -0700640 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
Jeff Browna20dda42014-05-27 20:57:24 -0700641 mPowerManager.wakeUp(SystemClock.uptimeMillis());
642 }
643 }
644 }
645 }
646
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800647 class MyOrientationListener extends WindowOrientationListener {
Craig Mautnereee29c42013-01-17 14:44:34 -0800648 MyOrientationListener(Context context, Handler handler) {
649 super(context, handler);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800650 }
Craig Mautner967212c2013-04-13 21:10:58 -0700651
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800652 @Override
Jeff Brownc0347aa2011-09-23 17:26:09 -0700653 public void onProposedRotationChanged(int rotation) {
Craig Mautnereda67292013-04-28 13:50:14 -0700654 if (localLOGV) Slog.v(TAG, "onProposedRotationChanged, rotation=" + rotation);
Jeff Brown01a98dd2011-09-20 15:08:29 -0700655 updateRotation(false);
656 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800657 }
658 MyOrientationListener mOrientationListener;
659
John Spurlock27735a42013-08-14 17:57:38 -0400660 private final BarController mStatusBarController = new BarController("StatusBar",
John Spurlock5b9145b2013-08-20 15:13:47 -0400661 View.STATUS_BAR_TRANSIENT,
662 View.STATUS_BAR_UNHIDE,
John Spurlockbd957402013-10-03 11:38:39 -0400663 View.STATUS_BAR_TRANSLUCENT,
664 StatusBarManager.WINDOW_STATUS_BAR,
665 WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
John Spurlock5b9145b2013-08-20 15:13:47 -0400666
John Spurlock27735a42013-08-14 17:57:38 -0400667 private final BarController mNavigationBarController = new BarController("NavigationBar",
John Spurlock5b9145b2013-08-20 15:13:47 -0400668 View.NAVIGATION_BAR_TRANSIENT,
669 View.NAVIGATION_BAR_UNHIDE,
John Spurlockbd957402013-10-03 11:38:39 -0400670 View.NAVIGATION_BAR_TRANSLUCENT,
671 StatusBarManager.WINDOW_NAVIGATION_BAR,
672 WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
John Spurlock5b9145b2013-08-20 15:13:47 -0400673
John Spurlockf1a36642013-10-12 17:50:42 -0400674 private ImmersiveModeConfirmation mImmersiveModeConfirmation;
John Spurlock32beb2c2013-03-11 10:16:47 -0400675
Craig Mautner037aa8d2013-06-07 10:35:44 -0700676 private SystemGesturesPointerEventListener mSystemGestures;
John Spurlock32beb2c2013-03-11 10:16:47 -0400677
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700678 IStatusBarService getStatusBarService() {
679 synchronized (mServiceAquireLock) {
680 if (mStatusBarService == null) {
681 mStatusBarService = IStatusBarService.Stub.asInterface(
682 ServiceManager.getService("statusbar"));
683 }
684 return mStatusBarService;
685 }
686 }
687
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700688 /*
689 * We always let the sensor be switched on by default except when
690 * the user has explicitly disabled sensor based rotation or when the
691 * screen is switched off.
692 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700693 boolean needSensorRunningLp() {
Jeff Brownbcdfc622014-03-06 19:13:04 -0800694 if (mSupportAutoRotation) {
695 if (mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
696 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
697 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT
698 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) {
699 // If the application has explicitly requested to follow the
700 // orientation, then we need to turn the sensor on.
701 return true;
702 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800703 }
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700704 if ((mCarDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_CAR) ||
Jeff Brown1a693182011-11-08 14:44:16 -0800705 (mDeskDockEnablesAccelerometer && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
706 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
707 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK))) {
Mike Lockwoode9867d22009-09-20 01:59:02 -0400708 // enable accelerometer if we are docked in a dock that enables accelerometer
709 // orientation management,
710 return true;
711 }
Jeff Brown207673cd2012-06-05 17:47:11 -0700712 if (mUserRotationMode == USER_ROTATION_LOCKED) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800713 // If the setting for using the sensor by default is enabled, then
714 // we will always leave it on. Note that the user could go to
715 // a window that forces an orientation that does not use the
716 // sensor and in theory we could turn it off... however, when next
717 // turning it on we won't have a good value for the current
718 // orientation for a little bit, which can cause orientation
719 // changes to lag, so we'd like to keep it always on. (It will
720 // still be turned off when the screen is off.)
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700721 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800722 }
Jeff Brownbcdfc622014-03-06 19:13:04 -0800723 return mSupportAutoRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800724 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700725
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800726 /*
727 * Various use cases for invoking this function
728 * screen turning off, should always disable listeners if already enabled
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700729 * screen turned on and current app has sensor based orientation, enable listeners
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800730 * if not already enabled
731 * screen turned on and current app does not have sensor orientation, disable listeners if
732 * already enabled
733 * screen turning on and current app has sensor based orientation, enable listeners if needed
734 * screen turning on and current app has nosensor based orientation, do nothing
735 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700736 void updateOrientationListenerLp() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800737 if (!mOrientationListener.canDetectOrientation()) {
738 // If sensor is turned off or nonexistent for some reason
739 return;
740 }
741 //Could have been invoked due to screen turning on or off or
742 //change of the currently visible window's orientation
Craig Mautnereda67292013-04-28 13:50:14 -0700743 if (localLOGV) Slog.v(TAG, "Screen status="+mScreenOnEarly+
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800744 ", current orientation="+mCurrentAppOrientation+
745 ", SensorEnabled="+mOrientationSensorEnabled);
746 boolean disable = true;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -0700747 if (mScreenOnEarly) {
The Android Open Source Project0727d222009-03-11 12:11:58 -0700748 if (needSensorRunningLp()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800749 disable = false;
750 //enable listener if not already enabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700751 if (!mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800752 mOrientationListener.enable();
Craig Mautnereda67292013-04-28 13:50:14 -0700753 if(localLOGV) Slog.v(TAG, "Enabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800754 mOrientationSensorEnabled = true;
755 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700756 }
757 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800758 //check if sensors need to be disabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700759 if (disable && mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800760 mOrientationListener.disable();
Craig Mautnereda67292013-04-28 13:50:14 -0700761 if(localLOGV) Slog.v(TAG, "Disabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800762 mOrientationSensorEnabled = false;
763 }
764 }
765
Jeff Brown4d396052010-10-29 21:50:21 -0700766 private void interceptPowerKeyDown(boolean handled) {
767 mPowerKeyHandled = handled;
768 if (!handled) {
Justin Kohfeabd2c2014-05-02 10:02:44 -0700769 mHandler.postDelayed(mPowerLongPress,
770 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Jeff Brown4d396052010-10-29 21:50:21 -0700771 }
772 }
773
774 private boolean interceptPowerKeyUp(boolean canceled) {
775 if (!mPowerKeyHandled) {
776 mHandler.removeCallbacks(mPowerLongPress);
777 return !canceled;
Jeff Brown4d396052010-10-29 21:50:21 -0700778 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700779 return false;
780 }
781
782 private void cancelPendingPowerKeyAction() {
783 if (!mPowerKeyHandled) {
784 mHandler.removeCallbacks(mPowerLongPress);
785 }
Jeff Brownff204712011-10-25 21:27:54 -0700786 if (mPowerKeyTriggered) {
787 mPendingPowerKeyUpCanceled = true;
788 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700789 }
790
791 private void interceptScreenshotChord() {
Christopher Tatee90585f2012-03-05 18:56:25 -0800792 if (mScreenshotChordEnabled
793 && mVolumeDownKeyTriggered && mPowerKeyTriggered && !mVolumeUpKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700794 final long now = SystemClock.uptimeMillis();
795 if (now <= mVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS
796 && now <= mPowerKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) {
797 mVolumeDownKeyConsumedByScreenshotChord = true;
798 cancelPendingPowerKeyAction();
799
Jeff Sharkey2991fa32012-12-05 18:06:43 -0800800 mHandler.postDelayed(mScreenshotRunnable, getScreenshotChordLongPressDelay());
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700801 }
802 }
803 }
804
Winson Chung1cea2f32012-10-08 20:42:01 -0700805 private long getScreenshotChordLongPressDelay() {
Jim Miller5ecd8112013-01-09 18:50:26 -0800806 if (mKeyguardDelegate.isShowing()) {
Winson Chung1cea2f32012-10-08 20:42:01 -0700807 // Double the time it takes to take a screenshot from the keyguard
808 return (long) (KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER *
Justin Kohfeabd2c2014-05-02 10:02:44 -0700809 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Winson Chung1cea2f32012-10-08 20:42:01 -0700810 }
Justin Kohfeabd2c2014-05-02 10:02:44 -0700811 return ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout();
Winson Chung1cea2f32012-10-08 20:42:01 -0700812 }
813
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700814 private void cancelPendingScreenshotChordAction() {
Jeff Sharkey2991fa32012-12-05 18:06:43 -0800815 mHandler.removeCallbacks(mScreenshotRunnable);
Jeff Brown4d396052010-10-29 21:50:21 -0700816 }
817
Jeff Brown6d8fd272014-05-20 21:24:38 -0700818 private void powerShortPress(long eventTime) {
819 if (mShortPressOnPowerBehavior < 0) {
820 mShortPressOnPowerBehavior = mContext.getResources().getInteger(
821 com.android.internal.R.integer.config_shortPressOnPowerBehavior);
822 }
823
824 switch (mShortPressOnPowerBehavior) {
825 case SHORT_PRESS_POWER_NOTHING:
826 break;
827 case SHORT_PRESS_POWER_GO_TO_SLEEP:
828 mPowerManager.goToSleep(eventTime,
829 PowerManager.GO_TO_SLEEP_REASON_USER, 0);
830 break;
831 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP:
832 mPowerManager.goToSleep(eventTime,
833 PowerManager.GO_TO_SLEEP_REASON_USER,
834 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
835 break;
836 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME:
837 mPowerManager.goToSleep(eventTime,
838 PowerManager.GO_TO_SLEEP_REASON_USER,
839 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
840 launchHomeFromHotKey();
841 break;
842 }
843 }
844
Jeff Brown4d396052010-10-29 21:50:21 -0700845 private final Runnable mPowerLongPress = new Runnable() {
Craig Mautnerf1b67412012-09-19 13:18:29 -0700846 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800847 public void run() {
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700848 // The context isn't read
849 if (mLongPressOnPowerBehavior < 0) {
Jeff Brown850c5b72012-10-01 15:17:22 -0700850 mLongPressOnPowerBehavior = mContext.getResources().getInteger(
851 com.android.internal.R.integer.config_longPressOnPowerBehavior);
Joe Onoratod208e702010-10-08 16:22:43 -0400852 }
Jeff Brown850c5b72012-10-01 15:17:22 -0700853 int resolvedBehavior = mLongPressOnPowerBehavior;
854 if (FactoryTest.isLongPressOnPowerOffEnabled()) {
855 resolvedBehavior = LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM;
856 }
857
858 switch (resolvedBehavior) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700859 case LONG_PRESS_POWER_NOTHING:
860 break;
861 case LONG_PRESS_POWER_GLOBAL_ACTIONS:
862 mPowerKeyHandled = true;
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -0700863 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
864 performAuditoryFeedbackForAccessibilityIfNeed();
865 }
Alan Viverettee34560b22014-07-10 14:50:06 -0700866 showGlobalActionsInternal();
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700867 break;
868 case LONG_PRESS_POWER_SHUT_OFF:
Jeff Brown9a538ee2012-08-20 14:56:57 -0700869 case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM:
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700870 mPowerKeyHandled = true;
871 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
872 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
Jeff Brown850c5b72012-10-01 15:17:22 -0700873 mWindowManagerFuncs.shutdown(resolvedBehavior == LONG_PRESS_POWER_SHUT_OFF);
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700874 break;
875 }
876 }
877 };
878
Jeff Sharkey2991fa32012-12-05 18:06:43 -0800879 private final Runnable mScreenshotRunnable = new Runnable() {
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800880 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700881 public void run() {
882 takeScreenshot();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800883 }
884 };
885
Alan Viverettee34560b22014-07-10 14:50:06 -0700886 @Override
887 public void showGlobalActions() {
888 mHandler.removeMessages(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
889 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
890 }
891
892 void showGlobalActionsInternal() {
893 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800894 if (mGlobalActions == null) {
Jeff Brown7304c342012-05-11 18:42:42 -0700895 mGlobalActions = new GlobalActions(mContext, mWindowManagerFuncs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800896 }
Mike Lockwood3a74bd32011-08-12 13:55:22 -0700897 final boolean keyguardShowing = keyguardIsShowingTq();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800898 mGlobalActions.showDialog(keyguardShowing, isDeviceProvisioned());
899 if (keyguardShowing) {
900 // since it took two seconds of long press to bring this up,
901 // poke the wake lock so they have some time to see the dialog.
Jim Miller25190572013-02-28 17:36:24 -0800902 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800903 }
904 }
905
906 boolean isDeviceProvisioned() {
Jeff Brownbf6f6f92012-09-25 15:03:20 -0700907 return Settings.Global.getInt(
908 mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800909 }
910
Maurice Lam99c6e072014-04-28 18:24:28 -0700911 boolean isUserSetupComplete() {
912 return Settings.Secure.getIntForUser(mContext.getContentResolver(),
913 Settings.Secure.USER_SETUP_COMPLETE, 0, UserHandle.USER_CURRENT) != 0;
914 }
915
Patrick Dubroyece94522011-02-23 18:35:01 -0800916 private void handleLongPressOnHome() {
Joe Onorato46b0d682010-11-22 17:37:27 -0800917 if (mLongPressOnHomeBehavior != LONG_PRESS_HOME_NOTHING) {
Jeff Browncaca8812013-05-09 13:34:33 -0700918 mHomeConsumed = true;
Joe Onorato46b0d682010-11-22 17:37:27 -0800919 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
Patrick Dubroyece94522011-02-23 18:35:01 -0800920
Jeff Browncaca8812013-05-09 13:34:33 -0700921 if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI) {
922 toggleRecentApps();
923 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_ASSIST) {
924 launchAssistAction();
Jim Millere6ad1a82010-08-20 19:25:39 -0700925 }
926 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800927 }
Patrick Dubroyece94522011-02-23 18:35:01 -0800928
Jeff Browncaca8812013-05-09 13:34:33 -0700929 private void handleDoubleTapOnHome() {
930 if (mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
931 mHomeConsumed = true;
932 toggleRecentApps();
933 }
934 }
935
936 private final Runnable mHomeDoubleTapTimeoutRunnable = new Runnable() {
937 @Override
938 public void run() {
939 if (mHomeDoubleTapPending) {
940 mHomeDoubleTapPending = false;
941 launchHomeFromHotKey();
942 }
943 }
944 };
945
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800946 /** {@inheritDoc} */
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800947 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800948 public void init(Context context, IWindowManager windowManager,
Jeff Brown96307042012-07-27 15:51:34 -0700949 WindowManagerFuncs windowManagerFuncs) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800950 mContext = context;
951 mWindowManager = windowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700952 mWindowManagerFuncs = windowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -0700953 mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class);
Jose Lima9546b202014-07-02 17:21:51 -0700954 mDreamManagerInternal = LocalServices.getService(DreamManagerInternal.class);
Craig Mautner8a0da012014-05-31 15:13:37 -0700955
Jeff Brown70825162012-03-28 17:27:48 -0700956 mHandler = new PolicyHandler();
Jeff Browna20dda42014-05-27 20:57:24 -0700957 mWakeGestureListener = new MyWakeGestureListener(mContext, mHandler);
Craig Mautnereee29c42013-01-17 14:44:34 -0800958 mOrientationListener = new MyOrientationListener(mContext, mHandler);
Jeff Brownc0347aa2011-09-23 17:26:09 -0700959 try {
960 mOrientationListener.setCurrentRotation(windowManager.getRotation());
961 } catch (RemoteException ex) { }
Christopher Tate5e08af02012-09-21 17:17:22 -0700962 mSettingsObserver = new SettingsObserver(mHandler);
963 mSettingsObserver.observe();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800964 mShortcutManager = new ShortcutManager(context, mHandler);
965 mShortcutManager.observe();
Daniel Sandler6396c722013-04-16 20:19:09 -0400966 mUiMode = context.getResources().getInteger(
967 com.android.internal.R.integer.config_defaultUiModeType);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800968 mHomeIntent = new Intent(Intent.ACTION_MAIN, null);
969 mHomeIntent.addCategory(Intent.CATEGORY_HOME);
970 mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
971 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700972 mCarDockIntent = new Intent(Intent.ACTION_MAIN, null);
973 mCarDockIntent.addCategory(Intent.CATEGORY_CAR_DOCK);
974 mCarDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
975 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
976 mDeskDockIntent = new Intent(Intent.ACTION_MAIN, null);
977 mDeskDockIntent.addCategory(Intent.CATEGORY_DESK_DOCK);
978 mDeskDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
979 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Jim Millere6ad1a82010-08-20 19:25:39 -0700980
Jeff Brown96307042012-07-27 15:51:34 -0700981 mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
982 mBroadcastWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800983 "PhoneWindowManager.mBroadcastWakeLock");
984 mEnableShiftMenuBugReports = "1".equals(SystemProperties.get("ro.debuggable"));
Jeff Brownbcdfc622014-03-06 19:13:04 -0800985 mSupportAutoRotation = mContext.getResources().getBoolean(
986 com.android.internal.R.bool.config_supportAutoRotation);
Dianne Hackborn2862fff2009-09-15 22:56:29 -0700987 mLidOpenRotation = readRotation(
Mike Lockwood2d1efbd2009-09-16 12:15:53 -0400988 com.android.internal.R.integer.config_lidOpenRotation);
989 mCarDockRotation = readRotation(
990 com.android.internal.R.integer.config_carDockRotation);
991 mDeskDockRotation = readRotation(
992 com.android.internal.R.integer.config_deskDockRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -0700993 mUndockedHdmiRotation = readRotation(
994 com.android.internal.R.integer.config_undockedHdmiRotation);
Mike Lockwoode9867d22009-09-20 01:59:02 -0400995 mCarDockEnablesAccelerometer = mContext.getResources().getBoolean(
996 com.android.internal.R.bool.config_carDockEnablesAccelerometer);
997 mDeskDockEnablesAccelerometer = mContext.getResources().getBoolean(
998 com.android.internal.R.bool.config_deskDockEnablesAccelerometer);
Dianne Hackborn2862fff2009-09-15 22:56:29 -0700999 mLidKeyboardAccessibility = mContext.getResources().getInteger(
1000 com.android.internal.R.integer.config_lidKeyboardAccessibility);
1001 mLidNavigationAccessibility = mContext.getResources().getInteger(
1002 com.android.internal.R.integer.config_lidNavigationAccessibility);
Jeff Brownc458ce92012-04-30 14:58:40 -07001003 mLidControlsSleep = mContext.getResources().getBoolean(
1004 com.android.internal.R.bool.config_lidControlsSleep);
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04001005 mTranslucentDecorEnabled = mContext.getResources().getBoolean(
1006 com.android.internal.R.bool.config_enableTranslucentDecor);
Jeff Brownf71343d2013-05-31 17:59:11 -07001007 readConfigurationDependentBehaviors();
Jeff Browncaca8812013-05-09 13:34:33 -07001008
Svetoslav8e3feb12014-02-24 13:46:47 -08001009 mAccessibilityManager = (AccessibilityManager) context.getSystemService(
1010 Context.ACCESSIBILITY_SERVICE);
1011
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001012 // register for dock events
Dianne Hackborn78968392010-03-04 20:47:56 -08001013 IntentFilter filter = new IntentFilter();
1014 filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE);
1015 filter.addAction(UiModeManager.ACTION_EXIT_CAR_MODE);
1016 filter.addAction(UiModeManager.ACTION_ENTER_DESK_MODE);
1017 filter.addAction(UiModeManager.ACTION_EXIT_DESK_MODE);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001018 filter.addAction(Intent.ACTION_DOCK_EVENT);
1019 Intent intent = context.registerReceiver(mDockReceiver, filter);
1020 if (intent != null) {
1021 // Retrieve current sticky dock event broadcast.
1022 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
1023 Intent.EXTRA_DOCK_STATE_UNDOCKED);
1024 }
Daniel Sandler7e37df52011-11-16 22:08:23 -08001025
Jeff Brown6aaf2952012-10-05 16:01:08 -07001026 // register for dream-related broadcasts
1027 filter = new IntentFilter();
1028 filter.addAction(Intent.ACTION_DREAMING_STARTED);
1029 filter.addAction(Intent.ACTION_DREAMING_STOPPED);
1030 context.registerReceiver(mDreamReceiver, filter);
1031
Christopher Tate5e08af02012-09-21 17:17:22 -07001032 // register for multiuser-relevant broadcasts
1033 filter = new IntentFilter(Intent.ACTION_USER_SWITCHED);
1034 context.registerReceiver(mMultiuserReceiver, filter);
1035
John Spurlock57306e62013-04-22 09:48:49 -04001036 // monitor for system gestures
Craig Mautner037aa8d2013-06-07 10:35:44 -07001037 mSystemGestures = new SystemGesturesPointerEventListener(context,
1038 new SystemGesturesPointerEventListener.Callbacks() {
John Spurlock57306e62013-04-22 09:48:49 -04001039 @Override
1040 public void onSwipeFromTop() {
John Spurlock04db1762013-05-13 12:46:41 -04001041 if (mStatusBar != null) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001042 requestTransientBars(mStatusBar);
John Spurlock04db1762013-05-13 12:46:41 -04001043 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04001044 }
1045 @Override
1046 public void onSwipeFromBottom() {
John Spurlock04db1762013-05-13 12:46:41 -04001047 if (mNavigationBar != null && mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001048 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001049 }
1050 }
1051 @Override
1052 public void onSwipeFromRight() {
John Spurlock04db1762013-05-13 12:46:41 -04001053 if (mNavigationBar != null && !mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001054 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001055 }
1056 }
1057 @Override
1058 public void onDebug() {
John Spurlockd67ec252013-09-05 11:31:54 -04001059 // no-op
John Spurlockad3e6cb2013-04-30 08:47:43 -04001060 }
1061 });
John Spurlockf1a36642013-10-12 17:50:42 -04001062 mImmersiveModeConfirmation = new ImmersiveModeConfirmation(mContext);
Craig Mautner037aa8d2013-06-07 10:35:44 -07001063 mWindowManagerFuncs.registerPointerEventListener(mSystemGestures);
John Spurlock32beb2c2013-03-11 10:16:47 -04001064
Jeff Brownc2346132012-04-13 01:55:38 -07001065 mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001066 mLongPressVibePattern = getLongIntArray(mContext.getResources(),
1067 com.android.internal.R.array.config_longPressVibePattern);
1068 mVirtualKeyVibePattern = getLongIntArray(mContext.getResources(),
1069 com.android.internal.R.array.config_virtualKeyVibePattern);
Amith Yamasanic33cb712010-02-10 15:21:49 -08001070 mKeyboardTapVibePattern = getLongIntArray(mContext.getResources(),
1071 com.android.internal.R.array.config_keyboardTapVibePattern);
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07001072 mClockTickVibePattern = getLongIntArray(mContext.getResources(),
1073 com.android.internal.R.array.config_clockTickVibePattern);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001074 mSafeModeDisabledVibePattern = getLongIntArray(mContext.getResources(),
1075 com.android.internal.R.array.config_safeModeDisabledVibePattern);
1076 mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(),
1077 com.android.internal.R.array.config_safeModeEnabledVibePattern);
Daniel Sandler40427442010-07-16 11:44:52 -04001078
Christopher Tatee90585f2012-03-05 18:56:25 -08001079 mScreenshotChordEnabled = mContext.getResources().getBoolean(
1080 com.android.internal.R.bool.config_enableScreenshotChord);
1081
Justin Kohd378ad72013-04-01 12:18:26 -07001082 mGlobalKeyManager = new GlobalKeyManager(mContext);
1083
Joe Onoratoea495d42011-04-06 11:41:11 -07001084 // Controls rotation and the like.
1085 initializeHdmiState();
Dianne Hackborn40011092011-09-22 13:37:48 -07001086
1087 // Match current screen state.
Jeff Brown26c6a502014-04-11 02:15:54 -07001088 if (mPowerManager.isInteractive()) {
Jeff Brown140ffc72014-05-01 15:18:00 -07001089 wakingUp(null);
Dianne Hackborn40011092011-09-22 13:37:48 -07001090 } else {
Jeff Brown140ffc72014-05-01 15:18:00 -07001091 goingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
Dianne Hackborn40011092011-09-22 13:37:48 -07001092 }
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001093 }
1094
Jeff Brownf71343d2013-05-31 17:59:11 -07001095 /**
1096 * Read values from config.xml that may be overridden depending on
1097 * the configuration of the device.
1098 * eg. Disable long press on home goes to recents on sw600dp.
1099 */
1100 private void readConfigurationDependentBehaviors() {
1101 mLongPressOnHomeBehavior = mContext.getResources().getInteger(
1102 com.android.internal.R.integer.config_longPressOnHomeBehavior);
1103 if (mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING ||
1104 mLongPressOnHomeBehavior > LONG_PRESS_HOME_ASSIST) {
1105 mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1106 }
1107
1108 mDoubleTapOnHomeBehavior = mContext.getResources().getInteger(
1109 com.android.internal.R.integer.config_doubleTapOnHomeBehavior);
1110 if (mDoubleTapOnHomeBehavior < DOUBLE_TAP_HOME_NOTHING ||
1111 mDoubleTapOnHomeBehavior > DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1112 mDoubleTapOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1113 }
1114 }
1115
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001116 @Override
Dianne Hackborndde331c2012-08-03 14:01:57 -07001117 public void setInitialDisplaySize(Display display, int width, int height, int density) {
Jeff Brownef981a42013-08-07 14:13:37 -07001118 // This method might be called before the policy has been fully initialized
1119 // or for other displays we don't care about.
1120 if (mContext == null || display.getDisplayId() != Display.DEFAULT_DISPLAY) {
1121 return;
Dianne Hackbornc652de82013-02-15 16:32:56 -08001122 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001123 mDisplay = display;
1124
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001125 final Resources res = mContext.getResources();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001126 int shortSize, longSize;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001127 if (width > height) {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001128 shortSize = height;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001129 longSize = width;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001130 mLandscapeRotation = Surface.ROTATION_0;
1131 mSeascapeRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001132 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001133 mPortraitRotation = Surface.ROTATION_90;
1134 mUpsideDownRotation = Surface.ROTATION_270;
1135 } else {
1136 mPortraitRotation = Surface.ROTATION_270;
1137 mUpsideDownRotation = Surface.ROTATION_90;
1138 }
1139 } else {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001140 shortSize = width;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001141 longSize = height;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001142 mPortraitRotation = Surface.ROTATION_0;
1143 mUpsideDownRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001144 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001145 mLandscapeRotation = Surface.ROTATION_270;
1146 mSeascapeRotation = Surface.ROTATION_90;
1147 } else {
1148 mLandscapeRotation = Surface.ROTATION_90;
1149 mSeascapeRotation = Surface.ROTATION_270;
1150 }
1151 }
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001152
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001153 mStatusBarHeight =
1154 res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001155
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001156 // Height of the navigation bar when presented horizontally at bottom
1157 mNavigationBarHeightForRotation[mPortraitRotation] =
1158 mNavigationBarHeightForRotation[mUpsideDownRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001159 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_height);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001160 mNavigationBarHeightForRotation[mLandscapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001161 mNavigationBarHeightForRotation[mSeascapeRotation] = res.getDimensionPixelSize(
1162 com.android.internal.R.dimen.navigation_bar_height_landscape);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001163
1164 // Width of the navigation bar when presented vertically along one side
1165 mNavigationBarWidthForRotation[mPortraitRotation] =
1166 mNavigationBarWidthForRotation[mUpsideDownRotation] =
1167 mNavigationBarWidthForRotation[mLandscapeRotation] =
1168 mNavigationBarWidthForRotation[mSeascapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001169 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_width);
Daniel Sandler4a066c52012-04-20 14:49:13 -04001170
1171 // SystemUI (status bar) layout policy
Dianne Hackborndde331c2012-08-03 14:01:57 -07001172 int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / density;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001173 int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / density;
Daniel Sandler4a066c52012-04-20 14:49:13 -04001174
Craig Mautnerd4ec33242013-07-22 10:37:43 -07001175 // Allow the navigation bar to move on small devices (phones).
1176 mNavigationBarCanMove = shortSizeDp < 600;
Daniel Sandler36412a72011-08-04 09:35:13 -04001177
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001178 mHasNavigationBar = res.getBoolean(com.android.internal.R.bool.config_showNavigationBar);
John Spurlock80f00c12013-06-13 11:10:51 -04001179 // Allow a system property to override this. Used by the emulator.
1180 // See also hasNavigationBar().
1181 String navBarOverride = SystemProperties.get("qemu.hw.mainkeys");
1182 if ("1".equals(navBarOverride)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001183 mHasNavigationBar = false;
John Spurlock80f00c12013-06-13 11:10:51 -04001184 } else if ("0".equals(navBarOverride)) {
1185 mHasNavigationBar = true;
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04001186 }
1187
Jeff Brown27f1d672012-10-17 18:32:34 -07001188 // For demo purposes, allow the rotation of the HDMI display to be controlled.
1189 // By default, HDMI locks rotation to landscape.
Erik Gilling9a41ef82011-09-26 19:21:03 -07001190 if ("portrait".equals(SystemProperties.get("persist.demo.hdmirotation"))) {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001191 mDemoHdmiRotation = mPortraitRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001192 } else {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001193 mDemoHdmiRotation = mLandscapeRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001194 }
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001195 mDemoHdmiRotationLock = SystemProperties.getBoolean("persist.demo.hdmirotationlock", false);
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001196
1197 // Only force the default orientation if the screen is xlarge, at least 960dp x 720dp, per
1198 // http://developer.android.com/guide/practices/screens_support.html#range
1199 mForceDefaultOrientation = longSizeDp >= 960 && shortSizeDp >= 720 &&
1200 res.getBoolean(com.android.internal.R.bool.config_forceDefaultOrientation) &&
1201 // For debug purposes the next line turns this feature off with:
1202 // $ adb shell setprop config.override_forced_orient true
1203 // $ adb shell wm size reset
1204 !"true".equals(SystemProperties.get("config.override_forced_orient"));
1205 }
1206
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001207 /**
1208 * @return whether the navigation bar can be hidden, e.g. the device has a
1209 * navigation bar and touch exploration is not enabled
1210 */
1211 private boolean canHideNavigationBar() {
Svetoslav8e3feb12014-02-24 13:46:47 -08001212 return mHasNavigationBar
1213 && !mAccessibilityManager.isTouchExplorationEnabled();
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001214 }
1215
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001216 @Override
1217 public boolean isDefaultOrientationForced() {
1218 return mForceDefaultOrientation;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001219 }
1220
Dianne Hackbornc652de82013-02-15 16:32:56 -08001221 @Override
1222 public void setDisplayOverscan(Display display, int left, int top, int right, int bottom) {
1223 if (display.getDisplayId() == Display.DEFAULT_DISPLAY) {
1224 mOverscanLeft = left;
1225 mOverscanTop = top;
1226 mOverscanRight = right;
1227 mOverscanBottom = bottom;
1228 }
1229 }
1230
Dianne Hackbornc777e072010-02-12 13:07:59 -08001231 public void updateSettings() {
1232 ContentResolver resolver = mContext.getContentResolver();
1233 boolean updateRotation = false;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001234 synchronized (mLock) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001235 mEndcallBehavior = Settings.System.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001236 Settings.System.END_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001237 Settings.System.END_BUTTON_BEHAVIOR_DEFAULT,
1238 UserHandle.USER_CURRENT);
1239 mIncallPowerBehavior = Settings.Secure.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001240 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001241 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT,
1242 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001243
Jeff Browna20dda42014-05-27 20:57:24 -07001244 // Configure wake gesture.
1245 boolean wakeGestureEnabledSetting = Settings.Secure.getIntForUser(resolver,
1246 Settings.Secure.WAKE_GESTURE_ENABLED, 0,
1247 UserHandle.USER_CURRENT) != 0;
1248 if (mWakeGestureEnabledSetting != wakeGestureEnabledSetting) {
1249 mWakeGestureEnabledSetting = wakeGestureEnabledSetting;
1250 updateWakeGestureListenerLp();
1251 }
1252
Jeff Brown207673cd2012-06-05 17:47:11 -07001253 // Configure rotation lock.
Christopher Tate5e08af02012-09-21 17:17:22 -07001254 int userRotation = Settings.System.getIntForUser(resolver,
1255 Settings.System.USER_ROTATION, Surface.ROTATION_0,
1256 UserHandle.USER_CURRENT);
Jeff Brown207673cd2012-06-05 17:47:11 -07001257 if (mUserRotation != userRotation) {
1258 mUserRotation = userRotation;
1259 updateRotation = true;
1260 }
Christopher Tate5e08af02012-09-21 17:17:22 -07001261 int userRotationMode = Settings.System.getIntForUser(resolver,
1262 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
Jeff Brown207673cd2012-06-05 17:47:11 -07001263 WindowManagerPolicy.USER_ROTATION_FREE :
1264 WindowManagerPolicy.USER_ROTATION_LOCKED;
1265 if (mUserRotationMode != userRotationMode) {
1266 mUserRotationMode = userRotationMode;
1267 updateRotation = true;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001268 updateOrientationListenerLp();
1269 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001270
Dianne Hackbornc777e072010-02-12 13:07:59 -08001271 if (mSystemReady) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001272 int pointerLocation = Settings.System.getIntForUser(resolver,
1273 Settings.System.POINTER_LOCATION, 0, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001274 if (mPointerLocationMode != pointerLocation) {
1275 mPointerLocationMode = pointerLocation;
Jeff Brown70825162012-03-28 17:27:48 -07001276 mHandler.sendEmptyMessage(pointerLocation != 0 ?
1277 MSG_ENABLE_POINTER_LOCATION : MSG_DISABLE_POINTER_LOCATION);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001278 }
1279 }
1280 // use screen off timeout setting as the timeout for the lockscreen
Christopher Tate5e08af02012-09-21 17:17:22 -07001281 mLockScreenTimeout = Settings.System.getIntForUser(resolver,
1282 Settings.System.SCREEN_OFF_TIMEOUT, 0, UserHandle.USER_CURRENT);
1283 String imId = Settings.Secure.getStringForUser(resolver,
1284 Settings.Secure.DEFAULT_INPUT_METHOD, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001285 boolean hasSoftInput = imId != null && imId.length() > 0;
1286 if (mHasSoftInput != hasSoftInput) {
1287 mHasSoftInput = hasSoftInput;
1288 updateRotation = true;
1289 }
John Spurlockf1a36642013-10-12 17:50:42 -04001290 if (mImmersiveModeConfirmation != null) {
John Spurlock4355a532014-02-19 09:49:25 -05001291 mImmersiveModeConfirmation.loadSetting(mCurrentUserId);
John Spurlockd67ec252013-09-05 11:31:54 -04001292 }
John Spurlockc6d1c602014-01-17 15:22:06 -05001293 PolicyControl.reloadFromSetting(mContext);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001294 }
1295 if (updateRotation) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07001296 updateRotation(true);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001297 }
Jeff Brown70825162012-03-28 17:27:48 -07001298 }
1299
Jeff Browna20dda42014-05-27 20:57:24 -07001300 private void updateWakeGestureListenerLp() {
1301 if (shouldEnableWakeGestureLp()) {
1302 mWakeGestureListener.requestWakeUpTrigger();
1303 } else {
1304 mWakeGestureListener.cancelWakeUpTrigger();
1305 }
1306 }
1307
1308 private boolean shouldEnableWakeGestureLp() {
1309 return mWakeGestureEnabledSetting && !mScreenOnEarly
1310 && (!mLidControlsSleep || mLidState != LID_CLOSED)
1311 && mWakeGestureListener.isSupported();
1312 }
1313
Jeff Brown70825162012-03-28 17:27:48 -07001314 private void enablePointerLocation() {
1315 if (mPointerLocationView == null) {
1316 mPointerLocationView = new PointerLocationView(mContext);
1317 mPointerLocationView.setPrintCoords(false);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001318 WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
1319 WindowManager.LayoutParams.MATCH_PARENT,
1320 WindowManager.LayoutParams.MATCH_PARENT);
Jeff Brown3b2b3542010-10-15 00:54:27 -07001321 lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001322 lp.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN
1323 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
1324 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1325 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
Jeff Brown90fc9052012-10-01 14:44:24 -07001326 if (ActivityManager.isHighEndGfx()) {
1327 lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
1328 lp.privateFlags |=
1329 WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED;
1330 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001331 lp.format = PixelFormat.TRANSLUCENT;
1332 lp.setTitle("PointerLocation");
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001333 WindowManager wm = (WindowManager)
Dianne Hackbornc777e072010-02-12 13:07:59 -08001334 mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Browncc4f7db2011-08-30 20:34:48 -07001335 lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL;
Jeff Brown70825162012-03-28 17:27:48 -07001336 wm.addView(mPointerLocationView, lp);
Michael Wrightc9c487e2013-11-07 18:55:09 -08001337 mWindowManagerFuncs.registerPointerEventListener(mPointerLocationView);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001338 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001339 }
Jeff Brown70825162012-03-28 17:27:48 -07001340
1341 private void disablePointerLocation() {
Jeff Brown70825162012-03-28 17:27:48 -07001342 if (mPointerLocationView != null) {
Michael Wrightc9c487e2013-11-07 18:55:09 -08001343 mWindowManagerFuncs.unregisterPointerEventListener(mPointerLocationView);
1344 WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Brown70825162012-03-28 17:27:48 -07001345 wm.removeView(mPointerLocationView);
1346 mPointerLocationView = null;
1347 }
1348 }
1349
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001350 private int readRotation(int resID) {
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001351 try {
1352 int rotation = mContext.getResources().getInteger(resID);
1353 switch (rotation) {
1354 case 0:
1355 return Surface.ROTATION_0;
1356 case 90:
1357 return Surface.ROTATION_90;
1358 case 180:
1359 return Surface.ROTATION_180;
1360 case 270:
1361 return Surface.ROTATION_270;
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001362 }
1363 } catch (Resources.NotFoundException e) {
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001364 // fall through
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001365 }
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001366 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001367 }
1368
1369 /** {@inheritDoc} */
Craig Mautner88400d32012-09-30 12:35:45 -07001370 @Override
Dianne Hackbornc2293022013-02-06 23:14:49 -08001371 public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001372 int type = attrs.type;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001373
1374 outAppOp[0] = AppOpsManager.OP_NONE;
1375
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001376 if (type < WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW
1377 || type > WindowManager.LayoutParams.LAST_SYSTEM_WINDOW) {
Jeff Brown98365d72012-08-19 20:30:52 -07001378 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001379 }
1380 String permission = null;
1381 switch (type) {
1382 case TYPE_TOAST:
1383 // XXX right now the app process has complete control over
1384 // this... should introduce a token to let the system
1385 // monitor/control what they are doing.
Jason Monk1c7c3192014-06-26 12:52:18 -04001386 outAppOp[0] = AppOpsManager.OP_TOAST_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001387 break;
Daniel Sandler7d276c32012-01-30 14:33:52 -05001388 case TYPE_DREAM:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001389 case TYPE_INPUT_METHOD:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001390 case TYPE_WALLPAPER:
keunyounga446bf02013-06-21 19:07:57 -07001391 case TYPE_PRIVATE_PRESENTATION:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001392 case TYPE_VOICE_INTERACTION:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001393 // The window manager will check these.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001394 break;
1395 case TYPE_PHONE:
1396 case TYPE_PRIORITY_PHONE:
1397 case TYPE_SYSTEM_ALERT:
1398 case TYPE_SYSTEM_ERROR:
1399 case TYPE_SYSTEM_OVERLAY:
1400 permission = android.Manifest.permission.SYSTEM_ALERT_WINDOW;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001401 outAppOp[0] = AppOpsManager.OP_SYSTEM_ALERT_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001402 break;
1403 default:
1404 permission = android.Manifest.permission.INTERNAL_SYSTEM_WINDOW;
1405 }
1406 if (permission != null) {
1407 if (mContext.checkCallingOrSelfPermission(permission)
1408 != PackageManager.PERMISSION_GRANTED) {
Jeff Brown98365d72012-08-19 20:30:52 -07001409 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001410 }
1411 }
Jeff Brown98365d72012-08-19 20:30:52 -07001412 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001413 }
Craig Mautner88400d32012-09-30 12:35:45 -07001414
1415 @Override
1416 public boolean checkShowToOwnerOnly(WindowManager.LayoutParams attrs) {
1417
1418 // If this switch statement is modified, modify the comment in the declarations of
1419 // the type in {@link WindowManager.LayoutParams} as well.
1420 switch (attrs.type) {
1421 default:
1422 // These are the windows that by default are shown only to the user that created
1423 // them. If this needs to be overridden, set
1424 // {@link WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS} in
1425 // {@link WindowManager.LayoutParams}. Note that permission
1426 // {@link android.Manifest.permission.INTERNAL_SYSTEM_WINDOW} is required as well.
1427 if ((attrs.privateFlags & PRIVATE_FLAG_SHOW_FOR_ALL_USERS) == 0) {
1428 return true;
1429 }
1430 break;
1431
1432 // These are the windows that by default are shown to all users. However, to
1433 // protect against spoofing, check permissions below.
1434 case TYPE_APPLICATION_STARTING:
1435 case TYPE_BOOT_PROGRESS:
1436 case TYPE_DISPLAY_OVERLAY:
1437 case TYPE_HIDDEN_NAV_CONSUMER:
Jim Miller5ecd8112013-01-09 18:50:26 -08001438 case TYPE_KEYGUARD_SCRIM:
Craig Mautner88400d32012-09-30 12:35:45 -07001439 case TYPE_KEYGUARD_DIALOG:
1440 case TYPE_MAGNIFICATION_OVERLAY:
1441 case TYPE_NAVIGATION_BAR:
1442 case TYPE_NAVIGATION_BAR_PANEL:
1443 case TYPE_PHONE:
1444 case TYPE_POINTER:
1445 case TYPE_PRIORITY_PHONE:
1446 case TYPE_RECENTS_OVERLAY:
1447 case TYPE_SEARCH_BAR:
1448 case TYPE_STATUS_BAR:
1449 case TYPE_STATUS_BAR_PANEL:
1450 case TYPE_STATUS_BAR_SUB_PANEL:
1451 case TYPE_SYSTEM_DIALOG:
1452 case TYPE_UNIVERSE_BACKGROUND:
1453 case TYPE_VOLUME_OVERLAY:
keunyounga446bf02013-06-21 19:07:57 -07001454 case TYPE_PRIVATE_PRESENTATION:
Craig Mautner88400d32012-09-30 12:35:45 -07001455 break;
1456 }
1457
1458 // Check if third party app has set window to system window type.
1459 return mContext.checkCallingOrSelfPermission(
1460 android.Manifest.permission.INTERNAL_SYSTEM_WINDOW)
1461 != PackageManager.PERMISSION_GRANTED;
1462 }
1463
Craig Mautner967212c2013-04-13 21:10:58 -07001464 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001465 public void adjustWindowParamsLw(WindowManager.LayoutParams attrs) {
1466 switch (attrs.type) {
1467 case TYPE_SYSTEM_OVERLAY:
Jeff Brown3b2b3542010-10-15 00:54:27 -07001468 case TYPE_SECURE_SYSTEM_OVERLAY:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001469 // These types of windows can't receive input events.
1470 attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1471 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001472 attrs.flags &= ~WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001473 break;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001474 case TYPE_STATUS_BAR:
1475
1476 // If the Keyguard is in a hidden state (occluded by another window), we force to
1477 // remove the wallpaper and keyguard flag so that any change in-flight after setting
1478 // the keyguard as occluded wouldn't set these flags again.
1479 // See {@link #processKeyguardSetHiddenResultLw}.
1480 if (mKeyguardHidden) {
1481 attrs.flags &= ~WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
1482 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
1483 }
1484 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001485 }
Adrian Roos38502112014-04-09 21:04:11 +02001486
1487 if (attrs.type != TYPE_STATUS_BAR) {
1488 // The status bar is the only window allowed to exhibit keyguard behavior.
1489 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
1490 }
Adrian Roosea562512014-05-05 13:33:03 +02001491
1492 if (ActivityManager.isHighEndGfx()
1493 && (attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0) {
1494 attrs.subtreeSystemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_STABLE
1495 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
1496 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
1497 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001498 }
RoboErik8a2cfc32014-05-16 11:19:38 -07001499
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001500 void readLidState() {
Jeff Brown2e7760e2012-04-11 15:14:55 -07001501 mLidState = mWindowManagerFuncs.getLidState();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001502 }
RoboErik8a2cfc32014-05-16 11:19:38 -07001503
Jeff Browndaa37532012-05-01 15:54:03 -07001504 private boolean isHidden(int accessibilityMode) {
1505 switch (accessibilityMode) {
1506 case 1:
1507 return mLidState == LID_CLOSED;
1508 case 2:
1509 return mLidState == LID_OPEN;
1510 default:
1511 return false;
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001512 }
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001513 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001514
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001515 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07001516 @Override
Jeff Browndaa37532012-05-01 15:54:03 -07001517 public void adjustConfigurationLw(Configuration config, int keyboardPresence,
1518 int navigationPresence) {
1519 mHaveBuiltInKeyboard = (keyboardPresence & PRESENCE_INTERNAL) != 0;
1520
Jeff Brownf71343d2013-05-31 17:59:11 -07001521 readConfigurationDependentBehaviors();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001522 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07001523 applyLidSwitchState();
Jeff Brownd04a88c2011-01-16 14:05:47 -08001524
Jeff Browndaa37532012-05-01 15:54:03 -07001525 if (config.keyboard == Configuration.KEYBOARD_NOKEYS
1526 || (keyboardPresence == PRESENCE_INTERNAL
1527 && isHidden(mLidKeyboardAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001528 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_YES;
Jeff Browndaa37532012-05-01 15:54:03 -07001529 if (!mHasSoftInput) {
1530 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_YES;
1531 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001532 }
1533
Jeff Browndaa37532012-05-01 15:54:03 -07001534 if (config.navigation == Configuration.NAVIGATION_NONAV
1535 || (navigationPresence == PRESENCE_INTERNAL
1536 && isHidden(mLidNavigationAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001537 config.navigationHidden = Configuration.NAVIGATIONHIDDEN_YES;
Jeff Brownd04a88c2011-01-16 14:05:47 -08001538 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001539 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001540
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001541 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07001542 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001543 public int windowTypeToLayerLw(int type) {
1544 if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001545 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001546 }
1547 switch (type) {
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001548 case TYPE_UNIVERSE_BACKGROUND:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001549 return 1;
keunyounga446bf02013-06-21 19:07:57 -07001550 case TYPE_PRIVATE_PRESENTATION:
1551 return 2;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001552 case TYPE_WALLPAPER:
1553 // wallpaper is at the bottom, though the window manager may move it.
1554 return 2;
1555 case TYPE_PHONE:
1556 return 3;
1557 case TYPE_SEARCH_BAR:
1558 return 4;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001559 case TYPE_VOICE_INTERACTION:
1560 // voice interaction layer is almost immediately above apps.
1561 return 5;
Craig Mautner88400d32012-09-30 12:35:45 -07001562 case TYPE_RECENTS_OVERLAY:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001563 case TYPE_SYSTEM_DIALOG:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001564 return 6;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001565 case TYPE_TOAST:
1566 // toasts and the plugged-in battery thing
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001567 return 7;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001568 case TYPE_PRIORITY_PHONE:
1569 // SIM errors and unlock. Not sure if this really should be in a high layer.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001570 return 8;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001571 case TYPE_DREAM:
1572 // used for Dreams (screensavers with TYPE_DREAM windows)
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001573 return 9;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001574 case TYPE_SYSTEM_ALERT:
1575 // like the ANR / app crashed dialogs
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001576 return 10;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001577 case TYPE_INPUT_METHOD:
1578 // on-screen keyboards and other such input method user interfaces go here.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001579 return 11;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001580 case TYPE_INPUT_METHOD_DIALOG:
1581 // on-screen keyboards and other such input method user interfaces go here.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001582 return 12;
Jim Miller5ecd8112013-01-09 18:50:26 -08001583 case TYPE_KEYGUARD_SCRIM:
1584 // the safety window that shows behind keyguard while keyguard is starting
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001585 return 13;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001586 case TYPE_STATUS_BAR_SUB_PANEL:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001587 return 14;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001588 case TYPE_STATUS_BAR:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001589 return 15;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001590 case TYPE_STATUS_BAR_PANEL:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001591 return 16;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001592 case TYPE_KEYGUARD_DIALOG:
1593 return 17;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001594 case TYPE_VOLUME_OVERLAY:
1595 // the on-screen volume indicator and controller shown when the user
1596 // changes the device volume
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001597 return 18;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001598 case TYPE_SYSTEM_OVERLAY:
1599 // the on-screen volume indicator and controller shown when the user
1600 // changes the device volume
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001601 return 19;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001602 case TYPE_NAVIGATION_BAR:
1603 // the navigation bar, if available, shows atop most things
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001604 return 20;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001605 case TYPE_NAVIGATION_BAR_PANEL:
1606 // some panels (e.g. search) need to show on top of the navigation bar
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001607 return 21;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001608 case TYPE_SYSTEM_ERROR:
1609 // system-level error dialogs
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001610 return 22;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001611 case TYPE_MAGNIFICATION_OVERLAY:
1612 // used to highlight the magnified portion of a display
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001613 return 23;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001614 case TYPE_DISPLAY_OVERLAY:
1615 // used to simulate secondary display devices
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001616 return 24;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001617 case TYPE_DRAG:
1618 // the drag layer: input for drag-and-drop is associated with this window,
1619 // which sits above all other focusable windows
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001620 return 25;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001621 case TYPE_SECURE_SYSTEM_OVERLAY:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001622 return 26;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001623 case TYPE_BOOT_PROGRESS:
1624 return 27;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001625 case TYPE_POINTER:
1626 // the (mouse) pointer layer
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001627 return 28;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001628 case TYPE_HIDDEN_NAV_CONSUMER:
1629 return 29;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001630 }
1631 Log.e(TAG, "Unknown window type: " + type);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001632 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001633 }
1634
1635 /** {@inheritDoc} */
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001636 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001637 public int subWindowTypeToLayerLw(int type) {
1638 switch (type) {
1639 case TYPE_APPLICATION_PANEL:
1640 case TYPE_APPLICATION_ATTACHED_DIALOG:
1641 return APPLICATION_PANEL_SUBLAYER;
1642 case TYPE_APPLICATION_MEDIA:
1643 return APPLICATION_MEDIA_SUBLAYER;
Dianne Hackborn5cb8d792009-05-21 17:34:15 -07001644 case TYPE_APPLICATION_MEDIA_OVERLAY:
1645 return APPLICATION_MEDIA_OVERLAY_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001646 case TYPE_APPLICATION_SUB_PANEL:
1647 return APPLICATION_SUB_PANEL_SUBLAYER;
1648 }
1649 Log.e(TAG, "Unknown sub-window type: " + type);
1650 return 0;
1651 }
1652
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001653 @Override
Dianne Hackbornabe0da02009-09-18 01:55:39 -07001654 public int getMaxWallpaperLayer() {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001655 return windowTypeToLayerLw(TYPE_STATUS_BAR);
Dianne Hackbornabe0da02009-09-18 01:55:39 -07001656 }
1657
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001658 @Override
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001659 public int getAboveUniverseLayer() {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001660 return windowTypeToLayerLw(TYPE_SYSTEM_ERROR);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001661 }
1662
Jose Lima9546b202014-07-02 17:21:51 -07001663 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001664 public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07001665 if (mHasNavigationBar) {
1666 // For a basic navigation bar, when we are in landscape mode we place
1667 // the navigation bar to the side.
Daniel Sandler4a066c52012-04-20 14:49:13 -04001668 if (mNavigationBarCanMove && fullWidth > fullHeight) {
1669 return fullWidth - mNavigationBarWidthForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07001670 }
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001671 }
1672 return fullWidth;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001673 }
1674
Jose Lima9546b202014-07-02 17:21:51 -07001675 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001676 public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07001677 if (mHasNavigationBar) {
1678 // For a basic navigation bar, when we are in portrait mode we place
1679 // the navigation bar to the bottom.
Daniel Sandler4a066c52012-04-20 14:49:13 -04001680 if (!mNavigationBarCanMove || fullWidth < fullHeight) {
1681 return fullHeight - mNavigationBarHeightForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07001682 }
1683 }
1684 return fullHeight;
Dianne Hackborn69cb8752011-05-19 18:13:32 -07001685 }
1686
Jose Lima9546b202014-07-02 17:21:51 -07001687 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001688 public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation) {
1689 return getNonDecorDisplayWidth(fullWidth, fullHeight, rotation);
Dianne Hackborn69cb8752011-05-19 18:13:32 -07001690 }
1691
Jose Lima9546b202014-07-02 17:21:51 -07001692 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001693 public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation) {
John Spurlock80f00c12013-06-13 11:10:51 -04001694 // There is a separate status bar at the top of the display. We don't count that as part
1695 // of the fixed decor, since it can hide; however, for purposes of configurations,
Dianne Hackborn077ee852012-04-09 16:27:07 -07001696 // we do want to exclude it since applications can't generally use that part
1697 // of the screen.
John Spurlock80f00c12013-06-13 11:10:51 -04001698 return getNonDecorDisplayHeight(fullWidth, fullHeight, rotation) - mStatusBarHeight;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001699 }
1700
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001701 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07001702 public boolean isForceHiding(WindowManager.LayoutParams attrs) {
1703 return (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 ||
Adrian Roos69e510d2014-07-13 14:57:59 +02001704 (isKeyguardHostWindow(attrs) && isKeyguardSecureIncludingHidden()) ||
1705 (attrs.type == TYPE_KEYGUARD_SCRIM);
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07001706 }
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001707
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001708 @Override
Jorim Jaggi0d674622014-05-21 01:34:15 +02001709 public boolean isKeyguardHostWindow(WindowManager.LayoutParams attrs) {
1710 return attrs.type == TYPE_STATUS_BAR;
1711 }
1712
1713 @Override
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07001714 public boolean canBeForceHidden(WindowState win, WindowManager.LayoutParams attrs) {
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001715 switch (attrs.type) {
1716 case TYPE_STATUS_BAR:
1717 case TYPE_NAVIGATION_BAR:
1718 case TYPE_WALLPAPER:
1719 case TYPE_DREAM:
1720 case TYPE_UNIVERSE_BACKGROUND:
Jim Miller5ecd8112013-01-09 18:50:26 -08001721 case TYPE_KEYGUARD_SCRIM:
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001722 return false;
1723 default:
1724 return true;
1725 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07001726 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001727
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001728 /** {@inheritDoc} */
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001729 @Override
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07001730 public View addStartingWindow(IBinder appToken, String packageName, int theme,
1731 CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes,
Adam Powell04fe6eb2013-05-31 14:39:48 -07001732 int icon, int logo, int windowFlags) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001733 if (!SHOW_STARTING_ANIMATIONS) {
1734 return null;
1735 }
1736 if (packageName == null) {
1737 return null;
1738 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001739
Mathias Jeppssond1443e92012-08-24 15:25:32 +02001740 WindowManager wm = null;
1741 View view = null;
1742
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001743 try {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001744 Context context = mContext;
Craig Mautner6fbda632012-07-03 09:26:39 -07001745 if (DEBUG_STARTING_WINDOW) Slog.d(TAG, "addStartingWindow " + packageName
1746 + ": nonLocalizedLabel=" + nonLocalizedLabel + " theme="
1747 + Integer.toHexString(theme));
Dianne Hackborn247fe742011-01-08 17:25:57 -08001748 if (theme != context.getThemeResId() || labelRes != 0) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001749 try {
1750 context = context.createPackageContext(packageName, 0);
Dianne Hackborn247fe742011-01-08 17:25:57 -08001751 context.setTheme(theme);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001752 } catch (PackageManager.NameNotFoundException e) {
1753 // Ignore
1754 }
1755 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001756
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001757 Window win = PolicyManager.makeNewWindow(context);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001758 final TypedArray ta = win.getWindowStyle();
1759 if (ta.getBoolean(
1760 com.android.internal.R.styleable.Window_windowDisablePreview, false)
1761 || ta.getBoolean(
1762 com.android.internal.R.styleable.Window_windowShowWallpaper,false)) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001763 return null;
1764 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001765
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001766 Resources r = context.getResources();
1767 win.setTitle(r.getText(labelRes, nonLocalizedLabel));
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001768
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001769 win.setType(
1770 WindowManager.LayoutParams.TYPE_APPLICATION_STARTING);
1771 // Force the window flags: this is a fake window, so it is not really
1772 // touchable or focusable by the user. We also add in the ALT_FOCUSABLE_IM
1773 // flag because we do know that the next window will take input
1774 // focus, so we want to get the IME window up on top of us right away.
1775 win.setFlags(
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08001776 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001777 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
1778 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
1779 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08001780 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001781 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
1782 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
1783 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001784
Adam Powell04fe6eb2013-05-31 14:39:48 -07001785 win.setDefaultIcon(icon);
1786 win.setDefaultLogo(logo);
1787
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001788 win.setLayout(WindowManager.LayoutParams.MATCH_PARENT,
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07001789 WindowManager.LayoutParams.MATCH_PARENT);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001790
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001791 final WindowManager.LayoutParams params = win.getAttributes();
1792 params.token = appToken;
1793 params.packageName = packageName;
1794 params.windowAnimations = win.getWindowStyle().getResourceId(
1795 com.android.internal.R.styleable.Window_windowAnimationStyle, 0);
Dianne Hackborn5d927c22011-09-02 12:22:18 -07001796 params.privateFlags |=
1797 WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED;
Craig Mautner88400d32012-09-30 12:35:45 -07001798 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
Adam Lesinski95c42972013-10-02 10:13:27 -07001799
1800 if (!compatInfo.supportsScreen()) {
1801 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
1802 }
1803
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001804 params.setTitle("Starting " + packageName);
1805
Mathias Jeppssond1443e92012-08-24 15:25:32 +02001806 wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
1807 view = win.getDecorView();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001808
1809 if (win.isFloating()) {
1810 // Whoops, there is no way to display an animation/preview
1811 // of such a thing! After all that work... let's skip it.
1812 // (Note that we must do this here because it is in
1813 // getDecorView() where the theme is evaluated... maybe
1814 // we should peek the floating attribute from the theme
1815 // earlier.)
1816 return null;
1817 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001818
Craig Mautner6fbda632012-07-03 09:26:39 -07001819 if (DEBUG_STARTING_WINDOW) Slog.d(
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001820 TAG, "Adding starting window for " + packageName
1821 + " / " + appToken + ": "
1822 + (view.getParent() != null ? view : null));
1823
1824 wm.addView(view, params);
1825
1826 // Only return the view if it was successfully added to the
1827 // window manager... which we can tell by it having a parent.
1828 return view.getParent() != null ? view : null;
Jeff Brown98365d72012-08-19 20:30:52 -07001829 } catch (WindowManager.BadTokenException e) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001830 // ignore
Craig Mautner42bf39e2014-02-21 16:46:22 -08001831 Log.w(TAG, appToken + " already running, starting window not displayed. " +
1832 e.getMessage());
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001833 } catch (RuntimeException e) {
1834 // don't crash if something else bad happens, for example a
1835 // failure loading resources because we are loading from an app
1836 // on external storage that has been unmounted.
1837 Log.w(TAG, appToken + " failed creating starting window", e);
Mathias Jeppssond1443e92012-08-24 15:25:32 +02001838 } finally {
1839 if (view != null && view.getParent() == null) {
1840 Log.w(TAG, "view not successfully added to wm, removing view");
1841 wm.removeViewImmediate(view);
1842 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001843 }
1844
1845 return null;
1846 }
1847
1848 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07001849 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001850 public void removeStartingWindow(IBinder appToken, View window) {
Craig Mautner6fbda632012-07-03 09:26:39 -07001851 if (DEBUG_STARTING_WINDOW) {
1852 RuntimeException e = new RuntimeException("here");
1853 e.fillInStackTrace();
1854 Log.v(TAG, "Removing starting window for " + appToken + ": " + window, e);
1855 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001856
1857 if (window != null) {
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001858 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001859 wm.removeView(window);
1860 }
1861 }
1862
1863 /**
1864 * Preflight adding a window to the system.
RoboErik8a2cfc32014-05-16 11:19:38 -07001865 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001866 * Currently enforces that three window types are singletons:
1867 * <ul>
1868 * <li>STATUS_BAR_TYPE</li>
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001869 * <li>KEYGUARD_TYPE</li>
1870 * </ul>
RoboErik8a2cfc32014-05-16 11:19:38 -07001871 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001872 * @param win The window to be added
1873 * @param attrs Information about the window to be added
RoboErik8a2cfc32014-05-16 11:19:38 -07001874 *
Jeff Brown98365d72012-08-19 20:30:52 -07001875 * @return If ok, WindowManagerImpl.ADD_OKAY. If too many singletons,
1876 * WindowManagerImpl.ADD_MULTIPLE_SINGLETON
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001877 */
Jose Lima9546b202014-07-02 17:21:51 -07001878 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001879 public int prepareAddWindowLw(WindowState win, WindowManager.LayoutParams attrs) {
1880 switch (attrs.type) {
1881 case TYPE_STATUS_BAR:
Joe Onorato8bc6c512010-06-04 16:21:12 -04001882 mContext.enforceCallingOrSelfPermission(
1883 android.Manifest.permission.STATUS_BAR_SERVICE,
1884 "PhoneWindowManager");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001885 if (mStatusBar != null) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001886 if (mStatusBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07001887 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001888 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001889 }
1890 mStatusBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04001891 mStatusBarController.setWindow(win);
John Spurlock8fdfe622014-05-21 17:10:10 -04001892 mKeyguardDelegate.hideScrim();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001893 break;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04001894 case TYPE_NAVIGATION_BAR:
1895 mContext.enforceCallingOrSelfPermission(
1896 android.Manifest.permission.STATUS_BAR_SERVICE,
1897 "PhoneWindowManager");
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001898 if (mNavigationBar != null) {
1899 if (mNavigationBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07001900 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001901 }
1902 }
Daniel Sandler8956dbb2011-04-22 07:55:02 -04001903 mNavigationBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04001904 mNavigationBarController.setWindow(win);
Craig Mautnereda67292013-04-28 13:50:14 -07001905 if (DEBUG_LAYOUT) Slog.i(TAG, "NAVIGATION BAR: " + mNavigationBar);
Daniel Sandler8956dbb2011-04-22 07:55:02 -04001906 break;
Jim Millere898ac52012-04-06 17:10:57 -07001907 case TYPE_NAVIGATION_BAR_PANEL:
1908 mContext.enforceCallingOrSelfPermission(
1909 android.Manifest.permission.STATUS_BAR_SERVICE,
1910 "PhoneWindowManager");
1911 break;
Dianne Hackborn08743722009-12-21 12:16:51 -08001912 case TYPE_STATUS_BAR_PANEL:
Joe Onorato8bc6c512010-06-04 16:21:12 -04001913 mContext.enforceCallingOrSelfPermission(
1914 android.Manifest.permission.STATUS_BAR_SERVICE,
1915 "PhoneWindowManager");
Dianne Hackborn08743722009-12-21 12:16:51 -08001916 break;
Joe Onorato29fc2c92010-11-24 10:26:50 -08001917 case TYPE_STATUS_BAR_SUB_PANEL:
1918 mContext.enforceCallingOrSelfPermission(
1919 android.Manifest.permission.STATUS_BAR_SERVICE,
1920 "PhoneWindowManager");
Joe Onorato29fc2c92010-11-24 10:26:50 -08001921 break;
Jim Miller5ecd8112013-01-09 18:50:26 -08001922 case TYPE_KEYGUARD_SCRIM:
Jim Miller25190572013-02-28 17:36:24 -08001923 if (mKeyguardScrim != null) {
1924 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
1925 }
Jim Miller5ecd8112013-01-09 18:50:26 -08001926 mKeyguardScrim = win;
1927 break;
1928
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001929 }
Jeff Brown98365d72012-08-19 20:30:52 -07001930 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001931 }
1932
1933 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07001934 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001935 public void removeWindowLw(WindowState win) {
1936 if (mStatusBar == win) {
1937 mStatusBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04001938 mStatusBarController.setWindow(null);
Jim Millerc0b676d2013-03-22 16:11:08 -07001939 mKeyguardDelegate.showScrim();
Jim Miller5ecd8112013-01-09 18:50:26 -08001940 } else if (mKeyguardScrim == win) {
1941 Log.v(TAG, "Removing keyguard scrim");
1942 mKeyguardScrim = null;
1943 } if (mNavigationBar == win) {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04001944 mNavigationBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04001945 mNavigationBarController.setWindow(null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001946 }
1947 }
1948
1949 static final boolean PRINT_ANIM = false;
RoboErik8a2cfc32014-05-16 11:19:38 -07001950
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001951 /** {@inheritDoc} */
Craig Mautner4b71aa12012-12-27 17:20:01 -08001952 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001953 public int selectAnimationLw(WindowState win, int transit) {
1954 if (PRINT_ANIM) Log.i(TAG, "selectAnimation in " + win
1955 + ": transit=" + transit);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001956 if (win == mStatusBar) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001957 boolean isKeyguard = (win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001958 if (transit == TRANSIT_EXIT
1959 || transit == TRANSIT_HIDE) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001960 return isKeyguard ? -1 : R.anim.dock_top_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001961 } else if (transit == TRANSIT_ENTER
1962 || transit == TRANSIT_SHOW) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001963 return isKeyguard ? -1 : R.anim.dock_top_enter;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001964 }
1965 } else if (win == mNavigationBar) {
1966 // This can be on either the bottom or the right.
1967 if (mNavigationBarOnBottom) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08001968 if (transit == TRANSIT_EXIT
1969 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001970 return R.anim.dock_bottom_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001971 } else if (transit == TRANSIT_ENTER
1972 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001973 return R.anim.dock_bottom_enter;
1974 }
1975 } else {
Craig Mautner4b71aa12012-12-27 17:20:01 -08001976 if (transit == TRANSIT_EXIT
1977 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001978 return R.anim.dock_right_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001979 } else if (transit == TRANSIT_ENTER
1980 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001981 return R.anim.dock_right_enter;
1982 }
1983 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08001984 }
1985
1986 if (transit == TRANSIT_PREVIEW_DONE) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001987 if (win.hasAppShownWindows()) {
1988 if (PRINT_ANIM) Log.i(TAG, "**** STARTING EXIT");
1989 return com.android.internal.R.anim.app_starting_exit;
1990 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07001991 } else if (win.getAttrs().type == TYPE_DREAM && mDreamingLockscreen
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001992 && transit == TRANSIT_ENTER) {
1993 // Special case: we are animating in a dream, while the keyguard
1994 // is shown. We don't want an animation on the dream, because
1995 // we need it shown immediately with the keyguard animating away
1996 // to reveal it.
1997 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001998 }
1999
2000 return 0;
2001 }
2002
Craig Mautner3c174372013-02-21 17:54:37 -08002003 @Override
2004 public void selectRotationAnimationLw(int anim[]) {
2005 if (PRINT_ANIM) Slog.i(TAG, "selectRotationAnimation mTopFullscreen="
2006 + mTopFullscreenOpaqueWindowState + " rotationAnimation="
2007 + (mTopFullscreenOpaqueWindowState == null ?
2008 "0" : mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation));
2009 if (mTopFullscreenOpaqueWindowState != null && mTopIsFullscreen) {
2010 switch (mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation) {
2011 case ROTATION_ANIMATION_CROSSFADE:
2012 anim[0] = R.anim.rotation_animation_xfade_exit;
2013 anim[1] = R.anim.rotation_animation_enter;
2014 break;
2015 case ROTATION_ANIMATION_JUMPCUT:
2016 anim[0] = R.anim.rotation_animation_jump_exit;
2017 anim[1] = R.anim.rotation_animation_enter;
2018 break;
2019 case ROTATION_ANIMATION_ROTATE:
2020 default:
2021 anim[0] = anim[1] = 0;
2022 break;
2023 }
2024 } else {
2025 anim[0] = anim[1] = 0;
2026 }
2027 }
2028
2029 @Override
2030 public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId,
2031 boolean forceDefault) {
2032 switch (exitAnimId) {
2033 case R.anim.rotation_animation_xfade_exit:
2034 case R.anim.rotation_animation_jump_exit:
2035 // These are the only cases that matter.
2036 if (forceDefault) {
2037 return false;
2038 }
2039 int anim[] = new int[2];
2040 selectRotationAnimationLw(anim);
2041 return (exitAnimId == anim[0] && enterAnimId == anim[1]);
2042 default:
2043 return true;
2044 }
2045 }
2046
2047 @Override
Dianne Hackborn0c2acff2012-04-12 15:17:07 -07002048 public Animation createForceHideEnterAnimation(boolean onWallpaper) {
Jorim Jaggie29b2db2014-05-30 23:17:03 +02002049 return AnimationUtils.loadAnimation(mContext,
2050 com.android.internal.R.anim.lock_screen_behind_enter);
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002051 }
John Spurlockc8b46ca2013-04-08 12:59:26 -04002052
2053 private static void awakenDreams() {
2054 IDreamManager dreamManager = getDreamManager();
2055 if (dreamManager != null) {
2056 try {
2057 dreamManager.awaken();
2058 } catch (RemoteException e) {
2059 // fine, stay asleep then
2060 }
2061 }
2062 }
2063
2064 static IDreamManager getDreamManager() {
2065 return IDreamManager.Stub.asInterface(
2066 ServiceManager.checkService(DreamService.DREAM_SERVICE));
2067 }
2068
Santos Cordon9eb45932014-06-27 12:28:43 -07002069 TelecommManager getTelecommService() {
2070 return (TelecommManager) mContext.getSystemService(Context.TELECOMM_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002071 }
2072
Jeff Brown4d396052010-10-29 21:50:21 -07002073 static IAudioService getAudioService() {
2074 IAudioService audioService = IAudioService.Stub.asInterface(
2075 ServiceManager.checkService(Context.AUDIO_SERVICE));
2076 if (audioService == null) {
2077 Log.w(TAG, "Unable to find IAudioService interface.");
2078 }
2079 return audioService;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002080 }
2081
2082 boolean keyguardOn() {
2083 return keyguardIsShowingTq() || inKeyguardRestrictedKeyInputMode();
2084 }
2085
2086 private static final int[] WINDOW_TYPES_WHERE_HOME_DOESNT_WORK = {
2087 WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
2088 WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
2089 };
2090
2091 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002092 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002093 public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002094 final boolean keyguardOn = keyguardOn();
Jeff Brown1f245102010-11-18 20:53:46 -08002095 final int keyCode = event.getKeyCode();
2096 final int repeatCount = event.getRepeatCount();
2097 final int metaState = event.getMetaState();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002098 final int flags = event.getFlags();
Jeff Brown1f245102010-11-18 20:53:46 -08002099 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
2100 final boolean canceled = event.isCanceled();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002101
Jeff Brown40013652012-05-16 21:22:36 -07002102 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002103 Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount="
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002104 + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed
2105 + " canceled=" + canceled);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002106 }
2107
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002108 // If we think we might have a volume down & power key chord on the way
2109 // but we're not sure, then tell the dispatcher to wait a little while and
2110 // try again later before dispatching.
Christopher Tatee90585f2012-03-05 18:56:25 -08002111 if (mScreenshotChordEnabled && (flags & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002112 if (mVolumeDownKeyTriggered && !mPowerKeyTriggered) {
2113 final long now = SystemClock.uptimeMillis();
2114 final long timeoutTime = mVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS;
2115 if (now < timeoutTime) {
2116 return timeoutTime - now;
2117 }
2118 }
2119 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
2120 && mVolumeDownKeyConsumedByScreenshotChord) {
2121 if (!down) {
2122 mVolumeDownKeyConsumedByScreenshotChord = false;
2123 }
2124 return -1;
2125 }
2126 }
2127
Michael Wright6a62e552014-06-03 19:19:48 -07002128 // Cancel any pending meta actions if we see any other keys being pressed between the down
2129 // of the meta key and its corresponding up.
2130 if (mPendingMetaAction && keyCode != KeyEvent.KEYCODE_META_LEFT) {
2131 mPendingMetaAction = false;
2132 }
2133
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002134 // First we always handle the home key here, so applications
2135 // can never break it, although if keyguard is on, we do let
2136 // it handle it, because that gives us the correct 5 second
2137 // timeout.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002138 if (keyCode == KeyEvent.KEYCODE_HOME) {
Michael Jurka7f2668c2012-03-27 07:49:52 -07002139
Jeff Brown49ed71d2010-12-06 17:13:33 -08002140 // If we have released the home key, and didn't do anything else
2141 // while it was pressed, then it is time to go home!
Michael Jurka7f2668c2012-03-27 07:49:52 -07002142 if (!down) {
Jeff Browncaca8812013-05-09 13:34:33 -07002143 cancelPreloadRecentApps();
2144
Jeff Brown49ed71d2010-12-06 17:13:33 -08002145 mHomePressed = false;
Jeff Browncaca8812013-05-09 13:34:33 -07002146 if (mHomeConsumed) {
2147 mHomeConsumed = false;
Michael Jurka7f2668c2012-03-27 07:49:52 -07002148 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002149 }
Jeff Browncaca8812013-05-09 13:34:33 -07002150
2151 if (canceled) {
2152 Log.i(TAG, "Ignoring HOME; event canceled.");
2153 return -1;
2154 }
2155
2156 // If an incoming call is ringing, HOME is totally disabled.
Santos Cordon9eb45932014-06-27 12:28:43 -07002157 // (The user is already on the InCallUI at this point,
Jeff Browncaca8812013-05-09 13:34:33 -07002158 // and his ONLY options are to answer or reject the call.)
Santos Cordon9eb45932014-06-27 12:28:43 -07002159 TelecommManager telecommManager = getTelecommService();
2160 if (telecommManager != null && telecommManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07002161 Log.i(TAG, "Ignoring HOME; there's a ringing incoming call.");
2162 return -1;
Jeff Browncaca8812013-05-09 13:34:33 -07002163 }
2164
2165 // Delay handling home if a double-tap is possible.
2166 if (mDoubleTapOnHomeBehavior != DOUBLE_TAP_HOME_NOTHING) {
2167 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); // just in case
2168 mHomeDoubleTapPending = true;
2169 mHandler.postDelayed(mHomeDoubleTapTimeoutRunnable,
2170 ViewConfiguration.getDoubleTapTimeout());
2171 return -1;
2172 }
2173
Jose Lima9546b202014-07-02 17:21:51 -07002174 // If there's a dream running then use home to escape the dream
2175 // but don't actually go home.
2176 if (mDreamManagerInternal != null && mDreamManagerInternal.isDreaming()) {
2177 mDreamManagerInternal.stopDream();
2178 return -1;
2179 }
2180
Jeff Browncaca8812013-05-09 13:34:33 -07002181 // Go home!
2182 launchHomeFromHotKey();
2183 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002184 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002185
2186 // If a system window has focus, then it doesn't make sense
2187 // right now to interact with applications.
2188 WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null;
2189 if (attrs != null) {
2190 final int type = attrs.type;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002191 if (type == WindowManager.LayoutParams.TYPE_KEYGUARD_SCRIM
2192 || type == WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG
2193 || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002194 // the "app" is keyguard, so give it the key
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002195 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002196 }
2197 final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length;
2198 for (int i=0; i<typeCount; i++) {
2199 if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) {
2200 // don't do anything, but also don't pass it to the app
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002201 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002202 }
2203 }
2204 }
Jeff Browncaca8812013-05-09 13:34:33 -07002205
2206 // Remember that home is pressed and handle special actions.
2207 if (repeatCount == 0) {
2208 mHomePressed = true;
2209 if (mHomeDoubleTapPending) {
2210 mHomeDoubleTapPending = false;
2211 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable);
2212 handleDoubleTapOnHome();
2213 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI
2214 || mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
2215 preloadRecentApps();
Michael Jurka7f2668c2012-03-27 07:49:52 -07002216 }
Jeff Browncaca8812013-05-09 13:34:33 -07002217 } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) {
2218 if (!keyguardOn) {
2219 handleLongPressOnHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002220 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002221 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002222 return -1;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002223 } else if (keyCode == KeyEvent.KEYCODE_MENU) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002224 // Hijack modified menu keys for debugging features
2225 final int chordBug = KeyEvent.META_SHIFT_ON;
2226
2227 if (down && repeatCount == 0) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002228 if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002229 Intent intent = new Intent(Intent.ACTION_BUG_REPORT);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002230 mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT,
2231 null, null, null, 0, null, null);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002232 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002233 } else if (SHOW_PROCESSES_ON_ALT_MENU &&
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002234 (metaState & KeyEvent.META_ALT_ON) == KeyEvent.META_ALT_ON) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002235 Intent service = new Intent();
2236 service.setClassName(mContext, "com.android.server.LoadAverageService");
2237 ContentResolver res = mContext.getContentResolver();
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002238 boolean shown = Settings.Global.getInt(
2239 res, Settings.Global.SHOW_PROCESSES, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002240 if (!shown) {
2241 mContext.startService(service);
2242 } else {
2243 mContext.stopService(service);
2244 }
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002245 Settings.Global.putInt(
2246 res, Settings.Global.SHOW_PROCESSES, shown ? 0 : 1);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002247 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002248 }
2249 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002250 } else if (keyCode == KeyEvent.KEYCODE_SEARCH) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002251 if (down) {
2252 if (repeatCount == 0) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002253 mSearchKeyShortcutPending = true;
2254 mConsumeSearchKeyUp = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002255 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002256 } else {
2257 mSearchKeyShortcutPending = false;
2258 if (mConsumeSearchKeyUp) {
2259 mConsumeSearchKeyUp = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002260 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002261 }
2262 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002263 return 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002264 } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) {
Michael Wrightc9ebea72013-01-16 19:25:02 -08002265 if (!keyguardOn) {
Jeff Browncaca8812013-05-09 13:34:33 -07002266 if (down && repeatCount == 0) {
2267 preloadRecentApps();
2268 } else if (!down) {
2269 toggleRecentApps();
Michael Wrightc9ebea72013-01-16 19:25:02 -08002270 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002271 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002272 return -1;
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002273 } else if (keyCode == KeyEvent.KEYCODE_ASSIST) {
2274 if (down) {
2275 if (repeatCount == 0) {
2276 mAssistKeyLongPressed = false;
2277 } else if (repeatCount == 1) {
2278 mAssistKeyLongPressed = true;
2279 if (!keyguardOn) {
2280 launchAssistLongPressAction();
2281 }
2282 }
2283 } else {
2284 if (mAssistKeyLongPressed) {
2285 mAssistKeyLongPressed = false;
2286 } else {
2287 if (!keyguardOn) {
2288 launchAssistAction();
2289 }
2290 }
2291 }
2292 return -1;
Jeff Sharkey2991fa32012-12-05 18:06:43 -08002293 } else if (keyCode == KeyEvent.KEYCODE_SYSRQ) {
2294 if (down && repeatCount == 0) {
2295 mHandler.post(mScreenshotRunnable);
2296 }
2297 return -1;
Michael Wrightb854e242013-02-05 17:54:02 -08002298 } else if (keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP
2299 || keyCode == KeyEvent.KEYCODE_BRIGHTNESS_DOWN) {
2300 if (down) {
2301 int direction = keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP ? 1 : -1;
2302
2303 // Disable autobrightness if it's on
2304 int auto = Settings.System.getIntForUser(
2305 mContext.getContentResolver(),
2306 Settings.System.SCREEN_BRIGHTNESS_MODE,
2307 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2308 UserHandle.USER_CURRENT_OR_SELF);
2309 if (auto != 0) {
2310 Settings.System.putIntForUser(mContext.getContentResolver(),
2311 Settings.System.SCREEN_BRIGHTNESS_MODE,
2312 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2313 UserHandle.USER_CURRENT_OR_SELF);
2314 }
2315
2316 int min = mPowerManager.getMinimumScreenBrightnessSetting();
2317 int max = mPowerManager.getMaximumScreenBrightnessSetting();
2318 int step = (max - min + BRIGHTNESS_STEPS - 1) / BRIGHTNESS_STEPS * direction;
2319 int brightness = Settings.System.getIntForUser(mContext.getContentResolver(),
2320 Settings.System.SCREEN_BRIGHTNESS,
2321 mPowerManager.getDefaultScreenBrightnessSetting(),
2322 UserHandle.USER_CURRENT_OR_SELF);
2323 brightness += step;
2324 // Make sure we don't go beyond the limits.
2325 brightness = Math.min(max, brightness);
2326 brightness = Math.max(min, brightness);
2327
2328 Settings.System.putIntForUser(mContext.getContentResolver(),
2329 Settings.System.SCREEN_BRIGHTNESS, brightness,
2330 UserHandle.USER_CURRENT_OR_SELF);
2331 Intent intent = new Intent(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG);
2332 mContext.sendBroadcastAsUser(intent, UserHandle.CURRENT_OR_SELF);
2333 }
2334 return -1;
Michael Wright6a62e552014-06-03 19:19:48 -07002335 } else if (keyCode == KeyEvent.KEYCODE_META_LEFT) {
2336 if (down) {
2337 mPendingMetaAction = true;
2338 } else if (mPendingMetaAction) {
2339 mPendingMetaAction = false;
2340 launchAssistAction();
2341 }
2342 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002343 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002344
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002345 // Shortcuts are invoked through Search+key, so intercept those here
Jeff Browncaab4d02010-12-09 22:13:41 -08002346 // Any printing key that is chorded with Search should be consumed
2347 // even if no shortcut was invoked. This prevents text from being
2348 // inadvertently inserted when using a keyboard that has built-in macro
2349 // shortcut keys (that emit Search+x) and some of them are not registered.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002350 if (mSearchKeyShortcutPending) {
Jeff Browncaab4d02010-12-09 22:13:41 -08002351 final KeyCharacterMap kcm = event.getKeyCharacterMap();
2352 if (kcm.isPrintingKey(keyCode)) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002353 mConsumeSearchKeyUp = true;
2354 mSearchKeyShortcutPending = false;
Jeff Browncaab4d02010-12-09 22:13:41 -08002355 if (down && repeatCount == 0 && !keyguardOn) {
2356 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState);
2357 if (shortcutIntent != null) {
2358 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002359 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002360 mContext.startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002361 } catch (ActivityNotFoundException ex) {
2362 Slog.w(TAG, "Dropping shortcut key combination because "
2363 + "the activity to which it is registered was not found: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002364 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode), ex);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002365 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002366 } else {
2367 Slog.i(TAG, "Dropping unregistered shortcut key combination: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002368 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002369 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002370 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002371 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002372 }
2373 }
2374
Jeff Brown68b909d2011-12-07 16:36:01 -08002375 // Invoke shortcuts using Meta.
Jeff Brown602ab322012-05-16 13:33:47 -07002376 if (down && repeatCount == 0 && !keyguardOn
Jeff Brown68b909d2011-12-07 16:36:01 -08002377 && (metaState & KeyEvent.META_META_ON) != 0) {
2378 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brown602ab322012-05-16 13:33:47 -07002379 if (kcm.isPrintingKey(keyCode)) {
2380 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode,
2381 metaState & ~(KeyEvent.META_META_ON
2382 | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON));
2383 if (shortcutIntent != null) {
2384 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2385 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002386 mContext.startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brown602ab322012-05-16 13:33:47 -07002387 } catch (ActivityNotFoundException ex) {
2388 Slog.w(TAG, "Dropping shortcut key combination because "
2389 + "the activity to which it is registered was not found: "
2390 + "META+" + KeyEvent.keyCodeToString(keyCode), ex);
2391 }
2392 return -1;
Jeff Brown68b909d2011-12-07 16:36:01 -08002393 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002394 }
2395 }
2396
Jeff Brown6651a632011-11-28 12:59:11 -08002397 // Handle application launch keys.
Jeff Brown602ab322012-05-16 13:33:47 -07002398 if (down && repeatCount == 0 && !keyguardOn) {
Jeff Brown6651a632011-11-28 12:59:11 -08002399 String category = sApplicationLaunchKeyCategories.get(keyCode);
2400 if (category != null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -08002401 Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category);
Jeff Brown6651a632011-11-28 12:59:11 -08002402 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2403 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002404 mContext.startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brown6651a632011-11-28 12:59:11 -08002405 } catch (ActivityNotFoundException ex) {
2406 Slog.w(TAG, "Dropping application launch key because "
2407 + "the activity to which it is registered was not found: "
2408 + "keyCode=" + keyCode + ", category=" + category, ex);
2409 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002410 return -1;
Jeff Brown6651a632011-11-28 12:59:11 -08002411 }
2412 }
2413
Jeff Brown68b909d2011-12-07 16:36:01 -08002414 // Display task switcher for ALT-TAB or Meta-TAB.
2415 if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_TAB) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002416 if (mRecentAppsHeldModifiers == 0 && !keyguardOn) {
Jeff Brown68b909d2011-12-07 16:36:01 -08002417 final int shiftlessModifiers = event.getModifiers() & ~KeyEvent.META_SHIFT_MASK;
Winson Chungc6011de2014-06-30 18:04:55 -07002418 if (KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_ALT_ON)) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002419 mRecentAppsHeldModifiers = shiftlessModifiers;
2420 showRecentApps(true);
Jeff Brown68b909d2011-12-07 16:36:01 -08002421 return -1;
2422 }
2423 }
Winson Chung1e8d71b2014-05-16 17:05:22 -07002424 } else if (!down && mRecentAppsHeldModifiers != 0
2425 && (metaState & mRecentAppsHeldModifiers) == 0) {
2426 mRecentAppsHeldModifiers = 0;
Winson Chung6cb485f2014-05-19 10:30:43 -07002427 hideRecentApps(true);
Jeff Brown68b909d2011-12-07 16:36:01 -08002428 }
2429
Jeff Browncf39bdf2012-05-18 14:41:19 -07002430 // Handle keyboard language switching.
2431 if (down && repeatCount == 0
2432 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2433 || (keyCode == KeyEvent.KEYCODE_SPACE
2434 && (metaState & KeyEvent.META_CTRL_MASK) != 0))) {
2435 int direction = (metaState & KeyEvent.META_SHIFT_MASK) != 0 ? -1 : 1;
2436 mWindowManagerFuncs.switchKeyboardLayout(event.getDeviceId(), direction);
2437 return -1;
2438 }
2439 if (mLanguageSwitchKeyPressed && !down
2440 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2441 || keyCode == KeyEvent.KEYCODE_SPACE)) {
2442 mLanguageSwitchKeyPressed = false;
2443 return -1;
2444 }
2445
Justin Kohd378ad72013-04-01 12:18:26 -07002446 if (mGlobalKeyManager.handleGlobalKey(mContext, keyCode, event)) {
2447 return -1;
2448 }
2449
Michael Wright6a62e552014-06-03 19:19:48 -07002450 // Reserve all the META modifier combos for system behavior
2451 if ((metaState & KeyEvent.META_META_LEFT_ON) != 0) {
2452 return -1;
2453 }
2454
Jeff Brown68b909d2011-12-07 16:36:01 -08002455 // Let the application handle the key.
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002456 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002457 }
2458
Jeff Brown3915bb82010-11-05 15:02:16 -07002459 /** {@inheritDoc} */
2460 @Override
Jeff Brown49ed71d2010-12-06 17:13:33 -08002461 public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown54875002011-04-06 15:33:01 -07002462 // Note: This method is only called if the initial down was unhandled.
Jeff Brown40013652012-05-16 21:22:36 -07002463 if (DEBUG_INPUT) {
Jeff Brown1f245102010-11-18 20:53:46 -08002464 Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction()
2465 + ", flags=" + event.getFlags()
2466 + ", keyCode=" + event.getKeyCode()
2467 + ", scanCode=" + event.getScanCode()
2468 + ", metaState=" + event.getMetaState()
2469 + ", repeatCount=" + event.getRepeatCount()
2470 + ", policyFlags=" + policyFlags);
Jeff Brown3915bb82010-11-05 15:02:16 -07002471 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002472
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002473 KeyEvent fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002474 if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
2475 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002476 final int keyCode = event.getKeyCode();
2477 final int metaState = event.getMetaState();
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002478 final boolean initialDown = event.getAction() == KeyEvent.ACTION_DOWN
2479 && event.getRepeatCount() == 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002480
Jeff Brown54875002011-04-06 15:33:01 -07002481 // Check for fallback actions specified by the key character map.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002482 final FallbackAction fallbackAction;
2483 if (initialDown) {
2484 fallbackAction = kcm.getFallbackAction(keyCode, metaState);
2485 } else {
2486 fallbackAction = mFallbackActions.get(keyCode);
2487 }
2488
2489 if (fallbackAction != null) {
Jeff Brown40013652012-05-16 21:22:36 -07002490 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002491 Slog.d(TAG, "Fallback: keyCode=" + fallbackAction.keyCode
2492 + " metaState=" + Integer.toHexString(fallbackAction.metaState));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002493 }
2494
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002495 final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK;
2496 fallbackEvent = KeyEvent.obtain(
Jeff Brown49ed71d2010-12-06 17:13:33 -08002497 event.getDownTime(), event.getEventTime(),
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002498 event.getAction(), fallbackAction.keyCode,
2499 event.getRepeatCount(), fallbackAction.metaState,
Jeff Brown49ed71d2010-12-06 17:13:33 -08002500 event.getDeviceId(), event.getScanCode(),
2501 flags, event.getSource(), null);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002502
2503 if (!interceptFallback(win, fallbackEvent, policyFlags)) {
2504 fallbackEvent.recycle();
2505 fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002506 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002507
2508 if (initialDown) {
2509 mFallbackActions.put(keyCode, fallbackAction);
2510 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2511 mFallbackActions.remove(keyCode);
2512 fallbackAction.recycle();
2513 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002514 }
2515 }
2516
Jeff Brown40013652012-05-16 21:22:36 -07002517 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002518 if (fallbackEvent == null) {
2519 Slog.d(TAG, "No fallback.");
2520 } else {
2521 Slog.d(TAG, "Performing fallback: " + fallbackEvent);
2522 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002523 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002524 return fallbackEvent;
Jeff Brown3915bb82010-11-05 15:02:16 -07002525 }
2526
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002527 private boolean interceptFallback(WindowState win, KeyEvent fallbackEvent, int policyFlags) {
Jeff Brown037c33e2014-04-09 00:31:55 -07002528 int actions = interceptKeyBeforeQueueing(fallbackEvent, policyFlags);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002529 if ((actions & ACTION_PASS_TO_USER) != 0) {
2530 long delayMillis = interceptKeyBeforeDispatching(
2531 win, fallbackEvent, policyFlags);
2532 if (delayMillis == 0) {
2533 return true;
2534 }
2535 }
2536 return false;
Jeff Brown6f2fba42011-02-19 01:08:02 -08002537 }
2538
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002539 private void launchAssistLongPressAction() {
2540 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
2541 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
2542
2543 // launch the search activity
2544 Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS);
2545 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2546 try {
RoboErik8a2cfc32014-05-16 11:19:38 -07002547 // TODO: This only stops the factory-installed search manager.
Jim Miller45308b12012-06-18 19:23:39 -07002548 // Need to formalize an API to handle others
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002549 SearchManager searchManager = getSearchManager();
2550 if (searchManager != null) {
2551 searchManager.stopSearch();
2552 }
Michael Wright43e27f72013-04-10 14:06:48 -07002553 mContext.startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002554 } catch (ActivityNotFoundException e) {
2555 Slog.w(TAG, "No activity to handle assist long press action.", e);
2556 }
2557 }
2558
2559 private void launchAssistAction() {
2560 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
Amith Yamasanic1d07a42012-08-14 09:32:02 -07002561 Intent intent = ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE))
Dianne Hackbornf9c5e0f2013-01-23 14:39:13 -08002562 .getAssistIntent(mContext, true, UserHandle.USER_CURRENT);
Jim Miller45308b12012-06-18 19:23:39 -07002563 if (intent != null) {
2564 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
2565 | Intent.FLAG_ACTIVITY_SINGLE_TOP
2566 | Intent.FLAG_ACTIVITY_CLEAR_TOP);
2567 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002568 mContext.startActivityAsUser(intent, UserHandle.CURRENT);
Jim Miller45308b12012-06-18 19:23:39 -07002569 } catch (ActivityNotFoundException e) {
2570 Slog.w(TAG, "No activity to handle assist action.", e);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002571 }
2572 }
2573 }
2574
2575 private SearchManager getSearchManager() {
2576 if (mSearchManager == null) {
2577 mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
2578 }
2579 return mSearchManager;
2580 }
2581
Jeff Browncaca8812013-05-09 13:34:33 -07002582 private void preloadRecentApps() {
2583 mPreloadedRecentApps = true;
2584 try {
2585 IStatusBarService statusbar = getStatusBarService();
2586 if (statusbar != null) {
2587 statusbar.preloadRecentApps();
2588 }
2589 } catch (RemoteException e) {
2590 Slog.e(TAG, "RemoteException when preloading recent apps", e);
2591 // re-acquire status bar service next time it is needed.
2592 mStatusBarService = null;
2593 }
2594 }
2595
2596 private void cancelPreloadRecentApps() {
2597 if (mPreloadedRecentApps) {
2598 mPreloadedRecentApps = false;
2599 try {
2600 IStatusBarService statusbar = getStatusBarService();
2601 if (statusbar != null) {
2602 statusbar.cancelPreloadRecentApps();
2603 }
2604 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002605 Slog.e(TAG, "RemoteException when cancelling recent apps preload", e);
Jeff Browncaca8812013-05-09 13:34:33 -07002606 // re-acquire status bar service next time it is needed.
2607 mStatusBarService = null;
2608 }
2609 }
2610 }
2611
2612 private void toggleRecentApps() {
2613 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
Jeff Browncaca8812013-05-09 13:34:33 -07002614 try {
2615 IStatusBarService statusbar = getStatusBarService();
2616 if (statusbar != null) {
2617 statusbar.toggleRecentApps();
2618 }
2619 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002620 Slog.e(TAG, "RemoteException when toggling recent apps", e);
2621 // re-acquire status bar service next time it is needed.
2622 mStatusBarService = null;
2623 }
2624 }
2625
Craig Mautner84984fa2014-06-19 11:19:20 -07002626 @Override
2627 public void showRecentApps() {
2628 mHandler.removeMessages(MSG_DISPATCH_SHOW_RECENTS);
2629 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_RECENTS);
2630 }
2631
Winson Chung1e8d71b2014-05-16 17:05:22 -07002632 private void showRecentApps(boolean triggeredFromAltTab) {
2633 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
2634 try {
2635 IStatusBarService statusbar = getStatusBarService();
2636 if (statusbar != null) {
2637 statusbar.showRecentApps(triggeredFromAltTab);
2638 }
2639 } catch (RemoteException e) {
Jeff Browncaca8812013-05-09 13:34:33 -07002640 Slog.e(TAG, "RemoteException when showing recent apps", e);
2641 // re-acquire status bar service next time it is needed.
2642 mStatusBarService = null;
2643 }
2644 }
2645
Winson Chung6cb485f2014-05-19 10:30:43 -07002646 private void hideRecentApps(boolean triggeredFromAltTab) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002647 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
2648 try {
2649 IStatusBarService statusbar = getStatusBarService();
2650 if (statusbar != null) {
Winson Chung6cb485f2014-05-19 10:30:43 -07002651 statusbar.hideRecentApps(triggeredFromAltTab);
Winson Chung1e8d71b2014-05-16 17:05:22 -07002652 }
2653 } catch (RemoteException e) {
2654 Slog.e(TAG, "RemoteException when closing recent apps", e);
2655 // re-acquire status bar service next time it is needed.
2656 mStatusBarService = null;
2657 }
2658 }
2659
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002660 /**
2661 * A home key -> launch home action was detected. Take the appropriate action
2662 * given the situation with the keyguard.
2663 */
2664 void launchHomeFromHotKey() {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01002665 if (mKeyguardDelegate != null && mKeyguardDelegate.isShowingAndNotOccluded()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002666 // don't launch home if keyguard showing
Jim Miller5ecd8112013-01-09 18:50:26 -08002667 } else if (!mHideLockScreen && mKeyguardDelegate.isInputRestricted()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002668 // when in keyguard restricted mode, must first verify unlock
2669 // before launching home
Jim Miller5ecd8112013-01-09 18:50:26 -08002670 mKeyguardDelegate.verifyUnlock(new OnKeyguardExitResult() {
Jose Lima9546b202014-07-02 17:21:51 -07002671 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002672 public void onKeyguardExitResult(boolean success) {
2673 if (success) {
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07002674 try {
2675 ActivityManagerNative.getDefault().stopAppSwitches();
2676 } catch (RemoteException e) {
2677 }
Joe Onoratof275f0c2009-11-24 16:11:13 -05002678 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07002679 startDockOrHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002680 }
2681 }
2682 });
2683 } else {
2684 // no keyguard stuff to worry about, just launch home!
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07002685 try {
2686 ActivityManagerNative.getDefault().stopAppSwitches();
2687 } catch (RemoteException e) {
2688 }
Winson Chungd543c1b2014-06-23 15:06:45 -07002689 if (mRecentsVisible) {
2690 // Hide Recents and notify it to launch Home
2691 awakenDreams();
2692 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
2693 hideRecentApps(false);
2694 } else {
2695 // Otherwise, just launch Home
2696 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
2697 startDockOrHome();
2698 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002699 }
2700 }
2701
John Spurlock04db1762013-05-13 12:46:41 -04002702 private final Runnable mClearHideNavigationFlag = new Runnable() {
2703 @Override
2704 public void run() {
2705 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
2706 // Clear flags.
2707 mForceClearedSystemUiFlags &=
2708 ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
2709 }
2710 mWindowManagerFuncs.reevaluateStatusBarVisibility();
Dianne Hackborne26ab702011-10-16 13:21:33 -07002711 }
2712 };
2713
2714 /**
2715 * Input handler used while nav bar is hidden. Captures any touch on the screen,
2716 * to determine when the nav bar should be shown and prevent applications from
2717 * receiving those touches.
2718 */
Jeff Brown32cbc38552011-12-01 14:01:49 -08002719 final class HideNavInputEventReceiver extends InputEventReceiver {
2720 public HideNavInputEventReceiver(InputChannel inputChannel, Looper looper) {
2721 super(inputChannel, looper);
2722 }
2723
Dianne Hackborndf89e652011-10-06 22:35:11 -07002724 @Override
Jeff Brown32cbc38552011-12-01 14:01:49 -08002725 public void onInputEvent(InputEvent event) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07002726 boolean handled = false;
2727 try {
Jeff Brown4952dfd2011-11-30 19:23:22 -08002728 if (event instanceof MotionEvent
2729 && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
2730 final MotionEvent motionEvent = (MotionEvent)event;
2731 if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07002732 // When the user taps down, we re-show the nav bar.
2733 boolean changed = false;
John Spurlock04db1762013-05-13 12:46:41 -04002734 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002735 // Any user activity always causes us to show the
2736 // navigation controls, if they had been hidden.
2737 // We also clear the low profile and only content
2738 // flags so that tapping on the screen will atomically
2739 // restore all currently hidden screen decorations.
2740 int newVal = mResettingSystemUiFlags |
2741 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
2742 View.SYSTEM_UI_FLAG_LOW_PROFILE |
2743 View.SYSTEM_UI_FLAG_FULLSCREEN;
Dianne Hackborne26ab702011-10-16 13:21:33 -07002744 if (mResettingSystemUiFlags != newVal) {
2745 mResettingSystemUiFlags = newVal;
Dianne Hackborndf89e652011-10-06 22:35:11 -07002746 changed = true;
2747 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07002748 // We don't allow the system's nav bar to be hidden
2749 // again for 1 second, to prevent applications from
2750 // spamming us and keeping it from being shown.
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002751 newVal = mForceClearedSystemUiFlags |
2752 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
Dianne Hackborne26ab702011-10-16 13:21:33 -07002753 if (mForceClearedSystemUiFlags != newVal) {
2754 mForceClearedSystemUiFlags = newVal;
2755 changed = true;
John Spurlock04db1762013-05-13 12:46:41 -04002756 mHandler.postDelayed(mClearHideNavigationFlag, 1000);
Dianne Hackborne26ab702011-10-16 13:21:33 -07002757 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07002758 }
2759 if (changed) {
2760 mWindowManagerFuncs.reevaluateStatusBarVisibility();
2761 }
2762 }
2763 }
2764 } finally {
Jeff Brown32cbc38552011-12-01 14:01:49 -08002765 finishInputEvent(event, handled);
Dianne Hackborndf89e652011-10-06 22:35:11 -07002766 }
2767 }
Jeff Brown32cbc38552011-12-01 14:01:49 -08002768 }
2769 final InputEventReceiver.Factory mHideNavInputEventReceiverFactory =
2770 new InputEventReceiver.Factory() {
2771 @Override
2772 public InputEventReceiver createInputEventReceiver(
2773 InputChannel inputChannel, Looper looper) {
2774 return new HideNavInputEventReceiver(inputChannel, looper);
2775 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07002776 };
2777
2778 @Override
2779 public int adjustSystemUiVisibilityLw(int visibility) {
John Spurlock5b9145b2013-08-20 15:13:47 -04002780 mStatusBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
2781 mNavigationBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
Winson Chungd42a6cf2014-06-03 16:24:04 -07002782 mRecentsVisible = (visibility & View.RECENT_APPS_VISIBLE) > 0;
John Spurlock27735a42013-08-14 17:57:38 -04002783
Dianne Hackborndf89e652011-10-06 22:35:11 -07002784 // Reset any bits in mForceClearingStatusBarVisibility that
2785 // are now clear.
Dianne Hackborne26ab702011-10-16 13:21:33 -07002786 mResettingSystemUiFlags &= visibility;
Dianne Hackborndf89e652011-10-06 22:35:11 -07002787 // Clear any bits in the new visibility that are currently being
2788 // force cleared, before reporting it.
Dianne Hackborne26ab702011-10-16 13:21:33 -07002789 return visibility & ~mResettingSystemUiFlags
2790 & ~mForceClearedSystemUiFlags;
Dianne Hackborndf89e652011-10-06 22:35:11 -07002791 }
2792
Craig Mautner69b08182012-09-05 13:07:13 -07002793 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002794 public void getContentInsetHintLw(WindowManager.LayoutParams attrs, Rect contentInset) {
John Spurlockc6d1c602014-01-17 15:22:06 -05002795 final int fl = PolicyControl.getWindowFlags(null, attrs);
John Spurlock1db8b682014-02-18 11:18:59 -05002796 final int sysuiVis = PolicyControl.getSystemUiVisibility(null, attrs);
2797 final int systemUiVisibility = (sysuiVis | attrs.subtreeSystemUiVisibility);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002798
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002799 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002800 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002801 int availRight, availBottom;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07002802 if (canHideNavigationBar() &&
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002803 (systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002804 availRight = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
2805 availBottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
2806 } else {
2807 availRight = mRestrictedScreenLeft + mRestrictedScreenWidth;
2808 availBottom = mRestrictedScreenTop + mRestrictedScreenHeight;
2809 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002810 if ((systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
2811 if ((fl & FLAG_FULLSCREEN) != 0) {
2812 contentInset.set(mStableFullscreenLeft, mStableFullscreenTop,
2813 availRight - mStableFullscreenRight,
2814 availBottom - mStableFullscreenBottom);
2815 } else {
2816 contentInset.set(mStableLeft, mStableTop,
2817 availRight - mStableRight, availBottom - mStableBottom);
2818 }
Dianne Hackbornc652de82013-02-15 16:32:56 -08002819 } else if ((fl & FLAG_FULLSCREEN) != 0 || (fl & FLAG_LAYOUT_IN_OVERSCAN) != 0) {
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002820 contentInset.setEmpty();
2821 } else if ((systemUiVisibility & (View.SYSTEM_UI_FLAG_FULLSCREEN
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002822 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)) == 0) {
2823 contentInset.set(mCurLeft, mCurTop,
2824 availRight - mCurRight, availBottom - mCurBottom);
2825 } else {
2826 contentInset.set(mCurLeft, mCurTop,
2827 availRight - mCurRight, availBottom - mCurBottom);
2828 }
2829 return;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002830 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002831 contentInset.setEmpty();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002832 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002833
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002834 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07002835 @Override
2836 public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight,
2837 int displayRotation) {
Dianne Hackbornc652de82013-02-15 16:32:56 -08002838 final int overscanLeft, overscanTop, overscanRight, overscanBottom;
2839 if (isDefaultDisplay) {
2840 switch (displayRotation) {
2841 case Surface.ROTATION_90:
2842 overscanLeft = mOverscanTop;
2843 overscanTop = mOverscanRight;
2844 overscanRight = mOverscanBottom;
2845 overscanBottom = mOverscanLeft;
2846 break;
2847 case Surface.ROTATION_180:
2848 overscanLeft = mOverscanRight;
2849 overscanTop = mOverscanBottom;
2850 overscanRight = mOverscanLeft;
2851 overscanBottom = mOverscanTop;
2852 break;
2853 case Surface.ROTATION_270:
2854 overscanLeft = mOverscanBottom;
2855 overscanTop = mOverscanLeft;
2856 overscanRight = mOverscanTop;
2857 overscanBottom = mOverscanRight;
2858 break;
2859 default:
2860 overscanLeft = mOverscanLeft;
2861 overscanTop = mOverscanTop;
2862 overscanRight = mOverscanRight;
2863 overscanBottom = mOverscanBottom;
2864 break;
2865 }
2866 } else {
2867 overscanLeft = 0;
2868 overscanTop = 0;
2869 overscanRight = 0;
2870 overscanBottom = 0;
2871 }
Dianne Hackborn313440842013-02-19 19:22:59 -08002872 mOverscanScreenLeft = mRestrictedOverscanScreenLeft = 0;
2873 mOverscanScreenTop = mRestrictedOverscanScreenTop = 0;
2874 mOverscanScreenWidth = mRestrictedOverscanScreenWidth = displayWidth;
2875 mOverscanScreenHeight = mRestrictedOverscanScreenHeight = displayHeight;
Dianne Hackbornc652de82013-02-15 16:32:56 -08002876 mSystemLeft = 0;
2877 mSystemTop = 0;
2878 mSystemRight = displayWidth;
2879 mSystemBottom = displayHeight;
2880 mUnrestrictedScreenLeft = overscanLeft;
2881 mUnrestrictedScreenTop = overscanTop;
2882 mUnrestrictedScreenWidth = displayWidth - overscanLeft - overscanRight;
2883 mUnrestrictedScreenHeight = displayHeight - overscanTop - overscanBottom;
2884 mRestrictedScreenLeft = mUnrestrictedScreenLeft;
2885 mRestrictedScreenTop = mUnrestrictedScreenTop;
John Spurlockad3e6cb2013-04-30 08:47:43 -04002886 mRestrictedScreenWidth = mSystemGestures.screenWidth = mUnrestrictedScreenWidth;
2887 mRestrictedScreenHeight = mSystemGestures.screenHeight = mUnrestrictedScreenHeight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002888 mDockLeft = mContentLeft = mVoiceContentLeft = mStableLeft = mStableFullscreenLeft
Dianne Hackbornc652de82013-02-15 16:32:56 -08002889 = mCurLeft = mUnrestrictedScreenLeft;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002890 mDockTop = mContentTop = mVoiceContentTop = mStableTop = mStableFullscreenTop
Dianne Hackbornc652de82013-02-15 16:32:56 -08002891 = mCurTop = mUnrestrictedScreenTop;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002892 mDockRight = mContentRight = mVoiceContentRight = mStableRight = mStableFullscreenRight
Dianne Hackbornc652de82013-02-15 16:32:56 -08002893 = mCurRight = displayWidth - overscanRight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002894 mDockBottom = mContentBottom = mVoiceContentBottom = mStableBottom = mStableFullscreenBottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08002895 = mCurBottom = displayHeight - overscanBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002896 mDockLayer = 0x10000000;
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002897 mStatusBarLayer = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002898
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002899 // start with the current dock rect, which will be (0,0,displayWidth,displayHeight)
2900 final Rect pf = mTmpParentFrame;
2901 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002902 final Rect of = mTmpOverscanFrame;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002903 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04002904 final Rect dcf = mTmpDecorFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002905 pf.left = df.left = of.left = vf.left = mDockLeft;
2906 pf.top = df.top = of.top = vf.top = mDockTop;
2907 pf.right = df.right = of.right = vf.right = mDockRight;
2908 pf.bottom = df.bottom = of.bottom = vf.bottom = mDockBottom;
John Spurlock46646232013-09-30 22:32:42 -04002909 dcf.setEmpty(); // Decor frame N/A for system bars.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002910
Craig Mautner69b08182012-09-05 13:07:13 -07002911 if (isDefaultDisplay) {
2912 // For purposes of putting out fake window up to steal focus, we will
2913 // drive nav being hidden only by whether it is requested.
John Spurlocke1f366f2013-08-05 12:22:40 -04002914 final int sysui = mLastSystemUiFlags;
2915 boolean navVisible = (sysui & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0;
Adrian Roosea562512014-05-05 13:33:03 +02002916 boolean navTranslucent = (sysui
2917 & (View.NAVIGATION_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04002918 boolean immersive = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
2919 boolean immersiveSticky = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
2920 boolean navAllowedHidden = immersive || immersiveSticky;
2921 navTranslucent &= !immersiveSticky; // transient trumps translucent
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04002922 navTranslucent &= areTranslucentBarsAllowed();
Dianne Hackborne26ab702011-10-16 13:21:33 -07002923
Craig Mautner69b08182012-09-05 13:07:13 -07002924 // When the navigation bar isn't visible, we put up a fake
2925 // input window to catch all touch events. This way we can
2926 // detect when the user presses anywhere to bring back the nav
2927 // bar and ensure the application doesn't see the event.
John Spurlockf1a36642013-10-12 17:50:42 -04002928 if (navVisible || navAllowedHidden) {
Craig Mautner69b08182012-09-05 13:07:13 -07002929 if (mHideNavFakeWindow != null) {
2930 mHideNavFakeWindow.dismiss();
2931 mHideNavFakeWindow = null;
2932 }
2933 } else if (mHideNavFakeWindow == null) {
2934 mHideNavFakeWindow = mWindowManagerFuncs.addFakeWindow(
2935 mHandler.getLooper(), mHideNavInputEventReceiverFactory,
Adam Lesinski95c42972013-10-02 10:13:27 -07002936 "hidden nav", WindowManager.LayoutParams.TYPE_HIDDEN_NAV_CONSUMER, 0,
Craig Mautner69b08182012-09-05 13:07:13 -07002937 0, false, false, true);
Dianne Hackborne26ab702011-10-16 13:21:33 -07002938 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07002939
Craig Mautner69b08182012-09-05 13:07:13 -07002940 // For purposes of positioning and showing the nav bar, if we have
2941 // decided that it can't be hidden (because of the screen aspect ratio),
2942 // then take that into account.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07002943 navVisible |= !canHideNavigationBar();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002944
John Spurlockad3e6cb2013-04-30 08:47:43 -04002945 boolean updateSysUiVisibility = false;
Craig Mautner69b08182012-09-05 13:07:13 -07002946 if (mNavigationBar != null) {
John Spurlock27735a42013-08-14 17:57:38 -04002947 boolean transientNavBarShowing = mNavigationBarController.isTransientShowing();
Craig Mautner69b08182012-09-05 13:07:13 -07002948 // Force the navigation bar to its appropriate place and
2949 // size. We need to do this directly, instead of relying on
2950 // it to bubble up from the nav bar, because this needs to
2951 // change atomically with screen rotations.
2952 mNavigationBarOnBottom = (!mNavigationBarCanMove || displayWidth < displayHeight);
2953 if (mNavigationBarOnBottom) {
2954 // It's a system nav bar or a portrait screen; nav bar goes on bottom.
Dianne Hackbornc652de82013-02-15 16:32:56 -08002955 int top = displayHeight - overscanBottom
2956 - mNavigationBarHeightForRotation[displayRotation];
2957 mTmpNavigationFrame.set(0, top, displayWidth, displayHeight - overscanBottom);
Craig Mautner69b08182012-09-05 13:07:13 -07002958 mStableBottom = mStableFullscreenBottom = mTmpNavigationFrame.top;
John Spurlockf95b89a2013-10-10 22:10:42 -04002959 if (transientNavBarShowing) {
John Spurlock27735a42013-08-14 17:57:38 -04002960 mNavigationBarController.setBarShowingLw(true);
John Spurlockad3e6cb2013-04-30 08:47:43 -04002961 } else if (navVisible) {
John Spurlock27735a42013-08-14 17:57:38 -04002962 mNavigationBarController.setBarShowingLw(true);
Craig Mautner69b08182012-09-05 13:07:13 -07002963 mDockBottom = mTmpNavigationFrame.top;
Dianne Hackborn313440842013-02-19 19:22:59 -08002964 mRestrictedScreenHeight = mDockBottom - mRestrictedScreenTop;
2965 mRestrictedOverscanScreenHeight = mDockBottom - mRestrictedOverscanScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07002966 } else {
2967 // We currently want to hide the navigation UI.
John Spurlock27735a42013-08-14 17:57:38 -04002968 mNavigationBarController.setBarShowingLw(false);
Craig Mautner69b08182012-09-05 13:07:13 -07002969 }
John Spurlockc6d1c602014-01-17 15:22:06 -05002970 if (navVisible && !navTranslucent && !navAllowedHidden
2971 && !mNavigationBar.isAnimatingLw()
John Spurlockbd957402013-10-03 11:38:39 -04002972 && !mNavigationBarController.wasRecentlyTranslucent()) {
John Spurlocke1f366f2013-08-05 12:22:40 -04002973 // If the opaque nav bar is currently requested to be visible,
Craig Mautner69b08182012-09-05 13:07:13 -07002974 // and not in the process of animating on or off, then
2975 // we can tell the app that it is covered by it.
2976 mSystemBottom = mTmpNavigationFrame.top;
2977 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002978 } else {
Craig Mautner69b08182012-09-05 13:07:13 -07002979 // Landscape screen; nav bar goes to the right.
Dianne Hackbornc652de82013-02-15 16:32:56 -08002980 int left = displayWidth - overscanRight
2981 - mNavigationBarWidthForRotation[displayRotation];
2982 mTmpNavigationFrame.set(left, 0, displayWidth - overscanRight, displayHeight);
Craig Mautner69b08182012-09-05 13:07:13 -07002983 mStableRight = mStableFullscreenRight = mTmpNavigationFrame.left;
John Spurlockf95b89a2013-10-10 22:10:42 -04002984 if (transientNavBarShowing) {
John Spurlock27735a42013-08-14 17:57:38 -04002985 mNavigationBarController.setBarShowingLw(true);
John Spurlockad3e6cb2013-04-30 08:47:43 -04002986 } else if (navVisible) {
John Spurlock27735a42013-08-14 17:57:38 -04002987 mNavigationBarController.setBarShowingLw(true);
Craig Mautner69b08182012-09-05 13:07:13 -07002988 mDockRight = mTmpNavigationFrame.left;
Dianne Hackborn313440842013-02-19 19:22:59 -08002989 mRestrictedScreenWidth = mDockRight - mRestrictedScreenLeft;
2990 mRestrictedOverscanScreenWidth = mDockRight - mRestrictedOverscanScreenLeft;
Craig Mautner69b08182012-09-05 13:07:13 -07002991 } else {
2992 // We currently want to hide the navigation UI.
John Spurlock27735a42013-08-14 17:57:38 -04002993 mNavigationBarController.setBarShowingLw(false);
Craig Mautner69b08182012-09-05 13:07:13 -07002994 }
John Spurlockbd957402013-10-03 11:38:39 -04002995 if (navVisible && !navTranslucent && !mNavigationBar.isAnimatingLw()
2996 && !mNavigationBarController.wasRecentlyTranslucent()) {
Craig Mautner69b08182012-09-05 13:07:13 -07002997 // If the nav bar is currently requested to be visible,
2998 // and not in the process of animating on or off, then
2999 // we can tell the app that it is covered by it.
3000 mSystemRight = mTmpNavigationFrame.left;
3001 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003002 }
Craig Mautner69b08182012-09-05 13:07:13 -07003003 // Make sure the content and current rectangles are updated to
3004 // account for the restrictions from the navigation bar.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003005 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3006 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3007 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3008 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
Craig Mautner69b08182012-09-05 13:07:13 -07003009 mStatusBarLayer = mNavigationBar.getSurfaceLayer();
3010 // And compute the final frame.
3011 mNavigationBar.computeFrameLw(mTmpNavigationFrame, mTmpNavigationFrame,
Adrian Roosfa104232014-06-20 16:10:14 -07003012 mTmpNavigationFrame, mTmpNavigationFrame, mTmpNavigationFrame, dcf,
3013 mTmpNavigationFrame);
Craig Mautnereda67292013-04-28 13:50:14 -07003014 if (DEBUG_LAYOUT) Slog.i(TAG, "mNavigationBar frame: " + mTmpNavigationFrame);
John Spurlock27735a42013-08-14 17:57:38 -04003015 if (mNavigationBarController.checkHiddenLw()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04003016 updateSysUiVisibility = true;
3017 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003018 }
Craig Mautnereda67292013-04-28 13:50:14 -07003019 if (DEBUG_LAYOUT) Slog.i(TAG, String.format("mDock rect: (%d,%d - %d,%d)",
Craig Mautner69b08182012-09-05 13:07:13 -07003020 mDockLeft, mDockTop, mDockRight, mDockBottom));
3021
3022 // decide where the status bar goes ahead of time
3023 if (mStatusBar != null) {
3024 // apply any navigation bar insets
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003025 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3026 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3027 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
3028 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight
3029 + mUnrestrictedScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07003030 vf.left = mStableLeft;
3031 vf.top = mStableTop;
3032 vf.right = mStableRight;
3033 vf.bottom = mStableBottom;
3034
3035 mStatusBarLayer = mStatusBar.getSurfaceLayer();
3036
3037 // Let the status bar determine its size.
Adrian Roosfa104232014-06-20 16:10:14 -07003038 mStatusBar.computeFrameLw(pf, df, vf, vf, vf, dcf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07003039
3040 // For layout, the status bar is always at the top with our fixed height.
3041 mStableTop = mUnrestrictedScreenTop + mStatusBarHeight;
3042
John Spurlocke1f366f2013-08-05 12:22:40 -04003043 boolean statusBarTransient = (sysui & View.STATUS_BAR_TRANSIENT) != 0;
Adrian Roosea562512014-05-05 13:33:03 +02003044 boolean statusBarTranslucent = (sysui
3045 & (View.STATUS_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0;
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04003046 statusBarTranslucent &= areTranslucentBarsAllowed();
John Spurlock32beb2c2013-03-11 10:16:47 -04003047
Craig Mautner69b08182012-09-05 13:07:13 -07003048 // If the status bar is hidden, we don't want to cause
3049 // windows behind it to scroll.
John Spurlockeda1f692013-09-16 11:38:44 -04003050 if (mStatusBar.isVisibleLw() && !statusBarTransient) {
Craig Mautner69b08182012-09-05 13:07:13 -07003051 // Status bar may go away, so the screen area it occupies
3052 // is available to apps but just covering them when the
3053 // status bar is visible.
3054 mDockTop = mUnrestrictedScreenTop + mStatusBarHeight;
3055
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003056 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3057 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3058 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3059 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
Craig Mautner69b08182012-09-05 13:07:13 -07003060
Craig Mautnereda67292013-04-28 13:50:14 -07003061 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar: " +
Craig Mautner69b08182012-09-05 13:07:13 -07003062 String.format(
3063 "dock=[%d,%d][%d,%d] content=[%d,%d][%d,%d] cur=[%d,%d][%d,%d]",
3064 mDockLeft, mDockTop, mDockRight, mDockBottom,
3065 mContentLeft, mContentTop, mContentRight, mContentBottom,
3066 mCurLeft, mCurTop, mCurRight, mCurBottom));
3067 }
John Spurlocke1f366f2013-08-05 12:22:40 -04003068 if (mStatusBar.isVisibleLw() && !mStatusBar.isAnimatingLw()
John Spurlockbd957402013-10-03 11:38:39 -04003069 && !statusBarTransient && !statusBarTranslucent
3070 && !mStatusBarController.wasRecentlyTranslucent()) {
John Spurlocke1f366f2013-08-05 12:22:40 -04003071 // If the opaque status bar is currently requested to be visible,
Craig Mautner69b08182012-09-05 13:07:13 -07003072 // and not in the process of animating on or off, then
3073 // we can tell the app that it is covered by it.
3074 mSystemTop = mUnrestrictedScreenTop + mStatusBarHeight;
3075 }
John Spurlock27735a42013-08-14 17:57:38 -04003076 if (mStatusBarController.checkHiddenLw()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04003077 updateSysUiVisibility = true;
John Spurlock32beb2c2013-03-11 10:16:47 -04003078 }
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003079 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04003080 if (updateSysUiVisibility) {
3081 updateSystemUiVisibilityLw();
3082 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003083 }
3084 }
3085
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003086 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07003087 @Override
John Spurlock46646232013-09-30 22:32:42 -04003088 public int getSystemDecorLayerLw() {
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003089 if (mStatusBar != null) return mStatusBar.getSurfaceLayer();
3090 if (mNavigationBar != null) return mNavigationBar.getSurfaceLayer();
3091 return 0;
3092 }
3093
Craig Mautner967212c2013-04-13 21:10:58 -07003094 @Override
3095 public void getContentRectLw(Rect r) {
3096 r.set(mContentLeft, mContentTop, mContentRight, mContentBottom);
3097 }
3098
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003099 void setAttachedWindowFrames(WindowState win, int fl, int adjust, WindowState attached,
3100 boolean insetDecors, Rect pf, Rect df, Rect of, Rect cf, Rect vf) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003101 if (win.getSurfaceLayer() > mDockLayer && attached.getSurfaceLayer() < mDockLayer) {
3102 // Here's a special case: if this attached window is a panel that is
3103 // above the dock window, and the window it is attached to is below
3104 // the dock window, then the frames we computed for the window it is
3105 // attached to can not be used because the dock is effectively part
3106 // of the underlying window and the attached window is floating on top
3107 // of the whole thing. So, we ignore the attached window and explicitly
3108 // compute the frames that would be appropriate without the dock.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003109 df.left = of.left = cf.left = vf.left = mDockLeft;
3110 df.top = of.top = cf.top = vf.top = mDockTop;
3111 df.right = of.right = cf.right = vf.right = mDockRight;
3112 df.bottom = of.bottom = cf.bottom = vf.bottom = mDockBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003113 } else {
3114 // The effective display frame of the attached window depends on
3115 // whether it is taking care of insetting its content. If not,
3116 // we need to use the parent's content frame so that the entire
3117 // window is positioned within that content. Otherwise we can use
3118 // the display frame and let the attached window take care of
3119 // positioning its content appropriately.
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003120 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003121 cf.set(attached.getOverscanFrameLw());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003122 } else {
3123 // If the window is resizing, then we want to base the content
3124 // frame on our attached content frame to resize... however,
3125 // things can be tricky if the attached window is NOT in resize
3126 // mode, in which case its content frame will be larger.
3127 // Ungh. So to deal with that, make sure the content frame
3128 // we end up using is not covering the IM dock.
3129 cf.set(attached.getContentFrameLw());
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003130 if (attached.isVoiceInteraction()) {
3131 if (cf.left < mVoiceContentLeft) cf.left = mVoiceContentLeft;
3132 if (cf.top < mVoiceContentTop) cf.top = mVoiceContentTop;
3133 if (cf.right > mVoiceContentRight) cf.right = mVoiceContentRight;
3134 if (cf.bottom > mVoiceContentBottom) cf.bottom = mVoiceContentBottom;
3135 } else if (attached.getSurfaceLayer() < mDockLayer) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003136 if (cf.left < mContentLeft) cf.left = mContentLeft;
3137 if (cf.top < mContentTop) cf.top = mContentTop;
3138 if (cf.right > mContentRight) cf.right = mContentRight;
3139 if (cf.bottom > mContentBottom) cf.bottom = mContentBottom;
3140 }
3141 }
3142 df.set(insetDecors ? attached.getDisplayFrameLw() : cf);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003143 of.set(insetDecors ? attached.getOverscanFrameLw() : cf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003144 vf.set(attached.getVisibleFrameLw());
3145 }
3146 // The LAYOUT_IN_SCREEN flag is used to determine whether the attached
3147 // window should be positioned relative to its parent or the entire
3148 // screen.
3149 pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0
3150 ? attached.getFrameLw() : df);
3151 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003152
3153 private void applyStableConstraints(int sysui, int fl, Rect r) {
3154 if ((sysui & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
3155 // If app is requesting a stable layout, don't let the
3156 // content insets go below the stable values.
3157 if ((fl & FLAG_FULLSCREEN) != 0) {
3158 if (r.left < mStableFullscreenLeft) r.left = mStableFullscreenLeft;
3159 if (r.top < mStableFullscreenTop) r.top = mStableFullscreenTop;
3160 if (r.right > mStableFullscreenRight) r.right = mStableFullscreenRight;
3161 if (r.bottom > mStableFullscreenBottom) r.bottom = mStableFullscreenBottom;
3162 } else {
3163 if (r.left < mStableLeft) r.left = mStableLeft;
3164 if (r.top < mStableTop) r.top = mStableTop;
3165 if (r.right > mStableRight) r.right = mStableRight;
3166 if (r.bottom > mStableBottom) r.bottom = mStableBottom;
3167 }
3168 }
3169 }
3170
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003171 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07003172 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003173 public void layoutWindowLw(WindowState win, WindowState attached) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003174 // we've already done the status bar
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003175 final WindowManager.LayoutParams attrs = win.getAttrs();
3176 if ((win == mStatusBar && (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) == 0) ||
3177 win == mNavigationBar) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003178 return;
3179 }
Craig Mautner69b08182012-09-05 13:07:13 -07003180 final boolean isDefaultDisplay = win.isDefaultDisplay();
3181 final boolean needsToOffsetInputMethodTarget = isDefaultDisplay &&
satok1bc0a492012-04-25 22:47:12 +09003182 (win == mLastInputMethodTargetWindow && mLastInputMethodWindow != null);
3183 if (needsToOffsetInputMethodTarget) {
Craig Mautnereda67292013-04-28 13:50:14 -07003184 if (DEBUG_LAYOUT) Slog.i(TAG, "Offset ime target window by the last ime window state");
satok1bc0a492012-04-25 22:47:12 +09003185 offsetInputMethodWindowLw(mLastInputMethodWindow);
3186 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003187
John Spurlockc6d1c602014-01-17 15:22:06 -05003188 final int fl = PolicyControl.getWindowFlags(win, attrs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003189 final int sim = attrs.softInputMode;
John Spurlock1db8b682014-02-18 11:18:59 -05003190 final int sysUiFl = PolicyControl.getSystemUiVisibility(win, null);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003191
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003192 final Rect pf = mTmpParentFrame;
3193 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003194 final Rect of = mTmpOverscanFrame;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003195 final Rect cf = mTmpContentFrame;
3196 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04003197 final Rect dcf = mTmpDecorFrame;
Adrian Roosfa104232014-06-20 16:10:14 -07003198 final Rect sf = mTmpStableFrame;
John Spurlock46646232013-09-30 22:32:42 -04003199 dcf.setEmpty();
Craig Mautner69b08182012-09-05 13:07:13 -07003200
3201 final boolean hasNavBar = (isDefaultDisplay && mHasNavigationBar
Daniel Sandler36412a72011-08-04 09:35:13 -04003202 && mNavigationBar != null && mNavigationBar.isVisibleLw());
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003203
Craig Mautnerf683b562012-10-02 11:10:57 -07003204 final int adjust = sim & SOFT_INPUT_MASK_ADJUST;
3205
Adrian Roosfa104232014-06-20 16:10:14 -07003206 if (isDefaultDisplay) {
3207 sf.set(mStableLeft, mStableTop, mStableRight, mStableBottom);
3208 } else {
3209 sf.set(mOverscanLeft, mOverscanTop, mOverscanRight, mOverscanBottom);
3210 }
3211
Craig Mautner69b08182012-09-05 13:07:13 -07003212 if (!isDefaultDisplay) {
3213 if (attached != null) {
3214 // If this window is attached to another, our display
3215 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003216 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07003217 } else {
3218 // Give the window full screen.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003219 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3220 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3221 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08003222 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003223 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003224 = mOverscanScreenTop + mOverscanScreenHeight;
Craig Mautner69b08182012-09-05 13:07:13 -07003225 }
3226 } else if (attrs.type == TYPE_INPUT_METHOD) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003227 pf.left = df.left = of.left = cf.left = vf.left = mDockLeft;
3228 pf.top = df.top = of.top = cf.top = vf.top = mDockTop;
3229 pf.right = df.right = of.right = cf.right = vf.right = mDockRight;
John Spurlockc68d5772013-10-08 11:47:58 -04003230 // IM dock windows layout below the nav bar...
John Spurlock57beb3b2013-10-10 10:27:44 -04003231 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlockc68d5772013-10-08 11:47:58 -04003232 // ...with content insets above the nav bar
3233 cf.bottom = vf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003234 // IM dock windows always go to the bottom of the screen.
3235 attrs.gravity = Gravity.BOTTOM;
3236 mDockLayer = win.getSurfaceLayer();
3237 } else {
John Spurlock46646232013-09-30 22:32:42 -04003238
3239 // Default policy decor for the default display
3240 dcf.left = mSystemLeft;
3241 dcf.top = mSystemTop;
3242 dcf.right = mSystemRight;
3243 dcf.bottom = mSystemBottom;
John Spurlockbd957402013-10-03 11:38:39 -04003244 final boolean inheritTranslucentDecor = (attrs.privateFlags
3245 & WindowManager.LayoutParams.PRIVATE_FLAG_INHERIT_TRANSLUCENT_DECOR) != 0;
John Spurlock65567d42013-10-08 10:08:32 -04003246 final boolean isAppWindow =
3247 attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW &&
3248 attrs.type <= WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
3249 final boolean topAtRest =
3250 win == mTopFullscreenOpaqueWindowState && !win.isAnimatingLw();
3251 if (isAppWindow && !inheritTranslucentDecor && !topAtRest) {
John Spurlockbd957402013-10-03 11:38:39 -04003252 if ((sysUiFl & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0
3253 && (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0
Adrian Roosea562512014-05-05 13:33:03 +02003254 && (fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) == 0
3255 && (fl & WindowManager.LayoutParams.
3256 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04003257 // Ensure policy decor includes status bar
3258 dcf.top = mStableTop;
3259 }
John Spurlockbd957402013-10-03 11:38:39 -04003260 if ((fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) == 0
Adrian Roosea562512014-05-05 13:33:03 +02003261 && (sysUiFl & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0
3262 && (fl & WindowManager.LayoutParams.
3263 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04003264 // Ensure policy decor includes navigation bar
3265 dcf.bottom = mStableBottom;
3266 dcf.right = mStableRight;
3267 }
3268 }
3269
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003270 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
3271 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
RoboErik8a2cfc32014-05-16 11:19:38 -07003272 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003273 + "): IN_SCREEN, INSET_DECOR");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003274 // This is the case for a normal activity window: we want it
3275 // to cover all of the screen space, and it can take care of
3276 // moving its contents to account for screen decorations that
3277 // intrude into that space.
3278 if (attached != null) {
3279 // If this window is attached to another, our display
3280 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003281 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003282 } else {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003283 if (attrs.type == TYPE_STATUS_BAR_PANEL
3284 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Joe Onorato29fc2c92010-11-24 10:26:50 -08003285 // Status bar panels are the only windows who can go on top of
3286 // the status bar. They are protected by the STATUS_BAR_SERVICE
3287 // permission, so they have the same privileges as the status
3288 // bar itself.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003289 //
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003290 // However, they should still dodge the navigation bar if it exists.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003291
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003292 pf.left = df.left = of.left = hasNavBar
3293 ? mDockLeft : mUnrestrictedScreenLeft;
3294 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3295 pf.right = df.right = of.right = hasNavBar
3296 ? mRestrictedScreenLeft+mRestrictedScreenWidth
3297 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3298 pf.bottom = df.bottom = of.bottom = hasNavBar
3299 ? mRestrictedScreenTop+mRestrictedScreenHeight
3300 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003301
Craig Mautnereda67292013-04-28 13:50:14 -07003302 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003303 "Laying out status bar window: (%d,%d - %d,%d)",
3304 pf.left, pf.top, pf.right, pf.bottom));
John Spurlock46646232013-09-30 22:32:42 -04003305 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08003306 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3307 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3308 // Asking to layout into the overscan region, so give it that pure
3309 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003310 pf.left = df.left = of.left = mOverscanScreenLeft;
3311 pf.top = df.top = of.top = mOverscanScreenTop;
3312 pf.right = df.right = of.right = mOverscanScreenLeft + mOverscanScreenWidth;
3313 pf.bottom = df.bottom = of.bottom = mOverscanScreenTop
3314 + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003315 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003316 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003317 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3318 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003319 // Asking for layout as if the nav bar is hidden, lets the
Dianne Hackbornc652de82013-02-15 16:32:56 -08003320 // application extend into the unrestricted overscan screen area. We
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003321 // only do this for application windows to ensure no window that
3322 // can be above the nav bar can do this.
Dianne Hackborn313440842013-02-19 19:22:59 -08003323 pf.left = df.left = mOverscanScreenLeft;
3324 pf.top = df.top = mOverscanScreenTop;
3325 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
3326 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003327 // We need to tell the app about where the frame inside the overscan
3328 // is, so it can inset its content by that amount -- it didn't ask
3329 // to actually extend itself into the overscan region.
3330 of.left = mUnrestrictedScreenLeft;
3331 of.top = mUnrestrictedScreenTop;
3332 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3333 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003334 } else {
Dianne Hackborn313440842013-02-19 19:22:59 -08003335 pf.left = df.left = mRestrictedOverscanScreenLeft;
3336 pf.top = df.top = mRestrictedOverscanScreenTop;
3337 pf.right = df.right = mRestrictedOverscanScreenLeft
3338 + mRestrictedOverscanScreenWidth;
3339 pf.bottom = df.bottom = mRestrictedOverscanScreenTop
3340 + mRestrictedOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003341 // We need to tell the app about where the frame inside the overscan
3342 // is, so it can inset its content by that amount -- it didn't ask
3343 // to actually extend itself into the overscan region.
3344 of.left = mUnrestrictedScreenLeft;
3345 of.top = mUnrestrictedScreenTop;
3346 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3347 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003348 }
Craig Mautner69b08182012-09-05 13:07:13 -07003349
John Spurlock46646232013-09-30 22:32:42 -04003350 if ((fl & FLAG_FULLSCREEN) == 0) {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003351 if (win.isVoiceInteraction()) {
3352 cf.left = mVoiceContentLeft;
3353 cf.top = mVoiceContentTop;
3354 cf.right = mVoiceContentRight;
3355 cf.bottom = mVoiceContentBottom;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003356 } else {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003357 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
3358 cf.left = mDockLeft;
3359 cf.top = mDockTop;
3360 cf.right = mDockRight;
3361 cf.bottom = mDockBottom;
3362 } else {
3363 cf.left = mContentLeft;
3364 cf.top = mContentTop;
3365 cf.right = mContentRight;
3366 cf.bottom = mContentBottom;
3367 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003368 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003369 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003370 // Full screen windows are always given a layout that is as if the
3371 // status bar and other transient decors are gone. This is to avoid
3372 // bad states when moving from a window that is not hding the
3373 // status bar to one that is.
3374 cf.left = mRestrictedScreenLeft;
3375 cf.top = mRestrictedScreenTop;
3376 cf.right = mRestrictedScreenLeft + mRestrictedScreenWidth;
3377 cf.bottom = mRestrictedScreenTop + mRestrictedScreenHeight;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003378 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003379 applyStableConstraints(sysUiFl, fl, cf);
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003380 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3381 vf.left = mCurLeft;
3382 vf.top = mCurTop;
3383 vf.right = mCurRight;
3384 vf.bottom = mCurBottom;
3385 } else {
3386 vf.set(cf);
3387 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003388 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003389 } else if ((fl & FLAG_LAYOUT_IN_SCREEN) != 0 || (sysUiFl
3390 & (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
3391 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)) != 0) {
Craig Mautnereda67292013-04-28 13:50:14 -07003392 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3393 "): IN_SCREEN");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003394 // A window that has requested to fill the entire screen just
3395 // gets everything, period.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003396 if (attrs.type == TYPE_STATUS_BAR_PANEL
3397 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003398 pf.left = df.left = of.left = cf.left = hasNavBar
3399 ? mDockLeft : mUnrestrictedScreenLeft;
3400 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
3401 pf.right = df.right = of.right = cf.right = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003402 ? mRestrictedScreenLeft+mRestrictedScreenWidth
Dianne Hackbornc652de82013-02-15 16:32:56 -08003403 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003404 pf.bottom = df.bottom = of.bottom = cf.bottom = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003405 ? mRestrictedScreenTop+mRestrictedScreenHeight
Dianne Hackbornc652de82013-02-15 16:32:56 -08003406 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07003407 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler36412a72011-08-04 09:35:13 -04003408 "Laying out IN_SCREEN status bar window: (%d,%d - %d,%d)",
3409 pf.left, pf.top, pf.right, pf.bottom));
Jim Millere898ac52012-04-06 17:10:57 -07003410 } else if (attrs.type == TYPE_NAVIGATION_BAR
3411 || attrs.type == TYPE_NAVIGATION_BAR_PANEL) {
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003412 // The navigation bar has Real Ultimate Power.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003413 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3414 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3415 pf.right = df.right = of.right = mUnrestrictedScreenLeft
3416 + mUnrestrictedScreenWidth;
3417 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop
3418 + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07003419 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003420 "Laying out navigation bar window: (%d,%d - %d,%d)",
3421 pf.left, pf.top, pf.right, pf.bottom));
Dianne Hackborn01011c32012-02-21 13:54:21 -08003422 } else if ((attrs.type == TYPE_SECURE_SYSTEM_OVERLAY
3423 || attrs.type == TYPE_BOOT_PROGRESS)
Jeff Brownbfcb60a2011-09-08 18:51:14 -07003424 && ((fl & FLAG_FULLSCREEN) != 0)) {
3425 // Fullscreen secure system overlays get what they ask for.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003426 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3427 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3428 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
3429 + mOverscanScreenWidth;
3430 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
3431 + mOverscanScreenHeight;
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07003432 } else if (attrs.type == TYPE_BOOT_PROGRESS
3433 || attrs.type == TYPE_UNIVERSE_BACKGROUND) {
Dianne Hackborn01011c32012-02-21 13:54:21 -08003434 // Boot progress screen always covers entire display.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003435 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3436 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3437 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
3438 + mOverscanScreenWidth;
3439 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
3440 + mOverscanScreenHeight;
John Spurlockef4adae2013-08-26 17:58:58 -04003441 } else if (attrs.type == TYPE_WALLPAPER) {
3442 // The wallpaper also has Real Ultimate Power.
3443 pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft;
3444 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003445 pf.right = df.right = of.right = cf.right
John Spurlockef4adae2013-08-26 17:58:58 -04003446 = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003447 pf.bottom = df.bottom = of.bottom = cf.bottom
John Spurlockef4adae2013-08-26 17:58:58 -04003448 = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlock46646232013-09-30 22:32:42 -04003449 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08003450 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3451 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3452 // Asking to layout into the overscan region, so give it that pure
3453 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003454 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3455 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3456 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08003457 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003458 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003459 = mOverscanScreenTop + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003460 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003461 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Craig Mautnerbeac1062014-06-03 14:38:57 -07003462 && (attrs.type == TYPE_STATUS_BAR
3463 || attrs.type == TYPE_TOAST
John Spurlock34e13d92013-08-10 06:52:28 -04003464 || (attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3465 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW))) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003466 // Asking for layout as if the nav bar is hidden, lets the
3467 // application extend into the unrestricted screen area. We
John Spurlock34e13d92013-08-10 06:52:28 -04003468 // only do this for application windows (or toasts) to ensure no window that
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003469 // can be above the nav bar can do this.
3470 // XXX This assumes that an app asking for this will also
3471 // ask for layout in only content. We can't currently figure out
3472 // what the screen would be if only laying out to hide the nav bar.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003473 pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft;
3474 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
3475 pf.right = df.right = of.right = cf.right = mUnrestrictedScreenLeft
3476 + mUnrestrictedScreenWidth;
3477 pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop
3478 + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003479 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003480 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
3481 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
3482 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
3483 + mRestrictedScreenWidth;
3484 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
3485 + mRestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003486 }
Craig Mautner69b08182012-09-05 13:07:13 -07003487
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003488 applyStableConstraints(sysUiFl, fl, cf);
Craig Mautner69b08182012-09-05 13:07:13 -07003489
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003490 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3491 vf.left = mCurLeft;
3492 vf.top = mCurTop;
3493 vf.right = mCurRight;
3494 vf.bottom = mCurBottom;
3495 } else {
3496 vf.set(cf);
3497 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003498 } else if (attached != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07003499 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3500 "): attached to " + attached);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003501 // A child window should be placed inside of the same visible
3502 // frame that its parent had.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003503 setAttachedWindowFrames(win, fl, adjust, attached, false, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003504 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07003505 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3506 "): normal window");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003507 // Otherwise, a normal window must be placed inside the content
3508 // of all screen decorations.
Dianne Hackborna239c842011-06-01 12:28:20 -07003509 if (attrs.type == TYPE_STATUS_BAR_PANEL) {
3510 // Status bar panels are the only windows who can go on top of
3511 // the status bar. They are protected by the STATUS_BAR_SERVICE
3512 // permission, so they have the same privileges as the status
3513 // bar itself.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003514 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
3515 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
3516 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
3517 + mRestrictedScreenWidth;
3518 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
3519 + mRestrictedScreenHeight;
John Spurlock414c1f02013-12-04 13:47:36 -05003520 } else if (attrs.type == TYPE_TOAST || attrs.type == TYPE_SYSTEM_ALERT
3521 || attrs.type == TYPE_VOLUME_OVERLAY) {
3522 // These dialogs are stable to interim decor changes.
John Spurlockbd957402013-10-03 11:38:39 -04003523 pf.left = df.left = of.left = cf.left = mStableLeft;
3524 pf.top = df.top = of.top = cf.top = mStableTop;
3525 pf.right = df.right = of.right = cf.right = mStableRight;
3526 pf.bottom = df.bottom = of.bottom = cf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003527 } else {
Dianne Hackborna239c842011-06-01 12:28:20 -07003528 pf.left = mContentLeft;
3529 pf.top = mContentTop;
3530 pf.right = mContentRight;
3531 pf.bottom = mContentBottom;
Dianne Hackborn20d94742014-05-29 18:35:45 -07003532 if (win.isVoiceInteraction()) {
3533 df.left = of.left = cf.left = mVoiceContentLeft;
3534 df.top = of.top = cf.top = mVoiceContentTop;
3535 df.right = of.right = cf.right = mVoiceContentRight;
3536 df.bottom = of.bottom = cf.bottom = mVoiceContentBottom;
3537 } else if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003538 df.left = of.left = cf.left = mDockLeft;
3539 df.top = of.top = cf.top = mDockTop;
3540 df.right = of.right = cf.right = mDockRight;
3541 df.bottom = of.bottom = cf.bottom = mDockBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07003542 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003543 df.left = of.left = cf.left = mContentLeft;
3544 df.top = of.top = cf.top = mContentTop;
3545 df.right = of.right = cf.right = mContentRight;
3546 df.bottom = of.bottom = cf.bottom = mContentBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07003547 }
3548 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3549 vf.left = mCurLeft;
3550 vf.top = mCurTop;
3551 vf.right = mCurRight;
3552 vf.bottom = mCurBottom;
3553 } else {
3554 vf.set(cf);
3555 }
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003556 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003557 }
3558 }
Craig Mautner69b08182012-09-05 13:07:13 -07003559
Craig Mautnerb816bed2013-07-23 10:26:17 -07003560 // TYPE_SYSTEM_ERROR is above the NavigationBar so it can't be allowed to extend over it.
3561 if ((fl & FLAG_LAYOUT_NO_LIMITS) != 0 && attrs.type != TYPE_SYSTEM_ERROR) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003562 df.left = df.top = of.left = of.top = cf.left = cf.top = vf.left = vf.top = -10000;
3563 df.right = df.bottom = of.right = of.bottom = cf.right = cf.bottom
3564 = vf.right = vf.bottom = 10000;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003565 }
3566
Craig Mautnereda67292013-04-28 13:50:14 -07003567 if (DEBUG_LAYOUT) Slog.v(TAG, "Compute frame " + attrs.getTitle()
The Android Open Source Project11267662009-03-18 17:39:47 -07003568 + ": sim=#" + Integer.toHexString(sim)
RoboErik8a2cfc32014-05-16 11:19:38 -07003569 + " attach=" + attached + " type=" + attrs.type
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003570 + String.format(" flags=0x%08x", fl)
The Android Open Source Project11267662009-03-18 17:39:47 -07003571 + " pf=" + pf.toShortString() + " df=" + df.toShortString()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003572 + " of=" + of.toShortString()
John Spurlock46646232013-09-30 22:32:42 -04003573 + " cf=" + cf.toShortString() + " vf=" + vf.toShortString()
Adrian Roosfa104232014-06-20 16:10:14 -07003574 + " dcf=" + dcf.toShortString()
3575 + " sf=" + sf.toShortString());
Craig Mautner69b08182012-09-05 13:07:13 -07003576
Adrian Roosfa104232014-06-20 16:10:14 -07003577 win.computeFrameLw(pf, df, of, cf, vf, dcf, sf);
Craig Mautner69b08182012-09-05 13:07:13 -07003578
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003579 // Dock windows carve out the bottom of the screen, so normal windows
3580 // can't appear underneath them.
Craig Mautner8bd206b2012-10-03 10:32:02 -07003581 if (attrs.type == TYPE_INPUT_METHOD && win.isVisibleOrBehindKeyguardLw()
3582 && !win.getGivenInsetsPendingLw()) {
satok1bc0a492012-04-25 22:47:12 +09003583 setLastInputMethodWindowLw(null, null);
3584 offsetInputMethodWindowLw(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003585 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003586 if (attrs.type == TYPE_VOICE_INTERACTION && win.isVisibleOrBehindKeyguardLw()
3587 && !win.getGivenInsetsPendingLw()) {
3588 offsetVoiceInputWindowLw(win);
3589 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003590 }
3591
satok1bc0a492012-04-25 22:47:12 +09003592 private void offsetInputMethodWindowLw(WindowState win) {
3593 int top = win.getContentFrameLw().top;
3594 top += win.getGivenContentInsetsLw().top;
3595 if (mContentBottom > top) {
3596 mContentBottom = top;
3597 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003598 if (mVoiceContentBottom > top) {
3599 mVoiceContentBottom = top;
3600 }
satok1bc0a492012-04-25 22:47:12 +09003601 top = win.getVisibleFrameLw().top;
3602 top += win.getGivenVisibleInsetsLw().top;
3603 if (mCurBottom > top) {
3604 mCurBottom = top;
3605 }
Craig Mautnereda67292013-04-28 13:50:14 -07003606 if (DEBUG_LAYOUT) Slog.v(TAG, "Input method: mDockBottom="
satok1bc0a492012-04-25 22:47:12 +09003607 + mDockBottom + " mContentBottom="
3608 + mContentBottom + " mCurBottom=" + mCurBottom);
3609 }
3610
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003611 private void offsetVoiceInputWindowLw(WindowState win) {
3612 final int gravity = win.getAttrs().gravity;
3613 switch (gravity&((Gravity.AXIS_PULL_BEFORE|Gravity.AXIS_PULL_AFTER)
3614 << Gravity.AXIS_X_SHIFT)) {
3615 case Gravity.AXIS_PULL_BEFORE<<Gravity.AXIS_X_SHIFT: {
3616 int right = win.getContentFrameLw().right - win.getGivenContentInsetsLw().right;
3617 if (mVoiceContentLeft < right) {
3618 mVoiceContentLeft = right;
3619 }
3620 } break;
3621 case Gravity.AXIS_PULL_AFTER<<Gravity.AXIS_X_SHIFT: {
3622 int left = win.getContentFrameLw().left - win.getGivenContentInsetsLw().left;
3623 if (mVoiceContentRight < left) {
3624 mVoiceContentRight = left;
3625 }
3626 } break;
3627 }
3628 switch (gravity&((Gravity.AXIS_PULL_BEFORE|Gravity.AXIS_PULL_AFTER)
3629 << Gravity.AXIS_Y_SHIFT)) {
3630 case Gravity.AXIS_PULL_BEFORE<<Gravity.AXIS_Y_SHIFT: {
3631 int bottom = win.getContentFrameLw().bottom - win.getGivenContentInsetsLw().bottom;
3632 if (mVoiceContentTop < bottom) {
3633 mVoiceContentTop = bottom;
3634 }
3635 } break;
3636 case Gravity.AXIS_PULL_AFTER<<Gravity.AXIS_Y_SHIFT: {
3637 int top = win.getContentFrameLw().top - win.getGivenContentInsetsLw().top;
3638 if (mVoiceContentBottom < top) {
3639 mVoiceContentBottom = top;
3640 }
3641 } break;
3642 }
3643 }
3644
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003645 /** {@inheritDoc} */
Craig Mautner61ac6bb2012-02-02 17:29:33 -08003646 @Override
3647 public void finishLayoutLw() {
3648 return;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003649 }
3650
3651 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003652 @Override
Craig Mautner39834192012-09-02 07:47:24 -07003653 public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) {
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003654 mTopFullscreenOpaqueWindowState = null;
Craig Mautner2bc789b2014-03-19 19:48:38 -07003655 mAppsToBeHidden.clear();
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003656 mForceStatusBar = false;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003657 mForceStatusBarFromKeyguard = false;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08003658 mForcingShowNavBar = false;
3659 mForcingShowNavBarLayer = -1;
RoboErik8a2cfc32014-05-16 11:19:38 -07003660
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003661 mHideLockScreen = false;
3662 mAllowLockscreenWhenOn = false;
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003663 mDismissKeyguard = DISMISS_KEYGUARD_NONE;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003664 mShowingLockscreen = false;
3665 mShowingDream = false;
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003666 mWinShowWhenLocked = null;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003667 }
3668
3669 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003670 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003671 public void applyPostLayoutPolicyLw(WindowState win, WindowManager.LayoutParams attrs) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07003672 if (DEBUG_LAYOUT) Slog.i(TAG, "Win " + win + ": isVisibleOrBehindKeyguardLw="
3673 + win.isVisibleOrBehindKeyguardLw());
John Spurlockc6d1c602014-01-17 15:22:06 -05003674 final int fl = PolicyControl.getWindowFlags(win, attrs);
John Spurlock414c1f02013-12-04 13:47:36 -05003675 if (mTopFullscreenOpaqueWindowState == null
3676 && win.isVisibleLw() && attrs.type == TYPE_INPUT_METHOD) {
3677 mForcingShowNavBar = true;
3678 mForcingShowNavBarLayer = win.getSurfaceLayer();
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08003679 }
Jorim Jaggiafd4a552014-04-08 15:13:05 +02003680 if (attrs.type == TYPE_STATUS_BAR && (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Jorim Jaggiafd4a552014-04-08 15:13:05 +02003681 mForceStatusBarFromKeyguard = true;
3682 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003683 if (mTopFullscreenOpaqueWindowState == null &&
Dianne Hackborn01b02a72012-01-12 14:05:03 -08003684 win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()) {
John Spurlockc6d1c602014-01-17 15:22:06 -05003685 if ((fl & FLAG_FORCE_NOT_FULLSCREEN) != 0) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003686 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003687 mForceStatusBarFromKeyguard = true;
3688 } else {
3689 mForceStatusBar = true;
3690 }
3691 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003692 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003693 mShowingLockscreen = true;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07003694 }
Craig Mautnerab55e522014-03-03 13:26:03 -08003695 boolean appWindow = attrs.type >= FIRST_APPLICATION_WINDOW
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003696 && attrs.type <= LAST_APPLICATION_WINDOW;
3697 if (attrs.type == TYPE_DREAM) {
Jeff Brownc8018eb2012-10-29 21:33:27 -07003698 // If the lockscreen was showing when the dream started then wait
3699 // for the dream to draw before hiding the lockscreen.
3700 if (!mDreamingLockscreen
3701 || (win.isVisibleLw() && win.hasDrawnLw())) {
3702 mShowingDream = true;
Craig Mautnerab55e522014-03-03 13:26:03 -08003703 appWindow = true;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003704 }
3705 }
Craig Mautnerab55e522014-03-03 13:26:03 -08003706
Craig Mautner00156ec2014-03-06 22:29:02 -08003707 final boolean showWhenLocked = (fl & FLAG_SHOW_WHEN_LOCKED) != 0;
Craig Mautner74ee9382014-04-01 15:20:16 -07003708 final boolean dismissKeyguard = (fl & FLAG_DISMISS_KEYGUARD) != 0;
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003709 final boolean secureKeyguard = isKeyguardSecure();
Craig Mautnerab55e522014-03-03 13:26:03 -08003710 if (appWindow) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003711 if (showWhenLocked || (dismissKeyguard && !secureKeyguard)) {
3712 // Remove any previous windows with the same appToken.
Craig Mautner2bc789b2014-03-19 19:48:38 -07003713 mAppsToBeHidden.remove(win.getAppToken());
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003714 if (mAppsToBeHidden.isEmpty() && showWhenLocked &&
3715 isKeyguardSecureIncludingHidden()) {
3716 mWinShowWhenLocked = win;
3717 mHideLockScreen = true;
3718 mForceStatusBarFromKeyguard = false;
3719 }
Craig Mautner2bc789b2014-03-19 19:48:38 -07003720 } else {
3721 mAppsToBeHidden.add(win.getAppToken());
3722 }
Craig Mautnerab55e522014-03-03 13:26:03 -08003723 if (attrs.x == 0 && attrs.y == 0
3724 && attrs.width == WindowManager.LayoutParams.MATCH_PARENT
3725 && attrs.height == WindowManager.LayoutParams.MATCH_PARENT) {
3726 if (DEBUG_LAYOUT) Slog.v(TAG, "Fullscreen window: " + win);
3727 mTopFullscreenOpaqueWindowState = win;
Craig Mautner2bc789b2014-03-19 19:48:38 -07003728 if (mAppsToBeHidden.isEmpty()) {
Craig Mautnerda09ae32014-03-03 13:26:03 -08003729 if (showWhenLocked) {
3730 if (DEBUG_LAYOUT) Slog.v(TAG,
3731 "Setting mHideLockScreen to true by win " + win);
3732 mHideLockScreen = true;
3733 mForceStatusBarFromKeyguard = false;
3734 }
Craig Mautner4bdab6b2014-04-01 12:05:11 -07003735 if (dismissKeyguard && mDismissKeyguard == DISMISS_KEYGUARD_NONE) {
Craig Mautnerda09ae32014-03-03 13:26:03 -08003736 if (DEBUG_LAYOUT) Slog.v(TAG,
3737 "Setting mDismissKeyguard true by win " + win);
3738 mDismissKeyguard = mWinDismissingKeyguard == win ?
3739 DISMISS_KEYGUARD_CONTINUE : DISMISS_KEYGUARD_START;
3740 mWinDismissingKeyguard = win;
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003741 mForceStatusBarFromKeyguard = mShowingLockscreen && secureKeyguard;
Craig Mautnerda09ae32014-03-03 13:26:03 -08003742 }
Craig Mautnerab55e522014-03-03 13:26:03 -08003743 }
Craig Mautner00156ec2014-03-06 22:29:02 -08003744 if ((fl & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) {
Craig Mautnerab55e522014-03-03 13:26:03 -08003745 mAllowLockscreenWhenOn = true;
3746 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003747 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003748
3749 if (mWinShowWhenLocked != null &&
3750 mWinShowWhenLocked.getAppToken() != win.getAppToken()) {
3751 win.hideLw(false);
3752 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003753 }
3754 }
3755 }
3756
3757 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003758 @Override
Craig Mautner39834192012-09-02 07:47:24 -07003759 public int finishPostLayoutPolicyLw() {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003760 if (mWinShowWhenLocked != null &&
3761 mWinShowWhenLocked != mTopFullscreenOpaqueWindowState) {
3762 // A dialog is dismissing the keyguard. Put the wallpaper behind it and hide the
3763 // fullscreen window.
3764 // TODO: Make sure FLAG_SHOW_WALLPAPER is restored when dialog is dismissed. Or not.
3765 mWinShowWhenLocked.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
3766 mTopFullscreenOpaqueWindowState.hideLw(false);
3767 mTopFullscreenOpaqueWindowState = mWinShowWhenLocked;
3768 }
3769
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003770 int changes = 0;
Joe Onorato93056472010-09-10 10:30:46 -04003771 boolean topIsFullscreen = false;
Daniel Sandlere02d8082010-10-08 15:13:22 -04003772
3773 final WindowManager.LayoutParams lp = (mTopFullscreenOpaqueWindowState != null)
3774 ? mTopFullscreenOpaqueWindowState.getAttrs()
3775 : null;
3776
Jeff Brownc8018eb2012-10-29 21:33:27 -07003777 // If we are not currently showing a dream then remember the current
3778 // lockscreen state. We will use this to determine whether the dream
3779 // started while the lockscreen was showing and remember this state
3780 // while the dream is showing.
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003781 if (!mShowingDream) {
3782 mDreamingLockscreen = mShowingLockscreen;
3783 }
3784
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003785 if (mStatusBar != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07003786 if (DEBUG_LAYOUT) Slog.i(TAG, "force=" + mForceStatusBar
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003787 + " forcefkg=" + mForceStatusBarFromKeyguard
Dianne Hackbornd70bc2f2009-10-06 23:25:51 -07003788 + " top=" + mTopFullscreenOpaqueWindowState);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003789 if (mForceStatusBar || mForceStatusBarFromKeyguard) {
Craig Mautnereda67292013-04-28 13:50:14 -07003790 if (DEBUG_LAYOUT) Slog.v(TAG, "Showing status bar: forced");
John Spurlock27735a42013-08-14 17:57:38 -04003791 if (mStatusBarController.setBarShowingLw(true)) {
3792 changes |= FINISH_LAYOUT_REDO_LAYOUT;
3793 }
Craig Mautner81defc72013-10-29 11:10:42 -07003794 // Maintain fullscreen layout until incoming animation is complete.
3795 topIsFullscreen = mTopIsFullscreen && mStatusBar.isAnimatingLw();
John Spurlockf92b6162013-11-11 15:01:16 -05003796 // Transient status bar on the lockscreen is not allowed
3797 if (mForceStatusBarFromKeyguard && mStatusBarController.isTransientShowing()) {
3798 mStatusBarController.updateVisibilityLw(false /*transientAllowed*/,
3799 mLastSystemUiFlags, mLastSystemUiFlags);
3800 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003801 } else if (mTopFullscreenOpaqueWindowState != null) {
John Spurlockc6d1c602014-01-17 15:22:06 -05003802 final int fl = PolicyControl.getWindowFlags(null, lp);
Joe Onorato93056472010-09-10 10:30:46 -04003803 if (localLOGV) {
Craig Mautnereda67292013-04-28 13:50:14 -07003804 Slog.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw()
Joe Onorato93056472010-09-10 10:30:46 -04003805 + " shown frame: " + mTopFullscreenOpaqueWindowState.getShownFrameLw());
Craig Mautnereda67292013-04-28 13:50:14 -07003806 Slog.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs()
John Spurlockc6d1c602014-01-17 15:22:06 -05003807 + " lp.flags=0x" + Integer.toHexString(fl));
Joe Onorato93056472010-09-10 10:30:46 -04003808 }
John Spurlockc6d1c602014-01-17 15:22:06 -05003809 topIsFullscreen = (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003810 || (mLastSystemUiFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
Joe Onorato93056472010-09-10 10:30:46 -04003811 // The subtle difference between the window for mTopFullscreenOpaqueWindowState
3812 // and mTopIsFullscreen is that that mTopIsFullscreen is set only if the window
3813 // has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the
3814 // case though.
John Spurlock27735a42013-08-14 17:57:38 -04003815 if (mStatusBarController.isTransientShowing()) {
3816 if (mStatusBarController.setBarShowingLw(true)) {
John Spurlock32beb2c2013-03-11 10:16:47 -04003817 changes |= FINISH_LAYOUT_REDO_LAYOUT;
3818 }
3819 } else if (topIsFullscreen) {
Craig Mautnereda67292013-04-28 13:50:14 -07003820 if (DEBUG_LAYOUT) Slog.v(TAG, "** HIDING status bar");
John Spurlock27735a42013-08-14 17:57:38 -04003821 if (mStatusBarController.setBarShowingLw(false)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003822 changes |= FINISH_LAYOUT_REDO_LAYOUT;
Craig Mautnereda67292013-04-28 13:50:14 -07003823 } else {
Craig Mautnerc5a6e442013-06-05 17:22:35 -07003824 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar already hiding");
Daniel Sandler40427442010-07-16 11:44:52 -04003825 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003826 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07003827 if (DEBUG_LAYOUT) Slog.v(TAG, "** SHOWING status bar: top is not fullscreen");
John Spurlock27735a42013-08-14 17:57:38 -04003828 if (mStatusBarController.setBarShowingLw(true)) {
3829 changes |= FINISH_LAYOUT_REDO_LAYOUT;
3830 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003831 }
3832 }
3833 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04003834
Craig Mautner81defc72013-10-29 11:10:42 -07003835 if (mTopIsFullscreen != topIsFullscreen) {
3836 if (!topIsFullscreen) {
3837 // Force another layout when status bar becomes fully shown.
3838 changes |= FINISH_LAYOUT_REDO_LAYOUT;
3839 }
3840 mTopIsFullscreen = topIsFullscreen;
3841 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04003842
Craig Mautner39834192012-09-02 07:47:24 -07003843 // Hide the key guard if a visible window explicitly specifies that it wants to be
3844 // displayed when the screen is locked.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01003845 if (mKeyguardDelegate != null && mStatusBar != null) {
3846 if (localLOGV) Slog.v(TAG, "finishPostLayoutPolicyLw: mHideKeyguard="
3847 + mHideLockScreen);
3848 if (mDismissKeyguard != DISMISS_KEYGUARD_NONE && !isKeyguardSecure()) {
3849 mKeyguardHidden = true;
3850 if (processKeyguardSetHiddenResultLw(mKeyguardDelegate.setOccluded(true))) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003851 changes |= FINISH_LAYOUT_REDO_LAYOUT
3852 | FINISH_LAYOUT_REDO_CONFIG
3853 | FINISH_LAYOUT_REDO_WALLPAPER;
3854 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01003855 if (mKeyguardDelegate.isShowing()) {
3856 mHandler.post(new Runnable() {
3857 @Override
3858 public void run() {
3859 mKeyguardDelegate.keyguardDone(false, false);
3860 }
3861 });
3862 }
3863 } else if (mHideLockScreen) {
3864 mKeyguardHidden = true;
3865 if (processKeyguardSetHiddenResultLw(mKeyguardDelegate.setOccluded(true))) {
3866 changes |= FINISH_LAYOUT_REDO_LAYOUT
3867 | FINISH_LAYOUT_REDO_CONFIG
3868 | FINISH_LAYOUT_REDO_WALLPAPER;
3869 }
3870 } else if (mDismissKeyguard != DISMISS_KEYGUARD_NONE) {
3871 // This is the case of keyguard isSecure() and not mHideLockScreen.
3872 if (mDismissKeyguard == DISMISS_KEYGUARD_START) {
3873 // Only launch the next keyguard unlock window once per window.
3874 mKeyguardHidden = false;
3875 if (processKeyguardSetHiddenResultLw(mKeyguardDelegate.setOccluded(false))) {
3876 changes |= FINISH_LAYOUT_REDO_LAYOUT
3877 | FINISH_LAYOUT_REDO_CONFIG
3878 | FINISH_LAYOUT_REDO_WALLPAPER;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003879 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01003880 mHandler.post(new Runnable() {
3881 @Override
3882 public void run() {
3883 mKeyguardDelegate.dismiss();
3884 }
3885 });
3886 }
3887 } else {
3888 mWinDismissingKeyguard = null;
3889 mKeyguardHidden = false;
3890 if (processKeyguardSetHiddenResultLw(mKeyguardDelegate.setOccluded(false))) {
3891 changes |= FINISH_LAYOUT_REDO_LAYOUT
3892 | FINISH_LAYOUT_REDO_CONFIG
3893 | FINISH_LAYOUT_REDO_WALLPAPER;
3894 }
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -07003895 }
3896 }
Joe Onorato664644d2011-01-23 17:53:23 -08003897
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003898 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003899 // If the navigation bar has been hidden or shown, we need to do another
3900 // layout pass to update that window.
3901 changes |= FINISH_LAYOUT_REDO_LAYOUT;
3902 }
Joe Onorato664644d2011-01-23 17:53:23 -08003903
Mike Lockwood28569302010-01-28 11:54:40 -05003904 // update since mAllowLockscreenWhenOn might have changed
3905 updateLockScreenTimeout();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003906 return changes;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003907 }
3908
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003909 /**
Jorim Jaggi5cf17872014-03-26 18:31:48 +01003910 * Processes the result code of {@link IKeyguardService#setOccluded}. This is needed because we
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003911 * immediately need to put the wallpaper directly behind the Keyguard when a window with flag
3912 * {@link android.view.WindowManager.LayoutParams#FLAG_SHOW_WHEN_LOCKED} gets dismissed. If we
3913 * would wait for Keyguard to change the flags, that would be running asynchronously and thus be
3914 * too late so the user might see the window behind.
3915 *
Jorim Jaggi5cf17872014-03-26 18:31:48 +01003916 * @param setHiddenResult The result code from {@link IKeyguardService#setOccluded}.
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003917 * @return Whether the flags have changed and we have to redo the layout.
3918 */
3919 private boolean processKeyguardSetHiddenResultLw(int setHiddenResult) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01003920 if (setHiddenResult
3921 == IKeyguardServiceConstants.KEYGUARD_SERVICE_SET_OCCLUDED_RESULT_SET_FLAGS) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003922 mStatusBar.getAttrs().privateFlags |= PRIVATE_FLAG_KEYGUARD;
3923 mStatusBar.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
3924 return true;
3925 } else if (setHiddenResult
Jorim Jaggi5cf17872014-03-26 18:31:48 +01003926 == IKeyguardServiceConstants.KEYGUARD_SERVICE_SET_OCCLUDED_RESULT_UNSET_FLAGS) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003927 mStatusBar.getAttrs().privateFlags &= ~PRIVATE_FLAG_KEYGUARD;
3928 mStatusBar.getAttrs().flags &= ~FLAG_SHOW_WALLPAPER;
3929 return true;
3930 } else {
3931 return false;
3932 }
3933 }
3934
3935 private boolean isStatusBarKeyguard() {
3936 return mStatusBar != null
3937 && (mStatusBar.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
3938 }
3939
Jose Lima9546b202014-07-02 17:21:51 -07003940 @Override
Dianne Hackborn08743722009-12-21 12:16:51 -08003941 public boolean allowAppAnimationsLw() {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003942 if (isStatusBarKeyguard() || mShowingDream) {
Craig Mautner28816302013-10-10 20:31:00 -07003943 // If keyguard or dreams is currently visible, no reason to animate behind it.
Dianne Hackborn08743722009-12-21 12:16:51 -08003944 return false;
3945 }
Dianne Hackborn08743722009-12-21 12:16:51 -08003946 return true;
3947 }
3948
Jose Lima9546b202014-07-02 17:21:51 -07003949 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07003950 public int focusChangedLw(WindowState lastFocus, WindowState newFocus) {
Joe Onorato664644d2011-01-23 17:53:23 -08003951 mFocusedWindow = newFocus;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003952 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003953 // If the navigation bar has been hidden or shown, we need to do another
3954 // layout pass to update that window.
3955 return FINISH_LAYOUT_REDO_LAYOUT;
3956 }
3957 return 0;
Joe Onorato664644d2011-01-23 17:53:23 -08003958 }
3959
Dianne Hackborn0ecadf72009-03-31 18:00:37 -07003960 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07003961 @Override
Jeff Brown46b9ac02010-04-22 18:58:52 -07003962 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
3963 // lid changed state
Jeff Brownc458ce92012-04-30 14:58:40 -07003964 final int newLidState = lidOpen ? LID_OPEN : LID_CLOSED;
3965 if (newLidState == mLidState) {
3966 return;
3967 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07003968
Jeff Brownc458ce92012-04-30 14:58:40 -07003969 mLidState = newLidState;
3970 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07003971 updateRotation(true);
Jeff Brownc458ce92012-04-30 14:58:40 -07003972
3973 if (lidOpen) {
Jim Millere51cf7ae2013-06-25 18:31:56 -07003974 mPowerManager.wakeUp(SystemClock.uptimeMillis());
Jeff Brownc458ce92012-04-30 14:58:40 -07003975 } else if (!mLidControlsSleep) {
Jeff Brown96307042012-07-27 15:51:34 -07003976 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
Jeff Brown46b9ac02010-04-22 18:58:52 -07003977 }
3978 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003979
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08003980 void setHdmiPlugged(boolean plugged) {
3981 if (mHdmiPlugged != plugged) {
3982 mHdmiPlugged = plugged;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003983 updateRotation(true, true);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08003984 Intent intent = new Intent(ACTION_HDMI_PLUGGED);
Joe Onoratodc100302011-01-11 17:07:41 -08003985 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08003986 intent.putExtra(EXTRA_HDMI_PLUGGED_STATE, plugged);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07003987 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08003988 }
3989 }
3990
Joe Onoratoea495d42011-04-06 11:41:11 -07003991 void initializeHdmiState() {
Joe Onorato7ba631f2011-05-04 15:28:00 -07003992 boolean plugged = false;
Joe Onoratoea495d42011-04-06 11:41:11 -07003993 // watch for HDMI plug messages if the hdmi switch exists
3994 if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) {
3995 mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi");
3996
Joe Onoratoea495d42011-04-06 11:41:11 -07003997 final String filename = "/sys/class/switch/hdmi/state";
3998 FileReader reader = null;
3999 try {
4000 reader = new FileReader(filename);
4001 char[] buf = new char[15];
4002 int n = reader.read(buf);
4003 if (n > 1) {
4004 plugged = 0 != Integer.parseInt(new String(buf, 0, n-1));
4005 }
4006 } catch (IOException ex) {
4007 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
4008 } catch (NumberFormatException ex) {
4009 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
4010 } finally {
4011 if (reader != null) {
4012 try {
4013 reader.close();
4014 } catch (IOException ex) {
4015 }
Joe Onoratodc100302011-01-11 17:07:41 -08004016 }
4017 }
4018 }
Joe Onorato7ba631f2011-05-04 15:28:00 -07004019 // This dance forces the code in setHdmiPlugged to run.
4020 // Always do this so the sticky intent is stuck (to false) if there is no hdmi.
4021 mHdmiPlugged = !plugged;
4022 setHdmiPlugged(!mHdmiPlugged);
Joe Onoratodc100302011-01-11 17:07:41 -08004023 }
4024
Dianne Hackbornc0e3f242011-08-19 14:19:10 -07004025 final Object mScreenshotLock = new Object();
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004026 ServiceConnection mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004027
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004028 final Runnable mScreenshotTimeout = new Runnable() {
4029 @Override public void run() {
4030 synchronized (mScreenshotLock) {
4031 if (mScreenshotConnection != null) {
4032 mContext.unbindService(mScreenshotConnection);
4033 mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004034 }
Winson Chung9112ec32011-06-27 13:15:32 -07004035 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004036 }
4037 };
4038
4039 // Assume this is called from the Handler thread.
4040 private void takeScreenshot() {
4041 synchronized (mScreenshotLock) {
4042 if (mScreenshotConnection != null) {
4043 return;
4044 }
4045 ComponentName cn = new ComponentName("com.android.systemui",
4046 "com.android.systemui.screenshot.TakeScreenshotService");
4047 Intent intent = new Intent();
4048 intent.setComponent(cn);
4049 ServiceConnection conn = new ServiceConnection() {
4050 @Override
4051 public void onServiceConnected(ComponentName name, IBinder service) {
4052 synchronized (mScreenshotLock) {
4053 if (mScreenshotConnection != this) {
4054 return;
4055 }
4056 Messenger messenger = new Messenger(service);
4057 Message msg = Message.obtain(null, 1);
4058 final ServiceConnection myConn = this;
4059 Handler h = new Handler(mHandler.getLooper()) {
4060 @Override
4061 public void handleMessage(Message msg) {
4062 synchronized (mScreenshotLock) {
4063 if (mScreenshotConnection == myConn) {
4064 mContext.unbindService(mScreenshotConnection);
4065 mScreenshotConnection = null;
4066 mHandler.removeCallbacks(mScreenshotTimeout);
4067 }
4068 }
4069 }
4070 };
4071 msg.replyTo = new Messenger(h);
Winson Chunga63bb842011-10-17 10:26:28 -07004072 msg.arg1 = msg.arg2 = 0;
4073 if (mStatusBar != null && mStatusBar.isVisibleLw())
4074 msg.arg1 = 1;
4075 if (mNavigationBar != null && mNavigationBar.isVisibleLw())
4076 msg.arg2 = 1;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004077 try {
4078 messenger.send(msg);
4079 } catch (RemoteException e) {
4080 }
4081 }
4082 }
4083 @Override
4084 public void onServiceDisconnected(ComponentName name) {}
4085 };
Amith Yamasani27b89e62013-01-16 12:30:11 -08004086 if (mContext.bindServiceAsUser(
4087 intent, conn, Context.BIND_AUTO_CREATE, UserHandle.CURRENT)) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004088 mScreenshotConnection = conn;
4089 mHandler.postDelayed(mScreenshotTimeout, 10000);
4090 }
4091 }
Winson Chung9112ec32011-06-27 13:15:32 -07004092 }
4093
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004094 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004095 @Override
Jeff Brown037c33e2014-04-09 00:31:55 -07004096 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) {
Jeff Brown96307042012-07-27 15:51:34 -07004097 if (!mSystemBooted) {
4098 // If we have not yet booted, don't let key events do anything.
4099 return 0;
4100 }
4101
Jeff Brown037c33e2014-04-09 00:31:55 -07004102 final boolean interactive = (policyFlags & FLAG_INTERACTIVE) != 0;
Jeff Brown1f245102010-11-18 20:53:46 -08004103 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
4104 final boolean canceled = event.isCanceled();
4105 final int keyCode = event.getKeyCode();
Jeff Browne20c9e02010-10-11 14:20:19 -07004106
Jeff Brown3122e442010-10-11 23:32:49 -07004107 final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0;
Jeff Brown3122e442010-10-11 23:32:49 -07004108
Mike Lockwoodc72b15f2009-11-28 20:58:22 -05004109 // If screen is off then we treat the case where the keyguard is open but hidden
4110 // the same as if it were open and in front.
4111 // This will prevent any keys other than the power button from waking the screen
4112 // when the keyguard is hidden by another activity.
Jim Miller5ecd8112013-01-09 18:50:26 -08004113 final boolean keyguardActive = (mKeyguardDelegate == null ? false :
Jeff Brown037c33e2014-04-09 00:31:55 -07004114 (interactive ?
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004115 mKeyguardDelegate.isShowingAndNotOccluded() :
Jim Miller5ecd8112013-01-09 18:50:26 -08004116 mKeyguardDelegate.isShowing()));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004117
Jeff Brown40013652012-05-16 21:22:36 -07004118 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004119 Log.d(TAG, "interceptKeyTq keycode=" + keyCode
Jeff Brown037c33e2014-04-09 00:31:55 -07004120 + " interactive=" + interactive + " keyguardActive=" + keyguardActive
Jeff Brown26875502014-01-30 21:47:47 -08004121 + " policyFlags=" + Integer.toHexString(policyFlags));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004122 }
4123
Jeff Brown037c33e2014-04-09 00:31:55 -07004124 // Basic policy based on interactive state.
Jeff Brown4d396052010-10-29 21:50:21 -07004125 int result;
Michael Wright337d9d22014-04-22 15:03:48 -07004126 boolean isWakeKey = (policyFlags & WindowManagerPolicy.FLAG_WAKE) != 0
4127 || event.isWakeKey();
Jeff Brown037c33e2014-04-09 00:31:55 -07004128 if (interactive || (isInjected && !isWakeKey)) {
Jeff Brown4d396052010-10-29 21:50:21 -07004129 // When the screen is on or if the key is injected pass the key to the application.
4130 result = ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07004131 isWakeKey = false;
Jeff Brown4d396052010-10-29 21:50:21 -07004132 } else {
4133 // When the screen is off and the key is not injected, determine whether
4134 // to wake the device but don't pass the key to the application.
4135 result = 0;
Jeff Brown26875502014-01-30 21:47:47 -08004136 if (isWakeKey && (!down || !isWakeKeyWhenScreenOff(keyCode))) {
4137 isWakeKey = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004138 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004139 }
4140
Justin Kohd378ad72013-04-01 12:18:26 -07004141 // If the key would be handled globally, just return the result, don't worry about special
4142 // key processing.
4143 if (mGlobalKeyManager.shouldHandleGlobalKey(keyCode, event)) {
Michael Wright85b1af62014-06-04 14:51:58 -07004144 if (isWakeKey) {
4145 mPowerManager.wakeUp(event.getEventTime());
4146 }
Justin Kohd378ad72013-04-01 12:18:26 -07004147 return result;
4148 }
4149
Jeff Brownbae8e772014-06-12 19:59:45 -07004150 boolean useHapticFeedback = down
4151 && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0
4152 && event.getRepeatCount() == 0;
4153
Jeff Brown4d396052010-10-29 21:50:21 -07004154 // Handle special keys.
4155 switch (keyCode) {
4156 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jeff Brownb0418da2010-11-01 15:24:01 -07004157 case KeyEvent.KEYCODE_VOLUME_UP:
4158 case KeyEvent.KEYCODE_VOLUME_MUTE: {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004159 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
4160 if (down) {
Jeff Brown037c33e2014-04-09 00:31:55 -07004161 if (interactive && !mVolumeDownKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004162 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
4163 mVolumeDownKeyTriggered = true;
4164 mVolumeDownKeyTime = event.getDownTime();
4165 mVolumeDownKeyConsumedByScreenshotChord = false;
4166 cancelPendingPowerKeyAction();
4167 interceptScreenshotChord();
4168 }
4169 } else {
4170 mVolumeDownKeyTriggered = false;
4171 cancelPendingScreenshotChordAction();
4172 }
4173 } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
4174 if (down) {
Jeff Brown037c33e2014-04-09 00:31:55 -07004175 if (interactive && !mVolumeUpKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004176 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
4177 mVolumeUpKeyTriggered = true;
4178 cancelPendingPowerKeyAction();
4179 cancelPendingScreenshotChordAction();
4180 }
4181 } else {
4182 mVolumeUpKeyTriggered = false;
4183 cancelPendingScreenshotChordAction();
4184 }
4185 }
Jeff Brown4d396052010-10-29 21:50:21 -07004186 if (down) {
Santos Cordon9eb45932014-06-27 12:28:43 -07004187 TelecommManager telecommManager = getTelecommService();
4188 if (telecommManager != null) {
4189 if (telecommManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07004190 // If an incoming call is ringing, either VOLUME key means
4191 // "silence ringer". We handle these keys here, rather than
4192 // in the InCallScreen, to make sure we'll respond to them
4193 // even if the InCallScreen hasn't come to the foreground yet.
4194 // Look for the DOWN event here, to agree with the "fallback"
4195 // behavior in the InCallScreen.
4196 Log.i(TAG, "interceptKeyBeforeQueueing:"
4197 + " VOLUME key-down while ringing: Silence ringer!");
Jeff Brown4d396052010-10-29 21:50:21 -07004198
Santos Cordon6848f722014-05-21 15:22:12 -07004199 // Silence the ringer. (It's safe to call this
4200 // even if the ringer has already been silenced.)
Santos Cordon9eb45932014-06-27 12:28:43 -07004201 telecommManager.silenceRinger();
Jeff Brown4d396052010-10-29 21:50:21 -07004202
Santos Cordon6848f722014-05-21 15:22:12 -07004203 // And *don't* pass this key thru to the current activity
4204 // (which is probably the InCallScreen.)
4205 result &= ~ACTION_PASS_TO_USER;
4206 break;
4207 }
Santos Cordon9eb45932014-06-27 12:28:43 -07004208 if (telecommManager.isInAPhoneCall()
Santos Cordon6848f722014-05-21 15:22:12 -07004209 && (result & ACTION_PASS_TO_USER) == 0) {
4210 // If we are in call but we decided not to pass the key to
RoboErik430fc482014-06-12 15:49:20 -07004211 // the application, just pass it to the session service.
4212
4213 MediaSessionLegacyHelper.getHelper(mContext)
RoboErik3c45c292014-07-08 16:47:31 -07004214 .sendVolumeKeyEvent(event, false);
Santos Cordon6848f722014-05-21 15:22:12 -07004215 break;
Jeff Brown4d396052010-10-29 21:50:21 -07004216 }
4217 }
4218
RoboErik430fc482014-06-12 15:49:20 -07004219 if ((result & ACTION_PASS_TO_USER) == 0) {
4220 // If we aren't passing to the user and no one else
4221 // handled it send it to the session manager to figure
4222 // out.
4223 MediaSessionLegacyHelper.getHelper(mContext)
RoboErik3c45c292014-07-08 16:47:31 -07004224 .sendVolumeKeyEvent(event, true);
Jeff Brown4d396052010-10-29 21:50:21 -07004225 break;
4226 }
4227 }
4228 break;
4229 }
4230
4231 case KeyEvent.KEYCODE_ENDCALL: {
4232 result &= ~ACTION_PASS_TO_USER;
4233 if (down) {
Santos Cordon9eb45932014-06-27 12:28:43 -07004234 TelecommManager telecommManager = getTelecommService();
Jeff Brown4d396052010-10-29 21:50:21 -07004235 boolean hungUp = false;
Santos Cordon9eb45932014-06-27 12:28:43 -07004236 if (telecommManager != null) {
4237 hungUp = telecommManager.endCall();
Jeff Brown4d396052010-10-29 21:50:21 -07004238 }
Jeff Brown037c33e2014-04-09 00:31:55 -07004239 interceptPowerKeyDown(!interactive || hungUp);
Jeff Brown4d396052010-10-29 21:50:21 -07004240 } else {
4241 if (interceptPowerKeyUp(canceled)) {
4242 if ((mEndcallBehavior
4243 & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) {
4244 if (goHome()) {
4245 break;
Dianne Hackborn0041e972009-07-24 17:14:43 -07004246 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004247 }
Jeff Brown4d396052010-10-29 21:50:21 -07004248 if ((mEndcallBehavior
4249 & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) {
Jeff Brown26875502014-01-30 21:47:47 -08004250 mPowerManager.goToSleep(event.getEventTime());
4251 isWakeKey = false;
Jeff Brown4d396052010-10-29 21:50:21 -07004252 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004253 }
Jeff Brown4d396052010-10-29 21:50:21 -07004254 }
4255 break;
4256 }
4257
4258 case KeyEvent.KEYCODE_POWER: {
4259 result &= ~ACTION_PASS_TO_USER;
4260 if (down) {
Jeff Brown26c6a502014-04-11 02:15:54 -07004261 boolean panic = mImmersiveModeConfirmation.onPowerKeyDown(interactive,
John Spurlockd9b70bd2014-02-06 17:02:44 -05004262 event.getDownTime(), isImmersiveMode(mLastSystemUiFlags));
4263 if (panic) {
4264 mHandler.post(mRequestTransientNav);
4265 }
Jeff Brown037c33e2014-04-09 00:31:55 -07004266 if (interactive && !mPowerKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004267 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
4268 mPowerKeyTriggered = true;
4269 mPowerKeyTime = event.getDownTime();
4270 interceptScreenshotChord();
Winson Chung9112ec32011-06-27 13:15:32 -07004271 }
Winson Chung9112ec32011-06-27 13:15:32 -07004272
Santos Cordon9eb45932014-06-27 12:28:43 -07004273 TelecommManager telecommManager = getTelecommService();
Jeff Brown4d396052010-10-29 21:50:21 -07004274 boolean hungUp = false;
Santos Cordon9eb45932014-06-27 12:28:43 -07004275 if (telecommManager != null) {
4276 if (telecommManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07004277 // Pressing Power while there's a ringing incoming
4278 // call should silence the ringer.
Santos Cordon9eb45932014-06-27 12:28:43 -07004279 telecommManager.silenceRinger();
Santos Cordon6848f722014-05-21 15:22:12 -07004280 } else if ((mIncallPowerBehavior
4281 & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0
Santos Cordon9eb45932014-06-27 12:28:43 -07004282 && telecommManager.isInAPhoneCall() && interactive) {
Santos Cordon6848f722014-05-21 15:22:12 -07004283 // Otherwise, if "Power button ends call" is enabled,
4284 // the Power button will hang up any current active call.
Santos Cordon9eb45932014-06-27 12:28:43 -07004285 hungUp = telecommManager.endCall();
Jeff Brown4d396052010-10-29 21:50:21 -07004286 }
4287 }
Jeff Brown037c33e2014-04-09 00:31:55 -07004288 interceptPowerKeyDown(!interactive || hungUp
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004289 || mVolumeDownKeyTriggered || mVolumeUpKeyTriggered);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004290 } else {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004291 mPowerKeyTriggered = false;
4292 cancelPendingScreenshotChordAction();
4293 if (interceptPowerKeyUp(canceled || mPendingPowerKeyUpCanceled)) {
Jeff Brown6d8fd272014-05-20 21:24:38 -07004294 powerShortPress(event.getEventTime());
Jeff Brown26875502014-01-30 21:47:47 -08004295 isWakeKey = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004296 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004297 mPendingPowerKeyUpCanceled = false;
Jeff Brown4d396052010-10-29 21:50:21 -07004298 }
4299 break;
4300 }
4301
Jeff Brown6212a492014-03-07 13:58:47 -08004302 case KeyEvent.KEYCODE_SLEEP: {
4303 result &= ~ACTION_PASS_TO_USER;
Jeff Brownbae8e772014-06-12 19:59:45 -07004304 if (!mPowerManager.isInteractive()) {
4305 useHapticFeedback = false; // suppress feedback if already non-interactive
4306 }
Jeff Brown6212a492014-03-07 13:58:47 -08004307 mPowerManager.goToSleep(event.getEventTime());
4308 isWakeKey = false;
4309 break;
4310 }
4311
4312 case KeyEvent.KEYCODE_WAKEUP: {
4313 result &= ~ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07004314 isWakeKey = true;
Jeff Brown6212a492014-03-07 13:58:47 -08004315 break;
4316 }
4317
Jeff Brown4d396052010-10-29 21:50:21 -07004318 case KeyEvent.KEYCODE_MEDIA_PLAY:
4319 case KeyEvent.KEYCODE_MEDIA_PAUSE:
4320 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
4321 if (down) {
Santos Cordon9eb45932014-06-27 12:28:43 -07004322 TelecommManager telecommManager = getTelecommService();
4323 if (telecommManager != null) {
4324 if (telecommManager.isInAPhoneCall()) {
Santos Cordon6848f722014-05-21 15:22:12 -07004325 // Suppress PLAY/PAUSE toggle when phone is ringing or in-call
4326 // to avoid music playback.
4327 break;
Jeff Brown3122e442010-10-11 23:32:49 -07004328 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004329 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004330 }
Jeff Brown4d396052010-10-29 21:50:21 -07004331 case KeyEvent.KEYCODE_HEADSETHOOK:
4332 case KeyEvent.KEYCODE_MUTE:
4333 case KeyEvent.KEYCODE_MEDIA_STOP:
4334 case KeyEvent.KEYCODE_MEDIA_NEXT:
4335 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
4336 case KeyEvent.KEYCODE_MEDIA_REWIND:
4337 case KeyEvent.KEYCODE_MEDIA_RECORD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09004338 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
4339 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: {
Jeff Brown4d396052010-10-29 21:50:21 -07004340 if ((result & ACTION_PASS_TO_USER) == 0) {
4341 // Only do this if we would otherwise not pass it to the user. In that
4342 // case, the PhoneWindow class will do the same thing, except it will
4343 // only do it if the showing app doesn't process the key on its own.
Jeff Brown40013652012-05-16 21:22:36 -07004344 // Note that we need to make a copy of the key event here because the
4345 // original key event will be recycled when we return.
Jeff Brown4d396052010-10-29 21:50:21 -07004346 mBroadcastWakeLock.acquire();
Jeff Brown40013652012-05-16 21:22:36 -07004347 Message msg = mHandler.obtainMessage(MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK,
4348 new KeyEvent(event));
4349 msg.setAsynchronous(true);
4350 msg.sendToTarget();
Jeff Brown4d396052010-10-29 21:50:21 -07004351 }
4352 break;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004353 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004354
Jeff Brown4d396052010-10-29 21:50:21 -07004355 case KeyEvent.KEYCODE_CALL: {
4356 if (down) {
Santos Cordon9eb45932014-06-27 12:28:43 -07004357 TelecommManager telecommManager = getTelecommService();
4358 if (telecommManager != null) {
4359 if (telecommManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07004360 Log.i(TAG, "interceptKeyBeforeQueueing:"
4361 + " CALL key-down while ringing: Answer the call!");
Santos Cordon9eb45932014-06-27 12:28:43 -07004362 telecommManager.acceptRingingCall();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004363
Santos Cordon6848f722014-05-21 15:22:12 -07004364 // And *don't* pass this key thru to the current activity
4365 // (which is presumably the InCallScreen.)
4366 result &= ~ACTION_PASS_TO_USER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004367 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004368 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004369 }
Jeff Brown4d396052010-10-29 21:50:21 -07004370 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004371 }
4372 }
Jeff Brown26875502014-01-30 21:47:47 -08004373
Jeff Brownbae8e772014-06-12 19:59:45 -07004374 if (useHapticFeedback) {
4375 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
4376 }
4377
Jeff Brown26875502014-01-30 21:47:47 -08004378 if (isWakeKey) {
4379 mPowerManager.wakeUp(event.getEventTime());
4380 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004381 return result;
4382 }
4383
Jeff Brown1c2e4942012-11-06 16:32:01 -08004384 /**
4385 * When the screen is off we ignore some keys that might otherwise typically
4386 * be considered wake keys. We filter them out here.
4387 *
4388 * {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it
4389 * is always considered a wake key.
4390 */
4391 private boolean isWakeKeyWhenScreenOff(int keyCode) {
4392 switch (keyCode) {
4393 // ignore volume keys unless docked
4394 case KeyEvent.KEYCODE_VOLUME_UP:
4395 case KeyEvent.KEYCODE_VOLUME_DOWN:
4396 case KeyEvent.KEYCODE_VOLUME_MUTE:
4397 return mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED;
4398
4399 // ignore media and camera keys
4400 case KeyEvent.KEYCODE_MUTE:
4401 case KeyEvent.KEYCODE_HEADSETHOOK:
4402 case KeyEvent.KEYCODE_MEDIA_PLAY:
4403 case KeyEvent.KEYCODE_MEDIA_PAUSE:
4404 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
4405 case KeyEvent.KEYCODE_MEDIA_STOP:
4406 case KeyEvent.KEYCODE_MEDIA_NEXT:
4407 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
4408 case KeyEvent.KEYCODE_MEDIA_REWIND:
4409 case KeyEvent.KEYCODE_MEDIA_RECORD:
4410 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09004411 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK:
Jeff Brown1c2e4942012-11-06 16:32:01 -08004412 case KeyEvent.KEYCODE_CAMERA:
4413 return false;
4414 }
4415 return true;
4416 }
4417
4418
Jeff Brown56194eb2011-03-02 19:23:13 -08004419 /** {@inheritDoc} */
4420 @Override
Jeff Brown037c33e2014-04-09 00:31:55 -07004421 public int interceptWakeMotionBeforeQueueing(long whenNanos, int policyFlags) {
4422 // We already know this is a wake motion so just wake up.
4423 // Note that we would observe policyFlags containing
4424 // FLAG_WAKE and FLAG_INTERACTIVE here.
4425 mPowerManager.wakeUp(whenNanos / 1000000);
4426 return 0;
Jeff Brown56194eb2011-03-02 19:23:13 -08004427 }
4428
Jeff Brown40013652012-05-16 21:22:36 -07004429 void dispatchMediaKeyWithWakeLock(KeyEvent event) {
4430 if (DEBUG_INPUT) {
4431 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: " + event);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004432 }
4433
Jeff Brown40013652012-05-16 21:22:36 -07004434 if (mHavePendingMediaKeyRepeatWithWakeLock) {
4435 if (DEBUG_INPUT) {
4436 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: canceled repeat");
4437 }
4438
4439 mHandler.removeMessages(MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK);
4440 mHavePendingMediaKeyRepeatWithWakeLock = false;
4441 mBroadcastWakeLock.release(); // pending repeat was holding onto the wake lock
4442 }
4443
4444 dispatchMediaKeyWithWakeLockToAudioService(event);
4445
4446 if (event.getAction() == KeyEvent.ACTION_DOWN
4447 && event.getRepeatCount() == 0) {
4448 mHavePendingMediaKeyRepeatWithWakeLock = true;
4449
4450 Message msg = mHandler.obtainMessage(
4451 MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK, event);
4452 msg.setAsynchronous(true);
4453 mHandler.sendMessageDelayed(msg, ViewConfiguration.getKeyRepeatTimeout());
4454 } else {
4455 mBroadcastWakeLock.release();
4456 }
4457 }
4458
4459 void dispatchMediaKeyRepeatWithWakeLock(KeyEvent event) {
4460 mHavePendingMediaKeyRepeatWithWakeLock = false;
4461
4462 KeyEvent repeatEvent = KeyEvent.changeTimeRepeat(event,
4463 SystemClock.uptimeMillis(), 1, event.getFlags() | KeyEvent.FLAG_LONG_PRESS);
4464 if (DEBUG_INPUT) {
4465 Slog.d(TAG, "dispatchMediaKeyRepeatWithWakeLock: " + repeatEvent);
4466 }
4467
4468 dispatchMediaKeyWithWakeLockToAudioService(repeatEvent);
4469 mBroadcastWakeLock.release();
4470 }
4471
4472 void dispatchMediaKeyWithWakeLockToAudioService(KeyEvent event) {
4473 if (ActivityManagerNative.isSystemReady()) {
RoboErik430fc482014-06-12 15:49:20 -07004474 MediaSessionLegacyHelper.getHelper(mContext).sendMediaButtonEvent(event, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004475 }
4476 }
4477
Mike Lockwood1753f7f2009-08-24 14:49:07 -07004478 BroadcastReceiver mDockReceiver = new BroadcastReceiver() {
Craig Mautnereee29c42013-01-17 14:44:34 -08004479 @Override
Mike Lockwood1753f7f2009-08-24 14:49:07 -07004480 public void onReceive(Context context, Intent intent) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07004481 if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) {
4482 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
4483 Intent.EXTRA_DOCK_STATE_UNDOCKED);
Daniel Sandler6396c722013-04-16 20:19:09 -04004484 } else {
4485 try {
4486 IUiModeManager uiModeService = IUiModeManager.Stub.asInterface(
4487 ServiceManager.getService(Context.UI_MODE_SERVICE));
4488 mUiMode = uiModeService.getCurrentModeType();
4489 } catch (RemoteException e) {
4490 }
Dianne Hackborn80fa1662009-10-07 14:02:10 -07004491 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004492 updateRotation(true);
Craig Mautnereee29c42013-01-17 14:44:34 -08004493 synchronized (mLock) {
4494 updateOrientationListenerLp();
4495 }
Mike Lockwood1753f7f2009-08-24 14:49:07 -07004496 }
4497 };
4498
Jeff Brown6aaf2952012-10-05 16:01:08 -07004499 BroadcastReceiver mDreamReceiver = new BroadcastReceiver() {
4500 @Override
4501 public void onReceive(Context context, Intent intent) {
4502 if (Intent.ACTION_DREAMING_STARTED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004503 if (mKeyguardDelegate != null) {
4504 mKeyguardDelegate.onDreamingStarted();
Jeff Brown6aaf2952012-10-05 16:01:08 -07004505 }
4506 } else if (Intent.ACTION_DREAMING_STOPPED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004507 if (mKeyguardDelegate != null) {
4508 mKeyguardDelegate.onDreamingStopped();
Jeff Brown6aaf2952012-10-05 16:01:08 -07004509 }
4510 }
4511 }
4512 };
4513
Christopher Tate5e08af02012-09-21 17:17:22 -07004514 BroadcastReceiver mMultiuserReceiver = new BroadcastReceiver() {
4515 @Override
4516 public void onReceive(Context context, Intent intent) {
4517 if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) {
4518 // tickle the settings observer: this first ensures that we're
4519 // observing the relevant settings for the newly-active user,
4520 // and then updates our own bookkeeping based on the now-
4521 // current user.
4522 mSettingsObserver.onChange(false);
John Spurlockce479d82012-11-29 09:52:21 -05004523
4524 // force a re-application of focused window sysui visibility.
4525 // the window may never have been shown for this user
4526 // e.g. the keyguard when going through the new-user setup flow
John Spurlock04db1762013-05-13 12:46:41 -04004527 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
John Spurlockce479d82012-11-29 09:52:21 -05004528 mLastSystemUiFlags = 0;
4529 updateSystemUiVisibilityLw();
4530 }
Christopher Tate5e08af02012-09-21 17:17:22 -07004531 }
4532 }
4533 };
4534
John Spurlockd9b70bd2014-02-06 17:02:44 -05004535 private final Runnable mRequestTransientNav = new Runnable() {
4536 @Override
4537 public void run() {
4538 requestTransientBars(mNavigationBar);
4539 }
4540 };
4541
John Spurlocke1f366f2013-08-05 12:22:40 -04004542 private void requestTransientBars(WindowState swipeTarget) {
John Spurlock04db1762013-05-13 12:46:41 -04004543 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Maurice Lam99c6e072014-04-28 18:24:28 -07004544 if (!isUserSetupComplete()) {
4545 // Swipe-up for navigation bar is disabled during setup
4546 return;
4547 }
John Spurlock27735a42013-08-14 17:57:38 -04004548 boolean sb = mStatusBarController.checkShowTransientBarLw();
4549 boolean nb = mNavigationBarController.checkShowTransientBarLw();
John Spurlockad3e6cb2013-04-30 08:47:43 -04004550 if (sb || nb) {
John Spurlocke1f366f2013-08-05 12:22:40 -04004551 WindowState barTarget = sb ? mStatusBar : mNavigationBar;
4552 if (sb ^ nb && barTarget != swipeTarget) {
4553 if (DEBUG) Slog.d(TAG, "Not showing transient bar, wrong swipe target");
John Spurlockad3e6cb2013-04-30 08:47:43 -04004554 return;
4555 }
John Spurlock27735a42013-08-14 17:57:38 -04004556 if (sb) mStatusBarController.showTransient();
4557 if (nb) mNavigationBarController.showTransient();
John Spurlockf1a36642013-10-12 17:50:42 -04004558 mImmersiveModeConfirmation.confirmCurrentPrompt();
John Spurlockad3e6cb2013-04-30 08:47:43 -04004559 updateSystemUiVisibilityLw();
John Spurlock32beb2c2013-03-11 10:16:47 -04004560 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04004561 }
4562 }
4563
Jeff Brownc38c9be2012-10-04 13:16:19 -07004564 @Override
Jeff Brown140ffc72014-05-01 15:18:00 -07004565 public void goingToSleep(int why) {
Dianne Hackborn74489012009-03-24 20:50:09 -07004566 EventLog.writeEvent(70000, 0);
The Android Open Source Project0727d222009-03-11 12:11:58 -07004567 synchronized (mLock) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004568 mScreenOnEarly = false;
4569 mScreenOnFully = false;
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07004570 }
Jim Miller5ecd8112013-01-09 18:50:26 -08004571 if (mKeyguardDelegate != null) {
4572 mKeyguardDelegate.onScreenTurnedOff(why);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004573 }
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07004574 synchronized (mLock) {
Jeff Browna20dda42014-05-27 20:57:24 -07004575 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07004576 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05004577 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07004578 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004579 }
4580
Jeff Brownc38c9be2012-10-04 13:16:19 -07004581 @Override
Jeff Brown140ffc72014-05-01 15:18:00 -07004582 public void wakingUp(final ScreenOnListener screenOnListener) {
Dianne Hackborn74489012009-03-24 20:50:09 -07004583 EventLog.writeEvent(70000, 1);
Craig Mautner8a0da012014-05-31 15:13:37 -07004584 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turning on...",
4585 new RuntimeException("here").fillInStackTrace());
4586 mHandler.obtainMessage(MSG_WAKING_UP, screenOnListener).sendToTarget();
4587 }
4588
4589 // Called on the mHandler thread.
4590 private void handleWakingUp(final ScreenOnListener screenOnListener) {
4591 if (screenOnListener != null) {
Craig Mautner13f6ea72014-06-23 14:57:02 -07004592 mScreenOnListener = screenOnListener;
Dianne Hackborn40011092011-09-22 13:37:48 -07004593 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07004594
The Android Open Source Project0727d222009-03-11 12:11:58 -07004595 synchronized (mLock) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004596 mScreenOnEarly = true;
Jeff Browna20dda42014-05-27 20:57:24 -07004597 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07004598 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05004599 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07004600 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07004601
Craig Mautner8a0da012014-05-31 15:13:37 -07004602 mKeyguardDrawComplete = false;
4603 mWindowManagerDrawComplete = false;
Jim Miller5ecd8112013-01-09 18:50:26 -08004604 if (mKeyguardDelegate != null) {
Craig Mautner8a0da012014-05-31 15:13:37 -07004605 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
4606 mHandler.sendEmptyMessageDelayed(MSG_KEYGUARD_DRAWN_TIMEOUT, 1000);
4607 mKeyguardDelegate.onScreenTurnedOn(mKeyguardDelegateCallback);
Jeff Brownc38c9be2012-10-04 13:16:19 -07004608 } else {
Craig Mautner8a0da012014-05-31 15:13:37 -07004609 if (DEBUG_WAKEUP) Slog.d(TAG, "null mKeyguardDelegate: setting mKeyguardDrawComplete.");
4610 mKeyguardDrawComplete = true;
Jeff Brownc38c9be2012-10-04 13:16:19 -07004611 }
Craig Mautner8a0da012014-05-31 15:13:37 -07004612 mWindowManagerInternal.waitForAllWindowsDrawn(mWindowManagerDrawCallback, 500);
Jeff Brownc38c9be2012-10-04 13:16:19 -07004613 }
4614
Craig Mautner8a0da012014-05-31 15:13:37 -07004615 // Called on the mHandler thread.
4616 private void finishScreenTurningOn() {
4617 if (DEBUG_WAKEUP) Slog.d(TAG,
4618 "finishScreenTurningOn: mKeyguardDrawComplete=" + mKeyguardDrawComplete
4619 + " mWindowManagerDrawComplete=" + mWindowManagerDrawComplete);
4620 if (!mKeyguardDrawComplete || !mWindowManagerDrawComplete) {
4621 return;
Jeff Brownc38c9be2012-10-04 13:16:19 -07004622 }
4623
Craig Mautner13f6ea72014-06-23 14:57:02 -07004624 ScreenOnListener screenOnListener;
Jeff Brownc38c9be2012-10-04 13:16:19 -07004625 synchronized (mLock) {
4626 mScreenOnFully = true;
Craig Mautner13f6ea72014-06-23 14:57:02 -07004627 screenOnListener = mScreenOnListener;
4628 mScreenOnListener = null;
Jeff Brownc38c9be2012-10-04 13:16:19 -07004629 }
4630
Jeff Brown4fc45272012-10-10 18:28:14 -07004631 try {
4632 mWindowManager.setEventDispatching(true);
4633 } catch (RemoteException unhandled) {
4634 }
4635
Craig Mautner13f6ea72014-06-23 14:57:02 -07004636 if (screenOnListener != null) {
4637 screenOnListener.onScreenOn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07004638 }
Craig Mautner8a0da012014-05-31 15:13:37 -07004639
4640 setKeyguardDrawn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07004641 }
4642
4643 @Override
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004644 public boolean isScreenOnEarly() {
4645 return mScreenOnEarly;
4646 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07004647
4648 @Override
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004649 public boolean isScreenOnFully() {
4650 return mScreenOnFully;
Dianne Hackborn08743722009-12-21 12:16:51 -08004651 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07004652
Dianne Hackborn08743722009-12-21 12:16:51 -08004653 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07004654 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004655 public void enableKeyguard(boolean enabled) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004656 if (mKeyguardDelegate != null) {
4657 mKeyguardDelegate.setKeyguardEnabled(enabled);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004658 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004659 }
4660
4661 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07004662 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004663 public void exitKeyguardSecurely(OnKeyguardExitResult callback) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004664 if (mKeyguardDelegate != null) {
4665 mKeyguardDelegate.verifyUnlock(callback);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004666 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004667 }
4668
Mike Lockwoodf7913302009-11-28 22:27:10 -05004669 private boolean keyguardIsShowingTq() {
Jim Miller5ecd8112013-01-09 18:50:26 -08004670 if (mKeyguardDelegate == null) return false;
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004671 return mKeyguardDelegate.isShowingAndNotOccluded();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004672 }
4673
Mike Lockwood520d8bc2011-02-18 13:23:13 -05004674
4675 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07004676 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05004677 public boolean isKeyguardLocked() {
4678 return keyguardOn();
4679 }
4680
4681 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07004682 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05004683 public boolean isKeyguardSecure() {
Jim Miller5ecd8112013-01-09 18:50:26 -08004684 if (mKeyguardDelegate == null) return false;
4685 return mKeyguardDelegate.isSecure();
Mike Lockwood520d8bc2011-02-18 13:23:13 -05004686 }
4687
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004688 // Returns true if keyguard is currently locked whether or not it is currently hidden.
4689 private boolean isKeyguardSecureIncludingHidden() {
4690 return mKeyguardDelegate.isSecure() && mKeyguardDelegate.isShowing();
4691 }
4692
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004693 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07004694 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004695 public boolean inKeyguardRestrictedKeyInputMode() {
Jim Miller5ecd8112013-01-09 18:50:26 -08004696 if (mKeyguardDelegate == null) return false;
4697 return mKeyguardDelegate.isInputRestricted();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004698 }
4699
Jose Lima9546b202014-07-02 17:21:51 -07004700 @Override
Dianne Hackborn90c52de2011-09-23 12:57:44 -07004701 public void dismissKeyguardLw() {
RoboErik8a2cfc32014-05-16 11:19:38 -07004702 if (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()) {
Daniel Sandler1ce804392012-11-07 15:07:12 -05004703 mHandler.post(new Runnable() {
Jose Lima9546b202014-07-02 17:21:51 -07004704 @Override
Daniel Sandler1ce804392012-11-07 15:07:12 -05004705 public void run() {
Jim Miller5ecd8112013-01-09 18:50:26 -08004706 if (mKeyguardDelegate.isDismissable()) {
Daniel Sandler1ce804392012-11-07 15:07:12 -05004707 // Can we just finish the keyguard straight away?
Jim Miller5ecd8112013-01-09 18:50:26 -08004708 mKeyguardDelegate.keyguardDone(false, true);
Daniel Sandler1ce804392012-11-07 15:07:12 -05004709 } else {
4710 // ask the keyguard to prompt the user to authenticate if necessary
Jim Miller5ecd8112013-01-09 18:50:26 -08004711 mKeyguardDelegate.dismiss();
Dianne Hackborn90c52de2011-09-23 12:57:44 -07004712 }
Daniel Sandler1ce804392012-11-07 15:07:12 -05004713 }
4714 });
Dianne Hackborn90c52de2011-09-23 12:57:44 -07004715 }
4716 }
4717
Jorim Jaggicff0acb2014-03-31 16:35:15 +02004718 private void setKeyguardDrawn() {
4719 synchronized (mLock) {
4720 mKeyguardDrawn = true;
4721 }
4722 try {
4723 mWindowManager.enableScreenIfNeeded();
4724 } catch (RemoteException unhandled) {
4725 }
4726 }
4727
4728 @Override
4729 public boolean isKeyguardDrawnLw() {
4730 synchronized (mLock) {
4731 return mKeyguardDrawn;
4732 }
4733 }
4734
Jorim Jaggi0d674622014-05-21 01:34:15 +02004735 @Override
Jorim Jaggie29b2db2014-05-30 23:17:03 +02004736 public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) {
Jorim Jaggi0d674622014-05-21 01:34:15 +02004737 if (mKeyguardDelegate != null) {
Jorim Jaggie29b2db2014-05-30 23:17:03 +02004738 mKeyguardDelegate.startKeyguardExitAnimation(startTime, fadeoutDuration);
Jorim Jaggi0d674622014-05-21 01:34:15 +02004739 }
4740 }
4741
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004742 void sendCloseSystemWindows() {
4743 sendCloseSystemWindows(mContext, null);
4744 }
4745
4746 void sendCloseSystemWindows(String reason) {
4747 sendCloseSystemWindows(mContext, reason);
4748 }
4749
4750 static void sendCloseSystemWindows(Context context, String reason) {
4751 if (ActivityManagerNative.isSystemReady()) {
Dianne Hackborn94a679d2009-07-28 17:51:07 -07004752 try {
4753 ActivityManagerNative.getDefault().closeSystemDialogs(reason);
4754 } catch (RemoteException e) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004755 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004756 }
4757 }
Mitsuru Oshima831d0d92009-06-16 18:27:18 -07004758
Jeff Brown01a98dd2011-09-20 15:08:29 -07004759 @Override
4760 public int rotationForOrientationLw(int orientation, int lastRotation) {
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05004761 if (false) {
4762 Slog.v(TAG, "rotationForOrientationLw(orient="
4763 + orientation + ", last=" + lastRotation
4764 + "); user=" + mUserRotation + " "
4765 + ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED)
4766 ? "USER_ROTATION_LOCKED" : "")
4767 );
4768 }
4769
Craig Mautner46ac6fa2013-08-01 10:06:34 -07004770 if (mForceDefaultOrientation) {
4771 return Surface.ROTATION_0;
4772 }
4773
The Android Open Source Project0727d222009-03-11 12:11:58 -07004774 synchronized (mLock) {
Jeff Brownc0347aa2011-09-23 17:26:09 -07004775 int sensorRotation = mOrientationListener.getProposedRotation(); // may be -1
4776 if (sensorRotation < 0) {
Jeff Brown0f862b42012-09-27 21:11:01 -07004777 sensorRotation = lastRotation;
Jeff Brownc0347aa2011-09-23 17:26:09 -07004778 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004779
Jeff Browndec6cf42011-11-15 14:08:20 -08004780 final int preferredRotation;
Jeff Brown2e7760e2012-04-11 15:14:55 -07004781 if (mLidState == LID_OPEN && mLidOpenRotation >= 0) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07004782 // Ignore sensor when lid switch is open and rotation is forced.
4783 preferredRotation = mLidOpenRotation;
4784 } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR
Jeff Brownc0347aa2011-09-23 17:26:09 -07004785 && (mCarDockEnablesAccelerometer || mCarDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07004786 // Ignore sensor when in car dock unless explicitly enabled.
4787 // This case can override the behavior of NOSENSOR, and can also
4788 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07004789 preferredRotation = mCarDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07004790 ? sensorRotation : mCarDockRotation;
Jeff Brown1a693182011-11-08 14:44:16 -08004791 } else if ((mDockMode == Intent.EXTRA_DOCK_STATE_DESK
4792 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
4793 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK)
Jeff Brownc0347aa2011-09-23 17:26:09 -07004794 && (mDeskDockEnablesAccelerometer || mDeskDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07004795 // Ignore sensor when in desk dock unless explicitly enabled.
4796 // This case can override the behavior of NOSENSOR, and can also
4797 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07004798 preferredRotation = mDeskDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07004799 ? sensorRotation : mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -07004800 } else if (mHdmiPlugged && mDemoHdmiRotationLock) {
4801 // Ignore sensor when plugged into HDMI when demo HDMI rotation lock enabled.
Jeff Browneb3e4b92011-12-06 19:54:24 -08004802 // Note that the dock orientation overrides the HDMI orientation.
Jeff Brownc82c89ed2013-04-17 17:18:15 -07004803 preferredRotation = mDemoHdmiRotation;
4804 } else if (mHdmiPlugged && mDockMode == Intent.EXTRA_DOCK_STATE_UNDOCKED
4805 && mUndockedHdmiRotation >= 0) {
4806 // Ignore sensor when plugged into HDMI and an undocked orientation has
4807 // been specified in the configuration (only for legacy devices without
4808 // full multi-display support).
4809 // Note that the dock orientation overrides the HDMI orientation.
4810 preferredRotation = mUndockedHdmiRotation;
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07004811 } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED) {
4812 // Application just wants to remain locked in the last rotation.
4813 preferredRotation = lastRotation;
Jeff Brownbcdfc622014-03-06 19:13:04 -08004814 } else if (!mSupportAutoRotation) {
4815 // If we don't support auto-rotation then bail out here and ignore
4816 // the sensor and any rotation lock settings.
4817 preferredRotation = -1;
Jeff Brown207673cd2012-06-05 17:47:11 -07004818 } else if ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE
Jeff Brown01a98dd2011-09-20 15:08:29 -07004819 && (orientation == ActivityInfo.SCREEN_ORIENTATION_USER
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07004820 || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
4821 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
4822 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
4823 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER))
Jeff Brown01a98dd2011-09-20 15:08:29 -07004824 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
4825 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
4826 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
4827 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) {
4828 // Otherwise, use sensor only if requested by the application or enabled
4829 // by default for USER or UNSPECIFIED modes. Does not apply to NOSENSOR.
Jeff Brownd3187e32011-09-21 19:26:44 -07004830 if (mAllowAllRotations < 0) {
4831 // Can't read this during init() because the context doesn't
4832 // have display metrics at that time so we cannot determine
4833 // tablet vs. phone then.
4834 mAllowAllRotations = mContext.getResources().getBoolean(
4835 com.android.internal.R.bool.config_allowAllRotations) ? 1 : 0;
4836 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004837 if (sensorRotation != Surface.ROTATION_180
Jeff Brownd3187e32011-09-21 19:26:44 -07004838 || mAllowAllRotations == 1
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07004839 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
4840 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07004841 preferredRotation = sensorRotation;
4842 } else {
4843 preferredRotation = lastRotation;
4844 }
Jeff Brown207673cd2012-06-05 17:47:11 -07004845 } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED
4846 && orientation != ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) {
4847 // Apply rotation lock. Does not apply to NOSENSOR.
4848 // The idea is that the user rotation expresses a weak preference for the direction
4849 // of gravity and as NOSENSOR is never affected by gravity, then neither should
4850 // NOSENSOR be affected by rotation lock (although it will be affected by docks).
Jeff Brown4dfce202011-10-05 12:00:10 -07004851 preferredRotation = mUserRotation;
Jeff Browndec6cf42011-11-15 14:08:20 -08004852 } else {
4853 // No overriding preference.
4854 // We will do exactly what the application asked us to do.
4855 preferredRotation = -1;
Jeff Brown01a98dd2011-09-20 15:08:29 -07004856 }
4857
Dianne Hackborne5439f22010-10-02 16:53:50 -07004858 switch (orientation) {
4859 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08004860 // Return portrait unless overridden.
4861 if (isAnyPortrait(preferredRotation)) {
4862 return preferredRotation;
4863 }
Dianne Hackborne5439f22010-10-02 16:53:50 -07004864 return mPortraitRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07004865
Jeff Brown01a98dd2011-09-20 15:08:29 -07004866 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08004867 // Return landscape unless overridden.
4868 if (isLandscapeOrSeascape(preferredRotation)) {
4869 return preferredRotation;
4870 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004871 return mLandscapeRotation;
4872
4873 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08004874 // Return reverse portrait unless overridden.
4875 if (isAnyPortrait(preferredRotation)) {
4876 return preferredRotation;
4877 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004878 return mUpsideDownRotation;
4879
4880 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08004881 // Return seascape unless overridden.
4882 if (isLandscapeOrSeascape(preferredRotation)) {
4883 return preferredRotation;
4884 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004885 return mSeascapeRotation;
4886
4887 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07004888 case ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE:
Jeff Brown01a98dd2011-09-20 15:08:29 -07004889 // Return either landscape rotation.
4890 if (isLandscapeOrSeascape(preferredRotation)) {
4891 return preferredRotation;
4892 }
4893 if (isLandscapeOrSeascape(lastRotation)) {
Jeff Brown4519f072011-01-23 13:16:01 -08004894 return lastRotation;
4895 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004896 return mLandscapeRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004897
Jeff Brown01a98dd2011-09-20 15:08:29 -07004898 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07004899 case ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT:
Jeff Brown01a98dd2011-09-20 15:08:29 -07004900 // Return either portrait rotation.
4901 if (isAnyPortrait(preferredRotation)) {
4902 return preferredRotation;
4903 }
4904 if (isAnyPortrait(lastRotation)) {
4905 return lastRotation;
4906 }
4907 return mPortraitRotation;
4908
4909 default:
Jeff Brown4dfce202011-10-05 12:00:10 -07004910 // For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR,
4911 // just return the preferred orientation we already calculated.
Jeff Brown01a98dd2011-09-20 15:08:29 -07004912 if (preferredRotation >= 0) {
4913 return preferredRotation;
4914 }
Dianne Hackborndacea8c2011-04-21 17:26:39 -07004915 return Surface.ROTATION_0;
Daniel Sandlere7e5ac22011-02-22 16:10:21 -05004916 }
4917 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07004918 }
4919
Jeff Brown01a98dd2011-09-20 15:08:29 -07004920 @Override
4921 public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation) {
4922 switch (orientation) {
4923 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
4924 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
4925 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
4926 return isAnyPortrait(rotation);
4927
4928 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
4929 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
4930 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
4931 return isLandscapeOrSeascape(rotation);
4932
4933 default:
4934 return true;
4935 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07004936 }
4937
Jeff Brownc0347aa2011-09-23 17:26:09 -07004938 @Override
4939 public void setRotationLw(int rotation) {
4940 mOrientationListener.setCurrentRotation(rotation);
4941 }
4942
Jeff Brown01a98dd2011-09-20 15:08:29 -07004943 private boolean isLandscapeOrSeascape(int rotation) {
4944 return rotation == mLandscapeRotation || rotation == mSeascapeRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07004945 }
4946
Jeff Brown01a98dd2011-09-20 15:08:29 -07004947 private boolean isAnyPortrait(int rotation) {
4948 return rotation == mPortraitRotation || rotation == mUpsideDownRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07004949 }
4950
Jose Lima9546b202014-07-02 17:21:51 -07004951 @Override
Svetoslav Ganov80943d82013-01-02 10:25:37 -08004952 public int getUserRotationMode() {
4953 return Settings.System.getIntForUser(mContext.getContentResolver(),
Brett Chabot7e55c402013-05-16 19:38:08 -07004954 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
4955 WindowManagerPolicy.USER_ROTATION_FREE :
4956 WindowManagerPolicy.USER_ROTATION_LOCKED;
Svetoslav Ganov80943d82013-01-02 10:25:37 -08004957 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004958
4959 // User rotation: to be used when all else fails in assigning an orientation to the device
Jose Lima9546b202014-07-02 17:21:51 -07004960 @Override
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004961 public void setUserRotationMode(int mode, int rot) {
4962 ContentResolver res = mContext.getContentResolver();
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05004963
4964 // mUserRotationMode and mUserRotation will be assigned by the content observer
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004965 if (mode == WindowManagerPolicy.USER_ROTATION_LOCKED) {
Christopher Tate5e08af02012-09-21 17:17:22 -07004966 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004967 Settings.System.USER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07004968 rot,
4969 UserHandle.USER_CURRENT);
4970 Settings.System.putIntForUser(res,
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05004971 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07004972 0,
4973 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004974 } else {
Christopher Tate5e08af02012-09-21 17:17:22 -07004975 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004976 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07004977 1,
4978 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004979 }
4980 }
4981
Jose Lima9546b202014-07-02 17:21:51 -07004982 @Override
Jeff Brownac143512012-04-05 18:57:33 -07004983 public void setSafeMode(boolean safeMode) {
4984 mSafeMode = safeMode;
4985 performHapticFeedbackLw(null, safeMode
4986 ? HapticFeedbackConstants.SAFE_MODE_ENABLED
4987 : HapticFeedbackConstants.SAFE_MODE_DISABLED, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004988 }
Craig Mautnereda67292013-04-28 13:50:14 -07004989
Dianne Hackborn181ceb52009-08-27 22:16:40 -07004990 static long[] getLongIntArray(Resources r, int resid) {
4991 int[] ar = r.getIntArray(resid);
4992 if (ar == null) {
4993 return null;
4994 }
4995 long[] out = new long[ar.length];
4996 for (int i=0; i<ar.length; i++) {
4997 out[i] = ar[i];
4998 }
4999 return out;
5000 }
Craig Mautnereda67292013-04-28 13:50:14 -07005001
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005002 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07005003 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005004 public void systemReady() {
Mike Lockwooded8902d2013-11-15 11:01:47 -08005005 mKeyguardDelegate = new KeyguardServiceDelegate(mContext, null);
5006 mKeyguardDelegate.onSystemReady();
5007
Jeff Brown4f5fa282014-06-12 19:19:15 -07005008 updateUiMode();
Dianne Hackbornb1a79802009-09-29 15:18:31 -07005009 synchronized (mLock) {
5010 updateOrientationListenerLp();
Dianne Hackbornc777e072010-02-12 13:07:59 -08005011 mSystemReady = true;
5012 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07005013 @Override
Dianne Hackbornc777e072010-02-12 13:07:59 -08005014 public void run() {
5015 updateSettings();
5016 }
5017 });
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005018 }
5019 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07005020
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005021 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005022 @Override
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005023 public void systemBooted() {
Jim Millere5f910a2013-10-16 18:15:46 -07005024 if (mKeyguardDelegate != null) {
5025 mKeyguardDelegate.onBootCompleted();
5026 }
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005027 synchronized (mLock) {
5028 mSystemBooted = true;
5029 }
Craig Mautner8a0da012014-05-31 15:13:37 -07005030 wakingUp(null);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005031 }
5032
Dianne Hackborn661cd522011-08-22 00:26:20 -07005033 ProgressDialog mBootMsgDialog = null;
5034
5035 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005036 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07005037 public void showBootMessage(final CharSequence msg, final boolean always) {
5038 mHandler.post(new Runnable() {
5039 @Override public void run() {
5040 if (mBootMsgDialog == null) {
Craig Stout4c0cb8a2014-04-04 13:03:10 -07005041 int theme;
5042 if (mContext.getPackageManager().hasSystemFeature(
5043 PackageManager.FEATURE_WATCH)) {
5044 theme = com.android.internal.R.style.Theme_Micro_Dialog_Alert;
5045 } else if (mContext.getPackageManager().hasSystemFeature(
5046 PackageManager.FEATURE_TELEVISION)) {
5047 theme = com.android.internal.R.style.Theme_Leanback_Dialog_Alert;
5048 } else {
5049 theme = 0;
5050 }
Vinod Krishnanfa8fc412014-04-18 14:35:53 -07005051
5052 mBootMsgDialog = new ProgressDialog(mContext, theme) {
Dianne Hackborn295e3c22011-08-25 13:19:08 -07005053 // This dialog will consume all events coming in to
5054 // it, to avoid it trying to do things too early in boot.
5055 @Override public boolean dispatchKeyEvent(KeyEvent event) {
5056 return true;
5057 }
5058 @Override public boolean dispatchKeyShortcutEvent(KeyEvent event) {
5059 return true;
5060 }
5061 @Override public boolean dispatchTouchEvent(MotionEvent ev) {
5062 return true;
5063 }
5064 @Override public boolean dispatchTrackballEvent(MotionEvent ev) {
5065 return true;
5066 }
5067 @Override public boolean dispatchGenericMotionEvent(MotionEvent ev) {
5068 return true;
5069 }
5070 @Override public boolean dispatchPopulateAccessibilityEvent(
5071 AccessibilityEvent event) {
5072 return true;
5073 }
5074 };
Dianne Hackborn661cd522011-08-22 00:26:20 -07005075 mBootMsgDialog.setTitle(R.string.android_upgrading_title);
5076 mBootMsgDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
5077 mBootMsgDialog.setIndeterminate(true);
5078 mBootMsgDialog.getWindow().setType(
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07005079 WindowManager.LayoutParams.TYPE_BOOT_PROGRESS);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005080 mBootMsgDialog.getWindow().addFlags(
5081 WindowManager.LayoutParams.FLAG_DIM_BEHIND
5082 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
5083 mBootMsgDialog.getWindow().setDimAmount(1);
Dianne Hackbornd9efb952011-12-07 14:56:51 -08005084 WindowManager.LayoutParams lp = mBootMsgDialog.getWindow().getAttributes();
5085 lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
5086 mBootMsgDialog.getWindow().setAttributes(lp);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005087 mBootMsgDialog.setCancelable(false);
5088 mBootMsgDialog.show();
5089 }
5090 mBootMsgDialog.setMessage(msg);
5091 }
5092 });
5093 }
5094
5095 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005096 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07005097 public void hideBootMessages() {
5098 mHandler.post(new Runnable() {
5099 @Override public void run() {
5100 if (mBootMsgDialog != null) {
5101 mBootMsgDialog.dismiss();
5102 mBootMsgDialog = null;
5103 }
5104 }
5105 });
5106 }
5107
Mike Lockwood28569302010-01-28 11:54:40 -05005108 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005109 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05005110 public void userActivity() {
Dianne Hackborndf89e652011-10-06 22:35:11 -07005111 // ***************************************
5112 // NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
5113 // ***************************************
5114 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
5115 // WITH ITS LOCKS HELD.
5116 //
5117 // This code must be VERY careful about the locks
5118 // it acquires.
5119 // In fact, the current code acquires way too many,
5120 // and probably has lurking deadlocks.
5121
Mike Lockwood28569302010-01-28 11:54:40 -05005122 synchronized (mScreenLockTimeout) {
5123 if (mLockScreenTimerActive) {
5124 // reset the timer
5125 mHandler.removeCallbacks(mScreenLockTimeout);
5126 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
5127 }
5128 }
Daniel Sandler0601eb72011-04-13 01:01:32 -04005129 }
5130
Adam Cohenf7522022012-10-03 20:03:18 -07005131 class ScreenLockTimeout implements Runnable {
5132 Bundle options;
5133
5134 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05005135 public void run() {
5136 synchronized (this) {
5137 if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard");
Jim Miller5ecd8112013-01-09 18:50:26 -08005138 if (mKeyguardDelegate != null) {
5139 mKeyguardDelegate.doKeyguardTimeout(options);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005140 }
Mike Lockwood28569302010-01-28 11:54:40 -05005141 mLockScreenTimerActive = false;
Adam Cohenf7522022012-10-03 20:03:18 -07005142 options = null;
Mike Lockwood28569302010-01-28 11:54:40 -05005143 }
5144 }
Mike Lockwood28569302010-01-28 11:54:40 -05005145
Adam Cohenf7522022012-10-03 20:03:18 -07005146 public void setLockOptions(Bundle options) {
5147 this.options = options;
5148 }
5149 }
5150
5151 ScreenLockTimeout mScreenLockTimeout = new ScreenLockTimeout();
5152
Jose Lima9546b202014-07-02 17:21:51 -07005153 @Override
Adam Cohenf7522022012-10-03 20:03:18 -07005154 public void lockNow(Bundle options) {
Jim Miller93c518e2012-01-17 15:55:31 -08005155 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null);
5156 mHandler.removeCallbacks(mScreenLockTimeout);
Adam Cohenf7522022012-10-03 20:03:18 -07005157 if (options != null) {
5158 // In case multiple calls are made to lockNow, we don't wipe out the options
5159 // until the runnable actually executes.
5160 mScreenLockTimeout.setLockOptions(options);
5161 }
Jim Miller93c518e2012-01-17 15:55:31 -08005162 mHandler.post(mScreenLockTimeout);
5163 }
5164
Mike Lockwood28569302010-01-28 11:54:40 -05005165 private void updateLockScreenTimeout() {
5166 synchronized (mScreenLockTimeout) {
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005167 boolean enable = (mAllowLockscreenWhenOn && mScreenOnEarly &&
Jim Miller5ecd8112013-01-09 18:50:26 -08005168 mKeyguardDelegate != null && mKeyguardDelegate.isSecure());
Mike Lockwood28569302010-01-28 11:54:40 -05005169 if (mLockScreenTimerActive != enable) {
5170 if (enable) {
5171 if (localLOGV) Log.v(TAG, "setting lockscreen timer");
5172 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
5173 } else {
5174 if (localLOGV) Log.v(TAG, "clearing lockscreen timer");
5175 mHandler.removeCallbacks(mScreenLockTimeout);
5176 }
5177 mLockScreenTimerActive = enable;
5178 }
5179 }
5180 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005181
5182 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07005183 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005184 public void enableScreenAfterBoot() {
5185 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07005186 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07005187 updateRotation(true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005188 }
Dianne Hackbornf54c8f92009-09-19 14:03:57 -07005189
Jeff Brownc458ce92012-04-30 14:58:40 -07005190 private void applyLidSwitchState() {
Jeff Brownc458ce92012-04-30 14:58:40 -07005191 if (mLidState == LID_CLOSED && mLidControlsSleep) {
Jeff Brown6d8fd272014-05-20 21:24:38 -07005192 mPowerManager.goToSleep(SystemClock.uptimeMillis(),
5193 PowerManager.GO_TO_SLEEP_REASON_USER,
5194 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
Jeff Brownc458ce92012-04-30 14:58:40 -07005195 }
Jeff Browna20dda42014-05-27 20:57:24 -07005196
5197 synchronized (mLock) {
5198 updateWakeGestureListenerLp();
5199 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005200 }
5201
Jeff Brown4f5fa282014-06-12 19:19:15 -07005202 void updateUiMode() {
5203 if (mUiModeManager == null) {
5204 mUiModeManager = IUiModeManager.Stub.asInterface(
5205 ServiceManager.getService(Context.UI_MODE_SERVICE));
5206 }
5207 try {
5208 mUiMode = mUiModeManager.getCurrentModeType();
5209 } catch (RemoteException e) {
5210 }
5211 }
5212
Jeff Brown01a98dd2011-09-20 15:08:29 -07005213 void updateRotation(boolean alwaysSendConfiguration) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005214 try {
5215 //set orientation on WindowManager
Dianne Hackbornf87d1962012-04-04 12:48:24 -07005216 mWindowManager.updateRotation(alwaysSendConfiguration, false);
5217 } catch (RemoteException e) {
5218 // Ignore
5219 }
5220 }
5221
5222 void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) {
5223 try {
5224 //set orientation on WindowManager
5225 mWindowManager.updateRotation(alwaysSendConfiguration, forceRelayout);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005226 } catch (RemoteException e) {
5227 // Ignore
5228 }
5229 }
5230
Daniel Sandler6396c722013-04-16 20:19:09 -04005231 /**
5232 * Return an Intent to launch the currently active dock app as home. Returns
5233 * null if the standard home should be launched, which is the case if any of the following is
5234 * true:
5235 * <ul>
5236 * <li>The device is not in either car mode or desk mode
5237 * <li>The device is in car mode but ENABLE_CAR_DOCK_HOME_CAPTURE is false
5238 * <li>The device is in desk mode but ENABLE_DESK_DOCK_HOME_CAPTURE is false
5239 * <li>The device is in car mode but there's no CAR_DOCK app with METADATA_DOCK_HOME
5240 * <li>The device is in desk mode but there's no DESK_DOCK app with METADATA_DOCK_HOME
5241 * </ul>
Craig Mautnereda67292013-04-28 13:50:14 -07005242 * @return A dock intent.
Daniel Sandler6396c722013-04-16 20:19:09 -04005243 */
5244 Intent createHomeDockIntent() {
5245 Intent intent = null;
5246
5247 // What home does is based on the mode, not the dock state. That
5248 // is, when in car mode you should be taken to car home regardless
5249 // of whether we are actually in a car dock.
5250 if (mUiMode == Configuration.UI_MODE_TYPE_CAR) {
5251 if (ENABLE_CAR_DOCK_HOME_CAPTURE) {
5252 intent = mCarDockIntent;
5253 }
5254 } else if (mUiMode == Configuration.UI_MODE_TYPE_DESK) {
5255 if (ENABLE_DESK_DOCK_HOME_CAPTURE) {
5256 intent = mDeskDockIntent;
5257 }
Jeff Brown4f5fa282014-06-12 19:19:15 -07005258 } else if (mUiMode == Configuration.UI_MODE_TYPE_WATCH
5259 && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
5260 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK
5261 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK)) {
5262 // Always launch dock home from home when watch is docked, if it exists.
5263 intent = mDeskDockIntent;
Daniel Sandler6396c722013-04-16 20:19:09 -04005264 }
5265
5266 if (intent == null) {
5267 return null;
5268 }
5269
5270 ActivityInfo ai = null;
5271 ResolveInfo info = mContext.getPackageManager().resolveActivityAsUser(
5272 intent,
John Spurlockf56bef12013-07-09 09:51:46 -04005273 PackageManager.MATCH_DEFAULT_ONLY | PackageManager.GET_META_DATA,
Craig Mautnerd625ab22013-09-06 13:40:31 -07005274 mCurrentUserId);
Daniel Sandler6396c722013-04-16 20:19:09 -04005275 if (info != null) {
5276 ai = info.activityInfo;
5277 }
5278 if (ai != null
5279 && ai.metaData != null
5280 && ai.metaData.getBoolean(Intent.METADATA_DOCK_HOME)) {
5281 intent = new Intent(intent);
5282 intent.setClassName(ai.packageName, ai.name);
5283 return intent;
5284 }
5285
5286 return null;
5287 }
5288
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005289 void startDockOrHome() {
John Spurlockc8b46ca2013-04-08 12:59:26 -04005290 awakenDreams();
Daniel Sandler6396c722013-04-16 20:19:09 -04005291
5292 Intent dock = createHomeDockIntent();
5293 if (dock != null) {
5294 try {
5295 mContext.startActivityAsUser(dock, UserHandle.CURRENT);
5296 return;
5297 } catch (ActivityNotFoundException e) {
5298 }
5299 }
5300
Dianne Hackbornd8883992012-09-07 15:58:52 -07005301 mContext.startActivityAsUser(mHomeIntent, UserHandle.CURRENT);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005302 }
Craig Mautnereda67292013-04-28 13:50:14 -07005303
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005304 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005305 * goes to the home screen
5306 * @return whether it did anything
5307 */
5308 boolean goHome() {
5309 if (false) {
5310 // This code always brings home to the front.
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07005311 try {
5312 ActivityManagerNative.getDefault().stopAppSwitches();
5313 } catch (RemoteException e) {
5314 }
Dianne Hackborn94a679d2009-07-28 17:51:07 -07005315 sendCloseSystemWindows();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005316 startDockOrHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005317 } else {
5318 // This code brings home to the front or, if it is already
5319 // at the front, puts the device to sleep.
5320 try {
Wink Savilled2e6a332010-02-12 12:12:06 -08005321 if (SystemProperties.getInt("persist.sys.uts-test-mode", 0) == 1) {
5322 /// Roll back EndcallBehavior as the cupcake design to pass P1 lab entry.
5323 Log.d(TAG, "UTS-TEST-MODE");
5324 } else {
5325 ActivityManagerNative.getDefault().stopAppSwitches();
5326 sendCloseSystemWindows();
Daniel Sandler6396c722013-04-16 20:19:09 -04005327 Intent dock = createHomeDockIntent();
5328 if (dock != null) {
5329 int result = ActivityManagerNative.getDefault()
5330 .startActivityAsUser(null, null, dock,
5331 dock.resolveTypeIfNeeded(mContext.getContentResolver()),
5332 null, null, 0,
5333 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
5334 null, null, null, UserHandle.USER_CURRENT);
5335 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
5336 return false;
5337 }
5338 }
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005339 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005340 int result = ActivityManagerNative.getDefault()
Dianne Hackbornf265ea92013-01-31 15:00:51 -08005341 .startActivityAsUser(null, null, mHomeIntent,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005342 mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()),
Dianne Hackborna4972e92012-03-14 10:38:05 -07005343 null, null, 0,
5344 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Dianne Hackborn5e03e2c2012-09-06 14:21:19 -07005345 null, null, null, UserHandle.USER_CURRENT);
Dianne Hackborna4972e92012-03-14 10:38:05 -07005346 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005347 return false;
5348 }
5349 } catch (RemoteException ex) {
5350 // bummer, the activity manager, which is in this process, is dead
5351 }
5352 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005353 return true;
5354 }
Craig Mautnereda67292013-04-28 13:50:14 -07005355
5356 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07005357 public void setCurrentOrientationLw(int newOrientation) {
5358 synchronized (mLock) {
5359 if (newOrientation != mCurrentAppOrientation) {
5360 mCurrentAppOrientation = newOrientation;
5361 updateOrientationListenerLp();
5362 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005363 }
5364 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08005365
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07005366 private void performAuditoryFeedbackForAccessibilityIfNeed() {
5367 if (!isGlobalAccessibilityGestureEnabled()) {
5368 return;
5369 }
5370 AudioManager audioManager = (AudioManager) mContext.getSystemService(
5371 Context.AUDIO_SERVICE);
5372 if (audioManager.isSilentMode()) {
5373 return;
5374 }
5375 Ringtone ringTone = RingtoneManager.getRingtone(mContext,
5376 Settings.System.DEFAULT_NOTIFICATION_URI);
5377 ringTone.setStreamType(AudioManager.STREAM_MUSIC);
5378 ringTone.play();
5379 }
Craig Mautnereda67292013-04-28 13:50:14 -07005380
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07005381 private boolean isGlobalAccessibilityGestureEnabled() {
5382 return Settings.Global.getInt(mContext.getContentResolver(),
5383 Settings.Global.ENABLE_ACCESSIBILITY_GLOBAL_GESTURE_ENABLED, 0) == 1;
5384 }
5385
Craig Mautnereda67292013-04-28 13:50:14 -07005386 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07005387 public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) {
Svetoslav Ganov96179212012-10-10 14:17:45 -07005388 if (!mVibrator.hasVibrator()) {
5389 return false;
5390 }
Christopher Tate5e08af02012-09-21 17:17:22 -07005391 final boolean hapticsDisabled = Settings.System.getIntForUser(mContext.getContentResolver(),
5392 Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) == 0;
Jorim Jaggi5cf17872014-03-26 18:31:48 +01005393 if (!always && (hapticsDisabled || mKeyguardDelegate.isShowingAndNotOccluded())) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005394 return false;
5395 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08005396 long[] pattern = null;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005397 switch (effectId) {
5398 case HapticFeedbackConstants.LONG_PRESS:
Amith Yamasanic33cb712010-02-10 15:21:49 -08005399 pattern = mLongPressVibePattern;
5400 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07005401 case HapticFeedbackConstants.VIRTUAL_KEY:
Amith Yamasanic33cb712010-02-10 15:21:49 -08005402 pattern = mVirtualKeyVibePattern;
5403 break;
5404 case HapticFeedbackConstants.KEYBOARD_TAP:
5405 pattern = mKeyboardTapVibePattern;
5406 break;
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07005407 case HapticFeedbackConstants.CLOCK_TICK:
5408 pattern = mClockTickVibePattern;
5409 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07005410 case HapticFeedbackConstants.SAFE_MODE_DISABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08005411 pattern = mSafeModeDisabledVibePattern;
5412 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07005413 case HapticFeedbackConstants.SAFE_MODE_ENABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08005414 pattern = mSafeModeEnabledVibePattern;
5415 break;
Amith Yamasanic33cb712010-02-10 15:21:49 -08005416 default:
5417 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005418 }
Dianne Hackbornf265ea92013-01-31 15:00:51 -08005419 int owningUid;
5420 String owningPackage;
5421 if (win != null) {
5422 owningUid = win.getOwningUid();
5423 owningPackage = win.getOwningPackage();
5424 } else {
5425 owningUid = android.os.Process.myUid();
Dianne Hackborn95d78532013-09-11 09:51:14 -07005426 owningPackage = mContext.getOpPackageName();
Dianne Hackbornf265ea92013-01-31 15:00:51 -08005427 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08005428 if (pattern.length == 1) {
5429 // One-shot vibration
John Spurlock1af30c72014-03-10 08:33:35 -04005430 mVibrator.vibrate(owningUid, owningPackage, pattern[0], AudioManager.STREAM_SYSTEM);
Amith Yamasanic33cb712010-02-10 15:21:49 -08005431 } else {
5432 // Pattern vibration
John Spurlock1af30c72014-03-10 08:33:35 -04005433 mVibrator.vibrate(owningUid, owningPackage, pattern, -1, AudioManager.STREAM_SYSTEM);
Amith Yamasanic33cb712010-02-10 15:21:49 -08005434 }
5435 return true;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005436 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005437
5438 @Override
5439 public void keepScreenOnStartedLw() {
Daniel Sandler0601eb72011-04-13 01:01:32 -04005440 }
5441
Jeff Brownc38c9be2012-10-04 13:16:19 -07005442 @Override
5443 public void keepScreenOnStoppedLw() {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01005444 if (mKeyguardDelegate != null && !mKeyguardDelegate.isShowingAndNotOccluded()) {
Jim Miller25190572013-02-28 17:36:24 -08005445 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005446 }
5447 }
Mike Lockwoodfcb39242009-10-21 23:01:07 -04005448
Dianne Hackborndf89e652011-10-06 22:35:11 -07005449 private int updateSystemUiVisibilityLw() {
Joe Onorato664644d2011-01-23 17:53:23 -08005450 // If there is no window focused, there will be nobody to handle the events
5451 // anyway, so just hang on in whatever state we're in until things settle down.
John Spurlock79da8332013-09-20 12:04:47 -04005452 WindowState win = mFocusedWindow != null ? mFocusedWindow : mTopFullscreenOpaqueWindowState;
5453 if (win == null) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07005454 return 0;
5455 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01005456 if ((win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 && mHideLockScreen == true) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07005457 // We are updating at a point where the keyguard has gotten
5458 // focus, but we were last in a state where the top window is
5459 // hiding it. This is probably because the keyguard as been
5460 // shown while the top window was displayed, so we want to ignore
5461 // it here because this is just a very transient change and it
5462 // will quickly lose focus once it correctly gets hidden.
5463 return 0;
5464 }
John Spurlock32beb2c2013-03-11 10:16:47 -04005465
John Spurlock1db8b682014-02-18 11:18:59 -05005466 int tmpVisibility = PolicyControl.getSystemUiVisibility(win, null)
Dianne Hackborne26ab702011-10-16 13:21:33 -07005467 & ~mResettingSystemUiFlags
5468 & ~mForceClearedSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04005469 if (mForcingShowNavBar && win.getSurfaceLayer() < mForcingShowNavBarLayer) {
John Spurlockc6d1c602014-01-17 15:22:06 -05005470 tmpVisibility &= ~PolicyControl.adjustClearableFlags(win, View.SYSTEM_UI_CLEARABLE_FLAGS);
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08005471 }
John Spurlock79da8332013-09-20 12:04:47 -04005472 final int visibility = updateSystemBarsLw(win, mLastSystemUiFlags, tmpVisibility);
John Spurlockad3e6cb2013-04-30 08:47:43 -04005473 final int diff = visibility ^ mLastSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04005474 final boolean needsMenu = win.getNeedsMenuLw(mTopFullscreenOpaqueWindowState);
Dianne Hackborne0f085d2011-11-30 18:41:15 -08005475 if (diff == 0 && mLastFocusNeedsMenu == needsMenu
John Spurlock79da8332013-09-20 12:04:47 -04005476 && mFocusedApp == win.getAppToken()) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07005477 return 0;
5478 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07005479 mLastSystemUiFlags = visibility;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08005480 mLastFocusNeedsMenu = needsMenu;
John Spurlock79da8332013-09-20 12:04:47 -04005481 mFocusedApp = win.getAppToken();
Dianne Hackborndf89e652011-10-06 22:35:11 -07005482 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07005483 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07005484 public void run() {
Dianne Hackborn42e620c2012-06-24 13:20:51 -07005485 try {
5486 IStatusBarService statusbar = getStatusBarService();
5487 if (statusbar != null) {
5488 statusbar.setSystemUiVisibility(visibility, 0xffffffff);
5489 statusbar.topAppWindowChanged(needsMenu);
Joe Onorato664644d2011-01-23 17:53:23 -08005490 }
Dianne Hackborn42e620c2012-06-24 13:20:51 -07005491 } catch (RemoteException e) {
5492 // re-acquire status bar service next time it is needed.
5493 mStatusBarService = null;
Joe Onorato664644d2011-01-23 17:53:23 -08005494 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07005495 }
5496 });
5497 return diff;
Joe Onorato664644d2011-01-23 17:53:23 -08005498 }
5499
John Spurlock79da8332013-09-20 12:04:47 -04005500 private int updateSystemBarsLw(WindowState win, int oldVis, int vis) {
John Spurlockbd957402013-10-03 11:38:39 -04005501 // apply translucent bar vis flags
Jorim Jaggi380ecb82014-03-14 17:25:20 +01005502 WindowState transWin = isStatusBarKeyguard() && !mHideLockScreen
5503 ? mStatusBar
John Spurlockbd957402013-10-03 11:38:39 -04005504 : mTopFullscreenOpaqueWindowState;
5505 vis = mStatusBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
5506 vis = mNavigationBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
5507
John Spurlock27735a42013-08-14 17:57:38 -04005508 // prevent status bar interaction from clearing certain flags
John Spurlock79da8332013-09-20 12:04:47 -04005509 boolean statusBarHasFocus = win.getAttrs().type == TYPE_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04005510 if (statusBarHasFocus && !isStatusBarKeyguard()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04005511 int flags = View.SYSTEM_UI_FLAG_FULLSCREEN
5512 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlockcfc359a2013-09-05 10:42:03 -04005513 | View.SYSTEM_UI_FLAG_IMMERSIVE
Jorim Jaggi5cf17872014-03-26 18:31:48 +01005514 | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
John Spurlock08ffcf52014-07-11 10:13:46 -04005515 if (mHideLockScreen) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01005516 flags |= View.STATUS_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSLUCENT;
5517 }
John Spurlockbd957402013-10-03 11:38:39 -04005518 vis = (vis & ~flags) | (oldVis & flags);
John Spurlockad3e6cb2013-04-30 08:47:43 -04005519 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04005520
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04005521 if (!areTranslucentBarsAllowed()) {
Adrian Roosea562512014-05-05 13:33:03 +02005522 vis &= ~(View.NAVIGATION_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSLUCENT
5523 | View.SYSTEM_UI_TRANSPARENT);
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07005524 }
5525
John Spurlock27735a42013-08-14 17:57:38 -04005526 // update status bar
John Spurlockf1a36642013-10-12 17:50:42 -04005527 boolean immersiveSticky =
5528 (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
John Spurlock27735a42013-08-14 17:57:38 -04005529 boolean hideStatusBarWM =
John Spurlockbd957402013-10-03 11:38:39 -04005530 mTopFullscreenOpaqueWindowState != null &&
John Spurlockc6d1c602014-01-17 15:22:06 -05005531 (PolicyControl.getWindowFlags(mTopFullscreenOpaqueWindowState, null)
John Spurlock27735a42013-08-14 17:57:38 -04005532 & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0;
5533 boolean hideStatusBarSysui =
5534 (vis & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04005535 boolean hideNavBarSysui =
5536 (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0;
John Spurlockad3e6cb2013-04-30 08:47:43 -04005537
John Spurlock27735a42013-08-14 17:57:38 -04005538 boolean transientStatusBarAllowed =
5539 mStatusBar != null && (
5540 hideStatusBarWM
John Spurlockf1a36642013-10-12 17:50:42 -04005541 || (hideStatusBarSysui && immersiveSticky)
John Spurlock27735a42013-08-14 17:57:38 -04005542 || statusBarHasFocus);
5543
John Spurlockf1a36642013-10-12 17:50:42 -04005544 boolean transientNavBarAllowed =
5545 mNavigationBar != null &&
5546 hideNavBarSysui && immersiveSticky;
5547
John Spurlockf25706f2013-11-07 18:02:43 -05005548 boolean denyTransientStatus = mStatusBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04005549 && !transientStatusBarAllowed && hideStatusBarSysui;
John Spurlockf25706f2013-11-07 18:02:43 -05005550 boolean denyTransientNav = mNavigationBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04005551 && !transientNavBarAllowed;
5552 if (denyTransientStatus || denyTransientNav) {
John Spurlock27735a42013-08-14 17:57:38 -04005553 // clear the clearable flags instead
John Spurlockf1a36642013-10-12 17:50:42 -04005554 clearClearableFlagsLw();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005555 }
John Spurlock27735a42013-08-14 17:57:38 -04005556
5557 vis = mStatusBarController.updateVisibilityLw(transientStatusBarAllowed, oldVis, vis);
5558
5559 // update navigation bar
John Spurlockf1a36642013-10-12 17:50:42 -04005560 boolean oldImmersiveMode = isImmersiveMode(oldVis);
5561 boolean newImmersiveMode = isImmersiveMode(vis);
5562 if (win != null && oldImmersiveMode != newImmersiveMode) {
John Spurlock79da8332013-09-20 12:04:47 -04005563 final String pkg = win.getOwningPackage();
Maurice Lam99c6e072014-04-28 18:24:28 -07005564 mImmersiveModeConfirmation.immersiveModeChanged(pkg, newImmersiveMode,
5565 isUserSetupComplete());
John Spurlock34e13d92013-08-10 06:52:28 -04005566 }
John Spurlock27735a42013-08-14 17:57:38 -04005567
John Spurlockf1a36642013-10-12 17:50:42 -04005568 vis = mNavigationBarController.updateVisibilityLw(transientNavBarAllowed, oldVis, vis);
5569
John Spurlocke1f366f2013-08-05 12:22:40 -04005570 return vis;
John Spurlockad3e6cb2013-04-30 08:47:43 -04005571 }
5572
John Spurlockf1a36642013-10-12 17:50:42 -04005573 private void clearClearableFlagsLw() {
5574 int newVal = mResettingSystemUiFlags | View.SYSTEM_UI_CLEARABLE_FLAGS;
5575 if (newVal != mResettingSystemUiFlags) {
5576 mResettingSystemUiFlags = newVal;
5577 mWindowManagerFuncs.reevaluateStatusBarVisibility();
5578 }
5579 }
5580
5581 private boolean isImmersiveMode(int vis) {
5582 final int flags = View.SYSTEM_UI_FLAG_IMMERSIVE | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
John Spurlock34e13d92013-08-10 06:52:28 -04005583 return mNavigationBar != null
5584 && (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0
Daniel Sandler900ece52013-10-18 15:53:27 -04005585 && (vis & flags) != 0
5586 && canHideNavigationBar();
John Spurlock34e13d92013-08-10 06:52:28 -04005587 }
5588
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07005589 /**
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04005590 * @return whether the navigation or status bar can be made translucent
5591 *
5592 * This should return true unless touch exploration is not enabled or
5593 * R.boolean.config_enableTranslucentDecor is false.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07005594 */
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04005595 private boolean areTranslucentBarsAllowed() {
Svetoslav8e3feb12014-02-24 13:46:47 -08005596 return mTranslucentDecorEnabled
5597 && !mAccessibilityManager.isTouchExplorationEnabled();
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07005598 }
5599
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04005600 // Use this instead of checking config_showNavigationBar so that it can be consistently
5601 // overridden by qemu.hw.mainkeys in the emulator.
Craig Mautnereda67292013-04-28 13:50:14 -07005602 @Override
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04005603 public boolean hasNavigationBar() {
5604 return mHasNavigationBar;
5605 }
5606
satok1bc0a492012-04-25 22:47:12 +09005607 @Override
5608 public void setLastInputMethodWindowLw(WindowState ime, WindowState target) {
5609 mLastInputMethodWindow = ime;
5610 mLastInputMethodTargetWindow = target;
5611 }
5612
Craig Mautnerf1b67412012-09-19 13:18:29 -07005613 @Override
Satoshi Kataoka658c7b82013-10-10 17:03:51 +09005614 public int getInputMethodWindowVisibleHeightLw() {
5615 return mDockBottom - mCurBottom;
5616 }
5617
5618 @Override
Craig Mautnerf1b67412012-09-19 13:18:29 -07005619 public void setCurrentUserLw(int newUserId) {
Craig Mautnerd625ab22013-09-06 13:40:31 -07005620 mCurrentUserId = newUserId;
Jim Miller5ecd8112013-01-09 18:50:26 -08005621 if (mKeyguardDelegate != null) {
5622 mKeyguardDelegate.setCurrentUser(newUserId);
Craig Mautnerf1b67412012-09-19 13:18:29 -07005623 }
John Spurlock13451a22012-09-28 14:40:41 -04005624 if (mStatusBarService != null) {
5625 try {
5626 mStatusBarService.setCurrentUser(newUserId);
5627 } catch (RemoteException e) {
5628 // oh well
5629 }
5630 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07005631 setLastInputMethodWindowLw(null, null);
Craig Mautnerf1b67412012-09-19 13:18:29 -07005632 }
5633
5634 @Override
Svetoslav Ganov545252f2012-12-10 18:29:24 -08005635 public boolean canMagnifyWindow(int windowType) {
5636 switch (windowType) {
5637 case WindowManager.LayoutParams.TYPE_INPUT_METHOD:
5638 case WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG:
5639 case WindowManager.LayoutParams.TYPE_NAVIGATION_BAR:
5640 case WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY: {
5641 return false;
5642 }
5643 }
5644 return true;
5645 }
5646
5647 @Override
5648 public boolean isTopLevelWindow(int windowType) {
5649 if (windowType >= WindowManager.LayoutParams.FIRST_SUB_WINDOW
5650 && windowType <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
5651 return (windowType == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG);
5652 }
5653 return true;
5654 }
5655
Jim Miller4eeb4f62012-11-08 00:04:29 -08005656 @Override
Jeff Brownd7a04de2012-06-17 14:17:52 -07005657 public void dump(String prefix, PrintWriter pw, String[] args) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005658 pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005659 pw.print(" mSystemReady="); pw.print(mSystemReady);
5660 pw.print(" mSystemBooted="); pw.println(mSystemBooted);
Jeff Brown2e7760e2012-04-11 15:14:55 -07005661 pw.print(prefix); pw.print("mLidState="); pw.print(mLidState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005662 pw.print(" mLidOpenRotation="); pw.print(mLidOpenRotation);
5663 pw.print(" mHdmiPlugged="); pw.println(mHdmiPlugged);
Dianne Hackborne26ab702011-10-16 13:21:33 -07005664 if (mLastSystemUiFlags != 0 || mResettingSystemUiFlags != 0
5665 || mForceClearedSystemUiFlags != 0) {
5666 pw.print(prefix); pw.print("mLastSystemUiFlags=0x");
5667 pw.print(Integer.toHexString(mLastSystemUiFlags));
5668 pw.print(" mResettingSystemUiFlags=0x");
5669 pw.print(Integer.toHexString(mResettingSystemUiFlags));
5670 pw.print(" mForceClearedSystemUiFlags=0x");
5671 pw.println(Integer.toHexString(mForceClearedSystemUiFlags));
Dianne Hackborndf89e652011-10-06 22:35:11 -07005672 }
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08005673 if (mLastFocusNeedsMenu) {
5674 pw.print(prefix); pw.print("mLastFocusNeedsMenu=");
5675 pw.println(mLastFocusNeedsMenu);
5676 }
Jeff Browna20dda42014-05-27 20:57:24 -07005677 pw.print(prefix); pw.print("mWakeGestureEnabledSetting=");
5678 pw.println(mWakeGestureEnabledSetting);
5679
Jeff Brownbcdfc622014-03-06 19:13:04 -08005680 pw.print(prefix); pw.print("mSupportAutoRotation="); pw.println(mSupportAutoRotation);
Daniel Sandler6396c722013-04-16 20:19:09 -04005681 pw.print(prefix); pw.print("mUiMode="); pw.print(mUiMode);
5682 pw.print(" mDockMode="); pw.print(mDockMode);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005683 pw.print(" mCarDockRotation="); pw.print(mCarDockRotation);
5684 pw.print(" mDeskDockRotation="); pw.println(mDeskDockRotation);
5685 pw.print(prefix); pw.print("mUserRotationMode="); pw.print(mUserRotationMode);
5686 pw.print(" mUserRotation="); pw.print(mUserRotation);
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005687 pw.print(" mAllowAllRotations="); pw.println(mAllowAllRotations);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07005688 pw.print(prefix); pw.print("mCurrentAppOrientation="); pw.println(mCurrentAppOrientation);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005689 pw.print(prefix); pw.print("mCarDockEnablesAccelerometer=");
5690 pw.print(mCarDockEnablesAccelerometer);
5691 pw.print(" mDeskDockEnablesAccelerometer=");
5692 pw.println(mDeskDockEnablesAccelerometer);
5693 pw.print(prefix); pw.print("mLidKeyboardAccessibility=");
5694 pw.print(mLidKeyboardAccessibility);
5695 pw.print(" mLidNavigationAccessibility="); pw.print(mLidNavigationAccessibility);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07005696 pw.print(" mLidControlsSleep="); pw.println(mLidControlsSleep);
Jeff Brown6d8fd272014-05-20 21:24:38 -07005697 pw.print(prefix);
5698 pw.print("mShortPressOnPowerBehavior="); pw.print(mShortPressOnPowerBehavior);
5699 pw.print(" mLongPressOnPowerBehavior="); pw.println(mLongPressOnPowerBehavior);
5700 pw.print(prefix); pw.print("mHasSoftInput="); pw.println(mHasSoftInput);
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07005701 pw.print(prefix); pw.print("mScreenOnEarly="); pw.print(mScreenOnEarly);
5702 pw.print(" mScreenOnFully="); pw.print(mScreenOnFully);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07005703 pw.print(" mOrientationSensorEnabled="); pw.println(mOrientationSensorEnabled);
Dianne Hackbornc652de82013-02-15 16:32:56 -08005704 pw.print(prefix); pw.print("mOverscanScreen=("); pw.print(mOverscanScreenLeft);
5705 pw.print(","); pw.print(mOverscanScreenTop);
5706 pw.print(") "); pw.print(mOverscanScreenWidth);
5707 pw.print("x"); pw.println(mOverscanScreenHeight);
5708 if (mOverscanLeft != 0 || mOverscanTop != 0
5709 || mOverscanRight != 0 || mOverscanBottom != 0) {
5710 pw.print(prefix); pw.print("mOverscan left="); pw.print(mOverscanLeft);
5711 pw.print(" top="); pw.print(mOverscanTop);
5712 pw.print(" right="); pw.print(mOverscanRight);
5713 pw.print(" bottom="); pw.println(mOverscanBottom);
5714 }
Dianne Hackborn313440842013-02-19 19:22:59 -08005715 pw.print(prefix); pw.print("mRestrictedOverscanScreen=(");
5716 pw.print(mRestrictedOverscanScreenLeft);
5717 pw.print(","); pw.print(mRestrictedOverscanScreenTop);
5718 pw.print(") "); pw.print(mRestrictedOverscanScreenWidth);
5719 pw.print("x"); pw.println(mRestrictedOverscanScreenHeight);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005720 pw.print(prefix); pw.print("mUnrestrictedScreen=("); pw.print(mUnrestrictedScreenLeft);
5721 pw.print(","); pw.print(mUnrestrictedScreenTop);
5722 pw.print(") "); pw.print(mUnrestrictedScreenWidth);
5723 pw.print("x"); pw.println(mUnrestrictedScreenHeight);
5724 pw.print(prefix); pw.print("mRestrictedScreen=("); pw.print(mRestrictedScreenLeft);
5725 pw.print(","); pw.print(mRestrictedScreenTop);
5726 pw.print(") "); pw.print(mRestrictedScreenWidth);
5727 pw.print("x"); pw.println(mRestrictedScreenHeight);
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07005728 pw.print(prefix); pw.print("mStableFullscreen=("); pw.print(mStableFullscreenLeft);
5729 pw.print(","); pw.print(mStableFullscreenTop);
5730 pw.print(")-("); pw.print(mStableFullscreenRight);
5731 pw.print(","); pw.print(mStableFullscreenBottom); pw.println(")");
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07005732 pw.print(prefix); pw.print("mStable=("); pw.print(mStableLeft);
5733 pw.print(","); pw.print(mStableTop);
5734 pw.print(")-("); pw.print(mStableRight);
5735 pw.print(","); pw.print(mStableBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07005736 pw.print(prefix); pw.print("mSystem=("); pw.print(mSystemLeft);
5737 pw.print(","); pw.print(mSystemTop);
5738 pw.print(")-("); pw.print(mSystemRight);
5739 pw.print(","); pw.print(mSystemBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005740 pw.print(prefix); pw.print("mCur=("); pw.print(mCurLeft);
5741 pw.print(","); pw.print(mCurTop);
5742 pw.print(")-("); pw.print(mCurRight);
5743 pw.print(","); pw.print(mCurBottom); pw.println(")");
5744 pw.print(prefix); pw.print("mContent=("); pw.print(mContentLeft);
5745 pw.print(","); pw.print(mContentTop);
5746 pw.print(")-("); pw.print(mContentRight);
5747 pw.print(","); pw.print(mContentBottom); pw.println(")");
Dianne Hackborne30e02f2014-05-27 18:24:45 -07005748 pw.print(prefix); pw.print("mVoiceContent=("); pw.print(mVoiceContentLeft);
5749 pw.print(","); pw.print(mVoiceContentTop);
5750 pw.print(")-("); pw.print(mVoiceContentRight);
5751 pw.print(","); pw.print(mVoiceContentBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005752 pw.print(prefix); pw.print("mDock=("); pw.print(mDockLeft);
5753 pw.print(","); pw.print(mDockTop);
5754 pw.print(")-("); pw.print(mDockRight);
5755 pw.print(","); pw.print(mDockBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07005756 pw.print(prefix); pw.print("mDockLayer="); pw.print(mDockLayer);
5757 pw.print(" mStatusBarLayer="); pw.println(mStatusBarLayer);
Dianne Hackborn7ad44382012-10-18 17:46:00 -07005758 pw.print(prefix); pw.print("mShowingLockscreen="); pw.print(mShowingLockscreen);
5759 pw.print(" mShowingDream="); pw.print(mShowingDream);
5760 pw.print(" mDreamingLockscreen="); pw.println(mDreamingLockscreen);
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07005761 if (mLastInputMethodWindow != null) {
5762 pw.print(prefix); pw.print("mLastInputMethodWindow=");
5763 pw.println(mLastInputMethodWindow);
5764 }
5765 if (mLastInputMethodTargetWindow != null) {
5766 pw.print(prefix); pw.print("mLastInputMethodTargetWindow=");
5767 pw.println(mLastInputMethodTargetWindow);
5768 }
5769 if (mStatusBar != null) {
5770 pw.print(prefix); pw.print("mStatusBar=");
5771 pw.println(mStatusBar);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01005772 pw.print(prefix); pw.print("isStatusBarKeyguard=");
5773 pw.print(isStatusBarKeyguard());
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07005774 }
5775 if (mNavigationBar != null) {
5776 pw.print(prefix); pw.print("mNavigationBar=");
5777 pw.println(mNavigationBar);
5778 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07005779 if (mFocusedWindow != null) {
5780 pw.print(prefix); pw.print("mFocusedWindow=");
5781 pw.println(mFocusedWindow);
5782 }
5783 if (mFocusedApp != null) {
5784 pw.print(prefix); pw.print("mFocusedApp=");
5785 pw.println(mFocusedApp);
5786 }
5787 if (mWinDismissingKeyguard != null) {
5788 pw.print(prefix); pw.print("mWinDismissingKeyguard=");
5789 pw.println(mWinDismissingKeyguard);
5790 }
5791 if (mTopFullscreenOpaqueWindowState != null) {
5792 pw.print(prefix); pw.print("mTopFullscreenOpaqueWindowState=");
5793 pw.println(mTopFullscreenOpaqueWindowState);
5794 }
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08005795 if (mForcingShowNavBar) {
5796 pw.print(prefix); pw.print("mForcingShowNavBar=");
5797 pw.println(mForcingShowNavBar); pw.print( "mForcingShowNavBarLayer=");
5798 pw.println(mForcingShowNavBarLayer);
5799 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07005800 pw.print(prefix); pw.print("mTopIsFullscreen="); pw.print(mTopIsFullscreen);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005801 pw.print(" mHideLockScreen="); pw.println(mHideLockScreen);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07005802 pw.print(prefix); pw.print("mForceStatusBar="); pw.print(mForceStatusBar);
5803 pw.print(" mForceStatusBarFromKeyguard=");
5804 pw.println(mForceStatusBarFromKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005805 pw.print(prefix); pw.print("mDismissKeyguard="); pw.print(mDismissKeyguard);
Craig Mautnerad09bcc2012-10-08 13:33:11 -07005806 pw.print(" mWinDismissingKeyguard="); pw.print(mWinDismissingKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005807 pw.print(" mHomePressed="); pw.println(mHomePressed);
5808 pw.print(prefix); pw.print("mAllowLockscreenWhenOn="); pw.print(mAllowLockscreenWhenOn);
5809 pw.print(" mLockScreenTimeout="); pw.print(mLockScreenTimeout);
5810 pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive);
5811 pw.print(prefix); pw.print("mEndcallBehavior="); pw.print(mEndcallBehavior);
5812 pw.print(" mIncallPowerBehavior="); pw.print(mIncallPowerBehavior);
5813 pw.print(" mLongPressOnHomeBehavior="); pw.println(mLongPressOnHomeBehavior);
5814 pw.print(prefix); pw.print("mLandscapeRotation="); pw.print(mLandscapeRotation);
5815 pw.print(" mSeascapeRotation="); pw.println(mSeascapeRotation);
5816 pw.print(prefix); pw.print("mPortraitRotation="); pw.print(mPortraitRotation);
5817 pw.print(" mUpsideDownRotation="); pw.println(mUpsideDownRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07005818 pw.print(prefix); pw.print("mDemoHdmiRotation="); pw.print(mDemoHdmiRotation);
5819 pw.print(" mDemoHdmiRotationLock="); pw.println(mDemoHdmiRotationLock);
5820 pw.print(prefix); pw.print("mUndockedHdmiRotation="); pw.println(mUndockedHdmiRotation);
Jeff Brown600f0032014-05-22 17:06:00 -07005821
Tim Kilbournd7c0c2e2014-05-29 16:08:10 -07005822 mGlobalKeyManager.dump(prefix, pw);
John Spurlock27735a42013-08-14 17:57:38 -04005823 mStatusBarController.dump(pw, prefix);
5824 mNavigationBarController.dump(pw, prefix);
John Spurlockc6d1c602014-01-17 15:22:06 -05005825 PolicyControl.dump(prefix, pw);
Jeff Brown600f0032014-05-22 17:06:00 -07005826
Jeff Browna20dda42014-05-27 20:57:24 -07005827 if (mWakeGestureListener != null) {
5828 mWakeGestureListener.dump(pw, prefix);
5829 }
Jeff Brown600f0032014-05-22 17:06:00 -07005830 if (mOrientationListener != null) {
5831 mOrientationListener.dump(pw, prefix);
5832 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005833 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005834}