blob: 5d21c8c30000891b96182505a4ed0b84e07bf3bb [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;
John Spurlock7b414672014-07-18 13:02:39 -040044import android.media.AudioAttributes;
Michael Jurka7a348952012-02-27 13:07:58 -080045import android.media.AudioManager;
46import 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;
Jeff Brown32cbc38552011-12-01 14:01:49 -080054import android.os.Looper;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -070055import android.os.Message;
56import android.os.Messenger;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080057import android.os.PowerManager;
58import android.os.RemoteException;
59import android.os.ServiceManager;
60import android.os.SystemClock;
61import android.os.SystemProperties;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -080062import android.os.UEventObserver;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -070063import android.os.UserHandle;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080064import android.os.Vibrator;
Michael Wright3818c922014-09-02 13:59:07 -070065import android.provider.MediaStore;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080066import android.provider.Settings;
Jose Lima9546b202014-07-02 17:21:51 -070067import android.service.dreams.DreamManagerInternal;
John Spurlockc8b46ca2013-04-08 12:59:26 -040068import android.service.dreams.DreamService;
69import android.service.dreams.IDreamManager;
Michael Wrightdc63f7b2014-08-21 19:05:21 -070070import android.speech.RecognizerIntent;
Tyler Gunnef9f6f92014-09-12 22:16:17 -070071import android.telecom.TelecomManager;
Dianne Hackborn81e56d52011-05-26 00:55:58 -070072import android.util.DisplayMetrics;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080073import android.util.EventLog;
74import android.util.Log;
Jeff Browna41ca772010-08-11 14:46:32 -070075import android.util.Slog;
Jeff Brown6651a632011-11-28 12:59:11 -080076import android.util.SparseArray;
Dianne Hackbornf87d1962012-04-04 12:48:24 -070077import android.view.Display;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080078import android.view.Gravity;
79import android.view.HapticFeedbackConstants;
Dianne Hackborne0f085d2011-11-30 18:41:15 -080080import android.view.IApplicationToken;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080081import android.view.IWindowManager;
Jeff Browna41ca772010-08-11 14:46:32 -070082import android.view.InputChannel;
Jeff Brown4d396052010-10-29 21:50:21 -070083import android.view.InputDevice;
Jeff Brown4952dfd2011-11-30 19:23:22 -080084import android.view.InputEvent;
Jeff Brown32cbc38552011-12-01 14:01:49 -080085import android.view.InputEventReceiver;
Jeff Brown6b53e8d2010-11-10 16:03:06 -080086import android.view.KeyCharacterMap;
Craig Mautnerae446592012-12-06 19:05:05 -080087import android.view.KeyCharacterMap.FallbackAction;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080088import android.view.KeyEvent;
89import android.view.MotionEvent;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080090import android.view.Surface;
91import android.view.View;
92import android.view.ViewConfiguration;
93import android.view.Window;
94import android.view.WindowManager;
Craig Mautnerae446592012-12-06 19:05:05 -080095import android.view.WindowManagerGlobal;
Craig Mautner8a0da012014-05-31 15:13:37 -070096import android.view.WindowManagerInternal;
Craig Mautnerae446592012-12-06 19:05:05 -080097import android.view.WindowManagerPolicy;
Craig Mautnerae446592012-12-06 19:05:05 -080098import android.view.accessibility.AccessibilityEvent;
Svetoslav8e3feb12014-02-24 13:46:47 -080099import android.view.accessibility.AccessibilityManager;
Craig Mautnerae446592012-12-06 19:05:05 -0800100import android.view.animation.Animation;
Jorim Jaggi76a16232014-08-08 17:00:47 +0200101import android.view.animation.AnimationSet;
Craig Mautnerae446592012-12-06 19:05:05 -0800102import android.view.animation.AnimationUtils;
103
104import com.android.internal.R;
Jorim Jaggi380ecb82014-03-14 17:25:20 +0100105import com.android.internal.policy.IKeyguardService;
106import com.android.internal.policy.IKeyguardServiceConstants;
Craig Mautnerae446592012-12-06 19:05:05 -0800107import com.android.internal.policy.PolicyManager;
Jim Miller5ecd8112013-01-09 18:50:26 -0800108import com.android.internal.policy.impl.keyguard.KeyguardServiceDelegate;
Craig Mautner8a0da012014-05-31 15:13:37 -0700109import com.android.internal.policy.impl.keyguard.KeyguardServiceDelegate.ShowListener;
Craig Mautnerae446592012-12-06 19:05:05 -0800110import com.android.internal.statusbar.IStatusBarService;
Craig Mautnerae446592012-12-06 19:05:05 -0800111import com.android.internal.widget.PointerLocationView;
Craig Mautner8a0da012014-05-31 15:13:37 -0700112import com.android.server.LocalServices;
Craig Mautnerae446592012-12-06 19:05:05 -0800113
114import java.io.File;
115import java.io.FileReader;
116import java.io.IOException;
117import java.io.PrintWriter;
Craig Mautner2bc789b2014-03-19 19:48:38 -0700118import java.util.HashSet;
Craig Mautnerae446592012-12-06 19:05:05 -0800119
Dianne Hackbornc652de82013-02-15 16:32:56 -0800120import static android.view.WindowManager.LayoutParams.*;
Jeff Brownac143512012-04-05 18:57:33 -0700121import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_ABSENT;
122import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_OPEN;
123import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_CLOSED;
Michael Wright3818c922014-09-02 13:59:07 -0700124import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVER_ABSENT;
125import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_UNCOVERED;
126import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVERED;
Dianne Hackborn08743722009-12-21 12:16:51 -0800127
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800128/**
The Android Open Source Project0727d222009-03-11 12:11:58 -0700129 * WindowManagerPolicy implementation for the Android phone UI. This
130 * introduces a new method suffix, Lp, for an internal lock of the
131 * PhoneWindowManager. This is used to protect some internal state, and
John Spurlock04db1762013-05-13 12:46:41 -0400132 * 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 -0700133 * of both of those when held.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800134 */
135public class PhoneWindowManager implements WindowManagerPolicy {
136 static final String TAG = "WindowManager";
137 static final boolean DEBUG = false;
Joe Onorato43a17652011-04-06 19:22:23 -0700138 static final boolean localLOGV = false;
The Android Open Source Project11267662009-03-18 17:39:47 -0700139 static final boolean DEBUG_LAYOUT = false;
Jeff Brown40013652012-05-16 21:22:36 -0700140 static final boolean DEBUG_INPUT = false;
Craig Mautner6fbda632012-07-03 09:26:39 -0700141 static final boolean DEBUG_STARTING_WINDOW = false;
Craig Mautner8a0da012014-05-31 15:13:37 -0700142 static final boolean DEBUG_WAKEUP = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800143 static final boolean SHOW_STARTING_ANIMATIONS = true;
144 static final boolean SHOW_PROCESSES_ON_ALT_MENU = false;
Joe Onoratod208e702010-10-08 16:22:43 -0400145
Daniel Sandler6396c722013-04-16 20:19:09 -0400146 // Whether to allow dock apps with METADATA_DOCK_HOME to temporarily take over the Home key.
147 // No longer recommended for desk docks; still useful in car docks.
148 static final boolean ENABLE_CAR_DOCK_HOME_CAPTURE = true;
149 static final boolean ENABLE_DESK_DOCK_HOME_CAPTURE = false;
150
Jeff Brown6d8fd272014-05-20 21:24:38 -0700151 static final int SHORT_PRESS_POWER_NOTHING = 0;
152 static final int SHORT_PRESS_POWER_GO_TO_SLEEP = 1;
153 static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP = 2;
154 static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME = 3;
155
Joe Onoratod208e702010-10-08 16:22:43 -0400156 static final int LONG_PRESS_POWER_NOTHING = 0;
157 static final int LONG_PRESS_POWER_GLOBAL_ACTIONS = 1;
158 static final int LONG_PRESS_POWER_SHUT_OFF = 2;
Jeff Brown9a538ee2012-08-20 14:56:57 -0700159 static final int LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM = 3;
Michael Jurka3b1fc472011-06-13 10:54:40 -0700160
161 // These need to match the documentation/constant in
162 // core/res/res/values/config.xml
Joe Onorato46b0d682010-11-22 17:37:27 -0800163 static final int LONG_PRESS_HOME_NOTHING = 0;
Michael Wrightc9ebea72013-01-16 19:25:02 -0800164 static final int LONG_PRESS_HOME_RECENT_SYSTEM_UI = 1;
Jeff Browncaca8812013-05-09 13:34:33 -0700165 static final int LONG_PRESS_HOME_ASSIST = 2;
166
167 static final int DOUBLE_TAP_HOME_NOTHING = 0;
168 static final int DOUBLE_TAP_HOME_RECENT_SYSTEM_UI = 1;
Joe Onorato46b0d682010-11-22 17:37:27 -0800169
Dianne Hackborn5cb8d792009-05-21 17:34:15 -0700170 static final int APPLICATION_MEDIA_SUBLAYER = -2;
171 static final int APPLICATION_MEDIA_OVERLAY_SUBLAYER = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800172 static final int APPLICATION_PANEL_SUBLAYER = 1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800173 static final int APPLICATION_SUB_PANEL_SUBLAYER = 2;
Craig Mautner88400d32012-09-30 12:35:45 -0700174
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800175 static public final String SYSTEM_DIALOG_REASON_KEY = "reason";
176 static public final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions";
177 static public final String SYSTEM_DIALOG_REASON_RECENT_APPS = "recentapps";
Joe Onoratof275f0c2009-11-24 16:11:13 -0500178 static public final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey";
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700179 static public final String SYSTEM_DIALOG_REASON_ASSIST = "assist";
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800180
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700181 /**
182 * These are the system UI flags that, when changing, can cause the layout
183 * of the screen to change.
184 */
185 static final int SYSTEM_UI_CHANGING_LAYOUT =
John Spurlocke1f366f2013-08-05 12:22:40 -0400186 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlock7f4820a2013-10-08 12:54:35 -0400187 | View.SYSTEM_UI_FLAG_FULLSCREEN
188 | View.STATUS_BAR_TRANSLUCENT
Adrian Roosea562512014-05-05 13:33:03 +0200189 | View.NAVIGATION_BAR_TRANSLUCENT
190 | View.SYSTEM_UI_TRANSPARENT;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700191
John Spurlock7b414672014-07-18 13:02:39 -0400192 private static final AudioAttributes VIBRATION_ATTRIBUTES = new AudioAttributes.Builder()
193 .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
194 .setUsage(AudioAttributes.USAGE_ASSISTANCE_SONIFICATION)
195 .build();
196
Jim Miller5ecd8112013-01-09 18:50:26 -0800197 /**
198 * Keyguard stuff
199 */
200 private WindowState mKeyguardScrim;
Jorim Jaggi380ecb82014-03-14 17:25:20 +0100201 private boolean mKeyguardHidden;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700202 private boolean mKeyguardDrawnOnce;
Jim Miller5ecd8112013-01-09 18:50:26 -0800203
Jeff Brown6651a632011-11-28 12:59:11 -0800204 /* Table of Application Launch keys. Maps from key codes to intent categories.
205 *
206 * These are special keys that are used to launch particular kinds of applications,
207 * such as a web browser. HID defines nearly a hundred of them in the Consumer (0x0C)
208 * usage page. We don't support quite that many yet...
209 */
210 static SparseArray<String> sApplicationLaunchKeyCategories;
211 static {
212 sApplicationLaunchKeyCategories = new SparseArray<String>();
213 sApplicationLaunchKeyCategories.append(
214 KeyEvent.KEYCODE_EXPLORER, Intent.CATEGORY_APP_BROWSER);
215 sApplicationLaunchKeyCategories.append(
216 KeyEvent.KEYCODE_ENVELOPE, Intent.CATEGORY_APP_EMAIL);
217 sApplicationLaunchKeyCategories.append(
218 KeyEvent.KEYCODE_CONTACTS, Intent.CATEGORY_APP_CONTACTS);
219 sApplicationLaunchKeyCategories.append(
220 KeyEvent.KEYCODE_CALENDAR, Intent.CATEGORY_APP_CALENDAR);
221 sApplicationLaunchKeyCategories.append(
222 KeyEvent.KEYCODE_MUSIC, Intent.CATEGORY_APP_MUSIC);
223 sApplicationLaunchKeyCategories.append(
224 KeyEvent.KEYCODE_CALCULATOR, Intent.CATEGORY_APP_CALCULATOR);
225 }
226
Craig Mautnerc3daedd2014-09-13 11:17:23 -0700227 /** Amount of time (in milliseconds) to wait for windows drawn before powering on. */
228 static final int WAITING_FOR_DRAWN_TIMEOUT = 1000;
229
Dianne Hackborndf89e652011-10-06 22:35:11 -0700230 /**
231 * Lock protecting internal state. Must not call out into window
232 * manager with lock held. (This lock will be acquired in places
233 * where the window manager is calling in with its own lock held.)
234 */
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800235 private final Object mLock = new Object();
Dianne Hackborndf89e652011-10-06 22:35:11 -0700236
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800237 Context mContext;
238 IWindowManager mWindowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700239 WindowManagerFuncs mWindowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -0700240 WindowManagerInternal mWindowManagerInternal;
Jeff Brown96307042012-07-27 15:51:34 -0700241 PowerManager mPowerManager;
Jose Lima9546b202014-07-02 17:21:51 -0700242 DreamManagerInternal mDreamManagerInternal;
Joe Onorato93056472010-09-10 10:30:46 -0400243 IStatusBarService mStatusBarService;
Jeff Browncaca8812013-05-09 13:34:33 -0700244 boolean mPreloadedRecentApps;
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700245 final Object mServiceAquireLock = new Object();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800246 Vibrator mVibrator; // Vibrator for giving feedback of orientation changes
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700247 SearchManager mSearchManager;
Svetoslav8e3feb12014-02-24 13:46:47 -0800248 AccessibilityManager mAccessibilityManager;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800249
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700250 // Vibrator pattern for haptic feedback of a long press.
251 long[] mLongPressVibePattern;
Craig Mautner88400d32012-09-30 12:35:45 -0700252
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700253 // Vibrator pattern for haptic feedback of virtual key press.
254 long[] mVirtualKeyVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700255
Amith Yamasanic33cb712010-02-10 15:21:49 -0800256 // Vibrator pattern for a short vibration.
257 long[] mKeyboardTapVibePattern;
258
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -0700259 // Vibrator pattern for a short vibration when tapping on an hour/minute tick of a Clock.
260 long[] mClockTickVibePattern;
261
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -0700262 // Vibrator pattern for a short vibration when tapping on a day/month/year date of a Calendar.
263 long[] mCalendarDateVibePattern;
264
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700265 // Vibrator pattern for haptic feedback during boot when safe mode is disabled.
266 long[] mSafeModeDisabledVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700267
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700268 // Vibrator pattern for haptic feedback during boot when safe mode is enabled.
269 long[] mSafeModeEnabledVibePattern;
Romain Guy8154cd32010-03-29 14:41:15 -0700270
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800271 /** If true, hitting shift & menu will broadcast Intent.ACTION_BUG_REPORT */
272 boolean mEnableShiftMenuBugReports = false;
Mike Lockwoodd747dc82011-09-13 16:28:22 -0400273
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800274 boolean mSafeMode;
275 WindowState mStatusBar = null;
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700276 int mStatusBarHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400277 WindowState mNavigationBar = null;
Daniel Sandler36412a72011-08-04 09:35:13 -0400278 boolean mHasNavigationBar = false;
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700279 boolean mCanHideNavigationBar = false;
Daniel Sandler4a066c52012-04-20 14:49:13 -0400280 boolean mNavigationBarCanMove = false; // can the navigation bar ever move to the side?
281 boolean mNavigationBarOnBottom = true; // is the navigation bar on the bottom *right now*?
282 int[] mNavigationBarHeightForRotation = new int[4];
283 int[] mNavigationBarWidthForRotation = new int[4];
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400284
Craig Mautnera631d492014-08-05 15:16:01 -0700285 boolean mBootMessageNeedsHiding;
Jim Miller5ecd8112013-01-09 18:50:26 -0800286 KeyguardServiceDelegate mKeyguardDelegate;
Craig Mautner13f6ea72014-06-23 14:57:02 -0700287 final Runnable mWindowManagerDrawCallback = new Runnable() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700288 @Override
Craig Mautner13f6ea72014-06-23 14:57:02 -0700289 public void run() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700290 if (DEBUG_WAKEUP) Slog.i(TAG, "All windows ready for display!");
291 mHandler.sendEmptyMessage(MSG_WINDOW_MANAGER_DRAWN_COMPLETE);
292 }
293 };
294 final ShowListener mKeyguardDelegateCallback = new ShowListener() {
295 @Override
296 public void onShown(IBinder windowToken) {
297 if (DEBUG_WAKEUP) Slog.d(TAG, "mKeyguardDelegate.ShowListener.onShown.");
298 mHandler.sendEmptyMessage(MSG_KEYGUARD_DRAWN_COMPLETE);
299 }
300 };
301
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800302 GlobalActions mGlobalActions;
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700303 volatile boolean mPowerKeyHandled; // accessed from input reader and handler thread
304 boolean mPendingPowerKeyUpCanceled;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800305 Handler mHandler;
satok1bc0a492012-04-25 22:47:12 +0900306 WindowState mLastInputMethodWindow = null;
307 WindowState mLastInputMethodTargetWindow = null;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800308
Winson Chungd42a6cf2014-06-03 16:24:04 -0700309 boolean mRecentsVisible;
Winson Chung1e8d71b2014-05-16 17:05:22 -0700310 int mRecentAppsHeldModifiers;
Jeff Browncf39bdf2012-05-18 14:41:19 -0700311 boolean mLanguageSwitchKeyPressed;
Jeff Brown68b909d2011-12-07 16:36:01 -0800312
Jeff Brown2e7760e2012-04-11 15:14:55 -0700313 int mLidState = LID_ABSENT;
Michael Wright3818c922014-09-02 13:59:07 -0700314 int mCameraLensCoverState = CAMERA_LENS_COVER_ABSENT;
Jeff Browndaa37532012-05-01 15:54:03 -0700315 boolean mHaveBuiltInKeyboard;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800316
Dianne Hackbornc777e072010-02-12 13:07:59 -0800317 boolean mSystemReady;
Dianne Hackbornba24e4d2011-09-01 11:17:06 -0700318 boolean mSystemBooted;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800319 boolean mHdmiPlugged;
Jeff Brown4f5fa282014-06-12 19:19:15 -0700320 IUiModeManager mUiModeManager;
Daniel Sandler6396c722013-04-16 20:19:09 -0400321 int mUiMode;
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700322 int mDockMode = Intent.EXTRA_DOCK_STATE_UNDOCKED;
Mike Lockwood1753f7f2009-08-24 14:49:07 -0700323 int mLidOpenRotation;
Mike Lockwood2d1efbd2009-09-16 12:15:53 -0400324 int mCarDockRotation;
325 int mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -0700326 int mUndockedHdmiRotation;
327 int mDemoHdmiRotation;
328 boolean mDemoHdmiRotationLock;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400329
Jeff Browna20dda42014-05-27 20:57:24 -0700330 boolean mWakeGestureEnabledSetting;
331 MyWakeGestureListener mWakeGestureListener;
332
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700333 // Default display does not rotate, apps that require non-default orientation will have to
334 // have the orientation emulated.
335 private boolean mForceDefaultOrientation = false;
336
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400337 int mUserRotationMode = WindowManagerPolicy.USER_ROTATION_FREE;
338 int mUserRotation = Surface.ROTATION_0;
Jeff Brown207673cd2012-06-05 17:47:11 -0700339 boolean mAccelerometerDefault;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400340
Jeff Brownbcdfc622014-03-06 19:13:04 -0800341 boolean mSupportAutoRotation;
Jeff Brownd3187e32011-09-21 19:26:44 -0700342 int mAllowAllRotations = -1;
Mike Lockwoode9867d22009-09-20 01:59:02 -0400343 boolean mCarDockEnablesAccelerometer;
344 boolean mDeskDockEnablesAccelerometer;
Dianne Hackborn2862fff2009-09-15 22:56:29 -0700345 int mLidKeyboardAccessibility;
346 int mLidNavigationAccessibility;
Jeff Brownc458ce92012-04-30 14:58:40 -0700347 boolean mLidControlsSleep;
Jeff Brown6d8fd272014-05-20 21:24:38 -0700348 int mShortPressOnPowerBehavior = -1;
Joe Onoratod208e702010-10-08 16:22:43 -0400349 int mLongPressOnPowerBehavior = -1;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700350 boolean mAwake;
351 boolean mScreenOnEarly;
352 boolean mScreenOnFully;
353 ScreenOnListener mScreenOnListener;
354 boolean mKeyguardDrawComplete;
355 boolean mWindowManagerDrawComplete;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800356 boolean mOrientationSensorEnabled = false;
357 int mCurrentAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800358 boolean mHasSoftInput = false;
Daniel Sandlerdd73ee42013-10-11 22:19:59 -0400359 boolean mTranslucentDecorEnabled = true;
Craig Mautner967212c2013-04-13 21:10:58 -0700360
Jeff Brown70825162012-03-28 17:27:48 -0700361 int mPointerLocationMode = 0; // guarded by mLock
Joe Onorato664644d2011-01-23 17:53:23 -0800362
363 // The last window we were told about in focusChanged.
364 WindowState mFocusedWindow;
Dianne Hackborne0f085d2011-11-30 18:41:15 -0800365 IApplicationToken mFocusedApp;
Joe Onorato664644d2011-01-23 17:53:23 -0800366
Jeff Brown70825162012-03-28 17:27:48 -0700367 PointerLocationView mPointerLocationView;
Jeff Brown32cbc38552011-12-01 14:01:49 -0800368
Dianne Hackbornc652de82013-02-15 16:32:56 -0800369 // The current size of the screen; really; extends into the overscan area of
370 // the screen and doesn't account for any system elements like the status bar.
371 int mOverscanScreenLeft, mOverscanScreenTop;
372 int mOverscanScreenWidth, mOverscanScreenHeight;
373 // The current visible size of the screen; really; (ir)regardless of whether the status
374 // bar can be hidden but not extending into the overscan area.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800375 int mUnrestrictedScreenLeft, mUnrestrictedScreenTop;
376 int mUnrestrictedScreenWidth, mUnrestrictedScreenHeight;
Dianne Hackborn313440842013-02-19 19:22:59 -0800377 // Like mOverscanScreen*, but allowed to move into the overscan region where appropriate.
378 int mRestrictedOverscanScreenLeft, mRestrictedOverscanScreenTop;
379 int mRestrictedOverscanScreenWidth, mRestrictedOverscanScreenHeight;
Dianne Hackborn82de1ae2010-10-28 11:28:39 -0700380 // The current size of the screen; these may be different than (0,0)-(dw,dh)
381 // if the status bar can't be hidden; in that case it effectively carves out
382 // that area of the display from all other windows.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800383 int mRestrictedScreenLeft, mRestrictedScreenTop;
384 int mRestrictedScreenWidth, mRestrictedScreenHeight;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700385 // During layout, the current screen borders accounting for any currently
386 // visible system UI elements.
387 int mSystemLeft, mSystemTop, mSystemRight, mSystemBottom;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700388 // For applications requesting stable content insets, these are them.
389 int mStableLeft, mStableTop, mStableRight, mStableBottom;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -0700390 // For applications requesting stable content insets but have also set the
391 // fullscreen window flag, these are the stable dimensions without the status bar.
392 int mStableFullscreenLeft, mStableFullscreenTop;
393 int mStableFullscreenRight, mStableFullscreenBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800394 // During layout, the current screen borders with all outer decoration
395 // (status bar, input method dock) accounted for.
396 int mCurLeft, mCurTop, mCurRight, mCurBottom;
397 // During layout, the frame in which content should be displayed
398 // to the user, accounting for all screen decoration except for any
399 // space they deem as available for other content. This is usually
400 // the same as mCur*, but may be larger if the screen decor has supplied
401 // content insets.
402 int mContentLeft, mContentTop, mContentRight, mContentBottom;
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700403 // During layout, the frame in which voice content should be displayed
404 // to the user, accounting for all screen decoration except for any
405 // space they deem as available for other content.
406 int mVoiceContentLeft, mVoiceContentTop, mVoiceContentRight, mVoiceContentBottom;
Dianne Hackborn8e11ef02010-11-18 19:47:42 -0800407 // During layout, the current screen borders along which input method
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800408 // windows are placed.
409 int mDockLeft, mDockTop, mDockRight, mDockBottom;
410 // During layout, the layer at which the doc window is placed.
411 int mDockLayer;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700412 // During layout, this is the layer of the status bar.
413 int mStatusBarLayer;
Dianne Hackborne26ab702011-10-16 13:21:33 -0700414 int mLastSystemUiFlags;
415 // Bits that we are in the process of clearing, so we want to prevent
416 // them from being set by applications until everything has been updated
417 // to have them clear.
418 int mResettingSystemUiFlags = 0;
419 // Bits that we are currently always keeping cleared.
420 int mForceClearedSystemUiFlags = 0;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -0800421 // What we last reported to system UI about whether the compatibility
422 // menu needs to be displayed.
423 boolean mLastFocusNeedsMenu = false;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700424
425 FakeWindow mHideNavFakeWindow = null;
426
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800427 static final Rect mTmpParentFrame = new Rect();
428 static final Rect mTmpDisplayFrame = new Rect();
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800429 static final Rect mTmpOverscanFrame = new Rect();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800430 static final Rect mTmpContentFrame = new Rect();
431 static final Rect mTmpVisibleFrame = new Rect();
John Spurlock46646232013-09-30 22:32:42 -0400432 static final Rect mTmpDecorFrame = new Rect();
Adrian Roosfa104232014-06-20 16:10:14 -0700433 static final Rect mTmpStableFrame = new Rect();
Dianne Hackborn1f903c32011-09-13 19:18:06 -0700434 static final Rect mTmpNavigationFrame = new Rect();
Craig Mautner967212c2013-04-13 21:10:58 -0700435
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800436 WindowState mTopFullscreenOpaqueWindowState;
Craig Mautner2bc789b2014-03-19 19:48:38 -0700437 HashSet<IApplicationToken> mAppsToBeHidden = new HashSet<IApplicationToken>();
Jorim Jaggic13fcac2014-09-11 17:36:57 +0200438 HashSet<IApplicationToken> mAppsThatDismissKeyguard = new HashSet<IApplicationToken>();
Joe Onorato93056472010-09-10 10:30:46 -0400439 boolean mTopIsFullscreen;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800440 boolean mForceStatusBar;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -0700441 boolean mForceStatusBarFromKeyguard;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700442 boolean mHideLockScreen;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -0800443 boolean mForcingShowNavBar;
444 int mForcingShowNavBarLayer;
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700445
446 // States of keyguard dismiss.
447 private static final int DISMISS_KEYGUARD_NONE = 0; // Keyguard not being dismissed.
448 private static final int DISMISS_KEYGUARD_START = 1; // Keyguard needs to be dismissed.
449 private static final int DISMISS_KEYGUARD_CONTINUE = 2; // Keyguard has been dismissed.
450 int mDismissKeyguard = DISMISS_KEYGUARD_NONE;
451
452 /** The window that is currently dismissing the keyguard. Dismissing the keyguard must only
453 * be done once per window. */
454 private WindowState mWinDismissingKeyguard;
455
Craig Mautnerc9457fa2014-06-06 14:27:48 -0700456 /** The window that is currently showing "over" the keyguard. If there is an app window
457 * belonging to another app on top of this the keyguard shows. If there is a fullscreen
458 * app window under this, still dismiss the keyguard but don't show the app underneath. Show
459 * the wallpaper. */
460 private WindowState mWinShowWhenLocked;
461
Dianne Hackborn7ad44382012-10-18 17:46:00 -0700462 boolean mShowingLockscreen;
463 boolean mShowingDream;
464 boolean mDreamingLockscreen;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800465 boolean mHomePressed;
Jeff Browncaca8812013-05-09 13:34:33 -0700466 boolean mHomeConsumed;
467 boolean mHomeDoubleTapPending;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800468 Intent mHomeIntent;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700469 Intent mCarDockIntent;
470 Intent mDeskDockIntent;
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700471 boolean mSearchKeyShortcutPending;
472 boolean mConsumeSearchKeyUp;
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700473 boolean mAssistKeyLongPressed;
Michael Wright6a62e552014-06-03 19:19:48 -0700474 boolean mPendingMetaAction;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800475
Mike Lockwood28569302010-01-28 11:54:40 -0500476 // support for activating the lock screen while the screen is on
477 boolean mAllowLockscreenWhenOn;
478 int mLockScreenTimeout;
479 boolean mLockScreenTimerActive;
480
David Brownbaf8d092010-03-08 21:52:59 -0800481 // Behavior of ENDCALL Button. (See Settings.System.END_BUTTON_BEHAVIOR.)
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800482 int mEndcallBehavior;
David Brownbaf8d092010-03-08 21:52:59 -0800483
484 // Behavior of POWER button while in-call and screen on.
485 // (See Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR.)
486 int mIncallPowerBehavior;
487
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700488 Display mDisplay;
489
Dianne Hackborn9d132642011-04-21 17:26:39 -0700490 int mLandscapeRotation = 0; // default landscape rotation
491 int mSeascapeRotation = 0; // "other" landscape rotation, 180 degrees from mLandscapeRotation
492 int mPortraitRotation = 0; // default portrait rotation
493 int mUpsideDownRotation = 0; // "other" portrait rotation
Mitsuru Oshima831d0d92009-06-16 18:27:18 -0700494
Dianne Hackbornc652de82013-02-15 16:32:56 -0800495 int mOverscanLeft = 0;
496 int mOverscanTop = 0;
497 int mOverscanRight = 0;
498 int mOverscanBottom = 0;
499
Joe Onorato46b0d682010-11-22 17:37:27 -0800500 // What we do when the user long presses on home
Jeff Browncaca8812013-05-09 13:34:33 -0700501 private int mLongPressOnHomeBehavior;
502
503 // What we do when the user double-taps on home
504 private int mDoubleTapOnHomeBehavior;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800505
Winson Chung9112ec32011-06-27 13:15:32 -0700506 // Screenshot trigger states
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700507 // Time to volume and power must be pressed within this interval of each other.
508 private static final long SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS = 150;
Winson Chung1cea2f32012-10-08 20:42:01 -0700509 // Increase the chord delay when taking a screenshot from the keyguard
510 private static final float KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER = 2.5f;
Christopher Tatee90585f2012-03-05 18:56:25 -0800511 private boolean mScreenshotChordEnabled;
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700512 private boolean mVolumeDownKeyTriggered;
513 private long mVolumeDownKeyTime;
514 private boolean mVolumeDownKeyConsumedByScreenshotChord;
515 private boolean mVolumeUpKeyTriggered;
516 private boolean mPowerKeyTriggered;
517 private long mPowerKeyTime;
Winson Chung9112ec32011-06-27 13:15:32 -0700518
Michael Wrightb854e242013-02-05 17:54:02 -0800519 /* The number of steps between min and max brightness */
520 private static final int BRIGHTNESS_STEPS = 10;
521
Christopher Tate5e08af02012-09-21 17:17:22 -0700522 SettingsObserver mSettingsObserver;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800523 ShortcutManager mShortcutManager;
524 PowerManager.WakeLock mBroadcastWakeLock;
Jeff Brown40013652012-05-16 21:22:36 -0700525 boolean mHavePendingMediaKeyRepeatWithWakeLock;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800526
Craig Mautnerd625ab22013-09-06 13:40:31 -0700527 private int mCurrentUserId;
528
Justin Kohd378ad72013-04-01 12:18:26 -0700529 // Maps global key codes to the components that will handle them.
530 private GlobalKeyManager mGlobalKeyManager;
531
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700532 // Fallback actions by key code.
533 private final SparseArray<KeyCharacterMap.FallbackAction> mFallbackActions =
534 new SparseArray<KeyCharacterMap.FallbackAction>();
Jeff Brown49ed71d2010-12-06 17:13:33 -0800535
Jorim Jaggi76a16232014-08-08 17:00:47 +0200536 private final LogDecelerateInterpolator mLogDecelerateInterpolator
537 = new LogDecelerateInterpolator(100, 0);
538
Jeff Brown70825162012-03-28 17:27:48 -0700539 private static final int MSG_ENABLE_POINTER_LOCATION = 1;
540 private static final int MSG_DISABLE_POINTER_LOCATION = 2;
Jeff Brown40013652012-05-16 21:22:36 -0700541 private static final int MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK = 3;
542 private static final int MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK = 4;
Craig Mautner8a0da012014-05-31 15:13:37 -0700543 private static final int MSG_KEYGUARD_DRAWN_COMPLETE = 5;
544 private static final int MSG_KEYGUARD_DRAWN_TIMEOUT = 6;
545 private static final int MSG_WINDOW_MANAGER_DRAWN_COMPLETE = 7;
Craig Mautner84984fa2014-06-19 11:19:20 -0700546 private static final int MSG_DISPATCH_SHOW_RECENTS = 9;
Alan Viverettee34560b22014-07-10 14:50:06 -0700547 private static final int MSG_DISPATCH_SHOW_GLOBAL_ACTIONS = 10;
Craig Mautnera631d492014-08-05 15:16:01 -0700548 private static final int MSG_HIDE_BOOT_MESSAGE = 11;
Michael Wright869a67c2014-08-26 19:33:06 -0700549 private static final int MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK = 12;
Jeff Brown70825162012-03-28 17:27:48 -0700550
551 private class PolicyHandler extends Handler {
552 @Override
553 public void handleMessage(Message msg) {
554 switch (msg.what) {
555 case MSG_ENABLE_POINTER_LOCATION:
556 enablePointerLocation();
557 break;
558 case MSG_DISABLE_POINTER_LOCATION:
559 disablePointerLocation();
560 break;
Jeff Brown40013652012-05-16 21:22:36 -0700561 case MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK:
562 dispatchMediaKeyWithWakeLock((KeyEvent)msg.obj);
563 break;
564 case MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK:
565 dispatchMediaKeyRepeatWithWakeLock((KeyEvent)msg.obj);
566 break;
Craig Mautner84984fa2014-06-19 11:19:20 -0700567 case MSG_DISPATCH_SHOW_RECENTS:
568 showRecentApps(false);
569 break;
Alan Viverettee34560b22014-07-10 14:50:06 -0700570 case MSG_DISPATCH_SHOW_GLOBAL_ACTIONS:
571 showGlobalActionsInternal();
572 break;
Craig Mautner8a0da012014-05-31 15:13:37 -0700573 case MSG_KEYGUARD_DRAWN_COMPLETE:
574 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mKeyguardDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700575 finishKeyguardDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700576 break;
577 case MSG_KEYGUARD_DRAWN_TIMEOUT:
578 Slog.w(TAG, "Keyguard drawn timeout. Setting mKeyguardDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700579 finishKeyguardDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700580 break;
581 case MSG_WINDOW_MANAGER_DRAWN_COMPLETE:
582 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mWindowManagerDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700583 finishWindowsDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700584 break;
Craig Mautnera631d492014-08-05 15:16:01 -0700585 case MSG_HIDE_BOOT_MESSAGE:
586 handleHideBootMessage();
587 break;
Michael Wright869a67c2014-08-26 19:33:06 -0700588 case MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK:
589 launchVoiceAssistWithWakeLock(msg.arg1 != 0);
590 break;
Jeff Brown70825162012-03-28 17:27:48 -0700591 }
592 }
593 }
594
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800595 private UEventObserver mHDMIObserver = new UEventObserver() {
596 @Override
597 public void onUEvent(UEventObserver.UEvent event) {
598 setHdmiPlugged("1".equals(event.get("SWITCH_STATE")));
599 }
600 };
601
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800602 class SettingsObserver extends ContentObserver {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800603 SettingsObserver(Handler handler) {
604 super(handler);
605 }
David Brownbaf8d092010-03-08 21:52:59 -0800606
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800607 void observe() {
Christopher Tate5e08af02012-09-21 17:17:22 -0700608 // Observe all users' changes
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800609 ContentResolver resolver = mContext.getContentResolver();
610 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700611 Settings.System.END_BUTTON_BEHAVIOR), false, this,
612 UserHandle.USER_ALL);
David Brownbaf8d092010-03-08 21:52:59 -0800613 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700614 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR), false, this,
615 UserHandle.USER_ALL);
Jeff Browna20dda42014-05-27 20:57:24 -0700616 resolver.registerContentObserver(Settings.Secure.getUriFor(
617 Settings.Secure.WAKE_GESTURE_ENABLED), false, this,
618 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800619 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700620 Settings.System.ACCELEROMETER_ROTATION), false, this,
621 UserHandle.USER_ALL);
Mike Lockwood28569302010-01-28 11:54:40 -0500622 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700623 Settings.System.USER_ROTATION), false, this,
624 UserHandle.USER_ALL);
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400625 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700626 Settings.System.SCREEN_OFF_TIMEOUT), false, this,
627 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800628 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700629 Settings.System.POINTER_LOCATION), false, this,
630 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800631 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700632 Settings.Secure.DEFAULT_INPUT_METHOD), false, this,
633 UserHandle.USER_ALL);
John Spurlockd9b70bd2014-02-06 17:02:44 -0500634 resolver.registerContentObserver(Settings.Secure.getUriFor(
John Spurlockf1a36642013-10-12 17:50:42 -0400635 Settings.Secure.IMMERSIVE_MODE_CONFIRMATIONS), false, this,
Christopher Tate5e08af02012-09-21 17:17:22 -0700636 UserHandle.USER_ALL);
John Spurlockc6d1c602014-01-17 15:22:06 -0500637 resolver.registerContentObserver(Settings.Global.getUriFor(
638 Settings.Global.POLICY_CONTROL), false, this,
639 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800640 updateSettings();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800641 }
642
643 @Override public void onChange(boolean selfChange) {
Dianne Hackbornc777e072010-02-12 13:07:59 -0800644 updateSettings();
Jeff Brown01a98dd2011-09-20 15:08:29 -0700645 updateRotation(false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800646 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800647 }
Craig Mautner967212c2013-04-13 21:10:58 -0700648
Jeff Browna20dda42014-05-27 20:57:24 -0700649 class MyWakeGestureListener extends WakeGestureListener {
650 MyWakeGestureListener(Context context, Handler handler) {
651 super(context, handler);
652 }
653
654 @Override
655 public void onWakeUp() {
656 synchronized (mLock) {
657 if (shouldEnableWakeGestureLp()) {
Jeff Browne07b94b2014-06-18 15:56:27 -0700658 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
Jeff Browna20dda42014-05-27 20:57:24 -0700659 mPowerManager.wakeUp(SystemClock.uptimeMillis());
660 }
661 }
662 }
663 }
664
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800665 class MyOrientationListener extends WindowOrientationListener {
Craig Mautnereee29c42013-01-17 14:44:34 -0800666 MyOrientationListener(Context context, Handler handler) {
667 super(context, handler);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800668 }
Craig Mautner967212c2013-04-13 21:10:58 -0700669
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800670 @Override
Jeff Brownc0347aa2011-09-23 17:26:09 -0700671 public void onProposedRotationChanged(int rotation) {
Craig Mautnereda67292013-04-28 13:50:14 -0700672 if (localLOGV) Slog.v(TAG, "onProposedRotationChanged, rotation=" + rotation);
Jeff Brown01a98dd2011-09-20 15:08:29 -0700673 updateRotation(false);
674 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800675 }
676 MyOrientationListener mOrientationListener;
677
John Spurlock27735a42013-08-14 17:57:38 -0400678 private final BarController mStatusBarController = new BarController("StatusBar",
John Spurlock5b9145b2013-08-20 15:13:47 -0400679 View.STATUS_BAR_TRANSIENT,
680 View.STATUS_BAR_UNHIDE,
John Spurlockbd957402013-10-03 11:38:39 -0400681 View.STATUS_BAR_TRANSLUCENT,
682 StatusBarManager.WINDOW_STATUS_BAR,
683 WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
John Spurlock5b9145b2013-08-20 15:13:47 -0400684
John Spurlock27735a42013-08-14 17:57:38 -0400685 private final BarController mNavigationBarController = new BarController("NavigationBar",
John Spurlock5b9145b2013-08-20 15:13:47 -0400686 View.NAVIGATION_BAR_TRANSIENT,
687 View.NAVIGATION_BAR_UNHIDE,
John Spurlockbd957402013-10-03 11:38:39 -0400688 View.NAVIGATION_BAR_TRANSLUCENT,
689 StatusBarManager.WINDOW_NAVIGATION_BAR,
690 WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
John Spurlock5b9145b2013-08-20 15:13:47 -0400691
John Spurlockf1a36642013-10-12 17:50:42 -0400692 private ImmersiveModeConfirmation mImmersiveModeConfirmation;
John Spurlock32beb2c2013-03-11 10:16:47 -0400693
Craig Mautner037aa8d2013-06-07 10:35:44 -0700694 private SystemGesturesPointerEventListener mSystemGestures;
John Spurlock32beb2c2013-03-11 10:16:47 -0400695
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700696 IStatusBarService getStatusBarService() {
697 synchronized (mServiceAquireLock) {
698 if (mStatusBarService == null) {
699 mStatusBarService = IStatusBarService.Stub.asInterface(
700 ServiceManager.getService("statusbar"));
701 }
702 return mStatusBarService;
703 }
704 }
705
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700706 /*
707 * We always let the sensor be switched on by default except when
708 * the user has explicitly disabled sensor based rotation or when the
709 * screen is switched off.
710 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700711 boolean needSensorRunningLp() {
Jeff Brownbcdfc622014-03-06 19:13:04 -0800712 if (mSupportAutoRotation) {
713 if (mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
714 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
715 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT
716 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) {
717 // If the application has explicitly requested to follow the
718 // orientation, then we need to turn the sensor on.
719 return true;
720 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800721 }
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700722 if ((mCarDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_CAR) ||
Jeff Brown1a693182011-11-08 14:44:16 -0800723 (mDeskDockEnablesAccelerometer && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
724 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
725 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK))) {
Mike Lockwoode9867d22009-09-20 01:59:02 -0400726 // enable accelerometer if we are docked in a dock that enables accelerometer
727 // orientation management,
728 return true;
729 }
Jeff Brown207673cd2012-06-05 17:47:11 -0700730 if (mUserRotationMode == USER_ROTATION_LOCKED) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800731 // If the setting for using the sensor by default is enabled, then
732 // we will always leave it on. Note that the user could go to
733 // a window that forces an orientation that does not use the
734 // sensor and in theory we could turn it off... however, when next
735 // turning it on we won't have a good value for the current
736 // orientation for a little bit, which can cause orientation
737 // changes to lag, so we'd like to keep it always on. (It will
738 // still be turned off when the screen is off.)
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700739 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800740 }
Jeff Brownbcdfc622014-03-06 19:13:04 -0800741 return mSupportAutoRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800742 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700743
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800744 /*
745 * Various use cases for invoking this function
746 * screen turning off, should always disable listeners if already enabled
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700747 * screen turned on and current app has sensor based orientation, enable listeners
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800748 * if not already enabled
749 * screen turned on and current app does not have sensor orientation, disable listeners if
750 * already enabled
751 * screen turning on and current app has sensor based orientation, enable listeners if needed
752 * screen turning on and current app has nosensor based orientation, do nothing
753 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700754 void updateOrientationListenerLp() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800755 if (!mOrientationListener.canDetectOrientation()) {
756 // If sensor is turned off or nonexistent for some reason
757 return;
758 }
759 //Could have been invoked due to screen turning on or off or
760 //change of the currently visible window's orientation
Jeff Brown3ee549c2014-09-22 20:14:39 -0700761 if (localLOGV) Slog.v(TAG, "mScreenOnEarly=" + mScreenOnEarly
762 + ", mAwake=" + mAwake + ", mCurrentAppOrientation=" + mCurrentAppOrientation
763 + ", mOrientationSensorEnabled=" + mOrientationSensorEnabled);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800764 boolean disable = true;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700765 if (mScreenOnEarly && mAwake) {
The Android Open Source Project0727d222009-03-11 12:11:58 -0700766 if (needSensorRunningLp()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800767 disable = false;
768 //enable listener if not already enabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700769 if (!mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800770 mOrientationListener.enable();
Craig Mautnereda67292013-04-28 13:50:14 -0700771 if(localLOGV) Slog.v(TAG, "Enabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800772 mOrientationSensorEnabled = true;
773 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700774 }
775 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800776 //check if sensors need to be disabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700777 if (disable && mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800778 mOrientationListener.disable();
Craig Mautnereda67292013-04-28 13:50:14 -0700779 if(localLOGV) Slog.v(TAG, "Disabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800780 mOrientationSensorEnabled = false;
781 }
782 }
783
Jeff Brown4d396052010-10-29 21:50:21 -0700784 private void interceptPowerKeyDown(boolean handled) {
785 mPowerKeyHandled = handled;
786 if (!handled) {
Justin Kohfeabd2c2014-05-02 10:02:44 -0700787 mHandler.postDelayed(mPowerLongPress,
788 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Jeff Brown4d396052010-10-29 21:50:21 -0700789 }
790 }
791
792 private boolean interceptPowerKeyUp(boolean canceled) {
793 if (!mPowerKeyHandled) {
794 mHandler.removeCallbacks(mPowerLongPress);
795 return !canceled;
Jeff Brown4d396052010-10-29 21:50:21 -0700796 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700797 return false;
798 }
799
800 private void cancelPendingPowerKeyAction() {
801 if (!mPowerKeyHandled) {
802 mHandler.removeCallbacks(mPowerLongPress);
803 }
Jeff Brownff204712011-10-25 21:27:54 -0700804 if (mPowerKeyTriggered) {
805 mPendingPowerKeyUpCanceled = true;
806 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700807 }
808
809 private void interceptScreenshotChord() {
Christopher Tatee90585f2012-03-05 18:56:25 -0800810 if (mScreenshotChordEnabled
811 && mVolumeDownKeyTriggered && mPowerKeyTriggered && !mVolumeUpKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700812 final long now = SystemClock.uptimeMillis();
813 if (now <= mVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS
814 && now <= mPowerKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) {
815 mVolumeDownKeyConsumedByScreenshotChord = true;
816 cancelPendingPowerKeyAction();
817
Jeff Sharkey2991fa32012-12-05 18:06:43 -0800818 mHandler.postDelayed(mScreenshotRunnable, getScreenshotChordLongPressDelay());
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700819 }
820 }
821 }
822
Winson Chung1cea2f32012-10-08 20:42:01 -0700823 private long getScreenshotChordLongPressDelay() {
Jim Miller5ecd8112013-01-09 18:50:26 -0800824 if (mKeyguardDelegate.isShowing()) {
Winson Chung1cea2f32012-10-08 20:42:01 -0700825 // Double the time it takes to take a screenshot from the keyguard
826 return (long) (KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER *
Justin Kohfeabd2c2014-05-02 10:02:44 -0700827 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Winson Chung1cea2f32012-10-08 20:42:01 -0700828 }
Justin Kohfeabd2c2014-05-02 10:02:44 -0700829 return ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout();
Winson Chung1cea2f32012-10-08 20:42:01 -0700830 }
831
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700832 private void cancelPendingScreenshotChordAction() {
Jeff Sharkey2991fa32012-12-05 18:06:43 -0800833 mHandler.removeCallbacks(mScreenshotRunnable);
Jeff Brown4d396052010-10-29 21:50:21 -0700834 }
835
Jeff Brown6d8fd272014-05-20 21:24:38 -0700836 private void powerShortPress(long eventTime) {
837 if (mShortPressOnPowerBehavior < 0) {
838 mShortPressOnPowerBehavior = mContext.getResources().getInteger(
839 com.android.internal.R.integer.config_shortPressOnPowerBehavior);
840 }
841
842 switch (mShortPressOnPowerBehavior) {
843 case SHORT_PRESS_POWER_NOTHING:
844 break;
845 case SHORT_PRESS_POWER_GO_TO_SLEEP:
846 mPowerManager.goToSleep(eventTime,
Jeff Brownc12035c2014-08-13 18:52:25 -0700847 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
Jeff Brown6d8fd272014-05-20 21:24:38 -0700848 break;
849 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP:
850 mPowerManager.goToSleep(eventTime,
Jeff Brownc12035c2014-08-13 18:52:25 -0700851 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
Jeff Brown6d8fd272014-05-20 21:24:38 -0700852 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
853 break;
854 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME:
855 mPowerManager.goToSleep(eventTime,
Jeff Brownc12035c2014-08-13 18:52:25 -0700856 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
Jeff Brown6d8fd272014-05-20 21:24:38 -0700857 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
858 launchHomeFromHotKey();
859 break;
860 }
861 }
862
Jeff Brown4d396052010-10-29 21:50:21 -0700863 private final Runnable mPowerLongPress = new Runnable() {
Craig Mautnerf1b67412012-09-19 13:18:29 -0700864 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800865 public void run() {
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700866 // The context isn't read
867 if (mLongPressOnPowerBehavior < 0) {
Jeff Brown850c5b72012-10-01 15:17:22 -0700868 mLongPressOnPowerBehavior = mContext.getResources().getInteger(
869 com.android.internal.R.integer.config_longPressOnPowerBehavior);
Joe Onoratod208e702010-10-08 16:22:43 -0400870 }
Jeff Brown850c5b72012-10-01 15:17:22 -0700871 int resolvedBehavior = mLongPressOnPowerBehavior;
872 if (FactoryTest.isLongPressOnPowerOffEnabled()) {
873 resolvedBehavior = LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM;
874 }
875
876 switch (resolvedBehavior) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700877 case LONG_PRESS_POWER_NOTHING:
878 break;
879 case LONG_PRESS_POWER_GLOBAL_ACTIONS:
880 mPowerKeyHandled = true;
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -0700881 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
882 performAuditoryFeedbackForAccessibilityIfNeed();
883 }
Alan Viverettee34560b22014-07-10 14:50:06 -0700884 showGlobalActionsInternal();
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700885 break;
886 case LONG_PRESS_POWER_SHUT_OFF:
Jeff Brown9a538ee2012-08-20 14:56:57 -0700887 case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM:
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700888 mPowerKeyHandled = true;
889 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
890 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
Jeff Brown850c5b72012-10-01 15:17:22 -0700891 mWindowManagerFuncs.shutdown(resolvedBehavior == LONG_PRESS_POWER_SHUT_OFF);
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700892 break;
893 }
894 }
895 };
896
Jeff Sharkey2991fa32012-12-05 18:06:43 -0800897 private final Runnable mScreenshotRunnable = new Runnable() {
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800898 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700899 public void run() {
900 takeScreenshot();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800901 }
902 };
903
Alan Viverettee34560b22014-07-10 14:50:06 -0700904 @Override
905 public void showGlobalActions() {
906 mHandler.removeMessages(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
907 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
908 }
909
910 void showGlobalActionsInternal() {
911 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800912 if (mGlobalActions == null) {
Jeff Brown7304c342012-05-11 18:42:42 -0700913 mGlobalActions = new GlobalActions(mContext, mWindowManagerFuncs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800914 }
Mike Lockwood3a74bd32011-08-12 13:55:22 -0700915 final boolean keyguardShowing = keyguardIsShowingTq();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800916 mGlobalActions.showDialog(keyguardShowing, isDeviceProvisioned());
917 if (keyguardShowing) {
918 // since it took two seconds of long press to bring this up,
919 // poke the wake lock so they have some time to see the dialog.
Jim Miller25190572013-02-28 17:36:24 -0800920 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800921 }
922 }
923
924 boolean isDeviceProvisioned() {
Jeff Brownbf6f6f92012-09-25 15:03:20 -0700925 return Settings.Global.getInt(
926 mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800927 }
928
Maurice Lam99c6e072014-04-28 18:24:28 -0700929 boolean isUserSetupComplete() {
930 return Settings.Secure.getIntForUser(mContext.getContentResolver(),
931 Settings.Secure.USER_SETUP_COMPLETE, 0, UserHandle.USER_CURRENT) != 0;
932 }
933
Patrick Dubroyece94522011-02-23 18:35:01 -0800934 private void handleLongPressOnHome() {
Joe Onorato46b0d682010-11-22 17:37:27 -0800935 if (mLongPressOnHomeBehavior != LONG_PRESS_HOME_NOTHING) {
Jeff Browncaca8812013-05-09 13:34:33 -0700936 mHomeConsumed = true;
Joe Onorato46b0d682010-11-22 17:37:27 -0800937 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
Patrick Dubroyece94522011-02-23 18:35:01 -0800938
Jeff Browncaca8812013-05-09 13:34:33 -0700939 if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI) {
940 toggleRecentApps();
941 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_ASSIST) {
942 launchAssistAction();
Jim Millere6ad1a82010-08-20 19:25:39 -0700943 }
944 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800945 }
Patrick Dubroyece94522011-02-23 18:35:01 -0800946
Jeff Browncaca8812013-05-09 13:34:33 -0700947 private void handleDoubleTapOnHome() {
948 if (mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
949 mHomeConsumed = true;
950 toggleRecentApps();
951 }
952 }
953
954 private final Runnable mHomeDoubleTapTimeoutRunnable = new Runnable() {
955 @Override
956 public void run() {
957 if (mHomeDoubleTapPending) {
958 mHomeDoubleTapPending = false;
959 launchHomeFromHotKey();
960 }
961 }
962 };
963
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800964 /** {@inheritDoc} */
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800965 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800966 public void init(Context context, IWindowManager windowManager,
Jeff Brown96307042012-07-27 15:51:34 -0700967 WindowManagerFuncs windowManagerFuncs) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800968 mContext = context;
969 mWindowManager = windowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700970 mWindowManagerFuncs = windowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -0700971 mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class);
Jose Lima9546b202014-07-02 17:21:51 -0700972 mDreamManagerInternal = LocalServices.getService(DreamManagerInternal.class);
Craig Mautner8a0da012014-05-31 15:13:37 -0700973
Jeff Brown70825162012-03-28 17:27:48 -0700974 mHandler = new PolicyHandler();
Jeff Browna20dda42014-05-27 20:57:24 -0700975 mWakeGestureListener = new MyWakeGestureListener(mContext, mHandler);
Craig Mautnereee29c42013-01-17 14:44:34 -0800976 mOrientationListener = new MyOrientationListener(mContext, mHandler);
Jeff Brownc0347aa2011-09-23 17:26:09 -0700977 try {
978 mOrientationListener.setCurrentRotation(windowManager.getRotation());
979 } catch (RemoteException ex) { }
Christopher Tate5e08af02012-09-21 17:17:22 -0700980 mSettingsObserver = new SettingsObserver(mHandler);
981 mSettingsObserver.observe();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800982 mShortcutManager = new ShortcutManager(context, mHandler);
983 mShortcutManager.observe();
Daniel Sandler6396c722013-04-16 20:19:09 -0400984 mUiMode = context.getResources().getInteger(
985 com.android.internal.R.integer.config_defaultUiModeType);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800986 mHomeIntent = new Intent(Intent.ACTION_MAIN, null);
987 mHomeIntent.addCategory(Intent.CATEGORY_HOME);
988 mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
989 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700990 mCarDockIntent = new Intent(Intent.ACTION_MAIN, null);
991 mCarDockIntent.addCategory(Intent.CATEGORY_CAR_DOCK);
992 mCarDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
993 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
994 mDeskDockIntent = new Intent(Intent.ACTION_MAIN, null);
995 mDeskDockIntent.addCategory(Intent.CATEGORY_DESK_DOCK);
996 mDeskDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
997 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Jim Millere6ad1a82010-08-20 19:25:39 -0700998
Jeff Brown96307042012-07-27 15:51:34 -0700999 mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
1000 mBroadcastWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001001 "PhoneWindowManager.mBroadcastWakeLock");
1002 mEnableShiftMenuBugReports = "1".equals(SystemProperties.get("ro.debuggable"));
Jeff Brownbcdfc622014-03-06 19:13:04 -08001003 mSupportAutoRotation = mContext.getResources().getBoolean(
1004 com.android.internal.R.bool.config_supportAutoRotation);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001005 mLidOpenRotation = readRotation(
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001006 com.android.internal.R.integer.config_lidOpenRotation);
1007 mCarDockRotation = readRotation(
1008 com.android.internal.R.integer.config_carDockRotation);
1009 mDeskDockRotation = readRotation(
1010 com.android.internal.R.integer.config_deskDockRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001011 mUndockedHdmiRotation = readRotation(
1012 com.android.internal.R.integer.config_undockedHdmiRotation);
Mike Lockwoode9867d22009-09-20 01:59:02 -04001013 mCarDockEnablesAccelerometer = mContext.getResources().getBoolean(
1014 com.android.internal.R.bool.config_carDockEnablesAccelerometer);
1015 mDeskDockEnablesAccelerometer = mContext.getResources().getBoolean(
1016 com.android.internal.R.bool.config_deskDockEnablesAccelerometer);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001017 mLidKeyboardAccessibility = mContext.getResources().getInteger(
1018 com.android.internal.R.integer.config_lidKeyboardAccessibility);
1019 mLidNavigationAccessibility = mContext.getResources().getInteger(
1020 com.android.internal.R.integer.config_lidNavigationAccessibility);
Jeff Brownc458ce92012-04-30 14:58:40 -07001021 mLidControlsSleep = mContext.getResources().getBoolean(
1022 com.android.internal.R.bool.config_lidControlsSleep);
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04001023 mTranslucentDecorEnabled = mContext.getResources().getBoolean(
1024 com.android.internal.R.bool.config_enableTranslucentDecor);
Jeff Brownf71343d2013-05-31 17:59:11 -07001025 readConfigurationDependentBehaviors();
Jeff Browncaca8812013-05-09 13:34:33 -07001026
Svetoslav8e3feb12014-02-24 13:46:47 -08001027 mAccessibilityManager = (AccessibilityManager) context.getSystemService(
1028 Context.ACCESSIBILITY_SERVICE);
1029
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001030 // register for dock events
Dianne Hackborn78968392010-03-04 20:47:56 -08001031 IntentFilter filter = new IntentFilter();
1032 filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE);
1033 filter.addAction(UiModeManager.ACTION_EXIT_CAR_MODE);
1034 filter.addAction(UiModeManager.ACTION_ENTER_DESK_MODE);
1035 filter.addAction(UiModeManager.ACTION_EXIT_DESK_MODE);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001036 filter.addAction(Intent.ACTION_DOCK_EVENT);
1037 Intent intent = context.registerReceiver(mDockReceiver, filter);
1038 if (intent != null) {
1039 // Retrieve current sticky dock event broadcast.
1040 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
1041 Intent.EXTRA_DOCK_STATE_UNDOCKED);
1042 }
Daniel Sandler7e37df52011-11-16 22:08:23 -08001043
Jeff Brown6aaf2952012-10-05 16:01:08 -07001044 // register for dream-related broadcasts
1045 filter = new IntentFilter();
1046 filter.addAction(Intent.ACTION_DREAMING_STARTED);
1047 filter.addAction(Intent.ACTION_DREAMING_STOPPED);
1048 context.registerReceiver(mDreamReceiver, filter);
1049
Christopher Tate5e08af02012-09-21 17:17:22 -07001050 // register for multiuser-relevant broadcasts
1051 filter = new IntentFilter(Intent.ACTION_USER_SWITCHED);
1052 context.registerReceiver(mMultiuserReceiver, filter);
1053
John Spurlock57306e62013-04-22 09:48:49 -04001054 // monitor for system gestures
Craig Mautner037aa8d2013-06-07 10:35:44 -07001055 mSystemGestures = new SystemGesturesPointerEventListener(context,
1056 new SystemGesturesPointerEventListener.Callbacks() {
John Spurlock57306e62013-04-22 09:48:49 -04001057 @Override
1058 public void onSwipeFromTop() {
John Spurlock04db1762013-05-13 12:46:41 -04001059 if (mStatusBar != null) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001060 requestTransientBars(mStatusBar);
John Spurlock04db1762013-05-13 12:46:41 -04001061 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04001062 }
1063 @Override
1064 public void onSwipeFromBottom() {
John Spurlock04db1762013-05-13 12:46:41 -04001065 if (mNavigationBar != null && mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001066 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001067 }
1068 }
1069 @Override
1070 public void onSwipeFromRight() {
John Spurlock04db1762013-05-13 12:46:41 -04001071 if (mNavigationBar != null && !mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001072 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001073 }
1074 }
1075 @Override
1076 public void onDebug() {
John Spurlockd67ec252013-09-05 11:31:54 -04001077 // no-op
John Spurlockad3e6cb2013-04-30 08:47:43 -04001078 }
1079 });
John Spurlockf1a36642013-10-12 17:50:42 -04001080 mImmersiveModeConfirmation = new ImmersiveModeConfirmation(mContext);
Craig Mautner037aa8d2013-06-07 10:35:44 -07001081 mWindowManagerFuncs.registerPointerEventListener(mSystemGestures);
John Spurlock32beb2c2013-03-11 10:16:47 -04001082
Jeff Brownc2346132012-04-13 01:55:38 -07001083 mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001084 mLongPressVibePattern = getLongIntArray(mContext.getResources(),
1085 com.android.internal.R.array.config_longPressVibePattern);
1086 mVirtualKeyVibePattern = getLongIntArray(mContext.getResources(),
1087 com.android.internal.R.array.config_virtualKeyVibePattern);
Amith Yamasanic33cb712010-02-10 15:21:49 -08001088 mKeyboardTapVibePattern = getLongIntArray(mContext.getResources(),
1089 com.android.internal.R.array.config_keyboardTapVibePattern);
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07001090 mClockTickVibePattern = getLongIntArray(mContext.getResources(),
1091 com.android.internal.R.array.config_clockTickVibePattern);
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07001092 mCalendarDateVibePattern = getLongIntArray(mContext.getResources(),
1093 com.android.internal.R.array.config_calendarDateVibePattern);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001094 mSafeModeDisabledVibePattern = getLongIntArray(mContext.getResources(),
1095 com.android.internal.R.array.config_safeModeDisabledVibePattern);
1096 mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(),
1097 com.android.internal.R.array.config_safeModeEnabledVibePattern);
Daniel Sandler40427442010-07-16 11:44:52 -04001098
Christopher Tatee90585f2012-03-05 18:56:25 -08001099 mScreenshotChordEnabled = mContext.getResources().getBoolean(
1100 com.android.internal.R.bool.config_enableScreenshotChord);
1101
Justin Kohd378ad72013-04-01 12:18:26 -07001102 mGlobalKeyManager = new GlobalKeyManager(mContext);
1103
Joe Onoratoea495d42011-04-06 11:41:11 -07001104 // Controls rotation and the like.
1105 initializeHdmiState();
Dianne Hackborn40011092011-09-22 13:37:48 -07001106
1107 // Match current screen state.
Craig Mautnera631d492014-08-05 15:16:01 -07001108 if (!mPowerManager.isInteractive()) {
Jeff Brown140ffc72014-05-01 15:18:00 -07001109 goingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
Dianne Hackborn40011092011-09-22 13:37:48 -07001110 }
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001111 }
1112
Jeff Brownf71343d2013-05-31 17:59:11 -07001113 /**
1114 * Read values from config.xml that may be overridden depending on
1115 * the configuration of the device.
1116 * eg. Disable long press on home goes to recents on sw600dp.
1117 */
1118 private void readConfigurationDependentBehaviors() {
1119 mLongPressOnHomeBehavior = mContext.getResources().getInteger(
1120 com.android.internal.R.integer.config_longPressOnHomeBehavior);
1121 if (mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING ||
1122 mLongPressOnHomeBehavior > LONG_PRESS_HOME_ASSIST) {
1123 mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1124 }
1125
1126 mDoubleTapOnHomeBehavior = mContext.getResources().getInteger(
1127 com.android.internal.R.integer.config_doubleTapOnHomeBehavior);
1128 if (mDoubleTapOnHomeBehavior < DOUBLE_TAP_HOME_NOTHING ||
1129 mDoubleTapOnHomeBehavior > DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1130 mDoubleTapOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1131 }
1132 }
1133
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001134 @Override
Dianne Hackborndde331c2012-08-03 14:01:57 -07001135 public void setInitialDisplaySize(Display display, int width, int height, int density) {
Jeff Brownef981a42013-08-07 14:13:37 -07001136 // This method might be called before the policy has been fully initialized
1137 // or for other displays we don't care about.
1138 if (mContext == null || display.getDisplayId() != Display.DEFAULT_DISPLAY) {
1139 return;
Dianne Hackbornc652de82013-02-15 16:32:56 -08001140 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001141 mDisplay = display;
1142
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001143 final Resources res = mContext.getResources();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001144 int shortSize, longSize;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001145 if (width > height) {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001146 shortSize = height;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001147 longSize = width;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001148 mLandscapeRotation = Surface.ROTATION_0;
1149 mSeascapeRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001150 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001151 mPortraitRotation = Surface.ROTATION_90;
1152 mUpsideDownRotation = Surface.ROTATION_270;
1153 } else {
1154 mPortraitRotation = Surface.ROTATION_270;
1155 mUpsideDownRotation = Surface.ROTATION_90;
1156 }
1157 } else {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001158 shortSize = width;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001159 longSize = height;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001160 mPortraitRotation = Surface.ROTATION_0;
1161 mUpsideDownRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001162 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001163 mLandscapeRotation = Surface.ROTATION_270;
1164 mSeascapeRotation = Surface.ROTATION_90;
1165 } else {
1166 mLandscapeRotation = Surface.ROTATION_90;
1167 mSeascapeRotation = Surface.ROTATION_270;
1168 }
1169 }
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001170
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001171 mStatusBarHeight =
1172 res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001173
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001174 // Height of the navigation bar when presented horizontally at bottom
1175 mNavigationBarHeightForRotation[mPortraitRotation] =
1176 mNavigationBarHeightForRotation[mUpsideDownRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001177 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_height);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001178 mNavigationBarHeightForRotation[mLandscapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001179 mNavigationBarHeightForRotation[mSeascapeRotation] = res.getDimensionPixelSize(
1180 com.android.internal.R.dimen.navigation_bar_height_landscape);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001181
1182 // Width of the navigation bar when presented vertically along one side
1183 mNavigationBarWidthForRotation[mPortraitRotation] =
1184 mNavigationBarWidthForRotation[mUpsideDownRotation] =
1185 mNavigationBarWidthForRotation[mLandscapeRotation] =
1186 mNavigationBarWidthForRotation[mSeascapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001187 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_width);
Daniel Sandler4a066c52012-04-20 14:49:13 -04001188
1189 // SystemUI (status bar) layout policy
Dianne Hackborndde331c2012-08-03 14:01:57 -07001190 int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / density;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001191 int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / density;
Daniel Sandler4a066c52012-04-20 14:49:13 -04001192
Craig Mautnerd4ec33242013-07-22 10:37:43 -07001193 // Allow the navigation bar to move on small devices (phones).
1194 mNavigationBarCanMove = shortSizeDp < 600;
Daniel Sandler36412a72011-08-04 09:35:13 -04001195
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001196 mHasNavigationBar = res.getBoolean(com.android.internal.R.bool.config_showNavigationBar);
John Spurlock80f00c12013-06-13 11:10:51 -04001197 // Allow a system property to override this. Used by the emulator.
1198 // See also hasNavigationBar().
1199 String navBarOverride = SystemProperties.get("qemu.hw.mainkeys");
1200 if ("1".equals(navBarOverride)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001201 mHasNavigationBar = false;
John Spurlock80f00c12013-06-13 11:10:51 -04001202 } else if ("0".equals(navBarOverride)) {
1203 mHasNavigationBar = true;
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04001204 }
1205
Jeff Brown27f1d672012-10-17 18:32:34 -07001206 // For demo purposes, allow the rotation of the HDMI display to be controlled.
1207 // By default, HDMI locks rotation to landscape.
Erik Gilling9a41ef82011-09-26 19:21:03 -07001208 if ("portrait".equals(SystemProperties.get("persist.demo.hdmirotation"))) {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001209 mDemoHdmiRotation = mPortraitRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001210 } else {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001211 mDemoHdmiRotation = mLandscapeRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001212 }
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001213 mDemoHdmiRotationLock = SystemProperties.getBoolean("persist.demo.hdmirotationlock", false);
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001214
1215 // Only force the default orientation if the screen is xlarge, at least 960dp x 720dp, per
1216 // http://developer.android.com/guide/practices/screens_support.html#range
1217 mForceDefaultOrientation = longSizeDp >= 960 && shortSizeDp >= 720 &&
1218 res.getBoolean(com.android.internal.R.bool.config_forceDefaultOrientation) &&
1219 // For debug purposes the next line turns this feature off with:
1220 // $ adb shell setprop config.override_forced_orient true
1221 // $ adb shell wm size reset
1222 !"true".equals(SystemProperties.get("config.override_forced_orient"));
1223 }
1224
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001225 /**
1226 * @return whether the navigation bar can be hidden, e.g. the device has a
1227 * navigation bar and touch exploration is not enabled
1228 */
1229 private boolean canHideNavigationBar() {
Svetoslav8e3feb12014-02-24 13:46:47 -08001230 return mHasNavigationBar
1231 && !mAccessibilityManager.isTouchExplorationEnabled();
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001232 }
1233
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001234 @Override
1235 public boolean isDefaultOrientationForced() {
1236 return mForceDefaultOrientation;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001237 }
1238
Dianne Hackbornc652de82013-02-15 16:32:56 -08001239 @Override
1240 public void setDisplayOverscan(Display display, int left, int top, int right, int bottom) {
1241 if (display.getDisplayId() == Display.DEFAULT_DISPLAY) {
1242 mOverscanLeft = left;
1243 mOverscanTop = top;
1244 mOverscanRight = right;
1245 mOverscanBottom = bottom;
1246 }
1247 }
1248
Dianne Hackbornc777e072010-02-12 13:07:59 -08001249 public void updateSettings() {
1250 ContentResolver resolver = mContext.getContentResolver();
1251 boolean updateRotation = false;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001252 synchronized (mLock) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001253 mEndcallBehavior = Settings.System.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001254 Settings.System.END_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001255 Settings.System.END_BUTTON_BEHAVIOR_DEFAULT,
1256 UserHandle.USER_CURRENT);
1257 mIncallPowerBehavior = Settings.Secure.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001258 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001259 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT,
1260 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001261
Jeff Browna20dda42014-05-27 20:57:24 -07001262 // Configure wake gesture.
1263 boolean wakeGestureEnabledSetting = Settings.Secure.getIntForUser(resolver,
1264 Settings.Secure.WAKE_GESTURE_ENABLED, 0,
1265 UserHandle.USER_CURRENT) != 0;
1266 if (mWakeGestureEnabledSetting != wakeGestureEnabledSetting) {
1267 mWakeGestureEnabledSetting = wakeGestureEnabledSetting;
1268 updateWakeGestureListenerLp();
1269 }
1270
Jeff Brown207673cd2012-06-05 17:47:11 -07001271 // Configure rotation lock.
Christopher Tate5e08af02012-09-21 17:17:22 -07001272 int userRotation = Settings.System.getIntForUser(resolver,
1273 Settings.System.USER_ROTATION, Surface.ROTATION_0,
1274 UserHandle.USER_CURRENT);
Jeff Brown207673cd2012-06-05 17:47:11 -07001275 if (mUserRotation != userRotation) {
1276 mUserRotation = userRotation;
1277 updateRotation = true;
1278 }
Christopher Tate5e08af02012-09-21 17:17:22 -07001279 int userRotationMode = Settings.System.getIntForUser(resolver,
1280 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
Jeff Brown207673cd2012-06-05 17:47:11 -07001281 WindowManagerPolicy.USER_ROTATION_FREE :
1282 WindowManagerPolicy.USER_ROTATION_LOCKED;
1283 if (mUserRotationMode != userRotationMode) {
1284 mUserRotationMode = userRotationMode;
1285 updateRotation = true;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001286 updateOrientationListenerLp();
1287 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001288
Dianne Hackbornc777e072010-02-12 13:07:59 -08001289 if (mSystemReady) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001290 int pointerLocation = Settings.System.getIntForUser(resolver,
1291 Settings.System.POINTER_LOCATION, 0, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001292 if (mPointerLocationMode != pointerLocation) {
1293 mPointerLocationMode = pointerLocation;
Jeff Brown70825162012-03-28 17:27:48 -07001294 mHandler.sendEmptyMessage(pointerLocation != 0 ?
1295 MSG_ENABLE_POINTER_LOCATION : MSG_DISABLE_POINTER_LOCATION);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001296 }
1297 }
1298 // use screen off timeout setting as the timeout for the lockscreen
Christopher Tate5e08af02012-09-21 17:17:22 -07001299 mLockScreenTimeout = Settings.System.getIntForUser(resolver,
1300 Settings.System.SCREEN_OFF_TIMEOUT, 0, UserHandle.USER_CURRENT);
1301 String imId = Settings.Secure.getStringForUser(resolver,
1302 Settings.Secure.DEFAULT_INPUT_METHOD, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001303 boolean hasSoftInput = imId != null && imId.length() > 0;
1304 if (mHasSoftInput != hasSoftInput) {
1305 mHasSoftInput = hasSoftInput;
1306 updateRotation = true;
1307 }
John Spurlockf1a36642013-10-12 17:50:42 -04001308 if (mImmersiveModeConfirmation != null) {
John Spurlock4355a532014-02-19 09:49:25 -05001309 mImmersiveModeConfirmation.loadSetting(mCurrentUserId);
John Spurlockd67ec252013-09-05 11:31:54 -04001310 }
John Spurlockc6d1c602014-01-17 15:22:06 -05001311 PolicyControl.reloadFromSetting(mContext);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001312 }
1313 if (updateRotation) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07001314 updateRotation(true);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001315 }
Jeff Brown70825162012-03-28 17:27:48 -07001316 }
1317
Jeff Browna20dda42014-05-27 20:57:24 -07001318 private void updateWakeGestureListenerLp() {
1319 if (shouldEnableWakeGestureLp()) {
1320 mWakeGestureListener.requestWakeUpTrigger();
1321 } else {
1322 mWakeGestureListener.cancelWakeUpTrigger();
1323 }
1324 }
1325
1326 private boolean shouldEnableWakeGestureLp() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07001327 return mWakeGestureEnabledSetting && !mAwake
Jeff Browna20dda42014-05-27 20:57:24 -07001328 && (!mLidControlsSleep || mLidState != LID_CLOSED)
1329 && mWakeGestureListener.isSupported();
1330 }
1331
Jeff Brown70825162012-03-28 17:27:48 -07001332 private void enablePointerLocation() {
1333 if (mPointerLocationView == null) {
1334 mPointerLocationView = new PointerLocationView(mContext);
1335 mPointerLocationView.setPrintCoords(false);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001336 WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
1337 WindowManager.LayoutParams.MATCH_PARENT,
1338 WindowManager.LayoutParams.MATCH_PARENT);
Jeff Brown3b2b3542010-10-15 00:54:27 -07001339 lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001340 lp.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN
1341 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
1342 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1343 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
Jeff Brown90fc9052012-10-01 14:44:24 -07001344 if (ActivityManager.isHighEndGfx()) {
1345 lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
1346 lp.privateFlags |=
1347 WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED;
1348 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001349 lp.format = PixelFormat.TRANSLUCENT;
1350 lp.setTitle("PointerLocation");
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001351 WindowManager wm = (WindowManager)
Dianne Hackbornc777e072010-02-12 13:07:59 -08001352 mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Browncc4f7db2011-08-30 20:34:48 -07001353 lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL;
Jeff Brown70825162012-03-28 17:27:48 -07001354 wm.addView(mPointerLocationView, lp);
Michael Wrightc9c487e2013-11-07 18:55:09 -08001355 mWindowManagerFuncs.registerPointerEventListener(mPointerLocationView);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001356 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001357 }
Jeff Brown70825162012-03-28 17:27:48 -07001358
1359 private void disablePointerLocation() {
Jeff Brown70825162012-03-28 17:27:48 -07001360 if (mPointerLocationView != null) {
Michael Wrightc9c487e2013-11-07 18:55:09 -08001361 mWindowManagerFuncs.unregisterPointerEventListener(mPointerLocationView);
1362 WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Brown70825162012-03-28 17:27:48 -07001363 wm.removeView(mPointerLocationView);
1364 mPointerLocationView = null;
1365 }
1366 }
1367
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001368 private int readRotation(int resID) {
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001369 try {
1370 int rotation = mContext.getResources().getInteger(resID);
1371 switch (rotation) {
1372 case 0:
1373 return Surface.ROTATION_0;
1374 case 90:
1375 return Surface.ROTATION_90;
1376 case 180:
1377 return Surface.ROTATION_180;
1378 case 270:
1379 return Surface.ROTATION_270;
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001380 }
1381 } catch (Resources.NotFoundException e) {
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001382 // fall through
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001383 }
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001384 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001385 }
1386
1387 /** {@inheritDoc} */
Craig Mautner88400d32012-09-30 12:35:45 -07001388 @Override
Dianne Hackbornc2293022013-02-06 23:14:49 -08001389 public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001390 int type = attrs.type;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001391
1392 outAppOp[0] = AppOpsManager.OP_NONE;
1393
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001394 if (type < WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW
1395 || type > WindowManager.LayoutParams.LAST_SYSTEM_WINDOW) {
Jeff Brown98365d72012-08-19 20:30:52 -07001396 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001397 }
1398 String permission = null;
1399 switch (type) {
1400 case TYPE_TOAST:
1401 // XXX right now the app process has complete control over
1402 // this... should introduce a token to let the system
1403 // monitor/control what they are doing.
Jason Monk1c7c3192014-06-26 12:52:18 -04001404 outAppOp[0] = AppOpsManager.OP_TOAST_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001405 break;
Daniel Sandler7d276c32012-01-30 14:33:52 -05001406 case TYPE_DREAM:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001407 case TYPE_INPUT_METHOD:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001408 case TYPE_WALLPAPER:
keunyounga446bf02013-06-21 19:07:57 -07001409 case TYPE_PRIVATE_PRESENTATION:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001410 case TYPE_VOICE_INTERACTION:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001411 // The window manager will check these.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001412 break;
1413 case TYPE_PHONE:
1414 case TYPE_PRIORITY_PHONE:
1415 case TYPE_SYSTEM_ALERT:
1416 case TYPE_SYSTEM_ERROR:
1417 case TYPE_SYSTEM_OVERLAY:
1418 permission = android.Manifest.permission.SYSTEM_ALERT_WINDOW;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001419 outAppOp[0] = AppOpsManager.OP_SYSTEM_ALERT_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001420 break;
1421 default:
1422 permission = android.Manifest.permission.INTERNAL_SYSTEM_WINDOW;
1423 }
1424 if (permission != null) {
1425 if (mContext.checkCallingOrSelfPermission(permission)
1426 != PackageManager.PERMISSION_GRANTED) {
Jeff Brown98365d72012-08-19 20:30:52 -07001427 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001428 }
1429 }
Jeff Brown98365d72012-08-19 20:30:52 -07001430 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001431 }
Craig Mautner88400d32012-09-30 12:35:45 -07001432
1433 @Override
1434 public boolean checkShowToOwnerOnly(WindowManager.LayoutParams attrs) {
1435
1436 // If this switch statement is modified, modify the comment in the declarations of
1437 // the type in {@link WindowManager.LayoutParams} as well.
1438 switch (attrs.type) {
1439 default:
1440 // These are the windows that by default are shown only to the user that created
1441 // them. If this needs to be overridden, set
1442 // {@link WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS} in
1443 // {@link WindowManager.LayoutParams}. Note that permission
1444 // {@link android.Manifest.permission.INTERNAL_SYSTEM_WINDOW} is required as well.
1445 if ((attrs.privateFlags & PRIVATE_FLAG_SHOW_FOR_ALL_USERS) == 0) {
1446 return true;
1447 }
1448 break;
1449
1450 // These are the windows that by default are shown to all users. However, to
1451 // protect against spoofing, check permissions below.
1452 case TYPE_APPLICATION_STARTING:
1453 case TYPE_BOOT_PROGRESS:
1454 case TYPE_DISPLAY_OVERLAY:
1455 case TYPE_HIDDEN_NAV_CONSUMER:
Jim Miller5ecd8112013-01-09 18:50:26 -08001456 case TYPE_KEYGUARD_SCRIM:
Craig Mautner88400d32012-09-30 12:35:45 -07001457 case TYPE_KEYGUARD_DIALOG:
1458 case TYPE_MAGNIFICATION_OVERLAY:
1459 case TYPE_NAVIGATION_BAR:
1460 case TYPE_NAVIGATION_BAR_PANEL:
1461 case TYPE_PHONE:
1462 case TYPE_POINTER:
1463 case TYPE_PRIORITY_PHONE:
Craig Mautner88400d32012-09-30 12:35:45 -07001464 case TYPE_SEARCH_BAR:
1465 case TYPE_STATUS_BAR:
1466 case TYPE_STATUS_BAR_PANEL:
1467 case TYPE_STATUS_BAR_SUB_PANEL:
1468 case TYPE_SYSTEM_DIALOG:
1469 case TYPE_UNIVERSE_BACKGROUND:
1470 case TYPE_VOLUME_OVERLAY:
keunyounga446bf02013-06-21 19:07:57 -07001471 case TYPE_PRIVATE_PRESENTATION:
Craig Mautner88400d32012-09-30 12:35:45 -07001472 break;
1473 }
1474
1475 // Check if third party app has set window to system window type.
1476 return mContext.checkCallingOrSelfPermission(
1477 android.Manifest.permission.INTERNAL_SYSTEM_WINDOW)
1478 != PackageManager.PERMISSION_GRANTED;
1479 }
1480
Craig Mautner967212c2013-04-13 21:10:58 -07001481 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001482 public void adjustWindowParamsLw(WindowManager.LayoutParams attrs) {
1483 switch (attrs.type) {
1484 case TYPE_SYSTEM_OVERLAY:
Jeff Brown3b2b3542010-10-15 00:54:27 -07001485 case TYPE_SECURE_SYSTEM_OVERLAY:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001486 // These types of windows can't receive input events.
1487 attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1488 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001489 attrs.flags &= ~WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001490 break;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001491 case TYPE_STATUS_BAR:
1492
1493 // If the Keyguard is in a hidden state (occluded by another window), we force to
1494 // remove the wallpaper and keyguard flag so that any change in-flight after setting
1495 // the keyguard as occluded wouldn't set these flags again.
1496 // See {@link #processKeyguardSetHiddenResultLw}.
1497 if (mKeyguardHidden) {
1498 attrs.flags &= ~WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
1499 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
1500 }
1501 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001502 }
Adrian Roos38502112014-04-09 21:04:11 +02001503
1504 if (attrs.type != TYPE_STATUS_BAR) {
1505 // The status bar is the only window allowed to exhibit keyguard behavior.
1506 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
1507 }
Adrian Roosea562512014-05-05 13:33:03 +02001508
1509 if (ActivityManager.isHighEndGfx()
1510 && (attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0) {
Adrian Roosf5e9b5c2014-09-10 15:27:41 +02001511 attrs.subtreeSystemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
Adrian Roosea562512014-05-05 13:33:03 +02001512 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
1513 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001514 }
RoboErik8a2cfc32014-05-16 11:19:38 -07001515
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001516 void readLidState() {
Jeff Brown2e7760e2012-04-11 15:14:55 -07001517 mLidState = mWindowManagerFuncs.getLidState();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001518 }
RoboErik8a2cfc32014-05-16 11:19:38 -07001519
Michael Wright3818c922014-09-02 13:59:07 -07001520 private void readCameraLensCoverState() {
1521 mCameraLensCoverState = mWindowManagerFuncs.getCameraLensCoverState();
1522 }
1523
Jeff Browndaa37532012-05-01 15:54:03 -07001524 private boolean isHidden(int accessibilityMode) {
1525 switch (accessibilityMode) {
1526 case 1:
1527 return mLidState == LID_CLOSED;
1528 case 2:
1529 return mLidState == LID_OPEN;
1530 default:
1531 return false;
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001532 }
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001533 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001534
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001535 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07001536 @Override
Jeff Browndaa37532012-05-01 15:54:03 -07001537 public void adjustConfigurationLw(Configuration config, int keyboardPresence,
1538 int navigationPresence) {
1539 mHaveBuiltInKeyboard = (keyboardPresence & PRESENCE_INTERNAL) != 0;
1540
Jeff Brownf71343d2013-05-31 17:59:11 -07001541 readConfigurationDependentBehaviors();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001542 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07001543 applyLidSwitchState();
Jeff Brownd04a88c2011-01-16 14:05:47 -08001544
Jeff Browndaa37532012-05-01 15:54:03 -07001545 if (config.keyboard == Configuration.KEYBOARD_NOKEYS
1546 || (keyboardPresence == PRESENCE_INTERNAL
1547 && isHidden(mLidKeyboardAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001548 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_YES;
Jeff Browndaa37532012-05-01 15:54:03 -07001549 if (!mHasSoftInput) {
1550 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_YES;
1551 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001552 }
1553
Jeff Browndaa37532012-05-01 15:54:03 -07001554 if (config.navigation == Configuration.NAVIGATION_NONAV
1555 || (navigationPresence == PRESENCE_INTERNAL
1556 && isHidden(mLidNavigationAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001557 config.navigationHidden = Configuration.NAVIGATIONHIDDEN_YES;
Jeff Brownd04a88c2011-01-16 14:05:47 -08001558 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001559 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001560
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001561 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07001562 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001563 public int windowTypeToLayerLw(int type) {
1564 if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001565 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001566 }
1567 switch (type) {
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001568 case TYPE_UNIVERSE_BACKGROUND:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001569 return 1;
keunyounga446bf02013-06-21 19:07:57 -07001570 case TYPE_PRIVATE_PRESENTATION:
1571 return 2;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001572 case TYPE_WALLPAPER:
1573 // wallpaper is at the bottom, though the window manager may move it.
1574 return 2;
1575 case TYPE_PHONE:
1576 return 3;
1577 case TYPE_SEARCH_BAR:
1578 return 4;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001579 case TYPE_VOICE_INTERACTION:
1580 // voice interaction layer is almost immediately above apps.
1581 return 5;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001582 case TYPE_SYSTEM_DIALOG:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001583 return 6;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001584 case TYPE_TOAST:
1585 // toasts and the plugged-in battery thing
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001586 return 7;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001587 case TYPE_PRIORITY_PHONE:
1588 // SIM errors and unlock. Not sure if this really should be in a high layer.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001589 return 8;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001590 case TYPE_DREAM:
1591 // used for Dreams (screensavers with TYPE_DREAM windows)
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001592 return 9;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001593 case TYPE_SYSTEM_ALERT:
1594 // like the ANR / app crashed dialogs
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001595 return 10;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001596 case TYPE_INPUT_METHOD:
1597 // on-screen keyboards and other such input method user interfaces go here.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001598 return 11;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001599 case TYPE_INPUT_METHOD_DIALOG:
1600 // on-screen keyboards and other such input method user interfaces go here.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001601 return 12;
Jim Miller5ecd8112013-01-09 18:50:26 -08001602 case TYPE_KEYGUARD_SCRIM:
1603 // the safety window that shows behind keyguard while keyguard is starting
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001604 return 13;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001605 case TYPE_STATUS_BAR_SUB_PANEL:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001606 return 14;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001607 case TYPE_STATUS_BAR:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001608 return 15;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001609 case TYPE_STATUS_BAR_PANEL:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001610 return 16;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001611 case TYPE_KEYGUARD_DIALOG:
1612 return 17;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001613 case TYPE_VOLUME_OVERLAY:
1614 // the on-screen volume indicator and controller shown when the user
1615 // changes the device volume
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001616 return 18;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001617 case TYPE_SYSTEM_OVERLAY:
1618 // the on-screen volume indicator and controller shown when the user
1619 // changes the device volume
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001620 return 19;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001621 case TYPE_NAVIGATION_BAR:
1622 // the navigation bar, if available, shows atop most things
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001623 return 20;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001624 case TYPE_NAVIGATION_BAR_PANEL:
1625 // some panels (e.g. search) need to show on top of the navigation bar
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001626 return 21;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001627 case TYPE_SYSTEM_ERROR:
1628 // system-level error dialogs
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001629 return 22;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001630 case TYPE_MAGNIFICATION_OVERLAY:
1631 // used to highlight the magnified portion of a display
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001632 return 23;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001633 case TYPE_DISPLAY_OVERLAY:
1634 // used to simulate secondary display devices
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001635 return 24;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001636 case TYPE_DRAG:
1637 // the drag layer: input for drag-and-drop is associated with this window,
1638 // which sits above all other focusable windows
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001639 return 25;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001640 case TYPE_SECURE_SYSTEM_OVERLAY:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001641 return 26;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001642 case TYPE_BOOT_PROGRESS:
1643 return 27;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001644 case TYPE_POINTER:
1645 // the (mouse) pointer layer
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001646 return 28;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001647 case TYPE_HIDDEN_NAV_CONSUMER:
1648 return 29;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001649 }
1650 Log.e(TAG, "Unknown window type: " + type);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001651 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001652 }
1653
1654 /** {@inheritDoc} */
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001655 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001656 public int subWindowTypeToLayerLw(int type) {
1657 switch (type) {
1658 case TYPE_APPLICATION_PANEL:
1659 case TYPE_APPLICATION_ATTACHED_DIALOG:
1660 return APPLICATION_PANEL_SUBLAYER;
1661 case TYPE_APPLICATION_MEDIA:
1662 return APPLICATION_MEDIA_SUBLAYER;
Dianne Hackborn5cb8d792009-05-21 17:34:15 -07001663 case TYPE_APPLICATION_MEDIA_OVERLAY:
1664 return APPLICATION_MEDIA_OVERLAY_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001665 case TYPE_APPLICATION_SUB_PANEL:
1666 return APPLICATION_SUB_PANEL_SUBLAYER;
1667 }
1668 Log.e(TAG, "Unknown sub-window type: " + type);
1669 return 0;
1670 }
1671
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001672 @Override
Dianne Hackbornabe0da02009-09-18 01:55:39 -07001673 public int getMaxWallpaperLayer() {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001674 return windowTypeToLayerLw(TYPE_STATUS_BAR);
Dianne Hackbornabe0da02009-09-18 01:55:39 -07001675 }
1676
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001677 @Override
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001678 public int getAboveUniverseLayer() {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001679 return windowTypeToLayerLw(TYPE_SYSTEM_ERROR);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001680 }
1681
Jose Lima9546b202014-07-02 17:21:51 -07001682 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001683 public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07001684 if (mHasNavigationBar) {
1685 // For a basic navigation bar, when we are in landscape mode we place
1686 // the navigation bar to the side.
Daniel Sandler4a066c52012-04-20 14:49:13 -04001687 if (mNavigationBarCanMove && fullWidth > fullHeight) {
1688 return fullWidth - mNavigationBarWidthForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07001689 }
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001690 }
1691 return fullWidth;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001692 }
1693
Jose Lima9546b202014-07-02 17:21:51 -07001694 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001695 public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07001696 if (mHasNavigationBar) {
1697 // For a basic navigation bar, when we are in portrait mode we place
1698 // the navigation bar to the bottom.
Daniel Sandler4a066c52012-04-20 14:49:13 -04001699 if (!mNavigationBarCanMove || fullWidth < fullHeight) {
1700 return fullHeight - mNavigationBarHeightForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07001701 }
1702 }
1703 return fullHeight;
Dianne Hackborn69cb8752011-05-19 18:13:32 -07001704 }
1705
Jose Lima9546b202014-07-02 17:21:51 -07001706 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001707 public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation) {
1708 return getNonDecorDisplayWidth(fullWidth, fullHeight, rotation);
Dianne Hackborn69cb8752011-05-19 18:13:32 -07001709 }
1710
Jose Lima9546b202014-07-02 17:21:51 -07001711 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001712 public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation) {
John Spurlock80f00c12013-06-13 11:10:51 -04001713 // There is a separate status bar at the top of the display. We don't count that as part
1714 // of the fixed decor, since it can hide; however, for purposes of configurations,
Dianne Hackborn077ee852012-04-09 16:27:07 -07001715 // we do want to exclude it since applications can't generally use that part
1716 // of the screen.
John Spurlock80f00c12013-06-13 11:10:51 -04001717 return getNonDecorDisplayHeight(fullWidth, fullHeight, rotation) - mStatusBarHeight;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001718 }
1719
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001720 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07001721 public boolean isForceHiding(WindowManager.LayoutParams attrs) {
1722 return (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 ||
Adrian Roos69e510d2014-07-13 14:57:59 +02001723 (isKeyguardHostWindow(attrs) && isKeyguardSecureIncludingHidden()) ||
1724 (attrs.type == TYPE_KEYGUARD_SCRIM);
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07001725 }
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001726
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001727 @Override
Jorim Jaggi0d674622014-05-21 01:34:15 +02001728 public boolean isKeyguardHostWindow(WindowManager.LayoutParams attrs) {
1729 return attrs.type == TYPE_STATUS_BAR;
1730 }
1731
1732 @Override
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07001733 public boolean canBeForceHidden(WindowState win, WindowManager.LayoutParams attrs) {
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001734 switch (attrs.type) {
1735 case TYPE_STATUS_BAR:
1736 case TYPE_NAVIGATION_BAR:
1737 case TYPE_WALLPAPER:
1738 case TYPE_DREAM:
1739 case TYPE_UNIVERSE_BACKGROUND:
Jim Miller5ecd8112013-01-09 18:50:26 -08001740 case TYPE_KEYGUARD_SCRIM:
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001741 return false;
1742 default:
1743 return true;
1744 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07001745 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001746
Craig Mautner7d7808f2014-09-11 18:02:38 -07001747 @Override
1748 public WindowState getWinShowWhenLockedLw() {
1749 return mWinShowWhenLocked;
1750 }
1751
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001752 /** {@inheritDoc} */
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001753 @Override
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07001754 public View addStartingWindow(IBinder appToken, String packageName, int theme,
1755 CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes,
Adam Powell04fe6eb2013-05-31 14:39:48 -07001756 int icon, int logo, int windowFlags) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001757 if (!SHOW_STARTING_ANIMATIONS) {
1758 return null;
1759 }
1760 if (packageName == null) {
1761 return null;
1762 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001763
Mathias Jeppssond1443e92012-08-24 15:25:32 +02001764 WindowManager wm = null;
1765 View view = null;
1766
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001767 try {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001768 Context context = mContext;
Craig Mautner6fbda632012-07-03 09:26:39 -07001769 if (DEBUG_STARTING_WINDOW) Slog.d(TAG, "addStartingWindow " + packageName
1770 + ": nonLocalizedLabel=" + nonLocalizedLabel + " theme="
1771 + Integer.toHexString(theme));
Dianne Hackborn247fe742011-01-08 17:25:57 -08001772 if (theme != context.getThemeResId() || labelRes != 0) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001773 try {
1774 context = context.createPackageContext(packageName, 0);
Dianne Hackborn247fe742011-01-08 17:25:57 -08001775 context.setTheme(theme);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001776 } catch (PackageManager.NameNotFoundException e) {
1777 // Ignore
1778 }
1779 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001780
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001781 Window win = PolicyManager.makeNewWindow(context);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001782 final TypedArray ta = win.getWindowStyle();
1783 if (ta.getBoolean(
1784 com.android.internal.R.styleable.Window_windowDisablePreview, false)
1785 || ta.getBoolean(
1786 com.android.internal.R.styleable.Window_windowShowWallpaper,false)) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001787 return null;
1788 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001789
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001790 Resources r = context.getResources();
1791 win.setTitle(r.getText(labelRes, nonLocalizedLabel));
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001792
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001793 win.setType(
1794 WindowManager.LayoutParams.TYPE_APPLICATION_STARTING);
1795 // Force the window flags: this is a fake window, so it is not really
1796 // touchable or focusable by the user. We also add in the ALT_FOCUSABLE_IM
1797 // flag because we do know that the next window will take input
1798 // focus, so we want to get the IME window up on top of us right away.
1799 win.setFlags(
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08001800 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001801 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
1802 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
1803 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08001804 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001805 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
1806 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
1807 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001808
Adam Powell04fe6eb2013-05-31 14:39:48 -07001809 win.setDefaultIcon(icon);
1810 win.setDefaultLogo(logo);
1811
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001812 win.setLayout(WindowManager.LayoutParams.MATCH_PARENT,
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07001813 WindowManager.LayoutParams.MATCH_PARENT);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001814
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001815 final WindowManager.LayoutParams params = win.getAttributes();
1816 params.token = appToken;
1817 params.packageName = packageName;
1818 params.windowAnimations = win.getWindowStyle().getResourceId(
1819 com.android.internal.R.styleable.Window_windowAnimationStyle, 0);
John Reck61375a82014-09-18 19:27:48 +00001820 params.privateFlags |=
1821 WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED;
Craig Mautner88400d32012-09-30 12:35:45 -07001822 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
Adam Lesinski95c42972013-10-02 10:13:27 -07001823
1824 if (!compatInfo.supportsScreen()) {
1825 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
1826 }
1827
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001828 params.setTitle("Starting " + packageName);
1829
Mathias Jeppssond1443e92012-08-24 15:25:32 +02001830 wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
1831 view = win.getDecorView();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001832
1833 if (win.isFloating()) {
1834 // Whoops, there is no way to display an animation/preview
1835 // of such a thing! After all that work... let's skip it.
1836 // (Note that we must do this here because it is in
1837 // getDecorView() where the theme is evaluated... maybe
1838 // we should peek the floating attribute from the theme
1839 // earlier.)
1840 return null;
1841 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001842
Craig Mautner6fbda632012-07-03 09:26:39 -07001843 if (DEBUG_STARTING_WINDOW) Slog.d(
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001844 TAG, "Adding starting window for " + packageName
1845 + " / " + appToken + ": "
1846 + (view.getParent() != null ? view : null));
1847
1848 wm.addView(view, params);
1849
1850 // Only return the view if it was successfully added to the
1851 // window manager... which we can tell by it having a parent.
1852 return view.getParent() != null ? view : null;
Jeff Brown98365d72012-08-19 20:30:52 -07001853 } catch (WindowManager.BadTokenException e) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001854 // ignore
Craig Mautner42bf39e2014-02-21 16:46:22 -08001855 Log.w(TAG, appToken + " already running, starting window not displayed. " +
1856 e.getMessage());
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001857 } catch (RuntimeException e) {
1858 // don't crash if something else bad happens, for example a
1859 // failure loading resources because we are loading from an app
1860 // on external storage that has been unmounted.
1861 Log.w(TAG, appToken + " failed creating starting window", e);
Mathias Jeppssond1443e92012-08-24 15:25:32 +02001862 } finally {
1863 if (view != null && view.getParent() == null) {
1864 Log.w(TAG, "view not successfully added to wm, removing view");
1865 wm.removeViewImmediate(view);
1866 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001867 }
1868
1869 return null;
1870 }
1871
1872 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07001873 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001874 public void removeStartingWindow(IBinder appToken, View window) {
Craig Mautner6fbda632012-07-03 09:26:39 -07001875 if (DEBUG_STARTING_WINDOW) {
1876 RuntimeException e = new RuntimeException("here");
1877 e.fillInStackTrace();
1878 Log.v(TAG, "Removing starting window for " + appToken + ": " + window, e);
1879 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001880
1881 if (window != null) {
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001882 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001883 wm.removeView(window);
1884 }
1885 }
1886
1887 /**
1888 * Preflight adding a window to the system.
RoboErik8a2cfc32014-05-16 11:19:38 -07001889 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001890 * Currently enforces that three window types are singletons:
1891 * <ul>
1892 * <li>STATUS_BAR_TYPE</li>
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001893 * <li>KEYGUARD_TYPE</li>
1894 * </ul>
RoboErik8a2cfc32014-05-16 11:19:38 -07001895 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001896 * @param win The window to be added
1897 * @param attrs Information about the window to be added
RoboErik8a2cfc32014-05-16 11:19:38 -07001898 *
Jeff Brown98365d72012-08-19 20:30:52 -07001899 * @return If ok, WindowManagerImpl.ADD_OKAY. If too many singletons,
1900 * WindowManagerImpl.ADD_MULTIPLE_SINGLETON
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001901 */
Jose Lima9546b202014-07-02 17:21:51 -07001902 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001903 public int prepareAddWindowLw(WindowState win, WindowManager.LayoutParams attrs) {
1904 switch (attrs.type) {
1905 case TYPE_STATUS_BAR:
Joe Onorato8bc6c512010-06-04 16:21:12 -04001906 mContext.enforceCallingOrSelfPermission(
1907 android.Manifest.permission.STATUS_BAR_SERVICE,
1908 "PhoneWindowManager");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001909 if (mStatusBar != null) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001910 if (mStatusBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07001911 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001912 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001913 }
1914 mStatusBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04001915 mStatusBarController.setWindow(win);
John Spurlock8fdfe622014-05-21 17:10:10 -04001916 mKeyguardDelegate.hideScrim();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001917 break;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04001918 case TYPE_NAVIGATION_BAR:
1919 mContext.enforceCallingOrSelfPermission(
1920 android.Manifest.permission.STATUS_BAR_SERVICE,
1921 "PhoneWindowManager");
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001922 if (mNavigationBar != null) {
1923 if (mNavigationBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07001924 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001925 }
1926 }
Daniel Sandler8956dbb2011-04-22 07:55:02 -04001927 mNavigationBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04001928 mNavigationBarController.setWindow(win);
Craig Mautnereda67292013-04-28 13:50:14 -07001929 if (DEBUG_LAYOUT) Slog.i(TAG, "NAVIGATION BAR: " + mNavigationBar);
Daniel Sandler8956dbb2011-04-22 07:55:02 -04001930 break;
Jim Millere898ac52012-04-06 17:10:57 -07001931 case TYPE_NAVIGATION_BAR_PANEL:
1932 mContext.enforceCallingOrSelfPermission(
1933 android.Manifest.permission.STATUS_BAR_SERVICE,
1934 "PhoneWindowManager");
1935 break;
Dianne Hackborn08743722009-12-21 12:16:51 -08001936 case TYPE_STATUS_BAR_PANEL:
Joe Onorato8bc6c512010-06-04 16:21:12 -04001937 mContext.enforceCallingOrSelfPermission(
1938 android.Manifest.permission.STATUS_BAR_SERVICE,
1939 "PhoneWindowManager");
Dianne Hackborn08743722009-12-21 12:16:51 -08001940 break;
Joe Onorato29fc2c92010-11-24 10:26:50 -08001941 case TYPE_STATUS_BAR_SUB_PANEL:
1942 mContext.enforceCallingOrSelfPermission(
1943 android.Manifest.permission.STATUS_BAR_SERVICE,
1944 "PhoneWindowManager");
Joe Onorato29fc2c92010-11-24 10:26:50 -08001945 break;
Jim Miller5ecd8112013-01-09 18:50:26 -08001946 case TYPE_KEYGUARD_SCRIM:
Jim Miller25190572013-02-28 17:36:24 -08001947 if (mKeyguardScrim != null) {
1948 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
1949 }
Jim Miller5ecd8112013-01-09 18:50:26 -08001950 mKeyguardScrim = win;
1951 break;
1952
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001953 }
Jeff Brown98365d72012-08-19 20:30:52 -07001954 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001955 }
1956
1957 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07001958 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001959 public void removeWindowLw(WindowState win) {
1960 if (mStatusBar == win) {
1961 mStatusBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04001962 mStatusBarController.setWindow(null);
Jim Millerc0b676d2013-03-22 16:11:08 -07001963 mKeyguardDelegate.showScrim();
Jim Miller5ecd8112013-01-09 18:50:26 -08001964 } else if (mKeyguardScrim == win) {
1965 Log.v(TAG, "Removing keyguard scrim");
1966 mKeyguardScrim = null;
1967 } if (mNavigationBar == win) {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04001968 mNavigationBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04001969 mNavigationBarController.setWindow(null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001970 }
1971 }
1972
1973 static final boolean PRINT_ANIM = false;
RoboErik8a2cfc32014-05-16 11:19:38 -07001974
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001975 /** {@inheritDoc} */
Craig Mautner4b71aa12012-12-27 17:20:01 -08001976 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001977 public int selectAnimationLw(WindowState win, int transit) {
1978 if (PRINT_ANIM) Log.i(TAG, "selectAnimation in " + win
1979 + ": transit=" + transit);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001980 if (win == mStatusBar) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001981 boolean isKeyguard = (win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001982 if (transit == TRANSIT_EXIT
1983 || transit == TRANSIT_HIDE) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001984 return isKeyguard ? -1 : R.anim.dock_top_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001985 } else if (transit == TRANSIT_ENTER
1986 || transit == TRANSIT_SHOW) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001987 return isKeyguard ? -1 : R.anim.dock_top_enter;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001988 }
1989 } else if (win == mNavigationBar) {
1990 // This can be on either the bottom or the right.
1991 if (mNavigationBarOnBottom) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08001992 if (transit == TRANSIT_EXIT
1993 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001994 return R.anim.dock_bottom_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001995 } else if (transit == TRANSIT_ENTER
1996 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001997 return R.anim.dock_bottom_enter;
1998 }
1999 } else {
Craig Mautner4b71aa12012-12-27 17:20:01 -08002000 if (transit == TRANSIT_EXIT
2001 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002002 return R.anim.dock_right_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002003 } else if (transit == TRANSIT_ENTER
2004 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002005 return R.anim.dock_right_enter;
2006 }
2007 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08002008 }
2009
2010 if (transit == TRANSIT_PREVIEW_DONE) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002011 if (win.hasAppShownWindows()) {
2012 if (PRINT_ANIM) Log.i(TAG, "**** STARTING EXIT");
2013 return com.android.internal.R.anim.app_starting_exit;
2014 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07002015 } else if (win.getAttrs().type == TYPE_DREAM && mDreamingLockscreen
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002016 && transit == TRANSIT_ENTER) {
2017 // Special case: we are animating in a dream, while the keyguard
2018 // is shown. We don't want an animation on the dream, because
2019 // we need it shown immediately with the keyguard animating away
2020 // to reveal it.
2021 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002022 }
2023
2024 return 0;
2025 }
2026
Craig Mautner3c174372013-02-21 17:54:37 -08002027 @Override
2028 public void selectRotationAnimationLw(int anim[]) {
2029 if (PRINT_ANIM) Slog.i(TAG, "selectRotationAnimation mTopFullscreen="
2030 + mTopFullscreenOpaqueWindowState + " rotationAnimation="
2031 + (mTopFullscreenOpaqueWindowState == null ?
2032 "0" : mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation));
2033 if (mTopFullscreenOpaqueWindowState != null && mTopIsFullscreen) {
2034 switch (mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation) {
2035 case ROTATION_ANIMATION_CROSSFADE:
2036 anim[0] = R.anim.rotation_animation_xfade_exit;
2037 anim[1] = R.anim.rotation_animation_enter;
2038 break;
2039 case ROTATION_ANIMATION_JUMPCUT:
2040 anim[0] = R.anim.rotation_animation_jump_exit;
2041 anim[1] = R.anim.rotation_animation_enter;
2042 break;
2043 case ROTATION_ANIMATION_ROTATE:
2044 default:
2045 anim[0] = anim[1] = 0;
2046 break;
2047 }
2048 } else {
2049 anim[0] = anim[1] = 0;
2050 }
2051 }
2052
2053 @Override
2054 public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId,
2055 boolean forceDefault) {
2056 switch (exitAnimId) {
2057 case R.anim.rotation_animation_xfade_exit:
2058 case R.anim.rotation_animation_jump_exit:
2059 // These are the only cases that matter.
2060 if (forceDefault) {
2061 return false;
2062 }
2063 int anim[] = new int[2];
2064 selectRotationAnimationLw(anim);
2065 return (exitAnimId == anim[0] && enterAnimId == anim[1]);
2066 default:
2067 return true;
2068 }
2069 }
2070
2071 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002072 public Animation createForceHideEnterAnimation(boolean onWallpaper,
2073 boolean goingToNotificationShade) {
2074 if (goingToNotificationShade) {
2075 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_behind_enter_fade_in);
2076 } else if (onWallpaper) {
Jorim Jaggi76a16232014-08-08 17:00:47 +02002077 Animation a = AnimationUtils.loadAnimation(mContext,
2078 R.anim.lock_screen_behind_enter_wallpaper);
2079 AnimationSet set = (AnimationSet) a;
2080
2081 // TODO: Use XML interpolators when we have log interpolators available in XML.
2082 set.getAnimations().get(0).setInterpolator(mLogDecelerateInterpolator);
2083 set.getAnimations().get(1).setInterpolator(mLogDecelerateInterpolator);
Jorim Jaggi76a16232014-08-08 17:00:47 +02002084 return set;
2085 } else {
2086 Animation a = AnimationUtils.loadAnimation(mContext,
2087 R.anim.lock_screen_behind_enter);
2088 AnimationSet set = (AnimationSet) a;
2089
2090 // TODO: Use XML interpolators when we have log interpolators available in XML.
2091 set.getAnimations().get(0).setInterpolator(mLogDecelerateInterpolator);
2092 return set;
2093 }
2094 }
2095
2096
2097 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002098 public Animation createForceHideWallpaperExitAnimation(boolean goingToNotificationShade) {
2099 if (goingToNotificationShade) {
2100 return null;
2101 } else {
2102 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_wallpaper_exit);
2103 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002104 }
John Spurlockc8b46ca2013-04-08 12:59:26 -04002105
2106 private static void awakenDreams() {
2107 IDreamManager dreamManager = getDreamManager();
2108 if (dreamManager != null) {
2109 try {
2110 dreamManager.awaken();
2111 } catch (RemoteException e) {
2112 // fine, stay asleep then
2113 }
2114 }
2115 }
2116
2117 static IDreamManager getDreamManager() {
2118 return IDreamManager.Stub.asInterface(
2119 ServiceManager.checkService(DreamService.DREAM_SERVICE));
2120 }
2121
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002122 TelecomManager getTelecommService() {
2123 return (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002124 }
2125
Jeff Brown4d396052010-10-29 21:50:21 -07002126 static IAudioService getAudioService() {
2127 IAudioService audioService = IAudioService.Stub.asInterface(
2128 ServiceManager.checkService(Context.AUDIO_SERVICE));
2129 if (audioService == null) {
2130 Log.w(TAG, "Unable to find IAudioService interface.");
2131 }
2132 return audioService;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002133 }
2134
2135 boolean keyguardOn() {
2136 return keyguardIsShowingTq() || inKeyguardRestrictedKeyInputMode();
2137 }
2138
2139 private static final int[] WINDOW_TYPES_WHERE_HOME_DOESNT_WORK = {
2140 WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
2141 WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
2142 };
2143
2144 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002145 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002146 public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002147 final boolean keyguardOn = keyguardOn();
Jeff Brown1f245102010-11-18 20:53:46 -08002148 final int keyCode = event.getKeyCode();
2149 final int repeatCount = event.getRepeatCount();
2150 final int metaState = event.getMetaState();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002151 final int flags = event.getFlags();
Jeff Brown1f245102010-11-18 20:53:46 -08002152 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
2153 final boolean canceled = event.isCanceled();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002154
Jeff Brown40013652012-05-16 21:22:36 -07002155 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002156 Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount="
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002157 + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed
2158 + " canceled=" + canceled);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002159 }
2160
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002161 // If we think we might have a volume down & power key chord on the way
2162 // but we're not sure, then tell the dispatcher to wait a little while and
2163 // try again later before dispatching.
Christopher Tatee90585f2012-03-05 18:56:25 -08002164 if (mScreenshotChordEnabled && (flags & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002165 if (mVolumeDownKeyTriggered && !mPowerKeyTriggered) {
2166 final long now = SystemClock.uptimeMillis();
2167 final long timeoutTime = mVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS;
2168 if (now < timeoutTime) {
2169 return timeoutTime - now;
2170 }
2171 }
2172 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
2173 && mVolumeDownKeyConsumedByScreenshotChord) {
2174 if (!down) {
2175 mVolumeDownKeyConsumedByScreenshotChord = false;
2176 }
2177 return -1;
2178 }
2179 }
2180
Michael Wright6a62e552014-06-03 19:19:48 -07002181 // Cancel any pending meta actions if we see any other keys being pressed between the down
2182 // of the meta key and its corresponding up.
Michael Wright251e35d2014-08-22 15:40:27 -07002183 if (mPendingMetaAction && !KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07002184 mPendingMetaAction = false;
2185 }
2186
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002187 // First we always handle the home key here, so applications
2188 // can never break it, although if keyguard is on, we do let
2189 // it handle it, because that gives us the correct 5 second
2190 // timeout.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002191 if (keyCode == KeyEvent.KEYCODE_HOME) {
Michael Jurka7f2668c2012-03-27 07:49:52 -07002192
Jeff Brown49ed71d2010-12-06 17:13:33 -08002193 // If we have released the home key, and didn't do anything else
2194 // while it was pressed, then it is time to go home!
Michael Jurka7f2668c2012-03-27 07:49:52 -07002195 if (!down) {
Jeff Browncaca8812013-05-09 13:34:33 -07002196 cancelPreloadRecentApps();
2197
Jeff Brown49ed71d2010-12-06 17:13:33 -08002198 mHomePressed = false;
Jeff Browncaca8812013-05-09 13:34:33 -07002199 if (mHomeConsumed) {
2200 mHomeConsumed = false;
Michael Jurka7f2668c2012-03-27 07:49:52 -07002201 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002202 }
Jeff Browncaca8812013-05-09 13:34:33 -07002203
2204 if (canceled) {
2205 Log.i(TAG, "Ignoring HOME; event canceled.");
2206 return -1;
2207 }
2208
Jeff Browncaca8812013-05-09 13:34:33 -07002209 // Delay handling home if a double-tap is possible.
2210 if (mDoubleTapOnHomeBehavior != DOUBLE_TAP_HOME_NOTHING) {
2211 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); // just in case
2212 mHomeDoubleTapPending = true;
2213 mHandler.postDelayed(mHomeDoubleTapTimeoutRunnable,
2214 ViewConfiguration.getDoubleTapTimeout());
2215 return -1;
2216 }
2217
Jose Lima9546b202014-07-02 17:21:51 -07002218 // If there's a dream running then use home to escape the dream
2219 // but don't actually go home.
2220 if (mDreamManagerInternal != null && mDreamManagerInternal.isDreaming()) {
Jeff Brownf6d46682014-07-17 22:44:20 -07002221 mDreamManagerInternal.stopDream(false /*immediate*/);
Jose Lima9546b202014-07-02 17:21:51 -07002222 return -1;
2223 }
2224
Jeff Browncaca8812013-05-09 13:34:33 -07002225 // Go home!
2226 launchHomeFromHotKey();
2227 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002228 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002229
2230 // If a system window has focus, then it doesn't make sense
2231 // right now to interact with applications.
2232 WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null;
2233 if (attrs != null) {
2234 final int type = attrs.type;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002235 if (type == WindowManager.LayoutParams.TYPE_KEYGUARD_SCRIM
2236 || type == WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG
2237 || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002238 // the "app" is keyguard, so give it the key
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002239 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002240 }
2241 final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length;
2242 for (int i=0; i<typeCount; i++) {
2243 if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) {
2244 // don't do anything, but also don't pass it to the app
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002245 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002246 }
2247 }
2248 }
Jeff Browncaca8812013-05-09 13:34:33 -07002249
2250 // Remember that home is pressed and handle special actions.
2251 if (repeatCount == 0) {
2252 mHomePressed = true;
2253 if (mHomeDoubleTapPending) {
2254 mHomeDoubleTapPending = false;
2255 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable);
2256 handleDoubleTapOnHome();
2257 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI
2258 || mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
2259 preloadRecentApps();
Michael Jurka7f2668c2012-03-27 07:49:52 -07002260 }
Jeff Browncaca8812013-05-09 13:34:33 -07002261 } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) {
2262 if (!keyguardOn) {
2263 handleLongPressOnHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002264 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002265 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002266 return -1;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002267 } else if (keyCode == KeyEvent.KEYCODE_MENU) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002268 // Hijack modified menu keys for debugging features
2269 final int chordBug = KeyEvent.META_SHIFT_ON;
2270
2271 if (down && repeatCount == 0) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002272 if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002273 Intent intent = new Intent(Intent.ACTION_BUG_REPORT);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002274 mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT,
2275 null, null, null, 0, null, null);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002276 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002277 } else if (SHOW_PROCESSES_ON_ALT_MENU &&
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002278 (metaState & KeyEvent.META_ALT_ON) == KeyEvent.META_ALT_ON) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002279 Intent service = new Intent();
2280 service.setClassName(mContext, "com.android.server.LoadAverageService");
2281 ContentResolver res = mContext.getContentResolver();
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002282 boolean shown = Settings.Global.getInt(
2283 res, Settings.Global.SHOW_PROCESSES, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002284 if (!shown) {
2285 mContext.startService(service);
2286 } else {
2287 mContext.stopService(service);
2288 }
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002289 Settings.Global.putInt(
2290 res, Settings.Global.SHOW_PROCESSES, shown ? 0 : 1);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002291 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002292 }
2293 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002294 } else if (keyCode == KeyEvent.KEYCODE_SEARCH) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002295 if (down) {
2296 if (repeatCount == 0) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002297 mSearchKeyShortcutPending = true;
2298 mConsumeSearchKeyUp = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002299 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002300 } else {
2301 mSearchKeyShortcutPending = false;
2302 if (mConsumeSearchKeyUp) {
2303 mConsumeSearchKeyUp = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002304 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002305 }
2306 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002307 return 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002308 } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) {
Michael Wrightc9ebea72013-01-16 19:25:02 -08002309 if (!keyguardOn) {
Jeff Browncaca8812013-05-09 13:34:33 -07002310 if (down && repeatCount == 0) {
2311 preloadRecentApps();
2312 } else if (!down) {
2313 toggleRecentApps();
Michael Wrightc9ebea72013-01-16 19:25:02 -08002314 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002315 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002316 return -1;
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002317 } else if (keyCode == KeyEvent.KEYCODE_ASSIST) {
2318 if (down) {
2319 if (repeatCount == 0) {
2320 mAssistKeyLongPressed = false;
2321 } else if (repeatCount == 1) {
2322 mAssistKeyLongPressed = true;
2323 if (!keyguardOn) {
2324 launchAssistLongPressAction();
2325 }
2326 }
2327 } else {
2328 if (mAssistKeyLongPressed) {
2329 mAssistKeyLongPressed = false;
2330 } else {
2331 if (!keyguardOn) {
2332 launchAssistAction();
2333 }
2334 }
2335 }
2336 return -1;
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002337 } else if (keyCode == KeyEvent.KEYCODE_VOICE_ASSIST) {
2338 if (!down) {
2339 Intent voiceIntent;
Michael Wright869a67c2014-08-26 19:33:06 -07002340 if (!keyguardOn) {
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002341 voiceIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
2342 } else {
2343 voiceIntent = new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
Michael Wright869a67c2014-08-26 19:33:06 -07002344 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, true);
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002345 }
2346 mContext.startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
2347 }
Jeff Sharkey2991fa32012-12-05 18:06:43 -08002348 } else if (keyCode == KeyEvent.KEYCODE_SYSRQ) {
2349 if (down && repeatCount == 0) {
2350 mHandler.post(mScreenshotRunnable);
2351 }
2352 return -1;
Michael Wrightb854e242013-02-05 17:54:02 -08002353 } else if (keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP
2354 || keyCode == KeyEvent.KEYCODE_BRIGHTNESS_DOWN) {
2355 if (down) {
2356 int direction = keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP ? 1 : -1;
2357
2358 // Disable autobrightness if it's on
2359 int auto = Settings.System.getIntForUser(
2360 mContext.getContentResolver(),
2361 Settings.System.SCREEN_BRIGHTNESS_MODE,
2362 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2363 UserHandle.USER_CURRENT_OR_SELF);
2364 if (auto != 0) {
2365 Settings.System.putIntForUser(mContext.getContentResolver(),
2366 Settings.System.SCREEN_BRIGHTNESS_MODE,
2367 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2368 UserHandle.USER_CURRENT_OR_SELF);
2369 }
2370
2371 int min = mPowerManager.getMinimumScreenBrightnessSetting();
2372 int max = mPowerManager.getMaximumScreenBrightnessSetting();
2373 int step = (max - min + BRIGHTNESS_STEPS - 1) / BRIGHTNESS_STEPS * direction;
2374 int brightness = Settings.System.getIntForUser(mContext.getContentResolver(),
2375 Settings.System.SCREEN_BRIGHTNESS,
2376 mPowerManager.getDefaultScreenBrightnessSetting(),
2377 UserHandle.USER_CURRENT_OR_SELF);
2378 brightness += step;
2379 // Make sure we don't go beyond the limits.
2380 brightness = Math.min(max, brightness);
2381 brightness = Math.max(min, brightness);
2382
2383 Settings.System.putIntForUser(mContext.getContentResolver(),
2384 Settings.System.SCREEN_BRIGHTNESS, brightness,
2385 UserHandle.USER_CURRENT_OR_SELF);
Alan Viverette5a399492014-07-14 16:19:38 -07002386 mContext.startActivityAsUser(new Intent(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG),
2387 UserHandle.CURRENT_OR_SELF);
Michael Wrightb854e242013-02-05 17:54:02 -08002388 }
2389 return -1;
Michael Wrightce0c13a2014-07-30 10:49:21 -07002390 } else if (KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07002391 if (down) {
2392 mPendingMetaAction = true;
2393 } else if (mPendingMetaAction) {
Michael Wright8ab940a2014-09-01 11:01:27 -07002394 launchAssistAction(Intent.EXTRA_ASSIST_INPUT_HINT_KEYBOARD);
Michael Wright6a62e552014-06-03 19:19:48 -07002395 }
2396 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002397 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002398
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002399 // Shortcuts are invoked through Search+key, so intercept those here
Jeff Browncaab4d02010-12-09 22:13:41 -08002400 // Any printing key that is chorded with Search should be consumed
2401 // even if no shortcut was invoked. This prevents text from being
2402 // inadvertently inserted when using a keyboard that has built-in macro
2403 // shortcut keys (that emit Search+x) and some of them are not registered.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002404 if (mSearchKeyShortcutPending) {
Jeff Browncaab4d02010-12-09 22:13:41 -08002405 final KeyCharacterMap kcm = event.getKeyCharacterMap();
2406 if (kcm.isPrintingKey(keyCode)) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002407 mConsumeSearchKeyUp = true;
2408 mSearchKeyShortcutPending = false;
Jeff Browncaab4d02010-12-09 22:13:41 -08002409 if (down && repeatCount == 0 && !keyguardOn) {
2410 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState);
2411 if (shortcutIntent != null) {
2412 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002413 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002414 mContext.startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002415 } catch (ActivityNotFoundException ex) {
2416 Slog.w(TAG, "Dropping shortcut key combination because "
2417 + "the activity to which it is registered was not found: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002418 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode), ex);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002419 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002420 } else {
2421 Slog.i(TAG, "Dropping unregistered shortcut key combination: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002422 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002423 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002424 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002425 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002426 }
2427 }
2428
Jeff Brown68b909d2011-12-07 16:36:01 -08002429 // Invoke shortcuts using Meta.
Jeff Brown602ab322012-05-16 13:33:47 -07002430 if (down && repeatCount == 0 && !keyguardOn
Jeff Brown68b909d2011-12-07 16:36:01 -08002431 && (metaState & KeyEvent.META_META_ON) != 0) {
2432 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brown602ab322012-05-16 13:33:47 -07002433 if (kcm.isPrintingKey(keyCode)) {
2434 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode,
2435 metaState & ~(KeyEvent.META_META_ON
2436 | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON));
2437 if (shortcutIntent != null) {
2438 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2439 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002440 mContext.startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brown602ab322012-05-16 13:33:47 -07002441 } catch (ActivityNotFoundException ex) {
2442 Slog.w(TAG, "Dropping shortcut key combination because "
2443 + "the activity to which it is registered was not found: "
2444 + "META+" + KeyEvent.keyCodeToString(keyCode), ex);
2445 }
2446 return -1;
Jeff Brown68b909d2011-12-07 16:36:01 -08002447 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002448 }
2449 }
2450
Jeff Brown6651a632011-11-28 12:59:11 -08002451 // Handle application launch keys.
Jeff Brown602ab322012-05-16 13:33:47 -07002452 if (down && repeatCount == 0 && !keyguardOn) {
Jeff Brown6651a632011-11-28 12:59:11 -08002453 String category = sApplicationLaunchKeyCategories.get(keyCode);
2454 if (category != null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -08002455 Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category);
Jeff Brown6651a632011-11-28 12:59:11 -08002456 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2457 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002458 mContext.startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brown6651a632011-11-28 12:59:11 -08002459 } catch (ActivityNotFoundException ex) {
2460 Slog.w(TAG, "Dropping application launch key because "
2461 + "the activity to which it is registered was not found: "
2462 + "keyCode=" + keyCode + ", category=" + category, ex);
2463 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002464 return -1;
Jeff Brown6651a632011-11-28 12:59:11 -08002465 }
2466 }
2467
Michael Wright61c46752014-08-21 16:57:33 -07002468 // Display task switcher for ALT-TAB.
Jeff Brown68b909d2011-12-07 16:36:01 -08002469 if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_TAB) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002470 if (mRecentAppsHeldModifiers == 0 && !keyguardOn) {
Jeff Brown68b909d2011-12-07 16:36:01 -08002471 final int shiftlessModifiers = event.getModifiers() & ~KeyEvent.META_SHIFT_MASK;
Michael Wright61c46752014-08-21 16:57:33 -07002472 if (KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_ALT_ON)) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002473 mRecentAppsHeldModifiers = shiftlessModifiers;
2474 showRecentApps(true);
Jeff Brown68b909d2011-12-07 16:36:01 -08002475 return -1;
2476 }
2477 }
Winson Chung1e8d71b2014-05-16 17:05:22 -07002478 } else if (!down && mRecentAppsHeldModifiers != 0
2479 && (metaState & mRecentAppsHeldModifiers) == 0) {
2480 mRecentAppsHeldModifiers = 0;
Winson Chungcdcd4872014-08-05 18:00:13 -07002481 hideRecentApps(true, false);
Jeff Brown68b909d2011-12-07 16:36:01 -08002482 }
2483
Jeff Browncf39bdf2012-05-18 14:41:19 -07002484 // Handle keyboard language switching.
2485 if (down && repeatCount == 0
2486 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2487 || (keyCode == KeyEvent.KEYCODE_SPACE
2488 && (metaState & KeyEvent.META_CTRL_MASK) != 0))) {
2489 int direction = (metaState & KeyEvent.META_SHIFT_MASK) != 0 ? -1 : 1;
2490 mWindowManagerFuncs.switchKeyboardLayout(event.getDeviceId(), direction);
2491 return -1;
2492 }
2493 if (mLanguageSwitchKeyPressed && !down
2494 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2495 || keyCode == KeyEvent.KEYCODE_SPACE)) {
2496 mLanguageSwitchKeyPressed = false;
2497 return -1;
2498 }
2499
Justin Kohd378ad72013-04-01 12:18:26 -07002500 if (mGlobalKeyManager.handleGlobalKey(mContext, keyCode, event)) {
2501 return -1;
2502 }
2503
Michael Wright6a62e552014-06-03 19:19:48 -07002504 // Reserve all the META modifier combos for system behavior
Michael Wrightce0c13a2014-07-30 10:49:21 -07002505 if ((metaState & KeyEvent.META_META_ON) != 0) {
Michael Wright6a62e552014-06-03 19:19:48 -07002506 return -1;
2507 }
2508
Jeff Brown68b909d2011-12-07 16:36:01 -08002509 // Let the application handle the key.
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002510 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002511 }
2512
Jeff Brown3915bb82010-11-05 15:02:16 -07002513 /** {@inheritDoc} */
2514 @Override
Jeff Brown49ed71d2010-12-06 17:13:33 -08002515 public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown54875002011-04-06 15:33:01 -07002516 // Note: This method is only called if the initial down was unhandled.
Jeff Brown40013652012-05-16 21:22:36 -07002517 if (DEBUG_INPUT) {
Jeff Brown1f245102010-11-18 20:53:46 -08002518 Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction()
2519 + ", flags=" + event.getFlags()
2520 + ", keyCode=" + event.getKeyCode()
2521 + ", scanCode=" + event.getScanCode()
2522 + ", metaState=" + event.getMetaState()
2523 + ", repeatCount=" + event.getRepeatCount()
2524 + ", policyFlags=" + policyFlags);
Jeff Brown3915bb82010-11-05 15:02:16 -07002525 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002526
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002527 KeyEvent fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002528 if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
2529 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002530 final int keyCode = event.getKeyCode();
2531 final int metaState = event.getMetaState();
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002532 final boolean initialDown = event.getAction() == KeyEvent.ACTION_DOWN
2533 && event.getRepeatCount() == 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002534
Jeff Brown54875002011-04-06 15:33:01 -07002535 // Check for fallback actions specified by the key character map.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002536 final FallbackAction fallbackAction;
2537 if (initialDown) {
2538 fallbackAction = kcm.getFallbackAction(keyCode, metaState);
2539 } else {
2540 fallbackAction = mFallbackActions.get(keyCode);
2541 }
2542
2543 if (fallbackAction != null) {
Jeff Brown40013652012-05-16 21:22:36 -07002544 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002545 Slog.d(TAG, "Fallback: keyCode=" + fallbackAction.keyCode
2546 + " metaState=" + Integer.toHexString(fallbackAction.metaState));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002547 }
2548
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002549 final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK;
2550 fallbackEvent = KeyEvent.obtain(
Jeff Brown49ed71d2010-12-06 17:13:33 -08002551 event.getDownTime(), event.getEventTime(),
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002552 event.getAction(), fallbackAction.keyCode,
2553 event.getRepeatCount(), fallbackAction.metaState,
Jeff Brown49ed71d2010-12-06 17:13:33 -08002554 event.getDeviceId(), event.getScanCode(),
2555 flags, event.getSource(), null);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002556
2557 if (!interceptFallback(win, fallbackEvent, policyFlags)) {
2558 fallbackEvent.recycle();
2559 fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002560 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002561
2562 if (initialDown) {
2563 mFallbackActions.put(keyCode, fallbackAction);
2564 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2565 mFallbackActions.remove(keyCode);
2566 fallbackAction.recycle();
2567 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002568 }
2569 }
2570
Jeff Brown40013652012-05-16 21:22:36 -07002571 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002572 if (fallbackEvent == null) {
2573 Slog.d(TAG, "No fallback.");
2574 } else {
2575 Slog.d(TAG, "Performing fallback: " + fallbackEvent);
2576 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002577 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002578 return fallbackEvent;
Jeff Brown3915bb82010-11-05 15:02:16 -07002579 }
2580
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002581 private boolean interceptFallback(WindowState win, KeyEvent fallbackEvent, int policyFlags) {
Jeff Brown037c33e2014-04-09 00:31:55 -07002582 int actions = interceptKeyBeforeQueueing(fallbackEvent, policyFlags);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002583 if ((actions & ACTION_PASS_TO_USER) != 0) {
2584 long delayMillis = interceptKeyBeforeDispatching(
2585 win, fallbackEvent, policyFlags);
2586 if (delayMillis == 0) {
2587 return true;
2588 }
2589 }
2590 return false;
Jeff Brown6f2fba42011-02-19 01:08:02 -08002591 }
2592
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002593 private void launchAssistLongPressAction() {
2594 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
2595 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
2596
2597 // launch the search activity
2598 Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS);
2599 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2600 try {
RoboErik8a2cfc32014-05-16 11:19:38 -07002601 // TODO: This only stops the factory-installed search manager.
Jim Miller45308b12012-06-18 19:23:39 -07002602 // Need to formalize an API to handle others
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002603 SearchManager searchManager = getSearchManager();
2604 if (searchManager != null) {
2605 searchManager.stopSearch();
2606 }
Michael Wright43e27f72013-04-10 14:06:48 -07002607 mContext.startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002608 } catch (ActivityNotFoundException e) {
2609 Slog.w(TAG, "No activity to handle assist long press action.", e);
2610 }
2611 }
2612
2613 private void launchAssistAction() {
Michael Wright8ab940a2014-09-01 11:01:27 -07002614 launchAssistAction(null);
2615 }
2616
2617 private void launchAssistAction(String hint) {
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002618 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
Amith Yamasanic1d07a42012-08-14 09:32:02 -07002619 Intent intent = ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE))
Dianne Hackbornf9c5e0f2013-01-23 14:39:13 -08002620 .getAssistIntent(mContext, true, UserHandle.USER_CURRENT);
Jim Miller45308b12012-06-18 19:23:39 -07002621 if (intent != null) {
Michael Wright8ab940a2014-09-01 11:01:27 -07002622 if (hint != null) {
2623 intent.putExtra(hint, true);
2624 }
Jim Miller45308b12012-06-18 19:23:39 -07002625 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
2626 | Intent.FLAG_ACTIVITY_SINGLE_TOP
2627 | Intent.FLAG_ACTIVITY_CLEAR_TOP);
2628 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002629 mContext.startActivityAsUser(intent, UserHandle.CURRENT);
Jim Miller45308b12012-06-18 19:23:39 -07002630 } catch (ActivityNotFoundException e) {
2631 Slog.w(TAG, "No activity to handle assist action.", e);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002632 }
2633 }
2634 }
2635
2636 private SearchManager getSearchManager() {
2637 if (mSearchManager == null) {
2638 mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
2639 }
2640 return mSearchManager;
2641 }
2642
Jeff Browncaca8812013-05-09 13:34:33 -07002643 private void preloadRecentApps() {
2644 mPreloadedRecentApps = true;
2645 try {
2646 IStatusBarService statusbar = getStatusBarService();
2647 if (statusbar != null) {
2648 statusbar.preloadRecentApps();
2649 }
2650 } catch (RemoteException e) {
2651 Slog.e(TAG, "RemoteException when preloading recent apps", e);
2652 // re-acquire status bar service next time it is needed.
2653 mStatusBarService = null;
2654 }
2655 }
2656
2657 private void cancelPreloadRecentApps() {
2658 if (mPreloadedRecentApps) {
2659 mPreloadedRecentApps = false;
2660 try {
2661 IStatusBarService statusbar = getStatusBarService();
2662 if (statusbar != null) {
2663 statusbar.cancelPreloadRecentApps();
2664 }
2665 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002666 Slog.e(TAG, "RemoteException when cancelling recent apps preload", e);
Jeff Browncaca8812013-05-09 13:34:33 -07002667 // re-acquire status bar service next time it is needed.
2668 mStatusBarService = null;
2669 }
2670 }
2671 }
2672
2673 private void toggleRecentApps() {
2674 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
Jeff Browncaca8812013-05-09 13:34:33 -07002675 try {
2676 IStatusBarService statusbar = getStatusBarService();
2677 if (statusbar != null) {
2678 statusbar.toggleRecentApps();
2679 }
2680 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002681 Slog.e(TAG, "RemoteException when toggling recent apps", e);
2682 // re-acquire status bar service next time it is needed.
2683 mStatusBarService = null;
2684 }
2685 }
2686
Craig Mautner84984fa2014-06-19 11:19:20 -07002687 @Override
2688 public void showRecentApps() {
2689 mHandler.removeMessages(MSG_DISPATCH_SHOW_RECENTS);
2690 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_RECENTS);
2691 }
2692
Winson Chung1e8d71b2014-05-16 17:05:22 -07002693 private void showRecentApps(boolean triggeredFromAltTab) {
2694 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
2695 try {
2696 IStatusBarService statusbar = getStatusBarService();
2697 if (statusbar != null) {
2698 statusbar.showRecentApps(triggeredFromAltTab);
2699 }
2700 } catch (RemoteException e) {
Jeff Browncaca8812013-05-09 13:34:33 -07002701 Slog.e(TAG, "RemoteException when showing recent apps", e);
2702 // re-acquire status bar service next time it is needed.
2703 mStatusBarService = null;
2704 }
2705 }
2706
Winson Chungcdcd4872014-08-05 18:00:13 -07002707 private void hideRecentApps(boolean triggeredFromAltTab, boolean triggeredFromHome) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002708 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
2709 try {
2710 IStatusBarService statusbar = getStatusBarService();
2711 if (statusbar != null) {
Winson Chungcdcd4872014-08-05 18:00:13 -07002712 statusbar.hideRecentApps(triggeredFromAltTab, triggeredFromHome);
Winson Chung1e8d71b2014-05-16 17:05:22 -07002713 }
2714 } catch (RemoteException e) {
2715 Slog.e(TAG, "RemoteException when closing recent apps", e);
2716 // re-acquire status bar service next time it is needed.
2717 mStatusBarService = null;
2718 }
2719 }
2720
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002721 /**
2722 * A home key -> launch home action was detected. Take the appropriate action
2723 * given the situation with the keyguard.
2724 */
2725 void launchHomeFromHotKey() {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01002726 if (mKeyguardDelegate != null && mKeyguardDelegate.isShowingAndNotOccluded()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002727 // don't launch home if keyguard showing
Jim Miller5ecd8112013-01-09 18:50:26 -08002728 } else if (!mHideLockScreen && mKeyguardDelegate.isInputRestricted()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002729 // when in keyguard restricted mode, must first verify unlock
2730 // before launching home
Jim Miller5ecd8112013-01-09 18:50:26 -08002731 mKeyguardDelegate.verifyUnlock(new OnKeyguardExitResult() {
Jose Lima9546b202014-07-02 17:21:51 -07002732 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002733 public void onKeyguardExitResult(boolean success) {
2734 if (success) {
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07002735 try {
2736 ActivityManagerNative.getDefault().stopAppSwitches();
2737 } catch (RemoteException e) {
2738 }
Joe Onoratof275f0c2009-11-24 16:11:13 -05002739 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07002740 startDockOrHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002741 }
2742 }
2743 });
2744 } else {
2745 // no keyguard stuff to worry about, just launch home!
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07002746 try {
2747 ActivityManagerNative.getDefault().stopAppSwitches();
2748 } catch (RemoteException e) {
2749 }
Winson Chungd543c1b2014-06-23 15:06:45 -07002750 if (mRecentsVisible) {
2751 // Hide Recents and notify it to launch Home
2752 awakenDreams();
2753 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
Winson Chungcdcd4872014-08-05 18:00:13 -07002754 hideRecentApps(false, true);
Winson Chungd543c1b2014-06-23 15:06:45 -07002755 } else {
2756 // Otherwise, just launch Home
2757 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
2758 startDockOrHome();
2759 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002760 }
2761 }
2762
John Spurlock04db1762013-05-13 12:46:41 -04002763 private final Runnable mClearHideNavigationFlag = new Runnable() {
2764 @Override
2765 public void run() {
2766 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
2767 // Clear flags.
2768 mForceClearedSystemUiFlags &=
2769 ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
2770 }
2771 mWindowManagerFuncs.reevaluateStatusBarVisibility();
Dianne Hackborne26ab702011-10-16 13:21:33 -07002772 }
2773 };
2774
2775 /**
2776 * Input handler used while nav bar is hidden. Captures any touch on the screen,
2777 * to determine when the nav bar should be shown and prevent applications from
2778 * receiving those touches.
2779 */
Jeff Brown32cbc38552011-12-01 14:01:49 -08002780 final class HideNavInputEventReceiver extends InputEventReceiver {
2781 public HideNavInputEventReceiver(InputChannel inputChannel, Looper looper) {
2782 super(inputChannel, looper);
2783 }
2784
Dianne Hackborndf89e652011-10-06 22:35:11 -07002785 @Override
Jeff Brown32cbc38552011-12-01 14:01:49 -08002786 public void onInputEvent(InputEvent event) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07002787 boolean handled = false;
2788 try {
Jeff Brown4952dfd2011-11-30 19:23:22 -08002789 if (event instanceof MotionEvent
2790 && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
2791 final MotionEvent motionEvent = (MotionEvent)event;
2792 if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07002793 // When the user taps down, we re-show the nav bar.
2794 boolean changed = false;
John Spurlock04db1762013-05-13 12:46:41 -04002795 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002796 // Any user activity always causes us to show the
2797 // navigation controls, if they had been hidden.
2798 // We also clear the low profile and only content
2799 // flags so that tapping on the screen will atomically
2800 // restore all currently hidden screen decorations.
2801 int newVal = mResettingSystemUiFlags |
2802 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
2803 View.SYSTEM_UI_FLAG_LOW_PROFILE |
2804 View.SYSTEM_UI_FLAG_FULLSCREEN;
Dianne Hackborne26ab702011-10-16 13:21:33 -07002805 if (mResettingSystemUiFlags != newVal) {
2806 mResettingSystemUiFlags = newVal;
Dianne Hackborndf89e652011-10-06 22:35:11 -07002807 changed = true;
2808 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07002809 // We don't allow the system's nav bar to be hidden
2810 // again for 1 second, to prevent applications from
2811 // spamming us and keeping it from being shown.
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002812 newVal = mForceClearedSystemUiFlags |
2813 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
Dianne Hackborne26ab702011-10-16 13:21:33 -07002814 if (mForceClearedSystemUiFlags != newVal) {
2815 mForceClearedSystemUiFlags = newVal;
2816 changed = true;
John Spurlock04db1762013-05-13 12:46:41 -04002817 mHandler.postDelayed(mClearHideNavigationFlag, 1000);
Dianne Hackborne26ab702011-10-16 13:21:33 -07002818 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07002819 }
2820 if (changed) {
2821 mWindowManagerFuncs.reevaluateStatusBarVisibility();
2822 }
2823 }
2824 }
2825 } finally {
Jeff Brown32cbc38552011-12-01 14:01:49 -08002826 finishInputEvent(event, handled);
Dianne Hackborndf89e652011-10-06 22:35:11 -07002827 }
2828 }
Jeff Brown32cbc38552011-12-01 14:01:49 -08002829 }
2830 final InputEventReceiver.Factory mHideNavInputEventReceiverFactory =
2831 new InputEventReceiver.Factory() {
2832 @Override
2833 public InputEventReceiver createInputEventReceiver(
2834 InputChannel inputChannel, Looper looper) {
2835 return new HideNavInputEventReceiver(inputChannel, looper);
2836 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07002837 };
2838
2839 @Override
2840 public int adjustSystemUiVisibilityLw(int visibility) {
John Spurlock5b9145b2013-08-20 15:13:47 -04002841 mStatusBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
2842 mNavigationBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
Winson Chungd42a6cf2014-06-03 16:24:04 -07002843 mRecentsVisible = (visibility & View.RECENT_APPS_VISIBLE) > 0;
John Spurlock27735a42013-08-14 17:57:38 -04002844
Dianne Hackborndf89e652011-10-06 22:35:11 -07002845 // Reset any bits in mForceClearingStatusBarVisibility that
2846 // are now clear.
Dianne Hackborne26ab702011-10-16 13:21:33 -07002847 mResettingSystemUiFlags &= visibility;
Dianne Hackborndf89e652011-10-06 22:35:11 -07002848 // Clear any bits in the new visibility that are currently being
2849 // force cleared, before reporting it.
Dianne Hackborne26ab702011-10-16 13:21:33 -07002850 return visibility & ~mResettingSystemUiFlags
2851 & ~mForceClearedSystemUiFlags;
Dianne Hackborndf89e652011-10-06 22:35:11 -07002852 }
2853
Craig Mautner69b08182012-09-05 13:07:13 -07002854 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002855 public void getContentInsetHintLw(WindowManager.LayoutParams attrs, Rect contentInset) {
John Spurlockc6d1c602014-01-17 15:22:06 -05002856 final int fl = PolicyControl.getWindowFlags(null, attrs);
John Spurlock1db8b682014-02-18 11:18:59 -05002857 final int sysuiVis = PolicyControl.getSystemUiVisibility(null, attrs);
2858 final int systemUiVisibility = (sysuiVis | attrs.subtreeSystemUiVisibility);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002859
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002860 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002861 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002862 int availRight, availBottom;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07002863 if (canHideNavigationBar() &&
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002864 (systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002865 availRight = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
2866 availBottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
2867 } else {
2868 availRight = mRestrictedScreenLeft + mRestrictedScreenWidth;
2869 availBottom = mRestrictedScreenTop + mRestrictedScreenHeight;
2870 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002871 if ((systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
2872 if ((fl & FLAG_FULLSCREEN) != 0) {
2873 contentInset.set(mStableFullscreenLeft, mStableFullscreenTop,
2874 availRight - mStableFullscreenRight,
2875 availBottom - mStableFullscreenBottom);
2876 } else {
2877 contentInset.set(mStableLeft, mStableTop,
2878 availRight - mStableRight, availBottom - mStableBottom);
2879 }
Dianne Hackbornc652de82013-02-15 16:32:56 -08002880 } else if ((fl & FLAG_FULLSCREEN) != 0 || (fl & FLAG_LAYOUT_IN_OVERSCAN) != 0) {
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002881 contentInset.setEmpty();
2882 } else if ((systemUiVisibility & (View.SYSTEM_UI_FLAG_FULLSCREEN
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002883 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)) == 0) {
2884 contentInset.set(mCurLeft, mCurTop,
2885 availRight - mCurRight, availBottom - mCurBottom);
2886 } else {
2887 contentInset.set(mCurLeft, mCurTop,
2888 availRight - mCurRight, availBottom - mCurBottom);
2889 }
2890 return;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002891 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002892 contentInset.setEmpty();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002893 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002894
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002895 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07002896 @Override
2897 public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight,
2898 int displayRotation) {
Dianne Hackbornc652de82013-02-15 16:32:56 -08002899 final int overscanLeft, overscanTop, overscanRight, overscanBottom;
2900 if (isDefaultDisplay) {
2901 switch (displayRotation) {
2902 case Surface.ROTATION_90:
2903 overscanLeft = mOverscanTop;
2904 overscanTop = mOverscanRight;
2905 overscanRight = mOverscanBottom;
2906 overscanBottom = mOverscanLeft;
2907 break;
2908 case Surface.ROTATION_180:
2909 overscanLeft = mOverscanRight;
2910 overscanTop = mOverscanBottom;
2911 overscanRight = mOverscanLeft;
2912 overscanBottom = mOverscanTop;
2913 break;
2914 case Surface.ROTATION_270:
2915 overscanLeft = mOverscanBottom;
2916 overscanTop = mOverscanLeft;
2917 overscanRight = mOverscanTop;
2918 overscanBottom = mOverscanRight;
2919 break;
2920 default:
2921 overscanLeft = mOverscanLeft;
2922 overscanTop = mOverscanTop;
2923 overscanRight = mOverscanRight;
2924 overscanBottom = mOverscanBottom;
2925 break;
2926 }
2927 } else {
2928 overscanLeft = 0;
2929 overscanTop = 0;
2930 overscanRight = 0;
2931 overscanBottom = 0;
2932 }
Dianne Hackborn313440842013-02-19 19:22:59 -08002933 mOverscanScreenLeft = mRestrictedOverscanScreenLeft = 0;
2934 mOverscanScreenTop = mRestrictedOverscanScreenTop = 0;
2935 mOverscanScreenWidth = mRestrictedOverscanScreenWidth = displayWidth;
2936 mOverscanScreenHeight = mRestrictedOverscanScreenHeight = displayHeight;
Dianne Hackbornc652de82013-02-15 16:32:56 -08002937 mSystemLeft = 0;
2938 mSystemTop = 0;
2939 mSystemRight = displayWidth;
2940 mSystemBottom = displayHeight;
2941 mUnrestrictedScreenLeft = overscanLeft;
2942 mUnrestrictedScreenTop = overscanTop;
2943 mUnrestrictedScreenWidth = displayWidth - overscanLeft - overscanRight;
2944 mUnrestrictedScreenHeight = displayHeight - overscanTop - overscanBottom;
2945 mRestrictedScreenLeft = mUnrestrictedScreenLeft;
2946 mRestrictedScreenTop = mUnrestrictedScreenTop;
John Spurlockad3e6cb2013-04-30 08:47:43 -04002947 mRestrictedScreenWidth = mSystemGestures.screenWidth = mUnrestrictedScreenWidth;
2948 mRestrictedScreenHeight = mSystemGestures.screenHeight = mUnrestrictedScreenHeight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002949 mDockLeft = mContentLeft = mVoiceContentLeft = mStableLeft = mStableFullscreenLeft
Dianne Hackbornc652de82013-02-15 16:32:56 -08002950 = mCurLeft = mUnrestrictedScreenLeft;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002951 mDockTop = mContentTop = mVoiceContentTop = mStableTop = mStableFullscreenTop
Dianne Hackbornc652de82013-02-15 16:32:56 -08002952 = mCurTop = mUnrestrictedScreenTop;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002953 mDockRight = mContentRight = mVoiceContentRight = mStableRight = mStableFullscreenRight
Dianne Hackbornc652de82013-02-15 16:32:56 -08002954 = mCurRight = displayWidth - overscanRight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002955 mDockBottom = mContentBottom = mVoiceContentBottom = mStableBottom = mStableFullscreenBottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08002956 = mCurBottom = displayHeight - overscanBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002957 mDockLayer = 0x10000000;
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002958 mStatusBarLayer = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002959
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002960 // start with the current dock rect, which will be (0,0,displayWidth,displayHeight)
2961 final Rect pf = mTmpParentFrame;
2962 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002963 final Rect of = mTmpOverscanFrame;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002964 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04002965 final Rect dcf = mTmpDecorFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002966 pf.left = df.left = of.left = vf.left = mDockLeft;
2967 pf.top = df.top = of.top = vf.top = mDockTop;
2968 pf.right = df.right = of.right = vf.right = mDockRight;
2969 pf.bottom = df.bottom = of.bottom = vf.bottom = mDockBottom;
John Spurlock46646232013-09-30 22:32:42 -04002970 dcf.setEmpty(); // Decor frame N/A for system bars.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002971
Craig Mautner69b08182012-09-05 13:07:13 -07002972 if (isDefaultDisplay) {
2973 // For purposes of putting out fake window up to steal focus, we will
2974 // drive nav being hidden only by whether it is requested.
John Spurlocke1f366f2013-08-05 12:22:40 -04002975 final int sysui = mLastSystemUiFlags;
2976 boolean navVisible = (sysui & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0;
Adrian Roosea562512014-05-05 13:33:03 +02002977 boolean navTranslucent = (sysui
2978 & (View.NAVIGATION_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04002979 boolean immersive = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
2980 boolean immersiveSticky = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
2981 boolean navAllowedHidden = immersive || immersiveSticky;
2982 navTranslucent &= !immersiveSticky; // transient trumps translucent
Adrian Roos4fb3ee32014-08-22 19:29:09 +02002983 boolean isKeyguardShowing = isStatusBarKeyguard() && !mHideLockScreen;
2984 if (!isKeyguardShowing) {
2985 navTranslucent &= areTranslucentBarsAllowed();
2986 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07002987
Craig Mautner69b08182012-09-05 13:07:13 -07002988 // When the navigation bar isn't visible, we put up a fake
2989 // input window to catch all touch events. This way we can
2990 // detect when the user presses anywhere to bring back the nav
2991 // bar and ensure the application doesn't see the event.
John Spurlockf1a36642013-10-12 17:50:42 -04002992 if (navVisible || navAllowedHidden) {
Craig Mautner69b08182012-09-05 13:07:13 -07002993 if (mHideNavFakeWindow != null) {
2994 mHideNavFakeWindow.dismiss();
2995 mHideNavFakeWindow = null;
2996 }
2997 } else if (mHideNavFakeWindow == null) {
2998 mHideNavFakeWindow = mWindowManagerFuncs.addFakeWindow(
2999 mHandler.getLooper(), mHideNavInputEventReceiverFactory,
Adam Lesinski95c42972013-10-02 10:13:27 -07003000 "hidden nav", WindowManager.LayoutParams.TYPE_HIDDEN_NAV_CONSUMER, 0,
Craig Mautner69b08182012-09-05 13:07:13 -07003001 0, false, false, true);
Dianne Hackborne26ab702011-10-16 13:21:33 -07003002 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003003
Craig Mautner69b08182012-09-05 13:07:13 -07003004 // For purposes of positioning and showing the nav bar, if we have
3005 // decided that it can't be hidden (because of the screen aspect ratio),
3006 // then take that into account.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003007 navVisible |= !canHideNavigationBar();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003008
John Spurlockad3e6cb2013-04-30 08:47:43 -04003009 boolean updateSysUiVisibility = false;
Craig Mautner69b08182012-09-05 13:07:13 -07003010 if (mNavigationBar != null) {
John Spurlock27735a42013-08-14 17:57:38 -04003011 boolean transientNavBarShowing = mNavigationBarController.isTransientShowing();
Craig Mautner69b08182012-09-05 13:07:13 -07003012 // Force the navigation bar to its appropriate place and
3013 // size. We need to do this directly, instead of relying on
3014 // it to bubble up from the nav bar, because this needs to
3015 // change atomically with screen rotations.
3016 mNavigationBarOnBottom = (!mNavigationBarCanMove || displayWidth < displayHeight);
3017 if (mNavigationBarOnBottom) {
3018 // It's a system nav bar or a portrait screen; nav bar goes on bottom.
Dianne Hackbornc652de82013-02-15 16:32:56 -08003019 int top = displayHeight - overscanBottom
3020 - mNavigationBarHeightForRotation[displayRotation];
3021 mTmpNavigationFrame.set(0, top, displayWidth, displayHeight - overscanBottom);
Craig Mautner69b08182012-09-05 13:07:13 -07003022 mStableBottom = mStableFullscreenBottom = mTmpNavigationFrame.top;
John Spurlockf95b89a2013-10-10 22:10:42 -04003023 if (transientNavBarShowing) {
John Spurlock27735a42013-08-14 17:57:38 -04003024 mNavigationBarController.setBarShowingLw(true);
John Spurlockad3e6cb2013-04-30 08:47:43 -04003025 } else if (navVisible) {
John Spurlock27735a42013-08-14 17:57:38 -04003026 mNavigationBarController.setBarShowingLw(true);
Craig Mautner69b08182012-09-05 13:07:13 -07003027 mDockBottom = mTmpNavigationFrame.top;
Dianne Hackborn313440842013-02-19 19:22:59 -08003028 mRestrictedScreenHeight = mDockBottom - mRestrictedScreenTop;
3029 mRestrictedOverscanScreenHeight = mDockBottom - mRestrictedOverscanScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07003030 } else {
3031 // We currently want to hide the navigation UI.
John Spurlock27735a42013-08-14 17:57:38 -04003032 mNavigationBarController.setBarShowingLw(false);
Craig Mautner69b08182012-09-05 13:07:13 -07003033 }
John Spurlockc6d1c602014-01-17 15:22:06 -05003034 if (navVisible && !navTranslucent && !navAllowedHidden
3035 && !mNavigationBar.isAnimatingLw()
John Spurlockbd957402013-10-03 11:38:39 -04003036 && !mNavigationBarController.wasRecentlyTranslucent()) {
John Spurlocke1f366f2013-08-05 12:22:40 -04003037 // If the opaque nav bar is currently requested to be visible,
Craig Mautner69b08182012-09-05 13:07:13 -07003038 // and not in the process of animating on or off, then
3039 // we can tell the app that it is covered by it.
3040 mSystemBottom = mTmpNavigationFrame.top;
3041 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003042 } else {
Craig Mautner69b08182012-09-05 13:07:13 -07003043 // Landscape screen; nav bar goes to the right.
Dianne Hackbornc652de82013-02-15 16:32:56 -08003044 int left = displayWidth - overscanRight
3045 - mNavigationBarWidthForRotation[displayRotation];
3046 mTmpNavigationFrame.set(left, 0, displayWidth - overscanRight, displayHeight);
Craig Mautner69b08182012-09-05 13:07:13 -07003047 mStableRight = mStableFullscreenRight = mTmpNavigationFrame.left;
John Spurlockf95b89a2013-10-10 22:10:42 -04003048 if (transientNavBarShowing) {
John Spurlock27735a42013-08-14 17:57:38 -04003049 mNavigationBarController.setBarShowingLw(true);
John Spurlockad3e6cb2013-04-30 08:47:43 -04003050 } else if (navVisible) {
John Spurlock27735a42013-08-14 17:57:38 -04003051 mNavigationBarController.setBarShowingLw(true);
Craig Mautner69b08182012-09-05 13:07:13 -07003052 mDockRight = mTmpNavigationFrame.left;
Dianne Hackborn313440842013-02-19 19:22:59 -08003053 mRestrictedScreenWidth = mDockRight - mRestrictedScreenLeft;
3054 mRestrictedOverscanScreenWidth = mDockRight - mRestrictedOverscanScreenLeft;
Craig Mautner69b08182012-09-05 13:07:13 -07003055 } else {
3056 // We currently want to hide the navigation UI.
John Spurlock27735a42013-08-14 17:57:38 -04003057 mNavigationBarController.setBarShowingLw(false);
Craig Mautner69b08182012-09-05 13:07:13 -07003058 }
John Spurlockbd957402013-10-03 11:38:39 -04003059 if (navVisible && !navTranslucent && !mNavigationBar.isAnimatingLw()
3060 && !mNavigationBarController.wasRecentlyTranslucent()) {
Craig Mautner69b08182012-09-05 13:07:13 -07003061 // If the nav bar is currently requested to be visible,
3062 // and not in the process of animating on or off, then
3063 // we can tell the app that it is covered by it.
3064 mSystemRight = mTmpNavigationFrame.left;
3065 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003066 }
Craig Mautner69b08182012-09-05 13:07:13 -07003067 // Make sure the content and current rectangles are updated to
3068 // account for the restrictions from the navigation bar.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003069 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3070 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3071 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3072 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
Craig Mautner69b08182012-09-05 13:07:13 -07003073 mStatusBarLayer = mNavigationBar.getSurfaceLayer();
3074 // And compute the final frame.
3075 mNavigationBar.computeFrameLw(mTmpNavigationFrame, mTmpNavigationFrame,
Adrian Roosfa104232014-06-20 16:10:14 -07003076 mTmpNavigationFrame, mTmpNavigationFrame, mTmpNavigationFrame, dcf,
3077 mTmpNavigationFrame);
Craig Mautnereda67292013-04-28 13:50:14 -07003078 if (DEBUG_LAYOUT) Slog.i(TAG, "mNavigationBar frame: " + mTmpNavigationFrame);
John Spurlock27735a42013-08-14 17:57:38 -04003079 if (mNavigationBarController.checkHiddenLw()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04003080 updateSysUiVisibility = true;
3081 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003082 }
Craig Mautnereda67292013-04-28 13:50:14 -07003083 if (DEBUG_LAYOUT) Slog.i(TAG, String.format("mDock rect: (%d,%d - %d,%d)",
Craig Mautner69b08182012-09-05 13:07:13 -07003084 mDockLeft, mDockTop, mDockRight, mDockBottom));
3085
3086 // decide where the status bar goes ahead of time
3087 if (mStatusBar != null) {
3088 // apply any navigation bar insets
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003089 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3090 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3091 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
3092 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight
3093 + mUnrestrictedScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07003094 vf.left = mStableLeft;
3095 vf.top = mStableTop;
3096 vf.right = mStableRight;
3097 vf.bottom = mStableBottom;
3098
3099 mStatusBarLayer = mStatusBar.getSurfaceLayer();
3100
3101 // Let the status bar determine its size.
Adrian Roosfa104232014-06-20 16:10:14 -07003102 mStatusBar.computeFrameLw(pf, df, vf, vf, vf, dcf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07003103
3104 // For layout, the status bar is always at the top with our fixed height.
3105 mStableTop = mUnrestrictedScreenTop + mStatusBarHeight;
3106
John Spurlocke1f366f2013-08-05 12:22:40 -04003107 boolean statusBarTransient = (sysui & View.STATUS_BAR_TRANSIENT) != 0;
Adrian Roosea562512014-05-05 13:33:03 +02003108 boolean statusBarTranslucent = (sysui
3109 & (View.STATUS_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0;
Adrian Roos4fb3ee32014-08-22 19:29:09 +02003110 if (!isKeyguardShowing) {
3111 statusBarTranslucent &= areTranslucentBarsAllowed();
3112 }
John Spurlock32beb2c2013-03-11 10:16:47 -04003113
Craig Mautner69b08182012-09-05 13:07:13 -07003114 // If the status bar is hidden, we don't want to cause
3115 // windows behind it to scroll.
John Spurlockeda1f692013-09-16 11:38:44 -04003116 if (mStatusBar.isVisibleLw() && !statusBarTransient) {
Craig Mautner69b08182012-09-05 13:07:13 -07003117 // Status bar may go away, so the screen area it occupies
3118 // is available to apps but just covering them when the
3119 // status bar is visible.
3120 mDockTop = mUnrestrictedScreenTop + mStatusBarHeight;
3121
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003122 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3123 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3124 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3125 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
Craig Mautner69b08182012-09-05 13:07:13 -07003126
Craig Mautnereda67292013-04-28 13:50:14 -07003127 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar: " +
Craig Mautner69b08182012-09-05 13:07:13 -07003128 String.format(
3129 "dock=[%d,%d][%d,%d] content=[%d,%d][%d,%d] cur=[%d,%d][%d,%d]",
3130 mDockLeft, mDockTop, mDockRight, mDockBottom,
3131 mContentLeft, mContentTop, mContentRight, mContentBottom,
3132 mCurLeft, mCurTop, mCurRight, mCurBottom));
3133 }
John Spurlocke1f366f2013-08-05 12:22:40 -04003134 if (mStatusBar.isVisibleLw() && !mStatusBar.isAnimatingLw()
John Spurlockbd957402013-10-03 11:38:39 -04003135 && !statusBarTransient && !statusBarTranslucent
3136 && !mStatusBarController.wasRecentlyTranslucent()) {
John Spurlocke1f366f2013-08-05 12:22:40 -04003137 // If the opaque status bar is currently requested to be visible,
Craig Mautner69b08182012-09-05 13:07:13 -07003138 // and not in the process of animating on or off, then
3139 // we can tell the app that it is covered by it.
3140 mSystemTop = mUnrestrictedScreenTop + mStatusBarHeight;
3141 }
John Spurlock27735a42013-08-14 17:57:38 -04003142 if (mStatusBarController.checkHiddenLw()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04003143 updateSysUiVisibility = true;
John Spurlock32beb2c2013-03-11 10:16:47 -04003144 }
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003145 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04003146 if (updateSysUiVisibility) {
3147 updateSystemUiVisibilityLw();
3148 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003149 }
3150 }
3151
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003152 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07003153 @Override
John Spurlock46646232013-09-30 22:32:42 -04003154 public int getSystemDecorLayerLw() {
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003155 if (mStatusBar != null) return mStatusBar.getSurfaceLayer();
3156 if (mNavigationBar != null) return mNavigationBar.getSurfaceLayer();
3157 return 0;
3158 }
3159
Craig Mautner967212c2013-04-13 21:10:58 -07003160 @Override
3161 public void getContentRectLw(Rect r) {
3162 r.set(mContentLeft, mContentTop, mContentRight, mContentBottom);
3163 }
3164
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003165 void setAttachedWindowFrames(WindowState win, int fl, int adjust, WindowState attached,
3166 boolean insetDecors, Rect pf, Rect df, Rect of, Rect cf, Rect vf) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003167 if (win.getSurfaceLayer() > mDockLayer && attached.getSurfaceLayer() < mDockLayer) {
3168 // Here's a special case: if this attached window is a panel that is
3169 // above the dock window, and the window it is attached to is below
3170 // the dock window, then the frames we computed for the window it is
3171 // attached to can not be used because the dock is effectively part
3172 // of the underlying window and the attached window is floating on top
3173 // of the whole thing. So, we ignore the attached window and explicitly
3174 // compute the frames that would be appropriate without the dock.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003175 df.left = of.left = cf.left = vf.left = mDockLeft;
3176 df.top = of.top = cf.top = vf.top = mDockTop;
3177 df.right = of.right = cf.right = vf.right = mDockRight;
3178 df.bottom = of.bottom = cf.bottom = vf.bottom = mDockBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003179 } else {
3180 // The effective display frame of the attached window depends on
3181 // whether it is taking care of insetting its content. If not,
3182 // we need to use the parent's content frame so that the entire
3183 // window is positioned within that content. Otherwise we can use
Wale Ogunwale393b1c12014-10-18 16:22:01 -07003184 // the overscan frame and let the attached window take care of
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003185 // positioning its content appropriately.
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003186 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Wale Ogunwale393b1c12014-10-18 16:22:01 -07003187 // Set the content frame of the attached window to the parent's decor frame
3188 // (same as content frame when IME isn't present) if specifically requested by
3189 // setting {@link WindowManager.LayoutParams#FLAG_LAYOUT_ATTACHED_IN_DECOR} flag.
3190 // Otherwise, use the overscan frame.
3191 cf.set((fl & FLAG_LAYOUT_ATTACHED_IN_DECOR) != 0
3192 ? attached.getContentFrameLw() : attached.getOverscanFrameLw());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003193 } else {
3194 // If the window is resizing, then we want to base the content
3195 // frame on our attached content frame to resize... however,
3196 // things can be tricky if the attached window is NOT in resize
3197 // mode, in which case its content frame will be larger.
3198 // Ungh. So to deal with that, make sure the content frame
3199 // we end up using is not covering the IM dock.
3200 cf.set(attached.getContentFrameLw());
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003201 if (attached.isVoiceInteraction()) {
3202 if (cf.left < mVoiceContentLeft) cf.left = mVoiceContentLeft;
3203 if (cf.top < mVoiceContentTop) cf.top = mVoiceContentTop;
3204 if (cf.right > mVoiceContentRight) cf.right = mVoiceContentRight;
3205 if (cf.bottom > mVoiceContentBottom) cf.bottom = mVoiceContentBottom;
3206 } else if (attached.getSurfaceLayer() < mDockLayer) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003207 if (cf.left < mContentLeft) cf.left = mContentLeft;
3208 if (cf.top < mContentTop) cf.top = mContentTop;
3209 if (cf.right > mContentRight) cf.right = mContentRight;
3210 if (cf.bottom > mContentBottom) cf.bottom = mContentBottom;
3211 }
3212 }
3213 df.set(insetDecors ? attached.getDisplayFrameLw() : cf);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003214 of.set(insetDecors ? attached.getOverscanFrameLw() : cf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003215 vf.set(attached.getVisibleFrameLw());
3216 }
3217 // The LAYOUT_IN_SCREEN flag is used to determine whether the attached
3218 // window should be positioned relative to its parent or the entire
3219 // screen.
3220 pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0
3221 ? attached.getFrameLw() : df);
3222 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003223
3224 private void applyStableConstraints(int sysui, int fl, Rect r) {
3225 if ((sysui & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
3226 // If app is requesting a stable layout, don't let the
3227 // content insets go below the stable values.
3228 if ((fl & FLAG_FULLSCREEN) != 0) {
3229 if (r.left < mStableFullscreenLeft) r.left = mStableFullscreenLeft;
3230 if (r.top < mStableFullscreenTop) r.top = mStableFullscreenTop;
3231 if (r.right > mStableFullscreenRight) r.right = mStableFullscreenRight;
3232 if (r.bottom > mStableFullscreenBottom) r.bottom = mStableFullscreenBottom;
3233 } else {
3234 if (r.left < mStableLeft) r.left = mStableLeft;
3235 if (r.top < mStableTop) r.top = mStableTop;
3236 if (r.right > mStableRight) r.right = mStableRight;
3237 if (r.bottom > mStableBottom) r.bottom = mStableBottom;
3238 }
3239 }
3240 }
3241
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003242 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07003243 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003244 public void layoutWindowLw(WindowState win, WindowState attached) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003245 // we've already done the status bar
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003246 final WindowManager.LayoutParams attrs = win.getAttrs();
3247 if ((win == mStatusBar && (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) == 0) ||
3248 win == mNavigationBar) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003249 return;
3250 }
Craig Mautner69b08182012-09-05 13:07:13 -07003251 final boolean isDefaultDisplay = win.isDefaultDisplay();
3252 final boolean needsToOffsetInputMethodTarget = isDefaultDisplay &&
satok1bc0a492012-04-25 22:47:12 +09003253 (win == mLastInputMethodTargetWindow && mLastInputMethodWindow != null);
3254 if (needsToOffsetInputMethodTarget) {
Craig Mautnereda67292013-04-28 13:50:14 -07003255 if (DEBUG_LAYOUT) Slog.i(TAG, "Offset ime target window by the last ime window state");
satok1bc0a492012-04-25 22:47:12 +09003256 offsetInputMethodWindowLw(mLastInputMethodWindow);
3257 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003258
John Spurlockc6d1c602014-01-17 15:22:06 -05003259 final int fl = PolicyControl.getWindowFlags(win, attrs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003260 final int sim = attrs.softInputMode;
John Spurlock1db8b682014-02-18 11:18:59 -05003261 final int sysUiFl = PolicyControl.getSystemUiVisibility(win, null);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003262
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003263 final Rect pf = mTmpParentFrame;
3264 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003265 final Rect of = mTmpOverscanFrame;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003266 final Rect cf = mTmpContentFrame;
3267 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04003268 final Rect dcf = mTmpDecorFrame;
Adrian Roosfa104232014-06-20 16:10:14 -07003269 final Rect sf = mTmpStableFrame;
John Spurlock46646232013-09-30 22:32:42 -04003270 dcf.setEmpty();
Craig Mautner69b08182012-09-05 13:07:13 -07003271
3272 final boolean hasNavBar = (isDefaultDisplay && mHasNavigationBar
Daniel Sandler36412a72011-08-04 09:35:13 -04003273 && mNavigationBar != null && mNavigationBar.isVisibleLw());
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003274
Craig Mautnerf683b562012-10-02 11:10:57 -07003275 final int adjust = sim & SOFT_INPUT_MASK_ADJUST;
3276
Adrian Roosfa104232014-06-20 16:10:14 -07003277 if (isDefaultDisplay) {
3278 sf.set(mStableLeft, mStableTop, mStableRight, mStableBottom);
3279 } else {
3280 sf.set(mOverscanLeft, mOverscanTop, mOverscanRight, mOverscanBottom);
3281 }
3282
Craig Mautner69b08182012-09-05 13:07:13 -07003283 if (!isDefaultDisplay) {
3284 if (attached != null) {
3285 // If this window is attached to another, our display
3286 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003287 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07003288 } else {
3289 // Give the window full screen.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003290 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3291 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3292 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08003293 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003294 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003295 = mOverscanScreenTop + mOverscanScreenHeight;
Craig Mautner69b08182012-09-05 13:07:13 -07003296 }
3297 } else if (attrs.type == TYPE_INPUT_METHOD) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003298 pf.left = df.left = of.left = cf.left = vf.left = mDockLeft;
3299 pf.top = df.top = of.top = cf.top = vf.top = mDockTop;
3300 pf.right = df.right = of.right = cf.right = vf.right = mDockRight;
John Spurlockc68d5772013-10-08 11:47:58 -04003301 // IM dock windows layout below the nav bar...
John Spurlock57beb3b2013-10-10 10:27:44 -04003302 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlockc68d5772013-10-08 11:47:58 -04003303 // ...with content insets above the nav bar
3304 cf.bottom = vf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003305 // IM dock windows always go to the bottom of the screen.
3306 attrs.gravity = Gravity.BOTTOM;
3307 mDockLayer = win.getSurfaceLayer();
Jorim Jaggie0700182014-08-21 01:12:37 +02003308 } else if (win == mStatusBar && (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
3309 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3310 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3311 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
3312 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight + mUnrestrictedScreenTop;
3313 cf.left = vf.left = mStableLeft;
3314 cf.top = vf.top = mStableTop;
3315 cf.right = vf.right = mStableRight;
3316 vf.bottom = mStableBottom;
3317 cf.bottom = mContentBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003318 } else {
John Spurlock46646232013-09-30 22:32:42 -04003319
3320 // Default policy decor for the default display
3321 dcf.left = mSystemLeft;
3322 dcf.top = mSystemTop;
3323 dcf.right = mSystemRight;
3324 dcf.bottom = mSystemBottom;
John Spurlockbd957402013-10-03 11:38:39 -04003325 final boolean inheritTranslucentDecor = (attrs.privateFlags
3326 & WindowManager.LayoutParams.PRIVATE_FLAG_INHERIT_TRANSLUCENT_DECOR) != 0;
John Spurlock65567d42013-10-08 10:08:32 -04003327 final boolean isAppWindow =
3328 attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW &&
3329 attrs.type <= WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
3330 final boolean topAtRest =
3331 win == mTopFullscreenOpaqueWindowState && !win.isAnimatingLw();
3332 if (isAppWindow && !inheritTranslucentDecor && !topAtRest) {
John Spurlockbd957402013-10-03 11:38:39 -04003333 if ((sysUiFl & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0
3334 && (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0
Adrian Roosea562512014-05-05 13:33:03 +02003335 && (fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) == 0
3336 && (fl & WindowManager.LayoutParams.
3337 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04003338 // Ensure policy decor includes status bar
3339 dcf.top = mStableTop;
3340 }
John Spurlockbd957402013-10-03 11:38:39 -04003341 if ((fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) == 0
Adrian Roosea562512014-05-05 13:33:03 +02003342 && (sysUiFl & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0
3343 && (fl & WindowManager.LayoutParams.
3344 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04003345 // Ensure policy decor includes navigation bar
3346 dcf.bottom = mStableBottom;
3347 dcf.right = mStableRight;
3348 }
3349 }
3350
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003351 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
3352 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
RoboErik8a2cfc32014-05-16 11:19:38 -07003353 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003354 + "): IN_SCREEN, INSET_DECOR");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003355 // This is the case for a normal activity window: we want it
3356 // to cover all of the screen space, and it can take care of
3357 // moving its contents to account for screen decorations that
3358 // intrude into that space.
3359 if (attached != null) {
3360 // If this window is attached to another, our display
3361 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003362 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003363 } else {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003364 if (attrs.type == TYPE_STATUS_BAR_PANEL
3365 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Joe Onorato29fc2c92010-11-24 10:26:50 -08003366 // Status bar panels are the only windows who can go on top of
3367 // the status bar. They are protected by the STATUS_BAR_SERVICE
3368 // permission, so they have the same privileges as the status
3369 // bar itself.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003370 //
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003371 // However, they should still dodge the navigation bar if it exists.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003372
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003373 pf.left = df.left = of.left = hasNavBar
3374 ? mDockLeft : mUnrestrictedScreenLeft;
3375 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3376 pf.right = df.right = of.right = hasNavBar
3377 ? mRestrictedScreenLeft+mRestrictedScreenWidth
3378 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3379 pf.bottom = df.bottom = of.bottom = hasNavBar
3380 ? mRestrictedScreenTop+mRestrictedScreenHeight
3381 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003382
Craig Mautnereda67292013-04-28 13:50:14 -07003383 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003384 "Laying out status bar window: (%d,%d - %d,%d)",
3385 pf.left, pf.top, pf.right, pf.bottom));
John Spurlock46646232013-09-30 22:32:42 -04003386 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08003387 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3388 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3389 // Asking to layout into the overscan region, so give it that pure
3390 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003391 pf.left = df.left = of.left = mOverscanScreenLeft;
3392 pf.top = df.top = of.top = mOverscanScreenTop;
3393 pf.right = df.right = of.right = mOverscanScreenLeft + mOverscanScreenWidth;
3394 pf.bottom = df.bottom = of.bottom = mOverscanScreenTop
3395 + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003396 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003397 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003398 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3399 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003400 // Asking for layout as if the nav bar is hidden, lets the
Dianne Hackbornc652de82013-02-15 16:32:56 -08003401 // application extend into the unrestricted overscan screen area. We
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003402 // only do this for application windows to ensure no window that
3403 // can be above the nav bar can do this.
Dianne Hackborn313440842013-02-19 19:22:59 -08003404 pf.left = df.left = mOverscanScreenLeft;
3405 pf.top = df.top = mOverscanScreenTop;
3406 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
3407 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003408 // We need to tell the app about where the frame inside the overscan
3409 // is, so it can inset its content by that amount -- it didn't ask
3410 // to actually extend itself into the overscan region.
3411 of.left = mUnrestrictedScreenLeft;
3412 of.top = mUnrestrictedScreenTop;
3413 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3414 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003415 } else {
Dianne Hackborn313440842013-02-19 19:22:59 -08003416 pf.left = df.left = mRestrictedOverscanScreenLeft;
3417 pf.top = df.top = mRestrictedOverscanScreenTop;
3418 pf.right = df.right = mRestrictedOverscanScreenLeft
3419 + mRestrictedOverscanScreenWidth;
3420 pf.bottom = df.bottom = mRestrictedOverscanScreenTop
3421 + mRestrictedOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003422 // We need to tell the app about where the frame inside the overscan
3423 // is, so it can inset its content by that amount -- it didn't ask
3424 // to actually extend itself into the overscan region.
3425 of.left = mUnrestrictedScreenLeft;
3426 of.top = mUnrestrictedScreenTop;
3427 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3428 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003429 }
Craig Mautner69b08182012-09-05 13:07:13 -07003430
John Spurlock46646232013-09-30 22:32:42 -04003431 if ((fl & FLAG_FULLSCREEN) == 0) {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003432 if (win.isVoiceInteraction()) {
3433 cf.left = mVoiceContentLeft;
3434 cf.top = mVoiceContentTop;
3435 cf.right = mVoiceContentRight;
3436 cf.bottom = mVoiceContentBottom;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003437 } else {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003438 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
3439 cf.left = mDockLeft;
3440 cf.top = mDockTop;
3441 cf.right = mDockRight;
3442 cf.bottom = mDockBottom;
3443 } else {
3444 cf.left = mContentLeft;
3445 cf.top = mContentTop;
3446 cf.right = mContentRight;
3447 cf.bottom = mContentBottom;
3448 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003449 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003450 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003451 // Full screen windows are always given a layout that is as if the
3452 // status bar and other transient decors are gone. This is to avoid
3453 // bad states when moving from a window that is not hding the
3454 // status bar to one that is.
3455 cf.left = mRestrictedScreenLeft;
3456 cf.top = mRestrictedScreenTop;
3457 cf.right = mRestrictedScreenLeft + mRestrictedScreenWidth;
3458 cf.bottom = mRestrictedScreenTop + mRestrictedScreenHeight;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003459 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003460 applyStableConstraints(sysUiFl, fl, cf);
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003461 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3462 vf.left = mCurLeft;
3463 vf.top = mCurTop;
3464 vf.right = mCurRight;
3465 vf.bottom = mCurBottom;
3466 } else {
3467 vf.set(cf);
3468 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003469 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003470 } else if ((fl & FLAG_LAYOUT_IN_SCREEN) != 0 || (sysUiFl
3471 & (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
3472 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)) != 0) {
Craig Mautnereda67292013-04-28 13:50:14 -07003473 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3474 "): IN_SCREEN");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003475 // A window that has requested to fill the entire screen just
3476 // gets everything, period.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003477 if (attrs.type == TYPE_STATUS_BAR_PANEL
3478 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003479 pf.left = df.left = of.left = cf.left = hasNavBar
3480 ? mDockLeft : mUnrestrictedScreenLeft;
3481 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
3482 pf.right = df.right = of.right = cf.right = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003483 ? mRestrictedScreenLeft+mRestrictedScreenWidth
Dianne Hackbornc652de82013-02-15 16:32:56 -08003484 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003485 pf.bottom = df.bottom = of.bottom = cf.bottom = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003486 ? mRestrictedScreenTop+mRestrictedScreenHeight
Dianne Hackbornc652de82013-02-15 16:32:56 -08003487 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07003488 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler36412a72011-08-04 09:35:13 -04003489 "Laying out IN_SCREEN status bar window: (%d,%d - %d,%d)",
3490 pf.left, pf.top, pf.right, pf.bottom));
Jim Millere898ac52012-04-06 17:10:57 -07003491 } else if (attrs.type == TYPE_NAVIGATION_BAR
3492 || attrs.type == TYPE_NAVIGATION_BAR_PANEL) {
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003493 // The navigation bar has Real Ultimate Power.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003494 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3495 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3496 pf.right = df.right = of.right = mUnrestrictedScreenLeft
3497 + mUnrestrictedScreenWidth;
3498 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop
3499 + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07003500 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003501 "Laying out navigation bar window: (%d,%d - %d,%d)",
3502 pf.left, pf.top, pf.right, pf.bottom));
Dianne Hackborn01011c32012-02-21 13:54:21 -08003503 } else if ((attrs.type == TYPE_SECURE_SYSTEM_OVERLAY
3504 || attrs.type == TYPE_BOOT_PROGRESS)
Jeff Brownbfcb60a2011-09-08 18:51:14 -07003505 && ((fl & FLAG_FULLSCREEN) != 0)) {
3506 // Fullscreen secure system overlays get what they ask for.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003507 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3508 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3509 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
3510 + mOverscanScreenWidth;
3511 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
3512 + mOverscanScreenHeight;
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07003513 } else if (attrs.type == TYPE_BOOT_PROGRESS
3514 || attrs.type == TYPE_UNIVERSE_BACKGROUND) {
Dianne Hackborn01011c32012-02-21 13:54:21 -08003515 // Boot progress screen always covers entire display.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003516 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3517 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3518 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
3519 + mOverscanScreenWidth;
3520 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
3521 + mOverscanScreenHeight;
John Spurlockef4adae2013-08-26 17:58:58 -04003522 } else if (attrs.type == TYPE_WALLPAPER) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07003523 // The wallpaper also has Real Ultimate Power, but we want to tell
3524 // it about the overscan area.
3525 pf.left = df.left = mOverscanScreenLeft;
3526 pf.top = df.top = mOverscanScreenTop;
3527 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
3528 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
3529 of.left = cf.left = mUnrestrictedScreenLeft;
3530 of.top = cf.top = mUnrestrictedScreenTop;
3531 of.right = cf.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3532 of.bottom = cf.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlock46646232013-09-30 22:32:42 -04003533 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08003534 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3535 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3536 // Asking to layout into the overscan region, so give it that pure
3537 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003538 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3539 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3540 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08003541 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003542 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003543 = mOverscanScreenTop + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003544 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003545 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Craig Mautnerbeac1062014-06-03 14:38:57 -07003546 && (attrs.type == TYPE_STATUS_BAR
3547 || attrs.type == TYPE_TOAST
John Spurlock34e13d92013-08-10 06:52:28 -04003548 || (attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3549 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW))) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003550 // Asking for layout as if the nav bar is hidden, lets the
3551 // application extend into the unrestricted screen area. We
John Spurlock34e13d92013-08-10 06:52:28 -04003552 // only do this for application windows (or toasts) to ensure no window that
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003553 // can be above the nav bar can do this.
3554 // XXX This assumes that an app asking for this will also
3555 // ask for layout in only content. We can't currently figure out
3556 // what the screen would be if only laying out to hide the nav bar.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003557 pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft;
3558 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
3559 pf.right = df.right = of.right = cf.right = mUnrestrictedScreenLeft
3560 + mUnrestrictedScreenWidth;
3561 pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop
3562 + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003563 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003564 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
3565 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
3566 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
3567 + mRestrictedScreenWidth;
3568 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
3569 + mRestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003570 }
Craig Mautner69b08182012-09-05 13:07:13 -07003571
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003572 applyStableConstraints(sysUiFl, fl, cf);
Craig Mautner69b08182012-09-05 13:07:13 -07003573
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003574 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3575 vf.left = mCurLeft;
3576 vf.top = mCurTop;
3577 vf.right = mCurRight;
3578 vf.bottom = mCurBottom;
3579 } else {
3580 vf.set(cf);
3581 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003582 } else if (attached != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07003583 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3584 "): attached to " + attached);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003585 // A child window should be placed inside of the same visible
3586 // frame that its parent had.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003587 setAttachedWindowFrames(win, fl, adjust, attached, false, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003588 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07003589 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3590 "): normal window");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003591 // Otherwise, a normal window must be placed inside the content
3592 // of all screen decorations.
Dianne Hackborna239c842011-06-01 12:28:20 -07003593 if (attrs.type == TYPE_STATUS_BAR_PANEL) {
3594 // Status bar panels are the only windows who can go on top of
3595 // the status bar. They are protected by the STATUS_BAR_SERVICE
3596 // permission, so they have the same privileges as the status
3597 // bar itself.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003598 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
3599 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
3600 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
3601 + mRestrictedScreenWidth;
3602 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
3603 + mRestrictedScreenHeight;
John Spurlock414c1f02013-12-04 13:47:36 -05003604 } else if (attrs.type == TYPE_TOAST || attrs.type == TYPE_SYSTEM_ALERT
3605 || attrs.type == TYPE_VOLUME_OVERLAY) {
3606 // These dialogs are stable to interim decor changes.
John Spurlockbd957402013-10-03 11:38:39 -04003607 pf.left = df.left = of.left = cf.left = mStableLeft;
3608 pf.top = df.top = of.top = cf.top = mStableTop;
3609 pf.right = df.right = of.right = cf.right = mStableRight;
3610 pf.bottom = df.bottom = of.bottom = cf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003611 } else {
Dianne Hackborna239c842011-06-01 12:28:20 -07003612 pf.left = mContentLeft;
3613 pf.top = mContentTop;
3614 pf.right = mContentRight;
3615 pf.bottom = mContentBottom;
Dianne Hackborn20d94742014-05-29 18:35:45 -07003616 if (win.isVoiceInteraction()) {
3617 df.left = of.left = cf.left = mVoiceContentLeft;
3618 df.top = of.top = cf.top = mVoiceContentTop;
3619 df.right = of.right = cf.right = mVoiceContentRight;
3620 df.bottom = of.bottom = cf.bottom = mVoiceContentBottom;
3621 } else if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003622 df.left = of.left = cf.left = mDockLeft;
3623 df.top = of.top = cf.top = mDockTop;
3624 df.right = of.right = cf.right = mDockRight;
3625 df.bottom = of.bottom = cf.bottom = mDockBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07003626 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003627 df.left = of.left = cf.left = mContentLeft;
3628 df.top = of.top = cf.top = mContentTop;
3629 df.right = of.right = cf.right = mContentRight;
3630 df.bottom = of.bottom = cf.bottom = mContentBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07003631 }
3632 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3633 vf.left = mCurLeft;
3634 vf.top = mCurTop;
3635 vf.right = mCurRight;
3636 vf.bottom = mCurBottom;
3637 } else {
3638 vf.set(cf);
3639 }
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003640 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003641 }
3642 }
Craig Mautner69b08182012-09-05 13:07:13 -07003643
Craig Mautnerb816bed2013-07-23 10:26:17 -07003644 // TYPE_SYSTEM_ERROR is above the NavigationBar so it can't be allowed to extend over it.
3645 if ((fl & FLAG_LAYOUT_NO_LIMITS) != 0 && attrs.type != TYPE_SYSTEM_ERROR) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07003646 df.left = df.top = -10000;
3647 df.right = df.bottom = 10000;
3648 if (attrs.type != TYPE_WALLPAPER) {
3649 of.left = of.top = cf.left = cf.top = vf.left = vf.top = -10000;
3650 of.right = of.bottom = cf.right = cf.bottom = vf.right = vf.bottom = 10000;
3651 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003652 }
3653
Craig Mautnereda67292013-04-28 13:50:14 -07003654 if (DEBUG_LAYOUT) Slog.v(TAG, "Compute frame " + attrs.getTitle()
The Android Open Source Project11267662009-03-18 17:39:47 -07003655 + ": sim=#" + Integer.toHexString(sim)
RoboErik8a2cfc32014-05-16 11:19:38 -07003656 + " attach=" + attached + " type=" + attrs.type
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003657 + String.format(" flags=0x%08x", fl)
The Android Open Source Project11267662009-03-18 17:39:47 -07003658 + " pf=" + pf.toShortString() + " df=" + df.toShortString()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003659 + " of=" + of.toShortString()
John Spurlock46646232013-09-30 22:32:42 -04003660 + " cf=" + cf.toShortString() + " vf=" + vf.toShortString()
Adrian Roosfa104232014-06-20 16:10:14 -07003661 + " dcf=" + dcf.toShortString()
3662 + " sf=" + sf.toShortString());
Craig Mautner69b08182012-09-05 13:07:13 -07003663
Adrian Roosfa104232014-06-20 16:10:14 -07003664 win.computeFrameLw(pf, df, of, cf, vf, dcf, sf);
Craig Mautner69b08182012-09-05 13:07:13 -07003665
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003666 // Dock windows carve out the bottom of the screen, so normal windows
3667 // can't appear underneath them.
Craig Mautner8bd206b2012-10-03 10:32:02 -07003668 if (attrs.type == TYPE_INPUT_METHOD && win.isVisibleOrBehindKeyguardLw()
3669 && !win.getGivenInsetsPendingLw()) {
satok1bc0a492012-04-25 22:47:12 +09003670 setLastInputMethodWindowLw(null, null);
3671 offsetInputMethodWindowLw(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003672 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003673 if (attrs.type == TYPE_VOICE_INTERACTION && win.isVisibleOrBehindKeyguardLw()
3674 && !win.getGivenInsetsPendingLw()) {
3675 offsetVoiceInputWindowLw(win);
3676 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003677 }
3678
satok1bc0a492012-04-25 22:47:12 +09003679 private void offsetInputMethodWindowLw(WindowState win) {
3680 int top = win.getContentFrameLw().top;
3681 top += win.getGivenContentInsetsLw().top;
3682 if (mContentBottom > top) {
3683 mContentBottom = top;
3684 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003685 if (mVoiceContentBottom > top) {
3686 mVoiceContentBottom = top;
3687 }
satok1bc0a492012-04-25 22:47:12 +09003688 top = win.getVisibleFrameLw().top;
3689 top += win.getGivenVisibleInsetsLw().top;
3690 if (mCurBottom > top) {
3691 mCurBottom = top;
3692 }
Craig Mautnereda67292013-04-28 13:50:14 -07003693 if (DEBUG_LAYOUT) Slog.v(TAG, "Input method: mDockBottom="
satok1bc0a492012-04-25 22:47:12 +09003694 + mDockBottom + " mContentBottom="
3695 + mContentBottom + " mCurBottom=" + mCurBottom);
3696 }
3697
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003698 private void offsetVoiceInputWindowLw(WindowState win) {
3699 final int gravity = win.getAttrs().gravity;
3700 switch (gravity&((Gravity.AXIS_PULL_BEFORE|Gravity.AXIS_PULL_AFTER)
3701 << Gravity.AXIS_X_SHIFT)) {
3702 case Gravity.AXIS_PULL_BEFORE<<Gravity.AXIS_X_SHIFT: {
3703 int right = win.getContentFrameLw().right - win.getGivenContentInsetsLw().right;
3704 if (mVoiceContentLeft < right) {
3705 mVoiceContentLeft = right;
3706 }
3707 } break;
3708 case Gravity.AXIS_PULL_AFTER<<Gravity.AXIS_X_SHIFT: {
3709 int left = win.getContentFrameLw().left - win.getGivenContentInsetsLw().left;
3710 if (mVoiceContentRight < left) {
3711 mVoiceContentRight = left;
3712 }
3713 } break;
3714 }
3715 switch (gravity&((Gravity.AXIS_PULL_BEFORE|Gravity.AXIS_PULL_AFTER)
3716 << Gravity.AXIS_Y_SHIFT)) {
3717 case Gravity.AXIS_PULL_BEFORE<<Gravity.AXIS_Y_SHIFT: {
3718 int bottom = win.getContentFrameLw().bottom - win.getGivenContentInsetsLw().bottom;
3719 if (mVoiceContentTop < bottom) {
3720 mVoiceContentTop = bottom;
3721 }
3722 } break;
3723 case Gravity.AXIS_PULL_AFTER<<Gravity.AXIS_Y_SHIFT: {
3724 int top = win.getContentFrameLw().top - win.getGivenContentInsetsLw().top;
3725 if (mVoiceContentBottom < top) {
3726 mVoiceContentBottom = top;
3727 }
3728 } break;
3729 }
3730 }
3731
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003732 /** {@inheritDoc} */
Craig Mautner61ac6bb2012-02-02 17:29:33 -08003733 @Override
3734 public void finishLayoutLw() {
3735 return;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003736 }
3737
3738 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003739 @Override
Craig Mautner39834192012-09-02 07:47:24 -07003740 public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) {
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003741 mTopFullscreenOpaqueWindowState = null;
Craig Mautner2bc789b2014-03-19 19:48:38 -07003742 mAppsToBeHidden.clear();
Jorim Jaggic13fcac2014-09-11 17:36:57 +02003743 mAppsThatDismissKeyguard.clear();
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003744 mForceStatusBar = false;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003745 mForceStatusBarFromKeyguard = false;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08003746 mForcingShowNavBar = false;
3747 mForcingShowNavBarLayer = -1;
RoboErik8a2cfc32014-05-16 11:19:38 -07003748
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003749 mHideLockScreen = false;
3750 mAllowLockscreenWhenOn = false;
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003751 mDismissKeyguard = DISMISS_KEYGUARD_NONE;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003752 mShowingLockscreen = false;
3753 mShowingDream = false;
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003754 mWinShowWhenLocked = null;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003755 }
3756
3757 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003758 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003759 public void applyPostLayoutPolicyLw(WindowState win, WindowManager.LayoutParams attrs) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07003760 if (DEBUG_LAYOUT) Slog.i(TAG, "Win " + win + ": isVisibleOrBehindKeyguardLw="
3761 + win.isVisibleOrBehindKeyguardLw());
John Spurlockc6d1c602014-01-17 15:22:06 -05003762 final int fl = PolicyControl.getWindowFlags(win, attrs);
John Spurlock414c1f02013-12-04 13:47:36 -05003763 if (mTopFullscreenOpaqueWindowState == null
3764 && win.isVisibleLw() && attrs.type == TYPE_INPUT_METHOD) {
3765 mForcingShowNavBar = true;
3766 mForcingShowNavBarLayer = win.getSurfaceLayer();
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08003767 }
Jorim Jaggiafd4a552014-04-08 15:13:05 +02003768 if (attrs.type == TYPE_STATUS_BAR && (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Jorim Jaggiafd4a552014-04-08 15:13:05 +02003769 mForceStatusBarFromKeyguard = true;
3770 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003771 if (mTopFullscreenOpaqueWindowState == null &&
Dianne Hackborn01b02a72012-01-12 14:05:03 -08003772 win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()) {
John Spurlockc6d1c602014-01-17 15:22:06 -05003773 if ((fl & FLAG_FORCE_NOT_FULLSCREEN) != 0) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003774 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003775 mForceStatusBarFromKeyguard = true;
3776 } else {
3777 mForceStatusBar = true;
3778 }
3779 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003780 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003781 mShowingLockscreen = true;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07003782 }
Craig Mautnerab55e522014-03-03 13:26:03 -08003783 boolean appWindow = attrs.type >= FIRST_APPLICATION_WINDOW
Craig Mautner7d7808f2014-09-11 18:02:38 -07003784 && attrs.type < FIRST_SYSTEM_WINDOW;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003785 if (attrs.type == TYPE_DREAM) {
Jeff Brownc8018eb2012-10-29 21:33:27 -07003786 // If the lockscreen was showing when the dream started then wait
3787 // for the dream to draw before hiding the lockscreen.
3788 if (!mDreamingLockscreen
3789 || (win.isVisibleLw() && win.hasDrawnLw())) {
3790 mShowingDream = true;
Craig Mautnerab55e522014-03-03 13:26:03 -08003791 appWindow = true;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003792 }
3793 }
Craig Mautnerab55e522014-03-03 13:26:03 -08003794
Craig Mautner00156ec2014-03-06 22:29:02 -08003795 final boolean showWhenLocked = (fl & FLAG_SHOW_WHEN_LOCKED) != 0;
Craig Mautner74ee9382014-04-01 15:20:16 -07003796 final boolean dismissKeyguard = (fl & FLAG_DISMISS_KEYGUARD) != 0;
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003797 final boolean secureKeyguard = isKeyguardSecure();
Craig Mautnerab55e522014-03-03 13:26:03 -08003798 if (appWindow) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02003799 final IApplicationToken appToken = win.getAppToken();
3800 if (showWhenLocked) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003801 // Remove any previous windows with the same appToken.
Jorim Jaggic13fcac2014-09-11 17:36:57 +02003802 mAppsToBeHidden.remove(appToken);
3803 mAppsThatDismissKeyguard.remove(appToken);
3804 if (mAppsToBeHidden.isEmpty() && isKeyguardSecureIncludingHidden()) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003805 mWinShowWhenLocked = win;
3806 mHideLockScreen = true;
3807 mForceStatusBarFromKeyguard = false;
3808 }
Jorim Jaggic13fcac2014-09-11 17:36:57 +02003809 } else if (dismissKeyguard) {
3810 if (secureKeyguard) {
3811 mAppsToBeHidden.add(appToken);
3812 } else {
3813 mAppsToBeHidden.remove(appToken);
3814 }
3815 mAppsThatDismissKeyguard.add(appToken);
Craig Mautner2bc789b2014-03-19 19:48:38 -07003816 } else {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02003817 mAppsToBeHidden.add(appToken);
Craig Mautner2bc789b2014-03-19 19:48:38 -07003818 }
Craig Mautnerab55e522014-03-03 13:26:03 -08003819 if (attrs.x == 0 && attrs.y == 0
3820 && attrs.width == WindowManager.LayoutParams.MATCH_PARENT
3821 && attrs.height == WindowManager.LayoutParams.MATCH_PARENT) {
3822 if (DEBUG_LAYOUT) Slog.v(TAG, "Fullscreen window: " + win);
3823 mTopFullscreenOpaqueWindowState = win;
Jorim Jaggic13fcac2014-09-11 17:36:57 +02003824 if (!mAppsThatDismissKeyguard.isEmpty() &&
3825 mDismissKeyguard == DISMISS_KEYGUARD_NONE) {
3826 if (DEBUG_LAYOUT) Slog.v(TAG,
3827 "Setting mDismissKeyguard true by win " + win);
3828 mDismissKeyguard = mWinDismissingKeyguard == win ?
3829 DISMISS_KEYGUARD_CONTINUE : DISMISS_KEYGUARD_START;
3830 mWinDismissingKeyguard = win;
3831 mForceStatusBarFromKeyguard = mShowingLockscreen && secureKeyguard;
3832 } else if (mAppsToBeHidden.isEmpty() && showWhenLocked) {
3833 if (DEBUG_LAYOUT) Slog.v(TAG,
3834 "Setting mHideLockScreen to true by win " + win);
3835 mHideLockScreen = true;
3836 mForceStatusBarFromKeyguard = false;
Craig Mautnerab55e522014-03-03 13:26:03 -08003837 }
Craig Mautner00156ec2014-03-06 22:29:02 -08003838 if ((fl & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) {
Craig Mautnerab55e522014-03-03 13:26:03 -08003839 mAllowLockscreenWhenOn = true;
3840 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003841 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003842
3843 if (mWinShowWhenLocked != null &&
3844 mWinShowWhenLocked.getAppToken() != win.getAppToken()) {
3845 win.hideLw(false);
3846 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003847 }
3848 }
3849 }
3850
3851 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003852 @Override
Craig Mautner39834192012-09-02 07:47:24 -07003853 public int finishPostLayoutPolicyLw() {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003854 if (mWinShowWhenLocked != null &&
3855 mWinShowWhenLocked != mTopFullscreenOpaqueWindowState) {
3856 // A dialog is dismissing the keyguard. Put the wallpaper behind it and hide the
3857 // fullscreen window.
3858 // TODO: Make sure FLAG_SHOW_WALLPAPER is restored when dialog is dismissed. Or not.
3859 mWinShowWhenLocked.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
3860 mTopFullscreenOpaqueWindowState.hideLw(false);
3861 mTopFullscreenOpaqueWindowState = mWinShowWhenLocked;
3862 }
3863
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003864 int changes = 0;
Joe Onorato93056472010-09-10 10:30:46 -04003865 boolean topIsFullscreen = false;
Daniel Sandlere02d8082010-10-08 15:13:22 -04003866
3867 final WindowManager.LayoutParams lp = (mTopFullscreenOpaqueWindowState != null)
3868 ? mTopFullscreenOpaqueWindowState.getAttrs()
3869 : null;
3870
Jeff Brownc8018eb2012-10-29 21:33:27 -07003871 // If we are not currently showing a dream then remember the current
3872 // lockscreen state. We will use this to determine whether the dream
3873 // started while the lockscreen was showing and remember this state
3874 // while the dream is showing.
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003875 if (!mShowingDream) {
3876 mDreamingLockscreen = mShowingLockscreen;
3877 }
3878
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003879 if (mStatusBar != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07003880 if (DEBUG_LAYOUT) Slog.i(TAG, "force=" + mForceStatusBar
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003881 + " forcefkg=" + mForceStatusBarFromKeyguard
Dianne Hackbornd70bc2f2009-10-06 23:25:51 -07003882 + " top=" + mTopFullscreenOpaqueWindowState);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003883 if (mForceStatusBar || mForceStatusBarFromKeyguard) {
Craig Mautnereda67292013-04-28 13:50:14 -07003884 if (DEBUG_LAYOUT) Slog.v(TAG, "Showing status bar: forced");
John Spurlock27735a42013-08-14 17:57:38 -04003885 if (mStatusBarController.setBarShowingLw(true)) {
3886 changes |= FINISH_LAYOUT_REDO_LAYOUT;
3887 }
Craig Mautner81defc72013-10-29 11:10:42 -07003888 // Maintain fullscreen layout until incoming animation is complete.
3889 topIsFullscreen = mTopIsFullscreen && mStatusBar.isAnimatingLw();
John Spurlockf92b6162013-11-11 15:01:16 -05003890 // Transient status bar on the lockscreen is not allowed
3891 if (mForceStatusBarFromKeyguard && mStatusBarController.isTransientShowing()) {
3892 mStatusBarController.updateVisibilityLw(false /*transientAllowed*/,
3893 mLastSystemUiFlags, mLastSystemUiFlags);
3894 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003895 } else if (mTopFullscreenOpaqueWindowState != null) {
John Spurlockc6d1c602014-01-17 15:22:06 -05003896 final int fl = PolicyControl.getWindowFlags(null, lp);
Joe Onorato93056472010-09-10 10:30:46 -04003897 if (localLOGV) {
Craig Mautnereda67292013-04-28 13:50:14 -07003898 Slog.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw()
Joe Onorato93056472010-09-10 10:30:46 -04003899 + " shown frame: " + mTopFullscreenOpaqueWindowState.getShownFrameLw());
Craig Mautnereda67292013-04-28 13:50:14 -07003900 Slog.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs()
John Spurlockc6d1c602014-01-17 15:22:06 -05003901 + " lp.flags=0x" + Integer.toHexString(fl));
Joe Onorato93056472010-09-10 10:30:46 -04003902 }
John Spurlockc6d1c602014-01-17 15:22:06 -05003903 topIsFullscreen = (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003904 || (mLastSystemUiFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
Joe Onorato93056472010-09-10 10:30:46 -04003905 // The subtle difference between the window for mTopFullscreenOpaqueWindowState
3906 // and mTopIsFullscreen is that that mTopIsFullscreen is set only if the window
3907 // has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the
3908 // case though.
John Spurlock27735a42013-08-14 17:57:38 -04003909 if (mStatusBarController.isTransientShowing()) {
3910 if (mStatusBarController.setBarShowingLw(true)) {
John Spurlock32beb2c2013-03-11 10:16:47 -04003911 changes |= FINISH_LAYOUT_REDO_LAYOUT;
3912 }
3913 } else if (topIsFullscreen) {
Craig Mautnereda67292013-04-28 13:50:14 -07003914 if (DEBUG_LAYOUT) Slog.v(TAG, "** HIDING status bar");
John Spurlock27735a42013-08-14 17:57:38 -04003915 if (mStatusBarController.setBarShowingLw(false)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003916 changes |= FINISH_LAYOUT_REDO_LAYOUT;
Craig Mautnereda67292013-04-28 13:50:14 -07003917 } else {
Craig Mautnerc5a6e442013-06-05 17:22:35 -07003918 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar already hiding");
Daniel Sandler40427442010-07-16 11:44:52 -04003919 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003920 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07003921 if (DEBUG_LAYOUT) Slog.v(TAG, "** SHOWING status bar: top is not fullscreen");
John Spurlock27735a42013-08-14 17:57:38 -04003922 if (mStatusBarController.setBarShowingLw(true)) {
3923 changes |= FINISH_LAYOUT_REDO_LAYOUT;
3924 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003925 }
3926 }
3927 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04003928
Craig Mautner81defc72013-10-29 11:10:42 -07003929 if (mTopIsFullscreen != topIsFullscreen) {
3930 if (!topIsFullscreen) {
3931 // Force another layout when status bar becomes fully shown.
3932 changes |= FINISH_LAYOUT_REDO_LAYOUT;
3933 }
3934 mTopIsFullscreen = topIsFullscreen;
3935 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04003936
Craig Mautner39834192012-09-02 07:47:24 -07003937 // Hide the key guard if a visible window explicitly specifies that it wants to be
3938 // displayed when the screen is locked.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01003939 if (mKeyguardDelegate != null && mStatusBar != null) {
3940 if (localLOGV) Slog.v(TAG, "finishPostLayoutPolicyLw: mHideKeyguard="
3941 + mHideLockScreen);
3942 if (mDismissKeyguard != DISMISS_KEYGUARD_NONE && !isKeyguardSecure()) {
3943 mKeyguardHidden = true;
3944 if (processKeyguardSetHiddenResultLw(mKeyguardDelegate.setOccluded(true))) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003945 changes |= FINISH_LAYOUT_REDO_LAYOUT
3946 | FINISH_LAYOUT_REDO_CONFIG
3947 | FINISH_LAYOUT_REDO_WALLPAPER;
3948 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01003949 if (mKeyguardDelegate.isShowing()) {
3950 mHandler.post(new Runnable() {
3951 @Override
3952 public void run() {
3953 mKeyguardDelegate.keyguardDone(false, false);
3954 }
3955 });
3956 }
3957 } else if (mHideLockScreen) {
3958 mKeyguardHidden = true;
3959 if (processKeyguardSetHiddenResultLw(mKeyguardDelegate.setOccluded(true))) {
3960 changes |= FINISH_LAYOUT_REDO_LAYOUT
3961 | FINISH_LAYOUT_REDO_CONFIG
3962 | FINISH_LAYOUT_REDO_WALLPAPER;
3963 }
3964 } else if (mDismissKeyguard != DISMISS_KEYGUARD_NONE) {
3965 // This is the case of keyguard isSecure() and not mHideLockScreen.
3966 if (mDismissKeyguard == DISMISS_KEYGUARD_START) {
3967 // Only launch the next keyguard unlock window once per window.
3968 mKeyguardHidden = false;
3969 if (processKeyguardSetHiddenResultLw(mKeyguardDelegate.setOccluded(false))) {
3970 changes |= FINISH_LAYOUT_REDO_LAYOUT
3971 | FINISH_LAYOUT_REDO_CONFIG
3972 | FINISH_LAYOUT_REDO_WALLPAPER;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003973 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01003974 mHandler.post(new Runnable() {
3975 @Override
3976 public void run() {
3977 mKeyguardDelegate.dismiss();
3978 }
3979 });
3980 }
3981 } else {
3982 mWinDismissingKeyguard = null;
3983 mKeyguardHidden = false;
3984 if (processKeyguardSetHiddenResultLw(mKeyguardDelegate.setOccluded(false))) {
3985 changes |= FINISH_LAYOUT_REDO_LAYOUT
3986 | FINISH_LAYOUT_REDO_CONFIG
3987 | FINISH_LAYOUT_REDO_WALLPAPER;
3988 }
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -07003989 }
3990 }
Joe Onorato664644d2011-01-23 17:53:23 -08003991
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003992 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003993 // If the navigation bar has been hidden or shown, we need to do another
3994 // layout pass to update that window.
3995 changes |= FINISH_LAYOUT_REDO_LAYOUT;
3996 }
Joe Onorato664644d2011-01-23 17:53:23 -08003997
Mike Lockwood28569302010-01-28 11:54:40 -05003998 // update since mAllowLockscreenWhenOn might have changed
3999 updateLockScreenTimeout();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004000 return changes;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004001 }
4002
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004003 /**
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004004 * Processes the result code of {@link IKeyguardService#setOccluded}. This is needed because we
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004005 * immediately need to put the wallpaper directly behind the Keyguard when a window with flag
4006 * {@link android.view.WindowManager.LayoutParams#FLAG_SHOW_WHEN_LOCKED} gets dismissed. If we
4007 * would wait for Keyguard to change the flags, that would be running asynchronously and thus be
4008 * too late so the user might see the window behind.
4009 *
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004010 * @param setHiddenResult The result code from {@link IKeyguardService#setOccluded}.
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004011 * @return Whether the flags have changed and we have to redo the layout.
4012 */
4013 private boolean processKeyguardSetHiddenResultLw(int setHiddenResult) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004014 if (setHiddenResult
4015 == IKeyguardServiceConstants.KEYGUARD_SERVICE_SET_OCCLUDED_RESULT_SET_FLAGS) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004016 mStatusBar.getAttrs().privateFlags |= PRIVATE_FLAG_KEYGUARD;
4017 mStatusBar.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
4018 return true;
4019 } else if (setHiddenResult
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004020 == IKeyguardServiceConstants.KEYGUARD_SERVICE_SET_OCCLUDED_RESULT_UNSET_FLAGS) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004021 mStatusBar.getAttrs().privateFlags &= ~PRIVATE_FLAG_KEYGUARD;
4022 mStatusBar.getAttrs().flags &= ~FLAG_SHOW_WALLPAPER;
4023 return true;
4024 } else {
4025 return false;
4026 }
4027 }
4028
4029 private boolean isStatusBarKeyguard() {
4030 return mStatusBar != null
4031 && (mStatusBar.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
4032 }
4033
Jose Lima9546b202014-07-02 17:21:51 -07004034 @Override
Dianne Hackborn08743722009-12-21 12:16:51 -08004035 public boolean allowAppAnimationsLw() {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004036 if (isStatusBarKeyguard() || mShowingDream) {
Craig Mautner28816302013-10-10 20:31:00 -07004037 // If keyguard or dreams is currently visible, no reason to animate behind it.
Dianne Hackborn08743722009-12-21 12:16:51 -08004038 return false;
4039 }
Dianne Hackborn08743722009-12-21 12:16:51 -08004040 return true;
4041 }
4042
Jose Lima9546b202014-07-02 17:21:51 -07004043 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07004044 public int focusChangedLw(WindowState lastFocus, WindowState newFocus) {
Joe Onorato664644d2011-01-23 17:53:23 -08004045 mFocusedWindow = newFocus;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004046 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004047 // If the navigation bar has been hidden or shown, we need to do another
4048 // layout pass to update that window.
4049 return FINISH_LAYOUT_REDO_LAYOUT;
4050 }
4051 return 0;
Joe Onorato664644d2011-01-23 17:53:23 -08004052 }
4053
Dianne Hackborn0ecadf72009-03-31 18:00:37 -07004054 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07004055 @Override
Jeff Brown46b9ac02010-04-22 18:58:52 -07004056 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
4057 // lid changed state
Jeff Brownc458ce92012-04-30 14:58:40 -07004058 final int newLidState = lidOpen ? LID_OPEN : LID_CLOSED;
4059 if (newLidState == mLidState) {
4060 return;
4061 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004062
Jeff Brownc458ce92012-04-30 14:58:40 -07004063 mLidState = newLidState;
4064 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07004065 updateRotation(true);
Jeff Brownc458ce92012-04-30 14:58:40 -07004066
4067 if (lidOpen) {
Jim Millere51cf7ae2013-06-25 18:31:56 -07004068 mPowerManager.wakeUp(SystemClock.uptimeMillis());
Jeff Brownc458ce92012-04-30 14:58:40 -07004069 } else if (!mLidControlsSleep) {
Jeff Brown96307042012-07-27 15:51:34 -07004070 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
Jeff Brown46b9ac02010-04-22 18:58:52 -07004071 }
4072 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004073
Michael Wright3818c922014-09-02 13:59:07 -07004074 @Override
4075 public void notifyCameraLensCoverSwitchChanged(long whenNanos, boolean lensCovered) {
4076 int lensCoverState = lensCovered ? CAMERA_LENS_COVERED : CAMERA_LENS_UNCOVERED;
4077 if (mCameraLensCoverState == lensCoverState) {
4078 return;
4079 }
4080 if (mCameraLensCoverState == CAMERA_LENS_COVERED &&
4081 lensCoverState == CAMERA_LENS_UNCOVERED) {
4082 Intent intent;
4083 final boolean keyguardActive = mKeyguardDelegate == null ? false :
4084 mKeyguardDelegate.isShowing();
4085 if (keyguardActive) {
4086 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE);
4087 } else {
4088 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
4089 }
Michael Wright61a43ee2014-09-24 14:36:43 -07004090 mPowerManager.wakeUp(whenNanos / 1000000);
Michael Wright3818c922014-09-02 13:59:07 -07004091 mContext.startActivityAsUser(intent, UserHandle.CURRENT_OR_SELF);
4092 }
4093 mCameraLensCoverState = lensCoverState;
4094 }
4095
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004096 void setHdmiPlugged(boolean plugged) {
4097 if (mHdmiPlugged != plugged) {
4098 mHdmiPlugged = plugged;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004099 updateRotation(true, true);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004100 Intent intent = new Intent(ACTION_HDMI_PLUGGED);
Joe Onoratodc100302011-01-11 17:07:41 -08004101 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004102 intent.putExtra(EXTRA_HDMI_PLUGGED_STATE, plugged);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07004103 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004104 }
4105 }
4106
Joe Onoratoea495d42011-04-06 11:41:11 -07004107 void initializeHdmiState() {
Joe Onorato7ba631f2011-05-04 15:28:00 -07004108 boolean plugged = false;
Joe Onoratoea495d42011-04-06 11:41:11 -07004109 // watch for HDMI plug messages if the hdmi switch exists
4110 if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) {
4111 mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi");
4112
Joe Onoratoea495d42011-04-06 11:41:11 -07004113 final String filename = "/sys/class/switch/hdmi/state";
4114 FileReader reader = null;
4115 try {
4116 reader = new FileReader(filename);
4117 char[] buf = new char[15];
4118 int n = reader.read(buf);
4119 if (n > 1) {
4120 plugged = 0 != Integer.parseInt(new String(buf, 0, n-1));
4121 }
4122 } catch (IOException ex) {
4123 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
4124 } catch (NumberFormatException ex) {
4125 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
4126 } finally {
4127 if (reader != null) {
4128 try {
4129 reader.close();
4130 } catch (IOException ex) {
4131 }
Joe Onoratodc100302011-01-11 17:07:41 -08004132 }
4133 }
4134 }
Joe Onorato7ba631f2011-05-04 15:28:00 -07004135 // This dance forces the code in setHdmiPlugged to run.
4136 // Always do this so the sticky intent is stuck (to false) if there is no hdmi.
4137 mHdmiPlugged = !plugged;
4138 setHdmiPlugged(!mHdmiPlugged);
Joe Onoratodc100302011-01-11 17:07:41 -08004139 }
4140
Dianne Hackbornc0e3f242011-08-19 14:19:10 -07004141 final Object mScreenshotLock = new Object();
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004142 ServiceConnection mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004143
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004144 final Runnable mScreenshotTimeout = new Runnable() {
4145 @Override public void run() {
4146 synchronized (mScreenshotLock) {
4147 if (mScreenshotConnection != null) {
4148 mContext.unbindService(mScreenshotConnection);
4149 mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004150 }
Winson Chung9112ec32011-06-27 13:15:32 -07004151 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004152 }
4153 };
4154
4155 // Assume this is called from the Handler thread.
4156 private void takeScreenshot() {
4157 synchronized (mScreenshotLock) {
4158 if (mScreenshotConnection != null) {
4159 return;
4160 }
4161 ComponentName cn = new ComponentName("com.android.systemui",
4162 "com.android.systemui.screenshot.TakeScreenshotService");
4163 Intent intent = new Intent();
4164 intent.setComponent(cn);
4165 ServiceConnection conn = new ServiceConnection() {
4166 @Override
4167 public void onServiceConnected(ComponentName name, IBinder service) {
4168 synchronized (mScreenshotLock) {
4169 if (mScreenshotConnection != this) {
4170 return;
4171 }
4172 Messenger messenger = new Messenger(service);
4173 Message msg = Message.obtain(null, 1);
4174 final ServiceConnection myConn = this;
4175 Handler h = new Handler(mHandler.getLooper()) {
4176 @Override
4177 public void handleMessage(Message msg) {
4178 synchronized (mScreenshotLock) {
4179 if (mScreenshotConnection == myConn) {
4180 mContext.unbindService(mScreenshotConnection);
4181 mScreenshotConnection = null;
4182 mHandler.removeCallbacks(mScreenshotTimeout);
4183 }
4184 }
4185 }
4186 };
4187 msg.replyTo = new Messenger(h);
Winson Chunga63bb842011-10-17 10:26:28 -07004188 msg.arg1 = msg.arg2 = 0;
4189 if (mStatusBar != null && mStatusBar.isVisibleLw())
4190 msg.arg1 = 1;
4191 if (mNavigationBar != null && mNavigationBar.isVisibleLw())
4192 msg.arg2 = 1;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004193 try {
4194 messenger.send(msg);
4195 } catch (RemoteException e) {
4196 }
4197 }
4198 }
4199 @Override
4200 public void onServiceDisconnected(ComponentName name) {}
4201 };
Amith Yamasani27b89e62013-01-16 12:30:11 -08004202 if (mContext.bindServiceAsUser(
4203 intent, conn, Context.BIND_AUTO_CREATE, UserHandle.CURRENT)) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004204 mScreenshotConnection = conn;
4205 mHandler.postDelayed(mScreenshotTimeout, 10000);
4206 }
4207 }
Winson Chung9112ec32011-06-27 13:15:32 -07004208 }
4209
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004210 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004211 @Override
Jeff Brown037c33e2014-04-09 00:31:55 -07004212 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) {
Jeff Brown96307042012-07-27 15:51:34 -07004213 if (!mSystemBooted) {
4214 // If we have not yet booted, don't let key events do anything.
4215 return 0;
4216 }
4217
Jeff Brown037c33e2014-04-09 00:31:55 -07004218 final boolean interactive = (policyFlags & FLAG_INTERACTIVE) != 0;
Jeff Brown1f245102010-11-18 20:53:46 -08004219 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
4220 final boolean canceled = event.isCanceled();
4221 final int keyCode = event.getKeyCode();
Jeff Browne20c9e02010-10-11 14:20:19 -07004222
Jeff Brown3122e442010-10-11 23:32:49 -07004223 final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0;
Jeff Brown3122e442010-10-11 23:32:49 -07004224
Mike Lockwoodc72b15f2009-11-28 20:58:22 -05004225 // If screen is off then we treat the case where the keyguard is open but hidden
4226 // the same as if it were open and in front.
4227 // This will prevent any keys other than the power button from waking the screen
4228 // when the keyguard is hidden by another activity.
Jim Miller5ecd8112013-01-09 18:50:26 -08004229 final boolean keyguardActive = (mKeyguardDelegate == null ? false :
Jeff Brown037c33e2014-04-09 00:31:55 -07004230 (interactive ?
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004231 mKeyguardDelegate.isShowingAndNotOccluded() :
Jim Miller5ecd8112013-01-09 18:50:26 -08004232 mKeyguardDelegate.isShowing()));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004233
Jeff Brown40013652012-05-16 21:22:36 -07004234 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004235 Log.d(TAG, "interceptKeyTq keycode=" + keyCode
Jeff Brown037c33e2014-04-09 00:31:55 -07004236 + " interactive=" + interactive + " keyguardActive=" + keyguardActive
Jeff Brown26875502014-01-30 21:47:47 -08004237 + " policyFlags=" + Integer.toHexString(policyFlags));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004238 }
4239
Jeff Brown037c33e2014-04-09 00:31:55 -07004240 // Basic policy based on interactive state.
Jeff Brown4d396052010-10-29 21:50:21 -07004241 int result;
Michael Wright337d9d22014-04-22 15:03:48 -07004242 boolean isWakeKey = (policyFlags & WindowManagerPolicy.FLAG_WAKE) != 0
4243 || event.isWakeKey();
Michael Wrightfc01f042014-09-08 14:12:24 -07004244 if (interactive || (isInjected && !isWakeKey)) {
RoboErikde9ba392014-09-26 12:51:01 -07004245 // When the device is interactive or the key is injected pass the
4246 // key to the application.
Jeff Brown4d396052010-10-29 21:50:21 -07004247 result = ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07004248 isWakeKey = false;
Michael Wrightfc01f042014-09-08 14:12:24 -07004249 } else if (!interactive && shouldDispatchInputWhenNonInteractive()) {
4250 // If we're currently dozing with the screen on and the keyguard showing, pass the key
4251 // to the application but preserve its wake key status to make sure we still move
4252 // from dozing to fully interactive if we would normally go from off to fully
4253 // interactive.
4254 result = ACTION_PASS_TO_USER;
Jeff Brown4d396052010-10-29 21:50:21 -07004255 } else {
4256 // When the screen is off and the key is not injected, determine whether
4257 // to wake the device but don't pass the key to the application.
4258 result = 0;
Jeff Brown26875502014-01-30 21:47:47 -08004259 if (isWakeKey && (!down || !isWakeKeyWhenScreenOff(keyCode))) {
4260 isWakeKey = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004261 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004262 }
4263
Justin Kohd378ad72013-04-01 12:18:26 -07004264 // If the key would be handled globally, just return the result, don't worry about special
4265 // key processing.
4266 if (mGlobalKeyManager.shouldHandleGlobalKey(keyCode, event)) {
Michael Wright85b1af62014-06-04 14:51:58 -07004267 if (isWakeKey) {
4268 mPowerManager.wakeUp(event.getEventTime());
4269 }
Justin Kohd378ad72013-04-01 12:18:26 -07004270 return result;
4271 }
4272
Jeff Brownbae8e772014-06-12 19:59:45 -07004273 boolean useHapticFeedback = down
4274 && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0
4275 && event.getRepeatCount() == 0;
4276
Jeff Brown4d396052010-10-29 21:50:21 -07004277 // Handle special keys.
4278 switch (keyCode) {
4279 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jeff Brownb0418da2010-11-01 15:24:01 -07004280 case KeyEvent.KEYCODE_VOLUME_UP:
4281 case KeyEvent.KEYCODE_VOLUME_MUTE: {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004282 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
4283 if (down) {
Jeff Brown037c33e2014-04-09 00:31:55 -07004284 if (interactive && !mVolumeDownKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004285 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
4286 mVolumeDownKeyTriggered = true;
4287 mVolumeDownKeyTime = event.getDownTime();
4288 mVolumeDownKeyConsumedByScreenshotChord = false;
4289 cancelPendingPowerKeyAction();
4290 interceptScreenshotChord();
4291 }
4292 } else {
4293 mVolumeDownKeyTriggered = false;
4294 cancelPendingScreenshotChordAction();
4295 }
4296 } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
4297 if (down) {
Jeff Brown037c33e2014-04-09 00:31:55 -07004298 if (interactive && !mVolumeUpKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004299 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
4300 mVolumeUpKeyTriggered = true;
4301 cancelPendingPowerKeyAction();
4302 cancelPendingScreenshotChordAction();
4303 }
4304 } else {
4305 mVolumeUpKeyTriggered = false;
4306 cancelPendingScreenshotChordAction();
4307 }
4308 }
Jeff Brown4d396052010-10-29 21:50:21 -07004309 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004310 TelecomManager telecomManager = getTelecommService();
4311 if (telecomManager != null) {
4312 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07004313 // If an incoming call is ringing, either VOLUME key means
4314 // "silence ringer". We handle these keys here, rather than
4315 // in the InCallScreen, to make sure we'll respond to them
4316 // even if the InCallScreen hasn't come to the foreground yet.
4317 // Look for the DOWN event here, to agree with the "fallback"
4318 // behavior in the InCallScreen.
4319 Log.i(TAG, "interceptKeyBeforeQueueing:"
4320 + " VOLUME key-down while ringing: Silence ringer!");
Jeff Brown4d396052010-10-29 21:50:21 -07004321
Santos Cordon6848f722014-05-21 15:22:12 -07004322 // Silence the ringer. (It's safe to call this
4323 // even if the ringer has already been silenced.)
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004324 telecomManager.silenceRinger();
Jeff Brown4d396052010-10-29 21:50:21 -07004325
Santos Cordon6848f722014-05-21 15:22:12 -07004326 // And *don't* pass this key thru to the current activity
4327 // (which is probably the InCallScreen.)
4328 result &= ~ACTION_PASS_TO_USER;
4329 break;
4330 }
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004331 if (telecomManager.isInCall()
Santos Cordon6848f722014-05-21 15:22:12 -07004332 && (result & ACTION_PASS_TO_USER) == 0) {
4333 // If we are in call but we decided not to pass the key to
RoboErik430fc482014-06-12 15:49:20 -07004334 // the application, just pass it to the session service.
4335
4336 MediaSessionLegacyHelper.getHelper(mContext)
RoboErik3c45c292014-07-08 16:47:31 -07004337 .sendVolumeKeyEvent(event, false);
Santos Cordon6848f722014-05-21 15:22:12 -07004338 break;
Jeff Brown4d396052010-10-29 21:50:21 -07004339 }
4340 }
4341
RoboErik430fc482014-06-12 15:49:20 -07004342 if ((result & ACTION_PASS_TO_USER) == 0) {
4343 // If we aren't passing to the user and no one else
4344 // handled it send it to the session manager to figure
4345 // out.
4346 MediaSessionLegacyHelper.getHelper(mContext)
RoboErik3c45c292014-07-08 16:47:31 -07004347 .sendVolumeKeyEvent(event, true);
Jeff Brown4d396052010-10-29 21:50:21 -07004348 break;
4349 }
4350 }
4351 break;
4352 }
4353
4354 case KeyEvent.KEYCODE_ENDCALL: {
4355 result &= ~ACTION_PASS_TO_USER;
4356 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004357 TelecomManager telecomManager = getTelecommService();
Jeff Brown4d396052010-10-29 21:50:21 -07004358 boolean hungUp = false;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004359 if (telecomManager != null) {
4360 hungUp = telecomManager.endCall();
Jeff Brown4d396052010-10-29 21:50:21 -07004361 }
Jeff Brown037c33e2014-04-09 00:31:55 -07004362 interceptPowerKeyDown(!interactive || hungUp);
Jeff Brown4d396052010-10-29 21:50:21 -07004363 } else {
4364 if (interceptPowerKeyUp(canceled)) {
4365 if ((mEndcallBehavior
4366 & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) {
4367 if (goHome()) {
4368 break;
Dianne Hackborn0041e972009-07-24 17:14:43 -07004369 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004370 }
Jeff Brown4d396052010-10-29 21:50:21 -07004371 if ((mEndcallBehavior
4372 & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) {
Jeff Brownc12035c2014-08-13 18:52:25 -07004373 mPowerManager.goToSleep(event.getEventTime(),
4374 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
Jeff Brown26875502014-01-30 21:47:47 -08004375 isWakeKey = false;
Jeff Brown4d396052010-10-29 21:50:21 -07004376 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004377 }
Jeff Brown4d396052010-10-29 21:50:21 -07004378 }
4379 break;
4380 }
4381
4382 case KeyEvent.KEYCODE_POWER: {
4383 result &= ~ACTION_PASS_TO_USER;
4384 if (down) {
Jeff Brown26c6a502014-04-11 02:15:54 -07004385 boolean panic = mImmersiveModeConfirmation.onPowerKeyDown(interactive,
John Spurlockd9b70bd2014-02-06 17:02:44 -05004386 event.getDownTime(), isImmersiveMode(mLastSystemUiFlags));
4387 if (panic) {
4388 mHandler.post(mRequestTransientNav);
4389 }
Jeff Brown037c33e2014-04-09 00:31:55 -07004390 if (interactive && !mPowerKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004391 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
4392 mPowerKeyTriggered = true;
4393 mPowerKeyTime = event.getDownTime();
4394 interceptScreenshotChord();
Winson Chung9112ec32011-06-27 13:15:32 -07004395 }
Winson Chung9112ec32011-06-27 13:15:32 -07004396
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004397 TelecomManager telecomManager = getTelecommService();
Jeff Brown4d396052010-10-29 21:50:21 -07004398 boolean hungUp = false;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004399 if (telecomManager != null) {
4400 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07004401 // Pressing Power while there's a ringing incoming
4402 // call should silence the ringer.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004403 telecomManager.silenceRinger();
Santos Cordon6848f722014-05-21 15:22:12 -07004404 } else if ((mIncallPowerBehavior
4405 & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004406 && telecomManager.isInCall() && interactive) {
Santos Cordon6848f722014-05-21 15:22:12 -07004407 // Otherwise, if "Power button ends call" is enabled,
4408 // the Power button will hang up any current active call.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004409 hungUp = telecomManager.endCall();
Jeff Brown4d396052010-10-29 21:50:21 -07004410 }
4411 }
Jeff Brown037c33e2014-04-09 00:31:55 -07004412 interceptPowerKeyDown(!interactive || hungUp
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004413 || mVolumeDownKeyTriggered || mVolumeUpKeyTriggered);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004414 } else {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004415 mPowerKeyTriggered = false;
4416 cancelPendingScreenshotChordAction();
4417 if (interceptPowerKeyUp(canceled || mPendingPowerKeyUpCanceled)) {
Jeff Brown734ab8e2014-10-07 16:42:28 -07004418 if (mScreenOnEarly && !mScreenOnFully) {
4419 Slog.i(TAG, "Suppressed redundant power key press while "
4420 + "already in the process of turning the screen on.");
4421 } else {
4422 powerShortPress(event.getEventTime());
4423 }
Jeff Brown26875502014-01-30 21:47:47 -08004424 isWakeKey = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004425 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004426 mPendingPowerKeyUpCanceled = false;
Jeff Brown4d396052010-10-29 21:50:21 -07004427 }
4428 break;
4429 }
4430
Jeff Brown6212a492014-03-07 13:58:47 -08004431 case KeyEvent.KEYCODE_SLEEP: {
4432 result &= ~ACTION_PASS_TO_USER;
Jeff Brownbae8e772014-06-12 19:59:45 -07004433 if (!mPowerManager.isInteractive()) {
4434 useHapticFeedback = false; // suppress feedback if already non-interactive
4435 }
Jeff Brownc12035c2014-08-13 18:52:25 -07004436 mPowerManager.goToSleep(event.getEventTime(),
4437 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
Jeff Brown6212a492014-03-07 13:58:47 -08004438 isWakeKey = false;
4439 break;
4440 }
4441
4442 case KeyEvent.KEYCODE_WAKEUP: {
4443 result &= ~ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07004444 isWakeKey = true;
Jeff Brown6212a492014-03-07 13:58:47 -08004445 break;
4446 }
4447
Jeff Brown4d396052010-10-29 21:50:21 -07004448 case KeyEvent.KEYCODE_MEDIA_PLAY:
4449 case KeyEvent.KEYCODE_MEDIA_PAUSE:
4450 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
Jeff Brown4d396052010-10-29 21:50:21 -07004451 case KeyEvent.KEYCODE_HEADSETHOOK:
4452 case KeyEvent.KEYCODE_MUTE:
4453 case KeyEvent.KEYCODE_MEDIA_STOP:
4454 case KeyEvent.KEYCODE_MEDIA_NEXT:
4455 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
4456 case KeyEvent.KEYCODE_MEDIA_REWIND:
4457 case KeyEvent.KEYCODE_MEDIA_RECORD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09004458 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
4459 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: {
RoboErikde9ba392014-09-26 12:51:01 -07004460 if (MediaSessionLegacyHelper.getHelper(mContext).isGlobalPriorityActive()) {
4461 // If the global session is active pass all media keys to it
4462 // instead of the active window.
4463 result &= ~ACTION_PASS_TO_USER;
4464 }
Jeff Brown4d396052010-10-29 21:50:21 -07004465 if ((result & ACTION_PASS_TO_USER) == 0) {
4466 // Only do this if we would otherwise not pass it to the user. In that
4467 // case, the PhoneWindow class will do the same thing, except it will
4468 // only do it if the showing app doesn't process the key on its own.
Jeff Brown40013652012-05-16 21:22:36 -07004469 // Note that we need to make a copy of the key event here because the
4470 // original key event will be recycled when we return.
Jeff Brown4d396052010-10-29 21:50:21 -07004471 mBroadcastWakeLock.acquire();
Jeff Brown40013652012-05-16 21:22:36 -07004472 Message msg = mHandler.obtainMessage(MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK,
4473 new KeyEvent(event));
4474 msg.setAsynchronous(true);
4475 msg.sendToTarget();
Jeff Brown4d396052010-10-29 21:50:21 -07004476 }
4477 break;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004478 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004479
Jeff Brown4d396052010-10-29 21:50:21 -07004480 case KeyEvent.KEYCODE_CALL: {
4481 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004482 TelecomManager telecomManager = getTelecommService();
4483 if (telecomManager != null) {
4484 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07004485 Log.i(TAG, "interceptKeyBeforeQueueing:"
4486 + " CALL key-down while ringing: Answer the call!");
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004487 telecomManager.acceptRingingCall();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004488
Santos Cordon6848f722014-05-21 15:22:12 -07004489 // And *don't* pass this key thru to the current activity
4490 // (which is presumably the InCallScreen.)
4491 result &= ~ACTION_PASS_TO_USER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004492 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004493 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004494 }
Jeff Brown4d396052010-10-29 21:50:21 -07004495 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004496 }
Michael Wright869a67c2014-08-26 19:33:06 -07004497 case KeyEvent.KEYCODE_VOICE_ASSIST: {
4498 // Only do this if we would otherwise not pass it to the user. In that case,
4499 // interceptKeyBeforeDispatching would apply a similar but different policy in
4500 // order to invoke voice assist actions. Note that we need to make a copy of the
4501 // key event here because the original key event will be recycled when we return.
4502 if ((result & ACTION_PASS_TO_USER) == 0 && !down) {
4503 mBroadcastWakeLock.acquire();
4504 Message msg = mHandler.obtainMessage(MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK,
4505 keyguardActive ? 1 : 0, 0);
4506 msg.setAsynchronous(true);
4507 msg.sendToTarget();
4508 }
4509 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004510 }
Jeff Brown26875502014-01-30 21:47:47 -08004511
Jeff Brownbae8e772014-06-12 19:59:45 -07004512 if (useHapticFeedback) {
4513 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
4514 }
4515
Jeff Brown26875502014-01-30 21:47:47 -08004516 if (isWakeKey) {
4517 mPowerManager.wakeUp(event.getEventTime());
4518 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004519 return result;
4520 }
4521
Jeff Brown1c2e4942012-11-06 16:32:01 -08004522 /**
4523 * When the screen is off we ignore some keys that might otherwise typically
4524 * be considered wake keys. We filter them out here.
4525 *
4526 * {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it
4527 * is always considered a wake key.
4528 */
4529 private boolean isWakeKeyWhenScreenOff(int keyCode) {
4530 switch (keyCode) {
4531 // ignore volume keys unless docked
4532 case KeyEvent.KEYCODE_VOLUME_UP:
4533 case KeyEvent.KEYCODE_VOLUME_DOWN:
4534 case KeyEvent.KEYCODE_VOLUME_MUTE:
4535 return mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED;
4536
4537 // ignore media and camera keys
4538 case KeyEvent.KEYCODE_MUTE:
4539 case KeyEvent.KEYCODE_HEADSETHOOK:
4540 case KeyEvent.KEYCODE_MEDIA_PLAY:
4541 case KeyEvent.KEYCODE_MEDIA_PAUSE:
4542 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
4543 case KeyEvent.KEYCODE_MEDIA_STOP:
4544 case KeyEvent.KEYCODE_MEDIA_NEXT:
4545 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
4546 case KeyEvent.KEYCODE_MEDIA_REWIND:
4547 case KeyEvent.KEYCODE_MEDIA_RECORD:
4548 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09004549 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK:
Jeff Brown1c2e4942012-11-06 16:32:01 -08004550 case KeyEvent.KEYCODE_CAMERA:
4551 return false;
4552 }
4553 return true;
4554 }
4555
4556
Jeff Brown56194eb2011-03-02 19:23:13 -08004557 /** {@inheritDoc} */
4558 @Override
Michael Wright70af00a2014-09-03 19:30:20 -07004559 public int interceptMotionBeforeQueueingNonInteractive(long whenNanos, int policyFlags) {
4560 if ((policyFlags & FLAG_WAKE) != 0) {
4561 mPowerManager.wakeUp(whenNanos / 1000000);
4562 return 0;
4563 }
4564 if (shouldDispatchInputWhenNonInteractive()) {
4565 return ACTION_PASS_TO_USER;
4566 }
Jeff Brown037c33e2014-04-09 00:31:55 -07004567 return 0;
Jeff Brown56194eb2011-03-02 19:23:13 -08004568 }
4569
Michael Wright70af00a2014-09-03 19:30:20 -07004570 private boolean shouldDispatchInputWhenNonInteractive() {
4571 return keyguardIsShowingTq() && mDisplay != null &&
4572 mDisplay.getState() != Display.STATE_OFF;
4573 }
4574
Jeff Brown40013652012-05-16 21:22:36 -07004575 void dispatchMediaKeyWithWakeLock(KeyEvent event) {
4576 if (DEBUG_INPUT) {
4577 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: " + event);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004578 }
4579
Jeff Brown40013652012-05-16 21:22:36 -07004580 if (mHavePendingMediaKeyRepeatWithWakeLock) {
4581 if (DEBUG_INPUT) {
4582 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: canceled repeat");
4583 }
4584
4585 mHandler.removeMessages(MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK);
4586 mHavePendingMediaKeyRepeatWithWakeLock = false;
4587 mBroadcastWakeLock.release(); // pending repeat was holding onto the wake lock
4588 }
4589
4590 dispatchMediaKeyWithWakeLockToAudioService(event);
4591
4592 if (event.getAction() == KeyEvent.ACTION_DOWN
4593 && event.getRepeatCount() == 0) {
4594 mHavePendingMediaKeyRepeatWithWakeLock = true;
4595
4596 Message msg = mHandler.obtainMessage(
4597 MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK, event);
4598 msg.setAsynchronous(true);
4599 mHandler.sendMessageDelayed(msg, ViewConfiguration.getKeyRepeatTimeout());
4600 } else {
4601 mBroadcastWakeLock.release();
4602 }
4603 }
4604
4605 void dispatchMediaKeyRepeatWithWakeLock(KeyEvent event) {
4606 mHavePendingMediaKeyRepeatWithWakeLock = false;
4607
4608 KeyEvent repeatEvent = KeyEvent.changeTimeRepeat(event,
4609 SystemClock.uptimeMillis(), 1, event.getFlags() | KeyEvent.FLAG_LONG_PRESS);
4610 if (DEBUG_INPUT) {
4611 Slog.d(TAG, "dispatchMediaKeyRepeatWithWakeLock: " + repeatEvent);
4612 }
4613
4614 dispatchMediaKeyWithWakeLockToAudioService(repeatEvent);
4615 mBroadcastWakeLock.release();
4616 }
4617
4618 void dispatchMediaKeyWithWakeLockToAudioService(KeyEvent event) {
4619 if (ActivityManagerNative.isSystemReady()) {
RoboErik430fc482014-06-12 15:49:20 -07004620 MediaSessionLegacyHelper.getHelper(mContext).sendMediaButtonEvent(event, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004621 }
4622 }
4623
Michael Wright869a67c2014-08-26 19:33:06 -07004624 void launchVoiceAssistWithWakeLock(boolean keyguardActive) {
4625 Intent voiceIntent =
4626 new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
4627 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, keyguardActive);
4628 mContext.startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
4629 mBroadcastWakeLock.release();
4630 }
4631
Mike Lockwood1753f7f2009-08-24 14:49:07 -07004632 BroadcastReceiver mDockReceiver = new BroadcastReceiver() {
Craig Mautnereee29c42013-01-17 14:44:34 -08004633 @Override
Mike Lockwood1753f7f2009-08-24 14:49:07 -07004634 public void onReceive(Context context, Intent intent) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07004635 if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) {
4636 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
4637 Intent.EXTRA_DOCK_STATE_UNDOCKED);
Daniel Sandler6396c722013-04-16 20:19:09 -04004638 } else {
4639 try {
4640 IUiModeManager uiModeService = IUiModeManager.Stub.asInterface(
4641 ServiceManager.getService(Context.UI_MODE_SERVICE));
4642 mUiMode = uiModeService.getCurrentModeType();
4643 } catch (RemoteException e) {
4644 }
Dianne Hackborn80fa1662009-10-07 14:02:10 -07004645 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004646 updateRotation(true);
Craig Mautnereee29c42013-01-17 14:44:34 -08004647 synchronized (mLock) {
4648 updateOrientationListenerLp();
4649 }
Mike Lockwood1753f7f2009-08-24 14:49:07 -07004650 }
4651 };
4652
Jeff Brown6aaf2952012-10-05 16:01:08 -07004653 BroadcastReceiver mDreamReceiver = new BroadcastReceiver() {
4654 @Override
4655 public void onReceive(Context context, Intent intent) {
4656 if (Intent.ACTION_DREAMING_STARTED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004657 if (mKeyguardDelegate != null) {
4658 mKeyguardDelegate.onDreamingStarted();
Jeff Brown6aaf2952012-10-05 16:01:08 -07004659 }
4660 } else if (Intent.ACTION_DREAMING_STOPPED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004661 if (mKeyguardDelegate != null) {
4662 mKeyguardDelegate.onDreamingStopped();
Jeff Brown6aaf2952012-10-05 16:01:08 -07004663 }
4664 }
4665 }
4666 };
4667
Christopher Tate5e08af02012-09-21 17:17:22 -07004668 BroadcastReceiver mMultiuserReceiver = new BroadcastReceiver() {
4669 @Override
4670 public void onReceive(Context context, Intent intent) {
4671 if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) {
4672 // tickle the settings observer: this first ensures that we're
4673 // observing the relevant settings for the newly-active user,
4674 // and then updates our own bookkeeping based on the now-
4675 // current user.
4676 mSettingsObserver.onChange(false);
John Spurlockce479d82012-11-29 09:52:21 -05004677
4678 // force a re-application of focused window sysui visibility.
4679 // the window may never have been shown for this user
4680 // e.g. the keyguard when going through the new-user setup flow
John Spurlock04db1762013-05-13 12:46:41 -04004681 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
John Spurlockce479d82012-11-29 09:52:21 -05004682 mLastSystemUiFlags = 0;
4683 updateSystemUiVisibilityLw();
4684 }
Christopher Tate5e08af02012-09-21 17:17:22 -07004685 }
4686 }
4687 };
4688
John Spurlockd9b70bd2014-02-06 17:02:44 -05004689 private final Runnable mRequestTransientNav = new Runnable() {
4690 @Override
4691 public void run() {
4692 requestTransientBars(mNavigationBar);
4693 }
4694 };
4695
John Spurlocke1f366f2013-08-05 12:22:40 -04004696 private void requestTransientBars(WindowState swipeTarget) {
John Spurlock04db1762013-05-13 12:46:41 -04004697 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Maurice Lam99c6e072014-04-28 18:24:28 -07004698 if (!isUserSetupComplete()) {
4699 // Swipe-up for navigation bar is disabled during setup
4700 return;
4701 }
John Spurlock27735a42013-08-14 17:57:38 -04004702 boolean sb = mStatusBarController.checkShowTransientBarLw();
4703 boolean nb = mNavigationBarController.checkShowTransientBarLw();
John Spurlockad3e6cb2013-04-30 08:47:43 -04004704 if (sb || nb) {
John Spurlocke1f366f2013-08-05 12:22:40 -04004705 WindowState barTarget = sb ? mStatusBar : mNavigationBar;
4706 if (sb ^ nb && barTarget != swipeTarget) {
4707 if (DEBUG) Slog.d(TAG, "Not showing transient bar, wrong swipe target");
John Spurlockad3e6cb2013-04-30 08:47:43 -04004708 return;
4709 }
John Spurlock27735a42013-08-14 17:57:38 -04004710 if (sb) mStatusBarController.showTransient();
4711 if (nb) mNavigationBarController.showTransient();
John Spurlockf1a36642013-10-12 17:50:42 -04004712 mImmersiveModeConfirmation.confirmCurrentPrompt();
John Spurlockad3e6cb2013-04-30 08:47:43 -04004713 updateSystemUiVisibilityLw();
John Spurlock32beb2c2013-03-11 10:16:47 -04004714 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04004715 }
4716 }
4717
Jeff Brown3ee549c2014-09-22 20:14:39 -07004718 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07004719 @Override
Jeff Brown140ffc72014-05-01 15:18:00 -07004720 public void goingToSleep(int why) {
Dianne Hackborn74489012009-03-24 20:50:09 -07004721 EventLog.writeEvent(70000, 0);
Jeff Brown36c4db82014-09-19 12:05:31 -07004722 if (DEBUG_WAKEUP) Slog.i(TAG, "Going to sleep...");
Jeff Brown3ee549c2014-09-22 20:14:39 -07004723
4724 // We must get this work done here because the power manager will drop
4725 // the wake lock and let the system suspend once this function returns.
The Android Open Source Project0727d222009-03-11 12:11:58 -07004726 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07004727 mAwake = false;
4728 mKeyguardDrawComplete = false;
Jeff Browna20dda42014-05-27 20:57:24 -07004729 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07004730 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05004731 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07004732 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07004733
4734 if (mKeyguardDelegate != null) {
4735 mKeyguardDelegate.onScreenTurnedOff(why);
4736 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004737 }
4738
Jeff Brown3ee549c2014-09-22 20:14:39 -07004739 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07004740 @Override
Jeff Brown36c4db82014-09-19 12:05:31 -07004741 public void wakingUp() {
Dianne Hackborn74489012009-03-24 20:50:09 -07004742 EventLog.writeEvent(70000, 1);
Jeff Brown36c4db82014-09-19 12:05:31 -07004743 if (DEBUG_WAKEUP) Slog.i(TAG, "Waking up...");
Craig Mautner8a0da012014-05-31 15:13:37 -07004744
Jeff Brown3ee549c2014-09-22 20:14:39 -07004745 // Since goToSleep performs these functions synchronously, we must
4746 // do the same here. We cannot post this work to a handler because
4747 // that might cause it to become reordered with respect to what
4748 // may happen in a future call to goToSleep.
The Android Open Source Project0727d222009-03-11 12:11:58 -07004749 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07004750 mAwake = true;
4751 mKeyguardDrawComplete = false;
4752 if (mKeyguardDelegate != null) {
4753 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
4754 mHandler.sendEmptyMessageDelayed(MSG_KEYGUARD_DRAWN_TIMEOUT, 1000);
4755 }
4756
Jeff Browna20dda42014-05-27 20:57:24 -07004757 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07004758 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05004759 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07004760 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07004761
Jim Miller5ecd8112013-01-09 18:50:26 -08004762 if (mKeyguardDelegate != null) {
Craig Mautner8a0da012014-05-31 15:13:37 -07004763 mKeyguardDelegate.onScreenTurnedOn(mKeyguardDelegateCallback);
Jeff Brown36c4db82014-09-19 12:05:31 -07004764 // ... eventually calls finishKeyguardDrawn
Jeff Brownc38c9be2012-10-04 13:16:19 -07004765 } else {
Craig Mautner8a0da012014-05-31 15:13:37 -07004766 if (DEBUG_WAKEUP) Slog.d(TAG, "null mKeyguardDelegate: setting mKeyguardDrawComplete.");
Jeff Brown36c4db82014-09-19 12:05:31 -07004767 finishKeyguardDrawn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07004768 }
Jeff Brown36c4db82014-09-19 12:05:31 -07004769 }
4770
Jeff Brown36c4db82014-09-19 12:05:31 -07004771 private void finishKeyguardDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07004772 synchronized (mLock) {
4773 if (!mAwake || mKeyguardDrawComplete) {
4774 return; // spurious
4775 }
4776
Jeff Brown36c4db82014-09-19 12:05:31 -07004777 mKeyguardDrawComplete = true;
Jeff Brown3ee549c2014-09-22 20:14:39 -07004778 if (mKeyguardDelegate != null) {
4779 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
4780 }
4781 }
4782
4783 finishScreenTurningOn();
4784 }
4785
4786 // Called on the DisplayManager's DisplayPowerController thread.
4787 @Override
4788 public void screenTurnedOff() {
4789 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turned off...");
4790
4791 synchronized (mLock) {
4792 mScreenOnEarly = false;
4793 mScreenOnFully = false;
4794 mWindowManagerDrawComplete = false;
4795 mScreenOnListener = null;
4796 updateOrientationListenerLp();
Jeff Brown36c4db82014-09-19 12:05:31 -07004797 }
4798 }
4799
Jeff Brown3ee549c2014-09-22 20:14:39 -07004800 // Called on the DisplayManager's DisplayPowerController thread.
Jeff Brown36c4db82014-09-19 12:05:31 -07004801 @Override
4802 public void screenTurningOn(final ScreenOnListener screenOnListener) {
Jeff Brown36c4db82014-09-19 12:05:31 -07004803 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turning on...");
Jeff Brown36c4db82014-09-19 12:05:31 -07004804
Jeff Brown3ee549c2014-09-22 20:14:39 -07004805 synchronized (mLock) {
4806 mScreenOnEarly = true;
4807 mScreenOnFully = false;
4808 mWindowManagerDrawComplete = false;
4809 mScreenOnListener = screenOnListener;
4810 updateOrientationListenerLp();
4811 }
Jeff Brown36c4db82014-09-19 12:05:31 -07004812
Craig Mautnerc3daedd2014-09-13 11:17:23 -07004813 mWindowManagerInternal.waitForAllWindowsDrawn(mWindowManagerDrawCallback,
4814 WAITING_FOR_DRAWN_TIMEOUT);
Jeff Brown36c4db82014-09-19 12:05:31 -07004815 // ... eventually calls finishWindowsDrawn
4816 }
4817
Jeff Brown36c4db82014-09-19 12:05:31 -07004818 private void finishWindowsDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07004819 synchronized (mLock) {
4820 if (!mScreenOnEarly || mWindowManagerDrawComplete) {
4821 return; // spurious
4822 }
4823
Jeff Brown36c4db82014-09-19 12:05:31 -07004824 mWindowManagerDrawComplete = true;
Jeff Brown36c4db82014-09-19 12:05:31 -07004825 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07004826
4827 finishScreenTurningOn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07004828 }
4829
Craig Mautner8a0da012014-05-31 15:13:37 -07004830 private void finishScreenTurningOn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07004831 final ScreenOnListener listener;
4832 final boolean enableScreen;
Jeff Brown36c4db82014-09-19 12:05:31 -07004833 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07004834 if (DEBUG_WAKEUP) Slog.d(TAG,
4835 "finishScreenTurningOn: mAwake=" + mAwake
4836 + ", mScreenOnEarly=" + mScreenOnEarly
4837 + ", mScreenOnFully=" + mScreenOnFully
4838 + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete
4839 + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete);
4840
4841 if (mScreenOnFully || !mScreenOnEarly || !mWindowManagerDrawComplete
4842 || (mAwake && !mKeyguardDrawComplete)) {
4843 return; // spurious or not ready yet
Jeff Brown36c4db82014-09-19 12:05:31 -07004844 }
4845
Jeff Brown3ee549c2014-09-22 20:14:39 -07004846 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished screen turning on...");
4847 listener = mScreenOnListener;
Craig Mautner13f6ea72014-06-23 14:57:02 -07004848 mScreenOnListener = null;
Jeff Brown3ee549c2014-09-22 20:14:39 -07004849 mScreenOnFully = true;
4850
4851 // Remember the first time we draw the keyguard so we know when we're done with
4852 // the main part of booting and can enable the screen and hide boot messages.
4853 if (!mKeyguardDrawnOnce && mAwake) {
4854 mKeyguardDrawnOnce = true;
4855 enableScreen = true;
4856 if (mBootMessageNeedsHiding) {
4857 mBootMessageNeedsHiding = false;
4858 hideBootMessages();
4859 }
4860 } else {
4861 enableScreen = false;
4862 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07004863 }
4864
Jeff Brown3ee549c2014-09-22 20:14:39 -07004865 if (listener != null) {
4866 listener.onScreenOn();
4867 }
Jeff Brown4fc45272012-10-10 18:28:14 -07004868
Jeff Brown3ee549c2014-09-22 20:14:39 -07004869 if (enableScreen) {
4870 try {
4871 mWindowManager.enableScreenIfNeeded();
4872 } catch (RemoteException unhandled) {
Jeff Brown36c4db82014-09-19 12:05:31 -07004873 }
Craig Mautnera631d492014-08-05 15:16:01 -07004874 }
4875 }
4876
4877 private void handleHideBootMessage() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07004878 synchronized (mLock) {
4879 if (!mKeyguardDrawnOnce) {
4880 mBootMessageNeedsHiding = true;
4881 return; // keyguard hasn't drawn the first time yet, not done booting
4882 }
Craig Mautnera631d492014-08-05 15:16:01 -07004883 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07004884
4885 if (mBootMsgDialog != null) {
4886 if (DEBUG_WAKEUP) Slog.d(TAG, "handleHideBootMessage: dismissing");
4887 mBootMsgDialog.dismiss();
4888 mBootMsgDialog = null;
Craig Mautnera631d492014-08-05 15:16:01 -07004889 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07004890 }
4891
4892 @Override
Jeff Brown3ee549c2014-09-22 20:14:39 -07004893 public boolean isScreenOn() {
4894 return mScreenOnFully;
Dianne Hackborn08743722009-12-21 12:16:51 -08004895 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07004896
Dianne Hackborn08743722009-12-21 12:16:51 -08004897 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07004898 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004899 public void enableKeyguard(boolean enabled) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004900 if (mKeyguardDelegate != null) {
4901 mKeyguardDelegate.setKeyguardEnabled(enabled);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004902 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004903 }
4904
4905 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07004906 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004907 public void exitKeyguardSecurely(OnKeyguardExitResult callback) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004908 if (mKeyguardDelegate != null) {
4909 mKeyguardDelegate.verifyUnlock(callback);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004910 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004911 }
4912
Mike Lockwoodf7913302009-11-28 22:27:10 -05004913 private boolean keyguardIsShowingTq() {
Jim Miller5ecd8112013-01-09 18:50:26 -08004914 if (mKeyguardDelegate == null) return false;
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004915 return mKeyguardDelegate.isShowingAndNotOccluded();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004916 }
4917
Mike Lockwood520d8bc2011-02-18 13:23:13 -05004918
4919 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07004920 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05004921 public boolean isKeyguardLocked() {
4922 return keyguardOn();
4923 }
4924
4925 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07004926 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05004927 public boolean isKeyguardSecure() {
Jim Miller5ecd8112013-01-09 18:50:26 -08004928 if (mKeyguardDelegate == null) return false;
4929 return mKeyguardDelegate.isSecure();
Mike Lockwood520d8bc2011-02-18 13:23:13 -05004930 }
4931
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004932 // Returns true if keyguard is currently locked whether or not it is currently hidden.
4933 private boolean isKeyguardSecureIncludingHidden() {
4934 return mKeyguardDelegate.isSecure() && mKeyguardDelegate.isShowing();
4935 }
4936
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004937 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07004938 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004939 public boolean inKeyguardRestrictedKeyInputMode() {
Jim Miller5ecd8112013-01-09 18:50:26 -08004940 if (mKeyguardDelegate == null) return false;
4941 return mKeyguardDelegate.isInputRestricted();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004942 }
4943
Jose Lima9546b202014-07-02 17:21:51 -07004944 @Override
Dianne Hackborn90c52de2011-09-23 12:57:44 -07004945 public void dismissKeyguardLw() {
RoboErik8a2cfc32014-05-16 11:19:38 -07004946 if (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()) {
Daniel Sandler1ce804392012-11-07 15:07:12 -05004947 mHandler.post(new Runnable() {
Jose Lima9546b202014-07-02 17:21:51 -07004948 @Override
Daniel Sandler1ce804392012-11-07 15:07:12 -05004949 public void run() {
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02004950 // ask the keyguard to prompt the user to authenticate if necessary
4951 mKeyguardDelegate.dismiss();
4952 }
4953 });
4954 }
4955 }
4956
4957 public void notifyActivityDrawnForKeyguardLw() {
4958 if (mKeyguardDelegate != null) {
4959 mHandler.post(new Runnable() {
4960 @Override
4961 public void run() {
4962 mKeyguardDelegate.onActivityDrawn();
Daniel Sandler1ce804392012-11-07 15:07:12 -05004963 }
4964 });
Dianne Hackborn90c52de2011-09-23 12:57:44 -07004965 }
4966 }
4967
Jorim Jaggicff0acb2014-03-31 16:35:15 +02004968 @Override
4969 public boolean isKeyguardDrawnLw() {
4970 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07004971 return mKeyguardDrawnOnce;
Jorim Jaggicff0acb2014-03-31 16:35:15 +02004972 }
4973 }
4974
Jorim Jaggi0d674622014-05-21 01:34:15 +02004975 @Override
Jorim Jaggie29b2db2014-05-30 23:17:03 +02004976 public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) {
Jorim Jaggi0d674622014-05-21 01:34:15 +02004977 if (mKeyguardDelegate != null) {
Jorim Jaggie29b2db2014-05-30 23:17:03 +02004978 mKeyguardDelegate.startKeyguardExitAnimation(startTime, fadeoutDuration);
Jorim Jaggi0d674622014-05-21 01:34:15 +02004979 }
4980 }
4981
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004982 void sendCloseSystemWindows() {
4983 sendCloseSystemWindows(mContext, null);
4984 }
4985
4986 void sendCloseSystemWindows(String reason) {
4987 sendCloseSystemWindows(mContext, reason);
4988 }
4989
4990 static void sendCloseSystemWindows(Context context, String reason) {
4991 if (ActivityManagerNative.isSystemReady()) {
Dianne Hackborn94a679d2009-07-28 17:51:07 -07004992 try {
4993 ActivityManagerNative.getDefault().closeSystemDialogs(reason);
4994 } catch (RemoteException e) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004995 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004996 }
4997 }
Mitsuru Oshima831d0d92009-06-16 18:27:18 -07004998
Jeff Brown01a98dd2011-09-20 15:08:29 -07004999 @Override
5000 public int rotationForOrientationLw(int orientation, int lastRotation) {
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005001 if (false) {
5002 Slog.v(TAG, "rotationForOrientationLw(orient="
5003 + orientation + ", last=" + lastRotation
5004 + "); user=" + mUserRotation + " "
5005 + ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED)
5006 ? "USER_ROTATION_LOCKED" : "")
5007 );
5008 }
5009
Craig Mautner46ac6fa2013-08-01 10:06:34 -07005010 if (mForceDefaultOrientation) {
5011 return Surface.ROTATION_0;
5012 }
5013
The Android Open Source Project0727d222009-03-11 12:11:58 -07005014 synchronized (mLock) {
Jeff Brownc0347aa2011-09-23 17:26:09 -07005015 int sensorRotation = mOrientationListener.getProposedRotation(); // may be -1
5016 if (sensorRotation < 0) {
Jeff Brown0f862b42012-09-27 21:11:01 -07005017 sensorRotation = lastRotation;
Jeff Brownc0347aa2011-09-23 17:26:09 -07005018 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005019
Jeff Browndec6cf42011-11-15 14:08:20 -08005020 final int preferredRotation;
Jeff Brown2e7760e2012-04-11 15:14:55 -07005021 if (mLidState == LID_OPEN && mLidOpenRotation >= 0) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005022 // Ignore sensor when lid switch is open and rotation is forced.
5023 preferredRotation = mLidOpenRotation;
5024 } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR
Jeff Brownc0347aa2011-09-23 17:26:09 -07005025 && (mCarDockEnablesAccelerometer || mCarDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005026 // Ignore sensor when in car dock unless explicitly enabled.
5027 // This case can override the behavior of NOSENSOR, and can also
5028 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07005029 preferredRotation = mCarDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07005030 ? sensorRotation : mCarDockRotation;
Jeff Brown1a693182011-11-08 14:44:16 -08005031 } else if ((mDockMode == Intent.EXTRA_DOCK_STATE_DESK
5032 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
5033 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK)
Jeff Brownc0347aa2011-09-23 17:26:09 -07005034 && (mDeskDockEnablesAccelerometer || mDeskDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005035 // Ignore sensor when in desk dock unless explicitly enabled.
5036 // This case can override the behavior of NOSENSOR, and can also
5037 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07005038 preferredRotation = mDeskDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07005039 ? sensorRotation : mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -07005040 } else if (mHdmiPlugged && mDemoHdmiRotationLock) {
5041 // Ignore sensor when plugged into HDMI when demo HDMI rotation lock enabled.
Jeff Browneb3e4b92011-12-06 19:54:24 -08005042 // Note that the dock orientation overrides the HDMI orientation.
Jeff Brownc82c89ed2013-04-17 17:18:15 -07005043 preferredRotation = mDemoHdmiRotation;
5044 } else if (mHdmiPlugged && mDockMode == Intent.EXTRA_DOCK_STATE_UNDOCKED
5045 && mUndockedHdmiRotation >= 0) {
5046 // Ignore sensor when plugged into HDMI and an undocked orientation has
5047 // been specified in the configuration (only for legacy devices without
5048 // full multi-display support).
5049 // Note that the dock orientation overrides the HDMI orientation.
5050 preferredRotation = mUndockedHdmiRotation;
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005051 } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED) {
5052 // Application just wants to remain locked in the last rotation.
5053 preferredRotation = lastRotation;
Jeff Brownbcdfc622014-03-06 19:13:04 -08005054 } else if (!mSupportAutoRotation) {
5055 // If we don't support auto-rotation then bail out here and ignore
5056 // the sensor and any rotation lock settings.
5057 preferredRotation = -1;
Jeff Brown207673cd2012-06-05 17:47:11 -07005058 } else if ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE
Jeff Brown01a98dd2011-09-20 15:08:29 -07005059 && (orientation == ActivityInfo.SCREEN_ORIENTATION_USER
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005060 || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
5061 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
5062 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
5063 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER))
Jeff Brown01a98dd2011-09-20 15:08:29 -07005064 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
5065 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
5066 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
5067 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) {
5068 // Otherwise, use sensor only if requested by the application or enabled
5069 // by default for USER or UNSPECIFIED modes. Does not apply to NOSENSOR.
Jeff Brownd3187e32011-09-21 19:26:44 -07005070 if (mAllowAllRotations < 0) {
5071 // Can't read this during init() because the context doesn't
5072 // have display metrics at that time so we cannot determine
5073 // tablet vs. phone then.
5074 mAllowAllRotations = mContext.getResources().getBoolean(
5075 com.android.internal.R.bool.config_allowAllRotations) ? 1 : 0;
5076 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005077 if (sensorRotation != Surface.ROTATION_180
Jeff Brownd3187e32011-09-21 19:26:44 -07005078 || mAllowAllRotations == 1
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005079 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
5080 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005081 preferredRotation = sensorRotation;
5082 } else {
5083 preferredRotation = lastRotation;
5084 }
Jeff Brown207673cd2012-06-05 17:47:11 -07005085 } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED
5086 && orientation != ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) {
5087 // Apply rotation lock. Does not apply to NOSENSOR.
5088 // The idea is that the user rotation expresses a weak preference for the direction
5089 // of gravity and as NOSENSOR is never affected by gravity, then neither should
5090 // NOSENSOR be affected by rotation lock (although it will be affected by docks).
Jeff Brown4dfce202011-10-05 12:00:10 -07005091 preferredRotation = mUserRotation;
Jeff Browndec6cf42011-11-15 14:08:20 -08005092 } else {
5093 // No overriding preference.
5094 // We will do exactly what the application asked us to do.
5095 preferredRotation = -1;
Jeff Brown01a98dd2011-09-20 15:08:29 -07005096 }
5097
Dianne Hackborne5439f22010-10-02 16:53:50 -07005098 switch (orientation) {
5099 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08005100 // Return portrait unless overridden.
5101 if (isAnyPortrait(preferredRotation)) {
5102 return preferredRotation;
5103 }
Dianne Hackborne5439f22010-10-02 16:53:50 -07005104 return mPortraitRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005105
Jeff Brown01a98dd2011-09-20 15:08:29 -07005106 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08005107 // Return landscape unless overridden.
5108 if (isLandscapeOrSeascape(preferredRotation)) {
5109 return preferredRotation;
5110 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005111 return mLandscapeRotation;
5112
5113 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08005114 // Return reverse portrait unless overridden.
5115 if (isAnyPortrait(preferredRotation)) {
5116 return preferredRotation;
5117 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005118 return mUpsideDownRotation;
5119
5120 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08005121 // Return seascape unless overridden.
5122 if (isLandscapeOrSeascape(preferredRotation)) {
5123 return preferredRotation;
5124 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005125 return mSeascapeRotation;
5126
5127 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005128 case ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE:
Jeff Brown01a98dd2011-09-20 15:08:29 -07005129 // Return either landscape rotation.
5130 if (isLandscapeOrSeascape(preferredRotation)) {
5131 return preferredRotation;
5132 }
5133 if (isLandscapeOrSeascape(lastRotation)) {
Jeff Brown4519f072011-01-23 13:16:01 -08005134 return lastRotation;
5135 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005136 return mLandscapeRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005137
Jeff Brown01a98dd2011-09-20 15:08:29 -07005138 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005139 case ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT:
Jeff Brown01a98dd2011-09-20 15:08:29 -07005140 // Return either portrait rotation.
5141 if (isAnyPortrait(preferredRotation)) {
5142 return preferredRotation;
5143 }
5144 if (isAnyPortrait(lastRotation)) {
5145 return lastRotation;
5146 }
5147 return mPortraitRotation;
5148
5149 default:
Jeff Brown4dfce202011-10-05 12:00:10 -07005150 // For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR,
5151 // just return the preferred orientation we already calculated.
Jeff Brown01a98dd2011-09-20 15:08:29 -07005152 if (preferredRotation >= 0) {
5153 return preferredRotation;
5154 }
Dianne Hackborndacea8c2011-04-21 17:26:39 -07005155 return Surface.ROTATION_0;
Daniel Sandlere7e5ac22011-02-22 16:10:21 -05005156 }
5157 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07005158 }
5159
Jeff Brown01a98dd2011-09-20 15:08:29 -07005160 @Override
5161 public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation) {
5162 switch (orientation) {
5163 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
5164 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
5165 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
5166 return isAnyPortrait(rotation);
5167
5168 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
5169 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
5170 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
5171 return isLandscapeOrSeascape(rotation);
5172
5173 default:
5174 return true;
5175 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07005176 }
5177
Jeff Brownc0347aa2011-09-23 17:26:09 -07005178 @Override
5179 public void setRotationLw(int rotation) {
5180 mOrientationListener.setCurrentRotation(rotation);
5181 }
5182
Jeff Brown01a98dd2011-09-20 15:08:29 -07005183 private boolean isLandscapeOrSeascape(int rotation) {
5184 return rotation == mLandscapeRotation || rotation == mSeascapeRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005185 }
5186
Jeff Brown01a98dd2011-09-20 15:08:29 -07005187 private boolean isAnyPortrait(int rotation) {
5188 return rotation == mPortraitRotation || rotation == mUpsideDownRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005189 }
5190
Jose Lima9546b202014-07-02 17:21:51 -07005191 @Override
Svetoslav Ganov80943d82013-01-02 10:25:37 -08005192 public int getUserRotationMode() {
5193 return Settings.System.getIntForUser(mContext.getContentResolver(),
Brett Chabot7e55c402013-05-16 19:38:08 -07005194 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
5195 WindowManagerPolicy.USER_ROTATION_FREE :
5196 WindowManagerPolicy.USER_ROTATION_LOCKED;
Svetoslav Ganov80943d82013-01-02 10:25:37 -08005197 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005198
5199 // User rotation: to be used when all else fails in assigning an orientation to the device
Jose Lima9546b202014-07-02 17:21:51 -07005200 @Override
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005201 public void setUserRotationMode(int mode, int rot) {
5202 ContentResolver res = mContext.getContentResolver();
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005203
5204 // mUserRotationMode and mUserRotation will be assigned by the content observer
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005205 if (mode == WindowManagerPolicy.USER_ROTATION_LOCKED) {
Christopher Tate5e08af02012-09-21 17:17:22 -07005206 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005207 Settings.System.USER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005208 rot,
5209 UserHandle.USER_CURRENT);
5210 Settings.System.putIntForUser(res,
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005211 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005212 0,
5213 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005214 } else {
Christopher Tate5e08af02012-09-21 17:17:22 -07005215 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005216 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005217 1,
5218 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005219 }
5220 }
5221
Jose Lima9546b202014-07-02 17:21:51 -07005222 @Override
Jeff Brownac143512012-04-05 18:57:33 -07005223 public void setSafeMode(boolean safeMode) {
5224 mSafeMode = safeMode;
5225 performHapticFeedbackLw(null, safeMode
5226 ? HapticFeedbackConstants.SAFE_MODE_ENABLED
5227 : HapticFeedbackConstants.SAFE_MODE_DISABLED, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005228 }
Craig Mautnereda67292013-04-28 13:50:14 -07005229
Dianne Hackborn181ceb52009-08-27 22:16:40 -07005230 static long[] getLongIntArray(Resources r, int resid) {
5231 int[] ar = r.getIntArray(resid);
5232 if (ar == null) {
5233 return null;
5234 }
5235 long[] out = new long[ar.length];
5236 for (int i=0; i<ar.length; i++) {
5237 out[i] = ar[i];
5238 }
5239 return out;
5240 }
Craig Mautnereda67292013-04-28 13:50:14 -07005241
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005242 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07005243 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005244 public void systemReady() {
Mike Lockwooded8902d2013-11-15 11:01:47 -08005245 mKeyguardDelegate = new KeyguardServiceDelegate(mContext, null);
5246 mKeyguardDelegate.onSystemReady();
5247
Michael Wright3818c922014-09-02 13:59:07 -07005248 readCameraLensCoverState();
Jeff Brown4f5fa282014-06-12 19:19:15 -07005249 updateUiMode();
Dianne Hackbornb1a79802009-09-29 15:18:31 -07005250 synchronized (mLock) {
5251 updateOrientationListenerLp();
Dianne Hackbornc777e072010-02-12 13:07:59 -08005252 mSystemReady = true;
5253 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07005254 @Override
Dianne Hackbornc777e072010-02-12 13:07:59 -08005255 public void run() {
5256 updateSettings();
5257 }
5258 });
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005259 }
5260 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07005261
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005262 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005263 @Override
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005264 public void systemBooted() {
Jim Millere5f910a2013-10-16 18:15:46 -07005265 if (mKeyguardDelegate != null) {
Jason Monk5eeebf52014-09-26 12:36:51 -04005266 mKeyguardDelegate.bindService(mContext);
Jim Millere5f910a2013-10-16 18:15:46 -07005267 mKeyguardDelegate.onBootCompleted();
5268 }
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005269 synchronized (mLock) {
5270 mSystemBooted = true;
5271 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005272 wakingUp();
5273 screenTurningOn(null);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005274 }
5275
Dianne Hackborn661cd522011-08-22 00:26:20 -07005276 ProgressDialog mBootMsgDialog = null;
5277
5278 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005279 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07005280 public void showBootMessage(final CharSequence msg, final boolean always) {
5281 mHandler.post(new Runnable() {
5282 @Override public void run() {
5283 if (mBootMsgDialog == null) {
Craig Stout4c0cb8a2014-04-04 13:03:10 -07005284 int theme;
5285 if (mContext.getPackageManager().hasSystemFeature(
5286 PackageManager.FEATURE_WATCH)) {
5287 theme = com.android.internal.R.style.Theme_Micro_Dialog_Alert;
5288 } else if (mContext.getPackageManager().hasSystemFeature(
5289 PackageManager.FEATURE_TELEVISION)) {
5290 theme = com.android.internal.R.style.Theme_Leanback_Dialog_Alert;
5291 } else {
5292 theme = 0;
5293 }
Vinod Krishnanfa8fc412014-04-18 14:35:53 -07005294
5295 mBootMsgDialog = new ProgressDialog(mContext, theme) {
Dianne Hackborn295e3c22011-08-25 13:19:08 -07005296 // This dialog will consume all events coming in to
5297 // it, to avoid it trying to do things too early in boot.
5298 @Override public boolean dispatchKeyEvent(KeyEvent event) {
5299 return true;
5300 }
5301 @Override public boolean dispatchKeyShortcutEvent(KeyEvent event) {
5302 return true;
5303 }
5304 @Override public boolean dispatchTouchEvent(MotionEvent ev) {
5305 return true;
5306 }
5307 @Override public boolean dispatchTrackballEvent(MotionEvent ev) {
5308 return true;
5309 }
5310 @Override public boolean dispatchGenericMotionEvent(MotionEvent ev) {
5311 return true;
5312 }
5313 @Override public boolean dispatchPopulateAccessibilityEvent(
5314 AccessibilityEvent event) {
5315 return true;
5316 }
5317 };
Dianne Hackborn661cd522011-08-22 00:26:20 -07005318 mBootMsgDialog.setTitle(R.string.android_upgrading_title);
5319 mBootMsgDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
5320 mBootMsgDialog.setIndeterminate(true);
5321 mBootMsgDialog.getWindow().setType(
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07005322 WindowManager.LayoutParams.TYPE_BOOT_PROGRESS);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005323 mBootMsgDialog.getWindow().addFlags(
5324 WindowManager.LayoutParams.FLAG_DIM_BEHIND
5325 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
5326 mBootMsgDialog.getWindow().setDimAmount(1);
Dianne Hackbornd9efb952011-12-07 14:56:51 -08005327 WindowManager.LayoutParams lp = mBootMsgDialog.getWindow().getAttributes();
5328 lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
5329 mBootMsgDialog.getWindow().setAttributes(lp);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005330 mBootMsgDialog.setCancelable(false);
5331 mBootMsgDialog.show();
5332 }
5333 mBootMsgDialog.setMessage(msg);
5334 }
5335 });
5336 }
5337
5338 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005339 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07005340 public void hideBootMessages() {
Craig Mautnera631d492014-08-05 15:16:01 -07005341 mHandler.sendEmptyMessage(MSG_HIDE_BOOT_MESSAGE);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005342 }
5343
Mike Lockwood28569302010-01-28 11:54:40 -05005344 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005345 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05005346 public void userActivity() {
Dianne Hackborndf89e652011-10-06 22:35:11 -07005347 // ***************************************
5348 // NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
5349 // ***************************************
5350 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
5351 // WITH ITS LOCKS HELD.
5352 //
5353 // This code must be VERY careful about the locks
5354 // it acquires.
5355 // In fact, the current code acquires way too many,
5356 // and probably has lurking deadlocks.
5357
Mike Lockwood28569302010-01-28 11:54:40 -05005358 synchronized (mScreenLockTimeout) {
5359 if (mLockScreenTimerActive) {
5360 // reset the timer
5361 mHandler.removeCallbacks(mScreenLockTimeout);
5362 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
5363 }
5364 }
Daniel Sandler0601eb72011-04-13 01:01:32 -04005365 }
5366
Adam Cohenf7522022012-10-03 20:03:18 -07005367 class ScreenLockTimeout implements Runnable {
5368 Bundle options;
5369
5370 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05005371 public void run() {
5372 synchronized (this) {
5373 if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard");
Jim Miller5ecd8112013-01-09 18:50:26 -08005374 if (mKeyguardDelegate != null) {
5375 mKeyguardDelegate.doKeyguardTimeout(options);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005376 }
Mike Lockwood28569302010-01-28 11:54:40 -05005377 mLockScreenTimerActive = false;
Adam Cohenf7522022012-10-03 20:03:18 -07005378 options = null;
Mike Lockwood28569302010-01-28 11:54:40 -05005379 }
5380 }
Mike Lockwood28569302010-01-28 11:54:40 -05005381
Adam Cohenf7522022012-10-03 20:03:18 -07005382 public void setLockOptions(Bundle options) {
5383 this.options = options;
5384 }
5385 }
5386
5387 ScreenLockTimeout mScreenLockTimeout = new ScreenLockTimeout();
5388
Jose Lima9546b202014-07-02 17:21:51 -07005389 @Override
Adam Cohenf7522022012-10-03 20:03:18 -07005390 public void lockNow(Bundle options) {
Jim Miller93c518e2012-01-17 15:55:31 -08005391 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null);
5392 mHandler.removeCallbacks(mScreenLockTimeout);
Adam Cohenf7522022012-10-03 20:03:18 -07005393 if (options != null) {
5394 // In case multiple calls are made to lockNow, we don't wipe out the options
5395 // until the runnable actually executes.
5396 mScreenLockTimeout.setLockOptions(options);
5397 }
Jim Miller93c518e2012-01-17 15:55:31 -08005398 mHandler.post(mScreenLockTimeout);
5399 }
5400
Mike Lockwood28569302010-01-28 11:54:40 -05005401 private void updateLockScreenTimeout() {
5402 synchronized (mScreenLockTimeout) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005403 boolean enable = (mAllowLockscreenWhenOn && mAwake &&
Jim Miller5ecd8112013-01-09 18:50:26 -08005404 mKeyguardDelegate != null && mKeyguardDelegate.isSecure());
Mike Lockwood28569302010-01-28 11:54:40 -05005405 if (mLockScreenTimerActive != enable) {
5406 if (enable) {
5407 if (localLOGV) Log.v(TAG, "setting lockscreen timer");
5408 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
5409 } else {
5410 if (localLOGV) Log.v(TAG, "clearing lockscreen timer");
5411 mHandler.removeCallbacks(mScreenLockTimeout);
5412 }
5413 mLockScreenTimerActive = enable;
5414 }
5415 }
5416 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005417
5418 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07005419 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005420 public void enableScreenAfterBoot() {
5421 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07005422 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07005423 updateRotation(true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005424 }
Dianne Hackbornf54c8f92009-09-19 14:03:57 -07005425
Jeff Brownc458ce92012-04-30 14:58:40 -07005426 private void applyLidSwitchState() {
Jeff Brownc458ce92012-04-30 14:58:40 -07005427 if (mLidState == LID_CLOSED && mLidControlsSleep) {
Jeff Brown6d8fd272014-05-20 21:24:38 -07005428 mPowerManager.goToSleep(SystemClock.uptimeMillis(),
Jeff Brownc12035c2014-08-13 18:52:25 -07005429 PowerManager.GO_TO_SLEEP_REASON_LID_SWITCH,
Jeff Brown6d8fd272014-05-20 21:24:38 -07005430 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
Jeff Brownc458ce92012-04-30 14:58:40 -07005431 }
Jeff Browna20dda42014-05-27 20:57:24 -07005432
5433 synchronized (mLock) {
5434 updateWakeGestureListenerLp();
5435 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005436 }
5437
Jeff Brown4f5fa282014-06-12 19:19:15 -07005438 void updateUiMode() {
5439 if (mUiModeManager == null) {
5440 mUiModeManager = IUiModeManager.Stub.asInterface(
5441 ServiceManager.getService(Context.UI_MODE_SERVICE));
5442 }
5443 try {
5444 mUiMode = mUiModeManager.getCurrentModeType();
5445 } catch (RemoteException e) {
5446 }
5447 }
5448
Jeff Brown01a98dd2011-09-20 15:08:29 -07005449 void updateRotation(boolean alwaysSendConfiguration) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005450 try {
5451 //set orientation on WindowManager
Dianne Hackbornf87d1962012-04-04 12:48:24 -07005452 mWindowManager.updateRotation(alwaysSendConfiguration, false);
5453 } catch (RemoteException e) {
5454 // Ignore
5455 }
5456 }
5457
5458 void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) {
5459 try {
5460 //set orientation on WindowManager
5461 mWindowManager.updateRotation(alwaysSendConfiguration, forceRelayout);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005462 } catch (RemoteException e) {
5463 // Ignore
5464 }
5465 }
5466
Daniel Sandler6396c722013-04-16 20:19:09 -04005467 /**
5468 * Return an Intent to launch the currently active dock app as home. Returns
5469 * null if the standard home should be launched, which is the case if any of the following is
5470 * true:
5471 * <ul>
5472 * <li>The device is not in either car mode or desk mode
5473 * <li>The device is in car mode but ENABLE_CAR_DOCK_HOME_CAPTURE is false
5474 * <li>The device is in desk mode but ENABLE_DESK_DOCK_HOME_CAPTURE is false
5475 * <li>The device is in car mode but there's no CAR_DOCK app with METADATA_DOCK_HOME
5476 * <li>The device is in desk mode but there's no DESK_DOCK app with METADATA_DOCK_HOME
5477 * </ul>
Craig Mautnereda67292013-04-28 13:50:14 -07005478 * @return A dock intent.
Daniel Sandler6396c722013-04-16 20:19:09 -04005479 */
5480 Intent createHomeDockIntent() {
5481 Intent intent = null;
5482
5483 // What home does is based on the mode, not the dock state. That
5484 // is, when in car mode you should be taken to car home regardless
5485 // of whether we are actually in a car dock.
5486 if (mUiMode == Configuration.UI_MODE_TYPE_CAR) {
5487 if (ENABLE_CAR_DOCK_HOME_CAPTURE) {
5488 intent = mCarDockIntent;
5489 }
5490 } else if (mUiMode == Configuration.UI_MODE_TYPE_DESK) {
5491 if (ENABLE_DESK_DOCK_HOME_CAPTURE) {
5492 intent = mDeskDockIntent;
5493 }
Jeff Brown4f5fa282014-06-12 19:19:15 -07005494 } else if (mUiMode == Configuration.UI_MODE_TYPE_WATCH
5495 && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
5496 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK
5497 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK)) {
5498 // Always launch dock home from home when watch is docked, if it exists.
5499 intent = mDeskDockIntent;
Daniel Sandler6396c722013-04-16 20:19:09 -04005500 }
5501
5502 if (intent == null) {
5503 return null;
5504 }
5505
5506 ActivityInfo ai = null;
5507 ResolveInfo info = mContext.getPackageManager().resolveActivityAsUser(
5508 intent,
John Spurlockf56bef12013-07-09 09:51:46 -04005509 PackageManager.MATCH_DEFAULT_ONLY | PackageManager.GET_META_DATA,
Craig Mautnerd625ab22013-09-06 13:40:31 -07005510 mCurrentUserId);
Daniel Sandler6396c722013-04-16 20:19:09 -04005511 if (info != null) {
5512 ai = info.activityInfo;
5513 }
5514 if (ai != null
5515 && ai.metaData != null
5516 && ai.metaData.getBoolean(Intent.METADATA_DOCK_HOME)) {
5517 intent = new Intent(intent);
5518 intent.setClassName(ai.packageName, ai.name);
5519 return intent;
5520 }
5521
5522 return null;
5523 }
5524
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005525 void startDockOrHome() {
John Spurlockc8b46ca2013-04-08 12:59:26 -04005526 awakenDreams();
Daniel Sandler6396c722013-04-16 20:19:09 -04005527
5528 Intent dock = createHomeDockIntent();
5529 if (dock != null) {
5530 try {
5531 mContext.startActivityAsUser(dock, UserHandle.CURRENT);
5532 return;
5533 } catch (ActivityNotFoundException e) {
5534 }
5535 }
5536
Dianne Hackbornd8883992012-09-07 15:58:52 -07005537 mContext.startActivityAsUser(mHomeIntent, UserHandle.CURRENT);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005538 }
Craig Mautnereda67292013-04-28 13:50:14 -07005539
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005540 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005541 * goes to the home screen
5542 * @return whether it did anything
5543 */
5544 boolean goHome() {
5545 if (false) {
5546 // This code always brings home to the front.
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07005547 try {
5548 ActivityManagerNative.getDefault().stopAppSwitches();
5549 } catch (RemoteException e) {
5550 }
Dianne Hackborn94a679d2009-07-28 17:51:07 -07005551 sendCloseSystemWindows();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005552 startDockOrHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005553 } else {
5554 // This code brings home to the front or, if it is already
5555 // at the front, puts the device to sleep.
5556 try {
Wink Savilled2e6a332010-02-12 12:12:06 -08005557 if (SystemProperties.getInt("persist.sys.uts-test-mode", 0) == 1) {
5558 /// Roll back EndcallBehavior as the cupcake design to pass P1 lab entry.
5559 Log.d(TAG, "UTS-TEST-MODE");
5560 } else {
5561 ActivityManagerNative.getDefault().stopAppSwitches();
5562 sendCloseSystemWindows();
Daniel Sandler6396c722013-04-16 20:19:09 -04005563 Intent dock = createHomeDockIntent();
5564 if (dock != null) {
5565 int result = ActivityManagerNative.getDefault()
5566 .startActivityAsUser(null, null, dock,
5567 dock.resolveTypeIfNeeded(mContext.getContentResolver()),
5568 null, null, 0,
5569 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07005570 null, null, UserHandle.USER_CURRENT);
Daniel Sandler6396c722013-04-16 20:19:09 -04005571 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
5572 return false;
5573 }
5574 }
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005575 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005576 int result = ActivityManagerNative.getDefault()
Dianne Hackbornf265ea92013-01-31 15:00:51 -08005577 .startActivityAsUser(null, null, mHomeIntent,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005578 mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()),
Dianne Hackborna4972e92012-03-14 10:38:05 -07005579 null, null, 0,
5580 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07005581 null, null, UserHandle.USER_CURRENT);
Dianne Hackborna4972e92012-03-14 10:38:05 -07005582 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005583 return false;
5584 }
5585 } catch (RemoteException ex) {
5586 // bummer, the activity manager, which is in this process, is dead
5587 }
5588 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005589 return true;
5590 }
Craig Mautnereda67292013-04-28 13:50:14 -07005591
5592 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07005593 public void setCurrentOrientationLw(int newOrientation) {
5594 synchronized (mLock) {
5595 if (newOrientation != mCurrentAppOrientation) {
5596 mCurrentAppOrientation = newOrientation;
5597 updateOrientationListenerLp();
5598 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005599 }
5600 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08005601
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07005602 private void performAuditoryFeedbackForAccessibilityIfNeed() {
5603 if (!isGlobalAccessibilityGestureEnabled()) {
5604 return;
5605 }
5606 AudioManager audioManager = (AudioManager) mContext.getSystemService(
5607 Context.AUDIO_SERVICE);
5608 if (audioManager.isSilentMode()) {
5609 return;
5610 }
5611 Ringtone ringTone = RingtoneManager.getRingtone(mContext,
5612 Settings.System.DEFAULT_NOTIFICATION_URI);
5613 ringTone.setStreamType(AudioManager.STREAM_MUSIC);
5614 ringTone.play();
5615 }
Craig Mautnereda67292013-04-28 13:50:14 -07005616
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07005617 private boolean isGlobalAccessibilityGestureEnabled() {
5618 return Settings.Global.getInt(mContext.getContentResolver(),
5619 Settings.Global.ENABLE_ACCESSIBILITY_GLOBAL_GESTURE_ENABLED, 0) == 1;
5620 }
5621
Craig Mautnereda67292013-04-28 13:50:14 -07005622 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07005623 public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) {
Svetoslav Ganov96179212012-10-10 14:17:45 -07005624 if (!mVibrator.hasVibrator()) {
5625 return false;
5626 }
Christopher Tate5e08af02012-09-21 17:17:22 -07005627 final boolean hapticsDisabled = Settings.System.getIntForUser(mContext.getContentResolver(),
5628 Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) == 0;
Jeff Brown82379ba2014-07-25 19:03:28 -07005629 if (hapticsDisabled && !always) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005630 return false;
5631 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08005632 long[] pattern = null;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005633 switch (effectId) {
5634 case HapticFeedbackConstants.LONG_PRESS:
Amith Yamasanic33cb712010-02-10 15:21:49 -08005635 pattern = mLongPressVibePattern;
5636 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07005637 case HapticFeedbackConstants.VIRTUAL_KEY:
Amith Yamasanic33cb712010-02-10 15:21:49 -08005638 pattern = mVirtualKeyVibePattern;
5639 break;
5640 case HapticFeedbackConstants.KEYBOARD_TAP:
5641 pattern = mKeyboardTapVibePattern;
5642 break;
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07005643 case HapticFeedbackConstants.CLOCK_TICK:
5644 pattern = mClockTickVibePattern;
5645 break;
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07005646 case HapticFeedbackConstants.CALENDAR_DATE:
5647 pattern = mCalendarDateVibePattern;
5648 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07005649 case HapticFeedbackConstants.SAFE_MODE_DISABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08005650 pattern = mSafeModeDisabledVibePattern;
5651 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07005652 case HapticFeedbackConstants.SAFE_MODE_ENABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08005653 pattern = mSafeModeEnabledVibePattern;
5654 break;
Amith Yamasanic33cb712010-02-10 15:21:49 -08005655 default:
5656 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005657 }
Dianne Hackbornf265ea92013-01-31 15:00:51 -08005658 int owningUid;
5659 String owningPackage;
5660 if (win != null) {
5661 owningUid = win.getOwningUid();
5662 owningPackage = win.getOwningPackage();
5663 } else {
5664 owningUid = android.os.Process.myUid();
Dianne Hackborn95d78532013-09-11 09:51:14 -07005665 owningPackage = mContext.getOpPackageName();
Dianne Hackbornf265ea92013-01-31 15:00:51 -08005666 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08005667 if (pattern.length == 1) {
5668 // One-shot vibration
John Spurlock7b414672014-07-18 13:02:39 -04005669 mVibrator.vibrate(owningUid, owningPackage, pattern[0], VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08005670 } else {
5671 // Pattern vibration
John Spurlock7b414672014-07-18 13:02:39 -04005672 mVibrator.vibrate(owningUid, owningPackage, pattern, -1, VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08005673 }
5674 return true;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005675 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005676
5677 @Override
5678 public void keepScreenOnStartedLw() {
Daniel Sandler0601eb72011-04-13 01:01:32 -04005679 }
5680
Jeff Brownc38c9be2012-10-04 13:16:19 -07005681 @Override
5682 public void keepScreenOnStoppedLw() {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01005683 if (mKeyguardDelegate != null && !mKeyguardDelegate.isShowingAndNotOccluded()) {
Jim Miller25190572013-02-28 17:36:24 -08005684 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005685 }
5686 }
Mike Lockwoodfcb39242009-10-21 23:01:07 -04005687
Dianne Hackborndf89e652011-10-06 22:35:11 -07005688 private int updateSystemUiVisibilityLw() {
Joe Onorato664644d2011-01-23 17:53:23 -08005689 // If there is no window focused, there will be nobody to handle the events
5690 // anyway, so just hang on in whatever state we're in until things settle down.
John Spurlock79da8332013-09-20 12:04:47 -04005691 WindowState win = mFocusedWindow != null ? mFocusedWindow : mTopFullscreenOpaqueWindowState;
5692 if (win == null) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07005693 return 0;
5694 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01005695 if ((win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 && mHideLockScreen == true) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07005696 // We are updating at a point where the keyguard has gotten
5697 // focus, but we were last in a state where the top window is
5698 // hiding it. This is probably because the keyguard as been
5699 // shown while the top window was displayed, so we want to ignore
5700 // it here because this is just a very transient change and it
5701 // will quickly lose focus once it correctly gets hidden.
5702 return 0;
5703 }
John Spurlock32beb2c2013-03-11 10:16:47 -04005704
John Spurlock1db8b682014-02-18 11:18:59 -05005705 int tmpVisibility = PolicyControl.getSystemUiVisibility(win, null)
Dianne Hackborne26ab702011-10-16 13:21:33 -07005706 & ~mResettingSystemUiFlags
5707 & ~mForceClearedSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04005708 if (mForcingShowNavBar && win.getSurfaceLayer() < mForcingShowNavBarLayer) {
John Spurlockc6d1c602014-01-17 15:22:06 -05005709 tmpVisibility &= ~PolicyControl.adjustClearableFlags(win, View.SYSTEM_UI_CLEARABLE_FLAGS);
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08005710 }
John Spurlock79da8332013-09-20 12:04:47 -04005711 final int visibility = updateSystemBarsLw(win, mLastSystemUiFlags, tmpVisibility);
John Spurlockad3e6cb2013-04-30 08:47:43 -04005712 final int diff = visibility ^ mLastSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04005713 final boolean needsMenu = win.getNeedsMenuLw(mTopFullscreenOpaqueWindowState);
Dianne Hackborne0f085d2011-11-30 18:41:15 -08005714 if (diff == 0 && mLastFocusNeedsMenu == needsMenu
John Spurlock79da8332013-09-20 12:04:47 -04005715 && mFocusedApp == win.getAppToken()) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07005716 return 0;
5717 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07005718 mLastSystemUiFlags = visibility;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08005719 mLastFocusNeedsMenu = needsMenu;
John Spurlock79da8332013-09-20 12:04:47 -04005720 mFocusedApp = win.getAppToken();
Dianne Hackborndf89e652011-10-06 22:35:11 -07005721 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07005722 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07005723 public void run() {
Dianne Hackborn42e620c2012-06-24 13:20:51 -07005724 try {
5725 IStatusBarService statusbar = getStatusBarService();
5726 if (statusbar != null) {
5727 statusbar.setSystemUiVisibility(visibility, 0xffffffff);
5728 statusbar.topAppWindowChanged(needsMenu);
Joe Onorato664644d2011-01-23 17:53:23 -08005729 }
Dianne Hackborn42e620c2012-06-24 13:20:51 -07005730 } catch (RemoteException e) {
5731 // re-acquire status bar service next time it is needed.
5732 mStatusBarService = null;
Joe Onorato664644d2011-01-23 17:53:23 -08005733 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07005734 }
5735 });
5736 return diff;
Joe Onorato664644d2011-01-23 17:53:23 -08005737 }
5738
John Spurlock79da8332013-09-20 12:04:47 -04005739 private int updateSystemBarsLw(WindowState win, int oldVis, int vis) {
John Spurlockbd957402013-10-03 11:38:39 -04005740 // apply translucent bar vis flags
Jorim Jaggi380ecb82014-03-14 17:25:20 +01005741 WindowState transWin = isStatusBarKeyguard() && !mHideLockScreen
5742 ? mStatusBar
John Spurlockbd957402013-10-03 11:38:39 -04005743 : mTopFullscreenOpaqueWindowState;
5744 vis = mStatusBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
5745 vis = mNavigationBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
5746
John Spurlock27735a42013-08-14 17:57:38 -04005747 // prevent status bar interaction from clearing certain flags
John Spurlock79da8332013-09-20 12:04:47 -04005748 boolean statusBarHasFocus = win.getAttrs().type == TYPE_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04005749 if (statusBarHasFocus && !isStatusBarKeyguard()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04005750 int flags = View.SYSTEM_UI_FLAG_FULLSCREEN
5751 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlockcfc359a2013-09-05 10:42:03 -04005752 | View.SYSTEM_UI_FLAG_IMMERSIVE
Jorim Jaggi5cf17872014-03-26 18:31:48 +01005753 | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
John Spurlock08ffcf52014-07-11 10:13:46 -04005754 if (mHideLockScreen) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01005755 flags |= View.STATUS_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSLUCENT;
5756 }
John Spurlockbd957402013-10-03 11:38:39 -04005757 vis = (vis & ~flags) | (oldVis & flags);
John Spurlockad3e6cb2013-04-30 08:47:43 -04005758 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04005759
Adrian Roos4fb3ee32014-08-22 19:29:09 +02005760 if (!areTranslucentBarsAllowed() && transWin != mStatusBar) {
Adrian Roosea562512014-05-05 13:33:03 +02005761 vis &= ~(View.NAVIGATION_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSLUCENT
5762 | View.SYSTEM_UI_TRANSPARENT);
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07005763 }
5764
John Spurlock27735a42013-08-14 17:57:38 -04005765 // update status bar
John Spurlockf1a36642013-10-12 17:50:42 -04005766 boolean immersiveSticky =
5767 (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
John Spurlock27735a42013-08-14 17:57:38 -04005768 boolean hideStatusBarWM =
John Spurlockbd957402013-10-03 11:38:39 -04005769 mTopFullscreenOpaqueWindowState != null &&
John Spurlockc6d1c602014-01-17 15:22:06 -05005770 (PolicyControl.getWindowFlags(mTopFullscreenOpaqueWindowState, null)
John Spurlock27735a42013-08-14 17:57:38 -04005771 & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0;
5772 boolean hideStatusBarSysui =
5773 (vis & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04005774 boolean hideNavBarSysui =
5775 (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0;
John Spurlockad3e6cb2013-04-30 08:47:43 -04005776
John Spurlock27735a42013-08-14 17:57:38 -04005777 boolean transientStatusBarAllowed =
5778 mStatusBar != null && (
5779 hideStatusBarWM
John Spurlockf1a36642013-10-12 17:50:42 -04005780 || (hideStatusBarSysui && immersiveSticky)
John Spurlock27735a42013-08-14 17:57:38 -04005781 || statusBarHasFocus);
5782
John Spurlockf1a36642013-10-12 17:50:42 -04005783 boolean transientNavBarAllowed =
5784 mNavigationBar != null &&
5785 hideNavBarSysui && immersiveSticky;
5786
John Spurlockf25706f2013-11-07 18:02:43 -05005787 boolean denyTransientStatus = mStatusBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04005788 && !transientStatusBarAllowed && hideStatusBarSysui;
John Spurlockf25706f2013-11-07 18:02:43 -05005789 boolean denyTransientNav = mNavigationBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04005790 && !transientNavBarAllowed;
5791 if (denyTransientStatus || denyTransientNav) {
John Spurlock27735a42013-08-14 17:57:38 -04005792 // clear the clearable flags instead
John Spurlockf1a36642013-10-12 17:50:42 -04005793 clearClearableFlagsLw();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005794 }
John Spurlock27735a42013-08-14 17:57:38 -04005795
5796 vis = mStatusBarController.updateVisibilityLw(transientStatusBarAllowed, oldVis, vis);
5797
5798 // update navigation bar
John Spurlockf1a36642013-10-12 17:50:42 -04005799 boolean oldImmersiveMode = isImmersiveMode(oldVis);
5800 boolean newImmersiveMode = isImmersiveMode(vis);
5801 if (win != null && oldImmersiveMode != newImmersiveMode) {
John Spurlock79da8332013-09-20 12:04:47 -04005802 final String pkg = win.getOwningPackage();
Maurice Lam99c6e072014-04-28 18:24:28 -07005803 mImmersiveModeConfirmation.immersiveModeChanged(pkg, newImmersiveMode,
5804 isUserSetupComplete());
John Spurlock34e13d92013-08-10 06:52:28 -04005805 }
John Spurlock27735a42013-08-14 17:57:38 -04005806
John Spurlockf1a36642013-10-12 17:50:42 -04005807 vis = mNavigationBarController.updateVisibilityLw(transientNavBarAllowed, oldVis, vis);
5808
John Spurlocke1f366f2013-08-05 12:22:40 -04005809 return vis;
John Spurlockad3e6cb2013-04-30 08:47:43 -04005810 }
5811
John Spurlockf1a36642013-10-12 17:50:42 -04005812 private void clearClearableFlagsLw() {
5813 int newVal = mResettingSystemUiFlags | View.SYSTEM_UI_CLEARABLE_FLAGS;
5814 if (newVal != mResettingSystemUiFlags) {
5815 mResettingSystemUiFlags = newVal;
5816 mWindowManagerFuncs.reevaluateStatusBarVisibility();
5817 }
5818 }
5819
5820 private boolean isImmersiveMode(int vis) {
5821 final int flags = View.SYSTEM_UI_FLAG_IMMERSIVE | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
John Spurlock34e13d92013-08-10 06:52:28 -04005822 return mNavigationBar != null
5823 && (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0
Daniel Sandler900ece52013-10-18 15:53:27 -04005824 && (vis & flags) != 0
5825 && canHideNavigationBar();
John Spurlock34e13d92013-08-10 06:52:28 -04005826 }
5827
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07005828 /**
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04005829 * @return whether the navigation or status bar can be made translucent
5830 *
5831 * This should return true unless touch exploration is not enabled or
5832 * R.boolean.config_enableTranslucentDecor is false.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07005833 */
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04005834 private boolean areTranslucentBarsAllowed() {
Svetoslav8e3feb12014-02-24 13:46:47 -08005835 return mTranslucentDecorEnabled
5836 && !mAccessibilityManager.isTouchExplorationEnabled();
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07005837 }
5838
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04005839 // Use this instead of checking config_showNavigationBar so that it can be consistently
5840 // overridden by qemu.hw.mainkeys in the emulator.
Craig Mautnereda67292013-04-28 13:50:14 -07005841 @Override
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04005842 public boolean hasNavigationBar() {
5843 return mHasNavigationBar;
5844 }
5845
satok1bc0a492012-04-25 22:47:12 +09005846 @Override
5847 public void setLastInputMethodWindowLw(WindowState ime, WindowState target) {
5848 mLastInputMethodWindow = ime;
5849 mLastInputMethodTargetWindow = target;
5850 }
5851
Craig Mautnerf1b67412012-09-19 13:18:29 -07005852 @Override
Satoshi Kataoka658c7b82013-10-10 17:03:51 +09005853 public int getInputMethodWindowVisibleHeightLw() {
5854 return mDockBottom - mCurBottom;
5855 }
5856
5857 @Override
Craig Mautnerf1b67412012-09-19 13:18:29 -07005858 public void setCurrentUserLw(int newUserId) {
Craig Mautnerd625ab22013-09-06 13:40:31 -07005859 mCurrentUserId = newUserId;
Jim Miller5ecd8112013-01-09 18:50:26 -08005860 if (mKeyguardDelegate != null) {
5861 mKeyguardDelegate.setCurrentUser(newUserId);
Craig Mautnerf1b67412012-09-19 13:18:29 -07005862 }
John Spurlock13451a22012-09-28 14:40:41 -04005863 if (mStatusBarService != null) {
5864 try {
5865 mStatusBarService.setCurrentUser(newUserId);
5866 } catch (RemoteException e) {
5867 // oh well
5868 }
5869 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07005870 setLastInputMethodWindowLw(null, null);
Craig Mautnerf1b67412012-09-19 13:18:29 -07005871 }
5872
5873 @Override
Svetoslav Ganov545252f2012-12-10 18:29:24 -08005874 public boolean canMagnifyWindow(int windowType) {
5875 switch (windowType) {
5876 case WindowManager.LayoutParams.TYPE_INPUT_METHOD:
5877 case WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG:
5878 case WindowManager.LayoutParams.TYPE_NAVIGATION_BAR:
5879 case WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY: {
5880 return false;
5881 }
5882 }
5883 return true;
5884 }
5885
5886 @Override
5887 public boolean isTopLevelWindow(int windowType) {
5888 if (windowType >= WindowManager.LayoutParams.FIRST_SUB_WINDOW
5889 && windowType <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
5890 return (windowType == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG);
5891 }
5892 return true;
5893 }
5894
Jim Miller4eeb4f62012-11-08 00:04:29 -08005895 @Override
Jeff Brownd7a04de2012-06-17 14:17:52 -07005896 public void dump(String prefix, PrintWriter pw, String[] args) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005897 pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005898 pw.print(" mSystemReady="); pw.print(mSystemReady);
5899 pw.print(" mSystemBooted="); pw.println(mSystemBooted);
Jeff Brown2e7760e2012-04-11 15:14:55 -07005900 pw.print(prefix); pw.print("mLidState="); pw.print(mLidState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005901 pw.print(" mLidOpenRotation="); pw.print(mLidOpenRotation);
Michael Wright3818c922014-09-02 13:59:07 -07005902 pw.print(" mCameraLensCoverState="); pw.print(mCameraLensCoverState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005903 pw.print(" mHdmiPlugged="); pw.println(mHdmiPlugged);
Dianne Hackborne26ab702011-10-16 13:21:33 -07005904 if (mLastSystemUiFlags != 0 || mResettingSystemUiFlags != 0
5905 || mForceClearedSystemUiFlags != 0) {
5906 pw.print(prefix); pw.print("mLastSystemUiFlags=0x");
5907 pw.print(Integer.toHexString(mLastSystemUiFlags));
5908 pw.print(" mResettingSystemUiFlags=0x");
5909 pw.print(Integer.toHexString(mResettingSystemUiFlags));
5910 pw.print(" mForceClearedSystemUiFlags=0x");
5911 pw.println(Integer.toHexString(mForceClearedSystemUiFlags));
Dianne Hackborndf89e652011-10-06 22:35:11 -07005912 }
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08005913 if (mLastFocusNeedsMenu) {
5914 pw.print(prefix); pw.print("mLastFocusNeedsMenu=");
5915 pw.println(mLastFocusNeedsMenu);
5916 }
Jeff Browna20dda42014-05-27 20:57:24 -07005917 pw.print(prefix); pw.print("mWakeGestureEnabledSetting=");
5918 pw.println(mWakeGestureEnabledSetting);
5919
Jeff Brownbcdfc622014-03-06 19:13:04 -08005920 pw.print(prefix); pw.print("mSupportAutoRotation="); pw.println(mSupportAutoRotation);
Daniel Sandler6396c722013-04-16 20:19:09 -04005921 pw.print(prefix); pw.print("mUiMode="); pw.print(mUiMode);
5922 pw.print(" mDockMode="); pw.print(mDockMode);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005923 pw.print(" mCarDockRotation="); pw.print(mCarDockRotation);
5924 pw.print(" mDeskDockRotation="); pw.println(mDeskDockRotation);
5925 pw.print(prefix); pw.print("mUserRotationMode="); pw.print(mUserRotationMode);
5926 pw.print(" mUserRotation="); pw.print(mUserRotation);
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005927 pw.print(" mAllowAllRotations="); pw.println(mAllowAllRotations);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07005928 pw.print(prefix); pw.print("mCurrentAppOrientation="); pw.println(mCurrentAppOrientation);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005929 pw.print(prefix); pw.print("mCarDockEnablesAccelerometer=");
5930 pw.print(mCarDockEnablesAccelerometer);
5931 pw.print(" mDeskDockEnablesAccelerometer=");
5932 pw.println(mDeskDockEnablesAccelerometer);
5933 pw.print(prefix); pw.print("mLidKeyboardAccessibility=");
5934 pw.print(mLidKeyboardAccessibility);
5935 pw.print(" mLidNavigationAccessibility="); pw.print(mLidNavigationAccessibility);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07005936 pw.print(" mLidControlsSleep="); pw.println(mLidControlsSleep);
Jeff Brown6d8fd272014-05-20 21:24:38 -07005937 pw.print(prefix);
5938 pw.print("mShortPressOnPowerBehavior="); pw.print(mShortPressOnPowerBehavior);
5939 pw.print(" mLongPressOnPowerBehavior="); pw.println(mLongPressOnPowerBehavior);
5940 pw.print(prefix); pw.print("mHasSoftInput="); pw.println(mHasSoftInput);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005941 pw.print(prefix); pw.print("mAwake="); pw.println(mAwake);
5942 pw.print(prefix); pw.print("mScreenOnEarly="); pw.print(mScreenOnEarly);
5943 pw.print(" mScreenOnFully="); pw.println(mScreenOnFully);
5944 pw.print(prefix); pw.print("mKeyguardDrawComplete="); pw.print(mKeyguardDrawComplete);
5945 pw.print(" mWindowManagerDrawComplete="); pw.println(mWindowManagerDrawComplete);
5946 pw.print(prefix); pw.print("mOrientationSensorEnabled=");
5947 pw.println(mOrientationSensorEnabled);
Dianne Hackbornc652de82013-02-15 16:32:56 -08005948 pw.print(prefix); pw.print("mOverscanScreen=("); pw.print(mOverscanScreenLeft);
5949 pw.print(","); pw.print(mOverscanScreenTop);
5950 pw.print(") "); pw.print(mOverscanScreenWidth);
5951 pw.print("x"); pw.println(mOverscanScreenHeight);
5952 if (mOverscanLeft != 0 || mOverscanTop != 0
5953 || mOverscanRight != 0 || mOverscanBottom != 0) {
5954 pw.print(prefix); pw.print("mOverscan left="); pw.print(mOverscanLeft);
5955 pw.print(" top="); pw.print(mOverscanTop);
5956 pw.print(" right="); pw.print(mOverscanRight);
5957 pw.print(" bottom="); pw.println(mOverscanBottom);
5958 }
Dianne Hackborn313440842013-02-19 19:22:59 -08005959 pw.print(prefix); pw.print("mRestrictedOverscanScreen=(");
5960 pw.print(mRestrictedOverscanScreenLeft);
5961 pw.print(","); pw.print(mRestrictedOverscanScreenTop);
5962 pw.print(") "); pw.print(mRestrictedOverscanScreenWidth);
5963 pw.print("x"); pw.println(mRestrictedOverscanScreenHeight);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005964 pw.print(prefix); pw.print("mUnrestrictedScreen=("); pw.print(mUnrestrictedScreenLeft);
5965 pw.print(","); pw.print(mUnrestrictedScreenTop);
5966 pw.print(") "); pw.print(mUnrestrictedScreenWidth);
5967 pw.print("x"); pw.println(mUnrestrictedScreenHeight);
5968 pw.print(prefix); pw.print("mRestrictedScreen=("); pw.print(mRestrictedScreenLeft);
5969 pw.print(","); pw.print(mRestrictedScreenTop);
5970 pw.print(") "); pw.print(mRestrictedScreenWidth);
5971 pw.print("x"); pw.println(mRestrictedScreenHeight);
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07005972 pw.print(prefix); pw.print("mStableFullscreen=("); pw.print(mStableFullscreenLeft);
5973 pw.print(","); pw.print(mStableFullscreenTop);
5974 pw.print(")-("); pw.print(mStableFullscreenRight);
5975 pw.print(","); pw.print(mStableFullscreenBottom); pw.println(")");
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07005976 pw.print(prefix); pw.print("mStable=("); pw.print(mStableLeft);
5977 pw.print(","); pw.print(mStableTop);
5978 pw.print(")-("); pw.print(mStableRight);
5979 pw.print(","); pw.print(mStableBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07005980 pw.print(prefix); pw.print("mSystem=("); pw.print(mSystemLeft);
5981 pw.print(","); pw.print(mSystemTop);
5982 pw.print(")-("); pw.print(mSystemRight);
5983 pw.print(","); pw.print(mSystemBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005984 pw.print(prefix); pw.print("mCur=("); pw.print(mCurLeft);
5985 pw.print(","); pw.print(mCurTop);
5986 pw.print(")-("); pw.print(mCurRight);
5987 pw.print(","); pw.print(mCurBottom); pw.println(")");
5988 pw.print(prefix); pw.print("mContent=("); pw.print(mContentLeft);
5989 pw.print(","); pw.print(mContentTop);
5990 pw.print(")-("); pw.print(mContentRight);
5991 pw.print(","); pw.print(mContentBottom); pw.println(")");
Dianne Hackborne30e02f2014-05-27 18:24:45 -07005992 pw.print(prefix); pw.print("mVoiceContent=("); pw.print(mVoiceContentLeft);
5993 pw.print(","); pw.print(mVoiceContentTop);
5994 pw.print(")-("); pw.print(mVoiceContentRight);
5995 pw.print(","); pw.print(mVoiceContentBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005996 pw.print(prefix); pw.print("mDock=("); pw.print(mDockLeft);
5997 pw.print(","); pw.print(mDockTop);
5998 pw.print(")-("); pw.print(mDockRight);
5999 pw.print(","); pw.print(mDockBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07006000 pw.print(prefix); pw.print("mDockLayer="); pw.print(mDockLayer);
6001 pw.print(" mStatusBarLayer="); pw.println(mStatusBarLayer);
Dianne Hackborn7ad44382012-10-18 17:46:00 -07006002 pw.print(prefix); pw.print("mShowingLockscreen="); pw.print(mShowingLockscreen);
6003 pw.print(" mShowingDream="); pw.print(mShowingDream);
6004 pw.print(" mDreamingLockscreen="); pw.println(mDreamingLockscreen);
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006005 if (mLastInputMethodWindow != null) {
6006 pw.print(prefix); pw.print("mLastInputMethodWindow=");
6007 pw.println(mLastInputMethodWindow);
6008 }
6009 if (mLastInputMethodTargetWindow != null) {
6010 pw.print(prefix); pw.print("mLastInputMethodTargetWindow=");
6011 pw.println(mLastInputMethodTargetWindow);
6012 }
6013 if (mStatusBar != null) {
6014 pw.print(prefix); pw.print("mStatusBar=");
6015 pw.println(mStatusBar);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01006016 pw.print(prefix); pw.print("isStatusBarKeyguard=");
6017 pw.print(isStatusBarKeyguard());
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006018 }
6019 if (mNavigationBar != null) {
6020 pw.print(prefix); pw.print("mNavigationBar=");
6021 pw.println(mNavigationBar);
6022 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006023 if (mFocusedWindow != null) {
6024 pw.print(prefix); pw.print("mFocusedWindow=");
6025 pw.println(mFocusedWindow);
6026 }
6027 if (mFocusedApp != null) {
6028 pw.print(prefix); pw.print("mFocusedApp=");
6029 pw.println(mFocusedApp);
6030 }
6031 if (mWinDismissingKeyguard != null) {
6032 pw.print(prefix); pw.print("mWinDismissingKeyguard=");
6033 pw.println(mWinDismissingKeyguard);
6034 }
6035 if (mTopFullscreenOpaqueWindowState != null) {
6036 pw.print(prefix); pw.print("mTopFullscreenOpaqueWindowState=");
6037 pw.println(mTopFullscreenOpaqueWindowState);
6038 }
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08006039 if (mForcingShowNavBar) {
6040 pw.print(prefix); pw.print("mForcingShowNavBar=");
6041 pw.println(mForcingShowNavBar); pw.print( "mForcingShowNavBarLayer=");
6042 pw.println(mForcingShowNavBarLayer);
6043 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07006044 pw.print(prefix); pw.print("mTopIsFullscreen="); pw.print(mTopIsFullscreen);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006045 pw.print(" mHideLockScreen="); pw.println(mHideLockScreen);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07006046 pw.print(prefix); pw.print("mForceStatusBar="); pw.print(mForceStatusBar);
6047 pw.print(" mForceStatusBarFromKeyguard=");
6048 pw.println(mForceStatusBarFromKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006049 pw.print(prefix); pw.print("mDismissKeyguard="); pw.print(mDismissKeyguard);
Craig Mautnerad09bcc2012-10-08 13:33:11 -07006050 pw.print(" mWinDismissingKeyguard="); pw.print(mWinDismissingKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006051 pw.print(" mHomePressed="); pw.println(mHomePressed);
6052 pw.print(prefix); pw.print("mAllowLockscreenWhenOn="); pw.print(mAllowLockscreenWhenOn);
6053 pw.print(" mLockScreenTimeout="); pw.print(mLockScreenTimeout);
6054 pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive);
6055 pw.print(prefix); pw.print("mEndcallBehavior="); pw.print(mEndcallBehavior);
6056 pw.print(" mIncallPowerBehavior="); pw.print(mIncallPowerBehavior);
6057 pw.print(" mLongPressOnHomeBehavior="); pw.println(mLongPressOnHomeBehavior);
6058 pw.print(prefix); pw.print("mLandscapeRotation="); pw.print(mLandscapeRotation);
6059 pw.print(" mSeascapeRotation="); pw.println(mSeascapeRotation);
6060 pw.print(prefix); pw.print("mPortraitRotation="); pw.print(mPortraitRotation);
6061 pw.print(" mUpsideDownRotation="); pw.println(mUpsideDownRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07006062 pw.print(prefix); pw.print("mDemoHdmiRotation="); pw.print(mDemoHdmiRotation);
6063 pw.print(" mDemoHdmiRotationLock="); pw.println(mDemoHdmiRotationLock);
6064 pw.print(prefix); pw.print("mUndockedHdmiRotation="); pw.println(mUndockedHdmiRotation);
Jeff Brown600f0032014-05-22 17:06:00 -07006065
Tim Kilbournd7c0c2e2014-05-29 16:08:10 -07006066 mGlobalKeyManager.dump(prefix, pw);
John Spurlock27735a42013-08-14 17:57:38 -04006067 mStatusBarController.dump(pw, prefix);
6068 mNavigationBarController.dump(pw, prefix);
John Spurlockc6d1c602014-01-17 15:22:06 -05006069 PolicyControl.dump(prefix, pw);
Jeff Brown600f0032014-05-22 17:06:00 -07006070
Jeff Browna20dda42014-05-27 20:57:24 -07006071 if (mWakeGestureListener != null) {
6072 mWakeGestureListener.dump(pw, prefix);
6073 }
Jeff Brown600f0032014-05-22 17:06:00 -07006074 if (mOrientationListener != null) {
6075 mOrientationListener.dump(pw, prefix);
6076 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006077 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006078}