blob: b0cd11ae9cee0b0768fa07348efbfff85b3a83d0 [file] [log] [blame]
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001/*
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16package com.android.internal.policy.impl;
17
Dianne Hackborna4972e92012-03-14 10:38:05 -070018import android.app.ActivityManager;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080019import android.app.ActivityManagerNative;
Dianne Hackbornc2293022013-02-06 23:14:49 -080020import android.app.AppOpsManager;
Daniel Sandler6396c722013-04-16 20:19:09 -040021import android.app.IUiModeManager;
Dianne Hackborn661cd522011-08-22 00:26:20 -070022import android.app.ProgressDialog;
Jeff Brownde7a8ea2012-06-13 18:28:57 -070023import android.app.SearchManager;
Dianne Hackborn78968392010-03-04 20:47:56 -080024import android.app.UiModeManager;
Dianne Hackborn39c2d712009-09-22 11:41:31 -070025import android.content.ActivityNotFoundException;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080026import android.content.BroadcastReceiver;
Daniel Sandler0601eb72011-04-13 01:01:32 -040027import android.content.ComponentName;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080028import android.content.ContentResolver;
29import android.content.Context;
30import android.content.Intent;
Mike Lockwood1753f7f2009-08-24 14:49:07 -070031import android.content.IntentFilter;
Winson Chung9112ec32011-06-27 13:15:32 -070032import android.content.ServiceConnection;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080033import android.content.pm.ActivityInfo;
34import android.content.pm.PackageManager;
Daniel Sandler6396c722013-04-16 20:19:09 -040035import android.content.pm.ResolveInfo;
Dianne Hackborn2f0b1752011-05-31 17:59:49 -070036import android.content.res.CompatibilityInfo;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080037import android.content.res.Configuration;
38import android.content.res.Resources;
Craig Mautner8e4df6c2012-05-23 16:57:23 -070039import android.content.res.TypedArray;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080040import android.database.ContentObserver;
Dianne Hackbornc777e072010-02-12 13:07:59 -080041import android.graphics.PixelFormat;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080042import android.graphics.Rect;
Michael Jurka7a348952012-02-27 13:07:58 -080043import android.media.AudioManager;
44import android.media.IAudioService;
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -070045import android.media.Ringtone;
46import android.media.RingtoneManager;
Dianne Hackborn38e29a62011-09-18 14:43:08 -070047import android.os.Bundle;
Jeff Brown9a538ee2012-08-20 14:56:57 -070048import android.os.FactoryTest;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080049import android.os.Handler;
50import android.os.IBinder;
Dianne Hackborn38e29a62011-09-18 14:43:08 -070051import android.os.IRemoteCallback;
Jeff Brown32cbc38552011-12-01 14:01:49 -080052import android.os.Looper;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -070053import android.os.Message;
54import android.os.Messenger;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080055import android.os.PowerManager;
56import android.os.RemoteException;
57import android.os.ServiceManager;
58import android.os.SystemClock;
59import android.os.SystemProperties;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -080060import android.os.UEventObserver;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -070061import android.os.UserHandle;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080062import android.os.Vibrator;
63import android.provider.Settings;
John Spurlockc8b46ca2013-04-08 12:59:26 -040064import android.service.dreams.DreamService;
65import android.service.dreams.IDreamManager;
Dianne Hackborn81e56d52011-05-26 00:55:58 -070066import android.util.DisplayMetrics;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080067import android.util.EventLog;
68import android.util.Log;
Jeff Browna41ca772010-08-11 14:46:32 -070069import android.util.Slog;
Jeff Brown6651a632011-11-28 12:59:11 -080070import android.util.SparseArray;
Dianne Hackbornf87d1962012-04-04 12:48:24 -070071import android.view.Display;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080072import android.view.Gravity;
73import android.view.HapticFeedbackConstants;
Dianne Hackborne0f085d2011-11-30 18:41:15 -080074import android.view.IApplicationToken;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080075import android.view.IWindowManager;
Jeff Browna41ca772010-08-11 14:46:32 -070076import android.view.InputChannel;
Jeff Brown4d396052010-10-29 21:50:21 -070077import android.view.InputDevice;
Jeff Brown4952dfd2011-11-30 19:23:22 -080078import android.view.InputEvent;
Jeff Brown32cbc38552011-12-01 14:01:49 -080079import android.view.InputEventReceiver;
Jeff Brown6b53e8d2010-11-10 16:03:06 -080080import android.view.KeyCharacterMap;
Craig Mautnerae446592012-12-06 19:05:05 -080081import android.view.KeyCharacterMap.FallbackAction;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080082import android.view.KeyEvent;
83import android.view.MotionEvent;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080084import android.view.Surface;
85import android.view.View;
86import android.view.ViewConfiguration;
87import android.view.Window;
88import android.view.WindowManager;
Craig Mautnerae446592012-12-06 19:05:05 -080089import android.view.WindowManagerGlobal;
90import android.view.WindowManagerPolicy;
Craig Mautnerae446592012-12-06 19:05:05 -080091import android.view.accessibility.AccessibilityEvent;
92import android.view.animation.Animation;
93import android.view.animation.AnimationUtils;
94
95import com.android.internal.R;
96import com.android.internal.policy.PolicyManager;
97import com.android.internal.policy.impl.keyguard.KeyguardViewManager;
98import com.android.internal.policy.impl.keyguard.KeyguardViewMediator;
99import com.android.internal.statusbar.IStatusBarService;
100import com.android.internal.telephony.ITelephony;
101import com.android.internal.widget.PointerLocationView;
102
103import java.io.File;
104import java.io.FileReader;
105import java.io.IOException;
106import java.io.PrintWriter;
107
Dianne Hackbornc652de82013-02-15 16:32:56 -0800108import static android.view.WindowManager.LayoutParams.*;
Jeff Brownac143512012-04-05 18:57:33 -0700109import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_ABSENT;
110import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_OPEN;
111import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_CLOSED;
Dianne Hackborn08743722009-12-21 12:16:51 -0800112
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800113/**
The Android Open Source Project0727d222009-03-11 12:11:58 -0700114 * WindowManagerPolicy implementation for the Android phone UI. This
115 * introduces a new method suffix, Lp, for an internal lock of the
116 * PhoneWindowManager. This is used to protect some internal state, and
117 * can be acquired with either thw Lw and Li lock held, so has the restrictions
118 * of both of those when held.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800119 */
120public class PhoneWindowManager implements WindowManagerPolicy {
121 static final String TAG = "WindowManager";
122 static final boolean DEBUG = false;
Joe Onorato43a17652011-04-06 19:22:23 -0700123 static final boolean localLOGV = false;
The Android Open Source Project11267662009-03-18 17:39:47 -0700124 static final boolean DEBUG_LAYOUT = false;
Jeff Brown40013652012-05-16 21:22:36 -0700125 static final boolean DEBUG_INPUT = false;
Craig Mautner6fbda632012-07-03 09:26:39 -0700126 static final boolean DEBUG_STARTING_WINDOW = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800127 static final boolean SHOW_STARTING_ANIMATIONS = true;
128 static final boolean SHOW_PROCESSES_ON_ALT_MENU = false;
Joe Onoratod208e702010-10-08 16:22:43 -0400129
Daniel Sandler6396c722013-04-16 20:19:09 -0400130 // Whether to allow dock apps with METADATA_DOCK_HOME to temporarily take over the Home key.
131 // No longer recommended for desk docks; still useful in car docks.
132 static final boolean ENABLE_CAR_DOCK_HOME_CAPTURE = true;
133 static final boolean ENABLE_DESK_DOCK_HOME_CAPTURE = false;
134
Joe Onoratod208e702010-10-08 16:22:43 -0400135 static final int LONG_PRESS_POWER_NOTHING = 0;
136 static final int LONG_PRESS_POWER_GLOBAL_ACTIONS = 1;
137 static final int LONG_PRESS_POWER_SHUT_OFF = 2;
Jeff Brown9a538ee2012-08-20 14:56:57 -0700138 static final int LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM = 3;
Michael Jurka3b1fc472011-06-13 10:54:40 -0700139
140 // These need to match the documentation/constant in
141 // core/res/res/values/config.xml
Joe Onorato46b0d682010-11-22 17:37:27 -0800142 static final int LONG_PRESS_HOME_NOTHING = 0;
Michael Wrightc9ebea72013-01-16 19:25:02 -0800143 static final int LONG_PRESS_HOME_RECENT_SYSTEM_UI = 1;
Jeff Browncaca8812013-05-09 13:34:33 -0700144 static final int LONG_PRESS_HOME_ASSIST = 2;
145
146 static final int DOUBLE_TAP_HOME_NOTHING = 0;
147 static final int DOUBLE_TAP_HOME_RECENT_SYSTEM_UI = 1;
Joe Onorato46b0d682010-11-22 17:37:27 -0800148
Dianne Hackborn5cb8d792009-05-21 17:34:15 -0700149 static final int APPLICATION_MEDIA_SUBLAYER = -2;
150 static final int APPLICATION_MEDIA_OVERLAY_SUBLAYER = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800151 static final int APPLICATION_PANEL_SUBLAYER = 1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800152 static final int APPLICATION_SUB_PANEL_SUBLAYER = 2;
Craig Mautner88400d32012-09-30 12:35:45 -0700153
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800154 static public final String SYSTEM_DIALOG_REASON_KEY = "reason";
155 static public final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions";
156 static public final String SYSTEM_DIALOG_REASON_RECENT_APPS = "recentapps";
Joe Onoratof275f0c2009-11-24 16:11:13 -0500157 static public final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey";
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700158 static public final String SYSTEM_DIALOG_REASON_ASSIST = "assist";
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800159
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700160 /**
161 * These are the system UI flags that, when changing, can cause the layout
162 * of the screen to change.
163 */
164 static final int SYSTEM_UI_CHANGING_LAYOUT =
165 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN;
166
Jeff Brown6651a632011-11-28 12:59:11 -0800167 /* Table of Application Launch keys. Maps from key codes to intent categories.
168 *
169 * These are special keys that are used to launch particular kinds of applications,
170 * such as a web browser. HID defines nearly a hundred of them in the Consumer (0x0C)
171 * usage page. We don't support quite that many yet...
172 */
173 static SparseArray<String> sApplicationLaunchKeyCategories;
174 static {
175 sApplicationLaunchKeyCategories = new SparseArray<String>();
176 sApplicationLaunchKeyCategories.append(
177 KeyEvent.KEYCODE_EXPLORER, Intent.CATEGORY_APP_BROWSER);
178 sApplicationLaunchKeyCategories.append(
179 KeyEvent.KEYCODE_ENVELOPE, Intent.CATEGORY_APP_EMAIL);
180 sApplicationLaunchKeyCategories.append(
181 KeyEvent.KEYCODE_CONTACTS, Intent.CATEGORY_APP_CONTACTS);
182 sApplicationLaunchKeyCategories.append(
183 KeyEvent.KEYCODE_CALENDAR, Intent.CATEGORY_APP_CALENDAR);
184 sApplicationLaunchKeyCategories.append(
185 KeyEvent.KEYCODE_MUSIC, Intent.CATEGORY_APP_MUSIC);
186 sApplicationLaunchKeyCategories.append(
187 KeyEvent.KEYCODE_CALCULATOR, Intent.CATEGORY_APP_CALCULATOR);
188 }
189
Dianne Hackborndf89e652011-10-06 22:35:11 -0700190 /**
191 * Lock protecting internal state. Must not call out into window
192 * manager with lock held. (This lock will be acquired in places
193 * where the window manager is calling in with its own lock held.)
194 */
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800195 private final Object mLock = new Object();
Dianne Hackborndf89e652011-10-06 22:35:11 -0700196
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800197 Context mContext;
198 IWindowManager mWindowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700199 WindowManagerFuncs mWindowManagerFuncs;
Jeff Brown96307042012-07-27 15:51:34 -0700200 PowerManager mPowerManager;
Joe Onorato93056472010-09-10 10:30:46 -0400201 IStatusBarService mStatusBarService;
Jeff Browncaca8812013-05-09 13:34:33 -0700202 boolean mPreloadedRecentApps;
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700203 final Object mServiceAquireLock = new Object();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800204 Vibrator mVibrator; // Vibrator for giving feedback of orientation changes
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700205 SearchManager mSearchManager;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800206
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700207 // Vibrator pattern for haptic feedback of a long press.
208 long[] mLongPressVibePattern;
Craig Mautner88400d32012-09-30 12:35:45 -0700209
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700210 // Vibrator pattern for haptic feedback of virtual key press.
211 long[] mVirtualKeyVibePattern;
212
Amith Yamasanic33cb712010-02-10 15:21:49 -0800213 // Vibrator pattern for a short vibration.
214 long[] mKeyboardTapVibePattern;
215
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700216 // Vibrator pattern for haptic feedback during boot when safe mode is disabled.
217 long[] mSafeModeDisabledVibePattern;
218
219 // Vibrator pattern for haptic feedback during boot when safe mode is enabled.
220 long[] mSafeModeEnabledVibePattern;
Romain Guy8154cd32010-03-29 14:41:15 -0700221
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800222 /** If true, hitting shift & menu will broadcast Intent.ACTION_BUG_REPORT */
223 boolean mEnableShiftMenuBugReports = false;
Mike Lockwoodd747dc82011-09-13 16:28:22 -0400224
225 boolean mHeadless;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800226 boolean mSafeMode;
227 WindowState mStatusBar = null;
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700228 boolean mHasSystemNavBar;
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700229 int mStatusBarHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400230 WindowState mNavigationBar = null;
Daniel Sandler36412a72011-08-04 09:35:13 -0400231 boolean mHasNavigationBar = false;
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700232 boolean mCanHideNavigationBar = false;
Daniel Sandler4a066c52012-04-20 14:49:13 -0400233 boolean mNavigationBarCanMove = false; // can the navigation bar ever move to the side?
234 boolean mNavigationBarOnBottom = true; // is the navigation bar on the bottom *right now*?
235 int[] mNavigationBarHeightForRotation = new int[4];
236 int[] mNavigationBarWidthForRotation = new int[4];
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400237
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800238 WindowState mKeyguard = null;
239 KeyguardViewMediator mKeyguardMediator;
240 GlobalActions mGlobalActions;
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700241 volatile boolean mPowerKeyHandled; // accessed from input reader and handler thread
242 boolean mPendingPowerKeyUpCanceled;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800243 Handler mHandler;
satok1bc0a492012-04-25 22:47:12 +0900244 WindowState mLastInputMethodWindow = null;
245 WindowState mLastInputMethodTargetWindow = null;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800246
Jeff Brown68b909d2011-12-07 16:36:01 -0800247 static final int RECENT_APPS_BEHAVIOR_SHOW_OR_DISMISS = 0;
248 static final int RECENT_APPS_BEHAVIOR_EXIT_TOUCH_MODE_AND_SHOW = 1;
Jeff Brown602ab322012-05-16 13:33:47 -0700249 static final int RECENT_APPS_BEHAVIOR_DISMISS = 2;
250 static final int RECENT_APPS_BEHAVIOR_DISMISS_AND_SWITCH = 3;
Jeff Brown68b909d2011-12-07 16:36:01 -0800251
252 RecentApplicationsDialog mRecentAppsDialog;
253 int mRecentAppsDialogHeldModifiers;
Jeff Browncf39bdf2012-05-18 14:41:19 -0700254 boolean mLanguageSwitchKeyPressed;
Jeff Brown68b909d2011-12-07 16:36:01 -0800255
Jeff Brown2e7760e2012-04-11 15:14:55 -0700256 int mLidState = LID_ABSENT;
Jeff Browndaa37532012-05-01 15:54:03 -0700257 boolean mHaveBuiltInKeyboard;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800258
Dianne Hackbornc777e072010-02-12 13:07:59 -0800259 boolean mSystemReady;
Dianne Hackbornba24e4d2011-09-01 11:17:06 -0700260 boolean mSystemBooted;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800261 boolean mHdmiPlugged;
Daniel Sandler6396c722013-04-16 20:19:09 -0400262 int mUiMode;
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700263 int mDockMode = Intent.EXTRA_DOCK_STATE_UNDOCKED;
Mike Lockwood1753f7f2009-08-24 14:49:07 -0700264 int mLidOpenRotation;
Mike Lockwood2d1efbd2009-09-16 12:15:53 -0400265 int mCarDockRotation;
266 int mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -0700267 int mUndockedHdmiRotation;
268 int mDemoHdmiRotation;
269 boolean mDemoHdmiRotationLock;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400270
271 int mUserRotationMode = WindowManagerPolicy.USER_ROTATION_FREE;
272 int mUserRotation = Surface.ROTATION_0;
Jeff Brown207673cd2012-06-05 17:47:11 -0700273 boolean mAccelerometerDefault;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400274
Jeff Brownd3187e32011-09-21 19:26:44 -0700275 int mAllowAllRotations = -1;
Mike Lockwoode9867d22009-09-20 01:59:02 -0400276 boolean mCarDockEnablesAccelerometer;
277 boolean mDeskDockEnablesAccelerometer;
Dianne Hackborn2862fff2009-09-15 22:56:29 -0700278 int mLidKeyboardAccessibility;
279 int mLidNavigationAccessibility;
Jeff Brownc458ce92012-04-30 14:58:40 -0700280 boolean mLidControlsSleep;
Joe Onoratod208e702010-10-08 16:22:43 -0400281 int mLongPressOnPowerBehavior = -1;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -0700282 boolean mScreenOnEarly = false;
283 boolean mScreenOnFully = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800284 boolean mOrientationSensorEnabled = false;
285 int mCurrentAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800286 boolean mHasSoftInput = false;
287
Jeff Brown70825162012-03-28 17:27:48 -0700288 int mPointerLocationMode = 0; // guarded by mLock
Joe Onorato664644d2011-01-23 17:53:23 -0800289
290 // The last window we were told about in focusChanged.
291 WindowState mFocusedWindow;
Dianne Hackborne0f085d2011-11-30 18:41:15 -0800292 IApplicationToken mFocusedApp;
Joe Onorato664644d2011-01-23 17:53:23 -0800293
Jeff Brown70825162012-03-28 17:27:48 -0700294 private static final class PointerLocationInputEventReceiver extends InputEventReceiver {
295 private final PointerLocationView mView;
296
297 public PointerLocationInputEventReceiver(InputChannel inputChannel, Looper looper,
298 PointerLocationView view) {
Jeff Brown32cbc38552011-12-01 14:01:49 -0800299 super(inputChannel, looper);
Jeff Brown70825162012-03-28 17:27:48 -0700300 mView = view;
Jeff Brown32cbc38552011-12-01 14:01:49 -0800301 }
302
Jeff Browna41ca772010-08-11 14:46:32 -0700303 @Override
Jeff Brown32cbc38552011-12-01 14:01:49 -0800304 public void onInputEvent(InputEvent event) {
Jeff Brown3915bb82010-11-05 15:02:16 -0700305 boolean handled = false;
306 try {
Jeff Brown4952dfd2011-11-30 19:23:22 -0800307 if (event instanceof MotionEvent
308 && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
309 final MotionEvent motionEvent = (MotionEvent)event;
Jeff Brown70825162012-03-28 17:27:48 -0700310 mView.addPointerEvent(motionEvent);
311 handled = true;
Jeff Brown93ed4e32010-09-23 13:51:48 -0700312 }
Jeff Brown3915bb82010-11-05 15:02:16 -0700313 } finally {
Jeff Brown32cbc38552011-12-01 14:01:49 -0800314 finishInputEvent(event, handled);
Jeff Browna41ca772010-08-11 14:46:32 -0700315 }
316 }
Jeff Brown32cbc38552011-12-01 14:01:49 -0800317 }
Jeff Brown70825162012-03-28 17:27:48 -0700318
319 // Pointer location view state, only modified on the mHandler Looper.
Jeff Brown32cbc38552011-12-01 14:01:49 -0800320 PointerLocationInputEventReceiver mPointerLocationInputEventReceiver;
Jeff Brown70825162012-03-28 17:27:48 -0700321 PointerLocationView mPointerLocationView;
322 InputChannel mPointerLocationInputChannel;
Jeff Brown32cbc38552011-12-01 14:01:49 -0800323
Dianne Hackbornc652de82013-02-15 16:32:56 -0800324 // The current size of the screen; really; extends into the overscan area of
325 // the screen and doesn't account for any system elements like the status bar.
326 int mOverscanScreenLeft, mOverscanScreenTop;
327 int mOverscanScreenWidth, mOverscanScreenHeight;
328 // The current visible size of the screen; really; (ir)regardless of whether the status
329 // bar can be hidden but not extending into the overscan area.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800330 int mUnrestrictedScreenLeft, mUnrestrictedScreenTop;
331 int mUnrestrictedScreenWidth, mUnrestrictedScreenHeight;
Dianne Hackborn313440842013-02-19 19:22:59 -0800332 // Like mOverscanScreen*, but allowed to move into the overscan region where appropriate.
333 int mRestrictedOverscanScreenLeft, mRestrictedOverscanScreenTop;
334 int mRestrictedOverscanScreenWidth, mRestrictedOverscanScreenHeight;
Dianne Hackborn82de1ae2010-10-28 11:28:39 -0700335 // The current size of the screen; these may be different than (0,0)-(dw,dh)
336 // if the status bar can't be hidden; in that case it effectively carves out
337 // that area of the display from all other windows.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800338 int mRestrictedScreenLeft, mRestrictedScreenTop;
339 int mRestrictedScreenWidth, mRestrictedScreenHeight;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700340 // During layout, the current screen borders accounting for any currently
341 // visible system UI elements.
342 int mSystemLeft, mSystemTop, mSystemRight, mSystemBottom;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700343 // For applications requesting stable content insets, these are them.
344 int mStableLeft, mStableTop, mStableRight, mStableBottom;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -0700345 // For applications requesting stable content insets but have also set the
346 // fullscreen window flag, these are the stable dimensions without the status bar.
347 int mStableFullscreenLeft, mStableFullscreenTop;
348 int mStableFullscreenRight, mStableFullscreenBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800349 // During layout, the current screen borders with all outer decoration
350 // (status bar, input method dock) accounted for.
351 int mCurLeft, mCurTop, mCurRight, mCurBottom;
352 // During layout, the frame in which content should be displayed
353 // to the user, accounting for all screen decoration except for any
354 // space they deem as available for other content. This is usually
355 // the same as mCur*, but may be larger if the screen decor has supplied
356 // content insets.
357 int mContentLeft, mContentTop, mContentRight, mContentBottom;
Dianne Hackborn8e11ef02010-11-18 19:47:42 -0800358 // During layout, the current screen borders along which input method
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800359 // windows are placed.
360 int mDockLeft, mDockTop, mDockRight, mDockBottom;
361 // During layout, the layer at which the doc window is placed.
362 int mDockLayer;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700363 // During layout, this is the layer of the status bar.
364 int mStatusBarLayer;
Dianne Hackborne26ab702011-10-16 13:21:33 -0700365 int mLastSystemUiFlags;
366 // Bits that we are in the process of clearing, so we want to prevent
367 // them from being set by applications until everything has been updated
368 // to have them clear.
369 int mResettingSystemUiFlags = 0;
370 // Bits that we are currently always keeping cleared.
371 int mForceClearedSystemUiFlags = 0;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -0800372 // What we last reported to system UI about whether the compatibility
373 // menu needs to be displayed.
374 boolean mLastFocusNeedsMenu = false;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700375
376 FakeWindow mHideNavFakeWindow = null;
377
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800378 static final Rect mTmpParentFrame = new Rect();
379 static final Rect mTmpDisplayFrame = new Rect();
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800380 static final Rect mTmpOverscanFrame = new Rect();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800381 static final Rect mTmpContentFrame = new Rect();
382 static final Rect mTmpVisibleFrame = new Rect();
Dianne Hackborn1f903c32011-09-13 19:18:06 -0700383 static final Rect mTmpNavigationFrame = new Rect();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800384
385 WindowState mTopFullscreenOpaqueWindowState;
Joe Onorato93056472010-09-10 10:30:46 -0400386 boolean mTopIsFullscreen;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800387 boolean mForceStatusBar;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -0700388 boolean mForceStatusBarFromKeyguard;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700389 boolean mHideLockScreen;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -0800390 boolean mForcingShowNavBar;
391 int mForcingShowNavBarLayer;
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700392
393 // States of keyguard dismiss.
394 private static final int DISMISS_KEYGUARD_NONE = 0; // Keyguard not being dismissed.
395 private static final int DISMISS_KEYGUARD_START = 1; // Keyguard needs to be dismissed.
396 private static final int DISMISS_KEYGUARD_CONTINUE = 2; // Keyguard has been dismissed.
397 int mDismissKeyguard = DISMISS_KEYGUARD_NONE;
398
399 /** The window that is currently dismissing the keyguard. Dismissing the keyguard must only
400 * be done once per window. */
401 private WindowState mWinDismissingKeyguard;
402
Dianne Hackborn7ad44382012-10-18 17:46:00 -0700403 boolean mShowingLockscreen;
404 boolean mShowingDream;
405 boolean mDreamingLockscreen;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800406 boolean mHomePressed;
Jeff Browncaca8812013-05-09 13:34:33 -0700407 boolean mHomeConsumed;
408 boolean mHomeDoubleTapPending;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800409 Intent mHomeIntent;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700410 Intent mCarDockIntent;
411 Intent mDeskDockIntent;
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700412 boolean mSearchKeyShortcutPending;
413 boolean mConsumeSearchKeyUp;
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700414 boolean mAssistKeyLongPressed;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800415
Mike Lockwood28569302010-01-28 11:54:40 -0500416 // support for activating the lock screen while the screen is on
417 boolean mAllowLockscreenWhenOn;
418 int mLockScreenTimeout;
419 boolean mLockScreenTimerActive;
420
David Brownbaf8d092010-03-08 21:52:59 -0800421 // Behavior of ENDCALL Button. (See Settings.System.END_BUTTON_BEHAVIOR.)
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800422 int mEndcallBehavior;
David Brownbaf8d092010-03-08 21:52:59 -0800423
424 // Behavior of POWER button while in-call and screen on.
425 // (See Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR.)
426 int mIncallPowerBehavior;
427
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700428 Display mDisplay;
429
Dianne Hackborn9d132642011-04-21 17:26:39 -0700430 int mLandscapeRotation = 0; // default landscape rotation
431 int mSeascapeRotation = 0; // "other" landscape rotation, 180 degrees from mLandscapeRotation
432 int mPortraitRotation = 0; // default portrait rotation
433 int mUpsideDownRotation = 0; // "other" portrait rotation
Mitsuru Oshima831d0d92009-06-16 18:27:18 -0700434
Dianne Hackbornc652de82013-02-15 16:32:56 -0800435 int mOverscanLeft = 0;
436 int mOverscanTop = 0;
437 int mOverscanRight = 0;
438 int mOverscanBottom = 0;
439
Joe Onorato46b0d682010-11-22 17:37:27 -0800440 // What we do when the user long presses on home
Jeff Browncaca8812013-05-09 13:34:33 -0700441 private int mLongPressOnHomeBehavior;
442
443 // What we do when the user double-taps on home
444 private int mDoubleTapOnHomeBehavior;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800445
Winson Chung9112ec32011-06-27 13:15:32 -0700446 // Screenshot trigger states
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700447 // Time to volume and power must be pressed within this interval of each other.
448 private static final long SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS = 150;
Winson Chung1cea2f32012-10-08 20:42:01 -0700449 // Increase the chord delay when taking a screenshot from the keyguard
450 private static final float KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER = 2.5f;
Christopher Tatee90585f2012-03-05 18:56:25 -0800451 private boolean mScreenshotChordEnabled;
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700452 private boolean mVolumeDownKeyTriggered;
453 private long mVolumeDownKeyTime;
454 private boolean mVolumeDownKeyConsumedByScreenshotChord;
455 private boolean mVolumeUpKeyTriggered;
456 private boolean mPowerKeyTriggered;
457 private long mPowerKeyTime;
Winson Chung9112ec32011-06-27 13:15:32 -0700458
Christopher Tate5e08af02012-09-21 17:17:22 -0700459 SettingsObserver mSettingsObserver;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800460 ShortcutManager mShortcutManager;
461 PowerManager.WakeLock mBroadcastWakeLock;
Jeff Brown40013652012-05-16 21:22:36 -0700462 boolean mHavePendingMediaKeyRepeatWithWakeLock;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800463
Justin Kohd378ad72013-04-01 12:18:26 -0700464 // Maps global key codes to the components that will handle them.
465 private GlobalKeyManager mGlobalKeyManager;
466
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700467 // Fallback actions by key code.
468 private final SparseArray<KeyCharacterMap.FallbackAction> mFallbackActions =
469 new SparseArray<KeyCharacterMap.FallbackAction>();
Jeff Brown49ed71d2010-12-06 17:13:33 -0800470
Jeff Brown70825162012-03-28 17:27:48 -0700471 private static final int MSG_ENABLE_POINTER_LOCATION = 1;
472 private static final int MSG_DISABLE_POINTER_LOCATION = 2;
Jeff Brown40013652012-05-16 21:22:36 -0700473 private static final int MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK = 3;
474 private static final int MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK = 4;
Jeff Brown70825162012-03-28 17:27:48 -0700475
476 private class PolicyHandler extends Handler {
477 @Override
478 public void handleMessage(Message msg) {
479 switch (msg.what) {
480 case MSG_ENABLE_POINTER_LOCATION:
481 enablePointerLocation();
482 break;
483 case MSG_DISABLE_POINTER_LOCATION:
484 disablePointerLocation();
485 break;
Jeff Brown40013652012-05-16 21:22:36 -0700486 case MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK:
487 dispatchMediaKeyWithWakeLock((KeyEvent)msg.obj);
488 break;
489 case MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK:
490 dispatchMediaKeyRepeatWithWakeLock((KeyEvent)msg.obj);
491 break;
Jeff Brown70825162012-03-28 17:27:48 -0700492 }
493 }
494 }
495
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800496 private UEventObserver mHDMIObserver = new UEventObserver() {
497 @Override
498 public void onUEvent(UEventObserver.UEvent event) {
499 setHdmiPlugged("1".equals(event.get("SWITCH_STATE")));
500 }
501 };
502
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800503 class SettingsObserver extends ContentObserver {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800504 SettingsObserver(Handler handler) {
505 super(handler);
506 }
David Brownbaf8d092010-03-08 21:52:59 -0800507
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800508 void observe() {
Christopher Tate5e08af02012-09-21 17:17:22 -0700509 // Observe all users' changes
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800510 ContentResolver resolver = mContext.getContentResolver();
511 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700512 Settings.System.END_BUTTON_BEHAVIOR), false, this,
513 UserHandle.USER_ALL);
David Brownbaf8d092010-03-08 21:52:59 -0800514 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700515 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR), false, this,
516 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800517 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700518 Settings.System.ACCELEROMETER_ROTATION), false, this,
519 UserHandle.USER_ALL);
Mike Lockwood28569302010-01-28 11:54:40 -0500520 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700521 Settings.System.USER_ROTATION), false, this,
522 UserHandle.USER_ALL);
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400523 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700524 Settings.System.SCREEN_OFF_TIMEOUT), false, this,
525 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800526 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700527 Settings.System.POINTER_LOCATION), false, this,
528 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800529 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700530 Settings.Secure.DEFAULT_INPUT_METHOD), false, this,
531 UserHandle.USER_ALL);
Dianne Hackborn03759ed2009-03-27 16:04:08 -0700532 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700533 "fancy_rotation_anim"), false, this,
534 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800535 updateSettings();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800536 }
537
538 @Override public void onChange(boolean selfChange) {
Dianne Hackbornc777e072010-02-12 13:07:59 -0800539 updateSettings();
Jeff Brown01a98dd2011-09-20 15:08:29 -0700540 updateRotation(false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800541 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800542 }
543
544 class MyOrientationListener extends WindowOrientationListener {
Craig Mautnereee29c42013-01-17 14:44:34 -0800545 MyOrientationListener(Context context, Handler handler) {
546 super(context, handler);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800547 }
548
549 @Override
Jeff Brownc0347aa2011-09-23 17:26:09 -0700550 public void onProposedRotationChanged(int rotation) {
551 if (localLOGV) Log.v(TAG, "onProposedRotationChanged, rotation=" + rotation);
Jeff Brown01a98dd2011-09-20 15:08:29 -0700552 updateRotation(false);
553 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800554 }
555 MyOrientationListener mOrientationListener;
556
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700557 IStatusBarService getStatusBarService() {
558 synchronized (mServiceAquireLock) {
559 if (mStatusBarService == null) {
560 mStatusBarService = IStatusBarService.Stub.asInterface(
561 ServiceManager.getService("statusbar"));
562 }
563 return mStatusBarService;
564 }
565 }
566
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700567 /*
568 * We always let the sensor be switched on by default except when
569 * the user has explicitly disabled sensor based rotation or when the
570 * screen is switched off.
571 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700572 boolean needSensorRunningLp() {
Dianne Hackborne5439f22010-10-02 16:53:50 -0700573 if (mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
574 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
575 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT
576 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800577 // If the application has explicitly requested to follow the
578 // orientation, then we need to turn the sensor or.
579 return true;
580 }
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700581 if ((mCarDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_CAR) ||
Jeff Brown1a693182011-11-08 14:44:16 -0800582 (mDeskDockEnablesAccelerometer && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
583 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
584 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK))) {
Mike Lockwoode9867d22009-09-20 01:59:02 -0400585 // enable accelerometer if we are docked in a dock that enables accelerometer
586 // orientation management,
587 return true;
588 }
Jeff Brown207673cd2012-06-05 17:47:11 -0700589 if (mUserRotationMode == USER_ROTATION_LOCKED) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800590 // If the setting for using the sensor by default is enabled, then
591 // we will always leave it on. Note that the user could go to
592 // a window that forces an orientation that does not use the
593 // sensor and in theory we could turn it off... however, when next
594 // turning it on we won't have a good value for the current
595 // orientation for a little bit, which can cause orientation
596 // changes to lag, so we'd like to keep it always on. (It will
597 // still be turned off when the screen is off.)
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700598 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800599 }
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700600 return true;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800601 }
602
603 /*
604 * Various use cases for invoking this function
605 * screen turning off, should always disable listeners if already enabled
606 * screen turned on and current app has sensor based orientation, enable listeners
607 * if not already enabled
608 * screen turned on and current app does not have sensor orientation, disable listeners if
609 * already enabled
610 * screen turning on and current app has sensor based orientation, enable listeners if needed
611 * screen turning on and current app has nosensor based orientation, do nothing
612 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700613 void updateOrientationListenerLp() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800614 if (!mOrientationListener.canDetectOrientation()) {
615 // If sensor is turned off or nonexistent for some reason
616 return;
617 }
618 //Could have been invoked due to screen turning on or off or
619 //change of the currently visible window's orientation
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -0700620 if (localLOGV) Log.v(TAG, "Screen status="+mScreenOnEarly+
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800621 ", current orientation="+mCurrentAppOrientation+
622 ", SensorEnabled="+mOrientationSensorEnabled);
623 boolean disable = true;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -0700624 if (mScreenOnEarly) {
The Android Open Source Project0727d222009-03-11 12:11:58 -0700625 if (needSensorRunningLp()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800626 disable = false;
627 //enable listener if not already enabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700628 if (!mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800629 mOrientationListener.enable();
Dianne Hackborn05726582009-09-22 17:28:24 -0700630 if(localLOGV) Log.v(TAG, "Enabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800631 mOrientationSensorEnabled = true;
632 }
633 }
634 }
635 //check if sensors need to be disabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700636 if (disable && mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800637 mOrientationListener.disable();
Dianne Hackborn05726582009-09-22 17:28:24 -0700638 if(localLOGV) Log.v(TAG, "Disabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800639 mOrientationSensorEnabled = false;
640 }
641 }
642
Jeff Brown4d396052010-10-29 21:50:21 -0700643 private void interceptPowerKeyDown(boolean handled) {
644 mPowerKeyHandled = handled;
645 if (!handled) {
646 mHandler.postDelayed(mPowerLongPress, ViewConfiguration.getGlobalActionKeyTimeout());
647 }
648 }
649
650 private boolean interceptPowerKeyUp(boolean canceled) {
651 if (!mPowerKeyHandled) {
652 mHandler.removeCallbacks(mPowerLongPress);
653 return !canceled;
Jeff Brown4d396052010-10-29 21:50:21 -0700654 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700655 return false;
656 }
657
658 private void cancelPendingPowerKeyAction() {
659 if (!mPowerKeyHandled) {
660 mHandler.removeCallbacks(mPowerLongPress);
661 }
Jeff Brownff204712011-10-25 21:27:54 -0700662 if (mPowerKeyTriggered) {
663 mPendingPowerKeyUpCanceled = true;
664 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700665 }
666
667 private void interceptScreenshotChord() {
Christopher Tatee90585f2012-03-05 18:56:25 -0800668 if (mScreenshotChordEnabled
669 && mVolumeDownKeyTriggered && mPowerKeyTriggered && !mVolumeUpKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700670 final long now = SystemClock.uptimeMillis();
671 if (now <= mVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS
672 && now <= mPowerKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) {
673 mVolumeDownKeyConsumedByScreenshotChord = true;
674 cancelPendingPowerKeyAction();
675
Jeff Sharkey2991fa32012-12-05 18:06:43 -0800676 mHandler.postDelayed(mScreenshotRunnable, getScreenshotChordLongPressDelay());
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700677 }
678 }
679 }
680
Winson Chung1cea2f32012-10-08 20:42:01 -0700681 private long getScreenshotChordLongPressDelay() {
682 if (mKeyguardMediator.isShowing()) {
683 // Double the time it takes to take a screenshot from the keyguard
684 return (long) (KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER *
685 ViewConfiguration.getGlobalActionKeyTimeout());
Winson Chung1cea2f32012-10-08 20:42:01 -0700686 }
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800687 return ViewConfiguration.getGlobalActionKeyTimeout();
Winson Chung1cea2f32012-10-08 20:42:01 -0700688 }
689
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700690 private void cancelPendingScreenshotChordAction() {
Jeff Sharkey2991fa32012-12-05 18:06:43 -0800691 mHandler.removeCallbacks(mScreenshotRunnable);
Jeff Brown4d396052010-10-29 21:50:21 -0700692 }
693
694 private final Runnable mPowerLongPress = new Runnable() {
Craig Mautnerf1b67412012-09-19 13:18:29 -0700695 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800696 public void run() {
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700697 // The context isn't read
698 if (mLongPressOnPowerBehavior < 0) {
Jeff Brown850c5b72012-10-01 15:17:22 -0700699 mLongPressOnPowerBehavior = mContext.getResources().getInteger(
700 com.android.internal.R.integer.config_longPressOnPowerBehavior);
Joe Onoratod208e702010-10-08 16:22:43 -0400701 }
Jeff Brown850c5b72012-10-01 15:17:22 -0700702 int resolvedBehavior = mLongPressOnPowerBehavior;
703 if (FactoryTest.isLongPressOnPowerOffEnabled()) {
704 resolvedBehavior = LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM;
705 }
706
707 switch (resolvedBehavior) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700708 case LONG_PRESS_POWER_NOTHING:
709 break;
710 case LONG_PRESS_POWER_GLOBAL_ACTIONS:
711 mPowerKeyHandled = true;
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -0700712 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
713 performAuditoryFeedbackForAccessibilityIfNeed();
714 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700715 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
716 showGlobalActionsDialog();
717 break;
718 case LONG_PRESS_POWER_SHUT_OFF:
Jeff Brown9a538ee2012-08-20 14:56:57 -0700719 case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM:
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700720 mPowerKeyHandled = true;
721 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
722 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
Jeff Brown850c5b72012-10-01 15:17:22 -0700723 mWindowManagerFuncs.shutdown(resolvedBehavior == LONG_PRESS_POWER_SHUT_OFF);
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700724 break;
725 }
726 }
727 };
728
Jeff Sharkey2991fa32012-12-05 18:06:43 -0800729 private final Runnable mScreenshotRunnable = new Runnable() {
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800730 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700731 public void run() {
732 takeScreenshot();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800733 }
734 };
735
736 void showGlobalActionsDialog() {
737 if (mGlobalActions == null) {
Jeff Brown7304c342012-05-11 18:42:42 -0700738 mGlobalActions = new GlobalActions(mContext, mWindowManagerFuncs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800739 }
Mike Lockwood3a74bd32011-08-12 13:55:22 -0700740 final boolean keyguardShowing = keyguardIsShowingTq();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800741 mGlobalActions.showDialog(keyguardShowing, isDeviceProvisioned());
742 if (keyguardShowing) {
743 // since it took two seconds of long press to bring this up,
744 // poke the wake lock so they have some time to see the dialog.
Jeff Brown3dc524b2012-09-30 19:49:11 -0700745 mKeyguardMediator.userActivity();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800746 }
747 }
748
749 boolean isDeviceProvisioned() {
Jeff Brownbf6f6f92012-09-25 15:03:20 -0700750 return Settings.Global.getInt(
751 mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800752 }
753
Patrick Dubroyece94522011-02-23 18:35:01 -0800754 private void handleLongPressOnHome() {
Joe Onorato46b0d682010-11-22 17:37:27 -0800755 if (mLongPressOnHomeBehavior != LONG_PRESS_HOME_NOTHING) {
Jeff Browncaca8812013-05-09 13:34:33 -0700756 mHomeConsumed = true;
Joe Onorato46b0d682010-11-22 17:37:27 -0800757 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
Patrick Dubroyece94522011-02-23 18:35:01 -0800758
Jeff Browncaca8812013-05-09 13:34:33 -0700759 if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI) {
760 toggleRecentApps();
761 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_ASSIST) {
762 launchAssistAction();
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
Jeff Browncaca8812013-05-09 13:34:33 -0700767 private void handleDoubleTapOnHome() {
768 if (mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
769 mHomeConsumed = true;
770 toggleRecentApps();
771 }
772 }
773
774 private final Runnable mHomeDoubleTapTimeoutRunnable = new Runnable() {
775 @Override
776 public void run() {
777 if (mHomeDoubleTapPending) {
778 mHomeDoubleTapPending = false;
779 launchHomeFromHotKey();
780 }
781 }
782 };
783
Patrick Dubroyece94522011-02-23 18:35:01 -0800784 /**
Jeff Brown68b909d2011-12-07 16:36:01 -0800785 * Create (if necessary) and show or dismiss the recent apps dialog according
786 * according to the requested behavior.
Patrick Dubroyece94522011-02-23 18:35:01 -0800787 */
Jeff Brown68b909d2011-12-07 16:36:01 -0800788 void showOrHideRecentAppsDialog(final int behavior) {
Jeff Brownda3d5a92011-03-29 15:11:34 -0700789 mHandler.post(new Runnable() {
790 @Override
791 public void run() {
792 if (mRecentAppsDialog == null) {
Jeff Brown54875002011-04-06 15:33:01 -0700793 mRecentAppsDialog = new RecentApplicationsDialog(mContext);
Jeff Brownda3d5a92011-03-29 15:11:34 -0700794 }
Jeff Brown54875002011-04-06 15:33:01 -0700795 if (mRecentAppsDialog.isShowing()) {
Jeff Brown68b909d2011-12-07 16:36:01 -0800796 switch (behavior) {
797 case RECENT_APPS_BEHAVIOR_SHOW_OR_DISMISS:
Jeff Brown602ab322012-05-16 13:33:47 -0700798 case RECENT_APPS_BEHAVIOR_DISMISS:
Jeff Brown68b909d2011-12-07 16:36:01 -0800799 mRecentAppsDialog.dismiss();
800 break;
801 case RECENT_APPS_BEHAVIOR_DISMISS_AND_SWITCH:
802 mRecentAppsDialog.dismissAndSwitch();
803 break;
804 case RECENT_APPS_BEHAVIOR_EXIT_TOUCH_MODE_AND_SHOW:
805 default:
806 break;
Jeff Brown54875002011-04-06 15:33:01 -0700807 }
808 } else {
Jeff Brown68b909d2011-12-07 16:36:01 -0800809 switch (behavior) {
810 case RECENT_APPS_BEHAVIOR_SHOW_OR_DISMISS:
811 mRecentAppsDialog.show();
812 break;
813 case RECENT_APPS_BEHAVIOR_EXIT_TOUCH_MODE_AND_SHOW:
814 try {
815 mWindowManager.setInTouchMode(false);
816 } catch (RemoteException e) {
817 }
818 mRecentAppsDialog.show();
819 break;
Jeff Brown602ab322012-05-16 13:33:47 -0700820 case RECENT_APPS_BEHAVIOR_DISMISS:
Jeff Brown68b909d2011-12-07 16:36:01 -0800821 case RECENT_APPS_BEHAVIOR_DISMISS_AND_SWITCH:
822 default:
823 break;
824 }
Jeff Brown54875002011-04-06 15:33:01 -0700825 }
Jeff Brownda3d5a92011-03-29 15:11:34 -0700826 }
827 });
Patrick Dubroyece94522011-02-23 18:35:01 -0800828 }
Jeff Brownda3d5a92011-03-29 15:11:34 -0700829
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800830 /** {@inheritDoc} */
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800831 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800832 public void init(Context context, IWindowManager windowManager,
Jeff Brown96307042012-07-27 15:51:34 -0700833 WindowManagerFuncs windowManagerFuncs) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800834 mContext = context;
835 mWindowManager = windowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700836 mWindowManagerFuncs = windowManagerFuncs;
Mike Lockwoodd747dc82011-09-13 16:28:22 -0400837 mHeadless = "1".equals(SystemProperties.get("ro.config.headless", "0"));
838 if (!mHeadless) {
Mike Lockwood3a74bd32011-08-12 13:55:22 -0700839 // don't create KeyguardViewMediator if headless
Jim Miller9c7e6302012-08-29 13:48:34 -0700840 mKeyguardMediator = new KeyguardViewMediator(context, null);
Mike Lockwood3a74bd32011-08-12 13:55:22 -0700841 }
Jeff Brown70825162012-03-28 17:27:48 -0700842 mHandler = new PolicyHandler();
Craig Mautnereee29c42013-01-17 14:44:34 -0800843 mOrientationListener = new MyOrientationListener(mContext, mHandler);
Jeff Brownc0347aa2011-09-23 17:26:09 -0700844 try {
845 mOrientationListener.setCurrentRotation(windowManager.getRotation());
846 } catch (RemoteException ex) { }
Christopher Tate5e08af02012-09-21 17:17:22 -0700847 mSettingsObserver = new SettingsObserver(mHandler);
848 mSettingsObserver.observe();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800849 mShortcutManager = new ShortcutManager(context, mHandler);
850 mShortcutManager.observe();
Daniel Sandler6396c722013-04-16 20:19:09 -0400851 mUiMode = context.getResources().getInteger(
852 com.android.internal.R.integer.config_defaultUiModeType);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800853 mHomeIntent = new Intent(Intent.ACTION_MAIN, null);
854 mHomeIntent.addCategory(Intent.CATEGORY_HOME);
855 mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
856 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700857 mCarDockIntent = new Intent(Intent.ACTION_MAIN, null);
858 mCarDockIntent.addCategory(Intent.CATEGORY_CAR_DOCK);
859 mCarDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
860 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
861 mDeskDockIntent = new Intent(Intent.ACTION_MAIN, null);
862 mDeskDockIntent.addCategory(Intent.CATEGORY_DESK_DOCK);
863 mDeskDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
864 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Jim Millere6ad1a82010-08-20 19:25:39 -0700865
Jeff Brown96307042012-07-27 15:51:34 -0700866 mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
867 mBroadcastWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800868 "PhoneWindowManager.mBroadcastWakeLock");
869 mEnableShiftMenuBugReports = "1".equals(SystemProperties.get("ro.debuggable"));
Dianne Hackborn2862fff2009-09-15 22:56:29 -0700870 mLidOpenRotation = readRotation(
Mike Lockwood2d1efbd2009-09-16 12:15:53 -0400871 com.android.internal.R.integer.config_lidOpenRotation);
872 mCarDockRotation = readRotation(
873 com.android.internal.R.integer.config_carDockRotation);
874 mDeskDockRotation = readRotation(
875 com.android.internal.R.integer.config_deskDockRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -0700876 mUndockedHdmiRotation = readRotation(
877 com.android.internal.R.integer.config_undockedHdmiRotation);
Mike Lockwoode9867d22009-09-20 01:59:02 -0400878 mCarDockEnablesAccelerometer = mContext.getResources().getBoolean(
879 com.android.internal.R.bool.config_carDockEnablesAccelerometer);
880 mDeskDockEnablesAccelerometer = mContext.getResources().getBoolean(
881 com.android.internal.R.bool.config_deskDockEnablesAccelerometer);
Dianne Hackborn2862fff2009-09-15 22:56:29 -0700882 mLidKeyboardAccessibility = mContext.getResources().getInteger(
883 com.android.internal.R.integer.config_lidKeyboardAccessibility);
884 mLidNavigationAccessibility = mContext.getResources().getInteger(
885 com.android.internal.R.integer.config_lidNavigationAccessibility);
Jeff Brownc458ce92012-04-30 14:58:40 -0700886 mLidControlsSleep = mContext.getResources().getBoolean(
887 com.android.internal.R.bool.config_lidControlsSleep);
Jeff Brownf71343d2013-05-31 17:59:11 -0700888 readConfigurationDependentBehaviors();
Jeff Browncaca8812013-05-09 13:34:33 -0700889
Mike Lockwood1753f7f2009-08-24 14:49:07 -0700890 // register for dock events
Dianne Hackborn78968392010-03-04 20:47:56 -0800891 IntentFilter filter = new IntentFilter();
892 filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE);
893 filter.addAction(UiModeManager.ACTION_EXIT_CAR_MODE);
894 filter.addAction(UiModeManager.ACTION_ENTER_DESK_MODE);
895 filter.addAction(UiModeManager.ACTION_EXIT_DESK_MODE);
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700896 filter.addAction(Intent.ACTION_DOCK_EVENT);
897 Intent intent = context.registerReceiver(mDockReceiver, filter);
898 if (intent != null) {
899 // Retrieve current sticky dock event broadcast.
900 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
901 Intent.EXTRA_DOCK_STATE_UNDOCKED);
902 }
Daniel Sandler7e37df52011-11-16 22:08:23 -0800903
Jeff Brown6aaf2952012-10-05 16:01:08 -0700904 // register for dream-related broadcasts
905 filter = new IntentFilter();
906 filter.addAction(Intent.ACTION_DREAMING_STARTED);
907 filter.addAction(Intent.ACTION_DREAMING_STOPPED);
908 context.registerReceiver(mDreamReceiver, filter);
909
Christopher Tate5e08af02012-09-21 17:17:22 -0700910 // register for multiuser-relevant broadcasts
911 filter = new IntentFilter(Intent.ACTION_USER_SWITCHED);
912 context.registerReceiver(mMultiuserReceiver, filter);
913
Jeff Brownc2346132012-04-13 01:55:38 -0700914 mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700915 mLongPressVibePattern = getLongIntArray(mContext.getResources(),
916 com.android.internal.R.array.config_longPressVibePattern);
917 mVirtualKeyVibePattern = getLongIntArray(mContext.getResources(),
918 com.android.internal.R.array.config_virtualKeyVibePattern);
Amith Yamasanic33cb712010-02-10 15:21:49 -0800919 mKeyboardTapVibePattern = getLongIntArray(mContext.getResources(),
920 com.android.internal.R.array.config_keyboardTapVibePattern);
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700921 mSafeModeDisabledVibePattern = getLongIntArray(mContext.getResources(),
922 com.android.internal.R.array.config_safeModeDisabledVibePattern);
923 mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(),
924 com.android.internal.R.array.config_safeModeEnabledVibePattern);
Daniel Sandler40427442010-07-16 11:44:52 -0400925
Christopher Tatee90585f2012-03-05 18:56:25 -0800926 mScreenshotChordEnabled = mContext.getResources().getBoolean(
927 com.android.internal.R.bool.config_enableScreenshotChord);
928
Justin Kohd378ad72013-04-01 12:18:26 -0700929 mGlobalKeyManager = new GlobalKeyManager(mContext);
930
Joe Onoratoea495d42011-04-06 11:41:11 -0700931 // Controls rotation and the like.
932 initializeHdmiState();
Dianne Hackborn40011092011-09-22 13:37:48 -0700933
934 // Match current screen state.
935 if (mPowerManager.isScreenOn()) {
936 screenTurningOn(null);
937 } else {
938 screenTurnedOff(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
939 }
Mike Lockwood1753f7f2009-08-24 14:49:07 -0700940 }
941
Jeff Brownf71343d2013-05-31 17:59:11 -0700942 /**
943 * Read values from config.xml that may be overridden depending on
944 * the configuration of the device.
945 * eg. Disable long press on home goes to recents on sw600dp.
946 */
947 private void readConfigurationDependentBehaviors() {
948 mLongPressOnHomeBehavior = mContext.getResources().getInteger(
949 com.android.internal.R.integer.config_longPressOnHomeBehavior);
950 if (mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING ||
951 mLongPressOnHomeBehavior > LONG_PRESS_HOME_ASSIST) {
952 mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
953 }
954
955 mDoubleTapOnHomeBehavior = mContext.getResources().getInteger(
956 com.android.internal.R.integer.config_doubleTapOnHomeBehavior);
957 if (mDoubleTapOnHomeBehavior < DOUBLE_TAP_HOME_NOTHING ||
958 mDoubleTapOnHomeBehavior > DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
959 mDoubleTapOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
960 }
961 }
962
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800963 @Override
Dianne Hackborndde331c2012-08-03 14:01:57 -0700964 public void setInitialDisplaySize(Display display, int width, int height, int density) {
Dianne Hackbornc652de82013-02-15 16:32:56 -0800965 if (display.getDisplayId() != Display.DEFAULT_DISPLAY) {
966 throw new IllegalArgumentException("Can only set the default display");
967 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700968 mDisplay = display;
969
970 int shortSize, longSize;
Dianne Hackborn9d132642011-04-21 17:26:39 -0700971 if (width > height) {
Dianne Hackborn81e56d52011-05-26 00:55:58 -0700972 shortSize = height;
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700973 longSize = width;
Dianne Hackborn9d132642011-04-21 17:26:39 -0700974 mLandscapeRotation = Surface.ROTATION_0;
975 mSeascapeRotation = Surface.ROTATION_180;
976 if (mContext.getResources().getBoolean(
977 com.android.internal.R.bool.config_reverseDefaultRotation)) {
978 mPortraitRotation = Surface.ROTATION_90;
979 mUpsideDownRotation = Surface.ROTATION_270;
980 } else {
981 mPortraitRotation = Surface.ROTATION_270;
982 mUpsideDownRotation = Surface.ROTATION_90;
983 }
984 } else {
Dianne Hackborn81e56d52011-05-26 00:55:58 -0700985 shortSize = width;
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700986 longSize = height;
Dianne Hackborn9d132642011-04-21 17:26:39 -0700987 mPortraitRotation = Surface.ROTATION_0;
988 mUpsideDownRotation = Surface.ROTATION_180;
989 if (mContext.getResources().getBoolean(
990 com.android.internal.R.bool.config_reverseDefaultRotation)) {
991 mLandscapeRotation = Surface.ROTATION_270;
992 mSeascapeRotation = Surface.ROTATION_90;
993 } else {
994 mLandscapeRotation = Surface.ROTATION_90;
995 mSeascapeRotation = Surface.ROTATION_270;
996 }
997 }
Dianne Hackborn81e56d52011-05-26 00:55:58 -0700998
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700999 mStatusBarHeight = mContext.getResources().getDimensionPixelSize(
1000 com.android.internal.R.dimen.status_bar_height);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001001
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001002 // Height of the navigation bar when presented horizontally at bottom
1003 mNavigationBarHeightForRotation[mPortraitRotation] =
1004 mNavigationBarHeightForRotation[mUpsideDownRotation] =
Daniel Sandler4a066c52012-04-20 14:49:13 -04001005 mContext.getResources().getDimensionPixelSize(
1006 com.android.internal.R.dimen.navigation_bar_height);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001007 mNavigationBarHeightForRotation[mLandscapeRotation] =
1008 mNavigationBarHeightForRotation[mSeascapeRotation] =
1009 mContext.getResources().getDimensionPixelSize(
1010 com.android.internal.R.dimen.navigation_bar_height_landscape);
1011
1012 // Width of the navigation bar when presented vertically along one side
1013 mNavigationBarWidthForRotation[mPortraitRotation] =
1014 mNavigationBarWidthForRotation[mUpsideDownRotation] =
1015 mNavigationBarWidthForRotation[mLandscapeRotation] =
1016 mNavigationBarWidthForRotation[mSeascapeRotation] =
Daniel Sandler4a066c52012-04-20 14:49:13 -04001017 mContext.getResources().getDimensionPixelSize(
1018 com.android.internal.R.dimen.navigation_bar_width);
1019
1020 // SystemUI (status bar) layout policy
Dianne Hackborndde331c2012-08-03 14:01:57 -07001021 int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / density;
Daniel Sandler4a066c52012-04-20 14:49:13 -04001022
1023 if (shortSizeDp < 600) {
1024 // 0-599dp: "phone" UI with a separate status & navigation bar
1025 mHasSystemNavBar = false;
1026 mNavigationBarCanMove = true;
1027 } else if (shortSizeDp < 720) {
Daniel Sandleref863702012-07-11 10:03:34 -04001028 // 600+dp: "phone" UI with modifications for larger screens
Daniel Sandler4a066c52012-04-20 14:49:13 -04001029 mHasSystemNavBar = false;
1030 mNavigationBarCanMove = false;
Daniel Sandler4a066c52012-04-20 14:49:13 -04001031 }
Daniel Sandler36412a72011-08-04 09:35:13 -04001032
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001033 if (!mHasSystemNavBar) {
1034 mHasNavigationBar = mContext.getResources().getBoolean(
1035 com.android.internal.R.bool.config_showNavigationBar);
1036 // Allow a system property to override this. Used by the emulator.
1037 // See also hasNavigationBar().
1038 String navBarOverride = SystemProperties.get("qemu.hw.mainkeys");
1039 if (! "".equals(navBarOverride)) {
1040 if (navBarOverride.equals("1")) mHasNavigationBar = false;
1041 else if (navBarOverride.equals("0")) mHasNavigationBar = true;
1042 }
1043 } else {
1044 mHasNavigationBar = false;
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04001045 }
1046
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001047 if (mHasSystemNavBar) {
1048 // The system bar is always at the bottom. If you are watching
1049 // a video in landscape, we don't need to hide it if we can still
1050 // show a 16:9 aspect ratio with it.
Dianne Hackborndde331c2012-08-03 14:01:57 -07001051 int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / density;
Daniel Sandler4a066c52012-04-20 14:49:13 -04001052 int barHeightDp = mNavigationBarHeightForRotation[mLandscapeRotation]
Dianne Hackborndde331c2012-08-03 14:01:57 -07001053 * DisplayMetrics.DENSITY_DEFAULT / density;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001054 int aspect = ((shortSizeDp-barHeightDp) * 16) / longSizeDp;
1055 // We have computed the aspect ratio with the bar height taken
1056 // out to be 16:aspect. If this is less than 9, then hiding
1057 // the navigation bar will provide more useful space for wide
1058 // screen movies.
1059 mCanHideNavigationBar = aspect < 9;
1060 } else if (mHasNavigationBar) {
1061 // The navigation bar is at the right in landscape; it seems always
1062 // useful to hide it for showing a video.
1063 mCanHideNavigationBar = true;
1064 } else {
1065 mCanHideNavigationBar = false;
1066 }
Erik Gilling9a41ef82011-09-26 19:21:03 -07001067
Jeff Brown27f1d672012-10-17 18:32:34 -07001068 // For demo purposes, allow the rotation of the HDMI display to be controlled.
1069 // By default, HDMI locks rotation to landscape.
Erik Gilling9a41ef82011-09-26 19:21:03 -07001070 if ("portrait".equals(SystemProperties.get("persist.demo.hdmirotation"))) {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001071 mDemoHdmiRotation = mPortraitRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001072 } else {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001073 mDemoHdmiRotation = mLandscapeRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001074 }
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001075 mDemoHdmiRotationLock = SystemProperties.getBoolean("persist.demo.hdmirotationlock", false);
Dianne Hackborn9d132642011-04-21 17:26:39 -07001076 }
1077
Dianne Hackbornc652de82013-02-15 16:32:56 -08001078 @Override
1079 public void setDisplayOverscan(Display display, int left, int top, int right, int bottom) {
1080 if (display.getDisplayId() == Display.DEFAULT_DISPLAY) {
1081 mOverscanLeft = left;
1082 mOverscanTop = top;
1083 mOverscanRight = right;
1084 mOverscanBottom = bottom;
1085 }
1086 }
1087
Dianne Hackbornc777e072010-02-12 13:07:59 -08001088 public void updateSettings() {
1089 ContentResolver resolver = mContext.getContentResolver();
1090 boolean updateRotation = false;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001091 synchronized (mLock) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001092 mEndcallBehavior = Settings.System.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001093 Settings.System.END_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001094 Settings.System.END_BUTTON_BEHAVIOR_DEFAULT,
1095 UserHandle.USER_CURRENT);
1096 mIncallPowerBehavior = Settings.Secure.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001097 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001098 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT,
1099 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001100
Jeff Brown207673cd2012-06-05 17:47:11 -07001101 // Configure rotation lock.
Christopher Tate5e08af02012-09-21 17:17:22 -07001102 int userRotation = Settings.System.getIntForUser(resolver,
1103 Settings.System.USER_ROTATION, Surface.ROTATION_0,
1104 UserHandle.USER_CURRENT);
Jeff Brown207673cd2012-06-05 17:47:11 -07001105 if (mUserRotation != userRotation) {
1106 mUserRotation = userRotation;
1107 updateRotation = true;
1108 }
Christopher Tate5e08af02012-09-21 17:17:22 -07001109 int userRotationMode = Settings.System.getIntForUser(resolver,
1110 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
Jeff Brown207673cd2012-06-05 17:47:11 -07001111 WindowManagerPolicy.USER_ROTATION_FREE :
1112 WindowManagerPolicy.USER_ROTATION_LOCKED;
1113 if (mUserRotationMode != userRotationMode) {
1114 mUserRotationMode = userRotationMode;
1115 updateRotation = true;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001116 updateOrientationListenerLp();
1117 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001118
Dianne Hackbornc777e072010-02-12 13:07:59 -08001119 if (mSystemReady) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001120 int pointerLocation = Settings.System.getIntForUser(resolver,
1121 Settings.System.POINTER_LOCATION, 0, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001122 if (mPointerLocationMode != pointerLocation) {
1123 mPointerLocationMode = pointerLocation;
Jeff Brown70825162012-03-28 17:27:48 -07001124 mHandler.sendEmptyMessage(pointerLocation != 0 ?
1125 MSG_ENABLE_POINTER_LOCATION : MSG_DISABLE_POINTER_LOCATION);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001126 }
1127 }
1128 // use screen off timeout setting as the timeout for the lockscreen
Christopher Tate5e08af02012-09-21 17:17:22 -07001129 mLockScreenTimeout = Settings.System.getIntForUser(resolver,
1130 Settings.System.SCREEN_OFF_TIMEOUT, 0, UserHandle.USER_CURRENT);
1131 String imId = Settings.Secure.getStringForUser(resolver,
1132 Settings.Secure.DEFAULT_INPUT_METHOD, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001133 boolean hasSoftInput = imId != null && imId.length() > 0;
1134 if (mHasSoftInput != hasSoftInput) {
1135 mHasSoftInput = hasSoftInput;
1136 updateRotation = true;
1137 }
1138 }
1139 if (updateRotation) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07001140 updateRotation(true);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001141 }
Jeff Brown70825162012-03-28 17:27:48 -07001142 }
1143
1144 private void enablePointerLocation() {
1145 if (mPointerLocationView == null) {
1146 mPointerLocationView = new PointerLocationView(mContext);
1147 mPointerLocationView.setPrintCoords(false);
1148
Dianne Hackbornc777e072010-02-12 13:07:59 -08001149 WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
1150 WindowManager.LayoutParams.MATCH_PARENT,
1151 WindowManager.LayoutParams.MATCH_PARENT);
Jeff Brown3b2b3542010-10-15 00:54:27 -07001152 lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001153 lp.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN
1154 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
1155 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1156 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
Jeff Brown90fc9052012-10-01 14:44:24 -07001157 if (ActivityManager.isHighEndGfx()) {
1158 lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
1159 lp.privateFlags |=
1160 WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED;
1161 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001162 lp.format = PixelFormat.TRANSLUCENT;
1163 lp.setTitle("PointerLocation");
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001164 WindowManager wm = (WindowManager)
Dianne Hackbornc777e072010-02-12 13:07:59 -08001165 mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Browncc4f7db2011-08-30 20:34:48 -07001166 lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL;
Jeff Brown70825162012-03-28 17:27:48 -07001167 wm.addView(mPointerLocationView, lp);
1168
Jeff Brownac143512012-04-05 18:57:33 -07001169 mPointerLocationInputChannel =
1170 mWindowManagerFuncs.monitorInput("PointerLocationView");
1171 mPointerLocationInputEventReceiver =
1172 new PointerLocationInputEventReceiver(mPointerLocationInputChannel,
1173 Looper.myLooper(), mPointerLocationView);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001174 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001175 }
Jeff Brown70825162012-03-28 17:27:48 -07001176
1177 private void disablePointerLocation() {
1178 if (mPointerLocationInputEventReceiver != null) {
1179 mPointerLocationInputEventReceiver.dispose();
1180 mPointerLocationInputEventReceiver = null;
1181 }
1182
1183 if (mPointerLocationInputChannel != null) {
1184 mPointerLocationInputChannel.dispose();
1185 mPointerLocationInputChannel = null;
1186 }
1187
1188 if (mPointerLocationView != null) {
1189 WindowManager wm = (WindowManager)
1190 mContext.getSystemService(Context.WINDOW_SERVICE);
1191 wm.removeView(mPointerLocationView);
1192 mPointerLocationView = null;
1193 }
1194 }
1195
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001196 private int readRotation(int resID) {
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001197 try {
1198 int rotation = mContext.getResources().getInteger(resID);
1199 switch (rotation) {
1200 case 0:
1201 return Surface.ROTATION_0;
1202 case 90:
1203 return Surface.ROTATION_90;
1204 case 180:
1205 return Surface.ROTATION_180;
1206 case 270:
1207 return Surface.ROTATION_270;
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001208 }
1209 } catch (Resources.NotFoundException e) {
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001210 // fall through
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001211 }
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001212 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001213 }
1214
1215 /** {@inheritDoc} */
Craig Mautner88400d32012-09-30 12:35:45 -07001216 @Override
Dianne Hackbornc2293022013-02-06 23:14:49 -08001217 public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001218 int type = attrs.type;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001219
1220 outAppOp[0] = AppOpsManager.OP_NONE;
1221
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001222 if (type < WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW
1223 || type > WindowManager.LayoutParams.LAST_SYSTEM_WINDOW) {
Jeff Brown98365d72012-08-19 20:30:52 -07001224 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001225 }
1226 String permission = null;
1227 switch (type) {
1228 case TYPE_TOAST:
1229 // XXX right now the app process has complete control over
1230 // this... should introduce a token to let the system
1231 // monitor/control what they are doing.
1232 break;
Daniel Sandler7d276c32012-01-30 14:33:52 -05001233 case TYPE_DREAM:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001234 case TYPE_INPUT_METHOD:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001235 case TYPE_WALLPAPER:
1236 // The window manager will check these.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001237 break;
1238 case TYPE_PHONE:
1239 case TYPE_PRIORITY_PHONE:
1240 case TYPE_SYSTEM_ALERT:
1241 case TYPE_SYSTEM_ERROR:
1242 case TYPE_SYSTEM_OVERLAY:
1243 permission = android.Manifest.permission.SYSTEM_ALERT_WINDOW;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001244 outAppOp[0] = AppOpsManager.OP_SYSTEM_ALERT_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001245 break;
1246 default:
1247 permission = android.Manifest.permission.INTERNAL_SYSTEM_WINDOW;
1248 }
1249 if (permission != null) {
1250 if (mContext.checkCallingOrSelfPermission(permission)
1251 != PackageManager.PERMISSION_GRANTED) {
Jeff Brown98365d72012-08-19 20:30:52 -07001252 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001253 }
1254 }
Jeff Brown98365d72012-08-19 20:30:52 -07001255 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001256 }
Craig Mautner88400d32012-09-30 12:35:45 -07001257
1258 @Override
1259 public boolean checkShowToOwnerOnly(WindowManager.LayoutParams attrs) {
1260
1261 // If this switch statement is modified, modify the comment in the declarations of
1262 // the type in {@link WindowManager.LayoutParams} as well.
1263 switch (attrs.type) {
1264 default:
1265 // These are the windows that by default are shown only to the user that created
1266 // them. If this needs to be overridden, set
1267 // {@link WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS} in
1268 // {@link WindowManager.LayoutParams}. Note that permission
1269 // {@link android.Manifest.permission.INTERNAL_SYSTEM_WINDOW} is required as well.
1270 if ((attrs.privateFlags & PRIVATE_FLAG_SHOW_FOR_ALL_USERS) == 0) {
1271 return true;
1272 }
1273 break;
1274
1275 // These are the windows that by default are shown to all users. However, to
1276 // protect against spoofing, check permissions below.
1277 case TYPE_APPLICATION_STARTING:
1278 case TYPE_BOOT_PROGRESS:
1279 case TYPE_DISPLAY_OVERLAY:
1280 case TYPE_HIDDEN_NAV_CONSUMER:
1281 case TYPE_KEYGUARD:
1282 case TYPE_KEYGUARD_DIALOG:
1283 case TYPE_MAGNIFICATION_OVERLAY:
1284 case TYPE_NAVIGATION_BAR:
1285 case TYPE_NAVIGATION_BAR_PANEL:
1286 case TYPE_PHONE:
1287 case TYPE_POINTER:
1288 case TYPE_PRIORITY_PHONE:
1289 case TYPE_RECENTS_OVERLAY:
1290 case TYPE_SEARCH_BAR:
1291 case TYPE_STATUS_BAR:
1292 case TYPE_STATUS_BAR_PANEL:
1293 case TYPE_STATUS_BAR_SUB_PANEL:
1294 case TYPE_SYSTEM_DIALOG:
1295 case TYPE_UNIVERSE_BACKGROUND:
1296 case TYPE_VOLUME_OVERLAY:
1297 break;
1298 }
1299
1300 // Check if third party app has set window to system window type.
1301 return mContext.checkCallingOrSelfPermission(
1302 android.Manifest.permission.INTERNAL_SYSTEM_WINDOW)
1303 != PackageManager.PERMISSION_GRANTED;
1304 }
1305
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001306 public void adjustWindowParamsLw(WindowManager.LayoutParams attrs) {
1307 switch (attrs.type) {
1308 case TYPE_SYSTEM_OVERLAY:
Jeff Brown3b2b3542010-10-15 00:54:27 -07001309 case TYPE_SECURE_SYSTEM_OVERLAY:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001310 case TYPE_TOAST:
1311 // These types of windows can't receive input events.
1312 attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1313 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001314 attrs.flags &= ~WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001315 break;
1316 }
1317 }
1318
1319 void readLidState() {
Jeff Brown2e7760e2012-04-11 15:14:55 -07001320 mLidState = mWindowManagerFuncs.getLidState();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001321 }
1322
Jeff Browndaa37532012-05-01 15:54:03 -07001323 private boolean isHidden(int accessibilityMode) {
1324 switch (accessibilityMode) {
1325 case 1:
1326 return mLidState == LID_CLOSED;
1327 case 2:
1328 return mLidState == LID_OPEN;
1329 default:
1330 return false;
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001331 }
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001332 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001333
Jeff Browndaa37532012-05-01 15:54:03 -07001334 private boolean isBuiltInKeyboardVisible() {
1335 return mHaveBuiltInKeyboard && !isHidden(mLidKeyboardAccessibility);
Jeff Brownc458ce92012-04-30 14:58:40 -07001336 }
1337
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001338 /** {@inheritDoc} */
Jeff Browndaa37532012-05-01 15:54:03 -07001339 public void adjustConfigurationLw(Configuration config, int keyboardPresence,
1340 int navigationPresence) {
1341 mHaveBuiltInKeyboard = (keyboardPresence & PRESENCE_INTERNAL) != 0;
1342
Jeff Brownf71343d2013-05-31 17:59:11 -07001343 readConfigurationDependentBehaviors();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001344 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07001345 applyLidSwitchState();
Jeff Brownd04a88c2011-01-16 14:05:47 -08001346
Jeff Browndaa37532012-05-01 15:54:03 -07001347 if (config.keyboard == Configuration.KEYBOARD_NOKEYS
1348 || (keyboardPresence == PRESENCE_INTERNAL
1349 && isHidden(mLidKeyboardAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001350 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_YES;
Jeff Browndaa37532012-05-01 15:54:03 -07001351 if (!mHasSoftInput) {
1352 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_YES;
1353 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001354 }
1355
Jeff Browndaa37532012-05-01 15:54:03 -07001356 if (config.navigation == Configuration.NAVIGATION_NONAV
1357 || (navigationPresence == PRESENCE_INTERNAL
1358 && isHidden(mLidNavigationAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001359 config.navigationHidden = Configuration.NAVIGATIONHIDDEN_YES;
Jeff Brownd04a88c2011-01-16 14:05:47 -08001360 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001361 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001362
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001363 /** {@inheritDoc} */
1364 public int windowTypeToLayerLw(int type) {
1365 if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001366 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001367 }
1368 switch (type) {
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001369 case TYPE_UNIVERSE_BACKGROUND:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001370 return 1;
1371 case TYPE_WALLPAPER:
1372 // wallpaper is at the bottom, though the window manager may move it.
1373 return 2;
1374 case TYPE_PHONE:
1375 return 3;
1376 case TYPE_SEARCH_BAR:
1377 return 4;
Craig Mautner88400d32012-09-30 12:35:45 -07001378 case TYPE_RECENTS_OVERLAY:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001379 case TYPE_SYSTEM_DIALOG:
1380 return 5;
1381 case TYPE_TOAST:
1382 // toasts and the plugged-in battery thing
1383 return 6;
1384 case TYPE_PRIORITY_PHONE:
1385 // SIM errors and unlock. Not sure if this really should be in a high layer.
1386 return 7;
1387 case TYPE_DREAM:
1388 // used for Dreams (screensavers with TYPE_DREAM windows)
1389 return 8;
1390 case TYPE_SYSTEM_ALERT:
1391 // like the ANR / app crashed dialogs
1392 return 9;
1393 case TYPE_INPUT_METHOD:
1394 // on-screen keyboards and other such input method user interfaces go here.
1395 return 10;
1396 case TYPE_INPUT_METHOD_DIALOG:
1397 // on-screen keyboards and other such input method user interfaces go here.
1398 return 11;
1399 case TYPE_KEYGUARD:
1400 // the keyguard; nothing on top of these can take focus, since they are
1401 // responsible for power management when displayed.
1402 return 12;
1403 case TYPE_KEYGUARD_DIALOG:
1404 return 13;
1405 case TYPE_STATUS_BAR_SUB_PANEL:
1406 return 14;
1407 case TYPE_STATUS_BAR:
1408 return 15;
1409 case TYPE_STATUS_BAR_PANEL:
1410 return 16;
1411 case TYPE_VOLUME_OVERLAY:
1412 // the on-screen volume indicator and controller shown when the user
1413 // changes the device volume
1414 return 17;
1415 case TYPE_SYSTEM_OVERLAY:
1416 // the on-screen volume indicator and controller shown when the user
1417 // changes the device volume
1418 return 18;
1419 case TYPE_NAVIGATION_BAR:
1420 // the navigation bar, if available, shows atop most things
1421 return 19;
1422 case TYPE_NAVIGATION_BAR_PANEL:
1423 // some panels (e.g. search) need to show on top of the navigation bar
1424 return 20;
1425 case TYPE_SYSTEM_ERROR:
1426 // system-level error dialogs
1427 return 21;
1428 case TYPE_MAGNIFICATION_OVERLAY:
1429 // used to highlight the magnified portion of a display
1430 return 22;
1431 case TYPE_DISPLAY_OVERLAY:
1432 // used to simulate secondary display devices
1433 return 23;
1434 case TYPE_DRAG:
1435 // the drag layer: input for drag-and-drop is associated with this window,
1436 // which sits above all other focusable windows
1437 return 24;
1438 case TYPE_SECURE_SYSTEM_OVERLAY:
1439 return 25;
1440 case TYPE_BOOT_PROGRESS:
1441 return 26;
1442 case TYPE_POINTER:
1443 // the (mouse) pointer layer
1444 return 27;
1445 case TYPE_HIDDEN_NAV_CONSUMER:
1446 return 28;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001447 }
1448 Log.e(TAG, "Unknown window type: " + type);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001449 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001450 }
1451
1452 /** {@inheritDoc} */
1453 public int subWindowTypeToLayerLw(int type) {
1454 switch (type) {
1455 case TYPE_APPLICATION_PANEL:
1456 case TYPE_APPLICATION_ATTACHED_DIALOG:
1457 return APPLICATION_PANEL_SUBLAYER;
1458 case TYPE_APPLICATION_MEDIA:
1459 return APPLICATION_MEDIA_SUBLAYER;
Dianne Hackborn5cb8d792009-05-21 17:34:15 -07001460 case TYPE_APPLICATION_MEDIA_OVERLAY:
1461 return APPLICATION_MEDIA_OVERLAY_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001462 case TYPE_APPLICATION_SUB_PANEL:
1463 return APPLICATION_SUB_PANEL_SUBLAYER;
1464 }
1465 Log.e(TAG, "Unknown sub-window type: " + type);
1466 return 0;
1467 }
1468
Dianne Hackbornabe0da02009-09-18 01:55:39 -07001469 public int getMaxWallpaperLayer() {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001470 return windowTypeToLayerLw(TYPE_STATUS_BAR);
Dianne Hackbornabe0da02009-09-18 01:55:39 -07001471 }
1472
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001473 public int getAboveUniverseLayer() {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001474 return windowTypeToLayerLw(TYPE_SYSTEM_ERROR);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001475 }
1476
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001477 public boolean hasSystemNavBar() {
1478 return mHasSystemNavBar;
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001479 }
1480
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001481 public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07001482 if (mHasNavigationBar) {
1483 // For a basic navigation bar, when we are in landscape mode we place
1484 // the navigation bar to the side.
Daniel Sandler4a066c52012-04-20 14:49:13 -04001485 if (mNavigationBarCanMove && fullWidth > fullHeight) {
1486 return fullWidth - mNavigationBarWidthForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07001487 }
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001488 }
1489 return fullWidth;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001490 }
1491
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001492 public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07001493 if (mHasSystemNavBar) {
1494 // For the system navigation bar, we always place it at the bottom.
Daniel Sandler4a066c52012-04-20 14:49:13 -04001495 return fullHeight - mNavigationBarHeightForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07001496 }
1497 if (mHasNavigationBar) {
1498 // For a basic navigation bar, when we are in portrait mode we place
1499 // the navigation bar to the bottom.
Daniel Sandler4a066c52012-04-20 14:49:13 -04001500 if (!mNavigationBarCanMove || fullWidth < fullHeight) {
1501 return fullHeight - mNavigationBarHeightForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07001502 }
1503 }
1504 return fullHeight;
Dianne Hackborn69cb8752011-05-19 18:13:32 -07001505 }
1506
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001507 public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation) {
1508 return getNonDecorDisplayWidth(fullWidth, fullHeight, rotation);
Dianne Hackborn69cb8752011-05-19 18:13:32 -07001509 }
1510
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001511 public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07001512 // If we don't have a system nav bar, then there is a separate status
1513 // bar at the top of the display. We don't count that as part of the
1514 // fixed decor, since it can hide; however, for purposes of configurations,
1515 // we do want to exclude it since applications can't generally use that part
1516 // of the screen.
1517 if (!mHasSystemNavBar) {
1518 return getNonDecorDisplayHeight(fullWidth, fullHeight, rotation) - mStatusBarHeight;
1519 }
1520 return getNonDecorDisplayHeight(fullWidth, fullHeight, rotation);
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001521 }
1522
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001523 @Override
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07001524 public boolean doesForceHide(WindowState win, WindowManager.LayoutParams attrs) {
1525 return attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD;
1526 }
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001527
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001528 @Override
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07001529 public boolean canBeForceHidden(WindowState win, WindowManager.LayoutParams attrs) {
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001530 switch (attrs.type) {
1531 case TYPE_STATUS_BAR:
1532 case TYPE_NAVIGATION_BAR:
1533 case TYPE_WALLPAPER:
1534 case TYPE_DREAM:
1535 case TYPE_UNIVERSE_BACKGROUND:
1536 case TYPE_KEYGUARD:
1537 return false;
1538 default:
1539 return true;
1540 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07001541 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001542
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001543 /** {@inheritDoc} */
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001544 @Override
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07001545 public View addStartingWindow(IBinder appToken, String packageName, int theme,
1546 CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes,
1547 int icon, int windowFlags) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001548 if (!SHOW_STARTING_ANIMATIONS) {
1549 return null;
1550 }
1551 if (packageName == null) {
1552 return null;
1553 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001554
Mathias Jeppssond1443e92012-08-24 15:25:32 +02001555 WindowManager wm = null;
1556 View view = null;
1557
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001558 try {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001559 Context context = mContext;
Craig Mautner6fbda632012-07-03 09:26:39 -07001560 if (DEBUG_STARTING_WINDOW) Slog.d(TAG, "addStartingWindow " + packageName
1561 + ": nonLocalizedLabel=" + nonLocalizedLabel + " theme="
1562 + Integer.toHexString(theme));
Dianne Hackborn247fe742011-01-08 17:25:57 -08001563 if (theme != context.getThemeResId() || labelRes != 0) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001564 try {
1565 context = context.createPackageContext(packageName, 0);
Dianne Hackborn247fe742011-01-08 17:25:57 -08001566 context.setTheme(theme);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001567 } catch (PackageManager.NameNotFoundException e) {
1568 // Ignore
1569 }
1570 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001571
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001572 Window win = PolicyManager.makeNewWindow(context);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001573 final TypedArray ta = win.getWindowStyle();
1574 if (ta.getBoolean(
1575 com.android.internal.R.styleable.Window_windowDisablePreview, false)
1576 || ta.getBoolean(
1577 com.android.internal.R.styleable.Window_windowShowWallpaper,false)) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001578 return null;
1579 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001580
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001581 Resources r = context.getResources();
1582 win.setTitle(r.getText(labelRes, nonLocalizedLabel));
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001583
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001584 win.setType(
1585 WindowManager.LayoutParams.TYPE_APPLICATION_STARTING);
1586 // Force the window flags: this is a fake window, so it is not really
1587 // touchable or focusable by the user. We also add in the ALT_FOCUSABLE_IM
1588 // flag because we do know that the next window will take input
1589 // focus, so we want to get the IME window up on top of us right away.
1590 win.setFlags(
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08001591 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001592 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
1593 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
1594 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08001595 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001596 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
1597 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
1598 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001599
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07001600 if (!compatInfo.supportsScreen()) {
1601 win.addFlags(WindowManager.LayoutParams.FLAG_COMPATIBLE_WINDOW);
1602 }
1603
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001604 win.setLayout(WindowManager.LayoutParams.MATCH_PARENT,
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07001605 WindowManager.LayoutParams.MATCH_PARENT);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001606
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001607 final WindowManager.LayoutParams params = win.getAttributes();
1608 params.token = appToken;
1609 params.packageName = packageName;
1610 params.windowAnimations = win.getWindowStyle().getResourceId(
1611 com.android.internal.R.styleable.Window_windowAnimationStyle, 0);
Dianne Hackborn5d927c22011-09-02 12:22:18 -07001612 params.privateFlags |=
1613 WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED;
Craig Mautner88400d32012-09-30 12:35:45 -07001614 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001615 params.setTitle("Starting " + packageName);
1616
Mathias Jeppssond1443e92012-08-24 15:25:32 +02001617 wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
1618 view = win.getDecorView();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001619
1620 if (win.isFloating()) {
1621 // Whoops, there is no way to display an animation/preview
1622 // of such a thing! After all that work... let's skip it.
1623 // (Note that we must do this here because it is in
1624 // getDecorView() where the theme is evaluated... maybe
1625 // we should peek the floating attribute from the theme
1626 // earlier.)
1627 return null;
1628 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001629
Craig Mautner6fbda632012-07-03 09:26:39 -07001630 if (DEBUG_STARTING_WINDOW) Slog.d(
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001631 TAG, "Adding starting window for " + packageName
1632 + " / " + appToken + ": "
1633 + (view.getParent() != null ? view : null));
1634
1635 wm.addView(view, params);
1636
1637 // Only return the view if it was successfully added to the
1638 // window manager... which we can tell by it having a parent.
1639 return view.getParent() != null ? view : null;
Jeff Brown98365d72012-08-19 20:30:52 -07001640 } catch (WindowManager.BadTokenException e) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001641 // ignore
1642 Log.w(TAG, appToken + " already running, starting window not displayed");
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001643 } catch (RuntimeException e) {
1644 // don't crash if something else bad happens, for example a
1645 // failure loading resources because we are loading from an app
1646 // on external storage that has been unmounted.
1647 Log.w(TAG, appToken + " failed creating starting window", e);
Mathias Jeppssond1443e92012-08-24 15:25:32 +02001648 } finally {
1649 if (view != null && view.getParent() == null) {
1650 Log.w(TAG, "view not successfully added to wm, removing view");
1651 wm.removeViewImmediate(view);
1652 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001653 }
1654
1655 return null;
1656 }
1657
1658 /** {@inheritDoc} */
1659 public void removeStartingWindow(IBinder appToken, View window) {
Craig Mautner6fbda632012-07-03 09:26:39 -07001660 if (DEBUG_STARTING_WINDOW) {
1661 RuntimeException e = new RuntimeException("here");
1662 e.fillInStackTrace();
1663 Log.v(TAG, "Removing starting window for " + appToken + ": " + window, e);
1664 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001665
1666 if (window != null) {
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001667 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001668 wm.removeView(window);
1669 }
1670 }
1671
1672 /**
1673 * Preflight adding a window to the system.
1674 *
1675 * Currently enforces that three window types are singletons:
1676 * <ul>
1677 * <li>STATUS_BAR_TYPE</li>
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001678 * <li>KEYGUARD_TYPE</li>
1679 * </ul>
1680 *
1681 * @param win The window to be added
1682 * @param attrs Information about the window to be added
1683 *
Jeff Brown98365d72012-08-19 20:30:52 -07001684 * @return If ok, WindowManagerImpl.ADD_OKAY. If too many singletons,
1685 * WindowManagerImpl.ADD_MULTIPLE_SINGLETON
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001686 */
1687 public int prepareAddWindowLw(WindowState win, WindowManager.LayoutParams attrs) {
1688 switch (attrs.type) {
1689 case TYPE_STATUS_BAR:
Joe Onorato8bc6c512010-06-04 16:21:12 -04001690 mContext.enforceCallingOrSelfPermission(
1691 android.Manifest.permission.STATUS_BAR_SERVICE,
1692 "PhoneWindowManager");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001693 if (mStatusBar != null) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001694 if (mStatusBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07001695 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001696 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001697 }
1698 mStatusBar = win;
1699 break;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04001700 case TYPE_NAVIGATION_BAR:
1701 mContext.enforceCallingOrSelfPermission(
1702 android.Manifest.permission.STATUS_BAR_SERVICE,
1703 "PhoneWindowManager");
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001704 if (mNavigationBar != null) {
1705 if (mNavigationBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07001706 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001707 }
1708 }
Daniel Sandler8956dbb2011-04-22 07:55:02 -04001709 mNavigationBar = win;
1710 if (DEBUG_LAYOUT) Log.i(TAG, "NAVIGATION BAR: " + mNavigationBar);
1711 break;
Jim Millere898ac52012-04-06 17:10:57 -07001712 case TYPE_NAVIGATION_BAR_PANEL:
1713 mContext.enforceCallingOrSelfPermission(
1714 android.Manifest.permission.STATUS_BAR_SERVICE,
1715 "PhoneWindowManager");
1716 break;
Dianne Hackborn08743722009-12-21 12:16:51 -08001717 case TYPE_STATUS_BAR_PANEL:
Joe Onorato8bc6c512010-06-04 16:21:12 -04001718 mContext.enforceCallingOrSelfPermission(
1719 android.Manifest.permission.STATUS_BAR_SERVICE,
1720 "PhoneWindowManager");
Dianne Hackborn08743722009-12-21 12:16:51 -08001721 break;
Joe Onorato29fc2c92010-11-24 10:26:50 -08001722 case TYPE_STATUS_BAR_SUB_PANEL:
1723 mContext.enforceCallingOrSelfPermission(
1724 android.Manifest.permission.STATUS_BAR_SERVICE,
1725 "PhoneWindowManager");
Joe Onorato29fc2c92010-11-24 10:26:50 -08001726 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001727 case TYPE_KEYGUARD:
1728 if (mKeyguard != null) {
Jeff Brown98365d72012-08-19 20:30:52 -07001729 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001730 }
1731 mKeyguard = win;
1732 break;
1733 }
Jeff Brown98365d72012-08-19 20:30:52 -07001734 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001735 }
1736
1737 /** {@inheritDoc} */
1738 public void removeWindowLw(WindowState win) {
1739 if (mStatusBar == win) {
1740 mStatusBar = null;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04001741 } else if (mKeyguard == win) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001742 mKeyguard = null;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04001743 } else if (mNavigationBar == win) {
1744 mNavigationBar = null;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001745 }
1746 }
1747
1748 static final boolean PRINT_ANIM = false;
1749
1750 /** {@inheritDoc} */
Craig Mautner4b71aa12012-12-27 17:20:01 -08001751 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001752 public int selectAnimationLw(WindowState win, int transit) {
1753 if (PRINT_ANIM) Log.i(TAG, "selectAnimation in " + win
1754 + ": transit=" + transit);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001755 if (win == mStatusBar) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08001756 if (transit == TRANSIT_EXIT
1757 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001758 return R.anim.dock_top_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001759 } else if (transit == TRANSIT_ENTER
1760 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001761 return R.anim.dock_top_enter;
1762 }
1763 } else if (win == mNavigationBar) {
1764 // This can be on either the bottom or the right.
1765 if (mNavigationBarOnBottom) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08001766 if (transit == TRANSIT_EXIT
1767 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001768 return R.anim.dock_bottom_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001769 } else if (transit == TRANSIT_ENTER
1770 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001771 return R.anim.dock_bottom_enter;
1772 }
1773 } else {
Craig Mautner4b71aa12012-12-27 17:20:01 -08001774 if (transit == TRANSIT_EXIT
1775 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001776 return R.anim.dock_right_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001777 } else if (transit == TRANSIT_ENTER
1778 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001779 return R.anim.dock_right_enter;
1780 }
1781 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08001782 }
1783
1784 if (transit == TRANSIT_PREVIEW_DONE) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001785 if (win.hasAppShownWindows()) {
1786 if (PRINT_ANIM) Log.i(TAG, "**** STARTING EXIT");
1787 return com.android.internal.R.anim.app_starting_exit;
1788 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07001789 } else if (win.getAttrs().type == TYPE_DREAM && mDreamingLockscreen
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001790 && transit == TRANSIT_ENTER) {
1791 // Special case: we are animating in a dream, while the keyguard
1792 // is shown. We don't want an animation on the dream, because
1793 // we need it shown immediately with the keyguard animating away
1794 // to reveal it.
1795 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001796 }
1797
1798 return 0;
1799 }
1800
Craig Mautner3c174372013-02-21 17:54:37 -08001801 @Override
1802 public void selectRotationAnimationLw(int anim[]) {
1803 if (PRINT_ANIM) Slog.i(TAG, "selectRotationAnimation mTopFullscreen="
1804 + mTopFullscreenOpaqueWindowState + " rotationAnimation="
1805 + (mTopFullscreenOpaqueWindowState == null ?
1806 "0" : mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation));
1807 if (mTopFullscreenOpaqueWindowState != null && mTopIsFullscreen) {
1808 switch (mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation) {
1809 case ROTATION_ANIMATION_CROSSFADE:
1810 anim[0] = R.anim.rotation_animation_xfade_exit;
1811 anim[1] = R.anim.rotation_animation_enter;
1812 break;
1813 case ROTATION_ANIMATION_JUMPCUT:
1814 anim[0] = R.anim.rotation_animation_jump_exit;
1815 anim[1] = R.anim.rotation_animation_enter;
1816 break;
1817 case ROTATION_ANIMATION_ROTATE:
1818 default:
1819 anim[0] = anim[1] = 0;
1820 break;
1821 }
1822 } else {
1823 anim[0] = anim[1] = 0;
1824 }
1825 }
1826
1827 @Override
1828 public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId,
1829 boolean forceDefault) {
1830 switch (exitAnimId) {
1831 case R.anim.rotation_animation_xfade_exit:
1832 case R.anim.rotation_animation_jump_exit:
1833 // These are the only cases that matter.
1834 if (forceDefault) {
1835 return false;
1836 }
1837 int anim[] = new int[2];
1838 selectRotationAnimationLw(anim);
1839 return (exitAnimId == anim[0] && enterAnimId == anim[1]);
1840 default:
1841 return true;
1842 }
1843 }
1844
1845 @Override
Dianne Hackborn0c2acff2012-04-12 15:17:07 -07001846 public Animation createForceHideEnterAnimation(boolean onWallpaper) {
1847 return AnimationUtils.loadAnimation(mContext, onWallpaper
1848 ? com.android.internal.R.anim.lock_screen_wallpaper_behind_enter
1849 : com.android.internal.R.anim.lock_screen_behind_enter);
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07001850 }
John Spurlockc8b46ca2013-04-08 12:59:26 -04001851
1852 private static void awakenDreams() {
1853 IDreamManager dreamManager = getDreamManager();
1854 if (dreamManager != null) {
1855 try {
1856 dreamManager.awaken();
1857 } catch (RemoteException e) {
1858 // fine, stay asleep then
1859 }
1860 }
1861 }
1862
1863 static IDreamManager getDreamManager() {
1864 return IDreamManager.Stub.asInterface(
1865 ServiceManager.checkService(DreamService.DREAM_SERVICE));
1866 }
1867
Jeff Brown4d396052010-10-29 21:50:21 -07001868 static ITelephony getTelephonyService() {
Mike Lockwoodf5f4ec92011-11-08 14:05:31 -08001869 return ITelephony.Stub.asInterface(
Jeff Brown4d396052010-10-29 21:50:21 -07001870 ServiceManager.checkService(Context.TELEPHONY_SERVICE));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001871 }
1872
Jeff Brown4d396052010-10-29 21:50:21 -07001873 static IAudioService getAudioService() {
1874 IAudioService audioService = IAudioService.Stub.asInterface(
1875 ServiceManager.checkService(Context.AUDIO_SERVICE));
1876 if (audioService == null) {
1877 Log.w(TAG, "Unable to find IAudioService interface.");
1878 }
1879 return audioService;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001880 }
1881
1882 boolean keyguardOn() {
1883 return keyguardIsShowingTq() || inKeyguardRestrictedKeyInputMode();
1884 }
1885
1886 private static final int[] WINDOW_TYPES_WHERE_HOME_DOESNT_WORK = {
1887 WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
1888 WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
1889 };
1890
1891 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001892 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001893 public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001894 final boolean keyguardOn = keyguardOn();
Jeff Brown1f245102010-11-18 20:53:46 -08001895 final int keyCode = event.getKeyCode();
1896 final int repeatCount = event.getRepeatCount();
1897 final int metaState = event.getMetaState();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001898 final int flags = event.getFlags();
Jeff Brown1f245102010-11-18 20:53:46 -08001899 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
1900 final boolean canceled = event.isCanceled();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001901
Jeff Brown40013652012-05-16 21:22:36 -07001902 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001903 Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount="
Jeff Brownfd23e3e2012-05-09 13:34:28 -07001904 + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed
1905 + " canceled=" + canceled);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001906 }
1907
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001908 // If we think we might have a volume down & power key chord on the way
1909 // but we're not sure, then tell the dispatcher to wait a little while and
1910 // try again later before dispatching.
Christopher Tatee90585f2012-03-05 18:56:25 -08001911 if (mScreenshotChordEnabled && (flags & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001912 if (mVolumeDownKeyTriggered && !mPowerKeyTriggered) {
1913 final long now = SystemClock.uptimeMillis();
1914 final long timeoutTime = mVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS;
1915 if (now < timeoutTime) {
1916 return timeoutTime - now;
1917 }
1918 }
1919 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
1920 && mVolumeDownKeyConsumedByScreenshotChord) {
1921 if (!down) {
1922 mVolumeDownKeyConsumedByScreenshotChord = false;
1923 }
1924 return -1;
1925 }
1926 }
1927
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001928 // First we always handle the home key here, so applications
1929 // can never break it, although if keyguard is on, we do let
1930 // it handle it, because that gives us the correct 5 second
1931 // timeout.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001932 if (keyCode == KeyEvent.KEYCODE_HOME) {
Michael Jurka7f2668c2012-03-27 07:49:52 -07001933
Jeff Brown49ed71d2010-12-06 17:13:33 -08001934 // If we have released the home key, and didn't do anything else
1935 // while it was pressed, then it is time to go home!
Michael Jurka7f2668c2012-03-27 07:49:52 -07001936 if (!down) {
Jeff Browncaca8812013-05-09 13:34:33 -07001937 cancelPreloadRecentApps();
1938
Jeff Brown49ed71d2010-12-06 17:13:33 -08001939 mHomePressed = false;
Jeff Browncaca8812013-05-09 13:34:33 -07001940 if (mHomeConsumed) {
1941 mHomeConsumed = false;
Michael Jurka7f2668c2012-03-27 07:49:52 -07001942 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08001943 }
Jeff Browncaca8812013-05-09 13:34:33 -07001944
1945 if (canceled) {
1946 Log.i(TAG, "Ignoring HOME; event canceled.");
1947 return -1;
1948 }
1949
1950 // If an incoming call is ringing, HOME is totally disabled.
1951 // (The user is already on the InCallScreen at this point,
1952 // and his ONLY options are to answer or reject the call.)
1953 try {
1954 ITelephony telephonyService = getTelephonyService();
1955 if (telephonyService != null && telephonyService.isRinging()) {
1956 Log.i(TAG, "Ignoring HOME; there's a ringing incoming call.");
1957 return -1;
1958 }
1959 } catch (RemoteException ex) {
1960 Log.w(TAG, "RemoteException from getPhoneInterface()", ex);
1961 }
1962
1963 // Delay handling home if a double-tap is possible.
1964 if (mDoubleTapOnHomeBehavior != DOUBLE_TAP_HOME_NOTHING) {
1965 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); // just in case
1966 mHomeDoubleTapPending = true;
1967 mHandler.postDelayed(mHomeDoubleTapTimeoutRunnable,
1968 ViewConfiguration.getDoubleTapTimeout());
1969 return -1;
1970 }
1971
1972 // Go home!
1973 launchHomeFromHotKey();
1974 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08001975 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001976
1977 // If a system window has focus, then it doesn't make sense
1978 // right now to interact with applications.
1979 WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null;
1980 if (attrs != null) {
1981 final int type = attrs.type;
1982 if (type == WindowManager.LayoutParams.TYPE_KEYGUARD
1983 || type == WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG) {
1984 // the "app" is keyguard, so give it the key
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001985 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001986 }
1987 final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length;
1988 for (int i=0; i<typeCount; i++) {
1989 if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) {
1990 // don't do anything, but also don't pass it to the app
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001991 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001992 }
1993 }
1994 }
Jeff Browncaca8812013-05-09 13:34:33 -07001995
1996 // Remember that home is pressed and handle special actions.
1997 if (repeatCount == 0) {
1998 mHomePressed = true;
1999 if (mHomeDoubleTapPending) {
2000 mHomeDoubleTapPending = false;
2001 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable);
2002 handleDoubleTapOnHome();
2003 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI
2004 || mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
2005 preloadRecentApps();
Michael Jurka7f2668c2012-03-27 07:49:52 -07002006 }
Jeff Browncaca8812013-05-09 13:34:33 -07002007 } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) {
2008 if (!keyguardOn) {
2009 handleLongPressOnHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002010 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002011 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002012 return -1;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002013 } else if (keyCode == KeyEvent.KEYCODE_MENU) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002014 // Hijack modified menu keys for debugging features
2015 final int chordBug = KeyEvent.META_SHIFT_ON;
2016
2017 if (down && repeatCount == 0) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002018 if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002019 Intent intent = new Intent(Intent.ACTION_BUG_REPORT);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002020 mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT,
2021 null, null, null, 0, null, null);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002022 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002023 } else if (SHOW_PROCESSES_ON_ALT_MENU &&
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002024 (metaState & KeyEvent.META_ALT_ON) == KeyEvent.META_ALT_ON) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002025 Intent service = new Intent();
2026 service.setClassName(mContext, "com.android.server.LoadAverageService");
2027 ContentResolver res = mContext.getContentResolver();
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002028 boolean shown = Settings.Global.getInt(
2029 res, Settings.Global.SHOW_PROCESSES, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002030 if (!shown) {
2031 mContext.startService(service);
2032 } else {
2033 mContext.stopService(service);
2034 }
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002035 Settings.Global.putInt(
2036 res, Settings.Global.SHOW_PROCESSES, shown ? 0 : 1);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002037 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002038 }
2039 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002040 } else if (keyCode == KeyEvent.KEYCODE_SEARCH) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002041 if (down) {
2042 if (repeatCount == 0) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002043 mSearchKeyShortcutPending = true;
2044 mConsumeSearchKeyUp = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002045 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002046 } else {
2047 mSearchKeyShortcutPending = false;
2048 if (mConsumeSearchKeyUp) {
2049 mConsumeSearchKeyUp = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002050 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002051 }
2052 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002053 return 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002054 } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) {
Michael Wrightc9ebea72013-01-16 19:25:02 -08002055 if (!keyguardOn) {
Jeff Browncaca8812013-05-09 13:34:33 -07002056 if (down && repeatCount == 0) {
2057 preloadRecentApps();
2058 } else if (!down) {
2059 toggleRecentApps();
Michael Wrightc9ebea72013-01-16 19:25:02 -08002060 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002061 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002062 return -1;
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002063 } else if (keyCode == KeyEvent.KEYCODE_ASSIST) {
2064 if (down) {
2065 if (repeatCount == 0) {
2066 mAssistKeyLongPressed = false;
2067 } else if (repeatCount == 1) {
2068 mAssistKeyLongPressed = true;
2069 if (!keyguardOn) {
2070 launchAssistLongPressAction();
2071 }
2072 }
2073 } else {
2074 if (mAssistKeyLongPressed) {
2075 mAssistKeyLongPressed = false;
2076 } else {
2077 if (!keyguardOn) {
2078 launchAssistAction();
2079 }
2080 }
2081 }
2082 return -1;
Jeff Sharkey2991fa32012-12-05 18:06:43 -08002083 } else if (keyCode == KeyEvent.KEYCODE_SYSRQ) {
2084 if (down && repeatCount == 0) {
2085 mHandler.post(mScreenshotRunnable);
2086 }
2087 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002088 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002089
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002090 // Shortcuts are invoked through Search+key, so intercept those here
Jeff Browncaab4d02010-12-09 22:13:41 -08002091 // Any printing key that is chorded with Search should be consumed
2092 // even if no shortcut was invoked. This prevents text from being
2093 // inadvertently inserted when using a keyboard that has built-in macro
2094 // shortcut keys (that emit Search+x) and some of them are not registered.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002095 if (mSearchKeyShortcutPending) {
Jeff Browncaab4d02010-12-09 22:13:41 -08002096 final KeyCharacterMap kcm = event.getKeyCharacterMap();
2097 if (kcm.isPrintingKey(keyCode)) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002098 mConsumeSearchKeyUp = true;
2099 mSearchKeyShortcutPending = false;
Jeff Browncaab4d02010-12-09 22:13:41 -08002100 if (down && repeatCount == 0 && !keyguardOn) {
2101 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState);
2102 if (shortcutIntent != null) {
2103 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002104 try {
2105 mContext.startActivity(shortcutIntent);
2106 } catch (ActivityNotFoundException ex) {
2107 Slog.w(TAG, "Dropping shortcut key combination because "
2108 + "the activity to which it is registered was not found: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002109 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode), ex);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002110 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002111 } else {
2112 Slog.i(TAG, "Dropping unregistered shortcut key combination: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002113 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002114 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002115 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002116 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002117 }
2118 }
2119
Jeff Brown68b909d2011-12-07 16:36:01 -08002120 // Invoke shortcuts using Meta.
Jeff Brown602ab322012-05-16 13:33:47 -07002121 if (down && repeatCount == 0 && !keyguardOn
Jeff Brown68b909d2011-12-07 16:36:01 -08002122 && (metaState & KeyEvent.META_META_ON) != 0) {
2123 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brown602ab322012-05-16 13:33:47 -07002124 if (kcm.isPrintingKey(keyCode)) {
2125 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode,
2126 metaState & ~(KeyEvent.META_META_ON
2127 | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON));
2128 if (shortcutIntent != null) {
2129 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2130 try {
2131 mContext.startActivity(shortcutIntent);
2132 } catch (ActivityNotFoundException ex) {
2133 Slog.w(TAG, "Dropping shortcut key combination because "
2134 + "the activity to which it is registered was not found: "
2135 + "META+" + KeyEvent.keyCodeToString(keyCode), ex);
2136 }
2137 return -1;
Jeff Brown68b909d2011-12-07 16:36:01 -08002138 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002139 }
2140 }
2141
Jeff Brown6651a632011-11-28 12:59:11 -08002142 // Handle application launch keys.
Jeff Brown602ab322012-05-16 13:33:47 -07002143 if (down && repeatCount == 0 && !keyguardOn) {
Jeff Brown6651a632011-11-28 12:59:11 -08002144 String category = sApplicationLaunchKeyCategories.get(keyCode);
2145 if (category != null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -08002146 Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category);
Jeff Brown6651a632011-11-28 12:59:11 -08002147 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2148 try {
2149 mContext.startActivity(intent);
2150 } catch (ActivityNotFoundException ex) {
2151 Slog.w(TAG, "Dropping application launch key because "
2152 + "the activity to which it is registered was not found: "
2153 + "keyCode=" + keyCode + ", category=" + category, ex);
2154 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002155 return -1;
Jeff Brown6651a632011-11-28 12:59:11 -08002156 }
2157 }
2158
Jeff Brown68b909d2011-12-07 16:36:01 -08002159 // Display task switcher for ALT-TAB or Meta-TAB.
2160 if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_TAB) {
Jeff Brown602ab322012-05-16 13:33:47 -07002161 if (mRecentAppsDialogHeldModifiers == 0 && !keyguardOn) {
Jeff Brown68b909d2011-12-07 16:36:01 -08002162 final int shiftlessModifiers = event.getModifiers() & ~KeyEvent.META_SHIFT_MASK;
2163 if (KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_ALT_ON)
2164 || KeyEvent.metaStateHasModifiers(
2165 shiftlessModifiers, KeyEvent.META_META_ON)) {
2166 mRecentAppsDialogHeldModifiers = shiftlessModifiers;
2167 showOrHideRecentAppsDialog(RECENT_APPS_BEHAVIOR_EXIT_TOUCH_MODE_AND_SHOW);
2168 return -1;
2169 }
2170 }
2171 } else if (!down && mRecentAppsDialogHeldModifiers != 0
2172 && (metaState & mRecentAppsDialogHeldModifiers) == 0) {
2173 mRecentAppsDialogHeldModifiers = 0;
Jeff Brown602ab322012-05-16 13:33:47 -07002174 showOrHideRecentAppsDialog(keyguardOn ? RECENT_APPS_BEHAVIOR_DISMISS :
2175 RECENT_APPS_BEHAVIOR_DISMISS_AND_SWITCH);
Jeff Brown68b909d2011-12-07 16:36:01 -08002176 }
2177
Jeff Browncf39bdf2012-05-18 14:41:19 -07002178 // Handle keyboard language switching.
2179 if (down && repeatCount == 0
2180 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2181 || (keyCode == KeyEvent.KEYCODE_SPACE
2182 && (metaState & KeyEvent.META_CTRL_MASK) != 0))) {
2183 int direction = (metaState & KeyEvent.META_SHIFT_MASK) != 0 ? -1 : 1;
2184 mWindowManagerFuncs.switchKeyboardLayout(event.getDeviceId(), direction);
2185 return -1;
2186 }
2187 if (mLanguageSwitchKeyPressed && !down
2188 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2189 || keyCode == KeyEvent.KEYCODE_SPACE)) {
2190 mLanguageSwitchKeyPressed = false;
2191 return -1;
2192 }
2193
Justin Kohd378ad72013-04-01 12:18:26 -07002194 if (mGlobalKeyManager.handleGlobalKey(mContext, keyCode, event)) {
2195 return -1;
2196 }
2197
Jeff Brown68b909d2011-12-07 16:36:01 -08002198 // Let the application handle the key.
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002199 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002200 }
2201
Jeff Brown3915bb82010-11-05 15:02:16 -07002202 /** {@inheritDoc} */
2203 @Override
Jeff Brown49ed71d2010-12-06 17:13:33 -08002204 public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown54875002011-04-06 15:33:01 -07002205 // Note: This method is only called if the initial down was unhandled.
Jeff Brown40013652012-05-16 21:22:36 -07002206 if (DEBUG_INPUT) {
Jeff Brown1f245102010-11-18 20:53:46 -08002207 Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction()
2208 + ", flags=" + event.getFlags()
2209 + ", keyCode=" + event.getKeyCode()
2210 + ", scanCode=" + event.getScanCode()
2211 + ", metaState=" + event.getMetaState()
2212 + ", repeatCount=" + event.getRepeatCount()
2213 + ", policyFlags=" + policyFlags);
Jeff Brown3915bb82010-11-05 15:02:16 -07002214 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002215
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002216 KeyEvent fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002217 if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
2218 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002219 final int keyCode = event.getKeyCode();
2220 final int metaState = event.getMetaState();
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002221 final boolean initialDown = event.getAction() == KeyEvent.ACTION_DOWN
2222 && event.getRepeatCount() == 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002223
Jeff Brown54875002011-04-06 15:33:01 -07002224 // Check for fallback actions specified by the key character map.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002225 final FallbackAction fallbackAction;
2226 if (initialDown) {
2227 fallbackAction = kcm.getFallbackAction(keyCode, metaState);
2228 } else {
2229 fallbackAction = mFallbackActions.get(keyCode);
2230 }
2231
2232 if (fallbackAction != null) {
Jeff Brown40013652012-05-16 21:22:36 -07002233 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002234 Slog.d(TAG, "Fallback: keyCode=" + fallbackAction.keyCode
2235 + " metaState=" + Integer.toHexString(fallbackAction.metaState));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002236 }
2237
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002238 final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK;
2239 fallbackEvent = KeyEvent.obtain(
Jeff Brown49ed71d2010-12-06 17:13:33 -08002240 event.getDownTime(), event.getEventTime(),
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002241 event.getAction(), fallbackAction.keyCode,
2242 event.getRepeatCount(), fallbackAction.metaState,
Jeff Brown49ed71d2010-12-06 17:13:33 -08002243 event.getDeviceId(), event.getScanCode(),
2244 flags, event.getSource(), null);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002245
2246 if (!interceptFallback(win, fallbackEvent, policyFlags)) {
2247 fallbackEvent.recycle();
2248 fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002249 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002250
2251 if (initialDown) {
2252 mFallbackActions.put(keyCode, fallbackAction);
2253 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2254 mFallbackActions.remove(keyCode);
2255 fallbackAction.recycle();
2256 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002257 }
2258 }
2259
Jeff Brown40013652012-05-16 21:22:36 -07002260 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002261 if (fallbackEvent == null) {
2262 Slog.d(TAG, "No fallback.");
2263 } else {
2264 Slog.d(TAG, "Performing fallback: " + fallbackEvent);
2265 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002266 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002267 return fallbackEvent;
Jeff Brown3915bb82010-11-05 15:02:16 -07002268 }
2269
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002270 private boolean interceptFallback(WindowState win, KeyEvent fallbackEvent, int policyFlags) {
2271 int actions = interceptKeyBeforeQueueing(fallbackEvent, policyFlags, true);
2272 if ((actions & ACTION_PASS_TO_USER) != 0) {
2273 long delayMillis = interceptKeyBeforeDispatching(
2274 win, fallbackEvent, policyFlags);
2275 if (delayMillis == 0) {
2276 return true;
2277 }
2278 }
2279 return false;
Jeff Brown6f2fba42011-02-19 01:08:02 -08002280 }
2281
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002282 private void launchAssistLongPressAction() {
2283 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
2284 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
2285
2286 // launch the search activity
2287 Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS);
2288 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2289 try {
Jim Miller45308b12012-06-18 19:23:39 -07002290 // TODO: This only stops the factory-installed search manager.
2291 // Need to formalize an API to handle others
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002292 SearchManager searchManager = getSearchManager();
2293 if (searchManager != null) {
2294 searchManager.stopSearch();
2295 }
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07002296 mContext.startActivityAsUser(intent, new UserHandle(UserHandle.USER_CURRENT));
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002297 } catch (ActivityNotFoundException e) {
2298 Slog.w(TAG, "No activity to handle assist long press action.", e);
2299 }
2300 }
2301
2302 private void launchAssistAction() {
2303 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
Amith Yamasanic1d07a42012-08-14 09:32:02 -07002304 Intent intent = ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE))
Dianne Hackbornf9c5e0f2013-01-23 14:39:13 -08002305 .getAssistIntent(mContext, true, UserHandle.USER_CURRENT);
Jim Miller45308b12012-06-18 19:23:39 -07002306 if (intent != null) {
2307 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
2308 | Intent.FLAG_ACTIVITY_SINGLE_TOP
2309 | Intent.FLAG_ACTIVITY_CLEAR_TOP);
2310 try {
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07002311 mContext.startActivityAsUser(intent, new UserHandle(UserHandle.USER_CURRENT));
Jim Miller45308b12012-06-18 19:23:39 -07002312 } catch (ActivityNotFoundException e) {
2313 Slog.w(TAG, "No activity to handle assist action.", e);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002314 }
2315 }
2316 }
2317
2318 private SearchManager getSearchManager() {
2319 if (mSearchManager == null) {
2320 mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
2321 }
2322 return mSearchManager;
2323 }
2324
Jeff Browncaca8812013-05-09 13:34:33 -07002325 private void preloadRecentApps() {
2326 mPreloadedRecentApps = true;
2327 try {
2328 IStatusBarService statusbar = getStatusBarService();
2329 if (statusbar != null) {
2330 statusbar.preloadRecentApps();
2331 }
2332 } catch (RemoteException e) {
2333 Slog.e(TAG, "RemoteException when preloading recent apps", e);
2334 // re-acquire status bar service next time it is needed.
2335 mStatusBarService = null;
2336 }
2337 }
2338
2339 private void cancelPreloadRecentApps() {
2340 if (mPreloadedRecentApps) {
2341 mPreloadedRecentApps = false;
2342 try {
2343 IStatusBarService statusbar = getStatusBarService();
2344 if (statusbar != null) {
2345 statusbar.cancelPreloadRecentApps();
2346 }
2347 } catch (RemoteException e) {
2348 Slog.e(TAG, "RemoteException when showing recent apps", e);
2349 // re-acquire status bar service next time it is needed.
2350 mStatusBarService = null;
2351 }
2352 }
2353 }
2354
2355 private void toggleRecentApps() {
2356 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
2357 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_RECENT_APPS);
2358 try {
2359 IStatusBarService statusbar = getStatusBarService();
2360 if (statusbar != null) {
2361 statusbar.toggleRecentApps();
2362 }
2363 } catch (RemoteException e) {
2364 Slog.e(TAG, "RemoteException when showing recent apps", e);
2365 // re-acquire status bar service next time it is needed.
2366 mStatusBarService = null;
2367 }
2368 }
2369
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002370 /**
2371 * A home key -> launch home action was detected. Take the appropriate action
2372 * given the situation with the keyguard.
2373 */
2374 void launchHomeFromHotKey() {
Mike Lockwood3a74bd32011-08-12 13:55:22 -07002375 if (mKeyguardMediator != null && mKeyguardMediator.isShowingAndNotHidden()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002376 // don't launch home if keyguard showing
Dianne Hackborn39c2d712009-09-22 11:41:31 -07002377 } else if (!mHideLockScreen && mKeyguardMediator.isInputRestricted()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002378 // when in keyguard restricted mode, must first verify unlock
2379 // before launching home
2380 mKeyguardMediator.verifyUnlock(new OnKeyguardExitResult() {
2381 public void onKeyguardExitResult(boolean success) {
2382 if (success) {
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07002383 try {
2384 ActivityManagerNative.getDefault().stopAppSwitches();
2385 } catch (RemoteException e) {
2386 }
Joe Onoratof275f0c2009-11-24 16:11:13 -05002387 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07002388 startDockOrHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002389 }
2390 }
2391 });
2392 } else {
2393 // no keyguard stuff to worry about, just launch home!
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07002394 try {
2395 ActivityManagerNative.getDefault().stopAppSwitches();
2396 } catch (RemoteException e) {
2397 }
Joe Onoratof275f0c2009-11-24 16:11:13 -05002398 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07002399 startDockOrHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002400 }
2401 }
2402
Dianne Hackborne26ab702011-10-16 13:21:33 -07002403 /**
2404 * A delayed callback use to determine when it is okay to re-allow applications
2405 * to use certain system UI flags. This is used to prevent applications from
2406 * spamming system UI changes that prevent the navigation bar from being shown.
2407 */
2408 final Runnable mAllowSystemUiDelay = new Runnable() {
2409 @Override public void run() {
2410 }
2411 };
2412
2413 /**
2414 * Input handler used while nav bar is hidden. Captures any touch on the screen,
2415 * to determine when the nav bar should be shown and prevent applications from
2416 * receiving those touches.
2417 */
Jeff Brown32cbc38552011-12-01 14:01:49 -08002418 final class HideNavInputEventReceiver extends InputEventReceiver {
2419 public HideNavInputEventReceiver(InputChannel inputChannel, Looper looper) {
2420 super(inputChannel, looper);
2421 }
2422
Dianne Hackborndf89e652011-10-06 22:35:11 -07002423 @Override
Jeff Brown32cbc38552011-12-01 14:01:49 -08002424 public void onInputEvent(InputEvent event) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07002425 boolean handled = false;
2426 try {
Jeff Brown4952dfd2011-11-30 19:23:22 -08002427 if (event instanceof MotionEvent
2428 && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
2429 final MotionEvent motionEvent = (MotionEvent)event;
2430 if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07002431 // When the user taps down, we re-show the nav bar.
2432 boolean changed = false;
2433 synchronized (mLock) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002434 // Any user activity always causes us to show the
2435 // navigation controls, if they had been hidden.
2436 // We also clear the low profile and only content
2437 // flags so that tapping on the screen will atomically
2438 // restore all currently hidden screen decorations.
2439 int newVal = mResettingSystemUiFlags |
2440 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
2441 View.SYSTEM_UI_FLAG_LOW_PROFILE |
2442 View.SYSTEM_UI_FLAG_FULLSCREEN;
Dianne Hackborne26ab702011-10-16 13:21:33 -07002443 if (mResettingSystemUiFlags != newVal) {
2444 mResettingSystemUiFlags = newVal;
Dianne Hackborndf89e652011-10-06 22:35:11 -07002445 changed = true;
2446 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07002447 // We don't allow the system's nav bar to be hidden
2448 // again for 1 second, to prevent applications from
2449 // spamming us and keeping it from being shown.
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002450 newVal = mForceClearedSystemUiFlags |
2451 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
Dianne Hackborne26ab702011-10-16 13:21:33 -07002452 if (mForceClearedSystemUiFlags != newVal) {
2453 mForceClearedSystemUiFlags = newVal;
2454 changed = true;
2455 mHandler.postDelayed(new Runnable() {
2456 @Override public void run() {
2457 synchronized (mLock) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002458 // Clear flags.
Dianne Hackborne26ab702011-10-16 13:21:33 -07002459 mForceClearedSystemUiFlags &=
2460 ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
2461 }
2462 mWindowManagerFuncs.reevaluateStatusBarVisibility();
2463 }
2464 }, 1000);
2465 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07002466 }
2467 if (changed) {
2468 mWindowManagerFuncs.reevaluateStatusBarVisibility();
2469 }
2470 }
2471 }
2472 } finally {
Jeff Brown32cbc38552011-12-01 14:01:49 -08002473 finishInputEvent(event, handled);
Dianne Hackborndf89e652011-10-06 22:35:11 -07002474 }
2475 }
Jeff Brown32cbc38552011-12-01 14:01:49 -08002476 }
2477 final InputEventReceiver.Factory mHideNavInputEventReceiverFactory =
2478 new InputEventReceiver.Factory() {
2479 @Override
2480 public InputEventReceiver createInputEventReceiver(
2481 InputChannel inputChannel, Looper looper) {
2482 return new HideNavInputEventReceiver(inputChannel, looper);
2483 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07002484 };
2485
2486 @Override
2487 public int adjustSystemUiVisibilityLw(int visibility) {
2488 // Reset any bits in mForceClearingStatusBarVisibility that
2489 // are now clear.
Dianne Hackborne26ab702011-10-16 13:21:33 -07002490 mResettingSystemUiFlags &= visibility;
Dianne Hackborndf89e652011-10-06 22:35:11 -07002491 // Clear any bits in the new visibility that are currently being
2492 // force cleared, before reporting it.
Dianne Hackborne26ab702011-10-16 13:21:33 -07002493 return visibility & ~mResettingSystemUiFlags
2494 & ~mForceClearedSystemUiFlags;
Dianne Hackborndf89e652011-10-06 22:35:11 -07002495 }
2496
Craig Mautner69b08182012-09-05 13:07:13 -07002497 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002498 public void getContentInsetHintLw(WindowManager.LayoutParams attrs, Rect contentInset) {
2499 final int fl = attrs.flags;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002500 final int systemUiVisibility = (attrs.systemUiVisibility|attrs.subtreeSystemUiVisibility);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002501
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002502 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002503 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002504 int availRight, availBottom;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002505 if (mCanHideNavigationBar &&
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002506 (systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002507 availRight = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
2508 availBottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
2509 } else {
2510 availRight = mRestrictedScreenLeft + mRestrictedScreenWidth;
2511 availBottom = mRestrictedScreenTop + mRestrictedScreenHeight;
2512 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002513 if ((systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
2514 if ((fl & FLAG_FULLSCREEN) != 0) {
2515 contentInset.set(mStableFullscreenLeft, mStableFullscreenTop,
2516 availRight - mStableFullscreenRight,
2517 availBottom - mStableFullscreenBottom);
2518 } else {
2519 contentInset.set(mStableLeft, mStableTop,
2520 availRight - mStableRight, availBottom - mStableBottom);
2521 }
Dianne Hackbornc652de82013-02-15 16:32:56 -08002522 } else if ((fl & FLAG_FULLSCREEN) != 0 || (fl & FLAG_LAYOUT_IN_OVERSCAN) != 0) {
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002523 contentInset.setEmpty();
2524 } else if ((systemUiVisibility & (View.SYSTEM_UI_FLAG_FULLSCREEN
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002525 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)) == 0) {
2526 contentInset.set(mCurLeft, mCurTop,
2527 availRight - mCurRight, availBottom - mCurBottom);
2528 } else {
2529 contentInset.set(mCurLeft, mCurTop,
2530 availRight - mCurRight, availBottom - mCurBottom);
2531 }
2532 return;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002533 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002534 contentInset.setEmpty();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002535 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002536
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002537 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07002538 @Override
2539 public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight,
2540 int displayRotation) {
Dianne Hackbornc652de82013-02-15 16:32:56 -08002541 final int overscanLeft, overscanTop, overscanRight, overscanBottom;
2542 if (isDefaultDisplay) {
2543 switch (displayRotation) {
2544 case Surface.ROTATION_90:
2545 overscanLeft = mOverscanTop;
2546 overscanTop = mOverscanRight;
2547 overscanRight = mOverscanBottom;
2548 overscanBottom = mOverscanLeft;
2549 break;
2550 case Surface.ROTATION_180:
2551 overscanLeft = mOverscanRight;
2552 overscanTop = mOverscanBottom;
2553 overscanRight = mOverscanLeft;
2554 overscanBottom = mOverscanTop;
2555 break;
2556 case Surface.ROTATION_270:
2557 overscanLeft = mOverscanBottom;
2558 overscanTop = mOverscanLeft;
2559 overscanRight = mOverscanTop;
2560 overscanBottom = mOverscanRight;
2561 break;
2562 default:
2563 overscanLeft = mOverscanLeft;
2564 overscanTop = mOverscanTop;
2565 overscanRight = mOverscanRight;
2566 overscanBottom = mOverscanBottom;
2567 break;
2568 }
2569 } else {
2570 overscanLeft = 0;
2571 overscanTop = 0;
2572 overscanRight = 0;
2573 overscanBottom = 0;
2574 }
Dianne Hackborn313440842013-02-19 19:22:59 -08002575 mOverscanScreenLeft = mRestrictedOverscanScreenLeft = 0;
2576 mOverscanScreenTop = mRestrictedOverscanScreenTop = 0;
2577 mOverscanScreenWidth = mRestrictedOverscanScreenWidth = displayWidth;
2578 mOverscanScreenHeight = mRestrictedOverscanScreenHeight = displayHeight;
Dianne Hackbornc652de82013-02-15 16:32:56 -08002579 mSystemLeft = 0;
2580 mSystemTop = 0;
2581 mSystemRight = displayWidth;
2582 mSystemBottom = displayHeight;
2583 mUnrestrictedScreenLeft = overscanLeft;
2584 mUnrestrictedScreenTop = overscanTop;
2585 mUnrestrictedScreenWidth = displayWidth - overscanLeft - overscanRight;
2586 mUnrestrictedScreenHeight = displayHeight - overscanTop - overscanBottom;
2587 mRestrictedScreenLeft = mUnrestrictedScreenLeft;
2588 mRestrictedScreenTop = mUnrestrictedScreenTop;
2589 mRestrictedScreenWidth = mUnrestrictedScreenWidth;
2590 mRestrictedScreenHeight = mUnrestrictedScreenHeight;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002591 mDockLeft = mContentLeft = mStableLeft = mStableFullscreenLeft
Dianne Hackbornc652de82013-02-15 16:32:56 -08002592 = mCurLeft = mUnrestrictedScreenLeft;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002593 mDockTop = mContentTop = mStableTop = mStableFullscreenTop
Dianne Hackbornc652de82013-02-15 16:32:56 -08002594 = mCurTop = mUnrestrictedScreenTop;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002595 mDockRight = mContentRight = mStableRight = mStableFullscreenRight
Dianne Hackbornc652de82013-02-15 16:32:56 -08002596 = mCurRight = displayWidth - overscanRight;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002597 mDockBottom = mContentBottom = mStableBottom = mStableFullscreenBottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08002598 = mCurBottom = displayHeight - overscanBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002599 mDockLayer = 0x10000000;
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002600 mStatusBarLayer = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002601
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002602 // start with the current dock rect, which will be (0,0,displayWidth,displayHeight)
2603 final Rect pf = mTmpParentFrame;
2604 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002605 final Rect of = mTmpOverscanFrame;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002606 final Rect vf = mTmpVisibleFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002607 pf.left = df.left = of.left = vf.left = mDockLeft;
2608 pf.top = df.top = of.top = vf.top = mDockTop;
2609 pf.right = df.right = of.right = vf.right = mDockRight;
2610 pf.bottom = df.bottom = of.bottom = vf.bottom = mDockBottom;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002611
Craig Mautner69b08182012-09-05 13:07:13 -07002612 if (isDefaultDisplay) {
2613 // For purposes of putting out fake window up to steal focus, we will
2614 // drive nav being hidden only by whether it is requested.
2615 boolean navVisible = (mLastSystemUiFlags&View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0;
Dianne Hackborne26ab702011-10-16 13:21:33 -07002616
Craig Mautner69b08182012-09-05 13:07:13 -07002617 // When the navigation bar isn't visible, we put up a fake
2618 // input window to catch all touch events. This way we can
2619 // detect when the user presses anywhere to bring back the nav
2620 // bar and ensure the application doesn't see the event.
2621 if (navVisible) {
2622 if (mHideNavFakeWindow != null) {
2623 mHideNavFakeWindow.dismiss();
2624 mHideNavFakeWindow = null;
2625 }
2626 } else if (mHideNavFakeWindow == null) {
2627 mHideNavFakeWindow = mWindowManagerFuncs.addFakeWindow(
2628 mHandler.getLooper(), mHideNavInputEventReceiverFactory,
2629 "hidden nav", WindowManager.LayoutParams.TYPE_HIDDEN_NAV_CONSUMER,
2630 0, false, false, true);
Dianne Hackborne26ab702011-10-16 13:21:33 -07002631 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07002632
Craig Mautner69b08182012-09-05 13:07:13 -07002633 // For purposes of positioning and showing the nav bar, if we have
2634 // decided that it can't be hidden (because of the screen aspect ratio),
2635 // then take that into account.
2636 navVisible |= !mCanHideNavigationBar;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002637
Craig Mautner69b08182012-09-05 13:07:13 -07002638 if (mNavigationBar != null) {
2639 // Force the navigation bar to its appropriate place and
2640 // size. We need to do this directly, instead of relying on
2641 // it to bubble up from the nav bar, because this needs to
2642 // change atomically with screen rotations.
2643 mNavigationBarOnBottom = (!mNavigationBarCanMove || displayWidth < displayHeight);
2644 if (mNavigationBarOnBottom) {
2645 // It's a system nav bar or a portrait screen; nav bar goes on bottom.
Dianne Hackbornc652de82013-02-15 16:32:56 -08002646 int top = displayHeight - overscanBottom
2647 - mNavigationBarHeightForRotation[displayRotation];
2648 mTmpNavigationFrame.set(0, top, displayWidth, displayHeight - overscanBottom);
Craig Mautner69b08182012-09-05 13:07:13 -07002649 mStableBottom = mStableFullscreenBottom = mTmpNavigationFrame.top;
2650 if (navVisible) {
2651 mNavigationBar.showLw(true);
2652 mDockBottom = mTmpNavigationFrame.top;
Dianne Hackborn313440842013-02-19 19:22:59 -08002653 mRestrictedScreenHeight = mDockBottom - mRestrictedScreenTop;
2654 mRestrictedOverscanScreenHeight = mDockBottom - mRestrictedOverscanScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07002655 } else {
2656 // We currently want to hide the navigation UI.
2657 mNavigationBar.hideLw(true);
2658 }
2659 if (navVisible && !mNavigationBar.isAnimatingLw()) {
2660 // If the nav bar is currently requested to be visible,
2661 // and not in the process of animating on or off, then
2662 // we can tell the app that it is covered by it.
2663 mSystemBottom = mTmpNavigationFrame.top;
2664 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002665 } else {
Craig Mautner69b08182012-09-05 13:07:13 -07002666 // Landscape screen; nav bar goes to the right.
Dianne Hackbornc652de82013-02-15 16:32:56 -08002667 int left = displayWidth - overscanRight
2668 - mNavigationBarWidthForRotation[displayRotation];
2669 mTmpNavigationFrame.set(left, 0, displayWidth - overscanRight, displayHeight);
Craig Mautner69b08182012-09-05 13:07:13 -07002670 mStableRight = mStableFullscreenRight = mTmpNavigationFrame.left;
2671 if (navVisible) {
2672 mNavigationBar.showLw(true);
2673 mDockRight = mTmpNavigationFrame.left;
Dianne Hackborn313440842013-02-19 19:22:59 -08002674 mRestrictedScreenWidth = mDockRight - mRestrictedScreenLeft;
2675 mRestrictedOverscanScreenWidth = mDockRight - mRestrictedOverscanScreenLeft;
Craig Mautner69b08182012-09-05 13:07:13 -07002676 } else {
2677 // We currently want to hide the navigation UI.
2678 mNavigationBar.hideLw(true);
2679 }
2680 if (navVisible && !mNavigationBar.isAnimatingLw()) {
2681 // If the nav bar is currently requested to be visible,
2682 // and not in the process of animating on or off, then
2683 // we can tell the app that it is covered by it.
2684 mSystemRight = mTmpNavigationFrame.left;
2685 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002686 }
Craig Mautner69b08182012-09-05 13:07:13 -07002687 // Make sure the content and current rectangles are updated to
2688 // account for the restrictions from the navigation bar.
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002689 mContentTop = mCurTop = mDockTop;
2690 mContentBottom = mCurBottom = mDockBottom;
2691 mContentLeft = mCurLeft = mDockLeft;
2692 mContentRight = mCurRight = mDockRight;
Craig Mautner69b08182012-09-05 13:07:13 -07002693 mStatusBarLayer = mNavigationBar.getSurfaceLayer();
2694 // And compute the final frame.
2695 mNavigationBar.computeFrameLw(mTmpNavigationFrame, mTmpNavigationFrame,
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002696 mTmpNavigationFrame, mTmpNavigationFrame, mTmpNavigationFrame);
Craig Mautner69b08182012-09-05 13:07:13 -07002697 if (DEBUG_LAYOUT) Log.i(TAG, "mNavigationBar frame: " + mTmpNavigationFrame);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002698 }
Craig Mautner69b08182012-09-05 13:07:13 -07002699 if (DEBUG_LAYOUT) Log.i(TAG, String.format("mDock rect: (%d,%d - %d,%d)",
2700 mDockLeft, mDockTop, mDockRight, mDockBottom));
2701
2702 // decide where the status bar goes ahead of time
2703 if (mStatusBar != null) {
2704 // apply any navigation bar insets
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002705 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
2706 pf.top = df.top = of.top = mUnrestrictedScreenTop;
2707 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
2708 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight
2709 + mUnrestrictedScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07002710 vf.left = mStableLeft;
2711 vf.top = mStableTop;
2712 vf.right = mStableRight;
2713 vf.bottom = mStableBottom;
2714
2715 mStatusBarLayer = mStatusBar.getSurfaceLayer();
2716
2717 // Let the status bar determine its size.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002718 mStatusBar.computeFrameLw(pf, df, vf, vf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07002719
2720 // For layout, the status bar is always at the top with our fixed height.
2721 mStableTop = mUnrestrictedScreenTop + mStatusBarHeight;
2722
2723 // If the status bar is hidden, we don't want to cause
2724 // windows behind it to scroll.
2725 if (mStatusBar.isVisibleLw()) {
2726 // Status bar may go away, so the screen area it occupies
2727 // is available to apps but just covering them when the
2728 // status bar is visible.
2729 mDockTop = mUnrestrictedScreenTop + mStatusBarHeight;
2730
2731 mContentTop = mCurTop = mDockTop;
2732 mContentBottom = mCurBottom = mDockBottom;
2733 mContentLeft = mCurLeft = mDockLeft;
2734 mContentRight = mCurRight = mDockRight;
2735
2736 if (DEBUG_LAYOUT) Log.v(TAG, "Status bar: " +
2737 String.format(
2738 "dock=[%d,%d][%d,%d] content=[%d,%d][%d,%d] cur=[%d,%d][%d,%d]",
2739 mDockLeft, mDockTop, mDockRight, mDockBottom,
2740 mContentLeft, mContentTop, mContentRight, mContentBottom,
2741 mCurLeft, mCurTop, mCurRight, mCurBottom));
2742 }
2743 if (mStatusBar.isVisibleLw() && !mStatusBar.isAnimatingLw()) {
2744 // If the status bar is currently requested to be visible,
2745 // and not in the process of animating on or off, then
2746 // we can tell the app that it is covered by it.
2747 mSystemTop = mUnrestrictedScreenTop + mStatusBarHeight;
2748 }
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002749 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002750 }
2751 }
2752
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07002753 /** {@inheritDoc} */
2754 public int getSystemDecorRectLw(Rect systemRect) {
2755 systemRect.left = mSystemLeft;
2756 systemRect.top = mSystemTop;
2757 systemRect.right = mSystemRight;
2758 systemRect.bottom = mSystemBottom;
2759 if (mStatusBar != null) return mStatusBar.getSurfaceLayer();
2760 if (mNavigationBar != null) return mNavigationBar.getSurfaceLayer();
2761 return 0;
2762 }
2763
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002764 void setAttachedWindowFrames(WindowState win, int fl, int adjust, WindowState attached,
2765 boolean insetDecors, Rect pf, Rect df, Rect of, Rect cf, Rect vf) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002766 if (win.getSurfaceLayer() > mDockLayer && attached.getSurfaceLayer() < mDockLayer) {
2767 // Here's a special case: if this attached window is a panel that is
2768 // above the dock window, and the window it is attached to is below
2769 // the dock window, then the frames we computed for the window it is
2770 // attached to can not be used because the dock is effectively part
2771 // of the underlying window and the attached window is floating on top
2772 // of the whole thing. So, we ignore the attached window and explicitly
2773 // compute the frames that would be appropriate without the dock.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002774 df.left = of.left = cf.left = vf.left = mDockLeft;
2775 df.top = of.top = cf.top = vf.top = mDockTop;
2776 df.right = of.right = cf.right = vf.right = mDockRight;
2777 df.bottom = of.bottom = cf.bottom = vf.bottom = mDockBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002778 } else {
2779 // The effective display frame of the attached window depends on
2780 // whether it is taking care of insetting its content. If not,
2781 // we need to use the parent's content frame so that the entire
2782 // window is positioned within that content. Otherwise we can use
2783 // the display frame and let the attached window take care of
2784 // positioning its content appropriately.
Dianne Hackborndea3ef72010-10-28 14:24:22 -07002785 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002786 cf.set(attached.getOverscanFrameLw());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002787 } else {
2788 // If the window is resizing, then we want to base the content
2789 // frame on our attached content frame to resize... however,
2790 // things can be tricky if the attached window is NOT in resize
2791 // mode, in which case its content frame will be larger.
2792 // Ungh. So to deal with that, make sure the content frame
2793 // we end up using is not covering the IM dock.
2794 cf.set(attached.getContentFrameLw());
2795 if (attached.getSurfaceLayer() < mDockLayer) {
2796 if (cf.left < mContentLeft) cf.left = mContentLeft;
2797 if (cf.top < mContentTop) cf.top = mContentTop;
2798 if (cf.right > mContentRight) cf.right = mContentRight;
2799 if (cf.bottom > mContentBottom) cf.bottom = mContentBottom;
2800 }
2801 }
2802 df.set(insetDecors ? attached.getDisplayFrameLw() : cf);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002803 of.set(insetDecors ? attached.getOverscanFrameLw() : cf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002804 vf.set(attached.getVisibleFrameLw());
2805 }
2806 // The LAYOUT_IN_SCREEN flag is used to determine whether the attached
2807 // window should be positioned relative to its parent or the entire
2808 // screen.
2809 pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0
2810 ? attached.getFrameLw() : df);
2811 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002812
2813 private void applyStableConstraints(int sysui, int fl, Rect r) {
2814 if ((sysui & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
2815 // If app is requesting a stable layout, don't let the
2816 // content insets go below the stable values.
2817 if ((fl & FLAG_FULLSCREEN) != 0) {
2818 if (r.left < mStableFullscreenLeft) r.left = mStableFullscreenLeft;
2819 if (r.top < mStableFullscreenTop) r.top = mStableFullscreenTop;
2820 if (r.right > mStableFullscreenRight) r.right = mStableFullscreenRight;
2821 if (r.bottom > mStableFullscreenBottom) r.bottom = mStableFullscreenBottom;
2822 } else {
2823 if (r.left < mStableLeft) r.left = mStableLeft;
2824 if (r.top < mStableTop) r.top = mStableTop;
2825 if (r.right > mStableRight) r.right = mStableRight;
2826 if (r.bottom > mStableBottom) r.bottom = mStableBottom;
2827 }
2828 }
2829 }
2830
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002831 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07002832 @Override
Dianne Hackborn0ecadf72009-03-31 18:00:37 -07002833 public void layoutWindowLw(WindowState win, WindowManager.LayoutParams attrs,
2834 WindowState attached) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002835 // we've already done the status bar
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002836 if (win == mStatusBar || win == mNavigationBar) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002837 return;
2838 }
Craig Mautner69b08182012-09-05 13:07:13 -07002839 final boolean isDefaultDisplay = win.isDefaultDisplay();
2840 final boolean needsToOffsetInputMethodTarget = isDefaultDisplay &&
satok1bc0a492012-04-25 22:47:12 +09002841 (win == mLastInputMethodTargetWindow && mLastInputMethodWindow != null);
2842 if (needsToOffsetInputMethodTarget) {
2843 if (DEBUG_LAYOUT) {
2844 Slog.i(TAG, "Offset ime target window by the last ime window state");
2845 }
2846 offsetInputMethodWindowLw(mLastInputMethodWindow);
2847 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002848
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002849 final int fl = attrs.flags;
2850 final int sim = attrs.softInputMode;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002851 final int sysUiFl = win.getSystemUiVisibility();
2852
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002853 final Rect pf = mTmpParentFrame;
2854 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002855 final Rect of = mTmpOverscanFrame;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002856 final Rect cf = mTmpContentFrame;
2857 final Rect vf = mTmpVisibleFrame;
Craig Mautner69b08182012-09-05 13:07:13 -07002858
2859 final boolean hasNavBar = (isDefaultDisplay && mHasNavigationBar
Daniel Sandler36412a72011-08-04 09:35:13 -04002860 && mNavigationBar != null && mNavigationBar.isVisibleLw());
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002861
Craig Mautnerf683b562012-10-02 11:10:57 -07002862 final int adjust = sim & SOFT_INPUT_MASK_ADJUST;
2863
Craig Mautner69b08182012-09-05 13:07:13 -07002864 if (!isDefaultDisplay) {
2865 if (attached != null) {
2866 // If this window is attached to another, our display
2867 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002868 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07002869 } else {
2870 // Give the window full screen.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002871 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
2872 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
2873 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08002874 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002875 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08002876 = mOverscanScreenTop + mOverscanScreenHeight;
Craig Mautner69b08182012-09-05 13:07:13 -07002877 }
2878 } else if (attrs.type == TYPE_INPUT_METHOD) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002879 pf.left = df.left = of.left = cf.left = vf.left = mDockLeft;
2880 pf.top = df.top = of.top = cf.top = vf.top = mDockTop;
2881 pf.right = df.right = of.right = cf.right = vf.right = mDockRight;
2882 pf.bottom = df.bottom = of.bottom = cf.bottom = vf.bottom = mDockBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002883 // IM dock windows always go to the bottom of the screen.
2884 attrs.gravity = Gravity.BOTTOM;
2885 mDockLayer = win.getSurfaceLayer();
2886 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002887 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
2888 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002889 if (DEBUG_LAYOUT)
2890 Log.v(TAG, "layoutWindowLw(" + attrs.getTitle()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002891 + "): IN_SCREEN, INSET_DECOR");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002892 // This is the case for a normal activity window: we want it
2893 // to cover all of the screen space, and it can take care of
2894 // moving its contents to account for screen decorations that
2895 // intrude into that space.
2896 if (attached != null) {
2897 // If this window is attached to another, our display
2898 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002899 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002900 } else {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002901 if (attrs.type == TYPE_STATUS_BAR_PANEL
2902 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Joe Onorato29fc2c92010-11-24 10:26:50 -08002903 // Status bar panels are the only windows who can go on top of
2904 // the status bar. They are protected by the STATUS_BAR_SERVICE
2905 // permission, so they have the same privileges as the status
2906 // bar itself.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002907 //
Daniel Sandler8e8b4152011-07-21 01:16:43 -04002908 // However, they should still dodge the navigation bar if it exists.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002909
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002910 pf.left = df.left = of.left = hasNavBar
2911 ? mDockLeft : mUnrestrictedScreenLeft;
2912 pf.top = df.top = of.top = mUnrestrictedScreenTop;
2913 pf.right = df.right = of.right = hasNavBar
2914 ? mRestrictedScreenLeft+mRestrictedScreenWidth
2915 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
2916 pf.bottom = df.bottom = of.bottom = hasNavBar
2917 ? mRestrictedScreenTop+mRestrictedScreenHeight
2918 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002919
Daniel Sandler8e8b4152011-07-21 01:16:43 -04002920 if (DEBUG_LAYOUT) {
2921 Log.v(TAG, String.format(
2922 "Laying out status bar window: (%d,%d - %d,%d)",
2923 pf.left, pf.top, pf.right, pf.bottom));
2924 }
Dianne Hackbornc652de82013-02-15 16:32:56 -08002925 } else if ((attrs.flags&FLAG_LAYOUT_IN_OVERSCAN) != 0
2926 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
2927 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
2928 // Asking to layout into the overscan region, so give it that pure
2929 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002930 pf.left = df.left = of.left = mOverscanScreenLeft;
2931 pf.top = df.top = of.top = mOverscanScreenTop;
2932 pf.right = df.right = of.right = mOverscanScreenLeft + mOverscanScreenWidth;
2933 pf.bottom = df.bottom = of.bottom = mOverscanScreenTop
2934 + mOverscanScreenHeight;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002935 } else if (mCanHideNavigationBar
2936 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002937 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
2938 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
2939 // Asking for layout as if the nav bar is hidden, lets the
Dianne Hackbornc652de82013-02-15 16:32:56 -08002940 // application extend into the unrestricted overscan screen area. We
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002941 // only do this for application windows to ensure no window that
2942 // can be above the nav bar can do this.
Dianne Hackborn313440842013-02-19 19:22:59 -08002943 pf.left = df.left = mOverscanScreenLeft;
2944 pf.top = df.top = mOverscanScreenTop;
2945 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
2946 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002947 // We need to tell the app about where the frame inside the overscan
2948 // is, so it can inset its content by that amount -- it didn't ask
2949 // to actually extend itself into the overscan region.
2950 of.left = mUnrestrictedScreenLeft;
2951 of.top = mUnrestrictedScreenTop;
2952 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
2953 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08002954 } else {
Dianne Hackborn313440842013-02-19 19:22:59 -08002955 pf.left = df.left = mRestrictedOverscanScreenLeft;
2956 pf.top = df.top = mRestrictedOverscanScreenTop;
2957 pf.right = df.right = mRestrictedOverscanScreenLeft
2958 + mRestrictedOverscanScreenWidth;
2959 pf.bottom = df.bottom = mRestrictedOverscanScreenTop
2960 + mRestrictedOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002961 // We need to tell the app about where the frame inside the overscan
2962 // is, so it can inset its content by that amount -- it didn't ask
2963 // to actually extend itself into the overscan region.
2964 of.left = mUnrestrictedScreenLeft;
2965 of.top = mUnrestrictedScreenTop;
2966 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
2967 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08002968 }
Craig Mautner69b08182012-09-05 13:07:13 -07002969
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002970 if ((attrs.flags&FLAG_FULLSCREEN) == 0) {
2971 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
2972 cf.left = mDockLeft;
2973 cf.top = mDockTop;
2974 cf.right = mDockRight;
2975 cf.bottom = mDockBottom;
2976 } else {
2977 cf.left = mContentLeft;
2978 cf.top = mContentTop;
2979 cf.right = mContentRight;
2980 cf.bottom = mContentBottom;
2981 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002982 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002983 // Full screen windows are always given a layout that is as if the
2984 // status bar and other transient decors are gone. This is to avoid
2985 // bad states when moving from a window that is not hding the
2986 // status bar to one that is.
2987 cf.left = mRestrictedScreenLeft;
2988 cf.top = mRestrictedScreenTop;
2989 cf.right = mRestrictedScreenLeft + mRestrictedScreenWidth;
2990 cf.bottom = mRestrictedScreenTop + mRestrictedScreenHeight;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002991 }
Craig Mautner69b08182012-09-05 13:07:13 -07002992
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002993 applyStableConstraints(sysUiFl, fl, cf);
Dianne Hackborndea3ef72010-10-28 14:24:22 -07002994 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
2995 vf.left = mCurLeft;
2996 vf.top = mCurTop;
2997 vf.right = mCurRight;
2998 vf.bottom = mCurBottom;
2999 } else {
3000 vf.set(cf);
3001 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003002 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003003 } else if ((fl & FLAG_LAYOUT_IN_SCREEN) != 0 || (sysUiFl
3004 & (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
3005 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)) != 0) {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003006 if (DEBUG_LAYOUT)
3007 Log.v(TAG, "layoutWindowLw(" + attrs.getTitle() + "): IN_SCREEN");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003008 // A window that has requested to fill the entire screen just
3009 // gets everything, period.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003010 if (attrs.type == TYPE_STATUS_BAR_PANEL
3011 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003012 pf.left = df.left = of.left = cf.left = hasNavBar
3013 ? mDockLeft : mUnrestrictedScreenLeft;
3014 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
3015 pf.right = df.right = of.right = cf.right = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003016 ? mRestrictedScreenLeft+mRestrictedScreenWidth
Dianne Hackbornc652de82013-02-15 16:32:56 -08003017 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003018 pf.bottom = df.bottom = of.bottom = cf.bottom = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003019 ? mRestrictedScreenTop+mRestrictedScreenHeight
Dianne Hackbornc652de82013-02-15 16:32:56 -08003020 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Daniel Sandler36412a72011-08-04 09:35:13 -04003021 if (DEBUG_LAYOUT) {
3022 Log.v(TAG, String.format(
3023 "Laying out IN_SCREEN status bar window: (%d,%d - %d,%d)",
3024 pf.left, pf.top, pf.right, pf.bottom));
3025 }
Jim Millere898ac52012-04-06 17:10:57 -07003026 } else if (attrs.type == TYPE_NAVIGATION_BAR
3027 || attrs.type == TYPE_NAVIGATION_BAR_PANEL) {
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003028 // The navigation bar has Real Ultimate Power.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003029 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3030 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3031 pf.right = df.right = of.right = mUnrestrictedScreenLeft
3032 + mUnrestrictedScreenWidth;
3033 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop
3034 + mUnrestrictedScreenHeight;
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003035 if (DEBUG_LAYOUT) {
3036 Log.v(TAG, String.format(
3037 "Laying out navigation bar window: (%d,%d - %d,%d)",
3038 pf.left, pf.top, pf.right, pf.bottom));
3039 }
Dianne Hackborn01011c32012-02-21 13:54:21 -08003040 } else if ((attrs.type == TYPE_SECURE_SYSTEM_OVERLAY
3041 || attrs.type == TYPE_BOOT_PROGRESS)
Jeff Brownbfcb60a2011-09-08 18:51:14 -07003042 && ((fl & FLAG_FULLSCREEN) != 0)) {
3043 // Fullscreen secure system overlays get what they ask for.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003044 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3045 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3046 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
3047 + mOverscanScreenWidth;
3048 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
3049 + mOverscanScreenHeight;
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07003050 } else if (attrs.type == TYPE_BOOT_PROGRESS
3051 || attrs.type == TYPE_UNIVERSE_BACKGROUND) {
Dianne Hackborn01011c32012-02-21 13:54:21 -08003052 // Boot progress screen always covers entire display.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003053 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3054 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3055 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
3056 + mOverscanScreenWidth;
3057 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
3058 + mOverscanScreenHeight;
Dianne Hackborn313440842013-02-19 19:22:59 -08003059 } else if (attrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER) {
3060 // The wallpaper mostly goes into the overscan region.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003061 pf.left = df.left = of.left = cf.left = mRestrictedOverscanScreenLeft;
3062 pf.top = df.top = of.top = cf.top = mRestrictedOverscanScreenTop;
3063 pf.right = df.right = of.right = cf.right
Dianne Hackborn313440842013-02-19 19:22:59 -08003064 = mRestrictedOverscanScreenLeft + mRestrictedOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003065 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackborn313440842013-02-19 19:22:59 -08003066 = mRestrictedOverscanScreenTop + mRestrictedOverscanScreenHeight;
Dianne Hackbornc652de82013-02-15 16:32:56 -08003067 } else if ((attrs.flags & FLAG_LAYOUT_IN_OVERSCAN) != 0
3068 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3069 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3070 // Asking to layout into the overscan region, so give it that pure
3071 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003072 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3073 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3074 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08003075 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003076 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003077 = mOverscanScreenTop + mOverscanScreenHeight;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003078 } else if (mCanHideNavigationBar
3079 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003080 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3081 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3082 // Asking for layout as if the nav bar is hidden, lets the
3083 // application extend into the unrestricted screen area. We
3084 // only do this for application windows to ensure no window that
3085 // can be above the nav bar can do this.
3086 // XXX This assumes that an app asking for this will also
3087 // ask for layout in only content. We can't currently figure out
3088 // what the screen would be if only laying out to hide the nav bar.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003089 pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft;
3090 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
3091 pf.right = df.right = of.right = cf.right = mUnrestrictedScreenLeft
3092 + mUnrestrictedScreenWidth;
3093 pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop
3094 + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003095 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003096 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
3097 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
3098 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
3099 + mRestrictedScreenWidth;
3100 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
3101 + mRestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003102 }
Craig Mautner69b08182012-09-05 13:07:13 -07003103
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003104 applyStableConstraints(sysUiFl, fl, cf);
Craig Mautner69b08182012-09-05 13:07:13 -07003105
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003106 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3107 vf.left = mCurLeft;
3108 vf.top = mCurTop;
3109 vf.right = mCurRight;
3110 vf.bottom = mCurBottom;
3111 } else {
3112 vf.set(cf);
3113 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003114 } else if (attached != null) {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003115 if (DEBUG_LAYOUT)
3116 Log.v(TAG, "layoutWindowLw(" + attrs.getTitle() + "): attached to " + attached);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003117 // A child window should be placed inside of the same visible
3118 // frame that its parent had.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003119 setAttachedWindowFrames(win, fl, adjust, attached, false, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003120 } else {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003121 if (DEBUG_LAYOUT)
3122 Log.v(TAG, "layoutWindowLw(" + attrs.getTitle() + "): normal window");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003123 // Otherwise, a normal window must be placed inside the content
3124 // of all screen decorations.
Dianne Hackborna239c842011-06-01 12:28:20 -07003125 if (attrs.type == TYPE_STATUS_BAR_PANEL) {
3126 // Status bar panels are the only windows who can go on top of
3127 // the status bar. They are protected by the STATUS_BAR_SERVICE
3128 // permission, so they have the same privileges as the status
3129 // bar itself.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003130 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
3131 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
3132 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
3133 + mRestrictedScreenWidth;
3134 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
3135 + mRestrictedScreenHeight;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003136 } else {
Dianne Hackborna239c842011-06-01 12:28:20 -07003137 pf.left = mContentLeft;
3138 pf.top = mContentTop;
3139 pf.right = mContentRight;
3140 pf.bottom = mContentBottom;
3141 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003142 df.left = of.left = cf.left = mDockLeft;
3143 df.top = of.top = cf.top = mDockTop;
3144 df.right = of.right = cf.right = mDockRight;
3145 df.bottom = of.bottom = cf.bottom = mDockBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07003146 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003147 df.left = of.left = cf.left = mContentLeft;
3148 df.top = of.top = cf.top = mContentTop;
3149 df.right = of.right = cf.right = mContentRight;
3150 df.bottom = of.bottom = cf.bottom = mContentBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07003151 }
3152 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3153 vf.left = mCurLeft;
3154 vf.top = mCurTop;
3155 vf.right = mCurRight;
3156 vf.bottom = mCurBottom;
3157 } else {
3158 vf.set(cf);
3159 }
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003160 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003161 }
3162 }
Craig Mautner69b08182012-09-05 13:07:13 -07003163
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003164 if ((fl & FLAG_LAYOUT_NO_LIMITS) != 0) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003165 df.left = df.top = of.left = of.top = cf.left = cf.top = vf.left = vf.top = -10000;
3166 df.right = df.bottom = of.right = of.bottom = cf.right = cf.bottom
3167 = vf.right = vf.bottom = 10000;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003168 }
3169
The Android Open Source Project11267662009-03-18 17:39:47 -07003170 if (DEBUG_LAYOUT) Log.v(TAG, "Compute frame " + attrs.getTitle()
3171 + ": sim=#" + Integer.toHexString(sim)
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003172 + " attach=" + attached + " type=" + attrs.type
3173 + String.format(" flags=0x%08x", fl)
The Android Open Source Project11267662009-03-18 17:39:47 -07003174 + " pf=" + pf.toShortString() + " df=" + df.toShortString()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003175 + " of=" + of.toShortString()
The Android Open Source Project11267662009-03-18 17:39:47 -07003176 + " cf=" + cf.toShortString() + " vf=" + vf.toShortString());
Craig Mautner69b08182012-09-05 13:07:13 -07003177
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003178 win.computeFrameLw(pf, df, of, cf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07003179
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003180 // Dock windows carve out the bottom of the screen, so normal windows
3181 // can't appear underneath them.
Craig Mautner8bd206b2012-10-03 10:32:02 -07003182 if (attrs.type == TYPE_INPUT_METHOD && win.isVisibleOrBehindKeyguardLw()
3183 && !win.getGivenInsetsPendingLw()) {
satok1bc0a492012-04-25 22:47:12 +09003184 setLastInputMethodWindowLw(null, null);
3185 offsetInputMethodWindowLw(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003186 }
3187 }
3188
satok1bc0a492012-04-25 22:47:12 +09003189 private void offsetInputMethodWindowLw(WindowState win) {
3190 int top = win.getContentFrameLw().top;
3191 top += win.getGivenContentInsetsLw().top;
3192 if (mContentBottom > top) {
3193 mContentBottom = top;
3194 }
3195 top = win.getVisibleFrameLw().top;
3196 top += win.getGivenVisibleInsetsLw().top;
3197 if (mCurBottom > top) {
3198 mCurBottom = top;
3199 }
3200 if (DEBUG_LAYOUT) Log.v(TAG, "Input method: mDockBottom="
3201 + mDockBottom + " mContentBottom="
3202 + mContentBottom + " mCurBottom=" + mCurBottom);
3203 }
3204
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003205 /** {@inheritDoc} */
Craig Mautner61ac6bb2012-02-02 17:29:33 -08003206 @Override
3207 public void finishLayoutLw() {
3208 return;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003209 }
3210
3211 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003212 @Override
Craig Mautner39834192012-09-02 07:47:24 -07003213 public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) {
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003214 mTopFullscreenOpaqueWindowState = null;
3215 mForceStatusBar = false;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003216 mForceStatusBarFromKeyguard = false;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08003217 mForcingShowNavBar = false;
3218 mForcingShowNavBarLayer = -1;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003219
3220 mHideLockScreen = false;
3221 mAllowLockscreenWhenOn = false;
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003222 mDismissKeyguard = DISMISS_KEYGUARD_NONE;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003223 mShowingLockscreen = false;
3224 mShowingDream = false;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003225 }
3226
3227 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003228 @Override
Craig Mautner39834192012-09-02 07:47:24 -07003229 public void applyPostLayoutPolicyLw(WindowState win,
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003230 WindowManager.LayoutParams attrs) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07003231 if (DEBUG_LAYOUT) Slog.i(TAG, "Win " + win + ": isVisibleOrBehindKeyguardLw="
3232 + win.isVisibleOrBehindKeyguardLw());
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08003233 if (mTopFullscreenOpaqueWindowState == null && (win.getAttrs().privateFlags
3234 &WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_SHOW_NAV_BAR) != 0) {
3235 if (mForcingShowNavBarLayer < 0) {
3236 mForcingShowNavBar = true;
3237 mForcingShowNavBarLayer = win.getSurfaceLayer();
3238 }
3239 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003240 if (mTopFullscreenOpaqueWindowState == null &&
Dianne Hackborn01b02a72012-01-12 14:05:03 -08003241 win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()) {
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003242 if ((attrs.flags & FLAG_FORCE_NOT_FULLSCREEN) != 0) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003243 if (attrs.type == TYPE_KEYGUARD) {
3244 mForceStatusBarFromKeyguard = true;
3245 } else {
3246 mForceStatusBar = true;
3247 }
3248 }
3249 if (attrs.type == TYPE_KEYGUARD) {
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003250 mShowingLockscreen = true;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07003251 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003252 boolean applyWindow = attrs.type >= FIRST_APPLICATION_WINDOW
3253 && attrs.type <= LAST_APPLICATION_WINDOW;
3254 if (attrs.type == TYPE_DREAM) {
Jeff Brownc8018eb2012-10-29 21:33:27 -07003255 // If the lockscreen was showing when the dream started then wait
3256 // for the dream to draw before hiding the lockscreen.
3257 if (!mDreamingLockscreen
3258 || (win.isVisibleLw() && win.hasDrawnLw())) {
3259 mShowingDream = true;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003260 applyWindow = true;
3261 }
3262 }
3263 if (applyWindow
Dianne Hackborn6493e642010-10-01 13:06:30 -07003264 && attrs.x == 0 && attrs.y == 0
3265 && attrs.width == WindowManager.LayoutParams.MATCH_PARENT
3266 && attrs.height == WindowManager.LayoutParams.MATCH_PARENT) {
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003267 if (DEBUG_LAYOUT) Log.v(TAG, "Fullscreen window: " + win);
3268 mTopFullscreenOpaqueWindowState = win;
3269 if ((attrs.flags & FLAG_SHOW_WHEN_LOCKED) != 0) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003270 if (DEBUG_LAYOUT) Log.v(TAG, "Setting mHideLockScreen to true by win " + win);
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003271 mHideLockScreen = true;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003272 mForceStatusBarFromKeyguard = false;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003273 }
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003274 if ((attrs.flags & FLAG_DISMISS_KEYGUARD) != 0
3275 && mDismissKeyguard == DISMISS_KEYGUARD_NONE) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003276 if (DEBUG_LAYOUT) Log.v(TAG, "Setting mDismissKeyguard to true by win " + win);
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003277 mDismissKeyguard = mWinDismissingKeyguard == win ?
3278 DISMISS_KEYGUARD_CONTINUE : DISMISS_KEYGUARD_START;
3279 mWinDismissingKeyguard = win;
John Spurlock3733c4c2013-04-11 16:55:12 -04003280 mForceStatusBarFromKeyguard =
3281 mShowingLockscreen && mKeyguardMediator.isSecure();
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003282 }
3283 if ((attrs.flags & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) {
3284 mAllowLockscreenWhenOn = true;
3285 }
3286 }
3287 }
3288 }
3289
3290 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003291 @Override
Craig Mautner39834192012-09-02 07:47:24 -07003292 public int finishPostLayoutPolicyLw() {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003293 int changes = 0;
Joe Onorato93056472010-09-10 10:30:46 -04003294 boolean topIsFullscreen = false;
Daniel Sandlere02d8082010-10-08 15:13:22 -04003295
3296 final WindowManager.LayoutParams lp = (mTopFullscreenOpaqueWindowState != null)
3297 ? mTopFullscreenOpaqueWindowState.getAttrs()
3298 : null;
3299
Jeff Brownc8018eb2012-10-29 21:33:27 -07003300 // If we are not currently showing a dream then remember the current
3301 // lockscreen state. We will use this to determine whether the dream
3302 // started while the lockscreen was showing and remember this state
3303 // while the dream is showing.
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003304 if (!mShowingDream) {
3305 mDreamingLockscreen = mShowingLockscreen;
3306 }
3307
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003308 if (mStatusBar != null) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07003309 if (DEBUG_LAYOUT) Log.i(TAG, "force=" + mForceStatusBar
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003310 + " forcefkg=" + mForceStatusBarFromKeyguard
Dianne Hackbornd70bc2f2009-10-06 23:25:51 -07003311 + " top=" + mTopFullscreenOpaqueWindowState);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003312 if (mForceStatusBar || mForceStatusBarFromKeyguard) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07003313 if (DEBUG_LAYOUT) Log.v(TAG, "Showing status bar: forced");
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003314 if (mStatusBar.showLw(true)) changes |= FINISH_LAYOUT_REDO_LAYOUT;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003315 } else if (mTopFullscreenOpaqueWindowState != null) {
Joe Onorato93056472010-09-10 10:30:46 -04003316 if (localLOGV) {
3317 Log.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw()
3318 + " shown frame: " + mTopFullscreenOpaqueWindowState.getShownFrameLw());
3319 Log.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs()
3320 + " lp.flags=0x" + Integer.toHexString(lp.flags));
3321 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003322 topIsFullscreen = (lp.flags & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0
3323 || (mLastSystemUiFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
Joe Onorato93056472010-09-10 10:30:46 -04003324 // The subtle difference between the window for mTopFullscreenOpaqueWindowState
3325 // and mTopIsFullscreen is that that mTopIsFullscreen is set only if the window
3326 // has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the
3327 // case though.
3328 if (topIsFullscreen) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003329 if (DEBUG_LAYOUT) Log.v(TAG, "** HIDING status bar");
3330 if (mStatusBar.hideLw(true)) {
3331 changes |= FINISH_LAYOUT_REDO_LAYOUT;
Daniel Sandler9c00d5b2011-09-13 14:04:26 -04003332
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003333 mHandler.post(new Runnable() {
3334 @Override
3335 public void run() {
Dianne Hackborn42e620c2012-06-24 13:20:51 -07003336 try {
3337 IStatusBarService statusbar = getStatusBarService();
3338 if (statusbar != null) {
Daniel Sandler11cf1782012-09-27 14:03:08 -04003339 statusbar.collapsePanels();
Dianne Hackborn42e620c2012-06-24 13:20:51 -07003340 }
3341 } catch (RemoteException ex) {
3342 // re-acquire status bar service next time it is needed.
3343 mStatusBarService = null;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003344 }
3345 }});
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07003346 } else if (DEBUG_LAYOUT) {
Daniel Sandler40427442010-07-16 11:44:52 -04003347 Log.v(TAG, "Preventing status bar from hiding by policy");
3348 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003349 } else {
Dianne Hackborn01b02a72012-01-12 14:05:03 -08003350 if (DEBUG_LAYOUT) Log.v(TAG, "** SHOWING status bar: top is not fullscreen");
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003351 if (mStatusBar.showLw(true)) changes |= FINISH_LAYOUT_REDO_LAYOUT;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003352 }
3353 }
3354 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04003355
Joe Onorato644f9c32011-01-25 12:06:23 -08003356 mTopIsFullscreen = topIsFullscreen;
Daniel Sandlere02d8082010-10-08 15:13:22 -04003357
Craig Mautner39834192012-09-02 07:47:24 -07003358 // Hide the key guard if a visible window explicitly specifies that it wants to be
3359 // displayed when the screen is locked.
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -07003360 if (mKeyguard != null) {
Craig Mautner39834192012-09-02 07:47:24 -07003361 if (localLOGV) Log.v(TAG, "finishPostLayoutPolicyLw: mHideKeyguard="
3362 + mHideLockScreen);
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003363 if (mDismissKeyguard != DISMISS_KEYGUARD_NONE && !mKeyguardMediator.isSecure()) {
Dianne Hackborn08743722009-12-21 12:16:51 -08003364 if (mKeyguard.hideLw(true)) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003365 changes |= FINISH_LAYOUT_REDO_LAYOUT
3366 | FINISH_LAYOUT_REDO_CONFIG
3367 | FINISH_LAYOUT_REDO_WALLPAPER;
3368 }
Dianne Hackborn05726582009-09-22 17:28:24 -07003369 if (mKeyguardMediator.isShowing()) {
Dianne Hackbornb446e972009-09-20 15:23:25 -07003370 mHandler.post(new Runnable() {
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003371 @Override
Dianne Hackbornb446e972009-09-20 15:23:25 -07003372 public void run() {
Dianne Hackborn05726582009-09-22 17:28:24 -07003373 mKeyguardMediator.keyguardDone(false, false);
Dianne Hackbornb446e972009-09-20 15:23:25 -07003374 }
3375 });
3376 }
Dianne Hackborn05726582009-09-22 17:28:24 -07003377 } else if (mHideLockScreen) {
Dianne Hackborn08743722009-12-21 12:16:51 -08003378 if (mKeyguard.hideLw(true)) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003379 changes |= FINISH_LAYOUT_REDO_LAYOUT
3380 | FINISH_LAYOUT_REDO_CONFIG
3381 | FINISH_LAYOUT_REDO_WALLPAPER;
3382 }
Mike Lockwoodf3bfed52010-01-21 16:38:44 -05003383 mKeyguardMediator.setHidden(true);
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003384 } else if (mDismissKeyguard != DISMISS_KEYGUARD_NONE) {
3385 // This is the case of keyguard isSecure() and not mHideLockScreen.
3386 if (mDismissKeyguard == DISMISS_KEYGUARD_START) {
3387 // Only launch the next keyguard unlock window once per window.
3388 if (mKeyguard.showLw(true)) {
3389 changes |= FINISH_LAYOUT_REDO_LAYOUT
3390 | FINISH_LAYOUT_REDO_CONFIG
3391 | FINISH_LAYOUT_REDO_WALLPAPER;
3392 }
3393 mKeyguardMediator.setHidden(false);
3394 mHandler.post(new Runnable() {
3395 @Override
3396 public void run() {
3397 mKeyguardMediator.dismiss();
3398 }
3399 });
3400 }
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -07003401 } else {
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003402 mWinDismissingKeyguard = null;
Dianne Hackborn08743722009-12-21 12:16:51 -08003403 if (mKeyguard.showLw(true)) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003404 changes |= FINISH_LAYOUT_REDO_LAYOUT
3405 | FINISH_LAYOUT_REDO_CONFIG
3406 | FINISH_LAYOUT_REDO_WALLPAPER;
3407 }
Mike Lockwoodf3bfed52010-01-21 16:38:44 -05003408 mKeyguardMediator.setHidden(false);
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -07003409 }
3410 }
Joe Onorato664644d2011-01-23 17:53:23 -08003411
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003412 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003413 // If the navigation bar has been hidden or shown, we need to do another
3414 // layout pass to update that window.
3415 changes |= FINISH_LAYOUT_REDO_LAYOUT;
3416 }
Joe Onorato664644d2011-01-23 17:53:23 -08003417
Mike Lockwood28569302010-01-28 11:54:40 -05003418 // update since mAllowLockscreenWhenOn might have changed
3419 updateLockScreenTimeout();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003420 return changes;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003421 }
3422
Dianne Hackborn08743722009-12-21 12:16:51 -08003423 public boolean allowAppAnimationsLw() {
Craig Mautnerf03e4c52012-06-14 14:11:27 -07003424 if (mKeyguard != null && mKeyguard.isVisibleLw() && !mKeyguard.isAnimatingLw()) {
Dianne Hackborn08743722009-12-21 12:16:51 -08003425 // If keyguard is currently visible, no reason to animate
3426 // behind it.
3427 return false;
3428 }
Dianne Hackborn08743722009-12-21 12:16:51 -08003429 return true;
3430 }
3431
Dianne Hackborndf89e652011-10-06 22:35:11 -07003432 public int focusChangedLw(WindowState lastFocus, WindowState newFocus) {
Joe Onorato664644d2011-01-23 17:53:23 -08003433 mFocusedWindow = newFocus;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003434 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003435 // If the navigation bar has been hidden or shown, we need to do another
3436 // layout pass to update that window.
3437 return FINISH_LAYOUT_REDO_LAYOUT;
3438 }
3439 return 0;
Joe Onorato664644d2011-01-23 17:53:23 -08003440 }
3441
Dianne Hackborn0ecadf72009-03-31 18:00:37 -07003442 /** {@inheritDoc} */
Jeff Brown46b9ac02010-04-22 18:58:52 -07003443 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
Mike Lockwood3a74bd32011-08-12 13:55:22 -07003444 // do nothing if headless
Mike Lockwoodd747dc82011-09-13 16:28:22 -04003445 if (mHeadless) return;
Mike Lockwood3a74bd32011-08-12 13:55:22 -07003446
Jeff Brown46b9ac02010-04-22 18:58:52 -07003447 // lid changed state
Jeff Brownc458ce92012-04-30 14:58:40 -07003448 final int newLidState = lidOpen ? LID_OPEN : LID_CLOSED;
3449 if (newLidState == mLidState) {
3450 return;
3451 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07003452
Jeff Brownc458ce92012-04-30 14:58:40 -07003453 mLidState = newLidState;
3454 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07003455 updateRotation(true);
Jeff Brownc458ce92012-04-30 14:58:40 -07003456
3457 if (lidOpen) {
3458 if (keyguardIsShowingTq()) {
Jeff Brown1c2e4942012-11-06 16:32:01 -08003459 mKeyguardMediator.onWakeKeyWhenKeyguardShowingTq(KeyEvent.KEYCODE_POWER);
Jeff Brown46b9ac02010-04-22 18:58:52 -07003460 } else {
Jeff Brown96307042012-07-27 15:51:34 -07003461 mPowerManager.wakeUp(SystemClock.uptimeMillis());
Jeff Brown46b9ac02010-04-22 18:58:52 -07003462 }
Jeff Brownc458ce92012-04-30 14:58:40 -07003463 } else if (!mLidControlsSleep) {
Jeff Brown96307042012-07-27 15:51:34 -07003464 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
Jeff Brown46b9ac02010-04-22 18:58:52 -07003465 }
3466 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003467
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08003468 void setHdmiPlugged(boolean plugged) {
3469 if (mHdmiPlugged != plugged) {
3470 mHdmiPlugged = plugged;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003471 updateRotation(true, true);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08003472 Intent intent = new Intent(ACTION_HDMI_PLUGGED);
Joe Onoratodc100302011-01-11 17:07:41 -08003473 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08003474 intent.putExtra(EXTRA_HDMI_PLUGGED_STATE, plugged);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07003475 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08003476 }
3477 }
3478
Joe Onoratoea495d42011-04-06 11:41:11 -07003479 void initializeHdmiState() {
Joe Onorato7ba631f2011-05-04 15:28:00 -07003480 boolean plugged = false;
Joe Onoratoea495d42011-04-06 11:41:11 -07003481 // watch for HDMI plug messages if the hdmi switch exists
3482 if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) {
3483 mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi");
3484
Joe Onoratoea495d42011-04-06 11:41:11 -07003485 final String filename = "/sys/class/switch/hdmi/state";
3486 FileReader reader = null;
3487 try {
3488 reader = new FileReader(filename);
3489 char[] buf = new char[15];
3490 int n = reader.read(buf);
3491 if (n > 1) {
3492 plugged = 0 != Integer.parseInt(new String(buf, 0, n-1));
3493 }
3494 } catch (IOException ex) {
3495 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
3496 } catch (NumberFormatException ex) {
3497 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
3498 } finally {
3499 if (reader != null) {
3500 try {
3501 reader.close();
3502 } catch (IOException ex) {
3503 }
Joe Onoratodc100302011-01-11 17:07:41 -08003504 }
3505 }
3506 }
Joe Onorato7ba631f2011-05-04 15:28:00 -07003507 // This dance forces the code in setHdmiPlugged to run.
3508 // Always do this so the sticky intent is stuck (to false) if there is no hdmi.
3509 mHdmiPlugged = !plugged;
3510 setHdmiPlugged(!mHdmiPlugged);
Joe Onoratodc100302011-01-11 17:07:41 -08003511 }
3512
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003513 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003514 * @return Whether music is being played right now.
3515 */
3516 boolean isMusicActive() {
Eric Laurent413cb9d2009-07-17 11:52:43 -07003517 final AudioManager am = (AudioManager)mContext.getSystemService(Context.AUDIO_SERVICE);
3518 if (am == null) {
3519 Log.w(TAG, "isMusicActive: couldn't get AudioManager reference");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003520 return false;
3521 }
Eric Laurent413cb9d2009-07-17 11:52:43 -07003522 return am.isMusicActive();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003523 }
3524
3525 /**
3526 * Tell the audio service to adjust the volume appropriate to the event.
3527 * @param keycode
3528 */
Mike Lockwooda53e3812009-09-25 10:51:39 -04003529 void handleVolumeKey(int stream, int keycode) {
Jeff Brown4d396052010-10-29 21:50:21 -07003530 IAudioService audioService = getAudioService();
3531 if (audioService == null) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003532 return;
3533 }
3534 try {
3535 // since audio is playing, we shouldn't have to hold a wake lock
3536 // during the call, but we do it as a precaution for the rare possibility
3537 // that the music stops right before we call this
Jeff Brownb0418da2010-11-01 15:24:01 -07003538 // TODO: Actually handle MUTE.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003539 mBroadcastWakeLock.acquire();
Jeff Brown4d396052010-10-29 21:50:21 -07003540 audioService.adjustStreamVolume(stream,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003541 keycode == KeyEvent.KEYCODE_VOLUME_UP
3542 ? AudioManager.ADJUST_RAISE
3543 : AudioManager.ADJUST_LOWER,
3544 0);
3545 } catch (RemoteException e) {
3546 Log.w(TAG, "IAudioService.adjustStreamVolume() threw RemoteException " + e);
3547 } finally {
3548 mBroadcastWakeLock.release();
3549 }
3550 }
Jeff Brown4d396052010-10-29 21:50:21 -07003551
Dianne Hackbornc0e3f242011-08-19 14:19:10 -07003552 final Object mScreenshotLock = new Object();
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07003553 ServiceConnection mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07003554
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003555 final Runnable mScreenshotTimeout = new Runnable() {
3556 @Override public void run() {
3557 synchronized (mScreenshotLock) {
3558 if (mScreenshotConnection != null) {
3559 mContext.unbindService(mScreenshotConnection);
3560 mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07003561 }
Winson Chung9112ec32011-06-27 13:15:32 -07003562 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003563 }
3564 };
3565
3566 // Assume this is called from the Handler thread.
3567 private void takeScreenshot() {
3568 synchronized (mScreenshotLock) {
3569 if (mScreenshotConnection != null) {
3570 return;
3571 }
3572 ComponentName cn = new ComponentName("com.android.systemui",
3573 "com.android.systemui.screenshot.TakeScreenshotService");
3574 Intent intent = new Intent();
3575 intent.setComponent(cn);
3576 ServiceConnection conn = new ServiceConnection() {
3577 @Override
3578 public void onServiceConnected(ComponentName name, IBinder service) {
3579 synchronized (mScreenshotLock) {
3580 if (mScreenshotConnection != this) {
3581 return;
3582 }
3583 Messenger messenger = new Messenger(service);
3584 Message msg = Message.obtain(null, 1);
3585 final ServiceConnection myConn = this;
3586 Handler h = new Handler(mHandler.getLooper()) {
3587 @Override
3588 public void handleMessage(Message msg) {
3589 synchronized (mScreenshotLock) {
3590 if (mScreenshotConnection == myConn) {
3591 mContext.unbindService(mScreenshotConnection);
3592 mScreenshotConnection = null;
3593 mHandler.removeCallbacks(mScreenshotTimeout);
3594 }
3595 }
3596 }
3597 };
3598 msg.replyTo = new Messenger(h);
Winson Chunga63bb842011-10-17 10:26:28 -07003599 msg.arg1 = msg.arg2 = 0;
3600 if (mStatusBar != null && mStatusBar.isVisibleLw())
3601 msg.arg1 = 1;
3602 if (mNavigationBar != null && mNavigationBar.isVisibleLw())
3603 msg.arg2 = 1;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003604 try {
3605 messenger.send(msg);
3606 } catch (RemoteException e) {
3607 }
3608 }
3609 }
3610 @Override
3611 public void onServiceDisconnected(ComponentName name) {}
3612 };
Amith Yamasani27b89e62013-01-16 12:30:11 -08003613 if (mContext.bindServiceAsUser(
3614 intent, conn, Context.BIND_AUTO_CREATE, UserHandle.CURRENT)) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003615 mScreenshotConnection = conn;
3616 mHandler.postDelayed(mScreenshotTimeout, 10000);
3617 }
3618 }
Winson Chung9112ec32011-06-27 13:15:32 -07003619 }
3620
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003621 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003622 @Override
Jeff Brown1f245102010-11-18 20:53:46 -08003623 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags, boolean isScreenOn) {
Jeff Brown96307042012-07-27 15:51:34 -07003624 if (!mSystemBooted) {
3625 // If we have not yet booted, don't let key events do anything.
3626 return 0;
3627 }
3628
Jeff Brown1f245102010-11-18 20:53:46 -08003629 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
3630 final boolean canceled = event.isCanceled();
3631 final int keyCode = event.getKeyCode();
Jeff Browne20c9e02010-10-11 14:20:19 -07003632
Jeff Brown3122e442010-10-11 23:32:49 -07003633 final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0;
Jeff Brown3122e442010-10-11 23:32:49 -07003634
Mike Lockwoodc72b15f2009-11-28 20:58:22 -05003635 // If screen is off then we treat the case where the keyguard is open but hidden
3636 // the same as if it were open and in front.
3637 // This will prevent any keys other than the power button from waking the screen
3638 // when the keyguard is hidden by another activity.
Mike Lockwood3a74bd32011-08-12 13:55:22 -07003639 final boolean keyguardActive = (mKeyguardMediator == null ? false :
3640 (isScreenOn ?
3641 mKeyguardMediator.isShowingAndNotHidden() :
3642 mKeyguardMediator.isShowing()));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003643
Jeff Brown96307042012-07-27 15:51:34 -07003644 if (keyCode == KeyEvent.KEYCODE_POWER) {
3645 policyFlags |= WindowManagerPolicy.FLAG_WAKE;
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07003646 }
Jeff Brown96307042012-07-27 15:51:34 -07003647 final boolean isWakeKey = (policyFlags & (WindowManagerPolicy.FLAG_WAKE
3648 | WindowManagerPolicy.FLAG_WAKE_DROPPED)) != 0;
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07003649
Jeff Brown40013652012-05-16 21:22:36 -07003650 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003651 Log.d(TAG, "interceptKeyTq keycode=" + keyCode
Jeff Brown96307042012-07-27 15:51:34 -07003652 + " screenIsOn=" + isScreenOn + " keyguardActive=" + keyguardActive
3653 + " policyFlags=" + Integer.toHexString(policyFlags)
3654 + " isWakeKey=" + isWakeKey);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003655 }
3656
Jeff Brown98392ef2011-09-12 18:24:59 -07003657 if (down && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0
3658 && event.getRepeatCount() == 0) {
Jeff Brown4d396052010-10-29 21:50:21 -07003659 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
3660 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003661
Jeff Brown4d396052010-10-29 21:50:21 -07003662 // Basic policy based on screen state and keyguard.
3663 // FIXME: This policy isn't quite correct. We shouldn't care whether the screen
3664 // is on or off, really. We should care about whether the device is in an
3665 // interactive state or is in suspend pretending to be "off".
3666 // The primary screen might be turned off due to proximity sensor or
3667 // because we are presenting media on an auxiliary screen or remotely controlling
3668 // the device some other way (which is why we have an exemption here for injected
3669 // events).
3670 int result;
Mike Lockwoodd747dc82011-09-13 16:28:22 -04003671 if ((isScreenOn && !mHeadless) || (isInjected && !isWakeKey)) {
Jeff Brown4d396052010-10-29 21:50:21 -07003672 // When the screen is on or if the key is injected pass the key to the application.
3673 result = ACTION_PASS_TO_USER;
3674 } else {
3675 // When the screen is off and the key is not injected, determine whether
3676 // to wake the device but don't pass the key to the application.
3677 result = 0;
Jeff Brown1c2e4942012-11-06 16:32:01 -08003678 if (down && isWakeKey && isWakeKeyWhenScreenOff(keyCode)) {
Jeff Brown4d396052010-10-29 21:50:21 -07003679 if (keyguardActive) {
Jeff Brown1c2e4942012-11-06 16:32:01 -08003680 // If the keyguard is showing, let it wake the device when ready.
3681 mKeyguardMediator.onWakeKeyWhenKeyguardShowingTq(keyCode);
Jeff Brown4d396052010-10-29 21:50:21 -07003682 } else {
3683 // Otherwise, wake the device ourselves.
Jeff Brown96307042012-07-27 15:51:34 -07003684 result |= ACTION_WAKE_UP;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003685 }
3686 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003687 }
3688
Justin Kohd378ad72013-04-01 12:18:26 -07003689 // If the key would be handled globally, just return the result, don't worry about special
3690 // key processing.
3691 if (mGlobalKeyManager.shouldHandleGlobalKey(keyCode, event)) {
3692 return result;
3693 }
3694
Jeff Brown4d396052010-10-29 21:50:21 -07003695 // Handle special keys.
3696 switch (keyCode) {
3697 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jeff Brownb0418da2010-11-01 15:24:01 -07003698 case KeyEvent.KEYCODE_VOLUME_UP:
3699 case KeyEvent.KEYCODE_VOLUME_MUTE: {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003700 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
3701 if (down) {
3702 if (isScreenOn && !mVolumeDownKeyTriggered
3703 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
3704 mVolumeDownKeyTriggered = true;
3705 mVolumeDownKeyTime = event.getDownTime();
3706 mVolumeDownKeyConsumedByScreenshotChord = false;
3707 cancelPendingPowerKeyAction();
3708 interceptScreenshotChord();
3709 }
3710 } else {
3711 mVolumeDownKeyTriggered = false;
3712 cancelPendingScreenshotChordAction();
3713 }
3714 } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
3715 if (down) {
3716 if (isScreenOn && !mVolumeUpKeyTriggered
3717 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
3718 mVolumeUpKeyTriggered = true;
3719 cancelPendingPowerKeyAction();
3720 cancelPendingScreenshotChordAction();
3721 }
3722 } else {
3723 mVolumeUpKeyTriggered = false;
3724 cancelPendingScreenshotChordAction();
3725 }
3726 }
Jeff Brown4d396052010-10-29 21:50:21 -07003727 if (down) {
3728 ITelephony telephonyService = getTelephonyService();
3729 if (telephonyService != null) {
3730 try {
3731 if (telephonyService.isRinging()) {
3732 // If an incoming call is ringing, either VOLUME key means
3733 // "silence ringer". We handle these keys here, rather than
3734 // in the InCallScreen, to make sure we'll respond to them
3735 // even if the InCallScreen hasn't come to the foreground yet.
3736 // Look for the DOWN event here, to agree with the "fallback"
3737 // behavior in the InCallScreen.
3738 Log.i(TAG, "interceptKeyBeforeQueueing:"
3739 + " VOLUME key-down while ringing: Silence ringer!");
3740
3741 // Silence the ringer. (It's safe to call this
3742 // even if the ringer has already been silenced.)
3743 telephonyService.silenceRinger();
3744
3745 // And *don't* pass this key thru to the current activity
3746 // (which is probably the InCallScreen.)
3747 result &= ~ACTION_PASS_TO_USER;
3748 break;
3749 }
3750 if (telephonyService.isOffhook()
3751 && (result & ACTION_PASS_TO_USER) == 0) {
3752 // If we are in call but we decided not to pass the key to
3753 // the application, handle the volume change here.
3754 handleVolumeKey(AudioManager.STREAM_VOICE_CALL, keyCode);
3755 break;
3756 }
3757 } catch (RemoteException ex) {
3758 Log.w(TAG, "ITelephony threw RemoteException", ex);
3759 }
3760 }
3761
3762 if (isMusicActive() && (result & ACTION_PASS_TO_USER) == 0) {
3763 // If music is playing but we decided not to pass the key to the
3764 // application, handle the volume change here.
3765 handleVolumeKey(AudioManager.STREAM_MUSIC, keyCode);
3766 break;
3767 }
3768 }
3769 break;
3770 }
3771
3772 case KeyEvent.KEYCODE_ENDCALL: {
3773 result &= ~ACTION_PASS_TO_USER;
3774 if (down) {
3775 ITelephony telephonyService = getTelephonyService();
3776 boolean hungUp = false;
3777 if (telephonyService != null) {
3778 try {
3779 hungUp = telephonyService.endCall();
3780 } catch (RemoteException ex) {
3781 Log.w(TAG, "ITelephony threw RemoteException", ex);
3782 }
3783 }
3784 interceptPowerKeyDown(!isScreenOn || hungUp);
3785 } else {
3786 if (interceptPowerKeyUp(canceled)) {
3787 if ((mEndcallBehavior
3788 & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) {
3789 if (goHome()) {
3790 break;
Dianne Hackborn0041e972009-07-24 17:14:43 -07003791 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003792 }
Jeff Brown4d396052010-10-29 21:50:21 -07003793 if ((mEndcallBehavior
3794 & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) {
Jeff Brown96307042012-07-27 15:51:34 -07003795 result = (result & ~ACTION_WAKE_UP) | ACTION_GO_TO_SLEEP;
Jeff Brown4d396052010-10-29 21:50:21 -07003796 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003797 }
Jeff Brown4d396052010-10-29 21:50:21 -07003798 }
3799 break;
3800 }
3801
3802 case KeyEvent.KEYCODE_POWER: {
3803 result &= ~ACTION_PASS_TO_USER;
3804 if (down) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003805 if (isScreenOn && !mPowerKeyTriggered
3806 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
3807 mPowerKeyTriggered = true;
3808 mPowerKeyTime = event.getDownTime();
3809 interceptScreenshotChord();
Winson Chung9112ec32011-06-27 13:15:32 -07003810 }
Winson Chung9112ec32011-06-27 13:15:32 -07003811
Jeff Brown4d396052010-10-29 21:50:21 -07003812 ITelephony telephonyService = getTelephonyService();
3813 boolean hungUp = false;
3814 if (telephonyService != null) {
3815 try {
3816 if (telephonyService.isRinging()) {
3817 // Pressing Power while there's a ringing incoming
3818 // call should silence the ringer.
3819 telephonyService.silenceRinger();
3820 } else if ((mIncallPowerBehavior
3821 & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0
3822 && telephonyService.isOffhook()) {
3823 // Otherwise, if "Power button ends call" is enabled,
3824 // the Power button will hang up any current active call.
3825 hungUp = telephonyService.endCall();
3826 }
3827 } catch (RemoteException ex) {
3828 Log.w(TAG, "ITelephony threw RemoteException", ex);
3829 }
3830 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003831 interceptPowerKeyDown(!isScreenOn || hungUp
3832 || mVolumeDownKeyTriggered || mVolumeUpKeyTriggered);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003833 } else {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003834 mPowerKeyTriggered = false;
3835 cancelPendingScreenshotChordAction();
3836 if (interceptPowerKeyUp(canceled || mPendingPowerKeyUpCanceled)) {
Jeff Brown96307042012-07-27 15:51:34 -07003837 result = (result & ~ACTION_WAKE_UP) | ACTION_GO_TO_SLEEP;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003838 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003839 mPendingPowerKeyUpCanceled = false;
Jeff Brown4d396052010-10-29 21:50:21 -07003840 }
3841 break;
3842 }
3843
3844 case KeyEvent.KEYCODE_MEDIA_PLAY:
3845 case KeyEvent.KEYCODE_MEDIA_PAUSE:
3846 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
3847 if (down) {
3848 ITelephony telephonyService = getTelephonyService();
3849 if (telephonyService != null) {
3850 try {
3851 if (!telephonyService.isIdle()) {
3852 // Suppress PLAY/PAUSE toggle when phone is ringing or in-call
3853 // to avoid music playback.
3854 break;
3855 }
3856 } catch (RemoteException ex) {
3857 Log.w(TAG, "ITelephony threw RemoteException", ex);
Jeff Brown3122e442010-10-11 23:32:49 -07003858 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003859 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003860 }
Jeff Brown4d396052010-10-29 21:50:21 -07003861 case KeyEvent.KEYCODE_HEADSETHOOK:
3862 case KeyEvent.KEYCODE_MUTE:
3863 case KeyEvent.KEYCODE_MEDIA_STOP:
3864 case KeyEvent.KEYCODE_MEDIA_NEXT:
3865 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
3866 case KeyEvent.KEYCODE_MEDIA_REWIND:
3867 case KeyEvent.KEYCODE_MEDIA_RECORD:
3868 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD: {
3869 if ((result & ACTION_PASS_TO_USER) == 0) {
3870 // Only do this if we would otherwise not pass it to the user. In that
3871 // case, the PhoneWindow class will do the same thing, except it will
3872 // only do it if the showing app doesn't process the key on its own.
Jeff Brown40013652012-05-16 21:22:36 -07003873 // Note that we need to make a copy of the key event here because the
3874 // original key event will be recycled when we return.
Jeff Brown4d396052010-10-29 21:50:21 -07003875 mBroadcastWakeLock.acquire();
Jeff Brown40013652012-05-16 21:22:36 -07003876 Message msg = mHandler.obtainMessage(MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK,
3877 new KeyEvent(event));
3878 msg.setAsynchronous(true);
3879 msg.sendToTarget();
Jeff Brown4d396052010-10-29 21:50:21 -07003880 }
3881 break;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003882 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003883
Jeff Brown4d396052010-10-29 21:50:21 -07003884 case KeyEvent.KEYCODE_CALL: {
3885 if (down) {
3886 ITelephony telephonyService = getTelephonyService();
3887 if (telephonyService != null) {
3888 try {
3889 if (telephonyService.isRinging()) {
3890 Log.i(TAG, "interceptKeyBeforeQueueing:"
3891 + " CALL key-down while ringing: Answer the call!");
3892 telephonyService.answerRingingCall();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003893
Jeff Brown4d396052010-10-29 21:50:21 -07003894 // And *don't* pass this key thru to the current activity
3895 // (which is presumably the InCallScreen.)
3896 result &= ~ACTION_PASS_TO_USER;
3897 }
3898 } catch (RemoteException ex) {
3899 Log.w(TAG, "ITelephony threw RemoteException", ex);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003900 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003901 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003902 }
Jeff Brown4d396052010-10-29 21:50:21 -07003903 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003904 }
3905 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003906 return result;
3907 }
3908
Jeff Brown1c2e4942012-11-06 16:32:01 -08003909 /**
3910 * When the screen is off we ignore some keys that might otherwise typically
3911 * be considered wake keys. We filter them out here.
3912 *
3913 * {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it
3914 * is always considered a wake key.
3915 */
3916 private boolean isWakeKeyWhenScreenOff(int keyCode) {
3917 switch (keyCode) {
3918 // ignore volume keys unless docked
3919 case KeyEvent.KEYCODE_VOLUME_UP:
3920 case KeyEvent.KEYCODE_VOLUME_DOWN:
3921 case KeyEvent.KEYCODE_VOLUME_MUTE:
3922 return mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED;
3923
3924 // ignore media and camera keys
3925 case KeyEvent.KEYCODE_MUTE:
3926 case KeyEvent.KEYCODE_HEADSETHOOK:
3927 case KeyEvent.KEYCODE_MEDIA_PLAY:
3928 case KeyEvent.KEYCODE_MEDIA_PAUSE:
3929 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
3930 case KeyEvent.KEYCODE_MEDIA_STOP:
3931 case KeyEvent.KEYCODE_MEDIA_NEXT:
3932 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
3933 case KeyEvent.KEYCODE_MEDIA_REWIND:
3934 case KeyEvent.KEYCODE_MEDIA_RECORD:
3935 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
3936 case KeyEvent.KEYCODE_CAMERA:
3937 return false;
3938 }
3939 return true;
3940 }
3941
3942
Jeff Brown56194eb2011-03-02 19:23:13 -08003943 /** {@inheritDoc} */
3944 @Override
3945 public int interceptMotionBeforeQueueingWhenScreenOff(int policyFlags) {
3946 int result = 0;
3947
3948 final boolean isWakeMotion = (policyFlags
3949 & (WindowManagerPolicy.FLAG_WAKE | WindowManagerPolicy.FLAG_WAKE_DROPPED)) != 0;
3950 if (isWakeMotion) {
Mike Lockwood3a74bd32011-08-12 13:55:22 -07003951 if (mKeyguardMediator != null && mKeyguardMediator.isShowing()) {
Jeff Brown56194eb2011-03-02 19:23:13 -08003952 // If the keyguard is showing, let it decide what to do with the wake motion.
3953 mKeyguardMediator.onWakeMotionWhenKeyguardShowingTq();
3954 } else {
3955 // Otherwise, wake the device ourselves.
Jeff Brown96307042012-07-27 15:51:34 -07003956 result |= ACTION_WAKE_UP;
Jeff Brown56194eb2011-03-02 19:23:13 -08003957 }
3958 }
3959 return result;
3960 }
3961
Jeff Brown40013652012-05-16 21:22:36 -07003962 void dispatchMediaKeyWithWakeLock(KeyEvent event) {
3963 if (DEBUG_INPUT) {
3964 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: " + event);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003965 }
3966
Jeff Brown40013652012-05-16 21:22:36 -07003967 if (mHavePendingMediaKeyRepeatWithWakeLock) {
3968 if (DEBUG_INPUT) {
3969 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: canceled repeat");
3970 }
3971
3972 mHandler.removeMessages(MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK);
3973 mHavePendingMediaKeyRepeatWithWakeLock = false;
3974 mBroadcastWakeLock.release(); // pending repeat was holding onto the wake lock
3975 }
3976
3977 dispatchMediaKeyWithWakeLockToAudioService(event);
3978
3979 if (event.getAction() == KeyEvent.ACTION_DOWN
3980 && event.getRepeatCount() == 0) {
3981 mHavePendingMediaKeyRepeatWithWakeLock = true;
3982
3983 Message msg = mHandler.obtainMessage(
3984 MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK, event);
3985 msg.setAsynchronous(true);
3986 mHandler.sendMessageDelayed(msg, ViewConfiguration.getKeyRepeatTimeout());
3987 } else {
3988 mBroadcastWakeLock.release();
3989 }
3990 }
3991
3992 void dispatchMediaKeyRepeatWithWakeLock(KeyEvent event) {
3993 mHavePendingMediaKeyRepeatWithWakeLock = false;
3994
3995 KeyEvent repeatEvent = KeyEvent.changeTimeRepeat(event,
3996 SystemClock.uptimeMillis(), 1, event.getFlags() | KeyEvent.FLAG_LONG_PRESS);
3997 if (DEBUG_INPUT) {
3998 Slog.d(TAG, "dispatchMediaKeyRepeatWithWakeLock: " + repeatEvent);
3999 }
4000
4001 dispatchMediaKeyWithWakeLockToAudioService(repeatEvent);
4002 mBroadcastWakeLock.release();
4003 }
4004
4005 void dispatchMediaKeyWithWakeLockToAudioService(KeyEvent event) {
4006 if (ActivityManagerNative.isSystemReady()) {
4007 IAudioService audioService = getAudioService();
4008 if (audioService != null) {
4009 try {
4010 audioService.dispatchMediaKeyEventUnderWakelock(event);
4011 } catch (RemoteException e) {
4012 Log.e(TAG, "dispatchMediaKeyEvent threw exception " + e);
Jean-Michel Trivic6802222012-04-30 11:15:03 -07004013 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004014 }
4015 }
4016 }
4017
Mike Lockwood1753f7f2009-08-24 14:49:07 -07004018 BroadcastReceiver mDockReceiver = new BroadcastReceiver() {
Craig Mautnereee29c42013-01-17 14:44:34 -08004019 @Override
Mike Lockwood1753f7f2009-08-24 14:49:07 -07004020 public void onReceive(Context context, Intent intent) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07004021 if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) {
4022 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
4023 Intent.EXTRA_DOCK_STATE_UNDOCKED);
Daniel Sandler6396c722013-04-16 20:19:09 -04004024 } else {
4025 try {
4026 IUiModeManager uiModeService = IUiModeManager.Stub.asInterface(
4027 ServiceManager.getService(Context.UI_MODE_SERVICE));
4028 mUiMode = uiModeService.getCurrentModeType();
4029 } catch (RemoteException e) {
4030 }
Dianne Hackborn80fa1662009-10-07 14:02:10 -07004031 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004032 updateRotation(true);
Craig Mautnereee29c42013-01-17 14:44:34 -08004033 synchronized (mLock) {
4034 updateOrientationListenerLp();
4035 }
Mike Lockwood1753f7f2009-08-24 14:49:07 -07004036 }
4037 };
4038
Jeff Brown6aaf2952012-10-05 16:01:08 -07004039 BroadcastReceiver mDreamReceiver = new BroadcastReceiver() {
4040 @Override
4041 public void onReceive(Context context, Intent intent) {
4042 if (Intent.ACTION_DREAMING_STARTED.equals(intent.getAction())) {
4043 if (mKeyguardMediator != null) {
4044 mKeyguardMediator.onDreamingStarted();
4045 }
4046 } else if (Intent.ACTION_DREAMING_STOPPED.equals(intent.getAction())) {
4047 if (mKeyguardMediator != null) {
4048 mKeyguardMediator.onDreamingStopped();
4049 }
4050 }
4051 }
4052 };
4053
Christopher Tate5e08af02012-09-21 17:17:22 -07004054 BroadcastReceiver mMultiuserReceiver = new BroadcastReceiver() {
4055 @Override
4056 public void onReceive(Context context, Intent intent) {
4057 if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) {
4058 // tickle the settings observer: this first ensures that we're
4059 // observing the relevant settings for the newly-active user,
4060 // and then updates our own bookkeeping based on the now-
4061 // current user.
4062 mSettingsObserver.onChange(false);
John Spurlockce479d82012-11-29 09:52:21 -05004063
4064 // force a re-application of focused window sysui visibility.
4065 // the window may never have been shown for this user
4066 // e.g. the keyguard when going through the new-user setup flow
4067 synchronized(mLock) {
4068 mLastSystemUiFlags = 0;
4069 updateSystemUiVisibilityLw();
4070 }
Christopher Tate5e08af02012-09-21 17:17:22 -07004071 }
4072 }
4073 };
4074
Jeff Brownc38c9be2012-10-04 13:16:19 -07004075 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004076 public void screenTurnedOff(int why) {
Dianne Hackborn74489012009-03-24 20:50:09 -07004077 EventLog.writeEvent(70000, 0);
The Android Open Source Project0727d222009-03-11 12:11:58 -07004078 synchronized (mLock) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004079 mScreenOnEarly = false;
4080 mScreenOnFully = false;
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07004081 }
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004082 if (mKeyguardMediator != null) {
4083 mKeyguardMediator.onScreenTurnedOff(why);
4084 }
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07004085 synchronized (mLock) {
The Android Open Source Project0727d222009-03-11 12:11:58 -07004086 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05004087 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07004088 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004089 }
4090
Jeff Brownc38c9be2012-10-04 13:16:19 -07004091 @Override
Dianne Hackborn38e29a62011-09-18 14:43:08 -07004092 public void screenTurningOn(final ScreenOnListener screenOnListener) {
Dianne Hackborn74489012009-03-24 20:50:09 -07004093 EventLog.writeEvent(70000, 1);
Dianne Hackborn40011092011-09-22 13:37:48 -07004094 if (false) {
4095 RuntimeException here = new RuntimeException("here");
4096 here.fillInStackTrace();
4097 Slog.i(TAG, "Screen turning on...", here);
4098 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07004099
The Android Open Source Project0727d222009-03-11 12:11:58 -07004100 synchronized (mLock) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004101 mScreenOnEarly = true;
The Android Open Source Project0727d222009-03-11 12:11:58 -07004102 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05004103 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07004104 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07004105
Jeff Brownc38c9be2012-10-04 13:16:19 -07004106 waitForKeyguard(screenOnListener);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004107 }
4108
Jeff Brownc38c9be2012-10-04 13:16:19 -07004109 private void waitForKeyguard(final ScreenOnListener screenOnListener) {
4110 if (mKeyguardMediator != null) {
4111 if (screenOnListener != null) {
4112 mKeyguardMediator.onScreenTurnedOn(new KeyguardViewManager.ShowListener() {
4113 @Override
4114 public void onShown(IBinder windowToken) {
4115 waitForKeyguardWindowDrawn(windowToken, screenOnListener);
4116 }
4117 });
4118 return;
4119 } else {
4120 mKeyguardMediator.onScreenTurnedOn(null);
4121 }
4122 } else {
4123 Slog.i(TAG, "No keyguard mediator!");
4124 }
4125 finishScreenTurningOn(screenOnListener);
4126 }
4127
4128 private void waitForKeyguardWindowDrawn(IBinder windowToken,
4129 final ScreenOnListener screenOnListener) {
4130 if (windowToken != null) {
4131 try {
4132 if (mWindowManager.waitForWindowDrawn(
4133 windowToken, new IRemoteCallback.Stub() {
4134 @Override
4135 public void sendResult(Bundle data) {
4136 Slog.i(TAG, "Lock screen displayed!");
4137 finishScreenTurningOn(screenOnListener);
4138 }
4139 })) {
4140 return;
4141 }
4142 } catch (RemoteException ex) {
4143 // Can't happen in system process.
4144 }
4145 }
4146
4147 Slog.i(TAG, "No lock screen!");
4148 finishScreenTurningOn(screenOnListener);
4149 }
4150
4151 private void finishScreenTurningOn(ScreenOnListener screenOnListener) {
4152 synchronized (mLock) {
4153 mScreenOnFully = true;
4154 }
4155
Jeff Brown4fc45272012-10-10 18:28:14 -07004156 try {
4157 mWindowManager.setEventDispatching(true);
4158 } catch (RemoteException unhandled) {
4159 }
4160
Jeff Brownc38c9be2012-10-04 13:16:19 -07004161 if (screenOnListener != null) {
4162 screenOnListener.onScreenOn();
4163 }
4164 }
4165
4166 @Override
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004167 public boolean isScreenOnEarly() {
4168 return mScreenOnEarly;
4169 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07004170
4171 @Override
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004172 public boolean isScreenOnFully() {
4173 return mScreenOnFully;
Dianne Hackborn08743722009-12-21 12:16:51 -08004174 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07004175
Dianne Hackborn08743722009-12-21 12:16:51 -08004176 /** {@inheritDoc} */
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004177 public void enableKeyguard(boolean enabled) {
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004178 if (mKeyguardMediator != null) {
4179 mKeyguardMediator.setKeyguardEnabled(enabled);
4180 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004181 }
4182
4183 /** {@inheritDoc} */
4184 public void exitKeyguardSecurely(OnKeyguardExitResult callback) {
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004185 if (mKeyguardMediator != null) {
4186 mKeyguardMediator.verifyUnlock(callback);
4187 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004188 }
4189
Mike Lockwoodf7913302009-11-28 22:27:10 -05004190 private boolean keyguardIsShowingTq() {
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004191 if (mKeyguardMediator == null) return false;
Dianne Hackborn9dc06cc2009-11-17 18:19:23 -08004192 return mKeyguardMediator.isShowingAndNotHidden();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004193 }
4194
Mike Lockwood520d8bc2011-02-18 13:23:13 -05004195
4196 /** {@inheritDoc} */
4197 public boolean isKeyguardLocked() {
4198 return keyguardOn();
4199 }
4200
4201 /** {@inheritDoc} */
4202 public boolean isKeyguardSecure() {
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004203 if (mKeyguardMediator == null) return false;
Mike Lockwood520d8bc2011-02-18 13:23:13 -05004204 return mKeyguardMediator.isSecure();
4205 }
4206
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004207 /** {@inheritDoc} */
4208 public boolean inKeyguardRestrictedKeyInputMode() {
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004209 if (mKeyguardMediator == null) return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004210 return mKeyguardMediator.isInputRestricted();
4211 }
4212
Dianne Hackborn90c52de2011-09-23 12:57:44 -07004213 public void dismissKeyguardLw() {
Daniel Sandler1ce804392012-11-07 15:07:12 -05004214 if (mKeyguardMediator.isShowing()) {
4215 mHandler.post(new Runnable() {
4216 public void run() {
4217 if (mKeyguardMediator.isDismissable()) {
4218 // Can we just finish the keyguard straight away?
Dianne Hackborn90c52de2011-09-23 12:57:44 -07004219 mKeyguardMediator.keyguardDone(false, true);
Daniel Sandler1ce804392012-11-07 15:07:12 -05004220 } else {
4221 // ask the keyguard to prompt the user to authenticate if necessary
4222 mKeyguardMediator.dismiss();
Dianne Hackborn90c52de2011-09-23 12:57:44 -07004223 }
Daniel Sandler1ce804392012-11-07 15:07:12 -05004224 }
4225 });
Dianne Hackborn90c52de2011-09-23 12:57:44 -07004226 }
4227 }
4228
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004229 void sendCloseSystemWindows() {
4230 sendCloseSystemWindows(mContext, null);
4231 }
4232
4233 void sendCloseSystemWindows(String reason) {
4234 sendCloseSystemWindows(mContext, reason);
4235 }
4236
4237 static void sendCloseSystemWindows(Context context, String reason) {
4238 if (ActivityManagerNative.isSystemReady()) {
Dianne Hackborn94a679d2009-07-28 17:51:07 -07004239 try {
4240 ActivityManagerNative.getDefault().closeSystemDialogs(reason);
4241 } catch (RemoteException e) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004242 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004243 }
4244 }
Mitsuru Oshima831d0d92009-06-16 18:27:18 -07004245
Jeff Brown01a98dd2011-09-20 15:08:29 -07004246 @Override
4247 public int rotationForOrientationLw(int orientation, int lastRotation) {
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05004248 if (false) {
4249 Slog.v(TAG, "rotationForOrientationLw(orient="
4250 + orientation + ", last=" + lastRotation
4251 + "); user=" + mUserRotation + " "
4252 + ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED)
4253 ? "USER_ROTATION_LOCKED" : "")
4254 );
4255 }
4256
The Android Open Source Project0727d222009-03-11 12:11:58 -07004257 synchronized (mLock) {
Jeff Brownc0347aa2011-09-23 17:26:09 -07004258 int sensorRotation = mOrientationListener.getProposedRotation(); // may be -1
4259 if (sensorRotation < 0) {
Jeff Brown0f862b42012-09-27 21:11:01 -07004260 sensorRotation = lastRotation;
Jeff Brownc0347aa2011-09-23 17:26:09 -07004261 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004262
Jeff Browndec6cf42011-11-15 14:08:20 -08004263 final int preferredRotation;
Jeff Brown2e7760e2012-04-11 15:14:55 -07004264 if (mLidState == LID_OPEN && mLidOpenRotation >= 0) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07004265 // Ignore sensor when lid switch is open and rotation is forced.
4266 preferredRotation = mLidOpenRotation;
4267 } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR
Jeff Brownc0347aa2011-09-23 17:26:09 -07004268 && (mCarDockEnablesAccelerometer || mCarDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07004269 // Ignore sensor when in car dock unless explicitly enabled.
4270 // This case can override the behavior of NOSENSOR, and can also
4271 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07004272 preferredRotation = mCarDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07004273 ? sensorRotation : mCarDockRotation;
Jeff Brown1a693182011-11-08 14:44:16 -08004274 } else if ((mDockMode == Intent.EXTRA_DOCK_STATE_DESK
4275 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
4276 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK)
Jeff Brownc0347aa2011-09-23 17:26:09 -07004277 && (mDeskDockEnablesAccelerometer || mDeskDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07004278 // Ignore sensor when in desk dock unless explicitly enabled.
4279 // This case can override the behavior of NOSENSOR, and can also
4280 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07004281 preferredRotation = mDeskDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07004282 ? sensorRotation : mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -07004283 } else if (mHdmiPlugged && mDemoHdmiRotationLock) {
4284 // Ignore sensor when plugged into HDMI when demo HDMI rotation lock enabled.
Jeff Browneb3e4b92011-12-06 19:54:24 -08004285 // Note that the dock orientation overrides the HDMI orientation.
Jeff Brownc82c89ed2013-04-17 17:18:15 -07004286 preferredRotation = mDemoHdmiRotation;
4287 } else if (mHdmiPlugged && mDockMode == Intent.EXTRA_DOCK_STATE_UNDOCKED
4288 && mUndockedHdmiRotation >= 0) {
4289 // Ignore sensor when plugged into HDMI and an undocked orientation has
4290 // been specified in the configuration (only for legacy devices without
4291 // full multi-display support).
4292 // Note that the dock orientation overrides the HDMI orientation.
4293 preferredRotation = mUndockedHdmiRotation;
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07004294 } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED) {
4295 // Application just wants to remain locked in the last rotation.
4296 preferredRotation = lastRotation;
Jeff Brown207673cd2012-06-05 17:47:11 -07004297 } else if ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE
Jeff Brown01a98dd2011-09-20 15:08:29 -07004298 && (orientation == ActivityInfo.SCREEN_ORIENTATION_USER
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07004299 || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
4300 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
4301 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
4302 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER))
Jeff Brown01a98dd2011-09-20 15:08:29 -07004303 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
4304 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
4305 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
4306 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) {
4307 // Otherwise, use sensor only if requested by the application or enabled
4308 // by default for USER or UNSPECIFIED modes. Does not apply to NOSENSOR.
Jeff Brownd3187e32011-09-21 19:26:44 -07004309 if (mAllowAllRotations < 0) {
4310 // Can't read this during init() because the context doesn't
4311 // have display metrics at that time so we cannot determine
4312 // tablet vs. phone then.
4313 mAllowAllRotations = mContext.getResources().getBoolean(
4314 com.android.internal.R.bool.config_allowAllRotations) ? 1 : 0;
4315 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004316 if (sensorRotation != Surface.ROTATION_180
Jeff Brownd3187e32011-09-21 19:26:44 -07004317 || mAllowAllRotations == 1
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07004318 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
4319 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07004320 preferredRotation = sensorRotation;
4321 } else {
4322 preferredRotation = lastRotation;
4323 }
Jeff Brown207673cd2012-06-05 17:47:11 -07004324 } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED
4325 && orientation != ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) {
4326 // Apply rotation lock. Does not apply to NOSENSOR.
4327 // The idea is that the user rotation expresses a weak preference for the direction
4328 // of gravity and as NOSENSOR is never affected by gravity, then neither should
4329 // NOSENSOR be affected by rotation lock (although it will be affected by docks).
Jeff Brown4dfce202011-10-05 12:00:10 -07004330 preferredRotation = mUserRotation;
Jeff Browndec6cf42011-11-15 14:08:20 -08004331 } else {
4332 // No overriding preference.
4333 // We will do exactly what the application asked us to do.
4334 preferredRotation = -1;
Jeff Brown01a98dd2011-09-20 15:08:29 -07004335 }
4336
Dianne Hackborne5439f22010-10-02 16:53:50 -07004337 switch (orientation) {
4338 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08004339 // Return portrait unless overridden.
4340 if (isAnyPortrait(preferredRotation)) {
4341 return preferredRotation;
4342 }
Dianne Hackborne5439f22010-10-02 16:53:50 -07004343 return mPortraitRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07004344
Jeff Brown01a98dd2011-09-20 15:08:29 -07004345 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08004346 // Return landscape unless overridden.
4347 if (isLandscapeOrSeascape(preferredRotation)) {
4348 return preferredRotation;
4349 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004350 return mLandscapeRotation;
4351
4352 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08004353 // Return reverse portrait unless overridden.
4354 if (isAnyPortrait(preferredRotation)) {
4355 return preferredRotation;
4356 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004357 return mUpsideDownRotation;
4358
4359 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08004360 // Return seascape unless overridden.
4361 if (isLandscapeOrSeascape(preferredRotation)) {
4362 return preferredRotation;
4363 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004364 return mSeascapeRotation;
4365
4366 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07004367 case ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE:
Jeff Brown01a98dd2011-09-20 15:08:29 -07004368 // Return either landscape rotation.
4369 if (isLandscapeOrSeascape(preferredRotation)) {
4370 return preferredRotation;
4371 }
4372 if (isLandscapeOrSeascape(lastRotation)) {
Jeff Brown4519f072011-01-23 13:16:01 -08004373 return lastRotation;
4374 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004375 return mLandscapeRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004376
Jeff Brown01a98dd2011-09-20 15:08:29 -07004377 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07004378 case ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT:
Jeff Brown01a98dd2011-09-20 15:08:29 -07004379 // Return either portrait rotation.
4380 if (isAnyPortrait(preferredRotation)) {
4381 return preferredRotation;
4382 }
4383 if (isAnyPortrait(lastRotation)) {
4384 return lastRotation;
4385 }
4386 return mPortraitRotation;
4387
4388 default:
Jeff Brown4dfce202011-10-05 12:00:10 -07004389 // For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR,
4390 // just return the preferred orientation we already calculated.
Jeff Brown01a98dd2011-09-20 15:08:29 -07004391 if (preferredRotation >= 0) {
4392 return preferredRotation;
4393 }
Dianne Hackborndacea8c2011-04-21 17:26:39 -07004394 return Surface.ROTATION_0;
Daniel Sandlere7e5ac22011-02-22 16:10:21 -05004395 }
4396 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07004397 }
4398
Jeff Brown01a98dd2011-09-20 15:08:29 -07004399 @Override
4400 public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation) {
4401 switch (orientation) {
4402 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
4403 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
4404 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
4405 return isAnyPortrait(rotation);
4406
4407 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
4408 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
4409 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
4410 return isLandscapeOrSeascape(rotation);
4411
4412 default:
4413 return true;
4414 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07004415 }
4416
Jeff Brownc0347aa2011-09-23 17:26:09 -07004417 @Override
4418 public void setRotationLw(int rotation) {
4419 mOrientationListener.setCurrentRotation(rotation);
4420 }
4421
Jeff Brown01a98dd2011-09-20 15:08:29 -07004422 private boolean isLandscapeOrSeascape(int rotation) {
4423 return rotation == mLandscapeRotation || rotation == mSeascapeRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07004424 }
4425
Jeff Brown01a98dd2011-09-20 15:08:29 -07004426 private boolean isAnyPortrait(int rotation) {
4427 return rotation == mPortraitRotation || rotation == mUpsideDownRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07004428 }
4429
Svetoslav Ganov80943d82013-01-02 10:25:37 -08004430 public int getUserRotationMode() {
4431 return Settings.System.getIntForUser(mContext.getContentResolver(),
Brett Chabot7e55c402013-05-16 19:38:08 -07004432 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
4433 WindowManagerPolicy.USER_ROTATION_FREE :
4434 WindowManagerPolicy.USER_ROTATION_LOCKED;
Svetoslav Ganov80943d82013-01-02 10:25:37 -08004435 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004436
4437 // User rotation: to be used when all else fails in assigning an orientation to the device
4438 public void setUserRotationMode(int mode, int rot) {
4439 ContentResolver res = mContext.getContentResolver();
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05004440
4441 // mUserRotationMode and mUserRotation will be assigned by the content observer
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004442 if (mode == WindowManagerPolicy.USER_ROTATION_LOCKED) {
Christopher Tate5e08af02012-09-21 17:17:22 -07004443 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004444 Settings.System.USER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07004445 rot,
4446 UserHandle.USER_CURRENT);
4447 Settings.System.putIntForUser(res,
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05004448 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07004449 0,
4450 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004451 } else {
Christopher Tate5e08af02012-09-21 17:17:22 -07004452 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004453 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07004454 1,
4455 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004456 }
4457 }
4458
Jeff Brownac143512012-04-05 18:57:33 -07004459 public void setSafeMode(boolean safeMode) {
4460 mSafeMode = safeMode;
4461 performHapticFeedbackLw(null, safeMode
4462 ? HapticFeedbackConstants.SAFE_MODE_ENABLED
4463 : HapticFeedbackConstants.SAFE_MODE_DISABLED, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004464 }
4465
Dianne Hackborn181ceb52009-08-27 22:16:40 -07004466 static long[] getLongIntArray(Resources r, int resid) {
4467 int[] ar = r.getIntArray(resid);
4468 if (ar == null) {
4469 return null;
4470 }
4471 long[] out = new long[ar.length];
4472 for (int i=0; i<ar.length; i++) {
4473 out[i] = ar[i];
4474 }
4475 return out;
4476 }
4477
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004478 /** {@inheritDoc} */
4479 public void systemReady() {
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004480 if (mKeyguardMediator != null) {
4481 // tell the keyguard
4482 mKeyguardMediator.onSystemReady();
4483 }
Dianne Hackbornb1a79802009-09-29 15:18:31 -07004484 synchronized (mLock) {
4485 updateOrientationListenerLp();
Dianne Hackbornc777e072010-02-12 13:07:59 -08004486 mSystemReady = true;
4487 mHandler.post(new Runnable() {
4488 public void run() {
4489 updateSettings();
4490 }
4491 });
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004492 }
4493 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07004494
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07004495 /** {@inheritDoc} */
4496 public void systemBooted() {
4497 synchronized (mLock) {
4498 mSystemBooted = true;
4499 }
4500 }
4501
Dianne Hackborn661cd522011-08-22 00:26:20 -07004502 ProgressDialog mBootMsgDialog = null;
4503
4504 /** {@inheritDoc} */
4505 public void showBootMessage(final CharSequence msg, final boolean always) {
Mike Lockwoodaa5bf142011-09-21 13:03:40 -04004506 if (mHeadless) return;
Dianne Hackborn661cd522011-08-22 00:26:20 -07004507 mHandler.post(new Runnable() {
4508 @Override public void run() {
4509 if (mBootMsgDialog == null) {
Dianne Hackborn295e3c22011-08-25 13:19:08 -07004510 mBootMsgDialog = new ProgressDialog(mContext) {
4511 // This dialog will consume all events coming in to
4512 // it, to avoid it trying to do things too early in boot.
4513 @Override public boolean dispatchKeyEvent(KeyEvent event) {
4514 return true;
4515 }
4516 @Override public boolean dispatchKeyShortcutEvent(KeyEvent event) {
4517 return true;
4518 }
4519 @Override public boolean dispatchTouchEvent(MotionEvent ev) {
4520 return true;
4521 }
4522 @Override public boolean dispatchTrackballEvent(MotionEvent ev) {
4523 return true;
4524 }
4525 @Override public boolean dispatchGenericMotionEvent(MotionEvent ev) {
4526 return true;
4527 }
4528 @Override public boolean dispatchPopulateAccessibilityEvent(
4529 AccessibilityEvent event) {
4530 return true;
4531 }
4532 };
Dianne Hackborn661cd522011-08-22 00:26:20 -07004533 mBootMsgDialog.setTitle(R.string.android_upgrading_title);
4534 mBootMsgDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
4535 mBootMsgDialog.setIndeterminate(true);
4536 mBootMsgDialog.getWindow().setType(
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07004537 WindowManager.LayoutParams.TYPE_BOOT_PROGRESS);
Dianne Hackborn661cd522011-08-22 00:26:20 -07004538 mBootMsgDialog.getWindow().addFlags(
4539 WindowManager.LayoutParams.FLAG_DIM_BEHIND
4540 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
4541 mBootMsgDialog.getWindow().setDimAmount(1);
Dianne Hackbornd9efb952011-12-07 14:56:51 -08004542 WindowManager.LayoutParams lp = mBootMsgDialog.getWindow().getAttributes();
4543 lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
4544 mBootMsgDialog.getWindow().setAttributes(lp);
Dianne Hackborn661cd522011-08-22 00:26:20 -07004545 mBootMsgDialog.setCancelable(false);
4546 mBootMsgDialog.show();
4547 }
4548 mBootMsgDialog.setMessage(msg);
4549 }
4550 });
4551 }
4552
4553 /** {@inheritDoc} */
4554 public void hideBootMessages() {
4555 mHandler.post(new Runnable() {
4556 @Override public void run() {
4557 if (mBootMsgDialog != null) {
4558 mBootMsgDialog.dismiss();
4559 mBootMsgDialog = null;
4560 }
4561 }
4562 });
4563 }
4564
Mike Lockwood28569302010-01-28 11:54:40 -05004565 /** {@inheritDoc} */
4566 public void userActivity() {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004567 // ***************************************
4568 // NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
4569 // ***************************************
4570 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
4571 // WITH ITS LOCKS HELD.
4572 //
4573 // This code must be VERY careful about the locks
4574 // it acquires.
4575 // In fact, the current code acquires way too many,
4576 // and probably has lurking deadlocks.
4577
Mike Lockwood28569302010-01-28 11:54:40 -05004578 synchronized (mScreenLockTimeout) {
4579 if (mLockScreenTimerActive) {
4580 // reset the timer
4581 mHandler.removeCallbacks(mScreenLockTimeout);
4582 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
4583 }
4584 }
Daniel Sandler0601eb72011-04-13 01:01:32 -04004585 }
4586
Adam Cohenf7522022012-10-03 20:03:18 -07004587 class ScreenLockTimeout implements Runnable {
4588 Bundle options;
4589
4590 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05004591 public void run() {
4592 synchronized (this) {
4593 if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard");
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004594 if (mKeyguardMediator != null) {
Adam Cohenf7522022012-10-03 20:03:18 -07004595 mKeyguardMediator.doKeyguardTimeout(options);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004596 }
Mike Lockwood28569302010-01-28 11:54:40 -05004597 mLockScreenTimerActive = false;
Adam Cohenf7522022012-10-03 20:03:18 -07004598 options = null;
Mike Lockwood28569302010-01-28 11:54:40 -05004599 }
4600 }
Mike Lockwood28569302010-01-28 11:54:40 -05004601
Adam Cohenf7522022012-10-03 20:03:18 -07004602 public void setLockOptions(Bundle options) {
4603 this.options = options;
4604 }
4605 }
4606
4607 ScreenLockTimeout mScreenLockTimeout = new ScreenLockTimeout();
4608
4609 public void lockNow(Bundle options) {
Jim Miller93c518e2012-01-17 15:55:31 -08004610 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null);
4611 mHandler.removeCallbacks(mScreenLockTimeout);
Adam Cohenf7522022012-10-03 20:03:18 -07004612 if (options != null) {
4613 // In case multiple calls are made to lockNow, we don't wipe out the options
4614 // until the runnable actually executes.
4615 mScreenLockTimeout.setLockOptions(options);
4616 }
Jim Miller93c518e2012-01-17 15:55:31 -08004617 mHandler.post(mScreenLockTimeout);
4618 }
4619
Mike Lockwood28569302010-01-28 11:54:40 -05004620 private void updateLockScreenTimeout() {
4621 synchronized (mScreenLockTimeout) {
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004622 boolean enable = (mAllowLockscreenWhenOn && mScreenOnEarly &&
4623 mKeyguardMediator != null && mKeyguardMediator.isSecure());
Mike Lockwood28569302010-01-28 11:54:40 -05004624 if (mLockScreenTimerActive != enable) {
4625 if (enable) {
4626 if (localLOGV) Log.v(TAG, "setting lockscreen timer");
4627 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
4628 } else {
4629 if (localLOGV) Log.v(TAG, "clearing lockscreen timer");
4630 mHandler.removeCallbacks(mScreenLockTimeout);
4631 }
4632 mLockScreenTimerActive = enable;
4633 }
4634 }
4635 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004636
4637 /** {@inheritDoc} */
4638 public void enableScreenAfterBoot() {
4639 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07004640 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07004641 updateRotation(true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004642 }
Dianne Hackbornf54c8f92009-09-19 14:03:57 -07004643
Jeff Brownc458ce92012-04-30 14:58:40 -07004644 private void applyLidSwitchState() {
Jeff Brownc458ce92012-04-30 14:58:40 -07004645 if (mLidState == LID_CLOSED && mLidControlsSleep) {
4646 mPowerManager.goToSleep(SystemClock.uptimeMillis());
4647 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004648 }
4649
4650 void updateRotation(boolean alwaysSendConfiguration) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004651 try {
4652 //set orientation on WindowManager
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004653 mWindowManager.updateRotation(alwaysSendConfiguration, false);
4654 } catch (RemoteException e) {
4655 // Ignore
4656 }
4657 }
4658
4659 void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) {
4660 try {
4661 //set orientation on WindowManager
4662 mWindowManager.updateRotation(alwaysSendConfiguration, forceRelayout);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004663 } catch (RemoteException e) {
4664 // Ignore
4665 }
4666 }
4667
Daniel Sandler6396c722013-04-16 20:19:09 -04004668 /**
4669 * Return an Intent to launch the currently active dock app as home. Returns
4670 * null if the standard home should be launched, which is the case if any of the following is
4671 * true:
4672 * <ul>
4673 * <li>The device is not in either car mode or desk mode
4674 * <li>The device is in car mode but ENABLE_CAR_DOCK_HOME_CAPTURE is false
4675 * <li>The device is in desk mode but ENABLE_DESK_DOCK_HOME_CAPTURE is false
4676 * <li>The device is in car mode but there's no CAR_DOCK app with METADATA_DOCK_HOME
4677 * <li>The device is in desk mode but there's no DESK_DOCK app with METADATA_DOCK_HOME
4678 * </ul>
4679 * @return
4680 */
4681 Intent createHomeDockIntent() {
4682 Intent intent = null;
4683
4684 // What home does is based on the mode, not the dock state. That
4685 // is, when in car mode you should be taken to car home regardless
4686 // of whether we are actually in a car dock.
4687 if (mUiMode == Configuration.UI_MODE_TYPE_CAR) {
4688 if (ENABLE_CAR_DOCK_HOME_CAPTURE) {
4689 intent = mCarDockIntent;
4690 }
4691 } else if (mUiMode == Configuration.UI_MODE_TYPE_DESK) {
4692 if (ENABLE_DESK_DOCK_HOME_CAPTURE) {
4693 intent = mDeskDockIntent;
4694 }
4695 }
4696
4697 if (intent == null) {
4698 return null;
4699 }
4700
4701 ActivityInfo ai = null;
4702 ResolveInfo info = mContext.getPackageManager().resolveActivityAsUser(
4703 intent,
4704 PackageManager.MATCH_DEFAULT_ONLY,
4705 UserHandle.USER_CURRENT);
4706 if (info != null) {
4707 ai = info.activityInfo;
4708 }
4709 if (ai != null
4710 && ai.metaData != null
4711 && ai.metaData.getBoolean(Intent.METADATA_DOCK_HOME)) {
4712 intent = new Intent(intent);
4713 intent.setClassName(ai.packageName, ai.name);
4714 return intent;
4715 }
4716
4717 return null;
4718 }
4719
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004720 void startDockOrHome() {
John Spurlockc8b46ca2013-04-08 12:59:26 -04004721 awakenDreams();
Daniel Sandler6396c722013-04-16 20:19:09 -04004722
4723 Intent dock = createHomeDockIntent();
4724 if (dock != null) {
4725 try {
4726 mContext.startActivityAsUser(dock, UserHandle.CURRENT);
4727 return;
4728 } catch (ActivityNotFoundException e) {
4729 }
4730 }
4731
Dianne Hackbornd8883992012-09-07 15:58:52 -07004732 mContext.startActivityAsUser(mHomeIntent, UserHandle.CURRENT);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004733 }
4734
4735 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004736 * goes to the home screen
4737 * @return whether it did anything
4738 */
4739 boolean goHome() {
4740 if (false) {
4741 // This code always brings home to the front.
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07004742 try {
4743 ActivityManagerNative.getDefault().stopAppSwitches();
4744 } catch (RemoteException e) {
4745 }
Dianne Hackborn94a679d2009-07-28 17:51:07 -07004746 sendCloseSystemWindows();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004747 startDockOrHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004748 } else {
4749 // This code brings home to the front or, if it is already
4750 // at the front, puts the device to sleep.
4751 try {
Wink Savilled2e6a332010-02-12 12:12:06 -08004752 if (SystemProperties.getInt("persist.sys.uts-test-mode", 0) == 1) {
4753 /// Roll back EndcallBehavior as the cupcake design to pass P1 lab entry.
4754 Log.d(TAG, "UTS-TEST-MODE");
4755 } else {
4756 ActivityManagerNative.getDefault().stopAppSwitches();
4757 sendCloseSystemWindows();
Daniel Sandler6396c722013-04-16 20:19:09 -04004758 Intent dock = createHomeDockIntent();
4759 if (dock != null) {
4760 int result = ActivityManagerNative.getDefault()
4761 .startActivityAsUser(null, null, dock,
4762 dock.resolveTypeIfNeeded(mContext.getContentResolver()),
4763 null, null, 0,
4764 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
4765 null, null, null, UserHandle.USER_CURRENT);
4766 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
4767 return false;
4768 }
4769 }
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004770 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004771 int result = ActivityManagerNative.getDefault()
Dianne Hackbornf265ea92013-01-31 15:00:51 -08004772 .startActivityAsUser(null, null, mHomeIntent,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004773 mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()),
Dianne Hackborna4972e92012-03-14 10:38:05 -07004774 null, null, 0,
4775 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Dianne Hackborn5e03e2c2012-09-06 14:21:19 -07004776 null, null, null, UserHandle.USER_CURRENT);
Dianne Hackborna4972e92012-03-14 10:38:05 -07004777 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004778 return false;
4779 }
4780 } catch (RemoteException ex) {
4781 // bummer, the activity manager, which is in this process, is dead
4782 }
4783 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004784 return true;
4785 }
4786
The Android Open Source Project0727d222009-03-11 12:11:58 -07004787 public void setCurrentOrientationLw(int newOrientation) {
4788 synchronized (mLock) {
4789 if (newOrientation != mCurrentAppOrientation) {
4790 mCurrentAppOrientation = newOrientation;
4791 updateOrientationListenerLp();
4792 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004793 }
4794 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08004795
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07004796 private void performAuditoryFeedbackForAccessibilityIfNeed() {
4797 if (!isGlobalAccessibilityGestureEnabled()) {
4798 return;
4799 }
4800 AudioManager audioManager = (AudioManager) mContext.getSystemService(
4801 Context.AUDIO_SERVICE);
4802 if (audioManager.isSilentMode()) {
4803 return;
4804 }
4805 Ringtone ringTone = RingtoneManager.getRingtone(mContext,
4806 Settings.System.DEFAULT_NOTIFICATION_URI);
4807 ringTone.setStreamType(AudioManager.STREAM_MUSIC);
4808 ringTone.play();
4809 }
4810 private boolean isGlobalAccessibilityGestureEnabled() {
4811 return Settings.Global.getInt(mContext.getContentResolver(),
4812 Settings.Global.ENABLE_ACCESSIBILITY_GLOBAL_GESTURE_ENABLED, 0) == 1;
4813 }
4814
The Android Open Source Project0727d222009-03-11 12:11:58 -07004815 public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) {
Svetoslav Ganov96179212012-10-10 14:17:45 -07004816 if (!mVibrator.hasVibrator()) {
4817 return false;
4818 }
Christopher Tate5e08af02012-09-21 17:17:22 -07004819 final boolean hapticsDisabled = Settings.System.getIntForUser(mContext.getContentResolver(),
4820 Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) == 0;
Dianne Hackborn9dc06cc2009-11-17 18:19:23 -08004821 if (!always && (hapticsDisabled || mKeyguardMediator.isShowingAndNotHidden())) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004822 return false;
4823 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08004824 long[] pattern = null;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004825 switch (effectId) {
4826 case HapticFeedbackConstants.LONG_PRESS:
Amith Yamasanic33cb712010-02-10 15:21:49 -08004827 pattern = mLongPressVibePattern;
4828 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07004829 case HapticFeedbackConstants.VIRTUAL_KEY:
Amith Yamasanic33cb712010-02-10 15:21:49 -08004830 pattern = mVirtualKeyVibePattern;
4831 break;
4832 case HapticFeedbackConstants.KEYBOARD_TAP:
4833 pattern = mKeyboardTapVibePattern;
4834 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07004835 case HapticFeedbackConstants.SAFE_MODE_DISABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08004836 pattern = mSafeModeDisabledVibePattern;
4837 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07004838 case HapticFeedbackConstants.SAFE_MODE_ENABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08004839 pattern = mSafeModeEnabledVibePattern;
4840 break;
Amith Yamasanic33cb712010-02-10 15:21:49 -08004841 default:
4842 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004843 }
Dianne Hackbornf265ea92013-01-31 15:00:51 -08004844 int owningUid;
4845 String owningPackage;
4846 if (win != null) {
4847 owningUid = win.getOwningUid();
4848 owningPackage = win.getOwningPackage();
4849 } else {
4850 owningUid = android.os.Process.myUid();
4851 owningPackage = mContext.getBasePackageName();
4852 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08004853 if (pattern.length == 1) {
4854 // One-shot vibration
Dianne Hackbornf265ea92013-01-31 15:00:51 -08004855 mVibrator.vibrate(owningUid, owningPackage, pattern[0]);
Amith Yamasanic33cb712010-02-10 15:21:49 -08004856 } else {
4857 // Pattern vibration
Dianne Hackbornf265ea92013-01-31 15:00:51 -08004858 mVibrator.vibrate(owningUid, owningPackage, pattern, -1);
Amith Yamasanic33cb712010-02-10 15:21:49 -08004859 }
4860 return true;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004861 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07004862
4863 @Override
4864 public void keepScreenOnStartedLw() {
Daniel Sandler0601eb72011-04-13 01:01:32 -04004865 }
4866
Jeff Brownc38c9be2012-10-04 13:16:19 -07004867 @Override
4868 public void keepScreenOnStoppedLw() {
4869 if (mKeyguardMediator != null && !mKeyguardMediator.isShowingAndNotHidden()) {
4870 long curTime = SystemClock.uptimeMillis();
4871 mPowerManager.userActivity(curTime, false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004872 }
4873 }
Mike Lockwoodfcb39242009-10-21 23:01:07 -04004874
Dianne Hackborndf89e652011-10-06 22:35:11 -07004875 private int updateSystemUiVisibilityLw() {
Joe Onorato664644d2011-01-23 17:53:23 -08004876 // If there is no window focused, there will be nobody to handle the events
4877 // anyway, so just hang on in whatever state we're in until things settle down.
Dianne Hackborndf89e652011-10-06 22:35:11 -07004878 if (mFocusedWindow == null) {
4879 return 0;
4880 }
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004881 if (mFocusedWindow.getAttrs().type == TYPE_KEYGUARD && mHideLockScreen == true) {
4882 // We are updating at a point where the keyguard has gotten
4883 // focus, but we were last in a state where the top window is
4884 // hiding it. This is probably because the keyguard as been
4885 // shown while the top window was displayed, so we want to ignore
4886 // it here because this is just a very transient change and it
4887 // will quickly lose focus once it correctly gets hidden.
4888 return 0;
4889 }
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08004890 int tmpVisibility = mFocusedWindow.getSystemUiVisibility()
Dianne Hackborne26ab702011-10-16 13:21:33 -07004891 & ~mResettingSystemUiFlags
4892 & ~mForceClearedSystemUiFlags;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08004893 if (mForcingShowNavBar && mFocusedWindow.getSurfaceLayer() < mForcingShowNavBarLayer) {
4894 tmpVisibility &= ~View.SYSTEM_UI_CLEARABLE_FLAGS;
4895 }
4896 final int visibility = tmpVisibility;
Dianne Hackborne26ab702011-10-16 13:21:33 -07004897 int diff = visibility ^ mLastSystemUiFlags;
Dianne Hackborn73ab6a42011-12-13 11:16:23 -08004898 final boolean needsMenu = mFocusedWindow.getNeedsMenuLw(mTopFullscreenOpaqueWindowState);
Dianne Hackborne0f085d2011-11-30 18:41:15 -08004899 if (diff == 0 && mLastFocusNeedsMenu == needsMenu
4900 && mFocusedApp == mFocusedWindow.getAppToken()) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004901 return 0;
4902 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07004903 mLastSystemUiFlags = visibility;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08004904 mLastFocusNeedsMenu = needsMenu;
Dianne Hackborne0f085d2011-11-30 18:41:15 -08004905 mFocusedApp = mFocusedWindow.getAppToken();
Dianne Hackborndf89e652011-10-06 22:35:11 -07004906 mHandler.post(new Runnable() {
4907 public void run() {
Dianne Hackborn42e620c2012-06-24 13:20:51 -07004908 try {
4909 IStatusBarService statusbar = getStatusBarService();
4910 if (statusbar != null) {
4911 statusbar.setSystemUiVisibility(visibility, 0xffffffff);
4912 statusbar.topAppWindowChanged(needsMenu);
Joe Onorato664644d2011-01-23 17:53:23 -08004913 }
Dianne Hackborn42e620c2012-06-24 13:20:51 -07004914 } catch (RemoteException e) {
4915 // re-acquire status bar service next time it is needed.
4916 mStatusBarService = null;
Joe Onorato664644d2011-01-23 17:53:23 -08004917 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07004918 }
4919 });
4920 return diff;
Joe Onorato664644d2011-01-23 17:53:23 -08004921 }
4922
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04004923 // Use this instead of checking config_showNavigationBar so that it can be consistently
4924 // overridden by qemu.hw.mainkeys in the emulator.
4925 public boolean hasNavigationBar() {
4926 return mHasNavigationBar;
4927 }
4928
satok1bc0a492012-04-25 22:47:12 +09004929 @Override
4930 public void setLastInputMethodWindowLw(WindowState ime, WindowState target) {
4931 mLastInputMethodWindow = ime;
4932 mLastInputMethodTargetWindow = target;
4933 }
4934
Craig Mautnerf1b67412012-09-19 13:18:29 -07004935 @Override
Craig Mautnerf1b67412012-09-19 13:18:29 -07004936 public void setCurrentUserLw(int newUserId) {
4937 if (mKeyguardMediator != null) {
4938 mKeyguardMediator.setCurrentUser(newUserId);
4939 }
John Spurlock13451a22012-09-28 14:40:41 -04004940 if (mStatusBarService != null) {
4941 try {
4942 mStatusBarService.setCurrentUser(newUserId);
4943 } catch (RemoteException e) {
4944 // oh well
4945 }
4946 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07004947 setLastInputMethodWindowLw(null, null);
Craig Mautnerf1b67412012-09-19 13:18:29 -07004948 }
4949
4950 @Override
Jim Miller4eeb4f62012-11-08 00:04:29 -08004951 public void showAssistant() {
4952 mKeyguardMediator.showAssistant();
4953 }
4954
Svetoslav Ganov545252f2012-12-10 18:29:24 -08004955 @Override
4956 public boolean canMagnifyWindow(int windowType) {
4957 switch (windowType) {
4958 case WindowManager.LayoutParams.TYPE_INPUT_METHOD:
4959 case WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG:
4960 case WindowManager.LayoutParams.TYPE_NAVIGATION_BAR:
4961 case WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY: {
4962 return false;
4963 }
4964 }
4965 return true;
4966 }
4967
4968 @Override
4969 public boolean isTopLevelWindow(int windowType) {
4970 if (windowType >= WindowManager.LayoutParams.FIRST_SUB_WINDOW
4971 && windowType <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
4972 return (windowType == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG);
4973 }
4974 return true;
4975 }
4976
Jim Miller4eeb4f62012-11-08 00:04:29 -08004977 @Override
Jeff Brownd7a04de2012-06-17 14:17:52 -07004978 public void dump(String prefix, PrintWriter pw, String[] args) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004979 pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07004980 pw.print(" mSystemReady="); pw.print(mSystemReady);
4981 pw.print(" mSystemBooted="); pw.println(mSystemBooted);
Jeff Brown2e7760e2012-04-11 15:14:55 -07004982 pw.print(prefix); pw.print("mLidState="); pw.print(mLidState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004983 pw.print(" mLidOpenRotation="); pw.print(mLidOpenRotation);
4984 pw.print(" mHdmiPlugged="); pw.println(mHdmiPlugged);
Dianne Hackborne26ab702011-10-16 13:21:33 -07004985 if (mLastSystemUiFlags != 0 || mResettingSystemUiFlags != 0
4986 || mForceClearedSystemUiFlags != 0) {
4987 pw.print(prefix); pw.print("mLastSystemUiFlags=0x");
4988 pw.print(Integer.toHexString(mLastSystemUiFlags));
4989 pw.print(" mResettingSystemUiFlags=0x");
4990 pw.print(Integer.toHexString(mResettingSystemUiFlags));
4991 pw.print(" mForceClearedSystemUiFlags=0x");
4992 pw.println(Integer.toHexString(mForceClearedSystemUiFlags));
Dianne Hackborndf89e652011-10-06 22:35:11 -07004993 }
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08004994 if (mLastFocusNeedsMenu) {
4995 pw.print(prefix); pw.print("mLastFocusNeedsMenu=");
4996 pw.println(mLastFocusNeedsMenu);
4997 }
Daniel Sandler6396c722013-04-16 20:19:09 -04004998 pw.print(prefix); pw.print("mUiMode="); pw.print(mUiMode);
4999 pw.print(" mDockMode="); pw.print(mDockMode);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005000 pw.print(" mCarDockRotation="); pw.print(mCarDockRotation);
5001 pw.print(" mDeskDockRotation="); pw.println(mDeskDockRotation);
5002 pw.print(prefix); pw.print("mUserRotationMode="); pw.print(mUserRotationMode);
5003 pw.print(" mUserRotation="); pw.print(mUserRotation);
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005004 pw.print(" mAllowAllRotations="); pw.println(mAllowAllRotations);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07005005 pw.print(prefix); pw.print("mCurrentAppOrientation="); pw.println(mCurrentAppOrientation);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005006 pw.print(prefix); pw.print("mCarDockEnablesAccelerometer=");
5007 pw.print(mCarDockEnablesAccelerometer);
5008 pw.print(" mDeskDockEnablesAccelerometer=");
5009 pw.println(mDeskDockEnablesAccelerometer);
5010 pw.print(prefix); pw.print("mLidKeyboardAccessibility=");
5011 pw.print(mLidKeyboardAccessibility);
5012 pw.print(" mLidNavigationAccessibility="); pw.print(mLidNavigationAccessibility);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07005013 pw.print(" mLidControlsSleep="); pw.println(mLidControlsSleep);
5014 pw.print(prefix); pw.print("mLongPressOnPowerBehavior=");
5015 pw.print(mLongPressOnPowerBehavior);
5016 pw.print(" mHasSoftInput="); pw.println(mHasSoftInput);
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07005017 pw.print(prefix); pw.print("mScreenOnEarly="); pw.print(mScreenOnEarly);
5018 pw.print(" mScreenOnFully="); pw.print(mScreenOnFully);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07005019 pw.print(" mOrientationSensorEnabled="); pw.println(mOrientationSensorEnabled);
Dianne Hackbornc652de82013-02-15 16:32:56 -08005020 pw.print(prefix); pw.print("mOverscanScreen=("); pw.print(mOverscanScreenLeft);
5021 pw.print(","); pw.print(mOverscanScreenTop);
5022 pw.print(") "); pw.print(mOverscanScreenWidth);
5023 pw.print("x"); pw.println(mOverscanScreenHeight);
5024 if (mOverscanLeft != 0 || mOverscanTop != 0
5025 || mOverscanRight != 0 || mOverscanBottom != 0) {
5026 pw.print(prefix); pw.print("mOverscan left="); pw.print(mOverscanLeft);
5027 pw.print(" top="); pw.print(mOverscanTop);
5028 pw.print(" right="); pw.print(mOverscanRight);
5029 pw.print(" bottom="); pw.println(mOverscanBottom);
5030 }
Dianne Hackborn313440842013-02-19 19:22:59 -08005031 pw.print(prefix); pw.print("mRestrictedOverscanScreen=(");
5032 pw.print(mRestrictedOverscanScreenLeft);
5033 pw.print(","); pw.print(mRestrictedOverscanScreenTop);
5034 pw.print(") "); pw.print(mRestrictedOverscanScreenWidth);
5035 pw.print("x"); pw.println(mRestrictedOverscanScreenHeight);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005036 pw.print(prefix); pw.print("mUnrestrictedScreen=("); pw.print(mUnrestrictedScreenLeft);
5037 pw.print(","); pw.print(mUnrestrictedScreenTop);
5038 pw.print(") "); pw.print(mUnrestrictedScreenWidth);
5039 pw.print("x"); pw.println(mUnrestrictedScreenHeight);
5040 pw.print(prefix); pw.print("mRestrictedScreen=("); pw.print(mRestrictedScreenLeft);
5041 pw.print(","); pw.print(mRestrictedScreenTop);
5042 pw.print(") "); pw.print(mRestrictedScreenWidth);
5043 pw.print("x"); pw.println(mRestrictedScreenHeight);
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07005044 pw.print(prefix); pw.print("mStableFullscreen=("); pw.print(mStableFullscreenLeft);
5045 pw.print(","); pw.print(mStableFullscreenTop);
5046 pw.print(")-("); pw.print(mStableFullscreenRight);
5047 pw.print(","); pw.print(mStableFullscreenBottom); pw.println(")");
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07005048 pw.print(prefix); pw.print("mStable=("); pw.print(mStableLeft);
5049 pw.print(","); pw.print(mStableTop);
5050 pw.print(")-("); pw.print(mStableRight);
5051 pw.print(","); pw.print(mStableBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07005052 pw.print(prefix); pw.print("mSystem=("); pw.print(mSystemLeft);
5053 pw.print(","); pw.print(mSystemTop);
5054 pw.print(")-("); pw.print(mSystemRight);
5055 pw.print(","); pw.print(mSystemBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005056 pw.print(prefix); pw.print("mCur=("); pw.print(mCurLeft);
5057 pw.print(","); pw.print(mCurTop);
5058 pw.print(")-("); pw.print(mCurRight);
5059 pw.print(","); pw.print(mCurBottom); pw.println(")");
5060 pw.print(prefix); pw.print("mContent=("); pw.print(mContentLeft);
5061 pw.print(","); pw.print(mContentTop);
5062 pw.print(")-("); pw.print(mContentRight);
5063 pw.print(","); pw.print(mContentBottom); pw.println(")");
5064 pw.print(prefix); pw.print("mDock=("); pw.print(mDockLeft);
5065 pw.print(","); pw.print(mDockTop);
5066 pw.print(")-("); pw.print(mDockRight);
5067 pw.print(","); pw.print(mDockBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07005068 pw.print(prefix); pw.print("mDockLayer="); pw.print(mDockLayer);
5069 pw.print(" mStatusBarLayer="); pw.println(mStatusBarLayer);
Dianne Hackborn7ad44382012-10-18 17:46:00 -07005070 pw.print(prefix); pw.print("mShowingLockscreen="); pw.print(mShowingLockscreen);
5071 pw.print(" mShowingDream="); pw.print(mShowingDream);
5072 pw.print(" mDreamingLockscreen="); pw.println(mDreamingLockscreen);
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07005073 if (mLastInputMethodWindow != null) {
5074 pw.print(prefix); pw.print("mLastInputMethodWindow=");
5075 pw.println(mLastInputMethodWindow);
5076 }
5077 if (mLastInputMethodTargetWindow != null) {
5078 pw.print(prefix); pw.print("mLastInputMethodTargetWindow=");
5079 pw.println(mLastInputMethodTargetWindow);
5080 }
5081 if (mStatusBar != null) {
5082 pw.print(prefix); pw.print("mStatusBar=");
5083 pw.println(mStatusBar);
5084 }
5085 if (mNavigationBar != null) {
5086 pw.print(prefix); pw.print("mNavigationBar=");
5087 pw.println(mNavigationBar);
5088 }
5089 if (mKeyguard != null) {
5090 pw.print(prefix); pw.print("mKeyguard=");
5091 pw.println(mKeyguard);
5092 }
5093 if (mFocusedWindow != null) {
5094 pw.print(prefix); pw.print("mFocusedWindow=");
5095 pw.println(mFocusedWindow);
5096 }
5097 if (mFocusedApp != null) {
5098 pw.print(prefix); pw.print("mFocusedApp=");
5099 pw.println(mFocusedApp);
5100 }
5101 if (mWinDismissingKeyguard != null) {
5102 pw.print(prefix); pw.print("mWinDismissingKeyguard=");
5103 pw.println(mWinDismissingKeyguard);
5104 }
5105 if (mTopFullscreenOpaqueWindowState != null) {
5106 pw.print(prefix); pw.print("mTopFullscreenOpaqueWindowState=");
5107 pw.println(mTopFullscreenOpaqueWindowState);
5108 }
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08005109 if (mForcingShowNavBar) {
5110 pw.print(prefix); pw.print("mForcingShowNavBar=");
5111 pw.println(mForcingShowNavBar); pw.print( "mForcingShowNavBarLayer=");
5112 pw.println(mForcingShowNavBarLayer);
5113 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07005114 pw.print(prefix); pw.print("mTopIsFullscreen="); pw.print(mTopIsFullscreen);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005115 pw.print(" mHideLockScreen="); pw.println(mHideLockScreen);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07005116 pw.print(prefix); pw.print("mForceStatusBar="); pw.print(mForceStatusBar);
5117 pw.print(" mForceStatusBarFromKeyguard=");
5118 pw.println(mForceStatusBarFromKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005119 pw.print(prefix); pw.print("mDismissKeyguard="); pw.print(mDismissKeyguard);
Craig Mautnerad09bcc2012-10-08 13:33:11 -07005120 pw.print(" mWinDismissingKeyguard="); pw.print(mWinDismissingKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005121 pw.print(" mHomePressed="); pw.println(mHomePressed);
5122 pw.print(prefix); pw.print("mAllowLockscreenWhenOn="); pw.print(mAllowLockscreenWhenOn);
5123 pw.print(" mLockScreenTimeout="); pw.print(mLockScreenTimeout);
5124 pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive);
5125 pw.print(prefix); pw.print("mEndcallBehavior="); pw.print(mEndcallBehavior);
5126 pw.print(" mIncallPowerBehavior="); pw.print(mIncallPowerBehavior);
5127 pw.print(" mLongPressOnHomeBehavior="); pw.println(mLongPressOnHomeBehavior);
5128 pw.print(prefix); pw.print("mLandscapeRotation="); pw.print(mLandscapeRotation);
5129 pw.print(" mSeascapeRotation="); pw.println(mSeascapeRotation);
5130 pw.print(prefix); pw.print("mPortraitRotation="); pw.print(mPortraitRotation);
5131 pw.print(" mUpsideDownRotation="); pw.println(mUpsideDownRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07005132 pw.print(prefix); pw.print("mDemoHdmiRotation="); pw.print(mDemoHdmiRotation);
5133 pw.print(" mDemoHdmiRotationLock="); pw.println(mDemoHdmiRotationLock);
5134 pw.print(prefix); pw.print("mUndockedHdmiRotation="); pw.println(mUndockedHdmiRotation);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005135 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005136}