blob: 8bc669ac0cb0f2f24f757b034aacc1d8d48765c3 [file] [log] [blame]
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001/*
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16package com.android.internal.policy.impl;
17
Dianne Hackborna4972e92012-03-14 10:38:05 -070018import android.app.ActivityManager;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080019import android.app.ActivityManagerNative;
Dianne Hackbornc2293022013-02-06 23:14:49 -080020import android.app.AppOpsManager;
Daniel Sandler6396c722013-04-16 20:19:09 -040021import android.app.IUiModeManager;
Dianne Hackborn661cd522011-08-22 00:26:20 -070022import android.app.ProgressDialog;
Jeff Brownde7a8ea2012-06-13 18:28:57 -070023import android.app.SearchManager;
John Spurlock97642182013-07-29 17:58:39 -040024import android.app.StatusBarManager;
Dianne Hackborn78968392010-03-04 20:47:56 -080025import android.app.UiModeManager;
Dianne Hackborn39c2d712009-09-22 11:41:31 -070026import android.content.ActivityNotFoundException;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080027import android.content.BroadcastReceiver;
Daniel Sandler0601eb72011-04-13 01:01:32 -040028import android.content.ComponentName;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080029import android.content.ContentResolver;
30import android.content.Context;
31import android.content.Intent;
Mike Lockwood1753f7f2009-08-24 14:49:07 -070032import android.content.IntentFilter;
Winson Chung9112ec32011-06-27 13:15:32 -070033import android.content.ServiceConnection;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080034import android.content.pm.ActivityInfo;
35import android.content.pm.PackageManager;
Daniel Sandler6396c722013-04-16 20:19:09 -040036import android.content.pm.ResolveInfo;
Dianne Hackborn2f0b1752011-05-31 17:59:49 -070037import android.content.res.CompatibilityInfo;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080038import android.content.res.Configuration;
39import android.content.res.Resources;
Craig Mautner8e4df6c2012-05-23 16:57:23 -070040import android.content.res.TypedArray;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080041import android.database.ContentObserver;
Dianne Hackbornc777e072010-02-12 13:07:59 -080042import android.graphics.PixelFormat;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080043import android.graphics.Rect;
Michael Jurka7a348952012-02-27 13:07:58 -080044import android.media.AudioManager;
Jean-Michel Trivifca1e602013-10-10 18:12:59 -070045import android.media.AudioSystem;
Michael Jurka7a348952012-02-27 13:07:58 -080046import android.media.IAudioService;
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -070047import android.media.Ringtone;
48import android.media.RingtoneManager;
Dianne Hackborn38e29a62011-09-18 14:43:08 -070049import android.os.Bundle;
Jeff Brown9a538ee2012-08-20 14:56:57 -070050import android.os.FactoryTest;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080051import android.os.Handler;
52import android.os.IBinder;
Dianne Hackborn38e29a62011-09-18 14:43:08 -070053import android.os.IRemoteCallback;
Jeff Brown32cbc38552011-12-01 14:01:49 -080054import android.os.Looper;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -070055import android.os.Message;
56import android.os.Messenger;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080057import android.os.PowerManager;
58import android.os.RemoteException;
59import android.os.ServiceManager;
60import android.os.SystemClock;
61import android.os.SystemProperties;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -080062import android.os.UEventObserver;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -070063import android.os.UserHandle;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080064import android.os.Vibrator;
65import android.provider.Settings;
John Spurlockc8b46ca2013-04-08 12:59:26 -040066import android.service.dreams.DreamService;
67import android.service.dreams.IDreamManager;
Dianne Hackborn81e56d52011-05-26 00:55:58 -070068import android.util.DisplayMetrics;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080069import android.util.EventLog;
70import android.util.Log;
Jeff Browna41ca772010-08-11 14:46:32 -070071import android.util.Slog;
Jeff Brown6651a632011-11-28 12:59:11 -080072import android.util.SparseArray;
Dianne Hackbornf87d1962012-04-04 12:48:24 -070073import android.view.Display;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080074import android.view.Gravity;
75import android.view.HapticFeedbackConstants;
Dianne Hackborne0f085d2011-11-30 18:41:15 -080076import android.view.IApplicationToken;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080077import android.view.IWindowManager;
Jeff Browna41ca772010-08-11 14:46:32 -070078import android.view.InputChannel;
Jeff Brown4d396052010-10-29 21:50:21 -070079import android.view.InputDevice;
Jeff Brown4952dfd2011-11-30 19:23:22 -080080import android.view.InputEvent;
Jeff Brown32cbc38552011-12-01 14:01:49 -080081import android.view.InputEventReceiver;
Jeff Brown6b53e8d2010-11-10 16:03:06 -080082import android.view.KeyCharacterMap;
Craig Mautnerae446592012-12-06 19:05:05 -080083import android.view.KeyCharacterMap.FallbackAction;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080084import android.view.KeyEvent;
85import android.view.MotionEvent;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080086import android.view.Surface;
87import android.view.View;
88import android.view.ViewConfiguration;
89import android.view.Window;
90import android.view.WindowManager;
Craig Mautnerae446592012-12-06 19:05:05 -080091import android.view.WindowManagerGlobal;
92import android.view.WindowManagerPolicy;
Craig Mautnerae446592012-12-06 19:05:05 -080093import android.view.accessibility.AccessibilityEvent;
Svetoslav8e3feb12014-02-24 13:46:47 -080094import android.view.accessibility.AccessibilityManager;
Craig Mautnerae446592012-12-06 19:05:05 -080095import android.view.animation.Animation;
96import android.view.animation.AnimationUtils;
97
98import com.android.internal.R;
Jorim Jaggi380ecb82014-03-14 17:25:20 +010099import com.android.internal.policy.IKeyguardService;
100import com.android.internal.policy.IKeyguardServiceConstants;
Craig Mautnerae446592012-12-06 19:05:05 -0800101import com.android.internal.policy.PolicyManager;
Jim Miller5ecd8112013-01-09 18:50:26 -0800102import com.android.internal.policy.impl.keyguard.KeyguardServiceDelegate;
Craig Mautnerae446592012-12-06 19:05:05 -0800103import com.android.internal.statusbar.IStatusBarService;
104import com.android.internal.telephony.ITelephony;
105import com.android.internal.widget.PointerLocationView;
106
107import java.io.File;
108import java.io.FileReader;
109import java.io.IOException;
110import java.io.PrintWriter;
Craig Mautner2bc789b2014-03-19 19:48:38 -0700111import java.util.HashSet;
Craig Mautnerae446592012-12-06 19:05:05 -0800112
Dianne Hackbornc652de82013-02-15 16:32:56 -0800113import static android.view.WindowManager.LayoutParams.*;
Jeff Brownac143512012-04-05 18:57:33 -0700114import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_ABSENT;
115import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_OPEN;
116import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_CLOSED;
Dianne Hackborn08743722009-12-21 12:16:51 -0800117
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800118/**
The Android Open Source Project0727d222009-03-11 12:11:58 -0700119 * WindowManagerPolicy implementation for the Android phone UI. This
120 * introduces a new method suffix, Lp, for an internal lock of the
121 * PhoneWindowManager. This is used to protect some internal state, and
John Spurlock04db1762013-05-13 12:46:41 -0400122 * 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 -0700123 * of both of those when held.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800124 */
125public class PhoneWindowManager implements WindowManagerPolicy {
126 static final String TAG = "WindowManager";
127 static final boolean DEBUG = false;
Joe Onorato43a17652011-04-06 19:22:23 -0700128 static final boolean localLOGV = false;
The Android Open Source Project11267662009-03-18 17:39:47 -0700129 static final boolean DEBUG_LAYOUT = false;
Jeff Brown40013652012-05-16 21:22:36 -0700130 static final boolean DEBUG_INPUT = false;
Craig Mautner6fbda632012-07-03 09:26:39 -0700131 static final boolean DEBUG_STARTING_WINDOW = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800132 static final boolean SHOW_STARTING_ANIMATIONS = true;
133 static final boolean SHOW_PROCESSES_ON_ALT_MENU = false;
Joe Onoratod208e702010-10-08 16:22:43 -0400134
Daniel Sandler6396c722013-04-16 20:19:09 -0400135 // Whether to allow dock apps with METADATA_DOCK_HOME to temporarily take over the Home key.
136 // No longer recommended for desk docks; still useful in car docks.
137 static final boolean ENABLE_CAR_DOCK_HOME_CAPTURE = true;
138 static final boolean ENABLE_DESK_DOCK_HOME_CAPTURE = false;
139
Joe Onoratod208e702010-10-08 16:22:43 -0400140 static final int LONG_PRESS_POWER_NOTHING = 0;
141 static final int LONG_PRESS_POWER_GLOBAL_ACTIONS = 1;
142 static final int LONG_PRESS_POWER_SHUT_OFF = 2;
Jeff Brown9a538ee2012-08-20 14:56:57 -0700143 static final int LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM = 3;
Michael Jurka3b1fc472011-06-13 10:54:40 -0700144
145 // These need to match the documentation/constant in
146 // core/res/res/values/config.xml
Joe Onorato46b0d682010-11-22 17:37:27 -0800147 static final int LONG_PRESS_HOME_NOTHING = 0;
Michael Wrightc9ebea72013-01-16 19:25:02 -0800148 static final int LONG_PRESS_HOME_RECENT_SYSTEM_UI = 1;
Jeff Browncaca8812013-05-09 13:34:33 -0700149 static final int LONG_PRESS_HOME_ASSIST = 2;
150
151 static final int DOUBLE_TAP_HOME_NOTHING = 0;
152 static final int DOUBLE_TAP_HOME_RECENT_SYSTEM_UI = 1;
Joe Onorato46b0d682010-11-22 17:37:27 -0800153
Dianne Hackborn5cb8d792009-05-21 17:34:15 -0700154 static final int APPLICATION_MEDIA_SUBLAYER = -2;
155 static final int APPLICATION_MEDIA_OVERLAY_SUBLAYER = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800156 static final int APPLICATION_PANEL_SUBLAYER = 1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800157 static final int APPLICATION_SUB_PANEL_SUBLAYER = 2;
Craig Mautner88400d32012-09-30 12:35:45 -0700158
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800159 static public final String SYSTEM_DIALOG_REASON_KEY = "reason";
160 static public final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions";
161 static public final String SYSTEM_DIALOG_REASON_RECENT_APPS = "recentapps";
Joe Onoratof275f0c2009-11-24 16:11:13 -0500162 static public final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey";
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700163 static public final String SYSTEM_DIALOG_REASON_ASSIST = "assist";
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800164
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700165 /**
166 * These are the system UI flags that, when changing, can cause the layout
167 * of the screen to change.
168 */
169 static final int SYSTEM_UI_CHANGING_LAYOUT =
John Spurlocke1f366f2013-08-05 12:22:40 -0400170 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlock7f4820a2013-10-08 12:54:35 -0400171 | View.SYSTEM_UI_FLAG_FULLSCREEN
172 | View.STATUS_BAR_TRANSLUCENT
173 | View.NAVIGATION_BAR_TRANSLUCENT;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700174
Jim Miller5ecd8112013-01-09 18:50:26 -0800175 /**
176 * Keyguard stuff
177 */
178 private WindowState mKeyguardScrim;
Jorim Jaggi380ecb82014-03-14 17:25:20 +0100179 private boolean mKeyguardHidden;
Jorim Jaggicff0acb2014-03-31 16:35:15 +0200180 private boolean mKeyguardDrawn;
Jim Miller5ecd8112013-01-09 18:50:26 -0800181
Jeff Brown6651a632011-11-28 12:59:11 -0800182 /* Table of Application Launch keys. Maps from key codes to intent categories.
183 *
184 * These are special keys that are used to launch particular kinds of applications,
185 * such as a web browser. HID defines nearly a hundred of them in the Consumer (0x0C)
186 * usage page. We don't support quite that many yet...
187 */
188 static SparseArray<String> sApplicationLaunchKeyCategories;
189 static {
190 sApplicationLaunchKeyCategories = new SparseArray<String>();
191 sApplicationLaunchKeyCategories.append(
192 KeyEvent.KEYCODE_EXPLORER, Intent.CATEGORY_APP_BROWSER);
193 sApplicationLaunchKeyCategories.append(
194 KeyEvent.KEYCODE_ENVELOPE, Intent.CATEGORY_APP_EMAIL);
195 sApplicationLaunchKeyCategories.append(
196 KeyEvent.KEYCODE_CONTACTS, Intent.CATEGORY_APP_CONTACTS);
197 sApplicationLaunchKeyCategories.append(
198 KeyEvent.KEYCODE_CALENDAR, Intent.CATEGORY_APP_CALENDAR);
199 sApplicationLaunchKeyCategories.append(
200 KeyEvent.KEYCODE_MUSIC, Intent.CATEGORY_APP_MUSIC);
201 sApplicationLaunchKeyCategories.append(
202 KeyEvent.KEYCODE_CALCULATOR, Intent.CATEGORY_APP_CALCULATOR);
203 }
204
Dianne Hackborndf89e652011-10-06 22:35:11 -0700205 /**
206 * Lock protecting internal state. Must not call out into window
207 * manager with lock held. (This lock will be acquired in places
208 * where the window manager is calling in with its own lock held.)
209 */
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800210 private final Object mLock = new Object();
Dianne Hackborndf89e652011-10-06 22:35:11 -0700211
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800212 Context mContext;
213 IWindowManager mWindowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700214 WindowManagerFuncs mWindowManagerFuncs;
Jeff Brown96307042012-07-27 15:51:34 -0700215 PowerManager mPowerManager;
Joe Onorato93056472010-09-10 10:30:46 -0400216 IStatusBarService mStatusBarService;
Jeff Browncaca8812013-05-09 13:34:33 -0700217 boolean mPreloadedRecentApps;
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700218 final Object mServiceAquireLock = new Object();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800219 Vibrator mVibrator; // Vibrator for giving feedback of orientation changes
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700220 SearchManager mSearchManager;
Svetoslav8e3feb12014-02-24 13:46:47 -0800221 AccessibilityManager mAccessibilityManager;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800222
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700223 // Vibrator pattern for haptic feedback of a long press.
224 long[] mLongPressVibePattern;
Craig Mautner88400d32012-09-30 12:35:45 -0700225
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700226 // Vibrator pattern for haptic feedback of virtual key press.
227 long[] mVirtualKeyVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700228
Amith Yamasanic33cb712010-02-10 15:21:49 -0800229 // Vibrator pattern for a short vibration.
230 long[] mKeyboardTapVibePattern;
231
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -0700232 // Vibrator pattern for a short vibration when tapping on an hour/minute tick of a Clock.
233 long[] mClockTickVibePattern;
234
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700235 // Vibrator pattern for haptic feedback during boot when safe mode is disabled.
236 long[] mSafeModeDisabledVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700237
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700238 // Vibrator pattern for haptic feedback during boot when safe mode is enabled.
239 long[] mSafeModeEnabledVibePattern;
Romain Guy8154cd32010-03-29 14:41:15 -0700240
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800241 /** If true, hitting shift & menu will broadcast Intent.ACTION_BUG_REPORT */
242 boolean mEnableShiftMenuBugReports = false;
Mike Lockwoodd747dc82011-09-13 16:28:22 -0400243
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800244 boolean mSafeMode;
245 WindowState mStatusBar = null;
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700246 int mStatusBarHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400247 WindowState mNavigationBar = null;
Daniel Sandler36412a72011-08-04 09:35:13 -0400248 boolean mHasNavigationBar = false;
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700249 boolean mCanHideNavigationBar = false;
Daniel Sandler4a066c52012-04-20 14:49:13 -0400250 boolean mNavigationBarCanMove = false; // can the navigation bar ever move to the side?
251 boolean mNavigationBarOnBottom = true; // is the navigation bar on the bottom *right now*?
252 int[] mNavigationBarHeightForRotation = new int[4];
253 int[] mNavigationBarWidthForRotation = new int[4];
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400254
Jim Miller5ecd8112013-01-09 18:50:26 -0800255 KeyguardServiceDelegate mKeyguardDelegate;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800256 GlobalActions mGlobalActions;
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700257 volatile boolean mPowerKeyHandled; // accessed from input reader and handler thread
258 boolean mPendingPowerKeyUpCanceled;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800259 Handler mHandler;
satok1bc0a492012-04-25 22:47:12 +0900260 WindowState mLastInputMethodWindow = null;
261 WindowState mLastInputMethodTargetWindow = null;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800262
Jeff Brown68b909d2011-12-07 16:36:01 -0800263 static final int RECENT_APPS_BEHAVIOR_SHOW_OR_DISMISS = 0;
264 static final int RECENT_APPS_BEHAVIOR_EXIT_TOUCH_MODE_AND_SHOW = 1;
Jeff Brown602ab322012-05-16 13:33:47 -0700265 static final int RECENT_APPS_BEHAVIOR_DISMISS = 2;
266 static final int RECENT_APPS_BEHAVIOR_DISMISS_AND_SWITCH = 3;
Jeff Brown68b909d2011-12-07 16:36:01 -0800267
268 RecentApplicationsDialog mRecentAppsDialog;
269 int mRecentAppsDialogHeldModifiers;
Jeff Browncf39bdf2012-05-18 14:41:19 -0700270 boolean mLanguageSwitchKeyPressed;
Jeff Brown68b909d2011-12-07 16:36:01 -0800271
Jeff Brown2e7760e2012-04-11 15:14:55 -0700272 int mLidState = LID_ABSENT;
Jeff Browndaa37532012-05-01 15:54:03 -0700273 boolean mHaveBuiltInKeyboard;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800274
Dianne Hackbornc777e072010-02-12 13:07:59 -0800275 boolean mSystemReady;
Dianne Hackbornba24e4d2011-09-01 11:17:06 -0700276 boolean mSystemBooted;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800277 boolean mHdmiPlugged;
Daniel Sandler6396c722013-04-16 20:19:09 -0400278 int mUiMode;
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700279 int mDockMode = Intent.EXTRA_DOCK_STATE_UNDOCKED;
Mike Lockwood1753f7f2009-08-24 14:49:07 -0700280 int mLidOpenRotation;
Mike Lockwood2d1efbd2009-09-16 12:15:53 -0400281 int mCarDockRotation;
282 int mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -0700283 int mUndockedHdmiRotation;
284 int mDemoHdmiRotation;
285 boolean mDemoHdmiRotationLock;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400286
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700287 // Default display does not rotate, apps that require non-default orientation will have to
288 // have the orientation emulated.
289 private boolean mForceDefaultOrientation = false;
290
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400291 int mUserRotationMode = WindowManagerPolicy.USER_ROTATION_FREE;
292 int mUserRotation = Surface.ROTATION_0;
Jeff Brown207673cd2012-06-05 17:47:11 -0700293 boolean mAccelerometerDefault;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400294
Jeff Brownbcdfc622014-03-06 19:13:04 -0800295 boolean mSupportAutoRotation;
Jeff Brownd3187e32011-09-21 19:26:44 -0700296 int mAllowAllRotations = -1;
Mike Lockwoode9867d22009-09-20 01:59:02 -0400297 boolean mCarDockEnablesAccelerometer;
298 boolean mDeskDockEnablesAccelerometer;
Dianne Hackborn2862fff2009-09-15 22:56:29 -0700299 int mLidKeyboardAccessibility;
300 int mLidNavigationAccessibility;
Jeff Brownc458ce92012-04-30 14:58:40 -0700301 boolean mLidControlsSleep;
Joe Onoratod208e702010-10-08 16:22:43 -0400302 int mLongPressOnPowerBehavior = -1;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -0700303 boolean mScreenOnEarly = false;
304 boolean mScreenOnFully = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800305 boolean mOrientationSensorEnabled = false;
306 int mCurrentAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800307 boolean mHasSoftInput = false;
Daniel Sandlerdd73ee42013-10-11 22:19:59 -0400308 boolean mTranslucentDecorEnabled = true;
Craig Mautner967212c2013-04-13 21:10:58 -0700309
Jeff Brown70825162012-03-28 17:27:48 -0700310 int mPointerLocationMode = 0; // guarded by mLock
Joe Onorato664644d2011-01-23 17:53:23 -0800311
312 // The last window we were told about in focusChanged.
313 WindowState mFocusedWindow;
Dianne Hackborne0f085d2011-11-30 18:41:15 -0800314 IApplicationToken mFocusedApp;
Joe Onorato664644d2011-01-23 17:53:23 -0800315
Jeff Brown70825162012-03-28 17:27:48 -0700316 PointerLocationView mPointerLocationView;
Jeff Brown32cbc38552011-12-01 14:01:49 -0800317
Dianne Hackbornc652de82013-02-15 16:32:56 -0800318 // The current size of the screen; really; extends into the overscan area of
319 // the screen and doesn't account for any system elements like the status bar.
320 int mOverscanScreenLeft, mOverscanScreenTop;
321 int mOverscanScreenWidth, mOverscanScreenHeight;
322 // The current visible size of the screen; really; (ir)regardless of whether the status
323 // bar can be hidden but not extending into the overscan area.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800324 int mUnrestrictedScreenLeft, mUnrestrictedScreenTop;
325 int mUnrestrictedScreenWidth, mUnrestrictedScreenHeight;
Dianne Hackborn313440842013-02-19 19:22:59 -0800326 // Like mOverscanScreen*, but allowed to move into the overscan region where appropriate.
327 int mRestrictedOverscanScreenLeft, mRestrictedOverscanScreenTop;
328 int mRestrictedOverscanScreenWidth, mRestrictedOverscanScreenHeight;
Dianne Hackborn82de1ae2010-10-28 11:28:39 -0700329 // The current size of the screen; these may be different than (0,0)-(dw,dh)
330 // if the status bar can't be hidden; in that case it effectively carves out
331 // that area of the display from all other windows.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800332 int mRestrictedScreenLeft, mRestrictedScreenTop;
333 int mRestrictedScreenWidth, mRestrictedScreenHeight;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700334 // During layout, the current screen borders accounting for any currently
335 // visible system UI elements.
336 int mSystemLeft, mSystemTop, mSystemRight, mSystemBottom;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700337 // For applications requesting stable content insets, these are them.
338 int mStableLeft, mStableTop, mStableRight, mStableBottom;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -0700339 // For applications requesting stable content insets but have also set the
340 // fullscreen window flag, these are the stable dimensions without the status bar.
341 int mStableFullscreenLeft, mStableFullscreenTop;
342 int mStableFullscreenRight, mStableFullscreenBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800343 // During layout, the current screen borders with all outer decoration
344 // (status bar, input method dock) accounted for.
345 int mCurLeft, mCurTop, mCurRight, mCurBottom;
346 // During layout, the frame in which content should be displayed
347 // to the user, accounting for all screen decoration except for any
348 // space they deem as available for other content. This is usually
349 // the same as mCur*, but may be larger if the screen decor has supplied
350 // content insets.
351 int mContentLeft, mContentTop, mContentRight, mContentBottom;
Dianne Hackborn8e11ef02010-11-18 19:47:42 -0800352 // During layout, the current screen borders along which input method
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800353 // windows are placed.
354 int mDockLeft, mDockTop, mDockRight, mDockBottom;
355 // During layout, the layer at which the doc window is placed.
356 int mDockLayer;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700357 // During layout, this is the layer of the status bar.
358 int mStatusBarLayer;
Dianne Hackborne26ab702011-10-16 13:21:33 -0700359 int mLastSystemUiFlags;
360 // Bits that we are in the process of clearing, so we want to prevent
361 // them from being set by applications until everything has been updated
362 // to have them clear.
363 int mResettingSystemUiFlags = 0;
364 // Bits that we are currently always keeping cleared.
365 int mForceClearedSystemUiFlags = 0;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -0800366 // What we last reported to system UI about whether the compatibility
367 // menu needs to be displayed.
368 boolean mLastFocusNeedsMenu = false;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700369
370 FakeWindow mHideNavFakeWindow = null;
371
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800372 static final Rect mTmpParentFrame = new Rect();
373 static final Rect mTmpDisplayFrame = new Rect();
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800374 static final Rect mTmpOverscanFrame = new Rect();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800375 static final Rect mTmpContentFrame = new Rect();
376 static final Rect mTmpVisibleFrame = new Rect();
John Spurlock46646232013-09-30 22:32:42 -0400377 static final Rect mTmpDecorFrame = new Rect();
Dianne Hackborn1f903c32011-09-13 19:18:06 -0700378 static final Rect mTmpNavigationFrame = new Rect();
Craig Mautner967212c2013-04-13 21:10:58 -0700379
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800380 WindowState mTopFullscreenOpaqueWindowState;
Craig Mautner2bc789b2014-03-19 19:48:38 -0700381 HashSet<IApplicationToken> mAppsToBeHidden = new HashSet<IApplicationToken>();
Joe Onorato93056472010-09-10 10:30:46 -0400382 boolean mTopIsFullscreen;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800383 boolean mForceStatusBar;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -0700384 boolean mForceStatusBarFromKeyguard;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700385 boolean mHideLockScreen;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -0800386 boolean mForcingShowNavBar;
387 int mForcingShowNavBarLayer;
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700388
389 // States of keyguard dismiss.
390 private static final int DISMISS_KEYGUARD_NONE = 0; // Keyguard not being dismissed.
391 private static final int DISMISS_KEYGUARD_START = 1; // Keyguard needs to be dismissed.
392 private static final int DISMISS_KEYGUARD_CONTINUE = 2; // Keyguard has been dismissed.
393 int mDismissKeyguard = DISMISS_KEYGUARD_NONE;
394
395 /** The window that is currently dismissing the keyguard. Dismissing the keyguard must only
396 * be done once per window. */
397 private WindowState mWinDismissingKeyguard;
398
Dianne Hackborn7ad44382012-10-18 17:46:00 -0700399 boolean mShowingLockscreen;
400 boolean mShowingDream;
401 boolean mDreamingLockscreen;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800402 boolean mHomePressed;
Jeff Browncaca8812013-05-09 13:34:33 -0700403 boolean mHomeConsumed;
404 boolean mHomeDoubleTapPending;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800405 Intent mHomeIntent;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700406 Intent mCarDockIntent;
407 Intent mDeskDockIntent;
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700408 boolean mSearchKeyShortcutPending;
409 boolean mConsumeSearchKeyUp;
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700410 boolean mAssistKeyLongPressed;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800411
Mike Lockwood28569302010-01-28 11:54:40 -0500412 // support for activating the lock screen while the screen is on
413 boolean mAllowLockscreenWhenOn;
414 int mLockScreenTimeout;
415 boolean mLockScreenTimerActive;
416
David Brownbaf8d092010-03-08 21:52:59 -0800417 // Behavior of ENDCALL Button. (See Settings.System.END_BUTTON_BEHAVIOR.)
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800418 int mEndcallBehavior;
David Brownbaf8d092010-03-08 21:52:59 -0800419
420 // Behavior of POWER button while in-call and screen on.
421 // (See Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR.)
422 int mIncallPowerBehavior;
423
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700424 Display mDisplay;
425
Dianne Hackborn9d132642011-04-21 17:26:39 -0700426 int mLandscapeRotation = 0; // default landscape rotation
427 int mSeascapeRotation = 0; // "other" landscape rotation, 180 degrees from mLandscapeRotation
428 int mPortraitRotation = 0; // default portrait rotation
429 int mUpsideDownRotation = 0; // "other" portrait rotation
Mitsuru Oshima831d0d92009-06-16 18:27:18 -0700430
Dianne Hackbornc652de82013-02-15 16:32:56 -0800431 int mOverscanLeft = 0;
432 int mOverscanTop = 0;
433 int mOverscanRight = 0;
434 int mOverscanBottom = 0;
435
Joe Onorato46b0d682010-11-22 17:37:27 -0800436 // What we do when the user long presses on home
Jeff Browncaca8812013-05-09 13:34:33 -0700437 private int mLongPressOnHomeBehavior;
438
439 // What we do when the user double-taps on home
440 private int mDoubleTapOnHomeBehavior;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800441
Winson Chung9112ec32011-06-27 13:15:32 -0700442 // Screenshot trigger states
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700443 // Time to volume and power must be pressed within this interval of each other.
444 private static final long SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS = 150;
Winson Chung1cea2f32012-10-08 20:42:01 -0700445 // Increase the chord delay when taking a screenshot from the keyguard
446 private static final float KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER = 2.5f;
Christopher Tatee90585f2012-03-05 18:56:25 -0800447 private boolean mScreenshotChordEnabled;
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700448 private boolean mVolumeDownKeyTriggered;
449 private long mVolumeDownKeyTime;
450 private boolean mVolumeDownKeyConsumedByScreenshotChord;
451 private boolean mVolumeUpKeyTriggered;
452 private boolean mPowerKeyTriggered;
453 private long mPowerKeyTime;
Winson Chung9112ec32011-06-27 13:15:32 -0700454
Michael Wrightb854e242013-02-05 17:54:02 -0800455 /* The number of steps between min and max brightness */
456 private static final int BRIGHTNESS_STEPS = 10;
457
Christopher Tate5e08af02012-09-21 17:17:22 -0700458 SettingsObserver mSettingsObserver;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800459 ShortcutManager mShortcutManager;
460 PowerManager.WakeLock mBroadcastWakeLock;
Jeff Brown40013652012-05-16 21:22:36 -0700461 boolean mHavePendingMediaKeyRepeatWithWakeLock;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800462
Craig Mautnerd625ab22013-09-06 13:40:31 -0700463 private int mCurrentUserId;
464
Justin Kohd378ad72013-04-01 12:18:26 -0700465 // Maps global key codes to the components that will handle them.
466 private GlobalKeyManager mGlobalKeyManager;
467
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700468 // Fallback actions by key code.
469 private final SparseArray<KeyCharacterMap.FallbackAction> mFallbackActions =
470 new SparseArray<KeyCharacterMap.FallbackAction>();
Jeff Brown49ed71d2010-12-06 17:13:33 -0800471
Jeff Brown70825162012-03-28 17:27:48 -0700472 private static final int MSG_ENABLE_POINTER_LOCATION = 1;
473 private static final int MSG_DISABLE_POINTER_LOCATION = 2;
Jeff Brown40013652012-05-16 21:22:36 -0700474 private static final int MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK = 3;
475 private static final int MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK = 4;
Jeff Brown70825162012-03-28 17:27:48 -0700476
477 private class PolicyHandler extends Handler {
478 @Override
479 public void handleMessage(Message msg) {
480 switch (msg.what) {
481 case MSG_ENABLE_POINTER_LOCATION:
482 enablePointerLocation();
483 break;
484 case MSG_DISABLE_POINTER_LOCATION:
485 disablePointerLocation();
486 break;
Jeff Brown40013652012-05-16 21:22:36 -0700487 case MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK:
488 dispatchMediaKeyWithWakeLock((KeyEvent)msg.obj);
489 break;
490 case MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK:
491 dispatchMediaKeyRepeatWithWakeLock((KeyEvent)msg.obj);
492 break;
Jeff Brown70825162012-03-28 17:27:48 -0700493 }
494 }
495 }
496
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800497 private UEventObserver mHDMIObserver = new UEventObserver() {
498 @Override
499 public void onUEvent(UEventObserver.UEvent event) {
500 setHdmiPlugged("1".equals(event.get("SWITCH_STATE")));
501 }
502 };
503
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800504 class SettingsObserver extends ContentObserver {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800505 SettingsObserver(Handler handler) {
506 super(handler);
507 }
David Brownbaf8d092010-03-08 21:52:59 -0800508
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800509 void observe() {
Christopher Tate5e08af02012-09-21 17:17:22 -0700510 // Observe all users' changes
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800511 ContentResolver resolver = mContext.getContentResolver();
512 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700513 Settings.System.END_BUTTON_BEHAVIOR), false, this,
514 UserHandle.USER_ALL);
David Brownbaf8d092010-03-08 21:52:59 -0800515 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700516 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR), false, this,
517 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800518 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700519 Settings.System.ACCELEROMETER_ROTATION), false, this,
520 UserHandle.USER_ALL);
Mike Lockwood28569302010-01-28 11:54:40 -0500521 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700522 Settings.System.USER_ROTATION), false, this,
523 UserHandle.USER_ALL);
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400524 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700525 Settings.System.SCREEN_OFF_TIMEOUT), false, this,
526 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800527 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700528 Settings.System.POINTER_LOCATION), false, this,
529 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800530 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700531 Settings.Secure.DEFAULT_INPUT_METHOD), false, this,
532 UserHandle.USER_ALL);
John Spurlockd9b70bd2014-02-06 17:02:44 -0500533 resolver.registerContentObserver(Settings.Secure.getUriFor(
John Spurlockf1a36642013-10-12 17:50:42 -0400534 Settings.Secure.IMMERSIVE_MODE_CONFIRMATIONS), false, this,
Christopher Tate5e08af02012-09-21 17:17:22 -0700535 UserHandle.USER_ALL);
John Spurlockc6d1c602014-01-17 15:22:06 -0500536 resolver.registerContentObserver(Settings.Global.getUriFor(
537 Settings.Global.POLICY_CONTROL), false, this,
538 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800539 updateSettings();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800540 }
541
542 @Override public void onChange(boolean selfChange) {
Dianne Hackbornc777e072010-02-12 13:07:59 -0800543 updateSettings();
Jeff Brown01a98dd2011-09-20 15:08:29 -0700544 updateRotation(false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800545 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800546 }
Craig Mautner967212c2013-04-13 21:10:58 -0700547
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800548 class MyOrientationListener extends WindowOrientationListener {
Craig Mautnereee29c42013-01-17 14:44:34 -0800549 MyOrientationListener(Context context, Handler handler) {
550 super(context, handler);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800551 }
Craig Mautner967212c2013-04-13 21:10:58 -0700552
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800553 @Override
Jeff Brownc0347aa2011-09-23 17:26:09 -0700554 public void onProposedRotationChanged(int rotation) {
Craig Mautnereda67292013-04-28 13:50:14 -0700555 if (localLOGV) Slog.v(TAG, "onProposedRotationChanged, rotation=" + rotation);
Jeff Brown01a98dd2011-09-20 15:08:29 -0700556 updateRotation(false);
557 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800558 }
559 MyOrientationListener mOrientationListener;
560
John Spurlock27735a42013-08-14 17:57:38 -0400561 private final BarController mStatusBarController = new BarController("StatusBar",
John Spurlock5b9145b2013-08-20 15:13:47 -0400562 View.STATUS_BAR_TRANSIENT,
563 View.STATUS_BAR_UNHIDE,
John Spurlockbd957402013-10-03 11:38:39 -0400564 View.STATUS_BAR_TRANSLUCENT,
565 StatusBarManager.WINDOW_STATUS_BAR,
566 WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
John Spurlock5b9145b2013-08-20 15:13:47 -0400567
John Spurlock27735a42013-08-14 17:57:38 -0400568 private final BarController mNavigationBarController = new BarController("NavigationBar",
John Spurlock5b9145b2013-08-20 15:13:47 -0400569 View.NAVIGATION_BAR_TRANSIENT,
570 View.NAVIGATION_BAR_UNHIDE,
John Spurlockbd957402013-10-03 11:38:39 -0400571 View.NAVIGATION_BAR_TRANSLUCENT,
572 StatusBarManager.WINDOW_NAVIGATION_BAR,
573 WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
John Spurlock5b9145b2013-08-20 15:13:47 -0400574
John Spurlockf1a36642013-10-12 17:50:42 -0400575 private ImmersiveModeConfirmation mImmersiveModeConfirmation;
John Spurlock32beb2c2013-03-11 10:16:47 -0400576
Craig Mautner037aa8d2013-06-07 10:35:44 -0700577 private SystemGesturesPointerEventListener mSystemGestures;
John Spurlock32beb2c2013-03-11 10:16:47 -0400578
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700579 IStatusBarService getStatusBarService() {
580 synchronized (mServiceAquireLock) {
581 if (mStatusBarService == null) {
582 mStatusBarService = IStatusBarService.Stub.asInterface(
583 ServiceManager.getService("statusbar"));
584 }
585 return mStatusBarService;
586 }
587 }
588
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700589 /*
590 * We always let the sensor be switched on by default except when
591 * the user has explicitly disabled sensor based rotation or when the
592 * screen is switched off.
593 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700594 boolean needSensorRunningLp() {
Jeff Brownbcdfc622014-03-06 19:13:04 -0800595 if (mSupportAutoRotation) {
596 if (mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
597 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
598 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT
599 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) {
600 // If the application has explicitly requested to follow the
601 // orientation, then we need to turn the sensor on.
602 return true;
603 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800604 }
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700605 if ((mCarDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_CAR) ||
Jeff Brown1a693182011-11-08 14:44:16 -0800606 (mDeskDockEnablesAccelerometer && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
607 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
608 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK))) {
Mike Lockwoode9867d22009-09-20 01:59:02 -0400609 // enable accelerometer if we are docked in a dock that enables accelerometer
610 // orientation management,
611 return true;
612 }
Jeff Brown207673cd2012-06-05 17:47:11 -0700613 if (mUserRotationMode == USER_ROTATION_LOCKED) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800614 // If the setting for using the sensor by default is enabled, then
615 // we will always leave it on. Note that the user could go to
616 // a window that forces an orientation that does not use the
617 // sensor and in theory we could turn it off... however, when next
618 // turning it on we won't have a good value for the current
619 // orientation for a little bit, which can cause orientation
620 // changes to lag, so we'd like to keep it always on. (It will
621 // still be turned off when the screen is off.)
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700622 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800623 }
Jeff Brownbcdfc622014-03-06 19:13:04 -0800624 return mSupportAutoRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800625 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700626
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800627 /*
628 * Various use cases for invoking this function
629 * screen turning off, should always disable listeners if already enabled
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700630 * screen turned on and current app has sensor based orientation, enable listeners
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800631 * if not already enabled
632 * screen turned on and current app does not have sensor orientation, disable listeners if
633 * already enabled
634 * screen turning on and current app has sensor based orientation, enable listeners if needed
635 * screen turning on and current app has nosensor based orientation, do nothing
636 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700637 void updateOrientationListenerLp() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800638 if (!mOrientationListener.canDetectOrientation()) {
639 // If sensor is turned off or nonexistent for some reason
640 return;
641 }
642 //Could have been invoked due to screen turning on or off or
643 //change of the currently visible window's orientation
Craig Mautnereda67292013-04-28 13:50:14 -0700644 if (localLOGV) Slog.v(TAG, "Screen status="+mScreenOnEarly+
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800645 ", current orientation="+mCurrentAppOrientation+
646 ", SensorEnabled="+mOrientationSensorEnabled);
647 boolean disable = true;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -0700648 if (mScreenOnEarly) {
The Android Open Source Project0727d222009-03-11 12:11:58 -0700649 if (needSensorRunningLp()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800650 disable = false;
651 //enable listener if not already enabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700652 if (!mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800653 mOrientationListener.enable();
Craig Mautnereda67292013-04-28 13:50:14 -0700654 if(localLOGV) Slog.v(TAG, "Enabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800655 mOrientationSensorEnabled = true;
656 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700657 }
658 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800659 //check if sensors need to be disabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700660 if (disable && mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800661 mOrientationListener.disable();
Craig Mautnereda67292013-04-28 13:50:14 -0700662 if(localLOGV) Slog.v(TAG, "Disabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800663 mOrientationSensorEnabled = false;
664 }
665 }
666
Jeff Brown4d396052010-10-29 21:50:21 -0700667 private void interceptPowerKeyDown(boolean handled) {
668 mPowerKeyHandled = handled;
669 if (!handled) {
670 mHandler.postDelayed(mPowerLongPress, ViewConfiguration.getGlobalActionKeyTimeout());
671 }
672 }
673
674 private boolean interceptPowerKeyUp(boolean canceled) {
675 if (!mPowerKeyHandled) {
676 mHandler.removeCallbacks(mPowerLongPress);
677 return !canceled;
Jeff Brown4d396052010-10-29 21:50:21 -0700678 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700679 return false;
680 }
681
682 private void cancelPendingPowerKeyAction() {
683 if (!mPowerKeyHandled) {
684 mHandler.removeCallbacks(mPowerLongPress);
685 }
Jeff Brownff204712011-10-25 21:27:54 -0700686 if (mPowerKeyTriggered) {
687 mPendingPowerKeyUpCanceled = true;
688 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700689 }
690
691 private void interceptScreenshotChord() {
Christopher Tatee90585f2012-03-05 18:56:25 -0800692 if (mScreenshotChordEnabled
693 && mVolumeDownKeyTriggered && mPowerKeyTriggered && !mVolumeUpKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700694 final long now = SystemClock.uptimeMillis();
695 if (now <= mVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS
696 && now <= mPowerKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) {
697 mVolumeDownKeyConsumedByScreenshotChord = true;
698 cancelPendingPowerKeyAction();
699
Jeff Sharkey2991fa32012-12-05 18:06:43 -0800700 mHandler.postDelayed(mScreenshotRunnable, getScreenshotChordLongPressDelay());
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700701 }
702 }
703 }
704
Winson Chung1cea2f32012-10-08 20:42:01 -0700705 private long getScreenshotChordLongPressDelay() {
Jim Miller5ecd8112013-01-09 18:50:26 -0800706 if (mKeyguardDelegate.isShowing()) {
Winson Chung1cea2f32012-10-08 20:42:01 -0700707 // Double the time it takes to take a screenshot from the keyguard
708 return (long) (KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER *
709 ViewConfiguration.getGlobalActionKeyTimeout());
Winson Chung1cea2f32012-10-08 20:42:01 -0700710 }
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800711 return ViewConfiguration.getGlobalActionKeyTimeout();
Winson Chung1cea2f32012-10-08 20:42:01 -0700712 }
713
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700714 private void cancelPendingScreenshotChordAction() {
Jeff Sharkey2991fa32012-12-05 18:06:43 -0800715 mHandler.removeCallbacks(mScreenshotRunnable);
Jeff Brown4d396052010-10-29 21:50:21 -0700716 }
717
718 private final Runnable mPowerLongPress = new Runnable() {
Craig Mautnerf1b67412012-09-19 13:18:29 -0700719 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800720 public void run() {
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700721 // The context isn't read
722 if (mLongPressOnPowerBehavior < 0) {
Jeff Brown850c5b72012-10-01 15:17:22 -0700723 mLongPressOnPowerBehavior = mContext.getResources().getInteger(
724 com.android.internal.R.integer.config_longPressOnPowerBehavior);
Joe Onoratod208e702010-10-08 16:22:43 -0400725 }
Jeff Brown850c5b72012-10-01 15:17:22 -0700726 int resolvedBehavior = mLongPressOnPowerBehavior;
727 if (FactoryTest.isLongPressOnPowerOffEnabled()) {
728 resolvedBehavior = LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM;
729 }
730
731 switch (resolvedBehavior) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700732 case LONG_PRESS_POWER_NOTHING:
733 break;
734 case LONG_PRESS_POWER_GLOBAL_ACTIONS:
735 mPowerKeyHandled = true;
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -0700736 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
737 performAuditoryFeedbackForAccessibilityIfNeed();
738 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700739 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
740 showGlobalActionsDialog();
741 break;
742 case LONG_PRESS_POWER_SHUT_OFF:
Jeff Brown9a538ee2012-08-20 14:56:57 -0700743 case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM:
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700744 mPowerKeyHandled = true;
745 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
746 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
Jeff Brown850c5b72012-10-01 15:17:22 -0700747 mWindowManagerFuncs.shutdown(resolvedBehavior == LONG_PRESS_POWER_SHUT_OFF);
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700748 break;
749 }
750 }
751 };
752
Jeff Sharkey2991fa32012-12-05 18:06:43 -0800753 private final Runnable mScreenshotRunnable = new Runnable() {
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800754 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700755 public void run() {
756 takeScreenshot();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800757 }
758 };
759
760 void showGlobalActionsDialog() {
761 if (mGlobalActions == null) {
Jeff Brown7304c342012-05-11 18:42:42 -0700762 mGlobalActions = new GlobalActions(mContext, mWindowManagerFuncs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800763 }
Mike Lockwood3a74bd32011-08-12 13:55:22 -0700764 final boolean keyguardShowing = keyguardIsShowingTq();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800765 mGlobalActions.showDialog(keyguardShowing, isDeviceProvisioned());
766 if (keyguardShowing) {
767 // since it took two seconds of long press to bring this up,
768 // poke the wake lock so they have some time to see the dialog.
Jim Miller25190572013-02-28 17:36:24 -0800769 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800770 }
771 }
772
773 boolean isDeviceProvisioned() {
Jeff Brownbf6f6f92012-09-25 15:03:20 -0700774 return Settings.Global.getInt(
775 mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800776 }
777
Patrick Dubroyece94522011-02-23 18:35:01 -0800778 private void handleLongPressOnHome() {
Joe Onorato46b0d682010-11-22 17:37:27 -0800779 if (mLongPressOnHomeBehavior != LONG_PRESS_HOME_NOTHING) {
Jeff Browncaca8812013-05-09 13:34:33 -0700780 mHomeConsumed = true;
Joe Onorato46b0d682010-11-22 17:37:27 -0800781 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
Patrick Dubroyece94522011-02-23 18:35:01 -0800782
Jeff Browncaca8812013-05-09 13:34:33 -0700783 if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI) {
784 toggleRecentApps();
785 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_ASSIST) {
786 launchAssistAction();
Jim Millere6ad1a82010-08-20 19:25:39 -0700787 }
788 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800789 }
Patrick Dubroyece94522011-02-23 18:35:01 -0800790
Jeff Browncaca8812013-05-09 13:34:33 -0700791 private void handleDoubleTapOnHome() {
792 if (mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
793 mHomeConsumed = true;
794 toggleRecentApps();
795 }
796 }
797
798 private final Runnable mHomeDoubleTapTimeoutRunnable = new Runnable() {
799 @Override
800 public void run() {
801 if (mHomeDoubleTapPending) {
802 mHomeDoubleTapPending = false;
803 launchHomeFromHotKey();
804 }
805 }
806 };
807
Patrick Dubroyece94522011-02-23 18:35:01 -0800808 /**
Jeff Brown68b909d2011-12-07 16:36:01 -0800809 * Create (if necessary) and show or dismiss the recent apps dialog according
810 * according to the requested behavior.
Patrick Dubroyece94522011-02-23 18:35:01 -0800811 */
Jeff Brown68b909d2011-12-07 16:36:01 -0800812 void showOrHideRecentAppsDialog(final int behavior) {
Jeff Brownda3d5a92011-03-29 15:11:34 -0700813 mHandler.post(new Runnable() {
814 @Override
815 public void run() {
816 if (mRecentAppsDialog == null) {
Jeff Brown54875002011-04-06 15:33:01 -0700817 mRecentAppsDialog = new RecentApplicationsDialog(mContext);
Jeff Brownda3d5a92011-03-29 15:11:34 -0700818 }
Jeff Brown54875002011-04-06 15:33:01 -0700819 if (mRecentAppsDialog.isShowing()) {
Jeff Brown68b909d2011-12-07 16:36:01 -0800820 switch (behavior) {
821 case RECENT_APPS_BEHAVIOR_SHOW_OR_DISMISS:
Jeff Brown602ab322012-05-16 13:33:47 -0700822 case RECENT_APPS_BEHAVIOR_DISMISS:
Jeff Brown68b909d2011-12-07 16:36:01 -0800823 mRecentAppsDialog.dismiss();
824 break;
825 case RECENT_APPS_BEHAVIOR_DISMISS_AND_SWITCH:
826 mRecentAppsDialog.dismissAndSwitch();
827 break;
828 case RECENT_APPS_BEHAVIOR_EXIT_TOUCH_MODE_AND_SHOW:
829 default:
830 break;
Jeff Brown54875002011-04-06 15:33:01 -0700831 }
832 } else {
Jeff Brown68b909d2011-12-07 16:36:01 -0800833 switch (behavior) {
834 case RECENT_APPS_BEHAVIOR_SHOW_OR_DISMISS:
835 mRecentAppsDialog.show();
836 break;
837 case RECENT_APPS_BEHAVIOR_EXIT_TOUCH_MODE_AND_SHOW:
838 try {
839 mWindowManager.setInTouchMode(false);
840 } catch (RemoteException e) {
841 }
842 mRecentAppsDialog.show();
843 break;
Jeff Brown602ab322012-05-16 13:33:47 -0700844 case RECENT_APPS_BEHAVIOR_DISMISS:
Jeff Brown68b909d2011-12-07 16:36:01 -0800845 case RECENT_APPS_BEHAVIOR_DISMISS_AND_SWITCH:
846 default:
847 break;
848 }
Jeff Brown54875002011-04-06 15:33:01 -0700849 }
Jeff Brownda3d5a92011-03-29 15:11:34 -0700850 }
851 });
Patrick Dubroyece94522011-02-23 18:35:01 -0800852 }
Jeff Brownda3d5a92011-03-29 15:11:34 -0700853
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800854 /** {@inheritDoc} */
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800855 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800856 public void init(Context context, IWindowManager windowManager,
Jeff Brown96307042012-07-27 15:51:34 -0700857 WindowManagerFuncs windowManagerFuncs) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800858 mContext = context;
859 mWindowManager = windowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700860 mWindowManagerFuncs = windowManagerFuncs;
Jeff Brown70825162012-03-28 17:27:48 -0700861 mHandler = new PolicyHandler();
Craig Mautnereee29c42013-01-17 14:44:34 -0800862 mOrientationListener = new MyOrientationListener(mContext, mHandler);
Jeff Brownc0347aa2011-09-23 17:26:09 -0700863 try {
864 mOrientationListener.setCurrentRotation(windowManager.getRotation());
865 } catch (RemoteException ex) { }
Christopher Tate5e08af02012-09-21 17:17:22 -0700866 mSettingsObserver = new SettingsObserver(mHandler);
867 mSettingsObserver.observe();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800868 mShortcutManager = new ShortcutManager(context, mHandler);
869 mShortcutManager.observe();
Daniel Sandler6396c722013-04-16 20:19:09 -0400870 mUiMode = context.getResources().getInteger(
871 com.android.internal.R.integer.config_defaultUiModeType);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800872 mHomeIntent = new Intent(Intent.ACTION_MAIN, null);
873 mHomeIntent.addCategory(Intent.CATEGORY_HOME);
874 mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
875 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700876 mCarDockIntent = new Intent(Intent.ACTION_MAIN, null);
877 mCarDockIntent.addCategory(Intent.CATEGORY_CAR_DOCK);
878 mCarDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
879 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
880 mDeskDockIntent = new Intent(Intent.ACTION_MAIN, null);
881 mDeskDockIntent.addCategory(Intent.CATEGORY_DESK_DOCK);
882 mDeskDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
883 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Jim Millere6ad1a82010-08-20 19:25:39 -0700884
Jeff Brown96307042012-07-27 15:51:34 -0700885 mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
886 mBroadcastWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800887 "PhoneWindowManager.mBroadcastWakeLock");
888 mEnableShiftMenuBugReports = "1".equals(SystemProperties.get("ro.debuggable"));
Jeff Brownbcdfc622014-03-06 19:13:04 -0800889 mSupportAutoRotation = mContext.getResources().getBoolean(
890 com.android.internal.R.bool.config_supportAutoRotation);
Dianne Hackborn2862fff2009-09-15 22:56:29 -0700891 mLidOpenRotation = readRotation(
Mike Lockwood2d1efbd2009-09-16 12:15:53 -0400892 com.android.internal.R.integer.config_lidOpenRotation);
893 mCarDockRotation = readRotation(
894 com.android.internal.R.integer.config_carDockRotation);
895 mDeskDockRotation = readRotation(
896 com.android.internal.R.integer.config_deskDockRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -0700897 mUndockedHdmiRotation = readRotation(
898 com.android.internal.R.integer.config_undockedHdmiRotation);
Mike Lockwoode9867d22009-09-20 01:59:02 -0400899 mCarDockEnablesAccelerometer = mContext.getResources().getBoolean(
900 com.android.internal.R.bool.config_carDockEnablesAccelerometer);
901 mDeskDockEnablesAccelerometer = mContext.getResources().getBoolean(
902 com.android.internal.R.bool.config_deskDockEnablesAccelerometer);
Dianne Hackborn2862fff2009-09-15 22:56:29 -0700903 mLidKeyboardAccessibility = mContext.getResources().getInteger(
904 com.android.internal.R.integer.config_lidKeyboardAccessibility);
905 mLidNavigationAccessibility = mContext.getResources().getInteger(
906 com.android.internal.R.integer.config_lidNavigationAccessibility);
Jeff Brownc458ce92012-04-30 14:58:40 -0700907 mLidControlsSleep = mContext.getResources().getBoolean(
908 com.android.internal.R.bool.config_lidControlsSleep);
Daniel Sandlerdd73ee42013-10-11 22:19:59 -0400909 mTranslucentDecorEnabled = mContext.getResources().getBoolean(
910 com.android.internal.R.bool.config_enableTranslucentDecor);
Jeff Brownf71343d2013-05-31 17:59:11 -0700911 readConfigurationDependentBehaviors();
Jeff Browncaca8812013-05-09 13:34:33 -0700912
Svetoslav8e3feb12014-02-24 13:46:47 -0800913 mAccessibilityManager = (AccessibilityManager) context.getSystemService(
914 Context.ACCESSIBILITY_SERVICE);
915
Mike Lockwood1753f7f2009-08-24 14:49:07 -0700916 // register for dock events
Dianne Hackborn78968392010-03-04 20:47:56 -0800917 IntentFilter filter = new IntentFilter();
918 filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE);
919 filter.addAction(UiModeManager.ACTION_EXIT_CAR_MODE);
920 filter.addAction(UiModeManager.ACTION_ENTER_DESK_MODE);
921 filter.addAction(UiModeManager.ACTION_EXIT_DESK_MODE);
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700922 filter.addAction(Intent.ACTION_DOCK_EVENT);
923 Intent intent = context.registerReceiver(mDockReceiver, filter);
924 if (intent != null) {
925 // Retrieve current sticky dock event broadcast.
926 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
927 Intent.EXTRA_DOCK_STATE_UNDOCKED);
928 }
Daniel Sandler7e37df52011-11-16 22:08:23 -0800929
Jeff Brown6aaf2952012-10-05 16:01:08 -0700930 // register for dream-related broadcasts
931 filter = new IntentFilter();
932 filter.addAction(Intent.ACTION_DREAMING_STARTED);
933 filter.addAction(Intent.ACTION_DREAMING_STOPPED);
934 context.registerReceiver(mDreamReceiver, filter);
935
Christopher Tate5e08af02012-09-21 17:17:22 -0700936 // register for multiuser-relevant broadcasts
937 filter = new IntentFilter(Intent.ACTION_USER_SWITCHED);
938 context.registerReceiver(mMultiuserReceiver, filter);
939
John Spurlock57306e62013-04-22 09:48:49 -0400940 // monitor for system gestures
Craig Mautner037aa8d2013-06-07 10:35:44 -0700941 mSystemGestures = new SystemGesturesPointerEventListener(context,
942 new SystemGesturesPointerEventListener.Callbacks() {
John Spurlock57306e62013-04-22 09:48:49 -0400943 @Override
944 public void onSwipeFromTop() {
John Spurlock04db1762013-05-13 12:46:41 -0400945 if (mStatusBar != null) {
John Spurlocke1f366f2013-08-05 12:22:40 -0400946 requestTransientBars(mStatusBar);
John Spurlock04db1762013-05-13 12:46:41 -0400947 }
John Spurlockad3e6cb2013-04-30 08:47:43 -0400948 }
949 @Override
950 public void onSwipeFromBottom() {
John Spurlock04db1762013-05-13 12:46:41 -0400951 if (mNavigationBar != null && mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -0400952 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -0400953 }
954 }
955 @Override
956 public void onSwipeFromRight() {
John Spurlock04db1762013-05-13 12:46:41 -0400957 if (mNavigationBar != null && !mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -0400958 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -0400959 }
960 }
961 @Override
962 public void onDebug() {
John Spurlockd67ec252013-09-05 11:31:54 -0400963 // no-op
John Spurlockad3e6cb2013-04-30 08:47:43 -0400964 }
965 });
John Spurlockf1a36642013-10-12 17:50:42 -0400966 mImmersiveModeConfirmation = new ImmersiveModeConfirmation(mContext);
Craig Mautner037aa8d2013-06-07 10:35:44 -0700967 mWindowManagerFuncs.registerPointerEventListener(mSystemGestures);
John Spurlock32beb2c2013-03-11 10:16:47 -0400968
Jeff Brownc2346132012-04-13 01:55:38 -0700969 mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700970 mLongPressVibePattern = getLongIntArray(mContext.getResources(),
971 com.android.internal.R.array.config_longPressVibePattern);
972 mVirtualKeyVibePattern = getLongIntArray(mContext.getResources(),
973 com.android.internal.R.array.config_virtualKeyVibePattern);
Amith Yamasanic33cb712010-02-10 15:21:49 -0800974 mKeyboardTapVibePattern = getLongIntArray(mContext.getResources(),
975 com.android.internal.R.array.config_keyboardTapVibePattern);
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -0700976 mClockTickVibePattern = getLongIntArray(mContext.getResources(),
977 com.android.internal.R.array.config_clockTickVibePattern);
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700978 mSafeModeDisabledVibePattern = getLongIntArray(mContext.getResources(),
979 com.android.internal.R.array.config_safeModeDisabledVibePattern);
980 mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(),
981 com.android.internal.R.array.config_safeModeEnabledVibePattern);
Daniel Sandler40427442010-07-16 11:44:52 -0400982
Christopher Tatee90585f2012-03-05 18:56:25 -0800983 mScreenshotChordEnabled = mContext.getResources().getBoolean(
984 com.android.internal.R.bool.config_enableScreenshotChord);
985
Justin Kohd378ad72013-04-01 12:18:26 -0700986 mGlobalKeyManager = new GlobalKeyManager(mContext);
987
Joe Onoratoea495d42011-04-06 11:41:11 -0700988 // Controls rotation and the like.
989 initializeHdmiState();
Dianne Hackborn40011092011-09-22 13:37:48 -0700990
991 // Match current screen state.
Jeff Brown26c6a502014-04-11 02:15:54 -0700992 if (mPowerManager.isInteractive()) {
Dianne Hackborn40011092011-09-22 13:37:48 -0700993 screenTurningOn(null);
994 } else {
995 screenTurnedOff(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
996 }
Mike Lockwood1753f7f2009-08-24 14:49:07 -0700997 }
998
Jeff Brownf71343d2013-05-31 17:59:11 -0700999 /**
1000 * Read values from config.xml that may be overridden depending on
1001 * the configuration of the device.
1002 * eg. Disable long press on home goes to recents on sw600dp.
1003 */
1004 private void readConfigurationDependentBehaviors() {
1005 mLongPressOnHomeBehavior = mContext.getResources().getInteger(
1006 com.android.internal.R.integer.config_longPressOnHomeBehavior);
1007 if (mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING ||
1008 mLongPressOnHomeBehavior > LONG_PRESS_HOME_ASSIST) {
1009 mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1010 }
1011
1012 mDoubleTapOnHomeBehavior = mContext.getResources().getInteger(
1013 com.android.internal.R.integer.config_doubleTapOnHomeBehavior);
1014 if (mDoubleTapOnHomeBehavior < DOUBLE_TAP_HOME_NOTHING ||
1015 mDoubleTapOnHomeBehavior > DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1016 mDoubleTapOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1017 }
1018 }
1019
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001020 @Override
Dianne Hackborndde331c2012-08-03 14:01:57 -07001021 public void setInitialDisplaySize(Display display, int width, int height, int density) {
Jeff Brownef981a42013-08-07 14:13:37 -07001022 // This method might be called before the policy has been fully initialized
1023 // or for other displays we don't care about.
1024 if (mContext == null || display.getDisplayId() != Display.DEFAULT_DISPLAY) {
1025 return;
Dianne Hackbornc652de82013-02-15 16:32:56 -08001026 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001027 mDisplay = display;
1028
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001029 final Resources res = mContext.getResources();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001030 int shortSize, longSize;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001031 if (width > height) {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001032 shortSize = height;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001033 longSize = width;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001034 mLandscapeRotation = Surface.ROTATION_0;
1035 mSeascapeRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001036 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001037 mPortraitRotation = Surface.ROTATION_90;
1038 mUpsideDownRotation = Surface.ROTATION_270;
1039 } else {
1040 mPortraitRotation = Surface.ROTATION_270;
1041 mUpsideDownRotation = Surface.ROTATION_90;
1042 }
1043 } else {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001044 shortSize = width;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001045 longSize = height;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001046 mPortraitRotation = Surface.ROTATION_0;
1047 mUpsideDownRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001048 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001049 mLandscapeRotation = Surface.ROTATION_270;
1050 mSeascapeRotation = Surface.ROTATION_90;
1051 } else {
1052 mLandscapeRotation = Surface.ROTATION_90;
1053 mSeascapeRotation = Surface.ROTATION_270;
1054 }
1055 }
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001056
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001057 mStatusBarHeight =
1058 res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001059
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001060 // Height of the navigation bar when presented horizontally at bottom
1061 mNavigationBarHeightForRotation[mPortraitRotation] =
1062 mNavigationBarHeightForRotation[mUpsideDownRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001063 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_height);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001064 mNavigationBarHeightForRotation[mLandscapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001065 mNavigationBarHeightForRotation[mSeascapeRotation] = res.getDimensionPixelSize(
1066 com.android.internal.R.dimen.navigation_bar_height_landscape);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001067
1068 // Width of the navigation bar when presented vertically along one side
1069 mNavigationBarWidthForRotation[mPortraitRotation] =
1070 mNavigationBarWidthForRotation[mUpsideDownRotation] =
1071 mNavigationBarWidthForRotation[mLandscapeRotation] =
1072 mNavigationBarWidthForRotation[mSeascapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001073 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_width);
Daniel Sandler4a066c52012-04-20 14:49:13 -04001074
1075 // SystemUI (status bar) layout policy
Dianne Hackborndde331c2012-08-03 14:01:57 -07001076 int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / density;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001077 int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / density;
Daniel Sandler4a066c52012-04-20 14:49:13 -04001078
Craig Mautnerd4ec33242013-07-22 10:37:43 -07001079 // Allow the navigation bar to move on small devices (phones).
1080 mNavigationBarCanMove = shortSizeDp < 600;
Daniel Sandler36412a72011-08-04 09:35:13 -04001081
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001082 mHasNavigationBar = res.getBoolean(com.android.internal.R.bool.config_showNavigationBar);
John Spurlock80f00c12013-06-13 11:10:51 -04001083 // Allow a system property to override this. Used by the emulator.
1084 // See also hasNavigationBar().
1085 String navBarOverride = SystemProperties.get("qemu.hw.mainkeys");
1086 if ("1".equals(navBarOverride)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001087 mHasNavigationBar = false;
John Spurlock80f00c12013-06-13 11:10:51 -04001088 } else if ("0".equals(navBarOverride)) {
1089 mHasNavigationBar = true;
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04001090 }
1091
Jeff Brown27f1d672012-10-17 18:32:34 -07001092 // For demo purposes, allow the rotation of the HDMI display to be controlled.
1093 // By default, HDMI locks rotation to landscape.
Erik Gilling9a41ef82011-09-26 19:21:03 -07001094 if ("portrait".equals(SystemProperties.get("persist.demo.hdmirotation"))) {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001095 mDemoHdmiRotation = mPortraitRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001096 } else {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001097 mDemoHdmiRotation = mLandscapeRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001098 }
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001099 mDemoHdmiRotationLock = SystemProperties.getBoolean("persist.demo.hdmirotationlock", false);
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001100
1101 // Only force the default orientation if the screen is xlarge, at least 960dp x 720dp, per
1102 // http://developer.android.com/guide/practices/screens_support.html#range
1103 mForceDefaultOrientation = longSizeDp >= 960 && shortSizeDp >= 720 &&
1104 res.getBoolean(com.android.internal.R.bool.config_forceDefaultOrientation) &&
1105 // For debug purposes the next line turns this feature off with:
1106 // $ adb shell setprop config.override_forced_orient true
1107 // $ adb shell wm size reset
1108 !"true".equals(SystemProperties.get("config.override_forced_orient"));
1109 }
1110
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001111 /**
1112 * @return whether the navigation bar can be hidden, e.g. the device has a
1113 * navigation bar and touch exploration is not enabled
1114 */
1115 private boolean canHideNavigationBar() {
Svetoslav8e3feb12014-02-24 13:46:47 -08001116 return mHasNavigationBar
1117 && !mAccessibilityManager.isTouchExplorationEnabled();
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001118 }
1119
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001120 @Override
1121 public boolean isDefaultOrientationForced() {
1122 return mForceDefaultOrientation;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001123 }
1124
Dianne Hackbornc652de82013-02-15 16:32:56 -08001125 @Override
1126 public void setDisplayOverscan(Display display, int left, int top, int right, int bottom) {
1127 if (display.getDisplayId() == Display.DEFAULT_DISPLAY) {
1128 mOverscanLeft = left;
1129 mOverscanTop = top;
1130 mOverscanRight = right;
1131 mOverscanBottom = bottom;
1132 }
1133 }
1134
Dianne Hackbornc777e072010-02-12 13:07:59 -08001135 public void updateSettings() {
1136 ContentResolver resolver = mContext.getContentResolver();
1137 boolean updateRotation = false;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001138 synchronized (mLock) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001139 mEndcallBehavior = Settings.System.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001140 Settings.System.END_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001141 Settings.System.END_BUTTON_BEHAVIOR_DEFAULT,
1142 UserHandle.USER_CURRENT);
1143 mIncallPowerBehavior = Settings.Secure.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001144 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001145 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT,
1146 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001147
Jeff Brown207673cd2012-06-05 17:47:11 -07001148 // Configure rotation lock.
Christopher Tate5e08af02012-09-21 17:17:22 -07001149 int userRotation = Settings.System.getIntForUser(resolver,
1150 Settings.System.USER_ROTATION, Surface.ROTATION_0,
1151 UserHandle.USER_CURRENT);
Jeff Brown207673cd2012-06-05 17:47:11 -07001152 if (mUserRotation != userRotation) {
1153 mUserRotation = userRotation;
1154 updateRotation = true;
1155 }
Christopher Tate5e08af02012-09-21 17:17:22 -07001156 int userRotationMode = Settings.System.getIntForUser(resolver,
1157 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
Jeff Brown207673cd2012-06-05 17:47:11 -07001158 WindowManagerPolicy.USER_ROTATION_FREE :
1159 WindowManagerPolicy.USER_ROTATION_LOCKED;
1160 if (mUserRotationMode != userRotationMode) {
1161 mUserRotationMode = userRotationMode;
1162 updateRotation = true;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001163 updateOrientationListenerLp();
1164 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001165
Dianne Hackbornc777e072010-02-12 13:07:59 -08001166 if (mSystemReady) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001167 int pointerLocation = Settings.System.getIntForUser(resolver,
1168 Settings.System.POINTER_LOCATION, 0, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001169 if (mPointerLocationMode != pointerLocation) {
1170 mPointerLocationMode = pointerLocation;
Jeff Brown70825162012-03-28 17:27:48 -07001171 mHandler.sendEmptyMessage(pointerLocation != 0 ?
1172 MSG_ENABLE_POINTER_LOCATION : MSG_DISABLE_POINTER_LOCATION);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001173 }
1174 }
1175 // use screen off timeout setting as the timeout for the lockscreen
Christopher Tate5e08af02012-09-21 17:17:22 -07001176 mLockScreenTimeout = Settings.System.getIntForUser(resolver,
1177 Settings.System.SCREEN_OFF_TIMEOUT, 0, UserHandle.USER_CURRENT);
1178 String imId = Settings.Secure.getStringForUser(resolver,
1179 Settings.Secure.DEFAULT_INPUT_METHOD, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001180 boolean hasSoftInput = imId != null && imId.length() > 0;
1181 if (mHasSoftInput != hasSoftInput) {
1182 mHasSoftInput = hasSoftInput;
1183 updateRotation = true;
1184 }
John Spurlockf1a36642013-10-12 17:50:42 -04001185 if (mImmersiveModeConfirmation != null) {
John Spurlock4355a532014-02-19 09:49:25 -05001186 mImmersiveModeConfirmation.loadSetting(mCurrentUserId);
John Spurlockd67ec252013-09-05 11:31:54 -04001187 }
John Spurlockc6d1c602014-01-17 15:22:06 -05001188 PolicyControl.reloadFromSetting(mContext);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001189 }
1190 if (updateRotation) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07001191 updateRotation(true);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001192 }
Jeff Brown70825162012-03-28 17:27:48 -07001193 }
1194
1195 private void enablePointerLocation() {
1196 if (mPointerLocationView == null) {
1197 mPointerLocationView = new PointerLocationView(mContext);
1198 mPointerLocationView.setPrintCoords(false);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001199 WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
1200 WindowManager.LayoutParams.MATCH_PARENT,
1201 WindowManager.LayoutParams.MATCH_PARENT);
Jeff Brown3b2b3542010-10-15 00:54:27 -07001202 lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001203 lp.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN
1204 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
1205 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1206 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
Jeff Brown90fc9052012-10-01 14:44:24 -07001207 if (ActivityManager.isHighEndGfx()) {
1208 lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
1209 lp.privateFlags |=
1210 WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED;
1211 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001212 lp.format = PixelFormat.TRANSLUCENT;
1213 lp.setTitle("PointerLocation");
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001214 WindowManager wm = (WindowManager)
Dianne Hackbornc777e072010-02-12 13:07:59 -08001215 mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Browncc4f7db2011-08-30 20:34:48 -07001216 lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL;
Jeff Brown70825162012-03-28 17:27:48 -07001217 wm.addView(mPointerLocationView, lp);
Michael Wrightc9c487e2013-11-07 18:55:09 -08001218 mWindowManagerFuncs.registerPointerEventListener(mPointerLocationView);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001219 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001220 }
Jeff Brown70825162012-03-28 17:27:48 -07001221
1222 private void disablePointerLocation() {
Jeff Brown70825162012-03-28 17:27:48 -07001223 if (mPointerLocationView != null) {
Michael Wrightc9c487e2013-11-07 18:55:09 -08001224 mWindowManagerFuncs.unregisterPointerEventListener(mPointerLocationView);
1225 WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Brown70825162012-03-28 17:27:48 -07001226 wm.removeView(mPointerLocationView);
1227 mPointerLocationView = null;
1228 }
1229 }
1230
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001231 private int readRotation(int resID) {
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001232 try {
1233 int rotation = mContext.getResources().getInteger(resID);
1234 switch (rotation) {
1235 case 0:
1236 return Surface.ROTATION_0;
1237 case 90:
1238 return Surface.ROTATION_90;
1239 case 180:
1240 return Surface.ROTATION_180;
1241 case 270:
1242 return Surface.ROTATION_270;
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001243 }
1244 } catch (Resources.NotFoundException e) {
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001245 // fall through
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001246 }
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001247 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001248 }
1249
1250 /** {@inheritDoc} */
Craig Mautner88400d32012-09-30 12:35:45 -07001251 @Override
Dianne Hackbornc2293022013-02-06 23:14:49 -08001252 public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001253 int type = attrs.type;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001254
1255 outAppOp[0] = AppOpsManager.OP_NONE;
1256
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001257 if (type < WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW
1258 || type > WindowManager.LayoutParams.LAST_SYSTEM_WINDOW) {
Jeff Brown98365d72012-08-19 20:30:52 -07001259 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001260 }
1261 String permission = null;
1262 switch (type) {
1263 case TYPE_TOAST:
1264 // XXX right now the app process has complete control over
1265 // this... should introduce a token to let the system
1266 // monitor/control what they are doing.
1267 break;
Daniel Sandler7d276c32012-01-30 14:33:52 -05001268 case TYPE_DREAM:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001269 case TYPE_INPUT_METHOD:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001270 case TYPE_WALLPAPER:
keunyounga446bf02013-06-21 19:07:57 -07001271 case TYPE_PRIVATE_PRESENTATION:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001272 // The window manager will check these.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001273 break;
1274 case TYPE_PHONE:
1275 case TYPE_PRIORITY_PHONE:
1276 case TYPE_SYSTEM_ALERT:
1277 case TYPE_SYSTEM_ERROR:
1278 case TYPE_SYSTEM_OVERLAY:
1279 permission = android.Manifest.permission.SYSTEM_ALERT_WINDOW;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001280 outAppOp[0] = AppOpsManager.OP_SYSTEM_ALERT_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001281 break;
1282 default:
1283 permission = android.Manifest.permission.INTERNAL_SYSTEM_WINDOW;
1284 }
1285 if (permission != null) {
1286 if (mContext.checkCallingOrSelfPermission(permission)
1287 != PackageManager.PERMISSION_GRANTED) {
Jeff Brown98365d72012-08-19 20:30:52 -07001288 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001289 }
1290 }
Jeff Brown98365d72012-08-19 20:30:52 -07001291 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001292 }
Craig Mautner88400d32012-09-30 12:35:45 -07001293
1294 @Override
1295 public boolean checkShowToOwnerOnly(WindowManager.LayoutParams attrs) {
1296
1297 // If this switch statement is modified, modify the comment in the declarations of
1298 // the type in {@link WindowManager.LayoutParams} as well.
1299 switch (attrs.type) {
1300 default:
1301 // These are the windows that by default are shown only to the user that created
1302 // them. If this needs to be overridden, set
1303 // {@link WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS} in
1304 // {@link WindowManager.LayoutParams}. Note that permission
1305 // {@link android.Manifest.permission.INTERNAL_SYSTEM_WINDOW} is required as well.
1306 if ((attrs.privateFlags & PRIVATE_FLAG_SHOW_FOR_ALL_USERS) == 0) {
1307 return true;
1308 }
1309 break;
1310
1311 // These are the windows that by default are shown to all users. However, to
1312 // protect against spoofing, check permissions below.
1313 case TYPE_APPLICATION_STARTING:
1314 case TYPE_BOOT_PROGRESS:
1315 case TYPE_DISPLAY_OVERLAY:
1316 case TYPE_HIDDEN_NAV_CONSUMER:
Jim Miller5ecd8112013-01-09 18:50:26 -08001317 case TYPE_KEYGUARD_SCRIM:
Craig Mautner88400d32012-09-30 12:35:45 -07001318 case TYPE_KEYGUARD_DIALOG:
1319 case TYPE_MAGNIFICATION_OVERLAY:
1320 case TYPE_NAVIGATION_BAR:
1321 case TYPE_NAVIGATION_BAR_PANEL:
1322 case TYPE_PHONE:
1323 case TYPE_POINTER:
1324 case TYPE_PRIORITY_PHONE:
1325 case TYPE_RECENTS_OVERLAY:
1326 case TYPE_SEARCH_BAR:
1327 case TYPE_STATUS_BAR:
1328 case TYPE_STATUS_BAR_PANEL:
1329 case TYPE_STATUS_BAR_SUB_PANEL:
1330 case TYPE_SYSTEM_DIALOG:
1331 case TYPE_UNIVERSE_BACKGROUND:
1332 case TYPE_VOLUME_OVERLAY:
keunyounga446bf02013-06-21 19:07:57 -07001333 case TYPE_PRIVATE_PRESENTATION:
Craig Mautner88400d32012-09-30 12:35:45 -07001334 break;
1335 }
1336
1337 // Check if third party app has set window to system window type.
1338 return mContext.checkCallingOrSelfPermission(
1339 android.Manifest.permission.INTERNAL_SYSTEM_WINDOW)
1340 != PackageManager.PERMISSION_GRANTED;
1341 }
1342
Craig Mautner967212c2013-04-13 21:10:58 -07001343 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001344 public void adjustWindowParamsLw(WindowManager.LayoutParams attrs) {
1345 switch (attrs.type) {
1346 case TYPE_SYSTEM_OVERLAY:
Jeff Brown3b2b3542010-10-15 00:54:27 -07001347 case TYPE_SECURE_SYSTEM_OVERLAY:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001348 // These types of windows can't receive input events.
1349 attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1350 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001351 attrs.flags &= ~WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001352 break;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001353 case TYPE_STATUS_BAR:
1354
1355 // If the Keyguard is in a hidden state (occluded by another window), we force to
1356 // remove the wallpaper and keyguard flag so that any change in-flight after setting
1357 // the keyguard as occluded wouldn't set these flags again.
1358 // See {@link #processKeyguardSetHiddenResultLw}.
1359 if (mKeyguardHidden) {
1360 attrs.flags &= ~WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
1361 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
1362 }
1363 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001364 }
Adrian Roos38502112014-04-09 21:04:11 +02001365
1366 if (attrs.type != TYPE_STATUS_BAR) {
1367 // The status bar is the only window allowed to exhibit keyguard behavior.
1368 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
1369 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001370 }
1371
1372 void readLidState() {
Jeff Brown2e7760e2012-04-11 15:14:55 -07001373 mLidState = mWindowManagerFuncs.getLidState();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001374 }
1375
Jeff Browndaa37532012-05-01 15:54:03 -07001376 private boolean isHidden(int accessibilityMode) {
1377 switch (accessibilityMode) {
1378 case 1:
1379 return mLidState == LID_CLOSED;
1380 case 2:
1381 return mLidState == LID_OPEN;
1382 default:
1383 return false;
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001384 }
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001385 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001386
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001387 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07001388 @Override
Jeff Browndaa37532012-05-01 15:54:03 -07001389 public void adjustConfigurationLw(Configuration config, int keyboardPresence,
1390 int navigationPresence) {
1391 mHaveBuiltInKeyboard = (keyboardPresence & PRESENCE_INTERNAL) != 0;
1392
Jeff Brownf71343d2013-05-31 17:59:11 -07001393 readConfigurationDependentBehaviors();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001394 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07001395 applyLidSwitchState();
Jeff Brownd04a88c2011-01-16 14:05:47 -08001396
Jeff Browndaa37532012-05-01 15:54:03 -07001397 if (config.keyboard == Configuration.KEYBOARD_NOKEYS
1398 || (keyboardPresence == PRESENCE_INTERNAL
1399 && isHidden(mLidKeyboardAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001400 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_YES;
Jeff Browndaa37532012-05-01 15:54:03 -07001401 if (!mHasSoftInput) {
1402 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_YES;
1403 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001404 }
1405
Jeff Browndaa37532012-05-01 15:54:03 -07001406 if (config.navigation == Configuration.NAVIGATION_NONAV
1407 || (navigationPresence == PRESENCE_INTERNAL
1408 && isHidden(mLidNavigationAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001409 config.navigationHidden = Configuration.NAVIGATIONHIDDEN_YES;
Jeff Brownd04a88c2011-01-16 14:05:47 -08001410 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001411 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001412
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001413 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07001414 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001415 public int windowTypeToLayerLw(int type) {
1416 if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001417 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001418 }
1419 switch (type) {
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001420 case TYPE_UNIVERSE_BACKGROUND:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001421 return 1;
keunyounga446bf02013-06-21 19:07:57 -07001422 case TYPE_PRIVATE_PRESENTATION:
1423 return 2;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001424 case TYPE_WALLPAPER:
1425 // wallpaper is at the bottom, though the window manager may move it.
1426 return 2;
1427 case TYPE_PHONE:
1428 return 3;
1429 case TYPE_SEARCH_BAR:
1430 return 4;
Craig Mautner88400d32012-09-30 12:35:45 -07001431 case TYPE_RECENTS_OVERLAY:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001432 case TYPE_SYSTEM_DIALOG:
1433 return 5;
1434 case TYPE_TOAST:
1435 // toasts and the plugged-in battery thing
1436 return 6;
1437 case TYPE_PRIORITY_PHONE:
1438 // SIM errors and unlock. Not sure if this really should be in a high layer.
1439 return 7;
1440 case TYPE_DREAM:
1441 // used for Dreams (screensavers with TYPE_DREAM windows)
1442 return 8;
1443 case TYPE_SYSTEM_ALERT:
1444 // like the ANR / app crashed dialogs
1445 return 9;
1446 case TYPE_INPUT_METHOD:
1447 // on-screen keyboards and other such input method user interfaces go here.
1448 return 10;
1449 case TYPE_INPUT_METHOD_DIALOG:
1450 // on-screen keyboards and other such input method user interfaces go here.
1451 return 11;
Jim Miller5ecd8112013-01-09 18:50:26 -08001452 case TYPE_KEYGUARD_SCRIM:
1453 // the safety window that shows behind keyguard while keyguard is starting
1454 return 12;
Jim Miller5ecd8112013-01-09 18:50:26 -08001455 case TYPE_STATUS_BAR_SUB_PANEL:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001456 return 13;
Jim Miller5ecd8112013-01-09 18:50:26 -08001457 case TYPE_STATUS_BAR:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001458 return 14;
Jim Miller5ecd8112013-01-09 18:50:26 -08001459 case TYPE_STATUS_BAR_PANEL:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001460 return 15;
1461 case TYPE_KEYGUARD_DIALOG:
1462 return 16;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001463 case TYPE_VOLUME_OVERLAY:
1464 // the on-screen volume indicator and controller shown when the user
1465 // changes the device volume
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001466 return 17;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001467 case TYPE_SYSTEM_OVERLAY:
1468 // the on-screen volume indicator and controller shown when the user
1469 // changes the device volume
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001470 return 18;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001471 case TYPE_NAVIGATION_BAR:
1472 // the navigation bar, if available, shows atop most things
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001473 return 19;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001474 case TYPE_NAVIGATION_BAR_PANEL:
1475 // some panels (e.g. search) need to show on top of the navigation bar
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001476 return 20;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001477 case TYPE_SYSTEM_ERROR:
1478 // system-level error dialogs
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001479 return 21;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001480 case TYPE_MAGNIFICATION_OVERLAY:
1481 // used to highlight the magnified portion of a display
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001482 return 22;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001483 case TYPE_DISPLAY_OVERLAY:
1484 // used to simulate secondary display devices
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001485 return 23;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001486 case TYPE_DRAG:
1487 // the drag layer: input for drag-and-drop is associated with this window,
1488 // which sits above all other focusable windows
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001489 return 24;
Jim Miller5ecd8112013-01-09 18:50:26 -08001490 case TYPE_SECURE_SYSTEM_OVERLAY:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001491 return 25;
Jim Miller5ecd8112013-01-09 18:50:26 -08001492 case TYPE_BOOT_PROGRESS:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001493 return 26;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001494 case TYPE_POINTER:
1495 // the (mouse) pointer layer
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001496 return 27;
Jim Miller5ecd8112013-01-09 18:50:26 -08001497 case TYPE_HIDDEN_NAV_CONSUMER:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001498 return 28;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001499 }
1500 Log.e(TAG, "Unknown window type: " + type);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001501 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001502 }
1503
1504 /** {@inheritDoc} */
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001505 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001506 public int subWindowTypeToLayerLw(int type) {
1507 switch (type) {
1508 case TYPE_APPLICATION_PANEL:
1509 case TYPE_APPLICATION_ATTACHED_DIALOG:
1510 return APPLICATION_PANEL_SUBLAYER;
1511 case TYPE_APPLICATION_MEDIA:
1512 return APPLICATION_MEDIA_SUBLAYER;
Dianne Hackborn5cb8d792009-05-21 17:34:15 -07001513 case TYPE_APPLICATION_MEDIA_OVERLAY:
1514 return APPLICATION_MEDIA_OVERLAY_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001515 case TYPE_APPLICATION_SUB_PANEL:
1516 return APPLICATION_SUB_PANEL_SUBLAYER;
1517 }
1518 Log.e(TAG, "Unknown sub-window type: " + type);
1519 return 0;
1520 }
1521
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001522 @Override
Dianne Hackbornabe0da02009-09-18 01:55:39 -07001523 public int getMaxWallpaperLayer() {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001524 return windowTypeToLayerLw(TYPE_STATUS_BAR);
Dianne Hackbornabe0da02009-09-18 01:55:39 -07001525 }
1526
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001527 @Override
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001528 public int getAboveUniverseLayer() {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001529 return windowTypeToLayerLw(TYPE_SYSTEM_ERROR);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001530 }
1531
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001532 public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07001533 if (mHasNavigationBar) {
1534 // For a basic navigation bar, when we are in landscape mode we place
1535 // the navigation bar to the side.
Daniel Sandler4a066c52012-04-20 14:49:13 -04001536 if (mNavigationBarCanMove && fullWidth > fullHeight) {
1537 return fullWidth - mNavigationBarWidthForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07001538 }
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001539 }
1540 return fullWidth;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001541 }
1542
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001543 public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07001544 if (mHasNavigationBar) {
1545 // For a basic navigation bar, when we are in portrait mode we place
1546 // the navigation bar to the bottom.
Daniel Sandler4a066c52012-04-20 14:49:13 -04001547 if (!mNavigationBarCanMove || fullWidth < fullHeight) {
1548 return fullHeight - mNavigationBarHeightForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07001549 }
1550 }
1551 return fullHeight;
Dianne Hackborn69cb8752011-05-19 18:13:32 -07001552 }
1553
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001554 public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation) {
1555 return getNonDecorDisplayWidth(fullWidth, fullHeight, rotation);
Dianne Hackborn69cb8752011-05-19 18:13:32 -07001556 }
1557
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001558 public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation) {
John Spurlock80f00c12013-06-13 11:10:51 -04001559 // There is a separate status bar at the top of the display. We don't count that as part
1560 // of the fixed decor, since it can hide; however, for purposes of configurations,
Dianne Hackborn077ee852012-04-09 16:27:07 -07001561 // we do want to exclude it since applications can't generally use that part
1562 // of the screen.
John Spurlock80f00c12013-06-13 11:10:51 -04001563 return getNonDecorDisplayHeight(fullWidth, fullHeight, rotation) - mStatusBarHeight;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001564 }
1565
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001566 @Override
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07001567 public boolean doesForceHide(WindowState win, WindowManager.LayoutParams attrs) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001568 return (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07001569 }
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001570
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001571 @Override
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07001572 public boolean canBeForceHidden(WindowState win, WindowManager.LayoutParams attrs) {
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001573 switch (attrs.type) {
1574 case TYPE_STATUS_BAR:
1575 case TYPE_NAVIGATION_BAR:
1576 case TYPE_WALLPAPER:
1577 case TYPE_DREAM:
1578 case TYPE_UNIVERSE_BACKGROUND:
Jim Miller5ecd8112013-01-09 18:50:26 -08001579 case TYPE_KEYGUARD_SCRIM:
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001580 return false;
1581 default:
1582 return true;
1583 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07001584 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001585
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001586 /** {@inheritDoc} */
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001587 @Override
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07001588 public View addStartingWindow(IBinder appToken, String packageName, int theme,
1589 CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes,
Adam Powell04fe6eb2013-05-31 14:39:48 -07001590 int icon, int logo, int windowFlags) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001591 if (!SHOW_STARTING_ANIMATIONS) {
1592 return null;
1593 }
1594 if (packageName == null) {
1595 return null;
1596 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001597
Mathias Jeppssond1443e92012-08-24 15:25:32 +02001598 WindowManager wm = null;
1599 View view = null;
1600
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001601 try {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001602 Context context = mContext;
Craig Mautner6fbda632012-07-03 09:26:39 -07001603 if (DEBUG_STARTING_WINDOW) Slog.d(TAG, "addStartingWindow " + packageName
1604 + ": nonLocalizedLabel=" + nonLocalizedLabel + " theme="
1605 + Integer.toHexString(theme));
Dianne Hackborn247fe742011-01-08 17:25:57 -08001606 if (theme != context.getThemeResId() || labelRes != 0) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001607 try {
1608 context = context.createPackageContext(packageName, 0);
Dianne Hackborn247fe742011-01-08 17:25:57 -08001609 context.setTheme(theme);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001610 } catch (PackageManager.NameNotFoundException e) {
1611 // Ignore
1612 }
1613 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001614
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001615 Window win = PolicyManager.makeNewWindow(context);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001616 final TypedArray ta = win.getWindowStyle();
1617 if (ta.getBoolean(
1618 com.android.internal.R.styleable.Window_windowDisablePreview, false)
1619 || ta.getBoolean(
1620 com.android.internal.R.styleable.Window_windowShowWallpaper,false)) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001621 return null;
1622 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001623
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001624 Resources r = context.getResources();
1625 win.setTitle(r.getText(labelRes, nonLocalizedLabel));
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001626
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001627 win.setType(
1628 WindowManager.LayoutParams.TYPE_APPLICATION_STARTING);
1629 // Force the window flags: this is a fake window, so it is not really
1630 // touchable or focusable by the user. We also add in the ALT_FOCUSABLE_IM
1631 // flag because we do know that the next window will take input
1632 // focus, so we want to get the IME window up on top of us right away.
1633 win.setFlags(
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08001634 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001635 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
1636 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
1637 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08001638 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001639 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
1640 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
1641 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001642
Adam Powell04fe6eb2013-05-31 14:39:48 -07001643 win.setDefaultIcon(icon);
1644 win.setDefaultLogo(logo);
1645
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001646 win.setLayout(WindowManager.LayoutParams.MATCH_PARENT,
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07001647 WindowManager.LayoutParams.MATCH_PARENT);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001648
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001649 final WindowManager.LayoutParams params = win.getAttributes();
1650 params.token = appToken;
1651 params.packageName = packageName;
1652 params.windowAnimations = win.getWindowStyle().getResourceId(
1653 com.android.internal.R.styleable.Window_windowAnimationStyle, 0);
Dianne Hackborn5d927c22011-09-02 12:22:18 -07001654 params.privateFlags |=
1655 WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED;
Craig Mautner88400d32012-09-30 12:35:45 -07001656 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
Adam Lesinski95c42972013-10-02 10:13:27 -07001657
1658 if (!compatInfo.supportsScreen()) {
1659 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
1660 }
1661
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001662 params.setTitle("Starting " + packageName);
1663
Mathias Jeppssond1443e92012-08-24 15:25:32 +02001664 wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
1665 view = win.getDecorView();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001666
1667 if (win.isFloating()) {
1668 // Whoops, there is no way to display an animation/preview
1669 // of such a thing! After all that work... let's skip it.
1670 // (Note that we must do this here because it is in
1671 // getDecorView() where the theme is evaluated... maybe
1672 // we should peek the floating attribute from the theme
1673 // earlier.)
1674 return null;
1675 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001676
Craig Mautner6fbda632012-07-03 09:26:39 -07001677 if (DEBUG_STARTING_WINDOW) Slog.d(
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001678 TAG, "Adding starting window for " + packageName
1679 + " / " + appToken + ": "
1680 + (view.getParent() != null ? view : null));
1681
1682 wm.addView(view, params);
1683
1684 // Only return the view if it was successfully added to the
1685 // window manager... which we can tell by it having a parent.
1686 return view.getParent() != null ? view : null;
Jeff Brown98365d72012-08-19 20:30:52 -07001687 } catch (WindowManager.BadTokenException e) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001688 // ignore
Craig Mautner42bf39e2014-02-21 16:46:22 -08001689 Log.w(TAG, appToken + " already running, starting window not displayed. " +
1690 e.getMessage());
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001691 } catch (RuntimeException e) {
1692 // don't crash if something else bad happens, for example a
1693 // failure loading resources because we are loading from an app
1694 // on external storage that has been unmounted.
1695 Log.w(TAG, appToken + " failed creating starting window", e);
Mathias Jeppssond1443e92012-08-24 15:25:32 +02001696 } finally {
1697 if (view != null && view.getParent() == null) {
1698 Log.w(TAG, "view not successfully added to wm, removing view");
1699 wm.removeViewImmediate(view);
1700 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001701 }
1702
1703 return null;
1704 }
1705
1706 /** {@inheritDoc} */
1707 public void removeStartingWindow(IBinder appToken, View window) {
Craig Mautner6fbda632012-07-03 09:26:39 -07001708 if (DEBUG_STARTING_WINDOW) {
1709 RuntimeException e = new RuntimeException("here");
1710 e.fillInStackTrace();
1711 Log.v(TAG, "Removing starting window for " + appToken + ": " + window, e);
1712 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001713
1714 if (window != null) {
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001715 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001716 wm.removeView(window);
1717 }
1718 }
1719
1720 /**
1721 * Preflight adding a window to the system.
1722 *
1723 * Currently enforces that three window types are singletons:
1724 * <ul>
1725 * <li>STATUS_BAR_TYPE</li>
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001726 * <li>KEYGUARD_TYPE</li>
1727 * </ul>
1728 *
1729 * @param win The window to be added
1730 * @param attrs Information about the window to be added
1731 *
Jeff Brown98365d72012-08-19 20:30:52 -07001732 * @return If ok, WindowManagerImpl.ADD_OKAY. If too many singletons,
1733 * WindowManagerImpl.ADD_MULTIPLE_SINGLETON
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001734 */
1735 public int prepareAddWindowLw(WindowState win, WindowManager.LayoutParams attrs) {
1736 switch (attrs.type) {
1737 case TYPE_STATUS_BAR:
Joe Onorato8bc6c512010-06-04 16:21:12 -04001738 mContext.enforceCallingOrSelfPermission(
1739 android.Manifest.permission.STATUS_BAR_SERVICE,
1740 "PhoneWindowManager");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001741 if (mStatusBar != null) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001742 if (mStatusBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07001743 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001744 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001745 }
1746 mStatusBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04001747 mStatusBarController.setWindow(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001748 break;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04001749 case TYPE_NAVIGATION_BAR:
1750 mContext.enforceCallingOrSelfPermission(
1751 android.Manifest.permission.STATUS_BAR_SERVICE,
1752 "PhoneWindowManager");
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001753 if (mNavigationBar != null) {
1754 if (mNavigationBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07001755 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001756 }
1757 }
Daniel Sandler8956dbb2011-04-22 07:55:02 -04001758 mNavigationBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04001759 mNavigationBarController.setWindow(win);
Craig Mautnereda67292013-04-28 13:50:14 -07001760 if (DEBUG_LAYOUT) Slog.i(TAG, "NAVIGATION BAR: " + mNavigationBar);
Daniel Sandler8956dbb2011-04-22 07:55:02 -04001761 break;
Jim Millere898ac52012-04-06 17:10:57 -07001762 case TYPE_NAVIGATION_BAR_PANEL:
1763 mContext.enforceCallingOrSelfPermission(
1764 android.Manifest.permission.STATUS_BAR_SERVICE,
1765 "PhoneWindowManager");
1766 break;
Dianne Hackborn08743722009-12-21 12:16:51 -08001767 case TYPE_STATUS_BAR_PANEL:
Joe Onorato8bc6c512010-06-04 16:21:12 -04001768 mContext.enforceCallingOrSelfPermission(
1769 android.Manifest.permission.STATUS_BAR_SERVICE,
1770 "PhoneWindowManager");
Dianne Hackborn08743722009-12-21 12:16:51 -08001771 break;
Joe Onorato29fc2c92010-11-24 10:26:50 -08001772 case TYPE_STATUS_BAR_SUB_PANEL:
1773 mContext.enforceCallingOrSelfPermission(
1774 android.Manifest.permission.STATUS_BAR_SERVICE,
1775 "PhoneWindowManager");
Joe Onorato29fc2c92010-11-24 10:26:50 -08001776 break;
Jim Miller5ecd8112013-01-09 18:50:26 -08001777 case TYPE_KEYGUARD_SCRIM:
Jim Miller25190572013-02-28 17:36:24 -08001778 if (mKeyguardScrim != null) {
1779 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
1780 }
Jim Miller5ecd8112013-01-09 18:50:26 -08001781 mKeyguardScrim = win;
1782 break;
1783
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001784 }
Jeff Brown98365d72012-08-19 20:30:52 -07001785 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001786 }
1787
1788 /** {@inheritDoc} */
1789 public void removeWindowLw(WindowState win) {
1790 if (mStatusBar == win) {
1791 mStatusBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04001792 mStatusBarController.setWindow(null);
Jim Millerc0b676d2013-03-22 16:11:08 -07001793 mKeyguardDelegate.showScrim();
Jim Miller5ecd8112013-01-09 18:50:26 -08001794 } else if (mKeyguardScrim == win) {
1795 Log.v(TAG, "Removing keyguard scrim");
1796 mKeyguardScrim = null;
1797 } if (mNavigationBar == win) {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04001798 mNavigationBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04001799 mNavigationBarController.setWindow(null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001800 }
1801 }
1802
1803 static final boolean PRINT_ANIM = false;
1804
1805 /** {@inheritDoc} */
Craig Mautner4b71aa12012-12-27 17:20:01 -08001806 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001807 public int selectAnimationLw(WindowState win, int transit) {
1808 if (PRINT_ANIM) Log.i(TAG, "selectAnimation in " + win
1809 + ": transit=" + transit);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001810 if (win == mStatusBar) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001811 boolean isKeyguard = (win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001812 if (transit == TRANSIT_EXIT
1813 || transit == TRANSIT_HIDE) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001814 return isKeyguard ? -1 : R.anim.dock_top_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001815 } else if (transit == TRANSIT_ENTER
1816 || transit == TRANSIT_SHOW) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001817 return isKeyguard ? -1 : R.anim.dock_top_enter;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001818 }
1819 } else if (win == mNavigationBar) {
1820 // This can be on either the bottom or the right.
1821 if (mNavigationBarOnBottom) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08001822 if (transit == TRANSIT_EXIT
1823 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001824 return R.anim.dock_bottom_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001825 } else if (transit == TRANSIT_ENTER
1826 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001827 return R.anim.dock_bottom_enter;
1828 }
1829 } else {
Craig Mautner4b71aa12012-12-27 17:20:01 -08001830 if (transit == TRANSIT_EXIT
1831 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001832 return R.anim.dock_right_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001833 } else if (transit == TRANSIT_ENTER
1834 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001835 return R.anim.dock_right_enter;
1836 }
1837 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08001838 }
1839
1840 if (transit == TRANSIT_PREVIEW_DONE) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001841 if (win.hasAppShownWindows()) {
1842 if (PRINT_ANIM) Log.i(TAG, "**** STARTING EXIT");
1843 return com.android.internal.R.anim.app_starting_exit;
1844 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07001845 } else if (win.getAttrs().type == TYPE_DREAM && mDreamingLockscreen
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001846 && transit == TRANSIT_ENTER) {
1847 // Special case: we are animating in a dream, while the keyguard
1848 // is shown. We don't want an animation on the dream, because
1849 // we need it shown immediately with the keyguard animating away
1850 // to reveal it.
1851 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001852 }
1853
1854 return 0;
1855 }
1856
Craig Mautner3c174372013-02-21 17:54:37 -08001857 @Override
1858 public void selectRotationAnimationLw(int anim[]) {
1859 if (PRINT_ANIM) Slog.i(TAG, "selectRotationAnimation mTopFullscreen="
1860 + mTopFullscreenOpaqueWindowState + " rotationAnimation="
1861 + (mTopFullscreenOpaqueWindowState == null ?
1862 "0" : mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation));
1863 if (mTopFullscreenOpaqueWindowState != null && mTopIsFullscreen) {
1864 switch (mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation) {
1865 case ROTATION_ANIMATION_CROSSFADE:
1866 anim[0] = R.anim.rotation_animation_xfade_exit;
1867 anim[1] = R.anim.rotation_animation_enter;
1868 break;
1869 case ROTATION_ANIMATION_JUMPCUT:
1870 anim[0] = R.anim.rotation_animation_jump_exit;
1871 anim[1] = R.anim.rotation_animation_enter;
1872 break;
1873 case ROTATION_ANIMATION_ROTATE:
1874 default:
1875 anim[0] = anim[1] = 0;
1876 break;
1877 }
1878 } else {
1879 anim[0] = anim[1] = 0;
1880 }
1881 }
1882
1883 @Override
1884 public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId,
1885 boolean forceDefault) {
1886 switch (exitAnimId) {
1887 case R.anim.rotation_animation_xfade_exit:
1888 case R.anim.rotation_animation_jump_exit:
1889 // These are the only cases that matter.
1890 if (forceDefault) {
1891 return false;
1892 }
1893 int anim[] = new int[2];
1894 selectRotationAnimationLw(anim);
1895 return (exitAnimId == anim[0] && enterAnimId == anim[1]);
1896 default:
1897 return true;
1898 }
1899 }
1900
1901 @Override
Dianne Hackborn0c2acff2012-04-12 15:17:07 -07001902 public Animation createForceHideEnterAnimation(boolean onWallpaper) {
1903 return AnimationUtils.loadAnimation(mContext, onWallpaper
1904 ? com.android.internal.R.anim.lock_screen_wallpaper_behind_enter
1905 : com.android.internal.R.anim.lock_screen_behind_enter);
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07001906 }
John Spurlockc8b46ca2013-04-08 12:59:26 -04001907
1908 private static void awakenDreams() {
1909 IDreamManager dreamManager = getDreamManager();
1910 if (dreamManager != null) {
1911 try {
1912 dreamManager.awaken();
1913 } catch (RemoteException e) {
1914 // fine, stay asleep then
1915 }
1916 }
1917 }
1918
1919 static IDreamManager getDreamManager() {
1920 return IDreamManager.Stub.asInterface(
1921 ServiceManager.checkService(DreamService.DREAM_SERVICE));
1922 }
1923
Jeff Brown4d396052010-10-29 21:50:21 -07001924 static ITelephony getTelephonyService() {
Mike Lockwoodf5f4ec92011-11-08 14:05:31 -08001925 return ITelephony.Stub.asInterface(
Jeff Brown4d396052010-10-29 21:50:21 -07001926 ServiceManager.checkService(Context.TELEPHONY_SERVICE));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001927 }
1928
Jeff Brown4d396052010-10-29 21:50:21 -07001929 static IAudioService getAudioService() {
1930 IAudioService audioService = IAudioService.Stub.asInterface(
1931 ServiceManager.checkService(Context.AUDIO_SERVICE));
1932 if (audioService == null) {
1933 Log.w(TAG, "Unable to find IAudioService interface.");
1934 }
1935 return audioService;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001936 }
1937
1938 boolean keyguardOn() {
1939 return keyguardIsShowingTq() || inKeyguardRestrictedKeyInputMode();
1940 }
1941
1942 private static final int[] WINDOW_TYPES_WHERE_HOME_DOESNT_WORK = {
1943 WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
1944 WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
1945 };
1946
1947 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001948 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001949 public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001950 final boolean keyguardOn = keyguardOn();
Jeff Brown1f245102010-11-18 20:53:46 -08001951 final int keyCode = event.getKeyCode();
1952 final int repeatCount = event.getRepeatCount();
1953 final int metaState = event.getMetaState();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001954 final int flags = event.getFlags();
Jeff Brown1f245102010-11-18 20:53:46 -08001955 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
1956 final boolean canceled = event.isCanceled();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001957
Jeff Brown40013652012-05-16 21:22:36 -07001958 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001959 Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount="
Jeff Brownfd23e3e2012-05-09 13:34:28 -07001960 + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed
1961 + " canceled=" + canceled);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001962 }
1963
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001964 // If we think we might have a volume down & power key chord on the way
1965 // but we're not sure, then tell the dispatcher to wait a little while and
1966 // try again later before dispatching.
Christopher Tatee90585f2012-03-05 18:56:25 -08001967 if (mScreenshotChordEnabled && (flags & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001968 if (mVolumeDownKeyTriggered && !mPowerKeyTriggered) {
1969 final long now = SystemClock.uptimeMillis();
1970 final long timeoutTime = mVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS;
1971 if (now < timeoutTime) {
1972 return timeoutTime - now;
1973 }
1974 }
1975 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
1976 && mVolumeDownKeyConsumedByScreenshotChord) {
1977 if (!down) {
1978 mVolumeDownKeyConsumedByScreenshotChord = false;
1979 }
1980 return -1;
1981 }
1982 }
1983
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001984 // First we always handle the home key here, so applications
1985 // can never break it, although if keyguard is on, we do let
1986 // it handle it, because that gives us the correct 5 second
1987 // timeout.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001988 if (keyCode == KeyEvent.KEYCODE_HOME) {
Michael Jurka7f2668c2012-03-27 07:49:52 -07001989
Jeff Brown49ed71d2010-12-06 17:13:33 -08001990 // If we have released the home key, and didn't do anything else
1991 // while it was pressed, then it is time to go home!
Michael Jurka7f2668c2012-03-27 07:49:52 -07001992 if (!down) {
Jeff Browncaca8812013-05-09 13:34:33 -07001993 cancelPreloadRecentApps();
1994
Jeff Brown49ed71d2010-12-06 17:13:33 -08001995 mHomePressed = false;
Jeff Browncaca8812013-05-09 13:34:33 -07001996 if (mHomeConsumed) {
1997 mHomeConsumed = false;
Michael Jurka7f2668c2012-03-27 07:49:52 -07001998 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08001999 }
Jeff Browncaca8812013-05-09 13:34:33 -07002000
2001 if (canceled) {
2002 Log.i(TAG, "Ignoring HOME; event canceled.");
2003 return -1;
2004 }
2005
2006 // If an incoming call is ringing, HOME is totally disabled.
2007 // (The user is already on the InCallScreen at this point,
2008 // and his ONLY options are to answer or reject the call.)
2009 try {
2010 ITelephony telephonyService = getTelephonyService();
2011 if (telephonyService != null && telephonyService.isRinging()) {
2012 Log.i(TAG, "Ignoring HOME; there's a ringing incoming call.");
2013 return -1;
2014 }
2015 } catch (RemoteException ex) {
2016 Log.w(TAG, "RemoteException from getPhoneInterface()", ex);
2017 }
2018
2019 // Delay handling home if a double-tap is possible.
2020 if (mDoubleTapOnHomeBehavior != DOUBLE_TAP_HOME_NOTHING) {
2021 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); // just in case
2022 mHomeDoubleTapPending = true;
2023 mHandler.postDelayed(mHomeDoubleTapTimeoutRunnable,
2024 ViewConfiguration.getDoubleTapTimeout());
2025 return -1;
2026 }
2027
2028 // Go home!
2029 launchHomeFromHotKey();
2030 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002031 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002032
2033 // If a system window has focus, then it doesn't make sense
2034 // right now to interact with applications.
2035 WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null;
2036 if (attrs != null) {
2037 final int type = attrs.type;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002038 if (type == WindowManager.LayoutParams.TYPE_KEYGUARD_SCRIM
2039 || type == WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG
2040 || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002041 // the "app" is keyguard, so give it the key
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002042 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002043 }
2044 final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length;
2045 for (int i=0; i<typeCount; i++) {
2046 if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) {
2047 // don't do anything, but also don't pass it to the app
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002048 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002049 }
2050 }
2051 }
Jeff Browncaca8812013-05-09 13:34:33 -07002052
2053 // Remember that home is pressed and handle special actions.
2054 if (repeatCount == 0) {
2055 mHomePressed = true;
2056 if (mHomeDoubleTapPending) {
2057 mHomeDoubleTapPending = false;
2058 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable);
2059 handleDoubleTapOnHome();
2060 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI
2061 || mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
2062 preloadRecentApps();
Michael Jurka7f2668c2012-03-27 07:49:52 -07002063 }
Jeff Browncaca8812013-05-09 13:34:33 -07002064 } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) {
2065 if (!keyguardOn) {
2066 handleLongPressOnHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002067 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002068 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002069 return -1;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002070 } else if (keyCode == KeyEvent.KEYCODE_MENU) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002071 // Hijack modified menu keys for debugging features
2072 final int chordBug = KeyEvent.META_SHIFT_ON;
2073
2074 if (down && repeatCount == 0) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002075 if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002076 Intent intent = new Intent(Intent.ACTION_BUG_REPORT);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002077 mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT,
2078 null, null, null, 0, null, null);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002079 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002080 } else if (SHOW_PROCESSES_ON_ALT_MENU &&
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002081 (metaState & KeyEvent.META_ALT_ON) == KeyEvent.META_ALT_ON) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002082 Intent service = new Intent();
2083 service.setClassName(mContext, "com.android.server.LoadAverageService");
2084 ContentResolver res = mContext.getContentResolver();
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002085 boolean shown = Settings.Global.getInt(
2086 res, Settings.Global.SHOW_PROCESSES, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002087 if (!shown) {
2088 mContext.startService(service);
2089 } else {
2090 mContext.stopService(service);
2091 }
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002092 Settings.Global.putInt(
2093 res, Settings.Global.SHOW_PROCESSES, shown ? 0 : 1);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002094 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002095 }
2096 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002097 } else if (keyCode == KeyEvent.KEYCODE_SEARCH) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002098 if (down) {
2099 if (repeatCount == 0) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002100 mSearchKeyShortcutPending = true;
2101 mConsumeSearchKeyUp = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002102 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002103 } else {
2104 mSearchKeyShortcutPending = false;
2105 if (mConsumeSearchKeyUp) {
2106 mConsumeSearchKeyUp = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002107 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002108 }
2109 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002110 return 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002111 } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) {
Michael Wrightc9ebea72013-01-16 19:25:02 -08002112 if (!keyguardOn) {
Jeff Browncaca8812013-05-09 13:34:33 -07002113 if (down && repeatCount == 0) {
2114 preloadRecentApps();
2115 } else if (!down) {
2116 toggleRecentApps();
Michael Wrightc9ebea72013-01-16 19:25:02 -08002117 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002118 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002119 return -1;
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002120 } else if (keyCode == KeyEvent.KEYCODE_ASSIST) {
2121 if (down) {
2122 if (repeatCount == 0) {
2123 mAssistKeyLongPressed = false;
2124 } else if (repeatCount == 1) {
2125 mAssistKeyLongPressed = true;
2126 if (!keyguardOn) {
2127 launchAssistLongPressAction();
2128 }
2129 }
2130 } else {
2131 if (mAssistKeyLongPressed) {
2132 mAssistKeyLongPressed = false;
2133 } else {
2134 if (!keyguardOn) {
2135 launchAssistAction();
2136 }
2137 }
2138 }
2139 return -1;
Jeff Sharkey2991fa32012-12-05 18:06:43 -08002140 } else if (keyCode == KeyEvent.KEYCODE_SYSRQ) {
2141 if (down && repeatCount == 0) {
2142 mHandler.post(mScreenshotRunnable);
2143 }
2144 return -1;
Michael Wrightb854e242013-02-05 17:54:02 -08002145 } else if (keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP
2146 || keyCode == KeyEvent.KEYCODE_BRIGHTNESS_DOWN) {
2147 if (down) {
2148 int direction = keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP ? 1 : -1;
2149
2150 // Disable autobrightness if it's on
2151 int auto = Settings.System.getIntForUser(
2152 mContext.getContentResolver(),
2153 Settings.System.SCREEN_BRIGHTNESS_MODE,
2154 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2155 UserHandle.USER_CURRENT_OR_SELF);
2156 if (auto != 0) {
2157 Settings.System.putIntForUser(mContext.getContentResolver(),
2158 Settings.System.SCREEN_BRIGHTNESS_MODE,
2159 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2160 UserHandle.USER_CURRENT_OR_SELF);
2161 }
2162
2163 int min = mPowerManager.getMinimumScreenBrightnessSetting();
2164 int max = mPowerManager.getMaximumScreenBrightnessSetting();
2165 int step = (max - min + BRIGHTNESS_STEPS - 1) / BRIGHTNESS_STEPS * direction;
2166 int brightness = Settings.System.getIntForUser(mContext.getContentResolver(),
2167 Settings.System.SCREEN_BRIGHTNESS,
2168 mPowerManager.getDefaultScreenBrightnessSetting(),
2169 UserHandle.USER_CURRENT_OR_SELF);
2170 brightness += step;
2171 // Make sure we don't go beyond the limits.
2172 brightness = Math.min(max, brightness);
2173 brightness = Math.max(min, brightness);
2174
2175 Settings.System.putIntForUser(mContext.getContentResolver(),
2176 Settings.System.SCREEN_BRIGHTNESS, brightness,
2177 UserHandle.USER_CURRENT_OR_SELF);
2178 Intent intent = new Intent(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG);
2179 mContext.sendBroadcastAsUser(intent, UserHandle.CURRENT_OR_SELF);
2180 }
2181 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002182 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002183
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002184 // Shortcuts are invoked through Search+key, so intercept those here
Jeff Browncaab4d02010-12-09 22:13:41 -08002185 // Any printing key that is chorded with Search should be consumed
2186 // even if no shortcut was invoked. This prevents text from being
2187 // inadvertently inserted when using a keyboard that has built-in macro
2188 // shortcut keys (that emit Search+x) and some of them are not registered.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002189 if (mSearchKeyShortcutPending) {
Jeff Browncaab4d02010-12-09 22:13:41 -08002190 final KeyCharacterMap kcm = event.getKeyCharacterMap();
2191 if (kcm.isPrintingKey(keyCode)) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002192 mConsumeSearchKeyUp = true;
2193 mSearchKeyShortcutPending = false;
Jeff Browncaab4d02010-12-09 22:13:41 -08002194 if (down && repeatCount == 0 && !keyguardOn) {
2195 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState);
2196 if (shortcutIntent != null) {
2197 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002198 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002199 mContext.startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002200 } catch (ActivityNotFoundException ex) {
2201 Slog.w(TAG, "Dropping shortcut key combination because "
2202 + "the activity to which it is registered was not found: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002203 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode), ex);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002204 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002205 } else {
2206 Slog.i(TAG, "Dropping unregistered shortcut key combination: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002207 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002208 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002209 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002210 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002211 }
2212 }
2213
Jeff Brown68b909d2011-12-07 16:36:01 -08002214 // Invoke shortcuts using Meta.
Jeff Brown602ab322012-05-16 13:33:47 -07002215 if (down && repeatCount == 0 && !keyguardOn
Jeff Brown68b909d2011-12-07 16:36:01 -08002216 && (metaState & KeyEvent.META_META_ON) != 0) {
2217 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brown602ab322012-05-16 13:33:47 -07002218 if (kcm.isPrintingKey(keyCode)) {
2219 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode,
2220 metaState & ~(KeyEvent.META_META_ON
2221 | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON));
2222 if (shortcutIntent != null) {
2223 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2224 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002225 mContext.startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brown602ab322012-05-16 13:33:47 -07002226 } catch (ActivityNotFoundException ex) {
2227 Slog.w(TAG, "Dropping shortcut key combination because "
2228 + "the activity to which it is registered was not found: "
2229 + "META+" + KeyEvent.keyCodeToString(keyCode), ex);
2230 }
2231 return -1;
Jeff Brown68b909d2011-12-07 16:36:01 -08002232 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002233 }
2234 }
2235
Jeff Brown6651a632011-11-28 12:59:11 -08002236 // Handle application launch keys.
Jeff Brown602ab322012-05-16 13:33:47 -07002237 if (down && repeatCount == 0 && !keyguardOn) {
Jeff Brown6651a632011-11-28 12:59:11 -08002238 String category = sApplicationLaunchKeyCategories.get(keyCode);
2239 if (category != null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -08002240 Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category);
Jeff Brown6651a632011-11-28 12:59:11 -08002241 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2242 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002243 mContext.startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brown6651a632011-11-28 12:59:11 -08002244 } catch (ActivityNotFoundException ex) {
2245 Slog.w(TAG, "Dropping application launch key because "
2246 + "the activity to which it is registered was not found: "
2247 + "keyCode=" + keyCode + ", category=" + category, ex);
2248 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002249 return -1;
Jeff Brown6651a632011-11-28 12:59:11 -08002250 }
2251 }
2252
Jeff Brown68b909d2011-12-07 16:36:01 -08002253 // Display task switcher for ALT-TAB or Meta-TAB.
2254 if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_TAB) {
Jeff Brown602ab322012-05-16 13:33:47 -07002255 if (mRecentAppsDialogHeldModifiers == 0 && !keyguardOn) {
Jeff Brown68b909d2011-12-07 16:36:01 -08002256 final int shiftlessModifiers = event.getModifiers() & ~KeyEvent.META_SHIFT_MASK;
2257 if (KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_ALT_ON)
2258 || KeyEvent.metaStateHasModifiers(
2259 shiftlessModifiers, KeyEvent.META_META_ON)) {
2260 mRecentAppsDialogHeldModifiers = shiftlessModifiers;
2261 showOrHideRecentAppsDialog(RECENT_APPS_BEHAVIOR_EXIT_TOUCH_MODE_AND_SHOW);
2262 return -1;
2263 }
2264 }
2265 } else if (!down && mRecentAppsDialogHeldModifiers != 0
2266 && (metaState & mRecentAppsDialogHeldModifiers) == 0) {
2267 mRecentAppsDialogHeldModifiers = 0;
Jeff Brown602ab322012-05-16 13:33:47 -07002268 showOrHideRecentAppsDialog(keyguardOn ? RECENT_APPS_BEHAVIOR_DISMISS :
2269 RECENT_APPS_BEHAVIOR_DISMISS_AND_SWITCH);
Jeff Brown68b909d2011-12-07 16:36:01 -08002270 }
2271
Jeff Browncf39bdf2012-05-18 14:41:19 -07002272 // Handle keyboard language switching.
2273 if (down && repeatCount == 0
2274 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2275 || (keyCode == KeyEvent.KEYCODE_SPACE
2276 && (metaState & KeyEvent.META_CTRL_MASK) != 0))) {
2277 int direction = (metaState & KeyEvent.META_SHIFT_MASK) != 0 ? -1 : 1;
2278 mWindowManagerFuncs.switchKeyboardLayout(event.getDeviceId(), direction);
2279 return -1;
2280 }
2281 if (mLanguageSwitchKeyPressed && !down
2282 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2283 || keyCode == KeyEvent.KEYCODE_SPACE)) {
2284 mLanguageSwitchKeyPressed = false;
2285 return -1;
2286 }
2287
Justin Kohd378ad72013-04-01 12:18:26 -07002288 if (mGlobalKeyManager.handleGlobalKey(mContext, keyCode, event)) {
2289 return -1;
2290 }
2291
Jeff Brown68b909d2011-12-07 16:36:01 -08002292 // Let the application handle the key.
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002293 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002294 }
2295
Jeff Brown3915bb82010-11-05 15:02:16 -07002296 /** {@inheritDoc} */
2297 @Override
Jeff Brown49ed71d2010-12-06 17:13:33 -08002298 public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown54875002011-04-06 15:33:01 -07002299 // Note: This method is only called if the initial down was unhandled.
Jeff Brown40013652012-05-16 21:22:36 -07002300 if (DEBUG_INPUT) {
Jeff Brown1f245102010-11-18 20:53:46 -08002301 Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction()
2302 + ", flags=" + event.getFlags()
2303 + ", keyCode=" + event.getKeyCode()
2304 + ", scanCode=" + event.getScanCode()
2305 + ", metaState=" + event.getMetaState()
2306 + ", repeatCount=" + event.getRepeatCount()
2307 + ", policyFlags=" + policyFlags);
Jeff Brown3915bb82010-11-05 15:02:16 -07002308 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002309
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002310 KeyEvent fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002311 if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
2312 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002313 final int keyCode = event.getKeyCode();
2314 final int metaState = event.getMetaState();
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002315 final boolean initialDown = event.getAction() == KeyEvent.ACTION_DOWN
2316 && event.getRepeatCount() == 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002317
Jeff Brown54875002011-04-06 15:33:01 -07002318 // Check for fallback actions specified by the key character map.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002319 final FallbackAction fallbackAction;
2320 if (initialDown) {
2321 fallbackAction = kcm.getFallbackAction(keyCode, metaState);
2322 } else {
2323 fallbackAction = mFallbackActions.get(keyCode);
2324 }
2325
2326 if (fallbackAction != null) {
Jeff Brown40013652012-05-16 21:22:36 -07002327 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002328 Slog.d(TAG, "Fallback: keyCode=" + fallbackAction.keyCode
2329 + " metaState=" + Integer.toHexString(fallbackAction.metaState));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002330 }
2331
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002332 final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK;
2333 fallbackEvent = KeyEvent.obtain(
Jeff Brown49ed71d2010-12-06 17:13:33 -08002334 event.getDownTime(), event.getEventTime(),
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002335 event.getAction(), fallbackAction.keyCode,
2336 event.getRepeatCount(), fallbackAction.metaState,
Jeff Brown49ed71d2010-12-06 17:13:33 -08002337 event.getDeviceId(), event.getScanCode(),
2338 flags, event.getSource(), null);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002339
2340 if (!interceptFallback(win, fallbackEvent, policyFlags)) {
2341 fallbackEvent.recycle();
2342 fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002343 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002344
2345 if (initialDown) {
2346 mFallbackActions.put(keyCode, fallbackAction);
2347 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2348 mFallbackActions.remove(keyCode);
2349 fallbackAction.recycle();
2350 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002351 }
2352 }
2353
Jeff Brown40013652012-05-16 21:22:36 -07002354 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002355 if (fallbackEvent == null) {
2356 Slog.d(TAG, "No fallback.");
2357 } else {
2358 Slog.d(TAG, "Performing fallback: " + fallbackEvent);
2359 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002360 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002361 return fallbackEvent;
Jeff Brown3915bb82010-11-05 15:02:16 -07002362 }
2363
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002364 private boolean interceptFallback(WindowState win, KeyEvent fallbackEvent, int policyFlags) {
Jeff Brown037c33e2014-04-09 00:31:55 -07002365 int actions = interceptKeyBeforeQueueing(fallbackEvent, policyFlags);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002366 if ((actions & ACTION_PASS_TO_USER) != 0) {
2367 long delayMillis = interceptKeyBeforeDispatching(
2368 win, fallbackEvent, policyFlags);
2369 if (delayMillis == 0) {
2370 return true;
2371 }
2372 }
2373 return false;
Jeff Brown6f2fba42011-02-19 01:08:02 -08002374 }
2375
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002376 private void launchAssistLongPressAction() {
2377 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
2378 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
2379
2380 // launch the search activity
2381 Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS);
2382 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2383 try {
Jim Miller45308b12012-06-18 19:23:39 -07002384 // TODO: This only stops the factory-installed search manager.
2385 // Need to formalize an API to handle others
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002386 SearchManager searchManager = getSearchManager();
2387 if (searchManager != null) {
2388 searchManager.stopSearch();
2389 }
Michael Wright43e27f72013-04-10 14:06:48 -07002390 mContext.startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002391 } catch (ActivityNotFoundException e) {
2392 Slog.w(TAG, "No activity to handle assist long press action.", e);
2393 }
2394 }
2395
2396 private void launchAssistAction() {
2397 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
Amith Yamasanic1d07a42012-08-14 09:32:02 -07002398 Intent intent = ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE))
Dianne Hackbornf9c5e0f2013-01-23 14:39:13 -08002399 .getAssistIntent(mContext, true, UserHandle.USER_CURRENT);
Jim Miller45308b12012-06-18 19:23:39 -07002400 if (intent != null) {
2401 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
2402 | Intent.FLAG_ACTIVITY_SINGLE_TOP
2403 | Intent.FLAG_ACTIVITY_CLEAR_TOP);
2404 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002405 mContext.startActivityAsUser(intent, UserHandle.CURRENT);
Jim Miller45308b12012-06-18 19:23:39 -07002406 } catch (ActivityNotFoundException e) {
2407 Slog.w(TAG, "No activity to handle assist action.", e);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002408 }
2409 }
2410 }
2411
2412 private SearchManager getSearchManager() {
2413 if (mSearchManager == null) {
2414 mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
2415 }
2416 return mSearchManager;
2417 }
2418
Jeff Browncaca8812013-05-09 13:34:33 -07002419 private void preloadRecentApps() {
2420 mPreloadedRecentApps = true;
2421 try {
2422 IStatusBarService statusbar = getStatusBarService();
2423 if (statusbar != null) {
2424 statusbar.preloadRecentApps();
2425 }
2426 } catch (RemoteException e) {
2427 Slog.e(TAG, "RemoteException when preloading recent apps", e);
2428 // re-acquire status bar service next time it is needed.
2429 mStatusBarService = null;
2430 }
2431 }
2432
2433 private void cancelPreloadRecentApps() {
2434 if (mPreloadedRecentApps) {
2435 mPreloadedRecentApps = false;
2436 try {
2437 IStatusBarService statusbar = getStatusBarService();
2438 if (statusbar != null) {
2439 statusbar.cancelPreloadRecentApps();
2440 }
2441 } catch (RemoteException e) {
2442 Slog.e(TAG, "RemoteException when showing recent apps", e);
2443 // re-acquire status bar service next time it is needed.
2444 mStatusBarService = null;
2445 }
2446 }
2447 }
2448
2449 private void toggleRecentApps() {
2450 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
2451 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_RECENT_APPS);
2452 try {
2453 IStatusBarService statusbar = getStatusBarService();
2454 if (statusbar != null) {
2455 statusbar.toggleRecentApps();
2456 }
2457 } catch (RemoteException e) {
2458 Slog.e(TAG, "RemoteException when showing recent apps", e);
2459 // re-acquire status bar service next time it is needed.
2460 mStatusBarService = null;
2461 }
2462 }
2463
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002464 /**
2465 * A home key -> launch home action was detected. Take the appropriate action
2466 * given the situation with the keyguard.
2467 */
2468 void launchHomeFromHotKey() {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01002469 if (mKeyguardDelegate != null && mKeyguardDelegate.isShowingAndNotOccluded()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002470 // don't launch home if keyguard showing
Jim Miller5ecd8112013-01-09 18:50:26 -08002471 } else if (!mHideLockScreen && mKeyguardDelegate.isInputRestricted()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002472 // when in keyguard restricted mode, must first verify unlock
2473 // before launching home
Jim Miller5ecd8112013-01-09 18:50:26 -08002474 mKeyguardDelegate.verifyUnlock(new OnKeyguardExitResult() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002475 public void onKeyguardExitResult(boolean success) {
2476 if (success) {
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07002477 try {
2478 ActivityManagerNative.getDefault().stopAppSwitches();
2479 } catch (RemoteException e) {
2480 }
Joe Onoratof275f0c2009-11-24 16:11:13 -05002481 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07002482 startDockOrHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002483 }
2484 }
2485 });
2486 } else {
2487 // no keyguard stuff to worry about, just launch home!
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07002488 try {
2489 ActivityManagerNative.getDefault().stopAppSwitches();
2490 } catch (RemoteException e) {
2491 }
Joe Onoratof275f0c2009-11-24 16:11:13 -05002492 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07002493 startDockOrHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002494 }
2495 }
2496
John Spurlock04db1762013-05-13 12:46:41 -04002497 private final Runnable mClearHideNavigationFlag = new Runnable() {
2498 @Override
2499 public void run() {
2500 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
2501 // Clear flags.
2502 mForceClearedSystemUiFlags &=
2503 ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
2504 }
2505 mWindowManagerFuncs.reevaluateStatusBarVisibility();
Dianne Hackborne26ab702011-10-16 13:21:33 -07002506 }
2507 };
2508
2509 /**
2510 * Input handler used while nav bar is hidden. Captures any touch on the screen,
2511 * to determine when the nav bar should be shown and prevent applications from
2512 * receiving those touches.
2513 */
Jeff Brown32cbc38552011-12-01 14:01:49 -08002514 final class HideNavInputEventReceiver extends InputEventReceiver {
2515 public HideNavInputEventReceiver(InputChannel inputChannel, Looper looper) {
2516 super(inputChannel, looper);
2517 }
2518
Dianne Hackborndf89e652011-10-06 22:35:11 -07002519 @Override
Jeff Brown32cbc38552011-12-01 14:01:49 -08002520 public void onInputEvent(InputEvent event) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07002521 boolean handled = false;
2522 try {
Jeff Brown4952dfd2011-11-30 19:23:22 -08002523 if (event instanceof MotionEvent
2524 && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
2525 final MotionEvent motionEvent = (MotionEvent)event;
2526 if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07002527 // When the user taps down, we re-show the nav bar.
2528 boolean changed = false;
John Spurlock04db1762013-05-13 12:46:41 -04002529 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002530 // Any user activity always causes us to show the
2531 // navigation controls, if they had been hidden.
2532 // We also clear the low profile and only content
2533 // flags so that tapping on the screen will atomically
2534 // restore all currently hidden screen decorations.
2535 int newVal = mResettingSystemUiFlags |
2536 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
2537 View.SYSTEM_UI_FLAG_LOW_PROFILE |
2538 View.SYSTEM_UI_FLAG_FULLSCREEN;
Dianne Hackborne26ab702011-10-16 13:21:33 -07002539 if (mResettingSystemUiFlags != newVal) {
2540 mResettingSystemUiFlags = newVal;
Dianne Hackborndf89e652011-10-06 22:35:11 -07002541 changed = true;
2542 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07002543 // We don't allow the system's nav bar to be hidden
2544 // again for 1 second, to prevent applications from
2545 // spamming us and keeping it from being shown.
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002546 newVal = mForceClearedSystemUiFlags |
2547 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
Dianne Hackborne26ab702011-10-16 13:21:33 -07002548 if (mForceClearedSystemUiFlags != newVal) {
2549 mForceClearedSystemUiFlags = newVal;
2550 changed = true;
John Spurlock04db1762013-05-13 12:46:41 -04002551 mHandler.postDelayed(mClearHideNavigationFlag, 1000);
Dianne Hackborne26ab702011-10-16 13:21:33 -07002552 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07002553 }
2554 if (changed) {
2555 mWindowManagerFuncs.reevaluateStatusBarVisibility();
2556 }
2557 }
2558 }
2559 } finally {
Jeff Brown32cbc38552011-12-01 14:01:49 -08002560 finishInputEvent(event, handled);
Dianne Hackborndf89e652011-10-06 22:35:11 -07002561 }
2562 }
Jeff Brown32cbc38552011-12-01 14:01:49 -08002563 }
2564 final InputEventReceiver.Factory mHideNavInputEventReceiverFactory =
2565 new InputEventReceiver.Factory() {
2566 @Override
2567 public InputEventReceiver createInputEventReceiver(
2568 InputChannel inputChannel, Looper looper) {
2569 return new HideNavInputEventReceiver(inputChannel, looper);
2570 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07002571 };
2572
2573 @Override
2574 public int adjustSystemUiVisibilityLw(int visibility) {
John Spurlock5b9145b2013-08-20 15:13:47 -04002575 mStatusBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
2576 mNavigationBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
John Spurlock27735a42013-08-14 17:57:38 -04002577
Dianne Hackborndf89e652011-10-06 22:35:11 -07002578 // Reset any bits in mForceClearingStatusBarVisibility that
2579 // are now clear.
Dianne Hackborne26ab702011-10-16 13:21:33 -07002580 mResettingSystemUiFlags &= visibility;
Dianne Hackborndf89e652011-10-06 22:35:11 -07002581 // Clear any bits in the new visibility that are currently being
2582 // force cleared, before reporting it.
Dianne Hackborne26ab702011-10-16 13:21:33 -07002583 return visibility & ~mResettingSystemUiFlags
2584 & ~mForceClearedSystemUiFlags;
Dianne Hackborndf89e652011-10-06 22:35:11 -07002585 }
2586
Craig Mautner69b08182012-09-05 13:07:13 -07002587 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002588 public void getContentInsetHintLw(WindowManager.LayoutParams attrs, Rect contentInset) {
John Spurlockc6d1c602014-01-17 15:22:06 -05002589 final int fl = PolicyControl.getWindowFlags(null, attrs);
John Spurlock1db8b682014-02-18 11:18:59 -05002590 final int sysuiVis = PolicyControl.getSystemUiVisibility(null, attrs);
2591 final int systemUiVisibility = (sysuiVis | attrs.subtreeSystemUiVisibility);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002592
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002593 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002594 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002595 int availRight, availBottom;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07002596 if (canHideNavigationBar() &&
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002597 (systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002598 availRight = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
2599 availBottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
2600 } else {
2601 availRight = mRestrictedScreenLeft + mRestrictedScreenWidth;
2602 availBottom = mRestrictedScreenTop + mRestrictedScreenHeight;
2603 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002604 if ((systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
2605 if ((fl & FLAG_FULLSCREEN) != 0) {
2606 contentInset.set(mStableFullscreenLeft, mStableFullscreenTop,
2607 availRight - mStableFullscreenRight,
2608 availBottom - mStableFullscreenBottom);
2609 } else {
2610 contentInset.set(mStableLeft, mStableTop,
2611 availRight - mStableRight, availBottom - mStableBottom);
2612 }
Dianne Hackbornc652de82013-02-15 16:32:56 -08002613 } else if ((fl & FLAG_FULLSCREEN) != 0 || (fl & FLAG_LAYOUT_IN_OVERSCAN) != 0) {
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002614 contentInset.setEmpty();
2615 } else if ((systemUiVisibility & (View.SYSTEM_UI_FLAG_FULLSCREEN
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002616 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)) == 0) {
2617 contentInset.set(mCurLeft, mCurTop,
2618 availRight - mCurRight, availBottom - mCurBottom);
2619 } else {
2620 contentInset.set(mCurLeft, mCurTop,
2621 availRight - mCurRight, availBottom - mCurBottom);
2622 }
2623 return;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002624 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002625 contentInset.setEmpty();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002626 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002627
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002628 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07002629 @Override
2630 public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight,
2631 int displayRotation) {
Dianne Hackbornc652de82013-02-15 16:32:56 -08002632 final int overscanLeft, overscanTop, overscanRight, overscanBottom;
2633 if (isDefaultDisplay) {
2634 switch (displayRotation) {
2635 case Surface.ROTATION_90:
2636 overscanLeft = mOverscanTop;
2637 overscanTop = mOverscanRight;
2638 overscanRight = mOverscanBottom;
2639 overscanBottom = mOverscanLeft;
2640 break;
2641 case Surface.ROTATION_180:
2642 overscanLeft = mOverscanRight;
2643 overscanTop = mOverscanBottom;
2644 overscanRight = mOverscanLeft;
2645 overscanBottom = mOverscanTop;
2646 break;
2647 case Surface.ROTATION_270:
2648 overscanLeft = mOverscanBottom;
2649 overscanTop = mOverscanLeft;
2650 overscanRight = mOverscanTop;
2651 overscanBottom = mOverscanRight;
2652 break;
2653 default:
2654 overscanLeft = mOverscanLeft;
2655 overscanTop = mOverscanTop;
2656 overscanRight = mOverscanRight;
2657 overscanBottom = mOverscanBottom;
2658 break;
2659 }
2660 } else {
2661 overscanLeft = 0;
2662 overscanTop = 0;
2663 overscanRight = 0;
2664 overscanBottom = 0;
2665 }
Dianne Hackborn313440842013-02-19 19:22:59 -08002666 mOverscanScreenLeft = mRestrictedOverscanScreenLeft = 0;
2667 mOverscanScreenTop = mRestrictedOverscanScreenTop = 0;
2668 mOverscanScreenWidth = mRestrictedOverscanScreenWidth = displayWidth;
2669 mOverscanScreenHeight = mRestrictedOverscanScreenHeight = displayHeight;
Dianne Hackbornc652de82013-02-15 16:32:56 -08002670 mSystemLeft = 0;
2671 mSystemTop = 0;
2672 mSystemRight = displayWidth;
2673 mSystemBottom = displayHeight;
2674 mUnrestrictedScreenLeft = overscanLeft;
2675 mUnrestrictedScreenTop = overscanTop;
2676 mUnrestrictedScreenWidth = displayWidth - overscanLeft - overscanRight;
2677 mUnrestrictedScreenHeight = displayHeight - overscanTop - overscanBottom;
2678 mRestrictedScreenLeft = mUnrestrictedScreenLeft;
2679 mRestrictedScreenTop = mUnrestrictedScreenTop;
John Spurlockad3e6cb2013-04-30 08:47:43 -04002680 mRestrictedScreenWidth = mSystemGestures.screenWidth = mUnrestrictedScreenWidth;
2681 mRestrictedScreenHeight = mSystemGestures.screenHeight = mUnrestrictedScreenHeight;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002682 mDockLeft = mContentLeft = mStableLeft = mStableFullscreenLeft
Dianne Hackbornc652de82013-02-15 16:32:56 -08002683 = mCurLeft = mUnrestrictedScreenLeft;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002684 mDockTop = mContentTop = mStableTop = mStableFullscreenTop
Dianne Hackbornc652de82013-02-15 16:32:56 -08002685 = mCurTop = mUnrestrictedScreenTop;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002686 mDockRight = mContentRight = mStableRight = mStableFullscreenRight
Dianne Hackbornc652de82013-02-15 16:32:56 -08002687 = mCurRight = displayWidth - overscanRight;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002688 mDockBottom = mContentBottom = mStableBottom = mStableFullscreenBottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08002689 = mCurBottom = displayHeight - overscanBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002690 mDockLayer = 0x10000000;
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002691 mStatusBarLayer = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002692
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002693 // start with the current dock rect, which will be (0,0,displayWidth,displayHeight)
2694 final Rect pf = mTmpParentFrame;
2695 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002696 final Rect of = mTmpOverscanFrame;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002697 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04002698 final Rect dcf = mTmpDecorFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002699 pf.left = df.left = of.left = vf.left = mDockLeft;
2700 pf.top = df.top = of.top = vf.top = mDockTop;
2701 pf.right = df.right = of.right = vf.right = mDockRight;
2702 pf.bottom = df.bottom = of.bottom = vf.bottom = mDockBottom;
John Spurlock46646232013-09-30 22:32:42 -04002703 dcf.setEmpty(); // Decor frame N/A for system bars.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002704
Craig Mautner69b08182012-09-05 13:07:13 -07002705 if (isDefaultDisplay) {
2706 // For purposes of putting out fake window up to steal focus, we will
2707 // drive nav being hidden only by whether it is requested.
John Spurlocke1f366f2013-08-05 12:22:40 -04002708 final int sysui = mLastSystemUiFlags;
2709 boolean navVisible = (sysui & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0;
John Spurlockbd957402013-10-03 11:38:39 -04002710 boolean navTranslucent = (sysui & View.NAVIGATION_BAR_TRANSLUCENT) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04002711 boolean immersive = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
2712 boolean immersiveSticky = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
2713 boolean navAllowedHidden = immersive || immersiveSticky;
2714 navTranslucent &= !immersiveSticky; // transient trumps translucent
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04002715 navTranslucent &= areTranslucentBarsAllowed();
Dianne Hackborne26ab702011-10-16 13:21:33 -07002716
Craig Mautner69b08182012-09-05 13:07:13 -07002717 // When the navigation bar isn't visible, we put up a fake
2718 // input window to catch all touch events. This way we can
2719 // detect when the user presses anywhere to bring back the nav
2720 // bar and ensure the application doesn't see the event.
John Spurlockf1a36642013-10-12 17:50:42 -04002721 if (navVisible || navAllowedHidden) {
Craig Mautner69b08182012-09-05 13:07:13 -07002722 if (mHideNavFakeWindow != null) {
2723 mHideNavFakeWindow.dismiss();
2724 mHideNavFakeWindow = null;
2725 }
2726 } else if (mHideNavFakeWindow == null) {
2727 mHideNavFakeWindow = mWindowManagerFuncs.addFakeWindow(
2728 mHandler.getLooper(), mHideNavInputEventReceiverFactory,
Adam Lesinski95c42972013-10-02 10:13:27 -07002729 "hidden nav", WindowManager.LayoutParams.TYPE_HIDDEN_NAV_CONSUMER, 0,
Craig Mautner69b08182012-09-05 13:07:13 -07002730 0, false, false, true);
Dianne Hackborne26ab702011-10-16 13:21:33 -07002731 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07002732
Craig Mautner69b08182012-09-05 13:07:13 -07002733 // For purposes of positioning and showing the nav bar, if we have
2734 // decided that it can't be hidden (because of the screen aspect ratio),
2735 // then take that into account.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07002736 navVisible |= !canHideNavigationBar();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002737
John Spurlockad3e6cb2013-04-30 08:47:43 -04002738 boolean updateSysUiVisibility = false;
Craig Mautner69b08182012-09-05 13:07:13 -07002739 if (mNavigationBar != null) {
John Spurlock27735a42013-08-14 17:57:38 -04002740 boolean transientNavBarShowing = mNavigationBarController.isTransientShowing();
Craig Mautner69b08182012-09-05 13:07:13 -07002741 // Force the navigation bar to its appropriate place and
2742 // size. We need to do this directly, instead of relying on
2743 // it to bubble up from the nav bar, because this needs to
2744 // change atomically with screen rotations.
2745 mNavigationBarOnBottom = (!mNavigationBarCanMove || displayWidth < displayHeight);
2746 if (mNavigationBarOnBottom) {
2747 // It's a system nav bar or a portrait screen; nav bar goes on bottom.
Dianne Hackbornc652de82013-02-15 16:32:56 -08002748 int top = displayHeight - overscanBottom
2749 - mNavigationBarHeightForRotation[displayRotation];
2750 mTmpNavigationFrame.set(0, top, displayWidth, displayHeight - overscanBottom);
Craig Mautner69b08182012-09-05 13:07:13 -07002751 mStableBottom = mStableFullscreenBottom = mTmpNavigationFrame.top;
John Spurlockf95b89a2013-10-10 22:10:42 -04002752 if (transientNavBarShowing) {
John Spurlock27735a42013-08-14 17:57:38 -04002753 mNavigationBarController.setBarShowingLw(true);
John Spurlockad3e6cb2013-04-30 08:47:43 -04002754 } else if (navVisible) {
John Spurlock27735a42013-08-14 17:57:38 -04002755 mNavigationBarController.setBarShowingLw(true);
Craig Mautner69b08182012-09-05 13:07:13 -07002756 mDockBottom = mTmpNavigationFrame.top;
Dianne Hackborn313440842013-02-19 19:22:59 -08002757 mRestrictedScreenHeight = mDockBottom - mRestrictedScreenTop;
2758 mRestrictedOverscanScreenHeight = mDockBottom - mRestrictedOverscanScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07002759 } else {
2760 // We currently want to hide the navigation UI.
John Spurlock27735a42013-08-14 17:57:38 -04002761 mNavigationBarController.setBarShowingLw(false);
Craig Mautner69b08182012-09-05 13:07:13 -07002762 }
John Spurlockc6d1c602014-01-17 15:22:06 -05002763 if (navVisible && !navTranslucent && !navAllowedHidden
2764 && !mNavigationBar.isAnimatingLw()
John Spurlockbd957402013-10-03 11:38:39 -04002765 && !mNavigationBarController.wasRecentlyTranslucent()) {
John Spurlocke1f366f2013-08-05 12:22:40 -04002766 // If the opaque nav bar is currently requested to be visible,
Craig Mautner69b08182012-09-05 13:07:13 -07002767 // and not in the process of animating on or off, then
2768 // we can tell the app that it is covered by it.
2769 mSystemBottom = mTmpNavigationFrame.top;
2770 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002771 } else {
Craig Mautner69b08182012-09-05 13:07:13 -07002772 // Landscape screen; nav bar goes to the right.
Dianne Hackbornc652de82013-02-15 16:32:56 -08002773 int left = displayWidth - overscanRight
2774 - mNavigationBarWidthForRotation[displayRotation];
2775 mTmpNavigationFrame.set(left, 0, displayWidth - overscanRight, displayHeight);
Craig Mautner69b08182012-09-05 13:07:13 -07002776 mStableRight = mStableFullscreenRight = mTmpNavigationFrame.left;
John Spurlockf95b89a2013-10-10 22:10:42 -04002777 if (transientNavBarShowing) {
John Spurlock27735a42013-08-14 17:57:38 -04002778 mNavigationBarController.setBarShowingLw(true);
John Spurlockad3e6cb2013-04-30 08:47:43 -04002779 } else if (navVisible) {
John Spurlock27735a42013-08-14 17:57:38 -04002780 mNavigationBarController.setBarShowingLw(true);
Craig Mautner69b08182012-09-05 13:07:13 -07002781 mDockRight = mTmpNavigationFrame.left;
Dianne Hackborn313440842013-02-19 19:22:59 -08002782 mRestrictedScreenWidth = mDockRight - mRestrictedScreenLeft;
2783 mRestrictedOverscanScreenWidth = mDockRight - mRestrictedOverscanScreenLeft;
Craig Mautner69b08182012-09-05 13:07:13 -07002784 } else {
2785 // We currently want to hide the navigation UI.
John Spurlock27735a42013-08-14 17:57:38 -04002786 mNavigationBarController.setBarShowingLw(false);
Craig Mautner69b08182012-09-05 13:07:13 -07002787 }
John Spurlockbd957402013-10-03 11:38:39 -04002788 if (navVisible && !navTranslucent && !mNavigationBar.isAnimatingLw()
2789 && !mNavigationBarController.wasRecentlyTranslucent()) {
Craig Mautner69b08182012-09-05 13:07:13 -07002790 // If the nav bar is currently requested to be visible,
2791 // and not in the process of animating on or off, then
2792 // we can tell the app that it is covered by it.
2793 mSystemRight = mTmpNavigationFrame.left;
2794 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002795 }
Craig Mautner69b08182012-09-05 13:07:13 -07002796 // Make sure the content and current rectangles are updated to
2797 // account for the restrictions from the navigation bar.
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002798 mContentTop = mCurTop = mDockTop;
2799 mContentBottom = mCurBottom = mDockBottom;
2800 mContentLeft = mCurLeft = mDockLeft;
2801 mContentRight = mCurRight = mDockRight;
Craig Mautner69b08182012-09-05 13:07:13 -07002802 mStatusBarLayer = mNavigationBar.getSurfaceLayer();
2803 // And compute the final frame.
2804 mNavigationBar.computeFrameLw(mTmpNavigationFrame, mTmpNavigationFrame,
John Spurlock46646232013-09-30 22:32:42 -04002805 mTmpNavigationFrame, mTmpNavigationFrame, mTmpNavigationFrame, dcf);
Craig Mautnereda67292013-04-28 13:50:14 -07002806 if (DEBUG_LAYOUT) Slog.i(TAG, "mNavigationBar frame: " + mTmpNavigationFrame);
John Spurlock27735a42013-08-14 17:57:38 -04002807 if (mNavigationBarController.checkHiddenLw()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04002808 updateSysUiVisibility = true;
2809 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002810 }
Craig Mautnereda67292013-04-28 13:50:14 -07002811 if (DEBUG_LAYOUT) Slog.i(TAG, String.format("mDock rect: (%d,%d - %d,%d)",
Craig Mautner69b08182012-09-05 13:07:13 -07002812 mDockLeft, mDockTop, mDockRight, mDockBottom));
2813
2814 // decide where the status bar goes ahead of time
2815 if (mStatusBar != null) {
2816 // apply any navigation bar insets
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002817 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
2818 pf.top = df.top = of.top = mUnrestrictedScreenTop;
2819 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
2820 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight
2821 + mUnrestrictedScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07002822 vf.left = mStableLeft;
2823 vf.top = mStableTop;
2824 vf.right = mStableRight;
2825 vf.bottom = mStableBottom;
2826
2827 mStatusBarLayer = mStatusBar.getSurfaceLayer();
2828
2829 // Let the status bar determine its size.
John Spurlock46646232013-09-30 22:32:42 -04002830 mStatusBar.computeFrameLw(pf, df, vf, vf, vf, dcf);
Craig Mautner69b08182012-09-05 13:07:13 -07002831
2832 // For layout, the status bar is always at the top with our fixed height.
2833 mStableTop = mUnrestrictedScreenTop + mStatusBarHeight;
2834
John Spurlocke1f366f2013-08-05 12:22:40 -04002835 boolean statusBarTransient = (sysui & View.STATUS_BAR_TRANSIENT) != 0;
John Spurlockbd957402013-10-03 11:38:39 -04002836 boolean statusBarTranslucent = (sysui & View.STATUS_BAR_TRANSLUCENT) != 0;
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04002837 statusBarTranslucent &= areTranslucentBarsAllowed();
John Spurlock32beb2c2013-03-11 10:16:47 -04002838
Craig Mautner69b08182012-09-05 13:07:13 -07002839 // If the status bar is hidden, we don't want to cause
2840 // windows behind it to scroll.
John Spurlockeda1f692013-09-16 11:38:44 -04002841 if (mStatusBar.isVisibleLw() && !statusBarTransient) {
Craig Mautner69b08182012-09-05 13:07:13 -07002842 // Status bar may go away, so the screen area it occupies
2843 // is available to apps but just covering them when the
2844 // status bar is visible.
2845 mDockTop = mUnrestrictedScreenTop + mStatusBarHeight;
2846
2847 mContentTop = mCurTop = mDockTop;
2848 mContentBottom = mCurBottom = mDockBottom;
2849 mContentLeft = mCurLeft = mDockLeft;
2850 mContentRight = mCurRight = mDockRight;
2851
Craig Mautnereda67292013-04-28 13:50:14 -07002852 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar: " +
Craig Mautner69b08182012-09-05 13:07:13 -07002853 String.format(
2854 "dock=[%d,%d][%d,%d] content=[%d,%d][%d,%d] cur=[%d,%d][%d,%d]",
2855 mDockLeft, mDockTop, mDockRight, mDockBottom,
2856 mContentLeft, mContentTop, mContentRight, mContentBottom,
2857 mCurLeft, mCurTop, mCurRight, mCurBottom));
2858 }
John Spurlocke1f366f2013-08-05 12:22:40 -04002859 if (mStatusBar.isVisibleLw() && !mStatusBar.isAnimatingLw()
John Spurlockbd957402013-10-03 11:38:39 -04002860 && !statusBarTransient && !statusBarTranslucent
2861 && !mStatusBarController.wasRecentlyTranslucent()) {
John Spurlocke1f366f2013-08-05 12:22:40 -04002862 // If the opaque status bar is currently requested to be visible,
Craig Mautner69b08182012-09-05 13:07:13 -07002863 // and not in the process of animating on or off, then
2864 // we can tell the app that it is covered by it.
2865 mSystemTop = mUnrestrictedScreenTop + mStatusBarHeight;
2866 }
John Spurlock27735a42013-08-14 17:57:38 -04002867 if (mStatusBarController.checkHiddenLw()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04002868 updateSysUiVisibility = true;
John Spurlock32beb2c2013-03-11 10:16:47 -04002869 }
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002870 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04002871 if (updateSysUiVisibility) {
2872 updateSystemUiVisibilityLw();
2873 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002874 }
2875 }
2876
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07002877 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07002878 @Override
John Spurlock46646232013-09-30 22:32:42 -04002879 public int getSystemDecorLayerLw() {
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07002880 if (mStatusBar != null) return mStatusBar.getSurfaceLayer();
2881 if (mNavigationBar != null) return mNavigationBar.getSurfaceLayer();
2882 return 0;
2883 }
2884
Craig Mautner967212c2013-04-13 21:10:58 -07002885 @Override
2886 public void getContentRectLw(Rect r) {
2887 r.set(mContentLeft, mContentTop, mContentRight, mContentBottom);
2888 }
2889
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002890 void setAttachedWindowFrames(WindowState win, int fl, int adjust, WindowState attached,
2891 boolean insetDecors, Rect pf, Rect df, Rect of, Rect cf, Rect vf) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002892 if (win.getSurfaceLayer() > mDockLayer && attached.getSurfaceLayer() < mDockLayer) {
2893 // Here's a special case: if this attached window is a panel that is
2894 // above the dock window, and the window it is attached to is below
2895 // the dock window, then the frames we computed for the window it is
2896 // attached to can not be used because the dock is effectively part
2897 // of the underlying window and the attached window is floating on top
2898 // of the whole thing. So, we ignore the attached window and explicitly
2899 // compute the frames that would be appropriate without the dock.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002900 df.left = of.left = cf.left = vf.left = mDockLeft;
2901 df.top = of.top = cf.top = vf.top = mDockTop;
2902 df.right = of.right = cf.right = vf.right = mDockRight;
2903 df.bottom = of.bottom = cf.bottom = vf.bottom = mDockBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002904 } else {
2905 // The effective display frame of the attached window depends on
2906 // whether it is taking care of insetting its content. If not,
2907 // we need to use the parent's content frame so that the entire
2908 // window is positioned within that content. Otherwise we can use
2909 // the display frame and let the attached window take care of
2910 // positioning its content appropriately.
Dianne Hackborndea3ef72010-10-28 14:24:22 -07002911 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002912 cf.set(attached.getOverscanFrameLw());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002913 } else {
2914 // If the window is resizing, then we want to base the content
2915 // frame on our attached content frame to resize... however,
2916 // things can be tricky if the attached window is NOT in resize
2917 // mode, in which case its content frame will be larger.
2918 // Ungh. So to deal with that, make sure the content frame
2919 // we end up using is not covering the IM dock.
2920 cf.set(attached.getContentFrameLw());
2921 if (attached.getSurfaceLayer() < mDockLayer) {
2922 if (cf.left < mContentLeft) cf.left = mContentLeft;
2923 if (cf.top < mContentTop) cf.top = mContentTop;
2924 if (cf.right > mContentRight) cf.right = mContentRight;
2925 if (cf.bottom > mContentBottom) cf.bottom = mContentBottom;
2926 }
2927 }
2928 df.set(insetDecors ? attached.getDisplayFrameLw() : cf);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002929 of.set(insetDecors ? attached.getOverscanFrameLw() : cf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002930 vf.set(attached.getVisibleFrameLw());
2931 }
2932 // The LAYOUT_IN_SCREEN flag is used to determine whether the attached
2933 // window should be positioned relative to its parent or the entire
2934 // screen.
2935 pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0
2936 ? attached.getFrameLw() : df);
2937 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002938
2939 private void applyStableConstraints(int sysui, int fl, Rect r) {
2940 if ((sysui & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
2941 // If app is requesting a stable layout, don't let the
2942 // content insets go below the stable values.
2943 if ((fl & FLAG_FULLSCREEN) != 0) {
2944 if (r.left < mStableFullscreenLeft) r.left = mStableFullscreenLeft;
2945 if (r.top < mStableFullscreenTop) r.top = mStableFullscreenTop;
2946 if (r.right > mStableFullscreenRight) r.right = mStableFullscreenRight;
2947 if (r.bottom > mStableFullscreenBottom) r.bottom = mStableFullscreenBottom;
2948 } else {
2949 if (r.left < mStableLeft) r.left = mStableLeft;
2950 if (r.top < mStableTop) r.top = mStableTop;
2951 if (r.right > mStableRight) r.right = mStableRight;
2952 if (r.bottom > mStableBottom) r.bottom = mStableBottom;
2953 }
2954 }
2955 }
2956
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002957 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07002958 @Override
Dianne Hackborn0ecadf72009-03-31 18:00:37 -07002959 public void layoutWindowLw(WindowState win, WindowManager.LayoutParams attrs,
2960 WindowState attached) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002961 // we've already done the status bar
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002962 if (win == mStatusBar || win == mNavigationBar) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002963 return;
2964 }
Craig Mautner69b08182012-09-05 13:07:13 -07002965 final boolean isDefaultDisplay = win.isDefaultDisplay();
2966 final boolean needsToOffsetInputMethodTarget = isDefaultDisplay &&
satok1bc0a492012-04-25 22:47:12 +09002967 (win == mLastInputMethodTargetWindow && mLastInputMethodWindow != null);
2968 if (needsToOffsetInputMethodTarget) {
Craig Mautnereda67292013-04-28 13:50:14 -07002969 if (DEBUG_LAYOUT) Slog.i(TAG, "Offset ime target window by the last ime window state");
satok1bc0a492012-04-25 22:47:12 +09002970 offsetInputMethodWindowLw(mLastInputMethodWindow);
2971 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002972
John Spurlockc6d1c602014-01-17 15:22:06 -05002973 final int fl = PolicyControl.getWindowFlags(win, attrs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002974 final int sim = attrs.softInputMode;
John Spurlock1db8b682014-02-18 11:18:59 -05002975 final int sysUiFl = PolicyControl.getSystemUiVisibility(win, null);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002976
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002977 final Rect pf = mTmpParentFrame;
2978 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002979 final Rect of = mTmpOverscanFrame;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002980 final Rect cf = mTmpContentFrame;
2981 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04002982 final Rect dcf = mTmpDecorFrame;
2983 dcf.setEmpty();
Craig Mautner69b08182012-09-05 13:07:13 -07002984
2985 final boolean hasNavBar = (isDefaultDisplay && mHasNavigationBar
Daniel Sandler36412a72011-08-04 09:35:13 -04002986 && mNavigationBar != null && mNavigationBar.isVisibleLw());
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002987
Craig Mautnerf683b562012-10-02 11:10:57 -07002988 final int adjust = sim & SOFT_INPUT_MASK_ADJUST;
2989
Craig Mautner69b08182012-09-05 13:07:13 -07002990 if (!isDefaultDisplay) {
2991 if (attached != null) {
2992 // If this window is attached to another, our display
2993 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002994 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07002995 } else {
2996 // Give the window full screen.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002997 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
2998 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
2999 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08003000 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003001 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003002 = mOverscanScreenTop + mOverscanScreenHeight;
Craig Mautner69b08182012-09-05 13:07:13 -07003003 }
3004 } else if (attrs.type == TYPE_INPUT_METHOD) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003005 pf.left = df.left = of.left = cf.left = vf.left = mDockLeft;
3006 pf.top = df.top = of.top = cf.top = vf.top = mDockTop;
3007 pf.right = df.right = of.right = cf.right = vf.right = mDockRight;
John Spurlockc68d5772013-10-08 11:47:58 -04003008 // IM dock windows layout below the nav bar...
John Spurlock57beb3b2013-10-10 10:27:44 -04003009 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlockc68d5772013-10-08 11:47:58 -04003010 // ...with content insets above the nav bar
3011 cf.bottom = vf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003012 // IM dock windows always go to the bottom of the screen.
3013 attrs.gravity = Gravity.BOTTOM;
3014 mDockLayer = win.getSurfaceLayer();
3015 } else {
John Spurlock46646232013-09-30 22:32:42 -04003016
3017 // Default policy decor for the default display
3018 dcf.left = mSystemLeft;
3019 dcf.top = mSystemTop;
3020 dcf.right = mSystemRight;
3021 dcf.bottom = mSystemBottom;
John Spurlockbd957402013-10-03 11:38:39 -04003022 final boolean inheritTranslucentDecor = (attrs.privateFlags
3023 & WindowManager.LayoutParams.PRIVATE_FLAG_INHERIT_TRANSLUCENT_DECOR) != 0;
John Spurlock65567d42013-10-08 10:08:32 -04003024 final boolean isAppWindow =
3025 attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW &&
3026 attrs.type <= WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
3027 final boolean topAtRest =
3028 win == mTopFullscreenOpaqueWindowState && !win.isAnimatingLw();
3029 if (isAppWindow && !inheritTranslucentDecor && !topAtRest) {
John Spurlockbd957402013-10-03 11:38:39 -04003030 if ((sysUiFl & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0
3031 && (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0
3032 && (fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04003033 // Ensure policy decor includes status bar
3034 dcf.top = mStableTop;
3035 }
John Spurlockbd957402013-10-03 11:38:39 -04003036 if ((fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) == 0
John Spurlock8e0ca282013-10-03 11:46:06 -04003037 && (sysUiFl & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04003038 // Ensure policy decor includes navigation bar
3039 dcf.bottom = mStableBottom;
3040 dcf.right = mStableRight;
3041 }
3042 }
3043
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003044 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
3045 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
Craig Mautnereda67292013-04-28 13:50:14 -07003046 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003047 + "): IN_SCREEN, INSET_DECOR");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003048 // This is the case for a normal activity window: we want it
3049 // to cover all of the screen space, and it can take care of
3050 // moving its contents to account for screen decorations that
3051 // intrude into that space.
3052 if (attached != null) {
3053 // If this window is attached to another, our display
3054 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003055 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003056 } else {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003057 if (attrs.type == TYPE_STATUS_BAR_PANEL
3058 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Joe Onorato29fc2c92010-11-24 10:26:50 -08003059 // Status bar panels are the only windows who can go on top of
3060 // the status bar. They are protected by the STATUS_BAR_SERVICE
3061 // permission, so they have the same privileges as the status
3062 // bar itself.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003063 //
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003064 // However, they should still dodge the navigation bar if it exists.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003065
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003066 pf.left = df.left = of.left = hasNavBar
3067 ? mDockLeft : mUnrestrictedScreenLeft;
3068 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3069 pf.right = df.right = of.right = hasNavBar
3070 ? mRestrictedScreenLeft+mRestrictedScreenWidth
3071 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3072 pf.bottom = df.bottom = of.bottom = hasNavBar
3073 ? mRestrictedScreenTop+mRestrictedScreenHeight
3074 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003075
Craig Mautnereda67292013-04-28 13:50:14 -07003076 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003077 "Laying out status bar window: (%d,%d - %d,%d)",
3078 pf.left, pf.top, pf.right, pf.bottom));
John Spurlock46646232013-09-30 22:32:42 -04003079 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08003080 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3081 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3082 // Asking to layout into the overscan region, so give it that pure
3083 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003084 pf.left = df.left = of.left = mOverscanScreenLeft;
3085 pf.top = df.top = of.top = mOverscanScreenTop;
3086 pf.right = df.right = of.right = mOverscanScreenLeft + mOverscanScreenWidth;
3087 pf.bottom = df.bottom = of.bottom = mOverscanScreenTop
3088 + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003089 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003090 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003091 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3092 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003093 // Asking for layout as if the nav bar is hidden, lets the
Dianne Hackbornc652de82013-02-15 16:32:56 -08003094 // application extend into the unrestricted overscan screen area. We
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003095 // only do this for application windows to ensure no window that
3096 // can be above the nav bar can do this.
Dianne Hackborn313440842013-02-19 19:22:59 -08003097 pf.left = df.left = mOverscanScreenLeft;
3098 pf.top = df.top = mOverscanScreenTop;
3099 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
3100 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003101 // We need to tell the app about where the frame inside the overscan
3102 // is, so it can inset its content by that amount -- it didn't ask
3103 // to actually extend itself into the overscan region.
3104 of.left = mUnrestrictedScreenLeft;
3105 of.top = mUnrestrictedScreenTop;
3106 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3107 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003108 } else {
Dianne Hackborn313440842013-02-19 19:22:59 -08003109 pf.left = df.left = mRestrictedOverscanScreenLeft;
3110 pf.top = df.top = mRestrictedOverscanScreenTop;
3111 pf.right = df.right = mRestrictedOverscanScreenLeft
3112 + mRestrictedOverscanScreenWidth;
3113 pf.bottom = df.bottom = mRestrictedOverscanScreenTop
3114 + mRestrictedOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003115 // We need to tell the app about where the frame inside the overscan
3116 // is, so it can inset its content by that amount -- it didn't ask
3117 // to actually extend itself into the overscan region.
3118 of.left = mUnrestrictedScreenLeft;
3119 of.top = mUnrestrictedScreenTop;
3120 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3121 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003122 }
Craig Mautner69b08182012-09-05 13:07:13 -07003123
John Spurlock46646232013-09-30 22:32:42 -04003124 if ((fl & FLAG_FULLSCREEN) == 0) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003125 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
3126 cf.left = mDockLeft;
3127 cf.top = mDockTop;
3128 cf.right = mDockRight;
3129 cf.bottom = mDockBottom;
3130 } else {
3131 cf.left = mContentLeft;
3132 cf.top = mContentTop;
3133 cf.right = mContentRight;
3134 cf.bottom = mContentBottom;
3135 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003136 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003137 // Full screen windows are always given a layout that is as if the
3138 // status bar and other transient decors are gone. This is to avoid
3139 // bad states when moving from a window that is not hding the
3140 // status bar to one that is.
3141 cf.left = mRestrictedScreenLeft;
3142 cf.top = mRestrictedScreenTop;
3143 cf.right = mRestrictedScreenLeft + mRestrictedScreenWidth;
3144 cf.bottom = mRestrictedScreenTop + mRestrictedScreenHeight;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003145 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003146 applyStableConstraints(sysUiFl, fl, cf);
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003147 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3148 vf.left = mCurLeft;
3149 vf.top = mCurTop;
3150 vf.right = mCurRight;
3151 vf.bottom = mCurBottom;
3152 } else {
3153 vf.set(cf);
3154 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003155 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003156 } else if ((fl & FLAG_LAYOUT_IN_SCREEN) != 0 || (sysUiFl
3157 & (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
3158 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)) != 0) {
Craig Mautnereda67292013-04-28 13:50:14 -07003159 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3160 "): IN_SCREEN");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003161 // A window that has requested to fill the entire screen just
3162 // gets everything, period.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003163 if (attrs.type == TYPE_STATUS_BAR_PANEL
3164 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003165 pf.left = df.left = of.left = cf.left = hasNavBar
3166 ? mDockLeft : mUnrestrictedScreenLeft;
3167 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
3168 pf.right = df.right = of.right = cf.right = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003169 ? mRestrictedScreenLeft+mRestrictedScreenWidth
Dianne Hackbornc652de82013-02-15 16:32:56 -08003170 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003171 pf.bottom = df.bottom = of.bottom = cf.bottom = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003172 ? mRestrictedScreenTop+mRestrictedScreenHeight
Dianne Hackbornc652de82013-02-15 16:32:56 -08003173 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07003174 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler36412a72011-08-04 09:35:13 -04003175 "Laying out IN_SCREEN status bar window: (%d,%d - %d,%d)",
3176 pf.left, pf.top, pf.right, pf.bottom));
Jim Millere898ac52012-04-06 17:10:57 -07003177 } else if (attrs.type == TYPE_NAVIGATION_BAR
3178 || attrs.type == TYPE_NAVIGATION_BAR_PANEL) {
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003179 // The navigation bar has Real Ultimate Power.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003180 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3181 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3182 pf.right = df.right = of.right = mUnrestrictedScreenLeft
3183 + mUnrestrictedScreenWidth;
3184 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop
3185 + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07003186 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003187 "Laying out navigation bar window: (%d,%d - %d,%d)",
3188 pf.left, pf.top, pf.right, pf.bottom));
Dianne Hackborn01011c32012-02-21 13:54:21 -08003189 } else if ((attrs.type == TYPE_SECURE_SYSTEM_OVERLAY
3190 || attrs.type == TYPE_BOOT_PROGRESS)
Jeff Brownbfcb60a2011-09-08 18:51:14 -07003191 && ((fl & FLAG_FULLSCREEN) != 0)) {
3192 // Fullscreen secure system overlays get what they ask for.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003193 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3194 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3195 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
3196 + mOverscanScreenWidth;
3197 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
3198 + mOverscanScreenHeight;
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07003199 } else if (attrs.type == TYPE_BOOT_PROGRESS
3200 || attrs.type == TYPE_UNIVERSE_BACKGROUND) {
Dianne Hackborn01011c32012-02-21 13:54:21 -08003201 // Boot progress screen always covers entire display.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003202 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3203 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3204 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
3205 + mOverscanScreenWidth;
3206 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
3207 + mOverscanScreenHeight;
John Spurlockef4adae2013-08-26 17:58:58 -04003208 } else if (attrs.type == TYPE_WALLPAPER) {
3209 // The wallpaper also has Real Ultimate Power.
3210 pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft;
3211 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003212 pf.right = df.right = of.right = cf.right
John Spurlockef4adae2013-08-26 17:58:58 -04003213 = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003214 pf.bottom = df.bottom = of.bottom = cf.bottom
John Spurlockef4adae2013-08-26 17:58:58 -04003215 = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlock46646232013-09-30 22:32:42 -04003216 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08003217 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3218 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3219 // Asking to layout into the overscan region, so give it that pure
3220 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003221 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3222 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3223 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08003224 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003225 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003226 = mOverscanScreenTop + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003227 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003228 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
John Spurlock34e13d92013-08-10 06:52:28 -04003229 && (attrs.type == TYPE_TOAST
3230 || (attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3231 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW))) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003232 // Asking for layout as if the nav bar is hidden, lets the
3233 // application extend into the unrestricted screen area. We
John Spurlock34e13d92013-08-10 06:52:28 -04003234 // only do this for application windows (or toasts) to ensure no window that
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003235 // can be above the nav bar can do this.
3236 // XXX This assumes that an app asking for this will also
3237 // ask for layout in only content. We can't currently figure out
3238 // what the screen would be if only laying out to hide the nav bar.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003239 pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft;
3240 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
3241 pf.right = df.right = of.right = cf.right = mUnrestrictedScreenLeft
3242 + mUnrestrictedScreenWidth;
3243 pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop
3244 + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003245 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003246 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
3247 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
3248 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
3249 + mRestrictedScreenWidth;
3250 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
3251 + mRestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003252 }
Craig Mautner69b08182012-09-05 13:07:13 -07003253
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003254 applyStableConstraints(sysUiFl, fl, cf);
Craig Mautner69b08182012-09-05 13:07:13 -07003255
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003256 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3257 vf.left = mCurLeft;
3258 vf.top = mCurTop;
3259 vf.right = mCurRight;
3260 vf.bottom = mCurBottom;
3261 } else {
3262 vf.set(cf);
3263 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003264 } else if (attached != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07003265 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3266 "): attached to " + attached);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003267 // A child window should be placed inside of the same visible
3268 // frame that its parent had.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003269 setAttachedWindowFrames(win, fl, adjust, attached, false, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003270 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07003271 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3272 "): normal window");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003273 // Otherwise, a normal window must be placed inside the content
3274 // of all screen decorations.
Dianne Hackborna239c842011-06-01 12:28:20 -07003275 if (attrs.type == TYPE_STATUS_BAR_PANEL) {
3276 // Status bar panels are the only windows who can go on top of
3277 // the status bar. They are protected by the STATUS_BAR_SERVICE
3278 // permission, so they have the same privileges as the status
3279 // bar itself.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003280 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
3281 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
3282 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
3283 + mRestrictedScreenWidth;
3284 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
3285 + mRestrictedScreenHeight;
John Spurlock414c1f02013-12-04 13:47:36 -05003286 } else if (attrs.type == TYPE_TOAST || attrs.type == TYPE_SYSTEM_ALERT
3287 || attrs.type == TYPE_VOLUME_OVERLAY) {
3288 // These dialogs are stable to interim decor changes.
John Spurlockbd957402013-10-03 11:38:39 -04003289 pf.left = df.left = of.left = cf.left = mStableLeft;
3290 pf.top = df.top = of.top = cf.top = mStableTop;
3291 pf.right = df.right = of.right = cf.right = mStableRight;
3292 pf.bottom = df.bottom = of.bottom = cf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003293 } else {
Dianne Hackborna239c842011-06-01 12:28:20 -07003294 pf.left = mContentLeft;
3295 pf.top = mContentTop;
3296 pf.right = mContentRight;
3297 pf.bottom = mContentBottom;
3298 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003299 df.left = of.left = cf.left = mDockLeft;
3300 df.top = of.top = cf.top = mDockTop;
3301 df.right = of.right = cf.right = mDockRight;
3302 df.bottom = of.bottom = cf.bottom = mDockBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07003303 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003304 df.left = of.left = cf.left = mContentLeft;
3305 df.top = of.top = cf.top = mContentTop;
3306 df.right = of.right = cf.right = mContentRight;
3307 df.bottom = of.bottom = cf.bottom = mContentBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07003308 }
3309 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3310 vf.left = mCurLeft;
3311 vf.top = mCurTop;
3312 vf.right = mCurRight;
3313 vf.bottom = mCurBottom;
3314 } else {
3315 vf.set(cf);
3316 }
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003317 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003318 }
3319 }
Craig Mautner69b08182012-09-05 13:07:13 -07003320
Craig Mautnerb816bed2013-07-23 10:26:17 -07003321 // TYPE_SYSTEM_ERROR is above the NavigationBar so it can't be allowed to extend over it.
3322 if ((fl & FLAG_LAYOUT_NO_LIMITS) != 0 && attrs.type != TYPE_SYSTEM_ERROR) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003323 df.left = df.top = of.left = of.top = cf.left = cf.top = vf.left = vf.top = -10000;
3324 df.right = df.bottom = of.right = of.bottom = cf.right = cf.bottom
3325 = vf.right = vf.bottom = 10000;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003326 }
3327
Craig Mautnereda67292013-04-28 13:50:14 -07003328 if (DEBUG_LAYOUT) Slog.v(TAG, "Compute frame " + attrs.getTitle()
The Android Open Source Project11267662009-03-18 17:39:47 -07003329 + ": sim=#" + Integer.toHexString(sim)
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003330 + " attach=" + attached + " type=" + attrs.type
3331 + String.format(" flags=0x%08x", fl)
The Android Open Source Project11267662009-03-18 17:39:47 -07003332 + " pf=" + pf.toShortString() + " df=" + df.toShortString()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003333 + " of=" + of.toShortString()
John Spurlock46646232013-09-30 22:32:42 -04003334 + " cf=" + cf.toShortString() + " vf=" + vf.toShortString()
3335 + " dcf=" + dcf.toShortString());
Craig Mautner69b08182012-09-05 13:07:13 -07003336
John Spurlock46646232013-09-30 22:32:42 -04003337 win.computeFrameLw(pf, df, of, cf, vf, dcf);
Craig Mautner69b08182012-09-05 13:07:13 -07003338
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003339 // Dock windows carve out the bottom of the screen, so normal windows
3340 // can't appear underneath them.
Craig Mautner8bd206b2012-10-03 10:32:02 -07003341 if (attrs.type == TYPE_INPUT_METHOD && win.isVisibleOrBehindKeyguardLw()
3342 && !win.getGivenInsetsPendingLw()) {
satok1bc0a492012-04-25 22:47:12 +09003343 setLastInputMethodWindowLw(null, null);
3344 offsetInputMethodWindowLw(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003345 }
3346 }
3347
satok1bc0a492012-04-25 22:47:12 +09003348 private void offsetInputMethodWindowLw(WindowState win) {
3349 int top = win.getContentFrameLw().top;
3350 top += win.getGivenContentInsetsLw().top;
3351 if (mContentBottom > top) {
3352 mContentBottom = top;
3353 }
3354 top = win.getVisibleFrameLw().top;
3355 top += win.getGivenVisibleInsetsLw().top;
3356 if (mCurBottom > top) {
3357 mCurBottom = top;
3358 }
Craig Mautnereda67292013-04-28 13:50:14 -07003359 if (DEBUG_LAYOUT) Slog.v(TAG, "Input method: mDockBottom="
satok1bc0a492012-04-25 22:47:12 +09003360 + mDockBottom + " mContentBottom="
3361 + mContentBottom + " mCurBottom=" + mCurBottom);
3362 }
3363
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003364 /** {@inheritDoc} */
Craig Mautner61ac6bb2012-02-02 17:29:33 -08003365 @Override
3366 public void finishLayoutLw() {
3367 return;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003368 }
3369
3370 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003371 @Override
Craig Mautner39834192012-09-02 07:47:24 -07003372 public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) {
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003373 mTopFullscreenOpaqueWindowState = null;
Craig Mautner2bc789b2014-03-19 19:48:38 -07003374 mAppsToBeHidden.clear();
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003375 mForceStatusBar = false;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003376 mForceStatusBarFromKeyguard = false;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08003377 mForcingShowNavBar = false;
3378 mForcingShowNavBarLayer = -1;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003379
3380 mHideLockScreen = false;
3381 mAllowLockscreenWhenOn = false;
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003382 mDismissKeyguard = DISMISS_KEYGUARD_NONE;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003383 mShowingLockscreen = false;
3384 mShowingDream = false;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003385 }
3386
3387 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003388 @Override
Craig Mautner39834192012-09-02 07:47:24 -07003389 public void applyPostLayoutPolicyLw(WindowState win,
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003390 WindowManager.LayoutParams attrs) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07003391 if (DEBUG_LAYOUT) Slog.i(TAG, "Win " + win + ": isVisibleOrBehindKeyguardLw="
3392 + win.isVisibleOrBehindKeyguardLw());
John Spurlockc6d1c602014-01-17 15:22:06 -05003393 final int fl = PolicyControl.getWindowFlags(win, attrs);
John Spurlock414c1f02013-12-04 13:47:36 -05003394 if (mTopFullscreenOpaqueWindowState == null
3395 && win.isVisibleLw() && attrs.type == TYPE_INPUT_METHOD) {
3396 mForcingShowNavBar = true;
3397 mForcingShowNavBarLayer = win.getSurfaceLayer();
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08003398 }
Jorim Jaggiafd4a552014-04-08 15:13:05 +02003399 if (attrs.type == TYPE_STATUS_BAR && (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Jorim Jaggiafd4a552014-04-08 15:13:05 +02003400 mForceStatusBarFromKeyguard = true;
3401 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003402 if (mTopFullscreenOpaqueWindowState == null &&
Dianne Hackborn01b02a72012-01-12 14:05:03 -08003403 win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()) {
John Spurlockc6d1c602014-01-17 15:22:06 -05003404 if ((fl & FLAG_FORCE_NOT_FULLSCREEN) != 0) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003405 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003406 mForceStatusBarFromKeyguard = true;
3407 } else {
3408 mForceStatusBar = true;
3409 }
3410 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003411 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003412 mShowingLockscreen = true;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07003413 }
Craig Mautnerab55e522014-03-03 13:26:03 -08003414 boolean appWindow = attrs.type >= FIRST_APPLICATION_WINDOW
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003415 && attrs.type <= LAST_APPLICATION_WINDOW;
3416 if (attrs.type == TYPE_DREAM) {
Jeff Brownc8018eb2012-10-29 21:33:27 -07003417 // If the lockscreen was showing when the dream started then wait
3418 // for the dream to draw before hiding the lockscreen.
3419 if (!mDreamingLockscreen
3420 || (win.isVisibleLw() && win.hasDrawnLw())) {
3421 mShowingDream = true;
Craig Mautnerab55e522014-03-03 13:26:03 -08003422 appWindow = true;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003423 }
3424 }
Craig Mautnerab55e522014-03-03 13:26:03 -08003425
Craig Mautner00156ec2014-03-06 22:29:02 -08003426 final boolean showWhenLocked = (fl & FLAG_SHOW_WHEN_LOCKED) != 0;
Craig Mautner74ee9382014-04-01 15:20:16 -07003427 final boolean dismissKeyguard = (fl & FLAG_DISMISS_KEYGUARD) != 0;
Craig Mautnerab55e522014-03-03 13:26:03 -08003428 if (appWindow) {
Craig Mautner4bdab6b2014-04-01 12:05:11 -07003429 if (showWhenLocked || (dismissKeyguard && !isKeyguardSecure())) {
Craig Mautner2bc789b2014-03-19 19:48:38 -07003430 mAppsToBeHidden.remove(win.getAppToken());
3431 } else {
3432 mAppsToBeHidden.add(win.getAppToken());
3433 }
Craig Mautnerab55e522014-03-03 13:26:03 -08003434 if (attrs.x == 0 && attrs.y == 0
3435 && attrs.width == WindowManager.LayoutParams.MATCH_PARENT
3436 && attrs.height == WindowManager.LayoutParams.MATCH_PARENT) {
3437 if (DEBUG_LAYOUT) Slog.v(TAG, "Fullscreen window: " + win);
3438 mTopFullscreenOpaqueWindowState = win;
Craig Mautner2bc789b2014-03-19 19:48:38 -07003439 if (mAppsToBeHidden.isEmpty()) {
Craig Mautnerda09ae32014-03-03 13:26:03 -08003440 if (showWhenLocked) {
3441 if (DEBUG_LAYOUT) Slog.v(TAG,
3442 "Setting mHideLockScreen to true by win " + win);
3443 mHideLockScreen = true;
3444 mForceStatusBarFromKeyguard = false;
3445 }
Craig Mautner4bdab6b2014-04-01 12:05:11 -07003446 if (dismissKeyguard && mDismissKeyguard == DISMISS_KEYGUARD_NONE) {
Craig Mautnerda09ae32014-03-03 13:26:03 -08003447 if (DEBUG_LAYOUT) Slog.v(TAG,
3448 "Setting mDismissKeyguard true by win " + win);
3449 mDismissKeyguard = mWinDismissingKeyguard == win ?
3450 DISMISS_KEYGUARD_CONTINUE : DISMISS_KEYGUARD_START;
3451 mWinDismissingKeyguard = win;
3452 mForceStatusBarFromKeyguard = mShowingLockscreen && isKeyguardSecure();
3453 }
Craig Mautnerab55e522014-03-03 13:26:03 -08003454 }
Craig Mautner00156ec2014-03-06 22:29:02 -08003455 if ((fl & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) {
Craig Mautnerab55e522014-03-03 13:26:03 -08003456 mAllowLockscreenWhenOn = true;
3457 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003458 }
3459 }
3460 }
3461 }
3462
3463 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003464 @Override
Craig Mautner39834192012-09-02 07:47:24 -07003465 public int finishPostLayoutPolicyLw() {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003466 int changes = 0;
Joe Onorato93056472010-09-10 10:30:46 -04003467 boolean topIsFullscreen = false;
Daniel Sandlere02d8082010-10-08 15:13:22 -04003468
3469 final WindowManager.LayoutParams lp = (mTopFullscreenOpaqueWindowState != null)
3470 ? mTopFullscreenOpaqueWindowState.getAttrs()
3471 : null;
3472
Jeff Brownc8018eb2012-10-29 21:33:27 -07003473 // If we are not currently showing a dream then remember the current
3474 // lockscreen state. We will use this to determine whether the dream
3475 // started while the lockscreen was showing and remember this state
3476 // while the dream is showing.
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003477 if (!mShowingDream) {
3478 mDreamingLockscreen = mShowingLockscreen;
3479 }
3480
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003481 if (mStatusBar != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07003482 if (DEBUG_LAYOUT) Slog.i(TAG, "force=" + mForceStatusBar
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003483 + " forcefkg=" + mForceStatusBarFromKeyguard
Dianne Hackbornd70bc2f2009-10-06 23:25:51 -07003484 + " top=" + mTopFullscreenOpaqueWindowState);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003485 if (mForceStatusBar || mForceStatusBarFromKeyguard) {
Craig Mautnereda67292013-04-28 13:50:14 -07003486 if (DEBUG_LAYOUT) Slog.v(TAG, "Showing status bar: forced");
John Spurlock27735a42013-08-14 17:57:38 -04003487 if (mStatusBarController.setBarShowingLw(true)) {
3488 changes |= FINISH_LAYOUT_REDO_LAYOUT;
3489 }
Craig Mautner81defc72013-10-29 11:10:42 -07003490 // Maintain fullscreen layout until incoming animation is complete.
3491 topIsFullscreen = mTopIsFullscreen && mStatusBar.isAnimatingLw();
John Spurlockf92b6162013-11-11 15:01:16 -05003492 // Transient status bar on the lockscreen is not allowed
3493 if (mForceStatusBarFromKeyguard && mStatusBarController.isTransientShowing()) {
3494 mStatusBarController.updateVisibilityLw(false /*transientAllowed*/,
3495 mLastSystemUiFlags, mLastSystemUiFlags);
3496 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003497 } else if (mTopFullscreenOpaqueWindowState != null) {
John Spurlockc6d1c602014-01-17 15:22:06 -05003498 final int fl = PolicyControl.getWindowFlags(null, lp);
Joe Onorato93056472010-09-10 10:30:46 -04003499 if (localLOGV) {
Craig Mautnereda67292013-04-28 13:50:14 -07003500 Slog.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw()
Joe Onorato93056472010-09-10 10:30:46 -04003501 + " shown frame: " + mTopFullscreenOpaqueWindowState.getShownFrameLw());
Craig Mautnereda67292013-04-28 13:50:14 -07003502 Slog.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs()
John Spurlockc6d1c602014-01-17 15:22:06 -05003503 + " lp.flags=0x" + Integer.toHexString(fl));
Joe Onorato93056472010-09-10 10:30:46 -04003504 }
John Spurlockc6d1c602014-01-17 15:22:06 -05003505 topIsFullscreen = (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003506 || (mLastSystemUiFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
Joe Onorato93056472010-09-10 10:30:46 -04003507 // The subtle difference between the window for mTopFullscreenOpaqueWindowState
3508 // and mTopIsFullscreen is that that mTopIsFullscreen is set only if the window
3509 // has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the
3510 // case though.
John Spurlock27735a42013-08-14 17:57:38 -04003511 if (mStatusBarController.isTransientShowing()) {
3512 if (mStatusBarController.setBarShowingLw(true)) {
John Spurlock32beb2c2013-03-11 10:16:47 -04003513 changes |= FINISH_LAYOUT_REDO_LAYOUT;
3514 }
3515 } else if (topIsFullscreen) {
Craig Mautnereda67292013-04-28 13:50:14 -07003516 if (DEBUG_LAYOUT) Slog.v(TAG, "** HIDING status bar");
John Spurlock27735a42013-08-14 17:57:38 -04003517 if (mStatusBarController.setBarShowingLw(false)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003518 changes |= FINISH_LAYOUT_REDO_LAYOUT;
Craig Mautnereda67292013-04-28 13:50:14 -07003519 } else {
Craig Mautnerc5a6e442013-06-05 17:22:35 -07003520 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar already hiding");
Daniel Sandler40427442010-07-16 11:44:52 -04003521 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003522 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07003523 if (DEBUG_LAYOUT) Slog.v(TAG, "** SHOWING status bar: top is not fullscreen");
John Spurlock27735a42013-08-14 17:57:38 -04003524 if (mStatusBarController.setBarShowingLw(true)) {
3525 changes |= FINISH_LAYOUT_REDO_LAYOUT;
3526 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003527 }
3528 }
3529 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04003530
Craig Mautner81defc72013-10-29 11:10:42 -07003531 if (mTopIsFullscreen != topIsFullscreen) {
3532 if (!topIsFullscreen) {
3533 // Force another layout when status bar becomes fully shown.
3534 changes |= FINISH_LAYOUT_REDO_LAYOUT;
3535 }
3536 mTopIsFullscreen = topIsFullscreen;
3537 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04003538
Craig Mautner39834192012-09-02 07:47:24 -07003539 // Hide the key guard if a visible window explicitly specifies that it wants to be
3540 // displayed when the screen is locked.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01003541 if (mKeyguardDelegate != null && mStatusBar != null) {
3542 if (localLOGV) Slog.v(TAG, "finishPostLayoutPolicyLw: mHideKeyguard="
3543 + mHideLockScreen);
3544 if (mDismissKeyguard != DISMISS_KEYGUARD_NONE && !isKeyguardSecure()) {
3545 mKeyguardHidden = true;
3546 if (processKeyguardSetHiddenResultLw(mKeyguardDelegate.setOccluded(true))) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003547 changes |= FINISH_LAYOUT_REDO_LAYOUT
3548 | FINISH_LAYOUT_REDO_CONFIG
3549 | FINISH_LAYOUT_REDO_WALLPAPER;
3550 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01003551 if (mKeyguardDelegate.isShowing()) {
3552 mHandler.post(new Runnable() {
3553 @Override
3554 public void run() {
3555 mKeyguardDelegate.keyguardDone(false, false);
3556 }
3557 });
3558 }
3559 } else if (mHideLockScreen) {
3560 mKeyguardHidden = true;
3561 if (processKeyguardSetHiddenResultLw(mKeyguardDelegate.setOccluded(true))) {
3562 changes |= FINISH_LAYOUT_REDO_LAYOUT
3563 | FINISH_LAYOUT_REDO_CONFIG
3564 | FINISH_LAYOUT_REDO_WALLPAPER;
3565 }
3566 } else if (mDismissKeyguard != DISMISS_KEYGUARD_NONE) {
3567 // This is the case of keyguard isSecure() and not mHideLockScreen.
3568 if (mDismissKeyguard == DISMISS_KEYGUARD_START) {
3569 // Only launch the next keyguard unlock window once per window.
3570 mKeyguardHidden = false;
3571 if (processKeyguardSetHiddenResultLw(mKeyguardDelegate.setOccluded(false))) {
3572 changes |= FINISH_LAYOUT_REDO_LAYOUT
3573 | FINISH_LAYOUT_REDO_CONFIG
3574 | FINISH_LAYOUT_REDO_WALLPAPER;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003575 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01003576 mHandler.post(new Runnable() {
3577 @Override
3578 public void run() {
3579 mKeyguardDelegate.dismiss();
3580 }
3581 });
3582 }
3583 } else {
3584 mWinDismissingKeyguard = null;
3585 mKeyguardHidden = false;
3586 if (processKeyguardSetHiddenResultLw(mKeyguardDelegate.setOccluded(false))) {
3587 changes |= FINISH_LAYOUT_REDO_LAYOUT
3588 | FINISH_LAYOUT_REDO_CONFIG
3589 | FINISH_LAYOUT_REDO_WALLPAPER;
3590 }
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -07003591 }
3592 }
Joe Onorato664644d2011-01-23 17:53:23 -08003593
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003594 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003595 // If the navigation bar has been hidden or shown, we need to do another
3596 // layout pass to update that window.
3597 changes |= FINISH_LAYOUT_REDO_LAYOUT;
3598 }
Joe Onorato664644d2011-01-23 17:53:23 -08003599
Mike Lockwood28569302010-01-28 11:54:40 -05003600 // update since mAllowLockscreenWhenOn might have changed
3601 updateLockScreenTimeout();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003602 return changes;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003603 }
3604
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003605 /**
Jorim Jaggi5cf17872014-03-26 18:31:48 +01003606 * Processes the result code of {@link IKeyguardService#setOccluded}. This is needed because we
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003607 * immediately need to put the wallpaper directly behind the Keyguard when a window with flag
3608 * {@link android.view.WindowManager.LayoutParams#FLAG_SHOW_WHEN_LOCKED} gets dismissed. If we
3609 * would wait for Keyguard to change the flags, that would be running asynchronously and thus be
3610 * too late so the user might see the window behind.
3611 *
Jorim Jaggi5cf17872014-03-26 18:31:48 +01003612 * @param setHiddenResult The result code from {@link IKeyguardService#setOccluded}.
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003613 * @return Whether the flags have changed and we have to redo the layout.
3614 */
3615 private boolean processKeyguardSetHiddenResultLw(int setHiddenResult) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01003616 if (setHiddenResult
3617 == IKeyguardServiceConstants.KEYGUARD_SERVICE_SET_OCCLUDED_RESULT_SET_FLAGS) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003618 mStatusBar.getAttrs().privateFlags |= PRIVATE_FLAG_KEYGUARD;
3619 mStatusBar.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
3620 return true;
3621 } else if (setHiddenResult
Jorim Jaggi5cf17872014-03-26 18:31:48 +01003622 == IKeyguardServiceConstants.KEYGUARD_SERVICE_SET_OCCLUDED_RESULT_UNSET_FLAGS) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003623 mStatusBar.getAttrs().privateFlags &= ~PRIVATE_FLAG_KEYGUARD;
3624 mStatusBar.getAttrs().flags &= ~FLAG_SHOW_WALLPAPER;
3625 return true;
3626 } else {
3627 return false;
3628 }
3629 }
3630
3631 private boolean isStatusBarKeyguard() {
3632 return mStatusBar != null
3633 && (mStatusBar.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
3634 }
3635
Dianne Hackborn08743722009-12-21 12:16:51 -08003636 public boolean allowAppAnimationsLw() {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003637 if (isStatusBarKeyguard() || mShowingDream) {
Craig Mautner28816302013-10-10 20:31:00 -07003638 // If keyguard or dreams is currently visible, no reason to animate behind it.
Dianne Hackborn08743722009-12-21 12:16:51 -08003639 return false;
3640 }
Dianne Hackborn08743722009-12-21 12:16:51 -08003641 return true;
3642 }
3643
Dianne Hackborndf89e652011-10-06 22:35:11 -07003644 public int focusChangedLw(WindowState lastFocus, WindowState newFocus) {
Joe Onorato664644d2011-01-23 17:53:23 -08003645 mFocusedWindow = newFocus;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003646 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003647 // If the navigation bar has been hidden or shown, we need to do another
3648 // layout pass to update that window.
3649 return FINISH_LAYOUT_REDO_LAYOUT;
3650 }
3651 return 0;
Joe Onorato664644d2011-01-23 17:53:23 -08003652 }
3653
Dianne Hackborn0ecadf72009-03-31 18:00:37 -07003654 /** {@inheritDoc} */
Jeff Brown46b9ac02010-04-22 18:58:52 -07003655 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
3656 // lid changed state
Jeff Brownc458ce92012-04-30 14:58:40 -07003657 final int newLidState = lidOpen ? LID_OPEN : LID_CLOSED;
3658 if (newLidState == mLidState) {
3659 return;
3660 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07003661
Jeff Brownc458ce92012-04-30 14:58:40 -07003662 mLidState = newLidState;
3663 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07003664 updateRotation(true);
Jeff Brownc458ce92012-04-30 14:58:40 -07003665
3666 if (lidOpen) {
Jim Millere51cf7ae2013-06-25 18:31:56 -07003667 mPowerManager.wakeUp(SystemClock.uptimeMillis());
Jeff Brownc458ce92012-04-30 14:58:40 -07003668 } else if (!mLidControlsSleep) {
Jeff Brown96307042012-07-27 15:51:34 -07003669 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
Jeff Brown46b9ac02010-04-22 18:58:52 -07003670 }
3671 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003672
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08003673 void setHdmiPlugged(boolean plugged) {
3674 if (mHdmiPlugged != plugged) {
3675 mHdmiPlugged = plugged;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003676 updateRotation(true, true);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08003677 Intent intent = new Intent(ACTION_HDMI_PLUGGED);
Joe Onoratodc100302011-01-11 17:07:41 -08003678 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08003679 intent.putExtra(EXTRA_HDMI_PLUGGED_STATE, plugged);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07003680 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08003681 }
3682 }
3683
Joe Onoratoea495d42011-04-06 11:41:11 -07003684 void initializeHdmiState() {
Joe Onorato7ba631f2011-05-04 15:28:00 -07003685 boolean plugged = false;
Joe Onoratoea495d42011-04-06 11:41:11 -07003686 // watch for HDMI plug messages if the hdmi switch exists
3687 if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) {
3688 mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi");
3689
Joe Onoratoea495d42011-04-06 11:41:11 -07003690 final String filename = "/sys/class/switch/hdmi/state";
3691 FileReader reader = null;
3692 try {
3693 reader = new FileReader(filename);
3694 char[] buf = new char[15];
3695 int n = reader.read(buf);
3696 if (n > 1) {
3697 plugged = 0 != Integer.parseInt(new String(buf, 0, n-1));
3698 }
3699 } catch (IOException ex) {
3700 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
3701 } catch (NumberFormatException ex) {
3702 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
3703 } finally {
3704 if (reader != null) {
3705 try {
3706 reader.close();
3707 } catch (IOException ex) {
3708 }
Joe Onoratodc100302011-01-11 17:07:41 -08003709 }
3710 }
3711 }
Joe Onorato7ba631f2011-05-04 15:28:00 -07003712 // This dance forces the code in setHdmiPlugged to run.
3713 // Always do this so the sticky intent is stuck (to false) if there is no hdmi.
3714 mHdmiPlugged = !plugged;
3715 setHdmiPlugged(!mHdmiPlugged);
Joe Onoratodc100302011-01-11 17:07:41 -08003716 }
3717
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003718 /**
Jean-Michel Trivifca1e602013-10-10 18:12:59 -07003719 * @return Whether music is being played right now "locally" (e.g. on the device's speakers
3720 * or wired headphones) or "remotely" (e.g. on a device using the Cast protocol and
3721 * controlled by this device, or through remote submix).
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003722 */
3723 boolean isMusicActive() {
Eric Laurent413cb9d2009-07-17 11:52:43 -07003724 final AudioManager am = (AudioManager)mContext.getSystemService(Context.AUDIO_SERVICE);
3725 if (am == null) {
3726 Log.w(TAG, "isMusicActive: couldn't get AudioManager reference");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003727 return false;
3728 }
Jean-Michel Trivifca1e602013-10-10 18:12:59 -07003729 return am.isLocalOrRemoteMusicActive();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003730 }
3731
3732 /**
3733 * Tell the audio service to adjust the volume appropriate to the event.
3734 * @param keycode
3735 */
Mike Lockwooda53e3812009-09-25 10:51:39 -04003736 void handleVolumeKey(int stream, int keycode) {
Jeff Brown4d396052010-10-29 21:50:21 -07003737 IAudioService audioService = getAudioService();
3738 if (audioService == null) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003739 return;
3740 }
3741 try {
Jean-Michel Trivifca1e602013-10-10 18:12:59 -07003742 // when audio is playing locally, we shouldn't have to hold a wake lock
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003743 // during the call, but we do it as a precaution for the rare possibility
Jean-Michel Trivifca1e602013-10-10 18:12:59 -07003744 // that the music stops right before we call this.
3745 // Otherwise we might also be in a remote playback case.
Jeff Brownb0418da2010-11-01 15:24:01 -07003746 // TODO: Actually handle MUTE.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003747 mBroadcastWakeLock.acquire();
Jean-Michel Trivifca1e602013-10-10 18:12:59 -07003748 if (stream == AudioSystem.STREAM_MUSIC) {
3749 audioService.adjustLocalOrRemoteStreamVolume(stream,
3750 keycode == KeyEvent.KEYCODE_VOLUME_UP
3751 ? AudioManager.ADJUST_RAISE
3752 : AudioManager.ADJUST_LOWER,
3753 mContext.getOpPackageName());
3754 } else {
3755 audioService.adjustStreamVolume(stream,
3756 keycode == KeyEvent.KEYCODE_VOLUME_UP
3757 ? AudioManager.ADJUST_RAISE
3758 : AudioManager.ADJUST_LOWER,
3759 0,
3760 mContext.getOpPackageName());
3761 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003762 } catch (RemoteException e) {
Jean-Michel Trivifca1e602013-10-10 18:12:59 -07003763 Log.w(TAG, "IAudioService.adjust*StreamVolume() threw RemoteException " + e);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003764 } finally {
3765 mBroadcastWakeLock.release();
3766 }
3767 }
Jeff Brown4d396052010-10-29 21:50:21 -07003768
Dianne Hackbornc0e3f242011-08-19 14:19:10 -07003769 final Object mScreenshotLock = new Object();
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07003770 ServiceConnection mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07003771
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003772 final Runnable mScreenshotTimeout = new Runnable() {
3773 @Override public void run() {
3774 synchronized (mScreenshotLock) {
3775 if (mScreenshotConnection != null) {
3776 mContext.unbindService(mScreenshotConnection);
3777 mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07003778 }
Winson Chung9112ec32011-06-27 13:15:32 -07003779 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003780 }
3781 };
3782
3783 // Assume this is called from the Handler thread.
3784 private void takeScreenshot() {
3785 synchronized (mScreenshotLock) {
3786 if (mScreenshotConnection != null) {
3787 return;
3788 }
3789 ComponentName cn = new ComponentName("com.android.systemui",
3790 "com.android.systemui.screenshot.TakeScreenshotService");
3791 Intent intent = new Intent();
3792 intent.setComponent(cn);
3793 ServiceConnection conn = new ServiceConnection() {
3794 @Override
3795 public void onServiceConnected(ComponentName name, IBinder service) {
3796 synchronized (mScreenshotLock) {
3797 if (mScreenshotConnection != this) {
3798 return;
3799 }
3800 Messenger messenger = new Messenger(service);
3801 Message msg = Message.obtain(null, 1);
3802 final ServiceConnection myConn = this;
3803 Handler h = new Handler(mHandler.getLooper()) {
3804 @Override
3805 public void handleMessage(Message msg) {
3806 synchronized (mScreenshotLock) {
3807 if (mScreenshotConnection == myConn) {
3808 mContext.unbindService(mScreenshotConnection);
3809 mScreenshotConnection = null;
3810 mHandler.removeCallbacks(mScreenshotTimeout);
3811 }
3812 }
3813 }
3814 };
3815 msg.replyTo = new Messenger(h);
Winson Chunga63bb842011-10-17 10:26:28 -07003816 msg.arg1 = msg.arg2 = 0;
3817 if (mStatusBar != null && mStatusBar.isVisibleLw())
3818 msg.arg1 = 1;
3819 if (mNavigationBar != null && mNavigationBar.isVisibleLw())
3820 msg.arg2 = 1;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003821 try {
3822 messenger.send(msg);
3823 } catch (RemoteException e) {
3824 }
3825 }
3826 }
3827 @Override
3828 public void onServiceDisconnected(ComponentName name) {}
3829 };
Amith Yamasani27b89e62013-01-16 12:30:11 -08003830 if (mContext.bindServiceAsUser(
3831 intent, conn, Context.BIND_AUTO_CREATE, UserHandle.CURRENT)) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003832 mScreenshotConnection = conn;
3833 mHandler.postDelayed(mScreenshotTimeout, 10000);
3834 }
3835 }
Winson Chung9112ec32011-06-27 13:15:32 -07003836 }
3837
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003838 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003839 @Override
Jeff Brown037c33e2014-04-09 00:31:55 -07003840 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) {
Jeff Brown96307042012-07-27 15:51:34 -07003841 if (!mSystemBooted) {
3842 // If we have not yet booted, don't let key events do anything.
3843 return 0;
3844 }
3845
Jeff Brown037c33e2014-04-09 00:31:55 -07003846 final boolean interactive = (policyFlags & FLAG_INTERACTIVE) != 0;
Jeff Brown1f245102010-11-18 20:53:46 -08003847 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
3848 final boolean canceled = event.isCanceled();
3849 final int keyCode = event.getKeyCode();
Jeff Browne20c9e02010-10-11 14:20:19 -07003850
Jeff Brown3122e442010-10-11 23:32:49 -07003851 final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0;
Jeff Brown3122e442010-10-11 23:32:49 -07003852
Mike Lockwoodc72b15f2009-11-28 20:58:22 -05003853 // If screen is off then we treat the case where the keyguard is open but hidden
3854 // the same as if it were open and in front.
3855 // This will prevent any keys other than the power button from waking the screen
3856 // when the keyguard is hidden by another activity.
Jim Miller5ecd8112013-01-09 18:50:26 -08003857 final boolean keyguardActive = (mKeyguardDelegate == null ? false :
Jeff Brown037c33e2014-04-09 00:31:55 -07003858 (interactive ?
Jorim Jaggi5cf17872014-03-26 18:31:48 +01003859 mKeyguardDelegate.isShowingAndNotOccluded() :
Jim Miller5ecd8112013-01-09 18:50:26 -08003860 mKeyguardDelegate.isShowing()));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003861
Jeff Brown40013652012-05-16 21:22:36 -07003862 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003863 Log.d(TAG, "interceptKeyTq keycode=" + keyCode
Jeff Brown037c33e2014-04-09 00:31:55 -07003864 + " interactive=" + interactive + " keyguardActive=" + keyguardActive
Jeff Brown26875502014-01-30 21:47:47 -08003865 + " policyFlags=" + Integer.toHexString(policyFlags));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003866 }
3867
Jeff Brown98392ef2011-09-12 18:24:59 -07003868 if (down && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0
3869 && event.getRepeatCount() == 0) {
Jeff Brown4d396052010-10-29 21:50:21 -07003870 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
3871 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003872
Jeff Brown037c33e2014-04-09 00:31:55 -07003873 // Basic policy based on interactive state.
Jeff Brown4d396052010-10-29 21:50:21 -07003874 int result;
Michael Wright337d9d22014-04-22 15:03:48 -07003875 boolean isWakeKey = (policyFlags & WindowManagerPolicy.FLAG_WAKE) != 0
3876 || event.isWakeKey();
Jeff Brown037c33e2014-04-09 00:31:55 -07003877 if (interactive || (isInjected && !isWakeKey)) {
Jeff Brown4d396052010-10-29 21:50:21 -07003878 // When the screen is on or if the key is injected pass the key to the application.
3879 result = ACTION_PASS_TO_USER;
3880 } else {
3881 // When the screen is off and the key is not injected, determine whether
3882 // to wake the device but don't pass the key to the application.
3883 result = 0;
Jeff Brown26875502014-01-30 21:47:47 -08003884 if (isWakeKey && (!down || !isWakeKeyWhenScreenOff(keyCode))) {
3885 isWakeKey = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003886 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003887 }
3888
Justin Kohd378ad72013-04-01 12:18:26 -07003889 // If the key would be handled globally, just return the result, don't worry about special
3890 // key processing.
3891 if (mGlobalKeyManager.shouldHandleGlobalKey(keyCode, event)) {
3892 return result;
3893 }
3894
Jeff Brown4d396052010-10-29 21:50:21 -07003895 // Handle special keys.
3896 switch (keyCode) {
3897 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jeff Brownb0418da2010-11-01 15:24:01 -07003898 case KeyEvent.KEYCODE_VOLUME_UP:
3899 case KeyEvent.KEYCODE_VOLUME_MUTE: {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003900 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
3901 if (down) {
Jeff Brown037c33e2014-04-09 00:31:55 -07003902 if (interactive && !mVolumeDownKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003903 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
3904 mVolumeDownKeyTriggered = true;
3905 mVolumeDownKeyTime = event.getDownTime();
3906 mVolumeDownKeyConsumedByScreenshotChord = false;
3907 cancelPendingPowerKeyAction();
3908 interceptScreenshotChord();
3909 }
3910 } else {
3911 mVolumeDownKeyTriggered = false;
3912 cancelPendingScreenshotChordAction();
3913 }
3914 } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
3915 if (down) {
Jeff Brown037c33e2014-04-09 00:31:55 -07003916 if (interactive && !mVolumeUpKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003917 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
3918 mVolumeUpKeyTriggered = true;
3919 cancelPendingPowerKeyAction();
3920 cancelPendingScreenshotChordAction();
3921 }
3922 } else {
3923 mVolumeUpKeyTriggered = false;
3924 cancelPendingScreenshotChordAction();
3925 }
3926 }
Jeff Brown4d396052010-10-29 21:50:21 -07003927 if (down) {
3928 ITelephony telephonyService = getTelephonyService();
3929 if (telephonyService != null) {
3930 try {
3931 if (telephonyService.isRinging()) {
3932 // If an incoming call is ringing, either VOLUME key means
3933 // "silence ringer". We handle these keys here, rather than
3934 // in the InCallScreen, to make sure we'll respond to them
3935 // even if the InCallScreen hasn't come to the foreground yet.
3936 // Look for the DOWN event here, to agree with the "fallback"
3937 // behavior in the InCallScreen.
3938 Log.i(TAG, "interceptKeyBeforeQueueing:"
3939 + " VOLUME key-down while ringing: Silence ringer!");
3940
3941 // Silence the ringer. (It's safe to call this
3942 // even if the ringer has already been silenced.)
3943 telephonyService.silenceRinger();
3944
3945 // And *don't* pass this key thru to the current activity
3946 // (which is probably the InCallScreen.)
3947 result &= ~ACTION_PASS_TO_USER;
3948 break;
3949 }
3950 if (telephonyService.isOffhook()
3951 && (result & ACTION_PASS_TO_USER) == 0) {
3952 // If we are in call but we decided not to pass the key to
3953 // the application, handle the volume change here.
3954 handleVolumeKey(AudioManager.STREAM_VOICE_CALL, keyCode);
3955 break;
3956 }
3957 } catch (RemoteException ex) {
3958 Log.w(TAG, "ITelephony threw RemoteException", ex);
3959 }
3960 }
3961
3962 if (isMusicActive() && (result & ACTION_PASS_TO_USER) == 0) {
3963 // If music is playing but we decided not to pass the key to the
3964 // application, handle the volume change here.
3965 handleVolumeKey(AudioManager.STREAM_MUSIC, keyCode);
3966 break;
3967 }
3968 }
3969 break;
3970 }
3971
3972 case KeyEvent.KEYCODE_ENDCALL: {
3973 result &= ~ACTION_PASS_TO_USER;
3974 if (down) {
3975 ITelephony telephonyService = getTelephonyService();
3976 boolean hungUp = false;
3977 if (telephonyService != null) {
3978 try {
3979 hungUp = telephonyService.endCall();
3980 } catch (RemoteException ex) {
3981 Log.w(TAG, "ITelephony threw RemoteException", ex);
3982 }
3983 }
Jeff Brown037c33e2014-04-09 00:31:55 -07003984 interceptPowerKeyDown(!interactive || hungUp);
Jeff Brown4d396052010-10-29 21:50:21 -07003985 } else {
3986 if (interceptPowerKeyUp(canceled)) {
3987 if ((mEndcallBehavior
3988 & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) {
3989 if (goHome()) {
3990 break;
Dianne Hackborn0041e972009-07-24 17:14:43 -07003991 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003992 }
Jeff Brown4d396052010-10-29 21:50:21 -07003993 if ((mEndcallBehavior
3994 & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) {
Jeff Brown26875502014-01-30 21:47:47 -08003995 mPowerManager.goToSleep(event.getEventTime());
3996 isWakeKey = false;
Jeff Brown4d396052010-10-29 21:50:21 -07003997 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003998 }
Jeff Brown4d396052010-10-29 21:50:21 -07003999 }
4000 break;
4001 }
4002
4003 case KeyEvent.KEYCODE_POWER: {
4004 result &= ~ACTION_PASS_TO_USER;
4005 if (down) {
Jeff Brown26c6a502014-04-11 02:15:54 -07004006 boolean panic = mImmersiveModeConfirmation.onPowerKeyDown(interactive,
John Spurlockd9b70bd2014-02-06 17:02:44 -05004007 event.getDownTime(), isImmersiveMode(mLastSystemUiFlags));
4008 if (panic) {
4009 mHandler.post(mRequestTransientNav);
4010 }
Jeff Brown037c33e2014-04-09 00:31:55 -07004011 if (interactive && !mPowerKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004012 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
4013 mPowerKeyTriggered = true;
4014 mPowerKeyTime = event.getDownTime();
4015 interceptScreenshotChord();
Winson Chung9112ec32011-06-27 13:15:32 -07004016 }
Winson Chung9112ec32011-06-27 13:15:32 -07004017
Jeff Brown4d396052010-10-29 21:50:21 -07004018 ITelephony telephonyService = getTelephonyService();
4019 boolean hungUp = false;
4020 if (telephonyService != null) {
4021 try {
4022 if (telephonyService.isRinging()) {
4023 // Pressing Power while there's a ringing incoming
4024 // call should silence the ringer.
4025 telephonyService.silenceRinger();
4026 } else if ((mIncallPowerBehavior
4027 & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0
Jeff Brown26c6a502014-04-11 02:15:54 -07004028 && telephonyService.isOffhook() && interactive) {
Jeff Brown4d396052010-10-29 21:50:21 -07004029 // Otherwise, if "Power button ends call" is enabled,
4030 // the Power button will hang up any current active call.
4031 hungUp = telephonyService.endCall();
4032 }
4033 } catch (RemoteException ex) {
4034 Log.w(TAG, "ITelephony threw RemoteException", ex);
4035 }
4036 }
Jeff Brown037c33e2014-04-09 00:31:55 -07004037 interceptPowerKeyDown(!interactive || hungUp
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004038 || mVolumeDownKeyTriggered || mVolumeUpKeyTriggered);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004039 } else {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004040 mPowerKeyTriggered = false;
4041 cancelPendingScreenshotChordAction();
4042 if (interceptPowerKeyUp(canceled || mPendingPowerKeyUpCanceled)) {
Jeff Brown26875502014-01-30 21:47:47 -08004043 mPowerManager.goToSleep(event.getEventTime());
4044 isWakeKey = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004045 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004046 mPendingPowerKeyUpCanceled = false;
Jeff Brown4d396052010-10-29 21:50:21 -07004047 }
4048 break;
4049 }
4050
Jeff Brown6212a492014-03-07 13:58:47 -08004051 case KeyEvent.KEYCODE_SLEEP: {
4052 result &= ~ACTION_PASS_TO_USER;
4053 mPowerManager.goToSleep(event.getEventTime());
4054 isWakeKey = false;
4055 break;
4056 }
4057
4058 case KeyEvent.KEYCODE_WAKEUP: {
4059 result &= ~ACTION_PASS_TO_USER;
4060 break;
4061 }
4062
Jeff Brown4d396052010-10-29 21:50:21 -07004063 case KeyEvent.KEYCODE_MEDIA_PLAY:
4064 case KeyEvent.KEYCODE_MEDIA_PAUSE:
4065 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
4066 if (down) {
4067 ITelephony telephonyService = getTelephonyService();
4068 if (telephonyService != null) {
4069 try {
4070 if (!telephonyService.isIdle()) {
4071 // Suppress PLAY/PAUSE toggle when phone is ringing or in-call
4072 // to avoid music playback.
4073 break;
4074 }
4075 } catch (RemoteException ex) {
4076 Log.w(TAG, "ITelephony threw RemoteException", ex);
Jeff Brown3122e442010-10-11 23:32:49 -07004077 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004078 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004079 }
Jeff Brown4d396052010-10-29 21:50:21 -07004080 case KeyEvent.KEYCODE_HEADSETHOOK:
4081 case KeyEvent.KEYCODE_MUTE:
4082 case KeyEvent.KEYCODE_MEDIA_STOP:
4083 case KeyEvent.KEYCODE_MEDIA_NEXT:
4084 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
4085 case KeyEvent.KEYCODE_MEDIA_REWIND:
4086 case KeyEvent.KEYCODE_MEDIA_RECORD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09004087 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
4088 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: {
Jeff Brown4d396052010-10-29 21:50:21 -07004089 if ((result & ACTION_PASS_TO_USER) == 0) {
4090 // Only do this if we would otherwise not pass it to the user. In that
4091 // case, the PhoneWindow class will do the same thing, except it will
4092 // only do it if the showing app doesn't process the key on its own.
Jeff Brown40013652012-05-16 21:22:36 -07004093 // Note that we need to make a copy of the key event here because the
4094 // original key event will be recycled when we return.
Jeff Brown4d396052010-10-29 21:50:21 -07004095 mBroadcastWakeLock.acquire();
Jeff Brown40013652012-05-16 21:22:36 -07004096 Message msg = mHandler.obtainMessage(MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK,
4097 new KeyEvent(event));
4098 msg.setAsynchronous(true);
4099 msg.sendToTarget();
Jeff Brown4d396052010-10-29 21:50:21 -07004100 }
4101 break;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004102 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004103
Jeff Brown4d396052010-10-29 21:50:21 -07004104 case KeyEvent.KEYCODE_CALL: {
4105 if (down) {
4106 ITelephony telephonyService = getTelephonyService();
4107 if (telephonyService != null) {
4108 try {
4109 if (telephonyService.isRinging()) {
4110 Log.i(TAG, "interceptKeyBeforeQueueing:"
4111 + " CALL key-down while ringing: Answer the call!");
4112 telephonyService.answerRingingCall();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004113
Jeff Brown4d396052010-10-29 21:50:21 -07004114 // And *don't* pass this key thru to the current activity
4115 // (which is presumably the InCallScreen.)
4116 result &= ~ACTION_PASS_TO_USER;
4117 }
4118 } catch (RemoteException ex) {
4119 Log.w(TAG, "ITelephony threw RemoteException", ex);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004120 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004121 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004122 }
Jeff Brown4d396052010-10-29 21:50:21 -07004123 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004124 }
4125 }
Jeff Brown26875502014-01-30 21:47:47 -08004126
4127 if (isWakeKey) {
4128 mPowerManager.wakeUp(event.getEventTime());
4129 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004130 return result;
4131 }
4132
Jeff Brown1c2e4942012-11-06 16:32:01 -08004133 /**
4134 * When the screen is off we ignore some keys that might otherwise typically
4135 * be considered wake keys. We filter them out here.
4136 *
4137 * {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it
4138 * is always considered a wake key.
4139 */
4140 private boolean isWakeKeyWhenScreenOff(int keyCode) {
4141 switch (keyCode) {
4142 // ignore volume keys unless docked
4143 case KeyEvent.KEYCODE_VOLUME_UP:
4144 case KeyEvent.KEYCODE_VOLUME_DOWN:
4145 case KeyEvent.KEYCODE_VOLUME_MUTE:
4146 return mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED;
4147
4148 // ignore media and camera keys
4149 case KeyEvent.KEYCODE_MUTE:
4150 case KeyEvent.KEYCODE_HEADSETHOOK:
4151 case KeyEvent.KEYCODE_MEDIA_PLAY:
4152 case KeyEvent.KEYCODE_MEDIA_PAUSE:
4153 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
4154 case KeyEvent.KEYCODE_MEDIA_STOP:
4155 case KeyEvent.KEYCODE_MEDIA_NEXT:
4156 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
4157 case KeyEvent.KEYCODE_MEDIA_REWIND:
4158 case KeyEvent.KEYCODE_MEDIA_RECORD:
4159 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09004160 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK:
Jeff Brown1c2e4942012-11-06 16:32:01 -08004161 case KeyEvent.KEYCODE_CAMERA:
4162 return false;
4163 }
4164 return true;
4165 }
4166
4167
Jeff Brown56194eb2011-03-02 19:23:13 -08004168 /** {@inheritDoc} */
4169 @Override
Jeff Brown037c33e2014-04-09 00:31:55 -07004170 public int interceptWakeMotionBeforeQueueing(long whenNanos, int policyFlags) {
4171 // We already know this is a wake motion so just wake up.
4172 // Note that we would observe policyFlags containing
4173 // FLAG_WAKE and FLAG_INTERACTIVE here.
4174 mPowerManager.wakeUp(whenNanos / 1000000);
4175 return 0;
Jeff Brown56194eb2011-03-02 19:23:13 -08004176 }
4177
Jeff Brown40013652012-05-16 21:22:36 -07004178 void dispatchMediaKeyWithWakeLock(KeyEvent event) {
4179 if (DEBUG_INPUT) {
4180 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: " + event);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004181 }
4182
Jeff Brown40013652012-05-16 21:22:36 -07004183 if (mHavePendingMediaKeyRepeatWithWakeLock) {
4184 if (DEBUG_INPUT) {
4185 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: canceled repeat");
4186 }
4187
4188 mHandler.removeMessages(MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK);
4189 mHavePendingMediaKeyRepeatWithWakeLock = false;
4190 mBroadcastWakeLock.release(); // pending repeat was holding onto the wake lock
4191 }
4192
4193 dispatchMediaKeyWithWakeLockToAudioService(event);
4194
4195 if (event.getAction() == KeyEvent.ACTION_DOWN
4196 && event.getRepeatCount() == 0) {
4197 mHavePendingMediaKeyRepeatWithWakeLock = true;
4198
4199 Message msg = mHandler.obtainMessage(
4200 MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK, event);
4201 msg.setAsynchronous(true);
4202 mHandler.sendMessageDelayed(msg, ViewConfiguration.getKeyRepeatTimeout());
4203 } else {
4204 mBroadcastWakeLock.release();
4205 }
4206 }
4207
4208 void dispatchMediaKeyRepeatWithWakeLock(KeyEvent event) {
4209 mHavePendingMediaKeyRepeatWithWakeLock = false;
4210
4211 KeyEvent repeatEvent = KeyEvent.changeTimeRepeat(event,
4212 SystemClock.uptimeMillis(), 1, event.getFlags() | KeyEvent.FLAG_LONG_PRESS);
4213 if (DEBUG_INPUT) {
4214 Slog.d(TAG, "dispatchMediaKeyRepeatWithWakeLock: " + repeatEvent);
4215 }
4216
4217 dispatchMediaKeyWithWakeLockToAudioService(repeatEvent);
4218 mBroadcastWakeLock.release();
4219 }
4220
4221 void dispatchMediaKeyWithWakeLockToAudioService(KeyEvent event) {
4222 if (ActivityManagerNative.isSystemReady()) {
4223 IAudioService audioService = getAudioService();
4224 if (audioService != null) {
4225 try {
4226 audioService.dispatchMediaKeyEventUnderWakelock(event);
4227 } catch (RemoteException e) {
4228 Log.e(TAG, "dispatchMediaKeyEvent threw exception " + e);
Jean-Michel Trivic6802222012-04-30 11:15:03 -07004229 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004230 }
4231 }
4232 }
4233
Mike Lockwood1753f7f2009-08-24 14:49:07 -07004234 BroadcastReceiver mDockReceiver = new BroadcastReceiver() {
Craig Mautnereee29c42013-01-17 14:44:34 -08004235 @Override
Mike Lockwood1753f7f2009-08-24 14:49:07 -07004236 public void onReceive(Context context, Intent intent) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07004237 if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) {
4238 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
4239 Intent.EXTRA_DOCK_STATE_UNDOCKED);
Daniel Sandler6396c722013-04-16 20:19:09 -04004240 } else {
4241 try {
4242 IUiModeManager uiModeService = IUiModeManager.Stub.asInterface(
4243 ServiceManager.getService(Context.UI_MODE_SERVICE));
4244 mUiMode = uiModeService.getCurrentModeType();
4245 } catch (RemoteException e) {
4246 }
Dianne Hackborn80fa1662009-10-07 14:02:10 -07004247 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004248 updateRotation(true);
Craig Mautnereee29c42013-01-17 14:44:34 -08004249 synchronized (mLock) {
4250 updateOrientationListenerLp();
4251 }
Mike Lockwood1753f7f2009-08-24 14:49:07 -07004252 }
4253 };
4254
Jeff Brown6aaf2952012-10-05 16:01:08 -07004255 BroadcastReceiver mDreamReceiver = new BroadcastReceiver() {
4256 @Override
4257 public void onReceive(Context context, Intent intent) {
4258 if (Intent.ACTION_DREAMING_STARTED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004259 if (mKeyguardDelegate != null) {
4260 mKeyguardDelegate.onDreamingStarted();
Jeff Brown6aaf2952012-10-05 16:01:08 -07004261 }
4262 } else if (Intent.ACTION_DREAMING_STOPPED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004263 if (mKeyguardDelegate != null) {
4264 mKeyguardDelegate.onDreamingStopped();
Jeff Brown6aaf2952012-10-05 16:01:08 -07004265 }
4266 }
4267 }
4268 };
4269
Christopher Tate5e08af02012-09-21 17:17:22 -07004270 BroadcastReceiver mMultiuserReceiver = new BroadcastReceiver() {
4271 @Override
4272 public void onReceive(Context context, Intent intent) {
4273 if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) {
4274 // tickle the settings observer: this first ensures that we're
4275 // observing the relevant settings for the newly-active user,
4276 // and then updates our own bookkeeping based on the now-
4277 // current user.
4278 mSettingsObserver.onChange(false);
John Spurlockce479d82012-11-29 09:52:21 -05004279
4280 // force a re-application of focused window sysui visibility.
4281 // the window may never have been shown for this user
4282 // e.g. the keyguard when going through the new-user setup flow
John Spurlock04db1762013-05-13 12:46:41 -04004283 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
John Spurlockce479d82012-11-29 09:52:21 -05004284 mLastSystemUiFlags = 0;
4285 updateSystemUiVisibilityLw();
4286 }
Christopher Tate5e08af02012-09-21 17:17:22 -07004287 }
4288 }
4289 };
4290
John Spurlockd9b70bd2014-02-06 17:02:44 -05004291 private final Runnable mRequestTransientNav = new Runnable() {
4292 @Override
4293 public void run() {
4294 requestTransientBars(mNavigationBar);
4295 }
4296 };
4297
John Spurlocke1f366f2013-08-05 12:22:40 -04004298 private void requestTransientBars(WindowState swipeTarget) {
John Spurlock04db1762013-05-13 12:46:41 -04004299 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
John Spurlock27735a42013-08-14 17:57:38 -04004300 boolean sb = mStatusBarController.checkShowTransientBarLw();
4301 boolean nb = mNavigationBarController.checkShowTransientBarLw();
John Spurlockad3e6cb2013-04-30 08:47:43 -04004302 if (sb || nb) {
John Spurlocke1f366f2013-08-05 12:22:40 -04004303 WindowState barTarget = sb ? mStatusBar : mNavigationBar;
4304 if (sb ^ nb && barTarget != swipeTarget) {
4305 if (DEBUG) Slog.d(TAG, "Not showing transient bar, wrong swipe target");
John Spurlockad3e6cb2013-04-30 08:47:43 -04004306 return;
4307 }
John Spurlock27735a42013-08-14 17:57:38 -04004308 if (sb) mStatusBarController.showTransient();
4309 if (nb) mNavigationBarController.showTransient();
John Spurlockf1a36642013-10-12 17:50:42 -04004310 mImmersiveModeConfirmation.confirmCurrentPrompt();
John Spurlockad3e6cb2013-04-30 08:47:43 -04004311 updateSystemUiVisibilityLw();
John Spurlock32beb2c2013-03-11 10:16:47 -04004312 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04004313 }
4314 }
4315
Jeff Brownc38c9be2012-10-04 13:16:19 -07004316 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004317 public void screenTurnedOff(int why) {
Dianne Hackborn74489012009-03-24 20:50:09 -07004318 EventLog.writeEvent(70000, 0);
The Android Open Source Project0727d222009-03-11 12:11:58 -07004319 synchronized (mLock) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004320 mScreenOnEarly = false;
4321 mScreenOnFully = false;
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07004322 }
Jim Miller5ecd8112013-01-09 18:50:26 -08004323 if (mKeyguardDelegate != null) {
4324 mKeyguardDelegate.onScreenTurnedOff(why);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004325 }
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07004326 synchronized (mLock) {
The Android Open Source Project0727d222009-03-11 12:11:58 -07004327 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05004328 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07004329 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004330 }
4331
Jeff Brownc38c9be2012-10-04 13:16:19 -07004332 @Override
Dianne Hackborn38e29a62011-09-18 14:43:08 -07004333 public void screenTurningOn(final ScreenOnListener screenOnListener) {
Dianne Hackborn74489012009-03-24 20:50:09 -07004334 EventLog.writeEvent(70000, 1);
Dianne Hackborn40011092011-09-22 13:37:48 -07004335 if (false) {
4336 RuntimeException here = new RuntimeException("here");
4337 here.fillInStackTrace();
4338 Slog.i(TAG, "Screen turning on...", here);
4339 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07004340
The Android Open Source Project0727d222009-03-11 12:11:58 -07004341 synchronized (mLock) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004342 mScreenOnEarly = true;
The Android Open Source Project0727d222009-03-11 12:11:58 -07004343 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05004344 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07004345 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07004346
Jeff Brownc38c9be2012-10-04 13:16:19 -07004347 waitForKeyguard(screenOnListener);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004348 }
4349
Jeff Brownc38c9be2012-10-04 13:16:19 -07004350 private void waitForKeyguard(final ScreenOnListener screenOnListener) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004351 if (mKeyguardDelegate != null) {
Jorim Jaggicff0acb2014-03-31 16:35:15 +02004352 mKeyguardDelegate.onScreenTurnedOn(new KeyguardServiceDelegate.ShowListener() {
4353 @Override
4354 public void onShown(IBinder windowToken) {
4355 waitForKeyguardWindowDrawn(windowToken, screenOnListener);
4356 }
4357 });
Jeff Brownc38c9be2012-10-04 13:16:19 -07004358 } else {
Jim Miller5ecd8112013-01-09 18:50:26 -08004359 Slog.i(TAG, "No keyguard interface!");
Jorim Jaggicff0acb2014-03-31 16:35:15 +02004360 finishScreenTurningOn(screenOnListener);
Jeff Brownc38c9be2012-10-04 13:16:19 -07004361 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07004362 }
4363
4364 private void waitForKeyguardWindowDrawn(IBinder windowToken,
4365 final ScreenOnListener screenOnListener) {
Craig Mautner6f295902013-10-11 21:43:06 -07004366 if (windowToken != null && !mHideLockScreen) {
Jeff Brownc38c9be2012-10-04 13:16:19 -07004367 try {
4368 if (mWindowManager.waitForWindowDrawn(
4369 windowToken, new IRemoteCallback.Stub() {
4370 @Override
4371 public void sendResult(Bundle data) {
4372 Slog.i(TAG, "Lock screen displayed!");
4373 finishScreenTurningOn(screenOnListener);
Jorim Jaggicff0acb2014-03-31 16:35:15 +02004374 setKeyguardDrawn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07004375 }
4376 })) {
4377 return;
4378 }
Craig Mautner4e8a19c2013-10-08 17:26:08 -07004379 Slog.i(TAG, "No lock screen! waitForWindowDrawn false");
4380
Jeff Brownc38c9be2012-10-04 13:16:19 -07004381 } catch (RemoteException ex) {
4382 // Can't happen in system process.
4383 }
4384 }
4385
Craig Mautner4e8a19c2013-10-08 17:26:08 -07004386 Slog.i(TAG, "No lock screen! windowToken=" + windowToken);
Jeff Brownc38c9be2012-10-04 13:16:19 -07004387 finishScreenTurningOn(screenOnListener);
Jorim Jaggicff0acb2014-03-31 16:35:15 +02004388 setKeyguardDrawn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07004389 }
4390
4391 private void finishScreenTurningOn(ScreenOnListener screenOnListener) {
4392 synchronized (mLock) {
4393 mScreenOnFully = true;
4394 }
4395
Jeff Brown4fc45272012-10-10 18:28:14 -07004396 try {
4397 mWindowManager.setEventDispatching(true);
4398 } catch (RemoteException unhandled) {
4399 }
4400
Jeff Brownc38c9be2012-10-04 13:16:19 -07004401 if (screenOnListener != null) {
4402 screenOnListener.onScreenOn();
4403 }
4404 }
4405
4406 @Override
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004407 public boolean isScreenOnEarly() {
4408 return mScreenOnEarly;
4409 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07004410
4411 @Override
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004412 public boolean isScreenOnFully() {
4413 return mScreenOnFully;
Dianne Hackborn08743722009-12-21 12:16:51 -08004414 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07004415
Dianne Hackborn08743722009-12-21 12:16:51 -08004416 /** {@inheritDoc} */
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004417 public void enableKeyguard(boolean enabled) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004418 if (mKeyguardDelegate != null) {
4419 mKeyguardDelegate.setKeyguardEnabled(enabled);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004420 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004421 }
4422
4423 /** {@inheritDoc} */
4424 public void exitKeyguardSecurely(OnKeyguardExitResult callback) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004425 if (mKeyguardDelegate != null) {
4426 mKeyguardDelegate.verifyUnlock(callback);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004427 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004428 }
4429
Mike Lockwoodf7913302009-11-28 22:27:10 -05004430 private boolean keyguardIsShowingTq() {
Jim Miller5ecd8112013-01-09 18:50:26 -08004431 if (mKeyguardDelegate == null) return false;
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004432 return mKeyguardDelegate.isShowingAndNotOccluded();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004433 }
4434
Mike Lockwood520d8bc2011-02-18 13:23:13 -05004435
4436 /** {@inheritDoc} */
4437 public boolean isKeyguardLocked() {
4438 return keyguardOn();
4439 }
4440
4441 /** {@inheritDoc} */
4442 public boolean isKeyguardSecure() {
Jim Miller5ecd8112013-01-09 18:50:26 -08004443 if (mKeyguardDelegate == null) return false;
4444 return mKeyguardDelegate.isSecure();
Mike Lockwood520d8bc2011-02-18 13:23:13 -05004445 }
4446
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004447 /** {@inheritDoc} */
4448 public boolean inKeyguardRestrictedKeyInputMode() {
Jim Miller5ecd8112013-01-09 18:50:26 -08004449 if (mKeyguardDelegate == null) return false;
4450 return mKeyguardDelegate.isInputRestricted();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004451 }
4452
Dianne Hackborn90c52de2011-09-23 12:57:44 -07004453 public void dismissKeyguardLw() {
Jim Miller195b5512013-02-28 03:35:57 -08004454 if (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()) {
Daniel Sandler1ce804392012-11-07 15:07:12 -05004455 mHandler.post(new Runnable() {
4456 public void run() {
Jim Miller5ecd8112013-01-09 18:50:26 -08004457 if (mKeyguardDelegate.isDismissable()) {
Daniel Sandler1ce804392012-11-07 15:07:12 -05004458 // Can we just finish the keyguard straight away?
Jim Miller5ecd8112013-01-09 18:50:26 -08004459 mKeyguardDelegate.keyguardDone(false, true);
Daniel Sandler1ce804392012-11-07 15:07:12 -05004460 } else {
4461 // ask the keyguard to prompt the user to authenticate if necessary
Jim Miller5ecd8112013-01-09 18:50:26 -08004462 mKeyguardDelegate.dismiss();
Dianne Hackborn90c52de2011-09-23 12:57:44 -07004463 }
Daniel Sandler1ce804392012-11-07 15:07:12 -05004464 }
4465 });
Dianne Hackborn90c52de2011-09-23 12:57:44 -07004466 }
4467 }
4468
Jorim Jaggicff0acb2014-03-31 16:35:15 +02004469 private void setKeyguardDrawn() {
4470 synchronized (mLock) {
4471 mKeyguardDrawn = true;
4472 }
4473 try {
4474 mWindowManager.enableScreenIfNeeded();
4475 } catch (RemoteException unhandled) {
4476 }
4477 }
4478
4479 @Override
4480 public boolean isKeyguardDrawnLw() {
4481 synchronized (mLock) {
4482 return mKeyguardDrawn;
4483 }
4484 }
4485
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004486 void sendCloseSystemWindows() {
4487 sendCloseSystemWindows(mContext, null);
4488 }
4489
4490 void sendCloseSystemWindows(String reason) {
4491 sendCloseSystemWindows(mContext, reason);
4492 }
4493
4494 static void sendCloseSystemWindows(Context context, String reason) {
4495 if (ActivityManagerNative.isSystemReady()) {
Dianne Hackborn94a679d2009-07-28 17:51:07 -07004496 try {
4497 ActivityManagerNative.getDefault().closeSystemDialogs(reason);
4498 } catch (RemoteException e) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004499 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004500 }
4501 }
Mitsuru Oshima831d0d92009-06-16 18:27:18 -07004502
Jeff Brown01a98dd2011-09-20 15:08:29 -07004503 @Override
4504 public int rotationForOrientationLw(int orientation, int lastRotation) {
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05004505 if (false) {
4506 Slog.v(TAG, "rotationForOrientationLw(orient="
4507 + orientation + ", last=" + lastRotation
4508 + "); user=" + mUserRotation + " "
4509 + ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED)
4510 ? "USER_ROTATION_LOCKED" : "")
4511 );
4512 }
4513
Craig Mautner46ac6fa2013-08-01 10:06:34 -07004514 if (mForceDefaultOrientation) {
4515 return Surface.ROTATION_0;
4516 }
4517
The Android Open Source Project0727d222009-03-11 12:11:58 -07004518 synchronized (mLock) {
Jeff Brownc0347aa2011-09-23 17:26:09 -07004519 int sensorRotation = mOrientationListener.getProposedRotation(); // may be -1
4520 if (sensorRotation < 0) {
Jeff Brown0f862b42012-09-27 21:11:01 -07004521 sensorRotation = lastRotation;
Jeff Brownc0347aa2011-09-23 17:26:09 -07004522 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004523
Jeff Browndec6cf42011-11-15 14:08:20 -08004524 final int preferredRotation;
Jeff Brown2e7760e2012-04-11 15:14:55 -07004525 if (mLidState == LID_OPEN && mLidOpenRotation >= 0) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07004526 // Ignore sensor when lid switch is open and rotation is forced.
4527 preferredRotation = mLidOpenRotation;
4528 } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR
Jeff Brownc0347aa2011-09-23 17:26:09 -07004529 && (mCarDockEnablesAccelerometer || mCarDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07004530 // Ignore sensor when in car dock unless explicitly enabled.
4531 // This case can override the behavior of NOSENSOR, and can also
4532 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07004533 preferredRotation = mCarDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07004534 ? sensorRotation : mCarDockRotation;
Jeff Brown1a693182011-11-08 14:44:16 -08004535 } else if ((mDockMode == Intent.EXTRA_DOCK_STATE_DESK
4536 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
4537 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK)
Jeff Brownc0347aa2011-09-23 17:26:09 -07004538 && (mDeskDockEnablesAccelerometer || mDeskDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07004539 // Ignore sensor when in desk dock unless explicitly enabled.
4540 // This case can override the behavior of NOSENSOR, and can also
4541 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07004542 preferredRotation = mDeskDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07004543 ? sensorRotation : mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -07004544 } else if (mHdmiPlugged && mDemoHdmiRotationLock) {
4545 // Ignore sensor when plugged into HDMI when demo HDMI rotation lock enabled.
Jeff Browneb3e4b92011-12-06 19:54:24 -08004546 // Note that the dock orientation overrides the HDMI orientation.
Jeff Brownc82c89ed2013-04-17 17:18:15 -07004547 preferredRotation = mDemoHdmiRotation;
4548 } else if (mHdmiPlugged && mDockMode == Intent.EXTRA_DOCK_STATE_UNDOCKED
4549 && mUndockedHdmiRotation >= 0) {
4550 // Ignore sensor when plugged into HDMI and an undocked orientation has
4551 // been specified in the configuration (only for legacy devices without
4552 // full multi-display support).
4553 // Note that the dock orientation overrides the HDMI orientation.
4554 preferredRotation = mUndockedHdmiRotation;
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07004555 } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED) {
4556 // Application just wants to remain locked in the last rotation.
4557 preferredRotation = lastRotation;
Jeff Brownbcdfc622014-03-06 19:13:04 -08004558 } else if (!mSupportAutoRotation) {
4559 // If we don't support auto-rotation then bail out here and ignore
4560 // the sensor and any rotation lock settings.
4561 preferredRotation = -1;
Jeff Brown207673cd2012-06-05 17:47:11 -07004562 } else if ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE
Jeff Brown01a98dd2011-09-20 15:08:29 -07004563 && (orientation == ActivityInfo.SCREEN_ORIENTATION_USER
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07004564 || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
4565 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
4566 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
4567 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER))
Jeff Brown01a98dd2011-09-20 15:08:29 -07004568 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
4569 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
4570 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
4571 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) {
4572 // Otherwise, use sensor only if requested by the application or enabled
4573 // by default for USER or UNSPECIFIED modes. Does not apply to NOSENSOR.
Jeff Brownd3187e32011-09-21 19:26:44 -07004574 if (mAllowAllRotations < 0) {
4575 // Can't read this during init() because the context doesn't
4576 // have display metrics at that time so we cannot determine
4577 // tablet vs. phone then.
4578 mAllowAllRotations = mContext.getResources().getBoolean(
4579 com.android.internal.R.bool.config_allowAllRotations) ? 1 : 0;
4580 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004581 if (sensorRotation != Surface.ROTATION_180
Jeff Brownd3187e32011-09-21 19:26:44 -07004582 || mAllowAllRotations == 1
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07004583 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
4584 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07004585 preferredRotation = sensorRotation;
4586 } else {
4587 preferredRotation = lastRotation;
4588 }
Jeff Brown207673cd2012-06-05 17:47:11 -07004589 } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED
4590 && orientation != ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) {
4591 // Apply rotation lock. Does not apply to NOSENSOR.
4592 // The idea is that the user rotation expresses a weak preference for the direction
4593 // of gravity and as NOSENSOR is never affected by gravity, then neither should
4594 // NOSENSOR be affected by rotation lock (although it will be affected by docks).
Jeff Brown4dfce202011-10-05 12:00:10 -07004595 preferredRotation = mUserRotation;
Jeff Browndec6cf42011-11-15 14:08:20 -08004596 } else {
4597 // No overriding preference.
4598 // We will do exactly what the application asked us to do.
4599 preferredRotation = -1;
Jeff Brown01a98dd2011-09-20 15:08:29 -07004600 }
4601
Dianne Hackborne5439f22010-10-02 16:53:50 -07004602 switch (orientation) {
4603 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08004604 // Return portrait unless overridden.
4605 if (isAnyPortrait(preferredRotation)) {
4606 return preferredRotation;
4607 }
Dianne Hackborne5439f22010-10-02 16:53:50 -07004608 return mPortraitRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07004609
Jeff Brown01a98dd2011-09-20 15:08:29 -07004610 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08004611 // Return landscape unless overridden.
4612 if (isLandscapeOrSeascape(preferredRotation)) {
4613 return preferredRotation;
4614 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004615 return mLandscapeRotation;
4616
4617 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08004618 // Return reverse portrait unless overridden.
4619 if (isAnyPortrait(preferredRotation)) {
4620 return preferredRotation;
4621 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004622 return mUpsideDownRotation;
4623
4624 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08004625 // Return seascape unless overridden.
4626 if (isLandscapeOrSeascape(preferredRotation)) {
4627 return preferredRotation;
4628 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004629 return mSeascapeRotation;
4630
4631 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07004632 case ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE:
Jeff Brown01a98dd2011-09-20 15:08:29 -07004633 // Return either landscape rotation.
4634 if (isLandscapeOrSeascape(preferredRotation)) {
4635 return preferredRotation;
4636 }
4637 if (isLandscapeOrSeascape(lastRotation)) {
Jeff Brown4519f072011-01-23 13:16:01 -08004638 return lastRotation;
4639 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004640 return mLandscapeRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004641
Jeff Brown01a98dd2011-09-20 15:08:29 -07004642 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07004643 case ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT:
Jeff Brown01a98dd2011-09-20 15:08:29 -07004644 // Return either portrait rotation.
4645 if (isAnyPortrait(preferredRotation)) {
4646 return preferredRotation;
4647 }
4648 if (isAnyPortrait(lastRotation)) {
4649 return lastRotation;
4650 }
4651 return mPortraitRotation;
4652
4653 default:
Jeff Brown4dfce202011-10-05 12:00:10 -07004654 // For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR,
4655 // just return the preferred orientation we already calculated.
Jeff Brown01a98dd2011-09-20 15:08:29 -07004656 if (preferredRotation >= 0) {
4657 return preferredRotation;
4658 }
Dianne Hackborndacea8c2011-04-21 17:26:39 -07004659 return Surface.ROTATION_0;
Daniel Sandlere7e5ac22011-02-22 16:10:21 -05004660 }
4661 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07004662 }
4663
Jeff Brown01a98dd2011-09-20 15:08:29 -07004664 @Override
4665 public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation) {
4666 switch (orientation) {
4667 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
4668 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
4669 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
4670 return isAnyPortrait(rotation);
4671
4672 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
4673 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
4674 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
4675 return isLandscapeOrSeascape(rotation);
4676
4677 default:
4678 return true;
4679 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07004680 }
4681
Jeff Brownc0347aa2011-09-23 17:26:09 -07004682 @Override
4683 public void setRotationLw(int rotation) {
4684 mOrientationListener.setCurrentRotation(rotation);
4685 }
4686
Jeff Brown01a98dd2011-09-20 15:08:29 -07004687 private boolean isLandscapeOrSeascape(int rotation) {
4688 return rotation == mLandscapeRotation || rotation == mSeascapeRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07004689 }
4690
Jeff Brown01a98dd2011-09-20 15:08:29 -07004691 private boolean isAnyPortrait(int rotation) {
4692 return rotation == mPortraitRotation || rotation == mUpsideDownRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07004693 }
4694
Svetoslav Ganov80943d82013-01-02 10:25:37 -08004695 public int getUserRotationMode() {
4696 return Settings.System.getIntForUser(mContext.getContentResolver(),
Brett Chabot7e55c402013-05-16 19:38:08 -07004697 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
4698 WindowManagerPolicy.USER_ROTATION_FREE :
4699 WindowManagerPolicy.USER_ROTATION_LOCKED;
Svetoslav Ganov80943d82013-01-02 10:25:37 -08004700 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004701
4702 // User rotation: to be used when all else fails in assigning an orientation to the device
4703 public void setUserRotationMode(int mode, int rot) {
4704 ContentResolver res = mContext.getContentResolver();
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05004705
4706 // mUserRotationMode and mUserRotation will be assigned by the content observer
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004707 if (mode == WindowManagerPolicy.USER_ROTATION_LOCKED) {
Christopher Tate5e08af02012-09-21 17:17:22 -07004708 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004709 Settings.System.USER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07004710 rot,
4711 UserHandle.USER_CURRENT);
4712 Settings.System.putIntForUser(res,
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05004713 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07004714 0,
4715 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004716 } else {
Christopher Tate5e08af02012-09-21 17:17:22 -07004717 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004718 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07004719 1,
4720 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004721 }
4722 }
4723
Jeff Brownac143512012-04-05 18:57:33 -07004724 public void setSafeMode(boolean safeMode) {
4725 mSafeMode = safeMode;
4726 performHapticFeedbackLw(null, safeMode
4727 ? HapticFeedbackConstants.SAFE_MODE_ENABLED
4728 : HapticFeedbackConstants.SAFE_MODE_DISABLED, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004729 }
Craig Mautnereda67292013-04-28 13:50:14 -07004730
Dianne Hackborn181ceb52009-08-27 22:16:40 -07004731 static long[] getLongIntArray(Resources r, int resid) {
4732 int[] ar = r.getIntArray(resid);
4733 if (ar == null) {
4734 return null;
4735 }
4736 long[] out = new long[ar.length];
4737 for (int i=0; i<ar.length; i++) {
4738 out[i] = ar[i];
4739 }
4740 return out;
4741 }
Craig Mautnereda67292013-04-28 13:50:14 -07004742
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004743 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07004744 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004745 public void systemReady() {
Mike Lockwooded8902d2013-11-15 11:01:47 -08004746 mKeyguardDelegate = new KeyguardServiceDelegate(mContext, null);
4747 mKeyguardDelegate.onSystemReady();
4748
Dianne Hackbornb1a79802009-09-29 15:18:31 -07004749 synchronized (mLock) {
4750 updateOrientationListenerLp();
Dianne Hackbornc777e072010-02-12 13:07:59 -08004751 mSystemReady = true;
4752 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07004753 @Override
Dianne Hackbornc777e072010-02-12 13:07:59 -08004754 public void run() {
4755 updateSettings();
4756 }
4757 });
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004758 }
4759 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07004760
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07004761 /** {@inheritDoc} */
4762 public void systemBooted() {
Jim Millere5f910a2013-10-16 18:15:46 -07004763 if (mKeyguardDelegate != null) {
4764 mKeyguardDelegate.onBootCompleted();
4765 }
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07004766 synchronized (mLock) {
4767 mSystemBooted = true;
4768 }
Jorim Jaggicff0acb2014-03-31 16:35:15 +02004769 waitForKeyguard(null);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07004770 }
4771
Dianne Hackborn661cd522011-08-22 00:26:20 -07004772 ProgressDialog mBootMsgDialog = null;
4773
4774 /** {@inheritDoc} */
4775 public void showBootMessage(final CharSequence msg, final boolean always) {
4776 mHandler.post(new Runnable() {
4777 @Override public void run() {
4778 if (mBootMsgDialog == null) {
Dianne Hackborn295e3c22011-08-25 13:19:08 -07004779 mBootMsgDialog = new ProgressDialog(mContext) {
4780 // This dialog will consume all events coming in to
4781 // it, to avoid it trying to do things too early in boot.
4782 @Override public boolean dispatchKeyEvent(KeyEvent event) {
4783 return true;
4784 }
4785 @Override public boolean dispatchKeyShortcutEvent(KeyEvent event) {
4786 return true;
4787 }
4788 @Override public boolean dispatchTouchEvent(MotionEvent ev) {
4789 return true;
4790 }
4791 @Override public boolean dispatchTrackballEvent(MotionEvent ev) {
4792 return true;
4793 }
4794 @Override public boolean dispatchGenericMotionEvent(MotionEvent ev) {
4795 return true;
4796 }
4797 @Override public boolean dispatchPopulateAccessibilityEvent(
4798 AccessibilityEvent event) {
4799 return true;
4800 }
4801 };
Dianne Hackborn661cd522011-08-22 00:26:20 -07004802 mBootMsgDialog.setTitle(R.string.android_upgrading_title);
4803 mBootMsgDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
4804 mBootMsgDialog.setIndeterminate(true);
4805 mBootMsgDialog.getWindow().setType(
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07004806 WindowManager.LayoutParams.TYPE_BOOT_PROGRESS);
Dianne Hackborn661cd522011-08-22 00:26:20 -07004807 mBootMsgDialog.getWindow().addFlags(
4808 WindowManager.LayoutParams.FLAG_DIM_BEHIND
4809 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
4810 mBootMsgDialog.getWindow().setDimAmount(1);
Dianne Hackbornd9efb952011-12-07 14:56:51 -08004811 WindowManager.LayoutParams lp = mBootMsgDialog.getWindow().getAttributes();
4812 lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
4813 mBootMsgDialog.getWindow().setAttributes(lp);
Dianne Hackborn661cd522011-08-22 00:26:20 -07004814 mBootMsgDialog.setCancelable(false);
4815 mBootMsgDialog.show();
4816 }
4817 mBootMsgDialog.setMessage(msg);
4818 }
4819 });
4820 }
4821
4822 /** {@inheritDoc} */
4823 public void hideBootMessages() {
4824 mHandler.post(new Runnable() {
4825 @Override public void run() {
4826 if (mBootMsgDialog != null) {
4827 mBootMsgDialog.dismiss();
4828 mBootMsgDialog = null;
4829 }
4830 }
4831 });
4832 }
4833
Mike Lockwood28569302010-01-28 11:54:40 -05004834 /** {@inheritDoc} */
4835 public void userActivity() {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004836 // ***************************************
4837 // NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
4838 // ***************************************
4839 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
4840 // WITH ITS LOCKS HELD.
4841 //
4842 // This code must be VERY careful about the locks
4843 // it acquires.
4844 // In fact, the current code acquires way too many,
4845 // and probably has lurking deadlocks.
4846
Mike Lockwood28569302010-01-28 11:54:40 -05004847 synchronized (mScreenLockTimeout) {
4848 if (mLockScreenTimerActive) {
4849 // reset the timer
4850 mHandler.removeCallbacks(mScreenLockTimeout);
4851 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
4852 }
4853 }
Daniel Sandler0601eb72011-04-13 01:01:32 -04004854 }
4855
Adam Cohenf7522022012-10-03 20:03:18 -07004856 class ScreenLockTimeout implements Runnable {
4857 Bundle options;
4858
4859 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05004860 public void run() {
4861 synchronized (this) {
4862 if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard");
Jim Miller5ecd8112013-01-09 18:50:26 -08004863 if (mKeyguardDelegate != null) {
4864 mKeyguardDelegate.doKeyguardTimeout(options);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004865 }
Mike Lockwood28569302010-01-28 11:54:40 -05004866 mLockScreenTimerActive = false;
Adam Cohenf7522022012-10-03 20:03:18 -07004867 options = null;
Mike Lockwood28569302010-01-28 11:54:40 -05004868 }
4869 }
Mike Lockwood28569302010-01-28 11:54:40 -05004870
Adam Cohenf7522022012-10-03 20:03:18 -07004871 public void setLockOptions(Bundle options) {
4872 this.options = options;
4873 }
4874 }
4875
4876 ScreenLockTimeout mScreenLockTimeout = new ScreenLockTimeout();
4877
4878 public void lockNow(Bundle options) {
Jim Miller93c518e2012-01-17 15:55:31 -08004879 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null);
4880 mHandler.removeCallbacks(mScreenLockTimeout);
Adam Cohenf7522022012-10-03 20:03:18 -07004881 if (options != null) {
4882 // In case multiple calls are made to lockNow, we don't wipe out the options
4883 // until the runnable actually executes.
4884 mScreenLockTimeout.setLockOptions(options);
4885 }
Jim Miller93c518e2012-01-17 15:55:31 -08004886 mHandler.post(mScreenLockTimeout);
4887 }
4888
Mike Lockwood28569302010-01-28 11:54:40 -05004889 private void updateLockScreenTimeout() {
4890 synchronized (mScreenLockTimeout) {
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004891 boolean enable = (mAllowLockscreenWhenOn && mScreenOnEarly &&
Jim Miller5ecd8112013-01-09 18:50:26 -08004892 mKeyguardDelegate != null && mKeyguardDelegate.isSecure());
Mike Lockwood28569302010-01-28 11:54:40 -05004893 if (mLockScreenTimerActive != enable) {
4894 if (enable) {
4895 if (localLOGV) Log.v(TAG, "setting lockscreen timer");
4896 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
4897 } else {
4898 if (localLOGV) Log.v(TAG, "clearing lockscreen timer");
4899 mHandler.removeCallbacks(mScreenLockTimeout);
4900 }
4901 mLockScreenTimerActive = enable;
4902 }
4903 }
4904 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004905
4906 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07004907 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004908 public void enableScreenAfterBoot() {
4909 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07004910 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07004911 updateRotation(true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004912 }
Dianne Hackbornf54c8f92009-09-19 14:03:57 -07004913
Jeff Brownc458ce92012-04-30 14:58:40 -07004914 private void applyLidSwitchState() {
Jeff Brownc458ce92012-04-30 14:58:40 -07004915 if (mLidState == LID_CLOSED && mLidControlsSleep) {
4916 mPowerManager.goToSleep(SystemClock.uptimeMillis());
4917 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004918 }
4919
4920 void updateRotation(boolean alwaysSendConfiguration) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004921 try {
4922 //set orientation on WindowManager
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004923 mWindowManager.updateRotation(alwaysSendConfiguration, false);
4924 } catch (RemoteException e) {
4925 // Ignore
4926 }
4927 }
4928
4929 void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) {
4930 try {
4931 //set orientation on WindowManager
4932 mWindowManager.updateRotation(alwaysSendConfiguration, forceRelayout);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004933 } catch (RemoteException e) {
4934 // Ignore
4935 }
4936 }
4937
Daniel Sandler6396c722013-04-16 20:19:09 -04004938 /**
4939 * Return an Intent to launch the currently active dock app as home. Returns
4940 * null if the standard home should be launched, which is the case if any of the following is
4941 * true:
4942 * <ul>
4943 * <li>The device is not in either car mode or desk mode
4944 * <li>The device is in car mode but ENABLE_CAR_DOCK_HOME_CAPTURE is false
4945 * <li>The device is in desk mode but ENABLE_DESK_DOCK_HOME_CAPTURE is false
4946 * <li>The device is in car mode but there's no CAR_DOCK app with METADATA_DOCK_HOME
4947 * <li>The device is in desk mode but there's no DESK_DOCK app with METADATA_DOCK_HOME
4948 * </ul>
Craig Mautnereda67292013-04-28 13:50:14 -07004949 * @return A dock intent.
Daniel Sandler6396c722013-04-16 20:19:09 -04004950 */
4951 Intent createHomeDockIntent() {
4952 Intent intent = null;
4953
4954 // What home does is based on the mode, not the dock state. That
4955 // is, when in car mode you should be taken to car home regardless
4956 // of whether we are actually in a car dock.
4957 if (mUiMode == Configuration.UI_MODE_TYPE_CAR) {
4958 if (ENABLE_CAR_DOCK_HOME_CAPTURE) {
4959 intent = mCarDockIntent;
4960 }
4961 } else if (mUiMode == Configuration.UI_MODE_TYPE_DESK) {
4962 if (ENABLE_DESK_DOCK_HOME_CAPTURE) {
4963 intent = mDeskDockIntent;
4964 }
4965 }
4966
4967 if (intent == null) {
4968 return null;
4969 }
4970
4971 ActivityInfo ai = null;
4972 ResolveInfo info = mContext.getPackageManager().resolveActivityAsUser(
4973 intent,
John Spurlockf56bef12013-07-09 09:51:46 -04004974 PackageManager.MATCH_DEFAULT_ONLY | PackageManager.GET_META_DATA,
Craig Mautnerd625ab22013-09-06 13:40:31 -07004975 mCurrentUserId);
Daniel Sandler6396c722013-04-16 20:19:09 -04004976 if (info != null) {
4977 ai = info.activityInfo;
4978 }
4979 if (ai != null
4980 && ai.metaData != null
4981 && ai.metaData.getBoolean(Intent.METADATA_DOCK_HOME)) {
4982 intent = new Intent(intent);
4983 intent.setClassName(ai.packageName, ai.name);
4984 return intent;
4985 }
4986
4987 return null;
4988 }
4989
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004990 void startDockOrHome() {
John Spurlockc8b46ca2013-04-08 12:59:26 -04004991 awakenDreams();
Daniel Sandler6396c722013-04-16 20:19:09 -04004992
4993 Intent dock = createHomeDockIntent();
4994 if (dock != null) {
4995 try {
4996 mContext.startActivityAsUser(dock, UserHandle.CURRENT);
4997 return;
4998 } catch (ActivityNotFoundException e) {
4999 }
5000 }
5001
Dianne Hackbornd8883992012-09-07 15:58:52 -07005002 mContext.startActivityAsUser(mHomeIntent, UserHandle.CURRENT);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005003 }
Craig Mautnereda67292013-04-28 13:50:14 -07005004
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005005 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005006 * goes to the home screen
5007 * @return whether it did anything
5008 */
5009 boolean goHome() {
5010 if (false) {
5011 // This code always brings home to the front.
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07005012 try {
5013 ActivityManagerNative.getDefault().stopAppSwitches();
5014 } catch (RemoteException e) {
5015 }
Dianne Hackborn94a679d2009-07-28 17:51:07 -07005016 sendCloseSystemWindows();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005017 startDockOrHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005018 } else {
5019 // This code brings home to the front or, if it is already
5020 // at the front, puts the device to sleep.
5021 try {
Wink Savilled2e6a332010-02-12 12:12:06 -08005022 if (SystemProperties.getInt("persist.sys.uts-test-mode", 0) == 1) {
5023 /// Roll back EndcallBehavior as the cupcake design to pass P1 lab entry.
5024 Log.d(TAG, "UTS-TEST-MODE");
5025 } else {
5026 ActivityManagerNative.getDefault().stopAppSwitches();
5027 sendCloseSystemWindows();
Daniel Sandler6396c722013-04-16 20:19:09 -04005028 Intent dock = createHomeDockIntent();
5029 if (dock != null) {
5030 int result = ActivityManagerNative.getDefault()
5031 .startActivityAsUser(null, null, dock,
5032 dock.resolveTypeIfNeeded(mContext.getContentResolver()),
5033 null, null, 0,
5034 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
5035 null, null, null, UserHandle.USER_CURRENT);
5036 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
5037 return false;
5038 }
5039 }
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005040 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005041 int result = ActivityManagerNative.getDefault()
Dianne Hackbornf265ea92013-01-31 15:00:51 -08005042 .startActivityAsUser(null, null, mHomeIntent,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005043 mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()),
Dianne Hackborna4972e92012-03-14 10:38:05 -07005044 null, null, 0,
5045 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Dianne Hackborn5e03e2c2012-09-06 14:21:19 -07005046 null, null, null, UserHandle.USER_CURRENT);
Dianne Hackborna4972e92012-03-14 10:38:05 -07005047 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005048 return false;
5049 }
5050 } catch (RemoteException ex) {
5051 // bummer, the activity manager, which is in this process, is dead
5052 }
5053 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005054 return true;
5055 }
Craig Mautnereda67292013-04-28 13:50:14 -07005056
5057 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07005058 public void setCurrentOrientationLw(int newOrientation) {
5059 synchronized (mLock) {
5060 if (newOrientation != mCurrentAppOrientation) {
5061 mCurrentAppOrientation = newOrientation;
5062 updateOrientationListenerLp();
5063 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005064 }
5065 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08005066
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07005067 private void performAuditoryFeedbackForAccessibilityIfNeed() {
5068 if (!isGlobalAccessibilityGestureEnabled()) {
5069 return;
5070 }
5071 AudioManager audioManager = (AudioManager) mContext.getSystemService(
5072 Context.AUDIO_SERVICE);
5073 if (audioManager.isSilentMode()) {
5074 return;
5075 }
5076 Ringtone ringTone = RingtoneManager.getRingtone(mContext,
5077 Settings.System.DEFAULT_NOTIFICATION_URI);
5078 ringTone.setStreamType(AudioManager.STREAM_MUSIC);
5079 ringTone.play();
5080 }
Craig Mautnereda67292013-04-28 13:50:14 -07005081
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07005082 private boolean isGlobalAccessibilityGestureEnabled() {
5083 return Settings.Global.getInt(mContext.getContentResolver(),
5084 Settings.Global.ENABLE_ACCESSIBILITY_GLOBAL_GESTURE_ENABLED, 0) == 1;
5085 }
5086
Craig Mautnereda67292013-04-28 13:50:14 -07005087 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07005088 public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) {
Svetoslav Ganov96179212012-10-10 14:17:45 -07005089 if (!mVibrator.hasVibrator()) {
5090 return false;
5091 }
Christopher Tate5e08af02012-09-21 17:17:22 -07005092 final boolean hapticsDisabled = Settings.System.getIntForUser(mContext.getContentResolver(),
5093 Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) == 0;
Jorim Jaggi5cf17872014-03-26 18:31:48 +01005094 if (!always && (hapticsDisabled || mKeyguardDelegate.isShowingAndNotOccluded())) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005095 return false;
5096 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08005097 long[] pattern = null;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005098 switch (effectId) {
5099 case HapticFeedbackConstants.LONG_PRESS:
Amith Yamasanic33cb712010-02-10 15:21:49 -08005100 pattern = mLongPressVibePattern;
5101 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07005102 case HapticFeedbackConstants.VIRTUAL_KEY:
Amith Yamasanic33cb712010-02-10 15:21:49 -08005103 pattern = mVirtualKeyVibePattern;
5104 break;
5105 case HapticFeedbackConstants.KEYBOARD_TAP:
5106 pattern = mKeyboardTapVibePattern;
5107 break;
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07005108 case HapticFeedbackConstants.CLOCK_TICK:
5109 pattern = mClockTickVibePattern;
5110 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07005111 case HapticFeedbackConstants.SAFE_MODE_DISABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08005112 pattern = mSafeModeDisabledVibePattern;
5113 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07005114 case HapticFeedbackConstants.SAFE_MODE_ENABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08005115 pattern = mSafeModeEnabledVibePattern;
5116 break;
Amith Yamasanic33cb712010-02-10 15:21:49 -08005117 default:
5118 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005119 }
Dianne Hackbornf265ea92013-01-31 15:00:51 -08005120 int owningUid;
5121 String owningPackage;
5122 if (win != null) {
5123 owningUid = win.getOwningUid();
5124 owningPackage = win.getOwningPackage();
5125 } else {
5126 owningUid = android.os.Process.myUid();
Dianne Hackborn95d78532013-09-11 09:51:14 -07005127 owningPackage = mContext.getOpPackageName();
Dianne Hackbornf265ea92013-01-31 15:00:51 -08005128 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08005129 if (pattern.length == 1) {
5130 // One-shot vibration
John Spurlock1af30c72014-03-10 08:33:35 -04005131 mVibrator.vibrate(owningUid, owningPackage, pattern[0], AudioManager.STREAM_SYSTEM);
Amith Yamasanic33cb712010-02-10 15:21:49 -08005132 } else {
5133 // Pattern vibration
John Spurlock1af30c72014-03-10 08:33:35 -04005134 mVibrator.vibrate(owningUid, owningPackage, pattern, -1, AudioManager.STREAM_SYSTEM);
Amith Yamasanic33cb712010-02-10 15:21:49 -08005135 }
5136 return true;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005137 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005138
5139 @Override
5140 public void keepScreenOnStartedLw() {
Daniel Sandler0601eb72011-04-13 01:01:32 -04005141 }
5142
Jeff Brownc38c9be2012-10-04 13:16:19 -07005143 @Override
5144 public void keepScreenOnStoppedLw() {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01005145 if (mKeyguardDelegate != null && !mKeyguardDelegate.isShowingAndNotOccluded()) {
Jim Miller25190572013-02-28 17:36:24 -08005146 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005147 }
5148 }
Mike Lockwoodfcb39242009-10-21 23:01:07 -04005149
Dianne Hackborndf89e652011-10-06 22:35:11 -07005150 private int updateSystemUiVisibilityLw() {
Joe Onorato664644d2011-01-23 17:53:23 -08005151 // If there is no window focused, there will be nobody to handle the events
5152 // anyway, so just hang on in whatever state we're in until things settle down.
John Spurlock79da8332013-09-20 12:04:47 -04005153 WindowState win = mFocusedWindow != null ? mFocusedWindow : mTopFullscreenOpaqueWindowState;
5154 if (win == null) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07005155 return 0;
5156 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01005157 if ((win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 && mHideLockScreen == true) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07005158 // We are updating at a point where the keyguard has gotten
5159 // focus, but we were last in a state where the top window is
5160 // hiding it. This is probably because the keyguard as been
5161 // shown while the top window was displayed, so we want to ignore
5162 // it here because this is just a very transient change and it
5163 // will quickly lose focus once it correctly gets hidden.
5164 return 0;
5165 }
John Spurlock32beb2c2013-03-11 10:16:47 -04005166
John Spurlock1db8b682014-02-18 11:18:59 -05005167 int tmpVisibility = PolicyControl.getSystemUiVisibility(win, null)
Dianne Hackborne26ab702011-10-16 13:21:33 -07005168 & ~mResettingSystemUiFlags
5169 & ~mForceClearedSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04005170 if (mForcingShowNavBar && win.getSurfaceLayer() < mForcingShowNavBarLayer) {
John Spurlockc6d1c602014-01-17 15:22:06 -05005171 tmpVisibility &= ~PolicyControl.adjustClearableFlags(win, View.SYSTEM_UI_CLEARABLE_FLAGS);
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08005172 }
John Spurlock79da8332013-09-20 12:04:47 -04005173 final int visibility = updateSystemBarsLw(win, mLastSystemUiFlags, tmpVisibility);
John Spurlockad3e6cb2013-04-30 08:47:43 -04005174 final int diff = visibility ^ mLastSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04005175 final boolean needsMenu = win.getNeedsMenuLw(mTopFullscreenOpaqueWindowState);
Dianne Hackborne0f085d2011-11-30 18:41:15 -08005176 if (diff == 0 && mLastFocusNeedsMenu == needsMenu
John Spurlock79da8332013-09-20 12:04:47 -04005177 && mFocusedApp == win.getAppToken()) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07005178 return 0;
5179 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07005180 mLastSystemUiFlags = visibility;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08005181 mLastFocusNeedsMenu = needsMenu;
John Spurlock79da8332013-09-20 12:04:47 -04005182 mFocusedApp = win.getAppToken();
Dianne Hackborndf89e652011-10-06 22:35:11 -07005183 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07005184 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07005185 public void run() {
Dianne Hackborn42e620c2012-06-24 13:20:51 -07005186 try {
5187 IStatusBarService statusbar = getStatusBarService();
5188 if (statusbar != null) {
5189 statusbar.setSystemUiVisibility(visibility, 0xffffffff);
5190 statusbar.topAppWindowChanged(needsMenu);
Joe Onorato664644d2011-01-23 17:53:23 -08005191 }
Dianne Hackborn42e620c2012-06-24 13:20:51 -07005192 } catch (RemoteException e) {
5193 // re-acquire status bar service next time it is needed.
5194 mStatusBarService = null;
Joe Onorato664644d2011-01-23 17:53:23 -08005195 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07005196 }
5197 });
5198 return diff;
Joe Onorato664644d2011-01-23 17:53:23 -08005199 }
5200
John Spurlock79da8332013-09-20 12:04:47 -04005201 private int updateSystemBarsLw(WindowState win, int oldVis, int vis) {
John Spurlockbd957402013-10-03 11:38:39 -04005202 // apply translucent bar vis flags
Jorim Jaggi380ecb82014-03-14 17:25:20 +01005203 WindowState transWin = isStatusBarKeyguard() && !mHideLockScreen
5204 ? mStatusBar
John Spurlockbd957402013-10-03 11:38:39 -04005205 : mTopFullscreenOpaqueWindowState;
5206 vis = mStatusBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
5207 vis = mNavigationBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
5208
John Spurlock27735a42013-08-14 17:57:38 -04005209 // prevent status bar interaction from clearing certain flags
John Spurlock79da8332013-09-20 12:04:47 -04005210 boolean statusBarHasFocus = win.getAttrs().type == TYPE_STATUS_BAR;
John Spurlockad3e6cb2013-04-30 08:47:43 -04005211 if (statusBarHasFocus) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04005212 int flags = View.SYSTEM_UI_FLAG_FULLSCREEN
5213 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlockcfc359a2013-09-05 10:42:03 -04005214 | View.SYSTEM_UI_FLAG_IMMERSIVE
Jorim Jaggi5cf17872014-03-26 18:31:48 +01005215 | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
5216 if (!isStatusBarKeyguard() || mHideLockScreen) {
5217 flags |= View.STATUS_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSLUCENT;
5218 }
John Spurlockbd957402013-10-03 11:38:39 -04005219 vis = (vis & ~flags) | (oldVis & flags);
John Spurlockad3e6cb2013-04-30 08:47:43 -04005220 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04005221
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04005222 if (!areTranslucentBarsAllowed()) {
5223 vis &= ~(View.NAVIGATION_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSLUCENT);
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07005224 }
5225
John Spurlock27735a42013-08-14 17:57:38 -04005226 // update status bar
John Spurlockf1a36642013-10-12 17:50:42 -04005227 boolean immersiveSticky =
5228 (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
John Spurlock27735a42013-08-14 17:57:38 -04005229 boolean hideStatusBarWM =
John Spurlockbd957402013-10-03 11:38:39 -04005230 mTopFullscreenOpaqueWindowState != null &&
John Spurlockc6d1c602014-01-17 15:22:06 -05005231 (PolicyControl.getWindowFlags(mTopFullscreenOpaqueWindowState, null)
John Spurlock27735a42013-08-14 17:57:38 -04005232 & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0;
5233 boolean hideStatusBarSysui =
5234 (vis & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04005235 boolean hideNavBarSysui =
5236 (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0;
John Spurlockad3e6cb2013-04-30 08:47:43 -04005237
John Spurlock27735a42013-08-14 17:57:38 -04005238 boolean transientStatusBarAllowed =
5239 mStatusBar != null && (
5240 hideStatusBarWM
John Spurlockf1a36642013-10-12 17:50:42 -04005241 || (hideStatusBarSysui && immersiveSticky)
John Spurlock27735a42013-08-14 17:57:38 -04005242 || statusBarHasFocus);
5243
John Spurlockf1a36642013-10-12 17:50:42 -04005244 boolean transientNavBarAllowed =
5245 mNavigationBar != null &&
5246 hideNavBarSysui && immersiveSticky;
5247
John Spurlockf25706f2013-11-07 18:02:43 -05005248 boolean denyTransientStatus = mStatusBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04005249 && !transientStatusBarAllowed && hideStatusBarSysui;
John Spurlockf25706f2013-11-07 18:02:43 -05005250 boolean denyTransientNav = mNavigationBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04005251 && !transientNavBarAllowed;
5252 if (denyTransientStatus || denyTransientNav) {
John Spurlock27735a42013-08-14 17:57:38 -04005253 // clear the clearable flags instead
John Spurlockf1a36642013-10-12 17:50:42 -04005254 clearClearableFlagsLw();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005255 }
John Spurlock27735a42013-08-14 17:57:38 -04005256
5257 vis = mStatusBarController.updateVisibilityLw(transientStatusBarAllowed, oldVis, vis);
5258
5259 // update navigation bar
John Spurlockf1a36642013-10-12 17:50:42 -04005260 boolean oldImmersiveMode = isImmersiveMode(oldVis);
5261 boolean newImmersiveMode = isImmersiveMode(vis);
5262 if (win != null && oldImmersiveMode != newImmersiveMode) {
John Spurlock79da8332013-09-20 12:04:47 -04005263 final String pkg = win.getOwningPackage();
John Spurlockf1a36642013-10-12 17:50:42 -04005264 mImmersiveModeConfirmation.immersiveModeChanged(pkg, newImmersiveMode);
John Spurlock34e13d92013-08-10 06:52:28 -04005265 }
John Spurlock27735a42013-08-14 17:57:38 -04005266
John Spurlockf1a36642013-10-12 17:50:42 -04005267 vis = mNavigationBarController.updateVisibilityLw(transientNavBarAllowed, oldVis, vis);
5268
John Spurlocke1f366f2013-08-05 12:22:40 -04005269 return vis;
John Spurlockad3e6cb2013-04-30 08:47:43 -04005270 }
5271
John Spurlockf1a36642013-10-12 17:50:42 -04005272 private void clearClearableFlagsLw() {
5273 int newVal = mResettingSystemUiFlags | View.SYSTEM_UI_CLEARABLE_FLAGS;
5274 if (newVal != mResettingSystemUiFlags) {
5275 mResettingSystemUiFlags = newVal;
5276 mWindowManagerFuncs.reevaluateStatusBarVisibility();
5277 }
5278 }
5279
5280 private boolean isImmersiveMode(int vis) {
5281 final int flags = View.SYSTEM_UI_FLAG_IMMERSIVE | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
John Spurlock34e13d92013-08-10 06:52:28 -04005282 return mNavigationBar != null
5283 && (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0
Daniel Sandler900ece52013-10-18 15:53:27 -04005284 && (vis & flags) != 0
5285 && canHideNavigationBar();
John Spurlock34e13d92013-08-10 06:52:28 -04005286 }
5287
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07005288 /**
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04005289 * @return whether the navigation or status bar can be made translucent
5290 *
5291 * This should return true unless touch exploration is not enabled or
5292 * R.boolean.config_enableTranslucentDecor is false.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07005293 */
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04005294 private boolean areTranslucentBarsAllowed() {
Svetoslav8e3feb12014-02-24 13:46:47 -08005295 return mTranslucentDecorEnabled
5296 && !mAccessibilityManager.isTouchExplorationEnabled();
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07005297 }
5298
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04005299 // Use this instead of checking config_showNavigationBar so that it can be consistently
5300 // overridden by qemu.hw.mainkeys in the emulator.
Craig Mautnereda67292013-04-28 13:50:14 -07005301 @Override
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04005302 public boolean hasNavigationBar() {
5303 return mHasNavigationBar;
5304 }
5305
satok1bc0a492012-04-25 22:47:12 +09005306 @Override
5307 public void setLastInputMethodWindowLw(WindowState ime, WindowState target) {
5308 mLastInputMethodWindow = ime;
5309 mLastInputMethodTargetWindow = target;
5310 }
5311
Craig Mautnerf1b67412012-09-19 13:18:29 -07005312 @Override
Satoshi Kataoka658c7b82013-10-10 17:03:51 +09005313 public int getInputMethodWindowVisibleHeightLw() {
5314 return mDockBottom - mCurBottom;
5315 }
5316
5317 @Override
Craig Mautnerf1b67412012-09-19 13:18:29 -07005318 public void setCurrentUserLw(int newUserId) {
Craig Mautnerd625ab22013-09-06 13:40:31 -07005319 mCurrentUserId = newUserId;
Jim Miller5ecd8112013-01-09 18:50:26 -08005320 if (mKeyguardDelegate != null) {
5321 mKeyguardDelegate.setCurrentUser(newUserId);
Craig Mautnerf1b67412012-09-19 13:18:29 -07005322 }
John Spurlock13451a22012-09-28 14:40:41 -04005323 if (mStatusBarService != null) {
5324 try {
5325 mStatusBarService.setCurrentUser(newUserId);
5326 } catch (RemoteException e) {
5327 // oh well
5328 }
5329 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07005330 setLastInputMethodWindowLw(null, null);
Craig Mautnerf1b67412012-09-19 13:18:29 -07005331 }
5332
5333 @Override
Svetoslav Ganov545252f2012-12-10 18:29:24 -08005334 public boolean canMagnifyWindow(int windowType) {
5335 switch (windowType) {
5336 case WindowManager.LayoutParams.TYPE_INPUT_METHOD:
5337 case WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG:
5338 case WindowManager.LayoutParams.TYPE_NAVIGATION_BAR:
5339 case WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY: {
5340 return false;
5341 }
5342 }
5343 return true;
5344 }
5345
5346 @Override
5347 public boolean isTopLevelWindow(int windowType) {
5348 if (windowType >= WindowManager.LayoutParams.FIRST_SUB_WINDOW
5349 && windowType <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
5350 return (windowType == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG);
5351 }
5352 return true;
5353 }
5354
Jim Miller4eeb4f62012-11-08 00:04:29 -08005355 @Override
Jeff Brownd7a04de2012-06-17 14:17:52 -07005356 public void dump(String prefix, PrintWriter pw, String[] args) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005357 pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005358 pw.print(" mSystemReady="); pw.print(mSystemReady);
5359 pw.print(" mSystemBooted="); pw.println(mSystemBooted);
Jeff Brown2e7760e2012-04-11 15:14:55 -07005360 pw.print(prefix); pw.print("mLidState="); pw.print(mLidState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005361 pw.print(" mLidOpenRotation="); pw.print(mLidOpenRotation);
5362 pw.print(" mHdmiPlugged="); pw.println(mHdmiPlugged);
Dianne Hackborne26ab702011-10-16 13:21:33 -07005363 if (mLastSystemUiFlags != 0 || mResettingSystemUiFlags != 0
5364 || mForceClearedSystemUiFlags != 0) {
5365 pw.print(prefix); pw.print("mLastSystemUiFlags=0x");
5366 pw.print(Integer.toHexString(mLastSystemUiFlags));
5367 pw.print(" mResettingSystemUiFlags=0x");
5368 pw.print(Integer.toHexString(mResettingSystemUiFlags));
5369 pw.print(" mForceClearedSystemUiFlags=0x");
5370 pw.println(Integer.toHexString(mForceClearedSystemUiFlags));
Dianne Hackborndf89e652011-10-06 22:35:11 -07005371 }
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08005372 if (mLastFocusNeedsMenu) {
5373 pw.print(prefix); pw.print("mLastFocusNeedsMenu=");
5374 pw.println(mLastFocusNeedsMenu);
5375 }
Jeff Brownbcdfc622014-03-06 19:13:04 -08005376 pw.print(prefix); pw.print("mSupportAutoRotation="); pw.println(mSupportAutoRotation);
Daniel Sandler6396c722013-04-16 20:19:09 -04005377 pw.print(prefix); pw.print("mUiMode="); pw.print(mUiMode);
5378 pw.print(" mDockMode="); pw.print(mDockMode);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005379 pw.print(" mCarDockRotation="); pw.print(mCarDockRotation);
5380 pw.print(" mDeskDockRotation="); pw.println(mDeskDockRotation);
5381 pw.print(prefix); pw.print("mUserRotationMode="); pw.print(mUserRotationMode);
5382 pw.print(" mUserRotation="); pw.print(mUserRotation);
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005383 pw.print(" mAllowAllRotations="); pw.println(mAllowAllRotations);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07005384 pw.print(prefix); pw.print("mCurrentAppOrientation="); pw.println(mCurrentAppOrientation);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005385 pw.print(prefix); pw.print("mCarDockEnablesAccelerometer=");
5386 pw.print(mCarDockEnablesAccelerometer);
5387 pw.print(" mDeskDockEnablesAccelerometer=");
5388 pw.println(mDeskDockEnablesAccelerometer);
5389 pw.print(prefix); pw.print("mLidKeyboardAccessibility=");
5390 pw.print(mLidKeyboardAccessibility);
5391 pw.print(" mLidNavigationAccessibility="); pw.print(mLidNavigationAccessibility);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07005392 pw.print(" mLidControlsSleep="); pw.println(mLidControlsSleep);
5393 pw.print(prefix); pw.print("mLongPressOnPowerBehavior=");
5394 pw.print(mLongPressOnPowerBehavior);
5395 pw.print(" mHasSoftInput="); pw.println(mHasSoftInput);
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07005396 pw.print(prefix); pw.print("mScreenOnEarly="); pw.print(mScreenOnEarly);
5397 pw.print(" mScreenOnFully="); pw.print(mScreenOnFully);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07005398 pw.print(" mOrientationSensorEnabled="); pw.println(mOrientationSensorEnabled);
Dianne Hackbornc652de82013-02-15 16:32:56 -08005399 pw.print(prefix); pw.print("mOverscanScreen=("); pw.print(mOverscanScreenLeft);
5400 pw.print(","); pw.print(mOverscanScreenTop);
5401 pw.print(") "); pw.print(mOverscanScreenWidth);
5402 pw.print("x"); pw.println(mOverscanScreenHeight);
5403 if (mOverscanLeft != 0 || mOverscanTop != 0
5404 || mOverscanRight != 0 || mOverscanBottom != 0) {
5405 pw.print(prefix); pw.print("mOverscan left="); pw.print(mOverscanLeft);
5406 pw.print(" top="); pw.print(mOverscanTop);
5407 pw.print(" right="); pw.print(mOverscanRight);
5408 pw.print(" bottom="); pw.println(mOverscanBottom);
5409 }
Dianne Hackborn313440842013-02-19 19:22:59 -08005410 pw.print(prefix); pw.print("mRestrictedOverscanScreen=(");
5411 pw.print(mRestrictedOverscanScreenLeft);
5412 pw.print(","); pw.print(mRestrictedOverscanScreenTop);
5413 pw.print(") "); pw.print(mRestrictedOverscanScreenWidth);
5414 pw.print("x"); pw.println(mRestrictedOverscanScreenHeight);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005415 pw.print(prefix); pw.print("mUnrestrictedScreen=("); pw.print(mUnrestrictedScreenLeft);
5416 pw.print(","); pw.print(mUnrestrictedScreenTop);
5417 pw.print(") "); pw.print(mUnrestrictedScreenWidth);
5418 pw.print("x"); pw.println(mUnrestrictedScreenHeight);
5419 pw.print(prefix); pw.print("mRestrictedScreen=("); pw.print(mRestrictedScreenLeft);
5420 pw.print(","); pw.print(mRestrictedScreenTop);
5421 pw.print(") "); pw.print(mRestrictedScreenWidth);
5422 pw.print("x"); pw.println(mRestrictedScreenHeight);
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07005423 pw.print(prefix); pw.print("mStableFullscreen=("); pw.print(mStableFullscreenLeft);
5424 pw.print(","); pw.print(mStableFullscreenTop);
5425 pw.print(")-("); pw.print(mStableFullscreenRight);
5426 pw.print(","); pw.print(mStableFullscreenBottom); pw.println(")");
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07005427 pw.print(prefix); pw.print("mStable=("); pw.print(mStableLeft);
5428 pw.print(","); pw.print(mStableTop);
5429 pw.print(")-("); pw.print(mStableRight);
5430 pw.print(","); pw.print(mStableBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07005431 pw.print(prefix); pw.print("mSystem=("); pw.print(mSystemLeft);
5432 pw.print(","); pw.print(mSystemTop);
5433 pw.print(")-("); pw.print(mSystemRight);
5434 pw.print(","); pw.print(mSystemBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005435 pw.print(prefix); pw.print("mCur=("); pw.print(mCurLeft);
5436 pw.print(","); pw.print(mCurTop);
5437 pw.print(")-("); pw.print(mCurRight);
5438 pw.print(","); pw.print(mCurBottom); pw.println(")");
5439 pw.print(prefix); pw.print("mContent=("); pw.print(mContentLeft);
5440 pw.print(","); pw.print(mContentTop);
5441 pw.print(")-("); pw.print(mContentRight);
5442 pw.print(","); pw.print(mContentBottom); pw.println(")");
5443 pw.print(prefix); pw.print("mDock=("); pw.print(mDockLeft);
5444 pw.print(","); pw.print(mDockTop);
5445 pw.print(")-("); pw.print(mDockRight);
5446 pw.print(","); pw.print(mDockBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07005447 pw.print(prefix); pw.print("mDockLayer="); pw.print(mDockLayer);
5448 pw.print(" mStatusBarLayer="); pw.println(mStatusBarLayer);
Dianne Hackborn7ad44382012-10-18 17:46:00 -07005449 pw.print(prefix); pw.print("mShowingLockscreen="); pw.print(mShowingLockscreen);
5450 pw.print(" mShowingDream="); pw.print(mShowingDream);
5451 pw.print(" mDreamingLockscreen="); pw.println(mDreamingLockscreen);
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07005452 if (mLastInputMethodWindow != null) {
5453 pw.print(prefix); pw.print("mLastInputMethodWindow=");
5454 pw.println(mLastInputMethodWindow);
5455 }
5456 if (mLastInputMethodTargetWindow != null) {
5457 pw.print(prefix); pw.print("mLastInputMethodTargetWindow=");
5458 pw.println(mLastInputMethodTargetWindow);
5459 }
5460 if (mStatusBar != null) {
5461 pw.print(prefix); pw.print("mStatusBar=");
5462 pw.println(mStatusBar);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01005463 pw.print(prefix); pw.print("isStatusBarKeyguard=");
5464 pw.print(isStatusBarKeyguard());
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07005465 }
5466 if (mNavigationBar != null) {
5467 pw.print(prefix); pw.print("mNavigationBar=");
5468 pw.println(mNavigationBar);
5469 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07005470 if (mFocusedWindow != null) {
5471 pw.print(prefix); pw.print("mFocusedWindow=");
5472 pw.println(mFocusedWindow);
5473 }
5474 if (mFocusedApp != null) {
5475 pw.print(prefix); pw.print("mFocusedApp=");
5476 pw.println(mFocusedApp);
5477 }
5478 if (mWinDismissingKeyguard != null) {
5479 pw.print(prefix); pw.print("mWinDismissingKeyguard=");
5480 pw.println(mWinDismissingKeyguard);
5481 }
5482 if (mTopFullscreenOpaqueWindowState != null) {
5483 pw.print(prefix); pw.print("mTopFullscreenOpaqueWindowState=");
5484 pw.println(mTopFullscreenOpaqueWindowState);
5485 }
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08005486 if (mForcingShowNavBar) {
5487 pw.print(prefix); pw.print("mForcingShowNavBar=");
5488 pw.println(mForcingShowNavBar); pw.print( "mForcingShowNavBarLayer=");
5489 pw.println(mForcingShowNavBarLayer);
5490 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07005491 pw.print(prefix); pw.print("mTopIsFullscreen="); pw.print(mTopIsFullscreen);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005492 pw.print(" mHideLockScreen="); pw.println(mHideLockScreen);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07005493 pw.print(prefix); pw.print("mForceStatusBar="); pw.print(mForceStatusBar);
5494 pw.print(" mForceStatusBarFromKeyguard=");
5495 pw.println(mForceStatusBarFromKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005496 pw.print(prefix); pw.print("mDismissKeyguard="); pw.print(mDismissKeyguard);
Craig Mautnerad09bcc2012-10-08 13:33:11 -07005497 pw.print(" mWinDismissingKeyguard="); pw.print(mWinDismissingKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005498 pw.print(" mHomePressed="); pw.println(mHomePressed);
5499 pw.print(prefix); pw.print("mAllowLockscreenWhenOn="); pw.print(mAllowLockscreenWhenOn);
5500 pw.print(" mLockScreenTimeout="); pw.print(mLockScreenTimeout);
5501 pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive);
5502 pw.print(prefix); pw.print("mEndcallBehavior="); pw.print(mEndcallBehavior);
5503 pw.print(" mIncallPowerBehavior="); pw.print(mIncallPowerBehavior);
5504 pw.print(" mLongPressOnHomeBehavior="); pw.println(mLongPressOnHomeBehavior);
5505 pw.print(prefix); pw.print("mLandscapeRotation="); pw.print(mLandscapeRotation);
5506 pw.print(" mSeascapeRotation="); pw.println(mSeascapeRotation);
5507 pw.print(prefix); pw.print("mPortraitRotation="); pw.print(mPortraitRotation);
5508 pw.print(" mUpsideDownRotation="); pw.println(mUpsideDownRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07005509 pw.print(prefix); pw.print("mDemoHdmiRotation="); pw.print(mDemoHdmiRotation);
5510 pw.print(" mDemoHdmiRotationLock="); pw.println(mDemoHdmiRotationLock);
5511 pw.print(prefix); pw.print("mUndockedHdmiRotation="); pw.println(mUndockedHdmiRotation);
John Spurlock27735a42013-08-14 17:57:38 -04005512 mStatusBarController.dump(pw, prefix);
5513 mNavigationBarController.dump(pw, prefix);
John Spurlockc6d1c602014-01-17 15:22:06 -05005514 PolicyControl.dump(prefix, pw);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005515 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005516}