blob: ededbb210223d8a3a2a9107699d3b634ac9380f1 [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;
Jean-Michel Trivifca1e602013-10-10 18:12:59 -070045import android.media.AudioSystem;
Michael Jurka7a348952012-02-27 13:07:58 -080046import android.media.IAudioService;
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -070047import android.media.Ringtone;
48import android.media.RingtoneManager;
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;
Dianne Hackborn38e29a62011-09-18 14:43:08 -070053import android.os.IRemoteCallback;
Jeff Brown32cbc38552011-12-01 14:01:49 -080054import android.os.Looper;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -070055import android.os.Message;
56import android.os.Messenger;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080057import android.os.PowerManager;
58import android.os.RemoteException;
59import android.os.ServiceManager;
60import android.os.SystemClock;
61import android.os.SystemProperties;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -080062import android.os.UEventObserver;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -070063import android.os.UserHandle;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080064import android.os.Vibrator;
65import android.provider.Settings;
John Spurlockc8b46ca2013-04-08 12:59:26 -040066import android.service.dreams.DreamService;
67import android.service.dreams.IDreamManager;
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;
92import android.view.WindowManagerPolicy;
Craig Mautnerae446592012-12-06 19:05:05 -080093import android.view.accessibility.AccessibilityEvent;
Svetoslav8e3feb12014-02-24 13:46:47 -080094import android.view.accessibility.AccessibilityManager;
Craig Mautnerae446592012-12-06 19:05:05 -080095import android.view.animation.Animation;
96import android.view.animation.AnimationUtils;
97
98import com.android.internal.R;
99import com.android.internal.policy.PolicyManager;
Jim Miller5ecd8112013-01-09 18:50:26 -0800100import com.android.internal.policy.impl.keyguard.KeyguardServiceDelegate;
Craig Mautnerae446592012-12-06 19:05:05 -0800101import com.android.internal.statusbar.IStatusBarService;
102import com.android.internal.telephony.ITelephony;
103import com.android.internal.widget.PointerLocationView;
104
105import java.io.File;
106import java.io.FileReader;
107import java.io.IOException;
108import java.io.PrintWriter;
Craig Mautner2bc789b2014-03-19 19:48:38 -0700109import java.util.HashSet;
Craig Mautnerae446592012-12-06 19:05:05 -0800110
Dianne Hackbornc652de82013-02-15 16:32:56 -0800111import static android.view.WindowManager.LayoutParams.*;
Jeff Brownac143512012-04-05 18:57:33 -0700112import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_ABSENT;
113import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_OPEN;
114import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_CLOSED;
Dianne Hackborn08743722009-12-21 12:16:51 -0800115
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800116/**
The Android Open Source Project0727d222009-03-11 12:11:58 -0700117 * WindowManagerPolicy implementation for the Android phone UI. This
118 * introduces a new method suffix, Lp, for an internal lock of the
119 * PhoneWindowManager. This is used to protect some internal state, and
John Spurlock04db1762013-05-13 12:46:41 -0400120 * 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 -0700121 * of both of those when held.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800122 */
123public class PhoneWindowManager implements WindowManagerPolicy {
124 static final String TAG = "WindowManager";
125 static final boolean DEBUG = false;
Joe Onorato43a17652011-04-06 19:22:23 -0700126 static final boolean localLOGV = false;
The Android Open Source Project11267662009-03-18 17:39:47 -0700127 static final boolean DEBUG_LAYOUT = false;
Jeff Brown40013652012-05-16 21:22:36 -0700128 static final boolean DEBUG_INPUT = false;
Craig Mautner6fbda632012-07-03 09:26:39 -0700129 static final boolean DEBUG_STARTING_WINDOW = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800130 static final boolean SHOW_STARTING_ANIMATIONS = true;
131 static final boolean SHOW_PROCESSES_ON_ALT_MENU = false;
Joe Onoratod208e702010-10-08 16:22:43 -0400132
Daniel Sandler6396c722013-04-16 20:19:09 -0400133 // Whether to allow dock apps with METADATA_DOCK_HOME to temporarily take over the Home key.
134 // No longer recommended for desk docks; still useful in car docks.
135 static final boolean ENABLE_CAR_DOCK_HOME_CAPTURE = true;
136 static final boolean ENABLE_DESK_DOCK_HOME_CAPTURE = false;
137
Joe Onoratod208e702010-10-08 16:22:43 -0400138 static final int LONG_PRESS_POWER_NOTHING = 0;
139 static final int LONG_PRESS_POWER_GLOBAL_ACTIONS = 1;
140 static final int LONG_PRESS_POWER_SHUT_OFF = 2;
Jeff Brown9a538ee2012-08-20 14:56:57 -0700141 static final int LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM = 3;
Michael Jurka3b1fc472011-06-13 10:54:40 -0700142
143 // These need to match the documentation/constant in
144 // core/res/res/values/config.xml
Joe Onorato46b0d682010-11-22 17:37:27 -0800145 static final int LONG_PRESS_HOME_NOTHING = 0;
Michael Wrightc9ebea72013-01-16 19:25:02 -0800146 static final int LONG_PRESS_HOME_RECENT_SYSTEM_UI = 1;
Jeff Browncaca8812013-05-09 13:34:33 -0700147 static final int LONG_PRESS_HOME_ASSIST = 2;
148
149 static final int DOUBLE_TAP_HOME_NOTHING = 0;
150 static final int DOUBLE_TAP_HOME_RECENT_SYSTEM_UI = 1;
Joe Onorato46b0d682010-11-22 17:37:27 -0800151
Dianne Hackborn5cb8d792009-05-21 17:34:15 -0700152 static final int APPLICATION_MEDIA_SUBLAYER = -2;
153 static final int APPLICATION_MEDIA_OVERLAY_SUBLAYER = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800154 static final int APPLICATION_PANEL_SUBLAYER = 1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800155 static final int APPLICATION_SUB_PANEL_SUBLAYER = 2;
Craig Mautner88400d32012-09-30 12:35:45 -0700156
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800157 static public final String SYSTEM_DIALOG_REASON_KEY = "reason";
158 static public final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions";
159 static public final String SYSTEM_DIALOG_REASON_RECENT_APPS = "recentapps";
Joe Onoratof275f0c2009-11-24 16:11:13 -0500160 static public final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey";
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700161 static public final String SYSTEM_DIALOG_REASON_ASSIST = "assist";
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800162
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700163 /**
164 * These are the system UI flags that, when changing, can cause the layout
165 * of the screen to change.
166 */
167 static final int SYSTEM_UI_CHANGING_LAYOUT =
John Spurlocke1f366f2013-08-05 12:22:40 -0400168 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlock7f4820a2013-10-08 12:54:35 -0400169 | View.SYSTEM_UI_FLAG_FULLSCREEN
170 | View.STATUS_BAR_TRANSLUCENT
171 | View.NAVIGATION_BAR_TRANSLUCENT;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700172
Jim Miller5ecd8112013-01-09 18:50:26 -0800173 /**
174 * Keyguard stuff
175 */
176 private WindowState mKeyguardScrim;
177
Jeff Brown6651a632011-11-28 12:59:11 -0800178 /* Table of Application Launch keys. Maps from key codes to intent categories.
179 *
180 * These are special keys that are used to launch particular kinds of applications,
181 * such as a web browser. HID defines nearly a hundred of them in the Consumer (0x0C)
182 * usage page. We don't support quite that many yet...
183 */
184 static SparseArray<String> sApplicationLaunchKeyCategories;
185 static {
186 sApplicationLaunchKeyCategories = new SparseArray<String>();
187 sApplicationLaunchKeyCategories.append(
188 KeyEvent.KEYCODE_EXPLORER, Intent.CATEGORY_APP_BROWSER);
189 sApplicationLaunchKeyCategories.append(
190 KeyEvent.KEYCODE_ENVELOPE, Intent.CATEGORY_APP_EMAIL);
191 sApplicationLaunchKeyCategories.append(
192 KeyEvent.KEYCODE_CONTACTS, Intent.CATEGORY_APP_CONTACTS);
193 sApplicationLaunchKeyCategories.append(
194 KeyEvent.KEYCODE_CALENDAR, Intent.CATEGORY_APP_CALENDAR);
195 sApplicationLaunchKeyCategories.append(
196 KeyEvent.KEYCODE_MUSIC, Intent.CATEGORY_APP_MUSIC);
197 sApplicationLaunchKeyCategories.append(
198 KeyEvent.KEYCODE_CALCULATOR, Intent.CATEGORY_APP_CALCULATOR);
199 }
200
Dianne Hackborndf89e652011-10-06 22:35:11 -0700201 /**
202 * Lock protecting internal state. Must not call out into window
203 * manager with lock held. (This lock will be acquired in places
204 * where the window manager is calling in with its own lock held.)
205 */
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800206 private final Object mLock = new Object();
Dianne Hackborndf89e652011-10-06 22:35:11 -0700207
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800208 Context mContext;
209 IWindowManager mWindowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700210 WindowManagerFuncs mWindowManagerFuncs;
Jeff Brown96307042012-07-27 15:51:34 -0700211 PowerManager mPowerManager;
Joe Onorato93056472010-09-10 10:30:46 -0400212 IStatusBarService mStatusBarService;
Jeff Browncaca8812013-05-09 13:34:33 -0700213 boolean mPreloadedRecentApps;
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700214 final Object mServiceAquireLock = new Object();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800215 Vibrator mVibrator; // Vibrator for giving feedback of orientation changes
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700216 SearchManager mSearchManager;
Svetoslav8e3feb12014-02-24 13:46:47 -0800217 AccessibilityManager mAccessibilityManager;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800218
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700219 // Vibrator pattern for haptic feedback of a long press.
220 long[] mLongPressVibePattern;
Craig Mautner88400d32012-09-30 12:35:45 -0700221
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700222 // Vibrator pattern for haptic feedback of virtual key press.
223 long[] mVirtualKeyVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700224
Amith Yamasanic33cb712010-02-10 15:21:49 -0800225 // Vibrator pattern for a short vibration.
226 long[] mKeyboardTapVibePattern;
227
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -0700228 // Vibrator pattern for a short vibration when tapping on an hour/minute tick of a Clock.
229 long[] mClockTickVibePattern;
230
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700231 // Vibrator pattern for haptic feedback during boot when safe mode is disabled.
232 long[] mSafeModeDisabledVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700233
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700234 // Vibrator pattern for haptic feedback during boot when safe mode is enabled.
235 long[] mSafeModeEnabledVibePattern;
Romain Guy8154cd32010-03-29 14:41:15 -0700236
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800237 /** If true, hitting shift & menu will broadcast Intent.ACTION_BUG_REPORT */
238 boolean mEnableShiftMenuBugReports = false;
Mike Lockwoodd747dc82011-09-13 16:28:22 -0400239
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800240 boolean mSafeMode;
241 WindowState mStatusBar = null;
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700242 int mStatusBarHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400243 WindowState mNavigationBar = null;
Daniel Sandler36412a72011-08-04 09:35:13 -0400244 boolean mHasNavigationBar = false;
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700245 boolean mCanHideNavigationBar = false;
Daniel Sandler4a066c52012-04-20 14:49:13 -0400246 boolean mNavigationBarCanMove = false; // can the navigation bar ever move to the side?
247 boolean mNavigationBarOnBottom = true; // is the navigation bar on the bottom *right now*?
248 int[] mNavigationBarHeightForRotation = new int[4];
249 int[] mNavigationBarWidthForRotation = new int[4];
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400250
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800251 WindowState mKeyguard = null;
Jim Miller5ecd8112013-01-09 18:50:26 -0800252 KeyguardServiceDelegate mKeyguardDelegate;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800253 GlobalActions mGlobalActions;
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700254 volatile boolean mPowerKeyHandled; // accessed from input reader and handler thread
255 boolean mPendingPowerKeyUpCanceled;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800256 Handler mHandler;
satok1bc0a492012-04-25 22:47:12 +0900257 WindowState mLastInputMethodWindow = null;
258 WindowState mLastInputMethodTargetWindow = null;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800259
Jeff Brown68b909d2011-12-07 16:36:01 -0800260 static final int RECENT_APPS_BEHAVIOR_SHOW_OR_DISMISS = 0;
261 static final int RECENT_APPS_BEHAVIOR_EXIT_TOUCH_MODE_AND_SHOW = 1;
Jeff Brown602ab322012-05-16 13:33:47 -0700262 static final int RECENT_APPS_BEHAVIOR_DISMISS = 2;
263 static final int RECENT_APPS_BEHAVIOR_DISMISS_AND_SWITCH = 3;
Jeff Brown68b909d2011-12-07 16:36:01 -0800264
265 RecentApplicationsDialog mRecentAppsDialog;
266 int mRecentAppsDialogHeldModifiers;
Jeff Browncf39bdf2012-05-18 14:41:19 -0700267 boolean mLanguageSwitchKeyPressed;
Jeff Brown68b909d2011-12-07 16:36:01 -0800268
Jeff Brown2e7760e2012-04-11 15:14:55 -0700269 int mLidState = LID_ABSENT;
Jeff Browndaa37532012-05-01 15:54:03 -0700270 boolean mHaveBuiltInKeyboard;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800271
Dianne Hackbornc777e072010-02-12 13:07:59 -0800272 boolean mSystemReady;
Dianne Hackbornba24e4d2011-09-01 11:17:06 -0700273 boolean mSystemBooted;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800274 boolean mHdmiPlugged;
Daniel Sandler6396c722013-04-16 20:19:09 -0400275 int mUiMode;
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700276 int mDockMode = Intent.EXTRA_DOCK_STATE_UNDOCKED;
Mike Lockwood1753f7f2009-08-24 14:49:07 -0700277 int mLidOpenRotation;
Mike Lockwood2d1efbd2009-09-16 12:15:53 -0400278 int mCarDockRotation;
279 int mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -0700280 int mUndockedHdmiRotation;
281 int mDemoHdmiRotation;
282 boolean mDemoHdmiRotationLock;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400283
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700284 // Default display does not rotate, apps that require non-default orientation will have to
285 // have the orientation emulated.
286 private boolean mForceDefaultOrientation = false;
287
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400288 int mUserRotationMode = WindowManagerPolicy.USER_ROTATION_FREE;
289 int mUserRotation = Surface.ROTATION_0;
Jeff Brown207673cd2012-06-05 17:47:11 -0700290 boolean mAccelerometerDefault;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400291
Jeff Brownbcdfc622014-03-06 19:13:04 -0800292 boolean mSupportAutoRotation;
Jeff Brownd3187e32011-09-21 19:26:44 -0700293 int mAllowAllRotations = -1;
Mike Lockwoode9867d22009-09-20 01:59:02 -0400294 boolean mCarDockEnablesAccelerometer;
295 boolean mDeskDockEnablesAccelerometer;
Dianne Hackborn2862fff2009-09-15 22:56:29 -0700296 int mLidKeyboardAccessibility;
297 int mLidNavigationAccessibility;
Jeff Brownc458ce92012-04-30 14:58:40 -0700298 boolean mLidControlsSleep;
Joe Onoratod208e702010-10-08 16:22:43 -0400299 int mLongPressOnPowerBehavior = -1;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -0700300 boolean mScreenOnEarly = false;
301 boolean mScreenOnFully = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800302 boolean mOrientationSensorEnabled = false;
303 int mCurrentAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800304 boolean mHasSoftInput = false;
Daniel Sandlerdd73ee42013-10-11 22:19:59 -0400305 boolean mTranslucentDecorEnabled = true;
Craig Mautner967212c2013-04-13 21:10:58 -0700306
Jeff Brown70825162012-03-28 17:27:48 -0700307 int mPointerLocationMode = 0; // guarded by mLock
Joe Onorato664644d2011-01-23 17:53:23 -0800308
309 // The last window we were told about in focusChanged.
310 WindowState mFocusedWindow;
Dianne Hackborne0f085d2011-11-30 18:41:15 -0800311 IApplicationToken mFocusedApp;
Joe Onorato664644d2011-01-23 17:53:23 -0800312
Jeff Brown70825162012-03-28 17:27:48 -0700313 PointerLocationView mPointerLocationView;
Jeff Brown32cbc38552011-12-01 14:01:49 -0800314
Dianne Hackbornc652de82013-02-15 16:32:56 -0800315 // The current size of the screen; really; extends into the overscan area of
316 // the screen and doesn't account for any system elements like the status bar.
317 int mOverscanScreenLeft, mOverscanScreenTop;
318 int mOverscanScreenWidth, mOverscanScreenHeight;
319 // The current visible size of the screen; really; (ir)regardless of whether the status
320 // bar can be hidden but not extending into the overscan area.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800321 int mUnrestrictedScreenLeft, mUnrestrictedScreenTop;
322 int mUnrestrictedScreenWidth, mUnrestrictedScreenHeight;
Dianne Hackborn313440842013-02-19 19:22:59 -0800323 // Like mOverscanScreen*, but allowed to move into the overscan region where appropriate.
324 int mRestrictedOverscanScreenLeft, mRestrictedOverscanScreenTop;
325 int mRestrictedOverscanScreenWidth, mRestrictedOverscanScreenHeight;
Dianne Hackborn82de1ae2010-10-28 11:28:39 -0700326 // The current size of the screen; these may be different than (0,0)-(dw,dh)
327 // if the status bar can't be hidden; in that case it effectively carves out
328 // that area of the display from all other windows.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800329 int mRestrictedScreenLeft, mRestrictedScreenTop;
330 int mRestrictedScreenWidth, mRestrictedScreenHeight;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700331 // During layout, the current screen borders accounting for any currently
332 // visible system UI elements.
333 int mSystemLeft, mSystemTop, mSystemRight, mSystemBottom;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700334 // For applications requesting stable content insets, these are them.
335 int mStableLeft, mStableTop, mStableRight, mStableBottom;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -0700336 // For applications requesting stable content insets but have also set the
337 // fullscreen window flag, these are the stable dimensions without the status bar.
338 int mStableFullscreenLeft, mStableFullscreenTop;
339 int mStableFullscreenRight, mStableFullscreenBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800340 // During layout, the current screen borders with all outer decoration
341 // (status bar, input method dock) accounted for.
342 int mCurLeft, mCurTop, mCurRight, mCurBottom;
343 // During layout, the frame in which content should be displayed
344 // to the user, accounting for all screen decoration except for any
345 // space they deem as available for other content. This is usually
346 // the same as mCur*, but may be larger if the screen decor has supplied
347 // content insets.
348 int mContentLeft, mContentTop, mContentRight, mContentBottom;
Dianne Hackborn8e11ef02010-11-18 19:47:42 -0800349 // During layout, the current screen borders along which input method
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800350 // windows are placed.
351 int mDockLeft, mDockTop, mDockRight, mDockBottom;
352 // During layout, the layer at which the doc window is placed.
353 int mDockLayer;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700354 // During layout, this is the layer of the status bar.
355 int mStatusBarLayer;
Dianne Hackborne26ab702011-10-16 13:21:33 -0700356 int mLastSystemUiFlags;
357 // Bits that we are in the process of clearing, so we want to prevent
358 // them from being set by applications until everything has been updated
359 // to have them clear.
360 int mResettingSystemUiFlags = 0;
361 // Bits that we are currently always keeping cleared.
362 int mForceClearedSystemUiFlags = 0;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -0800363 // What we last reported to system UI about whether the compatibility
364 // menu needs to be displayed.
365 boolean mLastFocusNeedsMenu = false;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700366
367 FakeWindow mHideNavFakeWindow = null;
368
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800369 static final Rect mTmpParentFrame = new Rect();
370 static final Rect mTmpDisplayFrame = new Rect();
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800371 static final Rect mTmpOverscanFrame = new Rect();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800372 static final Rect mTmpContentFrame = new Rect();
373 static final Rect mTmpVisibleFrame = new Rect();
John Spurlock46646232013-09-30 22:32:42 -0400374 static final Rect mTmpDecorFrame = new Rect();
Dianne Hackborn1f903c32011-09-13 19:18:06 -0700375 static final Rect mTmpNavigationFrame = new Rect();
Craig Mautner967212c2013-04-13 21:10:58 -0700376
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800377 WindowState mTopFullscreenOpaqueWindowState;
Craig Mautner2bc789b2014-03-19 19:48:38 -0700378 HashSet<IApplicationToken> mAppsToBeHidden = new HashSet<IApplicationToken>();
Joe Onorato93056472010-09-10 10:30:46 -0400379 boolean mTopIsFullscreen;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800380 boolean mForceStatusBar;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -0700381 boolean mForceStatusBarFromKeyguard;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700382 boolean mHideLockScreen;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -0800383 boolean mForcingShowNavBar;
384 int mForcingShowNavBarLayer;
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700385
386 // States of keyguard dismiss.
387 private static final int DISMISS_KEYGUARD_NONE = 0; // Keyguard not being dismissed.
388 private static final int DISMISS_KEYGUARD_START = 1; // Keyguard needs to be dismissed.
389 private static final int DISMISS_KEYGUARD_CONTINUE = 2; // Keyguard has been dismissed.
390 int mDismissKeyguard = DISMISS_KEYGUARD_NONE;
391
392 /** The window that is currently dismissing the keyguard. Dismissing the keyguard must only
393 * be done once per window. */
394 private WindowState mWinDismissingKeyguard;
395
Dianne Hackborn7ad44382012-10-18 17:46:00 -0700396 boolean mShowingLockscreen;
397 boolean mShowingDream;
398 boolean mDreamingLockscreen;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800399 boolean mHomePressed;
Jeff Browncaca8812013-05-09 13:34:33 -0700400 boolean mHomeConsumed;
401 boolean mHomeDoubleTapPending;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800402 Intent mHomeIntent;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700403 Intent mCarDockIntent;
404 Intent mDeskDockIntent;
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700405 boolean mSearchKeyShortcutPending;
406 boolean mConsumeSearchKeyUp;
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700407 boolean mAssistKeyLongPressed;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800408
Mike Lockwood28569302010-01-28 11:54:40 -0500409 // support for activating the lock screen while the screen is on
410 boolean mAllowLockscreenWhenOn;
411 int mLockScreenTimeout;
412 boolean mLockScreenTimerActive;
413
David Brownbaf8d092010-03-08 21:52:59 -0800414 // Behavior of ENDCALL Button. (See Settings.System.END_BUTTON_BEHAVIOR.)
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800415 int mEndcallBehavior;
David Brownbaf8d092010-03-08 21:52:59 -0800416
417 // Behavior of POWER button while in-call and screen on.
418 // (See Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR.)
419 int mIncallPowerBehavior;
420
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700421 Display mDisplay;
422
Dianne Hackborn9d132642011-04-21 17:26:39 -0700423 int mLandscapeRotation = 0; // default landscape rotation
424 int mSeascapeRotation = 0; // "other" landscape rotation, 180 degrees from mLandscapeRotation
425 int mPortraitRotation = 0; // default portrait rotation
426 int mUpsideDownRotation = 0; // "other" portrait rotation
Mitsuru Oshima831d0d92009-06-16 18:27:18 -0700427
Dianne Hackbornc652de82013-02-15 16:32:56 -0800428 int mOverscanLeft = 0;
429 int mOverscanTop = 0;
430 int mOverscanRight = 0;
431 int mOverscanBottom = 0;
432
Joe Onorato46b0d682010-11-22 17:37:27 -0800433 // What we do when the user long presses on home
Jeff Browncaca8812013-05-09 13:34:33 -0700434 private int mLongPressOnHomeBehavior;
435
436 // What we do when the user double-taps on home
437 private int mDoubleTapOnHomeBehavior;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800438
Winson Chung9112ec32011-06-27 13:15:32 -0700439 // Screenshot trigger states
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700440 // Time to volume and power must be pressed within this interval of each other.
441 private static final long SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS = 150;
Winson Chung1cea2f32012-10-08 20:42:01 -0700442 // Increase the chord delay when taking a screenshot from the keyguard
443 private static final float KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER = 2.5f;
Christopher Tatee90585f2012-03-05 18:56:25 -0800444 private boolean mScreenshotChordEnabled;
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700445 private boolean mVolumeDownKeyTriggered;
446 private long mVolumeDownKeyTime;
447 private boolean mVolumeDownKeyConsumedByScreenshotChord;
448 private boolean mVolumeUpKeyTriggered;
449 private boolean mPowerKeyTriggered;
450 private long mPowerKeyTime;
Winson Chung9112ec32011-06-27 13:15:32 -0700451
Michael Wrightb854e242013-02-05 17:54:02 -0800452 /* The number of steps between min and max brightness */
453 private static final int BRIGHTNESS_STEPS = 10;
454
Christopher Tate5e08af02012-09-21 17:17:22 -0700455 SettingsObserver mSettingsObserver;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800456 ShortcutManager mShortcutManager;
457 PowerManager.WakeLock mBroadcastWakeLock;
Jeff Brown40013652012-05-16 21:22:36 -0700458 boolean mHavePendingMediaKeyRepeatWithWakeLock;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800459
Craig Mautnerd625ab22013-09-06 13:40:31 -0700460 private int mCurrentUserId;
461
Justin Kohd378ad72013-04-01 12:18:26 -0700462 // Maps global key codes to the components that will handle them.
463 private GlobalKeyManager mGlobalKeyManager;
464
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700465 // Fallback actions by key code.
466 private final SparseArray<KeyCharacterMap.FallbackAction> mFallbackActions =
467 new SparseArray<KeyCharacterMap.FallbackAction>();
Jeff Brown49ed71d2010-12-06 17:13:33 -0800468
Jeff Brown70825162012-03-28 17:27:48 -0700469 private static final int MSG_ENABLE_POINTER_LOCATION = 1;
470 private static final int MSG_DISABLE_POINTER_LOCATION = 2;
Jeff Brown40013652012-05-16 21:22:36 -0700471 private static final int MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK = 3;
472 private static final int MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK = 4;
Jeff Brown70825162012-03-28 17:27:48 -0700473
474 private class PolicyHandler extends Handler {
475 @Override
476 public void handleMessage(Message msg) {
477 switch (msg.what) {
478 case MSG_ENABLE_POINTER_LOCATION:
479 enablePointerLocation();
480 break;
481 case MSG_DISABLE_POINTER_LOCATION:
482 disablePointerLocation();
483 break;
Jeff Brown40013652012-05-16 21:22:36 -0700484 case MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK:
485 dispatchMediaKeyWithWakeLock((KeyEvent)msg.obj);
486 break;
487 case MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK:
488 dispatchMediaKeyRepeatWithWakeLock((KeyEvent)msg.obj);
489 break;
Jeff Brown70825162012-03-28 17:27:48 -0700490 }
491 }
492 }
493
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800494 private UEventObserver mHDMIObserver = new UEventObserver() {
495 @Override
496 public void onUEvent(UEventObserver.UEvent event) {
497 setHdmiPlugged("1".equals(event.get("SWITCH_STATE")));
498 }
499 };
500
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800501 class SettingsObserver extends ContentObserver {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800502 SettingsObserver(Handler handler) {
503 super(handler);
504 }
David Brownbaf8d092010-03-08 21:52:59 -0800505
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800506 void observe() {
Christopher Tate5e08af02012-09-21 17:17:22 -0700507 // Observe all users' changes
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800508 ContentResolver resolver = mContext.getContentResolver();
509 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700510 Settings.System.END_BUTTON_BEHAVIOR), false, this,
511 UserHandle.USER_ALL);
David Brownbaf8d092010-03-08 21:52:59 -0800512 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700513 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR), false, this,
514 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800515 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700516 Settings.System.ACCELEROMETER_ROTATION), false, this,
517 UserHandle.USER_ALL);
Mike Lockwood28569302010-01-28 11:54:40 -0500518 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700519 Settings.System.USER_ROTATION), false, this,
520 UserHandle.USER_ALL);
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400521 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700522 Settings.System.SCREEN_OFF_TIMEOUT), false, this,
523 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800524 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700525 Settings.System.POINTER_LOCATION), false, this,
526 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800527 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700528 Settings.Secure.DEFAULT_INPUT_METHOD), false, this,
529 UserHandle.USER_ALL);
John Spurlockd9b70bd2014-02-06 17:02:44 -0500530 resolver.registerContentObserver(Settings.Secure.getUriFor(
John Spurlockf1a36642013-10-12 17:50:42 -0400531 Settings.Secure.IMMERSIVE_MODE_CONFIRMATIONS), false, this,
Christopher Tate5e08af02012-09-21 17:17:22 -0700532 UserHandle.USER_ALL);
John Spurlockc6d1c602014-01-17 15:22:06 -0500533 resolver.registerContentObserver(Settings.Global.getUriFor(
534 Settings.Global.POLICY_CONTROL), false, this,
535 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800536 updateSettings();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800537 }
538
539 @Override public void onChange(boolean selfChange) {
Dianne Hackbornc777e072010-02-12 13:07:59 -0800540 updateSettings();
Jeff Brown01a98dd2011-09-20 15:08:29 -0700541 updateRotation(false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800542 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800543 }
Craig Mautner967212c2013-04-13 21:10:58 -0700544
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800545 class MyOrientationListener extends WindowOrientationListener {
Craig Mautnereee29c42013-01-17 14:44:34 -0800546 MyOrientationListener(Context context, Handler handler) {
547 super(context, handler);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800548 }
Craig Mautner967212c2013-04-13 21:10:58 -0700549
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800550 @Override
Jeff Brownc0347aa2011-09-23 17:26:09 -0700551 public void onProposedRotationChanged(int rotation) {
Craig Mautnereda67292013-04-28 13:50:14 -0700552 if (localLOGV) Slog.v(TAG, "onProposedRotationChanged, rotation=" + rotation);
Jeff Brown01a98dd2011-09-20 15:08:29 -0700553 updateRotation(false);
554 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800555 }
556 MyOrientationListener mOrientationListener;
557
John Spurlock27735a42013-08-14 17:57:38 -0400558 private final BarController mStatusBarController = new BarController("StatusBar",
John Spurlock5b9145b2013-08-20 15:13:47 -0400559 View.STATUS_BAR_TRANSIENT,
560 View.STATUS_BAR_UNHIDE,
John Spurlockbd957402013-10-03 11:38:39 -0400561 View.STATUS_BAR_TRANSLUCENT,
562 StatusBarManager.WINDOW_STATUS_BAR,
563 WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
John Spurlock5b9145b2013-08-20 15:13:47 -0400564
John Spurlock27735a42013-08-14 17:57:38 -0400565 private final BarController mNavigationBarController = new BarController("NavigationBar",
John Spurlock5b9145b2013-08-20 15:13:47 -0400566 View.NAVIGATION_BAR_TRANSIENT,
567 View.NAVIGATION_BAR_UNHIDE,
John Spurlockbd957402013-10-03 11:38:39 -0400568 View.NAVIGATION_BAR_TRANSLUCENT,
569 StatusBarManager.WINDOW_NAVIGATION_BAR,
570 WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
John Spurlock5b9145b2013-08-20 15:13:47 -0400571
John Spurlockf1a36642013-10-12 17:50:42 -0400572 private ImmersiveModeConfirmation mImmersiveModeConfirmation;
John Spurlock32beb2c2013-03-11 10:16:47 -0400573
Craig Mautner037aa8d2013-06-07 10:35:44 -0700574 private SystemGesturesPointerEventListener mSystemGestures;
John Spurlock32beb2c2013-03-11 10:16:47 -0400575
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700576 IStatusBarService getStatusBarService() {
577 synchronized (mServiceAquireLock) {
578 if (mStatusBarService == null) {
579 mStatusBarService = IStatusBarService.Stub.asInterface(
580 ServiceManager.getService("statusbar"));
581 }
582 return mStatusBarService;
583 }
584 }
585
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700586 /*
587 * We always let the sensor be switched on by default except when
588 * the user has explicitly disabled sensor based rotation or when the
589 * screen is switched off.
590 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700591 boolean needSensorRunningLp() {
Jeff Brownbcdfc622014-03-06 19:13:04 -0800592 if (mSupportAutoRotation) {
593 if (mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
594 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
595 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT
596 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) {
597 // If the application has explicitly requested to follow the
598 // orientation, then we need to turn the sensor on.
599 return true;
600 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800601 }
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700602 if ((mCarDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_CAR) ||
Jeff Brown1a693182011-11-08 14:44:16 -0800603 (mDeskDockEnablesAccelerometer && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
604 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
605 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK))) {
Mike Lockwoode9867d22009-09-20 01:59:02 -0400606 // enable accelerometer if we are docked in a dock that enables accelerometer
607 // orientation management,
608 return true;
609 }
Jeff Brown207673cd2012-06-05 17:47:11 -0700610 if (mUserRotationMode == USER_ROTATION_LOCKED) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800611 // If the setting for using the sensor by default is enabled, then
612 // we will always leave it on. Note that the user could go to
613 // a window that forces an orientation that does not use the
614 // sensor and in theory we could turn it off... however, when next
615 // turning it on we won't have a good value for the current
616 // orientation for a little bit, which can cause orientation
617 // changes to lag, so we'd like to keep it always on. (It will
618 // still be turned off when the screen is off.)
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700619 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800620 }
Jeff Brownbcdfc622014-03-06 19:13:04 -0800621 return mSupportAutoRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800622 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700623
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800624 /*
625 * Various use cases for invoking this function
626 * screen turning off, should always disable listeners if already enabled
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700627 * screen turned on and current app has sensor based orientation, enable listeners
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800628 * if not already enabled
629 * screen turned on and current app does not have sensor orientation, disable listeners if
630 * already enabled
631 * screen turning on and current app has sensor based orientation, enable listeners if needed
632 * screen turning on and current app has nosensor based orientation, do nothing
633 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700634 void updateOrientationListenerLp() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800635 if (!mOrientationListener.canDetectOrientation()) {
636 // If sensor is turned off or nonexistent for some reason
637 return;
638 }
639 //Could have been invoked due to screen turning on or off or
640 //change of the currently visible window's orientation
Craig Mautnereda67292013-04-28 13:50:14 -0700641 if (localLOGV) Slog.v(TAG, "Screen status="+mScreenOnEarly+
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800642 ", current orientation="+mCurrentAppOrientation+
643 ", SensorEnabled="+mOrientationSensorEnabled);
644 boolean disable = true;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -0700645 if (mScreenOnEarly) {
The Android Open Source Project0727d222009-03-11 12:11:58 -0700646 if (needSensorRunningLp()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800647 disable = false;
648 //enable listener if not already enabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700649 if (!mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800650 mOrientationListener.enable();
Craig Mautnereda67292013-04-28 13:50:14 -0700651 if(localLOGV) Slog.v(TAG, "Enabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800652 mOrientationSensorEnabled = true;
653 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700654 }
655 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800656 //check if sensors need to be disabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700657 if (disable && mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800658 mOrientationListener.disable();
Craig Mautnereda67292013-04-28 13:50:14 -0700659 if(localLOGV) Slog.v(TAG, "Disabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800660 mOrientationSensorEnabled = false;
661 }
662 }
663
Jeff Brown4d396052010-10-29 21:50:21 -0700664 private void interceptPowerKeyDown(boolean handled) {
665 mPowerKeyHandled = handled;
666 if (!handled) {
667 mHandler.postDelayed(mPowerLongPress, ViewConfiguration.getGlobalActionKeyTimeout());
668 }
669 }
670
671 private boolean interceptPowerKeyUp(boolean canceled) {
672 if (!mPowerKeyHandled) {
673 mHandler.removeCallbacks(mPowerLongPress);
674 return !canceled;
Jeff Brown4d396052010-10-29 21:50:21 -0700675 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700676 return false;
677 }
678
679 private void cancelPendingPowerKeyAction() {
680 if (!mPowerKeyHandled) {
681 mHandler.removeCallbacks(mPowerLongPress);
682 }
Jeff Brownff204712011-10-25 21:27:54 -0700683 if (mPowerKeyTriggered) {
684 mPendingPowerKeyUpCanceled = true;
685 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700686 }
687
688 private void interceptScreenshotChord() {
Christopher Tatee90585f2012-03-05 18:56:25 -0800689 if (mScreenshotChordEnabled
690 && mVolumeDownKeyTriggered && mPowerKeyTriggered && !mVolumeUpKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700691 final long now = SystemClock.uptimeMillis();
692 if (now <= mVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS
693 && now <= mPowerKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) {
694 mVolumeDownKeyConsumedByScreenshotChord = true;
695 cancelPendingPowerKeyAction();
696
Jeff Sharkey2991fa32012-12-05 18:06:43 -0800697 mHandler.postDelayed(mScreenshotRunnable, getScreenshotChordLongPressDelay());
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700698 }
699 }
700 }
701
Winson Chung1cea2f32012-10-08 20:42:01 -0700702 private long getScreenshotChordLongPressDelay() {
Jim Miller5ecd8112013-01-09 18:50:26 -0800703 if (mKeyguardDelegate.isShowing()) {
Winson Chung1cea2f32012-10-08 20:42:01 -0700704 // Double the time it takes to take a screenshot from the keyguard
705 return (long) (KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER *
706 ViewConfiguration.getGlobalActionKeyTimeout());
Winson Chung1cea2f32012-10-08 20:42:01 -0700707 }
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800708 return ViewConfiguration.getGlobalActionKeyTimeout();
Winson Chung1cea2f32012-10-08 20:42:01 -0700709 }
710
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700711 private void cancelPendingScreenshotChordAction() {
Jeff Sharkey2991fa32012-12-05 18:06:43 -0800712 mHandler.removeCallbacks(mScreenshotRunnable);
Jeff Brown4d396052010-10-29 21:50:21 -0700713 }
714
715 private final Runnable mPowerLongPress = new Runnable() {
Craig Mautnerf1b67412012-09-19 13:18:29 -0700716 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800717 public void run() {
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700718 // The context isn't read
719 if (mLongPressOnPowerBehavior < 0) {
Jeff Brown850c5b72012-10-01 15:17:22 -0700720 mLongPressOnPowerBehavior = mContext.getResources().getInteger(
721 com.android.internal.R.integer.config_longPressOnPowerBehavior);
Joe Onoratod208e702010-10-08 16:22:43 -0400722 }
Jeff Brown850c5b72012-10-01 15:17:22 -0700723 int resolvedBehavior = mLongPressOnPowerBehavior;
724 if (FactoryTest.isLongPressOnPowerOffEnabled()) {
725 resolvedBehavior = LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM;
726 }
727
728 switch (resolvedBehavior) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700729 case LONG_PRESS_POWER_NOTHING:
730 break;
731 case LONG_PRESS_POWER_GLOBAL_ACTIONS:
732 mPowerKeyHandled = true;
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -0700733 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
734 performAuditoryFeedbackForAccessibilityIfNeed();
735 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700736 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
737 showGlobalActionsDialog();
738 break;
739 case LONG_PRESS_POWER_SHUT_OFF:
Jeff Brown9a538ee2012-08-20 14:56:57 -0700740 case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM:
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700741 mPowerKeyHandled = true;
742 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
743 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
Jeff Brown850c5b72012-10-01 15:17:22 -0700744 mWindowManagerFuncs.shutdown(resolvedBehavior == LONG_PRESS_POWER_SHUT_OFF);
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700745 break;
746 }
747 }
748 };
749
Jeff Sharkey2991fa32012-12-05 18:06:43 -0800750 private final Runnable mScreenshotRunnable = new Runnable() {
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800751 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700752 public void run() {
753 takeScreenshot();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800754 }
755 };
756
757 void showGlobalActionsDialog() {
758 if (mGlobalActions == null) {
Jeff Brown7304c342012-05-11 18:42:42 -0700759 mGlobalActions = new GlobalActions(mContext, mWindowManagerFuncs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800760 }
Mike Lockwood3a74bd32011-08-12 13:55:22 -0700761 final boolean keyguardShowing = keyguardIsShowingTq();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800762 mGlobalActions.showDialog(keyguardShowing, isDeviceProvisioned());
763 if (keyguardShowing) {
764 // since it took two seconds of long press to bring this up,
765 // poke the wake lock so they have some time to see the dialog.
Jim Miller25190572013-02-28 17:36:24 -0800766 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800767 }
768 }
769
770 boolean isDeviceProvisioned() {
Jeff Brownbf6f6f92012-09-25 15:03:20 -0700771 return Settings.Global.getInt(
772 mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800773 }
774
Patrick Dubroyece94522011-02-23 18:35:01 -0800775 private void handleLongPressOnHome() {
Joe Onorato46b0d682010-11-22 17:37:27 -0800776 if (mLongPressOnHomeBehavior != LONG_PRESS_HOME_NOTHING) {
Jeff Browncaca8812013-05-09 13:34:33 -0700777 mHomeConsumed = true;
Joe Onorato46b0d682010-11-22 17:37:27 -0800778 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
Patrick Dubroyece94522011-02-23 18:35:01 -0800779
Jeff Browncaca8812013-05-09 13:34:33 -0700780 if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI) {
781 toggleRecentApps();
782 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_ASSIST) {
783 launchAssistAction();
Jim Millere6ad1a82010-08-20 19:25:39 -0700784 }
785 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800786 }
Patrick Dubroyece94522011-02-23 18:35:01 -0800787
Jeff Browncaca8812013-05-09 13:34:33 -0700788 private void handleDoubleTapOnHome() {
789 if (mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
790 mHomeConsumed = true;
791 toggleRecentApps();
792 }
793 }
794
795 private final Runnable mHomeDoubleTapTimeoutRunnable = new Runnable() {
796 @Override
797 public void run() {
798 if (mHomeDoubleTapPending) {
799 mHomeDoubleTapPending = false;
800 launchHomeFromHotKey();
801 }
802 }
803 };
804
Patrick Dubroyece94522011-02-23 18:35:01 -0800805 /**
Jeff Brown68b909d2011-12-07 16:36:01 -0800806 * Create (if necessary) and show or dismiss the recent apps dialog according
807 * according to the requested behavior.
Patrick Dubroyece94522011-02-23 18:35:01 -0800808 */
Jeff Brown68b909d2011-12-07 16:36:01 -0800809 void showOrHideRecentAppsDialog(final int behavior) {
Jeff Brownda3d5a92011-03-29 15:11:34 -0700810 mHandler.post(new Runnable() {
811 @Override
812 public void run() {
813 if (mRecentAppsDialog == null) {
Jeff Brown54875002011-04-06 15:33:01 -0700814 mRecentAppsDialog = new RecentApplicationsDialog(mContext);
Jeff Brownda3d5a92011-03-29 15:11:34 -0700815 }
Jeff Brown54875002011-04-06 15:33:01 -0700816 if (mRecentAppsDialog.isShowing()) {
Jeff Brown68b909d2011-12-07 16:36:01 -0800817 switch (behavior) {
818 case RECENT_APPS_BEHAVIOR_SHOW_OR_DISMISS:
Jeff Brown602ab322012-05-16 13:33:47 -0700819 case RECENT_APPS_BEHAVIOR_DISMISS:
Jeff Brown68b909d2011-12-07 16:36:01 -0800820 mRecentAppsDialog.dismiss();
821 break;
822 case RECENT_APPS_BEHAVIOR_DISMISS_AND_SWITCH:
823 mRecentAppsDialog.dismissAndSwitch();
824 break;
825 case RECENT_APPS_BEHAVIOR_EXIT_TOUCH_MODE_AND_SHOW:
826 default:
827 break;
Jeff Brown54875002011-04-06 15:33:01 -0700828 }
829 } else {
Jeff Brown68b909d2011-12-07 16:36:01 -0800830 switch (behavior) {
831 case RECENT_APPS_BEHAVIOR_SHOW_OR_DISMISS:
832 mRecentAppsDialog.show();
833 break;
834 case RECENT_APPS_BEHAVIOR_EXIT_TOUCH_MODE_AND_SHOW:
835 try {
836 mWindowManager.setInTouchMode(false);
837 } catch (RemoteException e) {
838 }
839 mRecentAppsDialog.show();
840 break;
Jeff Brown602ab322012-05-16 13:33:47 -0700841 case RECENT_APPS_BEHAVIOR_DISMISS:
Jeff Brown68b909d2011-12-07 16:36:01 -0800842 case RECENT_APPS_BEHAVIOR_DISMISS_AND_SWITCH:
843 default:
844 break;
845 }
Jeff Brown54875002011-04-06 15:33:01 -0700846 }
Jeff Brownda3d5a92011-03-29 15:11:34 -0700847 }
848 });
Patrick Dubroyece94522011-02-23 18:35:01 -0800849 }
Jeff Brownda3d5a92011-03-29 15:11:34 -0700850
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800851 /** {@inheritDoc} */
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800852 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800853 public void init(Context context, IWindowManager windowManager,
Jeff Brown96307042012-07-27 15:51:34 -0700854 WindowManagerFuncs windowManagerFuncs) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800855 mContext = context;
856 mWindowManager = windowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700857 mWindowManagerFuncs = windowManagerFuncs;
Jeff Brown70825162012-03-28 17:27:48 -0700858 mHandler = new PolicyHandler();
Craig Mautnereee29c42013-01-17 14:44:34 -0800859 mOrientationListener = new MyOrientationListener(mContext, mHandler);
Jeff Brownc0347aa2011-09-23 17:26:09 -0700860 try {
861 mOrientationListener.setCurrentRotation(windowManager.getRotation());
862 } catch (RemoteException ex) { }
Christopher Tate5e08af02012-09-21 17:17:22 -0700863 mSettingsObserver = new SettingsObserver(mHandler);
864 mSettingsObserver.observe();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800865 mShortcutManager = new ShortcutManager(context, mHandler);
866 mShortcutManager.observe();
Daniel Sandler6396c722013-04-16 20:19:09 -0400867 mUiMode = context.getResources().getInteger(
868 com.android.internal.R.integer.config_defaultUiModeType);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800869 mHomeIntent = new Intent(Intent.ACTION_MAIN, null);
870 mHomeIntent.addCategory(Intent.CATEGORY_HOME);
871 mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
872 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700873 mCarDockIntent = new Intent(Intent.ACTION_MAIN, null);
874 mCarDockIntent.addCategory(Intent.CATEGORY_CAR_DOCK);
875 mCarDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
876 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
877 mDeskDockIntent = new Intent(Intent.ACTION_MAIN, null);
878 mDeskDockIntent.addCategory(Intent.CATEGORY_DESK_DOCK);
879 mDeskDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
880 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Jim Millere6ad1a82010-08-20 19:25:39 -0700881
Jeff Brown96307042012-07-27 15:51:34 -0700882 mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
883 mBroadcastWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800884 "PhoneWindowManager.mBroadcastWakeLock");
885 mEnableShiftMenuBugReports = "1".equals(SystemProperties.get("ro.debuggable"));
Jeff Brownbcdfc622014-03-06 19:13:04 -0800886 mSupportAutoRotation = mContext.getResources().getBoolean(
887 com.android.internal.R.bool.config_supportAutoRotation);
Dianne Hackborn2862fff2009-09-15 22:56:29 -0700888 mLidOpenRotation = readRotation(
Mike Lockwood2d1efbd2009-09-16 12:15:53 -0400889 com.android.internal.R.integer.config_lidOpenRotation);
890 mCarDockRotation = readRotation(
891 com.android.internal.R.integer.config_carDockRotation);
892 mDeskDockRotation = readRotation(
893 com.android.internal.R.integer.config_deskDockRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -0700894 mUndockedHdmiRotation = readRotation(
895 com.android.internal.R.integer.config_undockedHdmiRotation);
Mike Lockwoode9867d22009-09-20 01:59:02 -0400896 mCarDockEnablesAccelerometer = mContext.getResources().getBoolean(
897 com.android.internal.R.bool.config_carDockEnablesAccelerometer);
898 mDeskDockEnablesAccelerometer = mContext.getResources().getBoolean(
899 com.android.internal.R.bool.config_deskDockEnablesAccelerometer);
Dianne Hackborn2862fff2009-09-15 22:56:29 -0700900 mLidKeyboardAccessibility = mContext.getResources().getInteger(
901 com.android.internal.R.integer.config_lidKeyboardAccessibility);
902 mLidNavigationAccessibility = mContext.getResources().getInteger(
903 com.android.internal.R.integer.config_lidNavigationAccessibility);
Jeff Brownc458ce92012-04-30 14:58:40 -0700904 mLidControlsSleep = mContext.getResources().getBoolean(
905 com.android.internal.R.bool.config_lidControlsSleep);
Daniel Sandlerdd73ee42013-10-11 22:19:59 -0400906 mTranslucentDecorEnabled = mContext.getResources().getBoolean(
907 com.android.internal.R.bool.config_enableTranslucentDecor);
Jeff Brownf71343d2013-05-31 17:59:11 -0700908 readConfigurationDependentBehaviors();
Jeff Browncaca8812013-05-09 13:34:33 -0700909
Svetoslav8e3feb12014-02-24 13:46:47 -0800910 mAccessibilityManager = (AccessibilityManager) context.getSystemService(
911 Context.ACCESSIBILITY_SERVICE);
912
Mike Lockwood1753f7f2009-08-24 14:49:07 -0700913 // register for dock events
Dianne Hackborn78968392010-03-04 20:47:56 -0800914 IntentFilter filter = new IntentFilter();
915 filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE);
916 filter.addAction(UiModeManager.ACTION_EXIT_CAR_MODE);
917 filter.addAction(UiModeManager.ACTION_ENTER_DESK_MODE);
918 filter.addAction(UiModeManager.ACTION_EXIT_DESK_MODE);
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700919 filter.addAction(Intent.ACTION_DOCK_EVENT);
920 Intent intent = context.registerReceiver(mDockReceiver, filter);
921 if (intent != null) {
922 // Retrieve current sticky dock event broadcast.
923 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
924 Intent.EXTRA_DOCK_STATE_UNDOCKED);
925 }
Daniel Sandler7e37df52011-11-16 22:08:23 -0800926
Jeff Brown6aaf2952012-10-05 16:01:08 -0700927 // register for dream-related broadcasts
928 filter = new IntentFilter();
929 filter.addAction(Intent.ACTION_DREAMING_STARTED);
930 filter.addAction(Intent.ACTION_DREAMING_STOPPED);
931 context.registerReceiver(mDreamReceiver, filter);
932
Christopher Tate5e08af02012-09-21 17:17:22 -0700933 // register for multiuser-relevant broadcasts
934 filter = new IntentFilter(Intent.ACTION_USER_SWITCHED);
935 context.registerReceiver(mMultiuserReceiver, filter);
936
John Spurlock57306e62013-04-22 09:48:49 -0400937 // monitor for system gestures
Craig Mautner037aa8d2013-06-07 10:35:44 -0700938 mSystemGestures = new SystemGesturesPointerEventListener(context,
939 new SystemGesturesPointerEventListener.Callbacks() {
John Spurlock57306e62013-04-22 09:48:49 -0400940 @Override
941 public void onSwipeFromTop() {
John Spurlock04db1762013-05-13 12:46:41 -0400942 if (mStatusBar != null) {
John Spurlocke1f366f2013-08-05 12:22:40 -0400943 requestTransientBars(mStatusBar);
John Spurlock04db1762013-05-13 12:46:41 -0400944 }
John Spurlockad3e6cb2013-04-30 08:47:43 -0400945 }
946 @Override
947 public void onSwipeFromBottom() {
John Spurlock04db1762013-05-13 12:46:41 -0400948 if (mNavigationBar != null && mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -0400949 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -0400950 }
951 }
952 @Override
953 public void onSwipeFromRight() {
John Spurlock04db1762013-05-13 12:46:41 -0400954 if (mNavigationBar != null && !mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -0400955 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -0400956 }
957 }
958 @Override
959 public void onDebug() {
John Spurlockd67ec252013-09-05 11:31:54 -0400960 // no-op
John Spurlockad3e6cb2013-04-30 08:47:43 -0400961 }
962 });
John Spurlockf1a36642013-10-12 17:50:42 -0400963 mImmersiveModeConfirmation = new ImmersiveModeConfirmation(mContext);
Craig Mautner037aa8d2013-06-07 10:35:44 -0700964 mWindowManagerFuncs.registerPointerEventListener(mSystemGestures);
John Spurlock32beb2c2013-03-11 10:16:47 -0400965
Jeff Brownc2346132012-04-13 01:55:38 -0700966 mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700967 mLongPressVibePattern = getLongIntArray(mContext.getResources(),
968 com.android.internal.R.array.config_longPressVibePattern);
969 mVirtualKeyVibePattern = getLongIntArray(mContext.getResources(),
970 com.android.internal.R.array.config_virtualKeyVibePattern);
Amith Yamasanic33cb712010-02-10 15:21:49 -0800971 mKeyboardTapVibePattern = getLongIntArray(mContext.getResources(),
972 com.android.internal.R.array.config_keyboardTapVibePattern);
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -0700973 mClockTickVibePattern = getLongIntArray(mContext.getResources(),
974 com.android.internal.R.array.config_clockTickVibePattern);
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700975 mSafeModeDisabledVibePattern = getLongIntArray(mContext.getResources(),
976 com.android.internal.R.array.config_safeModeDisabledVibePattern);
977 mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(),
978 com.android.internal.R.array.config_safeModeEnabledVibePattern);
Daniel Sandler40427442010-07-16 11:44:52 -0400979
Christopher Tatee90585f2012-03-05 18:56:25 -0800980 mScreenshotChordEnabled = mContext.getResources().getBoolean(
981 com.android.internal.R.bool.config_enableScreenshotChord);
982
Justin Kohd378ad72013-04-01 12:18:26 -0700983 mGlobalKeyManager = new GlobalKeyManager(mContext);
984
Joe Onoratoea495d42011-04-06 11:41:11 -0700985 // Controls rotation and the like.
986 initializeHdmiState();
Dianne Hackborn40011092011-09-22 13:37:48 -0700987
988 // Match current screen state.
989 if (mPowerManager.isScreenOn()) {
990 screenTurningOn(null);
991 } else {
992 screenTurnedOff(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
993 }
Mike Lockwood1753f7f2009-08-24 14:49:07 -0700994 }
995
Jeff Brownf71343d2013-05-31 17:59:11 -0700996 /**
997 * Read values from config.xml that may be overridden depending on
998 * the configuration of the device.
999 * eg. Disable long press on home goes to recents on sw600dp.
1000 */
1001 private void readConfigurationDependentBehaviors() {
1002 mLongPressOnHomeBehavior = mContext.getResources().getInteger(
1003 com.android.internal.R.integer.config_longPressOnHomeBehavior);
1004 if (mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING ||
1005 mLongPressOnHomeBehavior > LONG_PRESS_HOME_ASSIST) {
1006 mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1007 }
1008
1009 mDoubleTapOnHomeBehavior = mContext.getResources().getInteger(
1010 com.android.internal.R.integer.config_doubleTapOnHomeBehavior);
1011 if (mDoubleTapOnHomeBehavior < DOUBLE_TAP_HOME_NOTHING ||
1012 mDoubleTapOnHomeBehavior > DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1013 mDoubleTapOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1014 }
1015 }
1016
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001017 @Override
Dianne Hackborndde331c2012-08-03 14:01:57 -07001018 public void setInitialDisplaySize(Display display, int width, int height, int density) {
Jeff Brownef981a42013-08-07 14:13:37 -07001019 // This method might be called before the policy has been fully initialized
1020 // or for other displays we don't care about.
1021 if (mContext == null || display.getDisplayId() != Display.DEFAULT_DISPLAY) {
1022 return;
Dianne Hackbornc652de82013-02-15 16:32:56 -08001023 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001024 mDisplay = display;
1025
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001026 final Resources res = mContext.getResources();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001027 int shortSize, longSize;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001028 if (width > height) {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001029 shortSize = height;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001030 longSize = width;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001031 mLandscapeRotation = Surface.ROTATION_0;
1032 mSeascapeRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001033 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001034 mPortraitRotation = Surface.ROTATION_90;
1035 mUpsideDownRotation = Surface.ROTATION_270;
1036 } else {
1037 mPortraitRotation = Surface.ROTATION_270;
1038 mUpsideDownRotation = Surface.ROTATION_90;
1039 }
1040 } else {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001041 shortSize = width;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001042 longSize = height;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001043 mPortraitRotation = Surface.ROTATION_0;
1044 mUpsideDownRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001045 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001046 mLandscapeRotation = Surface.ROTATION_270;
1047 mSeascapeRotation = Surface.ROTATION_90;
1048 } else {
1049 mLandscapeRotation = Surface.ROTATION_90;
1050 mSeascapeRotation = Surface.ROTATION_270;
1051 }
1052 }
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001053
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001054 mStatusBarHeight =
1055 res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001056
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001057 // Height of the navigation bar when presented horizontally at bottom
1058 mNavigationBarHeightForRotation[mPortraitRotation] =
1059 mNavigationBarHeightForRotation[mUpsideDownRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001060 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_height);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001061 mNavigationBarHeightForRotation[mLandscapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001062 mNavigationBarHeightForRotation[mSeascapeRotation] = res.getDimensionPixelSize(
1063 com.android.internal.R.dimen.navigation_bar_height_landscape);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001064
1065 // Width of the navigation bar when presented vertically along one side
1066 mNavigationBarWidthForRotation[mPortraitRotation] =
1067 mNavigationBarWidthForRotation[mUpsideDownRotation] =
1068 mNavigationBarWidthForRotation[mLandscapeRotation] =
1069 mNavigationBarWidthForRotation[mSeascapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001070 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_width);
Daniel Sandler4a066c52012-04-20 14:49:13 -04001071
1072 // SystemUI (status bar) layout policy
Dianne Hackborndde331c2012-08-03 14:01:57 -07001073 int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / density;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001074 int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / density;
Daniel Sandler4a066c52012-04-20 14:49:13 -04001075
Craig Mautnerd4ec33242013-07-22 10:37:43 -07001076 // Allow the navigation bar to move on small devices (phones).
1077 mNavigationBarCanMove = shortSizeDp < 600;
Daniel Sandler36412a72011-08-04 09:35:13 -04001078
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001079 mHasNavigationBar = res.getBoolean(com.android.internal.R.bool.config_showNavigationBar);
John Spurlock80f00c12013-06-13 11:10:51 -04001080 // Allow a system property to override this. Used by the emulator.
1081 // See also hasNavigationBar().
1082 String navBarOverride = SystemProperties.get("qemu.hw.mainkeys");
1083 if ("1".equals(navBarOverride)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001084 mHasNavigationBar = false;
John Spurlock80f00c12013-06-13 11:10:51 -04001085 } else if ("0".equals(navBarOverride)) {
1086 mHasNavigationBar = true;
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04001087 }
1088
Jeff Brown27f1d672012-10-17 18:32:34 -07001089 // For demo purposes, allow the rotation of the HDMI display to be controlled.
1090 // By default, HDMI locks rotation to landscape.
Erik Gilling9a41ef82011-09-26 19:21:03 -07001091 if ("portrait".equals(SystemProperties.get("persist.demo.hdmirotation"))) {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001092 mDemoHdmiRotation = mPortraitRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001093 } else {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001094 mDemoHdmiRotation = mLandscapeRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001095 }
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001096 mDemoHdmiRotationLock = SystemProperties.getBoolean("persist.demo.hdmirotationlock", false);
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001097
1098 // Only force the default orientation if the screen is xlarge, at least 960dp x 720dp, per
1099 // http://developer.android.com/guide/practices/screens_support.html#range
1100 mForceDefaultOrientation = longSizeDp >= 960 && shortSizeDp >= 720 &&
1101 res.getBoolean(com.android.internal.R.bool.config_forceDefaultOrientation) &&
1102 // For debug purposes the next line turns this feature off with:
1103 // $ adb shell setprop config.override_forced_orient true
1104 // $ adb shell wm size reset
1105 !"true".equals(SystemProperties.get("config.override_forced_orient"));
1106 }
1107
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001108 /**
1109 * @return whether the navigation bar can be hidden, e.g. the device has a
1110 * navigation bar and touch exploration is not enabled
1111 */
1112 private boolean canHideNavigationBar() {
Svetoslav8e3feb12014-02-24 13:46:47 -08001113 return mHasNavigationBar
1114 && !mAccessibilityManager.isTouchExplorationEnabled();
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001115 }
1116
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001117 @Override
1118 public boolean isDefaultOrientationForced() {
1119 return mForceDefaultOrientation;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001120 }
1121
Dianne Hackbornc652de82013-02-15 16:32:56 -08001122 @Override
1123 public void setDisplayOverscan(Display display, int left, int top, int right, int bottom) {
1124 if (display.getDisplayId() == Display.DEFAULT_DISPLAY) {
1125 mOverscanLeft = left;
1126 mOverscanTop = top;
1127 mOverscanRight = right;
1128 mOverscanBottom = bottom;
1129 }
1130 }
1131
Dianne Hackbornc777e072010-02-12 13:07:59 -08001132 public void updateSettings() {
1133 ContentResolver resolver = mContext.getContentResolver();
1134 boolean updateRotation = false;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001135 synchronized (mLock) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001136 mEndcallBehavior = Settings.System.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001137 Settings.System.END_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001138 Settings.System.END_BUTTON_BEHAVIOR_DEFAULT,
1139 UserHandle.USER_CURRENT);
1140 mIncallPowerBehavior = Settings.Secure.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001141 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001142 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT,
1143 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001144
Jeff Brown207673cd2012-06-05 17:47:11 -07001145 // Configure rotation lock.
Christopher Tate5e08af02012-09-21 17:17:22 -07001146 int userRotation = Settings.System.getIntForUser(resolver,
1147 Settings.System.USER_ROTATION, Surface.ROTATION_0,
1148 UserHandle.USER_CURRENT);
Jeff Brown207673cd2012-06-05 17:47:11 -07001149 if (mUserRotation != userRotation) {
1150 mUserRotation = userRotation;
1151 updateRotation = true;
1152 }
Christopher Tate5e08af02012-09-21 17:17:22 -07001153 int userRotationMode = Settings.System.getIntForUser(resolver,
1154 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
Jeff Brown207673cd2012-06-05 17:47:11 -07001155 WindowManagerPolicy.USER_ROTATION_FREE :
1156 WindowManagerPolicy.USER_ROTATION_LOCKED;
1157 if (mUserRotationMode != userRotationMode) {
1158 mUserRotationMode = userRotationMode;
1159 updateRotation = true;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001160 updateOrientationListenerLp();
1161 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001162
Dianne Hackbornc777e072010-02-12 13:07:59 -08001163 if (mSystemReady) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001164 int pointerLocation = Settings.System.getIntForUser(resolver,
1165 Settings.System.POINTER_LOCATION, 0, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001166 if (mPointerLocationMode != pointerLocation) {
1167 mPointerLocationMode = pointerLocation;
Jeff Brown70825162012-03-28 17:27:48 -07001168 mHandler.sendEmptyMessage(pointerLocation != 0 ?
1169 MSG_ENABLE_POINTER_LOCATION : MSG_DISABLE_POINTER_LOCATION);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001170 }
1171 }
1172 // use screen off timeout setting as the timeout for the lockscreen
Christopher Tate5e08af02012-09-21 17:17:22 -07001173 mLockScreenTimeout = Settings.System.getIntForUser(resolver,
1174 Settings.System.SCREEN_OFF_TIMEOUT, 0, UserHandle.USER_CURRENT);
1175 String imId = Settings.Secure.getStringForUser(resolver,
1176 Settings.Secure.DEFAULT_INPUT_METHOD, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001177 boolean hasSoftInput = imId != null && imId.length() > 0;
1178 if (mHasSoftInput != hasSoftInput) {
1179 mHasSoftInput = hasSoftInput;
1180 updateRotation = true;
1181 }
John Spurlockf1a36642013-10-12 17:50:42 -04001182 if (mImmersiveModeConfirmation != null) {
John Spurlock4355a532014-02-19 09:49:25 -05001183 mImmersiveModeConfirmation.loadSetting(mCurrentUserId);
John Spurlockd67ec252013-09-05 11:31:54 -04001184 }
John Spurlockc6d1c602014-01-17 15:22:06 -05001185 PolicyControl.reloadFromSetting(mContext);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001186 }
1187 if (updateRotation) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07001188 updateRotation(true);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001189 }
Jeff Brown70825162012-03-28 17:27:48 -07001190 }
1191
1192 private void enablePointerLocation() {
1193 if (mPointerLocationView == null) {
1194 mPointerLocationView = new PointerLocationView(mContext);
1195 mPointerLocationView.setPrintCoords(false);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001196 WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
1197 WindowManager.LayoutParams.MATCH_PARENT,
1198 WindowManager.LayoutParams.MATCH_PARENT);
Jeff Brown3b2b3542010-10-15 00:54:27 -07001199 lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001200 lp.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN
1201 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
1202 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1203 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
Jeff Brown90fc9052012-10-01 14:44:24 -07001204 if (ActivityManager.isHighEndGfx()) {
1205 lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
1206 lp.privateFlags |=
1207 WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED;
1208 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001209 lp.format = PixelFormat.TRANSLUCENT;
1210 lp.setTitle("PointerLocation");
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001211 WindowManager wm = (WindowManager)
Dianne Hackbornc777e072010-02-12 13:07:59 -08001212 mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Browncc4f7db2011-08-30 20:34:48 -07001213 lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL;
Jeff Brown70825162012-03-28 17:27:48 -07001214 wm.addView(mPointerLocationView, lp);
Michael Wrightc9c487e2013-11-07 18:55:09 -08001215 mWindowManagerFuncs.registerPointerEventListener(mPointerLocationView);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001216 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001217 }
Jeff Brown70825162012-03-28 17:27:48 -07001218
1219 private void disablePointerLocation() {
Jeff Brown70825162012-03-28 17:27:48 -07001220 if (mPointerLocationView != null) {
Michael Wrightc9c487e2013-11-07 18:55:09 -08001221 mWindowManagerFuncs.unregisterPointerEventListener(mPointerLocationView);
1222 WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Brown70825162012-03-28 17:27:48 -07001223 wm.removeView(mPointerLocationView);
1224 mPointerLocationView = null;
1225 }
1226 }
1227
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001228 private int readRotation(int resID) {
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001229 try {
1230 int rotation = mContext.getResources().getInteger(resID);
1231 switch (rotation) {
1232 case 0:
1233 return Surface.ROTATION_0;
1234 case 90:
1235 return Surface.ROTATION_90;
1236 case 180:
1237 return Surface.ROTATION_180;
1238 case 270:
1239 return Surface.ROTATION_270;
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001240 }
1241 } catch (Resources.NotFoundException e) {
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001242 // fall through
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001243 }
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001244 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001245 }
1246
1247 /** {@inheritDoc} */
Craig Mautner88400d32012-09-30 12:35:45 -07001248 @Override
Dianne Hackbornc2293022013-02-06 23:14:49 -08001249 public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001250 int type = attrs.type;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001251
1252 outAppOp[0] = AppOpsManager.OP_NONE;
1253
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001254 if (type < WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW
1255 || type > WindowManager.LayoutParams.LAST_SYSTEM_WINDOW) {
Jeff Brown98365d72012-08-19 20:30:52 -07001256 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001257 }
1258 String permission = null;
1259 switch (type) {
1260 case TYPE_TOAST:
1261 // XXX right now the app process has complete control over
1262 // this... should introduce a token to let the system
1263 // monitor/control what they are doing.
1264 break;
Daniel Sandler7d276c32012-01-30 14:33:52 -05001265 case TYPE_DREAM:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001266 case TYPE_INPUT_METHOD:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001267 case TYPE_WALLPAPER:
keunyounga446bf02013-06-21 19:07:57 -07001268 case TYPE_PRIVATE_PRESENTATION:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001269 // The window manager will check these.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001270 break;
1271 case TYPE_PHONE:
1272 case TYPE_PRIORITY_PHONE:
1273 case TYPE_SYSTEM_ALERT:
1274 case TYPE_SYSTEM_ERROR:
1275 case TYPE_SYSTEM_OVERLAY:
1276 permission = android.Manifest.permission.SYSTEM_ALERT_WINDOW;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001277 outAppOp[0] = AppOpsManager.OP_SYSTEM_ALERT_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001278 break;
1279 default:
1280 permission = android.Manifest.permission.INTERNAL_SYSTEM_WINDOW;
1281 }
1282 if (permission != null) {
1283 if (mContext.checkCallingOrSelfPermission(permission)
1284 != PackageManager.PERMISSION_GRANTED) {
Jeff Brown98365d72012-08-19 20:30:52 -07001285 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001286 }
1287 }
Jeff Brown98365d72012-08-19 20:30:52 -07001288 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001289 }
Craig Mautner88400d32012-09-30 12:35:45 -07001290
1291 @Override
1292 public boolean checkShowToOwnerOnly(WindowManager.LayoutParams attrs) {
1293
1294 // If this switch statement is modified, modify the comment in the declarations of
1295 // the type in {@link WindowManager.LayoutParams} as well.
1296 switch (attrs.type) {
1297 default:
1298 // These are the windows that by default are shown only to the user that created
1299 // them. If this needs to be overridden, set
1300 // {@link WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS} in
1301 // {@link WindowManager.LayoutParams}. Note that permission
1302 // {@link android.Manifest.permission.INTERNAL_SYSTEM_WINDOW} is required as well.
1303 if ((attrs.privateFlags & PRIVATE_FLAG_SHOW_FOR_ALL_USERS) == 0) {
1304 return true;
1305 }
1306 break;
1307
1308 // These are the windows that by default are shown to all users. However, to
1309 // protect against spoofing, check permissions below.
1310 case TYPE_APPLICATION_STARTING:
1311 case TYPE_BOOT_PROGRESS:
1312 case TYPE_DISPLAY_OVERLAY:
1313 case TYPE_HIDDEN_NAV_CONSUMER:
1314 case TYPE_KEYGUARD:
Jim Miller5ecd8112013-01-09 18:50:26 -08001315 case TYPE_KEYGUARD_SCRIM:
Craig Mautner88400d32012-09-30 12:35:45 -07001316 case TYPE_KEYGUARD_DIALOG:
1317 case TYPE_MAGNIFICATION_OVERLAY:
1318 case TYPE_NAVIGATION_BAR:
1319 case TYPE_NAVIGATION_BAR_PANEL:
1320 case TYPE_PHONE:
1321 case TYPE_POINTER:
1322 case TYPE_PRIORITY_PHONE:
1323 case TYPE_RECENTS_OVERLAY:
1324 case TYPE_SEARCH_BAR:
1325 case TYPE_STATUS_BAR:
1326 case TYPE_STATUS_BAR_PANEL:
1327 case TYPE_STATUS_BAR_SUB_PANEL:
1328 case TYPE_SYSTEM_DIALOG:
1329 case TYPE_UNIVERSE_BACKGROUND:
1330 case TYPE_VOLUME_OVERLAY:
keunyounga446bf02013-06-21 19:07:57 -07001331 case TYPE_PRIVATE_PRESENTATION:
Craig Mautner88400d32012-09-30 12:35:45 -07001332 break;
1333 }
1334
1335 // Check if third party app has set window to system window type.
1336 return mContext.checkCallingOrSelfPermission(
1337 android.Manifest.permission.INTERNAL_SYSTEM_WINDOW)
1338 != PackageManager.PERMISSION_GRANTED;
1339 }
1340
Craig Mautner967212c2013-04-13 21:10:58 -07001341 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001342 public void adjustWindowParamsLw(WindowManager.LayoutParams attrs) {
1343 switch (attrs.type) {
1344 case TYPE_SYSTEM_OVERLAY:
Jeff Brown3b2b3542010-10-15 00:54:27 -07001345 case TYPE_SECURE_SYSTEM_OVERLAY:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001346 // These types of windows can't receive input events.
1347 attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1348 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001349 attrs.flags &= ~WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001350 break;
1351 }
1352 }
1353
1354 void readLidState() {
Jeff Brown2e7760e2012-04-11 15:14:55 -07001355 mLidState = mWindowManagerFuncs.getLidState();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001356 }
1357
Jeff Browndaa37532012-05-01 15:54:03 -07001358 private boolean isHidden(int accessibilityMode) {
1359 switch (accessibilityMode) {
1360 case 1:
1361 return mLidState == LID_CLOSED;
1362 case 2:
1363 return mLidState == LID_OPEN;
1364 default:
1365 return false;
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001366 }
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001367 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001368
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001369 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07001370 @Override
Jeff Browndaa37532012-05-01 15:54:03 -07001371 public void adjustConfigurationLw(Configuration config, int keyboardPresence,
1372 int navigationPresence) {
1373 mHaveBuiltInKeyboard = (keyboardPresence & PRESENCE_INTERNAL) != 0;
1374
Jeff Brownf71343d2013-05-31 17:59:11 -07001375 readConfigurationDependentBehaviors();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001376 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07001377 applyLidSwitchState();
Jeff Brownd04a88c2011-01-16 14:05:47 -08001378
Jeff Browndaa37532012-05-01 15:54:03 -07001379 if (config.keyboard == Configuration.KEYBOARD_NOKEYS
1380 || (keyboardPresence == PRESENCE_INTERNAL
1381 && isHidden(mLidKeyboardAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001382 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_YES;
Jeff Browndaa37532012-05-01 15:54:03 -07001383 if (!mHasSoftInput) {
1384 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_YES;
1385 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001386 }
1387
Jeff Browndaa37532012-05-01 15:54:03 -07001388 if (config.navigation == Configuration.NAVIGATION_NONAV
1389 || (navigationPresence == PRESENCE_INTERNAL
1390 && isHidden(mLidNavigationAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001391 config.navigationHidden = Configuration.NAVIGATIONHIDDEN_YES;
Jeff Brownd04a88c2011-01-16 14:05:47 -08001392 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001393 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001394
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001395 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07001396 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001397 public int windowTypeToLayerLw(int type) {
1398 if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001399 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001400 }
1401 switch (type) {
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001402 case TYPE_UNIVERSE_BACKGROUND:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001403 return 1;
keunyounga446bf02013-06-21 19:07:57 -07001404 case TYPE_PRIVATE_PRESENTATION:
1405 return 2;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001406 case TYPE_WALLPAPER:
1407 // wallpaper is at the bottom, though the window manager may move it.
1408 return 2;
1409 case TYPE_PHONE:
1410 return 3;
1411 case TYPE_SEARCH_BAR:
1412 return 4;
Craig Mautner88400d32012-09-30 12:35:45 -07001413 case TYPE_RECENTS_OVERLAY:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001414 case TYPE_SYSTEM_DIALOG:
1415 return 5;
1416 case TYPE_TOAST:
1417 // toasts and the plugged-in battery thing
1418 return 6;
1419 case TYPE_PRIORITY_PHONE:
1420 // SIM errors and unlock. Not sure if this really should be in a high layer.
1421 return 7;
1422 case TYPE_DREAM:
1423 // used for Dreams (screensavers with TYPE_DREAM windows)
1424 return 8;
1425 case TYPE_SYSTEM_ALERT:
1426 // like the ANR / app crashed dialogs
1427 return 9;
1428 case TYPE_INPUT_METHOD:
1429 // on-screen keyboards and other such input method user interfaces go here.
1430 return 10;
1431 case TYPE_INPUT_METHOD_DIALOG:
1432 // on-screen keyboards and other such input method user interfaces go here.
1433 return 11;
Jim Miller5ecd8112013-01-09 18:50:26 -08001434 case TYPE_KEYGUARD_SCRIM:
1435 // the safety window that shows behind keyguard while keyguard is starting
1436 return 12;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001437 case TYPE_KEYGUARD:
1438 // the keyguard; nothing on top of these can take focus, since they are
1439 // responsible for power management when displayed.
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001440 return 13;
Jim Miller5ecd8112013-01-09 18:50:26 -08001441 case TYPE_KEYGUARD_DIALOG:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001442 return 14;
Jim Miller5ecd8112013-01-09 18:50:26 -08001443 case TYPE_STATUS_BAR_SUB_PANEL:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001444 return 15;
Jim Miller5ecd8112013-01-09 18:50:26 -08001445 case TYPE_STATUS_BAR:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001446 return 16;
Jim Miller5ecd8112013-01-09 18:50:26 -08001447 case TYPE_STATUS_BAR_PANEL:
1448 return 17;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001449 case TYPE_VOLUME_OVERLAY:
1450 // the on-screen volume indicator and controller shown when the user
1451 // changes the device volume
Jim Miller5ecd8112013-01-09 18:50:26 -08001452 return 18;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001453 case TYPE_SYSTEM_OVERLAY:
1454 // the on-screen volume indicator and controller shown when the user
1455 // changes the device volume
Jim Miller5ecd8112013-01-09 18:50:26 -08001456 return 19;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001457 case TYPE_NAVIGATION_BAR:
1458 // the navigation bar, if available, shows atop most things
Jim Miller5ecd8112013-01-09 18:50:26 -08001459 return 20;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001460 case TYPE_NAVIGATION_BAR_PANEL:
1461 // some panels (e.g. search) need to show on top of the navigation bar
Jim Miller5ecd8112013-01-09 18:50:26 -08001462 return 21;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001463 case TYPE_SYSTEM_ERROR:
1464 // system-level error dialogs
Jim Miller5ecd8112013-01-09 18:50:26 -08001465 return 22;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001466 case TYPE_MAGNIFICATION_OVERLAY:
1467 // used to highlight the magnified portion of a display
Jim Miller5ecd8112013-01-09 18:50:26 -08001468 return 23;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001469 case TYPE_DISPLAY_OVERLAY:
1470 // used to simulate secondary display devices
Jim Miller5ecd8112013-01-09 18:50:26 -08001471 return 24;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001472 case TYPE_DRAG:
1473 // the drag layer: input for drag-and-drop is associated with this window,
1474 // which sits above all other focusable windows
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001475 return 25;
Jim Miller5ecd8112013-01-09 18:50:26 -08001476 case TYPE_SECURE_SYSTEM_OVERLAY:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001477 return 26;
Jim Miller5ecd8112013-01-09 18:50:26 -08001478 case TYPE_BOOT_PROGRESS:
1479 return 27;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001480 case TYPE_POINTER:
1481 // the (mouse) pointer layer
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001482 return 28;
Jim Miller5ecd8112013-01-09 18:50:26 -08001483 case TYPE_HIDDEN_NAV_CONSUMER:
1484 return 29;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001485 }
1486 Log.e(TAG, "Unknown window type: " + type);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001487 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001488 }
1489
1490 /** {@inheritDoc} */
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001491 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001492 public int subWindowTypeToLayerLw(int type) {
1493 switch (type) {
1494 case TYPE_APPLICATION_PANEL:
1495 case TYPE_APPLICATION_ATTACHED_DIALOG:
1496 return APPLICATION_PANEL_SUBLAYER;
1497 case TYPE_APPLICATION_MEDIA:
1498 return APPLICATION_MEDIA_SUBLAYER;
Dianne Hackborn5cb8d792009-05-21 17:34:15 -07001499 case TYPE_APPLICATION_MEDIA_OVERLAY:
1500 return APPLICATION_MEDIA_OVERLAY_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001501 case TYPE_APPLICATION_SUB_PANEL:
1502 return APPLICATION_SUB_PANEL_SUBLAYER;
1503 }
1504 Log.e(TAG, "Unknown sub-window type: " + type);
1505 return 0;
1506 }
1507
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001508 @Override
Dianne Hackbornabe0da02009-09-18 01:55:39 -07001509 public int getMaxWallpaperLayer() {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001510 return windowTypeToLayerLw(TYPE_STATUS_BAR);
Dianne Hackbornabe0da02009-09-18 01:55:39 -07001511 }
1512
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001513 @Override
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001514 public int getAboveUniverseLayer() {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001515 return windowTypeToLayerLw(TYPE_SYSTEM_ERROR);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001516 }
1517
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001518 public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07001519 if (mHasNavigationBar) {
1520 // For a basic navigation bar, when we are in landscape mode we place
1521 // the navigation bar to the side.
Daniel Sandler4a066c52012-04-20 14:49:13 -04001522 if (mNavigationBarCanMove && fullWidth > fullHeight) {
1523 return fullWidth - mNavigationBarWidthForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07001524 }
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001525 }
1526 return fullWidth;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001527 }
1528
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001529 public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07001530 if (mHasNavigationBar) {
1531 // For a basic navigation bar, when we are in portrait mode we place
1532 // the navigation bar to the bottom.
Daniel Sandler4a066c52012-04-20 14:49:13 -04001533 if (!mNavigationBarCanMove || fullWidth < fullHeight) {
1534 return fullHeight - mNavigationBarHeightForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07001535 }
1536 }
1537 return fullHeight;
Dianne Hackborn69cb8752011-05-19 18:13:32 -07001538 }
1539
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001540 public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation) {
1541 return getNonDecorDisplayWidth(fullWidth, fullHeight, rotation);
Dianne Hackborn69cb8752011-05-19 18:13:32 -07001542 }
1543
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001544 public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation) {
John Spurlock80f00c12013-06-13 11:10:51 -04001545 // There is a separate status bar at the top of the display. We don't count that as part
1546 // of the fixed decor, since it can hide; however, for purposes of configurations,
Dianne Hackborn077ee852012-04-09 16:27:07 -07001547 // we do want to exclude it since applications can't generally use that part
1548 // of the screen.
John Spurlock80f00c12013-06-13 11:10:51 -04001549 return getNonDecorDisplayHeight(fullWidth, fullHeight, rotation) - mStatusBarHeight;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001550 }
1551
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001552 @Override
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07001553 public boolean doesForceHide(WindowState win, WindowManager.LayoutParams attrs) {
1554 return attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD;
1555 }
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001556
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001557 @Override
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07001558 public boolean canBeForceHidden(WindowState win, WindowManager.LayoutParams attrs) {
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001559 switch (attrs.type) {
1560 case TYPE_STATUS_BAR:
1561 case TYPE_NAVIGATION_BAR:
1562 case TYPE_WALLPAPER:
1563 case TYPE_DREAM:
1564 case TYPE_UNIVERSE_BACKGROUND:
1565 case TYPE_KEYGUARD:
Jim Miller5ecd8112013-01-09 18:50:26 -08001566 case TYPE_KEYGUARD_SCRIM:
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001567 return false;
1568 default:
1569 return true;
1570 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07001571 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001572
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001573 /** {@inheritDoc} */
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001574 @Override
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07001575 public View addStartingWindow(IBinder appToken, String packageName, int theme,
1576 CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes,
Adam Powell04fe6eb2013-05-31 14:39:48 -07001577 int icon, int logo, int windowFlags) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001578 if (!SHOW_STARTING_ANIMATIONS) {
1579 return null;
1580 }
1581 if (packageName == null) {
1582 return null;
1583 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001584
Mathias Jeppssond1443e92012-08-24 15:25:32 +02001585 WindowManager wm = null;
1586 View view = null;
1587
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001588 try {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001589 Context context = mContext;
Craig Mautner6fbda632012-07-03 09:26:39 -07001590 if (DEBUG_STARTING_WINDOW) Slog.d(TAG, "addStartingWindow " + packageName
1591 + ": nonLocalizedLabel=" + nonLocalizedLabel + " theme="
1592 + Integer.toHexString(theme));
Dianne Hackborn247fe742011-01-08 17:25:57 -08001593 if (theme != context.getThemeResId() || labelRes != 0) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001594 try {
1595 context = context.createPackageContext(packageName, 0);
Dianne Hackborn247fe742011-01-08 17:25:57 -08001596 context.setTheme(theme);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001597 } catch (PackageManager.NameNotFoundException e) {
1598 // Ignore
1599 }
1600 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001601
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001602 Window win = PolicyManager.makeNewWindow(context);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001603 final TypedArray ta = win.getWindowStyle();
1604 if (ta.getBoolean(
1605 com.android.internal.R.styleable.Window_windowDisablePreview, false)
1606 || ta.getBoolean(
1607 com.android.internal.R.styleable.Window_windowShowWallpaper,false)) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001608 return null;
1609 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001610
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001611 Resources r = context.getResources();
1612 win.setTitle(r.getText(labelRes, nonLocalizedLabel));
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001613
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001614 win.setType(
1615 WindowManager.LayoutParams.TYPE_APPLICATION_STARTING);
1616 // Force the window flags: this is a fake window, so it is not really
1617 // touchable or focusable by the user. We also add in the ALT_FOCUSABLE_IM
1618 // flag because we do know that the next window will take input
1619 // focus, so we want to get the IME window up on top of us right away.
1620 win.setFlags(
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08001621 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001622 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
1623 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
1624 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08001625 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001626 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
1627 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
1628 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001629
Adam Powell04fe6eb2013-05-31 14:39:48 -07001630 win.setDefaultIcon(icon);
1631 win.setDefaultLogo(logo);
1632
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001633 win.setLayout(WindowManager.LayoutParams.MATCH_PARENT,
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07001634 WindowManager.LayoutParams.MATCH_PARENT);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001635
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001636 final WindowManager.LayoutParams params = win.getAttributes();
1637 params.token = appToken;
1638 params.packageName = packageName;
1639 params.windowAnimations = win.getWindowStyle().getResourceId(
1640 com.android.internal.R.styleable.Window_windowAnimationStyle, 0);
Dianne Hackborn5d927c22011-09-02 12:22:18 -07001641 params.privateFlags |=
1642 WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED;
Craig Mautner88400d32012-09-30 12:35:45 -07001643 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
Adam Lesinski95c42972013-10-02 10:13:27 -07001644
1645 if (!compatInfo.supportsScreen()) {
1646 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
1647 }
1648
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001649 params.setTitle("Starting " + packageName);
1650
Mathias Jeppssond1443e92012-08-24 15:25:32 +02001651 wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
1652 view = win.getDecorView();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001653
1654 if (win.isFloating()) {
1655 // Whoops, there is no way to display an animation/preview
1656 // of such a thing! After all that work... let's skip it.
1657 // (Note that we must do this here because it is in
1658 // getDecorView() where the theme is evaluated... maybe
1659 // we should peek the floating attribute from the theme
1660 // earlier.)
1661 return null;
1662 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001663
Craig Mautner6fbda632012-07-03 09:26:39 -07001664 if (DEBUG_STARTING_WINDOW) Slog.d(
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001665 TAG, "Adding starting window for " + packageName
1666 + " / " + appToken + ": "
1667 + (view.getParent() != null ? view : null));
1668
1669 wm.addView(view, params);
1670
1671 // Only return the view if it was successfully added to the
1672 // window manager... which we can tell by it having a parent.
1673 return view.getParent() != null ? view : null;
Jeff Brown98365d72012-08-19 20:30:52 -07001674 } catch (WindowManager.BadTokenException e) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001675 // ignore
Craig Mautner42bf39e2014-02-21 16:46:22 -08001676 Log.w(TAG, appToken + " already running, starting window not displayed. " +
1677 e.getMessage());
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001678 } catch (RuntimeException e) {
1679 // don't crash if something else bad happens, for example a
1680 // failure loading resources because we are loading from an app
1681 // on external storage that has been unmounted.
1682 Log.w(TAG, appToken + " failed creating starting window", e);
Mathias Jeppssond1443e92012-08-24 15:25:32 +02001683 } finally {
1684 if (view != null && view.getParent() == null) {
1685 Log.w(TAG, "view not successfully added to wm, removing view");
1686 wm.removeViewImmediate(view);
1687 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001688 }
1689
1690 return null;
1691 }
1692
1693 /** {@inheritDoc} */
1694 public void removeStartingWindow(IBinder appToken, View window) {
Craig Mautner6fbda632012-07-03 09:26:39 -07001695 if (DEBUG_STARTING_WINDOW) {
1696 RuntimeException e = new RuntimeException("here");
1697 e.fillInStackTrace();
1698 Log.v(TAG, "Removing starting window for " + appToken + ": " + window, e);
1699 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001700
1701 if (window != null) {
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001702 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001703 wm.removeView(window);
1704 }
1705 }
1706
1707 /**
1708 * Preflight adding a window to the system.
1709 *
1710 * Currently enforces that three window types are singletons:
1711 * <ul>
1712 * <li>STATUS_BAR_TYPE</li>
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001713 * <li>KEYGUARD_TYPE</li>
1714 * </ul>
1715 *
1716 * @param win The window to be added
1717 * @param attrs Information about the window to be added
1718 *
Jeff Brown98365d72012-08-19 20:30:52 -07001719 * @return If ok, WindowManagerImpl.ADD_OKAY. If too many singletons,
1720 * WindowManagerImpl.ADD_MULTIPLE_SINGLETON
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001721 */
1722 public int prepareAddWindowLw(WindowState win, WindowManager.LayoutParams attrs) {
1723 switch (attrs.type) {
1724 case TYPE_STATUS_BAR:
Joe Onorato8bc6c512010-06-04 16:21:12 -04001725 mContext.enforceCallingOrSelfPermission(
1726 android.Manifest.permission.STATUS_BAR_SERVICE,
1727 "PhoneWindowManager");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001728 if (mStatusBar != null) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001729 if (mStatusBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07001730 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001731 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001732 }
1733 mStatusBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04001734 mStatusBarController.setWindow(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001735 break;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04001736 case TYPE_NAVIGATION_BAR:
1737 mContext.enforceCallingOrSelfPermission(
1738 android.Manifest.permission.STATUS_BAR_SERVICE,
1739 "PhoneWindowManager");
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001740 if (mNavigationBar != null) {
1741 if (mNavigationBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07001742 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001743 }
1744 }
Daniel Sandler8956dbb2011-04-22 07:55:02 -04001745 mNavigationBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04001746 mNavigationBarController.setWindow(win);
Craig Mautnereda67292013-04-28 13:50:14 -07001747 if (DEBUG_LAYOUT) Slog.i(TAG, "NAVIGATION BAR: " + mNavigationBar);
Daniel Sandler8956dbb2011-04-22 07:55:02 -04001748 break;
Jim Millere898ac52012-04-06 17:10:57 -07001749 case TYPE_NAVIGATION_BAR_PANEL:
1750 mContext.enforceCallingOrSelfPermission(
1751 android.Manifest.permission.STATUS_BAR_SERVICE,
1752 "PhoneWindowManager");
1753 break;
Dianne Hackborn08743722009-12-21 12:16:51 -08001754 case TYPE_STATUS_BAR_PANEL:
Joe Onorato8bc6c512010-06-04 16:21:12 -04001755 mContext.enforceCallingOrSelfPermission(
1756 android.Manifest.permission.STATUS_BAR_SERVICE,
1757 "PhoneWindowManager");
Dianne Hackborn08743722009-12-21 12:16:51 -08001758 break;
Joe Onorato29fc2c92010-11-24 10:26:50 -08001759 case TYPE_STATUS_BAR_SUB_PANEL:
1760 mContext.enforceCallingOrSelfPermission(
1761 android.Manifest.permission.STATUS_BAR_SERVICE,
1762 "PhoneWindowManager");
Joe Onorato29fc2c92010-11-24 10:26:50 -08001763 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001764 case TYPE_KEYGUARD:
1765 if (mKeyguard != null) {
Jeff Brown98365d72012-08-19 20:30:52 -07001766 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001767 }
1768 mKeyguard = win;
1769 break;
Jim Miller5ecd8112013-01-09 18:50:26 -08001770 case TYPE_KEYGUARD_SCRIM:
Jim Miller25190572013-02-28 17:36:24 -08001771 if (mKeyguardScrim != null) {
1772 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
1773 }
Jim Miller5ecd8112013-01-09 18:50:26 -08001774 mKeyguardScrim = win;
1775 break;
1776
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001777 }
Jeff Brown98365d72012-08-19 20:30:52 -07001778 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001779 }
1780
1781 /** {@inheritDoc} */
1782 public void removeWindowLw(WindowState win) {
1783 if (mStatusBar == win) {
1784 mStatusBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04001785 mStatusBarController.setWindow(null);
Daniel Sandler8956dbb2011-04-22 07:55:02 -04001786 } else if (mKeyguard == win) {
Jim Miller5ecd8112013-01-09 18:50:26 -08001787 Log.v(TAG, "Removing keyguard window (Did it crash?)");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001788 mKeyguard = null;
Jim Millerc0b676d2013-03-22 16:11:08 -07001789 mKeyguardDelegate.showScrim();
Jim Miller5ecd8112013-01-09 18:50:26 -08001790 } else if (mKeyguardScrim == win) {
1791 Log.v(TAG, "Removing keyguard scrim");
1792 mKeyguardScrim = null;
1793 } if (mNavigationBar == win) {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04001794 mNavigationBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04001795 mNavigationBarController.setWindow(null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001796 }
1797 }
1798
1799 static final boolean PRINT_ANIM = false;
1800
1801 /** {@inheritDoc} */
Craig Mautner4b71aa12012-12-27 17:20:01 -08001802 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001803 public int selectAnimationLw(WindowState win, int transit) {
1804 if (PRINT_ANIM) Log.i(TAG, "selectAnimation in " + win
1805 + ": transit=" + transit);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001806 if (win == mStatusBar) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08001807 if (transit == TRANSIT_EXIT
1808 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001809 return R.anim.dock_top_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001810 } else if (transit == TRANSIT_ENTER
1811 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001812 return R.anim.dock_top_enter;
1813 }
1814 } else if (win == mNavigationBar) {
1815 // This can be on either the bottom or the right.
1816 if (mNavigationBarOnBottom) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08001817 if (transit == TRANSIT_EXIT
1818 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001819 return R.anim.dock_bottom_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001820 } else if (transit == TRANSIT_ENTER
1821 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001822 return R.anim.dock_bottom_enter;
1823 }
1824 } else {
Craig Mautner4b71aa12012-12-27 17:20:01 -08001825 if (transit == TRANSIT_EXIT
1826 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001827 return R.anim.dock_right_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001828 } else if (transit == TRANSIT_ENTER
1829 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001830 return R.anim.dock_right_enter;
1831 }
1832 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08001833 }
1834
1835 if (transit == TRANSIT_PREVIEW_DONE) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001836 if (win.hasAppShownWindows()) {
1837 if (PRINT_ANIM) Log.i(TAG, "**** STARTING EXIT");
1838 return com.android.internal.R.anim.app_starting_exit;
1839 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07001840 } else if (win.getAttrs().type == TYPE_DREAM && mDreamingLockscreen
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001841 && transit == TRANSIT_ENTER) {
1842 // Special case: we are animating in a dream, while the keyguard
1843 // is shown. We don't want an animation on the dream, because
1844 // we need it shown immediately with the keyguard animating away
1845 // to reveal it.
1846 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001847 }
1848
1849 return 0;
1850 }
1851
Craig Mautner3c174372013-02-21 17:54:37 -08001852 @Override
1853 public void selectRotationAnimationLw(int anim[]) {
1854 if (PRINT_ANIM) Slog.i(TAG, "selectRotationAnimation mTopFullscreen="
1855 + mTopFullscreenOpaqueWindowState + " rotationAnimation="
1856 + (mTopFullscreenOpaqueWindowState == null ?
1857 "0" : mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation));
1858 if (mTopFullscreenOpaqueWindowState != null && mTopIsFullscreen) {
1859 switch (mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation) {
1860 case ROTATION_ANIMATION_CROSSFADE:
1861 anim[0] = R.anim.rotation_animation_xfade_exit;
1862 anim[1] = R.anim.rotation_animation_enter;
1863 break;
1864 case ROTATION_ANIMATION_JUMPCUT:
1865 anim[0] = R.anim.rotation_animation_jump_exit;
1866 anim[1] = R.anim.rotation_animation_enter;
1867 break;
1868 case ROTATION_ANIMATION_ROTATE:
1869 default:
1870 anim[0] = anim[1] = 0;
1871 break;
1872 }
1873 } else {
1874 anim[0] = anim[1] = 0;
1875 }
1876 }
1877
1878 @Override
1879 public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId,
1880 boolean forceDefault) {
1881 switch (exitAnimId) {
1882 case R.anim.rotation_animation_xfade_exit:
1883 case R.anim.rotation_animation_jump_exit:
1884 // These are the only cases that matter.
1885 if (forceDefault) {
1886 return false;
1887 }
1888 int anim[] = new int[2];
1889 selectRotationAnimationLw(anim);
1890 return (exitAnimId == anim[0] && enterAnimId == anim[1]);
1891 default:
1892 return true;
1893 }
1894 }
1895
1896 @Override
Dianne Hackborn0c2acff2012-04-12 15:17:07 -07001897 public Animation createForceHideEnterAnimation(boolean onWallpaper) {
1898 return AnimationUtils.loadAnimation(mContext, onWallpaper
1899 ? com.android.internal.R.anim.lock_screen_wallpaper_behind_enter
1900 : com.android.internal.R.anim.lock_screen_behind_enter);
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07001901 }
John Spurlockc8b46ca2013-04-08 12:59:26 -04001902
1903 private static void awakenDreams() {
1904 IDreamManager dreamManager = getDreamManager();
1905 if (dreamManager != null) {
1906 try {
1907 dreamManager.awaken();
1908 } catch (RemoteException e) {
1909 // fine, stay asleep then
1910 }
1911 }
1912 }
1913
1914 static IDreamManager getDreamManager() {
1915 return IDreamManager.Stub.asInterface(
1916 ServiceManager.checkService(DreamService.DREAM_SERVICE));
1917 }
1918
Jeff Brown4d396052010-10-29 21:50:21 -07001919 static ITelephony getTelephonyService() {
Mike Lockwoodf5f4ec92011-11-08 14:05:31 -08001920 return ITelephony.Stub.asInterface(
Jeff Brown4d396052010-10-29 21:50:21 -07001921 ServiceManager.checkService(Context.TELEPHONY_SERVICE));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001922 }
1923
Jeff Brown4d396052010-10-29 21:50:21 -07001924 static IAudioService getAudioService() {
1925 IAudioService audioService = IAudioService.Stub.asInterface(
1926 ServiceManager.checkService(Context.AUDIO_SERVICE));
1927 if (audioService == null) {
1928 Log.w(TAG, "Unable to find IAudioService interface.");
1929 }
1930 return audioService;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001931 }
1932
1933 boolean keyguardOn() {
1934 return keyguardIsShowingTq() || inKeyguardRestrictedKeyInputMode();
1935 }
1936
1937 private static final int[] WINDOW_TYPES_WHERE_HOME_DOESNT_WORK = {
1938 WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
1939 WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
1940 };
1941
1942 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001943 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001944 public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001945 final boolean keyguardOn = keyguardOn();
Jeff Brown1f245102010-11-18 20:53:46 -08001946 final int keyCode = event.getKeyCode();
1947 final int repeatCount = event.getRepeatCount();
1948 final int metaState = event.getMetaState();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001949 final int flags = event.getFlags();
Jeff Brown1f245102010-11-18 20:53:46 -08001950 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
1951 final boolean canceled = event.isCanceled();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001952
Jeff Brown40013652012-05-16 21:22:36 -07001953 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001954 Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount="
Jeff Brownfd23e3e2012-05-09 13:34:28 -07001955 + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed
1956 + " canceled=" + canceled);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001957 }
1958
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001959 // If we think we might have a volume down & power key chord on the way
1960 // but we're not sure, then tell the dispatcher to wait a little while and
1961 // try again later before dispatching.
Christopher Tatee90585f2012-03-05 18:56:25 -08001962 if (mScreenshotChordEnabled && (flags & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001963 if (mVolumeDownKeyTriggered && !mPowerKeyTriggered) {
1964 final long now = SystemClock.uptimeMillis();
1965 final long timeoutTime = mVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS;
1966 if (now < timeoutTime) {
1967 return timeoutTime - now;
1968 }
1969 }
1970 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
1971 && mVolumeDownKeyConsumedByScreenshotChord) {
1972 if (!down) {
1973 mVolumeDownKeyConsumedByScreenshotChord = false;
1974 }
1975 return -1;
1976 }
1977 }
1978
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001979 // First we always handle the home key here, so applications
1980 // can never break it, although if keyguard is on, we do let
1981 // it handle it, because that gives us the correct 5 second
1982 // timeout.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001983 if (keyCode == KeyEvent.KEYCODE_HOME) {
Michael Jurka7f2668c2012-03-27 07:49:52 -07001984
Jeff Brown49ed71d2010-12-06 17:13:33 -08001985 // If we have released the home key, and didn't do anything else
1986 // while it was pressed, then it is time to go home!
Michael Jurka7f2668c2012-03-27 07:49:52 -07001987 if (!down) {
Jeff Browncaca8812013-05-09 13:34:33 -07001988 cancelPreloadRecentApps();
1989
Jeff Brown49ed71d2010-12-06 17:13:33 -08001990 mHomePressed = false;
Jeff Browncaca8812013-05-09 13:34:33 -07001991 if (mHomeConsumed) {
1992 mHomeConsumed = false;
Michael Jurka7f2668c2012-03-27 07:49:52 -07001993 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08001994 }
Jeff Browncaca8812013-05-09 13:34:33 -07001995
1996 if (canceled) {
1997 Log.i(TAG, "Ignoring HOME; event canceled.");
1998 return -1;
1999 }
2000
2001 // If an incoming call is ringing, HOME is totally disabled.
2002 // (The user is already on the InCallScreen at this point,
2003 // and his ONLY options are to answer or reject the call.)
2004 try {
2005 ITelephony telephonyService = getTelephonyService();
2006 if (telephonyService != null && telephonyService.isRinging()) {
2007 Log.i(TAG, "Ignoring HOME; there's a ringing incoming call.");
2008 return -1;
2009 }
2010 } catch (RemoteException ex) {
2011 Log.w(TAG, "RemoteException from getPhoneInterface()", ex);
2012 }
2013
2014 // Delay handling home if a double-tap is possible.
2015 if (mDoubleTapOnHomeBehavior != DOUBLE_TAP_HOME_NOTHING) {
2016 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); // just in case
2017 mHomeDoubleTapPending = true;
2018 mHandler.postDelayed(mHomeDoubleTapTimeoutRunnable,
2019 ViewConfiguration.getDoubleTapTimeout());
2020 return -1;
2021 }
2022
2023 // Go home!
2024 launchHomeFromHotKey();
2025 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002026 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002027
2028 // If a system window has focus, then it doesn't make sense
2029 // right now to interact with applications.
2030 WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null;
2031 if (attrs != null) {
2032 final int type = attrs.type;
2033 if (type == WindowManager.LayoutParams.TYPE_KEYGUARD
Jim Miller5ecd8112013-01-09 18:50:26 -08002034 || type == WindowManager.LayoutParams.TYPE_KEYGUARD_SCRIM
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002035 || type == WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG) {
2036 // the "app" is keyguard, so give it the key
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002037 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002038 }
2039 final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length;
2040 for (int i=0; i<typeCount; i++) {
2041 if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) {
2042 // don't do anything, but also don't pass it to the app
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002043 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002044 }
2045 }
2046 }
Jeff Browncaca8812013-05-09 13:34:33 -07002047
2048 // Remember that home is pressed and handle special actions.
2049 if (repeatCount == 0) {
2050 mHomePressed = true;
2051 if (mHomeDoubleTapPending) {
2052 mHomeDoubleTapPending = false;
2053 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable);
2054 handleDoubleTapOnHome();
2055 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI
2056 || mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
2057 preloadRecentApps();
Michael Jurka7f2668c2012-03-27 07:49:52 -07002058 }
Jeff Browncaca8812013-05-09 13:34:33 -07002059 } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) {
2060 if (!keyguardOn) {
2061 handleLongPressOnHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002062 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002063 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002064 return -1;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002065 } else if (keyCode == KeyEvent.KEYCODE_MENU) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002066 // Hijack modified menu keys for debugging features
2067 final int chordBug = KeyEvent.META_SHIFT_ON;
2068
2069 if (down && repeatCount == 0) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002070 if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002071 Intent intent = new Intent(Intent.ACTION_BUG_REPORT);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002072 mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT,
2073 null, null, null, 0, null, null);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002074 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002075 } else if (SHOW_PROCESSES_ON_ALT_MENU &&
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002076 (metaState & KeyEvent.META_ALT_ON) == KeyEvent.META_ALT_ON) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002077 Intent service = new Intent();
2078 service.setClassName(mContext, "com.android.server.LoadAverageService");
2079 ContentResolver res = mContext.getContentResolver();
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002080 boolean shown = Settings.Global.getInt(
2081 res, Settings.Global.SHOW_PROCESSES, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002082 if (!shown) {
2083 mContext.startService(service);
2084 } else {
2085 mContext.stopService(service);
2086 }
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002087 Settings.Global.putInt(
2088 res, Settings.Global.SHOW_PROCESSES, shown ? 0 : 1);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002089 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002090 }
2091 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002092 } else if (keyCode == KeyEvent.KEYCODE_SEARCH) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002093 if (down) {
2094 if (repeatCount == 0) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002095 mSearchKeyShortcutPending = true;
2096 mConsumeSearchKeyUp = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002097 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002098 } else {
2099 mSearchKeyShortcutPending = false;
2100 if (mConsumeSearchKeyUp) {
2101 mConsumeSearchKeyUp = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002102 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002103 }
2104 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002105 return 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002106 } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) {
Michael Wrightc9ebea72013-01-16 19:25:02 -08002107 if (!keyguardOn) {
Jeff Browncaca8812013-05-09 13:34:33 -07002108 if (down && repeatCount == 0) {
2109 preloadRecentApps();
2110 } else if (!down) {
2111 toggleRecentApps();
Michael Wrightc9ebea72013-01-16 19:25:02 -08002112 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002113 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002114 return -1;
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002115 } else if (keyCode == KeyEvent.KEYCODE_ASSIST) {
2116 if (down) {
2117 if (repeatCount == 0) {
2118 mAssistKeyLongPressed = false;
2119 } else if (repeatCount == 1) {
2120 mAssistKeyLongPressed = true;
2121 if (!keyguardOn) {
2122 launchAssistLongPressAction();
2123 }
2124 }
2125 } else {
2126 if (mAssistKeyLongPressed) {
2127 mAssistKeyLongPressed = false;
2128 } else {
2129 if (!keyguardOn) {
2130 launchAssistAction();
2131 }
2132 }
2133 }
2134 return -1;
Jeff Sharkey2991fa32012-12-05 18:06:43 -08002135 } else if (keyCode == KeyEvent.KEYCODE_SYSRQ) {
2136 if (down && repeatCount == 0) {
2137 mHandler.post(mScreenshotRunnable);
2138 }
2139 return -1;
Michael Wrightb854e242013-02-05 17:54:02 -08002140 } else if (keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP
2141 || keyCode == KeyEvent.KEYCODE_BRIGHTNESS_DOWN) {
2142 if (down) {
2143 int direction = keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP ? 1 : -1;
2144
2145 // Disable autobrightness if it's on
2146 int auto = Settings.System.getIntForUser(
2147 mContext.getContentResolver(),
2148 Settings.System.SCREEN_BRIGHTNESS_MODE,
2149 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2150 UserHandle.USER_CURRENT_OR_SELF);
2151 if (auto != 0) {
2152 Settings.System.putIntForUser(mContext.getContentResolver(),
2153 Settings.System.SCREEN_BRIGHTNESS_MODE,
2154 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2155 UserHandle.USER_CURRENT_OR_SELF);
2156 }
2157
2158 int min = mPowerManager.getMinimumScreenBrightnessSetting();
2159 int max = mPowerManager.getMaximumScreenBrightnessSetting();
2160 int step = (max - min + BRIGHTNESS_STEPS - 1) / BRIGHTNESS_STEPS * direction;
2161 int brightness = Settings.System.getIntForUser(mContext.getContentResolver(),
2162 Settings.System.SCREEN_BRIGHTNESS,
2163 mPowerManager.getDefaultScreenBrightnessSetting(),
2164 UserHandle.USER_CURRENT_OR_SELF);
2165 brightness += step;
2166 // Make sure we don't go beyond the limits.
2167 brightness = Math.min(max, brightness);
2168 brightness = Math.max(min, brightness);
2169
2170 Settings.System.putIntForUser(mContext.getContentResolver(),
2171 Settings.System.SCREEN_BRIGHTNESS, brightness,
2172 UserHandle.USER_CURRENT_OR_SELF);
2173 Intent intent = new Intent(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG);
2174 mContext.sendBroadcastAsUser(intent, UserHandle.CURRENT_OR_SELF);
2175 }
2176 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002177 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002178
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002179 // Shortcuts are invoked through Search+key, so intercept those here
Jeff Browncaab4d02010-12-09 22:13:41 -08002180 // Any printing key that is chorded with Search should be consumed
2181 // even if no shortcut was invoked. This prevents text from being
2182 // inadvertently inserted when using a keyboard that has built-in macro
2183 // shortcut keys (that emit Search+x) and some of them are not registered.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002184 if (mSearchKeyShortcutPending) {
Jeff Browncaab4d02010-12-09 22:13:41 -08002185 final KeyCharacterMap kcm = event.getKeyCharacterMap();
2186 if (kcm.isPrintingKey(keyCode)) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002187 mConsumeSearchKeyUp = true;
2188 mSearchKeyShortcutPending = false;
Jeff Browncaab4d02010-12-09 22:13:41 -08002189 if (down && repeatCount == 0 && !keyguardOn) {
2190 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState);
2191 if (shortcutIntent != null) {
2192 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002193 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002194 mContext.startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002195 } catch (ActivityNotFoundException ex) {
2196 Slog.w(TAG, "Dropping shortcut key combination because "
2197 + "the activity to which it is registered was not found: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002198 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode), ex);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002199 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002200 } else {
2201 Slog.i(TAG, "Dropping unregistered shortcut key combination: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002202 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002203 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002204 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002205 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002206 }
2207 }
2208
Jeff Brown68b909d2011-12-07 16:36:01 -08002209 // Invoke shortcuts using Meta.
Jeff Brown602ab322012-05-16 13:33:47 -07002210 if (down && repeatCount == 0 && !keyguardOn
Jeff Brown68b909d2011-12-07 16:36:01 -08002211 && (metaState & KeyEvent.META_META_ON) != 0) {
2212 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brown602ab322012-05-16 13:33:47 -07002213 if (kcm.isPrintingKey(keyCode)) {
2214 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode,
2215 metaState & ~(KeyEvent.META_META_ON
2216 | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON));
2217 if (shortcutIntent != null) {
2218 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2219 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002220 mContext.startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brown602ab322012-05-16 13:33:47 -07002221 } catch (ActivityNotFoundException ex) {
2222 Slog.w(TAG, "Dropping shortcut key combination because "
2223 + "the activity to which it is registered was not found: "
2224 + "META+" + KeyEvent.keyCodeToString(keyCode), ex);
2225 }
2226 return -1;
Jeff Brown68b909d2011-12-07 16:36:01 -08002227 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002228 }
2229 }
2230
Jeff Brown6651a632011-11-28 12:59:11 -08002231 // Handle application launch keys.
Jeff Brown602ab322012-05-16 13:33:47 -07002232 if (down && repeatCount == 0 && !keyguardOn) {
Jeff Brown6651a632011-11-28 12:59:11 -08002233 String category = sApplicationLaunchKeyCategories.get(keyCode);
2234 if (category != null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -08002235 Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category);
Jeff Brown6651a632011-11-28 12:59:11 -08002236 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2237 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002238 mContext.startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brown6651a632011-11-28 12:59:11 -08002239 } catch (ActivityNotFoundException ex) {
2240 Slog.w(TAG, "Dropping application launch key because "
2241 + "the activity to which it is registered was not found: "
2242 + "keyCode=" + keyCode + ", category=" + category, ex);
2243 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002244 return -1;
Jeff Brown6651a632011-11-28 12:59:11 -08002245 }
2246 }
2247
Jeff Brown68b909d2011-12-07 16:36:01 -08002248 // Display task switcher for ALT-TAB or Meta-TAB.
2249 if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_TAB) {
Jeff Brown602ab322012-05-16 13:33:47 -07002250 if (mRecentAppsDialogHeldModifiers == 0 && !keyguardOn) {
Jeff Brown68b909d2011-12-07 16:36:01 -08002251 final int shiftlessModifiers = event.getModifiers() & ~KeyEvent.META_SHIFT_MASK;
2252 if (KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_ALT_ON)
2253 || KeyEvent.metaStateHasModifiers(
2254 shiftlessModifiers, KeyEvent.META_META_ON)) {
2255 mRecentAppsDialogHeldModifiers = shiftlessModifiers;
2256 showOrHideRecentAppsDialog(RECENT_APPS_BEHAVIOR_EXIT_TOUCH_MODE_AND_SHOW);
2257 return -1;
2258 }
2259 }
2260 } else if (!down && mRecentAppsDialogHeldModifiers != 0
2261 && (metaState & mRecentAppsDialogHeldModifiers) == 0) {
2262 mRecentAppsDialogHeldModifiers = 0;
Jeff Brown602ab322012-05-16 13:33:47 -07002263 showOrHideRecentAppsDialog(keyguardOn ? RECENT_APPS_BEHAVIOR_DISMISS :
2264 RECENT_APPS_BEHAVIOR_DISMISS_AND_SWITCH);
Jeff Brown68b909d2011-12-07 16:36:01 -08002265 }
2266
Jeff Browncf39bdf2012-05-18 14:41:19 -07002267 // Handle keyboard language switching.
2268 if (down && repeatCount == 0
2269 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2270 || (keyCode == KeyEvent.KEYCODE_SPACE
2271 && (metaState & KeyEvent.META_CTRL_MASK) != 0))) {
2272 int direction = (metaState & KeyEvent.META_SHIFT_MASK) != 0 ? -1 : 1;
2273 mWindowManagerFuncs.switchKeyboardLayout(event.getDeviceId(), direction);
2274 return -1;
2275 }
2276 if (mLanguageSwitchKeyPressed && !down
2277 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2278 || keyCode == KeyEvent.KEYCODE_SPACE)) {
2279 mLanguageSwitchKeyPressed = false;
2280 return -1;
2281 }
2282
Justin Kohd378ad72013-04-01 12:18:26 -07002283 if (mGlobalKeyManager.handleGlobalKey(mContext, keyCode, event)) {
2284 return -1;
2285 }
2286
Jeff Brown68b909d2011-12-07 16:36:01 -08002287 // Let the application handle the key.
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002288 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002289 }
2290
Jeff Brown3915bb82010-11-05 15:02:16 -07002291 /** {@inheritDoc} */
2292 @Override
Jeff Brown49ed71d2010-12-06 17:13:33 -08002293 public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown54875002011-04-06 15:33:01 -07002294 // Note: This method is only called if the initial down was unhandled.
Jeff Brown40013652012-05-16 21:22:36 -07002295 if (DEBUG_INPUT) {
Jeff Brown1f245102010-11-18 20:53:46 -08002296 Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction()
2297 + ", flags=" + event.getFlags()
2298 + ", keyCode=" + event.getKeyCode()
2299 + ", scanCode=" + event.getScanCode()
2300 + ", metaState=" + event.getMetaState()
2301 + ", repeatCount=" + event.getRepeatCount()
2302 + ", policyFlags=" + policyFlags);
Jeff Brown3915bb82010-11-05 15:02:16 -07002303 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002304
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002305 KeyEvent fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002306 if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
2307 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002308 final int keyCode = event.getKeyCode();
2309 final int metaState = event.getMetaState();
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002310 final boolean initialDown = event.getAction() == KeyEvent.ACTION_DOWN
2311 && event.getRepeatCount() == 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002312
Jeff Brown54875002011-04-06 15:33:01 -07002313 // Check for fallback actions specified by the key character map.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002314 final FallbackAction fallbackAction;
2315 if (initialDown) {
2316 fallbackAction = kcm.getFallbackAction(keyCode, metaState);
2317 } else {
2318 fallbackAction = mFallbackActions.get(keyCode);
2319 }
2320
2321 if (fallbackAction != null) {
Jeff Brown40013652012-05-16 21:22:36 -07002322 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002323 Slog.d(TAG, "Fallback: keyCode=" + fallbackAction.keyCode
2324 + " metaState=" + Integer.toHexString(fallbackAction.metaState));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002325 }
2326
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002327 final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK;
2328 fallbackEvent = KeyEvent.obtain(
Jeff Brown49ed71d2010-12-06 17:13:33 -08002329 event.getDownTime(), event.getEventTime(),
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002330 event.getAction(), fallbackAction.keyCode,
2331 event.getRepeatCount(), fallbackAction.metaState,
Jeff Brown49ed71d2010-12-06 17:13:33 -08002332 event.getDeviceId(), event.getScanCode(),
2333 flags, event.getSource(), null);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002334
2335 if (!interceptFallback(win, fallbackEvent, policyFlags)) {
2336 fallbackEvent.recycle();
2337 fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002338 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002339
2340 if (initialDown) {
2341 mFallbackActions.put(keyCode, fallbackAction);
2342 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2343 mFallbackActions.remove(keyCode);
2344 fallbackAction.recycle();
2345 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002346 }
2347 }
2348
Jeff Brown40013652012-05-16 21:22:36 -07002349 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002350 if (fallbackEvent == null) {
2351 Slog.d(TAG, "No fallback.");
2352 } else {
2353 Slog.d(TAG, "Performing fallback: " + fallbackEvent);
2354 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002355 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002356 return fallbackEvent;
Jeff Brown3915bb82010-11-05 15:02:16 -07002357 }
2358
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002359 private boolean interceptFallback(WindowState win, KeyEvent fallbackEvent, int policyFlags) {
2360 int actions = interceptKeyBeforeQueueing(fallbackEvent, policyFlags, true);
2361 if ((actions & ACTION_PASS_TO_USER) != 0) {
2362 long delayMillis = interceptKeyBeforeDispatching(
2363 win, fallbackEvent, policyFlags);
2364 if (delayMillis == 0) {
2365 return true;
2366 }
2367 }
2368 return false;
Jeff Brown6f2fba42011-02-19 01:08:02 -08002369 }
2370
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002371 private void launchAssistLongPressAction() {
2372 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
2373 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
2374
2375 // launch the search activity
2376 Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS);
2377 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2378 try {
Jim Miller45308b12012-06-18 19:23:39 -07002379 // TODO: This only stops the factory-installed search manager.
2380 // Need to formalize an API to handle others
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002381 SearchManager searchManager = getSearchManager();
2382 if (searchManager != null) {
2383 searchManager.stopSearch();
2384 }
Michael Wright43e27f72013-04-10 14:06:48 -07002385 mContext.startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002386 } catch (ActivityNotFoundException e) {
2387 Slog.w(TAG, "No activity to handle assist long press action.", e);
2388 }
2389 }
2390
2391 private void launchAssistAction() {
2392 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
Amith Yamasanic1d07a42012-08-14 09:32:02 -07002393 Intent intent = ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE))
Dianne Hackbornf9c5e0f2013-01-23 14:39:13 -08002394 .getAssistIntent(mContext, true, UserHandle.USER_CURRENT);
Jim Miller45308b12012-06-18 19:23:39 -07002395 if (intent != null) {
2396 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
2397 | Intent.FLAG_ACTIVITY_SINGLE_TOP
2398 | Intent.FLAG_ACTIVITY_CLEAR_TOP);
2399 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002400 mContext.startActivityAsUser(intent, UserHandle.CURRENT);
Jim Miller45308b12012-06-18 19:23:39 -07002401 } catch (ActivityNotFoundException e) {
2402 Slog.w(TAG, "No activity to handle assist action.", e);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002403 }
2404 }
2405 }
2406
2407 private SearchManager getSearchManager() {
2408 if (mSearchManager == null) {
2409 mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
2410 }
2411 return mSearchManager;
2412 }
2413
Jeff Browncaca8812013-05-09 13:34:33 -07002414 private void preloadRecentApps() {
2415 mPreloadedRecentApps = true;
2416 try {
2417 IStatusBarService statusbar = getStatusBarService();
2418 if (statusbar != null) {
2419 statusbar.preloadRecentApps();
2420 }
2421 } catch (RemoteException e) {
2422 Slog.e(TAG, "RemoteException when preloading recent apps", e);
2423 // re-acquire status bar service next time it is needed.
2424 mStatusBarService = null;
2425 }
2426 }
2427
2428 private void cancelPreloadRecentApps() {
2429 if (mPreloadedRecentApps) {
2430 mPreloadedRecentApps = false;
2431 try {
2432 IStatusBarService statusbar = getStatusBarService();
2433 if (statusbar != null) {
2434 statusbar.cancelPreloadRecentApps();
2435 }
2436 } catch (RemoteException e) {
2437 Slog.e(TAG, "RemoteException when showing recent apps", e);
2438 // re-acquire status bar service next time it is needed.
2439 mStatusBarService = null;
2440 }
2441 }
2442 }
2443
2444 private void toggleRecentApps() {
2445 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
2446 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_RECENT_APPS);
2447 try {
2448 IStatusBarService statusbar = getStatusBarService();
2449 if (statusbar != null) {
2450 statusbar.toggleRecentApps();
2451 }
2452 } catch (RemoteException e) {
2453 Slog.e(TAG, "RemoteException when showing recent apps", e);
2454 // re-acquire status bar service next time it is needed.
2455 mStatusBarService = null;
2456 }
2457 }
2458
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002459 /**
2460 * A home key -> launch home action was detected. Take the appropriate action
2461 * given the situation with the keyguard.
2462 */
2463 void launchHomeFromHotKey() {
Jim Miller5ecd8112013-01-09 18:50:26 -08002464 if (mKeyguardDelegate != null && mKeyguardDelegate.isShowingAndNotHidden()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002465 // don't launch home if keyguard showing
Jim Miller5ecd8112013-01-09 18:50:26 -08002466 } else if (!mHideLockScreen && mKeyguardDelegate.isInputRestricted()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002467 // when in keyguard restricted mode, must first verify unlock
2468 // before launching home
Jim Miller5ecd8112013-01-09 18:50:26 -08002469 mKeyguardDelegate.verifyUnlock(new OnKeyguardExitResult() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002470 public void onKeyguardExitResult(boolean success) {
2471 if (success) {
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07002472 try {
2473 ActivityManagerNative.getDefault().stopAppSwitches();
2474 } catch (RemoteException e) {
2475 }
Joe Onoratof275f0c2009-11-24 16:11:13 -05002476 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07002477 startDockOrHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002478 }
2479 }
2480 });
2481 } else {
2482 // no keyguard stuff to worry about, just launch home!
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07002483 try {
2484 ActivityManagerNative.getDefault().stopAppSwitches();
2485 } catch (RemoteException e) {
2486 }
Joe Onoratof275f0c2009-11-24 16:11:13 -05002487 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07002488 startDockOrHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002489 }
2490 }
2491
John Spurlock04db1762013-05-13 12:46:41 -04002492 private final Runnable mClearHideNavigationFlag = new Runnable() {
2493 @Override
2494 public void run() {
2495 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
2496 // Clear flags.
2497 mForceClearedSystemUiFlags &=
2498 ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
2499 }
2500 mWindowManagerFuncs.reevaluateStatusBarVisibility();
Dianne Hackborne26ab702011-10-16 13:21:33 -07002501 }
2502 };
2503
2504 /**
2505 * Input handler used while nav bar is hidden. Captures any touch on the screen,
2506 * to determine when the nav bar should be shown and prevent applications from
2507 * receiving those touches.
2508 */
Jeff Brown32cbc38552011-12-01 14:01:49 -08002509 final class HideNavInputEventReceiver extends InputEventReceiver {
2510 public HideNavInputEventReceiver(InputChannel inputChannel, Looper looper) {
2511 super(inputChannel, looper);
2512 }
2513
Dianne Hackborndf89e652011-10-06 22:35:11 -07002514 @Override
Jeff Brown32cbc38552011-12-01 14:01:49 -08002515 public void onInputEvent(InputEvent event) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07002516 boolean handled = false;
2517 try {
Jeff Brown4952dfd2011-11-30 19:23:22 -08002518 if (event instanceof MotionEvent
2519 && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
2520 final MotionEvent motionEvent = (MotionEvent)event;
2521 if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07002522 // When the user taps down, we re-show the nav bar.
2523 boolean changed = false;
John Spurlock04db1762013-05-13 12:46:41 -04002524 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002525 // Any user activity always causes us to show the
2526 // navigation controls, if they had been hidden.
2527 // We also clear the low profile and only content
2528 // flags so that tapping on the screen will atomically
2529 // restore all currently hidden screen decorations.
2530 int newVal = mResettingSystemUiFlags |
2531 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
2532 View.SYSTEM_UI_FLAG_LOW_PROFILE |
2533 View.SYSTEM_UI_FLAG_FULLSCREEN;
Dianne Hackborne26ab702011-10-16 13:21:33 -07002534 if (mResettingSystemUiFlags != newVal) {
2535 mResettingSystemUiFlags = newVal;
Dianne Hackborndf89e652011-10-06 22:35:11 -07002536 changed = true;
2537 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07002538 // We don't allow the system's nav bar to be hidden
2539 // again for 1 second, to prevent applications from
2540 // spamming us and keeping it from being shown.
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002541 newVal = mForceClearedSystemUiFlags |
2542 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
Dianne Hackborne26ab702011-10-16 13:21:33 -07002543 if (mForceClearedSystemUiFlags != newVal) {
2544 mForceClearedSystemUiFlags = newVal;
2545 changed = true;
John Spurlock04db1762013-05-13 12:46:41 -04002546 mHandler.postDelayed(mClearHideNavigationFlag, 1000);
Dianne Hackborne26ab702011-10-16 13:21:33 -07002547 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07002548 }
2549 if (changed) {
2550 mWindowManagerFuncs.reevaluateStatusBarVisibility();
2551 }
2552 }
2553 }
2554 } finally {
Jeff Brown32cbc38552011-12-01 14:01:49 -08002555 finishInputEvent(event, handled);
Dianne Hackborndf89e652011-10-06 22:35:11 -07002556 }
2557 }
Jeff Brown32cbc38552011-12-01 14:01:49 -08002558 }
2559 final InputEventReceiver.Factory mHideNavInputEventReceiverFactory =
2560 new InputEventReceiver.Factory() {
2561 @Override
2562 public InputEventReceiver createInputEventReceiver(
2563 InputChannel inputChannel, Looper looper) {
2564 return new HideNavInputEventReceiver(inputChannel, looper);
2565 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07002566 };
2567
2568 @Override
2569 public int adjustSystemUiVisibilityLw(int visibility) {
John Spurlock5b9145b2013-08-20 15:13:47 -04002570 mStatusBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
2571 mNavigationBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
John Spurlock27735a42013-08-14 17:57:38 -04002572
Dianne Hackborndf89e652011-10-06 22:35:11 -07002573 // Reset any bits in mForceClearingStatusBarVisibility that
2574 // are now clear.
Dianne Hackborne26ab702011-10-16 13:21:33 -07002575 mResettingSystemUiFlags &= visibility;
Dianne Hackborndf89e652011-10-06 22:35:11 -07002576 // Clear any bits in the new visibility that are currently being
2577 // force cleared, before reporting it.
Dianne Hackborne26ab702011-10-16 13:21:33 -07002578 return visibility & ~mResettingSystemUiFlags
2579 & ~mForceClearedSystemUiFlags;
Dianne Hackborndf89e652011-10-06 22:35:11 -07002580 }
2581
Craig Mautner69b08182012-09-05 13:07:13 -07002582 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002583 public void getContentInsetHintLw(WindowManager.LayoutParams attrs, Rect contentInset) {
John Spurlockc6d1c602014-01-17 15:22:06 -05002584 final int fl = PolicyControl.getWindowFlags(null, attrs);
John Spurlock1db8b682014-02-18 11:18:59 -05002585 final int sysuiVis = PolicyControl.getSystemUiVisibility(null, attrs);
2586 final int systemUiVisibility = (sysuiVis | attrs.subtreeSystemUiVisibility);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002587
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002588 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002589 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002590 int availRight, availBottom;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07002591 if (canHideNavigationBar() &&
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002592 (systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002593 availRight = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
2594 availBottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
2595 } else {
2596 availRight = mRestrictedScreenLeft + mRestrictedScreenWidth;
2597 availBottom = mRestrictedScreenTop + mRestrictedScreenHeight;
2598 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002599 if ((systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
2600 if ((fl & FLAG_FULLSCREEN) != 0) {
2601 contentInset.set(mStableFullscreenLeft, mStableFullscreenTop,
2602 availRight - mStableFullscreenRight,
2603 availBottom - mStableFullscreenBottom);
2604 } else {
2605 contentInset.set(mStableLeft, mStableTop,
2606 availRight - mStableRight, availBottom - mStableBottom);
2607 }
Dianne Hackbornc652de82013-02-15 16:32:56 -08002608 } else if ((fl & FLAG_FULLSCREEN) != 0 || (fl & FLAG_LAYOUT_IN_OVERSCAN) != 0) {
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002609 contentInset.setEmpty();
2610 } else if ((systemUiVisibility & (View.SYSTEM_UI_FLAG_FULLSCREEN
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002611 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)) == 0) {
2612 contentInset.set(mCurLeft, mCurTop,
2613 availRight - mCurRight, availBottom - mCurBottom);
2614 } else {
2615 contentInset.set(mCurLeft, mCurTop,
2616 availRight - mCurRight, availBottom - mCurBottom);
2617 }
2618 return;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002619 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002620 contentInset.setEmpty();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002621 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002622
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002623 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07002624 @Override
2625 public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight,
2626 int displayRotation) {
Dianne Hackbornc652de82013-02-15 16:32:56 -08002627 final int overscanLeft, overscanTop, overscanRight, overscanBottom;
2628 if (isDefaultDisplay) {
2629 switch (displayRotation) {
2630 case Surface.ROTATION_90:
2631 overscanLeft = mOverscanTop;
2632 overscanTop = mOverscanRight;
2633 overscanRight = mOverscanBottom;
2634 overscanBottom = mOverscanLeft;
2635 break;
2636 case Surface.ROTATION_180:
2637 overscanLeft = mOverscanRight;
2638 overscanTop = mOverscanBottom;
2639 overscanRight = mOverscanLeft;
2640 overscanBottom = mOverscanTop;
2641 break;
2642 case Surface.ROTATION_270:
2643 overscanLeft = mOverscanBottom;
2644 overscanTop = mOverscanLeft;
2645 overscanRight = mOverscanTop;
2646 overscanBottom = mOverscanRight;
2647 break;
2648 default:
2649 overscanLeft = mOverscanLeft;
2650 overscanTop = mOverscanTop;
2651 overscanRight = mOverscanRight;
2652 overscanBottom = mOverscanBottom;
2653 break;
2654 }
2655 } else {
2656 overscanLeft = 0;
2657 overscanTop = 0;
2658 overscanRight = 0;
2659 overscanBottom = 0;
2660 }
Dianne Hackborn313440842013-02-19 19:22:59 -08002661 mOverscanScreenLeft = mRestrictedOverscanScreenLeft = 0;
2662 mOverscanScreenTop = mRestrictedOverscanScreenTop = 0;
2663 mOverscanScreenWidth = mRestrictedOverscanScreenWidth = displayWidth;
2664 mOverscanScreenHeight = mRestrictedOverscanScreenHeight = displayHeight;
Dianne Hackbornc652de82013-02-15 16:32:56 -08002665 mSystemLeft = 0;
2666 mSystemTop = 0;
2667 mSystemRight = displayWidth;
2668 mSystemBottom = displayHeight;
2669 mUnrestrictedScreenLeft = overscanLeft;
2670 mUnrestrictedScreenTop = overscanTop;
2671 mUnrestrictedScreenWidth = displayWidth - overscanLeft - overscanRight;
2672 mUnrestrictedScreenHeight = displayHeight - overscanTop - overscanBottom;
2673 mRestrictedScreenLeft = mUnrestrictedScreenLeft;
2674 mRestrictedScreenTop = mUnrestrictedScreenTop;
John Spurlockad3e6cb2013-04-30 08:47:43 -04002675 mRestrictedScreenWidth = mSystemGestures.screenWidth = mUnrestrictedScreenWidth;
2676 mRestrictedScreenHeight = mSystemGestures.screenHeight = mUnrestrictedScreenHeight;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002677 mDockLeft = mContentLeft = mStableLeft = mStableFullscreenLeft
Dianne Hackbornc652de82013-02-15 16:32:56 -08002678 = mCurLeft = mUnrestrictedScreenLeft;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002679 mDockTop = mContentTop = mStableTop = mStableFullscreenTop
Dianne Hackbornc652de82013-02-15 16:32:56 -08002680 = mCurTop = mUnrestrictedScreenTop;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002681 mDockRight = mContentRight = mStableRight = mStableFullscreenRight
Dianne Hackbornc652de82013-02-15 16:32:56 -08002682 = mCurRight = displayWidth - overscanRight;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002683 mDockBottom = mContentBottom = mStableBottom = mStableFullscreenBottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08002684 = mCurBottom = displayHeight - overscanBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002685 mDockLayer = 0x10000000;
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002686 mStatusBarLayer = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002687
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002688 // start with the current dock rect, which will be (0,0,displayWidth,displayHeight)
2689 final Rect pf = mTmpParentFrame;
2690 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002691 final Rect of = mTmpOverscanFrame;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002692 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04002693 final Rect dcf = mTmpDecorFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002694 pf.left = df.left = of.left = vf.left = mDockLeft;
2695 pf.top = df.top = of.top = vf.top = mDockTop;
2696 pf.right = df.right = of.right = vf.right = mDockRight;
2697 pf.bottom = df.bottom = of.bottom = vf.bottom = mDockBottom;
John Spurlock46646232013-09-30 22:32:42 -04002698 dcf.setEmpty(); // Decor frame N/A for system bars.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002699
Craig Mautner69b08182012-09-05 13:07:13 -07002700 if (isDefaultDisplay) {
2701 // For purposes of putting out fake window up to steal focus, we will
2702 // drive nav being hidden only by whether it is requested.
John Spurlocke1f366f2013-08-05 12:22:40 -04002703 final int sysui = mLastSystemUiFlags;
2704 boolean navVisible = (sysui & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0;
John Spurlockbd957402013-10-03 11:38:39 -04002705 boolean navTranslucent = (sysui & View.NAVIGATION_BAR_TRANSLUCENT) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04002706 boolean immersive = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
2707 boolean immersiveSticky = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
2708 boolean navAllowedHidden = immersive || immersiveSticky;
2709 navTranslucent &= !immersiveSticky; // transient trumps translucent
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04002710 navTranslucent &= areTranslucentBarsAllowed();
Dianne Hackborne26ab702011-10-16 13:21:33 -07002711
Craig Mautner69b08182012-09-05 13:07:13 -07002712 // When the navigation bar isn't visible, we put up a fake
2713 // input window to catch all touch events. This way we can
2714 // detect when the user presses anywhere to bring back the nav
2715 // bar and ensure the application doesn't see the event.
John Spurlockf1a36642013-10-12 17:50:42 -04002716 if (navVisible || navAllowedHidden) {
Craig Mautner69b08182012-09-05 13:07:13 -07002717 if (mHideNavFakeWindow != null) {
2718 mHideNavFakeWindow.dismiss();
2719 mHideNavFakeWindow = null;
2720 }
2721 } else if (mHideNavFakeWindow == null) {
2722 mHideNavFakeWindow = mWindowManagerFuncs.addFakeWindow(
2723 mHandler.getLooper(), mHideNavInputEventReceiverFactory,
Adam Lesinski95c42972013-10-02 10:13:27 -07002724 "hidden nav", WindowManager.LayoutParams.TYPE_HIDDEN_NAV_CONSUMER, 0,
Craig Mautner69b08182012-09-05 13:07:13 -07002725 0, false, false, true);
Dianne Hackborne26ab702011-10-16 13:21:33 -07002726 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07002727
Craig Mautner69b08182012-09-05 13:07:13 -07002728 // For purposes of positioning and showing the nav bar, if we have
2729 // decided that it can't be hidden (because of the screen aspect ratio),
2730 // then take that into account.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07002731 navVisible |= !canHideNavigationBar();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002732
John Spurlockad3e6cb2013-04-30 08:47:43 -04002733 boolean updateSysUiVisibility = false;
Craig Mautner69b08182012-09-05 13:07:13 -07002734 if (mNavigationBar != null) {
John Spurlock27735a42013-08-14 17:57:38 -04002735 boolean transientNavBarShowing = mNavigationBarController.isTransientShowing();
Craig Mautner69b08182012-09-05 13:07:13 -07002736 // Force the navigation bar to its appropriate place and
2737 // size. We need to do this directly, instead of relying on
2738 // it to bubble up from the nav bar, because this needs to
2739 // change atomically with screen rotations.
2740 mNavigationBarOnBottom = (!mNavigationBarCanMove || displayWidth < displayHeight);
2741 if (mNavigationBarOnBottom) {
2742 // It's a system nav bar or a portrait screen; nav bar goes on bottom.
Dianne Hackbornc652de82013-02-15 16:32:56 -08002743 int top = displayHeight - overscanBottom
2744 - mNavigationBarHeightForRotation[displayRotation];
2745 mTmpNavigationFrame.set(0, top, displayWidth, displayHeight - overscanBottom);
Craig Mautner69b08182012-09-05 13:07:13 -07002746 mStableBottom = mStableFullscreenBottom = mTmpNavigationFrame.top;
John Spurlockf95b89a2013-10-10 22:10:42 -04002747 if (transientNavBarShowing) {
John Spurlock27735a42013-08-14 17:57:38 -04002748 mNavigationBarController.setBarShowingLw(true);
John Spurlockad3e6cb2013-04-30 08:47:43 -04002749 } else if (navVisible) {
John Spurlock27735a42013-08-14 17:57:38 -04002750 mNavigationBarController.setBarShowingLw(true);
Craig Mautner69b08182012-09-05 13:07:13 -07002751 mDockBottom = mTmpNavigationFrame.top;
Dianne Hackborn313440842013-02-19 19:22:59 -08002752 mRestrictedScreenHeight = mDockBottom - mRestrictedScreenTop;
2753 mRestrictedOverscanScreenHeight = mDockBottom - mRestrictedOverscanScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07002754 } else {
2755 // We currently want to hide the navigation UI.
John Spurlock27735a42013-08-14 17:57:38 -04002756 mNavigationBarController.setBarShowingLw(false);
Craig Mautner69b08182012-09-05 13:07:13 -07002757 }
John Spurlockc6d1c602014-01-17 15:22:06 -05002758 if (navVisible && !navTranslucent && !navAllowedHidden
2759 && !mNavigationBar.isAnimatingLw()
John Spurlockbd957402013-10-03 11:38:39 -04002760 && !mNavigationBarController.wasRecentlyTranslucent()) {
John Spurlocke1f366f2013-08-05 12:22:40 -04002761 // If the opaque nav bar is currently requested to be visible,
Craig Mautner69b08182012-09-05 13:07:13 -07002762 // and not in the process of animating on or off, then
2763 // we can tell the app that it is covered by it.
2764 mSystemBottom = mTmpNavigationFrame.top;
2765 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002766 } else {
Craig Mautner69b08182012-09-05 13:07:13 -07002767 // Landscape screen; nav bar goes to the right.
Dianne Hackbornc652de82013-02-15 16:32:56 -08002768 int left = displayWidth - overscanRight
2769 - mNavigationBarWidthForRotation[displayRotation];
2770 mTmpNavigationFrame.set(left, 0, displayWidth - overscanRight, displayHeight);
Craig Mautner69b08182012-09-05 13:07:13 -07002771 mStableRight = mStableFullscreenRight = mTmpNavigationFrame.left;
John Spurlockf95b89a2013-10-10 22:10:42 -04002772 if (transientNavBarShowing) {
John Spurlock27735a42013-08-14 17:57:38 -04002773 mNavigationBarController.setBarShowingLw(true);
John Spurlockad3e6cb2013-04-30 08:47:43 -04002774 } else if (navVisible) {
John Spurlock27735a42013-08-14 17:57:38 -04002775 mNavigationBarController.setBarShowingLw(true);
Craig Mautner69b08182012-09-05 13:07:13 -07002776 mDockRight = mTmpNavigationFrame.left;
Dianne Hackborn313440842013-02-19 19:22:59 -08002777 mRestrictedScreenWidth = mDockRight - mRestrictedScreenLeft;
2778 mRestrictedOverscanScreenWidth = mDockRight - mRestrictedOverscanScreenLeft;
Craig Mautner69b08182012-09-05 13:07:13 -07002779 } else {
2780 // We currently want to hide the navigation UI.
John Spurlock27735a42013-08-14 17:57:38 -04002781 mNavigationBarController.setBarShowingLw(false);
Craig Mautner69b08182012-09-05 13:07:13 -07002782 }
John Spurlockbd957402013-10-03 11:38:39 -04002783 if (navVisible && !navTranslucent && !mNavigationBar.isAnimatingLw()
2784 && !mNavigationBarController.wasRecentlyTranslucent()) {
Craig Mautner69b08182012-09-05 13:07:13 -07002785 // If the nav bar is currently requested to be visible,
2786 // and not in the process of animating on or off, then
2787 // we can tell the app that it is covered by it.
2788 mSystemRight = mTmpNavigationFrame.left;
2789 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002790 }
Craig Mautner69b08182012-09-05 13:07:13 -07002791 // Make sure the content and current rectangles are updated to
2792 // account for the restrictions from the navigation bar.
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002793 mContentTop = mCurTop = mDockTop;
2794 mContentBottom = mCurBottom = mDockBottom;
2795 mContentLeft = mCurLeft = mDockLeft;
2796 mContentRight = mCurRight = mDockRight;
Craig Mautner69b08182012-09-05 13:07:13 -07002797 mStatusBarLayer = mNavigationBar.getSurfaceLayer();
2798 // And compute the final frame.
2799 mNavigationBar.computeFrameLw(mTmpNavigationFrame, mTmpNavigationFrame,
John Spurlock46646232013-09-30 22:32:42 -04002800 mTmpNavigationFrame, mTmpNavigationFrame, mTmpNavigationFrame, dcf);
Craig Mautnereda67292013-04-28 13:50:14 -07002801 if (DEBUG_LAYOUT) Slog.i(TAG, "mNavigationBar frame: " + mTmpNavigationFrame);
John Spurlock27735a42013-08-14 17:57:38 -04002802 if (mNavigationBarController.checkHiddenLw()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04002803 updateSysUiVisibility = true;
2804 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002805 }
Craig Mautnereda67292013-04-28 13:50:14 -07002806 if (DEBUG_LAYOUT) Slog.i(TAG, String.format("mDock rect: (%d,%d - %d,%d)",
Craig Mautner69b08182012-09-05 13:07:13 -07002807 mDockLeft, mDockTop, mDockRight, mDockBottom));
2808
2809 // decide where the status bar goes ahead of time
2810 if (mStatusBar != null) {
2811 // apply any navigation bar insets
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002812 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
2813 pf.top = df.top = of.top = mUnrestrictedScreenTop;
2814 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
2815 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight
2816 + mUnrestrictedScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07002817 vf.left = mStableLeft;
2818 vf.top = mStableTop;
2819 vf.right = mStableRight;
2820 vf.bottom = mStableBottom;
2821
2822 mStatusBarLayer = mStatusBar.getSurfaceLayer();
2823
2824 // Let the status bar determine its size.
John Spurlock46646232013-09-30 22:32:42 -04002825 mStatusBar.computeFrameLw(pf, df, vf, vf, vf, dcf);
Craig Mautner69b08182012-09-05 13:07:13 -07002826
2827 // For layout, the status bar is always at the top with our fixed height.
2828 mStableTop = mUnrestrictedScreenTop + mStatusBarHeight;
2829
John Spurlocke1f366f2013-08-05 12:22:40 -04002830 boolean statusBarTransient = (sysui & View.STATUS_BAR_TRANSIENT) != 0;
John Spurlockbd957402013-10-03 11:38:39 -04002831 boolean statusBarTranslucent = (sysui & View.STATUS_BAR_TRANSLUCENT) != 0;
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04002832 statusBarTranslucent &= areTranslucentBarsAllowed();
John Spurlock32beb2c2013-03-11 10:16:47 -04002833
Craig Mautner69b08182012-09-05 13:07:13 -07002834 // If the status bar is hidden, we don't want to cause
2835 // windows behind it to scroll.
John Spurlockeda1f692013-09-16 11:38:44 -04002836 if (mStatusBar.isVisibleLw() && !statusBarTransient) {
Craig Mautner69b08182012-09-05 13:07:13 -07002837 // Status bar may go away, so the screen area it occupies
2838 // is available to apps but just covering them when the
2839 // status bar is visible.
2840 mDockTop = mUnrestrictedScreenTop + mStatusBarHeight;
2841
2842 mContentTop = mCurTop = mDockTop;
2843 mContentBottom = mCurBottom = mDockBottom;
2844 mContentLeft = mCurLeft = mDockLeft;
2845 mContentRight = mCurRight = mDockRight;
2846
Craig Mautnereda67292013-04-28 13:50:14 -07002847 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar: " +
Craig Mautner69b08182012-09-05 13:07:13 -07002848 String.format(
2849 "dock=[%d,%d][%d,%d] content=[%d,%d][%d,%d] cur=[%d,%d][%d,%d]",
2850 mDockLeft, mDockTop, mDockRight, mDockBottom,
2851 mContentLeft, mContentTop, mContentRight, mContentBottom,
2852 mCurLeft, mCurTop, mCurRight, mCurBottom));
2853 }
John Spurlocke1f366f2013-08-05 12:22:40 -04002854 if (mStatusBar.isVisibleLw() && !mStatusBar.isAnimatingLw()
John Spurlockbd957402013-10-03 11:38:39 -04002855 && !statusBarTransient && !statusBarTranslucent
2856 && !mStatusBarController.wasRecentlyTranslucent()) {
John Spurlocke1f366f2013-08-05 12:22:40 -04002857 // If the opaque status bar is currently requested to be visible,
Craig Mautner69b08182012-09-05 13:07:13 -07002858 // and not in the process of animating on or off, then
2859 // we can tell the app that it is covered by it.
2860 mSystemTop = mUnrestrictedScreenTop + mStatusBarHeight;
2861 }
John Spurlock27735a42013-08-14 17:57:38 -04002862 if (mStatusBarController.checkHiddenLw()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04002863 updateSysUiVisibility = true;
John Spurlock32beb2c2013-03-11 10:16:47 -04002864 }
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002865 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04002866 if (updateSysUiVisibility) {
2867 updateSystemUiVisibilityLw();
2868 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002869 }
2870 }
2871
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07002872 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07002873 @Override
John Spurlock46646232013-09-30 22:32:42 -04002874 public int getSystemDecorLayerLw() {
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07002875 if (mStatusBar != null) return mStatusBar.getSurfaceLayer();
2876 if (mNavigationBar != null) return mNavigationBar.getSurfaceLayer();
2877 return 0;
2878 }
2879
Craig Mautner967212c2013-04-13 21:10:58 -07002880 @Override
2881 public void getContentRectLw(Rect r) {
2882 r.set(mContentLeft, mContentTop, mContentRight, mContentBottom);
2883 }
2884
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002885 void setAttachedWindowFrames(WindowState win, int fl, int adjust, WindowState attached,
2886 boolean insetDecors, Rect pf, Rect df, Rect of, Rect cf, Rect vf) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002887 if (win.getSurfaceLayer() > mDockLayer && attached.getSurfaceLayer() < mDockLayer) {
2888 // Here's a special case: if this attached window is a panel that is
2889 // above the dock window, and the window it is attached to is below
2890 // the dock window, then the frames we computed for the window it is
2891 // attached to can not be used because the dock is effectively part
2892 // of the underlying window and the attached window is floating on top
2893 // of the whole thing. So, we ignore the attached window and explicitly
2894 // compute the frames that would be appropriate without the dock.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002895 df.left = of.left = cf.left = vf.left = mDockLeft;
2896 df.top = of.top = cf.top = vf.top = mDockTop;
2897 df.right = of.right = cf.right = vf.right = mDockRight;
2898 df.bottom = of.bottom = cf.bottom = vf.bottom = mDockBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002899 } else {
2900 // The effective display frame of the attached window depends on
2901 // whether it is taking care of insetting its content. If not,
2902 // we need to use the parent's content frame so that the entire
2903 // window is positioned within that content. Otherwise we can use
2904 // the display frame and let the attached window take care of
2905 // positioning its content appropriately.
Dianne Hackborndea3ef72010-10-28 14:24:22 -07002906 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002907 cf.set(attached.getOverscanFrameLw());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002908 } else {
2909 // If the window is resizing, then we want to base the content
2910 // frame on our attached content frame to resize... however,
2911 // things can be tricky if the attached window is NOT in resize
2912 // mode, in which case its content frame will be larger.
2913 // Ungh. So to deal with that, make sure the content frame
2914 // we end up using is not covering the IM dock.
2915 cf.set(attached.getContentFrameLw());
2916 if (attached.getSurfaceLayer() < mDockLayer) {
2917 if (cf.left < mContentLeft) cf.left = mContentLeft;
2918 if (cf.top < mContentTop) cf.top = mContentTop;
2919 if (cf.right > mContentRight) cf.right = mContentRight;
2920 if (cf.bottom > mContentBottom) cf.bottom = mContentBottom;
2921 }
2922 }
2923 df.set(insetDecors ? attached.getDisplayFrameLw() : cf);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002924 of.set(insetDecors ? attached.getOverscanFrameLw() : cf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002925 vf.set(attached.getVisibleFrameLw());
2926 }
2927 // The LAYOUT_IN_SCREEN flag is used to determine whether the attached
2928 // window should be positioned relative to its parent or the entire
2929 // screen.
2930 pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0
2931 ? attached.getFrameLw() : df);
2932 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002933
2934 private void applyStableConstraints(int sysui, int fl, Rect r) {
2935 if ((sysui & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
2936 // If app is requesting a stable layout, don't let the
2937 // content insets go below the stable values.
2938 if ((fl & FLAG_FULLSCREEN) != 0) {
2939 if (r.left < mStableFullscreenLeft) r.left = mStableFullscreenLeft;
2940 if (r.top < mStableFullscreenTop) r.top = mStableFullscreenTop;
2941 if (r.right > mStableFullscreenRight) r.right = mStableFullscreenRight;
2942 if (r.bottom > mStableFullscreenBottom) r.bottom = mStableFullscreenBottom;
2943 } else {
2944 if (r.left < mStableLeft) r.left = mStableLeft;
2945 if (r.top < mStableTop) r.top = mStableTop;
2946 if (r.right > mStableRight) r.right = mStableRight;
2947 if (r.bottom > mStableBottom) r.bottom = mStableBottom;
2948 }
2949 }
2950 }
2951
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002952 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07002953 @Override
Dianne Hackborn0ecadf72009-03-31 18:00:37 -07002954 public void layoutWindowLw(WindowState win, WindowManager.LayoutParams attrs,
2955 WindowState attached) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002956 // we've already done the status bar
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002957 if (win == mStatusBar || win == mNavigationBar) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002958 return;
2959 }
Craig Mautner69b08182012-09-05 13:07:13 -07002960 final boolean isDefaultDisplay = win.isDefaultDisplay();
2961 final boolean needsToOffsetInputMethodTarget = isDefaultDisplay &&
satok1bc0a492012-04-25 22:47:12 +09002962 (win == mLastInputMethodTargetWindow && mLastInputMethodWindow != null);
2963 if (needsToOffsetInputMethodTarget) {
Craig Mautnereda67292013-04-28 13:50:14 -07002964 if (DEBUG_LAYOUT) Slog.i(TAG, "Offset ime target window by the last ime window state");
satok1bc0a492012-04-25 22:47:12 +09002965 offsetInputMethodWindowLw(mLastInputMethodWindow);
2966 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002967
John Spurlockc6d1c602014-01-17 15:22:06 -05002968 final int fl = PolicyControl.getWindowFlags(win, attrs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002969 final int sim = attrs.softInputMode;
John Spurlock1db8b682014-02-18 11:18:59 -05002970 final int sysUiFl = PolicyControl.getSystemUiVisibility(win, null);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002971
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002972 final Rect pf = mTmpParentFrame;
2973 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002974 final Rect of = mTmpOverscanFrame;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002975 final Rect cf = mTmpContentFrame;
2976 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04002977 final Rect dcf = mTmpDecorFrame;
2978 dcf.setEmpty();
Craig Mautner69b08182012-09-05 13:07:13 -07002979
2980 final boolean hasNavBar = (isDefaultDisplay && mHasNavigationBar
Daniel Sandler36412a72011-08-04 09:35:13 -04002981 && mNavigationBar != null && mNavigationBar.isVisibleLw());
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002982
Craig Mautnerf683b562012-10-02 11:10:57 -07002983 final int adjust = sim & SOFT_INPUT_MASK_ADJUST;
2984
Craig Mautner69b08182012-09-05 13:07:13 -07002985 if (!isDefaultDisplay) {
2986 if (attached != null) {
2987 // If this window is attached to another, our display
2988 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002989 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07002990 } else {
2991 // Give the window full screen.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002992 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
2993 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
2994 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08002995 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002996 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08002997 = mOverscanScreenTop + mOverscanScreenHeight;
Craig Mautner69b08182012-09-05 13:07:13 -07002998 }
2999 } else if (attrs.type == TYPE_INPUT_METHOD) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003000 pf.left = df.left = of.left = cf.left = vf.left = mDockLeft;
3001 pf.top = df.top = of.top = cf.top = vf.top = mDockTop;
3002 pf.right = df.right = of.right = cf.right = vf.right = mDockRight;
John Spurlockc68d5772013-10-08 11:47:58 -04003003 // IM dock windows layout below the nav bar...
John Spurlock57beb3b2013-10-10 10:27:44 -04003004 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlockc68d5772013-10-08 11:47:58 -04003005 // ...with content insets above the nav bar
3006 cf.bottom = vf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003007 // IM dock windows always go to the bottom of the screen.
3008 attrs.gravity = Gravity.BOTTOM;
3009 mDockLayer = win.getSurfaceLayer();
3010 } else {
John Spurlock46646232013-09-30 22:32:42 -04003011
3012 // Default policy decor for the default display
3013 dcf.left = mSystemLeft;
3014 dcf.top = mSystemTop;
3015 dcf.right = mSystemRight;
3016 dcf.bottom = mSystemBottom;
John Spurlockbd957402013-10-03 11:38:39 -04003017 final boolean inheritTranslucentDecor = (attrs.privateFlags
3018 & WindowManager.LayoutParams.PRIVATE_FLAG_INHERIT_TRANSLUCENT_DECOR) != 0;
John Spurlock65567d42013-10-08 10:08:32 -04003019 final boolean isAppWindow =
3020 attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW &&
3021 attrs.type <= WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
3022 final boolean topAtRest =
3023 win == mTopFullscreenOpaqueWindowState && !win.isAnimatingLw();
3024 if (isAppWindow && !inheritTranslucentDecor && !topAtRest) {
John Spurlockbd957402013-10-03 11:38:39 -04003025 if ((sysUiFl & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0
3026 && (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0
3027 && (fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04003028 // Ensure policy decor includes status bar
3029 dcf.top = mStableTop;
3030 }
John Spurlockbd957402013-10-03 11:38:39 -04003031 if ((fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) == 0
John Spurlock8e0ca282013-10-03 11:46:06 -04003032 && (sysUiFl & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04003033 // Ensure policy decor includes navigation bar
3034 dcf.bottom = mStableBottom;
3035 dcf.right = mStableRight;
3036 }
3037 }
3038
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003039 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
3040 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
Craig Mautnereda67292013-04-28 13:50:14 -07003041 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003042 + "): IN_SCREEN, INSET_DECOR");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003043 // This is the case for a normal activity window: we want it
3044 // to cover all of the screen space, and it can take care of
3045 // moving its contents to account for screen decorations that
3046 // intrude into that space.
3047 if (attached != null) {
3048 // If this window is attached to another, our display
3049 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003050 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003051 } else {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003052 if (attrs.type == TYPE_STATUS_BAR_PANEL
3053 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Joe Onorato29fc2c92010-11-24 10:26:50 -08003054 // Status bar panels are the only windows who can go on top of
3055 // the status bar. They are protected by the STATUS_BAR_SERVICE
3056 // permission, so they have the same privileges as the status
3057 // bar itself.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003058 //
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003059 // However, they should still dodge the navigation bar if it exists.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003060
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003061 pf.left = df.left = of.left = hasNavBar
3062 ? mDockLeft : mUnrestrictedScreenLeft;
3063 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3064 pf.right = df.right = of.right = hasNavBar
3065 ? mRestrictedScreenLeft+mRestrictedScreenWidth
3066 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3067 pf.bottom = df.bottom = of.bottom = hasNavBar
3068 ? mRestrictedScreenTop+mRestrictedScreenHeight
3069 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003070
Craig Mautnereda67292013-04-28 13:50:14 -07003071 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003072 "Laying out status bar window: (%d,%d - %d,%d)",
3073 pf.left, pf.top, pf.right, pf.bottom));
John Spurlock46646232013-09-30 22:32:42 -04003074 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08003075 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3076 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3077 // Asking to layout into the overscan region, so give it that pure
3078 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003079 pf.left = df.left = of.left = mOverscanScreenLeft;
3080 pf.top = df.top = of.top = mOverscanScreenTop;
3081 pf.right = df.right = of.right = mOverscanScreenLeft + mOverscanScreenWidth;
3082 pf.bottom = df.bottom = of.bottom = mOverscanScreenTop
3083 + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003084 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003085 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
John Spurlockf95b89a2013-10-10 22:10:42 -04003086 && (attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD || (
3087 attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3088 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW))) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003089 // Asking for layout as if the nav bar is hidden, lets the
Dianne Hackbornc652de82013-02-15 16:32:56 -08003090 // application extend into the unrestricted overscan screen area. We
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003091 // only do this for application windows to ensure no window that
3092 // can be above the nav bar can do this.
Dianne Hackborn313440842013-02-19 19:22:59 -08003093 pf.left = df.left = mOverscanScreenLeft;
3094 pf.top = df.top = mOverscanScreenTop;
3095 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
3096 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003097 // We need to tell the app about where the frame inside the overscan
3098 // is, so it can inset its content by that amount -- it didn't ask
3099 // to actually extend itself into the overscan region.
3100 of.left = mUnrestrictedScreenLeft;
3101 of.top = mUnrestrictedScreenTop;
3102 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3103 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003104 } else {
Dianne Hackborn313440842013-02-19 19:22:59 -08003105 pf.left = df.left = mRestrictedOverscanScreenLeft;
3106 pf.top = df.top = mRestrictedOverscanScreenTop;
3107 pf.right = df.right = mRestrictedOverscanScreenLeft
3108 + mRestrictedOverscanScreenWidth;
3109 pf.bottom = df.bottom = mRestrictedOverscanScreenTop
3110 + mRestrictedOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003111 // We need to tell the app about where the frame inside the overscan
3112 // is, so it can inset its content by that amount -- it didn't ask
3113 // to actually extend itself into the overscan region.
3114 of.left = mUnrestrictedScreenLeft;
3115 of.top = mUnrestrictedScreenTop;
3116 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3117 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003118 }
Craig Mautner69b08182012-09-05 13:07:13 -07003119
John Spurlock46646232013-09-30 22:32:42 -04003120 if ((fl & FLAG_FULLSCREEN) == 0) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003121 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
3122 cf.left = mDockLeft;
3123 cf.top = mDockTop;
3124 cf.right = mDockRight;
3125 cf.bottom = mDockBottom;
3126 } else {
3127 cf.left = mContentLeft;
3128 cf.top = mContentTop;
3129 cf.right = mContentRight;
3130 cf.bottom = mContentBottom;
3131 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003132 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003133 // Full screen windows are always given a layout that is as if the
3134 // status bar and other transient decors are gone. This is to avoid
3135 // bad states when moving from a window that is not hding the
3136 // status bar to one that is.
3137 cf.left = mRestrictedScreenLeft;
3138 cf.top = mRestrictedScreenTop;
3139 cf.right = mRestrictedScreenLeft + mRestrictedScreenWidth;
3140 cf.bottom = mRestrictedScreenTop + mRestrictedScreenHeight;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003141 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003142 applyStableConstraints(sysUiFl, fl, cf);
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003143 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3144 vf.left = mCurLeft;
3145 vf.top = mCurTop;
3146 vf.right = mCurRight;
3147 vf.bottom = mCurBottom;
3148 } else {
3149 vf.set(cf);
3150 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003151 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003152 } else if ((fl & FLAG_LAYOUT_IN_SCREEN) != 0 || (sysUiFl
3153 & (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
3154 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)) != 0) {
Craig Mautnereda67292013-04-28 13:50:14 -07003155 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3156 "): IN_SCREEN");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003157 // A window that has requested to fill the entire screen just
3158 // gets everything, period.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003159 if (attrs.type == TYPE_STATUS_BAR_PANEL
3160 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003161 pf.left = df.left = of.left = cf.left = hasNavBar
3162 ? mDockLeft : mUnrestrictedScreenLeft;
3163 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
3164 pf.right = df.right = of.right = cf.right = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003165 ? mRestrictedScreenLeft+mRestrictedScreenWidth
Dianne Hackbornc652de82013-02-15 16:32:56 -08003166 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003167 pf.bottom = df.bottom = of.bottom = cf.bottom = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003168 ? mRestrictedScreenTop+mRestrictedScreenHeight
Dianne Hackbornc652de82013-02-15 16:32:56 -08003169 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07003170 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler36412a72011-08-04 09:35:13 -04003171 "Laying out IN_SCREEN status bar window: (%d,%d - %d,%d)",
3172 pf.left, pf.top, pf.right, pf.bottom));
Jim Millere898ac52012-04-06 17:10:57 -07003173 } else if (attrs.type == TYPE_NAVIGATION_BAR
3174 || attrs.type == TYPE_NAVIGATION_BAR_PANEL) {
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003175 // The navigation bar has Real Ultimate Power.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003176 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3177 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3178 pf.right = df.right = of.right = mUnrestrictedScreenLeft
3179 + mUnrestrictedScreenWidth;
3180 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop
3181 + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07003182 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003183 "Laying out navigation bar window: (%d,%d - %d,%d)",
3184 pf.left, pf.top, pf.right, pf.bottom));
Dianne Hackborn01011c32012-02-21 13:54:21 -08003185 } else if ((attrs.type == TYPE_SECURE_SYSTEM_OVERLAY
3186 || attrs.type == TYPE_BOOT_PROGRESS)
Jeff Brownbfcb60a2011-09-08 18:51:14 -07003187 && ((fl & FLAG_FULLSCREEN) != 0)) {
3188 // Fullscreen secure system overlays get what they ask for.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003189 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3190 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3191 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
3192 + mOverscanScreenWidth;
3193 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
3194 + mOverscanScreenHeight;
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07003195 } else if (attrs.type == TYPE_BOOT_PROGRESS
3196 || attrs.type == TYPE_UNIVERSE_BACKGROUND) {
Dianne Hackborn01011c32012-02-21 13:54:21 -08003197 // Boot progress screen always covers entire display.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003198 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3199 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3200 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
3201 + mOverscanScreenWidth;
3202 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
3203 + mOverscanScreenHeight;
John Spurlockef4adae2013-08-26 17:58:58 -04003204 } else if (attrs.type == TYPE_WALLPAPER) {
3205 // The wallpaper also has Real Ultimate Power.
3206 pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft;
3207 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003208 pf.right = df.right = of.right = cf.right
John Spurlockef4adae2013-08-26 17:58:58 -04003209 = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003210 pf.bottom = df.bottom = of.bottom = cf.bottom
John Spurlockef4adae2013-08-26 17:58:58 -04003211 = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlock46646232013-09-30 22:32:42 -04003212 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08003213 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3214 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3215 // Asking to layout into the overscan region, so give it that pure
3216 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003217 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3218 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3219 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08003220 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003221 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003222 = mOverscanScreenTop + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003223 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003224 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
John Spurlock34e13d92013-08-10 06:52:28 -04003225 && (attrs.type == TYPE_TOAST
3226 || (attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3227 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW))) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003228 // Asking for layout as if the nav bar is hidden, lets the
3229 // application extend into the unrestricted screen area. We
John Spurlock34e13d92013-08-10 06:52:28 -04003230 // only do this for application windows (or toasts) to ensure no window that
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003231 // can be above the nav bar can do this.
3232 // XXX This assumes that an app asking for this will also
3233 // ask for layout in only content. We can't currently figure out
3234 // what the screen would be if only laying out to hide the nav bar.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003235 pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft;
3236 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
3237 pf.right = df.right = of.right = cf.right = mUnrestrictedScreenLeft
3238 + mUnrestrictedScreenWidth;
3239 pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop
3240 + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003241 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003242 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
3243 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
3244 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
3245 + mRestrictedScreenWidth;
3246 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
3247 + mRestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003248 }
Craig Mautner69b08182012-09-05 13:07:13 -07003249
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003250 applyStableConstraints(sysUiFl, fl, cf);
Craig Mautner69b08182012-09-05 13:07:13 -07003251
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003252 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3253 vf.left = mCurLeft;
3254 vf.top = mCurTop;
3255 vf.right = mCurRight;
3256 vf.bottom = mCurBottom;
3257 } else {
3258 vf.set(cf);
3259 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003260 } else if (attached != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07003261 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3262 "): attached to " + attached);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003263 // A child window should be placed inside of the same visible
3264 // frame that its parent had.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003265 setAttachedWindowFrames(win, fl, adjust, attached, false, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003266 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07003267 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3268 "): normal window");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003269 // Otherwise, a normal window must be placed inside the content
3270 // of all screen decorations.
Dianne Hackborna239c842011-06-01 12:28:20 -07003271 if (attrs.type == TYPE_STATUS_BAR_PANEL) {
3272 // Status bar panels are the only windows who can go on top of
3273 // the status bar. They are protected by the STATUS_BAR_SERVICE
3274 // permission, so they have the same privileges as the status
3275 // bar itself.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003276 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
3277 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
3278 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
3279 + mRestrictedScreenWidth;
3280 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
3281 + mRestrictedScreenHeight;
John Spurlock414c1f02013-12-04 13:47:36 -05003282 } else if (attrs.type == TYPE_TOAST || attrs.type == TYPE_SYSTEM_ALERT
3283 || attrs.type == TYPE_VOLUME_OVERLAY) {
3284 // These dialogs are stable to interim decor changes.
John Spurlockbd957402013-10-03 11:38:39 -04003285 pf.left = df.left = of.left = cf.left = mStableLeft;
3286 pf.top = df.top = of.top = cf.top = mStableTop;
3287 pf.right = df.right = of.right = cf.right = mStableRight;
3288 pf.bottom = df.bottom = of.bottom = cf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003289 } else {
Dianne Hackborna239c842011-06-01 12:28:20 -07003290 pf.left = mContentLeft;
3291 pf.top = mContentTop;
3292 pf.right = mContentRight;
3293 pf.bottom = mContentBottom;
3294 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003295 df.left = of.left = cf.left = mDockLeft;
3296 df.top = of.top = cf.top = mDockTop;
3297 df.right = of.right = cf.right = mDockRight;
3298 df.bottom = of.bottom = cf.bottom = mDockBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07003299 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003300 df.left = of.left = cf.left = mContentLeft;
3301 df.top = of.top = cf.top = mContentTop;
3302 df.right = of.right = cf.right = mContentRight;
3303 df.bottom = of.bottom = cf.bottom = mContentBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07003304 }
3305 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3306 vf.left = mCurLeft;
3307 vf.top = mCurTop;
3308 vf.right = mCurRight;
3309 vf.bottom = mCurBottom;
3310 } else {
3311 vf.set(cf);
3312 }
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003313 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003314 }
3315 }
Craig Mautner69b08182012-09-05 13:07:13 -07003316
Craig Mautnerb816bed2013-07-23 10:26:17 -07003317 // TYPE_SYSTEM_ERROR is above the NavigationBar so it can't be allowed to extend over it.
3318 if ((fl & FLAG_LAYOUT_NO_LIMITS) != 0 && attrs.type != TYPE_SYSTEM_ERROR) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003319 df.left = df.top = of.left = of.top = cf.left = cf.top = vf.left = vf.top = -10000;
3320 df.right = df.bottom = of.right = of.bottom = cf.right = cf.bottom
3321 = vf.right = vf.bottom = 10000;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003322 }
3323
Craig Mautnereda67292013-04-28 13:50:14 -07003324 if (DEBUG_LAYOUT) Slog.v(TAG, "Compute frame " + attrs.getTitle()
The Android Open Source Project11267662009-03-18 17:39:47 -07003325 + ": sim=#" + Integer.toHexString(sim)
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003326 + " attach=" + attached + " type=" + attrs.type
3327 + String.format(" flags=0x%08x", fl)
The Android Open Source Project11267662009-03-18 17:39:47 -07003328 + " pf=" + pf.toShortString() + " df=" + df.toShortString()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003329 + " of=" + of.toShortString()
John Spurlock46646232013-09-30 22:32:42 -04003330 + " cf=" + cf.toShortString() + " vf=" + vf.toShortString()
3331 + " dcf=" + dcf.toShortString());
Craig Mautner69b08182012-09-05 13:07:13 -07003332
John Spurlock46646232013-09-30 22:32:42 -04003333 win.computeFrameLw(pf, df, of, cf, vf, dcf);
Craig Mautner69b08182012-09-05 13:07:13 -07003334
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003335 // Dock windows carve out the bottom of the screen, so normal windows
3336 // can't appear underneath them.
Craig Mautner8bd206b2012-10-03 10:32:02 -07003337 if (attrs.type == TYPE_INPUT_METHOD && win.isVisibleOrBehindKeyguardLw()
3338 && !win.getGivenInsetsPendingLw()) {
satok1bc0a492012-04-25 22:47:12 +09003339 setLastInputMethodWindowLw(null, null);
3340 offsetInputMethodWindowLw(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003341 }
3342 }
3343
satok1bc0a492012-04-25 22:47:12 +09003344 private void offsetInputMethodWindowLw(WindowState win) {
3345 int top = win.getContentFrameLw().top;
3346 top += win.getGivenContentInsetsLw().top;
3347 if (mContentBottom > top) {
3348 mContentBottom = top;
3349 }
3350 top = win.getVisibleFrameLw().top;
3351 top += win.getGivenVisibleInsetsLw().top;
3352 if (mCurBottom > top) {
3353 mCurBottom = top;
3354 }
Craig Mautnereda67292013-04-28 13:50:14 -07003355 if (DEBUG_LAYOUT) Slog.v(TAG, "Input method: mDockBottom="
satok1bc0a492012-04-25 22:47:12 +09003356 + mDockBottom + " mContentBottom="
3357 + mContentBottom + " mCurBottom=" + mCurBottom);
3358 }
3359
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003360 /** {@inheritDoc} */
Craig Mautner61ac6bb2012-02-02 17:29:33 -08003361 @Override
3362 public void finishLayoutLw() {
3363 return;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003364 }
3365
3366 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003367 @Override
Craig Mautner39834192012-09-02 07:47:24 -07003368 public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) {
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003369 mTopFullscreenOpaqueWindowState = null;
Craig Mautner2bc789b2014-03-19 19:48:38 -07003370 mAppsToBeHidden.clear();
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003371 mForceStatusBar = false;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003372 mForceStatusBarFromKeyguard = false;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08003373 mForcingShowNavBar = false;
3374 mForcingShowNavBarLayer = -1;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003375
3376 mHideLockScreen = false;
3377 mAllowLockscreenWhenOn = false;
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003378 mDismissKeyguard = DISMISS_KEYGUARD_NONE;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003379 mShowingLockscreen = false;
3380 mShowingDream = false;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003381 }
3382
3383 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003384 @Override
Craig Mautner39834192012-09-02 07:47:24 -07003385 public void applyPostLayoutPolicyLw(WindowState win,
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003386 WindowManager.LayoutParams attrs) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07003387 if (DEBUG_LAYOUT) Slog.i(TAG, "Win " + win + ": isVisibleOrBehindKeyguardLw="
3388 + win.isVisibleOrBehindKeyguardLw());
John Spurlockc6d1c602014-01-17 15:22:06 -05003389 final int fl = PolicyControl.getWindowFlags(win, attrs);
John Spurlock414c1f02013-12-04 13:47:36 -05003390 if (mTopFullscreenOpaqueWindowState == null
3391 && win.isVisibleLw() && attrs.type == TYPE_INPUT_METHOD) {
3392 mForcingShowNavBar = true;
3393 mForcingShowNavBarLayer = win.getSurfaceLayer();
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08003394 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003395 if (mTopFullscreenOpaqueWindowState == null &&
Dianne Hackborn01b02a72012-01-12 14:05:03 -08003396 win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()) {
John Spurlockc6d1c602014-01-17 15:22:06 -05003397 if ((fl & FLAG_FORCE_NOT_FULLSCREEN) != 0) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003398 if (attrs.type == TYPE_KEYGUARD) {
3399 mForceStatusBarFromKeyguard = true;
3400 } else {
3401 mForceStatusBar = true;
3402 }
3403 }
3404 if (attrs.type == TYPE_KEYGUARD) {
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003405 mShowingLockscreen = true;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07003406 }
Craig Mautnerab55e522014-03-03 13:26:03 -08003407 boolean appWindow = attrs.type >= FIRST_APPLICATION_WINDOW
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003408 && attrs.type <= LAST_APPLICATION_WINDOW;
3409 if (attrs.type == TYPE_DREAM) {
Jeff Brownc8018eb2012-10-29 21:33:27 -07003410 // If the lockscreen was showing when the dream started then wait
3411 // for the dream to draw before hiding the lockscreen.
3412 if (!mDreamingLockscreen
3413 || (win.isVisibleLw() && win.hasDrawnLw())) {
3414 mShowingDream = true;
Craig Mautnerab55e522014-03-03 13:26:03 -08003415 appWindow = true;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003416 }
3417 }
Craig Mautnerab55e522014-03-03 13:26:03 -08003418
Craig Mautner00156ec2014-03-06 22:29:02 -08003419 final boolean showWhenLocked = (fl & FLAG_SHOW_WHEN_LOCKED) != 0;
Craig Mautnerab55e522014-03-03 13:26:03 -08003420 if (appWindow) {
Craig Mautner2bc789b2014-03-19 19:48:38 -07003421 if (showWhenLocked) {
3422 mAppsToBeHidden.remove(win.getAppToken());
3423 } else {
3424 mAppsToBeHidden.add(win.getAppToken());
3425 }
Craig Mautnerab55e522014-03-03 13:26:03 -08003426 if (attrs.x == 0 && attrs.y == 0
3427 && attrs.width == WindowManager.LayoutParams.MATCH_PARENT
3428 && attrs.height == WindowManager.LayoutParams.MATCH_PARENT) {
3429 if (DEBUG_LAYOUT) Slog.v(TAG, "Fullscreen window: " + win);
3430 mTopFullscreenOpaqueWindowState = win;
Craig Mautner2bc789b2014-03-19 19:48:38 -07003431 if (mAppsToBeHidden.isEmpty()) {
Craig Mautnerda09ae32014-03-03 13:26:03 -08003432 if (showWhenLocked) {
3433 if (DEBUG_LAYOUT) Slog.v(TAG,
3434 "Setting mHideLockScreen to true by win " + win);
3435 mHideLockScreen = true;
3436 mForceStatusBarFromKeyguard = false;
3437 }
3438 if ((fl & FLAG_DISMISS_KEYGUARD) != 0
3439 && mDismissKeyguard == DISMISS_KEYGUARD_NONE) {
3440 if (DEBUG_LAYOUT) Slog.v(TAG,
3441 "Setting mDismissKeyguard true by win " + win);
3442 mDismissKeyguard = mWinDismissingKeyguard == win ?
3443 DISMISS_KEYGUARD_CONTINUE : DISMISS_KEYGUARD_START;
3444 mWinDismissingKeyguard = win;
3445 mForceStatusBarFromKeyguard = mShowingLockscreen && isKeyguardSecure();
3446 }
Craig Mautnerab55e522014-03-03 13:26:03 -08003447 }
Craig Mautner00156ec2014-03-06 22:29:02 -08003448 if ((fl & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) {
Craig Mautnerab55e522014-03-03 13:26:03 -08003449 mAllowLockscreenWhenOn = true;
3450 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003451 }
3452 }
3453 }
3454 }
3455
3456 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003457 @Override
Craig Mautner39834192012-09-02 07:47:24 -07003458 public int finishPostLayoutPolicyLw() {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003459 int changes = 0;
Joe Onorato93056472010-09-10 10:30:46 -04003460 boolean topIsFullscreen = false;
Daniel Sandlere02d8082010-10-08 15:13:22 -04003461
3462 final WindowManager.LayoutParams lp = (mTopFullscreenOpaqueWindowState != null)
3463 ? mTopFullscreenOpaqueWindowState.getAttrs()
3464 : null;
3465
Jeff Brownc8018eb2012-10-29 21:33:27 -07003466 // If we are not currently showing a dream then remember the current
3467 // lockscreen state. We will use this to determine whether the dream
3468 // started while the lockscreen was showing and remember this state
3469 // while the dream is showing.
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003470 if (!mShowingDream) {
3471 mDreamingLockscreen = mShowingLockscreen;
3472 }
3473
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003474 if (mStatusBar != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07003475 if (DEBUG_LAYOUT) Slog.i(TAG, "force=" + mForceStatusBar
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003476 + " forcefkg=" + mForceStatusBarFromKeyguard
Dianne Hackbornd70bc2f2009-10-06 23:25:51 -07003477 + " top=" + mTopFullscreenOpaqueWindowState);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003478 if (mForceStatusBar || mForceStatusBarFromKeyguard) {
Craig Mautnereda67292013-04-28 13:50:14 -07003479 if (DEBUG_LAYOUT) Slog.v(TAG, "Showing status bar: forced");
John Spurlock27735a42013-08-14 17:57:38 -04003480 if (mStatusBarController.setBarShowingLw(true)) {
3481 changes |= FINISH_LAYOUT_REDO_LAYOUT;
3482 }
Craig Mautner81defc72013-10-29 11:10:42 -07003483 // Maintain fullscreen layout until incoming animation is complete.
3484 topIsFullscreen = mTopIsFullscreen && mStatusBar.isAnimatingLw();
John Spurlockf92b6162013-11-11 15:01:16 -05003485 // Transient status bar on the lockscreen is not allowed
3486 if (mForceStatusBarFromKeyguard && mStatusBarController.isTransientShowing()) {
3487 mStatusBarController.updateVisibilityLw(false /*transientAllowed*/,
3488 mLastSystemUiFlags, mLastSystemUiFlags);
3489 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003490 } else if (mTopFullscreenOpaqueWindowState != null) {
John Spurlockc6d1c602014-01-17 15:22:06 -05003491 final int fl = PolicyControl.getWindowFlags(null, lp);
Joe Onorato93056472010-09-10 10:30:46 -04003492 if (localLOGV) {
Craig Mautnereda67292013-04-28 13:50:14 -07003493 Slog.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw()
Joe Onorato93056472010-09-10 10:30:46 -04003494 + " shown frame: " + mTopFullscreenOpaqueWindowState.getShownFrameLw());
Craig Mautnereda67292013-04-28 13:50:14 -07003495 Slog.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs()
John Spurlockc6d1c602014-01-17 15:22:06 -05003496 + " lp.flags=0x" + Integer.toHexString(fl));
Joe Onorato93056472010-09-10 10:30:46 -04003497 }
John Spurlockc6d1c602014-01-17 15:22:06 -05003498 topIsFullscreen = (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003499 || (mLastSystemUiFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
Joe Onorato93056472010-09-10 10:30:46 -04003500 // The subtle difference between the window for mTopFullscreenOpaqueWindowState
3501 // and mTopIsFullscreen is that that mTopIsFullscreen is set only if the window
3502 // has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the
3503 // case though.
John Spurlock27735a42013-08-14 17:57:38 -04003504 if (mStatusBarController.isTransientShowing()) {
3505 if (mStatusBarController.setBarShowingLw(true)) {
John Spurlock32beb2c2013-03-11 10:16:47 -04003506 changes |= FINISH_LAYOUT_REDO_LAYOUT;
3507 }
3508 } else if (topIsFullscreen) {
Craig Mautnereda67292013-04-28 13:50:14 -07003509 if (DEBUG_LAYOUT) Slog.v(TAG, "** HIDING status bar");
John Spurlock27735a42013-08-14 17:57:38 -04003510 if (mStatusBarController.setBarShowingLw(false)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003511 changes |= FINISH_LAYOUT_REDO_LAYOUT;
Craig Mautnereda67292013-04-28 13:50:14 -07003512 } else {
Craig Mautnerc5a6e442013-06-05 17:22:35 -07003513 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar already hiding");
Daniel Sandler40427442010-07-16 11:44:52 -04003514 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003515 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07003516 if (DEBUG_LAYOUT) Slog.v(TAG, "** SHOWING status bar: top is not fullscreen");
John Spurlock27735a42013-08-14 17:57:38 -04003517 if (mStatusBarController.setBarShowingLw(true)) {
3518 changes |= FINISH_LAYOUT_REDO_LAYOUT;
3519 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003520 }
3521 }
3522 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04003523
Craig Mautner81defc72013-10-29 11:10:42 -07003524 if (mTopIsFullscreen != topIsFullscreen) {
3525 if (!topIsFullscreen) {
3526 // Force another layout when status bar becomes fully shown.
3527 changes |= FINISH_LAYOUT_REDO_LAYOUT;
3528 }
3529 mTopIsFullscreen = topIsFullscreen;
3530 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04003531
Craig Mautner39834192012-09-02 07:47:24 -07003532 // Hide the key guard if a visible window explicitly specifies that it wants to be
3533 // displayed when the screen is locked.
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -07003534 if (mKeyguard != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07003535 if (localLOGV) Slog.v(TAG, "finishPostLayoutPolicyLw: mHideKeyguard="
Craig Mautner39834192012-09-02 07:47:24 -07003536 + mHideLockScreen);
Craig Mautnerab55e522014-03-03 13:26:03 -08003537 if (mDismissKeyguard != DISMISS_KEYGUARD_NONE && !isKeyguardSecure()) {
Dianne Hackborn08743722009-12-21 12:16:51 -08003538 if (mKeyguard.hideLw(true)) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003539 changes |= FINISH_LAYOUT_REDO_LAYOUT
3540 | FINISH_LAYOUT_REDO_CONFIG
3541 | FINISH_LAYOUT_REDO_WALLPAPER;
3542 }
Jim Miller5ecd8112013-01-09 18:50:26 -08003543 if (mKeyguardDelegate.isShowing()) {
Dianne Hackbornb446e972009-09-20 15:23:25 -07003544 mHandler.post(new Runnable() {
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003545 @Override
Dianne Hackbornb446e972009-09-20 15:23:25 -07003546 public void run() {
Jim Miller5ecd8112013-01-09 18:50:26 -08003547 mKeyguardDelegate.keyguardDone(false, false);
Dianne Hackbornb446e972009-09-20 15:23:25 -07003548 }
3549 });
3550 }
Dianne Hackborn05726582009-09-22 17:28:24 -07003551 } else if (mHideLockScreen) {
Dianne Hackborn08743722009-12-21 12:16:51 -08003552 if (mKeyguard.hideLw(true)) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003553 changes |= FINISH_LAYOUT_REDO_LAYOUT
3554 | FINISH_LAYOUT_REDO_CONFIG
3555 | FINISH_LAYOUT_REDO_WALLPAPER;
3556 }
Craig Mautner28816302013-10-10 20:31:00 -07003557 if (!mShowingDream) {
3558 mKeyguardDelegate.setHidden(true);
3559 }
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003560 } else if (mDismissKeyguard != DISMISS_KEYGUARD_NONE) {
3561 // This is the case of keyguard isSecure() and not mHideLockScreen.
3562 if (mDismissKeyguard == DISMISS_KEYGUARD_START) {
3563 // Only launch the next keyguard unlock window once per window.
3564 if (mKeyguard.showLw(true)) {
3565 changes |= FINISH_LAYOUT_REDO_LAYOUT
3566 | FINISH_LAYOUT_REDO_CONFIG
3567 | FINISH_LAYOUT_REDO_WALLPAPER;
3568 }
Jim Miller5ecd8112013-01-09 18:50:26 -08003569 mKeyguardDelegate.setHidden(false);
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003570 mHandler.post(new Runnable() {
3571 @Override
3572 public void run() {
Jim Miller5ecd8112013-01-09 18:50:26 -08003573 mKeyguardDelegate.dismiss();
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003574 }
3575 });
3576 }
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -07003577 } else {
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003578 mWinDismissingKeyguard = null;
Dianne Hackborn08743722009-12-21 12:16:51 -08003579 if (mKeyguard.showLw(true)) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003580 changes |= FINISH_LAYOUT_REDO_LAYOUT
3581 | FINISH_LAYOUT_REDO_CONFIG
3582 | FINISH_LAYOUT_REDO_WALLPAPER;
3583 }
Jim Miller5ecd8112013-01-09 18:50:26 -08003584 mKeyguardDelegate.setHidden(false);
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -07003585 }
3586 }
Joe Onorato664644d2011-01-23 17:53:23 -08003587
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003588 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003589 // If the navigation bar has been hidden or shown, we need to do another
3590 // layout pass to update that window.
3591 changes |= FINISH_LAYOUT_REDO_LAYOUT;
3592 }
Joe Onorato664644d2011-01-23 17:53:23 -08003593
Mike Lockwood28569302010-01-28 11:54:40 -05003594 // update since mAllowLockscreenWhenOn might have changed
3595 updateLockScreenTimeout();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003596 return changes;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003597 }
3598
Dianne Hackborn08743722009-12-21 12:16:51 -08003599 public boolean allowAppAnimationsLw() {
Craig Mautner58004432013-10-14 12:58:42 -07003600 if (mKeyguard != null && mKeyguard.isVisibleLw() && !mKeyguard.isAnimatingLw()
3601 || mShowingDream) {
Craig Mautner28816302013-10-10 20:31:00 -07003602 // If keyguard or dreams is currently visible, no reason to animate behind it.
Dianne Hackborn08743722009-12-21 12:16:51 -08003603 return false;
3604 }
Dianne Hackborn08743722009-12-21 12:16:51 -08003605 return true;
3606 }
3607
Dianne Hackborndf89e652011-10-06 22:35:11 -07003608 public int focusChangedLw(WindowState lastFocus, WindowState newFocus) {
Joe Onorato664644d2011-01-23 17:53:23 -08003609 mFocusedWindow = newFocus;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003610 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003611 // If the navigation bar has been hidden or shown, we need to do another
3612 // layout pass to update that window.
3613 return FINISH_LAYOUT_REDO_LAYOUT;
3614 }
3615 return 0;
Joe Onorato664644d2011-01-23 17:53:23 -08003616 }
3617
Dianne Hackborn0ecadf72009-03-31 18:00:37 -07003618 /** {@inheritDoc} */
Jeff Brown46b9ac02010-04-22 18:58:52 -07003619 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
3620 // lid changed state
Jeff Brownc458ce92012-04-30 14:58:40 -07003621 final int newLidState = lidOpen ? LID_OPEN : LID_CLOSED;
3622 if (newLidState == mLidState) {
3623 return;
3624 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07003625
Jeff Brownc458ce92012-04-30 14:58:40 -07003626 mLidState = newLidState;
3627 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07003628 updateRotation(true);
Jeff Brownc458ce92012-04-30 14:58:40 -07003629
3630 if (lidOpen) {
Jim Millere51cf7ae2013-06-25 18:31:56 -07003631 mPowerManager.wakeUp(SystemClock.uptimeMillis());
Jeff Brownc458ce92012-04-30 14:58:40 -07003632 } else if (!mLidControlsSleep) {
Jeff Brown96307042012-07-27 15:51:34 -07003633 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
Jeff Brown46b9ac02010-04-22 18:58:52 -07003634 }
3635 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003636
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08003637 void setHdmiPlugged(boolean plugged) {
3638 if (mHdmiPlugged != plugged) {
3639 mHdmiPlugged = plugged;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003640 updateRotation(true, true);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08003641 Intent intent = new Intent(ACTION_HDMI_PLUGGED);
Joe Onoratodc100302011-01-11 17:07:41 -08003642 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08003643 intent.putExtra(EXTRA_HDMI_PLUGGED_STATE, plugged);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07003644 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08003645 }
3646 }
3647
Joe Onoratoea495d42011-04-06 11:41:11 -07003648 void initializeHdmiState() {
Joe Onorato7ba631f2011-05-04 15:28:00 -07003649 boolean plugged = false;
Joe Onoratoea495d42011-04-06 11:41:11 -07003650 // watch for HDMI plug messages if the hdmi switch exists
3651 if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) {
3652 mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi");
3653
Joe Onoratoea495d42011-04-06 11:41:11 -07003654 final String filename = "/sys/class/switch/hdmi/state";
3655 FileReader reader = null;
3656 try {
3657 reader = new FileReader(filename);
3658 char[] buf = new char[15];
3659 int n = reader.read(buf);
3660 if (n > 1) {
3661 plugged = 0 != Integer.parseInt(new String(buf, 0, n-1));
3662 }
3663 } catch (IOException ex) {
3664 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
3665 } catch (NumberFormatException ex) {
3666 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
3667 } finally {
3668 if (reader != null) {
3669 try {
3670 reader.close();
3671 } catch (IOException ex) {
3672 }
Joe Onoratodc100302011-01-11 17:07:41 -08003673 }
3674 }
3675 }
Joe Onorato7ba631f2011-05-04 15:28:00 -07003676 // This dance forces the code in setHdmiPlugged to run.
3677 // Always do this so the sticky intent is stuck (to false) if there is no hdmi.
3678 mHdmiPlugged = !plugged;
3679 setHdmiPlugged(!mHdmiPlugged);
Joe Onoratodc100302011-01-11 17:07:41 -08003680 }
3681
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003682 /**
Jean-Michel Trivifca1e602013-10-10 18:12:59 -07003683 * @return Whether music is being played right now "locally" (e.g. on the device's speakers
3684 * or wired headphones) or "remotely" (e.g. on a device using the Cast protocol and
3685 * controlled by this device, or through remote submix).
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003686 */
3687 boolean isMusicActive() {
Eric Laurent413cb9d2009-07-17 11:52:43 -07003688 final AudioManager am = (AudioManager)mContext.getSystemService(Context.AUDIO_SERVICE);
3689 if (am == null) {
3690 Log.w(TAG, "isMusicActive: couldn't get AudioManager reference");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003691 return false;
3692 }
Jean-Michel Trivifca1e602013-10-10 18:12:59 -07003693 return am.isLocalOrRemoteMusicActive();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003694 }
3695
3696 /**
3697 * Tell the audio service to adjust the volume appropriate to the event.
3698 * @param keycode
3699 */
Mike Lockwooda53e3812009-09-25 10:51:39 -04003700 void handleVolumeKey(int stream, int keycode) {
Jeff Brown4d396052010-10-29 21:50:21 -07003701 IAudioService audioService = getAudioService();
3702 if (audioService == null) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003703 return;
3704 }
3705 try {
Jean-Michel Trivifca1e602013-10-10 18:12:59 -07003706 // when audio is playing locally, we shouldn't have to hold a wake lock
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003707 // during the call, but we do it as a precaution for the rare possibility
Jean-Michel Trivifca1e602013-10-10 18:12:59 -07003708 // that the music stops right before we call this.
3709 // Otherwise we might also be in a remote playback case.
Jeff Brownb0418da2010-11-01 15:24:01 -07003710 // TODO: Actually handle MUTE.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003711 mBroadcastWakeLock.acquire();
Jean-Michel Trivifca1e602013-10-10 18:12:59 -07003712 if (stream == AudioSystem.STREAM_MUSIC) {
3713 audioService.adjustLocalOrRemoteStreamVolume(stream,
3714 keycode == KeyEvent.KEYCODE_VOLUME_UP
3715 ? AudioManager.ADJUST_RAISE
3716 : AudioManager.ADJUST_LOWER,
3717 mContext.getOpPackageName());
3718 } else {
3719 audioService.adjustStreamVolume(stream,
3720 keycode == KeyEvent.KEYCODE_VOLUME_UP
3721 ? AudioManager.ADJUST_RAISE
3722 : AudioManager.ADJUST_LOWER,
3723 0,
3724 mContext.getOpPackageName());
3725 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003726 } catch (RemoteException e) {
Jean-Michel Trivifca1e602013-10-10 18:12:59 -07003727 Log.w(TAG, "IAudioService.adjust*StreamVolume() threw RemoteException " + e);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003728 } finally {
3729 mBroadcastWakeLock.release();
3730 }
3731 }
Jeff Brown4d396052010-10-29 21:50:21 -07003732
Dianne Hackbornc0e3f242011-08-19 14:19:10 -07003733 final Object mScreenshotLock = new Object();
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07003734 ServiceConnection mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07003735
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003736 final Runnable mScreenshotTimeout = new Runnable() {
3737 @Override public void run() {
3738 synchronized (mScreenshotLock) {
3739 if (mScreenshotConnection != null) {
3740 mContext.unbindService(mScreenshotConnection);
3741 mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07003742 }
Winson Chung9112ec32011-06-27 13:15:32 -07003743 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003744 }
3745 };
3746
3747 // Assume this is called from the Handler thread.
3748 private void takeScreenshot() {
3749 synchronized (mScreenshotLock) {
3750 if (mScreenshotConnection != null) {
3751 return;
3752 }
3753 ComponentName cn = new ComponentName("com.android.systemui",
3754 "com.android.systemui.screenshot.TakeScreenshotService");
3755 Intent intent = new Intent();
3756 intent.setComponent(cn);
3757 ServiceConnection conn = new ServiceConnection() {
3758 @Override
3759 public void onServiceConnected(ComponentName name, IBinder service) {
3760 synchronized (mScreenshotLock) {
3761 if (mScreenshotConnection != this) {
3762 return;
3763 }
3764 Messenger messenger = new Messenger(service);
3765 Message msg = Message.obtain(null, 1);
3766 final ServiceConnection myConn = this;
3767 Handler h = new Handler(mHandler.getLooper()) {
3768 @Override
3769 public void handleMessage(Message msg) {
3770 synchronized (mScreenshotLock) {
3771 if (mScreenshotConnection == myConn) {
3772 mContext.unbindService(mScreenshotConnection);
3773 mScreenshotConnection = null;
3774 mHandler.removeCallbacks(mScreenshotTimeout);
3775 }
3776 }
3777 }
3778 };
3779 msg.replyTo = new Messenger(h);
Winson Chunga63bb842011-10-17 10:26:28 -07003780 msg.arg1 = msg.arg2 = 0;
3781 if (mStatusBar != null && mStatusBar.isVisibleLw())
3782 msg.arg1 = 1;
3783 if (mNavigationBar != null && mNavigationBar.isVisibleLw())
3784 msg.arg2 = 1;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003785 try {
3786 messenger.send(msg);
3787 } catch (RemoteException e) {
3788 }
3789 }
3790 }
3791 @Override
3792 public void onServiceDisconnected(ComponentName name) {}
3793 };
Amith Yamasani27b89e62013-01-16 12:30:11 -08003794 if (mContext.bindServiceAsUser(
3795 intent, conn, Context.BIND_AUTO_CREATE, UserHandle.CURRENT)) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003796 mScreenshotConnection = conn;
3797 mHandler.postDelayed(mScreenshotTimeout, 10000);
3798 }
3799 }
Winson Chung9112ec32011-06-27 13:15:32 -07003800 }
3801
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003802 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003803 @Override
Jeff Brown1f245102010-11-18 20:53:46 -08003804 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags, boolean isScreenOn) {
Jeff Brown96307042012-07-27 15:51:34 -07003805 if (!mSystemBooted) {
3806 // If we have not yet booted, don't let key events do anything.
3807 return 0;
3808 }
3809
Jeff Brown1f245102010-11-18 20:53:46 -08003810 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
3811 final boolean canceled = event.isCanceled();
3812 final int keyCode = event.getKeyCode();
Jeff Browne20c9e02010-10-11 14:20:19 -07003813
Jeff Brown3122e442010-10-11 23:32:49 -07003814 final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0;
Jeff Brown3122e442010-10-11 23:32:49 -07003815
Mike Lockwoodc72b15f2009-11-28 20:58:22 -05003816 // If screen is off then we treat the case where the keyguard is open but hidden
3817 // the same as if it were open and in front.
3818 // This will prevent any keys other than the power button from waking the screen
3819 // when the keyguard is hidden by another activity.
Jim Miller5ecd8112013-01-09 18:50:26 -08003820 final boolean keyguardActive = (mKeyguardDelegate == null ? false :
Mike Lockwood3a74bd32011-08-12 13:55:22 -07003821 (isScreenOn ?
Jim Miller5ecd8112013-01-09 18:50:26 -08003822 mKeyguardDelegate.isShowingAndNotHidden() :
3823 mKeyguardDelegate.isShowing()));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003824
Jeff Brown6212a492014-03-07 13:58:47 -08003825 if (keyCode == KeyEvent.KEYCODE_POWER
3826 || keyCode == KeyEvent.KEYCODE_SLEEP
3827 || keyCode == KeyEvent.KEYCODE_WAKEUP) {
Jeff Brown96307042012-07-27 15:51:34 -07003828 policyFlags |= WindowManagerPolicy.FLAG_WAKE;
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07003829 }
3830
Jeff Brown40013652012-05-16 21:22:36 -07003831 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003832 Log.d(TAG, "interceptKeyTq keycode=" + keyCode
Jeff Brown96307042012-07-27 15:51:34 -07003833 + " screenIsOn=" + isScreenOn + " keyguardActive=" + keyguardActive
Jeff Brown26875502014-01-30 21:47:47 -08003834 + " policyFlags=" + Integer.toHexString(policyFlags));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003835 }
3836
Jeff Brown98392ef2011-09-12 18:24:59 -07003837 if (down && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0
3838 && event.getRepeatCount() == 0) {
Jeff Brown4d396052010-10-29 21:50:21 -07003839 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
3840 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003841
Jeff Brown4d396052010-10-29 21:50:21 -07003842 // Basic policy based on screen state and keyguard.
3843 // FIXME: This policy isn't quite correct. We shouldn't care whether the screen
3844 // is on or off, really. We should care about whether the device is in an
3845 // interactive state or is in suspend pretending to be "off".
3846 // The primary screen might be turned off due to proximity sensor or
3847 // because we are presenting media on an auxiliary screen or remotely controlling
3848 // the device some other way (which is why we have an exemption here for injected
3849 // events).
3850 int result;
Jeff Brown26875502014-01-30 21:47:47 -08003851 boolean isWakeKey = (policyFlags & (WindowManagerPolicy.FLAG_WAKE
3852 | WindowManagerPolicy.FLAG_WAKE_DROPPED)) != 0;
Mike Lockwooded8902d2013-11-15 11:01:47 -08003853 if (isScreenOn || (isInjected && !isWakeKey)) {
Jeff Brown4d396052010-10-29 21:50:21 -07003854 // When the screen is on or if the key is injected pass the key to the application.
3855 result = ACTION_PASS_TO_USER;
3856 } else {
3857 // When the screen is off and the key is not injected, determine whether
3858 // to wake the device but don't pass the key to the application.
3859 result = 0;
Jeff Brown26875502014-01-30 21:47:47 -08003860 if (isWakeKey && (!down || !isWakeKeyWhenScreenOff(keyCode))) {
3861 isWakeKey = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003862 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003863 }
3864
Justin Kohd378ad72013-04-01 12:18:26 -07003865 // If the key would be handled globally, just return the result, don't worry about special
3866 // key processing.
3867 if (mGlobalKeyManager.shouldHandleGlobalKey(keyCode, event)) {
3868 return result;
3869 }
3870
Jeff Brown4d396052010-10-29 21:50:21 -07003871 // Handle special keys.
3872 switch (keyCode) {
3873 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jeff Brownb0418da2010-11-01 15:24:01 -07003874 case KeyEvent.KEYCODE_VOLUME_UP:
3875 case KeyEvent.KEYCODE_VOLUME_MUTE: {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003876 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
3877 if (down) {
3878 if (isScreenOn && !mVolumeDownKeyTriggered
3879 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
3880 mVolumeDownKeyTriggered = true;
3881 mVolumeDownKeyTime = event.getDownTime();
3882 mVolumeDownKeyConsumedByScreenshotChord = false;
3883 cancelPendingPowerKeyAction();
3884 interceptScreenshotChord();
3885 }
3886 } else {
3887 mVolumeDownKeyTriggered = false;
3888 cancelPendingScreenshotChordAction();
3889 }
3890 } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
3891 if (down) {
3892 if (isScreenOn && !mVolumeUpKeyTriggered
3893 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
3894 mVolumeUpKeyTriggered = true;
3895 cancelPendingPowerKeyAction();
3896 cancelPendingScreenshotChordAction();
3897 }
3898 } else {
3899 mVolumeUpKeyTriggered = false;
3900 cancelPendingScreenshotChordAction();
3901 }
3902 }
Jeff Brown4d396052010-10-29 21:50:21 -07003903 if (down) {
3904 ITelephony telephonyService = getTelephonyService();
3905 if (telephonyService != null) {
3906 try {
3907 if (telephonyService.isRinging()) {
3908 // If an incoming call is ringing, either VOLUME key means
3909 // "silence ringer". We handle these keys here, rather than
3910 // in the InCallScreen, to make sure we'll respond to them
3911 // even if the InCallScreen hasn't come to the foreground yet.
3912 // Look for the DOWN event here, to agree with the "fallback"
3913 // behavior in the InCallScreen.
3914 Log.i(TAG, "interceptKeyBeforeQueueing:"
3915 + " VOLUME key-down while ringing: Silence ringer!");
3916
3917 // Silence the ringer. (It's safe to call this
3918 // even if the ringer has already been silenced.)
3919 telephonyService.silenceRinger();
3920
3921 // And *don't* pass this key thru to the current activity
3922 // (which is probably the InCallScreen.)
3923 result &= ~ACTION_PASS_TO_USER;
3924 break;
3925 }
3926 if (telephonyService.isOffhook()
3927 && (result & ACTION_PASS_TO_USER) == 0) {
3928 // If we are in call but we decided not to pass the key to
3929 // the application, handle the volume change here.
3930 handleVolumeKey(AudioManager.STREAM_VOICE_CALL, keyCode);
3931 break;
3932 }
3933 } catch (RemoteException ex) {
3934 Log.w(TAG, "ITelephony threw RemoteException", ex);
3935 }
3936 }
3937
3938 if (isMusicActive() && (result & ACTION_PASS_TO_USER) == 0) {
3939 // If music is playing but we decided not to pass the key to the
3940 // application, handle the volume change here.
3941 handleVolumeKey(AudioManager.STREAM_MUSIC, keyCode);
3942 break;
3943 }
3944 }
3945 break;
3946 }
3947
3948 case KeyEvent.KEYCODE_ENDCALL: {
3949 result &= ~ACTION_PASS_TO_USER;
3950 if (down) {
3951 ITelephony telephonyService = getTelephonyService();
3952 boolean hungUp = false;
3953 if (telephonyService != null) {
3954 try {
3955 hungUp = telephonyService.endCall();
3956 } catch (RemoteException ex) {
3957 Log.w(TAG, "ITelephony threw RemoteException", ex);
3958 }
3959 }
3960 interceptPowerKeyDown(!isScreenOn || hungUp);
3961 } else {
3962 if (interceptPowerKeyUp(canceled)) {
3963 if ((mEndcallBehavior
3964 & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) {
3965 if (goHome()) {
3966 break;
Dianne Hackborn0041e972009-07-24 17:14:43 -07003967 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003968 }
Jeff Brown4d396052010-10-29 21:50:21 -07003969 if ((mEndcallBehavior
3970 & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) {
Jeff Brown26875502014-01-30 21:47:47 -08003971 mPowerManager.goToSleep(event.getEventTime());
3972 isWakeKey = false;
Jeff Brown4d396052010-10-29 21:50:21 -07003973 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003974 }
Jeff Brown4d396052010-10-29 21:50:21 -07003975 }
3976 break;
3977 }
3978
3979 case KeyEvent.KEYCODE_POWER: {
3980 result &= ~ACTION_PASS_TO_USER;
3981 if (down) {
John Spurlockd9b70bd2014-02-06 17:02:44 -05003982 boolean panic = mImmersiveModeConfirmation.onPowerKeyDown(isScreenOn,
3983 event.getDownTime(), isImmersiveMode(mLastSystemUiFlags));
3984 if (panic) {
3985 mHandler.post(mRequestTransientNav);
3986 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003987 if (isScreenOn && !mPowerKeyTriggered
3988 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
3989 mPowerKeyTriggered = true;
3990 mPowerKeyTime = event.getDownTime();
3991 interceptScreenshotChord();
Winson Chung9112ec32011-06-27 13:15:32 -07003992 }
Winson Chung9112ec32011-06-27 13:15:32 -07003993
Jeff Brown4d396052010-10-29 21:50:21 -07003994 ITelephony telephonyService = getTelephonyService();
3995 boolean hungUp = false;
3996 if (telephonyService != null) {
3997 try {
3998 if (telephonyService.isRinging()) {
3999 // Pressing Power while there's a ringing incoming
4000 // call should silence the ringer.
4001 telephonyService.silenceRinger();
4002 } else if ((mIncallPowerBehavior
4003 & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0
shower3ac2f662014-01-03 15:33:50 +08004004 && telephonyService.isOffhook() && isScreenOn) {
Jeff Brown4d396052010-10-29 21:50:21 -07004005 // Otherwise, if "Power button ends call" is enabled,
4006 // the Power button will hang up any current active call.
4007 hungUp = telephonyService.endCall();
4008 }
4009 } catch (RemoteException ex) {
4010 Log.w(TAG, "ITelephony threw RemoteException", ex);
4011 }
4012 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004013 interceptPowerKeyDown(!isScreenOn || hungUp
4014 || mVolumeDownKeyTriggered || mVolumeUpKeyTriggered);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004015 } else {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004016 mPowerKeyTriggered = false;
4017 cancelPendingScreenshotChordAction();
4018 if (interceptPowerKeyUp(canceled || mPendingPowerKeyUpCanceled)) {
Jeff Brown26875502014-01-30 21:47:47 -08004019 mPowerManager.goToSleep(event.getEventTime());
4020 isWakeKey = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004021 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004022 mPendingPowerKeyUpCanceled = false;
Jeff Brown4d396052010-10-29 21:50:21 -07004023 }
4024 break;
4025 }
4026
Jeff Brown6212a492014-03-07 13:58:47 -08004027 case KeyEvent.KEYCODE_SLEEP: {
4028 result &= ~ACTION_PASS_TO_USER;
4029 mPowerManager.goToSleep(event.getEventTime());
4030 isWakeKey = false;
4031 break;
4032 }
4033
4034 case KeyEvent.KEYCODE_WAKEUP: {
4035 result &= ~ACTION_PASS_TO_USER;
4036 break;
4037 }
4038
Jeff Brown4d396052010-10-29 21:50:21 -07004039 case KeyEvent.KEYCODE_MEDIA_PLAY:
4040 case KeyEvent.KEYCODE_MEDIA_PAUSE:
4041 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
4042 if (down) {
4043 ITelephony telephonyService = getTelephonyService();
4044 if (telephonyService != null) {
4045 try {
4046 if (!telephonyService.isIdle()) {
4047 // Suppress PLAY/PAUSE toggle when phone is ringing or in-call
4048 // to avoid music playback.
4049 break;
4050 }
4051 } catch (RemoteException ex) {
4052 Log.w(TAG, "ITelephony threw RemoteException", ex);
Jeff Brown3122e442010-10-11 23:32:49 -07004053 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004054 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004055 }
Jeff Brown4d396052010-10-29 21:50:21 -07004056 case KeyEvent.KEYCODE_HEADSETHOOK:
4057 case KeyEvent.KEYCODE_MUTE:
4058 case KeyEvent.KEYCODE_MEDIA_STOP:
4059 case KeyEvent.KEYCODE_MEDIA_NEXT:
4060 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
4061 case KeyEvent.KEYCODE_MEDIA_REWIND:
4062 case KeyEvent.KEYCODE_MEDIA_RECORD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09004063 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
4064 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: {
Jeff Brown4d396052010-10-29 21:50:21 -07004065 if ((result & ACTION_PASS_TO_USER) == 0) {
4066 // Only do this if we would otherwise not pass it to the user. In that
4067 // case, the PhoneWindow class will do the same thing, except it will
4068 // only do it if the showing app doesn't process the key on its own.
Jeff Brown40013652012-05-16 21:22:36 -07004069 // Note that we need to make a copy of the key event here because the
4070 // original key event will be recycled when we return.
Jeff Brown4d396052010-10-29 21:50:21 -07004071 mBroadcastWakeLock.acquire();
Jeff Brown40013652012-05-16 21:22:36 -07004072 Message msg = mHandler.obtainMessage(MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK,
4073 new KeyEvent(event));
4074 msg.setAsynchronous(true);
4075 msg.sendToTarget();
Jeff Brown4d396052010-10-29 21:50:21 -07004076 }
4077 break;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004078 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004079
Jeff Brown4d396052010-10-29 21:50:21 -07004080 case KeyEvent.KEYCODE_CALL: {
4081 if (down) {
4082 ITelephony telephonyService = getTelephonyService();
4083 if (telephonyService != null) {
4084 try {
4085 if (telephonyService.isRinging()) {
4086 Log.i(TAG, "interceptKeyBeforeQueueing:"
4087 + " CALL key-down while ringing: Answer the call!");
4088 telephonyService.answerRingingCall();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004089
Jeff Brown4d396052010-10-29 21:50:21 -07004090 // And *don't* pass this key thru to the current activity
4091 // (which is presumably the InCallScreen.)
4092 result &= ~ACTION_PASS_TO_USER;
4093 }
4094 } catch (RemoteException ex) {
4095 Log.w(TAG, "ITelephony threw RemoteException", ex);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004096 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004097 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004098 }
Jeff Brown4d396052010-10-29 21:50:21 -07004099 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004100 }
4101 }
Jeff Brown26875502014-01-30 21:47:47 -08004102
4103 if (isWakeKey) {
4104 mPowerManager.wakeUp(event.getEventTime());
4105 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004106 return result;
4107 }
4108
Jeff Brown1c2e4942012-11-06 16:32:01 -08004109 /**
4110 * When the screen is off we ignore some keys that might otherwise typically
4111 * be considered wake keys. We filter them out here.
4112 *
4113 * {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it
4114 * is always considered a wake key.
4115 */
4116 private boolean isWakeKeyWhenScreenOff(int keyCode) {
4117 switch (keyCode) {
4118 // ignore volume keys unless docked
4119 case KeyEvent.KEYCODE_VOLUME_UP:
4120 case KeyEvent.KEYCODE_VOLUME_DOWN:
4121 case KeyEvent.KEYCODE_VOLUME_MUTE:
4122 return mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED;
4123
4124 // ignore media and camera keys
4125 case KeyEvent.KEYCODE_MUTE:
4126 case KeyEvent.KEYCODE_HEADSETHOOK:
4127 case KeyEvent.KEYCODE_MEDIA_PLAY:
4128 case KeyEvent.KEYCODE_MEDIA_PAUSE:
4129 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
4130 case KeyEvent.KEYCODE_MEDIA_STOP:
4131 case KeyEvent.KEYCODE_MEDIA_NEXT:
4132 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
4133 case KeyEvent.KEYCODE_MEDIA_REWIND:
4134 case KeyEvent.KEYCODE_MEDIA_RECORD:
4135 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09004136 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK:
Jeff Brown1c2e4942012-11-06 16:32:01 -08004137 case KeyEvent.KEYCODE_CAMERA:
4138 return false;
4139 }
4140 return true;
4141 }
4142
4143
Jeff Brown56194eb2011-03-02 19:23:13 -08004144 /** {@inheritDoc} */
4145 @Override
Jeff Brown26875502014-01-30 21:47:47 -08004146 public int interceptMotionBeforeQueueingWhenScreenOff(long whenNanos, int policyFlags) {
Jeff Brown56194eb2011-03-02 19:23:13 -08004147 int result = 0;
4148
4149 final boolean isWakeMotion = (policyFlags
4150 & (WindowManagerPolicy.FLAG_WAKE | WindowManagerPolicy.FLAG_WAKE_DROPPED)) != 0;
4151 if (isWakeMotion) {
Jeff Brown26875502014-01-30 21:47:47 -08004152 mPowerManager.wakeUp(whenNanos / 1000000);
Jeff Brown56194eb2011-03-02 19:23:13 -08004153 }
4154 return result;
4155 }
4156
Jeff Brown40013652012-05-16 21:22:36 -07004157 void dispatchMediaKeyWithWakeLock(KeyEvent event) {
4158 if (DEBUG_INPUT) {
4159 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: " + event);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004160 }
4161
Jeff Brown40013652012-05-16 21:22:36 -07004162 if (mHavePendingMediaKeyRepeatWithWakeLock) {
4163 if (DEBUG_INPUT) {
4164 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: canceled repeat");
4165 }
4166
4167 mHandler.removeMessages(MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK);
4168 mHavePendingMediaKeyRepeatWithWakeLock = false;
4169 mBroadcastWakeLock.release(); // pending repeat was holding onto the wake lock
4170 }
4171
4172 dispatchMediaKeyWithWakeLockToAudioService(event);
4173
4174 if (event.getAction() == KeyEvent.ACTION_DOWN
4175 && event.getRepeatCount() == 0) {
4176 mHavePendingMediaKeyRepeatWithWakeLock = true;
4177
4178 Message msg = mHandler.obtainMessage(
4179 MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK, event);
4180 msg.setAsynchronous(true);
4181 mHandler.sendMessageDelayed(msg, ViewConfiguration.getKeyRepeatTimeout());
4182 } else {
4183 mBroadcastWakeLock.release();
4184 }
4185 }
4186
4187 void dispatchMediaKeyRepeatWithWakeLock(KeyEvent event) {
4188 mHavePendingMediaKeyRepeatWithWakeLock = false;
4189
4190 KeyEvent repeatEvent = KeyEvent.changeTimeRepeat(event,
4191 SystemClock.uptimeMillis(), 1, event.getFlags() | KeyEvent.FLAG_LONG_PRESS);
4192 if (DEBUG_INPUT) {
4193 Slog.d(TAG, "dispatchMediaKeyRepeatWithWakeLock: " + repeatEvent);
4194 }
4195
4196 dispatchMediaKeyWithWakeLockToAudioService(repeatEvent);
4197 mBroadcastWakeLock.release();
4198 }
4199
4200 void dispatchMediaKeyWithWakeLockToAudioService(KeyEvent event) {
4201 if (ActivityManagerNative.isSystemReady()) {
4202 IAudioService audioService = getAudioService();
4203 if (audioService != null) {
4204 try {
4205 audioService.dispatchMediaKeyEventUnderWakelock(event);
4206 } catch (RemoteException e) {
4207 Log.e(TAG, "dispatchMediaKeyEvent threw exception " + e);
Jean-Michel Trivic6802222012-04-30 11:15:03 -07004208 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004209 }
4210 }
4211 }
4212
Mike Lockwood1753f7f2009-08-24 14:49:07 -07004213 BroadcastReceiver mDockReceiver = new BroadcastReceiver() {
Craig Mautnereee29c42013-01-17 14:44:34 -08004214 @Override
Mike Lockwood1753f7f2009-08-24 14:49:07 -07004215 public void onReceive(Context context, Intent intent) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07004216 if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) {
4217 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
4218 Intent.EXTRA_DOCK_STATE_UNDOCKED);
Daniel Sandler6396c722013-04-16 20:19:09 -04004219 } else {
4220 try {
4221 IUiModeManager uiModeService = IUiModeManager.Stub.asInterface(
4222 ServiceManager.getService(Context.UI_MODE_SERVICE));
4223 mUiMode = uiModeService.getCurrentModeType();
4224 } catch (RemoteException e) {
4225 }
Dianne Hackborn80fa1662009-10-07 14:02:10 -07004226 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004227 updateRotation(true);
Craig Mautnereee29c42013-01-17 14:44:34 -08004228 synchronized (mLock) {
4229 updateOrientationListenerLp();
4230 }
Mike Lockwood1753f7f2009-08-24 14:49:07 -07004231 }
4232 };
4233
Jeff Brown6aaf2952012-10-05 16:01:08 -07004234 BroadcastReceiver mDreamReceiver = new BroadcastReceiver() {
4235 @Override
4236 public void onReceive(Context context, Intent intent) {
4237 if (Intent.ACTION_DREAMING_STARTED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004238 if (mKeyguardDelegate != null) {
4239 mKeyguardDelegate.onDreamingStarted();
Jeff Brown6aaf2952012-10-05 16:01:08 -07004240 }
4241 } else if (Intent.ACTION_DREAMING_STOPPED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004242 if (mKeyguardDelegate != null) {
4243 mKeyguardDelegate.onDreamingStopped();
Jeff Brown6aaf2952012-10-05 16:01:08 -07004244 }
4245 }
4246 }
4247 };
4248
Christopher Tate5e08af02012-09-21 17:17:22 -07004249 BroadcastReceiver mMultiuserReceiver = new BroadcastReceiver() {
4250 @Override
4251 public void onReceive(Context context, Intent intent) {
4252 if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) {
4253 // tickle the settings observer: this first ensures that we're
4254 // observing the relevant settings for the newly-active user,
4255 // and then updates our own bookkeeping based on the now-
4256 // current user.
4257 mSettingsObserver.onChange(false);
John Spurlockce479d82012-11-29 09:52:21 -05004258
4259 // force a re-application of focused window sysui visibility.
4260 // the window may never have been shown for this user
4261 // e.g. the keyguard when going through the new-user setup flow
John Spurlock04db1762013-05-13 12:46:41 -04004262 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
John Spurlockce479d82012-11-29 09:52:21 -05004263 mLastSystemUiFlags = 0;
4264 updateSystemUiVisibilityLw();
4265 }
Christopher Tate5e08af02012-09-21 17:17:22 -07004266 }
4267 }
4268 };
4269
John Spurlockd9b70bd2014-02-06 17:02:44 -05004270 private final Runnable mRequestTransientNav = new Runnable() {
4271 @Override
4272 public void run() {
4273 requestTransientBars(mNavigationBar);
4274 }
4275 };
4276
John Spurlocke1f366f2013-08-05 12:22:40 -04004277 private void requestTransientBars(WindowState swipeTarget) {
John Spurlock04db1762013-05-13 12:46:41 -04004278 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
John Spurlock27735a42013-08-14 17:57:38 -04004279 boolean sb = mStatusBarController.checkShowTransientBarLw();
4280 boolean nb = mNavigationBarController.checkShowTransientBarLw();
John Spurlockad3e6cb2013-04-30 08:47:43 -04004281 if (sb || nb) {
John Spurlocke1f366f2013-08-05 12:22:40 -04004282 WindowState barTarget = sb ? mStatusBar : mNavigationBar;
4283 if (sb ^ nb && barTarget != swipeTarget) {
4284 if (DEBUG) Slog.d(TAG, "Not showing transient bar, wrong swipe target");
John Spurlockad3e6cb2013-04-30 08:47:43 -04004285 return;
4286 }
John Spurlock27735a42013-08-14 17:57:38 -04004287 if (sb) mStatusBarController.showTransient();
4288 if (nb) mNavigationBarController.showTransient();
John Spurlockf1a36642013-10-12 17:50:42 -04004289 mImmersiveModeConfirmation.confirmCurrentPrompt();
John Spurlockad3e6cb2013-04-30 08:47:43 -04004290 updateSystemUiVisibilityLw();
John Spurlock32beb2c2013-03-11 10:16:47 -04004291 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04004292 }
4293 }
4294
Jeff Brownc38c9be2012-10-04 13:16:19 -07004295 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004296 public void screenTurnedOff(int why) {
Dianne Hackborn74489012009-03-24 20:50:09 -07004297 EventLog.writeEvent(70000, 0);
The Android Open Source Project0727d222009-03-11 12:11:58 -07004298 synchronized (mLock) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004299 mScreenOnEarly = false;
4300 mScreenOnFully = false;
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07004301 }
Jim Miller5ecd8112013-01-09 18:50:26 -08004302 if (mKeyguardDelegate != null) {
4303 mKeyguardDelegate.onScreenTurnedOff(why);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004304 }
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07004305 synchronized (mLock) {
The Android Open Source Project0727d222009-03-11 12:11:58 -07004306 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05004307 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07004308 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004309 }
4310
Jeff Brownc38c9be2012-10-04 13:16:19 -07004311 @Override
Dianne Hackborn38e29a62011-09-18 14:43:08 -07004312 public void screenTurningOn(final ScreenOnListener screenOnListener) {
Dianne Hackborn74489012009-03-24 20:50:09 -07004313 EventLog.writeEvent(70000, 1);
Dianne Hackborn40011092011-09-22 13:37:48 -07004314 if (false) {
4315 RuntimeException here = new RuntimeException("here");
4316 here.fillInStackTrace();
4317 Slog.i(TAG, "Screen turning on...", here);
4318 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07004319
The Android Open Source Project0727d222009-03-11 12:11:58 -07004320 synchronized (mLock) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004321 mScreenOnEarly = true;
The Android Open Source Project0727d222009-03-11 12:11:58 -07004322 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05004323 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07004324 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07004325
Jeff Brownc38c9be2012-10-04 13:16:19 -07004326 waitForKeyguard(screenOnListener);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004327 }
4328
Jeff Brownc38c9be2012-10-04 13:16:19 -07004329 private void waitForKeyguard(final ScreenOnListener screenOnListener) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004330 if (mKeyguardDelegate != null) {
Jeff Brownc38c9be2012-10-04 13:16:19 -07004331 if (screenOnListener != null) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004332 mKeyguardDelegate.onScreenTurnedOn(new KeyguardServiceDelegate.ShowListener() {
Jeff Brownc38c9be2012-10-04 13:16:19 -07004333 @Override
4334 public void onShown(IBinder windowToken) {
4335 waitForKeyguardWindowDrawn(windowToken, screenOnListener);
4336 }
4337 });
4338 return;
4339 } else {
Jim Miller5ecd8112013-01-09 18:50:26 -08004340 mKeyguardDelegate.onScreenTurnedOn(null);
Jeff Brownc38c9be2012-10-04 13:16:19 -07004341 }
4342 } else {
Jim Miller5ecd8112013-01-09 18:50:26 -08004343 Slog.i(TAG, "No keyguard interface!");
Jeff Brownc38c9be2012-10-04 13:16:19 -07004344 }
4345 finishScreenTurningOn(screenOnListener);
4346 }
4347
4348 private void waitForKeyguardWindowDrawn(IBinder windowToken,
4349 final ScreenOnListener screenOnListener) {
Craig Mautner6f295902013-10-11 21:43:06 -07004350 if (windowToken != null && !mHideLockScreen) {
Jeff Brownc38c9be2012-10-04 13:16:19 -07004351 try {
4352 if (mWindowManager.waitForWindowDrawn(
4353 windowToken, new IRemoteCallback.Stub() {
4354 @Override
4355 public void sendResult(Bundle data) {
4356 Slog.i(TAG, "Lock screen displayed!");
4357 finishScreenTurningOn(screenOnListener);
4358 }
4359 })) {
4360 return;
4361 }
Craig Mautner4e8a19c2013-10-08 17:26:08 -07004362 Slog.i(TAG, "No lock screen! waitForWindowDrawn false");
4363
Jeff Brownc38c9be2012-10-04 13:16:19 -07004364 } catch (RemoteException ex) {
4365 // Can't happen in system process.
4366 }
4367 }
4368
Craig Mautner4e8a19c2013-10-08 17:26:08 -07004369 Slog.i(TAG, "No lock screen! windowToken=" + windowToken);
Jeff Brownc38c9be2012-10-04 13:16:19 -07004370 finishScreenTurningOn(screenOnListener);
4371 }
4372
4373 private void finishScreenTurningOn(ScreenOnListener screenOnListener) {
4374 synchronized (mLock) {
4375 mScreenOnFully = true;
4376 }
4377
Jeff Brown4fc45272012-10-10 18:28:14 -07004378 try {
4379 mWindowManager.setEventDispatching(true);
4380 } catch (RemoteException unhandled) {
4381 }
4382
Jeff Brownc38c9be2012-10-04 13:16:19 -07004383 if (screenOnListener != null) {
4384 screenOnListener.onScreenOn();
4385 }
4386 }
4387
4388 @Override
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004389 public boolean isScreenOnEarly() {
4390 return mScreenOnEarly;
4391 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07004392
4393 @Override
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004394 public boolean isScreenOnFully() {
4395 return mScreenOnFully;
Dianne Hackborn08743722009-12-21 12:16:51 -08004396 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07004397
Dianne Hackborn08743722009-12-21 12:16:51 -08004398 /** {@inheritDoc} */
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004399 public void enableKeyguard(boolean enabled) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004400 if (mKeyguardDelegate != null) {
4401 mKeyguardDelegate.setKeyguardEnabled(enabled);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004402 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004403 }
4404
4405 /** {@inheritDoc} */
4406 public void exitKeyguardSecurely(OnKeyguardExitResult callback) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004407 if (mKeyguardDelegate != null) {
4408 mKeyguardDelegate.verifyUnlock(callback);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004409 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004410 }
4411
Mike Lockwoodf7913302009-11-28 22:27:10 -05004412 private boolean keyguardIsShowingTq() {
Jim Miller5ecd8112013-01-09 18:50:26 -08004413 if (mKeyguardDelegate == null) return false;
4414 return mKeyguardDelegate.isShowingAndNotHidden();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004415 }
4416
Mike Lockwood520d8bc2011-02-18 13:23:13 -05004417
4418 /** {@inheritDoc} */
4419 public boolean isKeyguardLocked() {
4420 return keyguardOn();
4421 }
4422
4423 /** {@inheritDoc} */
4424 public boolean isKeyguardSecure() {
Jim Miller5ecd8112013-01-09 18:50:26 -08004425 if (mKeyguardDelegate == null) return false;
4426 return mKeyguardDelegate.isSecure();
Mike Lockwood520d8bc2011-02-18 13:23:13 -05004427 }
4428
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004429 /** {@inheritDoc} */
4430 public boolean inKeyguardRestrictedKeyInputMode() {
Jim Miller5ecd8112013-01-09 18:50:26 -08004431 if (mKeyguardDelegate == null) return false;
4432 return mKeyguardDelegate.isInputRestricted();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004433 }
4434
Dianne Hackborn90c52de2011-09-23 12:57:44 -07004435 public void dismissKeyguardLw() {
Jim Miller195b5512013-02-28 03:35:57 -08004436 if (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()) {
Daniel Sandler1ce804392012-11-07 15:07:12 -05004437 mHandler.post(new Runnable() {
4438 public void run() {
Jim Miller5ecd8112013-01-09 18:50:26 -08004439 if (mKeyguardDelegate.isDismissable()) {
Daniel Sandler1ce804392012-11-07 15:07:12 -05004440 // Can we just finish the keyguard straight away?
Jim Miller5ecd8112013-01-09 18:50:26 -08004441 mKeyguardDelegate.keyguardDone(false, true);
Daniel Sandler1ce804392012-11-07 15:07:12 -05004442 } else {
4443 // ask the keyguard to prompt the user to authenticate if necessary
Jim Miller5ecd8112013-01-09 18:50:26 -08004444 mKeyguardDelegate.dismiss();
Dianne Hackborn90c52de2011-09-23 12:57:44 -07004445 }
Daniel Sandler1ce804392012-11-07 15:07:12 -05004446 }
4447 });
Dianne Hackborn90c52de2011-09-23 12:57:44 -07004448 }
4449 }
4450
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004451 void sendCloseSystemWindows() {
4452 sendCloseSystemWindows(mContext, null);
4453 }
4454
4455 void sendCloseSystemWindows(String reason) {
4456 sendCloseSystemWindows(mContext, reason);
4457 }
4458
4459 static void sendCloseSystemWindows(Context context, String reason) {
4460 if (ActivityManagerNative.isSystemReady()) {
Dianne Hackborn94a679d2009-07-28 17:51:07 -07004461 try {
4462 ActivityManagerNative.getDefault().closeSystemDialogs(reason);
4463 } catch (RemoteException e) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004464 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004465 }
4466 }
Mitsuru Oshima831d0d92009-06-16 18:27:18 -07004467
Jeff Brown01a98dd2011-09-20 15:08:29 -07004468 @Override
4469 public int rotationForOrientationLw(int orientation, int lastRotation) {
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05004470 if (false) {
4471 Slog.v(TAG, "rotationForOrientationLw(orient="
4472 + orientation + ", last=" + lastRotation
4473 + "); user=" + mUserRotation + " "
4474 + ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED)
4475 ? "USER_ROTATION_LOCKED" : "")
4476 );
4477 }
4478
Craig Mautner46ac6fa2013-08-01 10:06:34 -07004479 if (mForceDefaultOrientation) {
4480 return Surface.ROTATION_0;
4481 }
4482
The Android Open Source Project0727d222009-03-11 12:11:58 -07004483 synchronized (mLock) {
Jeff Brownc0347aa2011-09-23 17:26:09 -07004484 int sensorRotation = mOrientationListener.getProposedRotation(); // may be -1
4485 if (sensorRotation < 0) {
Jeff Brown0f862b42012-09-27 21:11:01 -07004486 sensorRotation = lastRotation;
Jeff Brownc0347aa2011-09-23 17:26:09 -07004487 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004488
Jeff Browndec6cf42011-11-15 14:08:20 -08004489 final int preferredRotation;
Jeff Brown2e7760e2012-04-11 15:14:55 -07004490 if (mLidState == LID_OPEN && mLidOpenRotation >= 0) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07004491 // Ignore sensor when lid switch is open and rotation is forced.
4492 preferredRotation = mLidOpenRotation;
4493 } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR
Jeff Brownc0347aa2011-09-23 17:26:09 -07004494 && (mCarDockEnablesAccelerometer || mCarDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07004495 // Ignore sensor when in car dock unless explicitly enabled.
4496 // This case can override the behavior of NOSENSOR, and can also
4497 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07004498 preferredRotation = mCarDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07004499 ? sensorRotation : mCarDockRotation;
Jeff Brown1a693182011-11-08 14:44:16 -08004500 } else if ((mDockMode == Intent.EXTRA_DOCK_STATE_DESK
4501 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
4502 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK)
Jeff Brownc0347aa2011-09-23 17:26:09 -07004503 && (mDeskDockEnablesAccelerometer || mDeskDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07004504 // Ignore sensor when in desk dock unless explicitly enabled.
4505 // This case can override the behavior of NOSENSOR, and can also
4506 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07004507 preferredRotation = mDeskDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07004508 ? sensorRotation : mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -07004509 } else if (mHdmiPlugged && mDemoHdmiRotationLock) {
4510 // Ignore sensor when plugged into HDMI when demo HDMI rotation lock enabled.
Jeff Browneb3e4b92011-12-06 19:54:24 -08004511 // Note that the dock orientation overrides the HDMI orientation.
Jeff Brownc82c89ed2013-04-17 17:18:15 -07004512 preferredRotation = mDemoHdmiRotation;
4513 } else if (mHdmiPlugged && mDockMode == Intent.EXTRA_DOCK_STATE_UNDOCKED
4514 && mUndockedHdmiRotation >= 0) {
4515 // Ignore sensor when plugged into HDMI and an undocked orientation has
4516 // been specified in the configuration (only for legacy devices without
4517 // full multi-display support).
4518 // Note that the dock orientation overrides the HDMI orientation.
4519 preferredRotation = mUndockedHdmiRotation;
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07004520 } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED) {
4521 // Application just wants to remain locked in the last rotation.
4522 preferredRotation = lastRotation;
Jeff Brownbcdfc622014-03-06 19:13:04 -08004523 } else if (!mSupportAutoRotation) {
4524 // If we don't support auto-rotation then bail out here and ignore
4525 // the sensor and any rotation lock settings.
4526 preferredRotation = -1;
Jeff Brown207673cd2012-06-05 17:47:11 -07004527 } else if ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE
Jeff Brown01a98dd2011-09-20 15:08:29 -07004528 && (orientation == ActivityInfo.SCREEN_ORIENTATION_USER
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07004529 || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
4530 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
4531 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
4532 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER))
Jeff Brown01a98dd2011-09-20 15:08:29 -07004533 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
4534 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
4535 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
4536 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) {
4537 // Otherwise, use sensor only if requested by the application or enabled
4538 // by default for USER or UNSPECIFIED modes. Does not apply to NOSENSOR.
Jeff Brownd3187e32011-09-21 19:26:44 -07004539 if (mAllowAllRotations < 0) {
4540 // Can't read this during init() because the context doesn't
4541 // have display metrics at that time so we cannot determine
4542 // tablet vs. phone then.
4543 mAllowAllRotations = mContext.getResources().getBoolean(
4544 com.android.internal.R.bool.config_allowAllRotations) ? 1 : 0;
4545 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004546 if (sensorRotation != Surface.ROTATION_180
Jeff Brownd3187e32011-09-21 19:26:44 -07004547 || mAllowAllRotations == 1
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07004548 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
4549 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07004550 preferredRotation = sensorRotation;
4551 } else {
4552 preferredRotation = lastRotation;
4553 }
Jeff Brown207673cd2012-06-05 17:47:11 -07004554 } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED
4555 && orientation != ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) {
4556 // Apply rotation lock. Does not apply to NOSENSOR.
4557 // The idea is that the user rotation expresses a weak preference for the direction
4558 // of gravity and as NOSENSOR is never affected by gravity, then neither should
4559 // NOSENSOR be affected by rotation lock (although it will be affected by docks).
Jeff Brown4dfce202011-10-05 12:00:10 -07004560 preferredRotation = mUserRotation;
Jeff Browndec6cf42011-11-15 14:08:20 -08004561 } else {
4562 // No overriding preference.
4563 // We will do exactly what the application asked us to do.
4564 preferredRotation = -1;
Jeff Brown01a98dd2011-09-20 15:08:29 -07004565 }
4566
Dianne Hackborne5439f22010-10-02 16:53:50 -07004567 switch (orientation) {
4568 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08004569 // Return portrait unless overridden.
4570 if (isAnyPortrait(preferredRotation)) {
4571 return preferredRotation;
4572 }
Dianne Hackborne5439f22010-10-02 16:53:50 -07004573 return mPortraitRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07004574
Jeff Brown01a98dd2011-09-20 15:08:29 -07004575 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08004576 // Return landscape unless overridden.
4577 if (isLandscapeOrSeascape(preferredRotation)) {
4578 return preferredRotation;
4579 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004580 return mLandscapeRotation;
4581
4582 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08004583 // Return reverse portrait unless overridden.
4584 if (isAnyPortrait(preferredRotation)) {
4585 return preferredRotation;
4586 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004587 return mUpsideDownRotation;
4588
4589 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08004590 // Return seascape unless overridden.
4591 if (isLandscapeOrSeascape(preferredRotation)) {
4592 return preferredRotation;
4593 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004594 return mSeascapeRotation;
4595
4596 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07004597 case ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE:
Jeff Brown01a98dd2011-09-20 15:08:29 -07004598 // Return either landscape rotation.
4599 if (isLandscapeOrSeascape(preferredRotation)) {
4600 return preferredRotation;
4601 }
4602 if (isLandscapeOrSeascape(lastRotation)) {
Jeff Brown4519f072011-01-23 13:16:01 -08004603 return lastRotation;
4604 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004605 return mLandscapeRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004606
Jeff Brown01a98dd2011-09-20 15:08:29 -07004607 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07004608 case ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT:
Jeff Brown01a98dd2011-09-20 15:08:29 -07004609 // Return either portrait rotation.
4610 if (isAnyPortrait(preferredRotation)) {
4611 return preferredRotation;
4612 }
4613 if (isAnyPortrait(lastRotation)) {
4614 return lastRotation;
4615 }
4616 return mPortraitRotation;
4617
4618 default:
Jeff Brown4dfce202011-10-05 12:00:10 -07004619 // For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR,
4620 // just return the preferred orientation we already calculated.
Jeff Brown01a98dd2011-09-20 15:08:29 -07004621 if (preferredRotation >= 0) {
4622 return preferredRotation;
4623 }
Dianne Hackborndacea8c2011-04-21 17:26:39 -07004624 return Surface.ROTATION_0;
Daniel Sandlere7e5ac22011-02-22 16:10:21 -05004625 }
4626 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07004627 }
4628
Jeff Brown01a98dd2011-09-20 15:08:29 -07004629 @Override
4630 public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation) {
4631 switch (orientation) {
4632 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
4633 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
4634 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
4635 return isAnyPortrait(rotation);
4636
4637 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
4638 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
4639 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
4640 return isLandscapeOrSeascape(rotation);
4641
4642 default:
4643 return true;
4644 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07004645 }
4646
Jeff Brownc0347aa2011-09-23 17:26:09 -07004647 @Override
4648 public void setRotationLw(int rotation) {
4649 mOrientationListener.setCurrentRotation(rotation);
4650 }
4651
Jeff Brown01a98dd2011-09-20 15:08:29 -07004652 private boolean isLandscapeOrSeascape(int rotation) {
4653 return rotation == mLandscapeRotation || rotation == mSeascapeRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07004654 }
4655
Jeff Brown01a98dd2011-09-20 15:08:29 -07004656 private boolean isAnyPortrait(int rotation) {
4657 return rotation == mPortraitRotation || rotation == mUpsideDownRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07004658 }
4659
Svetoslav Ganov80943d82013-01-02 10:25:37 -08004660 public int getUserRotationMode() {
4661 return Settings.System.getIntForUser(mContext.getContentResolver(),
Brett Chabot7e55c402013-05-16 19:38:08 -07004662 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
4663 WindowManagerPolicy.USER_ROTATION_FREE :
4664 WindowManagerPolicy.USER_ROTATION_LOCKED;
Svetoslav Ganov80943d82013-01-02 10:25:37 -08004665 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004666
4667 // User rotation: to be used when all else fails in assigning an orientation to the device
4668 public void setUserRotationMode(int mode, int rot) {
4669 ContentResolver res = mContext.getContentResolver();
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05004670
4671 // mUserRotationMode and mUserRotation will be assigned by the content observer
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004672 if (mode == WindowManagerPolicy.USER_ROTATION_LOCKED) {
Christopher Tate5e08af02012-09-21 17:17:22 -07004673 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004674 Settings.System.USER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07004675 rot,
4676 UserHandle.USER_CURRENT);
4677 Settings.System.putIntForUser(res,
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05004678 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07004679 0,
4680 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004681 } else {
Christopher Tate5e08af02012-09-21 17:17:22 -07004682 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004683 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07004684 1,
4685 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004686 }
4687 }
4688
Jeff Brownac143512012-04-05 18:57:33 -07004689 public void setSafeMode(boolean safeMode) {
4690 mSafeMode = safeMode;
4691 performHapticFeedbackLw(null, safeMode
4692 ? HapticFeedbackConstants.SAFE_MODE_ENABLED
4693 : HapticFeedbackConstants.SAFE_MODE_DISABLED, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004694 }
Craig Mautnereda67292013-04-28 13:50:14 -07004695
Dianne Hackborn181ceb52009-08-27 22:16:40 -07004696 static long[] getLongIntArray(Resources r, int resid) {
4697 int[] ar = r.getIntArray(resid);
4698 if (ar == null) {
4699 return null;
4700 }
4701 long[] out = new long[ar.length];
4702 for (int i=0; i<ar.length; i++) {
4703 out[i] = ar[i];
4704 }
4705 return out;
4706 }
Craig Mautnereda67292013-04-28 13:50:14 -07004707
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004708 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07004709 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004710 public void systemReady() {
Mike Lockwooded8902d2013-11-15 11:01:47 -08004711 mKeyguardDelegate = new KeyguardServiceDelegate(mContext, null);
4712 mKeyguardDelegate.onSystemReady();
4713
Dianne Hackbornb1a79802009-09-29 15:18:31 -07004714 synchronized (mLock) {
4715 updateOrientationListenerLp();
Dianne Hackbornc777e072010-02-12 13:07:59 -08004716 mSystemReady = true;
4717 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07004718 @Override
Dianne Hackbornc777e072010-02-12 13:07:59 -08004719 public void run() {
4720 updateSettings();
4721 }
4722 });
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004723 }
4724 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07004725
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07004726 /** {@inheritDoc} */
4727 public void systemBooted() {
Jim Millere5f910a2013-10-16 18:15:46 -07004728 if (mKeyguardDelegate != null) {
4729 mKeyguardDelegate.onBootCompleted();
4730 }
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07004731 synchronized (mLock) {
4732 mSystemBooted = true;
4733 }
4734 }
4735
Dianne Hackborn661cd522011-08-22 00:26:20 -07004736 ProgressDialog mBootMsgDialog = null;
4737
4738 /** {@inheritDoc} */
4739 public void showBootMessage(final CharSequence msg, final boolean always) {
4740 mHandler.post(new Runnable() {
4741 @Override public void run() {
4742 if (mBootMsgDialog == null) {
Dianne Hackborn295e3c22011-08-25 13:19:08 -07004743 mBootMsgDialog = new ProgressDialog(mContext) {
4744 // This dialog will consume all events coming in to
4745 // it, to avoid it trying to do things too early in boot.
4746 @Override public boolean dispatchKeyEvent(KeyEvent event) {
4747 return true;
4748 }
4749 @Override public boolean dispatchKeyShortcutEvent(KeyEvent event) {
4750 return true;
4751 }
4752 @Override public boolean dispatchTouchEvent(MotionEvent ev) {
4753 return true;
4754 }
4755 @Override public boolean dispatchTrackballEvent(MotionEvent ev) {
4756 return true;
4757 }
4758 @Override public boolean dispatchGenericMotionEvent(MotionEvent ev) {
4759 return true;
4760 }
4761 @Override public boolean dispatchPopulateAccessibilityEvent(
4762 AccessibilityEvent event) {
4763 return true;
4764 }
4765 };
Dianne Hackborn661cd522011-08-22 00:26:20 -07004766 mBootMsgDialog.setTitle(R.string.android_upgrading_title);
4767 mBootMsgDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
4768 mBootMsgDialog.setIndeterminate(true);
4769 mBootMsgDialog.getWindow().setType(
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07004770 WindowManager.LayoutParams.TYPE_BOOT_PROGRESS);
Dianne Hackborn661cd522011-08-22 00:26:20 -07004771 mBootMsgDialog.getWindow().addFlags(
4772 WindowManager.LayoutParams.FLAG_DIM_BEHIND
4773 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
4774 mBootMsgDialog.getWindow().setDimAmount(1);
Dianne Hackbornd9efb952011-12-07 14:56:51 -08004775 WindowManager.LayoutParams lp = mBootMsgDialog.getWindow().getAttributes();
4776 lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
4777 mBootMsgDialog.getWindow().setAttributes(lp);
Dianne Hackborn661cd522011-08-22 00:26:20 -07004778 mBootMsgDialog.setCancelable(false);
4779 mBootMsgDialog.show();
4780 }
4781 mBootMsgDialog.setMessage(msg);
4782 }
4783 });
4784 }
4785
4786 /** {@inheritDoc} */
4787 public void hideBootMessages() {
4788 mHandler.post(new Runnable() {
4789 @Override public void run() {
4790 if (mBootMsgDialog != null) {
4791 mBootMsgDialog.dismiss();
4792 mBootMsgDialog = null;
4793 }
4794 }
4795 });
4796 }
4797
Mike Lockwood28569302010-01-28 11:54:40 -05004798 /** {@inheritDoc} */
4799 public void userActivity() {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004800 // ***************************************
4801 // NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
4802 // ***************************************
4803 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
4804 // WITH ITS LOCKS HELD.
4805 //
4806 // This code must be VERY careful about the locks
4807 // it acquires.
4808 // In fact, the current code acquires way too many,
4809 // and probably has lurking deadlocks.
4810
Mike Lockwood28569302010-01-28 11:54:40 -05004811 synchronized (mScreenLockTimeout) {
4812 if (mLockScreenTimerActive) {
4813 // reset the timer
4814 mHandler.removeCallbacks(mScreenLockTimeout);
4815 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
4816 }
4817 }
Daniel Sandler0601eb72011-04-13 01:01:32 -04004818 }
4819
Adam Cohenf7522022012-10-03 20:03:18 -07004820 class ScreenLockTimeout implements Runnable {
4821 Bundle options;
4822
4823 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05004824 public void run() {
4825 synchronized (this) {
4826 if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard");
Jim Miller5ecd8112013-01-09 18:50:26 -08004827 if (mKeyguardDelegate != null) {
4828 mKeyguardDelegate.doKeyguardTimeout(options);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004829 }
Mike Lockwood28569302010-01-28 11:54:40 -05004830 mLockScreenTimerActive = false;
Adam Cohenf7522022012-10-03 20:03:18 -07004831 options = null;
Mike Lockwood28569302010-01-28 11:54:40 -05004832 }
4833 }
Mike Lockwood28569302010-01-28 11:54:40 -05004834
Adam Cohenf7522022012-10-03 20:03:18 -07004835 public void setLockOptions(Bundle options) {
4836 this.options = options;
4837 }
4838 }
4839
4840 ScreenLockTimeout mScreenLockTimeout = new ScreenLockTimeout();
4841
4842 public void lockNow(Bundle options) {
Jim Miller93c518e2012-01-17 15:55:31 -08004843 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null);
4844 mHandler.removeCallbacks(mScreenLockTimeout);
Adam Cohenf7522022012-10-03 20:03:18 -07004845 if (options != null) {
4846 // In case multiple calls are made to lockNow, we don't wipe out the options
4847 // until the runnable actually executes.
4848 mScreenLockTimeout.setLockOptions(options);
4849 }
Jim Miller93c518e2012-01-17 15:55:31 -08004850 mHandler.post(mScreenLockTimeout);
4851 }
4852
Mike Lockwood28569302010-01-28 11:54:40 -05004853 private void updateLockScreenTimeout() {
4854 synchronized (mScreenLockTimeout) {
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004855 boolean enable = (mAllowLockscreenWhenOn && mScreenOnEarly &&
Jim Miller5ecd8112013-01-09 18:50:26 -08004856 mKeyguardDelegate != null && mKeyguardDelegate.isSecure());
Mike Lockwood28569302010-01-28 11:54:40 -05004857 if (mLockScreenTimerActive != enable) {
4858 if (enable) {
4859 if (localLOGV) Log.v(TAG, "setting lockscreen timer");
4860 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
4861 } else {
4862 if (localLOGV) Log.v(TAG, "clearing lockscreen timer");
4863 mHandler.removeCallbacks(mScreenLockTimeout);
4864 }
4865 mLockScreenTimerActive = enable;
4866 }
4867 }
4868 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004869
4870 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07004871 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004872 public void enableScreenAfterBoot() {
4873 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07004874 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07004875 updateRotation(true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004876 }
Dianne Hackbornf54c8f92009-09-19 14:03:57 -07004877
Jeff Brownc458ce92012-04-30 14:58:40 -07004878 private void applyLidSwitchState() {
Jeff Brownc458ce92012-04-30 14:58:40 -07004879 if (mLidState == LID_CLOSED && mLidControlsSleep) {
4880 mPowerManager.goToSleep(SystemClock.uptimeMillis());
4881 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004882 }
4883
4884 void updateRotation(boolean alwaysSendConfiguration) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004885 try {
4886 //set orientation on WindowManager
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004887 mWindowManager.updateRotation(alwaysSendConfiguration, false);
4888 } catch (RemoteException e) {
4889 // Ignore
4890 }
4891 }
4892
4893 void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) {
4894 try {
4895 //set orientation on WindowManager
4896 mWindowManager.updateRotation(alwaysSendConfiguration, forceRelayout);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004897 } catch (RemoteException e) {
4898 // Ignore
4899 }
4900 }
4901
Daniel Sandler6396c722013-04-16 20:19:09 -04004902 /**
4903 * Return an Intent to launch the currently active dock app as home. Returns
4904 * null if the standard home should be launched, which is the case if any of the following is
4905 * true:
4906 * <ul>
4907 * <li>The device is not in either car mode or desk mode
4908 * <li>The device is in car mode but ENABLE_CAR_DOCK_HOME_CAPTURE is false
4909 * <li>The device is in desk mode but ENABLE_DESK_DOCK_HOME_CAPTURE is false
4910 * <li>The device is in car mode but there's no CAR_DOCK app with METADATA_DOCK_HOME
4911 * <li>The device is in desk mode but there's no DESK_DOCK app with METADATA_DOCK_HOME
4912 * </ul>
Craig Mautnereda67292013-04-28 13:50:14 -07004913 * @return A dock intent.
Daniel Sandler6396c722013-04-16 20:19:09 -04004914 */
4915 Intent createHomeDockIntent() {
4916 Intent intent = null;
4917
4918 // What home does is based on the mode, not the dock state. That
4919 // is, when in car mode you should be taken to car home regardless
4920 // of whether we are actually in a car dock.
4921 if (mUiMode == Configuration.UI_MODE_TYPE_CAR) {
4922 if (ENABLE_CAR_DOCK_HOME_CAPTURE) {
4923 intent = mCarDockIntent;
4924 }
4925 } else if (mUiMode == Configuration.UI_MODE_TYPE_DESK) {
4926 if (ENABLE_DESK_DOCK_HOME_CAPTURE) {
4927 intent = mDeskDockIntent;
4928 }
4929 }
4930
4931 if (intent == null) {
4932 return null;
4933 }
4934
4935 ActivityInfo ai = null;
4936 ResolveInfo info = mContext.getPackageManager().resolveActivityAsUser(
4937 intent,
John Spurlockf56bef12013-07-09 09:51:46 -04004938 PackageManager.MATCH_DEFAULT_ONLY | PackageManager.GET_META_DATA,
Craig Mautnerd625ab22013-09-06 13:40:31 -07004939 mCurrentUserId);
Daniel Sandler6396c722013-04-16 20:19:09 -04004940 if (info != null) {
4941 ai = info.activityInfo;
4942 }
4943 if (ai != null
4944 && ai.metaData != null
4945 && ai.metaData.getBoolean(Intent.METADATA_DOCK_HOME)) {
4946 intent = new Intent(intent);
4947 intent.setClassName(ai.packageName, ai.name);
4948 return intent;
4949 }
4950
4951 return null;
4952 }
4953
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004954 void startDockOrHome() {
John Spurlockc8b46ca2013-04-08 12:59:26 -04004955 awakenDreams();
Daniel Sandler6396c722013-04-16 20:19:09 -04004956
4957 Intent dock = createHomeDockIntent();
4958 if (dock != null) {
4959 try {
4960 mContext.startActivityAsUser(dock, UserHandle.CURRENT);
4961 return;
4962 } catch (ActivityNotFoundException e) {
4963 }
4964 }
4965
Dianne Hackbornd8883992012-09-07 15:58:52 -07004966 mContext.startActivityAsUser(mHomeIntent, UserHandle.CURRENT);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004967 }
Craig Mautnereda67292013-04-28 13:50:14 -07004968
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004969 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004970 * goes to the home screen
4971 * @return whether it did anything
4972 */
4973 boolean goHome() {
4974 if (false) {
4975 // This code always brings home to the front.
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07004976 try {
4977 ActivityManagerNative.getDefault().stopAppSwitches();
4978 } catch (RemoteException e) {
4979 }
Dianne Hackborn94a679d2009-07-28 17:51:07 -07004980 sendCloseSystemWindows();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004981 startDockOrHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004982 } else {
4983 // This code brings home to the front or, if it is already
4984 // at the front, puts the device to sleep.
4985 try {
Wink Savilled2e6a332010-02-12 12:12:06 -08004986 if (SystemProperties.getInt("persist.sys.uts-test-mode", 0) == 1) {
4987 /// Roll back EndcallBehavior as the cupcake design to pass P1 lab entry.
4988 Log.d(TAG, "UTS-TEST-MODE");
4989 } else {
4990 ActivityManagerNative.getDefault().stopAppSwitches();
4991 sendCloseSystemWindows();
Daniel Sandler6396c722013-04-16 20:19:09 -04004992 Intent dock = createHomeDockIntent();
4993 if (dock != null) {
4994 int result = ActivityManagerNative.getDefault()
4995 .startActivityAsUser(null, null, dock,
4996 dock.resolveTypeIfNeeded(mContext.getContentResolver()),
4997 null, null, 0,
4998 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
4999 null, null, null, UserHandle.USER_CURRENT);
5000 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
5001 return false;
5002 }
5003 }
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005004 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005005 int result = ActivityManagerNative.getDefault()
Dianne Hackbornf265ea92013-01-31 15:00:51 -08005006 .startActivityAsUser(null, null, mHomeIntent,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005007 mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()),
Dianne Hackborna4972e92012-03-14 10:38:05 -07005008 null, null, 0,
5009 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Dianne Hackborn5e03e2c2012-09-06 14:21:19 -07005010 null, null, null, UserHandle.USER_CURRENT);
Dianne Hackborna4972e92012-03-14 10:38:05 -07005011 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005012 return false;
5013 }
5014 } catch (RemoteException ex) {
5015 // bummer, the activity manager, which is in this process, is dead
5016 }
5017 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005018 return true;
5019 }
Craig Mautnereda67292013-04-28 13:50:14 -07005020
5021 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07005022 public void setCurrentOrientationLw(int newOrientation) {
5023 synchronized (mLock) {
5024 if (newOrientation != mCurrentAppOrientation) {
5025 mCurrentAppOrientation = newOrientation;
5026 updateOrientationListenerLp();
5027 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005028 }
5029 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08005030
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07005031 private void performAuditoryFeedbackForAccessibilityIfNeed() {
5032 if (!isGlobalAccessibilityGestureEnabled()) {
5033 return;
5034 }
5035 AudioManager audioManager = (AudioManager) mContext.getSystemService(
5036 Context.AUDIO_SERVICE);
5037 if (audioManager.isSilentMode()) {
5038 return;
5039 }
5040 Ringtone ringTone = RingtoneManager.getRingtone(mContext,
5041 Settings.System.DEFAULT_NOTIFICATION_URI);
5042 ringTone.setStreamType(AudioManager.STREAM_MUSIC);
5043 ringTone.play();
5044 }
Craig Mautnereda67292013-04-28 13:50:14 -07005045
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07005046 private boolean isGlobalAccessibilityGestureEnabled() {
5047 return Settings.Global.getInt(mContext.getContentResolver(),
5048 Settings.Global.ENABLE_ACCESSIBILITY_GLOBAL_GESTURE_ENABLED, 0) == 1;
5049 }
5050
Craig Mautnereda67292013-04-28 13:50:14 -07005051 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07005052 public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) {
Svetoslav Ganov96179212012-10-10 14:17:45 -07005053 if (!mVibrator.hasVibrator()) {
5054 return false;
5055 }
Christopher Tate5e08af02012-09-21 17:17:22 -07005056 final boolean hapticsDisabled = Settings.System.getIntForUser(mContext.getContentResolver(),
5057 Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) == 0;
Jim Miller5ecd8112013-01-09 18:50:26 -08005058 if (!always && (hapticsDisabled || mKeyguardDelegate.isShowingAndNotHidden())) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005059 return false;
5060 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08005061 long[] pattern = null;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005062 switch (effectId) {
5063 case HapticFeedbackConstants.LONG_PRESS:
Amith Yamasanic33cb712010-02-10 15:21:49 -08005064 pattern = mLongPressVibePattern;
5065 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07005066 case HapticFeedbackConstants.VIRTUAL_KEY:
Amith Yamasanic33cb712010-02-10 15:21:49 -08005067 pattern = mVirtualKeyVibePattern;
5068 break;
5069 case HapticFeedbackConstants.KEYBOARD_TAP:
5070 pattern = mKeyboardTapVibePattern;
5071 break;
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07005072 case HapticFeedbackConstants.CLOCK_TICK:
5073 pattern = mClockTickVibePattern;
5074 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07005075 case HapticFeedbackConstants.SAFE_MODE_DISABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08005076 pattern = mSafeModeDisabledVibePattern;
5077 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07005078 case HapticFeedbackConstants.SAFE_MODE_ENABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08005079 pattern = mSafeModeEnabledVibePattern;
5080 break;
Amith Yamasanic33cb712010-02-10 15:21:49 -08005081 default:
5082 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005083 }
Dianne Hackbornf265ea92013-01-31 15:00:51 -08005084 int owningUid;
5085 String owningPackage;
5086 if (win != null) {
5087 owningUid = win.getOwningUid();
5088 owningPackage = win.getOwningPackage();
5089 } else {
5090 owningUid = android.os.Process.myUid();
Dianne Hackborn95d78532013-09-11 09:51:14 -07005091 owningPackage = mContext.getOpPackageName();
Dianne Hackbornf265ea92013-01-31 15:00:51 -08005092 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08005093 if (pattern.length == 1) {
5094 // One-shot vibration
John Spurlock1af30c72014-03-10 08:33:35 -04005095 mVibrator.vibrate(owningUid, owningPackage, pattern[0], AudioManager.STREAM_SYSTEM);
Amith Yamasanic33cb712010-02-10 15:21:49 -08005096 } else {
5097 // Pattern vibration
John Spurlock1af30c72014-03-10 08:33:35 -04005098 mVibrator.vibrate(owningUid, owningPackage, pattern, -1, AudioManager.STREAM_SYSTEM);
Amith Yamasanic33cb712010-02-10 15:21:49 -08005099 }
5100 return true;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005101 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005102
5103 @Override
5104 public void keepScreenOnStartedLw() {
Daniel Sandler0601eb72011-04-13 01:01:32 -04005105 }
5106
Jeff Brownc38c9be2012-10-04 13:16:19 -07005107 @Override
5108 public void keepScreenOnStoppedLw() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005109 if (mKeyguardDelegate != null && !mKeyguardDelegate.isShowingAndNotHidden()) {
Jim Miller25190572013-02-28 17:36:24 -08005110 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005111 }
5112 }
Mike Lockwoodfcb39242009-10-21 23:01:07 -04005113
Dianne Hackborndf89e652011-10-06 22:35:11 -07005114 private int updateSystemUiVisibilityLw() {
Joe Onorato664644d2011-01-23 17:53:23 -08005115 // If there is no window focused, there will be nobody to handle the events
5116 // anyway, so just hang on in whatever state we're in until things settle down.
John Spurlock79da8332013-09-20 12:04:47 -04005117 WindowState win = mFocusedWindow != null ? mFocusedWindow : mTopFullscreenOpaqueWindowState;
5118 if (win == null) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07005119 return 0;
5120 }
John Spurlock79da8332013-09-20 12:04:47 -04005121 if (win.getAttrs().type == TYPE_KEYGUARD && mHideLockScreen == true) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07005122 // We are updating at a point where the keyguard has gotten
5123 // focus, but we were last in a state where the top window is
5124 // hiding it. This is probably because the keyguard as been
5125 // shown while the top window was displayed, so we want to ignore
5126 // it here because this is just a very transient change and it
5127 // will quickly lose focus once it correctly gets hidden.
5128 return 0;
5129 }
John Spurlock32beb2c2013-03-11 10:16:47 -04005130
John Spurlock1db8b682014-02-18 11:18:59 -05005131 int tmpVisibility = PolicyControl.getSystemUiVisibility(win, null)
Dianne Hackborne26ab702011-10-16 13:21:33 -07005132 & ~mResettingSystemUiFlags
5133 & ~mForceClearedSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04005134 if (mForcingShowNavBar && win.getSurfaceLayer() < mForcingShowNavBarLayer) {
John Spurlockc6d1c602014-01-17 15:22:06 -05005135 tmpVisibility &= ~PolicyControl.adjustClearableFlags(win, View.SYSTEM_UI_CLEARABLE_FLAGS);
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08005136 }
John Spurlock79da8332013-09-20 12:04:47 -04005137 final int visibility = updateSystemBarsLw(win, mLastSystemUiFlags, tmpVisibility);
John Spurlockad3e6cb2013-04-30 08:47:43 -04005138 final int diff = visibility ^ mLastSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04005139 final boolean needsMenu = win.getNeedsMenuLw(mTopFullscreenOpaqueWindowState);
Dianne Hackborne0f085d2011-11-30 18:41:15 -08005140 if (diff == 0 && mLastFocusNeedsMenu == needsMenu
John Spurlock79da8332013-09-20 12:04:47 -04005141 && mFocusedApp == win.getAppToken()) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07005142 return 0;
5143 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07005144 mLastSystemUiFlags = visibility;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08005145 mLastFocusNeedsMenu = needsMenu;
John Spurlock79da8332013-09-20 12:04:47 -04005146 mFocusedApp = win.getAppToken();
Dianne Hackborndf89e652011-10-06 22:35:11 -07005147 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07005148 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07005149 public void run() {
Dianne Hackborn42e620c2012-06-24 13:20:51 -07005150 try {
5151 IStatusBarService statusbar = getStatusBarService();
5152 if (statusbar != null) {
5153 statusbar.setSystemUiVisibility(visibility, 0xffffffff);
5154 statusbar.topAppWindowChanged(needsMenu);
Joe Onorato664644d2011-01-23 17:53:23 -08005155 }
Dianne Hackborn42e620c2012-06-24 13:20:51 -07005156 } catch (RemoteException e) {
5157 // re-acquire status bar service next time it is needed.
5158 mStatusBarService = null;
Joe Onorato664644d2011-01-23 17:53:23 -08005159 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07005160 }
5161 });
5162 return diff;
Joe Onorato664644d2011-01-23 17:53:23 -08005163 }
5164
John Spurlock79da8332013-09-20 12:04:47 -04005165 private int updateSystemBarsLw(WindowState win, int oldVis, int vis) {
John Spurlockbd957402013-10-03 11:38:39 -04005166 // apply translucent bar vis flags
5167 WindowState transWin = mKeyguard != null && mKeyguard.isVisibleLw() && !mHideLockScreen
5168 ? mKeyguard
5169 : mTopFullscreenOpaqueWindowState;
5170 vis = mStatusBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
5171 vis = mNavigationBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
5172
John Spurlock27735a42013-08-14 17:57:38 -04005173 // prevent status bar interaction from clearing certain flags
John Spurlock79da8332013-09-20 12:04:47 -04005174 boolean statusBarHasFocus = win.getAttrs().type == TYPE_STATUS_BAR;
John Spurlockad3e6cb2013-04-30 08:47:43 -04005175 if (statusBarHasFocus) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04005176 int flags = View.SYSTEM_UI_FLAG_FULLSCREEN
5177 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlockcfc359a2013-09-05 10:42:03 -04005178 | View.SYSTEM_UI_FLAG_IMMERSIVE
John Spurlockf1a36642013-10-12 17:50:42 -04005179 | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
John Spurlockbd957402013-10-03 11:38:39 -04005180 | View.STATUS_BAR_TRANSLUCENT
5181 | View.NAVIGATION_BAR_TRANSLUCENT;
5182 vis = (vis & ~flags) | (oldVis & flags);
John Spurlockad3e6cb2013-04-30 08:47:43 -04005183 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04005184
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04005185 if (!areTranslucentBarsAllowed()) {
5186 vis &= ~(View.NAVIGATION_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSLUCENT);
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07005187 }
5188
John Spurlock27735a42013-08-14 17:57:38 -04005189 // update status bar
John Spurlockf1a36642013-10-12 17:50:42 -04005190 boolean immersiveSticky =
5191 (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
John Spurlock27735a42013-08-14 17:57:38 -04005192 boolean hideStatusBarWM =
John Spurlockbd957402013-10-03 11:38:39 -04005193 mTopFullscreenOpaqueWindowState != null &&
John Spurlockc6d1c602014-01-17 15:22:06 -05005194 (PolicyControl.getWindowFlags(mTopFullscreenOpaqueWindowState, null)
John Spurlock27735a42013-08-14 17:57:38 -04005195 & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0;
5196 boolean hideStatusBarSysui =
5197 (vis & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04005198 boolean hideNavBarSysui =
5199 (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0;
John Spurlockad3e6cb2013-04-30 08:47:43 -04005200
John Spurlock27735a42013-08-14 17:57:38 -04005201 boolean transientStatusBarAllowed =
5202 mStatusBar != null && (
5203 hideStatusBarWM
John Spurlockf1a36642013-10-12 17:50:42 -04005204 || (hideStatusBarSysui && immersiveSticky)
John Spurlock27735a42013-08-14 17:57:38 -04005205 || statusBarHasFocus);
5206
John Spurlockf1a36642013-10-12 17:50:42 -04005207 boolean transientNavBarAllowed =
5208 mNavigationBar != null &&
5209 hideNavBarSysui && immersiveSticky;
5210
John Spurlockf25706f2013-11-07 18:02:43 -05005211 boolean denyTransientStatus = mStatusBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04005212 && !transientStatusBarAllowed && hideStatusBarSysui;
John Spurlockf25706f2013-11-07 18:02:43 -05005213 boolean denyTransientNav = mNavigationBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04005214 && !transientNavBarAllowed;
5215 if (denyTransientStatus || denyTransientNav) {
John Spurlock27735a42013-08-14 17:57:38 -04005216 // clear the clearable flags instead
John Spurlockf1a36642013-10-12 17:50:42 -04005217 clearClearableFlagsLw();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005218 }
John Spurlock27735a42013-08-14 17:57:38 -04005219
5220 vis = mStatusBarController.updateVisibilityLw(transientStatusBarAllowed, oldVis, vis);
5221
5222 // update navigation bar
John Spurlockf1a36642013-10-12 17:50:42 -04005223 boolean oldImmersiveMode = isImmersiveMode(oldVis);
5224 boolean newImmersiveMode = isImmersiveMode(vis);
5225 if (win != null && oldImmersiveMode != newImmersiveMode) {
John Spurlock79da8332013-09-20 12:04:47 -04005226 final String pkg = win.getOwningPackage();
John Spurlockf1a36642013-10-12 17:50:42 -04005227 mImmersiveModeConfirmation.immersiveModeChanged(pkg, newImmersiveMode);
John Spurlock34e13d92013-08-10 06:52:28 -04005228 }
John Spurlock27735a42013-08-14 17:57:38 -04005229
John Spurlockf1a36642013-10-12 17:50:42 -04005230 vis = mNavigationBarController.updateVisibilityLw(transientNavBarAllowed, oldVis, vis);
5231
John Spurlocke1f366f2013-08-05 12:22:40 -04005232 return vis;
John Spurlockad3e6cb2013-04-30 08:47:43 -04005233 }
5234
John Spurlockf1a36642013-10-12 17:50:42 -04005235 private void clearClearableFlagsLw() {
5236 int newVal = mResettingSystemUiFlags | View.SYSTEM_UI_CLEARABLE_FLAGS;
5237 if (newVal != mResettingSystemUiFlags) {
5238 mResettingSystemUiFlags = newVal;
5239 mWindowManagerFuncs.reevaluateStatusBarVisibility();
5240 }
5241 }
5242
5243 private boolean isImmersiveMode(int vis) {
5244 final int flags = View.SYSTEM_UI_FLAG_IMMERSIVE | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
John Spurlock34e13d92013-08-10 06:52:28 -04005245 return mNavigationBar != null
5246 && (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0
Daniel Sandler900ece52013-10-18 15:53:27 -04005247 && (vis & flags) != 0
5248 && canHideNavigationBar();
John Spurlock34e13d92013-08-10 06:52:28 -04005249 }
5250
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07005251 /**
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04005252 * @return whether the navigation or status bar can be made translucent
5253 *
5254 * This should return true unless touch exploration is not enabled or
5255 * R.boolean.config_enableTranslucentDecor is false.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07005256 */
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04005257 private boolean areTranslucentBarsAllowed() {
Svetoslav8e3feb12014-02-24 13:46:47 -08005258 return mTranslucentDecorEnabled
5259 && !mAccessibilityManager.isTouchExplorationEnabled();
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07005260 }
5261
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04005262 // Use this instead of checking config_showNavigationBar so that it can be consistently
5263 // overridden by qemu.hw.mainkeys in the emulator.
Craig Mautnereda67292013-04-28 13:50:14 -07005264 @Override
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04005265 public boolean hasNavigationBar() {
5266 return mHasNavigationBar;
5267 }
5268
satok1bc0a492012-04-25 22:47:12 +09005269 @Override
5270 public void setLastInputMethodWindowLw(WindowState ime, WindowState target) {
5271 mLastInputMethodWindow = ime;
5272 mLastInputMethodTargetWindow = target;
5273 }
5274
Craig Mautnerf1b67412012-09-19 13:18:29 -07005275 @Override
Satoshi Kataoka658c7b82013-10-10 17:03:51 +09005276 public int getInputMethodWindowVisibleHeightLw() {
5277 return mDockBottom - mCurBottom;
5278 }
5279
5280 @Override
Craig Mautnerf1b67412012-09-19 13:18:29 -07005281 public void setCurrentUserLw(int newUserId) {
Craig Mautnerd625ab22013-09-06 13:40:31 -07005282 mCurrentUserId = newUserId;
Jim Miller5ecd8112013-01-09 18:50:26 -08005283 if (mKeyguardDelegate != null) {
5284 mKeyguardDelegate.setCurrentUser(newUserId);
Craig Mautnerf1b67412012-09-19 13:18:29 -07005285 }
John Spurlock13451a22012-09-28 14:40:41 -04005286 if (mStatusBarService != null) {
5287 try {
5288 mStatusBarService.setCurrentUser(newUserId);
5289 } catch (RemoteException e) {
5290 // oh well
5291 }
5292 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07005293 setLastInputMethodWindowLw(null, null);
Craig Mautnerf1b67412012-09-19 13:18:29 -07005294 }
5295
5296 @Override
Svetoslav Ganov545252f2012-12-10 18:29:24 -08005297 public boolean canMagnifyWindow(int windowType) {
5298 switch (windowType) {
5299 case WindowManager.LayoutParams.TYPE_INPUT_METHOD:
5300 case WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG:
5301 case WindowManager.LayoutParams.TYPE_NAVIGATION_BAR:
5302 case WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY: {
5303 return false;
5304 }
5305 }
5306 return true;
5307 }
5308
5309 @Override
5310 public boolean isTopLevelWindow(int windowType) {
5311 if (windowType >= WindowManager.LayoutParams.FIRST_SUB_WINDOW
5312 && windowType <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
5313 return (windowType == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG);
5314 }
5315 return true;
5316 }
5317
Jim Miller4eeb4f62012-11-08 00:04:29 -08005318 @Override
Jeff Brownd7a04de2012-06-17 14:17:52 -07005319 public void dump(String prefix, PrintWriter pw, String[] args) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005320 pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005321 pw.print(" mSystemReady="); pw.print(mSystemReady);
5322 pw.print(" mSystemBooted="); pw.println(mSystemBooted);
Jeff Brown2e7760e2012-04-11 15:14:55 -07005323 pw.print(prefix); pw.print("mLidState="); pw.print(mLidState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005324 pw.print(" mLidOpenRotation="); pw.print(mLidOpenRotation);
5325 pw.print(" mHdmiPlugged="); pw.println(mHdmiPlugged);
Dianne Hackborne26ab702011-10-16 13:21:33 -07005326 if (mLastSystemUiFlags != 0 || mResettingSystemUiFlags != 0
5327 || mForceClearedSystemUiFlags != 0) {
5328 pw.print(prefix); pw.print("mLastSystemUiFlags=0x");
5329 pw.print(Integer.toHexString(mLastSystemUiFlags));
5330 pw.print(" mResettingSystemUiFlags=0x");
5331 pw.print(Integer.toHexString(mResettingSystemUiFlags));
5332 pw.print(" mForceClearedSystemUiFlags=0x");
5333 pw.println(Integer.toHexString(mForceClearedSystemUiFlags));
Dianne Hackborndf89e652011-10-06 22:35:11 -07005334 }
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08005335 if (mLastFocusNeedsMenu) {
5336 pw.print(prefix); pw.print("mLastFocusNeedsMenu=");
5337 pw.println(mLastFocusNeedsMenu);
5338 }
Jeff Brownbcdfc622014-03-06 19:13:04 -08005339 pw.print(prefix); pw.print("mSupportAutoRotation="); pw.println(mSupportAutoRotation);
Daniel Sandler6396c722013-04-16 20:19:09 -04005340 pw.print(prefix); pw.print("mUiMode="); pw.print(mUiMode);
5341 pw.print(" mDockMode="); pw.print(mDockMode);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005342 pw.print(" mCarDockRotation="); pw.print(mCarDockRotation);
5343 pw.print(" mDeskDockRotation="); pw.println(mDeskDockRotation);
5344 pw.print(prefix); pw.print("mUserRotationMode="); pw.print(mUserRotationMode);
5345 pw.print(" mUserRotation="); pw.print(mUserRotation);
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005346 pw.print(" mAllowAllRotations="); pw.println(mAllowAllRotations);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07005347 pw.print(prefix); pw.print("mCurrentAppOrientation="); pw.println(mCurrentAppOrientation);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005348 pw.print(prefix); pw.print("mCarDockEnablesAccelerometer=");
5349 pw.print(mCarDockEnablesAccelerometer);
5350 pw.print(" mDeskDockEnablesAccelerometer=");
5351 pw.println(mDeskDockEnablesAccelerometer);
5352 pw.print(prefix); pw.print("mLidKeyboardAccessibility=");
5353 pw.print(mLidKeyboardAccessibility);
5354 pw.print(" mLidNavigationAccessibility="); pw.print(mLidNavigationAccessibility);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07005355 pw.print(" mLidControlsSleep="); pw.println(mLidControlsSleep);
5356 pw.print(prefix); pw.print("mLongPressOnPowerBehavior=");
5357 pw.print(mLongPressOnPowerBehavior);
5358 pw.print(" mHasSoftInput="); pw.println(mHasSoftInput);
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07005359 pw.print(prefix); pw.print("mScreenOnEarly="); pw.print(mScreenOnEarly);
5360 pw.print(" mScreenOnFully="); pw.print(mScreenOnFully);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07005361 pw.print(" mOrientationSensorEnabled="); pw.println(mOrientationSensorEnabled);
Dianne Hackbornc652de82013-02-15 16:32:56 -08005362 pw.print(prefix); pw.print("mOverscanScreen=("); pw.print(mOverscanScreenLeft);
5363 pw.print(","); pw.print(mOverscanScreenTop);
5364 pw.print(") "); pw.print(mOverscanScreenWidth);
5365 pw.print("x"); pw.println(mOverscanScreenHeight);
5366 if (mOverscanLeft != 0 || mOverscanTop != 0
5367 || mOverscanRight != 0 || mOverscanBottom != 0) {
5368 pw.print(prefix); pw.print("mOverscan left="); pw.print(mOverscanLeft);
5369 pw.print(" top="); pw.print(mOverscanTop);
5370 pw.print(" right="); pw.print(mOverscanRight);
5371 pw.print(" bottom="); pw.println(mOverscanBottom);
5372 }
Dianne Hackborn313440842013-02-19 19:22:59 -08005373 pw.print(prefix); pw.print("mRestrictedOverscanScreen=(");
5374 pw.print(mRestrictedOverscanScreenLeft);
5375 pw.print(","); pw.print(mRestrictedOverscanScreenTop);
5376 pw.print(") "); pw.print(mRestrictedOverscanScreenWidth);
5377 pw.print("x"); pw.println(mRestrictedOverscanScreenHeight);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005378 pw.print(prefix); pw.print("mUnrestrictedScreen=("); pw.print(mUnrestrictedScreenLeft);
5379 pw.print(","); pw.print(mUnrestrictedScreenTop);
5380 pw.print(") "); pw.print(mUnrestrictedScreenWidth);
5381 pw.print("x"); pw.println(mUnrestrictedScreenHeight);
5382 pw.print(prefix); pw.print("mRestrictedScreen=("); pw.print(mRestrictedScreenLeft);
5383 pw.print(","); pw.print(mRestrictedScreenTop);
5384 pw.print(") "); pw.print(mRestrictedScreenWidth);
5385 pw.print("x"); pw.println(mRestrictedScreenHeight);
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07005386 pw.print(prefix); pw.print("mStableFullscreen=("); pw.print(mStableFullscreenLeft);
5387 pw.print(","); pw.print(mStableFullscreenTop);
5388 pw.print(")-("); pw.print(mStableFullscreenRight);
5389 pw.print(","); pw.print(mStableFullscreenBottom); pw.println(")");
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07005390 pw.print(prefix); pw.print("mStable=("); pw.print(mStableLeft);
5391 pw.print(","); pw.print(mStableTop);
5392 pw.print(")-("); pw.print(mStableRight);
5393 pw.print(","); pw.print(mStableBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07005394 pw.print(prefix); pw.print("mSystem=("); pw.print(mSystemLeft);
5395 pw.print(","); pw.print(mSystemTop);
5396 pw.print(")-("); pw.print(mSystemRight);
5397 pw.print(","); pw.print(mSystemBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005398 pw.print(prefix); pw.print("mCur=("); pw.print(mCurLeft);
5399 pw.print(","); pw.print(mCurTop);
5400 pw.print(")-("); pw.print(mCurRight);
5401 pw.print(","); pw.print(mCurBottom); pw.println(")");
5402 pw.print(prefix); pw.print("mContent=("); pw.print(mContentLeft);
5403 pw.print(","); pw.print(mContentTop);
5404 pw.print(")-("); pw.print(mContentRight);
5405 pw.print(","); pw.print(mContentBottom); pw.println(")");
5406 pw.print(prefix); pw.print("mDock=("); pw.print(mDockLeft);
5407 pw.print(","); pw.print(mDockTop);
5408 pw.print(")-("); pw.print(mDockRight);
5409 pw.print(","); pw.print(mDockBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07005410 pw.print(prefix); pw.print("mDockLayer="); pw.print(mDockLayer);
5411 pw.print(" mStatusBarLayer="); pw.println(mStatusBarLayer);
Dianne Hackborn7ad44382012-10-18 17:46:00 -07005412 pw.print(prefix); pw.print("mShowingLockscreen="); pw.print(mShowingLockscreen);
5413 pw.print(" mShowingDream="); pw.print(mShowingDream);
5414 pw.print(" mDreamingLockscreen="); pw.println(mDreamingLockscreen);
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07005415 if (mLastInputMethodWindow != null) {
5416 pw.print(prefix); pw.print("mLastInputMethodWindow=");
5417 pw.println(mLastInputMethodWindow);
5418 }
5419 if (mLastInputMethodTargetWindow != null) {
5420 pw.print(prefix); pw.print("mLastInputMethodTargetWindow=");
5421 pw.println(mLastInputMethodTargetWindow);
5422 }
5423 if (mStatusBar != null) {
5424 pw.print(prefix); pw.print("mStatusBar=");
5425 pw.println(mStatusBar);
5426 }
5427 if (mNavigationBar != null) {
5428 pw.print(prefix); pw.print("mNavigationBar=");
5429 pw.println(mNavigationBar);
5430 }
5431 if (mKeyguard != null) {
5432 pw.print(prefix); pw.print("mKeyguard=");
5433 pw.println(mKeyguard);
5434 }
5435 if (mFocusedWindow != null) {
5436 pw.print(prefix); pw.print("mFocusedWindow=");
5437 pw.println(mFocusedWindow);
5438 }
5439 if (mFocusedApp != null) {
5440 pw.print(prefix); pw.print("mFocusedApp=");
5441 pw.println(mFocusedApp);
5442 }
5443 if (mWinDismissingKeyguard != null) {
5444 pw.print(prefix); pw.print("mWinDismissingKeyguard=");
5445 pw.println(mWinDismissingKeyguard);
5446 }
5447 if (mTopFullscreenOpaqueWindowState != null) {
5448 pw.print(prefix); pw.print("mTopFullscreenOpaqueWindowState=");
5449 pw.println(mTopFullscreenOpaqueWindowState);
5450 }
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08005451 if (mForcingShowNavBar) {
5452 pw.print(prefix); pw.print("mForcingShowNavBar=");
5453 pw.println(mForcingShowNavBar); pw.print( "mForcingShowNavBarLayer=");
5454 pw.println(mForcingShowNavBarLayer);
5455 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07005456 pw.print(prefix); pw.print("mTopIsFullscreen="); pw.print(mTopIsFullscreen);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005457 pw.print(" mHideLockScreen="); pw.println(mHideLockScreen);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07005458 pw.print(prefix); pw.print("mForceStatusBar="); pw.print(mForceStatusBar);
5459 pw.print(" mForceStatusBarFromKeyguard=");
5460 pw.println(mForceStatusBarFromKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005461 pw.print(prefix); pw.print("mDismissKeyguard="); pw.print(mDismissKeyguard);
Craig Mautnerad09bcc2012-10-08 13:33:11 -07005462 pw.print(" mWinDismissingKeyguard="); pw.print(mWinDismissingKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005463 pw.print(" mHomePressed="); pw.println(mHomePressed);
5464 pw.print(prefix); pw.print("mAllowLockscreenWhenOn="); pw.print(mAllowLockscreenWhenOn);
5465 pw.print(" mLockScreenTimeout="); pw.print(mLockScreenTimeout);
5466 pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive);
5467 pw.print(prefix); pw.print("mEndcallBehavior="); pw.print(mEndcallBehavior);
5468 pw.print(" mIncallPowerBehavior="); pw.print(mIncallPowerBehavior);
5469 pw.print(" mLongPressOnHomeBehavior="); pw.println(mLongPressOnHomeBehavior);
5470 pw.print(prefix); pw.print("mLandscapeRotation="); pw.print(mLandscapeRotation);
5471 pw.print(" mSeascapeRotation="); pw.println(mSeascapeRotation);
5472 pw.print(prefix); pw.print("mPortraitRotation="); pw.print(mPortraitRotation);
5473 pw.print(" mUpsideDownRotation="); pw.println(mUpsideDownRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07005474 pw.print(prefix); pw.print("mDemoHdmiRotation="); pw.print(mDemoHdmiRotation);
5475 pw.print(" mDemoHdmiRotationLock="); pw.println(mDemoHdmiRotationLock);
5476 pw.print(prefix); pw.print("mUndockedHdmiRotation="); pw.println(mUndockedHdmiRotation);
John Spurlock27735a42013-08-14 17:57:38 -04005477 mStatusBarController.dump(pw, prefix);
5478 mNavigationBarController.dump(pw, prefix);
John Spurlockc6d1c602014-01-17 15:22:06 -05005479 PolicyControl.dump(prefix, pw);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005480 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005481}