blob: 4458a8d64da3557cbd9397a10343f0bcc41774c6 [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;
John Spurlockc8b46ca2013-04-08 12:59:26 -040065import android.service.dreams.DreamService;
66import android.service.dreams.IDreamManager;
Santos Cordon9eb45932014-06-27 12:28:43 -070067import android.telecomm.TelecommManager;
Dianne Hackborn81e56d52011-05-26 00:55:58 -070068import android.util.DisplayMetrics;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080069import android.util.EventLog;
70import android.util.Log;
Jeff Browna41ca772010-08-11 14:46:32 -070071import android.util.Slog;
Jeff Brown6651a632011-11-28 12:59:11 -080072import android.util.SparseArray;
Dianne Hackbornf87d1962012-04-04 12:48:24 -070073import android.view.Display;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080074import android.view.Gravity;
75import android.view.HapticFeedbackConstants;
Dianne Hackborne0f085d2011-11-30 18:41:15 -080076import android.view.IApplicationToken;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080077import android.view.IWindowManager;
Jeff Browna41ca772010-08-11 14:46:32 -070078import android.view.InputChannel;
Jeff Brown4d396052010-10-29 21:50:21 -070079import android.view.InputDevice;
Jeff Brown4952dfd2011-11-30 19:23:22 -080080import android.view.InputEvent;
Jeff Brown32cbc38552011-12-01 14:01:49 -080081import android.view.InputEventReceiver;
Jeff Brown6b53e8d2010-11-10 16:03:06 -080082import android.view.KeyCharacterMap;
Craig Mautnerae446592012-12-06 19:05:05 -080083import android.view.KeyCharacterMap.FallbackAction;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080084import android.view.KeyEvent;
85import android.view.MotionEvent;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080086import android.view.Surface;
87import android.view.View;
88import android.view.ViewConfiguration;
89import android.view.Window;
90import android.view.WindowManager;
Craig Mautnerae446592012-12-06 19:05:05 -080091import android.view.WindowManagerGlobal;
Craig Mautner8a0da012014-05-31 15:13:37 -070092import android.view.WindowManagerInternal;
Craig Mautnerae446592012-12-06 19:05:05 -080093import android.view.WindowManagerPolicy;
Craig Mautnerae446592012-12-06 19:05:05 -080094import android.view.accessibility.AccessibilityEvent;
Svetoslav8e3feb12014-02-24 13:46:47 -080095import android.view.accessibility.AccessibilityManager;
Craig Mautnerae446592012-12-06 19:05:05 -080096import android.view.animation.Animation;
97import android.view.animation.AnimationUtils;
98
99import com.android.internal.R;
Jorim Jaggi380ecb82014-03-14 17:25:20 +0100100import com.android.internal.policy.IKeyguardService;
101import com.android.internal.policy.IKeyguardServiceConstants;
Craig Mautnerae446592012-12-06 19:05:05 -0800102import com.android.internal.policy.PolicyManager;
Jim Miller5ecd8112013-01-09 18:50:26 -0800103import com.android.internal.policy.impl.keyguard.KeyguardServiceDelegate;
Craig Mautner8a0da012014-05-31 15:13:37 -0700104import com.android.internal.policy.impl.keyguard.KeyguardServiceDelegate.ShowListener;
Craig Mautnerae446592012-12-06 19:05:05 -0800105import com.android.internal.statusbar.IStatusBarService;
Craig Mautnerae446592012-12-06 19:05:05 -0800106import com.android.internal.widget.PointerLocationView;
Craig Mautner8a0da012014-05-31 15:13:37 -0700107import com.android.server.LocalServices;
Craig Mautnerae446592012-12-06 19:05:05 -0800108
109import java.io.File;
110import java.io.FileReader;
111import java.io.IOException;
112import java.io.PrintWriter;
Craig Mautner8a0da012014-05-31 15:13:37 -0700113import java.util.ArrayList;
Craig Mautner2bc789b2014-03-19 19:48:38 -0700114import java.util.HashSet;
Craig Mautnerae446592012-12-06 19:05:05 -0800115
Dianne Hackbornc652de82013-02-15 16:32:56 -0800116import static android.view.WindowManager.LayoutParams.*;
Jeff Brownac143512012-04-05 18:57:33 -0700117import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_ABSENT;
118import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_OPEN;
119import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_CLOSED;
Dianne Hackborn08743722009-12-21 12:16:51 -0800120
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800121/**
The Android Open Source Project0727d222009-03-11 12:11:58 -0700122 * WindowManagerPolicy implementation for the Android phone UI. This
123 * introduces a new method suffix, Lp, for an internal lock of the
124 * PhoneWindowManager. This is used to protect some internal state, and
John Spurlock04db1762013-05-13 12:46:41 -0400125 * 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 -0700126 * of both of those when held.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800127 */
128public class PhoneWindowManager implements WindowManagerPolicy {
129 static final String TAG = "WindowManager";
130 static final boolean DEBUG = false;
Joe Onorato43a17652011-04-06 19:22:23 -0700131 static final boolean localLOGV = false;
The Android Open Source Project11267662009-03-18 17:39:47 -0700132 static final boolean DEBUG_LAYOUT = false;
Jeff Brown40013652012-05-16 21:22:36 -0700133 static final boolean DEBUG_INPUT = false;
Craig Mautner6fbda632012-07-03 09:26:39 -0700134 static final boolean DEBUG_STARTING_WINDOW = false;
Craig Mautner8a0da012014-05-31 15:13:37 -0700135 static final boolean DEBUG_WAKEUP = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800136 static final boolean SHOW_STARTING_ANIMATIONS = true;
137 static final boolean SHOW_PROCESSES_ON_ALT_MENU = false;
Joe Onoratod208e702010-10-08 16:22:43 -0400138
Daniel Sandler6396c722013-04-16 20:19:09 -0400139 // Whether to allow dock apps with METADATA_DOCK_HOME to temporarily take over the Home key.
140 // No longer recommended for desk docks; still useful in car docks.
141 static final boolean ENABLE_CAR_DOCK_HOME_CAPTURE = true;
142 static final boolean ENABLE_DESK_DOCK_HOME_CAPTURE = false;
143
Jeff Brown6d8fd272014-05-20 21:24:38 -0700144 static final int SHORT_PRESS_POWER_NOTHING = 0;
145 static final int SHORT_PRESS_POWER_GO_TO_SLEEP = 1;
146 static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP = 2;
147 static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME = 3;
148
Joe Onoratod208e702010-10-08 16:22:43 -0400149 static final int LONG_PRESS_POWER_NOTHING = 0;
150 static final int LONG_PRESS_POWER_GLOBAL_ACTIONS = 1;
151 static final int LONG_PRESS_POWER_SHUT_OFF = 2;
Jeff Brown9a538ee2012-08-20 14:56:57 -0700152 static final int LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM = 3;
Michael Jurka3b1fc472011-06-13 10:54:40 -0700153
154 // These need to match the documentation/constant in
155 // core/res/res/values/config.xml
Joe Onorato46b0d682010-11-22 17:37:27 -0800156 static final int LONG_PRESS_HOME_NOTHING = 0;
Michael Wrightc9ebea72013-01-16 19:25:02 -0800157 static final int LONG_PRESS_HOME_RECENT_SYSTEM_UI = 1;
Jeff Browncaca8812013-05-09 13:34:33 -0700158 static final int LONG_PRESS_HOME_ASSIST = 2;
159
160 static final int DOUBLE_TAP_HOME_NOTHING = 0;
161 static final int DOUBLE_TAP_HOME_RECENT_SYSTEM_UI = 1;
Joe Onorato46b0d682010-11-22 17:37:27 -0800162
Dianne Hackborn5cb8d792009-05-21 17:34:15 -0700163 static final int APPLICATION_MEDIA_SUBLAYER = -2;
164 static final int APPLICATION_MEDIA_OVERLAY_SUBLAYER = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800165 static final int APPLICATION_PANEL_SUBLAYER = 1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800166 static final int APPLICATION_SUB_PANEL_SUBLAYER = 2;
Craig Mautner88400d32012-09-30 12:35:45 -0700167
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800168 static public final String SYSTEM_DIALOG_REASON_KEY = "reason";
169 static public final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions";
170 static public final String SYSTEM_DIALOG_REASON_RECENT_APPS = "recentapps";
Joe Onoratof275f0c2009-11-24 16:11:13 -0500171 static public final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey";
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700172 static public final String SYSTEM_DIALOG_REASON_ASSIST = "assist";
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800173
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700174 /**
175 * These are the system UI flags that, when changing, can cause the layout
176 * of the screen to change.
177 */
178 static final int SYSTEM_UI_CHANGING_LAYOUT =
John Spurlocke1f366f2013-08-05 12:22:40 -0400179 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlock7f4820a2013-10-08 12:54:35 -0400180 | View.SYSTEM_UI_FLAG_FULLSCREEN
181 | View.STATUS_BAR_TRANSLUCENT
Adrian Roosea562512014-05-05 13:33:03 +0200182 | View.NAVIGATION_BAR_TRANSLUCENT
183 | View.SYSTEM_UI_TRANSPARENT;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700184
Jim Miller5ecd8112013-01-09 18:50:26 -0800185 /**
186 * Keyguard stuff
187 */
188 private WindowState mKeyguardScrim;
Jorim Jaggi380ecb82014-03-14 17:25:20 +0100189 private boolean mKeyguardHidden;
Jorim Jaggicff0acb2014-03-31 16:35:15 +0200190 private boolean mKeyguardDrawn;
Jim Miller5ecd8112013-01-09 18:50:26 -0800191
Jeff Brown6651a632011-11-28 12:59:11 -0800192 /* Table of Application Launch keys. Maps from key codes to intent categories.
193 *
194 * These are special keys that are used to launch particular kinds of applications,
195 * such as a web browser. HID defines nearly a hundred of them in the Consumer (0x0C)
196 * usage page. We don't support quite that many yet...
197 */
198 static SparseArray<String> sApplicationLaunchKeyCategories;
199 static {
200 sApplicationLaunchKeyCategories = new SparseArray<String>();
201 sApplicationLaunchKeyCategories.append(
202 KeyEvent.KEYCODE_EXPLORER, Intent.CATEGORY_APP_BROWSER);
203 sApplicationLaunchKeyCategories.append(
204 KeyEvent.KEYCODE_ENVELOPE, Intent.CATEGORY_APP_EMAIL);
205 sApplicationLaunchKeyCategories.append(
206 KeyEvent.KEYCODE_CONTACTS, Intent.CATEGORY_APP_CONTACTS);
207 sApplicationLaunchKeyCategories.append(
208 KeyEvent.KEYCODE_CALENDAR, Intent.CATEGORY_APP_CALENDAR);
209 sApplicationLaunchKeyCategories.append(
210 KeyEvent.KEYCODE_MUSIC, Intent.CATEGORY_APP_MUSIC);
211 sApplicationLaunchKeyCategories.append(
212 KeyEvent.KEYCODE_CALCULATOR, Intent.CATEGORY_APP_CALCULATOR);
213 }
214
Dianne Hackborndf89e652011-10-06 22:35:11 -0700215 /**
216 * Lock protecting internal state. Must not call out into window
217 * manager with lock held. (This lock will be acquired in places
218 * where the window manager is calling in with its own lock held.)
219 */
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800220 private final Object mLock = new Object();
Dianne Hackborndf89e652011-10-06 22:35:11 -0700221
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800222 Context mContext;
223 IWindowManager mWindowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700224 WindowManagerFuncs mWindowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -0700225 WindowManagerInternal mWindowManagerInternal;
Jeff Brown96307042012-07-27 15:51:34 -0700226 PowerManager mPowerManager;
Joe Onorato93056472010-09-10 10:30:46 -0400227 IStatusBarService mStatusBarService;
Jeff Browncaca8812013-05-09 13:34:33 -0700228 boolean mPreloadedRecentApps;
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700229 final Object mServiceAquireLock = new Object();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800230 Vibrator mVibrator; // Vibrator for giving feedback of orientation changes
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700231 SearchManager mSearchManager;
Svetoslav8e3feb12014-02-24 13:46:47 -0800232 AccessibilityManager mAccessibilityManager;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800233
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700234 // Vibrator pattern for haptic feedback of a long press.
235 long[] mLongPressVibePattern;
Craig Mautner88400d32012-09-30 12:35:45 -0700236
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700237 // Vibrator pattern for haptic feedback of virtual key press.
238 long[] mVirtualKeyVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700239
Amith Yamasanic33cb712010-02-10 15:21:49 -0800240 // Vibrator pattern for a short vibration.
241 long[] mKeyboardTapVibePattern;
242
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -0700243 // Vibrator pattern for a short vibration when tapping on an hour/minute tick of a Clock.
244 long[] mClockTickVibePattern;
245
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700246 // Vibrator pattern for haptic feedback during boot when safe mode is disabled.
247 long[] mSafeModeDisabledVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700248
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700249 // Vibrator pattern for haptic feedback during boot when safe mode is enabled.
250 long[] mSafeModeEnabledVibePattern;
Romain Guy8154cd32010-03-29 14:41:15 -0700251
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800252 /** If true, hitting shift & menu will broadcast Intent.ACTION_BUG_REPORT */
253 boolean mEnableShiftMenuBugReports = false;
Mike Lockwoodd747dc82011-09-13 16:28:22 -0400254
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800255 boolean mSafeMode;
256 WindowState mStatusBar = null;
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700257 int mStatusBarHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400258 WindowState mNavigationBar = null;
Daniel Sandler36412a72011-08-04 09:35:13 -0400259 boolean mHasNavigationBar = false;
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700260 boolean mCanHideNavigationBar = false;
Daniel Sandler4a066c52012-04-20 14:49:13 -0400261 boolean mNavigationBarCanMove = false; // can the navigation bar ever move to the side?
262 boolean mNavigationBarOnBottom = true; // is the navigation bar on the bottom *right now*?
263 int[] mNavigationBarHeightForRotation = new int[4];
264 int[] mNavigationBarWidthForRotation = new int[4];
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400265
Jim Miller5ecd8112013-01-09 18:50:26 -0800266 KeyguardServiceDelegate mKeyguardDelegate;
Craig Mautner8a0da012014-05-31 15:13:37 -0700267 // The following are only accessed on the mHandler thread.
268 boolean mKeyguardDrawComplete;
269 boolean mWindowManagerDrawComplete;
Craig Mautner13f6ea72014-06-23 14:57:02 -0700270 ScreenOnListener mScreenOnListener;
271 final Runnable mWindowManagerDrawCallback = new Runnable() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700272 @Override
Craig Mautner13f6ea72014-06-23 14:57:02 -0700273 public void run() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700274 if (DEBUG_WAKEUP) Slog.i(TAG, "All windows ready for display!");
275 mHandler.sendEmptyMessage(MSG_WINDOW_MANAGER_DRAWN_COMPLETE);
276 }
277 };
278 final ShowListener mKeyguardDelegateCallback = new ShowListener() {
279 @Override
280 public void onShown(IBinder windowToken) {
281 if (DEBUG_WAKEUP) Slog.d(TAG, "mKeyguardDelegate.ShowListener.onShown.");
282 mHandler.sendEmptyMessage(MSG_KEYGUARD_DRAWN_COMPLETE);
283 }
284 };
285
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800286 GlobalActions mGlobalActions;
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700287 volatile boolean mPowerKeyHandled; // accessed from input reader and handler thread
288 boolean mPendingPowerKeyUpCanceled;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800289 Handler mHandler;
satok1bc0a492012-04-25 22:47:12 +0900290 WindowState mLastInputMethodWindow = null;
291 WindowState mLastInputMethodTargetWindow = null;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800292
Winson Chungd42a6cf2014-06-03 16:24:04 -0700293 boolean mRecentsVisible;
Winson Chung1e8d71b2014-05-16 17:05:22 -0700294 int mRecentAppsHeldModifiers;
Jeff Browncf39bdf2012-05-18 14:41:19 -0700295 boolean mLanguageSwitchKeyPressed;
Jeff Brown68b909d2011-12-07 16:36:01 -0800296
Jeff Brown2e7760e2012-04-11 15:14:55 -0700297 int mLidState = LID_ABSENT;
Jeff Browndaa37532012-05-01 15:54:03 -0700298 boolean mHaveBuiltInKeyboard;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800299
Dianne Hackbornc777e072010-02-12 13:07:59 -0800300 boolean mSystemReady;
Dianne Hackbornba24e4d2011-09-01 11:17:06 -0700301 boolean mSystemBooted;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800302 boolean mHdmiPlugged;
Jeff Brown4f5fa282014-06-12 19:19:15 -0700303 IUiModeManager mUiModeManager;
Daniel Sandler6396c722013-04-16 20:19:09 -0400304 int mUiMode;
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700305 int mDockMode = Intent.EXTRA_DOCK_STATE_UNDOCKED;
Mike Lockwood1753f7f2009-08-24 14:49:07 -0700306 int mLidOpenRotation;
Mike Lockwood2d1efbd2009-09-16 12:15:53 -0400307 int mCarDockRotation;
308 int mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -0700309 int mUndockedHdmiRotation;
310 int mDemoHdmiRotation;
311 boolean mDemoHdmiRotationLock;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400312
Jeff Browna20dda42014-05-27 20:57:24 -0700313 boolean mWakeGestureEnabledSetting;
314 MyWakeGestureListener mWakeGestureListener;
315
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700316 // Default display does not rotate, apps that require non-default orientation will have to
317 // have the orientation emulated.
318 private boolean mForceDefaultOrientation = false;
319
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400320 int mUserRotationMode = WindowManagerPolicy.USER_ROTATION_FREE;
321 int mUserRotation = Surface.ROTATION_0;
Jeff Brown207673cd2012-06-05 17:47:11 -0700322 boolean mAccelerometerDefault;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400323
Jeff Brownbcdfc622014-03-06 19:13:04 -0800324 boolean mSupportAutoRotation;
Jeff Brownd3187e32011-09-21 19:26:44 -0700325 int mAllowAllRotations = -1;
Mike Lockwoode9867d22009-09-20 01:59:02 -0400326 boolean mCarDockEnablesAccelerometer;
327 boolean mDeskDockEnablesAccelerometer;
Dianne Hackborn2862fff2009-09-15 22:56:29 -0700328 int mLidKeyboardAccessibility;
329 int mLidNavigationAccessibility;
Jeff Brownc458ce92012-04-30 14:58:40 -0700330 boolean mLidControlsSleep;
Jeff Brown6d8fd272014-05-20 21:24:38 -0700331 int mShortPressOnPowerBehavior = -1;
Joe Onoratod208e702010-10-08 16:22:43 -0400332 int mLongPressOnPowerBehavior = -1;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -0700333 boolean mScreenOnEarly = false;
334 boolean mScreenOnFully = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800335 boolean mOrientationSensorEnabled = false;
336 int mCurrentAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800337 boolean mHasSoftInput = false;
Daniel Sandlerdd73ee42013-10-11 22:19:59 -0400338 boolean mTranslucentDecorEnabled = true;
Craig Mautner967212c2013-04-13 21:10:58 -0700339
Jeff Brown70825162012-03-28 17:27:48 -0700340 int mPointerLocationMode = 0; // guarded by mLock
Joe Onorato664644d2011-01-23 17:53:23 -0800341
342 // The last window we were told about in focusChanged.
343 WindowState mFocusedWindow;
Dianne Hackborne0f085d2011-11-30 18:41:15 -0800344 IApplicationToken mFocusedApp;
Joe Onorato664644d2011-01-23 17:53:23 -0800345
Jeff Brown70825162012-03-28 17:27:48 -0700346 PointerLocationView mPointerLocationView;
Jeff Brown32cbc38552011-12-01 14:01:49 -0800347
Dianne Hackbornc652de82013-02-15 16:32:56 -0800348 // The current size of the screen; really; extends into the overscan area of
349 // the screen and doesn't account for any system elements like the status bar.
350 int mOverscanScreenLeft, mOverscanScreenTop;
351 int mOverscanScreenWidth, mOverscanScreenHeight;
352 // The current visible size of the screen; really; (ir)regardless of whether the status
353 // bar can be hidden but not extending into the overscan area.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800354 int mUnrestrictedScreenLeft, mUnrestrictedScreenTop;
355 int mUnrestrictedScreenWidth, mUnrestrictedScreenHeight;
Dianne Hackborn313440842013-02-19 19:22:59 -0800356 // Like mOverscanScreen*, but allowed to move into the overscan region where appropriate.
357 int mRestrictedOverscanScreenLeft, mRestrictedOverscanScreenTop;
358 int mRestrictedOverscanScreenWidth, mRestrictedOverscanScreenHeight;
Dianne Hackborn82de1ae2010-10-28 11:28:39 -0700359 // The current size of the screen; these may be different than (0,0)-(dw,dh)
360 // if the status bar can't be hidden; in that case it effectively carves out
361 // that area of the display from all other windows.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800362 int mRestrictedScreenLeft, mRestrictedScreenTop;
363 int mRestrictedScreenWidth, mRestrictedScreenHeight;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700364 // During layout, the current screen borders accounting for any currently
365 // visible system UI elements.
366 int mSystemLeft, mSystemTop, mSystemRight, mSystemBottom;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700367 // For applications requesting stable content insets, these are them.
368 int mStableLeft, mStableTop, mStableRight, mStableBottom;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -0700369 // For applications requesting stable content insets but have also set the
370 // fullscreen window flag, these are the stable dimensions without the status bar.
371 int mStableFullscreenLeft, mStableFullscreenTop;
372 int mStableFullscreenRight, mStableFullscreenBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800373 // During layout, the current screen borders with all outer decoration
374 // (status bar, input method dock) accounted for.
375 int mCurLeft, mCurTop, mCurRight, mCurBottom;
376 // During layout, the frame in which content should be displayed
377 // to the user, accounting for all screen decoration except for any
378 // space they deem as available for other content. This is usually
379 // the same as mCur*, but may be larger if the screen decor has supplied
380 // content insets.
381 int mContentLeft, mContentTop, mContentRight, mContentBottom;
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700382 // During layout, the frame in which voice content should be displayed
383 // to the user, accounting for all screen decoration except for any
384 // space they deem as available for other content.
385 int mVoiceContentLeft, mVoiceContentTop, mVoiceContentRight, mVoiceContentBottom;
Dianne Hackborn8e11ef02010-11-18 19:47:42 -0800386 // During layout, the current screen borders along which input method
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800387 // windows are placed.
388 int mDockLeft, mDockTop, mDockRight, mDockBottom;
389 // During layout, the layer at which the doc window is placed.
390 int mDockLayer;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700391 // During layout, this is the layer of the status bar.
392 int mStatusBarLayer;
Dianne Hackborne26ab702011-10-16 13:21:33 -0700393 int mLastSystemUiFlags;
394 // Bits that we are in the process of clearing, so we want to prevent
395 // them from being set by applications until everything has been updated
396 // to have them clear.
397 int mResettingSystemUiFlags = 0;
398 // Bits that we are currently always keeping cleared.
399 int mForceClearedSystemUiFlags = 0;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -0800400 // What we last reported to system UI about whether the compatibility
401 // menu needs to be displayed.
402 boolean mLastFocusNeedsMenu = false;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700403
404 FakeWindow mHideNavFakeWindow = null;
405
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800406 static final Rect mTmpParentFrame = new Rect();
407 static final Rect mTmpDisplayFrame = new Rect();
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800408 static final Rect mTmpOverscanFrame = new Rect();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800409 static final Rect mTmpContentFrame = new Rect();
410 static final Rect mTmpVisibleFrame = new Rect();
John Spurlock46646232013-09-30 22:32:42 -0400411 static final Rect mTmpDecorFrame = new Rect();
Adrian Roosfa104232014-06-20 16:10:14 -0700412 static final Rect mTmpStableFrame = new Rect();
Dianne Hackborn1f903c32011-09-13 19:18:06 -0700413 static final Rect mTmpNavigationFrame = new Rect();
Craig Mautner967212c2013-04-13 21:10:58 -0700414
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800415 WindowState mTopFullscreenOpaqueWindowState;
Craig Mautner2bc789b2014-03-19 19:48:38 -0700416 HashSet<IApplicationToken> mAppsToBeHidden = new HashSet<IApplicationToken>();
Joe Onorato93056472010-09-10 10:30:46 -0400417 boolean mTopIsFullscreen;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800418 boolean mForceStatusBar;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -0700419 boolean mForceStatusBarFromKeyguard;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700420 boolean mHideLockScreen;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -0800421 boolean mForcingShowNavBar;
422 int mForcingShowNavBarLayer;
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700423
424 // States of keyguard dismiss.
425 private static final int DISMISS_KEYGUARD_NONE = 0; // Keyguard not being dismissed.
426 private static final int DISMISS_KEYGUARD_START = 1; // Keyguard needs to be dismissed.
427 private static final int DISMISS_KEYGUARD_CONTINUE = 2; // Keyguard has been dismissed.
428 int mDismissKeyguard = DISMISS_KEYGUARD_NONE;
429
430 /** The window that is currently dismissing the keyguard. Dismissing the keyguard must only
431 * be done once per window. */
432 private WindowState mWinDismissingKeyguard;
433
Craig Mautnerc9457fa2014-06-06 14:27:48 -0700434 /** The window that is currently showing "over" the keyguard. If there is an app window
435 * belonging to another app on top of this the keyguard shows. If there is a fullscreen
436 * app window under this, still dismiss the keyguard but don't show the app underneath. Show
437 * the wallpaper. */
438 private WindowState mWinShowWhenLocked;
439
Dianne Hackborn7ad44382012-10-18 17:46:00 -0700440 boolean mShowingLockscreen;
441 boolean mShowingDream;
442 boolean mDreamingLockscreen;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800443 boolean mHomePressed;
Jeff Browncaca8812013-05-09 13:34:33 -0700444 boolean mHomeConsumed;
445 boolean mHomeDoubleTapPending;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800446 Intent mHomeIntent;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700447 Intent mCarDockIntent;
448 Intent mDeskDockIntent;
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700449 boolean mSearchKeyShortcutPending;
450 boolean mConsumeSearchKeyUp;
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700451 boolean mAssistKeyLongPressed;
Michael Wright6a62e552014-06-03 19:19:48 -0700452 boolean mPendingMetaAction;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800453
Mike Lockwood28569302010-01-28 11:54:40 -0500454 // support for activating the lock screen while the screen is on
455 boolean mAllowLockscreenWhenOn;
456 int mLockScreenTimeout;
457 boolean mLockScreenTimerActive;
458
David Brownbaf8d092010-03-08 21:52:59 -0800459 // Behavior of ENDCALL Button. (See Settings.System.END_BUTTON_BEHAVIOR.)
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800460 int mEndcallBehavior;
David Brownbaf8d092010-03-08 21:52:59 -0800461
462 // Behavior of POWER button while in-call and screen on.
463 // (See Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR.)
464 int mIncallPowerBehavior;
465
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700466 Display mDisplay;
467
Dianne Hackborn9d132642011-04-21 17:26:39 -0700468 int mLandscapeRotation = 0; // default landscape rotation
469 int mSeascapeRotation = 0; // "other" landscape rotation, 180 degrees from mLandscapeRotation
470 int mPortraitRotation = 0; // default portrait rotation
471 int mUpsideDownRotation = 0; // "other" portrait rotation
Mitsuru Oshima831d0d92009-06-16 18:27:18 -0700472
Dianne Hackbornc652de82013-02-15 16:32:56 -0800473 int mOverscanLeft = 0;
474 int mOverscanTop = 0;
475 int mOverscanRight = 0;
476 int mOverscanBottom = 0;
477
Joe Onorato46b0d682010-11-22 17:37:27 -0800478 // What we do when the user long presses on home
Jeff Browncaca8812013-05-09 13:34:33 -0700479 private int mLongPressOnHomeBehavior;
480
481 // What we do when the user double-taps on home
482 private int mDoubleTapOnHomeBehavior;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800483
Winson Chung9112ec32011-06-27 13:15:32 -0700484 // Screenshot trigger states
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700485 // Time to volume and power must be pressed within this interval of each other.
486 private static final long SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS = 150;
Winson Chung1cea2f32012-10-08 20:42:01 -0700487 // Increase the chord delay when taking a screenshot from the keyguard
488 private static final float KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER = 2.5f;
Christopher Tatee90585f2012-03-05 18:56:25 -0800489 private boolean mScreenshotChordEnabled;
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700490 private boolean mVolumeDownKeyTriggered;
491 private long mVolumeDownKeyTime;
492 private boolean mVolumeDownKeyConsumedByScreenshotChord;
493 private boolean mVolumeUpKeyTriggered;
494 private boolean mPowerKeyTriggered;
495 private long mPowerKeyTime;
Winson Chung9112ec32011-06-27 13:15:32 -0700496
Michael Wrightb854e242013-02-05 17:54:02 -0800497 /* The number of steps between min and max brightness */
498 private static final int BRIGHTNESS_STEPS = 10;
499
Christopher Tate5e08af02012-09-21 17:17:22 -0700500 SettingsObserver mSettingsObserver;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800501 ShortcutManager mShortcutManager;
502 PowerManager.WakeLock mBroadcastWakeLock;
Jeff Brown40013652012-05-16 21:22:36 -0700503 boolean mHavePendingMediaKeyRepeatWithWakeLock;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800504
Craig Mautnerd625ab22013-09-06 13:40:31 -0700505 private int mCurrentUserId;
506
Justin Kohd378ad72013-04-01 12:18:26 -0700507 // Maps global key codes to the components that will handle them.
508 private GlobalKeyManager mGlobalKeyManager;
509
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700510 // Fallback actions by key code.
511 private final SparseArray<KeyCharacterMap.FallbackAction> mFallbackActions =
512 new SparseArray<KeyCharacterMap.FallbackAction>();
Jeff Brown49ed71d2010-12-06 17:13:33 -0800513
Jeff Brown70825162012-03-28 17:27:48 -0700514 private static final int MSG_ENABLE_POINTER_LOCATION = 1;
515 private static final int MSG_DISABLE_POINTER_LOCATION = 2;
Jeff Brown40013652012-05-16 21:22:36 -0700516 private static final int MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK = 3;
517 private static final int MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK = 4;
Craig Mautner8a0da012014-05-31 15:13:37 -0700518 private static final int MSG_KEYGUARD_DRAWN_COMPLETE = 5;
519 private static final int MSG_KEYGUARD_DRAWN_TIMEOUT = 6;
520 private static final int MSG_WINDOW_MANAGER_DRAWN_COMPLETE = 7;
521 private static final int MSG_WAKING_UP = 8;
Craig Mautner84984fa2014-06-19 11:19:20 -0700522 private static final int MSG_DISPATCH_SHOW_RECENTS = 9;
Jeff Brown70825162012-03-28 17:27:48 -0700523
524 private class PolicyHandler extends Handler {
525 @Override
526 public void handleMessage(Message msg) {
527 switch (msg.what) {
528 case MSG_ENABLE_POINTER_LOCATION:
529 enablePointerLocation();
530 break;
531 case MSG_DISABLE_POINTER_LOCATION:
532 disablePointerLocation();
533 break;
Jeff Brown40013652012-05-16 21:22:36 -0700534 case MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK:
535 dispatchMediaKeyWithWakeLock((KeyEvent)msg.obj);
536 break;
537 case MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK:
538 dispatchMediaKeyRepeatWithWakeLock((KeyEvent)msg.obj);
539 break;
Craig Mautner84984fa2014-06-19 11:19:20 -0700540 case MSG_DISPATCH_SHOW_RECENTS:
541 showRecentApps(false);
542 break;
Craig Mautner8a0da012014-05-31 15:13:37 -0700543 case MSG_KEYGUARD_DRAWN_COMPLETE:
544 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mKeyguardDrawComplete");
545 mKeyguardDrawComplete = true;
546 finishScreenTurningOn();
547 break;
548 case MSG_KEYGUARD_DRAWN_TIMEOUT:
549 Slog.w(TAG, "Keyguard drawn timeout. Setting mKeyguardDrawComplete");
550 mKeyguardDrawComplete = true;
551 finishScreenTurningOn();
552 break;
553 case MSG_WINDOW_MANAGER_DRAWN_COMPLETE:
554 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mWindowManagerDrawComplete");
555 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
556 mWindowManagerDrawComplete = true;
557 finishScreenTurningOn();
558 break;
559 case MSG_WAKING_UP:
560 handleWakingUp((ScreenOnListener) msg.obj);
561 break;
Jeff Brown70825162012-03-28 17:27:48 -0700562 }
563 }
564 }
565
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800566 private UEventObserver mHDMIObserver = new UEventObserver() {
567 @Override
568 public void onUEvent(UEventObserver.UEvent event) {
569 setHdmiPlugged("1".equals(event.get("SWITCH_STATE")));
570 }
571 };
572
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800573 class SettingsObserver extends ContentObserver {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800574 SettingsObserver(Handler handler) {
575 super(handler);
576 }
David Brownbaf8d092010-03-08 21:52:59 -0800577
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800578 void observe() {
Christopher Tate5e08af02012-09-21 17:17:22 -0700579 // Observe all users' changes
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800580 ContentResolver resolver = mContext.getContentResolver();
581 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700582 Settings.System.END_BUTTON_BEHAVIOR), false, this,
583 UserHandle.USER_ALL);
David Brownbaf8d092010-03-08 21:52:59 -0800584 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700585 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR), false, this,
586 UserHandle.USER_ALL);
Jeff Browna20dda42014-05-27 20:57:24 -0700587 resolver.registerContentObserver(Settings.Secure.getUriFor(
588 Settings.Secure.WAKE_GESTURE_ENABLED), false, this,
589 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800590 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700591 Settings.System.ACCELEROMETER_ROTATION), false, this,
592 UserHandle.USER_ALL);
Mike Lockwood28569302010-01-28 11:54:40 -0500593 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700594 Settings.System.USER_ROTATION), false, this,
595 UserHandle.USER_ALL);
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400596 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700597 Settings.System.SCREEN_OFF_TIMEOUT), false, this,
598 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800599 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700600 Settings.System.POINTER_LOCATION), false, this,
601 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800602 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700603 Settings.Secure.DEFAULT_INPUT_METHOD), false, this,
604 UserHandle.USER_ALL);
John Spurlockd9b70bd2014-02-06 17:02:44 -0500605 resolver.registerContentObserver(Settings.Secure.getUriFor(
John Spurlockf1a36642013-10-12 17:50:42 -0400606 Settings.Secure.IMMERSIVE_MODE_CONFIRMATIONS), false, this,
Christopher Tate5e08af02012-09-21 17:17:22 -0700607 UserHandle.USER_ALL);
John Spurlockc6d1c602014-01-17 15:22:06 -0500608 resolver.registerContentObserver(Settings.Global.getUriFor(
609 Settings.Global.POLICY_CONTROL), false, this,
610 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800611 updateSettings();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800612 }
613
614 @Override public void onChange(boolean selfChange) {
Dianne Hackbornc777e072010-02-12 13:07:59 -0800615 updateSettings();
Jeff Brown01a98dd2011-09-20 15:08:29 -0700616 updateRotation(false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800617 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800618 }
Craig Mautner967212c2013-04-13 21:10:58 -0700619
Jeff Browna20dda42014-05-27 20:57:24 -0700620 class MyWakeGestureListener extends WakeGestureListener {
621 MyWakeGestureListener(Context context, Handler handler) {
622 super(context, handler);
623 }
624
625 @Override
626 public void onWakeUp() {
627 synchronized (mLock) {
628 if (shouldEnableWakeGestureLp()) {
Jeff Browne07b94b2014-06-18 15:56:27 -0700629 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
Jeff Browna20dda42014-05-27 20:57:24 -0700630 mPowerManager.wakeUp(SystemClock.uptimeMillis());
631 }
632 }
633 }
634 }
635
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800636 class MyOrientationListener extends WindowOrientationListener {
Craig Mautnereee29c42013-01-17 14:44:34 -0800637 MyOrientationListener(Context context, Handler handler) {
638 super(context, handler);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800639 }
Craig Mautner967212c2013-04-13 21:10:58 -0700640
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800641 @Override
Jeff Brownc0347aa2011-09-23 17:26:09 -0700642 public void onProposedRotationChanged(int rotation) {
Craig Mautnereda67292013-04-28 13:50:14 -0700643 if (localLOGV) Slog.v(TAG, "onProposedRotationChanged, rotation=" + rotation);
Jeff Brown01a98dd2011-09-20 15:08:29 -0700644 updateRotation(false);
645 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800646 }
647 MyOrientationListener mOrientationListener;
648
John Spurlock27735a42013-08-14 17:57:38 -0400649 private final BarController mStatusBarController = new BarController("StatusBar",
John Spurlock5b9145b2013-08-20 15:13:47 -0400650 View.STATUS_BAR_TRANSIENT,
651 View.STATUS_BAR_UNHIDE,
John Spurlockbd957402013-10-03 11:38:39 -0400652 View.STATUS_BAR_TRANSLUCENT,
653 StatusBarManager.WINDOW_STATUS_BAR,
654 WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
John Spurlock5b9145b2013-08-20 15:13:47 -0400655
John Spurlock27735a42013-08-14 17:57:38 -0400656 private final BarController mNavigationBarController = new BarController("NavigationBar",
John Spurlock5b9145b2013-08-20 15:13:47 -0400657 View.NAVIGATION_BAR_TRANSIENT,
658 View.NAVIGATION_BAR_UNHIDE,
John Spurlockbd957402013-10-03 11:38:39 -0400659 View.NAVIGATION_BAR_TRANSLUCENT,
660 StatusBarManager.WINDOW_NAVIGATION_BAR,
661 WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
John Spurlock5b9145b2013-08-20 15:13:47 -0400662
John Spurlockf1a36642013-10-12 17:50:42 -0400663 private ImmersiveModeConfirmation mImmersiveModeConfirmation;
John Spurlock32beb2c2013-03-11 10:16:47 -0400664
Craig Mautner037aa8d2013-06-07 10:35:44 -0700665 private SystemGesturesPointerEventListener mSystemGestures;
John Spurlock32beb2c2013-03-11 10:16:47 -0400666
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700667 IStatusBarService getStatusBarService() {
668 synchronized (mServiceAquireLock) {
669 if (mStatusBarService == null) {
670 mStatusBarService = IStatusBarService.Stub.asInterface(
671 ServiceManager.getService("statusbar"));
672 }
673 return mStatusBarService;
674 }
675 }
676
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700677 /*
678 * We always let the sensor be switched on by default except when
679 * the user has explicitly disabled sensor based rotation or when the
680 * screen is switched off.
681 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700682 boolean needSensorRunningLp() {
Jeff Brownbcdfc622014-03-06 19:13:04 -0800683 if (mSupportAutoRotation) {
684 if (mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
685 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
686 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT
687 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) {
688 // If the application has explicitly requested to follow the
689 // orientation, then we need to turn the sensor on.
690 return true;
691 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800692 }
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700693 if ((mCarDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_CAR) ||
Jeff Brown1a693182011-11-08 14:44:16 -0800694 (mDeskDockEnablesAccelerometer && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
695 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
696 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK))) {
Mike Lockwoode9867d22009-09-20 01:59:02 -0400697 // enable accelerometer if we are docked in a dock that enables accelerometer
698 // orientation management,
699 return true;
700 }
Jeff Brown207673cd2012-06-05 17:47:11 -0700701 if (mUserRotationMode == USER_ROTATION_LOCKED) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800702 // If the setting for using the sensor by default is enabled, then
703 // we will always leave it on. Note that the user could go to
704 // a window that forces an orientation that does not use the
705 // sensor and in theory we could turn it off... however, when next
706 // turning it on we won't have a good value for the current
707 // orientation for a little bit, which can cause orientation
708 // changes to lag, so we'd like to keep it always on. (It will
709 // still be turned off when the screen is off.)
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700710 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800711 }
Jeff Brownbcdfc622014-03-06 19:13:04 -0800712 return mSupportAutoRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800713 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700714
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800715 /*
716 * Various use cases for invoking this function
717 * screen turning off, should always disable listeners if already enabled
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700718 * screen turned on and current app has sensor based orientation, enable listeners
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800719 * if not already enabled
720 * screen turned on and current app does not have sensor orientation, disable listeners if
721 * already enabled
722 * screen turning on and current app has sensor based orientation, enable listeners if needed
723 * screen turning on and current app has nosensor based orientation, do nothing
724 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700725 void updateOrientationListenerLp() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800726 if (!mOrientationListener.canDetectOrientation()) {
727 // If sensor is turned off or nonexistent for some reason
728 return;
729 }
730 //Could have been invoked due to screen turning on or off or
731 //change of the currently visible window's orientation
Craig Mautnereda67292013-04-28 13:50:14 -0700732 if (localLOGV) Slog.v(TAG, "Screen status="+mScreenOnEarly+
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800733 ", current orientation="+mCurrentAppOrientation+
734 ", SensorEnabled="+mOrientationSensorEnabled);
735 boolean disable = true;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -0700736 if (mScreenOnEarly) {
The Android Open Source Project0727d222009-03-11 12:11:58 -0700737 if (needSensorRunningLp()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800738 disable = false;
739 //enable listener if not already enabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700740 if (!mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800741 mOrientationListener.enable();
Craig Mautnereda67292013-04-28 13:50:14 -0700742 if(localLOGV) Slog.v(TAG, "Enabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800743 mOrientationSensorEnabled = true;
744 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700745 }
746 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800747 //check if sensors need to be disabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700748 if (disable && mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800749 mOrientationListener.disable();
Craig Mautnereda67292013-04-28 13:50:14 -0700750 if(localLOGV) Slog.v(TAG, "Disabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800751 mOrientationSensorEnabled = false;
752 }
753 }
754
Jeff Brown4d396052010-10-29 21:50:21 -0700755 private void interceptPowerKeyDown(boolean handled) {
756 mPowerKeyHandled = handled;
757 if (!handled) {
Justin Kohfeabd2c2014-05-02 10:02:44 -0700758 mHandler.postDelayed(mPowerLongPress,
759 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Jeff Brown4d396052010-10-29 21:50:21 -0700760 }
761 }
762
763 private boolean interceptPowerKeyUp(boolean canceled) {
764 if (!mPowerKeyHandled) {
765 mHandler.removeCallbacks(mPowerLongPress);
766 return !canceled;
Jeff Brown4d396052010-10-29 21:50:21 -0700767 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700768 return false;
769 }
770
771 private void cancelPendingPowerKeyAction() {
772 if (!mPowerKeyHandled) {
773 mHandler.removeCallbacks(mPowerLongPress);
774 }
Jeff Brownff204712011-10-25 21:27:54 -0700775 if (mPowerKeyTriggered) {
776 mPendingPowerKeyUpCanceled = true;
777 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700778 }
779
780 private void interceptScreenshotChord() {
Christopher Tatee90585f2012-03-05 18:56:25 -0800781 if (mScreenshotChordEnabled
782 && mVolumeDownKeyTriggered && mPowerKeyTriggered && !mVolumeUpKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700783 final long now = SystemClock.uptimeMillis();
784 if (now <= mVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS
785 && now <= mPowerKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) {
786 mVolumeDownKeyConsumedByScreenshotChord = true;
787 cancelPendingPowerKeyAction();
788
Jeff Sharkey2991fa32012-12-05 18:06:43 -0800789 mHandler.postDelayed(mScreenshotRunnable, getScreenshotChordLongPressDelay());
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700790 }
791 }
792 }
793
Winson Chung1cea2f32012-10-08 20:42:01 -0700794 private long getScreenshotChordLongPressDelay() {
Jim Miller5ecd8112013-01-09 18:50:26 -0800795 if (mKeyguardDelegate.isShowing()) {
Winson Chung1cea2f32012-10-08 20:42:01 -0700796 // Double the time it takes to take a screenshot from the keyguard
797 return (long) (KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER *
Justin Kohfeabd2c2014-05-02 10:02:44 -0700798 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Winson Chung1cea2f32012-10-08 20:42:01 -0700799 }
Justin Kohfeabd2c2014-05-02 10:02:44 -0700800 return ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout();
Winson Chung1cea2f32012-10-08 20:42:01 -0700801 }
802
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700803 private void cancelPendingScreenshotChordAction() {
Jeff Sharkey2991fa32012-12-05 18:06:43 -0800804 mHandler.removeCallbacks(mScreenshotRunnable);
Jeff Brown4d396052010-10-29 21:50:21 -0700805 }
806
Jeff Brown6d8fd272014-05-20 21:24:38 -0700807 private void powerShortPress(long eventTime) {
808 if (mShortPressOnPowerBehavior < 0) {
809 mShortPressOnPowerBehavior = mContext.getResources().getInteger(
810 com.android.internal.R.integer.config_shortPressOnPowerBehavior);
811 }
812
813 switch (mShortPressOnPowerBehavior) {
814 case SHORT_PRESS_POWER_NOTHING:
815 break;
816 case SHORT_PRESS_POWER_GO_TO_SLEEP:
817 mPowerManager.goToSleep(eventTime,
818 PowerManager.GO_TO_SLEEP_REASON_USER, 0);
819 break;
820 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP:
821 mPowerManager.goToSleep(eventTime,
822 PowerManager.GO_TO_SLEEP_REASON_USER,
823 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
824 break;
825 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME:
826 mPowerManager.goToSleep(eventTime,
827 PowerManager.GO_TO_SLEEP_REASON_USER,
828 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
829 launchHomeFromHotKey();
830 break;
831 }
832 }
833
Jeff Brown4d396052010-10-29 21:50:21 -0700834 private final Runnable mPowerLongPress = new Runnable() {
Craig Mautnerf1b67412012-09-19 13:18:29 -0700835 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800836 public void run() {
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700837 // The context isn't read
838 if (mLongPressOnPowerBehavior < 0) {
Jeff Brown850c5b72012-10-01 15:17:22 -0700839 mLongPressOnPowerBehavior = mContext.getResources().getInteger(
840 com.android.internal.R.integer.config_longPressOnPowerBehavior);
Joe Onoratod208e702010-10-08 16:22:43 -0400841 }
Jeff Brown850c5b72012-10-01 15:17:22 -0700842 int resolvedBehavior = mLongPressOnPowerBehavior;
843 if (FactoryTest.isLongPressOnPowerOffEnabled()) {
844 resolvedBehavior = LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM;
845 }
846
847 switch (resolvedBehavior) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700848 case LONG_PRESS_POWER_NOTHING:
849 break;
850 case LONG_PRESS_POWER_GLOBAL_ACTIONS:
851 mPowerKeyHandled = true;
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -0700852 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
853 performAuditoryFeedbackForAccessibilityIfNeed();
854 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700855 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
856 showGlobalActionsDialog();
857 break;
858 case LONG_PRESS_POWER_SHUT_OFF:
Jeff Brown9a538ee2012-08-20 14:56:57 -0700859 case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM:
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700860 mPowerKeyHandled = true;
861 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
862 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
Jeff Brown850c5b72012-10-01 15:17:22 -0700863 mWindowManagerFuncs.shutdown(resolvedBehavior == LONG_PRESS_POWER_SHUT_OFF);
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700864 break;
865 }
866 }
867 };
868
Jeff Sharkey2991fa32012-12-05 18:06:43 -0800869 private final Runnable mScreenshotRunnable = new Runnable() {
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800870 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700871 public void run() {
872 takeScreenshot();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800873 }
874 };
875
876 void showGlobalActionsDialog() {
877 if (mGlobalActions == null) {
Jeff Brown7304c342012-05-11 18:42:42 -0700878 mGlobalActions = new GlobalActions(mContext, mWindowManagerFuncs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800879 }
Mike Lockwood3a74bd32011-08-12 13:55:22 -0700880 final boolean keyguardShowing = keyguardIsShowingTq();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800881 mGlobalActions.showDialog(keyguardShowing, isDeviceProvisioned());
882 if (keyguardShowing) {
883 // since it took two seconds of long press to bring this up,
884 // poke the wake lock so they have some time to see the dialog.
Jim Miller25190572013-02-28 17:36:24 -0800885 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800886 }
887 }
888
889 boolean isDeviceProvisioned() {
Jeff Brownbf6f6f92012-09-25 15:03:20 -0700890 return Settings.Global.getInt(
891 mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800892 }
893
Maurice Lam99c6e072014-04-28 18:24:28 -0700894 boolean isUserSetupComplete() {
895 return Settings.Secure.getIntForUser(mContext.getContentResolver(),
896 Settings.Secure.USER_SETUP_COMPLETE, 0, UserHandle.USER_CURRENT) != 0;
897 }
898
Patrick Dubroyece94522011-02-23 18:35:01 -0800899 private void handleLongPressOnHome() {
Joe Onorato46b0d682010-11-22 17:37:27 -0800900 if (mLongPressOnHomeBehavior != LONG_PRESS_HOME_NOTHING) {
Jeff Browncaca8812013-05-09 13:34:33 -0700901 mHomeConsumed = true;
Joe Onorato46b0d682010-11-22 17:37:27 -0800902 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
Patrick Dubroyece94522011-02-23 18:35:01 -0800903
Jeff Browncaca8812013-05-09 13:34:33 -0700904 if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI) {
905 toggleRecentApps();
906 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_ASSIST) {
907 launchAssistAction();
Jim Millere6ad1a82010-08-20 19:25:39 -0700908 }
909 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800910 }
Patrick Dubroyece94522011-02-23 18:35:01 -0800911
Jeff Browncaca8812013-05-09 13:34:33 -0700912 private void handleDoubleTapOnHome() {
913 if (mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
914 mHomeConsumed = true;
915 toggleRecentApps();
916 }
917 }
918
919 private final Runnable mHomeDoubleTapTimeoutRunnable = new Runnable() {
920 @Override
921 public void run() {
922 if (mHomeDoubleTapPending) {
923 mHomeDoubleTapPending = false;
924 launchHomeFromHotKey();
925 }
926 }
927 };
928
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800929 /** {@inheritDoc} */
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800930 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800931 public void init(Context context, IWindowManager windowManager,
Jeff Brown96307042012-07-27 15:51:34 -0700932 WindowManagerFuncs windowManagerFuncs) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800933 mContext = context;
934 mWindowManager = windowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700935 mWindowManagerFuncs = windowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -0700936 mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class);
937
Jeff Brown70825162012-03-28 17:27:48 -0700938 mHandler = new PolicyHandler();
Jeff Browna20dda42014-05-27 20:57:24 -0700939 mWakeGestureListener = new MyWakeGestureListener(mContext, mHandler);
Craig Mautnereee29c42013-01-17 14:44:34 -0800940 mOrientationListener = new MyOrientationListener(mContext, mHandler);
Jeff Brownc0347aa2011-09-23 17:26:09 -0700941 try {
942 mOrientationListener.setCurrentRotation(windowManager.getRotation());
943 } catch (RemoteException ex) { }
Christopher Tate5e08af02012-09-21 17:17:22 -0700944 mSettingsObserver = new SettingsObserver(mHandler);
945 mSettingsObserver.observe();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800946 mShortcutManager = new ShortcutManager(context, mHandler);
947 mShortcutManager.observe();
Daniel Sandler6396c722013-04-16 20:19:09 -0400948 mUiMode = context.getResources().getInteger(
949 com.android.internal.R.integer.config_defaultUiModeType);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800950 mHomeIntent = new Intent(Intent.ACTION_MAIN, null);
951 mHomeIntent.addCategory(Intent.CATEGORY_HOME);
952 mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
953 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700954 mCarDockIntent = new Intent(Intent.ACTION_MAIN, null);
955 mCarDockIntent.addCategory(Intent.CATEGORY_CAR_DOCK);
956 mCarDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
957 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
958 mDeskDockIntent = new Intent(Intent.ACTION_MAIN, null);
959 mDeskDockIntent.addCategory(Intent.CATEGORY_DESK_DOCK);
960 mDeskDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
961 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Jim Millere6ad1a82010-08-20 19:25:39 -0700962
Jeff Brown96307042012-07-27 15:51:34 -0700963 mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
964 mBroadcastWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800965 "PhoneWindowManager.mBroadcastWakeLock");
966 mEnableShiftMenuBugReports = "1".equals(SystemProperties.get("ro.debuggable"));
Jeff Brownbcdfc622014-03-06 19:13:04 -0800967 mSupportAutoRotation = mContext.getResources().getBoolean(
968 com.android.internal.R.bool.config_supportAutoRotation);
Dianne Hackborn2862fff2009-09-15 22:56:29 -0700969 mLidOpenRotation = readRotation(
Mike Lockwood2d1efbd2009-09-16 12:15:53 -0400970 com.android.internal.R.integer.config_lidOpenRotation);
971 mCarDockRotation = readRotation(
972 com.android.internal.R.integer.config_carDockRotation);
973 mDeskDockRotation = readRotation(
974 com.android.internal.R.integer.config_deskDockRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -0700975 mUndockedHdmiRotation = readRotation(
976 com.android.internal.R.integer.config_undockedHdmiRotation);
Mike Lockwoode9867d22009-09-20 01:59:02 -0400977 mCarDockEnablesAccelerometer = mContext.getResources().getBoolean(
978 com.android.internal.R.bool.config_carDockEnablesAccelerometer);
979 mDeskDockEnablesAccelerometer = mContext.getResources().getBoolean(
980 com.android.internal.R.bool.config_deskDockEnablesAccelerometer);
Dianne Hackborn2862fff2009-09-15 22:56:29 -0700981 mLidKeyboardAccessibility = mContext.getResources().getInteger(
982 com.android.internal.R.integer.config_lidKeyboardAccessibility);
983 mLidNavigationAccessibility = mContext.getResources().getInteger(
984 com.android.internal.R.integer.config_lidNavigationAccessibility);
Jeff Brownc458ce92012-04-30 14:58:40 -0700985 mLidControlsSleep = mContext.getResources().getBoolean(
986 com.android.internal.R.bool.config_lidControlsSleep);
Daniel Sandlerdd73ee42013-10-11 22:19:59 -0400987 mTranslucentDecorEnabled = mContext.getResources().getBoolean(
988 com.android.internal.R.bool.config_enableTranslucentDecor);
Jeff Brownf71343d2013-05-31 17:59:11 -0700989 readConfigurationDependentBehaviors();
Jeff Browncaca8812013-05-09 13:34:33 -0700990
Svetoslav8e3feb12014-02-24 13:46:47 -0800991 mAccessibilityManager = (AccessibilityManager) context.getSystemService(
992 Context.ACCESSIBILITY_SERVICE);
993
Mike Lockwood1753f7f2009-08-24 14:49:07 -0700994 // register for dock events
Dianne Hackborn78968392010-03-04 20:47:56 -0800995 IntentFilter filter = new IntentFilter();
996 filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE);
997 filter.addAction(UiModeManager.ACTION_EXIT_CAR_MODE);
998 filter.addAction(UiModeManager.ACTION_ENTER_DESK_MODE);
999 filter.addAction(UiModeManager.ACTION_EXIT_DESK_MODE);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001000 filter.addAction(Intent.ACTION_DOCK_EVENT);
1001 Intent intent = context.registerReceiver(mDockReceiver, filter);
1002 if (intent != null) {
1003 // Retrieve current sticky dock event broadcast.
1004 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
1005 Intent.EXTRA_DOCK_STATE_UNDOCKED);
1006 }
Daniel Sandler7e37df52011-11-16 22:08:23 -08001007
Jeff Brown6aaf2952012-10-05 16:01:08 -07001008 // register for dream-related broadcasts
1009 filter = new IntentFilter();
1010 filter.addAction(Intent.ACTION_DREAMING_STARTED);
1011 filter.addAction(Intent.ACTION_DREAMING_STOPPED);
1012 context.registerReceiver(mDreamReceiver, filter);
1013
Christopher Tate5e08af02012-09-21 17:17:22 -07001014 // register for multiuser-relevant broadcasts
1015 filter = new IntentFilter(Intent.ACTION_USER_SWITCHED);
1016 context.registerReceiver(mMultiuserReceiver, filter);
1017
John Spurlock57306e62013-04-22 09:48:49 -04001018 // monitor for system gestures
Craig Mautner037aa8d2013-06-07 10:35:44 -07001019 mSystemGestures = new SystemGesturesPointerEventListener(context,
1020 new SystemGesturesPointerEventListener.Callbacks() {
John Spurlock57306e62013-04-22 09:48:49 -04001021 @Override
1022 public void onSwipeFromTop() {
John Spurlock04db1762013-05-13 12:46:41 -04001023 if (mStatusBar != null) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001024 requestTransientBars(mStatusBar);
John Spurlock04db1762013-05-13 12:46:41 -04001025 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04001026 }
1027 @Override
1028 public void onSwipeFromBottom() {
John Spurlock04db1762013-05-13 12:46:41 -04001029 if (mNavigationBar != null && mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001030 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001031 }
1032 }
1033 @Override
1034 public void onSwipeFromRight() {
John Spurlock04db1762013-05-13 12:46:41 -04001035 if (mNavigationBar != null && !mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001036 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001037 }
1038 }
1039 @Override
1040 public void onDebug() {
John Spurlockd67ec252013-09-05 11:31:54 -04001041 // no-op
John Spurlockad3e6cb2013-04-30 08:47:43 -04001042 }
1043 });
John Spurlockf1a36642013-10-12 17:50:42 -04001044 mImmersiveModeConfirmation = new ImmersiveModeConfirmation(mContext);
Craig Mautner037aa8d2013-06-07 10:35:44 -07001045 mWindowManagerFuncs.registerPointerEventListener(mSystemGestures);
John Spurlock32beb2c2013-03-11 10:16:47 -04001046
Jeff Brownc2346132012-04-13 01:55:38 -07001047 mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001048 mLongPressVibePattern = getLongIntArray(mContext.getResources(),
1049 com.android.internal.R.array.config_longPressVibePattern);
1050 mVirtualKeyVibePattern = getLongIntArray(mContext.getResources(),
1051 com.android.internal.R.array.config_virtualKeyVibePattern);
Amith Yamasanic33cb712010-02-10 15:21:49 -08001052 mKeyboardTapVibePattern = getLongIntArray(mContext.getResources(),
1053 com.android.internal.R.array.config_keyboardTapVibePattern);
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07001054 mClockTickVibePattern = getLongIntArray(mContext.getResources(),
1055 com.android.internal.R.array.config_clockTickVibePattern);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001056 mSafeModeDisabledVibePattern = getLongIntArray(mContext.getResources(),
1057 com.android.internal.R.array.config_safeModeDisabledVibePattern);
1058 mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(),
1059 com.android.internal.R.array.config_safeModeEnabledVibePattern);
Daniel Sandler40427442010-07-16 11:44:52 -04001060
Christopher Tatee90585f2012-03-05 18:56:25 -08001061 mScreenshotChordEnabled = mContext.getResources().getBoolean(
1062 com.android.internal.R.bool.config_enableScreenshotChord);
1063
Justin Kohd378ad72013-04-01 12:18:26 -07001064 mGlobalKeyManager = new GlobalKeyManager(mContext);
1065
Joe Onoratoea495d42011-04-06 11:41:11 -07001066 // Controls rotation and the like.
1067 initializeHdmiState();
Dianne Hackborn40011092011-09-22 13:37:48 -07001068
1069 // Match current screen state.
Jeff Brown26c6a502014-04-11 02:15:54 -07001070 if (mPowerManager.isInteractive()) {
Jeff Brown140ffc72014-05-01 15:18:00 -07001071 wakingUp(null);
Dianne Hackborn40011092011-09-22 13:37:48 -07001072 } else {
Jeff Brown140ffc72014-05-01 15:18:00 -07001073 goingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
Dianne Hackborn40011092011-09-22 13:37:48 -07001074 }
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001075 }
1076
Jeff Brownf71343d2013-05-31 17:59:11 -07001077 /**
1078 * Read values from config.xml that may be overridden depending on
1079 * the configuration of the device.
1080 * eg. Disable long press on home goes to recents on sw600dp.
1081 */
1082 private void readConfigurationDependentBehaviors() {
1083 mLongPressOnHomeBehavior = mContext.getResources().getInteger(
1084 com.android.internal.R.integer.config_longPressOnHomeBehavior);
1085 if (mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING ||
1086 mLongPressOnHomeBehavior > LONG_PRESS_HOME_ASSIST) {
1087 mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1088 }
1089
1090 mDoubleTapOnHomeBehavior = mContext.getResources().getInteger(
1091 com.android.internal.R.integer.config_doubleTapOnHomeBehavior);
1092 if (mDoubleTapOnHomeBehavior < DOUBLE_TAP_HOME_NOTHING ||
1093 mDoubleTapOnHomeBehavior > DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1094 mDoubleTapOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1095 }
1096 }
1097
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001098 @Override
Dianne Hackborndde331c2012-08-03 14:01:57 -07001099 public void setInitialDisplaySize(Display display, int width, int height, int density) {
Jeff Brownef981a42013-08-07 14:13:37 -07001100 // This method might be called before the policy has been fully initialized
1101 // or for other displays we don't care about.
1102 if (mContext == null || display.getDisplayId() != Display.DEFAULT_DISPLAY) {
1103 return;
Dianne Hackbornc652de82013-02-15 16:32:56 -08001104 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001105 mDisplay = display;
1106
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001107 final Resources res = mContext.getResources();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001108 int shortSize, longSize;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001109 if (width > height) {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001110 shortSize = height;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001111 longSize = width;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001112 mLandscapeRotation = Surface.ROTATION_0;
1113 mSeascapeRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001114 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001115 mPortraitRotation = Surface.ROTATION_90;
1116 mUpsideDownRotation = Surface.ROTATION_270;
1117 } else {
1118 mPortraitRotation = Surface.ROTATION_270;
1119 mUpsideDownRotation = Surface.ROTATION_90;
1120 }
1121 } else {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001122 shortSize = width;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001123 longSize = height;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001124 mPortraitRotation = Surface.ROTATION_0;
1125 mUpsideDownRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001126 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001127 mLandscapeRotation = Surface.ROTATION_270;
1128 mSeascapeRotation = Surface.ROTATION_90;
1129 } else {
1130 mLandscapeRotation = Surface.ROTATION_90;
1131 mSeascapeRotation = Surface.ROTATION_270;
1132 }
1133 }
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001134
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001135 mStatusBarHeight =
1136 res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001137
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001138 // Height of the navigation bar when presented horizontally at bottom
1139 mNavigationBarHeightForRotation[mPortraitRotation] =
1140 mNavigationBarHeightForRotation[mUpsideDownRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001141 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_height);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001142 mNavigationBarHeightForRotation[mLandscapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001143 mNavigationBarHeightForRotation[mSeascapeRotation] = res.getDimensionPixelSize(
1144 com.android.internal.R.dimen.navigation_bar_height_landscape);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001145
1146 // Width of the navigation bar when presented vertically along one side
1147 mNavigationBarWidthForRotation[mPortraitRotation] =
1148 mNavigationBarWidthForRotation[mUpsideDownRotation] =
1149 mNavigationBarWidthForRotation[mLandscapeRotation] =
1150 mNavigationBarWidthForRotation[mSeascapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001151 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_width);
Daniel Sandler4a066c52012-04-20 14:49:13 -04001152
1153 // SystemUI (status bar) layout policy
Dianne Hackborndde331c2012-08-03 14:01:57 -07001154 int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / density;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001155 int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / density;
Daniel Sandler4a066c52012-04-20 14:49:13 -04001156
Craig Mautnerd4ec33242013-07-22 10:37:43 -07001157 // Allow the navigation bar to move on small devices (phones).
1158 mNavigationBarCanMove = shortSizeDp < 600;
Daniel Sandler36412a72011-08-04 09:35:13 -04001159
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001160 mHasNavigationBar = res.getBoolean(com.android.internal.R.bool.config_showNavigationBar);
John Spurlock80f00c12013-06-13 11:10:51 -04001161 // Allow a system property to override this. Used by the emulator.
1162 // See also hasNavigationBar().
1163 String navBarOverride = SystemProperties.get("qemu.hw.mainkeys");
1164 if ("1".equals(navBarOverride)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001165 mHasNavigationBar = false;
John Spurlock80f00c12013-06-13 11:10:51 -04001166 } else if ("0".equals(navBarOverride)) {
1167 mHasNavigationBar = true;
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04001168 }
1169
Jeff Brown27f1d672012-10-17 18:32:34 -07001170 // For demo purposes, allow the rotation of the HDMI display to be controlled.
1171 // By default, HDMI locks rotation to landscape.
Erik Gilling9a41ef82011-09-26 19:21:03 -07001172 if ("portrait".equals(SystemProperties.get("persist.demo.hdmirotation"))) {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001173 mDemoHdmiRotation = mPortraitRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001174 } else {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001175 mDemoHdmiRotation = mLandscapeRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001176 }
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001177 mDemoHdmiRotationLock = SystemProperties.getBoolean("persist.demo.hdmirotationlock", false);
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001178
1179 // Only force the default orientation if the screen is xlarge, at least 960dp x 720dp, per
1180 // http://developer.android.com/guide/practices/screens_support.html#range
1181 mForceDefaultOrientation = longSizeDp >= 960 && shortSizeDp >= 720 &&
1182 res.getBoolean(com.android.internal.R.bool.config_forceDefaultOrientation) &&
1183 // For debug purposes the next line turns this feature off with:
1184 // $ adb shell setprop config.override_forced_orient true
1185 // $ adb shell wm size reset
1186 !"true".equals(SystemProperties.get("config.override_forced_orient"));
1187 }
1188
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001189 /**
1190 * @return whether the navigation bar can be hidden, e.g. the device has a
1191 * navigation bar and touch exploration is not enabled
1192 */
1193 private boolean canHideNavigationBar() {
Svetoslav8e3feb12014-02-24 13:46:47 -08001194 return mHasNavigationBar
1195 && !mAccessibilityManager.isTouchExplorationEnabled();
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001196 }
1197
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001198 @Override
1199 public boolean isDefaultOrientationForced() {
1200 return mForceDefaultOrientation;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001201 }
1202
Dianne Hackbornc652de82013-02-15 16:32:56 -08001203 @Override
1204 public void setDisplayOverscan(Display display, int left, int top, int right, int bottom) {
1205 if (display.getDisplayId() == Display.DEFAULT_DISPLAY) {
1206 mOverscanLeft = left;
1207 mOverscanTop = top;
1208 mOverscanRight = right;
1209 mOverscanBottom = bottom;
1210 }
1211 }
1212
Dianne Hackbornc777e072010-02-12 13:07:59 -08001213 public void updateSettings() {
1214 ContentResolver resolver = mContext.getContentResolver();
1215 boolean updateRotation = false;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001216 synchronized (mLock) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001217 mEndcallBehavior = Settings.System.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001218 Settings.System.END_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001219 Settings.System.END_BUTTON_BEHAVIOR_DEFAULT,
1220 UserHandle.USER_CURRENT);
1221 mIncallPowerBehavior = Settings.Secure.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001222 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001223 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT,
1224 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001225
Jeff Browna20dda42014-05-27 20:57:24 -07001226 // Configure wake gesture.
1227 boolean wakeGestureEnabledSetting = Settings.Secure.getIntForUser(resolver,
1228 Settings.Secure.WAKE_GESTURE_ENABLED, 0,
1229 UserHandle.USER_CURRENT) != 0;
1230 if (mWakeGestureEnabledSetting != wakeGestureEnabledSetting) {
1231 mWakeGestureEnabledSetting = wakeGestureEnabledSetting;
1232 updateWakeGestureListenerLp();
1233 }
1234
Jeff Brown207673cd2012-06-05 17:47:11 -07001235 // Configure rotation lock.
Christopher Tate5e08af02012-09-21 17:17:22 -07001236 int userRotation = Settings.System.getIntForUser(resolver,
1237 Settings.System.USER_ROTATION, Surface.ROTATION_0,
1238 UserHandle.USER_CURRENT);
Jeff Brown207673cd2012-06-05 17:47:11 -07001239 if (mUserRotation != userRotation) {
1240 mUserRotation = userRotation;
1241 updateRotation = true;
1242 }
Christopher Tate5e08af02012-09-21 17:17:22 -07001243 int userRotationMode = Settings.System.getIntForUser(resolver,
1244 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
Jeff Brown207673cd2012-06-05 17:47:11 -07001245 WindowManagerPolicy.USER_ROTATION_FREE :
1246 WindowManagerPolicy.USER_ROTATION_LOCKED;
1247 if (mUserRotationMode != userRotationMode) {
1248 mUserRotationMode = userRotationMode;
1249 updateRotation = true;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001250 updateOrientationListenerLp();
1251 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001252
Dianne Hackbornc777e072010-02-12 13:07:59 -08001253 if (mSystemReady) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001254 int pointerLocation = Settings.System.getIntForUser(resolver,
1255 Settings.System.POINTER_LOCATION, 0, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001256 if (mPointerLocationMode != pointerLocation) {
1257 mPointerLocationMode = pointerLocation;
Jeff Brown70825162012-03-28 17:27:48 -07001258 mHandler.sendEmptyMessage(pointerLocation != 0 ?
1259 MSG_ENABLE_POINTER_LOCATION : MSG_DISABLE_POINTER_LOCATION);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001260 }
1261 }
1262 // use screen off timeout setting as the timeout for the lockscreen
Christopher Tate5e08af02012-09-21 17:17:22 -07001263 mLockScreenTimeout = Settings.System.getIntForUser(resolver,
1264 Settings.System.SCREEN_OFF_TIMEOUT, 0, UserHandle.USER_CURRENT);
1265 String imId = Settings.Secure.getStringForUser(resolver,
1266 Settings.Secure.DEFAULT_INPUT_METHOD, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001267 boolean hasSoftInput = imId != null && imId.length() > 0;
1268 if (mHasSoftInput != hasSoftInput) {
1269 mHasSoftInput = hasSoftInput;
1270 updateRotation = true;
1271 }
John Spurlockf1a36642013-10-12 17:50:42 -04001272 if (mImmersiveModeConfirmation != null) {
John Spurlock4355a532014-02-19 09:49:25 -05001273 mImmersiveModeConfirmation.loadSetting(mCurrentUserId);
John Spurlockd67ec252013-09-05 11:31:54 -04001274 }
John Spurlockc6d1c602014-01-17 15:22:06 -05001275 PolicyControl.reloadFromSetting(mContext);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001276 }
1277 if (updateRotation) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07001278 updateRotation(true);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001279 }
Jeff Brown70825162012-03-28 17:27:48 -07001280 }
1281
Jeff Browna20dda42014-05-27 20:57:24 -07001282 private void updateWakeGestureListenerLp() {
1283 if (shouldEnableWakeGestureLp()) {
1284 mWakeGestureListener.requestWakeUpTrigger();
1285 } else {
1286 mWakeGestureListener.cancelWakeUpTrigger();
1287 }
1288 }
1289
1290 private boolean shouldEnableWakeGestureLp() {
1291 return mWakeGestureEnabledSetting && !mScreenOnEarly
1292 && (!mLidControlsSleep || mLidState != LID_CLOSED)
1293 && mWakeGestureListener.isSupported();
1294 }
1295
Jeff Brown70825162012-03-28 17:27:48 -07001296 private void enablePointerLocation() {
1297 if (mPointerLocationView == null) {
1298 mPointerLocationView = new PointerLocationView(mContext);
1299 mPointerLocationView.setPrintCoords(false);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001300 WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
1301 WindowManager.LayoutParams.MATCH_PARENT,
1302 WindowManager.LayoutParams.MATCH_PARENT);
Jeff Brown3b2b3542010-10-15 00:54:27 -07001303 lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001304 lp.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN
1305 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
1306 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1307 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
Jeff Brown90fc9052012-10-01 14:44:24 -07001308 if (ActivityManager.isHighEndGfx()) {
1309 lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
1310 lp.privateFlags |=
1311 WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED;
1312 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001313 lp.format = PixelFormat.TRANSLUCENT;
1314 lp.setTitle("PointerLocation");
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001315 WindowManager wm = (WindowManager)
Dianne Hackbornc777e072010-02-12 13:07:59 -08001316 mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Browncc4f7db2011-08-30 20:34:48 -07001317 lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL;
Jeff Brown70825162012-03-28 17:27:48 -07001318 wm.addView(mPointerLocationView, lp);
Michael Wrightc9c487e2013-11-07 18:55:09 -08001319 mWindowManagerFuncs.registerPointerEventListener(mPointerLocationView);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001320 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001321 }
Jeff Brown70825162012-03-28 17:27:48 -07001322
1323 private void disablePointerLocation() {
Jeff Brown70825162012-03-28 17:27:48 -07001324 if (mPointerLocationView != null) {
Michael Wrightc9c487e2013-11-07 18:55:09 -08001325 mWindowManagerFuncs.unregisterPointerEventListener(mPointerLocationView);
1326 WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Brown70825162012-03-28 17:27:48 -07001327 wm.removeView(mPointerLocationView);
1328 mPointerLocationView = null;
1329 }
1330 }
1331
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001332 private int readRotation(int resID) {
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001333 try {
1334 int rotation = mContext.getResources().getInteger(resID);
1335 switch (rotation) {
1336 case 0:
1337 return Surface.ROTATION_0;
1338 case 90:
1339 return Surface.ROTATION_90;
1340 case 180:
1341 return Surface.ROTATION_180;
1342 case 270:
1343 return Surface.ROTATION_270;
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001344 }
1345 } catch (Resources.NotFoundException e) {
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001346 // fall through
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001347 }
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001348 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001349 }
1350
1351 /** {@inheritDoc} */
Craig Mautner88400d32012-09-30 12:35:45 -07001352 @Override
Dianne Hackbornc2293022013-02-06 23:14:49 -08001353 public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001354 int type = attrs.type;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001355
1356 outAppOp[0] = AppOpsManager.OP_NONE;
1357
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001358 if (type < WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW
1359 || type > WindowManager.LayoutParams.LAST_SYSTEM_WINDOW) {
Jeff Brown98365d72012-08-19 20:30:52 -07001360 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001361 }
1362 String permission = null;
1363 switch (type) {
1364 case TYPE_TOAST:
1365 // XXX right now the app process has complete control over
1366 // this... should introduce a token to let the system
1367 // monitor/control what they are doing.
Jason Monk1c7c3192014-06-26 12:52:18 -04001368 outAppOp[0] = AppOpsManager.OP_TOAST_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001369 break;
Daniel Sandler7d276c32012-01-30 14:33:52 -05001370 case TYPE_DREAM:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001371 case TYPE_INPUT_METHOD:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001372 case TYPE_WALLPAPER:
keunyounga446bf02013-06-21 19:07:57 -07001373 case TYPE_PRIVATE_PRESENTATION:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001374 case TYPE_VOICE_INTERACTION:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001375 // The window manager will check these.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001376 break;
1377 case TYPE_PHONE:
1378 case TYPE_PRIORITY_PHONE:
1379 case TYPE_SYSTEM_ALERT:
1380 case TYPE_SYSTEM_ERROR:
1381 case TYPE_SYSTEM_OVERLAY:
1382 permission = android.Manifest.permission.SYSTEM_ALERT_WINDOW;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001383 outAppOp[0] = AppOpsManager.OP_SYSTEM_ALERT_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001384 break;
1385 default:
1386 permission = android.Manifest.permission.INTERNAL_SYSTEM_WINDOW;
1387 }
1388 if (permission != null) {
1389 if (mContext.checkCallingOrSelfPermission(permission)
1390 != PackageManager.PERMISSION_GRANTED) {
Jeff Brown98365d72012-08-19 20:30:52 -07001391 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001392 }
1393 }
Jeff Brown98365d72012-08-19 20:30:52 -07001394 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001395 }
Craig Mautner88400d32012-09-30 12:35:45 -07001396
1397 @Override
1398 public boolean checkShowToOwnerOnly(WindowManager.LayoutParams attrs) {
1399
1400 // If this switch statement is modified, modify the comment in the declarations of
1401 // the type in {@link WindowManager.LayoutParams} as well.
1402 switch (attrs.type) {
1403 default:
1404 // These are the windows that by default are shown only to the user that created
1405 // them. If this needs to be overridden, set
1406 // {@link WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS} in
1407 // {@link WindowManager.LayoutParams}. Note that permission
1408 // {@link android.Manifest.permission.INTERNAL_SYSTEM_WINDOW} is required as well.
1409 if ((attrs.privateFlags & PRIVATE_FLAG_SHOW_FOR_ALL_USERS) == 0) {
1410 return true;
1411 }
1412 break;
1413
1414 // These are the windows that by default are shown to all users. However, to
1415 // protect against spoofing, check permissions below.
1416 case TYPE_APPLICATION_STARTING:
1417 case TYPE_BOOT_PROGRESS:
1418 case TYPE_DISPLAY_OVERLAY:
1419 case TYPE_HIDDEN_NAV_CONSUMER:
Jim Miller5ecd8112013-01-09 18:50:26 -08001420 case TYPE_KEYGUARD_SCRIM:
Craig Mautner88400d32012-09-30 12:35:45 -07001421 case TYPE_KEYGUARD_DIALOG:
1422 case TYPE_MAGNIFICATION_OVERLAY:
1423 case TYPE_NAVIGATION_BAR:
1424 case TYPE_NAVIGATION_BAR_PANEL:
1425 case TYPE_PHONE:
1426 case TYPE_POINTER:
1427 case TYPE_PRIORITY_PHONE:
1428 case TYPE_RECENTS_OVERLAY:
1429 case TYPE_SEARCH_BAR:
1430 case TYPE_STATUS_BAR:
1431 case TYPE_STATUS_BAR_PANEL:
1432 case TYPE_STATUS_BAR_SUB_PANEL:
1433 case TYPE_SYSTEM_DIALOG:
1434 case TYPE_UNIVERSE_BACKGROUND:
1435 case TYPE_VOLUME_OVERLAY:
keunyounga446bf02013-06-21 19:07:57 -07001436 case TYPE_PRIVATE_PRESENTATION:
Craig Mautner88400d32012-09-30 12:35:45 -07001437 break;
1438 }
1439
1440 // Check if third party app has set window to system window type.
1441 return mContext.checkCallingOrSelfPermission(
1442 android.Manifest.permission.INTERNAL_SYSTEM_WINDOW)
1443 != PackageManager.PERMISSION_GRANTED;
1444 }
1445
Craig Mautner967212c2013-04-13 21:10:58 -07001446 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001447 public void adjustWindowParamsLw(WindowManager.LayoutParams attrs) {
1448 switch (attrs.type) {
1449 case TYPE_SYSTEM_OVERLAY:
Jeff Brown3b2b3542010-10-15 00:54:27 -07001450 case TYPE_SECURE_SYSTEM_OVERLAY:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001451 // These types of windows can't receive input events.
1452 attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1453 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001454 attrs.flags &= ~WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001455 break;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001456 case TYPE_STATUS_BAR:
1457
1458 // If the Keyguard is in a hidden state (occluded by another window), we force to
1459 // remove the wallpaper and keyguard flag so that any change in-flight after setting
1460 // the keyguard as occluded wouldn't set these flags again.
1461 // See {@link #processKeyguardSetHiddenResultLw}.
1462 if (mKeyguardHidden) {
1463 attrs.flags &= ~WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
1464 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
1465 }
1466 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001467 }
Adrian Roos38502112014-04-09 21:04:11 +02001468
1469 if (attrs.type != TYPE_STATUS_BAR) {
1470 // The status bar is the only window allowed to exhibit keyguard behavior.
1471 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
1472 }
Adrian Roosea562512014-05-05 13:33:03 +02001473
1474 if (ActivityManager.isHighEndGfx()
1475 && (attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0) {
1476 attrs.subtreeSystemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_STABLE
1477 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
1478 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
1479 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001480 }
RoboErik8a2cfc32014-05-16 11:19:38 -07001481
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001482 void readLidState() {
Jeff Brown2e7760e2012-04-11 15:14:55 -07001483 mLidState = mWindowManagerFuncs.getLidState();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001484 }
RoboErik8a2cfc32014-05-16 11:19:38 -07001485
Jeff Browndaa37532012-05-01 15:54:03 -07001486 private boolean isHidden(int accessibilityMode) {
1487 switch (accessibilityMode) {
1488 case 1:
1489 return mLidState == LID_CLOSED;
1490 case 2:
1491 return mLidState == LID_OPEN;
1492 default:
1493 return false;
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001494 }
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001495 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001496
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001497 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07001498 @Override
Jeff Browndaa37532012-05-01 15:54:03 -07001499 public void adjustConfigurationLw(Configuration config, int keyboardPresence,
1500 int navigationPresence) {
1501 mHaveBuiltInKeyboard = (keyboardPresence & PRESENCE_INTERNAL) != 0;
1502
Jeff Brownf71343d2013-05-31 17:59:11 -07001503 readConfigurationDependentBehaviors();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001504 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07001505 applyLidSwitchState();
Jeff Brownd04a88c2011-01-16 14:05:47 -08001506
Jeff Browndaa37532012-05-01 15:54:03 -07001507 if (config.keyboard == Configuration.KEYBOARD_NOKEYS
1508 || (keyboardPresence == PRESENCE_INTERNAL
1509 && isHidden(mLidKeyboardAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001510 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_YES;
Jeff Browndaa37532012-05-01 15:54:03 -07001511 if (!mHasSoftInput) {
1512 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_YES;
1513 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001514 }
1515
Jeff Browndaa37532012-05-01 15:54:03 -07001516 if (config.navigation == Configuration.NAVIGATION_NONAV
1517 || (navigationPresence == PRESENCE_INTERNAL
1518 && isHidden(mLidNavigationAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001519 config.navigationHidden = Configuration.NAVIGATIONHIDDEN_YES;
Jeff Brownd04a88c2011-01-16 14:05:47 -08001520 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001521 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001522
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001523 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07001524 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001525 public int windowTypeToLayerLw(int type) {
1526 if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001527 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001528 }
1529 switch (type) {
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001530 case TYPE_UNIVERSE_BACKGROUND:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001531 return 1;
keunyounga446bf02013-06-21 19:07:57 -07001532 case TYPE_PRIVATE_PRESENTATION:
1533 return 2;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001534 case TYPE_WALLPAPER:
1535 // wallpaper is at the bottom, though the window manager may move it.
1536 return 2;
1537 case TYPE_PHONE:
1538 return 3;
1539 case TYPE_SEARCH_BAR:
1540 return 4;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001541 case TYPE_VOICE_INTERACTION:
1542 // voice interaction layer is almost immediately above apps.
1543 return 5;
Craig Mautner88400d32012-09-30 12:35:45 -07001544 case TYPE_RECENTS_OVERLAY:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001545 case TYPE_SYSTEM_DIALOG:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001546 return 6;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001547 case TYPE_TOAST:
1548 // toasts and the plugged-in battery thing
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001549 return 7;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001550 case TYPE_PRIORITY_PHONE:
1551 // SIM errors and unlock. Not sure if this really should be in a high layer.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001552 return 8;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001553 case TYPE_DREAM:
1554 // used for Dreams (screensavers with TYPE_DREAM windows)
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001555 return 9;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001556 case TYPE_SYSTEM_ALERT:
1557 // like the ANR / app crashed dialogs
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001558 return 10;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001559 case TYPE_INPUT_METHOD:
1560 // on-screen keyboards and other such input method user interfaces go here.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001561 return 11;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001562 case TYPE_INPUT_METHOD_DIALOG:
1563 // on-screen keyboards and other such input method user interfaces go here.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001564 return 12;
Jim Miller5ecd8112013-01-09 18:50:26 -08001565 case TYPE_KEYGUARD_SCRIM:
1566 // the safety window that shows behind keyguard while keyguard is starting
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001567 return 13;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001568 case TYPE_STATUS_BAR_SUB_PANEL:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001569 return 14;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001570 case TYPE_STATUS_BAR:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001571 return 15;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001572 case TYPE_STATUS_BAR_PANEL:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001573 return 16;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001574 case TYPE_KEYGUARD_DIALOG:
1575 return 17;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001576 case TYPE_VOLUME_OVERLAY:
1577 // the on-screen volume indicator and controller shown when the user
1578 // changes the device volume
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001579 return 18;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001580 case TYPE_SYSTEM_OVERLAY:
1581 // the on-screen volume indicator and controller shown when the user
1582 // changes the device volume
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001583 return 19;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001584 case TYPE_NAVIGATION_BAR:
1585 // the navigation bar, if available, shows atop most things
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001586 return 20;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001587 case TYPE_NAVIGATION_BAR_PANEL:
1588 // some panels (e.g. search) need to show on top of the navigation bar
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001589 return 21;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001590 case TYPE_SYSTEM_ERROR:
1591 // system-level error dialogs
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001592 return 22;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001593 case TYPE_MAGNIFICATION_OVERLAY:
1594 // used to highlight the magnified portion of a display
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001595 return 23;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001596 case TYPE_DISPLAY_OVERLAY:
1597 // used to simulate secondary display devices
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001598 return 24;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001599 case TYPE_DRAG:
1600 // the drag layer: input for drag-and-drop is associated with this window,
1601 // which sits above all other focusable windows
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001602 return 25;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001603 case TYPE_SECURE_SYSTEM_OVERLAY:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001604 return 26;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001605 case TYPE_BOOT_PROGRESS:
1606 return 27;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001607 case TYPE_POINTER:
1608 // the (mouse) pointer layer
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001609 return 28;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001610 case TYPE_HIDDEN_NAV_CONSUMER:
1611 return 29;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001612 }
1613 Log.e(TAG, "Unknown window type: " + type);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001614 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001615 }
1616
1617 /** {@inheritDoc} */
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001618 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001619 public int subWindowTypeToLayerLw(int type) {
1620 switch (type) {
1621 case TYPE_APPLICATION_PANEL:
1622 case TYPE_APPLICATION_ATTACHED_DIALOG:
1623 return APPLICATION_PANEL_SUBLAYER;
1624 case TYPE_APPLICATION_MEDIA:
1625 return APPLICATION_MEDIA_SUBLAYER;
Dianne Hackborn5cb8d792009-05-21 17:34:15 -07001626 case TYPE_APPLICATION_MEDIA_OVERLAY:
1627 return APPLICATION_MEDIA_OVERLAY_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001628 case TYPE_APPLICATION_SUB_PANEL:
1629 return APPLICATION_SUB_PANEL_SUBLAYER;
1630 }
1631 Log.e(TAG, "Unknown sub-window type: " + type);
1632 return 0;
1633 }
1634
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001635 @Override
Dianne Hackbornabe0da02009-09-18 01:55:39 -07001636 public int getMaxWallpaperLayer() {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001637 return windowTypeToLayerLw(TYPE_STATUS_BAR);
Dianne Hackbornabe0da02009-09-18 01:55:39 -07001638 }
1639
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001640 @Override
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001641 public int getAboveUniverseLayer() {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001642 return windowTypeToLayerLw(TYPE_SYSTEM_ERROR);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001643 }
1644
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001645 public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07001646 if (mHasNavigationBar) {
1647 // For a basic navigation bar, when we are in landscape mode we place
1648 // the navigation bar to the side.
Daniel Sandler4a066c52012-04-20 14:49:13 -04001649 if (mNavigationBarCanMove && fullWidth > fullHeight) {
1650 return fullWidth - mNavigationBarWidthForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07001651 }
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001652 }
1653 return fullWidth;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001654 }
1655
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001656 public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07001657 if (mHasNavigationBar) {
1658 // For a basic navigation bar, when we are in portrait mode we place
1659 // the navigation bar to the bottom.
Daniel Sandler4a066c52012-04-20 14:49:13 -04001660 if (!mNavigationBarCanMove || fullWidth < fullHeight) {
1661 return fullHeight - mNavigationBarHeightForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07001662 }
1663 }
1664 return fullHeight;
Dianne Hackborn69cb8752011-05-19 18:13:32 -07001665 }
1666
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001667 public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation) {
1668 return getNonDecorDisplayWidth(fullWidth, fullHeight, rotation);
Dianne Hackborn69cb8752011-05-19 18:13:32 -07001669 }
1670
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001671 public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation) {
John Spurlock80f00c12013-06-13 11:10:51 -04001672 // There is a separate status bar at the top of the display. We don't count that as part
1673 // of the fixed decor, since it can hide; however, for purposes of configurations,
Dianne Hackborn077ee852012-04-09 16:27:07 -07001674 // we do want to exclude it since applications can't generally use that part
1675 // of the screen.
John Spurlock80f00c12013-06-13 11:10:51 -04001676 return getNonDecorDisplayHeight(fullWidth, fullHeight, rotation) - mStatusBarHeight;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001677 }
1678
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001679 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07001680 public boolean isForceHiding(WindowManager.LayoutParams attrs) {
1681 return (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 ||
1682 (isKeyguardHostWindow(attrs) && isKeyguardSecureIncludingHidden());
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07001683 }
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001684
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001685 @Override
Jorim Jaggi0d674622014-05-21 01:34:15 +02001686 public boolean isKeyguardHostWindow(WindowManager.LayoutParams attrs) {
1687 return attrs.type == TYPE_STATUS_BAR;
1688 }
1689
1690 @Override
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07001691 public boolean canBeForceHidden(WindowState win, WindowManager.LayoutParams attrs) {
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001692 switch (attrs.type) {
1693 case TYPE_STATUS_BAR:
1694 case TYPE_NAVIGATION_BAR:
1695 case TYPE_WALLPAPER:
1696 case TYPE_DREAM:
1697 case TYPE_UNIVERSE_BACKGROUND:
Jim Miller5ecd8112013-01-09 18:50:26 -08001698 case TYPE_KEYGUARD_SCRIM:
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001699 return false;
1700 default:
1701 return true;
1702 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07001703 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001704
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001705 /** {@inheritDoc} */
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001706 @Override
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07001707 public View addStartingWindow(IBinder appToken, String packageName, int theme,
1708 CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes,
Adam Powell04fe6eb2013-05-31 14:39:48 -07001709 int icon, int logo, int windowFlags) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001710 if (!SHOW_STARTING_ANIMATIONS) {
1711 return null;
1712 }
1713 if (packageName == null) {
1714 return null;
1715 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001716
Mathias Jeppssond1443e92012-08-24 15:25:32 +02001717 WindowManager wm = null;
1718 View view = null;
1719
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001720 try {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001721 Context context = mContext;
Craig Mautner6fbda632012-07-03 09:26:39 -07001722 if (DEBUG_STARTING_WINDOW) Slog.d(TAG, "addStartingWindow " + packageName
1723 + ": nonLocalizedLabel=" + nonLocalizedLabel + " theme="
1724 + Integer.toHexString(theme));
Dianne Hackborn247fe742011-01-08 17:25:57 -08001725 if (theme != context.getThemeResId() || labelRes != 0) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001726 try {
1727 context = context.createPackageContext(packageName, 0);
Dianne Hackborn247fe742011-01-08 17:25:57 -08001728 context.setTheme(theme);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001729 } catch (PackageManager.NameNotFoundException e) {
1730 // Ignore
1731 }
1732 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001733
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001734 Window win = PolicyManager.makeNewWindow(context);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001735 final TypedArray ta = win.getWindowStyle();
1736 if (ta.getBoolean(
1737 com.android.internal.R.styleable.Window_windowDisablePreview, false)
1738 || ta.getBoolean(
1739 com.android.internal.R.styleable.Window_windowShowWallpaper,false)) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001740 return null;
1741 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001742
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001743 Resources r = context.getResources();
1744 win.setTitle(r.getText(labelRes, nonLocalizedLabel));
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001745
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001746 win.setType(
1747 WindowManager.LayoutParams.TYPE_APPLICATION_STARTING);
1748 // Force the window flags: this is a fake window, so it is not really
1749 // touchable or focusable by the user. We also add in the ALT_FOCUSABLE_IM
1750 // flag because we do know that the next window will take input
1751 // focus, so we want to get the IME window up on top of us right away.
1752 win.setFlags(
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08001753 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001754 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
1755 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
1756 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08001757 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001758 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
1759 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
1760 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001761
Adam Powell04fe6eb2013-05-31 14:39:48 -07001762 win.setDefaultIcon(icon);
1763 win.setDefaultLogo(logo);
1764
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001765 win.setLayout(WindowManager.LayoutParams.MATCH_PARENT,
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07001766 WindowManager.LayoutParams.MATCH_PARENT);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001767
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001768 final WindowManager.LayoutParams params = win.getAttributes();
1769 params.token = appToken;
1770 params.packageName = packageName;
1771 params.windowAnimations = win.getWindowStyle().getResourceId(
1772 com.android.internal.R.styleable.Window_windowAnimationStyle, 0);
Dianne Hackborn5d927c22011-09-02 12:22:18 -07001773 params.privateFlags |=
1774 WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED;
Craig Mautner88400d32012-09-30 12:35:45 -07001775 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
Adam Lesinski95c42972013-10-02 10:13:27 -07001776
1777 if (!compatInfo.supportsScreen()) {
1778 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
1779 }
1780
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001781 params.setTitle("Starting " + packageName);
1782
Mathias Jeppssond1443e92012-08-24 15:25:32 +02001783 wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
1784 view = win.getDecorView();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001785
1786 if (win.isFloating()) {
1787 // Whoops, there is no way to display an animation/preview
1788 // of such a thing! After all that work... let's skip it.
1789 // (Note that we must do this here because it is in
1790 // getDecorView() where the theme is evaluated... maybe
1791 // we should peek the floating attribute from the theme
1792 // earlier.)
1793 return null;
1794 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001795
Craig Mautner6fbda632012-07-03 09:26:39 -07001796 if (DEBUG_STARTING_WINDOW) Slog.d(
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001797 TAG, "Adding starting window for " + packageName
1798 + " / " + appToken + ": "
1799 + (view.getParent() != null ? view : null));
1800
1801 wm.addView(view, params);
1802
1803 // Only return the view if it was successfully added to the
1804 // window manager... which we can tell by it having a parent.
1805 return view.getParent() != null ? view : null;
Jeff Brown98365d72012-08-19 20:30:52 -07001806 } catch (WindowManager.BadTokenException e) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001807 // ignore
Craig Mautner42bf39e2014-02-21 16:46:22 -08001808 Log.w(TAG, appToken + " already running, starting window not displayed. " +
1809 e.getMessage());
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001810 } catch (RuntimeException e) {
1811 // don't crash if something else bad happens, for example a
1812 // failure loading resources because we are loading from an app
1813 // on external storage that has been unmounted.
1814 Log.w(TAG, appToken + " failed creating starting window", e);
Mathias Jeppssond1443e92012-08-24 15:25:32 +02001815 } finally {
1816 if (view != null && view.getParent() == null) {
1817 Log.w(TAG, "view not successfully added to wm, removing view");
1818 wm.removeViewImmediate(view);
1819 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001820 }
1821
1822 return null;
1823 }
1824
1825 /** {@inheritDoc} */
1826 public void removeStartingWindow(IBinder appToken, View window) {
Craig Mautner6fbda632012-07-03 09:26:39 -07001827 if (DEBUG_STARTING_WINDOW) {
1828 RuntimeException e = new RuntimeException("here");
1829 e.fillInStackTrace();
1830 Log.v(TAG, "Removing starting window for " + appToken + ": " + window, e);
1831 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001832
1833 if (window != null) {
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001834 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001835 wm.removeView(window);
1836 }
1837 }
1838
1839 /**
1840 * Preflight adding a window to the system.
RoboErik8a2cfc32014-05-16 11:19:38 -07001841 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001842 * Currently enforces that three window types are singletons:
1843 * <ul>
1844 * <li>STATUS_BAR_TYPE</li>
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001845 * <li>KEYGUARD_TYPE</li>
1846 * </ul>
RoboErik8a2cfc32014-05-16 11:19:38 -07001847 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001848 * @param win The window to be added
1849 * @param attrs Information about the window to be added
RoboErik8a2cfc32014-05-16 11:19:38 -07001850 *
Jeff Brown98365d72012-08-19 20:30:52 -07001851 * @return If ok, WindowManagerImpl.ADD_OKAY. If too many singletons,
1852 * WindowManagerImpl.ADD_MULTIPLE_SINGLETON
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001853 */
1854 public int prepareAddWindowLw(WindowState win, WindowManager.LayoutParams attrs) {
1855 switch (attrs.type) {
1856 case TYPE_STATUS_BAR:
Joe Onorato8bc6c512010-06-04 16:21:12 -04001857 mContext.enforceCallingOrSelfPermission(
1858 android.Manifest.permission.STATUS_BAR_SERVICE,
1859 "PhoneWindowManager");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001860 if (mStatusBar != null) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001861 if (mStatusBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07001862 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001863 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001864 }
1865 mStatusBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04001866 mStatusBarController.setWindow(win);
John Spurlock8fdfe622014-05-21 17:10:10 -04001867 mKeyguardDelegate.hideScrim();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001868 break;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04001869 case TYPE_NAVIGATION_BAR:
1870 mContext.enforceCallingOrSelfPermission(
1871 android.Manifest.permission.STATUS_BAR_SERVICE,
1872 "PhoneWindowManager");
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001873 if (mNavigationBar != null) {
1874 if (mNavigationBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07001875 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001876 }
1877 }
Daniel Sandler8956dbb2011-04-22 07:55:02 -04001878 mNavigationBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04001879 mNavigationBarController.setWindow(win);
Craig Mautnereda67292013-04-28 13:50:14 -07001880 if (DEBUG_LAYOUT) Slog.i(TAG, "NAVIGATION BAR: " + mNavigationBar);
Daniel Sandler8956dbb2011-04-22 07:55:02 -04001881 break;
Jim Millere898ac52012-04-06 17:10:57 -07001882 case TYPE_NAVIGATION_BAR_PANEL:
1883 mContext.enforceCallingOrSelfPermission(
1884 android.Manifest.permission.STATUS_BAR_SERVICE,
1885 "PhoneWindowManager");
1886 break;
Dianne Hackborn08743722009-12-21 12:16:51 -08001887 case TYPE_STATUS_BAR_PANEL:
Joe Onorato8bc6c512010-06-04 16:21:12 -04001888 mContext.enforceCallingOrSelfPermission(
1889 android.Manifest.permission.STATUS_BAR_SERVICE,
1890 "PhoneWindowManager");
Dianne Hackborn08743722009-12-21 12:16:51 -08001891 break;
Joe Onorato29fc2c92010-11-24 10:26:50 -08001892 case TYPE_STATUS_BAR_SUB_PANEL:
1893 mContext.enforceCallingOrSelfPermission(
1894 android.Manifest.permission.STATUS_BAR_SERVICE,
1895 "PhoneWindowManager");
Joe Onorato29fc2c92010-11-24 10:26:50 -08001896 break;
Jim Miller5ecd8112013-01-09 18:50:26 -08001897 case TYPE_KEYGUARD_SCRIM:
Jim Miller25190572013-02-28 17:36:24 -08001898 if (mKeyguardScrim != null) {
1899 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
1900 }
Jim Miller5ecd8112013-01-09 18:50:26 -08001901 mKeyguardScrim = win;
1902 break;
1903
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001904 }
Jeff Brown98365d72012-08-19 20:30:52 -07001905 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001906 }
1907
1908 /** {@inheritDoc} */
1909 public void removeWindowLw(WindowState win) {
1910 if (mStatusBar == win) {
1911 mStatusBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04001912 mStatusBarController.setWindow(null);
Jim Millerc0b676d2013-03-22 16:11:08 -07001913 mKeyguardDelegate.showScrim();
Jim Miller5ecd8112013-01-09 18:50:26 -08001914 } else if (mKeyguardScrim == win) {
1915 Log.v(TAG, "Removing keyguard scrim");
1916 mKeyguardScrim = null;
1917 } if (mNavigationBar == win) {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04001918 mNavigationBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04001919 mNavigationBarController.setWindow(null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001920 }
1921 }
1922
1923 static final boolean PRINT_ANIM = false;
RoboErik8a2cfc32014-05-16 11:19:38 -07001924
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001925 /** {@inheritDoc} */
Craig Mautner4b71aa12012-12-27 17:20:01 -08001926 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001927 public int selectAnimationLw(WindowState win, int transit) {
1928 if (PRINT_ANIM) Log.i(TAG, "selectAnimation in " + win
1929 + ": transit=" + transit);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001930 if (win == mStatusBar) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001931 boolean isKeyguard = (win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001932 if (transit == TRANSIT_EXIT
1933 || transit == TRANSIT_HIDE) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001934 return isKeyguard ? -1 : R.anim.dock_top_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001935 } else if (transit == TRANSIT_ENTER
1936 || transit == TRANSIT_SHOW) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001937 return isKeyguard ? -1 : R.anim.dock_top_enter;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001938 }
1939 } else if (win == mNavigationBar) {
1940 // This can be on either the bottom or the right.
1941 if (mNavigationBarOnBottom) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08001942 if (transit == TRANSIT_EXIT
1943 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001944 return R.anim.dock_bottom_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001945 } else if (transit == TRANSIT_ENTER
1946 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001947 return R.anim.dock_bottom_enter;
1948 }
1949 } else {
Craig Mautner4b71aa12012-12-27 17:20:01 -08001950 if (transit == TRANSIT_EXIT
1951 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001952 return R.anim.dock_right_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001953 } else if (transit == TRANSIT_ENTER
1954 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001955 return R.anim.dock_right_enter;
1956 }
1957 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08001958 }
1959
1960 if (transit == TRANSIT_PREVIEW_DONE) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001961 if (win.hasAppShownWindows()) {
1962 if (PRINT_ANIM) Log.i(TAG, "**** STARTING EXIT");
1963 return com.android.internal.R.anim.app_starting_exit;
1964 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07001965 } else if (win.getAttrs().type == TYPE_DREAM && mDreamingLockscreen
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001966 && transit == TRANSIT_ENTER) {
1967 // Special case: we are animating in a dream, while the keyguard
1968 // is shown. We don't want an animation on the dream, because
1969 // we need it shown immediately with the keyguard animating away
1970 // to reveal it.
1971 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001972 }
1973
1974 return 0;
1975 }
1976
Craig Mautner3c174372013-02-21 17:54:37 -08001977 @Override
1978 public void selectRotationAnimationLw(int anim[]) {
1979 if (PRINT_ANIM) Slog.i(TAG, "selectRotationAnimation mTopFullscreen="
1980 + mTopFullscreenOpaqueWindowState + " rotationAnimation="
1981 + (mTopFullscreenOpaqueWindowState == null ?
1982 "0" : mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation));
1983 if (mTopFullscreenOpaqueWindowState != null && mTopIsFullscreen) {
1984 switch (mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation) {
1985 case ROTATION_ANIMATION_CROSSFADE:
1986 anim[0] = R.anim.rotation_animation_xfade_exit;
1987 anim[1] = R.anim.rotation_animation_enter;
1988 break;
1989 case ROTATION_ANIMATION_JUMPCUT:
1990 anim[0] = R.anim.rotation_animation_jump_exit;
1991 anim[1] = R.anim.rotation_animation_enter;
1992 break;
1993 case ROTATION_ANIMATION_ROTATE:
1994 default:
1995 anim[0] = anim[1] = 0;
1996 break;
1997 }
1998 } else {
1999 anim[0] = anim[1] = 0;
2000 }
2001 }
2002
2003 @Override
2004 public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId,
2005 boolean forceDefault) {
2006 switch (exitAnimId) {
2007 case R.anim.rotation_animation_xfade_exit:
2008 case R.anim.rotation_animation_jump_exit:
2009 // These are the only cases that matter.
2010 if (forceDefault) {
2011 return false;
2012 }
2013 int anim[] = new int[2];
2014 selectRotationAnimationLw(anim);
2015 return (exitAnimId == anim[0] && enterAnimId == anim[1]);
2016 default:
2017 return true;
2018 }
2019 }
2020
2021 @Override
Dianne Hackborn0c2acff2012-04-12 15:17:07 -07002022 public Animation createForceHideEnterAnimation(boolean onWallpaper) {
Jorim Jaggie29b2db2014-05-30 23:17:03 +02002023 return AnimationUtils.loadAnimation(mContext,
2024 com.android.internal.R.anim.lock_screen_behind_enter);
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002025 }
John Spurlockc8b46ca2013-04-08 12:59:26 -04002026
2027 private static void awakenDreams() {
2028 IDreamManager dreamManager = getDreamManager();
2029 if (dreamManager != null) {
2030 try {
2031 dreamManager.awaken();
2032 } catch (RemoteException e) {
2033 // fine, stay asleep then
2034 }
2035 }
2036 }
2037
2038 static IDreamManager getDreamManager() {
2039 return IDreamManager.Stub.asInterface(
2040 ServiceManager.checkService(DreamService.DREAM_SERVICE));
2041 }
2042
Santos Cordon9eb45932014-06-27 12:28:43 -07002043 TelecommManager getTelecommService() {
2044 return (TelecommManager) mContext.getSystemService(Context.TELECOMM_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002045 }
2046
Jeff Brown4d396052010-10-29 21:50:21 -07002047 static IAudioService getAudioService() {
2048 IAudioService audioService = IAudioService.Stub.asInterface(
2049 ServiceManager.checkService(Context.AUDIO_SERVICE));
2050 if (audioService == null) {
2051 Log.w(TAG, "Unable to find IAudioService interface.");
2052 }
2053 return audioService;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002054 }
2055
2056 boolean keyguardOn() {
2057 return keyguardIsShowingTq() || inKeyguardRestrictedKeyInputMode();
2058 }
2059
2060 private static final int[] WINDOW_TYPES_WHERE_HOME_DOESNT_WORK = {
2061 WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
2062 WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
2063 };
2064
2065 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002066 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002067 public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002068 final boolean keyguardOn = keyguardOn();
Jeff Brown1f245102010-11-18 20:53:46 -08002069 final int keyCode = event.getKeyCode();
2070 final int repeatCount = event.getRepeatCount();
2071 final int metaState = event.getMetaState();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002072 final int flags = event.getFlags();
Jeff Brown1f245102010-11-18 20:53:46 -08002073 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
2074 final boolean canceled = event.isCanceled();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002075
Jeff Brown40013652012-05-16 21:22:36 -07002076 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002077 Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount="
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002078 + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed
2079 + " canceled=" + canceled);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002080 }
2081
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002082 // If we think we might have a volume down & power key chord on the way
2083 // but we're not sure, then tell the dispatcher to wait a little while and
2084 // try again later before dispatching.
Christopher Tatee90585f2012-03-05 18:56:25 -08002085 if (mScreenshotChordEnabled && (flags & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002086 if (mVolumeDownKeyTriggered && !mPowerKeyTriggered) {
2087 final long now = SystemClock.uptimeMillis();
2088 final long timeoutTime = mVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS;
2089 if (now < timeoutTime) {
2090 return timeoutTime - now;
2091 }
2092 }
2093 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
2094 && mVolumeDownKeyConsumedByScreenshotChord) {
2095 if (!down) {
2096 mVolumeDownKeyConsumedByScreenshotChord = false;
2097 }
2098 return -1;
2099 }
2100 }
2101
Michael Wright6a62e552014-06-03 19:19:48 -07002102 // Cancel any pending meta actions if we see any other keys being pressed between the down
2103 // of the meta key and its corresponding up.
2104 if (mPendingMetaAction && keyCode != KeyEvent.KEYCODE_META_LEFT) {
2105 mPendingMetaAction = false;
2106 }
2107
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002108 // First we always handle the home key here, so applications
2109 // can never break it, although if keyguard is on, we do let
2110 // it handle it, because that gives us the correct 5 second
2111 // timeout.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002112 if (keyCode == KeyEvent.KEYCODE_HOME) {
Michael Jurka7f2668c2012-03-27 07:49:52 -07002113
Jeff Brown49ed71d2010-12-06 17:13:33 -08002114 // If we have released the home key, and didn't do anything else
2115 // while it was pressed, then it is time to go home!
Michael Jurka7f2668c2012-03-27 07:49:52 -07002116 if (!down) {
Jeff Browncaca8812013-05-09 13:34:33 -07002117 cancelPreloadRecentApps();
2118
Jeff Brown49ed71d2010-12-06 17:13:33 -08002119 mHomePressed = false;
Jeff Browncaca8812013-05-09 13:34:33 -07002120 if (mHomeConsumed) {
2121 mHomeConsumed = false;
Michael Jurka7f2668c2012-03-27 07:49:52 -07002122 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002123 }
Jeff Browncaca8812013-05-09 13:34:33 -07002124
2125 if (canceled) {
2126 Log.i(TAG, "Ignoring HOME; event canceled.");
2127 return -1;
2128 }
2129
2130 // If an incoming call is ringing, HOME is totally disabled.
Santos Cordon9eb45932014-06-27 12:28:43 -07002131 // (The user is already on the InCallUI at this point,
Jeff Browncaca8812013-05-09 13:34:33 -07002132 // and his ONLY options are to answer or reject the call.)
Santos Cordon9eb45932014-06-27 12:28:43 -07002133 TelecommManager telecommManager = getTelecommService();
2134 if (telecommManager != null && telecommManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07002135 Log.i(TAG, "Ignoring HOME; there's a ringing incoming call.");
2136 return -1;
Jeff Browncaca8812013-05-09 13:34:33 -07002137 }
2138
2139 // Delay handling home if a double-tap is possible.
2140 if (mDoubleTapOnHomeBehavior != DOUBLE_TAP_HOME_NOTHING) {
2141 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); // just in case
2142 mHomeDoubleTapPending = true;
2143 mHandler.postDelayed(mHomeDoubleTapTimeoutRunnable,
2144 ViewConfiguration.getDoubleTapTimeout());
2145 return -1;
2146 }
2147
2148 // Go home!
2149 launchHomeFromHotKey();
2150 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002151 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002152
2153 // If a system window has focus, then it doesn't make sense
2154 // right now to interact with applications.
2155 WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null;
2156 if (attrs != null) {
2157 final int type = attrs.type;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002158 if (type == WindowManager.LayoutParams.TYPE_KEYGUARD_SCRIM
2159 || type == WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG
2160 || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002161 // the "app" is keyguard, so give it the key
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002162 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002163 }
2164 final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length;
2165 for (int i=0; i<typeCount; i++) {
2166 if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) {
2167 // don't do anything, but also don't pass it to the app
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002168 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002169 }
2170 }
2171 }
Jeff Browncaca8812013-05-09 13:34:33 -07002172
2173 // Remember that home is pressed and handle special actions.
2174 if (repeatCount == 0) {
2175 mHomePressed = true;
2176 if (mHomeDoubleTapPending) {
2177 mHomeDoubleTapPending = false;
2178 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable);
2179 handleDoubleTapOnHome();
2180 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI
2181 || mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
2182 preloadRecentApps();
Michael Jurka7f2668c2012-03-27 07:49:52 -07002183 }
Jeff Browncaca8812013-05-09 13:34:33 -07002184 } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) {
2185 if (!keyguardOn) {
2186 handleLongPressOnHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002187 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002188 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002189 return -1;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002190 } else if (keyCode == KeyEvent.KEYCODE_MENU) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002191 // Hijack modified menu keys for debugging features
2192 final int chordBug = KeyEvent.META_SHIFT_ON;
2193
2194 if (down && repeatCount == 0) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002195 if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002196 Intent intent = new Intent(Intent.ACTION_BUG_REPORT);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002197 mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT,
2198 null, null, null, 0, null, null);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002199 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002200 } else if (SHOW_PROCESSES_ON_ALT_MENU &&
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002201 (metaState & KeyEvent.META_ALT_ON) == KeyEvent.META_ALT_ON) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002202 Intent service = new Intent();
2203 service.setClassName(mContext, "com.android.server.LoadAverageService");
2204 ContentResolver res = mContext.getContentResolver();
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002205 boolean shown = Settings.Global.getInt(
2206 res, Settings.Global.SHOW_PROCESSES, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002207 if (!shown) {
2208 mContext.startService(service);
2209 } else {
2210 mContext.stopService(service);
2211 }
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002212 Settings.Global.putInt(
2213 res, Settings.Global.SHOW_PROCESSES, shown ? 0 : 1);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002214 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002215 }
2216 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002217 } else if (keyCode == KeyEvent.KEYCODE_SEARCH) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002218 if (down) {
2219 if (repeatCount == 0) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002220 mSearchKeyShortcutPending = true;
2221 mConsumeSearchKeyUp = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002222 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002223 } else {
2224 mSearchKeyShortcutPending = false;
2225 if (mConsumeSearchKeyUp) {
2226 mConsumeSearchKeyUp = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002227 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002228 }
2229 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002230 return 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002231 } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) {
Michael Wrightc9ebea72013-01-16 19:25:02 -08002232 if (!keyguardOn) {
Jeff Browncaca8812013-05-09 13:34:33 -07002233 if (down && repeatCount == 0) {
2234 preloadRecentApps();
2235 } else if (!down) {
2236 toggleRecentApps();
Michael Wrightc9ebea72013-01-16 19:25:02 -08002237 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002238 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002239 return -1;
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002240 } else if (keyCode == KeyEvent.KEYCODE_ASSIST) {
2241 if (down) {
2242 if (repeatCount == 0) {
2243 mAssistKeyLongPressed = false;
2244 } else if (repeatCount == 1) {
2245 mAssistKeyLongPressed = true;
2246 if (!keyguardOn) {
2247 launchAssistLongPressAction();
2248 }
2249 }
2250 } else {
2251 if (mAssistKeyLongPressed) {
2252 mAssistKeyLongPressed = false;
2253 } else {
2254 if (!keyguardOn) {
2255 launchAssistAction();
2256 }
2257 }
2258 }
2259 return -1;
Jeff Sharkey2991fa32012-12-05 18:06:43 -08002260 } else if (keyCode == KeyEvent.KEYCODE_SYSRQ) {
2261 if (down && repeatCount == 0) {
2262 mHandler.post(mScreenshotRunnable);
2263 }
2264 return -1;
Michael Wrightb854e242013-02-05 17:54:02 -08002265 } else if (keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP
2266 || keyCode == KeyEvent.KEYCODE_BRIGHTNESS_DOWN) {
2267 if (down) {
2268 int direction = keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP ? 1 : -1;
2269
2270 // Disable autobrightness if it's on
2271 int auto = Settings.System.getIntForUser(
2272 mContext.getContentResolver(),
2273 Settings.System.SCREEN_BRIGHTNESS_MODE,
2274 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2275 UserHandle.USER_CURRENT_OR_SELF);
2276 if (auto != 0) {
2277 Settings.System.putIntForUser(mContext.getContentResolver(),
2278 Settings.System.SCREEN_BRIGHTNESS_MODE,
2279 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2280 UserHandle.USER_CURRENT_OR_SELF);
2281 }
2282
2283 int min = mPowerManager.getMinimumScreenBrightnessSetting();
2284 int max = mPowerManager.getMaximumScreenBrightnessSetting();
2285 int step = (max - min + BRIGHTNESS_STEPS - 1) / BRIGHTNESS_STEPS * direction;
2286 int brightness = Settings.System.getIntForUser(mContext.getContentResolver(),
2287 Settings.System.SCREEN_BRIGHTNESS,
2288 mPowerManager.getDefaultScreenBrightnessSetting(),
2289 UserHandle.USER_CURRENT_OR_SELF);
2290 brightness += step;
2291 // Make sure we don't go beyond the limits.
2292 brightness = Math.min(max, brightness);
2293 brightness = Math.max(min, brightness);
2294
2295 Settings.System.putIntForUser(mContext.getContentResolver(),
2296 Settings.System.SCREEN_BRIGHTNESS, brightness,
2297 UserHandle.USER_CURRENT_OR_SELF);
2298 Intent intent = new Intent(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG);
2299 mContext.sendBroadcastAsUser(intent, UserHandle.CURRENT_OR_SELF);
2300 }
2301 return -1;
Michael Wright6a62e552014-06-03 19:19:48 -07002302 } else if (keyCode == KeyEvent.KEYCODE_META_LEFT) {
2303 if (down) {
2304 mPendingMetaAction = true;
2305 } else if (mPendingMetaAction) {
2306 mPendingMetaAction = false;
2307 launchAssistAction();
2308 }
2309 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002310 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002311
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002312 // Shortcuts are invoked through Search+key, so intercept those here
Jeff Browncaab4d02010-12-09 22:13:41 -08002313 // Any printing key that is chorded with Search should be consumed
2314 // even if no shortcut was invoked. This prevents text from being
2315 // inadvertently inserted when using a keyboard that has built-in macro
2316 // shortcut keys (that emit Search+x) and some of them are not registered.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002317 if (mSearchKeyShortcutPending) {
Jeff Browncaab4d02010-12-09 22:13:41 -08002318 final KeyCharacterMap kcm = event.getKeyCharacterMap();
2319 if (kcm.isPrintingKey(keyCode)) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002320 mConsumeSearchKeyUp = true;
2321 mSearchKeyShortcutPending = false;
Jeff Browncaab4d02010-12-09 22:13:41 -08002322 if (down && repeatCount == 0 && !keyguardOn) {
2323 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState);
2324 if (shortcutIntent != null) {
2325 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002326 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002327 mContext.startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002328 } catch (ActivityNotFoundException ex) {
2329 Slog.w(TAG, "Dropping shortcut key combination because "
2330 + "the activity to which it is registered was not found: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002331 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode), ex);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002332 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002333 } else {
2334 Slog.i(TAG, "Dropping unregistered shortcut key combination: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002335 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002336 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002337 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002338 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002339 }
2340 }
2341
Jeff Brown68b909d2011-12-07 16:36:01 -08002342 // Invoke shortcuts using Meta.
Jeff Brown602ab322012-05-16 13:33:47 -07002343 if (down && repeatCount == 0 && !keyguardOn
Jeff Brown68b909d2011-12-07 16:36:01 -08002344 && (metaState & KeyEvent.META_META_ON) != 0) {
2345 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brown602ab322012-05-16 13:33:47 -07002346 if (kcm.isPrintingKey(keyCode)) {
2347 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode,
2348 metaState & ~(KeyEvent.META_META_ON
2349 | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON));
2350 if (shortcutIntent != null) {
2351 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2352 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002353 mContext.startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brown602ab322012-05-16 13:33:47 -07002354 } catch (ActivityNotFoundException ex) {
2355 Slog.w(TAG, "Dropping shortcut key combination because "
2356 + "the activity to which it is registered was not found: "
2357 + "META+" + KeyEvent.keyCodeToString(keyCode), ex);
2358 }
2359 return -1;
Jeff Brown68b909d2011-12-07 16:36:01 -08002360 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002361 }
2362 }
2363
Jeff Brown6651a632011-11-28 12:59:11 -08002364 // Handle application launch keys.
Jeff Brown602ab322012-05-16 13:33:47 -07002365 if (down && repeatCount == 0 && !keyguardOn) {
Jeff Brown6651a632011-11-28 12:59:11 -08002366 String category = sApplicationLaunchKeyCategories.get(keyCode);
2367 if (category != null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -08002368 Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category);
Jeff Brown6651a632011-11-28 12:59:11 -08002369 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2370 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002371 mContext.startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brown6651a632011-11-28 12:59:11 -08002372 } catch (ActivityNotFoundException ex) {
2373 Slog.w(TAG, "Dropping application launch key because "
2374 + "the activity to which it is registered was not found: "
2375 + "keyCode=" + keyCode + ", category=" + category, ex);
2376 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002377 return -1;
Jeff Brown6651a632011-11-28 12:59:11 -08002378 }
2379 }
2380
Jeff Brown68b909d2011-12-07 16:36:01 -08002381 // Display task switcher for ALT-TAB or Meta-TAB.
2382 if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_TAB) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002383 if (mRecentAppsHeldModifiers == 0 && !keyguardOn) {
Jeff Brown68b909d2011-12-07 16:36:01 -08002384 final int shiftlessModifiers = event.getModifiers() & ~KeyEvent.META_SHIFT_MASK;
Winson Chungc6011de2014-06-30 18:04:55 -07002385 if (KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_ALT_ON)) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002386 mRecentAppsHeldModifiers = shiftlessModifiers;
2387 showRecentApps(true);
Jeff Brown68b909d2011-12-07 16:36:01 -08002388 return -1;
2389 }
2390 }
Winson Chung1e8d71b2014-05-16 17:05:22 -07002391 } else if (!down && mRecentAppsHeldModifiers != 0
2392 && (metaState & mRecentAppsHeldModifiers) == 0) {
2393 mRecentAppsHeldModifiers = 0;
Winson Chung6cb485f2014-05-19 10:30:43 -07002394 hideRecentApps(true);
Jeff Brown68b909d2011-12-07 16:36:01 -08002395 }
2396
Jeff Browncf39bdf2012-05-18 14:41:19 -07002397 // Handle keyboard language switching.
2398 if (down && repeatCount == 0
2399 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2400 || (keyCode == KeyEvent.KEYCODE_SPACE
2401 && (metaState & KeyEvent.META_CTRL_MASK) != 0))) {
2402 int direction = (metaState & KeyEvent.META_SHIFT_MASK) != 0 ? -1 : 1;
2403 mWindowManagerFuncs.switchKeyboardLayout(event.getDeviceId(), direction);
2404 return -1;
2405 }
2406 if (mLanguageSwitchKeyPressed && !down
2407 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2408 || keyCode == KeyEvent.KEYCODE_SPACE)) {
2409 mLanguageSwitchKeyPressed = false;
2410 return -1;
2411 }
2412
Justin Kohd378ad72013-04-01 12:18:26 -07002413 if (mGlobalKeyManager.handleGlobalKey(mContext, keyCode, event)) {
2414 return -1;
2415 }
2416
Michael Wright6a62e552014-06-03 19:19:48 -07002417 // Reserve all the META modifier combos for system behavior
2418 if ((metaState & KeyEvent.META_META_LEFT_ON) != 0) {
2419 return -1;
2420 }
2421
Jeff Brown68b909d2011-12-07 16:36:01 -08002422 // Let the application handle the key.
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002423 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002424 }
2425
Jeff Brown3915bb82010-11-05 15:02:16 -07002426 /** {@inheritDoc} */
2427 @Override
Jeff Brown49ed71d2010-12-06 17:13:33 -08002428 public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown54875002011-04-06 15:33:01 -07002429 // Note: This method is only called if the initial down was unhandled.
Jeff Brown40013652012-05-16 21:22:36 -07002430 if (DEBUG_INPUT) {
Jeff Brown1f245102010-11-18 20:53:46 -08002431 Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction()
2432 + ", flags=" + event.getFlags()
2433 + ", keyCode=" + event.getKeyCode()
2434 + ", scanCode=" + event.getScanCode()
2435 + ", metaState=" + event.getMetaState()
2436 + ", repeatCount=" + event.getRepeatCount()
2437 + ", policyFlags=" + policyFlags);
Jeff Brown3915bb82010-11-05 15:02:16 -07002438 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002439
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002440 KeyEvent fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002441 if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
2442 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002443 final int keyCode = event.getKeyCode();
2444 final int metaState = event.getMetaState();
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002445 final boolean initialDown = event.getAction() == KeyEvent.ACTION_DOWN
2446 && event.getRepeatCount() == 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002447
Jeff Brown54875002011-04-06 15:33:01 -07002448 // Check for fallback actions specified by the key character map.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002449 final FallbackAction fallbackAction;
2450 if (initialDown) {
2451 fallbackAction = kcm.getFallbackAction(keyCode, metaState);
2452 } else {
2453 fallbackAction = mFallbackActions.get(keyCode);
2454 }
2455
2456 if (fallbackAction != null) {
Jeff Brown40013652012-05-16 21:22:36 -07002457 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002458 Slog.d(TAG, "Fallback: keyCode=" + fallbackAction.keyCode
2459 + " metaState=" + Integer.toHexString(fallbackAction.metaState));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002460 }
2461
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002462 final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK;
2463 fallbackEvent = KeyEvent.obtain(
Jeff Brown49ed71d2010-12-06 17:13:33 -08002464 event.getDownTime(), event.getEventTime(),
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002465 event.getAction(), fallbackAction.keyCode,
2466 event.getRepeatCount(), fallbackAction.metaState,
Jeff Brown49ed71d2010-12-06 17:13:33 -08002467 event.getDeviceId(), event.getScanCode(),
2468 flags, event.getSource(), null);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002469
2470 if (!interceptFallback(win, fallbackEvent, policyFlags)) {
2471 fallbackEvent.recycle();
2472 fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002473 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002474
2475 if (initialDown) {
2476 mFallbackActions.put(keyCode, fallbackAction);
2477 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2478 mFallbackActions.remove(keyCode);
2479 fallbackAction.recycle();
2480 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002481 }
2482 }
2483
Jeff Brown40013652012-05-16 21:22:36 -07002484 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002485 if (fallbackEvent == null) {
2486 Slog.d(TAG, "No fallback.");
2487 } else {
2488 Slog.d(TAG, "Performing fallback: " + fallbackEvent);
2489 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002490 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002491 return fallbackEvent;
Jeff Brown3915bb82010-11-05 15:02:16 -07002492 }
2493
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002494 private boolean interceptFallback(WindowState win, KeyEvent fallbackEvent, int policyFlags) {
Jeff Brown037c33e2014-04-09 00:31:55 -07002495 int actions = interceptKeyBeforeQueueing(fallbackEvent, policyFlags);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002496 if ((actions & ACTION_PASS_TO_USER) != 0) {
2497 long delayMillis = interceptKeyBeforeDispatching(
2498 win, fallbackEvent, policyFlags);
2499 if (delayMillis == 0) {
2500 return true;
2501 }
2502 }
2503 return false;
Jeff Brown6f2fba42011-02-19 01:08:02 -08002504 }
2505
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002506 private void launchAssistLongPressAction() {
2507 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
2508 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
2509
2510 // launch the search activity
2511 Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS);
2512 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2513 try {
RoboErik8a2cfc32014-05-16 11:19:38 -07002514 // TODO: This only stops the factory-installed search manager.
Jim Miller45308b12012-06-18 19:23:39 -07002515 // Need to formalize an API to handle others
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002516 SearchManager searchManager = getSearchManager();
2517 if (searchManager != null) {
2518 searchManager.stopSearch();
2519 }
Michael Wright43e27f72013-04-10 14:06:48 -07002520 mContext.startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002521 } catch (ActivityNotFoundException e) {
2522 Slog.w(TAG, "No activity to handle assist long press action.", e);
2523 }
2524 }
2525
2526 private void launchAssistAction() {
2527 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
Amith Yamasanic1d07a42012-08-14 09:32:02 -07002528 Intent intent = ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE))
Dianne Hackbornf9c5e0f2013-01-23 14:39:13 -08002529 .getAssistIntent(mContext, true, UserHandle.USER_CURRENT);
Jim Miller45308b12012-06-18 19:23:39 -07002530 if (intent != null) {
2531 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
2532 | Intent.FLAG_ACTIVITY_SINGLE_TOP
2533 | Intent.FLAG_ACTIVITY_CLEAR_TOP);
2534 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002535 mContext.startActivityAsUser(intent, UserHandle.CURRENT);
Jim Miller45308b12012-06-18 19:23:39 -07002536 } catch (ActivityNotFoundException e) {
2537 Slog.w(TAG, "No activity to handle assist action.", e);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002538 }
2539 }
2540 }
2541
2542 private SearchManager getSearchManager() {
2543 if (mSearchManager == null) {
2544 mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
2545 }
2546 return mSearchManager;
2547 }
2548
Jeff Browncaca8812013-05-09 13:34:33 -07002549 private void preloadRecentApps() {
2550 mPreloadedRecentApps = true;
2551 try {
2552 IStatusBarService statusbar = getStatusBarService();
2553 if (statusbar != null) {
2554 statusbar.preloadRecentApps();
2555 }
2556 } catch (RemoteException e) {
2557 Slog.e(TAG, "RemoteException when preloading recent apps", e);
2558 // re-acquire status bar service next time it is needed.
2559 mStatusBarService = null;
2560 }
2561 }
2562
2563 private void cancelPreloadRecentApps() {
2564 if (mPreloadedRecentApps) {
2565 mPreloadedRecentApps = false;
2566 try {
2567 IStatusBarService statusbar = getStatusBarService();
2568 if (statusbar != null) {
2569 statusbar.cancelPreloadRecentApps();
2570 }
2571 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002572 Slog.e(TAG, "RemoteException when cancelling recent apps preload", e);
Jeff Browncaca8812013-05-09 13:34:33 -07002573 // re-acquire status bar service next time it is needed.
2574 mStatusBarService = null;
2575 }
2576 }
2577 }
2578
2579 private void toggleRecentApps() {
2580 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
Jeff Browncaca8812013-05-09 13:34:33 -07002581 try {
2582 IStatusBarService statusbar = getStatusBarService();
2583 if (statusbar != null) {
2584 statusbar.toggleRecentApps();
2585 }
2586 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002587 Slog.e(TAG, "RemoteException when toggling recent apps", e);
2588 // re-acquire status bar service next time it is needed.
2589 mStatusBarService = null;
2590 }
2591 }
2592
Craig Mautner84984fa2014-06-19 11:19:20 -07002593 @Override
2594 public void showRecentApps() {
2595 mHandler.removeMessages(MSG_DISPATCH_SHOW_RECENTS);
2596 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_RECENTS);
2597 }
2598
Winson Chung1e8d71b2014-05-16 17:05:22 -07002599 private void showRecentApps(boolean triggeredFromAltTab) {
2600 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
2601 try {
2602 IStatusBarService statusbar = getStatusBarService();
2603 if (statusbar != null) {
2604 statusbar.showRecentApps(triggeredFromAltTab);
2605 }
2606 } catch (RemoteException e) {
Jeff Browncaca8812013-05-09 13:34:33 -07002607 Slog.e(TAG, "RemoteException when showing recent apps", e);
2608 // re-acquire status bar service next time it is needed.
2609 mStatusBarService = null;
2610 }
2611 }
2612
Winson Chung6cb485f2014-05-19 10:30:43 -07002613 private void hideRecentApps(boolean triggeredFromAltTab) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002614 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
2615 try {
2616 IStatusBarService statusbar = getStatusBarService();
2617 if (statusbar != null) {
Winson Chung6cb485f2014-05-19 10:30:43 -07002618 statusbar.hideRecentApps(triggeredFromAltTab);
Winson Chung1e8d71b2014-05-16 17:05:22 -07002619 }
2620 } catch (RemoteException e) {
2621 Slog.e(TAG, "RemoteException when closing recent apps", e);
2622 // re-acquire status bar service next time it is needed.
2623 mStatusBarService = null;
2624 }
2625 }
2626
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002627 /**
2628 * A home key -> launch home action was detected. Take the appropriate action
2629 * given the situation with the keyguard.
2630 */
2631 void launchHomeFromHotKey() {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01002632 if (mKeyguardDelegate != null && mKeyguardDelegate.isShowingAndNotOccluded()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002633 // don't launch home if keyguard showing
Jim Miller5ecd8112013-01-09 18:50:26 -08002634 } else if (!mHideLockScreen && mKeyguardDelegate.isInputRestricted()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002635 // when in keyguard restricted mode, must first verify unlock
2636 // before launching home
Jim Miller5ecd8112013-01-09 18:50:26 -08002637 mKeyguardDelegate.verifyUnlock(new OnKeyguardExitResult() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002638 public void onKeyguardExitResult(boolean success) {
2639 if (success) {
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07002640 try {
2641 ActivityManagerNative.getDefault().stopAppSwitches();
2642 } catch (RemoteException e) {
2643 }
Joe Onoratof275f0c2009-11-24 16:11:13 -05002644 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07002645 startDockOrHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002646 }
2647 }
2648 });
2649 } else {
2650 // no keyguard stuff to worry about, just launch home!
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07002651 try {
2652 ActivityManagerNative.getDefault().stopAppSwitches();
2653 } catch (RemoteException e) {
2654 }
Winson Chungd543c1b2014-06-23 15:06:45 -07002655 if (mRecentsVisible) {
2656 // Hide Recents and notify it to launch Home
2657 awakenDreams();
2658 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
2659 hideRecentApps(false);
2660 } else {
2661 // Otherwise, just launch Home
2662 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
2663 startDockOrHome();
2664 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002665 }
2666 }
2667
John Spurlock04db1762013-05-13 12:46:41 -04002668 private final Runnable mClearHideNavigationFlag = new Runnable() {
2669 @Override
2670 public void run() {
2671 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
2672 // Clear flags.
2673 mForceClearedSystemUiFlags &=
2674 ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
2675 }
2676 mWindowManagerFuncs.reevaluateStatusBarVisibility();
Dianne Hackborne26ab702011-10-16 13:21:33 -07002677 }
2678 };
2679
2680 /**
2681 * Input handler used while nav bar is hidden. Captures any touch on the screen,
2682 * to determine when the nav bar should be shown and prevent applications from
2683 * receiving those touches.
2684 */
Jeff Brown32cbc38552011-12-01 14:01:49 -08002685 final class HideNavInputEventReceiver extends InputEventReceiver {
2686 public HideNavInputEventReceiver(InputChannel inputChannel, Looper looper) {
2687 super(inputChannel, looper);
2688 }
2689
Dianne Hackborndf89e652011-10-06 22:35:11 -07002690 @Override
Jeff Brown32cbc38552011-12-01 14:01:49 -08002691 public void onInputEvent(InputEvent event) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07002692 boolean handled = false;
2693 try {
Jeff Brown4952dfd2011-11-30 19:23:22 -08002694 if (event instanceof MotionEvent
2695 && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
2696 final MotionEvent motionEvent = (MotionEvent)event;
2697 if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07002698 // When the user taps down, we re-show the nav bar.
2699 boolean changed = false;
John Spurlock04db1762013-05-13 12:46:41 -04002700 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002701 // Any user activity always causes us to show the
2702 // navigation controls, if they had been hidden.
2703 // We also clear the low profile and only content
2704 // flags so that tapping on the screen will atomically
2705 // restore all currently hidden screen decorations.
2706 int newVal = mResettingSystemUiFlags |
2707 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
2708 View.SYSTEM_UI_FLAG_LOW_PROFILE |
2709 View.SYSTEM_UI_FLAG_FULLSCREEN;
Dianne Hackborne26ab702011-10-16 13:21:33 -07002710 if (mResettingSystemUiFlags != newVal) {
2711 mResettingSystemUiFlags = newVal;
Dianne Hackborndf89e652011-10-06 22:35:11 -07002712 changed = true;
2713 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07002714 // We don't allow the system's nav bar to be hidden
2715 // again for 1 second, to prevent applications from
2716 // spamming us and keeping it from being shown.
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002717 newVal = mForceClearedSystemUiFlags |
2718 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
Dianne Hackborne26ab702011-10-16 13:21:33 -07002719 if (mForceClearedSystemUiFlags != newVal) {
2720 mForceClearedSystemUiFlags = newVal;
2721 changed = true;
John Spurlock04db1762013-05-13 12:46:41 -04002722 mHandler.postDelayed(mClearHideNavigationFlag, 1000);
Dianne Hackborne26ab702011-10-16 13:21:33 -07002723 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07002724 }
2725 if (changed) {
2726 mWindowManagerFuncs.reevaluateStatusBarVisibility();
2727 }
2728 }
2729 }
2730 } finally {
Jeff Brown32cbc38552011-12-01 14:01:49 -08002731 finishInputEvent(event, handled);
Dianne Hackborndf89e652011-10-06 22:35:11 -07002732 }
2733 }
Jeff Brown32cbc38552011-12-01 14:01:49 -08002734 }
2735 final InputEventReceiver.Factory mHideNavInputEventReceiverFactory =
2736 new InputEventReceiver.Factory() {
2737 @Override
2738 public InputEventReceiver createInputEventReceiver(
2739 InputChannel inputChannel, Looper looper) {
2740 return new HideNavInputEventReceiver(inputChannel, looper);
2741 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07002742 };
2743
2744 @Override
2745 public int adjustSystemUiVisibilityLw(int visibility) {
John Spurlock5b9145b2013-08-20 15:13:47 -04002746 mStatusBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
2747 mNavigationBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
Winson Chungd42a6cf2014-06-03 16:24:04 -07002748 mRecentsVisible = (visibility & View.RECENT_APPS_VISIBLE) > 0;
John Spurlock27735a42013-08-14 17:57:38 -04002749
Dianne Hackborndf89e652011-10-06 22:35:11 -07002750 // Reset any bits in mForceClearingStatusBarVisibility that
2751 // are now clear.
Dianne Hackborne26ab702011-10-16 13:21:33 -07002752 mResettingSystemUiFlags &= visibility;
Dianne Hackborndf89e652011-10-06 22:35:11 -07002753 // Clear any bits in the new visibility that are currently being
2754 // force cleared, before reporting it.
Dianne Hackborne26ab702011-10-16 13:21:33 -07002755 return visibility & ~mResettingSystemUiFlags
2756 & ~mForceClearedSystemUiFlags;
Dianne Hackborndf89e652011-10-06 22:35:11 -07002757 }
2758
Craig Mautner69b08182012-09-05 13:07:13 -07002759 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002760 public void getContentInsetHintLw(WindowManager.LayoutParams attrs, Rect contentInset) {
John Spurlockc6d1c602014-01-17 15:22:06 -05002761 final int fl = PolicyControl.getWindowFlags(null, attrs);
John Spurlock1db8b682014-02-18 11:18:59 -05002762 final int sysuiVis = PolicyControl.getSystemUiVisibility(null, attrs);
2763 final int systemUiVisibility = (sysuiVis | attrs.subtreeSystemUiVisibility);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002764
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002765 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002766 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002767 int availRight, availBottom;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07002768 if (canHideNavigationBar() &&
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002769 (systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002770 availRight = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
2771 availBottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
2772 } else {
2773 availRight = mRestrictedScreenLeft + mRestrictedScreenWidth;
2774 availBottom = mRestrictedScreenTop + mRestrictedScreenHeight;
2775 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002776 if ((systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
2777 if ((fl & FLAG_FULLSCREEN) != 0) {
2778 contentInset.set(mStableFullscreenLeft, mStableFullscreenTop,
2779 availRight - mStableFullscreenRight,
2780 availBottom - mStableFullscreenBottom);
2781 } else {
2782 contentInset.set(mStableLeft, mStableTop,
2783 availRight - mStableRight, availBottom - mStableBottom);
2784 }
Dianne Hackbornc652de82013-02-15 16:32:56 -08002785 } else if ((fl & FLAG_FULLSCREEN) != 0 || (fl & FLAG_LAYOUT_IN_OVERSCAN) != 0) {
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002786 contentInset.setEmpty();
2787 } else if ((systemUiVisibility & (View.SYSTEM_UI_FLAG_FULLSCREEN
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002788 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)) == 0) {
2789 contentInset.set(mCurLeft, mCurTop,
2790 availRight - mCurRight, availBottom - mCurBottom);
2791 } else {
2792 contentInset.set(mCurLeft, mCurTop,
2793 availRight - mCurRight, availBottom - mCurBottom);
2794 }
2795 return;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002796 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002797 contentInset.setEmpty();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002798 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002799
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002800 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07002801 @Override
2802 public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight,
2803 int displayRotation) {
Dianne Hackbornc652de82013-02-15 16:32:56 -08002804 final int overscanLeft, overscanTop, overscanRight, overscanBottom;
2805 if (isDefaultDisplay) {
2806 switch (displayRotation) {
2807 case Surface.ROTATION_90:
2808 overscanLeft = mOverscanTop;
2809 overscanTop = mOverscanRight;
2810 overscanRight = mOverscanBottom;
2811 overscanBottom = mOverscanLeft;
2812 break;
2813 case Surface.ROTATION_180:
2814 overscanLeft = mOverscanRight;
2815 overscanTop = mOverscanBottom;
2816 overscanRight = mOverscanLeft;
2817 overscanBottom = mOverscanTop;
2818 break;
2819 case Surface.ROTATION_270:
2820 overscanLeft = mOverscanBottom;
2821 overscanTop = mOverscanLeft;
2822 overscanRight = mOverscanTop;
2823 overscanBottom = mOverscanRight;
2824 break;
2825 default:
2826 overscanLeft = mOverscanLeft;
2827 overscanTop = mOverscanTop;
2828 overscanRight = mOverscanRight;
2829 overscanBottom = mOverscanBottom;
2830 break;
2831 }
2832 } else {
2833 overscanLeft = 0;
2834 overscanTop = 0;
2835 overscanRight = 0;
2836 overscanBottom = 0;
2837 }
Dianne Hackborn313440842013-02-19 19:22:59 -08002838 mOverscanScreenLeft = mRestrictedOverscanScreenLeft = 0;
2839 mOverscanScreenTop = mRestrictedOverscanScreenTop = 0;
2840 mOverscanScreenWidth = mRestrictedOverscanScreenWidth = displayWidth;
2841 mOverscanScreenHeight = mRestrictedOverscanScreenHeight = displayHeight;
Dianne Hackbornc652de82013-02-15 16:32:56 -08002842 mSystemLeft = 0;
2843 mSystemTop = 0;
2844 mSystemRight = displayWidth;
2845 mSystemBottom = displayHeight;
2846 mUnrestrictedScreenLeft = overscanLeft;
2847 mUnrestrictedScreenTop = overscanTop;
2848 mUnrestrictedScreenWidth = displayWidth - overscanLeft - overscanRight;
2849 mUnrestrictedScreenHeight = displayHeight - overscanTop - overscanBottom;
2850 mRestrictedScreenLeft = mUnrestrictedScreenLeft;
2851 mRestrictedScreenTop = mUnrestrictedScreenTop;
John Spurlockad3e6cb2013-04-30 08:47:43 -04002852 mRestrictedScreenWidth = mSystemGestures.screenWidth = mUnrestrictedScreenWidth;
2853 mRestrictedScreenHeight = mSystemGestures.screenHeight = mUnrestrictedScreenHeight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002854 mDockLeft = mContentLeft = mVoiceContentLeft = mStableLeft = mStableFullscreenLeft
Dianne Hackbornc652de82013-02-15 16:32:56 -08002855 = mCurLeft = mUnrestrictedScreenLeft;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002856 mDockTop = mContentTop = mVoiceContentTop = mStableTop = mStableFullscreenTop
Dianne Hackbornc652de82013-02-15 16:32:56 -08002857 = mCurTop = mUnrestrictedScreenTop;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002858 mDockRight = mContentRight = mVoiceContentRight = mStableRight = mStableFullscreenRight
Dianne Hackbornc652de82013-02-15 16:32:56 -08002859 = mCurRight = displayWidth - overscanRight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002860 mDockBottom = mContentBottom = mVoiceContentBottom = mStableBottom = mStableFullscreenBottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08002861 = mCurBottom = displayHeight - overscanBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002862 mDockLayer = 0x10000000;
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002863 mStatusBarLayer = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002864
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002865 // start with the current dock rect, which will be (0,0,displayWidth,displayHeight)
2866 final Rect pf = mTmpParentFrame;
2867 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002868 final Rect of = mTmpOverscanFrame;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002869 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04002870 final Rect dcf = mTmpDecorFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002871 pf.left = df.left = of.left = vf.left = mDockLeft;
2872 pf.top = df.top = of.top = vf.top = mDockTop;
2873 pf.right = df.right = of.right = vf.right = mDockRight;
2874 pf.bottom = df.bottom = of.bottom = vf.bottom = mDockBottom;
John Spurlock46646232013-09-30 22:32:42 -04002875 dcf.setEmpty(); // Decor frame N/A for system bars.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002876
Craig Mautner69b08182012-09-05 13:07:13 -07002877 if (isDefaultDisplay) {
2878 // For purposes of putting out fake window up to steal focus, we will
2879 // drive nav being hidden only by whether it is requested.
John Spurlocke1f366f2013-08-05 12:22:40 -04002880 final int sysui = mLastSystemUiFlags;
2881 boolean navVisible = (sysui & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0;
Adrian Roosea562512014-05-05 13:33:03 +02002882 boolean navTranslucent = (sysui
2883 & (View.NAVIGATION_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04002884 boolean immersive = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
2885 boolean immersiveSticky = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
2886 boolean navAllowedHidden = immersive || immersiveSticky;
2887 navTranslucent &= !immersiveSticky; // transient trumps translucent
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04002888 navTranslucent &= areTranslucentBarsAllowed();
Dianne Hackborne26ab702011-10-16 13:21:33 -07002889
Craig Mautner69b08182012-09-05 13:07:13 -07002890 // When the navigation bar isn't visible, we put up a fake
2891 // input window to catch all touch events. This way we can
2892 // detect when the user presses anywhere to bring back the nav
2893 // bar and ensure the application doesn't see the event.
John Spurlockf1a36642013-10-12 17:50:42 -04002894 if (navVisible || navAllowedHidden) {
Craig Mautner69b08182012-09-05 13:07:13 -07002895 if (mHideNavFakeWindow != null) {
2896 mHideNavFakeWindow.dismiss();
2897 mHideNavFakeWindow = null;
2898 }
2899 } else if (mHideNavFakeWindow == null) {
2900 mHideNavFakeWindow = mWindowManagerFuncs.addFakeWindow(
2901 mHandler.getLooper(), mHideNavInputEventReceiverFactory,
Adam Lesinski95c42972013-10-02 10:13:27 -07002902 "hidden nav", WindowManager.LayoutParams.TYPE_HIDDEN_NAV_CONSUMER, 0,
Craig Mautner69b08182012-09-05 13:07:13 -07002903 0, false, false, true);
Dianne Hackborne26ab702011-10-16 13:21:33 -07002904 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07002905
Craig Mautner69b08182012-09-05 13:07:13 -07002906 // For purposes of positioning and showing the nav bar, if we have
2907 // decided that it can't be hidden (because of the screen aspect ratio),
2908 // then take that into account.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07002909 navVisible |= !canHideNavigationBar();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002910
John Spurlockad3e6cb2013-04-30 08:47:43 -04002911 boolean updateSysUiVisibility = false;
Craig Mautner69b08182012-09-05 13:07:13 -07002912 if (mNavigationBar != null) {
John Spurlock27735a42013-08-14 17:57:38 -04002913 boolean transientNavBarShowing = mNavigationBarController.isTransientShowing();
Craig Mautner69b08182012-09-05 13:07:13 -07002914 // Force the navigation bar to its appropriate place and
2915 // size. We need to do this directly, instead of relying on
2916 // it to bubble up from the nav bar, because this needs to
2917 // change atomically with screen rotations.
2918 mNavigationBarOnBottom = (!mNavigationBarCanMove || displayWidth < displayHeight);
2919 if (mNavigationBarOnBottom) {
2920 // It's a system nav bar or a portrait screen; nav bar goes on bottom.
Dianne Hackbornc652de82013-02-15 16:32:56 -08002921 int top = displayHeight - overscanBottom
2922 - mNavigationBarHeightForRotation[displayRotation];
2923 mTmpNavigationFrame.set(0, top, displayWidth, displayHeight - overscanBottom);
Craig Mautner69b08182012-09-05 13:07:13 -07002924 mStableBottom = mStableFullscreenBottom = mTmpNavigationFrame.top;
John Spurlockf95b89a2013-10-10 22:10:42 -04002925 if (transientNavBarShowing) {
John Spurlock27735a42013-08-14 17:57:38 -04002926 mNavigationBarController.setBarShowingLw(true);
John Spurlockad3e6cb2013-04-30 08:47:43 -04002927 } else if (navVisible) {
John Spurlock27735a42013-08-14 17:57:38 -04002928 mNavigationBarController.setBarShowingLw(true);
Craig Mautner69b08182012-09-05 13:07:13 -07002929 mDockBottom = mTmpNavigationFrame.top;
Dianne Hackborn313440842013-02-19 19:22:59 -08002930 mRestrictedScreenHeight = mDockBottom - mRestrictedScreenTop;
2931 mRestrictedOverscanScreenHeight = mDockBottom - mRestrictedOverscanScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07002932 } else {
2933 // We currently want to hide the navigation UI.
John Spurlock27735a42013-08-14 17:57:38 -04002934 mNavigationBarController.setBarShowingLw(false);
Craig Mautner69b08182012-09-05 13:07:13 -07002935 }
John Spurlockc6d1c602014-01-17 15:22:06 -05002936 if (navVisible && !navTranslucent && !navAllowedHidden
2937 && !mNavigationBar.isAnimatingLw()
John Spurlockbd957402013-10-03 11:38:39 -04002938 && !mNavigationBarController.wasRecentlyTranslucent()) {
John Spurlocke1f366f2013-08-05 12:22:40 -04002939 // If the opaque nav bar is currently requested to be visible,
Craig Mautner69b08182012-09-05 13:07:13 -07002940 // and not in the process of animating on or off, then
2941 // we can tell the app that it is covered by it.
2942 mSystemBottom = mTmpNavigationFrame.top;
2943 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002944 } else {
Craig Mautner69b08182012-09-05 13:07:13 -07002945 // Landscape screen; nav bar goes to the right.
Dianne Hackbornc652de82013-02-15 16:32:56 -08002946 int left = displayWidth - overscanRight
2947 - mNavigationBarWidthForRotation[displayRotation];
2948 mTmpNavigationFrame.set(left, 0, displayWidth - overscanRight, displayHeight);
Craig Mautner69b08182012-09-05 13:07:13 -07002949 mStableRight = mStableFullscreenRight = mTmpNavigationFrame.left;
John Spurlockf95b89a2013-10-10 22:10:42 -04002950 if (transientNavBarShowing) {
John Spurlock27735a42013-08-14 17:57:38 -04002951 mNavigationBarController.setBarShowingLw(true);
John Spurlockad3e6cb2013-04-30 08:47:43 -04002952 } else if (navVisible) {
John Spurlock27735a42013-08-14 17:57:38 -04002953 mNavigationBarController.setBarShowingLw(true);
Craig Mautner69b08182012-09-05 13:07:13 -07002954 mDockRight = mTmpNavigationFrame.left;
Dianne Hackborn313440842013-02-19 19:22:59 -08002955 mRestrictedScreenWidth = mDockRight - mRestrictedScreenLeft;
2956 mRestrictedOverscanScreenWidth = mDockRight - mRestrictedOverscanScreenLeft;
Craig Mautner69b08182012-09-05 13:07:13 -07002957 } else {
2958 // We currently want to hide the navigation UI.
John Spurlock27735a42013-08-14 17:57:38 -04002959 mNavigationBarController.setBarShowingLw(false);
Craig Mautner69b08182012-09-05 13:07:13 -07002960 }
John Spurlockbd957402013-10-03 11:38:39 -04002961 if (navVisible && !navTranslucent && !mNavigationBar.isAnimatingLw()
2962 && !mNavigationBarController.wasRecentlyTranslucent()) {
Craig Mautner69b08182012-09-05 13:07:13 -07002963 // If the nav bar is currently requested to be visible,
2964 // and not in the process of animating on or off, then
2965 // we can tell the app that it is covered by it.
2966 mSystemRight = mTmpNavigationFrame.left;
2967 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002968 }
Craig Mautner69b08182012-09-05 13:07:13 -07002969 // Make sure the content and current rectangles are updated to
2970 // account for the restrictions from the navigation bar.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002971 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
2972 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
2973 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
2974 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
Craig Mautner69b08182012-09-05 13:07:13 -07002975 mStatusBarLayer = mNavigationBar.getSurfaceLayer();
2976 // And compute the final frame.
2977 mNavigationBar.computeFrameLw(mTmpNavigationFrame, mTmpNavigationFrame,
Adrian Roosfa104232014-06-20 16:10:14 -07002978 mTmpNavigationFrame, mTmpNavigationFrame, mTmpNavigationFrame, dcf,
2979 mTmpNavigationFrame);
Craig Mautnereda67292013-04-28 13:50:14 -07002980 if (DEBUG_LAYOUT) Slog.i(TAG, "mNavigationBar frame: " + mTmpNavigationFrame);
John Spurlock27735a42013-08-14 17:57:38 -04002981 if (mNavigationBarController.checkHiddenLw()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04002982 updateSysUiVisibility = true;
2983 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002984 }
Craig Mautnereda67292013-04-28 13:50:14 -07002985 if (DEBUG_LAYOUT) Slog.i(TAG, String.format("mDock rect: (%d,%d - %d,%d)",
Craig Mautner69b08182012-09-05 13:07:13 -07002986 mDockLeft, mDockTop, mDockRight, mDockBottom));
2987
2988 // decide where the status bar goes ahead of time
2989 if (mStatusBar != null) {
2990 // apply any navigation bar insets
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002991 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
2992 pf.top = df.top = of.top = mUnrestrictedScreenTop;
2993 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
2994 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight
2995 + mUnrestrictedScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07002996 vf.left = mStableLeft;
2997 vf.top = mStableTop;
2998 vf.right = mStableRight;
2999 vf.bottom = mStableBottom;
3000
3001 mStatusBarLayer = mStatusBar.getSurfaceLayer();
3002
3003 // Let the status bar determine its size.
Adrian Roosfa104232014-06-20 16:10:14 -07003004 mStatusBar.computeFrameLw(pf, df, vf, vf, vf, dcf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07003005
3006 // For layout, the status bar is always at the top with our fixed height.
3007 mStableTop = mUnrestrictedScreenTop + mStatusBarHeight;
3008
John Spurlocke1f366f2013-08-05 12:22:40 -04003009 boolean statusBarTransient = (sysui & View.STATUS_BAR_TRANSIENT) != 0;
Adrian Roosea562512014-05-05 13:33:03 +02003010 boolean statusBarTranslucent = (sysui
3011 & (View.STATUS_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0;
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04003012 statusBarTranslucent &= areTranslucentBarsAllowed();
John Spurlock32beb2c2013-03-11 10:16:47 -04003013
Craig Mautner69b08182012-09-05 13:07:13 -07003014 // If the status bar is hidden, we don't want to cause
3015 // windows behind it to scroll.
John Spurlockeda1f692013-09-16 11:38:44 -04003016 if (mStatusBar.isVisibleLw() && !statusBarTransient) {
Craig Mautner69b08182012-09-05 13:07:13 -07003017 // Status bar may go away, so the screen area it occupies
3018 // is available to apps but just covering them when the
3019 // status bar is visible.
3020 mDockTop = mUnrestrictedScreenTop + mStatusBarHeight;
3021
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003022 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3023 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3024 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3025 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
Craig Mautner69b08182012-09-05 13:07:13 -07003026
Craig Mautnereda67292013-04-28 13:50:14 -07003027 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar: " +
Craig Mautner69b08182012-09-05 13:07:13 -07003028 String.format(
3029 "dock=[%d,%d][%d,%d] content=[%d,%d][%d,%d] cur=[%d,%d][%d,%d]",
3030 mDockLeft, mDockTop, mDockRight, mDockBottom,
3031 mContentLeft, mContentTop, mContentRight, mContentBottom,
3032 mCurLeft, mCurTop, mCurRight, mCurBottom));
3033 }
John Spurlocke1f366f2013-08-05 12:22:40 -04003034 if (mStatusBar.isVisibleLw() && !mStatusBar.isAnimatingLw()
John Spurlockbd957402013-10-03 11:38:39 -04003035 && !statusBarTransient && !statusBarTranslucent
3036 && !mStatusBarController.wasRecentlyTranslucent()) {
John Spurlocke1f366f2013-08-05 12:22:40 -04003037 // If the opaque status bar is currently requested to be visible,
Craig Mautner69b08182012-09-05 13:07:13 -07003038 // and not in the process of animating on or off, then
3039 // we can tell the app that it is covered by it.
3040 mSystemTop = mUnrestrictedScreenTop + mStatusBarHeight;
3041 }
John Spurlock27735a42013-08-14 17:57:38 -04003042 if (mStatusBarController.checkHiddenLw()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04003043 updateSysUiVisibility = true;
John Spurlock32beb2c2013-03-11 10:16:47 -04003044 }
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003045 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04003046 if (updateSysUiVisibility) {
3047 updateSystemUiVisibilityLw();
3048 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003049 }
3050 }
3051
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003052 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07003053 @Override
John Spurlock46646232013-09-30 22:32:42 -04003054 public int getSystemDecorLayerLw() {
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003055 if (mStatusBar != null) return mStatusBar.getSurfaceLayer();
3056 if (mNavigationBar != null) return mNavigationBar.getSurfaceLayer();
3057 return 0;
3058 }
3059
Craig Mautner967212c2013-04-13 21:10:58 -07003060 @Override
3061 public void getContentRectLw(Rect r) {
3062 r.set(mContentLeft, mContentTop, mContentRight, mContentBottom);
3063 }
3064
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003065 void setAttachedWindowFrames(WindowState win, int fl, int adjust, WindowState attached,
3066 boolean insetDecors, Rect pf, Rect df, Rect of, Rect cf, Rect vf) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003067 if (win.getSurfaceLayer() > mDockLayer && attached.getSurfaceLayer() < mDockLayer) {
3068 // Here's a special case: if this attached window is a panel that is
3069 // above the dock window, and the window it is attached to is below
3070 // the dock window, then the frames we computed for the window it is
3071 // attached to can not be used because the dock is effectively part
3072 // of the underlying window and the attached window is floating on top
3073 // of the whole thing. So, we ignore the attached window and explicitly
3074 // compute the frames that would be appropriate without the dock.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003075 df.left = of.left = cf.left = vf.left = mDockLeft;
3076 df.top = of.top = cf.top = vf.top = mDockTop;
3077 df.right = of.right = cf.right = vf.right = mDockRight;
3078 df.bottom = of.bottom = cf.bottom = vf.bottom = mDockBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003079 } else {
3080 // The effective display frame of the attached window depends on
3081 // whether it is taking care of insetting its content. If not,
3082 // we need to use the parent's content frame so that the entire
3083 // window is positioned within that content. Otherwise we can use
3084 // the display frame and let the attached window take care of
3085 // positioning its content appropriately.
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003086 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003087 cf.set(attached.getOverscanFrameLw());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003088 } else {
3089 // If the window is resizing, then we want to base the content
3090 // frame on our attached content frame to resize... however,
3091 // things can be tricky if the attached window is NOT in resize
3092 // mode, in which case its content frame will be larger.
3093 // Ungh. So to deal with that, make sure the content frame
3094 // we end up using is not covering the IM dock.
3095 cf.set(attached.getContentFrameLw());
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003096 if (attached.isVoiceInteraction()) {
3097 if (cf.left < mVoiceContentLeft) cf.left = mVoiceContentLeft;
3098 if (cf.top < mVoiceContentTop) cf.top = mVoiceContentTop;
3099 if (cf.right > mVoiceContentRight) cf.right = mVoiceContentRight;
3100 if (cf.bottom > mVoiceContentBottom) cf.bottom = mVoiceContentBottom;
3101 } else if (attached.getSurfaceLayer() < mDockLayer) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003102 if (cf.left < mContentLeft) cf.left = mContentLeft;
3103 if (cf.top < mContentTop) cf.top = mContentTop;
3104 if (cf.right > mContentRight) cf.right = mContentRight;
3105 if (cf.bottom > mContentBottom) cf.bottom = mContentBottom;
3106 }
3107 }
3108 df.set(insetDecors ? attached.getDisplayFrameLw() : cf);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003109 of.set(insetDecors ? attached.getOverscanFrameLw() : cf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003110 vf.set(attached.getVisibleFrameLw());
3111 }
3112 // The LAYOUT_IN_SCREEN flag is used to determine whether the attached
3113 // window should be positioned relative to its parent or the entire
3114 // screen.
3115 pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0
3116 ? attached.getFrameLw() : df);
3117 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003118
3119 private void applyStableConstraints(int sysui, int fl, Rect r) {
3120 if ((sysui & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
3121 // If app is requesting a stable layout, don't let the
3122 // content insets go below the stable values.
3123 if ((fl & FLAG_FULLSCREEN) != 0) {
3124 if (r.left < mStableFullscreenLeft) r.left = mStableFullscreenLeft;
3125 if (r.top < mStableFullscreenTop) r.top = mStableFullscreenTop;
3126 if (r.right > mStableFullscreenRight) r.right = mStableFullscreenRight;
3127 if (r.bottom > mStableFullscreenBottom) r.bottom = mStableFullscreenBottom;
3128 } else {
3129 if (r.left < mStableLeft) r.left = mStableLeft;
3130 if (r.top < mStableTop) r.top = mStableTop;
3131 if (r.right > mStableRight) r.right = mStableRight;
3132 if (r.bottom > mStableBottom) r.bottom = mStableBottom;
3133 }
3134 }
3135 }
3136
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003137 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07003138 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003139 public void layoutWindowLw(WindowState win, WindowState attached) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003140 // we've already done the status bar
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003141 final WindowManager.LayoutParams attrs = win.getAttrs();
3142 if ((win == mStatusBar && (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) == 0) ||
3143 win == mNavigationBar) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003144 return;
3145 }
Craig Mautner69b08182012-09-05 13:07:13 -07003146 final boolean isDefaultDisplay = win.isDefaultDisplay();
3147 final boolean needsToOffsetInputMethodTarget = isDefaultDisplay &&
satok1bc0a492012-04-25 22:47:12 +09003148 (win == mLastInputMethodTargetWindow && mLastInputMethodWindow != null);
3149 if (needsToOffsetInputMethodTarget) {
Craig Mautnereda67292013-04-28 13:50:14 -07003150 if (DEBUG_LAYOUT) Slog.i(TAG, "Offset ime target window by the last ime window state");
satok1bc0a492012-04-25 22:47:12 +09003151 offsetInputMethodWindowLw(mLastInputMethodWindow);
3152 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003153
John Spurlockc6d1c602014-01-17 15:22:06 -05003154 final int fl = PolicyControl.getWindowFlags(win, attrs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003155 final int sim = attrs.softInputMode;
John Spurlock1db8b682014-02-18 11:18:59 -05003156 final int sysUiFl = PolicyControl.getSystemUiVisibility(win, null);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003157
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003158 final Rect pf = mTmpParentFrame;
3159 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003160 final Rect of = mTmpOverscanFrame;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003161 final Rect cf = mTmpContentFrame;
3162 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04003163 final Rect dcf = mTmpDecorFrame;
Adrian Roosfa104232014-06-20 16:10:14 -07003164 final Rect sf = mTmpStableFrame;
John Spurlock46646232013-09-30 22:32:42 -04003165 dcf.setEmpty();
Craig Mautner69b08182012-09-05 13:07:13 -07003166
3167 final boolean hasNavBar = (isDefaultDisplay && mHasNavigationBar
Daniel Sandler36412a72011-08-04 09:35:13 -04003168 && mNavigationBar != null && mNavigationBar.isVisibleLw());
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003169
Craig Mautnerf683b562012-10-02 11:10:57 -07003170 final int adjust = sim & SOFT_INPUT_MASK_ADJUST;
3171
Adrian Roosfa104232014-06-20 16:10:14 -07003172 if (isDefaultDisplay) {
3173 sf.set(mStableLeft, mStableTop, mStableRight, mStableBottom);
3174 } else {
3175 sf.set(mOverscanLeft, mOverscanTop, mOverscanRight, mOverscanBottom);
3176 }
3177
Craig Mautner69b08182012-09-05 13:07:13 -07003178 if (!isDefaultDisplay) {
3179 if (attached != null) {
3180 // If this window is attached to another, our display
3181 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003182 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07003183 } else {
3184 // Give the window full screen.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003185 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3186 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3187 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08003188 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003189 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003190 = mOverscanScreenTop + mOverscanScreenHeight;
Craig Mautner69b08182012-09-05 13:07:13 -07003191 }
3192 } else if (attrs.type == TYPE_INPUT_METHOD) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003193 pf.left = df.left = of.left = cf.left = vf.left = mDockLeft;
3194 pf.top = df.top = of.top = cf.top = vf.top = mDockTop;
3195 pf.right = df.right = of.right = cf.right = vf.right = mDockRight;
John Spurlockc68d5772013-10-08 11:47:58 -04003196 // IM dock windows layout below the nav bar...
John Spurlock57beb3b2013-10-10 10:27:44 -04003197 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlockc68d5772013-10-08 11:47:58 -04003198 // ...with content insets above the nav bar
3199 cf.bottom = vf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003200 // IM dock windows always go to the bottom of the screen.
3201 attrs.gravity = Gravity.BOTTOM;
3202 mDockLayer = win.getSurfaceLayer();
3203 } else {
John Spurlock46646232013-09-30 22:32:42 -04003204
3205 // Default policy decor for the default display
3206 dcf.left = mSystemLeft;
3207 dcf.top = mSystemTop;
3208 dcf.right = mSystemRight;
3209 dcf.bottom = mSystemBottom;
John Spurlockbd957402013-10-03 11:38:39 -04003210 final boolean inheritTranslucentDecor = (attrs.privateFlags
3211 & WindowManager.LayoutParams.PRIVATE_FLAG_INHERIT_TRANSLUCENT_DECOR) != 0;
John Spurlock65567d42013-10-08 10:08:32 -04003212 final boolean isAppWindow =
3213 attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW &&
3214 attrs.type <= WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
3215 final boolean topAtRest =
3216 win == mTopFullscreenOpaqueWindowState && !win.isAnimatingLw();
3217 if (isAppWindow && !inheritTranslucentDecor && !topAtRest) {
John Spurlockbd957402013-10-03 11:38:39 -04003218 if ((sysUiFl & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0
3219 && (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0
Adrian Roosea562512014-05-05 13:33:03 +02003220 && (fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) == 0
3221 && (fl & WindowManager.LayoutParams.
3222 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04003223 // Ensure policy decor includes status bar
3224 dcf.top = mStableTop;
3225 }
John Spurlockbd957402013-10-03 11:38:39 -04003226 if ((fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) == 0
Adrian Roosea562512014-05-05 13:33:03 +02003227 && (sysUiFl & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0
3228 && (fl & WindowManager.LayoutParams.
3229 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04003230 // Ensure policy decor includes navigation bar
3231 dcf.bottom = mStableBottom;
3232 dcf.right = mStableRight;
3233 }
3234 }
3235
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003236 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
3237 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
RoboErik8a2cfc32014-05-16 11:19:38 -07003238 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003239 + "): IN_SCREEN, INSET_DECOR");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003240 // This is the case for a normal activity window: we want it
3241 // to cover all of the screen space, and it can take care of
3242 // moving its contents to account for screen decorations that
3243 // intrude into that space.
3244 if (attached != null) {
3245 // If this window is attached to another, our display
3246 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003247 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003248 } else {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003249 if (attrs.type == TYPE_STATUS_BAR_PANEL
3250 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Joe Onorato29fc2c92010-11-24 10:26:50 -08003251 // Status bar panels are the only windows who can go on top of
3252 // the status bar. They are protected by the STATUS_BAR_SERVICE
3253 // permission, so they have the same privileges as the status
3254 // bar itself.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003255 //
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003256 // However, they should still dodge the navigation bar if it exists.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003257
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003258 pf.left = df.left = of.left = hasNavBar
3259 ? mDockLeft : mUnrestrictedScreenLeft;
3260 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3261 pf.right = df.right = of.right = hasNavBar
3262 ? mRestrictedScreenLeft+mRestrictedScreenWidth
3263 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3264 pf.bottom = df.bottom = of.bottom = hasNavBar
3265 ? mRestrictedScreenTop+mRestrictedScreenHeight
3266 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003267
Craig Mautnereda67292013-04-28 13:50:14 -07003268 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003269 "Laying out status bar window: (%d,%d - %d,%d)",
3270 pf.left, pf.top, pf.right, pf.bottom));
John Spurlock46646232013-09-30 22:32:42 -04003271 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08003272 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3273 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3274 // Asking to layout into the overscan region, so give it that pure
3275 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003276 pf.left = df.left = of.left = mOverscanScreenLeft;
3277 pf.top = df.top = of.top = mOverscanScreenTop;
3278 pf.right = df.right = of.right = mOverscanScreenLeft + mOverscanScreenWidth;
3279 pf.bottom = df.bottom = of.bottom = mOverscanScreenTop
3280 + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003281 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003282 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003283 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3284 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003285 // Asking for layout as if the nav bar is hidden, lets the
Dianne Hackbornc652de82013-02-15 16:32:56 -08003286 // application extend into the unrestricted overscan screen area. We
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003287 // only do this for application windows to ensure no window that
3288 // can be above the nav bar can do this.
Dianne Hackborn313440842013-02-19 19:22:59 -08003289 pf.left = df.left = mOverscanScreenLeft;
3290 pf.top = df.top = mOverscanScreenTop;
3291 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
3292 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003293 // We need to tell the app about where the frame inside the overscan
3294 // is, so it can inset its content by that amount -- it didn't ask
3295 // to actually extend itself into the overscan region.
3296 of.left = mUnrestrictedScreenLeft;
3297 of.top = mUnrestrictedScreenTop;
3298 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3299 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003300 } else {
Dianne Hackborn313440842013-02-19 19:22:59 -08003301 pf.left = df.left = mRestrictedOverscanScreenLeft;
3302 pf.top = df.top = mRestrictedOverscanScreenTop;
3303 pf.right = df.right = mRestrictedOverscanScreenLeft
3304 + mRestrictedOverscanScreenWidth;
3305 pf.bottom = df.bottom = mRestrictedOverscanScreenTop
3306 + mRestrictedOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003307 // We need to tell the app about where the frame inside the overscan
3308 // is, so it can inset its content by that amount -- it didn't ask
3309 // to actually extend itself into the overscan region.
3310 of.left = mUnrestrictedScreenLeft;
3311 of.top = mUnrestrictedScreenTop;
3312 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3313 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003314 }
Craig Mautner69b08182012-09-05 13:07:13 -07003315
John Spurlock46646232013-09-30 22:32:42 -04003316 if ((fl & FLAG_FULLSCREEN) == 0) {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003317 if (win.isVoiceInteraction()) {
3318 cf.left = mVoiceContentLeft;
3319 cf.top = mVoiceContentTop;
3320 cf.right = mVoiceContentRight;
3321 cf.bottom = mVoiceContentBottom;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003322 } else {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003323 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
3324 cf.left = mDockLeft;
3325 cf.top = mDockTop;
3326 cf.right = mDockRight;
3327 cf.bottom = mDockBottom;
3328 } else {
3329 cf.left = mContentLeft;
3330 cf.top = mContentTop;
3331 cf.right = mContentRight;
3332 cf.bottom = mContentBottom;
3333 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003334 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003335 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003336 // Full screen windows are always given a layout that is as if the
3337 // status bar and other transient decors are gone. This is to avoid
3338 // bad states when moving from a window that is not hding the
3339 // status bar to one that is.
3340 cf.left = mRestrictedScreenLeft;
3341 cf.top = mRestrictedScreenTop;
3342 cf.right = mRestrictedScreenLeft + mRestrictedScreenWidth;
3343 cf.bottom = mRestrictedScreenTop + mRestrictedScreenHeight;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003344 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003345 applyStableConstraints(sysUiFl, fl, cf);
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003346 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3347 vf.left = mCurLeft;
3348 vf.top = mCurTop;
3349 vf.right = mCurRight;
3350 vf.bottom = mCurBottom;
3351 } else {
3352 vf.set(cf);
3353 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003354 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003355 } else if ((fl & FLAG_LAYOUT_IN_SCREEN) != 0 || (sysUiFl
3356 & (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
3357 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)) != 0) {
Craig Mautnereda67292013-04-28 13:50:14 -07003358 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3359 "): IN_SCREEN");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003360 // A window that has requested to fill the entire screen just
3361 // gets everything, period.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003362 if (attrs.type == TYPE_STATUS_BAR_PANEL
3363 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003364 pf.left = df.left = of.left = cf.left = hasNavBar
3365 ? mDockLeft : mUnrestrictedScreenLeft;
3366 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
3367 pf.right = df.right = of.right = cf.right = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003368 ? mRestrictedScreenLeft+mRestrictedScreenWidth
Dianne Hackbornc652de82013-02-15 16:32:56 -08003369 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003370 pf.bottom = df.bottom = of.bottom = cf.bottom = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003371 ? mRestrictedScreenTop+mRestrictedScreenHeight
Dianne Hackbornc652de82013-02-15 16:32:56 -08003372 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07003373 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler36412a72011-08-04 09:35:13 -04003374 "Laying out IN_SCREEN status bar window: (%d,%d - %d,%d)",
3375 pf.left, pf.top, pf.right, pf.bottom));
Jim Millere898ac52012-04-06 17:10:57 -07003376 } else if (attrs.type == TYPE_NAVIGATION_BAR
3377 || attrs.type == TYPE_NAVIGATION_BAR_PANEL) {
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003378 // The navigation bar has Real Ultimate Power.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003379 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3380 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3381 pf.right = df.right = of.right = mUnrestrictedScreenLeft
3382 + mUnrestrictedScreenWidth;
3383 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop
3384 + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07003385 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003386 "Laying out navigation bar window: (%d,%d - %d,%d)",
3387 pf.left, pf.top, pf.right, pf.bottom));
Dianne Hackborn01011c32012-02-21 13:54:21 -08003388 } else if ((attrs.type == TYPE_SECURE_SYSTEM_OVERLAY
3389 || attrs.type == TYPE_BOOT_PROGRESS)
Jeff Brownbfcb60a2011-09-08 18:51:14 -07003390 && ((fl & FLAG_FULLSCREEN) != 0)) {
3391 // Fullscreen secure system overlays get what they ask for.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003392 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3393 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3394 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
3395 + mOverscanScreenWidth;
3396 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
3397 + mOverscanScreenHeight;
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07003398 } else if (attrs.type == TYPE_BOOT_PROGRESS
3399 || attrs.type == TYPE_UNIVERSE_BACKGROUND) {
Dianne Hackborn01011c32012-02-21 13:54:21 -08003400 // Boot progress screen always covers entire display.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003401 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3402 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3403 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
3404 + mOverscanScreenWidth;
3405 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
3406 + mOverscanScreenHeight;
John Spurlockef4adae2013-08-26 17:58:58 -04003407 } else if (attrs.type == TYPE_WALLPAPER) {
3408 // The wallpaper also has Real Ultimate Power.
3409 pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft;
3410 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003411 pf.right = df.right = of.right = cf.right
John Spurlockef4adae2013-08-26 17:58:58 -04003412 = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003413 pf.bottom = df.bottom = of.bottom = cf.bottom
John Spurlockef4adae2013-08-26 17:58:58 -04003414 = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlock46646232013-09-30 22:32:42 -04003415 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08003416 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3417 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3418 // Asking to layout into the overscan region, so give it that pure
3419 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003420 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3421 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3422 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08003423 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003424 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003425 = mOverscanScreenTop + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003426 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003427 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Craig Mautnerbeac1062014-06-03 14:38:57 -07003428 && (attrs.type == TYPE_STATUS_BAR
3429 || attrs.type == TYPE_TOAST
John Spurlock34e13d92013-08-10 06:52:28 -04003430 || (attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3431 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW))) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003432 // Asking for layout as if the nav bar is hidden, lets the
3433 // application extend into the unrestricted screen area. We
John Spurlock34e13d92013-08-10 06:52:28 -04003434 // only do this for application windows (or toasts) to ensure no window that
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003435 // can be above the nav bar can do this.
3436 // XXX This assumes that an app asking for this will also
3437 // ask for layout in only content. We can't currently figure out
3438 // what the screen would be if only laying out to hide the nav bar.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003439 pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft;
3440 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
3441 pf.right = df.right = of.right = cf.right = mUnrestrictedScreenLeft
3442 + mUnrestrictedScreenWidth;
3443 pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop
3444 + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003445 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003446 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
3447 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
3448 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
3449 + mRestrictedScreenWidth;
3450 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
3451 + mRestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003452 }
Craig Mautner69b08182012-09-05 13:07:13 -07003453
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003454 applyStableConstraints(sysUiFl, fl, cf);
Craig Mautner69b08182012-09-05 13:07:13 -07003455
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003456 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3457 vf.left = mCurLeft;
3458 vf.top = mCurTop;
3459 vf.right = mCurRight;
3460 vf.bottom = mCurBottom;
3461 } else {
3462 vf.set(cf);
3463 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003464 } else if (attached != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07003465 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3466 "): attached to " + attached);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003467 // A child window should be placed inside of the same visible
3468 // frame that its parent had.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003469 setAttachedWindowFrames(win, fl, adjust, attached, false, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003470 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07003471 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3472 "): normal window");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003473 // Otherwise, a normal window must be placed inside the content
3474 // of all screen decorations.
Dianne Hackborna239c842011-06-01 12:28:20 -07003475 if (attrs.type == TYPE_STATUS_BAR_PANEL) {
3476 // Status bar panels are the only windows who can go on top of
3477 // the status bar. They are protected by the STATUS_BAR_SERVICE
3478 // permission, so they have the same privileges as the status
3479 // bar itself.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003480 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
3481 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
3482 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
3483 + mRestrictedScreenWidth;
3484 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
3485 + mRestrictedScreenHeight;
John Spurlock414c1f02013-12-04 13:47:36 -05003486 } else if (attrs.type == TYPE_TOAST || attrs.type == TYPE_SYSTEM_ALERT
3487 || attrs.type == TYPE_VOLUME_OVERLAY) {
3488 // These dialogs are stable to interim decor changes.
John Spurlockbd957402013-10-03 11:38:39 -04003489 pf.left = df.left = of.left = cf.left = mStableLeft;
3490 pf.top = df.top = of.top = cf.top = mStableTop;
3491 pf.right = df.right = of.right = cf.right = mStableRight;
3492 pf.bottom = df.bottom = of.bottom = cf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003493 } else {
Dianne Hackborna239c842011-06-01 12:28:20 -07003494 pf.left = mContentLeft;
3495 pf.top = mContentTop;
3496 pf.right = mContentRight;
3497 pf.bottom = mContentBottom;
Dianne Hackborn20d94742014-05-29 18:35:45 -07003498 if (win.isVoiceInteraction()) {
3499 df.left = of.left = cf.left = mVoiceContentLeft;
3500 df.top = of.top = cf.top = mVoiceContentTop;
3501 df.right = of.right = cf.right = mVoiceContentRight;
3502 df.bottom = of.bottom = cf.bottom = mVoiceContentBottom;
3503 } else if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003504 df.left = of.left = cf.left = mDockLeft;
3505 df.top = of.top = cf.top = mDockTop;
3506 df.right = of.right = cf.right = mDockRight;
3507 df.bottom = of.bottom = cf.bottom = mDockBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07003508 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003509 df.left = of.left = cf.left = mContentLeft;
3510 df.top = of.top = cf.top = mContentTop;
3511 df.right = of.right = cf.right = mContentRight;
3512 df.bottom = of.bottom = cf.bottom = mContentBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07003513 }
3514 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3515 vf.left = mCurLeft;
3516 vf.top = mCurTop;
3517 vf.right = mCurRight;
3518 vf.bottom = mCurBottom;
3519 } else {
3520 vf.set(cf);
3521 }
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003522 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003523 }
3524 }
Craig Mautner69b08182012-09-05 13:07:13 -07003525
Craig Mautnerb816bed2013-07-23 10:26:17 -07003526 // TYPE_SYSTEM_ERROR is above the NavigationBar so it can't be allowed to extend over it.
3527 if ((fl & FLAG_LAYOUT_NO_LIMITS) != 0 && attrs.type != TYPE_SYSTEM_ERROR) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003528 df.left = df.top = of.left = of.top = cf.left = cf.top = vf.left = vf.top = -10000;
3529 df.right = df.bottom = of.right = of.bottom = cf.right = cf.bottom
3530 = vf.right = vf.bottom = 10000;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003531 }
3532
Craig Mautnereda67292013-04-28 13:50:14 -07003533 if (DEBUG_LAYOUT) Slog.v(TAG, "Compute frame " + attrs.getTitle()
The Android Open Source Project11267662009-03-18 17:39:47 -07003534 + ": sim=#" + Integer.toHexString(sim)
RoboErik8a2cfc32014-05-16 11:19:38 -07003535 + " attach=" + attached + " type=" + attrs.type
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003536 + String.format(" flags=0x%08x", fl)
The Android Open Source Project11267662009-03-18 17:39:47 -07003537 + " pf=" + pf.toShortString() + " df=" + df.toShortString()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003538 + " of=" + of.toShortString()
John Spurlock46646232013-09-30 22:32:42 -04003539 + " cf=" + cf.toShortString() + " vf=" + vf.toShortString()
Adrian Roosfa104232014-06-20 16:10:14 -07003540 + " dcf=" + dcf.toShortString()
3541 + " sf=" + sf.toShortString());
Craig Mautner69b08182012-09-05 13:07:13 -07003542
Adrian Roosfa104232014-06-20 16:10:14 -07003543 win.computeFrameLw(pf, df, of, cf, vf, dcf, sf);
Craig Mautner69b08182012-09-05 13:07:13 -07003544
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003545 // Dock windows carve out the bottom of the screen, so normal windows
3546 // can't appear underneath them.
Craig Mautner8bd206b2012-10-03 10:32:02 -07003547 if (attrs.type == TYPE_INPUT_METHOD && win.isVisibleOrBehindKeyguardLw()
3548 && !win.getGivenInsetsPendingLw()) {
satok1bc0a492012-04-25 22:47:12 +09003549 setLastInputMethodWindowLw(null, null);
3550 offsetInputMethodWindowLw(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003551 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003552 if (attrs.type == TYPE_VOICE_INTERACTION && win.isVisibleOrBehindKeyguardLw()
3553 && !win.getGivenInsetsPendingLw()) {
3554 offsetVoiceInputWindowLw(win);
3555 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003556 }
3557
satok1bc0a492012-04-25 22:47:12 +09003558 private void offsetInputMethodWindowLw(WindowState win) {
3559 int top = win.getContentFrameLw().top;
3560 top += win.getGivenContentInsetsLw().top;
3561 if (mContentBottom > top) {
3562 mContentBottom = top;
3563 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003564 if (mVoiceContentBottom > top) {
3565 mVoiceContentBottom = top;
3566 }
satok1bc0a492012-04-25 22:47:12 +09003567 top = win.getVisibleFrameLw().top;
3568 top += win.getGivenVisibleInsetsLw().top;
3569 if (mCurBottom > top) {
3570 mCurBottom = top;
3571 }
Craig Mautnereda67292013-04-28 13:50:14 -07003572 if (DEBUG_LAYOUT) Slog.v(TAG, "Input method: mDockBottom="
satok1bc0a492012-04-25 22:47:12 +09003573 + mDockBottom + " mContentBottom="
3574 + mContentBottom + " mCurBottom=" + mCurBottom);
3575 }
3576
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003577 private void offsetVoiceInputWindowLw(WindowState win) {
3578 final int gravity = win.getAttrs().gravity;
3579 switch (gravity&((Gravity.AXIS_PULL_BEFORE|Gravity.AXIS_PULL_AFTER)
3580 << Gravity.AXIS_X_SHIFT)) {
3581 case Gravity.AXIS_PULL_BEFORE<<Gravity.AXIS_X_SHIFT: {
3582 int right = win.getContentFrameLw().right - win.getGivenContentInsetsLw().right;
3583 if (mVoiceContentLeft < right) {
3584 mVoiceContentLeft = right;
3585 }
3586 } break;
3587 case Gravity.AXIS_PULL_AFTER<<Gravity.AXIS_X_SHIFT: {
3588 int left = win.getContentFrameLw().left - win.getGivenContentInsetsLw().left;
3589 if (mVoiceContentRight < left) {
3590 mVoiceContentRight = left;
3591 }
3592 } break;
3593 }
3594 switch (gravity&((Gravity.AXIS_PULL_BEFORE|Gravity.AXIS_PULL_AFTER)
3595 << Gravity.AXIS_Y_SHIFT)) {
3596 case Gravity.AXIS_PULL_BEFORE<<Gravity.AXIS_Y_SHIFT: {
3597 int bottom = win.getContentFrameLw().bottom - win.getGivenContentInsetsLw().bottom;
3598 if (mVoiceContentTop < bottom) {
3599 mVoiceContentTop = bottom;
3600 }
3601 } break;
3602 case Gravity.AXIS_PULL_AFTER<<Gravity.AXIS_Y_SHIFT: {
3603 int top = win.getContentFrameLw().top - win.getGivenContentInsetsLw().top;
3604 if (mVoiceContentBottom < top) {
3605 mVoiceContentBottom = top;
3606 }
3607 } break;
3608 }
3609 }
3610
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003611 /** {@inheritDoc} */
Craig Mautner61ac6bb2012-02-02 17:29:33 -08003612 @Override
3613 public void finishLayoutLw() {
3614 return;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003615 }
3616
3617 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003618 @Override
Craig Mautner39834192012-09-02 07:47:24 -07003619 public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) {
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003620 mTopFullscreenOpaqueWindowState = null;
Craig Mautner2bc789b2014-03-19 19:48:38 -07003621 mAppsToBeHidden.clear();
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003622 mForceStatusBar = false;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003623 mForceStatusBarFromKeyguard = false;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08003624 mForcingShowNavBar = false;
3625 mForcingShowNavBarLayer = -1;
RoboErik8a2cfc32014-05-16 11:19:38 -07003626
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003627 mHideLockScreen = false;
3628 mAllowLockscreenWhenOn = false;
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003629 mDismissKeyguard = DISMISS_KEYGUARD_NONE;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003630 mShowingLockscreen = false;
3631 mShowingDream = false;
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003632 mWinShowWhenLocked = null;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003633 }
3634
3635 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003636 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003637 public void applyPostLayoutPolicyLw(WindowState win, WindowManager.LayoutParams attrs) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07003638 if (DEBUG_LAYOUT) Slog.i(TAG, "Win " + win + ": isVisibleOrBehindKeyguardLw="
3639 + win.isVisibleOrBehindKeyguardLw());
John Spurlockc6d1c602014-01-17 15:22:06 -05003640 final int fl = PolicyControl.getWindowFlags(win, attrs);
John Spurlock414c1f02013-12-04 13:47:36 -05003641 if (mTopFullscreenOpaqueWindowState == null
3642 && win.isVisibleLw() && attrs.type == TYPE_INPUT_METHOD) {
3643 mForcingShowNavBar = true;
3644 mForcingShowNavBarLayer = win.getSurfaceLayer();
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08003645 }
Jorim Jaggiafd4a552014-04-08 15:13:05 +02003646 if (attrs.type == TYPE_STATUS_BAR && (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Jorim Jaggiafd4a552014-04-08 15:13:05 +02003647 mForceStatusBarFromKeyguard = true;
3648 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003649 if (mTopFullscreenOpaqueWindowState == null &&
Dianne Hackborn01b02a72012-01-12 14:05:03 -08003650 win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()) {
John Spurlockc6d1c602014-01-17 15:22:06 -05003651 if ((fl & FLAG_FORCE_NOT_FULLSCREEN) != 0) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003652 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003653 mForceStatusBarFromKeyguard = true;
3654 } else {
3655 mForceStatusBar = true;
3656 }
3657 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003658 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003659 mShowingLockscreen = true;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07003660 }
Craig Mautnerab55e522014-03-03 13:26:03 -08003661 boolean appWindow = attrs.type >= FIRST_APPLICATION_WINDOW
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003662 && attrs.type <= LAST_APPLICATION_WINDOW;
3663 if (attrs.type == TYPE_DREAM) {
Jeff Brownc8018eb2012-10-29 21:33:27 -07003664 // If the lockscreen was showing when the dream started then wait
3665 // for the dream to draw before hiding the lockscreen.
3666 if (!mDreamingLockscreen
3667 || (win.isVisibleLw() && win.hasDrawnLw())) {
3668 mShowingDream = true;
Craig Mautnerab55e522014-03-03 13:26:03 -08003669 appWindow = true;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003670 }
3671 }
Craig Mautnerab55e522014-03-03 13:26:03 -08003672
Craig Mautner00156ec2014-03-06 22:29:02 -08003673 final boolean showWhenLocked = (fl & FLAG_SHOW_WHEN_LOCKED) != 0;
Craig Mautner74ee9382014-04-01 15:20:16 -07003674 final boolean dismissKeyguard = (fl & FLAG_DISMISS_KEYGUARD) != 0;
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003675 final boolean secureKeyguard = isKeyguardSecure();
Craig Mautnerab55e522014-03-03 13:26:03 -08003676 if (appWindow) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003677 if (showWhenLocked || (dismissKeyguard && !secureKeyguard)) {
3678 // Remove any previous windows with the same appToken.
Craig Mautner2bc789b2014-03-19 19:48:38 -07003679 mAppsToBeHidden.remove(win.getAppToken());
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003680 if (mAppsToBeHidden.isEmpty() && showWhenLocked &&
3681 isKeyguardSecureIncludingHidden()) {
3682 mWinShowWhenLocked = win;
3683 mHideLockScreen = true;
3684 mForceStatusBarFromKeyguard = false;
3685 }
Craig Mautner2bc789b2014-03-19 19:48:38 -07003686 } else {
3687 mAppsToBeHidden.add(win.getAppToken());
3688 }
Craig Mautnerab55e522014-03-03 13:26:03 -08003689 if (attrs.x == 0 && attrs.y == 0
3690 && attrs.width == WindowManager.LayoutParams.MATCH_PARENT
3691 && attrs.height == WindowManager.LayoutParams.MATCH_PARENT) {
3692 if (DEBUG_LAYOUT) Slog.v(TAG, "Fullscreen window: " + win);
3693 mTopFullscreenOpaqueWindowState = win;
Craig Mautner2bc789b2014-03-19 19:48:38 -07003694 if (mAppsToBeHidden.isEmpty()) {
Craig Mautnerda09ae32014-03-03 13:26:03 -08003695 if (showWhenLocked) {
3696 if (DEBUG_LAYOUT) Slog.v(TAG,
3697 "Setting mHideLockScreen to true by win " + win);
3698 mHideLockScreen = true;
3699 mForceStatusBarFromKeyguard = false;
3700 }
Craig Mautner4bdab6b2014-04-01 12:05:11 -07003701 if (dismissKeyguard && mDismissKeyguard == DISMISS_KEYGUARD_NONE) {
Craig Mautnerda09ae32014-03-03 13:26:03 -08003702 if (DEBUG_LAYOUT) Slog.v(TAG,
3703 "Setting mDismissKeyguard true by win " + win);
3704 mDismissKeyguard = mWinDismissingKeyguard == win ?
3705 DISMISS_KEYGUARD_CONTINUE : DISMISS_KEYGUARD_START;
3706 mWinDismissingKeyguard = win;
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003707 mForceStatusBarFromKeyguard = mShowingLockscreen && secureKeyguard;
Craig Mautnerda09ae32014-03-03 13:26:03 -08003708 }
Craig Mautnerab55e522014-03-03 13:26:03 -08003709 }
Craig Mautner00156ec2014-03-06 22:29:02 -08003710 if ((fl & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) {
Craig Mautnerab55e522014-03-03 13:26:03 -08003711 mAllowLockscreenWhenOn = true;
3712 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003713 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003714
3715 if (mWinShowWhenLocked != null &&
3716 mWinShowWhenLocked.getAppToken() != win.getAppToken()) {
3717 win.hideLw(false);
3718 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003719 }
3720 }
3721 }
3722
3723 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003724 @Override
Craig Mautner39834192012-09-02 07:47:24 -07003725 public int finishPostLayoutPolicyLw() {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003726 if (mWinShowWhenLocked != null &&
3727 mWinShowWhenLocked != mTopFullscreenOpaqueWindowState) {
3728 // A dialog is dismissing the keyguard. Put the wallpaper behind it and hide the
3729 // fullscreen window.
3730 // TODO: Make sure FLAG_SHOW_WALLPAPER is restored when dialog is dismissed. Or not.
3731 mWinShowWhenLocked.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
3732 mTopFullscreenOpaqueWindowState.hideLw(false);
3733 mTopFullscreenOpaqueWindowState = mWinShowWhenLocked;
3734 }
3735
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003736 int changes = 0;
Joe Onorato93056472010-09-10 10:30:46 -04003737 boolean topIsFullscreen = false;
Daniel Sandlere02d8082010-10-08 15:13:22 -04003738
3739 final WindowManager.LayoutParams lp = (mTopFullscreenOpaqueWindowState != null)
3740 ? mTopFullscreenOpaqueWindowState.getAttrs()
3741 : null;
3742
Jeff Brownc8018eb2012-10-29 21:33:27 -07003743 // If we are not currently showing a dream then remember the current
3744 // lockscreen state. We will use this to determine whether the dream
3745 // started while the lockscreen was showing and remember this state
3746 // while the dream is showing.
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003747 if (!mShowingDream) {
3748 mDreamingLockscreen = mShowingLockscreen;
3749 }
3750
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003751 if (mStatusBar != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07003752 if (DEBUG_LAYOUT) Slog.i(TAG, "force=" + mForceStatusBar
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003753 + " forcefkg=" + mForceStatusBarFromKeyguard
Dianne Hackbornd70bc2f2009-10-06 23:25:51 -07003754 + " top=" + mTopFullscreenOpaqueWindowState);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003755 if (mForceStatusBar || mForceStatusBarFromKeyguard) {
Craig Mautnereda67292013-04-28 13:50:14 -07003756 if (DEBUG_LAYOUT) Slog.v(TAG, "Showing status bar: forced");
John Spurlock27735a42013-08-14 17:57:38 -04003757 if (mStatusBarController.setBarShowingLw(true)) {
3758 changes |= FINISH_LAYOUT_REDO_LAYOUT;
3759 }
Craig Mautner81defc72013-10-29 11:10:42 -07003760 // Maintain fullscreen layout until incoming animation is complete.
3761 topIsFullscreen = mTopIsFullscreen && mStatusBar.isAnimatingLw();
John Spurlockf92b6162013-11-11 15:01:16 -05003762 // Transient status bar on the lockscreen is not allowed
3763 if (mForceStatusBarFromKeyguard && mStatusBarController.isTransientShowing()) {
3764 mStatusBarController.updateVisibilityLw(false /*transientAllowed*/,
3765 mLastSystemUiFlags, mLastSystemUiFlags);
3766 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003767 } else if (mTopFullscreenOpaqueWindowState != null) {
John Spurlockc6d1c602014-01-17 15:22:06 -05003768 final int fl = PolicyControl.getWindowFlags(null, lp);
Joe Onorato93056472010-09-10 10:30:46 -04003769 if (localLOGV) {
Craig Mautnereda67292013-04-28 13:50:14 -07003770 Slog.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw()
Joe Onorato93056472010-09-10 10:30:46 -04003771 + " shown frame: " + mTopFullscreenOpaqueWindowState.getShownFrameLw());
Craig Mautnereda67292013-04-28 13:50:14 -07003772 Slog.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs()
John Spurlockc6d1c602014-01-17 15:22:06 -05003773 + " lp.flags=0x" + Integer.toHexString(fl));
Joe Onorato93056472010-09-10 10:30:46 -04003774 }
John Spurlockc6d1c602014-01-17 15:22:06 -05003775 topIsFullscreen = (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003776 || (mLastSystemUiFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
Joe Onorato93056472010-09-10 10:30:46 -04003777 // The subtle difference between the window for mTopFullscreenOpaqueWindowState
3778 // and mTopIsFullscreen is that that mTopIsFullscreen is set only if the window
3779 // has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the
3780 // case though.
John Spurlock27735a42013-08-14 17:57:38 -04003781 if (mStatusBarController.isTransientShowing()) {
3782 if (mStatusBarController.setBarShowingLw(true)) {
John Spurlock32beb2c2013-03-11 10:16:47 -04003783 changes |= FINISH_LAYOUT_REDO_LAYOUT;
3784 }
3785 } else if (topIsFullscreen) {
Craig Mautnereda67292013-04-28 13:50:14 -07003786 if (DEBUG_LAYOUT) Slog.v(TAG, "** HIDING status bar");
John Spurlock27735a42013-08-14 17:57:38 -04003787 if (mStatusBarController.setBarShowingLw(false)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003788 changes |= FINISH_LAYOUT_REDO_LAYOUT;
Craig Mautnereda67292013-04-28 13:50:14 -07003789 } else {
Craig Mautnerc5a6e442013-06-05 17:22:35 -07003790 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar already hiding");
Daniel Sandler40427442010-07-16 11:44:52 -04003791 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003792 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07003793 if (DEBUG_LAYOUT) Slog.v(TAG, "** SHOWING status bar: top is not fullscreen");
John Spurlock27735a42013-08-14 17:57:38 -04003794 if (mStatusBarController.setBarShowingLw(true)) {
3795 changes |= FINISH_LAYOUT_REDO_LAYOUT;
3796 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003797 }
3798 }
3799 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04003800
Craig Mautner81defc72013-10-29 11:10:42 -07003801 if (mTopIsFullscreen != topIsFullscreen) {
3802 if (!topIsFullscreen) {
3803 // Force another layout when status bar becomes fully shown.
3804 changes |= FINISH_LAYOUT_REDO_LAYOUT;
3805 }
3806 mTopIsFullscreen = topIsFullscreen;
3807 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04003808
Craig Mautner39834192012-09-02 07:47:24 -07003809 // Hide the key guard if a visible window explicitly specifies that it wants to be
3810 // displayed when the screen is locked.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01003811 if (mKeyguardDelegate != null && mStatusBar != null) {
3812 if (localLOGV) Slog.v(TAG, "finishPostLayoutPolicyLw: mHideKeyguard="
3813 + mHideLockScreen);
3814 if (mDismissKeyguard != DISMISS_KEYGUARD_NONE && !isKeyguardSecure()) {
3815 mKeyguardHidden = true;
3816 if (processKeyguardSetHiddenResultLw(mKeyguardDelegate.setOccluded(true))) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003817 changes |= FINISH_LAYOUT_REDO_LAYOUT
3818 | FINISH_LAYOUT_REDO_CONFIG
3819 | FINISH_LAYOUT_REDO_WALLPAPER;
3820 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01003821 if (mKeyguardDelegate.isShowing()) {
3822 mHandler.post(new Runnable() {
3823 @Override
3824 public void run() {
3825 mKeyguardDelegate.keyguardDone(false, false);
3826 }
3827 });
3828 }
3829 } else if (mHideLockScreen) {
3830 mKeyguardHidden = true;
3831 if (processKeyguardSetHiddenResultLw(mKeyguardDelegate.setOccluded(true))) {
3832 changes |= FINISH_LAYOUT_REDO_LAYOUT
3833 | FINISH_LAYOUT_REDO_CONFIG
3834 | FINISH_LAYOUT_REDO_WALLPAPER;
3835 }
3836 } else if (mDismissKeyguard != DISMISS_KEYGUARD_NONE) {
3837 // This is the case of keyguard isSecure() and not mHideLockScreen.
3838 if (mDismissKeyguard == DISMISS_KEYGUARD_START) {
3839 // Only launch the next keyguard unlock window once per window.
3840 mKeyguardHidden = false;
3841 if (processKeyguardSetHiddenResultLw(mKeyguardDelegate.setOccluded(false))) {
3842 changes |= FINISH_LAYOUT_REDO_LAYOUT
3843 | FINISH_LAYOUT_REDO_CONFIG
3844 | FINISH_LAYOUT_REDO_WALLPAPER;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003845 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01003846 mHandler.post(new Runnable() {
3847 @Override
3848 public void run() {
3849 mKeyguardDelegate.dismiss();
3850 }
3851 });
3852 }
3853 } else {
3854 mWinDismissingKeyguard = null;
3855 mKeyguardHidden = false;
3856 if (processKeyguardSetHiddenResultLw(mKeyguardDelegate.setOccluded(false))) {
3857 changes |= FINISH_LAYOUT_REDO_LAYOUT
3858 | FINISH_LAYOUT_REDO_CONFIG
3859 | FINISH_LAYOUT_REDO_WALLPAPER;
3860 }
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -07003861 }
3862 }
Joe Onorato664644d2011-01-23 17:53:23 -08003863
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003864 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003865 // If the navigation bar has been hidden or shown, we need to do another
3866 // layout pass to update that window.
3867 changes |= FINISH_LAYOUT_REDO_LAYOUT;
3868 }
Joe Onorato664644d2011-01-23 17:53:23 -08003869
Mike Lockwood28569302010-01-28 11:54:40 -05003870 // update since mAllowLockscreenWhenOn might have changed
3871 updateLockScreenTimeout();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003872 return changes;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003873 }
3874
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003875 /**
Jorim Jaggi5cf17872014-03-26 18:31:48 +01003876 * Processes the result code of {@link IKeyguardService#setOccluded}. This is needed because we
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003877 * immediately need to put the wallpaper directly behind the Keyguard when a window with flag
3878 * {@link android.view.WindowManager.LayoutParams#FLAG_SHOW_WHEN_LOCKED} gets dismissed. If we
3879 * would wait for Keyguard to change the flags, that would be running asynchronously and thus be
3880 * too late so the user might see the window behind.
3881 *
Jorim Jaggi5cf17872014-03-26 18:31:48 +01003882 * @param setHiddenResult The result code from {@link IKeyguardService#setOccluded}.
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003883 * @return Whether the flags have changed and we have to redo the layout.
3884 */
3885 private boolean processKeyguardSetHiddenResultLw(int setHiddenResult) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01003886 if (setHiddenResult
3887 == IKeyguardServiceConstants.KEYGUARD_SERVICE_SET_OCCLUDED_RESULT_SET_FLAGS) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003888 mStatusBar.getAttrs().privateFlags |= PRIVATE_FLAG_KEYGUARD;
3889 mStatusBar.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
3890 return true;
3891 } else if (setHiddenResult
Jorim Jaggi5cf17872014-03-26 18:31:48 +01003892 == IKeyguardServiceConstants.KEYGUARD_SERVICE_SET_OCCLUDED_RESULT_UNSET_FLAGS) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003893 mStatusBar.getAttrs().privateFlags &= ~PRIVATE_FLAG_KEYGUARD;
3894 mStatusBar.getAttrs().flags &= ~FLAG_SHOW_WALLPAPER;
3895 return true;
3896 } else {
3897 return false;
3898 }
3899 }
3900
3901 private boolean isStatusBarKeyguard() {
3902 return mStatusBar != null
3903 && (mStatusBar.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
3904 }
3905
Dianne Hackborn08743722009-12-21 12:16:51 -08003906 public boolean allowAppAnimationsLw() {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003907 if (isStatusBarKeyguard() || mShowingDream) {
Craig Mautner28816302013-10-10 20:31:00 -07003908 // If keyguard or dreams is currently visible, no reason to animate behind it.
Dianne Hackborn08743722009-12-21 12:16:51 -08003909 return false;
3910 }
Dianne Hackborn08743722009-12-21 12:16:51 -08003911 return true;
3912 }
3913
Dianne Hackborndf89e652011-10-06 22:35:11 -07003914 public int focusChangedLw(WindowState lastFocus, WindowState newFocus) {
Joe Onorato664644d2011-01-23 17:53:23 -08003915 mFocusedWindow = newFocus;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003916 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003917 // If the navigation bar has been hidden or shown, we need to do another
3918 // layout pass to update that window.
3919 return FINISH_LAYOUT_REDO_LAYOUT;
3920 }
3921 return 0;
Joe Onorato664644d2011-01-23 17:53:23 -08003922 }
3923
Dianne Hackborn0ecadf72009-03-31 18:00:37 -07003924 /** {@inheritDoc} */
Jeff Brown46b9ac02010-04-22 18:58:52 -07003925 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
3926 // lid changed state
Jeff Brownc458ce92012-04-30 14:58:40 -07003927 final int newLidState = lidOpen ? LID_OPEN : LID_CLOSED;
3928 if (newLidState == mLidState) {
3929 return;
3930 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07003931
Jeff Brownc458ce92012-04-30 14:58:40 -07003932 mLidState = newLidState;
3933 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07003934 updateRotation(true);
Jeff Brownc458ce92012-04-30 14:58:40 -07003935
3936 if (lidOpen) {
Jim Millere51cf7ae2013-06-25 18:31:56 -07003937 mPowerManager.wakeUp(SystemClock.uptimeMillis());
Jeff Brownc458ce92012-04-30 14:58:40 -07003938 } else if (!mLidControlsSleep) {
Jeff Brown96307042012-07-27 15:51:34 -07003939 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
Jeff Brown46b9ac02010-04-22 18:58:52 -07003940 }
3941 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003942
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08003943 void setHdmiPlugged(boolean plugged) {
3944 if (mHdmiPlugged != plugged) {
3945 mHdmiPlugged = plugged;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003946 updateRotation(true, true);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08003947 Intent intent = new Intent(ACTION_HDMI_PLUGGED);
Joe Onoratodc100302011-01-11 17:07:41 -08003948 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08003949 intent.putExtra(EXTRA_HDMI_PLUGGED_STATE, plugged);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07003950 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08003951 }
3952 }
3953
Joe Onoratoea495d42011-04-06 11:41:11 -07003954 void initializeHdmiState() {
Joe Onorato7ba631f2011-05-04 15:28:00 -07003955 boolean plugged = false;
Joe Onoratoea495d42011-04-06 11:41:11 -07003956 // watch for HDMI plug messages if the hdmi switch exists
3957 if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) {
3958 mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi");
3959
Joe Onoratoea495d42011-04-06 11:41:11 -07003960 final String filename = "/sys/class/switch/hdmi/state";
3961 FileReader reader = null;
3962 try {
3963 reader = new FileReader(filename);
3964 char[] buf = new char[15];
3965 int n = reader.read(buf);
3966 if (n > 1) {
3967 plugged = 0 != Integer.parseInt(new String(buf, 0, n-1));
3968 }
3969 } catch (IOException ex) {
3970 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
3971 } catch (NumberFormatException ex) {
3972 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
3973 } finally {
3974 if (reader != null) {
3975 try {
3976 reader.close();
3977 } catch (IOException ex) {
3978 }
Joe Onoratodc100302011-01-11 17:07:41 -08003979 }
3980 }
3981 }
Joe Onorato7ba631f2011-05-04 15:28:00 -07003982 // This dance forces the code in setHdmiPlugged to run.
3983 // Always do this so the sticky intent is stuck (to false) if there is no hdmi.
3984 mHdmiPlugged = !plugged;
3985 setHdmiPlugged(!mHdmiPlugged);
Joe Onoratodc100302011-01-11 17:07:41 -08003986 }
3987
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003988 /**
Jean-Michel Trivifca1e602013-10-10 18:12:59 -07003989 * @return Whether music is being played right now "locally" (e.g. on the device's speakers
3990 * or wired headphones) or "remotely" (e.g. on a device using the Cast protocol and
3991 * controlled by this device, or through remote submix).
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003992 */
3993 boolean isMusicActive() {
RoboErik430fc482014-06-12 15:49:20 -07003994
Eric Laurent413cb9d2009-07-17 11:52:43 -07003995 final AudioManager am = (AudioManager)mContext.getSystemService(Context.AUDIO_SERVICE);
3996 if (am == null) {
3997 Log.w(TAG, "isMusicActive: couldn't get AudioManager reference");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003998 return false;
3999 }
Jean-Michel Trivifca1e602013-10-10 18:12:59 -07004000 return am.isLocalOrRemoteMusicActive();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004001 }
4002
Dianne Hackbornc0e3f242011-08-19 14:19:10 -07004003 final Object mScreenshotLock = new Object();
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004004 ServiceConnection mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004005
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004006 final Runnable mScreenshotTimeout = new Runnable() {
4007 @Override public void run() {
4008 synchronized (mScreenshotLock) {
4009 if (mScreenshotConnection != null) {
4010 mContext.unbindService(mScreenshotConnection);
4011 mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004012 }
Winson Chung9112ec32011-06-27 13:15:32 -07004013 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004014 }
4015 };
4016
4017 // Assume this is called from the Handler thread.
4018 private void takeScreenshot() {
4019 synchronized (mScreenshotLock) {
4020 if (mScreenshotConnection != null) {
4021 return;
4022 }
4023 ComponentName cn = new ComponentName("com.android.systemui",
4024 "com.android.systemui.screenshot.TakeScreenshotService");
4025 Intent intent = new Intent();
4026 intent.setComponent(cn);
4027 ServiceConnection conn = new ServiceConnection() {
4028 @Override
4029 public void onServiceConnected(ComponentName name, IBinder service) {
4030 synchronized (mScreenshotLock) {
4031 if (mScreenshotConnection != this) {
4032 return;
4033 }
4034 Messenger messenger = new Messenger(service);
4035 Message msg = Message.obtain(null, 1);
4036 final ServiceConnection myConn = this;
4037 Handler h = new Handler(mHandler.getLooper()) {
4038 @Override
4039 public void handleMessage(Message msg) {
4040 synchronized (mScreenshotLock) {
4041 if (mScreenshotConnection == myConn) {
4042 mContext.unbindService(mScreenshotConnection);
4043 mScreenshotConnection = null;
4044 mHandler.removeCallbacks(mScreenshotTimeout);
4045 }
4046 }
4047 }
4048 };
4049 msg.replyTo = new Messenger(h);
Winson Chunga63bb842011-10-17 10:26:28 -07004050 msg.arg1 = msg.arg2 = 0;
4051 if (mStatusBar != null && mStatusBar.isVisibleLw())
4052 msg.arg1 = 1;
4053 if (mNavigationBar != null && mNavigationBar.isVisibleLw())
4054 msg.arg2 = 1;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004055 try {
4056 messenger.send(msg);
4057 } catch (RemoteException e) {
4058 }
4059 }
4060 }
4061 @Override
4062 public void onServiceDisconnected(ComponentName name) {}
4063 };
Amith Yamasani27b89e62013-01-16 12:30:11 -08004064 if (mContext.bindServiceAsUser(
4065 intent, conn, Context.BIND_AUTO_CREATE, UserHandle.CURRENT)) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004066 mScreenshotConnection = conn;
4067 mHandler.postDelayed(mScreenshotTimeout, 10000);
4068 }
4069 }
Winson Chung9112ec32011-06-27 13:15:32 -07004070 }
4071
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004072 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004073 @Override
Jeff Brown037c33e2014-04-09 00:31:55 -07004074 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) {
Jeff Brown96307042012-07-27 15:51:34 -07004075 if (!mSystemBooted) {
4076 // If we have not yet booted, don't let key events do anything.
4077 return 0;
4078 }
4079
Jeff Brown037c33e2014-04-09 00:31:55 -07004080 final boolean interactive = (policyFlags & FLAG_INTERACTIVE) != 0;
Jeff Brown1f245102010-11-18 20:53:46 -08004081 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
4082 final boolean canceled = event.isCanceled();
4083 final int keyCode = event.getKeyCode();
Jeff Browne20c9e02010-10-11 14:20:19 -07004084
Jeff Brown3122e442010-10-11 23:32:49 -07004085 final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0;
Jeff Brown3122e442010-10-11 23:32:49 -07004086
Mike Lockwoodc72b15f2009-11-28 20:58:22 -05004087 // If screen is off then we treat the case where the keyguard is open but hidden
4088 // the same as if it were open and in front.
4089 // This will prevent any keys other than the power button from waking the screen
4090 // when the keyguard is hidden by another activity.
Jim Miller5ecd8112013-01-09 18:50:26 -08004091 final boolean keyguardActive = (mKeyguardDelegate == null ? false :
Jeff Brown037c33e2014-04-09 00:31:55 -07004092 (interactive ?
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004093 mKeyguardDelegate.isShowingAndNotOccluded() :
Jim Miller5ecd8112013-01-09 18:50:26 -08004094 mKeyguardDelegate.isShowing()));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004095
Jeff Brown40013652012-05-16 21:22:36 -07004096 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004097 Log.d(TAG, "interceptKeyTq keycode=" + keyCode
Jeff Brown037c33e2014-04-09 00:31:55 -07004098 + " interactive=" + interactive + " keyguardActive=" + keyguardActive
Jeff Brown26875502014-01-30 21:47:47 -08004099 + " policyFlags=" + Integer.toHexString(policyFlags));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004100 }
4101
Jeff Brown037c33e2014-04-09 00:31:55 -07004102 // Basic policy based on interactive state.
Jeff Brown4d396052010-10-29 21:50:21 -07004103 int result;
Michael Wright337d9d22014-04-22 15:03:48 -07004104 boolean isWakeKey = (policyFlags & WindowManagerPolicy.FLAG_WAKE) != 0
4105 || event.isWakeKey();
Jeff Brown037c33e2014-04-09 00:31:55 -07004106 if (interactive || (isInjected && !isWakeKey)) {
Jeff Brown4d396052010-10-29 21:50:21 -07004107 // When the screen is on or if the key is injected pass the key to the application.
4108 result = ACTION_PASS_TO_USER;
4109 } else {
4110 // When the screen is off and the key is not injected, determine whether
4111 // to wake the device but don't pass the key to the application.
4112 result = 0;
Jeff Brown26875502014-01-30 21:47:47 -08004113 if (isWakeKey && (!down || !isWakeKeyWhenScreenOff(keyCode))) {
4114 isWakeKey = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004115 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004116 }
4117
Justin Kohd378ad72013-04-01 12:18:26 -07004118 // If the key would be handled globally, just return the result, don't worry about special
4119 // key processing.
4120 if (mGlobalKeyManager.shouldHandleGlobalKey(keyCode, event)) {
Michael Wright85b1af62014-06-04 14:51:58 -07004121 if (isWakeKey) {
4122 mPowerManager.wakeUp(event.getEventTime());
4123 }
Justin Kohd378ad72013-04-01 12:18:26 -07004124 return result;
4125 }
4126
Jeff Brownbae8e772014-06-12 19:59:45 -07004127 boolean useHapticFeedback = down
4128 && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0
4129 && event.getRepeatCount() == 0;
4130
Jeff Brown4d396052010-10-29 21:50:21 -07004131 // Handle special keys.
4132 switch (keyCode) {
4133 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jeff Brownb0418da2010-11-01 15:24:01 -07004134 case KeyEvent.KEYCODE_VOLUME_UP:
4135 case KeyEvent.KEYCODE_VOLUME_MUTE: {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004136 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
4137 if (down) {
Jeff Brown037c33e2014-04-09 00:31:55 -07004138 if (interactive && !mVolumeDownKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004139 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
4140 mVolumeDownKeyTriggered = true;
4141 mVolumeDownKeyTime = event.getDownTime();
4142 mVolumeDownKeyConsumedByScreenshotChord = false;
4143 cancelPendingPowerKeyAction();
4144 interceptScreenshotChord();
4145 }
4146 } else {
4147 mVolumeDownKeyTriggered = false;
4148 cancelPendingScreenshotChordAction();
4149 }
4150 } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
4151 if (down) {
Jeff Brown037c33e2014-04-09 00:31:55 -07004152 if (interactive && !mVolumeUpKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004153 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
4154 mVolumeUpKeyTriggered = true;
4155 cancelPendingPowerKeyAction();
4156 cancelPendingScreenshotChordAction();
4157 }
4158 } else {
4159 mVolumeUpKeyTriggered = false;
4160 cancelPendingScreenshotChordAction();
4161 }
4162 }
Jeff Brown4d396052010-10-29 21:50:21 -07004163 if (down) {
Santos Cordon9eb45932014-06-27 12:28:43 -07004164 TelecommManager telecommManager = getTelecommService();
4165 if (telecommManager != null) {
4166 if (telecommManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07004167 // If an incoming call is ringing, either VOLUME key means
4168 // "silence ringer". We handle these keys here, rather than
4169 // in the InCallScreen, to make sure we'll respond to them
4170 // even if the InCallScreen hasn't come to the foreground yet.
4171 // Look for the DOWN event here, to agree with the "fallback"
4172 // behavior in the InCallScreen.
4173 Log.i(TAG, "interceptKeyBeforeQueueing:"
4174 + " VOLUME key-down while ringing: Silence ringer!");
Jeff Brown4d396052010-10-29 21:50:21 -07004175
Santos Cordon6848f722014-05-21 15:22:12 -07004176 // Silence the ringer. (It's safe to call this
4177 // even if the ringer has already been silenced.)
Santos Cordon9eb45932014-06-27 12:28:43 -07004178 telecommManager.silenceRinger();
Jeff Brown4d396052010-10-29 21:50:21 -07004179
Santos Cordon6848f722014-05-21 15:22:12 -07004180 // And *don't* pass this key thru to the current activity
4181 // (which is probably the InCallScreen.)
4182 result &= ~ACTION_PASS_TO_USER;
4183 break;
4184 }
Santos Cordon9eb45932014-06-27 12:28:43 -07004185 if (telecommManager.isInAPhoneCall()
Santos Cordon6848f722014-05-21 15:22:12 -07004186 && (result & ACTION_PASS_TO_USER) == 0) {
4187 // If we are in call but we decided not to pass the key to
RoboErik430fc482014-06-12 15:49:20 -07004188 // the application, just pass it to the session service.
4189
4190 MediaSessionLegacyHelper.getHelper(mContext)
4191 .sendMediaButtonEvent(event, true);
Santos Cordon6848f722014-05-21 15:22:12 -07004192 break;
Jeff Brown4d396052010-10-29 21:50:21 -07004193 }
4194 }
4195
RoboErik430fc482014-06-12 15:49:20 -07004196 if ((result & ACTION_PASS_TO_USER) == 0) {
4197 // If we aren't passing to the user and no one else
4198 // handled it send it to the session manager to figure
4199 // out.
4200 MediaSessionLegacyHelper.getHelper(mContext)
4201 .sendMediaButtonEvent(event, true);
Jeff Brown4d396052010-10-29 21:50:21 -07004202 break;
4203 }
4204 }
4205 break;
4206 }
4207
4208 case KeyEvent.KEYCODE_ENDCALL: {
4209 result &= ~ACTION_PASS_TO_USER;
4210 if (down) {
Santos Cordon9eb45932014-06-27 12:28:43 -07004211 TelecommManager telecommManager = getTelecommService();
Jeff Brown4d396052010-10-29 21:50:21 -07004212 boolean hungUp = false;
Santos Cordon9eb45932014-06-27 12:28:43 -07004213 if (telecommManager != null) {
4214 hungUp = telecommManager.endCall();
Jeff Brown4d396052010-10-29 21:50:21 -07004215 }
Jeff Brown037c33e2014-04-09 00:31:55 -07004216 interceptPowerKeyDown(!interactive || hungUp);
Jeff Brown4d396052010-10-29 21:50:21 -07004217 } else {
4218 if (interceptPowerKeyUp(canceled)) {
4219 if ((mEndcallBehavior
4220 & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) {
4221 if (goHome()) {
4222 break;
Dianne Hackborn0041e972009-07-24 17:14:43 -07004223 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004224 }
Jeff Brown4d396052010-10-29 21:50:21 -07004225 if ((mEndcallBehavior
4226 & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) {
Jeff Brown26875502014-01-30 21:47:47 -08004227 mPowerManager.goToSleep(event.getEventTime());
4228 isWakeKey = false;
Jeff Brown4d396052010-10-29 21:50:21 -07004229 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004230 }
Jeff Brown4d396052010-10-29 21:50:21 -07004231 }
4232 break;
4233 }
4234
4235 case KeyEvent.KEYCODE_POWER: {
4236 result &= ~ACTION_PASS_TO_USER;
4237 if (down) {
Jeff Brown26c6a502014-04-11 02:15:54 -07004238 boolean panic = mImmersiveModeConfirmation.onPowerKeyDown(interactive,
John Spurlockd9b70bd2014-02-06 17:02:44 -05004239 event.getDownTime(), isImmersiveMode(mLastSystemUiFlags));
4240 if (panic) {
4241 mHandler.post(mRequestTransientNav);
4242 }
Jeff Brown037c33e2014-04-09 00:31:55 -07004243 if (interactive && !mPowerKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004244 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
4245 mPowerKeyTriggered = true;
4246 mPowerKeyTime = event.getDownTime();
4247 interceptScreenshotChord();
Winson Chung9112ec32011-06-27 13:15:32 -07004248 }
Winson Chung9112ec32011-06-27 13:15:32 -07004249
Santos Cordon9eb45932014-06-27 12:28:43 -07004250 TelecommManager telecommManager = getTelecommService();
Jeff Brown4d396052010-10-29 21:50:21 -07004251 boolean hungUp = false;
Santos Cordon9eb45932014-06-27 12:28:43 -07004252 if (telecommManager != null) {
4253 if (telecommManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07004254 // Pressing Power while there's a ringing incoming
4255 // call should silence the ringer.
Santos Cordon9eb45932014-06-27 12:28:43 -07004256 telecommManager.silenceRinger();
Santos Cordon6848f722014-05-21 15:22:12 -07004257 } else if ((mIncallPowerBehavior
4258 & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0
Santos Cordon9eb45932014-06-27 12:28:43 -07004259 && telecommManager.isInAPhoneCall() && interactive) {
Santos Cordon6848f722014-05-21 15:22:12 -07004260 // Otherwise, if "Power button ends call" is enabled,
4261 // the Power button will hang up any current active call.
Santos Cordon9eb45932014-06-27 12:28:43 -07004262 hungUp = telecommManager.endCall();
Jeff Brown4d396052010-10-29 21:50:21 -07004263 }
4264 }
Jeff Brown037c33e2014-04-09 00:31:55 -07004265 interceptPowerKeyDown(!interactive || hungUp
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004266 || mVolumeDownKeyTriggered || mVolumeUpKeyTriggered);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004267 } else {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004268 mPowerKeyTriggered = false;
4269 cancelPendingScreenshotChordAction();
4270 if (interceptPowerKeyUp(canceled || mPendingPowerKeyUpCanceled)) {
Jeff Brown6d8fd272014-05-20 21:24:38 -07004271 powerShortPress(event.getEventTime());
Jeff Brown26875502014-01-30 21:47:47 -08004272 isWakeKey = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004273 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004274 mPendingPowerKeyUpCanceled = false;
Jeff Brown4d396052010-10-29 21:50:21 -07004275 }
4276 break;
4277 }
4278
Jeff Brown6212a492014-03-07 13:58:47 -08004279 case KeyEvent.KEYCODE_SLEEP: {
4280 result &= ~ACTION_PASS_TO_USER;
Jeff Brownbae8e772014-06-12 19:59:45 -07004281 if (!mPowerManager.isInteractive()) {
4282 useHapticFeedback = false; // suppress feedback if already non-interactive
4283 }
Jeff Brown6212a492014-03-07 13:58:47 -08004284 mPowerManager.goToSleep(event.getEventTime());
4285 isWakeKey = false;
4286 break;
4287 }
4288
4289 case KeyEvent.KEYCODE_WAKEUP: {
4290 result &= ~ACTION_PASS_TO_USER;
4291 break;
4292 }
4293
Jeff Brown4d396052010-10-29 21:50:21 -07004294 case KeyEvent.KEYCODE_MEDIA_PLAY:
4295 case KeyEvent.KEYCODE_MEDIA_PAUSE:
4296 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
4297 if (down) {
Santos Cordon9eb45932014-06-27 12:28:43 -07004298 TelecommManager telecommManager = getTelecommService();
4299 if (telecommManager != null) {
4300 if (telecommManager.isInAPhoneCall()) {
Santos Cordon6848f722014-05-21 15:22:12 -07004301 // Suppress PLAY/PAUSE toggle when phone is ringing or in-call
4302 // to avoid music playback.
4303 break;
Jeff Brown3122e442010-10-11 23:32:49 -07004304 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004305 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004306 }
Jeff Brown4d396052010-10-29 21:50:21 -07004307 case KeyEvent.KEYCODE_HEADSETHOOK:
4308 case KeyEvent.KEYCODE_MUTE:
4309 case KeyEvent.KEYCODE_MEDIA_STOP:
4310 case KeyEvent.KEYCODE_MEDIA_NEXT:
4311 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
4312 case KeyEvent.KEYCODE_MEDIA_REWIND:
4313 case KeyEvent.KEYCODE_MEDIA_RECORD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09004314 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
4315 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: {
Jeff Brown4d396052010-10-29 21:50:21 -07004316 if ((result & ACTION_PASS_TO_USER) == 0) {
4317 // Only do this if we would otherwise not pass it to the user. In that
4318 // case, the PhoneWindow class will do the same thing, except it will
4319 // only do it if the showing app doesn't process the key on its own.
Jeff Brown40013652012-05-16 21:22:36 -07004320 // Note that we need to make a copy of the key event here because the
4321 // original key event will be recycled when we return.
Jeff Brown4d396052010-10-29 21:50:21 -07004322 mBroadcastWakeLock.acquire();
Jeff Brown40013652012-05-16 21:22:36 -07004323 Message msg = mHandler.obtainMessage(MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK,
4324 new KeyEvent(event));
4325 msg.setAsynchronous(true);
4326 msg.sendToTarget();
Jeff Brown4d396052010-10-29 21:50:21 -07004327 }
4328 break;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004329 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004330
Jeff Brown4d396052010-10-29 21:50:21 -07004331 case KeyEvent.KEYCODE_CALL: {
4332 if (down) {
Santos Cordon9eb45932014-06-27 12:28:43 -07004333 TelecommManager telecommManager = getTelecommService();
4334 if (telecommManager != null) {
4335 if (telecommManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07004336 Log.i(TAG, "interceptKeyBeforeQueueing:"
4337 + " CALL key-down while ringing: Answer the call!");
Santos Cordon9eb45932014-06-27 12:28:43 -07004338 telecommManager.acceptRingingCall();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004339
Santos Cordon6848f722014-05-21 15:22:12 -07004340 // And *don't* pass this key thru to the current activity
4341 // (which is presumably the InCallScreen.)
4342 result &= ~ACTION_PASS_TO_USER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004343 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004344 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004345 }
Jeff Brown4d396052010-10-29 21:50:21 -07004346 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004347 }
4348 }
Jeff Brown26875502014-01-30 21:47:47 -08004349
Jeff Brownbae8e772014-06-12 19:59:45 -07004350 if (useHapticFeedback) {
4351 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
4352 }
4353
Jeff Brown26875502014-01-30 21:47:47 -08004354 if (isWakeKey) {
4355 mPowerManager.wakeUp(event.getEventTime());
4356 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004357 return result;
4358 }
4359
Jeff Brown1c2e4942012-11-06 16:32:01 -08004360 /**
4361 * When the screen is off we ignore some keys that might otherwise typically
4362 * be considered wake keys. We filter them out here.
4363 *
4364 * {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it
4365 * is always considered a wake key.
4366 */
4367 private boolean isWakeKeyWhenScreenOff(int keyCode) {
4368 switch (keyCode) {
4369 // ignore volume keys unless docked
4370 case KeyEvent.KEYCODE_VOLUME_UP:
4371 case KeyEvent.KEYCODE_VOLUME_DOWN:
4372 case KeyEvent.KEYCODE_VOLUME_MUTE:
4373 return mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED;
4374
4375 // ignore media and camera keys
4376 case KeyEvent.KEYCODE_MUTE:
4377 case KeyEvent.KEYCODE_HEADSETHOOK:
4378 case KeyEvent.KEYCODE_MEDIA_PLAY:
4379 case KeyEvent.KEYCODE_MEDIA_PAUSE:
4380 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
4381 case KeyEvent.KEYCODE_MEDIA_STOP:
4382 case KeyEvent.KEYCODE_MEDIA_NEXT:
4383 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
4384 case KeyEvent.KEYCODE_MEDIA_REWIND:
4385 case KeyEvent.KEYCODE_MEDIA_RECORD:
4386 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09004387 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK:
Jeff Brown1c2e4942012-11-06 16:32:01 -08004388 case KeyEvent.KEYCODE_CAMERA:
4389 return false;
4390 }
4391 return true;
4392 }
4393
4394
Jeff Brown56194eb2011-03-02 19:23:13 -08004395 /** {@inheritDoc} */
4396 @Override
Jeff Brown037c33e2014-04-09 00:31:55 -07004397 public int interceptWakeMotionBeforeQueueing(long whenNanos, int policyFlags) {
4398 // We already know this is a wake motion so just wake up.
4399 // Note that we would observe policyFlags containing
4400 // FLAG_WAKE and FLAG_INTERACTIVE here.
4401 mPowerManager.wakeUp(whenNanos / 1000000);
4402 return 0;
Jeff Brown56194eb2011-03-02 19:23:13 -08004403 }
4404
Jeff Brown40013652012-05-16 21:22:36 -07004405 void dispatchMediaKeyWithWakeLock(KeyEvent event) {
4406 if (DEBUG_INPUT) {
4407 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: " + event);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004408 }
4409
Jeff Brown40013652012-05-16 21:22:36 -07004410 if (mHavePendingMediaKeyRepeatWithWakeLock) {
4411 if (DEBUG_INPUT) {
4412 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: canceled repeat");
4413 }
4414
4415 mHandler.removeMessages(MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK);
4416 mHavePendingMediaKeyRepeatWithWakeLock = false;
4417 mBroadcastWakeLock.release(); // pending repeat was holding onto the wake lock
4418 }
4419
4420 dispatchMediaKeyWithWakeLockToAudioService(event);
4421
4422 if (event.getAction() == KeyEvent.ACTION_DOWN
4423 && event.getRepeatCount() == 0) {
4424 mHavePendingMediaKeyRepeatWithWakeLock = true;
4425
4426 Message msg = mHandler.obtainMessage(
4427 MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK, event);
4428 msg.setAsynchronous(true);
4429 mHandler.sendMessageDelayed(msg, ViewConfiguration.getKeyRepeatTimeout());
4430 } else {
4431 mBroadcastWakeLock.release();
4432 }
4433 }
4434
4435 void dispatchMediaKeyRepeatWithWakeLock(KeyEvent event) {
4436 mHavePendingMediaKeyRepeatWithWakeLock = false;
4437
4438 KeyEvent repeatEvent = KeyEvent.changeTimeRepeat(event,
4439 SystemClock.uptimeMillis(), 1, event.getFlags() | KeyEvent.FLAG_LONG_PRESS);
4440 if (DEBUG_INPUT) {
4441 Slog.d(TAG, "dispatchMediaKeyRepeatWithWakeLock: " + repeatEvent);
4442 }
4443
4444 dispatchMediaKeyWithWakeLockToAudioService(repeatEvent);
4445 mBroadcastWakeLock.release();
4446 }
4447
4448 void dispatchMediaKeyWithWakeLockToAudioService(KeyEvent event) {
4449 if (ActivityManagerNative.isSystemReady()) {
RoboErik430fc482014-06-12 15:49:20 -07004450 MediaSessionLegacyHelper.getHelper(mContext).sendMediaButtonEvent(event, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004451 }
4452 }
4453
Mike Lockwood1753f7f2009-08-24 14:49:07 -07004454 BroadcastReceiver mDockReceiver = new BroadcastReceiver() {
Craig Mautnereee29c42013-01-17 14:44:34 -08004455 @Override
Mike Lockwood1753f7f2009-08-24 14:49:07 -07004456 public void onReceive(Context context, Intent intent) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07004457 if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) {
4458 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
4459 Intent.EXTRA_DOCK_STATE_UNDOCKED);
Daniel Sandler6396c722013-04-16 20:19:09 -04004460 } else {
4461 try {
4462 IUiModeManager uiModeService = IUiModeManager.Stub.asInterface(
4463 ServiceManager.getService(Context.UI_MODE_SERVICE));
4464 mUiMode = uiModeService.getCurrentModeType();
4465 } catch (RemoteException e) {
4466 }
Dianne Hackborn80fa1662009-10-07 14:02:10 -07004467 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004468 updateRotation(true);
Craig Mautnereee29c42013-01-17 14:44:34 -08004469 synchronized (mLock) {
4470 updateOrientationListenerLp();
4471 }
Mike Lockwood1753f7f2009-08-24 14:49:07 -07004472 }
4473 };
4474
Jeff Brown6aaf2952012-10-05 16:01:08 -07004475 BroadcastReceiver mDreamReceiver = new BroadcastReceiver() {
4476 @Override
4477 public void onReceive(Context context, Intent intent) {
4478 if (Intent.ACTION_DREAMING_STARTED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004479 if (mKeyguardDelegate != null) {
4480 mKeyguardDelegate.onDreamingStarted();
Jeff Brown6aaf2952012-10-05 16:01:08 -07004481 }
4482 } else if (Intent.ACTION_DREAMING_STOPPED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004483 if (mKeyguardDelegate != null) {
4484 mKeyguardDelegate.onDreamingStopped();
Jeff Brown6aaf2952012-10-05 16:01:08 -07004485 }
4486 }
4487 }
4488 };
4489
Christopher Tate5e08af02012-09-21 17:17:22 -07004490 BroadcastReceiver mMultiuserReceiver = new BroadcastReceiver() {
4491 @Override
4492 public void onReceive(Context context, Intent intent) {
4493 if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) {
4494 // tickle the settings observer: this first ensures that we're
4495 // observing the relevant settings for the newly-active user,
4496 // and then updates our own bookkeeping based on the now-
4497 // current user.
4498 mSettingsObserver.onChange(false);
John Spurlockce479d82012-11-29 09:52:21 -05004499
4500 // force a re-application of focused window sysui visibility.
4501 // the window may never have been shown for this user
4502 // e.g. the keyguard when going through the new-user setup flow
John Spurlock04db1762013-05-13 12:46:41 -04004503 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
John Spurlockce479d82012-11-29 09:52:21 -05004504 mLastSystemUiFlags = 0;
4505 updateSystemUiVisibilityLw();
4506 }
Christopher Tate5e08af02012-09-21 17:17:22 -07004507 }
4508 }
4509 };
4510
John Spurlockd9b70bd2014-02-06 17:02:44 -05004511 private final Runnable mRequestTransientNav = new Runnable() {
4512 @Override
4513 public void run() {
4514 requestTransientBars(mNavigationBar);
4515 }
4516 };
4517
John Spurlocke1f366f2013-08-05 12:22:40 -04004518 private void requestTransientBars(WindowState swipeTarget) {
John Spurlock04db1762013-05-13 12:46:41 -04004519 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Maurice Lam99c6e072014-04-28 18:24:28 -07004520 if (!isUserSetupComplete()) {
4521 // Swipe-up for navigation bar is disabled during setup
4522 return;
4523 }
John Spurlock27735a42013-08-14 17:57:38 -04004524 boolean sb = mStatusBarController.checkShowTransientBarLw();
4525 boolean nb = mNavigationBarController.checkShowTransientBarLw();
John Spurlockad3e6cb2013-04-30 08:47:43 -04004526 if (sb || nb) {
John Spurlocke1f366f2013-08-05 12:22:40 -04004527 WindowState barTarget = sb ? mStatusBar : mNavigationBar;
4528 if (sb ^ nb && barTarget != swipeTarget) {
4529 if (DEBUG) Slog.d(TAG, "Not showing transient bar, wrong swipe target");
John Spurlockad3e6cb2013-04-30 08:47:43 -04004530 return;
4531 }
John Spurlock27735a42013-08-14 17:57:38 -04004532 if (sb) mStatusBarController.showTransient();
4533 if (nb) mNavigationBarController.showTransient();
John Spurlockf1a36642013-10-12 17:50:42 -04004534 mImmersiveModeConfirmation.confirmCurrentPrompt();
John Spurlockad3e6cb2013-04-30 08:47:43 -04004535 updateSystemUiVisibilityLw();
John Spurlock32beb2c2013-03-11 10:16:47 -04004536 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04004537 }
4538 }
4539
Jeff Brownc38c9be2012-10-04 13:16:19 -07004540 @Override
Jeff Brown140ffc72014-05-01 15:18:00 -07004541 public void goingToSleep(int why) {
Dianne Hackborn74489012009-03-24 20:50:09 -07004542 EventLog.writeEvent(70000, 0);
The Android Open Source Project0727d222009-03-11 12:11:58 -07004543 synchronized (mLock) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004544 mScreenOnEarly = false;
4545 mScreenOnFully = false;
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07004546 }
Jim Miller5ecd8112013-01-09 18:50:26 -08004547 if (mKeyguardDelegate != null) {
4548 mKeyguardDelegate.onScreenTurnedOff(why);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004549 }
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07004550 synchronized (mLock) {
Jeff Browna20dda42014-05-27 20:57:24 -07004551 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07004552 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05004553 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07004554 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004555 }
4556
Jeff Brownc38c9be2012-10-04 13:16:19 -07004557 @Override
Jeff Brown140ffc72014-05-01 15:18:00 -07004558 public void wakingUp(final ScreenOnListener screenOnListener) {
Dianne Hackborn74489012009-03-24 20:50:09 -07004559 EventLog.writeEvent(70000, 1);
Craig Mautner8a0da012014-05-31 15:13:37 -07004560 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turning on...",
4561 new RuntimeException("here").fillInStackTrace());
4562 mHandler.obtainMessage(MSG_WAKING_UP, screenOnListener).sendToTarget();
4563 }
4564
4565 // Called on the mHandler thread.
4566 private void handleWakingUp(final ScreenOnListener screenOnListener) {
4567 if (screenOnListener != null) {
Craig Mautner13f6ea72014-06-23 14:57:02 -07004568 mScreenOnListener = screenOnListener;
Dianne Hackborn40011092011-09-22 13:37:48 -07004569 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07004570
The Android Open Source Project0727d222009-03-11 12:11:58 -07004571 synchronized (mLock) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004572 mScreenOnEarly = true;
Jeff Browna20dda42014-05-27 20:57:24 -07004573 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07004574 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05004575 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07004576 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07004577
Craig Mautner8a0da012014-05-31 15:13:37 -07004578 mKeyguardDrawComplete = false;
4579 mWindowManagerDrawComplete = false;
Jim Miller5ecd8112013-01-09 18:50:26 -08004580 if (mKeyguardDelegate != null) {
Craig Mautner8a0da012014-05-31 15:13:37 -07004581 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
4582 mHandler.sendEmptyMessageDelayed(MSG_KEYGUARD_DRAWN_TIMEOUT, 1000);
4583 mKeyguardDelegate.onScreenTurnedOn(mKeyguardDelegateCallback);
Jeff Brownc38c9be2012-10-04 13:16:19 -07004584 } else {
Craig Mautner8a0da012014-05-31 15:13:37 -07004585 if (DEBUG_WAKEUP) Slog.d(TAG, "null mKeyguardDelegate: setting mKeyguardDrawComplete.");
4586 mKeyguardDrawComplete = true;
Jeff Brownc38c9be2012-10-04 13:16:19 -07004587 }
Craig Mautner8a0da012014-05-31 15:13:37 -07004588 mWindowManagerInternal.waitForAllWindowsDrawn(mWindowManagerDrawCallback, 500);
Jeff Brownc38c9be2012-10-04 13:16:19 -07004589 }
4590
Craig Mautner8a0da012014-05-31 15:13:37 -07004591 // Called on the mHandler thread.
4592 private void finishScreenTurningOn() {
4593 if (DEBUG_WAKEUP) Slog.d(TAG,
4594 "finishScreenTurningOn: mKeyguardDrawComplete=" + mKeyguardDrawComplete
4595 + " mWindowManagerDrawComplete=" + mWindowManagerDrawComplete);
4596 if (!mKeyguardDrawComplete || !mWindowManagerDrawComplete) {
4597 return;
Jeff Brownc38c9be2012-10-04 13:16:19 -07004598 }
4599
Craig Mautner13f6ea72014-06-23 14:57:02 -07004600 ScreenOnListener screenOnListener;
Jeff Brownc38c9be2012-10-04 13:16:19 -07004601 synchronized (mLock) {
4602 mScreenOnFully = true;
Craig Mautner13f6ea72014-06-23 14:57:02 -07004603 screenOnListener = mScreenOnListener;
4604 mScreenOnListener = null;
Jeff Brownc38c9be2012-10-04 13:16:19 -07004605 }
4606
Jeff Brown4fc45272012-10-10 18:28:14 -07004607 try {
4608 mWindowManager.setEventDispatching(true);
4609 } catch (RemoteException unhandled) {
4610 }
4611
Craig Mautner13f6ea72014-06-23 14:57:02 -07004612 if (screenOnListener != null) {
4613 screenOnListener.onScreenOn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07004614 }
Craig Mautner8a0da012014-05-31 15:13:37 -07004615
4616 setKeyguardDrawn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07004617 }
4618
4619 @Override
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004620 public boolean isScreenOnEarly() {
4621 return mScreenOnEarly;
4622 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07004623
4624 @Override
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004625 public boolean isScreenOnFully() {
4626 return mScreenOnFully;
Dianne Hackborn08743722009-12-21 12:16:51 -08004627 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07004628
Dianne Hackborn08743722009-12-21 12:16:51 -08004629 /** {@inheritDoc} */
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004630 public void enableKeyguard(boolean enabled) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004631 if (mKeyguardDelegate != null) {
4632 mKeyguardDelegate.setKeyguardEnabled(enabled);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004633 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004634 }
4635
4636 /** {@inheritDoc} */
4637 public void exitKeyguardSecurely(OnKeyguardExitResult callback) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004638 if (mKeyguardDelegate != null) {
4639 mKeyguardDelegate.verifyUnlock(callback);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004640 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004641 }
4642
Mike Lockwoodf7913302009-11-28 22:27:10 -05004643 private boolean keyguardIsShowingTq() {
Jim Miller5ecd8112013-01-09 18:50:26 -08004644 if (mKeyguardDelegate == null) return false;
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004645 return mKeyguardDelegate.isShowingAndNotOccluded();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004646 }
4647
Mike Lockwood520d8bc2011-02-18 13:23:13 -05004648
4649 /** {@inheritDoc} */
4650 public boolean isKeyguardLocked() {
4651 return keyguardOn();
4652 }
4653
4654 /** {@inheritDoc} */
4655 public boolean isKeyguardSecure() {
Jim Miller5ecd8112013-01-09 18:50:26 -08004656 if (mKeyguardDelegate == null) return false;
4657 return mKeyguardDelegate.isSecure();
Mike Lockwood520d8bc2011-02-18 13:23:13 -05004658 }
4659
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004660 // Returns true if keyguard is currently locked whether or not it is currently hidden.
4661 private boolean isKeyguardSecureIncludingHidden() {
4662 return mKeyguardDelegate.isSecure() && mKeyguardDelegate.isShowing();
4663 }
4664
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004665 /** {@inheritDoc} */
4666 public boolean inKeyguardRestrictedKeyInputMode() {
Jim Miller5ecd8112013-01-09 18:50:26 -08004667 if (mKeyguardDelegate == null) return false;
4668 return mKeyguardDelegate.isInputRestricted();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004669 }
4670
Dianne Hackborn90c52de2011-09-23 12:57:44 -07004671 public void dismissKeyguardLw() {
RoboErik8a2cfc32014-05-16 11:19:38 -07004672 if (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()) {
Daniel Sandler1ce804392012-11-07 15:07:12 -05004673 mHandler.post(new Runnable() {
4674 public void run() {
Jim Miller5ecd8112013-01-09 18:50:26 -08004675 if (mKeyguardDelegate.isDismissable()) {
Daniel Sandler1ce804392012-11-07 15:07:12 -05004676 // Can we just finish the keyguard straight away?
Jim Miller5ecd8112013-01-09 18:50:26 -08004677 mKeyguardDelegate.keyguardDone(false, true);
Daniel Sandler1ce804392012-11-07 15:07:12 -05004678 } else {
4679 // ask the keyguard to prompt the user to authenticate if necessary
Jim Miller5ecd8112013-01-09 18:50:26 -08004680 mKeyguardDelegate.dismiss();
Dianne Hackborn90c52de2011-09-23 12:57:44 -07004681 }
Daniel Sandler1ce804392012-11-07 15:07:12 -05004682 }
4683 });
Dianne Hackborn90c52de2011-09-23 12:57:44 -07004684 }
4685 }
4686
Jorim Jaggicff0acb2014-03-31 16:35:15 +02004687 private void setKeyguardDrawn() {
4688 synchronized (mLock) {
4689 mKeyguardDrawn = true;
4690 }
4691 try {
4692 mWindowManager.enableScreenIfNeeded();
4693 } catch (RemoteException unhandled) {
4694 }
4695 }
4696
4697 @Override
4698 public boolean isKeyguardDrawnLw() {
4699 synchronized (mLock) {
4700 return mKeyguardDrawn;
4701 }
4702 }
4703
Jorim Jaggi0d674622014-05-21 01:34:15 +02004704 @Override
Jorim Jaggie29b2db2014-05-30 23:17:03 +02004705 public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) {
Jorim Jaggi0d674622014-05-21 01:34:15 +02004706 if (mKeyguardDelegate != null) {
Jorim Jaggie29b2db2014-05-30 23:17:03 +02004707 mKeyguardDelegate.startKeyguardExitAnimation(startTime, fadeoutDuration);
Jorim Jaggi0d674622014-05-21 01:34:15 +02004708 }
4709 }
4710
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004711 void sendCloseSystemWindows() {
4712 sendCloseSystemWindows(mContext, null);
4713 }
4714
4715 void sendCloseSystemWindows(String reason) {
4716 sendCloseSystemWindows(mContext, reason);
4717 }
4718
4719 static void sendCloseSystemWindows(Context context, String reason) {
4720 if (ActivityManagerNative.isSystemReady()) {
Dianne Hackborn94a679d2009-07-28 17:51:07 -07004721 try {
4722 ActivityManagerNative.getDefault().closeSystemDialogs(reason);
4723 } catch (RemoteException e) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004724 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004725 }
4726 }
Mitsuru Oshima831d0d92009-06-16 18:27:18 -07004727
Jeff Brown01a98dd2011-09-20 15:08:29 -07004728 @Override
4729 public int rotationForOrientationLw(int orientation, int lastRotation) {
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05004730 if (false) {
4731 Slog.v(TAG, "rotationForOrientationLw(orient="
4732 + orientation + ", last=" + lastRotation
4733 + "); user=" + mUserRotation + " "
4734 + ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED)
4735 ? "USER_ROTATION_LOCKED" : "")
4736 );
4737 }
4738
Craig Mautner46ac6fa2013-08-01 10:06:34 -07004739 if (mForceDefaultOrientation) {
4740 return Surface.ROTATION_0;
4741 }
4742
The Android Open Source Project0727d222009-03-11 12:11:58 -07004743 synchronized (mLock) {
Jeff Brownc0347aa2011-09-23 17:26:09 -07004744 int sensorRotation = mOrientationListener.getProposedRotation(); // may be -1
4745 if (sensorRotation < 0) {
Jeff Brown0f862b42012-09-27 21:11:01 -07004746 sensorRotation = lastRotation;
Jeff Brownc0347aa2011-09-23 17:26:09 -07004747 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004748
Jeff Browndec6cf42011-11-15 14:08:20 -08004749 final int preferredRotation;
Jeff Brown2e7760e2012-04-11 15:14:55 -07004750 if (mLidState == LID_OPEN && mLidOpenRotation >= 0) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07004751 // Ignore sensor when lid switch is open and rotation is forced.
4752 preferredRotation = mLidOpenRotation;
4753 } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR
Jeff Brownc0347aa2011-09-23 17:26:09 -07004754 && (mCarDockEnablesAccelerometer || mCarDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07004755 // Ignore sensor when in car dock unless explicitly enabled.
4756 // This case can override the behavior of NOSENSOR, and can also
4757 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07004758 preferredRotation = mCarDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07004759 ? sensorRotation : mCarDockRotation;
Jeff Brown1a693182011-11-08 14:44:16 -08004760 } else if ((mDockMode == Intent.EXTRA_DOCK_STATE_DESK
4761 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
4762 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK)
Jeff Brownc0347aa2011-09-23 17:26:09 -07004763 && (mDeskDockEnablesAccelerometer || mDeskDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07004764 // Ignore sensor when in desk dock unless explicitly enabled.
4765 // This case can override the behavior of NOSENSOR, and can also
4766 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07004767 preferredRotation = mDeskDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07004768 ? sensorRotation : mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -07004769 } else if (mHdmiPlugged && mDemoHdmiRotationLock) {
4770 // Ignore sensor when plugged into HDMI when demo HDMI rotation lock enabled.
Jeff Browneb3e4b92011-12-06 19:54:24 -08004771 // Note that the dock orientation overrides the HDMI orientation.
Jeff Brownc82c89ed2013-04-17 17:18:15 -07004772 preferredRotation = mDemoHdmiRotation;
4773 } else if (mHdmiPlugged && mDockMode == Intent.EXTRA_DOCK_STATE_UNDOCKED
4774 && mUndockedHdmiRotation >= 0) {
4775 // Ignore sensor when plugged into HDMI and an undocked orientation has
4776 // been specified in the configuration (only for legacy devices without
4777 // full multi-display support).
4778 // Note that the dock orientation overrides the HDMI orientation.
4779 preferredRotation = mUndockedHdmiRotation;
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07004780 } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED) {
4781 // Application just wants to remain locked in the last rotation.
4782 preferredRotation = lastRotation;
Jeff Brownbcdfc622014-03-06 19:13:04 -08004783 } else if (!mSupportAutoRotation) {
4784 // If we don't support auto-rotation then bail out here and ignore
4785 // the sensor and any rotation lock settings.
4786 preferredRotation = -1;
Jeff Brown207673cd2012-06-05 17:47:11 -07004787 } else if ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE
Jeff Brown01a98dd2011-09-20 15:08:29 -07004788 && (orientation == ActivityInfo.SCREEN_ORIENTATION_USER
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07004789 || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
4790 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
4791 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
4792 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER))
Jeff Brown01a98dd2011-09-20 15:08:29 -07004793 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
4794 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
4795 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
4796 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) {
4797 // Otherwise, use sensor only if requested by the application or enabled
4798 // by default for USER or UNSPECIFIED modes. Does not apply to NOSENSOR.
Jeff Brownd3187e32011-09-21 19:26:44 -07004799 if (mAllowAllRotations < 0) {
4800 // Can't read this during init() because the context doesn't
4801 // have display metrics at that time so we cannot determine
4802 // tablet vs. phone then.
4803 mAllowAllRotations = mContext.getResources().getBoolean(
4804 com.android.internal.R.bool.config_allowAllRotations) ? 1 : 0;
4805 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004806 if (sensorRotation != Surface.ROTATION_180
Jeff Brownd3187e32011-09-21 19:26:44 -07004807 || mAllowAllRotations == 1
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07004808 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
4809 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07004810 preferredRotation = sensorRotation;
4811 } else {
4812 preferredRotation = lastRotation;
4813 }
Jeff Brown207673cd2012-06-05 17:47:11 -07004814 } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED
4815 && orientation != ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) {
4816 // Apply rotation lock. Does not apply to NOSENSOR.
4817 // The idea is that the user rotation expresses a weak preference for the direction
4818 // of gravity and as NOSENSOR is never affected by gravity, then neither should
4819 // NOSENSOR be affected by rotation lock (although it will be affected by docks).
Jeff Brown4dfce202011-10-05 12:00:10 -07004820 preferredRotation = mUserRotation;
Jeff Browndec6cf42011-11-15 14:08:20 -08004821 } else {
4822 // No overriding preference.
4823 // We will do exactly what the application asked us to do.
4824 preferredRotation = -1;
Jeff Brown01a98dd2011-09-20 15:08:29 -07004825 }
4826
Dianne Hackborne5439f22010-10-02 16:53:50 -07004827 switch (orientation) {
4828 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08004829 // Return portrait unless overridden.
4830 if (isAnyPortrait(preferredRotation)) {
4831 return preferredRotation;
4832 }
Dianne Hackborne5439f22010-10-02 16:53:50 -07004833 return mPortraitRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07004834
Jeff Brown01a98dd2011-09-20 15:08:29 -07004835 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08004836 // Return landscape unless overridden.
4837 if (isLandscapeOrSeascape(preferredRotation)) {
4838 return preferredRotation;
4839 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004840 return mLandscapeRotation;
4841
4842 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08004843 // Return reverse portrait unless overridden.
4844 if (isAnyPortrait(preferredRotation)) {
4845 return preferredRotation;
4846 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004847 return mUpsideDownRotation;
4848
4849 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08004850 // Return seascape unless overridden.
4851 if (isLandscapeOrSeascape(preferredRotation)) {
4852 return preferredRotation;
4853 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004854 return mSeascapeRotation;
4855
4856 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07004857 case ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE:
Jeff Brown01a98dd2011-09-20 15:08:29 -07004858 // Return either landscape rotation.
4859 if (isLandscapeOrSeascape(preferredRotation)) {
4860 return preferredRotation;
4861 }
4862 if (isLandscapeOrSeascape(lastRotation)) {
Jeff Brown4519f072011-01-23 13:16:01 -08004863 return lastRotation;
4864 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004865 return mLandscapeRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004866
Jeff Brown01a98dd2011-09-20 15:08:29 -07004867 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07004868 case ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT:
Jeff Brown01a98dd2011-09-20 15:08:29 -07004869 // Return either portrait rotation.
4870 if (isAnyPortrait(preferredRotation)) {
4871 return preferredRotation;
4872 }
4873 if (isAnyPortrait(lastRotation)) {
4874 return lastRotation;
4875 }
4876 return mPortraitRotation;
4877
4878 default:
Jeff Brown4dfce202011-10-05 12:00:10 -07004879 // For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR,
4880 // just return the preferred orientation we already calculated.
Jeff Brown01a98dd2011-09-20 15:08:29 -07004881 if (preferredRotation >= 0) {
4882 return preferredRotation;
4883 }
Dianne Hackborndacea8c2011-04-21 17:26:39 -07004884 return Surface.ROTATION_0;
Daniel Sandlere7e5ac22011-02-22 16:10:21 -05004885 }
4886 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07004887 }
4888
Jeff Brown01a98dd2011-09-20 15:08:29 -07004889 @Override
4890 public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation) {
4891 switch (orientation) {
4892 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
4893 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
4894 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
4895 return isAnyPortrait(rotation);
4896
4897 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
4898 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
4899 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
4900 return isLandscapeOrSeascape(rotation);
4901
4902 default:
4903 return true;
4904 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07004905 }
4906
Jeff Brownc0347aa2011-09-23 17:26:09 -07004907 @Override
4908 public void setRotationLw(int rotation) {
4909 mOrientationListener.setCurrentRotation(rotation);
4910 }
4911
Jeff Brown01a98dd2011-09-20 15:08:29 -07004912 private boolean isLandscapeOrSeascape(int rotation) {
4913 return rotation == mLandscapeRotation || rotation == mSeascapeRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07004914 }
4915
Jeff Brown01a98dd2011-09-20 15:08:29 -07004916 private boolean isAnyPortrait(int rotation) {
4917 return rotation == mPortraitRotation || rotation == mUpsideDownRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07004918 }
4919
Svetoslav Ganov80943d82013-01-02 10:25:37 -08004920 public int getUserRotationMode() {
4921 return Settings.System.getIntForUser(mContext.getContentResolver(),
Brett Chabot7e55c402013-05-16 19:38:08 -07004922 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
4923 WindowManagerPolicy.USER_ROTATION_FREE :
4924 WindowManagerPolicy.USER_ROTATION_LOCKED;
Svetoslav Ganov80943d82013-01-02 10:25:37 -08004925 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004926
4927 // User rotation: to be used when all else fails in assigning an orientation to the device
4928 public void setUserRotationMode(int mode, int rot) {
4929 ContentResolver res = mContext.getContentResolver();
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05004930
4931 // mUserRotationMode and mUserRotation will be assigned by the content observer
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004932 if (mode == WindowManagerPolicy.USER_ROTATION_LOCKED) {
Christopher Tate5e08af02012-09-21 17:17:22 -07004933 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004934 Settings.System.USER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07004935 rot,
4936 UserHandle.USER_CURRENT);
4937 Settings.System.putIntForUser(res,
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05004938 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07004939 0,
4940 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004941 } else {
Christopher Tate5e08af02012-09-21 17:17:22 -07004942 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004943 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07004944 1,
4945 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004946 }
4947 }
4948
Jeff Brownac143512012-04-05 18:57:33 -07004949 public void setSafeMode(boolean safeMode) {
4950 mSafeMode = safeMode;
4951 performHapticFeedbackLw(null, safeMode
4952 ? HapticFeedbackConstants.SAFE_MODE_ENABLED
4953 : HapticFeedbackConstants.SAFE_MODE_DISABLED, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004954 }
Craig Mautnereda67292013-04-28 13:50:14 -07004955
Dianne Hackborn181ceb52009-08-27 22:16:40 -07004956 static long[] getLongIntArray(Resources r, int resid) {
4957 int[] ar = r.getIntArray(resid);
4958 if (ar == null) {
4959 return null;
4960 }
4961 long[] out = new long[ar.length];
4962 for (int i=0; i<ar.length; i++) {
4963 out[i] = ar[i];
4964 }
4965 return out;
4966 }
Craig Mautnereda67292013-04-28 13:50:14 -07004967
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004968 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07004969 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004970 public void systemReady() {
Mike Lockwooded8902d2013-11-15 11:01:47 -08004971 mKeyguardDelegate = new KeyguardServiceDelegate(mContext, null);
4972 mKeyguardDelegate.onSystemReady();
4973
Jeff Brown4f5fa282014-06-12 19:19:15 -07004974 updateUiMode();
Dianne Hackbornb1a79802009-09-29 15:18:31 -07004975 synchronized (mLock) {
4976 updateOrientationListenerLp();
Dianne Hackbornc777e072010-02-12 13:07:59 -08004977 mSystemReady = true;
4978 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07004979 @Override
Dianne Hackbornc777e072010-02-12 13:07:59 -08004980 public void run() {
4981 updateSettings();
4982 }
4983 });
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004984 }
4985 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07004986
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07004987 /** {@inheritDoc} */
4988 public void systemBooted() {
Jim Millere5f910a2013-10-16 18:15:46 -07004989 if (mKeyguardDelegate != null) {
4990 mKeyguardDelegate.onBootCompleted();
4991 }
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07004992 synchronized (mLock) {
4993 mSystemBooted = true;
4994 }
Craig Mautner8a0da012014-05-31 15:13:37 -07004995 wakingUp(null);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07004996 }
4997
Dianne Hackborn661cd522011-08-22 00:26:20 -07004998 ProgressDialog mBootMsgDialog = null;
4999
5000 /** {@inheritDoc} */
5001 public void showBootMessage(final CharSequence msg, final boolean always) {
5002 mHandler.post(new Runnable() {
5003 @Override public void run() {
5004 if (mBootMsgDialog == null) {
Craig Stout4c0cb8a2014-04-04 13:03:10 -07005005 int theme;
5006 if (mContext.getPackageManager().hasSystemFeature(
5007 PackageManager.FEATURE_WATCH)) {
5008 theme = com.android.internal.R.style.Theme_Micro_Dialog_Alert;
5009 } else if (mContext.getPackageManager().hasSystemFeature(
5010 PackageManager.FEATURE_TELEVISION)) {
5011 theme = com.android.internal.R.style.Theme_Leanback_Dialog_Alert;
5012 } else {
5013 theme = 0;
5014 }
Vinod Krishnanfa8fc412014-04-18 14:35:53 -07005015
5016 mBootMsgDialog = new ProgressDialog(mContext, theme) {
Dianne Hackborn295e3c22011-08-25 13:19:08 -07005017 // This dialog will consume all events coming in to
5018 // it, to avoid it trying to do things too early in boot.
5019 @Override public boolean dispatchKeyEvent(KeyEvent event) {
5020 return true;
5021 }
5022 @Override public boolean dispatchKeyShortcutEvent(KeyEvent event) {
5023 return true;
5024 }
5025 @Override public boolean dispatchTouchEvent(MotionEvent ev) {
5026 return true;
5027 }
5028 @Override public boolean dispatchTrackballEvent(MotionEvent ev) {
5029 return true;
5030 }
5031 @Override public boolean dispatchGenericMotionEvent(MotionEvent ev) {
5032 return true;
5033 }
5034 @Override public boolean dispatchPopulateAccessibilityEvent(
5035 AccessibilityEvent event) {
5036 return true;
5037 }
5038 };
Dianne Hackborn661cd522011-08-22 00:26:20 -07005039 mBootMsgDialog.setTitle(R.string.android_upgrading_title);
5040 mBootMsgDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
5041 mBootMsgDialog.setIndeterminate(true);
5042 mBootMsgDialog.getWindow().setType(
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07005043 WindowManager.LayoutParams.TYPE_BOOT_PROGRESS);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005044 mBootMsgDialog.getWindow().addFlags(
5045 WindowManager.LayoutParams.FLAG_DIM_BEHIND
5046 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
5047 mBootMsgDialog.getWindow().setDimAmount(1);
Dianne Hackbornd9efb952011-12-07 14:56:51 -08005048 WindowManager.LayoutParams lp = mBootMsgDialog.getWindow().getAttributes();
5049 lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
5050 mBootMsgDialog.getWindow().setAttributes(lp);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005051 mBootMsgDialog.setCancelable(false);
5052 mBootMsgDialog.show();
5053 }
5054 mBootMsgDialog.setMessage(msg);
5055 }
5056 });
5057 }
5058
5059 /** {@inheritDoc} */
5060 public void hideBootMessages() {
5061 mHandler.post(new Runnable() {
5062 @Override public void run() {
5063 if (mBootMsgDialog != null) {
5064 mBootMsgDialog.dismiss();
5065 mBootMsgDialog = null;
5066 }
5067 }
5068 });
5069 }
5070
Mike Lockwood28569302010-01-28 11:54:40 -05005071 /** {@inheritDoc} */
5072 public void userActivity() {
Dianne Hackborndf89e652011-10-06 22:35:11 -07005073 // ***************************************
5074 // NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
5075 // ***************************************
5076 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
5077 // WITH ITS LOCKS HELD.
5078 //
5079 // This code must be VERY careful about the locks
5080 // it acquires.
5081 // In fact, the current code acquires way too many,
5082 // and probably has lurking deadlocks.
5083
Mike Lockwood28569302010-01-28 11:54:40 -05005084 synchronized (mScreenLockTimeout) {
5085 if (mLockScreenTimerActive) {
5086 // reset the timer
5087 mHandler.removeCallbacks(mScreenLockTimeout);
5088 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
5089 }
5090 }
Daniel Sandler0601eb72011-04-13 01:01:32 -04005091 }
5092
Adam Cohenf7522022012-10-03 20:03:18 -07005093 class ScreenLockTimeout implements Runnable {
5094 Bundle options;
5095
5096 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05005097 public void run() {
5098 synchronized (this) {
5099 if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard");
Jim Miller5ecd8112013-01-09 18:50:26 -08005100 if (mKeyguardDelegate != null) {
5101 mKeyguardDelegate.doKeyguardTimeout(options);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005102 }
Mike Lockwood28569302010-01-28 11:54:40 -05005103 mLockScreenTimerActive = false;
Adam Cohenf7522022012-10-03 20:03:18 -07005104 options = null;
Mike Lockwood28569302010-01-28 11:54:40 -05005105 }
5106 }
Mike Lockwood28569302010-01-28 11:54:40 -05005107
Adam Cohenf7522022012-10-03 20:03:18 -07005108 public void setLockOptions(Bundle options) {
5109 this.options = options;
5110 }
5111 }
5112
5113 ScreenLockTimeout mScreenLockTimeout = new ScreenLockTimeout();
5114
5115 public void lockNow(Bundle options) {
Jim Miller93c518e2012-01-17 15:55:31 -08005116 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null);
5117 mHandler.removeCallbacks(mScreenLockTimeout);
Adam Cohenf7522022012-10-03 20:03:18 -07005118 if (options != null) {
5119 // In case multiple calls are made to lockNow, we don't wipe out the options
5120 // until the runnable actually executes.
5121 mScreenLockTimeout.setLockOptions(options);
5122 }
Jim Miller93c518e2012-01-17 15:55:31 -08005123 mHandler.post(mScreenLockTimeout);
5124 }
5125
Mike Lockwood28569302010-01-28 11:54:40 -05005126 private void updateLockScreenTimeout() {
5127 synchronized (mScreenLockTimeout) {
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005128 boolean enable = (mAllowLockscreenWhenOn && mScreenOnEarly &&
Jim Miller5ecd8112013-01-09 18:50:26 -08005129 mKeyguardDelegate != null && mKeyguardDelegate.isSecure());
Mike Lockwood28569302010-01-28 11:54:40 -05005130 if (mLockScreenTimerActive != enable) {
5131 if (enable) {
5132 if (localLOGV) Log.v(TAG, "setting lockscreen timer");
5133 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
5134 } else {
5135 if (localLOGV) Log.v(TAG, "clearing lockscreen timer");
5136 mHandler.removeCallbacks(mScreenLockTimeout);
5137 }
5138 mLockScreenTimerActive = enable;
5139 }
5140 }
5141 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005142
5143 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07005144 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005145 public void enableScreenAfterBoot() {
5146 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07005147 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07005148 updateRotation(true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005149 }
Dianne Hackbornf54c8f92009-09-19 14:03:57 -07005150
Jeff Brownc458ce92012-04-30 14:58:40 -07005151 private void applyLidSwitchState() {
Jeff Brownc458ce92012-04-30 14:58:40 -07005152 if (mLidState == LID_CLOSED && mLidControlsSleep) {
Jeff Brown6d8fd272014-05-20 21:24:38 -07005153 mPowerManager.goToSleep(SystemClock.uptimeMillis(),
5154 PowerManager.GO_TO_SLEEP_REASON_USER,
5155 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
Jeff Brownc458ce92012-04-30 14:58:40 -07005156 }
Jeff Browna20dda42014-05-27 20:57:24 -07005157
5158 synchronized (mLock) {
5159 updateWakeGestureListenerLp();
5160 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005161 }
5162
Jeff Brown4f5fa282014-06-12 19:19:15 -07005163 void updateUiMode() {
5164 if (mUiModeManager == null) {
5165 mUiModeManager = IUiModeManager.Stub.asInterface(
5166 ServiceManager.getService(Context.UI_MODE_SERVICE));
5167 }
5168 try {
5169 mUiMode = mUiModeManager.getCurrentModeType();
5170 } catch (RemoteException e) {
5171 }
5172 }
5173
Jeff Brown01a98dd2011-09-20 15:08:29 -07005174 void updateRotation(boolean alwaysSendConfiguration) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005175 try {
5176 //set orientation on WindowManager
Dianne Hackbornf87d1962012-04-04 12:48:24 -07005177 mWindowManager.updateRotation(alwaysSendConfiguration, false);
5178 } catch (RemoteException e) {
5179 // Ignore
5180 }
5181 }
5182
5183 void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) {
5184 try {
5185 //set orientation on WindowManager
5186 mWindowManager.updateRotation(alwaysSendConfiguration, forceRelayout);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005187 } catch (RemoteException e) {
5188 // Ignore
5189 }
5190 }
5191
Daniel Sandler6396c722013-04-16 20:19:09 -04005192 /**
5193 * Return an Intent to launch the currently active dock app as home. Returns
5194 * null if the standard home should be launched, which is the case if any of the following is
5195 * true:
5196 * <ul>
5197 * <li>The device is not in either car mode or desk mode
5198 * <li>The device is in car mode but ENABLE_CAR_DOCK_HOME_CAPTURE is false
5199 * <li>The device is in desk mode but ENABLE_DESK_DOCK_HOME_CAPTURE is false
5200 * <li>The device is in car mode but there's no CAR_DOCK app with METADATA_DOCK_HOME
5201 * <li>The device is in desk mode but there's no DESK_DOCK app with METADATA_DOCK_HOME
5202 * </ul>
Craig Mautnereda67292013-04-28 13:50:14 -07005203 * @return A dock intent.
Daniel Sandler6396c722013-04-16 20:19:09 -04005204 */
5205 Intent createHomeDockIntent() {
5206 Intent intent = null;
5207
5208 // What home does is based on the mode, not the dock state. That
5209 // is, when in car mode you should be taken to car home regardless
5210 // of whether we are actually in a car dock.
5211 if (mUiMode == Configuration.UI_MODE_TYPE_CAR) {
5212 if (ENABLE_CAR_DOCK_HOME_CAPTURE) {
5213 intent = mCarDockIntent;
5214 }
5215 } else if (mUiMode == Configuration.UI_MODE_TYPE_DESK) {
5216 if (ENABLE_DESK_DOCK_HOME_CAPTURE) {
5217 intent = mDeskDockIntent;
5218 }
Jeff Brown4f5fa282014-06-12 19:19:15 -07005219 } else if (mUiMode == Configuration.UI_MODE_TYPE_WATCH
5220 && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
5221 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK
5222 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK)) {
5223 // Always launch dock home from home when watch is docked, if it exists.
5224 intent = mDeskDockIntent;
Daniel Sandler6396c722013-04-16 20:19:09 -04005225 }
5226
5227 if (intent == null) {
5228 return null;
5229 }
5230
5231 ActivityInfo ai = null;
5232 ResolveInfo info = mContext.getPackageManager().resolveActivityAsUser(
5233 intent,
John Spurlockf56bef12013-07-09 09:51:46 -04005234 PackageManager.MATCH_DEFAULT_ONLY | PackageManager.GET_META_DATA,
Craig Mautnerd625ab22013-09-06 13:40:31 -07005235 mCurrentUserId);
Daniel Sandler6396c722013-04-16 20:19:09 -04005236 if (info != null) {
5237 ai = info.activityInfo;
5238 }
5239 if (ai != null
5240 && ai.metaData != null
5241 && ai.metaData.getBoolean(Intent.METADATA_DOCK_HOME)) {
5242 intent = new Intent(intent);
5243 intent.setClassName(ai.packageName, ai.name);
5244 return intent;
5245 }
5246
5247 return null;
5248 }
5249
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005250 void startDockOrHome() {
John Spurlockc8b46ca2013-04-08 12:59:26 -04005251 awakenDreams();
Daniel Sandler6396c722013-04-16 20:19:09 -04005252
5253 Intent dock = createHomeDockIntent();
5254 if (dock != null) {
5255 try {
5256 mContext.startActivityAsUser(dock, UserHandle.CURRENT);
5257 return;
5258 } catch (ActivityNotFoundException e) {
5259 }
5260 }
5261
Dianne Hackbornd8883992012-09-07 15:58:52 -07005262 mContext.startActivityAsUser(mHomeIntent, UserHandle.CURRENT);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005263 }
Craig Mautnereda67292013-04-28 13:50:14 -07005264
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005265 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005266 * goes to the home screen
5267 * @return whether it did anything
5268 */
5269 boolean goHome() {
5270 if (false) {
5271 // This code always brings home to the front.
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07005272 try {
5273 ActivityManagerNative.getDefault().stopAppSwitches();
5274 } catch (RemoteException e) {
5275 }
Dianne Hackborn94a679d2009-07-28 17:51:07 -07005276 sendCloseSystemWindows();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005277 startDockOrHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005278 } else {
5279 // This code brings home to the front or, if it is already
5280 // at the front, puts the device to sleep.
5281 try {
Wink Savilled2e6a332010-02-12 12:12:06 -08005282 if (SystemProperties.getInt("persist.sys.uts-test-mode", 0) == 1) {
5283 /// Roll back EndcallBehavior as the cupcake design to pass P1 lab entry.
5284 Log.d(TAG, "UTS-TEST-MODE");
5285 } else {
5286 ActivityManagerNative.getDefault().stopAppSwitches();
5287 sendCloseSystemWindows();
Daniel Sandler6396c722013-04-16 20:19:09 -04005288 Intent dock = createHomeDockIntent();
5289 if (dock != null) {
5290 int result = ActivityManagerNative.getDefault()
5291 .startActivityAsUser(null, null, dock,
5292 dock.resolveTypeIfNeeded(mContext.getContentResolver()),
5293 null, null, 0,
5294 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
5295 null, null, null, UserHandle.USER_CURRENT);
5296 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
5297 return false;
5298 }
5299 }
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005300 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005301 int result = ActivityManagerNative.getDefault()
Dianne Hackbornf265ea92013-01-31 15:00:51 -08005302 .startActivityAsUser(null, null, mHomeIntent,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005303 mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()),
Dianne Hackborna4972e92012-03-14 10:38:05 -07005304 null, null, 0,
5305 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Dianne Hackborn5e03e2c2012-09-06 14:21:19 -07005306 null, null, null, UserHandle.USER_CURRENT);
Dianne Hackborna4972e92012-03-14 10:38:05 -07005307 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005308 return false;
5309 }
5310 } catch (RemoteException ex) {
5311 // bummer, the activity manager, which is in this process, is dead
5312 }
5313 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005314 return true;
5315 }
Craig Mautnereda67292013-04-28 13:50:14 -07005316
5317 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07005318 public void setCurrentOrientationLw(int newOrientation) {
5319 synchronized (mLock) {
5320 if (newOrientation != mCurrentAppOrientation) {
5321 mCurrentAppOrientation = newOrientation;
5322 updateOrientationListenerLp();
5323 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005324 }
5325 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08005326
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07005327 private void performAuditoryFeedbackForAccessibilityIfNeed() {
5328 if (!isGlobalAccessibilityGestureEnabled()) {
5329 return;
5330 }
5331 AudioManager audioManager = (AudioManager) mContext.getSystemService(
5332 Context.AUDIO_SERVICE);
5333 if (audioManager.isSilentMode()) {
5334 return;
5335 }
5336 Ringtone ringTone = RingtoneManager.getRingtone(mContext,
5337 Settings.System.DEFAULT_NOTIFICATION_URI);
5338 ringTone.setStreamType(AudioManager.STREAM_MUSIC);
5339 ringTone.play();
5340 }
Craig Mautnereda67292013-04-28 13:50:14 -07005341
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07005342 private boolean isGlobalAccessibilityGestureEnabled() {
5343 return Settings.Global.getInt(mContext.getContentResolver(),
5344 Settings.Global.ENABLE_ACCESSIBILITY_GLOBAL_GESTURE_ENABLED, 0) == 1;
5345 }
5346
Craig Mautnereda67292013-04-28 13:50:14 -07005347 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07005348 public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) {
Svetoslav Ganov96179212012-10-10 14:17:45 -07005349 if (!mVibrator.hasVibrator()) {
5350 return false;
5351 }
Christopher Tate5e08af02012-09-21 17:17:22 -07005352 final boolean hapticsDisabled = Settings.System.getIntForUser(mContext.getContentResolver(),
5353 Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) == 0;
Jorim Jaggi5cf17872014-03-26 18:31:48 +01005354 if (!always && (hapticsDisabled || mKeyguardDelegate.isShowingAndNotOccluded())) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005355 return false;
5356 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08005357 long[] pattern = null;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005358 switch (effectId) {
5359 case HapticFeedbackConstants.LONG_PRESS:
Amith Yamasanic33cb712010-02-10 15:21:49 -08005360 pattern = mLongPressVibePattern;
5361 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07005362 case HapticFeedbackConstants.VIRTUAL_KEY:
Amith Yamasanic33cb712010-02-10 15:21:49 -08005363 pattern = mVirtualKeyVibePattern;
5364 break;
5365 case HapticFeedbackConstants.KEYBOARD_TAP:
5366 pattern = mKeyboardTapVibePattern;
5367 break;
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07005368 case HapticFeedbackConstants.CLOCK_TICK:
5369 pattern = mClockTickVibePattern;
5370 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07005371 case HapticFeedbackConstants.SAFE_MODE_DISABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08005372 pattern = mSafeModeDisabledVibePattern;
5373 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07005374 case HapticFeedbackConstants.SAFE_MODE_ENABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08005375 pattern = mSafeModeEnabledVibePattern;
5376 break;
Amith Yamasanic33cb712010-02-10 15:21:49 -08005377 default:
5378 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005379 }
Dianne Hackbornf265ea92013-01-31 15:00:51 -08005380 int owningUid;
5381 String owningPackage;
5382 if (win != null) {
5383 owningUid = win.getOwningUid();
5384 owningPackage = win.getOwningPackage();
5385 } else {
5386 owningUid = android.os.Process.myUid();
Dianne Hackborn95d78532013-09-11 09:51:14 -07005387 owningPackage = mContext.getOpPackageName();
Dianne Hackbornf265ea92013-01-31 15:00:51 -08005388 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08005389 if (pattern.length == 1) {
5390 // One-shot vibration
John Spurlock1af30c72014-03-10 08:33:35 -04005391 mVibrator.vibrate(owningUid, owningPackage, pattern[0], AudioManager.STREAM_SYSTEM);
Amith Yamasanic33cb712010-02-10 15:21:49 -08005392 } else {
5393 // Pattern vibration
John Spurlock1af30c72014-03-10 08:33:35 -04005394 mVibrator.vibrate(owningUid, owningPackage, pattern, -1, AudioManager.STREAM_SYSTEM);
Amith Yamasanic33cb712010-02-10 15:21:49 -08005395 }
5396 return true;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005397 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005398
5399 @Override
5400 public void keepScreenOnStartedLw() {
Daniel Sandler0601eb72011-04-13 01:01:32 -04005401 }
5402
Jeff Brownc38c9be2012-10-04 13:16:19 -07005403 @Override
5404 public void keepScreenOnStoppedLw() {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01005405 if (mKeyguardDelegate != null && !mKeyguardDelegate.isShowingAndNotOccluded()) {
Jim Miller25190572013-02-28 17:36:24 -08005406 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005407 }
5408 }
Mike Lockwoodfcb39242009-10-21 23:01:07 -04005409
Dianne Hackborndf89e652011-10-06 22:35:11 -07005410 private int updateSystemUiVisibilityLw() {
Joe Onorato664644d2011-01-23 17:53:23 -08005411 // If there is no window focused, there will be nobody to handle the events
5412 // anyway, so just hang on in whatever state we're in until things settle down.
John Spurlock79da8332013-09-20 12:04:47 -04005413 WindowState win = mFocusedWindow != null ? mFocusedWindow : mTopFullscreenOpaqueWindowState;
5414 if (win == null) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07005415 return 0;
5416 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01005417 if ((win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 && mHideLockScreen == true) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07005418 // We are updating at a point where the keyguard has gotten
5419 // focus, but we were last in a state where the top window is
5420 // hiding it. This is probably because the keyguard as been
5421 // shown while the top window was displayed, so we want to ignore
5422 // it here because this is just a very transient change and it
5423 // will quickly lose focus once it correctly gets hidden.
5424 return 0;
5425 }
John Spurlock32beb2c2013-03-11 10:16:47 -04005426
John Spurlock1db8b682014-02-18 11:18:59 -05005427 int tmpVisibility = PolicyControl.getSystemUiVisibility(win, null)
Dianne Hackborne26ab702011-10-16 13:21:33 -07005428 & ~mResettingSystemUiFlags
5429 & ~mForceClearedSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04005430 if (mForcingShowNavBar && win.getSurfaceLayer() < mForcingShowNavBarLayer) {
John Spurlockc6d1c602014-01-17 15:22:06 -05005431 tmpVisibility &= ~PolicyControl.adjustClearableFlags(win, View.SYSTEM_UI_CLEARABLE_FLAGS);
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08005432 }
John Spurlock79da8332013-09-20 12:04:47 -04005433 final int visibility = updateSystemBarsLw(win, mLastSystemUiFlags, tmpVisibility);
John Spurlockad3e6cb2013-04-30 08:47:43 -04005434 final int diff = visibility ^ mLastSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04005435 final boolean needsMenu = win.getNeedsMenuLw(mTopFullscreenOpaqueWindowState);
Dianne Hackborne0f085d2011-11-30 18:41:15 -08005436 if (diff == 0 && mLastFocusNeedsMenu == needsMenu
John Spurlock79da8332013-09-20 12:04:47 -04005437 && mFocusedApp == win.getAppToken()) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07005438 return 0;
5439 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07005440 mLastSystemUiFlags = visibility;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08005441 mLastFocusNeedsMenu = needsMenu;
John Spurlock79da8332013-09-20 12:04:47 -04005442 mFocusedApp = win.getAppToken();
Dianne Hackborndf89e652011-10-06 22:35:11 -07005443 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07005444 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07005445 public void run() {
Dianne Hackborn42e620c2012-06-24 13:20:51 -07005446 try {
5447 IStatusBarService statusbar = getStatusBarService();
5448 if (statusbar != null) {
5449 statusbar.setSystemUiVisibility(visibility, 0xffffffff);
5450 statusbar.topAppWindowChanged(needsMenu);
Joe Onorato664644d2011-01-23 17:53:23 -08005451 }
Dianne Hackborn42e620c2012-06-24 13:20:51 -07005452 } catch (RemoteException e) {
5453 // re-acquire status bar service next time it is needed.
5454 mStatusBarService = null;
Joe Onorato664644d2011-01-23 17:53:23 -08005455 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07005456 }
5457 });
5458 return diff;
Joe Onorato664644d2011-01-23 17:53:23 -08005459 }
5460
John Spurlock79da8332013-09-20 12:04:47 -04005461 private int updateSystemBarsLw(WindowState win, int oldVis, int vis) {
John Spurlockbd957402013-10-03 11:38:39 -04005462 // apply translucent bar vis flags
Jorim Jaggi380ecb82014-03-14 17:25:20 +01005463 WindowState transWin = isStatusBarKeyguard() && !mHideLockScreen
5464 ? mStatusBar
John Spurlockbd957402013-10-03 11:38:39 -04005465 : mTopFullscreenOpaqueWindowState;
5466 vis = mStatusBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
5467 vis = mNavigationBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
5468
John Spurlock27735a42013-08-14 17:57:38 -04005469 // prevent status bar interaction from clearing certain flags
John Spurlock79da8332013-09-20 12:04:47 -04005470 boolean statusBarHasFocus = win.getAttrs().type == TYPE_STATUS_BAR;
John Spurlockad3e6cb2013-04-30 08:47:43 -04005471 if (statusBarHasFocus) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04005472 int flags = View.SYSTEM_UI_FLAG_FULLSCREEN
5473 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlockcfc359a2013-09-05 10:42:03 -04005474 | View.SYSTEM_UI_FLAG_IMMERSIVE
Jorim Jaggi5cf17872014-03-26 18:31:48 +01005475 | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
5476 if (!isStatusBarKeyguard() || mHideLockScreen) {
5477 flags |= View.STATUS_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSLUCENT;
5478 }
John Spurlockbd957402013-10-03 11:38:39 -04005479 vis = (vis & ~flags) | (oldVis & flags);
John Spurlockad3e6cb2013-04-30 08:47:43 -04005480 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04005481
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04005482 if (!areTranslucentBarsAllowed()) {
Adrian Roosea562512014-05-05 13:33:03 +02005483 vis &= ~(View.NAVIGATION_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSLUCENT
5484 | View.SYSTEM_UI_TRANSPARENT);
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07005485 }
5486
John Spurlock27735a42013-08-14 17:57:38 -04005487 // update status bar
John Spurlockf1a36642013-10-12 17:50:42 -04005488 boolean immersiveSticky =
5489 (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
John Spurlock27735a42013-08-14 17:57:38 -04005490 boolean hideStatusBarWM =
John Spurlockbd957402013-10-03 11:38:39 -04005491 mTopFullscreenOpaqueWindowState != null &&
John Spurlockc6d1c602014-01-17 15:22:06 -05005492 (PolicyControl.getWindowFlags(mTopFullscreenOpaqueWindowState, null)
John Spurlock27735a42013-08-14 17:57:38 -04005493 & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0;
5494 boolean hideStatusBarSysui =
5495 (vis & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04005496 boolean hideNavBarSysui =
5497 (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0;
John Spurlockad3e6cb2013-04-30 08:47:43 -04005498
John Spurlock27735a42013-08-14 17:57:38 -04005499 boolean transientStatusBarAllowed =
5500 mStatusBar != null && (
5501 hideStatusBarWM
John Spurlockf1a36642013-10-12 17:50:42 -04005502 || (hideStatusBarSysui && immersiveSticky)
John Spurlock27735a42013-08-14 17:57:38 -04005503 || statusBarHasFocus);
5504
John Spurlockf1a36642013-10-12 17:50:42 -04005505 boolean transientNavBarAllowed =
5506 mNavigationBar != null &&
5507 hideNavBarSysui && immersiveSticky;
5508
John Spurlockf25706f2013-11-07 18:02:43 -05005509 boolean denyTransientStatus = mStatusBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04005510 && !transientStatusBarAllowed && hideStatusBarSysui;
John Spurlockf25706f2013-11-07 18:02:43 -05005511 boolean denyTransientNav = mNavigationBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04005512 && !transientNavBarAllowed;
5513 if (denyTransientStatus || denyTransientNav) {
John Spurlock27735a42013-08-14 17:57:38 -04005514 // clear the clearable flags instead
John Spurlockf1a36642013-10-12 17:50:42 -04005515 clearClearableFlagsLw();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005516 }
John Spurlock27735a42013-08-14 17:57:38 -04005517
5518 vis = mStatusBarController.updateVisibilityLw(transientStatusBarAllowed, oldVis, vis);
5519
5520 // update navigation bar
John Spurlockf1a36642013-10-12 17:50:42 -04005521 boolean oldImmersiveMode = isImmersiveMode(oldVis);
5522 boolean newImmersiveMode = isImmersiveMode(vis);
5523 if (win != null && oldImmersiveMode != newImmersiveMode) {
John Spurlock79da8332013-09-20 12:04:47 -04005524 final String pkg = win.getOwningPackage();
Maurice Lam99c6e072014-04-28 18:24:28 -07005525 mImmersiveModeConfirmation.immersiveModeChanged(pkg, newImmersiveMode,
5526 isUserSetupComplete());
John Spurlock34e13d92013-08-10 06:52:28 -04005527 }
John Spurlock27735a42013-08-14 17:57:38 -04005528
John Spurlockf1a36642013-10-12 17:50:42 -04005529 vis = mNavigationBarController.updateVisibilityLw(transientNavBarAllowed, oldVis, vis);
5530
John Spurlocke1f366f2013-08-05 12:22:40 -04005531 return vis;
John Spurlockad3e6cb2013-04-30 08:47:43 -04005532 }
5533
John Spurlockf1a36642013-10-12 17:50:42 -04005534 private void clearClearableFlagsLw() {
5535 int newVal = mResettingSystemUiFlags | View.SYSTEM_UI_CLEARABLE_FLAGS;
5536 if (newVal != mResettingSystemUiFlags) {
5537 mResettingSystemUiFlags = newVal;
5538 mWindowManagerFuncs.reevaluateStatusBarVisibility();
5539 }
5540 }
5541
5542 private boolean isImmersiveMode(int vis) {
5543 final int flags = View.SYSTEM_UI_FLAG_IMMERSIVE | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
John Spurlock34e13d92013-08-10 06:52:28 -04005544 return mNavigationBar != null
5545 && (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0
Daniel Sandler900ece52013-10-18 15:53:27 -04005546 && (vis & flags) != 0
5547 && canHideNavigationBar();
John Spurlock34e13d92013-08-10 06:52:28 -04005548 }
5549
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07005550 /**
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04005551 * @return whether the navigation or status bar can be made translucent
5552 *
5553 * This should return true unless touch exploration is not enabled or
5554 * R.boolean.config_enableTranslucentDecor is false.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07005555 */
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04005556 private boolean areTranslucentBarsAllowed() {
Svetoslav8e3feb12014-02-24 13:46:47 -08005557 return mTranslucentDecorEnabled
5558 && !mAccessibilityManager.isTouchExplorationEnabled();
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07005559 }
5560
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04005561 // Use this instead of checking config_showNavigationBar so that it can be consistently
5562 // overridden by qemu.hw.mainkeys in the emulator.
Craig Mautnereda67292013-04-28 13:50:14 -07005563 @Override
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04005564 public boolean hasNavigationBar() {
5565 return mHasNavigationBar;
5566 }
5567
satok1bc0a492012-04-25 22:47:12 +09005568 @Override
5569 public void setLastInputMethodWindowLw(WindowState ime, WindowState target) {
5570 mLastInputMethodWindow = ime;
5571 mLastInputMethodTargetWindow = target;
5572 }
5573
Craig Mautnerf1b67412012-09-19 13:18:29 -07005574 @Override
Satoshi Kataoka658c7b82013-10-10 17:03:51 +09005575 public int getInputMethodWindowVisibleHeightLw() {
5576 return mDockBottom - mCurBottom;
5577 }
5578
5579 @Override
Craig Mautnerf1b67412012-09-19 13:18:29 -07005580 public void setCurrentUserLw(int newUserId) {
Craig Mautnerd625ab22013-09-06 13:40:31 -07005581 mCurrentUserId = newUserId;
Jim Miller5ecd8112013-01-09 18:50:26 -08005582 if (mKeyguardDelegate != null) {
5583 mKeyguardDelegate.setCurrentUser(newUserId);
Craig Mautnerf1b67412012-09-19 13:18:29 -07005584 }
John Spurlock13451a22012-09-28 14:40:41 -04005585 if (mStatusBarService != null) {
5586 try {
5587 mStatusBarService.setCurrentUser(newUserId);
5588 } catch (RemoteException e) {
5589 // oh well
5590 }
5591 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07005592 setLastInputMethodWindowLw(null, null);
Craig Mautnerf1b67412012-09-19 13:18:29 -07005593 }
5594
5595 @Override
Svetoslav Ganov545252f2012-12-10 18:29:24 -08005596 public boolean canMagnifyWindow(int windowType) {
5597 switch (windowType) {
5598 case WindowManager.LayoutParams.TYPE_INPUT_METHOD:
5599 case WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG:
5600 case WindowManager.LayoutParams.TYPE_NAVIGATION_BAR:
5601 case WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY: {
5602 return false;
5603 }
5604 }
5605 return true;
5606 }
5607
5608 @Override
5609 public boolean isTopLevelWindow(int windowType) {
5610 if (windowType >= WindowManager.LayoutParams.FIRST_SUB_WINDOW
5611 && windowType <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
5612 return (windowType == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG);
5613 }
5614 return true;
5615 }
5616
Jim Miller4eeb4f62012-11-08 00:04:29 -08005617 @Override
Jeff Brownd7a04de2012-06-17 14:17:52 -07005618 public void dump(String prefix, PrintWriter pw, String[] args) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005619 pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005620 pw.print(" mSystemReady="); pw.print(mSystemReady);
5621 pw.print(" mSystemBooted="); pw.println(mSystemBooted);
Jeff Brown2e7760e2012-04-11 15:14:55 -07005622 pw.print(prefix); pw.print("mLidState="); pw.print(mLidState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005623 pw.print(" mLidOpenRotation="); pw.print(mLidOpenRotation);
5624 pw.print(" mHdmiPlugged="); pw.println(mHdmiPlugged);
Dianne Hackborne26ab702011-10-16 13:21:33 -07005625 if (mLastSystemUiFlags != 0 || mResettingSystemUiFlags != 0
5626 || mForceClearedSystemUiFlags != 0) {
5627 pw.print(prefix); pw.print("mLastSystemUiFlags=0x");
5628 pw.print(Integer.toHexString(mLastSystemUiFlags));
5629 pw.print(" mResettingSystemUiFlags=0x");
5630 pw.print(Integer.toHexString(mResettingSystemUiFlags));
5631 pw.print(" mForceClearedSystemUiFlags=0x");
5632 pw.println(Integer.toHexString(mForceClearedSystemUiFlags));
Dianne Hackborndf89e652011-10-06 22:35:11 -07005633 }
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08005634 if (mLastFocusNeedsMenu) {
5635 pw.print(prefix); pw.print("mLastFocusNeedsMenu=");
5636 pw.println(mLastFocusNeedsMenu);
5637 }
Jeff Browna20dda42014-05-27 20:57:24 -07005638 pw.print(prefix); pw.print("mWakeGestureEnabledSetting=");
5639 pw.println(mWakeGestureEnabledSetting);
5640
Jeff Brownbcdfc622014-03-06 19:13:04 -08005641 pw.print(prefix); pw.print("mSupportAutoRotation="); pw.println(mSupportAutoRotation);
Daniel Sandler6396c722013-04-16 20:19:09 -04005642 pw.print(prefix); pw.print("mUiMode="); pw.print(mUiMode);
5643 pw.print(" mDockMode="); pw.print(mDockMode);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005644 pw.print(" mCarDockRotation="); pw.print(mCarDockRotation);
5645 pw.print(" mDeskDockRotation="); pw.println(mDeskDockRotation);
5646 pw.print(prefix); pw.print("mUserRotationMode="); pw.print(mUserRotationMode);
5647 pw.print(" mUserRotation="); pw.print(mUserRotation);
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005648 pw.print(" mAllowAllRotations="); pw.println(mAllowAllRotations);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07005649 pw.print(prefix); pw.print("mCurrentAppOrientation="); pw.println(mCurrentAppOrientation);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005650 pw.print(prefix); pw.print("mCarDockEnablesAccelerometer=");
5651 pw.print(mCarDockEnablesAccelerometer);
5652 pw.print(" mDeskDockEnablesAccelerometer=");
5653 pw.println(mDeskDockEnablesAccelerometer);
5654 pw.print(prefix); pw.print("mLidKeyboardAccessibility=");
5655 pw.print(mLidKeyboardAccessibility);
5656 pw.print(" mLidNavigationAccessibility="); pw.print(mLidNavigationAccessibility);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07005657 pw.print(" mLidControlsSleep="); pw.println(mLidControlsSleep);
Jeff Brown6d8fd272014-05-20 21:24:38 -07005658 pw.print(prefix);
5659 pw.print("mShortPressOnPowerBehavior="); pw.print(mShortPressOnPowerBehavior);
5660 pw.print(" mLongPressOnPowerBehavior="); pw.println(mLongPressOnPowerBehavior);
5661 pw.print(prefix); pw.print("mHasSoftInput="); pw.println(mHasSoftInput);
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07005662 pw.print(prefix); pw.print("mScreenOnEarly="); pw.print(mScreenOnEarly);
5663 pw.print(" mScreenOnFully="); pw.print(mScreenOnFully);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07005664 pw.print(" mOrientationSensorEnabled="); pw.println(mOrientationSensorEnabled);
Dianne Hackbornc652de82013-02-15 16:32:56 -08005665 pw.print(prefix); pw.print("mOverscanScreen=("); pw.print(mOverscanScreenLeft);
5666 pw.print(","); pw.print(mOverscanScreenTop);
5667 pw.print(") "); pw.print(mOverscanScreenWidth);
5668 pw.print("x"); pw.println(mOverscanScreenHeight);
5669 if (mOverscanLeft != 0 || mOverscanTop != 0
5670 || mOverscanRight != 0 || mOverscanBottom != 0) {
5671 pw.print(prefix); pw.print("mOverscan left="); pw.print(mOverscanLeft);
5672 pw.print(" top="); pw.print(mOverscanTop);
5673 pw.print(" right="); pw.print(mOverscanRight);
5674 pw.print(" bottom="); pw.println(mOverscanBottom);
5675 }
Dianne Hackborn313440842013-02-19 19:22:59 -08005676 pw.print(prefix); pw.print("mRestrictedOverscanScreen=(");
5677 pw.print(mRestrictedOverscanScreenLeft);
5678 pw.print(","); pw.print(mRestrictedOverscanScreenTop);
5679 pw.print(") "); pw.print(mRestrictedOverscanScreenWidth);
5680 pw.print("x"); pw.println(mRestrictedOverscanScreenHeight);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005681 pw.print(prefix); pw.print("mUnrestrictedScreen=("); pw.print(mUnrestrictedScreenLeft);
5682 pw.print(","); pw.print(mUnrestrictedScreenTop);
5683 pw.print(") "); pw.print(mUnrestrictedScreenWidth);
5684 pw.print("x"); pw.println(mUnrestrictedScreenHeight);
5685 pw.print(prefix); pw.print("mRestrictedScreen=("); pw.print(mRestrictedScreenLeft);
5686 pw.print(","); pw.print(mRestrictedScreenTop);
5687 pw.print(") "); pw.print(mRestrictedScreenWidth);
5688 pw.print("x"); pw.println(mRestrictedScreenHeight);
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07005689 pw.print(prefix); pw.print("mStableFullscreen=("); pw.print(mStableFullscreenLeft);
5690 pw.print(","); pw.print(mStableFullscreenTop);
5691 pw.print(")-("); pw.print(mStableFullscreenRight);
5692 pw.print(","); pw.print(mStableFullscreenBottom); pw.println(")");
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07005693 pw.print(prefix); pw.print("mStable=("); pw.print(mStableLeft);
5694 pw.print(","); pw.print(mStableTop);
5695 pw.print(")-("); pw.print(mStableRight);
5696 pw.print(","); pw.print(mStableBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07005697 pw.print(prefix); pw.print("mSystem=("); pw.print(mSystemLeft);
5698 pw.print(","); pw.print(mSystemTop);
5699 pw.print(")-("); pw.print(mSystemRight);
5700 pw.print(","); pw.print(mSystemBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005701 pw.print(prefix); pw.print("mCur=("); pw.print(mCurLeft);
5702 pw.print(","); pw.print(mCurTop);
5703 pw.print(")-("); pw.print(mCurRight);
5704 pw.print(","); pw.print(mCurBottom); pw.println(")");
5705 pw.print(prefix); pw.print("mContent=("); pw.print(mContentLeft);
5706 pw.print(","); pw.print(mContentTop);
5707 pw.print(")-("); pw.print(mContentRight);
5708 pw.print(","); pw.print(mContentBottom); pw.println(")");
Dianne Hackborne30e02f2014-05-27 18:24:45 -07005709 pw.print(prefix); pw.print("mVoiceContent=("); pw.print(mVoiceContentLeft);
5710 pw.print(","); pw.print(mVoiceContentTop);
5711 pw.print(")-("); pw.print(mVoiceContentRight);
5712 pw.print(","); pw.print(mVoiceContentBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005713 pw.print(prefix); pw.print("mDock=("); pw.print(mDockLeft);
5714 pw.print(","); pw.print(mDockTop);
5715 pw.print(")-("); pw.print(mDockRight);
5716 pw.print(","); pw.print(mDockBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07005717 pw.print(prefix); pw.print("mDockLayer="); pw.print(mDockLayer);
5718 pw.print(" mStatusBarLayer="); pw.println(mStatusBarLayer);
Dianne Hackborn7ad44382012-10-18 17:46:00 -07005719 pw.print(prefix); pw.print("mShowingLockscreen="); pw.print(mShowingLockscreen);
5720 pw.print(" mShowingDream="); pw.print(mShowingDream);
5721 pw.print(" mDreamingLockscreen="); pw.println(mDreamingLockscreen);
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07005722 if (mLastInputMethodWindow != null) {
5723 pw.print(prefix); pw.print("mLastInputMethodWindow=");
5724 pw.println(mLastInputMethodWindow);
5725 }
5726 if (mLastInputMethodTargetWindow != null) {
5727 pw.print(prefix); pw.print("mLastInputMethodTargetWindow=");
5728 pw.println(mLastInputMethodTargetWindow);
5729 }
5730 if (mStatusBar != null) {
5731 pw.print(prefix); pw.print("mStatusBar=");
5732 pw.println(mStatusBar);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01005733 pw.print(prefix); pw.print("isStatusBarKeyguard=");
5734 pw.print(isStatusBarKeyguard());
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07005735 }
5736 if (mNavigationBar != null) {
5737 pw.print(prefix); pw.print("mNavigationBar=");
5738 pw.println(mNavigationBar);
5739 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07005740 if (mFocusedWindow != null) {
5741 pw.print(prefix); pw.print("mFocusedWindow=");
5742 pw.println(mFocusedWindow);
5743 }
5744 if (mFocusedApp != null) {
5745 pw.print(prefix); pw.print("mFocusedApp=");
5746 pw.println(mFocusedApp);
5747 }
5748 if (mWinDismissingKeyguard != null) {
5749 pw.print(prefix); pw.print("mWinDismissingKeyguard=");
5750 pw.println(mWinDismissingKeyguard);
5751 }
5752 if (mTopFullscreenOpaqueWindowState != null) {
5753 pw.print(prefix); pw.print("mTopFullscreenOpaqueWindowState=");
5754 pw.println(mTopFullscreenOpaqueWindowState);
5755 }
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08005756 if (mForcingShowNavBar) {
5757 pw.print(prefix); pw.print("mForcingShowNavBar=");
5758 pw.println(mForcingShowNavBar); pw.print( "mForcingShowNavBarLayer=");
5759 pw.println(mForcingShowNavBarLayer);
5760 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07005761 pw.print(prefix); pw.print("mTopIsFullscreen="); pw.print(mTopIsFullscreen);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005762 pw.print(" mHideLockScreen="); pw.println(mHideLockScreen);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07005763 pw.print(prefix); pw.print("mForceStatusBar="); pw.print(mForceStatusBar);
5764 pw.print(" mForceStatusBarFromKeyguard=");
5765 pw.println(mForceStatusBarFromKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005766 pw.print(prefix); pw.print("mDismissKeyguard="); pw.print(mDismissKeyguard);
Craig Mautnerad09bcc2012-10-08 13:33:11 -07005767 pw.print(" mWinDismissingKeyguard="); pw.print(mWinDismissingKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005768 pw.print(" mHomePressed="); pw.println(mHomePressed);
5769 pw.print(prefix); pw.print("mAllowLockscreenWhenOn="); pw.print(mAllowLockscreenWhenOn);
5770 pw.print(" mLockScreenTimeout="); pw.print(mLockScreenTimeout);
5771 pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive);
5772 pw.print(prefix); pw.print("mEndcallBehavior="); pw.print(mEndcallBehavior);
5773 pw.print(" mIncallPowerBehavior="); pw.print(mIncallPowerBehavior);
5774 pw.print(" mLongPressOnHomeBehavior="); pw.println(mLongPressOnHomeBehavior);
5775 pw.print(prefix); pw.print("mLandscapeRotation="); pw.print(mLandscapeRotation);
5776 pw.print(" mSeascapeRotation="); pw.println(mSeascapeRotation);
5777 pw.print(prefix); pw.print("mPortraitRotation="); pw.print(mPortraitRotation);
5778 pw.print(" mUpsideDownRotation="); pw.println(mUpsideDownRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07005779 pw.print(prefix); pw.print("mDemoHdmiRotation="); pw.print(mDemoHdmiRotation);
5780 pw.print(" mDemoHdmiRotationLock="); pw.println(mDemoHdmiRotationLock);
5781 pw.print(prefix); pw.print("mUndockedHdmiRotation="); pw.println(mUndockedHdmiRotation);
Jeff Brown600f0032014-05-22 17:06:00 -07005782
Tim Kilbournd7c0c2e2014-05-29 16:08:10 -07005783 mGlobalKeyManager.dump(prefix, pw);
John Spurlock27735a42013-08-14 17:57:38 -04005784 mStatusBarController.dump(pw, prefix);
5785 mNavigationBarController.dump(pw, prefix);
John Spurlockc6d1c602014-01-17 15:22:06 -05005786 PolicyControl.dump(prefix, pw);
Jeff Brown600f0032014-05-22 17:06:00 -07005787
Jeff Browna20dda42014-05-27 20:57:24 -07005788 if (mWakeGestureListener != null) {
5789 mWakeGestureListener.dump(pw, prefix);
5790 }
Jeff Brown600f0032014-05-22 17:06:00 -07005791 if (mOrientationListener != null) {
5792 mOrientationListener.dump(pw, prefix);
5793 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005794 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005795}