blob: f58017f48cc416b13f484d07ffe283597ed04f31 [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:
1464 case TYPE_RECENTS_OVERLAY:
1465 case TYPE_SEARCH_BAR:
1466 case TYPE_STATUS_BAR:
1467 case TYPE_STATUS_BAR_PANEL:
1468 case TYPE_STATUS_BAR_SUB_PANEL:
1469 case TYPE_SYSTEM_DIALOG:
1470 case TYPE_UNIVERSE_BACKGROUND:
1471 case TYPE_VOLUME_OVERLAY:
keunyounga446bf02013-06-21 19:07:57 -07001472 case TYPE_PRIVATE_PRESENTATION:
Craig Mautner88400d32012-09-30 12:35:45 -07001473 break;
1474 }
1475
1476 // Check if third party app has set window to system window type.
1477 return mContext.checkCallingOrSelfPermission(
1478 android.Manifest.permission.INTERNAL_SYSTEM_WINDOW)
1479 != PackageManager.PERMISSION_GRANTED;
1480 }
1481
Craig Mautner967212c2013-04-13 21:10:58 -07001482 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001483 public void adjustWindowParamsLw(WindowManager.LayoutParams attrs) {
1484 switch (attrs.type) {
1485 case TYPE_SYSTEM_OVERLAY:
Jeff Brown3b2b3542010-10-15 00:54:27 -07001486 case TYPE_SECURE_SYSTEM_OVERLAY:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001487 // These types of windows can't receive input events.
1488 attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1489 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001490 attrs.flags &= ~WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001491 break;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001492 case TYPE_STATUS_BAR:
1493
1494 // If the Keyguard is in a hidden state (occluded by another window), we force to
1495 // remove the wallpaper and keyguard flag so that any change in-flight after setting
1496 // the keyguard as occluded wouldn't set these flags again.
1497 // See {@link #processKeyguardSetHiddenResultLw}.
1498 if (mKeyguardHidden) {
1499 attrs.flags &= ~WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
1500 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
1501 }
1502 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001503 }
Adrian Roos38502112014-04-09 21:04:11 +02001504
1505 if (attrs.type != TYPE_STATUS_BAR) {
1506 // The status bar is the only window allowed to exhibit keyguard behavior.
1507 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
1508 }
Adrian Roosea562512014-05-05 13:33:03 +02001509
1510 if (ActivityManager.isHighEndGfx()
1511 && (attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0) {
Adrian Roosf5e9b5c2014-09-10 15:27:41 +02001512 attrs.subtreeSystemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
Adrian Roosea562512014-05-05 13:33:03 +02001513 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
1514 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001515 }
RoboErik8a2cfc32014-05-16 11:19:38 -07001516
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001517 void readLidState() {
Jeff Brown2e7760e2012-04-11 15:14:55 -07001518 mLidState = mWindowManagerFuncs.getLidState();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001519 }
RoboErik8a2cfc32014-05-16 11:19:38 -07001520
Michael Wright3818c922014-09-02 13:59:07 -07001521 private void readCameraLensCoverState() {
1522 mCameraLensCoverState = mWindowManagerFuncs.getCameraLensCoverState();
1523 }
1524
Jeff Browndaa37532012-05-01 15:54:03 -07001525 private boolean isHidden(int accessibilityMode) {
1526 switch (accessibilityMode) {
1527 case 1:
1528 return mLidState == LID_CLOSED;
1529 case 2:
1530 return mLidState == LID_OPEN;
1531 default:
1532 return false;
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001533 }
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001534 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001535
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001536 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07001537 @Override
Jeff Browndaa37532012-05-01 15:54:03 -07001538 public void adjustConfigurationLw(Configuration config, int keyboardPresence,
1539 int navigationPresence) {
1540 mHaveBuiltInKeyboard = (keyboardPresence & PRESENCE_INTERNAL) != 0;
1541
Jeff Brownf71343d2013-05-31 17:59:11 -07001542 readConfigurationDependentBehaviors();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001543 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07001544 applyLidSwitchState();
Jeff Brownd04a88c2011-01-16 14:05:47 -08001545
Jeff Browndaa37532012-05-01 15:54:03 -07001546 if (config.keyboard == Configuration.KEYBOARD_NOKEYS
1547 || (keyboardPresence == PRESENCE_INTERNAL
1548 && isHidden(mLidKeyboardAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001549 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_YES;
Jeff Browndaa37532012-05-01 15:54:03 -07001550 if (!mHasSoftInput) {
1551 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_YES;
1552 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001553 }
1554
Jeff Browndaa37532012-05-01 15:54:03 -07001555 if (config.navigation == Configuration.NAVIGATION_NONAV
1556 || (navigationPresence == PRESENCE_INTERNAL
1557 && isHidden(mLidNavigationAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001558 config.navigationHidden = Configuration.NAVIGATIONHIDDEN_YES;
Jeff Brownd04a88c2011-01-16 14:05:47 -08001559 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001560 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001561
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001562 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07001563 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001564 public int windowTypeToLayerLw(int type) {
1565 if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001566 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001567 }
1568 switch (type) {
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001569 case TYPE_UNIVERSE_BACKGROUND:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001570 return 1;
keunyounga446bf02013-06-21 19:07:57 -07001571 case TYPE_PRIVATE_PRESENTATION:
1572 return 2;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001573 case TYPE_WALLPAPER:
1574 // wallpaper is at the bottom, though the window manager may move it.
1575 return 2;
1576 case TYPE_PHONE:
1577 return 3;
1578 case TYPE_SEARCH_BAR:
1579 return 4;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001580 case TYPE_VOICE_INTERACTION:
1581 // voice interaction layer is almost immediately above apps.
1582 return 5;
Craig Mautner88400d32012-09-30 12:35:45 -07001583 case TYPE_RECENTS_OVERLAY:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001584 case TYPE_SYSTEM_DIALOG:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001585 return 6;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001586 case TYPE_TOAST:
1587 // toasts and the plugged-in battery thing
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001588 return 7;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001589 case TYPE_PRIORITY_PHONE:
1590 // SIM errors and unlock. Not sure if this really should be in a high layer.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001591 return 8;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001592 case TYPE_DREAM:
1593 // used for Dreams (screensavers with TYPE_DREAM windows)
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001594 return 9;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001595 case TYPE_SYSTEM_ALERT:
1596 // like the ANR / app crashed dialogs
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001597 return 10;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001598 case TYPE_INPUT_METHOD:
1599 // on-screen keyboards and other such input method user interfaces go here.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001600 return 11;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001601 case TYPE_INPUT_METHOD_DIALOG:
1602 // on-screen keyboards and other such input method user interfaces go here.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001603 return 12;
Jim Miller5ecd8112013-01-09 18:50:26 -08001604 case TYPE_KEYGUARD_SCRIM:
1605 // the safety window that shows behind keyguard while keyguard is starting
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001606 return 13;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001607 case TYPE_STATUS_BAR_SUB_PANEL:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001608 return 14;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001609 case TYPE_STATUS_BAR:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001610 return 15;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001611 case TYPE_STATUS_BAR_PANEL:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001612 return 16;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001613 case TYPE_KEYGUARD_DIALOG:
1614 return 17;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001615 case TYPE_VOLUME_OVERLAY:
1616 // the on-screen volume indicator and controller shown when the user
1617 // changes the device volume
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001618 return 18;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001619 case TYPE_SYSTEM_OVERLAY:
1620 // the on-screen volume indicator and controller shown when the user
1621 // changes the device volume
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001622 return 19;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001623 case TYPE_NAVIGATION_BAR:
1624 // the navigation bar, if available, shows atop most things
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001625 return 20;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001626 case TYPE_NAVIGATION_BAR_PANEL:
1627 // some panels (e.g. search) need to show on top of the navigation bar
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001628 return 21;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001629 case TYPE_SYSTEM_ERROR:
1630 // system-level error dialogs
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001631 return 22;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001632 case TYPE_MAGNIFICATION_OVERLAY:
1633 // used to highlight the magnified portion of a display
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001634 return 23;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001635 case TYPE_DISPLAY_OVERLAY:
1636 // used to simulate secondary display devices
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001637 return 24;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001638 case TYPE_DRAG:
1639 // the drag layer: input for drag-and-drop is associated with this window,
1640 // which sits above all other focusable windows
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001641 return 25;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001642 case TYPE_SECURE_SYSTEM_OVERLAY:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001643 return 26;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001644 case TYPE_BOOT_PROGRESS:
1645 return 27;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001646 case TYPE_POINTER:
1647 // the (mouse) pointer layer
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001648 return 28;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001649 case TYPE_HIDDEN_NAV_CONSUMER:
1650 return 29;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001651 }
1652 Log.e(TAG, "Unknown window type: " + type);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001653 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001654 }
1655
1656 /** {@inheritDoc} */
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001657 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001658 public int subWindowTypeToLayerLw(int type) {
1659 switch (type) {
1660 case TYPE_APPLICATION_PANEL:
1661 case TYPE_APPLICATION_ATTACHED_DIALOG:
1662 return APPLICATION_PANEL_SUBLAYER;
1663 case TYPE_APPLICATION_MEDIA:
1664 return APPLICATION_MEDIA_SUBLAYER;
Dianne Hackborn5cb8d792009-05-21 17:34:15 -07001665 case TYPE_APPLICATION_MEDIA_OVERLAY:
1666 return APPLICATION_MEDIA_OVERLAY_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001667 case TYPE_APPLICATION_SUB_PANEL:
1668 return APPLICATION_SUB_PANEL_SUBLAYER;
1669 }
1670 Log.e(TAG, "Unknown sub-window type: " + type);
1671 return 0;
1672 }
1673
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001674 @Override
Dianne Hackbornabe0da02009-09-18 01:55:39 -07001675 public int getMaxWallpaperLayer() {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001676 return windowTypeToLayerLw(TYPE_STATUS_BAR);
Dianne Hackbornabe0da02009-09-18 01:55:39 -07001677 }
1678
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001679 @Override
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001680 public int getAboveUniverseLayer() {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001681 return windowTypeToLayerLw(TYPE_SYSTEM_ERROR);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001682 }
1683
Jose Lima9546b202014-07-02 17:21:51 -07001684 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001685 public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07001686 if (mHasNavigationBar) {
1687 // For a basic navigation bar, when we are in landscape mode we place
1688 // the navigation bar to the side.
Daniel Sandler4a066c52012-04-20 14:49:13 -04001689 if (mNavigationBarCanMove && fullWidth > fullHeight) {
1690 return fullWidth - mNavigationBarWidthForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07001691 }
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001692 }
1693 return fullWidth;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001694 }
1695
Jose Lima9546b202014-07-02 17:21:51 -07001696 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001697 public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07001698 if (mHasNavigationBar) {
1699 // For a basic navigation bar, when we are in portrait mode we place
1700 // the navigation bar to the bottom.
Daniel Sandler4a066c52012-04-20 14:49:13 -04001701 if (!mNavigationBarCanMove || fullWidth < fullHeight) {
1702 return fullHeight - mNavigationBarHeightForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07001703 }
1704 }
1705 return fullHeight;
Dianne Hackborn69cb8752011-05-19 18:13:32 -07001706 }
1707
Jose Lima9546b202014-07-02 17:21:51 -07001708 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001709 public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation) {
1710 return getNonDecorDisplayWidth(fullWidth, fullHeight, rotation);
Dianne Hackborn69cb8752011-05-19 18:13:32 -07001711 }
1712
Jose Lima9546b202014-07-02 17:21:51 -07001713 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001714 public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation) {
John Spurlock80f00c12013-06-13 11:10:51 -04001715 // There is a separate status bar at the top of the display. We don't count that as part
1716 // of the fixed decor, since it can hide; however, for purposes of configurations,
Dianne Hackborn077ee852012-04-09 16:27:07 -07001717 // we do want to exclude it since applications can't generally use that part
1718 // of the screen.
John Spurlock80f00c12013-06-13 11:10:51 -04001719 return getNonDecorDisplayHeight(fullWidth, fullHeight, rotation) - mStatusBarHeight;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001720 }
1721
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001722 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07001723 public boolean isForceHiding(WindowManager.LayoutParams attrs) {
1724 return (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 ||
Adrian Roos69e510d2014-07-13 14:57:59 +02001725 (isKeyguardHostWindow(attrs) && isKeyguardSecureIncludingHidden()) ||
1726 (attrs.type == TYPE_KEYGUARD_SCRIM);
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07001727 }
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001728
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001729 @Override
Jorim Jaggi0d674622014-05-21 01:34:15 +02001730 public boolean isKeyguardHostWindow(WindowManager.LayoutParams attrs) {
1731 return attrs.type == TYPE_STATUS_BAR;
1732 }
1733
1734 @Override
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07001735 public boolean canBeForceHidden(WindowState win, WindowManager.LayoutParams attrs) {
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001736 switch (attrs.type) {
1737 case TYPE_STATUS_BAR:
1738 case TYPE_NAVIGATION_BAR:
1739 case TYPE_WALLPAPER:
1740 case TYPE_DREAM:
1741 case TYPE_UNIVERSE_BACKGROUND:
Jim Miller5ecd8112013-01-09 18:50:26 -08001742 case TYPE_KEYGUARD_SCRIM:
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001743 return false;
1744 default:
1745 return true;
1746 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07001747 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001748
Craig Mautner7d7808f2014-09-11 18:02:38 -07001749 @Override
1750 public WindowState getWinShowWhenLockedLw() {
1751 return mWinShowWhenLocked;
1752 }
1753
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001754 /** {@inheritDoc} */
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001755 @Override
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07001756 public View addStartingWindow(IBinder appToken, String packageName, int theme,
1757 CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes,
Adam Powell04fe6eb2013-05-31 14:39:48 -07001758 int icon, int logo, int windowFlags) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001759 if (!SHOW_STARTING_ANIMATIONS) {
1760 return null;
1761 }
1762 if (packageName == null) {
1763 return null;
1764 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001765
Mathias Jeppssond1443e92012-08-24 15:25:32 +02001766 WindowManager wm = null;
1767 View view = null;
1768
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001769 try {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001770 Context context = mContext;
Craig Mautner6fbda632012-07-03 09:26:39 -07001771 if (DEBUG_STARTING_WINDOW) Slog.d(TAG, "addStartingWindow " + packageName
1772 + ": nonLocalizedLabel=" + nonLocalizedLabel + " theme="
1773 + Integer.toHexString(theme));
Dianne Hackborn247fe742011-01-08 17:25:57 -08001774 if (theme != context.getThemeResId() || labelRes != 0) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001775 try {
1776 context = context.createPackageContext(packageName, 0);
Dianne Hackborn247fe742011-01-08 17:25:57 -08001777 context.setTheme(theme);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001778 } catch (PackageManager.NameNotFoundException e) {
1779 // Ignore
1780 }
1781 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001782
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001783 Window win = PolicyManager.makeNewWindow(context);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001784 final TypedArray ta = win.getWindowStyle();
1785 if (ta.getBoolean(
1786 com.android.internal.R.styleable.Window_windowDisablePreview, false)
1787 || ta.getBoolean(
1788 com.android.internal.R.styleable.Window_windowShowWallpaper,false)) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001789 return null;
1790 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001791
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001792 Resources r = context.getResources();
1793 win.setTitle(r.getText(labelRes, nonLocalizedLabel));
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001794
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001795 win.setType(
1796 WindowManager.LayoutParams.TYPE_APPLICATION_STARTING);
1797 // Force the window flags: this is a fake window, so it is not really
1798 // touchable or focusable by the user. We also add in the ALT_FOCUSABLE_IM
1799 // flag because we do know that the next window will take input
1800 // focus, so we want to get the IME window up on top of us right away.
1801 win.setFlags(
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08001802 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001803 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
1804 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
1805 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08001806 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001807 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
1808 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
1809 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001810
Adam Powell04fe6eb2013-05-31 14:39:48 -07001811 win.setDefaultIcon(icon);
1812 win.setDefaultLogo(logo);
1813
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001814 win.setLayout(WindowManager.LayoutParams.MATCH_PARENT,
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07001815 WindowManager.LayoutParams.MATCH_PARENT);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001816
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001817 final WindowManager.LayoutParams params = win.getAttributes();
1818 params.token = appToken;
1819 params.packageName = packageName;
1820 params.windowAnimations = win.getWindowStyle().getResourceId(
1821 com.android.internal.R.styleable.Window_windowAnimationStyle, 0);
John Reck61375a82014-09-18 19:27:48 +00001822 params.privateFlags |=
1823 WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED;
Craig Mautner88400d32012-09-30 12:35:45 -07001824 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
Adam Lesinski95c42972013-10-02 10:13:27 -07001825
1826 if (!compatInfo.supportsScreen()) {
1827 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
1828 }
1829
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001830 params.setTitle("Starting " + packageName);
1831
Mathias Jeppssond1443e92012-08-24 15:25:32 +02001832 wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
1833 view = win.getDecorView();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001834
1835 if (win.isFloating()) {
1836 // Whoops, there is no way to display an animation/preview
1837 // of such a thing! After all that work... let's skip it.
1838 // (Note that we must do this here because it is in
1839 // getDecorView() where the theme is evaluated... maybe
1840 // we should peek the floating attribute from the theme
1841 // earlier.)
1842 return null;
1843 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001844
Craig Mautner6fbda632012-07-03 09:26:39 -07001845 if (DEBUG_STARTING_WINDOW) Slog.d(
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001846 TAG, "Adding starting window for " + packageName
1847 + " / " + appToken + ": "
1848 + (view.getParent() != null ? view : null));
1849
1850 wm.addView(view, params);
1851
1852 // Only return the view if it was successfully added to the
1853 // window manager... which we can tell by it having a parent.
1854 return view.getParent() != null ? view : null;
Jeff Brown98365d72012-08-19 20:30:52 -07001855 } catch (WindowManager.BadTokenException e) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001856 // ignore
Craig Mautner42bf39e2014-02-21 16:46:22 -08001857 Log.w(TAG, appToken + " already running, starting window not displayed. " +
1858 e.getMessage());
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001859 } catch (RuntimeException e) {
1860 // don't crash if something else bad happens, for example a
1861 // failure loading resources because we are loading from an app
1862 // on external storage that has been unmounted.
1863 Log.w(TAG, appToken + " failed creating starting window", e);
Mathias Jeppssond1443e92012-08-24 15:25:32 +02001864 } finally {
1865 if (view != null && view.getParent() == null) {
1866 Log.w(TAG, "view not successfully added to wm, removing view");
1867 wm.removeViewImmediate(view);
1868 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001869 }
1870
1871 return null;
1872 }
1873
1874 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07001875 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001876 public void removeStartingWindow(IBinder appToken, View window) {
Craig Mautner6fbda632012-07-03 09:26:39 -07001877 if (DEBUG_STARTING_WINDOW) {
1878 RuntimeException e = new RuntimeException("here");
1879 e.fillInStackTrace();
1880 Log.v(TAG, "Removing starting window for " + appToken + ": " + window, e);
1881 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001882
1883 if (window != null) {
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001884 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001885 wm.removeView(window);
1886 }
1887 }
1888
1889 /**
1890 * Preflight adding a window to the system.
RoboErik8a2cfc32014-05-16 11:19:38 -07001891 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001892 * Currently enforces that three window types are singletons:
1893 * <ul>
1894 * <li>STATUS_BAR_TYPE</li>
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001895 * <li>KEYGUARD_TYPE</li>
1896 * </ul>
RoboErik8a2cfc32014-05-16 11:19:38 -07001897 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001898 * @param win The window to be added
1899 * @param attrs Information about the window to be added
RoboErik8a2cfc32014-05-16 11:19:38 -07001900 *
Jeff Brown98365d72012-08-19 20:30:52 -07001901 * @return If ok, WindowManagerImpl.ADD_OKAY. If too many singletons,
1902 * WindowManagerImpl.ADD_MULTIPLE_SINGLETON
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001903 */
Jose Lima9546b202014-07-02 17:21:51 -07001904 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001905 public int prepareAddWindowLw(WindowState win, WindowManager.LayoutParams attrs) {
1906 switch (attrs.type) {
1907 case TYPE_STATUS_BAR:
Joe Onorato8bc6c512010-06-04 16:21:12 -04001908 mContext.enforceCallingOrSelfPermission(
1909 android.Manifest.permission.STATUS_BAR_SERVICE,
1910 "PhoneWindowManager");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001911 if (mStatusBar != null) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001912 if (mStatusBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07001913 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001914 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001915 }
1916 mStatusBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04001917 mStatusBarController.setWindow(win);
John Spurlock8fdfe622014-05-21 17:10:10 -04001918 mKeyguardDelegate.hideScrim();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001919 break;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04001920 case TYPE_NAVIGATION_BAR:
1921 mContext.enforceCallingOrSelfPermission(
1922 android.Manifest.permission.STATUS_BAR_SERVICE,
1923 "PhoneWindowManager");
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001924 if (mNavigationBar != null) {
1925 if (mNavigationBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07001926 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001927 }
1928 }
Daniel Sandler8956dbb2011-04-22 07:55:02 -04001929 mNavigationBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04001930 mNavigationBarController.setWindow(win);
Craig Mautnereda67292013-04-28 13:50:14 -07001931 if (DEBUG_LAYOUT) Slog.i(TAG, "NAVIGATION BAR: " + mNavigationBar);
Daniel Sandler8956dbb2011-04-22 07:55:02 -04001932 break;
Jim Millere898ac52012-04-06 17:10:57 -07001933 case TYPE_NAVIGATION_BAR_PANEL:
1934 mContext.enforceCallingOrSelfPermission(
1935 android.Manifest.permission.STATUS_BAR_SERVICE,
1936 "PhoneWindowManager");
1937 break;
Dianne Hackborn08743722009-12-21 12:16:51 -08001938 case TYPE_STATUS_BAR_PANEL:
Joe Onorato8bc6c512010-06-04 16:21:12 -04001939 mContext.enforceCallingOrSelfPermission(
1940 android.Manifest.permission.STATUS_BAR_SERVICE,
1941 "PhoneWindowManager");
Dianne Hackborn08743722009-12-21 12:16:51 -08001942 break;
Joe Onorato29fc2c92010-11-24 10:26:50 -08001943 case TYPE_STATUS_BAR_SUB_PANEL:
1944 mContext.enforceCallingOrSelfPermission(
1945 android.Manifest.permission.STATUS_BAR_SERVICE,
1946 "PhoneWindowManager");
Joe Onorato29fc2c92010-11-24 10:26:50 -08001947 break;
Jim Miller5ecd8112013-01-09 18:50:26 -08001948 case TYPE_KEYGUARD_SCRIM:
Jim Miller25190572013-02-28 17:36:24 -08001949 if (mKeyguardScrim != null) {
1950 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
1951 }
Jim Miller5ecd8112013-01-09 18:50:26 -08001952 mKeyguardScrim = win;
1953 break;
1954
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001955 }
Jeff Brown98365d72012-08-19 20:30:52 -07001956 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001957 }
1958
1959 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07001960 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001961 public void removeWindowLw(WindowState win) {
1962 if (mStatusBar == win) {
1963 mStatusBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04001964 mStatusBarController.setWindow(null);
Jim Millerc0b676d2013-03-22 16:11:08 -07001965 mKeyguardDelegate.showScrim();
Jim Miller5ecd8112013-01-09 18:50:26 -08001966 } else if (mKeyguardScrim == win) {
1967 Log.v(TAG, "Removing keyguard scrim");
1968 mKeyguardScrim = null;
1969 } if (mNavigationBar == win) {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04001970 mNavigationBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04001971 mNavigationBarController.setWindow(null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001972 }
1973 }
1974
1975 static final boolean PRINT_ANIM = false;
RoboErik8a2cfc32014-05-16 11:19:38 -07001976
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001977 /** {@inheritDoc} */
Craig Mautner4b71aa12012-12-27 17:20:01 -08001978 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001979 public int selectAnimationLw(WindowState win, int transit) {
1980 if (PRINT_ANIM) Log.i(TAG, "selectAnimation in " + win
1981 + ": transit=" + transit);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001982 if (win == mStatusBar) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001983 boolean isKeyguard = (win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001984 if (transit == TRANSIT_EXIT
1985 || transit == TRANSIT_HIDE) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001986 return isKeyguard ? -1 : R.anim.dock_top_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001987 } else if (transit == TRANSIT_ENTER
1988 || transit == TRANSIT_SHOW) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001989 return isKeyguard ? -1 : R.anim.dock_top_enter;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001990 }
1991 } else if (win == mNavigationBar) {
1992 // This can be on either the bottom or the right.
1993 if (mNavigationBarOnBottom) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08001994 if (transit == TRANSIT_EXIT
1995 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001996 return R.anim.dock_bottom_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001997 } else if (transit == TRANSIT_ENTER
1998 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001999 return R.anim.dock_bottom_enter;
2000 }
2001 } else {
Craig Mautner4b71aa12012-12-27 17:20:01 -08002002 if (transit == TRANSIT_EXIT
2003 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002004 return R.anim.dock_right_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002005 } else if (transit == TRANSIT_ENTER
2006 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002007 return R.anim.dock_right_enter;
2008 }
2009 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08002010 }
2011
2012 if (transit == TRANSIT_PREVIEW_DONE) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002013 if (win.hasAppShownWindows()) {
2014 if (PRINT_ANIM) Log.i(TAG, "**** STARTING EXIT");
2015 return com.android.internal.R.anim.app_starting_exit;
2016 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07002017 } else if (win.getAttrs().type == TYPE_DREAM && mDreamingLockscreen
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002018 && transit == TRANSIT_ENTER) {
2019 // Special case: we are animating in a dream, while the keyguard
2020 // is shown. We don't want an animation on the dream, because
2021 // we need it shown immediately with the keyguard animating away
2022 // to reveal it.
2023 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002024 }
2025
2026 return 0;
2027 }
2028
Craig Mautner3c174372013-02-21 17:54:37 -08002029 @Override
2030 public void selectRotationAnimationLw(int anim[]) {
2031 if (PRINT_ANIM) Slog.i(TAG, "selectRotationAnimation mTopFullscreen="
2032 + mTopFullscreenOpaqueWindowState + " rotationAnimation="
2033 + (mTopFullscreenOpaqueWindowState == null ?
2034 "0" : mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation));
2035 if (mTopFullscreenOpaqueWindowState != null && mTopIsFullscreen) {
2036 switch (mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation) {
2037 case ROTATION_ANIMATION_CROSSFADE:
2038 anim[0] = R.anim.rotation_animation_xfade_exit;
2039 anim[1] = R.anim.rotation_animation_enter;
2040 break;
2041 case ROTATION_ANIMATION_JUMPCUT:
2042 anim[0] = R.anim.rotation_animation_jump_exit;
2043 anim[1] = R.anim.rotation_animation_enter;
2044 break;
2045 case ROTATION_ANIMATION_ROTATE:
2046 default:
2047 anim[0] = anim[1] = 0;
2048 break;
2049 }
2050 } else {
2051 anim[0] = anim[1] = 0;
2052 }
2053 }
2054
2055 @Override
2056 public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId,
2057 boolean forceDefault) {
2058 switch (exitAnimId) {
2059 case R.anim.rotation_animation_xfade_exit:
2060 case R.anim.rotation_animation_jump_exit:
2061 // These are the only cases that matter.
2062 if (forceDefault) {
2063 return false;
2064 }
2065 int anim[] = new int[2];
2066 selectRotationAnimationLw(anim);
2067 return (exitAnimId == anim[0] && enterAnimId == anim[1]);
2068 default:
2069 return true;
2070 }
2071 }
2072
2073 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002074 public Animation createForceHideEnterAnimation(boolean onWallpaper,
2075 boolean goingToNotificationShade) {
2076 if (goingToNotificationShade) {
2077 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_behind_enter_fade_in);
2078 } else if (onWallpaper) {
Jorim Jaggi76a16232014-08-08 17:00:47 +02002079 Animation a = AnimationUtils.loadAnimation(mContext,
2080 R.anim.lock_screen_behind_enter_wallpaper);
2081 AnimationSet set = (AnimationSet) a;
2082
2083 // TODO: Use XML interpolators when we have log interpolators available in XML.
2084 set.getAnimations().get(0).setInterpolator(mLogDecelerateInterpolator);
2085 set.getAnimations().get(1).setInterpolator(mLogDecelerateInterpolator);
Jorim Jaggi76a16232014-08-08 17:00:47 +02002086 return set;
2087 } else {
2088 Animation a = AnimationUtils.loadAnimation(mContext,
2089 R.anim.lock_screen_behind_enter);
2090 AnimationSet set = (AnimationSet) a;
2091
2092 // TODO: Use XML interpolators when we have log interpolators available in XML.
2093 set.getAnimations().get(0).setInterpolator(mLogDecelerateInterpolator);
2094 return set;
2095 }
2096 }
2097
2098
2099 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002100 public Animation createForceHideWallpaperExitAnimation(boolean goingToNotificationShade) {
2101 if (goingToNotificationShade) {
2102 return null;
2103 } else {
2104 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_wallpaper_exit);
2105 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002106 }
John Spurlockc8b46ca2013-04-08 12:59:26 -04002107
2108 private static void awakenDreams() {
2109 IDreamManager dreamManager = getDreamManager();
2110 if (dreamManager != null) {
2111 try {
2112 dreamManager.awaken();
2113 } catch (RemoteException e) {
2114 // fine, stay asleep then
2115 }
2116 }
2117 }
2118
2119 static IDreamManager getDreamManager() {
2120 return IDreamManager.Stub.asInterface(
2121 ServiceManager.checkService(DreamService.DREAM_SERVICE));
2122 }
2123
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002124 TelecomManager getTelecommService() {
2125 return (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002126 }
2127
Jeff Brown4d396052010-10-29 21:50:21 -07002128 static IAudioService getAudioService() {
2129 IAudioService audioService = IAudioService.Stub.asInterface(
2130 ServiceManager.checkService(Context.AUDIO_SERVICE));
2131 if (audioService == null) {
2132 Log.w(TAG, "Unable to find IAudioService interface.");
2133 }
2134 return audioService;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002135 }
2136
2137 boolean keyguardOn() {
2138 return keyguardIsShowingTq() || inKeyguardRestrictedKeyInputMode();
2139 }
2140
2141 private static final int[] WINDOW_TYPES_WHERE_HOME_DOESNT_WORK = {
2142 WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
2143 WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
2144 };
2145
2146 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002147 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002148 public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002149 final boolean keyguardOn = keyguardOn();
Jeff Brown1f245102010-11-18 20:53:46 -08002150 final int keyCode = event.getKeyCode();
2151 final int repeatCount = event.getRepeatCount();
2152 final int metaState = event.getMetaState();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002153 final int flags = event.getFlags();
Jeff Brown1f245102010-11-18 20:53:46 -08002154 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
2155 final boolean canceled = event.isCanceled();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002156
Jeff Brown40013652012-05-16 21:22:36 -07002157 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002158 Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount="
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002159 + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed
2160 + " canceled=" + canceled);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002161 }
2162
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002163 // If we think we might have a volume down & power key chord on the way
2164 // but we're not sure, then tell the dispatcher to wait a little while and
2165 // try again later before dispatching.
Christopher Tatee90585f2012-03-05 18:56:25 -08002166 if (mScreenshotChordEnabled && (flags & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002167 if (mVolumeDownKeyTriggered && !mPowerKeyTriggered) {
2168 final long now = SystemClock.uptimeMillis();
2169 final long timeoutTime = mVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS;
2170 if (now < timeoutTime) {
2171 return timeoutTime - now;
2172 }
2173 }
2174 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
2175 && mVolumeDownKeyConsumedByScreenshotChord) {
2176 if (!down) {
2177 mVolumeDownKeyConsumedByScreenshotChord = false;
2178 }
2179 return -1;
2180 }
2181 }
2182
Michael Wright6a62e552014-06-03 19:19:48 -07002183 // Cancel any pending meta actions if we see any other keys being pressed between the down
2184 // of the meta key and its corresponding up.
Michael Wright251e35d2014-08-22 15:40:27 -07002185 if (mPendingMetaAction && !KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07002186 mPendingMetaAction = false;
2187 }
2188
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002189 // First we always handle the home key here, so applications
2190 // can never break it, although if keyguard is on, we do let
2191 // it handle it, because that gives us the correct 5 second
2192 // timeout.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002193 if (keyCode == KeyEvent.KEYCODE_HOME) {
Michael Jurka7f2668c2012-03-27 07:49:52 -07002194
Jeff Brown49ed71d2010-12-06 17:13:33 -08002195 // If we have released the home key, and didn't do anything else
2196 // while it was pressed, then it is time to go home!
Michael Jurka7f2668c2012-03-27 07:49:52 -07002197 if (!down) {
Jeff Browncaca8812013-05-09 13:34:33 -07002198 cancelPreloadRecentApps();
2199
Jeff Brown49ed71d2010-12-06 17:13:33 -08002200 mHomePressed = false;
Jeff Browncaca8812013-05-09 13:34:33 -07002201 if (mHomeConsumed) {
2202 mHomeConsumed = false;
Michael Jurka7f2668c2012-03-27 07:49:52 -07002203 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002204 }
Jeff Browncaca8812013-05-09 13:34:33 -07002205
2206 if (canceled) {
2207 Log.i(TAG, "Ignoring HOME; event canceled.");
2208 return -1;
2209 }
2210
2211 // If an incoming call is ringing, HOME is totally disabled.
Santos Cordon9eb45932014-06-27 12:28:43 -07002212 // (The user is already on the InCallUI at this point,
Jeff Browncaca8812013-05-09 13:34:33 -07002213 // and his ONLY options are to answer or reject the call.)
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002214 TelecomManager telecomManager = getTelecommService();
2215 if (telecomManager != null && telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07002216 Log.i(TAG, "Ignoring HOME; there's a ringing incoming call.");
2217 return -1;
Jeff Browncaca8812013-05-09 13:34:33 -07002218 }
2219
2220 // Delay handling home if a double-tap is possible.
2221 if (mDoubleTapOnHomeBehavior != DOUBLE_TAP_HOME_NOTHING) {
2222 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); // just in case
2223 mHomeDoubleTapPending = true;
2224 mHandler.postDelayed(mHomeDoubleTapTimeoutRunnable,
2225 ViewConfiguration.getDoubleTapTimeout());
2226 return -1;
2227 }
2228
Jose Lima9546b202014-07-02 17:21:51 -07002229 // If there's a dream running then use home to escape the dream
2230 // but don't actually go home.
2231 if (mDreamManagerInternal != null && mDreamManagerInternal.isDreaming()) {
Jeff Brownf6d46682014-07-17 22:44:20 -07002232 mDreamManagerInternal.stopDream(false /*immediate*/);
Jose Lima9546b202014-07-02 17:21:51 -07002233 return -1;
2234 }
2235
Jeff Browncaca8812013-05-09 13:34:33 -07002236 // Go home!
2237 launchHomeFromHotKey();
2238 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002239 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002240
2241 // If a system window has focus, then it doesn't make sense
2242 // right now to interact with applications.
2243 WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null;
2244 if (attrs != null) {
2245 final int type = attrs.type;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002246 if (type == WindowManager.LayoutParams.TYPE_KEYGUARD_SCRIM
2247 || type == WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG
2248 || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002249 // the "app" is keyguard, so give it the key
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002250 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002251 }
2252 final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length;
2253 for (int i=0; i<typeCount; i++) {
2254 if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) {
2255 // don't do anything, but also don't pass it to the app
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002256 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002257 }
2258 }
2259 }
Jeff Browncaca8812013-05-09 13:34:33 -07002260
2261 // Remember that home is pressed and handle special actions.
2262 if (repeatCount == 0) {
2263 mHomePressed = true;
2264 if (mHomeDoubleTapPending) {
2265 mHomeDoubleTapPending = false;
2266 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable);
2267 handleDoubleTapOnHome();
2268 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI
2269 || mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
2270 preloadRecentApps();
Michael Jurka7f2668c2012-03-27 07:49:52 -07002271 }
Jeff Browncaca8812013-05-09 13:34:33 -07002272 } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) {
2273 if (!keyguardOn) {
2274 handleLongPressOnHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002275 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002276 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002277 return -1;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002278 } else if (keyCode == KeyEvent.KEYCODE_MENU) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002279 // Hijack modified menu keys for debugging features
2280 final int chordBug = KeyEvent.META_SHIFT_ON;
2281
2282 if (down && repeatCount == 0) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002283 if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002284 Intent intent = new Intent(Intent.ACTION_BUG_REPORT);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002285 mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT,
2286 null, null, null, 0, null, null);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002287 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002288 } else if (SHOW_PROCESSES_ON_ALT_MENU &&
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002289 (metaState & KeyEvent.META_ALT_ON) == KeyEvent.META_ALT_ON) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002290 Intent service = new Intent();
2291 service.setClassName(mContext, "com.android.server.LoadAverageService");
2292 ContentResolver res = mContext.getContentResolver();
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002293 boolean shown = Settings.Global.getInt(
2294 res, Settings.Global.SHOW_PROCESSES, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002295 if (!shown) {
2296 mContext.startService(service);
2297 } else {
2298 mContext.stopService(service);
2299 }
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002300 Settings.Global.putInt(
2301 res, Settings.Global.SHOW_PROCESSES, shown ? 0 : 1);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002302 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002303 }
2304 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002305 } else if (keyCode == KeyEvent.KEYCODE_SEARCH) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002306 if (down) {
2307 if (repeatCount == 0) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002308 mSearchKeyShortcutPending = true;
2309 mConsumeSearchKeyUp = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002310 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002311 } else {
2312 mSearchKeyShortcutPending = false;
2313 if (mConsumeSearchKeyUp) {
2314 mConsumeSearchKeyUp = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002315 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002316 }
2317 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002318 return 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002319 } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) {
Michael Wrightc9ebea72013-01-16 19:25:02 -08002320 if (!keyguardOn) {
Jeff Browncaca8812013-05-09 13:34:33 -07002321 if (down && repeatCount == 0) {
2322 preloadRecentApps();
2323 } else if (!down) {
2324 toggleRecentApps();
Michael Wrightc9ebea72013-01-16 19:25:02 -08002325 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002326 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002327 return -1;
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002328 } else if (keyCode == KeyEvent.KEYCODE_ASSIST) {
2329 if (down) {
2330 if (repeatCount == 0) {
2331 mAssistKeyLongPressed = false;
2332 } else if (repeatCount == 1) {
2333 mAssistKeyLongPressed = true;
2334 if (!keyguardOn) {
2335 launchAssistLongPressAction();
2336 }
2337 }
2338 } else {
2339 if (mAssistKeyLongPressed) {
2340 mAssistKeyLongPressed = false;
2341 } else {
2342 if (!keyguardOn) {
2343 launchAssistAction();
2344 }
2345 }
2346 }
2347 return -1;
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002348 } else if (keyCode == KeyEvent.KEYCODE_VOICE_ASSIST) {
2349 if (!down) {
2350 Intent voiceIntent;
Michael Wright869a67c2014-08-26 19:33:06 -07002351 if (!keyguardOn) {
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002352 voiceIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
2353 } else {
2354 voiceIntent = new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
Michael Wright869a67c2014-08-26 19:33:06 -07002355 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, true);
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002356 }
2357 mContext.startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
2358 }
Jeff Sharkey2991fa32012-12-05 18:06:43 -08002359 } else if (keyCode == KeyEvent.KEYCODE_SYSRQ) {
2360 if (down && repeatCount == 0) {
2361 mHandler.post(mScreenshotRunnable);
2362 }
2363 return -1;
Michael Wrightb854e242013-02-05 17:54:02 -08002364 } else if (keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP
2365 || keyCode == KeyEvent.KEYCODE_BRIGHTNESS_DOWN) {
2366 if (down) {
2367 int direction = keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP ? 1 : -1;
2368
2369 // Disable autobrightness if it's on
2370 int auto = Settings.System.getIntForUser(
2371 mContext.getContentResolver(),
2372 Settings.System.SCREEN_BRIGHTNESS_MODE,
2373 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2374 UserHandle.USER_CURRENT_OR_SELF);
2375 if (auto != 0) {
2376 Settings.System.putIntForUser(mContext.getContentResolver(),
2377 Settings.System.SCREEN_BRIGHTNESS_MODE,
2378 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2379 UserHandle.USER_CURRENT_OR_SELF);
2380 }
2381
2382 int min = mPowerManager.getMinimumScreenBrightnessSetting();
2383 int max = mPowerManager.getMaximumScreenBrightnessSetting();
2384 int step = (max - min + BRIGHTNESS_STEPS - 1) / BRIGHTNESS_STEPS * direction;
2385 int brightness = Settings.System.getIntForUser(mContext.getContentResolver(),
2386 Settings.System.SCREEN_BRIGHTNESS,
2387 mPowerManager.getDefaultScreenBrightnessSetting(),
2388 UserHandle.USER_CURRENT_OR_SELF);
2389 brightness += step;
2390 // Make sure we don't go beyond the limits.
2391 brightness = Math.min(max, brightness);
2392 brightness = Math.max(min, brightness);
2393
2394 Settings.System.putIntForUser(mContext.getContentResolver(),
2395 Settings.System.SCREEN_BRIGHTNESS, brightness,
2396 UserHandle.USER_CURRENT_OR_SELF);
Alan Viverette5a399492014-07-14 16:19:38 -07002397 mContext.startActivityAsUser(new Intent(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG),
2398 UserHandle.CURRENT_OR_SELF);
Michael Wrightb854e242013-02-05 17:54:02 -08002399 }
2400 return -1;
Michael Wrightce0c13a2014-07-30 10:49:21 -07002401 } else if (KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07002402 if (down) {
2403 mPendingMetaAction = true;
2404 } else if (mPendingMetaAction) {
Michael Wright8ab940a2014-09-01 11:01:27 -07002405 launchAssistAction(Intent.EXTRA_ASSIST_INPUT_HINT_KEYBOARD);
Michael Wright6a62e552014-06-03 19:19:48 -07002406 }
2407 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002408 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002409
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002410 // Shortcuts are invoked through Search+key, so intercept those here
Jeff Browncaab4d02010-12-09 22:13:41 -08002411 // Any printing key that is chorded with Search should be consumed
2412 // even if no shortcut was invoked. This prevents text from being
2413 // inadvertently inserted when using a keyboard that has built-in macro
2414 // shortcut keys (that emit Search+x) and some of them are not registered.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002415 if (mSearchKeyShortcutPending) {
Jeff Browncaab4d02010-12-09 22:13:41 -08002416 final KeyCharacterMap kcm = event.getKeyCharacterMap();
2417 if (kcm.isPrintingKey(keyCode)) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002418 mConsumeSearchKeyUp = true;
2419 mSearchKeyShortcutPending = false;
Jeff Browncaab4d02010-12-09 22:13:41 -08002420 if (down && repeatCount == 0 && !keyguardOn) {
2421 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState);
2422 if (shortcutIntent != null) {
2423 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002424 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002425 mContext.startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002426 } catch (ActivityNotFoundException ex) {
2427 Slog.w(TAG, "Dropping shortcut key combination because "
2428 + "the activity to which it is registered was not found: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002429 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode), ex);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002430 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002431 } else {
2432 Slog.i(TAG, "Dropping unregistered shortcut key combination: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002433 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002434 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002435 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002436 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002437 }
2438 }
2439
Jeff Brown68b909d2011-12-07 16:36:01 -08002440 // Invoke shortcuts using Meta.
Jeff Brown602ab322012-05-16 13:33:47 -07002441 if (down && repeatCount == 0 && !keyguardOn
Jeff Brown68b909d2011-12-07 16:36:01 -08002442 && (metaState & KeyEvent.META_META_ON) != 0) {
2443 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brown602ab322012-05-16 13:33:47 -07002444 if (kcm.isPrintingKey(keyCode)) {
2445 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode,
2446 metaState & ~(KeyEvent.META_META_ON
2447 | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON));
2448 if (shortcutIntent != null) {
2449 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2450 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002451 mContext.startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brown602ab322012-05-16 13:33:47 -07002452 } catch (ActivityNotFoundException ex) {
2453 Slog.w(TAG, "Dropping shortcut key combination because "
2454 + "the activity to which it is registered was not found: "
2455 + "META+" + KeyEvent.keyCodeToString(keyCode), ex);
2456 }
2457 return -1;
Jeff Brown68b909d2011-12-07 16:36:01 -08002458 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002459 }
2460 }
2461
Jeff Brown6651a632011-11-28 12:59:11 -08002462 // Handle application launch keys.
Jeff Brown602ab322012-05-16 13:33:47 -07002463 if (down && repeatCount == 0 && !keyguardOn) {
Jeff Brown6651a632011-11-28 12:59:11 -08002464 String category = sApplicationLaunchKeyCategories.get(keyCode);
2465 if (category != null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -08002466 Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category);
Jeff Brown6651a632011-11-28 12:59:11 -08002467 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2468 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002469 mContext.startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brown6651a632011-11-28 12:59:11 -08002470 } catch (ActivityNotFoundException ex) {
2471 Slog.w(TAG, "Dropping application launch key because "
2472 + "the activity to which it is registered was not found: "
2473 + "keyCode=" + keyCode + ", category=" + category, ex);
2474 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002475 return -1;
Jeff Brown6651a632011-11-28 12:59:11 -08002476 }
2477 }
2478
Michael Wright61c46752014-08-21 16:57:33 -07002479 // Display task switcher for ALT-TAB.
Jeff Brown68b909d2011-12-07 16:36:01 -08002480 if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_TAB) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002481 if (mRecentAppsHeldModifiers == 0 && !keyguardOn) {
Jeff Brown68b909d2011-12-07 16:36:01 -08002482 final int shiftlessModifiers = event.getModifiers() & ~KeyEvent.META_SHIFT_MASK;
Michael Wright61c46752014-08-21 16:57:33 -07002483 if (KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_ALT_ON)) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002484 mRecentAppsHeldModifiers = shiftlessModifiers;
2485 showRecentApps(true);
Jeff Brown68b909d2011-12-07 16:36:01 -08002486 return -1;
2487 }
2488 }
Winson Chung1e8d71b2014-05-16 17:05:22 -07002489 } else if (!down && mRecentAppsHeldModifiers != 0
2490 && (metaState & mRecentAppsHeldModifiers) == 0) {
2491 mRecentAppsHeldModifiers = 0;
Winson Chungcdcd4872014-08-05 18:00:13 -07002492 hideRecentApps(true, false);
Jeff Brown68b909d2011-12-07 16:36:01 -08002493 }
2494
Jeff Browncf39bdf2012-05-18 14:41:19 -07002495 // Handle keyboard language switching.
2496 if (down && repeatCount == 0
2497 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2498 || (keyCode == KeyEvent.KEYCODE_SPACE
2499 && (metaState & KeyEvent.META_CTRL_MASK) != 0))) {
2500 int direction = (metaState & KeyEvent.META_SHIFT_MASK) != 0 ? -1 : 1;
2501 mWindowManagerFuncs.switchKeyboardLayout(event.getDeviceId(), direction);
2502 return -1;
2503 }
2504 if (mLanguageSwitchKeyPressed && !down
2505 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2506 || keyCode == KeyEvent.KEYCODE_SPACE)) {
2507 mLanguageSwitchKeyPressed = false;
2508 return -1;
2509 }
2510
Justin Kohd378ad72013-04-01 12:18:26 -07002511 if (mGlobalKeyManager.handleGlobalKey(mContext, keyCode, event)) {
2512 return -1;
2513 }
2514
Michael Wright6a62e552014-06-03 19:19:48 -07002515 // Reserve all the META modifier combos for system behavior
Michael Wrightce0c13a2014-07-30 10:49:21 -07002516 if ((metaState & KeyEvent.META_META_ON) != 0) {
Michael Wright6a62e552014-06-03 19:19:48 -07002517 return -1;
2518 }
2519
Jeff Brown68b909d2011-12-07 16:36:01 -08002520 // Let the application handle the key.
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002521 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002522 }
2523
Jeff Brown3915bb82010-11-05 15:02:16 -07002524 /** {@inheritDoc} */
2525 @Override
Jeff Brown49ed71d2010-12-06 17:13:33 -08002526 public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown54875002011-04-06 15:33:01 -07002527 // Note: This method is only called if the initial down was unhandled.
Jeff Brown40013652012-05-16 21:22:36 -07002528 if (DEBUG_INPUT) {
Jeff Brown1f245102010-11-18 20:53:46 -08002529 Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction()
2530 + ", flags=" + event.getFlags()
2531 + ", keyCode=" + event.getKeyCode()
2532 + ", scanCode=" + event.getScanCode()
2533 + ", metaState=" + event.getMetaState()
2534 + ", repeatCount=" + event.getRepeatCount()
2535 + ", policyFlags=" + policyFlags);
Jeff Brown3915bb82010-11-05 15:02:16 -07002536 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002537
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002538 KeyEvent fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002539 if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
2540 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002541 final int keyCode = event.getKeyCode();
2542 final int metaState = event.getMetaState();
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002543 final boolean initialDown = event.getAction() == KeyEvent.ACTION_DOWN
2544 && event.getRepeatCount() == 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002545
Jeff Brown54875002011-04-06 15:33:01 -07002546 // Check for fallback actions specified by the key character map.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002547 final FallbackAction fallbackAction;
2548 if (initialDown) {
2549 fallbackAction = kcm.getFallbackAction(keyCode, metaState);
2550 } else {
2551 fallbackAction = mFallbackActions.get(keyCode);
2552 }
2553
2554 if (fallbackAction != null) {
Jeff Brown40013652012-05-16 21:22:36 -07002555 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002556 Slog.d(TAG, "Fallback: keyCode=" + fallbackAction.keyCode
2557 + " metaState=" + Integer.toHexString(fallbackAction.metaState));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002558 }
2559
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002560 final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK;
2561 fallbackEvent = KeyEvent.obtain(
Jeff Brown49ed71d2010-12-06 17:13:33 -08002562 event.getDownTime(), event.getEventTime(),
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002563 event.getAction(), fallbackAction.keyCode,
2564 event.getRepeatCount(), fallbackAction.metaState,
Jeff Brown49ed71d2010-12-06 17:13:33 -08002565 event.getDeviceId(), event.getScanCode(),
2566 flags, event.getSource(), null);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002567
2568 if (!interceptFallback(win, fallbackEvent, policyFlags)) {
2569 fallbackEvent.recycle();
2570 fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002571 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002572
2573 if (initialDown) {
2574 mFallbackActions.put(keyCode, fallbackAction);
2575 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2576 mFallbackActions.remove(keyCode);
2577 fallbackAction.recycle();
2578 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002579 }
2580 }
2581
Jeff Brown40013652012-05-16 21:22:36 -07002582 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002583 if (fallbackEvent == null) {
2584 Slog.d(TAG, "No fallback.");
2585 } else {
2586 Slog.d(TAG, "Performing fallback: " + fallbackEvent);
2587 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002588 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002589 return fallbackEvent;
Jeff Brown3915bb82010-11-05 15:02:16 -07002590 }
2591
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002592 private boolean interceptFallback(WindowState win, KeyEvent fallbackEvent, int policyFlags) {
Jeff Brown037c33e2014-04-09 00:31:55 -07002593 int actions = interceptKeyBeforeQueueing(fallbackEvent, policyFlags);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002594 if ((actions & ACTION_PASS_TO_USER) != 0) {
2595 long delayMillis = interceptKeyBeforeDispatching(
2596 win, fallbackEvent, policyFlags);
2597 if (delayMillis == 0) {
2598 return true;
2599 }
2600 }
2601 return false;
Jeff Brown6f2fba42011-02-19 01:08:02 -08002602 }
2603
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002604 private void launchAssistLongPressAction() {
2605 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
2606 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
2607
2608 // launch the search activity
2609 Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS);
2610 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2611 try {
RoboErik8a2cfc32014-05-16 11:19:38 -07002612 // TODO: This only stops the factory-installed search manager.
Jim Miller45308b12012-06-18 19:23:39 -07002613 // Need to formalize an API to handle others
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002614 SearchManager searchManager = getSearchManager();
2615 if (searchManager != null) {
2616 searchManager.stopSearch();
2617 }
Michael Wright43e27f72013-04-10 14:06:48 -07002618 mContext.startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002619 } catch (ActivityNotFoundException e) {
2620 Slog.w(TAG, "No activity to handle assist long press action.", e);
2621 }
2622 }
2623
2624 private void launchAssistAction() {
Michael Wright8ab940a2014-09-01 11:01:27 -07002625 launchAssistAction(null);
2626 }
2627
2628 private void launchAssistAction(String hint) {
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002629 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
Amith Yamasanic1d07a42012-08-14 09:32:02 -07002630 Intent intent = ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE))
Dianne Hackbornf9c5e0f2013-01-23 14:39:13 -08002631 .getAssistIntent(mContext, true, UserHandle.USER_CURRENT);
Jim Miller45308b12012-06-18 19:23:39 -07002632 if (intent != null) {
Michael Wright8ab940a2014-09-01 11:01:27 -07002633 if (hint != null) {
2634 intent.putExtra(hint, true);
2635 }
Jim Miller45308b12012-06-18 19:23:39 -07002636 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
2637 | Intent.FLAG_ACTIVITY_SINGLE_TOP
2638 | Intent.FLAG_ACTIVITY_CLEAR_TOP);
2639 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002640 mContext.startActivityAsUser(intent, UserHandle.CURRENT);
Jim Miller45308b12012-06-18 19:23:39 -07002641 } catch (ActivityNotFoundException e) {
2642 Slog.w(TAG, "No activity to handle assist action.", e);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002643 }
2644 }
2645 }
2646
2647 private SearchManager getSearchManager() {
2648 if (mSearchManager == null) {
2649 mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
2650 }
2651 return mSearchManager;
2652 }
2653
Jeff Browncaca8812013-05-09 13:34:33 -07002654 private void preloadRecentApps() {
2655 mPreloadedRecentApps = true;
2656 try {
2657 IStatusBarService statusbar = getStatusBarService();
2658 if (statusbar != null) {
2659 statusbar.preloadRecentApps();
2660 }
2661 } catch (RemoteException e) {
2662 Slog.e(TAG, "RemoteException when preloading recent apps", e);
2663 // re-acquire status bar service next time it is needed.
2664 mStatusBarService = null;
2665 }
2666 }
2667
2668 private void cancelPreloadRecentApps() {
2669 if (mPreloadedRecentApps) {
2670 mPreloadedRecentApps = false;
2671 try {
2672 IStatusBarService statusbar = getStatusBarService();
2673 if (statusbar != null) {
2674 statusbar.cancelPreloadRecentApps();
2675 }
2676 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002677 Slog.e(TAG, "RemoteException when cancelling recent apps preload", e);
Jeff Browncaca8812013-05-09 13:34:33 -07002678 // re-acquire status bar service next time it is needed.
2679 mStatusBarService = null;
2680 }
2681 }
2682 }
2683
2684 private void toggleRecentApps() {
2685 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
Jeff Browncaca8812013-05-09 13:34:33 -07002686 try {
2687 IStatusBarService statusbar = getStatusBarService();
2688 if (statusbar != null) {
2689 statusbar.toggleRecentApps();
2690 }
2691 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002692 Slog.e(TAG, "RemoteException when toggling recent apps", e);
2693 // re-acquire status bar service next time it is needed.
2694 mStatusBarService = null;
2695 }
2696 }
2697
Craig Mautner84984fa2014-06-19 11:19:20 -07002698 @Override
2699 public void showRecentApps() {
2700 mHandler.removeMessages(MSG_DISPATCH_SHOW_RECENTS);
2701 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_RECENTS);
2702 }
2703
Winson Chung1e8d71b2014-05-16 17:05:22 -07002704 private void showRecentApps(boolean triggeredFromAltTab) {
2705 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
2706 try {
2707 IStatusBarService statusbar = getStatusBarService();
2708 if (statusbar != null) {
2709 statusbar.showRecentApps(triggeredFromAltTab);
2710 }
2711 } catch (RemoteException e) {
Jeff Browncaca8812013-05-09 13:34:33 -07002712 Slog.e(TAG, "RemoteException when showing recent apps", e);
2713 // re-acquire status bar service next time it is needed.
2714 mStatusBarService = null;
2715 }
2716 }
2717
Winson Chungcdcd4872014-08-05 18:00:13 -07002718 private void hideRecentApps(boolean triggeredFromAltTab, boolean triggeredFromHome) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002719 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
2720 try {
2721 IStatusBarService statusbar = getStatusBarService();
2722 if (statusbar != null) {
Winson Chungcdcd4872014-08-05 18:00:13 -07002723 statusbar.hideRecentApps(triggeredFromAltTab, triggeredFromHome);
Winson Chung1e8d71b2014-05-16 17:05:22 -07002724 }
2725 } catch (RemoteException e) {
2726 Slog.e(TAG, "RemoteException when closing recent apps", e);
2727 // re-acquire status bar service next time it is needed.
2728 mStatusBarService = null;
2729 }
2730 }
2731
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002732 /**
2733 * A home key -> launch home action was detected. Take the appropriate action
2734 * given the situation with the keyguard.
2735 */
2736 void launchHomeFromHotKey() {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01002737 if (mKeyguardDelegate != null && mKeyguardDelegate.isShowingAndNotOccluded()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002738 // don't launch home if keyguard showing
Jim Miller5ecd8112013-01-09 18:50:26 -08002739 } else if (!mHideLockScreen && mKeyguardDelegate.isInputRestricted()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002740 // when in keyguard restricted mode, must first verify unlock
2741 // before launching home
Jim Miller5ecd8112013-01-09 18:50:26 -08002742 mKeyguardDelegate.verifyUnlock(new OnKeyguardExitResult() {
Jose Lima9546b202014-07-02 17:21:51 -07002743 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002744 public void onKeyguardExitResult(boolean success) {
2745 if (success) {
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07002746 try {
2747 ActivityManagerNative.getDefault().stopAppSwitches();
2748 } catch (RemoteException e) {
2749 }
Joe Onoratof275f0c2009-11-24 16:11:13 -05002750 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07002751 startDockOrHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002752 }
2753 }
2754 });
2755 } else {
2756 // no keyguard stuff to worry about, just launch home!
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07002757 try {
2758 ActivityManagerNative.getDefault().stopAppSwitches();
2759 } catch (RemoteException e) {
2760 }
Winson Chungd543c1b2014-06-23 15:06:45 -07002761 if (mRecentsVisible) {
2762 // Hide Recents and notify it to launch Home
2763 awakenDreams();
2764 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
Winson Chungcdcd4872014-08-05 18:00:13 -07002765 hideRecentApps(false, true);
Winson Chungd543c1b2014-06-23 15:06:45 -07002766 } else {
2767 // Otherwise, just launch Home
2768 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
2769 startDockOrHome();
2770 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002771 }
2772 }
2773
John Spurlock04db1762013-05-13 12:46:41 -04002774 private final Runnable mClearHideNavigationFlag = new Runnable() {
2775 @Override
2776 public void run() {
2777 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
2778 // Clear flags.
2779 mForceClearedSystemUiFlags &=
2780 ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
2781 }
2782 mWindowManagerFuncs.reevaluateStatusBarVisibility();
Dianne Hackborne26ab702011-10-16 13:21:33 -07002783 }
2784 };
2785
2786 /**
2787 * Input handler used while nav bar is hidden. Captures any touch on the screen,
2788 * to determine when the nav bar should be shown and prevent applications from
2789 * receiving those touches.
2790 */
Jeff Brown32cbc38552011-12-01 14:01:49 -08002791 final class HideNavInputEventReceiver extends InputEventReceiver {
2792 public HideNavInputEventReceiver(InputChannel inputChannel, Looper looper) {
2793 super(inputChannel, looper);
2794 }
2795
Dianne Hackborndf89e652011-10-06 22:35:11 -07002796 @Override
Jeff Brown32cbc38552011-12-01 14:01:49 -08002797 public void onInputEvent(InputEvent event) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07002798 boolean handled = false;
2799 try {
Jeff Brown4952dfd2011-11-30 19:23:22 -08002800 if (event instanceof MotionEvent
2801 && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
2802 final MotionEvent motionEvent = (MotionEvent)event;
2803 if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07002804 // When the user taps down, we re-show the nav bar.
2805 boolean changed = false;
John Spurlock04db1762013-05-13 12:46:41 -04002806 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002807 // Any user activity always causes us to show the
2808 // navigation controls, if they had been hidden.
2809 // We also clear the low profile and only content
2810 // flags so that tapping on the screen will atomically
2811 // restore all currently hidden screen decorations.
2812 int newVal = mResettingSystemUiFlags |
2813 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
2814 View.SYSTEM_UI_FLAG_LOW_PROFILE |
2815 View.SYSTEM_UI_FLAG_FULLSCREEN;
Dianne Hackborne26ab702011-10-16 13:21:33 -07002816 if (mResettingSystemUiFlags != newVal) {
2817 mResettingSystemUiFlags = newVal;
Dianne Hackborndf89e652011-10-06 22:35:11 -07002818 changed = true;
2819 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07002820 // We don't allow the system's nav bar to be hidden
2821 // again for 1 second, to prevent applications from
2822 // spamming us and keeping it from being shown.
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002823 newVal = mForceClearedSystemUiFlags |
2824 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
Dianne Hackborne26ab702011-10-16 13:21:33 -07002825 if (mForceClearedSystemUiFlags != newVal) {
2826 mForceClearedSystemUiFlags = newVal;
2827 changed = true;
John Spurlock04db1762013-05-13 12:46:41 -04002828 mHandler.postDelayed(mClearHideNavigationFlag, 1000);
Dianne Hackborne26ab702011-10-16 13:21:33 -07002829 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07002830 }
2831 if (changed) {
2832 mWindowManagerFuncs.reevaluateStatusBarVisibility();
2833 }
2834 }
2835 }
2836 } finally {
Jeff Brown32cbc38552011-12-01 14:01:49 -08002837 finishInputEvent(event, handled);
Dianne Hackborndf89e652011-10-06 22:35:11 -07002838 }
2839 }
Jeff Brown32cbc38552011-12-01 14:01:49 -08002840 }
2841 final InputEventReceiver.Factory mHideNavInputEventReceiverFactory =
2842 new InputEventReceiver.Factory() {
2843 @Override
2844 public InputEventReceiver createInputEventReceiver(
2845 InputChannel inputChannel, Looper looper) {
2846 return new HideNavInputEventReceiver(inputChannel, looper);
2847 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07002848 };
2849
2850 @Override
2851 public int adjustSystemUiVisibilityLw(int visibility) {
John Spurlock5b9145b2013-08-20 15:13:47 -04002852 mStatusBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
2853 mNavigationBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
Winson Chungd42a6cf2014-06-03 16:24:04 -07002854 mRecentsVisible = (visibility & View.RECENT_APPS_VISIBLE) > 0;
John Spurlock27735a42013-08-14 17:57:38 -04002855
Dianne Hackborndf89e652011-10-06 22:35:11 -07002856 // Reset any bits in mForceClearingStatusBarVisibility that
2857 // are now clear.
Dianne Hackborne26ab702011-10-16 13:21:33 -07002858 mResettingSystemUiFlags &= visibility;
Dianne Hackborndf89e652011-10-06 22:35:11 -07002859 // Clear any bits in the new visibility that are currently being
2860 // force cleared, before reporting it.
Dianne Hackborne26ab702011-10-16 13:21:33 -07002861 return visibility & ~mResettingSystemUiFlags
2862 & ~mForceClearedSystemUiFlags;
Dianne Hackborndf89e652011-10-06 22:35:11 -07002863 }
2864
Craig Mautner69b08182012-09-05 13:07:13 -07002865 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002866 public void getContentInsetHintLw(WindowManager.LayoutParams attrs, Rect contentInset) {
John Spurlockc6d1c602014-01-17 15:22:06 -05002867 final int fl = PolicyControl.getWindowFlags(null, attrs);
John Spurlock1db8b682014-02-18 11:18:59 -05002868 final int sysuiVis = PolicyControl.getSystemUiVisibility(null, attrs);
2869 final int systemUiVisibility = (sysuiVis | attrs.subtreeSystemUiVisibility);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002870
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002871 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002872 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002873 int availRight, availBottom;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07002874 if (canHideNavigationBar() &&
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002875 (systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002876 availRight = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
2877 availBottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
2878 } else {
2879 availRight = mRestrictedScreenLeft + mRestrictedScreenWidth;
2880 availBottom = mRestrictedScreenTop + mRestrictedScreenHeight;
2881 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002882 if ((systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
2883 if ((fl & FLAG_FULLSCREEN) != 0) {
2884 contentInset.set(mStableFullscreenLeft, mStableFullscreenTop,
2885 availRight - mStableFullscreenRight,
2886 availBottom - mStableFullscreenBottom);
2887 } else {
2888 contentInset.set(mStableLeft, mStableTop,
2889 availRight - mStableRight, availBottom - mStableBottom);
2890 }
Dianne Hackbornc652de82013-02-15 16:32:56 -08002891 } else if ((fl & FLAG_FULLSCREEN) != 0 || (fl & FLAG_LAYOUT_IN_OVERSCAN) != 0) {
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002892 contentInset.setEmpty();
2893 } else if ((systemUiVisibility & (View.SYSTEM_UI_FLAG_FULLSCREEN
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002894 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)) == 0) {
2895 contentInset.set(mCurLeft, mCurTop,
2896 availRight - mCurRight, availBottom - mCurBottom);
2897 } else {
2898 contentInset.set(mCurLeft, mCurTop,
2899 availRight - mCurRight, availBottom - mCurBottom);
2900 }
2901 return;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002902 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002903 contentInset.setEmpty();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002904 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002905
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002906 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07002907 @Override
2908 public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight,
2909 int displayRotation) {
Dianne Hackbornc652de82013-02-15 16:32:56 -08002910 final int overscanLeft, overscanTop, overscanRight, overscanBottom;
2911 if (isDefaultDisplay) {
2912 switch (displayRotation) {
2913 case Surface.ROTATION_90:
2914 overscanLeft = mOverscanTop;
2915 overscanTop = mOverscanRight;
2916 overscanRight = mOverscanBottom;
2917 overscanBottom = mOverscanLeft;
2918 break;
2919 case Surface.ROTATION_180:
2920 overscanLeft = mOverscanRight;
2921 overscanTop = mOverscanBottom;
2922 overscanRight = mOverscanLeft;
2923 overscanBottom = mOverscanTop;
2924 break;
2925 case Surface.ROTATION_270:
2926 overscanLeft = mOverscanBottom;
2927 overscanTop = mOverscanLeft;
2928 overscanRight = mOverscanTop;
2929 overscanBottom = mOverscanRight;
2930 break;
2931 default:
2932 overscanLeft = mOverscanLeft;
2933 overscanTop = mOverscanTop;
2934 overscanRight = mOverscanRight;
2935 overscanBottom = mOverscanBottom;
2936 break;
2937 }
2938 } else {
2939 overscanLeft = 0;
2940 overscanTop = 0;
2941 overscanRight = 0;
2942 overscanBottom = 0;
2943 }
Dianne Hackborn313440842013-02-19 19:22:59 -08002944 mOverscanScreenLeft = mRestrictedOverscanScreenLeft = 0;
2945 mOverscanScreenTop = mRestrictedOverscanScreenTop = 0;
2946 mOverscanScreenWidth = mRestrictedOverscanScreenWidth = displayWidth;
2947 mOverscanScreenHeight = mRestrictedOverscanScreenHeight = displayHeight;
Dianne Hackbornc652de82013-02-15 16:32:56 -08002948 mSystemLeft = 0;
2949 mSystemTop = 0;
2950 mSystemRight = displayWidth;
2951 mSystemBottom = displayHeight;
2952 mUnrestrictedScreenLeft = overscanLeft;
2953 mUnrestrictedScreenTop = overscanTop;
2954 mUnrestrictedScreenWidth = displayWidth - overscanLeft - overscanRight;
2955 mUnrestrictedScreenHeight = displayHeight - overscanTop - overscanBottom;
2956 mRestrictedScreenLeft = mUnrestrictedScreenLeft;
2957 mRestrictedScreenTop = mUnrestrictedScreenTop;
John Spurlockad3e6cb2013-04-30 08:47:43 -04002958 mRestrictedScreenWidth = mSystemGestures.screenWidth = mUnrestrictedScreenWidth;
2959 mRestrictedScreenHeight = mSystemGestures.screenHeight = mUnrestrictedScreenHeight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002960 mDockLeft = mContentLeft = mVoiceContentLeft = mStableLeft = mStableFullscreenLeft
Dianne Hackbornc652de82013-02-15 16:32:56 -08002961 = mCurLeft = mUnrestrictedScreenLeft;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002962 mDockTop = mContentTop = mVoiceContentTop = mStableTop = mStableFullscreenTop
Dianne Hackbornc652de82013-02-15 16:32:56 -08002963 = mCurTop = mUnrestrictedScreenTop;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002964 mDockRight = mContentRight = mVoiceContentRight = mStableRight = mStableFullscreenRight
Dianne Hackbornc652de82013-02-15 16:32:56 -08002965 = mCurRight = displayWidth - overscanRight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002966 mDockBottom = mContentBottom = mVoiceContentBottom = mStableBottom = mStableFullscreenBottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08002967 = mCurBottom = displayHeight - overscanBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002968 mDockLayer = 0x10000000;
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002969 mStatusBarLayer = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002970
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002971 // start with the current dock rect, which will be (0,0,displayWidth,displayHeight)
2972 final Rect pf = mTmpParentFrame;
2973 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002974 final Rect of = mTmpOverscanFrame;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002975 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04002976 final Rect dcf = mTmpDecorFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002977 pf.left = df.left = of.left = vf.left = mDockLeft;
2978 pf.top = df.top = of.top = vf.top = mDockTop;
2979 pf.right = df.right = of.right = vf.right = mDockRight;
2980 pf.bottom = df.bottom = of.bottom = vf.bottom = mDockBottom;
John Spurlock46646232013-09-30 22:32:42 -04002981 dcf.setEmpty(); // Decor frame N/A for system bars.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002982
Craig Mautner69b08182012-09-05 13:07:13 -07002983 if (isDefaultDisplay) {
2984 // For purposes of putting out fake window up to steal focus, we will
2985 // drive nav being hidden only by whether it is requested.
John Spurlocke1f366f2013-08-05 12:22:40 -04002986 final int sysui = mLastSystemUiFlags;
2987 boolean navVisible = (sysui & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0;
Adrian Roosea562512014-05-05 13:33:03 +02002988 boolean navTranslucent = (sysui
2989 & (View.NAVIGATION_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04002990 boolean immersive = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
2991 boolean immersiveSticky = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
2992 boolean navAllowedHidden = immersive || immersiveSticky;
2993 navTranslucent &= !immersiveSticky; // transient trumps translucent
Adrian Roos4fb3ee32014-08-22 19:29:09 +02002994 boolean isKeyguardShowing = isStatusBarKeyguard() && !mHideLockScreen;
2995 if (!isKeyguardShowing) {
2996 navTranslucent &= areTranslucentBarsAllowed();
2997 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07002998
Craig Mautner69b08182012-09-05 13:07:13 -07002999 // When the navigation bar isn't visible, we put up a fake
3000 // input window to catch all touch events. This way we can
3001 // detect when the user presses anywhere to bring back the nav
3002 // bar and ensure the application doesn't see the event.
John Spurlockf1a36642013-10-12 17:50:42 -04003003 if (navVisible || navAllowedHidden) {
Craig Mautner69b08182012-09-05 13:07:13 -07003004 if (mHideNavFakeWindow != null) {
3005 mHideNavFakeWindow.dismiss();
3006 mHideNavFakeWindow = null;
3007 }
3008 } else if (mHideNavFakeWindow == null) {
3009 mHideNavFakeWindow = mWindowManagerFuncs.addFakeWindow(
3010 mHandler.getLooper(), mHideNavInputEventReceiverFactory,
Adam Lesinski95c42972013-10-02 10:13:27 -07003011 "hidden nav", WindowManager.LayoutParams.TYPE_HIDDEN_NAV_CONSUMER, 0,
Craig Mautner69b08182012-09-05 13:07:13 -07003012 0, false, false, true);
Dianne Hackborne26ab702011-10-16 13:21:33 -07003013 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003014
Craig Mautner69b08182012-09-05 13:07:13 -07003015 // For purposes of positioning and showing the nav bar, if we have
3016 // decided that it can't be hidden (because of the screen aspect ratio),
3017 // then take that into account.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003018 navVisible |= !canHideNavigationBar();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003019
John Spurlockad3e6cb2013-04-30 08:47:43 -04003020 boolean updateSysUiVisibility = false;
Craig Mautner69b08182012-09-05 13:07:13 -07003021 if (mNavigationBar != null) {
John Spurlock27735a42013-08-14 17:57:38 -04003022 boolean transientNavBarShowing = mNavigationBarController.isTransientShowing();
Craig Mautner69b08182012-09-05 13:07:13 -07003023 // Force the navigation bar to its appropriate place and
3024 // size. We need to do this directly, instead of relying on
3025 // it to bubble up from the nav bar, because this needs to
3026 // change atomically with screen rotations.
3027 mNavigationBarOnBottom = (!mNavigationBarCanMove || displayWidth < displayHeight);
3028 if (mNavigationBarOnBottom) {
3029 // It's a system nav bar or a portrait screen; nav bar goes on bottom.
Dianne Hackbornc652de82013-02-15 16:32:56 -08003030 int top = displayHeight - overscanBottom
3031 - mNavigationBarHeightForRotation[displayRotation];
3032 mTmpNavigationFrame.set(0, top, displayWidth, displayHeight - overscanBottom);
Craig Mautner69b08182012-09-05 13:07:13 -07003033 mStableBottom = mStableFullscreenBottom = mTmpNavigationFrame.top;
John Spurlockf95b89a2013-10-10 22:10:42 -04003034 if (transientNavBarShowing) {
John Spurlock27735a42013-08-14 17:57:38 -04003035 mNavigationBarController.setBarShowingLw(true);
John Spurlockad3e6cb2013-04-30 08:47:43 -04003036 } else if (navVisible) {
John Spurlock27735a42013-08-14 17:57:38 -04003037 mNavigationBarController.setBarShowingLw(true);
Craig Mautner69b08182012-09-05 13:07:13 -07003038 mDockBottom = mTmpNavigationFrame.top;
Dianne Hackborn313440842013-02-19 19:22:59 -08003039 mRestrictedScreenHeight = mDockBottom - mRestrictedScreenTop;
3040 mRestrictedOverscanScreenHeight = mDockBottom - mRestrictedOverscanScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07003041 } else {
3042 // We currently want to hide the navigation UI.
John Spurlock27735a42013-08-14 17:57:38 -04003043 mNavigationBarController.setBarShowingLw(false);
Craig Mautner69b08182012-09-05 13:07:13 -07003044 }
John Spurlockc6d1c602014-01-17 15:22:06 -05003045 if (navVisible && !navTranslucent && !navAllowedHidden
3046 && !mNavigationBar.isAnimatingLw()
John Spurlockbd957402013-10-03 11:38:39 -04003047 && !mNavigationBarController.wasRecentlyTranslucent()) {
John Spurlocke1f366f2013-08-05 12:22:40 -04003048 // If the opaque nav bar is currently requested to be visible,
Craig Mautner69b08182012-09-05 13:07:13 -07003049 // and not in the process of animating on or off, then
3050 // we can tell the app that it is covered by it.
3051 mSystemBottom = mTmpNavigationFrame.top;
3052 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003053 } else {
Craig Mautner69b08182012-09-05 13:07:13 -07003054 // Landscape screen; nav bar goes to the right.
Dianne Hackbornc652de82013-02-15 16:32:56 -08003055 int left = displayWidth - overscanRight
3056 - mNavigationBarWidthForRotation[displayRotation];
3057 mTmpNavigationFrame.set(left, 0, displayWidth - overscanRight, displayHeight);
Craig Mautner69b08182012-09-05 13:07:13 -07003058 mStableRight = mStableFullscreenRight = mTmpNavigationFrame.left;
John Spurlockf95b89a2013-10-10 22:10:42 -04003059 if (transientNavBarShowing) {
John Spurlock27735a42013-08-14 17:57:38 -04003060 mNavigationBarController.setBarShowingLw(true);
John Spurlockad3e6cb2013-04-30 08:47:43 -04003061 } else if (navVisible) {
John Spurlock27735a42013-08-14 17:57:38 -04003062 mNavigationBarController.setBarShowingLw(true);
Craig Mautner69b08182012-09-05 13:07:13 -07003063 mDockRight = mTmpNavigationFrame.left;
Dianne Hackborn313440842013-02-19 19:22:59 -08003064 mRestrictedScreenWidth = mDockRight - mRestrictedScreenLeft;
3065 mRestrictedOverscanScreenWidth = mDockRight - mRestrictedOverscanScreenLeft;
Craig Mautner69b08182012-09-05 13:07:13 -07003066 } else {
3067 // We currently want to hide the navigation UI.
John Spurlock27735a42013-08-14 17:57:38 -04003068 mNavigationBarController.setBarShowingLw(false);
Craig Mautner69b08182012-09-05 13:07:13 -07003069 }
John Spurlockbd957402013-10-03 11:38:39 -04003070 if (navVisible && !navTranslucent && !mNavigationBar.isAnimatingLw()
3071 && !mNavigationBarController.wasRecentlyTranslucent()) {
Craig Mautner69b08182012-09-05 13:07:13 -07003072 // If the nav bar is currently requested to be visible,
3073 // and not in the process of animating on or off, then
3074 // we can tell the app that it is covered by it.
3075 mSystemRight = mTmpNavigationFrame.left;
3076 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003077 }
Craig Mautner69b08182012-09-05 13:07:13 -07003078 // Make sure the content and current rectangles are updated to
3079 // account for the restrictions from the navigation bar.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003080 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3081 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3082 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3083 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
Craig Mautner69b08182012-09-05 13:07:13 -07003084 mStatusBarLayer = mNavigationBar.getSurfaceLayer();
3085 // And compute the final frame.
3086 mNavigationBar.computeFrameLw(mTmpNavigationFrame, mTmpNavigationFrame,
Adrian Roosfa104232014-06-20 16:10:14 -07003087 mTmpNavigationFrame, mTmpNavigationFrame, mTmpNavigationFrame, dcf,
3088 mTmpNavigationFrame);
Craig Mautnereda67292013-04-28 13:50:14 -07003089 if (DEBUG_LAYOUT) Slog.i(TAG, "mNavigationBar frame: " + mTmpNavigationFrame);
John Spurlock27735a42013-08-14 17:57:38 -04003090 if (mNavigationBarController.checkHiddenLw()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04003091 updateSysUiVisibility = true;
3092 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003093 }
Craig Mautnereda67292013-04-28 13:50:14 -07003094 if (DEBUG_LAYOUT) Slog.i(TAG, String.format("mDock rect: (%d,%d - %d,%d)",
Craig Mautner69b08182012-09-05 13:07:13 -07003095 mDockLeft, mDockTop, mDockRight, mDockBottom));
3096
3097 // decide where the status bar goes ahead of time
3098 if (mStatusBar != null) {
3099 // apply any navigation bar insets
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003100 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3101 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3102 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
3103 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight
3104 + mUnrestrictedScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07003105 vf.left = mStableLeft;
3106 vf.top = mStableTop;
3107 vf.right = mStableRight;
3108 vf.bottom = mStableBottom;
3109
3110 mStatusBarLayer = mStatusBar.getSurfaceLayer();
3111
3112 // Let the status bar determine its size.
Adrian Roosfa104232014-06-20 16:10:14 -07003113 mStatusBar.computeFrameLw(pf, df, vf, vf, vf, dcf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07003114
3115 // For layout, the status bar is always at the top with our fixed height.
3116 mStableTop = mUnrestrictedScreenTop + mStatusBarHeight;
3117
John Spurlocke1f366f2013-08-05 12:22:40 -04003118 boolean statusBarTransient = (sysui & View.STATUS_BAR_TRANSIENT) != 0;
Adrian Roosea562512014-05-05 13:33:03 +02003119 boolean statusBarTranslucent = (sysui
3120 & (View.STATUS_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0;
Adrian Roos4fb3ee32014-08-22 19:29:09 +02003121 if (!isKeyguardShowing) {
3122 statusBarTranslucent &= areTranslucentBarsAllowed();
3123 }
John Spurlock32beb2c2013-03-11 10:16:47 -04003124
Craig Mautner69b08182012-09-05 13:07:13 -07003125 // If the status bar is hidden, we don't want to cause
3126 // windows behind it to scroll.
John Spurlockeda1f692013-09-16 11:38:44 -04003127 if (mStatusBar.isVisibleLw() && !statusBarTransient) {
Craig Mautner69b08182012-09-05 13:07:13 -07003128 // Status bar may go away, so the screen area it occupies
3129 // is available to apps but just covering them when the
3130 // status bar is visible.
3131 mDockTop = mUnrestrictedScreenTop + mStatusBarHeight;
3132
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003133 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3134 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3135 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3136 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
Craig Mautner69b08182012-09-05 13:07:13 -07003137
Craig Mautnereda67292013-04-28 13:50:14 -07003138 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar: " +
Craig Mautner69b08182012-09-05 13:07:13 -07003139 String.format(
3140 "dock=[%d,%d][%d,%d] content=[%d,%d][%d,%d] cur=[%d,%d][%d,%d]",
3141 mDockLeft, mDockTop, mDockRight, mDockBottom,
3142 mContentLeft, mContentTop, mContentRight, mContentBottom,
3143 mCurLeft, mCurTop, mCurRight, mCurBottom));
3144 }
John Spurlocke1f366f2013-08-05 12:22:40 -04003145 if (mStatusBar.isVisibleLw() && !mStatusBar.isAnimatingLw()
John Spurlockbd957402013-10-03 11:38:39 -04003146 && !statusBarTransient && !statusBarTranslucent
3147 && !mStatusBarController.wasRecentlyTranslucent()) {
John Spurlocke1f366f2013-08-05 12:22:40 -04003148 // If the opaque status bar is currently requested to be visible,
Craig Mautner69b08182012-09-05 13:07:13 -07003149 // and not in the process of animating on or off, then
3150 // we can tell the app that it is covered by it.
3151 mSystemTop = mUnrestrictedScreenTop + mStatusBarHeight;
3152 }
John Spurlock27735a42013-08-14 17:57:38 -04003153 if (mStatusBarController.checkHiddenLw()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04003154 updateSysUiVisibility = true;
John Spurlock32beb2c2013-03-11 10:16:47 -04003155 }
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003156 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04003157 if (updateSysUiVisibility) {
3158 updateSystemUiVisibilityLw();
3159 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003160 }
3161 }
3162
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003163 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07003164 @Override
John Spurlock46646232013-09-30 22:32:42 -04003165 public int getSystemDecorLayerLw() {
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003166 if (mStatusBar != null) return mStatusBar.getSurfaceLayer();
3167 if (mNavigationBar != null) return mNavigationBar.getSurfaceLayer();
3168 return 0;
3169 }
3170
Craig Mautner967212c2013-04-13 21:10:58 -07003171 @Override
3172 public void getContentRectLw(Rect r) {
3173 r.set(mContentLeft, mContentTop, mContentRight, mContentBottom);
3174 }
3175
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003176 void setAttachedWindowFrames(WindowState win, int fl, int adjust, WindowState attached,
3177 boolean insetDecors, Rect pf, Rect df, Rect of, Rect cf, Rect vf) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003178 if (win.getSurfaceLayer() > mDockLayer && attached.getSurfaceLayer() < mDockLayer) {
3179 // Here's a special case: if this attached window is a panel that is
3180 // above the dock window, and the window it is attached to is below
3181 // the dock window, then the frames we computed for the window it is
3182 // attached to can not be used because the dock is effectively part
3183 // of the underlying window and the attached window is floating on top
3184 // of the whole thing. So, we ignore the attached window and explicitly
3185 // compute the frames that would be appropriate without the dock.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003186 df.left = of.left = cf.left = vf.left = mDockLeft;
3187 df.top = of.top = cf.top = vf.top = mDockTop;
3188 df.right = of.right = cf.right = vf.right = mDockRight;
3189 df.bottom = of.bottom = cf.bottom = vf.bottom = mDockBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003190 } else {
3191 // The effective display frame of the attached window depends on
3192 // whether it is taking care of insetting its content. If not,
3193 // we need to use the parent's content frame so that the entire
3194 // window is positioned within that content. Otherwise we can use
3195 // the display frame and let the attached window take care of
3196 // positioning its content appropriately.
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003197 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003198 cf.set(attached.getOverscanFrameLw());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003199 } else {
3200 // If the window is resizing, then we want to base the content
3201 // frame on our attached content frame to resize... however,
3202 // things can be tricky if the attached window is NOT in resize
3203 // mode, in which case its content frame will be larger.
3204 // Ungh. So to deal with that, make sure the content frame
3205 // we end up using is not covering the IM dock.
3206 cf.set(attached.getContentFrameLw());
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003207 if (attached.isVoiceInteraction()) {
3208 if (cf.left < mVoiceContentLeft) cf.left = mVoiceContentLeft;
3209 if (cf.top < mVoiceContentTop) cf.top = mVoiceContentTop;
3210 if (cf.right > mVoiceContentRight) cf.right = mVoiceContentRight;
3211 if (cf.bottom > mVoiceContentBottom) cf.bottom = mVoiceContentBottom;
3212 } else if (attached.getSurfaceLayer() < mDockLayer) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003213 if (cf.left < mContentLeft) cf.left = mContentLeft;
3214 if (cf.top < mContentTop) cf.top = mContentTop;
3215 if (cf.right > mContentRight) cf.right = mContentRight;
3216 if (cf.bottom > mContentBottom) cf.bottom = mContentBottom;
3217 }
3218 }
3219 df.set(insetDecors ? attached.getDisplayFrameLw() : cf);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003220 of.set(insetDecors ? attached.getOverscanFrameLw() : cf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003221 vf.set(attached.getVisibleFrameLw());
3222 }
3223 // The LAYOUT_IN_SCREEN flag is used to determine whether the attached
3224 // window should be positioned relative to its parent or the entire
3225 // screen.
3226 pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0
3227 ? attached.getFrameLw() : df);
3228 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003229
3230 private void applyStableConstraints(int sysui, int fl, Rect r) {
3231 if ((sysui & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
3232 // If app is requesting a stable layout, don't let the
3233 // content insets go below the stable values.
3234 if ((fl & FLAG_FULLSCREEN) != 0) {
3235 if (r.left < mStableFullscreenLeft) r.left = mStableFullscreenLeft;
3236 if (r.top < mStableFullscreenTop) r.top = mStableFullscreenTop;
3237 if (r.right > mStableFullscreenRight) r.right = mStableFullscreenRight;
3238 if (r.bottom > mStableFullscreenBottom) r.bottom = mStableFullscreenBottom;
3239 } else {
3240 if (r.left < mStableLeft) r.left = mStableLeft;
3241 if (r.top < mStableTop) r.top = mStableTop;
3242 if (r.right > mStableRight) r.right = mStableRight;
3243 if (r.bottom > mStableBottom) r.bottom = mStableBottom;
3244 }
3245 }
3246 }
3247
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003248 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07003249 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003250 public void layoutWindowLw(WindowState win, WindowState attached) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003251 // we've already done the status bar
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003252 final WindowManager.LayoutParams attrs = win.getAttrs();
3253 if ((win == mStatusBar && (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) == 0) ||
3254 win == mNavigationBar) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003255 return;
3256 }
Craig Mautner69b08182012-09-05 13:07:13 -07003257 final boolean isDefaultDisplay = win.isDefaultDisplay();
3258 final boolean needsToOffsetInputMethodTarget = isDefaultDisplay &&
satok1bc0a492012-04-25 22:47:12 +09003259 (win == mLastInputMethodTargetWindow && mLastInputMethodWindow != null);
3260 if (needsToOffsetInputMethodTarget) {
Craig Mautnereda67292013-04-28 13:50:14 -07003261 if (DEBUG_LAYOUT) Slog.i(TAG, "Offset ime target window by the last ime window state");
satok1bc0a492012-04-25 22:47:12 +09003262 offsetInputMethodWindowLw(mLastInputMethodWindow);
3263 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003264
John Spurlockc6d1c602014-01-17 15:22:06 -05003265 final int fl = PolicyControl.getWindowFlags(win, attrs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003266 final int sim = attrs.softInputMode;
John Spurlock1db8b682014-02-18 11:18:59 -05003267 final int sysUiFl = PolicyControl.getSystemUiVisibility(win, null);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003268
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003269 final Rect pf = mTmpParentFrame;
3270 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003271 final Rect of = mTmpOverscanFrame;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003272 final Rect cf = mTmpContentFrame;
3273 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04003274 final Rect dcf = mTmpDecorFrame;
Adrian Roosfa104232014-06-20 16:10:14 -07003275 final Rect sf = mTmpStableFrame;
John Spurlock46646232013-09-30 22:32:42 -04003276 dcf.setEmpty();
Craig Mautner69b08182012-09-05 13:07:13 -07003277
3278 final boolean hasNavBar = (isDefaultDisplay && mHasNavigationBar
Daniel Sandler36412a72011-08-04 09:35:13 -04003279 && mNavigationBar != null && mNavigationBar.isVisibleLw());
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003280
Craig Mautnerf683b562012-10-02 11:10:57 -07003281 final int adjust = sim & SOFT_INPUT_MASK_ADJUST;
3282
Adrian Roosfa104232014-06-20 16:10:14 -07003283 if (isDefaultDisplay) {
3284 sf.set(mStableLeft, mStableTop, mStableRight, mStableBottom);
3285 } else {
3286 sf.set(mOverscanLeft, mOverscanTop, mOverscanRight, mOverscanBottom);
3287 }
3288
Craig Mautner69b08182012-09-05 13:07:13 -07003289 if (!isDefaultDisplay) {
3290 if (attached != null) {
3291 // If this window is attached to another, our display
3292 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003293 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07003294 } else {
3295 // Give the window full screen.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003296 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3297 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3298 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08003299 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003300 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003301 = mOverscanScreenTop + mOverscanScreenHeight;
Craig Mautner69b08182012-09-05 13:07:13 -07003302 }
3303 } else if (attrs.type == TYPE_INPUT_METHOD) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003304 pf.left = df.left = of.left = cf.left = vf.left = mDockLeft;
3305 pf.top = df.top = of.top = cf.top = vf.top = mDockTop;
3306 pf.right = df.right = of.right = cf.right = vf.right = mDockRight;
John Spurlockc68d5772013-10-08 11:47:58 -04003307 // IM dock windows layout below the nav bar...
John Spurlock57beb3b2013-10-10 10:27:44 -04003308 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlockc68d5772013-10-08 11:47:58 -04003309 // ...with content insets above the nav bar
3310 cf.bottom = vf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003311 // IM dock windows always go to the bottom of the screen.
3312 attrs.gravity = Gravity.BOTTOM;
3313 mDockLayer = win.getSurfaceLayer();
Jorim Jaggie0700182014-08-21 01:12:37 +02003314 } else if (win == mStatusBar && (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
3315 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3316 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3317 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
3318 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight + mUnrestrictedScreenTop;
3319 cf.left = vf.left = mStableLeft;
3320 cf.top = vf.top = mStableTop;
3321 cf.right = vf.right = mStableRight;
3322 vf.bottom = mStableBottom;
3323 cf.bottom = mContentBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003324 } else {
John Spurlock46646232013-09-30 22:32:42 -04003325
3326 // Default policy decor for the default display
3327 dcf.left = mSystemLeft;
3328 dcf.top = mSystemTop;
3329 dcf.right = mSystemRight;
3330 dcf.bottom = mSystemBottom;
John Spurlockbd957402013-10-03 11:38:39 -04003331 final boolean inheritTranslucentDecor = (attrs.privateFlags
3332 & WindowManager.LayoutParams.PRIVATE_FLAG_INHERIT_TRANSLUCENT_DECOR) != 0;
John Spurlock65567d42013-10-08 10:08:32 -04003333 final boolean isAppWindow =
3334 attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW &&
3335 attrs.type <= WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
3336 final boolean topAtRest =
3337 win == mTopFullscreenOpaqueWindowState && !win.isAnimatingLw();
3338 if (isAppWindow && !inheritTranslucentDecor && !topAtRest) {
John Spurlockbd957402013-10-03 11:38:39 -04003339 if ((sysUiFl & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0
3340 && (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0
Adrian Roosea562512014-05-05 13:33:03 +02003341 && (fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) == 0
3342 && (fl & WindowManager.LayoutParams.
3343 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04003344 // Ensure policy decor includes status bar
3345 dcf.top = mStableTop;
3346 }
John Spurlockbd957402013-10-03 11:38:39 -04003347 if ((fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) == 0
Adrian Roosea562512014-05-05 13:33:03 +02003348 && (sysUiFl & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0
3349 && (fl & WindowManager.LayoutParams.
3350 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04003351 // Ensure policy decor includes navigation bar
3352 dcf.bottom = mStableBottom;
3353 dcf.right = mStableRight;
3354 }
3355 }
3356
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003357 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
3358 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
RoboErik8a2cfc32014-05-16 11:19:38 -07003359 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003360 + "): IN_SCREEN, INSET_DECOR");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003361 // This is the case for a normal activity window: we want it
3362 // to cover all of the screen space, and it can take care of
3363 // moving its contents to account for screen decorations that
3364 // intrude into that space.
3365 if (attached != null) {
3366 // If this window is attached to another, our display
3367 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003368 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003369 } else {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003370 if (attrs.type == TYPE_STATUS_BAR_PANEL
3371 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Joe Onorato29fc2c92010-11-24 10:26:50 -08003372 // Status bar panels are the only windows who can go on top of
3373 // the status bar. They are protected by the STATUS_BAR_SERVICE
3374 // permission, so they have the same privileges as the status
3375 // bar itself.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003376 //
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003377 // However, they should still dodge the navigation bar if it exists.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003378
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003379 pf.left = df.left = of.left = hasNavBar
3380 ? mDockLeft : mUnrestrictedScreenLeft;
3381 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3382 pf.right = df.right = of.right = hasNavBar
3383 ? mRestrictedScreenLeft+mRestrictedScreenWidth
3384 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3385 pf.bottom = df.bottom = of.bottom = hasNavBar
3386 ? mRestrictedScreenTop+mRestrictedScreenHeight
3387 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003388
Craig Mautnereda67292013-04-28 13:50:14 -07003389 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003390 "Laying out status bar window: (%d,%d - %d,%d)",
3391 pf.left, pf.top, pf.right, pf.bottom));
John Spurlock46646232013-09-30 22:32:42 -04003392 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08003393 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3394 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3395 // Asking to layout into the overscan region, so give it that pure
3396 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003397 pf.left = df.left = of.left = mOverscanScreenLeft;
3398 pf.top = df.top = of.top = mOverscanScreenTop;
3399 pf.right = df.right = of.right = mOverscanScreenLeft + mOverscanScreenWidth;
3400 pf.bottom = df.bottom = of.bottom = mOverscanScreenTop
3401 + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003402 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003403 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003404 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3405 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003406 // Asking for layout as if the nav bar is hidden, lets the
Dianne Hackbornc652de82013-02-15 16:32:56 -08003407 // application extend into the unrestricted overscan screen area. We
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003408 // only do this for application windows to ensure no window that
3409 // can be above the nav bar can do this.
Dianne Hackborn313440842013-02-19 19:22:59 -08003410 pf.left = df.left = mOverscanScreenLeft;
3411 pf.top = df.top = mOverscanScreenTop;
3412 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
3413 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003414 // We need to tell the app about where the frame inside the overscan
3415 // is, so it can inset its content by that amount -- it didn't ask
3416 // to actually extend itself into the overscan region.
3417 of.left = mUnrestrictedScreenLeft;
3418 of.top = mUnrestrictedScreenTop;
3419 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3420 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003421 } else {
Dianne Hackborn313440842013-02-19 19:22:59 -08003422 pf.left = df.left = mRestrictedOverscanScreenLeft;
3423 pf.top = df.top = mRestrictedOverscanScreenTop;
3424 pf.right = df.right = mRestrictedOverscanScreenLeft
3425 + mRestrictedOverscanScreenWidth;
3426 pf.bottom = df.bottom = mRestrictedOverscanScreenTop
3427 + mRestrictedOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003428 // We need to tell the app about where the frame inside the overscan
3429 // is, so it can inset its content by that amount -- it didn't ask
3430 // to actually extend itself into the overscan region.
3431 of.left = mUnrestrictedScreenLeft;
3432 of.top = mUnrestrictedScreenTop;
3433 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3434 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003435 }
Craig Mautner69b08182012-09-05 13:07:13 -07003436
John Spurlock46646232013-09-30 22:32:42 -04003437 if ((fl & FLAG_FULLSCREEN) == 0) {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003438 if (win.isVoiceInteraction()) {
3439 cf.left = mVoiceContentLeft;
3440 cf.top = mVoiceContentTop;
3441 cf.right = mVoiceContentRight;
3442 cf.bottom = mVoiceContentBottom;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003443 } else {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003444 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
3445 cf.left = mDockLeft;
3446 cf.top = mDockTop;
3447 cf.right = mDockRight;
3448 cf.bottom = mDockBottom;
3449 } else {
3450 cf.left = mContentLeft;
3451 cf.top = mContentTop;
3452 cf.right = mContentRight;
3453 cf.bottom = mContentBottom;
3454 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003455 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003456 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003457 // Full screen windows are always given a layout that is as if the
3458 // status bar and other transient decors are gone. This is to avoid
3459 // bad states when moving from a window that is not hding the
3460 // status bar to one that is.
3461 cf.left = mRestrictedScreenLeft;
3462 cf.top = mRestrictedScreenTop;
3463 cf.right = mRestrictedScreenLeft + mRestrictedScreenWidth;
3464 cf.bottom = mRestrictedScreenTop + mRestrictedScreenHeight;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003465 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003466 applyStableConstraints(sysUiFl, fl, cf);
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003467 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3468 vf.left = mCurLeft;
3469 vf.top = mCurTop;
3470 vf.right = mCurRight;
3471 vf.bottom = mCurBottom;
3472 } else {
3473 vf.set(cf);
3474 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003475 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003476 } else if ((fl & FLAG_LAYOUT_IN_SCREEN) != 0 || (sysUiFl
3477 & (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
3478 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)) != 0) {
Craig Mautnereda67292013-04-28 13:50:14 -07003479 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3480 "): IN_SCREEN");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003481 // A window that has requested to fill the entire screen just
3482 // gets everything, period.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003483 if (attrs.type == TYPE_STATUS_BAR_PANEL
3484 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003485 pf.left = df.left = of.left = cf.left = hasNavBar
3486 ? mDockLeft : mUnrestrictedScreenLeft;
3487 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
3488 pf.right = df.right = of.right = cf.right = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003489 ? mRestrictedScreenLeft+mRestrictedScreenWidth
Dianne Hackbornc652de82013-02-15 16:32:56 -08003490 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003491 pf.bottom = df.bottom = of.bottom = cf.bottom = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003492 ? mRestrictedScreenTop+mRestrictedScreenHeight
Dianne Hackbornc652de82013-02-15 16:32:56 -08003493 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07003494 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler36412a72011-08-04 09:35:13 -04003495 "Laying out IN_SCREEN status bar window: (%d,%d - %d,%d)",
3496 pf.left, pf.top, pf.right, pf.bottom));
Jim Millere898ac52012-04-06 17:10:57 -07003497 } else if (attrs.type == TYPE_NAVIGATION_BAR
3498 || attrs.type == TYPE_NAVIGATION_BAR_PANEL) {
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003499 // The navigation bar has Real Ultimate Power.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003500 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3501 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3502 pf.right = df.right = of.right = mUnrestrictedScreenLeft
3503 + mUnrestrictedScreenWidth;
3504 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop
3505 + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07003506 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003507 "Laying out navigation bar window: (%d,%d - %d,%d)",
3508 pf.left, pf.top, pf.right, pf.bottom));
Dianne Hackborn01011c32012-02-21 13:54:21 -08003509 } else if ((attrs.type == TYPE_SECURE_SYSTEM_OVERLAY
3510 || attrs.type == TYPE_BOOT_PROGRESS)
Jeff Brownbfcb60a2011-09-08 18:51:14 -07003511 && ((fl & FLAG_FULLSCREEN) != 0)) {
3512 // Fullscreen secure system overlays get what they ask for.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003513 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3514 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3515 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
3516 + mOverscanScreenWidth;
3517 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
3518 + mOverscanScreenHeight;
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07003519 } else if (attrs.type == TYPE_BOOT_PROGRESS
3520 || attrs.type == TYPE_UNIVERSE_BACKGROUND) {
Dianne Hackborn01011c32012-02-21 13:54:21 -08003521 // Boot progress screen always covers entire display.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003522 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3523 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3524 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
3525 + mOverscanScreenWidth;
3526 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
3527 + mOverscanScreenHeight;
John Spurlockef4adae2013-08-26 17:58:58 -04003528 } else if (attrs.type == TYPE_WALLPAPER) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07003529 // The wallpaper also has Real Ultimate Power, but we want to tell
3530 // it about the overscan area.
3531 pf.left = df.left = mOverscanScreenLeft;
3532 pf.top = df.top = mOverscanScreenTop;
3533 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
3534 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
3535 of.left = cf.left = mUnrestrictedScreenLeft;
3536 of.top = cf.top = mUnrestrictedScreenTop;
3537 of.right = cf.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3538 of.bottom = cf.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlock46646232013-09-30 22:32:42 -04003539 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08003540 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3541 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3542 // Asking to layout into the overscan region, so give it that pure
3543 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003544 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3545 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3546 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08003547 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003548 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003549 = mOverscanScreenTop + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003550 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003551 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Craig Mautnerbeac1062014-06-03 14:38:57 -07003552 && (attrs.type == TYPE_STATUS_BAR
3553 || attrs.type == TYPE_TOAST
John Spurlock34e13d92013-08-10 06:52:28 -04003554 || (attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3555 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW))) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003556 // Asking for layout as if the nav bar is hidden, lets the
3557 // application extend into the unrestricted screen area. We
John Spurlock34e13d92013-08-10 06:52:28 -04003558 // only do this for application windows (or toasts) to ensure no window that
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003559 // can be above the nav bar can do this.
3560 // XXX This assumes that an app asking for this will also
3561 // ask for layout in only content. We can't currently figure out
3562 // what the screen would be if only laying out to hide the nav bar.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003563 pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft;
3564 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
3565 pf.right = df.right = of.right = cf.right = mUnrestrictedScreenLeft
3566 + mUnrestrictedScreenWidth;
3567 pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop
3568 + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003569 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003570 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
3571 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
3572 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
3573 + mRestrictedScreenWidth;
3574 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
3575 + mRestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003576 }
Craig Mautner69b08182012-09-05 13:07:13 -07003577
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003578 applyStableConstraints(sysUiFl, fl, cf);
Craig Mautner69b08182012-09-05 13:07:13 -07003579
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003580 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3581 vf.left = mCurLeft;
3582 vf.top = mCurTop;
3583 vf.right = mCurRight;
3584 vf.bottom = mCurBottom;
3585 } else {
3586 vf.set(cf);
3587 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003588 } else if (attached != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07003589 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3590 "): attached to " + attached);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003591 // A child window should be placed inside of the same visible
3592 // frame that its parent had.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003593 setAttachedWindowFrames(win, fl, adjust, attached, false, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003594 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07003595 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3596 "): normal window");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003597 // Otherwise, a normal window must be placed inside the content
3598 // of all screen decorations.
Dianne Hackborna239c842011-06-01 12:28:20 -07003599 if (attrs.type == TYPE_STATUS_BAR_PANEL) {
3600 // Status bar panels are the only windows who can go on top of
3601 // the status bar. They are protected by the STATUS_BAR_SERVICE
3602 // permission, so they have the same privileges as the status
3603 // bar itself.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003604 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
3605 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
3606 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
3607 + mRestrictedScreenWidth;
3608 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
3609 + mRestrictedScreenHeight;
John Spurlock414c1f02013-12-04 13:47:36 -05003610 } else if (attrs.type == TYPE_TOAST || attrs.type == TYPE_SYSTEM_ALERT
3611 || attrs.type == TYPE_VOLUME_OVERLAY) {
3612 // These dialogs are stable to interim decor changes.
John Spurlockbd957402013-10-03 11:38:39 -04003613 pf.left = df.left = of.left = cf.left = mStableLeft;
3614 pf.top = df.top = of.top = cf.top = mStableTop;
3615 pf.right = df.right = of.right = cf.right = mStableRight;
3616 pf.bottom = df.bottom = of.bottom = cf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003617 } else {
Dianne Hackborna239c842011-06-01 12:28:20 -07003618 pf.left = mContentLeft;
3619 pf.top = mContentTop;
3620 pf.right = mContentRight;
3621 pf.bottom = mContentBottom;
Dianne Hackborn20d94742014-05-29 18:35:45 -07003622 if (win.isVoiceInteraction()) {
3623 df.left = of.left = cf.left = mVoiceContentLeft;
3624 df.top = of.top = cf.top = mVoiceContentTop;
3625 df.right = of.right = cf.right = mVoiceContentRight;
3626 df.bottom = of.bottom = cf.bottom = mVoiceContentBottom;
3627 } else if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003628 df.left = of.left = cf.left = mDockLeft;
3629 df.top = of.top = cf.top = mDockTop;
3630 df.right = of.right = cf.right = mDockRight;
3631 df.bottom = of.bottom = cf.bottom = mDockBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07003632 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003633 df.left = of.left = cf.left = mContentLeft;
3634 df.top = of.top = cf.top = mContentTop;
3635 df.right = of.right = cf.right = mContentRight;
3636 df.bottom = of.bottom = cf.bottom = mContentBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07003637 }
3638 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3639 vf.left = mCurLeft;
3640 vf.top = mCurTop;
3641 vf.right = mCurRight;
3642 vf.bottom = mCurBottom;
3643 } else {
3644 vf.set(cf);
3645 }
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003646 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003647 }
3648 }
Craig Mautner69b08182012-09-05 13:07:13 -07003649
Craig Mautnerb816bed2013-07-23 10:26:17 -07003650 // TYPE_SYSTEM_ERROR is above the NavigationBar so it can't be allowed to extend over it.
3651 if ((fl & FLAG_LAYOUT_NO_LIMITS) != 0 && attrs.type != TYPE_SYSTEM_ERROR) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07003652 df.left = df.top = -10000;
3653 df.right = df.bottom = 10000;
3654 if (attrs.type != TYPE_WALLPAPER) {
3655 of.left = of.top = cf.left = cf.top = vf.left = vf.top = -10000;
3656 of.right = of.bottom = cf.right = cf.bottom = vf.right = vf.bottom = 10000;
3657 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003658 }
3659
Craig Mautnereda67292013-04-28 13:50:14 -07003660 if (DEBUG_LAYOUT) Slog.v(TAG, "Compute frame " + attrs.getTitle()
The Android Open Source Project11267662009-03-18 17:39:47 -07003661 + ": sim=#" + Integer.toHexString(sim)
RoboErik8a2cfc32014-05-16 11:19:38 -07003662 + " attach=" + attached + " type=" + attrs.type
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003663 + String.format(" flags=0x%08x", fl)
The Android Open Source Project11267662009-03-18 17:39:47 -07003664 + " pf=" + pf.toShortString() + " df=" + df.toShortString()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003665 + " of=" + of.toShortString()
John Spurlock46646232013-09-30 22:32:42 -04003666 + " cf=" + cf.toShortString() + " vf=" + vf.toShortString()
Adrian Roosfa104232014-06-20 16:10:14 -07003667 + " dcf=" + dcf.toShortString()
3668 + " sf=" + sf.toShortString());
Craig Mautner69b08182012-09-05 13:07:13 -07003669
Adrian Roosfa104232014-06-20 16:10:14 -07003670 win.computeFrameLw(pf, df, of, cf, vf, dcf, sf);
Craig Mautner69b08182012-09-05 13:07:13 -07003671
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003672 // Dock windows carve out the bottom of the screen, so normal windows
3673 // can't appear underneath them.
Craig Mautner8bd206b2012-10-03 10:32:02 -07003674 if (attrs.type == TYPE_INPUT_METHOD && win.isVisibleOrBehindKeyguardLw()
3675 && !win.getGivenInsetsPendingLw()) {
satok1bc0a492012-04-25 22:47:12 +09003676 setLastInputMethodWindowLw(null, null);
3677 offsetInputMethodWindowLw(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003678 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003679 if (attrs.type == TYPE_VOICE_INTERACTION && win.isVisibleOrBehindKeyguardLw()
3680 && !win.getGivenInsetsPendingLw()) {
3681 offsetVoiceInputWindowLw(win);
3682 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003683 }
3684
satok1bc0a492012-04-25 22:47:12 +09003685 private void offsetInputMethodWindowLw(WindowState win) {
3686 int top = win.getContentFrameLw().top;
3687 top += win.getGivenContentInsetsLw().top;
3688 if (mContentBottom > top) {
3689 mContentBottom = top;
3690 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003691 if (mVoiceContentBottom > top) {
3692 mVoiceContentBottom = top;
3693 }
satok1bc0a492012-04-25 22:47:12 +09003694 top = win.getVisibleFrameLw().top;
3695 top += win.getGivenVisibleInsetsLw().top;
3696 if (mCurBottom > top) {
3697 mCurBottom = top;
3698 }
Craig Mautnereda67292013-04-28 13:50:14 -07003699 if (DEBUG_LAYOUT) Slog.v(TAG, "Input method: mDockBottom="
satok1bc0a492012-04-25 22:47:12 +09003700 + mDockBottom + " mContentBottom="
3701 + mContentBottom + " mCurBottom=" + mCurBottom);
3702 }
3703
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003704 private void offsetVoiceInputWindowLw(WindowState win) {
3705 final int gravity = win.getAttrs().gravity;
3706 switch (gravity&((Gravity.AXIS_PULL_BEFORE|Gravity.AXIS_PULL_AFTER)
3707 << Gravity.AXIS_X_SHIFT)) {
3708 case Gravity.AXIS_PULL_BEFORE<<Gravity.AXIS_X_SHIFT: {
3709 int right = win.getContentFrameLw().right - win.getGivenContentInsetsLw().right;
3710 if (mVoiceContentLeft < right) {
3711 mVoiceContentLeft = right;
3712 }
3713 } break;
3714 case Gravity.AXIS_PULL_AFTER<<Gravity.AXIS_X_SHIFT: {
3715 int left = win.getContentFrameLw().left - win.getGivenContentInsetsLw().left;
3716 if (mVoiceContentRight < left) {
3717 mVoiceContentRight = left;
3718 }
3719 } break;
3720 }
3721 switch (gravity&((Gravity.AXIS_PULL_BEFORE|Gravity.AXIS_PULL_AFTER)
3722 << Gravity.AXIS_Y_SHIFT)) {
3723 case Gravity.AXIS_PULL_BEFORE<<Gravity.AXIS_Y_SHIFT: {
3724 int bottom = win.getContentFrameLw().bottom - win.getGivenContentInsetsLw().bottom;
3725 if (mVoiceContentTop < bottom) {
3726 mVoiceContentTop = bottom;
3727 }
3728 } break;
3729 case Gravity.AXIS_PULL_AFTER<<Gravity.AXIS_Y_SHIFT: {
3730 int top = win.getContentFrameLw().top - win.getGivenContentInsetsLw().top;
3731 if (mVoiceContentBottom < top) {
3732 mVoiceContentBottom = top;
3733 }
3734 } break;
3735 }
3736 }
3737
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003738 /** {@inheritDoc} */
Craig Mautner61ac6bb2012-02-02 17:29:33 -08003739 @Override
3740 public void finishLayoutLw() {
3741 return;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003742 }
3743
3744 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003745 @Override
Craig Mautner39834192012-09-02 07:47:24 -07003746 public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) {
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003747 mTopFullscreenOpaqueWindowState = null;
Craig Mautner2bc789b2014-03-19 19:48:38 -07003748 mAppsToBeHidden.clear();
Jorim Jaggic13fcac2014-09-11 17:36:57 +02003749 mAppsThatDismissKeyguard.clear();
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003750 mForceStatusBar = false;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003751 mForceStatusBarFromKeyguard = false;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08003752 mForcingShowNavBar = false;
3753 mForcingShowNavBarLayer = -1;
RoboErik8a2cfc32014-05-16 11:19:38 -07003754
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003755 mHideLockScreen = false;
3756 mAllowLockscreenWhenOn = false;
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003757 mDismissKeyguard = DISMISS_KEYGUARD_NONE;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003758 mShowingLockscreen = false;
3759 mShowingDream = false;
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003760 mWinShowWhenLocked = null;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003761 }
3762
3763 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003764 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003765 public void applyPostLayoutPolicyLw(WindowState win, WindowManager.LayoutParams attrs) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07003766 if (DEBUG_LAYOUT) Slog.i(TAG, "Win " + win + ": isVisibleOrBehindKeyguardLw="
3767 + win.isVisibleOrBehindKeyguardLw());
John Spurlockc6d1c602014-01-17 15:22:06 -05003768 final int fl = PolicyControl.getWindowFlags(win, attrs);
John Spurlock414c1f02013-12-04 13:47:36 -05003769 if (mTopFullscreenOpaqueWindowState == null
3770 && win.isVisibleLw() && attrs.type == TYPE_INPUT_METHOD) {
3771 mForcingShowNavBar = true;
3772 mForcingShowNavBarLayer = win.getSurfaceLayer();
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08003773 }
Jorim Jaggiafd4a552014-04-08 15:13:05 +02003774 if (attrs.type == TYPE_STATUS_BAR && (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Jorim Jaggiafd4a552014-04-08 15:13:05 +02003775 mForceStatusBarFromKeyguard = true;
3776 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003777 if (mTopFullscreenOpaqueWindowState == null &&
Dianne Hackborn01b02a72012-01-12 14:05:03 -08003778 win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()) {
John Spurlockc6d1c602014-01-17 15:22:06 -05003779 if ((fl & FLAG_FORCE_NOT_FULLSCREEN) != 0) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003780 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003781 mForceStatusBarFromKeyguard = true;
3782 } else {
3783 mForceStatusBar = true;
3784 }
3785 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003786 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003787 mShowingLockscreen = true;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07003788 }
Craig Mautnerab55e522014-03-03 13:26:03 -08003789 boolean appWindow = attrs.type >= FIRST_APPLICATION_WINDOW
Craig Mautner7d7808f2014-09-11 18:02:38 -07003790 && attrs.type < FIRST_SYSTEM_WINDOW;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003791 if (attrs.type == TYPE_DREAM) {
Jeff Brownc8018eb2012-10-29 21:33:27 -07003792 // If the lockscreen was showing when the dream started then wait
3793 // for the dream to draw before hiding the lockscreen.
3794 if (!mDreamingLockscreen
3795 || (win.isVisibleLw() && win.hasDrawnLw())) {
3796 mShowingDream = true;
Craig Mautnerab55e522014-03-03 13:26:03 -08003797 appWindow = true;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003798 }
3799 }
Craig Mautnerab55e522014-03-03 13:26:03 -08003800
Craig Mautner00156ec2014-03-06 22:29:02 -08003801 final boolean showWhenLocked = (fl & FLAG_SHOW_WHEN_LOCKED) != 0;
Craig Mautner74ee9382014-04-01 15:20:16 -07003802 final boolean dismissKeyguard = (fl & FLAG_DISMISS_KEYGUARD) != 0;
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003803 final boolean secureKeyguard = isKeyguardSecure();
Craig Mautnerab55e522014-03-03 13:26:03 -08003804 if (appWindow) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02003805 final IApplicationToken appToken = win.getAppToken();
3806 if (showWhenLocked) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003807 // Remove any previous windows with the same appToken.
Jorim Jaggic13fcac2014-09-11 17:36:57 +02003808 mAppsToBeHidden.remove(appToken);
3809 mAppsThatDismissKeyguard.remove(appToken);
3810 if (mAppsToBeHidden.isEmpty() && isKeyguardSecureIncludingHidden()) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003811 mWinShowWhenLocked = win;
3812 mHideLockScreen = true;
3813 mForceStatusBarFromKeyguard = false;
3814 }
Jorim Jaggic13fcac2014-09-11 17:36:57 +02003815 } else if (dismissKeyguard) {
3816 if (secureKeyguard) {
3817 mAppsToBeHidden.add(appToken);
3818 } else {
3819 mAppsToBeHidden.remove(appToken);
3820 }
3821 mAppsThatDismissKeyguard.add(appToken);
Craig Mautner2bc789b2014-03-19 19:48:38 -07003822 } else {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02003823 mAppsToBeHidden.add(appToken);
Craig Mautner2bc789b2014-03-19 19:48:38 -07003824 }
Craig Mautnerab55e522014-03-03 13:26:03 -08003825 if (attrs.x == 0 && attrs.y == 0
3826 && attrs.width == WindowManager.LayoutParams.MATCH_PARENT
3827 && attrs.height == WindowManager.LayoutParams.MATCH_PARENT) {
3828 if (DEBUG_LAYOUT) Slog.v(TAG, "Fullscreen window: " + win);
3829 mTopFullscreenOpaqueWindowState = win;
Jorim Jaggic13fcac2014-09-11 17:36:57 +02003830 if (!mAppsThatDismissKeyguard.isEmpty() &&
3831 mDismissKeyguard == DISMISS_KEYGUARD_NONE) {
3832 if (DEBUG_LAYOUT) Slog.v(TAG,
3833 "Setting mDismissKeyguard true by win " + win);
3834 mDismissKeyguard = mWinDismissingKeyguard == win ?
3835 DISMISS_KEYGUARD_CONTINUE : DISMISS_KEYGUARD_START;
3836 mWinDismissingKeyguard = win;
3837 mForceStatusBarFromKeyguard = mShowingLockscreen && secureKeyguard;
3838 } else if (mAppsToBeHidden.isEmpty() && showWhenLocked) {
3839 if (DEBUG_LAYOUT) Slog.v(TAG,
3840 "Setting mHideLockScreen to true by win " + win);
3841 mHideLockScreen = true;
3842 mForceStatusBarFromKeyguard = false;
Craig Mautnerab55e522014-03-03 13:26:03 -08003843 }
Craig Mautner00156ec2014-03-06 22:29:02 -08003844 if ((fl & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) {
Craig Mautnerab55e522014-03-03 13:26:03 -08003845 mAllowLockscreenWhenOn = true;
3846 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003847 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003848
3849 if (mWinShowWhenLocked != null &&
3850 mWinShowWhenLocked.getAppToken() != win.getAppToken()) {
3851 win.hideLw(false);
3852 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003853 }
3854 }
3855 }
3856
3857 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003858 @Override
Craig Mautner39834192012-09-02 07:47:24 -07003859 public int finishPostLayoutPolicyLw() {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003860 if (mWinShowWhenLocked != null &&
3861 mWinShowWhenLocked != mTopFullscreenOpaqueWindowState) {
3862 // A dialog is dismissing the keyguard. Put the wallpaper behind it and hide the
3863 // fullscreen window.
3864 // TODO: Make sure FLAG_SHOW_WALLPAPER is restored when dialog is dismissed. Or not.
3865 mWinShowWhenLocked.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
3866 mTopFullscreenOpaqueWindowState.hideLw(false);
3867 mTopFullscreenOpaqueWindowState = mWinShowWhenLocked;
3868 }
3869
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003870 int changes = 0;
Joe Onorato93056472010-09-10 10:30:46 -04003871 boolean topIsFullscreen = false;
Daniel Sandlere02d8082010-10-08 15:13:22 -04003872
3873 final WindowManager.LayoutParams lp = (mTopFullscreenOpaqueWindowState != null)
3874 ? mTopFullscreenOpaqueWindowState.getAttrs()
3875 : null;
3876
Jeff Brownc8018eb2012-10-29 21:33:27 -07003877 // If we are not currently showing a dream then remember the current
3878 // lockscreen state. We will use this to determine whether the dream
3879 // started while the lockscreen was showing and remember this state
3880 // while the dream is showing.
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003881 if (!mShowingDream) {
3882 mDreamingLockscreen = mShowingLockscreen;
3883 }
3884
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003885 if (mStatusBar != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07003886 if (DEBUG_LAYOUT) Slog.i(TAG, "force=" + mForceStatusBar
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003887 + " forcefkg=" + mForceStatusBarFromKeyguard
Dianne Hackbornd70bc2f2009-10-06 23:25:51 -07003888 + " top=" + mTopFullscreenOpaqueWindowState);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003889 if (mForceStatusBar || mForceStatusBarFromKeyguard) {
Craig Mautnereda67292013-04-28 13:50:14 -07003890 if (DEBUG_LAYOUT) Slog.v(TAG, "Showing status bar: forced");
John Spurlock27735a42013-08-14 17:57:38 -04003891 if (mStatusBarController.setBarShowingLw(true)) {
3892 changes |= FINISH_LAYOUT_REDO_LAYOUT;
3893 }
Craig Mautner81defc72013-10-29 11:10:42 -07003894 // Maintain fullscreen layout until incoming animation is complete.
3895 topIsFullscreen = mTopIsFullscreen && mStatusBar.isAnimatingLw();
John Spurlockf92b6162013-11-11 15:01:16 -05003896 // Transient status bar on the lockscreen is not allowed
3897 if (mForceStatusBarFromKeyguard && mStatusBarController.isTransientShowing()) {
3898 mStatusBarController.updateVisibilityLw(false /*transientAllowed*/,
3899 mLastSystemUiFlags, mLastSystemUiFlags);
3900 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003901 } else if (mTopFullscreenOpaqueWindowState != null) {
John Spurlockc6d1c602014-01-17 15:22:06 -05003902 final int fl = PolicyControl.getWindowFlags(null, lp);
Joe Onorato93056472010-09-10 10:30:46 -04003903 if (localLOGV) {
Craig Mautnereda67292013-04-28 13:50:14 -07003904 Slog.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw()
Joe Onorato93056472010-09-10 10:30:46 -04003905 + " shown frame: " + mTopFullscreenOpaqueWindowState.getShownFrameLw());
Craig Mautnereda67292013-04-28 13:50:14 -07003906 Slog.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs()
John Spurlockc6d1c602014-01-17 15:22:06 -05003907 + " lp.flags=0x" + Integer.toHexString(fl));
Joe Onorato93056472010-09-10 10:30:46 -04003908 }
John Spurlockc6d1c602014-01-17 15:22:06 -05003909 topIsFullscreen = (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003910 || (mLastSystemUiFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
Joe Onorato93056472010-09-10 10:30:46 -04003911 // The subtle difference between the window for mTopFullscreenOpaqueWindowState
3912 // and mTopIsFullscreen is that that mTopIsFullscreen is set only if the window
3913 // has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the
3914 // case though.
John Spurlock27735a42013-08-14 17:57:38 -04003915 if (mStatusBarController.isTransientShowing()) {
3916 if (mStatusBarController.setBarShowingLw(true)) {
John Spurlock32beb2c2013-03-11 10:16:47 -04003917 changes |= FINISH_LAYOUT_REDO_LAYOUT;
3918 }
3919 } else if (topIsFullscreen) {
Craig Mautnereda67292013-04-28 13:50:14 -07003920 if (DEBUG_LAYOUT) Slog.v(TAG, "** HIDING status bar");
John Spurlock27735a42013-08-14 17:57:38 -04003921 if (mStatusBarController.setBarShowingLw(false)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003922 changes |= FINISH_LAYOUT_REDO_LAYOUT;
Craig Mautnereda67292013-04-28 13:50:14 -07003923 } else {
Craig Mautnerc5a6e442013-06-05 17:22:35 -07003924 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar already hiding");
Daniel Sandler40427442010-07-16 11:44:52 -04003925 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003926 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07003927 if (DEBUG_LAYOUT) Slog.v(TAG, "** SHOWING status bar: top is not fullscreen");
John Spurlock27735a42013-08-14 17:57:38 -04003928 if (mStatusBarController.setBarShowingLw(true)) {
3929 changes |= FINISH_LAYOUT_REDO_LAYOUT;
3930 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003931 }
3932 }
3933 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04003934
Craig Mautner81defc72013-10-29 11:10:42 -07003935 if (mTopIsFullscreen != topIsFullscreen) {
3936 if (!topIsFullscreen) {
3937 // Force another layout when status bar becomes fully shown.
3938 changes |= FINISH_LAYOUT_REDO_LAYOUT;
3939 }
3940 mTopIsFullscreen = topIsFullscreen;
3941 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04003942
Craig Mautner39834192012-09-02 07:47:24 -07003943 // Hide the key guard if a visible window explicitly specifies that it wants to be
3944 // displayed when the screen is locked.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01003945 if (mKeyguardDelegate != null && mStatusBar != null) {
3946 if (localLOGV) Slog.v(TAG, "finishPostLayoutPolicyLw: mHideKeyguard="
3947 + mHideLockScreen);
3948 if (mDismissKeyguard != DISMISS_KEYGUARD_NONE && !isKeyguardSecure()) {
3949 mKeyguardHidden = true;
3950 if (processKeyguardSetHiddenResultLw(mKeyguardDelegate.setOccluded(true))) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003951 changes |= FINISH_LAYOUT_REDO_LAYOUT
3952 | FINISH_LAYOUT_REDO_CONFIG
3953 | FINISH_LAYOUT_REDO_WALLPAPER;
3954 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01003955 if (mKeyguardDelegate.isShowing()) {
3956 mHandler.post(new Runnable() {
3957 @Override
3958 public void run() {
3959 mKeyguardDelegate.keyguardDone(false, false);
3960 }
3961 });
3962 }
3963 } else if (mHideLockScreen) {
3964 mKeyguardHidden = true;
3965 if (processKeyguardSetHiddenResultLw(mKeyguardDelegate.setOccluded(true))) {
3966 changes |= FINISH_LAYOUT_REDO_LAYOUT
3967 | FINISH_LAYOUT_REDO_CONFIG
3968 | FINISH_LAYOUT_REDO_WALLPAPER;
3969 }
3970 } else if (mDismissKeyguard != DISMISS_KEYGUARD_NONE) {
3971 // This is the case of keyguard isSecure() and not mHideLockScreen.
3972 if (mDismissKeyguard == DISMISS_KEYGUARD_START) {
3973 // Only launch the next keyguard unlock window once per window.
3974 mKeyguardHidden = false;
3975 if (processKeyguardSetHiddenResultLw(mKeyguardDelegate.setOccluded(false))) {
3976 changes |= FINISH_LAYOUT_REDO_LAYOUT
3977 | FINISH_LAYOUT_REDO_CONFIG
3978 | FINISH_LAYOUT_REDO_WALLPAPER;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003979 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01003980 mHandler.post(new Runnable() {
3981 @Override
3982 public void run() {
3983 mKeyguardDelegate.dismiss();
3984 }
3985 });
3986 }
3987 } else {
3988 mWinDismissingKeyguard = null;
3989 mKeyguardHidden = false;
3990 if (processKeyguardSetHiddenResultLw(mKeyguardDelegate.setOccluded(false))) {
3991 changes |= FINISH_LAYOUT_REDO_LAYOUT
3992 | FINISH_LAYOUT_REDO_CONFIG
3993 | FINISH_LAYOUT_REDO_WALLPAPER;
3994 }
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -07003995 }
3996 }
Joe Onorato664644d2011-01-23 17:53:23 -08003997
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003998 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003999 // If the navigation bar has been hidden or shown, we need to do another
4000 // layout pass to update that window.
4001 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4002 }
Joe Onorato664644d2011-01-23 17:53:23 -08004003
Mike Lockwood28569302010-01-28 11:54:40 -05004004 // update since mAllowLockscreenWhenOn might have changed
4005 updateLockScreenTimeout();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004006 return changes;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004007 }
4008
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004009 /**
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004010 * Processes the result code of {@link IKeyguardService#setOccluded}. This is needed because we
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004011 * immediately need to put the wallpaper directly behind the Keyguard when a window with flag
4012 * {@link android.view.WindowManager.LayoutParams#FLAG_SHOW_WHEN_LOCKED} gets dismissed. If we
4013 * would wait for Keyguard to change the flags, that would be running asynchronously and thus be
4014 * too late so the user might see the window behind.
4015 *
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004016 * @param setHiddenResult The result code from {@link IKeyguardService#setOccluded}.
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004017 * @return Whether the flags have changed and we have to redo the layout.
4018 */
4019 private boolean processKeyguardSetHiddenResultLw(int setHiddenResult) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004020 if (setHiddenResult
4021 == IKeyguardServiceConstants.KEYGUARD_SERVICE_SET_OCCLUDED_RESULT_SET_FLAGS) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004022 mStatusBar.getAttrs().privateFlags |= PRIVATE_FLAG_KEYGUARD;
4023 mStatusBar.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
4024 return true;
4025 } else if (setHiddenResult
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004026 == IKeyguardServiceConstants.KEYGUARD_SERVICE_SET_OCCLUDED_RESULT_UNSET_FLAGS) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004027 mStatusBar.getAttrs().privateFlags &= ~PRIVATE_FLAG_KEYGUARD;
4028 mStatusBar.getAttrs().flags &= ~FLAG_SHOW_WALLPAPER;
4029 return true;
4030 } else {
4031 return false;
4032 }
4033 }
4034
4035 private boolean isStatusBarKeyguard() {
4036 return mStatusBar != null
4037 && (mStatusBar.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
4038 }
4039
Jose Lima9546b202014-07-02 17:21:51 -07004040 @Override
Dianne Hackborn08743722009-12-21 12:16:51 -08004041 public boolean allowAppAnimationsLw() {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004042 if (isStatusBarKeyguard() || mShowingDream) {
Craig Mautner28816302013-10-10 20:31:00 -07004043 // If keyguard or dreams is currently visible, no reason to animate behind it.
Dianne Hackborn08743722009-12-21 12:16:51 -08004044 return false;
4045 }
Dianne Hackborn08743722009-12-21 12:16:51 -08004046 return true;
4047 }
4048
Jose Lima9546b202014-07-02 17:21:51 -07004049 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07004050 public int focusChangedLw(WindowState lastFocus, WindowState newFocus) {
Joe Onorato664644d2011-01-23 17:53:23 -08004051 mFocusedWindow = newFocus;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004052 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004053 // If the navigation bar has been hidden or shown, we need to do another
4054 // layout pass to update that window.
4055 return FINISH_LAYOUT_REDO_LAYOUT;
4056 }
4057 return 0;
Joe Onorato664644d2011-01-23 17:53:23 -08004058 }
4059
Dianne Hackborn0ecadf72009-03-31 18:00:37 -07004060 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07004061 @Override
Jeff Brown46b9ac02010-04-22 18:58:52 -07004062 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
4063 // lid changed state
Jeff Brownc458ce92012-04-30 14:58:40 -07004064 final int newLidState = lidOpen ? LID_OPEN : LID_CLOSED;
4065 if (newLidState == mLidState) {
4066 return;
4067 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004068
Jeff Brownc458ce92012-04-30 14:58:40 -07004069 mLidState = newLidState;
4070 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07004071 updateRotation(true);
Jeff Brownc458ce92012-04-30 14:58:40 -07004072
4073 if (lidOpen) {
Jim Millere51cf7ae2013-06-25 18:31:56 -07004074 mPowerManager.wakeUp(SystemClock.uptimeMillis());
Jeff Brownc458ce92012-04-30 14:58:40 -07004075 } else if (!mLidControlsSleep) {
Jeff Brown96307042012-07-27 15:51:34 -07004076 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
Jeff Brown46b9ac02010-04-22 18:58:52 -07004077 }
4078 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004079
Michael Wright3818c922014-09-02 13:59:07 -07004080 @Override
4081 public void notifyCameraLensCoverSwitchChanged(long whenNanos, boolean lensCovered) {
4082 int lensCoverState = lensCovered ? CAMERA_LENS_COVERED : CAMERA_LENS_UNCOVERED;
4083 if (mCameraLensCoverState == lensCoverState) {
4084 return;
4085 }
4086 if (mCameraLensCoverState == CAMERA_LENS_COVERED &&
4087 lensCoverState == CAMERA_LENS_UNCOVERED) {
4088 Intent intent;
4089 final boolean keyguardActive = mKeyguardDelegate == null ? false :
4090 mKeyguardDelegate.isShowing();
4091 if (keyguardActive) {
4092 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE);
4093 } else {
4094 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
4095 }
4096 mContext.startActivityAsUser(intent, UserHandle.CURRENT_OR_SELF);
4097 }
4098 mCameraLensCoverState = lensCoverState;
4099 }
4100
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004101 void setHdmiPlugged(boolean plugged) {
4102 if (mHdmiPlugged != plugged) {
4103 mHdmiPlugged = plugged;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004104 updateRotation(true, true);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004105 Intent intent = new Intent(ACTION_HDMI_PLUGGED);
Joe Onoratodc100302011-01-11 17:07:41 -08004106 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004107 intent.putExtra(EXTRA_HDMI_PLUGGED_STATE, plugged);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07004108 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004109 }
4110 }
4111
Joe Onoratoea495d42011-04-06 11:41:11 -07004112 void initializeHdmiState() {
Joe Onorato7ba631f2011-05-04 15:28:00 -07004113 boolean plugged = false;
Joe Onoratoea495d42011-04-06 11:41:11 -07004114 // watch for HDMI plug messages if the hdmi switch exists
4115 if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) {
4116 mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi");
4117
Joe Onoratoea495d42011-04-06 11:41:11 -07004118 final String filename = "/sys/class/switch/hdmi/state";
4119 FileReader reader = null;
4120 try {
4121 reader = new FileReader(filename);
4122 char[] buf = new char[15];
4123 int n = reader.read(buf);
4124 if (n > 1) {
4125 plugged = 0 != Integer.parseInt(new String(buf, 0, n-1));
4126 }
4127 } catch (IOException ex) {
4128 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
4129 } catch (NumberFormatException ex) {
4130 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
4131 } finally {
4132 if (reader != null) {
4133 try {
4134 reader.close();
4135 } catch (IOException ex) {
4136 }
Joe Onoratodc100302011-01-11 17:07:41 -08004137 }
4138 }
4139 }
Joe Onorato7ba631f2011-05-04 15:28:00 -07004140 // This dance forces the code in setHdmiPlugged to run.
4141 // Always do this so the sticky intent is stuck (to false) if there is no hdmi.
4142 mHdmiPlugged = !plugged;
4143 setHdmiPlugged(!mHdmiPlugged);
Joe Onoratodc100302011-01-11 17:07:41 -08004144 }
4145
Dianne Hackbornc0e3f242011-08-19 14:19:10 -07004146 final Object mScreenshotLock = new Object();
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004147 ServiceConnection mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004148
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004149 final Runnable mScreenshotTimeout = new Runnable() {
4150 @Override public void run() {
4151 synchronized (mScreenshotLock) {
4152 if (mScreenshotConnection != null) {
4153 mContext.unbindService(mScreenshotConnection);
4154 mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004155 }
Winson Chung9112ec32011-06-27 13:15:32 -07004156 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004157 }
4158 };
4159
4160 // Assume this is called from the Handler thread.
4161 private void takeScreenshot() {
4162 synchronized (mScreenshotLock) {
4163 if (mScreenshotConnection != null) {
4164 return;
4165 }
4166 ComponentName cn = new ComponentName("com.android.systemui",
4167 "com.android.systemui.screenshot.TakeScreenshotService");
4168 Intent intent = new Intent();
4169 intent.setComponent(cn);
4170 ServiceConnection conn = new ServiceConnection() {
4171 @Override
4172 public void onServiceConnected(ComponentName name, IBinder service) {
4173 synchronized (mScreenshotLock) {
4174 if (mScreenshotConnection != this) {
4175 return;
4176 }
4177 Messenger messenger = new Messenger(service);
4178 Message msg = Message.obtain(null, 1);
4179 final ServiceConnection myConn = this;
4180 Handler h = new Handler(mHandler.getLooper()) {
4181 @Override
4182 public void handleMessage(Message msg) {
4183 synchronized (mScreenshotLock) {
4184 if (mScreenshotConnection == myConn) {
4185 mContext.unbindService(mScreenshotConnection);
4186 mScreenshotConnection = null;
4187 mHandler.removeCallbacks(mScreenshotTimeout);
4188 }
4189 }
4190 }
4191 };
4192 msg.replyTo = new Messenger(h);
Winson Chunga63bb842011-10-17 10:26:28 -07004193 msg.arg1 = msg.arg2 = 0;
4194 if (mStatusBar != null && mStatusBar.isVisibleLw())
4195 msg.arg1 = 1;
4196 if (mNavigationBar != null && mNavigationBar.isVisibleLw())
4197 msg.arg2 = 1;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004198 try {
4199 messenger.send(msg);
4200 } catch (RemoteException e) {
4201 }
4202 }
4203 }
4204 @Override
4205 public void onServiceDisconnected(ComponentName name) {}
4206 };
Amith Yamasani27b89e62013-01-16 12:30:11 -08004207 if (mContext.bindServiceAsUser(
4208 intent, conn, Context.BIND_AUTO_CREATE, UserHandle.CURRENT)) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004209 mScreenshotConnection = conn;
4210 mHandler.postDelayed(mScreenshotTimeout, 10000);
4211 }
4212 }
Winson Chung9112ec32011-06-27 13:15:32 -07004213 }
4214
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004215 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004216 @Override
Jeff Brown037c33e2014-04-09 00:31:55 -07004217 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) {
Jeff Brown96307042012-07-27 15:51:34 -07004218 if (!mSystemBooted) {
4219 // If we have not yet booted, don't let key events do anything.
4220 return 0;
4221 }
4222
Jeff Brown037c33e2014-04-09 00:31:55 -07004223 final boolean interactive = (policyFlags & FLAG_INTERACTIVE) != 0;
Jeff Brown1f245102010-11-18 20:53:46 -08004224 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
4225 final boolean canceled = event.isCanceled();
4226 final int keyCode = event.getKeyCode();
Jeff Browne20c9e02010-10-11 14:20:19 -07004227
Jeff Brown3122e442010-10-11 23:32:49 -07004228 final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0;
Jeff Brown3122e442010-10-11 23:32:49 -07004229
Mike Lockwoodc72b15f2009-11-28 20:58:22 -05004230 // If screen is off then we treat the case where the keyguard is open but hidden
4231 // the same as if it were open and in front.
4232 // This will prevent any keys other than the power button from waking the screen
4233 // when the keyguard is hidden by another activity.
Jim Miller5ecd8112013-01-09 18:50:26 -08004234 final boolean keyguardActive = (mKeyguardDelegate == null ? false :
Jeff Brown037c33e2014-04-09 00:31:55 -07004235 (interactive ?
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004236 mKeyguardDelegate.isShowingAndNotOccluded() :
Jim Miller5ecd8112013-01-09 18:50:26 -08004237 mKeyguardDelegate.isShowing()));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004238
Jeff Brown40013652012-05-16 21:22:36 -07004239 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004240 Log.d(TAG, "interceptKeyTq keycode=" + keyCode
Jeff Brown037c33e2014-04-09 00:31:55 -07004241 + " interactive=" + interactive + " keyguardActive=" + keyguardActive
Jeff Brown26875502014-01-30 21:47:47 -08004242 + " policyFlags=" + Integer.toHexString(policyFlags));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004243 }
4244
Jeff Brown037c33e2014-04-09 00:31:55 -07004245 // Basic policy based on interactive state.
Jeff Brown4d396052010-10-29 21:50:21 -07004246 int result;
Michael Wright337d9d22014-04-22 15:03:48 -07004247 boolean isWakeKey = (policyFlags & WindowManagerPolicy.FLAG_WAKE) != 0
4248 || event.isWakeKey();
Michael Wrightfc01f042014-09-08 14:12:24 -07004249 if (interactive || (isInjected && !isWakeKey)) {
4250 // When the device is interactive or the key is injected pass the key to the
4251 // application.
Jeff Brown4d396052010-10-29 21:50:21 -07004252 result = ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07004253 isWakeKey = false;
Michael Wrightfc01f042014-09-08 14:12:24 -07004254 } else if (!interactive && shouldDispatchInputWhenNonInteractive()) {
4255 // If we're currently dozing with the screen on and the keyguard showing, pass the key
4256 // to the application but preserve its wake key status to make sure we still move
4257 // from dozing to fully interactive if we would normally go from off to fully
4258 // interactive.
4259 result = ACTION_PASS_TO_USER;
Jeff Brown4d396052010-10-29 21:50:21 -07004260 } else {
4261 // When the screen is off and the key is not injected, determine whether
4262 // to wake the device but don't pass the key to the application.
4263 result = 0;
Jeff Brown26875502014-01-30 21:47:47 -08004264 if (isWakeKey && (!down || !isWakeKeyWhenScreenOff(keyCode))) {
4265 isWakeKey = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004266 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004267 }
4268
Justin Kohd378ad72013-04-01 12:18:26 -07004269 // If the key would be handled globally, just return the result, don't worry about special
4270 // key processing.
4271 if (mGlobalKeyManager.shouldHandleGlobalKey(keyCode, event)) {
Michael Wright85b1af62014-06-04 14:51:58 -07004272 if (isWakeKey) {
4273 mPowerManager.wakeUp(event.getEventTime());
4274 }
Justin Kohd378ad72013-04-01 12:18:26 -07004275 return result;
4276 }
4277
Jeff Brownbae8e772014-06-12 19:59:45 -07004278 boolean useHapticFeedback = down
4279 && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0
4280 && event.getRepeatCount() == 0;
4281
Jeff Brown4d396052010-10-29 21:50:21 -07004282 // Handle special keys.
4283 switch (keyCode) {
4284 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jeff Brownb0418da2010-11-01 15:24:01 -07004285 case KeyEvent.KEYCODE_VOLUME_UP:
4286 case KeyEvent.KEYCODE_VOLUME_MUTE: {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004287 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
4288 if (down) {
Jeff Brown037c33e2014-04-09 00:31:55 -07004289 if (interactive && !mVolumeDownKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004290 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
4291 mVolumeDownKeyTriggered = true;
4292 mVolumeDownKeyTime = event.getDownTime();
4293 mVolumeDownKeyConsumedByScreenshotChord = false;
4294 cancelPendingPowerKeyAction();
4295 interceptScreenshotChord();
4296 }
4297 } else {
4298 mVolumeDownKeyTriggered = false;
4299 cancelPendingScreenshotChordAction();
4300 }
4301 } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
4302 if (down) {
Jeff Brown037c33e2014-04-09 00:31:55 -07004303 if (interactive && !mVolumeUpKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004304 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
4305 mVolumeUpKeyTriggered = true;
4306 cancelPendingPowerKeyAction();
4307 cancelPendingScreenshotChordAction();
4308 }
4309 } else {
4310 mVolumeUpKeyTriggered = false;
4311 cancelPendingScreenshotChordAction();
4312 }
4313 }
Jeff Brown4d396052010-10-29 21:50:21 -07004314 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004315 TelecomManager telecomManager = getTelecommService();
4316 if (telecomManager != null) {
4317 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07004318 // If an incoming call is ringing, either VOLUME key means
4319 // "silence ringer". We handle these keys here, rather than
4320 // in the InCallScreen, to make sure we'll respond to them
4321 // even if the InCallScreen hasn't come to the foreground yet.
4322 // Look for the DOWN event here, to agree with the "fallback"
4323 // behavior in the InCallScreen.
4324 Log.i(TAG, "interceptKeyBeforeQueueing:"
4325 + " VOLUME key-down while ringing: Silence ringer!");
Jeff Brown4d396052010-10-29 21:50:21 -07004326
Santos Cordon6848f722014-05-21 15:22:12 -07004327 // Silence the ringer. (It's safe to call this
4328 // even if the ringer has already been silenced.)
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004329 telecomManager.silenceRinger();
Jeff Brown4d396052010-10-29 21:50:21 -07004330
Santos Cordon6848f722014-05-21 15:22:12 -07004331 // And *don't* pass this key thru to the current activity
4332 // (which is probably the InCallScreen.)
4333 result &= ~ACTION_PASS_TO_USER;
4334 break;
4335 }
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004336 if (telecomManager.isInCall()
Santos Cordon6848f722014-05-21 15:22:12 -07004337 && (result & ACTION_PASS_TO_USER) == 0) {
4338 // If we are in call but we decided not to pass the key to
RoboErik430fc482014-06-12 15:49:20 -07004339 // the application, just pass it to the session service.
4340
4341 MediaSessionLegacyHelper.getHelper(mContext)
RoboErik3c45c292014-07-08 16:47:31 -07004342 .sendVolumeKeyEvent(event, false);
Santos Cordon6848f722014-05-21 15:22:12 -07004343 break;
Jeff Brown4d396052010-10-29 21:50:21 -07004344 }
4345 }
4346
RoboErik430fc482014-06-12 15:49:20 -07004347 if ((result & ACTION_PASS_TO_USER) == 0) {
4348 // If we aren't passing to the user and no one else
4349 // handled it send it to the session manager to figure
4350 // out.
4351 MediaSessionLegacyHelper.getHelper(mContext)
RoboErik3c45c292014-07-08 16:47:31 -07004352 .sendVolumeKeyEvent(event, true);
Jeff Brown4d396052010-10-29 21:50:21 -07004353 break;
4354 }
4355 }
4356 break;
4357 }
4358
4359 case KeyEvent.KEYCODE_ENDCALL: {
4360 result &= ~ACTION_PASS_TO_USER;
4361 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004362 TelecomManager telecomManager = getTelecommService();
Jeff Brown4d396052010-10-29 21:50:21 -07004363 boolean hungUp = false;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004364 if (telecomManager != null) {
4365 hungUp = telecomManager.endCall();
Jeff Brown4d396052010-10-29 21:50:21 -07004366 }
Jeff Brown037c33e2014-04-09 00:31:55 -07004367 interceptPowerKeyDown(!interactive || hungUp);
Jeff Brown4d396052010-10-29 21:50:21 -07004368 } else {
4369 if (interceptPowerKeyUp(canceled)) {
4370 if ((mEndcallBehavior
4371 & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) {
4372 if (goHome()) {
4373 break;
Dianne Hackborn0041e972009-07-24 17:14:43 -07004374 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004375 }
Jeff Brown4d396052010-10-29 21:50:21 -07004376 if ((mEndcallBehavior
4377 & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) {
Jeff Brownc12035c2014-08-13 18:52:25 -07004378 mPowerManager.goToSleep(event.getEventTime(),
4379 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
Jeff Brown26875502014-01-30 21:47:47 -08004380 isWakeKey = false;
Jeff Brown4d396052010-10-29 21:50:21 -07004381 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004382 }
Jeff Brown4d396052010-10-29 21:50:21 -07004383 }
4384 break;
4385 }
4386
4387 case KeyEvent.KEYCODE_POWER: {
4388 result &= ~ACTION_PASS_TO_USER;
4389 if (down) {
Jeff Brown26c6a502014-04-11 02:15:54 -07004390 boolean panic = mImmersiveModeConfirmation.onPowerKeyDown(interactive,
John Spurlockd9b70bd2014-02-06 17:02:44 -05004391 event.getDownTime(), isImmersiveMode(mLastSystemUiFlags));
4392 if (panic) {
4393 mHandler.post(mRequestTransientNav);
4394 }
Jeff Brown037c33e2014-04-09 00:31:55 -07004395 if (interactive && !mPowerKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004396 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
4397 mPowerKeyTriggered = true;
4398 mPowerKeyTime = event.getDownTime();
4399 interceptScreenshotChord();
Winson Chung9112ec32011-06-27 13:15:32 -07004400 }
Winson Chung9112ec32011-06-27 13:15:32 -07004401
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004402 TelecomManager telecomManager = getTelecommService();
Jeff Brown4d396052010-10-29 21:50:21 -07004403 boolean hungUp = false;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004404 if (telecomManager != null) {
4405 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07004406 // Pressing Power while there's a ringing incoming
4407 // call should silence the ringer.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004408 telecomManager.silenceRinger();
Santos Cordon6848f722014-05-21 15:22:12 -07004409 } else if ((mIncallPowerBehavior
4410 & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004411 && telecomManager.isInCall() && interactive) {
Santos Cordon6848f722014-05-21 15:22:12 -07004412 // Otherwise, if "Power button ends call" is enabled,
4413 // the Power button will hang up any current active call.
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004414 hungUp = telecomManager.endCall();
Jeff Brown4d396052010-10-29 21:50:21 -07004415 }
4416 }
Jeff Brown037c33e2014-04-09 00:31:55 -07004417 interceptPowerKeyDown(!interactive || hungUp
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004418 || mVolumeDownKeyTriggered || mVolumeUpKeyTriggered);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004419 } else {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004420 mPowerKeyTriggered = false;
4421 cancelPendingScreenshotChordAction();
4422 if (interceptPowerKeyUp(canceled || mPendingPowerKeyUpCanceled)) {
Jeff Brown6d8fd272014-05-20 21:24:38 -07004423 powerShortPress(event.getEventTime());
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:
4451 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004452 TelecomManager telecomManager = getTelecommService();
4453 if (telecomManager != null) {
4454 if (telecomManager.isInCall()) {
Santos Cordon6848f722014-05-21 15:22:12 -07004455 // Suppress PLAY/PAUSE toggle when phone is ringing or in-call
4456 // to avoid music playback.
4457 break;
Jeff Brown3122e442010-10-11 23:32:49 -07004458 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004459 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004460 }
Jeff Brown4d396052010-10-29 21:50:21 -07004461 case KeyEvent.KEYCODE_HEADSETHOOK:
4462 case KeyEvent.KEYCODE_MUTE:
4463 case KeyEvent.KEYCODE_MEDIA_STOP:
4464 case KeyEvent.KEYCODE_MEDIA_NEXT:
4465 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
4466 case KeyEvent.KEYCODE_MEDIA_REWIND:
4467 case KeyEvent.KEYCODE_MEDIA_RECORD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09004468 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
4469 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: {
Jeff Brown4d396052010-10-29 21:50:21 -07004470 if ((result & ACTION_PASS_TO_USER) == 0) {
4471 // Only do this if we would otherwise not pass it to the user. In that
4472 // case, the PhoneWindow class will do the same thing, except it will
4473 // only do it if the showing app doesn't process the key on its own.
Jeff Brown40013652012-05-16 21:22:36 -07004474 // Note that we need to make a copy of the key event here because the
4475 // original key event will be recycled when we return.
Jeff Brown4d396052010-10-29 21:50:21 -07004476 mBroadcastWakeLock.acquire();
Jeff Brown40013652012-05-16 21:22:36 -07004477 Message msg = mHandler.obtainMessage(MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK,
4478 new KeyEvent(event));
4479 msg.setAsynchronous(true);
4480 msg.sendToTarget();
Jeff Brown4d396052010-10-29 21:50:21 -07004481 }
4482 break;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004483 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004484
Jeff Brown4d396052010-10-29 21:50:21 -07004485 case KeyEvent.KEYCODE_CALL: {
4486 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004487 TelecomManager telecomManager = getTelecommService();
4488 if (telecomManager != null) {
4489 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07004490 Log.i(TAG, "interceptKeyBeforeQueueing:"
4491 + " CALL key-down while ringing: Answer the call!");
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004492 telecomManager.acceptRingingCall();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004493
Santos Cordon6848f722014-05-21 15:22:12 -07004494 // And *don't* pass this key thru to the current activity
4495 // (which is presumably the InCallScreen.)
4496 result &= ~ACTION_PASS_TO_USER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004497 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004498 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004499 }
Jeff Brown4d396052010-10-29 21:50:21 -07004500 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004501 }
Michael Wright869a67c2014-08-26 19:33:06 -07004502 case KeyEvent.KEYCODE_VOICE_ASSIST: {
4503 // Only do this if we would otherwise not pass it to the user. In that case,
4504 // interceptKeyBeforeDispatching would apply a similar but different policy in
4505 // order to invoke voice assist actions. Note that we need to make a copy of the
4506 // key event here because the original key event will be recycled when we return.
4507 if ((result & ACTION_PASS_TO_USER) == 0 && !down) {
4508 mBroadcastWakeLock.acquire();
4509 Message msg = mHandler.obtainMessage(MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK,
4510 keyguardActive ? 1 : 0, 0);
4511 msg.setAsynchronous(true);
4512 msg.sendToTarget();
4513 }
4514 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004515 }
Jeff Brown26875502014-01-30 21:47:47 -08004516
Jeff Brownbae8e772014-06-12 19:59:45 -07004517 if (useHapticFeedback) {
4518 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
4519 }
4520
Jeff Brown26875502014-01-30 21:47:47 -08004521 if (isWakeKey) {
4522 mPowerManager.wakeUp(event.getEventTime());
4523 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004524 return result;
4525 }
4526
Jeff Brown1c2e4942012-11-06 16:32:01 -08004527 /**
4528 * When the screen is off we ignore some keys that might otherwise typically
4529 * be considered wake keys. We filter them out here.
4530 *
4531 * {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it
4532 * is always considered a wake key.
4533 */
4534 private boolean isWakeKeyWhenScreenOff(int keyCode) {
4535 switch (keyCode) {
4536 // ignore volume keys unless docked
4537 case KeyEvent.KEYCODE_VOLUME_UP:
4538 case KeyEvent.KEYCODE_VOLUME_DOWN:
4539 case KeyEvent.KEYCODE_VOLUME_MUTE:
4540 return mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED;
4541
4542 // ignore media and camera keys
4543 case KeyEvent.KEYCODE_MUTE:
4544 case KeyEvent.KEYCODE_HEADSETHOOK:
4545 case KeyEvent.KEYCODE_MEDIA_PLAY:
4546 case KeyEvent.KEYCODE_MEDIA_PAUSE:
4547 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
4548 case KeyEvent.KEYCODE_MEDIA_STOP:
4549 case KeyEvent.KEYCODE_MEDIA_NEXT:
4550 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
4551 case KeyEvent.KEYCODE_MEDIA_REWIND:
4552 case KeyEvent.KEYCODE_MEDIA_RECORD:
4553 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09004554 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK:
Jeff Brown1c2e4942012-11-06 16:32:01 -08004555 case KeyEvent.KEYCODE_CAMERA:
4556 return false;
4557 }
4558 return true;
4559 }
4560
4561
Jeff Brown56194eb2011-03-02 19:23:13 -08004562 /** {@inheritDoc} */
4563 @Override
Michael Wright70af00a2014-09-03 19:30:20 -07004564 public int interceptMotionBeforeQueueingNonInteractive(long whenNanos, int policyFlags) {
4565 if ((policyFlags & FLAG_WAKE) != 0) {
4566 mPowerManager.wakeUp(whenNanos / 1000000);
4567 return 0;
4568 }
4569 if (shouldDispatchInputWhenNonInteractive()) {
4570 return ACTION_PASS_TO_USER;
4571 }
Jeff Brown037c33e2014-04-09 00:31:55 -07004572 return 0;
Jeff Brown56194eb2011-03-02 19:23:13 -08004573 }
4574
Michael Wright70af00a2014-09-03 19:30:20 -07004575 private boolean shouldDispatchInputWhenNonInteractive() {
4576 return keyguardIsShowingTq() && mDisplay != null &&
4577 mDisplay.getState() != Display.STATE_OFF;
4578 }
4579
Jeff Brown40013652012-05-16 21:22:36 -07004580 void dispatchMediaKeyWithWakeLock(KeyEvent event) {
4581 if (DEBUG_INPUT) {
4582 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: " + event);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004583 }
4584
Jeff Brown40013652012-05-16 21:22:36 -07004585 if (mHavePendingMediaKeyRepeatWithWakeLock) {
4586 if (DEBUG_INPUT) {
4587 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: canceled repeat");
4588 }
4589
4590 mHandler.removeMessages(MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK);
4591 mHavePendingMediaKeyRepeatWithWakeLock = false;
4592 mBroadcastWakeLock.release(); // pending repeat was holding onto the wake lock
4593 }
4594
4595 dispatchMediaKeyWithWakeLockToAudioService(event);
4596
4597 if (event.getAction() == KeyEvent.ACTION_DOWN
4598 && event.getRepeatCount() == 0) {
4599 mHavePendingMediaKeyRepeatWithWakeLock = true;
4600
4601 Message msg = mHandler.obtainMessage(
4602 MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK, event);
4603 msg.setAsynchronous(true);
4604 mHandler.sendMessageDelayed(msg, ViewConfiguration.getKeyRepeatTimeout());
4605 } else {
4606 mBroadcastWakeLock.release();
4607 }
4608 }
4609
4610 void dispatchMediaKeyRepeatWithWakeLock(KeyEvent event) {
4611 mHavePendingMediaKeyRepeatWithWakeLock = false;
4612
4613 KeyEvent repeatEvent = KeyEvent.changeTimeRepeat(event,
4614 SystemClock.uptimeMillis(), 1, event.getFlags() | KeyEvent.FLAG_LONG_PRESS);
4615 if (DEBUG_INPUT) {
4616 Slog.d(TAG, "dispatchMediaKeyRepeatWithWakeLock: " + repeatEvent);
4617 }
4618
4619 dispatchMediaKeyWithWakeLockToAudioService(repeatEvent);
4620 mBroadcastWakeLock.release();
4621 }
4622
4623 void dispatchMediaKeyWithWakeLockToAudioService(KeyEvent event) {
4624 if (ActivityManagerNative.isSystemReady()) {
RoboErik430fc482014-06-12 15:49:20 -07004625 MediaSessionLegacyHelper.getHelper(mContext).sendMediaButtonEvent(event, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004626 }
4627 }
4628
Michael Wright869a67c2014-08-26 19:33:06 -07004629 void launchVoiceAssistWithWakeLock(boolean keyguardActive) {
4630 Intent voiceIntent =
4631 new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
4632 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, keyguardActive);
4633 mContext.startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
4634 mBroadcastWakeLock.release();
4635 }
4636
Mike Lockwood1753f7f2009-08-24 14:49:07 -07004637 BroadcastReceiver mDockReceiver = new BroadcastReceiver() {
Craig Mautnereee29c42013-01-17 14:44:34 -08004638 @Override
Mike Lockwood1753f7f2009-08-24 14:49:07 -07004639 public void onReceive(Context context, Intent intent) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07004640 if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) {
4641 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
4642 Intent.EXTRA_DOCK_STATE_UNDOCKED);
Daniel Sandler6396c722013-04-16 20:19:09 -04004643 } else {
4644 try {
4645 IUiModeManager uiModeService = IUiModeManager.Stub.asInterface(
4646 ServiceManager.getService(Context.UI_MODE_SERVICE));
4647 mUiMode = uiModeService.getCurrentModeType();
4648 } catch (RemoteException e) {
4649 }
Dianne Hackborn80fa1662009-10-07 14:02:10 -07004650 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004651 updateRotation(true);
Craig Mautnereee29c42013-01-17 14:44:34 -08004652 synchronized (mLock) {
4653 updateOrientationListenerLp();
4654 }
Mike Lockwood1753f7f2009-08-24 14:49:07 -07004655 }
4656 };
4657
Jeff Brown6aaf2952012-10-05 16:01:08 -07004658 BroadcastReceiver mDreamReceiver = new BroadcastReceiver() {
4659 @Override
4660 public void onReceive(Context context, Intent intent) {
4661 if (Intent.ACTION_DREAMING_STARTED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004662 if (mKeyguardDelegate != null) {
4663 mKeyguardDelegate.onDreamingStarted();
Jeff Brown6aaf2952012-10-05 16:01:08 -07004664 }
4665 } else if (Intent.ACTION_DREAMING_STOPPED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004666 if (mKeyguardDelegate != null) {
4667 mKeyguardDelegate.onDreamingStopped();
Jeff Brown6aaf2952012-10-05 16:01:08 -07004668 }
4669 }
4670 }
4671 };
4672
Christopher Tate5e08af02012-09-21 17:17:22 -07004673 BroadcastReceiver mMultiuserReceiver = new BroadcastReceiver() {
4674 @Override
4675 public void onReceive(Context context, Intent intent) {
4676 if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) {
4677 // tickle the settings observer: this first ensures that we're
4678 // observing the relevant settings for the newly-active user,
4679 // and then updates our own bookkeeping based on the now-
4680 // current user.
4681 mSettingsObserver.onChange(false);
John Spurlockce479d82012-11-29 09:52:21 -05004682
4683 // force a re-application of focused window sysui visibility.
4684 // the window may never have been shown for this user
4685 // e.g. the keyguard when going through the new-user setup flow
John Spurlock04db1762013-05-13 12:46:41 -04004686 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
John Spurlockce479d82012-11-29 09:52:21 -05004687 mLastSystemUiFlags = 0;
4688 updateSystemUiVisibilityLw();
4689 }
Christopher Tate5e08af02012-09-21 17:17:22 -07004690 }
4691 }
4692 };
4693
John Spurlockd9b70bd2014-02-06 17:02:44 -05004694 private final Runnable mRequestTransientNav = new Runnable() {
4695 @Override
4696 public void run() {
4697 requestTransientBars(mNavigationBar);
4698 }
4699 };
4700
John Spurlocke1f366f2013-08-05 12:22:40 -04004701 private void requestTransientBars(WindowState swipeTarget) {
John Spurlock04db1762013-05-13 12:46:41 -04004702 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Maurice Lam99c6e072014-04-28 18:24:28 -07004703 if (!isUserSetupComplete()) {
4704 // Swipe-up for navigation bar is disabled during setup
4705 return;
4706 }
John Spurlock27735a42013-08-14 17:57:38 -04004707 boolean sb = mStatusBarController.checkShowTransientBarLw();
4708 boolean nb = mNavigationBarController.checkShowTransientBarLw();
John Spurlockad3e6cb2013-04-30 08:47:43 -04004709 if (sb || nb) {
John Spurlocke1f366f2013-08-05 12:22:40 -04004710 WindowState barTarget = sb ? mStatusBar : mNavigationBar;
4711 if (sb ^ nb && barTarget != swipeTarget) {
4712 if (DEBUG) Slog.d(TAG, "Not showing transient bar, wrong swipe target");
John Spurlockad3e6cb2013-04-30 08:47:43 -04004713 return;
4714 }
John Spurlock27735a42013-08-14 17:57:38 -04004715 if (sb) mStatusBarController.showTransient();
4716 if (nb) mNavigationBarController.showTransient();
John Spurlockf1a36642013-10-12 17:50:42 -04004717 mImmersiveModeConfirmation.confirmCurrentPrompt();
John Spurlockad3e6cb2013-04-30 08:47:43 -04004718 updateSystemUiVisibilityLw();
John Spurlock32beb2c2013-03-11 10:16:47 -04004719 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04004720 }
4721 }
4722
Jeff Brown3ee549c2014-09-22 20:14:39 -07004723 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07004724 @Override
Jeff Brown140ffc72014-05-01 15:18:00 -07004725 public void goingToSleep(int why) {
Dianne Hackborn74489012009-03-24 20:50:09 -07004726 EventLog.writeEvent(70000, 0);
Jeff Brown36c4db82014-09-19 12:05:31 -07004727 if (DEBUG_WAKEUP) Slog.i(TAG, "Going to sleep...");
Jeff Brown3ee549c2014-09-22 20:14:39 -07004728
4729 // We must get this work done here because the power manager will drop
4730 // the wake lock and let the system suspend once this function returns.
The Android Open Source Project0727d222009-03-11 12:11:58 -07004731 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07004732 mAwake = false;
4733 mKeyguardDrawComplete = false;
Jeff Browna20dda42014-05-27 20:57:24 -07004734 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07004735 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05004736 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07004737 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07004738
4739 if (mKeyguardDelegate != null) {
4740 mKeyguardDelegate.onScreenTurnedOff(why);
4741 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004742 }
4743
Jeff Brown3ee549c2014-09-22 20:14:39 -07004744 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07004745 @Override
Jeff Brown36c4db82014-09-19 12:05:31 -07004746 public void wakingUp() {
Dianne Hackborn74489012009-03-24 20:50:09 -07004747 EventLog.writeEvent(70000, 1);
Jeff Brown36c4db82014-09-19 12:05:31 -07004748 if (DEBUG_WAKEUP) Slog.i(TAG, "Waking up...");
Craig Mautner8a0da012014-05-31 15:13:37 -07004749
Jeff Brown3ee549c2014-09-22 20:14:39 -07004750 // Since goToSleep performs these functions synchronously, we must
4751 // do the same here. We cannot post this work to a handler because
4752 // that might cause it to become reordered with respect to what
4753 // may happen in a future call to goToSleep.
The Android Open Source Project0727d222009-03-11 12:11:58 -07004754 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07004755 mAwake = true;
4756 mKeyguardDrawComplete = false;
4757 if (mKeyguardDelegate != null) {
4758 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
4759 mHandler.sendEmptyMessageDelayed(MSG_KEYGUARD_DRAWN_TIMEOUT, 1000);
4760 }
4761
Jeff Browna20dda42014-05-27 20:57:24 -07004762 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07004763 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05004764 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07004765 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07004766
Jim Miller5ecd8112013-01-09 18:50:26 -08004767 if (mKeyguardDelegate != null) {
Craig Mautner8a0da012014-05-31 15:13:37 -07004768 mKeyguardDelegate.onScreenTurnedOn(mKeyguardDelegateCallback);
Jeff Brown36c4db82014-09-19 12:05:31 -07004769 // ... eventually calls finishKeyguardDrawn
Jeff Brownc38c9be2012-10-04 13:16:19 -07004770 } else {
Craig Mautner8a0da012014-05-31 15:13:37 -07004771 if (DEBUG_WAKEUP) Slog.d(TAG, "null mKeyguardDelegate: setting mKeyguardDrawComplete.");
Jeff Brown36c4db82014-09-19 12:05:31 -07004772 finishKeyguardDrawn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07004773 }
Jeff Brown36c4db82014-09-19 12:05:31 -07004774 }
4775
Jeff Brown36c4db82014-09-19 12:05:31 -07004776 private void finishKeyguardDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07004777 synchronized (mLock) {
4778 if (!mAwake || mKeyguardDrawComplete) {
4779 return; // spurious
4780 }
4781
Jeff Brown36c4db82014-09-19 12:05:31 -07004782 mKeyguardDrawComplete = true;
Jeff Brown3ee549c2014-09-22 20:14:39 -07004783 if (mKeyguardDelegate != null) {
4784 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
4785 }
4786 }
4787
4788 finishScreenTurningOn();
4789 }
4790
4791 // Called on the DisplayManager's DisplayPowerController thread.
4792 @Override
4793 public void screenTurnedOff() {
4794 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turned off...");
4795
4796 synchronized (mLock) {
4797 mScreenOnEarly = false;
4798 mScreenOnFully = false;
4799 mWindowManagerDrawComplete = false;
4800 mScreenOnListener = null;
4801 updateOrientationListenerLp();
Jeff Brown36c4db82014-09-19 12:05:31 -07004802 }
4803 }
4804
Jeff Brown3ee549c2014-09-22 20:14:39 -07004805 // Called on the DisplayManager's DisplayPowerController thread.
Jeff Brown36c4db82014-09-19 12:05:31 -07004806 @Override
4807 public void screenTurningOn(final ScreenOnListener screenOnListener) {
Jeff Brown36c4db82014-09-19 12:05:31 -07004808 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turning on...");
Jeff Brown36c4db82014-09-19 12:05:31 -07004809
Jeff Brown3ee549c2014-09-22 20:14:39 -07004810 synchronized (mLock) {
4811 mScreenOnEarly = true;
4812 mScreenOnFully = false;
4813 mWindowManagerDrawComplete = false;
4814 mScreenOnListener = screenOnListener;
4815 updateOrientationListenerLp();
4816 }
Jeff Brown36c4db82014-09-19 12:05:31 -07004817
Craig Mautnerc3daedd2014-09-13 11:17:23 -07004818 mWindowManagerInternal.waitForAllWindowsDrawn(mWindowManagerDrawCallback,
4819 WAITING_FOR_DRAWN_TIMEOUT);
Jeff Brown36c4db82014-09-19 12:05:31 -07004820 // ... eventually calls finishWindowsDrawn
4821 }
4822
Jeff Brown36c4db82014-09-19 12:05:31 -07004823 private void finishWindowsDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07004824 synchronized (mLock) {
4825 if (!mScreenOnEarly || mWindowManagerDrawComplete) {
4826 return; // spurious
4827 }
4828
Jeff Brown36c4db82014-09-19 12:05:31 -07004829 mWindowManagerDrawComplete = true;
Jeff Brown36c4db82014-09-19 12:05:31 -07004830 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07004831
4832 finishScreenTurningOn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07004833 }
4834
Craig Mautner8a0da012014-05-31 15:13:37 -07004835 private void finishScreenTurningOn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07004836 final ScreenOnListener listener;
4837 final boolean enableScreen;
Jeff Brown36c4db82014-09-19 12:05:31 -07004838 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07004839 if (DEBUG_WAKEUP) Slog.d(TAG,
4840 "finishScreenTurningOn: mAwake=" + mAwake
4841 + ", mScreenOnEarly=" + mScreenOnEarly
4842 + ", mScreenOnFully=" + mScreenOnFully
4843 + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete
4844 + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete);
4845
4846 if (mScreenOnFully || !mScreenOnEarly || !mWindowManagerDrawComplete
4847 || (mAwake && !mKeyguardDrawComplete)) {
4848 return; // spurious or not ready yet
Jeff Brown36c4db82014-09-19 12:05:31 -07004849 }
4850
Jeff Brown3ee549c2014-09-22 20:14:39 -07004851 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished screen turning on...");
4852 listener = mScreenOnListener;
Craig Mautner13f6ea72014-06-23 14:57:02 -07004853 mScreenOnListener = null;
Jeff Brown3ee549c2014-09-22 20:14:39 -07004854 mScreenOnFully = true;
4855
4856 // Remember the first time we draw the keyguard so we know when we're done with
4857 // the main part of booting and can enable the screen and hide boot messages.
4858 if (!mKeyguardDrawnOnce && mAwake) {
4859 mKeyguardDrawnOnce = true;
4860 enableScreen = true;
4861 if (mBootMessageNeedsHiding) {
4862 mBootMessageNeedsHiding = false;
4863 hideBootMessages();
4864 }
4865 } else {
4866 enableScreen = false;
4867 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07004868 }
4869
Jeff Brown3ee549c2014-09-22 20:14:39 -07004870 if (listener != null) {
4871 listener.onScreenOn();
4872 }
Jeff Brown4fc45272012-10-10 18:28:14 -07004873
Jeff Brown3ee549c2014-09-22 20:14:39 -07004874 if (enableScreen) {
4875 try {
4876 mWindowManager.enableScreenIfNeeded();
4877 } catch (RemoteException unhandled) {
Jeff Brown36c4db82014-09-19 12:05:31 -07004878 }
Craig Mautnera631d492014-08-05 15:16:01 -07004879 }
4880 }
4881
4882 private void handleHideBootMessage() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07004883 synchronized (mLock) {
4884 if (!mKeyguardDrawnOnce) {
4885 mBootMessageNeedsHiding = true;
4886 return; // keyguard hasn't drawn the first time yet, not done booting
4887 }
Craig Mautnera631d492014-08-05 15:16:01 -07004888 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07004889
4890 if (mBootMsgDialog != null) {
4891 if (DEBUG_WAKEUP) Slog.d(TAG, "handleHideBootMessage: dismissing");
4892 mBootMsgDialog.dismiss();
4893 mBootMsgDialog = null;
Craig Mautnera631d492014-08-05 15:16:01 -07004894 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07004895 }
4896
4897 @Override
Jeff Brown3ee549c2014-09-22 20:14:39 -07004898 public boolean isScreenOn() {
4899 return mScreenOnFully;
Dianne Hackborn08743722009-12-21 12:16:51 -08004900 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07004901
Dianne Hackborn08743722009-12-21 12:16:51 -08004902 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07004903 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004904 public void enableKeyguard(boolean enabled) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004905 if (mKeyguardDelegate != null) {
4906 mKeyguardDelegate.setKeyguardEnabled(enabled);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004907 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004908 }
4909
4910 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07004911 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004912 public void exitKeyguardSecurely(OnKeyguardExitResult callback) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004913 if (mKeyguardDelegate != null) {
4914 mKeyguardDelegate.verifyUnlock(callback);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004915 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004916 }
4917
Mike Lockwoodf7913302009-11-28 22:27:10 -05004918 private boolean keyguardIsShowingTq() {
Jim Miller5ecd8112013-01-09 18:50:26 -08004919 if (mKeyguardDelegate == null) return false;
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004920 return mKeyguardDelegate.isShowingAndNotOccluded();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004921 }
4922
Mike Lockwood520d8bc2011-02-18 13:23:13 -05004923
4924 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07004925 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05004926 public boolean isKeyguardLocked() {
4927 return keyguardOn();
4928 }
4929
4930 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07004931 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05004932 public boolean isKeyguardSecure() {
Jim Miller5ecd8112013-01-09 18:50:26 -08004933 if (mKeyguardDelegate == null) return false;
4934 return mKeyguardDelegate.isSecure();
Mike Lockwood520d8bc2011-02-18 13:23:13 -05004935 }
4936
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004937 // Returns true if keyguard is currently locked whether or not it is currently hidden.
4938 private boolean isKeyguardSecureIncludingHidden() {
4939 return mKeyguardDelegate.isSecure() && mKeyguardDelegate.isShowing();
4940 }
4941
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004942 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07004943 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004944 public boolean inKeyguardRestrictedKeyInputMode() {
Jim Miller5ecd8112013-01-09 18:50:26 -08004945 if (mKeyguardDelegate == null) return false;
4946 return mKeyguardDelegate.isInputRestricted();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004947 }
4948
Jose Lima9546b202014-07-02 17:21:51 -07004949 @Override
Dianne Hackborn90c52de2011-09-23 12:57:44 -07004950 public void dismissKeyguardLw() {
RoboErik8a2cfc32014-05-16 11:19:38 -07004951 if (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()) {
Daniel Sandler1ce804392012-11-07 15:07:12 -05004952 mHandler.post(new Runnable() {
Jose Lima9546b202014-07-02 17:21:51 -07004953 @Override
Daniel Sandler1ce804392012-11-07 15:07:12 -05004954 public void run() {
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02004955 // ask the keyguard to prompt the user to authenticate if necessary
4956 mKeyguardDelegate.dismiss();
4957 }
4958 });
4959 }
4960 }
4961
4962 public void notifyActivityDrawnForKeyguardLw() {
4963 if (mKeyguardDelegate != null) {
4964 mHandler.post(new Runnable() {
4965 @Override
4966 public void run() {
4967 mKeyguardDelegate.onActivityDrawn();
Daniel Sandler1ce804392012-11-07 15:07:12 -05004968 }
4969 });
Dianne Hackborn90c52de2011-09-23 12:57:44 -07004970 }
4971 }
4972
Jorim Jaggicff0acb2014-03-31 16:35:15 +02004973 @Override
4974 public boolean isKeyguardDrawnLw() {
4975 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07004976 return mKeyguardDrawnOnce;
Jorim Jaggicff0acb2014-03-31 16:35:15 +02004977 }
4978 }
4979
Jorim Jaggi0d674622014-05-21 01:34:15 +02004980 @Override
Jorim Jaggie29b2db2014-05-30 23:17:03 +02004981 public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) {
Jorim Jaggi0d674622014-05-21 01:34:15 +02004982 if (mKeyguardDelegate != null) {
Jorim Jaggie29b2db2014-05-30 23:17:03 +02004983 mKeyguardDelegate.startKeyguardExitAnimation(startTime, fadeoutDuration);
Jorim Jaggi0d674622014-05-21 01:34:15 +02004984 }
4985 }
4986
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004987 void sendCloseSystemWindows() {
4988 sendCloseSystemWindows(mContext, null);
4989 }
4990
4991 void sendCloseSystemWindows(String reason) {
4992 sendCloseSystemWindows(mContext, reason);
4993 }
4994
4995 static void sendCloseSystemWindows(Context context, String reason) {
4996 if (ActivityManagerNative.isSystemReady()) {
Dianne Hackborn94a679d2009-07-28 17:51:07 -07004997 try {
4998 ActivityManagerNative.getDefault().closeSystemDialogs(reason);
4999 } catch (RemoteException e) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005000 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005001 }
5002 }
Mitsuru Oshima831d0d92009-06-16 18:27:18 -07005003
Jeff Brown01a98dd2011-09-20 15:08:29 -07005004 @Override
5005 public int rotationForOrientationLw(int orientation, int lastRotation) {
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005006 if (false) {
5007 Slog.v(TAG, "rotationForOrientationLw(orient="
5008 + orientation + ", last=" + lastRotation
5009 + "); user=" + mUserRotation + " "
5010 + ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED)
5011 ? "USER_ROTATION_LOCKED" : "")
5012 );
5013 }
5014
Craig Mautner46ac6fa2013-08-01 10:06:34 -07005015 if (mForceDefaultOrientation) {
5016 return Surface.ROTATION_0;
5017 }
5018
The Android Open Source Project0727d222009-03-11 12:11:58 -07005019 synchronized (mLock) {
Jeff Brownc0347aa2011-09-23 17:26:09 -07005020 int sensorRotation = mOrientationListener.getProposedRotation(); // may be -1
5021 if (sensorRotation < 0) {
Jeff Brown0f862b42012-09-27 21:11:01 -07005022 sensorRotation = lastRotation;
Jeff Brownc0347aa2011-09-23 17:26:09 -07005023 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005024
Jeff Browndec6cf42011-11-15 14:08:20 -08005025 final int preferredRotation;
Jeff Brown2e7760e2012-04-11 15:14:55 -07005026 if (mLidState == LID_OPEN && mLidOpenRotation >= 0) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005027 // Ignore sensor when lid switch is open and rotation is forced.
5028 preferredRotation = mLidOpenRotation;
5029 } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR
Jeff Brownc0347aa2011-09-23 17:26:09 -07005030 && (mCarDockEnablesAccelerometer || mCarDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005031 // Ignore sensor when in car dock unless explicitly enabled.
5032 // This case can override the behavior of NOSENSOR, and can also
5033 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07005034 preferredRotation = mCarDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07005035 ? sensorRotation : mCarDockRotation;
Jeff Brown1a693182011-11-08 14:44:16 -08005036 } else if ((mDockMode == Intent.EXTRA_DOCK_STATE_DESK
5037 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
5038 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK)
Jeff Brownc0347aa2011-09-23 17:26:09 -07005039 && (mDeskDockEnablesAccelerometer || mDeskDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005040 // Ignore sensor when in desk dock unless explicitly enabled.
5041 // This case can override the behavior of NOSENSOR, and can also
5042 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07005043 preferredRotation = mDeskDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07005044 ? sensorRotation : mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -07005045 } else if (mHdmiPlugged && mDemoHdmiRotationLock) {
5046 // Ignore sensor when plugged into HDMI when demo HDMI rotation lock enabled.
Jeff Browneb3e4b92011-12-06 19:54:24 -08005047 // Note that the dock orientation overrides the HDMI orientation.
Jeff Brownc82c89ed2013-04-17 17:18:15 -07005048 preferredRotation = mDemoHdmiRotation;
5049 } else if (mHdmiPlugged && mDockMode == Intent.EXTRA_DOCK_STATE_UNDOCKED
5050 && mUndockedHdmiRotation >= 0) {
5051 // Ignore sensor when plugged into HDMI and an undocked orientation has
5052 // been specified in the configuration (only for legacy devices without
5053 // full multi-display support).
5054 // Note that the dock orientation overrides the HDMI orientation.
5055 preferredRotation = mUndockedHdmiRotation;
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005056 } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED) {
5057 // Application just wants to remain locked in the last rotation.
5058 preferredRotation = lastRotation;
Jeff Brownbcdfc622014-03-06 19:13:04 -08005059 } else if (!mSupportAutoRotation) {
5060 // If we don't support auto-rotation then bail out here and ignore
5061 // the sensor and any rotation lock settings.
5062 preferredRotation = -1;
Jeff Brown207673cd2012-06-05 17:47:11 -07005063 } else if ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE
Jeff Brown01a98dd2011-09-20 15:08:29 -07005064 && (orientation == ActivityInfo.SCREEN_ORIENTATION_USER
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005065 || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
5066 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
5067 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
5068 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER))
Jeff Brown01a98dd2011-09-20 15:08:29 -07005069 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
5070 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
5071 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
5072 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) {
5073 // Otherwise, use sensor only if requested by the application or enabled
5074 // by default for USER or UNSPECIFIED modes. Does not apply to NOSENSOR.
Jeff Brownd3187e32011-09-21 19:26:44 -07005075 if (mAllowAllRotations < 0) {
5076 // Can't read this during init() because the context doesn't
5077 // have display metrics at that time so we cannot determine
5078 // tablet vs. phone then.
5079 mAllowAllRotations = mContext.getResources().getBoolean(
5080 com.android.internal.R.bool.config_allowAllRotations) ? 1 : 0;
5081 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005082 if (sensorRotation != Surface.ROTATION_180
Jeff Brownd3187e32011-09-21 19:26:44 -07005083 || mAllowAllRotations == 1
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005084 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
5085 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005086 preferredRotation = sensorRotation;
5087 } else {
5088 preferredRotation = lastRotation;
5089 }
Jeff Brown207673cd2012-06-05 17:47:11 -07005090 } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED
5091 && orientation != ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) {
5092 // Apply rotation lock. Does not apply to NOSENSOR.
5093 // The idea is that the user rotation expresses a weak preference for the direction
5094 // of gravity and as NOSENSOR is never affected by gravity, then neither should
5095 // NOSENSOR be affected by rotation lock (although it will be affected by docks).
Jeff Brown4dfce202011-10-05 12:00:10 -07005096 preferredRotation = mUserRotation;
Jeff Browndec6cf42011-11-15 14:08:20 -08005097 } else {
5098 // No overriding preference.
5099 // We will do exactly what the application asked us to do.
5100 preferredRotation = -1;
Jeff Brown01a98dd2011-09-20 15:08:29 -07005101 }
5102
Dianne Hackborne5439f22010-10-02 16:53:50 -07005103 switch (orientation) {
5104 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08005105 // Return portrait unless overridden.
5106 if (isAnyPortrait(preferredRotation)) {
5107 return preferredRotation;
5108 }
Dianne Hackborne5439f22010-10-02 16:53:50 -07005109 return mPortraitRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005110
Jeff Brown01a98dd2011-09-20 15:08:29 -07005111 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08005112 // Return landscape unless overridden.
5113 if (isLandscapeOrSeascape(preferredRotation)) {
5114 return preferredRotation;
5115 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005116 return mLandscapeRotation;
5117
5118 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08005119 // Return reverse portrait unless overridden.
5120 if (isAnyPortrait(preferredRotation)) {
5121 return preferredRotation;
5122 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005123 return mUpsideDownRotation;
5124
5125 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08005126 // Return seascape unless overridden.
5127 if (isLandscapeOrSeascape(preferredRotation)) {
5128 return preferredRotation;
5129 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005130 return mSeascapeRotation;
5131
5132 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005133 case ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE:
Jeff Brown01a98dd2011-09-20 15:08:29 -07005134 // Return either landscape rotation.
5135 if (isLandscapeOrSeascape(preferredRotation)) {
5136 return preferredRotation;
5137 }
5138 if (isLandscapeOrSeascape(lastRotation)) {
Jeff Brown4519f072011-01-23 13:16:01 -08005139 return lastRotation;
5140 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005141 return mLandscapeRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005142
Jeff Brown01a98dd2011-09-20 15:08:29 -07005143 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005144 case ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT:
Jeff Brown01a98dd2011-09-20 15:08:29 -07005145 // Return either portrait rotation.
5146 if (isAnyPortrait(preferredRotation)) {
5147 return preferredRotation;
5148 }
5149 if (isAnyPortrait(lastRotation)) {
5150 return lastRotation;
5151 }
5152 return mPortraitRotation;
5153
5154 default:
Jeff Brown4dfce202011-10-05 12:00:10 -07005155 // For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR,
5156 // just return the preferred orientation we already calculated.
Jeff Brown01a98dd2011-09-20 15:08:29 -07005157 if (preferredRotation >= 0) {
5158 return preferredRotation;
5159 }
Dianne Hackborndacea8c2011-04-21 17:26:39 -07005160 return Surface.ROTATION_0;
Daniel Sandlere7e5ac22011-02-22 16:10:21 -05005161 }
5162 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07005163 }
5164
Jeff Brown01a98dd2011-09-20 15:08:29 -07005165 @Override
5166 public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation) {
5167 switch (orientation) {
5168 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
5169 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
5170 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
5171 return isAnyPortrait(rotation);
5172
5173 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
5174 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
5175 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
5176 return isLandscapeOrSeascape(rotation);
5177
5178 default:
5179 return true;
5180 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07005181 }
5182
Jeff Brownc0347aa2011-09-23 17:26:09 -07005183 @Override
5184 public void setRotationLw(int rotation) {
5185 mOrientationListener.setCurrentRotation(rotation);
5186 }
5187
Jeff Brown01a98dd2011-09-20 15:08:29 -07005188 private boolean isLandscapeOrSeascape(int rotation) {
5189 return rotation == mLandscapeRotation || rotation == mSeascapeRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005190 }
5191
Jeff Brown01a98dd2011-09-20 15:08:29 -07005192 private boolean isAnyPortrait(int rotation) {
5193 return rotation == mPortraitRotation || rotation == mUpsideDownRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005194 }
5195
Jose Lima9546b202014-07-02 17:21:51 -07005196 @Override
Svetoslav Ganov80943d82013-01-02 10:25:37 -08005197 public int getUserRotationMode() {
5198 return Settings.System.getIntForUser(mContext.getContentResolver(),
Brett Chabot7e55c402013-05-16 19:38:08 -07005199 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
5200 WindowManagerPolicy.USER_ROTATION_FREE :
5201 WindowManagerPolicy.USER_ROTATION_LOCKED;
Svetoslav Ganov80943d82013-01-02 10:25:37 -08005202 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005203
5204 // User rotation: to be used when all else fails in assigning an orientation to the device
Jose Lima9546b202014-07-02 17:21:51 -07005205 @Override
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005206 public void setUserRotationMode(int mode, int rot) {
5207 ContentResolver res = mContext.getContentResolver();
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005208
5209 // mUserRotationMode and mUserRotation will be assigned by the content observer
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005210 if (mode == WindowManagerPolicy.USER_ROTATION_LOCKED) {
Christopher Tate5e08af02012-09-21 17:17:22 -07005211 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005212 Settings.System.USER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005213 rot,
5214 UserHandle.USER_CURRENT);
5215 Settings.System.putIntForUser(res,
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005216 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005217 0,
5218 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005219 } else {
Christopher Tate5e08af02012-09-21 17:17:22 -07005220 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005221 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005222 1,
5223 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005224 }
5225 }
5226
Jose Lima9546b202014-07-02 17:21:51 -07005227 @Override
Jeff Brownac143512012-04-05 18:57:33 -07005228 public void setSafeMode(boolean safeMode) {
5229 mSafeMode = safeMode;
5230 performHapticFeedbackLw(null, safeMode
5231 ? HapticFeedbackConstants.SAFE_MODE_ENABLED
5232 : HapticFeedbackConstants.SAFE_MODE_DISABLED, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005233 }
Craig Mautnereda67292013-04-28 13:50:14 -07005234
Dianne Hackborn181ceb52009-08-27 22:16:40 -07005235 static long[] getLongIntArray(Resources r, int resid) {
5236 int[] ar = r.getIntArray(resid);
5237 if (ar == null) {
5238 return null;
5239 }
5240 long[] out = new long[ar.length];
5241 for (int i=0; i<ar.length; i++) {
5242 out[i] = ar[i];
5243 }
5244 return out;
5245 }
Craig Mautnereda67292013-04-28 13:50:14 -07005246
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005247 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07005248 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005249 public void systemReady() {
Mike Lockwooded8902d2013-11-15 11:01:47 -08005250 mKeyguardDelegate = new KeyguardServiceDelegate(mContext, null);
5251 mKeyguardDelegate.onSystemReady();
5252
Michael Wright3818c922014-09-02 13:59:07 -07005253 readCameraLensCoverState();
Jeff Brown4f5fa282014-06-12 19:19:15 -07005254 updateUiMode();
Dianne Hackbornb1a79802009-09-29 15:18:31 -07005255 synchronized (mLock) {
5256 updateOrientationListenerLp();
Dianne Hackbornc777e072010-02-12 13:07:59 -08005257 mSystemReady = true;
5258 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07005259 @Override
Dianne Hackbornc777e072010-02-12 13:07:59 -08005260 public void run() {
5261 updateSettings();
5262 }
5263 });
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005264 }
5265 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07005266
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005267 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005268 @Override
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005269 public void systemBooted() {
Jim Millere5f910a2013-10-16 18:15:46 -07005270 if (mKeyguardDelegate != null) {
Jason Monk5eeebf52014-09-26 12:36:51 -04005271 mKeyguardDelegate.bindService(mContext);
Jim Millere5f910a2013-10-16 18:15:46 -07005272 mKeyguardDelegate.onBootCompleted();
5273 }
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005274 synchronized (mLock) {
5275 mSystemBooted = true;
5276 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005277 wakingUp();
5278 screenTurningOn(null);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005279 }
5280
Dianne Hackborn661cd522011-08-22 00:26:20 -07005281 ProgressDialog mBootMsgDialog = null;
5282
5283 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005284 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07005285 public void showBootMessage(final CharSequence msg, final boolean always) {
5286 mHandler.post(new Runnable() {
5287 @Override public void run() {
5288 if (mBootMsgDialog == null) {
Craig Stout4c0cb8a2014-04-04 13:03:10 -07005289 int theme;
5290 if (mContext.getPackageManager().hasSystemFeature(
5291 PackageManager.FEATURE_WATCH)) {
5292 theme = com.android.internal.R.style.Theme_Micro_Dialog_Alert;
5293 } else if (mContext.getPackageManager().hasSystemFeature(
5294 PackageManager.FEATURE_TELEVISION)) {
5295 theme = com.android.internal.R.style.Theme_Leanback_Dialog_Alert;
5296 } else {
5297 theme = 0;
5298 }
Vinod Krishnanfa8fc412014-04-18 14:35:53 -07005299
5300 mBootMsgDialog = new ProgressDialog(mContext, theme) {
Dianne Hackborn295e3c22011-08-25 13:19:08 -07005301 // This dialog will consume all events coming in to
5302 // it, to avoid it trying to do things too early in boot.
5303 @Override public boolean dispatchKeyEvent(KeyEvent event) {
5304 return true;
5305 }
5306 @Override public boolean dispatchKeyShortcutEvent(KeyEvent event) {
5307 return true;
5308 }
5309 @Override public boolean dispatchTouchEvent(MotionEvent ev) {
5310 return true;
5311 }
5312 @Override public boolean dispatchTrackballEvent(MotionEvent ev) {
5313 return true;
5314 }
5315 @Override public boolean dispatchGenericMotionEvent(MotionEvent ev) {
5316 return true;
5317 }
5318 @Override public boolean dispatchPopulateAccessibilityEvent(
5319 AccessibilityEvent event) {
5320 return true;
5321 }
5322 };
Dianne Hackborn661cd522011-08-22 00:26:20 -07005323 mBootMsgDialog.setTitle(R.string.android_upgrading_title);
5324 mBootMsgDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
5325 mBootMsgDialog.setIndeterminate(true);
5326 mBootMsgDialog.getWindow().setType(
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07005327 WindowManager.LayoutParams.TYPE_BOOT_PROGRESS);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005328 mBootMsgDialog.getWindow().addFlags(
5329 WindowManager.LayoutParams.FLAG_DIM_BEHIND
5330 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
5331 mBootMsgDialog.getWindow().setDimAmount(1);
Dianne Hackbornd9efb952011-12-07 14:56:51 -08005332 WindowManager.LayoutParams lp = mBootMsgDialog.getWindow().getAttributes();
5333 lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
5334 mBootMsgDialog.getWindow().setAttributes(lp);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005335 mBootMsgDialog.setCancelable(false);
5336 mBootMsgDialog.show();
5337 }
5338 mBootMsgDialog.setMessage(msg);
5339 }
5340 });
5341 }
5342
5343 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005344 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07005345 public void hideBootMessages() {
Craig Mautnera631d492014-08-05 15:16:01 -07005346 mHandler.sendEmptyMessage(MSG_HIDE_BOOT_MESSAGE);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005347 }
5348
Mike Lockwood28569302010-01-28 11:54:40 -05005349 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005350 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05005351 public void userActivity() {
Dianne Hackborndf89e652011-10-06 22:35:11 -07005352 // ***************************************
5353 // NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
5354 // ***************************************
5355 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
5356 // WITH ITS LOCKS HELD.
5357 //
5358 // This code must be VERY careful about the locks
5359 // it acquires.
5360 // In fact, the current code acquires way too many,
5361 // and probably has lurking deadlocks.
5362
Mike Lockwood28569302010-01-28 11:54:40 -05005363 synchronized (mScreenLockTimeout) {
5364 if (mLockScreenTimerActive) {
5365 // reset the timer
5366 mHandler.removeCallbacks(mScreenLockTimeout);
5367 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
5368 }
5369 }
Daniel Sandler0601eb72011-04-13 01:01:32 -04005370 }
5371
Adam Cohenf7522022012-10-03 20:03:18 -07005372 class ScreenLockTimeout implements Runnable {
5373 Bundle options;
5374
5375 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05005376 public void run() {
5377 synchronized (this) {
5378 if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard");
Jim Miller5ecd8112013-01-09 18:50:26 -08005379 if (mKeyguardDelegate != null) {
5380 mKeyguardDelegate.doKeyguardTimeout(options);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005381 }
Mike Lockwood28569302010-01-28 11:54:40 -05005382 mLockScreenTimerActive = false;
Adam Cohenf7522022012-10-03 20:03:18 -07005383 options = null;
Mike Lockwood28569302010-01-28 11:54:40 -05005384 }
5385 }
Mike Lockwood28569302010-01-28 11:54:40 -05005386
Adam Cohenf7522022012-10-03 20:03:18 -07005387 public void setLockOptions(Bundle options) {
5388 this.options = options;
5389 }
5390 }
5391
5392 ScreenLockTimeout mScreenLockTimeout = new ScreenLockTimeout();
5393
Jose Lima9546b202014-07-02 17:21:51 -07005394 @Override
Adam Cohenf7522022012-10-03 20:03:18 -07005395 public void lockNow(Bundle options) {
Jim Miller93c518e2012-01-17 15:55:31 -08005396 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null);
5397 mHandler.removeCallbacks(mScreenLockTimeout);
Adam Cohenf7522022012-10-03 20:03:18 -07005398 if (options != null) {
5399 // In case multiple calls are made to lockNow, we don't wipe out the options
5400 // until the runnable actually executes.
5401 mScreenLockTimeout.setLockOptions(options);
5402 }
Jim Miller93c518e2012-01-17 15:55:31 -08005403 mHandler.post(mScreenLockTimeout);
5404 }
5405
Mike Lockwood28569302010-01-28 11:54:40 -05005406 private void updateLockScreenTimeout() {
5407 synchronized (mScreenLockTimeout) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005408 boolean enable = (mAllowLockscreenWhenOn && mAwake &&
Jim Miller5ecd8112013-01-09 18:50:26 -08005409 mKeyguardDelegate != null && mKeyguardDelegate.isSecure());
Mike Lockwood28569302010-01-28 11:54:40 -05005410 if (mLockScreenTimerActive != enable) {
5411 if (enable) {
5412 if (localLOGV) Log.v(TAG, "setting lockscreen timer");
5413 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
5414 } else {
5415 if (localLOGV) Log.v(TAG, "clearing lockscreen timer");
5416 mHandler.removeCallbacks(mScreenLockTimeout);
5417 }
5418 mLockScreenTimerActive = enable;
5419 }
5420 }
5421 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005422
5423 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07005424 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005425 public void enableScreenAfterBoot() {
5426 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07005427 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07005428 updateRotation(true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005429 }
Dianne Hackbornf54c8f92009-09-19 14:03:57 -07005430
Jeff Brownc458ce92012-04-30 14:58:40 -07005431 private void applyLidSwitchState() {
Jeff Brownc458ce92012-04-30 14:58:40 -07005432 if (mLidState == LID_CLOSED && mLidControlsSleep) {
Jeff Brown6d8fd272014-05-20 21:24:38 -07005433 mPowerManager.goToSleep(SystemClock.uptimeMillis(),
Jeff Brownc12035c2014-08-13 18:52:25 -07005434 PowerManager.GO_TO_SLEEP_REASON_LID_SWITCH,
Jeff Brown6d8fd272014-05-20 21:24:38 -07005435 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
Jeff Brownc458ce92012-04-30 14:58:40 -07005436 }
Jeff Browna20dda42014-05-27 20:57:24 -07005437
5438 synchronized (mLock) {
5439 updateWakeGestureListenerLp();
5440 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005441 }
5442
Jeff Brown4f5fa282014-06-12 19:19:15 -07005443 void updateUiMode() {
5444 if (mUiModeManager == null) {
5445 mUiModeManager = IUiModeManager.Stub.asInterface(
5446 ServiceManager.getService(Context.UI_MODE_SERVICE));
5447 }
5448 try {
5449 mUiMode = mUiModeManager.getCurrentModeType();
5450 } catch (RemoteException e) {
5451 }
5452 }
5453
Jeff Brown01a98dd2011-09-20 15:08:29 -07005454 void updateRotation(boolean alwaysSendConfiguration) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005455 try {
5456 //set orientation on WindowManager
Dianne Hackbornf87d1962012-04-04 12:48:24 -07005457 mWindowManager.updateRotation(alwaysSendConfiguration, false);
5458 } catch (RemoteException e) {
5459 // Ignore
5460 }
5461 }
5462
5463 void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) {
5464 try {
5465 //set orientation on WindowManager
5466 mWindowManager.updateRotation(alwaysSendConfiguration, forceRelayout);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005467 } catch (RemoteException e) {
5468 // Ignore
5469 }
5470 }
5471
Daniel Sandler6396c722013-04-16 20:19:09 -04005472 /**
5473 * Return an Intent to launch the currently active dock app as home. Returns
5474 * null if the standard home should be launched, which is the case if any of the following is
5475 * true:
5476 * <ul>
5477 * <li>The device is not in either car mode or desk mode
5478 * <li>The device is in car mode but ENABLE_CAR_DOCK_HOME_CAPTURE is false
5479 * <li>The device is in desk mode but ENABLE_DESK_DOCK_HOME_CAPTURE is false
5480 * <li>The device is in car mode but there's no CAR_DOCK app with METADATA_DOCK_HOME
5481 * <li>The device is in desk mode but there's no DESK_DOCK app with METADATA_DOCK_HOME
5482 * </ul>
Craig Mautnereda67292013-04-28 13:50:14 -07005483 * @return A dock intent.
Daniel Sandler6396c722013-04-16 20:19:09 -04005484 */
5485 Intent createHomeDockIntent() {
5486 Intent intent = null;
5487
5488 // What home does is based on the mode, not the dock state. That
5489 // is, when in car mode you should be taken to car home regardless
5490 // of whether we are actually in a car dock.
5491 if (mUiMode == Configuration.UI_MODE_TYPE_CAR) {
5492 if (ENABLE_CAR_DOCK_HOME_CAPTURE) {
5493 intent = mCarDockIntent;
5494 }
5495 } else if (mUiMode == Configuration.UI_MODE_TYPE_DESK) {
5496 if (ENABLE_DESK_DOCK_HOME_CAPTURE) {
5497 intent = mDeskDockIntent;
5498 }
Jeff Brown4f5fa282014-06-12 19:19:15 -07005499 } else if (mUiMode == Configuration.UI_MODE_TYPE_WATCH
5500 && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
5501 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK
5502 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK)) {
5503 // Always launch dock home from home when watch is docked, if it exists.
5504 intent = mDeskDockIntent;
Daniel Sandler6396c722013-04-16 20:19:09 -04005505 }
5506
5507 if (intent == null) {
5508 return null;
5509 }
5510
5511 ActivityInfo ai = null;
5512 ResolveInfo info = mContext.getPackageManager().resolveActivityAsUser(
5513 intent,
John Spurlockf56bef12013-07-09 09:51:46 -04005514 PackageManager.MATCH_DEFAULT_ONLY | PackageManager.GET_META_DATA,
Craig Mautnerd625ab22013-09-06 13:40:31 -07005515 mCurrentUserId);
Daniel Sandler6396c722013-04-16 20:19:09 -04005516 if (info != null) {
5517 ai = info.activityInfo;
5518 }
5519 if (ai != null
5520 && ai.metaData != null
5521 && ai.metaData.getBoolean(Intent.METADATA_DOCK_HOME)) {
5522 intent = new Intent(intent);
5523 intent.setClassName(ai.packageName, ai.name);
5524 return intent;
5525 }
5526
5527 return null;
5528 }
5529
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005530 void startDockOrHome() {
John Spurlockc8b46ca2013-04-08 12:59:26 -04005531 awakenDreams();
Daniel Sandler6396c722013-04-16 20:19:09 -04005532
5533 Intent dock = createHomeDockIntent();
5534 if (dock != null) {
5535 try {
5536 mContext.startActivityAsUser(dock, UserHandle.CURRENT);
5537 return;
5538 } catch (ActivityNotFoundException e) {
5539 }
5540 }
5541
Dianne Hackbornd8883992012-09-07 15:58:52 -07005542 mContext.startActivityAsUser(mHomeIntent, UserHandle.CURRENT);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005543 }
Craig Mautnereda67292013-04-28 13:50:14 -07005544
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005545 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005546 * goes to the home screen
5547 * @return whether it did anything
5548 */
5549 boolean goHome() {
5550 if (false) {
5551 // This code always brings home to the front.
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07005552 try {
5553 ActivityManagerNative.getDefault().stopAppSwitches();
5554 } catch (RemoteException e) {
5555 }
Dianne Hackborn94a679d2009-07-28 17:51:07 -07005556 sendCloseSystemWindows();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005557 startDockOrHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005558 } else {
5559 // This code brings home to the front or, if it is already
5560 // at the front, puts the device to sleep.
5561 try {
Wink Savilled2e6a332010-02-12 12:12:06 -08005562 if (SystemProperties.getInt("persist.sys.uts-test-mode", 0) == 1) {
5563 /// Roll back EndcallBehavior as the cupcake design to pass P1 lab entry.
5564 Log.d(TAG, "UTS-TEST-MODE");
5565 } else {
5566 ActivityManagerNative.getDefault().stopAppSwitches();
5567 sendCloseSystemWindows();
Daniel Sandler6396c722013-04-16 20:19:09 -04005568 Intent dock = createHomeDockIntent();
5569 if (dock != null) {
5570 int result = ActivityManagerNative.getDefault()
5571 .startActivityAsUser(null, null, dock,
5572 dock.resolveTypeIfNeeded(mContext.getContentResolver()),
5573 null, null, 0,
5574 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07005575 null, null, UserHandle.USER_CURRENT);
Daniel Sandler6396c722013-04-16 20:19:09 -04005576 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
5577 return false;
5578 }
5579 }
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005580 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005581 int result = ActivityManagerNative.getDefault()
Dianne Hackbornf265ea92013-01-31 15:00:51 -08005582 .startActivityAsUser(null, null, mHomeIntent,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005583 mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()),
Dianne Hackborna4972e92012-03-14 10:38:05 -07005584 null, null, 0,
5585 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07005586 null, null, UserHandle.USER_CURRENT);
Dianne Hackborna4972e92012-03-14 10:38:05 -07005587 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005588 return false;
5589 }
5590 } catch (RemoteException ex) {
5591 // bummer, the activity manager, which is in this process, is dead
5592 }
5593 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005594 return true;
5595 }
Craig Mautnereda67292013-04-28 13:50:14 -07005596
5597 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07005598 public void setCurrentOrientationLw(int newOrientation) {
5599 synchronized (mLock) {
5600 if (newOrientation != mCurrentAppOrientation) {
5601 mCurrentAppOrientation = newOrientation;
5602 updateOrientationListenerLp();
5603 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005604 }
5605 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08005606
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07005607 private void performAuditoryFeedbackForAccessibilityIfNeed() {
5608 if (!isGlobalAccessibilityGestureEnabled()) {
5609 return;
5610 }
5611 AudioManager audioManager = (AudioManager) mContext.getSystemService(
5612 Context.AUDIO_SERVICE);
5613 if (audioManager.isSilentMode()) {
5614 return;
5615 }
5616 Ringtone ringTone = RingtoneManager.getRingtone(mContext,
5617 Settings.System.DEFAULT_NOTIFICATION_URI);
5618 ringTone.setStreamType(AudioManager.STREAM_MUSIC);
5619 ringTone.play();
5620 }
Craig Mautnereda67292013-04-28 13:50:14 -07005621
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07005622 private boolean isGlobalAccessibilityGestureEnabled() {
5623 return Settings.Global.getInt(mContext.getContentResolver(),
5624 Settings.Global.ENABLE_ACCESSIBILITY_GLOBAL_GESTURE_ENABLED, 0) == 1;
5625 }
5626
Craig Mautnereda67292013-04-28 13:50:14 -07005627 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07005628 public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) {
Svetoslav Ganov96179212012-10-10 14:17:45 -07005629 if (!mVibrator.hasVibrator()) {
5630 return false;
5631 }
Christopher Tate5e08af02012-09-21 17:17:22 -07005632 final boolean hapticsDisabled = Settings.System.getIntForUser(mContext.getContentResolver(),
5633 Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) == 0;
Jeff Brown82379ba2014-07-25 19:03:28 -07005634 if (hapticsDisabled && !always) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005635 return false;
5636 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08005637 long[] pattern = null;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005638 switch (effectId) {
5639 case HapticFeedbackConstants.LONG_PRESS:
Amith Yamasanic33cb712010-02-10 15:21:49 -08005640 pattern = mLongPressVibePattern;
5641 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07005642 case HapticFeedbackConstants.VIRTUAL_KEY:
Amith Yamasanic33cb712010-02-10 15:21:49 -08005643 pattern = mVirtualKeyVibePattern;
5644 break;
5645 case HapticFeedbackConstants.KEYBOARD_TAP:
5646 pattern = mKeyboardTapVibePattern;
5647 break;
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07005648 case HapticFeedbackConstants.CLOCK_TICK:
5649 pattern = mClockTickVibePattern;
5650 break;
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07005651 case HapticFeedbackConstants.CALENDAR_DATE:
5652 pattern = mCalendarDateVibePattern;
5653 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07005654 case HapticFeedbackConstants.SAFE_MODE_DISABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08005655 pattern = mSafeModeDisabledVibePattern;
5656 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07005657 case HapticFeedbackConstants.SAFE_MODE_ENABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08005658 pattern = mSafeModeEnabledVibePattern;
5659 break;
Amith Yamasanic33cb712010-02-10 15:21:49 -08005660 default:
5661 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005662 }
Dianne Hackbornf265ea92013-01-31 15:00:51 -08005663 int owningUid;
5664 String owningPackage;
5665 if (win != null) {
5666 owningUid = win.getOwningUid();
5667 owningPackage = win.getOwningPackage();
5668 } else {
5669 owningUid = android.os.Process.myUid();
Dianne Hackborn95d78532013-09-11 09:51:14 -07005670 owningPackage = mContext.getOpPackageName();
Dianne Hackbornf265ea92013-01-31 15:00:51 -08005671 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08005672 if (pattern.length == 1) {
5673 // One-shot vibration
John Spurlock7b414672014-07-18 13:02:39 -04005674 mVibrator.vibrate(owningUid, owningPackage, pattern[0], VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08005675 } else {
5676 // Pattern vibration
John Spurlock7b414672014-07-18 13:02:39 -04005677 mVibrator.vibrate(owningUid, owningPackage, pattern, -1, VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08005678 }
5679 return true;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005680 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005681
5682 @Override
5683 public void keepScreenOnStartedLw() {
Daniel Sandler0601eb72011-04-13 01:01:32 -04005684 }
5685
Jeff Brownc38c9be2012-10-04 13:16:19 -07005686 @Override
5687 public void keepScreenOnStoppedLw() {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01005688 if (mKeyguardDelegate != null && !mKeyguardDelegate.isShowingAndNotOccluded()) {
Jim Miller25190572013-02-28 17:36:24 -08005689 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005690 }
5691 }
Mike Lockwoodfcb39242009-10-21 23:01:07 -04005692
Dianne Hackborndf89e652011-10-06 22:35:11 -07005693 private int updateSystemUiVisibilityLw() {
Joe Onorato664644d2011-01-23 17:53:23 -08005694 // If there is no window focused, there will be nobody to handle the events
5695 // anyway, so just hang on in whatever state we're in until things settle down.
John Spurlock79da8332013-09-20 12:04:47 -04005696 WindowState win = mFocusedWindow != null ? mFocusedWindow : mTopFullscreenOpaqueWindowState;
5697 if (win == null) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07005698 return 0;
5699 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01005700 if ((win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 && mHideLockScreen == true) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07005701 // We are updating at a point where the keyguard has gotten
5702 // focus, but we were last in a state where the top window is
5703 // hiding it. This is probably because the keyguard as been
5704 // shown while the top window was displayed, so we want to ignore
5705 // it here because this is just a very transient change and it
5706 // will quickly lose focus once it correctly gets hidden.
5707 return 0;
5708 }
John Spurlock32beb2c2013-03-11 10:16:47 -04005709
John Spurlock1db8b682014-02-18 11:18:59 -05005710 int tmpVisibility = PolicyControl.getSystemUiVisibility(win, null)
Dianne Hackborne26ab702011-10-16 13:21:33 -07005711 & ~mResettingSystemUiFlags
5712 & ~mForceClearedSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04005713 if (mForcingShowNavBar && win.getSurfaceLayer() < mForcingShowNavBarLayer) {
John Spurlockc6d1c602014-01-17 15:22:06 -05005714 tmpVisibility &= ~PolicyControl.adjustClearableFlags(win, View.SYSTEM_UI_CLEARABLE_FLAGS);
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08005715 }
John Spurlock79da8332013-09-20 12:04:47 -04005716 final int visibility = updateSystemBarsLw(win, mLastSystemUiFlags, tmpVisibility);
John Spurlockad3e6cb2013-04-30 08:47:43 -04005717 final int diff = visibility ^ mLastSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04005718 final boolean needsMenu = win.getNeedsMenuLw(mTopFullscreenOpaqueWindowState);
Dianne Hackborne0f085d2011-11-30 18:41:15 -08005719 if (diff == 0 && mLastFocusNeedsMenu == needsMenu
John Spurlock79da8332013-09-20 12:04:47 -04005720 && mFocusedApp == win.getAppToken()) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07005721 return 0;
5722 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07005723 mLastSystemUiFlags = visibility;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08005724 mLastFocusNeedsMenu = needsMenu;
John Spurlock79da8332013-09-20 12:04:47 -04005725 mFocusedApp = win.getAppToken();
Dianne Hackborndf89e652011-10-06 22:35:11 -07005726 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07005727 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07005728 public void run() {
Dianne Hackborn42e620c2012-06-24 13:20:51 -07005729 try {
5730 IStatusBarService statusbar = getStatusBarService();
5731 if (statusbar != null) {
5732 statusbar.setSystemUiVisibility(visibility, 0xffffffff);
5733 statusbar.topAppWindowChanged(needsMenu);
Joe Onorato664644d2011-01-23 17:53:23 -08005734 }
Dianne Hackborn42e620c2012-06-24 13:20:51 -07005735 } catch (RemoteException e) {
5736 // re-acquire status bar service next time it is needed.
5737 mStatusBarService = null;
Joe Onorato664644d2011-01-23 17:53:23 -08005738 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07005739 }
5740 });
5741 return diff;
Joe Onorato664644d2011-01-23 17:53:23 -08005742 }
5743
John Spurlock79da8332013-09-20 12:04:47 -04005744 private int updateSystemBarsLw(WindowState win, int oldVis, int vis) {
John Spurlockbd957402013-10-03 11:38:39 -04005745 // apply translucent bar vis flags
Jorim Jaggi380ecb82014-03-14 17:25:20 +01005746 WindowState transWin = isStatusBarKeyguard() && !mHideLockScreen
5747 ? mStatusBar
John Spurlockbd957402013-10-03 11:38:39 -04005748 : mTopFullscreenOpaqueWindowState;
5749 vis = mStatusBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
5750 vis = mNavigationBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
5751
John Spurlock27735a42013-08-14 17:57:38 -04005752 // prevent status bar interaction from clearing certain flags
John Spurlock79da8332013-09-20 12:04:47 -04005753 boolean statusBarHasFocus = win.getAttrs().type == TYPE_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04005754 if (statusBarHasFocus && !isStatusBarKeyguard()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04005755 int flags = View.SYSTEM_UI_FLAG_FULLSCREEN
5756 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlockcfc359a2013-09-05 10:42:03 -04005757 | View.SYSTEM_UI_FLAG_IMMERSIVE
Jorim Jaggi5cf17872014-03-26 18:31:48 +01005758 | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
John Spurlock08ffcf52014-07-11 10:13:46 -04005759 if (mHideLockScreen) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01005760 flags |= View.STATUS_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSLUCENT;
5761 }
John Spurlockbd957402013-10-03 11:38:39 -04005762 vis = (vis & ~flags) | (oldVis & flags);
John Spurlockad3e6cb2013-04-30 08:47:43 -04005763 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04005764
Adrian Roos4fb3ee32014-08-22 19:29:09 +02005765 if (!areTranslucentBarsAllowed() && transWin != mStatusBar) {
Adrian Roosea562512014-05-05 13:33:03 +02005766 vis &= ~(View.NAVIGATION_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSLUCENT
5767 | View.SYSTEM_UI_TRANSPARENT);
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07005768 }
5769
John Spurlock27735a42013-08-14 17:57:38 -04005770 // update status bar
John Spurlockf1a36642013-10-12 17:50:42 -04005771 boolean immersiveSticky =
5772 (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
John Spurlock27735a42013-08-14 17:57:38 -04005773 boolean hideStatusBarWM =
John Spurlockbd957402013-10-03 11:38:39 -04005774 mTopFullscreenOpaqueWindowState != null &&
John Spurlockc6d1c602014-01-17 15:22:06 -05005775 (PolicyControl.getWindowFlags(mTopFullscreenOpaqueWindowState, null)
John Spurlock27735a42013-08-14 17:57:38 -04005776 & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0;
5777 boolean hideStatusBarSysui =
5778 (vis & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04005779 boolean hideNavBarSysui =
5780 (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0;
John Spurlockad3e6cb2013-04-30 08:47:43 -04005781
John Spurlock27735a42013-08-14 17:57:38 -04005782 boolean transientStatusBarAllowed =
5783 mStatusBar != null && (
5784 hideStatusBarWM
John Spurlockf1a36642013-10-12 17:50:42 -04005785 || (hideStatusBarSysui && immersiveSticky)
John Spurlock27735a42013-08-14 17:57:38 -04005786 || statusBarHasFocus);
5787
John Spurlockf1a36642013-10-12 17:50:42 -04005788 boolean transientNavBarAllowed =
5789 mNavigationBar != null &&
5790 hideNavBarSysui && immersiveSticky;
5791
John Spurlockf25706f2013-11-07 18:02:43 -05005792 boolean denyTransientStatus = mStatusBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04005793 && !transientStatusBarAllowed && hideStatusBarSysui;
John Spurlockf25706f2013-11-07 18:02:43 -05005794 boolean denyTransientNav = mNavigationBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04005795 && !transientNavBarAllowed;
5796 if (denyTransientStatus || denyTransientNav) {
John Spurlock27735a42013-08-14 17:57:38 -04005797 // clear the clearable flags instead
John Spurlockf1a36642013-10-12 17:50:42 -04005798 clearClearableFlagsLw();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005799 }
John Spurlock27735a42013-08-14 17:57:38 -04005800
5801 vis = mStatusBarController.updateVisibilityLw(transientStatusBarAllowed, oldVis, vis);
5802
5803 // update navigation bar
John Spurlockf1a36642013-10-12 17:50:42 -04005804 boolean oldImmersiveMode = isImmersiveMode(oldVis);
5805 boolean newImmersiveMode = isImmersiveMode(vis);
5806 if (win != null && oldImmersiveMode != newImmersiveMode) {
John Spurlock79da8332013-09-20 12:04:47 -04005807 final String pkg = win.getOwningPackage();
Maurice Lam99c6e072014-04-28 18:24:28 -07005808 mImmersiveModeConfirmation.immersiveModeChanged(pkg, newImmersiveMode,
5809 isUserSetupComplete());
John Spurlock34e13d92013-08-10 06:52:28 -04005810 }
John Spurlock27735a42013-08-14 17:57:38 -04005811
John Spurlockf1a36642013-10-12 17:50:42 -04005812 vis = mNavigationBarController.updateVisibilityLw(transientNavBarAllowed, oldVis, vis);
5813
John Spurlocke1f366f2013-08-05 12:22:40 -04005814 return vis;
John Spurlockad3e6cb2013-04-30 08:47:43 -04005815 }
5816
John Spurlockf1a36642013-10-12 17:50:42 -04005817 private void clearClearableFlagsLw() {
5818 int newVal = mResettingSystemUiFlags | View.SYSTEM_UI_CLEARABLE_FLAGS;
5819 if (newVal != mResettingSystemUiFlags) {
5820 mResettingSystemUiFlags = newVal;
5821 mWindowManagerFuncs.reevaluateStatusBarVisibility();
5822 }
5823 }
5824
5825 private boolean isImmersiveMode(int vis) {
5826 final int flags = View.SYSTEM_UI_FLAG_IMMERSIVE | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
John Spurlock34e13d92013-08-10 06:52:28 -04005827 return mNavigationBar != null
5828 && (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0
Daniel Sandler900ece52013-10-18 15:53:27 -04005829 && (vis & flags) != 0
5830 && canHideNavigationBar();
John Spurlock34e13d92013-08-10 06:52:28 -04005831 }
5832
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07005833 /**
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04005834 * @return whether the navigation or status bar can be made translucent
5835 *
5836 * This should return true unless touch exploration is not enabled or
5837 * R.boolean.config_enableTranslucentDecor is false.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07005838 */
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04005839 private boolean areTranslucentBarsAllowed() {
Svetoslav8e3feb12014-02-24 13:46:47 -08005840 return mTranslucentDecorEnabled
5841 && !mAccessibilityManager.isTouchExplorationEnabled();
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07005842 }
5843
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04005844 // Use this instead of checking config_showNavigationBar so that it can be consistently
5845 // overridden by qemu.hw.mainkeys in the emulator.
Craig Mautnereda67292013-04-28 13:50:14 -07005846 @Override
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04005847 public boolean hasNavigationBar() {
5848 return mHasNavigationBar;
5849 }
5850
satok1bc0a492012-04-25 22:47:12 +09005851 @Override
5852 public void setLastInputMethodWindowLw(WindowState ime, WindowState target) {
5853 mLastInputMethodWindow = ime;
5854 mLastInputMethodTargetWindow = target;
5855 }
5856
Craig Mautnerf1b67412012-09-19 13:18:29 -07005857 @Override
Satoshi Kataoka658c7b82013-10-10 17:03:51 +09005858 public int getInputMethodWindowVisibleHeightLw() {
5859 return mDockBottom - mCurBottom;
5860 }
5861
5862 @Override
Craig Mautnerf1b67412012-09-19 13:18:29 -07005863 public void setCurrentUserLw(int newUserId) {
Craig Mautnerd625ab22013-09-06 13:40:31 -07005864 mCurrentUserId = newUserId;
Jim Miller5ecd8112013-01-09 18:50:26 -08005865 if (mKeyguardDelegate != null) {
5866 mKeyguardDelegate.setCurrentUser(newUserId);
Craig Mautnerf1b67412012-09-19 13:18:29 -07005867 }
John Spurlock13451a22012-09-28 14:40:41 -04005868 if (mStatusBarService != null) {
5869 try {
5870 mStatusBarService.setCurrentUser(newUserId);
5871 } catch (RemoteException e) {
5872 // oh well
5873 }
5874 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07005875 setLastInputMethodWindowLw(null, null);
Craig Mautnerf1b67412012-09-19 13:18:29 -07005876 }
5877
5878 @Override
Svetoslav Ganov545252f2012-12-10 18:29:24 -08005879 public boolean canMagnifyWindow(int windowType) {
5880 switch (windowType) {
5881 case WindowManager.LayoutParams.TYPE_INPUT_METHOD:
5882 case WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG:
5883 case WindowManager.LayoutParams.TYPE_NAVIGATION_BAR:
5884 case WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY: {
5885 return false;
5886 }
5887 }
5888 return true;
5889 }
5890
5891 @Override
5892 public boolean isTopLevelWindow(int windowType) {
5893 if (windowType >= WindowManager.LayoutParams.FIRST_SUB_WINDOW
5894 && windowType <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
5895 return (windowType == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG);
5896 }
5897 return true;
5898 }
5899
Jim Miller4eeb4f62012-11-08 00:04:29 -08005900 @Override
Jeff Brownd7a04de2012-06-17 14:17:52 -07005901 public void dump(String prefix, PrintWriter pw, String[] args) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005902 pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005903 pw.print(" mSystemReady="); pw.print(mSystemReady);
5904 pw.print(" mSystemBooted="); pw.println(mSystemBooted);
Jeff Brown2e7760e2012-04-11 15:14:55 -07005905 pw.print(prefix); pw.print("mLidState="); pw.print(mLidState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005906 pw.print(" mLidOpenRotation="); pw.print(mLidOpenRotation);
Michael Wright3818c922014-09-02 13:59:07 -07005907 pw.print(" mCameraLensCoverState="); pw.print(mCameraLensCoverState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005908 pw.print(" mHdmiPlugged="); pw.println(mHdmiPlugged);
Dianne Hackborne26ab702011-10-16 13:21:33 -07005909 if (mLastSystemUiFlags != 0 || mResettingSystemUiFlags != 0
5910 || mForceClearedSystemUiFlags != 0) {
5911 pw.print(prefix); pw.print("mLastSystemUiFlags=0x");
5912 pw.print(Integer.toHexString(mLastSystemUiFlags));
5913 pw.print(" mResettingSystemUiFlags=0x");
5914 pw.print(Integer.toHexString(mResettingSystemUiFlags));
5915 pw.print(" mForceClearedSystemUiFlags=0x");
5916 pw.println(Integer.toHexString(mForceClearedSystemUiFlags));
Dianne Hackborndf89e652011-10-06 22:35:11 -07005917 }
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08005918 if (mLastFocusNeedsMenu) {
5919 pw.print(prefix); pw.print("mLastFocusNeedsMenu=");
5920 pw.println(mLastFocusNeedsMenu);
5921 }
Jeff Browna20dda42014-05-27 20:57:24 -07005922 pw.print(prefix); pw.print("mWakeGestureEnabledSetting=");
5923 pw.println(mWakeGestureEnabledSetting);
5924
Jeff Brownbcdfc622014-03-06 19:13:04 -08005925 pw.print(prefix); pw.print("mSupportAutoRotation="); pw.println(mSupportAutoRotation);
Daniel Sandler6396c722013-04-16 20:19:09 -04005926 pw.print(prefix); pw.print("mUiMode="); pw.print(mUiMode);
5927 pw.print(" mDockMode="); pw.print(mDockMode);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005928 pw.print(" mCarDockRotation="); pw.print(mCarDockRotation);
5929 pw.print(" mDeskDockRotation="); pw.println(mDeskDockRotation);
5930 pw.print(prefix); pw.print("mUserRotationMode="); pw.print(mUserRotationMode);
5931 pw.print(" mUserRotation="); pw.print(mUserRotation);
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005932 pw.print(" mAllowAllRotations="); pw.println(mAllowAllRotations);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07005933 pw.print(prefix); pw.print("mCurrentAppOrientation="); pw.println(mCurrentAppOrientation);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005934 pw.print(prefix); pw.print("mCarDockEnablesAccelerometer=");
5935 pw.print(mCarDockEnablesAccelerometer);
5936 pw.print(" mDeskDockEnablesAccelerometer=");
5937 pw.println(mDeskDockEnablesAccelerometer);
5938 pw.print(prefix); pw.print("mLidKeyboardAccessibility=");
5939 pw.print(mLidKeyboardAccessibility);
5940 pw.print(" mLidNavigationAccessibility="); pw.print(mLidNavigationAccessibility);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07005941 pw.print(" mLidControlsSleep="); pw.println(mLidControlsSleep);
Jeff Brown6d8fd272014-05-20 21:24:38 -07005942 pw.print(prefix);
5943 pw.print("mShortPressOnPowerBehavior="); pw.print(mShortPressOnPowerBehavior);
5944 pw.print(" mLongPressOnPowerBehavior="); pw.println(mLongPressOnPowerBehavior);
5945 pw.print(prefix); pw.print("mHasSoftInput="); pw.println(mHasSoftInput);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005946 pw.print(prefix); pw.print("mAwake="); pw.println(mAwake);
5947 pw.print(prefix); pw.print("mScreenOnEarly="); pw.print(mScreenOnEarly);
5948 pw.print(" mScreenOnFully="); pw.println(mScreenOnFully);
5949 pw.print(prefix); pw.print("mKeyguardDrawComplete="); pw.print(mKeyguardDrawComplete);
5950 pw.print(" mWindowManagerDrawComplete="); pw.println(mWindowManagerDrawComplete);
5951 pw.print(prefix); pw.print("mOrientationSensorEnabled=");
5952 pw.println(mOrientationSensorEnabled);
Dianne Hackbornc652de82013-02-15 16:32:56 -08005953 pw.print(prefix); pw.print("mOverscanScreen=("); pw.print(mOverscanScreenLeft);
5954 pw.print(","); pw.print(mOverscanScreenTop);
5955 pw.print(") "); pw.print(mOverscanScreenWidth);
5956 pw.print("x"); pw.println(mOverscanScreenHeight);
5957 if (mOverscanLeft != 0 || mOverscanTop != 0
5958 || mOverscanRight != 0 || mOverscanBottom != 0) {
5959 pw.print(prefix); pw.print("mOverscan left="); pw.print(mOverscanLeft);
5960 pw.print(" top="); pw.print(mOverscanTop);
5961 pw.print(" right="); pw.print(mOverscanRight);
5962 pw.print(" bottom="); pw.println(mOverscanBottom);
5963 }
Dianne Hackborn313440842013-02-19 19:22:59 -08005964 pw.print(prefix); pw.print("mRestrictedOverscanScreen=(");
5965 pw.print(mRestrictedOverscanScreenLeft);
5966 pw.print(","); pw.print(mRestrictedOverscanScreenTop);
5967 pw.print(") "); pw.print(mRestrictedOverscanScreenWidth);
5968 pw.print("x"); pw.println(mRestrictedOverscanScreenHeight);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005969 pw.print(prefix); pw.print("mUnrestrictedScreen=("); pw.print(mUnrestrictedScreenLeft);
5970 pw.print(","); pw.print(mUnrestrictedScreenTop);
5971 pw.print(") "); pw.print(mUnrestrictedScreenWidth);
5972 pw.print("x"); pw.println(mUnrestrictedScreenHeight);
5973 pw.print(prefix); pw.print("mRestrictedScreen=("); pw.print(mRestrictedScreenLeft);
5974 pw.print(","); pw.print(mRestrictedScreenTop);
5975 pw.print(") "); pw.print(mRestrictedScreenWidth);
5976 pw.print("x"); pw.println(mRestrictedScreenHeight);
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07005977 pw.print(prefix); pw.print("mStableFullscreen=("); pw.print(mStableFullscreenLeft);
5978 pw.print(","); pw.print(mStableFullscreenTop);
5979 pw.print(")-("); pw.print(mStableFullscreenRight);
5980 pw.print(","); pw.print(mStableFullscreenBottom); pw.println(")");
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07005981 pw.print(prefix); pw.print("mStable=("); pw.print(mStableLeft);
5982 pw.print(","); pw.print(mStableTop);
5983 pw.print(")-("); pw.print(mStableRight);
5984 pw.print(","); pw.print(mStableBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07005985 pw.print(prefix); pw.print("mSystem=("); pw.print(mSystemLeft);
5986 pw.print(","); pw.print(mSystemTop);
5987 pw.print(")-("); pw.print(mSystemRight);
5988 pw.print(","); pw.print(mSystemBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005989 pw.print(prefix); pw.print("mCur=("); pw.print(mCurLeft);
5990 pw.print(","); pw.print(mCurTop);
5991 pw.print(")-("); pw.print(mCurRight);
5992 pw.print(","); pw.print(mCurBottom); pw.println(")");
5993 pw.print(prefix); pw.print("mContent=("); pw.print(mContentLeft);
5994 pw.print(","); pw.print(mContentTop);
5995 pw.print(")-("); pw.print(mContentRight);
5996 pw.print(","); pw.print(mContentBottom); pw.println(")");
Dianne Hackborne30e02f2014-05-27 18:24:45 -07005997 pw.print(prefix); pw.print("mVoiceContent=("); pw.print(mVoiceContentLeft);
5998 pw.print(","); pw.print(mVoiceContentTop);
5999 pw.print(")-("); pw.print(mVoiceContentRight);
6000 pw.print(","); pw.print(mVoiceContentBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006001 pw.print(prefix); pw.print("mDock=("); pw.print(mDockLeft);
6002 pw.print(","); pw.print(mDockTop);
6003 pw.print(")-("); pw.print(mDockRight);
6004 pw.print(","); pw.print(mDockBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07006005 pw.print(prefix); pw.print("mDockLayer="); pw.print(mDockLayer);
6006 pw.print(" mStatusBarLayer="); pw.println(mStatusBarLayer);
Dianne Hackborn7ad44382012-10-18 17:46:00 -07006007 pw.print(prefix); pw.print("mShowingLockscreen="); pw.print(mShowingLockscreen);
6008 pw.print(" mShowingDream="); pw.print(mShowingDream);
6009 pw.print(" mDreamingLockscreen="); pw.println(mDreamingLockscreen);
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006010 if (mLastInputMethodWindow != null) {
6011 pw.print(prefix); pw.print("mLastInputMethodWindow=");
6012 pw.println(mLastInputMethodWindow);
6013 }
6014 if (mLastInputMethodTargetWindow != null) {
6015 pw.print(prefix); pw.print("mLastInputMethodTargetWindow=");
6016 pw.println(mLastInputMethodTargetWindow);
6017 }
6018 if (mStatusBar != null) {
6019 pw.print(prefix); pw.print("mStatusBar=");
6020 pw.println(mStatusBar);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01006021 pw.print(prefix); pw.print("isStatusBarKeyguard=");
6022 pw.print(isStatusBarKeyguard());
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006023 }
6024 if (mNavigationBar != null) {
6025 pw.print(prefix); pw.print("mNavigationBar=");
6026 pw.println(mNavigationBar);
6027 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006028 if (mFocusedWindow != null) {
6029 pw.print(prefix); pw.print("mFocusedWindow=");
6030 pw.println(mFocusedWindow);
6031 }
6032 if (mFocusedApp != null) {
6033 pw.print(prefix); pw.print("mFocusedApp=");
6034 pw.println(mFocusedApp);
6035 }
6036 if (mWinDismissingKeyguard != null) {
6037 pw.print(prefix); pw.print("mWinDismissingKeyguard=");
6038 pw.println(mWinDismissingKeyguard);
6039 }
6040 if (mTopFullscreenOpaqueWindowState != null) {
6041 pw.print(prefix); pw.print("mTopFullscreenOpaqueWindowState=");
6042 pw.println(mTopFullscreenOpaqueWindowState);
6043 }
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08006044 if (mForcingShowNavBar) {
6045 pw.print(prefix); pw.print("mForcingShowNavBar=");
6046 pw.println(mForcingShowNavBar); pw.print( "mForcingShowNavBarLayer=");
6047 pw.println(mForcingShowNavBarLayer);
6048 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07006049 pw.print(prefix); pw.print("mTopIsFullscreen="); pw.print(mTopIsFullscreen);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006050 pw.print(" mHideLockScreen="); pw.println(mHideLockScreen);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07006051 pw.print(prefix); pw.print("mForceStatusBar="); pw.print(mForceStatusBar);
6052 pw.print(" mForceStatusBarFromKeyguard=");
6053 pw.println(mForceStatusBarFromKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006054 pw.print(prefix); pw.print("mDismissKeyguard="); pw.print(mDismissKeyguard);
Craig Mautnerad09bcc2012-10-08 13:33:11 -07006055 pw.print(" mWinDismissingKeyguard="); pw.print(mWinDismissingKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006056 pw.print(" mHomePressed="); pw.println(mHomePressed);
6057 pw.print(prefix); pw.print("mAllowLockscreenWhenOn="); pw.print(mAllowLockscreenWhenOn);
6058 pw.print(" mLockScreenTimeout="); pw.print(mLockScreenTimeout);
6059 pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive);
6060 pw.print(prefix); pw.print("mEndcallBehavior="); pw.print(mEndcallBehavior);
6061 pw.print(" mIncallPowerBehavior="); pw.print(mIncallPowerBehavior);
6062 pw.print(" mLongPressOnHomeBehavior="); pw.println(mLongPressOnHomeBehavior);
6063 pw.print(prefix); pw.print("mLandscapeRotation="); pw.print(mLandscapeRotation);
6064 pw.print(" mSeascapeRotation="); pw.println(mSeascapeRotation);
6065 pw.print(prefix); pw.print("mPortraitRotation="); pw.print(mPortraitRotation);
6066 pw.print(" mUpsideDownRotation="); pw.println(mUpsideDownRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07006067 pw.print(prefix); pw.print("mDemoHdmiRotation="); pw.print(mDemoHdmiRotation);
6068 pw.print(" mDemoHdmiRotationLock="); pw.println(mDemoHdmiRotationLock);
6069 pw.print(prefix); pw.print("mUndockedHdmiRotation="); pw.println(mUndockedHdmiRotation);
Jeff Brown600f0032014-05-22 17:06:00 -07006070
Tim Kilbournd7c0c2e2014-05-29 16:08:10 -07006071 mGlobalKeyManager.dump(prefix, pw);
John Spurlock27735a42013-08-14 17:57:38 -04006072 mStatusBarController.dump(pw, prefix);
6073 mNavigationBarController.dump(pw, prefix);
John Spurlockc6d1c602014-01-17 15:22:06 -05006074 PolicyControl.dump(prefix, pw);
Jeff Brown600f0032014-05-22 17:06:00 -07006075
Jeff Browna20dda42014-05-27 20:57:24 -07006076 if (mWakeGestureListener != null) {
6077 mWakeGestureListener.dump(pw, prefix);
6078 }
Jeff Brown600f0032014-05-22 17:06:00 -07006079 if (mOrientationListener != null) {
6080 mOrientationListener.dump(pw, prefix);
6081 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006082 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006083}