blob: 273ac310a9aa075dbcabb76aeef5e5d3749ebe2d [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;
Dianne Hackborn661cd522011-08-22 00:26:20 -070021import android.app.ProgressDialog;
Jeff Brownde7a8ea2012-06-13 18:28:57 -070022import android.app.SearchManager;
Dianne Hackborn78968392010-03-04 20:47:56 -080023import android.app.UiModeManager;
Dianne Hackborn39c2d712009-09-22 11:41:31 -070024import android.content.ActivityNotFoundException;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080025import android.content.BroadcastReceiver;
Daniel Sandler0601eb72011-04-13 01:01:32 -040026import android.content.ComponentName;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080027import android.content.ContentResolver;
28import android.content.Context;
29import android.content.Intent;
Mike Lockwood1753f7f2009-08-24 14:49:07 -070030import android.content.IntentFilter;
Winson Chung9112ec32011-06-27 13:15:32 -070031import android.content.ServiceConnection;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080032import android.content.pm.ActivityInfo;
33import android.content.pm.PackageManager;
Dianne Hackborn2f0b1752011-05-31 17:59:49 -070034import android.content.res.CompatibilityInfo;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080035import android.content.res.Configuration;
36import android.content.res.Resources;
Craig Mautner8e4df6c2012-05-23 16:57:23 -070037import android.content.res.TypedArray;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080038import android.database.ContentObserver;
Dianne Hackbornc777e072010-02-12 13:07:59 -080039import android.graphics.PixelFormat;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080040import android.graphics.Rect;
Michael Jurka7a348952012-02-27 13:07:58 -080041import android.media.AudioManager;
42import android.media.IAudioService;
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -070043import android.media.Ringtone;
44import android.media.RingtoneManager;
Dianne Hackborn38e29a62011-09-18 14:43:08 -070045import android.os.Bundle;
Jeff Brown9a538ee2012-08-20 14:56:57 -070046import android.os.FactoryTest;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080047import android.os.Handler;
48import android.os.IBinder;
Dianne Hackborn38e29a62011-09-18 14:43:08 -070049import android.os.IRemoteCallback;
Jeff Brown32cbc38552011-12-01 14:01:49 -080050import android.os.Looper;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -070051import android.os.Message;
52import android.os.Messenger;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080053import android.os.PowerManager;
54import android.os.RemoteException;
55import android.os.ServiceManager;
56import android.os.SystemClock;
57import android.os.SystemProperties;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -080058import android.os.UEventObserver;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -070059import android.os.UserHandle;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080060import android.os.Vibrator;
61import android.provider.Settings;
John Spurlockc8b46ca2013-04-08 12:59:26 -040062import android.service.dreams.DreamService;
63import android.service.dreams.IDreamManager;
Dianne Hackborn81e56d52011-05-26 00:55:58 -070064import android.util.DisplayMetrics;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080065import android.util.EventLog;
66import android.util.Log;
Jeff Browna41ca772010-08-11 14:46:32 -070067import android.util.Slog;
Jeff Brown6651a632011-11-28 12:59:11 -080068import android.util.SparseArray;
Dianne Hackbornf87d1962012-04-04 12:48:24 -070069import android.view.Display;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080070import android.view.Gravity;
71import android.view.HapticFeedbackConstants;
Dianne Hackborne0f085d2011-11-30 18:41:15 -080072import android.view.IApplicationToken;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080073import android.view.IWindowManager;
Jeff Browna41ca772010-08-11 14:46:32 -070074import android.view.InputChannel;
Jeff Brown4d396052010-10-29 21:50:21 -070075import android.view.InputDevice;
Jeff Brown4952dfd2011-11-30 19:23:22 -080076import android.view.InputEvent;
Jeff Brown32cbc38552011-12-01 14:01:49 -080077import android.view.InputEventReceiver;
Jeff Brown6b53e8d2010-11-10 16:03:06 -080078import android.view.KeyCharacterMap;
Craig Mautnerae446592012-12-06 19:05:05 -080079import android.view.KeyCharacterMap.FallbackAction;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080080import android.view.KeyEvent;
81import android.view.MotionEvent;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080082import android.view.Surface;
83import android.view.View;
84import android.view.ViewConfiguration;
85import android.view.Window;
86import android.view.WindowManager;
Craig Mautnerae446592012-12-06 19:05:05 -080087import android.view.WindowManagerGlobal;
88import android.view.WindowManagerPolicy;
Craig Mautnerae446592012-12-06 19:05:05 -080089import android.view.accessibility.AccessibilityEvent;
90import android.view.animation.Animation;
91import android.view.animation.AnimationUtils;
92
93import com.android.internal.R;
94import com.android.internal.policy.PolicyManager;
95import com.android.internal.policy.impl.keyguard.KeyguardViewManager;
96import com.android.internal.policy.impl.keyguard.KeyguardViewMediator;
97import com.android.internal.statusbar.IStatusBarService;
98import com.android.internal.telephony.ITelephony;
99import com.android.internal.widget.PointerLocationView;
100
101import java.io.File;
102import java.io.FileReader;
103import java.io.IOException;
104import java.io.PrintWriter;
105
Dianne Hackbornc652de82013-02-15 16:32:56 -0800106import static android.view.WindowManager.LayoutParams.*;
Jeff Brownac143512012-04-05 18:57:33 -0700107import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_ABSENT;
108import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_OPEN;
109import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_CLOSED;
Dianne Hackborn08743722009-12-21 12:16:51 -0800110
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800111/**
The Android Open Source Project0727d222009-03-11 12:11:58 -0700112 * WindowManagerPolicy implementation for the Android phone UI. This
113 * introduces a new method suffix, Lp, for an internal lock of the
114 * PhoneWindowManager. This is used to protect some internal state, and
115 * can be acquired with either thw Lw and Li lock held, so has the restrictions
116 * of both of those when held.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800117 */
118public class PhoneWindowManager implements WindowManagerPolicy {
119 static final String TAG = "WindowManager";
120 static final boolean DEBUG = false;
Joe Onorato43a17652011-04-06 19:22:23 -0700121 static final boolean localLOGV = false;
The Android Open Source Project11267662009-03-18 17:39:47 -0700122 static final boolean DEBUG_LAYOUT = false;
Jeff Brown40013652012-05-16 21:22:36 -0700123 static final boolean DEBUG_INPUT = false;
Craig Mautner6fbda632012-07-03 09:26:39 -0700124 static final boolean DEBUG_STARTING_WINDOW = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800125 static final boolean SHOW_STARTING_ANIMATIONS = true;
126 static final boolean SHOW_PROCESSES_ON_ALT_MENU = false;
Joe Onoratod208e702010-10-08 16:22:43 -0400127
128 static final int LONG_PRESS_POWER_NOTHING = 0;
129 static final int LONG_PRESS_POWER_GLOBAL_ACTIONS = 1;
130 static final int LONG_PRESS_POWER_SHUT_OFF = 2;
Jeff Brown9a538ee2012-08-20 14:56:57 -0700131 static final int LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM = 3;
Michael Jurka3b1fc472011-06-13 10:54:40 -0700132
133 // These need to match the documentation/constant in
134 // core/res/res/values/config.xml
Joe Onorato46b0d682010-11-22 17:37:27 -0800135 static final int LONG_PRESS_HOME_NOTHING = 0;
Michael Wrightc9ebea72013-01-16 19:25:02 -0800136 static final int LONG_PRESS_HOME_RECENT_SYSTEM_UI = 1;
Joe Onorato46b0d682010-11-22 17:37:27 -0800137
Dianne Hackborn5cb8d792009-05-21 17:34:15 -0700138 static final int APPLICATION_MEDIA_SUBLAYER = -2;
139 static final int APPLICATION_MEDIA_OVERLAY_SUBLAYER = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800140 static final int APPLICATION_PANEL_SUBLAYER = 1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800141 static final int APPLICATION_SUB_PANEL_SUBLAYER = 2;
Craig Mautner88400d32012-09-30 12:35:45 -0700142
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800143 static public final String SYSTEM_DIALOG_REASON_KEY = "reason";
144 static public final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions";
145 static public final String SYSTEM_DIALOG_REASON_RECENT_APPS = "recentapps";
Joe Onoratof275f0c2009-11-24 16:11:13 -0500146 static public final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey";
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700147 static public final String SYSTEM_DIALOG_REASON_ASSIST = "assist";
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800148
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700149 /**
150 * These are the system UI flags that, when changing, can cause the layout
151 * of the screen to change.
152 */
153 static final int SYSTEM_UI_CHANGING_LAYOUT =
154 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN;
155
Jeff Brown6651a632011-11-28 12:59:11 -0800156 /* Table of Application Launch keys. Maps from key codes to intent categories.
157 *
158 * These are special keys that are used to launch particular kinds of applications,
159 * such as a web browser. HID defines nearly a hundred of them in the Consumer (0x0C)
160 * usage page. We don't support quite that many yet...
161 */
162 static SparseArray<String> sApplicationLaunchKeyCategories;
163 static {
164 sApplicationLaunchKeyCategories = new SparseArray<String>();
165 sApplicationLaunchKeyCategories.append(
166 KeyEvent.KEYCODE_EXPLORER, Intent.CATEGORY_APP_BROWSER);
167 sApplicationLaunchKeyCategories.append(
168 KeyEvent.KEYCODE_ENVELOPE, Intent.CATEGORY_APP_EMAIL);
169 sApplicationLaunchKeyCategories.append(
170 KeyEvent.KEYCODE_CONTACTS, Intent.CATEGORY_APP_CONTACTS);
171 sApplicationLaunchKeyCategories.append(
172 KeyEvent.KEYCODE_CALENDAR, Intent.CATEGORY_APP_CALENDAR);
173 sApplicationLaunchKeyCategories.append(
174 KeyEvent.KEYCODE_MUSIC, Intent.CATEGORY_APP_MUSIC);
175 sApplicationLaunchKeyCategories.append(
176 KeyEvent.KEYCODE_CALCULATOR, Intent.CATEGORY_APP_CALCULATOR);
177 }
178
Dianne Hackborndf89e652011-10-06 22:35:11 -0700179 /**
180 * Lock protecting internal state. Must not call out into window
181 * manager with lock held. (This lock will be acquired in places
182 * where the window manager is calling in with its own lock held.)
183 */
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800184 private final Object mLock = new Object();
Dianne Hackborndf89e652011-10-06 22:35:11 -0700185
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800186 Context mContext;
187 IWindowManager mWindowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700188 WindowManagerFuncs mWindowManagerFuncs;
Jeff Brown96307042012-07-27 15:51:34 -0700189 PowerManager mPowerManager;
Joe Onorato93056472010-09-10 10:30:46 -0400190 IStatusBarService mStatusBarService;
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700191 final Object mServiceAquireLock = new Object();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800192 Vibrator mVibrator; // Vibrator for giving feedback of orientation changes
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700193 SearchManager mSearchManager;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800194
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700195 // Vibrator pattern for haptic feedback of a long press.
196 long[] mLongPressVibePattern;
Craig Mautner88400d32012-09-30 12:35:45 -0700197
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700198 // Vibrator pattern for haptic feedback of virtual key press.
199 long[] mVirtualKeyVibePattern;
200
Amith Yamasanic33cb712010-02-10 15:21:49 -0800201 // Vibrator pattern for a short vibration.
202 long[] mKeyboardTapVibePattern;
203
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700204 // Vibrator pattern for haptic feedback during boot when safe mode is disabled.
205 long[] mSafeModeDisabledVibePattern;
206
207 // Vibrator pattern for haptic feedback during boot when safe mode is enabled.
208 long[] mSafeModeEnabledVibePattern;
Romain Guy8154cd32010-03-29 14:41:15 -0700209
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800210 /** If true, hitting shift & menu will broadcast Intent.ACTION_BUG_REPORT */
211 boolean mEnableShiftMenuBugReports = false;
Mike Lockwoodd747dc82011-09-13 16:28:22 -0400212
213 boolean mHeadless;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800214 boolean mSafeMode;
215 WindowState mStatusBar = null;
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700216 boolean mHasSystemNavBar;
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700217 int mStatusBarHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400218 WindowState mNavigationBar = null;
Daniel Sandler36412a72011-08-04 09:35:13 -0400219 boolean mHasNavigationBar = false;
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700220 boolean mCanHideNavigationBar = false;
Daniel Sandler4a066c52012-04-20 14:49:13 -0400221 boolean mNavigationBarCanMove = false; // can the navigation bar ever move to the side?
222 boolean mNavigationBarOnBottom = true; // is the navigation bar on the bottom *right now*?
223 int[] mNavigationBarHeightForRotation = new int[4];
224 int[] mNavigationBarWidthForRotation = new int[4];
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400225
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800226 WindowState mKeyguard = null;
227 KeyguardViewMediator mKeyguardMediator;
228 GlobalActions mGlobalActions;
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700229 volatile boolean mPowerKeyHandled; // accessed from input reader and handler thread
230 boolean mPendingPowerKeyUpCanceled;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800231 Handler mHandler;
satok1bc0a492012-04-25 22:47:12 +0900232 WindowState mLastInputMethodWindow = null;
233 WindowState mLastInputMethodTargetWindow = null;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800234
Jeff Brown68b909d2011-12-07 16:36:01 -0800235 static final int RECENT_APPS_BEHAVIOR_SHOW_OR_DISMISS = 0;
236 static final int RECENT_APPS_BEHAVIOR_EXIT_TOUCH_MODE_AND_SHOW = 1;
Jeff Brown602ab322012-05-16 13:33:47 -0700237 static final int RECENT_APPS_BEHAVIOR_DISMISS = 2;
238 static final int RECENT_APPS_BEHAVIOR_DISMISS_AND_SWITCH = 3;
Jeff Brown68b909d2011-12-07 16:36:01 -0800239
240 RecentApplicationsDialog mRecentAppsDialog;
241 int mRecentAppsDialogHeldModifiers;
Jeff Browncf39bdf2012-05-18 14:41:19 -0700242 boolean mLanguageSwitchKeyPressed;
Jeff Brown68b909d2011-12-07 16:36:01 -0800243
Jeff Brown2e7760e2012-04-11 15:14:55 -0700244 int mLidState = LID_ABSENT;
Jeff Browndaa37532012-05-01 15:54:03 -0700245 boolean mHaveBuiltInKeyboard;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800246
Dianne Hackbornc777e072010-02-12 13:07:59 -0800247 boolean mSystemReady;
Dianne Hackbornba24e4d2011-09-01 11:17:06 -0700248 boolean mSystemBooted;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800249 boolean mHdmiPlugged;
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700250 int mDockMode = Intent.EXTRA_DOCK_STATE_UNDOCKED;
Mike Lockwood1753f7f2009-08-24 14:49:07 -0700251 int mLidOpenRotation;
Mike Lockwood2d1efbd2009-09-16 12:15:53 -0400252 int mCarDockRotation;
253 int mDeskDockRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -0700254 int mHdmiRotation;
Jeff Brown27f1d672012-10-17 18:32:34 -0700255 boolean mHdmiRotationLock;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400256
257 int mUserRotationMode = WindowManagerPolicy.USER_ROTATION_FREE;
258 int mUserRotation = Surface.ROTATION_0;
Jeff Brown207673cd2012-06-05 17:47:11 -0700259 boolean mAccelerometerDefault;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400260
Jeff Brownd3187e32011-09-21 19:26:44 -0700261 int mAllowAllRotations = -1;
Mike Lockwoode9867d22009-09-20 01:59:02 -0400262 boolean mCarDockEnablesAccelerometer;
263 boolean mDeskDockEnablesAccelerometer;
Dianne Hackborn2862fff2009-09-15 22:56:29 -0700264 int mLidKeyboardAccessibility;
265 int mLidNavigationAccessibility;
Jeff Brownc458ce92012-04-30 14:58:40 -0700266 boolean mLidControlsSleep;
Joe Onoratod208e702010-10-08 16:22:43 -0400267 int mLongPressOnPowerBehavior = -1;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -0700268 boolean mScreenOnEarly = false;
269 boolean mScreenOnFully = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800270 boolean mOrientationSensorEnabled = false;
271 int mCurrentAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800272 boolean mHasSoftInput = false;
273
Jeff Brown70825162012-03-28 17:27:48 -0700274 int mPointerLocationMode = 0; // guarded by mLock
Joe Onorato664644d2011-01-23 17:53:23 -0800275
276 // The last window we were told about in focusChanged.
277 WindowState mFocusedWindow;
Dianne Hackborne0f085d2011-11-30 18:41:15 -0800278 IApplicationToken mFocusedApp;
Joe Onorato664644d2011-01-23 17:53:23 -0800279
Jeff Brown70825162012-03-28 17:27:48 -0700280 private static final class PointerLocationInputEventReceiver extends InputEventReceiver {
281 private final PointerLocationView mView;
282
283 public PointerLocationInputEventReceiver(InputChannel inputChannel, Looper looper,
284 PointerLocationView view) {
Jeff Brown32cbc38552011-12-01 14:01:49 -0800285 super(inputChannel, looper);
Jeff Brown70825162012-03-28 17:27:48 -0700286 mView = view;
Jeff Brown32cbc38552011-12-01 14:01:49 -0800287 }
288
Jeff Browna41ca772010-08-11 14:46:32 -0700289 @Override
Jeff Brown32cbc38552011-12-01 14:01:49 -0800290 public void onInputEvent(InputEvent event) {
Jeff Brown3915bb82010-11-05 15:02:16 -0700291 boolean handled = false;
292 try {
Jeff Brown4952dfd2011-11-30 19:23:22 -0800293 if (event instanceof MotionEvent
294 && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
295 final MotionEvent motionEvent = (MotionEvent)event;
Jeff Brown70825162012-03-28 17:27:48 -0700296 mView.addPointerEvent(motionEvent);
297 handled = true;
Jeff Brown93ed4e32010-09-23 13:51:48 -0700298 }
Jeff Brown3915bb82010-11-05 15:02:16 -0700299 } finally {
Jeff Brown32cbc38552011-12-01 14:01:49 -0800300 finishInputEvent(event, handled);
Jeff Browna41ca772010-08-11 14:46:32 -0700301 }
302 }
Jeff Brown32cbc38552011-12-01 14:01:49 -0800303 }
Jeff Brown70825162012-03-28 17:27:48 -0700304
305 // Pointer location view state, only modified on the mHandler Looper.
Jeff Brown32cbc38552011-12-01 14:01:49 -0800306 PointerLocationInputEventReceiver mPointerLocationInputEventReceiver;
Jeff Brown70825162012-03-28 17:27:48 -0700307 PointerLocationView mPointerLocationView;
308 InputChannel mPointerLocationInputChannel;
Jeff Brown32cbc38552011-12-01 14:01:49 -0800309
Dianne Hackbornc652de82013-02-15 16:32:56 -0800310 // The current size of the screen; really; extends into the overscan area of
311 // the screen and doesn't account for any system elements like the status bar.
312 int mOverscanScreenLeft, mOverscanScreenTop;
313 int mOverscanScreenWidth, mOverscanScreenHeight;
314 // The current visible size of the screen; really; (ir)regardless of whether the status
315 // bar can be hidden but not extending into the overscan area.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800316 int mUnrestrictedScreenLeft, mUnrestrictedScreenTop;
317 int mUnrestrictedScreenWidth, mUnrestrictedScreenHeight;
Dianne Hackborn313440842013-02-19 19:22:59 -0800318 // Like mOverscanScreen*, but allowed to move into the overscan region where appropriate.
319 int mRestrictedOverscanScreenLeft, mRestrictedOverscanScreenTop;
320 int mRestrictedOverscanScreenWidth, mRestrictedOverscanScreenHeight;
Dianne Hackborn82de1ae2010-10-28 11:28:39 -0700321 // The current size of the screen; these may be different than (0,0)-(dw,dh)
322 // if the status bar can't be hidden; in that case it effectively carves out
323 // that area of the display from all other windows.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800324 int mRestrictedScreenLeft, mRestrictedScreenTop;
325 int mRestrictedScreenWidth, mRestrictedScreenHeight;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700326 // During layout, the current screen borders accounting for any currently
327 // visible system UI elements.
328 int mSystemLeft, mSystemTop, mSystemRight, mSystemBottom;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700329 // For applications requesting stable content insets, these are them.
330 int mStableLeft, mStableTop, mStableRight, mStableBottom;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -0700331 // For applications requesting stable content insets but have also set the
332 // fullscreen window flag, these are the stable dimensions without the status bar.
333 int mStableFullscreenLeft, mStableFullscreenTop;
334 int mStableFullscreenRight, mStableFullscreenBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800335 // During layout, the current screen borders with all outer decoration
336 // (status bar, input method dock) accounted for.
337 int mCurLeft, mCurTop, mCurRight, mCurBottom;
338 // During layout, the frame in which content should be displayed
339 // to the user, accounting for all screen decoration except for any
340 // space they deem as available for other content. This is usually
341 // the same as mCur*, but may be larger if the screen decor has supplied
342 // content insets.
343 int mContentLeft, mContentTop, mContentRight, mContentBottom;
Dianne Hackborn8e11ef02010-11-18 19:47:42 -0800344 // During layout, the current screen borders along which input method
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800345 // windows are placed.
346 int mDockLeft, mDockTop, mDockRight, mDockBottom;
347 // During layout, the layer at which the doc window is placed.
348 int mDockLayer;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700349 // During layout, this is the layer of the status bar.
350 int mStatusBarLayer;
Dianne Hackborne26ab702011-10-16 13:21:33 -0700351 int mLastSystemUiFlags;
352 // Bits that we are in the process of clearing, so we want to prevent
353 // them from being set by applications until everything has been updated
354 // to have them clear.
355 int mResettingSystemUiFlags = 0;
356 // Bits that we are currently always keeping cleared.
357 int mForceClearedSystemUiFlags = 0;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -0800358 // What we last reported to system UI about whether the compatibility
359 // menu needs to be displayed.
360 boolean mLastFocusNeedsMenu = false;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700361
362 FakeWindow mHideNavFakeWindow = null;
363
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800364 static final Rect mTmpParentFrame = new Rect();
365 static final Rect mTmpDisplayFrame = new Rect();
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800366 static final Rect mTmpOverscanFrame = new Rect();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800367 static final Rect mTmpContentFrame = new Rect();
368 static final Rect mTmpVisibleFrame = new Rect();
Dianne Hackborn1f903c32011-09-13 19:18:06 -0700369 static final Rect mTmpNavigationFrame = new Rect();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800370
371 WindowState mTopFullscreenOpaqueWindowState;
Joe Onorato93056472010-09-10 10:30:46 -0400372 boolean mTopIsFullscreen;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800373 boolean mForceStatusBar;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -0700374 boolean mForceStatusBarFromKeyguard;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700375 boolean mHideLockScreen;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -0800376 boolean mForcingShowNavBar;
377 int mForcingShowNavBarLayer;
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700378
379 // States of keyguard dismiss.
380 private static final int DISMISS_KEYGUARD_NONE = 0; // Keyguard not being dismissed.
381 private static final int DISMISS_KEYGUARD_START = 1; // Keyguard needs to be dismissed.
382 private static final int DISMISS_KEYGUARD_CONTINUE = 2; // Keyguard has been dismissed.
383 int mDismissKeyguard = DISMISS_KEYGUARD_NONE;
384
385 /** The window that is currently dismissing the keyguard. Dismissing the keyguard must only
386 * be done once per window. */
387 private WindowState mWinDismissingKeyguard;
388
Dianne Hackborn7ad44382012-10-18 17:46:00 -0700389 boolean mShowingLockscreen;
390 boolean mShowingDream;
391 boolean mDreamingLockscreen;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800392 boolean mHomePressed;
Michael Jurka7f2668c2012-03-27 07:49:52 -0700393 boolean mHomeLongPressed;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800394 Intent mHomeIntent;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700395 Intent mCarDockIntent;
396 Intent mDeskDockIntent;
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700397 boolean mSearchKeyShortcutPending;
398 boolean mConsumeSearchKeyUp;
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700399 boolean mAssistKeyLongPressed;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800400
Mike Lockwood28569302010-01-28 11:54:40 -0500401 // support for activating the lock screen while the screen is on
402 boolean mAllowLockscreenWhenOn;
403 int mLockScreenTimeout;
404 boolean mLockScreenTimerActive;
405
David Brownbaf8d092010-03-08 21:52:59 -0800406 // Behavior of ENDCALL Button. (See Settings.System.END_BUTTON_BEHAVIOR.)
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800407 int mEndcallBehavior;
David Brownbaf8d092010-03-08 21:52:59 -0800408
409 // Behavior of POWER button while in-call and screen on.
410 // (See Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR.)
411 int mIncallPowerBehavior;
412
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700413 Display mDisplay;
414
Dianne Hackborn9d132642011-04-21 17:26:39 -0700415 int mLandscapeRotation = 0; // default landscape rotation
416 int mSeascapeRotation = 0; // "other" landscape rotation, 180 degrees from mLandscapeRotation
417 int mPortraitRotation = 0; // default portrait rotation
418 int mUpsideDownRotation = 0; // "other" portrait rotation
Mitsuru Oshima831d0d92009-06-16 18:27:18 -0700419
Dianne Hackbornc652de82013-02-15 16:32:56 -0800420 int mOverscanLeft = 0;
421 int mOverscanTop = 0;
422 int mOverscanRight = 0;
423 int mOverscanBottom = 0;
424
Joe Onorato46b0d682010-11-22 17:37:27 -0800425 // What we do when the user long presses on home
426 private int mLongPressOnHomeBehavior = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800427
Winson Chung9112ec32011-06-27 13:15:32 -0700428 // Screenshot trigger states
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700429 // Time to volume and power must be pressed within this interval of each other.
430 private static final long SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS = 150;
Winson Chung1cea2f32012-10-08 20:42:01 -0700431 // Increase the chord delay when taking a screenshot from the keyguard
432 private static final float KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER = 2.5f;
Christopher Tatee90585f2012-03-05 18:56:25 -0800433 private boolean mScreenshotChordEnabled;
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700434 private boolean mVolumeDownKeyTriggered;
435 private long mVolumeDownKeyTime;
436 private boolean mVolumeDownKeyConsumedByScreenshotChord;
437 private boolean mVolumeUpKeyTriggered;
438 private boolean mPowerKeyTriggered;
439 private long mPowerKeyTime;
Winson Chung9112ec32011-06-27 13:15:32 -0700440
Christopher Tate5e08af02012-09-21 17:17:22 -0700441 SettingsObserver mSettingsObserver;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800442 ShortcutManager mShortcutManager;
443 PowerManager.WakeLock mBroadcastWakeLock;
Jeff Brown40013652012-05-16 21:22:36 -0700444 boolean mHavePendingMediaKeyRepeatWithWakeLock;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800445
Justin Kohd378ad72013-04-01 12:18:26 -0700446 // Maps global key codes to the components that will handle them.
447 private GlobalKeyManager mGlobalKeyManager;
448
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700449 // Fallback actions by key code.
450 private final SparseArray<KeyCharacterMap.FallbackAction> mFallbackActions =
451 new SparseArray<KeyCharacterMap.FallbackAction>();
Jeff Brown49ed71d2010-12-06 17:13:33 -0800452
Jeff Brown70825162012-03-28 17:27:48 -0700453 private static final int MSG_ENABLE_POINTER_LOCATION = 1;
454 private static final int MSG_DISABLE_POINTER_LOCATION = 2;
Jeff Brown40013652012-05-16 21:22:36 -0700455 private static final int MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK = 3;
456 private static final int MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK = 4;
Jeff Brown70825162012-03-28 17:27:48 -0700457
458 private class PolicyHandler extends Handler {
459 @Override
460 public void handleMessage(Message msg) {
461 switch (msg.what) {
462 case MSG_ENABLE_POINTER_LOCATION:
463 enablePointerLocation();
464 break;
465 case MSG_DISABLE_POINTER_LOCATION:
466 disablePointerLocation();
467 break;
Jeff Brown40013652012-05-16 21:22:36 -0700468 case MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK:
469 dispatchMediaKeyWithWakeLock((KeyEvent)msg.obj);
470 break;
471 case MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK:
472 dispatchMediaKeyRepeatWithWakeLock((KeyEvent)msg.obj);
473 break;
Jeff Brown70825162012-03-28 17:27:48 -0700474 }
475 }
476 }
477
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800478 private UEventObserver mHDMIObserver = new UEventObserver() {
479 @Override
480 public void onUEvent(UEventObserver.UEvent event) {
481 setHdmiPlugged("1".equals(event.get("SWITCH_STATE")));
482 }
483 };
484
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800485 class SettingsObserver extends ContentObserver {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800486 SettingsObserver(Handler handler) {
487 super(handler);
488 }
David Brownbaf8d092010-03-08 21:52:59 -0800489
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800490 void observe() {
Christopher Tate5e08af02012-09-21 17:17:22 -0700491 // Observe all users' changes
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800492 ContentResolver resolver = mContext.getContentResolver();
493 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700494 Settings.System.END_BUTTON_BEHAVIOR), false, this,
495 UserHandle.USER_ALL);
David Brownbaf8d092010-03-08 21:52:59 -0800496 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700497 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR), false, this,
498 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800499 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700500 Settings.System.ACCELEROMETER_ROTATION), false, this,
501 UserHandle.USER_ALL);
Mike Lockwood28569302010-01-28 11:54:40 -0500502 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700503 Settings.System.USER_ROTATION), false, this,
504 UserHandle.USER_ALL);
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400505 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700506 Settings.System.SCREEN_OFF_TIMEOUT), false, this,
507 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800508 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700509 Settings.System.POINTER_LOCATION), false, this,
510 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800511 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700512 Settings.Secure.DEFAULT_INPUT_METHOD), false, this,
513 UserHandle.USER_ALL);
Dianne Hackborn03759ed2009-03-27 16:04:08 -0700514 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700515 "fancy_rotation_anim"), false, this,
516 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800517 updateSettings();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800518 }
519
520 @Override public void onChange(boolean selfChange) {
Dianne Hackbornc777e072010-02-12 13:07:59 -0800521 updateSettings();
Jeff Brown01a98dd2011-09-20 15:08:29 -0700522 updateRotation(false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800523 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800524 }
525
526 class MyOrientationListener extends WindowOrientationListener {
Craig Mautnereee29c42013-01-17 14:44:34 -0800527 MyOrientationListener(Context context, Handler handler) {
528 super(context, handler);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800529 }
530
531 @Override
Jeff Brownc0347aa2011-09-23 17:26:09 -0700532 public void onProposedRotationChanged(int rotation) {
533 if (localLOGV) Log.v(TAG, "onProposedRotationChanged, rotation=" + rotation);
Jeff Brown01a98dd2011-09-20 15:08:29 -0700534 updateRotation(false);
535 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800536 }
537 MyOrientationListener mOrientationListener;
538
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700539 IStatusBarService getStatusBarService() {
540 synchronized (mServiceAquireLock) {
541 if (mStatusBarService == null) {
542 mStatusBarService = IStatusBarService.Stub.asInterface(
543 ServiceManager.getService("statusbar"));
544 }
545 return mStatusBarService;
546 }
547 }
548
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700549 /*
550 * We always let the sensor be switched on by default except when
551 * the user has explicitly disabled sensor based rotation or when the
552 * screen is switched off.
553 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700554 boolean needSensorRunningLp() {
Dianne Hackborne5439f22010-10-02 16:53:50 -0700555 if (mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
556 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
557 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT
558 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800559 // If the application has explicitly requested to follow the
560 // orientation, then we need to turn the sensor or.
561 return true;
562 }
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700563 if ((mCarDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_CAR) ||
Jeff Brown1a693182011-11-08 14:44:16 -0800564 (mDeskDockEnablesAccelerometer && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
565 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
566 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK))) {
Mike Lockwoode9867d22009-09-20 01:59:02 -0400567 // enable accelerometer if we are docked in a dock that enables accelerometer
568 // orientation management,
569 return true;
570 }
Jeff Brown207673cd2012-06-05 17:47:11 -0700571 if (mUserRotationMode == USER_ROTATION_LOCKED) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800572 // If the setting for using the sensor by default is enabled, then
573 // we will always leave it on. Note that the user could go to
574 // a window that forces an orientation that does not use the
575 // sensor and in theory we could turn it off... however, when next
576 // turning it on we won't have a good value for the current
577 // orientation for a little bit, which can cause orientation
578 // changes to lag, so we'd like to keep it always on. (It will
579 // still be turned off when the screen is off.)
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700580 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800581 }
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700582 return true;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800583 }
584
585 /*
586 * Various use cases for invoking this function
587 * screen turning off, should always disable listeners if already enabled
588 * screen turned on and current app has sensor based orientation, enable listeners
589 * if not already enabled
590 * screen turned on and current app does not have sensor orientation, disable listeners if
591 * already enabled
592 * screen turning on and current app has sensor based orientation, enable listeners if needed
593 * screen turning on and current app has nosensor based orientation, do nothing
594 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700595 void updateOrientationListenerLp() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800596 if (!mOrientationListener.canDetectOrientation()) {
597 // If sensor is turned off or nonexistent for some reason
598 return;
599 }
600 //Could have been invoked due to screen turning on or off or
601 //change of the currently visible window's orientation
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -0700602 if (localLOGV) Log.v(TAG, "Screen status="+mScreenOnEarly+
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800603 ", current orientation="+mCurrentAppOrientation+
604 ", SensorEnabled="+mOrientationSensorEnabled);
605 boolean disable = true;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -0700606 if (mScreenOnEarly) {
The Android Open Source Project0727d222009-03-11 12:11:58 -0700607 if (needSensorRunningLp()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800608 disable = false;
609 //enable listener if not already enabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700610 if (!mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800611 mOrientationListener.enable();
Dianne Hackborn05726582009-09-22 17:28:24 -0700612 if(localLOGV) Log.v(TAG, "Enabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800613 mOrientationSensorEnabled = true;
614 }
615 }
616 }
617 //check if sensors need to be disabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700618 if (disable && mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800619 mOrientationListener.disable();
Dianne Hackborn05726582009-09-22 17:28:24 -0700620 if(localLOGV) Log.v(TAG, "Disabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800621 mOrientationSensorEnabled = false;
622 }
623 }
624
Jeff Brown4d396052010-10-29 21:50:21 -0700625 private void interceptPowerKeyDown(boolean handled) {
626 mPowerKeyHandled = handled;
627 if (!handled) {
628 mHandler.postDelayed(mPowerLongPress, ViewConfiguration.getGlobalActionKeyTimeout());
629 }
630 }
631
632 private boolean interceptPowerKeyUp(boolean canceled) {
633 if (!mPowerKeyHandled) {
634 mHandler.removeCallbacks(mPowerLongPress);
635 return !canceled;
Jeff Brown4d396052010-10-29 21:50:21 -0700636 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700637 return false;
638 }
639
640 private void cancelPendingPowerKeyAction() {
641 if (!mPowerKeyHandled) {
642 mHandler.removeCallbacks(mPowerLongPress);
643 }
Jeff Brownff204712011-10-25 21:27:54 -0700644 if (mPowerKeyTriggered) {
645 mPendingPowerKeyUpCanceled = true;
646 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700647 }
648
649 private void interceptScreenshotChord() {
Christopher Tatee90585f2012-03-05 18:56:25 -0800650 if (mScreenshotChordEnabled
651 && mVolumeDownKeyTriggered && mPowerKeyTriggered && !mVolumeUpKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700652 final long now = SystemClock.uptimeMillis();
653 if (now <= mVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS
654 && now <= mPowerKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) {
655 mVolumeDownKeyConsumedByScreenshotChord = true;
656 cancelPendingPowerKeyAction();
657
Jeff Sharkey2991fa32012-12-05 18:06:43 -0800658 mHandler.postDelayed(mScreenshotRunnable, getScreenshotChordLongPressDelay());
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700659 }
660 }
661 }
662
Winson Chung1cea2f32012-10-08 20:42:01 -0700663 private long getScreenshotChordLongPressDelay() {
664 if (mKeyguardMediator.isShowing()) {
665 // Double the time it takes to take a screenshot from the keyguard
666 return (long) (KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER *
667 ViewConfiguration.getGlobalActionKeyTimeout());
Winson Chung1cea2f32012-10-08 20:42:01 -0700668 }
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800669 return ViewConfiguration.getGlobalActionKeyTimeout();
Winson Chung1cea2f32012-10-08 20:42:01 -0700670 }
671
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700672 private void cancelPendingScreenshotChordAction() {
Jeff Sharkey2991fa32012-12-05 18:06:43 -0800673 mHandler.removeCallbacks(mScreenshotRunnable);
Jeff Brown4d396052010-10-29 21:50:21 -0700674 }
675
676 private final Runnable mPowerLongPress = new Runnable() {
Craig Mautnerf1b67412012-09-19 13:18:29 -0700677 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800678 public void run() {
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700679 // The context isn't read
680 if (mLongPressOnPowerBehavior < 0) {
Jeff Brown850c5b72012-10-01 15:17:22 -0700681 mLongPressOnPowerBehavior = mContext.getResources().getInteger(
682 com.android.internal.R.integer.config_longPressOnPowerBehavior);
Joe Onoratod208e702010-10-08 16:22:43 -0400683 }
Jeff Brown850c5b72012-10-01 15:17:22 -0700684 int resolvedBehavior = mLongPressOnPowerBehavior;
685 if (FactoryTest.isLongPressOnPowerOffEnabled()) {
686 resolvedBehavior = LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM;
687 }
688
689 switch (resolvedBehavior) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700690 case LONG_PRESS_POWER_NOTHING:
691 break;
692 case LONG_PRESS_POWER_GLOBAL_ACTIONS:
693 mPowerKeyHandled = true;
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -0700694 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
695 performAuditoryFeedbackForAccessibilityIfNeed();
696 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700697 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
698 showGlobalActionsDialog();
699 break;
700 case LONG_PRESS_POWER_SHUT_OFF:
Jeff Brown9a538ee2012-08-20 14:56:57 -0700701 case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM:
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700702 mPowerKeyHandled = true;
703 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
704 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
Jeff Brown850c5b72012-10-01 15:17:22 -0700705 mWindowManagerFuncs.shutdown(resolvedBehavior == LONG_PRESS_POWER_SHUT_OFF);
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700706 break;
707 }
708 }
709 };
710
Jeff Sharkey2991fa32012-12-05 18:06:43 -0800711 private final Runnable mScreenshotRunnable = new Runnable() {
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800712 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700713 public void run() {
714 takeScreenshot();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800715 }
716 };
717
718 void showGlobalActionsDialog() {
719 if (mGlobalActions == null) {
Jeff Brown7304c342012-05-11 18:42:42 -0700720 mGlobalActions = new GlobalActions(mContext, mWindowManagerFuncs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800721 }
Mike Lockwood3a74bd32011-08-12 13:55:22 -0700722 final boolean keyguardShowing = keyguardIsShowingTq();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800723 mGlobalActions.showDialog(keyguardShowing, isDeviceProvisioned());
724 if (keyguardShowing) {
725 // since it took two seconds of long press to bring this up,
726 // poke the wake lock so they have some time to see the dialog.
Jeff Brown3dc524b2012-09-30 19:49:11 -0700727 mKeyguardMediator.userActivity();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800728 }
729 }
730
731 boolean isDeviceProvisioned() {
Jeff Brownbf6f6f92012-09-25 15:03:20 -0700732 return Settings.Global.getInt(
733 mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800734 }
735
Patrick Dubroyece94522011-02-23 18:35:01 -0800736 private void handleLongPressOnHome() {
Jim Milleree969aa2010-08-26 20:17:43 -0700737 // We can't initialize this in init() since the configuration hasn't been loaded yet.
Joe Onorato46b0d682010-11-22 17:37:27 -0800738 if (mLongPressOnHomeBehavior < 0) {
739 mLongPressOnHomeBehavior
Joe Onorato50262e52010-11-26 14:04:54 -0800740 = mContext.getResources().getInteger(R.integer.config_longPressOnHomeBehavior);
Joe Onorato46b0d682010-11-22 17:37:27 -0800741 if (mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING ||
Michael Jurka3b1fc472011-06-13 10:54:40 -0700742 mLongPressOnHomeBehavior > LONG_PRESS_HOME_RECENT_SYSTEM_UI) {
Joe Onorato46b0d682010-11-22 17:37:27 -0800743 mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
744 }
745 }
746
747 if (mLongPressOnHomeBehavior != LONG_PRESS_HOME_NOTHING) {
748 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
749 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_RECENT_APPS);
Patrick Dubroyece94522011-02-23 18:35:01 -0800750
751 // Eat the longpress so it won't dismiss the recent apps dialog when
752 // the user lets go of the home key
Michael Jurka7f2668c2012-03-27 07:49:52 -0700753 mHomeLongPressed = true;
Jim Millere6ad1a82010-08-20 19:25:39 -0700754 try {
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700755 IStatusBarService statusbar = getStatusBarService();
756 if (statusbar != null) {
757 statusbar.toggleRecentApps();
758 }
Michael Jurka3b1fc472011-06-13 10:54:40 -0700759 } catch (RemoteException e) {
760 Slog.e(TAG, "RemoteException when showing recent apps", e);
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700761 // re-acquire status bar service next time it is needed.
762 mStatusBarService = null;
Jim Millere6ad1a82010-08-20 19:25:39 -0700763 }
764 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800765 }
Patrick Dubroyece94522011-02-23 18:35:01 -0800766
767 /**
Jeff Brown68b909d2011-12-07 16:36:01 -0800768 * Create (if necessary) and show or dismiss the recent apps dialog according
769 * according to the requested behavior.
Patrick Dubroyece94522011-02-23 18:35:01 -0800770 */
Jeff Brown68b909d2011-12-07 16:36:01 -0800771 void showOrHideRecentAppsDialog(final int behavior) {
Jeff Brownda3d5a92011-03-29 15:11:34 -0700772 mHandler.post(new Runnable() {
773 @Override
774 public void run() {
775 if (mRecentAppsDialog == null) {
Jeff Brown54875002011-04-06 15:33:01 -0700776 mRecentAppsDialog = new RecentApplicationsDialog(mContext);
Jeff Brownda3d5a92011-03-29 15:11:34 -0700777 }
Jeff Brown54875002011-04-06 15:33:01 -0700778 if (mRecentAppsDialog.isShowing()) {
Jeff Brown68b909d2011-12-07 16:36:01 -0800779 switch (behavior) {
780 case RECENT_APPS_BEHAVIOR_SHOW_OR_DISMISS:
Jeff Brown602ab322012-05-16 13:33:47 -0700781 case RECENT_APPS_BEHAVIOR_DISMISS:
Jeff Brown68b909d2011-12-07 16:36:01 -0800782 mRecentAppsDialog.dismiss();
783 break;
784 case RECENT_APPS_BEHAVIOR_DISMISS_AND_SWITCH:
785 mRecentAppsDialog.dismissAndSwitch();
786 break;
787 case RECENT_APPS_BEHAVIOR_EXIT_TOUCH_MODE_AND_SHOW:
788 default:
789 break;
Jeff Brown54875002011-04-06 15:33:01 -0700790 }
791 } else {
Jeff Brown68b909d2011-12-07 16:36:01 -0800792 switch (behavior) {
793 case RECENT_APPS_BEHAVIOR_SHOW_OR_DISMISS:
794 mRecentAppsDialog.show();
795 break;
796 case RECENT_APPS_BEHAVIOR_EXIT_TOUCH_MODE_AND_SHOW:
797 try {
798 mWindowManager.setInTouchMode(false);
799 } catch (RemoteException e) {
800 }
801 mRecentAppsDialog.show();
802 break;
Jeff Brown602ab322012-05-16 13:33:47 -0700803 case RECENT_APPS_BEHAVIOR_DISMISS:
Jeff Brown68b909d2011-12-07 16:36:01 -0800804 case RECENT_APPS_BEHAVIOR_DISMISS_AND_SWITCH:
805 default:
806 break;
807 }
Jeff Brown54875002011-04-06 15:33:01 -0700808 }
Jeff Brownda3d5a92011-03-29 15:11:34 -0700809 }
810 });
Patrick Dubroyece94522011-02-23 18:35:01 -0800811 }
Jeff Brownda3d5a92011-03-29 15:11:34 -0700812
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800813 /** {@inheritDoc} */
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800814 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800815 public void init(Context context, IWindowManager windowManager,
Jeff Brown96307042012-07-27 15:51:34 -0700816 WindowManagerFuncs windowManagerFuncs) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800817 mContext = context;
818 mWindowManager = windowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700819 mWindowManagerFuncs = windowManagerFuncs;
Mike Lockwoodd747dc82011-09-13 16:28:22 -0400820 mHeadless = "1".equals(SystemProperties.get("ro.config.headless", "0"));
821 if (!mHeadless) {
Mike Lockwood3a74bd32011-08-12 13:55:22 -0700822 // don't create KeyguardViewMediator if headless
Jim Miller9c7e6302012-08-29 13:48:34 -0700823 mKeyguardMediator = new KeyguardViewMediator(context, null);
Mike Lockwood3a74bd32011-08-12 13:55:22 -0700824 }
Jeff Brown70825162012-03-28 17:27:48 -0700825 mHandler = new PolicyHandler();
Craig Mautnereee29c42013-01-17 14:44:34 -0800826 mOrientationListener = new MyOrientationListener(mContext, mHandler);
Jeff Brownc0347aa2011-09-23 17:26:09 -0700827 try {
828 mOrientationListener.setCurrentRotation(windowManager.getRotation());
829 } catch (RemoteException ex) { }
Christopher Tate5e08af02012-09-21 17:17:22 -0700830 mSettingsObserver = new SettingsObserver(mHandler);
831 mSettingsObserver.observe();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800832 mShortcutManager = new ShortcutManager(context, mHandler);
833 mShortcutManager.observe();
834 mHomeIntent = new Intent(Intent.ACTION_MAIN, null);
835 mHomeIntent.addCategory(Intent.CATEGORY_HOME);
836 mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
837 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700838 mCarDockIntent = new Intent(Intent.ACTION_MAIN, null);
839 mCarDockIntent.addCategory(Intent.CATEGORY_CAR_DOCK);
840 mCarDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
841 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
842 mDeskDockIntent = new Intent(Intent.ACTION_MAIN, null);
843 mDeskDockIntent.addCategory(Intent.CATEGORY_DESK_DOCK);
844 mDeskDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
845 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Jim Millere6ad1a82010-08-20 19:25:39 -0700846
Jeff Brown96307042012-07-27 15:51:34 -0700847 mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
848 mBroadcastWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800849 "PhoneWindowManager.mBroadcastWakeLock");
850 mEnableShiftMenuBugReports = "1".equals(SystemProperties.get("ro.debuggable"));
Dianne Hackborn2862fff2009-09-15 22:56:29 -0700851 mLidOpenRotation = readRotation(
Mike Lockwood2d1efbd2009-09-16 12:15:53 -0400852 com.android.internal.R.integer.config_lidOpenRotation);
853 mCarDockRotation = readRotation(
854 com.android.internal.R.integer.config_carDockRotation);
855 mDeskDockRotation = readRotation(
856 com.android.internal.R.integer.config_deskDockRotation);
Mike Lockwoode9867d22009-09-20 01:59:02 -0400857 mCarDockEnablesAccelerometer = mContext.getResources().getBoolean(
858 com.android.internal.R.bool.config_carDockEnablesAccelerometer);
859 mDeskDockEnablesAccelerometer = mContext.getResources().getBoolean(
860 com.android.internal.R.bool.config_deskDockEnablesAccelerometer);
Dianne Hackborn2862fff2009-09-15 22:56:29 -0700861 mLidKeyboardAccessibility = mContext.getResources().getInteger(
862 com.android.internal.R.integer.config_lidKeyboardAccessibility);
863 mLidNavigationAccessibility = mContext.getResources().getInteger(
864 com.android.internal.R.integer.config_lidNavigationAccessibility);
Jeff Brownc458ce92012-04-30 14:58:40 -0700865 mLidControlsSleep = mContext.getResources().getBoolean(
866 com.android.internal.R.bool.config_lidControlsSleep);
Mike Lockwood1753f7f2009-08-24 14:49:07 -0700867 // register for dock events
Dianne Hackborn78968392010-03-04 20:47:56 -0800868 IntentFilter filter = new IntentFilter();
869 filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE);
870 filter.addAction(UiModeManager.ACTION_EXIT_CAR_MODE);
871 filter.addAction(UiModeManager.ACTION_ENTER_DESK_MODE);
872 filter.addAction(UiModeManager.ACTION_EXIT_DESK_MODE);
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700873 filter.addAction(Intent.ACTION_DOCK_EVENT);
874 Intent intent = context.registerReceiver(mDockReceiver, filter);
875 if (intent != null) {
876 // Retrieve current sticky dock event broadcast.
877 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
878 Intent.EXTRA_DOCK_STATE_UNDOCKED);
879 }
Daniel Sandler7e37df52011-11-16 22:08:23 -0800880
Jeff Brown6aaf2952012-10-05 16:01:08 -0700881 // register for dream-related broadcasts
882 filter = new IntentFilter();
883 filter.addAction(Intent.ACTION_DREAMING_STARTED);
884 filter.addAction(Intent.ACTION_DREAMING_STOPPED);
885 context.registerReceiver(mDreamReceiver, filter);
886
Christopher Tate5e08af02012-09-21 17:17:22 -0700887 // register for multiuser-relevant broadcasts
888 filter = new IntentFilter(Intent.ACTION_USER_SWITCHED);
889 context.registerReceiver(mMultiuserReceiver, filter);
890
Jeff Brownc2346132012-04-13 01:55:38 -0700891 mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700892 mLongPressVibePattern = getLongIntArray(mContext.getResources(),
893 com.android.internal.R.array.config_longPressVibePattern);
894 mVirtualKeyVibePattern = getLongIntArray(mContext.getResources(),
895 com.android.internal.R.array.config_virtualKeyVibePattern);
Amith Yamasanic33cb712010-02-10 15:21:49 -0800896 mKeyboardTapVibePattern = getLongIntArray(mContext.getResources(),
897 com.android.internal.R.array.config_keyboardTapVibePattern);
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700898 mSafeModeDisabledVibePattern = getLongIntArray(mContext.getResources(),
899 com.android.internal.R.array.config_safeModeDisabledVibePattern);
900 mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(),
901 com.android.internal.R.array.config_safeModeEnabledVibePattern);
Daniel Sandler40427442010-07-16 11:44:52 -0400902
Christopher Tatee90585f2012-03-05 18:56:25 -0800903 mScreenshotChordEnabled = mContext.getResources().getBoolean(
904 com.android.internal.R.bool.config_enableScreenshotChord);
905
Justin Kohd378ad72013-04-01 12:18:26 -0700906 mGlobalKeyManager = new GlobalKeyManager(mContext);
907
Joe Onoratoea495d42011-04-06 11:41:11 -0700908 // Controls rotation and the like.
909 initializeHdmiState();
Dianne Hackborn40011092011-09-22 13:37:48 -0700910
911 // Match current screen state.
912 if (mPowerManager.isScreenOn()) {
913 screenTurningOn(null);
914 } else {
915 screenTurnedOff(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
916 }
Mike Lockwood1753f7f2009-08-24 14:49:07 -0700917 }
918
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800919 @Override
Dianne Hackborndde331c2012-08-03 14:01:57 -0700920 public void setInitialDisplaySize(Display display, int width, int height, int density) {
Dianne Hackbornc652de82013-02-15 16:32:56 -0800921 if (display.getDisplayId() != Display.DEFAULT_DISPLAY) {
922 throw new IllegalArgumentException("Can only set the default display");
923 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700924 mDisplay = display;
925
926 int shortSize, longSize;
Dianne Hackborn9d132642011-04-21 17:26:39 -0700927 if (width > height) {
Dianne Hackborn81e56d52011-05-26 00:55:58 -0700928 shortSize = height;
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700929 longSize = width;
Dianne Hackborn9d132642011-04-21 17:26:39 -0700930 mLandscapeRotation = Surface.ROTATION_0;
931 mSeascapeRotation = Surface.ROTATION_180;
932 if (mContext.getResources().getBoolean(
933 com.android.internal.R.bool.config_reverseDefaultRotation)) {
934 mPortraitRotation = Surface.ROTATION_90;
935 mUpsideDownRotation = Surface.ROTATION_270;
936 } else {
937 mPortraitRotation = Surface.ROTATION_270;
938 mUpsideDownRotation = Surface.ROTATION_90;
939 }
940 } else {
Dianne Hackborn81e56d52011-05-26 00:55:58 -0700941 shortSize = width;
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700942 longSize = height;
Dianne Hackborn9d132642011-04-21 17:26:39 -0700943 mPortraitRotation = Surface.ROTATION_0;
944 mUpsideDownRotation = Surface.ROTATION_180;
945 if (mContext.getResources().getBoolean(
946 com.android.internal.R.bool.config_reverseDefaultRotation)) {
947 mLandscapeRotation = Surface.ROTATION_270;
948 mSeascapeRotation = Surface.ROTATION_90;
949 } else {
950 mLandscapeRotation = Surface.ROTATION_90;
951 mSeascapeRotation = Surface.ROTATION_270;
952 }
953 }
Dianne Hackborn81e56d52011-05-26 00:55:58 -0700954
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700955 mStatusBarHeight = mContext.getResources().getDimensionPixelSize(
956 com.android.internal.R.dimen.status_bar_height);
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700957
Daniel Sandler9f65c4c2012-04-26 01:35:35 -0400958 // Height of the navigation bar when presented horizontally at bottom
959 mNavigationBarHeightForRotation[mPortraitRotation] =
960 mNavigationBarHeightForRotation[mUpsideDownRotation] =
Daniel Sandler4a066c52012-04-20 14:49:13 -0400961 mContext.getResources().getDimensionPixelSize(
962 com.android.internal.R.dimen.navigation_bar_height);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -0400963 mNavigationBarHeightForRotation[mLandscapeRotation] =
964 mNavigationBarHeightForRotation[mSeascapeRotation] =
965 mContext.getResources().getDimensionPixelSize(
966 com.android.internal.R.dimen.navigation_bar_height_landscape);
967
968 // Width of the navigation bar when presented vertically along one side
969 mNavigationBarWidthForRotation[mPortraitRotation] =
970 mNavigationBarWidthForRotation[mUpsideDownRotation] =
971 mNavigationBarWidthForRotation[mLandscapeRotation] =
972 mNavigationBarWidthForRotation[mSeascapeRotation] =
Daniel Sandler4a066c52012-04-20 14:49:13 -0400973 mContext.getResources().getDimensionPixelSize(
974 com.android.internal.R.dimen.navigation_bar_width);
975
976 // SystemUI (status bar) layout policy
Dianne Hackborndde331c2012-08-03 14:01:57 -0700977 int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / density;
Daniel Sandler4a066c52012-04-20 14:49:13 -0400978
979 if (shortSizeDp < 600) {
980 // 0-599dp: "phone" UI with a separate status & navigation bar
981 mHasSystemNavBar = false;
982 mNavigationBarCanMove = true;
983 } else if (shortSizeDp < 720) {
Daniel Sandleref863702012-07-11 10:03:34 -0400984 // 600+dp: "phone" UI with modifications for larger screens
Daniel Sandler4a066c52012-04-20 14:49:13 -0400985 mHasSystemNavBar = false;
986 mNavigationBarCanMove = false;
Daniel Sandler4a066c52012-04-20 14:49:13 -0400987 }
Daniel Sandler36412a72011-08-04 09:35:13 -0400988
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700989 if (!mHasSystemNavBar) {
990 mHasNavigationBar = mContext.getResources().getBoolean(
991 com.android.internal.R.bool.config_showNavigationBar);
992 // Allow a system property to override this. Used by the emulator.
993 // See also hasNavigationBar().
994 String navBarOverride = SystemProperties.get("qemu.hw.mainkeys");
995 if (! "".equals(navBarOverride)) {
996 if (navBarOverride.equals("1")) mHasNavigationBar = false;
997 else if (navBarOverride.equals("0")) mHasNavigationBar = true;
998 }
999 } else {
1000 mHasNavigationBar = false;
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04001001 }
1002
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001003 if (mHasSystemNavBar) {
1004 // The system bar is always at the bottom. If you are watching
1005 // a video in landscape, we don't need to hide it if we can still
1006 // show a 16:9 aspect ratio with it.
Dianne Hackborndde331c2012-08-03 14:01:57 -07001007 int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / density;
Daniel Sandler4a066c52012-04-20 14:49:13 -04001008 int barHeightDp = mNavigationBarHeightForRotation[mLandscapeRotation]
Dianne Hackborndde331c2012-08-03 14:01:57 -07001009 * DisplayMetrics.DENSITY_DEFAULT / density;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001010 int aspect = ((shortSizeDp-barHeightDp) * 16) / longSizeDp;
1011 // We have computed the aspect ratio with the bar height taken
1012 // out to be 16:aspect. If this is less than 9, then hiding
1013 // the navigation bar will provide more useful space for wide
1014 // screen movies.
1015 mCanHideNavigationBar = aspect < 9;
1016 } else if (mHasNavigationBar) {
1017 // The navigation bar is at the right in landscape; it seems always
1018 // useful to hide it for showing a video.
1019 mCanHideNavigationBar = true;
1020 } else {
1021 mCanHideNavigationBar = false;
1022 }
Erik Gilling9a41ef82011-09-26 19:21:03 -07001023
Jeff Brown27f1d672012-10-17 18:32:34 -07001024 // For demo purposes, allow the rotation of the HDMI display to be controlled.
1025 // By default, HDMI locks rotation to landscape.
Erik Gilling9a41ef82011-09-26 19:21:03 -07001026 if ("portrait".equals(SystemProperties.get("persist.demo.hdmirotation"))) {
1027 mHdmiRotation = mPortraitRotation;
1028 } else {
1029 mHdmiRotation = mLandscapeRotation;
1030 }
Jeff Brown74bea062012-10-25 12:16:10 -07001031 mHdmiRotationLock = SystemProperties.getBoolean("persist.demo.hdmirotationlock", false);
Dianne Hackborn9d132642011-04-21 17:26:39 -07001032 }
1033
Dianne Hackbornc652de82013-02-15 16:32:56 -08001034 @Override
1035 public void setDisplayOverscan(Display display, int left, int top, int right, int bottom) {
1036 if (display.getDisplayId() == Display.DEFAULT_DISPLAY) {
1037 mOverscanLeft = left;
1038 mOverscanTop = top;
1039 mOverscanRight = right;
1040 mOverscanBottom = bottom;
1041 }
1042 }
1043
Dianne Hackbornc777e072010-02-12 13:07:59 -08001044 public void updateSettings() {
1045 ContentResolver resolver = mContext.getContentResolver();
1046 boolean updateRotation = false;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001047 synchronized (mLock) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001048 mEndcallBehavior = Settings.System.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001049 Settings.System.END_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001050 Settings.System.END_BUTTON_BEHAVIOR_DEFAULT,
1051 UserHandle.USER_CURRENT);
1052 mIncallPowerBehavior = Settings.Secure.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001053 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001054 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT,
1055 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001056
Jeff Brown207673cd2012-06-05 17:47:11 -07001057 // Configure rotation lock.
Christopher Tate5e08af02012-09-21 17:17:22 -07001058 int userRotation = Settings.System.getIntForUser(resolver,
1059 Settings.System.USER_ROTATION, Surface.ROTATION_0,
1060 UserHandle.USER_CURRENT);
Jeff Brown207673cd2012-06-05 17:47:11 -07001061 if (mUserRotation != userRotation) {
1062 mUserRotation = userRotation;
1063 updateRotation = true;
1064 }
Christopher Tate5e08af02012-09-21 17:17:22 -07001065 int userRotationMode = Settings.System.getIntForUser(resolver,
1066 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
Jeff Brown207673cd2012-06-05 17:47:11 -07001067 WindowManagerPolicy.USER_ROTATION_FREE :
1068 WindowManagerPolicy.USER_ROTATION_LOCKED;
1069 if (mUserRotationMode != userRotationMode) {
1070 mUserRotationMode = userRotationMode;
1071 updateRotation = true;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001072 updateOrientationListenerLp();
1073 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001074
Dianne Hackbornc777e072010-02-12 13:07:59 -08001075 if (mSystemReady) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001076 int pointerLocation = Settings.System.getIntForUser(resolver,
1077 Settings.System.POINTER_LOCATION, 0, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001078 if (mPointerLocationMode != pointerLocation) {
1079 mPointerLocationMode = pointerLocation;
Jeff Brown70825162012-03-28 17:27:48 -07001080 mHandler.sendEmptyMessage(pointerLocation != 0 ?
1081 MSG_ENABLE_POINTER_LOCATION : MSG_DISABLE_POINTER_LOCATION);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001082 }
1083 }
1084 // use screen off timeout setting as the timeout for the lockscreen
Christopher Tate5e08af02012-09-21 17:17:22 -07001085 mLockScreenTimeout = Settings.System.getIntForUser(resolver,
1086 Settings.System.SCREEN_OFF_TIMEOUT, 0, UserHandle.USER_CURRENT);
1087 String imId = Settings.Secure.getStringForUser(resolver,
1088 Settings.Secure.DEFAULT_INPUT_METHOD, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001089 boolean hasSoftInput = imId != null && imId.length() > 0;
1090 if (mHasSoftInput != hasSoftInput) {
1091 mHasSoftInput = hasSoftInput;
1092 updateRotation = true;
1093 }
1094 }
1095 if (updateRotation) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07001096 updateRotation(true);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001097 }
Jeff Brown70825162012-03-28 17:27:48 -07001098 }
1099
1100 private void enablePointerLocation() {
1101 if (mPointerLocationView == null) {
1102 mPointerLocationView = new PointerLocationView(mContext);
1103 mPointerLocationView.setPrintCoords(false);
1104
Dianne Hackbornc777e072010-02-12 13:07:59 -08001105 WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
1106 WindowManager.LayoutParams.MATCH_PARENT,
1107 WindowManager.LayoutParams.MATCH_PARENT);
Jeff Brown3b2b3542010-10-15 00:54:27 -07001108 lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001109 lp.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN
1110 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
1111 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1112 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
Jeff Brown90fc9052012-10-01 14:44:24 -07001113 if (ActivityManager.isHighEndGfx()) {
1114 lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
1115 lp.privateFlags |=
1116 WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED;
1117 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001118 lp.format = PixelFormat.TRANSLUCENT;
1119 lp.setTitle("PointerLocation");
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001120 WindowManager wm = (WindowManager)
Dianne Hackbornc777e072010-02-12 13:07:59 -08001121 mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Browncc4f7db2011-08-30 20:34:48 -07001122 lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL;
Jeff Brown70825162012-03-28 17:27:48 -07001123 wm.addView(mPointerLocationView, lp);
1124
Jeff Brownac143512012-04-05 18:57:33 -07001125 mPointerLocationInputChannel =
1126 mWindowManagerFuncs.monitorInput("PointerLocationView");
1127 mPointerLocationInputEventReceiver =
1128 new PointerLocationInputEventReceiver(mPointerLocationInputChannel,
1129 Looper.myLooper(), mPointerLocationView);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001130 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001131 }
Jeff Brown70825162012-03-28 17:27:48 -07001132
1133 private void disablePointerLocation() {
1134 if (mPointerLocationInputEventReceiver != null) {
1135 mPointerLocationInputEventReceiver.dispose();
1136 mPointerLocationInputEventReceiver = null;
1137 }
1138
1139 if (mPointerLocationInputChannel != null) {
1140 mPointerLocationInputChannel.dispose();
1141 mPointerLocationInputChannel = null;
1142 }
1143
1144 if (mPointerLocationView != null) {
1145 WindowManager wm = (WindowManager)
1146 mContext.getSystemService(Context.WINDOW_SERVICE);
1147 wm.removeView(mPointerLocationView);
1148 mPointerLocationView = null;
1149 }
1150 }
1151
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001152 private int readRotation(int resID) {
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001153 try {
1154 int rotation = mContext.getResources().getInteger(resID);
1155 switch (rotation) {
1156 case 0:
1157 return Surface.ROTATION_0;
1158 case 90:
1159 return Surface.ROTATION_90;
1160 case 180:
1161 return Surface.ROTATION_180;
1162 case 270:
1163 return Surface.ROTATION_270;
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001164 }
1165 } catch (Resources.NotFoundException e) {
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001166 // fall through
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001167 }
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001168 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001169 }
1170
1171 /** {@inheritDoc} */
Craig Mautner88400d32012-09-30 12:35:45 -07001172 @Override
Dianne Hackbornc2293022013-02-06 23:14:49 -08001173 public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001174 int type = attrs.type;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001175
1176 outAppOp[0] = AppOpsManager.OP_NONE;
1177
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001178 if (type < WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW
1179 || type > WindowManager.LayoutParams.LAST_SYSTEM_WINDOW) {
Jeff Brown98365d72012-08-19 20:30:52 -07001180 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001181 }
1182 String permission = null;
1183 switch (type) {
1184 case TYPE_TOAST:
1185 // XXX right now the app process has complete control over
1186 // this... should introduce a token to let the system
1187 // monitor/control what they are doing.
1188 break;
Daniel Sandler7d276c32012-01-30 14:33:52 -05001189 case TYPE_DREAM:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001190 case TYPE_INPUT_METHOD:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001191 case TYPE_WALLPAPER:
1192 // The window manager will check these.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001193 break;
1194 case TYPE_PHONE:
1195 case TYPE_PRIORITY_PHONE:
1196 case TYPE_SYSTEM_ALERT:
1197 case TYPE_SYSTEM_ERROR:
1198 case TYPE_SYSTEM_OVERLAY:
1199 permission = android.Manifest.permission.SYSTEM_ALERT_WINDOW;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001200 outAppOp[0] = AppOpsManager.OP_SYSTEM_ALERT_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001201 break;
1202 default:
1203 permission = android.Manifest.permission.INTERNAL_SYSTEM_WINDOW;
1204 }
1205 if (permission != null) {
1206 if (mContext.checkCallingOrSelfPermission(permission)
1207 != PackageManager.PERMISSION_GRANTED) {
Jeff Brown98365d72012-08-19 20:30:52 -07001208 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001209 }
1210 }
Jeff Brown98365d72012-08-19 20:30:52 -07001211 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001212 }
Craig Mautner88400d32012-09-30 12:35:45 -07001213
1214 @Override
1215 public boolean checkShowToOwnerOnly(WindowManager.LayoutParams attrs) {
1216
1217 // If this switch statement is modified, modify the comment in the declarations of
1218 // the type in {@link WindowManager.LayoutParams} as well.
1219 switch (attrs.type) {
1220 default:
1221 // These are the windows that by default are shown only to the user that created
1222 // them. If this needs to be overridden, set
1223 // {@link WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS} in
1224 // {@link WindowManager.LayoutParams}. Note that permission
1225 // {@link android.Manifest.permission.INTERNAL_SYSTEM_WINDOW} is required as well.
1226 if ((attrs.privateFlags & PRIVATE_FLAG_SHOW_FOR_ALL_USERS) == 0) {
1227 return true;
1228 }
1229 break;
1230
1231 // These are the windows that by default are shown to all users. However, to
1232 // protect against spoofing, check permissions below.
1233 case TYPE_APPLICATION_STARTING:
1234 case TYPE_BOOT_PROGRESS:
1235 case TYPE_DISPLAY_OVERLAY:
1236 case TYPE_HIDDEN_NAV_CONSUMER:
1237 case TYPE_KEYGUARD:
1238 case TYPE_KEYGUARD_DIALOG:
1239 case TYPE_MAGNIFICATION_OVERLAY:
1240 case TYPE_NAVIGATION_BAR:
1241 case TYPE_NAVIGATION_BAR_PANEL:
1242 case TYPE_PHONE:
1243 case TYPE_POINTER:
1244 case TYPE_PRIORITY_PHONE:
1245 case TYPE_RECENTS_OVERLAY:
1246 case TYPE_SEARCH_BAR:
1247 case TYPE_STATUS_BAR:
1248 case TYPE_STATUS_BAR_PANEL:
1249 case TYPE_STATUS_BAR_SUB_PANEL:
1250 case TYPE_SYSTEM_DIALOG:
1251 case TYPE_UNIVERSE_BACKGROUND:
1252 case TYPE_VOLUME_OVERLAY:
1253 break;
1254 }
1255
1256 // Check if third party app has set window to system window type.
1257 return mContext.checkCallingOrSelfPermission(
1258 android.Manifest.permission.INTERNAL_SYSTEM_WINDOW)
1259 != PackageManager.PERMISSION_GRANTED;
1260 }
1261
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001262 public void adjustWindowParamsLw(WindowManager.LayoutParams attrs) {
1263 switch (attrs.type) {
1264 case TYPE_SYSTEM_OVERLAY:
Jeff Brown3b2b3542010-10-15 00:54:27 -07001265 case TYPE_SECURE_SYSTEM_OVERLAY:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001266 case TYPE_TOAST:
1267 // These types of windows can't receive input events.
1268 attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1269 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001270 attrs.flags &= ~WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001271 break;
1272 }
1273 }
1274
1275 void readLidState() {
Jeff Brown2e7760e2012-04-11 15:14:55 -07001276 mLidState = mWindowManagerFuncs.getLidState();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001277 }
1278
Jeff Browndaa37532012-05-01 15:54:03 -07001279 private boolean isHidden(int accessibilityMode) {
1280 switch (accessibilityMode) {
1281 case 1:
1282 return mLidState == LID_CLOSED;
1283 case 2:
1284 return mLidState == LID_OPEN;
1285 default:
1286 return false;
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001287 }
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001288 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001289
Jeff Browndaa37532012-05-01 15:54:03 -07001290 private boolean isBuiltInKeyboardVisible() {
1291 return mHaveBuiltInKeyboard && !isHidden(mLidKeyboardAccessibility);
Jeff Brownc458ce92012-04-30 14:58:40 -07001292 }
1293
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001294 /** {@inheritDoc} */
Jeff Browndaa37532012-05-01 15:54:03 -07001295 public void adjustConfigurationLw(Configuration config, int keyboardPresence,
1296 int navigationPresence) {
1297 mHaveBuiltInKeyboard = (keyboardPresence & PRESENCE_INTERNAL) != 0;
1298
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001299 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07001300 applyLidSwitchState();
Jeff Brownd04a88c2011-01-16 14:05:47 -08001301
Jeff Browndaa37532012-05-01 15:54:03 -07001302 if (config.keyboard == Configuration.KEYBOARD_NOKEYS
1303 || (keyboardPresence == PRESENCE_INTERNAL
1304 && isHidden(mLidKeyboardAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001305 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_YES;
Jeff Browndaa37532012-05-01 15:54:03 -07001306 if (!mHasSoftInput) {
1307 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_YES;
1308 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001309 }
1310
Jeff Browndaa37532012-05-01 15:54:03 -07001311 if (config.navigation == Configuration.NAVIGATION_NONAV
1312 || (navigationPresence == PRESENCE_INTERNAL
1313 && isHidden(mLidNavigationAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001314 config.navigationHidden = Configuration.NAVIGATIONHIDDEN_YES;
Jeff Brownd04a88c2011-01-16 14:05:47 -08001315 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001316 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001317
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001318 /** {@inheritDoc} */
1319 public int windowTypeToLayerLw(int type) {
1320 if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001321 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001322 }
1323 switch (type) {
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001324 case TYPE_UNIVERSE_BACKGROUND:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001325 return 1;
1326 case TYPE_WALLPAPER:
1327 // wallpaper is at the bottom, though the window manager may move it.
1328 return 2;
1329 case TYPE_PHONE:
1330 return 3;
1331 case TYPE_SEARCH_BAR:
1332 return 4;
Craig Mautner88400d32012-09-30 12:35:45 -07001333 case TYPE_RECENTS_OVERLAY:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001334 case TYPE_SYSTEM_DIALOG:
1335 return 5;
1336 case TYPE_TOAST:
1337 // toasts and the plugged-in battery thing
1338 return 6;
1339 case TYPE_PRIORITY_PHONE:
1340 // SIM errors and unlock. Not sure if this really should be in a high layer.
1341 return 7;
1342 case TYPE_DREAM:
1343 // used for Dreams (screensavers with TYPE_DREAM windows)
1344 return 8;
1345 case TYPE_SYSTEM_ALERT:
1346 // like the ANR / app crashed dialogs
1347 return 9;
1348 case TYPE_INPUT_METHOD:
1349 // on-screen keyboards and other such input method user interfaces go here.
1350 return 10;
1351 case TYPE_INPUT_METHOD_DIALOG:
1352 // on-screen keyboards and other such input method user interfaces go here.
1353 return 11;
1354 case TYPE_KEYGUARD:
1355 // the keyguard; nothing on top of these can take focus, since they are
1356 // responsible for power management when displayed.
1357 return 12;
1358 case TYPE_KEYGUARD_DIALOG:
1359 return 13;
1360 case TYPE_STATUS_BAR_SUB_PANEL:
1361 return 14;
1362 case TYPE_STATUS_BAR:
1363 return 15;
1364 case TYPE_STATUS_BAR_PANEL:
1365 return 16;
1366 case TYPE_VOLUME_OVERLAY:
1367 // the on-screen volume indicator and controller shown when the user
1368 // changes the device volume
1369 return 17;
1370 case TYPE_SYSTEM_OVERLAY:
1371 // the on-screen volume indicator and controller shown when the user
1372 // changes the device volume
1373 return 18;
1374 case TYPE_NAVIGATION_BAR:
1375 // the navigation bar, if available, shows atop most things
1376 return 19;
1377 case TYPE_NAVIGATION_BAR_PANEL:
1378 // some panels (e.g. search) need to show on top of the navigation bar
1379 return 20;
1380 case TYPE_SYSTEM_ERROR:
1381 // system-level error dialogs
1382 return 21;
1383 case TYPE_MAGNIFICATION_OVERLAY:
1384 // used to highlight the magnified portion of a display
1385 return 22;
1386 case TYPE_DISPLAY_OVERLAY:
1387 // used to simulate secondary display devices
1388 return 23;
1389 case TYPE_DRAG:
1390 // the drag layer: input for drag-and-drop is associated with this window,
1391 // which sits above all other focusable windows
1392 return 24;
1393 case TYPE_SECURE_SYSTEM_OVERLAY:
1394 return 25;
1395 case TYPE_BOOT_PROGRESS:
1396 return 26;
1397 case TYPE_POINTER:
1398 // the (mouse) pointer layer
1399 return 27;
1400 case TYPE_HIDDEN_NAV_CONSUMER:
1401 return 28;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001402 }
1403 Log.e(TAG, "Unknown window type: " + type);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001404 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001405 }
1406
1407 /** {@inheritDoc} */
1408 public int subWindowTypeToLayerLw(int type) {
1409 switch (type) {
1410 case TYPE_APPLICATION_PANEL:
1411 case TYPE_APPLICATION_ATTACHED_DIALOG:
1412 return APPLICATION_PANEL_SUBLAYER;
1413 case TYPE_APPLICATION_MEDIA:
1414 return APPLICATION_MEDIA_SUBLAYER;
Dianne Hackborn5cb8d792009-05-21 17:34:15 -07001415 case TYPE_APPLICATION_MEDIA_OVERLAY:
1416 return APPLICATION_MEDIA_OVERLAY_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001417 case TYPE_APPLICATION_SUB_PANEL:
1418 return APPLICATION_SUB_PANEL_SUBLAYER;
1419 }
1420 Log.e(TAG, "Unknown sub-window type: " + type);
1421 return 0;
1422 }
1423
Dianne Hackbornabe0da02009-09-18 01:55:39 -07001424 public int getMaxWallpaperLayer() {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001425 return windowTypeToLayerLw(TYPE_STATUS_BAR);
Dianne Hackbornabe0da02009-09-18 01:55:39 -07001426 }
1427
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001428 public int getAboveUniverseLayer() {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001429 return windowTypeToLayerLw(TYPE_SYSTEM_ERROR);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001430 }
1431
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001432 public boolean hasSystemNavBar() {
1433 return mHasSystemNavBar;
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001434 }
1435
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001436 public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07001437 if (mHasNavigationBar) {
1438 // For a basic navigation bar, when we are in landscape mode we place
1439 // the navigation bar to the side.
Daniel Sandler4a066c52012-04-20 14:49:13 -04001440 if (mNavigationBarCanMove && fullWidth > fullHeight) {
1441 return fullWidth - mNavigationBarWidthForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07001442 }
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001443 }
1444 return fullWidth;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001445 }
1446
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001447 public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07001448 if (mHasSystemNavBar) {
1449 // For the system navigation bar, we always place it at the bottom.
Daniel Sandler4a066c52012-04-20 14:49:13 -04001450 return fullHeight - mNavigationBarHeightForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07001451 }
1452 if (mHasNavigationBar) {
1453 // For a basic navigation bar, when we are in portrait mode we place
1454 // the navigation bar to the bottom.
Daniel Sandler4a066c52012-04-20 14:49:13 -04001455 if (!mNavigationBarCanMove || fullWidth < fullHeight) {
1456 return fullHeight - mNavigationBarHeightForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07001457 }
1458 }
1459 return fullHeight;
Dianne Hackborn69cb8752011-05-19 18:13:32 -07001460 }
1461
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001462 public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation) {
1463 return getNonDecorDisplayWidth(fullWidth, fullHeight, rotation);
Dianne Hackborn69cb8752011-05-19 18:13:32 -07001464 }
1465
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001466 public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07001467 // If we don't have a system nav bar, then there is a separate status
1468 // bar at the top of the display. We don't count that as part of the
1469 // fixed decor, since it can hide; however, for purposes of configurations,
1470 // we do want to exclude it since applications can't generally use that part
1471 // of the screen.
1472 if (!mHasSystemNavBar) {
1473 return getNonDecorDisplayHeight(fullWidth, fullHeight, rotation) - mStatusBarHeight;
1474 }
1475 return getNonDecorDisplayHeight(fullWidth, fullHeight, rotation);
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001476 }
1477
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001478 @Override
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07001479 public boolean doesForceHide(WindowState win, WindowManager.LayoutParams attrs) {
1480 return attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD;
1481 }
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001482
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001483 @Override
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07001484 public boolean canBeForceHidden(WindowState win, WindowManager.LayoutParams attrs) {
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001485 switch (attrs.type) {
1486 case TYPE_STATUS_BAR:
1487 case TYPE_NAVIGATION_BAR:
1488 case TYPE_WALLPAPER:
1489 case TYPE_DREAM:
1490 case TYPE_UNIVERSE_BACKGROUND:
1491 case TYPE_KEYGUARD:
1492 return false;
1493 default:
1494 return true;
1495 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07001496 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001497
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001498 /** {@inheritDoc} */
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001499 @Override
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07001500 public View addStartingWindow(IBinder appToken, String packageName, int theme,
1501 CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes,
1502 int icon, int windowFlags) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001503 if (!SHOW_STARTING_ANIMATIONS) {
1504 return null;
1505 }
1506 if (packageName == null) {
1507 return null;
1508 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001509
Mathias Jeppssond1443e92012-08-24 15:25:32 +02001510 WindowManager wm = null;
1511 View view = null;
1512
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001513 try {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001514 Context context = mContext;
Craig Mautner6fbda632012-07-03 09:26:39 -07001515 if (DEBUG_STARTING_WINDOW) Slog.d(TAG, "addStartingWindow " + packageName
1516 + ": nonLocalizedLabel=" + nonLocalizedLabel + " theme="
1517 + Integer.toHexString(theme));
Dianne Hackborn247fe742011-01-08 17:25:57 -08001518 if (theme != context.getThemeResId() || labelRes != 0) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001519 try {
1520 context = context.createPackageContext(packageName, 0);
Dianne Hackborn247fe742011-01-08 17:25:57 -08001521 context.setTheme(theme);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001522 } catch (PackageManager.NameNotFoundException e) {
1523 // Ignore
1524 }
1525 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001526
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001527 Window win = PolicyManager.makeNewWindow(context);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001528 final TypedArray ta = win.getWindowStyle();
1529 if (ta.getBoolean(
1530 com.android.internal.R.styleable.Window_windowDisablePreview, false)
1531 || ta.getBoolean(
1532 com.android.internal.R.styleable.Window_windowShowWallpaper,false)) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001533 return null;
1534 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001535
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001536 Resources r = context.getResources();
1537 win.setTitle(r.getText(labelRes, nonLocalizedLabel));
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001538
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001539 win.setType(
1540 WindowManager.LayoutParams.TYPE_APPLICATION_STARTING);
1541 // Force the window flags: this is a fake window, so it is not really
1542 // touchable or focusable by the user. We also add in the ALT_FOCUSABLE_IM
1543 // flag because we do know that the next window will take input
1544 // focus, so we want to get the IME window up on top of us right away.
1545 win.setFlags(
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08001546 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001547 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
1548 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
1549 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08001550 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001551 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
1552 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
1553 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001554
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07001555 if (!compatInfo.supportsScreen()) {
1556 win.addFlags(WindowManager.LayoutParams.FLAG_COMPATIBLE_WINDOW);
1557 }
1558
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001559 win.setLayout(WindowManager.LayoutParams.MATCH_PARENT,
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07001560 WindowManager.LayoutParams.MATCH_PARENT);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001561
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001562 final WindowManager.LayoutParams params = win.getAttributes();
1563 params.token = appToken;
1564 params.packageName = packageName;
1565 params.windowAnimations = win.getWindowStyle().getResourceId(
1566 com.android.internal.R.styleable.Window_windowAnimationStyle, 0);
Dianne Hackborn5d927c22011-09-02 12:22:18 -07001567 params.privateFlags |=
1568 WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED;
Craig Mautner88400d32012-09-30 12:35:45 -07001569 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001570 params.setTitle("Starting " + packageName);
1571
Mathias Jeppssond1443e92012-08-24 15:25:32 +02001572 wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
1573 view = win.getDecorView();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001574
1575 if (win.isFloating()) {
1576 // Whoops, there is no way to display an animation/preview
1577 // of such a thing! After all that work... let's skip it.
1578 // (Note that we must do this here because it is in
1579 // getDecorView() where the theme is evaluated... maybe
1580 // we should peek the floating attribute from the theme
1581 // earlier.)
1582 return null;
1583 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001584
Craig Mautner6fbda632012-07-03 09:26:39 -07001585 if (DEBUG_STARTING_WINDOW) Slog.d(
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001586 TAG, "Adding starting window for " + packageName
1587 + " / " + appToken + ": "
1588 + (view.getParent() != null ? view : null));
1589
1590 wm.addView(view, params);
1591
1592 // Only return the view if it was successfully added to the
1593 // window manager... which we can tell by it having a parent.
1594 return view.getParent() != null ? view : null;
Jeff Brown98365d72012-08-19 20:30:52 -07001595 } catch (WindowManager.BadTokenException e) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001596 // ignore
1597 Log.w(TAG, appToken + " already running, starting window not displayed");
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001598 } catch (RuntimeException e) {
1599 // don't crash if something else bad happens, for example a
1600 // failure loading resources because we are loading from an app
1601 // on external storage that has been unmounted.
1602 Log.w(TAG, appToken + " failed creating starting window", e);
Mathias Jeppssond1443e92012-08-24 15:25:32 +02001603 } finally {
1604 if (view != null && view.getParent() == null) {
1605 Log.w(TAG, "view not successfully added to wm, removing view");
1606 wm.removeViewImmediate(view);
1607 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001608 }
1609
1610 return null;
1611 }
1612
1613 /** {@inheritDoc} */
1614 public void removeStartingWindow(IBinder appToken, View window) {
Craig Mautner6fbda632012-07-03 09:26:39 -07001615 if (DEBUG_STARTING_WINDOW) {
1616 RuntimeException e = new RuntimeException("here");
1617 e.fillInStackTrace();
1618 Log.v(TAG, "Removing starting window for " + appToken + ": " + window, e);
1619 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001620
1621 if (window != null) {
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001622 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001623 wm.removeView(window);
1624 }
1625 }
1626
1627 /**
1628 * Preflight adding a window to the system.
1629 *
1630 * Currently enforces that three window types are singletons:
1631 * <ul>
1632 * <li>STATUS_BAR_TYPE</li>
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001633 * <li>KEYGUARD_TYPE</li>
1634 * </ul>
1635 *
1636 * @param win The window to be added
1637 * @param attrs Information about the window to be added
1638 *
Jeff Brown98365d72012-08-19 20:30:52 -07001639 * @return If ok, WindowManagerImpl.ADD_OKAY. If too many singletons,
1640 * WindowManagerImpl.ADD_MULTIPLE_SINGLETON
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001641 */
1642 public int prepareAddWindowLw(WindowState win, WindowManager.LayoutParams attrs) {
1643 switch (attrs.type) {
1644 case TYPE_STATUS_BAR:
Joe Onorato8bc6c512010-06-04 16:21:12 -04001645 mContext.enforceCallingOrSelfPermission(
1646 android.Manifest.permission.STATUS_BAR_SERVICE,
1647 "PhoneWindowManager");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001648 if (mStatusBar != null) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001649 if (mStatusBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07001650 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001651 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001652 }
1653 mStatusBar = win;
1654 break;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04001655 case TYPE_NAVIGATION_BAR:
1656 mContext.enforceCallingOrSelfPermission(
1657 android.Manifest.permission.STATUS_BAR_SERVICE,
1658 "PhoneWindowManager");
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001659 if (mNavigationBar != null) {
1660 if (mNavigationBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07001661 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001662 }
1663 }
Daniel Sandler8956dbb2011-04-22 07:55:02 -04001664 mNavigationBar = win;
1665 if (DEBUG_LAYOUT) Log.i(TAG, "NAVIGATION BAR: " + mNavigationBar);
1666 break;
Jim Millere898ac52012-04-06 17:10:57 -07001667 case TYPE_NAVIGATION_BAR_PANEL:
1668 mContext.enforceCallingOrSelfPermission(
1669 android.Manifest.permission.STATUS_BAR_SERVICE,
1670 "PhoneWindowManager");
1671 break;
Dianne Hackborn08743722009-12-21 12:16:51 -08001672 case TYPE_STATUS_BAR_PANEL:
Joe Onorato8bc6c512010-06-04 16:21:12 -04001673 mContext.enforceCallingOrSelfPermission(
1674 android.Manifest.permission.STATUS_BAR_SERVICE,
1675 "PhoneWindowManager");
Dianne Hackborn08743722009-12-21 12:16:51 -08001676 break;
Joe Onorato29fc2c92010-11-24 10:26:50 -08001677 case TYPE_STATUS_BAR_SUB_PANEL:
1678 mContext.enforceCallingOrSelfPermission(
1679 android.Manifest.permission.STATUS_BAR_SERVICE,
1680 "PhoneWindowManager");
Joe Onorato29fc2c92010-11-24 10:26:50 -08001681 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001682 case TYPE_KEYGUARD:
1683 if (mKeyguard != null) {
Jeff Brown98365d72012-08-19 20:30:52 -07001684 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001685 }
1686 mKeyguard = win;
1687 break;
1688 }
Jeff Brown98365d72012-08-19 20:30:52 -07001689 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001690 }
1691
1692 /** {@inheritDoc} */
1693 public void removeWindowLw(WindowState win) {
1694 if (mStatusBar == win) {
1695 mStatusBar = null;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04001696 } else if (mKeyguard == win) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001697 mKeyguard = null;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04001698 } else if (mNavigationBar == win) {
1699 mNavigationBar = null;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001700 }
1701 }
1702
1703 static final boolean PRINT_ANIM = false;
1704
1705 /** {@inheritDoc} */
Craig Mautner4b71aa12012-12-27 17:20:01 -08001706 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001707 public int selectAnimationLw(WindowState win, int transit) {
1708 if (PRINT_ANIM) Log.i(TAG, "selectAnimation in " + win
1709 + ": transit=" + transit);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001710 if (win == mStatusBar) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08001711 if (transit == TRANSIT_EXIT
1712 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001713 return R.anim.dock_top_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001714 } else if (transit == TRANSIT_ENTER
1715 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001716 return R.anim.dock_top_enter;
1717 }
1718 } else if (win == mNavigationBar) {
1719 // This can be on either the bottom or the right.
1720 if (mNavigationBarOnBottom) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08001721 if (transit == TRANSIT_EXIT
1722 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001723 return R.anim.dock_bottom_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001724 } else if (transit == TRANSIT_ENTER
1725 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001726 return R.anim.dock_bottom_enter;
1727 }
1728 } else {
Craig Mautner4b71aa12012-12-27 17:20:01 -08001729 if (transit == TRANSIT_EXIT
1730 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001731 return R.anim.dock_right_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001732 } else if (transit == TRANSIT_ENTER
1733 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001734 return R.anim.dock_right_enter;
1735 }
1736 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08001737 }
1738
1739 if (transit == TRANSIT_PREVIEW_DONE) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001740 if (win.hasAppShownWindows()) {
1741 if (PRINT_ANIM) Log.i(TAG, "**** STARTING EXIT");
1742 return com.android.internal.R.anim.app_starting_exit;
1743 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07001744 } else if (win.getAttrs().type == TYPE_DREAM && mDreamingLockscreen
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001745 && transit == TRANSIT_ENTER) {
1746 // Special case: we are animating in a dream, while the keyguard
1747 // is shown. We don't want an animation on the dream, because
1748 // we need it shown immediately with the keyguard animating away
1749 // to reveal it.
1750 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001751 }
1752
1753 return 0;
1754 }
1755
Craig Mautner3c174372013-02-21 17:54:37 -08001756 @Override
1757 public void selectRotationAnimationLw(int anim[]) {
1758 if (PRINT_ANIM) Slog.i(TAG, "selectRotationAnimation mTopFullscreen="
1759 + mTopFullscreenOpaqueWindowState + " rotationAnimation="
1760 + (mTopFullscreenOpaqueWindowState == null ?
1761 "0" : mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation));
1762 if (mTopFullscreenOpaqueWindowState != null && mTopIsFullscreen) {
1763 switch (mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation) {
1764 case ROTATION_ANIMATION_CROSSFADE:
1765 anim[0] = R.anim.rotation_animation_xfade_exit;
1766 anim[1] = R.anim.rotation_animation_enter;
1767 break;
1768 case ROTATION_ANIMATION_JUMPCUT:
1769 anim[0] = R.anim.rotation_animation_jump_exit;
1770 anim[1] = R.anim.rotation_animation_enter;
1771 break;
1772 case ROTATION_ANIMATION_ROTATE:
1773 default:
1774 anim[0] = anim[1] = 0;
1775 break;
1776 }
1777 } else {
1778 anim[0] = anim[1] = 0;
1779 }
1780 }
1781
1782 @Override
1783 public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId,
1784 boolean forceDefault) {
1785 switch (exitAnimId) {
1786 case R.anim.rotation_animation_xfade_exit:
1787 case R.anim.rotation_animation_jump_exit:
1788 // These are the only cases that matter.
1789 if (forceDefault) {
1790 return false;
1791 }
1792 int anim[] = new int[2];
1793 selectRotationAnimationLw(anim);
1794 return (exitAnimId == anim[0] && enterAnimId == anim[1]);
1795 default:
1796 return true;
1797 }
1798 }
1799
1800 @Override
Dianne Hackborn0c2acff2012-04-12 15:17:07 -07001801 public Animation createForceHideEnterAnimation(boolean onWallpaper) {
1802 return AnimationUtils.loadAnimation(mContext, onWallpaper
1803 ? com.android.internal.R.anim.lock_screen_wallpaper_behind_enter
1804 : com.android.internal.R.anim.lock_screen_behind_enter);
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07001805 }
John Spurlockc8b46ca2013-04-08 12:59:26 -04001806
1807 private static void awakenDreams() {
1808 IDreamManager dreamManager = getDreamManager();
1809 if (dreamManager != null) {
1810 try {
1811 dreamManager.awaken();
1812 } catch (RemoteException e) {
1813 // fine, stay asleep then
1814 }
1815 }
1816 }
1817
1818 static IDreamManager getDreamManager() {
1819 return IDreamManager.Stub.asInterface(
1820 ServiceManager.checkService(DreamService.DREAM_SERVICE));
1821 }
1822
Jeff Brown4d396052010-10-29 21:50:21 -07001823 static ITelephony getTelephonyService() {
Mike Lockwoodf5f4ec92011-11-08 14:05:31 -08001824 return ITelephony.Stub.asInterface(
Jeff Brown4d396052010-10-29 21:50:21 -07001825 ServiceManager.checkService(Context.TELEPHONY_SERVICE));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001826 }
1827
Jeff Brown4d396052010-10-29 21:50:21 -07001828 static IAudioService getAudioService() {
1829 IAudioService audioService = IAudioService.Stub.asInterface(
1830 ServiceManager.checkService(Context.AUDIO_SERVICE));
1831 if (audioService == null) {
1832 Log.w(TAG, "Unable to find IAudioService interface.");
1833 }
1834 return audioService;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001835 }
1836
1837 boolean keyguardOn() {
1838 return keyguardIsShowingTq() || inKeyguardRestrictedKeyInputMode();
1839 }
1840
1841 private static final int[] WINDOW_TYPES_WHERE_HOME_DOESNT_WORK = {
1842 WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
1843 WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
1844 };
1845
1846 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001847 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001848 public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001849 final boolean keyguardOn = keyguardOn();
Jeff Brown1f245102010-11-18 20:53:46 -08001850 final int keyCode = event.getKeyCode();
1851 final int repeatCount = event.getRepeatCount();
1852 final int metaState = event.getMetaState();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001853 final int flags = event.getFlags();
Jeff Brown1f245102010-11-18 20:53:46 -08001854 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
1855 final boolean canceled = event.isCanceled();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001856
Jeff Brown40013652012-05-16 21:22:36 -07001857 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001858 Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount="
Jeff Brownfd23e3e2012-05-09 13:34:28 -07001859 + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed
1860 + " canceled=" + canceled);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001861 }
1862
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001863 // If we think we might have a volume down & power key chord on the way
1864 // but we're not sure, then tell the dispatcher to wait a little while and
1865 // try again later before dispatching.
Christopher Tatee90585f2012-03-05 18:56:25 -08001866 if (mScreenshotChordEnabled && (flags & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001867 if (mVolumeDownKeyTriggered && !mPowerKeyTriggered) {
1868 final long now = SystemClock.uptimeMillis();
1869 final long timeoutTime = mVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS;
1870 if (now < timeoutTime) {
1871 return timeoutTime - now;
1872 }
1873 }
1874 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
1875 && mVolumeDownKeyConsumedByScreenshotChord) {
1876 if (!down) {
1877 mVolumeDownKeyConsumedByScreenshotChord = false;
1878 }
1879 return -1;
1880 }
1881 }
1882
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001883 // First we always handle the home key here, so applications
1884 // can never break it, although if keyguard is on, we do let
1885 // it handle it, because that gives us the correct 5 second
1886 // timeout.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001887 if (keyCode == KeyEvent.KEYCODE_HOME) {
Michael Jurka7f2668c2012-03-27 07:49:52 -07001888
Jeff Brown49ed71d2010-12-06 17:13:33 -08001889 // If we have released the home key, and didn't do anything else
1890 // while it was pressed, then it is time to go home!
Michael Jurka7f2668c2012-03-27 07:49:52 -07001891 if (!down) {
1892 final boolean homeWasLongPressed = mHomeLongPressed;
Jeff Brown49ed71d2010-12-06 17:13:33 -08001893 mHomePressed = false;
Michael Jurka7f2668c2012-03-27 07:49:52 -07001894 mHomeLongPressed = false;
1895 if (!homeWasLongPressed) {
Michael Wrightc9ebea72013-01-16 19:25:02 -08001896 if (mLongPressOnHomeBehavior != LONG_PRESS_HOME_NOTHING) {
Michael Jurka01de93d2012-04-13 09:32:47 -07001897 try {
1898 IStatusBarService statusbar = getStatusBarService();
1899 if (statusbar != null) {
1900 statusbar.cancelPreloadRecentApps();
1901 }
1902 } catch (RemoteException e) {
1903 Slog.e(TAG, "RemoteException when showing recent apps", e);
1904 // re-acquire status bar service next time it is needed.
1905 mStatusBarService = null;
Dianne Hackborn42e620c2012-06-24 13:20:51 -07001906 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08001907 }
1908
Michael Jurka7f2668c2012-03-27 07:49:52 -07001909 mHomePressed = false;
1910 if (!canceled) {
1911 // If an incoming call is ringing, HOME is totally disabled.
1912 // (The user is already on the InCallScreen at this point,
1913 // and his ONLY options are to answer or reject the call.)
1914 boolean incomingRinging = false;
1915 try {
1916 ITelephony telephonyService = getTelephonyService();
1917 if (telephonyService != null) {
1918 incomingRinging = telephonyService.isRinging();
1919 }
1920 } catch (RemoteException ex) {
1921 Log.w(TAG, "RemoteException from getPhoneInterface()", ex);
1922 }
1923
1924 if (incomingRinging) {
1925 Log.i(TAG, "Ignoring HOME; there's a ringing incoming call.");
1926 } else {
1927 launchHomeFromHotKey();
1928 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08001929 } else {
Michael Jurka7f2668c2012-03-27 07:49:52 -07001930 Log.i(TAG, "Ignoring HOME; event canceled.");
Jeff Brown49ed71d2010-12-06 17:13:33 -08001931 }
Michael Jurka7f2668c2012-03-27 07:49:52 -07001932 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08001933 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08001934 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001935
1936 // If a system window has focus, then it doesn't make sense
1937 // right now to interact with applications.
1938 WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null;
1939 if (attrs != null) {
1940 final int type = attrs.type;
1941 if (type == WindowManager.LayoutParams.TYPE_KEYGUARD
1942 || type == WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG) {
1943 // the "app" is keyguard, so give it the key
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001944 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001945 }
1946 final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length;
1947 for (int i=0; i<typeCount; i++) {
1948 if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) {
1949 // don't do anything, but also don't pass it to the app
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001950 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001951 }
1952 }
1953 }
Jeff Brown98392ef2011-09-12 18:24:59 -07001954 if (down) {
Michael Jurka40040332012-05-29 08:25:32 -07001955 if (!mHomePressed && mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI) {
Michael Jurka7f2668c2012-03-27 07:49:52 -07001956 try {
Dianne Hackborn42e620c2012-06-24 13:20:51 -07001957 IStatusBarService statusbar = getStatusBarService();
1958 if (statusbar != null) {
1959 statusbar.preloadRecentApps();
1960 }
Michael Jurka7f2668c2012-03-27 07:49:52 -07001961 } catch (RemoteException e) {
1962 Slog.e(TAG, "RemoteException when preloading recent apps", e);
Dianne Hackborn42e620c2012-06-24 13:20:51 -07001963 // re-acquire status bar service next time it is needed.
1964 mStatusBarService = null;
Michael Jurka7f2668c2012-03-27 07:49:52 -07001965 }
1966 }
Jeff Brown98392ef2011-09-12 18:24:59 -07001967 if (repeatCount == 0) {
1968 mHomePressed = true;
1969 } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) {
1970 if (!keyguardOn) {
1971 handleLongPressOnHome();
1972 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001973 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001974 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001975 return -1;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001976 } else if (keyCode == KeyEvent.KEYCODE_MENU) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001977 // Hijack modified menu keys for debugging features
1978 final int chordBug = KeyEvent.META_SHIFT_ON;
1979
1980 if (down && repeatCount == 0) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001981 if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001982 Intent intent = new Intent(Intent.ACTION_BUG_REPORT);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001983 mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT,
1984 null, null, null, 0, null, null);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001985 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001986 } else if (SHOW_PROCESSES_ON_ALT_MENU &&
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001987 (metaState & KeyEvent.META_ALT_ON) == KeyEvent.META_ALT_ON) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001988 Intent service = new Intent();
1989 service.setClassName(mContext, "com.android.server.LoadAverageService");
1990 ContentResolver res = mContext.getContentResolver();
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07001991 boolean shown = Settings.Global.getInt(
1992 res, Settings.Global.SHOW_PROCESSES, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001993 if (!shown) {
1994 mContext.startService(service);
1995 } else {
1996 mContext.stopService(service);
1997 }
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07001998 Settings.Global.putInt(
1999 res, Settings.Global.SHOW_PROCESSES, shown ? 0 : 1);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002000 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002001 }
2002 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002003 } else if (keyCode == KeyEvent.KEYCODE_SEARCH) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002004 if (down) {
2005 if (repeatCount == 0) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002006 mSearchKeyShortcutPending = true;
2007 mConsumeSearchKeyUp = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002008 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002009 } else {
2010 mSearchKeyShortcutPending = false;
2011 if (mConsumeSearchKeyUp) {
2012 mConsumeSearchKeyUp = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002013 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002014 }
2015 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002016 return 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002017 } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) {
Michael Wrightc9ebea72013-01-16 19:25:02 -08002018 if (!keyguardOn) {
2019 try {
2020 IStatusBarService statusbar = getStatusBarService();
2021 if (statusbar != null) {
2022 if (down && repeatCount == 0) {
2023 statusbar.preloadRecentApps();
2024 } else if (!down) {
2025 statusbar.toggleRecentApps();
2026 }
2027 }
2028 } catch (RemoteException e) {
2029 Slog.e(TAG, "RemoteException when preloading recent apps", e);
2030 // re-acquire status bar service next time it is needed.
2031 mStatusBarService = null;
2032 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002033 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002034 return -1;
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002035 } else if (keyCode == KeyEvent.KEYCODE_ASSIST) {
2036 if (down) {
2037 if (repeatCount == 0) {
2038 mAssistKeyLongPressed = false;
2039 } else if (repeatCount == 1) {
2040 mAssistKeyLongPressed = true;
2041 if (!keyguardOn) {
2042 launchAssistLongPressAction();
2043 }
2044 }
2045 } else {
2046 if (mAssistKeyLongPressed) {
2047 mAssistKeyLongPressed = false;
2048 } else {
2049 if (!keyguardOn) {
2050 launchAssistAction();
2051 }
2052 }
2053 }
2054 return -1;
Jeff Sharkey2991fa32012-12-05 18:06:43 -08002055 } else if (keyCode == KeyEvent.KEYCODE_SYSRQ) {
2056 if (down && repeatCount == 0) {
2057 mHandler.post(mScreenshotRunnable);
2058 }
2059 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002060 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002061
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002062 // Shortcuts are invoked through Search+key, so intercept those here
Jeff Browncaab4d02010-12-09 22:13:41 -08002063 // Any printing key that is chorded with Search should be consumed
2064 // even if no shortcut was invoked. This prevents text from being
2065 // inadvertently inserted when using a keyboard that has built-in macro
2066 // shortcut keys (that emit Search+x) and some of them are not registered.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002067 if (mSearchKeyShortcutPending) {
Jeff Browncaab4d02010-12-09 22:13:41 -08002068 final KeyCharacterMap kcm = event.getKeyCharacterMap();
2069 if (kcm.isPrintingKey(keyCode)) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002070 mConsumeSearchKeyUp = true;
2071 mSearchKeyShortcutPending = false;
Jeff Browncaab4d02010-12-09 22:13:41 -08002072 if (down && repeatCount == 0 && !keyguardOn) {
2073 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState);
2074 if (shortcutIntent != null) {
2075 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002076 try {
2077 mContext.startActivity(shortcutIntent);
2078 } catch (ActivityNotFoundException ex) {
2079 Slog.w(TAG, "Dropping shortcut key combination because "
2080 + "the activity to which it is registered was not found: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002081 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode), ex);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002082 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002083 } else {
2084 Slog.i(TAG, "Dropping unregistered shortcut key combination: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002085 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002086 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002087 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002088 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002089 }
2090 }
2091
Jeff Brown68b909d2011-12-07 16:36:01 -08002092 // Invoke shortcuts using Meta.
Jeff Brown602ab322012-05-16 13:33:47 -07002093 if (down && repeatCount == 0 && !keyguardOn
Jeff Brown68b909d2011-12-07 16:36:01 -08002094 && (metaState & KeyEvent.META_META_ON) != 0) {
2095 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brown602ab322012-05-16 13:33:47 -07002096 if (kcm.isPrintingKey(keyCode)) {
2097 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode,
2098 metaState & ~(KeyEvent.META_META_ON
2099 | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON));
2100 if (shortcutIntent != null) {
2101 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2102 try {
2103 mContext.startActivity(shortcutIntent);
2104 } catch (ActivityNotFoundException ex) {
2105 Slog.w(TAG, "Dropping shortcut key combination because "
2106 + "the activity to which it is registered was not found: "
2107 + "META+" + KeyEvent.keyCodeToString(keyCode), ex);
2108 }
2109 return -1;
Jeff Brown68b909d2011-12-07 16:36:01 -08002110 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002111 }
2112 }
2113
Jeff Brown6651a632011-11-28 12:59:11 -08002114 // Handle application launch keys.
Jeff Brown602ab322012-05-16 13:33:47 -07002115 if (down && repeatCount == 0 && !keyguardOn) {
Jeff Brown6651a632011-11-28 12:59:11 -08002116 String category = sApplicationLaunchKeyCategories.get(keyCode);
2117 if (category != null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -08002118 Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category);
Jeff Brown6651a632011-11-28 12:59:11 -08002119 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2120 try {
2121 mContext.startActivity(intent);
2122 } catch (ActivityNotFoundException ex) {
2123 Slog.w(TAG, "Dropping application launch key because "
2124 + "the activity to which it is registered was not found: "
2125 + "keyCode=" + keyCode + ", category=" + category, ex);
2126 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002127 return -1;
Jeff Brown6651a632011-11-28 12:59:11 -08002128 }
2129 }
2130
Jeff Brown68b909d2011-12-07 16:36:01 -08002131 // Display task switcher for ALT-TAB or Meta-TAB.
2132 if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_TAB) {
Jeff Brown602ab322012-05-16 13:33:47 -07002133 if (mRecentAppsDialogHeldModifiers == 0 && !keyguardOn) {
Jeff Brown68b909d2011-12-07 16:36:01 -08002134 final int shiftlessModifiers = event.getModifiers() & ~KeyEvent.META_SHIFT_MASK;
2135 if (KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_ALT_ON)
2136 || KeyEvent.metaStateHasModifiers(
2137 shiftlessModifiers, KeyEvent.META_META_ON)) {
2138 mRecentAppsDialogHeldModifiers = shiftlessModifiers;
2139 showOrHideRecentAppsDialog(RECENT_APPS_BEHAVIOR_EXIT_TOUCH_MODE_AND_SHOW);
2140 return -1;
2141 }
2142 }
2143 } else if (!down && mRecentAppsDialogHeldModifiers != 0
2144 && (metaState & mRecentAppsDialogHeldModifiers) == 0) {
2145 mRecentAppsDialogHeldModifiers = 0;
Jeff Brown602ab322012-05-16 13:33:47 -07002146 showOrHideRecentAppsDialog(keyguardOn ? RECENT_APPS_BEHAVIOR_DISMISS :
2147 RECENT_APPS_BEHAVIOR_DISMISS_AND_SWITCH);
Jeff Brown68b909d2011-12-07 16:36:01 -08002148 }
2149
Jeff Browncf39bdf2012-05-18 14:41:19 -07002150 // Handle keyboard language switching.
2151 if (down && repeatCount == 0
2152 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2153 || (keyCode == KeyEvent.KEYCODE_SPACE
2154 && (metaState & KeyEvent.META_CTRL_MASK) != 0))) {
2155 int direction = (metaState & KeyEvent.META_SHIFT_MASK) != 0 ? -1 : 1;
2156 mWindowManagerFuncs.switchKeyboardLayout(event.getDeviceId(), direction);
2157 return -1;
2158 }
2159 if (mLanguageSwitchKeyPressed && !down
2160 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2161 || keyCode == KeyEvent.KEYCODE_SPACE)) {
2162 mLanguageSwitchKeyPressed = false;
2163 return -1;
2164 }
2165
Justin Kohd378ad72013-04-01 12:18:26 -07002166 if (mGlobalKeyManager.handleGlobalKey(mContext, keyCode, event)) {
2167 return -1;
2168 }
2169
Jeff Brown68b909d2011-12-07 16:36:01 -08002170 // Let the application handle the key.
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002171 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002172 }
2173
Jeff Brown3915bb82010-11-05 15:02:16 -07002174 /** {@inheritDoc} */
2175 @Override
Jeff Brown49ed71d2010-12-06 17:13:33 -08002176 public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown54875002011-04-06 15:33:01 -07002177 // Note: This method is only called if the initial down was unhandled.
Jeff Brown40013652012-05-16 21:22:36 -07002178 if (DEBUG_INPUT) {
Jeff Brown1f245102010-11-18 20:53:46 -08002179 Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction()
2180 + ", flags=" + event.getFlags()
2181 + ", keyCode=" + event.getKeyCode()
2182 + ", scanCode=" + event.getScanCode()
2183 + ", metaState=" + event.getMetaState()
2184 + ", repeatCount=" + event.getRepeatCount()
2185 + ", policyFlags=" + policyFlags);
Jeff Brown3915bb82010-11-05 15:02:16 -07002186 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002187
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002188 KeyEvent fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002189 if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
2190 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002191 final int keyCode = event.getKeyCode();
2192 final int metaState = event.getMetaState();
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002193 final boolean initialDown = event.getAction() == KeyEvent.ACTION_DOWN
2194 && event.getRepeatCount() == 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002195
Jeff Brown54875002011-04-06 15:33:01 -07002196 // Check for fallback actions specified by the key character map.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002197 final FallbackAction fallbackAction;
2198 if (initialDown) {
2199 fallbackAction = kcm.getFallbackAction(keyCode, metaState);
2200 } else {
2201 fallbackAction = mFallbackActions.get(keyCode);
2202 }
2203
2204 if (fallbackAction != null) {
Jeff Brown40013652012-05-16 21:22:36 -07002205 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002206 Slog.d(TAG, "Fallback: keyCode=" + fallbackAction.keyCode
2207 + " metaState=" + Integer.toHexString(fallbackAction.metaState));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002208 }
2209
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002210 final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK;
2211 fallbackEvent = KeyEvent.obtain(
Jeff Brown49ed71d2010-12-06 17:13:33 -08002212 event.getDownTime(), event.getEventTime(),
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002213 event.getAction(), fallbackAction.keyCode,
2214 event.getRepeatCount(), fallbackAction.metaState,
Jeff Brown49ed71d2010-12-06 17:13:33 -08002215 event.getDeviceId(), event.getScanCode(),
2216 flags, event.getSource(), null);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002217
2218 if (!interceptFallback(win, fallbackEvent, policyFlags)) {
2219 fallbackEvent.recycle();
2220 fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002221 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002222
2223 if (initialDown) {
2224 mFallbackActions.put(keyCode, fallbackAction);
2225 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2226 mFallbackActions.remove(keyCode);
2227 fallbackAction.recycle();
2228 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002229 }
2230 }
2231
Jeff Brown40013652012-05-16 21:22:36 -07002232 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002233 if (fallbackEvent == null) {
2234 Slog.d(TAG, "No fallback.");
2235 } else {
2236 Slog.d(TAG, "Performing fallback: " + fallbackEvent);
2237 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002238 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002239 return fallbackEvent;
Jeff Brown3915bb82010-11-05 15:02:16 -07002240 }
2241
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002242 private boolean interceptFallback(WindowState win, KeyEvent fallbackEvent, int policyFlags) {
2243 int actions = interceptKeyBeforeQueueing(fallbackEvent, policyFlags, true);
2244 if ((actions & ACTION_PASS_TO_USER) != 0) {
2245 long delayMillis = interceptKeyBeforeDispatching(
2246 win, fallbackEvent, policyFlags);
2247 if (delayMillis == 0) {
2248 return true;
2249 }
2250 }
2251 return false;
Jeff Brown6f2fba42011-02-19 01:08:02 -08002252 }
2253
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002254 private void launchAssistLongPressAction() {
2255 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
2256 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
2257
2258 // launch the search activity
2259 Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS);
2260 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2261 try {
Jim Miller45308b12012-06-18 19:23:39 -07002262 // TODO: This only stops the factory-installed search manager.
2263 // Need to formalize an API to handle others
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002264 SearchManager searchManager = getSearchManager();
2265 if (searchManager != null) {
2266 searchManager.stopSearch();
2267 }
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07002268 mContext.startActivityAsUser(intent, new UserHandle(UserHandle.USER_CURRENT));
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002269 } catch (ActivityNotFoundException e) {
2270 Slog.w(TAG, "No activity to handle assist long press action.", e);
2271 }
2272 }
2273
2274 private void launchAssistAction() {
2275 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
Amith Yamasanic1d07a42012-08-14 09:32:02 -07002276 Intent intent = ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE))
Dianne Hackbornf9c5e0f2013-01-23 14:39:13 -08002277 .getAssistIntent(mContext, true, UserHandle.USER_CURRENT);
Jim Miller45308b12012-06-18 19:23:39 -07002278 if (intent != null) {
2279 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
2280 | Intent.FLAG_ACTIVITY_SINGLE_TOP
2281 | Intent.FLAG_ACTIVITY_CLEAR_TOP);
2282 try {
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07002283 mContext.startActivityAsUser(intent, new UserHandle(UserHandle.USER_CURRENT));
Jim Miller45308b12012-06-18 19:23:39 -07002284 } catch (ActivityNotFoundException e) {
2285 Slog.w(TAG, "No activity to handle assist action.", e);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002286 }
2287 }
2288 }
2289
2290 private SearchManager getSearchManager() {
2291 if (mSearchManager == null) {
2292 mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
2293 }
2294 return mSearchManager;
2295 }
2296
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002297 /**
2298 * A home key -> launch home action was detected. Take the appropriate action
2299 * given the situation with the keyguard.
2300 */
2301 void launchHomeFromHotKey() {
Mike Lockwood3a74bd32011-08-12 13:55:22 -07002302 if (mKeyguardMediator != null && mKeyguardMediator.isShowingAndNotHidden()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002303 // don't launch home if keyguard showing
Dianne Hackborn39c2d712009-09-22 11:41:31 -07002304 } else if (!mHideLockScreen && mKeyguardMediator.isInputRestricted()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002305 // when in keyguard restricted mode, must first verify unlock
2306 // before launching home
2307 mKeyguardMediator.verifyUnlock(new OnKeyguardExitResult() {
2308 public void onKeyguardExitResult(boolean success) {
2309 if (success) {
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07002310 try {
2311 ActivityManagerNative.getDefault().stopAppSwitches();
2312 } catch (RemoteException e) {
2313 }
Joe Onoratof275f0c2009-11-24 16:11:13 -05002314 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07002315 startDockOrHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002316 }
2317 }
2318 });
2319 } else {
2320 // no keyguard stuff to worry about, just launch home!
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07002321 try {
2322 ActivityManagerNative.getDefault().stopAppSwitches();
2323 } catch (RemoteException e) {
2324 }
Joe Onoratof275f0c2009-11-24 16:11:13 -05002325 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07002326 startDockOrHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002327 }
2328 }
2329
Dianne Hackborne26ab702011-10-16 13:21:33 -07002330 /**
2331 * A delayed callback use to determine when it is okay to re-allow applications
2332 * to use certain system UI flags. This is used to prevent applications from
2333 * spamming system UI changes that prevent the navigation bar from being shown.
2334 */
2335 final Runnable mAllowSystemUiDelay = new Runnable() {
2336 @Override public void run() {
2337 }
2338 };
2339
2340 /**
2341 * Input handler used while nav bar is hidden. Captures any touch on the screen,
2342 * to determine when the nav bar should be shown and prevent applications from
2343 * receiving those touches.
2344 */
Jeff Brown32cbc38552011-12-01 14:01:49 -08002345 final class HideNavInputEventReceiver extends InputEventReceiver {
2346 public HideNavInputEventReceiver(InputChannel inputChannel, Looper looper) {
2347 super(inputChannel, looper);
2348 }
2349
Dianne Hackborndf89e652011-10-06 22:35:11 -07002350 @Override
Jeff Brown32cbc38552011-12-01 14:01:49 -08002351 public void onInputEvent(InputEvent event) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07002352 boolean handled = false;
2353 try {
Jeff Brown4952dfd2011-11-30 19:23:22 -08002354 if (event instanceof MotionEvent
2355 && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
2356 final MotionEvent motionEvent = (MotionEvent)event;
2357 if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07002358 // When the user taps down, we re-show the nav bar.
2359 boolean changed = false;
2360 synchronized (mLock) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002361 // Any user activity always causes us to show the
2362 // navigation controls, if they had been hidden.
2363 // We also clear the low profile and only content
2364 // flags so that tapping on the screen will atomically
2365 // restore all currently hidden screen decorations.
2366 int newVal = mResettingSystemUiFlags |
2367 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
2368 View.SYSTEM_UI_FLAG_LOW_PROFILE |
2369 View.SYSTEM_UI_FLAG_FULLSCREEN;
Dianne Hackborne26ab702011-10-16 13:21:33 -07002370 if (mResettingSystemUiFlags != newVal) {
2371 mResettingSystemUiFlags = newVal;
Dianne Hackborndf89e652011-10-06 22:35:11 -07002372 changed = true;
2373 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07002374 // We don't allow the system's nav bar to be hidden
2375 // again for 1 second, to prevent applications from
2376 // spamming us and keeping it from being shown.
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002377 newVal = mForceClearedSystemUiFlags |
2378 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
Dianne Hackborne26ab702011-10-16 13:21:33 -07002379 if (mForceClearedSystemUiFlags != newVal) {
2380 mForceClearedSystemUiFlags = newVal;
2381 changed = true;
2382 mHandler.postDelayed(new Runnable() {
2383 @Override public void run() {
2384 synchronized (mLock) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002385 // Clear flags.
Dianne Hackborne26ab702011-10-16 13:21:33 -07002386 mForceClearedSystemUiFlags &=
2387 ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
2388 }
2389 mWindowManagerFuncs.reevaluateStatusBarVisibility();
2390 }
2391 }, 1000);
2392 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07002393 }
2394 if (changed) {
2395 mWindowManagerFuncs.reevaluateStatusBarVisibility();
2396 }
2397 }
2398 }
2399 } finally {
Jeff Brown32cbc38552011-12-01 14:01:49 -08002400 finishInputEvent(event, handled);
Dianne Hackborndf89e652011-10-06 22:35:11 -07002401 }
2402 }
Jeff Brown32cbc38552011-12-01 14:01:49 -08002403 }
2404 final InputEventReceiver.Factory mHideNavInputEventReceiverFactory =
2405 new InputEventReceiver.Factory() {
2406 @Override
2407 public InputEventReceiver createInputEventReceiver(
2408 InputChannel inputChannel, Looper looper) {
2409 return new HideNavInputEventReceiver(inputChannel, looper);
2410 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07002411 };
2412
2413 @Override
2414 public int adjustSystemUiVisibilityLw(int visibility) {
2415 // Reset any bits in mForceClearingStatusBarVisibility that
2416 // are now clear.
Dianne Hackborne26ab702011-10-16 13:21:33 -07002417 mResettingSystemUiFlags &= visibility;
Dianne Hackborndf89e652011-10-06 22:35:11 -07002418 // Clear any bits in the new visibility that are currently being
2419 // force cleared, before reporting it.
Dianne Hackborne26ab702011-10-16 13:21:33 -07002420 return visibility & ~mResettingSystemUiFlags
2421 & ~mForceClearedSystemUiFlags;
Dianne Hackborndf89e652011-10-06 22:35:11 -07002422 }
2423
Craig Mautner69b08182012-09-05 13:07:13 -07002424 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002425 public void getContentInsetHintLw(WindowManager.LayoutParams attrs, Rect contentInset) {
2426 final int fl = attrs.flags;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002427 final int systemUiVisibility = (attrs.systemUiVisibility|attrs.subtreeSystemUiVisibility);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002428
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002429 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002430 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002431 int availRight, availBottom;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002432 if (mCanHideNavigationBar &&
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002433 (systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002434 availRight = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
2435 availBottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
2436 } else {
2437 availRight = mRestrictedScreenLeft + mRestrictedScreenWidth;
2438 availBottom = mRestrictedScreenTop + mRestrictedScreenHeight;
2439 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002440 if ((systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
2441 if ((fl & FLAG_FULLSCREEN) != 0) {
2442 contentInset.set(mStableFullscreenLeft, mStableFullscreenTop,
2443 availRight - mStableFullscreenRight,
2444 availBottom - mStableFullscreenBottom);
2445 } else {
2446 contentInset.set(mStableLeft, mStableTop,
2447 availRight - mStableRight, availBottom - mStableBottom);
2448 }
Dianne Hackbornc652de82013-02-15 16:32:56 -08002449 } else if ((fl & FLAG_FULLSCREEN) != 0 || (fl & FLAG_LAYOUT_IN_OVERSCAN) != 0) {
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002450 contentInset.setEmpty();
2451 } else if ((systemUiVisibility & (View.SYSTEM_UI_FLAG_FULLSCREEN
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002452 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)) == 0) {
2453 contentInset.set(mCurLeft, mCurTop,
2454 availRight - mCurRight, availBottom - mCurBottom);
2455 } else {
2456 contentInset.set(mCurLeft, mCurTop,
2457 availRight - mCurRight, availBottom - mCurBottom);
2458 }
2459 return;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002460 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002461 contentInset.setEmpty();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002462 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002463
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002464 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07002465 @Override
2466 public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight,
2467 int displayRotation) {
Dianne Hackbornc652de82013-02-15 16:32:56 -08002468 final int overscanLeft, overscanTop, overscanRight, overscanBottom;
2469 if (isDefaultDisplay) {
2470 switch (displayRotation) {
2471 case Surface.ROTATION_90:
2472 overscanLeft = mOverscanTop;
2473 overscanTop = mOverscanRight;
2474 overscanRight = mOverscanBottom;
2475 overscanBottom = mOverscanLeft;
2476 break;
2477 case Surface.ROTATION_180:
2478 overscanLeft = mOverscanRight;
2479 overscanTop = mOverscanBottom;
2480 overscanRight = mOverscanLeft;
2481 overscanBottom = mOverscanTop;
2482 break;
2483 case Surface.ROTATION_270:
2484 overscanLeft = mOverscanBottom;
2485 overscanTop = mOverscanLeft;
2486 overscanRight = mOverscanTop;
2487 overscanBottom = mOverscanRight;
2488 break;
2489 default:
2490 overscanLeft = mOverscanLeft;
2491 overscanTop = mOverscanTop;
2492 overscanRight = mOverscanRight;
2493 overscanBottom = mOverscanBottom;
2494 break;
2495 }
2496 } else {
2497 overscanLeft = 0;
2498 overscanTop = 0;
2499 overscanRight = 0;
2500 overscanBottom = 0;
2501 }
Dianne Hackborn313440842013-02-19 19:22:59 -08002502 mOverscanScreenLeft = mRestrictedOverscanScreenLeft = 0;
2503 mOverscanScreenTop = mRestrictedOverscanScreenTop = 0;
2504 mOverscanScreenWidth = mRestrictedOverscanScreenWidth = displayWidth;
2505 mOverscanScreenHeight = mRestrictedOverscanScreenHeight = displayHeight;
Dianne Hackbornc652de82013-02-15 16:32:56 -08002506 mSystemLeft = 0;
2507 mSystemTop = 0;
2508 mSystemRight = displayWidth;
2509 mSystemBottom = displayHeight;
2510 mUnrestrictedScreenLeft = overscanLeft;
2511 mUnrestrictedScreenTop = overscanTop;
2512 mUnrestrictedScreenWidth = displayWidth - overscanLeft - overscanRight;
2513 mUnrestrictedScreenHeight = displayHeight - overscanTop - overscanBottom;
2514 mRestrictedScreenLeft = mUnrestrictedScreenLeft;
2515 mRestrictedScreenTop = mUnrestrictedScreenTop;
2516 mRestrictedScreenWidth = mUnrestrictedScreenWidth;
2517 mRestrictedScreenHeight = mUnrestrictedScreenHeight;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002518 mDockLeft = mContentLeft = mStableLeft = mStableFullscreenLeft
Dianne Hackbornc652de82013-02-15 16:32:56 -08002519 = mCurLeft = mUnrestrictedScreenLeft;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002520 mDockTop = mContentTop = mStableTop = mStableFullscreenTop
Dianne Hackbornc652de82013-02-15 16:32:56 -08002521 = mCurTop = mUnrestrictedScreenTop;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002522 mDockRight = mContentRight = mStableRight = mStableFullscreenRight
Dianne Hackbornc652de82013-02-15 16:32:56 -08002523 = mCurRight = displayWidth - overscanRight;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002524 mDockBottom = mContentBottom = mStableBottom = mStableFullscreenBottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08002525 = mCurBottom = displayHeight - overscanBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002526 mDockLayer = 0x10000000;
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002527 mStatusBarLayer = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002528
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002529 // start with the current dock rect, which will be (0,0,displayWidth,displayHeight)
2530 final Rect pf = mTmpParentFrame;
2531 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002532 final Rect of = mTmpOverscanFrame;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002533 final Rect vf = mTmpVisibleFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002534 pf.left = df.left = of.left = vf.left = mDockLeft;
2535 pf.top = df.top = of.top = vf.top = mDockTop;
2536 pf.right = df.right = of.right = vf.right = mDockRight;
2537 pf.bottom = df.bottom = of.bottom = vf.bottom = mDockBottom;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002538
Craig Mautner69b08182012-09-05 13:07:13 -07002539 if (isDefaultDisplay) {
2540 // For purposes of putting out fake window up to steal focus, we will
2541 // drive nav being hidden only by whether it is requested.
2542 boolean navVisible = (mLastSystemUiFlags&View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0;
Dianne Hackborne26ab702011-10-16 13:21:33 -07002543
Craig Mautner69b08182012-09-05 13:07:13 -07002544 // When the navigation bar isn't visible, we put up a fake
2545 // input window to catch all touch events. This way we can
2546 // detect when the user presses anywhere to bring back the nav
2547 // bar and ensure the application doesn't see the event.
2548 if (navVisible) {
2549 if (mHideNavFakeWindow != null) {
2550 mHideNavFakeWindow.dismiss();
2551 mHideNavFakeWindow = null;
2552 }
2553 } else if (mHideNavFakeWindow == null) {
2554 mHideNavFakeWindow = mWindowManagerFuncs.addFakeWindow(
2555 mHandler.getLooper(), mHideNavInputEventReceiverFactory,
2556 "hidden nav", WindowManager.LayoutParams.TYPE_HIDDEN_NAV_CONSUMER,
2557 0, false, false, true);
Dianne Hackborne26ab702011-10-16 13:21:33 -07002558 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07002559
Craig Mautner69b08182012-09-05 13:07:13 -07002560 // For purposes of positioning and showing the nav bar, if we have
2561 // decided that it can't be hidden (because of the screen aspect ratio),
2562 // then take that into account.
2563 navVisible |= !mCanHideNavigationBar;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002564
Craig Mautner69b08182012-09-05 13:07:13 -07002565 if (mNavigationBar != null) {
2566 // Force the navigation bar to its appropriate place and
2567 // size. We need to do this directly, instead of relying on
2568 // it to bubble up from the nav bar, because this needs to
2569 // change atomically with screen rotations.
2570 mNavigationBarOnBottom = (!mNavigationBarCanMove || displayWidth < displayHeight);
2571 if (mNavigationBarOnBottom) {
2572 // It's a system nav bar or a portrait screen; nav bar goes on bottom.
Dianne Hackbornc652de82013-02-15 16:32:56 -08002573 int top = displayHeight - overscanBottom
2574 - mNavigationBarHeightForRotation[displayRotation];
2575 mTmpNavigationFrame.set(0, top, displayWidth, displayHeight - overscanBottom);
Craig Mautner69b08182012-09-05 13:07:13 -07002576 mStableBottom = mStableFullscreenBottom = mTmpNavigationFrame.top;
2577 if (navVisible) {
2578 mNavigationBar.showLw(true);
2579 mDockBottom = mTmpNavigationFrame.top;
Dianne Hackborn313440842013-02-19 19:22:59 -08002580 mRestrictedScreenHeight = mDockBottom - mRestrictedScreenTop;
2581 mRestrictedOverscanScreenHeight = mDockBottom - mRestrictedOverscanScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07002582 } else {
2583 // We currently want to hide the navigation UI.
2584 mNavigationBar.hideLw(true);
2585 }
2586 if (navVisible && !mNavigationBar.isAnimatingLw()) {
2587 // If the nav bar is currently requested to be visible,
2588 // and not in the process of animating on or off, then
2589 // we can tell the app that it is covered by it.
2590 mSystemBottom = mTmpNavigationFrame.top;
2591 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002592 } else {
Craig Mautner69b08182012-09-05 13:07:13 -07002593 // Landscape screen; nav bar goes to the right.
Dianne Hackbornc652de82013-02-15 16:32:56 -08002594 int left = displayWidth - overscanRight
2595 - mNavigationBarWidthForRotation[displayRotation];
2596 mTmpNavigationFrame.set(left, 0, displayWidth - overscanRight, displayHeight);
Craig Mautner69b08182012-09-05 13:07:13 -07002597 mStableRight = mStableFullscreenRight = mTmpNavigationFrame.left;
2598 if (navVisible) {
2599 mNavigationBar.showLw(true);
2600 mDockRight = mTmpNavigationFrame.left;
Dianne Hackborn313440842013-02-19 19:22:59 -08002601 mRestrictedScreenWidth = mDockRight - mRestrictedScreenLeft;
2602 mRestrictedOverscanScreenWidth = mDockRight - mRestrictedOverscanScreenLeft;
Craig Mautner69b08182012-09-05 13:07:13 -07002603 } else {
2604 // We currently want to hide the navigation UI.
2605 mNavigationBar.hideLw(true);
2606 }
2607 if (navVisible && !mNavigationBar.isAnimatingLw()) {
2608 // If the nav bar is currently requested to be visible,
2609 // and not in the process of animating on or off, then
2610 // we can tell the app that it is covered by it.
2611 mSystemRight = mTmpNavigationFrame.left;
2612 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002613 }
Craig Mautner69b08182012-09-05 13:07:13 -07002614 // Make sure the content and current rectangles are updated to
2615 // account for the restrictions from the navigation bar.
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002616 mContentTop = mCurTop = mDockTop;
2617 mContentBottom = mCurBottom = mDockBottom;
2618 mContentLeft = mCurLeft = mDockLeft;
2619 mContentRight = mCurRight = mDockRight;
Craig Mautner69b08182012-09-05 13:07:13 -07002620 mStatusBarLayer = mNavigationBar.getSurfaceLayer();
2621 // And compute the final frame.
2622 mNavigationBar.computeFrameLw(mTmpNavigationFrame, mTmpNavigationFrame,
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002623 mTmpNavigationFrame, mTmpNavigationFrame, mTmpNavigationFrame);
Craig Mautner69b08182012-09-05 13:07:13 -07002624 if (DEBUG_LAYOUT) Log.i(TAG, "mNavigationBar frame: " + mTmpNavigationFrame);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002625 }
Craig Mautner69b08182012-09-05 13:07:13 -07002626 if (DEBUG_LAYOUT) Log.i(TAG, String.format("mDock rect: (%d,%d - %d,%d)",
2627 mDockLeft, mDockTop, mDockRight, mDockBottom));
2628
2629 // decide where the status bar goes ahead of time
2630 if (mStatusBar != null) {
2631 // apply any navigation bar insets
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002632 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
2633 pf.top = df.top = of.top = mUnrestrictedScreenTop;
2634 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
2635 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight
2636 + mUnrestrictedScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07002637 vf.left = mStableLeft;
2638 vf.top = mStableTop;
2639 vf.right = mStableRight;
2640 vf.bottom = mStableBottom;
2641
2642 mStatusBarLayer = mStatusBar.getSurfaceLayer();
2643
2644 // Let the status bar determine its size.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002645 mStatusBar.computeFrameLw(pf, df, vf, vf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07002646
2647 // For layout, the status bar is always at the top with our fixed height.
2648 mStableTop = mUnrestrictedScreenTop + mStatusBarHeight;
2649
2650 // If the status bar is hidden, we don't want to cause
2651 // windows behind it to scroll.
2652 if (mStatusBar.isVisibleLw()) {
2653 // Status bar may go away, so the screen area it occupies
2654 // is available to apps but just covering them when the
2655 // status bar is visible.
2656 mDockTop = mUnrestrictedScreenTop + mStatusBarHeight;
2657
2658 mContentTop = mCurTop = mDockTop;
2659 mContentBottom = mCurBottom = mDockBottom;
2660 mContentLeft = mCurLeft = mDockLeft;
2661 mContentRight = mCurRight = mDockRight;
2662
2663 if (DEBUG_LAYOUT) Log.v(TAG, "Status bar: " +
2664 String.format(
2665 "dock=[%d,%d][%d,%d] content=[%d,%d][%d,%d] cur=[%d,%d][%d,%d]",
2666 mDockLeft, mDockTop, mDockRight, mDockBottom,
2667 mContentLeft, mContentTop, mContentRight, mContentBottom,
2668 mCurLeft, mCurTop, mCurRight, mCurBottom));
2669 }
2670 if (mStatusBar.isVisibleLw() && !mStatusBar.isAnimatingLw()) {
2671 // If the status bar is currently requested to be visible,
2672 // and not in the process of animating on or off, then
2673 // we can tell the app that it is covered by it.
2674 mSystemTop = mUnrestrictedScreenTop + mStatusBarHeight;
2675 }
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002676 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002677 }
2678 }
2679
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07002680 /** {@inheritDoc} */
2681 public int getSystemDecorRectLw(Rect systemRect) {
2682 systemRect.left = mSystemLeft;
2683 systemRect.top = mSystemTop;
2684 systemRect.right = mSystemRight;
2685 systemRect.bottom = mSystemBottom;
2686 if (mStatusBar != null) return mStatusBar.getSurfaceLayer();
2687 if (mNavigationBar != null) return mNavigationBar.getSurfaceLayer();
2688 return 0;
2689 }
2690
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002691 void setAttachedWindowFrames(WindowState win, int fl, int adjust, WindowState attached,
2692 boolean insetDecors, Rect pf, Rect df, Rect of, Rect cf, Rect vf) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002693 if (win.getSurfaceLayer() > mDockLayer && attached.getSurfaceLayer() < mDockLayer) {
2694 // Here's a special case: if this attached window is a panel that is
2695 // above the dock window, and the window it is attached to is below
2696 // the dock window, then the frames we computed for the window it is
2697 // attached to can not be used because the dock is effectively part
2698 // of the underlying window and the attached window is floating on top
2699 // of the whole thing. So, we ignore the attached window and explicitly
2700 // compute the frames that would be appropriate without the dock.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002701 df.left = of.left = cf.left = vf.left = mDockLeft;
2702 df.top = of.top = cf.top = vf.top = mDockTop;
2703 df.right = of.right = cf.right = vf.right = mDockRight;
2704 df.bottom = of.bottom = cf.bottom = vf.bottom = mDockBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002705 } else {
2706 // The effective display frame of the attached window depends on
2707 // whether it is taking care of insetting its content. If not,
2708 // we need to use the parent's content frame so that the entire
2709 // window is positioned within that content. Otherwise we can use
2710 // the display frame and let the attached window take care of
2711 // positioning its content appropriately.
Dianne Hackborndea3ef72010-10-28 14:24:22 -07002712 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002713 cf.set(attached.getOverscanFrameLw());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002714 } else {
2715 // If the window is resizing, then we want to base the content
2716 // frame on our attached content frame to resize... however,
2717 // things can be tricky if the attached window is NOT in resize
2718 // mode, in which case its content frame will be larger.
2719 // Ungh. So to deal with that, make sure the content frame
2720 // we end up using is not covering the IM dock.
2721 cf.set(attached.getContentFrameLw());
2722 if (attached.getSurfaceLayer() < mDockLayer) {
2723 if (cf.left < mContentLeft) cf.left = mContentLeft;
2724 if (cf.top < mContentTop) cf.top = mContentTop;
2725 if (cf.right > mContentRight) cf.right = mContentRight;
2726 if (cf.bottom > mContentBottom) cf.bottom = mContentBottom;
2727 }
2728 }
2729 df.set(insetDecors ? attached.getDisplayFrameLw() : cf);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002730 of.set(insetDecors ? attached.getOverscanFrameLw() : cf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002731 vf.set(attached.getVisibleFrameLw());
2732 }
2733 // The LAYOUT_IN_SCREEN flag is used to determine whether the attached
2734 // window should be positioned relative to its parent or the entire
2735 // screen.
2736 pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0
2737 ? attached.getFrameLw() : df);
2738 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002739
2740 private void applyStableConstraints(int sysui, int fl, Rect r) {
2741 if ((sysui & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
2742 // If app is requesting a stable layout, don't let the
2743 // content insets go below the stable values.
2744 if ((fl & FLAG_FULLSCREEN) != 0) {
2745 if (r.left < mStableFullscreenLeft) r.left = mStableFullscreenLeft;
2746 if (r.top < mStableFullscreenTop) r.top = mStableFullscreenTop;
2747 if (r.right > mStableFullscreenRight) r.right = mStableFullscreenRight;
2748 if (r.bottom > mStableFullscreenBottom) r.bottom = mStableFullscreenBottom;
2749 } else {
2750 if (r.left < mStableLeft) r.left = mStableLeft;
2751 if (r.top < mStableTop) r.top = mStableTop;
2752 if (r.right > mStableRight) r.right = mStableRight;
2753 if (r.bottom > mStableBottom) r.bottom = mStableBottom;
2754 }
2755 }
2756 }
2757
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002758 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07002759 @Override
Dianne Hackborn0ecadf72009-03-31 18:00:37 -07002760 public void layoutWindowLw(WindowState win, WindowManager.LayoutParams attrs,
2761 WindowState attached) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002762 // we've already done the status bar
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002763 if (win == mStatusBar || win == mNavigationBar) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002764 return;
2765 }
Craig Mautner69b08182012-09-05 13:07:13 -07002766 final boolean isDefaultDisplay = win.isDefaultDisplay();
2767 final boolean needsToOffsetInputMethodTarget = isDefaultDisplay &&
satok1bc0a492012-04-25 22:47:12 +09002768 (win == mLastInputMethodTargetWindow && mLastInputMethodWindow != null);
2769 if (needsToOffsetInputMethodTarget) {
2770 if (DEBUG_LAYOUT) {
2771 Slog.i(TAG, "Offset ime target window by the last ime window state");
2772 }
2773 offsetInputMethodWindowLw(mLastInputMethodWindow);
2774 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002775
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002776 final int fl = attrs.flags;
2777 final int sim = attrs.softInputMode;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002778 final int sysUiFl = win.getSystemUiVisibility();
2779
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002780 final Rect pf = mTmpParentFrame;
2781 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002782 final Rect of = mTmpOverscanFrame;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002783 final Rect cf = mTmpContentFrame;
2784 final Rect vf = mTmpVisibleFrame;
Craig Mautner69b08182012-09-05 13:07:13 -07002785
2786 final boolean hasNavBar = (isDefaultDisplay && mHasNavigationBar
Daniel Sandler36412a72011-08-04 09:35:13 -04002787 && mNavigationBar != null && mNavigationBar.isVisibleLw());
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002788
Craig Mautnerf683b562012-10-02 11:10:57 -07002789 final int adjust = sim & SOFT_INPUT_MASK_ADJUST;
2790
Craig Mautner69b08182012-09-05 13:07:13 -07002791 if (!isDefaultDisplay) {
2792 if (attached != null) {
2793 // If this window is attached to another, our display
2794 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002795 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07002796 } else {
2797 // Give the window full screen.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002798 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
2799 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
2800 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08002801 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002802 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08002803 = mOverscanScreenTop + mOverscanScreenHeight;
Craig Mautner69b08182012-09-05 13:07:13 -07002804 }
2805 } else if (attrs.type == TYPE_INPUT_METHOD) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002806 pf.left = df.left = of.left = cf.left = vf.left = mDockLeft;
2807 pf.top = df.top = of.top = cf.top = vf.top = mDockTop;
2808 pf.right = df.right = of.right = cf.right = vf.right = mDockRight;
2809 pf.bottom = df.bottom = of.bottom = cf.bottom = vf.bottom = mDockBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002810 // IM dock windows always go to the bottom of the screen.
2811 attrs.gravity = Gravity.BOTTOM;
2812 mDockLayer = win.getSurfaceLayer();
2813 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002814 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
2815 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002816 if (DEBUG_LAYOUT)
2817 Log.v(TAG, "layoutWindowLw(" + attrs.getTitle()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002818 + "): IN_SCREEN, INSET_DECOR");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002819 // This is the case for a normal activity window: we want it
2820 // to cover all of the screen space, and it can take care of
2821 // moving its contents to account for screen decorations that
2822 // intrude into that space.
2823 if (attached != null) {
2824 // If this window is attached to another, our display
2825 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002826 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002827 } else {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002828 if (attrs.type == TYPE_STATUS_BAR_PANEL
2829 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Joe Onorato29fc2c92010-11-24 10:26:50 -08002830 // Status bar panels are the only windows who can go on top of
2831 // the status bar. They are protected by the STATUS_BAR_SERVICE
2832 // permission, so they have the same privileges as the status
2833 // bar itself.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002834 //
Daniel Sandler8e8b4152011-07-21 01:16:43 -04002835 // However, they should still dodge the navigation bar if it exists.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002836
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002837 pf.left = df.left = of.left = hasNavBar
2838 ? mDockLeft : mUnrestrictedScreenLeft;
2839 pf.top = df.top = of.top = mUnrestrictedScreenTop;
2840 pf.right = df.right = of.right = hasNavBar
2841 ? mRestrictedScreenLeft+mRestrictedScreenWidth
2842 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
2843 pf.bottom = df.bottom = of.bottom = hasNavBar
2844 ? mRestrictedScreenTop+mRestrictedScreenHeight
2845 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002846
Daniel Sandler8e8b4152011-07-21 01:16:43 -04002847 if (DEBUG_LAYOUT) {
2848 Log.v(TAG, String.format(
2849 "Laying out status bar window: (%d,%d - %d,%d)",
2850 pf.left, pf.top, pf.right, pf.bottom));
2851 }
Dianne Hackbornc652de82013-02-15 16:32:56 -08002852 } else if ((attrs.flags&FLAG_LAYOUT_IN_OVERSCAN) != 0
2853 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
2854 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
2855 // Asking to layout into the overscan region, so give it that pure
2856 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002857 pf.left = df.left = of.left = mOverscanScreenLeft;
2858 pf.top = df.top = of.top = mOverscanScreenTop;
2859 pf.right = df.right = of.right = mOverscanScreenLeft + mOverscanScreenWidth;
2860 pf.bottom = df.bottom = of.bottom = mOverscanScreenTop
2861 + mOverscanScreenHeight;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002862 } else if (mCanHideNavigationBar
2863 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002864 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
2865 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
2866 // Asking for layout as if the nav bar is hidden, lets the
Dianne Hackbornc652de82013-02-15 16:32:56 -08002867 // application extend into the unrestricted overscan screen area. We
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002868 // only do this for application windows to ensure no window that
2869 // can be above the nav bar can do this.
Dianne Hackborn313440842013-02-19 19:22:59 -08002870 pf.left = df.left = mOverscanScreenLeft;
2871 pf.top = df.top = mOverscanScreenTop;
2872 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
2873 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002874 // We need to tell the app about where the frame inside the overscan
2875 // is, so it can inset its content by that amount -- it didn't ask
2876 // to actually extend itself into the overscan region.
2877 of.left = mUnrestrictedScreenLeft;
2878 of.top = mUnrestrictedScreenTop;
2879 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
2880 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08002881 } else {
Dianne Hackborn313440842013-02-19 19:22:59 -08002882 pf.left = df.left = mRestrictedOverscanScreenLeft;
2883 pf.top = df.top = mRestrictedOverscanScreenTop;
2884 pf.right = df.right = mRestrictedOverscanScreenLeft
2885 + mRestrictedOverscanScreenWidth;
2886 pf.bottom = df.bottom = mRestrictedOverscanScreenTop
2887 + mRestrictedOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002888 // We need to tell the app about where the frame inside the overscan
2889 // is, so it can inset its content by that amount -- it didn't ask
2890 // to actually extend itself into the overscan region.
2891 of.left = mUnrestrictedScreenLeft;
2892 of.top = mUnrestrictedScreenTop;
2893 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
2894 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08002895 }
Craig Mautner69b08182012-09-05 13:07:13 -07002896
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002897 if ((attrs.flags&FLAG_FULLSCREEN) == 0) {
2898 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
2899 cf.left = mDockLeft;
2900 cf.top = mDockTop;
2901 cf.right = mDockRight;
2902 cf.bottom = mDockBottom;
2903 } else {
2904 cf.left = mContentLeft;
2905 cf.top = mContentTop;
2906 cf.right = mContentRight;
2907 cf.bottom = mContentBottom;
2908 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002909 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002910 // Full screen windows are always given a layout that is as if the
2911 // status bar and other transient decors are gone. This is to avoid
2912 // bad states when moving from a window that is not hding the
2913 // status bar to one that is.
2914 cf.left = mRestrictedScreenLeft;
2915 cf.top = mRestrictedScreenTop;
2916 cf.right = mRestrictedScreenLeft + mRestrictedScreenWidth;
2917 cf.bottom = mRestrictedScreenTop + mRestrictedScreenHeight;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002918 }
Craig Mautner69b08182012-09-05 13:07:13 -07002919
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002920 applyStableConstraints(sysUiFl, fl, cf);
Dianne Hackborndea3ef72010-10-28 14:24:22 -07002921 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
2922 vf.left = mCurLeft;
2923 vf.top = mCurTop;
2924 vf.right = mCurRight;
2925 vf.bottom = mCurBottom;
2926 } else {
2927 vf.set(cf);
2928 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002929 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002930 } else if ((fl & FLAG_LAYOUT_IN_SCREEN) != 0 || (sysUiFl
2931 & (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
2932 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)) != 0) {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002933 if (DEBUG_LAYOUT)
2934 Log.v(TAG, "layoutWindowLw(" + attrs.getTitle() + "): IN_SCREEN");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002935 // A window that has requested to fill the entire screen just
2936 // gets everything, period.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002937 if (attrs.type == TYPE_STATUS_BAR_PANEL
2938 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002939 pf.left = df.left = of.left = cf.left = hasNavBar
2940 ? mDockLeft : mUnrestrictedScreenLeft;
2941 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
2942 pf.right = df.right = of.right = cf.right = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04002943 ? mRestrictedScreenLeft+mRestrictedScreenWidth
Dianne Hackbornc652de82013-02-15 16:32:56 -08002944 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002945 pf.bottom = df.bottom = of.bottom = cf.bottom = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04002946 ? mRestrictedScreenTop+mRestrictedScreenHeight
Dianne Hackbornc652de82013-02-15 16:32:56 -08002947 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Daniel Sandler36412a72011-08-04 09:35:13 -04002948 if (DEBUG_LAYOUT) {
2949 Log.v(TAG, String.format(
2950 "Laying out IN_SCREEN status bar window: (%d,%d - %d,%d)",
2951 pf.left, pf.top, pf.right, pf.bottom));
2952 }
Jim Millere898ac52012-04-06 17:10:57 -07002953 } else if (attrs.type == TYPE_NAVIGATION_BAR
2954 || attrs.type == TYPE_NAVIGATION_BAR_PANEL) {
Daniel Sandler8e8b4152011-07-21 01:16:43 -04002955 // The navigation bar has Real Ultimate Power.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002956 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
2957 pf.top = df.top = of.top = mUnrestrictedScreenTop;
2958 pf.right = df.right = of.right = mUnrestrictedScreenLeft
2959 + mUnrestrictedScreenWidth;
2960 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop
2961 + mUnrestrictedScreenHeight;
Daniel Sandler8e8b4152011-07-21 01:16:43 -04002962 if (DEBUG_LAYOUT) {
2963 Log.v(TAG, String.format(
2964 "Laying out navigation bar window: (%d,%d - %d,%d)",
2965 pf.left, pf.top, pf.right, pf.bottom));
2966 }
Dianne Hackborn01011c32012-02-21 13:54:21 -08002967 } else if ((attrs.type == TYPE_SECURE_SYSTEM_OVERLAY
2968 || attrs.type == TYPE_BOOT_PROGRESS)
Jeff Brownbfcb60a2011-09-08 18:51:14 -07002969 && ((fl & FLAG_FULLSCREEN) != 0)) {
2970 // Fullscreen secure system overlays get what they ask for.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002971 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
2972 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
2973 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
2974 + mOverscanScreenWidth;
2975 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
2976 + mOverscanScreenHeight;
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07002977 } else if (attrs.type == TYPE_BOOT_PROGRESS
2978 || attrs.type == TYPE_UNIVERSE_BACKGROUND) {
Dianne Hackborn01011c32012-02-21 13:54:21 -08002979 // Boot progress screen always covers entire display.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002980 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
2981 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
2982 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
2983 + mOverscanScreenWidth;
2984 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
2985 + mOverscanScreenHeight;
Dianne Hackborn313440842013-02-19 19:22:59 -08002986 } else if (attrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER) {
2987 // The wallpaper mostly goes into the overscan region.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002988 pf.left = df.left = of.left = cf.left = mRestrictedOverscanScreenLeft;
2989 pf.top = df.top = of.top = cf.top = mRestrictedOverscanScreenTop;
2990 pf.right = df.right = of.right = cf.right
Dianne Hackborn313440842013-02-19 19:22:59 -08002991 = mRestrictedOverscanScreenLeft + mRestrictedOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002992 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackborn313440842013-02-19 19:22:59 -08002993 = mRestrictedOverscanScreenTop + mRestrictedOverscanScreenHeight;
Dianne Hackbornc652de82013-02-15 16:32:56 -08002994 } else if ((attrs.flags & FLAG_LAYOUT_IN_OVERSCAN) != 0
2995 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
2996 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
2997 // Asking to layout into the overscan region, so give it that pure
2998 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002999 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3000 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3001 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08003002 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003003 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003004 = mOverscanScreenTop + mOverscanScreenHeight;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003005 } else if (mCanHideNavigationBar
3006 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003007 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3008 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3009 // Asking for layout as if the nav bar is hidden, lets the
3010 // application extend into the unrestricted screen area. We
3011 // only do this for application windows to ensure no window that
3012 // can be above the nav bar can do this.
3013 // XXX This assumes that an app asking for this will also
3014 // ask for layout in only content. We can't currently figure out
3015 // what the screen would be if only laying out to hide the nav bar.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003016 pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft;
3017 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
3018 pf.right = df.right = of.right = cf.right = mUnrestrictedScreenLeft
3019 + mUnrestrictedScreenWidth;
3020 pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop
3021 + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003022 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003023 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
3024 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
3025 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
3026 + mRestrictedScreenWidth;
3027 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
3028 + mRestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003029 }
Craig Mautner69b08182012-09-05 13:07:13 -07003030
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003031 applyStableConstraints(sysUiFl, fl, cf);
Craig Mautner69b08182012-09-05 13:07:13 -07003032
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003033 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3034 vf.left = mCurLeft;
3035 vf.top = mCurTop;
3036 vf.right = mCurRight;
3037 vf.bottom = mCurBottom;
3038 } else {
3039 vf.set(cf);
3040 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003041 } else if (attached != null) {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003042 if (DEBUG_LAYOUT)
3043 Log.v(TAG, "layoutWindowLw(" + attrs.getTitle() + "): attached to " + attached);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003044 // A child window should be placed inside of the same visible
3045 // frame that its parent had.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003046 setAttachedWindowFrames(win, fl, adjust, attached, false, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003047 } else {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003048 if (DEBUG_LAYOUT)
3049 Log.v(TAG, "layoutWindowLw(" + attrs.getTitle() + "): normal window");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003050 // Otherwise, a normal window must be placed inside the content
3051 // of all screen decorations.
Dianne Hackborna239c842011-06-01 12:28:20 -07003052 if (attrs.type == TYPE_STATUS_BAR_PANEL) {
3053 // Status bar panels are the only windows who can go on top of
3054 // the status bar. They are protected by the STATUS_BAR_SERVICE
3055 // permission, so they have the same privileges as the status
3056 // bar itself.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003057 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
3058 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
3059 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
3060 + mRestrictedScreenWidth;
3061 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
3062 + mRestrictedScreenHeight;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003063 } else {
Dianne Hackborna239c842011-06-01 12:28:20 -07003064 pf.left = mContentLeft;
3065 pf.top = mContentTop;
3066 pf.right = mContentRight;
3067 pf.bottom = mContentBottom;
3068 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003069 df.left = of.left = cf.left = mDockLeft;
3070 df.top = of.top = cf.top = mDockTop;
3071 df.right = of.right = cf.right = mDockRight;
3072 df.bottom = of.bottom = cf.bottom = mDockBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07003073 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003074 df.left = of.left = cf.left = mContentLeft;
3075 df.top = of.top = cf.top = mContentTop;
3076 df.right = of.right = cf.right = mContentRight;
3077 df.bottom = of.bottom = cf.bottom = mContentBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07003078 }
3079 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3080 vf.left = mCurLeft;
3081 vf.top = mCurTop;
3082 vf.right = mCurRight;
3083 vf.bottom = mCurBottom;
3084 } else {
3085 vf.set(cf);
3086 }
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003087 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003088 }
3089 }
Craig Mautner69b08182012-09-05 13:07:13 -07003090
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003091 if ((fl & FLAG_LAYOUT_NO_LIMITS) != 0) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003092 df.left = df.top = of.left = of.top = cf.left = cf.top = vf.left = vf.top = -10000;
3093 df.right = df.bottom = of.right = of.bottom = cf.right = cf.bottom
3094 = vf.right = vf.bottom = 10000;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003095 }
3096
The Android Open Source Project11267662009-03-18 17:39:47 -07003097 if (DEBUG_LAYOUT) Log.v(TAG, "Compute frame " + attrs.getTitle()
3098 + ": sim=#" + Integer.toHexString(sim)
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003099 + " attach=" + attached + " type=" + attrs.type
3100 + String.format(" flags=0x%08x", fl)
The Android Open Source Project11267662009-03-18 17:39:47 -07003101 + " pf=" + pf.toShortString() + " df=" + df.toShortString()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003102 + " of=" + of.toShortString()
The Android Open Source Project11267662009-03-18 17:39:47 -07003103 + " cf=" + cf.toShortString() + " vf=" + vf.toShortString());
Craig Mautner69b08182012-09-05 13:07:13 -07003104
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003105 win.computeFrameLw(pf, df, of, cf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07003106
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003107 // Dock windows carve out the bottom of the screen, so normal windows
3108 // can't appear underneath them.
Craig Mautner8bd206b2012-10-03 10:32:02 -07003109 if (attrs.type == TYPE_INPUT_METHOD && win.isVisibleOrBehindKeyguardLw()
3110 && !win.getGivenInsetsPendingLw()) {
satok1bc0a492012-04-25 22:47:12 +09003111 setLastInputMethodWindowLw(null, null);
3112 offsetInputMethodWindowLw(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003113 }
3114 }
3115
satok1bc0a492012-04-25 22:47:12 +09003116 private void offsetInputMethodWindowLw(WindowState win) {
3117 int top = win.getContentFrameLw().top;
3118 top += win.getGivenContentInsetsLw().top;
3119 if (mContentBottom > top) {
3120 mContentBottom = top;
3121 }
3122 top = win.getVisibleFrameLw().top;
3123 top += win.getGivenVisibleInsetsLw().top;
3124 if (mCurBottom > top) {
3125 mCurBottom = top;
3126 }
3127 if (DEBUG_LAYOUT) Log.v(TAG, "Input method: mDockBottom="
3128 + mDockBottom + " mContentBottom="
3129 + mContentBottom + " mCurBottom=" + mCurBottom);
3130 }
3131
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003132 /** {@inheritDoc} */
Craig Mautner61ac6bb2012-02-02 17:29:33 -08003133 @Override
3134 public void finishLayoutLw() {
3135 return;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003136 }
3137
3138 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003139 @Override
Craig Mautner39834192012-09-02 07:47:24 -07003140 public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) {
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003141 mTopFullscreenOpaqueWindowState = null;
3142 mForceStatusBar = false;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003143 mForceStatusBarFromKeyguard = false;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08003144 mForcingShowNavBar = false;
3145 mForcingShowNavBarLayer = -1;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003146
3147 mHideLockScreen = false;
3148 mAllowLockscreenWhenOn = false;
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003149 mDismissKeyguard = DISMISS_KEYGUARD_NONE;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003150 mShowingLockscreen = false;
3151 mShowingDream = false;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003152 }
3153
3154 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003155 @Override
Craig Mautner39834192012-09-02 07:47:24 -07003156 public void applyPostLayoutPolicyLw(WindowState win,
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003157 WindowManager.LayoutParams attrs) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07003158 if (DEBUG_LAYOUT) Slog.i(TAG, "Win " + win + ": isVisibleOrBehindKeyguardLw="
3159 + win.isVisibleOrBehindKeyguardLw());
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08003160 if (mTopFullscreenOpaqueWindowState == null && (win.getAttrs().privateFlags
3161 &WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_SHOW_NAV_BAR) != 0) {
3162 if (mForcingShowNavBarLayer < 0) {
3163 mForcingShowNavBar = true;
3164 mForcingShowNavBarLayer = win.getSurfaceLayer();
3165 }
3166 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003167 if (mTopFullscreenOpaqueWindowState == null &&
Dianne Hackborn01b02a72012-01-12 14:05:03 -08003168 win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()) {
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003169 if ((attrs.flags & FLAG_FORCE_NOT_FULLSCREEN) != 0) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003170 if (attrs.type == TYPE_KEYGUARD) {
3171 mForceStatusBarFromKeyguard = true;
3172 } else {
3173 mForceStatusBar = true;
3174 }
3175 }
3176 if (attrs.type == TYPE_KEYGUARD) {
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003177 mShowingLockscreen = true;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07003178 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003179 boolean applyWindow = attrs.type >= FIRST_APPLICATION_WINDOW
3180 && attrs.type <= LAST_APPLICATION_WINDOW;
3181 if (attrs.type == TYPE_DREAM) {
Jeff Brownc8018eb2012-10-29 21:33:27 -07003182 // If the lockscreen was showing when the dream started then wait
3183 // for the dream to draw before hiding the lockscreen.
3184 if (!mDreamingLockscreen
3185 || (win.isVisibleLw() && win.hasDrawnLw())) {
3186 mShowingDream = true;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003187 applyWindow = true;
3188 }
3189 }
3190 if (applyWindow
Dianne Hackborn6493e642010-10-01 13:06:30 -07003191 && attrs.x == 0 && attrs.y == 0
3192 && attrs.width == WindowManager.LayoutParams.MATCH_PARENT
3193 && attrs.height == WindowManager.LayoutParams.MATCH_PARENT) {
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003194 if (DEBUG_LAYOUT) Log.v(TAG, "Fullscreen window: " + win);
3195 mTopFullscreenOpaqueWindowState = win;
3196 if ((attrs.flags & FLAG_SHOW_WHEN_LOCKED) != 0) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003197 if (DEBUG_LAYOUT) Log.v(TAG, "Setting mHideLockScreen to true by win " + win);
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003198 mHideLockScreen = true;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003199 mForceStatusBarFromKeyguard = false;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003200 }
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003201 if ((attrs.flags & FLAG_DISMISS_KEYGUARD) != 0
3202 && mDismissKeyguard == DISMISS_KEYGUARD_NONE) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003203 if (DEBUG_LAYOUT) Log.v(TAG, "Setting mDismissKeyguard to true by win " + win);
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003204 mDismissKeyguard = mWinDismissingKeyguard == win ?
3205 DISMISS_KEYGUARD_CONTINUE : DISMISS_KEYGUARD_START;
3206 mWinDismissingKeyguard = win;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003207 mForceStatusBarFromKeyguard = false;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003208 }
3209 if ((attrs.flags & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) {
3210 mAllowLockscreenWhenOn = true;
3211 }
3212 }
3213 }
3214 }
3215
3216 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003217 @Override
Craig Mautner39834192012-09-02 07:47:24 -07003218 public int finishPostLayoutPolicyLw() {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003219 int changes = 0;
Joe Onorato93056472010-09-10 10:30:46 -04003220 boolean topIsFullscreen = false;
Daniel Sandlere02d8082010-10-08 15:13:22 -04003221
3222 final WindowManager.LayoutParams lp = (mTopFullscreenOpaqueWindowState != null)
3223 ? mTopFullscreenOpaqueWindowState.getAttrs()
3224 : null;
3225
Jeff Brownc8018eb2012-10-29 21:33:27 -07003226 // If we are not currently showing a dream then remember the current
3227 // lockscreen state. We will use this to determine whether the dream
3228 // started while the lockscreen was showing and remember this state
3229 // while the dream is showing.
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003230 if (!mShowingDream) {
3231 mDreamingLockscreen = mShowingLockscreen;
3232 }
3233
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003234 if (mStatusBar != null) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07003235 if (DEBUG_LAYOUT) Log.i(TAG, "force=" + mForceStatusBar
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003236 + " forcefkg=" + mForceStatusBarFromKeyguard
Dianne Hackbornd70bc2f2009-10-06 23:25:51 -07003237 + " top=" + mTopFullscreenOpaqueWindowState);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003238 if (mForceStatusBar || mForceStatusBarFromKeyguard) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07003239 if (DEBUG_LAYOUT) Log.v(TAG, "Showing status bar: forced");
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003240 if (mStatusBar.showLw(true)) changes |= FINISH_LAYOUT_REDO_LAYOUT;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003241 } else if (mTopFullscreenOpaqueWindowState != null) {
Joe Onorato93056472010-09-10 10:30:46 -04003242 if (localLOGV) {
3243 Log.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw()
3244 + " shown frame: " + mTopFullscreenOpaqueWindowState.getShownFrameLw());
3245 Log.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs()
3246 + " lp.flags=0x" + Integer.toHexString(lp.flags));
3247 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003248 topIsFullscreen = (lp.flags & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0
3249 || (mLastSystemUiFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
Joe Onorato93056472010-09-10 10:30:46 -04003250 // The subtle difference between the window for mTopFullscreenOpaqueWindowState
3251 // and mTopIsFullscreen is that that mTopIsFullscreen is set only if the window
3252 // has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the
3253 // case though.
3254 if (topIsFullscreen) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003255 if (DEBUG_LAYOUT) Log.v(TAG, "** HIDING status bar");
3256 if (mStatusBar.hideLw(true)) {
3257 changes |= FINISH_LAYOUT_REDO_LAYOUT;
Daniel Sandler9c00d5b2011-09-13 14:04:26 -04003258
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003259 mHandler.post(new Runnable() {
3260 @Override
3261 public void run() {
Dianne Hackborn42e620c2012-06-24 13:20:51 -07003262 try {
3263 IStatusBarService statusbar = getStatusBarService();
3264 if (statusbar != null) {
Daniel Sandler11cf1782012-09-27 14:03:08 -04003265 statusbar.collapsePanels();
Dianne Hackborn42e620c2012-06-24 13:20:51 -07003266 }
3267 } catch (RemoteException ex) {
3268 // re-acquire status bar service next time it is needed.
3269 mStatusBarService = null;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003270 }
3271 }});
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07003272 } else if (DEBUG_LAYOUT) {
Daniel Sandler40427442010-07-16 11:44:52 -04003273 Log.v(TAG, "Preventing status bar from hiding by policy");
3274 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003275 } else {
Dianne Hackborn01b02a72012-01-12 14:05:03 -08003276 if (DEBUG_LAYOUT) Log.v(TAG, "** SHOWING status bar: top is not fullscreen");
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003277 if (mStatusBar.showLw(true)) changes |= FINISH_LAYOUT_REDO_LAYOUT;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003278 }
3279 }
3280 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04003281
Joe Onorato644f9c32011-01-25 12:06:23 -08003282 mTopIsFullscreen = topIsFullscreen;
Daniel Sandlere02d8082010-10-08 15:13:22 -04003283
Craig Mautner39834192012-09-02 07:47:24 -07003284 // Hide the key guard if a visible window explicitly specifies that it wants to be
3285 // displayed when the screen is locked.
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -07003286 if (mKeyguard != null) {
Craig Mautner39834192012-09-02 07:47:24 -07003287 if (localLOGV) Log.v(TAG, "finishPostLayoutPolicyLw: mHideKeyguard="
3288 + mHideLockScreen);
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003289 if (mDismissKeyguard != DISMISS_KEYGUARD_NONE && !mKeyguardMediator.isSecure()) {
Dianne Hackborn08743722009-12-21 12:16:51 -08003290 if (mKeyguard.hideLw(true)) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003291 changes |= FINISH_LAYOUT_REDO_LAYOUT
3292 | FINISH_LAYOUT_REDO_CONFIG
3293 | FINISH_LAYOUT_REDO_WALLPAPER;
3294 }
Dianne Hackborn05726582009-09-22 17:28:24 -07003295 if (mKeyguardMediator.isShowing()) {
Dianne Hackbornb446e972009-09-20 15:23:25 -07003296 mHandler.post(new Runnable() {
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003297 @Override
Dianne Hackbornb446e972009-09-20 15:23:25 -07003298 public void run() {
Dianne Hackborn05726582009-09-22 17:28:24 -07003299 mKeyguardMediator.keyguardDone(false, false);
Dianne Hackbornb446e972009-09-20 15:23:25 -07003300 }
3301 });
3302 }
Dianne Hackborn05726582009-09-22 17:28:24 -07003303 } else if (mHideLockScreen) {
Dianne Hackborn08743722009-12-21 12:16:51 -08003304 if (mKeyguard.hideLw(true)) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003305 changes |= FINISH_LAYOUT_REDO_LAYOUT
3306 | FINISH_LAYOUT_REDO_CONFIG
3307 | FINISH_LAYOUT_REDO_WALLPAPER;
3308 }
Mike Lockwoodf3bfed52010-01-21 16:38:44 -05003309 mKeyguardMediator.setHidden(true);
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003310 } else if (mDismissKeyguard != DISMISS_KEYGUARD_NONE) {
3311 // This is the case of keyguard isSecure() and not mHideLockScreen.
3312 if (mDismissKeyguard == DISMISS_KEYGUARD_START) {
3313 // Only launch the next keyguard unlock window once per window.
3314 if (mKeyguard.showLw(true)) {
3315 changes |= FINISH_LAYOUT_REDO_LAYOUT
3316 | FINISH_LAYOUT_REDO_CONFIG
3317 | FINISH_LAYOUT_REDO_WALLPAPER;
3318 }
3319 mKeyguardMediator.setHidden(false);
3320 mHandler.post(new Runnable() {
3321 @Override
3322 public void run() {
3323 mKeyguardMediator.dismiss();
3324 }
3325 });
3326 }
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -07003327 } else {
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003328 mWinDismissingKeyguard = null;
Dianne Hackborn08743722009-12-21 12:16:51 -08003329 if (mKeyguard.showLw(true)) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003330 changes |= FINISH_LAYOUT_REDO_LAYOUT
3331 | FINISH_LAYOUT_REDO_CONFIG
3332 | FINISH_LAYOUT_REDO_WALLPAPER;
3333 }
Mike Lockwoodf3bfed52010-01-21 16:38:44 -05003334 mKeyguardMediator.setHidden(false);
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -07003335 }
3336 }
Joe Onorato664644d2011-01-23 17:53:23 -08003337
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003338 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003339 // If the navigation bar has been hidden or shown, we need to do another
3340 // layout pass to update that window.
3341 changes |= FINISH_LAYOUT_REDO_LAYOUT;
3342 }
Joe Onorato664644d2011-01-23 17:53:23 -08003343
Mike Lockwood28569302010-01-28 11:54:40 -05003344 // update since mAllowLockscreenWhenOn might have changed
3345 updateLockScreenTimeout();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003346 return changes;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003347 }
3348
Dianne Hackborn08743722009-12-21 12:16:51 -08003349 public boolean allowAppAnimationsLw() {
Craig Mautnerf03e4c52012-06-14 14:11:27 -07003350 if (mKeyguard != null && mKeyguard.isVisibleLw() && !mKeyguard.isAnimatingLw()) {
Dianne Hackborn08743722009-12-21 12:16:51 -08003351 // If keyguard is currently visible, no reason to animate
3352 // behind it.
3353 return false;
3354 }
Dianne Hackborn08743722009-12-21 12:16:51 -08003355 return true;
3356 }
3357
Dianne Hackborndf89e652011-10-06 22:35:11 -07003358 public int focusChangedLw(WindowState lastFocus, WindowState newFocus) {
Joe Onorato664644d2011-01-23 17:53:23 -08003359 mFocusedWindow = newFocus;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003360 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003361 // If the navigation bar has been hidden or shown, we need to do another
3362 // layout pass to update that window.
3363 return FINISH_LAYOUT_REDO_LAYOUT;
3364 }
3365 return 0;
Joe Onorato664644d2011-01-23 17:53:23 -08003366 }
3367
Dianne Hackborn0ecadf72009-03-31 18:00:37 -07003368 /** {@inheritDoc} */
Jeff Brown46b9ac02010-04-22 18:58:52 -07003369 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
Mike Lockwood3a74bd32011-08-12 13:55:22 -07003370 // do nothing if headless
Mike Lockwoodd747dc82011-09-13 16:28:22 -04003371 if (mHeadless) return;
Mike Lockwood3a74bd32011-08-12 13:55:22 -07003372
Jeff Brown46b9ac02010-04-22 18:58:52 -07003373 // lid changed state
Jeff Brownc458ce92012-04-30 14:58:40 -07003374 final int newLidState = lidOpen ? LID_OPEN : LID_CLOSED;
3375 if (newLidState == mLidState) {
3376 return;
3377 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07003378
Jeff Brownc458ce92012-04-30 14:58:40 -07003379 mLidState = newLidState;
3380 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07003381 updateRotation(true);
Jeff Brownc458ce92012-04-30 14:58:40 -07003382
3383 if (lidOpen) {
3384 if (keyguardIsShowingTq()) {
Jeff Brown1c2e4942012-11-06 16:32:01 -08003385 mKeyguardMediator.onWakeKeyWhenKeyguardShowingTq(KeyEvent.KEYCODE_POWER);
Jeff Brown46b9ac02010-04-22 18:58:52 -07003386 } else {
Jeff Brown96307042012-07-27 15:51:34 -07003387 mPowerManager.wakeUp(SystemClock.uptimeMillis());
Jeff Brown46b9ac02010-04-22 18:58:52 -07003388 }
Jeff Brownc458ce92012-04-30 14:58:40 -07003389 } else if (!mLidControlsSleep) {
Jeff Brown96307042012-07-27 15:51:34 -07003390 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
Jeff Brown46b9ac02010-04-22 18:58:52 -07003391 }
3392 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003393
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08003394 void setHdmiPlugged(boolean plugged) {
3395 if (mHdmiPlugged != plugged) {
3396 mHdmiPlugged = plugged;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003397 updateRotation(true, true);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08003398 Intent intent = new Intent(ACTION_HDMI_PLUGGED);
Joe Onoratodc100302011-01-11 17:07:41 -08003399 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08003400 intent.putExtra(EXTRA_HDMI_PLUGGED_STATE, plugged);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07003401 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08003402 }
3403 }
3404
Joe Onoratoea495d42011-04-06 11:41:11 -07003405 void initializeHdmiState() {
Joe Onorato7ba631f2011-05-04 15:28:00 -07003406 boolean plugged = false;
Joe Onoratoea495d42011-04-06 11:41:11 -07003407 // watch for HDMI plug messages if the hdmi switch exists
3408 if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) {
3409 mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi");
3410
Joe Onoratoea495d42011-04-06 11:41:11 -07003411 final String filename = "/sys/class/switch/hdmi/state";
3412 FileReader reader = null;
3413 try {
3414 reader = new FileReader(filename);
3415 char[] buf = new char[15];
3416 int n = reader.read(buf);
3417 if (n > 1) {
3418 plugged = 0 != Integer.parseInt(new String(buf, 0, n-1));
3419 }
3420 } catch (IOException ex) {
3421 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
3422 } catch (NumberFormatException ex) {
3423 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
3424 } finally {
3425 if (reader != null) {
3426 try {
3427 reader.close();
3428 } catch (IOException ex) {
3429 }
Joe Onoratodc100302011-01-11 17:07:41 -08003430 }
3431 }
3432 }
Joe Onorato7ba631f2011-05-04 15:28:00 -07003433 // This dance forces the code in setHdmiPlugged to run.
3434 // Always do this so the sticky intent is stuck (to false) if there is no hdmi.
3435 mHdmiPlugged = !plugged;
3436 setHdmiPlugged(!mHdmiPlugged);
Joe Onoratodc100302011-01-11 17:07:41 -08003437 }
3438
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003439 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003440 * @return Whether music is being played right now.
3441 */
3442 boolean isMusicActive() {
Eric Laurent413cb9d2009-07-17 11:52:43 -07003443 final AudioManager am = (AudioManager)mContext.getSystemService(Context.AUDIO_SERVICE);
3444 if (am == null) {
3445 Log.w(TAG, "isMusicActive: couldn't get AudioManager reference");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003446 return false;
3447 }
Eric Laurent413cb9d2009-07-17 11:52:43 -07003448 return am.isMusicActive();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003449 }
3450
3451 /**
3452 * Tell the audio service to adjust the volume appropriate to the event.
3453 * @param keycode
3454 */
Mike Lockwooda53e3812009-09-25 10:51:39 -04003455 void handleVolumeKey(int stream, int keycode) {
Jeff Brown4d396052010-10-29 21:50:21 -07003456 IAudioService audioService = getAudioService();
3457 if (audioService == null) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003458 return;
3459 }
3460 try {
3461 // since audio is playing, we shouldn't have to hold a wake lock
3462 // during the call, but we do it as a precaution for the rare possibility
3463 // that the music stops right before we call this
Jeff Brownb0418da2010-11-01 15:24:01 -07003464 // TODO: Actually handle MUTE.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003465 mBroadcastWakeLock.acquire();
Jeff Brown4d396052010-10-29 21:50:21 -07003466 audioService.adjustStreamVolume(stream,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003467 keycode == KeyEvent.KEYCODE_VOLUME_UP
3468 ? AudioManager.ADJUST_RAISE
3469 : AudioManager.ADJUST_LOWER,
3470 0);
3471 } catch (RemoteException e) {
3472 Log.w(TAG, "IAudioService.adjustStreamVolume() threw RemoteException " + e);
3473 } finally {
3474 mBroadcastWakeLock.release();
3475 }
3476 }
Jeff Brown4d396052010-10-29 21:50:21 -07003477
Dianne Hackbornc0e3f242011-08-19 14:19:10 -07003478 final Object mScreenshotLock = new Object();
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07003479 ServiceConnection mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07003480
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003481 final Runnable mScreenshotTimeout = new Runnable() {
3482 @Override public void run() {
3483 synchronized (mScreenshotLock) {
3484 if (mScreenshotConnection != null) {
3485 mContext.unbindService(mScreenshotConnection);
3486 mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07003487 }
Winson Chung9112ec32011-06-27 13:15:32 -07003488 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003489 }
3490 };
3491
3492 // Assume this is called from the Handler thread.
3493 private void takeScreenshot() {
3494 synchronized (mScreenshotLock) {
3495 if (mScreenshotConnection != null) {
3496 return;
3497 }
3498 ComponentName cn = new ComponentName("com.android.systemui",
3499 "com.android.systemui.screenshot.TakeScreenshotService");
3500 Intent intent = new Intent();
3501 intent.setComponent(cn);
3502 ServiceConnection conn = new ServiceConnection() {
3503 @Override
3504 public void onServiceConnected(ComponentName name, IBinder service) {
3505 synchronized (mScreenshotLock) {
3506 if (mScreenshotConnection != this) {
3507 return;
3508 }
3509 Messenger messenger = new Messenger(service);
3510 Message msg = Message.obtain(null, 1);
3511 final ServiceConnection myConn = this;
3512 Handler h = new Handler(mHandler.getLooper()) {
3513 @Override
3514 public void handleMessage(Message msg) {
3515 synchronized (mScreenshotLock) {
3516 if (mScreenshotConnection == myConn) {
3517 mContext.unbindService(mScreenshotConnection);
3518 mScreenshotConnection = null;
3519 mHandler.removeCallbacks(mScreenshotTimeout);
3520 }
3521 }
3522 }
3523 };
3524 msg.replyTo = new Messenger(h);
Winson Chunga63bb842011-10-17 10:26:28 -07003525 msg.arg1 = msg.arg2 = 0;
3526 if (mStatusBar != null && mStatusBar.isVisibleLw())
3527 msg.arg1 = 1;
3528 if (mNavigationBar != null && mNavigationBar.isVisibleLw())
3529 msg.arg2 = 1;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003530 try {
3531 messenger.send(msg);
3532 } catch (RemoteException e) {
3533 }
3534 }
3535 }
3536 @Override
3537 public void onServiceDisconnected(ComponentName name) {}
3538 };
Amith Yamasani27b89e62013-01-16 12:30:11 -08003539 if (mContext.bindServiceAsUser(
3540 intent, conn, Context.BIND_AUTO_CREATE, UserHandle.CURRENT)) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003541 mScreenshotConnection = conn;
3542 mHandler.postDelayed(mScreenshotTimeout, 10000);
3543 }
3544 }
Winson Chung9112ec32011-06-27 13:15:32 -07003545 }
3546
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003547 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003548 @Override
Jeff Brown1f245102010-11-18 20:53:46 -08003549 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags, boolean isScreenOn) {
Jeff Brown96307042012-07-27 15:51:34 -07003550 if (!mSystemBooted) {
3551 // If we have not yet booted, don't let key events do anything.
3552 return 0;
3553 }
3554
Jeff Brown1f245102010-11-18 20:53:46 -08003555 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
3556 final boolean canceled = event.isCanceled();
3557 final int keyCode = event.getKeyCode();
Jeff Browne20c9e02010-10-11 14:20:19 -07003558
Jeff Brown3122e442010-10-11 23:32:49 -07003559 final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0;
Jeff Brown3122e442010-10-11 23:32:49 -07003560
Mike Lockwoodc72b15f2009-11-28 20:58:22 -05003561 // If screen is off then we treat the case where the keyguard is open but hidden
3562 // the same as if it were open and in front.
3563 // This will prevent any keys other than the power button from waking the screen
3564 // when the keyguard is hidden by another activity.
Mike Lockwood3a74bd32011-08-12 13:55:22 -07003565 final boolean keyguardActive = (mKeyguardMediator == null ? false :
3566 (isScreenOn ?
3567 mKeyguardMediator.isShowingAndNotHidden() :
3568 mKeyguardMediator.isShowing()));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003569
Jeff Brown96307042012-07-27 15:51:34 -07003570 if (keyCode == KeyEvent.KEYCODE_POWER) {
3571 policyFlags |= WindowManagerPolicy.FLAG_WAKE;
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07003572 }
Jeff Brown96307042012-07-27 15:51:34 -07003573 final boolean isWakeKey = (policyFlags & (WindowManagerPolicy.FLAG_WAKE
3574 | WindowManagerPolicy.FLAG_WAKE_DROPPED)) != 0;
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07003575
Jeff Brown40013652012-05-16 21:22:36 -07003576 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003577 Log.d(TAG, "interceptKeyTq keycode=" + keyCode
Jeff Brown96307042012-07-27 15:51:34 -07003578 + " screenIsOn=" + isScreenOn + " keyguardActive=" + keyguardActive
3579 + " policyFlags=" + Integer.toHexString(policyFlags)
3580 + " isWakeKey=" + isWakeKey);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003581 }
3582
Jeff Brown98392ef2011-09-12 18:24:59 -07003583 if (down && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0
3584 && event.getRepeatCount() == 0) {
Jeff Brown4d396052010-10-29 21:50:21 -07003585 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
3586 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003587
Jeff Brown4d396052010-10-29 21:50:21 -07003588 // Basic policy based on screen state and keyguard.
3589 // FIXME: This policy isn't quite correct. We shouldn't care whether the screen
3590 // is on or off, really. We should care about whether the device is in an
3591 // interactive state or is in suspend pretending to be "off".
3592 // The primary screen might be turned off due to proximity sensor or
3593 // because we are presenting media on an auxiliary screen or remotely controlling
3594 // the device some other way (which is why we have an exemption here for injected
3595 // events).
3596 int result;
Mike Lockwoodd747dc82011-09-13 16:28:22 -04003597 if ((isScreenOn && !mHeadless) || (isInjected && !isWakeKey)) {
Jeff Brown4d396052010-10-29 21:50:21 -07003598 // When the screen is on or if the key is injected pass the key to the application.
3599 result = ACTION_PASS_TO_USER;
3600 } else {
3601 // When the screen is off and the key is not injected, determine whether
3602 // to wake the device but don't pass the key to the application.
3603 result = 0;
Jeff Brown1c2e4942012-11-06 16:32:01 -08003604 if (down && isWakeKey && isWakeKeyWhenScreenOff(keyCode)) {
Jeff Brown4d396052010-10-29 21:50:21 -07003605 if (keyguardActive) {
Jeff Brown1c2e4942012-11-06 16:32:01 -08003606 // If the keyguard is showing, let it wake the device when ready.
3607 mKeyguardMediator.onWakeKeyWhenKeyguardShowingTq(keyCode);
Jeff Brown4d396052010-10-29 21:50:21 -07003608 } else {
3609 // Otherwise, wake the device ourselves.
Jeff Brown96307042012-07-27 15:51:34 -07003610 result |= ACTION_WAKE_UP;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003611 }
3612 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003613 }
3614
Justin Kohd378ad72013-04-01 12:18:26 -07003615 // If the key would be handled globally, just return the result, don't worry about special
3616 // key processing.
3617 if (mGlobalKeyManager.shouldHandleGlobalKey(keyCode, event)) {
3618 return result;
3619 }
3620
Jeff Brown4d396052010-10-29 21:50:21 -07003621 // Handle special keys.
3622 switch (keyCode) {
3623 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jeff Brownb0418da2010-11-01 15:24:01 -07003624 case KeyEvent.KEYCODE_VOLUME_UP:
3625 case KeyEvent.KEYCODE_VOLUME_MUTE: {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003626 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
3627 if (down) {
3628 if (isScreenOn && !mVolumeDownKeyTriggered
3629 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
3630 mVolumeDownKeyTriggered = true;
3631 mVolumeDownKeyTime = event.getDownTime();
3632 mVolumeDownKeyConsumedByScreenshotChord = false;
3633 cancelPendingPowerKeyAction();
3634 interceptScreenshotChord();
3635 }
3636 } else {
3637 mVolumeDownKeyTriggered = false;
3638 cancelPendingScreenshotChordAction();
3639 }
3640 } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
3641 if (down) {
3642 if (isScreenOn && !mVolumeUpKeyTriggered
3643 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
3644 mVolumeUpKeyTriggered = true;
3645 cancelPendingPowerKeyAction();
3646 cancelPendingScreenshotChordAction();
3647 }
3648 } else {
3649 mVolumeUpKeyTriggered = false;
3650 cancelPendingScreenshotChordAction();
3651 }
3652 }
Jeff Brown4d396052010-10-29 21:50:21 -07003653 if (down) {
3654 ITelephony telephonyService = getTelephonyService();
3655 if (telephonyService != null) {
3656 try {
3657 if (telephonyService.isRinging()) {
3658 // If an incoming call is ringing, either VOLUME key means
3659 // "silence ringer". We handle these keys here, rather than
3660 // in the InCallScreen, to make sure we'll respond to them
3661 // even if the InCallScreen hasn't come to the foreground yet.
3662 // Look for the DOWN event here, to agree with the "fallback"
3663 // behavior in the InCallScreen.
3664 Log.i(TAG, "interceptKeyBeforeQueueing:"
3665 + " VOLUME key-down while ringing: Silence ringer!");
3666
3667 // Silence the ringer. (It's safe to call this
3668 // even if the ringer has already been silenced.)
3669 telephonyService.silenceRinger();
3670
3671 // And *don't* pass this key thru to the current activity
3672 // (which is probably the InCallScreen.)
3673 result &= ~ACTION_PASS_TO_USER;
3674 break;
3675 }
3676 if (telephonyService.isOffhook()
3677 && (result & ACTION_PASS_TO_USER) == 0) {
3678 // If we are in call but we decided not to pass the key to
3679 // the application, handle the volume change here.
3680 handleVolumeKey(AudioManager.STREAM_VOICE_CALL, keyCode);
3681 break;
3682 }
3683 } catch (RemoteException ex) {
3684 Log.w(TAG, "ITelephony threw RemoteException", ex);
3685 }
3686 }
3687
3688 if (isMusicActive() && (result & ACTION_PASS_TO_USER) == 0) {
3689 // If music is playing but we decided not to pass the key to the
3690 // application, handle the volume change here.
3691 handleVolumeKey(AudioManager.STREAM_MUSIC, keyCode);
3692 break;
3693 }
3694 }
3695 break;
3696 }
3697
3698 case KeyEvent.KEYCODE_ENDCALL: {
3699 result &= ~ACTION_PASS_TO_USER;
3700 if (down) {
3701 ITelephony telephonyService = getTelephonyService();
3702 boolean hungUp = false;
3703 if (telephonyService != null) {
3704 try {
3705 hungUp = telephonyService.endCall();
3706 } catch (RemoteException ex) {
3707 Log.w(TAG, "ITelephony threw RemoteException", ex);
3708 }
3709 }
3710 interceptPowerKeyDown(!isScreenOn || hungUp);
3711 } else {
3712 if (interceptPowerKeyUp(canceled)) {
3713 if ((mEndcallBehavior
3714 & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) {
3715 if (goHome()) {
3716 break;
Dianne Hackborn0041e972009-07-24 17:14:43 -07003717 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003718 }
Jeff Brown4d396052010-10-29 21:50:21 -07003719 if ((mEndcallBehavior
3720 & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) {
Jeff Brown96307042012-07-27 15:51:34 -07003721 result = (result & ~ACTION_WAKE_UP) | ACTION_GO_TO_SLEEP;
Jeff Brown4d396052010-10-29 21:50:21 -07003722 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003723 }
Jeff Brown4d396052010-10-29 21:50:21 -07003724 }
3725 break;
3726 }
3727
3728 case KeyEvent.KEYCODE_POWER: {
3729 result &= ~ACTION_PASS_TO_USER;
3730 if (down) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003731 if (isScreenOn && !mPowerKeyTriggered
3732 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
3733 mPowerKeyTriggered = true;
3734 mPowerKeyTime = event.getDownTime();
3735 interceptScreenshotChord();
Winson Chung9112ec32011-06-27 13:15:32 -07003736 }
Winson Chung9112ec32011-06-27 13:15:32 -07003737
Jeff Brown4d396052010-10-29 21:50:21 -07003738 ITelephony telephonyService = getTelephonyService();
3739 boolean hungUp = false;
3740 if (telephonyService != null) {
3741 try {
3742 if (telephonyService.isRinging()) {
3743 // Pressing Power while there's a ringing incoming
3744 // call should silence the ringer.
3745 telephonyService.silenceRinger();
3746 } else if ((mIncallPowerBehavior
3747 & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0
3748 && telephonyService.isOffhook()) {
3749 // Otherwise, if "Power button ends call" is enabled,
3750 // the Power button will hang up any current active call.
3751 hungUp = telephonyService.endCall();
3752 }
3753 } catch (RemoteException ex) {
3754 Log.w(TAG, "ITelephony threw RemoteException", ex);
3755 }
3756 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003757 interceptPowerKeyDown(!isScreenOn || hungUp
3758 || mVolumeDownKeyTriggered || mVolumeUpKeyTriggered);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003759 } else {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003760 mPowerKeyTriggered = false;
3761 cancelPendingScreenshotChordAction();
3762 if (interceptPowerKeyUp(canceled || mPendingPowerKeyUpCanceled)) {
Jeff Brown96307042012-07-27 15:51:34 -07003763 result = (result & ~ACTION_WAKE_UP) | ACTION_GO_TO_SLEEP;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003764 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003765 mPendingPowerKeyUpCanceled = false;
Jeff Brown4d396052010-10-29 21:50:21 -07003766 }
3767 break;
3768 }
3769
3770 case KeyEvent.KEYCODE_MEDIA_PLAY:
3771 case KeyEvent.KEYCODE_MEDIA_PAUSE:
3772 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
3773 if (down) {
3774 ITelephony telephonyService = getTelephonyService();
3775 if (telephonyService != null) {
3776 try {
3777 if (!telephonyService.isIdle()) {
3778 // Suppress PLAY/PAUSE toggle when phone is ringing or in-call
3779 // to avoid music playback.
3780 break;
3781 }
3782 } catch (RemoteException ex) {
3783 Log.w(TAG, "ITelephony threw RemoteException", ex);
Jeff Brown3122e442010-10-11 23:32:49 -07003784 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003785 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003786 }
Jeff Brown4d396052010-10-29 21:50:21 -07003787 case KeyEvent.KEYCODE_HEADSETHOOK:
3788 case KeyEvent.KEYCODE_MUTE:
3789 case KeyEvent.KEYCODE_MEDIA_STOP:
3790 case KeyEvent.KEYCODE_MEDIA_NEXT:
3791 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
3792 case KeyEvent.KEYCODE_MEDIA_REWIND:
3793 case KeyEvent.KEYCODE_MEDIA_RECORD:
3794 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD: {
3795 if ((result & ACTION_PASS_TO_USER) == 0) {
3796 // Only do this if we would otherwise not pass it to the user. In that
3797 // case, the PhoneWindow class will do the same thing, except it will
3798 // only do it if the showing app doesn't process the key on its own.
Jeff Brown40013652012-05-16 21:22:36 -07003799 // Note that we need to make a copy of the key event here because the
3800 // original key event will be recycled when we return.
Jeff Brown4d396052010-10-29 21:50:21 -07003801 mBroadcastWakeLock.acquire();
Jeff Brown40013652012-05-16 21:22:36 -07003802 Message msg = mHandler.obtainMessage(MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK,
3803 new KeyEvent(event));
3804 msg.setAsynchronous(true);
3805 msg.sendToTarget();
Jeff Brown4d396052010-10-29 21:50:21 -07003806 }
3807 break;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003808 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003809
Jeff Brown4d396052010-10-29 21:50:21 -07003810 case KeyEvent.KEYCODE_CALL: {
3811 if (down) {
3812 ITelephony telephonyService = getTelephonyService();
3813 if (telephonyService != null) {
3814 try {
3815 if (telephonyService.isRinging()) {
3816 Log.i(TAG, "interceptKeyBeforeQueueing:"
3817 + " CALL key-down while ringing: Answer the call!");
3818 telephonyService.answerRingingCall();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003819
Jeff Brown4d396052010-10-29 21:50:21 -07003820 // And *don't* pass this key thru to the current activity
3821 // (which is presumably the InCallScreen.)
3822 result &= ~ACTION_PASS_TO_USER;
3823 }
3824 } catch (RemoteException ex) {
3825 Log.w(TAG, "ITelephony threw RemoteException", ex);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003826 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003827 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003828 }
Jeff Brown4d396052010-10-29 21:50:21 -07003829 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003830 }
3831 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003832 return result;
3833 }
3834
Jeff Brown1c2e4942012-11-06 16:32:01 -08003835 /**
3836 * When the screen is off we ignore some keys that might otherwise typically
3837 * be considered wake keys. We filter them out here.
3838 *
3839 * {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it
3840 * is always considered a wake key.
3841 */
3842 private boolean isWakeKeyWhenScreenOff(int keyCode) {
3843 switch (keyCode) {
3844 // ignore volume keys unless docked
3845 case KeyEvent.KEYCODE_VOLUME_UP:
3846 case KeyEvent.KEYCODE_VOLUME_DOWN:
3847 case KeyEvent.KEYCODE_VOLUME_MUTE:
3848 return mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED;
3849
3850 // ignore media and camera keys
3851 case KeyEvent.KEYCODE_MUTE:
3852 case KeyEvent.KEYCODE_HEADSETHOOK:
3853 case KeyEvent.KEYCODE_MEDIA_PLAY:
3854 case KeyEvent.KEYCODE_MEDIA_PAUSE:
3855 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
3856 case KeyEvent.KEYCODE_MEDIA_STOP:
3857 case KeyEvent.KEYCODE_MEDIA_NEXT:
3858 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
3859 case KeyEvent.KEYCODE_MEDIA_REWIND:
3860 case KeyEvent.KEYCODE_MEDIA_RECORD:
3861 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
3862 case KeyEvent.KEYCODE_CAMERA:
3863 return false;
3864 }
3865 return true;
3866 }
3867
3868
Jeff Brown56194eb2011-03-02 19:23:13 -08003869 /** {@inheritDoc} */
3870 @Override
3871 public int interceptMotionBeforeQueueingWhenScreenOff(int policyFlags) {
3872 int result = 0;
3873
3874 final boolean isWakeMotion = (policyFlags
3875 & (WindowManagerPolicy.FLAG_WAKE | WindowManagerPolicy.FLAG_WAKE_DROPPED)) != 0;
3876 if (isWakeMotion) {
Mike Lockwood3a74bd32011-08-12 13:55:22 -07003877 if (mKeyguardMediator != null && mKeyguardMediator.isShowing()) {
Jeff Brown56194eb2011-03-02 19:23:13 -08003878 // If the keyguard is showing, let it decide what to do with the wake motion.
3879 mKeyguardMediator.onWakeMotionWhenKeyguardShowingTq();
3880 } else {
3881 // Otherwise, wake the device ourselves.
Jeff Brown96307042012-07-27 15:51:34 -07003882 result |= ACTION_WAKE_UP;
Jeff Brown56194eb2011-03-02 19:23:13 -08003883 }
3884 }
3885 return result;
3886 }
3887
Jeff Brown40013652012-05-16 21:22:36 -07003888 void dispatchMediaKeyWithWakeLock(KeyEvent event) {
3889 if (DEBUG_INPUT) {
3890 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: " + event);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003891 }
3892
Jeff Brown40013652012-05-16 21:22:36 -07003893 if (mHavePendingMediaKeyRepeatWithWakeLock) {
3894 if (DEBUG_INPUT) {
3895 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: canceled repeat");
3896 }
3897
3898 mHandler.removeMessages(MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK);
3899 mHavePendingMediaKeyRepeatWithWakeLock = false;
3900 mBroadcastWakeLock.release(); // pending repeat was holding onto the wake lock
3901 }
3902
3903 dispatchMediaKeyWithWakeLockToAudioService(event);
3904
3905 if (event.getAction() == KeyEvent.ACTION_DOWN
3906 && event.getRepeatCount() == 0) {
3907 mHavePendingMediaKeyRepeatWithWakeLock = true;
3908
3909 Message msg = mHandler.obtainMessage(
3910 MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK, event);
3911 msg.setAsynchronous(true);
3912 mHandler.sendMessageDelayed(msg, ViewConfiguration.getKeyRepeatTimeout());
3913 } else {
3914 mBroadcastWakeLock.release();
3915 }
3916 }
3917
3918 void dispatchMediaKeyRepeatWithWakeLock(KeyEvent event) {
3919 mHavePendingMediaKeyRepeatWithWakeLock = false;
3920
3921 KeyEvent repeatEvent = KeyEvent.changeTimeRepeat(event,
3922 SystemClock.uptimeMillis(), 1, event.getFlags() | KeyEvent.FLAG_LONG_PRESS);
3923 if (DEBUG_INPUT) {
3924 Slog.d(TAG, "dispatchMediaKeyRepeatWithWakeLock: " + repeatEvent);
3925 }
3926
3927 dispatchMediaKeyWithWakeLockToAudioService(repeatEvent);
3928 mBroadcastWakeLock.release();
3929 }
3930
3931 void dispatchMediaKeyWithWakeLockToAudioService(KeyEvent event) {
3932 if (ActivityManagerNative.isSystemReady()) {
3933 IAudioService audioService = getAudioService();
3934 if (audioService != null) {
3935 try {
3936 audioService.dispatchMediaKeyEventUnderWakelock(event);
3937 } catch (RemoteException e) {
3938 Log.e(TAG, "dispatchMediaKeyEvent threw exception " + e);
Jean-Michel Trivic6802222012-04-30 11:15:03 -07003939 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003940 }
3941 }
3942 }
3943
Mike Lockwood1753f7f2009-08-24 14:49:07 -07003944 BroadcastReceiver mDockReceiver = new BroadcastReceiver() {
Craig Mautnereee29c42013-01-17 14:44:34 -08003945 @Override
Mike Lockwood1753f7f2009-08-24 14:49:07 -07003946 public void onReceive(Context context, Intent intent) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07003947 if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) {
3948 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
3949 Intent.EXTRA_DOCK_STATE_UNDOCKED);
Dianne Hackborn80fa1662009-10-07 14:02:10 -07003950 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07003951 updateRotation(true);
Craig Mautnereee29c42013-01-17 14:44:34 -08003952 synchronized (mLock) {
3953 updateOrientationListenerLp();
3954 }
Mike Lockwood1753f7f2009-08-24 14:49:07 -07003955 }
3956 };
3957
Jeff Brown6aaf2952012-10-05 16:01:08 -07003958 BroadcastReceiver mDreamReceiver = new BroadcastReceiver() {
3959 @Override
3960 public void onReceive(Context context, Intent intent) {
3961 if (Intent.ACTION_DREAMING_STARTED.equals(intent.getAction())) {
3962 if (mKeyguardMediator != null) {
3963 mKeyguardMediator.onDreamingStarted();
3964 }
3965 } else if (Intent.ACTION_DREAMING_STOPPED.equals(intent.getAction())) {
3966 if (mKeyguardMediator != null) {
3967 mKeyguardMediator.onDreamingStopped();
3968 }
3969 }
3970 }
3971 };
3972
Christopher Tate5e08af02012-09-21 17:17:22 -07003973 BroadcastReceiver mMultiuserReceiver = new BroadcastReceiver() {
3974 @Override
3975 public void onReceive(Context context, Intent intent) {
3976 if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) {
3977 // tickle the settings observer: this first ensures that we're
3978 // observing the relevant settings for the newly-active user,
3979 // and then updates our own bookkeeping based on the now-
3980 // current user.
3981 mSettingsObserver.onChange(false);
John Spurlockce479d82012-11-29 09:52:21 -05003982
3983 // force a re-application of focused window sysui visibility.
3984 // the window may never have been shown for this user
3985 // e.g. the keyguard when going through the new-user setup flow
3986 synchronized(mLock) {
3987 mLastSystemUiFlags = 0;
3988 updateSystemUiVisibilityLw();
3989 }
Christopher Tate5e08af02012-09-21 17:17:22 -07003990 }
3991 }
3992 };
3993
Jeff Brownc38c9be2012-10-04 13:16:19 -07003994 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003995 public void screenTurnedOff(int why) {
Dianne Hackborn74489012009-03-24 20:50:09 -07003996 EventLog.writeEvent(70000, 0);
The Android Open Source Project0727d222009-03-11 12:11:58 -07003997 synchronized (mLock) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07003998 mScreenOnEarly = false;
3999 mScreenOnFully = false;
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07004000 }
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004001 if (mKeyguardMediator != null) {
4002 mKeyguardMediator.onScreenTurnedOff(why);
4003 }
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07004004 synchronized (mLock) {
The Android Open Source Project0727d222009-03-11 12:11:58 -07004005 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05004006 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07004007 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004008 }
4009
Jeff Brownc38c9be2012-10-04 13:16:19 -07004010 @Override
Dianne Hackborn38e29a62011-09-18 14:43:08 -07004011 public void screenTurningOn(final ScreenOnListener screenOnListener) {
Dianne Hackborn74489012009-03-24 20:50:09 -07004012 EventLog.writeEvent(70000, 1);
Dianne Hackborn40011092011-09-22 13:37:48 -07004013 if (false) {
4014 RuntimeException here = new RuntimeException("here");
4015 here.fillInStackTrace();
4016 Slog.i(TAG, "Screen turning on...", here);
4017 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07004018
The Android Open Source Project0727d222009-03-11 12:11:58 -07004019 synchronized (mLock) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004020 mScreenOnEarly = true;
The Android Open Source Project0727d222009-03-11 12:11:58 -07004021 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05004022 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07004023 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07004024
Jeff Brownc38c9be2012-10-04 13:16:19 -07004025 waitForKeyguard(screenOnListener);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004026 }
4027
Jeff Brownc38c9be2012-10-04 13:16:19 -07004028 private void waitForKeyguard(final ScreenOnListener screenOnListener) {
4029 if (mKeyguardMediator != null) {
4030 if (screenOnListener != null) {
4031 mKeyguardMediator.onScreenTurnedOn(new KeyguardViewManager.ShowListener() {
4032 @Override
4033 public void onShown(IBinder windowToken) {
4034 waitForKeyguardWindowDrawn(windowToken, screenOnListener);
4035 }
4036 });
4037 return;
4038 } else {
4039 mKeyguardMediator.onScreenTurnedOn(null);
4040 }
4041 } else {
4042 Slog.i(TAG, "No keyguard mediator!");
4043 }
4044 finishScreenTurningOn(screenOnListener);
4045 }
4046
4047 private void waitForKeyguardWindowDrawn(IBinder windowToken,
4048 final ScreenOnListener screenOnListener) {
4049 if (windowToken != null) {
4050 try {
4051 if (mWindowManager.waitForWindowDrawn(
4052 windowToken, new IRemoteCallback.Stub() {
4053 @Override
4054 public void sendResult(Bundle data) {
4055 Slog.i(TAG, "Lock screen displayed!");
4056 finishScreenTurningOn(screenOnListener);
4057 }
4058 })) {
4059 return;
4060 }
4061 } catch (RemoteException ex) {
4062 // Can't happen in system process.
4063 }
4064 }
4065
4066 Slog.i(TAG, "No lock screen!");
4067 finishScreenTurningOn(screenOnListener);
4068 }
4069
4070 private void finishScreenTurningOn(ScreenOnListener screenOnListener) {
4071 synchronized (mLock) {
4072 mScreenOnFully = true;
4073 }
4074
Jeff Brown4fc45272012-10-10 18:28:14 -07004075 try {
4076 mWindowManager.setEventDispatching(true);
4077 } catch (RemoteException unhandled) {
4078 }
4079
Jeff Brownc38c9be2012-10-04 13:16:19 -07004080 if (screenOnListener != null) {
4081 screenOnListener.onScreenOn();
4082 }
4083 }
4084
4085 @Override
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004086 public boolean isScreenOnEarly() {
4087 return mScreenOnEarly;
4088 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07004089
4090 @Override
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004091 public boolean isScreenOnFully() {
4092 return mScreenOnFully;
Dianne Hackborn08743722009-12-21 12:16:51 -08004093 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07004094
Dianne Hackborn08743722009-12-21 12:16:51 -08004095 /** {@inheritDoc} */
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004096 public void enableKeyguard(boolean enabled) {
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004097 if (mKeyguardMediator != null) {
4098 mKeyguardMediator.setKeyguardEnabled(enabled);
4099 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004100 }
4101
4102 /** {@inheritDoc} */
4103 public void exitKeyguardSecurely(OnKeyguardExitResult callback) {
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004104 if (mKeyguardMediator != null) {
4105 mKeyguardMediator.verifyUnlock(callback);
4106 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004107 }
4108
Mike Lockwoodf7913302009-11-28 22:27:10 -05004109 private boolean keyguardIsShowingTq() {
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004110 if (mKeyguardMediator == null) return false;
Dianne Hackborn9dc06cc2009-11-17 18:19:23 -08004111 return mKeyguardMediator.isShowingAndNotHidden();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004112 }
4113
Mike Lockwood520d8bc2011-02-18 13:23:13 -05004114
4115 /** {@inheritDoc} */
4116 public boolean isKeyguardLocked() {
4117 return keyguardOn();
4118 }
4119
4120 /** {@inheritDoc} */
4121 public boolean isKeyguardSecure() {
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004122 if (mKeyguardMediator == null) return false;
Mike Lockwood520d8bc2011-02-18 13:23:13 -05004123 return mKeyguardMediator.isSecure();
4124 }
4125
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004126 /** {@inheritDoc} */
4127 public boolean inKeyguardRestrictedKeyInputMode() {
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004128 if (mKeyguardMediator == null) return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004129 return mKeyguardMediator.isInputRestricted();
4130 }
4131
Dianne Hackborn90c52de2011-09-23 12:57:44 -07004132 public void dismissKeyguardLw() {
Daniel Sandler1ce804392012-11-07 15:07:12 -05004133 if (mKeyguardMediator.isShowing()) {
4134 mHandler.post(new Runnable() {
4135 public void run() {
4136 if (mKeyguardMediator.isDismissable()) {
4137 // Can we just finish the keyguard straight away?
Dianne Hackborn90c52de2011-09-23 12:57:44 -07004138 mKeyguardMediator.keyguardDone(false, true);
Daniel Sandler1ce804392012-11-07 15:07:12 -05004139 } else {
4140 // ask the keyguard to prompt the user to authenticate if necessary
4141 mKeyguardMediator.dismiss();
Dianne Hackborn90c52de2011-09-23 12:57:44 -07004142 }
Daniel Sandler1ce804392012-11-07 15:07:12 -05004143 }
4144 });
Dianne Hackborn90c52de2011-09-23 12:57:44 -07004145 }
4146 }
4147
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004148 void sendCloseSystemWindows() {
4149 sendCloseSystemWindows(mContext, null);
4150 }
4151
4152 void sendCloseSystemWindows(String reason) {
4153 sendCloseSystemWindows(mContext, reason);
4154 }
4155
4156 static void sendCloseSystemWindows(Context context, String reason) {
4157 if (ActivityManagerNative.isSystemReady()) {
Dianne Hackborn94a679d2009-07-28 17:51:07 -07004158 try {
4159 ActivityManagerNative.getDefault().closeSystemDialogs(reason);
4160 } catch (RemoteException e) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004161 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004162 }
4163 }
Mitsuru Oshima831d0d92009-06-16 18:27:18 -07004164
Jeff Brown01a98dd2011-09-20 15:08:29 -07004165 @Override
4166 public int rotationForOrientationLw(int orientation, int lastRotation) {
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05004167 if (false) {
4168 Slog.v(TAG, "rotationForOrientationLw(orient="
4169 + orientation + ", last=" + lastRotation
4170 + "); user=" + mUserRotation + " "
4171 + ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED)
4172 ? "USER_ROTATION_LOCKED" : "")
4173 );
4174 }
4175
The Android Open Source Project0727d222009-03-11 12:11:58 -07004176 synchronized (mLock) {
Jeff Brownc0347aa2011-09-23 17:26:09 -07004177 int sensorRotation = mOrientationListener.getProposedRotation(); // may be -1
4178 if (sensorRotation < 0) {
Jeff Brown0f862b42012-09-27 21:11:01 -07004179 sensorRotation = lastRotation;
Jeff Brownc0347aa2011-09-23 17:26:09 -07004180 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004181
Jeff Browndec6cf42011-11-15 14:08:20 -08004182 final int preferredRotation;
Jeff Brown2e7760e2012-04-11 15:14:55 -07004183 if (mLidState == LID_OPEN && mLidOpenRotation >= 0) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07004184 // Ignore sensor when lid switch is open and rotation is forced.
4185 preferredRotation = mLidOpenRotation;
4186 } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR
Jeff Brownc0347aa2011-09-23 17:26:09 -07004187 && (mCarDockEnablesAccelerometer || mCarDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07004188 // Ignore sensor when in car dock unless explicitly enabled.
4189 // This case can override the behavior of NOSENSOR, and can also
4190 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07004191 preferredRotation = mCarDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07004192 ? sensorRotation : mCarDockRotation;
Jeff Brown1a693182011-11-08 14:44:16 -08004193 } else if ((mDockMode == Intent.EXTRA_DOCK_STATE_DESK
4194 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
4195 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK)
Jeff Brownc0347aa2011-09-23 17:26:09 -07004196 && (mDeskDockEnablesAccelerometer || mDeskDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07004197 // Ignore sensor when in desk dock unless explicitly enabled.
4198 // This case can override the behavior of NOSENSOR, and can also
4199 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07004200 preferredRotation = mDeskDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07004201 ? sensorRotation : mDeskDockRotation;
Jeff Brown27f1d672012-10-17 18:32:34 -07004202 } else if (mHdmiPlugged && mHdmiRotationLock) {
Jeff Browneb3e4b92011-12-06 19:54:24 -08004203 // Ignore sensor when plugged into HDMI.
4204 // Note that the dock orientation overrides the HDMI orientation.
4205 preferredRotation = mHdmiRotation;
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07004206 } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED) {
4207 // Application just wants to remain locked in the last rotation.
4208 preferredRotation = lastRotation;
Jeff Brown207673cd2012-06-05 17:47:11 -07004209 } else if ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE
Jeff Brown01a98dd2011-09-20 15:08:29 -07004210 && (orientation == ActivityInfo.SCREEN_ORIENTATION_USER
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07004211 || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
4212 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
4213 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
4214 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER))
Jeff Brown01a98dd2011-09-20 15:08:29 -07004215 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
4216 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
4217 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
4218 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) {
4219 // Otherwise, use sensor only if requested by the application or enabled
4220 // by default for USER or UNSPECIFIED modes. Does not apply to NOSENSOR.
Jeff Brownd3187e32011-09-21 19:26:44 -07004221 if (mAllowAllRotations < 0) {
4222 // Can't read this during init() because the context doesn't
4223 // have display metrics at that time so we cannot determine
4224 // tablet vs. phone then.
4225 mAllowAllRotations = mContext.getResources().getBoolean(
4226 com.android.internal.R.bool.config_allowAllRotations) ? 1 : 0;
4227 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004228 if (sensorRotation != Surface.ROTATION_180
Jeff Brownd3187e32011-09-21 19:26:44 -07004229 || mAllowAllRotations == 1
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07004230 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
4231 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07004232 preferredRotation = sensorRotation;
4233 } else {
4234 preferredRotation = lastRotation;
4235 }
Jeff Brown207673cd2012-06-05 17:47:11 -07004236 } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED
4237 && orientation != ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) {
4238 // Apply rotation lock. Does not apply to NOSENSOR.
4239 // The idea is that the user rotation expresses a weak preference for the direction
4240 // of gravity and as NOSENSOR is never affected by gravity, then neither should
4241 // NOSENSOR be affected by rotation lock (although it will be affected by docks).
Jeff Brown4dfce202011-10-05 12:00:10 -07004242 preferredRotation = mUserRotation;
Jeff Browndec6cf42011-11-15 14:08:20 -08004243 } else {
4244 // No overriding preference.
4245 // We will do exactly what the application asked us to do.
4246 preferredRotation = -1;
Jeff Brown01a98dd2011-09-20 15:08:29 -07004247 }
4248
Dianne Hackborne5439f22010-10-02 16:53:50 -07004249 switch (orientation) {
4250 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08004251 // Return portrait unless overridden.
4252 if (isAnyPortrait(preferredRotation)) {
4253 return preferredRotation;
4254 }
Dianne Hackborne5439f22010-10-02 16:53:50 -07004255 return mPortraitRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07004256
Jeff Brown01a98dd2011-09-20 15:08:29 -07004257 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08004258 // Return landscape unless overridden.
4259 if (isLandscapeOrSeascape(preferredRotation)) {
4260 return preferredRotation;
4261 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004262 return mLandscapeRotation;
4263
4264 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08004265 // Return reverse portrait unless overridden.
4266 if (isAnyPortrait(preferredRotation)) {
4267 return preferredRotation;
4268 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004269 return mUpsideDownRotation;
4270
4271 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08004272 // Return seascape unless overridden.
4273 if (isLandscapeOrSeascape(preferredRotation)) {
4274 return preferredRotation;
4275 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004276 return mSeascapeRotation;
4277
4278 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07004279 case ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE:
Jeff Brown01a98dd2011-09-20 15:08:29 -07004280 // Return either landscape rotation.
4281 if (isLandscapeOrSeascape(preferredRotation)) {
4282 return preferredRotation;
4283 }
4284 if (isLandscapeOrSeascape(lastRotation)) {
Jeff Brown4519f072011-01-23 13:16:01 -08004285 return lastRotation;
4286 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004287 return mLandscapeRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004288
Jeff Brown01a98dd2011-09-20 15:08:29 -07004289 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07004290 case ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT:
Jeff Brown01a98dd2011-09-20 15:08:29 -07004291 // Return either portrait rotation.
4292 if (isAnyPortrait(preferredRotation)) {
4293 return preferredRotation;
4294 }
4295 if (isAnyPortrait(lastRotation)) {
4296 return lastRotation;
4297 }
4298 return mPortraitRotation;
4299
4300 default:
Jeff Brown4dfce202011-10-05 12:00:10 -07004301 // For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR,
4302 // just return the preferred orientation we already calculated.
Jeff Brown01a98dd2011-09-20 15:08:29 -07004303 if (preferredRotation >= 0) {
4304 return preferredRotation;
4305 }
Dianne Hackborndacea8c2011-04-21 17:26:39 -07004306 return Surface.ROTATION_0;
Daniel Sandlere7e5ac22011-02-22 16:10:21 -05004307 }
4308 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07004309 }
4310
Jeff Brown01a98dd2011-09-20 15:08:29 -07004311 @Override
4312 public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation) {
4313 switch (orientation) {
4314 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
4315 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
4316 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
4317 return isAnyPortrait(rotation);
4318
4319 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
4320 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
4321 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
4322 return isLandscapeOrSeascape(rotation);
4323
4324 default:
4325 return true;
4326 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07004327 }
4328
Jeff Brownc0347aa2011-09-23 17:26:09 -07004329 @Override
4330 public void setRotationLw(int rotation) {
4331 mOrientationListener.setCurrentRotation(rotation);
4332 }
4333
Jeff Brown01a98dd2011-09-20 15:08:29 -07004334 private boolean isLandscapeOrSeascape(int rotation) {
4335 return rotation == mLandscapeRotation || rotation == mSeascapeRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07004336 }
4337
Jeff Brown01a98dd2011-09-20 15:08:29 -07004338 private boolean isAnyPortrait(int rotation) {
4339 return rotation == mPortraitRotation || rotation == mUpsideDownRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07004340 }
4341
Svetoslav Ganov80943d82013-01-02 10:25:37 -08004342 public int getUserRotationMode() {
4343 return Settings.System.getIntForUser(mContext.getContentResolver(),
4344 Settings.System.USER_ROTATION, WindowManagerPolicy.USER_ROTATION_FREE,
4345 UserHandle.USER_CURRENT);
4346 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004347
4348 // User rotation: to be used when all else fails in assigning an orientation to the device
4349 public void setUserRotationMode(int mode, int rot) {
4350 ContentResolver res = mContext.getContentResolver();
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05004351
4352 // mUserRotationMode and mUserRotation will be assigned by the content observer
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004353 if (mode == WindowManagerPolicy.USER_ROTATION_LOCKED) {
Christopher Tate5e08af02012-09-21 17:17:22 -07004354 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004355 Settings.System.USER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07004356 rot,
4357 UserHandle.USER_CURRENT);
4358 Settings.System.putIntForUser(res,
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05004359 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07004360 0,
4361 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004362 } else {
Christopher Tate5e08af02012-09-21 17:17:22 -07004363 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004364 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07004365 1,
4366 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004367 }
4368 }
4369
Jeff Brownac143512012-04-05 18:57:33 -07004370 public void setSafeMode(boolean safeMode) {
4371 mSafeMode = safeMode;
4372 performHapticFeedbackLw(null, safeMode
4373 ? HapticFeedbackConstants.SAFE_MODE_ENABLED
4374 : HapticFeedbackConstants.SAFE_MODE_DISABLED, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004375 }
4376
Dianne Hackborn181ceb52009-08-27 22:16:40 -07004377 static long[] getLongIntArray(Resources r, int resid) {
4378 int[] ar = r.getIntArray(resid);
4379 if (ar == null) {
4380 return null;
4381 }
4382 long[] out = new long[ar.length];
4383 for (int i=0; i<ar.length; i++) {
4384 out[i] = ar[i];
4385 }
4386 return out;
4387 }
4388
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004389 /** {@inheritDoc} */
4390 public void systemReady() {
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004391 if (mKeyguardMediator != null) {
4392 // tell the keyguard
4393 mKeyguardMediator.onSystemReady();
4394 }
Dianne Hackbornb1a79802009-09-29 15:18:31 -07004395 synchronized (mLock) {
4396 updateOrientationListenerLp();
Dianne Hackbornc777e072010-02-12 13:07:59 -08004397 mSystemReady = true;
4398 mHandler.post(new Runnable() {
4399 public void run() {
4400 updateSettings();
4401 }
4402 });
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004403 }
4404 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07004405
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07004406 /** {@inheritDoc} */
4407 public void systemBooted() {
4408 synchronized (mLock) {
4409 mSystemBooted = true;
4410 }
4411 }
4412
Dianne Hackborn661cd522011-08-22 00:26:20 -07004413 ProgressDialog mBootMsgDialog = null;
4414
4415 /** {@inheritDoc} */
4416 public void showBootMessage(final CharSequence msg, final boolean always) {
Mike Lockwoodaa5bf142011-09-21 13:03:40 -04004417 if (mHeadless) return;
Dianne Hackborn661cd522011-08-22 00:26:20 -07004418 mHandler.post(new Runnable() {
4419 @Override public void run() {
4420 if (mBootMsgDialog == null) {
Dianne Hackborn295e3c22011-08-25 13:19:08 -07004421 mBootMsgDialog = new ProgressDialog(mContext) {
4422 // This dialog will consume all events coming in to
4423 // it, to avoid it trying to do things too early in boot.
4424 @Override public boolean dispatchKeyEvent(KeyEvent event) {
4425 return true;
4426 }
4427 @Override public boolean dispatchKeyShortcutEvent(KeyEvent event) {
4428 return true;
4429 }
4430 @Override public boolean dispatchTouchEvent(MotionEvent ev) {
4431 return true;
4432 }
4433 @Override public boolean dispatchTrackballEvent(MotionEvent ev) {
4434 return true;
4435 }
4436 @Override public boolean dispatchGenericMotionEvent(MotionEvent ev) {
4437 return true;
4438 }
4439 @Override public boolean dispatchPopulateAccessibilityEvent(
4440 AccessibilityEvent event) {
4441 return true;
4442 }
4443 };
Dianne Hackborn661cd522011-08-22 00:26:20 -07004444 mBootMsgDialog.setTitle(R.string.android_upgrading_title);
4445 mBootMsgDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
4446 mBootMsgDialog.setIndeterminate(true);
4447 mBootMsgDialog.getWindow().setType(
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07004448 WindowManager.LayoutParams.TYPE_BOOT_PROGRESS);
Dianne Hackborn661cd522011-08-22 00:26:20 -07004449 mBootMsgDialog.getWindow().addFlags(
4450 WindowManager.LayoutParams.FLAG_DIM_BEHIND
4451 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
4452 mBootMsgDialog.getWindow().setDimAmount(1);
Dianne Hackbornd9efb952011-12-07 14:56:51 -08004453 WindowManager.LayoutParams lp = mBootMsgDialog.getWindow().getAttributes();
4454 lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
4455 mBootMsgDialog.getWindow().setAttributes(lp);
Dianne Hackborn661cd522011-08-22 00:26:20 -07004456 mBootMsgDialog.setCancelable(false);
4457 mBootMsgDialog.show();
4458 }
4459 mBootMsgDialog.setMessage(msg);
4460 }
4461 });
4462 }
4463
4464 /** {@inheritDoc} */
4465 public void hideBootMessages() {
4466 mHandler.post(new Runnable() {
4467 @Override public void run() {
4468 if (mBootMsgDialog != null) {
4469 mBootMsgDialog.dismiss();
4470 mBootMsgDialog = null;
4471 }
4472 }
4473 });
4474 }
4475
Mike Lockwood28569302010-01-28 11:54:40 -05004476 /** {@inheritDoc} */
4477 public void userActivity() {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004478 // ***************************************
4479 // NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
4480 // ***************************************
4481 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
4482 // WITH ITS LOCKS HELD.
4483 //
4484 // This code must be VERY careful about the locks
4485 // it acquires.
4486 // In fact, the current code acquires way too many,
4487 // and probably has lurking deadlocks.
4488
Mike Lockwood28569302010-01-28 11:54:40 -05004489 synchronized (mScreenLockTimeout) {
4490 if (mLockScreenTimerActive) {
4491 // reset the timer
4492 mHandler.removeCallbacks(mScreenLockTimeout);
4493 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
4494 }
4495 }
Daniel Sandler0601eb72011-04-13 01:01:32 -04004496 }
4497
Adam Cohenf7522022012-10-03 20:03:18 -07004498 class ScreenLockTimeout implements Runnable {
4499 Bundle options;
4500
4501 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05004502 public void run() {
4503 synchronized (this) {
4504 if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard");
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004505 if (mKeyguardMediator != null) {
Adam Cohenf7522022012-10-03 20:03:18 -07004506 mKeyguardMediator.doKeyguardTimeout(options);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004507 }
Mike Lockwood28569302010-01-28 11:54:40 -05004508 mLockScreenTimerActive = false;
Adam Cohenf7522022012-10-03 20:03:18 -07004509 options = null;
Mike Lockwood28569302010-01-28 11:54:40 -05004510 }
4511 }
Mike Lockwood28569302010-01-28 11:54:40 -05004512
Adam Cohenf7522022012-10-03 20:03:18 -07004513 public void setLockOptions(Bundle options) {
4514 this.options = options;
4515 }
4516 }
4517
4518 ScreenLockTimeout mScreenLockTimeout = new ScreenLockTimeout();
4519
4520 public void lockNow(Bundle options) {
Jim Miller93c518e2012-01-17 15:55:31 -08004521 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null);
4522 mHandler.removeCallbacks(mScreenLockTimeout);
Adam Cohenf7522022012-10-03 20:03:18 -07004523 if (options != null) {
4524 // In case multiple calls are made to lockNow, we don't wipe out the options
4525 // until the runnable actually executes.
4526 mScreenLockTimeout.setLockOptions(options);
4527 }
Jim Miller93c518e2012-01-17 15:55:31 -08004528 mHandler.post(mScreenLockTimeout);
4529 }
4530
Mike Lockwood28569302010-01-28 11:54:40 -05004531 private void updateLockScreenTimeout() {
4532 synchronized (mScreenLockTimeout) {
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004533 boolean enable = (mAllowLockscreenWhenOn && mScreenOnEarly &&
4534 mKeyguardMediator != null && mKeyguardMediator.isSecure());
Mike Lockwood28569302010-01-28 11:54:40 -05004535 if (mLockScreenTimerActive != enable) {
4536 if (enable) {
4537 if (localLOGV) Log.v(TAG, "setting lockscreen timer");
4538 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
4539 } else {
4540 if (localLOGV) Log.v(TAG, "clearing lockscreen timer");
4541 mHandler.removeCallbacks(mScreenLockTimeout);
4542 }
4543 mLockScreenTimerActive = enable;
4544 }
4545 }
4546 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004547
4548 /** {@inheritDoc} */
4549 public void enableScreenAfterBoot() {
4550 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07004551 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07004552 updateRotation(true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004553 }
Dianne Hackbornf54c8f92009-09-19 14:03:57 -07004554
Jeff Brownc458ce92012-04-30 14:58:40 -07004555 private void applyLidSwitchState() {
Jeff Brownc458ce92012-04-30 14:58:40 -07004556 if (mLidState == LID_CLOSED && mLidControlsSleep) {
4557 mPowerManager.goToSleep(SystemClock.uptimeMillis());
4558 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004559 }
4560
4561 void updateRotation(boolean alwaysSendConfiguration) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004562 try {
4563 //set orientation on WindowManager
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004564 mWindowManager.updateRotation(alwaysSendConfiguration, false);
4565 } catch (RemoteException e) {
4566 // Ignore
4567 }
4568 }
4569
4570 void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) {
4571 try {
4572 //set orientation on WindowManager
4573 mWindowManager.updateRotation(alwaysSendConfiguration, forceRelayout);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004574 } catch (RemoteException e) {
4575 // Ignore
4576 }
4577 }
4578
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004579 void startDockOrHome() {
John Spurlockc8b46ca2013-04-08 12:59:26 -04004580 awakenDreams();
Daniel Sandler7c135202012-09-28 14:04:59 -04004581 // We don't have dock home anymore. Home is home. If you lived here, you'd be home by now.
Dianne Hackbornd8883992012-09-07 15:58:52 -07004582 mContext.startActivityAsUser(mHomeIntent, UserHandle.CURRENT);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004583 }
4584
4585 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004586 * goes to the home screen
4587 * @return whether it did anything
4588 */
4589 boolean goHome() {
4590 if (false) {
4591 // This code always brings home to the front.
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07004592 try {
4593 ActivityManagerNative.getDefault().stopAppSwitches();
4594 } catch (RemoteException e) {
4595 }
Dianne Hackborn94a679d2009-07-28 17:51:07 -07004596 sendCloseSystemWindows();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004597 startDockOrHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004598 } else {
4599 // This code brings home to the front or, if it is already
4600 // at the front, puts the device to sleep.
4601 try {
Wink Savilled2e6a332010-02-12 12:12:06 -08004602 if (SystemProperties.getInt("persist.sys.uts-test-mode", 0) == 1) {
4603 /// Roll back EndcallBehavior as the cupcake design to pass P1 lab entry.
4604 Log.d(TAG, "UTS-TEST-MODE");
4605 } else {
4606 ActivityManagerNative.getDefault().stopAppSwitches();
4607 sendCloseSystemWindows();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004608 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004609 int result = ActivityManagerNative.getDefault()
Dianne Hackbornf265ea92013-01-31 15:00:51 -08004610 .startActivityAsUser(null, null, mHomeIntent,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004611 mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()),
Dianne Hackborna4972e92012-03-14 10:38:05 -07004612 null, null, 0,
4613 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Dianne Hackborn5e03e2c2012-09-06 14:21:19 -07004614 null, null, null, UserHandle.USER_CURRENT);
Dianne Hackborna4972e92012-03-14 10:38:05 -07004615 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004616 return false;
4617 }
4618 } catch (RemoteException ex) {
4619 // bummer, the activity manager, which is in this process, is dead
4620 }
4621 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004622 return true;
4623 }
4624
The Android Open Source Project0727d222009-03-11 12:11:58 -07004625 public void setCurrentOrientationLw(int newOrientation) {
4626 synchronized (mLock) {
4627 if (newOrientation != mCurrentAppOrientation) {
4628 mCurrentAppOrientation = newOrientation;
4629 updateOrientationListenerLp();
4630 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004631 }
4632 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08004633
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07004634 private void performAuditoryFeedbackForAccessibilityIfNeed() {
4635 if (!isGlobalAccessibilityGestureEnabled()) {
4636 return;
4637 }
4638 AudioManager audioManager = (AudioManager) mContext.getSystemService(
4639 Context.AUDIO_SERVICE);
4640 if (audioManager.isSilentMode()) {
4641 return;
4642 }
4643 Ringtone ringTone = RingtoneManager.getRingtone(mContext,
4644 Settings.System.DEFAULT_NOTIFICATION_URI);
4645 ringTone.setStreamType(AudioManager.STREAM_MUSIC);
4646 ringTone.play();
4647 }
4648 private boolean isGlobalAccessibilityGestureEnabled() {
4649 return Settings.Global.getInt(mContext.getContentResolver(),
4650 Settings.Global.ENABLE_ACCESSIBILITY_GLOBAL_GESTURE_ENABLED, 0) == 1;
4651 }
4652
The Android Open Source Project0727d222009-03-11 12:11:58 -07004653 public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) {
Svetoslav Ganov96179212012-10-10 14:17:45 -07004654 if (!mVibrator.hasVibrator()) {
4655 return false;
4656 }
Christopher Tate5e08af02012-09-21 17:17:22 -07004657 final boolean hapticsDisabled = Settings.System.getIntForUser(mContext.getContentResolver(),
4658 Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) == 0;
Dianne Hackborn9dc06cc2009-11-17 18:19:23 -08004659 if (!always && (hapticsDisabled || mKeyguardMediator.isShowingAndNotHidden())) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004660 return false;
4661 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08004662 long[] pattern = null;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004663 switch (effectId) {
4664 case HapticFeedbackConstants.LONG_PRESS:
Amith Yamasanic33cb712010-02-10 15:21:49 -08004665 pattern = mLongPressVibePattern;
4666 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07004667 case HapticFeedbackConstants.VIRTUAL_KEY:
Amith Yamasanic33cb712010-02-10 15:21:49 -08004668 pattern = mVirtualKeyVibePattern;
4669 break;
4670 case HapticFeedbackConstants.KEYBOARD_TAP:
4671 pattern = mKeyboardTapVibePattern;
4672 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07004673 case HapticFeedbackConstants.SAFE_MODE_DISABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08004674 pattern = mSafeModeDisabledVibePattern;
4675 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07004676 case HapticFeedbackConstants.SAFE_MODE_ENABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08004677 pattern = mSafeModeEnabledVibePattern;
4678 break;
Amith Yamasanic33cb712010-02-10 15:21:49 -08004679 default:
4680 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004681 }
Dianne Hackbornf265ea92013-01-31 15:00:51 -08004682 int owningUid;
4683 String owningPackage;
4684 if (win != null) {
4685 owningUid = win.getOwningUid();
4686 owningPackage = win.getOwningPackage();
4687 } else {
4688 owningUid = android.os.Process.myUid();
4689 owningPackage = mContext.getBasePackageName();
4690 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08004691 if (pattern.length == 1) {
4692 // One-shot vibration
Dianne Hackbornf265ea92013-01-31 15:00:51 -08004693 mVibrator.vibrate(owningUid, owningPackage, pattern[0]);
Amith Yamasanic33cb712010-02-10 15:21:49 -08004694 } else {
4695 // Pattern vibration
Dianne Hackbornf265ea92013-01-31 15:00:51 -08004696 mVibrator.vibrate(owningUid, owningPackage, pattern, -1);
Amith Yamasanic33cb712010-02-10 15:21:49 -08004697 }
4698 return true;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004699 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07004700
4701 @Override
4702 public void keepScreenOnStartedLw() {
Daniel Sandler0601eb72011-04-13 01:01:32 -04004703 }
4704
Jeff Brownc38c9be2012-10-04 13:16:19 -07004705 @Override
4706 public void keepScreenOnStoppedLw() {
4707 if (mKeyguardMediator != null && !mKeyguardMediator.isShowingAndNotHidden()) {
4708 long curTime = SystemClock.uptimeMillis();
4709 mPowerManager.userActivity(curTime, false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004710 }
4711 }
Mike Lockwoodfcb39242009-10-21 23:01:07 -04004712
Dianne Hackborndf89e652011-10-06 22:35:11 -07004713 private int updateSystemUiVisibilityLw() {
Joe Onorato664644d2011-01-23 17:53:23 -08004714 // If there is no window focused, there will be nobody to handle the events
4715 // anyway, so just hang on in whatever state we're in until things settle down.
Dianne Hackborndf89e652011-10-06 22:35:11 -07004716 if (mFocusedWindow == null) {
4717 return 0;
4718 }
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004719 if (mFocusedWindow.getAttrs().type == TYPE_KEYGUARD && mHideLockScreen == true) {
4720 // We are updating at a point where the keyguard has gotten
4721 // focus, but we were last in a state where the top window is
4722 // hiding it. This is probably because the keyguard as been
4723 // shown while the top window was displayed, so we want to ignore
4724 // it here because this is just a very transient change and it
4725 // will quickly lose focus once it correctly gets hidden.
4726 return 0;
4727 }
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08004728 int tmpVisibility = mFocusedWindow.getSystemUiVisibility()
Dianne Hackborne26ab702011-10-16 13:21:33 -07004729 & ~mResettingSystemUiFlags
4730 & ~mForceClearedSystemUiFlags;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08004731 if (mForcingShowNavBar && mFocusedWindow.getSurfaceLayer() < mForcingShowNavBarLayer) {
4732 tmpVisibility &= ~View.SYSTEM_UI_CLEARABLE_FLAGS;
4733 }
4734 final int visibility = tmpVisibility;
Dianne Hackborne26ab702011-10-16 13:21:33 -07004735 int diff = visibility ^ mLastSystemUiFlags;
Dianne Hackborn73ab6a42011-12-13 11:16:23 -08004736 final boolean needsMenu = mFocusedWindow.getNeedsMenuLw(mTopFullscreenOpaqueWindowState);
Dianne Hackborne0f085d2011-11-30 18:41:15 -08004737 if (diff == 0 && mLastFocusNeedsMenu == needsMenu
4738 && mFocusedApp == mFocusedWindow.getAppToken()) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004739 return 0;
4740 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07004741 mLastSystemUiFlags = visibility;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08004742 mLastFocusNeedsMenu = needsMenu;
Dianne Hackborne0f085d2011-11-30 18:41:15 -08004743 mFocusedApp = mFocusedWindow.getAppToken();
Dianne Hackborndf89e652011-10-06 22:35:11 -07004744 mHandler.post(new Runnable() {
4745 public void run() {
Dianne Hackborn42e620c2012-06-24 13:20:51 -07004746 try {
4747 IStatusBarService statusbar = getStatusBarService();
4748 if (statusbar != null) {
4749 statusbar.setSystemUiVisibility(visibility, 0xffffffff);
4750 statusbar.topAppWindowChanged(needsMenu);
Joe Onorato664644d2011-01-23 17:53:23 -08004751 }
Dianne Hackborn42e620c2012-06-24 13:20:51 -07004752 } catch (RemoteException e) {
4753 // re-acquire status bar service next time it is needed.
4754 mStatusBarService = null;
Joe Onorato664644d2011-01-23 17:53:23 -08004755 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07004756 }
4757 });
4758 return diff;
Joe Onorato664644d2011-01-23 17:53:23 -08004759 }
4760
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04004761 // Use this instead of checking config_showNavigationBar so that it can be consistently
4762 // overridden by qemu.hw.mainkeys in the emulator.
4763 public boolean hasNavigationBar() {
4764 return mHasNavigationBar;
4765 }
4766
satok1bc0a492012-04-25 22:47:12 +09004767 @Override
4768 public void setLastInputMethodWindowLw(WindowState ime, WindowState target) {
4769 mLastInputMethodWindow = ime;
4770 mLastInputMethodTargetWindow = target;
4771 }
4772
Craig Mautnerf1b67412012-09-19 13:18:29 -07004773 @Override
Craig Mautnerf1b67412012-09-19 13:18:29 -07004774 public void setCurrentUserLw(int newUserId) {
4775 if (mKeyguardMediator != null) {
4776 mKeyguardMediator.setCurrentUser(newUserId);
4777 }
John Spurlock13451a22012-09-28 14:40:41 -04004778 if (mStatusBarService != null) {
4779 try {
4780 mStatusBarService.setCurrentUser(newUserId);
4781 } catch (RemoteException e) {
4782 // oh well
4783 }
4784 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07004785 setLastInputMethodWindowLw(null, null);
Craig Mautnerf1b67412012-09-19 13:18:29 -07004786 }
4787
4788 @Override
Jim Miller4eeb4f62012-11-08 00:04:29 -08004789 public void showAssistant() {
4790 mKeyguardMediator.showAssistant();
4791 }
4792
Svetoslav Ganov545252f2012-12-10 18:29:24 -08004793 @Override
4794 public boolean canMagnifyWindow(int windowType) {
4795 switch (windowType) {
4796 case WindowManager.LayoutParams.TYPE_INPUT_METHOD:
4797 case WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG:
4798 case WindowManager.LayoutParams.TYPE_NAVIGATION_BAR:
4799 case WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY: {
4800 return false;
4801 }
4802 }
4803 return true;
4804 }
4805
4806 @Override
4807 public boolean isTopLevelWindow(int windowType) {
4808 if (windowType >= WindowManager.LayoutParams.FIRST_SUB_WINDOW
4809 && windowType <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
4810 return (windowType == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG);
4811 }
4812 return true;
4813 }
4814
Jim Miller4eeb4f62012-11-08 00:04:29 -08004815 @Override
Jeff Brownd7a04de2012-06-17 14:17:52 -07004816 public void dump(String prefix, PrintWriter pw, String[] args) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004817 pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07004818 pw.print(" mSystemReady="); pw.print(mSystemReady);
4819 pw.print(" mSystemBooted="); pw.println(mSystemBooted);
Jeff Brown2e7760e2012-04-11 15:14:55 -07004820 pw.print(prefix); pw.print("mLidState="); pw.print(mLidState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004821 pw.print(" mLidOpenRotation="); pw.print(mLidOpenRotation);
4822 pw.print(" mHdmiPlugged="); pw.println(mHdmiPlugged);
Dianne Hackborne26ab702011-10-16 13:21:33 -07004823 if (mLastSystemUiFlags != 0 || mResettingSystemUiFlags != 0
4824 || mForceClearedSystemUiFlags != 0) {
4825 pw.print(prefix); pw.print("mLastSystemUiFlags=0x");
4826 pw.print(Integer.toHexString(mLastSystemUiFlags));
4827 pw.print(" mResettingSystemUiFlags=0x");
4828 pw.print(Integer.toHexString(mResettingSystemUiFlags));
4829 pw.print(" mForceClearedSystemUiFlags=0x");
4830 pw.println(Integer.toHexString(mForceClearedSystemUiFlags));
Dianne Hackborndf89e652011-10-06 22:35:11 -07004831 }
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08004832 if (mLastFocusNeedsMenu) {
4833 pw.print(prefix); pw.print("mLastFocusNeedsMenu=");
4834 pw.println(mLastFocusNeedsMenu);
4835 }
Daniel Sandler7c135202012-09-28 14:04:59 -04004836 pw.print(prefix); pw.print("mDockMode="); pw.print(mDockMode);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004837 pw.print(" mCarDockRotation="); pw.print(mCarDockRotation);
4838 pw.print(" mDeskDockRotation="); pw.println(mDeskDockRotation);
4839 pw.print(prefix); pw.print("mUserRotationMode="); pw.print(mUserRotationMode);
4840 pw.print(" mUserRotation="); pw.print(mUserRotation);
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05004841 pw.print(" mAllowAllRotations="); pw.println(mAllowAllRotations);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07004842 pw.print(prefix); pw.print("mCurrentAppOrientation="); pw.println(mCurrentAppOrientation);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004843 pw.print(prefix); pw.print("mCarDockEnablesAccelerometer=");
4844 pw.print(mCarDockEnablesAccelerometer);
4845 pw.print(" mDeskDockEnablesAccelerometer=");
4846 pw.println(mDeskDockEnablesAccelerometer);
4847 pw.print(prefix); pw.print("mLidKeyboardAccessibility=");
4848 pw.print(mLidKeyboardAccessibility);
4849 pw.print(" mLidNavigationAccessibility="); pw.print(mLidNavigationAccessibility);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07004850 pw.print(" mLidControlsSleep="); pw.println(mLidControlsSleep);
4851 pw.print(prefix); pw.print("mLongPressOnPowerBehavior=");
4852 pw.print(mLongPressOnPowerBehavior);
4853 pw.print(" mHasSoftInput="); pw.println(mHasSoftInput);
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004854 pw.print(prefix); pw.print("mScreenOnEarly="); pw.print(mScreenOnEarly);
4855 pw.print(" mScreenOnFully="); pw.print(mScreenOnFully);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07004856 pw.print(" mOrientationSensorEnabled="); pw.println(mOrientationSensorEnabled);
Dianne Hackbornc652de82013-02-15 16:32:56 -08004857 pw.print(prefix); pw.print("mOverscanScreen=("); pw.print(mOverscanScreenLeft);
4858 pw.print(","); pw.print(mOverscanScreenTop);
4859 pw.print(") "); pw.print(mOverscanScreenWidth);
4860 pw.print("x"); pw.println(mOverscanScreenHeight);
4861 if (mOverscanLeft != 0 || mOverscanTop != 0
4862 || mOverscanRight != 0 || mOverscanBottom != 0) {
4863 pw.print(prefix); pw.print("mOverscan left="); pw.print(mOverscanLeft);
4864 pw.print(" top="); pw.print(mOverscanTop);
4865 pw.print(" right="); pw.print(mOverscanRight);
4866 pw.print(" bottom="); pw.println(mOverscanBottom);
4867 }
Dianne Hackborn313440842013-02-19 19:22:59 -08004868 pw.print(prefix); pw.print("mRestrictedOverscanScreen=(");
4869 pw.print(mRestrictedOverscanScreenLeft);
4870 pw.print(","); pw.print(mRestrictedOverscanScreenTop);
4871 pw.print(") "); pw.print(mRestrictedOverscanScreenWidth);
4872 pw.print("x"); pw.println(mRestrictedOverscanScreenHeight);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004873 pw.print(prefix); pw.print("mUnrestrictedScreen=("); pw.print(mUnrestrictedScreenLeft);
4874 pw.print(","); pw.print(mUnrestrictedScreenTop);
4875 pw.print(") "); pw.print(mUnrestrictedScreenWidth);
4876 pw.print("x"); pw.println(mUnrestrictedScreenHeight);
4877 pw.print(prefix); pw.print("mRestrictedScreen=("); pw.print(mRestrictedScreenLeft);
4878 pw.print(","); pw.print(mRestrictedScreenTop);
4879 pw.print(") "); pw.print(mRestrictedScreenWidth);
4880 pw.print("x"); pw.println(mRestrictedScreenHeight);
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07004881 pw.print(prefix); pw.print("mStableFullscreen=("); pw.print(mStableFullscreenLeft);
4882 pw.print(","); pw.print(mStableFullscreenTop);
4883 pw.print(")-("); pw.print(mStableFullscreenRight);
4884 pw.print(","); pw.print(mStableFullscreenBottom); pw.println(")");
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004885 pw.print(prefix); pw.print("mStable=("); pw.print(mStableLeft);
4886 pw.print(","); pw.print(mStableTop);
4887 pw.print(")-("); pw.print(mStableRight);
4888 pw.print(","); pw.print(mStableBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07004889 pw.print(prefix); pw.print("mSystem=("); pw.print(mSystemLeft);
4890 pw.print(","); pw.print(mSystemTop);
4891 pw.print(")-("); pw.print(mSystemRight);
4892 pw.print(","); pw.print(mSystemBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004893 pw.print(prefix); pw.print("mCur=("); pw.print(mCurLeft);
4894 pw.print(","); pw.print(mCurTop);
4895 pw.print(")-("); pw.print(mCurRight);
4896 pw.print(","); pw.print(mCurBottom); pw.println(")");
4897 pw.print(prefix); pw.print("mContent=("); pw.print(mContentLeft);
4898 pw.print(","); pw.print(mContentTop);
4899 pw.print(")-("); pw.print(mContentRight);
4900 pw.print(","); pw.print(mContentBottom); pw.println(")");
4901 pw.print(prefix); pw.print("mDock=("); pw.print(mDockLeft);
4902 pw.print(","); pw.print(mDockTop);
4903 pw.print(")-("); pw.print(mDockRight);
4904 pw.print(","); pw.print(mDockBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07004905 pw.print(prefix); pw.print("mDockLayer="); pw.print(mDockLayer);
4906 pw.print(" mStatusBarLayer="); pw.println(mStatusBarLayer);
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004907 pw.print(prefix); pw.print("mShowingLockscreen="); pw.print(mShowingLockscreen);
4908 pw.print(" mShowingDream="); pw.print(mShowingDream);
4909 pw.print(" mDreamingLockscreen="); pw.println(mDreamingLockscreen);
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07004910 if (mLastInputMethodWindow != null) {
4911 pw.print(prefix); pw.print("mLastInputMethodWindow=");
4912 pw.println(mLastInputMethodWindow);
4913 }
4914 if (mLastInputMethodTargetWindow != null) {
4915 pw.print(prefix); pw.print("mLastInputMethodTargetWindow=");
4916 pw.println(mLastInputMethodTargetWindow);
4917 }
4918 if (mStatusBar != null) {
4919 pw.print(prefix); pw.print("mStatusBar=");
4920 pw.println(mStatusBar);
4921 }
4922 if (mNavigationBar != null) {
4923 pw.print(prefix); pw.print("mNavigationBar=");
4924 pw.println(mNavigationBar);
4925 }
4926 if (mKeyguard != null) {
4927 pw.print(prefix); pw.print("mKeyguard=");
4928 pw.println(mKeyguard);
4929 }
4930 if (mFocusedWindow != null) {
4931 pw.print(prefix); pw.print("mFocusedWindow=");
4932 pw.println(mFocusedWindow);
4933 }
4934 if (mFocusedApp != null) {
4935 pw.print(prefix); pw.print("mFocusedApp=");
4936 pw.println(mFocusedApp);
4937 }
4938 if (mWinDismissingKeyguard != null) {
4939 pw.print(prefix); pw.print("mWinDismissingKeyguard=");
4940 pw.println(mWinDismissingKeyguard);
4941 }
4942 if (mTopFullscreenOpaqueWindowState != null) {
4943 pw.print(prefix); pw.print("mTopFullscreenOpaqueWindowState=");
4944 pw.println(mTopFullscreenOpaqueWindowState);
4945 }
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08004946 if (mForcingShowNavBar) {
4947 pw.print(prefix); pw.print("mForcingShowNavBar=");
4948 pw.println(mForcingShowNavBar); pw.print( "mForcingShowNavBarLayer=");
4949 pw.println(mForcingShowNavBarLayer);
4950 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004951 pw.print(prefix); pw.print("mTopIsFullscreen="); pw.print(mTopIsFullscreen);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004952 pw.print(" mHideLockScreen="); pw.println(mHideLockScreen);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004953 pw.print(prefix); pw.print("mForceStatusBar="); pw.print(mForceStatusBar);
4954 pw.print(" mForceStatusBarFromKeyguard=");
4955 pw.println(mForceStatusBarFromKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004956 pw.print(prefix); pw.print("mDismissKeyguard="); pw.print(mDismissKeyguard);
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004957 pw.print(" mWinDismissingKeyguard="); pw.print(mWinDismissingKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004958 pw.print(" mHomePressed="); pw.println(mHomePressed);
4959 pw.print(prefix); pw.print("mAllowLockscreenWhenOn="); pw.print(mAllowLockscreenWhenOn);
4960 pw.print(" mLockScreenTimeout="); pw.print(mLockScreenTimeout);
4961 pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive);
4962 pw.print(prefix); pw.print("mEndcallBehavior="); pw.print(mEndcallBehavior);
4963 pw.print(" mIncallPowerBehavior="); pw.print(mIncallPowerBehavior);
4964 pw.print(" mLongPressOnHomeBehavior="); pw.println(mLongPressOnHomeBehavior);
4965 pw.print(prefix); pw.print("mLandscapeRotation="); pw.print(mLandscapeRotation);
4966 pw.print(" mSeascapeRotation="); pw.println(mSeascapeRotation);
4967 pw.print(prefix); pw.print("mPortraitRotation="); pw.print(mPortraitRotation);
4968 pw.print(" mUpsideDownRotation="); pw.println(mUpsideDownRotation);
Jeff Brown27f1d672012-10-17 18:32:34 -07004969 pw.print(prefix); pw.print("mHdmiRotation="); pw.print(mHdmiRotation);
4970 pw.print(" mHdmiRotationLock="); pw.println(mHdmiRotationLock);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004971 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004972}