blob: c096bb78680bcb4b6f5082490d0f000c3cc8e614 [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;
Craig Mautner228742d2014-05-31 15:13:37 -070092import android.view.WindowManagerInternal;
Craig Mautnerae446592012-12-06 19:05:05 -080093import android.view.WindowManagerPolicy;
Craig Mautnerae446592012-12-06 19:05:05 -080094import android.view.accessibility.AccessibilityEvent;
95import 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 Mautner228742d2014-05-31 15:13:37 -0700101import com.android.internal.policy.impl.keyguard.KeyguardServiceDelegate.ShowListener;
Craig Mautnerae446592012-12-06 19:05:05 -0800102import com.android.internal.statusbar.IStatusBarService;
103import com.android.internal.telephony.ITelephony;
104import com.android.internal.widget.PointerLocationView;
Craig Mautner228742d2014-05-31 15:13:37 -0700105import com.android.server.LocalServices;
Craig Mautnerae446592012-12-06 19:05:05 -0800106
107import java.io.File;
108import java.io.FileReader;
109import java.io.IOException;
110import java.io.PrintWriter;
Craig Mautner228742d2014-05-31 15:13:37 -0700111import java.util.ArrayList;
Craig Mautner03924422014-03-19 19:48:38 -0700112import java.util.HashSet;
Craig Mautnerae446592012-12-06 19:05:05 -0800113
Dianne Hackbornc652de82013-02-15 16:32:56 -0800114import static android.view.WindowManager.LayoutParams.*;
Jeff Brownac143512012-04-05 18:57:33 -0700115import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_ABSENT;
116import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_OPEN;
117import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_CLOSED;
Dianne Hackborn08743722009-12-21 12:16:51 -0800118
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800119/**
The Android Open Source Project0727d222009-03-11 12:11:58 -0700120 * WindowManagerPolicy implementation for the Android phone UI. This
121 * introduces a new method suffix, Lp, for an internal lock of the
122 * PhoneWindowManager. This is used to protect some internal state, and
John Spurlock04db1762013-05-13 12:46:41 -0400123 * 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 -0700124 * of both of those when held.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800125 */
126public class PhoneWindowManager implements WindowManagerPolicy {
127 static final String TAG = "WindowManager";
128 static final boolean DEBUG = false;
Joe Onorato43a17652011-04-06 19:22:23 -0700129 static final boolean localLOGV = false;
The Android Open Source Project11267662009-03-18 17:39:47 -0700130 static final boolean DEBUG_LAYOUT = false;
Jeff Brown40013652012-05-16 21:22:36 -0700131 static final boolean DEBUG_INPUT = false;
Craig Mautner6fbda632012-07-03 09:26:39 -0700132 static final boolean DEBUG_STARTING_WINDOW = false;
Craig Mautner228742d2014-05-31 15:13:37 -0700133 static final boolean DEBUG_WAKEUP = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800134 static final boolean SHOW_STARTING_ANIMATIONS = true;
135 static final boolean SHOW_PROCESSES_ON_ALT_MENU = false;
Joe Onoratod208e702010-10-08 16:22:43 -0400136
Daniel Sandler6396c722013-04-16 20:19:09 -0400137 // Whether to allow dock apps with METADATA_DOCK_HOME to temporarily take over the Home key.
138 // No longer recommended for desk docks; still useful in car docks.
139 static final boolean ENABLE_CAR_DOCK_HOME_CAPTURE = true;
140 static final boolean ENABLE_DESK_DOCK_HOME_CAPTURE = false;
141
Jeff Brown6d8fd272014-05-20 21:24:38 -0700142 static final int SHORT_PRESS_POWER_NOTHING = 0;
143 static final int SHORT_PRESS_POWER_GO_TO_SLEEP = 1;
144 static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP = 2;
145 static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME = 3;
146
Joe Onoratod208e702010-10-08 16:22:43 -0400147 static final int LONG_PRESS_POWER_NOTHING = 0;
148 static final int LONG_PRESS_POWER_GLOBAL_ACTIONS = 1;
149 static final int LONG_PRESS_POWER_SHUT_OFF = 2;
Jeff Brown9a538ee2012-08-20 14:56:57 -0700150 static final int LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM = 3;
Michael Jurka3b1fc472011-06-13 10:54:40 -0700151
152 // These need to match the documentation/constant in
153 // core/res/res/values/config.xml
Joe Onorato46b0d682010-11-22 17:37:27 -0800154 static final int LONG_PRESS_HOME_NOTHING = 0;
Michael Wrightc9ebea72013-01-16 19:25:02 -0800155 static final int LONG_PRESS_HOME_RECENT_SYSTEM_UI = 1;
Jeff Browncaca8812013-05-09 13:34:33 -0700156 static final int LONG_PRESS_HOME_ASSIST = 2;
157
158 static final int DOUBLE_TAP_HOME_NOTHING = 0;
159 static final int DOUBLE_TAP_HOME_RECENT_SYSTEM_UI = 1;
Joe Onorato46b0d682010-11-22 17:37:27 -0800160
Dianne Hackborn5cb8d792009-05-21 17:34:15 -0700161 static final int APPLICATION_MEDIA_SUBLAYER = -2;
162 static final int APPLICATION_MEDIA_OVERLAY_SUBLAYER = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800163 static final int APPLICATION_PANEL_SUBLAYER = 1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800164 static final int APPLICATION_SUB_PANEL_SUBLAYER = 2;
Craig Mautner88400d32012-09-30 12:35:45 -0700165
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800166 static public final String SYSTEM_DIALOG_REASON_KEY = "reason";
167 static public final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions";
168 static public final String SYSTEM_DIALOG_REASON_RECENT_APPS = "recentapps";
Joe Onoratof275f0c2009-11-24 16:11:13 -0500169 static public final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey";
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700170 static public final String SYSTEM_DIALOG_REASON_ASSIST = "assist";
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800171
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700172 /**
173 * These are the system UI flags that, when changing, can cause the layout
174 * of the screen to change.
175 */
176 static final int SYSTEM_UI_CHANGING_LAYOUT =
John Spurlocke1f366f2013-08-05 12:22:40 -0400177 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlock7f4820a2013-10-08 12:54:35 -0400178 | View.SYSTEM_UI_FLAG_FULLSCREEN
179 | View.STATUS_BAR_TRANSLUCENT
180 | View.NAVIGATION_BAR_TRANSLUCENT;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700181
Jim Miller5ecd8112013-01-09 18:50:26 -0800182 /**
183 * Keyguard stuff
184 */
185 private WindowState mKeyguardScrim;
186
Jeff Brown6651a632011-11-28 12:59:11 -0800187 /* Table of Application Launch keys. Maps from key codes to intent categories.
188 *
189 * These are special keys that are used to launch particular kinds of applications,
190 * such as a web browser. HID defines nearly a hundred of them in the Consumer (0x0C)
191 * usage page. We don't support quite that many yet...
192 */
193 static SparseArray<String> sApplicationLaunchKeyCategories;
194 static {
195 sApplicationLaunchKeyCategories = new SparseArray<String>();
196 sApplicationLaunchKeyCategories.append(
197 KeyEvent.KEYCODE_EXPLORER, Intent.CATEGORY_APP_BROWSER);
198 sApplicationLaunchKeyCategories.append(
199 KeyEvent.KEYCODE_ENVELOPE, Intent.CATEGORY_APP_EMAIL);
200 sApplicationLaunchKeyCategories.append(
201 KeyEvent.KEYCODE_CONTACTS, Intent.CATEGORY_APP_CONTACTS);
202 sApplicationLaunchKeyCategories.append(
203 KeyEvent.KEYCODE_CALENDAR, Intent.CATEGORY_APP_CALENDAR);
204 sApplicationLaunchKeyCategories.append(
205 KeyEvent.KEYCODE_MUSIC, Intent.CATEGORY_APP_MUSIC);
206 sApplicationLaunchKeyCategories.append(
207 KeyEvent.KEYCODE_CALCULATOR, Intent.CATEGORY_APP_CALCULATOR);
208 }
209
Dianne Hackborndf89e652011-10-06 22:35:11 -0700210 /**
211 * Lock protecting internal state. Must not call out into window
212 * manager with lock held. (This lock will be acquired in places
213 * where the window manager is calling in with its own lock held.)
214 */
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800215 private final Object mLock = new Object();
Dianne Hackborndf89e652011-10-06 22:35:11 -0700216
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800217 Context mContext;
218 IWindowManager mWindowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700219 WindowManagerFuncs mWindowManagerFuncs;
Craig Mautner228742d2014-05-31 15:13:37 -0700220 WindowManagerInternal mWindowManagerInternal;
Jeff Brown96307042012-07-27 15:51:34 -0700221 PowerManager mPowerManager;
Joe Onorato93056472010-09-10 10:30:46 -0400222 IStatusBarService mStatusBarService;
Jeff Browncaca8812013-05-09 13:34:33 -0700223 boolean mPreloadedRecentApps;
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700224 final Object mServiceAquireLock = new Object();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800225 Vibrator mVibrator; // Vibrator for giving feedback of orientation changes
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700226 SearchManager mSearchManager;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800227
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700228 // Vibrator pattern for haptic feedback of a long press.
229 long[] mLongPressVibePattern;
Craig Mautner88400d32012-09-30 12:35:45 -0700230
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700231 // Vibrator pattern for haptic feedback of virtual key press.
232 long[] mVirtualKeyVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700233
Amith Yamasanic33cb712010-02-10 15:21:49 -0800234 // Vibrator pattern for a short vibration.
235 long[] mKeyboardTapVibePattern;
236
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700237 // Vibrator pattern for haptic feedback during boot when safe mode is disabled.
238 long[] mSafeModeDisabledVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700239
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700240 // Vibrator pattern for haptic feedback during boot when safe mode is enabled.
241 long[] mSafeModeEnabledVibePattern;
Romain Guy8154cd32010-03-29 14:41:15 -0700242
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800243 /** If true, hitting shift & menu will broadcast Intent.ACTION_BUG_REPORT */
244 boolean mEnableShiftMenuBugReports = false;
Mike Lockwoodd747dc82011-09-13 16:28:22 -0400245
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800246 boolean mSafeMode;
247 WindowState mStatusBar = null;
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700248 int mStatusBarHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400249 WindowState mNavigationBar = null;
Daniel Sandler36412a72011-08-04 09:35:13 -0400250 boolean mHasNavigationBar = false;
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700251 boolean mCanHideNavigationBar = false;
Daniel Sandler4a066c52012-04-20 14:49:13 -0400252 boolean mNavigationBarCanMove = false; // can the navigation bar ever move to the side?
253 boolean mNavigationBarOnBottom = true; // is the navigation bar on the bottom *right now*?
254 int[] mNavigationBarHeightForRotation = new int[4];
255 int[] mNavigationBarWidthForRotation = new int[4];
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400256
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800257 WindowState mKeyguard = null;
Jim Miller5ecd8112013-01-09 18:50:26 -0800258 KeyguardServiceDelegate mKeyguardDelegate;
Craig Mautner228742d2014-05-31 15:13:37 -0700259 // The following are only accessed on the mHandler thread.
260 boolean mKeyguardDrawComplete;
261 boolean mWindowManagerDrawComplete;
262 ArrayList<ScreenOnListener> mScreenOnListeners = new ArrayList<ScreenOnListener>();
263 final IRemoteCallback mWindowManagerDrawCallback = new IRemoteCallback.Stub() {
264 @Override
265 public void sendResult(Bundle data) {
266 if (DEBUG_WAKEUP) Slog.i(TAG, "All windows ready for display!");
267 mHandler.sendEmptyMessage(MSG_WINDOW_MANAGER_DRAWN_COMPLETE);
268 }
269 };
270 final ShowListener mKeyguardDelegateCallback = new ShowListener() {
271 @Override
272 public void onShown(IBinder windowToken) {
273 if (DEBUG_WAKEUP) Slog.d(TAG, "mKeyguardDelegate.ShowListener.onShown.");
274 mHandler.sendEmptyMessage(MSG_KEYGUARD_DRAWN_COMPLETE);
275 }
276 };
277
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800278 GlobalActions mGlobalActions;
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700279 volatile boolean mPowerKeyHandled; // accessed from input reader and handler thread
280 boolean mPendingPowerKeyUpCanceled;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800281 Handler mHandler;
satok1bc0a492012-04-25 22:47:12 +0900282 WindowState mLastInputMethodWindow = null;
283 WindowState mLastInputMethodTargetWindow = null;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800284
Jeff Brown68b909d2011-12-07 16:36:01 -0800285 static final int RECENT_APPS_BEHAVIOR_SHOW_OR_DISMISS = 0;
286 static final int RECENT_APPS_BEHAVIOR_EXIT_TOUCH_MODE_AND_SHOW = 1;
Jeff Brown602ab322012-05-16 13:33:47 -0700287 static final int RECENT_APPS_BEHAVIOR_DISMISS = 2;
288 static final int RECENT_APPS_BEHAVIOR_DISMISS_AND_SWITCH = 3;
Jeff Brown68b909d2011-12-07 16:36:01 -0800289
290 RecentApplicationsDialog mRecentAppsDialog;
291 int mRecentAppsDialogHeldModifiers;
Jeff Browncf39bdf2012-05-18 14:41:19 -0700292 boolean mLanguageSwitchKeyPressed;
Jeff Brown68b909d2011-12-07 16:36:01 -0800293
Jeff Brown2e7760e2012-04-11 15:14:55 -0700294 int mLidState = LID_ABSENT;
Jeff Browndaa37532012-05-01 15:54:03 -0700295 boolean mHaveBuiltInKeyboard;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800296
Dianne Hackbornc777e072010-02-12 13:07:59 -0800297 boolean mSystemReady;
Dianne Hackbornba24e4d2011-09-01 11:17:06 -0700298 boolean mSystemBooted;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800299 boolean mHdmiPlugged;
Jeff Brown4f5fa282014-06-12 19:19:15 -0700300 IUiModeManager mUiModeManager;
Daniel Sandler6396c722013-04-16 20:19:09 -0400301 int mUiMode;
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700302 int mDockMode = Intent.EXTRA_DOCK_STATE_UNDOCKED;
Mike Lockwood1753f7f2009-08-24 14:49:07 -0700303 int mLidOpenRotation;
Mike Lockwood2d1efbd2009-09-16 12:15:53 -0400304 int mCarDockRotation;
305 int mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -0700306 int mUndockedHdmiRotation;
307 int mDemoHdmiRotation;
308 boolean mDemoHdmiRotationLock;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400309
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700310 // Default display does not rotate, apps that require non-default orientation will have to
311 // have the orientation emulated.
312 private boolean mForceDefaultOrientation = false;
313
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400314 int mUserRotationMode = WindowManagerPolicy.USER_ROTATION_FREE;
315 int mUserRotation = Surface.ROTATION_0;
Jeff Brown207673cd2012-06-05 17:47:11 -0700316 boolean mAccelerometerDefault;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400317
Jeff Brownbcdfc622014-03-06 19:13:04 -0800318 boolean mSupportAutoRotation;
Jeff Brownd3187e32011-09-21 19:26:44 -0700319 int mAllowAllRotations = -1;
Mike Lockwoode9867d22009-09-20 01:59:02 -0400320 boolean mCarDockEnablesAccelerometer;
321 boolean mDeskDockEnablesAccelerometer;
Dianne Hackborn2862fff2009-09-15 22:56:29 -0700322 int mLidKeyboardAccessibility;
323 int mLidNavigationAccessibility;
Jeff Brownc458ce92012-04-30 14:58:40 -0700324 boolean mLidControlsSleep;
Jeff Brown6d8fd272014-05-20 21:24:38 -0700325 int mShortPressOnPowerBehavior = -1;
Joe Onoratod208e702010-10-08 16:22:43 -0400326 int mLongPressOnPowerBehavior = -1;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -0700327 boolean mScreenOnEarly = false;
328 boolean mScreenOnFully = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800329 boolean mOrientationSensorEnabled = false;
330 int mCurrentAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800331 boolean mHasSoftInput = false;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -0700332 boolean mTouchExplorationEnabled = false;
Daniel Sandlerdd73ee42013-10-11 22:19:59 -0400333 boolean mTranslucentDecorEnabled = true;
Craig Mautner967212c2013-04-13 21:10:58 -0700334
Jeff Brown70825162012-03-28 17:27:48 -0700335 int mPointerLocationMode = 0; // guarded by mLock
Joe Onorato664644d2011-01-23 17:53:23 -0800336
337 // The last window we were told about in focusChanged.
338 WindowState mFocusedWindow;
Dianne Hackborne0f085d2011-11-30 18:41:15 -0800339 IApplicationToken mFocusedApp;
Joe Onorato664644d2011-01-23 17:53:23 -0800340
Craig Mautner037aa8d2013-06-07 10:35:44 -0700341 private final class PointerLocationPointerEventListener implements PointerEventListener {
Jeff Browna41ca772010-08-11 14:46:32 -0700342 @Override
Craig Mautner037aa8d2013-06-07 10:35:44 -0700343 public void onPointerEvent(MotionEvent motionEvent) {
344 if (mPointerLocationView != null) {
345 mPointerLocationView.addPointerEvent(motionEvent);
Jeff Browna41ca772010-08-11 14:46:32 -0700346 }
347 }
Jeff Brown32cbc38552011-12-01 14:01:49 -0800348 }
Jeff Brown70825162012-03-28 17:27:48 -0700349
350 // Pointer location view state, only modified on the mHandler Looper.
Craig Mautner037aa8d2013-06-07 10:35:44 -0700351 PointerLocationPointerEventListener mPointerLocationPointerEventListener;
Jeff Brown70825162012-03-28 17:27:48 -0700352 PointerLocationView mPointerLocationView;
Jeff Brown32cbc38552011-12-01 14:01:49 -0800353
Dianne Hackbornc652de82013-02-15 16:32:56 -0800354 // The current size of the screen; really; extends into the overscan area of
355 // the screen and doesn't account for any system elements like the status bar.
356 int mOverscanScreenLeft, mOverscanScreenTop;
357 int mOverscanScreenWidth, mOverscanScreenHeight;
358 // The current visible size of the screen; really; (ir)regardless of whether the status
359 // bar can be hidden but not extending into the overscan area.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800360 int mUnrestrictedScreenLeft, mUnrestrictedScreenTop;
361 int mUnrestrictedScreenWidth, mUnrestrictedScreenHeight;
Dianne Hackborn313440842013-02-19 19:22:59 -0800362 // Like mOverscanScreen*, but allowed to move into the overscan region where appropriate.
363 int mRestrictedOverscanScreenLeft, mRestrictedOverscanScreenTop;
364 int mRestrictedOverscanScreenWidth, mRestrictedOverscanScreenHeight;
Dianne Hackborn82de1ae2010-10-28 11:28:39 -0700365 // The current size of the screen; these may be different than (0,0)-(dw,dh)
366 // if the status bar can't be hidden; in that case it effectively carves out
367 // that area of the display from all other windows.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800368 int mRestrictedScreenLeft, mRestrictedScreenTop;
369 int mRestrictedScreenWidth, mRestrictedScreenHeight;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700370 // During layout, the current screen borders accounting for any currently
371 // visible system UI elements.
372 int mSystemLeft, mSystemTop, mSystemRight, mSystemBottom;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700373 // For applications requesting stable content insets, these are them.
374 int mStableLeft, mStableTop, mStableRight, mStableBottom;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -0700375 // For applications requesting stable content insets but have also set the
376 // fullscreen window flag, these are the stable dimensions without the status bar.
377 int mStableFullscreenLeft, mStableFullscreenTop;
378 int mStableFullscreenRight, mStableFullscreenBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800379 // During layout, the current screen borders with all outer decoration
380 // (status bar, input method dock) accounted for.
381 int mCurLeft, mCurTop, mCurRight, mCurBottom;
382 // During layout, the frame in which content should be displayed
383 // to the user, accounting for all screen decoration except for any
384 // space they deem as available for other content. This is usually
385 // the same as mCur*, but may be larger if the screen decor has supplied
386 // content insets.
387 int mContentLeft, mContentTop, mContentRight, mContentBottom;
Dianne Hackborn8e11ef02010-11-18 19:47:42 -0800388 // During layout, the current screen borders along which input method
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800389 // windows are placed.
390 int mDockLeft, mDockTop, mDockRight, mDockBottom;
391 // During layout, the layer at which the doc window is placed.
392 int mDockLayer;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700393 // During layout, this is the layer of the status bar.
394 int mStatusBarLayer;
Dianne Hackborne26ab702011-10-16 13:21:33 -0700395 int mLastSystemUiFlags;
396 // Bits that we are in the process of clearing, so we want to prevent
397 // them from being set by applications until everything has been updated
398 // to have them clear.
399 int mResettingSystemUiFlags = 0;
400 // Bits that we are currently always keeping cleared.
401 int mForceClearedSystemUiFlags = 0;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -0800402 // What we last reported to system UI about whether the compatibility
403 // menu needs to be displayed.
404 boolean mLastFocusNeedsMenu = false;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700405
406 FakeWindow mHideNavFakeWindow = null;
407
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800408 static final Rect mTmpParentFrame = new Rect();
409 static final Rect mTmpDisplayFrame = new Rect();
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800410 static final Rect mTmpOverscanFrame = new Rect();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800411 static final Rect mTmpContentFrame = new Rect();
412 static final Rect mTmpVisibleFrame = new Rect();
John Spurlock46646232013-09-30 22:32:42 -0400413 static final Rect mTmpDecorFrame = new Rect();
Dianne Hackborn1f903c32011-09-13 19:18:06 -0700414 static final Rect mTmpNavigationFrame = new Rect();
Craig Mautner967212c2013-04-13 21:10:58 -0700415
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800416 WindowState mTopFullscreenOpaqueWindowState;
Craig Mautner03924422014-03-19 19:48:38 -0700417 HashSet<IApplicationToken> mAppsToBeHidden = new HashSet<IApplicationToken>();
Joe Onorato93056472010-09-10 10:30:46 -0400418 boolean mTopIsFullscreen;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800419 boolean mForceStatusBar;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -0700420 boolean mForceStatusBarFromKeyguard;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700421 boolean mHideLockScreen;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -0800422 boolean mForcingShowNavBar;
423 int mForcingShowNavBarLayer;
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700424
425 // States of keyguard dismiss.
426 private static final int DISMISS_KEYGUARD_NONE = 0; // Keyguard not being dismissed.
427 private static final int DISMISS_KEYGUARD_START = 1; // Keyguard needs to be dismissed.
428 private static final int DISMISS_KEYGUARD_CONTINUE = 2; // Keyguard has been dismissed.
429 int mDismissKeyguard = DISMISS_KEYGUARD_NONE;
430
431 /** The window that is currently dismissing the keyguard. Dismissing the keyguard must only
432 * be done once per window. */
433 private WindowState mWinDismissingKeyguard;
434
Dianne Hackborn7ad44382012-10-18 17:46:00 -0700435 boolean mShowingLockscreen;
436 boolean mShowingDream;
437 boolean mDreamingLockscreen;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800438 boolean mHomePressed;
Jeff Browncaca8812013-05-09 13:34:33 -0700439 boolean mHomeConsumed;
440 boolean mHomeDoubleTapPending;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800441 Intent mHomeIntent;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700442 Intent mCarDockIntent;
443 Intent mDeskDockIntent;
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700444 boolean mSearchKeyShortcutPending;
445 boolean mConsumeSearchKeyUp;
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700446 boolean mAssistKeyLongPressed;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800447
Mike Lockwood28569302010-01-28 11:54:40 -0500448 // support for activating the lock screen while the screen is on
449 boolean mAllowLockscreenWhenOn;
450 int mLockScreenTimeout;
451 boolean mLockScreenTimerActive;
452
David Brownbaf8d092010-03-08 21:52:59 -0800453 // Behavior of ENDCALL Button. (See Settings.System.END_BUTTON_BEHAVIOR.)
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800454 int mEndcallBehavior;
David Brownbaf8d092010-03-08 21:52:59 -0800455
456 // Behavior of POWER button while in-call and screen on.
457 // (See Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR.)
458 int mIncallPowerBehavior;
459
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700460 Display mDisplay;
461
Dianne Hackborn9d132642011-04-21 17:26:39 -0700462 int mLandscapeRotation = 0; // default landscape rotation
463 int mSeascapeRotation = 0; // "other" landscape rotation, 180 degrees from mLandscapeRotation
464 int mPortraitRotation = 0; // default portrait rotation
465 int mUpsideDownRotation = 0; // "other" portrait rotation
Mitsuru Oshima831d0d92009-06-16 18:27:18 -0700466
Dianne Hackbornc652de82013-02-15 16:32:56 -0800467 int mOverscanLeft = 0;
468 int mOverscanTop = 0;
469 int mOverscanRight = 0;
470 int mOverscanBottom = 0;
471
Joe Onorato46b0d682010-11-22 17:37:27 -0800472 // What we do when the user long presses on home
Jeff Browncaca8812013-05-09 13:34:33 -0700473 private int mLongPressOnHomeBehavior;
474
475 // What we do when the user double-taps on home
476 private int mDoubleTapOnHomeBehavior;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800477
Winson Chung9112ec32011-06-27 13:15:32 -0700478 // Screenshot trigger states
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700479 // Time to volume and power must be pressed within this interval of each other.
480 private static final long SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS = 150;
Winson Chung1cea2f32012-10-08 20:42:01 -0700481 // Increase the chord delay when taking a screenshot from the keyguard
482 private static final float KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER = 2.5f;
Christopher Tatee90585f2012-03-05 18:56:25 -0800483 private boolean mScreenshotChordEnabled;
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700484 private boolean mVolumeDownKeyTriggered;
485 private long mVolumeDownKeyTime;
486 private boolean mVolumeDownKeyConsumedByScreenshotChord;
487 private boolean mVolumeUpKeyTriggered;
488 private boolean mPowerKeyTriggered;
489 private long mPowerKeyTime;
Winson Chung9112ec32011-06-27 13:15:32 -0700490
Michael Wrightb854e242013-02-05 17:54:02 -0800491 /* The number of steps between min and max brightness */
492 private static final int BRIGHTNESS_STEPS = 10;
493
Christopher Tate5e08af02012-09-21 17:17:22 -0700494 SettingsObserver mSettingsObserver;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800495 ShortcutManager mShortcutManager;
496 PowerManager.WakeLock mBroadcastWakeLock;
Jeff Brown40013652012-05-16 21:22:36 -0700497 boolean mHavePendingMediaKeyRepeatWithWakeLock;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800498
Craig Mautnerd625ab22013-09-06 13:40:31 -0700499 private int mCurrentUserId;
500
Justin Kohd378ad72013-04-01 12:18:26 -0700501 // Maps global key codes to the components that will handle them.
502 private GlobalKeyManager mGlobalKeyManager;
503
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700504 // Fallback actions by key code.
505 private final SparseArray<KeyCharacterMap.FallbackAction> mFallbackActions =
506 new SparseArray<KeyCharacterMap.FallbackAction>();
Jeff Brown49ed71d2010-12-06 17:13:33 -0800507
Jeff Brown70825162012-03-28 17:27:48 -0700508 private static final int MSG_ENABLE_POINTER_LOCATION = 1;
509 private static final int MSG_DISABLE_POINTER_LOCATION = 2;
Jeff Brown40013652012-05-16 21:22:36 -0700510 private static final int MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK = 3;
511 private static final int MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK = 4;
Craig Mautner228742d2014-05-31 15:13:37 -0700512 private static final int MSG_KEYGUARD_DRAWN_COMPLETE = 5;
513 private static final int MSG_KEYGUARD_DRAWN_TIMEOUT = 6;
514 private static final int MSG_WINDOW_MANAGER_DRAWN_COMPLETE = 7;
515 private static final int MSG_WAKING_UP = 8;
Jeff Brown70825162012-03-28 17:27:48 -0700516
517 private class PolicyHandler extends Handler {
518 @Override
519 public void handleMessage(Message msg) {
520 switch (msg.what) {
521 case MSG_ENABLE_POINTER_LOCATION:
522 enablePointerLocation();
523 break;
524 case MSG_DISABLE_POINTER_LOCATION:
525 disablePointerLocation();
526 break;
Jeff Brown40013652012-05-16 21:22:36 -0700527 case MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK:
528 dispatchMediaKeyWithWakeLock((KeyEvent)msg.obj);
529 break;
530 case MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK:
531 dispatchMediaKeyRepeatWithWakeLock((KeyEvent)msg.obj);
532 break;
Craig Mautner228742d2014-05-31 15:13:37 -0700533 case MSG_KEYGUARD_DRAWN_COMPLETE:
534 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mKeyguardDrawComplete");
535 mKeyguardDrawComplete = true;
536 finishScreenTurningOn();
537 break;
538 case MSG_KEYGUARD_DRAWN_TIMEOUT:
539 Slog.w(TAG, "Keyguard drawn timeout. Setting mKeyguardDrawComplete");
540 mKeyguardDrawComplete = true;
541 finishScreenTurningOn();
542 break;
543 case MSG_WINDOW_MANAGER_DRAWN_COMPLETE:
544 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mWindowManagerDrawComplete");
545 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
546 mWindowManagerDrawComplete = true;
547 finishScreenTurningOn();
548 break;
549 case MSG_WAKING_UP:
550 handleWakingUp((ScreenOnListener) msg.obj);
551 break;
Jeff Brown70825162012-03-28 17:27:48 -0700552 }
553 }
554 }
555
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800556 private UEventObserver mHDMIObserver = new UEventObserver() {
557 @Override
558 public void onUEvent(UEventObserver.UEvent event) {
559 setHdmiPlugged("1".equals(event.get("SWITCH_STATE")));
560 }
561 };
562
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800563 class SettingsObserver extends ContentObserver {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800564 SettingsObserver(Handler handler) {
565 super(handler);
566 }
David Brownbaf8d092010-03-08 21:52:59 -0800567
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800568 void observe() {
Christopher Tate5e08af02012-09-21 17:17:22 -0700569 // Observe all users' changes
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800570 ContentResolver resolver = mContext.getContentResolver();
571 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700572 Settings.System.END_BUTTON_BEHAVIOR), false, this,
573 UserHandle.USER_ALL);
David Brownbaf8d092010-03-08 21:52:59 -0800574 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700575 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR), false, this,
576 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800577 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700578 Settings.System.ACCELEROMETER_ROTATION), false, this,
579 UserHandle.USER_ALL);
Mike Lockwood28569302010-01-28 11:54:40 -0500580 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700581 Settings.System.USER_ROTATION), false, this,
582 UserHandle.USER_ALL);
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400583 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700584 Settings.System.SCREEN_OFF_TIMEOUT), false, this,
585 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800586 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700587 Settings.System.POINTER_LOCATION), false, this,
588 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800589 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700590 Settings.Secure.DEFAULT_INPUT_METHOD), false, this,
591 UserHandle.USER_ALL);
Dianne Hackborn03759ed2009-03-27 16:04:08 -0700592 resolver.registerContentObserver(Settings.System.getUriFor(
John Spurlockf1a36642013-10-12 17:50:42 -0400593 Settings.Secure.IMMERSIVE_MODE_CONFIRMATIONS), false, this,
Christopher Tate5e08af02012-09-21 17:17:22 -0700594 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800595 updateSettings();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800596 }
597
598 @Override public void onChange(boolean selfChange) {
Dianne Hackbornc777e072010-02-12 13:07:59 -0800599 updateSettings();
Jeff Brown01a98dd2011-09-20 15:08:29 -0700600 updateRotation(false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800601 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800602 }
Craig Mautner967212c2013-04-13 21:10:58 -0700603
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800604 class MyOrientationListener extends WindowOrientationListener {
Craig Mautnereee29c42013-01-17 14:44:34 -0800605 MyOrientationListener(Context context, Handler handler) {
606 super(context, handler);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800607 }
Craig Mautner967212c2013-04-13 21:10:58 -0700608
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800609 @Override
Jeff Brownc0347aa2011-09-23 17:26:09 -0700610 public void onProposedRotationChanged(int rotation) {
Craig Mautnereda67292013-04-28 13:50:14 -0700611 if (localLOGV) Slog.v(TAG, "onProposedRotationChanged, rotation=" + rotation);
Jeff Brown01a98dd2011-09-20 15:08:29 -0700612 updateRotation(false);
613 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800614 }
615 MyOrientationListener mOrientationListener;
616
John Spurlock27735a42013-08-14 17:57:38 -0400617 private final BarController mStatusBarController = new BarController("StatusBar",
John Spurlock5b9145b2013-08-20 15:13:47 -0400618 View.STATUS_BAR_TRANSIENT,
619 View.STATUS_BAR_UNHIDE,
John Spurlockbd957402013-10-03 11:38:39 -0400620 View.STATUS_BAR_TRANSLUCENT,
621 StatusBarManager.WINDOW_STATUS_BAR,
622 WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
John Spurlock5b9145b2013-08-20 15:13:47 -0400623
John Spurlock27735a42013-08-14 17:57:38 -0400624 private final BarController mNavigationBarController = new BarController("NavigationBar",
John Spurlock5b9145b2013-08-20 15:13:47 -0400625 View.NAVIGATION_BAR_TRANSIENT,
626 View.NAVIGATION_BAR_UNHIDE,
John Spurlockbd957402013-10-03 11:38:39 -0400627 View.NAVIGATION_BAR_TRANSLUCENT,
628 StatusBarManager.WINDOW_NAVIGATION_BAR,
629 WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
John Spurlock5b9145b2013-08-20 15:13:47 -0400630
John Spurlockf1a36642013-10-12 17:50:42 -0400631 private ImmersiveModeConfirmation mImmersiveModeConfirmation;
John Spurlock32beb2c2013-03-11 10:16:47 -0400632
Craig Mautner037aa8d2013-06-07 10:35:44 -0700633 private SystemGesturesPointerEventListener mSystemGestures;
John Spurlock32beb2c2013-03-11 10:16:47 -0400634
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700635 IStatusBarService getStatusBarService() {
636 synchronized (mServiceAquireLock) {
637 if (mStatusBarService == null) {
638 mStatusBarService = IStatusBarService.Stub.asInterface(
639 ServiceManager.getService("statusbar"));
640 }
641 return mStatusBarService;
642 }
643 }
644
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700645 /*
646 * We always let the sensor be switched on by default except when
647 * the user has explicitly disabled sensor based rotation or when the
648 * screen is switched off.
649 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700650 boolean needSensorRunningLp() {
Jeff Brownbcdfc622014-03-06 19:13:04 -0800651 if (mSupportAutoRotation) {
652 if (mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
653 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
654 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT
655 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) {
656 // If the application has explicitly requested to follow the
657 // orientation, then we need to turn the sensor on.
658 return true;
659 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800660 }
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700661 if ((mCarDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_CAR) ||
Jeff Brown1a693182011-11-08 14:44:16 -0800662 (mDeskDockEnablesAccelerometer && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
663 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
664 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK))) {
Mike Lockwoode9867d22009-09-20 01:59:02 -0400665 // enable accelerometer if we are docked in a dock that enables accelerometer
666 // orientation management,
667 return true;
668 }
Jeff Brown207673cd2012-06-05 17:47:11 -0700669 if (mUserRotationMode == USER_ROTATION_LOCKED) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800670 // If the setting for using the sensor by default is enabled, then
671 // we will always leave it on. Note that the user could go to
672 // a window that forces an orientation that does not use the
673 // sensor and in theory we could turn it off... however, when next
674 // turning it on we won't have a good value for the current
675 // orientation for a little bit, which can cause orientation
676 // changes to lag, so we'd like to keep it always on. (It will
677 // still be turned off when the screen is off.)
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700678 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800679 }
Jeff Brownbcdfc622014-03-06 19:13:04 -0800680 return mSupportAutoRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800681 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700682
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800683 /*
684 * Various use cases for invoking this function
685 * screen turning off, should always disable listeners if already enabled
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700686 * screen turned on and current app has sensor based orientation, enable listeners
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800687 * if not already enabled
688 * screen turned on and current app does not have sensor orientation, disable listeners if
689 * already enabled
690 * screen turning on and current app has sensor based orientation, enable listeners if needed
691 * screen turning on and current app has nosensor based orientation, do nothing
692 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700693 void updateOrientationListenerLp() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800694 if (!mOrientationListener.canDetectOrientation()) {
695 // If sensor is turned off or nonexistent for some reason
696 return;
697 }
698 //Could have been invoked due to screen turning on or off or
699 //change of the currently visible window's orientation
Craig Mautnereda67292013-04-28 13:50:14 -0700700 if (localLOGV) Slog.v(TAG, "Screen status="+mScreenOnEarly+
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800701 ", current orientation="+mCurrentAppOrientation+
702 ", SensorEnabled="+mOrientationSensorEnabled);
703 boolean disable = true;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -0700704 if (mScreenOnEarly) {
The Android Open Source Project0727d222009-03-11 12:11:58 -0700705 if (needSensorRunningLp()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800706 disable = false;
707 //enable listener if not already enabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700708 if (!mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800709 mOrientationListener.enable();
Craig Mautnereda67292013-04-28 13:50:14 -0700710 if(localLOGV) Slog.v(TAG, "Enabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800711 mOrientationSensorEnabled = true;
712 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700713 }
714 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800715 //check if sensors need to be disabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700716 if (disable && mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800717 mOrientationListener.disable();
Craig Mautnereda67292013-04-28 13:50:14 -0700718 if(localLOGV) Slog.v(TAG, "Disabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800719 mOrientationSensorEnabled = false;
720 }
721 }
722
Jeff Brown4d396052010-10-29 21:50:21 -0700723 private void interceptPowerKeyDown(boolean handled) {
724 mPowerKeyHandled = handled;
725 if (!handled) {
Justin Kohfeabd2c2014-05-02 10:02:44 -0700726 mHandler.postDelayed(mPowerLongPress,
727 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Jeff Brown4d396052010-10-29 21:50:21 -0700728 }
729 }
730
731 private boolean interceptPowerKeyUp(boolean canceled) {
732 if (!mPowerKeyHandled) {
733 mHandler.removeCallbacks(mPowerLongPress);
734 return !canceled;
Jeff Brown4d396052010-10-29 21:50:21 -0700735 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700736 return false;
737 }
738
739 private void cancelPendingPowerKeyAction() {
740 if (!mPowerKeyHandled) {
741 mHandler.removeCallbacks(mPowerLongPress);
742 }
Jeff Brownff204712011-10-25 21:27:54 -0700743 if (mPowerKeyTriggered) {
744 mPendingPowerKeyUpCanceled = true;
745 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700746 }
747
748 private void interceptScreenshotChord() {
Christopher Tatee90585f2012-03-05 18:56:25 -0800749 if (mScreenshotChordEnabled
750 && mVolumeDownKeyTriggered && mPowerKeyTriggered && !mVolumeUpKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700751 final long now = SystemClock.uptimeMillis();
752 if (now <= mVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS
753 && now <= mPowerKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) {
754 mVolumeDownKeyConsumedByScreenshotChord = true;
755 cancelPendingPowerKeyAction();
756
Jeff Sharkey2991fa32012-12-05 18:06:43 -0800757 mHandler.postDelayed(mScreenshotRunnable, getScreenshotChordLongPressDelay());
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700758 }
759 }
760 }
761
Winson Chung1cea2f32012-10-08 20:42:01 -0700762 private long getScreenshotChordLongPressDelay() {
Jim Miller5ecd8112013-01-09 18:50:26 -0800763 if (mKeyguardDelegate.isShowing()) {
Winson Chung1cea2f32012-10-08 20:42:01 -0700764 // Double the time it takes to take a screenshot from the keyguard
765 return (long) (KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER *
Justin Kohfeabd2c2014-05-02 10:02:44 -0700766 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Winson Chung1cea2f32012-10-08 20:42:01 -0700767 }
Justin Kohfeabd2c2014-05-02 10:02:44 -0700768 return ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout();
Winson Chung1cea2f32012-10-08 20:42:01 -0700769 }
770
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700771 private void cancelPendingScreenshotChordAction() {
Jeff Sharkey2991fa32012-12-05 18:06:43 -0800772 mHandler.removeCallbacks(mScreenshotRunnable);
Jeff Brown4d396052010-10-29 21:50:21 -0700773 }
774
Jeff Brown6d8fd272014-05-20 21:24:38 -0700775 private void powerShortPress(long eventTime) {
776 if (mShortPressOnPowerBehavior < 0) {
777 mShortPressOnPowerBehavior = mContext.getResources().getInteger(
778 com.android.internal.R.integer.config_shortPressOnPowerBehavior);
779 }
780
781 switch (mShortPressOnPowerBehavior) {
782 case SHORT_PRESS_POWER_NOTHING:
783 break;
784 case SHORT_PRESS_POWER_GO_TO_SLEEP:
785 mPowerManager.goToSleep(eventTime,
786 PowerManager.GO_TO_SLEEP_REASON_USER, 0);
787 break;
788 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP:
789 mPowerManager.goToSleep(eventTime,
790 PowerManager.GO_TO_SLEEP_REASON_USER,
791 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
792 break;
793 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME:
794 mPowerManager.goToSleep(eventTime,
795 PowerManager.GO_TO_SLEEP_REASON_USER,
796 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
797 launchHomeFromHotKey();
798 break;
799 }
800 }
801
Jeff Brown4d396052010-10-29 21:50:21 -0700802 private final Runnable mPowerLongPress = new Runnable() {
Craig Mautnerf1b67412012-09-19 13:18:29 -0700803 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800804 public void run() {
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700805 // The context isn't read
806 if (mLongPressOnPowerBehavior < 0) {
Jeff Brown850c5b72012-10-01 15:17:22 -0700807 mLongPressOnPowerBehavior = mContext.getResources().getInteger(
808 com.android.internal.R.integer.config_longPressOnPowerBehavior);
Joe Onoratod208e702010-10-08 16:22:43 -0400809 }
Jeff Brown850c5b72012-10-01 15:17:22 -0700810 int resolvedBehavior = mLongPressOnPowerBehavior;
811 if (FactoryTest.isLongPressOnPowerOffEnabled()) {
812 resolvedBehavior = LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM;
813 }
814
815 switch (resolvedBehavior) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700816 case LONG_PRESS_POWER_NOTHING:
817 break;
818 case LONG_PRESS_POWER_GLOBAL_ACTIONS:
819 mPowerKeyHandled = true;
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -0700820 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
821 performAuditoryFeedbackForAccessibilityIfNeed();
822 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700823 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
824 showGlobalActionsDialog();
825 break;
826 case LONG_PRESS_POWER_SHUT_OFF:
Jeff Brown9a538ee2012-08-20 14:56:57 -0700827 case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM:
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700828 mPowerKeyHandled = true;
829 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
830 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
Jeff Brown850c5b72012-10-01 15:17:22 -0700831 mWindowManagerFuncs.shutdown(resolvedBehavior == LONG_PRESS_POWER_SHUT_OFF);
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700832 break;
833 }
834 }
835 };
836
Jeff Sharkey2991fa32012-12-05 18:06:43 -0800837 private final Runnable mScreenshotRunnable = new Runnable() {
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800838 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700839 public void run() {
840 takeScreenshot();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800841 }
842 };
843
844 void showGlobalActionsDialog() {
845 if (mGlobalActions == null) {
Jeff Brown7304c342012-05-11 18:42:42 -0700846 mGlobalActions = new GlobalActions(mContext, mWindowManagerFuncs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800847 }
Mike Lockwood3a74bd32011-08-12 13:55:22 -0700848 final boolean keyguardShowing = keyguardIsShowingTq();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800849 mGlobalActions.showDialog(keyguardShowing, isDeviceProvisioned());
850 if (keyguardShowing) {
851 // since it took two seconds of long press to bring this up,
852 // poke the wake lock so they have some time to see the dialog.
Jim Miller25190572013-02-28 17:36:24 -0800853 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800854 }
855 }
856
857 boolean isDeviceProvisioned() {
Jeff Brownbf6f6f92012-09-25 15:03:20 -0700858 return Settings.Global.getInt(
859 mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800860 }
861
Patrick Dubroyece94522011-02-23 18:35:01 -0800862 private void handleLongPressOnHome() {
Joe Onorato46b0d682010-11-22 17:37:27 -0800863 if (mLongPressOnHomeBehavior != LONG_PRESS_HOME_NOTHING) {
Jeff Browncaca8812013-05-09 13:34:33 -0700864 mHomeConsumed = true;
Joe Onorato46b0d682010-11-22 17:37:27 -0800865 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
Patrick Dubroyece94522011-02-23 18:35:01 -0800866
Jeff Browncaca8812013-05-09 13:34:33 -0700867 if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI) {
868 toggleRecentApps();
869 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_ASSIST) {
870 launchAssistAction();
Jim Millere6ad1a82010-08-20 19:25:39 -0700871 }
872 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800873 }
Patrick Dubroyece94522011-02-23 18:35:01 -0800874
Jeff Browncaca8812013-05-09 13:34:33 -0700875 private void handleDoubleTapOnHome() {
876 if (mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
877 mHomeConsumed = true;
878 toggleRecentApps();
879 }
880 }
881
882 private final Runnable mHomeDoubleTapTimeoutRunnable = new Runnable() {
883 @Override
884 public void run() {
885 if (mHomeDoubleTapPending) {
886 mHomeDoubleTapPending = false;
887 launchHomeFromHotKey();
888 }
889 }
890 };
891
Patrick Dubroyece94522011-02-23 18:35:01 -0800892 /**
Jeff Brown68b909d2011-12-07 16:36:01 -0800893 * Create (if necessary) and show or dismiss the recent apps dialog according
894 * according to the requested behavior.
Patrick Dubroyece94522011-02-23 18:35:01 -0800895 */
Jeff Brown68b909d2011-12-07 16:36:01 -0800896 void showOrHideRecentAppsDialog(final int behavior) {
Jeff Brownda3d5a92011-03-29 15:11:34 -0700897 mHandler.post(new Runnable() {
898 @Override
899 public void run() {
900 if (mRecentAppsDialog == null) {
Jeff Brown54875002011-04-06 15:33:01 -0700901 mRecentAppsDialog = new RecentApplicationsDialog(mContext);
Jeff Brownda3d5a92011-03-29 15:11:34 -0700902 }
Jeff Brown54875002011-04-06 15:33:01 -0700903 if (mRecentAppsDialog.isShowing()) {
Jeff Brown68b909d2011-12-07 16:36:01 -0800904 switch (behavior) {
905 case RECENT_APPS_BEHAVIOR_SHOW_OR_DISMISS:
Jeff Brown602ab322012-05-16 13:33:47 -0700906 case RECENT_APPS_BEHAVIOR_DISMISS:
Jeff Brown68b909d2011-12-07 16:36:01 -0800907 mRecentAppsDialog.dismiss();
908 break;
909 case RECENT_APPS_BEHAVIOR_DISMISS_AND_SWITCH:
910 mRecentAppsDialog.dismissAndSwitch();
911 break;
912 case RECENT_APPS_BEHAVIOR_EXIT_TOUCH_MODE_AND_SHOW:
913 default:
914 break;
Jeff Brown54875002011-04-06 15:33:01 -0700915 }
916 } else {
Jeff Brown68b909d2011-12-07 16:36:01 -0800917 switch (behavior) {
918 case RECENT_APPS_BEHAVIOR_SHOW_OR_DISMISS:
919 mRecentAppsDialog.show();
920 break;
921 case RECENT_APPS_BEHAVIOR_EXIT_TOUCH_MODE_AND_SHOW:
922 try {
923 mWindowManager.setInTouchMode(false);
924 } catch (RemoteException e) {
925 }
926 mRecentAppsDialog.show();
927 break;
Jeff Brown602ab322012-05-16 13:33:47 -0700928 case RECENT_APPS_BEHAVIOR_DISMISS:
Jeff Brown68b909d2011-12-07 16:36:01 -0800929 case RECENT_APPS_BEHAVIOR_DISMISS_AND_SWITCH:
930 default:
931 break;
932 }
Jeff Brown54875002011-04-06 15:33:01 -0700933 }
Jeff Brownda3d5a92011-03-29 15:11:34 -0700934 }
935 });
Patrick Dubroyece94522011-02-23 18:35:01 -0800936 }
Jeff Brownda3d5a92011-03-29 15:11:34 -0700937
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800938 /** {@inheritDoc} */
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800939 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800940 public void init(Context context, IWindowManager windowManager,
Jeff Brown96307042012-07-27 15:51:34 -0700941 WindowManagerFuncs windowManagerFuncs) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800942 mContext = context;
943 mWindowManager = windowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700944 mWindowManagerFuncs = windowManagerFuncs;
Craig Mautner228742d2014-05-31 15:13:37 -0700945 mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class);
946
Jeff Brown70825162012-03-28 17:27:48 -0700947 mHandler = new PolicyHandler();
Craig Mautnereee29c42013-01-17 14:44:34 -0800948 mOrientationListener = new MyOrientationListener(mContext, mHandler);
Jeff Brownc0347aa2011-09-23 17:26:09 -0700949 try {
950 mOrientationListener.setCurrentRotation(windowManager.getRotation());
951 } catch (RemoteException ex) { }
Christopher Tate5e08af02012-09-21 17:17:22 -0700952 mSettingsObserver = new SettingsObserver(mHandler);
953 mSettingsObserver.observe();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800954 mShortcutManager = new ShortcutManager(context, mHandler);
955 mShortcutManager.observe();
Daniel Sandler6396c722013-04-16 20:19:09 -0400956 mUiMode = context.getResources().getInteger(
957 com.android.internal.R.integer.config_defaultUiModeType);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800958 mHomeIntent = new Intent(Intent.ACTION_MAIN, null);
959 mHomeIntent.addCategory(Intent.CATEGORY_HOME);
960 mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
961 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700962 mCarDockIntent = new Intent(Intent.ACTION_MAIN, null);
963 mCarDockIntent.addCategory(Intent.CATEGORY_CAR_DOCK);
964 mCarDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
965 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
966 mDeskDockIntent = new Intent(Intent.ACTION_MAIN, null);
967 mDeskDockIntent.addCategory(Intent.CATEGORY_DESK_DOCK);
968 mDeskDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
969 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Jim Millere6ad1a82010-08-20 19:25:39 -0700970
Jeff Brown96307042012-07-27 15:51:34 -0700971 mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
972 mBroadcastWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800973 "PhoneWindowManager.mBroadcastWakeLock");
974 mEnableShiftMenuBugReports = "1".equals(SystemProperties.get("ro.debuggable"));
Jeff Brownbcdfc622014-03-06 19:13:04 -0800975 mSupportAutoRotation = mContext.getResources().getBoolean(
976 com.android.internal.R.bool.config_supportAutoRotation);
Dianne Hackborn2862fff2009-09-15 22:56:29 -0700977 mLidOpenRotation = readRotation(
Mike Lockwood2d1efbd2009-09-16 12:15:53 -0400978 com.android.internal.R.integer.config_lidOpenRotation);
979 mCarDockRotation = readRotation(
980 com.android.internal.R.integer.config_carDockRotation);
981 mDeskDockRotation = readRotation(
982 com.android.internal.R.integer.config_deskDockRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -0700983 mUndockedHdmiRotation = readRotation(
984 com.android.internal.R.integer.config_undockedHdmiRotation);
Mike Lockwoode9867d22009-09-20 01:59:02 -0400985 mCarDockEnablesAccelerometer = mContext.getResources().getBoolean(
986 com.android.internal.R.bool.config_carDockEnablesAccelerometer);
987 mDeskDockEnablesAccelerometer = mContext.getResources().getBoolean(
988 com.android.internal.R.bool.config_deskDockEnablesAccelerometer);
Dianne Hackborn2862fff2009-09-15 22:56:29 -0700989 mLidKeyboardAccessibility = mContext.getResources().getInteger(
990 com.android.internal.R.integer.config_lidKeyboardAccessibility);
991 mLidNavigationAccessibility = mContext.getResources().getInteger(
992 com.android.internal.R.integer.config_lidNavigationAccessibility);
Jeff Brownc458ce92012-04-30 14:58:40 -0700993 mLidControlsSleep = mContext.getResources().getBoolean(
994 com.android.internal.R.bool.config_lidControlsSleep);
Daniel Sandlerdd73ee42013-10-11 22:19:59 -0400995 mTranslucentDecorEnabled = mContext.getResources().getBoolean(
996 com.android.internal.R.bool.config_enableTranslucentDecor);
Jeff Brownf71343d2013-05-31 17:59:11 -0700997 readConfigurationDependentBehaviors();
Jeff Browncaca8812013-05-09 13:34:33 -0700998
Mike Lockwood1753f7f2009-08-24 14:49:07 -0700999 // register for dock events
Dianne Hackborn78968392010-03-04 20:47:56 -08001000 IntentFilter filter = new IntentFilter();
1001 filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE);
1002 filter.addAction(UiModeManager.ACTION_EXIT_CAR_MODE);
1003 filter.addAction(UiModeManager.ACTION_ENTER_DESK_MODE);
1004 filter.addAction(UiModeManager.ACTION_EXIT_DESK_MODE);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001005 filter.addAction(Intent.ACTION_DOCK_EVENT);
1006 Intent intent = context.registerReceiver(mDockReceiver, filter);
1007 if (intent != null) {
1008 // Retrieve current sticky dock event broadcast.
1009 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
1010 Intent.EXTRA_DOCK_STATE_UNDOCKED);
1011 }
Daniel Sandler7e37df52011-11-16 22:08:23 -08001012
Jeff Brown6aaf2952012-10-05 16:01:08 -07001013 // register for dream-related broadcasts
1014 filter = new IntentFilter();
1015 filter.addAction(Intent.ACTION_DREAMING_STARTED);
1016 filter.addAction(Intent.ACTION_DREAMING_STOPPED);
1017 context.registerReceiver(mDreamReceiver, filter);
1018
Christopher Tate5e08af02012-09-21 17:17:22 -07001019 // register for multiuser-relevant broadcasts
1020 filter = new IntentFilter(Intent.ACTION_USER_SWITCHED);
1021 context.registerReceiver(mMultiuserReceiver, filter);
1022
John Spurlock57306e62013-04-22 09:48:49 -04001023 // monitor for system gestures
Craig Mautner037aa8d2013-06-07 10:35:44 -07001024 mSystemGestures = new SystemGesturesPointerEventListener(context,
1025 new SystemGesturesPointerEventListener.Callbacks() {
John Spurlock57306e62013-04-22 09:48:49 -04001026 @Override
1027 public void onSwipeFromTop() {
John Spurlock04db1762013-05-13 12:46:41 -04001028 if (mStatusBar != null) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001029 requestTransientBars(mStatusBar);
John Spurlock04db1762013-05-13 12:46:41 -04001030 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04001031 }
1032 @Override
1033 public void onSwipeFromBottom() {
John Spurlock04db1762013-05-13 12:46:41 -04001034 if (mNavigationBar != null && mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001035 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001036 }
1037 }
1038 @Override
1039 public void onSwipeFromRight() {
John Spurlock04db1762013-05-13 12:46:41 -04001040 if (mNavigationBar != null && !mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001041 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001042 }
1043 }
1044 @Override
1045 public void onDebug() {
John Spurlockd67ec252013-09-05 11:31:54 -04001046 // no-op
John Spurlockad3e6cb2013-04-30 08:47:43 -04001047 }
1048 });
John Spurlockf1a36642013-10-12 17:50:42 -04001049 mImmersiveModeConfirmation = new ImmersiveModeConfirmation(mContext);
Craig Mautner037aa8d2013-06-07 10:35:44 -07001050 mWindowManagerFuncs.registerPointerEventListener(mSystemGestures);
John Spurlock32beb2c2013-03-11 10:16:47 -04001051
Jeff Brownc2346132012-04-13 01:55:38 -07001052 mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001053 mLongPressVibePattern = getLongIntArray(mContext.getResources(),
1054 com.android.internal.R.array.config_longPressVibePattern);
1055 mVirtualKeyVibePattern = getLongIntArray(mContext.getResources(),
1056 com.android.internal.R.array.config_virtualKeyVibePattern);
Amith Yamasanic33cb712010-02-10 15:21:49 -08001057 mKeyboardTapVibePattern = getLongIntArray(mContext.getResources(),
1058 com.android.internal.R.array.config_keyboardTapVibePattern);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001059 mSafeModeDisabledVibePattern = getLongIntArray(mContext.getResources(),
1060 com.android.internal.R.array.config_safeModeDisabledVibePattern);
1061 mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(),
1062 com.android.internal.R.array.config_safeModeEnabledVibePattern);
Daniel Sandler40427442010-07-16 11:44:52 -04001063
Christopher Tatee90585f2012-03-05 18:56:25 -08001064 mScreenshotChordEnabled = mContext.getResources().getBoolean(
1065 com.android.internal.R.bool.config_enableScreenshotChord);
1066
Justin Kohd378ad72013-04-01 12:18:26 -07001067 mGlobalKeyManager = new GlobalKeyManager(mContext);
1068
Joe Onoratoea495d42011-04-06 11:41:11 -07001069 // Controls rotation and the like.
1070 initializeHdmiState();
Dianne Hackborn40011092011-09-22 13:37:48 -07001071
1072 // Match current screen state.
1073 if (mPowerManager.isScreenOn()) {
Jeff Brown140ffc72014-05-01 15:18:00 -07001074 wakingUp(null);
Dianne Hackborn40011092011-09-22 13:37:48 -07001075 } else {
Jeff Brown140ffc72014-05-01 15:18:00 -07001076 goingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
Dianne Hackborn40011092011-09-22 13:37:48 -07001077 }
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001078 }
1079
Jeff Brownf71343d2013-05-31 17:59:11 -07001080 /**
1081 * Read values from config.xml that may be overridden depending on
1082 * the configuration of the device.
1083 * eg. Disable long press on home goes to recents on sw600dp.
1084 */
1085 private void readConfigurationDependentBehaviors() {
1086 mLongPressOnHomeBehavior = mContext.getResources().getInteger(
1087 com.android.internal.R.integer.config_longPressOnHomeBehavior);
1088 if (mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING ||
1089 mLongPressOnHomeBehavior > LONG_PRESS_HOME_ASSIST) {
1090 mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1091 }
1092
1093 mDoubleTapOnHomeBehavior = mContext.getResources().getInteger(
1094 com.android.internal.R.integer.config_doubleTapOnHomeBehavior);
1095 if (mDoubleTapOnHomeBehavior < DOUBLE_TAP_HOME_NOTHING ||
1096 mDoubleTapOnHomeBehavior > DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1097 mDoubleTapOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1098 }
1099 }
1100
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001101 @Override
Dianne Hackborndde331c2012-08-03 14:01:57 -07001102 public void setInitialDisplaySize(Display display, int width, int height, int density) {
Jeff Brownef981a42013-08-07 14:13:37 -07001103 // This method might be called before the policy has been fully initialized
1104 // or for other displays we don't care about.
1105 if (mContext == null || display.getDisplayId() != Display.DEFAULT_DISPLAY) {
1106 return;
Dianne Hackbornc652de82013-02-15 16:32:56 -08001107 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001108 mDisplay = display;
1109
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001110 final Resources res = mContext.getResources();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001111 int shortSize, longSize;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001112 if (width > height) {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001113 shortSize = height;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001114 longSize = width;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001115 mLandscapeRotation = Surface.ROTATION_0;
1116 mSeascapeRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001117 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001118 mPortraitRotation = Surface.ROTATION_90;
1119 mUpsideDownRotation = Surface.ROTATION_270;
1120 } else {
1121 mPortraitRotation = Surface.ROTATION_270;
1122 mUpsideDownRotation = Surface.ROTATION_90;
1123 }
1124 } else {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001125 shortSize = width;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001126 longSize = height;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001127 mPortraitRotation = Surface.ROTATION_0;
1128 mUpsideDownRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001129 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001130 mLandscapeRotation = Surface.ROTATION_270;
1131 mSeascapeRotation = Surface.ROTATION_90;
1132 } else {
1133 mLandscapeRotation = Surface.ROTATION_90;
1134 mSeascapeRotation = Surface.ROTATION_270;
1135 }
1136 }
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001137
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001138 mStatusBarHeight =
1139 res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001140
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001141 // Height of the navigation bar when presented horizontally at bottom
1142 mNavigationBarHeightForRotation[mPortraitRotation] =
1143 mNavigationBarHeightForRotation[mUpsideDownRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001144 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_height);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001145 mNavigationBarHeightForRotation[mLandscapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001146 mNavigationBarHeightForRotation[mSeascapeRotation] = res.getDimensionPixelSize(
1147 com.android.internal.R.dimen.navigation_bar_height_landscape);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001148
1149 // Width of the navigation bar when presented vertically along one side
1150 mNavigationBarWidthForRotation[mPortraitRotation] =
1151 mNavigationBarWidthForRotation[mUpsideDownRotation] =
1152 mNavigationBarWidthForRotation[mLandscapeRotation] =
1153 mNavigationBarWidthForRotation[mSeascapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001154 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_width);
Daniel Sandler4a066c52012-04-20 14:49:13 -04001155
1156 // SystemUI (status bar) layout policy
Dianne Hackborndde331c2012-08-03 14:01:57 -07001157 int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / density;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001158 int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / density;
Daniel Sandler4a066c52012-04-20 14:49:13 -04001159
Craig Mautnerd4ec33242013-07-22 10:37:43 -07001160 // Allow the navigation bar to move on small devices (phones).
1161 mNavigationBarCanMove = shortSizeDp < 600;
Daniel Sandler36412a72011-08-04 09:35:13 -04001162
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001163 mHasNavigationBar = res.getBoolean(com.android.internal.R.bool.config_showNavigationBar);
John Spurlock80f00c12013-06-13 11:10:51 -04001164 // Allow a system property to override this. Used by the emulator.
1165 // See also hasNavigationBar().
1166 String navBarOverride = SystemProperties.get("qemu.hw.mainkeys");
1167 if ("1".equals(navBarOverride)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001168 mHasNavigationBar = false;
John Spurlock80f00c12013-06-13 11:10:51 -04001169 } else if ("0".equals(navBarOverride)) {
1170 mHasNavigationBar = true;
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04001171 }
1172
Jeff Brown27f1d672012-10-17 18:32:34 -07001173 // For demo purposes, allow the rotation of the HDMI display to be controlled.
1174 // By default, HDMI locks rotation to landscape.
Erik Gilling9a41ef82011-09-26 19:21:03 -07001175 if ("portrait".equals(SystemProperties.get("persist.demo.hdmirotation"))) {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001176 mDemoHdmiRotation = mPortraitRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001177 } else {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001178 mDemoHdmiRotation = mLandscapeRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001179 }
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001180 mDemoHdmiRotationLock = SystemProperties.getBoolean("persist.demo.hdmirotationlock", false);
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001181
1182 // Only force the default orientation if the screen is xlarge, at least 960dp x 720dp, per
1183 // http://developer.android.com/guide/practices/screens_support.html#range
1184 mForceDefaultOrientation = longSizeDp >= 960 && shortSizeDp >= 720 &&
1185 res.getBoolean(com.android.internal.R.bool.config_forceDefaultOrientation) &&
1186 // For debug purposes the next line turns this feature off with:
1187 // $ adb shell setprop config.override_forced_orient true
1188 // $ adb shell wm size reset
1189 !"true".equals(SystemProperties.get("config.override_forced_orient"));
1190 }
1191
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001192 /**
1193 * @return whether the navigation bar can be hidden, e.g. the device has a
1194 * navigation bar and touch exploration is not enabled
1195 */
1196 private boolean canHideNavigationBar() {
1197 return mHasNavigationBar && !mTouchExplorationEnabled;
1198 }
1199
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001200 @Override
1201 public boolean isDefaultOrientationForced() {
1202 return mForceDefaultOrientation;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001203 }
1204
Dianne Hackbornc652de82013-02-15 16:32:56 -08001205 @Override
1206 public void setDisplayOverscan(Display display, int left, int top, int right, int bottom) {
1207 if (display.getDisplayId() == Display.DEFAULT_DISPLAY) {
1208 mOverscanLeft = left;
1209 mOverscanTop = top;
1210 mOverscanRight = right;
1211 mOverscanBottom = bottom;
1212 }
1213 }
1214
Dianne Hackbornc777e072010-02-12 13:07:59 -08001215 public void updateSettings() {
1216 ContentResolver resolver = mContext.getContentResolver();
1217 boolean updateRotation = false;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001218 synchronized (mLock) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001219 mEndcallBehavior = Settings.System.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001220 Settings.System.END_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001221 Settings.System.END_BUTTON_BEHAVIOR_DEFAULT,
1222 UserHandle.USER_CURRENT);
1223 mIncallPowerBehavior = Settings.Secure.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001224 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001225 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT,
1226 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001227
Jeff Brown207673cd2012-06-05 17:47:11 -07001228 // Configure rotation lock.
Christopher Tate5e08af02012-09-21 17:17:22 -07001229 int userRotation = Settings.System.getIntForUser(resolver,
1230 Settings.System.USER_ROTATION, Surface.ROTATION_0,
1231 UserHandle.USER_CURRENT);
Jeff Brown207673cd2012-06-05 17:47:11 -07001232 if (mUserRotation != userRotation) {
1233 mUserRotation = userRotation;
1234 updateRotation = true;
1235 }
Christopher Tate5e08af02012-09-21 17:17:22 -07001236 int userRotationMode = Settings.System.getIntForUser(resolver,
1237 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
Jeff Brown207673cd2012-06-05 17:47:11 -07001238 WindowManagerPolicy.USER_ROTATION_FREE :
1239 WindowManagerPolicy.USER_ROTATION_LOCKED;
1240 if (mUserRotationMode != userRotationMode) {
1241 mUserRotationMode = userRotationMode;
1242 updateRotation = true;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001243 updateOrientationListenerLp();
1244 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001245
Dianne Hackbornc777e072010-02-12 13:07:59 -08001246 if (mSystemReady) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001247 int pointerLocation = Settings.System.getIntForUser(resolver,
1248 Settings.System.POINTER_LOCATION, 0, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001249 if (mPointerLocationMode != pointerLocation) {
1250 mPointerLocationMode = pointerLocation;
Jeff Brown70825162012-03-28 17:27:48 -07001251 mHandler.sendEmptyMessage(pointerLocation != 0 ?
1252 MSG_ENABLE_POINTER_LOCATION : MSG_DISABLE_POINTER_LOCATION);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001253 }
1254 }
1255 // use screen off timeout setting as the timeout for the lockscreen
Christopher Tate5e08af02012-09-21 17:17:22 -07001256 mLockScreenTimeout = Settings.System.getIntForUser(resolver,
1257 Settings.System.SCREEN_OFF_TIMEOUT, 0, UserHandle.USER_CURRENT);
1258 String imId = Settings.Secure.getStringForUser(resolver,
1259 Settings.Secure.DEFAULT_INPUT_METHOD, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001260 boolean hasSoftInput = imId != null && imId.length() > 0;
1261 if (mHasSoftInput != hasSoftInput) {
1262 mHasSoftInput = hasSoftInput;
1263 updateRotation = true;
1264 }
John Spurlockf1a36642013-10-12 17:50:42 -04001265 if (mImmersiveModeConfirmation != null) {
1266 mImmersiveModeConfirmation.loadSetting();
John Spurlockd67ec252013-09-05 11:31:54 -04001267 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001268 }
1269 if (updateRotation) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07001270 updateRotation(true);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001271 }
Jeff Brown70825162012-03-28 17:27:48 -07001272 }
1273
1274 private void enablePointerLocation() {
1275 if (mPointerLocationView == null) {
1276 mPointerLocationView = new PointerLocationView(mContext);
1277 mPointerLocationView.setPrintCoords(false);
1278
Dianne Hackbornc777e072010-02-12 13:07:59 -08001279 WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
1280 WindowManager.LayoutParams.MATCH_PARENT,
1281 WindowManager.LayoutParams.MATCH_PARENT);
Jeff Brown3b2b3542010-10-15 00:54:27 -07001282 lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001283 lp.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN
1284 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
1285 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1286 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
Jeff Brown90fc9052012-10-01 14:44:24 -07001287 if (ActivityManager.isHighEndGfx()) {
1288 lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
1289 lp.privateFlags |=
1290 WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED;
1291 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001292 lp.format = PixelFormat.TRANSLUCENT;
1293 lp.setTitle("PointerLocation");
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001294 WindowManager wm = (WindowManager)
Dianne Hackbornc777e072010-02-12 13:07:59 -08001295 mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Browncc4f7db2011-08-30 20:34:48 -07001296 lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL;
Jeff Brown70825162012-03-28 17:27:48 -07001297 wm.addView(mPointerLocationView, lp);
1298
Craig Mautner037aa8d2013-06-07 10:35:44 -07001299 mPointerLocationPointerEventListener = new PointerLocationPointerEventListener();
1300 mWindowManagerFuncs.registerPointerEventListener(mPointerLocationPointerEventListener);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001301 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001302 }
Jeff Brown70825162012-03-28 17:27:48 -07001303
1304 private void disablePointerLocation() {
Craig Mautner037aa8d2013-06-07 10:35:44 -07001305 if (mPointerLocationPointerEventListener != null) {
1306 mWindowManagerFuncs.unregisterPointerEventListener(
1307 mPointerLocationPointerEventListener);
1308 mPointerLocationPointerEventListener = null;
Jeff Brown70825162012-03-28 17:27:48 -07001309 }
1310
1311 if (mPointerLocationView != null) {
1312 WindowManager wm = (WindowManager)
1313 mContext.getSystemService(Context.WINDOW_SERVICE);
1314 wm.removeView(mPointerLocationView);
1315 mPointerLocationView = null;
1316 }
1317 }
1318
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001319 private int readRotation(int resID) {
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001320 try {
1321 int rotation = mContext.getResources().getInteger(resID);
1322 switch (rotation) {
1323 case 0:
1324 return Surface.ROTATION_0;
1325 case 90:
1326 return Surface.ROTATION_90;
1327 case 180:
1328 return Surface.ROTATION_180;
1329 case 270:
1330 return Surface.ROTATION_270;
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001331 }
1332 } catch (Resources.NotFoundException e) {
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001333 // fall through
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001334 }
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001335 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001336 }
1337
1338 /** {@inheritDoc} */
Craig Mautner88400d32012-09-30 12:35:45 -07001339 @Override
Dianne Hackbornc2293022013-02-06 23:14:49 -08001340 public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001341 int type = attrs.type;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001342
1343 outAppOp[0] = AppOpsManager.OP_NONE;
1344
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001345 if (type < WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW
1346 || type > WindowManager.LayoutParams.LAST_SYSTEM_WINDOW) {
Jeff Brown98365d72012-08-19 20:30:52 -07001347 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001348 }
1349 String permission = null;
1350 switch (type) {
1351 case TYPE_TOAST:
1352 // XXX right now the app process has complete control over
1353 // this... should introduce a token to let the system
1354 // monitor/control what they are doing.
1355 break;
Daniel Sandler7d276c32012-01-30 14:33:52 -05001356 case TYPE_DREAM:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001357 case TYPE_INPUT_METHOD:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001358 case TYPE_WALLPAPER:
keunyounga446bf02013-06-21 19:07:57 -07001359 case TYPE_PRIVATE_PRESENTATION:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001360 // The window manager will check these.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001361 break;
1362 case TYPE_PHONE:
1363 case TYPE_PRIORITY_PHONE:
1364 case TYPE_SYSTEM_ALERT:
1365 case TYPE_SYSTEM_ERROR:
1366 case TYPE_SYSTEM_OVERLAY:
1367 permission = android.Manifest.permission.SYSTEM_ALERT_WINDOW;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001368 outAppOp[0] = AppOpsManager.OP_SYSTEM_ALERT_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001369 break;
1370 default:
1371 permission = android.Manifest.permission.INTERNAL_SYSTEM_WINDOW;
1372 }
1373 if (permission != null) {
1374 if (mContext.checkCallingOrSelfPermission(permission)
1375 != PackageManager.PERMISSION_GRANTED) {
Jeff Brown98365d72012-08-19 20:30:52 -07001376 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001377 }
1378 }
Jeff Brown98365d72012-08-19 20:30:52 -07001379 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001380 }
Craig Mautner88400d32012-09-30 12:35:45 -07001381
1382 @Override
1383 public boolean checkShowToOwnerOnly(WindowManager.LayoutParams attrs) {
1384
1385 // If this switch statement is modified, modify the comment in the declarations of
1386 // the type in {@link WindowManager.LayoutParams} as well.
1387 switch (attrs.type) {
1388 default:
1389 // These are the windows that by default are shown only to the user that created
1390 // them. If this needs to be overridden, set
1391 // {@link WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS} in
1392 // {@link WindowManager.LayoutParams}. Note that permission
1393 // {@link android.Manifest.permission.INTERNAL_SYSTEM_WINDOW} is required as well.
1394 if ((attrs.privateFlags & PRIVATE_FLAG_SHOW_FOR_ALL_USERS) == 0) {
1395 return true;
1396 }
1397 break;
1398
1399 // These are the windows that by default are shown to all users. However, to
1400 // protect against spoofing, check permissions below.
1401 case TYPE_APPLICATION_STARTING:
1402 case TYPE_BOOT_PROGRESS:
1403 case TYPE_DISPLAY_OVERLAY:
1404 case TYPE_HIDDEN_NAV_CONSUMER:
1405 case TYPE_KEYGUARD:
Jim Miller5ecd8112013-01-09 18:50:26 -08001406 case TYPE_KEYGUARD_SCRIM:
Craig Mautner88400d32012-09-30 12:35:45 -07001407 case TYPE_KEYGUARD_DIALOG:
1408 case TYPE_MAGNIFICATION_OVERLAY:
1409 case TYPE_NAVIGATION_BAR:
1410 case TYPE_NAVIGATION_BAR_PANEL:
1411 case TYPE_PHONE:
1412 case TYPE_POINTER:
1413 case TYPE_PRIORITY_PHONE:
1414 case TYPE_RECENTS_OVERLAY:
1415 case TYPE_SEARCH_BAR:
1416 case TYPE_STATUS_BAR:
1417 case TYPE_STATUS_BAR_PANEL:
1418 case TYPE_STATUS_BAR_SUB_PANEL:
1419 case TYPE_SYSTEM_DIALOG:
1420 case TYPE_UNIVERSE_BACKGROUND:
1421 case TYPE_VOLUME_OVERLAY:
keunyounga446bf02013-06-21 19:07:57 -07001422 case TYPE_PRIVATE_PRESENTATION:
Craig Mautner88400d32012-09-30 12:35:45 -07001423 break;
1424 }
1425
1426 // Check if third party app has set window to system window type.
1427 return mContext.checkCallingOrSelfPermission(
1428 android.Manifest.permission.INTERNAL_SYSTEM_WINDOW)
1429 != PackageManager.PERMISSION_GRANTED;
1430 }
1431
Craig Mautner967212c2013-04-13 21:10:58 -07001432 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001433 public void adjustWindowParamsLw(WindowManager.LayoutParams attrs) {
1434 switch (attrs.type) {
1435 case TYPE_SYSTEM_OVERLAY:
Jeff Brown3b2b3542010-10-15 00:54:27 -07001436 case TYPE_SECURE_SYSTEM_OVERLAY:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001437 // These types of windows can't receive input events.
1438 attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1439 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001440 attrs.flags &= ~WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001441 break;
1442 }
1443 }
1444
1445 void readLidState() {
Jeff Brown2e7760e2012-04-11 15:14:55 -07001446 mLidState = mWindowManagerFuncs.getLidState();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001447 }
1448
Jeff Browndaa37532012-05-01 15:54:03 -07001449 private boolean isHidden(int accessibilityMode) {
1450 switch (accessibilityMode) {
1451 case 1:
1452 return mLidState == LID_CLOSED;
1453 case 2:
1454 return mLidState == LID_OPEN;
1455 default:
1456 return false;
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001457 }
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001458 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001459
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001460 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07001461 @Override
Jeff Browndaa37532012-05-01 15:54:03 -07001462 public void adjustConfigurationLw(Configuration config, int keyboardPresence,
1463 int navigationPresence) {
1464 mHaveBuiltInKeyboard = (keyboardPresence & PRESENCE_INTERNAL) != 0;
1465
Jeff Brownf71343d2013-05-31 17:59:11 -07001466 readConfigurationDependentBehaviors();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001467 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07001468 applyLidSwitchState();
Jeff Brownd04a88c2011-01-16 14:05:47 -08001469
Jeff Browndaa37532012-05-01 15:54:03 -07001470 if (config.keyboard == Configuration.KEYBOARD_NOKEYS
1471 || (keyboardPresence == PRESENCE_INTERNAL
1472 && isHidden(mLidKeyboardAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001473 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_YES;
Jeff Browndaa37532012-05-01 15:54:03 -07001474 if (!mHasSoftInput) {
1475 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_YES;
1476 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001477 }
1478
Jeff Browndaa37532012-05-01 15:54:03 -07001479 if (config.navigation == Configuration.NAVIGATION_NONAV
1480 || (navigationPresence == PRESENCE_INTERNAL
1481 && isHidden(mLidNavigationAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001482 config.navigationHidden = Configuration.NAVIGATIONHIDDEN_YES;
Jeff Brownd04a88c2011-01-16 14:05:47 -08001483 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001484 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001485
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001486 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07001487 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001488 public int windowTypeToLayerLw(int type) {
1489 if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001490 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001491 }
1492 switch (type) {
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001493 case TYPE_UNIVERSE_BACKGROUND:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001494 return 1;
keunyounga446bf02013-06-21 19:07:57 -07001495 case TYPE_PRIVATE_PRESENTATION:
1496 return 2;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001497 case TYPE_WALLPAPER:
1498 // wallpaper is at the bottom, though the window manager may move it.
1499 return 2;
1500 case TYPE_PHONE:
1501 return 3;
1502 case TYPE_SEARCH_BAR:
1503 return 4;
Craig Mautner88400d32012-09-30 12:35:45 -07001504 case TYPE_RECENTS_OVERLAY:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001505 case TYPE_SYSTEM_DIALOG:
1506 return 5;
1507 case TYPE_TOAST:
1508 // toasts and the plugged-in battery thing
1509 return 6;
1510 case TYPE_PRIORITY_PHONE:
1511 // SIM errors and unlock. Not sure if this really should be in a high layer.
1512 return 7;
1513 case TYPE_DREAM:
1514 // used for Dreams (screensavers with TYPE_DREAM windows)
1515 return 8;
1516 case TYPE_SYSTEM_ALERT:
1517 // like the ANR / app crashed dialogs
1518 return 9;
1519 case TYPE_INPUT_METHOD:
1520 // on-screen keyboards and other such input method user interfaces go here.
1521 return 10;
1522 case TYPE_INPUT_METHOD_DIALOG:
1523 // on-screen keyboards and other such input method user interfaces go here.
1524 return 11;
Jim Miller5ecd8112013-01-09 18:50:26 -08001525 case TYPE_KEYGUARD_SCRIM:
1526 // the safety window that shows behind keyguard while keyguard is starting
1527 return 12;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001528 case TYPE_KEYGUARD:
1529 // the keyguard; nothing on top of these can take focus, since they are
1530 // responsible for power management when displayed.
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001531 return 13;
Jim Miller5ecd8112013-01-09 18:50:26 -08001532 case TYPE_KEYGUARD_DIALOG:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001533 return 14;
Jim Miller5ecd8112013-01-09 18:50:26 -08001534 case TYPE_STATUS_BAR_SUB_PANEL:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001535 return 15;
Jim Miller5ecd8112013-01-09 18:50:26 -08001536 case TYPE_STATUS_BAR:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001537 return 16;
Jim Miller5ecd8112013-01-09 18:50:26 -08001538 case TYPE_STATUS_BAR_PANEL:
1539 return 17;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001540 case TYPE_VOLUME_OVERLAY:
1541 // the on-screen volume indicator and controller shown when the user
1542 // changes the device volume
Jim Miller5ecd8112013-01-09 18:50:26 -08001543 return 18;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001544 case TYPE_SYSTEM_OVERLAY:
1545 // the on-screen volume indicator and controller shown when the user
1546 // changes the device volume
Jim Miller5ecd8112013-01-09 18:50:26 -08001547 return 19;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001548 case TYPE_NAVIGATION_BAR:
1549 // the navigation bar, if available, shows atop most things
Jim Miller5ecd8112013-01-09 18:50:26 -08001550 return 20;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001551 case TYPE_NAVIGATION_BAR_PANEL:
1552 // some panels (e.g. search) need to show on top of the navigation bar
Jim Miller5ecd8112013-01-09 18:50:26 -08001553 return 21;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001554 case TYPE_SYSTEM_ERROR:
1555 // system-level error dialogs
Jim Miller5ecd8112013-01-09 18:50:26 -08001556 return 22;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001557 case TYPE_MAGNIFICATION_OVERLAY:
1558 // used to highlight the magnified portion of a display
Jim Miller5ecd8112013-01-09 18:50:26 -08001559 return 23;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001560 case TYPE_DISPLAY_OVERLAY:
1561 // used to simulate secondary display devices
Jim Miller5ecd8112013-01-09 18:50:26 -08001562 return 24;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001563 case TYPE_DRAG:
1564 // the drag layer: input for drag-and-drop is associated with this window,
1565 // which sits above all other focusable windows
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001566 return 25;
Jim Miller5ecd8112013-01-09 18:50:26 -08001567 case TYPE_SECURE_SYSTEM_OVERLAY:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001568 return 26;
Jim Miller5ecd8112013-01-09 18:50:26 -08001569 case TYPE_BOOT_PROGRESS:
1570 return 27;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001571 case TYPE_POINTER:
1572 // the (mouse) pointer layer
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001573 return 28;
Jim Miller5ecd8112013-01-09 18:50:26 -08001574 case TYPE_HIDDEN_NAV_CONSUMER:
1575 return 29;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001576 }
1577 Log.e(TAG, "Unknown window type: " + type);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001578 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001579 }
1580
1581 /** {@inheritDoc} */
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001582 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001583 public int subWindowTypeToLayerLw(int type) {
1584 switch (type) {
1585 case TYPE_APPLICATION_PANEL:
1586 case TYPE_APPLICATION_ATTACHED_DIALOG:
1587 return APPLICATION_PANEL_SUBLAYER;
1588 case TYPE_APPLICATION_MEDIA:
1589 return APPLICATION_MEDIA_SUBLAYER;
Dianne Hackborn5cb8d792009-05-21 17:34:15 -07001590 case TYPE_APPLICATION_MEDIA_OVERLAY:
1591 return APPLICATION_MEDIA_OVERLAY_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001592 case TYPE_APPLICATION_SUB_PANEL:
1593 return APPLICATION_SUB_PANEL_SUBLAYER;
1594 }
1595 Log.e(TAG, "Unknown sub-window type: " + type);
1596 return 0;
1597 }
1598
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001599 @Override
Dianne Hackbornabe0da02009-09-18 01:55:39 -07001600 public int getMaxWallpaperLayer() {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001601 return windowTypeToLayerLw(TYPE_STATUS_BAR);
Dianne Hackbornabe0da02009-09-18 01:55:39 -07001602 }
1603
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001604 @Override
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001605 public int getAboveUniverseLayer() {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001606 return windowTypeToLayerLw(TYPE_SYSTEM_ERROR);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001607 }
1608
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001609 public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07001610 if (mHasNavigationBar) {
1611 // For a basic navigation bar, when we are in landscape mode we place
1612 // the navigation bar to the side.
Daniel Sandler4a066c52012-04-20 14:49:13 -04001613 if (mNavigationBarCanMove && fullWidth > fullHeight) {
1614 return fullWidth - mNavigationBarWidthForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07001615 }
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001616 }
1617 return fullWidth;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001618 }
1619
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001620 public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07001621 if (mHasNavigationBar) {
1622 // For a basic navigation bar, when we are in portrait mode we place
1623 // the navigation bar to the bottom.
Daniel Sandler4a066c52012-04-20 14:49:13 -04001624 if (!mNavigationBarCanMove || fullWidth < fullHeight) {
1625 return fullHeight - mNavigationBarHeightForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07001626 }
1627 }
1628 return fullHeight;
Dianne Hackborn69cb8752011-05-19 18:13:32 -07001629 }
1630
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001631 public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation) {
1632 return getNonDecorDisplayWidth(fullWidth, fullHeight, rotation);
Dianne Hackborn69cb8752011-05-19 18:13:32 -07001633 }
1634
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001635 public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation) {
John Spurlock80f00c12013-06-13 11:10:51 -04001636 // There is a separate status bar at the top of the display. We don't count that as part
1637 // of the fixed decor, since it can hide; however, for purposes of configurations,
Dianne Hackborn077ee852012-04-09 16:27:07 -07001638 // we do want to exclude it since applications can't generally use that part
1639 // of the screen.
John Spurlock80f00c12013-06-13 11:10:51 -04001640 return getNonDecorDisplayHeight(fullWidth, fullHeight, rotation) - mStatusBarHeight;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001641 }
1642
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001643 @Override
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07001644 public boolean doesForceHide(WindowState win, WindowManager.LayoutParams attrs) {
1645 return attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD;
1646 }
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001647
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001648 @Override
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07001649 public boolean canBeForceHidden(WindowState win, WindowManager.LayoutParams attrs) {
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001650 switch (attrs.type) {
1651 case TYPE_STATUS_BAR:
1652 case TYPE_NAVIGATION_BAR:
1653 case TYPE_WALLPAPER:
1654 case TYPE_DREAM:
1655 case TYPE_UNIVERSE_BACKGROUND:
1656 case TYPE_KEYGUARD:
Jim Miller5ecd8112013-01-09 18:50:26 -08001657 case TYPE_KEYGUARD_SCRIM:
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001658 return false;
1659 default:
1660 return true;
1661 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07001662 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001663
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001664 /** {@inheritDoc} */
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001665 @Override
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07001666 public View addStartingWindow(IBinder appToken, String packageName, int theme,
1667 CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes,
Adam Powell04fe6eb2013-05-31 14:39:48 -07001668 int icon, int logo, int windowFlags) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001669 if (!SHOW_STARTING_ANIMATIONS) {
1670 return null;
1671 }
1672 if (packageName == null) {
1673 return null;
1674 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001675
Mathias Jeppssond1443e92012-08-24 15:25:32 +02001676 WindowManager wm = null;
1677 View view = null;
1678
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001679 try {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001680 Context context = mContext;
Craig Mautner6fbda632012-07-03 09:26:39 -07001681 if (DEBUG_STARTING_WINDOW) Slog.d(TAG, "addStartingWindow " + packageName
1682 + ": nonLocalizedLabel=" + nonLocalizedLabel + " theme="
1683 + Integer.toHexString(theme));
Dianne Hackborn247fe742011-01-08 17:25:57 -08001684 if (theme != context.getThemeResId() || labelRes != 0) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001685 try {
1686 context = context.createPackageContext(packageName, 0);
Dianne Hackborn247fe742011-01-08 17:25:57 -08001687 context.setTheme(theme);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001688 } catch (PackageManager.NameNotFoundException e) {
1689 // Ignore
1690 }
1691 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001692
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001693 Window win = PolicyManager.makeNewWindow(context);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001694 final TypedArray ta = win.getWindowStyle();
1695 if (ta.getBoolean(
1696 com.android.internal.R.styleable.Window_windowDisablePreview, false)
1697 || ta.getBoolean(
1698 com.android.internal.R.styleable.Window_windowShowWallpaper,false)) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001699 return null;
1700 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001701
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001702 Resources r = context.getResources();
1703 win.setTitle(r.getText(labelRes, nonLocalizedLabel));
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001704
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001705 win.setType(
1706 WindowManager.LayoutParams.TYPE_APPLICATION_STARTING);
1707 // Force the window flags: this is a fake window, so it is not really
1708 // touchable or focusable by the user. We also add in the ALT_FOCUSABLE_IM
1709 // flag because we do know that the next window will take input
1710 // focus, so we want to get the IME window up on top of us right away.
1711 win.setFlags(
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08001712 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001713 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
1714 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
1715 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08001716 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001717 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
1718 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
1719 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001720
Adam Powell04fe6eb2013-05-31 14:39:48 -07001721 win.setDefaultIcon(icon);
1722 win.setDefaultLogo(logo);
1723
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001724 win.setLayout(WindowManager.LayoutParams.MATCH_PARENT,
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07001725 WindowManager.LayoutParams.MATCH_PARENT);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001726
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001727 final WindowManager.LayoutParams params = win.getAttributes();
1728 params.token = appToken;
1729 params.packageName = packageName;
1730 params.windowAnimations = win.getWindowStyle().getResourceId(
1731 com.android.internal.R.styleable.Window_windowAnimationStyle, 0);
Dianne Hackborn5d927c22011-09-02 12:22:18 -07001732 params.privateFlags |=
1733 WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED;
Craig Mautner88400d32012-09-30 12:35:45 -07001734 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
Adam Lesinski95c42972013-10-02 10:13:27 -07001735
1736 if (!compatInfo.supportsScreen()) {
1737 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
1738 }
1739
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001740 params.setTitle("Starting " + packageName);
1741
Mathias Jeppssond1443e92012-08-24 15:25:32 +02001742 wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
1743 view = win.getDecorView();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001744
1745 if (win.isFloating()) {
1746 // Whoops, there is no way to display an animation/preview
1747 // of such a thing! After all that work... let's skip it.
1748 // (Note that we must do this here because it is in
1749 // getDecorView() where the theme is evaluated... maybe
1750 // we should peek the floating attribute from the theme
1751 // earlier.)
1752 return null;
1753 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001754
Craig Mautner6fbda632012-07-03 09:26:39 -07001755 if (DEBUG_STARTING_WINDOW) Slog.d(
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001756 TAG, "Adding starting window for " + packageName
1757 + " / " + appToken + ": "
1758 + (view.getParent() != null ? view : null));
1759
1760 wm.addView(view, params);
1761
1762 // Only return the view if it was successfully added to the
1763 // window manager... which we can tell by it having a parent.
1764 return view.getParent() != null ? view : null;
Jeff Brown98365d72012-08-19 20:30:52 -07001765 } catch (WindowManager.BadTokenException e) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001766 // ignore
Craig Mautner42bf39e2014-02-21 16:46:22 -08001767 Log.w(TAG, appToken + " already running, starting window not displayed. " +
1768 e.getMessage());
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001769 } catch (RuntimeException e) {
1770 // don't crash if something else bad happens, for example a
1771 // failure loading resources because we are loading from an app
1772 // on external storage that has been unmounted.
1773 Log.w(TAG, appToken + " failed creating starting window", e);
Mathias Jeppssond1443e92012-08-24 15:25:32 +02001774 } finally {
1775 if (view != null && view.getParent() == null) {
1776 Log.w(TAG, "view not successfully added to wm, removing view");
1777 wm.removeViewImmediate(view);
1778 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001779 }
1780
1781 return null;
1782 }
1783
1784 /** {@inheritDoc} */
1785 public void removeStartingWindow(IBinder appToken, View window) {
Craig Mautner6fbda632012-07-03 09:26:39 -07001786 if (DEBUG_STARTING_WINDOW) {
1787 RuntimeException e = new RuntimeException("here");
1788 e.fillInStackTrace();
1789 Log.v(TAG, "Removing starting window for " + appToken + ": " + window, e);
1790 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001791
1792 if (window != null) {
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001793 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001794 wm.removeView(window);
1795 }
1796 }
1797
1798 /**
1799 * Preflight adding a window to the system.
1800 *
1801 * Currently enforces that three window types are singletons:
1802 * <ul>
1803 * <li>STATUS_BAR_TYPE</li>
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001804 * <li>KEYGUARD_TYPE</li>
1805 * </ul>
1806 *
1807 * @param win The window to be added
1808 * @param attrs Information about the window to be added
1809 *
Jeff Brown98365d72012-08-19 20:30:52 -07001810 * @return If ok, WindowManagerImpl.ADD_OKAY. If too many singletons,
1811 * WindowManagerImpl.ADD_MULTIPLE_SINGLETON
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001812 */
1813 public int prepareAddWindowLw(WindowState win, WindowManager.LayoutParams attrs) {
1814 switch (attrs.type) {
1815 case TYPE_STATUS_BAR:
Joe Onorato8bc6c512010-06-04 16:21:12 -04001816 mContext.enforceCallingOrSelfPermission(
1817 android.Manifest.permission.STATUS_BAR_SERVICE,
1818 "PhoneWindowManager");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001819 if (mStatusBar != null) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001820 if (mStatusBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07001821 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001822 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001823 }
1824 mStatusBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04001825 mStatusBarController.setWindow(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001826 break;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04001827 case TYPE_NAVIGATION_BAR:
1828 mContext.enforceCallingOrSelfPermission(
1829 android.Manifest.permission.STATUS_BAR_SERVICE,
1830 "PhoneWindowManager");
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001831 if (mNavigationBar != null) {
1832 if (mNavigationBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07001833 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001834 }
1835 }
Daniel Sandler8956dbb2011-04-22 07:55:02 -04001836 mNavigationBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04001837 mNavigationBarController.setWindow(win);
Craig Mautnereda67292013-04-28 13:50:14 -07001838 if (DEBUG_LAYOUT) Slog.i(TAG, "NAVIGATION BAR: " + mNavigationBar);
Daniel Sandler8956dbb2011-04-22 07:55:02 -04001839 break;
Jim Millere898ac52012-04-06 17:10:57 -07001840 case TYPE_NAVIGATION_BAR_PANEL:
1841 mContext.enforceCallingOrSelfPermission(
1842 android.Manifest.permission.STATUS_BAR_SERVICE,
1843 "PhoneWindowManager");
1844 break;
Dianne Hackborn08743722009-12-21 12:16:51 -08001845 case TYPE_STATUS_BAR_PANEL:
Joe Onorato8bc6c512010-06-04 16:21:12 -04001846 mContext.enforceCallingOrSelfPermission(
1847 android.Manifest.permission.STATUS_BAR_SERVICE,
1848 "PhoneWindowManager");
Dianne Hackborn08743722009-12-21 12:16:51 -08001849 break;
Joe Onorato29fc2c92010-11-24 10:26:50 -08001850 case TYPE_STATUS_BAR_SUB_PANEL:
1851 mContext.enforceCallingOrSelfPermission(
1852 android.Manifest.permission.STATUS_BAR_SERVICE,
1853 "PhoneWindowManager");
Joe Onorato29fc2c92010-11-24 10:26:50 -08001854 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001855 case TYPE_KEYGUARD:
1856 if (mKeyguard != null) {
Jeff Brown98365d72012-08-19 20:30:52 -07001857 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001858 }
1859 mKeyguard = win;
1860 break;
Jim Miller5ecd8112013-01-09 18:50:26 -08001861 case TYPE_KEYGUARD_SCRIM:
Jim Miller25190572013-02-28 17:36:24 -08001862 if (mKeyguardScrim != null) {
1863 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
1864 }
Jim Miller5ecd8112013-01-09 18:50:26 -08001865 mKeyguardScrim = win;
1866 break;
1867
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001868 }
Jeff Brown98365d72012-08-19 20:30:52 -07001869 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001870 }
1871
1872 /** {@inheritDoc} */
1873 public void removeWindowLw(WindowState win) {
1874 if (mStatusBar == win) {
1875 mStatusBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04001876 mStatusBarController.setWindow(null);
Daniel Sandler8956dbb2011-04-22 07:55:02 -04001877 } else if (mKeyguard == win) {
Jim Miller5ecd8112013-01-09 18:50:26 -08001878 Log.v(TAG, "Removing keyguard window (Did it crash?)");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001879 mKeyguard = null;
Jim Millerc0b676d2013-03-22 16:11:08 -07001880 mKeyguardDelegate.showScrim();
Jim Miller5ecd8112013-01-09 18:50:26 -08001881 } else if (mKeyguardScrim == win) {
1882 Log.v(TAG, "Removing keyguard scrim");
1883 mKeyguardScrim = null;
1884 } if (mNavigationBar == win) {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04001885 mNavigationBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04001886 mNavigationBarController.setWindow(null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001887 }
1888 }
1889
1890 static final boolean PRINT_ANIM = false;
1891
1892 /** {@inheritDoc} */
Craig Mautner4b71aa12012-12-27 17:20:01 -08001893 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001894 public int selectAnimationLw(WindowState win, int transit) {
1895 if (PRINT_ANIM) Log.i(TAG, "selectAnimation in " + win
1896 + ": transit=" + transit);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001897 if (win == mStatusBar) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08001898 if (transit == TRANSIT_EXIT
1899 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001900 return R.anim.dock_top_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001901 } else if (transit == TRANSIT_ENTER
1902 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001903 return R.anim.dock_top_enter;
1904 }
1905 } else if (win == mNavigationBar) {
1906 // This can be on either the bottom or the right.
1907 if (mNavigationBarOnBottom) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08001908 if (transit == TRANSIT_EXIT
1909 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001910 return R.anim.dock_bottom_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001911 } else if (transit == TRANSIT_ENTER
1912 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001913 return R.anim.dock_bottom_enter;
1914 }
1915 } else {
Craig Mautner4b71aa12012-12-27 17:20:01 -08001916 if (transit == TRANSIT_EXIT
1917 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001918 return R.anim.dock_right_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001919 } else if (transit == TRANSIT_ENTER
1920 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001921 return R.anim.dock_right_enter;
1922 }
1923 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08001924 }
1925
1926 if (transit == TRANSIT_PREVIEW_DONE) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001927 if (win.hasAppShownWindows()) {
1928 if (PRINT_ANIM) Log.i(TAG, "**** STARTING EXIT");
1929 return com.android.internal.R.anim.app_starting_exit;
1930 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07001931 } else if (win.getAttrs().type == TYPE_DREAM && mDreamingLockscreen
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001932 && transit == TRANSIT_ENTER) {
1933 // Special case: we are animating in a dream, while the keyguard
1934 // is shown. We don't want an animation on the dream, because
1935 // we need it shown immediately with the keyguard animating away
1936 // to reveal it.
1937 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001938 }
1939
1940 return 0;
1941 }
1942
Craig Mautner3c174372013-02-21 17:54:37 -08001943 @Override
1944 public void selectRotationAnimationLw(int anim[]) {
1945 if (PRINT_ANIM) Slog.i(TAG, "selectRotationAnimation mTopFullscreen="
1946 + mTopFullscreenOpaqueWindowState + " rotationAnimation="
1947 + (mTopFullscreenOpaqueWindowState == null ?
1948 "0" : mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation));
1949 if (mTopFullscreenOpaqueWindowState != null && mTopIsFullscreen) {
1950 switch (mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation) {
1951 case ROTATION_ANIMATION_CROSSFADE:
1952 anim[0] = R.anim.rotation_animation_xfade_exit;
1953 anim[1] = R.anim.rotation_animation_enter;
1954 break;
1955 case ROTATION_ANIMATION_JUMPCUT:
1956 anim[0] = R.anim.rotation_animation_jump_exit;
1957 anim[1] = R.anim.rotation_animation_enter;
1958 break;
1959 case ROTATION_ANIMATION_ROTATE:
1960 default:
1961 anim[0] = anim[1] = 0;
1962 break;
1963 }
1964 } else {
1965 anim[0] = anim[1] = 0;
1966 }
1967 }
1968
1969 @Override
1970 public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId,
1971 boolean forceDefault) {
1972 switch (exitAnimId) {
1973 case R.anim.rotation_animation_xfade_exit:
1974 case R.anim.rotation_animation_jump_exit:
1975 // These are the only cases that matter.
1976 if (forceDefault) {
1977 return false;
1978 }
1979 int anim[] = new int[2];
1980 selectRotationAnimationLw(anim);
1981 return (exitAnimId == anim[0] && enterAnimId == anim[1]);
1982 default:
1983 return true;
1984 }
1985 }
1986
1987 @Override
Dianne Hackborn0c2acff2012-04-12 15:17:07 -07001988 public Animation createForceHideEnterAnimation(boolean onWallpaper) {
1989 return AnimationUtils.loadAnimation(mContext, onWallpaper
1990 ? com.android.internal.R.anim.lock_screen_wallpaper_behind_enter
1991 : com.android.internal.R.anim.lock_screen_behind_enter);
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07001992 }
John Spurlockc8b46ca2013-04-08 12:59:26 -04001993
1994 private static void awakenDreams() {
1995 IDreamManager dreamManager = getDreamManager();
1996 if (dreamManager != null) {
1997 try {
1998 dreamManager.awaken();
1999 } catch (RemoteException e) {
2000 // fine, stay asleep then
2001 }
2002 }
2003 }
2004
2005 static IDreamManager getDreamManager() {
2006 return IDreamManager.Stub.asInterface(
2007 ServiceManager.checkService(DreamService.DREAM_SERVICE));
2008 }
2009
Jeff Brown4d396052010-10-29 21:50:21 -07002010 static ITelephony getTelephonyService() {
Mike Lockwoodf5f4ec92011-11-08 14:05:31 -08002011 return ITelephony.Stub.asInterface(
Jeff Brown4d396052010-10-29 21:50:21 -07002012 ServiceManager.checkService(Context.TELEPHONY_SERVICE));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002013 }
2014
Jeff Brown4d396052010-10-29 21:50:21 -07002015 static IAudioService getAudioService() {
2016 IAudioService audioService = IAudioService.Stub.asInterface(
2017 ServiceManager.checkService(Context.AUDIO_SERVICE));
2018 if (audioService == null) {
2019 Log.w(TAG, "Unable to find IAudioService interface.");
2020 }
2021 return audioService;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002022 }
2023
2024 boolean keyguardOn() {
2025 return keyguardIsShowingTq() || inKeyguardRestrictedKeyInputMode();
2026 }
2027
2028 private static final int[] WINDOW_TYPES_WHERE_HOME_DOESNT_WORK = {
2029 WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
2030 WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
2031 };
2032
2033 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002034 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002035 public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002036 final boolean keyguardOn = keyguardOn();
Jeff Brown1f245102010-11-18 20:53:46 -08002037 final int keyCode = event.getKeyCode();
2038 final int repeatCount = event.getRepeatCount();
2039 final int metaState = event.getMetaState();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002040 final int flags = event.getFlags();
Jeff Brown1f245102010-11-18 20:53:46 -08002041 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
2042 final boolean canceled = event.isCanceled();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002043
Jeff Brown40013652012-05-16 21:22:36 -07002044 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002045 Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount="
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002046 + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed
2047 + " canceled=" + canceled);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002048 }
2049
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002050 // If we think we might have a volume down & power key chord on the way
2051 // but we're not sure, then tell the dispatcher to wait a little while and
2052 // try again later before dispatching.
Christopher Tatee90585f2012-03-05 18:56:25 -08002053 if (mScreenshotChordEnabled && (flags & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002054 if (mVolumeDownKeyTriggered && !mPowerKeyTriggered) {
2055 final long now = SystemClock.uptimeMillis();
2056 final long timeoutTime = mVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS;
2057 if (now < timeoutTime) {
2058 return timeoutTime - now;
2059 }
2060 }
2061 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
2062 && mVolumeDownKeyConsumedByScreenshotChord) {
2063 if (!down) {
2064 mVolumeDownKeyConsumedByScreenshotChord = false;
2065 }
2066 return -1;
2067 }
2068 }
2069
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002070 // First we always handle the home key here, so applications
2071 // can never break it, although if keyguard is on, we do let
2072 // it handle it, because that gives us the correct 5 second
2073 // timeout.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002074 if (keyCode == KeyEvent.KEYCODE_HOME) {
Michael Jurka7f2668c2012-03-27 07:49:52 -07002075
Jeff Brown49ed71d2010-12-06 17:13:33 -08002076 // If we have released the home key, and didn't do anything else
2077 // while it was pressed, then it is time to go home!
Michael Jurka7f2668c2012-03-27 07:49:52 -07002078 if (!down) {
Jeff Browncaca8812013-05-09 13:34:33 -07002079 cancelPreloadRecentApps();
2080
Jeff Brown49ed71d2010-12-06 17:13:33 -08002081 mHomePressed = false;
Jeff Browncaca8812013-05-09 13:34:33 -07002082 if (mHomeConsumed) {
2083 mHomeConsumed = false;
Michael Jurka7f2668c2012-03-27 07:49:52 -07002084 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002085 }
Jeff Browncaca8812013-05-09 13:34:33 -07002086
2087 if (canceled) {
2088 Log.i(TAG, "Ignoring HOME; event canceled.");
2089 return -1;
2090 }
2091
2092 // If an incoming call is ringing, HOME is totally disabled.
2093 // (The user is already on the InCallScreen at this point,
2094 // and his ONLY options are to answer or reject the call.)
2095 try {
2096 ITelephony telephonyService = getTelephonyService();
2097 if (telephonyService != null && telephonyService.isRinging()) {
2098 Log.i(TAG, "Ignoring HOME; there's a ringing incoming call.");
2099 return -1;
2100 }
2101 } catch (RemoteException ex) {
2102 Log.w(TAG, "RemoteException from getPhoneInterface()", ex);
2103 }
2104
2105 // Delay handling home if a double-tap is possible.
2106 if (mDoubleTapOnHomeBehavior != DOUBLE_TAP_HOME_NOTHING) {
2107 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); // just in case
2108 mHomeDoubleTapPending = true;
2109 mHandler.postDelayed(mHomeDoubleTapTimeoutRunnable,
2110 ViewConfiguration.getDoubleTapTimeout());
2111 return -1;
2112 }
2113
2114 // Go home!
2115 launchHomeFromHotKey();
2116 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002117 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002118
2119 // If a system window has focus, then it doesn't make sense
2120 // right now to interact with applications.
2121 WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null;
2122 if (attrs != null) {
2123 final int type = attrs.type;
2124 if (type == WindowManager.LayoutParams.TYPE_KEYGUARD
Jim Miller5ecd8112013-01-09 18:50:26 -08002125 || type == WindowManager.LayoutParams.TYPE_KEYGUARD_SCRIM
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002126 || type == WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG) {
2127 // the "app" is keyguard, so give it the key
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002128 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002129 }
2130 final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length;
2131 for (int i=0; i<typeCount; i++) {
2132 if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) {
2133 // don't do anything, but also don't pass it to the app
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002134 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002135 }
2136 }
2137 }
Jeff Browncaca8812013-05-09 13:34:33 -07002138
2139 // Remember that home is pressed and handle special actions.
2140 if (repeatCount == 0) {
2141 mHomePressed = true;
2142 if (mHomeDoubleTapPending) {
2143 mHomeDoubleTapPending = false;
2144 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable);
2145 handleDoubleTapOnHome();
2146 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI
2147 || mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
2148 preloadRecentApps();
Michael Jurka7f2668c2012-03-27 07:49:52 -07002149 }
Jeff Browncaca8812013-05-09 13:34:33 -07002150 } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) {
2151 if (!keyguardOn) {
2152 handleLongPressOnHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002153 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002154 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002155 return -1;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002156 } else if (keyCode == KeyEvent.KEYCODE_MENU) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002157 // Hijack modified menu keys for debugging features
2158 final int chordBug = KeyEvent.META_SHIFT_ON;
2159
2160 if (down && repeatCount == 0) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002161 if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002162 Intent intent = new Intent(Intent.ACTION_BUG_REPORT);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002163 mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT,
2164 null, null, null, 0, null, null);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002165 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002166 } else if (SHOW_PROCESSES_ON_ALT_MENU &&
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002167 (metaState & KeyEvent.META_ALT_ON) == KeyEvent.META_ALT_ON) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002168 Intent service = new Intent();
2169 service.setClassName(mContext, "com.android.server.LoadAverageService");
2170 ContentResolver res = mContext.getContentResolver();
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002171 boolean shown = Settings.Global.getInt(
2172 res, Settings.Global.SHOW_PROCESSES, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002173 if (!shown) {
2174 mContext.startService(service);
2175 } else {
2176 mContext.stopService(service);
2177 }
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002178 Settings.Global.putInt(
2179 res, Settings.Global.SHOW_PROCESSES, shown ? 0 : 1);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002180 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002181 }
2182 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002183 } else if (keyCode == KeyEvent.KEYCODE_SEARCH) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002184 if (down) {
2185 if (repeatCount == 0) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002186 mSearchKeyShortcutPending = true;
2187 mConsumeSearchKeyUp = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002188 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002189 } else {
2190 mSearchKeyShortcutPending = false;
2191 if (mConsumeSearchKeyUp) {
2192 mConsumeSearchKeyUp = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002193 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002194 }
2195 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002196 return 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002197 } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) {
Michael Wrightc9ebea72013-01-16 19:25:02 -08002198 if (!keyguardOn) {
Jeff Browncaca8812013-05-09 13:34:33 -07002199 if (down && repeatCount == 0) {
2200 preloadRecentApps();
2201 } else if (!down) {
2202 toggleRecentApps();
Michael Wrightc9ebea72013-01-16 19:25:02 -08002203 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002204 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002205 return -1;
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002206 } else if (keyCode == KeyEvent.KEYCODE_ASSIST) {
2207 if (down) {
2208 if (repeatCount == 0) {
2209 mAssistKeyLongPressed = false;
2210 } else if (repeatCount == 1) {
2211 mAssistKeyLongPressed = true;
2212 if (!keyguardOn) {
2213 launchAssistLongPressAction();
2214 }
2215 }
2216 } else {
2217 if (mAssistKeyLongPressed) {
2218 mAssistKeyLongPressed = false;
2219 } else {
2220 if (!keyguardOn) {
2221 launchAssistAction();
2222 }
2223 }
2224 }
2225 return -1;
Jeff Sharkey2991fa32012-12-05 18:06:43 -08002226 } else if (keyCode == KeyEvent.KEYCODE_SYSRQ) {
2227 if (down && repeatCount == 0) {
2228 mHandler.post(mScreenshotRunnable);
2229 }
2230 return -1;
Michael Wrightb854e242013-02-05 17:54:02 -08002231 } else if (keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP
2232 || keyCode == KeyEvent.KEYCODE_BRIGHTNESS_DOWN) {
2233 if (down) {
2234 int direction = keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP ? 1 : -1;
2235
2236 // Disable autobrightness if it's on
2237 int auto = Settings.System.getIntForUser(
2238 mContext.getContentResolver(),
2239 Settings.System.SCREEN_BRIGHTNESS_MODE,
2240 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2241 UserHandle.USER_CURRENT_OR_SELF);
2242 if (auto != 0) {
2243 Settings.System.putIntForUser(mContext.getContentResolver(),
2244 Settings.System.SCREEN_BRIGHTNESS_MODE,
2245 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2246 UserHandle.USER_CURRENT_OR_SELF);
2247 }
2248
2249 int min = mPowerManager.getMinimumScreenBrightnessSetting();
2250 int max = mPowerManager.getMaximumScreenBrightnessSetting();
2251 int step = (max - min + BRIGHTNESS_STEPS - 1) / BRIGHTNESS_STEPS * direction;
2252 int brightness = Settings.System.getIntForUser(mContext.getContentResolver(),
2253 Settings.System.SCREEN_BRIGHTNESS,
2254 mPowerManager.getDefaultScreenBrightnessSetting(),
2255 UserHandle.USER_CURRENT_OR_SELF);
2256 brightness += step;
2257 // Make sure we don't go beyond the limits.
2258 brightness = Math.min(max, brightness);
2259 brightness = Math.max(min, brightness);
2260
2261 Settings.System.putIntForUser(mContext.getContentResolver(),
2262 Settings.System.SCREEN_BRIGHTNESS, brightness,
2263 UserHandle.USER_CURRENT_OR_SELF);
2264 Intent intent = new Intent(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG);
2265 mContext.sendBroadcastAsUser(intent, UserHandle.CURRENT_OR_SELF);
2266 }
2267 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002268 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002269
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002270 // Shortcuts are invoked through Search+key, so intercept those here
Jeff Browncaab4d02010-12-09 22:13:41 -08002271 // Any printing key that is chorded with Search should be consumed
2272 // even if no shortcut was invoked. This prevents text from being
2273 // inadvertently inserted when using a keyboard that has built-in macro
2274 // shortcut keys (that emit Search+x) and some of them are not registered.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002275 if (mSearchKeyShortcutPending) {
Jeff Browncaab4d02010-12-09 22:13:41 -08002276 final KeyCharacterMap kcm = event.getKeyCharacterMap();
2277 if (kcm.isPrintingKey(keyCode)) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002278 mConsumeSearchKeyUp = true;
2279 mSearchKeyShortcutPending = false;
Jeff Browncaab4d02010-12-09 22:13:41 -08002280 if (down && repeatCount == 0 && !keyguardOn) {
2281 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState);
2282 if (shortcutIntent != null) {
2283 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002284 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002285 mContext.startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002286 } catch (ActivityNotFoundException ex) {
2287 Slog.w(TAG, "Dropping shortcut key combination because "
2288 + "the activity to which it is registered was not found: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002289 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode), ex);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002290 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002291 } else {
2292 Slog.i(TAG, "Dropping unregistered shortcut key combination: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002293 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002294 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002295 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002296 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002297 }
2298 }
2299
Jeff Brown68b909d2011-12-07 16:36:01 -08002300 // Invoke shortcuts using Meta.
Jeff Brown602ab322012-05-16 13:33:47 -07002301 if (down && repeatCount == 0 && !keyguardOn
Jeff Brown68b909d2011-12-07 16:36:01 -08002302 && (metaState & KeyEvent.META_META_ON) != 0) {
2303 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brown602ab322012-05-16 13:33:47 -07002304 if (kcm.isPrintingKey(keyCode)) {
2305 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode,
2306 metaState & ~(KeyEvent.META_META_ON
2307 | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON));
2308 if (shortcutIntent != null) {
2309 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2310 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002311 mContext.startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brown602ab322012-05-16 13:33:47 -07002312 } catch (ActivityNotFoundException ex) {
2313 Slog.w(TAG, "Dropping shortcut key combination because "
2314 + "the activity to which it is registered was not found: "
2315 + "META+" + KeyEvent.keyCodeToString(keyCode), ex);
2316 }
2317 return -1;
Jeff Brown68b909d2011-12-07 16:36:01 -08002318 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002319 }
2320 }
2321
Jeff Brown6651a632011-11-28 12:59:11 -08002322 // Handle application launch keys.
Jeff Brown602ab322012-05-16 13:33:47 -07002323 if (down && repeatCount == 0 && !keyguardOn) {
Jeff Brown6651a632011-11-28 12:59:11 -08002324 String category = sApplicationLaunchKeyCategories.get(keyCode);
2325 if (category != null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -08002326 Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category);
Jeff Brown6651a632011-11-28 12:59:11 -08002327 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2328 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002329 mContext.startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brown6651a632011-11-28 12:59:11 -08002330 } catch (ActivityNotFoundException ex) {
2331 Slog.w(TAG, "Dropping application launch key because "
2332 + "the activity to which it is registered was not found: "
2333 + "keyCode=" + keyCode + ", category=" + category, ex);
2334 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002335 return -1;
Jeff Brown6651a632011-11-28 12:59:11 -08002336 }
2337 }
2338
Jeff Brown68b909d2011-12-07 16:36:01 -08002339 // Display task switcher for ALT-TAB or Meta-TAB.
2340 if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_TAB) {
Jeff Brown602ab322012-05-16 13:33:47 -07002341 if (mRecentAppsDialogHeldModifiers == 0 && !keyguardOn) {
Jeff Brown68b909d2011-12-07 16:36:01 -08002342 final int shiftlessModifiers = event.getModifiers() & ~KeyEvent.META_SHIFT_MASK;
2343 if (KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_ALT_ON)
2344 || KeyEvent.metaStateHasModifiers(
2345 shiftlessModifiers, KeyEvent.META_META_ON)) {
2346 mRecentAppsDialogHeldModifiers = shiftlessModifiers;
2347 showOrHideRecentAppsDialog(RECENT_APPS_BEHAVIOR_EXIT_TOUCH_MODE_AND_SHOW);
2348 return -1;
2349 }
2350 }
2351 } else if (!down && mRecentAppsDialogHeldModifiers != 0
2352 && (metaState & mRecentAppsDialogHeldModifiers) == 0) {
2353 mRecentAppsDialogHeldModifiers = 0;
Jeff Brown602ab322012-05-16 13:33:47 -07002354 showOrHideRecentAppsDialog(keyguardOn ? RECENT_APPS_BEHAVIOR_DISMISS :
2355 RECENT_APPS_BEHAVIOR_DISMISS_AND_SWITCH);
Jeff Brown68b909d2011-12-07 16:36:01 -08002356 }
2357
Jeff Browncf39bdf2012-05-18 14:41:19 -07002358 // Handle keyboard language switching.
2359 if (down && repeatCount == 0
2360 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2361 || (keyCode == KeyEvent.KEYCODE_SPACE
2362 && (metaState & KeyEvent.META_CTRL_MASK) != 0))) {
2363 int direction = (metaState & KeyEvent.META_SHIFT_MASK) != 0 ? -1 : 1;
2364 mWindowManagerFuncs.switchKeyboardLayout(event.getDeviceId(), direction);
2365 return -1;
2366 }
2367 if (mLanguageSwitchKeyPressed && !down
2368 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2369 || keyCode == KeyEvent.KEYCODE_SPACE)) {
2370 mLanguageSwitchKeyPressed = false;
2371 return -1;
2372 }
2373
Justin Kohd378ad72013-04-01 12:18:26 -07002374 if (mGlobalKeyManager.handleGlobalKey(mContext, keyCode, event)) {
2375 return -1;
2376 }
2377
Jeff Brown68b909d2011-12-07 16:36:01 -08002378 // Let the application handle the key.
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002379 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002380 }
2381
Jeff Brown3915bb82010-11-05 15:02:16 -07002382 /** {@inheritDoc} */
2383 @Override
Jeff Brown49ed71d2010-12-06 17:13:33 -08002384 public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown54875002011-04-06 15:33:01 -07002385 // Note: This method is only called if the initial down was unhandled.
Jeff Brown40013652012-05-16 21:22:36 -07002386 if (DEBUG_INPUT) {
Jeff Brown1f245102010-11-18 20:53:46 -08002387 Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction()
2388 + ", flags=" + event.getFlags()
2389 + ", keyCode=" + event.getKeyCode()
2390 + ", scanCode=" + event.getScanCode()
2391 + ", metaState=" + event.getMetaState()
2392 + ", repeatCount=" + event.getRepeatCount()
2393 + ", policyFlags=" + policyFlags);
Jeff Brown3915bb82010-11-05 15:02:16 -07002394 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002395
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002396 KeyEvent fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002397 if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
2398 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002399 final int keyCode = event.getKeyCode();
2400 final int metaState = event.getMetaState();
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002401 final boolean initialDown = event.getAction() == KeyEvent.ACTION_DOWN
2402 && event.getRepeatCount() == 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002403
Jeff Brown54875002011-04-06 15:33:01 -07002404 // Check for fallback actions specified by the key character map.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002405 final FallbackAction fallbackAction;
2406 if (initialDown) {
2407 fallbackAction = kcm.getFallbackAction(keyCode, metaState);
2408 } else {
2409 fallbackAction = mFallbackActions.get(keyCode);
2410 }
2411
2412 if (fallbackAction != null) {
Jeff Brown40013652012-05-16 21:22:36 -07002413 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002414 Slog.d(TAG, "Fallback: keyCode=" + fallbackAction.keyCode
2415 + " metaState=" + Integer.toHexString(fallbackAction.metaState));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002416 }
2417
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002418 final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK;
2419 fallbackEvent = KeyEvent.obtain(
Jeff Brown49ed71d2010-12-06 17:13:33 -08002420 event.getDownTime(), event.getEventTime(),
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002421 event.getAction(), fallbackAction.keyCode,
2422 event.getRepeatCount(), fallbackAction.metaState,
Jeff Brown49ed71d2010-12-06 17:13:33 -08002423 event.getDeviceId(), event.getScanCode(),
2424 flags, event.getSource(), null);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002425
2426 if (!interceptFallback(win, fallbackEvent, policyFlags)) {
2427 fallbackEvent.recycle();
2428 fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002429 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002430
2431 if (initialDown) {
2432 mFallbackActions.put(keyCode, fallbackAction);
2433 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2434 mFallbackActions.remove(keyCode);
2435 fallbackAction.recycle();
2436 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002437 }
2438 }
2439
Jeff Brown40013652012-05-16 21:22:36 -07002440 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002441 if (fallbackEvent == null) {
2442 Slog.d(TAG, "No fallback.");
2443 } else {
2444 Slog.d(TAG, "Performing fallback: " + fallbackEvent);
2445 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002446 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002447 return fallbackEvent;
Jeff Brown3915bb82010-11-05 15:02:16 -07002448 }
2449
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002450 private boolean interceptFallback(WindowState win, KeyEvent fallbackEvent, int policyFlags) {
Jeff Brown037c33e2014-04-09 00:31:55 -07002451 int actions = interceptKeyBeforeQueueing(fallbackEvent, policyFlags);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002452 if ((actions & ACTION_PASS_TO_USER) != 0) {
2453 long delayMillis = interceptKeyBeforeDispatching(
2454 win, fallbackEvent, policyFlags);
2455 if (delayMillis == 0) {
2456 return true;
2457 }
2458 }
2459 return false;
Jeff Brown6f2fba42011-02-19 01:08:02 -08002460 }
2461
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002462 private void launchAssistLongPressAction() {
2463 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
2464 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
2465
2466 // launch the search activity
2467 Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS);
2468 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2469 try {
Jim Miller45308b12012-06-18 19:23:39 -07002470 // TODO: This only stops the factory-installed search manager.
2471 // Need to formalize an API to handle others
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002472 SearchManager searchManager = getSearchManager();
2473 if (searchManager != null) {
2474 searchManager.stopSearch();
2475 }
Michael Wright43e27f72013-04-10 14:06:48 -07002476 mContext.startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002477 } catch (ActivityNotFoundException e) {
2478 Slog.w(TAG, "No activity to handle assist long press action.", e);
2479 }
2480 }
2481
2482 private void launchAssistAction() {
2483 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
Amith Yamasanic1d07a42012-08-14 09:32:02 -07002484 Intent intent = ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE))
Dianne Hackbornf9c5e0f2013-01-23 14:39:13 -08002485 .getAssistIntent(mContext, true, UserHandle.USER_CURRENT);
Jim Miller45308b12012-06-18 19:23:39 -07002486 if (intent != null) {
2487 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
2488 | Intent.FLAG_ACTIVITY_SINGLE_TOP
2489 | Intent.FLAG_ACTIVITY_CLEAR_TOP);
2490 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002491 mContext.startActivityAsUser(intent, UserHandle.CURRENT);
Jim Miller45308b12012-06-18 19:23:39 -07002492 } catch (ActivityNotFoundException e) {
2493 Slog.w(TAG, "No activity to handle assist action.", e);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002494 }
2495 }
2496 }
2497
2498 private SearchManager getSearchManager() {
2499 if (mSearchManager == null) {
2500 mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
2501 }
2502 return mSearchManager;
2503 }
2504
Jeff Browncaca8812013-05-09 13:34:33 -07002505 private void preloadRecentApps() {
2506 mPreloadedRecentApps = true;
2507 try {
2508 IStatusBarService statusbar = getStatusBarService();
2509 if (statusbar != null) {
2510 statusbar.preloadRecentApps();
2511 }
2512 } catch (RemoteException e) {
2513 Slog.e(TAG, "RemoteException when preloading recent apps", e);
2514 // re-acquire status bar service next time it is needed.
2515 mStatusBarService = null;
2516 }
2517 }
2518
2519 private void cancelPreloadRecentApps() {
2520 if (mPreloadedRecentApps) {
2521 mPreloadedRecentApps = false;
2522 try {
2523 IStatusBarService statusbar = getStatusBarService();
2524 if (statusbar != null) {
2525 statusbar.cancelPreloadRecentApps();
2526 }
2527 } catch (RemoteException e) {
2528 Slog.e(TAG, "RemoteException when showing recent apps", e);
2529 // re-acquire status bar service next time it is needed.
2530 mStatusBarService = null;
2531 }
2532 }
2533 }
2534
2535 private void toggleRecentApps() {
2536 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
2537 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_RECENT_APPS);
2538 try {
2539 IStatusBarService statusbar = getStatusBarService();
2540 if (statusbar != null) {
2541 statusbar.toggleRecentApps();
2542 }
2543 } catch (RemoteException e) {
2544 Slog.e(TAG, "RemoteException when showing recent apps", e);
2545 // re-acquire status bar service next time it is needed.
2546 mStatusBarService = null;
2547 }
2548 }
2549
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002550 /**
2551 * A home key -> launch home action was detected. Take the appropriate action
2552 * given the situation with the keyguard.
2553 */
2554 void launchHomeFromHotKey() {
Jim Miller5ecd8112013-01-09 18:50:26 -08002555 if (mKeyguardDelegate != null && mKeyguardDelegate.isShowingAndNotHidden()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002556 // don't launch home if keyguard showing
Jim Miller5ecd8112013-01-09 18:50:26 -08002557 } else if (!mHideLockScreen && mKeyguardDelegate.isInputRestricted()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002558 // when in keyguard restricted mode, must first verify unlock
2559 // before launching home
Jim Miller5ecd8112013-01-09 18:50:26 -08002560 mKeyguardDelegate.verifyUnlock(new OnKeyguardExitResult() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002561 public void onKeyguardExitResult(boolean success) {
2562 if (success) {
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07002563 try {
2564 ActivityManagerNative.getDefault().stopAppSwitches();
2565 } catch (RemoteException e) {
2566 }
Joe Onoratof275f0c2009-11-24 16:11:13 -05002567 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07002568 startDockOrHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002569 }
2570 }
2571 });
2572 } else {
2573 // no keyguard stuff to worry about, just launch home!
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07002574 try {
2575 ActivityManagerNative.getDefault().stopAppSwitches();
2576 } catch (RemoteException e) {
2577 }
Joe Onoratof275f0c2009-11-24 16:11:13 -05002578 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07002579 startDockOrHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002580 }
2581 }
2582
John Spurlock04db1762013-05-13 12:46:41 -04002583 private final Runnable mClearHideNavigationFlag = new Runnable() {
2584 @Override
2585 public void run() {
2586 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
2587 // Clear flags.
2588 mForceClearedSystemUiFlags &=
2589 ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
2590 }
2591 mWindowManagerFuncs.reevaluateStatusBarVisibility();
Dianne Hackborne26ab702011-10-16 13:21:33 -07002592 }
2593 };
2594
2595 /**
2596 * Input handler used while nav bar is hidden. Captures any touch on the screen,
2597 * to determine when the nav bar should be shown and prevent applications from
2598 * receiving those touches.
2599 */
Jeff Brown32cbc38552011-12-01 14:01:49 -08002600 final class HideNavInputEventReceiver extends InputEventReceiver {
2601 public HideNavInputEventReceiver(InputChannel inputChannel, Looper looper) {
2602 super(inputChannel, looper);
2603 }
2604
Dianne Hackborndf89e652011-10-06 22:35:11 -07002605 @Override
Jeff Brown32cbc38552011-12-01 14:01:49 -08002606 public void onInputEvent(InputEvent event) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07002607 boolean handled = false;
2608 try {
Jeff Brown4952dfd2011-11-30 19:23:22 -08002609 if (event instanceof MotionEvent
2610 && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
2611 final MotionEvent motionEvent = (MotionEvent)event;
2612 if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07002613 // When the user taps down, we re-show the nav bar.
2614 boolean changed = false;
John Spurlock04db1762013-05-13 12:46:41 -04002615 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002616 // Any user activity always causes us to show the
2617 // navigation controls, if they had been hidden.
2618 // We also clear the low profile and only content
2619 // flags so that tapping on the screen will atomically
2620 // restore all currently hidden screen decorations.
2621 int newVal = mResettingSystemUiFlags |
2622 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
2623 View.SYSTEM_UI_FLAG_LOW_PROFILE |
2624 View.SYSTEM_UI_FLAG_FULLSCREEN;
Dianne Hackborne26ab702011-10-16 13:21:33 -07002625 if (mResettingSystemUiFlags != newVal) {
2626 mResettingSystemUiFlags = newVal;
Dianne Hackborndf89e652011-10-06 22:35:11 -07002627 changed = true;
2628 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07002629 // We don't allow the system's nav bar to be hidden
2630 // again for 1 second, to prevent applications from
2631 // spamming us and keeping it from being shown.
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002632 newVal = mForceClearedSystemUiFlags |
2633 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
Dianne Hackborne26ab702011-10-16 13:21:33 -07002634 if (mForceClearedSystemUiFlags != newVal) {
2635 mForceClearedSystemUiFlags = newVal;
2636 changed = true;
John Spurlock04db1762013-05-13 12:46:41 -04002637 mHandler.postDelayed(mClearHideNavigationFlag, 1000);
Dianne Hackborne26ab702011-10-16 13:21:33 -07002638 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07002639 }
2640 if (changed) {
2641 mWindowManagerFuncs.reevaluateStatusBarVisibility();
2642 }
2643 }
2644 }
2645 } finally {
Jeff Brown32cbc38552011-12-01 14:01:49 -08002646 finishInputEvent(event, handled);
Dianne Hackborndf89e652011-10-06 22:35:11 -07002647 }
2648 }
Jeff Brown32cbc38552011-12-01 14:01:49 -08002649 }
2650 final InputEventReceiver.Factory mHideNavInputEventReceiverFactory =
2651 new InputEventReceiver.Factory() {
2652 @Override
2653 public InputEventReceiver createInputEventReceiver(
2654 InputChannel inputChannel, Looper looper) {
2655 return new HideNavInputEventReceiver(inputChannel, looper);
2656 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07002657 };
2658
2659 @Override
2660 public int adjustSystemUiVisibilityLw(int visibility) {
John Spurlock5b9145b2013-08-20 15:13:47 -04002661 mStatusBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
2662 mNavigationBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
John Spurlock27735a42013-08-14 17:57:38 -04002663
Dianne Hackborndf89e652011-10-06 22:35:11 -07002664 // Reset any bits in mForceClearingStatusBarVisibility that
2665 // are now clear.
Dianne Hackborne26ab702011-10-16 13:21:33 -07002666 mResettingSystemUiFlags &= visibility;
Dianne Hackborndf89e652011-10-06 22:35:11 -07002667 // Clear any bits in the new visibility that are currently being
2668 // force cleared, before reporting it.
Dianne Hackborne26ab702011-10-16 13:21:33 -07002669 return visibility & ~mResettingSystemUiFlags
2670 & ~mForceClearedSystemUiFlags;
Dianne Hackborndf89e652011-10-06 22:35:11 -07002671 }
2672
Craig Mautner69b08182012-09-05 13:07:13 -07002673 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002674 public void getContentInsetHintLw(WindowManager.LayoutParams attrs, Rect contentInset) {
2675 final int fl = attrs.flags;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002676 final int systemUiVisibility = (attrs.systemUiVisibility|attrs.subtreeSystemUiVisibility);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002677
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002678 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002679 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002680 int availRight, availBottom;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07002681 if (canHideNavigationBar() &&
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002682 (systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002683 availRight = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
2684 availBottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
2685 } else {
2686 availRight = mRestrictedScreenLeft + mRestrictedScreenWidth;
2687 availBottom = mRestrictedScreenTop + mRestrictedScreenHeight;
2688 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002689 if ((systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
2690 if ((fl & FLAG_FULLSCREEN) != 0) {
2691 contentInset.set(mStableFullscreenLeft, mStableFullscreenTop,
2692 availRight - mStableFullscreenRight,
2693 availBottom - mStableFullscreenBottom);
2694 } else {
2695 contentInset.set(mStableLeft, mStableTop,
2696 availRight - mStableRight, availBottom - mStableBottom);
2697 }
Dianne Hackbornc652de82013-02-15 16:32:56 -08002698 } else if ((fl & FLAG_FULLSCREEN) != 0 || (fl & FLAG_LAYOUT_IN_OVERSCAN) != 0) {
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002699 contentInset.setEmpty();
2700 } else if ((systemUiVisibility & (View.SYSTEM_UI_FLAG_FULLSCREEN
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002701 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)) == 0) {
2702 contentInset.set(mCurLeft, mCurTop,
2703 availRight - mCurRight, availBottom - mCurBottom);
2704 } else {
2705 contentInset.set(mCurLeft, mCurTop,
2706 availRight - mCurRight, availBottom - mCurBottom);
2707 }
2708 return;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002709 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002710 contentInset.setEmpty();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002711 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002712
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002713 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07002714 @Override
2715 public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight,
2716 int displayRotation) {
Dianne Hackbornc652de82013-02-15 16:32:56 -08002717 final int overscanLeft, overscanTop, overscanRight, overscanBottom;
2718 if (isDefaultDisplay) {
2719 switch (displayRotation) {
2720 case Surface.ROTATION_90:
2721 overscanLeft = mOverscanTop;
2722 overscanTop = mOverscanRight;
2723 overscanRight = mOverscanBottom;
2724 overscanBottom = mOverscanLeft;
2725 break;
2726 case Surface.ROTATION_180:
2727 overscanLeft = mOverscanRight;
2728 overscanTop = mOverscanBottom;
2729 overscanRight = mOverscanLeft;
2730 overscanBottom = mOverscanTop;
2731 break;
2732 case Surface.ROTATION_270:
2733 overscanLeft = mOverscanBottom;
2734 overscanTop = mOverscanLeft;
2735 overscanRight = mOverscanTop;
2736 overscanBottom = mOverscanRight;
2737 break;
2738 default:
2739 overscanLeft = mOverscanLeft;
2740 overscanTop = mOverscanTop;
2741 overscanRight = mOverscanRight;
2742 overscanBottom = mOverscanBottom;
2743 break;
2744 }
2745 } else {
2746 overscanLeft = 0;
2747 overscanTop = 0;
2748 overscanRight = 0;
2749 overscanBottom = 0;
2750 }
Dianne Hackborn313440842013-02-19 19:22:59 -08002751 mOverscanScreenLeft = mRestrictedOverscanScreenLeft = 0;
2752 mOverscanScreenTop = mRestrictedOverscanScreenTop = 0;
2753 mOverscanScreenWidth = mRestrictedOverscanScreenWidth = displayWidth;
2754 mOverscanScreenHeight = mRestrictedOverscanScreenHeight = displayHeight;
Dianne Hackbornc652de82013-02-15 16:32:56 -08002755 mSystemLeft = 0;
2756 mSystemTop = 0;
2757 mSystemRight = displayWidth;
2758 mSystemBottom = displayHeight;
2759 mUnrestrictedScreenLeft = overscanLeft;
2760 mUnrestrictedScreenTop = overscanTop;
2761 mUnrestrictedScreenWidth = displayWidth - overscanLeft - overscanRight;
2762 mUnrestrictedScreenHeight = displayHeight - overscanTop - overscanBottom;
2763 mRestrictedScreenLeft = mUnrestrictedScreenLeft;
2764 mRestrictedScreenTop = mUnrestrictedScreenTop;
John Spurlockad3e6cb2013-04-30 08:47:43 -04002765 mRestrictedScreenWidth = mSystemGestures.screenWidth = mUnrestrictedScreenWidth;
2766 mRestrictedScreenHeight = mSystemGestures.screenHeight = mUnrestrictedScreenHeight;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002767 mDockLeft = mContentLeft = mStableLeft = mStableFullscreenLeft
Dianne Hackbornc652de82013-02-15 16:32:56 -08002768 = mCurLeft = mUnrestrictedScreenLeft;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002769 mDockTop = mContentTop = mStableTop = mStableFullscreenTop
Dianne Hackbornc652de82013-02-15 16:32:56 -08002770 = mCurTop = mUnrestrictedScreenTop;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002771 mDockRight = mContentRight = mStableRight = mStableFullscreenRight
Dianne Hackbornc652de82013-02-15 16:32:56 -08002772 = mCurRight = displayWidth - overscanRight;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002773 mDockBottom = mContentBottom = mStableBottom = mStableFullscreenBottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08002774 = mCurBottom = displayHeight - overscanBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002775 mDockLayer = 0x10000000;
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002776 mStatusBarLayer = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002777
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002778 // start with the current dock rect, which will be (0,0,displayWidth,displayHeight)
2779 final Rect pf = mTmpParentFrame;
2780 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002781 final Rect of = mTmpOverscanFrame;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002782 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04002783 final Rect dcf = mTmpDecorFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002784 pf.left = df.left = of.left = vf.left = mDockLeft;
2785 pf.top = df.top = of.top = vf.top = mDockTop;
2786 pf.right = df.right = of.right = vf.right = mDockRight;
2787 pf.bottom = df.bottom = of.bottom = vf.bottom = mDockBottom;
John Spurlock46646232013-09-30 22:32:42 -04002788 dcf.setEmpty(); // Decor frame N/A for system bars.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002789
Craig Mautner69b08182012-09-05 13:07:13 -07002790 if (isDefaultDisplay) {
2791 // For purposes of putting out fake window up to steal focus, we will
2792 // drive nav being hidden only by whether it is requested.
John Spurlocke1f366f2013-08-05 12:22:40 -04002793 final int sysui = mLastSystemUiFlags;
2794 boolean navVisible = (sysui & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0;
John Spurlockbd957402013-10-03 11:38:39 -04002795 boolean navTranslucent = (sysui & View.NAVIGATION_BAR_TRANSLUCENT) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04002796 boolean immersive = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
2797 boolean immersiveSticky = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
2798 boolean navAllowedHidden = immersive || immersiveSticky;
2799 navTranslucent &= !immersiveSticky; // transient trumps translucent
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04002800 navTranslucent &= areTranslucentBarsAllowed();
Dianne Hackborne26ab702011-10-16 13:21:33 -07002801
Craig Mautner69b08182012-09-05 13:07:13 -07002802 // When the navigation bar isn't visible, we put up a fake
2803 // input window to catch all touch events. This way we can
2804 // detect when the user presses anywhere to bring back the nav
2805 // bar and ensure the application doesn't see the event.
John Spurlockf1a36642013-10-12 17:50:42 -04002806 if (navVisible || navAllowedHidden) {
Craig Mautner69b08182012-09-05 13:07:13 -07002807 if (mHideNavFakeWindow != null) {
2808 mHideNavFakeWindow.dismiss();
2809 mHideNavFakeWindow = null;
2810 }
2811 } else if (mHideNavFakeWindow == null) {
2812 mHideNavFakeWindow = mWindowManagerFuncs.addFakeWindow(
2813 mHandler.getLooper(), mHideNavInputEventReceiverFactory,
Adam Lesinski95c42972013-10-02 10:13:27 -07002814 "hidden nav", WindowManager.LayoutParams.TYPE_HIDDEN_NAV_CONSUMER, 0,
Craig Mautner69b08182012-09-05 13:07:13 -07002815 0, false, false, true);
Dianne Hackborne26ab702011-10-16 13:21:33 -07002816 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07002817
Craig Mautner69b08182012-09-05 13:07:13 -07002818 // For purposes of positioning and showing the nav bar, if we have
2819 // decided that it can't be hidden (because of the screen aspect ratio),
2820 // then take that into account.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07002821 navVisible |= !canHideNavigationBar();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002822
John Spurlockad3e6cb2013-04-30 08:47:43 -04002823 boolean updateSysUiVisibility = false;
Craig Mautner69b08182012-09-05 13:07:13 -07002824 if (mNavigationBar != null) {
John Spurlock27735a42013-08-14 17:57:38 -04002825 boolean transientNavBarShowing = mNavigationBarController.isTransientShowing();
Craig Mautner69b08182012-09-05 13:07:13 -07002826 // Force the navigation bar to its appropriate place and
2827 // size. We need to do this directly, instead of relying on
2828 // it to bubble up from the nav bar, because this needs to
2829 // change atomically with screen rotations.
2830 mNavigationBarOnBottom = (!mNavigationBarCanMove || displayWidth < displayHeight);
2831 if (mNavigationBarOnBottom) {
2832 // It's a system nav bar or a portrait screen; nav bar goes on bottom.
Dianne Hackbornc652de82013-02-15 16:32:56 -08002833 int top = displayHeight - overscanBottom
2834 - mNavigationBarHeightForRotation[displayRotation];
2835 mTmpNavigationFrame.set(0, top, displayWidth, displayHeight - overscanBottom);
Craig Mautner69b08182012-09-05 13:07:13 -07002836 mStableBottom = mStableFullscreenBottom = mTmpNavigationFrame.top;
John Spurlockf95b89a2013-10-10 22:10:42 -04002837 if (transientNavBarShowing) {
John Spurlock27735a42013-08-14 17:57:38 -04002838 mNavigationBarController.setBarShowingLw(true);
John Spurlockad3e6cb2013-04-30 08:47:43 -04002839 } else if (navVisible) {
John Spurlock27735a42013-08-14 17:57:38 -04002840 mNavigationBarController.setBarShowingLw(true);
Craig Mautner69b08182012-09-05 13:07:13 -07002841 mDockBottom = mTmpNavigationFrame.top;
Dianne Hackborn313440842013-02-19 19:22:59 -08002842 mRestrictedScreenHeight = mDockBottom - mRestrictedScreenTop;
2843 mRestrictedOverscanScreenHeight = mDockBottom - mRestrictedOverscanScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07002844 } else {
2845 // We currently want to hide the navigation UI.
John Spurlock27735a42013-08-14 17:57:38 -04002846 mNavigationBarController.setBarShowingLw(false);
Craig Mautner69b08182012-09-05 13:07:13 -07002847 }
John Spurlockbd957402013-10-03 11:38:39 -04002848 if (navVisible && !navTranslucent && !mNavigationBar.isAnimatingLw()
2849 && !mNavigationBarController.wasRecentlyTranslucent()) {
John Spurlocke1f366f2013-08-05 12:22:40 -04002850 // If the opaque nav bar is currently requested to be visible,
Craig Mautner69b08182012-09-05 13:07:13 -07002851 // and not in the process of animating on or off, then
2852 // we can tell the app that it is covered by it.
2853 mSystemBottom = mTmpNavigationFrame.top;
2854 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002855 } else {
Craig Mautner69b08182012-09-05 13:07:13 -07002856 // Landscape screen; nav bar goes to the right.
Dianne Hackbornc652de82013-02-15 16:32:56 -08002857 int left = displayWidth - overscanRight
2858 - mNavigationBarWidthForRotation[displayRotation];
2859 mTmpNavigationFrame.set(left, 0, displayWidth - overscanRight, displayHeight);
Craig Mautner69b08182012-09-05 13:07:13 -07002860 mStableRight = mStableFullscreenRight = mTmpNavigationFrame.left;
John Spurlockf95b89a2013-10-10 22:10:42 -04002861 if (transientNavBarShowing) {
John Spurlock27735a42013-08-14 17:57:38 -04002862 mNavigationBarController.setBarShowingLw(true);
John Spurlockad3e6cb2013-04-30 08:47:43 -04002863 } else if (navVisible) {
John Spurlock27735a42013-08-14 17:57:38 -04002864 mNavigationBarController.setBarShowingLw(true);
Craig Mautner69b08182012-09-05 13:07:13 -07002865 mDockRight = mTmpNavigationFrame.left;
Dianne Hackborn313440842013-02-19 19:22:59 -08002866 mRestrictedScreenWidth = mDockRight - mRestrictedScreenLeft;
2867 mRestrictedOverscanScreenWidth = mDockRight - mRestrictedOverscanScreenLeft;
Craig Mautner69b08182012-09-05 13:07:13 -07002868 } else {
2869 // We currently want to hide the navigation UI.
John Spurlock27735a42013-08-14 17:57:38 -04002870 mNavigationBarController.setBarShowingLw(false);
Craig Mautner69b08182012-09-05 13:07:13 -07002871 }
John Spurlockbd957402013-10-03 11:38:39 -04002872 if (navVisible && !navTranslucent && !mNavigationBar.isAnimatingLw()
2873 && !mNavigationBarController.wasRecentlyTranslucent()) {
Craig Mautner69b08182012-09-05 13:07:13 -07002874 // If the nav bar is currently requested to be visible,
2875 // and not in the process of animating on or off, then
2876 // we can tell the app that it is covered by it.
2877 mSystemRight = mTmpNavigationFrame.left;
2878 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002879 }
Craig Mautner69b08182012-09-05 13:07:13 -07002880 // Make sure the content and current rectangles are updated to
2881 // account for the restrictions from the navigation bar.
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002882 mContentTop = mCurTop = mDockTop;
2883 mContentBottom = mCurBottom = mDockBottom;
2884 mContentLeft = mCurLeft = mDockLeft;
2885 mContentRight = mCurRight = mDockRight;
Craig Mautner69b08182012-09-05 13:07:13 -07002886 mStatusBarLayer = mNavigationBar.getSurfaceLayer();
2887 // And compute the final frame.
2888 mNavigationBar.computeFrameLw(mTmpNavigationFrame, mTmpNavigationFrame,
John Spurlock46646232013-09-30 22:32:42 -04002889 mTmpNavigationFrame, mTmpNavigationFrame, mTmpNavigationFrame, dcf);
Craig Mautnereda67292013-04-28 13:50:14 -07002890 if (DEBUG_LAYOUT) Slog.i(TAG, "mNavigationBar frame: " + mTmpNavigationFrame);
John Spurlock27735a42013-08-14 17:57:38 -04002891 if (mNavigationBarController.checkHiddenLw()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04002892 updateSysUiVisibility = true;
2893 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002894 }
Craig Mautnereda67292013-04-28 13:50:14 -07002895 if (DEBUG_LAYOUT) Slog.i(TAG, String.format("mDock rect: (%d,%d - %d,%d)",
Craig Mautner69b08182012-09-05 13:07:13 -07002896 mDockLeft, mDockTop, mDockRight, mDockBottom));
2897
2898 // decide where the status bar goes ahead of time
2899 if (mStatusBar != null) {
2900 // apply any navigation bar insets
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002901 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
2902 pf.top = df.top = of.top = mUnrestrictedScreenTop;
2903 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
2904 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight
2905 + mUnrestrictedScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07002906 vf.left = mStableLeft;
2907 vf.top = mStableTop;
2908 vf.right = mStableRight;
2909 vf.bottom = mStableBottom;
2910
2911 mStatusBarLayer = mStatusBar.getSurfaceLayer();
2912
2913 // Let the status bar determine its size.
John Spurlock46646232013-09-30 22:32:42 -04002914 mStatusBar.computeFrameLw(pf, df, vf, vf, vf, dcf);
Craig Mautner69b08182012-09-05 13:07:13 -07002915
2916 // For layout, the status bar is always at the top with our fixed height.
2917 mStableTop = mUnrestrictedScreenTop + mStatusBarHeight;
2918
John Spurlocke1f366f2013-08-05 12:22:40 -04002919 boolean statusBarTransient = (sysui & View.STATUS_BAR_TRANSIENT) != 0;
John Spurlockbd957402013-10-03 11:38:39 -04002920 boolean statusBarTranslucent = (sysui & View.STATUS_BAR_TRANSLUCENT) != 0;
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04002921 statusBarTranslucent &= areTranslucentBarsAllowed();
John Spurlock32beb2c2013-03-11 10:16:47 -04002922
Craig Mautner69b08182012-09-05 13:07:13 -07002923 // If the status bar is hidden, we don't want to cause
2924 // windows behind it to scroll.
John Spurlockeda1f692013-09-16 11:38:44 -04002925 if (mStatusBar.isVisibleLw() && !statusBarTransient) {
Craig Mautner69b08182012-09-05 13:07:13 -07002926 // Status bar may go away, so the screen area it occupies
2927 // is available to apps but just covering them when the
2928 // status bar is visible.
2929 mDockTop = mUnrestrictedScreenTop + mStatusBarHeight;
2930
2931 mContentTop = mCurTop = mDockTop;
2932 mContentBottom = mCurBottom = mDockBottom;
2933 mContentLeft = mCurLeft = mDockLeft;
2934 mContentRight = mCurRight = mDockRight;
2935
Craig Mautnereda67292013-04-28 13:50:14 -07002936 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar: " +
Craig Mautner69b08182012-09-05 13:07:13 -07002937 String.format(
2938 "dock=[%d,%d][%d,%d] content=[%d,%d][%d,%d] cur=[%d,%d][%d,%d]",
2939 mDockLeft, mDockTop, mDockRight, mDockBottom,
2940 mContentLeft, mContentTop, mContentRight, mContentBottom,
2941 mCurLeft, mCurTop, mCurRight, mCurBottom));
2942 }
John Spurlocke1f366f2013-08-05 12:22:40 -04002943 if (mStatusBar.isVisibleLw() && !mStatusBar.isAnimatingLw()
John Spurlockbd957402013-10-03 11:38:39 -04002944 && !statusBarTransient && !statusBarTranslucent
2945 && !mStatusBarController.wasRecentlyTranslucent()) {
John Spurlocke1f366f2013-08-05 12:22:40 -04002946 // If the opaque status bar is currently requested to be visible,
Craig Mautner69b08182012-09-05 13:07:13 -07002947 // and not in the process of animating on or off, then
2948 // we can tell the app that it is covered by it.
2949 mSystemTop = mUnrestrictedScreenTop + mStatusBarHeight;
2950 }
John Spurlock27735a42013-08-14 17:57:38 -04002951 if (mStatusBarController.checkHiddenLw()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04002952 updateSysUiVisibility = true;
John Spurlock32beb2c2013-03-11 10:16:47 -04002953 }
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002954 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04002955 if (updateSysUiVisibility) {
2956 updateSystemUiVisibilityLw();
2957 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002958 }
2959 }
2960
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07002961 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07002962 @Override
John Spurlock46646232013-09-30 22:32:42 -04002963 public int getSystemDecorLayerLw() {
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07002964 if (mStatusBar != null) return mStatusBar.getSurfaceLayer();
2965 if (mNavigationBar != null) return mNavigationBar.getSurfaceLayer();
2966 return 0;
2967 }
2968
Craig Mautner967212c2013-04-13 21:10:58 -07002969 @Override
2970 public void getContentRectLw(Rect r) {
2971 r.set(mContentLeft, mContentTop, mContentRight, mContentBottom);
2972 }
2973
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002974 void setAttachedWindowFrames(WindowState win, int fl, int adjust, WindowState attached,
2975 boolean insetDecors, Rect pf, Rect df, Rect of, Rect cf, Rect vf) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002976 if (win.getSurfaceLayer() > mDockLayer && attached.getSurfaceLayer() < mDockLayer) {
2977 // Here's a special case: if this attached window is a panel that is
2978 // above the dock window, and the window it is attached to is below
2979 // the dock window, then the frames we computed for the window it is
2980 // attached to can not be used because the dock is effectively part
2981 // of the underlying window and the attached window is floating on top
2982 // of the whole thing. So, we ignore the attached window and explicitly
2983 // compute the frames that would be appropriate without the dock.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002984 df.left = of.left = cf.left = vf.left = mDockLeft;
2985 df.top = of.top = cf.top = vf.top = mDockTop;
2986 df.right = of.right = cf.right = vf.right = mDockRight;
2987 df.bottom = of.bottom = cf.bottom = vf.bottom = mDockBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002988 } else {
2989 // The effective display frame of the attached window depends on
2990 // whether it is taking care of insetting its content. If not,
2991 // we need to use the parent's content frame so that the entire
2992 // window is positioned within that content. Otherwise we can use
2993 // the display frame and let the attached window take care of
2994 // positioning its content appropriately.
Dianne Hackborndea3ef72010-10-28 14:24:22 -07002995 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002996 cf.set(attached.getOverscanFrameLw());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002997 } else {
2998 // If the window is resizing, then we want to base the content
2999 // frame on our attached content frame to resize... however,
3000 // things can be tricky if the attached window is NOT in resize
3001 // mode, in which case its content frame will be larger.
3002 // Ungh. So to deal with that, make sure the content frame
3003 // we end up using is not covering the IM dock.
3004 cf.set(attached.getContentFrameLw());
3005 if (attached.getSurfaceLayer() < mDockLayer) {
3006 if (cf.left < mContentLeft) cf.left = mContentLeft;
3007 if (cf.top < mContentTop) cf.top = mContentTop;
3008 if (cf.right > mContentRight) cf.right = mContentRight;
3009 if (cf.bottom > mContentBottom) cf.bottom = mContentBottom;
3010 }
3011 }
3012 df.set(insetDecors ? attached.getDisplayFrameLw() : cf);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003013 of.set(insetDecors ? attached.getOverscanFrameLw() : cf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003014 vf.set(attached.getVisibleFrameLw());
3015 }
3016 // The LAYOUT_IN_SCREEN flag is used to determine whether the attached
3017 // window should be positioned relative to its parent or the entire
3018 // screen.
3019 pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0
3020 ? attached.getFrameLw() : df);
3021 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003022
3023 private void applyStableConstraints(int sysui, int fl, Rect r) {
3024 if ((sysui & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
3025 // If app is requesting a stable layout, don't let the
3026 // content insets go below the stable values.
3027 if ((fl & FLAG_FULLSCREEN) != 0) {
3028 if (r.left < mStableFullscreenLeft) r.left = mStableFullscreenLeft;
3029 if (r.top < mStableFullscreenTop) r.top = mStableFullscreenTop;
3030 if (r.right > mStableFullscreenRight) r.right = mStableFullscreenRight;
3031 if (r.bottom > mStableFullscreenBottom) r.bottom = mStableFullscreenBottom;
3032 } else {
3033 if (r.left < mStableLeft) r.left = mStableLeft;
3034 if (r.top < mStableTop) r.top = mStableTop;
3035 if (r.right > mStableRight) r.right = mStableRight;
3036 if (r.bottom > mStableBottom) r.bottom = mStableBottom;
3037 }
3038 }
3039 }
3040
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003041 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07003042 @Override
Dianne Hackborn0ecadf72009-03-31 18:00:37 -07003043 public void layoutWindowLw(WindowState win, WindowManager.LayoutParams attrs,
3044 WindowState attached) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003045 // we've already done the status bar
Dianne Hackborn1f903c32011-09-13 19:18:06 -07003046 if (win == mStatusBar || win == mNavigationBar) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003047 return;
3048 }
Craig Mautner69b08182012-09-05 13:07:13 -07003049 final boolean isDefaultDisplay = win.isDefaultDisplay();
3050 final boolean needsToOffsetInputMethodTarget = isDefaultDisplay &&
satok1bc0a492012-04-25 22:47:12 +09003051 (win == mLastInputMethodTargetWindow && mLastInputMethodWindow != null);
3052 if (needsToOffsetInputMethodTarget) {
Craig Mautnereda67292013-04-28 13:50:14 -07003053 if (DEBUG_LAYOUT) Slog.i(TAG, "Offset ime target window by the last ime window state");
satok1bc0a492012-04-25 22:47:12 +09003054 offsetInputMethodWindowLw(mLastInputMethodWindow);
3055 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003056
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003057 final int fl = attrs.flags;
3058 final int sim = attrs.softInputMode;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003059 final int sysUiFl = win.getSystemUiVisibility();
3060
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003061 final Rect pf = mTmpParentFrame;
3062 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003063 final Rect of = mTmpOverscanFrame;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003064 final Rect cf = mTmpContentFrame;
3065 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04003066 final Rect dcf = mTmpDecorFrame;
3067 dcf.setEmpty();
Craig Mautner69b08182012-09-05 13:07:13 -07003068
3069 final boolean hasNavBar = (isDefaultDisplay && mHasNavigationBar
Daniel Sandler36412a72011-08-04 09:35:13 -04003070 && mNavigationBar != null && mNavigationBar.isVisibleLw());
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003071
Craig Mautnerf683b562012-10-02 11:10:57 -07003072 final int adjust = sim & SOFT_INPUT_MASK_ADJUST;
3073
Craig Mautner69b08182012-09-05 13:07:13 -07003074 if (!isDefaultDisplay) {
3075 if (attached != null) {
3076 // If this window is attached to another, our display
3077 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003078 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07003079 } else {
3080 // Give the window full screen.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003081 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3082 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3083 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08003084 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003085 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003086 = mOverscanScreenTop + mOverscanScreenHeight;
Craig Mautner69b08182012-09-05 13:07:13 -07003087 }
3088 } else if (attrs.type == TYPE_INPUT_METHOD) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003089 pf.left = df.left = of.left = cf.left = vf.left = mDockLeft;
3090 pf.top = df.top = of.top = cf.top = vf.top = mDockTop;
3091 pf.right = df.right = of.right = cf.right = vf.right = mDockRight;
John Spurlockc68d5772013-10-08 11:47:58 -04003092 // IM dock windows layout below the nav bar...
John Spurlock57beb3b2013-10-10 10:27:44 -04003093 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlockc68d5772013-10-08 11:47:58 -04003094 // ...with content insets above the nav bar
3095 cf.bottom = vf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003096 // IM dock windows always go to the bottom of the screen.
3097 attrs.gravity = Gravity.BOTTOM;
3098 mDockLayer = win.getSurfaceLayer();
3099 } else {
John Spurlock46646232013-09-30 22:32:42 -04003100
3101 // Default policy decor for the default display
3102 dcf.left = mSystemLeft;
3103 dcf.top = mSystemTop;
3104 dcf.right = mSystemRight;
3105 dcf.bottom = mSystemBottom;
John Spurlockbd957402013-10-03 11:38:39 -04003106 final boolean inheritTranslucentDecor = (attrs.privateFlags
3107 & WindowManager.LayoutParams.PRIVATE_FLAG_INHERIT_TRANSLUCENT_DECOR) != 0;
John Spurlock65567d42013-10-08 10:08:32 -04003108 final boolean isAppWindow =
3109 attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW &&
3110 attrs.type <= WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
3111 final boolean topAtRest =
3112 win == mTopFullscreenOpaqueWindowState && !win.isAnimatingLw();
3113 if (isAppWindow && !inheritTranslucentDecor && !topAtRest) {
John Spurlockbd957402013-10-03 11:38:39 -04003114 if ((sysUiFl & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0
3115 && (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0
3116 && (fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04003117 // Ensure policy decor includes status bar
3118 dcf.top = mStableTop;
3119 }
John Spurlockbd957402013-10-03 11:38:39 -04003120 if ((fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) == 0
John Spurlock8e0ca282013-10-03 11:46:06 -04003121 && (sysUiFl & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04003122 // Ensure policy decor includes navigation bar
3123 dcf.bottom = mStableBottom;
3124 dcf.right = mStableRight;
3125 }
3126 }
3127
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003128 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
3129 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
Craig Mautnereda67292013-04-28 13:50:14 -07003130 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003131 + "): IN_SCREEN, INSET_DECOR");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003132 // This is the case for a normal activity window: we want it
3133 // to cover all of the screen space, and it can take care of
3134 // moving its contents to account for screen decorations that
3135 // intrude into that space.
3136 if (attached != null) {
3137 // If this window is attached to another, our display
3138 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003139 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003140 } else {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003141 if (attrs.type == TYPE_STATUS_BAR_PANEL
3142 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Joe Onorato29fc2c92010-11-24 10:26:50 -08003143 // Status bar panels are the only windows who can go on top of
3144 // the status bar. They are protected by the STATUS_BAR_SERVICE
3145 // permission, so they have the same privileges as the status
3146 // bar itself.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003147 //
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003148 // However, they should still dodge the navigation bar if it exists.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003149
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003150 pf.left = df.left = of.left = hasNavBar
3151 ? mDockLeft : mUnrestrictedScreenLeft;
3152 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3153 pf.right = df.right = of.right = hasNavBar
3154 ? mRestrictedScreenLeft+mRestrictedScreenWidth
3155 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3156 pf.bottom = df.bottom = of.bottom = hasNavBar
3157 ? mRestrictedScreenTop+mRestrictedScreenHeight
3158 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003159
Craig Mautnereda67292013-04-28 13:50:14 -07003160 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003161 "Laying out status bar window: (%d,%d - %d,%d)",
3162 pf.left, pf.top, pf.right, pf.bottom));
John Spurlock46646232013-09-30 22:32:42 -04003163 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08003164 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3165 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3166 // Asking to layout into the overscan region, so give it that pure
3167 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003168 pf.left = df.left = of.left = mOverscanScreenLeft;
3169 pf.top = df.top = of.top = mOverscanScreenTop;
3170 pf.right = df.right = of.right = mOverscanScreenLeft + mOverscanScreenWidth;
3171 pf.bottom = df.bottom = of.bottom = mOverscanScreenTop
3172 + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003173 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003174 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
John Spurlockf95b89a2013-10-10 22:10:42 -04003175 && (attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD || (
3176 attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3177 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW))) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003178 // Asking for layout as if the nav bar is hidden, lets the
Dianne Hackbornc652de82013-02-15 16:32:56 -08003179 // application extend into the unrestricted overscan screen area. We
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003180 // only do this for application windows to ensure no window that
3181 // can be above the nav bar can do this.
Dianne Hackborn313440842013-02-19 19:22:59 -08003182 pf.left = df.left = mOverscanScreenLeft;
3183 pf.top = df.top = mOverscanScreenTop;
3184 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
3185 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003186 // We need to tell the app about where the frame inside the overscan
3187 // is, so it can inset its content by that amount -- it didn't ask
3188 // to actually extend itself into the overscan region.
3189 of.left = mUnrestrictedScreenLeft;
3190 of.top = mUnrestrictedScreenTop;
3191 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3192 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003193 } else {
Dianne Hackborn313440842013-02-19 19:22:59 -08003194 pf.left = df.left = mRestrictedOverscanScreenLeft;
3195 pf.top = df.top = mRestrictedOverscanScreenTop;
3196 pf.right = df.right = mRestrictedOverscanScreenLeft
3197 + mRestrictedOverscanScreenWidth;
3198 pf.bottom = df.bottom = mRestrictedOverscanScreenTop
3199 + mRestrictedOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003200 // We need to tell the app about where the frame inside the overscan
3201 // is, so it can inset its content by that amount -- it didn't ask
3202 // to actually extend itself into the overscan region.
3203 of.left = mUnrestrictedScreenLeft;
3204 of.top = mUnrestrictedScreenTop;
3205 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3206 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003207 }
Craig Mautner69b08182012-09-05 13:07:13 -07003208
John Spurlock46646232013-09-30 22:32:42 -04003209 if ((fl & FLAG_FULLSCREEN) == 0) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003210 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
3211 cf.left = mDockLeft;
3212 cf.top = mDockTop;
3213 cf.right = mDockRight;
3214 cf.bottom = mDockBottom;
3215 } else {
3216 cf.left = mContentLeft;
3217 cf.top = mContentTop;
3218 cf.right = mContentRight;
3219 cf.bottom = mContentBottom;
3220 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003221 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003222 // Full screen windows are always given a layout that is as if the
3223 // status bar and other transient decors are gone. This is to avoid
3224 // bad states when moving from a window that is not hding the
3225 // status bar to one that is.
3226 cf.left = mRestrictedScreenLeft;
3227 cf.top = mRestrictedScreenTop;
3228 cf.right = mRestrictedScreenLeft + mRestrictedScreenWidth;
3229 cf.bottom = mRestrictedScreenTop + mRestrictedScreenHeight;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003230 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003231 applyStableConstraints(sysUiFl, fl, cf);
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003232 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3233 vf.left = mCurLeft;
3234 vf.top = mCurTop;
3235 vf.right = mCurRight;
3236 vf.bottom = mCurBottom;
3237 } else {
3238 vf.set(cf);
3239 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003240 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003241 } else if ((fl & FLAG_LAYOUT_IN_SCREEN) != 0 || (sysUiFl
3242 & (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
3243 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)) != 0) {
Craig Mautnereda67292013-04-28 13:50:14 -07003244 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3245 "): IN_SCREEN");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003246 // A window that has requested to fill the entire screen just
3247 // gets everything, period.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003248 if (attrs.type == TYPE_STATUS_BAR_PANEL
3249 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003250 pf.left = df.left = of.left = cf.left = hasNavBar
3251 ? mDockLeft : mUnrestrictedScreenLeft;
3252 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
3253 pf.right = df.right = of.right = cf.right = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003254 ? mRestrictedScreenLeft+mRestrictedScreenWidth
Dianne Hackbornc652de82013-02-15 16:32:56 -08003255 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003256 pf.bottom = df.bottom = of.bottom = cf.bottom = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003257 ? mRestrictedScreenTop+mRestrictedScreenHeight
Dianne Hackbornc652de82013-02-15 16:32:56 -08003258 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07003259 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler36412a72011-08-04 09:35:13 -04003260 "Laying out IN_SCREEN status bar window: (%d,%d - %d,%d)",
3261 pf.left, pf.top, pf.right, pf.bottom));
Jim Millere898ac52012-04-06 17:10:57 -07003262 } else if (attrs.type == TYPE_NAVIGATION_BAR
3263 || attrs.type == TYPE_NAVIGATION_BAR_PANEL) {
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003264 // The navigation bar has Real Ultimate Power.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003265 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3266 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3267 pf.right = df.right = of.right = mUnrestrictedScreenLeft
3268 + mUnrestrictedScreenWidth;
3269 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop
3270 + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07003271 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003272 "Laying out navigation bar window: (%d,%d - %d,%d)",
3273 pf.left, pf.top, pf.right, pf.bottom));
Dianne Hackborn01011c32012-02-21 13:54:21 -08003274 } else if ((attrs.type == TYPE_SECURE_SYSTEM_OVERLAY
3275 || attrs.type == TYPE_BOOT_PROGRESS)
Jeff Brownbfcb60a2011-09-08 18:51:14 -07003276 && ((fl & FLAG_FULLSCREEN) != 0)) {
3277 // Fullscreen secure system overlays get what they ask for.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003278 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3279 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3280 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
3281 + mOverscanScreenWidth;
3282 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
3283 + mOverscanScreenHeight;
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07003284 } else if (attrs.type == TYPE_BOOT_PROGRESS
3285 || attrs.type == TYPE_UNIVERSE_BACKGROUND) {
Dianne Hackborn01011c32012-02-21 13:54:21 -08003286 // Boot progress screen always covers entire display.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003287 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3288 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3289 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
3290 + mOverscanScreenWidth;
3291 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
3292 + mOverscanScreenHeight;
John Spurlockef4adae2013-08-26 17:58:58 -04003293 } else if (attrs.type == TYPE_WALLPAPER) {
3294 // The wallpaper also has Real Ultimate Power.
3295 pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft;
3296 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003297 pf.right = df.right = of.right = cf.right
John Spurlockef4adae2013-08-26 17:58:58 -04003298 = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003299 pf.bottom = df.bottom = of.bottom = cf.bottom
John Spurlockef4adae2013-08-26 17:58:58 -04003300 = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlock46646232013-09-30 22:32:42 -04003301 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08003302 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3303 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3304 // Asking to layout into the overscan region, so give it that pure
3305 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003306 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3307 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3308 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08003309 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003310 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003311 = mOverscanScreenTop + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003312 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003313 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
John Spurlock34e13d92013-08-10 06:52:28 -04003314 && (attrs.type == TYPE_TOAST
3315 || (attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3316 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW))) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003317 // Asking for layout as if the nav bar is hidden, lets the
3318 // application extend into the unrestricted screen area. We
John Spurlock34e13d92013-08-10 06:52:28 -04003319 // only do this for application windows (or toasts) to ensure no window that
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003320 // can be above the nav bar can do this.
3321 // XXX This assumes that an app asking for this will also
3322 // ask for layout in only content. We can't currently figure out
3323 // what the screen would be if only laying out to hide the nav bar.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003324 pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft;
3325 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
3326 pf.right = df.right = of.right = cf.right = mUnrestrictedScreenLeft
3327 + mUnrestrictedScreenWidth;
3328 pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop
3329 + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003330 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003331 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
3332 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
3333 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
3334 + mRestrictedScreenWidth;
3335 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
3336 + mRestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003337 }
Craig Mautner69b08182012-09-05 13:07:13 -07003338
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003339 applyStableConstraints(sysUiFl, fl, cf);
Craig Mautner69b08182012-09-05 13:07:13 -07003340
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003341 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3342 vf.left = mCurLeft;
3343 vf.top = mCurTop;
3344 vf.right = mCurRight;
3345 vf.bottom = mCurBottom;
3346 } else {
3347 vf.set(cf);
3348 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003349 } else if (attached != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07003350 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3351 "): attached to " + attached);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003352 // A child window should be placed inside of the same visible
3353 // frame that its parent had.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003354 setAttachedWindowFrames(win, fl, adjust, attached, false, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003355 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07003356 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3357 "): normal window");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003358 // Otherwise, a normal window must be placed inside the content
3359 // of all screen decorations.
Dianne Hackborna239c842011-06-01 12:28:20 -07003360 if (attrs.type == TYPE_STATUS_BAR_PANEL) {
3361 // Status bar panels are the only windows who can go on top of
3362 // the status bar. They are protected by the STATUS_BAR_SERVICE
3363 // permission, so they have the same privileges as the status
3364 // bar itself.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003365 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
3366 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
3367 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
3368 + mRestrictedScreenWidth;
3369 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
3370 + mRestrictedScreenHeight;
John Spurlockca4d0402013-12-04 13:47:36 -05003371 } else if (attrs.type == TYPE_TOAST || attrs.type == TYPE_SYSTEM_ALERT
3372 || attrs.type == TYPE_VOLUME_OVERLAY) {
3373 // These dialogs are stable to interim decor changes.
John Spurlockbd957402013-10-03 11:38:39 -04003374 pf.left = df.left = of.left = cf.left = mStableLeft;
3375 pf.top = df.top = of.top = cf.top = mStableTop;
3376 pf.right = df.right = of.right = cf.right = mStableRight;
3377 pf.bottom = df.bottom = of.bottom = cf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003378 } else {
Dianne Hackborna239c842011-06-01 12:28:20 -07003379 pf.left = mContentLeft;
3380 pf.top = mContentTop;
3381 pf.right = mContentRight;
3382 pf.bottom = mContentBottom;
3383 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003384 df.left = of.left = cf.left = mDockLeft;
3385 df.top = of.top = cf.top = mDockTop;
3386 df.right = of.right = cf.right = mDockRight;
3387 df.bottom = of.bottom = cf.bottom = mDockBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07003388 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003389 df.left = of.left = cf.left = mContentLeft;
3390 df.top = of.top = cf.top = mContentTop;
3391 df.right = of.right = cf.right = mContentRight;
3392 df.bottom = of.bottom = cf.bottom = mContentBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07003393 }
3394 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3395 vf.left = mCurLeft;
3396 vf.top = mCurTop;
3397 vf.right = mCurRight;
3398 vf.bottom = mCurBottom;
3399 } else {
3400 vf.set(cf);
3401 }
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003402 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003403 }
3404 }
Craig Mautner69b08182012-09-05 13:07:13 -07003405
Craig Mautnerb816bed2013-07-23 10:26:17 -07003406 // TYPE_SYSTEM_ERROR is above the NavigationBar so it can't be allowed to extend over it.
3407 if ((fl & FLAG_LAYOUT_NO_LIMITS) != 0 && attrs.type != TYPE_SYSTEM_ERROR) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003408 df.left = df.top = of.left = of.top = cf.left = cf.top = vf.left = vf.top = -10000;
3409 df.right = df.bottom = of.right = of.bottom = cf.right = cf.bottom
3410 = vf.right = vf.bottom = 10000;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003411 }
3412
Craig Mautnereda67292013-04-28 13:50:14 -07003413 if (DEBUG_LAYOUT) Slog.v(TAG, "Compute frame " + attrs.getTitle()
The Android Open Source Project11267662009-03-18 17:39:47 -07003414 + ": sim=#" + Integer.toHexString(sim)
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003415 + " attach=" + attached + " type=" + attrs.type
3416 + String.format(" flags=0x%08x", fl)
The Android Open Source Project11267662009-03-18 17:39:47 -07003417 + " pf=" + pf.toShortString() + " df=" + df.toShortString()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003418 + " of=" + of.toShortString()
John Spurlock46646232013-09-30 22:32:42 -04003419 + " cf=" + cf.toShortString() + " vf=" + vf.toShortString()
3420 + " dcf=" + dcf.toShortString());
Craig Mautner69b08182012-09-05 13:07:13 -07003421
John Spurlock46646232013-09-30 22:32:42 -04003422 win.computeFrameLw(pf, df, of, cf, vf, dcf);
Craig Mautner69b08182012-09-05 13:07:13 -07003423
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003424 // Dock windows carve out the bottom of the screen, so normal windows
3425 // can't appear underneath them.
Craig Mautner8bd206b2012-10-03 10:32:02 -07003426 if (attrs.type == TYPE_INPUT_METHOD && win.isVisibleOrBehindKeyguardLw()
3427 && !win.getGivenInsetsPendingLw()) {
satok1bc0a492012-04-25 22:47:12 +09003428 setLastInputMethodWindowLw(null, null);
3429 offsetInputMethodWindowLw(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003430 }
3431 }
3432
satok1bc0a492012-04-25 22:47:12 +09003433 private void offsetInputMethodWindowLw(WindowState win) {
3434 int top = win.getContentFrameLw().top;
3435 top += win.getGivenContentInsetsLw().top;
3436 if (mContentBottom > top) {
3437 mContentBottom = top;
3438 }
3439 top = win.getVisibleFrameLw().top;
3440 top += win.getGivenVisibleInsetsLw().top;
3441 if (mCurBottom > top) {
3442 mCurBottom = top;
3443 }
Craig Mautnereda67292013-04-28 13:50:14 -07003444 if (DEBUG_LAYOUT) Slog.v(TAG, "Input method: mDockBottom="
satok1bc0a492012-04-25 22:47:12 +09003445 + mDockBottom + " mContentBottom="
3446 + mContentBottom + " mCurBottom=" + mCurBottom);
3447 }
3448
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003449 /** {@inheritDoc} */
Craig Mautner61ac6bb2012-02-02 17:29:33 -08003450 @Override
3451 public void finishLayoutLw() {
3452 return;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003453 }
3454
3455 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003456 @Override
Craig Mautner39834192012-09-02 07:47:24 -07003457 public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) {
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003458 mTopFullscreenOpaqueWindowState = null;
Craig Mautner03924422014-03-19 19:48:38 -07003459 mAppsToBeHidden.clear();
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003460 mForceStatusBar = false;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003461 mForceStatusBarFromKeyguard = false;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08003462 mForcingShowNavBar = false;
3463 mForcingShowNavBarLayer = -1;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003464
3465 mHideLockScreen = false;
3466 mAllowLockscreenWhenOn = false;
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003467 mDismissKeyguard = DISMISS_KEYGUARD_NONE;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003468 mShowingLockscreen = false;
3469 mShowingDream = false;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003470 }
3471
3472 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003473 @Override
Craig Mautner39834192012-09-02 07:47:24 -07003474 public void applyPostLayoutPolicyLw(WindowState win,
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003475 WindowManager.LayoutParams attrs) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07003476 if (DEBUG_LAYOUT) Slog.i(TAG, "Win " + win + ": isVisibleOrBehindKeyguardLw="
3477 + win.isVisibleOrBehindKeyguardLw());
John Spurlockca4d0402013-12-04 13:47:36 -05003478 if (mTopFullscreenOpaqueWindowState == null
3479 && win.isVisibleLw() && attrs.type == TYPE_INPUT_METHOD) {
3480 mForcingShowNavBar = true;
3481 mForcingShowNavBarLayer = win.getSurfaceLayer();
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08003482 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003483 if (mTopFullscreenOpaqueWindowState == null &&
Dianne Hackborn01b02a72012-01-12 14:05:03 -08003484 win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()) {
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003485 if ((attrs.flags & FLAG_FORCE_NOT_FULLSCREEN) != 0) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003486 if (attrs.type == TYPE_KEYGUARD) {
3487 mForceStatusBarFromKeyguard = true;
3488 } else {
3489 mForceStatusBar = true;
3490 }
3491 }
3492 if (attrs.type == TYPE_KEYGUARD) {
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003493 mShowingLockscreen = true;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07003494 }
Craig Mautnerab55e522014-03-03 13:26:03 -08003495 boolean appWindow = attrs.type >= FIRST_APPLICATION_WINDOW
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003496 && attrs.type <= LAST_APPLICATION_WINDOW;
3497 if (attrs.type == TYPE_DREAM) {
Jeff Brownc8018eb2012-10-29 21:33:27 -07003498 // If the lockscreen was showing when the dream started then wait
3499 // for the dream to draw before hiding the lockscreen.
3500 if (!mDreamingLockscreen
3501 || (win.isVisibleLw() && win.hasDrawnLw())) {
3502 mShowingDream = true;
Craig Mautnerab55e522014-03-03 13:26:03 -08003503 appWindow = true;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003504 }
3505 }
Craig Mautnerab55e522014-03-03 13:26:03 -08003506
3507 final boolean showWhenLocked = (attrs.flags & FLAG_SHOW_WHEN_LOCKED) != 0;
Craig Mautner4bdab6b2014-04-01 12:05:11 -07003508 final boolean dismissKeyguard = (attrs.flags & FLAG_DISMISS_KEYGUARD) != 0;
Craig Mautnerab55e522014-03-03 13:26:03 -08003509 if (appWindow) {
Craig Mautner4bdab6b2014-04-01 12:05:11 -07003510 if (showWhenLocked || (dismissKeyguard && !isKeyguardSecure())) {
Craig Mautner03924422014-03-19 19:48:38 -07003511 mAppsToBeHidden.remove(win.getAppToken());
3512 } else {
3513 mAppsToBeHidden.add(win.getAppToken());
3514 }
Craig Mautnerab55e522014-03-03 13:26:03 -08003515 if (attrs.x == 0 && attrs.y == 0
3516 && attrs.width == WindowManager.LayoutParams.MATCH_PARENT
3517 && attrs.height == WindowManager.LayoutParams.MATCH_PARENT) {
3518 if (DEBUG_LAYOUT) Slog.v(TAG, "Fullscreen window: " + win);
3519 mTopFullscreenOpaqueWindowState = win;
Craig Mautner03924422014-03-19 19:48:38 -07003520 if (mAppsToBeHidden.isEmpty()) {
Craig Mautner1f524372014-03-03 13:26:03 -08003521 if (showWhenLocked) {
Craig Mautnerff89d582014-03-13 21:09:35 -07003522 if (DEBUG_LAYOUT) Slog.v(TAG,
3523 "Setting mHideLockScreen to true by win " + win);
Craig Mautner1f524372014-03-03 13:26:03 -08003524 mHideLockScreen = true;
3525 mForceStatusBarFromKeyguard = false;
3526 }
Craig Mautner4bdab6b2014-04-01 12:05:11 -07003527 if (dismissKeyguard && mDismissKeyguard == DISMISS_KEYGUARD_NONE) {
Craig Mautner1f524372014-03-03 13:26:03 -08003528 if (DEBUG_LAYOUT) Slog.v(TAG, "Setting mDismissKeyguard true by win " + win);
3529 mDismissKeyguard = mWinDismissingKeyguard == win ?
3530 DISMISS_KEYGUARD_CONTINUE : DISMISS_KEYGUARD_START;
3531 mWinDismissingKeyguard = win;
Craig Mautnerff89d582014-03-13 21:09:35 -07003532 mForceStatusBarFromKeyguard = mShowingLockscreen && isKeyguardSecure();
Craig Mautner1f524372014-03-03 13:26:03 -08003533 }
Craig Mautnerab55e522014-03-03 13:26:03 -08003534 }
3535 if ((attrs.flags & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) {
3536 mAllowLockscreenWhenOn = true;
3537 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003538 }
3539 }
3540 }
3541 }
3542
3543 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003544 @Override
Craig Mautner39834192012-09-02 07:47:24 -07003545 public int finishPostLayoutPolicyLw() {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003546 int changes = 0;
Joe Onorato93056472010-09-10 10:30:46 -04003547 boolean topIsFullscreen = false;
Daniel Sandlere02d8082010-10-08 15:13:22 -04003548
3549 final WindowManager.LayoutParams lp = (mTopFullscreenOpaqueWindowState != null)
3550 ? mTopFullscreenOpaqueWindowState.getAttrs()
3551 : null;
3552
Jeff Brownc8018eb2012-10-29 21:33:27 -07003553 // If we are not currently showing a dream then remember the current
3554 // lockscreen state. We will use this to determine whether the dream
3555 // started while the lockscreen was showing and remember this state
3556 // while the dream is showing.
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003557 if (!mShowingDream) {
3558 mDreamingLockscreen = mShowingLockscreen;
3559 }
3560
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003561 if (mStatusBar != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07003562 if (DEBUG_LAYOUT) Slog.i(TAG, "force=" + mForceStatusBar
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003563 + " forcefkg=" + mForceStatusBarFromKeyguard
Dianne Hackbornd70bc2f2009-10-06 23:25:51 -07003564 + " top=" + mTopFullscreenOpaqueWindowState);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003565 if (mForceStatusBar || mForceStatusBarFromKeyguard) {
Craig Mautnereda67292013-04-28 13:50:14 -07003566 if (DEBUG_LAYOUT) Slog.v(TAG, "Showing status bar: forced");
John Spurlock27735a42013-08-14 17:57:38 -04003567 if (mStatusBarController.setBarShowingLw(true)) {
3568 changes |= FINISH_LAYOUT_REDO_LAYOUT;
3569 }
Craig Mautner81defc72013-10-29 11:10:42 -07003570 // Maintain fullscreen layout until incoming animation is complete.
3571 topIsFullscreen = mTopIsFullscreen && mStatusBar.isAnimatingLw();
John Spurlockf92b6162013-11-11 15:01:16 -05003572 // Transient status bar on the lockscreen is not allowed
3573 if (mForceStatusBarFromKeyguard && mStatusBarController.isTransientShowing()) {
3574 mStatusBarController.updateVisibilityLw(false /*transientAllowed*/,
3575 mLastSystemUiFlags, mLastSystemUiFlags);
3576 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003577 } else if (mTopFullscreenOpaqueWindowState != null) {
Joe Onorato93056472010-09-10 10:30:46 -04003578 if (localLOGV) {
Craig Mautnereda67292013-04-28 13:50:14 -07003579 Slog.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw()
Joe Onorato93056472010-09-10 10:30:46 -04003580 + " shown frame: " + mTopFullscreenOpaqueWindowState.getShownFrameLw());
Craig Mautnereda67292013-04-28 13:50:14 -07003581 Slog.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs()
Joe Onorato93056472010-09-10 10:30:46 -04003582 + " lp.flags=0x" + Integer.toHexString(lp.flags));
3583 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003584 topIsFullscreen = (lp.flags & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0
3585 || (mLastSystemUiFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
Joe Onorato93056472010-09-10 10:30:46 -04003586 // The subtle difference between the window for mTopFullscreenOpaqueWindowState
3587 // and mTopIsFullscreen is that that mTopIsFullscreen is set only if the window
3588 // has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the
3589 // case though.
John Spurlock27735a42013-08-14 17:57:38 -04003590 if (mStatusBarController.isTransientShowing()) {
3591 if (mStatusBarController.setBarShowingLw(true)) {
John Spurlock32beb2c2013-03-11 10:16:47 -04003592 changes |= FINISH_LAYOUT_REDO_LAYOUT;
3593 }
3594 } else if (topIsFullscreen) {
Craig Mautnereda67292013-04-28 13:50:14 -07003595 if (DEBUG_LAYOUT) Slog.v(TAG, "** HIDING status bar");
John Spurlock27735a42013-08-14 17:57:38 -04003596 if (mStatusBarController.setBarShowingLw(false)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003597 changes |= FINISH_LAYOUT_REDO_LAYOUT;
Craig Mautnereda67292013-04-28 13:50:14 -07003598 } else {
Craig Mautnerc5a6e442013-06-05 17:22:35 -07003599 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar already hiding");
Daniel Sandler40427442010-07-16 11:44:52 -04003600 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003601 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07003602 if (DEBUG_LAYOUT) Slog.v(TAG, "** SHOWING status bar: top is not fullscreen");
John Spurlock27735a42013-08-14 17:57:38 -04003603 if (mStatusBarController.setBarShowingLw(true)) {
3604 changes |= FINISH_LAYOUT_REDO_LAYOUT;
3605 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003606 }
3607 }
3608 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04003609
Craig Mautner81defc72013-10-29 11:10:42 -07003610 if (mTopIsFullscreen != topIsFullscreen) {
3611 if (!topIsFullscreen) {
3612 // Force another layout when status bar becomes fully shown.
3613 changes |= FINISH_LAYOUT_REDO_LAYOUT;
3614 }
3615 mTopIsFullscreen = topIsFullscreen;
3616 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04003617
Craig Mautner39834192012-09-02 07:47:24 -07003618 // Hide the key guard if a visible window explicitly specifies that it wants to be
3619 // displayed when the screen is locked.
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -07003620 if (mKeyguard != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07003621 if (localLOGV) Slog.v(TAG, "finishPostLayoutPolicyLw: mHideKeyguard="
Craig Mautner39834192012-09-02 07:47:24 -07003622 + mHideLockScreen);
Craig Mautnerab55e522014-03-03 13:26:03 -08003623 if (mDismissKeyguard != DISMISS_KEYGUARD_NONE && !isKeyguardSecure()) {
Dianne Hackborn08743722009-12-21 12:16:51 -08003624 if (mKeyguard.hideLw(true)) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003625 changes |= FINISH_LAYOUT_REDO_LAYOUT
3626 | FINISH_LAYOUT_REDO_CONFIG
3627 | FINISH_LAYOUT_REDO_WALLPAPER;
3628 }
Jim Miller5ecd8112013-01-09 18:50:26 -08003629 if (mKeyguardDelegate.isShowing()) {
Dianne Hackbornb446e972009-09-20 15:23:25 -07003630 mHandler.post(new Runnable() {
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003631 @Override
Dianne Hackbornb446e972009-09-20 15:23:25 -07003632 public void run() {
Jim Miller5ecd8112013-01-09 18:50:26 -08003633 mKeyguardDelegate.keyguardDone(false, false);
Dianne Hackbornb446e972009-09-20 15:23:25 -07003634 }
3635 });
3636 }
Dianne Hackborn05726582009-09-22 17:28:24 -07003637 } else if (mHideLockScreen) {
Dianne Hackborn08743722009-12-21 12:16:51 -08003638 if (mKeyguard.hideLw(true)) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003639 changes |= FINISH_LAYOUT_REDO_LAYOUT
3640 | FINISH_LAYOUT_REDO_CONFIG
3641 | FINISH_LAYOUT_REDO_WALLPAPER;
3642 }
Craig Mautner28816302013-10-10 20:31:00 -07003643 if (!mShowingDream) {
3644 mKeyguardDelegate.setHidden(true);
3645 }
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003646 } else if (mDismissKeyguard != DISMISS_KEYGUARD_NONE) {
3647 // This is the case of keyguard isSecure() and not mHideLockScreen.
3648 if (mDismissKeyguard == DISMISS_KEYGUARD_START) {
3649 // Only launch the next keyguard unlock window once per window.
3650 if (mKeyguard.showLw(true)) {
3651 changes |= FINISH_LAYOUT_REDO_LAYOUT
3652 | FINISH_LAYOUT_REDO_CONFIG
3653 | FINISH_LAYOUT_REDO_WALLPAPER;
3654 }
Jim Miller5ecd8112013-01-09 18:50:26 -08003655 mKeyguardDelegate.setHidden(false);
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003656 mHandler.post(new Runnable() {
3657 @Override
3658 public void run() {
Jim Miller5ecd8112013-01-09 18:50:26 -08003659 mKeyguardDelegate.dismiss();
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003660 }
3661 });
3662 }
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -07003663 } else {
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003664 mWinDismissingKeyguard = null;
Dianne Hackborn08743722009-12-21 12:16:51 -08003665 if (mKeyguard.showLw(true)) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003666 changes |= FINISH_LAYOUT_REDO_LAYOUT
3667 | FINISH_LAYOUT_REDO_CONFIG
3668 | FINISH_LAYOUT_REDO_WALLPAPER;
3669 }
Jim Miller5ecd8112013-01-09 18:50:26 -08003670 mKeyguardDelegate.setHidden(false);
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -07003671 }
3672 }
Joe Onorato664644d2011-01-23 17:53:23 -08003673
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003674 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003675 // If the navigation bar has been hidden or shown, we need to do another
3676 // layout pass to update that window.
3677 changes |= FINISH_LAYOUT_REDO_LAYOUT;
3678 }
Joe Onorato664644d2011-01-23 17:53:23 -08003679
Mike Lockwood28569302010-01-28 11:54:40 -05003680 // update since mAllowLockscreenWhenOn might have changed
3681 updateLockScreenTimeout();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003682 return changes;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003683 }
3684
Dianne Hackborn08743722009-12-21 12:16:51 -08003685 public boolean allowAppAnimationsLw() {
Craig Mautner58004432013-10-14 12:58:42 -07003686 if (mKeyguard != null && mKeyguard.isVisibleLw() && !mKeyguard.isAnimatingLw()
3687 || mShowingDream) {
Craig Mautner28816302013-10-10 20:31:00 -07003688 // If keyguard or dreams is currently visible, no reason to animate behind it.
Dianne Hackborn08743722009-12-21 12:16:51 -08003689 return false;
3690 }
Dianne Hackborn08743722009-12-21 12:16:51 -08003691 return true;
3692 }
3693
Dianne Hackborndf89e652011-10-06 22:35:11 -07003694 public int focusChangedLw(WindowState lastFocus, WindowState newFocus) {
Joe Onorato664644d2011-01-23 17:53:23 -08003695 mFocusedWindow = newFocus;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003696 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003697 // If the navigation bar has been hidden or shown, we need to do another
3698 // layout pass to update that window.
3699 return FINISH_LAYOUT_REDO_LAYOUT;
3700 }
3701 return 0;
Joe Onorato664644d2011-01-23 17:53:23 -08003702 }
3703
Dianne Hackborn0ecadf72009-03-31 18:00:37 -07003704 /** {@inheritDoc} */
Jeff Brown46b9ac02010-04-22 18:58:52 -07003705 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
3706 // lid changed state
Jeff Brownc458ce92012-04-30 14:58:40 -07003707 final int newLidState = lidOpen ? LID_OPEN : LID_CLOSED;
3708 if (newLidState == mLidState) {
3709 return;
3710 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07003711
Jeff Brownc458ce92012-04-30 14:58:40 -07003712 mLidState = newLidState;
3713 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07003714 updateRotation(true);
Jeff Brownc458ce92012-04-30 14:58:40 -07003715
3716 if (lidOpen) {
Jim Millere51cf7ae2013-06-25 18:31:56 -07003717 mPowerManager.wakeUp(SystemClock.uptimeMillis());
Jeff Brownc458ce92012-04-30 14:58:40 -07003718 } else if (!mLidControlsSleep) {
Jeff Brown96307042012-07-27 15:51:34 -07003719 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
Jeff Brown46b9ac02010-04-22 18:58:52 -07003720 }
3721 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003722
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08003723 void setHdmiPlugged(boolean plugged) {
3724 if (mHdmiPlugged != plugged) {
3725 mHdmiPlugged = plugged;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003726 updateRotation(true, true);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08003727 Intent intent = new Intent(ACTION_HDMI_PLUGGED);
Joe Onoratodc100302011-01-11 17:07:41 -08003728 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08003729 intent.putExtra(EXTRA_HDMI_PLUGGED_STATE, plugged);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07003730 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08003731 }
3732 }
3733
Joe Onoratoea495d42011-04-06 11:41:11 -07003734 void initializeHdmiState() {
Joe Onorato7ba631f2011-05-04 15:28:00 -07003735 boolean plugged = false;
Joe Onoratoea495d42011-04-06 11:41:11 -07003736 // watch for HDMI plug messages if the hdmi switch exists
3737 if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) {
3738 mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi");
3739
Joe Onoratoea495d42011-04-06 11:41:11 -07003740 final String filename = "/sys/class/switch/hdmi/state";
3741 FileReader reader = null;
3742 try {
3743 reader = new FileReader(filename);
3744 char[] buf = new char[15];
3745 int n = reader.read(buf);
3746 if (n > 1) {
3747 plugged = 0 != Integer.parseInt(new String(buf, 0, n-1));
3748 }
3749 } catch (IOException ex) {
3750 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
3751 } catch (NumberFormatException ex) {
3752 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
3753 } finally {
3754 if (reader != null) {
3755 try {
3756 reader.close();
3757 } catch (IOException ex) {
3758 }
Joe Onoratodc100302011-01-11 17:07:41 -08003759 }
3760 }
3761 }
Joe Onorato7ba631f2011-05-04 15:28:00 -07003762 // This dance forces the code in setHdmiPlugged to run.
3763 // Always do this so the sticky intent is stuck (to false) if there is no hdmi.
3764 mHdmiPlugged = !plugged;
3765 setHdmiPlugged(!mHdmiPlugged);
Joe Onoratodc100302011-01-11 17:07:41 -08003766 }
3767
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003768 /**
Jean-Michel Trivifca1e602013-10-10 18:12:59 -07003769 * @return Whether music is being played right now "locally" (e.g. on the device's speakers
3770 * or wired headphones) or "remotely" (e.g. on a device using the Cast protocol and
3771 * controlled by this device, or through remote submix).
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003772 */
3773 boolean isMusicActive() {
Eric Laurent413cb9d2009-07-17 11:52:43 -07003774 final AudioManager am = (AudioManager)mContext.getSystemService(Context.AUDIO_SERVICE);
3775 if (am == null) {
3776 Log.w(TAG, "isMusicActive: couldn't get AudioManager reference");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003777 return false;
3778 }
Jean-Michel Trivifca1e602013-10-10 18:12:59 -07003779 return am.isLocalOrRemoteMusicActive();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003780 }
3781
3782 /**
3783 * Tell the audio service to adjust the volume appropriate to the event.
3784 * @param keycode
3785 */
Mike Lockwooda53e3812009-09-25 10:51:39 -04003786 void handleVolumeKey(int stream, int keycode) {
Jeff Brown4d396052010-10-29 21:50:21 -07003787 IAudioService audioService = getAudioService();
3788 if (audioService == null) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003789 return;
3790 }
3791 try {
Jean-Michel Trivifca1e602013-10-10 18:12:59 -07003792 // when audio is playing locally, we shouldn't have to hold a wake lock
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003793 // during the call, but we do it as a precaution for the rare possibility
Jean-Michel Trivifca1e602013-10-10 18:12:59 -07003794 // that the music stops right before we call this.
3795 // Otherwise we might also be in a remote playback case.
Jeff Brownb0418da2010-11-01 15:24:01 -07003796 // TODO: Actually handle MUTE.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003797 mBroadcastWakeLock.acquire();
Jean-Michel Trivifca1e602013-10-10 18:12:59 -07003798 if (stream == AudioSystem.STREAM_MUSIC) {
3799 audioService.adjustLocalOrRemoteStreamVolume(stream,
3800 keycode == KeyEvent.KEYCODE_VOLUME_UP
3801 ? AudioManager.ADJUST_RAISE
3802 : AudioManager.ADJUST_LOWER,
3803 mContext.getOpPackageName());
3804 } else {
3805 audioService.adjustStreamVolume(stream,
3806 keycode == KeyEvent.KEYCODE_VOLUME_UP
3807 ? AudioManager.ADJUST_RAISE
3808 : AudioManager.ADJUST_LOWER,
3809 0,
3810 mContext.getOpPackageName());
3811 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003812 } catch (RemoteException e) {
Jean-Michel Trivifca1e602013-10-10 18:12:59 -07003813 Log.w(TAG, "IAudioService.adjust*StreamVolume() threw RemoteException " + e);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003814 } finally {
3815 mBroadcastWakeLock.release();
3816 }
3817 }
Jeff Brown4d396052010-10-29 21:50:21 -07003818
Dianne Hackbornc0e3f242011-08-19 14:19:10 -07003819 final Object mScreenshotLock = new Object();
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07003820 ServiceConnection mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07003821
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003822 final Runnable mScreenshotTimeout = new Runnable() {
3823 @Override public void run() {
3824 synchronized (mScreenshotLock) {
3825 if (mScreenshotConnection != null) {
3826 mContext.unbindService(mScreenshotConnection);
3827 mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07003828 }
Winson Chung9112ec32011-06-27 13:15:32 -07003829 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003830 }
3831 };
3832
3833 // Assume this is called from the Handler thread.
3834 private void takeScreenshot() {
3835 synchronized (mScreenshotLock) {
3836 if (mScreenshotConnection != null) {
3837 return;
3838 }
3839 ComponentName cn = new ComponentName("com.android.systemui",
3840 "com.android.systemui.screenshot.TakeScreenshotService");
3841 Intent intent = new Intent();
3842 intent.setComponent(cn);
3843 ServiceConnection conn = new ServiceConnection() {
3844 @Override
3845 public void onServiceConnected(ComponentName name, IBinder service) {
3846 synchronized (mScreenshotLock) {
3847 if (mScreenshotConnection != this) {
3848 return;
3849 }
3850 Messenger messenger = new Messenger(service);
3851 Message msg = Message.obtain(null, 1);
3852 final ServiceConnection myConn = this;
3853 Handler h = new Handler(mHandler.getLooper()) {
3854 @Override
3855 public void handleMessage(Message msg) {
3856 synchronized (mScreenshotLock) {
3857 if (mScreenshotConnection == myConn) {
3858 mContext.unbindService(mScreenshotConnection);
3859 mScreenshotConnection = null;
3860 mHandler.removeCallbacks(mScreenshotTimeout);
3861 }
3862 }
3863 }
3864 };
3865 msg.replyTo = new Messenger(h);
Winson Chunga63bb842011-10-17 10:26:28 -07003866 msg.arg1 = msg.arg2 = 0;
3867 if (mStatusBar != null && mStatusBar.isVisibleLw())
3868 msg.arg1 = 1;
3869 if (mNavigationBar != null && mNavigationBar.isVisibleLw())
3870 msg.arg2 = 1;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003871 try {
3872 messenger.send(msg);
3873 } catch (RemoteException e) {
3874 }
3875 }
3876 }
3877 @Override
3878 public void onServiceDisconnected(ComponentName name) {}
3879 };
Amith Yamasani27b89e62013-01-16 12:30:11 -08003880 if (mContext.bindServiceAsUser(
3881 intent, conn, Context.BIND_AUTO_CREATE, UserHandle.CURRENT)) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003882 mScreenshotConnection = conn;
3883 mHandler.postDelayed(mScreenshotTimeout, 10000);
3884 }
3885 }
Winson Chung9112ec32011-06-27 13:15:32 -07003886 }
3887
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003888 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003889 @Override
Jeff Brown037c33e2014-04-09 00:31:55 -07003890 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) {
Jeff Brown96307042012-07-27 15:51:34 -07003891 if (!mSystemBooted) {
3892 // If we have not yet booted, don't let key events do anything.
3893 return 0;
3894 }
3895
Jeff Brown037c33e2014-04-09 00:31:55 -07003896 final boolean interactive = (policyFlags & FLAG_INTERACTIVE) != 0;
Jeff Brown1f245102010-11-18 20:53:46 -08003897 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
3898 final boolean canceled = event.isCanceled();
3899 final int keyCode = event.getKeyCode();
Jeff Browne20c9e02010-10-11 14:20:19 -07003900
Jeff Brown3122e442010-10-11 23:32:49 -07003901 final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0;
Jeff Brown3122e442010-10-11 23:32:49 -07003902
Mike Lockwoodc72b15f2009-11-28 20:58:22 -05003903 // If screen is off then we treat the case where the keyguard is open but hidden
3904 // the same as if it were open and in front.
3905 // This will prevent any keys other than the power button from waking the screen
3906 // when the keyguard is hidden by another activity.
Jim Miller5ecd8112013-01-09 18:50:26 -08003907 final boolean keyguardActive = (mKeyguardDelegate == null ? false :
Jeff Brown037c33e2014-04-09 00:31:55 -07003908 (interactive ?
Jim Miller5ecd8112013-01-09 18:50:26 -08003909 mKeyguardDelegate.isShowingAndNotHidden() :
3910 mKeyguardDelegate.isShowing()));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003911
Jeff Brown6212a492014-03-07 13:58:47 -08003912 if (keyCode == KeyEvent.KEYCODE_POWER
3913 || keyCode == KeyEvent.KEYCODE_SLEEP
3914 || keyCode == KeyEvent.KEYCODE_WAKEUP) {
Jeff Brown96307042012-07-27 15:51:34 -07003915 policyFlags |= WindowManagerPolicy.FLAG_WAKE;
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07003916 }
3917
Jeff Brown40013652012-05-16 21:22:36 -07003918 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003919 Log.d(TAG, "interceptKeyTq keycode=" + keyCode
Jeff Brown037c33e2014-04-09 00:31:55 -07003920 + " interactive=" + interactive + " keyguardActive=" + keyguardActive
Jeff Brown26875502014-01-30 21:47:47 -08003921 + " policyFlags=" + Integer.toHexString(policyFlags));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003922 }
3923
Jeff Brown037c33e2014-04-09 00:31:55 -07003924 // Basic policy based on interactive state.
Jeff Brown4d396052010-10-29 21:50:21 -07003925 int result;
Jeff Brown26875502014-01-30 21:47:47 -08003926 boolean isWakeKey = (policyFlags & (WindowManagerPolicy.FLAG_WAKE
3927 | WindowManagerPolicy.FLAG_WAKE_DROPPED)) != 0;
Jeff Brown037c33e2014-04-09 00:31:55 -07003928 if (interactive || (isInjected && !isWakeKey)) {
Jeff Brown4d396052010-10-29 21:50:21 -07003929 // When the screen is on or if the key is injected pass the key to the application.
3930 result = ACTION_PASS_TO_USER;
3931 } else {
3932 // When the screen is off and the key is not injected, determine whether
3933 // to wake the device but don't pass the key to the application.
3934 result = 0;
Jeff Brown26875502014-01-30 21:47:47 -08003935 if (isWakeKey && (!down || !isWakeKeyWhenScreenOff(keyCode))) {
3936 isWakeKey = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003937 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003938 }
3939
Justin Kohd378ad72013-04-01 12:18:26 -07003940 // If the key would be handled globally, just return the result, don't worry about special
3941 // key processing.
3942 if (mGlobalKeyManager.shouldHandleGlobalKey(keyCode, event)) {
3943 return result;
3944 }
3945
Jeff Brownbae8e772014-06-12 19:59:45 -07003946 boolean useHapticFeedback = down
3947 && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0
3948 && event.getRepeatCount() == 0;
3949
Jeff Brown4d396052010-10-29 21:50:21 -07003950 // Handle special keys.
3951 switch (keyCode) {
3952 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jeff Brownb0418da2010-11-01 15:24:01 -07003953 case KeyEvent.KEYCODE_VOLUME_UP:
3954 case KeyEvent.KEYCODE_VOLUME_MUTE: {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003955 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
3956 if (down) {
Jeff Brown037c33e2014-04-09 00:31:55 -07003957 if (interactive && !mVolumeDownKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003958 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
3959 mVolumeDownKeyTriggered = true;
3960 mVolumeDownKeyTime = event.getDownTime();
3961 mVolumeDownKeyConsumedByScreenshotChord = false;
3962 cancelPendingPowerKeyAction();
3963 interceptScreenshotChord();
3964 }
3965 } else {
3966 mVolumeDownKeyTriggered = false;
3967 cancelPendingScreenshotChordAction();
3968 }
3969 } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
3970 if (down) {
Jeff Brown037c33e2014-04-09 00:31:55 -07003971 if (interactive && !mVolumeUpKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003972 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
3973 mVolumeUpKeyTriggered = true;
3974 cancelPendingPowerKeyAction();
3975 cancelPendingScreenshotChordAction();
3976 }
3977 } else {
3978 mVolumeUpKeyTriggered = false;
3979 cancelPendingScreenshotChordAction();
3980 }
3981 }
Jeff Brown4d396052010-10-29 21:50:21 -07003982 if (down) {
3983 ITelephony telephonyService = getTelephonyService();
3984 if (telephonyService != null) {
3985 try {
3986 if (telephonyService.isRinging()) {
3987 // If an incoming call is ringing, either VOLUME key means
3988 // "silence ringer". We handle these keys here, rather than
3989 // in the InCallScreen, to make sure we'll respond to them
3990 // even if the InCallScreen hasn't come to the foreground yet.
3991 // Look for the DOWN event here, to agree with the "fallback"
3992 // behavior in the InCallScreen.
3993 Log.i(TAG, "interceptKeyBeforeQueueing:"
3994 + " VOLUME key-down while ringing: Silence ringer!");
3995
3996 // Silence the ringer. (It's safe to call this
3997 // even if the ringer has already been silenced.)
3998 telephonyService.silenceRinger();
3999
4000 // And *don't* pass this key thru to the current activity
4001 // (which is probably the InCallScreen.)
4002 result &= ~ACTION_PASS_TO_USER;
4003 break;
4004 }
4005 if (telephonyService.isOffhook()
4006 && (result & ACTION_PASS_TO_USER) == 0) {
4007 // If we are in call but we decided not to pass the key to
4008 // the application, handle the volume change here.
4009 handleVolumeKey(AudioManager.STREAM_VOICE_CALL, keyCode);
4010 break;
4011 }
4012 } catch (RemoteException ex) {
4013 Log.w(TAG, "ITelephony threw RemoteException", ex);
4014 }
4015 }
4016
4017 if (isMusicActive() && (result & ACTION_PASS_TO_USER) == 0) {
4018 // If music is playing but we decided not to pass the key to the
4019 // application, handle the volume change here.
4020 handleVolumeKey(AudioManager.STREAM_MUSIC, keyCode);
4021 break;
4022 }
4023 }
4024 break;
4025 }
4026
4027 case KeyEvent.KEYCODE_ENDCALL: {
4028 result &= ~ACTION_PASS_TO_USER;
4029 if (down) {
4030 ITelephony telephonyService = getTelephonyService();
4031 boolean hungUp = false;
4032 if (telephonyService != null) {
4033 try {
4034 hungUp = telephonyService.endCall();
4035 } catch (RemoteException ex) {
4036 Log.w(TAG, "ITelephony threw RemoteException", ex);
4037 }
4038 }
Jeff Brown037c33e2014-04-09 00:31:55 -07004039 interceptPowerKeyDown(!interactive || hungUp);
Jeff Brown4d396052010-10-29 21:50:21 -07004040 } else {
4041 if (interceptPowerKeyUp(canceled)) {
4042 if ((mEndcallBehavior
4043 & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) {
4044 if (goHome()) {
4045 break;
Dianne Hackborn0041e972009-07-24 17:14:43 -07004046 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004047 }
Jeff Brown4d396052010-10-29 21:50:21 -07004048 if ((mEndcallBehavior
4049 & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) {
Jeff Brown26875502014-01-30 21:47:47 -08004050 mPowerManager.goToSleep(event.getEventTime());
4051 isWakeKey = false;
Jeff Brown4d396052010-10-29 21:50:21 -07004052 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004053 }
Jeff Brown4d396052010-10-29 21:50:21 -07004054 }
4055 break;
4056 }
4057
4058 case KeyEvent.KEYCODE_POWER: {
4059 result &= ~ACTION_PASS_TO_USER;
4060 if (down) {
Jeff Brown037c33e2014-04-09 00:31:55 -07004061 mImmersiveModeConfirmation.onPowerKeyDown(interactive, event.getDownTime(),
John Spurlockf1a36642013-10-12 17:50:42 -04004062 isImmersiveMode(mLastSystemUiFlags));
Jeff Brown037c33e2014-04-09 00:31:55 -07004063 if (interactive && !mPowerKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004064 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
4065 mPowerKeyTriggered = true;
4066 mPowerKeyTime = event.getDownTime();
4067 interceptScreenshotChord();
Winson Chung9112ec32011-06-27 13:15:32 -07004068 }
Winson Chung9112ec32011-06-27 13:15:32 -07004069
Jeff Brown4d396052010-10-29 21:50:21 -07004070 ITelephony telephonyService = getTelephonyService();
4071 boolean hungUp = false;
4072 if (telephonyService != null) {
4073 try {
4074 if (telephonyService.isRinging()) {
4075 // Pressing Power while there's a ringing incoming
4076 // call should silence the ringer.
4077 telephonyService.silenceRinger();
4078 } else if ((mIncallPowerBehavior
4079 & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0
4080 && telephonyService.isOffhook()) {
4081 // Otherwise, if "Power button ends call" is enabled,
4082 // the Power button will hang up any current active call.
4083 hungUp = telephonyService.endCall();
4084 }
4085 } catch (RemoteException ex) {
4086 Log.w(TAG, "ITelephony threw RemoteException", ex);
4087 }
4088 }
Jeff Brown037c33e2014-04-09 00:31:55 -07004089 interceptPowerKeyDown(!interactive || hungUp
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004090 || mVolumeDownKeyTriggered || mVolumeUpKeyTriggered);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004091 } else {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004092 mPowerKeyTriggered = false;
4093 cancelPendingScreenshotChordAction();
4094 if (interceptPowerKeyUp(canceled || mPendingPowerKeyUpCanceled)) {
Jeff Brown6d8fd272014-05-20 21:24:38 -07004095 powerShortPress(event.getEventTime());
Jeff Brown26875502014-01-30 21:47:47 -08004096 isWakeKey = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004097 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004098 mPendingPowerKeyUpCanceled = false;
Jeff Brown4d396052010-10-29 21:50:21 -07004099 }
4100 break;
4101 }
4102
Jeff Brown6212a492014-03-07 13:58:47 -08004103 case KeyEvent.KEYCODE_SLEEP: {
4104 result &= ~ACTION_PASS_TO_USER;
Jeff Brownbae8e772014-06-12 19:59:45 -07004105 if (!mPowerManager.isInteractive()) {
4106 useHapticFeedback = false; // suppress feedback if already non-interactive
4107 }
Jeff Brown6212a492014-03-07 13:58:47 -08004108 mPowerManager.goToSleep(event.getEventTime());
4109 isWakeKey = false;
4110 break;
4111 }
4112
4113 case KeyEvent.KEYCODE_WAKEUP: {
4114 result &= ~ACTION_PASS_TO_USER;
4115 break;
4116 }
4117
Jeff Brown4d396052010-10-29 21:50:21 -07004118 case KeyEvent.KEYCODE_MEDIA_PLAY:
4119 case KeyEvent.KEYCODE_MEDIA_PAUSE:
4120 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
4121 if (down) {
4122 ITelephony telephonyService = getTelephonyService();
4123 if (telephonyService != null) {
4124 try {
4125 if (!telephonyService.isIdle()) {
4126 // Suppress PLAY/PAUSE toggle when phone is ringing or in-call
4127 // to avoid music playback.
4128 break;
4129 }
4130 } catch (RemoteException ex) {
4131 Log.w(TAG, "ITelephony threw RemoteException", ex);
Jeff Brown3122e442010-10-11 23:32:49 -07004132 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004133 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004134 }
Jeff Brown4d396052010-10-29 21:50:21 -07004135 case KeyEvent.KEYCODE_HEADSETHOOK:
4136 case KeyEvent.KEYCODE_MUTE:
4137 case KeyEvent.KEYCODE_MEDIA_STOP:
4138 case KeyEvent.KEYCODE_MEDIA_NEXT:
4139 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
4140 case KeyEvent.KEYCODE_MEDIA_REWIND:
4141 case KeyEvent.KEYCODE_MEDIA_RECORD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09004142 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
4143 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: {
Jeff Brown4d396052010-10-29 21:50:21 -07004144 if ((result & ACTION_PASS_TO_USER) == 0) {
4145 // Only do this if we would otherwise not pass it to the user. In that
4146 // case, the PhoneWindow class will do the same thing, except it will
4147 // only do it if the showing app doesn't process the key on its own.
Jeff Brown40013652012-05-16 21:22:36 -07004148 // Note that we need to make a copy of the key event here because the
4149 // original key event will be recycled when we return.
Jeff Brown4d396052010-10-29 21:50:21 -07004150 mBroadcastWakeLock.acquire();
Jeff Brown40013652012-05-16 21:22:36 -07004151 Message msg = mHandler.obtainMessage(MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK,
4152 new KeyEvent(event));
4153 msg.setAsynchronous(true);
4154 msg.sendToTarget();
Jeff Brown4d396052010-10-29 21:50:21 -07004155 }
4156 break;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004157 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004158
Jeff Brown4d396052010-10-29 21:50:21 -07004159 case KeyEvent.KEYCODE_CALL: {
4160 if (down) {
4161 ITelephony telephonyService = getTelephonyService();
4162 if (telephonyService != null) {
4163 try {
4164 if (telephonyService.isRinging()) {
4165 Log.i(TAG, "interceptKeyBeforeQueueing:"
4166 + " CALL key-down while ringing: Answer the call!");
4167 telephonyService.answerRingingCall();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004168
Jeff Brown4d396052010-10-29 21:50:21 -07004169 // And *don't* pass this key thru to the current activity
4170 // (which is presumably the InCallScreen.)
4171 result &= ~ACTION_PASS_TO_USER;
4172 }
4173 } catch (RemoteException ex) {
4174 Log.w(TAG, "ITelephony threw RemoteException", ex);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004175 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004176 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004177 }
Jeff Brown4d396052010-10-29 21:50:21 -07004178 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004179 }
4180 }
Jeff Brown26875502014-01-30 21:47:47 -08004181
Jeff Brownbae8e772014-06-12 19:59:45 -07004182 if (useHapticFeedback) {
4183 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
4184 }
4185
Jeff Brown26875502014-01-30 21:47:47 -08004186 if (isWakeKey) {
4187 mPowerManager.wakeUp(event.getEventTime());
4188 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004189 return result;
4190 }
4191
Jeff Brown1c2e4942012-11-06 16:32:01 -08004192 /**
4193 * When the screen is off we ignore some keys that might otherwise typically
4194 * be considered wake keys. We filter them out here.
4195 *
4196 * {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it
4197 * is always considered a wake key.
4198 */
4199 private boolean isWakeKeyWhenScreenOff(int keyCode) {
4200 switch (keyCode) {
4201 // ignore volume keys unless docked
4202 case KeyEvent.KEYCODE_VOLUME_UP:
4203 case KeyEvent.KEYCODE_VOLUME_DOWN:
4204 case KeyEvent.KEYCODE_VOLUME_MUTE:
4205 return mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED;
4206
4207 // ignore media and camera keys
4208 case KeyEvent.KEYCODE_MUTE:
4209 case KeyEvent.KEYCODE_HEADSETHOOK:
4210 case KeyEvent.KEYCODE_MEDIA_PLAY:
4211 case KeyEvent.KEYCODE_MEDIA_PAUSE:
4212 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
4213 case KeyEvent.KEYCODE_MEDIA_STOP:
4214 case KeyEvent.KEYCODE_MEDIA_NEXT:
4215 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
4216 case KeyEvent.KEYCODE_MEDIA_REWIND:
4217 case KeyEvent.KEYCODE_MEDIA_RECORD:
4218 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09004219 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK:
Jeff Brown1c2e4942012-11-06 16:32:01 -08004220 case KeyEvent.KEYCODE_CAMERA:
4221 return false;
4222 }
4223 return true;
4224 }
4225
4226
Jeff Brown56194eb2011-03-02 19:23:13 -08004227 /** {@inheritDoc} */
4228 @Override
Jeff Brown037c33e2014-04-09 00:31:55 -07004229 public int interceptWakeMotionBeforeQueueing(long whenNanos, int policyFlags) {
4230 // We already know this is a wake motion so just wake up.
4231 // Note that we would observe policyFlags containing
4232 // FLAG_WAKE and FLAG_INTERACTIVE here.
4233 mPowerManager.wakeUp(whenNanos / 1000000);
4234 return 0;
Jeff Brown56194eb2011-03-02 19:23:13 -08004235 }
4236
Jeff Brown40013652012-05-16 21:22:36 -07004237 void dispatchMediaKeyWithWakeLock(KeyEvent event) {
4238 if (DEBUG_INPUT) {
4239 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: " + event);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004240 }
4241
Jeff Brown40013652012-05-16 21:22:36 -07004242 if (mHavePendingMediaKeyRepeatWithWakeLock) {
4243 if (DEBUG_INPUT) {
4244 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: canceled repeat");
4245 }
4246
4247 mHandler.removeMessages(MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK);
4248 mHavePendingMediaKeyRepeatWithWakeLock = false;
4249 mBroadcastWakeLock.release(); // pending repeat was holding onto the wake lock
4250 }
4251
4252 dispatchMediaKeyWithWakeLockToAudioService(event);
4253
4254 if (event.getAction() == KeyEvent.ACTION_DOWN
4255 && event.getRepeatCount() == 0) {
4256 mHavePendingMediaKeyRepeatWithWakeLock = true;
4257
4258 Message msg = mHandler.obtainMessage(
4259 MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK, event);
4260 msg.setAsynchronous(true);
4261 mHandler.sendMessageDelayed(msg, ViewConfiguration.getKeyRepeatTimeout());
4262 } else {
4263 mBroadcastWakeLock.release();
4264 }
4265 }
4266
4267 void dispatchMediaKeyRepeatWithWakeLock(KeyEvent event) {
4268 mHavePendingMediaKeyRepeatWithWakeLock = false;
4269
4270 KeyEvent repeatEvent = KeyEvent.changeTimeRepeat(event,
4271 SystemClock.uptimeMillis(), 1, event.getFlags() | KeyEvent.FLAG_LONG_PRESS);
4272 if (DEBUG_INPUT) {
4273 Slog.d(TAG, "dispatchMediaKeyRepeatWithWakeLock: " + repeatEvent);
4274 }
4275
4276 dispatchMediaKeyWithWakeLockToAudioService(repeatEvent);
4277 mBroadcastWakeLock.release();
4278 }
4279
4280 void dispatchMediaKeyWithWakeLockToAudioService(KeyEvent event) {
4281 if (ActivityManagerNative.isSystemReady()) {
4282 IAudioService audioService = getAudioService();
4283 if (audioService != null) {
4284 try {
4285 audioService.dispatchMediaKeyEventUnderWakelock(event);
4286 } catch (RemoteException e) {
4287 Log.e(TAG, "dispatchMediaKeyEvent threw exception " + e);
Jean-Michel Trivic6802222012-04-30 11:15:03 -07004288 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004289 }
4290 }
4291 }
4292
Mike Lockwood1753f7f2009-08-24 14:49:07 -07004293 BroadcastReceiver mDockReceiver = new BroadcastReceiver() {
Craig Mautnereee29c42013-01-17 14:44:34 -08004294 @Override
Mike Lockwood1753f7f2009-08-24 14:49:07 -07004295 public void onReceive(Context context, Intent intent) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07004296 if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) {
4297 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
4298 Intent.EXTRA_DOCK_STATE_UNDOCKED);
Daniel Sandler6396c722013-04-16 20:19:09 -04004299 } else {
4300 try {
4301 IUiModeManager uiModeService = IUiModeManager.Stub.asInterface(
4302 ServiceManager.getService(Context.UI_MODE_SERVICE));
4303 mUiMode = uiModeService.getCurrentModeType();
4304 } catch (RemoteException e) {
4305 }
Dianne Hackborn80fa1662009-10-07 14:02:10 -07004306 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004307 updateRotation(true);
Craig Mautnereee29c42013-01-17 14:44:34 -08004308 synchronized (mLock) {
4309 updateOrientationListenerLp();
4310 }
Mike Lockwood1753f7f2009-08-24 14:49:07 -07004311 }
4312 };
4313
Jeff Brown6aaf2952012-10-05 16:01:08 -07004314 BroadcastReceiver mDreamReceiver = new BroadcastReceiver() {
4315 @Override
4316 public void onReceive(Context context, Intent intent) {
4317 if (Intent.ACTION_DREAMING_STARTED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004318 if (mKeyguardDelegate != null) {
4319 mKeyguardDelegate.onDreamingStarted();
Jeff Brown6aaf2952012-10-05 16:01:08 -07004320 }
4321 } else if (Intent.ACTION_DREAMING_STOPPED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004322 if (mKeyguardDelegate != null) {
4323 mKeyguardDelegate.onDreamingStopped();
Jeff Brown6aaf2952012-10-05 16:01:08 -07004324 }
4325 }
4326 }
4327 };
4328
Christopher Tate5e08af02012-09-21 17:17:22 -07004329 BroadcastReceiver mMultiuserReceiver = new BroadcastReceiver() {
4330 @Override
4331 public void onReceive(Context context, Intent intent) {
4332 if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) {
4333 // tickle the settings observer: this first ensures that we're
4334 // observing the relevant settings for the newly-active user,
4335 // and then updates our own bookkeeping based on the now-
4336 // current user.
4337 mSettingsObserver.onChange(false);
John Spurlockce479d82012-11-29 09:52:21 -05004338
4339 // force a re-application of focused window sysui visibility.
4340 // the window may never have been shown for this user
4341 // e.g. the keyguard when going through the new-user setup flow
John Spurlock04db1762013-05-13 12:46:41 -04004342 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
John Spurlockce479d82012-11-29 09:52:21 -05004343 mLastSystemUiFlags = 0;
4344 updateSystemUiVisibilityLw();
4345 }
Christopher Tate5e08af02012-09-21 17:17:22 -07004346 }
4347 }
4348 };
4349
John Spurlocke1f366f2013-08-05 12:22:40 -04004350 private void requestTransientBars(WindowState swipeTarget) {
John Spurlock04db1762013-05-13 12:46:41 -04004351 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
John Spurlock27735a42013-08-14 17:57:38 -04004352 boolean sb = mStatusBarController.checkShowTransientBarLw();
4353 boolean nb = mNavigationBarController.checkShowTransientBarLw();
John Spurlockad3e6cb2013-04-30 08:47:43 -04004354 if (sb || nb) {
John Spurlocke1f366f2013-08-05 12:22:40 -04004355 WindowState barTarget = sb ? mStatusBar : mNavigationBar;
4356 if (sb ^ nb && barTarget != swipeTarget) {
4357 if (DEBUG) Slog.d(TAG, "Not showing transient bar, wrong swipe target");
John Spurlockad3e6cb2013-04-30 08:47:43 -04004358 return;
4359 }
John Spurlock27735a42013-08-14 17:57:38 -04004360 if (sb) mStatusBarController.showTransient();
4361 if (nb) mNavigationBarController.showTransient();
John Spurlockf1a36642013-10-12 17:50:42 -04004362 mImmersiveModeConfirmation.confirmCurrentPrompt();
John Spurlockad3e6cb2013-04-30 08:47:43 -04004363 updateSystemUiVisibilityLw();
John Spurlock32beb2c2013-03-11 10:16:47 -04004364 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04004365 }
4366 }
4367
Jeff Brownc38c9be2012-10-04 13:16:19 -07004368 @Override
Jeff Brown140ffc72014-05-01 15:18:00 -07004369 public void goingToSleep(int why) {
Dianne Hackborn74489012009-03-24 20:50:09 -07004370 EventLog.writeEvent(70000, 0);
The Android Open Source Project0727d222009-03-11 12:11:58 -07004371 synchronized (mLock) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004372 mScreenOnEarly = false;
4373 mScreenOnFully = false;
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07004374 }
Jim Miller5ecd8112013-01-09 18:50:26 -08004375 if (mKeyguardDelegate != null) {
4376 mKeyguardDelegate.onScreenTurnedOff(why);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004377 }
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07004378 synchronized (mLock) {
The Android Open Source Project0727d222009-03-11 12:11:58 -07004379 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05004380 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07004381 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004382 }
4383
Jeff Brownc38c9be2012-10-04 13:16:19 -07004384 @Override
Jeff Brown140ffc72014-05-01 15:18:00 -07004385 public void wakingUp(final ScreenOnListener screenOnListener) {
Dianne Hackborn74489012009-03-24 20:50:09 -07004386 EventLog.writeEvent(70000, 1);
Craig Mautner228742d2014-05-31 15:13:37 -07004387 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turning on...",
4388 new RuntimeException("here").fillInStackTrace());
4389 mHandler.obtainMessage(MSG_WAKING_UP, screenOnListener).sendToTarget();
4390 }
4391
4392 // Called on the mHandler thread.
4393 private void handleWakingUp(final ScreenOnListener screenOnListener) {
4394 if (screenOnListener != null) {
4395 mScreenOnListeners.add(screenOnListener);
Dianne Hackborn40011092011-09-22 13:37:48 -07004396 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07004397
The Android Open Source Project0727d222009-03-11 12:11:58 -07004398 synchronized (mLock) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004399 mScreenOnEarly = true;
The Android Open Source Project0727d222009-03-11 12:11:58 -07004400 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05004401 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07004402 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07004403
Craig Mautner228742d2014-05-31 15:13:37 -07004404 mKeyguardDrawComplete = false;
4405 mWindowManagerDrawComplete = false;
Jim Miller5ecd8112013-01-09 18:50:26 -08004406 if (mKeyguardDelegate != null) {
Craig Mautner228742d2014-05-31 15:13:37 -07004407 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
4408 mHandler.sendEmptyMessageDelayed(MSG_KEYGUARD_DRAWN_TIMEOUT, 1000);
4409 mKeyguardDelegate.onScreenTurnedOn(mKeyguardDelegateCallback);
Jeff Brownc38c9be2012-10-04 13:16:19 -07004410 } else {
Craig Mautner228742d2014-05-31 15:13:37 -07004411 if (DEBUG_WAKEUP) Slog.d(TAG, "null mKeyguardDelegate: setting mKeyguardDrawComplete.");
4412 mKeyguardDrawComplete = true;
Jeff Brownc38c9be2012-10-04 13:16:19 -07004413 }
Craig Mautner228742d2014-05-31 15:13:37 -07004414 mWindowManagerInternal.waitForAllWindowsDrawn(mWindowManagerDrawCallback, 500);
Jeff Brownc38c9be2012-10-04 13:16:19 -07004415 }
4416
Craig Mautner228742d2014-05-31 15:13:37 -07004417 // Called on the mHandler thread.
4418 private void finishScreenTurningOn() {
4419 if (DEBUG_WAKEUP) Slog.d(TAG,
4420 "finishScreenTurningOn: mKeyguardDrawComplete=" + mKeyguardDrawComplete
4421 + " mWindowManagerDrawComplete=" + mWindowManagerDrawComplete);
4422 if (!mKeyguardDrawComplete || !mWindowManagerDrawComplete) {
4423 return;
Jeff Brownc38c9be2012-10-04 13:16:19 -07004424 }
4425
Jeff Brownc38c9be2012-10-04 13:16:19 -07004426 synchronized (mLock) {
4427 mScreenOnFully = true;
4428 }
4429
Jeff Brown4fc45272012-10-10 18:28:14 -07004430 try {
4431 mWindowManager.setEventDispatching(true);
4432 } catch (RemoteException unhandled) {
4433 }
4434
Craig Mautner228742d2014-05-31 15:13:37 -07004435 for (int i = mScreenOnListeners.size() - 1; i >=0; --i) {
4436 mScreenOnListeners.remove(i).onScreenOn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07004437 }
4438 }
4439
4440 @Override
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004441 public boolean isScreenOnEarly() {
4442 return mScreenOnEarly;
4443 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07004444
4445 @Override
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004446 public boolean isScreenOnFully() {
4447 return mScreenOnFully;
Dianne Hackborn08743722009-12-21 12:16:51 -08004448 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07004449
Dianne Hackborn08743722009-12-21 12:16:51 -08004450 /** {@inheritDoc} */
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004451 public void enableKeyguard(boolean enabled) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004452 if (mKeyguardDelegate != null) {
4453 mKeyguardDelegate.setKeyguardEnabled(enabled);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004454 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004455 }
4456
4457 /** {@inheritDoc} */
4458 public void exitKeyguardSecurely(OnKeyguardExitResult callback) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004459 if (mKeyguardDelegate != null) {
4460 mKeyguardDelegate.verifyUnlock(callback);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004461 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004462 }
4463
Mike Lockwoodf7913302009-11-28 22:27:10 -05004464 private boolean keyguardIsShowingTq() {
Jim Miller5ecd8112013-01-09 18:50:26 -08004465 if (mKeyguardDelegate == null) return false;
4466 return mKeyguardDelegate.isShowingAndNotHidden();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004467 }
4468
Mike Lockwood520d8bc2011-02-18 13:23:13 -05004469
4470 /** {@inheritDoc} */
4471 public boolean isKeyguardLocked() {
4472 return keyguardOn();
4473 }
4474
4475 /** {@inheritDoc} */
4476 public boolean isKeyguardSecure() {
Jim Miller5ecd8112013-01-09 18:50:26 -08004477 if (mKeyguardDelegate == null) return false;
4478 return mKeyguardDelegate.isSecure();
Mike Lockwood520d8bc2011-02-18 13:23:13 -05004479 }
4480
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004481 /** {@inheritDoc} */
4482 public boolean inKeyguardRestrictedKeyInputMode() {
Jim Miller5ecd8112013-01-09 18:50:26 -08004483 if (mKeyguardDelegate == null) return false;
4484 return mKeyguardDelegate.isInputRestricted();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004485 }
4486
Dianne Hackborn90c52de2011-09-23 12:57:44 -07004487 public void dismissKeyguardLw() {
Jim Miller195b5512013-02-28 03:35:57 -08004488 if (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()) {
Daniel Sandler1ce804392012-11-07 15:07:12 -05004489 mHandler.post(new Runnable() {
4490 public void run() {
Jim Miller5ecd8112013-01-09 18:50:26 -08004491 if (mKeyguardDelegate.isDismissable()) {
Daniel Sandler1ce804392012-11-07 15:07:12 -05004492 // Can we just finish the keyguard straight away?
Jim Miller5ecd8112013-01-09 18:50:26 -08004493 mKeyguardDelegate.keyguardDone(false, true);
Daniel Sandler1ce804392012-11-07 15:07:12 -05004494 } else {
4495 // ask the keyguard to prompt the user to authenticate if necessary
Jim Miller5ecd8112013-01-09 18:50:26 -08004496 mKeyguardDelegate.dismiss();
Dianne Hackborn90c52de2011-09-23 12:57:44 -07004497 }
Daniel Sandler1ce804392012-11-07 15:07:12 -05004498 }
4499 });
Dianne Hackborn90c52de2011-09-23 12:57:44 -07004500 }
4501 }
4502
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004503 void sendCloseSystemWindows() {
4504 sendCloseSystemWindows(mContext, null);
4505 }
4506
4507 void sendCloseSystemWindows(String reason) {
4508 sendCloseSystemWindows(mContext, reason);
4509 }
4510
4511 static void sendCloseSystemWindows(Context context, String reason) {
4512 if (ActivityManagerNative.isSystemReady()) {
Dianne Hackborn94a679d2009-07-28 17:51:07 -07004513 try {
4514 ActivityManagerNative.getDefault().closeSystemDialogs(reason);
4515 } catch (RemoteException e) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004516 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004517 }
4518 }
Mitsuru Oshima831d0d92009-06-16 18:27:18 -07004519
Jeff Brown01a98dd2011-09-20 15:08:29 -07004520 @Override
4521 public int rotationForOrientationLw(int orientation, int lastRotation) {
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05004522 if (false) {
4523 Slog.v(TAG, "rotationForOrientationLw(orient="
4524 + orientation + ", last=" + lastRotation
4525 + "); user=" + mUserRotation + " "
4526 + ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED)
4527 ? "USER_ROTATION_LOCKED" : "")
4528 );
4529 }
4530
Craig Mautner46ac6fa2013-08-01 10:06:34 -07004531 if (mForceDefaultOrientation) {
4532 return Surface.ROTATION_0;
4533 }
4534
The Android Open Source Project0727d222009-03-11 12:11:58 -07004535 synchronized (mLock) {
Jeff Brownc0347aa2011-09-23 17:26:09 -07004536 int sensorRotation = mOrientationListener.getProposedRotation(); // may be -1
4537 if (sensorRotation < 0) {
Jeff Brown0f862b42012-09-27 21:11:01 -07004538 sensorRotation = lastRotation;
Jeff Brownc0347aa2011-09-23 17:26:09 -07004539 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004540
Jeff Browndec6cf42011-11-15 14:08:20 -08004541 final int preferredRotation;
Jeff Brown2e7760e2012-04-11 15:14:55 -07004542 if (mLidState == LID_OPEN && mLidOpenRotation >= 0) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07004543 // Ignore sensor when lid switch is open and rotation is forced.
4544 preferredRotation = mLidOpenRotation;
4545 } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR
Jeff Brownc0347aa2011-09-23 17:26:09 -07004546 && (mCarDockEnablesAccelerometer || mCarDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07004547 // Ignore sensor when in car dock unless explicitly enabled.
4548 // This case can override the behavior of NOSENSOR, and can also
4549 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07004550 preferredRotation = mCarDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07004551 ? sensorRotation : mCarDockRotation;
Jeff Brown1a693182011-11-08 14:44:16 -08004552 } else if ((mDockMode == Intent.EXTRA_DOCK_STATE_DESK
4553 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
4554 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK)
Jeff Brownc0347aa2011-09-23 17:26:09 -07004555 && (mDeskDockEnablesAccelerometer || mDeskDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07004556 // Ignore sensor when in desk dock unless explicitly enabled.
4557 // This case can override the behavior of NOSENSOR, and can also
4558 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07004559 preferredRotation = mDeskDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07004560 ? sensorRotation : mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -07004561 } else if (mHdmiPlugged && mDemoHdmiRotationLock) {
4562 // Ignore sensor when plugged into HDMI when demo HDMI rotation lock enabled.
Jeff Browneb3e4b92011-12-06 19:54:24 -08004563 // Note that the dock orientation overrides the HDMI orientation.
Jeff Brownc82c89ed2013-04-17 17:18:15 -07004564 preferredRotation = mDemoHdmiRotation;
4565 } else if (mHdmiPlugged && mDockMode == Intent.EXTRA_DOCK_STATE_UNDOCKED
4566 && mUndockedHdmiRotation >= 0) {
4567 // Ignore sensor when plugged into HDMI and an undocked orientation has
4568 // been specified in the configuration (only for legacy devices without
4569 // full multi-display support).
4570 // Note that the dock orientation overrides the HDMI orientation.
4571 preferredRotation = mUndockedHdmiRotation;
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07004572 } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED) {
4573 // Application just wants to remain locked in the last rotation.
4574 preferredRotation = lastRotation;
Jeff Brownbcdfc622014-03-06 19:13:04 -08004575 } else if (!mSupportAutoRotation) {
4576 // If we don't support auto-rotation then bail out here and ignore
4577 // the sensor and any rotation lock settings.
4578 preferredRotation = -1;
Jeff Brown207673cd2012-06-05 17:47:11 -07004579 } else if ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE
Jeff Brown01a98dd2011-09-20 15:08:29 -07004580 && (orientation == ActivityInfo.SCREEN_ORIENTATION_USER
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07004581 || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
4582 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
4583 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
4584 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER))
Jeff Brown01a98dd2011-09-20 15:08:29 -07004585 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
4586 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
4587 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
4588 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) {
4589 // Otherwise, use sensor only if requested by the application or enabled
4590 // by default for USER or UNSPECIFIED modes. Does not apply to NOSENSOR.
Jeff Brownd3187e32011-09-21 19:26:44 -07004591 if (mAllowAllRotations < 0) {
4592 // Can't read this during init() because the context doesn't
4593 // have display metrics at that time so we cannot determine
4594 // tablet vs. phone then.
4595 mAllowAllRotations = mContext.getResources().getBoolean(
4596 com.android.internal.R.bool.config_allowAllRotations) ? 1 : 0;
4597 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004598 if (sensorRotation != Surface.ROTATION_180
Jeff Brownd3187e32011-09-21 19:26:44 -07004599 || mAllowAllRotations == 1
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07004600 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
4601 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07004602 preferredRotation = sensorRotation;
4603 } else {
4604 preferredRotation = lastRotation;
4605 }
Jeff Brown207673cd2012-06-05 17:47:11 -07004606 } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED
4607 && orientation != ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) {
4608 // Apply rotation lock. Does not apply to NOSENSOR.
4609 // The idea is that the user rotation expresses a weak preference for the direction
4610 // of gravity and as NOSENSOR is never affected by gravity, then neither should
4611 // NOSENSOR be affected by rotation lock (although it will be affected by docks).
Jeff Brown4dfce202011-10-05 12:00:10 -07004612 preferredRotation = mUserRotation;
Jeff Browndec6cf42011-11-15 14:08:20 -08004613 } else {
4614 // No overriding preference.
4615 // We will do exactly what the application asked us to do.
4616 preferredRotation = -1;
Jeff Brown01a98dd2011-09-20 15:08:29 -07004617 }
4618
Dianne Hackborne5439f22010-10-02 16:53:50 -07004619 switch (orientation) {
4620 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08004621 // Return portrait unless overridden.
4622 if (isAnyPortrait(preferredRotation)) {
4623 return preferredRotation;
4624 }
Dianne Hackborne5439f22010-10-02 16:53:50 -07004625 return mPortraitRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07004626
Jeff Brown01a98dd2011-09-20 15:08:29 -07004627 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08004628 // Return landscape unless overridden.
4629 if (isLandscapeOrSeascape(preferredRotation)) {
4630 return preferredRotation;
4631 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004632 return mLandscapeRotation;
4633
4634 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08004635 // Return reverse portrait unless overridden.
4636 if (isAnyPortrait(preferredRotation)) {
4637 return preferredRotation;
4638 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004639 return mUpsideDownRotation;
4640
4641 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08004642 // Return seascape unless overridden.
4643 if (isLandscapeOrSeascape(preferredRotation)) {
4644 return preferredRotation;
4645 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004646 return mSeascapeRotation;
4647
4648 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07004649 case ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE:
Jeff Brown01a98dd2011-09-20 15:08:29 -07004650 // Return either landscape rotation.
4651 if (isLandscapeOrSeascape(preferredRotation)) {
4652 return preferredRotation;
4653 }
4654 if (isLandscapeOrSeascape(lastRotation)) {
Jeff Brown4519f072011-01-23 13:16:01 -08004655 return lastRotation;
4656 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004657 return mLandscapeRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004658
Jeff Brown01a98dd2011-09-20 15:08:29 -07004659 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07004660 case ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT:
Jeff Brown01a98dd2011-09-20 15:08:29 -07004661 // Return either portrait rotation.
4662 if (isAnyPortrait(preferredRotation)) {
4663 return preferredRotation;
4664 }
4665 if (isAnyPortrait(lastRotation)) {
4666 return lastRotation;
4667 }
4668 return mPortraitRotation;
4669
4670 default:
Jeff Brown4dfce202011-10-05 12:00:10 -07004671 // For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR,
4672 // just return the preferred orientation we already calculated.
Jeff Brown01a98dd2011-09-20 15:08:29 -07004673 if (preferredRotation >= 0) {
4674 return preferredRotation;
4675 }
Dianne Hackborndacea8c2011-04-21 17:26:39 -07004676 return Surface.ROTATION_0;
Daniel Sandlere7e5ac22011-02-22 16:10:21 -05004677 }
4678 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07004679 }
4680
Jeff Brown01a98dd2011-09-20 15:08:29 -07004681 @Override
4682 public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation) {
4683 switch (orientation) {
4684 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
4685 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
4686 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
4687 return isAnyPortrait(rotation);
4688
4689 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
4690 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
4691 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
4692 return isLandscapeOrSeascape(rotation);
4693
4694 default:
4695 return true;
4696 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07004697 }
4698
Jeff Brownc0347aa2011-09-23 17:26:09 -07004699 @Override
4700 public void setRotationLw(int rotation) {
4701 mOrientationListener.setCurrentRotation(rotation);
4702 }
4703
Jeff Brown01a98dd2011-09-20 15:08:29 -07004704 private boolean isLandscapeOrSeascape(int rotation) {
4705 return rotation == mLandscapeRotation || rotation == mSeascapeRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07004706 }
4707
Jeff Brown01a98dd2011-09-20 15:08:29 -07004708 private boolean isAnyPortrait(int rotation) {
4709 return rotation == mPortraitRotation || rotation == mUpsideDownRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07004710 }
4711
Svetoslav Ganov80943d82013-01-02 10:25:37 -08004712 public int getUserRotationMode() {
4713 return Settings.System.getIntForUser(mContext.getContentResolver(),
Brett Chabot7e55c402013-05-16 19:38:08 -07004714 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
4715 WindowManagerPolicy.USER_ROTATION_FREE :
4716 WindowManagerPolicy.USER_ROTATION_LOCKED;
Svetoslav Ganov80943d82013-01-02 10:25:37 -08004717 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004718
4719 // User rotation: to be used when all else fails in assigning an orientation to the device
4720 public void setUserRotationMode(int mode, int rot) {
4721 ContentResolver res = mContext.getContentResolver();
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05004722
4723 // mUserRotationMode and mUserRotation will be assigned by the content observer
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004724 if (mode == WindowManagerPolicy.USER_ROTATION_LOCKED) {
Christopher Tate5e08af02012-09-21 17:17:22 -07004725 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004726 Settings.System.USER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07004727 rot,
4728 UserHandle.USER_CURRENT);
4729 Settings.System.putIntForUser(res,
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05004730 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07004731 0,
4732 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004733 } else {
Christopher Tate5e08af02012-09-21 17:17:22 -07004734 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004735 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07004736 1,
4737 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004738 }
4739 }
4740
Jeff Brownac143512012-04-05 18:57:33 -07004741 public void setSafeMode(boolean safeMode) {
4742 mSafeMode = safeMode;
4743 performHapticFeedbackLw(null, safeMode
4744 ? HapticFeedbackConstants.SAFE_MODE_ENABLED
4745 : HapticFeedbackConstants.SAFE_MODE_DISABLED, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004746 }
Craig Mautnereda67292013-04-28 13:50:14 -07004747
Dianne Hackborn181ceb52009-08-27 22:16:40 -07004748 static long[] getLongIntArray(Resources r, int resid) {
4749 int[] ar = r.getIntArray(resid);
4750 if (ar == null) {
4751 return null;
4752 }
4753 long[] out = new long[ar.length];
4754 for (int i=0; i<ar.length; i++) {
4755 out[i] = ar[i];
4756 }
4757 return out;
4758 }
Craig Mautnereda67292013-04-28 13:50:14 -07004759
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004760 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07004761 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004762 public void systemReady() {
Mike Lockwoode63f6f72013-11-15 11:01:47 -08004763 mKeyguardDelegate = new KeyguardServiceDelegate(mContext, null);
4764 mKeyguardDelegate.onSystemReady();
4765
Jeff Brown4f5fa282014-06-12 19:19:15 -07004766 updateUiMode();
Dianne Hackbornb1a79802009-09-29 15:18:31 -07004767 synchronized (mLock) {
4768 updateOrientationListenerLp();
Dianne Hackbornc777e072010-02-12 13:07:59 -08004769 mSystemReady = true;
4770 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07004771 @Override
Dianne Hackbornc777e072010-02-12 13:07:59 -08004772 public void run() {
4773 updateSettings();
4774 }
4775 });
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004776 }
4777 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07004778
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07004779 /** {@inheritDoc} */
4780 public void systemBooted() {
Jim Millere5f910a2013-10-16 18:15:46 -07004781 if (mKeyguardDelegate != null) {
4782 mKeyguardDelegate.onBootCompleted();
4783 }
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07004784 synchronized (mLock) {
4785 mSystemBooted = true;
4786 }
4787 }
4788
Dianne Hackborn661cd522011-08-22 00:26:20 -07004789 ProgressDialog mBootMsgDialog = null;
4790
4791 /** {@inheritDoc} */
4792 public void showBootMessage(final CharSequence msg, final boolean always) {
4793 mHandler.post(new Runnable() {
4794 @Override public void run() {
4795 if (mBootMsgDialog == null) {
Vinod Krishnanfa8fc412014-04-18 14:35:53 -07004796 int theme = mContext.getPackageManager().hasSystemFeature(
4797 PackageManager.FEATURE_WATCH) ?
4798 com.android.internal.R.style.Theme_Micro_Dialog_Alert : 0;
4799
4800 mBootMsgDialog = new ProgressDialog(mContext, theme) {
Dianne Hackborn295e3c22011-08-25 13:19:08 -07004801 // This dialog will consume all events coming in to
4802 // it, to avoid it trying to do things too early in boot.
4803 @Override public boolean dispatchKeyEvent(KeyEvent event) {
4804 return true;
4805 }
4806 @Override public boolean dispatchKeyShortcutEvent(KeyEvent event) {
4807 return true;
4808 }
4809 @Override public boolean dispatchTouchEvent(MotionEvent ev) {
4810 return true;
4811 }
4812 @Override public boolean dispatchTrackballEvent(MotionEvent ev) {
4813 return true;
4814 }
4815 @Override public boolean dispatchGenericMotionEvent(MotionEvent ev) {
4816 return true;
4817 }
4818 @Override public boolean dispatchPopulateAccessibilityEvent(
4819 AccessibilityEvent event) {
4820 return true;
4821 }
4822 };
Dianne Hackborn661cd522011-08-22 00:26:20 -07004823 mBootMsgDialog.setTitle(R.string.android_upgrading_title);
4824 mBootMsgDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
4825 mBootMsgDialog.setIndeterminate(true);
4826 mBootMsgDialog.getWindow().setType(
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07004827 WindowManager.LayoutParams.TYPE_BOOT_PROGRESS);
Dianne Hackborn661cd522011-08-22 00:26:20 -07004828 mBootMsgDialog.getWindow().addFlags(
4829 WindowManager.LayoutParams.FLAG_DIM_BEHIND
4830 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
4831 mBootMsgDialog.getWindow().setDimAmount(1);
Dianne Hackbornd9efb952011-12-07 14:56:51 -08004832 WindowManager.LayoutParams lp = mBootMsgDialog.getWindow().getAttributes();
4833 lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
4834 mBootMsgDialog.getWindow().setAttributes(lp);
Dianne Hackborn661cd522011-08-22 00:26:20 -07004835 mBootMsgDialog.setCancelable(false);
4836 mBootMsgDialog.show();
4837 }
4838 mBootMsgDialog.setMessage(msg);
4839 }
4840 });
4841 }
4842
4843 /** {@inheritDoc} */
4844 public void hideBootMessages() {
4845 mHandler.post(new Runnable() {
4846 @Override public void run() {
4847 if (mBootMsgDialog != null) {
4848 mBootMsgDialog.dismiss();
4849 mBootMsgDialog = null;
4850 }
4851 }
4852 });
4853 }
4854
Mike Lockwood28569302010-01-28 11:54:40 -05004855 /** {@inheritDoc} */
4856 public void userActivity() {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004857 // ***************************************
4858 // NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
4859 // ***************************************
4860 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
4861 // WITH ITS LOCKS HELD.
4862 //
4863 // This code must be VERY careful about the locks
4864 // it acquires.
4865 // In fact, the current code acquires way too many,
4866 // and probably has lurking deadlocks.
4867
Mike Lockwood28569302010-01-28 11:54:40 -05004868 synchronized (mScreenLockTimeout) {
4869 if (mLockScreenTimerActive) {
4870 // reset the timer
4871 mHandler.removeCallbacks(mScreenLockTimeout);
4872 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
4873 }
4874 }
Daniel Sandler0601eb72011-04-13 01:01:32 -04004875 }
4876
Adam Cohenf7522022012-10-03 20:03:18 -07004877 class ScreenLockTimeout implements Runnable {
4878 Bundle options;
4879
4880 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05004881 public void run() {
4882 synchronized (this) {
4883 if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard");
Jim Miller5ecd8112013-01-09 18:50:26 -08004884 if (mKeyguardDelegate != null) {
4885 mKeyguardDelegate.doKeyguardTimeout(options);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004886 }
Mike Lockwood28569302010-01-28 11:54:40 -05004887 mLockScreenTimerActive = false;
Adam Cohenf7522022012-10-03 20:03:18 -07004888 options = null;
Mike Lockwood28569302010-01-28 11:54:40 -05004889 }
4890 }
Mike Lockwood28569302010-01-28 11:54:40 -05004891
Adam Cohenf7522022012-10-03 20:03:18 -07004892 public void setLockOptions(Bundle options) {
4893 this.options = options;
4894 }
4895 }
4896
4897 ScreenLockTimeout mScreenLockTimeout = new ScreenLockTimeout();
4898
4899 public void lockNow(Bundle options) {
Jim Miller93c518e2012-01-17 15:55:31 -08004900 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null);
4901 mHandler.removeCallbacks(mScreenLockTimeout);
Adam Cohenf7522022012-10-03 20:03:18 -07004902 if (options != null) {
4903 // In case multiple calls are made to lockNow, we don't wipe out the options
4904 // until the runnable actually executes.
4905 mScreenLockTimeout.setLockOptions(options);
4906 }
Jim Miller93c518e2012-01-17 15:55:31 -08004907 mHandler.post(mScreenLockTimeout);
4908 }
4909
Mike Lockwood28569302010-01-28 11:54:40 -05004910 private void updateLockScreenTimeout() {
4911 synchronized (mScreenLockTimeout) {
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004912 boolean enable = (mAllowLockscreenWhenOn && mScreenOnEarly &&
Jim Miller5ecd8112013-01-09 18:50:26 -08004913 mKeyguardDelegate != null && mKeyguardDelegate.isSecure());
Mike Lockwood28569302010-01-28 11:54:40 -05004914 if (mLockScreenTimerActive != enable) {
4915 if (enable) {
4916 if (localLOGV) Log.v(TAG, "setting lockscreen timer");
4917 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
4918 } else {
4919 if (localLOGV) Log.v(TAG, "clearing lockscreen timer");
4920 mHandler.removeCallbacks(mScreenLockTimeout);
4921 }
4922 mLockScreenTimerActive = enable;
4923 }
4924 }
4925 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004926
4927 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07004928 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004929 public void enableScreenAfterBoot() {
4930 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07004931 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07004932 updateRotation(true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004933 }
Dianne Hackbornf54c8f92009-09-19 14:03:57 -07004934
Jeff Brownc458ce92012-04-30 14:58:40 -07004935 private void applyLidSwitchState() {
Jeff Brownc458ce92012-04-30 14:58:40 -07004936 if (mLidState == LID_CLOSED && mLidControlsSleep) {
Jeff Brown6d8fd272014-05-20 21:24:38 -07004937 mPowerManager.goToSleep(SystemClock.uptimeMillis(),
4938 PowerManager.GO_TO_SLEEP_REASON_USER,
4939 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
Jeff Brownc458ce92012-04-30 14:58:40 -07004940 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004941 }
4942
Jeff Brown4f5fa282014-06-12 19:19:15 -07004943 void updateUiMode() {
4944 if (mUiModeManager == null) {
4945 mUiModeManager = IUiModeManager.Stub.asInterface(
4946 ServiceManager.getService(Context.UI_MODE_SERVICE));
4947 }
4948 try {
4949 mUiMode = mUiModeManager.getCurrentModeType();
4950 } catch (RemoteException e) {
4951 }
4952 }
4953
Jeff Brown01a98dd2011-09-20 15:08:29 -07004954 void updateRotation(boolean alwaysSendConfiguration) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004955 try {
4956 //set orientation on WindowManager
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004957 mWindowManager.updateRotation(alwaysSendConfiguration, false);
4958 } catch (RemoteException e) {
4959 // Ignore
4960 }
4961 }
4962
4963 void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) {
4964 try {
4965 //set orientation on WindowManager
4966 mWindowManager.updateRotation(alwaysSendConfiguration, forceRelayout);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004967 } catch (RemoteException e) {
4968 // Ignore
4969 }
4970 }
4971
Daniel Sandler6396c722013-04-16 20:19:09 -04004972 /**
4973 * Return an Intent to launch the currently active dock app as home. Returns
4974 * null if the standard home should be launched, which is the case if any of the following is
4975 * true:
4976 * <ul>
4977 * <li>The device is not in either car mode or desk mode
4978 * <li>The device is in car mode but ENABLE_CAR_DOCK_HOME_CAPTURE is false
4979 * <li>The device is in desk mode but ENABLE_DESK_DOCK_HOME_CAPTURE is false
4980 * <li>The device is in car mode but there's no CAR_DOCK app with METADATA_DOCK_HOME
4981 * <li>The device is in desk mode but there's no DESK_DOCK app with METADATA_DOCK_HOME
4982 * </ul>
Craig Mautnereda67292013-04-28 13:50:14 -07004983 * @return A dock intent.
Daniel Sandler6396c722013-04-16 20:19:09 -04004984 */
4985 Intent createHomeDockIntent() {
4986 Intent intent = null;
4987
4988 // What home does is based on the mode, not the dock state. That
4989 // is, when in car mode you should be taken to car home regardless
4990 // of whether we are actually in a car dock.
4991 if (mUiMode == Configuration.UI_MODE_TYPE_CAR) {
4992 if (ENABLE_CAR_DOCK_HOME_CAPTURE) {
4993 intent = mCarDockIntent;
4994 }
4995 } else if (mUiMode == Configuration.UI_MODE_TYPE_DESK) {
4996 if (ENABLE_DESK_DOCK_HOME_CAPTURE) {
4997 intent = mDeskDockIntent;
4998 }
Jeff Brown4f5fa282014-06-12 19:19:15 -07004999 } else if (mUiMode == Configuration.UI_MODE_TYPE_WATCH
5000 && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
5001 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK
5002 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK)) {
5003 // Always launch dock home from home when watch is docked, if it exists.
5004 intent = mDeskDockIntent;
Daniel Sandler6396c722013-04-16 20:19:09 -04005005 }
5006
5007 if (intent == null) {
5008 return null;
5009 }
5010
5011 ActivityInfo ai = null;
5012 ResolveInfo info = mContext.getPackageManager().resolveActivityAsUser(
5013 intent,
John Spurlockf56bef12013-07-09 09:51:46 -04005014 PackageManager.MATCH_DEFAULT_ONLY | PackageManager.GET_META_DATA,
Craig Mautnerd625ab22013-09-06 13:40:31 -07005015 mCurrentUserId);
Daniel Sandler6396c722013-04-16 20:19:09 -04005016 if (info != null) {
5017 ai = info.activityInfo;
5018 }
5019 if (ai != null
5020 && ai.metaData != null
5021 && ai.metaData.getBoolean(Intent.METADATA_DOCK_HOME)) {
5022 intent = new Intent(intent);
5023 intent.setClassName(ai.packageName, ai.name);
5024 return intent;
5025 }
5026
5027 return null;
5028 }
5029
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005030 void startDockOrHome() {
John Spurlockc8b46ca2013-04-08 12:59:26 -04005031 awakenDreams();
Daniel Sandler6396c722013-04-16 20:19:09 -04005032
5033 Intent dock = createHomeDockIntent();
5034 if (dock != null) {
5035 try {
5036 mContext.startActivityAsUser(dock, UserHandle.CURRENT);
5037 return;
5038 } catch (ActivityNotFoundException e) {
5039 }
5040 }
5041
Dianne Hackbornd8883992012-09-07 15:58:52 -07005042 mContext.startActivityAsUser(mHomeIntent, UserHandle.CURRENT);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005043 }
Craig Mautnereda67292013-04-28 13:50:14 -07005044
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005045 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005046 * goes to the home screen
5047 * @return whether it did anything
5048 */
5049 boolean goHome() {
5050 if (false) {
5051 // This code always brings home to the front.
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07005052 try {
5053 ActivityManagerNative.getDefault().stopAppSwitches();
5054 } catch (RemoteException e) {
5055 }
Dianne Hackborn94a679d2009-07-28 17:51:07 -07005056 sendCloseSystemWindows();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005057 startDockOrHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005058 } else {
5059 // This code brings home to the front or, if it is already
5060 // at the front, puts the device to sleep.
5061 try {
Wink Savilled2e6a332010-02-12 12:12:06 -08005062 if (SystemProperties.getInt("persist.sys.uts-test-mode", 0) == 1) {
5063 /// Roll back EndcallBehavior as the cupcake design to pass P1 lab entry.
5064 Log.d(TAG, "UTS-TEST-MODE");
5065 } else {
5066 ActivityManagerNative.getDefault().stopAppSwitches();
5067 sendCloseSystemWindows();
Daniel Sandler6396c722013-04-16 20:19:09 -04005068 Intent dock = createHomeDockIntent();
5069 if (dock != null) {
5070 int result = ActivityManagerNative.getDefault()
5071 .startActivityAsUser(null, null, dock,
5072 dock.resolveTypeIfNeeded(mContext.getContentResolver()),
5073 null, null, 0,
5074 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
5075 null, null, null, UserHandle.USER_CURRENT);
5076 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
5077 return false;
5078 }
5079 }
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005080 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005081 int result = ActivityManagerNative.getDefault()
Dianne Hackbornf265ea92013-01-31 15:00:51 -08005082 .startActivityAsUser(null, null, mHomeIntent,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005083 mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()),
Dianne Hackborna4972e92012-03-14 10:38:05 -07005084 null, null, 0,
5085 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Dianne Hackborn5e03e2c2012-09-06 14:21:19 -07005086 null, null, null, UserHandle.USER_CURRENT);
Dianne Hackborna4972e92012-03-14 10:38:05 -07005087 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005088 return false;
5089 }
5090 } catch (RemoteException ex) {
5091 // bummer, the activity manager, which is in this process, is dead
5092 }
5093 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005094 return true;
5095 }
Craig Mautnereda67292013-04-28 13:50:14 -07005096
5097 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07005098 public void setCurrentOrientationLw(int newOrientation) {
5099 synchronized (mLock) {
5100 if (newOrientation != mCurrentAppOrientation) {
5101 mCurrentAppOrientation = newOrientation;
5102 updateOrientationListenerLp();
5103 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005104 }
5105 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08005106
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07005107 private void performAuditoryFeedbackForAccessibilityIfNeed() {
5108 if (!isGlobalAccessibilityGestureEnabled()) {
5109 return;
5110 }
5111 AudioManager audioManager = (AudioManager) mContext.getSystemService(
5112 Context.AUDIO_SERVICE);
5113 if (audioManager.isSilentMode()) {
5114 return;
5115 }
5116 Ringtone ringTone = RingtoneManager.getRingtone(mContext,
5117 Settings.System.DEFAULT_NOTIFICATION_URI);
5118 ringTone.setStreamType(AudioManager.STREAM_MUSIC);
5119 ringTone.play();
5120 }
Craig Mautnereda67292013-04-28 13:50:14 -07005121
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07005122 private boolean isGlobalAccessibilityGestureEnabled() {
5123 return Settings.Global.getInt(mContext.getContentResolver(),
5124 Settings.Global.ENABLE_ACCESSIBILITY_GLOBAL_GESTURE_ENABLED, 0) == 1;
5125 }
5126
Craig Mautnereda67292013-04-28 13:50:14 -07005127 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07005128 public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) {
Svetoslav Ganov96179212012-10-10 14:17:45 -07005129 if (!mVibrator.hasVibrator()) {
5130 return false;
5131 }
Christopher Tate5e08af02012-09-21 17:17:22 -07005132 final boolean hapticsDisabled = Settings.System.getIntForUser(mContext.getContentResolver(),
5133 Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) == 0;
Jim Miller5ecd8112013-01-09 18:50:26 -08005134 if (!always && (hapticsDisabled || mKeyguardDelegate.isShowingAndNotHidden())) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005135 return false;
5136 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08005137 long[] pattern = null;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005138 switch (effectId) {
5139 case HapticFeedbackConstants.LONG_PRESS:
Amith Yamasanic33cb712010-02-10 15:21:49 -08005140 pattern = mLongPressVibePattern;
5141 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07005142 case HapticFeedbackConstants.VIRTUAL_KEY:
Amith Yamasanic33cb712010-02-10 15:21:49 -08005143 pattern = mVirtualKeyVibePattern;
5144 break;
5145 case HapticFeedbackConstants.KEYBOARD_TAP:
5146 pattern = mKeyboardTapVibePattern;
5147 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07005148 case HapticFeedbackConstants.SAFE_MODE_DISABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08005149 pattern = mSafeModeDisabledVibePattern;
5150 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07005151 case HapticFeedbackConstants.SAFE_MODE_ENABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08005152 pattern = mSafeModeEnabledVibePattern;
5153 break;
Amith Yamasanic33cb712010-02-10 15:21:49 -08005154 default:
5155 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005156 }
Dianne Hackbornf265ea92013-01-31 15:00:51 -08005157 int owningUid;
5158 String owningPackage;
5159 if (win != null) {
5160 owningUid = win.getOwningUid();
5161 owningPackage = win.getOwningPackage();
5162 } else {
5163 owningUid = android.os.Process.myUid();
Dianne Hackborn95d78532013-09-11 09:51:14 -07005164 owningPackage = mContext.getOpPackageName();
Dianne Hackbornf265ea92013-01-31 15:00:51 -08005165 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08005166 if (pattern.length == 1) {
5167 // One-shot vibration
Dianne Hackbornf265ea92013-01-31 15:00:51 -08005168 mVibrator.vibrate(owningUid, owningPackage, pattern[0]);
Amith Yamasanic33cb712010-02-10 15:21:49 -08005169 } else {
5170 // Pattern vibration
Dianne Hackbornf265ea92013-01-31 15:00:51 -08005171 mVibrator.vibrate(owningUid, owningPackage, pattern, -1);
Amith Yamasanic33cb712010-02-10 15:21:49 -08005172 }
5173 return true;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005174 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005175
5176 @Override
5177 public void keepScreenOnStartedLw() {
Daniel Sandler0601eb72011-04-13 01:01:32 -04005178 }
5179
Jeff Brownc38c9be2012-10-04 13:16:19 -07005180 @Override
5181 public void keepScreenOnStoppedLw() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005182 if (mKeyguardDelegate != null && !mKeyguardDelegate.isShowingAndNotHidden()) {
Jeff Brownc38c9be2012-10-04 13:16:19 -07005183 long curTime = SystemClock.uptimeMillis();
Jim Miller25190572013-02-28 17:36:24 -08005184 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005185 }
5186 }
Mike Lockwoodfcb39242009-10-21 23:01:07 -04005187
Dianne Hackborndf89e652011-10-06 22:35:11 -07005188 private int updateSystemUiVisibilityLw() {
Joe Onorato664644d2011-01-23 17:53:23 -08005189 // If there is no window focused, there will be nobody to handle the events
5190 // anyway, so just hang on in whatever state we're in until things settle down.
John Spurlock79da8332013-09-20 12:04:47 -04005191 WindowState win = mFocusedWindow != null ? mFocusedWindow : mTopFullscreenOpaqueWindowState;
5192 if (win == null) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07005193 return 0;
5194 }
John Spurlock79da8332013-09-20 12:04:47 -04005195 if (win.getAttrs().type == TYPE_KEYGUARD && mHideLockScreen == true) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07005196 // We are updating at a point where the keyguard has gotten
5197 // focus, but we were last in a state where the top window is
5198 // hiding it. This is probably because the keyguard as been
5199 // shown while the top window was displayed, so we want to ignore
5200 // it here because this is just a very transient change and it
5201 // will quickly lose focus once it correctly gets hidden.
5202 return 0;
5203 }
John Spurlock32beb2c2013-03-11 10:16:47 -04005204
John Spurlock79da8332013-09-20 12:04:47 -04005205 int tmpVisibility = win.getSystemUiVisibility()
Dianne Hackborne26ab702011-10-16 13:21:33 -07005206 & ~mResettingSystemUiFlags
5207 & ~mForceClearedSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04005208 if (mForcingShowNavBar && win.getSurfaceLayer() < mForcingShowNavBarLayer) {
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08005209 tmpVisibility &= ~View.SYSTEM_UI_CLEARABLE_FLAGS;
5210 }
John Spurlock79da8332013-09-20 12:04:47 -04005211 final int visibility = updateSystemBarsLw(win, mLastSystemUiFlags, tmpVisibility);
John Spurlockad3e6cb2013-04-30 08:47:43 -04005212 final int diff = visibility ^ mLastSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04005213 final boolean needsMenu = win.getNeedsMenuLw(mTopFullscreenOpaqueWindowState);
Dianne Hackborne0f085d2011-11-30 18:41:15 -08005214 if (diff == 0 && mLastFocusNeedsMenu == needsMenu
John Spurlock79da8332013-09-20 12:04:47 -04005215 && mFocusedApp == win.getAppToken()) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07005216 return 0;
5217 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07005218 mLastSystemUiFlags = visibility;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08005219 mLastFocusNeedsMenu = needsMenu;
John Spurlock79da8332013-09-20 12:04:47 -04005220 mFocusedApp = win.getAppToken();
Dianne Hackborndf89e652011-10-06 22:35:11 -07005221 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07005222 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07005223 public void run() {
Dianne Hackborn42e620c2012-06-24 13:20:51 -07005224 try {
5225 IStatusBarService statusbar = getStatusBarService();
5226 if (statusbar != null) {
5227 statusbar.setSystemUiVisibility(visibility, 0xffffffff);
5228 statusbar.topAppWindowChanged(needsMenu);
Joe Onorato664644d2011-01-23 17:53:23 -08005229 }
Dianne Hackborn42e620c2012-06-24 13:20:51 -07005230 } catch (RemoteException e) {
5231 // re-acquire status bar service next time it is needed.
5232 mStatusBarService = null;
Joe Onorato664644d2011-01-23 17:53:23 -08005233 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07005234 }
5235 });
5236 return diff;
Joe Onorato664644d2011-01-23 17:53:23 -08005237 }
5238
John Spurlock79da8332013-09-20 12:04:47 -04005239 private int updateSystemBarsLw(WindowState win, int oldVis, int vis) {
John Spurlockbd957402013-10-03 11:38:39 -04005240 // apply translucent bar vis flags
5241 WindowState transWin = mKeyguard != null && mKeyguard.isVisibleLw() && !mHideLockScreen
5242 ? mKeyguard
5243 : mTopFullscreenOpaqueWindowState;
5244 vis = mStatusBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
5245 vis = mNavigationBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
5246
John Spurlock27735a42013-08-14 17:57:38 -04005247 // prevent status bar interaction from clearing certain flags
John Spurlock79da8332013-09-20 12:04:47 -04005248 boolean statusBarHasFocus = win.getAttrs().type == TYPE_STATUS_BAR;
John Spurlockad3e6cb2013-04-30 08:47:43 -04005249 if (statusBarHasFocus) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04005250 int flags = View.SYSTEM_UI_FLAG_FULLSCREEN
5251 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlockcfc359a2013-09-05 10:42:03 -04005252 | View.SYSTEM_UI_FLAG_IMMERSIVE
John Spurlockf1a36642013-10-12 17:50:42 -04005253 | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
John Spurlockbd957402013-10-03 11:38:39 -04005254 | View.STATUS_BAR_TRANSLUCENT
5255 | View.NAVIGATION_BAR_TRANSLUCENT;
5256 vis = (vis & ~flags) | (oldVis & flags);
John Spurlockad3e6cb2013-04-30 08:47:43 -04005257 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04005258
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04005259 if (!areTranslucentBarsAllowed()) {
5260 vis &= ~(View.NAVIGATION_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSLUCENT);
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07005261 }
5262
John Spurlock27735a42013-08-14 17:57:38 -04005263 // update status bar
John Spurlockf1a36642013-10-12 17:50:42 -04005264 boolean immersiveSticky =
5265 (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
John Spurlock27735a42013-08-14 17:57:38 -04005266 boolean hideStatusBarWM =
John Spurlockbd957402013-10-03 11:38:39 -04005267 mTopFullscreenOpaqueWindowState != null &&
5268 (mTopFullscreenOpaqueWindowState.getAttrs().flags
John Spurlock27735a42013-08-14 17:57:38 -04005269 & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0;
5270 boolean hideStatusBarSysui =
5271 (vis & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04005272 boolean hideNavBarSysui =
5273 (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0;
John Spurlockad3e6cb2013-04-30 08:47:43 -04005274
John Spurlock27735a42013-08-14 17:57:38 -04005275 boolean transientStatusBarAllowed =
5276 mStatusBar != null && (
5277 hideStatusBarWM
John Spurlockf1a36642013-10-12 17:50:42 -04005278 || (hideStatusBarSysui && immersiveSticky)
John Spurlock27735a42013-08-14 17:57:38 -04005279 || statusBarHasFocus);
5280
John Spurlockf1a36642013-10-12 17:50:42 -04005281 boolean transientNavBarAllowed =
5282 mNavigationBar != null &&
5283 hideNavBarSysui && immersiveSticky;
5284
John Spurlockf25706f2013-11-07 18:02:43 -05005285 boolean denyTransientStatus = mStatusBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04005286 && !transientStatusBarAllowed && hideStatusBarSysui;
John Spurlockf25706f2013-11-07 18:02:43 -05005287 boolean denyTransientNav = mNavigationBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04005288 && !transientNavBarAllowed;
5289 if (denyTransientStatus || denyTransientNav) {
John Spurlock27735a42013-08-14 17:57:38 -04005290 // clear the clearable flags instead
John Spurlockf1a36642013-10-12 17:50:42 -04005291 clearClearableFlagsLw();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005292 }
John Spurlock27735a42013-08-14 17:57:38 -04005293
5294 vis = mStatusBarController.updateVisibilityLw(transientStatusBarAllowed, oldVis, vis);
5295
5296 // update navigation bar
John Spurlockf1a36642013-10-12 17:50:42 -04005297 boolean oldImmersiveMode = isImmersiveMode(oldVis);
5298 boolean newImmersiveMode = isImmersiveMode(vis);
5299 if (win != null && oldImmersiveMode != newImmersiveMode) {
John Spurlock79da8332013-09-20 12:04:47 -04005300 final String pkg = win.getOwningPackage();
John Spurlockf1a36642013-10-12 17:50:42 -04005301 mImmersiveModeConfirmation.immersiveModeChanged(pkg, newImmersiveMode);
John Spurlock34e13d92013-08-10 06:52:28 -04005302 }
John Spurlock27735a42013-08-14 17:57:38 -04005303
John Spurlockf1a36642013-10-12 17:50:42 -04005304 vis = mNavigationBarController.updateVisibilityLw(transientNavBarAllowed, oldVis, vis);
5305
John Spurlocke1f366f2013-08-05 12:22:40 -04005306 return vis;
John Spurlockad3e6cb2013-04-30 08:47:43 -04005307 }
5308
John Spurlockf1a36642013-10-12 17:50:42 -04005309 private void clearClearableFlagsLw() {
5310 int newVal = mResettingSystemUiFlags | View.SYSTEM_UI_CLEARABLE_FLAGS;
5311 if (newVal != mResettingSystemUiFlags) {
5312 mResettingSystemUiFlags = newVal;
5313 mWindowManagerFuncs.reevaluateStatusBarVisibility();
5314 }
5315 }
5316
5317 private boolean isImmersiveMode(int vis) {
5318 final int flags = View.SYSTEM_UI_FLAG_IMMERSIVE | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
John Spurlock34e13d92013-08-10 06:52:28 -04005319 return mNavigationBar != null
5320 && (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0
Daniel Sandler900ece52013-10-18 15:53:27 -04005321 && (vis & flags) != 0
5322 && canHideNavigationBar();
John Spurlock34e13d92013-08-10 06:52:28 -04005323 }
5324
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07005325 /**
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04005326 * @return whether the navigation or status bar can be made translucent
5327 *
5328 * This should return true unless touch exploration is not enabled or
5329 * R.boolean.config_enableTranslucentDecor is false.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07005330 */
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04005331 private boolean areTranslucentBarsAllowed() {
5332 return mTranslucentDecorEnabled && !mTouchExplorationEnabled;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07005333 }
5334
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04005335 // Use this instead of checking config_showNavigationBar so that it can be consistently
5336 // overridden by qemu.hw.mainkeys in the emulator.
Craig Mautnereda67292013-04-28 13:50:14 -07005337 @Override
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04005338 public boolean hasNavigationBar() {
5339 return mHasNavigationBar;
5340 }
5341
satok1bc0a492012-04-25 22:47:12 +09005342 @Override
5343 public void setLastInputMethodWindowLw(WindowState ime, WindowState target) {
5344 mLastInputMethodWindow = ime;
5345 mLastInputMethodTargetWindow = target;
5346 }
5347
Craig Mautnerf1b67412012-09-19 13:18:29 -07005348 @Override
Craig Mautnerf1b67412012-09-19 13:18:29 -07005349 public void setCurrentUserLw(int newUserId) {
Craig Mautnerd625ab22013-09-06 13:40:31 -07005350 mCurrentUserId = newUserId;
Jim Miller5ecd8112013-01-09 18:50:26 -08005351 if (mKeyguardDelegate != null) {
5352 mKeyguardDelegate.setCurrentUser(newUserId);
Craig Mautnerf1b67412012-09-19 13:18:29 -07005353 }
John Spurlock13451a22012-09-28 14:40:41 -04005354 if (mStatusBarService != null) {
5355 try {
5356 mStatusBarService.setCurrentUser(newUserId);
5357 } catch (RemoteException e) {
5358 // oh well
5359 }
5360 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07005361 setLastInputMethodWindowLw(null, null);
Craig Mautnerf1b67412012-09-19 13:18:29 -07005362 }
5363
5364 @Override
Svetoslav Ganov545252f2012-12-10 18:29:24 -08005365 public boolean canMagnifyWindow(int windowType) {
5366 switch (windowType) {
5367 case WindowManager.LayoutParams.TYPE_INPUT_METHOD:
5368 case WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG:
5369 case WindowManager.LayoutParams.TYPE_NAVIGATION_BAR:
5370 case WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY: {
5371 return false;
5372 }
5373 }
5374 return true;
5375 }
5376
5377 @Override
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07005378 public void setTouchExplorationEnabled(boolean enabled) {
5379 mTouchExplorationEnabled = enabled;
5380 }
5381
5382 @Override
Svetoslav Ganov545252f2012-12-10 18:29:24 -08005383 public boolean isTopLevelWindow(int windowType) {
5384 if (windowType >= WindowManager.LayoutParams.FIRST_SUB_WINDOW
5385 && windowType <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
5386 return (windowType == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG);
5387 }
5388 return true;
5389 }
5390
Jim Miller4eeb4f62012-11-08 00:04:29 -08005391 @Override
Jeff Brownd7a04de2012-06-17 14:17:52 -07005392 public void dump(String prefix, PrintWriter pw, String[] args) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005393 pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005394 pw.print(" mSystemReady="); pw.print(mSystemReady);
5395 pw.print(" mSystemBooted="); pw.println(mSystemBooted);
Jeff Brown2e7760e2012-04-11 15:14:55 -07005396 pw.print(prefix); pw.print("mLidState="); pw.print(mLidState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005397 pw.print(" mLidOpenRotation="); pw.print(mLidOpenRotation);
5398 pw.print(" mHdmiPlugged="); pw.println(mHdmiPlugged);
Dianne Hackborne26ab702011-10-16 13:21:33 -07005399 if (mLastSystemUiFlags != 0 || mResettingSystemUiFlags != 0
5400 || mForceClearedSystemUiFlags != 0) {
5401 pw.print(prefix); pw.print("mLastSystemUiFlags=0x");
5402 pw.print(Integer.toHexString(mLastSystemUiFlags));
5403 pw.print(" mResettingSystemUiFlags=0x");
5404 pw.print(Integer.toHexString(mResettingSystemUiFlags));
5405 pw.print(" mForceClearedSystemUiFlags=0x");
5406 pw.println(Integer.toHexString(mForceClearedSystemUiFlags));
Dianne Hackborndf89e652011-10-06 22:35:11 -07005407 }
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08005408 if (mLastFocusNeedsMenu) {
5409 pw.print(prefix); pw.print("mLastFocusNeedsMenu=");
5410 pw.println(mLastFocusNeedsMenu);
5411 }
Jeff Brownbcdfc622014-03-06 19:13:04 -08005412 pw.print(prefix); pw.print("mSupportAutoRotation="); pw.println(mSupportAutoRotation);
Daniel Sandler6396c722013-04-16 20:19:09 -04005413 pw.print(prefix); pw.print("mUiMode="); pw.print(mUiMode);
5414 pw.print(" mDockMode="); pw.print(mDockMode);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005415 pw.print(" mCarDockRotation="); pw.print(mCarDockRotation);
5416 pw.print(" mDeskDockRotation="); pw.println(mDeskDockRotation);
5417 pw.print(prefix); pw.print("mUserRotationMode="); pw.print(mUserRotationMode);
5418 pw.print(" mUserRotation="); pw.print(mUserRotation);
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005419 pw.print(" mAllowAllRotations="); pw.println(mAllowAllRotations);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07005420 pw.print(prefix); pw.print("mCurrentAppOrientation="); pw.println(mCurrentAppOrientation);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005421 pw.print(prefix); pw.print("mCarDockEnablesAccelerometer=");
5422 pw.print(mCarDockEnablesAccelerometer);
5423 pw.print(" mDeskDockEnablesAccelerometer=");
5424 pw.println(mDeskDockEnablesAccelerometer);
5425 pw.print(prefix); pw.print("mLidKeyboardAccessibility=");
5426 pw.print(mLidKeyboardAccessibility);
5427 pw.print(" mLidNavigationAccessibility="); pw.print(mLidNavigationAccessibility);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07005428 pw.print(" mLidControlsSleep="); pw.println(mLidControlsSleep);
Jeff Brown6d8fd272014-05-20 21:24:38 -07005429 pw.print(prefix);
5430 pw.print("mShortPressOnPowerBehavior="); pw.print(mShortPressOnPowerBehavior);
5431 pw.print(" mLongPressOnPowerBehavior="); pw.println(mLongPressOnPowerBehavior);
5432 pw.print(prefix); pw.print("mHasSoftInput="); pw.println(mHasSoftInput);
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07005433 pw.print(prefix); pw.print("mScreenOnEarly="); pw.print(mScreenOnEarly);
5434 pw.print(" mScreenOnFully="); pw.print(mScreenOnFully);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07005435 pw.print(" mOrientationSensorEnabled="); pw.println(mOrientationSensorEnabled);
Dianne Hackbornc652de82013-02-15 16:32:56 -08005436 pw.print(prefix); pw.print("mOverscanScreen=("); pw.print(mOverscanScreenLeft);
5437 pw.print(","); pw.print(mOverscanScreenTop);
5438 pw.print(") "); pw.print(mOverscanScreenWidth);
5439 pw.print("x"); pw.println(mOverscanScreenHeight);
5440 if (mOverscanLeft != 0 || mOverscanTop != 0
5441 || mOverscanRight != 0 || mOverscanBottom != 0) {
5442 pw.print(prefix); pw.print("mOverscan left="); pw.print(mOverscanLeft);
5443 pw.print(" top="); pw.print(mOverscanTop);
5444 pw.print(" right="); pw.print(mOverscanRight);
5445 pw.print(" bottom="); pw.println(mOverscanBottom);
5446 }
Dianne Hackborn313440842013-02-19 19:22:59 -08005447 pw.print(prefix); pw.print("mRestrictedOverscanScreen=(");
5448 pw.print(mRestrictedOverscanScreenLeft);
5449 pw.print(","); pw.print(mRestrictedOverscanScreenTop);
5450 pw.print(") "); pw.print(mRestrictedOverscanScreenWidth);
5451 pw.print("x"); pw.println(mRestrictedOverscanScreenHeight);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005452 pw.print(prefix); pw.print("mUnrestrictedScreen=("); pw.print(mUnrestrictedScreenLeft);
5453 pw.print(","); pw.print(mUnrestrictedScreenTop);
5454 pw.print(") "); pw.print(mUnrestrictedScreenWidth);
5455 pw.print("x"); pw.println(mUnrestrictedScreenHeight);
5456 pw.print(prefix); pw.print("mRestrictedScreen=("); pw.print(mRestrictedScreenLeft);
5457 pw.print(","); pw.print(mRestrictedScreenTop);
5458 pw.print(") "); pw.print(mRestrictedScreenWidth);
5459 pw.print("x"); pw.println(mRestrictedScreenHeight);
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07005460 pw.print(prefix); pw.print("mStableFullscreen=("); pw.print(mStableFullscreenLeft);
5461 pw.print(","); pw.print(mStableFullscreenTop);
5462 pw.print(")-("); pw.print(mStableFullscreenRight);
5463 pw.print(","); pw.print(mStableFullscreenBottom); pw.println(")");
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07005464 pw.print(prefix); pw.print("mStable=("); pw.print(mStableLeft);
5465 pw.print(","); pw.print(mStableTop);
5466 pw.print(")-("); pw.print(mStableRight);
5467 pw.print(","); pw.print(mStableBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07005468 pw.print(prefix); pw.print("mSystem=("); pw.print(mSystemLeft);
5469 pw.print(","); pw.print(mSystemTop);
5470 pw.print(")-("); pw.print(mSystemRight);
5471 pw.print(","); pw.print(mSystemBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005472 pw.print(prefix); pw.print("mCur=("); pw.print(mCurLeft);
5473 pw.print(","); pw.print(mCurTop);
5474 pw.print(")-("); pw.print(mCurRight);
5475 pw.print(","); pw.print(mCurBottom); pw.println(")");
5476 pw.print(prefix); pw.print("mContent=("); pw.print(mContentLeft);
5477 pw.print(","); pw.print(mContentTop);
5478 pw.print(")-("); pw.print(mContentRight);
5479 pw.print(","); pw.print(mContentBottom); pw.println(")");
5480 pw.print(prefix); pw.print("mDock=("); pw.print(mDockLeft);
5481 pw.print(","); pw.print(mDockTop);
5482 pw.print(")-("); pw.print(mDockRight);
5483 pw.print(","); pw.print(mDockBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07005484 pw.print(prefix); pw.print("mDockLayer="); pw.print(mDockLayer);
5485 pw.print(" mStatusBarLayer="); pw.println(mStatusBarLayer);
Dianne Hackborn7ad44382012-10-18 17:46:00 -07005486 pw.print(prefix); pw.print("mShowingLockscreen="); pw.print(mShowingLockscreen);
5487 pw.print(" mShowingDream="); pw.print(mShowingDream);
5488 pw.print(" mDreamingLockscreen="); pw.println(mDreamingLockscreen);
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07005489 if (mLastInputMethodWindow != null) {
5490 pw.print(prefix); pw.print("mLastInputMethodWindow=");
5491 pw.println(mLastInputMethodWindow);
5492 }
5493 if (mLastInputMethodTargetWindow != null) {
5494 pw.print(prefix); pw.print("mLastInputMethodTargetWindow=");
5495 pw.println(mLastInputMethodTargetWindow);
5496 }
5497 if (mStatusBar != null) {
5498 pw.print(prefix); pw.print("mStatusBar=");
5499 pw.println(mStatusBar);
5500 }
5501 if (mNavigationBar != null) {
5502 pw.print(prefix); pw.print("mNavigationBar=");
5503 pw.println(mNavigationBar);
5504 }
5505 if (mKeyguard != null) {
5506 pw.print(prefix); pw.print("mKeyguard=");
5507 pw.println(mKeyguard);
5508 }
5509 if (mFocusedWindow != null) {
5510 pw.print(prefix); pw.print("mFocusedWindow=");
5511 pw.println(mFocusedWindow);
5512 }
5513 if (mFocusedApp != null) {
5514 pw.print(prefix); pw.print("mFocusedApp=");
5515 pw.println(mFocusedApp);
5516 }
5517 if (mWinDismissingKeyguard != null) {
5518 pw.print(prefix); pw.print("mWinDismissingKeyguard=");
5519 pw.println(mWinDismissingKeyguard);
5520 }
5521 if (mTopFullscreenOpaqueWindowState != null) {
5522 pw.print(prefix); pw.print("mTopFullscreenOpaqueWindowState=");
5523 pw.println(mTopFullscreenOpaqueWindowState);
5524 }
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08005525 if (mForcingShowNavBar) {
5526 pw.print(prefix); pw.print("mForcingShowNavBar=");
5527 pw.println(mForcingShowNavBar); pw.print( "mForcingShowNavBarLayer=");
5528 pw.println(mForcingShowNavBarLayer);
5529 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07005530 pw.print(prefix); pw.print("mTopIsFullscreen="); pw.print(mTopIsFullscreen);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005531 pw.print(" mHideLockScreen="); pw.println(mHideLockScreen);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07005532 pw.print(prefix); pw.print("mForceStatusBar="); pw.print(mForceStatusBar);
5533 pw.print(" mForceStatusBarFromKeyguard=");
5534 pw.println(mForceStatusBarFromKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005535 pw.print(prefix); pw.print("mDismissKeyguard="); pw.print(mDismissKeyguard);
Craig Mautnerad09bcc2012-10-08 13:33:11 -07005536 pw.print(" mWinDismissingKeyguard="); pw.print(mWinDismissingKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005537 pw.print(" mHomePressed="); pw.println(mHomePressed);
5538 pw.print(prefix); pw.print("mAllowLockscreenWhenOn="); pw.print(mAllowLockscreenWhenOn);
5539 pw.print(" mLockScreenTimeout="); pw.print(mLockScreenTimeout);
5540 pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive);
5541 pw.print(prefix); pw.print("mEndcallBehavior="); pw.print(mEndcallBehavior);
5542 pw.print(" mIncallPowerBehavior="); pw.print(mIncallPowerBehavior);
5543 pw.print(" mLongPressOnHomeBehavior="); pw.println(mLongPressOnHomeBehavior);
5544 pw.print(prefix); pw.print("mLandscapeRotation="); pw.print(mLandscapeRotation);
5545 pw.print(" mSeascapeRotation="); pw.println(mSeascapeRotation);
5546 pw.print(prefix); pw.print("mPortraitRotation="); pw.print(mPortraitRotation);
5547 pw.print(" mUpsideDownRotation="); pw.println(mUpsideDownRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07005548 pw.print(prefix); pw.print("mDemoHdmiRotation="); pw.print(mDemoHdmiRotation);
5549 pw.print(" mDemoHdmiRotationLock="); pw.println(mDemoHdmiRotationLock);
5550 pw.print(prefix); pw.print("mUndockedHdmiRotation="); pw.println(mUndockedHdmiRotation);
John Spurlock27735a42013-08-14 17:57:38 -04005551 mStatusBarController.dump(pw, prefix);
5552 mNavigationBarController.dump(pw, prefix);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005553 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005554}