blob: cacf66b470944fe575add05b8f9ba2c006f313e2 [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;
RoboErik8a2cfc32014-05-16 11:19:38 -070049import android.media.session.MediaSessionLegacyHelper;
Dianne Hackborn38e29a62011-09-18 14:43:08 -070050import android.os.Bundle;
Jeff Brown9a538ee2012-08-20 14:56:57 -070051import android.os.FactoryTest;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080052import android.os.Handler;
53import android.os.IBinder;
Dianne Hackborn38e29a62011-09-18 14:43:08 -070054import android.os.IRemoteCallback;
Jeff Brown32cbc38552011-12-01 14:01:49 -080055import android.os.Looper;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -070056import android.os.Message;
57import android.os.Messenger;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080058import android.os.PowerManager;
59import android.os.RemoteException;
60import android.os.ServiceManager;
61import android.os.SystemClock;
62import android.os.SystemProperties;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -080063import android.os.UEventObserver;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -070064import android.os.UserHandle;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080065import android.os.Vibrator;
66import android.provider.Settings;
John Spurlockc8b46ca2013-04-08 12:59:26 -040067import android.service.dreams.DreamService;
68import android.service.dreams.IDreamManager;
Santos Cordon6848f722014-05-21 15:22:12 -070069import android.telephony.TelephonyManager;
Dianne Hackborn81e56d52011-05-26 00:55:58 -070070import android.util.DisplayMetrics;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080071import android.util.EventLog;
72import android.util.Log;
Jeff Browna41ca772010-08-11 14:46:32 -070073import android.util.Slog;
Jeff Brown6651a632011-11-28 12:59:11 -080074import android.util.SparseArray;
Dianne Hackbornf87d1962012-04-04 12:48:24 -070075import android.view.Display;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080076import android.view.Gravity;
77import android.view.HapticFeedbackConstants;
Dianne Hackborne0f085d2011-11-30 18:41:15 -080078import android.view.IApplicationToken;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080079import android.view.IWindowManager;
Jeff Browna41ca772010-08-11 14:46:32 -070080import android.view.InputChannel;
Jeff Brown4d396052010-10-29 21:50:21 -070081import android.view.InputDevice;
Jeff Brown4952dfd2011-11-30 19:23:22 -080082import android.view.InputEvent;
Jeff Brown32cbc38552011-12-01 14:01:49 -080083import android.view.InputEventReceiver;
Jeff Brown6b53e8d2010-11-10 16:03:06 -080084import android.view.KeyCharacterMap;
Craig Mautnerae446592012-12-06 19:05:05 -080085import android.view.KeyCharacterMap.FallbackAction;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080086import android.view.KeyEvent;
87import android.view.MotionEvent;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080088import android.view.Surface;
89import android.view.View;
90import android.view.ViewConfiguration;
91import android.view.Window;
92import android.view.WindowManager;
Craig Mautnerae446592012-12-06 19:05:05 -080093import android.view.WindowManagerGlobal;
Craig Mautner8a0da012014-05-31 15:13:37 -070094import android.view.WindowManagerInternal;
Craig Mautnerae446592012-12-06 19:05:05 -080095import android.view.WindowManagerPolicy;
Craig Mautnerae446592012-12-06 19:05:05 -080096import android.view.accessibility.AccessibilityEvent;
Svetoslav8e3feb12014-02-24 13:46:47 -080097import android.view.accessibility.AccessibilityManager;
Craig Mautnerae446592012-12-06 19:05:05 -080098import android.view.animation.Animation;
99import android.view.animation.AnimationUtils;
100
101import com.android.internal.R;
Jorim Jaggi380ecb82014-03-14 17:25:20 +0100102import com.android.internal.policy.IKeyguardService;
103import com.android.internal.policy.IKeyguardServiceConstants;
Craig Mautnerae446592012-12-06 19:05:05 -0800104import com.android.internal.policy.PolicyManager;
Jim Miller5ecd8112013-01-09 18:50:26 -0800105import com.android.internal.policy.impl.keyguard.KeyguardServiceDelegate;
Craig Mautner8a0da012014-05-31 15:13:37 -0700106import com.android.internal.policy.impl.keyguard.KeyguardServiceDelegate.ShowListener;
Craig Mautnerae446592012-12-06 19:05:05 -0800107import com.android.internal.statusbar.IStatusBarService;
108import com.android.internal.telephony.ITelephony;
109import com.android.internal.widget.PointerLocationView;
Craig Mautner8a0da012014-05-31 15:13:37 -0700110import com.android.server.LocalServices;
Craig Mautnerae446592012-12-06 19:05:05 -0800111
112import java.io.File;
113import java.io.FileReader;
114import java.io.IOException;
115import java.io.PrintWriter;
Craig Mautner8a0da012014-05-31 15:13:37 -0700116import java.util.ArrayList;
Craig Mautner2bc789b2014-03-19 19:48:38 -0700117import java.util.HashSet;
Craig Mautnerae446592012-12-06 19:05:05 -0800118
Dianne Hackbornc652de82013-02-15 16:32:56 -0800119import static android.view.WindowManager.LayoutParams.*;
Jeff Brownac143512012-04-05 18:57:33 -0700120import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_ABSENT;
121import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_OPEN;
122import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_CLOSED;
Dianne Hackborn08743722009-12-21 12:16:51 -0800123
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800124/**
The Android Open Source Project0727d222009-03-11 12:11:58 -0700125 * WindowManagerPolicy implementation for the Android phone UI. This
126 * introduces a new method suffix, Lp, for an internal lock of the
127 * PhoneWindowManager. This is used to protect some internal state, and
John Spurlock04db1762013-05-13 12:46:41 -0400128 * 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 -0700129 * of both of those when held.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800130 */
131public class PhoneWindowManager implements WindowManagerPolicy {
132 static final String TAG = "WindowManager";
133 static final boolean DEBUG = false;
Joe Onorato43a17652011-04-06 19:22:23 -0700134 static final boolean localLOGV = false;
The Android Open Source Project11267662009-03-18 17:39:47 -0700135 static final boolean DEBUG_LAYOUT = false;
Jeff Brown40013652012-05-16 21:22:36 -0700136 static final boolean DEBUG_INPUT = false;
Craig Mautner6fbda632012-07-03 09:26:39 -0700137 static final boolean DEBUG_STARTING_WINDOW = false;
Craig Mautner8a0da012014-05-31 15:13:37 -0700138 static final boolean DEBUG_WAKEUP = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800139 static final boolean SHOW_STARTING_ANIMATIONS = true;
140 static final boolean SHOW_PROCESSES_ON_ALT_MENU = false;
Joe Onoratod208e702010-10-08 16:22:43 -0400141
Daniel Sandler6396c722013-04-16 20:19:09 -0400142 // Whether to allow dock apps with METADATA_DOCK_HOME to temporarily take over the Home key.
143 // No longer recommended for desk docks; still useful in car docks.
144 static final boolean ENABLE_CAR_DOCK_HOME_CAPTURE = true;
145 static final boolean ENABLE_DESK_DOCK_HOME_CAPTURE = false;
146
RoboErik8a2cfc32014-05-16 11:19:38 -0700147 // Whether to use the new Session APIs
148 static final boolean USE_SESSIONS = true;
149
Jeff Brown6d8fd272014-05-20 21:24:38 -0700150 static final int SHORT_PRESS_POWER_NOTHING = 0;
151 static final int SHORT_PRESS_POWER_GO_TO_SLEEP = 1;
152 static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP = 2;
153 static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME = 3;
154
Joe Onoratod208e702010-10-08 16:22:43 -0400155 static final int LONG_PRESS_POWER_NOTHING = 0;
156 static final int LONG_PRESS_POWER_GLOBAL_ACTIONS = 1;
157 static final int LONG_PRESS_POWER_SHUT_OFF = 2;
Jeff Brown9a538ee2012-08-20 14:56:57 -0700158 static final int LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM = 3;
Michael Jurka3b1fc472011-06-13 10:54:40 -0700159
160 // These need to match the documentation/constant in
161 // core/res/res/values/config.xml
Joe Onorato46b0d682010-11-22 17:37:27 -0800162 static final int LONG_PRESS_HOME_NOTHING = 0;
Michael Wrightc9ebea72013-01-16 19:25:02 -0800163 static final int LONG_PRESS_HOME_RECENT_SYSTEM_UI = 1;
Jeff Browncaca8812013-05-09 13:34:33 -0700164 static final int LONG_PRESS_HOME_ASSIST = 2;
165
166 static final int DOUBLE_TAP_HOME_NOTHING = 0;
167 static final int DOUBLE_TAP_HOME_RECENT_SYSTEM_UI = 1;
Joe Onorato46b0d682010-11-22 17:37:27 -0800168
Dianne Hackborn5cb8d792009-05-21 17:34:15 -0700169 static final int APPLICATION_MEDIA_SUBLAYER = -2;
170 static final int APPLICATION_MEDIA_OVERLAY_SUBLAYER = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800171 static final int APPLICATION_PANEL_SUBLAYER = 1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800172 static final int APPLICATION_SUB_PANEL_SUBLAYER = 2;
Craig Mautner88400d32012-09-30 12:35:45 -0700173
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800174 static public final String SYSTEM_DIALOG_REASON_KEY = "reason";
175 static public final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions";
176 static public final String SYSTEM_DIALOG_REASON_RECENT_APPS = "recentapps";
Joe Onoratof275f0c2009-11-24 16:11:13 -0500177 static public final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey";
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700178 static public final String SYSTEM_DIALOG_REASON_ASSIST = "assist";
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800179
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700180 /**
181 * These are the system UI flags that, when changing, can cause the layout
182 * of the screen to change.
183 */
184 static final int SYSTEM_UI_CHANGING_LAYOUT =
John Spurlocke1f366f2013-08-05 12:22:40 -0400185 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlock7f4820a2013-10-08 12:54:35 -0400186 | View.SYSTEM_UI_FLAG_FULLSCREEN
187 | View.STATUS_BAR_TRANSLUCENT
Adrian Roosea562512014-05-05 13:33:03 +0200188 | View.NAVIGATION_BAR_TRANSLUCENT
189 | View.SYSTEM_UI_TRANSPARENT;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700190
Jim Miller5ecd8112013-01-09 18:50:26 -0800191 /**
192 * Keyguard stuff
193 */
194 private WindowState mKeyguardScrim;
Jorim Jaggi380ecb82014-03-14 17:25:20 +0100195 private boolean mKeyguardHidden;
Jorim Jaggicff0acb2014-03-31 16:35:15 +0200196 private boolean mKeyguardDrawn;
Jim Miller5ecd8112013-01-09 18:50:26 -0800197
Jeff Brown6651a632011-11-28 12:59:11 -0800198 /* Table of Application Launch keys. Maps from key codes to intent categories.
199 *
200 * These are special keys that are used to launch particular kinds of applications,
201 * such as a web browser. HID defines nearly a hundred of them in the Consumer (0x0C)
202 * usage page. We don't support quite that many yet...
203 */
204 static SparseArray<String> sApplicationLaunchKeyCategories;
205 static {
206 sApplicationLaunchKeyCategories = new SparseArray<String>();
207 sApplicationLaunchKeyCategories.append(
208 KeyEvent.KEYCODE_EXPLORER, Intent.CATEGORY_APP_BROWSER);
209 sApplicationLaunchKeyCategories.append(
210 KeyEvent.KEYCODE_ENVELOPE, Intent.CATEGORY_APP_EMAIL);
211 sApplicationLaunchKeyCategories.append(
212 KeyEvent.KEYCODE_CONTACTS, Intent.CATEGORY_APP_CONTACTS);
213 sApplicationLaunchKeyCategories.append(
214 KeyEvent.KEYCODE_CALENDAR, Intent.CATEGORY_APP_CALENDAR);
215 sApplicationLaunchKeyCategories.append(
216 KeyEvent.KEYCODE_MUSIC, Intent.CATEGORY_APP_MUSIC);
217 sApplicationLaunchKeyCategories.append(
218 KeyEvent.KEYCODE_CALCULATOR, Intent.CATEGORY_APP_CALCULATOR);
219 }
220
Dianne Hackborndf89e652011-10-06 22:35:11 -0700221 /**
222 * Lock protecting internal state. Must not call out into window
223 * manager with lock held. (This lock will be acquired in places
224 * where the window manager is calling in with its own lock held.)
225 */
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800226 private final Object mLock = new Object();
Dianne Hackborndf89e652011-10-06 22:35:11 -0700227
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800228 Context mContext;
229 IWindowManager mWindowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700230 WindowManagerFuncs mWindowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -0700231 WindowManagerInternal mWindowManagerInternal;
Jeff Brown96307042012-07-27 15:51:34 -0700232 PowerManager mPowerManager;
Joe Onorato93056472010-09-10 10:30:46 -0400233 IStatusBarService mStatusBarService;
Jeff Browncaca8812013-05-09 13:34:33 -0700234 boolean mPreloadedRecentApps;
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700235 final Object mServiceAquireLock = new Object();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800236 Vibrator mVibrator; // Vibrator for giving feedback of orientation changes
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700237 SearchManager mSearchManager;
Svetoslav8e3feb12014-02-24 13:46:47 -0800238 AccessibilityManager mAccessibilityManager;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800239
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700240 // Vibrator pattern for haptic feedback of a long press.
241 long[] mLongPressVibePattern;
Craig Mautner88400d32012-09-30 12:35:45 -0700242
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700243 // Vibrator pattern for haptic feedback of virtual key press.
244 long[] mVirtualKeyVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700245
Amith Yamasanic33cb712010-02-10 15:21:49 -0800246 // Vibrator pattern for a short vibration.
247 long[] mKeyboardTapVibePattern;
248
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -0700249 // Vibrator pattern for a short vibration when tapping on an hour/minute tick of a Clock.
250 long[] mClockTickVibePattern;
251
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700252 // Vibrator pattern for haptic feedback during boot when safe mode is disabled.
253 long[] mSafeModeDisabledVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700254
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700255 // Vibrator pattern for haptic feedback during boot when safe mode is enabled.
256 long[] mSafeModeEnabledVibePattern;
Romain Guy8154cd32010-03-29 14:41:15 -0700257
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800258 /** If true, hitting shift & menu will broadcast Intent.ACTION_BUG_REPORT */
259 boolean mEnableShiftMenuBugReports = false;
Mike Lockwoodd747dc82011-09-13 16:28:22 -0400260
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800261 boolean mSafeMode;
262 WindowState mStatusBar = null;
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700263 int mStatusBarHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400264 WindowState mNavigationBar = null;
Daniel Sandler36412a72011-08-04 09:35:13 -0400265 boolean mHasNavigationBar = false;
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700266 boolean mCanHideNavigationBar = false;
Daniel Sandler4a066c52012-04-20 14:49:13 -0400267 boolean mNavigationBarCanMove = false; // can the navigation bar ever move to the side?
268 boolean mNavigationBarOnBottom = true; // is the navigation bar on the bottom *right now*?
269 int[] mNavigationBarHeightForRotation = new int[4];
270 int[] mNavigationBarWidthForRotation = new int[4];
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400271
Jim Miller5ecd8112013-01-09 18:50:26 -0800272 KeyguardServiceDelegate mKeyguardDelegate;
Craig Mautner8a0da012014-05-31 15:13:37 -0700273 // The following are only accessed on the mHandler thread.
274 boolean mKeyguardDrawComplete;
275 boolean mWindowManagerDrawComplete;
276 ArrayList<ScreenOnListener> mScreenOnListeners = new ArrayList<ScreenOnListener>();
277 final IRemoteCallback mWindowManagerDrawCallback = new IRemoteCallback.Stub() {
278 @Override
279 public void sendResult(Bundle data) {
280 if (DEBUG_WAKEUP) Slog.i(TAG, "All windows ready for display!");
281 mHandler.sendEmptyMessage(MSG_WINDOW_MANAGER_DRAWN_COMPLETE);
282 }
283 };
284 final ShowListener mKeyguardDelegateCallback = new ShowListener() {
285 @Override
286 public void onShown(IBinder windowToken) {
287 if (DEBUG_WAKEUP) Slog.d(TAG, "mKeyguardDelegate.ShowListener.onShown.");
288 mHandler.sendEmptyMessage(MSG_KEYGUARD_DRAWN_COMPLETE);
289 }
290 };
291
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800292 GlobalActions mGlobalActions;
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700293 volatile boolean mPowerKeyHandled; // accessed from input reader and handler thread
294 boolean mPendingPowerKeyUpCanceled;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800295 Handler mHandler;
satok1bc0a492012-04-25 22:47:12 +0900296 WindowState mLastInputMethodWindow = null;
297 WindowState mLastInputMethodTargetWindow = null;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800298
Winson Chungd42a6cf2014-06-03 16:24:04 -0700299 boolean mRecentsVisible;
Winson Chung1e8d71b2014-05-16 17:05:22 -0700300 int mRecentAppsHeldModifiers;
Jeff Browncf39bdf2012-05-18 14:41:19 -0700301 boolean mLanguageSwitchKeyPressed;
Jeff Brown68b909d2011-12-07 16:36:01 -0800302
Jeff Brown2e7760e2012-04-11 15:14:55 -0700303 int mLidState = LID_ABSENT;
Jeff Browndaa37532012-05-01 15:54:03 -0700304 boolean mHaveBuiltInKeyboard;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800305
Dianne Hackbornc777e072010-02-12 13:07:59 -0800306 boolean mSystemReady;
Dianne Hackbornba24e4d2011-09-01 11:17:06 -0700307 boolean mSystemBooted;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800308 boolean mHdmiPlugged;
Daniel Sandler6396c722013-04-16 20:19:09 -0400309 int mUiMode;
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700310 int mDockMode = Intent.EXTRA_DOCK_STATE_UNDOCKED;
Mike Lockwood1753f7f2009-08-24 14:49:07 -0700311 int mLidOpenRotation;
Mike Lockwood2d1efbd2009-09-16 12:15:53 -0400312 int mCarDockRotation;
313 int mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -0700314 int mUndockedHdmiRotation;
315 int mDemoHdmiRotation;
316 boolean mDemoHdmiRotationLock;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400317
Jeff Browna20dda42014-05-27 20:57:24 -0700318 boolean mWakeGestureEnabledSetting;
319 MyWakeGestureListener mWakeGestureListener;
320
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700321 // Default display does not rotate, apps that require non-default orientation will have to
322 // have the orientation emulated.
323 private boolean mForceDefaultOrientation = false;
324
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400325 int mUserRotationMode = WindowManagerPolicy.USER_ROTATION_FREE;
326 int mUserRotation = Surface.ROTATION_0;
Jeff Brown207673cd2012-06-05 17:47:11 -0700327 boolean mAccelerometerDefault;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400328
Jeff Brownbcdfc622014-03-06 19:13:04 -0800329 boolean mSupportAutoRotation;
Jeff Brownd3187e32011-09-21 19:26:44 -0700330 int mAllowAllRotations = -1;
Mike Lockwoode9867d22009-09-20 01:59:02 -0400331 boolean mCarDockEnablesAccelerometer;
332 boolean mDeskDockEnablesAccelerometer;
Dianne Hackborn2862fff2009-09-15 22:56:29 -0700333 int mLidKeyboardAccessibility;
334 int mLidNavigationAccessibility;
Jeff Brownc458ce92012-04-30 14:58:40 -0700335 boolean mLidControlsSleep;
Jeff Brown6d8fd272014-05-20 21:24:38 -0700336 int mShortPressOnPowerBehavior = -1;
Joe Onoratod208e702010-10-08 16:22:43 -0400337 int mLongPressOnPowerBehavior = -1;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -0700338 boolean mScreenOnEarly = false;
339 boolean mScreenOnFully = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800340 boolean mOrientationSensorEnabled = false;
341 int mCurrentAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800342 boolean mHasSoftInput = false;
Daniel Sandlerdd73ee42013-10-11 22:19:59 -0400343 boolean mTranslucentDecorEnabled = true;
Craig Mautner967212c2013-04-13 21:10:58 -0700344
Jeff Brown70825162012-03-28 17:27:48 -0700345 int mPointerLocationMode = 0; // guarded by mLock
Joe Onorato664644d2011-01-23 17:53:23 -0800346
347 // The last window we were told about in focusChanged.
348 WindowState mFocusedWindow;
Dianne Hackborne0f085d2011-11-30 18:41:15 -0800349 IApplicationToken mFocusedApp;
Joe Onorato664644d2011-01-23 17:53:23 -0800350
Jeff Brown70825162012-03-28 17:27:48 -0700351 PointerLocationView mPointerLocationView;
Jeff Brown32cbc38552011-12-01 14:01:49 -0800352
Dianne Hackbornc652de82013-02-15 16:32:56 -0800353 // The current size of the screen; really; extends into the overscan area of
354 // the screen and doesn't account for any system elements like the status bar.
355 int mOverscanScreenLeft, mOverscanScreenTop;
356 int mOverscanScreenWidth, mOverscanScreenHeight;
357 // The current visible size of the screen; really; (ir)regardless of whether the status
358 // bar can be hidden but not extending into the overscan area.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800359 int mUnrestrictedScreenLeft, mUnrestrictedScreenTop;
360 int mUnrestrictedScreenWidth, mUnrestrictedScreenHeight;
Dianne Hackborn313440842013-02-19 19:22:59 -0800361 // Like mOverscanScreen*, but allowed to move into the overscan region where appropriate.
362 int mRestrictedOverscanScreenLeft, mRestrictedOverscanScreenTop;
363 int mRestrictedOverscanScreenWidth, mRestrictedOverscanScreenHeight;
Dianne Hackborn82de1ae2010-10-28 11:28:39 -0700364 // The current size of the screen; these may be different than (0,0)-(dw,dh)
365 // if the status bar can't be hidden; in that case it effectively carves out
366 // that area of the display from all other windows.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800367 int mRestrictedScreenLeft, mRestrictedScreenTop;
368 int mRestrictedScreenWidth, mRestrictedScreenHeight;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700369 // During layout, the current screen borders accounting for any currently
370 // visible system UI elements.
371 int mSystemLeft, mSystemTop, mSystemRight, mSystemBottom;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700372 // For applications requesting stable content insets, these are them.
373 int mStableLeft, mStableTop, mStableRight, mStableBottom;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -0700374 // For applications requesting stable content insets but have also set the
375 // fullscreen window flag, these are the stable dimensions without the status bar.
376 int mStableFullscreenLeft, mStableFullscreenTop;
377 int mStableFullscreenRight, mStableFullscreenBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800378 // During layout, the current screen borders with all outer decoration
379 // (status bar, input method dock) accounted for.
380 int mCurLeft, mCurTop, mCurRight, mCurBottom;
381 // During layout, the frame in which content should be displayed
382 // to the user, accounting for all screen decoration except for any
383 // space they deem as available for other content. This is usually
384 // the same as mCur*, but may be larger if the screen decor has supplied
385 // content insets.
386 int mContentLeft, mContentTop, mContentRight, mContentBottom;
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700387 // During layout, the frame in which voice content should be displayed
388 // to the user, accounting for all screen decoration except for any
389 // space they deem as available for other content.
390 int mVoiceContentLeft, mVoiceContentTop, mVoiceContentRight, mVoiceContentBottom;
Dianne Hackborn8e11ef02010-11-18 19:47:42 -0800391 // During layout, the current screen borders along which input method
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800392 // windows are placed.
393 int mDockLeft, mDockTop, mDockRight, mDockBottom;
394 // During layout, the layer at which the doc window is placed.
395 int mDockLayer;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700396 // During layout, this is the layer of the status bar.
397 int mStatusBarLayer;
Dianne Hackborne26ab702011-10-16 13:21:33 -0700398 int mLastSystemUiFlags;
399 // Bits that we are in the process of clearing, so we want to prevent
400 // them from being set by applications until everything has been updated
401 // to have them clear.
402 int mResettingSystemUiFlags = 0;
403 // Bits that we are currently always keeping cleared.
404 int mForceClearedSystemUiFlags = 0;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -0800405 // What we last reported to system UI about whether the compatibility
406 // menu needs to be displayed.
407 boolean mLastFocusNeedsMenu = false;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700408
409 FakeWindow mHideNavFakeWindow = null;
410
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800411 static final Rect mTmpParentFrame = new Rect();
412 static final Rect mTmpDisplayFrame = new Rect();
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800413 static final Rect mTmpOverscanFrame = new Rect();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800414 static final Rect mTmpContentFrame = new Rect();
415 static final Rect mTmpVisibleFrame = new Rect();
John Spurlock46646232013-09-30 22:32:42 -0400416 static final Rect mTmpDecorFrame = new Rect();
Dianne Hackborn1f903c32011-09-13 19:18:06 -0700417 static final Rect mTmpNavigationFrame = new Rect();
Craig Mautner967212c2013-04-13 21:10:58 -0700418
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800419 WindowState mTopFullscreenOpaqueWindowState;
Craig Mautner2bc789b2014-03-19 19:48:38 -0700420 HashSet<IApplicationToken> mAppsToBeHidden = new HashSet<IApplicationToken>();
Joe Onorato93056472010-09-10 10:30:46 -0400421 boolean mTopIsFullscreen;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800422 boolean mForceStatusBar;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -0700423 boolean mForceStatusBarFromKeyguard;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700424 boolean mHideLockScreen;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -0800425 boolean mForcingShowNavBar;
426 int mForcingShowNavBarLayer;
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700427
428 // States of keyguard dismiss.
429 private static final int DISMISS_KEYGUARD_NONE = 0; // Keyguard not being dismissed.
430 private static final int DISMISS_KEYGUARD_START = 1; // Keyguard needs to be dismissed.
431 private static final int DISMISS_KEYGUARD_CONTINUE = 2; // Keyguard has been dismissed.
432 int mDismissKeyguard = DISMISS_KEYGUARD_NONE;
433
434 /** The window that is currently dismissing the keyguard. Dismissing the keyguard must only
435 * be done once per window. */
436 private WindowState mWinDismissingKeyguard;
437
Dianne Hackborn7ad44382012-10-18 17:46:00 -0700438 boolean mShowingLockscreen;
439 boolean mShowingDream;
440 boolean mDreamingLockscreen;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800441 boolean mHomePressed;
Jeff Browncaca8812013-05-09 13:34:33 -0700442 boolean mHomeConsumed;
443 boolean mHomeDoubleTapPending;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800444 Intent mHomeIntent;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700445 Intent mCarDockIntent;
446 Intent mDeskDockIntent;
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700447 boolean mSearchKeyShortcutPending;
448 boolean mConsumeSearchKeyUp;
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700449 boolean mAssistKeyLongPressed;
Michael Wright6a62e552014-06-03 19:19:48 -0700450 boolean mPendingMetaAction;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800451
Mike Lockwood28569302010-01-28 11:54:40 -0500452 // support for activating the lock screen while the screen is on
453 boolean mAllowLockscreenWhenOn;
454 int mLockScreenTimeout;
455 boolean mLockScreenTimerActive;
456
David Brownbaf8d092010-03-08 21:52:59 -0800457 // Behavior of ENDCALL Button. (See Settings.System.END_BUTTON_BEHAVIOR.)
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800458 int mEndcallBehavior;
David Brownbaf8d092010-03-08 21:52:59 -0800459
460 // Behavior of POWER button while in-call and screen on.
461 // (See Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR.)
462 int mIncallPowerBehavior;
463
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700464 Display mDisplay;
465
Dianne Hackborn9d132642011-04-21 17:26:39 -0700466 int mLandscapeRotation = 0; // default landscape rotation
467 int mSeascapeRotation = 0; // "other" landscape rotation, 180 degrees from mLandscapeRotation
468 int mPortraitRotation = 0; // default portrait rotation
469 int mUpsideDownRotation = 0; // "other" portrait rotation
Mitsuru Oshima831d0d92009-06-16 18:27:18 -0700470
Dianne Hackbornc652de82013-02-15 16:32:56 -0800471 int mOverscanLeft = 0;
472 int mOverscanTop = 0;
473 int mOverscanRight = 0;
474 int mOverscanBottom = 0;
475
Joe Onorato46b0d682010-11-22 17:37:27 -0800476 // What we do when the user long presses on home
Jeff Browncaca8812013-05-09 13:34:33 -0700477 private int mLongPressOnHomeBehavior;
478
479 // What we do when the user double-taps on home
480 private int mDoubleTapOnHomeBehavior;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800481
Winson Chung9112ec32011-06-27 13:15:32 -0700482 // Screenshot trigger states
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700483 // Time to volume and power must be pressed within this interval of each other.
484 private static final long SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS = 150;
Winson Chung1cea2f32012-10-08 20:42:01 -0700485 // Increase the chord delay when taking a screenshot from the keyguard
486 private static final float KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER = 2.5f;
Christopher Tatee90585f2012-03-05 18:56:25 -0800487 private boolean mScreenshotChordEnabled;
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700488 private boolean mVolumeDownKeyTriggered;
489 private long mVolumeDownKeyTime;
490 private boolean mVolumeDownKeyConsumedByScreenshotChord;
491 private boolean mVolumeUpKeyTriggered;
492 private boolean mPowerKeyTriggered;
493 private long mPowerKeyTime;
Winson Chung9112ec32011-06-27 13:15:32 -0700494
Michael Wrightb854e242013-02-05 17:54:02 -0800495 /* The number of steps between min and max brightness */
496 private static final int BRIGHTNESS_STEPS = 10;
497
Christopher Tate5e08af02012-09-21 17:17:22 -0700498 SettingsObserver mSettingsObserver;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800499 ShortcutManager mShortcutManager;
500 PowerManager.WakeLock mBroadcastWakeLock;
Jeff Brown40013652012-05-16 21:22:36 -0700501 boolean mHavePendingMediaKeyRepeatWithWakeLock;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800502
Craig Mautnerd625ab22013-09-06 13:40:31 -0700503 private int mCurrentUserId;
504
Justin Kohd378ad72013-04-01 12:18:26 -0700505 // Maps global key codes to the components that will handle them.
506 private GlobalKeyManager mGlobalKeyManager;
507
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700508 // Fallback actions by key code.
509 private final SparseArray<KeyCharacterMap.FallbackAction> mFallbackActions =
510 new SparseArray<KeyCharacterMap.FallbackAction>();
Jeff Brown49ed71d2010-12-06 17:13:33 -0800511
Jeff Brown70825162012-03-28 17:27:48 -0700512 private static final int MSG_ENABLE_POINTER_LOCATION = 1;
513 private static final int MSG_DISABLE_POINTER_LOCATION = 2;
Jeff Brown40013652012-05-16 21:22:36 -0700514 private static final int MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK = 3;
515 private static final int MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK = 4;
Craig Mautner8a0da012014-05-31 15:13:37 -0700516 private static final int MSG_KEYGUARD_DRAWN_COMPLETE = 5;
517 private static final int MSG_KEYGUARD_DRAWN_TIMEOUT = 6;
518 private static final int MSG_WINDOW_MANAGER_DRAWN_COMPLETE = 7;
519 private static final int MSG_WAKING_UP = 8;
Jeff Brown70825162012-03-28 17:27:48 -0700520
521 private class PolicyHandler extends Handler {
522 @Override
523 public void handleMessage(Message msg) {
524 switch (msg.what) {
525 case MSG_ENABLE_POINTER_LOCATION:
526 enablePointerLocation();
527 break;
528 case MSG_DISABLE_POINTER_LOCATION:
529 disablePointerLocation();
530 break;
Jeff Brown40013652012-05-16 21:22:36 -0700531 case MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK:
532 dispatchMediaKeyWithWakeLock((KeyEvent)msg.obj);
533 break;
534 case MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK:
535 dispatchMediaKeyRepeatWithWakeLock((KeyEvent)msg.obj);
536 break;
Craig Mautner8a0da012014-05-31 15:13:37 -0700537 case MSG_KEYGUARD_DRAWN_COMPLETE:
538 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mKeyguardDrawComplete");
539 mKeyguardDrawComplete = true;
540 finishScreenTurningOn();
541 break;
542 case MSG_KEYGUARD_DRAWN_TIMEOUT:
543 Slog.w(TAG, "Keyguard drawn timeout. Setting mKeyguardDrawComplete");
544 mKeyguardDrawComplete = true;
545 finishScreenTurningOn();
546 break;
547 case MSG_WINDOW_MANAGER_DRAWN_COMPLETE:
548 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mWindowManagerDrawComplete");
549 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
550 mWindowManagerDrawComplete = true;
551 finishScreenTurningOn();
552 break;
553 case MSG_WAKING_UP:
554 handleWakingUp((ScreenOnListener) msg.obj);
555 break;
Jeff Brown70825162012-03-28 17:27:48 -0700556 }
557 }
558 }
559
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800560 private UEventObserver mHDMIObserver = new UEventObserver() {
561 @Override
562 public void onUEvent(UEventObserver.UEvent event) {
563 setHdmiPlugged("1".equals(event.get("SWITCH_STATE")));
564 }
565 };
566
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800567 class SettingsObserver extends ContentObserver {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800568 SettingsObserver(Handler handler) {
569 super(handler);
570 }
David Brownbaf8d092010-03-08 21:52:59 -0800571
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800572 void observe() {
Christopher Tate5e08af02012-09-21 17:17:22 -0700573 // Observe all users' changes
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800574 ContentResolver resolver = mContext.getContentResolver();
575 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700576 Settings.System.END_BUTTON_BEHAVIOR), false, this,
577 UserHandle.USER_ALL);
David Brownbaf8d092010-03-08 21:52:59 -0800578 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700579 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR), false, this,
580 UserHandle.USER_ALL);
Jeff Browna20dda42014-05-27 20:57:24 -0700581 resolver.registerContentObserver(Settings.Secure.getUriFor(
582 Settings.Secure.WAKE_GESTURE_ENABLED), false, this,
583 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800584 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700585 Settings.System.ACCELEROMETER_ROTATION), false, this,
586 UserHandle.USER_ALL);
Mike Lockwood28569302010-01-28 11:54:40 -0500587 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700588 Settings.System.USER_ROTATION), false, this,
589 UserHandle.USER_ALL);
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400590 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700591 Settings.System.SCREEN_OFF_TIMEOUT), false, this,
592 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800593 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700594 Settings.System.POINTER_LOCATION), false, this,
595 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800596 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700597 Settings.Secure.DEFAULT_INPUT_METHOD), false, this,
598 UserHandle.USER_ALL);
John Spurlockd9b70bd2014-02-06 17:02:44 -0500599 resolver.registerContentObserver(Settings.Secure.getUriFor(
John Spurlockf1a36642013-10-12 17:50:42 -0400600 Settings.Secure.IMMERSIVE_MODE_CONFIRMATIONS), false, this,
Christopher Tate5e08af02012-09-21 17:17:22 -0700601 UserHandle.USER_ALL);
John Spurlockc6d1c602014-01-17 15:22:06 -0500602 resolver.registerContentObserver(Settings.Global.getUriFor(
603 Settings.Global.POLICY_CONTROL), false, this,
604 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800605 updateSettings();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800606 }
607
608 @Override public void onChange(boolean selfChange) {
Dianne Hackbornc777e072010-02-12 13:07:59 -0800609 updateSettings();
Jeff Brown01a98dd2011-09-20 15:08:29 -0700610 updateRotation(false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800611 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800612 }
Craig Mautner967212c2013-04-13 21:10:58 -0700613
Jeff Browna20dda42014-05-27 20:57:24 -0700614 class MyWakeGestureListener extends WakeGestureListener {
615 MyWakeGestureListener(Context context, Handler handler) {
616 super(context, handler);
617 }
618
619 @Override
620 public void onWakeUp() {
621 synchronized (mLock) {
622 if (shouldEnableWakeGestureLp()) {
623 mPowerManager.wakeUp(SystemClock.uptimeMillis());
624 }
625 }
626 }
627 }
628
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800629 class MyOrientationListener extends WindowOrientationListener {
Craig Mautnereee29c42013-01-17 14:44:34 -0800630 MyOrientationListener(Context context, Handler handler) {
631 super(context, handler);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800632 }
Craig Mautner967212c2013-04-13 21:10:58 -0700633
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800634 @Override
Jeff Brownc0347aa2011-09-23 17:26:09 -0700635 public void onProposedRotationChanged(int rotation) {
Craig Mautnereda67292013-04-28 13:50:14 -0700636 if (localLOGV) Slog.v(TAG, "onProposedRotationChanged, rotation=" + rotation);
Jeff Brown01a98dd2011-09-20 15:08:29 -0700637 updateRotation(false);
638 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800639 }
640 MyOrientationListener mOrientationListener;
641
John Spurlock27735a42013-08-14 17:57:38 -0400642 private final BarController mStatusBarController = new BarController("StatusBar",
John Spurlock5b9145b2013-08-20 15:13:47 -0400643 View.STATUS_BAR_TRANSIENT,
644 View.STATUS_BAR_UNHIDE,
John Spurlockbd957402013-10-03 11:38:39 -0400645 View.STATUS_BAR_TRANSLUCENT,
646 StatusBarManager.WINDOW_STATUS_BAR,
647 WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
John Spurlock5b9145b2013-08-20 15:13:47 -0400648
John Spurlock27735a42013-08-14 17:57:38 -0400649 private final BarController mNavigationBarController = new BarController("NavigationBar",
John Spurlock5b9145b2013-08-20 15:13:47 -0400650 View.NAVIGATION_BAR_TRANSIENT,
651 View.NAVIGATION_BAR_UNHIDE,
John Spurlockbd957402013-10-03 11:38:39 -0400652 View.NAVIGATION_BAR_TRANSLUCENT,
653 StatusBarManager.WINDOW_NAVIGATION_BAR,
654 WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
John Spurlock5b9145b2013-08-20 15:13:47 -0400655
John Spurlockf1a36642013-10-12 17:50:42 -0400656 private ImmersiveModeConfirmation mImmersiveModeConfirmation;
John Spurlock32beb2c2013-03-11 10:16:47 -0400657
Craig Mautner037aa8d2013-06-07 10:35:44 -0700658 private SystemGesturesPointerEventListener mSystemGestures;
John Spurlock32beb2c2013-03-11 10:16:47 -0400659
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700660 IStatusBarService getStatusBarService() {
661 synchronized (mServiceAquireLock) {
662 if (mStatusBarService == null) {
663 mStatusBarService = IStatusBarService.Stub.asInterface(
664 ServiceManager.getService("statusbar"));
665 }
666 return mStatusBarService;
667 }
668 }
669
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700670 /*
671 * We always let the sensor be switched on by default except when
672 * the user has explicitly disabled sensor based rotation or when the
673 * screen is switched off.
674 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700675 boolean needSensorRunningLp() {
Jeff Brownbcdfc622014-03-06 19:13:04 -0800676 if (mSupportAutoRotation) {
677 if (mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
678 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
679 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT
680 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) {
681 // If the application has explicitly requested to follow the
682 // orientation, then we need to turn the sensor on.
683 return true;
684 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800685 }
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700686 if ((mCarDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_CAR) ||
Jeff Brown1a693182011-11-08 14:44:16 -0800687 (mDeskDockEnablesAccelerometer && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
688 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
689 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK))) {
Mike Lockwoode9867d22009-09-20 01:59:02 -0400690 // enable accelerometer if we are docked in a dock that enables accelerometer
691 // orientation management,
692 return true;
693 }
Jeff Brown207673cd2012-06-05 17:47:11 -0700694 if (mUserRotationMode == USER_ROTATION_LOCKED) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800695 // If the setting for using the sensor by default is enabled, then
696 // we will always leave it on. Note that the user could go to
697 // a window that forces an orientation that does not use the
698 // sensor and in theory we could turn it off... however, when next
699 // turning it on we won't have a good value for the current
700 // orientation for a little bit, which can cause orientation
701 // changes to lag, so we'd like to keep it always on. (It will
702 // still be turned off when the screen is off.)
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700703 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800704 }
Jeff Brownbcdfc622014-03-06 19:13:04 -0800705 return mSupportAutoRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800706 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700707
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800708 /*
709 * Various use cases for invoking this function
710 * screen turning off, should always disable listeners if already enabled
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700711 * screen turned on and current app has sensor based orientation, enable listeners
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800712 * if not already enabled
713 * screen turned on and current app does not have sensor orientation, disable listeners if
714 * already enabled
715 * screen turning on and current app has sensor based orientation, enable listeners if needed
716 * screen turning on and current app has nosensor based orientation, do nothing
717 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700718 void updateOrientationListenerLp() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800719 if (!mOrientationListener.canDetectOrientation()) {
720 // If sensor is turned off or nonexistent for some reason
721 return;
722 }
723 //Could have been invoked due to screen turning on or off or
724 //change of the currently visible window's orientation
Craig Mautnereda67292013-04-28 13:50:14 -0700725 if (localLOGV) Slog.v(TAG, "Screen status="+mScreenOnEarly+
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800726 ", current orientation="+mCurrentAppOrientation+
727 ", SensorEnabled="+mOrientationSensorEnabled);
728 boolean disable = true;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -0700729 if (mScreenOnEarly) {
The Android Open Source Project0727d222009-03-11 12:11:58 -0700730 if (needSensorRunningLp()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800731 disable = false;
732 //enable listener if not already enabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700733 if (!mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800734 mOrientationListener.enable();
Craig Mautnereda67292013-04-28 13:50:14 -0700735 if(localLOGV) Slog.v(TAG, "Enabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800736 mOrientationSensorEnabled = true;
737 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700738 }
739 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800740 //check if sensors need to be disabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700741 if (disable && mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800742 mOrientationListener.disable();
Craig Mautnereda67292013-04-28 13:50:14 -0700743 if(localLOGV) Slog.v(TAG, "Disabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800744 mOrientationSensorEnabled = false;
745 }
746 }
747
Jeff Brown4d396052010-10-29 21:50:21 -0700748 private void interceptPowerKeyDown(boolean handled) {
749 mPowerKeyHandled = handled;
750 if (!handled) {
Justin Kohfeabd2c2014-05-02 10:02:44 -0700751 mHandler.postDelayed(mPowerLongPress,
752 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Jeff Brown4d396052010-10-29 21:50:21 -0700753 }
754 }
755
756 private boolean interceptPowerKeyUp(boolean canceled) {
757 if (!mPowerKeyHandled) {
758 mHandler.removeCallbacks(mPowerLongPress);
759 return !canceled;
Jeff Brown4d396052010-10-29 21:50:21 -0700760 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700761 return false;
762 }
763
764 private void cancelPendingPowerKeyAction() {
765 if (!mPowerKeyHandled) {
766 mHandler.removeCallbacks(mPowerLongPress);
767 }
Jeff Brownff204712011-10-25 21:27:54 -0700768 if (mPowerKeyTriggered) {
769 mPendingPowerKeyUpCanceled = true;
770 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700771 }
772
773 private void interceptScreenshotChord() {
Christopher Tatee90585f2012-03-05 18:56:25 -0800774 if (mScreenshotChordEnabled
775 && mVolumeDownKeyTriggered && mPowerKeyTriggered && !mVolumeUpKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700776 final long now = SystemClock.uptimeMillis();
777 if (now <= mVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS
778 && now <= mPowerKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) {
779 mVolumeDownKeyConsumedByScreenshotChord = true;
780 cancelPendingPowerKeyAction();
781
Jeff Sharkey2991fa32012-12-05 18:06:43 -0800782 mHandler.postDelayed(mScreenshotRunnable, getScreenshotChordLongPressDelay());
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700783 }
784 }
785 }
786
Winson Chung1cea2f32012-10-08 20:42:01 -0700787 private long getScreenshotChordLongPressDelay() {
Jim Miller5ecd8112013-01-09 18:50:26 -0800788 if (mKeyguardDelegate.isShowing()) {
Winson Chung1cea2f32012-10-08 20:42:01 -0700789 // Double the time it takes to take a screenshot from the keyguard
790 return (long) (KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER *
Justin Kohfeabd2c2014-05-02 10:02:44 -0700791 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Winson Chung1cea2f32012-10-08 20:42:01 -0700792 }
Justin Kohfeabd2c2014-05-02 10:02:44 -0700793 return ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout();
Winson Chung1cea2f32012-10-08 20:42:01 -0700794 }
795
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700796 private void cancelPendingScreenshotChordAction() {
Jeff Sharkey2991fa32012-12-05 18:06:43 -0800797 mHandler.removeCallbacks(mScreenshotRunnable);
Jeff Brown4d396052010-10-29 21:50:21 -0700798 }
799
Jeff Brown6d8fd272014-05-20 21:24:38 -0700800 private void powerShortPress(long eventTime) {
801 if (mShortPressOnPowerBehavior < 0) {
802 mShortPressOnPowerBehavior = mContext.getResources().getInteger(
803 com.android.internal.R.integer.config_shortPressOnPowerBehavior);
804 }
805
806 switch (mShortPressOnPowerBehavior) {
807 case SHORT_PRESS_POWER_NOTHING:
808 break;
809 case SHORT_PRESS_POWER_GO_TO_SLEEP:
810 mPowerManager.goToSleep(eventTime,
811 PowerManager.GO_TO_SLEEP_REASON_USER, 0);
812 break;
813 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP:
814 mPowerManager.goToSleep(eventTime,
815 PowerManager.GO_TO_SLEEP_REASON_USER,
816 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
817 break;
818 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME:
819 mPowerManager.goToSleep(eventTime,
820 PowerManager.GO_TO_SLEEP_REASON_USER,
821 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
822 launchHomeFromHotKey();
823 break;
824 }
825 }
826
Jeff Brown4d396052010-10-29 21:50:21 -0700827 private final Runnable mPowerLongPress = new Runnable() {
Craig Mautnerf1b67412012-09-19 13:18:29 -0700828 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800829 public void run() {
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700830 // The context isn't read
831 if (mLongPressOnPowerBehavior < 0) {
Jeff Brown850c5b72012-10-01 15:17:22 -0700832 mLongPressOnPowerBehavior = mContext.getResources().getInteger(
833 com.android.internal.R.integer.config_longPressOnPowerBehavior);
Joe Onoratod208e702010-10-08 16:22:43 -0400834 }
Jeff Brown850c5b72012-10-01 15:17:22 -0700835 int resolvedBehavior = mLongPressOnPowerBehavior;
836 if (FactoryTest.isLongPressOnPowerOffEnabled()) {
837 resolvedBehavior = LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM;
838 }
839
840 switch (resolvedBehavior) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700841 case LONG_PRESS_POWER_NOTHING:
842 break;
843 case LONG_PRESS_POWER_GLOBAL_ACTIONS:
844 mPowerKeyHandled = true;
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -0700845 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
846 performAuditoryFeedbackForAccessibilityIfNeed();
847 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700848 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
849 showGlobalActionsDialog();
850 break;
851 case LONG_PRESS_POWER_SHUT_OFF:
Jeff Brown9a538ee2012-08-20 14:56:57 -0700852 case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM:
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700853 mPowerKeyHandled = true;
854 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
855 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
Jeff Brown850c5b72012-10-01 15:17:22 -0700856 mWindowManagerFuncs.shutdown(resolvedBehavior == LONG_PRESS_POWER_SHUT_OFF);
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700857 break;
858 }
859 }
860 };
861
Jeff Sharkey2991fa32012-12-05 18:06:43 -0800862 private final Runnable mScreenshotRunnable = new Runnable() {
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800863 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700864 public void run() {
865 takeScreenshot();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800866 }
867 };
868
869 void showGlobalActionsDialog() {
870 if (mGlobalActions == null) {
Jeff Brown7304c342012-05-11 18:42:42 -0700871 mGlobalActions = new GlobalActions(mContext, mWindowManagerFuncs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800872 }
Mike Lockwood3a74bd32011-08-12 13:55:22 -0700873 final boolean keyguardShowing = keyguardIsShowingTq();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800874 mGlobalActions.showDialog(keyguardShowing, isDeviceProvisioned());
875 if (keyguardShowing) {
876 // since it took two seconds of long press to bring this up,
877 // poke the wake lock so they have some time to see the dialog.
Jim Miller25190572013-02-28 17:36:24 -0800878 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800879 }
880 }
881
882 boolean isDeviceProvisioned() {
Jeff Brownbf6f6f92012-09-25 15:03:20 -0700883 return Settings.Global.getInt(
884 mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800885 }
886
Maurice Lam99c6e072014-04-28 18:24:28 -0700887 boolean isUserSetupComplete() {
888 return Settings.Secure.getIntForUser(mContext.getContentResolver(),
889 Settings.Secure.USER_SETUP_COMPLETE, 0, UserHandle.USER_CURRENT) != 0;
890 }
891
Patrick Dubroyece94522011-02-23 18:35:01 -0800892 private void handleLongPressOnHome() {
Joe Onorato46b0d682010-11-22 17:37:27 -0800893 if (mLongPressOnHomeBehavior != LONG_PRESS_HOME_NOTHING) {
Jeff Browncaca8812013-05-09 13:34:33 -0700894 mHomeConsumed = true;
Joe Onorato46b0d682010-11-22 17:37:27 -0800895 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
Patrick Dubroyece94522011-02-23 18:35:01 -0800896
Jeff Browncaca8812013-05-09 13:34:33 -0700897 if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI) {
898 toggleRecentApps();
899 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_ASSIST) {
900 launchAssistAction();
Jim Millere6ad1a82010-08-20 19:25:39 -0700901 }
902 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800903 }
Patrick Dubroyece94522011-02-23 18:35:01 -0800904
Jeff Browncaca8812013-05-09 13:34:33 -0700905 private void handleDoubleTapOnHome() {
906 if (mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
907 mHomeConsumed = true;
908 toggleRecentApps();
909 }
910 }
911
912 private final Runnable mHomeDoubleTapTimeoutRunnable = new Runnable() {
913 @Override
914 public void run() {
915 if (mHomeDoubleTapPending) {
916 mHomeDoubleTapPending = false;
917 launchHomeFromHotKey();
918 }
919 }
920 };
921
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800922 /** {@inheritDoc} */
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800923 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800924 public void init(Context context, IWindowManager windowManager,
Jeff Brown96307042012-07-27 15:51:34 -0700925 WindowManagerFuncs windowManagerFuncs) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800926 mContext = context;
927 mWindowManager = windowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700928 mWindowManagerFuncs = windowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -0700929 mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class);
930
Jeff Brown70825162012-03-28 17:27:48 -0700931 mHandler = new PolicyHandler();
Jeff Browna20dda42014-05-27 20:57:24 -0700932 mWakeGestureListener = new MyWakeGestureListener(mContext, mHandler);
Craig Mautnereee29c42013-01-17 14:44:34 -0800933 mOrientationListener = new MyOrientationListener(mContext, mHandler);
Jeff Brownc0347aa2011-09-23 17:26:09 -0700934 try {
935 mOrientationListener.setCurrentRotation(windowManager.getRotation());
936 } catch (RemoteException ex) { }
Christopher Tate5e08af02012-09-21 17:17:22 -0700937 mSettingsObserver = new SettingsObserver(mHandler);
938 mSettingsObserver.observe();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800939 mShortcutManager = new ShortcutManager(context, mHandler);
940 mShortcutManager.observe();
Daniel Sandler6396c722013-04-16 20:19:09 -0400941 mUiMode = context.getResources().getInteger(
942 com.android.internal.R.integer.config_defaultUiModeType);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800943 mHomeIntent = new Intent(Intent.ACTION_MAIN, null);
944 mHomeIntent.addCategory(Intent.CATEGORY_HOME);
945 mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
946 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700947 mCarDockIntent = new Intent(Intent.ACTION_MAIN, null);
948 mCarDockIntent.addCategory(Intent.CATEGORY_CAR_DOCK);
949 mCarDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
950 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
951 mDeskDockIntent = new Intent(Intent.ACTION_MAIN, null);
952 mDeskDockIntent.addCategory(Intent.CATEGORY_DESK_DOCK);
953 mDeskDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
954 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Jim Millere6ad1a82010-08-20 19:25:39 -0700955
Jeff Brown96307042012-07-27 15:51:34 -0700956 mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
957 mBroadcastWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800958 "PhoneWindowManager.mBroadcastWakeLock");
959 mEnableShiftMenuBugReports = "1".equals(SystemProperties.get("ro.debuggable"));
Jeff Brownbcdfc622014-03-06 19:13:04 -0800960 mSupportAutoRotation = mContext.getResources().getBoolean(
961 com.android.internal.R.bool.config_supportAutoRotation);
Dianne Hackborn2862fff2009-09-15 22:56:29 -0700962 mLidOpenRotation = readRotation(
Mike Lockwood2d1efbd2009-09-16 12:15:53 -0400963 com.android.internal.R.integer.config_lidOpenRotation);
964 mCarDockRotation = readRotation(
965 com.android.internal.R.integer.config_carDockRotation);
966 mDeskDockRotation = readRotation(
967 com.android.internal.R.integer.config_deskDockRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -0700968 mUndockedHdmiRotation = readRotation(
969 com.android.internal.R.integer.config_undockedHdmiRotation);
Mike Lockwoode9867d22009-09-20 01:59:02 -0400970 mCarDockEnablesAccelerometer = mContext.getResources().getBoolean(
971 com.android.internal.R.bool.config_carDockEnablesAccelerometer);
972 mDeskDockEnablesAccelerometer = mContext.getResources().getBoolean(
973 com.android.internal.R.bool.config_deskDockEnablesAccelerometer);
Dianne Hackborn2862fff2009-09-15 22:56:29 -0700974 mLidKeyboardAccessibility = mContext.getResources().getInteger(
975 com.android.internal.R.integer.config_lidKeyboardAccessibility);
976 mLidNavigationAccessibility = mContext.getResources().getInteger(
977 com.android.internal.R.integer.config_lidNavigationAccessibility);
Jeff Brownc458ce92012-04-30 14:58:40 -0700978 mLidControlsSleep = mContext.getResources().getBoolean(
979 com.android.internal.R.bool.config_lidControlsSleep);
Daniel Sandlerdd73ee42013-10-11 22:19:59 -0400980 mTranslucentDecorEnabled = mContext.getResources().getBoolean(
981 com.android.internal.R.bool.config_enableTranslucentDecor);
Jeff Brownf71343d2013-05-31 17:59:11 -0700982 readConfigurationDependentBehaviors();
Jeff Browncaca8812013-05-09 13:34:33 -0700983
Svetoslav8e3feb12014-02-24 13:46:47 -0800984 mAccessibilityManager = (AccessibilityManager) context.getSystemService(
985 Context.ACCESSIBILITY_SERVICE);
986
Mike Lockwood1753f7f2009-08-24 14:49:07 -0700987 // register for dock events
Dianne Hackborn78968392010-03-04 20:47:56 -0800988 IntentFilter filter = new IntentFilter();
989 filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE);
990 filter.addAction(UiModeManager.ACTION_EXIT_CAR_MODE);
991 filter.addAction(UiModeManager.ACTION_ENTER_DESK_MODE);
992 filter.addAction(UiModeManager.ACTION_EXIT_DESK_MODE);
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700993 filter.addAction(Intent.ACTION_DOCK_EVENT);
994 Intent intent = context.registerReceiver(mDockReceiver, filter);
995 if (intent != null) {
996 // Retrieve current sticky dock event broadcast.
997 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
998 Intent.EXTRA_DOCK_STATE_UNDOCKED);
999 }
Daniel Sandler7e37df52011-11-16 22:08:23 -08001000
Jeff Brown6aaf2952012-10-05 16:01:08 -07001001 // register for dream-related broadcasts
1002 filter = new IntentFilter();
1003 filter.addAction(Intent.ACTION_DREAMING_STARTED);
1004 filter.addAction(Intent.ACTION_DREAMING_STOPPED);
1005 context.registerReceiver(mDreamReceiver, filter);
1006
Christopher Tate5e08af02012-09-21 17:17:22 -07001007 // register for multiuser-relevant broadcasts
1008 filter = new IntentFilter(Intent.ACTION_USER_SWITCHED);
1009 context.registerReceiver(mMultiuserReceiver, filter);
1010
John Spurlock57306e62013-04-22 09:48:49 -04001011 // monitor for system gestures
Craig Mautner037aa8d2013-06-07 10:35:44 -07001012 mSystemGestures = new SystemGesturesPointerEventListener(context,
1013 new SystemGesturesPointerEventListener.Callbacks() {
John Spurlock57306e62013-04-22 09:48:49 -04001014 @Override
1015 public void onSwipeFromTop() {
John Spurlock04db1762013-05-13 12:46:41 -04001016 if (mStatusBar != null) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001017 requestTransientBars(mStatusBar);
John Spurlock04db1762013-05-13 12:46:41 -04001018 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04001019 }
1020 @Override
1021 public void onSwipeFromBottom() {
John Spurlock04db1762013-05-13 12:46:41 -04001022 if (mNavigationBar != null && mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001023 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001024 }
1025 }
1026 @Override
1027 public void onSwipeFromRight() {
John Spurlock04db1762013-05-13 12:46:41 -04001028 if (mNavigationBar != null && !mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001029 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001030 }
1031 }
1032 @Override
1033 public void onDebug() {
John Spurlockd67ec252013-09-05 11:31:54 -04001034 // no-op
John Spurlockad3e6cb2013-04-30 08:47:43 -04001035 }
1036 });
John Spurlockf1a36642013-10-12 17:50:42 -04001037 mImmersiveModeConfirmation = new ImmersiveModeConfirmation(mContext);
Craig Mautner037aa8d2013-06-07 10:35:44 -07001038 mWindowManagerFuncs.registerPointerEventListener(mSystemGestures);
John Spurlock32beb2c2013-03-11 10:16:47 -04001039
Jeff Brownc2346132012-04-13 01:55:38 -07001040 mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001041 mLongPressVibePattern = getLongIntArray(mContext.getResources(),
1042 com.android.internal.R.array.config_longPressVibePattern);
1043 mVirtualKeyVibePattern = getLongIntArray(mContext.getResources(),
1044 com.android.internal.R.array.config_virtualKeyVibePattern);
Amith Yamasanic33cb712010-02-10 15:21:49 -08001045 mKeyboardTapVibePattern = getLongIntArray(mContext.getResources(),
1046 com.android.internal.R.array.config_keyboardTapVibePattern);
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07001047 mClockTickVibePattern = getLongIntArray(mContext.getResources(),
1048 com.android.internal.R.array.config_clockTickVibePattern);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001049 mSafeModeDisabledVibePattern = getLongIntArray(mContext.getResources(),
1050 com.android.internal.R.array.config_safeModeDisabledVibePattern);
1051 mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(),
1052 com.android.internal.R.array.config_safeModeEnabledVibePattern);
Daniel Sandler40427442010-07-16 11:44:52 -04001053
Christopher Tatee90585f2012-03-05 18:56:25 -08001054 mScreenshotChordEnabled = mContext.getResources().getBoolean(
1055 com.android.internal.R.bool.config_enableScreenshotChord);
1056
Justin Kohd378ad72013-04-01 12:18:26 -07001057 mGlobalKeyManager = new GlobalKeyManager(mContext);
1058
Joe Onoratoea495d42011-04-06 11:41:11 -07001059 // Controls rotation and the like.
1060 initializeHdmiState();
Dianne Hackborn40011092011-09-22 13:37:48 -07001061
1062 // Match current screen state.
Jeff Brown26c6a502014-04-11 02:15:54 -07001063 if (mPowerManager.isInteractive()) {
Jeff Brown140ffc72014-05-01 15:18:00 -07001064 wakingUp(null);
Dianne Hackborn40011092011-09-22 13:37:48 -07001065 } else {
Jeff Brown140ffc72014-05-01 15:18:00 -07001066 goingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
Dianne Hackborn40011092011-09-22 13:37:48 -07001067 }
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001068 }
1069
Jeff Brownf71343d2013-05-31 17:59:11 -07001070 /**
1071 * Read values from config.xml that may be overridden depending on
1072 * the configuration of the device.
1073 * eg. Disable long press on home goes to recents on sw600dp.
1074 */
1075 private void readConfigurationDependentBehaviors() {
1076 mLongPressOnHomeBehavior = mContext.getResources().getInteger(
1077 com.android.internal.R.integer.config_longPressOnHomeBehavior);
1078 if (mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING ||
1079 mLongPressOnHomeBehavior > LONG_PRESS_HOME_ASSIST) {
1080 mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1081 }
1082
1083 mDoubleTapOnHomeBehavior = mContext.getResources().getInteger(
1084 com.android.internal.R.integer.config_doubleTapOnHomeBehavior);
1085 if (mDoubleTapOnHomeBehavior < DOUBLE_TAP_HOME_NOTHING ||
1086 mDoubleTapOnHomeBehavior > DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1087 mDoubleTapOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1088 }
1089 }
1090
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001091 @Override
Dianne Hackborndde331c2012-08-03 14:01:57 -07001092 public void setInitialDisplaySize(Display display, int width, int height, int density) {
Jeff Brownef981a42013-08-07 14:13:37 -07001093 // This method might be called before the policy has been fully initialized
1094 // or for other displays we don't care about.
1095 if (mContext == null || display.getDisplayId() != Display.DEFAULT_DISPLAY) {
1096 return;
Dianne Hackbornc652de82013-02-15 16:32:56 -08001097 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001098 mDisplay = display;
1099
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001100 final Resources res = mContext.getResources();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001101 int shortSize, longSize;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001102 if (width > height) {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001103 shortSize = height;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001104 longSize = width;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001105 mLandscapeRotation = Surface.ROTATION_0;
1106 mSeascapeRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001107 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001108 mPortraitRotation = Surface.ROTATION_90;
1109 mUpsideDownRotation = Surface.ROTATION_270;
1110 } else {
1111 mPortraitRotation = Surface.ROTATION_270;
1112 mUpsideDownRotation = Surface.ROTATION_90;
1113 }
1114 } else {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001115 shortSize = width;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001116 longSize = height;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001117 mPortraitRotation = Surface.ROTATION_0;
1118 mUpsideDownRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001119 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001120 mLandscapeRotation = Surface.ROTATION_270;
1121 mSeascapeRotation = Surface.ROTATION_90;
1122 } else {
1123 mLandscapeRotation = Surface.ROTATION_90;
1124 mSeascapeRotation = Surface.ROTATION_270;
1125 }
1126 }
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001127
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001128 mStatusBarHeight =
1129 res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001130
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001131 // Height of the navigation bar when presented horizontally at bottom
1132 mNavigationBarHeightForRotation[mPortraitRotation] =
1133 mNavigationBarHeightForRotation[mUpsideDownRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001134 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_height);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001135 mNavigationBarHeightForRotation[mLandscapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001136 mNavigationBarHeightForRotation[mSeascapeRotation] = res.getDimensionPixelSize(
1137 com.android.internal.R.dimen.navigation_bar_height_landscape);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001138
1139 // Width of the navigation bar when presented vertically along one side
1140 mNavigationBarWidthForRotation[mPortraitRotation] =
1141 mNavigationBarWidthForRotation[mUpsideDownRotation] =
1142 mNavigationBarWidthForRotation[mLandscapeRotation] =
1143 mNavigationBarWidthForRotation[mSeascapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001144 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_width);
Daniel Sandler4a066c52012-04-20 14:49:13 -04001145
1146 // SystemUI (status bar) layout policy
Dianne Hackborndde331c2012-08-03 14:01:57 -07001147 int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / density;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001148 int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / density;
Daniel Sandler4a066c52012-04-20 14:49:13 -04001149
Craig Mautnerd4ec33242013-07-22 10:37:43 -07001150 // Allow the navigation bar to move on small devices (phones).
1151 mNavigationBarCanMove = shortSizeDp < 600;
Daniel Sandler36412a72011-08-04 09:35:13 -04001152
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001153 mHasNavigationBar = res.getBoolean(com.android.internal.R.bool.config_showNavigationBar);
John Spurlock80f00c12013-06-13 11:10:51 -04001154 // Allow a system property to override this. Used by the emulator.
1155 // See also hasNavigationBar().
1156 String navBarOverride = SystemProperties.get("qemu.hw.mainkeys");
1157 if ("1".equals(navBarOverride)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001158 mHasNavigationBar = false;
John Spurlock80f00c12013-06-13 11:10:51 -04001159 } else if ("0".equals(navBarOverride)) {
1160 mHasNavigationBar = true;
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04001161 }
1162
Jeff Brown27f1d672012-10-17 18:32:34 -07001163 // For demo purposes, allow the rotation of the HDMI display to be controlled.
1164 // By default, HDMI locks rotation to landscape.
Erik Gilling9a41ef82011-09-26 19:21:03 -07001165 if ("portrait".equals(SystemProperties.get("persist.demo.hdmirotation"))) {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001166 mDemoHdmiRotation = mPortraitRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001167 } else {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001168 mDemoHdmiRotation = mLandscapeRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001169 }
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001170 mDemoHdmiRotationLock = SystemProperties.getBoolean("persist.demo.hdmirotationlock", false);
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001171
1172 // Only force the default orientation if the screen is xlarge, at least 960dp x 720dp, per
1173 // http://developer.android.com/guide/practices/screens_support.html#range
1174 mForceDefaultOrientation = longSizeDp >= 960 && shortSizeDp >= 720 &&
1175 res.getBoolean(com.android.internal.R.bool.config_forceDefaultOrientation) &&
1176 // For debug purposes the next line turns this feature off with:
1177 // $ adb shell setprop config.override_forced_orient true
1178 // $ adb shell wm size reset
1179 !"true".equals(SystemProperties.get("config.override_forced_orient"));
1180 }
1181
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001182 /**
1183 * @return whether the navigation bar can be hidden, e.g. the device has a
1184 * navigation bar and touch exploration is not enabled
1185 */
1186 private boolean canHideNavigationBar() {
Svetoslav8e3feb12014-02-24 13:46:47 -08001187 return mHasNavigationBar
1188 && !mAccessibilityManager.isTouchExplorationEnabled();
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001189 }
1190
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001191 @Override
1192 public boolean isDefaultOrientationForced() {
1193 return mForceDefaultOrientation;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001194 }
1195
Dianne Hackbornc652de82013-02-15 16:32:56 -08001196 @Override
1197 public void setDisplayOverscan(Display display, int left, int top, int right, int bottom) {
1198 if (display.getDisplayId() == Display.DEFAULT_DISPLAY) {
1199 mOverscanLeft = left;
1200 mOverscanTop = top;
1201 mOverscanRight = right;
1202 mOverscanBottom = bottom;
1203 }
1204 }
1205
Dianne Hackbornc777e072010-02-12 13:07:59 -08001206 public void updateSettings() {
1207 ContentResolver resolver = mContext.getContentResolver();
1208 boolean updateRotation = false;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001209 synchronized (mLock) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001210 mEndcallBehavior = Settings.System.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001211 Settings.System.END_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001212 Settings.System.END_BUTTON_BEHAVIOR_DEFAULT,
1213 UserHandle.USER_CURRENT);
1214 mIncallPowerBehavior = Settings.Secure.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001215 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001216 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT,
1217 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001218
Jeff Browna20dda42014-05-27 20:57:24 -07001219 // Configure wake gesture.
1220 boolean wakeGestureEnabledSetting = Settings.Secure.getIntForUser(resolver,
1221 Settings.Secure.WAKE_GESTURE_ENABLED, 0,
1222 UserHandle.USER_CURRENT) != 0;
1223 if (mWakeGestureEnabledSetting != wakeGestureEnabledSetting) {
1224 mWakeGestureEnabledSetting = wakeGestureEnabledSetting;
1225 updateWakeGestureListenerLp();
1226 }
1227
Jeff Brown207673cd2012-06-05 17:47:11 -07001228 // Configure rotation lock.
Christopher Tate5e08af02012-09-21 17:17:22 -07001229 int userRotation = Settings.System.getIntForUser(resolver,
1230 Settings.System.USER_ROTATION, Surface.ROTATION_0,
1231 UserHandle.USER_CURRENT);
Jeff Brown207673cd2012-06-05 17:47:11 -07001232 if (mUserRotation != userRotation) {
1233 mUserRotation = userRotation;
1234 updateRotation = true;
1235 }
Christopher Tate5e08af02012-09-21 17:17:22 -07001236 int userRotationMode = Settings.System.getIntForUser(resolver,
1237 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
Jeff Brown207673cd2012-06-05 17:47:11 -07001238 WindowManagerPolicy.USER_ROTATION_FREE :
1239 WindowManagerPolicy.USER_ROTATION_LOCKED;
1240 if (mUserRotationMode != userRotationMode) {
1241 mUserRotationMode = userRotationMode;
1242 updateRotation = true;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001243 updateOrientationListenerLp();
1244 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001245
Dianne Hackbornc777e072010-02-12 13:07:59 -08001246 if (mSystemReady) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001247 int pointerLocation = Settings.System.getIntForUser(resolver,
1248 Settings.System.POINTER_LOCATION, 0, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001249 if (mPointerLocationMode != pointerLocation) {
1250 mPointerLocationMode = pointerLocation;
Jeff Brown70825162012-03-28 17:27:48 -07001251 mHandler.sendEmptyMessage(pointerLocation != 0 ?
1252 MSG_ENABLE_POINTER_LOCATION : MSG_DISABLE_POINTER_LOCATION);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001253 }
1254 }
1255 // use screen off timeout setting as the timeout for the lockscreen
Christopher Tate5e08af02012-09-21 17:17:22 -07001256 mLockScreenTimeout = Settings.System.getIntForUser(resolver,
1257 Settings.System.SCREEN_OFF_TIMEOUT, 0, UserHandle.USER_CURRENT);
1258 String imId = Settings.Secure.getStringForUser(resolver,
1259 Settings.Secure.DEFAULT_INPUT_METHOD, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001260 boolean hasSoftInput = imId != null && imId.length() > 0;
1261 if (mHasSoftInput != hasSoftInput) {
1262 mHasSoftInput = hasSoftInput;
1263 updateRotation = true;
1264 }
John Spurlockf1a36642013-10-12 17:50:42 -04001265 if (mImmersiveModeConfirmation != null) {
John Spurlock4355a532014-02-19 09:49:25 -05001266 mImmersiveModeConfirmation.loadSetting(mCurrentUserId);
John Spurlockd67ec252013-09-05 11:31:54 -04001267 }
John Spurlockc6d1c602014-01-17 15:22:06 -05001268 PolicyControl.reloadFromSetting(mContext);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001269 }
1270 if (updateRotation) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07001271 updateRotation(true);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001272 }
Jeff Brown70825162012-03-28 17:27:48 -07001273 }
1274
Jeff Browna20dda42014-05-27 20:57:24 -07001275 private void updateWakeGestureListenerLp() {
1276 if (shouldEnableWakeGestureLp()) {
1277 mWakeGestureListener.requestWakeUpTrigger();
1278 } else {
1279 mWakeGestureListener.cancelWakeUpTrigger();
1280 }
1281 }
1282
1283 private boolean shouldEnableWakeGestureLp() {
1284 return mWakeGestureEnabledSetting && !mScreenOnEarly
1285 && (!mLidControlsSleep || mLidState != LID_CLOSED)
1286 && mWakeGestureListener.isSupported();
1287 }
1288
Jeff Brown70825162012-03-28 17:27:48 -07001289 private void enablePointerLocation() {
1290 if (mPointerLocationView == null) {
1291 mPointerLocationView = new PointerLocationView(mContext);
1292 mPointerLocationView.setPrintCoords(false);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001293 WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
1294 WindowManager.LayoutParams.MATCH_PARENT,
1295 WindowManager.LayoutParams.MATCH_PARENT);
Jeff Brown3b2b3542010-10-15 00:54:27 -07001296 lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001297 lp.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN
1298 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
1299 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1300 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
Jeff Brown90fc9052012-10-01 14:44:24 -07001301 if (ActivityManager.isHighEndGfx()) {
1302 lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
1303 lp.privateFlags |=
1304 WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED;
1305 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001306 lp.format = PixelFormat.TRANSLUCENT;
1307 lp.setTitle("PointerLocation");
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001308 WindowManager wm = (WindowManager)
Dianne Hackbornc777e072010-02-12 13:07:59 -08001309 mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Browncc4f7db2011-08-30 20:34:48 -07001310 lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL;
Jeff Brown70825162012-03-28 17:27:48 -07001311 wm.addView(mPointerLocationView, lp);
Michael Wrightc9c487e2013-11-07 18:55:09 -08001312 mWindowManagerFuncs.registerPointerEventListener(mPointerLocationView);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001313 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001314 }
Jeff Brown70825162012-03-28 17:27:48 -07001315
1316 private void disablePointerLocation() {
Jeff Brown70825162012-03-28 17:27:48 -07001317 if (mPointerLocationView != null) {
Michael Wrightc9c487e2013-11-07 18:55:09 -08001318 mWindowManagerFuncs.unregisterPointerEventListener(mPointerLocationView);
1319 WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Brown70825162012-03-28 17:27:48 -07001320 wm.removeView(mPointerLocationView);
1321 mPointerLocationView = null;
1322 }
1323 }
1324
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001325 private int readRotation(int resID) {
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001326 try {
1327 int rotation = mContext.getResources().getInteger(resID);
1328 switch (rotation) {
1329 case 0:
1330 return Surface.ROTATION_0;
1331 case 90:
1332 return Surface.ROTATION_90;
1333 case 180:
1334 return Surface.ROTATION_180;
1335 case 270:
1336 return Surface.ROTATION_270;
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001337 }
1338 } catch (Resources.NotFoundException e) {
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001339 // fall through
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001340 }
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001341 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001342 }
1343
1344 /** {@inheritDoc} */
Craig Mautner88400d32012-09-30 12:35:45 -07001345 @Override
Dianne Hackbornc2293022013-02-06 23:14:49 -08001346 public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001347 int type = attrs.type;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001348
1349 outAppOp[0] = AppOpsManager.OP_NONE;
1350
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001351 if (type < WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW
1352 || type > WindowManager.LayoutParams.LAST_SYSTEM_WINDOW) {
Jeff Brown98365d72012-08-19 20:30:52 -07001353 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001354 }
1355 String permission = null;
1356 switch (type) {
1357 case TYPE_TOAST:
1358 // XXX right now the app process has complete control over
1359 // this... should introduce a token to let the system
1360 // monitor/control what they are doing.
1361 break;
Daniel Sandler7d276c32012-01-30 14:33:52 -05001362 case TYPE_DREAM:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001363 case TYPE_INPUT_METHOD:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001364 case TYPE_WALLPAPER:
keunyounga446bf02013-06-21 19:07:57 -07001365 case TYPE_PRIVATE_PRESENTATION:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001366 case TYPE_VOICE_INTERACTION:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001367 // The window manager will check these.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001368 break;
1369 case TYPE_PHONE:
1370 case TYPE_PRIORITY_PHONE:
1371 case TYPE_SYSTEM_ALERT:
1372 case TYPE_SYSTEM_ERROR:
1373 case TYPE_SYSTEM_OVERLAY:
1374 permission = android.Manifest.permission.SYSTEM_ALERT_WINDOW;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001375 outAppOp[0] = AppOpsManager.OP_SYSTEM_ALERT_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001376 break;
1377 default:
1378 permission = android.Manifest.permission.INTERNAL_SYSTEM_WINDOW;
1379 }
1380 if (permission != null) {
1381 if (mContext.checkCallingOrSelfPermission(permission)
1382 != PackageManager.PERMISSION_GRANTED) {
Jeff Brown98365d72012-08-19 20:30:52 -07001383 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001384 }
1385 }
Jeff Brown98365d72012-08-19 20:30:52 -07001386 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001387 }
Craig Mautner88400d32012-09-30 12:35:45 -07001388
1389 @Override
1390 public boolean checkShowToOwnerOnly(WindowManager.LayoutParams attrs) {
1391
1392 // If this switch statement is modified, modify the comment in the declarations of
1393 // the type in {@link WindowManager.LayoutParams} as well.
1394 switch (attrs.type) {
1395 default:
1396 // These are the windows that by default are shown only to the user that created
1397 // them. If this needs to be overridden, set
1398 // {@link WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS} in
1399 // {@link WindowManager.LayoutParams}. Note that permission
1400 // {@link android.Manifest.permission.INTERNAL_SYSTEM_WINDOW} is required as well.
1401 if ((attrs.privateFlags & PRIVATE_FLAG_SHOW_FOR_ALL_USERS) == 0) {
1402 return true;
1403 }
1404 break;
1405
1406 // These are the windows that by default are shown to all users. However, to
1407 // protect against spoofing, check permissions below.
1408 case TYPE_APPLICATION_STARTING:
1409 case TYPE_BOOT_PROGRESS:
1410 case TYPE_DISPLAY_OVERLAY:
1411 case TYPE_HIDDEN_NAV_CONSUMER:
Jim Miller5ecd8112013-01-09 18:50:26 -08001412 case TYPE_KEYGUARD_SCRIM:
Craig Mautner88400d32012-09-30 12:35:45 -07001413 case TYPE_KEYGUARD_DIALOG:
1414 case TYPE_MAGNIFICATION_OVERLAY:
1415 case TYPE_NAVIGATION_BAR:
1416 case TYPE_NAVIGATION_BAR_PANEL:
1417 case TYPE_PHONE:
1418 case TYPE_POINTER:
1419 case TYPE_PRIORITY_PHONE:
1420 case TYPE_RECENTS_OVERLAY:
1421 case TYPE_SEARCH_BAR:
1422 case TYPE_STATUS_BAR:
1423 case TYPE_STATUS_BAR_PANEL:
1424 case TYPE_STATUS_BAR_SUB_PANEL:
1425 case TYPE_SYSTEM_DIALOG:
1426 case TYPE_UNIVERSE_BACKGROUND:
1427 case TYPE_VOLUME_OVERLAY:
keunyounga446bf02013-06-21 19:07:57 -07001428 case TYPE_PRIVATE_PRESENTATION:
Craig Mautner88400d32012-09-30 12:35:45 -07001429 break;
1430 }
1431
1432 // Check if third party app has set window to system window type.
1433 return mContext.checkCallingOrSelfPermission(
1434 android.Manifest.permission.INTERNAL_SYSTEM_WINDOW)
1435 != PackageManager.PERMISSION_GRANTED;
1436 }
1437
Craig Mautner967212c2013-04-13 21:10:58 -07001438 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001439 public void adjustWindowParamsLw(WindowManager.LayoutParams attrs) {
1440 switch (attrs.type) {
1441 case TYPE_SYSTEM_OVERLAY:
Jeff Brown3b2b3542010-10-15 00:54:27 -07001442 case TYPE_SECURE_SYSTEM_OVERLAY:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001443 // These types of windows can't receive input events.
1444 attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1445 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001446 attrs.flags &= ~WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001447 break;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001448 case TYPE_STATUS_BAR:
1449
1450 // If the Keyguard is in a hidden state (occluded by another window), we force to
1451 // remove the wallpaper and keyguard flag so that any change in-flight after setting
1452 // the keyguard as occluded wouldn't set these flags again.
1453 // See {@link #processKeyguardSetHiddenResultLw}.
1454 if (mKeyguardHidden) {
1455 attrs.flags &= ~WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
1456 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
1457 }
1458 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001459 }
Adrian Roos38502112014-04-09 21:04:11 +02001460
1461 if (attrs.type != TYPE_STATUS_BAR) {
1462 // The status bar is the only window allowed to exhibit keyguard behavior.
1463 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
1464 }
Adrian Roosea562512014-05-05 13:33:03 +02001465
1466 if (ActivityManager.isHighEndGfx()
1467 && (attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0) {
1468 attrs.subtreeSystemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_STABLE
1469 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
1470 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
1471 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001472 }
RoboErik8a2cfc32014-05-16 11:19:38 -07001473
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001474 void readLidState() {
Jeff Brown2e7760e2012-04-11 15:14:55 -07001475 mLidState = mWindowManagerFuncs.getLidState();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001476 }
RoboErik8a2cfc32014-05-16 11:19:38 -07001477
Jeff Browndaa37532012-05-01 15:54:03 -07001478 private boolean isHidden(int accessibilityMode) {
1479 switch (accessibilityMode) {
1480 case 1:
1481 return mLidState == LID_CLOSED;
1482 case 2:
1483 return mLidState == LID_OPEN;
1484 default:
1485 return false;
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001486 }
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001487 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001488
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001489 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07001490 @Override
Jeff Browndaa37532012-05-01 15:54:03 -07001491 public void adjustConfigurationLw(Configuration config, int keyboardPresence,
1492 int navigationPresence) {
1493 mHaveBuiltInKeyboard = (keyboardPresence & PRESENCE_INTERNAL) != 0;
1494
Jeff Brownf71343d2013-05-31 17:59:11 -07001495 readConfigurationDependentBehaviors();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001496 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07001497 applyLidSwitchState();
Jeff Brownd04a88c2011-01-16 14:05:47 -08001498
Jeff Browndaa37532012-05-01 15:54:03 -07001499 if (config.keyboard == Configuration.KEYBOARD_NOKEYS
1500 || (keyboardPresence == PRESENCE_INTERNAL
1501 && isHidden(mLidKeyboardAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001502 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_YES;
Jeff Browndaa37532012-05-01 15:54:03 -07001503 if (!mHasSoftInput) {
1504 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_YES;
1505 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001506 }
1507
Jeff Browndaa37532012-05-01 15:54:03 -07001508 if (config.navigation == Configuration.NAVIGATION_NONAV
1509 || (navigationPresence == PRESENCE_INTERNAL
1510 && isHidden(mLidNavigationAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001511 config.navigationHidden = Configuration.NAVIGATIONHIDDEN_YES;
Jeff Brownd04a88c2011-01-16 14:05:47 -08001512 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001513 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001514
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001515 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07001516 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001517 public int windowTypeToLayerLw(int type) {
1518 if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001519 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001520 }
1521 switch (type) {
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001522 case TYPE_UNIVERSE_BACKGROUND:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001523 return 1;
keunyounga446bf02013-06-21 19:07:57 -07001524 case TYPE_PRIVATE_PRESENTATION:
1525 return 2;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001526 case TYPE_WALLPAPER:
1527 // wallpaper is at the bottom, though the window manager may move it.
1528 return 2;
1529 case TYPE_PHONE:
1530 return 3;
1531 case TYPE_SEARCH_BAR:
1532 return 4;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001533 case TYPE_VOICE_INTERACTION:
1534 // voice interaction layer is almost immediately above apps.
1535 return 5;
Craig Mautner88400d32012-09-30 12:35:45 -07001536 case TYPE_RECENTS_OVERLAY:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001537 case TYPE_SYSTEM_DIALOG:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001538 return 6;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001539 case TYPE_TOAST:
1540 // toasts and the plugged-in battery thing
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001541 return 7;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001542 case TYPE_PRIORITY_PHONE:
1543 // SIM errors and unlock. Not sure if this really should be in a high layer.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001544 return 8;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001545 case TYPE_DREAM:
1546 // used for Dreams (screensavers with TYPE_DREAM windows)
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001547 return 9;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001548 case TYPE_SYSTEM_ALERT:
1549 // like the ANR / app crashed dialogs
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001550 return 10;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001551 case TYPE_INPUT_METHOD:
1552 // on-screen keyboards and other such input method user interfaces go here.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001553 return 11;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001554 case TYPE_INPUT_METHOD_DIALOG:
1555 // on-screen keyboards and other such input method user interfaces go here.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001556 return 12;
Jim Miller5ecd8112013-01-09 18:50:26 -08001557 case TYPE_KEYGUARD_SCRIM:
1558 // the safety window that shows behind keyguard while keyguard is starting
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001559 return 13;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001560 case TYPE_STATUS_BAR_SUB_PANEL:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001561 return 14;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001562 case TYPE_STATUS_BAR:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001563 return 15;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001564 case TYPE_STATUS_BAR_PANEL:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001565 return 16;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001566 case TYPE_KEYGUARD_DIALOG:
1567 return 17;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001568 case TYPE_VOLUME_OVERLAY:
1569 // the on-screen volume indicator and controller shown when the user
1570 // changes the device volume
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001571 return 18;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001572 case TYPE_SYSTEM_OVERLAY:
1573 // the on-screen volume indicator and controller shown when the user
1574 // changes the device volume
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001575 return 19;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001576 case TYPE_NAVIGATION_BAR:
1577 // the navigation bar, if available, shows atop most things
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001578 return 20;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001579 case TYPE_NAVIGATION_BAR_PANEL:
1580 // some panels (e.g. search) need to show on top of the navigation bar
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001581 return 21;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001582 case TYPE_SYSTEM_ERROR:
1583 // system-level error dialogs
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001584 return 22;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001585 case TYPE_MAGNIFICATION_OVERLAY:
1586 // used to highlight the magnified portion of a display
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001587 return 23;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001588 case TYPE_DISPLAY_OVERLAY:
1589 // used to simulate secondary display devices
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001590 return 24;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001591 case TYPE_DRAG:
1592 // the drag layer: input for drag-and-drop is associated with this window,
1593 // which sits above all other focusable windows
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001594 return 25;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001595 case TYPE_SECURE_SYSTEM_OVERLAY:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001596 return 26;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001597 case TYPE_BOOT_PROGRESS:
1598 return 27;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001599 case TYPE_POINTER:
1600 // the (mouse) pointer layer
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001601 return 28;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001602 case TYPE_HIDDEN_NAV_CONSUMER:
1603 return 29;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001604 }
1605 Log.e(TAG, "Unknown window type: " + type);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001606 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001607 }
1608
1609 /** {@inheritDoc} */
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001610 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001611 public int subWindowTypeToLayerLw(int type) {
1612 switch (type) {
1613 case TYPE_APPLICATION_PANEL:
1614 case TYPE_APPLICATION_ATTACHED_DIALOG:
1615 return APPLICATION_PANEL_SUBLAYER;
1616 case TYPE_APPLICATION_MEDIA:
1617 return APPLICATION_MEDIA_SUBLAYER;
Dianne Hackborn5cb8d792009-05-21 17:34:15 -07001618 case TYPE_APPLICATION_MEDIA_OVERLAY:
1619 return APPLICATION_MEDIA_OVERLAY_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001620 case TYPE_APPLICATION_SUB_PANEL:
1621 return APPLICATION_SUB_PANEL_SUBLAYER;
1622 }
1623 Log.e(TAG, "Unknown sub-window type: " + type);
1624 return 0;
1625 }
1626
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001627 @Override
Dianne Hackbornabe0da02009-09-18 01:55:39 -07001628 public int getMaxWallpaperLayer() {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001629 return windowTypeToLayerLw(TYPE_STATUS_BAR);
Dianne Hackbornabe0da02009-09-18 01:55:39 -07001630 }
1631
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001632 @Override
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001633 public int getAboveUniverseLayer() {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001634 return windowTypeToLayerLw(TYPE_SYSTEM_ERROR);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001635 }
1636
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001637 public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07001638 if (mHasNavigationBar) {
1639 // For a basic navigation bar, when we are in landscape mode we place
1640 // the navigation bar to the side.
Daniel Sandler4a066c52012-04-20 14:49:13 -04001641 if (mNavigationBarCanMove && fullWidth > fullHeight) {
1642 return fullWidth - mNavigationBarWidthForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07001643 }
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001644 }
1645 return fullWidth;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001646 }
1647
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001648 public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07001649 if (mHasNavigationBar) {
1650 // For a basic navigation bar, when we are in portrait mode we place
1651 // the navigation bar to the bottom.
Daniel Sandler4a066c52012-04-20 14:49:13 -04001652 if (!mNavigationBarCanMove || fullWidth < fullHeight) {
1653 return fullHeight - mNavigationBarHeightForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07001654 }
1655 }
1656 return fullHeight;
Dianne Hackborn69cb8752011-05-19 18:13:32 -07001657 }
1658
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001659 public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation) {
1660 return getNonDecorDisplayWidth(fullWidth, fullHeight, rotation);
Dianne Hackborn69cb8752011-05-19 18:13:32 -07001661 }
1662
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001663 public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation) {
John Spurlock80f00c12013-06-13 11:10:51 -04001664 // There is a separate status bar at the top of the display. We don't count that as part
1665 // of the fixed decor, since it can hide; however, for purposes of configurations,
Dianne Hackborn077ee852012-04-09 16:27:07 -07001666 // we do want to exclude it since applications can't generally use that part
1667 // of the screen.
John Spurlock80f00c12013-06-13 11:10:51 -04001668 return getNonDecorDisplayHeight(fullWidth, fullHeight, rotation) - mStatusBarHeight;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001669 }
1670
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001671 @Override
Jorim Jaggi0d674622014-05-21 01:34:15 +02001672 public boolean doesForceHide(WindowManager.LayoutParams attrs) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001673 return (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07001674 }
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001675
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001676 @Override
Jorim Jaggi0d674622014-05-21 01:34:15 +02001677 public boolean isKeyguardHostWindow(WindowManager.LayoutParams attrs) {
1678 return attrs.type == TYPE_STATUS_BAR;
1679 }
1680
1681 @Override
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07001682 public boolean canBeForceHidden(WindowState win, WindowManager.LayoutParams attrs) {
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001683 switch (attrs.type) {
1684 case TYPE_STATUS_BAR:
1685 case TYPE_NAVIGATION_BAR:
1686 case TYPE_WALLPAPER:
1687 case TYPE_DREAM:
1688 case TYPE_UNIVERSE_BACKGROUND:
Jim Miller5ecd8112013-01-09 18:50:26 -08001689 case TYPE_KEYGUARD_SCRIM:
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001690 return false;
1691 default:
1692 return true;
1693 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07001694 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001695
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001696 /** {@inheritDoc} */
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001697 @Override
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07001698 public View addStartingWindow(IBinder appToken, String packageName, int theme,
1699 CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes,
Adam Powell04fe6eb2013-05-31 14:39:48 -07001700 int icon, int logo, int windowFlags) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001701 if (!SHOW_STARTING_ANIMATIONS) {
1702 return null;
1703 }
1704 if (packageName == null) {
1705 return null;
1706 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001707
Mathias Jeppssond1443e92012-08-24 15:25:32 +02001708 WindowManager wm = null;
1709 View view = null;
1710
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001711 try {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001712 Context context = mContext;
Craig Mautner6fbda632012-07-03 09:26:39 -07001713 if (DEBUG_STARTING_WINDOW) Slog.d(TAG, "addStartingWindow " + packageName
1714 + ": nonLocalizedLabel=" + nonLocalizedLabel + " theme="
1715 + Integer.toHexString(theme));
Dianne Hackborn247fe742011-01-08 17:25:57 -08001716 if (theme != context.getThemeResId() || labelRes != 0) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001717 try {
1718 context = context.createPackageContext(packageName, 0);
Dianne Hackborn247fe742011-01-08 17:25:57 -08001719 context.setTheme(theme);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001720 } catch (PackageManager.NameNotFoundException e) {
1721 // Ignore
1722 }
1723 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001724
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001725 Window win = PolicyManager.makeNewWindow(context);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001726 final TypedArray ta = win.getWindowStyle();
1727 if (ta.getBoolean(
1728 com.android.internal.R.styleable.Window_windowDisablePreview, false)
1729 || ta.getBoolean(
1730 com.android.internal.R.styleable.Window_windowShowWallpaper,false)) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001731 return null;
1732 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001733
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001734 Resources r = context.getResources();
1735 win.setTitle(r.getText(labelRes, nonLocalizedLabel));
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001736
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001737 win.setType(
1738 WindowManager.LayoutParams.TYPE_APPLICATION_STARTING);
1739 // Force the window flags: this is a fake window, so it is not really
1740 // touchable or focusable by the user. We also add in the ALT_FOCUSABLE_IM
1741 // flag because we do know that the next window will take input
1742 // focus, so we want to get the IME window up on top of us right away.
1743 win.setFlags(
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08001744 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001745 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
1746 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
1747 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08001748 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001749 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
1750 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
1751 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001752
Adam Powell04fe6eb2013-05-31 14:39:48 -07001753 win.setDefaultIcon(icon);
1754 win.setDefaultLogo(logo);
1755
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001756 win.setLayout(WindowManager.LayoutParams.MATCH_PARENT,
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07001757 WindowManager.LayoutParams.MATCH_PARENT);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001758
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001759 final WindowManager.LayoutParams params = win.getAttributes();
1760 params.token = appToken;
1761 params.packageName = packageName;
1762 params.windowAnimations = win.getWindowStyle().getResourceId(
1763 com.android.internal.R.styleable.Window_windowAnimationStyle, 0);
Dianne Hackborn5d927c22011-09-02 12:22:18 -07001764 params.privateFlags |=
1765 WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED;
Craig Mautner88400d32012-09-30 12:35:45 -07001766 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
Adam Lesinski95c42972013-10-02 10:13:27 -07001767
1768 if (!compatInfo.supportsScreen()) {
1769 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
1770 }
1771
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001772 params.setTitle("Starting " + packageName);
1773
Mathias Jeppssond1443e92012-08-24 15:25:32 +02001774 wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
1775 view = win.getDecorView();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001776
1777 if (win.isFloating()) {
1778 // Whoops, there is no way to display an animation/preview
1779 // of such a thing! After all that work... let's skip it.
1780 // (Note that we must do this here because it is in
1781 // getDecorView() where the theme is evaluated... maybe
1782 // we should peek the floating attribute from the theme
1783 // earlier.)
1784 return null;
1785 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001786
Craig Mautner6fbda632012-07-03 09:26:39 -07001787 if (DEBUG_STARTING_WINDOW) Slog.d(
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001788 TAG, "Adding starting window for " + packageName
1789 + " / " + appToken + ": "
1790 + (view.getParent() != null ? view : null));
1791
1792 wm.addView(view, params);
1793
1794 // Only return the view if it was successfully added to the
1795 // window manager... which we can tell by it having a parent.
1796 return view.getParent() != null ? view : null;
Jeff Brown98365d72012-08-19 20:30:52 -07001797 } catch (WindowManager.BadTokenException e) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001798 // ignore
Craig Mautner42bf39e2014-02-21 16:46:22 -08001799 Log.w(TAG, appToken + " already running, starting window not displayed. " +
1800 e.getMessage());
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001801 } catch (RuntimeException e) {
1802 // don't crash if something else bad happens, for example a
1803 // failure loading resources because we are loading from an app
1804 // on external storage that has been unmounted.
1805 Log.w(TAG, appToken + " failed creating starting window", e);
Mathias Jeppssond1443e92012-08-24 15:25:32 +02001806 } finally {
1807 if (view != null && view.getParent() == null) {
1808 Log.w(TAG, "view not successfully added to wm, removing view");
1809 wm.removeViewImmediate(view);
1810 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001811 }
1812
1813 return null;
1814 }
1815
1816 /** {@inheritDoc} */
1817 public void removeStartingWindow(IBinder appToken, View window) {
Craig Mautner6fbda632012-07-03 09:26:39 -07001818 if (DEBUG_STARTING_WINDOW) {
1819 RuntimeException e = new RuntimeException("here");
1820 e.fillInStackTrace();
1821 Log.v(TAG, "Removing starting window for " + appToken + ": " + window, e);
1822 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001823
1824 if (window != null) {
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001825 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001826 wm.removeView(window);
1827 }
1828 }
1829
1830 /**
1831 * Preflight adding a window to the system.
RoboErik8a2cfc32014-05-16 11:19:38 -07001832 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001833 * Currently enforces that three window types are singletons:
1834 * <ul>
1835 * <li>STATUS_BAR_TYPE</li>
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001836 * <li>KEYGUARD_TYPE</li>
1837 * </ul>
RoboErik8a2cfc32014-05-16 11:19:38 -07001838 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001839 * @param win The window to be added
1840 * @param attrs Information about the window to be added
RoboErik8a2cfc32014-05-16 11:19:38 -07001841 *
Jeff Brown98365d72012-08-19 20:30:52 -07001842 * @return If ok, WindowManagerImpl.ADD_OKAY. If too many singletons,
1843 * WindowManagerImpl.ADD_MULTIPLE_SINGLETON
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001844 */
1845 public int prepareAddWindowLw(WindowState win, WindowManager.LayoutParams attrs) {
1846 switch (attrs.type) {
1847 case TYPE_STATUS_BAR:
Joe Onorato8bc6c512010-06-04 16:21:12 -04001848 mContext.enforceCallingOrSelfPermission(
1849 android.Manifest.permission.STATUS_BAR_SERVICE,
1850 "PhoneWindowManager");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001851 if (mStatusBar != null) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001852 if (mStatusBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07001853 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001854 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001855 }
1856 mStatusBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04001857 mStatusBarController.setWindow(win);
John Spurlock8fdfe622014-05-21 17:10:10 -04001858 mKeyguardDelegate.hideScrim();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001859 break;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04001860 case TYPE_NAVIGATION_BAR:
1861 mContext.enforceCallingOrSelfPermission(
1862 android.Manifest.permission.STATUS_BAR_SERVICE,
1863 "PhoneWindowManager");
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001864 if (mNavigationBar != null) {
1865 if (mNavigationBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07001866 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001867 }
1868 }
Daniel Sandler8956dbb2011-04-22 07:55:02 -04001869 mNavigationBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04001870 mNavigationBarController.setWindow(win);
Craig Mautnereda67292013-04-28 13:50:14 -07001871 if (DEBUG_LAYOUT) Slog.i(TAG, "NAVIGATION BAR: " + mNavigationBar);
Daniel Sandler8956dbb2011-04-22 07:55:02 -04001872 break;
Jim Millere898ac52012-04-06 17:10:57 -07001873 case TYPE_NAVIGATION_BAR_PANEL:
1874 mContext.enforceCallingOrSelfPermission(
1875 android.Manifest.permission.STATUS_BAR_SERVICE,
1876 "PhoneWindowManager");
1877 break;
Dianne Hackborn08743722009-12-21 12:16:51 -08001878 case TYPE_STATUS_BAR_PANEL:
Joe Onorato8bc6c512010-06-04 16:21:12 -04001879 mContext.enforceCallingOrSelfPermission(
1880 android.Manifest.permission.STATUS_BAR_SERVICE,
1881 "PhoneWindowManager");
Dianne Hackborn08743722009-12-21 12:16:51 -08001882 break;
Joe Onorato29fc2c92010-11-24 10:26:50 -08001883 case TYPE_STATUS_BAR_SUB_PANEL:
1884 mContext.enforceCallingOrSelfPermission(
1885 android.Manifest.permission.STATUS_BAR_SERVICE,
1886 "PhoneWindowManager");
Joe Onorato29fc2c92010-11-24 10:26:50 -08001887 break;
Jim Miller5ecd8112013-01-09 18:50:26 -08001888 case TYPE_KEYGUARD_SCRIM:
Jim Miller25190572013-02-28 17:36:24 -08001889 if (mKeyguardScrim != null) {
1890 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
1891 }
Jim Miller5ecd8112013-01-09 18:50:26 -08001892 mKeyguardScrim = win;
1893 break;
1894
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001895 }
Jeff Brown98365d72012-08-19 20:30:52 -07001896 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001897 }
1898
1899 /** {@inheritDoc} */
1900 public void removeWindowLw(WindowState win) {
1901 if (mStatusBar == win) {
1902 mStatusBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04001903 mStatusBarController.setWindow(null);
Jim Millerc0b676d2013-03-22 16:11:08 -07001904 mKeyguardDelegate.showScrim();
Jim Miller5ecd8112013-01-09 18:50:26 -08001905 } else if (mKeyguardScrim == win) {
1906 Log.v(TAG, "Removing keyguard scrim");
1907 mKeyguardScrim = null;
1908 } if (mNavigationBar == win) {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04001909 mNavigationBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04001910 mNavigationBarController.setWindow(null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001911 }
1912 }
1913
1914 static final boolean PRINT_ANIM = false;
RoboErik8a2cfc32014-05-16 11:19:38 -07001915
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001916 /** {@inheritDoc} */
Craig Mautner4b71aa12012-12-27 17:20:01 -08001917 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001918 public int selectAnimationLw(WindowState win, int transit) {
1919 if (PRINT_ANIM) Log.i(TAG, "selectAnimation in " + win
1920 + ": transit=" + transit);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001921 if (win == mStatusBar) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001922 boolean isKeyguard = (win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001923 if (transit == TRANSIT_EXIT
1924 || transit == TRANSIT_HIDE) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001925 return isKeyguard ? -1 : R.anim.dock_top_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001926 } else if (transit == TRANSIT_ENTER
1927 || transit == TRANSIT_SHOW) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001928 return isKeyguard ? -1 : R.anim.dock_top_enter;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001929 }
1930 } else if (win == mNavigationBar) {
1931 // This can be on either the bottom or the right.
1932 if (mNavigationBarOnBottom) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08001933 if (transit == TRANSIT_EXIT
1934 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001935 return R.anim.dock_bottom_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001936 } else if (transit == TRANSIT_ENTER
1937 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001938 return R.anim.dock_bottom_enter;
1939 }
1940 } else {
Craig Mautner4b71aa12012-12-27 17:20:01 -08001941 if (transit == TRANSIT_EXIT
1942 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001943 return R.anim.dock_right_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001944 } else if (transit == TRANSIT_ENTER
1945 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001946 return R.anim.dock_right_enter;
1947 }
1948 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08001949 }
1950
1951 if (transit == TRANSIT_PREVIEW_DONE) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001952 if (win.hasAppShownWindows()) {
1953 if (PRINT_ANIM) Log.i(TAG, "**** STARTING EXIT");
1954 return com.android.internal.R.anim.app_starting_exit;
1955 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07001956 } else if (win.getAttrs().type == TYPE_DREAM && mDreamingLockscreen
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001957 && transit == TRANSIT_ENTER) {
1958 // Special case: we are animating in a dream, while the keyguard
1959 // is shown. We don't want an animation on the dream, because
1960 // we need it shown immediately with the keyguard animating away
1961 // to reveal it.
1962 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001963 }
1964
1965 return 0;
1966 }
1967
Craig Mautner3c174372013-02-21 17:54:37 -08001968 @Override
1969 public void selectRotationAnimationLw(int anim[]) {
1970 if (PRINT_ANIM) Slog.i(TAG, "selectRotationAnimation mTopFullscreen="
1971 + mTopFullscreenOpaqueWindowState + " rotationAnimation="
1972 + (mTopFullscreenOpaqueWindowState == null ?
1973 "0" : mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation));
1974 if (mTopFullscreenOpaqueWindowState != null && mTopIsFullscreen) {
1975 switch (mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation) {
1976 case ROTATION_ANIMATION_CROSSFADE:
1977 anim[0] = R.anim.rotation_animation_xfade_exit;
1978 anim[1] = R.anim.rotation_animation_enter;
1979 break;
1980 case ROTATION_ANIMATION_JUMPCUT:
1981 anim[0] = R.anim.rotation_animation_jump_exit;
1982 anim[1] = R.anim.rotation_animation_enter;
1983 break;
1984 case ROTATION_ANIMATION_ROTATE:
1985 default:
1986 anim[0] = anim[1] = 0;
1987 break;
1988 }
1989 } else {
1990 anim[0] = anim[1] = 0;
1991 }
1992 }
1993
1994 @Override
1995 public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId,
1996 boolean forceDefault) {
1997 switch (exitAnimId) {
1998 case R.anim.rotation_animation_xfade_exit:
1999 case R.anim.rotation_animation_jump_exit:
2000 // These are the only cases that matter.
2001 if (forceDefault) {
2002 return false;
2003 }
2004 int anim[] = new int[2];
2005 selectRotationAnimationLw(anim);
2006 return (exitAnimId == anim[0] && enterAnimId == anim[1]);
2007 default:
2008 return true;
2009 }
2010 }
2011
2012 @Override
Dianne Hackborn0c2acff2012-04-12 15:17:07 -07002013 public Animation createForceHideEnterAnimation(boolean onWallpaper) {
Jorim Jaggie29b2db2014-05-30 23:17:03 +02002014 return AnimationUtils.loadAnimation(mContext,
2015 com.android.internal.R.anim.lock_screen_behind_enter);
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002016 }
John Spurlockc8b46ca2013-04-08 12:59:26 -04002017
2018 private static void awakenDreams() {
2019 IDreamManager dreamManager = getDreamManager();
2020 if (dreamManager != null) {
2021 try {
2022 dreamManager.awaken();
2023 } catch (RemoteException e) {
2024 // fine, stay asleep then
2025 }
2026 }
2027 }
2028
2029 static IDreamManager getDreamManager() {
2030 return IDreamManager.Stub.asInterface(
2031 ServiceManager.checkService(DreamService.DREAM_SERVICE));
2032 }
2033
Santos Cordon6848f722014-05-21 15:22:12 -07002034 TelephonyManager getTelephonyService() {
2035 return (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002036 }
2037
Jeff Brown4d396052010-10-29 21:50:21 -07002038 static IAudioService getAudioService() {
2039 IAudioService audioService = IAudioService.Stub.asInterface(
2040 ServiceManager.checkService(Context.AUDIO_SERVICE));
2041 if (audioService == null) {
2042 Log.w(TAG, "Unable to find IAudioService interface.");
2043 }
2044 return audioService;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002045 }
2046
2047 boolean keyguardOn() {
2048 return keyguardIsShowingTq() || inKeyguardRestrictedKeyInputMode();
2049 }
2050
2051 private static final int[] WINDOW_TYPES_WHERE_HOME_DOESNT_WORK = {
2052 WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
2053 WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
2054 };
2055
2056 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002057 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002058 public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002059 final boolean keyguardOn = keyguardOn();
Jeff Brown1f245102010-11-18 20:53:46 -08002060 final int keyCode = event.getKeyCode();
2061 final int repeatCount = event.getRepeatCount();
2062 final int metaState = event.getMetaState();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002063 final int flags = event.getFlags();
Jeff Brown1f245102010-11-18 20:53:46 -08002064 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
2065 final boolean canceled = event.isCanceled();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002066
Jeff Brown40013652012-05-16 21:22:36 -07002067 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002068 Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount="
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002069 + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed
2070 + " canceled=" + canceled);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002071 }
2072
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002073 // If we think we might have a volume down & power key chord on the way
2074 // but we're not sure, then tell the dispatcher to wait a little while and
2075 // try again later before dispatching.
Christopher Tatee90585f2012-03-05 18:56:25 -08002076 if (mScreenshotChordEnabled && (flags & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002077 if (mVolumeDownKeyTriggered && !mPowerKeyTriggered) {
2078 final long now = SystemClock.uptimeMillis();
2079 final long timeoutTime = mVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS;
2080 if (now < timeoutTime) {
2081 return timeoutTime - now;
2082 }
2083 }
2084 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
2085 && mVolumeDownKeyConsumedByScreenshotChord) {
2086 if (!down) {
2087 mVolumeDownKeyConsumedByScreenshotChord = false;
2088 }
2089 return -1;
2090 }
2091 }
2092
Michael Wright6a62e552014-06-03 19:19:48 -07002093 // Cancel any pending meta actions if we see any other keys being pressed between the down
2094 // of the meta key and its corresponding up.
2095 if (mPendingMetaAction && keyCode != KeyEvent.KEYCODE_META_LEFT) {
2096 mPendingMetaAction = false;
2097 }
2098
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002099 // First we always handle the home key here, so applications
2100 // can never break it, although if keyguard is on, we do let
2101 // it handle it, because that gives us the correct 5 second
2102 // timeout.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002103 if (keyCode == KeyEvent.KEYCODE_HOME) {
Michael Jurka7f2668c2012-03-27 07:49:52 -07002104
Jeff Brown49ed71d2010-12-06 17:13:33 -08002105 // If we have released the home key, and didn't do anything else
2106 // while it was pressed, then it is time to go home!
Michael Jurka7f2668c2012-03-27 07:49:52 -07002107 if (!down) {
Jeff Browncaca8812013-05-09 13:34:33 -07002108 cancelPreloadRecentApps();
2109
Jeff Brown49ed71d2010-12-06 17:13:33 -08002110 mHomePressed = false;
Jeff Browncaca8812013-05-09 13:34:33 -07002111 if (mHomeConsumed) {
2112 mHomeConsumed = false;
Michael Jurka7f2668c2012-03-27 07:49:52 -07002113 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002114 }
Jeff Browncaca8812013-05-09 13:34:33 -07002115
2116 if (canceled) {
2117 Log.i(TAG, "Ignoring HOME; event canceled.");
2118 return -1;
2119 }
2120
2121 // If an incoming call is ringing, HOME is totally disabled.
2122 // (The user is already on the InCallScreen at this point,
2123 // and his ONLY options are to answer or reject the call.)
Santos Cordon6848f722014-05-21 15:22:12 -07002124 TelephonyManager telephonyManager = getTelephonyService();
2125 if (telephonyManager != null && telephonyManager.isRinging()) {
2126 Log.i(TAG, "Ignoring HOME; there's a ringing incoming call.");
2127 return -1;
Jeff Browncaca8812013-05-09 13:34:33 -07002128 }
2129
2130 // Delay handling home if a double-tap is possible.
2131 if (mDoubleTapOnHomeBehavior != DOUBLE_TAP_HOME_NOTHING) {
2132 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); // just in case
2133 mHomeDoubleTapPending = true;
2134 mHandler.postDelayed(mHomeDoubleTapTimeoutRunnable,
2135 ViewConfiguration.getDoubleTapTimeout());
2136 return -1;
2137 }
2138
2139 // Go home!
2140 launchHomeFromHotKey();
2141 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002142 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002143
2144 // If a system window has focus, then it doesn't make sense
2145 // right now to interact with applications.
2146 WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null;
2147 if (attrs != null) {
2148 final int type = attrs.type;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002149 if (type == WindowManager.LayoutParams.TYPE_KEYGUARD_SCRIM
2150 || type == WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG
2151 || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002152 // the "app" is keyguard, so give it the key
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002153 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002154 }
2155 final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length;
2156 for (int i=0; i<typeCount; i++) {
2157 if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) {
2158 // don't do anything, but also don't pass it to the app
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002159 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002160 }
2161 }
2162 }
Jeff Browncaca8812013-05-09 13:34:33 -07002163
2164 // Remember that home is pressed and handle special actions.
2165 if (repeatCount == 0) {
2166 mHomePressed = true;
2167 if (mHomeDoubleTapPending) {
2168 mHomeDoubleTapPending = false;
2169 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable);
2170 handleDoubleTapOnHome();
2171 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI
2172 || mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
2173 preloadRecentApps();
Michael Jurka7f2668c2012-03-27 07:49:52 -07002174 }
Jeff Browncaca8812013-05-09 13:34:33 -07002175 } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) {
2176 if (!keyguardOn) {
2177 handleLongPressOnHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002178 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002179 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002180 return -1;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002181 } else if (keyCode == KeyEvent.KEYCODE_MENU) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002182 // Hijack modified menu keys for debugging features
2183 final int chordBug = KeyEvent.META_SHIFT_ON;
2184
2185 if (down && repeatCount == 0) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002186 if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002187 Intent intent = new Intent(Intent.ACTION_BUG_REPORT);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002188 mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT,
2189 null, null, null, 0, null, null);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002190 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002191 } else if (SHOW_PROCESSES_ON_ALT_MENU &&
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002192 (metaState & KeyEvent.META_ALT_ON) == KeyEvent.META_ALT_ON) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002193 Intent service = new Intent();
2194 service.setClassName(mContext, "com.android.server.LoadAverageService");
2195 ContentResolver res = mContext.getContentResolver();
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002196 boolean shown = Settings.Global.getInt(
2197 res, Settings.Global.SHOW_PROCESSES, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002198 if (!shown) {
2199 mContext.startService(service);
2200 } else {
2201 mContext.stopService(service);
2202 }
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002203 Settings.Global.putInt(
2204 res, Settings.Global.SHOW_PROCESSES, shown ? 0 : 1);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002205 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002206 }
2207 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002208 } else if (keyCode == KeyEvent.KEYCODE_SEARCH) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002209 if (down) {
2210 if (repeatCount == 0) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002211 mSearchKeyShortcutPending = true;
2212 mConsumeSearchKeyUp = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002213 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002214 } else {
2215 mSearchKeyShortcutPending = false;
2216 if (mConsumeSearchKeyUp) {
2217 mConsumeSearchKeyUp = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002218 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002219 }
2220 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002221 return 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002222 } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) {
Michael Wrightc9ebea72013-01-16 19:25:02 -08002223 if (!keyguardOn) {
Jeff Browncaca8812013-05-09 13:34:33 -07002224 if (down && repeatCount == 0) {
2225 preloadRecentApps();
2226 } else if (!down) {
2227 toggleRecentApps();
Michael Wrightc9ebea72013-01-16 19:25:02 -08002228 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002229 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002230 return -1;
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002231 } else if (keyCode == KeyEvent.KEYCODE_ASSIST) {
2232 if (down) {
2233 if (repeatCount == 0) {
2234 mAssistKeyLongPressed = false;
2235 } else if (repeatCount == 1) {
2236 mAssistKeyLongPressed = true;
2237 if (!keyguardOn) {
2238 launchAssistLongPressAction();
2239 }
2240 }
2241 } else {
2242 if (mAssistKeyLongPressed) {
2243 mAssistKeyLongPressed = false;
2244 } else {
2245 if (!keyguardOn) {
2246 launchAssistAction();
2247 }
2248 }
2249 }
2250 return -1;
Jeff Sharkey2991fa32012-12-05 18:06:43 -08002251 } else if (keyCode == KeyEvent.KEYCODE_SYSRQ) {
2252 if (down && repeatCount == 0) {
2253 mHandler.post(mScreenshotRunnable);
2254 }
2255 return -1;
Michael Wrightb854e242013-02-05 17:54:02 -08002256 } else if (keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP
2257 || keyCode == KeyEvent.KEYCODE_BRIGHTNESS_DOWN) {
2258 if (down) {
2259 int direction = keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP ? 1 : -1;
2260
2261 // Disable autobrightness if it's on
2262 int auto = Settings.System.getIntForUser(
2263 mContext.getContentResolver(),
2264 Settings.System.SCREEN_BRIGHTNESS_MODE,
2265 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2266 UserHandle.USER_CURRENT_OR_SELF);
2267 if (auto != 0) {
2268 Settings.System.putIntForUser(mContext.getContentResolver(),
2269 Settings.System.SCREEN_BRIGHTNESS_MODE,
2270 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2271 UserHandle.USER_CURRENT_OR_SELF);
2272 }
2273
2274 int min = mPowerManager.getMinimumScreenBrightnessSetting();
2275 int max = mPowerManager.getMaximumScreenBrightnessSetting();
2276 int step = (max - min + BRIGHTNESS_STEPS - 1) / BRIGHTNESS_STEPS * direction;
2277 int brightness = Settings.System.getIntForUser(mContext.getContentResolver(),
2278 Settings.System.SCREEN_BRIGHTNESS,
2279 mPowerManager.getDefaultScreenBrightnessSetting(),
2280 UserHandle.USER_CURRENT_OR_SELF);
2281 brightness += step;
2282 // Make sure we don't go beyond the limits.
2283 brightness = Math.min(max, brightness);
2284 brightness = Math.max(min, brightness);
2285
2286 Settings.System.putIntForUser(mContext.getContentResolver(),
2287 Settings.System.SCREEN_BRIGHTNESS, brightness,
2288 UserHandle.USER_CURRENT_OR_SELF);
2289 Intent intent = new Intent(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG);
2290 mContext.sendBroadcastAsUser(intent, UserHandle.CURRENT_OR_SELF);
2291 }
2292 return -1;
Michael Wright6a62e552014-06-03 19:19:48 -07002293 } else if (keyCode == KeyEvent.KEYCODE_META_LEFT) {
2294 if (down) {
2295 mPendingMetaAction = true;
2296 } else if (mPendingMetaAction) {
2297 mPendingMetaAction = false;
2298 launchAssistAction();
2299 }
2300 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002301 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002302
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002303 // Shortcuts are invoked through Search+key, so intercept those here
Jeff Browncaab4d02010-12-09 22:13:41 -08002304 // Any printing key that is chorded with Search should be consumed
2305 // even if no shortcut was invoked. This prevents text from being
2306 // inadvertently inserted when using a keyboard that has built-in macro
2307 // shortcut keys (that emit Search+x) and some of them are not registered.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002308 if (mSearchKeyShortcutPending) {
Jeff Browncaab4d02010-12-09 22:13:41 -08002309 final KeyCharacterMap kcm = event.getKeyCharacterMap();
2310 if (kcm.isPrintingKey(keyCode)) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002311 mConsumeSearchKeyUp = true;
2312 mSearchKeyShortcutPending = false;
Jeff Browncaab4d02010-12-09 22:13:41 -08002313 if (down && repeatCount == 0 && !keyguardOn) {
2314 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState);
2315 if (shortcutIntent != null) {
2316 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002317 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002318 mContext.startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002319 } catch (ActivityNotFoundException ex) {
2320 Slog.w(TAG, "Dropping shortcut key combination because "
2321 + "the activity to which it is registered was not found: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002322 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode), ex);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002323 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002324 } else {
2325 Slog.i(TAG, "Dropping unregistered shortcut key combination: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002326 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002327 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002328 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002329 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002330 }
2331 }
2332
Jeff Brown68b909d2011-12-07 16:36:01 -08002333 // Invoke shortcuts using Meta.
Jeff Brown602ab322012-05-16 13:33:47 -07002334 if (down && repeatCount == 0 && !keyguardOn
Jeff Brown68b909d2011-12-07 16:36:01 -08002335 && (metaState & KeyEvent.META_META_ON) != 0) {
2336 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brown602ab322012-05-16 13:33:47 -07002337 if (kcm.isPrintingKey(keyCode)) {
2338 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode,
2339 metaState & ~(KeyEvent.META_META_ON
2340 | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON));
2341 if (shortcutIntent != null) {
2342 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2343 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002344 mContext.startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brown602ab322012-05-16 13:33:47 -07002345 } catch (ActivityNotFoundException ex) {
2346 Slog.w(TAG, "Dropping shortcut key combination because "
2347 + "the activity to which it is registered was not found: "
2348 + "META+" + KeyEvent.keyCodeToString(keyCode), ex);
2349 }
2350 return -1;
Jeff Brown68b909d2011-12-07 16:36:01 -08002351 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002352 }
2353 }
2354
Jeff Brown6651a632011-11-28 12:59:11 -08002355 // Handle application launch keys.
Jeff Brown602ab322012-05-16 13:33:47 -07002356 if (down && repeatCount == 0 && !keyguardOn) {
Jeff Brown6651a632011-11-28 12:59:11 -08002357 String category = sApplicationLaunchKeyCategories.get(keyCode);
2358 if (category != null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -08002359 Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category);
Jeff Brown6651a632011-11-28 12:59:11 -08002360 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2361 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002362 mContext.startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brown6651a632011-11-28 12:59:11 -08002363 } catch (ActivityNotFoundException ex) {
2364 Slog.w(TAG, "Dropping application launch key because "
2365 + "the activity to which it is registered was not found: "
2366 + "keyCode=" + keyCode + ", category=" + category, ex);
2367 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002368 return -1;
Jeff Brown6651a632011-11-28 12:59:11 -08002369 }
2370 }
2371
Jeff Brown68b909d2011-12-07 16:36:01 -08002372 // Display task switcher for ALT-TAB or Meta-TAB.
2373 if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_TAB) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002374 if (mRecentAppsHeldModifiers == 0 && !keyguardOn) {
Jeff Brown68b909d2011-12-07 16:36:01 -08002375 final int shiftlessModifiers = event.getModifiers() & ~KeyEvent.META_SHIFT_MASK;
2376 if (KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_ALT_ON)
2377 || KeyEvent.metaStateHasModifiers(
2378 shiftlessModifiers, KeyEvent.META_META_ON)) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002379 mRecentAppsHeldModifiers = shiftlessModifiers;
2380 showRecentApps(true);
Jeff Brown68b909d2011-12-07 16:36:01 -08002381 return -1;
2382 }
2383 }
Winson Chung1e8d71b2014-05-16 17:05:22 -07002384 } else if (!down && mRecentAppsHeldModifiers != 0
2385 && (metaState & mRecentAppsHeldModifiers) == 0) {
2386 mRecentAppsHeldModifiers = 0;
Winson Chung6cb485f2014-05-19 10:30:43 -07002387 hideRecentApps(true);
Jeff Brown68b909d2011-12-07 16:36:01 -08002388 }
2389
Jeff Browncf39bdf2012-05-18 14:41:19 -07002390 // Handle keyboard language switching.
2391 if (down && repeatCount == 0
2392 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2393 || (keyCode == KeyEvent.KEYCODE_SPACE
2394 && (metaState & KeyEvent.META_CTRL_MASK) != 0))) {
2395 int direction = (metaState & KeyEvent.META_SHIFT_MASK) != 0 ? -1 : 1;
2396 mWindowManagerFuncs.switchKeyboardLayout(event.getDeviceId(), direction);
2397 return -1;
2398 }
2399 if (mLanguageSwitchKeyPressed && !down
2400 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2401 || keyCode == KeyEvent.KEYCODE_SPACE)) {
2402 mLanguageSwitchKeyPressed = false;
2403 return -1;
2404 }
2405
Justin Kohd378ad72013-04-01 12:18:26 -07002406 if (mGlobalKeyManager.handleGlobalKey(mContext, keyCode, event)) {
2407 return -1;
2408 }
2409
Michael Wright6a62e552014-06-03 19:19:48 -07002410 // Reserve all the META modifier combos for system behavior
2411 if ((metaState & KeyEvent.META_META_LEFT_ON) != 0) {
2412 return -1;
2413 }
2414
Jeff Brown68b909d2011-12-07 16:36:01 -08002415 // Let the application handle the key.
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002416 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002417 }
2418
Jeff Brown3915bb82010-11-05 15:02:16 -07002419 /** {@inheritDoc} */
2420 @Override
Jeff Brown49ed71d2010-12-06 17:13:33 -08002421 public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown54875002011-04-06 15:33:01 -07002422 // Note: This method is only called if the initial down was unhandled.
Jeff Brown40013652012-05-16 21:22:36 -07002423 if (DEBUG_INPUT) {
Jeff Brown1f245102010-11-18 20:53:46 -08002424 Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction()
2425 + ", flags=" + event.getFlags()
2426 + ", keyCode=" + event.getKeyCode()
2427 + ", scanCode=" + event.getScanCode()
2428 + ", metaState=" + event.getMetaState()
2429 + ", repeatCount=" + event.getRepeatCount()
2430 + ", policyFlags=" + policyFlags);
Jeff Brown3915bb82010-11-05 15:02:16 -07002431 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002432
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002433 KeyEvent fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002434 if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
2435 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002436 final int keyCode = event.getKeyCode();
2437 final int metaState = event.getMetaState();
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002438 final boolean initialDown = event.getAction() == KeyEvent.ACTION_DOWN
2439 && event.getRepeatCount() == 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002440
Jeff Brown54875002011-04-06 15:33:01 -07002441 // Check for fallback actions specified by the key character map.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002442 final FallbackAction fallbackAction;
2443 if (initialDown) {
2444 fallbackAction = kcm.getFallbackAction(keyCode, metaState);
2445 } else {
2446 fallbackAction = mFallbackActions.get(keyCode);
2447 }
2448
2449 if (fallbackAction != null) {
Jeff Brown40013652012-05-16 21:22:36 -07002450 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002451 Slog.d(TAG, "Fallback: keyCode=" + fallbackAction.keyCode
2452 + " metaState=" + Integer.toHexString(fallbackAction.metaState));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002453 }
2454
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002455 final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK;
2456 fallbackEvent = KeyEvent.obtain(
Jeff Brown49ed71d2010-12-06 17:13:33 -08002457 event.getDownTime(), event.getEventTime(),
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002458 event.getAction(), fallbackAction.keyCode,
2459 event.getRepeatCount(), fallbackAction.metaState,
Jeff Brown49ed71d2010-12-06 17:13:33 -08002460 event.getDeviceId(), event.getScanCode(),
2461 flags, event.getSource(), null);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002462
2463 if (!interceptFallback(win, fallbackEvent, policyFlags)) {
2464 fallbackEvent.recycle();
2465 fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002466 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002467
2468 if (initialDown) {
2469 mFallbackActions.put(keyCode, fallbackAction);
2470 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2471 mFallbackActions.remove(keyCode);
2472 fallbackAction.recycle();
2473 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002474 }
2475 }
2476
Jeff Brown40013652012-05-16 21:22:36 -07002477 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002478 if (fallbackEvent == null) {
2479 Slog.d(TAG, "No fallback.");
2480 } else {
2481 Slog.d(TAG, "Performing fallback: " + fallbackEvent);
2482 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002483 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002484 return fallbackEvent;
Jeff Brown3915bb82010-11-05 15:02:16 -07002485 }
2486
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002487 private boolean interceptFallback(WindowState win, KeyEvent fallbackEvent, int policyFlags) {
Jeff Brown037c33e2014-04-09 00:31:55 -07002488 int actions = interceptKeyBeforeQueueing(fallbackEvent, policyFlags);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002489 if ((actions & ACTION_PASS_TO_USER) != 0) {
2490 long delayMillis = interceptKeyBeforeDispatching(
2491 win, fallbackEvent, policyFlags);
2492 if (delayMillis == 0) {
2493 return true;
2494 }
2495 }
2496 return false;
Jeff Brown6f2fba42011-02-19 01:08:02 -08002497 }
2498
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002499 private void launchAssistLongPressAction() {
2500 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
2501 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
2502
2503 // launch the search activity
2504 Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS);
2505 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2506 try {
RoboErik8a2cfc32014-05-16 11:19:38 -07002507 // TODO: This only stops the factory-installed search manager.
Jim Miller45308b12012-06-18 19:23:39 -07002508 // Need to formalize an API to handle others
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002509 SearchManager searchManager = getSearchManager();
2510 if (searchManager != null) {
2511 searchManager.stopSearch();
2512 }
Michael Wright43e27f72013-04-10 14:06:48 -07002513 mContext.startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002514 } catch (ActivityNotFoundException e) {
2515 Slog.w(TAG, "No activity to handle assist long press action.", e);
2516 }
2517 }
2518
2519 private void launchAssistAction() {
2520 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
Amith Yamasanic1d07a42012-08-14 09:32:02 -07002521 Intent intent = ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE))
Dianne Hackbornf9c5e0f2013-01-23 14:39:13 -08002522 .getAssistIntent(mContext, true, UserHandle.USER_CURRENT);
Jim Miller45308b12012-06-18 19:23:39 -07002523 if (intent != null) {
2524 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
2525 | Intent.FLAG_ACTIVITY_SINGLE_TOP
2526 | Intent.FLAG_ACTIVITY_CLEAR_TOP);
2527 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002528 mContext.startActivityAsUser(intent, UserHandle.CURRENT);
Jim Miller45308b12012-06-18 19:23:39 -07002529 } catch (ActivityNotFoundException e) {
2530 Slog.w(TAG, "No activity to handle assist action.", e);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002531 }
2532 }
2533 }
2534
2535 private SearchManager getSearchManager() {
2536 if (mSearchManager == null) {
2537 mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
2538 }
2539 return mSearchManager;
2540 }
2541
Jeff Browncaca8812013-05-09 13:34:33 -07002542 private void preloadRecentApps() {
2543 mPreloadedRecentApps = true;
2544 try {
2545 IStatusBarService statusbar = getStatusBarService();
2546 if (statusbar != null) {
2547 statusbar.preloadRecentApps();
2548 }
2549 } catch (RemoteException e) {
2550 Slog.e(TAG, "RemoteException when preloading recent apps", e);
2551 // re-acquire status bar service next time it is needed.
2552 mStatusBarService = null;
2553 }
2554 }
2555
2556 private void cancelPreloadRecentApps() {
2557 if (mPreloadedRecentApps) {
2558 mPreloadedRecentApps = false;
2559 try {
2560 IStatusBarService statusbar = getStatusBarService();
2561 if (statusbar != null) {
2562 statusbar.cancelPreloadRecentApps();
2563 }
2564 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002565 Slog.e(TAG, "RemoteException when cancelling recent apps preload", e);
Jeff Browncaca8812013-05-09 13:34:33 -07002566 // re-acquire status bar service next time it is needed.
2567 mStatusBarService = null;
2568 }
2569 }
2570 }
2571
2572 private void toggleRecentApps() {
2573 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
Jeff Browncaca8812013-05-09 13:34:33 -07002574 try {
2575 IStatusBarService statusbar = getStatusBarService();
2576 if (statusbar != null) {
2577 statusbar.toggleRecentApps();
2578 }
2579 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002580 Slog.e(TAG, "RemoteException when toggling recent apps", e);
2581 // re-acquire status bar service next time it is needed.
2582 mStatusBarService = null;
2583 }
2584 }
2585
2586 private void showRecentApps(boolean triggeredFromAltTab) {
2587 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
2588 try {
2589 IStatusBarService statusbar = getStatusBarService();
2590 if (statusbar != null) {
2591 statusbar.showRecentApps(triggeredFromAltTab);
2592 }
2593 } catch (RemoteException e) {
Jeff Browncaca8812013-05-09 13:34:33 -07002594 Slog.e(TAG, "RemoteException when showing recent apps", e);
2595 // re-acquire status bar service next time it is needed.
2596 mStatusBarService = null;
2597 }
2598 }
2599
Winson Chung6cb485f2014-05-19 10:30:43 -07002600 private void hideRecentApps(boolean triggeredFromAltTab) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002601 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
2602 try {
2603 IStatusBarService statusbar = getStatusBarService();
2604 if (statusbar != null) {
Winson Chung6cb485f2014-05-19 10:30:43 -07002605 statusbar.hideRecentApps(triggeredFromAltTab);
Winson Chung1e8d71b2014-05-16 17:05:22 -07002606 }
2607 } catch (RemoteException e) {
2608 Slog.e(TAG, "RemoteException when closing recent apps", e);
2609 // re-acquire status bar service next time it is needed.
2610 mStatusBarService = null;
2611 }
2612 }
2613
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002614 /**
2615 * A home key -> launch home action was detected. Take the appropriate action
2616 * given the situation with the keyguard.
2617 */
2618 void launchHomeFromHotKey() {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01002619 if (mKeyguardDelegate != null && mKeyguardDelegate.isShowingAndNotOccluded()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002620 // don't launch home if keyguard showing
Jim Miller5ecd8112013-01-09 18:50:26 -08002621 } else if (!mHideLockScreen && mKeyguardDelegate.isInputRestricted()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002622 // when in keyguard restricted mode, must first verify unlock
2623 // before launching home
Jim Miller5ecd8112013-01-09 18:50:26 -08002624 mKeyguardDelegate.verifyUnlock(new OnKeyguardExitResult() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002625 public void onKeyguardExitResult(boolean success) {
2626 if (success) {
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07002627 try {
2628 ActivityManagerNative.getDefault().stopAppSwitches();
2629 } catch (RemoteException e) {
2630 }
Joe Onoratof275f0c2009-11-24 16:11:13 -05002631 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07002632 startDockOrHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002633 }
2634 }
2635 });
Winson Chungd42a6cf2014-06-03 16:24:04 -07002636 } else if (mRecentsVisible) {
2637 // Recents is started on top of Home, so when we launch home while recents is open, let
2638 // it do its own animation and then finish itself
2639 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
2640 hideRecentApps(false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002641 } else {
2642 // no keyguard stuff to worry about, just launch home!
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07002643 try {
2644 ActivityManagerNative.getDefault().stopAppSwitches();
2645 } catch (RemoteException e) {
2646 }
Joe Onoratof275f0c2009-11-24 16:11:13 -05002647 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07002648 startDockOrHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002649 }
2650 }
2651
John Spurlock04db1762013-05-13 12:46:41 -04002652 private final Runnable mClearHideNavigationFlag = new Runnable() {
2653 @Override
2654 public void run() {
2655 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
2656 // Clear flags.
2657 mForceClearedSystemUiFlags &=
2658 ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
2659 }
2660 mWindowManagerFuncs.reevaluateStatusBarVisibility();
Dianne Hackborne26ab702011-10-16 13:21:33 -07002661 }
2662 };
2663
2664 /**
2665 * Input handler used while nav bar is hidden. Captures any touch on the screen,
2666 * to determine when the nav bar should be shown and prevent applications from
2667 * receiving those touches.
2668 */
Jeff Brown32cbc38552011-12-01 14:01:49 -08002669 final class HideNavInputEventReceiver extends InputEventReceiver {
2670 public HideNavInputEventReceiver(InputChannel inputChannel, Looper looper) {
2671 super(inputChannel, looper);
2672 }
2673
Dianne Hackborndf89e652011-10-06 22:35:11 -07002674 @Override
Jeff Brown32cbc38552011-12-01 14:01:49 -08002675 public void onInputEvent(InputEvent event) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07002676 boolean handled = false;
2677 try {
Jeff Brown4952dfd2011-11-30 19:23:22 -08002678 if (event instanceof MotionEvent
2679 && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
2680 final MotionEvent motionEvent = (MotionEvent)event;
2681 if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07002682 // When the user taps down, we re-show the nav bar.
2683 boolean changed = false;
John Spurlock04db1762013-05-13 12:46:41 -04002684 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002685 // Any user activity always causes us to show the
2686 // navigation controls, if they had been hidden.
2687 // We also clear the low profile and only content
2688 // flags so that tapping on the screen will atomically
2689 // restore all currently hidden screen decorations.
2690 int newVal = mResettingSystemUiFlags |
2691 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
2692 View.SYSTEM_UI_FLAG_LOW_PROFILE |
2693 View.SYSTEM_UI_FLAG_FULLSCREEN;
Dianne Hackborne26ab702011-10-16 13:21:33 -07002694 if (mResettingSystemUiFlags != newVal) {
2695 mResettingSystemUiFlags = newVal;
Dianne Hackborndf89e652011-10-06 22:35:11 -07002696 changed = true;
2697 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07002698 // We don't allow the system's nav bar to be hidden
2699 // again for 1 second, to prevent applications from
2700 // spamming us and keeping it from being shown.
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002701 newVal = mForceClearedSystemUiFlags |
2702 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
Dianne Hackborne26ab702011-10-16 13:21:33 -07002703 if (mForceClearedSystemUiFlags != newVal) {
2704 mForceClearedSystemUiFlags = newVal;
2705 changed = true;
John Spurlock04db1762013-05-13 12:46:41 -04002706 mHandler.postDelayed(mClearHideNavigationFlag, 1000);
Dianne Hackborne26ab702011-10-16 13:21:33 -07002707 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07002708 }
2709 if (changed) {
2710 mWindowManagerFuncs.reevaluateStatusBarVisibility();
2711 }
2712 }
2713 }
2714 } finally {
Jeff Brown32cbc38552011-12-01 14:01:49 -08002715 finishInputEvent(event, handled);
Dianne Hackborndf89e652011-10-06 22:35:11 -07002716 }
2717 }
Jeff Brown32cbc38552011-12-01 14:01:49 -08002718 }
2719 final InputEventReceiver.Factory mHideNavInputEventReceiverFactory =
2720 new InputEventReceiver.Factory() {
2721 @Override
2722 public InputEventReceiver createInputEventReceiver(
2723 InputChannel inputChannel, Looper looper) {
2724 return new HideNavInputEventReceiver(inputChannel, looper);
2725 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07002726 };
2727
2728 @Override
2729 public int adjustSystemUiVisibilityLw(int visibility) {
John Spurlock5b9145b2013-08-20 15:13:47 -04002730 mStatusBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
2731 mNavigationBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
Winson Chungd42a6cf2014-06-03 16:24:04 -07002732 mRecentsVisible = (visibility & View.RECENT_APPS_VISIBLE) > 0;
John Spurlock27735a42013-08-14 17:57:38 -04002733
Dianne Hackborndf89e652011-10-06 22:35:11 -07002734 // Reset any bits in mForceClearingStatusBarVisibility that
2735 // are now clear.
Dianne Hackborne26ab702011-10-16 13:21:33 -07002736 mResettingSystemUiFlags &= visibility;
Dianne Hackborndf89e652011-10-06 22:35:11 -07002737 // Clear any bits in the new visibility that are currently being
2738 // force cleared, before reporting it.
Dianne Hackborne26ab702011-10-16 13:21:33 -07002739 return visibility & ~mResettingSystemUiFlags
2740 & ~mForceClearedSystemUiFlags;
Dianne Hackborndf89e652011-10-06 22:35:11 -07002741 }
2742
Craig Mautner69b08182012-09-05 13:07:13 -07002743 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002744 public void getContentInsetHintLw(WindowManager.LayoutParams attrs, Rect contentInset) {
John Spurlockc6d1c602014-01-17 15:22:06 -05002745 final int fl = PolicyControl.getWindowFlags(null, attrs);
John Spurlock1db8b682014-02-18 11:18:59 -05002746 final int sysuiVis = PolicyControl.getSystemUiVisibility(null, attrs);
2747 final int systemUiVisibility = (sysuiVis | attrs.subtreeSystemUiVisibility);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002748
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002749 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002750 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002751 int availRight, availBottom;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07002752 if (canHideNavigationBar() &&
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002753 (systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002754 availRight = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
2755 availBottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
2756 } else {
2757 availRight = mRestrictedScreenLeft + mRestrictedScreenWidth;
2758 availBottom = mRestrictedScreenTop + mRestrictedScreenHeight;
2759 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002760 if ((systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
2761 if ((fl & FLAG_FULLSCREEN) != 0) {
2762 contentInset.set(mStableFullscreenLeft, mStableFullscreenTop,
2763 availRight - mStableFullscreenRight,
2764 availBottom - mStableFullscreenBottom);
2765 } else {
2766 contentInset.set(mStableLeft, mStableTop,
2767 availRight - mStableRight, availBottom - mStableBottom);
2768 }
Dianne Hackbornc652de82013-02-15 16:32:56 -08002769 } else if ((fl & FLAG_FULLSCREEN) != 0 || (fl & FLAG_LAYOUT_IN_OVERSCAN) != 0) {
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002770 contentInset.setEmpty();
2771 } else if ((systemUiVisibility & (View.SYSTEM_UI_FLAG_FULLSCREEN
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002772 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)) == 0) {
2773 contentInset.set(mCurLeft, mCurTop,
2774 availRight - mCurRight, availBottom - mCurBottom);
2775 } else {
2776 contentInset.set(mCurLeft, mCurTop,
2777 availRight - mCurRight, availBottom - mCurBottom);
2778 }
2779 return;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002780 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002781 contentInset.setEmpty();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002782 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002783
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002784 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07002785 @Override
2786 public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight,
2787 int displayRotation) {
Dianne Hackbornc652de82013-02-15 16:32:56 -08002788 final int overscanLeft, overscanTop, overscanRight, overscanBottom;
2789 if (isDefaultDisplay) {
2790 switch (displayRotation) {
2791 case Surface.ROTATION_90:
2792 overscanLeft = mOverscanTop;
2793 overscanTop = mOverscanRight;
2794 overscanRight = mOverscanBottom;
2795 overscanBottom = mOverscanLeft;
2796 break;
2797 case Surface.ROTATION_180:
2798 overscanLeft = mOverscanRight;
2799 overscanTop = mOverscanBottom;
2800 overscanRight = mOverscanLeft;
2801 overscanBottom = mOverscanTop;
2802 break;
2803 case Surface.ROTATION_270:
2804 overscanLeft = mOverscanBottom;
2805 overscanTop = mOverscanLeft;
2806 overscanRight = mOverscanTop;
2807 overscanBottom = mOverscanRight;
2808 break;
2809 default:
2810 overscanLeft = mOverscanLeft;
2811 overscanTop = mOverscanTop;
2812 overscanRight = mOverscanRight;
2813 overscanBottom = mOverscanBottom;
2814 break;
2815 }
2816 } else {
2817 overscanLeft = 0;
2818 overscanTop = 0;
2819 overscanRight = 0;
2820 overscanBottom = 0;
2821 }
Dianne Hackborn313440842013-02-19 19:22:59 -08002822 mOverscanScreenLeft = mRestrictedOverscanScreenLeft = 0;
2823 mOverscanScreenTop = mRestrictedOverscanScreenTop = 0;
2824 mOverscanScreenWidth = mRestrictedOverscanScreenWidth = displayWidth;
2825 mOverscanScreenHeight = mRestrictedOverscanScreenHeight = displayHeight;
Dianne Hackbornc652de82013-02-15 16:32:56 -08002826 mSystemLeft = 0;
2827 mSystemTop = 0;
2828 mSystemRight = displayWidth;
2829 mSystemBottom = displayHeight;
2830 mUnrestrictedScreenLeft = overscanLeft;
2831 mUnrestrictedScreenTop = overscanTop;
2832 mUnrestrictedScreenWidth = displayWidth - overscanLeft - overscanRight;
2833 mUnrestrictedScreenHeight = displayHeight - overscanTop - overscanBottom;
2834 mRestrictedScreenLeft = mUnrestrictedScreenLeft;
2835 mRestrictedScreenTop = mUnrestrictedScreenTop;
John Spurlockad3e6cb2013-04-30 08:47:43 -04002836 mRestrictedScreenWidth = mSystemGestures.screenWidth = mUnrestrictedScreenWidth;
2837 mRestrictedScreenHeight = mSystemGestures.screenHeight = mUnrestrictedScreenHeight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002838 mDockLeft = mContentLeft = mVoiceContentLeft = mStableLeft = mStableFullscreenLeft
Dianne Hackbornc652de82013-02-15 16:32:56 -08002839 = mCurLeft = mUnrestrictedScreenLeft;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002840 mDockTop = mContentTop = mVoiceContentTop = mStableTop = mStableFullscreenTop
Dianne Hackbornc652de82013-02-15 16:32:56 -08002841 = mCurTop = mUnrestrictedScreenTop;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002842 mDockRight = mContentRight = mVoiceContentRight = mStableRight = mStableFullscreenRight
Dianne Hackbornc652de82013-02-15 16:32:56 -08002843 = mCurRight = displayWidth - overscanRight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002844 mDockBottom = mContentBottom = mVoiceContentBottom = mStableBottom = mStableFullscreenBottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08002845 = mCurBottom = displayHeight - overscanBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002846 mDockLayer = 0x10000000;
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002847 mStatusBarLayer = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002848
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002849 // start with the current dock rect, which will be (0,0,displayWidth,displayHeight)
2850 final Rect pf = mTmpParentFrame;
2851 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002852 final Rect of = mTmpOverscanFrame;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002853 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04002854 final Rect dcf = mTmpDecorFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002855 pf.left = df.left = of.left = vf.left = mDockLeft;
2856 pf.top = df.top = of.top = vf.top = mDockTop;
2857 pf.right = df.right = of.right = vf.right = mDockRight;
2858 pf.bottom = df.bottom = of.bottom = vf.bottom = mDockBottom;
John Spurlock46646232013-09-30 22:32:42 -04002859 dcf.setEmpty(); // Decor frame N/A for system bars.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002860
Craig Mautner69b08182012-09-05 13:07:13 -07002861 if (isDefaultDisplay) {
2862 // For purposes of putting out fake window up to steal focus, we will
2863 // drive nav being hidden only by whether it is requested.
John Spurlocke1f366f2013-08-05 12:22:40 -04002864 final int sysui = mLastSystemUiFlags;
2865 boolean navVisible = (sysui & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0;
Adrian Roosea562512014-05-05 13:33:03 +02002866 boolean navTranslucent = (sysui
2867 & (View.NAVIGATION_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04002868 boolean immersive = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
2869 boolean immersiveSticky = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
2870 boolean navAllowedHidden = immersive || immersiveSticky;
2871 navTranslucent &= !immersiveSticky; // transient trumps translucent
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04002872 navTranslucent &= areTranslucentBarsAllowed();
Dianne Hackborne26ab702011-10-16 13:21:33 -07002873
Craig Mautner69b08182012-09-05 13:07:13 -07002874 // When the navigation bar isn't visible, we put up a fake
2875 // input window to catch all touch events. This way we can
2876 // detect when the user presses anywhere to bring back the nav
2877 // bar and ensure the application doesn't see the event.
John Spurlockf1a36642013-10-12 17:50:42 -04002878 if (navVisible || navAllowedHidden) {
Craig Mautner69b08182012-09-05 13:07:13 -07002879 if (mHideNavFakeWindow != null) {
2880 mHideNavFakeWindow.dismiss();
2881 mHideNavFakeWindow = null;
2882 }
2883 } else if (mHideNavFakeWindow == null) {
2884 mHideNavFakeWindow = mWindowManagerFuncs.addFakeWindow(
2885 mHandler.getLooper(), mHideNavInputEventReceiverFactory,
Adam Lesinski95c42972013-10-02 10:13:27 -07002886 "hidden nav", WindowManager.LayoutParams.TYPE_HIDDEN_NAV_CONSUMER, 0,
Craig Mautner69b08182012-09-05 13:07:13 -07002887 0, false, false, true);
Dianne Hackborne26ab702011-10-16 13:21:33 -07002888 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07002889
Craig Mautner69b08182012-09-05 13:07:13 -07002890 // For purposes of positioning and showing the nav bar, if we have
2891 // decided that it can't be hidden (because of the screen aspect ratio),
2892 // then take that into account.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07002893 navVisible |= !canHideNavigationBar();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002894
John Spurlockad3e6cb2013-04-30 08:47:43 -04002895 boolean updateSysUiVisibility = false;
Craig Mautner69b08182012-09-05 13:07:13 -07002896 if (mNavigationBar != null) {
John Spurlock27735a42013-08-14 17:57:38 -04002897 boolean transientNavBarShowing = mNavigationBarController.isTransientShowing();
Craig Mautner69b08182012-09-05 13:07:13 -07002898 // Force the navigation bar to its appropriate place and
2899 // size. We need to do this directly, instead of relying on
2900 // it to bubble up from the nav bar, because this needs to
2901 // change atomically with screen rotations.
2902 mNavigationBarOnBottom = (!mNavigationBarCanMove || displayWidth < displayHeight);
2903 if (mNavigationBarOnBottom) {
2904 // It's a system nav bar or a portrait screen; nav bar goes on bottom.
Dianne Hackbornc652de82013-02-15 16:32:56 -08002905 int top = displayHeight - overscanBottom
2906 - mNavigationBarHeightForRotation[displayRotation];
2907 mTmpNavigationFrame.set(0, top, displayWidth, displayHeight - overscanBottom);
Craig Mautner69b08182012-09-05 13:07:13 -07002908 mStableBottom = mStableFullscreenBottom = mTmpNavigationFrame.top;
John Spurlockf95b89a2013-10-10 22:10:42 -04002909 if (transientNavBarShowing) {
John Spurlock27735a42013-08-14 17:57:38 -04002910 mNavigationBarController.setBarShowingLw(true);
John Spurlockad3e6cb2013-04-30 08:47:43 -04002911 } else if (navVisible) {
John Spurlock27735a42013-08-14 17:57:38 -04002912 mNavigationBarController.setBarShowingLw(true);
Craig Mautner69b08182012-09-05 13:07:13 -07002913 mDockBottom = mTmpNavigationFrame.top;
Dianne Hackborn313440842013-02-19 19:22:59 -08002914 mRestrictedScreenHeight = mDockBottom - mRestrictedScreenTop;
2915 mRestrictedOverscanScreenHeight = mDockBottom - mRestrictedOverscanScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07002916 } else {
2917 // We currently want to hide the navigation UI.
John Spurlock27735a42013-08-14 17:57:38 -04002918 mNavigationBarController.setBarShowingLw(false);
Craig Mautner69b08182012-09-05 13:07:13 -07002919 }
John Spurlockc6d1c602014-01-17 15:22:06 -05002920 if (navVisible && !navTranslucent && !navAllowedHidden
2921 && !mNavigationBar.isAnimatingLw()
John Spurlockbd957402013-10-03 11:38:39 -04002922 && !mNavigationBarController.wasRecentlyTranslucent()) {
John Spurlocke1f366f2013-08-05 12:22:40 -04002923 // If the opaque nav bar is currently requested to be visible,
Craig Mautner69b08182012-09-05 13:07:13 -07002924 // and not in the process of animating on or off, then
2925 // we can tell the app that it is covered by it.
2926 mSystemBottom = mTmpNavigationFrame.top;
2927 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002928 } else {
Craig Mautner69b08182012-09-05 13:07:13 -07002929 // Landscape screen; nav bar goes to the right.
Dianne Hackbornc652de82013-02-15 16:32:56 -08002930 int left = displayWidth - overscanRight
2931 - mNavigationBarWidthForRotation[displayRotation];
2932 mTmpNavigationFrame.set(left, 0, displayWidth - overscanRight, displayHeight);
Craig Mautner69b08182012-09-05 13:07:13 -07002933 mStableRight = mStableFullscreenRight = mTmpNavigationFrame.left;
John Spurlockf95b89a2013-10-10 22:10:42 -04002934 if (transientNavBarShowing) {
John Spurlock27735a42013-08-14 17:57:38 -04002935 mNavigationBarController.setBarShowingLw(true);
John Spurlockad3e6cb2013-04-30 08:47:43 -04002936 } else if (navVisible) {
John Spurlock27735a42013-08-14 17:57:38 -04002937 mNavigationBarController.setBarShowingLw(true);
Craig Mautner69b08182012-09-05 13:07:13 -07002938 mDockRight = mTmpNavigationFrame.left;
Dianne Hackborn313440842013-02-19 19:22:59 -08002939 mRestrictedScreenWidth = mDockRight - mRestrictedScreenLeft;
2940 mRestrictedOverscanScreenWidth = mDockRight - mRestrictedOverscanScreenLeft;
Craig Mautner69b08182012-09-05 13:07:13 -07002941 } else {
2942 // We currently want to hide the navigation UI.
John Spurlock27735a42013-08-14 17:57:38 -04002943 mNavigationBarController.setBarShowingLw(false);
Craig Mautner69b08182012-09-05 13:07:13 -07002944 }
John Spurlockbd957402013-10-03 11:38:39 -04002945 if (navVisible && !navTranslucent && !mNavigationBar.isAnimatingLw()
2946 && !mNavigationBarController.wasRecentlyTranslucent()) {
Craig Mautner69b08182012-09-05 13:07:13 -07002947 // If the nav bar is currently requested to be visible,
2948 // and not in the process of animating on or off, then
2949 // we can tell the app that it is covered by it.
2950 mSystemRight = mTmpNavigationFrame.left;
2951 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002952 }
Craig Mautner69b08182012-09-05 13:07:13 -07002953 // Make sure the content and current rectangles are updated to
2954 // account for the restrictions from the navigation bar.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002955 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
2956 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
2957 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
2958 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
Craig Mautner69b08182012-09-05 13:07:13 -07002959 mStatusBarLayer = mNavigationBar.getSurfaceLayer();
2960 // And compute the final frame.
2961 mNavigationBar.computeFrameLw(mTmpNavigationFrame, mTmpNavigationFrame,
John Spurlock46646232013-09-30 22:32:42 -04002962 mTmpNavigationFrame, mTmpNavigationFrame, mTmpNavigationFrame, dcf);
Craig Mautnereda67292013-04-28 13:50:14 -07002963 if (DEBUG_LAYOUT) Slog.i(TAG, "mNavigationBar frame: " + mTmpNavigationFrame);
John Spurlock27735a42013-08-14 17:57:38 -04002964 if (mNavigationBarController.checkHiddenLw()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04002965 updateSysUiVisibility = true;
2966 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002967 }
Craig Mautnereda67292013-04-28 13:50:14 -07002968 if (DEBUG_LAYOUT) Slog.i(TAG, String.format("mDock rect: (%d,%d - %d,%d)",
Craig Mautner69b08182012-09-05 13:07:13 -07002969 mDockLeft, mDockTop, mDockRight, mDockBottom));
2970
2971 // decide where the status bar goes ahead of time
2972 if (mStatusBar != null) {
2973 // apply any navigation bar insets
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002974 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
2975 pf.top = df.top = of.top = mUnrestrictedScreenTop;
2976 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
2977 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight
2978 + mUnrestrictedScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07002979 vf.left = mStableLeft;
2980 vf.top = mStableTop;
2981 vf.right = mStableRight;
2982 vf.bottom = mStableBottom;
2983
2984 mStatusBarLayer = mStatusBar.getSurfaceLayer();
2985
2986 // Let the status bar determine its size.
John Spurlock46646232013-09-30 22:32:42 -04002987 mStatusBar.computeFrameLw(pf, df, vf, vf, vf, dcf);
Craig Mautner69b08182012-09-05 13:07:13 -07002988
2989 // For layout, the status bar is always at the top with our fixed height.
2990 mStableTop = mUnrestrictedScreenTop + mStatusBarHeight;
2991
John Spurlocke1f366f2013-08-05 12:22:40 -04002992 boolean statusBarTransient = (sysui & View.STATUS_BAR_TRANSIENT) != 0;
Adrian Roosea562512014-05-05 13:33:03 +02002993 boolean statusBarTranslucent = (sysui
2994 & (View.STATUS_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0;
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04002995 statusBarTranslucent &= areTranslucentBarsAllowed();
John Spurlock32beb2c2013-03-11 10:16:47 -04002996
Craig Mautner69b08182012-09-05 13:07:13 -07002997 // If the status bar is hidden, we don't want to cause
2998 // windows behind it to scroll.
John Spurlockeda1f692013-09-16 11:38:44 -04002999 if (mStatusBar.isVisibleLw() && !statusBarTransient) {
Craig Mautner69b08182012-09-05 13:07:13 -07003000 // Status bar may go away, so the screen area it occupies
3001 // is available to apps but just covering them when the
3002 // status bar is visible.
3003 mDockTop = mUnrestrictedScreenTop + mStatusBarHeight;
3004
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003005 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3006 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3007 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3008 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
Craig Mautner69b08182012-09-05 13:07:13 -07003009
Craig Mautnereda67292013-04-28 13:50:14 -07003010 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar: " +
Craig Mautner69b08182012-09-05 13:07:13 -07003011 String.format(
3012 "dock=[%d,%d][%d,%d] content=[%d,%d][%d,%d] cur=[%d,%d][%d,%d]",
3013 mDockLeft, mDockTop, mDockRight, mDockBottom,
3014 mContentLeft, mContentTop, mContentRight, mContentBottom,
3015 mCurLeft, mCurTop, mCurRight, mCurBottom));
3016 }
John Spurlocke1f366f2013-08-05 12:22:40 -04003017 if (mStatusBar.isVisibleLw() && !mStatusBar.isAnimatingLw()
John Spurlockbd957402013-10-03 11:38:39 -04003018 && !statusBarTransient && !statusBarTranslucent
3019 && !mStatusBarController.wasRecentlyTranslucent()) {
John Spurlocke1f366f2013-08-05 12:22:40 -04003020 // If the opaque status bar is currently requested to be visible,
Craig Mautner69b08182012-09-05 13:07:13 -07003021 // and not in the process of animating on or off, then
3022 // we can tell the app that it is covered by it.
3023 mSystemTop = mUnrestrictedScreenTop + mStatusBarHeight;
3024 }
John Spurlock27735a42013-08-14 17:57:38 -04003025 if (mStatusBarController.checkHiddenLw()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04003026 updateSysUiVisibility = true;
John Spurlock32beb2c2013-03-11 10:16:47 -04003027 }
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003028 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04003029 if (updateSysUiVisibility) {
3030 updateSystemUiVisibilityLw();
3031 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003032 }
3033 }
3034
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003035 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07003036 @Override
John Spurlock46646232013-09-30 22:32:42 -04003037 public int getSystemDecorLayerLw() {
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003038 if (mStatusBar != null) return mStatusBar.getSurfaceLayer();
3039 if (mNavigationBar != null) return mNavigationBar.getSurfaceLayer();
3040 return 0;
3041 }
3042
Craig Mautner967212c2013-04-13 21:10:58 -07003043 @Override
3044 public void getContentRectLw(Rect r) {
3045 r.set(mContentLeft, mContentTop, mContentRight, mContentBottom);
3046 }
3047
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003048 void setAttachedWindowFrames(WindowState win, int fl, int adjust, WindowState attached,
3049 boolean insetDecors, Rect pf, Rect df, Rect of, Rect cf, Rect vf) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003050 if (win.getSurfaceLayer() > mDockLayer && attached.getSurfaceLayer() < mDockLayer) {
3051 // Here's a special case: if this attached window is a panel that is
3052 // above the dock window, and the window it is attached to is below
3053 // the dock window, then the frames we computed for the window it is
3054 // attached to can not be used because the dock is effectively part
3055 // of the underlying window and the attached window is floating on top
3056 // of the whole thing. So, we ignore the attached window and explicitly
3057 // compute the frames that would be appropriate without the dock.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003058 df.left = of.left = cf.left = vf.left = mDockLeft;
3059 df.top = of.top = cf.top = vf.top = mDockTop;
3060 df.right = of.right = cf.right = vf.right = mDockRight;
3061 df.bottom = of.bottom = cf.bottom = vf.bottom = mDockBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003062 } else {
3063 // The effective display frame of the attached window depends on
3064 // whether it is taking care of insetting its content. If not,
3065 // we need to use the parent's content frame so that the entire
3066 // window is positioned within that content. Otherwise we can use
3067 // the display frame and let the attached window take care of
3068 // positioning its content appropriately.
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003069 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003070 cf.set(attached.getOverscanFrameLw());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003071 } else {
3072 // If the window is resizing, then we want to base the content
3073 // frame on our attached content frame to resize... however,
3074 // things can be tricky if the attached window is NOT in resize
3075 // mode, in which case its content frame will be larger.
3076 // Ungh. So to deal with that, make sure the content frame
3077 // we end up using is not covering the IM dock.
3078 cf.set(attached.getContentFrameLw());
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003079 if (attached.isVoiceInteraction()) {
3080 if (cf.left < mVoiceContentLeft) cf.left = mVoiceContentLeft;
3081 if (cf.top < mVoiceContentTop) cf.top = mVoiceContentTop;
3082 if (cf.right > mVoiceContentRight) cf.right = mVoiceContentRight;
3083 if (cf.bottom > mVoiceContentBottom) cf.bottom = mVoiceContentBottom;
3084 } else if (attached.getSurfaceLayer() < mDockLayer) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003085 if (cf.left < mContentLeft) cf.left = mContentLeft;
3086 if (cf.top < mContentTop) cf.top = mContentTop;
3087 if (cf.right > mContentRight) cf.right = mContentRight;
3088 if (cf.bottom > mContentBottom) cf.bottom = mContentBottom;
3089 }
3090 }
3091 df.set(insetDecors ? attached.getDisplayFrameLw() : cf);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003092 of.set(insetDecors ? attached.getOverscanFrameLw() : cf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003093 vf.set(attached.getVisibleFrameLw());
3094 }
3095 // The LAYOUT_IN_SCREEN flag is used to determine whether the attached
3096 // window should be positioned relative to its parent or the entire
3097 // screen.
3098 pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0
3099 ? attached.getFrameLw() : df);
3100 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003101
3102 private void applyStableConstraints(int sysui, int fl, Rect r) {
3103 if ((sysui & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
3104 // If app is requesting a stable layout, don't let the
3105 // content insets go below the stable values.
3106 if ((fl & FLAG_FULLSCREEN) != 0) {
3107 if (r.left < mStableFullscreenLeft) r.left = mStableFullscreenLeft;
3108 if (r.top < mStableFullscreenTop) r.top = mStableFullscreenTop;
3109 if (r.right > mStableFullscreenRight) r.right = mStableFullscreenRight;
3110 if (r.bottom > mStableFullscreenBottom) r.bottom = mStableFullscreenBottom;
3111 } else {
3112 if (r.left < mStableLeft) r.left = mStableLeft;
3113 if (r.top < mStableTop) r.top = mStableTop;
3114 if (r.right > mStableRight) r.right = mStableRight;
3115 if (r.bottom > mStableBottom) r.bottom = mStableBottom;
3116 }
3117 }
3118 }
3119
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003120 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07003121 @Override
Dianne Hackborn0ecadf72009-03-31 18:00:37 -07003122 public void layoutWindowLw(WindowState win, WindowManager.LayoutParams attrs,
3123 WindowState attached) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003124 // we've already done the status bar
Craig Mautnerbeac1062014-06-03 14:38:57 -07003125 if ((win == mStatusBar && !doesForceHide(attrs)) || win == mNavigationBar) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003126 return;
3127 }
Craig Mautner69b08182012-09-05 13:07:13 -07003128 final boolean isDefaultDisplay = win.isDefaultDisplay();
3129 final boolean needsToOffsetInputMethodTarget = isDefaultDisplay &&
satok1bc0a492012-04-25 22:47:12 +09003130 (win == mLastInputMethodTargetWindow && mLastInputMethodWindow != null);
3131 if (needsToOffsetInputMethodTarget) {
Craig Mautnereda67292013-04-28 13:50:14 -07003132 if (DEBUG_LAYOUT) Slog.i(TAG, "Offset ime target window by the last ime window state");
satok1bc0a492012-04-25 22:47:12 +09003133 offsetInputMethodWindowLw(mLastInputMethodWindow);
3134 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003135
John Spurlockc6d1c602014-01-17 15:22:06 -05003136 final int fl = PolicyControl.getWindowFlags(win, attrs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003137 final int sim = attrs.softInputMode;
John Spurlock1db8b682014-02-18 11:18:59 -05003138 final int sysUiFl = PolicyControl.getSystemUiVisibility(win, null);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003139
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003140 final Rect pf = mTmpParentFrame;
3141 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003142 final Rect of = mTmpOverscanFrame;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003143 final Rect cf = mTmpContentFrame;
3144 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04003145 final Rect dcf = mTmpDecorFrame;
3146 dcf.setEmpty();
Craig Mautner69b08182012-09-05 13:07:13 -07003147
3148 final boolean hasNavBar = (isDefaultDisplay && mHasNavigationBar
Daniel Sandler36412a72011-08-04 09:35:13 -04003149 && mNavigationBar != null && mNavigationBar.isVisibleLw());
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003150
Craig Mautnerf683b562012-10-02 11:10:57 -07003151 final int adjust = sim & SOFT_INPUT_MASK_ADJUST;
3152
Craig Mautner69b08182012-09-05 13:07:13 -07003153 if (!isDefaultDisplay) {
3154 if (attached != null) {
3155 // If this window is attached to another, our display
3156 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003157 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07003158 } else {
3159 // Give the window full screen.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003160 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3161 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3162 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08003163 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003164 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003165 = mOverscanScreenTop + mOverscanScreenHeight;
Craig Mautner69b08182012-09-05 13:07:13 -07003166 }
3167 } else if (attrs.type == TYPE_INPUT_METHOD) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003168 pf.left = df.left = of.left = cf.left = vf.left = mDockLeft;
3169 pf.top = df.top = of.top = cf.top = vf.top = mDockTop;
3170 pf.right = df.right = of.right = cf.right = vf.right = mDockRight;
John Spurlockc68d5772013-10-08 11:47:58 -04003171 // IM dock windows layout below the nav bar...
John Spurlock57beb3b2013-10-10 10:27:44 -04003172 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlockc68d5772013-10-08 11:47:58 -04003173 // ...with content insets above the nav bar
3174 cf.bottom = vf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003175 // IM dock windows always go to the bottom of the screen.
3176 attrs.gravity = Gravity.BOTTOM;
3177 mDockLayer = win.getSurfaceLayer();
3178 } else {
John Spurlock46646232013-09-30 22:32:42 -04003179
3180 // Default policy decor for the default display
3181 dcf.left = mSystemLeft;
3182 dcf.top = mSystemTop;
3183 dcf.right = mSystemRight;
3184 dcf.bottom = mSystemBottom;
John Spurlockbd957402013-10-03 11:38:39 -04003185 final boolean inheritTranslucentDecor = (attrs.privateFlags
3186 & WindowManager.LayoutParams.PRIVATE_FLAG_INHERIT_TRANSLUCENT_DECOR) != 0;
John Spurlock65567d42013-10-08 10:08:32 -04003187 final boolean isAppWindow =
3188 attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW &&
3189 attrs.type <= WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
3190 final boolean topAtRest =
3191 win == mTopFullscreenOpaqueWindowState && !win.isAnimatingLw();
3192 if (isAppWindow && !inheritTranslucentDecor && !topAtRest) {
John Spurlockbd957402013-10-03 11:38:39 -04003193 if ((sysUiFl & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0
3194 && (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0
Adrian Roosea562512014-05-05 13:33:03 +02003195 && (fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) == 0
3196 && (fl & WindowManager.LayoutParams.
3197 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04003198 // Ensure policy decor includes status bar
3199 dcf.top = mStableTop;
3200 }
John Spurlockbd957402013-10-03 11:38:39 -04003201 if ((fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) == 0
Adrian Roosea562512014-05-05 13:33:03 +02003202 && (sysUiFl & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0
3203 && (fl & WindowManager.LayoutParams.
3204 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04003205 // Ensure policy decor includes navigation bar
3206 dcf.bottom = mStableBottom;
3207 dcf.right = mStableRight;
3208 }
3209 }
3210
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003211 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
3212 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
RoboErik8a2cfc32014-05-16 11:19:38 -07003213 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003214 + "): IN_SCREEN, INSET_DECOR");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003215 // This is the case for a normal activity window: we want it
3216 // to cover all of the screen space, and it can take care of
3217 // moving its contents to account for screen decorations that
3218 // intrude into that space.
3219 if (attached != null) {
3220 // If this window is attached to another, our display
3221 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003222 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003223 } else {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003224 if (attrs.type == TYPE_STATUS_BAR_PANEL
3225 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Joe Onorato29fc2c92010-11-24 10:26:50 -08003226 // Status bar panels are the only windows who can go on top of
3227 // the status bar. They are protected by the STATUS_BAR_SERVICE
3228 // permission, so they have the same privileges as the status
3229 // bar itself.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003230 //
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003231 // However, they should still dodge the navigation bar if it exists.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003232
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003233 pf.left = df.left = of.left = hasNavBar
3234 ? mDockLeft : mUnrestrictedScreenLeft;
3235 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3236 pf.right = df.right = of.right = hasNavBar
3237 ? mRestrictedScreenLeft+mRestrictedScreenWidth
3238 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3239 pf.bottom = df.bottom = of.bottom = hasNavBar
3240 ? mRestrictedScreenTop+mRestrictedScreenHeight
3241 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003242
Craig Mautnereda67292013-04-28 13:50:14 -07003243 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003244 "Laying out status bar window: (%d,%d - %d,%d)",
3245 pf.left, pf.top, pf.right, pf.bottom));
John Spurlock46646232013-09-30 22:32:42 -04003246 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08003247 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3248 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3249 // Asking to layout into the overscan region, so give it that pure
3250 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003251 pf.left = df.left = of.left = mOverscanScreenLeft;
3252 pf.top = df.top = of.top = mOverscanScreenTop;
3253 pf.right = df.right = of.right = mOverscanScreenLeft + mOverscanScreenWidth;
3254 pf.bottom = df.bottom = of.bottom = mOverscanScreenTop
3255 + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003256 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003257 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003258 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3259 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003260 // Asking for layout as if the nav bar is hidden, lets the
Dianne Hackbornc652de82013-02-15 16:32:56 -08003261 // application extend into the unrestricted overscan screen area. We
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003262 // only do this for application windows to ensure no window that
3263 // can be above the nav bar can do this.
Dianne Hackborn313440842013-02-19 19:22:59 -08003264 pf.left = df.left = mOverscanScreenLeft;
3265 pf.top = df.top = mOverscanScreenTop;
3266 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
3267 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003268 // We need to tell the app about where the frame inside the overscan
3269 // is, so it can inset its content by that amount -- it didn't ask
3270 // to actually extend itself into the overscan region.
3271 of.left = mUnrestrictedScreenLeft;
3272 of.top = mUnrestrictedScreenTop;
3273 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3274 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003275 } else {
Dianne Hackborn313440842013-02-19 19:22:59 -08003276 pf.left = df.left = mRestrictedOverscanScreenLeft;
3277 pf.top = df.top = mRestrictedOverscanScreenTop;
3278 pf.right = df.right = mRestrictedOverscanScreenLeft
3279 + mRestrictedOverscanScreenWidth;
3280 pf.bottom = df.bottom = mRestrictedOverscanScreenTop
3281 + mRestrictedOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003282 // We need to tell the app about where the frame inside the overscan
3283 // is, so it can inset its content by that amount -- it didn't ask
3284 // to actually extend itself into the overscan region.
3285 of.left = mUnrestrictedScreenLeft;
3286 of.top = mUnrestrictedScreenTop;
3287 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3288 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003289 }
Craig Mautner69b08182012-09-05 13:07:13 -07003290
John Spurlock46646232013-09-30 22:32:42 -04003291 if ((fl & FLAG_FULLSCREEN) == 0) {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003292 if (win.isVoiceInteraction()) {
3293 cf.left = mVoiceContentLeft;
3294 cf.top = mVoiceContentTop;
3295 cf.right = mVoiceContentRight;
3296 cf.bottom = mVoiceContentBottom;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003297 } else {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003298 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
3299 cf.left = mDockLeft;
3300 cf.top = mDockTop;
3301 cf.right = mDockRight;
3302 cf.bottom = mDockBottom;
3303 } else {
3304 cf.left = mContentLeft;
3305 cf.top = mContentTop;
3306 cf.right = mContentRight;
3307 cf.bottom = mContentBottom;
3308 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003309 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003310 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003311 // Full screen windows are always given a layout that is as if the
3312 // status bar and other transient decors are gone. This is to avoid
3313 // bad states when moving from a window that is not hding the
3314 // status bar to one that is.
3315 cf.left = mRestrictedScreenLeft;
3316 cf.top = mRestrictedScreenTop;
3317 cf.right = mRestrictedScreenLeft + mRestrictedScreenWidth;
3318 cf.bottom = mRestrictedScreenTop + mRestrictedScreenHeight;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003319 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003320 applyStableConstraints(sysUiFl, fl, cf);
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003321 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3322 vf.left = mCurLeft;
3323 vf.top = mCurTop;
3324 vf.right = mCurRight;
3325 vf.bottom = mCurBottom;
3326 } else {
3327 vf.set(cf);
3328 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003329 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003330 } else if ((fl & FLAG_LAYOUT_IN_SCREEN) != 0 || (sysUiFl
3331 & (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
3332 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)) != 0) {
Craig Mautnereda67292013-04-28 13:50:14 -07003333 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3334 "): IN_SCREEN");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003335 // A window that has requested to fill the entire screen just
3336 // gets everything, period.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003337 if (attrs.type == TYPE_STATUS_BAR_PANEL
3338 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003339 pf.left = df.left = of.left = cf.left = hasNavBar
3340 ? mDockLeft : mUnrestrictedScreenLeft;
3341 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
3342 pf.right = df.right = of.right = cf.right = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003343 ? mRestrictedScreenLeft+mRestrictedScreenWidth
Dianne Hackbornc652de82013-02-15 16:32:56 -08003344 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003345 pf.bottom = df.bottom = of.bottom = cf.bottom = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003346 ? mRestrictedScreenTop+mRestrictedScreenHeight
Dianne Hackbornc652de82013-02-15 16:32:56 -08003347 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07003348 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler36412a72011-08-04 09:35:13 -04003349 "Laying out IN_SCREEN status bar window: (%d,%d - %d,%d)",
3350 pf.left, pf.top, pf.right, pf.bottom));
Jim Millere898ac52012-04-06 17:10:57 -07003351 } else if (attrs.type == TYPE_NAVIGATION_BAR
3352 || attrs.type == TYPE_NAVIGATION_BAR_PANEL) {
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003353 // The navigation bar has Real Ultimate Power.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003354 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3355 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3356 pf.right = df.right = of.right = mUnrestrictedScreenLeft
3357 + mUnrestrictedScreenWidth;
3358 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop
3359 + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07003360 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003361 "Laying out navigation bar window: (%d,%d - %d,%d)",
3362 pf.left, pf.top, pf.right, pf.bottom));
Dianne Hackborn01011c32012-02-21 13:54:21 -08003363 } else if ((attrs.type == TYPE_SECURE_SYSTEM_OVERLAY
3364 || attrs.type == TYPE_BOOT_PROGRESS)
Jeff Brownbfcb60a2011-09-08 18:51:14 -07003365 && ((fl & FLAG_FULLSCREEN) != 0)) {
3366 // Fullscreen secure system overlays get what they ask for.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003367 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3368 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3369 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
3370 + mOverscanScreenWidth;
3371 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
3372 + mOverscanScreenHeight;
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07003373 } else if (attrs.type == TYPE_BOOT_PROGRESS
3374 || attrs.type == TYPE_UNIVERSE_BACKGROUND) {
Dianne Hackborn01011c32012-02-21 13:54:21 -08003375 // Boot progress screen always covers entire display.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003376 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3377 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3378 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
3379 + mOverscanScreenWidth;
3380 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
3381 + mOverscanScreenHeight;
John Spurlockef4adae2013-08-26 17:58:58 -04003382 } else if (attrs.type == TYPE_WALLPAPER) {
3383 // The wallpaper also has Real Ultimate Power.
3384 pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft;
3385 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003386 pf.right = df.right = of.right = cf.right
John Spurlockef4adae2013-08-26 17:58:58 -04003387 = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003388 pf.bottom = df.bottom = of.bottom = cf.bottom
John Spurlockef4adae2013-08-26 17:58:58 -04003389 = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlock46646232013-09-30 22:32:42 -04003390 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08003391 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3392 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3393 // Asking to layout into the overscan region, so give it that pure
3394 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003395 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3396 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3397 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08003398 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003399 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003400 = mOverscanScreenTop + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003401 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003402 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Craig Mautnerbeac1062014-06-03 14:38:57 -07003403 && (attrs.type == TYPE_STATUS_BAR
3404 || attrs.type == TYPE_TOAST
John Spurlock34e13d92013-08-10 06:52:28 -04003405 || (attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3406 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW))) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003407 // Asking for layout as if the nav bar is hidden, lets the
3408 // application extend into the unrestricted screen area. We
John Spurlock34e13d92013-08-10 06:52:28 -04003409 // only do this for application windows (or toasts) to ensure no window that
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003410 // can be above the nav bar can do this.
3411 // XXX This assumes that an app asking for this will also
3412 // ask for layout in only content. We can't currently figure out
3413 // what the screen would be if only laying out to hide the nav bar.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003414 pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft;
3415 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
3416 pf.right = df.right = of.right = cf.right = mUnrestrictedScreenLeft
3417 + mUnrestrictedScreenWidth;
3418 pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop
3419 + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003420 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003421 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
3422 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
3423 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
3424 + mRestrictedScreenWidth;
3425 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
3426 + mRestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003427 }
Craig Mautner69b08182012-09-05 13:07:13 -07003428
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003429 applyStableConstraints(sysUiFl, fl, cf);
Craig Mautner69b08182012-09-05 13:07:13 -07003430
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003431 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3432 vf.left = mCurLeft;
3433 vf.top = mCurTop;
3434 vf.right = mCurRight;
3435 vf.bottom = mCurBottom;
3436 } else {
3437 vf.set(cf);
3438 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003439 } else if (attached != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07003440 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3441 "): attached to " + attached);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003442 // A child window should be placed inside of the same visible
3443 // frame that its parent had.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003444 setAttachedWindowFrames(win, fl, adjust, attached, false, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003445 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07003446 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3447 "): normal window");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003448 // Otherwise, a normal window must be placed inside the content
3449 // of all screen decorations.
Dianne Hackborna239c842011-06-01 12:28:20 -07003450 if (attrs.type == TYPE_STATUS_BAR_PANEL) {
3451 // Status bar panels are the only windows who can go on top of
3452 // the status bar. They are protected by the STATUS_BAR_SERVICE
3453 // permission, so they have the same privileges as the status
3454 // bar itself.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003455 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
3456 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
3457 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
3458 + mRestrictedScreenWidth;
3459 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
3460 + mRestrictedScreenHeight;
John Spurlock414c1f02013-12-04 13:47:36 -05003461 } else if (attrs.type == TYPE_TOAST || attrs.type == TYPE_SYSTEM_ALERT
3462 || attrs.type == TYPE_VOLUME_OVERLAY) {
3463 // These dialogs are stable to interim decor changes.
John Spurlockbd957402013-10-03 11:38:39 -04003464 pf.left = df.left = of.left = cf.left = mStableLeft;
3465 pf.top = df.top = of.top = cf.top = mStableTop;
3466 pf.right = df.right = of.right = cf.right = mStableRight;
3467 pf.bottom = df.bottom = of.bottom = cf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003468 } else {
Dianne Hackborna239c842011-06-01 12:28:20 -07003469 pf.left = mContentLeft;
3470 pf.top = mContentTop;
3471 pf.right = mContentRight;
3472 pf.bottom = mContentBottom;
Dianne Hackborn20d94742014-05-29 18:35:45 -07003473 if (win.isVoiceInteraction()) {
3474 df.left = of.left = cf.left = mVoiceContentLeft;
3475 df.top = of.top = cf.top = mVoiceContentTop;
3476 df.right = of.right = cf.right = mVoiceContentRight;
3477 df.bottom = of.bottom = cf.bottom = mVoiceContentBottom;
3478 } else if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003479 df.left = of.left = cf.left = mDockLeft;
3480 df.top = of.top = cf.top = mDockTop;
3481 df.right = of.right = cf.right = mDockRight;
3482 df.bottom = of.bottom = cf.bottom = mDockBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07003483 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003484 df.left = of.left = cf.left = mContentLeft;
3485 df.top = of.top = cf.top = mContentTop;
3486 df.right = of.right = cf.right = mContentRight;
3487 df.bottom = of.bottom = cf.bottom = mContentBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07003488 }
3489 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3490 vf.left = mCurLeft;
3491 vf.top = mCurTop;
3492 vf.right = mCurRight;
3493 vf.bottom = mCurBottom;
3494 } else {
3495 vf.set(cf);
3496 }
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003497 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003498 }
3499 }
Craig Mautner69b08182012-09-05 13:07:13 -07003500
Craig Mautnerb816bed2013-07-23 10:26:17 -07003501 // TYPE_SYSTEM_ERROR is above the NavigationBar so it can't be allowed to extend over it.
3502 if ((fl & FLAG_LAYOUT_NO_LIMITS) != 0 && attrs.type != TYPE_SYSTEM_ERROR) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003503 df.left = df.top = of.left = of.top = cf.left = cf.top = vf.left = vf.top = -10000;
3504 df.right = df.bottom = of.right = of.bottom = cf.right = cf.bottom
3505 = vf.right = vf.bottom = 10000;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003506 }
3507
Craig Mautnereda67292013-04-28 13:50:14 -07003508 if (DEBUG_LAYOUT) Slog.v(TAG, "Compute frame " + attrs.getTitle()
The Android Open Source Project11267662009-03-18 17:39:47 -07003509 + ": sim=#" + Integer.toHexString(sim)
RoboErik8a2cfc32014-05-16 11:19:38 -07003510 + " attach=" + attached + " type=" + attrs.type
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003511 + String.format(" flags=0x%08x", fl)
The Android Open Source Project11267662009-03-18 17:39:47 -07003512 + " pf=" + pf.toShortString() + " df=" + df.toShortString()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003513 + " of=" + of.toShortString()
John Spurlock46646232013-09-30 22:32:42 -04003514 + " cf=" + cf.toShortString() + " vf=" + vf.toShortString()
3515 + " dcf=" + dcf.toShortString());
Craig Mautner69b08182012-09-05 13:07:13 -07003516
John Spurlock46646232013-09-30 22:32:42 -04003517 win.computeFrameLw(pf, df, of, cf, vf, dcf);
Craig Mautner69b08182012-09-05 13:07:13 -07003518
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003519 // Dock windows carve out the bottom of the screen, so normal windows
3520 // can't appear underneath them.
Craig Mautner8bd206b2012-10-03 10:32:02 -07003521 if (attrs.type == TYPE_INPUT_METHOD && win.isVisibleOrBehindKeyguardLw()
3522 && !win.getGivenInsetsPendingLw()) {
satok1bc0a492012-04-25 22:47:12 +09003523 setLastInputMethodWindowLw(null, null);
3524 offsetInputMethodWindowLw(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003525 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003526 if (attrs.type == TYPE_VOICE_INTERACTION && win.isVisibleOrBehindKeyguardLw()
3527 && !win.getGivenInsetsPendingLw()) {
3528 offsetVoiceInputWindowLw(win);
3529 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003530 }
3531
satok1bc0a492012-04-25 22:47:12 +09003532 private void offsetInputMethodWindowLw(WindowState win) {
3533 int top = win.getContentFrameLw().top;
3534 top += win.getGivenContentInsetsLw().top;
3535 if (mContentBottom > top) {
3536 mContentBottom = top;
3537 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003538 if (mVoiceContentBottom > top) {
3539 mVoiceContentBottom = top;
3540 }
satok1bc0a492012-04-25 22:47:12 +09003541 top = win.getVisibleFrameLw().top;
3542 top += win.getGivenVisibleInsetsLw().top;
3543 if (mCurBottom > top) {
3544 mCurBottom = top;
3545 }
Craig Mautnereda67292013-04-28 13:50:14 -07003546 if (DEBUG_LAYOUT) Slog.v(TAG, "Input method: mDockBottom="
satok1bc0a492012-04-25 22:47:12 +09003547 + mDockBottom + " mContentBottom="
3548 + mContentBottom + " mCurBottom=" + mCurBottom);
3549 }
3550
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003551 private void offsetVoiceInputWindowLw(WindowState win) {
3552 final int gravity = win.getAttrs().gravity;
3553 switch (gravity&((Gravity.AXIS_PULL_BEFORE|Gravity.AXIS_PULL_AFTER)
3554 << Gravity.AXIS_X_SHIFT)) {
3555 case Gravity.AXIS_PULL_BEFORE<<Gravity.AXIS_X_SHIFT: {
3556 int right = win.getContentFrameLw().right - win.getGivenContentInsetsLw().right;
3557 if (mVoiceContentLeft < right) {
3558 mVoiceContentLeft = right;
3559 }
3560 } break;
3561 case Gravity.AXIS_PULL_AFTER<<Gravity.AXIS_X_SHIFT: {
3562 int left = win.getContentFrameLw().left - win.getGivenContentInsetsLw().left;
3563 if (mVoiceContentRight < left) {
3564 mVoiceContentRight = left;
3565 }
3566 } break;
3567 }
3568 switch (gravity&((Gravity.AXIS_PULL_BEFORE|Gravity.AXIS_PULL_AFTER)
3569 << Gravity.AXIS_Y_SHIFT)) {
3570 case Gravity.AXIS_PULL_BEFORE<<Gravity.AXIS_Y_SHIFT: {
3571 int bottom = win.getContentFrameLw().bottom - win.getGivenContentInsetsLw().bottom;
3572 if (mVoiceContentTop < bottom) {
3573 mVoiceContentTop = bottom;
3574 }
3575 } break;
3576 case Gravity.AXIS_PULL_AFTER<<Gravity.AXIS_Y_SHIFT: {
3577 int top = win.getContentFrameLw().top - win.getGivenContentInsetsLw().top;
3578 if (mVoiceContentBottom < top) {
3579 mVoiceContentBottom = top;
3580 }
3581 } break;
3582 }
3583 }
3584
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003585 /** {@inheritDoc} */
Craig Mautner61ac6bb2012-02-02 17:29:33 -08003586 @Override
3587 public void finishLayoutLw() {
3588 return;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003589 }
3590
3591 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003592 @Override
Craig Mautner39834192012-09-02 07:47:24 -07003593 public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) {
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003594 mTopFullscreenOpaqueWindowState = null;
Craig Mautner2bc789b2014-03-19 19:48:38 -07003595 mAppsToBeHidden.clear();
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003596 mForceStatusBar = false;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003597 mForceStatusBarFromKeyguard = false;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08003598 mForcingShowNavBar = false;
3599 mForcingShowNavBarLayer = -1;
RoboErik8a2cfc32014-05-16 11:19:38 -07003600
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003601 mHideLockScreen = false;
3602 mAllowLockscreenWhenOn = false;
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003603 mDismissKeyguard = DISMISS_KEYGUARD_NONE;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003604 mShowingLockscreen = false;
3605 mShowingDream = false;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003606 }
3607
3608 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003609 @Override
Craig Mautner39834192012-09-02 07:47:24 -07003610 public void applyPostLayoutPolicyLw(WindowState win,
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003611 WindowManager.LayoutParams attrs) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07003612 if (DEBUG_LAYOUT) Slog.i(TAG, "Win " + win + ": isVisibleOrBehindKeyguardLw="
3613 + win.isVisibleOrBehindKeyguardLw());
John Spurlockc6d1c602014-01-17 15:22:06 -05003614 final int fl = PolicyControl.getWindowFlags(win, attrs);
John Spurlock414c1f02013-12-04 13:47:36 -05003615 if (mTopFullscreenOpaqueWindowState == null
3616 && win.isVisibleLw() && attrs.type == TYPE_INPUT_METHOD) {
3617 mForcingShowNavBar = true;
3618 mForcingShowNavBarLayer = win.getSurfaceLayer();
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08003619 }
Jorim Jaggiafd4a552014-04-08 15:13:05 +02003620 if (attrs.type == TYPE_STATUS_BAR && (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Jorim Jaggiafd4a552014-04-08 15:13:05 +02003621 mForceStatusBarFromKeyguard = true;
3622 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003623 if (mTopFullscreenOpaqueWindowState == null &&
Dianne Hackborn01b02a72012-01-12 14:05:03 -08003624 win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()) {
John Spurlockc6d1c602014-01-17 15:22:06 -05003625 if ((fl & FLAG_FORCE_NOT_FULLSCREEN) != 0) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003626 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003627 mForceStatusBarFromKeyguard = true;
3628 } else {
3629 mForceStatusBar = true;
3630 }
3631 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003632 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003633 mShowingLockscreen = true;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07003634 }
Craig Mautnerab55e522014-03-03 13:26:03 -08003635 boolean appWindow = attrs.type >= FIRST_APPLICATION_WINDOW
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003636 && attrs.type <= LAST_APPLICATION_WINDOW;
3637 if (attrs.type == TYPE_DREAM) {
Jeff Brownc8018eb2012-10-29 21:33:27 -07003638 // If the lockscreen was showing when the dream started then wait
3639 // for the dream to draw before hiding the lockscreen.
3640 if (!mDreamingLockscreen
3641 || (win.isVisibleLw() && win.hasDrawnLw())) {
3642 mShowingDream = true;
Craig Mautnerab55e522014-03-03 13:26:03 -08003643 appWindow = true;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003644 }
3645 }
Craig Mautnerab55e522014-03-03 13:26:03 -08003646
Craig Mautner00156ec2014-03-06 22:29:02 -08003647 final boolean showWhenLocked = (fl & FLAG_SHOW_WHEN_LOCKED) != 0;
Craig Mautner74ee9382014-04-01 15:20:16 -07003648 final boolean dismissKeyguard = (fl & FLAG_DISMISS_KEYGUARD) != 0;
Craig Mautnerab55e522014-03-03 13:26:03 -08003649 if (appWindow) {
Craig Mautner4bdab6b2014-04-01 12:05:11 -07003650 if (showWhenLocked || (dismissKeyguard && !isKeyguardSecure())) {
Craig Mautner2bc789b2014-03-19 19:48:38 -07003651 mAppsToBeHidden.remove(win.getAppToken());
3652 } else {
3653 mAppsToBeHidden.add(win.getAppToken());
3654 }
Craig Mautnerab55e522014-03-03 13:26:03 -08003655 if (attrs.x == 0 && attrs.y == 0
3656 && attrs.width == WindowManager.LayoutParams.MATCH_PARENT
3657 && attrs.height == WindowManager.LayoutParams.MATCH_PARENT) {
3658 if (DEBUG_LAYOUT) Slog.v(TAG, "Fullscreen window: " + win);
3659 mTopFullscreenOpaqueWindowState = win;
Craig Mautner2bc789b2014-03-19 19:48:38 -07003660 if (mAppsToBeHidden.isEmpty()) {
Craig Mautnerda09ae32014-03-03 13:26:03 -08003661 if (showWhenLocked) {
3662 if (DEBUG_LAYOUT) Slog.v(TAG,
3663 "Setting mHideLockScreen to true by win " + win);
3664 mHideLockScreen = true;
3665 mForceStatusBarFromKeyguard = false;
3666 }
Craig Mautner4bdab6b2014-04-01 12:05:11 -07003667 if (dismissKeyguard && mDismissKeyguard == DISMISS_KEYGUARD_NONE) {
Craig Mautnerda09ae32014-03-03 13:26:03 -08003668 if (DEBUG_LAYOUT) Slog.v(TAG,
3669 "Setting mDismissKeyguard true by win " + win);
3670 mDismissKeyguard = mWinDismissingKeyguard == win ?
3671 DISMISS_KEYGUARD_CONTINUE : DISMISS_KEYGUARD_START;
3672 mWinDismissingKeyguard = win;
3673 mForceStatusBarFromKeyguard = mShowingLockscreen && isKeyguardSecure();
3674 }
Craig Mautnerab55e522014-03-03 13:26:03 -08003675 }
Craig Mautner00156ec2014-03-06 22:29:02 -08003676 if ((fl & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) {
Craig Mautnerab55e522014-03-03 13:26:03 -08003677 mAllowLockscreenWhenOn = true;
3678 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003679 }
3680 }
3681 }
3682 }
3683
3684 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003685 @Override
Craig Mautner39834192012-09-02 07:47:24 -07003686 public int finishPostLayoutPolicyLw() {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003687 int changes = 0;
Joe Onorato93056472010-09-10 10:30:46 -04003688 boolean topIsFullscreen = false;
Daniel Sandlere02d8082010-10-08 15:13:22 -04003689
3690 final WindowManager.LayoutParams lp = (mTopFullscreenOpaqueWindowState != null)
3691 ? mTopFullscreenOpaqueWindowState.getAttrs()
3692 : null;
3693
Jeff Brownc8018eb2012-10-29 21:33:27 -07003694 // If we are not currently showing a dream then remember the current
3695 // lockscreen state. We will use this to determine whether the dream
3696 // started while the lockscreen was showing and remember this state
3697 // while the dream is showing.
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003698 if (!mShowingDream) {
3699 mDreamingLockscreen = mShowingLockscreen;
3700 }
3701
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003702 if (mStatusBar != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07003703 if (DEBUG_LAYOUT) Slog.i(TAG, "force=" + mForceStatusBar
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003704 + " forcefkg=" + mForceStatusBarFromKeyguard
Dianne Hackbornd70bc2f2009-10-06 23:25:51 -07003705 + " top=" + mTopFullscreenOpaqueWindowState);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003706 if (mForceStatusBar || mForceStatusBarFromKeyguard) {
Craig Mautnereda67292013-04-28 13:50:14 -07003707 if (DEBUG_LAYOUT) Slog.v(TAG, "Showing status bar: forced");
John Spurlock27735a42013-08-14 17:57:38 -04003708 if (mStatusBarController.setBarShowingLw(true)) {
3709 changes |= FINISH_LAYOUT_REDO_LAYOUT;
3710 }
Craig Mautner81defc72013-10-29 11:10:42 -07003711 // Maintain fullscreen layout until incoming animation is complete.
3712 topIsFullscreen = mTopIsFullscreen && mStatusBar.isAnimatingLw();
John Spurlockf92b6162013-11-11 15:01:16 -05003713 // Transient status bar on the lockscreen is not allowed
3714 if (mForceStatusBarFromKeyguard && mStatusBarController.isTransientShowing()) {
3715 mStatusBarController.updateVisibilityLw(false /*transientAllowed*/,
3716 mLastSystemUiFlags, mLastSystemUiFlags);
3717 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003718 } else if (mTopFullscreenOpaqueWindowState != null) {
John Spurlockc6d1c602014-01-17 15:22:06 -05003719 final int fl = PolicyControl.getWindowFlags(null, lp);
Joe Onorato93056472010-09-10 10:30:46 -04003720 if (localLOGV) {
Craig Mautnereda67292013-04-28 13:50:14 -07003721 Slog.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw()
Joe Onorato93056472010-09-10 10:30:46 -04003722 + " shown frame: " + mTopFullscreenOpaqueWindowState.getShownFrameLw());
Craig Mautnereda67292013-04-28 13:50:14 -07003723 Slog.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs()
John Spurlockc6d1c602014-01-17 15:22:06 -05003724 + " lp.flags=0x" + Integer.toHexString(fl));
Joe Onorato93056472010-09-10 10:30:46 -04003725 }
John Spurlockc6d1c602014-01-17 15:22:06 -05003726 topIsFullscreen = (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003727 || (mLastSystemUiFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
Joe Onorato93056472010-09-10 10:30:46 -04003728 // The subtle difference between the window for mTopFullscreenOpaqueWindowState
3729 // and mTopIsFullscreen is that that mTopIsFullscreen is set only if the window
3730 // has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the
3731 // case though.
John Spurlock27735a42013-08-14 17:57:38 -04003732 if (mStatusBarController.isTransientShowing()) {
3733 if (mStatusBarController.setBarShowingLw(true)) {
John Spurlock32beb2c2013-03-11 10:16:47 -04003734 changes |= FINISH_LAYOUT_REDO_LAYOUT;
3735 }
3736 } else if (topIsFullscreen) {
Craig Mautnereda67292013-04-28 13:50:14 -07003737 if (DEBUG_LAYOUT) Slog.v(TAG, "** HIDING status bar");
John Spurlock27735a42013-08-14 17:57:38 -04003738 if (mStatusBarController.setBarShowingLw(false)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003739 changes |= FINISH_LAYOUT_REDO_LAYOUT;
Craig Mautnereda67292013-04-28 13:50:14 -07003740 } else {
Craig Mautnerc5a6e442013-06-05 17:22:35 -07003741 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar already hiding");
Daniel Sandler40427442010-07-16 11:44:52 -04003742 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003743 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07003744 if (DEBUG_LAYOUT) Slog.v(TAG, "** SHOWING status bar: top is not fullscreen");
John Spurlock27735a42013-08-14 17:57:38 -04003745 if (mStatusBarController.setBarShowingLw(true)) {
3746 changes |= FINISH_LAYOUT_REDO_LAYOUT;
3747 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003748 }
3749 }
3750 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04003751
Craig Mautner81defc72013-10-29 11:10:42 -07003752 if (mTopIsFullscreen != topIsFullscreen) {
3753 if (!topIsFullscreen) {
3754 // Force another layout when status bar becomes fully shown.
3755 changes |= FINISH_LAYOUT_REDO_LAYOUT;
3756 }
3757 mTopIsFullscreen = topIsFullscreen;
3758 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04003759
Craig Mautner39834192012-09-02 07:47:24 -07003760 // Hide the key guard if a visible window explicitly specifies that it wants to be
3761 // displayed when the screen is locked.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01003762 if (mKeyguardDelegate != null && mStatusBar != null) {
3763 if (localLOGV) Slog.v(TAG, "finishPostLayoutPolicyLw: mHideKeyguard="
3764 + mHideLockScreen);
3765 if (mDismissKeyguard != DISMISS_KEYGUARD_NONE && !isKeyguardSecure()) {
3766 mKeyguardHidden = true;
3767 if (processKeyguardSetHiddenResultLw(mKeyguardDelegate.setOccluded(true))) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003768 changes |= FINISH_LAYOUT_REDO_LAYOUT
3769 | FINISH_LAYOUT_REDO_CONFIG
3770 | FINISH_LAYOUT_REDO_WALLPAPER;
3771 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01003772 if (mKeyguardDelegate.isShowing()) {
3773 mHandler.post(new Runnable() {
3774 @Override
3775 public void run() {
3776 mKeyguardDelegate.keyguardDone(false, false);
3777 }
3778 });
3779 }
3780 } else if (mHideLockScreen) {
3781 mKeyguardHidden = true;
3782 if (processKeyguardSetHiddenResultLw(mKeyguardDelegate.setOccluded(true))) {
3783 changes |= FINISH_LAYOUT_REDO_LAYOUT
3784 | FINISH_LAYOUT_REDO_CONFIG
3785 | FINISH_LAYOUT_REDO_WALLPAPER;
3786 }
3787 } else if (mDismissKeyguard != DISMISS_KEYGUARD_NONE) {
3788 // This is the case of keyguard isSecure() and not mHideLockScreen.
3789 if (mDismissKeyguard == DISMISS_KEYGUARD_START) {
3790 // Only launch the next keyguard unlock window once per window.
3791 mKeyguardHidden = false;
3792 if (processKeyguardSetHiddenResultLw(mKeyguardDelegate.setOccluded(false))) {
3793 changes |= FINISH_LAYOUT_REDO_LAYOUT
3794 | FINISH_LAYOUT_REDO_CONFIG
3795 | FINISH_LAYOUT_REDO_WALLPAPER;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003796 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01003797 mHandler.post(new Runnable() {
3798 @Override
3799 public void run() {
3800 mKeyguardDelegate.dismiss();
3801 }
3802 });
3803 }
3804 } else {
3805 mWinDismissingKeyguard = null;
3806 mKeyguardHidden = false;
3807 if (processKeyguardSetHiddenResultLw(mKeyguardDelegate.setOccluded(false))) {
3808 changes |= FINISH_LAYOUT_REDO_LAYOUT
3809 | FINISH_LAYOUT_REDO_CONFIG
3810 | FINISH_LAYOUT_REDO_WALLPAPER;
3811 }
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -07003812 }
3813 }
Joe Onorato664644d2011-01-23 17:53:23 -08003814
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003815 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003816 // If the navigation bar has been hidden or shown, we need to do another
3817 // layout pass to update that window.
3818 changes |= FINISH_LAYOUT_REDO_LAYOUT;
3819 }
Joe Onorato664644d2011-01-23 17:53:23 -08003820
Mike Lockwood28569302010-01-28 11:54:40 -05003821 // update since mAllowLockscreenWhenOn might have changed
3822 updateLockScreenTimeout();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003823 return changes;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003824 }
3825
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003826 /**
Jorim Jaggi5cf17872014-03-26 18:31:48 +01003827 * Processes the result code of {@link IKeyguardService#setOccluded}. This is needed because we
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003828 * immediately need to put the wallpaper directly behind the Keyguard when a window with flag
3829 * {@link android.view.WindowManager.LayoutParams#FLAG_SHOW_WHEN_LOCKED} gets dismissed. If we
3830 * would wait for Keyguard to change the flags, that would be running asynchronously and thus be
3831 * too late so the user might see the window behind.
3832 *
Jorim Jaggi5cf17872014-03-26 18:31:48 +01003833 * @param setHiddenResult The result code from {@link IKeyguardService#setOccluded}.
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003834 * @return Whether the flags have changed and we have to redo the layout.
3835 */
3836 private boolean processKeyguardSetHiddenResultLw(int setHiddenResult) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01003837 if (setHiddenResult
3838 == IKeyguardServiceConstants.KEYGUARD_SERVICE_SET_OCCLUDED_RESULT_SET_FLAGS) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003839 mStatusBar.getAttrs().privateFlags |= PRIVATE_FLAG_KEYGUARD;
3840 mStatusBar.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
3841 return true;
3842 } else if (setHiddenResult
Jorim Jaggi5cf17872014-03-26 18:31:48 +01003843 == IKeyguardServiceConstants.KEYGUARD_SERVICE_SET_OCCLUDED_RESULT_UNSET_FLAGS) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003844 mStatusBar.getAttrs().privateFlags &= ~PRIVATE_FLAG_KEYGUARD;
3845 mStatusBar.getAttrs().flags &= ~FLAG_SHOW_WALLPAPER;
3846 return true;
3847 } else {
3848 return false;
3849 }
3850 }
3851
3852 private boolean isStatusBarKeyguard() {
3853 return mStatusBar != null
3854 && (mStatusBar.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
3855 }
3856
Dianne Hackborn08743722009-12-21 12:16:51 -08003857 public boolean allowAppAnimationsLw() {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003858 if (isStatusBarKeyguard() || mShowingDream) {
Craig Mautner28816302013-10-10 20:31:00 -07003859 // If keyguard or dreams is currently visible, no reason to animate behind it.
Dianne Hackborn08743722009-12-21 12:16:51 -08003860 return false;
3861 }
Dianne Hackborn08743722009-12-21 12:16:51 -08003862 return true;
3863 }
3864
Dianne Hackborndf89e652011-10-06 22:35:11 -07003865 public int focusChangedLw(WindowState lastFocus, WindowState newFocus) {
Joe Onorato664644d2011-01-23 17:53:23 -08003866 mFocusedWindow = newFocus;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003867 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003868 // If the navigation bar has been hidden or shown, we need to do another
3869 // layout pass to update that window.
3870 return FINISH_LAYOUT_REDO_LAYOUT;
3871 }
3872 return 0;
Joe Onorato664644d2011-01-23 17:53:23 -08003873 }
3874
Dianne Hackborn0ecadf72009-03-31 18:00:37 -07003875 /** {@inheritDoc} */
Jeff Brown46b9ac02010-04-22 18:58:52 -07003876 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
3877 // lid changed state
Jeff Brownc458ce92012-04-30 14:58:40 -07003878 final int newLidState = lidOpen ? LID_OPEN : LID_CLOSED;
3879 if (newLidState == mLidState) {
3880 return;
3881 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07003882
Jeff Brownc458ce92012-04-30 14:58:40 -07003883 mLidState = newLidState;
3884 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07003885 updateRotation(true);
Jeff Brownc458ce92012-04-30 14:58:40 -07003886
3887 if (lidOpen) {
Jim Millere51cf7ae2013-06-25 18:31:56 -07003888 mPowerManager.wakeUp(SystemClock.uptimeMillis());
Jeff Brownc458ce92012-04-30 14:58:40 -07003889 } else if (!mLidControlsSleep) {
Jeff Brown96307042012-07-27 15:51:34 -07003890 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
Jeff Brown46b9ac02010-04-22 18:58:52 -07003891 }
3892 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003893
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08003894 void setHdmiPlugged(boolean plugged) {
3895 if (mHdmiPlugged != plugged) {
3896 mHdmiPlugged = plugged;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003897 updateRotation(true, true);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08003898 Intent intent = new Intent(ACTION_HDMI_PLUGGED);
Joe Onoratodc100302011-01-11 17:07:41 -08003899 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08003900 intent.putExtra(EXTRA_HDMI_PLUGGED_STATE, plugged);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07003901 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08003902 }
3903 }
3904
Joe Onoratoea495d42011-04-06 11:41:11 -07003905 void initializeHdmiState() {
Joe Onorato7ba631f2011-05-04 15:28:00 -07003906 boolean plugged = false;
Joe Onoratoea495d42011-04-06 11:41:11 -07003907 // watch for HDMI plug messages if the hdmi switch exists
3908 if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) {
3909 mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi");
3910
Joe Onoratoea495d42011-04-06 11:41:11 -07003911 final String filename = "/sys/class/switch/hdmi/state";
3912 FileReader reader = null;
3913 try {
3914 reader = new FileReader(filename);
3915 char[] buf = new char[15];
3916 int n = reader.read(buf);
3917 if (n > 1) {
3918 plugged = 0 != Integer.parseInt(new String(buf, 0, n-1));
3919 }
3920 } catch (IOException ex) {
3921 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
3922 } catch (NumberFormatException ex) {
3923 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
3924 } finally {
3925 if (reader != null) {
3926 try {
3927 reader.close();
3928 } catch (IOException ex) {
3929 }
Joe Onoratodc100302011-01-11 17:07:41 -08003930 }
3931 }
3932 }
Joe Onorato7ba631f2011-05-04 15:28:00 -07003933 // This dance forces the code in setHdmiPlugged to run.
3934 // Always do this so the sticky intent is stuck (to false) if there is no hdmi.
3935 mHdmiPlugged = !plugged;
3936 setHdmiPlugged(!mHdmiPlugged);
Joe Onoratodc100302011-01-11 17:07:41 -08003937 }
3938
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003939 /**
Jean-Michel Trivifca1e602013-10-10 18:12:59 -07003940 * @return Whether music is being played right now "locally" (e.g. on the device's speakers
3941 * or wired headphones) or "remotely" (e.g. on a device using the Cast protocol and
3942 * controlled by this device, or through remote submix).
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003943 */
3944 boolean isMusicActive() {
Eric Laurent413cb9d2009-07-17 11:52:43 -07003945 final AudioManager am = (AudioManager)mContext.getSystemService(Context.AUDIO_SERVICE);
3946 if (am == null) {
3947 Log.w(TAG, "isMusicActive: couldn't get AudioManager reference");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003948 return false;
3949 }
Jean-Michel Trivifca1e602013-10-10 18:12:59 -07003950 return am.isLocalOrRemoteMusicActive();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003951 }
3952
3953 /**
3954 * Tell the audio service to adjust the volume appropriate to the event.
3955 * @param keycode
3956 */
Mike Lockwooda53e3812009-09-25 10:51:39 -04003957 void handleVolumeKey(int stream, int keycode) {
Jeff Brown4d396052010-10-29 21:50:21 -07003958 IAudioService audioService = getAudioService();
3959 if (audioService == null) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003960 return;
3961 }
3962 try {
Jean-Michel Trivifca1e602013-10-10 18:12:59 -07003963 // when audio is playing locally, we shouldn't have to hold a wake lock
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003964 // during the call, but we do it as a precaution for the rare possibility
Jean-Michel Trivifca1e602013-10-10 18:12:59 -07003965 // that the music stops right before we call this.
3966 // Otherwise we might also be in a remote playback case.
Jeff Brownb0418da2010-11-01 15:24:01 -07003967 // TODO: Actually handle MUTE.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003968 mBroadcastWakeLock.acquire();
Jean-Michel Trivifca1e602013-10-10 18:12:59 -07003969 if (stream == AudioSystem.STREAM_MUSIC) {
3970 audioService.adjustLocalOrRemoteStreamVolume(stream,
3971 keycode == KeyEvent.KEYCODE_VOLUME_UP
3972 ? AudioManager.ADJUST_RAISE
3973 : AudioManager.ADJUST_LOWER,
3974 mContext.getOpPackageName());
3975 } else {
3976 audioService.adjustStreamVolume(stream,
3977 keycode == KeyEvent.KEYCODE_VOLUME_UP
3978 ? AudioManager.ADJUST_RAISE
3979 : AudioManager.ADJUST_LOWER,
3980 0,
3981 mContext.getOpPackageName());
3982 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003983 } catch (RemoteException e) {
Jean-Michel Trivifca1e602013-10-10 18:12:59 -07003984 Log.w(TAG, "IAudioService.adjust*StreamVolume() threw RemoteException " + e);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003985 } finally {
3986 mBroadcastWakeLock.release();
3987 }
3988 }
Jeff Brown4d396052010-10-29 21:50:21 -07003989
Dianne Hackbornc0e3f242011-08-19 14:19:10 -07003990 final Object mScreenshotLock = new Object();
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07003991 ServiceConnection mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07003992
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003993 final Runnable mScreenshotTimeout = new Runnable() {
3994 @Override public void run() {
3995 synchronized (mScreenshotLock) {
3996 if (mScreenshotConnection != null) {
3997 mContext.unbindService(mScreenshotConnection);
3998 mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07003999 }
Winson Chung9112ec32011-06-27 13:15:32 -07004000 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004001 }
4002 };
4003
4004 // Assume this is called from the Handler thread.
4005 private void takeScreenshot() {
4006 synchronized (mScreenshotLock) {
4007 if (mScreenshotConnection != null) {
4008 return;
4009 }
4010 ComponentName cn = new ComponentName("com.android.systemui",
4011 "com.android.systemui.screenshot.TakeScreenshotService");
4012 Intent intent = new Intent();
4013 intent.setComponent(cn);
4014 ServiceConnection conn = new ServiceConnection() {
4015 @Override
4016 public void onServiceConnected(ComponentName name, IBinder service) {
4017 synchronized (mScreenshotLock) {
4018 if (mScreenshotConnection != this) {
4019 return;
4020 }
4021 Messenger messenger = new Messenger(service);
4022 Message msg = Message.obtain(null, 1);
4023 final ServiceConnection myConn = this;
4024 Handler h = new Handler(mHandler.getLooper()) {
4025 @Override
4026 public void handleMessage(Message msg) {
4027 synchronized (mScreenshotLock) {
4028 if (mScreenshotConnection == myConn) {
4029 mContext.unbindService(mScreenshotConnection);
4030 mScreenshotConnection = null;
4031 mHandler.removeCallbacks(mScreenshotTimeout);
4032 }
4033 }
4034 }
4035 };
4036 msg.replyTo = new Messenger(h);
Winson Chunga63bb842011-10-17 10:26:28 -07004037 msg.arg1 = msg.arg2 = 0;
4038 if (mStatusBar != null && mStatusBar.isVisibleLw())
4039 msg.arg1 = 1;
4040 if (mNavigationBar != null && mNavigationBar.isVisibleLw())
4041 msg.arg2 = 1;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004042 try {
4043 messenger.send(msg);
4044 } catch (RemoteException e) {
4045 }
4046 }
4047 }
4048 @Override
4049 public void onServiceDisconnected(ComponentName name) {}
4050 };
Amith Yamasani27b89e62013-01-16 12:30:11 -08004051 if (mContext.bindServiceAsUser(
4052 intent, conn, Context.BIND_AUTO_CREATE, UserHandle.CURRENT)) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004053 mScreenshotConnection = conn;
4054 mHandler.postDelayed(mScreenshotTimeout, 10000);
4055 }
4056 }
Winson Chung9112ec32011-06-27 13:15:32 -07004057 }
4058
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004059 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004060 @Override
Jeff Brown037c33e2014-04-09 00:31:55 -07004061 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) {
Jeff Brown96307042012-07-27 15:51:34 -07004062 if (!mSystemBooted) {
4063 // If we have not yet booted, don't let key events do anything.
4064 return 0;
4065 }
4066
Jeff Brown037c33e2014-04-09 00:31:55 -07004067 final boolean interactive = (policyFlags & FLAG_INTERACTIVE) != 0;
Jeff Brown1f245102010-11-18 20:53:46 -08004068 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
4069 final boolean canceled = event.isCanceled();
4070 final int keyCode = event.getKeyCode();
Jeff Browne20c9e02010-10-11 14:20:19 -07004071
Jeff Brown3122e442010-10-11 23:32:49 -07004072 final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0;
Jeff Brown3122e442010-10-11 23:32:49 -07004073
Mike Lockwoodc72b15f2009-11-28 20:58:22 -05004074 // If screen is off then we treat the case where the keyguard is open but hidden
4075 // the same as if it were open and in front.
4076 // This will prevent any keys other than the power button from waking the screen
4077 // when the keyguard is hidden by another activity.
Jim Miller5ecd8112013-01-09 18:50:26 -08004078 final boolean keyguardActive = (mKeyguardDelegate == null ? false :
Jeff Brown037c33e2014-04-09 00:31:55 -07004079 (interactive ?
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004080 mKeyguardDelegate.isShowingAndNotOccluded() :
Jim Miller5ecd8112013-01-09 18:50:26 -08004081 mKeyguardDelegate.isShowing()));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004082
Jeff Brown40013652012-05-16 21:22:36 -07004083 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004084 Log.d(TAG, "interceptKeyTq keycode=" + keyCode
Jeff Brown037c33e2014-04-09 00:31:55 -07004085 + " interactive=" + interactive + " keyguardActive=" + keyguardActive
Jeff Brown26875502014-01-30 21:47:47 -08004086 + " policyFlags=" + Integer.toHexString(policyFlags));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004087 }
4088
Jeff Brown98392ef2011-09-12 18:24:59 -07004089 if (down && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0
4090 && event.getRepeatCount() == 0) {
Jeff Brown4d396052010-10-29 21:50:21 -07004091 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
4092 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004093
Jeff Brown037c33e2014-04-09 00:31:55 -07004094 // Basic policy based on interactive state.
Jeff Brown4d396052010-10-29 21:50:21 -07004095 int result;
Michael Wright337d9d22014-04-22 15:03:48 -07004096 boolean isWakeKey = (policyFlags & WindowManagerPolicy.FLAG_WAKE) != 0
4097 || event.isWakeKey();
Jeff Brown037c33e2014-04-09 00:31:55 -07004098 if (interactive || (isInjected && !isWakeKey)) {
Jeff Brown4d396052010-10-29 21:50:21 -07004099 // When the screen is on or if the key is injected pass the key to the application.
4100 result = ACTION_PASS_TO_USER;
4101 } else {
4102 // When the screen is off and the key is not injected, determine whether
4103 // to wake the device but don't pass the key to the application.
4104 result = 0;
Jeff Brown26875502014-01-30 21:47:47 -08004105 if (isWakeKey && (!down || !isWakeKeyWhenScreenOff(keyCode))) {
4106 isWakeKey = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004107 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004108 }
4109
Justin Kohd378ad72013-04-01 12:18:26 -07004110 // If the key would be handled globally, just return the result, don't worry about special
4111 // key processing.
4112 if (mGlobalKeyManager.shouldHandleGlobalKey(keyCode, event)) {
4113 return result;
4114 }
4115
Jeff Brown4d396052010-10-29 21:50:21 -07004116 // Handle special keys.
4117 switch (keyCode) {
4118 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jeff Brownb0418da2010-11-01 15:24:01 -07004119 case KeyEvent.KEYCODE_VOLUME_UP:
4120 case KeyEvent.KEYCODE_VOLUME_MUTE: {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004121 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
4122 if (down) {
Jeff Brown037c33e2014-04-09 00:31:55 -07004123 if (interactive && !mVolumeDownKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004124 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
4125 mVolumeDownKeyTriggered = true;
4126 mVolumeDownKeyTime = event.getDownTime();
4127 mVolumeDownKeyConsumedByScreenshotChord = false;
4128 cancelPendingPowerKeyAction();
4129 interceptScreenshotChord();
4130 }
4131 } else {
4132 mVolumeDownKeyTriggered = false;
4133 cancelPendingScreenshotChordAction();
4134 }
4135 } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
4136 if (down) {
Jeff Brown037c33e2014-04-09 00:31:55 -07004137 if (interactive && !mVolumeUpKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004138 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
4139 mVolumeUpKeyTriggered = true;
4140 cancelPendingPowerKeyAction();
4141 cancelPendingScreenshotChordAction();
4142 }
4143 } else {
4144 mVolumeUpKeyTriggered = false;
4145 cancelPendingScreenshotChordAction();
4146 }
4147 }
Jeff Brown4d396052010-10-29 21:50:21 -07004148 if (down) {
Santos Cordon6848f722014-05-21 15:22:12 -07004149 TelephonyManager telephonyManager = getTelephonyService();
4150 if (telephonyManager != null) {
4151 if (telephonyManager.isRinging()) {
4152 // If an incoming call is ringing, either VOLUME key means
4153 // "silence ringer". We handle these keys here, rather than
4154 // in the InCallScreen, to make sure we'll respond to them
4155 // even if the InCallScreen hasn't come to the foreground yet.
4156 // Look for the DOWN event here, to agree with the "fallback"
4157 // behavior in the InCallScreen.
4158 Log.i(TAG, "interceptKeyBeforeQueueing:"
4159 + " VOLUME key-down while ringing: Silence ringer!");
Jeff Brown4d396052010-10-29 21:50:21 -07004160
Santos Cordon6848f722014-05-21 15:22:12 -07004161 // Silence the ringer. (It's safe to call this
4162 // even if the ringer has already been silenced.)
4163 telephonyManager.silenceRinger();
Jeff Brown4d396052010-10-29 21:50:21 -07004164
Santos Cordon6848f722014-05-21 15:22:12 -07004165 // And *don't* pass this key thru to the current activity
4166 // (which is probably the InCallScreen.)
4167 result &= ~ACTION_PASS_TO_USER;
4168 break;
4169 }
4170 if (telephonyManager.isOffhook()
4171 && (result & ACTION_PASS_TO_USER) == 0) {
4172 // If we are in call but we decided not to pass the key to
4173 // the application, handle the volume change here.
4174 handleVolumeKey(AudioManager.STREAM_VOICE_CALL, keyCode);
4175 break;
Jeff Brown4d396052010-10-29 21:50:21 -07004176 }
4177 }
4178
4179 if (isMusicActive() && (result & ACTION_PASS_TO_USER) == 0) {
4180 // If music is playing but we decided not to pass the key to the
4181 // application, handle the volume change here.
4182 handleVolumeKey(AudioManager.STREAM_MUSIC, keyCode);
4183 break;
4184 }
4185 }
4186 break;
4187 }
4188
4189 case KeyEvent.KEYCODE_ENDCALL: {
4190 result &= ~ACTION_PASS_TO_USER;
4191 if (down) {
Santos Cordon6848f722014-05-21 15:22:12 -07004192 TelephonyManager telephonyManager = getTelephonyService();
Jeff Brown4d396052010-10-29 21:50:21 -07004193 boolean hungUp = false;
Santos Cordon6848f722014-05-21 15:22:12 -07004194 if (telephonyManager != null) {
4195 hungUp = telephonyManager.endCall();
Jeff Brown4d396052010-10-29 21:50:21 -07004196 }
Jeff Brown037c33e2014-04-09 00:31:55 -07004197 interceptPowerKeyDown(!interactive || hungUp);
Jeff Brown4d396052010-10-29 21:50:21 -07004198 } else {
4199 if (interceptPowerKeyUp(canceled)) {
4200 if ((mEndcallBehavior
4201 & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) {
4202 if (goHome()) {
4203 break;
Dianne Hackborn0041e972009-07-24 17:14:43 -07004204 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004205 }
Jeff Brown4d396052010-10-29 21:50:21 -07004206 if ((mEndcallBehavior
4207 & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) {
Jeff Brown26875502014-01-30 21:47:47 -08004208 mPowerManager.goToSleep(event.getEventTime());
4209 isWakeKey = false;
Jeff Brown4d396052010-10-29 21:50:21 -07004210 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004211 }
Jeff Brown4d396052010-10-29 21:50:21 -07004212 }
4213 break;
4214 }
4215
4216 case KeyEvent.KEYCODE_POWER: {
4217 result &= ~ACTION_PASS_TO_USER;
4218 if (down) {
Jeff Brown26c6a502014-04-11 02:15:54 -07004219 boolean panic = mImmersiveModeConfirmation.onPowerKeyDown(interactive,
John Spurlockd9b70bd2014-02-06 17:02:44 -05004220 event.getDownTime(), isImmersiveMode(mLastSystemUiFlags));
4221 if (panic) {
4222 mHandler.post(mRequestTransientNav);
4223 }
Jeff Brown037c33e2014-04-09 00:31:55 -07004224 if (interactive && !mPowerKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004225 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
4226 mPowerKeyTriggered = true;
4227 mPowerKeyTime = event.getDownTime();
4228 interceptScreenshotChord();
Winson Chung9112ec32011-06-27 13:15:32 -07004229 }
Winson Chung9112ec32011-06-27 13:15:32 -07004230
Santos Cordon6848f722014-05-21 15:22:12 -07004231 TelephonyManager telephonyManager = getTelephonyService();
Jeff Brown4d396052010-10-29 21:50:21 -07004232 boolean hungUp = false;
Santos Cordon6848f722014-05-21 15:22:12 -07004233 if (telephonyManager != null) {
4234 if (telephonyManager.isRinging()) {
4235 // Pressing Power while there's a ringing incoming
4236 // call should silence the ringer.
4237 telephonyManager.silenceRinger();
4238 } else if ((mIncallPowerBehavior
4239 & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0
4240 && telephonyManager.isOffhook() && interactive) {
4241 // Otherwise, if "Power button ends call" is enabled,
4242 // the Power button will hang up any current active call.
4243 hungUp = telephonyManager.endCall();
Jeff Brown4d396052010-10-29 21:50:21 -07004244 }
4245 }
Jeff Brown037c33e2014-04-09 00:31:55 -07004246 interceptPowerKeyDown(!interactive || hungUp
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004247 || mVolumeDownKeyTriggered || mVolumeUpKeyTriggered);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004248 } else {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004249 mPowerKeyTriggered = false;
4250 cancelPendingScreenshotChordAction();
4251 if (interceptPowerKeyUp(canceled || mPendingPowerKeyUpCanceled)) {
Jeff Brown6d8fd272014-05-20 21:24:38 -07004252 powerShortPress(event.getEventTime());
Jeff Brown26875502014-01-30 21:47:47 -08004253 isWakeKey = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004254 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004255 mPendingPowerKeyUpCanceled = false;
Jeff Brown4d396052010-10-29 21:50:21 -07004256 }
4257 break;
4258 }
4259
Jeff Brown6212a492014-03-07 13:58:47 -08004260 case KeyEvent.KEYCODE_SLEEP: {
4261 result &= ~ACTION_PASS_TO_USER;
4262 mPowerManager.goToSleep(event.getEventTime());
4263 isWakeKey = false;
4264 break;
4265 }
4266
4267 case KeyEvent.KEYCODE_WAKEUP: {
4268 result &= ~ACTION_PASS_TO_USER;
4269 break;
4270 }
4271
Jeff Brown4d396052010-10-29 21:50:21 -07004272 case KeyEvent.KEYCODE_MEDIA_PLAY:
4273 case KeyEvent.KEYCODE_MEDIA_PAUSE:
4274 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
4275 if (down) {
Santos Cordon6848f722014-05-21 15:22:12 -07004276 TelephonyManager telephonyManager = getTelephonyService();
4277 if (telephonyManager != null) {
4278 if (!telephonyManager.isIdle()) {
4279 // Suppress PLAY/PAUSE toggle when phone is ringing or in-call
4280 // to avoid music playback.
4281 break;
Jeff Brown3122e442010-10-11 23:32:49 -07004282 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004283 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004284 }
Jeff Brown4d396052010-10-29 21:50:21 -07004285 case KeyEvent.KEYCODE_HEADSETHOOK:
4286 case KeyEvent.KEYCODE_MUTE:
4287 case KeyEvent.KEYCODE_MEDIA_STOP:
4288 case KeyEvent.KEYCODE_MEDIA_NEXT:
4289 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
4290 case KeyEvent.KEYCODE_MEDIA_REWIND:
4291 case KeyEvent.KEYCODE_MEDIA_RECORD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09004292 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
4293 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: {
Jeff Brown4d396052010-10-29 21:50:21 -07004294 if ((result & ACTION_PASS_TO_USER) == 0) {
4295 // Only do this if we would otherwise not pass it to the user. In that
4296 // case, the PhoneWindow class will do the same thing, except it will
4297 // only do it if the showing app doesn't process the key on its own.
Jeff Brown40013652012-05-16 21:22:36 -07004298 // Note that we need to make a copy of the key event here because the
4299 // original key event will be recycled when we return.
Jeff Brown4d396052010-10-29 21:50:21 -07004300 mBroadcastWakeLock.acquire();
Jeff Brown40013652012-05-16 21:22:36 -07004301 Message msg = mHandler.obtainMessage(MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK,
4302 new KeyEvent(event));
4303 msg.setAsynchronous(true);
4304 msg.sendToTarget();
Jeff Brown4d396052010-10-29 21:50:21 -07004305 }
4306 break;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004307 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004308
Jeff Brown4d396052010-10-29 21:50:21 -07004309 case KeyEvent.KEYCODE_CALL: {
4310 if (down) {
Santos Cordon6848f722014-05-21 15:22:12 -07004311 TelephonyManager telephonyManager = getTelephonyService();
4312 if (telephonyManager != null) {
4313 if (telephonyManager.isRinging()) {
4314 Log.i(TAG, "interceptKeyBeforeQueueing:"
4315 + " CALL key-down while ringing: Answer the call!");
4316 telephonyManager.answerRingingCall();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004317
Santos Cordon6848f722014-05-21 15:22:12 -07004318 // And *don't* pass this key thru to the current activity
4319 // (which is presumably the InCallScreen.)
4320 result &= ~ACTION_PASS_TO_USER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004321 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004322 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004323 }
Jeff Brown4d396052010-10-29 21:50:21 -07004324 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004325 }
4326 }
Jeff Brown26875502014-01-30 21:47:47 -08004327
4328 if (isWakeKey) {
4329 mPowerManager.wakeUp(event.getEventTime());
4330 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004331 return result;
4332 }
4333
Jeff Brown1c2e4942012-11-06 16:32:01 -08004334 /**
4335 * When the screen is off we ignore some keys that might otherwise typically
4336 * be considered wake keys. We filter them out here.
4337 *
4338 * {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it
4339 * is always considered a wake key.
4340 */
4341 private boolean isWakeKeyWhenScreenOff(int keyCode) {
4342 switch (keyCode) {
4343 // ignore volume keys unless docked
4344 case KeyEvent.KEYCODE_VOLUME_UP:
4345 case KeyEvent.KEYCODE_VOLUME_DOWN:
4346 case KeyEvent.KEYCODE_VOLUME_MUTE:
4347 return mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED;
4348
4349 // ignore media and camera keys
4350 case KeyEvent.KEYCODE_MUTE:
4351 case KeyEvent.KEYCODE_HEADSETHOOK:
4352 case KeyEvent.KEYCODE_MEDIA_PLAY:
4353 case KeyEvent.KEYCODE_MEDIA_PAUSE:
4354 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
4355 case KeyEvent.KEYCODE_MEDIA_STOP:
4356 case KeyEvent.KEYCODE_MEDIA_NEXT:
4357 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
4358 case KeyEvent.KEYCODE_MEDIA_REWIND:
4359 case KeyEvent.KEYCODE_MEDIA_RECORD:
4360 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09004361 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK:
Jeff Brown1c2e4942012-11-06 16:32:01 -08004362 case KeyEvent.KEYCODE_CAMERA:
4363 return false;
4364 }
4365 return true;
4366 }
4367
4368
Jeff Brown56194eb2011-03-02 19:23:13 -08004369 /** {@inheritDoc} */
4370 @Override
Jeff Brown037c33e2014-04-09 00:31:55 -07004371 public int interceptWakeMotionBeforeQueueing(long whenNanos, int policyFlags) {
4372 // We already know this is a wake motion so just wake up.
4373 // Note that we would observe policyFlags containing
4374 // FLAG_WAKE and FLAG_INTERACTIVE here.
4375 mPowerManager.wakeUp(whenNanos / 1000000);
4376 return 0;
Jeff Brown56194eb2011-03-02 19:23:13 -08004377 }
4378
Jeff Brown40013652012-05-16 21:22:36 -07004379 void dispatchMediaKeyWithWakeLock(KeyEvent event) {
4380 if (DEBUG_INPUT) {
4381 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: " + event);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004382 }
4383
Jeff Brown40013652012-05-16 21:22:36 -07004384 if (mHavePendingMediaKeyRepeatWithWakeLock) {
4385 if (DEBUG_INPUT) {
4386 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: canceled repeat");
4387 }
4388
4389 mHandler.removeMessages(MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK);
4390 mHavePendingMediaKeyRepeatWithWakeLock = false;
4391 mBroadcastWakeLock.release(); // pending repeat was holding onto the wake lock
4392 }
4393
4394 dispatchMediaKeyWithWakeLockToAudioService(event);
4395
4396 if (event.getAction() == KeyEvent.ACTION_DOWN
4397 && event.getRepeatCount() == 0) {
4398 mHavePendingMediaKeyRepeatWithWakeLock = true;
4399
4400 Message msg = mHandler.obtainMessage(
4401 MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK, event);
4402 msg.setAsynchronous(true);
4403 mHandler.sendMessageDelayed(msg, ViewConfiguration.getKeyRepeatTimeout());
4404 } else {
4405 mBroadcastWakeLock.release();
4406 }
4407 }
4408
4409 void dispatchMediaKeyRepeatWithWakeLock(KeyEvent event) {
4410 mHavePendingMediaKeyRepeatWithWakeLock = false;
4411
4412 KeyEvent repeatEvent = KeyEvent.changeTimeRepeat(event,
4413 SystemClock.uptimeMillis(), 1, event.getFlags() | KeyEvent.FLAG_LONG_PRESS);
4414 if (DEBUG_INPUT) {
4415 Slog.d(TAG, "dispatchMediaKeyRepeatWithWakeLock: " + repeatEvent);
4416 }
4417
4418 dispatchMediaKeyWithWakeLockToAudioService(repeatEvent);
4419 mBroadcastWakeLock.release();
4420 }
4421
4422 void dispatchMediaKeyWithWakeLockToAudioService(KeyEvent event) {
4423 if (ActivityManagerNative.isSystemReady()) {
RoboErik8a2cfc32014-05-16 11:19:38 -07004424 if (USE_SESSIONS) {
4425 MediaSessionLegacyHelper.getHelper(mContext).sendMediaButtonEvent(event, true);
4426 } else {
4427 IAudioService audioService = getAudioService();
4428 if (audioService != null) {
4429 try {
4430 audioService.dispatchMediaKeyEventUnderWakelock(event);
4431 } catch (RemoteException e) {
4432 Log.e(TAG, "dispatchMediaKeyEvent threw exception " + e);
4433 }
Jean-Michel Trivic6802222012-04-30 11:15:03 -07004434 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004435 }
4436 }
4437 }
4438
Mike Lockwood1753f7f2009-08-24 14:49:07 -07004439 BroadcastReceiver mDockReceiver = new BroadcastReceiver() {
Craig Mautnereee29c42013-01-17 14:44:34 -08004440 @Override
Mike Lockwood1753f7f2009-08-24 14:49:07 -07004441 public void onReceive(Context context, Intent intent) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07004442 if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) {
4443 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
4444 Intent.EXTRA_DOCK_STATE_UNDOCKED);
Daniel Sandler6396c722013-04-16 20:19:09 -04004445 } else {
4446 try {
4447 IUiModeManager uiModeService = IUiModeManager.Stub.asInterface(
4448 ServiceManager.getService(Context.UI_MODE_SERVICE));
4449 mUiMode = uiModeService.getCurrentModeType();
4450 } catch (RemoteException e) {
4451 }
Dianne Hackborn80fa1662009-10-07 14:02:10 -07004452 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004453 updateRotation(true);
Craig Mautnereee29c42013-01-17 14:44:34 -08004454 synchronized (mLock) {
4455 updateOrientationListenerLp();
4456 }
Mike Lockwood1753f7f2009-08-24 14:49:07 -07004457 }
4458 };
4459
Jeff Brown6aaf2952012-10-05 16:01:08 -07004460 BroadcastReceiver mDreamReceiver = new BroadcastReceiver() {
4461 @Override
4462 public void onReceive(Context context, Intent intent) {
4463 if (Intent.ACTION_DREAMING_STARTED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004464 if (mKeyguardDelegate != null) {
4465 mKeyguardDelegate.onDreamingStarted();
Jeff Brown6aaf2952012-10-05 16:01:08 -07004466 }
4467 } else if (Intent.ACTION_DREAMING_STOPPED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004468 if (mKeyguardDelegate != null) {
4469 mKeyguardDelegate.onDreamingStopped();
Jeff Brown6aaf2952012-10-05 16:01:08 -07004470 }
4471 }
4472 }
4473 };
4474
Christopher Tate5e08af02012-09-21 17:17:22 -07004475 BroadcastReceiver mMultiuserReceiver = new BroadcastReceiver() {
4476 @Override
4477 public void onReceive(Context context, Intent intent) {
4478 if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) {
4479 // tickle the settings observer: this first ensures that we're
4480 // observing the relevant settings for the newly-active user,
4481 // and then updates our own bookkeeping based on the now-
4482 // current user.
4483 mSettingsObserver.onChange(false);
John Spurlockce479d82012-11-29 09:52:21 -05004484
4485 // force a re-application of focused window sysui visibility.
4486 // the window may never have been shown for this user
4487 // e.g. the keyguard when going through the new-user setup flow
John Spurlock04db1762013-05-13 12:46:41 -04004488 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
John Spurlockce479d82012-11-29 09:52:21 -05004489 mLastSystemUiFlags = 0;
4490 updateSystemUiVisibilityLw();
4491 }
Christopher Tate5e08af02012-09-21 17:17:22 -07004492 }
4493 }
4494 };
4495
John Spurlockd9b70bd2014-02-06 17:02:44 -05004496 private final Runnable mRequestTransientNav = new Runnable() {
4497 @Override
4498 public void run() {
4499 requestTransientBars(mNavigationBar);
4500 }
4501 };
4502
John Spurlocke1f366f2013-08-05 12:22:40 -04004503 private void requestTransientBars(WindowState swipeTarget) {
John Spurlock04db1762013-05-13 12:46:41 -04004504 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Maurice Lam99c6e072014-04-28 18:24:28 -07004505 if (!isUserSetupComplete()) {
4506 // Swipe-up for navigation bar is disabled during setup
4507 return;
4508 }
John Spurlock27735a42013-08-14 17:57:38 -04004509 boolean sb = mStatusBarController.checkShowTransientBarLw();
4510 boolean nb = mNavigationBarController.checkShowTransientBarLw();
John Spurlockad3e6cb2013-04-30 08:47:43 -04004511 if (sb || nb) {
John Spurlocke1f366f2013-08-05 12:22:40 -04004512 WindowState barTarget = sb ? mStatusBar : mNavigationBar;
4513 if (sb ^ nb && barTarget != swipeTarget) {
4514 if (DEBUG) Slog.d(TAG, "Not showing transient bar, wrong swipe target");
John Spurlockad3e6cb2013-04-30 08:47:43 -04004515 return;
4516 }
John Spurlock27735a42013-08-14 17:57:38 -04004517 if (sb) mStatusBarController.showTransient();
4518 if (nb) mNavigationBarController.showTransient();
John Spurlockf1a36642013-10-12 17:50:42 -04004519 mImmersiveModeConfirmation.confirmCurrentPrompt();
John Spurlockad3e6cb2013-04-30 08:47:43 -04004520 updateSystemUiVisibilityLw();
John Spurlock32beb2c2013-03-11 10:16:47 -04004521 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04004522 }
4523 }
4524
Jeff Brownc38c9be2012-10-04 13:16:19 -07004525 @Override
Jeff Brown140ffc72014-05-01 15:18:00 -07004526 public void goingToSleep(int why) {
Dianne Hackborn74489012009-03-24 20:50:09 -07004527 EventLog.writeEvent(70000, 0);
The Android Open Source Project0727d222009-03-11 12:11:58 -07004528 synchronized (mLock) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004529 mScreenOnEarly = false;
4530 mScreenOnFully = false;
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07004531 }
Jim Miller5ecd8112013-01-09 18:50:26 -08004532 if (mKeyguardDelegate != null) {
4533 mKeyguardDelegate.onScreenTurnedOff(why);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004534 }
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07004535 synchronized (mLock) {
Jeff Browna20dda42014-05-27 20:57:24 -07004536 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07004537 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05004538 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07004539 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004540 }
4541
Jeff Brownc38c9be2012-10-04 13:16:19 -07004542 @Override
Jeff Brown140ffc72014-05-01 15:18:00 -07004543 public void wakingUp(final ScreenOnListener screenOnListener) {
Dianne Hackborn74489012009-03-24 20:50:09 -07004544 EventLog.writeEvent(70000, 1);
Craig Mautner8a0da012014-05-31 15:13:37 -07004545 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turning on...",
4546 new RuntimeException("here").fillInStackTrace());
4547 mHandler.obtainMessage(MSG_WAKING_UP, screenOnListener).sendToTarget();
4548 }
4549
4550 // Called on the mHandler thread.
4551 private void handleWakingUp(final ScreenOnListener screenOnListener) {
4552 if (screenOnListener != null) {
4553 mScreenOnListeners.add(screenOnListener);
Dianne Hackborn40011092011-09-22 13:37:48 -07004554 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07004555
The Android Open Source Project0727d222009-03-11 12:11:58 -07004556 synchronized (mLock) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004557 mScreenOnEarly = true;
Jeff Browna20dda42014-05-27 20:57:24 -07004558 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07004559 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05004560 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07004561 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07004562
Craig Mautner8a0da012014-05-31 15:13:37 -07004563 mKeyguardDrawComplete = false;
4564 mWindowManagerDrawComplete = false;
Jim Miller5ecd8112013-01-09 18:50:26 -08004565 if (mKeyguardDelegate != null) {
Craig Mautner8a0da012014-05-31 15:13:37 -07004566 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
4567 mHandler.sendEmptyMessageDelayed(MSG_KEYGUARD_DRAWN_TIMEOUT, 1000);
4568 mKeyguardDelegate.onScreenTurnedOn(mKeyguardDelegateCallback);
Jeff Brownc38c9be2012-10-04 13:16:19 -07004569 } else {
Craig Mautner8a0da012014-05-31 15:13:37 -07004570 if (DEBUG_WAKEUP) Slog.d(TAG, "null mKeyguardDelegate: setting mKeyguardDrawComplete.");
4571 mKeyguardDrawComplete = true;
Jeff Brownc38c9be2012-10-04 13:16:19 -07004572 }
Craig Mautner8a0da012014-05-31 15:13:37 -07004573 mWindowManagerInternal.waitForAllWindowsDrawn(mWindowManagerDrawCallback, 500);
Jeff Brownc38c9be2012-10-04 13:16:19 -07004574 }
4575
Craig Mautner8a0da012014-05-31 15:13:37 -07004576 // Called on the mHandler thread.
4577 private void finishScreenTurningOn() {
4578 if (DEBUG_WAKEUP) Slog.d(TAG,
4579 "finishScreenTurningOn: mKeyguardDrawComplete=" + mKeyguardDrawComplete
4580 + " mWindowManagerDrawComplete=" + mWindowManagerDrawComplete);
4581 if (!mKeyguardDrawComplete || !mWindowManagerDrawComplete) {
4582 return;
Jeff Brownc38c9be2012-10-04 13:16:19 -07004583 }
4584
Jeff Brownc38c9be2012-10-04 13:16:19 -07004585 synchronized (mLock) {
4586 mScreenOnFully = true;
4587 }
4588
Jeff Brown4fc45272012-10-10 18:28:14 -07004589 try {
4590 mWindowManager.setEventDispatching(true);
4591 } catch (RemoteException unhandled) {
4592 }
4593
Craig Mautner8a0da012014-05-31 15:13:37 -07004594 for (int i = mScreenOnListeners.size() - 1; i >=0; --i) {
4595 mScreenOnListeners.remove(i).onScreenOn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07004596 }
Craig Mautner8a0da012014-05-31 15:13:37 -07004597
4598 setKeyguardDrawn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07004599 }
4600
4601 @Override
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004602 public boolean isScreenOnEarly() {
4603 return mScreenOnEarly;
4604 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07004605
4606 @Override
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004607 public boolean isScreenOnFully() {
4608 return mScreenOnFully;
Dianne Hackborn08743722009-12-21 12:16:51 -08004609 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07004610
Dianne Hackborn08743722009-12-21 12:16:51 -08004611 /** {@inheritDoc} */
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004612 public void enableKeyguard(boolean enabled) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004613 if (mKeyguardDelegate != null) {
4614 mKeyguardDelegate.setKeyguardEnabled(enabled);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004615 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004616 }
4617
4618 /** {@inheritDoc} */
4619 public void exitKeyguardSecurely(OnKeyguardExitResult callback) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004620 if (mKeyguardDelegate != null) {
4621 mKeyguardDelegate.verifyUnlock(callback);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004622 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004623 }
4624
Mike Lockwoodf7913302009-11-28 22:27:10 -05004625 private boolean keyguardIsShowingTq() {
Jim Miller5ecd8112013-01-09 18:50:26 -08004626 if (mKeyguardDelegate == null) return false;
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004627 return mKeyguardDelegate.isShowingAndNotOccluded();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004628 }
4629
Mike Lockwood520d8bc2011-02-18 13:23:13 -05004630
4631 /** {@inheritDoc} */
4632 public boolean isKeyguardLocked() {
4633 return keyguardOn();
4634 }
4635
4636 /** {@inheritDoc} */
4637 public boolean isKeyguardSecure() {
Jim Miller5ecd8112013-01-09 18:50:26 -08004638 if (mKeyguardDelegate == null) return false;
4639 return mKeyguardDelegate.isSecure();
Mike Lockwood520d8bc2011-02-18 13:23:13 -05004640 }
4641
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004642 /** {@inheritDoc} */
4643 public boolean inKeyguardRestrictedKeyInputMode() {
Jim Miller5ecd8112013-01-09 18:50:26 -08004644 if (mKeyguardDelegate == null) return false;
4645 return mKeyguardDelegate.isInputRestricted();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004646 }
4647
Dianne Hackborn90c52de2011-09-23 12:57:44 -07004648 public void dismissKeyguardLw() {
RoboErik8a2cfc32014-05-16 11:19:38 -07004649 if (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()) {
Daniel Sandler1ce804392012-11-07 15:07:12 -05004650 mHandler.post(new Runnable() {
4651 public void run() {
Jim Miller5ecd8112013-01-09 18:50:26 -08004652 if (mKeyguardDelegate.isDismissable()) {
Daniel Sandler1ce804392012-11-07 15:07:12 -05004653 // Can we just finish the keyguard straight away?
Jim Miller5ecd8112013-01-09 18:50:26 -08004654 mKeyguardDelegate.keyguardDone(false, true);
Daniel Sandler1ce804392012-11-07 15:07:12 -05004655 } else {
4656 // ask the keyguard to prompt the user to authenticate if necessary
Jim Miller5ecd8112013-01-09 18:50:26 -08004657 mKeyguardDelegate.dismiss();
Dianne Hackborn90c52de2011-09-23 12:57:44 -07004658 }
Daniel Sandler1ce804392012-11-07 15:07:12 -05004659 }
4660 });
Dianne Hackborn90c52de2011-09-23 12:57:44 -07004661 }
4662 }
4663
Jorim Jaggicff0acb2014-03-31 16:35:15 +02004664 private void setKeyguardDrawn() {
4665 synchronized (mLock) {
4666 mKeyguardDrawn = true;
4667 }
4668 try {
4669 mWindowManager.enableScreenIfNeeded();
4670 } catch (RemoteException unhandled) {
4671 }
4672 }
4673
4674 @Override
4675 public boolean isKeyguardDrawnLw() {
4676 synchronized (mLock) {
4677 return mKeyguardDrawn;
4678 }
4679 }
4680
Jorim Jaggi0d674622014-05-21 01:34:15 +02004681 @Override
Jorim Jaggie29b2db2014-05-30 23:17:03 +02004682 public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) {
Jorim Jaggi0d674622014-05-21 01:34:15 +02004683 if (mKeyguardDelegate != null) {
Jorim Jaggie29b2db2014-05-30 23:17:03 +02004684 mKeyguardDelegate.startKeyguardExitAnimation(startTime, fadeoutDuration);
Jorim Jaggi0d674622014-05-21 01:34:15 +02004685 }
4686 }
4687
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004688 void sendCloseSystemWindows() {
4689 sendCloseSystemWindows(mContext, null);
4690 }
4691
4692 void sendCloseSystemWindows(String reason) {
4693 sendCloseSystemWindows(mContext, reason);
4694 }
4695
4696 static void sendCloseSystemWindows(Context context, String reason) {
4697 if (ActivityManagerNative.isSystemReady()) {
Dianne Hackborn94a679d2009-07-28 17:51:07 -07004698 try {
4699 ActivityManagerNative.getDefault().closeSystemDialogs(reason);
4700 } catch (RemoteException e) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004701 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004702 }
4703 }
Mitsuru Oshima831d0d92009-06-16 18:27:18 -07004704
Jeff Brown01a98dd2011-09-20 15:08:29 -07004705 @Override
4706 public int rotationForOrientationLw(int orientation, int lastRotation) {
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05004707 if (false) {
4708 Slog.v(TAG, "rotationForOrientationLw(orient="
4709 + orientation + ", last=" + lastRotation
4710 + "); user=" + mUserRotation + " "
4711 + ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED)
4712 ? "USER_ROTATION_LOCKED" : "")
4713 );
4714 }
4715
Craig Mautner46ac6fa2013-08-01 10:06:34 -07004716 if (mForceDefaultOrientation) {
4717 return Surface.ROTATION_0;
4718 }
4719
The Android Open Source Project0727d222009-03-11 12:11:58 -07004720 synchronized (mLock) {
Jeff Brownc0347aa2011-09-23 17:26:09 -07004721 int sensorRotation = mOrientationListener.getProposedRotation(); // may be -1
4722 if (sensorRotation < 0) {
Jeff Brown0f862b42012-09-27 21:11:01 -07004723 sensorRotation = lastRotation;
Jeff Brownc0347aa2011-09-23 17:26:09 -07004724 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004725
Jeff Browndec6cf42011-11-15 14:08:20 -08004726 final int preferredRotation;
Jeff Brown2e7760e2012-04-11 15:14:55 -07004727 if (mLidState == LID_OPEN && mLidOpenRotation >= 0) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07004728 // Ignore sensor when lid switch is open and rotation is forced.
4729 preferredRotation = mLidOpenRotation;
4730 } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR
Jeff Brownc0347aa2011-09-23 17:26:09 -07004731 && (mCarDockEnablesAccelerometer || mCarDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07004732 // Ignore sensor when in car dock unless explicitly enabled.
4733 // This case can override the behavior of NOSENSOR, and can also
4734 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07004735 preferredRotation = mCarDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07004736 ? sensorRotation : mCarDockRotation;
Jeff Brown1a693182011-11-08 14:44:16 -08004737 } else if ((mDockMode == Intent.EXTRA_DOCK_STATE_DESK
4738 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
4739 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK)
Jeff Brownc0347aa2011-09-23 17:26:09 -07004740 && (mDeskDockEnablesAccelerometer || mDeskDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07004741 // Ignore sensor when in desk dock unless explicitly enabled.
4742 // This case can override the behavior of NOSENSOR, and can also
4743 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07004744 preferredRotation = mDeskDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07004745 ? sensorRotation : mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -07004746 } else if (mHdmiPlugged && mDemoHdmiRotationLock) {
4747 // Ignore sensor when plugged into HDMI when demo HDMI rotation lock enabled.
Jeff Browneb3e4b92011-12-06 19:54:24 -08004748 // Note that the dock orientation overrides the HDMI orientation.
Jeff Brownc82c89ed2013-04-17 17:18:15 -07004749 preferredRotation = mDemoHdmiRotation;
4750 } else if (mHdmiPlugged && mDockMode == Intent.EXTRA_DOCK_STATE_UNDOCKED
4751 && mUndockedHdmiRotation >= 0) {
4752 // Ignore sensor when plugged into HDMI and an undocked orientation has
4753 // been specified in the configuration (only for legacy devices without
4754 // full multi-display support).
4755 // Note that the dock orientation overrides the HDMI orientation.
4756 preferredRotation = mUndockedHdmiRotation;
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07004757 } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED) {
4758 // Application just wants to remain locked in the last rotation.
4759 preferredRotation = lastRotation;
Jeff Brownbcdfc622014-03-06 19:13:04 -08004760 } else if (!mSupportAutoRotation) {
4761 // If we don't support auto-rotation then bail out here and ignore
4762 // the sensor and any rotation lock settings.
4763 preferredRotation = -1;
Jeff Brown207673cd2012-06-05 17:47:11 -07004764 } else if ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE
Jeff Brown01a98dd2011-09-20 15:08:29 -07004765 && (orientation == ActivityInfo.SCREEN_ORIENTATION_USER
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07004766 || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
4767 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
4768 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
4769 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER))
Jeff Brown01a98dd2011-09-20 15:08:29 -07004770 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
4771 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
4772 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
4773 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) {
4774 // Otherwise, use sensor only if requested by the application or enabled
4775 // by default for USER or UNSPECIFIED modes. Does not apply to NOSENSOR.
Jeff Brownd3187e32011-09-21 19:26:44 -07004776 if (mAllowAllRotations < 0) {
4777 // Can't read this during init() because the context doesn't
4778 // have display metrics at that time so we cannot determine
4779 // tablet vs. phone then.
4780 mAllowAllRotations = mContext.getResources().getBoolean(
4781 com.android.internal.R.bool.config_allowAllRotations) ? 1 : 0;
4782 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004783 if (sensorRotation != Surface.ROTATION_180
Jeff Brownd3187e32011-09-21 19:26:44 -07004784 || mAllowAllRotations == 1
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07004785 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
4786 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07004787 preferredRotation = sensorRotation;
4788 } else {
4789 preferredRotation = lastRotation;
4790 }
Jeff Brown207673cd2012-06-05 17:47:11 -07004791 } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED
4792 && orientation != ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) {
4793 // Apply rotation lock. Does not apply to NOSENSOR.
4794 // The idea is that the user rotation expresses a weak preference for the direction
4795 // of gravity and as NOSENSOR is never affected by gravity, then neither should
4796 // NOSENSOR be affected by rotation lock (although it will be affected by docks).
Jeff Brown4dfce202011-10-05 12:00:10 -07004797 preferredRotation = mUserRotation;
Jeff Browndec6cf42011-11-15 14:08:20 -08004798 } else {
4799 // No overriding preference.
4800 // We will do exactly what the application asked us to do.
4801 preferredRotation = -1;
Jeff Brown01a98dd2011-09-20 15:08:29 -07004802 }
4803
Dianne Hackborne5439f22010-10-02 16:53:50 -07004804 switch (orientation) {
4805 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08004806 // Return portrait unless overridden.
4807 if (isAnyPortrait(preferredRotation)) {
4808 return preferredRotation;
4809 }
Dianne Hackborne5439f22010-10-02 16:53:50 -07004810 return mPortraitRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07004811
Jeff Brown01a98dd2011-09-20 15:08:29 -07004812 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08004813 // Return landscape unless overridden.
4814 if (isLandscapeOrSeascape(preferredRotation)) {
4815 return preferredRotation;
4816 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004817 return mLandscapeRotation;
4818
4819 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08004820 // Return reverse portrait unless overridden.
4821 if (isAnyPortrait(preferredRotation)) {
4822 return preferredRotation;
4823 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004824 return mUpsideDownRotation;
4825
4826 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08004827 // Return seascape unless overridden.
4828 if (isLandscapeOrSeascape(preferredRotation)) {
4829 return preferredRotation;
4830 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004831 return mSeascapeRotation;
4832
4833 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07004834 case ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE:
Jeff Brown01a98dd2011-09-20 15:08:29 -07004835 // Return either landscape rotation.
4836 if (isLandscapeOrSeascape(preferredRotation)) {
4837 return preferredRotation;
4838 }
4839 if (isLandscapeOrSeascape(lastRotation)) {
Jeff Brown4519f072011-01-23 13:16:01 -08004840 return lastRotation;
4841 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004842 return mLandscapeRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004843
Jeff Brown01a98dd2011-09-20 15:08:29 -07004844 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07004845 case ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT:
Jeff Brown01a98dd2011-09-20 15:08:29 -07004846 // Return either portrait rotation.
4847 if (isAnyPortrait(preferredRotation)) {
4848 return preferredRotation;
4849 }
4850 if (isAnyPortrait(lastRotation)) {
4851 return lastRotation;
4852 }
4853 return mPortraitRotation;
4854
4855 default:
Jeff Brown4dfce202011-10-05 12:00:10 -07004856 // For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR,
4857 // just return the preferred orientation we already calculated.
Jeff Brown01a98dd2011-09-20 15:08:29 -07004858 if (preferredRotation >= 0) {
4859 return preferredRotation;
4860 }
Dianne Hackborndacea8c2011-04-21 17:26:39 -07004861 return Surface.ROTATION_0;
Daniel Sandlere7e5ac22011-02-22 16:10:21 -05004862 }
4863 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07004864 }
4865
Jeff Brown01a98dd2011-09-20 15:08:29 -07004866 @Override
4867 public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation) {
4868 switch (orientation) {
4869 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
4870 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
4871 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
4872 return isAnyPortrait(rotation);
4873
4874 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
4875 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
4876 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
4877 return isLandscapeOrSeascape(rotation);
4878
4879 default:
4880 return true;
4881 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07004882 }
4883
Jeff Brownc0347aa2011-09-23 17:26:09 -07004884 @Override
4885 public void setRotationLw(int rotation) {
4886 mOrientationListener.setCurrentRotation(rotation);
4887 }
4888
Jeff Brown01a98dd2011-09-20 15:08:29 -07004889 private boolean isLandscapeOrSeascape(int rotation) {
4890 return rotation == mLandscapeRotation || rotation == mSeascapeRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07004891 }
4892
Jeff Brown01a98dd2011-09-20 15:08:29 -07004893 private boolean isAnyPortrait(int rotation) {
4894 return rotation == mPortraitRotation || rotation == mUpsideDownRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07004895 }
4896
Svetoslav Ganov80943d82013-01-02 10:25:37 -08004897 public int getUserRotationMode() {
4898 return Settings.System.getIntForUser(mContext.getContentResolver(),
Brett Chabot7e55c402013-05-16 19:38:08 -07004899 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
4900 WindowManagerPolicy.USER_ROTATION_FREE :
4901 WindowManagerPolicy.USER_ROTATION_LOCKED;
Svetoslav Ganov80943d82013-01-02 10:25:37 -08004902 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004903
4904 // User rotation: to be used when all else fails in assigning an orientation to the device
4905 public void setUserRotationMode(int mode, int rot) {
4906 ContentResolver res = mContext.getContentResolver();
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05004907
4908 // mUserRotationMode and mUserRotation will be assigned by the content observer
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004909 if (mode == WindowManagerPolicy.USER_ROTATION_LOCKED) {
Christopher Tate5e08af02012-09-21 17:17:22 -07004910 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004911 Settings.System.USER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07004912 rot,
4913 UserHandle.USER_CURRENT);
4914 Settings.System.putIntForUser(res,
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05004915 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07004916 0,
4917 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004918 } else {
Christopher Tate5e08af02012-09-21 17:17:22 -07004919 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004920 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07004921 1,
4922 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004923 }
4924 }
4925
Jeff Brownac143512012-04-05 18:57:33 -07004926 public void setSafeMode(boolean safeMode) {
4927 mSafeMode = safeMode;
4928 performHapticFeedbackLw(null, safeMode
4929 ? HapticFeedbackConstants.SAFE_MODE_ENABLED
4930 : HapticFeedbackConstants.SAFE_MODE_DISABLED, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004931 }
Craig Mautnereda67292013-04-28 13:50:14 -07004932
Dianne Hackborn181ceb52009-08-27 22:16:40 -07004933 static long[] getLongIntArray(Resources r, int resid) {
4934 int[] ar = r.getIntArray(resid);
4935 if (ar == null) {
4936 return null;
4937 }
4938 long[] out = new long[ar.length];
4939 for (int i=0; i<ar.length; i++) {
4940 out[i] = ar[i];
4941 }
4942 return out;
4943 }
Craig Mautnereda67292013-04-28 13:50:14 -07004944
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004945 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07004946 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004947 public void systemReady() {
Mike Lockwooded8902d2013-11-15 11:01:47 -08004948 mKeyguardDelegate = new KeyguardServiceDelegate(mContext, null);
4949 mKeyguardDelegate.onSystemReady();
4950
Dianne Hackbornb1a79802009-09-29 15:18:31 -07004951 synchronized (mLock) {
4952 updateOrientationListenerLp();
Dianne Hackbornc777e072010-02-12 13:07:59 -08004953 mSystemReady = true;
4954 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07004955 @Override
Dianne Hackbornc777e072010-02-12 13:07:59 -08004956 public void run() {
4957 updateSettings();
4958 }
4959 });
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004960 }
4961 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07004962
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07004963 /** {@inheritDoc} */
4964 public void systemBooted() {
Jim Millere5f910a2013-10-16 18:15:46 -07004965 if (mKeyguardDelegate != null) {
4966 mKeyguardDelegate.onBootCompleted();
4967 }
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07004968 synchronized (mLock) {
4969 mSystemBooted = true;
4970 }
Craig Mautner8a0da012014-05-31 15:13:37 -07004971 wakingUp(null);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07004972 }
4973
Dianne Hackborn661cd522011-08-22 00:26:20 -07004974 ProgressDialog mBootMsgDialog = null;
4975
4976 /** {@inheritDoc} */
4977 public void showBootMessage(final CharSequence msg, final boolean always) {
4978 mHandler.post(new Runnable() {
4979 @Override public void run() {
4980 if (mBootMsgDialog == null) {
Craig Stout4c0cb8a2014-04-04 13:03:10 -07004981 int theme;
4982 if (mContext.getPackageManager().hasSystemFeature(
4983 PackageManager.FEATURE_WATCH)) {
4984 theme = com.android.internal.R.style.Theme_Micro_Dialog_Alert;
4985 } else if (mContext.getPackageManager().hasSystemFeature(
4986 PackageManager.FEATURE_TELEVISION)) {
4987 theme = com.android.internal.R.style.Theme_Leanback_Dialog_Alert;
4988 } else {
4989 theme = 0;
4990 }
Vinod Krishnanfa8fc412014-04-18 14:35:53 -07004991
4992 mBootMsgDialog = new ProgressDialog(mContext, theme) {
Dianne Hackborn295e3c22011-08-25 13:19:08 -07004993 // This dialog will consume all events coming in to
4994 // it, to avoid it trying to do things too early in boot.
4995 @Override public boolean dispatchKeyEvent(KeyEvent event) {
4996 return true;
4997 }
4998 @Override public boolean dispatchKeyShortcutEvent(KeyEvent event) {
4999 return true;
5000 }
5001 @Override public boolean dispatchTouchEvent(MotionEvent ev) {
5002 return true;
5003 }
5004 @Override public boolean dispatchTrackballEvent(MotionEvent ev) {
5005 return true;
5006 }
5007 @Override public boolean dispatchGenericMotionEvent(MotionEvent ev) {
5008 return true;
5009 }
5010 @Override public boolean dispatchPopulateAccessibilityEvent(
5011 AccessibilityEvent event) {
5012 return true;
5013 }
5014 };
Dianne Hackborn661cd522011-08-22 00:26:20 -07005015 mBootMsgDialog.setTitle(R.string.android_upgrading_title);
5016 mBootMsgDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
5017 mBootMsgDialog.setIndeterminate(true);
5018 mBootMsgDialog.getWindow().setType(
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07005019 WindowManager.LayoutParams.TYPE_BOOT_PROGRESS);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005020 mBootMsgDialog.getWindow().addFlags(
5021 WindowManager.LayoutParams.FLAG_DIM_BEHIND
5022 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
5023 mBootMsgDialog.getWindow().setDimAmount(1);
Dianne Hackbornd9efb952011-12-07 14:56:51 -08005024 WindowManager.LayoutParams lp = mBootMsgDialog.getWindow().getAttributes();
5025 lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
5026 mBootMsgDialog.getWindow().setAttributes(lp);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005027 mBootMsgDialog.setCancelable(false);
5028 mBootMsgDialog.show();
5029 }
5030 mBootMsgDialog.setMessage(msg);
5031 }
5032 });
5033 }
5034
5035 /** {@inheritDoc} */
5036 public void hideBootMessages() {
5037 mHandler.post(new Runnable() {
5038 @Override public void run() {
5039 if (mBootMsgDialog != null) {
5040 mBootMsgDialog.dismiss();
5041 mBootMsgDialog = null;
5042 }
5043 }
5044 });
5045 }
5046
Mike Lockwood28569302010-01-28 11:54:40 -05005047 /** {@inheritDoc} */
5048 public void userActivity() {
Dianne Hackborndf89e652011-10-06 22:35:11 -07005049 // ***************************************
5050 // NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
5051 // ***************************************
5052 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
5053 // WITH ITS LOCKS HELD.
5054 //
5055 // This code must be VERY careful about the locks
5056 // it acquires.
5057 // In fact, the current code acquires way too many,
5058 // and probably has lurking deadlocks.
5059
Mike Lockwood28569302010-01-28 11:54:40 -05005060 synchronized (mScreenLockTimeout) {
5061 if (mLockScreenTimerActive) {
5062 // reset the timer
5063 mHandler.removeCallbacks(mScreenLockTimeout);
5064 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
5065 }
5066 }
Daniel Sandler0601eb72011-04-13 01:01:32 -04005067 }
5068
Adam Cohenf7522022012-10-03 20:03:18 -07005069 class ScreenLockTimeout implements Runnable {
5070 Bundle options;
5071
5072 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05005073 public void run() {
5074 synchronized (this) {
5075 if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard");
Jim Miller5ecd8112013-01-09 18:50:26 -08005076 if (mKeyguardDelegate != null) {
5077 mKeyguardDelegate.doKeyguardTimeout(options);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005078 }
Mike Lockwood28569302010-01-28 11:54:40 -05005079 mLockScreenTimerActive = false;
Adam Cohenf7522022012-10-03 20:03:18 -07005080 options = null;
Mike Lockwood28569302010-01-28 11:54:40 -05005081 }
5082 }
Mike Lockwood28569302010-01-28 11:54:40 -05005083
Adam Cohenf7522022012-10-03 20:03:18 -07005084 public void setLockOptions(Bundle options) {
5085 this.options = options;
5086 }
5087 }
5088
5089 ScreenLockTimeout mScreenLockTimeout = new ScreenLockTimeout();
5090
5091 public void lockNow(Bundle options) {
Jim Miller93c518e2012-01-17 15:55:31 -08005092 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null);
5093 mHandler.removeCallbacks(mScreenLockTimeout);
Adam Cohenf7522022012-10-03 20:03:18 -07005094 if (options != null) {
5095 // In case multiple calls are made to lockNow, we don't wipe out the options
5096 // until the runnable actually executes.
5097 mScreenLockTimeout.setLockOptions(options);
5098 }
Jim Miller93c518e2012-01-17 15:55:31 -08005099 mHandler.post(mScreenLockTimeout);
5100 }
5101
Mike Lockwood28569302010-01-28 11:54:40 -05005102 private void updateLockScreenTimeout() {
5103 synchronized (mScreenLockTimeout) {
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005104 boolean enable = (mAllowLockscreenWhenOn && mScreenOnEarly &&
Jim Miller5ecd8112013-01-09 18:50:26 -08005105 mKeyguardDelegate != null && mKeyguardDelegate.isSecure());
Mike Lockwood28569302010-01-28 11:54:40 -05005106 if (mLockScreenTimerActive != enable) {
5107 if (enable) {
5108 if (localLOGV) Log.v(TAG, "setting lockscreen timer");
5109 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
5110 } else {
5111 if (localLOGV) Log.v(TAG, "clearing lockscreen timer");
5112 mHandler.removeCallbacks(mScreenLockTimeout);
5113 }
5114 mLockScreenTimerActive = enable;
5115 }
5116 }
5117 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005118
5119 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07005120 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005121 public void enableScreenAfterBoot() {
5122 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07005123 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07005124 updateRotation(true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005125 }
Dianne Hackbornf54c8f92009-09-19 14:03:57 -07005126
Jeff Brownc458ce92012-04-30 14:58:40 -07005127 private void applyLidSwitchState() {
Jeff Brownc458ce92012-04-30 14:58:40 -07005128 if (mLidState == LID_CLOSED && mLidControlsSleep) {
Jeff Brown6d8fd272014-05-20 21:24:38 -07005129 mPowerManager.goToSleep(SystemClock.uptimeMillis(),
5130 PowerManager.GO_TO_SLEEP_REASON_USER,
5131 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
Jeff Brownc458ce92012-04-30 14:58:40 -07005132 }
Jeff Browna20dda42014-05-27 20:57:24 -07005133
5134 synchronized (mLock) {
5135 updateWakeGestureListenerLp();
5136 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005137 }
5138
5139 void updateRotation(boolean alwaysSendConfiguration) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005140 try {
5141 //set orientation on WindowManager
Dianne Hackbornf87d1962012-04-04 12:48:24 -07005142 mWindowManager.updateRotation(alwaysSendConfiguration, false);
5143 } catch (RemoteException e) {
5144 // Ignore
5145 }
5146 }
5147
5148 void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) {
5149 try {
5150 //set orientation on WindowManager
5151 mWindowManager.updateRotation(alwaysSendConfiguration, forceRelayout);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005152 } catch (RemoteException e) {
5153 // Ignore
5154 }
5155 }
5156
Daniel Sandler6396c722013-04-16 20:19:09 -04005157 /**
5158 * Return an Intent to launch the currently active dock app as home. Returns
5159 * null if the standard home should be launched, which is the case if any of the following is
5160 * true:
5161 * <ul>
5162 * <li>The device is not in either car mode or desk mode
5163 * <li>The device is in car mode but ENABLE_CAR_DOCK_HOME_CAPTURE is false
5164 * <li>The device is in desk mode but ENABLE_DESK_DOCK_HOME_CAPTURE is false
5165 * <li>The device is in car mode but there's no CAR_DOCK app with METADATA_DOCK_HOME
5166 * <li>The device is in desk mode but there's no DESK_DOCK app with METADATA_DOCK_HOME
5167 * </ul>
Craig Mautnereda67292013-04-28 13:50:14 -07005168 * @return A dock intent.
Daniel Sandler6396c722013-04-16 20:19:09 -04005169 */
5170 Intent createHomeDockIntent() {
5171 Intent intent = null;
5172
5173 // What home does is based on the mode, not the dock state. That
5174 // is, when in car mode you should be taken to car home regardless
5175 // of whether we are actually in a car dock.
5176 if (mUiMode == Configuration.UI_MODE_TYPE_CAR) {
5177 if (ENABLE_CAR_DOCK_HOME_CAPTURE) {
5178 intent = mCarDockIntent;
5179 }
5180 } else if (mUiMode == Configuration.UI_MODE_TYPE_DESK) {
5181 if (ENABLE_DESK_DOCK_HOME_CAPTURE) {
5182 intent = mDeskDockIntent;
5183 }
5184 }
5185
5186 if (intent == null) {
5187 return null;
5188 }
5189
5190 ActivityInfo ai = null;
5191 ResolveInfo info = mContext.getPackageManager().resolveActivityAsUser(
5192 intent,
John Spurlockf56bef12013-07-09 09:51:46 -04005193 PackageManager.MATCH_DEFAULT_ONLY | PackageManager.GET_META_DATA,
Craig Mautnerd625ab22013-09-06 13:40:31 -07005194 mCurrentUserId);
Daniel Sandler6396c722013-04-16 20:19:09 -04005195 if (info != null) {
5196 ai = info.activityInfo;
5197 }
5198 if (ai != null
5199 && ai.metaData != null
5200 && ai.metaData.getBoolean(Intent.METADATA_DOCK_HOME)) {
5201 intent = new Intent(intent);
5202 intent.setClassName(ai.packageName, ai.name);
5203 return intent;
5204 }
5205
5206 return null;
5207 }
5208
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005209 void startDockOrHome() {
John Spurlockc8b46ca2013-04-08 12:59:26 -04005210 awakenDreams();
Daniel Sandler6396c722013-04-16 20:19:09 -04005211
5212 Intent dock = createHomeDockIntent();
5213 if (dock != null) {
5214 try {
5215 mContext.startActivityAsUser(dock, UserHandle.CURRENT);
5216 return;
5217 } catch (ActivityNotFoundException e) {
5218 }
5219 }
5220
Dianne Hackbornd8883992012-09-07 15:58:52 -07005221 mContext.startActivityAsUser(mHomeIntent, UserHandle.CURRENT);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005222 }
Craig Mautnereda67292013-04-28 13:50:14 -07005223
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005224 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005225 * goes to the home screen
5226 * @return whether it did anything
5227 */
5228 boolean goHome() {
5229 if (false) {
5230 // This code always brings home to the front.
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07005231 try {
5232 ActivityManagerNative.getDefault().stopAppSwitches();
5233 } catch (RemoteException e) {
5234 }
Dianne Hackborn94a679d2009-07-28 17:51:07 -07005235 sendCloseSystemWindows();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005236 startDockOrHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005237 } else {
5238 // This code brings home to the front or, if it is already
5239 // at the front, puts the device to sleep.
5240 try {
Wink Savilled2e6a332010-02-12 12:12:06 -08005241 if (SystemProperties.getInt("persist.sys.uts-test-mode", 0) == 1) {
5242 /// Roll back EndcallBehavior as the cupcake design to pass P1 lab entry.
5243 Log.d(TAG, "UTS-TEST-MODE");
5244 } else {
5245 ActivityManagerNative.getDefault().stopAppSwitches();
5246 sendCloseSystemWindows();
Daniel Sandler6396c722013-04-16 20:19:09 -04005247 Intent dock = createHomeDockIntent();
5248 if (dock != null) {
5249 int result = ActivityManagerNative.getDefault()
5250 .startActivityAsUser(null, null, dock,
5251 dock.resolveTypeIfNeeded(mContext.getContentResolver()),
5252 null, null, 0,
5253 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
5254 null, null, null, UserHandle.USER_CURRENT);
5255 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
5256 return false;
5257 }
5258 }
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005259 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005260 int result = ActivityManagerNative.getDefault()
Dianne Hackbornf265ea92013-01-31 15:00:51 -08005261 .startActivityAsUser(null, null, mHomeIntent,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005262 mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()),
Dianne Hackborna4972e92012-03-14 10:38:05 -07005263 null, null, 0,
5264 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Dianne Hackborn5e03e2c2012-09-06 14:21:19 -07005265 null, null, null, UserHandle.USER_CURRENT);
Dianne Hackborna4972e92012-03-14 10:38:05 -07005266 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005267 return false;
5268 }
5269 } catch (RemoteException ex) {
5270 // bummer, the activity manager, which is in this process, is dead
5271 }
5272 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005273 return true;
5274 }
Craig Mautnereda67292013-04-28 13:50:14 -07005275
5276 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07005277 public void setCurrentOrientationLw(int newOrientation) {
5278 synchronized (mLock) {
5279 if (newOrientation != mCurrentAppOrientation) {
5280 mCurrentAppOrientation = newOrientation;
5281 updateOrientationListenerLp();
5282 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005283 }
5284 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08005285
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07005286 private void performAuditoryFeedbackForAccessibilityIfNeed() {
5287 if (!isGlobalAccessibilityGestureEnabled()) {
5288 return;
5289 }
5290 AudioManager audioManager = (AudioManager) mContext.getSystemService(
5291 Context.AUDIO_SERVICE);
5292 if (audioManager.isSilentMode()) {
5293 return;
5294 }
5295 Ringtone ringTone = RingtoneManager.getRingtone(mContext,
5296 Settings.System.DEFAULT_NOTIFICATION_URI);
5297 ringTone.setStreamType(AudioManager.STREAM_MUSIC);
5298 ringTone.play();
5299 }
Craig Mautnereda67292013-04-28 13:50:14 -07005300
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07005301 private boolean isGlobalAccessibilityGestureEnabled() {
5302 return Settings.Global.getInt(mContext.getContentResolver(),
5303 Settings.Global.ENABLE_ACCESSIBILITY_GLOBAL_GESTURE_ENABLED, 0) == 1;
5304 }
5305
Craig Mautnereda67292013-04-28 13:50:14 -07005306 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07005307 public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) {
Svetoslav Ganov96179212012-10-10 14:17:45 -07005308 if (!mVibrator.hasVibrator()) {
5309 return false;
5310 }
Christopher Tate5e08af02012-09-21 17:17:22 -07005311 final boolean hapticsDisabled = Settings.System.getIntForUser(mContext.getContentResolver(),
5312 Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) == 0;
Jorim Jaggi5cf17872014-03-26 18:31:48 +01005313 if (!always && (hapticsDisabled || mKeyguardDelegate.isShowingAndNotOccluded())) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005314 return false;
5315 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08005316 long[] pattern = null;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005317 switch (effectId) {
5318 case HapticFeedbackConstants.LONG_PRESS:
Amith Yamasanic33cb712010-02-10 15:21:49 -08005319 pattern = mLongPressVibePattern;
5320 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07005321 case HapticFeedbackConstants.VIRTUAL_KEY:
Amith Yamasanic33cb712010-02-10 15:21:49 -08005322 pattern = mVirtualKeyVibePattern;
5323 break;
5324 case HapticFeedbackConstants.KEYBOARD_TAP:
5325 pattern = mKeyboardTapVibePattern;
5326 break;
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07005327 case HapticFeedbackConstants.CLOCK_TICK:
5328 pattern = mClockTickVibePattern;
5329 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07005330 case HapticFeedbackConstants.SAFE_MODE_DISABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08005331 pattern = mSafeModeDisabledVibePattern;
5332 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07005333 case HapticFeedbackConstants.SAFE_MODE_ENABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08005334 pattern = mSafeModeEnabledVibePattern;
5335 break;
Amith Yamasanic33cb712010-02-10 15:21:49 -08005336 default:
5337 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005338 }
Dianne Hackbornf265ea92013-01-31 15:00:51 -08005339 int owningUid;
5340 String owningPackage;
5341 if (win != null) {
5342 owningUid = win.getOwningUid();
5343 owningPackage = win.getOwningPackage();
5344 } else {
5345 owningUid = android.os.Process.myUid();
Dianne Hackborn95d78532013-09-11 09:51:14 -07005346 owningPackage = mContext.getOpPackageName();
Dianne Hackbornf265ea92013-01-31 15:00:51 -08005347 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08005348 if (pattern.length == 1) {
5349 // One-shot vibration
John Spurlock1af30c72014-03-10 08:33:35 -04005350 mVibrator.vibrate(owningUid, owningPackage, pattern[0], AudioManager.STREAM_SYSTEM);
Amith Yamasanic33cb712010-02-10 15:21:49 -08005351 } else {
5352 // Pattern vibration
John Spurlock1af30c72014-03-10 08:33:35 -04005353 mVibrator.vibrate(owningUid, owningPackage, pattern, -1, AudioManager.STREAM_SYSTEM);
Amith Yamasanic33cb712010-02-10 15:21:49 -08005354 }
5355 return true;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005356 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005357
5358 @Override
5359 public void keepScreenOnStartedLw() {
Daniel Sandler0601eb72011-04-13 01:01:32 -04005360 }
5361
Jeff Brownc38c9be2012-10-04 13:16:19 -07005362 @Override
5363 public void keepScreenOnStoppedLw() {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01005364 if (mKeyguardDelegate != null && !mKeyguardDelegate.isShowingAndNotOccluded()) {
Jim Miller25190572013-02-28 17:36:24 -08005365 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005366 }
5367 }
Mike Lockwoodfcb39242009-10-21 23:01:07 -04005368
Dianne Hackborndf89e652011-10-06 22:35:11 -07005369 private int updateSystemUiVisibilityLw() {
Joe Onorato664644d2011-01-23 17:53:23 -08005370 // If there is no window focused, there will be nobody to handle the events
5371 // anyway, so just hang on in whatever state we're in until things settle down.
John Spurlock79da8332013-09-20 12:04:47 -04005372 WindowState win = mFocusedWindow != null ? mFocusedWindow : mTopFullscreenOpaqueWindowState;
5373 if (win == null) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07005374 return 0;
5375 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01005376 if ((win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 && mHideLockScreen == true) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07005377 // We are updating at a point where the keyguard has gotten
5378 // focus, but we were last in a state where the top window is
5379 // hiding it. This is probably because the keyguard as been
5380 // shown while the top window was displayed, so we want to ignore
5381 // it here because this is just a very transient change and it
5382 // will quickly lose focus once it correctly gets hidden.
5383 return 0;
5384 }
John Spurlock32beb2c2013-03-11 10:16:47 -04005385
John Spurlock1db8b682014-02-18 11:18:59 -05005386 int tmpVisibility = PolicyControl.getSystemUiVisibility(win, null)
Dianne Hackborne26ab702011-10-16 13:21:33 -07005387 & ~mResettingSystemUiFlags
5388 & ~mForceClearedSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04005389 if (mForcingShowNavBar && win.getSurfaceLayer() < mForcingShowNavBarLayer) {
John Spurlockc6d1c602014-01-17 15:22:06 -05005390 tmpVisibility &= ~PolicyControl.adjustClearableFlags(win, View.SYSTEM_UI_CLEARABLE_FLAGS);
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08005391 }
John Spurlock79da8332013-09-20 12:04:47 -04005392 final int visibility = updateSystemBarsLw(win, mLastSystemUiFlags, tmpVisibility);
John Spurlockad3e6cb2013-04-30 08:47:43 -04005393 final int diff = visibility ^ mLastSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04005394 final boolean needsMenu = win.getNeedsMenuLw(mTopFullscreenOpaqueWindowState);
Dianne Hackborne0f085d2011-11-30 18:41:15 -08005395 if (diff == 0 && mLastFocusNeedsMenu == needsMenu
John Spurlock79da8332013-09-20 12:04:47 -04005396 && mFocusedApp == win.getAppToken()) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07005397 return 0;
5398 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07005399 mLastSystemUiFlags = visibility;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08005400 mLastFocusNeedsMenu = needsMenu;
John Spurlock79da8332013-09-20 12:04:47 -04005401 mFocusedApp = win.getAppToken();
Dianne Hackborndf89e652011-10-06 22:35:11 -07005402 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07005403 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07005404 public void run() {
Dianne Hackborn42e620c2012-06-24 13:20:51 -07005405 try {
5406 IStatusBarService statusbar = getStatusBarService();
5407 if (statusbar != null) {
5408 statusbar.setSystemUiVisibility(visibility, 0xffffffff);
5409 statusbar.topAppWindowChanged(needsMenu);
Joe Onorato664644d2011-01-23 17:53:23 -08005410 }
Dianne Hackborn42e620c2012-06-24 13:20:51 -07005411 } catch (RemoteException e) {
5412 // re-acquire status bar service next time it is needed.
5413 mStatusBarService = null;
Joe Onorato664644d2011-01-23 17:53:23 -08005414 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07005415 }
5416 });
5417 return diff;
Joe Onorato664644d2011-01-23 17:53:23 -08005418 }
5419
John Spurlock79da8332013-09-20 12:04:47 -04005420 private int updateSystemBarsLw(WindowState win, int oldVis, int vis) {
John Spurlockbd957402013-10-03 11:38:39 -04005421 // apply translucent bar vis flags
Jorim Jaggi380ecb82014-03-14 17:25:20 +01005422 WindowState transWin = isStatusBarKeyguard() && !mHideLockScreen
5423 ? mStatusBar
John Spurlockbd957402013-10-03 11:38:39 -04005424 : mTopFullscreenOpaqueWindowState;
5425 vis = mStatusBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
5426 vis = mNavigationBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
5427
John Spurlock27735a42013-08-14 17:57:38 -04005428 // prevent status bar interaction from clearing certain flags
John Spurlock79da8332013-09-20 12:04:47 -04005429 boolean statusBarHasFocus = win.getAttrs().type == TYPE_STATUS_BAR;
John Spurlockad3e6cb2013-04-30 08:47:43 -04005430 if (statusBarHasFocus) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04005431 int flags = View.SYSTEM_UI_FLAG_FULLSCREEN
5432 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlockcfc359a2013-09-05 10:42:03 -04005433 | View.SYSTEM_UI_FLAG_IMMERSIVE
Jorim Jaggi5cf17872014-03-26 18:31:48 +01005434 | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
5435 if (!isStatusBarKeyguard() || mHideLockScreen) {
5436 flags |= View.STATUS_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSLUCENT;
5437 }
John Spurlockbd957402013-10-03 11:38:39 -04005438 vis = (vis & ~flags) | (oldVis & flags);
John Spurlockad3e6cb2013-04-30 08:47:43 -04005439 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04005440
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04005441 if (!areTranslucentBarsAllowed()) {
Adrian Roosea562512014-05-05 13:33:03 +02005442 vis &= ~(View.NAVIGATION_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSLUCENT
5443 | View.SYSTEM_UI_TRANSPARENT);
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07005444 }
5445
John Spurlock27735a42013-08-14 17:57:38 -04005446 // update status bar
John Spurlockf1a36642013-10-12 17:50:42 -04005447 boolean immersiveSticky =
5448 (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
John Spurlock27735a42013-08-14 17:57:38 -04005449 boolean hideStatusBarWM =
John Spurlockbd957402013-10-03 11:38:39 -04005450 mTopFullscreenOpaqueWindowState != null &&
John Spurlockc6d1c602014-01-17 15:22:06 -05005451 (PolicyControl.getWindowFlags(mTopFullscreenOpaqueWindowState, null)
John Spurlock27735a42013-08-14 17:57:38 -04005452 & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0;
5453 boolean hideStatusBarSysui =
5454 (vis & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04005455 boolean hideNavBarSysui =
5456 (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0;
John Spurlockad3e6cb2013-04-30 08:47:43 -04005457
John Spurlock27735a42013-08-14 17:57:38 -04005458 boolean transientStatusBarAllowed =
5459 mStatusBar != null && (
5460 hideStatusBarWM
John Spurlockf1a36642013-10-12 17:50:42 -04005461 || (hideStatusBarSysui && immersiveSticky)
John Spurlock27735a42013-08-14 17:57:38 -04005462 || statusBarHasFocus);
5463
John Spurlockf1a36642013-10-12 17:50:42 -04005464 boolean transientNavBarAllowed =
5465 mNavigationBar != null &&
5466 hideNavBarSysui && immersiveSticky;
5467
John Spurlockf25706f2013-11-07 18:02:43 -05005468 boolean denyTransientStatus = mStatusBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04005469 && !transientStatusBarAllowed && hideStatusBarSysui;
John Spurlockf25706f2013-11-07 18:02:43 -05005470 boolean denyTransientNav = mNavigationBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04005471 && !transientNavBarAllowed;
5472 if (denyTransientStatus || denyTransientNav) {
John Spurlock27735a42013-08-14 17:57:38 -04005473 // clear the clearable flags instead
John Spurlockf1a36642013-10-12 17:50:42 -04005474 clearClearableFlagsLw();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005475 }
John Spurlock27735a42013-08-14 17:57:38 -04005476
5477 vis = mStatusBarController.updateVisibilityLw(transientStatusBarAllowed, oldVis, vis);
5478
5479 // update navigation bar
John Spurlockf1a36642013-10-12 17:50:42 -04005480 boolean oldImmersiveMode = isImmersiveMode(oldVis);
5481 boolean newImmersiveMode = isImmersiveMode(vis);
5482 if (win != null && oldImmersiveMode != newImmersiveMode) {
John Spurlock79da8332013-09-20 12:04:47 -04005483 final String pkg = win.getOwningPackage();
Maurice Lam99c6e072014-04-28 18:24:28 -07005484 mImmersiveModeConfirmation.immersiveModeChanged(pkg, newImmersiveMode,
5485 isUserSetupComplete());
John Spurlock34e13d92013-08-10 06:52:28 -04005486 }
John Spurlock27735a42013-08-14 17:57:38 -04005487
John Spurlockf1a36642013-10-12 17:50:42 -04005488 vis = mNavigationBarController.updateVisibilityLw(transientNavBarAllowed, oldVis, vis);
5489
John Spurlocke1f366f2013-08-05 12:22:40 -04005490 return vis;
John Spurlockad3e6cb2013-04-30 08:47:43 -04005491 }
5492
John Spurlockf1a36642013-10-12 17:50:42 -04005493 private void clearClearableFlagsLw() {
5494 int newVal = mResettingSystemUiFlags | View.SYSTEM_UI_CLEARABLE_FLAGS;
5495 if (newVal != mResettingSystemUiFlags) {
5496 mResettingSystemUiFlags = newVal;
5497 mWindowManagerFuncs.reevaluateStatusBarVisibility();
5498 }
5499 }
5500
5501 private boolean isImmersiveMode(int vis) {
5502 final int flags = View.SYSTEM_UI_FLAG_IMMERSIVE | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
John Spurlock34e13d92013-08-10 06:52:28 -04005503 return mNavigationBar != null
5504 && (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0
Daniel Sandler900ece52013-10-18 15:53:27 -04005505 && (vis & flags) != 0
5506 && canHideNavigationBar();
John Spurlock34e13d92013-08-10 06:52:28 -04005507 }
5508
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07005509 /**
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04005510 * @return whether the navigation or status bar can be made translucent
5511 *
5512 * This should return true unless touch exploration is not enabled or
5513 * R.boolean.config_enableTranslucentDecor is false.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07005514 */
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04005515 private boolean areTranslucentBarsAllowed() {
Svetoslav8e3feb12014-02-24 13:46:47 -08005516 return mTranslucentDecorEnabled
5517 && !mAccessibilityManager.isTouchExplorationEnabled();
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07005518 }
5519
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04005520 // Use this instead of checking config_showNavigationBar so that it can be consistently
5521 // overridden by qemu.hw.mainkeys in the emulator.
Craig Mautnereda67292013-04-28 13:50:14 -07005522 @Override
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04005523 public boolean hasNavigationBar() {
5524 return mHasNavigationBar;
5525 }
5526
satok1bc0a492012-04-25 22:47:12 +09005527 @Override
5528 public void setLastInputMethodWindowLw(WindowState ime, WindowState target) {
5529 mLastInputMethodWindow = ime;
5530 mLastInputMethodTargetWindow = target;
5531 }
5532
Craig Mautnerf1b67412012-09-19 13:18:29 -07005533 @Override
Satoshi Kataoka658c7b82013-10-10 17:03:51 +09005534 public int getInputMethodWindowVisibleHeightLw() {
5535 return mDockBottom - mCurBottom;
5536 }
5537
5538 @Override
Craig Mautnerf1b67412012-09-19 13:18:29 -07005539 public void setCurrentUserLw(int newUserId) {
Craig Mautnerd625ab22013-09-06 13:40:31 -07005540 mCurrentUserId = newUserId;
Jim Miller5ecd8112013-01-09 18:50:26 -08005541 if (mKeyguardDelegate != null) {
5542 mKeyguardDelegate.setCurrentUser(newUserId);
Craig Mautnerf1b67412012-09-19 13:18:29 -07005543 }
John Spurlock13451a22012-09-28 14:40:41 -04005544 if (mStatusBarService != null) {
5545 try {
5546 mStatusBarService.setCurrentUser(newUserId);
5547 } catch (RemoteException e) {
5548 // oh well
5549 }
5550 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07005551 setLastInputMethodWindowLw(null, null);
Craig Mautnerf1b67412012-09-19 13:18:29 -07005552 }
5553
5554 @Override
Svetoslav Ganov545252f2012-12-10 18:29:24 -08005555 public boolean canMagnifyWindow(int windowType) {
5556 switch (windowType) {
5557 case WindowManager.LayoutParams.TYPE_INPUT_METHOD:
5558 case WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG:
5559 case WindowManager.LayoutParams.TYPE_NAVIGATION_BAR:
5560 case WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY: {
5561 return false;
5562 }
5563 }
5564 return true;
5565 }
5566
5567 @Override
5568 public boolean isTopLevelWindow(int windowType) {
5569 if (windowType >= WindowManager.LayoutParams.FIRST_SUB_WINDOW
5570 && windowType <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
5571 return (windowType == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG);
5572 }
5573 return true;
5574 }
5575
Jim Miller4eeb4f62012-11-08 00:04:29 -08005576 @Override
Jeff Brownd7a04de2012-06-17 14:17:52 -07005577 public void dump(String prefix, PrintWriter pw, String[] args) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005578 pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005579 pw.print(" mSystemReady="); pw.print(mSystemReady);
5580 pw.print(" mSystemBooted="); pw.println(mSystemBooted);
Jeff Brown2e7760e2012-04-11 15:14:55 -07005581 pw.print(prefix); pw.print("mLidState="); pw.print(mLidState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005582 pw.print(" mLidOpenRotation="); pw.print(mLidOpenRotation);
5583 pw.print(" mHdmiPlugged="); pw.println(mHdmiPlugged);
Dianne Hackborne26ab702011-10-16 13:21:33 -07005584 if (mLastSystemUiFlags != 0 || mResettingSystemUiFlags != 0
5585 || mForceClearedSystemUiFlags != 0) {
5586 pw.print(prefix); pw.print("mLastSystemUiFlags=0x");
5587 pw.print(Integer.toHexString(mLastSystemUiFlags));
5588 pw.print(" mResettingSystemUiFlags=0x");
5589 pw.print(Integer.toHexString(mResettingSystemUiFlags));
5590 pw.print(" mForceClearedSystemUiFlags=0x");
5591 pw.println(Integer.toHexString(mForceClearedSystemUiFlags));
Dianne Hackborndf89e652011-10-06 22:35:11 -07005592 }
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08005593 if (mLastFocusNeedsMenu) {
5594 pw.print(prefix); pw.print("mLastFocusNeedsMenu=");
5595 pw.println(mLastFocusNeedsMenu);
5596 }
Jeff Browna20dda42014-05-27 20:57:24 -07005597 pw.print(prefix); pw.print("mWakeGestureEnabledSetting=");
5598 pw.println(mWakeGestureEnabledSetting);
5599
Jeff Brownbcdfc622014-03-06 19:13:04 -08005600 pw.print(prefix); pw.print("mSupportAutoRotation="); pw.println(mSupportAutoRotation);
Daniel Sandler6396c722013-04-16 20:19:09 -04005601 pw.print(prefix); pw.print("mUiMode="); pw.print(mUiMode);
5602 pw.print(" mDockMode="); pw.print(mDockMode);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005603 pw.print(" mCarDockRotation="); pw.print(mCarDockRotation);
5604 pw.print(" mDeskDockRotation="); pw.println(mDeskDockRotation);
5605 pw.print(prefix); pw.print("mUserRotationMode="); pw.print(mUserRotationMode);
5606 pw.print(" mUserRotation="); pw.print(mUserRotation);
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005607 pw.print(" mAllowAllRotations="); pw.println(mAllowAllRotations);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07005608 pw.print(prefix); pw.print("mCurrentAppOrientation="); pw.println(mCurrentAppOrientation);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005609 pw.print(prefix); pw.print("mCarDockEnablesAccelerometer=");
5610 pw.print(mCarDockEnablesAccelerometer);
5611 pw.print(" mDeskDockEnablesAccelerometer=");
5612 pw.println(mDeskDockEnablesAccelerometer);
5613 pw.print(prefix); pw.print("mLidKeyboardAccessibility=");
5614 pw.print(mLidKeyboardAccessibility);
5615 pw.print(" mLidNavigationAccessibility="); pw.print(mLidNavigationAccessibility);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07005616 pw.print(" mLidControlsSleep="); pw.println(mLidControlsSleep);
Jeff Brown6d8fd272014-05-20 21:24:38 -07005617 pw.print(prefix);
5618 pw.print("mShortPressOnPowerBehavior="); pw.print(mShortPressOnPowerBehavior);
5619 pw.print(" mLongPressOnPowerBehavior="); pw.println(mLongPressOnPowerBehavior);
5620 pw.print(prefix); pw.print("mHasSoftInput="); pw.println(mHasSoftInput);
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07005621 pw.print(prefix); pw.print("mScreenOnEarly="); pw.print(mScreenOnEarly);
5622 pw.print(" mScreenOnFully="); pw.print(mScreenOnFully);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07005623 pw.print(" mOrientationSensorEnabled="); pw.println(mOrientationSensorEnabled);
Dianne Hackbornc652de82013-02-15 16:32:56 -08005624 pw.print(prefix); pw.print("mOverscanScreen=("); pw.print(mOverscanScreenLeft);
5625 pw.print(","); pw.print(mOverscanScreenTop);
5626 pw.print(") "); pw.print(mOverscanScreenWidth);
5627 pw.print("x"); pw.println(mOverscanScreenHeight);
5628 if (mOverscanLeft != 0 || mOverscanTop != 0
5629 || mOverscanRight != 0 || mOverscanBottom != 0) {
5630 pw.print(prefix); pw.print("mOverscan left="); pw.print(mOverscanLeft);
5631 pw.print(" top="); pw.print(mOverscanTop);
5632 pw.print(" right="); pw.print(mOverscanRight);
5633 pw.print(" bottom="); pw.println(mOverscanBottom);
5634 }
Dianne Hackborn313440842013-02-19 19:22:59 -08005635 pw.print(prefix); pw.print("mRestrictedOverscanScreen=(");
5636 pw.print(mRestrictedOverscanScreenLeft);
5637 pw.print(","); pw.print(mRestrictedOverscanScreenTop);
5638 pw.print(") "); pw.print(mRestrictedOverscanScreenWidth);
5639 pw.print("x"); pw.println(mRestrictedOverscanScreenHeight);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005640 pw.print(prefix); pw.print("mUnrestrictedScreen=("); pw.print(mUnrestrictedScreenLeft);
5641 pw.print(","); pw.print(mUnrestrictedScreenTop);
5642 pw.print(") "); pw.print(mUnrestrictedScreenWidth);
5643 pw.print("x"); pw.println(mUnrestrictedScreenHeight);
5644 pw.print(prefix); pw.print("mRestrictedScreen=("); pw.print(mRestrictedScreenLeft);
5645 pw.print(","); pw.print(mRestrictedScreenTop);
5646 pw.print(") "); pw.print(mRestrictedScreenWidth);
5647 pw.print("x"); pw.println(mRestrictedScreenHeight);
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07005648 pw.print(prefix); pw.print("mStableFullscreen=("); pw.print(mStableFullscreenLeft);
5649 pw.print(","); pw.print(mStableFullscreenTop);
5650 pw.print(")-("); pw.print(mStableFullscreenRight);
5651 pw.print(","); pw.print(mStableFullscreenBottom); pw.println(")");
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07005652 pw.print(prefix); pw.print("mStable=("); pw.print(mStableLeft);
5653 pw.print(","); pw.print(mStableTop);
5654 pw.print(")-("); pw.print(mStableRight);
5655 pw.print(","); pw.print(mStableBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07005656 pw.print(prefix); pw.print("mSystem=("); pw.print(mSystemLeft);
5657 pw.print(","); pw.print(mSystemTop);
5658 pw.print(")-("); pw.print(mSystemRight);
5659 pw.print(","); pw.print(mSystemBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005660 pw.print(prefix); pw.print("mCur=("); pw.print(mCurLeft);
5661 pw.print(","); pw.print(mCurTop);
5662 pw.print(")-("); pw.print(mCurRight);
5663 pw.print(","); pw.print(mCurBottom); pw.println(")");
5664 pw.print(prefix); pw.print("mContent=("); pw.print(mContentLeft);
5665 pw.print(","); pw.print(mContentTop);
5666 pw.print(")-("); pw.print(mContentRight);
5667 pw.print(","); pw.print(mContentBottom); pw.println(")");
Dianne Hackborne30e02f2014-05-27 18:24:45 -07005668 pw.print(prefix); pw.print("mVoiceContent=("); pw.print(mVoiceContentLeft);
5669 pw.print(","); pw.print(mVoiceContentTop);
5670 pw.print(")-("); pw.print(mVoiceContentRight);
5671 pw.print(","); pw.print(mVoiceContentBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005672 pw.print(prefix); pw.print("mDock=("); pw.print(mDockLeft);
5673 pw.print(","); pw.print(mDockTop);
5674 pw.print(")-("); pw.print(mDockRight);
5675 pw.print(","); pw.print(mDockBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07005676 pw.print(prefix); pw.print("mDockLayer="); pw.print(mDockLayer);
5677 pw.print(" mStatusBarLayer="); pw.println(mStatusBarLayer);
Dianne Hackborn7ad44382012-10-18 17:46:00 -07005678 pw.print(prefix); pw.print("mShowingLockscreen="); pw.print(mShowingLockscreen);
5679 pw.print(" mShowingDream="); pw.print(mShowingDream);
5680 pw.print(" mDreamingLockscreen="); pw.println(mDreamingLockscreen);
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07005681 if (mLastInputMethodWindow != null) {
5682 pw.print(prefix); pw.print("mLastInputMethodWindow=");
5683 pw.println(mLastInputMethodWindow);
5684 }
5685 if (mLastInputMethodTargetWindow != null) {
5686 pw.print(prefix); pw.print("mLastInputMethodTargetWindow=");
5687 pw.println(mLastInputMethodTargetWindow);
5688 }
5689 if (mStatusBar != null) {
5690 pw.print(prefix); pw.print("mStatusBar=");
5691 pw.println(mStatusBar);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01005692 pw.print(prefix); pw.print("isStatusBarKeyguard=");
5693 pw.print(isStatusBarKeyguard());
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07005694 }
5695 if (mNavigationBar != null) {
5696 pw.print(prefix); pw.print("mNavigationBar=");
5697 pw.println(mNavigationBar);
5698 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07005699 if (mFocusedWindow != null) {
5700 pw.print(prefix); pw.print("mFocusedWindow=");
5701 pw.println(mFocusedWindow);
5702 }
5703 if (mFocusedApp != null) {
5704 pw.print(prefix); pw.print("mFocusedApp=");
5705 pw.println(mFocusedApp);
5706 }
5707 if (mWinDismissingKeyguard != null) {
5708 pw.print(prefix); pw.print("mWinDismissingKeyguard=");
5709 pw.println(mWinDismissingKeyguard);
5710 }
5711 if (mTopFullscreenOpaqueWindowState != null) {
5712 pw.print(prefix); pw.print("mTopFullscreenOpaqueWindowState=");
5713 pw.println(mTopFullscreenOpaqueWindowState);
5714 }
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08005715 if (mForcingShowNavBar) {
5716 pw.print(prefix); pw.print("mForcingShowNavBar=");
5717 pw.println(mForcingShowNavBar); pw.print( "mForcingShowNavBarLayer=");
5718 pw.println(mForcingShowNavBarLayer);
5719 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07005720 pw.print(prefix); pw.print("mTopIsFullscreen="); pw.print(mTopIsFullscreen);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005721 pw.print(" mHideLockScreen="); pw.println(mHideLockScreen);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07005722 pw.print(prefix); pw.print("mForceStatusBar="); pw.print(mForceStatusBar);
5723 pw.print(" mForceStatusBarFromKeyguard=");
5724 pw.println(mForceStatusBarFromKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005725 pw.print(prefix); pw.print("mDismissKeyguard="); pw.print(mDismissKeyguard);
Craig Mautnerad09bcc2012-10-08 13:33:11 -07005726 pw.print(" mWinDismissingKeyguard="); pw.print(mWinDismissingKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005727 pw.print(" mHomePressed="); pw.println(mHomePressed);
5728 pw.print(prefix); pw.print("mAllowLockscreenWhenOn="); pw.print(mAllowLockscreenWhenOn);
5729 pw.print(" mLockScreenTimeout="); pw.print(mLockScreenTimeout);
5730 pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive);
5731 pw.print(prefix); pw.print("mEndcallBehavior="); pw.print(mEndcallBehavior);
5732 pw.print(" mIncallPowerBehavior="); pw.print(mIncallPowerBehavior);
5733 pw.print(" mLongPressOnHomeBehavior="); pw.println(mLongPressOnHomeBehavior);
5734 pw.print(prefix); pw.print("mLandscapeRotation="); pw.print(mLandscapeRotation);
5735 pw.print(" mSeascapeRotation="); pw.println(mSeascapeRotation);
5736 pw.print(prefix); pw.print("mPortraitRotation="); pw.print(mPortraitRotation);
5737 pw.print(" mUpsideDownRotation="); pw.println(mUpsideDownRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07005738 pw.print(prefix); pw.print("mDemoHdmiRotation="); pw.print(mDemoHdmiRotation);
5739 pw.print(" mDemoHdmiRotationLock="); pw.println(mDemoHdmiRotationLock);
5740 pw.print(prefix); pw.print("mUndockedHdmiRotation="); pw.println(mUndockedHdmiRotation);
Jeff Brown600f0032014-05-22 17:06:00 -07005741
Tim Kilbournd7c0c2e2014-05-29 16:08:10 -07005742 mGlobalKeyManager.dump(prefix, pw);
John Spurlock27735a42013-08-14 17:57:38 -04005743 mStatusBarController.dump(pw, prefix);
5744 mNavigationBarController.dump(pw, prefix);
John Spurlockc6d1c602014-01-17 15:22:06 -05005745 PolicyControl.dump(prefix, pw);
Jeff Brown600f0032014-05-22 17:06:00 -07005746
Jeff Browna20dda42014-05-27 20:57:24 -07005747 if (mWakeGestureListener != null) {
5748 mWakeGestureListener.dump(pw, prefix);
5749 }
Jeff Brown600f0032014-05-22 17:06:00 -07005750 if (mOrientationListener != null) {
5751 mOrientationListener.dump(pw, prefix);
5752 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005753 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005754}