blob: f65e9ac6a0298af0029673dd47b1645998414155 [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;
John Spurlockf56bef12013-07-09 09:51:46 -040036import android.content.pm.UserInfo;
Dianne Hackborn2f0b1752011-05-31 17:59:49 -070037import android.content.res.CompatibilityInfo;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080038import android.content.res.Configuration;
39import android.content.res.Resources;
Craig Mautner8e4df6c2012-05-23 16:57:23 -070040import android.content.res.TypedArray;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080041import android.database.ContentObserver;
Dianne Hackbornc777e072010-02-12 13:07:59 -080042import android.graphics.PixelFormat;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080043import android.graphics.Rect;
Michael Jurka7a348952012-02-27 13:07:58 -080044import android.media.AudioManager;
45import android.media.IAudioService;
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -070046import android.media.Ringtone;
47import android.media.RingtoneManager;
Dianne Hackborn38e29a62011-09-18 14:43:08 -070048import android.os.Bundle;
Jeff Brown9a538ee2012-08-20 14:56:57 -070049import android.os.FactoryTest;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080050import android.os.Handler;
51import android.os.IBinder;
Dianne Hackborn38e29a62011-09-18 14:43:08 -070052import android.os.IRemoteCallback;
Jeff Brown32cbc38552011-12-01 14:01:49 -080053import android.os.Looper;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -070054import android.os.Message;
55import android.os.Messenger;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080056import android.os.PowerManager;
57import android.os.RemoteException;
58import android.os.ServiceManager;
59import android.os.SystemClock;
60import android.os.SystemProperties;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -080061import android.os.UEventObserver;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -070062import android.os.UserHandle;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080063import android.os.Vibrator;
64import android.provider.Settings;
John Spurlockc8b46ca2013-04-08 12:59:26 -040065import android.service.dreams.DreamService;
66import android.service.dreams.IDreamManager;
Dianne Hackborn81e56d52011-05-26 00:55:58 -070067import android.util.DisplayMetrics;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080068import android.util.EventLog;
69import android.util.Log;
Jeff Browna41ca772010-08-11 14:46:32 -070070import android.util.Slog;
Jeff Brown6651a632011-11-28 12:59:11 -080071import android.util.SparseArray;
Dianne Hackbornf87d1962012-04-04 12:48:24 -070072import android.view.Display;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080073import android.view.Gravity;
74import android.view.HapticFeedbackConstants;
Dianne Hackborne0f085d2011-11-30 18:41:15 -080075import android.view.IApplicationToken;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080076import android.view.IWindowManager;
Jeff Browna41ca772010-08-11 14:46:32 -070077import android.view.InputChannel;
Jeff Brown4d396052010-10-29 21:50:21 -070078import android.view.InputDevice;
Jeff Brown4952dfd2011-11-30 19:23:22 -080079import android.view.InputEvent;
Jeff Brown32cbc38552011-12-01 14:01:49 -080080import android.view.InputEventReceiver;
Jeff Brown6b53e8d2010-11-10 16:03:06 -080081import android.view.KeyCharacterMap;
Craig Mautnerae446592012-12-06 19:05:05 -080082import android.view.KeyCharacterMap.FallbackAction;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080083import android.view.KeyEvent;
84import android.view.MotionEvent;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080085import android.view.Surface;
86import android.view.View;
87import android.view.ViewConfiguration;
88import android.view.Window;
89import android.view.WindowManager;
Craig Mautnerae446592012-12-06 19:05:05 -080090import android.view.WindowManagerGlobal;
91import android.view.WindowManagerPolicy;
Craig Mautnerae446592012-12-06 19:05:05 -080092import android.view.accessibility.AccessibilityEvent;
93import android.view.animation.Animation;
94import android.view.animation.AnimationUtils;
95
96import com.android.internal.R;
97import com.android.internal.policy.PolicyManager;
Jim Miller5ecd8112013-01-09 18:50:26 -080098import com.android.internal.policy.impl.keyguard.KeyguardServiceDelegate;
Craig Mautnerae446592012-12-06 19:05:05 -080099import 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;
John Spurlockad3e6cb2013-04-30 08:47:43 -0400107import java.util.HashSet;
Craig Mautnerae446592012-12-06 19:05:05 -0800108
Dianne Hackbornc652de82013-02-15 16:32:56 -0800109import static android.view.WindowManager.LayoutParams.*;
Jeff Brownac143512012-04-05 18:57:33 -0700110import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_ABSENT;
111import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_OPEN;
112import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_CLOSED;
Dianne Hackborn08743722009-12-21 12:16:51 -0800113
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800114/**
The Android Open Source Project0727d222009-03-11 12:11:58 -0700115 * WindowManagerPolicy implementation for the Android phone UI. This
116 * introduces a new method suffix, Lp, for an internal lock of the
117 * PhoneWindowManager. This is used to protect some internal state, and
John Spurlock04db1762013-05-13 12:46:41 -0400118 * can be acquired with either the Lw and Li lock held, so has the restrictions
The Android Open Source Project0727d222009-03-11 12:11:58 -0700119 * of both of those when held.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800120 */
121public class PhoneWindowManager implements WindowManagerPolicy {
122 static final String TAG = "WindowManager";
123 static final boolean DEBUG = false;
Joe Onorato43a17652011-04-06 19:22:23 -0700124 static final boolean localLOGV = false;
The Android Open Source Project11267662009-03-18 17:39:47 -0700125 static final boolean DEBUG_LAYOUT = false;
Jeff Brown40013652012-05-16 21:22:36 -0700126 static final boolean DEBUG_INPUT = false;
Craig Mautner6fbda632012-07-03 09:26:39 -0700127 static final boolean DEBUG_STARTING_WINDOW = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800128 static final boolean SHOW_STARTING_ANIMATIONS = true;
129 static final boolean SHOW_PROCESSES_ON_ALT_MENU = false;
Joe Onoratod208e702010-10-08 16:22:43 -0400130
Daniel Sandler6396c722013-04-16 20:19:09 -0400131 // Whether to allow dock apps with METADATA_DOCK_HOME to temporarily take over the Home key.
132 // No longer recommended for desk docks; still useful in car docks.
133 static final boolean ENABLE_CAR_DOCK_HOME_CAPTURE = true;
134 static final boolean ENABLE_DESK_DOCK_HOME_CAPTURE = false;
135
Joe Onoratod208e702010-10-08 16:22:43 -0400136 static final int LONG_PRESS_POWER_NOTHING = 0;
137 static final int LONG_PRESS_POWER_GLOBAL_ACTIONS = 1;
138 static final int LONG_PRESS_POWER_SHUT_OFF = 2;
Jeff Brown9a538ee2012-08-20 14:56:57 -0700139 static final int LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM = 3;
Michael Jurka3b1fc472011-06-13 10:54:40 -0700140
141 // These need to match the documentation/constant in
142 // core/res/res/values/config.xml
Joe Onorato46b0d682010-11-22 17:37:27 -0800143 static final int LONG_PRESS_HOME_NOTHING = 0;
Michael Wrightc9ebea72013-01-16 19:25:02 -0800144 static final int LONG_PRESS_HOME_RECENT_SYSTEM_UI = 1;
Jeff Browncaca8812013-05-09 13:34:33 -0700145 static final int LONG_PRESS_HOME_ASSIST = 2;
146
147 static final int DOUBLE_TAP_HOME_NOTHING = 0;
148 static final int DOUBLE_TAP_HOME_RECENT_SYSTEM_UI = 1;
Joe Onorato46b0d682010-11-22 17:37:27 -0800149
Dianne Hackborn5cb8d792009-05-21 17:34:15 -0700150 static final int APPLICATION_MEDIA_SUBLAYER = -2;
151 static final int APPLICATION_MEDIA_OVERLAY_SUBLAYER = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800152 static final int APPLICATION_PANEL_SUBLAYER = 1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800153 static final int APPLICATION_SUB_PANEL_SUBLAYER = 2;
Craig Mautner88400d32012-09-30 12:35:45 -0700154
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800155 static public final String SYSTEM_DIALOG_REASON_KEY = "reason";
156 static public final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions";
157 static public final String SYSTEM_DIALOG_REASON_RECENT_APPS = "recentapps";
Joe Onoratof275f0c2009-11-24 16:11:13 -0500158 static public final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey";
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700159 static public final String SYSTEM_DIALOG_REASON_ASSIST = "assist";
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800160
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700161 /**
162 * These are the system UI flags that, when changing, can cause the layout
163 * of the screen to change.
164 */
165 static final int SYSTEM_UI_CHANGING_LAYOUT =
166 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN;
167
Jim Miller5ecd8112013-01-09 18:50:26 -0800168 /**
169 * Keyguard stuff
170 */
171 private WindowState mKeyguardScrim;
172
Jeff Brown6651a632011-11-28 12:59:11 -0800173 /* Table of Application Launch keys. Maps from key codes to intent categories.
174 *
175 * These are special keys that are used to launch particular kinds of applications,
176 * such as a web browser. HID defines nearly a hundred of them in the Consumer (0x0C)
177 * usage page. We don't support quite that many yet...
178 */
179 static SparseArray<String> sApplicationLaunchKeyCategories;
180 static {
181 sApplicationLaunchKeyCategories = new SparseArray<String>();
182 sApplicationLaunchKeyCategories.append(
183 KeyEvent.KEYCODE_EXPLORER, Intent.CATEGORY_APP_BROWSER);
184 sApplicationLaunchKeyCategories.append(
185 KeyEvent.KEYCODE_ENVELOPE, Intent.CATEGORY_APP_EMAIL);
186 sApplicationLaunchKeyCategories.append(
187 KeyEvent.KEYCODE_CONTACTS, Intent.CATEGORY_APP_CONTACTS);
188 sApplicationLaunchKeyCategories.append(
189 KeyEvent.KEYCODE_CALENDAR, Intent.CATEGORY_APP_CALENDAR);
190 sApplicationLaunchKeyCategories.append(
191 KeyEvent.KEYCODE_MUSIC, Intent.CATEGORY_APP_MUSIC);
192 sApplicationLaunchKeyCategories.append(
193 KeyEvent.KEYCODE_CALCULATOR, Intent.CATEGORY_APP_CALCULATOR);
194 }
195
Dianne Hackborndf89e652011-10-06 22:35:11 -0700196 /**
197 * Lock protecting internal state. Must not call out into window
198 * manager with lock held. (This lock will be acquired in places
199 * where the window manager is calling in with its own lock held.)
200 */
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800201 private final Object mLock = new Object();
Dianne Hackborndf89e652011-10-06 22:35:11 -0700202
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800203 Context mContext;
204 IWindowManager mWindowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700205 WindowManagerFuncs mWindowManagerFuncs;
Jeff Brown96307042012-07-27 15:51:34 -0700206 PowerManager mPowerManager;
Joe Onorato93056472010-09-10 10:30:46 -0400207 IStatusBarService mStatusBarService;
Jeff Browncaca8812013-05-09 13:34:33 -0700208 boolean mPreloadedRecentApps;
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700209 final Object mServiceAquireLock = new Object();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800210 Vibrator mVibrator; // Vibrator for giving feedback of orientation changes
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700211 SearchManager mSearchManager;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800212
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700213 // Vibrator pattern for haptic feedback of a long press.
214 long[] mLongPressVibePattern;
Craig Mautner88400d32012-09-30 12:35:45 -0700215
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700216 // Vibrator pattern for haptic feedback of virtual key press.
217 long[] mVirtualKeyVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700218
Amith Yamasanic33cb712010-02-10 15:21:49 -0800219 // Vibrator pattern for a short vibration.
220 long[] mKeyboardTapVibePattern;
221
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700222 // Vibrator pattern for haptic feedback during boot when safe mode is disabled.
223 long[] mSafeModeDisabledVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700224
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700225 // Vibrator pattern for haptic feedback during boot when safe mode is enabled.
226 long[] mSafeModeEnabledVibePattern;
Romain Guy8154cd32010-03-29 14:41:15 -0700227
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800228 /** If true, hitting shift & menu will broadcast Intent.ACTION_BUG_REPORT */
229 boolean mEnableShiftMenuBugReports = false;
Mike Lockwoodd747dc82011-09-13 16:28:22 -0400230
231 boolean mHeadless;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800232 boolean mSafeMode;
233 WindowState mStatusBar = null;
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700234 int mStatusBarHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400235 WindowState mNavigationBar = null;
Daniel Sandler36412a72011-08-04 09:35:13 -0400236 boolean mHasNavigationBar = false;
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700237 boolean mCanHideNavigationBar = false;
Daniel Sandler4a066c52012-04-20 14:49:13 -0400238 boolean mNavigationBarCanMove = false; // can the navigation bar ever move to the side?
239 boolean mNavigationBarOnBottom = true; // is the navigation bar on the bottom *right now*?
240 int[] mNavigationBarHeightForRotation = new int[4];
241 int[] mNavigationBarWidthForRotation = new int[4];
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400242
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800243 WindowState mKeyguard = null;
Jim Miller5ecd8112013-01-09 18:50:26 -0800244 KeyguardServiceDelegate mKeyguardDelegate;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800245 GlobalActions mGlobalActions;
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700246 volatile boolean mPowerKeyHandled; // accessed from input reader and handler thread
247 boolean mPendingPowerKeyUpCanceled;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800248 Handler mHandler;
satok1bc0a492012-04-25 22:47:12 +0900249 WindowState mLastInputMethodWindow = null;
250 WindowState mLastInputMethodTargetWindow = null;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800251
Jeff Brown68b909d2011-12-07 16:36:01 -0800252 static final int RECENT_APPS_BEHAVIOR_SHOW_OR_DISMISS = 0;
253 static final int RECENT_APPS_BEHAVIOR_EXIT_TOUCH_MODE_AND_SHOW = 1;
Jeff Brown602ab322012-05-16 13:33:47 -0700254 static final int RECENT_APPS_BEHAVIOR_DISMISS = 2;
255 static final int RECENT_APPS_BEHAVIOR_DISMISS_AND_SWITCH = 3;
Jeff Brown68b909d2011-12-07 16:36:01 -0800256
257 RecentApplicationsDialog mRecentAppsDialog;
258 int mRecentAppsDialogHeldModifiers;
Jeff Browncf39bdf2012-05-18 14:41:19 -0700259 boolean mLanguageSwitchKeyPressed;
Jeff Brown68b909d2011-12-07 16:36:01 -0800260
Jeff Brown2e7760e2012-04-11 15:14:55 -0700261 int mLidState = LID_ABSENT;
Jeff Browndaa37532012-05-01 15:54:03 -0700262 boolean mHaveBuiltInKeyboard;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800263
Dianne Hackbornc777e072010-02-12 13:07:59 -0800264 boolean mSystemReady;
Dianne Hackbornba24e4d2011-09-01 11:17:06 -0700265 boolean mSystemBooted;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800266 boolean mHdmiPlugged;
Daniel Sandler6396c722013-04-16 20:19:09 -0400267 int mUiMode;
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700268 int mDockMode = Intent.EXTRA_DOCK_STATE_UNDOCKED;
Mike Lockwood1753f7f2009-08-24 14:49:07 -0700269 int mLidOpenRotation;
Mike Lockwood2d1efbd2009-09-16 12:15:53 -0400270 int mCarDockRotation;
271 int mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -0700272 int mUndockedHdmiRotation;
273 int mDemoHdmiRotation;
274 boolean mDemoHdmiRotationLock;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400275
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700276 // Default display does not rotate, apps that require non-default orientation will have to
277 // have the orientation emulated.
278 private boolean mForceDefaultOrientation = false;
279
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400280 int mUserRotationMode = WindowManagerPolicy.USER_ROTATION_FREE;
281 int mUserRotation = Surface.ROTATION_0;
Jeff Brown207673cd2012-06-05 17:47:11 -0700282 boolean mAccelerometerDefault;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400283
Jeff Brownd3187e32011-09-21 19:26:44 -0700284 int mAllowAllRotations = -1;
Mike Lockwoode9867d22009-09-20 01:59:02 -0400285 boolean mCarDockEnablesAccelerometer;
286 boolean mDeskDockEnablesAccelerometer;
Dianne Hackborn2862fff2009-09-15 22:56:29 -0700287 int mLidKeyboardAccessibility;
288 int mLidNavigationAccessibility;
Jeff Brownc458ce92012-04-30 14:58:40 -0700289 boolean mLidControlsSleep;
Joe Onoratod208e702010-10-08 16:22:43 -0400290 int mLongPressOnPowerBehavior = -1;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -0700291 boolean mScreenOnEarly = false;
292 boolean mScreenOnFully = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800293 boolean mOrientationSensorEnabled = false;
294 int mCurrentAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800295 boolean mHasSoftInput = false;
Craig Mautner967212c2013-04-13 21:10:58 -0700296
Jeff Brown70825162012-03-28 17:27:48 -0700297 int mPointerLocationMode = 0; // guarded by mLock
Joe Onorato664644d2011-01-23 17:53:23 -0800298
299 // The last window we were told about in focusChanged.
300 WindowState mFocusedWindow;
Dianne Hackborne0f085d2011-11-30 18:41:15 -0800301 IApplicationToken mFocusedApp;
Joe Onorato664644d2011-01-23 17:53:23 -0800302
Craig Mautner037aa8d2013-06-07 10:35:44 -0700303 private final class PointerLocationPointerEventListener implements PointerEventListener {
Jeff Browna41ca772010-08-11 14:46:32 -0700304 @Override
Craig Mautner037aa8d2013-06-07 10:35:44 -0700305 public void onPointerEvent(MotionEvent motionEvent) {
306 if (mPointerLocationView != null) {
307 mPointerLocationView.addPointerEvent(motionEvent);
Jeff Browna41ca772010-08-11 14:46:32 -0700308 }
309 }
Jeff Brown32cbc38552011-12-01 14:01:49 -0800310 }
Jeff Brown70825162012-03-28 17:27:48 -0700311
312 // Pointer location view state, only modified on the mHandler Looper.
Craig Mautner037aa8d2013-06-07 10:35:44 -0700313 PointerLocationPointerEventListener mPointerLocationPointerEventListener;
Jeff Brown70825162012-03-28 17:27:48 -0700314 PointerLocationView mPointerLocationView;
Jeff Brown32cbc38552011-12-01 14:01:49 -0800315
Dianne Hackbornc652de82013-02-15 16:32:56 -0800316 // The current size of the screen; really; extends into the overscan area of
317 // the screen and doesn't account for any system elements like the status bar.
318 int mOverscanScreenLeft, mOverscanScreenTop;
319 int mOverscanScreenWidth, mOverscanScreenHeight;
320 // The current visible size of the screen; really; (ir)regardless of whether the status
321 // bar can be hidden but not extending into the overscan area.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800322 int mUnrestrictedScreenLeft, mUnrestrictedScreenTop;
323 int mUnrestrictedScreenWidth, mUnrestrictedScreenHeight;
Dianne Hackborn313440842013-02-19 19:22:59 -0800324 // Like mOverscanScreen*, but allowed to move into the overscan region where appropriate.
325 int mRestrictedOverscanScreenLeft, mRestrictedOverscanScreenTop;
326 int mRestrictedOverscanScreenWidth, mRestrictedOverscanScreenHeight;
Dianne Hackborn82de1ae2010-10-28 11:28:39 -0700327 // The current size of the screen; these may be different than (0,0)-(dw,dh)
328 // if the status bar can't be hidden; in that case it effectively carves out
329 // that area of the display from all other windows.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800330 int mRestrictedScreenLeft, mRestrictedScreenTop;
331 int mRestrictedScreenWidth, mRestrictedScreenHeight;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700332 // During layout, the current screen borders accounting for any currently
333 // visible system UI elements.
334 int mSystemLeft, mSystemTop, mSystemRight, mSystemBottom;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700335 // For applications requesting stable content insets, these are them.
336 int mStableLeft, mStableTop, mStableRight, mStableBottom;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -0700337 // For applications requesting stable content insets but have also set the
338 // fullscreen window flag, these are the stable dimensions without the status bar.
339 int mStableFullscreenLeft, mStableFullscreenTop;
340 int mStableFullscreenRight, mStableFullscreenBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800341 // During layout, the current screen borders with all outer decoration
342 // (status bar, input method dock) accounted for.
343 int mCurLeft, mCurTop, mCurRight, mCurBottom;
344 // During layout, the frame in which content should be displayed
345 // to the user, accounting for all screen decoration except for any
346 // space they deem as available for other content. This is usually
347 // the same as mCur*, but may be larger if the screen decor has supplied
348 // content insets.
349 int mContentLeft, mContentTop, mContentRight, mContentBottom;
Dianne Hackborn8e11ef02010-11-18 19:47:42 -0800350 // During layout, the current screen borders along which input method
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800351 // windows are placed.
352 int mDockLeft, mDockTop, mDockRight, mDockBottom;
353 // During layout, the layer at which the doc window is placed.
354 int mDockLayer;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700355 // During layout, this is the layer of the status bar.
356 int mStatusBarLayer;
Dianne Hackborne26ab702011-10-16 13:21:33 -0700357 int mLastSystemUiFlags;
358 // Bits that we are in the process of clearing, so we want to prevent
359 // them from being set by applications until everything has been updated
360 // to have them clear.
361 int mResettingSystemUiFlags = 0;
362 // Bits that we are currently always keeping cleared.
363 int mForceClearedSystemUiFlags = 0;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -0800364 // What we last reported to system UI about whether the compatibility
365 // menu needs to be displayed.
366 boolean mLastFocusNeedsMenu = false;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700367
368 FakeWindow mHideNavFakeWindow = null;
369
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800370 static final Rect mTmpParentFrame = new Rect();
371 static final Rect mTmpDisplayFrame = new Rect();
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800372 static final Rect mTmpOverscanFrame = new Rect();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800373 static final Rect mTmpContentFrame = new Rect();
374 static final Rect mTmpVisibleFrame = new Rect();
Dianne Hackborn1f903c32011-09-13 19:18:06 -0700375 static final Rect mTmpNavigationFrame = new Rect();
Craig Mautner967212c2013-04-13 21:10:58 -0700376
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800377 WindowState mTopFullscreenOpaqueWindowState;
Joe Onorato93056472010-09-10 10:30:46 -0400378 boolean mTopIsFullscreen;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800379 boolean mForceStatusBar;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -0700380 boolean mForceStatusBarFromKeyguard;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700381 boolean mHideLockScreen;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -0800382 boolean mForcingShowNavBar;
383 int mForcingShowNavBarLayer;
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700384
385 // States of keyguard dismiss.
386 private static final int DISMISS_KEYGUARD_NONE = 0; // Keyguard not being dismissed.
387 private static final int DISMISS_KEYGUARD_START = 1; // Keyguard needs to be dismissed.
388 private static final int DISMISS_KEYGUARD_CONTINUE = 2; // Keyguard has been dismissed.
389 int mDismissKeyguard = DISMISS_KEYGUARD_NONE;
390
391 /** The window that is currently dismissing the keyguard. Dismissing the keyguard must only
392 * be done once per window. */
393 private WindowState mWinDismissingKeyguard;
394
Dianne Hackborn7ad44382012-10-18 17:46:00 -0700395 boolean mShowingLockscreen;
396 boolean mShowingDream;
397 boolean mDreamingLockscreen;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800398 boolean mHomePressed;
Jeff Browncaca8812013-05-09 13:34:33 -0700399 boolean mHomeConsumed;
400 boolean mHomeDoubleTapPending;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800401 Intent mHomeIntent;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700402 Intent mCarDockIntent;
403 Intent mDeskDockIntent;
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700404 boolean mSearchKeyShortcutPending;
405 boolean mConsumeSearchKeyUp;
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700406 boolean mAssistKeyLongPressed;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800407
Mike Lockwood28569302010-01-28 11:54:40 -0500408 // support for activating the lock screen while the screen is on
409 boolean mAllowLockscreenWhenOn;
410 int mLockScreenTimeout;
411 boolean mLockScreenTimerActive;
412
David Brownbaf8d092010-03-08 21:52:59 -0800413 // Behavior of ENDCALL Button. (See Settings.System.END_BUTTON_BEHAVIOR.)
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800414 int mEndcallBehavior;
David Brownbaf8d092010-03-08 21:52:59 -0800415
416 // Behavior of POWER button while in-call and screen on.
417 // (See Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR.)
418 int mIncallPowerBehavior;
419
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700420 Display mDisplay;
421
Dianne Hackborn9d132642011-04-21 17:26:39 -0700422 int mLandscapeRotation = 0; // default landscape rotation
423 int mSeascapeRotation = 0; // "other" landscape rotation, 180 degrees from mLandscapeRotation
424 int mPortraitRotation = 0; // default portrait rotation
425 int mUpsideDownRotation = 0; // "other" portrait rotation
Mitsuru Oshima831d0d92009-06-16 18:27:18 -0700426
Dianne Hackbornc652de82013-02-15 16:32:56 -0800427 int mOverscanLeft = 0;
428 int mOverscanTop = 0;
429 int mOverscanRight = 0;
430 int mOverscanBottom = 0;
431
Joe Onorato46b0d682010-11-22 17:37:27 -0800432 // What we do when the user long presses on home
Jeff Browncaca8812013-05-09 13:34:33 -0700433 private int mLongPressOnHomeBehavior;
434
435 // What we do when the user double-taps on home
436 private int mDoubleTapOnHomeBehavior;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800437
Winson Chung9112ec32011-06-27 13:15:32 -0700438 // Screenshot trigger states
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700439 // Time to volume and power must be pressed within this interval of each other.
440 private static final long SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS = 150;
Winson Chung1cea2f32012-10-08 20:42:01 -0700441 // Increase the chord delay when taking a screenshot from the keyguard
442 private static final float KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER = 2.5f;
Christopher Tatee90585f2012-03-05 18:56:25 -0800443 private boolean mScreenshotChordEnabled;
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700444 private boolean mVolumeDownKeyTriggered;
445 private long mVolumeDownKeyTime;
446 private boolean mVolumeDownKeyConsumedByScreenshotChord;
447 private boolean mVolumeUpKeyTriggered;
448 private boolean mPowerKeyTriggered;
449 private long mPowerKeyTime;
Winson Chung9112ec32011-06-27 13:15:32 -0700450
Michael Wrightb854e242013-02-05 17:54:02 -0800451 /* The number of steps between min and max brightness */
452 private static final int BRIGHTNESS_STEPS = 10;
453
Christopher Tate5e08af02012-09-21 17:17:22 -0700454 SettingsObserver mSettingsObserver;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800455 ShortcutManager mShortcutManager;
456 PowerManager.WakeLock mBroadcastWakeLock;
Jeff Brown40013652012-05-16 21:22:36 -0700457 boolean mHavePendingMediaKeyRepeatWithWakeLock;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800458
Justin Kohd378ad72013-04-01 12:18:26 -0700459 // Maps global key codes to the components that will handle them.
460 private GlobalKeyManager mGlobalKeyManager;
461
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700462 // Fallback actions by key code.
463 private final SparseArray<KeyCharacterMap.FallbackAction> mFallbackActions =
464 new SparseArray<KeyCharacterMap.FallbackAction>();
Jeff Brown49ed71d2010-12-06 17:13:33 -0800465
Jeff Brown70825162012-03-28 17:27:48 -0700466 private static final int MSG_ENABLE_POINTER_LOCATION = 1;
467 private static final int MSG_DISABLE_POINTER_LOCATION = 2;
Jeff Brown40013652012-05-16 21:22:36 -0700468 private static final int MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK = 3;
469 private static final int MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK = 4;
Jeff Brown70825162012-03-28 17:27:48 -0700470
471 private class PolicyHandler extends Handler {
472 @Override
473 public void handleMessage(Message msg) {
474 switch (msg.what) {
475 case MSG_ENABLE_POINTER_LOCATION:
476 enablePointerLocation();
477 break;
478 case MSG_DISABLE_POINTER_LOCATION:
479 disablePointerLocation();
480 break;
Jeff Brown40013652012-05-16 21:22:36 -0700481 case MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK:
482 dispatchMediaKeyWithWakeLock((KeyEvent)msg.obj);
483 break;
484 case MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK:
485 dispatchMediaKeyRepeatWithWakeLock((KeyEvent)msg.obj);
486 break;
Jeff Brown70825162012-03-28 17:27:48 -0700487 }
488 }
489 }
490
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800491 private UEventObserver mHDMIObserver = new UEventObserver() {
492 @Override
493 public void onUEvent(UEventObserver.UEvent event) {
494 setHdmiPlugged("1".equals(event.get("SWITCH_STATE")));
495 }
496 };
497
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800498 class SettingsObserver extends ContentObserver {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800499 SettingsObserver(Handler handler) {
500 super(handler);
501 }
David Brownbaf8d092010-03-08 21:52:59 -0800502
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800503 void observe() {
Christopher Tate5e08af02012-09-21 17:17:22 -0700504 // Observe all users' changes
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800505 ContentResolver resolver = mContext.getContentResolver();
506 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700507 Settings.System.END_BUTTON_BEHAVIOR), false, this,
508 UserHandle.USER_ALL);
David Brownbaf8d092010-03-08 21:52:59 -0800509 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700510 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR), false, this,
511 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800512 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700513 Settings.System.ACCELEROMETER_ROTATION), false, this,
514 UserHandle.USER_ALL);
Mike Lockwood28569302010-01-28 11:54:40 -0500515 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700516 Settings.System.USER_ROTATION), false, this,
517 UserHandle.USER_ALL);
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400518 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700519 Settings.System.SCREEN_OFF_TIMEOUT), false, this,
520 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800521 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700522 Settings.System.POINTER_LOCATION), false, this,
523 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800524 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700525 Settings.Secure.DEFAULT_INPUT_METHOD), false, this,
526 UserHandle.USER_ALL);
Dianne Hackborn03759ed2009-03-27 16:04:08 -0700527 resolver.registerContentObserver(Settings.System.getUriFor(
John Spurlock245fd012013-05-31 10:31:04 -0400528 OverlayTesting.ENABLED_SETTING), false, this,
Christopher Tate5e08af02012-09-21 17:17:22 -0700529 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800530 updateSettings();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800531 }
532
533 @Override public void onChange(boolean selfChange) {
Dianne Hackbornc777e072010-02-12 13:07:59 -0800534 updateSettings();
Jeff Brown01a98dd2011-09-20 15:08:29 -0700535 updateRotation(false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800536 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800537 }
Craig Mautner967212c2013-04-13 21:10:58 -0700538
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800539 class MyOrientationListener extends WindowOrientationListener {
Craig Mautnereee29c42013-01-17 14:44:34 -0800540 MyOrientationListener(Context context, Handler handler) {
541 super(context, handler);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800542 }
Craig Mautner967212c2013-04-13 21:10:58 -0700543
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800544 @Override
Jeff Brownc0347aa2011-09-23 17:26:09 -0700545 public void onProposedRotationChanged(int rotation) {
Craig Mautnereda67292013-04-28 13:50:14 -0700546 if (localLOGV) Slog.v(TAG, "onProposedRotationChanged, rotation=" + rotation);
Jeff Brown01a98dd2011-09-20 15:08:29 -0700547 updateRotation(false);
548 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800549 }
550 MyOrientationListener mOrientationListener;
551
John Spurlockad3e6cb2013-04-30 08:47:43 -0400552 private static final int HIDEYBAR_NONE = 0;
553 private static final int HIDEYBAR_SHOWING = 1;
554 private static final int HIDEYBAR_HIDING = 2;
555 private int mStatusHideybar;
556 private int mNavigationHideybar;
John Spurlock32beb2c2013-03-11 10:16:47 -0400557
Craig Mautner037aa8d2013-06-07 10:35:44 -0700558 private SystemGesturesPointerEventListener mSystemGestures;
John Spurlock32beb2c2013-03-11 10:16:47 -0400559
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700560 IStatusBarService getStatusBarService() {
561 synchronized (mServiceAquireLock) {
562 if (mStatusBarService == null) {
563 mStatusBarService = IStatusBarService.Stub.asInterface(
564 ServiceManager.getService("statusbar"));
565 }
566 return mStatusBarService;
567 }
568 }
569
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700570 /*
571 * We always let the sensor be switched on by default except when
572 * the user has explicitly disabled sensor based rotation or when the
573 * screen is switched off.
574 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700575 boolean needSensorRunningLp() {
Dianne Hackborne5439f22010-10-02 16:53:50 -0700576 if (mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
577 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
578 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT
579 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800580 // If the application has explicitly requested to follow the
581 // orientation, then we need to turn the sensor or.
582 return true;
583 }
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700584 if ((mCarDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_CAR) ||
Jeff Brown1a693182011-11-08 14:44:16 -0800585 (mDeskDockEnablesAccelerometer && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
586 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
587 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK))) {
Mike Lockwoode9867d22009-09-20 01:59:02 -0400588 // enable accelerometer if we are docked in a dock that enables accelerometer
589 // orientation management,
590 return true;
591 }
Jeff Brown207673cd2012-06-05 17:47:11 -0700592 if (mUserRotationMode == USER_ROTATION_LOCKED) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800593 // If the setting for using the sensor by default is enabled, then
594 // we will always leave it on. Note that the user could go to
595 // a window that forces an orientation that does not use the
596 // sensor and in theory we could turn it off... however, when next
597 // turning it on we won't have a good value for the current
598 // orientation for a little bit, which can cause orientation
599 // changes to lag, so we'd like to keep it always on. (It will
600 // still be turned off when the screen is off.)
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700601 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800602 }
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700603 return true;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800604 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700605
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800606 /*
607 * Various use cases for invoking this function
608 * screen turning off, should always disable listeners if already enabled
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700609 * screen turned on and current app has sensor based orientation, enable listeners
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800610 * if not already enabled
611 * screen turned on and current app does not have sensor orientation, disable listeners if
612 * already enabled
613 * screen turning on and current app has sensor based orientation, enable listeners if needed
614 * screen turning on and current app has nosensor based orientation, do nothing
615 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700616 void updateOrientationListenerLp() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800617 if (!mOrientationListener.canDetectOrientation()) {
618 // If sensor is turned off or nonexistent for some reason
619 return;
620 }
621 //Could have been invoked due to screen turning on or off or
622 //change of the currently visible window's orientation
Craig Mautnereda67292013-04-28 13:50:14 -0700623 if (localLOGV) Slog.v(TAG, "Screen status="+mScreenOnEarly+
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800624 ", current orientation="+mCurrentAppOrientation+
625 ", SensorEnabled="+mOrientationSensorEnabled);
626 boolean disable = true;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -0700627 if (mScreenOnEarly) {
The Android Open Source Project0727d222009-03-11 12:11:58 -0700628 if (needSensorRunningLp()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800629 disable = false;
630 //enable listener if not already enabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700631 if (!mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800632 mOrientationListener.enable();
Craig Mautnereda67292013-04-28 13:50:14 -0700633 if(localLOGV) Slog.v(TAG, "Enabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800634 mOrientationSensorEnabled = true;
635 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700636 }
637 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800638 //check if sensors need to be disabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700639 if (disable && mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800640 mOrientationListener.disable();
Craig Mautnereda67292013-04-28 13:50:14 -0700641 if(localLOGV) Slog.v(TAG, "Disabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800642 mOrientationSensorEnabled = false;
643 }
644 }
645
Jeff Brown4d396052010-10-29 21:50:21 -0700646 private void interceptPowerKeyDown(boolean handled) {
647 mPowerKeyHandled = handled;
648 if (!handled) {
649 mHandler.postDelayed(mPowerLongPress, ViewConfiguration.getGlobalActionKeyTimeout());
650 }
651 }
652
653 private boolean interceptPowerKeyUp(boolean canceled) {
654 if (!mPowerKeyHandled) {
655 mHandler.removeCallbacks(mPowerLongPress);
656 return !canceled;
Jeff Brown4d396052010-10-29 21:50:21 -0700657 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700658 return false;
659 }
660
661 private void cancelPendingPowerKeyAction() {
662 if (!mPowerKeyHandled) {
663 mHandler.removeCallbacks(mPowerLongPress);
664 }
Jeff Brownff204712011-10-25 21:27:54 -0700665 if (mPowerKeyTriggered) {
666 mPendingPowerKeyUpCanceled = true;
667 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700668 }
669
670 private void interceptScreenshotChord() {
Christopher Tatee90585f2012-03-05 18:56:25 -0800671 if (mScreenshotChordEnabled
672 && mVolumeDownKeyTriggered && mPowerKeyTriggered && !mVolumeUpKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700673 final long now = SystemClock.uptimeMillis();
674 if (now <= mVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS
675 && now <= mPowerKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) {
676 mVolumeDownKeyConsumedByScreenshotChord = true;
677 cancelPendingPowerKeyAction();
678
Jeff Sharkey2991fa32012-12-05 18:06:43 -0800679 mHandler.postDelayed(mScreenshotRunnable, getScreenshotChordLongPressDelay());
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700680 }
681 }
682 }
683
Winson Chung1cea2f32012-10-08 20:42:01 -0700684 private long getScreenshotChordLongPressDelay() {
Jim Miller5ecd8112013-01-09 18:50:26 -0800685 if (mKeyguardDelegate.isShowing()) {
Winson Chung1cea2f32012-10-08 20:42:01 -0700686 // Double the time it takes to take a screenshot from the keyguard
687 return (long) (KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER *
688 ViewConfiguration.getGlobalActionKeyTimeout());
Winson Chung1cea2f32012-10-08 20:42:01 -0700689 }
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800690 return ViewConfiguration.getGlobalActionKeyTimeout();
Winson Chung1cea2f32012-10-08 20:42:01 -0700691 }
692
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700693 private void cancelPendingScreenshotChordAction() {
Jeff Sharkey2991fa32012-12-05 18:06:43 -0800694 mHandler.removeCallbacks(mScreenshotRunnable);
Jeff Brown4d396052010-10-29 21:50:21 -0700695 }
696
697 private final Runnable mPowerLongPress = new Runnable() {
Craig Mautnerf1b67412012-09-19 13:18:29 -0700698 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800699 public void run() {
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700700 // The context isn't read
701 if (mLongPressOnPowerBehavior < 0) {
Jeff Brown850c5b72012-10-01 15:17:22 -0700702 mLongPressOnPowerBehavior = mContext.getResources().getInteger(
703 com.android.internal.R.integer.config_longPressOnPowerBehavior);
Joe Onoratod208e702010-10-08 16:22:43 -0400704 }
Jeff Brown850c5b72012-10-01 15:17:22 -0700705 int resolvedBehavior = mLongPressOnPowerBehavior;
706 if (FactoryTest.isLongPressOnPowerOffEnabled()) {
707 resolvedBehavior = LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM;
708 }
709
710 switch (resolvedBehavior) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700711 case LONG_PRESS_POWER_NOTHING:
712 break;
713 case LONG_PRESS_POWER_GLOBAL_ACTIONS:
714 mPowerKeyHandled = true;
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -0700715 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
716 performAuditoryFeedbackForAccessibilityIfNeed();
717 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700718 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
719 showGlobalActionsDialog();
720 break;
721 case LONG_PRESS_POWER_SHUT_OFF:
Jeff Brown9a538ee2012-08-20 14:56:57 -0700722 case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM:
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700723 mPowerKeyHandled = true;
724 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
725 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
Jeff Brown850c5b72012-10-01 15:17:22 -0700726 mWindowManagerFuncs.shutdown(resolvedBehavior == LONG_PRESS_POWER_SHUT_OFF);
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700727 break;
728 }
729 }
730 };
731
Jeff Sharkey2991fa32012-12-05 18:06:43 -0800732 private final Runnable mScreenshotRunnable = new Runnable() {
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800733 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700734 public void run() {
735 takeScreenshot();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800736 }
737 };
738
739 void showGlobalActionsDialog() {
740 if (mGlobalActions == null) {
Jeff Brown7304c342012-05-11 18:42:42 -0700741 mGlobalActions = new GlobalActions(mContext, mWindowManagerFuncs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800742 }
Mike Lockwood3a74bd32011-08-12 13:55:22 -0700743 final boolean keyguardShowing = keyguardIsShowingTq();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800744 mGlobalActions.showDialog(keyguardShowing, isDeviceProvisioned());
745 if (keyguardShowing) {
746 // since it took two seconds of long press to bring this up,
747 // poke the wake lock so they have some time to see the dialog.
Jim Miller25190572013-02-28 17:36:24 -0800748 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800749 }
750 }
751
752 boolean isDeviceProvisioned() {
Jeff Brownbf6f6f92012-09-25 15:03:20 -0700753 return Settings.Global.getInt(
754 mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800755 }
756
Patrick Dubroyece94522011-02-23 18:35:01 -0800757 private void handleLongPressOnHome() {
Joe Onorato46b0d682010-11-22 17:37:27 -0800758 if (mLongPressOnHomeBehavior != LONG_PRESS_HOME_NOTHING) {
Jeff Browncaca8812013-05-09 13:34:33 -0700759 mHomeConsumed = true;
Joe Onorato46b0d682010-11-22 17:37:27 -0800760 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
Patrick Dubroyece94522011-02-23 18:35:01 -0800761
Jeff Browncaca8812013-05-09 13:34:33 -0700762 if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI) {
763 toggleRecentApps();
764 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_ASSIST) {
765 launchAssistAction();
Jim Millere6ad1a82010-08-20 19:25:39 -0700766 }
767 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800768 }
Patrick Dubroyece94522011-02-23 18:35:01 -0800769
Jeff Browncaca8812013-05-09 13:34:33 -0700770 private void handleDoubleTapOnHome() {
771 if (mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
772 mHomeConsumed = true;
773 toggleRecentApps();
774 }
775 }
776
777 private final Runnable mHomeDoubleTapTimeoutRunnable = new Runnable() {
778 @Override
779 public void run() {
780 if (mHomeDoubleTapPending) {
781 mHomeDoubleTapPending = false;
782 launchHomeFromHotKey();
783 }
784 }
785 };
786
Patrick Dubroyece94522011-02-23 18:35:01 -0800787 /**
Jeff Brown68b909d2011-12-07 16:36:01 -0800788 * Create (if necessary) and show or dismiss the recent apps dialog according
789 * according to the requested behavior.
Patrick Dubroyece94522011-02-23 18:35:01 -0800790 */
Jeff Brown68b909d2011-12-07 16:36:01 -0800791 void showOrHideRecentAppsDialog(final int behavior) {
Jeff Brownda3d5a92011-03-29 15:11:34 -0700792 mHandler.post(new Runnable() {
793 @Override
794 public void run() {
795 if (mRecentAppsDialog == null) {
Jeff Brown54875002011-04-06 15:33:01 -0700796 mRecentAppsDialog = new RecentApplicationsDialog(mContext);
Jeff Brownda3d5a92011-03-29 15:11:34 -0700797 }
Jeff Brown54875002011-04-06 15:33:01 -0700798 if (mRecentAppsDialog.isShowing()) {
Jeff Brown68b909d2011-12-07 16:36:01 -0800799 switch (behavior) {
800 case RECENT_APPS_BEHAVIOR_SHOW_OR_DISMISS:
Jeff Brown602ab322012-05-16 13:33:47 -0700801 case RECENT_APPS_BEHAVIOR_DISMISS:
Jeff Brown68b909d2011-12-07 16:36:01 -0800802 mRecentAppsDialog.dismiss();
803 break;
804 case RECENT_APPS_BEHAVIOR_DISMISS_AND_SWITCH:
805 mRecentAppsDialog.dismissAndSwitch();
806 break;
807 case RECENT_APPS_BEHAVIOR_EXIT_TOUCH_MODE_AND_SHOW:
808 default:
809 break;
Jeff Brown54875002011-04-06 15:33:01 -0700810 }
811 } else {
Jeff Brown68b909d2011-12-07 16:36:01 -0800812 switch (behavior) {
813 case RECENT_APPS_BEHAVIOR_SHOW_OR_DISMISS:
814 mRecentAppsDialog.show();
815 break;
816 case RECENT_APPS_BEHAVIOR_EXIT_TOUCH_MODE_AND_SHOW:
817 try {
818 mWindowManager.setInTouchMode(false);
819 } catch (RemoteException e) {
820 }
821 mRecentAppsDialog.show();
822 break;
Jeff Brown602ab322012-05-16 13:33:47 -0700823 case RECENT_APPS_BEHAVIOR_DISMISS:
Jeff Brown68b909d2011-12-07 16:36:01 -0800824 case RECENT_APPS_BEHAVIOR_DISMISS_AND_SWITCH:
825 default:
826 break;
827 }
Jeff Brown54875002011-04-06 15:33:01 -0700828 }
Jeff Brownda3d5a92011-03-29 15:11:34 -0700829 }
830 });
Patrick Dubroyece94522011-02-23 18:35:01 -0800831 }
Jeff Brownda3d5a92011-03-29 15:11:34 -0700832
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800833 /** {@inheritDoc} */
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800834 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800835 public void init(Context context, IWindowManager windowManager,
Jeff Brown96307042012-07-27 15:51:34 -0700836 WindowManagerFuncs windowManagerFuncs) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800837 mContext = context;
838 mWindowManager = windowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700839 mWindowManagerFuncs = windowManagerFuncs;
Mike Lockwoodd747dc82011-09-13 16:28:22 -0400840 mHeadless = "1".equals(SystemProperties.get("ro.config.headless", "0"));
Jeff Brown70825162012-03-28 17:27:48 -0700841 mHandler = new PolicyHandler();
Craig Mautnereee29c42013-01-17 14:44:34 -0800842 mOrientationListener = new MyOrientationListener(mContext, mHandler);
Jeff Brownc0347aa2011-09-23 17:26:09 -0700843 try {
844 mOrientationListener.setCurrentRotation(windowManager.getRotation());
845 } catch (RemoteException ex) { }
Christopher Tate5e08af02012-09-21 17:17:22 -0700846 mSettingsObserver = new SettingsObserver(mHandler);
847 mSettingsObserver.observe();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800848 mShortcutManager = new ShortcutManager(context, mHandler);
849 mShortcutManager.observe();
Daniel Sandler6396c722013-04-16 20:19:09 -0400850 mUiMode = context.getResources().getInteger(
851 com.android.internal.R.integer.config_defaultUiModeType);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800852 mHomeIntent = new Intent(Intent.ACTION_MAIN, null);
853 mHomeIntent.addCategory(Intent.CATEGORY_HOME);
854 mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
855 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700856 mCarDockIntent = new Intent(Intent.ACTION_MAIN, null);
857 mCarDockIntent.addCategory(Intent.CATEGORY_CAR_DOCK);
858 mCarDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
859 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
860 mDeskDockIntent = new Intent(Intent.ACTION_MAIN, null);
861 mDeskDockIntent.addCategory(Intent.CATEGORY_DESK_DOCK);
862 mDeskDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
863 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Jim Millere6ad1a82010-08-20 19:25:39 -0700864
Jeff Brown96307042012-07-27 15:51:34 -0700865 mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
866 mBroadcastWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800867 "PhoneWindowManager.mBroadcastWakeLock");
868 mEnableShiftMenuBugReports = "1".equals(SystemProperties.get("ro.debuggable"));
Dianne Hackborn2862fff2009-09-15 22:56:29 -0700869 mLidOpenRotation = readRotation(
Mike Lockwood2d1efbd2009-09-16 12:15:53 -0400870 com.android.internal.R.integer.config_lidOpenRotation);
871 mCarDockRotation = readRotation(
872 com.android.internal.R.integer.config_carDockRotation);
873 mDeskDockRotation = readRotation(
874 com.android.internal.R.integer.config_deskDockRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -0700875 mUndockedHdmiRotation = readRotation(
876 com.android.internal.R.integer.config_undockedHdmiRotation);
Mike Lockwoode9867d22009-09-20 01:59:02 -0400877 mCarDockEnablesAccelerometer = mContext.getResources().getBoolean(
878 com.android.internal.R.bool.config_carDockEnablesAccelerometer);
879 mDeskDockEnablesAccelerometer = mContext.getResources().getBoolean(
880 com.android.internal.R.bool.config_deskDockEnablesAccelerometer);
Dianne Hackborn2862fff2009-09-15 22:56:29 -0700881 mLidKeyboardAccessibility = mContext.getResources().getInteger(
882 com.android.internal.R.integer.config_lidKeyboardAccessibility);
883 mLidNavigationAccessibility = mContext.getResources().getInteger(
884 com.android.internal.R.integer.config_lidNavigationAccessibility);
Jeff Brownc458ce92012-04-30 14:58:40 -0700885 mLidControlsSleep = mContext.getResources().getBoolean(
886 com.android.internal.R.bool.config_lidControlsSleep);
Jeff Brownf71343d2013-05-31 17:59:11 -0700887 readConfigurationDependentBehaviors();
Jeff Browncaca8812013-05-09 13:34:33 -0700888
Mike Lockwood1753f7f2009-08-24 14:49:07 -0700889 // register for dock events
Dianne Hackborn78968392010-03-04 20:47:56 -0800890 IntentFilter filter = new IntentFilter();
891 filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE);
892 filter.addAction(UiModeManager.ACTION_EXIT_CAR_MODE);
893 filter.addAction(UiModeManager.ACTION_ENTER_DESK_MODE);
894 filter.addAction(UiModeManager.ACTION_EXIT_DESK_MODE);
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700895 filter.addAction(Intent.ACTION_DOCK_EVENT);
896 Intent intent = context.registerReceiver(mDockReceiver, filter);
897 if (intent != null) {
898 // Retrieve current sticky dock event broadcast.
899 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
900 Intent.EXTRA_DOCK_STATE_UNDOCKED);
901 }
Daniel Sandler7e37df52011-11-16 22:08:23 -0800902
Jeff Brown6aaf2952012-10-05 16:01:08 -0700903 // register for dream-related broadcasts
904 filter = new IntentFilter();
905 filter.addAction(Intent.ACTION_DREAMING_STARTED);
906 filter.addAction(Intent.ACTION_DREAMING_STOPPED);
907 context.registerReceiver(mDreamReceiver, filter);
908
Christopher Tate5e08af02012-09-21 17:17:22 -0700909 // register for multiuser-relevant broadcasts
910 filter = new IntentFilter(Intent.ACTION_USER_SWITCHED);
911 context.registerReceiver(mMultiuserReceiver, filter);
912
John Spurlock57306e62013-04-22 09:48:49 -0400913 // monitor for system gestures
Craig Mautner037aa8d2013-06-07 10:35:44 -0700914 mSystemGestures = new SystemGesturesPointerEventListener(context,
915 new SystemGesturesPointerEventListener.Callbacks() {
John Spurlock57306e62013-04-22 09:48:49 -0400916 @Override
917 public void onSwipeFromTop() {
John Spurlock04db1762013-05-13 12:46:41 -0400918 if (mStatusBar != null) {
919 requestHideybars(mStatusBar);
920 }
John Spurlockad3e6cb2013-04-30 08:47:43 -0400921 }
922 @Override
923 public void onSwipeFromBottom() {
John Spurlock04db1762013-05-13 12:46:41 -0400924 if (mNavigationBar != null && mNavigationBarOnBottom) {
925 requestHideybars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -0400926 }
927 }
928 @Override
929 public void onSwipeFromRight() {
John Spurlock04db1762013-05-13 12:46:41 -0400930 if (mNavigationBar != null && !mNavigationBarOnBottom) {
931 requestHideybars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -0400932 }
933 }
934 @Override
935 public void onDebug() {
John Spurlock245fd012013-05-31 10:31:04 -0400936 if (OverlayTesting.enabled) {
John Spurlockad3e6cb2013-04-30 08:47:43 -0400937 OverlayTesting.toggleForceOverlay(mFocusedWindow, mContext);
938 }
939 }
940 });
Craig Mautner037aa8d2013-06-07 10:35:44 -0700941 mWindowManagerFuncs.registerPointerEventListener(mSystemGestures);
John Spurlock32beb2c2013-03-11 10:16:47 -0400942
Jeff Brownc2346132012-04-13 01:55:38 -0700943 mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700944 mLongPressVibePattern = getLongIntArray(mContext.getResources(),
945 com.android.internal.R.array.config_longPressVibePattern);
946 mVirtualKeyVibePattern = getLongIntArray(mContext.getResources(),
947 com.android.internal.R.array.config_virtualKeyVibePattern);
Amith Yamasanic33cb712010-02-10 15:21:49 -0800948 mKeyboardTapVibePattern = getLongIntArray(mContext.getResources(),
949 com.android.internal.R.array.config_keyboardTapVibePattern);
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700950 mSafeModeDisabledVibePattern = getLongIntArray(mContext.getResources(),
951 com.android.internal.R.array.config_safeModeDisabledVibePattern);
952 mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(),
953 com.android.internal.R.array.config_safeModeEnabledVibePattern);
Daniel Sandler40427442010-07-16 11:44:52 -0400954
Christopher Tatee90585f2012-03-05 18:56:25 -0800955 mScreenshotChordEnabled = mContext.getResources().getBoolean(
956 com.android.internal.R.bool.config_enableScreenshotChord);
957
Justin Kohd378ad72013-04-01 12:18:26 -0700958 mGlobalKeyManager = new GlobalKeyManager(mContext);
959
Joe Onoratoea495d42011-04-06 11:41:11 -0700960 // Controls rotation and the like.
961 initializeHdmiState();
Dianne Hackborn40011092011-09-22 13:37:48 -0700962
963 // Match current screen state.
964 if (mPowerManager.isScreenOn()) {
965 screenTurningOn(null);
966 } else {
967 screenTurnedOff(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
968 }
Mike Lockwood1753f7f2009-08-24 14:49:07 -0700969 }
970
Jeff Brownf71343d2013-05-31 17:59:11 -0700971 /**
972 * Read values from config.xml that may be overridden depending on
973 * the configuration of the device.
974 * eg. Disable long press on home goes to recents on sw600dp.
975 */
976 private void readConfigurationDependentBehaviors() {
977 mLongPressOnHomeBehavior = mContext.getResources().getInteger(
978 com.android.internal.R.integer.config_longPressOnHomeBehavior);
979 if (mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING ||
980 mLongPressOnHomeBehavior > LONG_PRESS_HOME_ASSIST) {
981 mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
982 }
983
984 mDoubleTapOnHomeBehavior = mContext.getResources().getInteger(
985 com.android.internal.R.integer.config_doubleTapOnHomeBehavior);
986 if (mDoubleTapOnHomeBehavior < DOUBLE_TAP_HOME_NOTHING ||
987 mDoubleTapOnHomeBehavior > DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
988 mDoubleTapOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
989 }
990 }
991
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800992 @Override
Dianne Hackborndde331c2012-08-03 14:01:57 -0700993 public void setInitialDisplaySize(Display display, int width, int height, int density) {
Dianne Hackbornc652de82013-02-15 16:32:56 -0800994 if (display.getDisplayId() != Display.DEFAULT_DISPLAY) {
995 throw new IllegalArgumentException("Can only set the default display");
996 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700997 mDisplay = display;
998
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700999 final Resources res = mContext.getResources();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001000 int shortSize, longSize;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001001 if (width > height) {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001002 shortSize = height;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001003 longSize = width;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001004 mLandscapeRotation = Surface.ROTATION_0;
1005 mSeascapeRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001006 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001007 mPortraitRotation = Surface.ROTATION_90;
1008 mUpsideDownRotation = Surface.ROTATION_270;
1009 } else {
1010 mPortraitRotation = Surface.ROTATION_270;
1011 mUpsideDownRotation = Surface.ROTATION_90;
1012 }
1013 } else {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001014 shortSize = width;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001015 longSize = height;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001016 mPortraitRotation = Surface.ROTATION_0;
1017 mUpsideDownRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001018 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001019 mLandscapeRotation = Surface.ROTATION_270;
1020 mSeascapeRotation = Surface.ROTATION_90;
1021 } else {
1022 mLandscapeRotation = Surface.ROTATION_90;
1023 mSeascapeRotation = Surface.ROTATION_270;
1024 }
1025 }
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001026
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001027 mStatusBarHeight =
1028 res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001029
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001030 // Height of the navigation bar when presented horizontally at bottom
1031 mNavigationBarHeightForRotation[mPortraitRotation] =
1032 mNavigationBarHeightForRotation[mUpsideDownRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001033 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_height);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001034 mNavigationBarHeightForRotation[mLandscapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001035 mNavigationBarHeightForRotation[mSeascapeRotation] = res.getDimensionPixelSize(
1036 com.android.internal.R.dimen.navigation_bar_height_landscape);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001037
1038 // Width of the navigation bar when presented vertically along one side
1039 mNavigationBarWidthForRotation[mPortraitRotation] =
1040 mNavigationBarWidthForRotation[mUpsideDownRotation] =
1041 mNavigationBarWidthForRotation[mLandscapeRotation] =
1042 mNavigationBarWidthForRotation[mSeascapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001043 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_width);
Daniel Sandler4a066c52012-04-20 14:49:13 -04001044
1045 // SystemUI (status bar) layout policy
Dianne Hackborndde331c2012-08-03 14:01:57 -07001046 int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / density;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001047 int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / density;
Daniel Sandler4a066c52012-04-20 14:49:13 -04001048
Craig Mautnerd4ec33242013-07-22 10:37:43 -07001049 // Allow the navigation bar to move on small devices (phones).
1050 mNavigationBarCanMove = shortSizeDp < 600;
Daniel Sandler36412a72011-08-04 09:35:13 -04001051
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001052 mHasNavigationBar = res.getBoolean(com.android.internal.R.bool.config_showNavigationBar);
John Spurlock80f00c12013-06-13 11:10:51 -04001053 // Allow a system property to override this. Used by the emulator.
1054 // See also hasNavigationBar().
1055 String navBarOverride = SystemProperties.get("qemu.hw.mainkeys");
1056 if ("1".equals(navBarOverride)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001057 mHasNavigationBar = false;
John Spurlock80f00c12013-06-13 11:10:51 -04001058 } else if ("0".equals(navBarOverride)) {
1059 mHasNavigationBar = true;
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04001060 }
1061
John Spurlock80f00c12013-06-13 11:10:51 -04001062 if (mHasNavigationBar) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001063 // The navigation bar is at the right in landscape; it seems always
1064 // useful to hide it for showing a video.
1065 mCanHideNavigationBar = true;
1066 } else {
1067 mCanHideNavigationBar = false;
1068 }
Erik Gilling9a41ef82011-09-26 19:21:03 -07001069
Jeff Brown27f1d672012-10-17 18:32:34 -07001070 // For demo purposes, allow the rotation of the HDMI display to be controlled.
1071 // By default, HDMI locks rotation to landscape.
Erik Gilling9a41ef82011-09-26 19:21:03 -07001072 if ("portrait".equals(SystemProperties.get("persist.demo.hdmirotation"))) {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001073 mDemoHdmiRotation = mPortraitRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001074 } else {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001075 mDemoHdmiRotation = mLandscapeRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001076 }
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001077 mDemoHdmiRotationLock = SystemProperties.getBoolean("persist.demo.hdmirotationlock", false);
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001078
1079 // Only force the default orientation if the screen is xlarge, at least 960dp x 720dp, per
1080 // http://developer.android.com/guide/practices/screens_support.html#range
1081 mForceDefaultOrientation = longSizeDp >= 960 && shortSizeDp >= 720 &&
1082 res.getBoolean(com.android.internal.R.bool.config_forceDefaultOrientation) &&
1083 // For debug purposes the next line turns this feature off with:
1084 // $ adb shell setprop config.override_forced_orient true
1085 // $ adb shell wm size reset
1086 !"true".equals(SystemProperties.get("config.override_forced_orient"));
1087 }
1088
1089 @Override
1090 public boolean isDefaultOrientationForced() {
1091 return mForceDefaultOrientation;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001092 }
1093
Dianne Hackbornc652de82013-02-15 16:32:56 -08001094 @Override
1095 public void setDisplayOverscan(Display display, int left, int top, int right, int bottom) {
1096 if (display.getDisplayId() == Display.DEFAULT_DISPLAY) {
1097 mOverscanLeft = left;
1098 mOverscanTop = top;
1099 mOverscanRight = right;
1100 mOverscanBottom = bottom;
1101 }
1102 }
1103
Dianne Hackbornc777e072010-02-12 13:07:59 -08001104 public void updateSettings() {
1105 ContentResolver resolver = mContext.getContentResolver();
1106 boolean updateRotation = false;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001107 synchronized (mLock) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001108 mEndcallBehavior = Settings.System.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001109 Settings.System.END_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001110 Settings.System.END_BUTTON_BEHAVIOR_DEFAULT,
1111 UserHandle.USER_CURRENT);
1112 mIncallPowerBehavior = Settings.Secure.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001113 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001114 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT,
1115 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001116
Jeff Brown207673cd2012-06-05 17:47:11 -07001117 // Configure rotation lock.
Christopher Tate5e08af02012-09-21 17:17:22 -07001118 int userRotation = Settings.System.getIntForUser(resolver,
1119 Settings.System.USER_ROTATION, Surface.ROTATION_0,
1120 UserHandle.USER_CURRENT);
Jeff Brown207673cd2012-06-05 17:47:11 -07001121 if (mUserRotation != userRotation) {
1122 mUserRotation = userRotation;
1123 updateRotation = true;
1124 }
Christopher Tate5e08af02012-09-21 17:17:22 -07001125 int userRotationMode = Settings.System.getIntForUser(resolver,
1126 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
Jeff Brown207673cd2012-06-05 17:47:11 -07001127 WindowManagerPolicy.USER_ROTATION_FREE :
1128 WindowManagerPolicy.USER_ROTATION_LOCKED;
1129 if (mUserRotationMode != userRotationMode) {
1130 mUserRotationMode = userRotationMode;
1131 updateRotation = true;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001132 updateOrientationListenerLp();
1133 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001134
Dianne Hackbornc777e072010-02-12 13:07:59 -08001135 if (mSystemReady) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001136 int pointerLocation = Settings.System.getIntForUser(resolver,
1137 Settings.System.POINTER_LOCATION, 0, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001138 if (mPointerLocationMode != pointerLocation) {
1139 mPointerLocationMode = pointerLocation;
Jeff Brown70825162012-03-28 17:27:48 -07001140 mHandler.sendEmptyMessage(pointerLocation != 0 ?
1141 MSG_ENABLE_POINTER_LOCATION : MSG_DISABLE_POINTER_LOCATION);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001142 }
1143 }
1144 // use screen off timeout setting as the timeout for the lockscreen
Christopher Tate5e08af02012-09-21 17:17:22 -07001145 mLockScreenTimeout = Settings.System.getIntForUser(resolver,
1146 Settings.System.SCREEN_OFF_TIMEOUT, 0, UserHandle.USER_CURRENT);
1147 String imId = Settings.Secure.getStringForUser(resolver,
1148 Settings.Secure.DEFAULT_INPUT_METHOD, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001149 boolean hasSoftInput = imId != null && imId.length() > 0;
1150 if (mHasSoftInput != hasSoftInput) {
1151 mHasSoftInput = hasSoftInput;
1152 updateRotation = true;
1153 }
John Spurlock245fd012013-05-31 10:31:04 -04001154 OverlayTesting.enabled = Settings.System.getIntForUser(resolver,
1155 OverlayTesting.ENABLED_SETTING, 0, UserHandle.USER_CURRENT) != 0;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001156 }
1157 if (updateRotation) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07001158 updateRotation(true);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001159 }
Jeff Brown70825162012-03-28 17:27:48 -07001160 }
1161
1162 private void enablePointerLocation() {
1163 if (mPointerLocationView == null) {
1164 mPointerLocationView = new PointerLocationView(mContext);
1165 mPointerLocationView.setPrintCoords(false);
1166
Dianne Hackbornc777e072010-02-12 13:07:59 -08001167 WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
1168 WindowManager.LayoutParams.MATCH_PARENT,
1169 WindowManager.LayoutParams.MATCH_PARENT);
Jeff Brown3b2b3542010-10-15 00:54:27 -07001170 lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001171 lp.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN
1172 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
1173 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1174 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
Jeff Brown90fc9052012-10-01 14:44:24 -07001175 if (ActivityManager.isHighEndGfx()) {
1176 lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
1177 lp.privateFlags |=
1178 WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED;
1179 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001180 lp.format = PixelFormat.TRANSLUCENT;
1181 lp.setTitle("PointerLocation");
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001182 WindowManager wm = (WindowManager)
Dianne Hackbornc777e072010-02-12 13:07:59 -08001183 mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Browncc4f7db2011-08-30 20:34:48 -07001184 lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL;
Jeff Brown70825162012-03-28 17:27:48 -07001185 wm.addView(mPointerLocationView, lp);
1186
Craig Mautner037aa8d2013-06-07 10:35:44 -07001187 mPointerLocationPointerEventListener = new PointerLocationPointerEventListener();
1188 mWindowManagerFuncs.registerPointerEventListener(mPointerLocationPointerEventListener);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001189 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001190 }
Jeff Brown70825162012-03-28 17:27:48 -07001191
1192 private void disablePointerLocation() {
Craig Mautner037aa8d2013-06-07 10:35:44 -07001193 if (mPointerLocationPointerEventListener != null) {
1194 mWindowManagerFuncs.unregisterPointerEventListener(
1195 mPointerLocationPointerEventListener);
1196 mPointerLocationPointerEventListener = null;
Jeff Brown70825162012-03-28 17:27:48 -07001197 }
1198
1199 if (mPointerLocationView != null) {
1200 WindowManager wm = (WindowManager)
1201 mContext.getSystemService(Context.WINDOW_SERVICE);
1202 wm.removeView(mPointerLocationView);
1203 mPointerLocationView = null;
1204 }
1205 }
1206
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001207 private int readRotation(int resID) {
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001208 try {
1209 int rotation = mContext.getResources().getInteger(resID);
1210 switch (rotation) {
1211 case 0:
1212 return Surface.ROTATION_0;
1213 case 90:
1214 return Surface.ROTATION_90;
1215 case 180:
1216 return Surface.ROTATION_180;
1217 case 270:
1218 return Surface.ROTATION_270;
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001219 }
1220 } catch (Resources.NotFoundException e) {
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001221 // fall through
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001222 }
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001223 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001224 }
1225
1226 /** {@inheritDoc} */
Craig Mautner88400d32012-09-30 12:35:45 -07001227 @Override
Dianne Hackbornc2293022013-02-06 23:14:49 -08001228 public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001229 int type = attrs.type;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001230
1231 outAppOp[0] = AppOpsManager.OP_NONE;
1232
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001233 if (type < WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW
1234 || type > WindowManager.LayoutParams.LAST_SYSTEM_WINDOW) {
Jeff Brown98365d72012-08-19 20:30:52 -07001235 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001236 }
1237 String permission = null;
1238 switch (type) {
1239 case TYPE_TOAST:
1240 // XXX right now the app process has complete control over
1241 // this... should introduce a token to let the system
1242 // monitor/control what they are doing.
1243 break;
Daniel Sandler7d276c32012-01-30 14:33:52 -05001244 case TYPE_DREAM:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001245 case TYPE_INPUT_METHOD:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001246 case TYPE_WALLPAPER:
keunyounga446bf02013-06-21 19:07:57 -07001247 case TYPE_PRIVATE_PRESENTATION:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001248 // The window manager will check these.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001249 break;
1250 case TYPE_PHONE:
1251 case TYPE_PRIORITY_PHONE:
1252 case TYPE_SYSTEM_ALERT:
1253 case TYPE_SYSTEM_ERROR:
1254 case TYPE_SYSTEM_OVERLAY:
1255 permission = android.Manifest.permission.SYSTEM_ALERT_WINDOW;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001256 outAppOp[0] = AppOpsManager.OP_SYSTEM_ALERT_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001257 break;
1258 default:
1259 permission = android.Manifest.permission.INTERNAL_SYSTEM_WINDOW;
1260 }
1261 if (permission != null) {
1262 if (mContext.checkCallingOrSelfPermission(permission)
1263 != PackageManager.PERMISSION_GRANTED) {
Jeff Brown98365d72012-08-19 20:30:52 -07001264 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001265 }
1266 }
Jeff Brown98365d72012-08-19 20:30:52 -07001267 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001268 }
Craig Mautner88400d32012-09-30 12:35:45 -07001269
1270 @Override
1271 public boolean checkShowToOwnerOnly(WindowManager.LayoutParams attrs) {
1272
1273 // If this switch statement is modified, modify the comment in the declarations of
1274 // the type in {@link WindowManager.LayoutParams} as well.
1275 switch (attrs.type) {
1276 default:
1277 // These are the windows that by default are shown only to the user that created
1278 // them. If this needs to be overridden, set
1279 // {@link WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS} in
1280 // {@link WindowManager.LayoutParams}. Note that permission
1281 // {@link android.Manifest.permission.INTERNAL_SYSTEM_WINDOW} is required as well.
1282 if ((attrs.privateFlags & PRIVATE_FLAG_SHOW_FOR_ALL_USERS) == 0) {
1283 return true;
1284 }
1285 break;
1286
1287 // These are the windows that by default are shown to all users. However, to
1288 // protect against spoofing, check permissions below.
1289 case TYPE_APPLICATION_STARTING:
1290 case TYPE_BOOT_PROGRESS:
1291 case TYPE_DISPLAY_OVERLAY:
1292 case TYPE_HIDDEN_NAV_CONSUMER:
1293 case TYPE_KEYGUARD:
Jim Miller5ecd8112013-01-09 18:50:26 -08001294 case TYPE_KEYGUARD_SCRIM:
Craig Mautner88400d32012-09-30 12:35:45 -07001295 case TYPE_KEYGUARD_DIALOG:
1296 case TYPE_MAGNIFICATION_OVERLAY:
1297 case TYPE_NAVIGATION_BAR:
1298 case TYPE_NAVIGATION_BAR_PANEL:
1299 case TYPE_PHONE:
1300 case TYPE_POINTER:
1301 case TYPE_PRIORITY_PHONE:
1302 case TYPE_RECENTS_OVERLAY:
1303 case TYPE_SEARCH_BAR:
1304 case TYPE_STATUS_BAR:
1305 case TYPE_STATUS_BAR_PANEL:
1306 case TYPE_STATUS_BAR_SUB_PANEL:
1307 case TYPE_SYSTEM_DIALOG:
1308 case TYPE_UNIVERSE_BACKGROUND:
1309 case TYPE_VOLUME_OVERLAY:
keunyounga446bf02013-06-21 19:07:57 -07001310 case TYPE_PRIVATE_PRESENTATION:
Craig Mautner88400d32012-09-30 12:35:45 -07001311 break;
1312 }
1313
1314 // Check if third party app has set window to system window type.
1315 return mContext.checkCallingOrSelfPermission(
1316 android.Manifest.permission.INTERNAL_SYSTEM_WINDOW)
1317 != PackageManager.PERMISSION_GRANTED;
1318 }
1319
Craig Mautner967212c2013-04-13 21:10:58 -07001320 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001321 public void adjustWindowParamsLw(WindowManager.LayoutParams attrs) {
1322 switch (attrs.type) {
1323 case TYPE_SYSTEM_OVERLAY:
Jeff Brown3b2b3542010-10-15 00:54:27 -07001324 case TYPE_SECURE_SYSTEM_OVERLAY:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001325 // These types of windows can't receive input events.
1326 attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1327 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001328 attrs.flags &= ~WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001329 break;
1330 }
1331 }
1332
1333 void readLidState() {
Jeff Brown2e7760e2012-04-11 15:14:55 -07001334 mLidState = mWindowManagerFuncs.getLidState();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001335 }
1336
Jeff Browndaa37532012-05-01 15:54:03 -07001337 private boolean isHidden(int accessibilityMode) {
1338 switch (accessibilityMode) {
1339 case 1:
1340 return mLidState == LID_CLOSED;
1341 case 2:
1342 return mLidState == LID_OPEN;
1343 default:
1344 return false;
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001345 }
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001346 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001347
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001348 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07001349 @Override
Jeff Browndaa37532012-05-01 15:54:03 -07001350 public void adjustConfigurationLw(Configuration config, int keyboardPresence,
1351 int navigationPresence) {
1352 mHaveBuiltInKeyboard = (keyboardPresence & PRESENCE_INTERNAL) != 0;
1353
Jeff Brownf71343d2013-05-31 17:59:11 -07001354 readConfigurationDependentBehaviors();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001355 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07001356 applyLidSwitchState();
Jeff Brownd04a88c2011-01-16 14:05:47 -08001357
Jeff Browndaa37532012-05-01 15:54:03 -07001358 if (config.keyboard == Configuration.KEYBOARD_NOKEYS
1359 || (keyboardPresence == PRESENCE_INTERNAL
1360 && isHidden(mLidKeyboardAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001361 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_YES;
Jeff Browndaa37532012-05-01 15:54:03 -07001362 if (!mHasSoftInput) {
1363 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_YES;
1364 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001365 }
1366
Jeff Browndaa37532012-05-01 15:54:03 -07001367 if (config.navigation == Configuration.NAVIGATION_NONAV
1368 || (navigationPresence == PRESENCE_INTERNAL
1369 && isHidden(mLidNavigationAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001370 config.navigationHidden = Configuration.NAVIGATIONHIDDEN_YES;
Jeff Brownd04a88c2011-01-16 14:05:47 -08001371 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001372 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001373
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001374 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07001375 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001376 public int windowTypeToLayerLw(int type) {
1377 if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001378 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001379 }
1380 switch (type) {
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001381 case TYPE_UNIVERSE_BACKGROUND:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001382 return 1;
keunyounga446bf02013-06-21 19:07:57 -07001383 case TYPE_PRIVATE_PRESENTATION:
1384 return 2;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001385 case TYPE_WALLPAPER:
1386 // wallpaper is at the bottom, though the window manager may move it.
1387 return 2;
1388 case TYPE_PHONE:
1389 return 3;
1390 case TYPE_SEARCH_BAR:
1391 return 4;
Craig Mautner88400d32012-09-30 12:35:45 -07001392 case TYPE_RECENTS_OVERLAY:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001393 case TYPE_SYSTEM_DIALOG:
1394 return 5;
1395 case TYPE_TOAST:
1396 // toasts and the plugged-in battery thing
1397 return 6;
1398 case TYPE_PRIORITY_PHONE:
1399 // SIM errors and unlock. Not sure if this really should be in a high layer.
1400 return 7;
1401 case TYPE_DREAM:
1402 // used for Dreams (screensavers with TYPE_DREAM windows)
1403 return 8;
1404 case TYPE_SYSTEM_ALERT:
1405 // like the ANR / app crashed dialogs
1406 return 9;
1407 case TYPE_INPUT_METHOD:
1408 // on-screen keyboards and other such input method user interfaces go here.
1409 return 10;
1410 case TYPE_INPUT_METHOD_DIALOG:
1411 // on-screen keyboards and other such input method user interfaces go here.
1412 return 11;
Jim Miller5ecd8112013-01-09 18:50:26 -08001413 case TYPE_KEYGUARD_SCRIM:
1414 // the safety window that shows behind keyguard while keyguard is starting
1415 return 12;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001416 case TYPE_KEYGUARD:
1417 // the keyguard; nothing on top of these can take focus, since they are
1418 // responsible for power management when displayed.
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001419 return 13;
Jim Miller5ecd8112013-01-09 18:50:26 -08001420 case TYPE_KEYGUARD_DIALOG:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001421 return 14;
Jim Miller5ecd8112013-01-09 18:50:26 -08001422 case TYPE_STATUS_BAR_SUB_PANEL:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001423 return 15;
Jim Miller5ecd8112013-01-09 18:50:26 -08001424 case TYPE_STATUS_BAR:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001425 return 16;
Jim Miller5ecd8112013-01-09 18:50:26 -08001426 case TYPE_STATUS_BAR_PANEL:
1427 return 17;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001428 case TYPE_VOLUME_OVERLAY:
1429 // the on-screen volume indicator and controller shown when the user
1430 // changes the device volume
Jim Miller5ecd8112013-01-09 18:50:26 -08001431 return 18;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001432 case TYPE_SYSTEM_OVERLAY:
1433 // the on-screen volume indicator and controller shown when the user
1434 // changes the device volume
Jim Miller5ecd8112013-01-09 18:50:26 -08001435 return 19;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001436 case TYPE_NAVIGATION_BAR:
1437 // the navigation bar, if available, shows atop most things
Jim Miller5ecd8112013-01-09 18:50:26 -08001438 return 20;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001439 case TYPE_NAVIGATION_BAR_PANEL:
1440 // some panels (e.g. search) need to show on top of the navigation bar
Jim Miller5ecd8112013-01-09 18:50:26 -08001441 return 21;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001442 case TYPE_SYSTEM_ERROR:
1443 // system-level error dialogs
Jim Miller5ecd8112013-01-09 18:50:26 -08001444 return 22;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001445 case TYPE_MAGNIFICATION_OVERLAY:
1446 // used to highlight the magnified portion of a display
Jim Miller5ecd8112013-01-09 18:50:26 -08001447 return 23;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001448 case TYPE_DISPLAY_OVERLAY:
1449 // used to simulate secondary display devices
Jim Miller5ecd8112013-01-09 18:50:26 -08001450 return 24;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001451 case TYPE_DRAG:
1452 // the drag layer: input for drag-and-drop is associated with this window,
1453 // which sits above all other focusable windows
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001454 return 25;
Jim Miller5ecd8112013-01-09 18:50:26 -08001455 case TYPE_SECURE_SYSTEM_OVERLAY:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001456 return 26;
Jim Miller5ecd8112013-01-09 18:50:26 -08001457 case TYPE_BOOT_PROGRESS:
1458 return 27;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001459 case TYPE_POINTER:
1460 // the (mouse) pointer layer
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001461 return 28;
Jim Miller5ecd8112013-01-09 18:50:26 -08001462 case TYPE_HIDDEN_NAV_CONSUMER:
1463 return 29;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001464 }
1465 Log.e(TAG, "Unknown window type: " + type);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001466 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001467 }
1468
1469 /** {@inheritDoc} */
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001470 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001471 public int subWindowTypeToLayerLw(int type) {
1472 switch (type) {
1473 case TYPE_APPLICATION_PANEL:
1474 case TYPE_APPLICATION_ATTACHED_DIALOG:
1475 return APPLICATION_PANEL_SUBLAYER;
1476 case TYPE_APPLICATION_MEDIA:
1477 return APPLICATION_MEDIA_SUBLAYER;
Dianne Hackborn5cb8d792009-05-21 17:34:15 -07001478 case TYPE_APPLICATION_MEDIA_OVERLAY:
1479 return APPLICATION_MEDIA_OVERLAY_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001480 case TYPE_APPLICATION_SUB_PANEL:
1481 return APPLICATION_SUB_PANEL_SUBLAYER;
1482 }
1483 Log.e(TAG, "Unknown sub-window type: " + type);
1484 return 0;
1485 }
1486
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001487 @Override
Dianne Hackbornabe0da02009-09-18 01:55:39 -07001488 public int getMaxWallpaperLayer() {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001489 return windowTypeToLayerLw(TYPE_STATUS_BAR);
Dianne Hackbornabe0da02009-09-18 01:55:39 -07001490 }
1491
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001492 @Override
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001493 public int getAboveUniverseLayer() {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001494 return windowTypeToLayerLw(TYPE_SYSTEM_ERROR);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001495 }
1496
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001497 public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07001498 if (mHasNavigationBar) {
1499 // For a basic navigation bar, when we are in landscape mode we place
1500 // the navigation bar to the side.
Daniel Sandler4a066c52012-04-20 14:49:13 -04001501 if (mNavigationBarCanMove && fullWidth > fullHeight) {
1502 return fullWidth - mNavigationBarWidthForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07001503 }
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001504 }
1505 return fullWidth;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001506 }
1507
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001508 public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07001509 if (mHasNavigationBar) {
1510 // For a basic navigation bar, when we are in portrait mode we place
1511 // the navigation bar to the bottom.
Daniel Sandler4a066c52012-04-20 14:49:13 -04001512 if (!mNavigationBarCanMove || fullWidth < fullHeight) {
1513 return fullHeight - mNavigationBarHeightForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07001514 }
1515 }
1516 return fullHeight;
Dianne Hackborn69cb8752011-05-19 18:13:32 -07001517 }
1518
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001519 public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation) {
1520 return getNonDecorDisplayWidth(fullWidth, fullHeight, rotation);
Dianne Hackborn69cb8752011-05-19 18:13:32 -07001521 }
1522
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001523 public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation) {
John Spurlock80f00c12013-06-13 11:10:51 -04001524 // There is a separate status bar at the top of the display. We don't count that as part
1525 // of the fixed decor, since it can hide; however, for purposes of configurations,
Dianne Hackborn077ee852012-04-09 16:27:07 -07001526 // we do want to exclude it since applications can't generally use that part
1527 // of the screen.
John Spurlock80f00c12013-06-13 11:10:51 -04001528 return getNonDecorDisplayHeight(fullWidth, fullHeight, rotation) - mStatusBarHeight;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001529 }
1530
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001531 @Override
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07001532 public boolean doesForceHide(WindowState win, WindowManager.LayoutParams attrs) {
1533 return attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD;
1534 }
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001535
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001536 @Override
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07001537 public boolean canBeForceHidden(WindowState win, WindowManager.LayoutParams attrs) {
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001538 switch (attrs.type) {
1539 case TYPE_STATUS_BAR:
1540 case TYPE_NAVIGATION_BAR:
1541 case TYPE_WALLPAPER:
1542 case TYPE_DREAM:
1543 case TYPE_UNIVERSE_BACKGROUND:
1544 case TYPE_KEYGUARD:
Jim Miller5ecd8112013-01-09 18:50:26 -08001545 case TYPE_KEYGUARD_SCRIM:
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001546 return false;
1547 default:
1548 return true;
1549 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07001550 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001551
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001552 /** {@inheritDoc} */
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001553 @Override
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07001554 public View addStartingWindow(IBinder appToken, String packageName, int theme,
1555 CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes,
Adam Powell04fe6eb2013-05-31 14:39:48 -07001556 int icon, int logo, int windowFlags) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001557 if (!SHOW_STARTING_ANIMATIONS) {
1558 return null;
1559 }
1560 if (packageName == null) {
1561 return null;
1562 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001563
Mathias Jeppssond1443e92012-08-24 15:25:32 +02001564 WindowManager wm = null;
1565 View view = null;
1566
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001567 try {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001568 Context context = mContext;
Craig Mautner6fbda632012-07-03 09:26:39 -07001569 if (DEBUG_STARTING_WINDOW) Slog.d(TAG, "addStartingWindow " + packageName
1570 + ": nonLocalizedLabel=" + nonLocalizedLabel + " theme="
1571 + Integer.toHexString(theme));
Dianne Hackborn247fe742011-01-08 17:25:57 -08001572 if (theme != context.getThemeResId() || labelRes != 0) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001573 try {
1574 context = context.createPackageContext(packageName, 0);
Dianne Hackborn247fe742011-01-08 17:25:57 -08001575 context.setTheme(theme);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001576 } catch (PackageManager.NameNotFoundException e) {
1577 // Ignore
1578 }
1579 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001580
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001581 Window win = PolicyManager.makeNewWindow(context);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001582 final TypedArray ta = win.getWindowStyle();
1583 if (ta.getBoolean(
1584 com.android.internal.R.styleable.Window_windowDisablePreview, false)
1585 || ta.getBoolean(
1586 com.android.internal.R.styleable.Window_windowShowWallpaper,false)) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001587 return null;
1588 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001589
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001590 Resources r = context.getResources();
1591 win.setTitle(r.getText(labelRes, nonLocalizedLabel));
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001592
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001593 win.setType(
1594 WindowManager.LayoutParams.TYPE_APPLICATION_STARTING);
1595 // Force the window flags: this is a fake window, so it is not really
1596 // touchable or focusable by the user. We also add in the ALT_FOCUSABLE_IM
1597 // flag because we do know that the next window will take input
1598 // focus, so we want to get the IME window up on top of us right away.
1599 win.setFlags(
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08001600 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001601 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
1602 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
1603 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08001604 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001605 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
1606 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
1607 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001608
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07001609 if (!compatInfo.supportsScreen()) {
1610 win.addFlags(WindowManager.LayoutParams.FLAG_COMPATIBLE_WINDOW);
1611 }
1612
Adam Powell04fe6eb2013-05-31 14:39:48 -07001613 win.setDefaultIcon(icon);
1614 win.setDefaultLogo(logo);
1615
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001616 win.setLayout(WindowManager.LayoutParams.MATCH_PARENT,
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07001617 WindowManager.LayoutParams.MATCH_PARENT);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001618
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001619 final WindowManager.LayoutParams params = win.getAttributes();
1620 params.token = appToken;
1621 params.packageName = packageName;
1622 params.windowAnimations = win.getWindowStyle().getResourceId(
1623 com.android.internal.R.styleable.Window_windowAnimationStyle, 0);
Dianne Hackborn5d927c22011-09-02 12:22:18 -07001624 params.privateFlags |=
1625 WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED;
Craig Mautner88400d32012-09-30 12:35:45 -07001626 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001627 params.setTitle("Starting " + packageName);
1628
Mathias Jeppssond1443e92012-08-24 15:25:32 +02001629 wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
1630 view = win.getDecorView();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001631
1632 if (win.isFloating()) {
1633 // Whoops, there is no way to display an animation/preview
1634 // of such a thing! After all that work... let's skip it.
1635 // (Note that we must do this here because it is in
1636 // getDecorView() where the theme is evaluated... maybe
1637 // we should peek the floating attribute from the theme
1638 // earlier.)
1639 return null;
1640 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001641
Craig Mautner6fbda632012-07-03 09:26:39 -07001642 if (DEBUG_STARTING_WINDOW) Slog.d(
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001643 TAG, "Adding starting window for " + packageName
1644 + " / " + appToken + ": "
1645 + (view.getParent() != null ? view : null));
1646
1647 wm.addView(view, params);
1648
1649 // Only return the view if it was successfully added to the
1650 // window manager... which we can tell by it having a parent.
1651 return view.getParent() != null ? view : null;
Jeff Brown98365d72012-08-19 20:30:52 -07001652 } catch (WindowManager.BadTokenException e) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001653 // ignore
1654 Log.w(TAG, appToken + " already running, starting window not displayed");
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001655 } catch (RuntimeException e) {
1656 // don't crash if something else bad happens, for example a
1657 // failure loading resources because we are loading from an app
1658 // on external storage that has been unmounted.
1659 Log.w(TAG, appToken + " failed creating starting window", e);
Mathias Jeppssond1443e92012-08-24 15:25:32 +02001660 } finally {
1661 if (view != null && view.getParent() == null) {
1662 Log.w(TAG, "view not successfully added to wm, removing view");
1663 wm.removeViewImmediate(view);
1664 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001665 }
1666
1667 return null;
1668 }
1669
1670 /** {@inheritDoc} */
1671 public void removeStartingWindow(IBinder appToken, View window) {
Craig Mautner6fbda632012-07-03 09:26:39 -07001672 if (DEBUG_STARTING_WINDOW) {
1673 RuntimeException e = new RuntimeException("here");
1674 e.fillInStackTrace();
1675 Log.v(TAG, "Removing starting window for " + appToken + ": " + window, e);
1676 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001677
1678 if (window != null) {
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001679 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001680 wm.removeView(window);
1681 }
1682 }
1683
1684 /**
1685 * Preflight adding a window to the system.
1686 *
1687 * Currently enforces that three window types are singletons:
1688 * <ul>
1689 * <li>STATUS_BAR_TYPE</li>
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001690 * <li>KEYGUARD_TYPE</li>
1691 * </ul>
1692 *
1693 * @param win The window to be added
1694 * @param attrs Information about the window to be added
1695 *
Jeff Brown98365d72012-08-19 20:30:52 -07001696 * @return If ok, WindowManagerImpl.ADD_OKAY. If too many singletons,
1697 * WindowManagerImpl.ADD_MULTIPLE_SINGLETON
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001698 */
1699 public int prepareAddWindowLw(WindowState win, WindowManager.LayoutParams attrs) {
1700 switch (attrs.type) {
1701 case TYPE_STATUS_BAR:
Joe Onorato8bc6c512010-06-04 16:21:12 -04001702 mContext.enforceCallingOrSelfPermission(
1703 android.Manifest.permission.STATUS_BAR_SERVICE,
1704 "PhoneWindowManager");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001705 if (mStatusBar != null) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001706 if (mStatusBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07001707 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001708 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001709 }
1710 mStatusBar = win;
1711 break;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04001712 case TYPE_NAVIGATION_BAR:
1713 mContext.enforceCallingOrSelfPermission(
1714 android.Manifest.permission.STATUS_BAR_SERVICE,
1715 "PhoneWindowManager");
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001716 if (mNavigationBar != null) {
1717 if (mNavigationBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07001718 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001719 }
1720 }
Daniel Sandler8956dbb2011-04-22 07:55:02 -04001721 mNavigationBar = win;
Craig Mautnereda67292013-04-28 13:50:14 -07001722 if (DEBUG_LAYOUT) Slog.i(TAG, "NAVIGATION BAR: " + mNavigationBar);
Daniel Sandler8956dbb2011-04-22 07:55:02 -04001723 break;
Jim Millere898ac52012-04-06 17:10:57 -07001724 case TYPE_NAVIGATION_BAR_PANEL:
1725 mContext.enforceCallingOrSelfPermission(
1726 android.Manifest.permission.STATUS_BAR_SERVICE,
1727 "PhoneWindowManager");
1728 break;
Dianne Hackborn08743722009-12-21 12:16:51 -08001729 case TYPE_STATUS_BAR_PANEL:
Joe Onorato8bc6c512010-06-04 16:21:12 -04001730 mContext.enforceCallingOrSelfPermission(
1731 android.Manifest.permission.STATUS_BAR_SERVICE,
1732 "PhoneWindowManager");
Dianne Hackborn08743722009-12-21 12:16:51 -08001733 break;
Joe Onorato29fc2c92010-11-24 10:26:50 -08001734 case TYPE_STATUS_BAR_SUB_PANEL:
1735 mContext.enforceCallingOrSelfPermission(
1736 android.Manifest.permission.STATUS_BAR_SERVICE,
1737 "PhoneWindowManager");
Joe Onorato29fc2c92010-11-24 10:26:50 -08001738 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001739 case TYPE_KEYGUARD:
1740 if (mKeyguard != null) {
Jeff Brown98365d72012-08-19 20:30:52 -07001741 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001742 }
1743 mKeyguard = win;
1744 break;
Jim Miller5ecd8112013-01-09 18:50:26 -08001745 case TYPE_KEYGUARD_SCRIM:
Jim Miller25190572013-02-28 17:36:24 -08001746 if (mKeyguardScrim != null) {
1747 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
1748 }
Jim Miller5ecd8112013-01-09 18:50:26 -08001749 mKeyguardScrim = win;
1750 break;
1751
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001752 }
Jeff Brown98365d72012-08-19 20:30:52 -07001753 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001754 }
1755
1756 /** {@inheritDoc} */
1757 public void removeWindowLw(WindowState win) {
1758 if (mStatusBar == win) {
1759 mStatusBar = null;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04001760 } else if (mKeyguard == win) {
Jim Miller5ecd8112013-01-09 18:50:26 -08001761 Log.v(TAG, "Removing keyguard window (Did it crash?)");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001762 mKeyguard = null;
Jim Millerc0b676d2013-03-22 16:11:08 -07001763 mKeyguardDelegate.showScrim();
Jim Miller5ecd8112013-01-09 18:50:26 -08001764 } else if (mKeyguardScrim == win) {
1765 Log.v(TAG, "Removing keyguard scrim");
1766 mKeyguardScrim = null;
1767 } if (mNavigationBar == win) {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04001768 mNavigationBar = null;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001769 }
1770 }
1771
1772 static final boolean PRINT_ANIM = false;
1773
1774 /** {@inheritDoc} */
Craig Mautner4b71aa12012-12-27 17:20:01 -08001775 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001776 public int selectAnimationLw(WindowState win, int transit) {
1777 if (PRINT_ANIM) Log.i(TAG, "selectAnimation in " + win
1778 + ": transit=" + transit);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001779 if (win == mStatusBar) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08001780 if (transit == TRANSIT_EXIT
1781 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001782 return R.anim.dock_top_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001783 } else if (transit == TRANSIT_ENTER
1784 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001785 return R.anim.dock_top_enter;
1786 }
1787 } else if (win == mNavigationBar) {
1788 // This can be on either the bottom or the right.
1789 if (mNavigationBarOnBottom) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08001790 if (transit == TRANSIT_EXIT
1791 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001792 return R.anim.dock_bottom_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001793 } else if (transit == TRANSIT_ENTER
1794 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001795 return R.anim.dock_bottom_enter;
1796 }
1797 } else {
Craig Mautner4b71aa12012-12-27 17:20:01 -08001798 if (transit == TRANSIT_EXIT
1799 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001800 return R.anim.dock_right_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001801 } else if (transit == TRANSIT_ENTER
1802 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001803 return R.anim.dock_right_enter;
1804 }
1805 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08001806 }
1807
1808 if (transit == TRANSIT_PREVIEW_DONE) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001809 if (win.hasAppShownWindows()) {
1810 if (PRINT_ANIM) Log.i(TAG, "**** STARTING EXIT");
1811 return com.android.internal.R.anim.app_starting_exit;
1812 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07001813 } else if (win.getAttrs().type == TYPE_DREAM && mDreamingLockscreen
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001814 && transit == TRANSIT_ENTER) {
1815 // Special case: we are animating in a dream, while the keyguard
1816 // is shown. We don't want an animation on the dream, because
1817 // we need it shown immediately with the keyguard animating away
1818 // to reveal it.
1819 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001820 }
1821
1822 return 0;
1823 }
1824
Craig Mautner3c174372013-02-21 17:54:37 -08001825 @Override
1826 public void selectRotationAnimationLw(int anim[]) {
1827 if (PRINT_ANIM) Slog.i(TAG, "selectRotationAnimation mTopFullscreen="
1828 + mTopFullscreenOpaqueWindowState + " rotationAnimation="
1829 + (mTopFullscreenOpaqueWindowState == null ?
1830 "0" : mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation));
1831 if (mTopFullscreenOpaqueWindowState != null && mTopIsFullscreen) {
1832 switch (mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation) {
1833 case ROTATION_ANIMATION_CROSSFADE:
1834 anim[0] = R.anim.rotation_animation_xfade_exit;
1835 anim[1] = R.anim.rotation_animation_enter;
1836 break;
1837 case ROTATION_ANIMATION_JUMPCUT:
1838 anim[0] = R.anim.rotation_animation_jump_exit;
1839 anim[1] = R.anim.rotation_animation_enter;
1840 break;
1841 case ROTATION_ANIMATION_ROTATE:
1842 default:
1843 anim[0] = anim[1] = 0;
1844 break;
1845 }
1846 } else {
1847 anim[0] = anim[1] = 0;
1848 }
1849 }
1850
1851 @Override
1852 public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId,
1853 boolean forceDefault) {
1854 switch (exitAnimId) {
1855 case R.anim.rotation_animation_xfade_exit:
1856 case R.anim.rotation_animation_jump_exit:
1857 // These are the only cases that matter.
1858 if (forceDefault) {
1859 return false;
1860 }
1861 int anim[] = new int[2];
1862 selectRotationAnimationLw(anim);
1863 return (exitAnimId == anim[0] && enterAnimId == anim[1]);
1864 default:
1865 return true;
1866 }
1867 }
1868
1869 @Override
Dianne Hackborn0c2acff2012-04-12 15:17:07 -07001870 public Animation createForceHideEnterAnimation(boolean onWallpaper) {
1871 return AnimationUtils.loadAnimation(mContext, onWallpaper
1872 ? com.android.internal.R.anim.lock_screen_wallpaper_behind_enter
1873 : com.android.internal.R.anim.lock_screen_behind_enter);
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07001874 }
John Spurlockc8b46ca2013-04-08 12:59:26 -04001875
1876 private static void awakenDreams() {
1877 IDreamManager dreamManager = getDreamManager();
1878 if (dreamManager != null) {
1879 try {
1880 dreamManager.awaken();
1881 } catch (RemoteException e) {
1882 // fine, stay asleep then
1883 }
1884 }
1885 }
1886
1887 static IDreamManager getDreamManager() {
1888 return IDreamManager.Stub.asInterface(
1889 ServiceManager.checkService(DreamService.DREAM_SERVICE));
1890 }
1891
Jeff Brown4d396052010-10-29 21:50:21 -07001892 static ITelephony getTelephonyService() {
Mike Lockwoodf5f4ec92011-11-08 14:05:31 -08001893 return ITelephony.Stub.asInterface(
Jeff Brown4d396052010-10-29 21:50:21 -07001894 ServiceManager.checkService(Context.TELEPHONY_SERVICE));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001895 }
1896
Jeff Brown4d396052010-10-29 21:50:21 -07001897 static IAudioService getAudioService() {
1898 IAudioService audioService = IAudioService.Stub.asInterface(
1899 ServiceManager.checkService(Context.AUDIO_SERVICE));
1900 if (audioService == null) {
1901 Log.w(TAG, "Unable to find IAudioService interface.");
1902 }
1903 return audioService;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001904 }
1905
1906 boolean keyguardOn() {
1907 return keyguardIsShowingTq() || inKeyguardRestrictedKeyInputMode();
1908 }
1909
1910 private static final int[] WINDOW_TYPES_WHERE_HOME_DOESNT_WORK = {
1911 WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
1912 WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
1913 };
1914
1915 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001916 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001917 public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001918 final boolean keyguardOn = keyguardOn();
Jeff Brown1f245102010-11-18 20:53:46 -08001919 final int keyCode = event.getKeyCode();
1920 final int repeatCount = event.getRepeatCount();
1921 final int metaState = event.getMetaState();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001922 final int flags = event.getFlags();
Jeff Brown1f245102010-11-18 20:53:46 -08001923 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
1924 final boolean canceled = event.isCanceled();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001925
Jeff Brown40013652012-05-16 21:22:36 -07001926 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001927 Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount="
Jeff Brownfd23e3e2012-05-09 13:34:28 -07001928 + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed
1929 + " canceled=" + canceled);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001930 }
1931
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001932 // If we think we might have a volume down & power key chord on the way
1933 // but we're not sure, then tell the dispatcher to wait a little while and
1934 // try again later before dispatching.
Christopher Tatee90585f2012-03-05 18:56:25 -08001935 if (mScreenshotChordEnabled && (flags & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001936 if (mVolumeDownKeyTriggered && !mPowerKeyTriggered) {
1937 final long now = SystemClock.uptimeMillis();
1938 final long timeoutTime = mVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS;
1939 if (now < timeoutTime) {
1940 return timeoutTime - now;
1941 }
1942 }
1943 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
1944 && mVolumeDownKeyConsumedByScreenshotChord) {
1945 if (!down) {
1946 mVolumeDownKeyConsumedByScreenshotChord = false;
1947 }
1948 return -1;
1949 }
1950 }
1951
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001952 // First we always handle the home key here, so applications
1953 // can never break it, although if keyguard is on, we do let
1954 // it handle it, because that gives us the correct 5 second
1955 // timeout.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001956 if (keyCode == KeyEvent.KEYCODE_HOME) {
Michael Jurka7f2668c2012-03-27 07:49:52 -07001957
Jeff Brown49ed71d2010-12-06 17:13:33 -08001958 // If we have released the home key, and didn't do anything else
1959 // while it was pressed, then it is time to go home!
Michael Jurka7f2668c2012-03-27 07:49:52 -07001960 if (!down) {
Jeff Browncaca8812013-05-09 13:34:33 -07001961 cancelPreloadRecentApps();
1962
Jeff Brown49ed71d2010-12-06 17:13:33 -08001963 mHomePressed = false;
Jeff Browncaca8812013-05-09 13:34:33 -07001964 if (mHomeConsumed) {
1965 mHomeConsumed = false;
Michael Jurka7f2668c2012-03-27 07:49:52 -07001966 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08001967 }
Jeff Browncaca8812013-05-09 13:34:33 -07001968
1969 if (canceled) {
1970 Log.i(TAG, "Ignoring HOME; event canceled.");
1971 return -1;
1972 }
1973
1974 // If an incoming call is ringing, HOME is totally disabled.
1975 // (The user is already on the InCallScreen at this point,
1976 // and his ONLY options are to answer or reject the call.)
1977 try {
1978 ITelephony telephonyService = getTelephonyService();
1979 if (telephonyService != null && telephonyService.isRinging()) {
1980 Log.i(TAG, "Ignoring HOME; there's a ringing incoming call.");
1981 return -1;
1982 }
1983 } catch (RemoteException ex) {
1984 Log.w(TAG, "RemoteException from getPhoneInterface()", ex);
1985 }
1986
1987 // Delay handling home if a double-tap is possible.
1988 if (mDoubleTapOnHomeBehavior != DOUBLE_TAP_HOME_NOTHING) {
1989 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); // just in case
1990 mHomeDoubleTapPending = true;
1991 mHandler.postDelayed(mHomeDoubleTapTimeoutRunnable,
1992 ViewConfiguration.getDoubleTapTimeout());
1993 return -1;
1994 }
1995
1996 // Go home!
1997 launchHomeFromHotKey();
1998 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08001999 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002000
2001 // If a system window has focus, then it doesn't make sense
2002 // right now to interact with applications.
2003 WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null;
2004 if (attrs != null) {
2005 final int type = attrs.type;
2006 if (type == WindowManager.LayoutParams.TYPE_KEYGUARD
Jim Miller5ecd8112013-01-09 18:50:26 -08002007 || type == WindowManager.LayoutParams.TYPE_KEYGUARD_SCRIM
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002008 || type == WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG) {
2009 // the "app" is keyguard, so give it the key
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002010 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002011 }
2012 final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length;
2013 for (int i=0; i<typeCount; i++) {
2014 if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) {
2015 // don't do anything, but also don't pass it to the app
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002016 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002017 }
2018 }
2019 }
Jeff Browncaca8812013-05-09 13:34:33 -07002020
2021 // Remember that home is pressed and handle special actions.
2022 if (repeatCount == 0) {
2023 mHomePressed = true;
2024 if (mHomeDoubleTapPending) {
2025 mHomeDoubleTapPending = false;
2026 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable);
2027 handleDoubleTapOnHome();
2028 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI
2029 || mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
2030 preloadRecentApps();
Michael Jurka7f2668c2012-03-27 07:49:52 -07002031 }
Jeff Browncaca8812013-05-09 13:34:33 -07002032 } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) {
2033 if (!keyguardOn) {
2034 handleLongPressOnHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002035 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002036 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002037 return -1;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002038 } else if (keyCode == KeyEvent.KEYCODE_MENU) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002039 // Hijack modified menu keys for debugging features
2040 final int chordBug = KeyEvent.META_SHIFT_ON;
2041
2042 if (down && repeatCount == 0) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002043 if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002044 Intent intent = new Intent(Intent.ACTION_BUG_REPORT);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002045 mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT,
2046 null, null, null, 0, null, null);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002047 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002048 } else if (SHOW_PROCESSES_ON_ALT_MENU &&
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002049 (metaState & KeyEvent.META_ALT_ON) == KeyEvent.META_ALT_ON) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002050 Intent service = new Intent();
2051 service.setClassName(mContext, "com.android.server.LoadAverageService");
2052 ContentResolver res = mContext.getContentResolver();
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002053 boolean shown = Settings.Global.getInt(
2054 res, Settings.Global.SHOW_PROCESSES, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002055 if (!shown) {
2056 mContext.startService(service);
2057 } else {
2058 mContext.stopService(service);
2059 }
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002060 Settings.Global.putInt(
2061 res, Settings.Global.SHOW_PROCESSES, shown ? 0 : 1);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002062 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002063 }
2064 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002065 } else if (keyCode == KeyEvent.KEYCODE_SEARCH) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002066 if (down) {
2067 if (repeatCount == 0) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002068 mSearchKeyShortcutPending = true;
2069 mConsumeSearchKeyUp = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002070 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002071 } else {
2072 mSearchKeyShortcutPending = false;
2073 if (mConsumeSearchKeyUp) {
2074 mConsumeSearchKeyUp = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002075 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002076 }
2077 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002078 return 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002079 } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) {
Michael Wrightc9ebea72013-01-16 19:25:02 -08002080 if (!keyguardOn) {
Jeff Browncaca8812013-05-09 13:34:33 -07002081 if (down && repeatCount == 0) {
2082 preloadRecentApps();
2083 } else if (!down) {
2084 toggleRecentApps();
Michael Wrightc9ebea72013-01-16 19:25:02 -08002085 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002086 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002087 return -1;
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002088 } else if (keyCode == KeyEvent.KEYCODE_ASSIST) {
2089 if (down) {
2090 if (repeatCount == 0) {
2091 mAssistKeyLongPressed = false;
2092 } else if (repeatCount == 1) {
2093 mAssistKeyLongPressed = true;
2094 if (!keyguardOn) {
2095 launchAssistLongPressAction();
2096 }
2097 }
2098 } else {
2099 if (mAssistKeyLongPressed) {
2100 mAssistKeyLongPressed = false;
2101 } else {
2102 if (!keyguardOn) {
2103 launchAssistAction();
2104 }
2105 }
2106 }
2107 return -1;
Jeff Sharkey2991fa32012-12-05 18:06:43 -08002108 } else if (keyCode == KeyEvent.KEYCODE_SYSRQ) {
2109 if (down && repeatCount == 0) {
2110 mHandler.post(mScreenshotRunnable);
2111 }
2112 return -1;
Michael Wrightb854e242013-02-05 17:54:02 -08002113 } else if (keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP
2114 || keyCode == KeyEvent.KEYCODE_BRIGHTNESS_DOWN) {
2115 if (down) {
2116 int direction = keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP ? 1 : -1;
2117
2118 // Disable autobrightness if it's on
2119 int auto = Settings.System.getIntForUser(
2120 mContext.getContentResolver(),
2121 Settings.System.SCREEN_BRIGHTNESS_MODE,
2122 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2123 UserHandle.USER_CURRENT_OR_SELF);
2124 if (auto != 0) {
2125 Settings.System.putIntForUser(mContext.getContentResolver(),
2126 Settings.System.SCREEN_BRIGHTNESS_MODE,
2127 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2128 UserHandle.USER_CURRENT_OR_SELF);
2129 }
2130
2131 int min = mPowerManager.getMinimumScreenBrightnessSetting();
2132 int max = mPowerManager.getMaximumScreenBrightnessSetting();
2133 int step = (max - min + BRIGHTNESS_STEPS - 1) / BRIGHTNESS_STEPS * direction;
2134 int brightness = Settings.System.getIntForUser(mContext.getContentResolver(),
2135 Settings.System.SCREEN_BRIGHTNESS,
2136 mPowerManager.getDefaultScreenBrightnessSetting(),
2137 UserHandle.USER_CURRENT_OR_SELF);
2138 brightness += step;
2139 // Make sure we don't go beyond the limits.
2140 brightness = Math.min(max, brightness);
2141 brightness = Math.max(min, brightness);
2142
2143 Settings.System.putIntForUser(mContext.getContentResolver(),
2144 Settings.System.SCREEN_BRIGHTNESS, brightness,
2145 UserHandle.USER_CURRENT_OR_SELF);
2146 Intent intent = new Intent(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG);
2147 mContext.sendBroadcastAsUser(intent, UserHandle.CURRENT_OR_SELF);
2148 }
2149 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002150 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002151
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002152 // Shortcuts are invoked through Search+key, so intercept those here
Jeff Browncaab4d02010-12-09 22:13:41 -08002153 // Any printing key that is chorded with Search should be consumed
2154 // even if no shortcut was invoked. This prevents text from being
2155 // inadvertently inserted when using a keyboard that has built-in macro
2156 // shortcut keys (that emit Search+x) and some of them are not registered.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002157 if (mSearchKeyShortcutPending) {
Jeff Browncaab4d02010-12-09 22:13:41 -08002158 final KeyCharacterMap kcm = event.getKeyCharacterMap();
2159 if (kcm.isPrintingKey(keyCode)) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002160 mConsumeSearchKeyUp = true;
2161 mSearchKeyShortcutPending = false;
Jeff Browncaab4d02010-12-09 22:13:41 -08002162 if (down && repeatCount == 0 && !keyguardOn) {
2163 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState);
2164 if (shortcutIntent != null) {
2165 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002166 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002167 mContext.startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002168 } catch (ActivityNotFoundException ex) {
2169 Slog.w(TAG, "Dropping shortcut key combination because "
2170 + "the activity to which it is registered was not found: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002171 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode), ex);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002172 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002173 } else {
2174 Slog.i(TAG, "Dropping unregistered shortcut key combination: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002175 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002176 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002177 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002178 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002179 }
2180 }
2181
Jeff Brown68b909d2011-12-07 16:36:01 -08002182 // Invoke shortcuts using Meta.
Jeff Brown602ab322012-05-16 13:33:47 -07002183 if (down && repeatCount == 0 && !keyguardOn
Jeff Brown68b909d2011-12-07 16:36:01 -08002184 && (metaState & KeyEvent.META_META_ON) != 0) {
2185 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brown602ab322012-05-16 13:33:47 -07002186 if (kcm.isPrintingKey(keyCode)) {
2187 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode,
2188 metaState & ~(KeyEvent.META_META_ON
2189 | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON));
2190 if (shortcutIntent != null) {
2191 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2192 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002193 mContext.startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brown602ab322012-05-16 13:33:47 -07002194 } catch (ActivityNotFoundException ex) {
2195 Slog.w(TAG, "Dropping shortcut key combination because "
2196 + "the activity to which it is registered was not found: "
2197 + "META+" + KeyEvent.keyCodeToString(keyCode), ex);
2198 }
2199 return -1;
Jeff Brown68b909d2011-12-07 16:36:01 -08002200 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002201 }
2202 }
2203
Jeff Brown6651a632011-11-28 12:59:11 -08002204 // Handle application launch keys.
Jeff Brown602ab322012-05-16 13:33:47 -07002205 if (down && repeatCount == 0 && !keyguardOn) {
Jeff Brown6651a632011-11-28 12:59:11 -08002206 String category = sApplicationLaunchKeyCategories.get(keyCode);
2207 if (category != null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -08002208 Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category);
Jeff Brown6651a632011-11-28 12:59:11 -08002209 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2210 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002211 mContext.startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brown6651a632011-11-28 12:59:11 -08002212 } catch (ActivityNotFoundException ex) {
2213 Slog.w(TAG, "Dropping application launch key because "
2214 + "the activity to which it is registered was not found: "
2215 + "keyCode=" + keyCode + ", category=" + category, ex);
2216 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002217 return -1;
Jeff Brown6651a632011-11-28 12:59:11 -08002218 }
2219 }
2220
Jeff Brown68b909d2011-12-07 16:36:01 -08002221 // Display task switcher for ALT-TAB or Meta-TAB.
2222 if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_TAB) {
Jeff Brown602ab322012-05-16 13:33:47 -07002223 if (mRecentAppsDialogHeldModifiers == 0 && !keyguardOn) {
Jeff Brown68b909d2011-12-07 16:36:01 -08002224 final int shiftlessModifiers = event.getModifiers() & ~KeyEvent.META_SHIFT_MASK;
2225 if (KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_ALT_ON)
2226 || KeyEvent.metaStateHasModifiers(
2227 shiftlessModifiers, KeyEvent.META_META_ON)) {
2228 mRecentAppsDialogHeldModifiers = shiftlessModifiers;
2229 showOrHideRecentAppsDialog(RECENT_APPS_BEHAVIOR_EXIT_TOUCH_MODE_AND_SHOW);
2230 return -1;
2231 }
2232 }
2233 } else if (!down && mRecentAppsDialogHeldModifiers != 0
2234 && (metaState & mRecentAppsDialogHeldModifiers) == 0) {
2235 mRecentAppsDialogHeldModifiers = 0;
Jeff Brown602ab322012-05-16 13:33:47 -07002236 showOrHideRecentAppsDialog(keyguardOn ? RECENT_APPS_BEHAVIOR_DISMISS :
2237 RECENT_APPS_BEHAVIOR_DISMISS_AND_SWITCH);
Jeff Brown68b909d2011-12-07 16:36:01 -08002238 }
2239
Jeff Browncf39bdf2012-05-18 14:41:19 -07002240 // Handle keyboard language switching.
2241 if (down && repeatCount == 0
2242 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2243 || (keyCode == KeyEvent.KEYCODE_SPACE
2244 && (metaState & KeyEvent.META_CTRL_MASK) != 0))) {
2245 int direction = (metaState & KeyEvent.META_SHIFT_MASK) != 0 ? -1 : 1;
2246 mWindowManagerFuncs.switchKeyboardLayout(event.getDeviceId(), direction);
2247 return -1;
2248 }
2249 if (mLanguageSwitchKeyPressed && !down
2250 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2251 || keyCode == KeyEvent.KEYCODE_SPACE)) {
2252 mLanguageSwitchKeyPressed = false;
2253 return -1;
2254 }
2255
Justin Kohd378ad72013-04-01 12:18:26 -07002256 if (mGlobalKeyManager.handleGlobalKey(mContext, keyCode, event)) {
2257 return -1;
2258 }
2259
Jeff Brown68b909d2011-12-07 16:36:01 -08002260 // Let the application handle the key.
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002261 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002262 }
2263
Jeff Brown3915bb82010-11-05 15:02:16 -07002264 /** {@inheritDoc} */
2265 @Override
Jeff Brown49ed71d2010-12-06 17:13:33 -08002266 public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown54875002011-04-06 15:33:01 -07002267 // Note: This method is only called if the initial down was unhandled.
Jeff Brown40013652012-05-16 21:22:36 -07002268 if (DEBUG_INPUT) {
Jeff Brown1f245102010-11-18 20:53:46 -08002269 Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction()
2270 + ", flags=" + event.getFlags()
2271 + ", keyCode=" + event.getKeyCode()
2272 + ", scanCode=" + event.getScanCode()
2273 + ", metaState=" + event.getMetaState()
2274 + ", repeatCount=" + event.getRepeatCount()
2275 + ", policyFlags=" + policyFlags);
Jeff Brown3915bb82010-11-05 15:02:16 -07002276 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002277
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002278 KeyEvent fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002279 if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
2280 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002281 final int keyCode = event.getKeyCode();
2282 final int metaState = event.getMetaState();
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002283 final boolean initialDown = event.getAction() == KeyEvent.ACTION_DOWN
2284 && event.getRepeatCount() == 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002285
Jeff Brown54875002011-04-06 15:33:01 -07002286 // Check for fallback actions specified by the key character map.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002287 final FallbackAction fallbackAction;
2288 if (initialDown) {
2289 fallbackAction = kcm.getFallbackAction(keyCode, metaState);
2290 } else {
2291 fallbackAction = mFallbackActions.get(keyCode);
2292 }
2293
2294 if (fallbackAction != null) {
Jeff Brown40013652012-05-16 21:22:36 -07002295 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002296 Slog.d(TAG, "Fallback: keyCode=" + fallbackAction.keyCode
2297 + " metaState=" + Integer.toHexString(fallbackAction.metaState));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002298 }
2299
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002300 final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK;
2301 fallbackEvent = KeyEvent.obtain(
Jeff Brown49ed71d2010-12-06 17:13:33 -08002302 event.getDownTime(), event.getEventTime(),
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002303 event.getAction(), fallbackAction.keyCode,
2304 event.getRepeatCount(), fallbackAction.metaState,
Jeff Brown49ed71d2010-12-06 17:13:33 -08002305 event.getDeviceId(), event.getScanCode(),
2306 flags, event.getSource(), null);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002307
2308 if (!interceptFallback(win, fallbackEvent, policyFlags)) {
2309 fallbackEvent.recycle();
2310 fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002311 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002312
2313 if (initialDown) {
2314 mFallbackActions.put(keyCode, fallbackAction);
2315 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2316 mFallbackActions.remove(keyCode);
2317 fallbackAction.recycle();
2318 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002319 }
2320 }
2321
Jeff Brown40013652012-05-16 21:22:36 -07002322 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002323 if (fallbackEvent == null) {
2324 Slog.d(TAG, "No fallback.");
2325 } else {
2326 Slog.d(TAG, "Performing fallback: " + fallbackEvent);
2327 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002328 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002329 return fallbackEvent;
Jeff Brown3915bb82010-11-05 15:02:16 -07002330 }
2331
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002332 private boolean interceptFallback(WindowState win, KeyEvent fallbackEvent, int policyFlags) {
2333 int actions = interceptKeyBeforeQueueing(fallbackEvent, policyFlags, true);
2334 if ((actions & ACTION_PASS_TO_USER) != 0) {
2335 long delayMillis = interceptKeyBeforeDispatching(
2336 win, fallbackEvent, policyFlags);
2337 if (delayMillis == 0) {
2338 return true;
2339 }
2340 }
2341 return false;
Jeff Brown6f2fba42011-02-19 01:08:02 -08002342 }
2343
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002344 private void launchAssistLongPressAction() {
2345 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
2346 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
2347
2348 // launch the search activity
2349 Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS);
2350 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2351 try {
Jim Miller45308b12012-06-18 19:23:39 -07002352 // TODO: This only stops the factory-installed search manager.
2353 // Need to formalize an API to handle others
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002354 SearchManager searchManager = getSearchManager();
2355 if (searchManager != null) {
2356 searchManager.stopSearch();
2357 }
Michael Wright43e27f72013-04-10 14:06:48 -07002358 mContext.startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002359 } catch (ActivityNotFoundException e) {
2360 Slog.w(TAG, "No activity to handle assist long press action.", e);
2361 }
2362 }
2363
2364 private void launchAssistAction() {
2365 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
Amith Yamasanic1d07a42012-08-14 09:32:02 -07002366 Intent intent = ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE))
Dianne Hackbornf9c5e0f2013-01-23 14:39:13 -08002367 .getAssistIntent(mContext, true, UserHandle.USER_CURRENT);
Jim Miller45308b12012-06-18 19:23:39 -07002368 if (intent != null) {
2369 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
2370 | Intent.FLAG_ACTIVITY_SINGLE_TOP
2371 | Intent.FLAG_ACTIVITY_CLEAR_TOP);
2372 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002373 mContext.startActivityAsUser(intent, UserHandle.CURRENT);
Jim Miller45308b12012-06-18 19:23:39 -07002374 } catch (ActivityNotFoundException e) {
2375 Slog.w(TAG, "No activity to handle assist action.", e);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002376 }
2377 }
2378 }
2379
2380 private SearchManager getSearchManager() {
2381 if (mSearchManager == null) {
2382 mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
2383 }
2384 return mSearchManager;
2385 }
2386
Jeff Browncaca8812013-05-09 13:34:33 -07002387 private void preloadRecentApps() {
2388 mPreloadedRecentApps = true;
2389 try {
2390 IStatusBarService statusbar = getStatusBarService();
2391 if (statusbar != null) {
2392 statusbar.preloadRecentApps();
2393 }
2394 } catch (RemoteException e) {
2395 Slog.e(TAG, "RemoteException when preloading recent apps", e);
2396 // re-acquire status bar service next time it is needed.
2397 mStatusBarService = null;
2398 }
2399 }
2400
2401 private void cancelPreloadRecentApps() {
2402 if (mPreloadedRecentApps) {
2403 mPreloadedRecentApps = false;
2404 try {
2405 IStatusBarService statusbar = getStatusBarService();
2406 if (statusbar != null) {
2407 statusbar.cancelPreloadRecentApps();
2408 }
2409 } catch (RemoteException e) {
2410 Slog.e(TAG, "RemoteException when showing recent apps", e);
2411 // re-acquire status bar service next time it is needed.
2412 mStatusBarService = null;
2413 }
2414 }
2415 }
2416
2417 private void toggleRecentApps() {
2418 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
2419 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_RECENT_APPS);
2420 try {
2421 IStatusBarService statusbar = getStatusBarService();
2422 if (statusbar != null) {
2423 statusbar.toggleRecentApps();
2424 }
2425 } catch (RemoteException e) {
2426 Slog.e(TAG, "RemoteException when showing recent apps", e);
2427 // re-acquire status bar service next time it is needed.
2428 mStatusBarService = null;
2429 }
2430 }
2431
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002432 /**
2433 * A home key -> launch home action was detected. Take the appropriate action
2434 * given the situation with the keyguard.
2435 */
2436 void launchHomeFromHotKey() {
Jim Miller5ecd8112013-01-09 18:50:26 -08002437 if (mKeyguardDelegate != null && mKeyguardDelegate.isShowingAndNotHidden()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002438 // don't launch home if keyguard showing
Jim Miller5ecd8112013-01-09 18:50:26 -08002439 } else if (!mHideLockScreen && mKeyguardDelegate.isInputRestricted()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002440 // when in keyguard restricted mode, must first verify unlock
2441 // before launching home
Jim Miller5ecd8112013-01-09 18:50:26 -08002442 mKeyguardDelegate.verifyUnlock(new OnKeyguardExitResult() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002443 public void onKeyguardExitResult(boolean success) {
2444 if (success) {
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07002445 try {
2446 ActivityManagerNative.getDefault().stopAppSwitches();
2447 } catch (RemoteException e) {
2448 }
Joe Onoratof275f0c2009-11-24 16:11:13 -05002449 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07002450 startDockOrHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002451 }
2452 }
2453 });
2454 } else {
2455 // no keyguard stuff to worry about, just launch home!
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07002456 try {
2457 ActivityManagerNative.getDefault().stopAppSwitches();
2458 } catch (RemoteException e) {
2459 }
Joe Onoratof275f0c2009-11-24 16:11:13 -05002460 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07002461 startDockOrHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002462 }
2463 }
2464
John Spurlock04db1762013-05-13 12:46:41 -04002465 private final Runnable mClearHideNavigationFlag = new Runnable() {
2466 @Override
2467 public void run() {
2468 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
2469 // Clear flags.
2470 mForceClearedSystemUiFlags &=
2471 ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
2472 }
2473 mWindowManagerFuncs.reevaluateStatusBarVisibility();
Dianne Hackborne26ab702011-10-16 13:21:33 -07002474 }
2475 };
2476
2477 /**
2478 * Input handler used while nav bar is hidden. Captures any touch on the screen,
2479 * to determine when the nav bar should be shown and prevent applications from
2480 * receiving those touches.
2481 */
Jeff Brown32cbc38552011-12-01 14:01:49 -08002482 final class HideNavInputEventReceiver extends InputEventReceiver {
2483 public HideNavInputEventReceiver(InputChannel inputChannel, Looper looper) {
2484 super(inputChannel, looper);
2485 }
2486
Dianne Hackborndf89e652011-10-06 22:35:11 -07002487 @Override
Jeff Brown32cbc38552011-12-01 14:01:49 -08002488 public void onInputEvent(InputEvent event) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07002489 boolean handled = false;
2490 try {
Jeff Brown4952dfd2011-11-30 19:23:22 -08002491 if (event instanceof MotionEvent
2492 && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
2493 final MotionEvent motionEvent = (MotionEvent)event;
2494 if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07002495 // When the user taps down, we re-show the nav bar.
2496 boolean changed = false;
John Spurlock04db1762013-05-13 12:46:41 -04002497 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002498 // Any user activity always causes us to show the
2499 // navigation controls, if they had been hidden.
2500 // We also clear the low profile and only content
2501 // flags so that tapping on the screen will atomically
2502 // restore all currently hidden screen decorations.
2503 int newVal = mResettingSystemUiFlags |
2504 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
2505 View.SYSTEM_UI_FLAG_LOW_PROFILE |
2506 View.SYSTEM_UI_FLAG_FULLSCREEN;
Dianne Hackborne26ab702011-10-16 13:21:33 -07002507 if (mResettingSystemUiFlags != newVal) {
2508 mResettingSystemUiFlags = newVal;
Dianne Hackborndf89e652011-10-06 22:35:11 -07002509 changed = true;
2510 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07002511 // We don't allow the system's nav bar to be hidden
2512 // again for 1 second, to prevent applications from
2513 // spamming us and keeping it from being shown.
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002514 newVal = mForceClearedSystemUiFlags |
2515 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
Dianne Hackborne26ab702011-10-16 13:21:33 -07002516 if (mForceClearedSystemUiFlags != newVal) {
2517 mForceClearedSystemUiFlags = newVal;
2518 changed = true;
John Spurlock04db1762013-05-13 12:46:41 -04002519 mHandler.postDelayed(mClearHideNavigationFlag, 1000);
Dianne Hackborne26ab702011-10-16 13:21:33 -07002520 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07002521 }
2522 if (changed) {
2523 mWindowManagerFuncs.reevaluateStatusBarVisibility();
2524 }
2525 }
2526 }
2527 } finally {
Jeff Brown32cbc38552011-12-01 14:01:49 -08002528 finishInputEvent(event, handled);
Dianne Hackborndf89e652011-10-06 22:35:11 -07002529 }
2530 }
Jeff Brown32cbc38552011-12-01 14:01:49 -08002531 }
2532 final InputEventReceiver.Factory mHideNavInputEventReceiverFactory =
2533 new InputEventReceiver.Factory() {
2534 @Override
2535 public InputEventReceiver createInputEventReceiver(
2536 InputChannel inputChannel, Looper looper) {
2537 return new HideNavInputEventReceiver(inputChannel, looper);
2538 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07002539 };
2540
2541 @Override
2542 public int adjustSystemUiVisibilityLw(int visibility) {
John Spurlock04db1762013-05-13 12:46:41 -04002543 if (mStatusBar != null && mStatusHideybar == HIDEYBAR_SHOWING &&
John Spurlockad3e6cb2013-04-30 08:47:43 -04002544 0 == (visibility & View.STATUS_BAR_OVERLAY)) {
2545 mStatusHideybar = HIDEYBAR_HIDING;
John Spurlock32beb2c2013-03-11 10:16:47 -04002546 mStatusBar.hideLw(true);
2547 }
John Spurlocke3b642e2013-05-09 15:51:32 -04002548 if (mNavigationBar != null && mNavigationHideybar == HIDEYBAR_SHOWING &&
John Spurlockad3e6cb2013-04-30 08:47:43 -04002549 0 == (visibility & View.NAVIGATION_BAR_OVERLAY)) {
2550 mNavigationHideybar = HIDEYBAR_HIDING;
2551 mNavigationBar.hideLw(true);
2552 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07002553 // Reset any bits in mForceClearingStatusBarVisibility that
2554 // are now clear.
Dianne Hackborne26ab702011-10-16 13:21:33 -07002555 mResettingSystemUiFlags &= visibility;
Dianne Hackborndf89e652011-10-06 22:35:11 -07002556 // Clear any bits in the new visibility that are currently being
2557 // force cleared, before reporting it.
Dianne Hackborne26ab702011-10-16 13:21:33 -07002558 return visibility & ~mResettingSystemUiFlags
2559 & ~mForceClearedSystemUiFlags;
Dianne Hackborndf89e652011-10-06 22:35:11 -07002560 }
2561
Craig Mautner69b08182012-09-05 13:07:13 -07002562 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002563 public void getContentInsetHintLw(WindowManager.LayoutParams attrs, Rect contentInset) {
2564 final int fl = attrs.flags;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002565 final int systemUiVisibility = (attrs.systemUiVisibility|attrs.subtreeSystemUiVisibility);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002566
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002567 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002568 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002569 int availRight, availBottom;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002570 if (mCanHideNavigationBar &&
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002571 (systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002572 availRight = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
2573 availBottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
2574 } else {
2575 availRight = mRestrictedScreenLeft + mRestrictedScreenWidth;
2576 availBottom = mRestrictedScreenTop + mRestrictedScreenHeight;
2577 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002578 if ((systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
2579 if ((fl & FLAG_FULLSCREEN) != 0) {
2580 contentInset.set(mStableFullscreenLeft, mStableFullscreenTop,
2581 availRight - mStableFullscreenRight,
2582 availBottom - mStableFullscreenBottom);
2583 } else {
2584 contentInset.set(mStableLeft, mStableTop,
2585 availRight - mStableRight, availBottom - mStableBottom);
2586 }
Dianne Hackbornc652de82013-02-15 16:32:56 -08002587 } else if ((fl & FLAG_FULLSCREEN) != 0 || (fl & FLAG_LAYOUT_IN_OVERSCAN) != 0) {
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002588 contentInset.setEmpty();
2589 } else if ((systemUiVisibility & (View.SYSTEM_UI_FLAG_FULLSCREEN
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002590 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)) == 0) {
2591 contentInset.set(mCurLeft, mCurTop,
2592 availRight - mCurRight, availBottom - mCurBottom);
2593 } else {
2594 contentInset.set(mCurLeft, mCurTop,
2595 availRight - mCurRight, availBottom - mCurBottom);
2596 }
2597 return;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002598 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002599 contentInset.setEmpty();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002600 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002601
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002602 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07002603 @Override
2604 public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight,
2605 int displayRotation) {
Dianne Hackbornc652de82013-02-15 16:32:56 -08002606 final int overscanLeft, overscanTop, overscanRight, overscanBottom;
2607 if (isDefaultDisplay) {
2608 switch (displayRotation) {
2609 case Surface.ROTATION_90:
2610 overscanLeft = mOverscanTop;
2611 overscanTop = mOverscanRight;
2612 overscanRight = mOverscanBottom;
2613 overscanBottom = mOverscanLeft;
2614 break;
2615 case Surface.ROTATION_180:
2616 overscanLeft = mOverscanRight;
2617 overscanTop = mOverscanBottom;
2618 overscanRight = mOverscanLeft;
2619 overscanBottom = mOverscanTop;
2620 break;
2621 case Surface.ROTATION_270:
2622 overscanLeft = mOverscanBottom;
2623 overscanTop = mOverscanLeft;
2624 overscanRight = mOverscanTop;
2625 overscanBottom = mOverscanRight;
2626 break;
2627 default:
2628 overscanLeft = mOverscanLeft;
2629 overscanTop = mOverscanTop;
2630 overscanRight = mOverscanRight;
2631 overscanBottom = mOverscanBottom;
2632 break;
2633 }
2634 } else {
2635 overscanLeft = 0;
2636 overscanTop = 0;
2637 overscanRight = 0;
2638 overscanBottom = 0;
2639 }
Dianne Hackborn313440842013-02-19 19:22:59 -08002640 mOverscanScreenLeft = mRestrictedOverscanScreenLeft = 0;
2641 mOverscanScreenTop = mRestrictedOverscanScreenTop = 0;
2642 mOverscanScreenWidth = mRestrictedOverscanScreenWidth = displayWidth;
2643 mOverscanScreenHeight = mRestrictedOverscanScreenHeight = displayHeight;
Dianne Hackbornc652de82013-02-15 16:32:56 -08002644 mSystemLeft = 0;
2645 mSystemTop = 0;
2646 mSystemRight = displayWidth;
2647 mSystemBottom = displayHeight;
2648 mUnrestrictedScreenLeft = overscanLeft;
2649 mUnrestrictedScreenTop = overscanTop;
2650 mUnrestrictedScreenWidth = displayWidth - overscanLeft - overscanRight;
2651 mUnrestrictedScreenHeight = displayHeight - overscanTop - overscanBottom;
2652 mRestrictedScreenLeft = mUnrestrictedScreenLeft;
2653 mRestrictedScreenTop = mUnrestrictedScreenTop;
John Spurlockad3e6cb2013-04-30 08:47:43 -04002654 mRestrictedScreenWidth = mSystemGestures.screenWidth = mUnrestrictedScreenWidth;
2655 mRestrictedScreenHeight = mSystemGestures.screenHeight = mUnrestrictedScreenHeight;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002656 mDockLeft = mContentLeft = mStableLeft = mStableFullscreenLeft
Dianne Hackbornc652de82013-02-15 16:32:56 -08002657 = mCurLeft = mUnrestrictedScreenLeft;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002658 mDockTop = mContentTop = mStableTop = mStableFullscreenTop
Dianne Hackbornc652de82013-02-15 16:32:56 -08002659 = mCurTop = mUnrestrictedScreenTop;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002660 mDockRight = mContentRight = mStableRight = mStableFullscreenRight
Dianne Hackbornc652de82013-02-15 16:32:56 -08002661 = mCurRight = displayWidth - overscanRight;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002662 mDockBottom = mContentBottom = mStableBottom = mStableFullscreenBottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08002663 = mCurBottom = displayHeight - overscanBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002664 mDockLayer = 0x10000000;
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002665 mStatusBarLayer = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002666
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002667 // start with the current dock rect, which will be (0,0,displayWidth,displayHeight)
2668 final Rect pf = mTmpParentFrame;
2669 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002670 final Rect of = mTmpOverscanFrame;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002671 final Rect vf = mTmpVisibleFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002672 pf.left = df.left = of.left = vf.left = mDockLeft;
2673 pf.top = df.top = of.top = vf.top = mDockTop;
2674 pf.right = df.right = of.right = vf.right = mDockRight;
2675 pf.bottom = df.bottom = of.bottom = vf.bottom = mDockBottom;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002676
Craig Mautner69b08182012-09-05 13:07:13 -07002677 if (isDefaultDisplay) {
2678 // For purposes of putting out fake window up to steal focus, we will
2679 // drive nav being hidden only by whether it is requested.
2680 boolean navVisible = (mLastSystemUiFlags&View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0;
John Spurlockad3e6cb2013-04-30 08:47:43 -04002681 boolean overlayAllowed = (mLastSystemUiFlags&View.SYSTEM_UI_FLAG_ALLOW_OVERLAY) != 0;
Dianne Hackborne26ab702011-10-16 13:21:33 -07002682
Craig Mautner69b08182012-09-05 13:07:13 -07002683 // When the navigation bar isn't visible, we put up a fake
2684 // input window to catch all touch events. This way we can
2685 // detect when the user presses anywhere to bring back the nav
2686 // bar and ensure the application doesn't see the event.
John Spurlockad3e6cb2013-04-30 08:47:43 -04002687 if (navVisible || overlayAllowed) {
Craig Mautner69b08182012-09-05 13:07:13 -07002688 if (mHideNavFakeWindow != null) {
2689 mHideNavFakeWindow.dismiss();
2690 mHideNavFakeWindow = null;
2691 }
2692 } else if (mHideNavFakeWindow == null) {
2693 mHideNavFakeWindow = mWindowManagerFuncs.addFakeWindow(
2694 mHandler.getLooper(), mHideNavInputEventReceiverFactory,
2695 "hidden nav", WindowManager.LayoutParams.TYPE_HIDDEN_NAV_CONSUMER,
2696 0, false, false, true);
Dianne Hackborne26ab702011-10-16 13:21:33 -07002697 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07002698
Craig Mautner69b08182012-09-05 13:07:13 -07002699 // For purposes of positioning and showing the nav bar, if we have
2700 // decided that it can't be hidden (because of the screen aspect ratio),
2701 // then take that into account.
2702 navVisible |= !mCanHideNavigationBar;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002703
John Spurlockad3e6cb2013-04-30 08:47:43 -04002704 boolean updateSysUiVisibility = false;
Craig Mautner69b08182012-09-05 13:07:13 -07002705 if (mNavigationBar != null) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04002706 boolean navBarHideyShowing = mNavigationHideybar == HIDEYBAR_SHOWING;
Craig Mautner69b08182012-09-05 13:07:13 -07002707 // Force the navigation bar to its appropriate place and
2708 // size. We need to do this directly, instead of relying on
2709 // it to bubble up from the nav bar, because this needs to
2710 // change atomically with screen rotations.
2711 mNavigationBarOnBottom = (!mNavigationBarCanMove || displayWidth < displayHeight);
2712 if (mNavigationBarOnBottom) {
2713 // It's a system nav bar or a portrait screen; nav bar goes on bottom.
Dianne Hackbornc652de82013-02-15 16:32:56 -08002714 int top = displayHeight - overscanBottom
2715 - mNavigationBarHeightForRotation[displayRotation];
2716 mTmpNavigationFrame.set(0, top, displayWidth, displayHeight - overscanBottom);
Craig Mautner69b08182012-09-05 13:07:13 -07002717 mStableBottom = mStableFullscreenBottom = mTmpNavigationFrame.top;
John Spurlockad3e6cb2013-04-30 08:47:43 -04002718 if (navBarHideyShowing) {
2719 mNavigationBar.showLw(true);
2720 } else if (navVisible) {
Craig Mautner69b08182012-09-05 13:07:13 -07002721 mNavigationBar.showLw(true);
2722 mDockBottom = mTmpNavigationFrame.top;
Dianne Hackborn313440842013-02-19 19:22:59 -08002723 mRestrictedScreenHeight = mDockBottom - mRestrictedScreenTop;
2724 mRestrictedOverscanScreenHeight = mDockBottom - mRestrictedOverscanScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07002725 } else {
2726 // We currently want to hide the navigation UI.
2727 mNavigationBar.hideLw(true);
2728 }
2729 if (navVisible && !mNavigationBar.isAnimatingLw()) {
2730 // If the nav bar is currently requested to be visible,
2731 // and not in the process of animating on or off, then
2732 // we can tell the app that it is covered by it.
2733 mSystemBottom = mTmpNavigationFrame.top;
2734 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002735 } else {
Craig Mautner69b08182012-09-05 13:07:13 -07002736 // Landscape screen; nav bar goes to the right.
Dianne Hackbornc652de82013-02-15 16:32:56 -08002737 int left = displayWidth - overscanRight
2738 - mNavigationBarWidthForRotation[displayRotation];
2739 mTmpNavigationFrame.set(left, 0, displayWidth - overscanRight, displayHeight);
Craig Mautner69b08182012-09-05 13:07:13 -07002740 mStableRight = mStableFullscreenRight = mTmpNavigationFrame.left;
John Spurlockad3e6cb2013-04-30 08:47:43 -04002741 if (navBarHideyShowing) {
2742 mNavigationBar.showLw(true);
2743 } else if (navVisible) {
Craig Mautner69b08182012-09-05 13:07:13 -07002744 mNavigationBar.showLw(true);
2745 mDockRight = mTmpNavigationFrame.left;
Dianne Hackborn313440842013-02-19 19:22:59 -08002746 mRestrictedScreenWidth = mDockRight - mRestrictedScreenLeft;
2747 mRestrictedOverscanScreenWidth = mDockRight - mRestrictedOverscanScreenLeft;
Craig Mautner69b08182012-09-05 13:07:13 -07002748 } else {
2749 // We currently want to hide the navigation UI.
2750 mNavigationBar.hideLw(true);
2751 }
2752 if (navVisible && !mNavigationBar.isAnimatingLw()) {
2753 // If the nav bar is currently requested to be visible,
2754 // and not in the process of animating on or off, then
2755 // we can tell the app that it is covered by it.
2756 mSystemRight = mTmpNavigationFrame.left;
2757 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002758 }
Craig Mautner69b08182012-09-05 13:07:13 -07002759 // Make sure the content and current rectangles are updated to
2760 // account for the restrictions from the navigation bar.
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002761 mContentTop = mCurTop = mDockTop;
2762 mContentBottom = mCurBottom = mDockBottom;
2763 mContentLeft = mCurLeft = mDockLeft;
2764 mContentRight = mCurRight = mDockRight;
Craig Mautner69b08182012-09-05 13:07:13 -07002765 mStatusBarLayer = mNavigationBar.getSurfaceLayer();
2766 // And compute the final frame.
2767 mNavigationBar.computeFrameLw(mTmpNavigationFrame, mTmpNavigationFrame,
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002768 mTmpNavigationFrame, mTmpNavigationFrame, mTmpNavigationFrame);
Craig Mautnereda67292013-04-28 13:50:14 -07002769 if (DEBUG_LAYOUT) Slog.i(TAG, "mNavigationBar frame: " + mTmpNavigationFrame);
John Spurlockad3e6cb2013-04-30 08:47:43 -04002770 if (mNavigationHideybar == HIDEYBAR_HIDING && !mNavigationBar.isVisibleLw()) {
2771 // Finished animating out, clean up and reset alpha
2772 mNavigationHideybar = HIDEYBAR_NONE;
2773 updateSysUiVisibility = true;
2774 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002775 }
Craig Mautnereda67292013-04-28 13:50:14 -07002776 if (DEBUG_LAYOUT) Slog.i(TAG, String.format("mDock rect: (%d,%d - %d,%d)",
Craig Mautner69b08182012-09-05 13:07:13 -07002777 mDockLeft, mDockTop, mDockRight, mDockBottom));
2778
2779 // decide where the status bar goes ahead of time
2780 if (mStatusBar != null) {
2781 // apply any navigation bar insets
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002782 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
2783 pf.top = df.top = of.top = mUnrestrictedScreenTop;
2784 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
2785 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight
2786 + mUnrestrictedScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07002787 vf.left = mStableLeft;
2788 vf.top = mStableTop;
2789 vf.right = mStableRight;
2790 vf.bottom = mStableBottom;
2791
2792 mStatusBarLayer = mStatusBar.getSurfaceLayer();
2793
2794 // Let the status bar determine its size.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002795 mStatusBar.computeFrameLw(pf, df, vf, vf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07002796
2797 // For layout, the status bar is always at the top with our fixed height.
2798 mStableTop = mUnrestrictedScreenTop + mStatusBarHeight;
2799
John Spurlock32beb2c2013-03-11 10:16:47 -04002800 boolean statusBarOverlay = (mLastSystemUiFlags & View.STATUS_BAR_OVERLAY) != 0;
2801
Craig Mautner69b08182012-09-05 13:07:13 -07002802 // If the status bar is hidden, we don't want to cause
2803 // windows behind it to scroll.
John Spurlock32beb2c2013-03-11 10:16:47 -04002804 if (mStatusBar.isVisibleLw() && !statusBarOverlay) {
Craig Mautner69b08182012-09-05 13:07:13 -07002805 // Status bar may go away, so the screen area it occupies
2806 // is available to apps but just covering them when the
2807 // status bar is visible.
2808 mDockTop = mUnrestrictedScreenTop + mStatusBarHeight;
2809
2810 mContentTop = mCurTop = mDockTop;
2811 mContentBottom = mCurBottom = mDockBottom;
2812 mContentLeft = mCurLeft = mDockLeft;
2813 mContentRight = mCurRight = mDockRight;
2814
Craig Mautnereda67292013-04-28 13:50:14 -07002815 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar: " +
Craig Mautner69b08182012-09-05 13:07:13 -07002816 String.format(
2817 "dock=[%d,%d][%d,%d] content=[%d,%d][%d,%d] cur=[%d,%d][%d,%d]",
2818 mDockLeft, mDockTop, mDockRight, mDockBottom,
2819 mContentLeft, mContentTop, mContentRight, mContentBottom,
2820 mCurLeft, mCurTop, mCurRight, mCurBottom));
2821 }
John Spurlock32beb2c2013-03-11 10:16:47 -04002822 if (mStatusBar.isVisibleLw() && !mStatusBar.isAnimatingLw() && !statusBarOverlay) {
Craig Mautner69b08182012-09-05 13:07:13 -07002823 // If the status bar is currently requested to be visible,
2824 // and not in the process of animating on or off, then
2825 // we can tell the app that it is covered by it.
2826 mSystemTop = mUnrestrictedScreenTop + mStatusBarHeight;
2827 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04002828
2829 if (mStatusHideybar == HIDEYBAR_HIDING && !mStatusBar.isVisibleLw()) {
2830 // Finished animating out, clean up and reset alpha
2831 mStatusHideybar = HIDEYBAR_NONE;
2832 updateSysUiVisibility = true;
John Spurlock32beb2c2013-03-11 10:16:47 -04002833 }
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002834 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04002835 if (updateSysUiVisibility) {
2836 updateSystemUiVisibilityLw();
2837 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002838 }
2839 }
2840
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07002841 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07002842 @Override
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07002843 public int getSystemDecorRectLw(Rect systemRect) {
2844 systemRect.left = mSystemLeft;
2845 systemRect.top = mSystemTop;
2846 systemRect.right = mSystemRight;
2847 systemRect.bottom = mSystemBottom;
2848 if (mStatusBar != null) return mStatusBar.getSurfaceLayer();
2849 if (mNavigationBar != null) return mNavigationBar.getSurfaceLayer();
2850 return 0;
2851 }
2852
Craig Mautner967212c2013-04-13 21:10:58 -07002853 @Override
2854 public void getContentRectLw(Rect r) {
2855 r.set(mContentLeft, mContentTop, mContentRight, mContentBottom);
2856 }
2857
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002858 void setAttachedWindowFrames(WindowState win, int fl, int adjust, WindowState attached,
2859 boolean insetDecors, Rect pf, Rect df, Rect of, Rect cf, Rect vf) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002860 if (win.getSurfaceLayer() > mDockLayer && attached.getSurfaceLayer() < mDockLayer) {
2861 // Here's a special case: if this attached window is a panel that is
2862 // above the dock window, and the window it is attached to is below
2863 // the dock window, then the frames we computed for the window it is
2864 // attached to can not be used because the dock is effectively part
2865 // of the underlying window and the attached window is floating on top
2866 // of the whole thing. So, we ignore the attached window and explicitly
2867 // compute the frames that would be appropriate without the dock.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002868 df.left = of.left = cf.left = vf.left = mDockLeft;
2869 df.top = of.top = cf.top = vf.top = mDockTop;
2870 df.right = of.right = cf.right = vf.right = mDockRight;
2871 df.bottom = of.bottom = cf.bottom = vf.bottom = mDockBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002872 } else {
2873 // The effective display frame of the attached window depends on
2874 // whether it is taking care of insetting its content. If not,
2875 // we need to use the parent's content frame so that the entire
2876 // window is positioned within that content. Otherwise we can use
2877 // the display frame and let the attached window take care of
2878 // positioning its content appropriately.
Dianne Hackborndea3ef72010-10-28 14:24:22 -07002879 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002880 cf.set(attached.getOverscanFrameLw());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002881 } else {
2882 // If the window is resizing, then we want to base the content
2883 // frame on our attached content frame to resize... however,
2884 // things can be tricky if the attached window is NOT in resize
2885 // mode, in which case its content frame will be larger.
2886 // Ungh. So to deal with that, make sure the content frame
2887 // we end up using is not covering the IM dock.
2888 cf.set(attached.getContentFrameLw());
2889 if (attached.getSurfaceLayer() < mDockLayer) {
2890 if (cf.left < mContentLeft) cf.left = mContentLeft;
2891 if (cf.top < mContentTop) cf.top = mContentTop;
2892 if (cf.right > mContentRight) cf.right = mContentRight;
2893 if (cf.bottom > mContentBottom) cf.bottom = mContentBottom;
2894 }
2895 }
2896 df.set(insetDecors ? attached.getDisplayFrameLw() : cf);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002897 of.set(insetDecors ? attached.getOverscanFrameLw() : cf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002898 vf.set(attached.getVisibleFrameLw());
2899 }
2900 // The LAYOUT_IN_SCREEN flag is used to determine whether the attached
2901 // window should be positioned relative to its parent or the entire
2902 // screen.
2903 pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0
2904 ? attached.getFrameLw() : df);
2905 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002906
2907 private void applyStableConstraints(int sysui, int fl, Rect r) {
2908 if ((sysui & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
2909 // If app is requesting a stable layout, don't let the
2910 // content insets go below the stable values.
2911 if ((fl & FLAG_FULLSCREEN) != 0) {
2912 if (r.left < mStableFullscreenLeft) r.left = mStableFullscreenLeft;
2913 if (r.top < mStableFullscreenTop) r.top = mStableFullscreenTop;
2914 if (r.right > mStableFullscreenRight) r.right = mStableFullscreenRight;
2915 if (r.bottom > mStableFullscreenBottom) r.bottom = mStableFullscreenBottom;
2916 } else {
2917 if (r.left < mStableLeft) r.left = mStableLeft;
2918 if (r.top < mStableTop) r.top = mStableTop;
2919 if (r.right > mStableRight) r.right = mStableRight;
2920 if (r.bottom > mStableBottom) r.bottom = mStableBottom;
2921 }
2922 }
2923 }
2924
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002925 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07002926 @Override
Dianne Hackborn0ecadf72009-03-31 18:00:37 -07002927 public void layoutWindowLw(WindowState win, WindowManager.LayoutParams attrs,
2928 WindowState attached) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002929 // we've already done the status bar
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002930 if (win == mStatusBar || win == mNavigationBar) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002931 return;
2932 }
Craig Mautner69b08182012-09-05 13:07:13 -07002933 final boolean isDefaultDisplay = win.isDefaultDisplay();
2934 final boolean needsToOffsetInputMethodTarget = isDefaultDisplay &&
satok1bc0a492012-04-25 22:47:12 +09002935 (win == mLastInputMethodTargetWindow && mLastInputMethodWindow != null);
2936 if (needsToOffsetInputMethodTarget) {
Craig Mautnereda67292013-04-28 13:50:14 -07002937 if (DEBUG_LAYOUT) Slog.i(TAG, "Offset ime target window by the last ime window state");
satok1bc0a492012-04-25 22:47:12 +09002938 offsetInputMethodWindowLw(mLastInputMethodWindow);
2939 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002940
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002941 final int fl = attrs.flags;
2942 final int sim = attrs.softInputMode;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002943 final int sysUiFl = win.getSystemUiVisibility();
2944
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002945 final Rect pf = mTmpParentFrame;
2946 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002947 final Rect of = mTmpOverscanFrame;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002948 final Rect cf = mTmpContentFrame;
2949 final Rect vf = mTmpVisibleFrame;
Craig Mautner69b08182012-09-05 13:07:13 -07002950
2951 final boolean hasNavBar = (isDefaultDisplay && mHasNavigationBar
Daniel Sandler36412a72011-08-04 09:35:13 -04002952 && mNavigationBar != null && mNavigationBar.isVisibleLw());
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002953
Craig Mautnerf683b562012-10-02 11:10:57 -07002954 final int adjust = sim & SOFT_INPUT_MASK_ADJUST;
2955
Craig Mautner69b08182012-09-05 13:07:13 -07002956 if (!isDefaultDisplay) {
2957 if (attached != null) {
2958 // If this window is attached to another, our display
2959 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002960 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07002961 } else {
2962 // Give the window full screen.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002963 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
2964 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
2965 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08002966 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002967 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08002968 = mOverscanScreenTop + mOverscanScreenHeight;
Craig Mautner69b08182012-09-05 13:07:13 -07002969 }
2970 } else if (attrs.type == TYPE_INPUT_METHOD) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002971 pf.left = df.left = of.left = cf.left = vf.left = mDockLeft;
2972 pf.top = df.top = of.top = cf.top = vf.top = mDockTop;
2973 pf.right = df.right = of.right = cf.right = vf.right = mDockRight;
2974 pf.bottom = df.bottom = of.bottom = cf.bottom = vf.bottom = mDockBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002975 // IM dock windows always go to the bottom of the screen.
2976 attrs.gravity = Gravity.BOTTOM;
2977 mDockLayer = win.getSurfaceLayer();
2978 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002979 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
2980 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
Craig Mautnereda67292013-04-28 13:50:14 -07002981 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002982 + "): IN_SCREEN, INSET_DECOR");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002983 // This is the case for a normal activity window: we want it
2984 // to cover all of the screen space, and it can take care of
2985 // moving its contents to account for screen decorations that
2986 // intrude into that space.
2987 if (attached != null) {
2988 // If this window is attached to another, our display
2989 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002990 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002991 } else {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002992 if (attrs.type == TYPE_STATUS_BAR_PANEL
2993 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Joe Onorato29fc2c92010-11-24 10:26:50 -08002994 // Status bar panels are the only windows who can go on top of
2995 // the status bar. They are protected by the STATUS_BAR_SERVICE
2996 // permission, so they have the same privileges as the status
2997 // bar itself.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002998 //
Daniel Sandler8e8b4152011-07-21 01:16:43 -04002999 // However, they should still dodge the navigation bar if it exists.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003000
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003001 pf.left = df.left = of.left = hasNavBar
3002 ? mDockLeft : mUnrestrictedScreenLeft;
3003 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3004 pf.right = df.right = of.right = hasNavBar
3005 ? mRestrictedScreenLeft+mRestrictedScreenWidth
3006 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3007 pf.bottom = df.bottom = of.bottom = hasNavBar
3008 ? mRestrictedScreenTop+mRestrictedScreenHeight
3009 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003010
Craig Mautnereda67292013-04-28 13:50:14 -07003011 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003012 "Laying out status bar window: (%d,%d - %d,%d)",
3013 pf.left, pf.top, pf.right, pf.bottom));
Dianne Hackbornc652de82013-02-15 16:32:56 -08003014 } else if ((attrs.flags&FLAG_LAYOUT_IN_OVERSCAN) != 0
3015 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3016 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3017 // Asking to layout into the overscan region, so give it that pure
3018 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003019 pf.left = df.left = of.left = mOverscanScreenLeft;
3020 pf.top = df.top = of.top = mOverscanScreenTop;
3021 pf.right = df.right = of.right = mOverscanScreenLeft + mOverscanScreenWidth;
3022 pf.bottom = df.bottom = of.bottom = mOverscanScreenTop
3023 + mOverscanScreenHeight;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003024 } else if (mCanHideNavigationBar
3025 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003026 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3027 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3028 // Asking for layout as if the nav bar is hidden, lets the
Dianne Hackbornc652de82013-02-15 16:32:56 -08003029 // application extend into the unrestricted overscan screen area. We
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003030 // only do this for application windows to ensure no window that
3031 // can be above the nav bar can do this.
Dianne Hackborn313440842013-02-19 19:22:59 -08003032 pf.left = df.left = mOverscanScreenLeft;
3033 pf.top = df.top = mOverscanScreenTop;
3034 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
3035 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003036 // We need to tell the app about where the frame inside the overscan
3037 // is, so it can inset its content by that amount -- it didn't ask
3038 // to actually extend itself into the overscan region.
3039 of.left = mUnrestrictedScreenLeft;
3040 of.top = mUnrestrictedScreenTop;
3041 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3042 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003043 } else {
Dianne Hackborn313440842013-02-19 19:22:59 -08003044 pf.left = df.left = mRestrictedOverscanScreenLeft;
3045 pf.top = df.top = mRestrictedOverscanScreenTop;
3046 pf.right = df.right = mRestrictedOverscanScreenLeft
3047 + mRestrictedOverscanScreenWidth;
3048 pf.bottom = df.bottom = mRestrictedOverscanScreenTop
3049 + mRestrictedOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003050 // We need to tell the app about where the frame inside the overscan
3051 // is, so it can inset its content by that amount -- it didn't ask
3052 // to actually extend itself into the overscan region.
3053 of.left = mUnrestrictedScreenLeft;
3054 of.top = mUnrestrictedScreenTop;
3055 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3056 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003057 }
Craig Mautner69b08182012-09-05 13:07:13 -07003058
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003059 if ((attrs.flags&FLAG_FULLSCREEN) == 0) {
3060 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
3061 cf.left = mDockLeft;
3062 cf.top = mDockTop;
3063 cf.right = mDockRight;
3064 cf.bottom = mDockBottom;
3065 } else {
3066 cf.left = mContentLeft;
3067 cf.top = mContentTop;
3068 cf.right = mContentRight;
3069 cf.bottom = mContentBottom;
3070 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003071 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003072 // Full screen windows are always given a layout that is as if the
3073 // status bar and other transient decors are gone. This is to avoid
3074 // bad states when moving from a window that is not hding the
3075 // status bar to one that is.
3076 cf.left = mRestrictedScreenLeft;
3077 cf.top = mRestrictedScreenTop;
3078 cf.right = mRestrictedScreenLeft + mRestrictedScreenWidth;
3079 cf.bottom = mRestrictedScreenTop + mRestrictedScreenHeight;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003080 }
Craig Mautner69b08182012-09-05 13:07:13 -07003081
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003082 applyStableConstraints(sysUiFl, fl, cf);
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003083 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3084 vf.left = mCurLeft;
3085 vf.top = mCurTop;
3086 vf.right = mCurRight;
3087 vf.bottom = mCurBottom;
3088 } else {
3089 vf.set(cf);
3090 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003091 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003092 } else if ((fl & FLAG_LAYOUT_IN_SCREEN) != 0 || (sysUiFl
3093 & (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
3094 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)) != 0) {
Craig Mautnereda67292013-04-28 13:50:14 -07003095 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3096 "): IN_SCREEN");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003097 // A window that has requested to fill the entire screen just
3098 // gets everything, period.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003099 if (attrs.type == TYPE_STATUS_BAR_PANEL
3100 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003101 pf.left = df.left = of.left = cf.left = hasNavBar
3102 ? mDockLeft : mUnrestrictedScreenLeft;
3103 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
3104 pf.right = df.right = of.right = cf.right = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003105 ? mRestrictedScreenLeft+mRestrictedScreenWidth
Dianne Hackbornc652de82013-02-15 16:32:56 -08003106 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003107 pf.bottom = df.bottom = of.bottom = cf.bottom = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003108 ? mRestrictedScreenTop+mRestrictedScreenHeight
Dianne Hackbornc652de82013-02-15 16:32:56 -08003109 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07003110 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler36412a72011-08-04 09:35:13 -04003111 "Laying out IN_SCREEN status bar window: (%d,%d - %d,%d)",
3112 pf.left, pf.top, pf.right, pf.bottom));
Jim Millere898ac52012-04-06 17:10:57 -07003113 } else if (attrs.type == TYPE_NAVIGATION_BAR
3114 || attrs.type == TYPE_NAVIGATION_BAR_PANEL) {
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003115 // The navigation bar has Real Ultimate Power.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003116 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3117 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3118 pf.right = df.right = of.right = mUnrestrictedScreenLeft
3119 + mUnrestrictedScreenWidth;
3120 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop
3121 + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07003122 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003123 "Laying out navigation bar window: (%d,%d - %d,%d)",
3124 pf.left, pf.top, pf.right, pf.bottom));
Dianne Hackborn01011c32012-02-21 13:54:21 -08003125 } else if ((attrs.type == TYPE_SECURE_SYSTEM_OVERLAY
3126 || attrs.type == TYPE_BOOT_PROGRESS)
Jeff Brownbfcb60a2011-09-08 18:51:14 -07003127 && ((fl & FLAG_FULLSCREEN) != 0)) {
3128 // Fullscreen secure system overlays get what they ask for.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003129 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3130 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3131 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
3132 + mOverscanScreenWidth;
3133 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
3134 + mOverscanScreenHeight;
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07003135 } else if (attrs.type == TYPE_BOOT_PROGRESS
3136 || attrs.type == TYPE_UNIVERSE_BACKGROUND) {
Dianne Hackborn01011c32012-02-21 13:54:21 -08003137 // Boot progress screen always covers entire display.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003138 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3139 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3140 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
3141 + mOverscanScreenWidth;
3142 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
3143 + mOverscanScreenHeight;
Dianne Hackborn313440842013-02-19 19:22:59 -08003144 } else if (attrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER) {
3145 // The wallpaper mostly goes into the overscan region.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003146 pf.left = df.left = of.left = cf.left = mRestrictedOverscanScreenLeft;
3147 pf.top = df.top = of.top = cf.top = mRestrictedOverscanScreenTop;
3148 pf.right = df.right = of.right = cf.right
Dianne Hackborn313440842013-02-19 19:22:59 -08003149 = mRestrictedOverscanScreenLeft + mRestrictedOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003150 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackborn313440842013-02-19 19:22:59 -08003151 = mRestrictedOverscanScreenTop + mRestrictedOverscanScreenHeight;
Dianne Hackbornc652de82013-02-15 16:32:56 -08003152 } else if ((attrs.flags & FLAG_LAYOUT_IN_OVERSCAN) != 0
3153 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3154 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3155 // Asking to layout into the overscan region, so give it that pure
3156 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003157 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3158 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3159 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08003160 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003161 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003162 = mOverscanScreenTop + mOverscanScreenHeight;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003163 } else if (mCanHideNavigationBar
3164 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003165 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3166 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3167 // Asking for layout as if the nav bar is hidden, lets the
3168 // application extend into the unrestricted screen area. We
3169 // only do this for application windows to ensure no window that
3170 // can be above the nav bar can do this.
3171 // XXX This assumes that an app asking for this will also
3172 // ask for layout in only content. We can't currently figure out
3173 // what the screen would be if only laying out to hide the nav bar.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003174 pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft;
3175 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
3176 pf.right = df.right = of.right = cf.right = mUnrestrictedScreenLeft
3177 + mUnrestrictedScreenWidth;
3178 pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop
3179 + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003180 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003181 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
3182 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
3183 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
3184 + mRestrictedScreenWidth;
3185 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
3186 + mRestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003187 }
Craig Mautner69b08182012-09-05 13:07:13 -07003188
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003189 applyStableConstraints(sysUiFl, fl, cf);
Craig Mautner69b08182012-09-05 13:07:13 -07003190
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003191 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3192 vf.left = mCurLeft;
3193 vf.top = mCurTop;
3194 vf.right = mCurRight;
3195 vf.bottom = mCurBottom;
3196 } else {
3197 vf.set(cf);
3198 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003199 } else if (attached != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07003200 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3201 "): attached to " + attached);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003202 // A child window should be placed inside of the same visible
3203 // frame that its parent had.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003204 setAttachedWindowFrames(win, fl, adjust, attached, false, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003205 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07003206 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3207 "): normal window");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003208 // Otherwise, a normal window must be placed inside the content
3209 // of all screen decorations.
Dianne Hackborna239c842011-06-01 12:28:20 -07003210 if (attrs.type == TYPE_STATUS_BAR_PANEL) {
3211 // Status bar panels are the only windows who can go on top of
3212 // the status bar. They are protected by the STATUS_BAR_SERVICE
3213 // permission, so they have the same privileges as the status
3214 // bar itself.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003215 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
3216 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
3217 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
3218 + mRestrictedScreenWidth;
3219 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
3220 + mRestrictedScreenHeight;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003221 } else {
Dianne Hackborna239c842011-06-01 12:28:20 -07003222 pf.left = mContentLeft;
3223 pf.top = mContentTop;
3224 pf.right = mContentRight;
3225 pf.bottom = mContentBottom;
3226 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003227 df.left = of.left = cf.left = mDockLeft;
3228 df.top = of.top = cf.top = mDockTop;
3229 df.right = of.right = cf.right = mDockRight;
3230 df.bottom = of.bottom = cf.bottom = mDockBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07003231 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003232 df.left = of.left = cf.left = mContentLeft;
3233 df.top = of.top = cf.top = mContentTop;
3234 df.right = of.right = cf.right = mContentRight;
3235 df.bottom = of.bottom = cf.bottom = mContentBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07003236 }
3237 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3238 vf.left = mCurLeft;
3239 vf.top = mCurTop;
3240 vf.right = mCurRight;
3241 vf.bottom = mCurBottom;
3242 } else {
3243 vf.set(cf);
3244 }
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003245 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003246 }
3247 }
Craig Mautner69b08182012-09-05 13:07:13 -07003248
Craig Mautnerb816bed2013-07-23 10:26:17 -07003249 // TYPE_SYSTEM_ERROR is above the NavigationBar so it can't be allowed to extend over it.
3250 if ((fl & FLAG_LAYOUT_NO_LIMITS) != 0 && attrs.type != TYPE_SYSTEM_ERROR) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003251 df.left = df.top = of.left = of.top = cf.left = cf.top = vf.left = vf.top = -10000;
3252 df.right = df.bottom = of.right = of.bottom = cf.right = cf.bottom
3253 = vf.right = vf.bottom = 10000;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003254 }
3255
Craig Mautnereda67292013-04-28 13:50:14 -07003256 if (DEBUG_LAYOUT) Slog.v(TAG, "Compute frame " + attrs.getTitle()
The Android Open Source Project11267662009-03-18 17:39:47 -07003257 + ": sim=#" + Integer.toHexString(sim)
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003258 + " attach=" + attached + " type=" + attrs.type
3259 + String.format(" flags=0x%08x", fl)
The Android Open Source Project11267662009-03-18 17:39:47 -07003260 + " pf=" + pf.toShortString() + " df=" + df.toShortString()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003261 + " of=" + of.toShortString()
The Android Open Source Project11267662009-03-18 17:39:47 -07003262 + " cf=" + cf.toShortString() + " vf=" + vf.toShortString());
Craig Mautner69b08182012-09-05 13:07:13 -07003263
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003264 win.computeFrameLw(pf, df, of, cf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07003265
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003266 // Dock windows carve out the bottom of the screen, so normal windows
3267 // can't appear underneath them.
Craig Mautner8bd206b2012-10-03 10:32:02 -07003268 if (attrs.type == TYPE_INPUT_METHOD && win.isVisibleOrBehindKeyguardLw()
3269 && !win.getGivenInsetsPendingLw()) {
satok1bc0a492012-04-25 22:47:12 +09003270 setLastInputMethodWindowLw(null, null);
3271 offsetInputMethodWindowLw(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003272 }
3273 }
3274
satok1bc0a492012-04-25 22:47:12 +09003275 private void offsetInputMethodWindowLw(WindowState win) {
3276 int top = win.getContentFrameLw().top;
3277 top += win.getGivenContentInsetsLw().top;
3278 if (mContentBottom > top) {
3279 mContentBottom = top;
3280 }
3281 top = win.getVisibleFrameLw().top;
3282 top += win.getGivenVisibleInsetsLw().top;
3283 if (mCurBottom > top) {
3284 mCurBottom = top;
3285 }
Craig Mautnereda67292013-04-28 13:50:14 -07003286 if (DEBUG_LAYOUT) Slog.v(TAG, "Input method: mDockBottom="
satok1bc0a492012-04-25 22:47:12 +09003287 + mDockBottom + " mContentBottom="
3288 + mContentBottom + " mCurBottom=" + mCurBottom);
3289 }
3290
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003291 /** {@inheritDoc} */
Craig Mautner61ac6bb2012-02-02 17:29:33 -08003292 @Override
3293 public void finishLayoutLw() {
3294 return;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003295 }
3296
3297 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003298 @Override
Craig Mautner39834192012-09-02 07:47:24 -07003299 public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) {
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003300 mTopFullscreenOpaqueWindowState = null;
3301 mForceStatusBar = false;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003302 mForceStatusBarFromKeyguard = false;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08003303 mForcingShowNavBar = false;
3304 mForcingShowNavBarLayer = -1;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003305
3306 mHideLockScreen = false;
3307 mAllowLockscreenWhenOn = false;
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003308 mDismissKeyguard = DISMISS_KEYGUARD_NONE;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003309 mShowingLockscreen = false;
3310 mShowingDream = false;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003311 }
3312
3313 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003314 @Override
Craig Mautner39834192012-09-02 07:47:24 -07003315 public void applyPostLayoutPolicyLw(WindowState win,
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003316 WindowManager.LayoutParams attrs) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07003317 if (DEBUG_LAYOUT) Slog.i(TAG, "Win " + win + ": isVisibleOrBehindKeyguardLw="
3318 + win.isVisibleOrBehindKeyguardLw());
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08003319 if (mTopFullscreenOpaqueWindowState == null && (win.getAttrs().privateFlags
3320 &WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_SHOW_NAV_BAR) != 0) {
3321 if (mForcingShowNavBarLayer < 0) {
3322 mForcingShowNavBar = true;
3323 mForcingShowNavBarLayer = win.getSurfaceLayer();
3324 }
3325 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003326 if (mTopFullscreenOpaqueWindowState == null &&
Dianne Hackborn01b02a72012-01-12 14:05:03 -08003327 win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()) {
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003328 if ((attrs.flags & FLAG_FORCE_NOT_FULLSCREEN) != 0) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003329 if (attrs.type == TYPE_KEYGUARD) {
3330 mForceStatusBarFromKeyguard = true;
3331 } else {
3332 mForceStatusBar = true;
3333 }
3334 }
3335 if (attrs.type == TYPE_KEYGUARD) {
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003336 mShowingLockscreen = true;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07003337 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003338 boolean applyWindow = attrs.type >= FIRST_APPLICATION_WINDOW
3339 && attrs.type <= LAST_APPLICATION_WINDOW;
3340 if (attrs.type == TYPE_DREAM) {
Jeff Brownc8018eb2012-10-29 21:33:27 -07003341 // If the lockscreen was showing when the dream started then wait
3342 // for the dream to draw before hiding the lockscreen.
3343 if (!mDreamingLockscreen
3344 || (win.isVisibleLw() && win.hasDrawnLw())) {
3345 mShowingDream = true;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003346 applyWindow = true;
3347 }
3348 }
3349 if (applyWindow
Dianne Hackborn6493e642010-10-01 13:06:30 -07003350 && attrs.x == 0 && attrs.y == 0
3351 && attrs.width == WindowManager.LayoutParams.MATCH_PARENT
3352 && attrs.height == WindowManager.LayoutParams.MATCH_PARENT) {
Craig Mautnereda67292013-04-28 13:50:14 -07003353 if (DEBUG_LAYOUT) Slog.v(TAG, "Fullscreen window: " + win);
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003354 mTopFullscreenOpaqueWindowState = win;
3355 if ((attrs.flags & FLAG_SHOW_WHEN_LOCKED) != 0) {
Craig Mautnereda67292013-04-28 13:50:14 -07003356 if (DEBUG_LAYOUT) Slog.v(TAG, "Setting mHideLockScreen to true by win " + win);
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003357 mHideLockScreen = true;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003358 mForceStatusBarFromKeyguard = false;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003359 }
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003360 if ((attrs.flags & FLAG_DISMISS_KEYGUARD) != 0
3361 && mDismissKeyguard == DISMISS_KEYGUARD_NONE) {
Craig Mautnereda67292013-04-28 13:50:14 -07003362 if (DEBUG_LAYOUT) Slog.v(TAG, "Setting mDismissKeyguard true by win " + win);
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003363 mDismissKeyguard = mWinDismissingKeyguard == win ?
3364 DISMISS_KEYGUARD_CONTINUE : DISMISS_KEYGUARD_START;
3365 mWinDismissingKeyguard = win;
Craig Mautnereda67292013-04-28 13:50:14 -07003366 mForceStatusBarFromKeyguard = mShowingLockscreen && isKeyguardSecure();
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003367 }
3368 if ((attrs.flags & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) {
3369 mAllowLockscreenWhenOn = true;
3370 }
3371 }
3372 }
3373 }
3374
3375 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003376 @Override
Craig Mautner39834192012-09-02 07:47:24 -07003377 public int finishPostLayoutPolicyLw() {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003378 int changes = 0;
Joe Onorato93056472010-09-10 10:30:46 -04003379 boolean topIsFullscreen = false;
Daniel Sandlere02d8082010-10-08 15:13:22 -04003380
3381 final WindowManager.LayoutParams lp = (mTopFullscreenOpaqueWindowState != null)
3382 ? mTopFullscreenOpaqueWindowState.getAttrs()
3383 : null;
3384
Jeff Brownc8018eb2012-10-29 21:33:27 -07003385 // If we are not currently showing a dream then remember the current
3386 // lockscreen state. We will use this to determine whether the dream
3387 // started while the lockscreen was showing and remember this state
3388 // while the dream is showing.
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003389 if (!mShowingDream) {
3390 mDreamingLockscreen = mShowingLockscreen;
3391 }
3392
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003393 if (mStatusBar != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07003394 if (DEBUG_LAYOUT) Slog.i(TAG, "force=" + mForceStatusBar
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003395 + " forcefkg=" + mForceStatusBarFromKeyguard
Dianne Hackbornd70bc2f2009-10-06 23:25:51 -07003396 + " top=" + mTopFullscreenOpaqueWindowState);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003397 if (mForceStatusBar || mForceStatusBarFromKeyguard) {
Craig Mautnereda67292013-04-28 13:50:14 -07003398 if (DEBUG_LAYOUT) Slog.v(TAG, "Showing status bar: forced");
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003399 if (mStatusBar.showLw(true)) changes |= FINISH_LAYOUT_REDO_LAYOUT;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003400 } else if (mTopFullscreenOpaqueWindowState != null) {
Joe Onorato93056472010-09-10 10:30:46 -04003401 if (localLOGV) {
Craig Mautnereda67292013-04-28 13:50:14 -07003402 Slog.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw()
Joe Onorato93056472010-09-10 10:30:46 -04003403 + " shown frame: " + mTopFullscreenOpaqueWindowState.getShownFrameLw());
Craig Mautnereda67292013-04-28 13:50:14 -07003404 Slog.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs()
Joe Onorato93056472010-09-10 10:30:46 -04003405 + " lp.flags=0x" + Integer.toHexString(lp.flags));
3406 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003407 topIsFullscreen = (lp.flags & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0
3408 || (mLastSystemUiFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
Joe Onorato93056472010-09-10 10:30:46 -04003409 // The subtle difference between the window for mTopFullscreenOpaqueWindowState
3410 // and mTopIsFullscreen is that that mTopIsFullscreen is set only if the window
3411 // has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the
3412 // case though.
John Spurlockad3e6cb2013-04-30 08:47:43 -04003413 if (mStatusHideybar == HIDEYBAR_SHOWING) {
John Spurlock32beb2c2013-03-11 10:16:47 -04003414 if (mStatusBar.showLw(true)) {
3415 changes |= FINISH_LAYOUT_REDO_LAYOUT;
3416 }
3417 } else if (topIsFullscreen) {
Craig Mautnereda67292013-04-28 13:50:14 -07003418 if (DEBUG_LAYOUT) Slog.v(TAG, "** HIDING status bar");
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003419 if (mStatusBar.hideLw(true)) {
3420 changes |= FINISH_LAYOUT_REDO_LAYOUT;
Daniel Sandler9c00d5b2011-09-13 14:04:26 -04003421
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003422 mHandler.post(new Runnable() {
3423 @Override
3424 public void run() {
Dianne Hackborn42e620c2012-06-24 13:20:51 -07003425 try {
3426 IStatusBarService statusbar = getStatusBarService();
3427 if (statusbar != null) {
Daniel Sandler11cf1782012-09-27 14:03:08 -04003428 statusbar.collapsePanels();
Dianne Hackborn42e620c2012-06-24 13:20:51 -07003429 }
3430 } catch (RemoteException ex) {
3431 // re-acquire status bar service next time it is needed.
3432 mStatusBarService = null;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003433 }
3434 }});
Craig Mautnereda67292013-04-28 13:50:14 -07003435 } else {
Craig Mautnerc5a6e442013-06-05 17:22:35 -07003436 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar already hiding");
Daniel Sandler40427442010-07-16 11:44:52 -04003437 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003438 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07003439 if (DEBUG_LAYOUT) Slog.v(TAG, "** SHOWING status bar: top is not fullscreen");
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003440 if (mStatusBar.showLw(true)) changes |= FINISH_LAYOUT_REDO_LAYOUT;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003441 }
3442 }
3443 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04003444
Joe Onorato644f9c32011-01-25 12:06:23 -08003445 mTopIsFullscreen = topIsFullscreen;
Daniel Sandlere02d8082010-10-08 15:13:22 -04003446
Craig Mautner39834192012-09-02 07:47:24 -07003447 // Hide the key guard if a visible window explicitly specifies that it wants to be
3448 // displayed when the screen is locked.
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -07003449 if (mKeyguard != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07003450 if (localLOGV) Slog.v(TAG, "finishPostLayoutPolicyLw: mHideKeyguard="
Craig Mautner39834192012-09-02 07:47:24 -07003451 + mHideLockScreen);
Jim Miller5ecd8112013-01-09 18:50:26 -08003452 if (mDismissKeyguard != DISMISS_KEYGUARD_NONE && !mKeyguardDelegate.isSecure()) {
Dianne Hackborn08743722009-12-21 12:16:51 -08003453 if (mKeyguard.hideLw(true)) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003454 changes |= FINISH_LAYOUT_REDO_LAYOUT
3455 | FINISH_LAYOUT_REDO_CONFIG
3456 | FINISH_LAYOUT_REDO_WALLPAPER;
3457 }
Jim Miller5ecd8112013-01-09 18:50:26 -08003458 if (mKeyguardDelegate.isShowing()) {
Dianne Hackbornb446e972009-09-20 15:23:25 -07003459 mHandler.post(new Runnable() {
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003460 @Override
Dianne Hackbornb446e972009-09-20 15:23:25 -07003461 public void run() {
Jim Miller5ecd8112013-01-09 18:50:26 -08003462 mKeyguardDelegate.keyguardDone(false, false);
Dianne Hackbornb446e972009-09-20 15:23:25 -07003463 }
3464 });
3465 }
Dianne Hackborn05726582009-09-22 17:28:24 -07003466 } else if (mHideLockScreen) {
Dianne Hackborn08743722009-12-21 12:16:51 -08003467 if (mKeyguard.hideLw(true)) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003468 changes |= FINISH_LAYOUT_REDO_LAYOUT
3469 | FINISH_LAYOUT_REDO_CONFIG
3470 | FINISH_LAYOUT_REDO_WALLPAPER;
3471 }
Jim Miller5ecd8112013-01-09 18:50:26 -08003472 mKeyguardDelegate.setHidden(true);
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003473 } else if (mDismissKeyguard != DISMISS_KEYGUARD_NONE) {
3474 // This is the case of keyguard isSecure() and not mHideLockScreen.
3475 if (mDismissKeyguard == DISMISS_KEYGUARD_START) {
3476 // Only launch the next keyguard unlock window once per window.
3477 if (mKeyguard.showLw(true)) {
3478 changes |= FINISH_LAYOUT_REDO_LAYOUT
3479 | FINISH_LAYOUT_REDO_CONFIG
3480 | FINISH_LAYOUT_REDO_WALLPAPER;
3481 }
Jim Miller5ecd8112013-01-09 18:50:26 -08003482 mKeyguardDelegate.setHidden(false);
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003483 mHandler.post(new Runnable() {
3484 @Override
3485 public void run() {
Jim Miller5ecd8112013-01-09 18:50:26 -08003486 mKeyguardDelegate.dismiss();
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003487 }
3488 });
3489 }
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -07003490 } else {
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003491 mWinDismissingKeyguard = null;
Dianne Hackborn08743722009-12-21 12:16:51 -08003492 if (mKeyguard.showLw(true)) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003493 changes |= FINISH_LAYOUT_REDO_LAYOUT
3494 | FINISH_LAYOUT_REDO_CONFIG
3495 | FINISH_LAYOUT_REDO_WALLPAPER;
3496 }
Jim Miller5ecd8112013-01-09 18:50:26 -08003497 mKeyguardDelegate.setHidden(false);
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -07003498 }
3499 }
Joe Onorato664644d2011-01-23 17:53:23 -08003500
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003501 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003502 // If the navigation bar has been hidden or shown, we need to do another
3503 // layout pass to update that window.
3504 changes |= FINISH_LAYOUT_REDO_LAYOUT;
3505 }
Joe Onorato664644d2011-01-23 17:53:23 -08003506
Mike Lockwood28569302010-01-28 11:54:40 -05003507 // update since mAllowLockscreenWhenOn might have changed
3508 updateLockScreenTimeout();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003509 return changes;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003510 }
3511
Dianne Hackborn08743722009-12-21 12:16:51 -08003512 public boolean allowAppAnimationsLw() {
Craig Mautnerf03e4c52012-06-14 14:11:27 -07003513 if (mKeyguard != null && mKeyguard.isVisibleLw() && !mKeyguard.isAnimatingLw()) {
Dianne Hackborn08743722009-12-21 12:16:51 -08003514 // If keyguard is currently visible, no reason to animate
3515 // behind it.
3516 return false;
3517 }
Dianne Hackborn08743722009-12-21 12:16:51 -08003518 return true;
3519 }
3520
Dianne Hackborndf89e652011-10-06 22:35:11 -07003521 public int focusChangedLw(WindowState lastFocus, WindowState newFocus) {
Joe Onorato664644d2011-01-23 17:53:23 -08003522 mFocusedWindow = newFocus;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003523 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003524 // If the navigation bar has been hidden or shown, we need to do another
3525 // layout pass to update that window.
3526 return FINISH_LAYOUT_REDO_LAYOUT;
3527 }
3528 return 0;
Joe Onorato664644d2011-01-23 17:53:23 -08003529 }
3530
Dianne Hackborn0ecadf72009-03-31 18:00:37 -07003531 /** {@inheritDoc} */
Jeff Brown46b9ac02010-04-22 18:58:52 -07003532 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
Mike Lockwood3a74bd32011-08-12 13:55:22 -07003533 // do nothing if headless
Mike Lockwoodd747dc82011-09-13 16:28:22 -04003534 if (mHeadless) return;
Mike Lockwood3a74bd32011-08-12 13:55:22 -07003535
Jeff Brown46b9ac02010-04-22 18:58:52 -07003536 // lid changed state
Jeff Brownc458ce92012-04-30 14:58:40 -07003537 final int newLidState = lidOpen ? LID_OPEN : LID_CLOSED;
3538 if (newLidState == mLidState) {
3539 return;
3540 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07003541
Jeff Brownc458ce92012-04-30 14:58:40 -07003542 mLidState = newLidState;
3543 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07003544 updateRotation(true);
Jeff Brownc458ce92012-04-30 14:58:40 -07003545
3546 if (lidOpen) {
Jim Millere51cf7ae2013-06-25 18:31:56 -07003547 mPowerManager.wakeUp(SystemClock.uptimeMillis());
Jeff Brownc458ce92012-04-30 14:58:40 -07003548 } else if (!mLidControlsSleep) {
Jeff Brown96307042012-07-27 15:51:34 -07003549 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
Jeff Brown46b9ac02010-04-22 18:58:52 -07003550 }
3551 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003552
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08003553 void setHdmiPlugged(boolean plugged) {
3554 if (mHdmiPlugged != plugged) {
3555 mHdmiPlugged = plugged;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003556 updateRotation(true, true);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08003557 Intent intent = new Intent(ACTION_HDMI_PLUGGED);
Joe Onoratodc100302011-01-11 17:07:41 -08003558 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08003559 intent.putExtra(EXTRA_HDMI_PLUGGED_STATE, plugged);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07003560 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08003561 }
3562 }
3563
Joe Onoratoea495d42011-04-06 11:41:11 -07003564 void initializeHdmiState() {
Joe Onorato7ba631f2011-05-04 15:28:00 -07003565 boolean plugged = false;
Joe Onoratoea495d42011-04-06 11:41:11 -07003566 // watch for HDMI plug messages if the hdmi switch exists
3567 if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) {
3568 mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi");
3569
Joe Onoratoea495d42011-04-06 11:41:11 -07003570 final String filename = "/sys/class/switch/hdmi/state";
3571 FileReader reader = null;
3572 try {
3573 reader = new FileReader(filename);
3574 char[] buf = new char[15];
3575 int n = reader.read(buf);
3576 if (n > 1) {
3577 plugged = 0 != Integer.parseInt(new String(buf, 0, n-1));
3578 }
3579 } catch (IOException ex) {
3580 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
3581 } catch (NumberFormatException ex) {
3582 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
3583 } finally {
3584 if (reader != null) {
3585 try {
3586 reader.close();
3587 } catch (IOException ex) {
3588 }
Joe Onoratodc100302011-01-11 17:07:41 -08003589 }
3590 }
3591 }
Joe Onorato7ba631f2011-05-04 15:28:00 -07003592 // This dance forces the code in setHdmiPlugged to run.
3593 // Always do this so the sticky intent is stuck (to false) if there is no hdmi.
3594 mHdmiPlugged = !plugged;
3595 setHdmiPlugged(!mHdmiPlugged);
Joe Onoratodc100302011-01-11 17:07:41 -08003596 }
3597
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003598 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003599 * @return Whether music is being played right now.
3600 */
3601 boolean isMusicActive() {
Eric Laurent413cb9d2009-07-17 11:52:43 -07003602 final AudioManager am = (AudioManager)mContext.getSystemService(Context.AUDIO_SERVICE);
3603 if (am == null) {
3604 Log.w(TAG, "isMusicActive: couldn't get AudioManager reference");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003605 return false;
3606 }
Eric Laurent413cb9d2009-07-17 11:52:43 -07003607 return am.isMusicActive();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003608 }
3609
3610 /**
3611 * Tell the audio service to adjust the volume appropriate to the event.
3612 * @param keycode
3613 */
Mike Lockwooda53e3812009-09-25 10:51:39 -04003614 void handleVolumeKey(int stream, int keycode) {
Jeff Brown4d396052010-10-29 21:50:21 -07003615 IAudioService audioService = getAudioService();
3616 if (audioService == null) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003617 return;
3618 }
3619 try {
3620 // since audio is playing, we shouldn't have to hold a wake lock
3621 // during the call, but we do it as a precaution for the rare possibility
3622 // that the music stops right before we call this
Jeff Brownb0418da2010-11-01 15:24:01 -07003623 // TODO: Actually handle MUTE.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003624 mBroadcastWakeLock.acquire();
Jeff Brown4d396052010-10-29 21:50:21 -07003625 audioService.adjustStreamVolume(stream,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003626 keycode == KeyEvent.KEYCODE_VOLUME_UP
3627 ? AudioManager.ADJUST_RAISE
3628 : AudioManager.ADJUST_LOWER,
Dianne Hackbornba50b97c2013-04-30 15:04:46 -07003629 0,
3630 mContext.getBasePackageName());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003631 } catch (RemoteException e) {
3632 Log.w(TAG, "IAudioService.adjustStreamVolume() threw RemoteException " + e);
3633 } finally {
3634 mBroadcastWakeLock.release();
3635 }
3636 }
Jeff Brown4d396052010-10-29 21:50:21 -07003637
Dianne Hackbornc0e3f242011-08-19 14:19:10 -07003638 final Object mScreenshotLock = new Object();
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07003639 ServiceConnection mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07003640
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003641 final Runnable mScreenshotTimeout = new Runnable() {
3642 @Override public void run() {
3643 synchronized (mScreenshotLock) {
3644 if (mScreenshotConnection != null) {
3645 mContext.unbindService(mScreenshotConnection);
3646 mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07003647 }
Winson Chung9112ec32011-06-27 13:15:32 -07003648 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003649 }
3650 };
3651
3652 // Assume this is called from the Handler thread.
3653 private void takeScreenshot() {
3654 synchronized (mScreenshotLock) {
3655 if (mScreenshotConnection != null) {
3656 return;
3657 }
3658 ComponentName cn = new ComponentName("com.android.systemui",
3659 "com.android.systemui.screenshot.TakeScreenshotService");
3660 Intent intent = new Intent();
3661 intent.setComponent(cn);
3662 ServiceConnection conn = new ServiceConnection() {
3663 @Override
3664 public void onServiceConnected(ComponentName name, IBinder service) {
3665 synchronized (mScreenshotLock) {
3666 if (mScreenshotConnection != this) {
3667 return;
3668 }
3669 Messenger messenger = new Messenger(service);
3670 Message msg = Message.obtain(null, 1);
3671 final ServiceConnection myConn = this;
3672 Handler h = new Handler(mHandler.getLooper()) {
3673 @Override
3674 public void handleMessage(Message msg) {
3675 synchronized (mScreenshotLock) {
3676 if (mScreenshotConnection == myConn) {
3677 mContext.unbindService(mScreenshotConnection);
3678 mScreenshotConnection = null;
3679 mHandler.removeCallbacks(mScreenshotTimeout);
3680 }
3681 }
3682 }
3683 };
3684 msg.replyTo = new Messenger(h);
Winson Chunga63bb842011-10-17 10:26:28 -07003685 msg.arg1 = msg.arg2 = 0;
3686 if (mStatusBar != null && mStatusBar.isVisibleLw())
3687 msg.arg1 = 1;
3688 if (mNavigationBar != null && mNavigationBar.isVisibleLw())
3689 msg.arg2 = 1;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003690 try {
3691 messenger.send(msg);
3692 } catch (RemoteException e) {
3693 }
3694 }
3695 }
3696 @Override
3697 public void onServiceDisconnected(ComponentName name) {}
3698 };
Amith Yamasani27b89e62013-01-16 12:30:11 -08003699 if (mContext.bindServiceAsUser(
3700 intent, conn, Context.BIND_AUTO_CREATE, UserHandle.CURRENT)) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003701 mScreenshotConnection = conn;
3702 mHandler.postDelayed(mScreenshotTimeout, 10000);
3703 }
3704 }
Winson Chung9112ec32011-06-27 13:15:32 -07003705 }
3706
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003707 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003708 @Override
Jeff Brown1f245102010-11-18 20:53:46 -08003709 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags, boolean isScreenOn) {
Jeff Brown96307042012-07-27 15:51:34 -07003710 if (!mSystemBooted) {
3711 // If we have not yet booted, don't let key events do anything.
3712 return 0;
3713 }
3714
Jeff Brown1f245102010-11-18 20:53:46 -08003715 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
3716 final boolean canceled = event.isCanceled();
3717 final int keyCode = event.getKeyCode();
Jeff Browne20c9e02010-10-11 14:20:19 -07003718
Jeff Brown3122e442010-10-11 23:32:49 -07003719 final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0;
Jeff Brown3122e442010-10-11 23:32:49 -07003720
Mike Lockwoodc72b15f2009-11-28 20:58:22 -05003721 // If screen is off then we treat the case where the keyguard is open but hidden
3722 // the same as if it were open and in front.
3723 // This will prevent any keys other than the power button from waking the screen
3724 // when the keyguard is hidden by another activity.
Jim Miller5ecd8112013-01-09 18:50:26 -08003725 final boolean keyguardActive = (mKeyguardDelegate == null ? false :
Mike Lockwood3a74bd32011-08-12 13:55:22 -07003726 (isScreenOn ?
Jim Miller5ecd8112013-01-09 18:50:26 -08003727 mKeyguardDelegate.isShowingAndNotHidden() :
3728 mKeyguardDelegate.isShowing()));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003729
Jeff Brown96307042012-07-27 15:51:34 -07003730 if (keyCode == KeyEvent.KEYCODE_POWER) {
3731 policyFlags |= WindowManagerPolicy.FLAG_WAKE;
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07003732 }
Jeff Brown96307042012-07-27 15:51:34 -07003733 final boolean isWakeKey = (policyFlags & (WindowManagerPolicy.FLAG_WAKE
3734 | WindowManagerPolicy.FLAG_WAKE_DROPPED)) != 0;
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07003735
Jeff Brown40013652012-05-16 21:22:36 -07003736 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003737 Log.d(TAG, "interceptKeyTq keycode=" + keyCode
Jeff Brown96307042012-07-27 15:51:34 -07003738 + " screenIsOn=" + isScreenOn + " keyguardActive=" + keyguardActive
3739 + " policyFlags=" + Integer.toHexString(policyFlags)
3740 + " isWakeKey=" + isWakeKey);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003741 }
3742
Jeff Brown98392ef2011-09-12 18:24:59 -07003743 if (down && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0
3744 && event.getRepeatCount() == 0) {
Jeff Brown4d396052010-10-29 21:50:21 -07003745 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
3746 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003747
Jeff Brown4d396052010-10-29 21:50:21 -07003748 // Basic policy based on screen state and keyguard.
3749 // FIXME: This policy isn't quite correct. We shouldn't care whether the screen
3750 // is on or off, really. We should care about whether the device is in an
3751 // interactive state or is in suspend pretending to be "off".
3752 // The primary screen might be turned off due to proximity sensor or
3753 // because we are presenting media on an auxiliary screen or remotely controlling
3754 // the device some other way (which is why we have an exemption here for injected
3755 // events).
3756 int result;
Mike Lockwoodd747dc82011-09-13 16:28:22 -04003757 if ((isScreenOn && !mHeadless) || (isInjected && !isWakeKey)) {
Jeff Brown4d396052010-10-29 21:50:21 -07003758 // When the screen is on or if the key is injected pass the key to the application.
3759 result = ACTION_PASS_TO_USER;
3760 } else {
3761 // When the screen is off and the key is not injected, determine whether
3762 // to wake the device but don't pass the key to the application.
3763 result = 0;
Jeff Brown1c2e4942012-11-06 16:32:01 -08003764 if (down && isWakeKey && isWakeKeyWhenScreenOff(keyCode)) {
Jim Millere51cf7ae2013-06-25 18:31:56 -07003765 result |= ACTION_WAKE_UP;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003766 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003767 }
3768
Justin Kohd378ad72013-04-01 12:18:26 -07003769 // If the key would be handled globally, just return the result, don't worry about special
3770 // key processing.
3771 if (mGlobalKeyManager.shouldHandleGlobalKey(keyCode, event)) {
3772 return result;
3773 }
3774
Jeff Brown4d396052010-10-29 21:50:21 -07003775 // Handle special keys.
3776 switch (keyCode) {
3777 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jeff Brownb0418da2010-11-01 15:24:01 -07003778 case KeyEvent.KEYCODE_VOLUME_UP:
3779 case KeyEvent.KEYCODE_VOLUME_MUTE: {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003780 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
3781 if (down) {
3782 if (isScreenOn && !mVolumeDownKeyTriggered
3783 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
3784 mVolumeDownKeyTriggered = true;
3785 mVolumeDownKeyTime = event.getDownTime();
3786 mVolumeDownKeyConsumedByScreenshotChord = false;
3787 cancelPendingPowerKeyAction();
3788 interceptScreenshotChord();
3789 }
3790 } else {
3791 mVolumeDownKeyTriggered = false;
3792 cancelPendingScreenshotChordAction();
3793 }
3794 } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
3795 if (down) {
3796 if (isScreenOn && !mVolumeUpKeyTriggered
3797 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
3798 mVolumeUpKeyTriggered = true;
3799 cancelPendingPowerKeyAction();
3800 cancelPendingScreenshotChordAction();
3801 }
3802 } else {
3803 mVolumeUpKeyTriggered = false;
3804 cancelPendingScreenshotChordAction();
3805 }
3806 }
Jeff Brown4d396052010-10-29 21:50:21 -07003807 if (down) {
3808 ITelephony telephonyService = getTelephonyService();
3809 if (telephonyService != null) {
3810 try {
3811 if (telephonyService.isRinging()) {
3812 // If an incoming call is ringing, either VOLUME key means
3813 // "silence ringer". We handle these keys here, rather than
3814 // in the InCallScreen, to make sure we'll respond to them
3815 // even if the InCallScreen hasn't come to the foreground yet.
3816 // Look for the DOWN event here, to agree with the "fallback"
3817 // behavior in the InCallScreen.
3818 Log.i(TAG, "interceptKeyBeforeQueueing:"
3819 + " VOLUME key-down while ringing: Silence ringer!");
3820
3821 // Silence the ringer. (It's safe to call this
3822 // even if the ringer has already been silenced.)
3823 telephonyService.silenceRinger();
3824
3825 // And *don't* pass this key thru to the current activity
3826 // (which is probably the InCallScreen.)
3827 result &= ~ACTION_PASS_TO_USER;
3828 break;
3829 }
3830 if (telephonyService.isOffhook()
3831 && (result & ACTION_PASS_TO_USER) == 0) {
3832 // If we are in call but we decided not to pass the key to
3833 // the application, handle the volume change here.
3834 handleVolumeKey(AudioManager.STREAM_VOICE_CALL, keyCode);
3835 break;
3836 }
3837 } catch (RemoteException ex) {
3838 Log.w(TAG, "ITelephony threw RemoteException", ex);
3839 }
3840 }
3841
3842 if (isMusicActive() && (result & ACTION_PASS_TO_USER) == 0) {
3843 // If music is playing but we decided not to pass the key to the
3844 // application, handle the volume change here.
3845 handleVolumeKey(AudioManager.STREAM_MUSIC, keyCode);
3846 break;
3847 }
3848 }
3849 break;
3850 }
3851
3852 case KeyEvent.KEYCODE_ENDCALL: {
3853 result &= ~ACTION_PASS_TO_USER;
3854 if (down) {
3855 ITelephony telephonyService = getTelephonyService();
3856 boolean hungUp = false;
3857 if (telephonyService != null) {
3858 try {
3859 hungUp = telephonyService.endCall();
3860 } catch (RemoteException ex) {
3861 Log.w(TAG, "ITelephony threw RemoteException", ex);
3862 }
3863 }
3864 interceptPowerKeyDown(!isScreenOn || hungUp);
3865 } else {
3866 if (interceptPowerKeyUp(canceled)) {
3867 if ((mEndcallBehavior
3868 & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) {
3869 if (goHome()) {
3870 break;
Dianne Hackborn0041e972009-07-24 17:14:43 -07003871 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003872 }
Jeff Brown4d396052010-10-29 21:50:21 -07003873 if ((mEndcallBehavior
3874 & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) {
Jeff Brown96307042012-07-27 15:51:34 -07003875 result = (result & ~ACTION_WAKE_UP) | ACTION_GO_TO_SLEEP;
Jeff Brown4d396052010-10-29 21:50:21 -07003876 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003877 }
Jeff Brown4d396052010-10-29 21:50:21 -07003878 }
3879 break;
3880 }
3881
3882 case KeyEvent.KEYCODE_POWER: {
3883 result &= ~ACTION_PASS_TO_USER;
3884 if (down) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003885 if (isScreenOn && !mPowerKeyTriggered
3886 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
3887 mPowerKeyTriggered = true;
3888 mPowerKeyTime = event.getDownTime();
3889 interceptScreenshotChord();
Winson Chung9112ec32011-06-27 13:15:32 -07003890 }
Winson Chung9112ec32011-06-27 13:15:32 -07003891
Jeff Brown4d396052010-10-29 21:50:21 -07003892 ITelephony telephonyService = getTelephonyService();
3893 boolean hungUp = false;
3894 if (telephonyService != null) {
3895 try {
3896 if (telephonyService.isRinging()) {
3897 // Pressing Power while there's a ringing incoming
3898 // call should silence the ringer.
3899 telephonyService.silenceRinger();
3900 } else if ((mIncallPowerBehavior
3901 & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0
3902 && telephonyService.isOffhook()) {
3903 // Otherwise, if "Power button ends call" is enabled,
3904 // the Power button will hang up any current active call.
3905 hungUp = telephonyService.endCall();
3906 }
3907 } catch (RemoteException ex) {
3908 Log.w(TAG, "ITelephony threw RemoteException", ex);
3909 }
3910 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003911 interceptPowerKeyDown(!isScreenOn || hungUp
3912 || mVolumeDownKeyTriggered || mVolumeUpKeyTriggered);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003913 } else {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003914 mPowerKeyTriggered = false;
3915 cancelPendingScreenshotChordAction();
3916 if (interceptPowerKeyUp(canceled || mPendingPowerKeyUpCanceled)) {
Jeff Brown96307042012-07-27 15:51:34 -07003917 result = (result & ~ACTION_WAKE_UP) | ACTION_GO_TO_SLEEP;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003918 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003919 mPendingPowerKeyUpCanceled = false;
Jeff Brown4d396052010-10-29 21:50:21 -07003920 }
3921 break;
3922 }
3923
3924 case KeyEvent.KEYCODE_MEDIA_PLAY:
3925 case KeyEvent.KEYCODE_MEDIA_PAUSE:
3926 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
3927 if (down) {
3928 ITelephony telephonyService = getTelephonyService();
3929 if (telephonyService != null) {
3930 try {
3931 if (!telephonyService.isIdle()) {
3932 // Suppress PLAY/PAUSE toggle when phone is ringing or in-call
3933 // to avoid music playback.
3934 break;
3935 }
3936 } catch (RemoteException ex) {
3937 Log.w(TAG, "ITelephony threw RemoteException", ex);
Jeff Brown3122e442010-10-11 23:32:49 -07003938 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003939 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003940 }
Jeff Brown4d396052010-10-29 21:50:21 -07003941 case KeyEvent.KEYCODE_HEADSETHOOK:
3942 case KeyEvent.KEYCODE_MUTE:
3943 case KeyEvent.KEYCODE_MEDIA_STOP:
3944 case KeyEvent.KEYCODE_MEDIA_NEXT:
3945 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
3946 case KeyEvent.KEYCODE_MEDIA_REWIND:
3947 case KeyEvent.KEYCODE_MEDIA_RECORD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09003948 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
3949 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: {
Jeff Brown4d396052010-10-29 21:50:21 -07003950 if ((result & ACTION_PASS_TO_USER) == 0) {
3951 // Only do this if we would otherwise not pass it to the user. In that
3952 // case, the PhoneWindow class will do the same thing, except it will
3953 // only do it if the showing app doesn't process the key on its own.
Jeff Brown40013652012-05-16 21:22:36 -07003954 // Note that we need to make a copy of the key event here because the
3955 // original key event will be recycled when we return.
Jeff Brown4d396052010-10-29 21:50:21 -07003956 mBroadcastWakeLock.acquire();
Jeff Brown40013652012-05-16 21:22:36 -07003957 Message msg = mHandler.obtainMessage(MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK,
3958 new KeyEvent(event));
3959 msg.setAsynchronous(true);
3960 msg.sendToTarget();
Jeff Brown4d396052010-10-29 21:50:21 -07003961 }
3962 break;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003963 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003964
Jeff Brown4d396052010-10-29 21:50:21 -07003965 case KeyEvent.KEYCODE_CALL: {
3966 if (down) {
3967 ITelephony telephonyService = getTelephonyService();
3968 if (telephonyService != null) {
3969 try {
3970 if (telephonyService.isRinging()) {
3971 Log.i(TAG, "interceptKeyBeforeQueueing:"
3972 + " CALL key-down while ringing: Answer the call!");
3973 telephonyService.answerRingingCall();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003974
Jeff Brown4d396052010-10-29 21:50:21 -07003975 // And *don't* pass this key thru to the current activity
3976 // (which is presumably the InCallScreen.)
3977 result &= ~ACTION_PASS_TO_USER;
3978 }
3979 } catch (RemoteException ex) {
3980 Log.w(TAG, "ITelephony threw RemoteException", ex);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003981 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003982 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003983 }
Jeff Brown4d396052010-10-29 21:50:21 -07003984 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003985 }
3986 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003987 return result;
3988 }
3989
Jeff Brown1c2e4942012-11-06 16:32:01 -08003990 /**
3991 * When the screen is off we ignore some keys that might otherwise typically
3992 * be considered wake keys. We filter them out here.
3993 *
3994 * {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it
3995 * is always considered a wake key.
3996 */
3997 private boolean isWakeKeyWhenScreenOff(int keyCode) {
3998 switch (keyCode) {
3999 // ignore volume keys unless docked
4000 case KeyEvent.KEYCODE_VOLUME_UP:
4001 case KeyEvent.KEYCODE_VOLUME_DOWN:
4002 case KeyEvent.KEYCODE_VOLUME_MUTE:
4003 return mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED;
4004
4005 // ignore media and camera keys
4006 case KeyEvent.KEYCODE_MUTE:
4007 case KeyEvent.KEYCODE_HEADSETHOOK:
4008 case KeyEvent.KEYCODE_MEDIA_PLAY:
4009 case KeyEvent.KEYCODE_MEDIA_PAUSE:
4010 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
4011 case KeyEvent.KEYCODE_MEDIA_STOP:
4012 case KeyEvent.KEYCODE_MEDIA_NEXT:
4013 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
4014 case KeyEvent.KEYCODE_MEDIA_REWIND:
4015 case KeyEvent.KEYCODE_MEDIA_RECORD:
4016 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09004017 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK:
Jeff Brown1c2e4942012-11-06 16:32:01 -08004018 case KeyEvent.KEYCODE_CAMERA:
4019 return false;
4020 }
4021 return true;
4022 }
4023
4024
Jeff Brown56194eb2011-03-02 19:23:13 -08004025 /** {@inheritDoc} */
4026 @Override
4027 public int interceptMotionBeforeQueueingWhenScreenOff(int policyFlags) {
4028 int result = 0;
4029
4030 final boolean isWakeMotion = (policyFlags
4031 & (WindowManagerPolicy.FLAG_WAKE | WindowManagerPolicy.FLAG_WAKE_DROPPED)) != 0;
4032 if (isWakeMotion) {
Jim Millere51cf7ae2013-06-25 18:31:56 -07004033 result |= ACTION_WAKE_UP;
Jeff Brown56194eb2011-03-02 19:23:13 -08004034 }
4035 return result;
4036 }
4037
Jeff Brown40013652012-05-16 21:22:36 -07004038 void dispatchMediaKeyWithWakeLock(KeyEvent event) {
4039 if (DEBUG_INPUT) {
4040 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: " + event);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004041 }
4042
Jeff Brown40013652012-05-16 21:22:36 -07004043 if (mHavePendingMediaKeyRepeatWithWakeLock) {
4044 if (DEBUG_INPUT) {
4045 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: canceled repeat");
4046 }
4047
4048 mHandler.removeMessages(MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK);
4049 mHavePendingMediaKeyRepeatWithWakeLock = false;
4050 mBroadcastWakeLock.release(); // pending repeat was holding onto the wake lock
4051 }
4052
4053 dispatchMediaKeyWithWakeLockToAudioService(event);
4054
4055 if (event.getAction() == KeyEvent.ACTION_DOWN
4056 && event.getRepeatCount() == 0) {
4057 mHavePendingMediaKeyRepeatWithWakeLock = true;
4058
4059 Message msg = mHandler.obtainMessage(
4060 MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK, event);
4061 msg.setAsynchronous(true);
4062 mHandler.sendMessageDelayed(msg, ViewConfiguration.getKeyRepeatTimeout());
4063 } else {
4064 mBroadcastWakeLock.release();
4065 }
4066 }
4067
4068 void dispatchMediaKeyRepeatWithWakeLock(KeyEvent event) {
4069 mHavePendingMediaKeyRepeatWithWakeLock = false;
4070
4071 KeyEvent repeatEvent = KeyEvent.changeTimeRepeat(event,
4072 SystemClock.uptimeMillis(), 1, event.getFlags() | KeyEvent.FLAG_LONG_PRESS);
4073 if (DEBUG_INPUT) {
4074 Slog.d(TAG, "dispatchMediaKeyRepeatWithWakeLock: " + repeatEvent);
4075 }
4076
4077 dispatchMediaKeyWithWakeLockToAudioService(repeatEvent);
4078 mBroadcastWakeLock.release();
4079 }
4080
4081 void dispatchMediaKeyWithWakeLockToAudioService(KeyEvent event) {
4082 if (ActivityManagerNative.isSystemReady()) {
4083 IAudioService audioService = getAudioService();
4084 if (audioService != null) {
4085 try {
4086 audioService.dispatchMediaKeyEventUnderWakelock(event);
4087 } catch (RemoteException e) {
4088 Log.e(TAG, "dispatchMediaKeyEvent threw exception " + e);
Jean-Michel Trivic6802222012-04-30 11:15:03 -07004089 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004090 }
4091 }
4092 }
4093
Mike Lockwood1753f7f2009-08-24 14:49:07 -07004094 BroadcastReceiver mDockReceiver = new BroadcastReceiver() {
Craig Mautnereee29c42013-01-17 14:44:34 -08004095 @Override
Mike Lockwood1753f7f2009-08-24 14:49:07 -07004096 public void onReceive(Context context, Intent intent) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07004097 if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) {
4098 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
4099 Intent.EXTRA_DOCK_STATE_UNDOCKED);
Daniel Sandler6396c722013-04-16 20:19:09 -04004100 } else {
4101 try {
4102 IUiModeManager uiModeService = IUiModeManager.Stub.asInterface(
4103 ServiceManager.getService(Context.UI_MODE_SERVICE));
4104 mUiMode = uiModeService.getCurrentModeType();
4105 } catch (RemoteException e) {
4106 }
Dianne Hackborn80fa1662009-10-07 14:02:10 -07004107 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004108 updateRotation(true);
Craig Mautnereee29c42013-01-17 14:44:34 -08004109 synchronized (mLock) {
4110 updateOrientationListenerLp();
4111 }
Mike Lockwood1753f7f2009-08-24 14:49:07 -07004112 }
4113 };
4114
Jeff Brown6aaf2952012-10-05 16:01:08 -07004115 BroadcastReceiver mDreamReceiver = new BroadcastReceiver() {
4116 @Override
4117 public void onReceive(Context context, Intent intent) {
4118 if (Intent.ACTION_DREAMING_STARTED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004119 if (mKeyguardDelegate != null) {
4120 mKeyguardDelegate.onDreamingStarted();
Jeff Brown6aaf2952012-10-05 16:01:08 -07004121 }
4122 } else if (Intent.ACTION_DREAMING_STOPPED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004123 if (mKeyguardDelegate != null) {
4124 mKeyguardDelegate.onDreamingStopped();
Jeff Brown6aaf2952012-10-05 16:01:08 -07004125 }
4126 }
4127 }
4128 };
4129
Christopher Tate5e08af02012-09-21 17:17:22 -07004130 BroadcastReceiver mMultiuserReceiver = new BroadcastReceiver() {
4131 @Override
4132 public void onReceive(Context context, Intent intent) {
4133 if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) {
4134 // tickle the settings observer: this first ensures that we're
4135 // observing the relevant settings for the newly-active user,
4136 // and then updates our own bookkeeping based on the now-
4137 // current user.
4138 mSettingsObserver.onChange(false);
John Spurlockce479d82012-11-29 09:52:21 -05004139
4140 // force a re-application of focused window sysui visibility.
4141 // the window may never have been shown for this user
4142 // e.g. the keyguard when going through the new-user setup flow
John Spurlock04db1762013-05-13 12:46:41 -04004143 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
John Spurlockce479d82012-11-29 09:52:21 -05004144 mLastSystemUiFlags = 0;
4145 updateSystemUiVisibilityLw();
4146 }
Christopher Tate5e08af02012-09-21 17:17:22 -07004147 }
4148 }
4149 };
4150
John Spurlock04db1762013-05-13 12:46:41 -04004151 private void requestHideybars(WindowState swipeTarget) {
4152 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04004153 boolean sb = checkShowHideybar("status", mStatusHideybar, mStatusBar);
4154 boolean nb = checkShowHideybar("navigation", mNavigationHideybar, mNavigationBar);
4155 if (sb || nb) {
4156 WindowState hideyTarget = sb ? mStatusBar : mNavigationBar;
4157 if (sb ^ nb && hideyTarget != swipeTarget) {
4158 if (DEBUG) Slog.d(TAG, "Not showing hideybar, wrong swipe target");
4159 return;
4160 }
4161 mStatusHideybar = sb ? HIDEYBAR_SHOWING : mStatusHideybar;
4162 mNavigationHideybar = nb ? HIDEYBAR_SHOWING : mNavigationHideybar;
4163 updateSystemUiVisibilityLw();
John Spurlock32beb2c2013-03-11 10:16:47 -04004164 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04004165 }
4166 }
4167
4168 private boolean checkShowHideybar(String tag, int hideybar, WindowState win) {
4169 if (hideybar == HIDEYBAR_SHOWING) {
4170 if (DEBUG) Slog.d(TAG, "Not showing " + tag + " hideybar, already shown");
4171 return false;
John Spurlocke3b642e2013-05-09 15:51:32 -04004172 } else if (win == null) {
4173 if (DEBUG) Slog.d(TAG, "Not showing " + tag + " hideybar, bar doesn't exist");
4174 return false;
John Spurlockad3e6cb2013-04-30 08:47:43 -04004175 } else if (win.isDisplayedLw()) {
4176 if (DEBUG) Slog.d(TAG, "Not showing " + tag + " hideybar, bar already visible");
4177 return false;
4178 } else {
4179 return true;
John Spurlock32beb2c2013-03-11 10:16:47 -04004180 }
4181 }
4182
Jeff Brownc38c9be2012-10-04 13:16:19 -07004183 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004184 public void screenTurnedOff(int why) {
Dianne Hackborn74489012009-03-24 20:50:09 -07004185 EventLog.writeEvent(70000, 0);
The Android Open Source Project0727d222009-03-11 12:11:58 -07004186 synchronized (mLock) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004187 mScreenOnEarly = false;
4188 mScreenOnFully = false;
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07004189 }
Jim Miller5ecd8112013-01-09 18:50:26 -08004190 if (mKeyguardDelegate != null) {
4191 mKeyguardDelegate.onScreenTurnedOff(why);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004192 }
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07004193 synchronized (mLock) {
The Android Open Source Project0727d222009-03-11 12:11:58 -07004194 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05004195 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07004196 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004197 }
4198
Jeff Brownc38c9be2012-10-04 13:16:19 -07004199 @Override
Dianne Hackborn38e29a62011-09-18 14:43:08 -07004200 public void screenTurningOn(final ScreenOnListener screenOnListener) {
Dianne Hackborn74489012009-03-24 20:50:09 -07004201 EventLog.writeEvent(70000, 1);
Dianne Hackborn40011092011-09-22 13:37:48 -07004202 if (false) {
4203 RuntimeException here = new RuntimeException("here");
4204 here.fillInStackTrace();
4205 Slog.i(TAG, "Screen turning on...", here);
4206 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07004207
The Android Open Source Project0727d222009-03-11 12:11:58 -07004208 synchronized (mLock) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004209 mScreenOnEarly = true;
The Android Open Source Project0727d222009-03-11 12:11:58 -07004210 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05004211 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07004212 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07004213
Jeff Brownc38c9be2012-10-04 13:16:19 -07004214 waitForKeyguard(screenOnListener);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004215 }
4216
Jeff Brownc38c9be2012-10-04 13:16:19 -07004217 private void waitForKeyguard(final ScreenOnListener screenOnListener) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004218 if (mKeyguardDelegate != null) {
Jeff Brownc38c9be2012-10-04 13:16:19 -07004219 if (screenOnListener != null) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004220 mKeyguardDelegate.onScreenTurnedOn(new KeyguardServiceDelegate.ShowListener() {
Jeff Brownc38c9be2012-10-04 13:16:19 -07004221 @Override
4222 public void onShown(IBinder windowToken) {
4223 waitForKeyguardWindowDrawn(windowToken, screenOnListener);
4224 }
4225 });
4226 return;
4227 } else {
Jim Miller5ecd8112013-01-09 18:50:26 -08004228 mKeyguardDelegate.onScreenTurnedOn(null);
Jeff Brownc38c9be2012-10-04 13:16:19 -07004229 }
4230 } else {
Jim Miller5ecd8112013-01-09 18:50:26 -08004231 Slog.i(TAG, "No keyguard interface!");
Jeff Brownc38c9be2012-10-04 13:16:19 -07004232 }
4233 finishScreenTurningOn(screenOnListener);
4234 }
4235
4236 private void waitForKeyguardWindowDrawn(IBinder windowToken,
4237 final ScreenOnListener screenOnListener) {
4238 if (windowToken != null) {
4239 try {
4240 if (mWindowManager.waitForWindowDrawn(
4241 windowToken, new IRemoteCallback.Stub() {
4242 @Override
4243 public void sendResult(Bundle data) {
4244 Slog.i(TAG, "Lock screen displayed!");
4245 finishScreenTurningOn(screenOnListener);
4246 }
4247 })) {
4248 return;
4249 }
4250 } catch (RemoteException ex) {
4251 // Can't happen in system process.
4252 }
4253 }
4254
4255 Slog.i(TAG, "No lock screen!");
4256 finishScreenTurningOn(screenOnListener);
4257 }
4258
4259 private void finishScreenTurningOn(ScreenOnListener screenOnListener) {
4260 synchronized (mLock) {
4261 mScreenOnFully = true;
4262 }
4263
Jeff Brown4fc45272012-10-10 18:28:14 -07004264 try {
4265 mWindowManager.setEventDispatching(true);
4266 } catch (RemoteException unhandled) {
4267 }
4268
Jeff Brownc38c9be2012-10-04 13:16:19 -07004269 if (screenOnListener != null) {
4270 screenOnListener.onScreenOn();
4271 }
4272 }
4273
4274 @Override
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004275 public boolean isScreenOnEarly() {
4276 return mScreenOnEarly;
4277 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07004278
4279 @Override
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004280 public boolean isScreenOnFully() {
4281 return mScreenOnFully;
Dianne Hackborn08743722009-12-21 12:16:51 -08004282 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07004283
Dianne Hackborn08743722009-12-21 12:16:51 -08004284 /** {@inheritDoc} */
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004285 public void enableKeyguard(boolean enabled) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004286 if (mKeyguardDelegate != null) {
4287 mKeyguardDelegate.setKeyguardEnabled(enabled);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004288 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004289 }
4290
4291 /** {@inheritDoc} */
4292 public void exitKeyguardSecurely(OnKeyguardExitResult callback) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004293 if (mKeyguardDelegate != null) {
4294 mKeyguardDelegate.verifyUnlock(callback);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004295 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004296 }
4297
Mike Lockwoodf7913302009-11-28 22:27:10 -05004298 private boolean keyguardIsShowingTq() {
Jim Miller5ecd8112013-01-09 18:50:26 -08004299 if (mKeyguardDelegate == null) return false;
4300 return mKeyguardDelegate.isShowingAndNotHidden();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004301 }
4302
Mike Lockwood520d8bc2011-02-18 13:23:13 -05004303
4304 /** {@inheritDoc} */
4305 public boolean isKeyguardLocked() {
4306 return keyguardOn();
4307 }
4308
4309 /** {@inheritDoc} */
4310 public boolean isKeyguardSecure() {
Jim Miller5ecd8112013-01-09 18:50:26 -08004311 if (mKeyguardDelegate == null) return false;
4312 return mKeyguardDelegate.isSecure();
Mike Lockwood520d8bc2011-02-18 13:23:13 -05004313 }
4314
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004315 /** {@inheritDoc} */
4316 public boolean inKeyguardRestrictedKeyInputMode() {
Jim Miller5ecd8112013-01-09 18:50:26 -08004317 if (mKeyguardDelegate == null) return false;
4318 return mKeyguardDelegate.isInputRestricted();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004319 }
4320
Dianne Hackborn90c52de2011-09-23 12:57:44 -07004321 public void dismissKeyguardLw() {
Jim Miller195b5512013-02-28 03:35:57 -08004322 if (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()) {
Daniel Sandler1ce804392012-11-07 15:07:12 -05004323 mHandler.post(new Runnable() {
4324 public void run() {
Jim Miller5ecd8112013-01-09 18:50:26 -08004325 if (mKeyguardDelegate.isDismissable()) {
Daniel Sandler1ce804392012-11-07 15:07:12 -05004326 // Can we just finish the keyguard straight away?
Jim Miller5ecd8112013-01-09 18:50:26 -08004327 mKeyguardDelegate.keyguardDone(false, true);
Daniel Sandler1ce804392012-11-07 15:07:12 -05004328 } else {
4329 // ask the keyguard to prompt the user to authenticate if necessary
Jim Miller5ecd8112013-01-09 18:50:26 -08004330 mKeyguardDelegate.dismiss();
Dianne Hackborn90c52de2011-09-23 12:57:44 -07004331 }
Daniel Sandler1ce804392012-11-07 15:07:12 -05004332 }
4333 });
Dianne Hackborn90c52de2011-09-23 12:57:44 -07004334 }
4335 }
4336
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004337 void sendCloseSystemWindows() {
4338 sendCloseSystemWindows(mContext, null);
4339 }
4340
4341 void sendCloseSystemWindows(String reason) {
4342 sendCloseSystemWindows(mContext, reason);
4343 }
4344
4345 static void sendCloseSystemWindows(Context context, String reason) {
4346 if (ActivityManagerNative.isSystemReady()) {
Dianne Hackborn94a679d2009-07-28 17:51:07 -07004347 try {
4348 ActivityManagerNative.getDefault().closeSystemDialogs(reason);
4349 } catch (RemoteException e) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004350 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004351 }
4352 }
Mitsuru Oshima831d0d92009-06-16 18:27:18 -07004353
Jeff Brown01a98dd2011-09-20 15:08:29 -07004354 @Override
4355 public int rotationForOrientationLw(int orientation, int lastRotation) {
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05004356 if (false) {
4357 Slog.v(TAG, "rotationForOrientationLw(orient="
4358 + orientation + ", last=" + lastRotation
4359 + "); user=" + mUserRotation + " "
4360 + ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED)
4361 ? "USER_ROTATION_LOCKED" : "")
4362 );
4363 }
4364
Craig Mautner46ac6fa2013-08-01 10:06:34 -07004365 if (mForceDefaultOrientation) {
4366 return Surface.ROTATION_0;
4367 }
4368
The Android Open Source Project0727d222009-03-11 12:11:58 -07004369 synchronized (mLock) {
Jeff Brownc0347aa2011-09-23 17:26:09 -07004370 int sensorRotation = mOrientationListener.getProposedRotation(); // may be -1
4371 if (sensorRotation < 0) {
Jeff Brown0f862b42012-09-27 21:11:01 -07004372 sensorRotation = lastRotation;
Jeff Brownc0347aa2011-09-23 17:26:09 -07004373 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004374
Jeff Browndec6cf42011-11-15 14:08:20 -08004375 final int preferredRotation;
Jeff Brown2e7760e2012-04-11 15:14:55 -07004376 if (mLidState == LID_OPEN && mLidOpenRotation >= 0) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07004377 // Ignore sensor when lid switch is open and rotation is forced.
4378 preferredRotation = mLidOpenRotation;
4379 } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR
Jeff Brownc0347aa2011-09-23 17:26:09 -07004380 && (mCarDockEnablesAccelerometer || mCarDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07004381 // Ignore sensor when in car dock unless explicitly enabled.
4382 // This case can override the behavior of NOSENSOR, and can also
4383 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07004384 preferredRotation = mCarDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07004385 ? sensorRotation : mCarDockRotation;
Jeff Brown1a693182011-11-08 14:44:16 -08004386 } else if ((mDockMode == Intent.EXTRA_DOCK_STATE_DESK
4387 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
4388 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK)
Jeff Brownc0347aa2011-09-23 17:26:09 -07004389 && (mDeskDockEnablesAccelerometer || mDeskDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07004390 // Ignore sensor when in desk dock unless explicitly enabled.
4391 // This case can override the behavior of NOSENSOR, and can also
4392 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07004393 preferredRotation = mDeskDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07004394 ? sensorRotation : mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -07004395 } else if (mHdmiPlugged && mDemoHdmiRotationLock) {
4396 // Ignore sensor when plugged into HDMI when demo HDMI rotation lock enabled.
Jeff Browneb3e4b92011-12-06 19:54:24 -08004397 // Note that the dock orientation overrides the HDMI orientation.
Jeff Brownc82c89ed2013-04-17 17:18:15 -07004398 preferredRotation = mDemoHdmiRotation;
4399 } else if (mHdmiPlugged && mDockMode == Intent.EXTRA_DOCK_STATE_UNDOCKED
4400 && mUndockedHdmiRotation >= 0) {
4401 // Ignore sensor when plugged into HDMI and an undocked orientation has
4402 // been specified in the configuration (only for legacy devices without
4403 // full multi-display support).
4404 // Note that the dock orientation overrides the HDMI orientation.
4405 preferredRotation = mUndockedHdmiRotation;
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07004406 } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED) {
4407 // Application just wants to remain locked in the last rotation.
4408 preferredRotation = lastRotation;
Jeff Brown207673cd2012-06-05 17:47:11 -07004409 } else if ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE
Jeff Brown01a98dd2011-09-20 15:08:29 -07004410 && (orientation == ActivityInfo.SCREEN_ORIENTATION_USER
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07004411 || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
4412 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
4413 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
4414 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER))
Jeff Brown01a98dd2011-09-20 15:08:29 -07004415 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
4416 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
4417 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
4418 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) {
4419 // Otherwise, use sensor only if requested by the application or enabled
4420 // by default for USER or UNSPECIFIED modes. Does not apply to NOSENSOR.
Jeff Brownd3187e32011-09-21 19:26:44 -07004421 if (mAllowAllRotations < 0) {
4422 // Can't read this during init() because the context doesn't
4423 // have display metrics at that time so we cannot determine
4424 // tablet vs. phone then.
4425 mAllowAllRotations = mContext.getResources().getBoolean(
4426 com.android.internal.R.bool.config_allowAllRotations) ? 1 : 0;
4427 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004428 if (sensorRotation != Surface.ROTATION_180
Jeff Brownd3187e32011-09-21 19:26:44 -07004429 || mAllowAllRotations == 1
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07004430 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
4431 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07004432 preferredRotation = sensorRotation;
4433 } else {
4434 preferredRotation = lastRotation;
4435 }
Jeff Brown207673cd2012-06-05 17:47:11 -07004436 } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED
4437 && orientation != ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) {
4438 // Apply rotation lock. Does not apply to NOSENSOR.
4439 // The idea is that the user rotation expresses a weak preference for the direction
4440 // of gravity and as NOSENSOR is never affected by gravity, then neither should
4441 // NOSENSOR be affected by rotation lock (although it will be affected by docks).
Jeff Brown4dfce202011-10-05 12:00:10 -07004442 preferredRotation = mUserRotation;
Jeff Browndec6cf42011-11-15 14:08:20 -08004443 } else {
4444 // No overriding preference.
4445 // We will do exactly what the application asked us to do.
4446 preferredRotation = -1;
Jeff Brown01a98dd2011-09-20 15:08:29 -07004447 }
4448
Dianne Hackborne5439f22010-10-02 16:53:50 -07004449 switch (orientation) {
4450 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08004451 // Return portrait unless overridden.
4452 if (isAnyPortrait(preferredRotation)) {
4453 return preferredRotation;
4454 }
Dianne Hackborne5439f22010-10-02 16:53:50 -07004455 return mPortraitRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07004456
Jeff Brown01a98dd2011-09-20 15:08:29 -07004457 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08004458 // Return landscape unless overridden.
4459 if (isLandscapeOrSeascape(preferredRotation)) {
4460 return preferredRotation;
4461 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004462 return mLandscapeRotation;
4463
4464 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08004465 // Return reverse portrait unless overridden.
4466 if (isAnyPortrait(preferredRotation)) {
4467 return preferredRotation;
4468 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004469 return mUpsideDownRotation;
4470
4471 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08004472 // Return seascape unless overridden.
4473 if (isLandscapeOrSeascape(preferredRotation)) {
4474 return preferredRotation;
4475 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004476 return mSeascapeRotation;
4477
4478 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07004479 case ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE:
Jeff Brown01a98dd2011-09-20 15:08:29 -07004480 // Return either landscape rotation.
4481 if (isLandscapeOrSeascape(preferredRotation)) {
4482 return preferredRotation;
4483 }
4484 if (isLandscapeOrSeascape(lastRotation)) {
Jeff Brown4519f072011-01-23 13:16:01 -08004485 return lastRotation;
4486 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004487 return mLandscapeRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004488
Jeff Brown01a98dd2011-09-20 15:08:29 -07004489 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07004490 case ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT:
Jeff Brown01a98dd2011-09-20 15:08:29 -07004491 // Return either portrait rotation.
4492 if (isAnyPortrait(preferredRotation)) {
4493 return preferredRotation;
4494 }
4495 if (isAnyPortrait(lastRotation)) {
4496 return lastRotation;
4497 }
4498 return mPortraitRotation;
4499
4500 default:
Jeff Brown4dfce202011-10-05 12:00:10 -07004501 // For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR,
4502 // just return the preferred orientation we already calculated.
Jeff Brown01a98dd2011-09-20 15:08:29 -07004503 if (preferredRotation >= 0) {
4504 return preferredRotation;
4505 }
Dianne Hackborndacea8c2011-04-21 17:26:39 -07004506 return Surface.ROTATION_0;
Daniel Sandlere7e5ac22011-02-22 16:10:21 -05004507 }
4508 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07004509 }
4510
Jeff Brown01a98dd2011-09-20 15:08:29 -07004511 @Override
4512 public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation) {
4513 switch (orientation) {
4514 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
4515 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
4516 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
4517 return isAnyPortrait(rotation);
4518
4519 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
4520 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
4521 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
4522 return isLandscapeOrSeascape(rotation);
4523
4524 default:
4525 return true;
4526 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07004527 }
4528
Jeff Brownc0347aa2011-09-23 17:26:09 -07004529 @Override
4530 public void setRotationLw(int rotation) {
4531 mOrientationListener.setCurrentRotation(rotation);
4532 }
4533
Jeff Brown01a98dd2011-09-20 15:08:29 -07004534 private boolean isLandscapeOrSeascape(int rotation) {
4535 return rotation == mLandscapeRotation || rotation == mSeascapeRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07004536 }
4537
Jeff Brown01a98dd2011-09-20 15:08:29 -07004538 private boolean isAnyPortrait(int rotation) {
4539 return rotation == mPortraitRotation || rotation == mUpsideDownRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07004540 }
4541
Svetoslav Ganov80943d82013-01-02 10:25:37 -08004542 public int getUserRotationMode() {
4543 return Settings.System.getIntForUser(mContext.getContentResolver(),
Brett Chabot7e55c402013-05-16 19:38:08 -07004544 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
4545 WindowManagerPolicy.USER_ROTATION_FREE :
4546 WindowManagerPolicy.USER_ROTATION_LOCKED;
Svetoslav Ganov80943d82013-01-02 10:25:37 -08004547 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004548
4549 // User rotation: to be used when all else fails in assigning an orientation to the device
4550 public void setUserRotationMode(int mode, int rot) {
4551 ContentResolver res = mContext.getContentResolver();
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05004552
4553 // mUserRotationMode and mUserRotation will be assigned by the content observer
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004554 if (mode == WindowManagerPolicy.USER_ROTATION_LOCKED) {
Christopher Tate5e08af02012-09-21 17:17:22 -07004555 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004556 Settings.System.USER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07004557 rot,
4558 UserHandle.USER_CURRENT);
4559 Settings.System.putIntForUser(res,
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05004560 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07004561 0,
4562 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004563 } else {
Christopher Tate5e08af02012-09-21 17:17:22 -07004564 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004565 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07004566 1,
4567 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004568 }
4569 }
4570
Jeff Brownac143512012-04-05 18:57:33 -07004571 public void setSafeMode(boolean safeMode) {
4572 mSafeMode = safeMode;
4573 performHapticFeedbackLw(null, safeMode
4574 ? HapticFeedbackConstants.SAFE_MODE_ENABLED
4575 : HapticFeedbackConstants.SAFE_MODE_DISABLED, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004576 }
Craig Mautnereda67292013-04-28 13:50:14 -07004577
Dianne Hackborn181ceb52009-08-27 22:16:40 -07004578 static long[] getLongIntArray(Resources r, int resid) {
4579 int[] ar = r.getIntArray(resid);
4580 if (ar == null) {
4581 return null;
4582 }
4583 long[] out = new long[ar.length];
4584 for (int i=0; i<ar.length; i++) {
4585 out[i] = ar[i];
4586 }
4587 return out;
4588 }
Craig Mautnereda67292013-04-28 13:50:14 -07004589
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004590 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07004591 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004592 public void systemReady() {
Jim Miller195b5512013-02-28 03:35:57 -08004593 if (!mHeadless) {
4594 mKeyguardDelegate = new KeyguardServiceDelegate(mContext, null);
Jim Miller5ecd8112013-01-09 18:50:26 -08004595 mKeyguardDelegate.onSystemReady();
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004596 }
Dianne Hackbornb1a79802009-09-29 15:18:31 -07004597 synchronized (mLock) {
4598 updateOrientationListenerLp();
Dianne Hackbornc777e072010-02-12 13:07:59 -08004599 mSystemReady = true;
4600 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07004601 @Override
Dianne Hackbornc777e072010-02-12 13:07:59 -08004602 public void run() {
4603 updateSettings();
4604 }
4605 });
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004606 }
4607 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07004608
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07004609 /** {@inheritDoc} */
4610 public void systemBooted() {
4611 synchronized (mLock) {
4612 mSystemBooted = true;
4613 }
4614 }
4615
Dianne Hackborn661cd522011-08-22 00:26:20 -07004616 ProgressDialog mBootMsgDialog = null;
4617
4618 /** {@inheritDoc} */
4619 public void showBootMessage(final CharSequence msg, final boolean always) {
Mike Lockwoodaa5bf142011-09-21 13:03:40 -04004620 if (mHeadless) return;
Dianne Hackborn661cd522011-08-22 00:26:20 -07004621 mHandler.post(new Runnable() {
4622 @Override public void run() {
4623 if (mBootMsgDialog == null) {
Dianne Hackborn295e3c22011-08-25 13:19:08 -07004624 mBootMsgDialog = new ProgressDialog(mContext) {
4625 // This dialog will consume all events coming in to
4626 // it, to avoid it trying to do things too early in boot.
4627 @Override public boolean dispatchKeyEvent(KeyEvent event) {
4628 return true;
4629 }
4630 @Override public boolean dispatchKeyShortcutEvent(KeyEvent event) {
4631 return true;
4632 }
4633 @Override public boolean dispatchTouchEvent(MotionEvent ev) {
4634 return true;
4635 }
4636 @Override public boolean dispatchTrackballEvent(MotionEvent ev) {
4637 return true;
4638 }
4639 @Override public boolean dispatchGenericMotionEvent(MotionEvent ev) {
4640 return true;
4641 }
4642 @Override public boolean dispatchPopulateAccessibilityEvent(
4643 AccessibilityEvent event) {
4644 return true;
4645 }
4646 };
Dianne Hackborn661cd522011-08-22 00:26:20 -07004647 mBootMsgDialog.setTitle(R.string.android_upgrading_title);
4648 mBootMsgDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
4649 mBootMsgDialog.setIndeterminate(true);
4650 mBootMsgDialog.getWindow().setType(
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07004651 WindowManager.LayoutParams.TYPE_BOOT_PROGRESS);
Dianne Hackborn661cd522011-08-22 00:26:20 -07004652 mBootMsgDialog.getWindow().addFlags(
4653 WindowManager.LayoutParams.FLAG_DIM_BEHIND
4654 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
4655 mBootMsgDialog.getWindow().setDimAmount(1);
Dianne Hackbornd9efb952011-12-07 14:56:51 -08004656 WindowManager.LayoutParams lp = mBootMsgDialog.getWindow().getAttributes();
4657 lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
4658 mBootMsgDialog.getWindow().setAttributes(lp);
Dianne Hackborn661cd522011-08-22 00:26:20 -07004659 mBootMsgDialog.setCancelable(false);
4660 mBootMsgDialog.show();
4661 }
4662 mBootMsgDialog.setMessage(msg);
4663 }
4664 });
4665 }
4666
4667 /** {@inheritDoc} */
4668 public void hideBootMessages() {
4669 mHandler.post(new Runnable() {
4670 @Override public void run() {
4671 if (mBootMsgDialog != null) {
4672 mBootMsgDialog.dismiss();
4673 mBootMsgDialog = null;
4674 }
4675 }
4676 });
4677 }
4678
Mike Lockwood28569302010-01-28 11:54:40 -05004679 /** {@inheritDoc} */
4680 public void userActivity() {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004681 // ***************************************
4682 // NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
4683 // ***************************************
4684 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
4685 // WITH ITS LOCKS HELD.
4686 //
4687 // This code must be VERY careful about the locks
4688 // it acquires.
4689 // In fact, the current code acquires way too many,
4690 // and probably has lurking deadlocks.
4691
Mike Lockwood28569302010-01-28 11:54:40 -05004692 synchronized (mScreenLockTimeout) {
4693 if (mLockScreenTimerActive) {
4694 // reset the timer
4695 mHandler.removeCallbacks(mScreenLockTimeout);
4696 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
4697 }
4698 }
Daniel Sandler0601eb72011-04-13 01:01:32 -04004699 }
4700
Adam Cohenf7522022012-10-03 20:03:18 -07004701 class ScreenLockTimeout implements Runnable {
4702 Bundle options;
4703
4704 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05004705 public void run() {
4706 synchronized (this) {
4707 if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard");
Jim Miller5ecd8112013-01-09 18:50:26 -08004708 if (mKeyguardDelegate != null) {
4709 mKeyguardDelegate.doKeyguardTimeout(options);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004710 }
Mike Lockwood28569302010-01-28 11:54:40 -05004711 mLockScreenTimerActive = false;
Adam Cohenf7522022012-10-03 20:03:18 -07004712 options = null;
Mike Lockwood28569302010-01-28 11:54:40 -05004713 }
4714 }
Mike Lockwood28569302010-01-28 11:54:40 -05004715
Adam Cohenf7522022012-10-03 20:03:18 -07004716 public void setLockOptions(Bundle options) {
4717 this.options = options;
4718 }
4719 }
4720
4721 ScreenLockTimeout mScreenLockTimeout = new ScreenLockTimeout();
4722
4723 public void lockNow(Bundle options) {
Jim Miller93c518e2012-01-17 15:55:31 -08004724 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null);
4725 mHandler.removeCallbacks(mScreenLockTimeout);
Adam Cohenf7522022012-10-03 20:03:18 -07004726 if (options != null) {
4727 // In case multiple calls are made to lockNow, we don't wipe out the options
4728 // until the runnable actually executes.
4729 mScreenLockTimeout.setLockOptions(options);
4730 }
Jim Miller93c518e2012-01-17 15:55:31 -08004731 mHandler.post(mScreenLockTimeout);
4732 }
4733
Mike Lockwood28569302010-01-28 11:54:40 -05004734 private void updateLockScreenTimeout() {
4735 synchronized (mScreenLockTimeout) {
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004736 boolean enable = (mAllowLockscreenWhenOn && mScreenOnEarly &&
Jim Miller5ecd8112013-01-09 18:50:26 -08004737 mKeyguardDelegate != null && mKeyguardDelegate.isSecure());
Mike Lockwood28569302010-01-28 11:54:40 -05004738 if (mLockScreenTimerActive != enable) {
4739 if (enable) {
4740 if (localLOGV) Log.v(TAG, "setting lockscreen timer");
4741 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
4742 } else {
4743 if (localLOGV) Log.v(TAG, "clearing lockscreen timer");
4744 mHandler.removeCallbacks(mScreenLockTimeout);
4745 }
4746 mLockScreenTimerActive = enable;
4747 }
4748 }
4749 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004750
4751 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07004752 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004753 public void enableScreenAfterBoot() {
4754 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07004755 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07004756 updateRotation(true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004757 }
Dianne Hackbornf54c8f92009-09-19 14:03:57 -07004758
Jeff Brownc458ce92012-04-30 14:58:40 -07004759 private void applyLidSwitchState() {
Jeff Brownc458ce92012-04-30 14:58:40 -07004760 if (mLidState == LID_CLOSED && mLidControlsSleep) {
4761 mPowerManager.goToSleep(SystemClock.uptimeMillis());
4762 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004763 }
4764
4765 void updateRotation(boolean alwaysSendConfiguration) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004766 try {
4767 //set orientation on WindowManager
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004768 mWindowManager.updateRotation(alwaysSendConfiguration, false);
4769 } catch (RemoteException e) {
4770 // Ignore
4771 }
4772 }
4773
4774 void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) {
4775 try {
4776 //set orientation on WindowManager
4777 mWindowManager.updateRotation(alwaysSendConfiguration, forceRelayout);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004778 } catch (RemoteException e) {
4779 // Ignore
4780 }
4781 }
4782
Daniel Sandler6396c722013-04-16 20:19:09 -04004783 /**
4784 * Return an Intent to launch the currently active dock app as home. Returns
4785 * null if the standard home should be launched, which is the case if any of the following is
4786 * true:
4787 * <ul>
4788 * <li>The device is not in either car mode or desk mode
4789 * <li>The device is in car mode but ENABLE_CAR_DOCK_HOME_CAPTURE is false
4790 * <li>The device is in desk mode but ENABLE_DESK_DOCK_HOME_CAPTURE is false
4791 * <li>The device is in car mode but there's no CAR_DOCK app with METADATA_DOCK_HOME
4792 * <li>The device is in desk mode but there's no DESK_DOCK app with METADATA_DOCK_HOME
4793 * </ul>
Craig Mautnereda67292013-04-28 13:50:14 -07004794 * @return A dock intent.
Daniel Sandler6396c722013-04-16 20:19:09 -04004795 */
4796 Intent createHomeDockIntent() {
4797 Intent intent = null;
4798
4799 // What home does is based on the mode, not the dock state. That
4800 // is, when in car mode you should be taken to car home regardless
4801 // of whether we are actually in a car dock.
4802 if (mUiMode == Configuration.UI_MODE_TYPE_CAR) {
4803 if (ENABLE_CAR_DOCK_HOME_CAPTURE) {
4804 intent = mCarDockIntent;
4805 }
4806 } else if (mUiMode == Configuration.UI_MODE_TYPE_DESK) {
4807 if (ENABLE_DESK_DOCK_HOME_CAPTURE) {
4808 intent = mDeskDockIntent;
4809 }
4810 }
4811
4812 if (intent == null) {
4813 return null;
4814 }
4815
4816 ActivityInfo ai = null;
4817 ResolveInfo info = mContext.getPackageManager().resolveActivityAsUser(
4818 intent,
John Spurlockf56bef12013-07-09 09:51:46 -04004819 PackageManager.MATCH_DEFAULT_ONLY | PackageManager.GET_META_DATA,
4820 getCurrentUserId());
Daniel Sandler6396c722013-04-16 20:19:09 -04004821 if (info != null) {
4822 ai = info.activityInfo;
4823 }
4824 if (ai != null
4825 && ai.metaData != null
4826 && ai.metaData.getBoolean(Intent.METADATA_DOCK_HOME)) {
4827 intent = new Intent(intent);
4828 intent.setClassName(ai.packageName, ai.name);
4829 return intent;
4830 }
4831
4832 return null;
4833 }
4834
John Spurlockf56bef12013-07-09 09:51:46 -04004835 private int getCurrentUserId() {
4836 try {
4837 UserInfo user = ActivityManagerNative.getDefault().getCurrentUser();
4838 return user != null ? user.id : UserHandle.USER_NULL;
4839 } catch (RemoteException e) {
4840 // noop
4841 }
4842 return UserHandle.USER_NULL;
4843 }
4844
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004845 void startDockOrHome() {
John Spurlockc8b46ca2013-04-08 12:59:26 -04004846 awakenDreams();
Daniel Sandler6396c722013-04-16 20:19:09 -04004847
4848 Intent dock = createHomeDockIntent();
4849 if (dock != null) {
4850 try {
4851 mContext.startActivityAsUser(dock, UserHandle.CURRENT);
4852 return;
4853 } catch (ActivityNotFoundException e) {
4854 }
4855 }
4856
Dianne Hackbornd8883992012-09-07 15:58:52 -07004857 mContext.startActivityAsUser(mHomeIntent, UserHandle.CURRENT);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004858 }
Craig Mautnereda67292013-04-28 13:50:14 -07004859
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004860 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004861 * goes to the home screen
4862 * @return whether it did anything
4863 */
4864 boolean goHome() {
4865 if (false) {
4866 // This code always brings home to the front.
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07004867 try {
4868 ActivityManagerNative.getDefault().stopAppSwitches();
4869 } catch (RemoteException e) {
4870 }
Dianne Hackborn94a679d2009-07-28 17:51:07 -07004871 sendCloseSystemWindows();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004872 startDockOrHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004873 } else {
4874 // This code brings home to the front or, if it is already
4875 // at the front, puts the device to sleep.
4876 try {
Wink Savilled2e6a332010-02-12 12:12:06 -08004877 if (SystemProperties.getInt("persist.sys.uts-test-mode", 0) == 1) {
4878 /// Roll back EndcallBehavior as the cupcake design to pass P1 lab entry.
4879 Log.d(TAG, "UTS-TEST-MODE");
4880 } else {
4881 ActivityManagerNative.getDefault().stopAppSwitches();
4882 sendCloseSystemWindows();
Daniel Sandler6396c722013-04-16 20:19:09 -04004883 Intent dock = createHomeDockIntent();
4884 if (dock != null) {
4885 int result = ActivityManagerNative.getDefault()
4886 .startActivityAsUser(null, null, dock,
4887 dock.resolveTypeIfNeeded(mContext.getContentResolver()),
4888 null, null, 0,
4889 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
4890 null, null, null, UserHandle.USER_CURRENT);
4891 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
4892 return false;
4893 }
4894 }
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004895 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004896 int result = ActivityManagerNative.getDefault()
Dianne Hackbornf265ea92013-01-31 15:00:51 -08004897 .startActivityAsUser(null, null, mHomeIntent,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004898 mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()),
Dianne Hackborna4972e92012-03-14 10:38:05 -07004899 null, null, 0,
4900 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Dianne Hackborn5e03e2c2012-09-06 14:21:19 -07004901 null, null, null, UserHandle.USER_CURRENT);
Dianne Hackborna4972e92012-03-14 10:38:05 -07004902 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004903 return false;
4904 }
4905 } catch (RemoteException ex) {
4906 // bummer, the activity manager, which is in this process, is dead
4907 }
4908 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004909 return true;
4910 }
Craig Mautnereda67292013-04-28 13:50:14 -07004911
4912 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07004913 public void setCurrentOrientationLw(int newOrientation) {
4914 synchronized (mLock) {
4915 if (newOrientation != mCurrentAppOrientation) {
4916 mCurrentAppOrientation = newOrientation;
4917 updateOrientationListenerLp();
4918 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004919 }
4920 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08004921
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07004922 private void performAuditoryFeedbackForAccessibilityIfNeed() {
4923 if (!isGlobalAccessibilityGestureEnabled()) {
4924 return;
4925 }
4926 AudioManager audioManager = (AudioManager) mContext.getSystemService(
4927 Context.AUDIO_SERVICE);
4928 if (audioManager.isSilentMode()) {
4929 return;
4930 }
4931 Ringtone ringTone = RingtoneManager.getRingtone(mContext,
4932 Settings.System.DEFAULT_NOTIFICATION_URI);
4933 ringTone.setStreamType(AudioManager.STREAM_MUSIC);
4934 ringTone.play();
4935 }
Craig Mautnereda67292013-04-28 13:50:14 -07004936
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07004937 private boolean isGlobalAccessibilityGestureEnabled() {
4938 return Settings.Global.getInt(mContext.getContentResolver(),
4939 Settings.Global.ENABLE_ACCESSIBILITY_GLOBAL_GESTURE_ENABLED, 0) == 1;
4940 }
4941
Craig Mautnereda67292013-04-28 13:50:14 -07004942 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07004943 public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) {
Svetoslav Ganov96179212012-10-10 14:17:45 -07004944 if (!mVibrator.hasVibrator()) {
4945 return false;
4946 }
Christopher Tate5e08af02012-09-21 17:17:22 -07004947 final boolean hapticsDisabled = Settings.System.getIntForUser(mContext.getContentResolver(),
4948 Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) == 0;
Jim Miller5ecd8112013-01-09 18:50:26 -08004949 if (!always && (hapticsDisabled || mKeyguardDelegate.isShowingAndNotHidden())) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004950 return false;
4951 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08004952 long[] pattern = null;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004953 switch (effectId) {
4954 case HapticFeedbackConstants.LONG_PRESS:
Amith Yamasanic33cb712010-02-10 15:21:49 -08004955 pattern = mLongPressVibePattern;
4956 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07004957 case HapticFeedbackConstants.VIRTUAL_KEY:
Amith Yamasanic33cb712010-02-10 15:21:49 -08004958 pattern = mVirtualKeyVibePattern;
4959 break;
4960 case HapticFeedbackConstants.KEYBOARD_TAP:
4961 pattern = mKeyboardTapVibePattern;
4962 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07004963 case HapticFeedbackConstants.SAFE_MODE_DISABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08004964 pattern = mSafeModeDisabledVibePattern;
4965 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07004966 case HapticFeedbackConstants.SAFE_MODE_ENABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08004967 pattern = mSafeModeEnabledVibePattern;
4968 break;
Amith Yamasanic33cb712010-02-10 15:21:49 -08004969 default:
4970 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004971 }
Dianne Hackbornf265ea92013-01-31 15:00:51 -08004972 int owningUid;
4973 String owningPackage;
4974 if (win != null) {
4975 owningUid = win.getOwningUid();
4976 owningPackage = win.getOwningPackage();
4977 } else {
4978 owningUid = android.os.Process.myUid();
4979 owningPackage = mContext.getBasePackageName();
4980 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08004981 if (pattern.length == 1) {
4982 // One-shot vibration
Dianne Hackbornf265ea92013-01-31 15:00:51 -08004983 mVibrator.vibrate(owningUid, owningPackage, pattern[0]);
Amith Yamasanic33cb712010-02-10 15:21:49 -08004984 } else {
4985 // Pattern vibration
Dianne Hackbornf265ea92013-01-31 15:00:51 -08004986 mVibrator.vibrate(owningUid, owningPackage, pattern, -1);
Amith Yamasanic33cb712010-02-10 15:21:49 -08004987 }
4988 return true;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004989 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07004990
4991 @Override
4992 public void keepScreenOnStartedLw() {
Daniel Sandler0601eb72011-04-13 01:01:32 -04004993 }
4994
Jeff Brownc38c9be2012-10-04 13:16:19 -07004995 @Override
4996 public void keepScreenOnStoppedLw() {
Jim Miller5ecd8112013-01-09 18:50:26 -08004997 if (mKeyguardDelegate != null && !mKeyguardDelegate.isShowingAndNotHidden()) {
Jeff Brownc38c9be2012-10-04 13:16:19 -07004998 long curTime = SystemClock.uptimeMillis();
Jim Miller25190572013-02-28 17:36:24 -08004999 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005000 }
5001 }
Mike Lockwoodfcb39242009-10-21 23:01:07 -04005002
Dianne Hackborndf89e652011-10-06 22:35:11 -07005003 private int updateSystemUiVisibilityLw() {
Joe Onorato664644d2011-01-23 17:53:23 -08005004 // If there is no window focused, there will be nobody to handle the events
5005 // anyway, so just hang on in whatever state we're in until things settle down.
Dianne Hackborndf89e652011-10-06 22:35:11 -07005006 if (mFocusedWindow == null) {
5007 return 0;
5008 }
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07005009 if (mFocusedWindow.getAttrs().type == TYPE_KEYGUARD && mHideLockScreen == true) {
5010 // We are updating at a point where the keyguard has gotten
5011 // focus, but we were last in a state where the top window is
5012 // hiding it. This is probably because the keyguard as been
5013 // shown while the top window was displayed, so we want to ignore
5014 // it here because this is just a very transient change and it
5015 // will quickly lose focus once it correctly gets hidden.
5016 return 0;
5017 }
John Spurlock32beb2c2013-03-11 10:16:47 -04005018
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08005019 int tmpVisibility = mFocusedWindow.getSystemUiVisibility()
Dianne Hackborne26ab702011-10-16 13:21:33 -07005020 & ~mResettingSystemUiFlags
5021 & ~mForceClearedSystemUiFlags;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08005022 if (mForcingShowNavBar && mFocusedWindow.getSurfaceLayer() < mForcingShowNavBarLayer) {
5023 tmpVisibility &= ~View.SYSTEM_UI_CLEARABLE_FLAGS;
5024 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04005025 final int visibility = updateHideybarsLw(tmpVisibility);
5026 final int diff = visibility ^ mLastSystemUiFlags;
Dianne Hackborn73ab6a42011-12-13 11:16:23 -08005027 final boolean needsMenu = mFocusedWindow.getNeedsMenuLw(mTopFullscreenOpaqueWindowState);
Dianne Hackborne0f085d2011-11-30 18:41:15 -08005028 if (diff == 0 && mLastFocusNeedsMenu == needsMenu
5029 && mFocusedApp == mFocusedWindow.getAppToken()) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07005030 return 0;
5031 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07005032 mLastSystemUiFlags = visibility;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08005033 mLastFocusNeedsMenu = needsMenu;
Dianne Hackborne0f085d2011-11-30 18:41:15 -08005034 mFocusedApp = mFocusedWindow.getAppToken();
Dianne Hackborndf89e652011-10-06 22:35:11 -07005035 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07005036 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07005037 public void run() {
Dianne Hackborn42e620c2012-06-24 13:20:51 -07005038 try {
5039 IStatusBarService statusbar = getStatusBarService();
5040 if (statusbar != null) {
5041 statusbar.setSystemUiVisibility(visibility, 0xffffffff);
5042 statusbar.topAppWindowChanged(needsMenu);
Joe Onorato664644d2011-01-23 17:53:23 -08005043 }
Dianne Hackborn42e620c2012-06-24 13:20:51 -07005044 } catch (RemoteException e) {
5045 // re-acquire status bar service next time it is needed.
5046 mStatusBarService = null;
Joe Onorato664644d2011-01-23 17:53:23 -08005047 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07005048 }
5049 });
5050 return diff;
Joe Onorato664644d2011-01-23 17:53:23 -08005051 }
5052
John Spurlockad3e6cb2013-04-30 08:47:43 -04005053 private int updateHideybarsLw(int tmpVisibility) {
John Spurlock245fd012013-05-31 10:31:04 -04005054 if (OverlayTesting.enabled) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04005055 tmpVisibility = OverlayTesting.applyForced(mFocusedWindow, tmpVisibility);
5056 }
5057 boolean statusBarHasFocus =
5058 mFocusedWindow.getAttrs().type == TYPE_STATUS_BAR;
5059 if (statusBarHasFocus) {
5060 // prevent status bar interaction from clearing certain flags
5061 int flags = View.SYSTEM_UI_FLAG_FULLSCREEN
5062 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
5063 | View.SYSTEM_UI_FLAG_ALLOW_OVERLAY;
5064 tmpVisibility = (tmpVisibility & ~flags) | (mLastSystemUiFlags & flags);
5065 }
5066 boolean overlayAllowed = (tmpVisibility & View.SYSTEM_UI_FLAG_ALLOW_OVERLAY) != 0;
5067 if (mStatusHideybar == HIDEYBAR_SHOWING) {
5068 // status hideybar requested
5069 boolean hideStatusBarWM =
5070 (mFocusedWindow.getAttrs().flags
5071 & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0;
5072 boolean hideStatusBarSysui =
5073 (tmpVisibility & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
5074
5075 boolean statusHideyAllowed =
5076 hideStatusBarWM
5077 || (hideStatusBarSysui && overlayAllowed)
5078 || statusBarHasFocus;
5079
John Spurlock04db1762013-05-13 12:46:41 -04005080 if (mStatusBar == null || !statusHideyAllowed) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04005081 mStatusHideybar = HIDEYBAR_NONE;
John Spurlock04db1762013-05-13 12:46:41 -04005082 if (mStatusBar != null && hideStatusBarSysui) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04005083 // clear the clearable flags instead
5084 int newVal = mResettingSystemUiFlags | View.SYSTEM_UI_CLEARABLE_FLAGS;
5085 if (newVal != mResettingSystemUiFlags) {
5086 mResettingSystemUiFlags = newVal;
5087 mWindowManagerFuncs.reevaluateStatusBarVisibility();
5088 }
5089 }
5090 } else {
5091 // show status hideybar
5092 tmpVisibility |= View.STATUS_BAR_OVERLAY;
5093 if ((mLastSystemUiFlags & View.STATUS_BAR_OVERLAY) == 0) {
John Spurlockd85618e2013-05-28 14:58:50 -04005094 tmpVisibility &= ~View.SYSTEM_UI_FLAG_LOW_PROFILE;
John Spurlockad3e6cb2013-04-30 08:47:43 -04005095 mStatusBar.showLw(true);
5096 }
5097 }
5098 }
5099 if (mNavigationHideybar == HIDEYBAR_SHOWING) {
5100 // navigation hideybar requested
5101 boolean hideNavigationBarSysui =
5102 (tmpVisibility & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0;
5103 boolean navigationHideyAllowed =
John Spurlocke3b642e2013-05-09 15:51:32 -04005104 hideNavigationBarSysui && overlayAllowed && mNavigationBar != null;
John Spurlockad3e6cb2013-04-30 08:47:43 -04005105 if (!navigationHideyAllowed) {
5106 mNavigationHideybar = HIDEYBAR_NONE;
5107 } else {
5108 // show navigation hideybar
5109 tmpVisibility |= View.NAVIGATION_BAR_OVERLAY;
5110 if ((mLastSystemUiFlags & View.NAVIGATION_BAR_OVERLAY) == 0) {
John Spurlockd85618e2013-05-28 14:58:50 -04005111 tmpVisibility &= ~View.SYSTEM_UI_FLAG_LOW_PROFILE;
John Spurlockad3e6cb2013-04-30 08:47:43 -04005112 mNavigationBar.showLw(true);
5113 }
5114 }
5115 }
5116 return tmpVisibility;
5117 }
5118
5119 // TODO temporary helper that allows testing overlay bars on existing apps
5120 private static final class OverlayTesting {
John Spurlock245fd012013-05-31 10:31:04 -04005121 static String ENABLED_SETTING = "overlay_testing_enabled";
5122 static boolean enabled = false;
John Spurlockad3e6cb2013-04-30 08:47:43 -04005123 private static final HashSet<String> sForced = new HashSet<String>();
5124
5125 private static String parseActivity(WindowState win) {
5126 if (win != null && win.getAppToken() != null) {
5127 String str = win.getAppToken().toString();
5128 int end = str.lastIndexOf(' ');
5129 if (end > 0) {
5130 int start = str.lastIndexOf(' ', end - 1);
5131 if (start > -1) {
5132 return str.substring(start + 1, end);
5133 }
5134 }
5135 }
5136 return null;
5137 }
5138
5139 public static int applyForced(WindowState focused, int vis) {
5140 if (sForced.contains(parseActivity(focused))) {
5141 vis |= View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
5142 View.SYSTEM_UI_FLAG_FULLSCREEN |
5143 View.SYSTEM_UI_FLAG_ALLOW_OVERLAY;
5144 }
5145 return vis;
5146 }
5147
5148 public static void toggleForceOverlay(WindowState focused, Context context) {
5149 String activity = parseActivity(focused);
5150 if (activity != null) {
5151 String action;
5152 if (sForced.contains(activity)) {
5153 sForced.remove(activity);
5154 action = "Force overlay disabled";
5155 } else {
5156 sForced.add(activity);
5157 action = "Force overlay enabled";
5158 }
5159 android.widget.Toast.makeText(context,
5160 action + " for " + activity, android.widget.Toast.LENGTH_SHORT).show();
5161 }
5162 }
5163 }
5164
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04005165 // Use this instead of checking config_showNavigationBar so that it can be consistently
5166 // overridden by qemu.hw.mainkeys in the emulator.
Craig Mautnereda67292013-04-28 13:50:14 -07005167 @Override
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04005168 public boolean hasNavigationBar() {
5169 return mHasNavigationBar;
5170 }
5171
satok1bc0a492012-04-25 22:47:12 +09005172 @Override
5173 public void setLastInputMethodWindowLw(WindowState ime, WindowState target) {
5174 mLastInputMethodWindow = ime;
5175 mLastInputMethodTargetWindow = target;
5176 }
5177
Craig Mautnerf1b67412012-09-19 13:18:29 -07005178 @Override
Craig Mautnerf1b67412012-09-19 13:18:29 -07005179 public void setCurrentUserLw(int newUserId) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005180 if (mKeyguardDelegate != null) {
5181 mKeyguardDelegate.setCurrentUser(newUserId);
Craig Mautnerf1b67412012-09-19 13:18:29 -07005182 }
John Spurlock13451a22012-09-28 14:40:41 -04005183 if (mStatusBarService != null) {
5184 try {
5185 mStatusBarService.setCurrentUser(newUserId);
5186 } catch (RemoteException e) {
5187 // oh well
5188 }
5189 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07005190 setLastInputMethodWindowLw(null, null);
Craig Mautnerf1b67412012-09-19 13:18:29 -07005191 }
5192
5193 @Override
Jim Miller4eeb4f62012-11-08 00:04:29 -08005194 public void showAssistant() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005195 mKeyguardDelegate.showAssistant();
Jim Miller4eeb4f62012-11-08 00:04:29 -08005196 }
5197
Svetoslav Ganov545252f2012-12-10 18:29:24 -08005198 @Override
5199 public boolean canMagnifyWindow(int windowType) {
5200 switch (windowType) {
5201 case WindowManager.LayoutParams.TYPE_INPUT_METHOD:
5202 case WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG:
5203 case WindowManager.LayoutParams.TYPE_NAVIGATION_BAR:
5204 case WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY: {
5205 return false;
5206 }
5207 }
5208 return true;
5209 }
5210
5211 @Override
5212 public boolean isTopLevelWindow(int windowType) {
5213 if (windowType >= WindowManager.LayoutParams.FIRST_SUB_WINDOW
5214 && windowType <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
5215 return (windowType == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG);
5216 }
5217 return true;
5218 }
5219
Jim Miller4eeb4f62012-11-08 00:04:29 -08005220 @Override
Jeff Brownd7a04de2012-06-17 14:17:52 -07005221 public void dump(String prefix, PrintWriter pw, String[] args) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005222 pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005223 pw.print(" mSystemReady="); pw.print(mSystemReady);
5224 pw.print(" mSystemBooted="); pw.println(mSystemBooted);
Jeff Brown2e7760e2012-04-11 15:14:55 -07005225 pw.print(prefix); pw.print("mLidState="); pw.print(mLidState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005226 pw.print(" mLidOpenRotation="); pw.print(mLidOpenRotation);
5227 pw.print(" mHdmiPlugged="); pw.println(mHdmiPlugged);
Dianne Hackborne26ab702011-10-16 13:21:33 -07005228 if (mLastSystemUiFlags != 0 || mResettingSystemUiFlags != 0
5229 || mForceClearedSystemUiFlags != 0) {
5230 pw.print(prefix); pw.print("mLastSystemUiFlags=0x");
5231 pw.print(Integer.toHexString(mLastSystemUiFlags));
5232 pw.print(" mResettingSystemUiFlags=0x");
5233 pw.print(Integer.toHexString(mResettingSystemUiFlags));
5234 pw.print(" mForceClearedSystemUiFlags=0x");
5235 pw.println(Integer.toHexString(mForceClearedSystemUiFlags));
Dianne Hackborndf89e652011-10-06 22:35:11 -07005236 }
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08005237 if (mLastFocusNeedsMenu) {
5238 pw.print(prefix); pw.print("mLastFocusNeedsMenu=");
5239 pw.println(mLastFocusNeedsMenu);
5240 }
Daniel Sandler6396c722013-04-16 20:19:09 -04005241 pw.print(prefix); pw.print("mUiMode="); pw.print(mUiMode);
5242 pw.print(" mDockMode="); pw.print(mDockMode);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005243 pw.print(" mCarDockRotation="); pw.print(mCarDockRotation);
5244 pw.print(" mDeskDockRotation="); pw.println(mDeskDockRotation);
5245 pw.print(prefix); pw.print("mUserRotationMode="); pw.print(mUserRotationMode);
5246 pw.print(" mUserRotation="); pw.print(mUserRotation);
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005247 pw.print(" mAllowAllRotations="); pw.println(mAllowAllRotations);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07005248 pw.print(prefix); pw.print("mCurrentAppOrientation="); pw.println(mCurrentAppOrientation);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005249 pw.print(prefix); pw.print("mCarDockEnablesAccelerometer=");
5250 pw.print(mCarDockEnablesAccelerometer);
5251 pw.print(" mDeskDockEnablesAccelerometer=");
5252 pw.println(mDeskDockEnablesAccelerometer);
5253 pw.print(prefix); pw.print("mLidKeyboardAccessibility=");
5254 pw.print(mLidKeyboardAccessibility);
5255 pw.print(" mLidNavigationAccessibility="); pw.print(mLidNavigationAccessibility);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07005256 pw.print(" mLidControlsSleep="); pw.println(mLidControlsSleep);
5257 pw.print(prefix); pw.print("mLongPressOnPowerBehavior=");
5258 pw.print(mLongPressOnPowerBehavior);
5259 pw.print(" mHasSoftInput="); pw.println(mHasSoftInput);
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07005260 pw.print(prefix); pw.print("mScreenOnEarly="); pw.print(mScreenOnEarly);
5261 pw.print(" mScreenOnFully="); pw.print(mScreenOnFully);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07005262 pw.print(" mOrientationSensorEnabled="); pw.println(mOrientationSensorEnabled);
Dianne Hackbornc652de82013-02-15 16:32:56 -08005263 pw.print(prefix); pw.print("mOverscanScreen=("); pw.print(mOverscanScreenLeft);
5264 pw.print(","); pw.print(mOverscanScreenTop);
5265 pw.print(") "); pw.print(mOverscanScreenWidth);
5266 pw.print("x"); pw.println(mOverscanScreenHeight);
5267 if (mOverscanLeft != 0 || mOverscanTop != 0
5268 || mOverscanRight != 0 || mOverscanBottom != 0) {
5269 pw.print(prefix); pw.print("mOverscan left="); pw.print(mOverscanLeft);
5270 pw.print(" top="); pw.print(mOverscanTop);
5271 pw.print(" right="); pw.print(mOverscanRight);
5272 pw.print(" bottom="); pw.println(mOverscanBottom);
5273 }
Dianne Hackborn313440842013-02-19 19:22:59 -08005274 pw.print(prefix); pw.print("mRestrictedOverscanScreen=(");
5275 pw.print(mRestrictedOverscanScreenLeft);
5276 pw.print(","); pw.print(mRestrictedOverscanScreenTop);
5277 pw.print(") "); pw.print(mRestrictedOverscanScreenWidth);
5278 pw.print("x"); pw.println(mRestrictedOverscanScreenHeight);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005279 pw.print(prefix); pw.print("mUnrestrictedScreen=("); pw.print(mUnrestrictedScreenLeft);
5280 pw.print(","); pw.print(mUnrestrictedScreenTop);
5281 pw.print(") "); pw.print(mUnrestrictedScreenWidth);
5282 pw.print("x"); pw.println(mUnrestrictedScreenHeight);
5283 pw.print(prefix); pw.print("mRestrictedScreen=("); pw.print(mRestrictedScreenLeft);
5284 pw.print(","); pw.print(mRestrictedScreenTop);
5285 pw.print(") "); pw.print(mRestrictedScreenWidth);
5286 pw.print("x"); pw.println(mRestrictedScreenHeight);
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07005287 pw.print(prefix); pw.print("mStableFullscreen=("); pw.print(mStableFullscreenLeft);
5288 pw.print(","); pw.print(mStableFullscreenTop);
5289 pw.print(")-("); pw.print(mStableFullscreenRight);
5290 pw.print(","); pw.print(mStableFullscreenBottom); pw.println(")");
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07005291 pw.print(prefix); pw.print("mStable=("); pw.print(mStableLeft);
5292 pw.print(","); pw.print(mStableTop);
5293 pw.print(")-("); pw.print(mStableRight);
5294 pw.print(","); pw.print(mStableBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07005295 pw.print(prefix); pw.print("mSystem=("); pw.print(mSystemLeft);
5296 pw.print(","); pw.print(mSystemTop);
5297 pw.print(")-("); pw.print(mSystemRight);
5298 pw.print(","); pw.print(mSystemBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005299 pw.print(prefix); pw.print("mCur=("); pw.print(mCurLeft);
5300 pw.print(","); pw.print(mCurTop);
5301 pw.print(")-("); pw.print(mCurRight);
5302 pw.print(","); pw.print(mCurBottom); pw.println(")");
5303 pw.print(prefix); pw.print("mContent=("); pw.print(mContentLeft);
5304 pw.print(","); pw.print(mContentTop);
5305 pw.print(")-("); pw.print(mContentRight);
5306 pw.print(","); pw.print(mContentBottom); pw.println(")");
5307 pw.print(prefix); pw.print("mDock=("); pw.print(mDockLeft);
5308 pw.print(","); pw.print(mDockTop);
5309 pw.print(")-("); pw.print(mDockRight);
5310 pw.print(","); pw.print(mDockBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07005311 pw.print(prefix); pw.print("mDockLayer="); pw.print(mDockLayer);
5312 pw.print(" mStatusBarLayer="); pw.println(mStatusBarLayer);
Dianne Hackborn7ad44382012-10-18 17:46:00 -07005313 pw.print(prefix); pw.print("mShowingLockscreen="); pw.print(mShowingLockscreen);
5314 pw.print(" mShowingDream="); pw.print(mShowingDream);
5315 pw.print(" mDreamingLockscreen="); pw.println(mDreamingLockscreen);
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07005316 if (mLastInputMethodWindow != null) {
5317 pw.print(prefix); pw.print("mLastInputMethodWindow=");
5318 pw.println(mLastInputMethodWindow);
5319 }
5320 if (mLastInputMethodTargetWindow != null) {
5321 pw.print(prefix); pw.print("mLastInputMethodTargetWindow=");
5322 pw.println(mLastInputMethodTargetWindow);
5323 }
5324 if (mStatusBar != null) {
5325 pw.print(prefix); pw.print("mStatusBar=");
5326 pw.println(mStatusBar);
5327 }
5328 if (mNavigationBar != null) {
5329 pw.print(prefix); pw.print("mNavigationBar=");
5330 pw.println(mNavigationBar);
5331 }
5332 if (mKeyguard != null) {
5333 pw.print(prefix); pw.print("mKeyguard=");
5334 pw.println(mKeyguard);
5335 }
5336 if (mFocusedWindow != null) {
5337 pw.print(prefix); pw.print("mFocusedWindow=");
5338 pw.println(mFocusedWindow);
5339 }
5340 if (mFocusedApp != null) {
5341 pw.print(prefix); pw.print("mFocusedApp=");
5342 pw.println(mFocusedApp);
5343 }
5344 if (mWinDismissingKeyguard != null) {
5345 pw.print(prefix); pw.print("mWinDismissingKeyguard=");
5346 pw.println(mWinDismissingKeyguard);
5347 }
5348 if (mTopFullscreenOpaqueWindowState != null) {
5349 pw.print(prefix); pw.print("mTopFullscreenOpaqueWindowState=");
5350 pw.println(mTopFullscreenOpaqueWindowState);
5351 }
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08005352 if (mForcingShowNavBar) {
5353 pw.print(prefix); pw.print("mForcingShowNavBar=");
5354 pw.println(mForcingShowNavBar); pw.print( "mForcingShowNavBarLayer=");
5355 pw.println(mForcingShowNavBarLayer);
5356 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07005357 pw.print(prefix); pw.print("mTopIsFullscreen="); pw.print(mTopIsFullscreen);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005358 pw.print(" mHideLockScreen="); pw.println(mHideLockScreen);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07005359 pw.print(prefix); pw.print("mForceStatusBar="); pw.print(mForceStatusBar);
5360 pw.print(" mForceStatusBarFromKeyguard=");
5361 pw.println(mForceStatusBarFromKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005362 pw.print(prefix); pw.print("mDismissKeyguard="); pw.print(mDismissKeyguard);
Craig Mautnerad09bcc2012-10-08 13:33:11 -07005363 pw.print(" mWinDismissingKeyguard="); pw.print(mWinDismissingKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005364 pw.print(" mHomePressed="); pw.println(mHomePressed);
5365 pw.print(prefix); pw.print("mAllowLockscreenWhenOn="); pw.print(mAllowLockscreenWhenOn);
5366 pw.print(" mLockScreenTimeout="); pw.print(mLockScreenTimeout);
5367 pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive);
5368 pw.print(prefix); pw.print("mEndcallBehavior="); pw.print(mEndcallBehavior);
5369 pw.print(" mIncallPowerBehavior="); pw.print(mIncallPowerBehavior);
5370 pw.print(" mLongPressOnHomeBehavior="); pw.println(mLongPressOnHomeBehavior);
5371 pw.print(prefix); pw.print("mLandscapeRotation="); pw.print(mLandscapeRotation);
5372 pw.print(" mSeascapeRotation="); pw.println(mSeascapeRotation);
5373 pw.print(prefix); pw.print("mPortraitRotation="); pw.print(mPortraitRotation);
5374 pw.print(" mUpsideDownRotation="); pw.println(mUpsideDownRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07005375 pw.print(prefix); pw.print("mDemoHdmiRotation="); pw.print(mDemoHdmiRotation);
5376 pw.print(" mDemoHdmiRotationLock="); pw.println(mDemoHdmiRotationLock);
5377 pw.print(prefix); pw.print("mUndockedHdmiRotation="); pw.println(mUndockedHdmiRotation);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005378 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005379}