blob: c668f5a6eea5db9a0adfe6f737df94ee6a9d1e66 [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;
RoboErik8a2cfc32014-05-16 11:19:38 -070048import android.media.session.MediaSessionLegacyHelper;
Dianne Hackborn38e29a62011-09-18 14:43:08 -070049import android.os.Bundle;
Jeff Brown9a538ee2012-08-20 14:56:57 -070050import android.os.FactoryTest;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080051import android.os.Handler;
52import android.os.IBinder;
Jeff Brown32cbc38552011-12-01 14:01:49 -080053import android.os.Looper;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -070054import android.os.Message;
55import android.os.Messenger;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080056import android.os.PowerManager;
57import android.os.RemoteException;
58import android.os.ServiceManager;
59import android.os.SystemClock;
60import android.os.SystemProperties;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -080061import android.os.UEventObserver;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -070062import android.os.UserHandle;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080063import android.os.Vibrator;
64import android.provider.Settings;
Jose Lima9546b202014-07-02 17:21:51 -070065import android.service.dreams.DreamManagerInternal;
John Spurlockc8b46ca2013-04-08 12:59:26 -040066import android.service.dreams.DreamService;
67import android.service.dreams.IDreamManager;
Santos Cordon9eb45932014-06-27 12:28:43 -070068import android.telecomm.TelecommManager;
Dianne Hackborn81e56d52011-05-26 00:55:58 -070069import android.util.DisplayMetrics;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080070import android.util.EventLog;
71import android.util.Log;
Jeff Browna41ca772010-08-11 14:46:32 -070072import android.util.Slog;
Jeff Brown6651a632011-11-28 12:59:11 -080073import android.util.SparseArray;
Dianne Hackbornf87d1962012-04-04 12:48:24 -070074import android.view.Display;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080075import android.view.Gravity;
76import android.view.HapticFeedbackConstants;
Dianne Hackborne0f085d2011-11-30 18:41:15 -080077import android.view.IApplicationToken;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080078import android.view.IWindowManager;
Jeff Browna41ca772010-08-11 14:46:32 -070079import android.view.InputChannel;
Jeff Brown4d396052010-10-29 21:50:21 -070080import android.view.InputDevice;
Jeff Brown4952dfd2011-11-30 19:23:22 -080081import android.view.InputEvent;
Jeff Brown32cbc38552011-12-01 14:01:49 -080082import android.view.InputEventReceiver;
Jeff Brown6b53e8d2010-11-10 16:03:06 -080083import android.view.KeyCharacterMap;
Craig Mautnerae446592012-12-06 19:05:05 -080084import android.view.KeyCharacterMap.FallbackAction;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080085import android.view.KeyEvent;
86import android.view.MotionEvent;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080087import android.view.Surface;
88import android.view.View;
89import android.view.ViewConfiguration;
90import android.view.Window;
91import android.view.WindowManager;
Craig Mautnerae446592012-12-06 19:05:05 -080092import android.view.WindowManagerGlobal;
Craig Mautner8a0da012014-05-31 15:13:37 -070093import android.view.WindowManagerInternal;
Craig Mautnerae446592012-12-06 19:05:05 -080094import android.view.WindowManagerPolicy;
Craig Mautnerae446592012-12-06 19:05:05 -080095import android.view.accessibility.AccessibilityEvent;
Svetoslav8e3feb12014-02-24 13:46:47 -080096import android.view.accessibility.AccessibilityManager;
Craig Mautnerae446592012-12-06 19:05:05 -080097import android.view.animation.Animation;
98import android.view.animation.AnimationUtils;
99
100import com.android.internal.R;
Jorim Jaggi380ecb82014-03-14 17:25:20 +0100101import com.android.internal.policy.IKeyguardService;
102import com.android.internal.policy.IKeyguardServiceConstants;
Craig Mautnerae446592012-12-06 19:05:05 -0800103import com.android.internal.policy.PolicyManager;
Jim Miller5ecd8112013-01-09 18:50:26 -0800104import com.android.internal.policy.impl.keyguard.KeyguardServiceDelegate;
Craig Mautner8a0da012014-05-31 15:13:37 -0700105import com.android.internal.policy.impl.keyguard.KeyguardServiceDelegate.ShowListener;
Craig Mautnerae446592012-12-06 19:05:05 -0800106import com.android.internal.statusbar.IStatusBarService;
Craig Mautnerae446592012-12-06 19:05:05 -0800107import com.android.internal.widget.PointerLocationView;
Craig Mautner8a0da012014-05-31 15:13:37 -0700108import com.android.server.LocalServices;
Craig Mautnerae446592012-12-06 19:05:05 -0800109
110import java.io.File;
111import java.io.FileReader;
112import java.io.IOException;
113import java.io.PrintWriter;
Craig Mautner8a0da012014-05-31 15:13:37 -0700114import java.util.ArrayList;
Craig Mautner2bc789b2014-03-19 19:48:38 -0700115import java.util.HashSet;
Craig Mautnerae446592012-12-06 19:05:05 -0800116
Dianne Hackbornc652de82013-02-15 16:32:56 -0800117import static android.view.WindowManager.LayoutParams.*;
Jeff Brownac143512012-04-05 18:57:33 -0700118import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_ABSENT;
119import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_OPEN;
120import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_CLOSED;
Dianne Hackborn08743722009-12-21 12:16:51 -0800121
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800122/**
The Android Open Source Project0727d222009-03-11 12:11:58 -0700123 * WindowManagerPolicy implementation for the Android phone UI. This
124 * introduces a new method suffix, Lp, for an internal lock of the
125 * PhoneWindowManager. This is used to protect some internal state, and
John Spurlock04db1762013-05-13 12:46:41 -0400126 * 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 -0700127 * of both of those when held.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800128 */
129public class PhoneWindowManager implements WindowManagerPolicy {
130 static final String TAG = "WindowManager";
131 static final boolean DEBUG = false;
Joe Onorato43a17652011-04-06 19:22:23 -0700132 static final boolean localLOGV = false;
The Android Open Source Project11267662009-03-18 17:39:47 -0700133 static final boolean DEBUG_LAYOUT = false;
Jeff Brown40013652012-05-16 21:22:36 -0700134 static final boolean DEBUG_INPUT = false;
Craig Mautner6fbda632012-07-03 09:26:39 -0700135 static final boolean DEBUG_STARTING_WINDOW = false;
Craig Mautner8a0da012014-05-31 15:13:37 -0700136 static final boolean DEBUG_WAKEUP = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800137 static final boolean SHOW_STARTING_ANIMATIONS = true;
138 static final boolean SHOW_PROCESSES_ON_ALT_MENU = false;
Joe Onoratod208e702010-10-08 16:22:43 -0400139
Daniel Sandler6396c722013-04-16 20:19:09 -0400140 // Whether to allow dock apps with METADATA_DOCK_HOME to temporarily take over the Home key.
141 // No longer recommended for desk docks; still useful in car docks.
142 static final boolean ENABLE_CAR_DOCK_HOME_CAPTURE = true;
143 static final boolean ENABLE_DESK_DOCK_HOME_CAPTURE = false;
144
Jeff Brown6d8fd272014-05-20 21:24:38 -0700145 static final int SHORT_PRESS_POWER_NOTHING = 0;
146 static final int SHORT_PRESS_POWER_GO_TO_SLEEP = 1;
147 static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP = 2;
148 static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME = 3;
149
Joe Onoratod208e702010-10-08 16:22:43 -0400150 static final int LONG_PRESS_POWER_NOTHING = 0;
151 static final int LONG_PRESS_POWER_GLOBAL_ACTIONS = 1;
152 static final int LONG_PRESS_POWER_SHUT_OFF = 2;
Jeff Brown9a538ee2012-08-20 14:56:57 -0700153 static final int LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM = 3;
Michael Jurka3b1fc472011-06-13 10:54:40 -0700154
155 // These need to match the documentation/constant in
156 // core/res/res/values/config.xml
Joe Onorato46b0d682010-11-22 17:37:27 -0800157 static final int LONG_PRESS_HOME_NOTHING = 0;
Michael Wrightc9ebea72013-01-16 19:25:02 -0800158 static final int LONG_PRESS_HOME_RECENT_SYSTEM_UI = 1;
Jeff Browncaca8812013-05-09 13:34:33 -0700159 static final int LONG_PRESS_HOME_ASSIST = 2;
160
161 static final int DOUBLE_TAP_HOME_NOTHING = 0;
162 static final int DOUBLE_TAP_HOME_RECENT_SYSTEM_UI = 1;
Joe Onorato46b0d682010-11-22 17:37:27 -0800163
Dianne Hackborn5cb8d792009-05-21 17:34:15 -0700164 static final int APPLICATION_MEDIA_SUBLAYER = -2;
165 static final int APPLICATION_MEDIA_OVERLAY_SUBLAYER = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800166 static final int APPLICATION_PANEL_SUBLAYER = 1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800167 static final int APPLICATION_SUB_PANEL_SUBLAYER = 2;
Craig Mautner88400d32012-09-30 12:35:45 -0700168
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800169 static public final String SYSTEM_DIALOG_REASON_KEY = "reason";
170 static public final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions";
171 static public final String SYSTEM_DIALOG_REASON_RECENT_APPS = "recentapps";
Joe Onoratof275f0c2009-11-24 16:11:13 -0500172 static public final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey";
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700173 static public final String SYSTEM_DIALOG_REASON_ASSIST = "assist";
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800174
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700175 /**
176 * These are the system UI flags that, when changing, can cause the layout
177 * of the screen to change.
178 */
179 static final int SYSTEM_UI_CHANGING_LAYOUT =
John Spurlocke1f366f2013-08-05 12:22:40 -0400180 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlock7f4820a2013-10-08 12:54:35 -0400181 | View.SYSTEM_UI_FLAG_FULLSCREEN
182 | View.STATUS_BAR_TRANSLUCENT
Adrian Roosea562512014-05-05 13:33:03 +0200183 | View.NAVIGATION_BAR_TRANSLUCENT
184 | View.SYSTEM_UI_TRANSPARENT;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700185
Jim Miller5ecd8112013-01-09 18:50:26 -0800186 /**
187 * Keyguard stuff
188 */
189 private WindowState mKeyguardScrim;
Jorim Jaggi380ecb82014-03-14 17:25:20 +0100190 private boolean mKeyguardHidden;
Jorim Jaggicff0acb2014-03-31 16:35:15 +0200191 private boolean mKeyguardDrawn;
Jim Miller5ecd8112013-01-09 18:50:26 -0800192
Jeff Brown6651a632011-11-28 12:59:11 -0800193 /* Table of Application Launch keys. Maps from key codes to intent categories.
194 *
195 * These are special keys that are used to launch particular kinds of applications,
196 * such as a web browser. HID defines nearly a hundred of them in the Consumer (0x0C)
197 * usage page. We don't support quite that many yet...
198 */
199 static SparseArray<String> sApplicationLaunchKeyCategories;
200 static {
201 sApplicationLaunchKeyCategories = new SparseArray<String>();
202 sApplicationLaunchKeyCategories.append(
203 KeyEvent.KEYCODE_EXPLORER, Intent.CATEGORY_APP_BROWSER);
204 sApplicationLaunchKeyCategories.append(
205 KeyEvent.KEYCODE_ENVELOPE, Intent.CATEGORY_APP_EMAIL);
206 sApplicationLaunchKeyCategories.append(
207 KeyEvent.KEYCODE_CONTACTS, Intent.CATEGORY_APP_CONTACTS);
208 sApplicationLaunchKeyCategories.append(
209 KeyEvent.KEYCODE_CALENDAR, Intent.CATEGORY_APP_CALENDAR);
210 sApplicationLaunchKeyCategories.append(
211 KeyEvent.KEYCODE_MUSIC, Intent.CATEGORY_APP_MUSIC);
212 sApplicationLaunchKeyCategories.append(
213 KeyEvent.KEYCODE_CALCULATOR, Intent.CATEGORY_APP_CALCULATOR);
214 }
215
Dianne Hackborndf89e652011-10-06 22:35:11 -0700216 /**
217 * Lock protecting internal state. Must not call out into window
218 * manager with lock held. (This lock will be acquired in places
219 * where the window manager is calling in with its own lock held.)
220 */
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800221 private final Object mLock = new Object();
Dianne Hackborndf89e652011-10-06 22:35:11 -0700222
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800223 Context mContext;
224 IWindowManager mWindowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700225 WindowManagerFuncs mWindowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -0700226 WindowManagerInternal mWindowManagerInternal;
Jeff Brown96307042012-07-27 15:51:34 -0700227 PowerManager mPowerManager;
Jose Lima9546b202014-07-02 17:21:51 -0700228 DreamManagerInternal mDreamManagerInternal;
Joe Onorato93056472010-09-10 10:30:46 -0400229 IStatusBarService mStatusBarService;
Jeff Browncaca8812013-05-09 13:34:33 -0700230 boolean mPreloadedRecentApps;
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700231 final Object mServiceAquireLock = new Object();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800232 Vibrator mVibrator; // Vibrator for giving feedback of orientation changes
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700233 SearchManager mSearchManager;
Svetoslav8e3feb12014-02-24 13:46:47 -0800234 AccessibilityManager mAccessibilityManager;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800235
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700236 // Vibrator pattern for haptic feedback of a long press.
237 long[] mLongPressVibePattern;
Craig Mautner88400d32012-09-30 12:35:45 -0700238
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700239 // Vibrator pattern for haptic feedback of virtual key press.
240 long[] mVirtualKeyVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700241
Amith Yamasanic33cb712010-02-10 15:21:49 -0800242 // Vibrator pattern for a short vibration.
243 long[] mKeyboardTapVibePattern;
244
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -0700245 // Vibrator pattern for a short vibration when tapping on an hour/minute tick of a Clock.
246 long[] mClockTickVibePattern;
247
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700248 // Vibrator pattern for haptic feedback during boot when safe mode is disabled.
249 long[] mSafeModeDisabledVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700250
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700251 // Vibrator pattern for haptic feedback during boot when safe mode is enabled.
252 long[] mSafeModeEnabledVibePattern;
Romain Guy8154cd32010-03-29 14:41:15 -0700253
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800254 /** If true, hitting shift & menu will broadcast Intent.ACTION_BUG_REPORT */
255 boolean mEnableShiftMenuBugReports = false;
Mike Lockwoodd747dc82011-09-13 16:28:22 -0400256
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800257 boolean mSafeMode;
258 WindowState mStatusBar = null;
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700259 int mStatusBarHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400260 WindowState mNavigationBar = null;
Daniel Sandler36412a72011-08-04 09:35:13 -0400261 boolean mHasNavigationBar = false;
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700262 boolean mCanHideNavigationBar = false;
Daniel Sandler4a066c52012-04-20 14:49:13 -0400263 boolean mNavigationBarCanMove = false; // can the navigation bar ever move to the side?
264 boolean mNavigationBarOnBottom = true; // is the navigation bar on the bottom *right now*?
265 int[] mNavigationBarHeightForRotation = new int[4];
266 int[] mNavigationBarWidthForRotation = new int[4];
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400267
Jim Miller5ecd8112013-01-09 18:50:26 -0800268 KeyguardServiceDelegate mKeyguardDelegate;
Craig Mautner8a0da012014-05-31 15:13:37 -0700269 // The following are only accessed on the mHandler thread.
270 boolean mKeyguardDrawComplete;
271 boolean mWindowManagerDrawComplete;
Craig Mautner13f6ea72014-06-23 14:57:02 -0700272 ScreenOnListener mScreenOnListener;
273 final Runnable mWindowManagerDrawCallback = new Runnable() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700274 @Override
Craig Mautner13f6ea72014-06-23 14:57:02 -0700275 public void run() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700276 if (DEBUG_WAKEUP) Slog.i(TAG, "All windows ready for display!");
277 mHandler.sendEmptyMessage(MSG_WINDOW_MANAGER_DRAWN_COMPLETE);
278 }
279 };
280 final ShowListener mKeyguardDelegateCallback = new ShowListener() {
281 @Override
282 public void onShown(IBinder windowToken) {
283 if (DEBUG_WAKEUP) Slog.d(TAG, "mKeyguardDelegate.ShowListener.onShown.");
284 mHandler.sendEmptyMessage(MSG_KEYGUARD_DRAWN_COMPLETE);
285 }
286 };
287
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800288 GlobalActions mGlobalActions;
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700289 volatile boolean mPowerKeyHandled; // accessed from input reader and handler thread
290 boolean mPendingPowerKeyUpCanceled;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800291 Handler mHandler;
satok1bc0a492012-04-25 22:47:12 +0900292 WindowState mLastInputMethodWindow = null;
293 WindowState mLastInputMethodTargetWindow = null;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800294
Winson Chungd42a6cf2014-06-03 16:24:04 -0700295 boolean mRecentsVisible;
Winson Chung1e8d71b2014-05-16 17:05:22 -0700296 int mRecentAppsHeldModifiers;
Jeff Browncf39bdf2012-05-18 14:41:19 -0700297 boolean mLanguageSwitchKeyPressed;
Jeff Brown68b909d2011-12-07 16:36:01 -0800298
Jeff Brown2e7760e2012-04-11 15:14:55 -0700299 int mLidState = LID_ABSENT;
Jeff Browndaa37532012-05-01 15:54:03 -0700300 boolean mHaveBuiltInKeyboard;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800301
Dianne Hackbornc777e072010-02-12 13:07:59 -0800302 boolean mSystemReady;
Dianne Hackbornba24e4d2011-09-01 11:17:06 -0700303 boolean mSystemBooted;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800304 boolean mHdmiPlugged;
Jeff Brown4f5fa282014-06-12 19:19:15 -0700305 IUiModeManager mUiModeManager;
Daniel Sandler6396c722013-04-16 20:19:09 -0400306 int mUiMode;
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700307 int mDockMode = Intent.EXTRA_DOCK_STATE_UNDOCKED;
Mike Lockwood1753f7f2009-08-24 14:49:07 -0700308 int mLidOpenRotation;
Mike Lockwood2d1efbd2009-09-16 12:15:53 -0400309 int mCarDockRotation;
310 int mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -0700311 int mUndockedHdmiRotation;
312 int mDemoHdmiRotation;
313 boolean mDemoHdmiRotationLock;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400314
Jeff Browna20dda42014-05-27 20:57:24 -0700315 boolean mWakeGestureEnabledSetting;
316 MyWakeGestureListener mWakeGestureListener;
317
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700318 // Default display does not rotate, apps that require non-default orientation will have to
319 // have the orientation emulated.
320 private boolean mForceDefaultOrientation = false;
321
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400322 int mUserRotationMode = WindowManagerPolicy.USER_ROTATION_FREE;
323 int mUserRotation = Surface.ROTATION_0;
Jeff Brown207673cd2012-06-05 17:47:11 -0700324 boolean mAccelerometerDefault;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400325
Jeff Brownbcdfc622014-03-06 19:13:04 -0800326 boolean mSupportAutoRotation;
Jeff Brownd3187e32011-09-21 19:26:44 -0700327 int mAllowAllRotations = -1;
Mike Lockwoode9867d22009-09-20 01:59:02 -0400328 boolean mCarDockEnablesAccelerometer;
329 boolean mDeskDockEnablesAccelerometer;
Dianne Hackborn2862fff2009-09-15 22:56:29 -0700330 int mLidKeyboardAccessibility;
331 int mLidNavigationAccessibility;
Jeff Brownc458ce92012-04-30 14:58:40 -0700332 boolean mLidControlsSleep;
Jeff Brown6d8fd272014-05-20 21:24:38 -0700333 int mShortPressOnPowerBehavior = -1;
Joe Onoratod208e702010-10-08 16:22:43 -0400334 int mLongPressOnPowerBehavior = -1;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -0700335 boolean mScreenOnEarly = false;
336 boolean mScreenOnFully = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800337 boolean mOrientationSensorEnabled = false;
338 int mCurrentAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800339 boolean mHasSoftInput = false;
Daniel Sandlerdd73ee42013-10-11 22:19:59 -0400340 boolean mTranslucentDecorEnabled = true;
Craig Mautner967212c2013-04-13 21:10:58 -0700341
Jeff Brown70825162012-03-28 17:27:48 -0700342 int mPointerLocationMode = 0; // guarded by mLock
Joe Onorato664644d2011-01-23 17:53:23 -0800343
344 // The last window we were told about in focusChanged.
345 WindowState mFocusedWindow;
Dianne Hackborne0f085d2011-11-30 18:41:15 -0800346 IApplicationToken mFocusedApp;
Joe Onorato664644d2011-01-23 17:53:23 -0800347
Jeff Brown70825162012-03-28 17:27:48 -0700348 PointerLocationView mPointerLocationView;
Jeff Brown32cbc38552011-12-01 14:01:49 -0800349
Dianne Hackbornc652de82013-02-15 16:32:56 -0800350 // The current size of the screen; really; extends into the overscan area of
351 // the screen and doesn't account for any system elements like the status bar.
352 int mOverscanScreenLeft, mOverscanScreenTop;
353 int mOverscanScreenWidth, mOverscanScreenHeight;
354 // The current visible size of the screen; really; (ir)regardless of whether the status
355 // bar can be hidden but not extending into the overscan area.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800356 int mUnrestrictedScreenLeft, mUnrestrictedScreenTop;
357 int mUnrestrictedScreenWidth, mUnrestrictedScreenHeight;
Dianne Hackborn313440842013-02-19 19:22:59 -0800358 // Like mOverscanScreen*, but allowed to move into the overscan region where appropriate.
359 int mRestrictedOverscanScreenLeft, mRestrictedOverscanScreenTop;
360 int mRestrictedOverscanScreenWidth, mRestrictedOverscanScreenHeight;
Dianne Hackborn82de1ae2010-10-28 11:28:39 -0700361 // The current size of the screen; these may be different than (0,0)-(dw,dh)
362 // if the status bar can't be hidden; in that case it effectively carves out
363 // that area of the display from all other windows.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800364 int mRestrictedScreenLeft, mRestrictedScreenTop;
365 int mRestrictedScreenWidth, mRestrictedScreenHeight;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700366 // During layout, the current screen borders accounting for any currently
367 // visible system UI elements.
368 int mSystemLeft, mSystemTop, mSystemRight, mSystemBottom;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700369 // For applications requesting stable content insets, these are them.
370 int mStableLeft, mStableTop, mStableRight, mStableBottom;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -0700371 // For applications requesting stable content insets but have also set the
372 // fullscreen window flag, these are the stable dimensions without the status bar.
373 int mStableFullscreenLeft, mStableFullscreenTop;
374 int mStableFullscreenRight, mStableFullscreenBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800375 // During layout, the current screen borders with all outer decoration
376 // (status bar, input method dock) accounted for.
377 int mCurLeft, mCurTop, mCurRight, mCurBottom;
378 // During layout, the frame in which content should be displayed
379 // to the user, accounting for all screen decoration except for any
380 // space they deem as available for other content. This is usually
381 // the same as mCur*, but may be larger if the screen decor has supplied
382 // content insets.
383 int mContentLeft, mContentTop, mContentRight, mContentBottom;
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700384 // During layout, the frame in which voice content should be displayed
385 // to the user, accounting for all screen decoration except for any
386 // space they deem as available for other content.
387 int mVoiceContentLeft, mVoiceContentTop, mVoiceContentRight, mVoiceContentBottom;
Dianne Hackborn8e11ef02010-11-18 19:47:42 -0800388 // During layout, the current screen borders along which input method
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800389 // windows are placed.
390 int mDockLeft, mDockTop, mDockRight, mDockBottom;
391 // During layout, the layer at which the doc window is placed.
392 int mDockLayer;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700393 // During layout, this is the layer of the status bar.
394 int mStatusBarLayer;
Dianne Hackborne26ab702011-10-16 13:21:33 -0700395 int mLastSystemUiFlags;
396 // Bits that we are in the process of clearing, so we want to prevent
397 // them from being set by applications until everything has been updated
398 // to have them clear.
399 int mResettingSystemUiFlags = 0;
400 // Bits that we are currently always keeping cleared.
401 int mForceClearedSystemUiFlags = 0;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -0800402 // What we last reported to system UI about whether the compatibility
403 // menu needs to be displayed.
404 boolean mLastFocusNeedsMenu = false;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700405
406 FakeWindow mHideNavFakeWindow = null;
407
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800408 static final Rect mTmpParentFrame = new Rect();
409 static final Rect mTmpDisplayFrame = new Rect();
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800410 static final Rect mTmpOverscanFrame = new Rect();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800411 static final Rect mTmpContentFrame = new Rect();
412 static final Rect mTmpVisibleFrame = new Rect();
John Spurlock46646232013-09-30 22:32:42 -0400413 static final Rect mTmpDecorFrame = new Rect();
Adrian Roosfa104232014-06-20 16:10:14 -0700414 static final Rect mTmpStableFrame = new Rect();
Dianne Hackborn1f903c32011-09-13 19:18:06 -0700415 static final Rect mTmpNavigationFrame = new Rect();
Craig Mautner967212c2013-04-13 21:10:58 -0700416
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800417 WindowState mTopFullscreenOpaqueWindowState;
Craig Mautner2bc789b2014-03-19 19:48:38 -0700418 HashSet<IApplicationToken> mAppsToBeHidden = new HashSet<IApplicationToken>();
Joe Onorato93056472010-09-10 10:30:46 -0400419 boolean mTopIsFullscreen;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800420 boolean mForceStatusBar;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -0700421 boolean mForceStatusBarFromKeyguard;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700422 boolean mHideLockScreen;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -0800423 boolean mForcingShowNavBar;
424 int mForcingShowNavBarLayer;
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700425
426 // States of keyguard dismiss.
427 private static final int DISMISS_KEYGUARD_NONE = 0; // Keyguard not being dismissed.
428 private static final int DISMISS_KEYGUARD_START = 1; // Keyguard needs to be dismissed.
429 private static final int DISMISS_KEYGUARD_CONTINUE = 2; // Keyguard has been dismissed.
430 int mDismissKeyguard = DISMISS_KEYGUARD_NONE;
431
432 /** The window that is currently dismissing the keyguard. Dismissing the keyguard must only
433 * be done once per window. */
434 private WindowState mWinDismissingKeyguard;
435
Craig Mautnerc9457fa2014-06-06 14:27:48 -0700436 /** The window that is currently showing "over" the keyguard. If there is an app window
437 * belonging to another app on top of this the keyguard shows. If there is a fullscreen
438 * app window under this, still dismiss the keyguard but don't show the app underneath. Show
439 * the wallpaper. */
440 private WindowState mWinShowWhenLocked;
441
Dianne Hackborn7ad44382012-10-18 17:46:00 -0700442 boolean mShowingLockscreen;
443 boolean mShowingDream;
444 boolean mDreamingLockscreen;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800445 boolean mHomePressed;
Jeff Browncaca8812013-05-09 13:34:33 -0700446 boolean mHomeConsumed;
447 boolean mHomeDoubleTapPending;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800448 Intent mHomeIntent;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700449 Intent mCarDockIntent;
450 Intent mDeskDockIntent;
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700451 boolean mSearchKeyShortcutPending;
452 boolean mConsumeSearchKeyUp;
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700453 boolean mAssistKeyLongPressed;
Michael Wright6a62e552014-06-03 19:19:48 -0700454 boolean mPendingMetaAction;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800455
Mike Lockwood28569302010-01-28 11:54:40 -0500456 // support for activating the lock screen while the screen is on
457 boolean mAllowLockscreenWhenOn;
458 int mLockScreenTimeout;
459 boolean mLockScreenTimerActive;
460
David Brownbaf8d092010-03-08 21:52:59 -0800461 // Behavior of ENDCALL Button. (See Settings.System.END_BUTTON_BEHAVIOR.)
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800462 int mEndcallBehavior;
David Brownbaf8d092010-03-08 21:52:59 -0800463
464 // Behavior of POWER button while in-call and screen on.
465 // (See Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR.)
466 int mIncallPowerBehavior;
467
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700468 Display mDisplay;
469
Dianne Hackborn9d132642011-04-21 17:26:39 -0700470 int mLandscapeRotation = 0; // default landscape rotation
471 int mSeascapeRotation = 0; // "other" landscape rotation, 180 degrees from mLandscapeRotation
472 int mPortraitRotation = 0; // default portrait rotation
473 int mUpsideDownRotation = 0; // "other" portrait rotation
Mitsuru Oshima831d0d92009-06-16 18:27:18 -0700474
Dianne Hackbornc652de82013-02-15 16:32:56 -0800475 int mOverscanLeft = 0;
476 int mOverscanTop = 0;
477 int mOverscanRight = 0;
478 int mOverscanBottom = 0;
479
Joe Onorato46b0d682010-11-22 17:37:27 -0800480 // What we do when the user long presses on home
Jeff Browncaca8812013-05-09 13:34:33 -0700481 private int mLongPressOnHomeBehavior;
482
483 // What we do when the user double-taps on home
484 private int mDoubleTapOnHomeBehavior;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800485
Winson Chung9112ec32011-06-27 13:15:32 -0700486 // Screenshot trigger states
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700487 // Time to volume and power must be pressed within this interval of each other.
488 private static final long SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS = 150;
Winson Chung1cea2f32012-10-08 20:42:01 -0700489 // Increase the chord delay when taking a screenshot from the keyguard
490 private static final float KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER = 2.5f;
Christopher Tatee90585f2012-03-05 18:56:25 -0800491 private boolean mScreenshotChordEnabled;
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700492 private boolean mVolumeDownKeyTriggered;
493 private long mVolumeDownKeyTime;
494 private boolean mVolumeDownKeyConsumedByScreenshotChord;
495 private boolean mVolumeUpKeyTriggered;
496 private boolean mPowerKeyTriggered;
497 private long mPowerKeyTime;
Winson Chung9112ec32011-06-27 13:15:32 -0700498
Michael Wrightb854e242013-02-05 17:54:02 -0800499 /* The number of steps between min and max brightness */
500 private static final int BRIGHTNESS_STEPS = 10;
501
Christopher Tate5e08af02012-09-21 17:17:22 -0700502 SettingsObserver mSettingsObserver;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800503 ShortcutManager mShortcutManager;
504 PowerManager.WakeLock mBroadcastWakeLock;
Jeff Brown40013652012-05-16 21:22:36 -0700505 boolean mHavePendingMediaKeyRepeatWithWakeLock;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800506
Craig Mautnerd625ab22013-09-06 13:40:31 -0700507 private int mCurrentUserId;
508
Justin Kohd378ad72013-04-01 12:18:26 -0700509 // Maps global key codes to the components that will handle them.
510 private GlobalKeyManager mGlobalKeyManager;
511
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700512 // Fallback actions by key code.
513 private final SparseArray<KeyCharacterMap.FallbackAction> mFallbackActions =
514 new SparseArray<KeyCharacterMap.FallbackAction>();
Jeff Brown49ed71d2010-12-06 17:13:33 -0800515
Jeff Brown70825162012-03-28 17:27:48 -0700516 private static final int MSG_ENABLE_POINTER_LOCATION = 1;
517 private static final int MSG_DISABLE_POINTER_LOCATION = 2;
Jeff Brown40013652012-05-16 21:22:36 -0700518 private static final int MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK = 3;
519 private static final int MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK = 4;
Craig Mautner8a0da012014-05-31 15:13:37 -0700520 private static final int MSG_KEYGUARD_DRAWN_COMPLETE = 5;
521 private static final int MSG_KEYGUARD_DRAWN_TIMEOUT = 6;
522 private static final int MSG_WINDOW_MANAGER_DRAWN_COMPLETE = 7;
523 private static final int MSG_WAKING_UP = 8;
Craig Mautner84984fa2014-06-19 11:19:20 -0700524 private static final int MSG_DISPATCH_SHOW_RECENTS = 9;
Jeff Brown70825162012-03-28 17:27:48 -0700525
526 private class PolicyHandler extends Handler {
527 @Override
528 public void handleMessage(Message msg) {
529 switch (msg.what) {
530 case MSG_ENABLE_POINTER_LOCATION:
531 enablePointerLocation();
532 break;
533 case MSG_DISABLE_POINTER_LOCATION:
534 disablePointerLocation();
535 break;
Jeff Brown40013652012-05-16 21:22:36 -0700536 case MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK:
537 dispatchMediaKeyWithWakeLock((KeyEvent)msg.obj);
538 break;
539 case MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK:
540 dispatchMediaKeyRepeatWithWakeLock((KeyEvent)msg.obj);
541 break;
Craig Mautner84984fa2014-06-19 11:19:20 -0700542 case MSG_DISPATCH_SHOW_RECENTS:
543 showRecentApps(false);
544 break;
Craig Mautner8a0da012014-05-31 15:13:37 -0700545 case MSG_KEYGUARD_DRAWN_COMPLETE:
546 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mKeyguardDrawComplete");
547 mKeyguardDrawComplete = true;
548 finishScreenTurningOn();
549 break;
550 case MSG_KEYGUARD_DRAWN_TIMEOUT:
551 Slog.w(TAG, "Keyguard drawn timeout. Setting mKeyguardDrawComplete");
552 mKeyguardDrawComplete = true;
553 finishScreenTurningOn();
554 break;
555 case MSG_WINDOW_MANAGER_DRAWN_COMPLETE:
556 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mWindowManagerDrawComplete");
557 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
558 mWindowManagerDrawComplete = true;
559 finishScreenTurningOn();
560 break;
561 case MSG_WAKING_UP:
562 handleWakingUp((ScreenOnListener) msg.obj);
563 break;
Jeff Brown70825162012-03-28 17:27:48 -0700564 }
565 }
566 }
567
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800568 private UEventObserver mHDMIObserver = new UEventObserver() {
569 @Override
570 public void onUEvent(UEventObserver.UEvent event) {
571 setHdmiPlugged("1".equals(event.get("SWITCH_STATE")));
572 }
573 };
574
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800575 class SettingsObserver extends ContentObserver {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800576 SettingsObserver(Handler handler) {
577 super(handler);
578 }
David Brownbaf8d092010-03-08 21:52:59 -0800579
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800580 void observe() {
Christopher Tate5e08af02012-09-21 17:17:22 -0700581 // Observe all users' changes
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800582 ContentResolver resolver = mContext.getContentResolver();
583 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700584 Settings.System.END_BUTTON_BEHAVIOR), false, this,
585 UserHandle.USER_ALL);
David Brownbaf8d092010-03-08 21:52:59 -0800586 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700587 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR), false, this,
588 UserHandle.USER_ALL);
Jeff Browna20dda42014-05-27 20:57:24 -0700589 resolver.registerContentObserver(Settings.Secure.getUriFor(
590 Settings.Secure.WAKE_GESTURE_ENABLED), false, this,
591 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800592 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700593 Settings.System.ACCELEROMETER_ROTATION), false, this,
594 UserHandle.USER_ALL);
Mike Lockwood28569302010-01-28 11:54:40 -0500595 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700596 Settings.System.USER_ROTATION), false, this,
597 UserHandle.USER_ALL);
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400598 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700599 Settings.System.SCREEN_OFF_TIMEOUT), false, this,
600 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800601 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700602 Settings.System.POINTER_LOCATION), false, this,
603 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800604 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700605 Settings.Secure.DEFAULT_INPUT_METHOD), false, this,
606 UserHandle.USER_ALL);
John Spurlockd9b70bd2014-02-06 17:02:44 -0500607 resolver.registerContentObserver(Settings.Secure.getUriFor(
John Spurlockf1a36642013-10-12 17:50:42 -0400608 Settings.Secure.IMMERSIVE_MODE_CONFIRMATIONS), false, this,
Christopher Tate5e08af02012-09-21 17:17:22 -0700609 UserHandle.USER_ALL);
John Spurlockc6d1c602014-01-17 15:22:06 -0500610 resolver.registerContentObserver(Settings.Global.getUriFor(
611 Settings.Global.POLICY_CONTROL), false, this,
612 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800613 updateSettings();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800614 }
615
616 @Override public void onChange(boolean selfChange) {
Dianne Hackbornc777e072010-02-12 13:07:59 -0800617 updateSettings();
Jeff Brown01a98dd2011-09-20 15:08:29 -0700618 updateRotation(false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800619 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800620 }
Craig Mautner967212c2013-04-13 21:10:58 -0700621
Jeff Browna20dda42014-05-27 20:57:24 -0700622 class MyWakeGestureListener extends WakeGestureListener {
623 MyWakeGestureListener(Context context, Handler handler) {
624 super(context, handler);
625 }
626
627 @Override
628 public void onWakeUp() {
629 synchronized (mLock) {
630 if (shouldEnableWakeGestureLp()) {
Jeff Browne07b94b2014-06-18 15:56:27 -0700631 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
Jeff Browna20dda42014-05-27 20:57:24 -0700632 mPowerManager.wakeUp(SystemClock.uptimeMillis());
633 }
634 }
635 }
636 }
637
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800638 class MyOrientationListener extends WindowOrientationListener {
Craig Mautnereee29c42013-01-17 14:44:34 -0800639 MyOrientationListener(Context context, Handler handler) {
640 super(context, handler);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800641 }
Craig Mautner967212c2013-04-13 21:10:58 -0700642
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800643 @Override
Jeff Brownc0347aa2011-09-23 17:26:09 -0700644 public void onProposedRotationChanged(int rotation) {
Craig Mautnereda67292013-04-28 13:50:14 -0700645 if (localLOGV) Slog.v(TAG, "onProposedRotationChanged, rotation=" + rotation);
Jeff Brown01a98dd2011-09-20 15:08:29 -0700646 updateRotation(false);
647 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800648 }
649 MyOrientationListener mOrientationListener;
650
John Spurlock27735a42013-08-14 17:57:38 -0400651 private final BarController mStatusBarController = new BarController("StatusBar",
John Spurlock5b9145b2013-08-20 15:13:47 -0400652 View.STATUS_BAR_TRANSIENT,
653 View.STATUS_BAR_UNHIDE,
John Spurlockbd957402013-10-03 11:38:39 -0400654 View.STATUS_BAR_TRANSLUCENT,
655 StatusBarManager.WINDOW_STATUS_BAR,
656 WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
John Spurlock5b9145b2013-08-20 15:13:47 -0400657
John Spurlock27735a42013-08-14 17:57:38 -0400658 private final BarController mNavigationBarController = new BarController("NavigationBar",
John Spurlock5b9145b2013-08-20 15:13:47 -0400659 View.NAVIGATION_BAR_TRANSIENT,
660 View.NAVIGATION_BAR_UNHIDE,
John Spurlockbd957402013-10-03 11:38:39 -0400661 View.NAVIGATION_BAR_TRANSLUCENT,
662 StatusBarManager.WINDOW_NAVIGATION_BAR,
663 WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
John Spurlock5b9145b2013-08-20 15:13:47 -0400664
John Spurlockf1a36642013-10-12 17:50:42 -0400665 private ImmersiveModeConfirmation mImmersiveModeConfirmation;
John Spurlock32beb2c2013-03-11 10:16:47 -0400666
Craig Mautner037aa8d2013-06-07 10:35:44 -0700667 private SystemGesturesPointerEventListener mSystemGestures;
John Spurlock32beb2c2013-03-11 10:16:47 -0400668
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700669 IStatusBarService getStatusBarService() {
670 synchronized (mServiceAquireLock) {
671 if (mStatusBarService == null) {
672 mStatusBarService = IStatusBarService.Stub.asInterface(
673 ServiceManager.getService("statusbar"));
674 }
675 return mStatusBarService;
676 }
677 }
678
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700679 /*
680 * We always let the sensor be switched on by default except when
681 * the user has explicitly disabled sensor based rotation or when the
682 * screen is switched off.
683 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700684 boolean needSensorRunningLp() {
Jeff Brownbcdfc622014-03-06 19:13:04 -0800685 if (mSupportAutoRotation) {
686 if (mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
687 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
688 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT
689 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) {
690 // If the application has explicitly requested to follow the
691 // orientation, then we need to turn the sensor on.
692 return true;
693 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800694 }
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700695 if ((mCarDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_CAR) ||
Jeff Brown1a693182011-11-08 14:44:16 -0800696 (mDeskDockEnablesAccelerometer && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
697 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
698 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK))) {
Mike Lockwoode9867d22009-09-20 01:59:02 -0400699 // enable accelerometer if we are docked in a dock that enables accelerometer
700 // orientation management,
701 return true;
702 }
Jeff Brown207673cd2012-06-05 17:47:11 -0700703 if (mUserRotationMode == USER_ROTATION_LOCKED) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800704 // If the setting for using the sensor by default is enabled, then
705 // we will always leave it on. Note that the user could go to
706 // a window that forces an orientation that does not use the
707 // sensor and in theory we could turn it off... however, when next
708 // turning it on we won't have a good value for the current
709 // orientation for a little bit, which can cause orientation
710 // changes to lag, so we'd like to keep it always on. (It will
711 // still be turned off when the screen is off.)
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700712 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800713 }
Jeff Brownbcdfc622014-03-06 19:13:04 -0800714 return mSupportAutoRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800715 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700716
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800717 /*
718 * Various use cases for invoking this function
719 * screen turning off, should always disable listeners if already enabled
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700720 * screen turned on and current app has sensor based orientation, enable listeners
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800721 * if not already enabled
722 * screen turned on and current app does not have sensor orientation, disable listeners if
723 * already enabled
724 * screen turning on and current app has sensor based orientation, enable listeners if needed
725 * screen turning on and current app has nosensor based orientation, do nothing
726 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700727 void updateOrientationListenerLp() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800728 if (!mOrientationListener.canDetectOrientation()) {
729 // If sensor is turned off or nonexistent for some reason
730 return;
731 }
732 //Could have been invoked due to screen turning on or off or
733 //change of the currently visible window's orientation
Craig Mautnereda67292013-04-28 13:50:14 -0700734 if (localLOGV) Slog.v(TAG, "Screen status="+mScreenOnEarly+
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800735 ", current orientation="+mCurrentAppOrientation+
736 ", SensorEnabled="+mOrientationSensorEnabled);
737 boolean disable = true;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -0700738 if (mScreenOnEarly) {
The Android Open Source Project0727d222009-03-11 12:11:58 -0700739 if (needSensorRunningLp()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800740 disable = false;
741 //enable listener if not already enabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700742 if (!mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800743 mOrientationListener.enable();
Craig Mautnereda67292013-04-28 13:50:14 -0700744 if(localLOGV) Slog.v(TAG, "Enabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800745 mOrientationSensorEnabled = true;
746 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700747 }
748 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800749 //check if sensors need to be disabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700750 if (disable && mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800751 mOrientationListener.disable();
Craig Mautnereda67292013-04-28 13:50:14 -0700752 if(localLOGV) Slog.v(TAG, "Disabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800753 mOrientationSensorEnabled = false;
754 }
755 }
756
Jeff Brown4d396052010-10-29 21:50:21 -0700757 private void interceptPowerKeyDown(boolean handled) {
758 mPowerKeyHandled = handled;
759 if (!handled) {
Justin Kohfeabd2c2014-05-02 10:02:44 -0700760 mHandler.postDelayed(mPowerLongPress,
761 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Jeff Brown4d396052010-10-29 21:50:21 -0700762 }
763 }
764
765 private boolean interceptPowerKeyUp(boolean canceled) {
766 if (!mPowerKeyHandled) {
767 mHandler.removeCallbacks(mPowerLongPress);
768 return !canceled;
Jeff Brown4d396052010-10-29 21:50:21 -0700769 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700770 return false;
771 }
772
773 private void cancelPendingPowerKeyAction() {
774 if (!mPowerKeyHandled) {
775 mHandler.removeCallbacks(mPowerLongPress);
776 }
Jeff Brownff204712011-10-25 21:27:54 -0700777 if (mPowerKeyTriggered) {
778 mPendingPowerKeyUpCanceled = true;
779 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700780 }
781
782 private void interceptScreenshotChord() {
Christopher Tatee90585f2012-03-05 18:56:25 -0800783 if (mScreenshotChordEnabled
784 && mVolumeDownKeyTriggered && mPowerKeyTriggered && !mVolumeUpKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700785 final long now = SystemClock.uptimeMillis();
786 if (now <= mVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS
787 && now <= mPowerKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) {
788 mVolumeDownKeyConsumedByScreenshotChord = true;
789 cancelPendingPowerKeyAction();
790
Jeff Sharkey2991fa32012-12-05 18:06:43 -0800791 mHandler.postDelayed(mScreenshotRunnable, getScreenshotChordLongPressDelay());
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700792 }
793 }
794 }
795
Winson Chung1cea2f32012-10-08 20:42:01 -0700796 private long getScreenshotChordLongPressDelay() {
Jim Miller5ecd8112013-01-09 18:50:26 -0800797 if (mKeyguardDelegate.isShowing()) {
Winson Chung1cea2f32012-10-08 20:42:01 -0700798 // Double the time it takes to take a screenshot from the keyguard
799 return (long) (KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER *
Justin Kohfeabd2c2014-05-02 10:02:44 -0700800 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Winson Chung1cea2f32012-10-08 20:42:01 -0700801 }
Justin Kohfeabd2c2014-05-02 10:02:44 -0700802 return ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout();
Winson Chung1cea2f32012-10-08 20:42:01 -0700803 }
804
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700805 private void cancelPendingScreenshotChordAction() {
Jeff Sharkey2991fa32012-12-05 18:06:43 -0800806 mHandler.removeCallbacks(mScreenshotRunnable);
Jeff Brown4d396052010-10-29 21:50:21 -0700807 }
808
Jeff Brown6d8fd272014-05-20 21:24:38 -0700809 private void powerShortPress(long eventTime) {
810 if (mShortPressOnPowerBehavior < 0) {
811 mShortPressOnPowerBehavior = mContext.getResources().getInteger(
812 com.android.internal.R.integer.config_shortPressOnPowerBehavior);
813 }
814
815 switch (mShortPressOnPowerBehavior) {
816 case SHORT_PRESS_POWER_NOTHING:
817 break;
818 case SHORT_PRESS_POWER_GO_TO_SLEEP:
819 mPowerManager.goToSleep(eventTime,
820 PowerManager.GO_TO_SLEEP_REASON_USER, 0);
821 break;
822 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP:
823 mPowerManager.goToSleep(eventTime,
824 PowerManager.GO_TO_SLEEP_REASON_USER,
825 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
826 break;
827 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME:
828 mPowerManager.goToSleep(eventTime,
829 PowerManager.GO_TO_SLEEP_REASON_USER,
830 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
831 launchHomeFromHotKey();
832 break;
833 }
834 }
835
Jeff Brown4d396052010-10-29 21:50:21 -0700836 private final Runnable mPowerLongPress = new Runnable() {
Craig Mautnerf1b67412012-09-19 13:18:29 -0700837 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800838 public void run() {
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700839 // The context isn't read
840 if (mLongPressOnPowerBehavior < 0) {
Jeff Brown850c5b72012-10-01 15:17:22 -0700841 mLongPressOnPowerBehavior = mContext.getResources().getInteger(
842 com.android.internal.R.integer.config_longPressOnPowerBehavior);
Joe Onoratod208e702010-10-08 16:22:43 -0400843 }
Jeff Brown850c5b72012-10-01 15:17:22 -0700844 int resolvedBehavior = mLongPressOnPowerBehavior;
845 if (FactoryTest.isLongPressOnPowerOffEnabled()) {
846 resolvedBehavior = LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM;
847 }
848
849 switch (resolvedBehavior) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700850 case LONG_PRESS_POWER_NOTHING:
851 break;
852 case LONG_PRESS_POWER_GLOBAL_ACTIONS:
853 mPowerKeyHandled = true;
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -0700854 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
855 performAuditoryFeedbackForAccessibilityIfNeed();
856 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700857 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
858 showGlobalActionsDialog();
859 break;
860 case LONG_PRESS_POWER_SHUT_OFF:
Jeff Brown9a538ee2012-08-20 14:56:57 -0700861 case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM:
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700862 mPowerKeyHandled = true;
863 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
864 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
Jeff Brown850c5b72012-10-01 15:17:22 -0700865 mWindowManagerFuncs.shutdown(resolvedBehavior == LONG_PRESS_POWER_SHUT_OFF);
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700866 break;
867 }
868 }
869 };
870
Jeff Sharkey2991fa32012-12-05 18:06:43 -0800871 private final Runnable mScreenshotRunnable = new Runnable() {
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800872 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700873 public void run() {
874 takeScreenshot();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800875 }
876 };
877
878 void showGlobalActionsDialog() {
879 if (mGlobalActions == null) {
Jeff Brown7304c342012-05-11 18:42:42 -0700880 mGlobalActions = new GlobalActions(mContext, mWindowManagerFuncs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800881 }
Mike Lockwood3a74bd32011-08-12 13:55:22 -0700882 final boolean keyguardShowing = keyguardIsShowingTq();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800883 mGlobalActions.showDialog(keyguardShowing, isDeviceProvisioned());
884 if (keyguardShowing) {
885 // since it took two seconds of long press to bring this up,
886 // poke the wake lock so they have some time to see the dialog.
Jim Miller25190572013-02-28 17:36:24 -0800887 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800888 }
889 }
890
891 boolean isDeviceProvisioned() {
Jeff Brownbf6f6f92012-09-25 15:03:20 -0700892 return Settings.Global.getInt(
893 mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800894 }
895
Maurice Lam99c6e072014-04-28 18:24:28 -0700896 boolean isUserSetupComplete() {
897 return Settings.Secure.getIntForUser(mContext.getContentResolver(),
898 Settings.Secure.USER_SETUP_COMPLETE, 0, UserHandle.USER_CURRENT) != 0;
899 }
900
Patrick Dubroyece94522011-02-23 18:35:01 -0800901 private void handleLongPressOnHome() {
Joe Onorato46b0d682010-11-22 17:37:27 -0800902 if (mLongPressOnHomeBehavior != LONG_PRESS_HOME_NOTHING) {
Jeff Browncaca8812013-05-09 13:34:33 -0700903 mHomeConsumed = true;
Joe Onorato46b0d682010-11-22 17:37:27 -0800904 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
Patrick Dubroyece94522011-02-23 18:35:01 -0800905
Jeff Browncaca8812013-05-09 13:34:33 -0700906 if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI) {
907 toggleRecentApps();
908 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_ASSIST) {
909 launchAssistAction();
Jim Millere6ad1a82010-08-20 19:25:39 -0700910 }
911 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800912 }
Patrick Dubroyece94522011-02-23 18:35:01 -0800913
Jeff Browncaca8812013-05-09 13:34:33 -0700914 private void handleDoubleTapOnHome() {
915 if (mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
916 mHomeConsumed = true;
917 toggleRecentApps();
918 }
919 }
920
921 private final Runnable mHomeDoubleTapTimeoutRunnable = new Runnable() {
922 @Override
923 public void run() {
924 if (mHomeDoubleTapPending) {
925 mHomeDoubleTapPending = false;
926 launchHomeFromHotKey();
927 }
928 }
929 };
930
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800931 /** {@inheritDoc} */
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800932 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800933 public void init(Context context, IWindowManager windowManager,
Jeff Brown96307042012-07-27 15:51:34 -0700934 WindowManagerFuncs windowManagerFuncs) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800935 mContext = context;
936 mWindowManager = windowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700937 mWindowManagerFuncs = windowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -0700938 mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class);
Jose Lima9546b202014-07-02 17:21:51 -0700939 mDreamManagerInternal = LocalServices.getService(DreamManagerInternal.class);
Craig Mautner8a0da012014-05-31 15:13:37 -0700940
Jeff Brown70825162012-03-28 17:27:48 -0700941 mHandler = new PolicyHandler();
Jeff Browna20dda42014-05-27 20:57:24 -0700942 mWakeGestureListener = new MyWakeGestureListener(mContext, mHandler);
Craig Mautnereee29c42013-01-17 14:44:34 -0800943 mOrientationListener = new MyOrientationListener(mContext, mHandler);
Jeff Brownc0347aa2011-09-23 17:26:09 -0700944 try {
945 mOrientationListener.setCurrentRotation(windowManager.getRotation());
946 } catch (RemoteException ex) { }
Christopher Tate5e08af02012-09-21 17:17:22 -0700947 mSettingsObserver = new SettingsObserver(mHandler);
948 mSettingsObserver.observe();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800949 mShortcutManager = new ShortcutManager(context, mHandler);
950 mShortcutManager.observe();
Daniel Sandler6396c722013-04-16 20:19:09 -0400951 mUiMode = context.getResources().getInteger(
952 com.android.internal.R.integer.config_defaultUiModeType);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800953 mHomeIntent = new Intent(Intent.ACTION_MAIN, null);
954 mHomeIntent.addCategory(Intent.CATEGORY_HOME);
955 mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
956 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700957 mCarDockIntent = new Intent(Intent.ACTION_MAIN, null);
958 mCarDockIntent.addCategory(Intent.CATEGORY_CAR_DOCK);
959 mCarDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
960 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
961 mDeskDockIntent = new Intent(Intent.ACTION_MAIN, null);
962 mDeskDockIntent.addCategory(Intent.CATEGORY_DESK_DOCK);
963 mDeskDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
964 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Jim Millere6ad1a82010-08-20 19:25:39 -0700965
Jeff Brown96307042012-07-27 15:51:34 -0700966 mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
967 mBroadcastWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800968 "PhoneWindowManager.mBroadcastWakeLock");
969 mEnableShiftMenuBugReports = "1".equals(SystemProperties.get("ro.debuggable"));
Jeff Brownbcdfc622014-03-06 19:13:04 -0800970 mSupportAutoRotation = mContext.getResources().getBoolean(
971 com.android.internal.R.bool.config_supportAutoRotation);
Dianne Hackborn2862fff2009-09-15 22:56:29 -0700972 mLidOpenRotation = readRotation(
Mike Lockwood2d1efbd2009-09-16 12:15:53 -0400973 com.android.internal.R.integer.config_lidOpenRotation);
974 mCarDockRotation = readRotation(
975 com.android.internal.R.integer.config_carDockRotation);
976 mDeskDockRotation = readRotation(
977 com.android.internal.R.integer.config_deskDockRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -0700978 mUndockedHdmiRotation = readRotation(
979 com.android.internal.R.integer.config_undockedHdmiRotation);
Mike Lockwoode9867d22009-09-20 01:59:02 -0400980 mCarDockEnablesAccelerometer = mContext.getResources().getBoolean(
981 com.android.internal.R.bool.config_carDockEnablesAccelerometer);
982 mDeskDockEnablesAccelerometer = mContext.getResources().getBoolean(
983 com.android.internal.R.bool.config_deskDockEnablesAccelerometer);
Dianne Hackborn2862fff2009-09-15 22:56:29 -0700984 mLidKeyboardAccessibility = mContext.getResources().getInteger(
985 com.android.internal.R.integer.config_lidKeyboardAccessibility);
986 mLidNavigationAccessibility = mContext.getResources().getInteger(
987 com.android.internal.R.integer.config_lidNavigationAccessibility);
Jeff Brownc458ce92012-04-30 14:58:40 -0700988 mLidControlsSleep = mContext.getResources().getBoolean(
989 com.android.internal.R.bool.config_lidControlsSleep);
Daniel Sandlerdd73ee42013-10-11 22:19:59 -0400990 mTranslucentDecorEnabled = mContext.getResources().getBoolean(
991 com.android.internal.R.bool.config_enableTranslucentDecor);
Jeff Brownf71343d2013-05-31 17:59:11 -0700992 readConfigurationDependentBehaviors();
Jeff Browncaca8812013-05-09 13:34:33 -0700993
Svetoslav8e3feb12014-02-24 13:46:47 -0800994 mAccessibilityManager = (AccessibilityManager) context.getSystemService(
995 Context.ACCESSIBILITY_SERVICE);
996
Mike Lockwood1753f7f2009-08-24 14:49:07 -0700997 // register for dock events
Dianne Hackborn78968392010-03-04 20:47:56 -0800998 IntentFilter filter = new IntentFilter();
999 filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE);
1000 filter.addAction(UiModeManager.ACTION_EXIT_CAR_MODE);
1001 filter.addAction(UiModeManager.ACTION_ENTER_DESK_MODE);
1002 filter.addAction(UiModeManager.ACTION_EXIT_DESK_MODE);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001003 filter.addAction(Intent.ACTION_DOCK_EVENT);
1004 Intent intent = context.registerReceiver(mDockReceiver, filter);
1005 if (intent != null) {
1006 // Retrieve current sticky dock event broadcast.
1007 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
1008 Intent.EXTRA_DOCK_STATE_UNDOCKED);
1009 }
Daniel Sandler7e37df52011-11-16 22:08:23 -08001010
Jeff Brown6aaf2952012-10-05 16:01:08 -07001011 // register for dream-related broadcasts
1012 filter = new IntentFilter();
1013 filter.addAction(Intent.ACTION_DREAMING_STARTED);
1014 filter.addAction(Intent.ACTION_DREAMING_STOPPED);
1015 context.registerReceiver(mDreamReceiver, filter);
1016
Christopher Tate5e08af02012-09-21 17:17:22 -07001017 // register for multiuser-relevant broadcasts
1018 filter = new IntentFilter(Intent.ACTION_USER_SWITCHED);
1019 context.registerReceiver(mMultiuserReceiver, filter);
1020
John Spurlock57306e62013-04-22 09:48:49 -04001021 // monitor for system gestures
Craig Mautner037aa8d2013-06-07 10:35:44 -07001022 mSystemGestures = new SystemGesturesPointerEventListener(context,
1023 new SystemGesturesPointerEventListener.Callbacks() {
John Spurlock57306e62013-04-22 09:48:49 -04001024 @Override
1025 public void onSwipeFromTop() {
John Spurlock04db1762013-05-13 12:46:41 -04001026 if (mStatusBar != null) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001027 requestTransientBars(mStatusBar);
John Spurlock04db1762013-05-13 12:46:41 -04001028 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04001029 }
1030 @Override
1031 public void onSwipeFromBottom() {
John Spurlock04db1762013-05-13 12:46:41 -04001032 if (mNavigationBar != null && mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001033 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001034 }
1035 }
1036 @Override
1037 public void onSwipeFromRight() {
John Spurlock04db1762013-05-13 12:46:41 -04001038 if (mNavigationBar != null && !mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001039 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001040 }
1041 }
1042 @Override
1043 public void onDebug() {
John Spurlockd67ec252013-09-05 11:31:54 -04001044 // no-op
John Spurlockad3e6cb2013-04-30 08:47:43 -04001045 }
1046 });
John Spurlockf1a36642013-10-12 17:50:42 -04001047 mImmersiveModeConfirmation = new ImmersiveModeConfirmation(mContext);
Craig Mautner037aa8d2013-06-07 10:35:44 -07001048 mWindowManagerFuncs.registerPointerEventListener(mSystemGestures);
John Spurlock32beb2c2013-03-11 10:16:47 -04001049
Jeff Brownc2346132012-04-13 01:55:38 -07001050 mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001051 mLongPressVibePattern = getLongIntArray(mContext.getResources(),
1052 com.android.internal.R.array.config_longPressVibePattern);
1053 mVirtualKeyVibePattern = getLongIntArray(mContext.getResources(),
1054 com.android.internal.R.array.config_virtualKeyVibePattern);
Amith Yamasanic33cb712010-02-10 15:21:49 -08001055 mKeyboardTapVibePattern = getLongIntArray(mContext.getResources(),
1056 com.android.internal.R.array.config_keyboardTapVibePattern);
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07001057 mClockTickVibePattern = getLongIntArray(mContext.getResources(),
1058 com.android.internal.R.array.config_clockTickVibePattern);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001059 mSafeModeDisabledVibePattern = getLongIntArray(mContext.getResources(),
1060 com.android.internal.R.array.config_safeModeDisabledVibePattern);
1061 mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(),
1062 com.android.internal.R.array.config_safeModeEnabledVibePattern);
Daniel Sandler40427442010-07-16 11:44:52 -04001063
Christopher Tatee90585f2012-03-05 18:56:25 -08001064 mScreenshotChordEnabled = mContext.getResources().getBoolean(
1065 com.android.internal.R.bool.config_enableScreenshotChord);
1066
Justin Kohd378ad72013-04-01 12:18:26 -07001067 mGlobalKeyManager = new GlobalKeyManager(mContext);
1068
Joe Onoratoea495d42011-04-06 11:41:11 -07001069 // Controls rotation and the like.
1070 initializeHdmiState();
Dianne Hackborn40011092011-09-22 13:37:48 -07001071
1072 // Match current screen state.
Jeff Brown26c6a502014-04-11 02:15:54 -07001073 if (mPowerManager.isInteractive()) {
Jeff Brown140ffc72014-05-01 15:18:00 -07001074 wakingUp(null);
Dianne Hackborn40011092011-09-22 13:37:48 -07001075 } else {
Jeff Brown140ffc72014-05-01 15:18:00 -07001076 goingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
Dianne Hackborn40011092011-09-22 13:37:48 -07001077 }
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001078 }
1079
Jeff Brownf71343d2013-05-31 17:59:11 -07001080 /**
1081 * Read values from config.xml that may be overridden depending on
1082 * the configuration of the device.
1083 * eg. Disable long press on home goes to recents on sw600dp.
1084 */
1085 private void readConfigurationDependentBehaviors() {
1086 mLongPressOnHomeBehavior = mContext.getResources().getInteger(
1087 com.android.internal.R.integer.config_longPressOnHomeBehavior);
1088 if (mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING ||
1089 mLongPressOnHomeBehavior > LONG_PRESS_HOME_ASSIST) {
1090 mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1091 }
1092
1093 mDoubleTapOnHomeBehavior = mContext.getResources().getInteger(
1094 com.android.internal.R.integer.config_doubleTapOnHomeBehavior);
1095 if (mDoubleTapOnHomeBehavior < DOUBLE_TAP_HOME_NOTHING ||
1096 mDoubleTapOnHomeBehavior > DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1097 mDoubleTapOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1098 }
1099 }
1100
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001101 @Override
Dianne Hackborndde331c2012-08-03 14:01:57 -07001102 public void setInitialDisplaySize(Display display, int width, int height, int density) {
Jeff Brownef981a42013-08-07 14:13:37 -07001103 // This method might be called before the policy has been fully initialized
1104 // or for other displays we don't care about.
1105 if (mContext == null || display.getDisplayId() != Display.DEFAULT_DISPLAY) {
1106 return;
Dianne Hackbornc652de82013-02-15 16:32:56 -08001107 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001108 mDisplay = display;
1109
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001110 final Resources res = mContext.getResources();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001111 int shortSize, longSize;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001112 if (width > height) {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001113 shortSize = height;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001114 longSize = width;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001115 mLandscapeRotation = Surface.ROTATION_0;
1116 mSeascapeRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001117 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001118 mPortraitRotation = Surface.ROTATION_90;
1119 mUpsideDownRotation = Surface.ROTATION_270;
1120 } else {
1121 mPortraitRotation = Surface.ROTATION_270;
1122 mUpsideDownRotation = Surface.ROTATION_90;
1123 }
1124 } else {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001125 shortSize = width;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001126 longSize = height;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001127 mPortraitRotation = Surface.ROTATION_0;
1128 mUpsideDownRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001129 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001130 mLandscapeRotation = Surface.ROTATION_270;
1131 mSeascapeRotation = Surface.ROTATION_90;
1132 } else {
1133 mLandscapeRotation = Surface.ROTATION_90;
1134 mSeascapeRotation = Surface.ROTATION_270;
1135 }
1136 }
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001137
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001138 mStatusBarHeight =
1139 res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001140
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001141 // Height of the navigation bar when presented horizontally at bottom
1142 mNavigationBarHeightForRotation[mPortraitRotation] =
1143 mNavigationBarHeightForRotation[mUpsideDownRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001144 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_height);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001145 mNavigationBarHeightForRotation[mLandscapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001146 mNavigationBarHeightForRotation[mSeascapeRotation] = res.getDimensionPixelSize(
1147 com.android.internal.R.dimen.navigation_bar_height_landscape);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001148
1149 // Width of the navigation bar when presented vertically along one side
1150 mNavigationBarWidthForRotation[mPortraitRotation] =
1151 mNavigationBarWidthForRotation[mUpsideDownRotation] =
1152 mNavigationBarWidthForRotation[mLandscapeRotation] =
1153 mNavigationBarWidthForRotation[mSeascapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001154 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_width);
Daniel Sandler4a066c52012-04-20 14:49:13 -04001155
1156 // SystemUI (status bar) layout policy
Dianne Hackborndde331c2012-08-03 14:01:57 -07001157 int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / density;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001158 int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / density;
Daniel Sandler4a066c52012-04-20 14:49:13 -04001159
Craig Mautnerd4ec33242013-07-22 10:37:43 -07001160 // Allow the navigation bar to move on small devices (phones).
1161 mNavigationBarCanMove = shortSizeDp < 600;
Daniel Sandler36412a72011-08-04 09:35:13 -04001162
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001163 mHasNavigationBar = res.getBoolean(com.android.internal.R.bool.config_showNavigationBar);
John Spurlock80f00c12013-06-13 11:10:51 -04001164 // Allow a system property to override this. Used by the emulator.
1165 // See also hasNavigationBar().
1166 String navBarOverride = SystemProperties.get("qemu.hw.mainkeys");
1167 if ("1".equals(navBarOverride)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001168 mHasNavigationBar = false;
John Spurlock80f00c12013-06-13 11:10:51 -04001169 } else if ("0".equals(navBarOverride)) {
1170 mHasNavigationBar = true;
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04001171 }
1172
Jeff Brown27f1d672012-10-17 18:32:34 -07001173 // For demo purposes, allow the rotation of the HDMI display to be controlled.
1174 // By default, HDMI locks rotation to landscape.
Erik Gilling9a41ef82011-09-26 19:21:03 -07001175 if ("portrait".equals(SystemProperties.get("persist.demo.hdmirotation"))) {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001176 mDemoHdmiRotation = mPortraitRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001177 } else {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001178 mDemoHdmiRotation = mLandscapeRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001179 }
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001180 mDemoHdmiRotationLock = SystemProperties.getBoolean("persist.demo.hdmirotationlock", false);
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001181
1182 // Only force the default orientation if the screen is xlarge, at least 960dp x 720dp, per
1183 // http://developer.android.com/guide/practices/screens_support.html#range
1184 mForceDefaultOrientation = longSizeDp >= 960 && shortSizeDp >= 720 &&
1185 res.getBoolean(com.android.internal.R.bool.config_forceDefaultOrientation) &&
1186 // For debug purposes the next line turns this feature off with:
1187 // $ adb shell setprop config.override_forced_orient true
1188 // $ adb shell wm size reset
1189 !"true".equals(SystemProperties.get("config.override_forced_orient"));
1190 }
1191
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001192 /**
1193 * @return whether the navigation bar can be hidden, e.g. the device has a
1194 * navigation bar and touch exploration is not enabled
1195 */
1196 private boolean canHideNavigationBar() {
Svetoslav8e3feb12014-02-24 13:46:47 -08001197 return mHasNavigationBar
1198 && !mAccessibilityManager.isTouchExplorationEnabled();
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001199 }
1200
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001201 @Override
1202 public boolean isDefaultOrientationForced() {
1203 return mForceDefaultOrientation;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001204 }
1205
Dianne Hackbornc652de82013-02-15 16:32:56 -08001206 @Override
1207 public void setDisplayOverscan(Display display, int left, int top, int right, int bottom) {
1208 if (display.getDisplayId() == Display.DEFAULT_DISPLAY) {
1209 mOverscanLeft = left;
1210 mOverscanTop = top;
1211 mOverscanRight = right;
1212 mOverscanBottom = bottom;
1213 }
1214 }
1215
Dianne Hackbornc777e072010-02-12 13:07:59 -08001216 public void updateSettings() {
1217 ContentResolver resolver = mContext.getContentResolver();
1218 boolean updateRotation = false;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001219 synchronized (mLock) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001220 mEndcallBehavior = Settings.System.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001221 Settings.System.END_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001222 Settings.System.END_BUTTON_BEHAVIOR_DEFAULT,
1223 UserHandle.USER_CURRENT);
1224 mIncallPowerBehavior = Settings.Secure.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001225 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001226 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT,
1227 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001228
Jeff Browna20dda42014-05-27 20:57:24 -07001229 // Configure wake gesture.
1230 boolean wakeGestureEnabledSetting = Settings.Secure.getIntForUser(resolver,
1231 Settings.Secure.WAKE_GESTURE_ENABLED, 0,
1232 UserHandle.USER_CURRENT) != 0;
1233 if (mWakeGestureEnabledSetting != wakeGestureEnabledSetting) {
1234 mWakeGestureEnabledSetting = wakeGestureEnabledSetting;
1235 updateWakeGestureListenerLp();
1236 }
1237
Jeff Brown207673cd2012-06-05 17:47:11 -07001238 // Configure rotation lock.
Christopher Tate5e08af02012-09-21 17:17:22 -07001239 int userRotation = Settings.System.getIntForUser(resolver,
1240 Settings.System.USER_ROTATION, Surface.ROTATION_0,
1241 UserHandle.USER_CURRENT);
Jeff Brown207673cd2012-06-05 17:47:11 -07001242 if (mUserRotation != userRotation) {
1243 mUserRotation = userRotation;
1244 updateRotation = true;
1245 }
Christopher Tate5e08af02012-09-21 17:17:22 -07001246 int userRotationMode = Settings.System.getIntForUser(resolver,
1247 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
Jeff Brown207673cd2012-06-05 17:47:11 -07001248 WindowManagerPolicy.USER_ROTATION_FREE :
1249 WindowManagerPolicy.USER_ROTATION_LOCKED;
1250 if (mUserRotationMode != userRotationMode) {
1251 mUserRotationMode = userRotationMode;
1252 updateRotation = true;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001253 updateOrientationListenerLp();
1254 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001255
Dianne Hackbornc777e072010-02-12 13:07:59 -08001256 if (mSystemReady) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001257 int pointerLocation = Settings.System.getIntForUser(resolver,
1258 Settings.System.POINTER_LOCATION, 0, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001259 if (mPointerLocationMode != pointerLocation) {
1260 mPointerLocationMode = pointerLocation;
Jeff Brown70825162012-03-28 17:27:48 -07001261 mHandler.sendEmptyMessage(pointerLocation != 0 ?
1262 MSG_ENABLE_POINTER_LOCATION : MSG_DISABLE_POINTER_LOCATION);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001263 }
1264 }
1265 // use screen off timeout setting as the timeout for the lockscreen
Christopher Tate5e08af02012-09-21 17:17:22 -07001266 mLockScreenTimeout = Settings.System.getIntForUser(resolver,
1267 Settings.System.SCREEN_OFF_TIMEOUT, 0, UserHandle.USER_CURRENT);
1268 String imId = Settings.Secure.getStringForUser(resolver,
1269 Settings.Secure.DEFAULT_INPUT_METHOD, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001270 boolean hasSoftInput = imId != null && imId.length() > 0;
1271 if (mHasSoftInput != hasSoftInput) {
1272 mHasSoftInput = hasSoftInput;
1273 updateRotation = true;
1274 }
John Spurlockf1a36642013-10-12 17:50:42 -04001275 if (mImmersiveModeConfirmation != null) {
John Spurlock4355a532014-02-19 09:49:25 -05001276 mImmersiveModeConfirmation.loadSetting(mCurrentUserId);
John Spurlockd67ec252013-09-05 11:31:54 -04001277 }
John Spurlockc6d1c602014-01-17 15:22:06 -05001278 PolicyControl.reloadFromSetting(mContext);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001279 }
1280 if (updateRotation) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07001281 updateRotation(true);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001282 }
Jeff Brown70825162012-03-28 17:27:48 -07001283 }
1284
Jeff Browna20dda42014-05-27 20:57:24 -07001285 private void updateWakeGestureListenerLp() {
1286 if (shouldEnableWakeGestureLp()) {
1287 mWakeGestureListener.requestWakeUpTrigger();
1288 } else {
1289 mWakeGestureListener.cancelWakeUpTrigger();
1290 }
1291 }
1292
1293 private boolean shouldEnableWakeGestureLp() {
1294 return mWakeGestureEnabledSetting && !mScreenOnEarly
1295 && (!mLidControlsSleep || mLidState != LID_CLOSED)
1296 && mWakeGestureListener.isSupported();
1297 }
1298
Jeff Brown70825162012-03-28 17:27:48 -07001299 private void enablePointerLocation() {
1300 if (mPointerLocationView == null) {
1301 mPointerLocationView = new PointerLocationView(mContext);
1302 mPointerLocationView.setPrintCoords(false);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001303 WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
1304 WindowManager.LayoutParams.MATCH_PARENT,
1305 WindowManager.LayoutParams.MATCH_PARENT);
Jeff Brown3b2b3542010-10-15 00:54:27 -07001306 lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001307 lp.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN
1308 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
1309 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1310 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
Jeff Brown90fc9052012-10-01 14:44:24 -07001311 if (ActivityManager.isHighEndGfx()) {
1312 lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
1313 lp.privateFlags |=
1314 WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED;
1315 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001316 lp.format = PixelFormat.TRANSLUCENT;
1317 lp.setTitle("PointerLocation");
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001318 WindowManager wm = (WindowManager)
Dianne Hackbornc777e072010-02-12 13:07:59 -08001319 mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Browncc4f7db2011-08-30 20:34:48 -07001320 lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL;
Jeff Brown70825162012-03-28 17:27:48 -07001321 wm.addView(mPointerLocationView, lp);
Michael Wrightc9c487e2013-11-07 18:55:09 -08001322 mWindowManagerFuncs.registerPointerEventListener(mPointerLocationView);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001323 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001324 }
Jeff Brown70825162012-03-28 17:27:48 -07001325
1326 private void disablePointerLocation() {
Jeff Brown70825162012-03-28 17:27:48 -07001327 if (mPointerLocationView != null) {
Michael Wrightc9c487e2013-11-07 18:55:09 -08001328 mWindowManagerFuncs.unregisterPointerEventListener(mPointerLocationView);
1329 WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Brown70825162012-03-28 17:27:48 -07001330 wm.removeView(mPointerLocationView);
1331 mPointerLocationView = null;
1332 }
1333 }
1334
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001335 private int readRotation(int resID) {
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001336 try {
1337 int rotation = mContext.getResources().getInteger(resID);
1338 switch (rotation) {
1339 case 0:
1340 return Surface.ROTATION_0;
1341 case 90:
1342 return Surface.ROTATION_90;
1343 case 180:
1344 return Surface.ROTATION_180;
1345 case 270:
1346 return Surface.ROTATION_270;
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001347 }
1348 } catch (Resources.NotFoundException e) {
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001349 // fall through
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001350 }
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001351 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001352 }
1353
1354 /** {@inheritDoc} */
Craig Mautner88400d32012-09-30 12:35:45 -07001355 @Override
Dianne Hackbornc2293022013-02-06 23:14:49 -08001356 public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001357 int type = attrs.type;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001358
1359 outAppOp[0] = AppOpsManager.OP_NONE;
1360
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001361 if (type < WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW
1362 || type > WindowManager.LayoutParams.LAST_SYSTEM_WINDOW) {
Jeff Brown98365d72012-08-19 20:30:52 -07001363 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001364 }
1365 String permission = null;
1366 switch (type) {
1367 case TYPE_TOAST:
1368 // XXX right now the app process has complete control over
1369 // this... should introduce a token to let the system
1370 // monitor/control what they are doing.
Jason Monk1c7c3192014-06-26 12:52:18 -04001371 outAppOp[0] = AppOpsManager.OP_TOAST_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001372 break;
Daniel Sandler7d276c32012-01-30 14:33:52 -05001373 case TYPE_DREAM:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001374 case TYPE_INPUT_METHOD:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001375 case TYPE_WALLPAPER:
keunyounga446bf02013-06-21 19:07:57 -07001376 case TYPE_PRIVATE_PRESENTATION:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001377 case TYPE_VOICE_INTERACTION:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001378 // The window manager will check these.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001379 break;
1380 case TYPE_PHONE:
1381 case TYPE_PRIORITY_PHONE:
1382 case TYPE_SYSTEM_ALERT:
1383 case TYPE_SYSTEM_ERROR:
1384 case TYPE_SYSTEM_OVERLAY:
1385 permission = android.Manifest.permission.SYSTEM_ALERT_WINDOW;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001386 outAppOp[0] = AppOpsManager.OP_SYSTEM_ALERT_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001387 break;
1388 default:
1389 permission = android.Manifest.permission.INTERNAL_SYSTEM_WINDOW;
1390 }
1391 if (permission != null) {
1392 if (mContext.checkCallingOrSelfPermission(permission)
1393 != PackageManager.PERMISSION_GRANTED) {
Jeff Brown98365d72012-08-19 20:30:52 -07001394 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001395 }
1396 }
Jeff Brown98365d72012-08-19 20:30:52 -07001397 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001398 }
Craig Mautner88400d32012-09-30 12:35:45 -07001399
1400 @Override
1401 public boolean checkShowToOwnerOnly(WindowManager.LayoutParams attrs) {
1402
1403 // If this switch statement is modified, modify the comment in the declarations of
1404 // the type in {@link WindowManager.LayoutParams} as well.
1405 switch (attrs.type) {
1406 default:
1407 // These are the windows that by default are shown only to the user that created
1408 // them. If this needs to be overridden, set
1409 // {@link WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS} in
1410 // {@link WindowManager.LayoutParams}. Note that permission
1411 // {@link android.Manifest.permission.INTERNAL_SYSTEM_WINDOW} is required as well.
1412 if ((attrs.privateFlags & PRIVATE_FLAG_SHOW_FOR_ALL_USERS) == 0) {
1413 return true;
1414 }
1415 break;
1416
1417 // These are the windows that by default are shown to all users. However, to
1418 // protect against spoofing, check permissions below.
1419 case TYPE_APPLICATION_STARTING:
1420 case TYPE_BOOT_PROGRESS:
1421 case TYPE_DISPLAY_OVERLAY:
1422 case TYPE_HIDDEN_NAV_CONSUMER:
Jim Miller5ecd8112013-01-09 18:50:26 -08001423 case TYPE_KEYGUARD_SCRIM:
Craig Mautner88400d32012-09-30 12:35:45 -07001424 case TYPE_KEYGUARD_DIALOG:
1425 case TYPE_MAGNIFICATION_OVERLAY:
1426 case TYPE_NAVIGATION_BAR:
1427 case TYPE_NAVIGATION_BAR_PANEL:
1428 case TYPE_PHONE:
1429 case TYPE_POINTER:
1430 case TYPE_PRIORITY_PHONE:
1431 case TYPE_RECENTS_OVERLAY:
1432 case TYPE_SEARCH_BAR:
1433 case TYPE_STATUS_BAR:
1434 case TYPE_STATUS_BAR_PANEL:
1435 case TYPE_STATUS_BAR_SUB_PANEL:
1436 case TYPE_SYSTEM_DIALOG:
1437 case TYPE_UNIVERSE_BACKGROUND:
1438 case TYPE_VOLUME_OVERLAY:
keunyounga446bf02013-06-21 19:07:57 -07001439 case TYPE_PRIVATE_PRESENTATION:
Craig Mautner88400d32012-09-30 12:35:45 -07001440 break;
1441 }
1442
1443 // Check if third party app has set window to system window type.
1444 return mContext.checkCallingOrSelfPermission(
1445 android.Manifest.permission.INTERNAL_SYSTEM_WINDOW)
1446 != PackageManager.PERMISSION_GRANTED;
1447 }
1448
Craig Mautner967212c2013-04-13 21:10:58 -07001449 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001450 public void adjustWindowParamsLw(WindowManager.LayoutParams attrs) {
1451 switch (attrs.type) {
1452 case TYPE_SYSTEM_OVERLAY:
Jeff Brown3b2b3542010-10-15 00:54:27 -07001453 case TYPE_SECURE_SYSTEM_OVERLAY:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001454 // These types of windows can't receive input events.
1455 attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1456 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001457 attrs.flags &= ~WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001458 break;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001459 case TYPE_STATUS_BAR:
1460
1461 // If the Keyguard is in a hidden state (occluded by another window), we force to
1462 // remove the wallpaper and keyguard flag so that any change in-flight after setting
1463 // the keyguard as occluded wouldn't set these flags again.
1464 // See {@link #processKeyguardSetHiddenResultLw}.
1465 if (mKeyguardHidden) {
1466 attrs.flags &= ~WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
1467 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
1468 }
1469 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001470 }
Adrian Roos38502112014-04-09 21:04:11 +02001471
1472 if (attrs.type != TYPE_STATUS_BAR) {
1473 // The status bar is the only window allowed to exhibit keyguard behavior.
1474 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
1475 }
Adrian Roosea562512014-05-05 13:33:03 +02001476
1477 if (ActivityManager.isHighEndGfx()
1478 && (attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0) {
1479 attrs.subtreeSystemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_STABLE
1480 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
1481 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
1482 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001483 }
RoboErik8a2cfc32014-05-16 11:19:38 -07001484
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001485 void readLidState() {
Jeff Brown2e7760e2012-04-11 15:14:55 -07001486 mLidState = mWindowManagerFuncs.getLidState();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001487 }
RoboErik8a2cfc32014-05-16 11:19:38 -07001488
Jeff Browndaa37532012-05-01 15:54:03 -07001489 private boolean isHidden(int accessibilityMode) {
1490 switch (accessibilityMode) {
1491 case 1:
1492 return mLidState == LID_CLOSED;
1493 case 2:
1494 return mLidState == LID_OPEN;
1495 default:
1496 return false;
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001497 }
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001498 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001499
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001500 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07001501 @Override
Jeff Browndaa37532012-05-01 15:54:03 -07001502 public void adjustConfigurationLw(Configuration config, int keyboardPresence,
1503 int navigationPresence) {
1504 mHaveBuiltInKeyboard = (keyboardPresence & PRESENCE_INTERNAL) != 0;
1505
Jeff Brownf71343d2013-05-31 17:59:11 -07001506 readConfigurationDependentBehaviors();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001507 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07001508 applyLidSwitchState();
Jeff Brownd04a88c2011-01-16 14:05:47 -08001509
Jeff Browndaa37532012-05-01 15:54:03 -07001510 if (config.keyboard == Configuration.KEYBOARD_NOKEYS
1511 || (keyboardPresence == PRESENCE_INTERNAL
1512 && isHidden(mLidKeyboardAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001513 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_YES;
Jeff Browndaa37532012-05-01 15:54:03 -07001514 if (!mHasSoftInput) {
1515 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_YES;
1516 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001517 }
1518
Jeff Browndaa37532012-05-01 15:54:03 -07001519 if (config.navigation == Configuration.NAVIGATION_NONAV
1520 || (navigationPresence == PRESENCE_INTERNAL
1521 && isHidden(mLidNavigationAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001522 config.navigationHidden = Configuration.NAVIGATIONHIDDEN_YES;
Jeff Brownd04a88c2011-01-16 14:05:47 -08001523 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001524 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001525
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001526 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07001527 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001528 public int windowTypeToLayerLw(int type) {
1529 if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001530 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001531 }
1532 switch (type) {
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001533 case TYPE_UNIVERSE_BACKGROUND:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001534 return 1;
keunyounga446bf02013-06-21 19:07:57 -07001535 case TYPE_PRIVATE_PRESENTATION:
1536 return 2;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001537 case TYPE_WALLPAPER:
1538 // wallpaper is at the bottom, though the window manager may move it.
1539 return 2;
1540 case TYPE_PHONE:
1541 return 3;
1542 case TYPE_SEARCH_BAR:
1543 return 4;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001544 case TYPE_VOICE_INTERACTION:
1545 // voice interaction layer is almost immediately above apps.
1546 return 5;
Craig Mautner88400d32012-09-30 12:35:45 -07001547 case TYPE_RECENTS_OVERLAY:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001548 case TYPE_SYSTEM_DIALOG:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001549 return 6;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001550 case TYPE_TOAST:
1551 // toasts and the plugged-in battery thing
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001552 return 7;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001553 case TYPE_PRIORITY_PHONE:
1554 // SIM errors and unlock. Not sure if this really should be in a high layer.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001555 return 8;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001556 case TYPE_DREAM:
1557 // used for Dreams (screensavers with TYPE_DREAM windows)
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001558 return 9;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001559 case TYPE_SYSTEM_ALERT:
1560 // like the ANR / app crashed dialogs
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001561 return 10;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001562 case TYPE_INPUT_METHOD:
1563 // on-screen keyboards and other such input method user interfaces go here.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001564 return 11;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001565 case TYPE_INPUT_METHOD_DIALOG:
1566 // on-screen keyboards and other such input method user interfaces go here.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001567 return 12;
Jim Miller5ecd8112013-01-09 18:50:26 -08001568 case TYPE_KEYGUARD_SCRIM:
1569 // the safety window that shows behind keyguard while keyguard is starting
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001570 return 13;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001571 case TYPE_STATUS_BAR_SUB_PANEL:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001572 return 14;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001573 case TYPE_STATUS_BAR:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001574 return 15;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001575 case TYPE_STATUS_BAR_PANEL:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001576 return 16;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001577 case TYPE_KEYGUARD_DIALOG:
1578 return 17;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001579 case TYPE_VOLUME_OVERLAY:
1580 // the on-screen volume indicator and controller shown when the user
1581 // changes the device volume
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001582 return 18;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001583 case TYPE_SYSTEM_OVERLAY:
1584 // the on-screen volume indicator and controller shown when the user
1585 // changes the device volume
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001586 return 19;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001587 case TYPE_NAVIGATION_BAR:
1588 // the navigation bar, if available, shows atop most things
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001589 return 20;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001590 case TYPE_NAVIGATION_BAR_PANEL:
1591 // some panels (e.g. search) need to show on top of the navigation bar
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001592 return 21;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001593 case TYPE_SYSTEM_ERROR:
1594 // system-level error dialogs
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001595 return 22;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001596 case TYPE_MAGNIFICATION_OVERLAY:
1597 // used to highlight the magnified portion of a display
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001598 return 23;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001599 case TYPE_DISPLAY_OVERLAY:
1600 // used to simulate secondary display devices
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001601 return 24;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001602 case TYPE_DRAG:
1603 // the drag layer: input for drag-and-drop is associated with this window,
1604 // which sits above all other focusable windows
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001605 return 25;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001606 case TYPE_SECURE_SYSTEM_OVERLAY:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001607 return 26;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001608 case TYPE_BOOT_PROGRESS:
1609 return 27;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001610 case TYPE_POINTER:
1611 // the (mouse) pointer layer
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001612 return 28;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001613 case TYPE_HIDDEN_NAV_CONSUMER:
1614 return 29;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001615 }
1616 Log.e(TAG, "Unknown window type: " + type);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001617 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001618 }
1619
1620 /** {@inheritDoc} */
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001621 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001622 public int subWindowTypeToLayerLw(int type) {
1623 switch (type) {
1624 case TYPE_APPLICATION_PANEL:
1625 case TYPE_APPLICATION_ATTACHED_DIALOG:
1626 return APPLICATION_PANEL_SUBLAYER;
1627 case TYPE_APPLICATION_MEDIA:
1628 return APPLICATION_MEDIA_SUBLAYER;
Dianne Hackborn5cb8d792009-05-21 17:34:15 -07001629 case TYPE_APPLICATION_MEDIA_OVERLAY:
1630 return APPLICATION_MEDIA_OVERLAY_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001631 case TYPE_APPLICATION_SUB_PANEL:
1632 return APPLICATION_SUB_PANEL_SUBLAYER;
1633 }
1634 Log.e(TAG, "Unknown sub-window type: " + type);
1635 return 0;
1636 }
1637
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001638 @Override
Dianne Hackbornabe0da02009-09-18 01:55:39 -07001639 public int getMaxWallpaperLayer() {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001640 return windowTypeToLayerLw(TYPE_STATUS_BAR);
Dianne Hackbornabe0da02009-09-18 01:55:39 -07001641 }
1642
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001643 @Override
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001644 public int getAboveUniverseLayer() {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001645 return windowTypeToLayerLw(TYPE_SYSTEM_ERROR);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001646 }
1647
Jose Lima9546b202014-07-02 17:21:51 -07001648 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001649 public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07001650 if (mHasNavigationBar) {
1651 // For a basic navigation bar, when we are in landscape mode we place
1652 // the navigation bar to the side.
Daniel Sandler4a066c52012-04-20 14:49:13 -04001653 if (mNavigationBarCanMove && fullWidth > fullHeight) {
1654 return fullWidth - mNavigationBarWidthForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07001655 }
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001656 }
1657 return fullWidth;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001658 }
1659
Jose Lima9546b202014-07-02 17:21:51 -07001660 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001661 public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07001662 if (mHasNavigationBar) {
1663 // For a basic navigation bar, when we are in portrait mode we place
1664 // the navigation bar to the bottom.
Daniel Sandler4a066c52012-04-20 14:49:13 -04001665 if (!mNavigationBarCanMove || fullWidth < fullHeight) {
1666 return fullHeight - mNavigationBarHeightForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07001667 }
1668 }
1669 return fullHeight;
Dianne Hackborn69cb8752011-05-19 18:13:32 -07001670 }
1671
Jose Lima9546b202014-07-02 17:21:51 -07001672 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001673 public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation) {
1674 return getNonDecorDisplayWidth(fullWidth, fullHeight, rotation);
Dianne Hackborn69cb8752011-05-19 18:13:32 -07001675 }
1676
Jose Lima9546b202014-07-02 17:21:51 -07001677 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001678 public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation) {
John Spurlock80f00c12013-06-13 11:10:51 -04001679 // There is a separate status bar at the top of the display. We don't count that as part
1680 // of the fixed decor, since it can hide; however, for purposes of configurations,
Dianne Hackborn077ee852012-04-09 16:27:07 -07001681 // we do want to exclude it since applications can't generally use that part
1682 // of the screen.
John Spurlock80f00c12013-06-13 11:10:51 -04001683 return getNonDecorDisplayHeight(fullWidth, fullHeight, rotation) - mStatusBarHeight;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001684 }
1685
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001686 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07001687 public boolean isForceHiding(WindowManager.LayoutParams attrs) {
1688 return (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 ||
1689 (isKeyguardHostWindow(attrs) && isKeyguardSecureIncludingHidden());
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07001690 }
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001691
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001692 @Override
Jorim Jaggi0d674622014-05-21 01:34:15 +02001693 public boolean isKeyguardHostWindow(WindowManager.LayoutParams attrs) {
1694 return attrs.type == TYPE_STATUS_BAR;
1695 }
1696
1697 @Override
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07001698 public boolean canBeForceHidden(WindowState win, WindowManager.LayoutParams attrs) {
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001699 switch (attrs.type) {
1700 case TYPE_STATUS_BAR:
1701 case TYPE_NAVIGATION_BAR:
1702 case TYPE_WALLPAPER:
1703 case TYPE_DREAM:
1704 case TYPE_UNIVERSE_BACKGROUND:
Jim Miller5ecd8112013-01-09 18:50:26 -08001705 case TYPE_KEYGUARD_SCRIM:
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001706 return false;
1707 default:
1708 return true;
1709 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07001710 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001711
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001712 /** {@inheritDoc} */
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001713 @Override
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07001714 public View addStartingWindow(IBinder appToken, String packageName, int theme,
1715 CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes,
Adam Powell04fe6eb2013-05-31 14:39:48 -07001716 int icon, int logo, int windowFlags) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001717 if (!SHOW_STARTING_ANIMATIONS) {
1718 return null;
1719 }
1720 if (packageName == null) {
1721 return null;
1722 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001723
Mathias Jeppssond1443e92012-08-24 15:25:32 +02001724 WindowManager wm = null;
1725 View view = null;
1726
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001727 try {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001728 Context context = mContext;
Craig Mautner6fbda632012-07-03 09:26:39 -07001729 if (DEBUG_STARTING_WINDOW) Slog.d(TAG, "addStartingWindow " + packageName
1730 + ": nonLocalizedLabel=" + nonLocalizedLabel + " theme="
1731 + Integer.toHexString(theme));
Dianne Hackborn247fe742011-01-08 17:25:57 -08001732 if (theme != context.getThemeResId() || labelRes != 0) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001733 try {
1734 context = context.createPackageContext(packageName, 0);
Dianne Hackborn247fe742011-01-08 17:25:57 -08001735 context.setTheme(theme);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001736 } catch (PackageManager.NameNotFoundException e) {
1737 // Ignore
1738 }
1739 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001740
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001741 Window win = PolicyManager.makeNewWindow(context);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001742 final TypedArray ta = win.getWindowStyle();
1743 if (ta.getBoolean(
1744 com.android.internal.R.styleable.Window_windowDisablePreview, false)
1745 || ta.getBoolean(
1746 com.android.internal.R.styleable.Window_windowShowWallpaper,false)) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001747 return null;
1748 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001749
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001750 Resources r = context.getResources();
1751 win.setTitle(r.getText(labelRes, nonLocalizedLabel));
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001752
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001753 win.setType(
1754 WindowManager.LayoutParams.TYPE_APPLICATION_STARTING);
1755 // Force the window flags: this is a fake window, so it is not really
1756 // touchable or focusable by the user. We also add in the ALT_FOCUSABLE_IM
1757 // flag because we do know that the next window will take input
1758 // focus, so we want to get the IME window up on top of us right away.
1759 win.setFlags(
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08001760 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001761 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
1762 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
1763 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08001764 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001765 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
1766 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
1767 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001768
Adam Powell04fe6eb2013-05-31 14:39:48 -07001769 win.setDefaultIcon(icon);
1770 win.setDefaultLogo(logo);
1771
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001772 win.setLayout(WindowManager.LayoutParams.MATCH_PARENT,
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07001773 WindowManager.LayoutParams.MATCH_PARENT);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001774
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001775 final WindowManager.LayoutParams params = win.getAttributes();
1776 params.token = appToken;
1777 params.packageName = packageName;
1778 params.windowAnimations = win.getWindowStyle().getResourceId(
1779 com.android.internal.R.styleable.Window_windowAnimationStyle, 0);
Dianne Hackborn5d927c22011-09-02 12:22:18 -07001780 params.privateFlags |=
1781 WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED;
Craig Mautner88400d32012-09-30 12:35:45 -07001782 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
Adam Lesinski95c42972013-10-02 10:13:27 -07001783
1784 if (!compatInfo.supportsScreen()) {
1785 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
1786 }
1787
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001788 params.setTitle("Starting " + packageName);
1789
Mathias Jeppssond1443e92012-08-24 15:25:32 +02001790 wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
1791 view = win.getDecorView();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001792
1793 if (win.isFloating()) {
1794 // Whoops, there is no way to display an animation/preview
1795 // of such a thing! After all that work... let's skip it.
1796 // (Note that we must do this here because it is in
1797 // getDecorView() where the theme is evaluated... maybe
1798 // we should peek the floating attribute from the theme
1799 // earlier.)
1800 return null;
1801 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001802
Craig Mautner6fbda632012-07-03 09:26:39 -07001803 if (DEBUG_STARTING_WINDOW) Slog.d(
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001804 TAG, "Adding starting window for " + packageName
1805 + " / " + appToken + ": "
1806 + (view.getParent() != null ? view : null));
1807
1808 wm.addView(view, params);
1809
1810 // Only return the view if it was successfully added to the
1811 // window manager... which we can tell by it having a parent.
1812 return view.getParent() != null ? view : null;
Jeff Brown98365d72012-08-19 20:30:52 -07001813 } catch (WindowManager.BadTokenException e) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001814 // ignore
Craig Mautner42bf39e2014-02-21 16:46:22 -08001815 Log.w(TAG, appToken + " already running, starting window not displayed. " +
1816 e.getMessage());
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001817 } catch (RuntimeException e) {
1818 // don't crash if something else bad happens, for example a
1819 // failure loading resources because we are loading from an app
1820 // on external storage that has been unmounted.
1821 Log.w(TAG, appToken + " failed creating starting window", e);
Mathias Jeppssond1443e92012-08-24 15:25:32 +02001822 } finally {
1823 if (view != null && view.getParent() == null) {
1824 Log.w(TAG, "view not successfully added to wm, removing view");
1825 wm.removeViewImmediate(view);
1826 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001827 }
1828
1829 return null;
1830 }
1831
1832 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07001833 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001834 public void removeStartingWindow(IBinder appToken, View window) {
Craig Mautner6fbda632012-07-03 09:26:39 -07001835 if (DEBUG_STARTING_WINDOW) {
1836 RuntimeException e = new RuntimeException("here");
1837 e.fillInStackTrace();
1838 Log.v(TAG, "Removing starting window for " + appToken + ": " + window, e);
1839 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001840
1841 if (window != null) {
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001842 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001843 wm.removeView(window);
1844 }
1845 }
1846
1847 /**
1848 * Preflight adding a window to the system.
RoboErik8a2cfc32014-05-16 11:19:38 -07001849 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001850 * Currently enforces that three window types are singletons:
1851 * <ul>
1852 * <li>STATUS_BAR_TYPE</li>
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001853 * <li>KEYGUARD_TYPE</li>
1854 * </ul>
RoboErik8a2cfc32014-05-16 11:19:38 -07001855 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001856 * @param win The window to be added
1857 * @param attrs Information about the window to be added
RoboErik8a2cfc32014-05-16 11:19:38 -07001858 *
Jeff Brown98365d72012-08-19 20:30:52 -07001859 * @return If ok, WindowManagerImpl.ADD_OKAY. If too many singletons,
1860 * WindowManagerImpl.ADD_MULTIPLE_SINGLETON
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001861 */
Jose Lima9546b202014-07-02 17:21:51 -07001862 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001863 public int prepareAddWindowLw(WindowState win, WindowManager.LayoutParams attrs) {
1864 switch (attrs.type) {
1865 case TYPE_STATUS_BAR:
Joe Onorato8bc6c512010-06-04 16:21:12 -04001866 mContext.enforceCallingOrSelfPermission(
1867 android.Manifest.permission.STATUS_BAR_SERVICE,
1868 "PhoneWindowManager");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001869 if (mStatusBar != null) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001870 if (mStatusBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07001871 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001872 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001873 }
1874 mStatusBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04001875 mStatusBarController.setWindow(win);
John Spurlock8fdfe622014-05-21 17:10:10 -04001876 mKeyguardDelegate.hideScrim();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001877 break;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04001878 case TYPE_NAVIGATION_BAR:
1879 mContext.enforceCallingOrSelfPermission(
1880 android.Manifest.permission.STATUS_BAR_SERVICE,
1881 "PhoneWindowManager");
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001882 if (mNavigationBar != null) {
1883 if (mNavigationBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07001884 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001885 }
1886 }
Daniel Sandler8956dbb2011-04-22 07:55:02 -04001887 mNavigationBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04001888 mNavigationBarController.setWindow(win);
Craig Mautnereda67292013-04-28 13:50:14 -07001889 if (DEBUG_LAYOUT) Slog.i(TAG, "NAVIGATION BAR: " + mNavigationBar);
Daniel Sandler8956dbb2011-04-22 07:55:02 -04001890 break;
Jim Millere898ac52012-04-06 17:10:57 -07001891 case TYPE_NAVIGATION_BAR_PANEL:
1892 mContext.enforceCallingOrSelfPermission(
1893 android.Manifest.permission.STATUS_BAR_SERVICE,
1894 "PhoneWindowManager");
1895 break;
Dianne Hackborn08743722009-12-21 12:16:51 -08001896 case TYPE_STATUS_BAR_PANEL:
Joe Onorato8bc6c512010-06-04 16:21:12 -04001897 mContext.enforceCallingOrSelfPermission(
1898 android.Manifest.permission.STATUS_BAR_SERVICE,
1899 "PhoneWindowManager");
Dianne Hackborn08743722009-12-21 12:16:51 -08001900 break;
Joe Onorato29fc2c92010-11-24 10:26:50 -08001901 case TYPE_STATUS_BAR_SUB_PANEL:
1902 mContext.enforceCallingOrSelfPermission(
1903 android.Manifest.permission.STATUS_BAR_SERVICE,
1904 "PhoneWindowManager");
Joe Onorato29fc2c92010-11-24 10:26:50 -08001905 break;
Jim Miller5ecd8112013-01-09 18:50:26 -08001906 case TYPE_KEYGUARD_SCRIM:
Jim Miller25190572013-02-28 17:36:24 -08001907 if (mKeyguardScrim != null) {
1908 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
1909 }
Jim Miller5ecd8112013-01-09 18:50:26 -08001910 mKeyguardScrim = win;
1911 break;
1912
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001913 }
Jeff Brown98365d72012-08-19 20:30:52 -07001914 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001915 }
1916
1917 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07001918 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001919 public void removeWindowLw(WindowState win) {
1920 if (mStatusBar == win) {
1921 mStatusBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04001922 mStatusBarController.setWindow(null);
Jim Millerc0b676d2013-03-22 16:11:08 -07001923 mKeyguardDelegate.showScrim();
Jim Miller5ecd8112013-01-09 18:50:26 -08001924 } else if (mKeyguardScrim == win) {
1925 Log.v(TAG, "Removing keyguard scrim");
1926 mKeyguardScrim = null;
1927 } if (mNavigationBar == win) {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04001928 mNavigationBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04001929 mNavigationBarController.setWindow(null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001930 }
1931 }
1932
1933 static final boolean PRINT_ANIM = false;
RoboErik8a2cfc32014-05-16 11:19:38 -07001934
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001935 /** {@inheritDoc} */
Craig Mautner4b71aa12012-12-27 17:20:01 -08001936 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001937 public int selectAnimationLw(WindowState win, int transit) {
1938 if (PRINT_ANIM) Log.i(TAG, "selectAnimation in " + win
1939 + ": transit=" + transit);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001940 if (win == mStatusBar) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001941 boolean isKeyguard = (win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001942 if (transit == TRANSIT_EXIT
1943 || transit == TRANSIT_HIDE) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001944 return isKeyguard ? -1 : R.anim.dock_top_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001945 } else if (transit == TRANSIT_ENTER
1946 || transit == TRANSIT_SHOW) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001947 return isKeyguard ? -1 : R.anim.dock_top_enter;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001948 }
1949 } else if (win == mNavigationBar) {
1950 // This can be on either the bottom or the right.
1951 if (mNavigationBarOnBottom) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08001952 if (transit == TRANSIT_EXIT
1953 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001954 return R.anim.dock_bottom_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001955 } else if (transit == TRANSIT_ENTER
1956 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001957 return R.anim.dock_bottom_enter;
1958 }
1959 } else {
Craig Mautner4b71aa12012-12-27 17:20:01 -08001960 if (transit == TRANSIT_EXIT
1961 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001962 return R.anim.dock_right_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001963 } else if (transit == TRANSIT_ENTER
1964 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001965 return R.anim.dock_right_enter;
1966 }
1967 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08001968 }
1969
1970 if (transit == TRANSIT_PREVIEW_DONE) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001971 if (win.hasAppShownWindows()) {
1972 if (PRINT_ANIM) Log.i(TAG, "**** STARTING EXIT");
1973 return com.android.internal.R.anim.app_starting_exit;
1974 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07001975 } else if (win.getAttrs().type == TYPE_DREAM && mDreamingLockscreen
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001976 && transit == TRANSIT_ENTER) {
1977 // Special case: we are animating in a dream, while the keyguard
1978 // is shown. We don't want an animation on the dream, because
1979 // we need it shown immediately with the keyguard animating away
1980 // to reveal it.
1981 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001982 }
1983
1984 return 0;
1985 }
1986
Craig Mautner3c174372013-02-21 17:54:37 -08001987 @Override
1988 public void selectRotationAnimationLw(int anim[]) {
1989 if (PRINT_ANIM) Slog.i(TAG, "selectRotationAnimation mTopFullscreen="
1990 + mTopFullscreenOpaqueWindowState + " rotationAnimation="
1991 + (mTopFullscreenOpaqueWindowState == null ?
1992 "0" : mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation));
1993 if (mTopFullscreenOpaqueWindowState != null && mTopIsFullscreen) {
1994 switch (mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation) {
1995 case ROTATION_ANIMATION_CROSSFADE:
1996 anim[0] = R.anim.rotation_animation_xfade_exit;
1997 anim[1] = R.anim.rotation_animation_enter;
1998 break;
1999 case ROTATION_ANIMATION_JUMPCUT:
2000 anim[0] = R.anim.rotation_animation_jump_exit;
2001 anim[1] = R.anim.rotation_animation_enter;
2002 break;
2003 case ROTATION_ANIMATION_ROTATE:
2004 default:
2005 anim[0] = anim[1] = 0;
2006 break;
2007 }
2008 } else {
2009 anim[0] = anim[1] = 0;
2010 }
2011 }
2012
2013 @Override
2014 public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId,
2015 boolean forceDefault) {
2016 switch (exitAnimId) {
2017 case R.anim.rotation_animation_xfade_exit:
2018 case R.anim.rotation_animation_jump_exit:
2019 // These are the only cases that matter.
2020 if (forceDefault) {
2021 return false;
2022 }
2023 int anim[] = new int[2];
2024 selectRotationAnimationLw(anim);
2025 return (exitAnimId == anim[0] && enterAnimId == anim[1]);
2026 default:
2027 return true;
2028 }
2029 }
2030
2031 @Override
Dianne Hackborn0c2acff2012-04-12 15:17:07 -07002032 public Animation createForceHideEnterAnimation(boolean onWallpaper) {
Jorim Jaggie29b2db2014-05-30 23:17:03 +02002033 return AnimationUtils.loadAnimation(mContext,
2034 com.android.internal.R.anim.lock_screen_behind_enter);
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002035 }
John Spurlockc8b46ca2013-04-08 12:59:26 -04002036
2037 private static void awakenDreams() {
2038 IDreamManager dreamManager = getDreamManager();
2039 if (dreamManager != null) {
2040 try {
2041 dreamManager.awaken();
2042 } catch (RemoteException e) {
2043 // fine, stay asleep then
2044 }
2045 }
2046 }
2047
2048 static IDreamManager getDreamManager() {
2049 return IDreamManager.Stub.asInterface(
2050 ServiceManager.checkService(DreamService.DREAM_SERVICE));
2051 }
2052
Santos Cordon9eb45932014-06-27 12:28:43 -07002053 TelecommManager getTelecommService() {
2054 return (TelecommManager) mContext.getSystemService(Context.TELECOMM_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002055 }
2056
Jeff Brown4d396052010-10-29 21:50:21 -07002057 static IAudioService getAudioService() {
2058 IAudioService audioService = IAudioService.Stub.asInterface(
2059 ServiceManager.checkService(Context.AUDIO_SERVICE));
2060 if (audioService == null) {
2061 Log.w(TAG, "Unable to find IAudioService interface.");
2062 }
2063 return audioService;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002064 }
2065
2066 boolean keyguardOn() {
2067 return keyguardIsShowingTq() || inKeyguardRestrictedKeyInputMode();
2068 }
2069
2070 private static final int[] WINDOW_TYPES_WHERE_HOME_DOESNT_WORK = {
2071 WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
2072 WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
2073 };
2074
2075 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002076 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002077 public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002078 final boolean keyguardOn = keyguardOn();
Jeff Brown1f245102010-11-18 20:53:46 -08002079 final int keyCode = event.getKeyCode();
2080 final int repeatCount = event.getRepeatCount();
2081 final int metaState = event.getMetaState();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002082 final int flags = event.getFlags();
Jeff Brown1f245102010-11-18 20:53:46 -08002083 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
2084 final boolean canceled = event.isCanceled();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002085
Jeff Brown40013652012-05-16 21:22:36 -07002086 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002087 Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount="
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002088 + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed
2089 + " canceled=" + canceled);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002090 }
2091
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002092 // If we think we might have a volume down & power key chord on the way
2093 // but we're not sure, then tell the dispatcher to wait a little while and
2094 // try again later before dispatching.
Christopher Tatee90585f2012-03-05 18:56:25 -08002095 if (mScreenshotChordEnabled && (flags & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002096 if (mVolumeDownKeyTriggered && !mPowerKeyTriggered) {
2097 final long now = SystemClock.uptimeMillis();
2098 final long timeoutTime = mVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS;
2099 if (now < timeoutTime) {
2100 return timeoutTime - now;
2101 }
2102 }
2103 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
2104 && mVolumeDownKeyConsumedByScreenshotChord) {
2105 if (!down) {
2106 mVolumeDownKeyConsumedByScreenshotChord = false;
2107 }
2108 return -1;
2109 }
2110 }
2111
Michael Wright6a62e552014-06-03 19:19:48 -07002112 // Cancel any pending meta actions if we see any other keys being pressed between the down
2113 // of the meta key and its corresponding up.
2114 if (mPendingMetaAction && keyCode != KeyEvent.KEYCODE_META_LEFT) {
2115 mPendingMetaAction = false;
2116 }
2117
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002118 // First we always handle the home key here, so applications
2119 // can never break it, although if keyguard is on, we do let
2120 // it handle it, because that gives us the correct 5 second
2121 // timeout.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002122 if (keyCode == KeyEvent.KEYCODE_HOME) {
Michael Jurka7f2668c2012-03-27 07:49:52 -07002123
Jeff Brown49ed71d2010-12-06 17:13:33 -08002124 // If we have released the home key, and didn't do anything else
2125 // while it was pressed, then it is time to go home!
Michael Jurka7f2668c2012-03-27 07:49:52 -07002126 if (!down) {
Jeff Browncaca8812013-05-09 13:34:33 -07002127 cancelPreloadRecentApps();
2128
Jeff Brown49ed71d2010-12-06 17:13:33 -08002129 mHomePressed = false;
Jeff Browncaca8812013-05-09 13:34:33 -07002130 if (mHomeConsumed) {
2131 mHomeConsumed = false;
Michael Jurka7f2668c2012-03-27 07:49:52 -07002132 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002133 }
Jeff Browncaca8812013-05-09 13:34:33 -07002134
2135 if (canceled) {
2136 Log.i(TAG, "Ignoring HOME; event canceled.");
2137 return -1;
2138 }
2139
2140 // If an incoming call is ringing, HOME is totally disabled.
Santos Cordon9eb45932014-06-27 12:28:43 -07002141 // (The user is already on the InCallUI at this point,
Jeff Browncaca8812013-05-09 13:34:33 -07002142 // and his ONLY options are to answer or reject the call.)
Santos Cordon9eb45932014-06-27 12:28:43 -07002143 TelecommManager telecommManager = getTelecommService();
2144 if (telecommManager != null && telecommManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07002145 Log.i(TAG, "Ignoring HOME; there's a ringing incoming call.");
2146 return -1;
Jeff Browncaca8812013-05-09 13:34:33 -07002147 }
2148
2149 // Delay handling home if a double-tap is possible.
2150 if (mDoubleTapOnHomeBehavior != DOUBLE_TAP_HOME_NOTHING) {
2151 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); // just in case
2152 mHomeDoubleTapPending = true;
2153 mHandler.postDelayed(mHomeDoubleTapTimeoutRunnable,
2154 ViewConfiguration.getDoubleTapTimeout());
2155 return -1;
2156 }
2157
Jose Lima9546b202014-07-02 17:21:51 -07002158 // If there's a dream running then use home to escape the dream
2159 // but don't actually go home.
2160 if (mDreamManagerInternal != null && mDreamManagerInternal.isDreaming()) {
2161 mDreamManagerInternal.stopDream();
2162 return -1;
2163 }
2164
Jeff Browncaca8812013-05-09 13:34:33 -07002165 // Go home!
2166 launchHomeFromHotKey();
2167 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002168 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002169
2170 // If a system window has focus, then it doesn't make sense
2171 // right now to interact with applications.
2172 WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null;
2173 if (attrs != null) {
2174 final int type = attrs.type;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002175 if (type == WindowManager.LayoutParams.TYPE_KEYGUARD_SCRIM
2176 || type == WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG
2177 || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002178 // the "app" is keyguard, so give it the key
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002179 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002180 }
2181 final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length;
2182 for (int i=0; i<typeCount; i++) {
2183 if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) {
2184 // don't do anything, but also don't pass it to the app
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002185 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002186 }
2187 }
2188 }
Jeff Browncaca8812013-05-09 13:34:33 -07002189
2190 // Remember that home is pressed and handle special actions.
2191 if (repeatCount == 0) {
2192 mHomePressed = true;
2193 if (mHomeDoubleTapPending) {
2194 mHomeDoubleTapPending = false;
2195 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable);
2196 handleDoubleTapOnHome();
2197 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI
2198 || mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
2199 preloadRecentApps();
Michael Jurka7f2668c2012-03-27 07:49:52 -07002200 }
Jeff Browncaca8812013-05-09 13:34:33 -07002201 } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) {
2202 if (!keyguardOn) {
2203 handleLongPressOnHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002204 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002205 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002206 return -1;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002207 } else if (keyCode == KeyEvent.KEYCODE_MENU) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002208 // Hijack modified menu keys for debugging features
2209 final int chordBug = KeyEvent.META_SHIFT_ON;
2210
2211 if (down && repeatCount == 0) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002212 if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002213 Intent intent = new Intent(Intent.ACTION_BUG_REPORT);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002214 mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT,
2215 null, null, null, 0, null, null);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002216 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002217 } else if (SHOW_PROCESSES_ON_ALT_MENU &&
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002218 (metaState & KeyEvent.META_ALT_ON) == KeyEvent.META_ALT_ON) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002219 Intent service = new Intent();
2220 service.setClassName(mContext, "com.android.server.LoadAverageService");
2221 ContentResolver res = mContext.getContentResolver();
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002222 boolean shown = Settings.Global.getInt(
2223 res, Settings.Global.SHOW_PROCESSES, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002224 if (!shown) {
2225 mContext.startService(service);
2226 } else {
2227 mContext.stopService(service);
2228 }
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002229 Settings.Global.putInt(
2230 res, Settings.Global.SHOW_PROCESSES, shown ? 0 : 1);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002231 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002232 }
2233 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002234 } else if (keyCode == KeyEvent.KEYCODE_SEARCH) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002235 if (down) {
2236 if (repeatCount == 0) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002237 mSearchKeyShortcutPending = true;
2238 mConsumeSearchKeyUp = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002239 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002240 } else {
2241 mSearchKeyShortcutPending = false;
2242 if (mConsumeSearchKeyUp) {
2243 mConsumeSearchKeyUp = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002244 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002245 }
2246 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002247 return 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002248 } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) {
Michael Wrightc9ebea72013-01-16 19:25:02 -08002249 if (!keyguardOn) {
Jeff Browncaca8812013-05-09 13:34:33 -07002250 if (down && repeatCount == 0) {
2251 preloadRecentApps();
2252 } else if (!down) {
2253 toggleRecentApps();
Michael Wrightc9ebea72013-01-16 19:25:02 -08002254 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002255 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002256 return -1;
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002257 } else if (keyCode == KeyEvent.KEYCODE_ASSIST) {
2258 if (down) {
2259 if (repeatCount == 0) {
2260 mAssistKeyLongPressed = false;
2261 } else if (repeatCount == 1) {
2262 mAssistKeyLongPressed = true;
2263 if (!keyguardOn) {
2264 launchAssistLongPressAction();
2265 }
2266 }
2267 } else {
2268 if (mAssistKeyLongPressed) {
2269 mAssistKeyLongPressed = false;
2270 } else {
2271 if (!keyguardOn) {
2272 launchAssistAction();
2273 }
2274 }
2275 }
2276 return -1;
Jeff Sharkey2991fa32012-12-05 18:06:43 -08002277 } else if (keyCode == KeyEvent.KEYCODE_SYSRQ) {
2278 if (down && repeatCount == 0) {
2279 mHandler.post(mScreenshotRunnable);
2280 }
2281 return -1;
Michael Wrightb854e242013-02-05 17:54:02 -08002282 } else if (keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP
2283 || keyCode == KeyEvent.KEYCODE_BRIGHTNESS_DOWN) {
2284 if (down) {
2285 int direction = keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP ? 1 : -1;
2286
2287 // Disable autobrightness if it's on
2288 int auto = Settings.System.getIntForUser(
2289 mContext.getContentResolver(),
2290 Settings.System.SCREEN_BRIGHTNESS_MODE,
2291 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2292 UserHandle.USER_CURRENT_OR_SELF);
2293 if (auto != 0) {
2294 Settings.System.putIntForUser(mContext.getContentResolver(),
2295 Settings.System.SCREEN_BRIGHTNESS_MODE,
2296 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2297 UserHandle.USER_CURRENT_OR_SELF);
2298 }
2299
2300 int min = mPowerManager.getMinimumScreenBrightnessSetting();
2301 int max = mPowerManager.getMaximumScreenBrightnessSetting();
2302 int step = (max - min + BRIGHTNESS_STEPS - 1) / BRIGHTNESS_STEPS * direction;
2303 int brightness = Settings.System.getIntForUser(mContext.getContentResolver(),
2304 Settings.System.SCREEN_BRIGHTNESS,
2305 mPowerManager.getDefaultScreenBrightnessSetting(),
2306 UserHandle.USER_CURRENT_OR_SELF);
2307 brightness += step;
2308 // Make sure we don't go beyond the limits.
2309 brightness = Math.min(max, brightness);
2310 brightness = Math.max(min, brightness);
2311
2312 Settings.System.putIntForUser(mContext.getContentResolver(),
2313 Settings.System.SCREEN_BRIGHTNESS, brightness,
2314 UserHandle.USER_CURRENT_OR_SELF);
2315 Intent intent = new Intent(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG);
2316 mContext.sendBroadcastAsUser(intent, UserHandle.CURRENT_OR_SELF);
2317 }
2318 return -1;
Michael Wright6a62e552014-06-03 19:19:48 -07002319 } else if (keyCode == KeyEvent.KEYCODE_META_LEFT) {
2320 if (down) {
2321 mPendingMetaAction = true;
2322 } else if (mPendingMetaAction) {
2323 mPendingMetaAction = false;
2324 launchAssistAction();
2325 }
2326 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002327 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002328
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002329 // Shortcuts are invoked through Search+key, so intercept those here
Jeff Browncaab4d02010-12-09 22:13:41 -08002330 // Any printing key that is chorded with Search should be consumed
2331 // even if no shortcut was invoked. This prevents text from being
2332 // inadvertently inserted when using a keyboard that has built-in macro
2333 // shortcut keys (that emit Search+x) and some of them are not registered.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002334 if (mSearchKeyShortcutPending) {
Jeff Browncaab4d02010-12-09 22:13:41 -08002335 final KeyCharacterMap kcm = event.getKeyCharacterMap();
2336 if (kcm.isPrintingKey(keyCode)) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002337 mConsumeSearchKeyUp = true;
2338 mSearchKeyShortcutPending = false;
Jeff Browncaab4d02010-12-09 22:13:41 -08002339 if (down && repeatCount == 0 && !keyguardOn) {
2340 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState);
2341 if (shortcutIntent != null) {
2342 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002343 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002344 mContext.startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002345 } catch (ActivityNotFoundException ex) {
2346 Slog.w(TAG, "Dropping shortcut key combination because "
2347 + "the activity to which it is registered was not found: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002348 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode), ex);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002349 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002350 } else {
2351 Slog.i(TAG, "Dropping unregistered shortcut key combination: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002352 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002353 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002354 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002355 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002356 }
2357 }
2358
Jeff Brown68b909d2011-12-07 16:36:01 -08002359 // Invoke shortcuts using Meta.
Jeff Brown602ab322012-05-16 13:33:47 -07002360 if (down && repeatCount == 0 && !keyguardOn
Jeff Brown68b909d2011-12-07 16:36:01 -08002361 && (metaState & KeyEvent.META_META_ON) != 0) {
2362 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brown602ab322012-05-16 13:33:47 -07002363 if (kcm.isPrintingKey(keyCode)) {
2364 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode,
2365 metaState & ~(KeyEvent.META_META_ON
2366 | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON));
2367 if (shortcutIntent != null) {
2368 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2369 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002370 mContext.startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brown602ab322012-05-16 13:33:47 -07002371 } catch (ActivityNotFoundException ex) {
2372 Slog.w(TAG, "Dropping shortcut key combination because "
2373 + "the activity to which it is registered was not found: "
2374 + "META+" + KeyEvent.keyCodeToString(keyCode), ex);
2375 }
2376 return -1;
Jeff Brown68b909d2011-12-07 16:36:01 -08002377 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002378 }
2379 }
2380
Jeff Brown6651a632011-11-28 12:59:11 -08002381 // Handle application launch keys.
Jeff Brown602ab322012-05-16 13:33:47 -07002382 if (down && repeatCount == 0 && !keyguardOn) {
Jeff Brown6651a632011-11-28 12:59:11 -08002383 String category = sApplicationLaunchKeyCategories.get(keyCode);
2384 if (category != null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -08002385 Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category);
Jeff Brown6651a632011-11-28 12:59:11 -08002386 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2387 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002388 mContext.startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brown6651a632011-11-28 12:59:11 -08002389 } catch (ActivityNotFoundException ex) {
2390 Slog.w(TAG, "Dropping application launch key because "
2391 + "the activity to which it is registered was not found: "
2392 + "keyCode=" + keyCode + ", category=" + category, ex);
2393 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002394 return -1;
Jeff Brown6651a632011-11-28 12:59:11 -08002395 }
2396 }
2397
Jeff Brown68b909d2011-12-07 16:36:01 -08002398 // Display task switcher for ALT-TAB or Meta-TAB.
2399 if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_TAB) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002400 if (mRecentAppsHeldModifiers == 0 && !keyguardOn) {
Jeff Brown68b909d2011-12-07 16:36:01 -08002401 final int shiftlessModifiers = event.getModifiers() & ~KeyEvent.META_SHIFT_MASK;
Winson Chungc6011de2014-06-30 18:04:55 -07002402 if (KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_ALT_ON)) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002403 mRecentAppsHeldModifiers = shiftlessModifiers;
2404 showRecentApps(true);
Jeff Brown68b909d2011-12-07 16:36:01 -08002405 return -1;
2406 }
2407 }
Winson Chung1e8d71b2014-05-16 17:05:22 -07002408 } else if (!down && mRecentAppsHeldModifiers != 0
2409 && (metaState & mRecentAppsHeldModifiers) == 0) {
2410 mRecentAppsHeldModifiers = 0;
Winson Chung6cb485f2014-05-19 10:30:43 -07002411 hideRecentApps(true);
Jeff Brown68b909d2011-12-07 16:36:01 -08002412 }
2413
Jeff Browncf39bdf2012-05-18 14:41:19 -07002414 // Handle keyboard language switching.
2415 if (down && repeatCount == 0
2416 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2417 || (keyCode == KeyEvent.KEYCODE_SPACE
2418 && (metaState & KeyEvent.META_CTRL_MASK) != 0))) {
2419 int direction = (metaState & KeyEvent.META_SHIFT_MASK) != 0 ? -1 : 1;
2420 mWindowManagerFuncs.switchKeyboardLayout(event.getDeviceId(), direction);
2421 return -1;
2422 }
2423 if (mLanguageSwitchKeyPressed && !down
2424 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2425 || keyCode == KeyEvent.KEYCODE_SPACE)) {
2426 mLanguageSwitchKeyPressed = false;
2427 return -1;
2428 }
2429
Justin Kohd378ad72013-04-01 12:18:26 -07002430 if (mGlobalKeyManager.handleGlobalKey(mContext, keyCode, event)) {
2431 return -1;
2432 }
2433
Michael Wright6a62e552014-06-03 19:19:48 -07002434 // Reserve all the META modifier combos for system behavior
2435 if ((metaState & KeyEvent.META_META_LEFT_ON) != 0) {
2436 return -1;
2437 }
2438
Jeff Brown68b909d2011-12-07 16:36:01 -08002439 // Let the application handle the key.
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002440 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002441 }
2442
Jeff Brown3915bb82010-11-05 15:02:16 -07002443 /** {@inheritDoc} */
2444 @Override
Jeff Brown49ed71d2010-12-06 17:13:33 -08002445 public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown54875002011-04-06 15:33:01 -07002446 // Note: This method is only called if the initial down was unhandled.
Jeff Brown40013652012-05-16 21:22:36 -07002447 if (DEBUG_INPUT) {
Jeff Brown1f245102010-11-18 20:53:46 -08002448 Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction()
2449 + ", flags=" + event.getFlags()
2450 + ", keyCode=" + event.getKeyCode()
2451 + ", scanCode=" + event.getScanCode()
2452 + ", metaState=" + event.getMetaState()
2453 + ", repeatCount=" + event.getRepeatCount()
2454 + ", policyFlags=" + policyFlags);
Jeff Brown3915bb82010-11-05 15:02:16 -07002455 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002456
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002457 KeyEvent fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002458 if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
2459 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002460 final int keyCode = event.getKeyCode();
2461 final int metaState = event.getMetaState();
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002462 final boolean initialDown = event.getAction() == KeyEvent.ACTION_DOWN
2463 && event.getRepeatCount() == 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002464
Jeff Brown54875002011-04-06 15:33:01 -07002465 // Check for fallback actions specified by the key character map.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002466 final FallbackAction fallbackAction;
2467 if (initialDown) {
2468 fallbackAction = kcm.getFallbackAction(keyCode, metaState);
2469 } else {
2470 fallbackAction = mFallbackActions.get(keyCode);
2471 }
2472
2473 if (fallbackAction != null) {
Jeff Brown40013652012-05-16 21:22:36 -07002474 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002475 Slog.d(TAG, "Fallback: keyCode=" + fallbackAction.keyCode
2476 + " metaState=" + Integer.toHexString(fallbackAction.metaState));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002477 }
2478
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002479 final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK;
2480 fallbackEvent = KeyEvent.obtain(
Jeff Brown49ed71d2010-12-06 17:13:33 -08002481 event.getDownTime(), event.getEventTime(),
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002482 event.getAction(), fallbackAction.keyCode,
2483 event.getRepeatCount(), fallbackAction.metaState,
Jeff Brown49ed71d2010-12-06 17:13:33 -08002484 event.getDeviceId(), event.getScanCode(),
2485 flags, event.getSource(), null);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002486
2487 if (!interceptFallback(win, fallbackEvent, policyFlags)) {
2488 fallbackEvent.recycle();
2489 fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002490 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002491
2492 if (initialDown) {
2493 mFallbackActions.put(keyCode, fallbackAction);
2494 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2495 mFallbackActions.remove(keyCode);
2496 fallbackAction.recycle();
2497 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002498 }
2499 }
2500
Jeff Brown40013652012-05-16 21:22:36 -07002501 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002502 if (fallbackEvent == null) {
2503 Slog.d(TAG, "No fallback.");
2504 } else {
2505 Slog.d(TAG, "Performing fallback: " + fallbackEvent);
2506 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002507 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002508 return fallbackEvent;
Jeff Brown3915bb82010-11-05 15:02:16 -07002509 }
2510
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002511 private boolean interceptFallback(WindowState win, KeyEvent fallbackEvent, int policyFlags) {
Jeff Brown037c33e2014-04-09 00:31:55 -07002512 int actions = interceptKeyBeforeQueueing(fallbackEvent, policyFlags);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002513 if ((actions & ACTION_PASS_TO_USER) != 0) {
2514 long delayMillis = interceptKeyBeforeDispatching(
2515 win, fallbackEvent, policyFlags);
2516 if (delayMillis == 0) {
2517 return true;
2518 }
2519 }
2520 return false;
Jeff Brown6f2fba42011-02-19 01:08:02 -08002521 }
2522
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002523 private void launchAssistLongPressAction() {
2524 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
2525 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
2526
2527 // launch the search activity
2528 Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS);
2529 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2530 try {
RoboErik8a2cfc32014-05-16 11:19:38 -07002531 // TODO: This only stops the factory-installed search manager.
Jim Miller45308b12012-06-18 19:23:39 -07002532 // Need to formalize an API to handle others
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002533 SearchManager searchManager = getSearchManager();
2534 if (searchManager != null) {
2535 searchManager.stopSearch();
2536 }
Michael Wright43e27f72013-04-10 14:06:48 -07002537 mContext.startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002538 } catch (ActivityNotFoundException e) {
2539 Slog.w(TAG, "No activity to handle assist long press action.", e);
2540 }
2541 }
2542
2543 private void launchAssistAction() {
2544 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
Amith Yamasanic1d07a42012-08-14 09:32:02 -07002545 Intent intent = ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE))
Dianne Hackbornf9c5e0f2013-01-23 14:39:13 -08002546 .getAssistIntent(mContext, true, UserHandle.USER_CURRENT);
Jim Miller45308b12012-06-18 19:23:39 -07002547 if (intent != null) {
2548 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
2549 | Intent.FLAG_ACTIVITY_SINGLE_TOP
2550 | Intent.FLAG_ACTIVITY_CLEAR_TOP);
2551 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002552 mContext.startActivityAsUser(intent, UserHandle.CURRENT);
Jim Miller45308b12012-06-18 19:23:39 -07002553 } catch (ActivityNotFoundException e) {
2554 Slog.w(TAG, "No activity to handle assist action.", e);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002555 }
2556 }
2557 }
2558
2559 private SearchManager getSearchManager() {
2560 if (mSearchManager == null) {
2561 mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
2562 }
2563 return mSearchManager;
2564 }
2565
Jeff Browncaca8812013-05-09 13:34:33 -07002566 private void preloadRecentApps() {
2567 mPreloadedRecentApps = true;
2568 try {
2569 IStatusBarService statusbar = getStatusBarService();
2570 if (statusbar != null) {
2571 statusbar.preloadRecentApps();
2572 }
2573 } catch (RemoteException e) {
2574 Slog.e(TAG, "RemoteException when preloading recent apps", e);
2575 // re-acquire status bar service next time it is needed.
2576 mStatusBarService = null;
2577 }
2578 }
2579
2580 private void cancelPreloadRecentApps() {
2581 if (mPreloadedRecentApps) {
2582 mPreloadedRecentApps = false;
2583 try {
2584 IStatusBarService statusbar = getStatusBarService();
2585 if (statusbar != null) {
2586 statusbar.cancelPreloadRecentApps();
2587 }
2588 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002589 Slog.e(TAG, "RemoteException when cancelling recent apps preload", e);
Jeff Browncaca8812013-05-09 13:34:33 -07002590 // re-acquire status bar service next time it is needed.
2591 mStatusBarService = null;
2592 }
2593 }
2594 }
2595
2596 private void toggleRecentApps() {
2597 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
Jeff Browncaca8812013-05-09 13:34:33 -07002598 try {
2599 IStatusBarService statusbar = getStatusBarService();
2600 if (statusbar != null) {
2601 statusbar.toggleRecentApps();
2602 }
2603 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002604 Slog.e(TAG, "RemoteException when toggling recent apps", e);
2605 // re-acquire status bar service next time it is needed.
2606 mStatusBarService = null;
2607 }
2608 }
2609
Craig Mautner84984fa2014-06-19 11:19:20 -07002610 @Override
2611 public void showRecentApps() {
2612 mHandler.removeMessages(MSG_DISPATCH_SHOW_RECENTS);
2613 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_RECENTS);
2614 }
2615
Winson Chung1e8d71b2014-05-16 17:05:22 -07002616 private void showRecentApps(boolean triggeredFromAltTab) {
2617 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
2618 try {
2619 IStatusBarService statusbar = getStatusBarService();
2620 if (statusbar != null) {
2621 statusbar.showRecentApps(triggeredFromAltTab);
2622 }
2623 } catch (RemoteException e) {
Jeff Browncaca8812013-05-09 13:34:33 -07002624 Slog.e(TAG, "RemoteException when showing recent apps", e);
2625 // re-acquire status bar service next time it is needed.
2626 mStatusBarService = null;
2627 }
2628 }
2629
Winson Chung6cb485f2014-05-19 10:30:43 -07002630 private void hideRecentApps(boolean triggeredFromAltTab) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002631 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
2632 try {
2633 IStatusBarService statusbar = getStatusBarService();
2634 if (statusbar != null) {
Winson Chung6cb485f2014-05-19 10:30:43 -07002635 statusbar.hideRecentApps(triggeredFromAltTab);
Winson Chung1e8d71b2014-05-16 17:05:22 -07002636 }
2637 } catch (RemoteException e) {
2638 Slog.e(TAG, "RemoteException when closing recent apps", e);
2639 // re-acquire status bar service next time it is needed.
2640 mStatusBarService = null;
2641 }
2642 }
2643
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002644 /**
2645 * A home key -> launch home action was detected. Take the appropriate action
2646 * given the situation with the keyguard.
2647 */
2648 void launchHomeFromHotKey() {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01002649 if (mKeyguardDelegate != null && mKeyguardDelegate.isShowingAndNotOccluded()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002650 // don't launch home if keyguard showing
Jim Miller5ecd8112013-01-09 18:50:26 -08002651 } else if (!mHideLockScreen && mKeyguardDelegate.isInputRestricted()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002652 // when in keyguard restricted mode, must first verify unlock
2653 // before launching home
Jim Miller5ecd8112013-01-09 18:50:26 -08002654 mKeyguardDelegate.verifyUnlock(new OnKeyguardExitResult() {
Jose Lima9546b202014-07-02 17:21:51 -07002655 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002656 public void onKeyguardExitResult(boolean success) {
2657 if (success) {
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07002658 try {
2659 ActivityManagerNative.getDefault().stopAppSwitches();
2660 } catch (RemoteException e) {
2661 }
Joe Onoratof275f0c2009-11-24 16:11:13 -05002662 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07002663 startDockOrHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002664 }
2665 }
2666 });
2667 } else {
2668 // no keyguard stuff to worry about, just launch home!
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07002669 try {
2670 ActivityManagerNative.getDefault().stopAppSwitches();
2671 } catch (RemoteException e) {
2672 }
Winson Chungd543c1b2014-06-23 15:06:45 -07002673 if (mRecentsVisible) {
2674 // Hide Recents and notify it to launch Home
2675 awakenDreams();
2676 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
2677 hideRecentApps(false);
2678 } else {
2679 // Otherwise, just launch Home
2680 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
2681 startDockOrHome();
2682 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002683 }
2684 }
2685
John Spurlock04db1762013-05-13 12:46:41 -04002686 private final Runnable mClearHideNavigationFlag = new Runnable() {
2687 @Override
2688 public void run() {
2689 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
2690 // Clear flags.
2691 mForceClearedSystemUiFlags &=
2692 ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
2693 }
2694 mWindowManagerFuncs.reevaluateStatusBarVisibility();
Dianne Hackborne26ab702011-10-16 13:21:33 -07002695 }
2696 };
2697
2698 /**
2699 * Input handler used while nav bar is hidden. Captures any touch on the screen,
2700 * to determine when the nav bar should be shown and prevent applications from
2701 * receiving those touches.
2702 */
Jeff Brown32cbc38552011-12-01 14:01:49 -08002703 final class HideNavInputEventReceiver extends InputEventReceiver {
2704 public HideNavInputEventReceiver(InputChannel inputChannel, Looper looper) {
2705 super(inputChannel, looper);
2706 }
2707
Dianne Hackborndf89e652011-10-06 22:35:11 -07002708 @Override
Jeff Brown32cbc38552011-12-01 14:01:49 -08002709 public void onInputEvent(InputEvent event) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07002710 boolean handled = false;
2711 try {
Jeff Brown4952dfd2011-11-30 19:23:22 -08002712 if (event instanceof MotionEvent
2713 && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
2714 final MotionEvent motionEvent = (MotionEvent)event;
2715 if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07002716 // When the user taps down, we re-show the nav bar.
2717 boolean changed = false;
John Spurlock04db1762013-05-13 12:46:41 -04002718 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002719 // Any user activity always causes us to show the
2720 // navigation controls, if they had been hidden.
2721 // We also clear the low profile and only content
2722 // flags so that tapping on the screen will atomically
2723 // restore all currently hidden screen decorations.
2724 int newVal = mResettingSystemUiFlags |
2725 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
2726 View.SYSTEM_UI_FLAG_LOW_PROFILE |
2727 View.SYSTEM_UI_FLAG_FULLSCREEN;
Dianne Hackborne26ab702011-10-16 13:21:33 -07002728 if (mResettingSystemUiFlags != newVal) {
2729 mResettingSystemUiFlags = newVal;
Dianne Hackborndf89e652011-10-06 22:35:11 -07002730 changed = true;
2731 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07002732 // We don't allow the system's nav bar to be hidden
2733 // again for 1 second, to prevent applications from
2734 // spamming us and keeping it from being shown.
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002735 newVal = mForceClearedSystemUiFlags |
2736 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
Dianne Hackborne26ab702011-10-16 13:21:33 -07002737 if (mForceClearedSystemUiFlags != newVal) {
2738 mForceClearedSystemUiFlags = newVal;
2739 changed = true;
John Spurlock04db1762013-05-13 12:46:41 -04002740 mHandler.postDelayed(mClearHideNavigationFlag, 1000);
Dianne Hackborne26ab702011-10-16 13:21:33 -07002741 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07002742 }
2743 if (changed) {
2744 mWindowManagerFuncs.reevaluateStatusBarVisibility();
2745 }
2746 }
2747 }
2748 } finally {
Jeff Brown32cbc38552011-12-01 14:01:49 -08002749 finishInputEvent(event, handled);
Dianne Hackborndf89e652011-10-06 22:35:11 -07002750 }
2751 }
Jeff Brown32cbc38552011-12-01 14:01:49 -08002752 }
2753 final InputEventReceiver.Factory mHideNavInputEventReceiverFactory =
2754 new InputEventReceiver.Factory() {
2755 @Override
2756 public InputEventReceiver createInputEventReceiver(
2757 InputChannel inputChannel, Looper looper) {
2758 return new HideNavInputEventReceiver(inputChannel, looper);
2759 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07002760 };
2761
2762 @Override
2763 public int adjustSystemUiVisibilityLw(int visibility) {
John Spurlock5b9145b2013-08-20 15:13:47 -04002764 mStatusBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
2765 mNavigationBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
Winson Chungd42a6cf2014-06-03 16:24:04 -07002766 mRecentsVisible = (visibility & View.RECENT_APPS_VISIBLE) > 0;
John Spurlock27735a42013-08-14 17:57:38 -04002767
Dianne Hackborndf89e652011-10-06 22:35:11 -07002768 // Reset any bits in mForceClearingStatusBarVisibility that
2769 // are now clear.
Dianne Hackborne26ab702011-10-16 13:21:33 -07002770 mResettingSystemUiFlags &= visibility;
Dianne Hackborndf89e652011-10-06 22:35:11 -07002771 // Clear any bits in the new visibility that are currently being
2772 // force cleared, before reporting it.
Dianne Hackborne26ab702011-10-16 13:21:33 -07002773 return visibility & ~mResettingSystemUiFlags
2774 & ~mForceClearedSystemUiFlags;
Dianne Hackborndf89e652011-10-06 22:35:11 -07002775 }
2776
Craig Mautner69b08182012-09-05 13:07:13 -07002777 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002778 public void getContentInsetHintLw(WindowManager.LayoutParams attrs, Rect contentInset) {
John Spurlockc6d1c602014-01-17 15:22:06 -05002779 final int fl = PolicyControl.getWindowFlags(null, attrs);
John Spurlock1db8b682014-02-18 11:18:59 -05002780 final int sysuiVis = PolicyControl.getSystemUiVisibility(null, attrs);
2781 final int systemUiVisibility = (sysuiVis | attrs.subtreeSystemUiVisibility);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002782
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002783 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002784 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002785 int availRight, availBottom;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07002786 if (canHideNavigationBar() &&
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002787 (systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002788 availRight = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
2789 availBottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
2790 } else {
2791 availRight = mRestrictedScreenLeft + mRestrictedScreenWidth;
2792 availBottom = mRestrictedScreenTop + mRestrictedScreenHeight;
2793 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002794 if ((systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
2795 if ((fl & FLAG_FULLSCREEN) != 0) {
2796 contentInset.set(mStableFullscreenLeft, mStableFullscreenTop,
2797 availRight - mStableFullscreenRight,
2798 availBottom - mStableFullscreenBottom);
2799 } else {
2800 contentInset.set(mStableLeft, mStableTop,
2801 availRight - mStableRight, availBottom - mStableBottom);
2802 }
Dianne Hackbornc652de82013-02-15 16:32:56 -08002803 } else if ((fl & FLAG_FULLSCREEN) != 0 || (fl & FLAG_LAYOUT_IN_OVERSCAN) != 0) {
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002804 contentInset.setEmpty();
2805 } else if ((systemUiVisibility & (View.SYSTEM_UI_FLAG_FULLSCREEN
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002806 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)) == 0) {
2807 contentInset.set(mCurLeft, mCurTop,
2808 availRight - mCurRight, availBottom - mCurBottom);
2809 } else {
2810 contentInset.set(mCurLeft, mCurTop,
2811 availRight - mCurRight, availBottom - mCurBottom);
2812 }
2813 return;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002814 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002815 contentInset.setEmpty();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002816 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002817
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002818 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07002819 @Override
2820 public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight,
2821 int displayRotation) {
Dianne Hackbornc652de82013-02-15 16:32:56 -08002822 final int overscanLeft, overscanTop, overscanRight, overscanBottom;
2823 if (isDefaultDisplay) {
2824 switch (displayRotation) {
2825 case Surface.ROTATION_90:
2826 overscanLeft = mOverscanTop;
2827 overscanTop = mOverscanRight;
2828 overscanRight = mOverscanBottom;
2829 overscanBottom = mOverscanLeft;
2830 break;
2831 case Surface.ROTATION_180:
2832 overscanLeft = mOverscanRight;
2833 overscanTop = mOverscanBottom;
2834 overscanRight = mOverscanLeft;
2835 overscanBottom = mOverscanTop;
2836 break;
2837 case Surface.ROTATION_270:
2838 overscanLeft = mOverscanBottom;
2839 overscanTop = mOverscanLeft;
2840 overscanRight = mOverscanTop;
2841 overscanBottom = mOverscanRight;
2842 break;
2843 default:
2844 overscanLeft = mOverscanLeft;
2845 overscanTop = mOverscanTop;
2846 overscanRight = mOverscanRight;
2847 overscanBottom = mOverscanBottom;
2848 break;
2849 }
2850 } else {
2851 overscanLeft = 0;
2852 overscanTop = 0;
2853 overscanRight = 0;
2854 overscanBottom = 0;
2855 }
Dianne Hackborn313440842013-02-19 19:22:59 -08002856 mOverscanScreenLeft = mRestrictedOverscanScreenLeft = 0;
2857 mOverscanScreenTop = mRestrictedOverscanScreenTop = 0;
2858 mOverscanScreenWidth = mRestrictedOverscanScreenWidth = displayWidth;
2859 mOverscanScreenHeight = mRestrictedOverscanScreenHeight = displayHeight;
Dianne Hackbornc652de82013-02-15 16:32:56 -08002860 mSystemLeft = 0;
2861 mSystemTop = 0;
2862 mSystemRight = displayWidth;
2863 mSystemBottom = displayHeight;
2864 mUnrestrictedScreenLeft = overscanLeft;
2865 mUnrestrictedScreenTop = overscanTop;
2866 mUnrestrictedScreenWidth = displayWidth - overscanLeft - overscanRight;
2867 mUnrestrictedScreenHeight = displayHeight - overscanTop - overscanBottom;
2868 mRestrictedScreenLeft = mUnrestrictedScreenLeft;
2869 mRestrictedScreenTop = mUnrestrictedScreenTop;
John Spurlockad3e6cb2013-04-30 08:47:43 -04002870 mRestrictedScreenWidth = mSystemGestures.screenWidth = mUnrestrictedScreenWidth;
2871 mRestrictedScreenHeight = mSystemGestures.screenHeight = mUnrestrictedScreenHeight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002872 mDockLeft = mContentLeft = mVoiceContentLeft = mStableLeft = mStableFullscreenLeft
Dianne Hackbornc652de82013-02-15 16:32:56 -08002873 = mCurLeft = mUnrestrictedScreenLeft;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002874 mDockTop = mContentTop = mVoiceContentTop = mStableTop = mStableFullscreenTop
Dianne Hackbornc652de82013-02-15 16:32:56 -08002875 = mCurTop = mUnrestrictedScreenTop;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002876 mDockRight = mContentRight = mVoiceContentRight = mStableRight = mStableFullscreenRight
Dianne Hackbornc652de82013-02-15 16:32:56 -08002877 = mCurRight = displayWidth - overscanRight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002878 mDockBottom = mContentBottom = mVoiceContentBottom = mStableBottom = mStableFullscreenBottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08002879 = mCurBottom = displayHeight - overscanBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002880 mDockLayer = 0x10000000;
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002881 mStatusBarLayer = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002882
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002883 // start with the current dock rect, which will be (0,0,displayWidth,displayHeight)
2884 final Rect pf = mTmpParentFrame;
2885 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002886 final Rect of = mTmpOverscanFrame;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002887 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04002888 final Rect dcf = mTmpDecorFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002889 pf.left = df.left = of.left = vf.left = mDockLeft;
2890 pf.top = df.top = of.top = vf.top = mDockTop;
2891 pf.right = df.right = of.right = vf.right = mDockRight;
2892 pf.bottom = df.bottom = of.bottom = vf.bottom = mDockBottom;
John Spurlock46646232013-09-30 22:32:42 -04002893 dcf.setEmpty(); // Decor frame N/A for system bars.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002894
Craig Mautner69b08182012-09-05 13:07:13 -07002895 if (isDefaultDisplay) {
2896 // For purposes of putting out fake window up to steal focus, we will
2897 // drive nav being hidden only by whether it is requested.
John Spurlocke1f366f2013-08-05 12:22:40 -04002898 final int sysui = mLastSystemUiFlags;
2899 boolean navVisible = (sysui & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0;
Adrian Roosea562512014-05-05 13:33:03 +02002900 boolean navTranslucent = (sysui
2901 & (View.NAVIGATION_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04002902 boolean immersive = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
2903 boolean immersiveSticky = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
2904 boolean navAllowedHidden = immersive || immersiveSticky;
2905 navTranslucent &= !immersiveSticky; // transient trumps translucent
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04002906 navTranslucent &= areTranslucentBarsAllowed();
Dianne Hackborne26ab702011-10-16 13:21:33 -07002907
Craig Mautner69b08182012-09-05 13:07:13 -07002908 // When the navigation bar isn't visible, we put up a fake
2909 // input window to catch all touch events. This way we can
2910 // detect when the user presses anywhere to bring back the nav
2911 // bar and ensure the application doesn't see the event.
John Spurlockf1a36642013-10-12 17:50:42 -04002912 if (navVisible || navAllowedHidden) {
Craig Mautner69b08182012-09-05 13:07:13 -07002913 if (mHideNavFakeWindow != null) {
2914 mHideNavFakeWindow.dismiss();
2915 mHideNavFakeWindow = null;
2916 }
2917 } else if (mHideNavFakeWindow == null) {
2918 mHideNavFakeWindow = mWindowManagerFuncs.addFakeWindow(
2919 mHandler.getLooper(), mHideNavInputEventReceiverFactory,
Adam Lesinski95c42972013-10-02 10:13:27 -07002920 "hidden nav", WindowManager.LayoutParams.TYPE_HIDDEN_NAV_CONSUMER, 0,
Craig Mautner69b08182012-09-05 13:07:13 -07002921 0, false, false, true);
Dianne Hackborne26ab702011-10-16 13:21:33 -07002922 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07002923
Craig Mautner69b08182012-09-05 13:07:13 -07002924 // For purposes of positioning and showing the nav bar, if we have
2925 // decided that it can't be hidden (because of the screen aspect ratio),
2926 // then take that into account.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07002927 navVisible |= !canHideNavigationBar();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002928
John Spurlockad3e6cb2013-04-30 08:47:43 -04002929 boolean updateSysUiVisibility = false;
Craig Mautner69b08182012-09-05 13:07:13 -07002930 if (mNavigationBar != null) {
John Spurlock27735a42013-08-14 17:57:38 -04002931 boolean transientNavBarShowing = mNavigationBarController.isTransientShowing();
Craig Mautner69b08182012-09-05 13:07:13 -07002932 // Force the navigation bar to its appropriate place and
2933 // size. We need to do this directly, instead of relying on
2934 // it to bubble up from the nav bar, because this needs to
2935 // change atomically with screen rotations.
2936 mNavigationBarOnBottom = (!mNavigationBarCanMove || displayWidth < displayHeight);
2937 if (mNavigationBarOnBottom) {
2938 // It's a system nav bar or a portrait screen; nav bar goes on bottom.
Dianne Hackbornc652de82013-02-15 16:32:56 -08002939 int top = displayHeight - overscanBottom
2940 - mNavigationBarHeightForRotation[displayRotation];
2941 mTmpNavigationFrame.set(0, top, displayWidth, displayHeight - overscanBottom);
Craig Mautner69b08182012-09-05 13:07:13 -07002942 mStableBottom = mStableFullscreenBottom = mTmpNavigationFrame.top;
John Spurlockf95b89a2013-10-10 22:10:42 -04002943 if (transientNavBarShowing) {
John Spurlock27735a42013-08-14 17:57:38 -04002944 mNavigationBarController.setBarShowingLw(true);
John Spurlockad3e6cb2013-04-30 08:47:43 -04002945 } else if (navVisible) {
John Spurlock27735a42013-08-14 17:57:38 -04002946 mNavigationBarController.setBarShowingLw(true);
Craig Mautner69b08182012-09-05 13:07:13 -07002947 mDockBottom = mTmpNavigationFrame.top;
Dianne Hackborn313440842013-02-19 19:22:59 -08002948 mRestrictedScreenHeight = mDockBottom - mRestrictedScreenTop;
2949 mRestrictedOverscanScreenHeight = mDockBottom - mRestrictedOverscanScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07002950 } else {
2951 // We currently want to hide the navigation UI.
John Spurlock27735a42013-08-14 17:57:38 -04002952 mNavigationBarController.setBarShowingLw(false);
Craig Mautner69b08182012-09-05 13:07:13 -07002953 }
John Spurlockc6d1c602014-01-17 15:22:06 -05002954 if (navVisible && !navTranslucent && !navAllowedHidden
2955 && !mNavigationBar.isAnimatingLw()
John Spurlockbd957402013-10-03 11:38:39 -04002956 && !mNavigationBarController.wasRecentlyTranslucent()) {
John Spurlocke1f366f2013-08-05 12:22:40 -04002957 // If the opaque nav bar is currently requested to be visible,
Craig Mautner69b08182012-09-05 13:07:13 -07002958 // and not in the process of animating on or off, then
2959 // we can tell the app that it is covered by it.
2960 mSystemBottom = mTmpNavigationFrame.top;
2961 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002962 } else {
Craig Mautner69b08182012-09-05 13:07:13 -07002963 // Landscape screen; nav bar goes to the right.
Dianne Hackbornc652de82013-02-15 16:32:56 -08002964 int left = displayWidth - overscanRight
2965 - mNavigationBarWidthForRotation[displayRotation];
2966 mTmpNavigationFrame.set(left, 0, displayWidth - overscanRight, displayHeight);
Craig Mautner69b08182012-09-05 13:07:13 -07002967 mStableRight = mStableFullscreenRight = mTmpNavigationFrame.left;
John Spurlockf95b89a2013-10-10 22:10:42 -04002968 if (transientNavBarShowing) {
John Spurlock27735a42013-08-14 17:57:38 -04002969 mNavigationBarController.setBarShowingLw(true);
John Spurlockad3e6cb2013-04-30 08:47:43 -04002970 } else if (navVisible) {
John Spurlock27735a42013-08-14 17:57:38 -04002971 mNavigationBarController.setBarShowingLw(true);
Craig Mautner69b08182012-09-05 13:07:13 -07002972 mDockRight = mTmpNavigationFrame.left;
Dianne Hackborn313440842013-02-19 19:22:59 -08002973 mRestrictedScreenWidth = mDockRight - mRestrictedScreenLeft;
2974 mRestrictedOverscanScreenWidth = mDockRight - mRestrictedOverscanScreenLeft;
Craig Mautner69b08182012-09-05 13:07:13 -07002975 } else {
2976 // We currently want to hide the navigation UI.
John Spurlock27735a42013-08-14 17:57:38 -04002977 mNavigationBarController.setBarShowingLw(false);
Craig Mautner69b08182012-09-05 13:07:13 -07002978 }
John Spurlockbd957402013-10-03 11:38:39 -04002979 if (navVisible && !navTranslucent && !mNavigationBar.isAnimatingLw()
2980 && !mNavigationBarController.wasRecentlyTranslucent()) {
Craig Mautner69b08182012-09-05 13:07:13 -07002981 // If the nav bar is currently requested to be visible,
2982 // and not in the process of animating on or off, then
2983 // we can tell the app that it is covered by it.
2984 mSystemRight = mTmpNavigationFrame.left;
2985 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002986 }
Craig Mautner69b08182012-09-05 13:07:13 -07002987 // Make sure the content and current rectangles are updated to
2988 // account for the restrictions from the navigation bar.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002989 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
2990 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
2991 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
2992 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
Craig Mautner69b08182012-09-05 13:07:13 -07002993 mStatusBarLayer = mNavigationBar.getSurfaceLayer();
2994 // And compute the final frame.
2995 mNavigationBar.computeFrameLw(mTmpNavigationFrame, mTmpNavigationFrame,
Adrian Roosfa104232014-06-20 16:10:14 -07002996 mTmpNavigationFrame, mTmpNavigationFrame, mTmpNavigationFrame, dcf,
2997 mTmpNavigationFrame);
Craig Mautnereda67292013-04-28 13:50:14 -07002998 if (DEBUG_LAYOUT) Slog.i(TAG, "mNavigationBar frame: " + mTmpNavigationFrame);
John Spurlock27735a42013-08-14 17:57:38 -04002999 if (mNavigationBarController.checkHiddenLw()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04003000 updateSysUiVisibility = true;
3001 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003002 }
Craig Mautnereda67292013-04-28 13:50:14 -07003003 if (DEBUG_LAYOUT) Slog.i(TAG, String.format("mDock rect: (%d,%d - %d,%d)",
Craig Mautner69b08182012-09-05 13:07:13 -07003004 mDockLeft, mDockTop, mDockRight, mDockBottom));
3005
3006 // decide where the status bar goes ahead of time
3007 if (mStatusBar != null) {
3008 // apply any navigation bar insets
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003009 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3010 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3011 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
3012 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight
3013 + mUnrestrictedScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07003014 vf.left = mStableLeft;
3015 vf.top = mStableTop;
3016 vf.right = mStableRight;
3017 vf.bottom = mStableBottom;
3018
3019 mStatusBarLayer = mStatusBar.getSurfaceLayer();
3020
3021 // Let the status bar determine its size.
Adrian Roosfa104232014-06-20 16:10:14 -07003022 mStatusBar.computeFrameLw(pf, df, vf, vf, vf, dcf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07003023
3024 // For layout, the status bar is always at the top with our fixed height.
3025 mStableTop = mUnrestrictedScreenTop + mStatusBarHeight;
3026
John Spurlocke1f366f2013-08-05 12:22:40 -04003027 boolean statusBarTransient = (sysui & View.STATUS_BAR_TRANSIENT) != 0;
Adrian Roosea562512014-05-05 13:33:03 +02003028 boolean statusBarTranslucent = (sysui
3029 & (View.STATUS_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0;
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04003030 statusBarTranslucent &= areTranslucentBarsAllowed();
John Spurlock32beb2c2013-03-11 10:16:47 -04003031
Craig Mautner69b08182012-09-05 13:07:13 -07003032 // If the status bar is hidden, we don't want to cause
3033 // windows behind it to scroll.
John Spurlockeda1f692013-09-16 11:38:44 -04003034 if (mStatusBar.isVisibleLw() && !statusBarTransient) {
Craig Mautner69b08182012-09-05 13:07:13 -07003035 // Status bar may go away, so the screen area it occupies
3036 // is available to apps but just covering them when the
3037 // status bar is visible.
3038 mDockTop = mUnrestrictedScreenTop + mStatusBarHeight;
3039
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003040 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3041 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3042 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3043 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
Craig Mautner69b08182012-09-05 13:07:13 -07003044
Craig Mautnereda67292013-04-28 13:50:14 -07003045 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar: " +
Craig Mautner69b08182012-09-05 13:07:13 -07003046 String.format(
3047 "dock=[%d,%d][%d,%d] content=[%d,%d][%d,%d] cur=[%d,%d][%d,%d]",
3048 mDockLeft, mDockTop, mDockRight, mDockBottom,
3049 mContentLeft, mContentTop, mContentRight, mContentBottom,
3050 mCurLeft, mCurTop, mCurRight, mCurBottom));
3051 }
John Spurlocke1f366f2013-08-05 12:22:40 -04003052 if (mStatusBar.isVisibleLw() && !mStatusBar.isAnimatingLw()
John Spurlockbd957402013-10-03 11:38:39 -04003053 && !statusBarTransient && !statusBarTranslucent
3054 && !mStatusBarController.wasRecentlyTranslucent()) {
John Spurlocke1f366f2013-08-05 12:22:40 -04003055 // If the opaque status bar is currently requested to be visible,
Craig Mautner69b08182012-09-05 13:07:13 -07003056 // and not in the process of animating on or off, then
3057 // we can tell the app that it is covered by it.
3058 mSystemTop = mUnrestrictedScreenTop + mStatusBarHeight;
3059 }
John Spurlock27735a42013-08-14 17:57:38 -04003060 if (mStatusBarController.checkHiddenLw()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04003061 updateSysUiVisibility = true;
John Spurlock32beb2c2013-03-11 10:16:47 -04003062 }
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003063 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04003064 if (updateSysUiVisibility) {
3065 updateSystemUiVisibilityLw();
3066 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003067 }
3068 }
3069
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003070 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07003071 @Override
John Spurlock46646232013-09-30 22:32:42 -04003072 public int getSystemDecorLayerLw() {
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003073 if (mStatusBar != null) return mStatusBar.getSurfaceLayer();
3074 if (mNavigationBar != null) return mNavigationBar.getSurfaceLayer();
3075 return 0;
3076 }
3077
Craig Mautner967212c2013-04-13 21:10:58 -07003078 @Override
3079 public void getContentRectLw(Rect r) {
3080 r.set(mContentLeft, mContentTop, mContentRight, mContentBottom);
3081 }
3082
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003083 void setAttachedWindowFrames(WindowState win, int fl, int adjust, WindowState attached,
3084 boolean insetDecors, Rect pf, Rect df, Rect of, Rect cf, Rect vf) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003085 if (win.getSurfaceLayer() > mDockLayer && attached.getSurfaceLayer() < mDockLayer) {
3086 // Here's a special case: if this attached window is a panel that is
3087 // above the dock window, and the window it is attached to is below
3088 // the dock window, then the frames we computed for the window it is
3089 // attached to can not be used because the dock is effectively part
3090 // of the underlying window and the attached window is floating on top
3091 // of the whole thing. So, we ignore the attached window and explicitly
3092 // compute the frames that would be appropriate without the dock.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003093 df.left = of.left = cf.left = vf.left = mDockLeft;
3094 df.top = of.top = cf.top = vf.top = mDockTop;
3095 df.right = of.right = cf.right = vf.right = mDockRight;
3096 df.bottom = of.bottom = cf.bottom = vf.bottom = mDockBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003097 } else {
3098 // The effective display frame of the attached window depends on
3099 // whether it is taking care of insetting its content. If not,
3100 // we need to use the parent's content frame so that the entire
3101 // window is positioned within that content. Otherwise we can use
3102 // the display frame and let the attached window take care of
3103 // positioning its content appropriately.
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003104 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003105 cf.set(attached.getOverscanFrameLw());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003106 } else {
3107 // If the window is resizing, then we want to base the content
3108 // frame on our attached content frame to resize... however,
3109 // things can be tricky if the attached window is NOT in resize
3110 // mode, in which case its content frame will be larger.
3111 // Ungh. So to deal with that, make sure the content frame
3112 // we end up using is not covering the IM dock.
3113 cf.set(attached.getContentFrameLw());
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003114 if (attached.isVoiceInteraction()) {
3115 if (cf.left < mVoiceContentLeft) cf.left = mVoiceContentLeft;
3116 if (cf.top < mVoiceContentTop) cf.top = mVoiceContentTop;
3117 if (cf.right > mVoiceContentRight) cf.right = mVoiceContentRight;
3118 if (cf.bottom > mVoiceContentBottom) cf.bottom = mVoiceContentBottom;
3119 } else if (attached.getSurfaceLayer() < mDockLayer) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003120 if (cf.left < mContentLeft) cf.left = mContentLeft;
3121 if (cf.top < mContentTop) cf.top = mContentTop;
3122 if (cf.right > mContentRight) cf.right = mContentRight;
3123 if (cf.bottom > mContentBottom) cf.bottom = mContentBottom;
3124 }
3125 }
3126 df.set(insetDecors ? attached.getDisplayFrameLw() : cf);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003127 of.set(insetDecors ? attached.getOverscanFrameLw() : cf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003128 vf.set(attached.getVisibleFrameLw());
3129 }
3130 // The LAYOUT_IN_SCREEN flag is used to determine whether the attached
3131 // window should be positioned relative to its parent or the entire
3132 // screen.
3133 pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0
3134 ? attached.getFrameLw() : df);
3135 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003136
3137 private void applyStableConstraints(int sysui, int fl, Rect r) {
3138 if ((sysui & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
3139 // If app is requesting a stable layout, don't let the
3140 // content insets go below the stable values.
3141 if ((fl & FLAG_FULLSCREEN) != 0) {
3142 if (r.left < mStableFullscreenLeft) r.left = mStableFullscreenLeft;
3143 if (r.top < mStableFullscreenTop) r.top = mStableFullscreenTop;
3144 if (r.right > mStableFullscreenRight) r.right = mStableFullscreenRight;
3145 if (r.bottom > mStableFullscreenBottom) r.bottom = mStableFullscreenBottom;
3146 } else {
3147 if (r.left < mStableLeft) r.left = mStableLeft;
3148 if (r.top < mStableTop) r.top = mStableTop;
3149 if (r.right > mStableRight) r.right = mStableRight;
3150 if (r.bottom > mStableBottom) r.bottom = mStableBottom;
3151 }
3152 }
3153 }
3154
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003155 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07003156 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003157 public void layoutWindowLw(WindowState win, WindowState attached) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003158 // we've already done the status bar
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003159 final WindowManager.LayoutParams attrs = win.getAttrs();
3160 if ((win == mStatusBar && (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) == 0) ||
3161 win == mNavigationBar) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003162 return;
3163 }
Craig Mautner69b08182012-09-05 13:07:13 -07003164 final boolean isDefaultDisplay = win.isDefaultDisplay();
3165 final boolean needsToOffsetInputMethodTarget = isDefaultDisplay &&
satok1bc0a492012-04-25 22:47:12 +09003166 (win == mLastInputMethodTargetWindow && mLastInputMethodWindow != null);
3167 if (needsToOffsetInputMethodTarget) {
Craig Mautnereda67292013-04-28 13:50:14 -07003168 if (DEBUG_LAYOUT) Slog.i(TAG, "Offset ime target window by the last ime window state");
satok1bc0a492012-04-25 22:47:12 +09003169 offsetInputMethodWindowLw(mLastInputMethodWindow);
3170 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003171
John Spurlockc6d1c602014-01-17 15:22:06 -05003172 final int fl = PolicyControl.getWindowFlags(win, attrs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003173 final int sim = attrs.softInputMode;
John Spurlock1db8b682014-02-18 11:18:59 -05003174 final int sysUiFl = PolicyControl.getSystemUiVisibility(win, null);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003175
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003176 final Rect pf = mTmpParentFrame;
3177 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003178 final Rect of = mTmpOverscanFrame;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003179 final Rect cf = mTmpContentFrame;
3180 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04003181 final Rect dcf = mTmpDecorFrame;
Adrian Roosfa104232014-06-20 16:10:14 -07003182 final Rect sf = mTmpStableFrame;
John Spurlock46646232013-09-30 22:32:42 -04003183 dcf.setEmpty();
Craig Mautner69b08182012-09-05 13:07:13 -07003184
3185 final boolean hasNavBar = (isDefaultDisplay && mHasNavigationBar
Daniel Sandler36412a72011-08-04 09:35:13 -04003186 && mNavigationBar != null && mNavigationBar.isVisibleLw());
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003187
Craig Mautnerf683b562012-10-02 11:10:57 -07003188 final int adjust = sim & SOFT_INPUT_MASK_ADJUST;
3189
Adrian Roosfa104232014-06-20 16:10:14 -07003190 if (isDefaultDisplay) {
3191 sf.set(mStableLeft, mStableTop, mStableRight, mStableBottom);
3192 } else {
3193 sf.set(mOverscanLeft, mOverscanTop, mOverscanRight, mOverscanBottom);
3194 }
3195
Craig Mautner69b08182012-09-05 13:07:13 -07003196 if (!isDefaultDisplay) {
3197 if (attached != null) {
3198 // If this window is attached to another, our display
3199 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003200 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07003201 } else {
3202 // Give the window full screen.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003203 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3204 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3205 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08003206 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003207 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003208 = mOverscanScreenTop + mOverscanScreenHeight;
Craig Mautner69b08182012-09-05 13:07:13 -07003209 }
3210 } else if (attrs.type == TYPE_INPUT_METHOD) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003211 pf.left = df.left = of.left = cf.left = vf.left = mDockLeft;
3212 pf.top = df.top = of.top = cf.top = vf.top = mDockTop;
3213 pf.right = df.right = of.right = cf.right = vf.right = mDockRight;
John Spurlockc68d5772013-10-08 11:47:58 -04003214 // IM dock windows layout below the nav bar...
John Spurlock57beb3b2013-10-10 10:27:44 -04003215 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlockc68d5772013-10-08 11:47:58 -04003216 // ...with content insets above the nav bar
3217 cf.bottom = vf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003218 // IM dock windows always go to the bottom of the screen.
3219 attrs.gravity = Gravity.BOTTOM;
3220 mDockLayer = win.getSurfaceLayer();
3221 } else {
John Spurlock46646232013-09-30 22:32:42 -04003222
3223 // Default policy decor for the default display
3224 dcf.left = mSystemLeft;
3225 dcf.top = mSystemTop;
3226 dcf.right = mSystemRight;
3227 dcf.bottom = mSystemBottom;
John Spurlockbd957402013-10-03 11:38:39 -04003228 final boolean inheritTranslucentDecor = (attrs.privateFlags
3229 & WindowManager.LayoutParams.PRIVATE_FLAG_INHERIT_TRANSLUCENT_DECOR) != 0;
John Spurlock65567d42013-10-08 10:08:32 -04003230 final boolean isAppWindow =
3231 attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW &&
3232 attrs.type <= WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
3233 final boolean topAtRest =
3234 win == mTopFullscreenOpaqueWindowState && !win.isAnimatingLw();
3235 if (isAppWindow && !inheritTranslucentDecor && !topAtRest) {
John Spurlockbd957402013-10-03 11:38:39 -04003236 if ((sysUiFl & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0
3237 && (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0
Adrian Roosea562512014-05-05 13:33:03 +02003238 && (fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) == 0
3239 && (fl & WindowManager.LayoutParams.
3240 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04003241 // Ensure policy decor includes status bar
3242 dcf.top = mStableTop;
3243 }
John Spurlockbd957402013-10-03 11:38:39 -04003244 if ((fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) == 0
Adrian Roosea562512014-05-05 13:33:03 +02003245 && (sysUiFl & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0
3246 && (fl & WindowManager.LayoutParams.
3247 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04003248 // Ensure policy decor includes navigation bar
3249 dcf.bottom = mStableBottom;
3250 dcf.right = mStableRight;
3251 }
3252 }
3253
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003254 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
3255 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
RoboErik8a2cfc32014-05-16 11:19:38 -07003256 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003257 + "): IN_SCREEN, INSET_DECOR");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003258 // This is the case for a normal activity window: we want it
3259 // to cover all of the screen space, and it can take care of
3260 // moving its contents to account for screen decorations that
3261 // intrude into that space.
3262 if (attached != null) {
3263 // If this window is attached to another, our display
3264 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003265 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003266 } else {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003267 if (attrs.type == TYPE_STATUS_BAR_PANEL
3268 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Joe Onorato29fc2c92010-11-24 10:26:50 -08003269 // Status bar panels are the only windows who can go on top of
3270 // the status bar. They are protected by the STATUS_BAR_SERVICE
3271 // permission, so they have the same privileges as the status
3272 // bar itself.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003273 //
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003274 // However, they should still dodge the navigation bar if it exists.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003275
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003276 pf.left = df.left = of.left = hasNavBar
3277 ? mDockLeft : mUnrestrictedScreenLeft;
3278 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3279 pf.right = df.right = of.right = hasNavBar
3280 ? mRestrictedScreenLeft+mRestrictedScreenWidth
3281 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3282 pf.bottom = df.bottom = of.bottom = hasNavBar
3283 ? mRestrictedScreenTop+mRestrictedScreenHeight
3284 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003285
Craig Mautnereda67292013-04-28 13:50:14 -07003286 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003287 "Laying out status bar window: (%d,%d - %d,%d)",
3288 pf.left, pf.top, pf.right, pf.bottom));
John Spurlock46646232013-09-30 22:32:42 -04003289 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08003290 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3291 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3292 // Asking to layout into the overscan region, so give it that pure
3293 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003294 pf.left = df.left = of.left = mOverscanScreenLeft;
3295 pf.top = df.top = of.top = mOverscanScreenTop;
3296 pf.right = df.right = of.right = mOverscanScreenLeft + mOverscanScreenWidth;
3297 pf.bottom = df.bottom = of.bottom = mOverscanScreenTop
3298 + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003299 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003300 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003301 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3302 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003303 // Asking for layout as if the nav bar is hidden, lets the
Dianne Hackbornc652de82013-02-15 16:32:56 -08003304 // application extend into the unrestricted overscan screen area. We
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003305 // only do this for application windows to ensure no window that
3306 // can be above the nav bar can do this.
Dianne Hackborn313440842013-02-19 19:22:59 -08003307 pf.left = df.left = mOverscanScreenLeft;
3308 pf.top = df.top = mOverscanScreenTop;
3309 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
3310 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003311 // We need to tell the app about where the frame inside the overscan
3312 // is, so it can inset its content by that amount -- it didn't ask
3313 // to actually extend itself into the overscan region.
3314 of.left = mUnrestrictedScreenLeft;
3315 of.top = mUnrestrictedScreenTop;
3316 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3317 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003318 } else {
Dianne Hackborn313440842013-02-19 19:22:59 -08003319 pf.left = df.left = mRestrictedOverscanScreenLeft;
3320 pf.top = df.top = mRestrictedOverscanScreenTop;
3321 pf.right = df.right = mRestrictedOverscanScreenLeft
3322 + mRestrictedOverscanScreenWidth;
3323 pf.bottom = df.bottom = mRestrictedOverscanScreenTop
3324 + mRestrictedOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003325 // We need to tell the app about where the frame inside the overscan
3326 // is, so it can inset its content by that amount -- it didn't ask
3327 // to actually extend itself into the overscan region.
3328 of.left = mUnrestrictedScreenLeft;
3329 of.top = mUnrestrictedScreenTop;
3330 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3331 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003332 }
Craig Mautner69b08182012-09-05 13:07:13 -07003333
John Spurlock46646232013-09-30 22:32:42 -04003334 if ((fl & FLAG_FULLSCREEN) == 0) {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003335 if (win.isVoiceInteraction()) {
3336 cf.left = mVoiceContentLeft;
3337 cf.top = mVoiceContentTop;
3338 cf.right = mVoiceContentRight;
3339 cf.bottom = mVoiceContentBottom;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003340 } else {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003341 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
3342 cf.left = mDockLeft;
3343 cf.top = mDockTop;
3344 cf.right = mDockRight;
3345 cf.bottom = mDockBottom;
3346 } else {
3347 cf.left = mContentLeft;
3348 cf.top = mContentTop;
3349 cf.right = mContentRight;
3350 cf.bottom = mContentBottom;
3351 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003352 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003353 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003354 // Full screen windows are always given a layout that is as if the
3355 // status bar and other transient decors are gone. This is to avoid
3356 // bad states when moving from a window that is not hding the
3357 // status bar to one that is.
3358 cf.left = mRestrictedScreenLeft;
3359 cf.top = mRestrictedScreenTop;
3360 cf.right = mRestrictedScreenLeft + mRestrictedScreenWidth;
3361 cf.bottom = mRestrictedScreenTop + mRestrictedScreenHeight;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003362 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003363 applyStableConstraints(sysUiFl, fl, cf);
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003364 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3365 vf.left = mCurLeft;
3366 vf.top = mCurTop;
3367 vf.right = mCurRight;
3368 vf.bottom = mCurBottom;
3369 } else {
3370 vf.set(cf);
3371 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003372 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003373 } else if ((fl & FLAG_LAYOUT_IN_SCREEN) != 0 || (sysUiFl
3374 & (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
3375 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)) != 0) {
Craig Mautnereda67292013-04-28 13:50:14 -07003376 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3377 "): IN_SCREEN");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003378 // A window that has requested to fill the entire screen just
3379 // gets everything, period.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003380 if (attrs.type == TYPE_STATUS_BAR_PANEL
3381 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003382 pf.left = df.left = of.left = cf.left = hasNavBar
3383 ? mDockLeft : mUnrestrictedScreenLeft;
3384 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
3385 pf.right = df.right = of.right = cf.right = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003386 ? mRestrictedScreenLeft+mRestrictedScreenWidth
Dianne Hackbornc652de82013-02-15 16:32:56 -08003387 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003388 pf.bottom = df.bottom = of.bottom = cf.bottom = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003389 ? mRestrictedScreenTop+mRestrictedScreenHeight
Dianne Hackbornc652de82013-02-15 16:32:56 -08003390 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07003391 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler36412a72011-08-04 09:35:13 -04003392 "Laying out IN_SCREEN status bar window: (%d,%d - %d,%d)",
3393 pf.left, pf.top, pf.right, pf.bottom));
Jim Millere898ac52012-04-06 17:10:57 -07003394 } else if (attrs.type == TYPE_NAVIGATION_BAR
3395 || attrs.type == TYPE_NAVIGATION_BAR_PANEL) {
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003396 // The navigation bar has Real Ultimate Power.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003397 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3398 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3399 pf.right = df.right = of.right = mUnrestrictedScreenLeft
3400 + mUnrestrictedScreenWidth;
3401 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop
3402 + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07003403 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003404 "Laying out navigation bar window: (%d,%d - %d,%d)",
3405 pf.left, pf.top, pf.right, pf.bottom));
Dianne Hackborn01011c32012-02-21 13:54:21 -08003406 } else if ((attrs.type == TYPE_SECURE_SYSTEM_OVERLAY
3407 || attrs.type == TYPE_BOOT_PROGRESS)
Jeff Brownbfcb60a2011-09-08 18:51:14 -07003408 && ((fl & FLAG_FULLSCREEN) != 0)) {
3409 // Fullscreen secure system overlays get what they ask for.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003410 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3411 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3412 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
3413 + mOverscanScreenWidth;
3414 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
3415 + mOverscanScreenHeight;
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07003416 } else if (attrs.type == TYPE_BOOT_PROGRESS
3417 || attrs.type == TYPE_UNIVERSE_BACKGROUND) {
Dianne Hackborn01011c32012-02-21 13:54:21 -08003418 // Boot progress screen always covers entire display.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003419 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3420 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3421 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
3422 + mOverscanScreenWidth;
3423 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
3424 + mOverscanScreenHeight;
John Spurlockef4adae2013-08-26 17:58:58 -04003425 } else if (attrs.type == TYPE_WALLPAPER) {
3426 // The wallpaper also has Real Ultimate Power.
3427 pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft;
3428 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003429 pf.right = df.right = of.right = cf.right
John Spurlockef4adae2013-08-26 17:58:58 -04003430 = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003431 pf.bottom = df.bottom = of.bottom = cf.bottom
John Spurlockef4adae2013-08-26 17:58:58 -04003432 = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlock46646232013-09-30 22:32:42 -04003433 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08003434 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3435 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3436 // Asking to layout into the overscan region, so give it that pure
3437 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003438 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3439 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3440 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08003441 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003442 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003443 = mOverscanScreenTop + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003444 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003445 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Craig Mautnerbeac1062014-06-03 14:38:57 -07003446 && (attrs.type == TYPE_STATUS_BAR
3447 || attrs.type == TYPE_TOAST
John Spurlock34e13d92013-08-10 06:52:28 -04003448 || (attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3449 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW))) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003450 // Asking for layout as if the nav bar is hidden, lets the
3451 // application extend into the unrestricted screen area. We
John Spurlock34e13d92013-08-10 06:52:28 -04003452 // only do this for application windows (or toasts) to ensure no window that
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003453 // can be above the nav bar can do this.
3454 // XXX This assumes that an app asking for this will also
3455 // ask for layout in only content. We can't currently figure out
3456 // what the screen would be if only laying out to hide the nav bar.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003457 pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft;
3458 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
3459 pf.right = df.right = of.right = cf.right = mUnrestrictedScreenLeft
3460 + mUnrestrictedScreenWidth;
3461 pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop
3462 + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003463 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003464 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
3465 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
3466 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
3467 + mRestrictedScreenWidth;
3468 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
3469 + mRestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003470 }
Craig Mautner69b08182012-09-05 13:07:13 -07003471
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003472 applyStableConstraints(sysUiFl, fl, cf);
Craig Mautner69b08182012-09-05 13:07:13 -07003473
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003474 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3475 vf.left = mCurLeft;
3476 vf.top = mCurTop;
3477 vf.right = mCurRight;
3478 vf.bottom = mCurBottom;
3479 } else {
3480 vf.set(cf);
3481 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003482 } else if (attached != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07003483 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3484 "): attached to " + attached);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003485 // A child window should be placed inside of the same visible
3486 // frame that its parent had.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003487 setAttachedWindowFrames(win, fl, adjust, attached, false, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003488 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07003489 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3490 "): normal window");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003491 // Otherwise, a normal window must be placed inside the content
3492 // of all screen decorations.
Dianne Hackborna239c842011-06-01 12:28:20 -07003493 if (attrs.type == TYPE_STATUS_BAR_PANEL) {
3494 // Status bar panels are the only windows who can go on top of
3495 // the status bar. They are protected by the STATUS_BAR_SERVICE
3496 // permission, so they have the same privileges as the status
3497 // bar itself.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003498 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
3499 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
3500 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
3501 + mRestrictedScreenWidth;
3502 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
3503 + mRestrictedScreenHeight;
John Spurlock414c1f02013-12-04 13:47:36 -05003504 } else if (attrs.type == TYPE_TOAST || attrs.type == TYPE_SYSTEM_ALERT
3505 || attrs.type == TYPE_VOLUME_OVERLAY) {
3506 // These dialogs are stable to interim decor changes.
John Spurlockbd957402013-10-03 11:38:39 -04003507 pf.left = df.left = of.left = cf.left = mStableLeft;
3508 pf.top = df.top = of.top = cf.top = mStableTop;
3509 pf.right = df.right = of.right = cf.right = mStableRight;
3510 pf.bottom = df.bottom = of.bottom = cf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003511 } else {
Dianne Hackborna239c842011-06-01 12:28:20 -07003512 pf.left = mContentLeft;
3513 pf.top = mContentTop;
3514 pf.right = mContentRight;
3515 pf.bottom = mContentBottom;
Dianne Hackborn20d94742014-05-29 18:35:45 -07003516 if (win.isVoiceInteraction()) {
3517 df.left = of.left = cf.left = mVoiceContentLeft;
3518 df.top = of.top = cf.top = mVoiceContentTop;
3519 df.right = of.right = cf.right = mVoiceContentRight;
3520 df.bottom = of.bottom = cf.bottom = mVoiceContentBottom;
3521 } else if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003522 df.left = of.left = cf.left = mDockLeft;
3523 df.top = of.top = cf.top = mDockTop;
3524 df.right = of.right = cf.right = mDockRight;
3525 df.bottom = of.bottom = cf.bottom = mDockBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07003526 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003527 df.left = of.left = cf.left = mContentLeft;
3528 df.top = of.top = cf.top = mContentTop;
3529 df.right = of.right = cf.right = mContentRight;
3530 df.bottom = of.bottom = cf.bottom = mContentBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07003531 }
3532 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3533 vf.left = mCurLeft;
3534 vf.top = mCurTop;
3535 vf.right = mCurRight;
3536 vf.bottom = mCurBottom;
3537 } else {
3538 vf.set(cf);
3539 }
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003540 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003541 }
3542 }
Craig Mautner69b08182012-09-05 13:07:13 -07003543
Craig Mautnerb816bed2013-07-23 10:26:17 -07003544 // TYPE_SYSTEM_ERROR is above the NavigationBar so it can't be allowed to extend over it.
3545 if ((fl & FLAG_LAYOUT_NO_LIMITS) != 0 && attrs.type != TYPE_SYSTEM_ERROR) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003546 df.left = df.top = of.left = of.top = cf.left = cf.top = vf.left = vf.top = -10000;
3547 df.right = df.bottom = of.right = of.bottom = cf.right = cf.bottom
3548 = vf.right = vf.bottom = 10000;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003549 }
3550
Craig Mautnereda67292013-04-28 13:50:14 -07003551 if (DEBUG_LAYOUT) Slog.v(TAG, "Compute frame " + attrs.getTitle()
The Android Open Source Project11267662009-03-18 17:39:47 -07003552 + ": sim=#" + Integer.toHexString(sim)
RoboErik8a2cfc32014-05-16 11:19:38 -07003553 + " attach=" + attached + " type=" + attrs.type
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003554 + String.format(" flags=0x%08x", fl)
The Android Open Source Project11267662009-03-18 17:39:47 -07003555 + " pf=" + pf.toShortString() + " df=" + df.toShortString()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003556 + " of=" + of.toShortString()
John Spurlock46646232013-09-30 22:32:42 -04003557 + " cf=" + cf.toShortString() + " vf=" + vf.toShortString()
Adrian Roosfa104232014-06-20 16:10:14 -07003558 + " dcf=" + dcf.toShortString()
3559 + " sf=" + sf.toShortString());
Craig Mautner69b08182012-09-05 13:07:13 -07003560
Adrian Roosfa104232014-06-20 16:10:14 -07003561 win.computeFrameLw(pf, df, of, cf, vf, dcf, sf);
Craig Mautner69b08182012-09-05 13:07:13 -07003562
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003563 // Dock windows carve out the bottom of the screen, so normal windows
3564 // can't appear underneath them.
Craig Mautner8bd206b2012-10-03 10:32:02 -07003565 if (attrs.type == TYPE_INPUT_METHOD && win.isVisibleOrBehindKeyguardLw()
3566 && !win.getGivenInsetsPendingLw()) {
satok1bc0a492012-04-25 22:47:12 +09003567 setLastInputMethodWindowLw(null, null);
3568 offsetInputMethodWindowLw(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003569 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003570 if (attrs.type == TYPE_VOICE_INTERACTION && win.isVisibleOrBehindKeyguardLw()
3571 && !win.getGivenInsetsPendingLw()) {
3572 offsetVoiceInputWindowLw(win);
3573 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003574 }
3575
satok1bc0a492012-04-25 22:47:12 +09003576 private void offsetInputMethodWindowLw(WindowState win) {
3577 int top = win.getContentFrameLw().top;
3578 top += win.getGivenContentInsetsLw().top;
3579 if (mContentBottom > top) {
3580 mContentBottom = top;
3581 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003582 if (mVoiceContentBottom > top) {
3583 mVoiceContentBottom = top;
3584 }
satok1bc0a492012-04-25 22:47:12 +09003585 top = win.getVisibleFrameLw().top;
3586 top += win.getGivenVisibleInsetsLw().top;
3587 if (mCurBottom > top) {
3588 mCurBottom = top;
3589 }
Craig Mautnereda67292013-04-28 13:50:14 -07003590 if (DEBUG_LAYOUT) Slog.v(TAG, "Input method: mDockBottom="
satok1bc0a492012-04-25 22:47:12 +09003591 + mDockBottom + " mContentBottom="
3592 + mContentBottom + " mCurBottom=" + mCurBottom);
3593 }
3594
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003595 private void offsetVoiceInputWindowLw(WindowState win) {
3596 final int gravity = win.getAttrs().gravity;
3597 switch (gravity&((Gravity.AXIS_PULL_BEFORE|Gravity.AXIS_PULL_AFTER)
3598 << Gravity.AXIS_X_SHIFT)) {
3599 case Gravity.AXIS_PULL_BEFORE<<Gravity.AXIS_X_SHIFT: {
3600 int right = win.getContentFrameLw().right - win.getGivenContentInsetsLw().right;
3601 if (mVoiceContentLeft < right) {
3602 mVoiceContentLeft = right;
3603 }
3604 } break;
3605 case Gravity.AXIS_PULL_AFTER<<Gravity.AXIS_X_SHIFT: {
3606 int left = win.getContentFrameLw().left - win.getGivenContentInsetsLw().left;
3607 if (mVoiceContentRight < left) {
3608 mVoiceContentRight = left;
3609 }
3610 } break;
3611 }
3612 switch (gravity&((Gravity.AXIS_PULL_BEFORE|Gravity.AXIS_PULL_AFTER)
3613 << Gravity.AXIS_Y_SHIFT)) {
3614 case Gravity.AXIS_PULL_BEFORE<<Gravity.AXIS_Y_SHIFT: {
3615 int bottom = win.getContentFrameLw().bottom - win.getGivenContentInsetsLw().bottom;
3616 if (mVoiceContentTop < bottom) {
3617 mVoiceContentTop = bottom;
3618 }
3619 } break;
3620 case Gravity.AXIS_PULL_AFTER<<Gravity.AXIS_Y_SHIFT: {
3621 int top = win.getContentFrameLw().top - win.getGivenContentInsetsLw().top;
3622 if (mVoiceContentBottom < top) {
3623 mVoiceContentBottom = top;
3624 }
3625 } break;
3626 }
3627 }
3628
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003629 /** {@inheritDoc} */
Craig Mautner61ac6bb2012-02-02 17:29:33 -08003630 @Override
3631 public void finishLayoutLw() {
3632 return;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003633 }
3634
3635 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003636 @Override
Craig Mautner39834192012-09-02 07:47:24 -07003637 public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) {
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003638 mTopFullscreenOpaqueWindowState = null;
Craig Mautner2bc789b2014-03-19 19:48:38 -07003639 mAppsToBeHidden.clear();
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003640 mForceStatusBar = false;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003641 mForceStatusBarFromKeyguard = false;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08003642 mForcingShowNavBar = false;
3643 mForcingShowNavBarLayer = -1;
RoboErik8a2cfc32014-05-16 11:19:38 -07003644
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003645 mHideLockScreen = false;
3646 mAllowLockscreenWhenOn = false;
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003647 mDismissKeyguard = DISMISS_KEYGUARD_NONE;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003648 mShowingLockscreen = false;
3649 mShowingDream = false;
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003650 mWinShowWhenLocked = null;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003651 }
3652
3653 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003654 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003655 public void applyPostLayoutPolicyLw(WindowState win, WindowManager.LayoutParams attrs) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07003656 if (DEBUG_LAYOUT) Slog.i(TAG, "Win " + win + ": isVisibleOrBehindKeyguardLw="
3657 + win.isVisibleOrBehindKeyguardLw());
John Spurlockc6d1c602014-01-17 15:22:06 -05003658 final int fl = PolicyControl.getWindowFlags(win, attrs);
John Spurlock414c1f02013-12-04 13:47:36 -05003659 if (mTopFullscreenOpaqueWindowState == null
3660 && win.isVisibleLw() && attrs.type == TYPE_INPUT_METHOD) {
3661 mForcingShowNavBar = true;
3662 mForcingShowNavBarLayer = win.getSurfaceLayer();
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08003663 }
Jorim Jaggiafd4a552014-04-08 15:13:05 +02003664 if (attrs.type == TYPE_STATUS_BAR && (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Jorim Jaggiafd4a552014-04-08 15:13:05 +02003665 mForceStatusBarFromKeyguard = true;
3666 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003667 if (mTopFullscreenOpaqueWindowState == null &&
Dianne Hackborn01b02a72012-01-12 14:05:03 -08003668 win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()) {
John Spurlockc6d1c602014-01-17 15:22:06 -05003669 if ((fl & FLAG_FORCE_NOT_FULLSCREEN) != 0) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003670 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003671 mForceStatusBarFromKeyguard = true;
3672 } else {
3673 mForceStatusBar = true;
3674 }
3675 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003676 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003677 mShowingLockscreen = true;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07003678 }
Craig Mautnerab55e522014-03-03 13:26:03 -08003679 boolean appWindow = attrs.type >= FIRST_APPLICATION_WINDOW
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003680 && attrs.type <= LAST_APPLICATION_WINDOW;
3681 if (attrs.type == TYPE_DREAM) {
Jeff Brownc8018eb2012-10-29 21:33:27 -07003682 // If the lockscreen was showing when the dream started then wait
3683 // for the dream to draw before hiding the lockscreen.
3684 if (!mDreamingLockscreen
3685 || (win.isVisibleLw() && win.hasDrawnLw())) {
3686 mShowingDream = true;
Craig Mautnerab55e522014-03-03 13:26:03 -08003687 appWindow = true;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003688 }
3689 }
Craig Mautnerab55e522014-03-03 13:26:03 -08003690
Craig Mautner00156ec2014-03-06 22:29:02 -08003691 final boolean showWhenLocked = (fl & FLAG_SHOW_WHEN_LOCKED) != 0;
Craig Mautner74ee9382014-04-01 15:20:16 -07003692 final boolean dismissKeyguard = (fl & FLAG_DISMISS_KEYGUARD) != 0;
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003693 final boolean secureKeyguard = isKeyguardSecure();
Craig Mautnerab55e522014-03-03 13:26:03 -08003694 if (appWindow) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003695 if (showWhenLocked || (dismissKeyguard && !secureKeyguard)) {
3696 // Remove any previous windows with the same appToken.
Craig Mautner2bc789b2014-03-19 19:48:38 -07003697 mAppsToBeHidden.remove(win.getAppToken());
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003698 if (mAppsToBeHidden.isEmpty() && showWhenLocked &&
3699 isKeyguardSecureIncludingHidden()) {
3700 mWinShowWhenLocked = win;
3701 mHideLockScreen = true;
3702 mForceStatusBarFromKeyguard = false;
3703 }
Craig Mautner2bc789b2014-03-19 19:48:38 -07003704 } else {
3705 mAppsToBeHidden.add(win.getAppToken());
3706 }
Craig Mautnerab55e522014-03-03 13:26:03 -08003707 if (attrs.x == 0 && attrs.y == 0
3708 && attrs.width == WindowManager.LayoutParams.MATCH_PARENT
3709 && attrs.height == WindowManager.LayoutParams.MATCH_PARENT) {
3710 if (DEBUG_LAYOUT) Slog.v(TAG, "Fullscreen window: " + win);
3711 mTopFullscreenOpaqueWindowState = win;
Craig Mautner2bc789b2014-03-19 19:48:38 -07003712 if (mAppsToBeHidden.isEmpty()) {
Craig Mautnerda09ae32014-03-03 13:26:03 -08003713 if (showWhenLocked) {
3714 if (DEBUG_LAYOUT) Slog.v(TAG,
3715 "Setting mHideLockScreen to true by win " + win);
3716 mHideLockScreen = true;
3717 mForceStatusBarFromKeyguard = false;
3718 }
Craig Mautner4bdab6b2014-04-01 12:05:11 -07003719 if (dismissKeyguard && mDismissKeyguard == DISMISS_KEYGUARD_NONE) {
Craig Mautnerda09ae32014-03-03 13:26:03 -08003720 if (DEBUG_LAYOUT) Slog.v(TAG,
3721 "Setting mDismissKeyguard true by win " + win);
3722 mDismissKeyguard = mWinDismissingKeyguard == win ?
3723 DISMISS_KEYGUARD_CONTINUE : DISMISS_KEYGUARD_START;
3724 mWinDismissingKeyguard = win;
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003725 mForceStatusBarFromKeyguard = mShowingLockscreen && secureKeyguard;
Craig Mautnerda09ae32014-03-03 13:26:03 -08003726 }
Craig Mautnerab55e522014-03-03 13:26:03 -08003727 }
Craig Mautner00156ec2014-03-06 22:29:02 -08003728 if ((fl & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) {
Craig Mautnerab55e522014-03-03 13:26:03 -08003729 mAllowLockscreenWhenOn = true;
3730 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003731 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003732
3733 if (mWinShowWhenLocked != null &&
3734 mWinShowWhenLocked.getAppToken() != win.getAppToken()) {
3735 win.hideLw(false);
3736 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003737 }
3738 }
3739 }
3740
3741 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003742 @Override
Craig Mautner39834192012-09-02 07:47:24 -07003743 public int finishPostLayoutPolicyLw() {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003744 if (mWinShowWhenLocked != null &&
3745 mWinShowWhenLocked != mTopFullscreenOpaqueWindowState) {
3746 // A dialog is dismissing the keyguard. Put the wallpaper behind it and hide the
3747 // fullscreen window.
3748 // TODO: Make sure FLAG_SHOW_WALLPAPER is restored when dialog is dismissed. Or not.
3749 mWinShowWhenLocked.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
3750 mTopFullscreenOpaqueWindowState.hideLw(false);
3751 mTopFullscreenOpaqueWindowState = mWinShowWhenLocked;
3752 }
3753
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003754 int changes = 0;
Joe Onorato93056472010-09-10 10:30:46 -04003755 boolean topIsFullscreen = false;
Daniel Sandlere02d8082010-10-08 15:13:22 -04003756
3757 final WindowManager.LayoutParams lp = (mTopFullscreenOpaqueWindowState != null)
3758 ? mTopFullscreenOpaqueWindowState.getAttrs()
3759 : null;
3760
Jeff Brownc8018eb2012-10-29 21:33:27 -07003761 // If we are not currently showing a dream then remember the current
3762 // lockscreen state. We will use this to determine whether the dream
3763 // started while the lockscreen was showing and remember this state
3764 // while the dream is showing.
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003765 if (!mShowingDream) {
3766 mDreamingLockscreen = mShowingLockscreen;
3767 }
3768
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003769 if (mStatusBar != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07003770 if (DEBUG_LAYOUT) Slog.i(TAG, "force=" + mForceStatusBar
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003771 + " forcefkg=" + mForceStatusBarFromKeyguard
Dianne Hackbornd70bc2f2009-10-06 23:25:51 -07003772 + " top=" + mTopFullscreenOpaqueWindowState);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003773 if (mForceStatusBar || mForceStatusBarFromKeyguard) {
Craig Mautnereda67292013-04-28 13:50:14 -07003774 if (DEBUG_LAYOUT) Slog.v(TAG, "Showing status bar: forced");
John Spurlock27735a42013-08-14 17:57:38 -04003775 if (mStatusBarController.setBarShowingLw(true)) {
3776 changes |= FINISH_LAYOUT_REDO_LAYOUT;
3777 }
Craig Mautner81defc72013-10-29 11:10:42 -07003778 // Maintain fullscreen layout until incoming animation is complete.
3779 topIsFullscreen = mTopIsFullscreen && mStatusBar.isAnimatingLw();
John Spurlockf92b6162013-11-11 15:01:16 -05003780 // Transient status bar on the lockscreen is not allowed
3781 if (mForceStatusBarFromKeyguard && mStatusBarController.isTransientShowing()) {
3782 mStatusBarController.updateVisibilityLw(false /*transientAllowed*/,
3783 mLastSystemUiFlags, mLastSystemUiFlags);
3784 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003785 } else if (mTopFullscreenOpaqueWindowState != null) {
John Spurlockc6d1c602014-01-17 15:22:06 -05003786 final int fl = PolicyControl.getWindowFlags(null, lp);
Joe Onorato93056472010-09-10 10:30:46 -04003787 if (localLOGV) {
Craig Mautnereda67292013-04-28 13:50:14 -07003788 Slog.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw()
Joe Onorato93056472010-09-10 10:30:46 -04003789 + " shown frame: " + mTopFullscreenOpaqueWindowState.getShownFrameLw());
Craig Mautnereda67292013-04-28 13:50:14 -07003790 Slog.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs()
John Spurlockc6d1c602014-01-17 15:22:06 -05003791 + " lp.flags=0x" + Integer.toHexString(fl));
Joe Onorato93056472010-09-10 10:30:46 -04003792 }
John Spurlockc6d1c602014-01-17 15:22:06 -05003793 topIsFullscreen = (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003794 || (mLastSystemUiFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
Joe Onorato93056472010-09-10 10:30:46 -04003795 // The subtle difference between the window for mTopFullscreenOpaqueWindowState
3796 // and mTopIsFullscreen is that that mTopIsFullscreen is set only if the window
3797 // has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the
3798 // case though.
John Spurlock27735a42013-08-14 17:57:38 -04003799 if (mStatusBarController.isTransientShowing()) {
3800 if (mStatusBarController.setBarShowingLw(true)) {
John Spurlock32beb2c2013-03-11 10:16:47 -04003801 changes |= FINISH_LAYOUT_REDO_LAYOUT;
3802 }
3803 } else if (topIsFullscreen) {
Craig Mautnereda67292013-04-28 13:50:14 -07003804 if (DEBUG_LAYOUT) Slog.v(TAG, "** HIDING status bar");
John Spurlock27735a42013-08-14 17:57:38 -04003805 if (mStatusBarController.setBarShowingLw(false)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003806 changes |= FINISH_LAYOUT_REDO_LAYOUT;
Craig Mautnereda67292013-04-28 13:50:14 -07003807 } else {
Craig Mautnerc5a6e442013-06-05 17:22:35 -07003808 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar already hiding");
Daniel Sandler40427442010-07-16 11:44:52 -04003809 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003810 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07003811 if (DEBUG_LAYOUT) Slog.v(TAG, "** SHOWING status bar: top is not fullscreen");
John Spurlock27735a42013-08-14 17:57:38 -04003812 if (mStatusBarController.setBarShowingLw(true)) {
3813 changes |= FINISH_LAYOUT_REDO_LAYOUT;
3814 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003815 }
3816 }
3817 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04003818
Craig Mautner81defc72013-10-29 11:10:42 -07003819 if (mTopIsFullscreen != topIsFullscreen) {
3820 if (!topIsFullscreen) {
3821 // Force another layout when status bar becomes fully shown.
3822 changes |= FINISH_LAYOUT_REDO_LAYOUT;
3823 }
3824 mTopIsFullscreen = topIsFullscreen;
3825 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04003826
Craig Mautner39834192012-09-02 07:47:24 -07003827 // Hide the key guard if a visible window explicitly specifies that it wants to be
3828 // displayed when the screen is locked.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01003829 if (mKeyguardDelegate != null && mStatusBar != null) {
3830 if (localLOGV) Slog.v(TAG, "finishPostLayoutPolicyLw: mHideKeyguard="
3831 + mHideLockScreen);
3832 if (mDismissKeyguard != DISMISS_KEYGUARD_NONE && !isKeyguardSecure()) {
3833 mKeyguardHidden = true;
3834 if (processKeyguardSetHiddenResultLw(mKeyguardDelegate.setOccluded(true))) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003835 changes |= FINISH_LAYOUT_REDO_LAYOUT
3836 | FINISH_LAYOUT_REDO_CONFIG
3837 | FINISH_LAYOUT_REDO_WALLPAPER;
3838 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01003839 if (mKeyguardDelegate.isShowing()) {
3840 mHandler.post(new Runnable() {
3841 @Override
3842 public void run() {
3843 mKeyguardDelegate.keyguardDone(false, false);
3844 }
3845 });
3846 }
3847 } else if (mHideLockScreen) {
3848 mKeyguardHidden = true;
3849 if (processKeyguardSetHiddenResultLw(mKeyguardDelegate.setOccluded(true))) {
3850 changes |= FINISH_LAYOUT_REDO_LAYOUT
3851 | FINISH_LAYOUT_REDO_CONFIG
3852 | FINISH_LAYOUT_REDO_WALLPAPER;
3853 }
3854 } else if (mDismissKeyguard != DISMISS_KEYGUARD_NONE) {
3855 // This is the case of keyguard isSecure() and not mHideLockScreen.
3856 if (mDismissKeyguard == DISMISS_KEYGUARD_START) {
3857 // Only launch the next keyguard unlock window once per window.
3858 mKeyguardHidden = false;
3859 if (processKeyguardSetHiddenResultLw(mKeyguardDelegate.setOccluded(false))) {
3860 changes |= FINISH_LAYOUT_REDO_LAYOUT
3861 | FINISH_LAYOUT_REDO_CONFIG
3862 | FINISH_LAYOUT_REDO_WALLPAPER;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003863 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01003864 mHandler.post(new Runnable() {
3865 @Override
3866 public void run() {
3867 mKeyguardDelegate.dismiss();
3868 }
3869 });
3870 }
3871 } else {
3872 mWinDismissingKeyguard = null;
3873 mKeyguardHidden = false;
3874 if (processKeyguardSetHiddenResultLw(mKeyguardDelegate.setOccluded(false))) {
3875 changes |= FINISH_LAYOUT_REDO_LAYOUT
3876 | FINISH_LAYOUT_REDO_CONFIG
3877 | FINISH_LAYOUT_REDO_WALLPAPER;
3878 }
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -07003879 }
3880 }
Joe Onorato664644d2011-01-23 17:53:23 -08003881
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003882 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003883 // If the navigation bar has been hidden or shown, we need to do another
3884 // layout pass to update that window.
3885 changes |= FINISH_LAYOUT_REDO_LAYOUT;
3886 }
Joe Onorato664644d2011-01-23 17:53:23 -08003887
Mike Lockwood28569302010-01-28 11:54:40 -05003888 // update since mAllowLockscreenWhenOn might have changed
3889 updateLockScreenTimeout();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003890 return changes;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003891 }
3892
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003893 /**
Jorim Jaggi5cf17872014-03-26 18:31:48 +01003894 * Processes the result code of {@link IKeyguardService#setOccluded}. This is needed because we
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003895 * immediately need to put the wallpaper directly behind the Keyguard when a window with flag
3896 * {@link android.view.WindowManager.LayoutParams#FLAG_SHOW_WHEN_LOCKED} gets dismissed. If we
3897 * would wait for Keyguard to change the flags, that would be running asynchronously and thus be
3898 * too late so the user might see the window behind.
3899 *
Jorim Jaggi5cf17872014-03-26 18:31:48 +01003900 * @param setHiddenResult The result code from {@link IKeyguardService#setOccluded}.
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003901 * @return Whether the flags have changed and we have to redo the layout.
3902 */
3903 private boolean processKeyguardSetHiddenResultLw(int setHiddenResult) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01003904 if (setHiddenResult
3905 == IKeyguardServiceConstants.KEYGUARD_SERVICE_SET_OCCLUDED_RESULT_SET_FLAGS) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003906 mStatusBar.getAttrs().privateFlags |= PRIVATE_FLAG_KEYGUARD;
3907 mStatusBar.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
3908 return true;
3909 } else if (setHiddenResult
Jorim Jaggi5cf17872014-03-26 18:31:48 +01003910 == IKeyguardServiceConstants.KEYGUARD_SERVICE_SET_OCCLUDED_RESULT_UNSET_FLAGS) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003911 mStatusBar.getAttrs().privateFlags &= ~PRIVATE_FLAG_KEYGUARD;
3912 mStatusBar.getAttrs().flags &= ~FLAG_SHOW_WALLPAPER;
3913 return true;
3914 } else {
3915 return false;
3916 }
3917 }
3918
3919 private boolean isStatusBarKeyguard() {
3920 return mStatusBar != null
3921 && (mStatusBar.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
3922 }
3923
Jose Lima9546b202014-07-02 17:21:51 -07003924 @Override
Dianne Hackborn08743722009-12-21 12:16:51 -08003925 public boolean allowAppAnimationsLw() {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003926 if (isStatusBarKeyguard() || mShowingDream) {
Craig Mautner28816302013-10-10 20:31:00 -07003927 // If keyguard or dreams is currently visible, no reason to animate behind it.
Dianne Hackborn08743722009-12-21 12:16:51 -08003928 return false;
3929 }
Dianne Hackborn08743722009-12-21 12:16:51 -08003930 return true;
3931 }
3932
Jose Lima9546b202014-07-02 17:21:51 -07003933 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07003934 public int focusChangedLw(WindowState lastFocus, WindowState newFocus) {
Joe Onorato664644d2011-01-23 17:53:23 -08003935 mFocusedWindow = newFocus;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003936 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003937 // If the navigation bar has been hidden or shown, we need to do another
3938 // layout pass to update that window.
3939 return FINISH_LAYOUT_REDO_LAYOUT;
3940 }
3941 return 0;
Joe Onorato664644d2011-01-23 17:53:23 -08003942 }
3943
Dianne Hackborn0ecadf72009-03-31 18:00:37 -07003944 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07003945 @Override
Jeff Brown46b9ac02010-04-22 18:58:52 -07003946 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
3947 // lid changed state
Jeff Brownc458ce92012-04-30 14:58:40 -07003948 final int newLidState = lidOpen ? LID_OPEN : LID_CLOSED;
3949 if (newLidState == mLidState) {
3950 return;
3951 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07003952
Jeff Brownc458ce92012-04-30 14:58:40 -07003953 mLidState = newLidState;
3954 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07003955 updateRotation(true);
Jeff Brownc458ce92012-04-30 14:58:40 -07003956
3957 if (lidOpen) {
Jim Millere51cf7ae2013-06-25 18:31:56 -07003958 mPowerManager.wakeUp(SystemClock.uptimeMillis());
Jeff Brownc458ce92012-04-30 14:58:40 -07003959 } else if (!mLidControlsSleep) {
Jeff Brown96307042012-07-27 15:51:34 -07003960 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
Jeff Brown46b9ac02010-04-22 18:58:52 -07003961 }
3962 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003963
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08003964 void setHdmiPlugged(boolean plugged) {
3965 if (mHdmiPlugged != plugged) {
3966 mHdmiPlugged = plugged;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003967 updateRotation(true, true);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08003968 Intent intent = new Intent(ACTION_HDMI_PLUGGED);
Joe Onoratodc100302011-01-11 17:07:41 -08003969 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08003970 intent.putExtra(EXTRA_HDMI_PLUGGED_STATE, plugged);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07003971 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08003972 }
3973 }
3974
Joe Onoratoea495d42011-04-06 11:41:11 -07003975 void initializeHdmiState() {
Joe Onorato7ba631f2011-05-04 15:28:00 -07003976 boolean plugged = false;
Joe Onoratoea495d42011-04-06 11:41:11 -07003977 // watch for HDMI plug messages if the hdmi switch exists
3978 if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) {
3979 mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi");
3980
Joe Onoratoea495d42011-04-06 11:41:11 -07003981 final String filename = "/sys/class/switch/hdmi/state";
3982 FileReader reader = null;
3983 try {
3984 reader = new FileReader(filename);
3985 char[] buf = new char[15];
3986 int n = reader.read(buf);
3987 if (n > 1) {
3988 plugged = 0 != Integer.parseInt(new String(buf, 0, n-1));
3989 }
3990 } catch (IOException ex) {
3991 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
3992 } catch (NumberFormatException ex) {
3993 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
3994 } finally {
3995 if (reader != null) {
3996 try {
3997 reader.close();
3998 } catch (IOException ex) {
3999 }
Joe Onoratodc100302011-01-11 17:07:41 -08004000 }
4001 }
4002 }
Joe Onorato7ba631f2011-05-04 15:28:00 -07004003 // This dance forces the code in setHdmiPlugged to run.
4004 // Always do this so the sticky intent is stuck (to false) if there is no hdmi.
4005 mHdmiPlugged = !plugged;
4006 setHdmiPlugged(!mHdmiPlugged);
Joe Onoratodc100302011-01-11 17:07:41 -08004007 }
4008
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004009 /**
Jean-Michel Trivifca1e602013-10-10 18:12:59 -07004010 * @return Whether music is being played right now "locally" (e.g. on the device's speakers
4011 * or wired headphones) or "remotely" (e.g. on a device using the Cast protocol and
4012 * controlled by this device, or through remote submix).
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004013 */
4014 boolean isMusicActive() {
RoboErik430fc482014-06-12 15:49:20 -07004015
Eric Laurent413cb9d2009-07-17 11:52:43 -07004016 final AudioManager am = (AudioManager)mContext.getSystemService(Context.AUDIO_SERVICE);
4017 if (am == null) {
4018 Log.w(TAG, "isMusicActive: couldn't get AudioManager reference");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004019 return false;
4020 }
Jean-Michel Trivifca1e602013-10-10 18:12:59 -07004021 return am.isLocalOrRemoteMusicActive();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004022 }
4023
Dianne Hackbornc0e3f242011-08-19 14:19:10 -07004024 final Object mScreenshotLock = new Object();
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004025 ServiceConnection mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004026
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004027 final Runnable mScreenshotTimeout = new Runnable() {
4028 @Override public void run() {
4029 synchronized (mScreenshotLock) {
4030 if (mScreenshotConnection != null) {
4031 mContext.unbindService(mScreenshotConnection);
4032 mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004033 }
Winson Chung9112ec32011-06-27 13:15:32 -07004034 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004035 }
4036 };
4037
4038 // Assume this is called from the Handler thread.
4039 private void takeScreenshot() {
4040 synchronized (mScreenshotLock) {
4041 if (mScreenshotConnection != null) {
4042 return;
4043 }
4044 ComponentName cn = new ComponentName("com.android.systemui",
4045 "com.android.systemui.screenshot.TakeScreenshotService");
4046 Intent intent = new Intent();
4047 intent.setComponent(cn);
4048 ServiceConnection conn = new ServiceConnection() {
4049 @Override
4050 public void onServiceConnected(ComponentName name, IBinder service) {
4051 synchronized (mScreenshotLock) {
4052 if (mScreenshotConnection != this) {
4053 return;
4054 }
4055 Messenger messenger = new Messenger(service);
4056 Message msg = Message.obtain(null, 1);
4057 final ServiceConnection myConn = this;
4058 Handler h = new Handler(mHandler.getLooper()) {
4059 @Override
4060 public void handleMessage(Message msg) {
4061 synchronized (mScreenshotLock) {
4062 if (mScreenshotConnection == myConn) {
4063 mContext.unbindService(mScreenshotConnection);
4064 mScreenshotConnection = null;
4065 mHandler.removeCallbacks(mScreenshotTimeout);
4066 }
4067 }
4068 }
4069 };
4070 msg.replyTo = new Messenger(h);
Winson Chunga63bb842011-10-17 10:26:28 -07004071 msg.arg1 = msg.arg2 = 0;
4072 if (mStatusBar != null && mStatusBar.isVisibleLw())
4073 msg.arg1 = 1;
4074 if (mNavigationBar != null && mNavigationBar.isVisibleLw())
4075 msg.arg2 = 1;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004076 try {
4077 messenger.send(msg);
4078 } catch (RemoteException e) {
4079 }
4080 }
4081 }
4082 @Override
4083 public void onServiceDisconnected(ComponentName name) {}
4084 };
Amith Yamasani27b89e62013-01-16 12:30:11 -08004085 if (mContext.bindServiceAsUser(
4086 intent, conn, Context.BIND_AUTO_CREATE, UserHandle.CURRENT)) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004087 mScreenshotConnection = conn;
4088 mHandler.postDelayed(mScreenshotTimeout, 10000);
4089 }
4090 }
Winson Chung9112ec32011-06-27 13:15:32 -07004091 }
4092
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004093 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004094 @Override
Jeff Brown037c33e2014-04-09 00:31:55 -07004095 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) {
Jeff Brown96307042012-07-27 15:51:34 -07004096 if (!mSystemBooted) {
4097 // If we have not yet booted, don't let key events do anything.
4098 return 0;
4099 }
4100
Jeff Brown037c33e2014-04-09 00:31:55 -07004101 final boolean interactive = (policyFlags & FLAG_INTERACTIVE) != 0;
Jeff Brown1f245102010-11-18 20:53:46 -08004102 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
4103 final boolean canceled = event.isCanceled();
4104 final int keyCode = event.getKeyCode();
Jeff Browne20c9e02010-10-11 14:20:19 -07004105
Jeff Brown3122e442010-10-11 23:32:49 -07004106 final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0;
Jeff Brown3122e442010-10-11 23:32:49 -07004107
Mike Lockwoodc72b15f2009-11-28 20:58:22 -05004108 // If screen is off then we treat the case where the keyguard is open but hidden
4109 // the same as if it were open and in front.
4110 // This will prevent any keys other than the power button from waking the screen
4111 // when the keyguard is hidden by another activity.
Jim Miller5ecd8112013-01-09 18:50:26 -08004112 final boolean keyguardActive = (mKeyguardDelegate == null ? false :
Jeff Brown037c33e2014-04-09 00:31:55 -07004113 (interactive ?
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004114 mKeyguardDelegate.isShowingAndNotOccluded() :
Jim Miller5ecd8112013-01-09 18:50:26 -08004115 mKeyguardDelegate.isShowing()));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004116
Jeff Brown40013652012-05-16 21:22:36 -07004117 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004118 Log.d(TAG, "interceptKeyTq keycode=" + keyCode
Jeff Brown037c33e2014-04-09 00:31:55 -07004119 + " interactive=" + interactive + " keyguardActive=" + keyguardActive
Jeff Brown26875502014-01-30 21:47:47 -08004120 + " policyFlags=" + Integer.toHexString(policyFlags));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004121 }
4122
Jeff Brown037c33e2014-04-09 00:31:55 -07004123 // Basic policy based on interactive state.
Jeff Brown4d396052010-10-29 21:50:21 -07004124 int result;
Michael Wright337d9d22014-04-22 15:03:48 -07004125 boolean isWakeKey = (policyFlags & WindowManagerPolicy.FLAG_WAKE) != 0
4126 || event.isWakeKey();
Jeff Brown037c33e2014-04-09 00:31:55 -07004127 if (interactive || (isInjected && !isWakeKey)) {
Jeff Brown4d396052010-10-29 21:50:21 -07004128 // When the screen is on or if the key is injected pass the key to the application.
4129 result = ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07004130 isWakeKey = false;
Jeff Brown4d396052010-10-29 21:50:21 -07004131 } else {
4132 // When the screen is off and the key is not injected, determine whether
4133 // to wake the device but don't pass the key to the application.
4134 result = 0;
Jeff Brown26875502014-01-30 21:47:47 -08004135 if (isWakeKey && (!down || !isWakeKeyWhenScreenOff(keyCode))) {
4136 isWakeKey = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004137 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004138 }
4139
Justin Kohd378ad72013-04-01 12:18:26 -07004140 // If the key would be handled globally, just return the result, don't worry about special
4141 // key processing.
4142 if (mGlobalKeyManager.shouldHandleGlobalKey(keyCode, event)) {
Michael Wright85b1af62014-06-04 14:51:58 -07004143 if (isWakeKey) {
4144 mPowerManager.wakeUp(event.getEventTime());
4145 }
Justin Kohd378ad72013-04-01 12:18:26 -07004146 return result;
4147 }
4148
Jeff Brownbae8e772014-06-12 19:59:45 -07004149 boolean useHapticFeedback = down
4150 && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0
4151 && event.getRepeatCount() == 0;
4152
Jeff Brown4d396052010-10-29 21:50:21 -07004153 // Handle special keys.
4154 switch (keyCode) {
4155 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jeff Brownb0418da2010-11-01 15:24:01 -07004156 case KeyEvent.KEYCODE_VOLUME_UP:
4157 case KeyEvent.KEYCODE_VOLUME_MUTE: {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004158 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
4159 if (down) {
Jeff Brown037c33e2014-04-09 00:31:55 -07004160 if (interactive && !mVolumeDownKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004161 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
4162 mVolumeDownKeyTriggered = true;
4163 mVolumeDownKeyTime = event.getDownTime();
4164 mVolumeDownKeyConsumedByScreenshotChord = false;
4165 cancelPendingPowerKeyAction();
4166 interceptScreenshotChord();
4167 }
4168 } else {
4169 mVolumeDownKeyTriggered = false;
4170 cancelPendingScreenshotChordAction();
4171 }
4172 } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
4173 if (down) {
Jeff Brown037c33e2014-04-09 00:31:55 -07004174 if (interactive && !mVolumeUpKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004175 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
4176 mVolumeUpKeyTriggered = true;
4177 cancelPendingPowerKeyAction();
4178 cancelPendingScreenshotChordAction();
4179 }
4180 } else {
4181 mVolumeUpKeyTriggered = false;
4182 cancelPendingScreenshotChordAction();
4183 }
4184 }
Jeff Brown4d396052010-10-29 21:50:21 -07004185 if (down) {
Santos Cordon9eb45932014-06-27 12:28:43 -07004186 TelecommManager telecommManager = getTelecommService();
4187 if (telecommManager != null) {
4188 if (telecommManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07004189 // If an incoming call is ringing, either VOLUME key means
4190 // "silence ringer". We handle these keys here, rather than
4191 // in the InCallScreen, to make sure we'll respond to them
4192 // even if the InCallScreen hasn't come to the foreground yet.
4193 // Look for the DOWN event here, to agree with the "fallback"
4194 // behavior in the InCallScreen.
4195 Log.i(TAG, "interceptKeyBeforeQueueing:"
4196 + " VOLUME key-down while ringing: Silence ringer!");
Jeff Brown4d396052010-10-29 21:50:21 -07004197
Santos Cordon6848f722014-05-21 15:22:12 -07004198 // Silence the ringer. (It's safe to call this
4199 // even if the ringer has already been silenced.)
Santos Cordon9eb45932014-06-27 12:28:43 -07004200 telecommManager.silenceRinger();
Jeff Brown4d396052010-10-29 21:50:21 -07004201
Santos Cordon6848f722014-05-21 15:22:12 -07004202 // And *don't* pass this key thru to the current activity
4203 // (which is probably the InCallScreen.)
4204 result &= ~ACTION_PASS_TO_USER;
4205 break;
4206 }
Santos Cordon9eb45932014-06-27 12:28:43 -07004207 if (telecommManager.isInAPhoneCall()
Santos Cordon6848f722014-05-21 15:22:12 -07004208 && (result & ACTION_PASS_TO_USER) == 0) {
4209 // If we are in call but we decided not to pass the key to
RoboErik430fc482014-06-12 15:49:20 -07004210 // the application, just pass it to the session service.
4211
4212 MediaSessionLegacyHelper.getHelper(mContext)
4213 .sendMediaButtonEvent(event, true);
Santos Cordon6848f722014-05-21 15:22:12 -07004214 break;
Jeff Brown4d396052010-10-29 21:50:21 -07004215 }
4216 }
4217
RoboErik430fc482014-06-12 15:49:20 -07004218 if ((result & ACTION_PASS_TO_USER) == 0) {
4219 // If we aren't passing to the user and no one else
4220 // handled it send it to the session manager to figure
4221 // out.
4222 MediaSessionLegacyHelper.getHelper(mContext)
4223 .sendMediaButtonEvent(event, true);
Jeff Brown4d396052010-10-29 21:50:21 -07004224 break;
4225 }
4226 }
4227 break;
4228 }
4229
4230 case KeyEvent.KEYCODE_ENDCALL: {
4231 result &= ~ACTION_PASS_TO_USER;
4232 if (down) {
Santos Cordon9eb45932014-06-27 12:28:43 -07004233 TelecommManager telecommManager = getTelecommService();
Jeff Brown4d396052010-10-29 21:50:21 -07004234 boolean hungUp = false;
Santos Cordon9eb45932014-06-27 12:28:43 -07004235 if (telecommManager != null) {
4236 hungUp = telecommManager.endCall();
Jeff Brown4d396052010-10-29 21:50:21 -07004237 }
Jeff Brown037c33e2014-04-09 00:31:55 -07004238 interceptPowerKeyDown(!interactive || hungUp);
Jeff Brown4d396052010-10-29 21:50:21 -07004239 } else {
4240 if (interceptPowerKeyUp(canceled)) {
4241 if ((mEndcallBehavior
4242 & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) {
4243 if (goHome()) {
4244 break;
Dianne Hackborn0041e972009-07-24 17:14:43 -07004245 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004246 }
Jeff Brown4d396052010-10-29 21:50:21 -07004247 if ((mEndcallBehavior
4248 & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) {
Jeff Brown26875502014-01-30 21:47:47 -08004249 mPowerManager.goToSleep(event.getEventTime());
4250 isWakeKey = false;
Jeff Brown4d396052010-10-29 21:50:21 -07004251 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004252 }
Jeff Brown4d396052010-10-29 21:50:21 -07004253 }
4254 break;
4255 }
4256
4257 case KeyEvent.KEYCODE_POWER: {
4258 result &= ~ACTION_PASS_TO_USER;
4259 if (down) {
Jeff Brown26c6a502014-04-11 02:15:54 -07004260 boolean panic = mImmersiveModeConfirmation.onPowerKeyDown(interactive,
John Spurlockd9b70bd2014-02-06 17:02:44 -05004261 event.getDownTime(), isImmersiveMode(mLastSystemUiFlags));
4262 if (panic) {
4263 mHandler.post(mRequestTransientNav);
4264 }
Jeff Brown037c33e2014-04-09 00:31:55 -07004265 if (interactive && !mPowerKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004266 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
4267 mPowerKeyTriggered = true;
4268 mPowerKeyTime = event.getDownTime();
4269 interceptScreenshotChord();
Winson Chung9112ec32011-06-27 13:15:32 -07004270 }
Winson Chung9112ec32011-06-27 13:15:32 -07004271
Santos Cordon9eb45932014-06-27 12:28:43 -07004272 TelecommManager telecommManager = getTelecommService();
Jeff Brown4d396052010-10-29 21:50:21 -07004273 boolean hungUp = false;
Santos Cordon9eb45932014-06-27 12:28:43 -07004274 if (telecommManager != null) {
4275 if (telecommManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07004276 // Pressing Power while there's a ringing incoming
4277 // call should silence the ringer.
Santos Cordon9eb45932014-06-27 12:28:43 -07004278 telecommManager.silenceRinger();
Santos Cordon6848f722014-05-21 15:22:12 -07004279 } else if ((mIncallPowerBehavior
4280 & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0
Santos Cordon9eb45932014-06-27 12:28:43 -07004281 && telecommManager.isInAPhoneCall() && interactive) {
Santos Cordon6848f722014-05-21 15:22:12 -07004282 // Otherwise, if "Power button ends call" is enabled,
4283 // the Power button will hang up any current active call.
Santos Cordon9eb45932014-06-27 12:28:43 -07004284 hungUp = telecommManager.endCall();
Jeff Brown4d396052010-10-29 21:50:21 -07004285 }
4286 }
Jeff Brown037c33e2014-04-09 00:31:55 -07004287 interceptPowerKeyDown(!interactive || hungUp
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004288 || mVolumeDownKeyTriggered || mVolumeUpKeyTriggered);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004289 } else {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004290 mPowerKeyTriggered = false;
4291 cancelPendingScreenshotChordAction();
4292 if (interceptPowerKeyUp(canceled || mPendingPowerKeyUpCanceled)) {
Jeff Brown6d8fd272014-05-20 21:24:38 -07004293 powerShortPress(event.getEventTime());
Jeff Brown26875502014-01-30 21:47:47 -08004294 isWakeKey = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004295 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004296 mPendingPowerKeyUpCanceled = false;
Jeff Brown4d396052010-10-29 21:50:21 -07004297 }
4298 break;
4299 }
4300
Jeff Brown6212a492014-03-07 13:58:47 -08004301 case KeyEvent.KEYCODE_SLEEP: {
4302 result &= ~ACTION_PASS_TO_USER;
Jeff Brownbae8e772014-06-12 19:59:45 -07004303 if (!mPowerManager.isInteractive()) {
4304 useHapticFeedback = false; // suppress feedback if already non-interactive
4305 }
Jeff Brown6212a492014-03-07 13:58:47 -08004306 mPowerManager.goToSleep(event.getEventTime());
4307 isWakeKey = false;
4308 break;
4309 }
4310
4311 case KeyEvent.KEYCODE_WAKEUP: {
4312 result &= ~ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07004313 isWakeKey = true;
Jeff Brown6212a492014-03-07 13:58:47 -08004314 break;
4315 }
4316
Jeff Brown4d396052010-10-29 21:50:21 -07004317 case KeyEvent.KEYCODE_MEDIA_PLAY:
4318 case KeyEvent.KEYCODE_MEDIA_PAUSE:
4319 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
4320 if (down) {
Santos Cordon9eb45932014-06-27 12:28:43 -07004321 TelecommManager telecommManager = getTelecommService();
4322 if (telecommManager != null) {
4323 if (telecommManager.isInAPhoneCall()) {
Santos Cordon6848f722014-05-21 15:22:12 -07004324 // Suppress PLAY/PAUSE toggle when phone is ringing or in-call
4325 // to avoid music playback.
4326 break;
Jeff Brown3122e442010-10-11 23:32:49 -07004327 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004328 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004329 }
Jeff Brown4d396052010-10-29 21:50:21 -07004330 case KeyEvent.KEYCODE_HEADSETHOOK:
4331 case KeyEvent.KEYCODE_MUTE:
4332 case KeyEvent.KEYCODE_MEDIA_STOP:
4333 case KeyEvent.KEYCODE_MEDIA_NEXT:
4334 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
4335 case KeyEvent.KEYCODE_MEDIA_REWIND:
4336 case KeyEvent.KEYCODE_MEDIA_RECORD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09004337 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
4338 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: {
Jeff Brown4d396052010-10-29 21:50:21 -07004339 if ((result & ACTION_PASS_TO_USER) == 0) {
4340 // Only do this if we would otherwise not pass it to the user. In that
4341 // case, the PhoneWindow class will do the same thing, except it will
4342 // only do it if the showing app doesn't process the key on its own.
Jeff Brown40013652012-05-16 21:22:36 -07004343 // Note that we need to make a copy of the key event here because the
4344 // original key event will be recycled when we return.
Jeff Brown4d396052010-10-29 21:50:21 -07004345 mBroadcastWakeLock.acquire();
Jeff Brown40013652012-05-16 21:22:36 -07004346 Message msg = mHandler.obtainMessage(MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK,
4347 new KeyEvent(event));
4348 msg.setAsynchronous(true);
4349 msg.sendToTarget();
Jeff Brown4d396052010-10-29 21:50:21 -07004350 }
4351 break;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004352 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004353
Jeff Brown4d396052010-10-29 21:50:21 -07004354 case KeyEvent.KEYCODE_CALL: {
4355 if (down) {
Santos Cordon9eb45932014-06-27 12:28:43 -07004356 TelecommManager telecommManager = getTelecommService();
4357 if (telecommManager != null) {
4358 if (telecommManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07004359 Log.i(TAG, "interceptKeyBeforeQueueing:"
4360 + " CALL key-down while ringing: Answer the call!");
Santos Cordon9eb45932014-06-27 12:28:43 -07004361 telecommManager.acceptRingingCall();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004362
Santos Cordon6848f722014-05-21 15:22:12 -07004363 // And *don't* pass this key thru to the current activity
4364 // (which is presumably the InCallScreen.)
4365 result &= ~ACTION_PASS_TO_USER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004366 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004367 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004368 }
Jeff Brown4d396052010-10-29 21:50:21 -07004369 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004370 }
4371 }
Jeff Brown26875502014-01-30 21:47:47 -08004372
Jeff Brownbae8e772014-06-12 19:59:45 -07004373 if (useHapticFeedback) {
4374 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
4375 }
4376
Jeff Brown26875502014-01-30 21:47:47 -08004377 if (isWakeKey) {
4378 mPowerManager.wakeUp(event.getEventTime());
4379 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004380 return result;
4381 }
4382
Jeff Brown1c2e4942012-11-06 16:32:01 -08004383 /**
4384 * When the screen is off we ignore some keys that might otherwise typically
4385 * be considered wake keys. We filter them out here.
4386 *
4387 * {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it
4388 * is always considered a wake key.
4389 */
4390 private boolean isWakeKeyWhenScreenOff(int keyCode) {
4391 switch (keyCode) {
4392 // ignore volume keys unless docked
4393 case KeyEvent.KEYCODE_VOLUME_UP:
4394 case KeyEvent.KEYCODE_VOLUME_DOWN:
4395 case KeyEvent.KEYCODE_VOLUME_MUTE:
4396 return mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED;
4397
4398 // ignore media and camera keys
4399 case KeyEvent.KEYCODE_MUTE:
4400 case KeyEvent.KEYCODE_HEADSETHOOK:
4401 case KeyEvent.KEYCODE_MEDIA_PLAY:
4402 case KeyEvent.KEYCODE_MEDIA_PAUSE:
4403 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
4404 case KeyEvent.KEYCODE_MEDIA_STOP:
4405 case KeyEvent.KEYCODE_MEDIA_NEXT:
4406 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
4407 case KeyEvent.KEYCODE_MEDIA_REWIND:
4408 case KeyEvent.KEYCODE_MEDIA_RECORD:
4409 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09004410 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK:
Jeff Brown1c2e4942012-11-06 16:32:01 -08004411 case KeyEvent.KEYCODE_CAMERA:
4412 return false;
4413 }
4414 return true;
4415 }
4416
4417
Jeff Brown56194eb2011-03-02 19:23:13 -08004418 /** {@inheritDoc} */
4419 @Override
Jeff Brown037c33e2014-04-09 00:31:55 -07004420 public int interceptWakeMotionBeforeQueueing(long whenNanos, int policyFlags) {
4421 // We already know this is a wake motion so just wake up.
4422 // Note that we would observe policyFlags containing
4423 // FLAG_WAKE and FLAG_INTERACTIVE here.
4424 mPowerManager.wakeUp(whenNanos / 1000000);
4425 return 0;
Jeff Brown56194eb2011-03-02 19:23:13 -08004426 }
4427
Jeff Brown40013652012-05-16 21:22:36 -07004428 void dispatchMediaKeyWithWakeLock(KeyEvent event) {
4429 if (DEBUG_INPUT) {
4430 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: " + event);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004431 }
4432
Jeff Brown40013652012-05-16 21:22:36 -07004433 if (mHavePendingMediaKeyRepeatWithWakeLock) {
4434 if (DEBUG_INPUT) {
4435 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: canceled repeat");
4436 }
4437
4438 mHandler.removeMessages(MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK);
4439 mHavePendingMediaKeyRepeatWithWakeLock = false;
4440 mBroadcastWakeLock.release(); // pending repeat was holding onto the wake lock
4441 }
4442
4443 dispatchMediaKeyWithWakeLockToAudioService(event);
4444
4445 if (event.getAction() == KeyEvent.ACTION_DOWN
4446 && event.getRepeatCount() == 0) {
4447 mHavePendingMediaKeyRepeatWithWakeLock = true;
4448
4449 Message msg = mHandler.obtainMessage(
4450 MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK, event);
4451 msg.setAsynchronous(true);
4452 mHandler.sendMessageDelayed(msg, ViewConfiguration.getKeyRepeatTimeout());
4453 } else {
4454 mBroadcastWakeLock.release();
4455 }
4456 }
4457
4458 void dispatchMediaKeyRepeatWithWakeLock(KeyEvent event) {
4459 mHavePendingMediaKeyRepeatWithWakeLock = false;
4460
4461 KeyEvent repeatEvent = KeyEvent.changeTimeRepeat(event,
4462 SystemClock.uptimeMillis(), 1, event.getFlags() | KeyEvent.FLAG_LONG_PRESS);
4463 if (DEBUG_INPUT) {
4464 Slog.d(TAG, "dispatchMediaKeyRepeatWithWakeLock: " + repeatEvent);
4465 }
4466
4467 dispatchMediaKeyWithWakeLockToAudioService(repeatEvent);
4468 mBroadcastWakeLock.release();
4469 }
4470
4471 void dispatchMediaKeyWithWakeLockToAudioService(KeyEvent event) {
4472 if (ActivityManagerNative.isSystemReady()) {
RoboErik430fc482014-06-12 15:49:20 -07004473 MediaSessionLegacyHelper.getHelper(mContext).sendMediaButtonEvent(event, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004474 }
4475 }
4476
Mike Lockwood1753f7f2009-08-24 14:49:07 -07004477 BroadcastReceiver mDockReceiver = new BroadcastReceiver() {
Craig Mautnereee29c42013-01-17 14:44:34 -08004478 @Override
Mike Lockwood1753f7f2009-08-24 14:49:07 -07004479 public void onReceive(Context context, Intent intent) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07004480 if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) {
4481 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
4482 Intent.EXTRA_DOCK_STATE_UNDOCKED);
Daniel Sandler6396c722013-04-16 20:19:09 -04004483 } else {
4484 try {
4485 IUiModeManager uiModeService = IUiModeManager.Stub.asInterface(
4486 ServiceManager.getService(Context.UI_MODE_SERVICE));
4487 mUiMode = uiModeService.getCurrentModeType();
4488 } catch (RemoteException e) {
4489 }
Dianne Hackborn80fa1662009-10-07 14:02:10 -07004490 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004491 updateRotation(true);
Craig Mautnereee29c42013-01-17 14:44:34 -08004492 synchronized (mLock) {
4493 updateOrientationListenerLp();
4494 }
Mike Lockwood1753f7f2009-08-24 14:49:07 -07004495 }
4496 };
4497
Jeff Brown6aaf2952012-10-05 16:01:08 -07004498 BroadcastReceiver mDreamReceiver = new BroadcastReceiver() {
4499 @Override
4500 public void onReceive(Context context, Intent intent) {
4501 if (Intent.ACTION_DREAMING_STARTED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004502 if (mKeyguardDelegate != null) {
4503 mKeyguardDelegate.onDreamingStarted();
Jeff Brown6aaf2952012-10-05 16:01:08 -07004504 }
4505 } else if (Intent.ACTION_DREAMING_STOPPED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004506 if (mKeyguardDelegate != null) {
4507 mKeyguardDelegate.onDreamingStopped();
Jeff Brown6aaf2952012-10-05 16:01:08 -07004508 }
4509 }
4510 }
4511 };
4512
Christopher Tate5e08af02012-09-21 17:17:22 -07004513 BroadcastReceiver mMultiuserReceiver = new BroadcastReceiver() {
4514 @Override
4515 public void onReceive(Context context, Intent intent) {
4516 if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) {
4517 // tickle the settings observer: this first ensures that we're
4518 // observing the relevant settings for the newly-active user,
4519 // and then updates our own bookkeeping based on the now-
4520 // current user.
4521 mSettingsObserver.onChange(false);
John Spurlockce479d82012-11-29 09:52:21 -05004522
4523 // force a re-application of focused window sysui visibility.
4524 // the window may never have been shown for this user
4525 // e.g. the keyguard when going through the new-user setup flow
John Spurlock04db1762013-05-13 12:46:41 -04004526 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
John Spurlockce479d82012-11-29 09:52:21 -05004527 mLastSystemUiFlags = 0;
4528 updateSystemUiVisibilityLw();
4529 }
Christopher Tate5e08af02012-09-21 17:17:22 -07004530 }
4531 }
4532 };
4533
John Spurlockd9b70bd2014-02-06 17:02:44 -05004534 private final Runnable mRequestTransientNav = new Runnable() {
4535 @Override
4536 public void run() {
4537 requestTransientBars(mNavigationBar);
4538 }
4539 };
4540
John Spurlocke1f366f2013-08-05 12:22:40 -04004541 private void requestTransientBars(WindowState swipeTarget) {
John Spurlock04db1762013-05-13 12:46:41 -04004542 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Maurice Lam99c6e072014-04-28 18:24:28 -07004543 if (!isUserSetupComplete()) {
4544 // Swipe-up for navigation bar is disabled during setup
4545 return;
4546 }
John Spurlock27735a42013-08-14 17:57:38 -04004547 boolean sb = mStatusBarController.checkShowTransientBarLw();
4548 boolean nb = mNavigationBarController.checkShowTransientBarLw();
John Spurlockad3e6cb2013-04-30 08:47:43 -04004549 if (sb || nb) {
John Spurlocke1f366f2013-08-05 12:22:40 -04004550 WindowState barTarget = sb ? mStatusBar : mNavigationBar;
4551 if (sb ^ nb && barTarget != swipeTarget) {
4552 if (DEBUG) Slog.d(TAG, "Not showing transient bar, wrong swipe target");
John Spurlockad3e6cb2013-04-30 08:47:43 -04004553 return;
4554 }
John Spurlock27735a42013-08-14 17:57:38 -04004555 if (sb) mStatusBarController.showTransient();
4556 if (nb) mNavigationBarController.showTransient();
John Spurlockf1a36642013-10-12 17:50:42 -04004557 mImmersiveModeConfirmation.confirmCurrentPrompt();
John Spurlockad3e6cb2013-04-30 08:47:43 -04004558 updateSystemUiVisibilityLw();
John Spurlock32beb2c2013-03-11 10:16:47 -04004559 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04004560 }
4561 }
4562
Jeff Brownc38c9be2012-10-04 13:16:19 -07004563 @Override
Jeff Brown140ffc72014-05-01 15:18:00 -07004564 public void goingToSleep(int why) {
Dianne Hackborn74489012009-03-24 20:50:09 -07004565 EventLog.writeEvent(70000, 0);
The Android Open Source Project0727d222009-03-11 12:11:58 -07004566 synchronized (mLock) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004567 mScreenOnEarly = false;
4568 mScreenOnFully = false;
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07004569 }
Jim Miller5ecd8112013-01-09 18:50:26 -08004570 if (mKeyguardDelegate != null) {
4571 mKeyguardDelegate.onScreenTurnedOff(why);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004572 }
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07004573 synchronized (mLock) {
Jeff Browna20dda42014-05-27 20:57:24 -07004574 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07004575 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05004576 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07004577 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004578 }
4579
Jeff Brownc38c9be2012-10-04 13:16:19 -07004580 @Override
Jeff Brown140ffc72014-05-01 15:18:00 -07004581 public void wakingUp(final ScreenOnListener screenOnListener) {
Dianne Hackborn74489012009-03-24 20:50:09 -07004582 EventLog.writeEvent(70000, 1);
Craig Mautner8a0da012014-05-31 15:13:37 -07004583 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turning on...",
4584 new RuntimeException("here").fillInStackTrace());
4585 mHandler.obtainMessage(MSG_WAKING_UP, screenOnListener).sendToTarget();
4586 }
4587
4588 // Called on the mHandler thread.
4589 private void handleWakingUp(final ScreenOnListener screenOnListener) {
4590 if (screenOnListener != null) {
Craig Mautner13f6ea72014-06-23 14:57:02 -07004591 mScreenOnListener = screenOnListener;
Dianne Hackborn40011092011-09-22 13:37:48 -07004592 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07004593
The Android Open Source Project0727d222009-03-11 12:11:58 -07004594 synchronized (mLock) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004595 mScreenOnEarly = true;
Jeff Browna20dda42014-05-27 20:57:24 -07004596 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07004597 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05004598 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07004599 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07004600
Craig Mautner8a0da012014-05-31 15:13:37 -07004601 mKeyguardDrawComplete = false;
4602 mWindowManagerDrawComplete = false;
Jim Miller5ecd8112013-01-09 18:50:26 -08004603 if (mKeyguardDelegate != null) {
Craig Mautner8a0da012014-05-31 15:13:37 -07004604 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
4605 mHandler.sendEmptyMessageDelayed(MSG_KEYGUARD_DRAWN_TIMEOUT, 1000);
4606 mKeyguardDelegate.onScreenTurnedOn(mKeyguardDelegateCallback);
Jeff Brownc38c9be2012-10-04 13:16:19 -07004607 } else {
Craig Mautner8a0da012014-05-31 15:13:37 -07004608 if (DEBUG_WAKEUP) Slog.d(TAG, "null mKeyguardDelegate: setting mKeyguardDrawComplete.");
4609 mKeyguardDrawComplete = true;
Jeff Brownc38c9be2012-10-04 13:16:19 -07004610 }
Craig Mautner8a0da012014-05-31 15:13:37 -07004611 mWindowManagerInternal.waitForAllWindowsDrawn(mWindowManagerDrawCallback, 500);
Jeff Brownc38c9be2012-10-04 13:16:19 -07004612 }
4613
Craig Mautner8a0da012014-05-31 15:13:37 -07004614 // Called on the mHandler thread.
4615 private void finishScreenTurningOn() {
4616 if (DEBUG_WAKEUP) Slog.d(TAG,
4617 "finishScreenTurningOn: mKeyguardDrawComplete=" + mKeyguardDrawComplete
4618 + " mWindowManagerDrawComplete=" + mWindowManagerDrawComplete);
4619 if (!mKeyguardDrawComplete || !mWindowManagerDrawComplete) {
4620 return;
Jeff Brownc38c9be2012-10-04 13:16:19 -07004621 }
4622
Craig Mautner13f6ea72014-06-23 14:57:02 -07004623 ScreenOnListener screenOnListener;
Jeff Brownc38c9be2012-10-04 13:16:19 -07004624 synchronized (mLock) {
4625 mScreenOnFully = true;
Craig Mautner13f6ea72014-06-23 14:57:02 -07004626 screenOnListener = mScreenOnListener;
4627 mScreenOnListener = null;
Jeff Brownc38c9be2012-10-04 13:16:19 -07004628 }
4629
Jeff Brown4fc45272012-10-10 18:28:14 -07004630 try {
4631 mWindowManager.setEventDispatching(true);
4632 } catch (RemoteException unhandled) {
4633 }
4634
Craig Mautner13f6ea72014-06-23 14:57:02 -07004635 if (screenOnListener != null) {
4636 screenOnListener.onScreenOn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07004637 }
Craig Mautner8a0da012014-05-31 15:13:37 -07004638
4639 setKeyguardDrawn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07004640 }
4641
4642 @Override
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004643 public boolean isScreenOnEarly() {
4644 return mScreenOnEarly;
4645 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07004646
4647 @Override
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004648 public boolean isScreenOnFully() {
4649 return mScreenOnFully;
Dianne Hackborn08743722009-12-21 12:16:51 -08004650 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07004651
Dianne Hackborn08743722009-12-21 12:16:51 -08004652 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07004653 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004654 public void enableKeyguard(boolean enabled) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004655 if (mKeyguardDelegate != null) {
4656 mKeyguardDelegate.setKeyguardEnabled(enabled);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004657 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004658 }
4659
4660 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07004661 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004662 public void exitKeyguardSecurely(OnKeyguardExitResult callback) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004663 if (mKeyguardDelegate != null) {
4664 mKeyguardDelegate.verifyUnlock(callback);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004665 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004666 }
4667
Mike Lockwoodf7913302009-11-28 22:27:10 -05004668 private boolean keyguardIsShowingTq() {
Jim Miller5ecd8112013-01-09 18:50:26 -08004669 if (mKeyguardDelegate == null) return false;
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004670 return mKeyguardDelegate.isShowingAndNotOccluded();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004671 }
4672
Mike Lockwood520d8bc2011-02-18 13:23:13 -05004673
4674 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07004675 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05004676 public boolean isKeyguardLocked() {
4677 return keyguardOn();
4678 }
4679
4680 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07004681 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05004682 public boolean isKeyguardSecure() {
Jim Miller5ecd8112013-01-09 18:50:26 -08004683 if (mKeyguardDelegate == null) return false;
4684 return mKeyguardDelegate.isSecure();
Mike Lockwood520d8bc2011-02-18 13:23:13 -05004685 }
4686
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004687 // Returns true if keyguard is currently locked whether or not it is currently hidden.
4688 private boolean isKeyguardSecureIncludingHidden() {
4689 return mKeyguardDelegate.isSecure() && mKeyguardDelegate.isShowing();
4690 }
4691
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004692 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07004693 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004694 public boolean inKeyguardRestrictedKeyInputMode() {
Jim Miller5ecd8112013-01-09 18:50:26 -08004695 if (mKeyguardDelegate == null) return false;
4696 return mKeyguardDelegate.isInputRestricted();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004697 }
4698
Jose Lima9546b202014-07-02 17:21:51 -07004699 @Override
Dianne Hackborn90c52de2011-09-23 12:57:44 -07004700 public void dismissKeyguardLw() {
RoboErik8a2cfc32014-05-16 11:19:38 -07004701 if (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()) {
Daniel Sandler1ce804392012-11-07 15:07:12 -05004702 mHandler.post(new Runnable() {
Jose Lima9546b202014-07-02 17:21:51 -07004703 @Override
Daniel Sandler1ce804392012-11-07 15:07:12 -05004704 public void run() {
Jim Miller5ecd8112013-01-09 18:50:26 -08004705 if (mKeyguardDelegate.isDismissable()) {
Daniel Sandler1ce804392012-11-07 15:07:12 -05004706 // Can we just finish the keyguard straight away?
Jim Miller5ecd8112013-01-09 18:50:26 -08004707 mKeyguardDelegate.keyguardDone(false, true);
Daniel Sandler1ce804392012-11-07 15:07:12 -05004708 } else {
4709 // ask the keyguard to prompt the user to authenticate if necessary
Jim Miller5ecd8112013-01-09 18:50:26 -08004710 mKeyguardDelegate.dismiss();
Dianne Hackborn90c52de2011-09-23 12:57:44 -07004711 }
Daniel Sandler1ce804392012-11-07 15:07:12 -05004712 }
4713 });
Dianne Hackborn90c52de2011-09-23 12:57:44 -07004714 }
4715 }
4716
Jorim Jaggicff0acb2014-03-31 16:35:15 +02004717 private void setKeyguardDrawn() {
4718 synchronized (mLock) {
4719 mKeyguardDrawn = true;
4720 }
4721 try {
4722 mWindowManager.enableScreenIfNeeded();
4723 } catch (RemoteException unhandled) {
4724 }
4725 }
4726
4727 @Override
4728 public boolean isKeyguardDrawnLw() {
4729 synchronized (mLock) {
4730 return mKeyguardDrawn;
4731 }
4732 }
4733
Jorim Jaggi0d674622014-05-21 01:34:15 +02004734 @Override
Jorim Jaggie29b2db2014-05-30 23:17:03 +02004735 public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) {
Jorim Jaggi0d674622014-05-21 01:34:15 +02004736 if (mKeyguardDelegate != null) {
Jorim Jaggie29b2db2014-05-30 23:17:03 +02004737 mKeyguardDelegate.startKeyguardExitAnimation(startTime, fadeoutDuration);
Jorim Jaggi0d674622014-05-21 01:34:15 +02004738 }
4739 }
4740
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004741 void sendCloseSystemWindows() {
4742 sendCloseSystemWindows(mContext, null);
4743 }
4744
4745 void sendCloseSystemWindows(String reason) {
4746 sendCloseSystemWindows(mContext, reason);
4747 }
4748
4749 static void sendCloseSystemWindows(Context context, String reason) {
4750 if (ActivityManagerNative.isSystemReady()) {
Dianne Hackborn94a679d2009-07-28 17:51:07 -07004751 try {
4752 ActivityManagerNative.getDefault().closeSystemDialogs(reason);
4753 } catch (RemoteException e) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004754 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004755 }
4756 }
Mitsuru Oshima831d0d92009-06-16 18:27:18 -07004757
Jeff Brown01a98dd2011-09-20 15:08:29 -07004758 @Override
4759 public int rotationForOrientationLw(int orientation, int lastRotation) {
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05004760 if (false) {
4761 Slog.v(TAG, "rotationForOrientationLw(orient="
4762 + orientation + ", last=" + lastRotation
4763 + "); user=" + mUserRotation + " "
4764 + ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED)
4765 ? "USER_ROTATION_LOCKED" : "")
4766 );
4767 }
4768
Craig Mautner46ac6fa2013-08-01 10:06:34 -07004769 if (mForceDefaultOrientation) {
4770 return Surface.ROTATION_0;
4771 }
4772
The Android Open Source Project0727d222009-03-11 12:11:58 -07004773 synchronized (mLock) {
Jeff Brownc0347aa2011-09-23 17:26:09 -07004774 int sensorRotation = mOrientationListener.getProposedRotation(); // may be -1
4775 if (sensorRotation < 0) {
Jeff Brown0f862b42012-09-27 21:11:01 -07004776 sensorRotation = lastRotation;
Jeff Brownc0347aa2011-09-23 17:26:09 -07004777 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004778
Jeff Browndec6cf42011-11-15 14:08:20 -08004779 final int preferredRotation;
Jeff Brown2e7760e2012-04-11 15:14:55 -07004780 if (mLidState == LID_OPEN && mLidOpenRotation >= 0) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07004781 // Ignore sensor when lid switch is open and rotation is forced.
4782 preferredRotation = mLidOpenRotation;
4783 } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR
Jeff Brownc0347aa2011-09-23 17:26:09 -07004784 && (mCarDockEnablesAccelerometer || mCarDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07004785 // Ignore sensor when in car dock unless explicitly enabled.
4786 // This case can override the behavior of NOSENSOR, and can also
4787 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07004788 preferredRotation = mCarDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07004789 ? sensorRotation : mCarDockRotation;
Jeff Brown1a693182011-11-08 14:44:16 -08004790 } else if ((mDockMode == Intent.EXTRA_DOCK_STATE_DESK
4791 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
4792 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK)
Jeff Brownc0347aa2011-09-23 17:26:09 -07004793 && (mDeskDockEnablesAccelerometer || mDeskDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07004794 // Ignore sensor when in desk dock unless explicitly enabled.
4795 // This case can override the behavior of NOSENSOR, and can also
4796 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07004797 preferredRotation = mDeskDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07004798 ? sensorRotation : mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -07004799 } else if (mHdmiPlugged && mDemoHdmiRotationLock) {
4800 // Ignore sensor when plugged into HDMI when demo HDMI rotation lock enabled.
Jeff Browneb3e4b92011-12-06 19:54:24 -08004801 // Note that the dock orientation overrides the HDMI orientation.
Jeff Brownc82c89ed2013-04-17 17:18:15 -07004802 preferredRotation = mDemoHdmiRotation;
4803 } else if (mHdmiPlugged && mDockMode == Intent.EXTRA_DOCK_STATE_UNDOCKED
4804 && mUndockedHdmiRotation >= 0) {
4805 // Ignore sensor when plugged into HDMI and an undocked orientation has
4806 // been specified in the configuration (only for legacy devices without
4807 // full multi-display support).
4808 // Note that the dock orientation overrides the HDMI orientation.
4809 preferredRotation = mUndockedHdmiRotation;
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07004810 } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED) {
4811 // Application just wants to remain locked in the last rotation.
4812 preferredRotation = lastRotation;
Jeff Brownbcdfc622014-03-06 19:13:04 -08004813 } else if (!mSupportAutoRotation) {
4814 // If we don't support auto-rotation then bail out here and ignore
4815 // the sensor and any rotation lock settings.
4816 preferredRotation = -1;
Jeff Brown207673cd2012-06-05 17:47:11 -07004817 } else if ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE
Jeff Brown01a98dd2011-09-20 15:08:29 -07004818 && (orientation == ActivityInfo.SCREEN_ORIENTATION_USER
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07004819 || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
4820 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
4821 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
4822 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER))
Jeff Brown01a98dd2011-09-20 15:08:29 -07004823 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
4824 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
4825 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
4826 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) {
4827 // Otherwise, use sensor only if requested by the application or enabled
4828 // by default for USER or UNSPECIFIED modes. Does not apply to NOSENSOR.
Jeff Brownd3187e32011-09-21 19:26:44 -07004829 if (mAllowAllRotations < 0) {
4830 // Can't read this during init() because the context doesn't
4831 // have display metrics at that time so we cannot determine
4832 // tablet vs. phone then.
4833 mAllowAllRotations = mContext.getResources().getBoolean(
4834 com.android.internal.R.bool.config_allowAllRotations) ? 1 : 0;
4835 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004836 if (sensorRotation != Surface.ROTATION_180
Jeff Brownd3187e32011-09-21 19:26:44 -07004837 || mAllowAllRotations == 1
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07004838 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
4839 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07004840 preferredRotation = sensorRotation;
4841 } else {
4842 preferredRotation = lastRotation;
4843 }
Jeff Brown207673cd2012-06-05 17:47:11 -07004844 } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED
4845 && orientation != ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) {
4846 // Apply rotation lock. Does not apply to NOSENSOR.
4847 // The idea is that the user rotation expresses a weak preference for the direction
4848 // of gravity and as NOSENSOR is never affected by gravity, then neither should
4849 // NOSENSOR be affected by rotation lock (although it will be affected by docks).
Jeff Brown4dfce202011-10-05 12:00:10 -07004850 preferredRotation = mUserRotation;
Jeff Browndec6cf42011-11-15 14:08:20 -08004851 } else {
4852 // No overriding preference.
4853 // We will do exactly what the application asked us to do.
4854 preferredRotation = -1;
Jeff Brown01a98dd2011-09-20 15:08:29 -07004855 }
4856
Dianne Hackborne5439f22010-10-02 16:53:50 -07004857 switch (orientation) {
4858 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08004859 // Return portrait unless overridden.
4860 if (isAnyPortrait(preferredRotation)) {
4861 return preferredRotation;
4862 }
Dianne Hackborne5439f22010-10-02 16:53:50 -07004863 return mPortraitRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07004864
Jeff Brown01a98dd2011-09-20 15:08:29 -07004865 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08004866 // Return landscape unless overridden.
4867 if (isLandscapeOrSeascape(preferredRotation)) {
4868 return preferredRotation;
4869 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004870 return mLandscapeRotation;
4871
4872 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08004873 // Return reverse portrait unless overridden.
4874 if (isAnyPortrait(preferredRotation)) {
4875 return preferredRotation;
4876 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004877 return mUpsideDownRotation;
4878
4879 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08004880 // Return seascape unless overridden.
4881 if (isLandscapeOrSeascape(preferredRotation)) {
4882 return preferredRotation;
4883 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004884 return mSeascapeRotation;
4885
4886 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07004887 case ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE:
Jeff Brown01a98dd2011-09-20 15:08:29 -07004888 // Return either landscape rotation.
4889 if (isLandscapeOrSeascape(preferredRotation)) {
4890 return preferredRotation;
4891 }
4892 if (isLandscapeOrSeascape(lastRotation)) {
Jeff Brown4519f072011-01-23 13:16:01 -08004893 return lastRotation;
4894 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004895 return mLandscapeRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004896
Jeff Brown01a98dd2011-09-20 15:08:29 -07004897 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07004898 case ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT:
Jeff Brown01a98dd2011-09-20 15:08:29 -07004899 // Return either portrait rotation.
4900 if (isAnyPortrait(preferredRotation)) {
4901 return preferredRotation;
4902 }
4903 if (isAnyPortrait(lastRotation)) {
4904 return lastRotation;
4905 }
4906 return mPortraitRotation;
4907
4908 default:
Jeff Brown4dfce202011-10-05 12:00:10 -07004909 // For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR,
4910 // just return the preferred orientation we already calculated.
Jeff Brown01a98dd2011-09-20 15:08:29 -07004911 if (preferredRotation >= 0) {
4912 return preferredRotation;
4913 }
Dianne Hackborndacea8c2011-04-21 17:26:39 -07004914 return Surface.ROTATION_0;
Daniel Sandlere7e5ac22011-02-22 16:10:21 -05004915 }
4916 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07004917 }
4918
Jeff Brown01a98dd2011-09-20 15:08:29 -07004919 @Override
4920 public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation) {
4921 switch (orientation) {
4922 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
4923 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
4924 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
4925 return isAnyPortrait(rotation);
4926
4927 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
4928 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
4929 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
4930 return isLandscapeOrSeascape(rotation);
4931
4932 default:
4933 return true;
4934 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07004935 }
4936
Jeff Brownc0347aa2011-09-23 17:26:09 -07004937 @Override
4938 public void setRotationLw(int rotation) {
4939 mOrientationListener.setCurrentRotation(rotation);
4940 }
4941
Jeff Brown01a98dd2011-09-20 15:08:29 -07004942 private boolean isLandscapeOrSeascape(int rotation) {
4943 return rotation == mLandscapeRotation || rotation == mSeascapeRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07004944 }
4945
Jeff Brown01a98dd2011-09-20 15:08:29 -07004946 private boolean isAnyPortrait(int rotation) {
4947 return rotation == mPortraitRotation || rotation == mUpsideDownRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07004948 }
4949
Jose Lima9546b202014-07-02 17:21:51 -07004950 @Override
Svetoslav Ganov80943d82013-01-02 10:25:37 -08004951 public int getUserRotationMode() {
4952 return Settings.System.getIntForUser(mContext.getContentResolver(),
Brett Chabot7e55c402013-05-16 19:38:08 -07004953 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
4954 WindowManagerPolicy.USER_ROTATION_FREE :
4955 WindowManagerPolicy.USER_ROTATION_LOCKED;
Svetoslav Ganov80943d82013-01-02 10:25:37 -08004956 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004957
4958 // User rotation: to be used when all else fails in assigning an orientation to the device
Jose Lima9546b202014-07-02 17:21:51 -07004959 @Override
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004960 public void setUserRotationMode(int mode, int rot) {
4961 ContentResolver res = mContext.getContentResolver();
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05004962
4963 // mUserRotationMode and mUserRotation will be assigned by the content observer
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004964 if (mode == WindowManagerPolicy.USER_ROTATION_LOCKED) {
Christopher Tate5e08af02012-09-21 17:17:22 -07004965 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004966 Settings.System.USER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07004967 rot,
4968 UserHandle.USER_CURRENT);
4969 Settings.System.putIntForUser(res,
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05004970 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07004971 0,
4972 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004973 } else {
Christopher Tate5e08af02012-09-21 17:17:22 -07004974 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004975 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07004976 1,
4977 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004978 }
4979 }
4980
Jose Lima9546b202014-07-02 17:21:51 -07004981 @Override
Jeff Brownac143512012-04-05 18:57:33 -07004982 public void setSafeMode(boolean safeMode) {
4983 mSafeMode = safeMode;
4984 performHapticFeedbackLw(null, safeMode
4985 ? HapticFeedbackConstants.SAFE_MODE_ENABLED
4986 : HapticFeedbackConstants.SAFE_MODE_DISABLED, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004987 }
Craig Mautnereda67292013-04-28 13:50:14 -07004988
Dianne Hackborn181ceb52009-08-27 22:16:40 -07004989 static long[] getLongIntArray(Resources r, int resid) {
4990 int[] ar = r.getIntArray(resid);
4991 if (ar == null) {
4992 return null;
4993 }
4994 long[] out = new long[ar.length];
4995 for (int i=0; i<ar.length; i++) {
4996 out[i] = ar[i];
4997 }
4998 return out;
4999 }
Craig Mautnereda67292013-04-28 13:50:14 -07005000
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005001 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07005002 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005003 public void systemReady() {
Mike Lockwooded8902d2013-11-15 11:01:47 -08005004 mKeyguardDelegate = new KeyguardServiceDelegate(mContext, null);
5005 mKeyguardDelegate.onSystemReady();
5006
Jeff Brown4f5fa282014-06-12 19:19:15 -07005007 updateUiMode();
Dianne Hackbornb1a79802009-09-29 15:18:31 -07005008 synchronized (mLock) {
5009 updateOrientationListenerLp();
Dianne Hackbornc777e072010-02-12 13:07:59 -08005010 mSystemReady = true;
5011 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07005012 @Override
Dianne Hackbornc777e072010-02-12 13:07:59 -08005013 public void run() {
5014 updateSettings();
5015 }
5016 });
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005017 }
5018 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07005019
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005020 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005021 @Override
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005022 public void systemBooted() {
Jim Millere5f910a2013-10-16 18:15:46 -07005023 if (mKeyguardDelegate != null) {
5024 mKeyguardDelegate.onBootCompleted();
5025 }
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005026 synchronized (mLock) {
5027 mSystemBooted = true;
5028 }
Craig Mautner8a0da012014-05-31 15:13:37 -07005029 wakingUp(null);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005030 }
5031
Dianne Hackborn661cd522011-08-22 00:26:20 -07005032 ProgressDialog mBootMsgDialog = null;
5033
5034 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005035 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07005036 public void showBootMessage(final CharSequence msg, final boolean always) {
5037 mHandler.post(new Runnable() {
5038 @Override public void run() {
5039 if (mBootMsgDialog == null) {
Craig Stout4c0cb8a2014-04-04 13:03:10 -07005040 int theme;
5041 if (mContext.getPackageManager().hasSystemFeature(
5042 PackageManager.FEATURE_WATCH)) {
5043 theme = com.android.internal.R.style.Theme_Micro_Dialog_Alert;
5044 } else if (mContext.getPackageManager().hasSystemFeature(
5045 PackageManager.FEATURE_TELEVISION)) {
5046 theme = com.android.internal.R.style.Theme_Leanback_Dialog_Alert;
5047 } else {
5048 theme = 0;
5049 }
Vinod Krishnanfa8fc412014-04-18 14:35:53 -07005050
5051 mBootMsgDialog = new ProgressDialog(mContext, theme) {
Dianne Hackborn295e3c22011-08-25 13:19:08 -07005052 // This dialog will consume all events coming in to
5053 // it, to avoid it trying to do things too early in boot.
5054 @Override public boolean dispatchKeyEvent(KeyEvent event) {
5055 return true;
5056 }
5057 @Override public boolean dispatchKeyShortcutEvent(KeyEvent event) {
5058 return true;
5059 }
5060 @Override public boolean dispatchTouchEvent(MotionEvent ev) {
5061 return true;
5062 }
5063 @Override public boolean dispatchTrackballEvent(MotionEvent ev) {
5064 return true;
5065 }
5066 @Override public boolean dispatchGenericMotionEvent(MotionEvent ev) {
5067 return true;
5068 }
5069 @Override public boolean dispatchPopulateAccessibilityEvent(
5070 AccessibilityEvent event) {
5071 return true;
5072 }
5073 };
Dianne Hackborn661cd522011-08-22 00:26:20 -07005074 mBootMsgDialog.setTitle(R.string.android_upgrading_title);
5075 mBootMsgDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
5076 mBootMsgDialog.setIndeterminate(true);
5077 mBootMsgDialog.getWindow().setType(
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07005078 WindowManager.LayoutParams.TYPE_BOOT_PROGRESS);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005079 mBootMsgDialog.getWindow().addFlags(
5080 WindowManager.LayoutParams.FLAG_DIM_BEHIND
5081 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
5082 mBootMsgDialog.getWindow().setDimAmount(1);
Dianne Hackbornd9efb952011-12-07 14:56:51 -08005083 WindowManager.LayoutParams lp = mBootMsgDialog.getWindow().getAttributes();
5084 lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
5085 mBootMsgDialog.getWindow().setAttributes(lp);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005086 mBootMsgDialog.setCancelable(false);
5087 mBootMsgDialog.show();
5088 }
5089 mBootMsgDialog.setMessage(msg);
5090 }
5091 });
5092 }
5093
5094 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005095 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07005096 public void hideBootMessages() {
5097 mHandler.post(new Runnable() {
5098 @Override public void run() {
5099 if (mBootMsgDialog != null) {
5100 mBootMsgDialog.dismiss();
5101 mBootMsgDialog = null;
5102 }
5103 }
5104 });
5105 }
5106
Mike Lockwood28569302010-01-28 11:54:40 -05005107 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005108 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05005109 public void userActivity() {
Dianne Hackborndf89e652011-10-06 22:35:11 -07005110 // ***************************************
5111 // NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
5112 // ***************************************
5113 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
5114 // WITH ITS LOCKS HELD.
5115 //
5116 // This code must be VERY careful about the locks
5117 // it acquires.
5118 // In fact, the current code acquires way too many,
5119 // and probably has lurking deadlocks.
5120
Mike Lockwood28569302010-01-28 11:54:40 -05005121 synchronized (mScreenLockTimeout) {
5122 if (mLockScreenTimerActive) {
5123 // reset the timer
5124 mHandler.removeCallbacks(mScreenLockTimeout);
5125 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
5126 }
5127 }
Daniel Sandler0601eb72011-04-13 01:01:32 -04005128 }
5129
Adam Cohenf7522022012-10-03 20:03:18 -07005130 class ScreenLockTimeout implements Runnable {
5131 Bundle options;
5132
5133 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05005134 public void run() {
5135 synchronized (this) {
5136 if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard");
Jim Miller5ecd8112013-01-09 18:50:26 -08005137 if (mKeyguardDelegate != null) {
5138 mKeyguardDelegate.doKeyguardTimeout(options);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005139 }
Mike Lockwood28569302010-01-28 11:54:40 -05005140 mLockScreenTimerActive = false;
Adam Cohenf7522022012-10-03 20:03:18 -07005141 options = null;
Mike Lockwood28569302010-01-28 11:54:40 -05005142 }
5143 }
Mike Lockwood28569302010-01-28 11:54:40 -05005144
Adam Cohenf7522022012-10-03 20:03:18 -07005145 public void setLockOptions(Bundle options) {
5146 this.options = options;
5147 }
5148 }
5149
5150 ScreenLockTimeout mScreenLockTimeout = new ScreenLockTimeout();
5151
Jose Lima9546b202014-07-02 17:21:51 -07005152 @Override
Adam Cohenf7522022012-10-03 20:03:18 -07005153 public void lockNow(Bundle options) {
Jim Miller93c518e2012-01-17 15:55:31 -08005154 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null);
5155 mHandler.removeCallbacks(mScreenLockTimeout);
Adam Cohenf7522022012-10-03 20:03:18 -07005156 if (options != null) {
5157 // In case multiple calls are made to lockNow, we don't wipe out the options
5158 // until the runnable actually executes.
5159 mScreenLockTimeout.setLockOptions(options);
5160 }
Jim Miller93c518e2012-01-17 15:55:31 -08005161 mHandler.post(mScreenLockTimeout);
5162 }
5163
Mike Lockwood28569302010-01-28 11:54:40 -05005164 private void updateLockScreenTimeout() {
5165 synchronized (mScreenLockTimeout) {
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005166 boolean enable = (mAllowLockscreenWhenOn && mScreenOnEarly &&
Jim Miller5ecd8112013-01-09 18:50:26 -08005167 mKeyguardDelegate != null && mKeyguardDelegate.isSecure());
Mike Lockwood28569302010-01-28 11:54:40 -05005168 if (mLockScreenTimerActive != enable) {
5169 if (enable) {
5170 if (localLOGV) Log.v(TAG, "setting lockscreen timer");
5171 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
5172 } else {
5173 if (localLOGV) Log.v(TAG, "clearing lockscreen timer");
5174 mHandler.removeCallbacks(mScreenLockTimeout);
5175 }
5176 mLockScreenTimerActive = enable;
5177 }
5178 }
5179 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005180
5181 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07005182 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005183 public void enableScreenAfterBoot() {
5184 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07005185 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07005186 updateRotation(true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005187 }
Dianne Hackbornf54c8f92009-09-19 14:03:57 -07005188
Jeff Brownc458ce92012-04-30 14:58:40 -07005189 private void applyLidSwitchState() {
Jeff Brownc458ce92012-04-30 14:58:40 -07005190 if (mLidState == LID_CLOSED && mLidControlsSleep) {
Jeff Brown6d8fd272014-05-20 21:24:38 -07005191 mPowerManager.goToSleep(SystemClock.uptimeMillis(),
5192 PowerManager.GO_TO_SLEEP_REASON_USER,
5193 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
Jeff Brownc458ce92012-04-30 14:58:40 -07005194 }
Jeff Browna20dda42014-05-27 20:57:24 -07005195
5196 synchronized (mLock) {
5197 updateWakeGestureListenerLp();
5198 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005199 }
5200
Jeff Brown4f5fa282014-06-12 19:19:15 -07005201 void updateUiMode() {
5202 if (mUiModeManager == null) {
5203 mUiModeManager = IUiModeManager.Stub.asInterface(
5204 ServiceManager.getService(Context.UI_MODE_SERVICE));
5205 }
5206 try {
5207 mUiMode = mUiModeManager.getCurrentModeType();
5208 } catch (RemoteException e) {
5209 }
5210 }
5211
Jeff Brown01a98dd2011-09-20 15:08:29 -07005212 void updateRotation(boolean alwaysSendConfiguration) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005213 try {
5214 //set orientation on WindowManager
Dianne Hackbornf87d1962012-04-04 12:48:24 -07005215 mWindowManager.updateRotation(alwaysSendConfiguration, false);
5216 } catch (RemoteException e) {
5217 // Ignore
5218 }
5219 }
5220
5221 void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) {
5222 try {
5223 //set orientation on WindowManager
5224 mWindowManager.updateRotation(alwaysSendConfiguration, forceRelayout);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005225 } catch (RemoteException e) {
5226 // Ignore
5227 }
5228 }
5229
Daniel Sandler6396c722013-04-16 20:19:09 -04005230 /**
5231 * Return an Intent to launch the currently active dock app as home. Returns
5232 * null if the standard home should be launched, which is the case if any of the following is
5233 * true:
5234 * <ul>
5235 * <li>The device is not in either car mode or desk mode
5236 * <li>The device is in car mode but ENABLE_CAR_DOCK_HOME_CAPTURE is false
5237 * <li>The device is in desk mode but ENABLE_DESK_DOCK_HOME_CAPTURE is false
5238 * <li>The device is in car mode but there's no CAR_DOCK app with METADATA_DOCK_HOME
5239 * <li>The device is in desk mode but there's no DESK_DOCK app with METADATA_DOCK_HOME
5240 * </ul>
Craig Mautnereda67292013-04-28 13:50:14 -07005241 * @return A dock intent.
Daniel Sandler6396c722013-04-16 20:19:09 -04005242 */
5243 Intent createHomeDockIntent() {
5244 Intent intent = null;
5245
5246 // What home does is based on the mode, not the dock state. That
5247 // is, when in car mode you should be taken to car home regardless
5248 // of whether we are actually in a car dock.
5249 if (mUiMode == Configuration.UI_MODE_TYPE_CAR) {
5250 if (ENABLE_CAR_DOCK_HOME_CAPTURE) {
5251 intent = mCarDockIntent;
5252 }
5253 } else if (mUiMode == Configuration.UI_MODE_TYPE_DESK) {
5254 if (ENABLE_DESK_DOCK_HOME_CAPTURE) {
5255 intent = mDeskDockIntent;
5256 }
Jeff Brown4f5fa282014-06-12 19:19:15 -07005257 } else if (mUiMode == Configuration.UI_MODE_TYPE_WATCH
5258 && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
5259 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK
5260 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK)) {
5261 // Always launch dock home from home when watch is docked, if it exists.
5262 intent = mDeskDockIntent;
Daniel Sandler6396c722013-04-16 20:19:09 -04005263 }
5264
5265 if (intent == null) {
5266 return null;
5267 }
5268
5269 ActivityInfo ai = null;
5270 ResolveInfo info = mContext.getPackageManager().resolveActivityAsUser(
5271 intent,
John Spurlockf56bef12013-07-09 09:51:46 -04005272 PackageManager.MATCH_DEFAULT_ONLY | PackageManager.GET_META_DATA,
Craig Mautnerd625ab22013-09-06 13:40:31 -07005273 mCurrentUserId);
Daniel Sandler6396c722013-04-16 20:19:09 -04005274 if (info != null) {
5275 ai = info.activityInfo;
5276 }
5277 if (ai != null
5278 && ai.metaData != null
5279 && ai.metaData.getBoolean(Intent.METADATA_DOCK_HOME)) {
5280 intent = new Intent(intent);
5281 intent.setClassName(ai.packageName, ai.name);
5282 return intent;
5283 }
5284
5285 return null;
5286 }
5287
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005288 void startDockOrHome() {
John Spurlockc8b46ca2013-04-08 12:59:26 -04005289 awakenDreams();
Daniel Sandler6396c722013-04-16 20:19:09 -04005290
5291 Intent dock = createHomeDockIntent();
5292 if (dock != null) {
5293 try {
5294 mContext.startActivityAsUser(dock, UserHandle.CURRENT);
5295 return;
5296 } catch (ActivityNotFoundException e) {
5297 }
5298 }
5299
Dianne Hackbornd8883992012-09-07 15:58:52 -07005300 mContext.startActivityAsUser(mHomeIntent, UserHandle.CURRENT);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005301 }
Craig Mautnereda67292013-04-28 13:50:14 -07005302
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005303 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005304 * goes to the home screen
5305 * @return whether it did anything
5306 */
5307 boolean goHome() {
5308 if (false) {
5309 // This code always brings home to the front.
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07005310 try {
5311 ActivityManagerNative.getDefault().stopAppSwitches();
5312 } catch (RemoteException e) {
5313 }
Dianne Hackborn94a679d2009-07-28 17:51:07 -07005314 sendCloseSystemWindows();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005315 startDockOrHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005316 } else {
5317 // This code brings home to the front or, if it is already
5318 // at the front, puts the device to sleep.
5319 try {
Wink Savilled2e6a332010-02-12 12:12:06 -08005320 if (SystemProperties.getInt("persist.sys.uts-test-mode", 0) == 1) {
5321 /// Roll back EndcallBehavior as the cupcake design to pass P1 lab entry.
5322 Log.d(TAG, "UTS-TEST-MODE");
5323 } else {
5324 ActivityManagerNative.getDefault().stopAppSwitches();
5325 sendCloseSystemWindows();
Daniel Sandler6396c722013-04-16 20:19:09 -04005326 Intent dock = createHomeDockIntent();
5327 if (dock != null) {
5328 int result = ActivityManagerNative.getDefault()
5329 .startActivityAsUser(null, null, dock,
5330 dock.resolveTypeIfNeeded(mContext.getContentResolver()),
5331 null, null, 0,
5332 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
5333 null, null, null, UserHandle.USER_CURRENT);
5334 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
5335 return false;
5336 }
5337 }
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005338 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005339 int result = ActivityManagerNative.getDefault()
Dianne Hackbornf265ea92013-01-31 15:00:51 -08005340 .startActivityAsUser(null, null, mHomeIntent,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005341 mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()),
Dianne Hackborna4972e92012-03-14 10:38:05 -07005342 null, null, 0,
5343 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Dianne Hackborn5e03e2c2012-09-06 14:21:19 -07005344 null, null, null, UserHandle.USER_CURRENT);
Dianne Hackborna4972e92012-03-14 10:38:05 -07005345 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005346 return false;
5347 }
5348 } catch (RemoteException ex) {
5349 // bummer, the activity manager, which is in this process, is dead
5350 }
5351 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005352 return true;
5353 }
Craig Mautnereda67292013-04-28 13:50:14 -07005354
5355 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07005356 public void setCurrentOrientationLw(int newOrientation) {
5357 synchronized (mLock) {
5358 if (newOrientation != mCurrentAppOrientation) {
5359 mCurrentAppOrientation = newOrientation;
5360 updateOrientationListenerLp();
5361 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005362 }
5363 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08005364
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07005365 private void performAuditoryFeedbackForAccessibilityIfNeed() {
5366 if (!isGlobalAccessibilityGestureEnabled()) {
5367 return;
5368 }
5369 AudioManager audioManager = (AudioManager) mContext.getSystemService(
5370 Context.AUDIO_SERVICE);
5371 if (audioManager.isSilentMode()) {
5372 return;
5373 }
5374 Ringtone ringTone = RingtoneManager.getRingtone(mContext,
5375 Settings.System.DEFAULT_NOTIFICATION_URI);
5376 ringTone.setStreamType(AudioManager.STREAM_MUSIC);
5377 ringTone.play();
5378 }
Craig Mautnereda67292013-04-28 13:50:14 -07005379
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07005380 private boolean isGlobalAccessibilityGestureEnabled() {
5381 return Settings.Global.getInt(mContext.getContentResolver(),
5382 Settings.Global.ENABLE_ACCESSIBILITY_GLOBAL_GESTURE_ENABLED, 0) == 1;
5383 }
5384
Craig Mautnereda67292013-04-28 13:50:14 -07005385 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07005386 public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) {
Svetoslav Ganov96179212012-10-10 14:17:45 -07005387 if (!mVibrator.hasVibrator()) {
5388 return false;
5389 }
Christopher Tate5e08af02012-09-21 17:17:22 -07005390 final boolean hapticsDisabled = Settings.System.getIntForUser(mContext.getContentResolver(),
5391 Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) == 0;
Jorim Jaggi5cf17872014-03-26 18:31:48 +01005392 if (!always && (hapticsDisabled || mKeyguardDelegate.isShowingAndNotOccluded())) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005393 return false;
5394 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08005395 long[] pattern = null;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005396 switch (effectId) {
5397 case HapticFeedbackConstants.LONG_PRESS:
Amith Yamasanic33cb712010-02-10 15:21:49 -08005398 pattern = mLongPressVibePattern;
5399 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07005400 case HapticFeedbackConstants.VIRTUAL_KEY:
Amith Yamasanic33cb712010-02-10 15:21:49 -08005401 pattern = mVirtualKeyVibePattern;
5402 break;
5403 case HapticFeedbackConstants.KEYBOARD_TAP:
5404 pattern = mKeyboardTapVibePattern;
5405 break;
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07005406 case HapticFeedbackConstants.CLOCK_TICK:
5407 pattern = mClockTickVibePattern;
5408 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07005409 case HapticFeedbackConstants.SAFE_MODE_DISABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08005410 pattern = mSafeModeDisabledVibePattern;
5411 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07005412 case HapticFeedbackConstants.SAFE_MODE_ENABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08005413 pattern = mSafeModeEnabledVibePattern;
5414 break;
Amith Yamasanic33cb712010-02-10 15:21:49 -08005415 default:
5416 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005417 }
Dianne Hackbornf265ea92013-01-31 15:00:51 -08005418 int owningUid;
5419 String owningPackage;
5420 if (win != null) {
5421 owningUid = win.getOwningUid();
5422 owningPackage = win.getOwningPackage();
5423 } else {
5424 owningUid = android.os.Process.myUid();
Dianne Hackborn95d78532013-09-11 09:51:14 -07005425 owningPackage = mContext.getOpPackageName();
Dianne Hackbornf265ea92013-01-31 15:00:51 -08005426 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08005427 if (pattern.length == 1) {
5428 // One-shot vibration
John Spurlock1af30c72014-03-10 08:33:35 -04005429 mVibrator.vibrate(owningUid, owningPackage, pattern[0], AudioManager.STREAM_SYSTEM);
Amith Yamasanic33cb712010-02-10 15:21:49 -08005430 } else {
5431 // Pattern vibration
John Spurlock1af30c72014-03-10 08:33:35 -04005432 mVibrator.vibrate(owningUid, owningPackage, pattern, -1, AudioManager.STREAM_SYSTEM);
Amith Yamasanic33cb712010-02-10 15:21:49 -08005433 }
5434 return true;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005435 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005436
5437 @Override
5438 public void keepScreenOnStartedLw() {
Daniel Sandler0601eb72011-04-13 01:01:32 -04005439 }
5440
Jeff Brownc38c9be2012-10-04 13:16:19 -07005441 @Override
5442 public void keepScreenOnStoppedLw() {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01005443 if (mKeyguardDelegate != null && !mKeyguardDelegate.isShowingAndNotOccluded()) {
Jim Miller25190572013-02-28 17:36:24 -08005444 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005445 }
5446 }
Mike Lockwoodfcb39242009-10-21 23:01:07 -04005447
Dianne Hackborndf89e652011-10-06 22:35:11 -07005448 private int updateSystemUiVisibilityLw() {
Joe Onorato664644d2011-01-23 17:53:23 -08005449 // If there is no window focused, there will be nobody to handle the events
5450 // anyway, so just hang on in whatever state we're in until things settle down.
John Spurlock79da8332013-09-20 12:04:47 -04005451 WindowState win = mFocusedWindow != null ? mFocusedWindow : mTopFullscreenOpaqueWindowState;
5452 if (win == null) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07005453 return 0;
5454 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01005455 if ((win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 && mHideLockScreen == true) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07005456 // We are updating at a point where the keyguard has gotten
5457 // focus, but we were last in a state where the top window is
5458 // hiding it. This is probably because the keyguard as been
5459 // shown while the top window was displayed, so we want to ignore
5460 // it here because this is just a very transient change and it
5461 // will quickly lose focus once it correctly gets hidden.
5462 return 0;
5463 }
John Spurlock32beb2c2013-03-11 10:16:47 -04005464
John Spurlock1db8b682014-02-18 11:18:59 -05005465 int tmpVisibility = PolicyControl.getSystemUiVisibility(win, null)
Dianne Hackborne26ab702011-10-16 13:21:33 -07005466 & ~mResettingSystemUiFlags
5467 & ~mForceClearedSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04005468 if (mForcingShowNavBar && win.getSurfaceLayer() < mForcingShowNavBarLayer) {
John Spurlockc6d1c602014-01-17 15:22:06 -05005469 tmpVisibility &= ~PolicyControl.adjustClearableFlags(win, View.SYSTEM_UI_CLEARABLE_FLAGS);
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08005470 }
John Spurlock79da8332013-09-20 12:04:47 -04005471 final int visibility = updateSystemBarsLw(win, mLastSystemUiFlags, tmpVisibility);
John Spurlockad3e6cb2013-04-30 08:47:43 -04005472 final int diff = visibility ^ mLastSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04005473 final boolean needsMenu = win.getNeedsMenuLw(mTopFullscreenOpaqueWindowState);
Dianne Hackborne0f085d2011-11-30 18:41:15 -08005474 if (diff == 0 && mLastFocusNeedsMenu == needsMenu
John Spurlock79da8332013-09-20 12:04:47 -04005475 && mFocusedApp == win.getAppToken()) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07005476 return 0;
5477 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07005478 mLastSystemUiFlags = visibility;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08005479 mLastFocusNeedsMenu = needsMenu;
John Spurlock79da8332013-09-20 12:04:47 -04005480 mFocusedApp = win.getAppToken();
Dianne Hackborndf89e652011-10-06 22:35:11 -07005481 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07005482 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07005483 public void run() {
Dianne Hackborn42e620c2012-06-24 13:20:51 -07005484 try {
5485 IStatusBarService statusbar = getStatusBarService();
5486 if (statusbar != null) {
5487 statusbar.setSystemUiVisibility(visibility, 0xffffffff);
5488 statusbar.topAppWindowChanged(needsMenu);
Joe Onorato664644d2011-01-23 17:53:23 -08005489 }
Dianne Hackborn42e620c2012-06-24 13:20:51 -07005490 } catch (RemoteException e) {
5491 // re-acquire status bar service next time it is needed.
5492 mStatusBarService = null;
Joe Onorato664644d2011-01-23 17:53:23 -08005493 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07005494 }
5495 });
5496 return diff;
Joe Onorato664644d2011-01-23 17:53:23 -08005497 }
5498
John Spurlock79da8332013-09-20 12:04:47 -04005499 private int updateSystemBarsLw(WindowState win, int oldVis, int vis) {
John Spurlockbd957402013-10-03 11:38:39 -04005500 // apply translucent bar vis flags
Jorim Jaggi380ecb82014-03-14 17:25:20 +01005501 WindowState transWin = isStatusBarKeyguard() && !mHideLockScreen
5502 ? mStatusBar
John Spurlockbd957402013-10-03 11:38:39 -04005503 : mTopFullscreenOpaqueWindowState;
5504 vis = mStatusBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
5505 vis = mNavigationBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
5506
John Spurlock27735a42013-08-14 17:57:38 -04005507 // prevent status bar interaction from clearing certain flags
John Spurlock79da8332013-09-20 12:04:47 -04005508 boolean statusBarHasFocus = win.getAttrs().type == TYPE_STATUS_BAR;
John Spurlockad3e6cb2013-04-30 08:47:43 -04005509 if (statusBarHasFocus) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04005510 int flags = View.SYSTEM_UI_FLAG_FULLSCREEN
5511 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlockcfc359a2013-09-05 10:42:03 -04005512 | View.SYSTEM_UI_FLAG_IMMERSIVE
Jorim Jaggi5cf17872014-03-26 18:31:48 +01005513 | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
5514 if (!isStatusBarKeyguard() || mHideLockScreen) {
5515 flags |= View.STATUS_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSLUCENT;
5516 }
John Spurlockbd957402013-10-03 11:38:39 -04005517 vis = (vis & ~flags) | (oldVis & flags);
John Spurlockad3e6cb2013-04-30 08:47:43 -04005518 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04005519
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04005520 if (!areTranslucentBarsAllowed()) {
Adrian Roosea562512014-05-05 13:33:03 +02005521 vis &= ~(View.NAVIGATION_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSLUCENT
5522 | View.SYSTEM_UI_TRANSPARENT);
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07005523 }
5524
John Spurlock27735a42013-08-14 17:57:38 -04005525 // update status bar
John Spurlockf1a36642013-10-12 17:50:42 -04005526 boolean immersiveSticky =
5527 (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
John Spurlock27735a42013-08-14 17:57:38 -04005528 boolean hideStatusBarWM =
John Spurlockbd957402013-10-03 11:38:39 -04005529 mTopFullscreenOpaqueWindowState != null &&
John Spurlockc6d1c602014-01-17 15:22:06 -05005530 (PolicyControl.getWindowFlags(mTopFullscreenOpaqueWindowState, null)
John Spurlock27735a42013-08-14 17:57:38 -04005531 & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0;
5532 boolean hideStatusBarSysui =
5533 (vis & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04005534 boolean hideNavBarSysui =
5535 (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0;
John Spurlockad3e6cb2013-04-30 08:47:43 -04005536
John Spurlock27735a42013-08-14 17:57:38 -04005537 boolean transientStatusBarAllowed =
5538 mStatusBar != null && (
5539 hideStatusBarWM
John Spurlockf1a36642013-10-12 17:50:42 -04005540 || (hideStatusBarSysui && immersiveSticky)
John Spurlock27735a42013-08-14 17:57:38 -04005541 || statusBarHasFocus);
5542
John Spurlockf1a36642013-10-12 17:50:42 -04005543 boolean transientNavBarAllowed =
5544 mNavigationBar != null &&
5545 hideNavBarSysui && immersiveSticky;
5546
John Spurlockf25706f2013-11-07 18:02:43 -05005547 boolean denyTransientStatus = mStatusBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04005548 && !transientStatusBarAllowed && hideStatusBarSysui;
John Spurlockf25706f2013-11-07 18:02:43 -05005549 boolean denyTransientNav = mNavigationBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04005550 && !transientNavBarAllowed;
5551 if (denyTransientStatus || denyTransientNav) {
John Spurlock27735a42013-08-14 17:57:38 -04005552 // clear the clearable flags instead
John Spurlockf1a36642013-10-12 17:50:42 -04005553 clearClearableFlagsLw();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005554 }
John Spurlock27735a42013-08-14 17:57:38 -04005555
5556 vis = mStatusBarController.updateVisibilityLw(transientStatusBarAllowed, oldVis, vis);
5557
5558 // update navigation bar
John Spurlockf1a36642013-10-12 17:50:42 -04005559 boolean oldImmersiveMode = isImmersiveMode(oldVis);
5560 boolean newImmersiveMode = isImmersiveMode(vis);
5561 if (win != null && oldImmersiveMode != newImmersiveMode) {
John Spurlock79da8332013-09-20 12:04:47 -04005562 final String pkg = win.getOwningPackage();
Maurice Lam99c6e072014-04-28 18:24:28 -07005563 mImmersiveModeConfirmation.immersiveModeChanged(pkg, newImmersiveMode,
5564 isUserSetupComplete());
John Spurlock34e13d92013-08-10 06:52:28 -04005565 }
John Spurlock27735a42013-08-14 17:57:38 -04005566
John Spurlockf1a36642013-10-12 17:50:42 -04005567 vis = mNavigationBarController.updateVisibilityLw(transientNavBarAllowed, oldVis, vis);
5568
John Spurlocke1f366f2013-08-05 12:22:40 -04005569 return vis;
John Spurlockad3e6cb2013-04-30 08:47:43 -04005570 }
5571
John Spurlockf1a36642013-10-12 17:50:42 -04005572 private void clearClearableFlagsLw() {
5573 int newVal = mResettingSystemUiFlags | View.SYSTEM_UI_CLEARABLE_FLAGS;
5574 if (newVal != mResettingSystemUiFlags) {
5575 mResettingSystemUiFlags = newVal;
5576 mWindowManagerFuncs.reevaluateStatusBarVisibility();
5577 }
5578 }
5579
5580 private boolean isImmersiveMode(int vis) {
5581 final int flags = View.SYSTEM_UI_FLAG_IMMERSIVE | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
John Spurlock34e13d92013-08-10 06:52:28 -04005582 return mNavigationBar != null
5583 && (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0
Daniel Sandler900ece52013-10-18 15:53:27 -04005584 && (vis & flags) != 0
5585 && canHideNavigationBar();
John Spurlock34e13d92013-08-10 06:52:28 -04005586 }
5587
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07005588 /**
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04005589 * @return whether the navigation or status bar can be made translucent
5590 *
5591 * This should return true unless touch exploration is not enabled or
5592 * R.boolean.config_enableTranslucentDecor is false.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07005593 */
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04005594 private boolean areTranslucentBarsAllowed() {
Svetoslav8e3feb12014-02-24 13:46:47 -08005595 return mTranslucentDecorEnabled
5596 && !mAccessibilityManager.isTouchExplorationEnabled();
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07005597 }
5598
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04005599 // Use this instead of checking config_showNavigationBar so that it can be consistently
5600 // overridden by qemu.hw.mainkeys in the emulator.
Craig Mautnereda67292013-04-28 13:50:14 -07005601 @Override
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04005602 public boolean hasNavigationBar() {
5603 return mHasNavigationBar;
5604 }
5605
satok1bc0a492012-04-25 22:47:12 +09005606 @Override
5607 public void setLastInputMethodWindowLw(WindowState ime, WindowState target) {
5608 mLastInputMethodWindow = ime;
5609 mLastInputMethodTargetWindow = target;
5610 }
5611
Craig Mautnerf1b67412012-09-19 13:18:29 -07005612 @Override
Satoshi Kataoka658c7b82013-10-10 17:03:51 +09005613 public int getInputMethodWindowVisibleHeightLw() {
5614 return mDockBottom - mCurBottom;
5615 }
5616
5617 @Override
Craig Mautnerf1b67412012-09-19 13:18:29 -07005618 public void setCurrentUserLw(int newUserId) {
Craig Mautnerd625ab22013-09-06 13:40:31 -07005619 mCurrentUserId = newUserId;
Jim Miller5ecd8112013-01-09 18:50:26 -08005620 if (mKeyguardDelegate != null) {
5621 mKeyguardDelegate.setCurrentUser(newUserId);
Craig Mautnerf1b67412012-09-19 13:18:29 -07005622 }
John Spurlock13451a22012-09-28 14:40:41 -04005623 if (mStatusBarService != null) {
5624 try {
5625 mStatusBarService.setCurrentUser(newUserId);
5626 } catch (RemoteException e) {
5627 // oh well
5628 }
5629 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07005630 setLastInputMethodWindowLw(null, null);
Craig Mautnerf1b67412012-09-19 13:18:29 -07005631 }
5632
5633 @Override
Svetoslav Ganov545252f2012-12-10 18:29:24 -08005634 public boolean canMagnifyWindow(int windowType) {
5635 switch (windowType) {
5636 case WindowManager.LayoutParams.TYPE_INPUT_METHOD:
5637 case WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG:
5638 case WindowManager.LayoutParams.TYPE_NAVIGATION_BAR:
5639 case WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY: {
5640 return false;
5641 }
5642 }
5643 return true;
5644 }
5645
5646 @Override
5647 public boolean isTopLevelWindow(int windowType) {
5648 if (windowType >= WindowManager.LayoutParams.FIRST_SUB_WINDOW
5649 && windowType <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
5650 return (windowType == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG);
5651 }
5652 return true;
5653 }
5654
Jim Miller4eeb4f62012-11-08 00:04:29 -08005655 @Override
Jeff Brownd7a04de2012-06-17 14:17:52 -07005656 public void dump(String prefix, PrintWriter pw, String[] args) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005657 pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005658 pw.print(" mSystemReady="); pw.print(mSystemReady);
5659 pw.print(" mSystemBooted="); pw.println(mSystemBooted);
Jeff Brown2e7760e2012-04-11 15:14:55 -07005660 pw.print(prefix); pw.print("mLidState="); pw.print(mLidState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005661 pw.print(" mLidOpenRotation="); pw.print(mLidOpenRotation);
5662 pw.print(" mHdmiPlugged="); pw.println(mHdmiPlugged);
Dianne Hackborne26ab702011-10-16 13:21:33 -07005663 if (mLastSystemUiFlags != 0 || mResettingSystemUiFlags != 0
5664 || mForceClearedSystemUiFlags != 0) {
5665 pw.print(prefix); pw.print("mLastSystemUiFlags=0x");
5666 pw.print(Integer.toHexString(mLastSystemUiFlags));
5667 pw.print(" mResettingSystemUiFlags=0x");
5668 pw.print(Integer.toHexString(mResettingSystemUiFlags));
5669 pw.print(" mForceClearedSystemUiFlags=0x");
5670 pw.println(Integer.toHexString(mForceClearedSystemUiFlags));
Dianne Hackborndf89e652011-10-06 22:35:11 -07005671 }
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08005672 if (mLastFocusNeedsMenu) {
5673 pw.print(prefix); pw.print("mLastFocusNeedsMenu=");
5674 pw.println(mLastFocusNeedsMenu);
5675 }
Jeff Browna20dda42014-05-27 20:57:24 -07005676 pw.print(prefix); pw.print("mWakeGestureEnabledSetting=");
5677 pw.println(mWakeGestureEnabledSetting);
5678
Jeff Brownbcdfc622014-03-06 19:13:04 -08005679 pw.print(prefix); pw.print("mSupportAutoRotation="); pw.println(mSupportAutoRotation);
Daniel Sandler6396c722013-04-16 20:19:09 -04005680 pw.print(prefix); pw.print("mUiMode="); pw.print(mUiMode);
5681 pw.print(" mDockMode="); pw.print(mDockMode);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005682 pw.print(" mCarDockRotation="); pw.print(mCarDockRotation);
5683 pw.print(" mDeskDockRotation="); pw.println(mDeskDockRotation);
5684 pw.print(prefix); pw.print("mUserRotationMode="); pw.print(mUserRotationMode);
5685 pw.print(" mUserRotation="); pw.print(mUserRotation);
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005686 pw.print(" mAllowAllRotations="); pw.println(mAllowAllRotations);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07005687 pw.print(prefix); pw.print("mCurrentAppOrientation="); pw.println(mCurrentAppOrientation);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005688 pw.print(prefix); pw.print("mCarDockEnablesAccelerometer=");
5689 pw.print(mCarDockEnablesAccelerometer);
5690 pw.print(" mDeskDockEnablesAccelerometer=");
5691 pw.println(mDeskDockEnablesAccelerometer);
5692 pw.print(prefix); pw.print("mLidKeyboardAccessibility=");
5693 pw.print(mLidKeyboardAccessibility);
5694 pw.print(" mLidNavigationAccessibility="); pw.print(mLidNavigationAccessibility);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07005695 pw.print(" mLidControlsSleep="); pw.println(mLidControlsSleep);
Jeff Brown6d8fd272014-05-20 21:24:38 -07005696 pw.print(prefix);
5697 pw.print("mShortPressOnPowerBehavior="); pw.print(mShortPressOnPowerBehavior);
5698 pw.print(" mLongPressOnPowerBehavior="); pw.println(mLongPressOnPowerBehavior);
5699 pw.print(prefix); pw.print("mHasSoftInput="); pw.println(mHasSoftInput);
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07005700 pw.print(prefix); pw.print("mScreenOnEarly="); pw.print(mScreenOnEarly);
5701 pw.print(" mScreenOnFully="); pw.print(mScreenOnFully);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07005702 pw.print(" mOrientationSensorEnabled="); pw.println(mOrientationSensorEnabled);
Dianne Hackbornc652de82013-02-15 16:32:56 -08005703 pw.print(prefix); pw.print("mOverscanScreen=("); pw.print(mOverscanScreenLeft);
5704 pw.print(","); pw.print(mOverscanScreenTop);
5705 pw.print(") "); pw.print(mOverscanScreenWidth);
5706 pw.print("x"); pw.println(mOverscanScreenHeight);
5707 if (mOverscanLeft != 0 || mOverscanTop != 0
5708 || mOverscanRight != 0 || mOverscanBottom != 0) {
5709 pw.print(prefix); pw.print("mOverscan left="); pw.print(mOverscanLeft);
5710 pw.print(" top="); pw.print(mOverscanTop);
5711 pw.print(" right="); pw.print(mOverscanRight);
5712 pw.print(" bottom="); pw.println(mOverscanBottom);
5713 }
Dianne Hackborn313440842013-02-19 19:22:59 -08005714 pw.print(prefix); pw.print("mRestrictedOverscanScreen=(");
5715 pw.print(mRestrictedOverscanScreenLeft);
5716 pw.print(","); pw.print(mRestrictedOverscanScreenTop);
5717 pw.print(") "); pw.print(mRestrictedOverscanScreenWidth);
5718 pw.print("x"); pw.println(mRestrictedOverscanScreenHeight);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005719 pw.print(prefix); pw.print("mUnrestrictedScreen=("); pw.print(mUnrestrictedScreenLeft);
5720 pw.print(","); pw.print(mUnrestrictedScreenTop);
5721 pw.print(") "); pw.print(mUnrestrictedScreenWidth);
5722 pw.print("x"); pw.println(mUnrestrictedScreenHeight);
5723 pw.print(prefix); pw.print("mRestrictedScreen=("); pw.print(mRestrictedScreenLeft);
5724 pw.print(","); pw.print(mRestrictedScreenTop);
5725 pw.print(") "); pw.print(mRestrictedScreenWidth);
5726 pw.print("x"); pw.println(mRestrictedScreenHeight);
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07005727 pw.print(prefix); pw.print("mStableFullscreen=("); pw.print(mStableFullscreenLeft);
5728 pw.print(","); pw.print(mStableFullscreenTop);
5729 pw.print(")-("); pw.print(mStableFullscreenRight);
5730 pw.print(","); pw.print(mStableFullscreenBottom); pw.println(")");
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07005731 pw.print(prefix); pw.print("mStable=("); pw.print(mStableLeft);
5732 pw.print(","); pw.print(mStableTop);
5733 pw.print(")-("); pw.print(mStableRight);
5734 pw.print(","); pw.print(mStableBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07005735 pw.print(prefix); pw.print("mSystem=("); pw.print(mSystemLeft);
5736 pw.print(","); pw.print(mSystemTop);
5737 pw.print(")-("); pw.print(mSystemRight);
5738 pw.print(","); pw.print(mSystemBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005739 pw.print(prefix); pw.print("mCur=("); pw.print(mCurLeft);
5740 pw.print(","); pw.print(mCurTop);
5741 pw.print(")-("); pw.print(mCurRight);
5742 pw.print(","); pw.print(mCurBottom); pw.println(")");
5743 pw.print(prefix); pw.print("mContent=("); pw.print(mContentLeft);
5744 pw.print(","); pw.print(mContentTop);
5745 pw.print(")-("); pw.print(mContentRight);
5746 pw.print(","); pw.print(mContentBottom); pw.println(")");
Dianne Hackborne30e02f2014-05-27 18:24:45 -07005747 pw.print(prefix); pw.print("mVoiceContent=("); pw.print(mVoiceContentLeft);
5748 pw.print(","); pw.print(mVoiceContentTop);
5749 pw.print(")-("); pw.print(mVoiceContentRight);
5750 pw.print(","); pw.print(mVoiceContentBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005751 pw.print(prefix); pw.print("mDock=("); pw.print(mDockLeft);
5752 pw.print(","); pw.print(mDockTop);
5753 pw.print(")-("); pw.print(mDockRight);
5754 pw.print(","); pw.print(mDockBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07005755 pw.print(prefix); pw.print("mDockLayer="); pw.print(mDockLayer);
5756 pw.print(" mStatusBarLayer="); pw.println(mStatusBarLayer);
Dianne Hackborn7ad44382012-10-18 17:46:00 -07005757 pw.print(prefix); pw.print("mShowingLockscreen="); pw.print(mShowingLockscreen);
5758 pw.print(" mShowingDream="); pw.print(mShowingDream);
5759 pw.print(" mDreamingLockscreen="); pw.println(mDreamingLockscreen);
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07005760 if (mLastInputMethodWindow != null) {
5761 pw.print(prefix); pw.print("mLastInputMethodWindow=");
5762 pw.println(mLastInputMethodWindow);
5763 }
5764 if (mLastInputMethodTargetWindow != null) {
5765 pw.print(prefix); pw.print("mLastInputMethodTargetWindow=");
5766 pw.println(mLastInputMethodTargetWindow);
5767 }
5768 if (mStatusBar != null) {
5769 pw.print(prefix); pw.print("mStatusBar=");
5770 pw.println(mStatusBar);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01005771 pw.print(prefix); pw.print("isStatusBarKeyguard=");
5772 pw.print(isStatusBarKeyguard());
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07005773 }
5774 if (mNavigationBar != null) {
5775 pw.print(prefix); pw.print("mNavigationBar=");
5776 pw.println(mNavigationBar);
5777 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07005778 if (mFocusedWindow != null) {
5779 pw.print(prefix); pw.print("mFocusedWindow=");
5780 pw.println(mFocusedWindow);
5781 }
5782 if (mFocusedApp != null) {
5783 pw.print(prefix); pw.print("mFocusedApp=");
5784 pw.println(mFocusedApp);
5785 }
5786 if (mWinDismissingKeyguard != null) {
5787 pw.print(prefix); pw.print("mWinDismissingKeyguard=");
5788 pw.println(mWinDismissingKeyguard);
5789 }
5790 if (mTopFullscreenOpaqueWindowState != null) {
5791 pw.print(prefix); pw.print("mTopFullscreenOpaqueWindowState=");
5792 pw.println(mTopFullscreenOpaqueWindowState);
5793 }
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08005794 if (mForcingShowNavBar) {
5795 pw.print(prefix); pw.print("mForcingShowNavBar=");
5796 pw.println(mForcingShowNavBar); pw.print( "mForcingShowNavBarLayer=");
5797 pw.println(mForcingShowNavBarLayer);
5798 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07005799 pw.print(prefix); pw.print("mTopIsFullscreen="); pw.print(mTopIsFullscreen);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005800 pw.print(" mHideLockScreen="); pw.println(mHideLockScreen);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07005801 pw.print(prefix); pw.print("mForceStatusBar="); pw.print(mForceStatusBar);
5802 pw.print(" mForceStatusBarFromKeyguard=");
5803 pw.println(mForceStatusBarFromKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005804 pw.print(prefix); pw.print("mDismissKeyguard="); pw.print(mDismissKeyguard);
Craig Mautnerad09bcc2012-10-08 13:33:11 -07005805 pw.print(" mWinDismissingKeyguard="); pw.print(mWinDismissingKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005806 pw.print(" mHomePressed="); pw.println(mHomePressed);
5807 pw.print(prefix); pw.print("mAllowLockscreenWhenOn="); pw.print(mAllowLockscreenWhenOn);
5808 pw.print(" mLockScreenTimeout="); pw.print(mLockScreenTimeout);
5809 pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive);
5810 pw.print(prefix); pw.print("mEndcallBehavior="); pw.print(mEndcallBehavior);
5811 pw.print(" mIncallPowerBehavior="); pw.print(mIncallPowerBehavior);
5812 pw.print(" mLongPressOnHomeBehavior="); pw.println(mLongPressOnHomeBehavior);
5813 pw.print(prefix); pw.print("mLandscapeRotation="); pw.print(mLandscapeRotation);
5814 pw.print(" mSeascapeRotation="); pw.println(mSeascapeRotation);
5815 pw.print(prefix); pw.print("mPortraitRotation="); pw.print(mPortraitRotation);
5816 pw.print(" mUpsideDownRotation="); pw.println(mUpsideDownRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07005817 pw.print(prefix); pw.print("mDemoHdmiRotation="); pw.print(mDemoHdmiRotation);
5818 pw.print(" mDemoHdmiRotationLock="); pw.println(mDemoHdmiRotationLock);
5819 pw.print(prefix); pw.print("mUndockedHdmiRotation="); pw.println(mUndockedHdmiRotation);
Jeff Brown600f0032014-05-22 17:06:00 -07005820
Tim Kilbournd7c0c2e2014-05-29 16:08:10 -07005821 mGlobalKeyManager.dump(prefix, pw);
John Spurlock27735a42013-08-14 17:57:38 -04005822 mStatusBarController.dump(pw, prefix);
5823 mNavigationBarController.dump(pw, prefix);
John Spurlockc6d1c602014-01-17 15:22:06 -05005824 PolicyControl.dump(prefix, pw);
Jeff Brown600f0032014-05-22 17:06:00 -07005825
Jeff Browna20dda42014-05-27 20:57:24 -07005826 if (mWakeGestureListener != null) {
5827 mWakeGestureListener.dump(pw, prefix);
5828 }
Jeff Brown600f0032014-05-22 17:06:00 -07005829 if (mOrientationListener != null) {
5830 mOrientationListener.dump(pw, prefix);
5831 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005832 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005833}