blob: c4140728233311665c6c7dcf0fdd4aa2fce3c2d0 [file] [log] [blame]
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001/*
Jeff Brown37df39a92015-02-25 15:42:31 -08002 * Copyright (C) 2006 The Android Open Source Project
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Jorim Jaggib10e33f2015-02-04 21:57:40 +010017package com.android.server.policy;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080018
Dianne Hackborna4972e92012-03-14 10:38:05 -070019import android.app.ActivityManager;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080020import android.app.ActivityManagerNative;
Dianne Hackbornc2293022013-02-06 23:14:49 -080021import android.app.AppOpsManager;
Daniel Sandler6396c722013-04-16 20:19:09 -040022import android.app.IUiModeManager;
Dianne Hackborn661cd522011-08-22 00:26:20 -070023import android.app.ProgressDialog;
Jeff Brownde7a8ea2012-06-13 18:28:57 -070024import android.app.SearchManager;
John Spurlock97642182013-07-29 17:58:39 -040025import android.app.StatusBarManager;
Dianne Hackborn78968392010-03-04 20:47:56 -080026import android.app.UiModeManager;
Dianne Hackborn39c2d712009-09-22 11:41:31 -070027import android.content.ActivityNotFoundException;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080028import android.content.BroadcastReceiver;
Daniel Sandler0601eb72011-04-13 01:01:32 -040029import android.content.ComponentName;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080030import android.content.ContentResolver;
31import android.content.Context;
32import android.content.Intent;
Mike Lockwood1753f7f2009-08-24 14:49:07 -070033import android.content.IntentFilter;
Winson Chung9112ec32011-06-27 13:15:32 -070034import android.content.ServiceConnection;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080035import android.content.pm.ActivityInfo;
36import android.content.pm.PackageManager;
Daniel Sandler6396c722013-04-16 20:19:09 -040037import android.content.pm.ResolveInfo;
Dianne Hackborn2f0b1752011-05-31 17:59:49 -070038import android.content.res.CompatibilityInfo;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080039import android.content.res.Configuration;
40import android.content.res.Resources;
Craig Mautner8e4df6c2012-05-23 16:57:23 -070041import android.content.res.TypedArray;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080042import android.database.ContentObserver;
Dianne Hackbornc777e072010-02-12 13:07:59 -080043import android.graphics.PixelFormat;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080044import android.graphics.Rect;
John Spurlock7b414672014-07-18 13:02:39 -040045import android.media.AudioAttributes;
Michael Jurka7a348952012-02-27 13:07:58 -080046import android.media.AudioManager;
John Spurlock61560172015-02-06 19:46:04 -050047import android.media.AudioSystem;
Michael Jurka7a348952012-02-27 13:07:58 -080048import android.media.IAudioService;
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -070049import android.media.Ringtone;
50import android.media.RingtoneManager;
RoboErik8a2cfc32014-05-16 11:19:38 -070051import android.media.session.MediaSessionLegacyHelper;
Dianne Hackborn38e29a62011-09-18 14:43:08 -070052import android.os.Bundle;
Craig Mautner276a6eb2014-11-04 15:32:57 -080053import android.os.Debug;
Jeff Brown9a538ee2012-08-20 14:56:57 -070054import android.os.FactoryTest;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080055import android.os.Handler;
56import android.os.IBinder;
Jeff Brown32cbc38552011-12-01 14:01:49 -080057import android.os.Looper;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -070058import android.os.Message;
59import android.os.Messenger;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080060import android.os.PowerManager;
61import android.os.RemoteException;
62import android.os.ServiceManager;
63import android.os.SystemClock;
64import android.os.SystemProperties;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -080065import android.os.UEventObserver;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -070066import android.os.UserHandle;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080067import android.os.Vibrator;
Michael Wright3818c922014-09-02 13:59:07 -070068import android.provider.MediaStore;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080069import android.provider.Settings;
Jose Lima9546b202014-07-02 17:21:51 -070070import android.service.dreams.DreamManagerInternal;
John Spurlockc8b46ca2013-04-08 12:59:26 -040071import android.service.dreams.DreamService;
72import android.service.dreams.IDreamManager;
Michael Wrightdc63f7b2014-08-21 19:05:21 -070073import android.speech.RecognizerIntent;
Tyler Gunnef9f6f92014-09-12 22:16:17 -070074import android.telecom.TelecomManager;
Dianne Hackborn81e56d52011-05-26 00:55:58 -070075import android.util.DisplayMetrics;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080076import android.util.EventLog;
77import android.util.Log;
Jorim Jaggi24bec7c2015-02-04 12:40:14 +010078import android.util.Pair;
Jeff Browna41ca772010-08-11 14:46:32 -070079import android.util.Slog;
Jeff Brown6651a632011-11-28 12:59:11 -080080import android.util.SparseArray;
Dianne Hackbornf87d1962012-04-04 12:48:24 -070081import android.view.Display;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080082import android.view.Gravity;
83import android.view.HapticFeedbackConstants;
Dianne Hackborne0f085d2011-11-30 18:41:15 -080084import android.view.IApplicationToken;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080085import android.view.IWindowManager;
Jeff Browna41ca772010-08-11 14:46:32 -070086import android.view.InputChannel;
Jeff Brown4d396052010-10-29 21:50:21 -070087import android.view.InputDevice;
Jeff Brown4952dfd2011-11-30 19:23:22 -080088import android.view.InputEvent;
Jeff Brown32cbc38552011-12-01 14:01:49 -080089import android.view.InputEventReceiver;
Jeff Brown6b53e8d2010-11-10 16:03:06 -080090import android.view.KeyCharacterMap;
Craig Mautnerae446592012-12-06 19:05:05 -080091import android.view.KeyCharacterMap.FallbackAction;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080092import android.view.KeyEvent;
93import android.view.MotionEvent;
Jorim Jaggib10e33f2015-02-04 21:57:40 +010094import android.view.PhoneWindow;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080095import android.view.Surface;
96import android.view.View;
97import android.view.ViewConfiguration;
98import android.view.Window;
99import android.view.WindowManager;
Craig Mautnerae446592012-12-06 19:05:05 -0800100import android.view.WindowManagerGlobal;
Craig Mautner8a0da012014-05-31 15:13:37 -0700101import android.view.WindowManagerInternal;
Craig Mautnerae446592012-12-06 19:05:05 -0800102import android.view.WindowManagerPolicy;
Craig Mautnerae446592012-12-06 19:05:05 -0800103import android.view.accessibility.AccessibilityEvent;
Svetoslav8e3feb12014-02-24 13:46:47 -0800104import android.view.accessibility.AccessibilityManager;
Craig Mautnerae446592012-12-06 19:05:05 -0800105import android.view.animation.Animation;
Jorim Jaggi76a16232014-08-08 17:00:47 +0200106import android.view.animation.AnimationSet;
Craig Mautnerae446592012-12-06 19:05:05 -0800107import android.view.animation.AnimationUtils;
Jorim Jaggi24bec7c2015-02-04 12:40:14 +0100108import android.view.animation.Interpolator;
109import android.view.animation.TranslateAnimation;
Craig Mautnerae446592012-12-06 19:05:05 -0800110
111import com.android.internal.R;
Craig Mautnerae446592012-12-06 19:05:05 -0800112import com.android.internal.statusbar.IStatusBarService;
Craig Mautnerae446592012-12-06 19:05:05 -0800113import com.android.internal.widget.PointerLocationView;
Craig Mautner8a0da012014-05-31 15:13:37 -0700114import com.android.server.LocalServices;
Jorim Jaggib10e33f2015-02-04 21:57:40 +0100115import com.android.server.policy.keyguard.KeyguardServiceDelegate;
116import com.android.server.policy.keyguard.KeyguardServiceDelegate.ShowListener;
Craig Mautnerae446592012-12-06 19:05:05 -0800117
118import java.io.File;
119import java.io.FileReader;
120import java.io.IOException;
121import java.io.PrintWriter;
Craig Mautner2bc789b2014-03-19 19:48:38 -0700122import java.util.HashSet;
Craig Mautner276a6eb2014-11-04 15:32:57 -0800123import java.util.List;
Craig Mautnerae446592012-12-06 19:05:05 -0800124
Dianne Hackbornc652de82013-02-15 16:32:56 -0800125import static android.view.WindowManager.LayoutParams.*;
Jeff Brownac143512012-04-05 18:57:33 -0700126import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_ABSENT;
127import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_OPEN;
128import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_CLOSED;
Michael Wright3818c922014-09-02 13:59:07 -0700129import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVER_ABSENT;
130import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_UNCOVERED;
131import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVERED;
Dianne Hackborn08743722009-12-21 12:16:51 -0800132
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800133/**
The Android Open Source Project0727d222009-03-11 12:11:58 -0700134 * WindowManagerPolicy implementation for the Android phone UI. This
135 * introduces a new method suffix, Lp, for an internal lock of the
136 * PhoneWindowManager. This is used to protect some internal state, and
John Spurlock04db1762013-05-13 12:46:41 -0400137 * 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 -0700138 * of both of those when held.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800139 */
140public class PhoneWindowManager implements WindowManagerPolicy {
141 static final String TAG = "WindowManager";
142 static final boolean DEBUG = false;
Joe Onorato43a17652011-04-06 19:22:23 -0700143 static final boolean localLOGV = false;
Jeff Brown40013652012-05-16 21:22:36 -0700144 static final boolean DEBUG_INPUT = false;
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -0700145 static final boolean DEBUG_KEYGUARD = false;
146 static final boolean DEBUG_LAYOUT = false;
Craig Mautner6fbda632012-07-03 09:26:39 -0700147 static final boolean DEBUG_STARTING_WINDOW = false;
Craig Mautner8a0da012014-05-31 15:13:37 -0700148 static final boolean DEBUG_WAKEUP = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800149 static final boolean SHOW_STARTING_ANIMATIONS = true;
150 static final boolean SHOW_PROCESSES_ON_ALT_MENU = false;
Joe Onoratod208e702010-10-08 16:22:43 -0400151
Daniel Sandler6396c722013-04-16 20:19:09 -0400152 // Whether to allow dock apps with METADATA_DOCK_HOME to temporarily take over the Home key.
153 // No longer recommended for desk docks; still useful in car docks.
154 static final boolean ENABLE_CAR_DOCK_HOME_CAPTURE = true;
155 static final boolean ENABLE_DESK_DOCK_HOME_CAPTURE = false;
156
Jeff Brown6d8fd272014-05-20 21:24:38 -0700157 static final int SHORT_PRESS_POWER_NOTHING = 0;
158 static final int SHORT_PRESS_POWER_GO_TO_SLEEP = 1;
159 static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP = 2;
160 static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME = 3;
Bryce Lee01b0c5f2015-02-05 18:24:04 -0800161 static final int SHORT_PRESS_POWER_GO_HOME = 4;
Jeff Brown6d8fd272014-05-20 21:24:38 -0700162
Joe Onoratod208e702010-10-08 16:22:43 -0400163 static final int LONG_PRESS_POWER_NOTHING = 0;
164 static final int LONG_PRESS_POWER_GLOBAL_ACTIONS = 1;
165 static final int LONG_PRESS_POWER_SHUT_OFF = 2;
Jeff Brown9a538ee2012-08-20 14:56:57 -0700166 static final int LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM = 3;
Michael Jurka3b1fc472011-06-13 10:54:40 -0700167
Jeff Brown13f00f02014-10-31 14:45:50 -0700168 static final int MULTI_PRESS_POWER_NOTHING = 0;
169 static final int MULTI_PRESS_POWER_THEATER_MODE = 1;
170 static final int MULTI_PRESS_POWER_BRIGHTNESS_BOOST = 2;
171
Michael Jurka3b1fc472011-06-13 10:54:40 -0700172 // These need to match the documentation/constant in
173 // core/res/res/values/config.xml
Joe Onorato46b0d682010-11-22 17:37:27 -0800174 static final int LONG_PRESS_HOME_NOTHING = 0;
Michael Wrightc9ebea72013-01-16 19:25:02 -0800175 static final int LONG_PRESS_HOME_RECENT_SYSTEM_UI = 1;
Jeff Browncaca8812013-05-09 13:34:33 -0700176 static final int LONG_PRESS_HOME_ASSIST = 2;
177
178 static final int DOUBLE_TAP_HOME_NOTHING = 0;
179 static final int DOUBLE_TAP_HOME_RECENT_SYSTEM_UI = 1;
Joe Onorato46b0d682010-11-22 17:37:27 -0800180
Dianne Hackborn5cb8d792009-05-21 17:34:15 -0700181 static final int APPLICATION_MEDIA_SUBLAYER = -2;
182 static final int APPLICATION_MEDIA_OVERLAY_SUBLAYER = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800183 static final int APPLICATION_PANEL_SUBLAYER = 1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800184 static final int APPLICATION_SUB_PANEL_SUBLAYER = 2;
Craig Mautner88400d32012-09-30 12:35:45 -0700185
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800186 static public final String SYSTEM_DIALOG_REASON_KEY = "reason";
187 static public final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions";
188 static public final String SYSTEM_DIALOG_REASON_RECENT_APPS = "recentapps";
Joe Onoratof275f0c2009-11-24 16:11:13 -0500189 static public final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey";
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700190 static public final String SYSTEM_DIALOG_REASON_ASSIST = "assist";
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800191
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700192 /**
193 * These are the system UI flags that, when changing, can cause the layout
194 * of the screen to change.
195 */
196 static final int SYSTEM_UI_CHANGING_LAYOUT =
John Spurlocke1f366f2013-08-05 12:22:40 -0400197 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlock7f4820a2013-10-08 12:54:35 -0400198 | View.SYSTEM_UI_FLAG_FULLSCREEN
199 | View.STATUS_BAR_TRANSLUCENT
Adrian Roosea562512014-05-05 13:33:03 +0200200 | View.NAVIGATION_BAR_TRANSLUCENT
201 | View.SYSTEM_UI_TRANSPARENT;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700202
John Spurlock7b414672014-07-18 13:02:39 -0400203 private static final AudioAttributes VIBRATION_ATTRIBUTES = new AudioAttributes.Builder()
204 .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
205 .setUsage(AudioAttributes.USAGE_ASSISTANCE_SONIFICATION)
206 .build();
207
Jim Miller5ecd8112013-01-09 18:50:26 -0800208 /**
209 * Keyguard stuff
210 */
211 private WindowState mKeyguardScrim;
Jorim Jaggi380ecb82014-03-14 17:25:20 +0100212 private boolean mKeyguardHidden;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700213 private boolean mKeyguardDrawnOnce;
Jim Miller5ecd8112013-01-09 18:50:26 -0800214
Jeff Brown6651a632011-11-28 12:59:11 -0800215 /* Table of Application Launch keys. Maps from key codes to intent categories.
216 *
217 * These are special keys that are used to launch particular kinds of applications,
218 * such as a web browser. HID defines nearly a hundred of them in the Consumer (0x0C)
219 * usage page. We don't support quite that many yet...
220 */
221 static SparseArray<String> sApplicationLaunchKeyCategories;
222 static {
223 sApplicationLaunchKeyCategories = new SparseArray<String>();
224 sApplicationLaunchKeyCategories.append(
225 KeyEvent.KEYCODE_EXPLORER, Intent.CATEGORY_APP_BROWSER);
226 sApplicationLaunchKeyCategories.append(
227 KeyEvent.KEYCODE_ENVELOPE, Intent.CATEGORY_APP_EMAIL);
228 sApplicationLaunchKeyCategories.append(
229 KeyEvent.KEYCODE_CONTACTS, Intent.CATEGORY_APP_CONTACTS);
230 sApplicationLaunchKeyCategories.append(
231 KeyEvent.KEYCODE_CALENDAR, Intent.CATEGORY_APP_CALENDAR);
232 sApplicationLaunchKeyCategories.append(
233 KeyEvent.KEYCODE_MUSIC, Intent.CATEGORY_APP_MUSIC);
234 sApplicationLaunchKeyCategories.append(
235 KeyEvent.KEYCODE_CALCULATOR, Intent.CATEGORY_APP_CALCULATOR);
236 }
237
Craig Mautnerc3daedd2014-09-13 11:17:23 -0700238 /** Amount of time (in milliseconds) to wait for windows drawn before powering on. */
239 static final int WAITING_FOR_DRAWN_TIMEOUT = 1000;
240
Dianne Hackborndf89e652011-10-06 22:35:11 -0700241 /**
242 * Lock protecting internal state. Must not call out into window
243 * manager with lock held. (This lock will be acquired in places
244 * where the window manager is calling in with its own lock held.)
245 */
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800246 private final Object mLock = new Object();
Dianne Hackborndf89e652011-10-06 22:35:11 -0700247
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800248 Context mContext;
249 IWindowManager mWindowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700250 WindowManagerFuncs mWindowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -0700251 WindowManagerInternal mWindowManagerInternal;
Jeff Brown96307042012-07-27 15:51:34 -0700252 PowerManager mPowerManager;
Jose Lima9546b202014-07-02 17:21:51 -0700253 DreamManagerInternal mDreamManagerInternal;
Joe Onorato93056472010-09-10 10:30:46 -0400254 IStatusBarService mStatusBarService;
Jeff Browncaca8812013-05-09 13:34:33 -0700255 boolean mPreloadedRecentApps;
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700256 final Object mServiceAquireLock = new Object();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800257 Vibrator mVibrator; // Vibrator for giving feedback of orientation changes
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700258 SearchManager mSearchManager;
Svetoslav8e3feb12014-02-24 13:46:47 -0800259 AccessibilityManager mAccessibilityManager;
Filip Gruszczynskicfb31852015-02-25 21:47:12 +0000260 BurnInProtectionHelper mBurnInProtectionHelper;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800261
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700262 // Vibrator pattern for haptic feedback of a long press.
263 long[] mLongPressVibePattern;
Craig Mautner88400d32012-09-30 12:35:45 -0700264
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700265 // Vibrator pattern for haptic feedback of virtual key press.
266 long[] mVirtualKeyVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700267
Amith Yamasanic33cb712010-02-10 15:21:49 -0800268 // Vibrator pattern for a short vibration.
269 long[] mKeyboardTapVibePattern;
270
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -0700271 // Vibrator pattern for a short vibration when tapping on an hour/minute tick of a Clock.
272 long[] mClockTickVibePattern;
273
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -0700274 // Vibrator pattern for a short vibration when tapping on a day/month/year date of a Calendar.
275 long[] mCalendarDateVibePattern;
276
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700277 // Vibrator pattern for haptic feedback during boot when safe mode is disabled.
278 long[] mSafeModeDisabledVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700279
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700280 // Vibrator pattern for haptic feedback during boot when safe mode is enabled.
281 long[] mSafeModeEnabledVibePattern;
Romain Guy8154cd32010-03-29 14:41:15 -0700282
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800283 /** If true, hitting shift & menu will broadcast Intent.ACTION_BUG_REPORT */
284 boolean mEnableShiftMenuBugReports = false;
Mike Lockwoodd747dc82011-09-13 16:28:22 -0400285
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800286 boolean mSafeMode;
287 WindowState mStatusBar = null;
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700288 int mStatusBarHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400289 WindowState mNavigationBar = null;
Daniel Sandler36412a72011-08-04 09:35:13 -0400290 boolean mHasNavigationBar = false;
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700291 boolean mCanHideNavigationBar = false;
Daniel Sandler4a066c52012-04-20 14:49:13 -0400292 boolean mNavigationBarCanMove = false; // can the navigation bar ever move to the side?
293 boolean mNavigationBarOnBottom = true; // is the navigation bar on the bottom *right now*?
294 int[] mNavigationBarHeightForRotation = new int[4];
295 int[] mNavigationBarWidthForRotation = new int[4];
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400296
Craig Mautnera631d492014-08-05 15:16:01 -0700297 boolean mBootMessageNeedsHiding;
Jim Miller5ecd8112013-01-09 18:50:26 -0800298 KeyguardServiceDelegate mKeyguardDelegate;
Craig Mautner13f6ea72014-06-23 14:57:02 -0700299 final Runnable mWindowManagerDrawCallback = new Runnable() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700300 @Override
Craig Mautner13f6ea72014-06-23 14:57:02 -0700301 public void run() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700302 if (DEBUG_WAKEUP) Slog.i(TAG, "All windows ready for display!");
303 mHandler.sendEmptyMessage(MSG_WINDOW_MANAGER_DRAWN_COMPLETE);
304 }
305 };
306 final ShowListener mKeyguardDelegateCallback = new ShowListener() {
307 @Override
308 public void onShown(IBinder windowToken) {
309 if (DEBUG_WAKEUP) Slog.d(TAG, "mKeyguardDelegate.ShowListener.onShown.");
310 mHandler.sendEmptyMessage(MSG_KEYGUARD_DRAWN_COMPLETE);
311 }
312 };
313
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800314 GlobalActions mGlobalActions;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800315 Handler mHandler;
satok1bc0a492012-04-25 22:47:12 +0900316 WindowState mLastInputMethodWindow = null;
317 WindowState mLastInputMethodTargetWindow = null;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800318
Jeff Brown13f00f02014-10-31 14:45:50 -0700319 // FIXME This state is shared between the input reader and handler thread.
320 // Technically it's broken and buggy but it has been like this for many years
321 // and we have not yet seen any problems. Someday we'll rewrite this logic
322 // so that only one thread is involved in handling input policy. Unfortunately
323 // it's on a critical path for power management so we can't just post the work to the
324 // handler thread. We'll need to resolve this someday by teaching the input dispatcher
325 // to hold wakelocks during dispatch and eliminating the critical path.
326 volatile boolean mPowerKeyHandled;
Bryce Leed9268e32014-11-17 17:40:59 -0800327 volatile boolean mBeganFromNonInteractive;
Jeff Brown13f00f02014-10-31 14:45:50 -0700328 volatile int mPowerKeyPressCounter;
329 volatile boolean mEndCallKeyHandled;
330
Winson Chungd42a6cf2014-06-03 16:24:04 -0700331 boolean mRecentsVisible;
Winson Chung1e8d71b2014-05-16 17:05:22 -0700332 int mRecentAppsHeldModifiers;
Jeff Browncf39bdf2012-05-18 14:41:19 -0700333 boolean mLanguageSwitchKeyPressed;
Jeff Brown68b909d2011-12-07 16:36:01 -0800334
Jeff Brown2e7760e2012-04-11 15:14:55 -0700335 int mLidState = LID_ABSENT;
Michael Wright3818c922014-09-02 13:59:07 -0700336 int mCameraLensCoverState = CAMERA_LENS_COVER_ABSENT;
Jeff Browndaa37532012-05-01 15:54:03 -0700337 boolean mHaveBuiltInKeyboard;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800338
Dianne Hackbornc777e072010-02-12 13:07:59 -0800339 boolean mSystemReady;
Dianne Hackbornba24e4d2011-09-01 11:17:06 -0700340 boolean mSystemBooted;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800341 boolean mHdmiPlugged;
Jeff Brown4f5fa282014-06-12 19:19:15 -0700342 IUiModeManager mUiModeManager;
Daniel Sandler6396c722013-04-16 20:19:09 -0400343 int mUiMode;
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700344 int mDockMode = Intent.EXTRA_DOCK_STATE_UNDOCKED;
Mike Lockwood1753f7f2009-08-24 14:49:07 -0700345 int mLidOpenRotation;
Mike Lockwood2d1efbd2009-09-16 12:15:53 -0400346 int mCarDockRotation;
347 int mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -0700348 int mUndockedHdmiRotation;
349 int mDemoHdmiRotation;
350 boolean mDemoHdmiRotationLock;
Chong Zhangae6119ff2014-11-11 18:54:39 -0800351 int mDemoRotation;
352 boolean mDemoRotationLock;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400353
Jeff Browna20dda42014-05-27 20:57:24 -0700354 boolean mWakeGestureEnabledSetting;
355 MyWakeGestureListener mWakeGestureListener;
356
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700357 // Default display does not rotate, apps that require non-default orientation will have to
358 // have the orientation emulated.
359 private boolean mForceDefaultOrientation = false;
360
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400361 int mUserRotationMode = WindowManagerPolicy.USER_ROTATION_FREE;
362 int mUserRotation = Surface.ROTATION_0;
Jeff Brown207673cd2012-06-05 17:47:11 -0700363 boolean mAccelerometerDefault;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400364
Jeff Brownbcdfc622014-03-06 19:13:04 -0800365 boolean mSupportAutoRotation;
Jeff Brownd3187e32011-09-21 19:26:44 -0700366 int mAllowAllRotations = -1;
Mike Lockwoode9867d22009-09-20 01:59:02 -0400367 boolean mCarDockEnablesAccelerometer;
368 boolean mDeskDockEnablesAccelerometer;
Dianne Hackborn2862fff2009-09-15 22:56:29 -0700369 int mLidKeyboardAccessibility;
370 int mLidNavigationAccessibility;
Jeff Brownc458ce92012-04-30 14:58:40 -0700371 boolean mLidControlsSleep;
Jeff Brown13f00f02014-10-31 14:45:50 -0700372 int mShortPressOnPowerBehavior;
373 int mLongPressOnPowerBehavior;
374 int mDoublePressOnPowerBehavior;
375 int mTriplePressOnPowerBehavior;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700376 boolean mAwake;
377 boolean mScreenOnEarly;
378 boolean mScreenOnFully;
379 ScreenOnListener mScreenOnListener;
380 boolean mKeyguardDrawComplete;
381 boolean mWindowManagerDrawComplete;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800382 boolean mOrientationSensorEnabled = false;
383 int mCurrentAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800384 boolean mHasSoftInput = false;
Daniel Sandlerdd73ee42013-10-11 22:19:59 -0400385 boolean mTranslucentDecorEnabled = true;
RoboErik001c59c2015-01-26 15:53:51 -0800386 boolean mUseTvRouting;
387 boolean mUseMasterVolume;
Craig Mautner967212c2013-04-13 21:10:58 -0700388
Jeff Brown70825162012-03-28 17:27:48 -0700389 int mPointerLocationMode = 0; // guarded by mLock
Joe Onorato664644d2011-01-23 17:53:23 -0800390
391 // The last window we were told about in focusChanged.
392 WindowState mFocusedWindow;
Dianne Hackborne0f085d2011-11-30 18:41:15 -0800393 IApplicationToken mFocusedApp;
Joe Onorato664644d2011-01-23 17:53:23 -0800394
Jeff Brown70825162012-03-28 17:27:48 -0700395 PointerLocationView mPointerLocationView;
Jeff Brown32cbc38552011-12-01 14:01:49 -0800396
Dianne Hackbornc652de82013-02-15 16:32:56 -0800397 // The current size of the screen; really; extends into the overscan area of
398 // the screen and doesn't account for any system elements like the status bar.
399 int mOverscanScreenLeft, mOverscanScreenTop;
400 int mOverscanScreenWidth, mOverscanScreenHeight;
401 // The current visible size of the screen; really; (ir)regardless of whether the status
402 // bar can be hidden but not extending into the overscan area.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800403 int mUnrestrictedScreenLeft, mUnrestrictedScreenTop;
404 int mUnrestrictedScreenWidth, mUnrestrictedScreenHeight;
Dianne Hackborn313440842013-02-19 19:22:59 -0800405 // Like mOverscanScreen*, but allowed to move into the overscan region where appropriate.
406 int mRestrictedOverscanScreenLeft, mRestrictedOverscanScreenTop;
407 int mRestrictedOverscanScreenWidth, mRestrictedOverscanScreenHeight;
Dianne Hackborn82de1ae2010-10-28 11:28:39 -0700408 // The current size of the screen; these may be different than (0,0)-(dw,dh)
409 // if the status bar can't be hidden; in that case it effectively carves out
410 // that area of the display from all other windows.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800411 int mRestrictedScreenLeft, mRestrictedScreenTop;
412 int mRestrictedScreenWidth, mRestrictedScreenHeight;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700413 // During layout, the current screen borders accounting for any currently
414 // visible system UI elements.
415 int mSystemLeft, mSystemTop, mSystemRight, mSystemBottom;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700416 // For applications requesting stable content insets, these are them.
417 int mStableLeft, mStableTop, mStableRight, mStableBottom;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -0700418 // For applications requesting stable content insets but have also set the
419 // fullscreen window flag, these are the stable dimensions without the status bar.
420 int mStableFullscreenLeft, mStableFullscreenTop;
421 int mStableFullscreenRight, mStableFullscreenBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800422 // During layout, the current screen borders with all outer decoration
423 // (status bar, input method dock) accounted for.
424 int mCurLeft, mCurTop, mCurRight, mCurBottom;
425 // During layout, the frame in which content should be displayed
426 // to the user, accounting for all screen decoration except for any
427 // space they deem as available for other content. This is usually
428 // the same as mCur*, but may be larger if the screen decor has supplied
429 // content insets.
430 int mContentLeft, mContentTop, mContentRight, mContentBottom;
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700431 // During layout, the frame in which voice content should be displayed
432 // to the user, accounting for all screen decoration except for any
433 // space they deem as available for other content.
434 int mVoiceContentLeft, mVoiceContentTop, mVoiceContentRight, mVoiceContentBottom;
Dianne Hackborn8e11ef02010-11-18 19:47:42 -0800435 // During layout, the current screen borders along which input method
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800436 // windows are placed.
437 int mDockLeft, mDockTop, mDockRight, mDockBottom;
438 // During layout, the layer at which the doc window is placed.
439 int mDockLayer;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700440 // During layout, this is the layer of the status bar.
441 int mStatusBarLayer;
Dianne Hackborne26ab702011-10-16 13:21:33 -0700442 int mLastSystemUiFlags;
443 // Bits that we are in the process of clearing, so we want to prevent
444 // them from being set by applications until everything has been updated
445 // to have them clear.
446 int mResettingSystemUiFlags = 0;
447 // Bits that we are currently always keeping cleared.
448 int mForceClearedSystemUiFlags = 0;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -0800449 // What we last reported to system UI about whether the compatibility
450 // menu needs to be displayed.
451 boolean mLastFocusNeedsMenu = false;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700452
453 FakeWindow mHideNavFakeWindow = null;
454
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800455 static final Rect mTmpParentFrame = new Rect();
456 static final Rect mTmpDisplayFrame = new Rect();
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800457 static final Rect mTmpOverscanFrame = new Rect();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800458 static final Rect mTmpContentFrame = new Rect();
459 static final Rect mTmpVisibleFrame = new Rect();
John Spurlock46646232013-09-30 22:32:42 -0400460 static final Rect mTmpDecorFrame = new Rect();
Adrian Roosfa104232014-06-20 16:10:14 -0700461 static final Rect mTmpStableFrame = new Rect();
Dianne Hackborn1f903c32011-09-13 19:18:06 -0700462 static final Rect mTmpNavigationFrame = new Rect();
Craig Mautner967212c2013-04-13 21:10:58 -0700463
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800464 WindowState mTopFullscreenOpaqueWindowState;
Adrian Rooscd3884d2015-02-18 17:25:23 +0100465 WindowState mTopFullscreenOpaqueOrDimmingWindowState;
Craig Mautner2bc789b2014-03-19 19:48:38 -0700466 HashSet<IApplicationToken> mAppsToBeHidden = new HashSet<IApplicationToken>();
Jorim Jaggic13fcac2014-09-11 17:36:57 +0200467 HashSet<IApplicationToken> mAppsThatDismissKeyguard = new HashSet<IApplicationToken>();
Joe Onorato93056472010-09-10 10:30:46 -0400468 boolean mTopIsFullscreen;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800469 boolean mForceStatusBar;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -0700470 boolean mForceStatusBarFromKeyguard;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700471 boolean mHideLockScreen;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -0800472 boolean mForcingShowNavBar;
473 int mForcingShowNavBarLayer;
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700474
475 // States of keyguard dismiss.
476 private static final int DISMISS_KEYGUARD_NONE = 0; // Keyguard not being dismissed.
477 private static final int DISMISS_KEYGUARD_START = 1; // Keyguard needs to be dismissed.
478 private static final int DISMISS_KEYGUARD_CONTINUE = 2; // Keyguard has been dismissed.
479 int mDismissKeyguard = DISMISS_KEYGUARD_NONE;
480
481 /** The window that is currently dismissing the keyguard. Dismissing the keyguard must only
482 * be done once per window. */
483 private WindowState mWinDismissingKeyguard;
484
Craig Mautnerc9457fa2014-06-06 14:27:48 -0700485 /** The window that is currently showing "over" the keyguard. If there is an app window
486 * belonging to another app on top of this the keyguard shows. If there is a fullscreen
487 * app window under this, still dismiss the keyguard but don't show the app underneath. Show
488 * the wallpaper. */
489 private WindowState mWinShowWhenLocked;
490
Dianne Hackborn7ad44382012-10-18 17:46:00 -0700491 boolean mShowingLockscreen;
492 boolean mShowingDream;
493 boolean mDreamingLockscreen;
Jim Millerab954542014-10-10 18:21:49 -0700494 boolean mKeyguardSecure;
495 boolean mKeyguardSecureIncludingHidden;
496 volatile boolean mKeyguardOccluded;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800497 boolean mHomePressed;
Jeff Browncaca8812013-05-09 13:34:33 -0700498 boolean mHomeConsumed;
499 boolean mHomeDoubleTapPending;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800500 Intent mHomeIntent;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700501 Intent mCarDockIntent;
502 Intent mDeskDockIntent;
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700503 boolean mSearchKeyShortcutPending;
504 boolean mConsumeSearchKeyUp;
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700505 boolean mAssistKeyLongPressed;
Michael Wright6a62e552014-06-03 19:19:48 -0700506 boolean mPendingMetaAction;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800507
Mike Lockwood28569302010-01-28 11:54:40 -0500508 // support for activating the lock screen while the screen is on
509 boolean mAllowLockscreenWhenOn;
510 int mLockScreenTimeout;
511 boolean mLockScreenTimerActive;
512
David Brownbaf8d092010-03-08 21:52:59 -0800513 // Behavior of ENDCALL Button. (See Settings.System.END_BUTTON_BEHAVIOR.)
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800514 int mEndcallBehavior;
David Brownbaf8d092010-03-08 21:52:59 -0800515
516 // Behavior of POWER button while in-call and screen on.
517 // (See Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR.)
518 int mIncallPowerBehavior;
519
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700520 Display mDisplay;
521
Dianne Hackborn9d132642011-04-21 17:26:39 -0700522 int mLandscapeRotation = 0; // default landscape rotation
523 int mSeascapeRotation = 0; // "other" landscape rotation, 180 degrees from mLandscapeRotation
524 int mPortraitRotation = 0; // default portrait rotation
525 int mUpsideDownRotation = 0; // "other" portrait rotation
Mitsuru Oshima831d0d92009-06-16 18:27:18 -0700526
Dianne Hackbornc652de82013-02-15 16:32:56 -0800527 int mOverscanLeft = 0;
528 int mOverscanTop = 0;
529 int mOverscanRight = 0;
530 int mOverscanBottom = 0;
531
Joe Onorato46b0d682010-11-22 17:37:27 -0800532 // What we do when the user long presses on home
Jeff Browncaca8812013-05-09 13:34:33 -0700533 private int mLongPressOnHomeBehavior;
534
535 // What we do when the user double-taps on home
536 private int mDoubleTapOnHomeBehavior;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800537
Bryce Lee584a4452014-10-21 15:55:55 -0700538 // Allowed theater mode wake actions
539 private boolean mAllowTheaterModeWakeFromKey;
540 private boolean mAllowTheaterModeWakeFromPowerKey;
541 private boolean mAllowTheaterModeWakeFromMotion;
Bryce Lee812d7022014-11-10 13:33:28 -0800542 private boolean mAllowTheaterModeWakeFromMotionWhenNotDreaming;
Bryce Lee584a4452014-10-21 15:55:55 -0700543 private boolean mAllowTheaterModeWakeFromCameraLens;
544 private boolean mAllowTheaterModeWakeFromLidSwitch;
545 private boolean mAllowTheaterModeWakeFromWakeGesture;
546
Bryce Lee55e846d2014-11-04 12:43:44 -0800547 // Whether to go to sleep entering theater mode from power button
548 private boolean mGoToSleepOnButtonPressTheaterMode;
549
Winson Chung9112ec32011-06-27 13:15:32 -0700550 // Screenshot trigger states
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700551 // Time to volume and power must be pressed within this interval of each other.
552 private static final long SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS = 150;
Winson Chung1cea2f32012-10-08 20:42:01 -0700553 // Increase the chord delay when taking a screenshot from the keyguard
554 private static final float KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER = 2.5f;
Christopher Tatee90585f2012-03-05 18:56:25 -0800555 private boolean mScreenshotChordEnabled;
Jeff Brown13f00f02014-10-31 14:45:50 -0700556 private boolean mScreenshotChordVolumeDownKeyTriggered;
557 private long mScreenshotChordVolumeDownKeyTime;
558 private boolean mScreenshotChordVolumeDownKeyConsumed;
559 private boolean mScreenshotChordVolumeUpKeyTriggered;
560 private boolean mScreenshotChordPowerKeyTriggered;
561 private long mScreenshotChordPowerKeyTime;
Winson Chung9112ec32011-06-27 13:15:32 -0700562
Michael Wrightb854e242013-02-05 17:54:02 -0800563 /* The number of steps between min and max brightness */
564 private static final int BRIGHTNESS_STEPS = 10;
565
Christopher Tate5e08af02012-09-21 17:17:22 -0700566 SettingsObserver mSettingsObserver;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800567 ShortcutManager mShortcutManager;
568 PowerManager.WakeLock mBroadcastWakeLock;
Jeff Brown13f00f02014-10-31 14:45:50 -0700569 PowerManager.WakeLock mPowerKeyWakeLock;
Jeff Brown40013652012-05-16 21:22:36 -0700570 boolean mHavePendingMediaKeyRepeatWithWakeLock;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800571
Craig Mautnerd625ab22013-09-06 13:40:31 -0700572 private int mCurrentUserId;
573
Justin Kohd378ad72013-04-01 12:18:26 -0700574 // Maps global key codes to the components that will handle them.
575 private GlobalKeyManager mGlobalKeyManager;
576
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700577 // Fallback actions by key code.
578 private final SparseArray<KeyCharacterMap.FallbackAction> mFallbackActions =
579 new SparseArray<KeyCharacterMap.FallbackAction>();
Jeff Brown49ed71d2010-12-06 17:13:33 -0800580
Jorim Jaggi76a16232014-08-08 17:00:47 +0200581 private final LogDecelerateInterpolator mLogDecelerateInterpolator
582 = new LogDecelerateInterpolator(100, 0);
583
Jeff Brown70825162012-03-28 17:27:48 -0700584 private static final int MSG_ENABLE_POINTER_LOCATION = 1;
585 private static final int MSG_DISABLE_POINTER_LOCATION = 2;
Jeff Brown40013652012-05-16 21:22:36 -0700586 private static final int MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK = 3;
587 private static final int MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK = 4;
Craig Mautner8a0da012014-05-31 15:13:37 -0700588 private static final int MSG_KEYGUARD_DRAWN_COMPLETE = 5;
589 private static final int MSG_KEYGUARD_DRAWN_TIMEOUT = 6;
590 private static final int MSG_WINDOW_MANAGER_DRAWN_COMPLETE = 7;
Craig Mautner84984fa2014-06-19 11:19:20 -0700591 private static final int MSG_DISPATCH_SHOW_RECENTS = 9;
Alan Viverettee34560b22014-07-10 14:50:06 -0700592 private static final int MSG_DISPATCH_SHOW_GLOBAL_ACTIONS = 10;
Craig Mautnera631d492014-08-05 15:16:01 -0700593 private static final int MSG_HIDE_BOOT_MESSAGE = 11;
Michael Wright869a67c2014-08-26 19:33:06 -0700594 private static final int MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK = 12;
Jeff Brown13f00f02014-10-31 14:45:50 -0700595 private static final int MSG_POWER_DELAYED_PRESS = 13;
596 private static final int MSG_POWER_LONG_PRESS = 14;
Jeff Brown70825162012-03-28 17:27:48 -0700597
598 private class PolicyHandler extends Handler {
599 @Override
600 public void handleMessage(Message msg) {
601 switch (msg.what) {
602 case MSG_ENABLE_POINTER_LOCATION:
603 enablePointerLocation();
604 break;
605 case MSG_DISABLE_POINTER_LOCATION:
606 disablePointerLocation();
607 break;
Jeff Brown40013652012-05-16 21:22:36 -0700608 case MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK:
609 dispatchMediaKeyWithWakeLock((KeyEvent)msg.obj);
610 break;
611 case MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK:
612 dispatchMediaKeyRepeatWithWakeLock((KeyEvent)msg.obj);
613 break;
Craig Mautner84984fa2014-06-19 11:19:20 -0700614 case MSG_DISPATCH_SHOW_RECENTS:
615 showRecentApps(false);
616 break;
Alan Viverettee34560b22014-07-10 14:50:06 -0700617 case MSG_DISPATCH_SHOW_GLOBAL_ACTIONS:
618 showGlobalActionsInternal();
619 break;
Craig Mautner8a0da012014-05-31 15:13:37 -0700620 case MSG_KEYGUARD_DRAWN_COMPLETE:
621 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mKeyguardDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700622 finishKeyguardDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700623 break;
624 case MSG_KEYGUARD_DRAWN_TIMEOUT:
625 Slog.w(TAG, "Keyguard drawn timeout. Setting mKeyguardDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700626 finishKeyguardDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700627 break;
628 case MSG_WINDOW_MANAGER_DRAWN_COMPLETE:
629 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mWindowManagerDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700630 finishWindowsDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700631 break;
Craig Mautnera631d492014-08-05 15:16:01 -0700632 case MSG_HIDE_BOOT_MESSAGE:
633 handleHideBootMessage();
634 break;
Michael Wright869a67c2014-08-26 19:33:06 -0700635 case MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK:
636 launchVoiceAssistWithWakeLock(msg.arg1 != 0);
637 break;
Jeff Brown13f00f02014-10-31 14:45:50 -0700638 case MSG_POWER_DELAYED_PRESS:
639 powerPress((Long)msg.obj, msg.arg1 != 0, msg.arg2);
640 finishPowerKeyPress();
641 break;
642 case MSG_POWER_LONG_PRESS:
643 powerLongPress();
644 break;
Jeff Brown70825162012-03-28 17:27:48 -0700645 }
646 }
647 }
648
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800649 private UEventObserver mHDMIObserver = new UEventObserver() {
650 @Override
651 public void onUEvent(UEventObserver.UEvent event) {
652 setHdmiPlugged("1".equals(event.get("SWITCH_STATE")));
653 }
654 };
655
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800656 class SettingsObserver extends ContentObserver {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800657 SettingsObserver(Handler handler) {
658 super(handler);
659 }
David Brownbaf8d092010-03-08 21:52:59 -0800660
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800661 void observe() {
Christopher Tate5e08af02012-09-21 17:17:22 -0700662 // Observe all users' changes
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800663 ContentResolver resolver = mContext.getContentResolver();
664 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700665 Settings.System.END_BUTTON_BEHAVIOR), false, this,
666 UserHandle.USER_ALL);
David Brownbaf8d092010-03-08 21:52:59 -0800667 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700668 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR), false, this,
669 UserHandle.USER_ALL);
Jeff Browna20dda42014-05-27 20:57:24 -0700670 resolver.registerContentObserver(Settings.Secure.getUriFor(
671 Settings.Secure.WAKE_GESTURE_ENABLED), false, this,
672 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800673 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700674 Settings.System.ACCELEROMETER_ROTATION), false, this,
675 UserHandle.USER_ALL);
Mike Lockwood28569302010-01-28 11:54:40 -0500676 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700677 Settings.System.USER_ROTATION), false, this,
678 UserHandle.USER_ALL);
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400679 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700680 Settings.System.SCREEN_OFF_TIMEOUT), false, this,
681 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800682 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700683 Settings.System.POINTER_LOCATION), false, this,
684 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800685 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700686 Settings.Secure.DEFAULT_INPUT_METHOD), false, this,
687 UserHandle.USER_ALL);
John Spurlockd9b70bd2014-02-06 17:02:44 -0500688 resolver.registerContentObserver(Settings.Secure.getUriFor(
John Spurlockf1a36642013-10-12 17:50:42 -0400689 Settings.Secure.IMMERSIVE_MODE_CONFIRMATIONS), false, this,
Christopher Tate5e08af02012-09-21 17:17:22 -0700690 UserHandle.USER_ALL);
John Spurlockc6d1c602014-01-17 15:22:06 -0500691 resolver.registerContentObserver(Settings.Global.getUriFor(
692 Settings.Global.POLICY_CONTROL), false, this,
693 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800694 updateSettings();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800695 }
696
697 @Override public void onChange(boolean selfChange) {
Dianne Hackbornc777e072010-02-12 13:07:59 -0800698 updateSettings();
Jeff Brown01a98dd2011-09-20 15:08:29 -0700699 updateRotation(false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800700 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800701 }
Craig Mautner967212c2013-04-13 21:10:58 -0700702
Jeff Browna20dda42014-05-27 20:57:24 -0700703 class MyWakeGestureListener extends WakeGestureListener {
704 MyWakeGestureListener(Context context, Handler handler) {
705 super(context, handler);
706 }
707
708 @Override
709 public void onWakeUp() {
710 synchronized (mLock) {
711 if (shouldEnableWakeGestureLp()) {
Jeff Browne07b94b2014-06-18 15:56:27 -0700712 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
Bryce Lee584a4452014-10-21 15:55:55 -0700713 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromWakeGesture);
Jeff Browna20dda42014-05-27 20:57:24 -0700714 }
715 }
716 }
717 }
718
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800719 class MyOrientationListener extends WindowOrientationListener {
Craig Mautnereee29c42013-01-17 14:44:34 -0800720 MyOrientationListener(Context context, Handler handler) {
721 super(context, handler);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800722 }
Craig Mautner967212c2013-04-13 21:10:58 -0700723
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800724 @Override
Jeff Brownc0347aa2011-09-23 17:26:09 -0700725 public void onProposedRotationChanged(int rotation) {
Craig Mautnereda67292013-04-28 13:50:14 -0700726 if (localLOGV) Slog.v(TAG, "onProposedRotationChanged, rotation=" + rotation);
Jeff Brown01a98dd2011-09-20 15:08:29 -0700727 updateRotation(false);
728 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800729 }
730 MyOrientationListener mOrientationListener;
731
Jorim Jaggi24bec7c2015-02-04 12:40:14 +0100732 private final StatusBarController mStatusBarController = new StatusBarController();
John Spurlock5b9145b2013-08-20 15:13:47 -0400733
John Spurlock27735a42013-08-14 17:57:38 -0400734 private final BarController mNavigationBarController = new BarController("NavigationBar",
John Spurlock5b9145b2013-08-20 15:13:47 -0400735 View.NAVIGATION_BAR_TRANSIENT,
736 View.NAVIGATION_BAR_UNHIDE,
John Spurlockbd957402013-10-03 11:38:39 -0400737 View.NAVIGATION_BAR_TRANSLUCENT,
738 StatusBarManager.WINDOW_NAVIGATION_BAR,
739 WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
John Spurlock5b9145b2013-08-20 15:13:47 -0400740
John Spurlockf1a36642013-10-12 17:50:42 -0400741 private ImmersiveModeConfirmation mImmersiveModeConfirmation;
John Spurlock32beb2c2013-03-11 10:16:47 -0400742
Craig Mautner037aa8d2013-06-07 10:35:44 -0700743 private SystemGesturesPointerEventListener mSystemGestures;
John Spurlock32beb2c2013-03-11 10:16:47 -0400744
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700745 IStatusBarService getStatusBarService() {
746 synchronized (mServiceAquireLock) {
747 if (mStatusBarService == null) {
748 mStatusBarService = IStatusBarService.Stub.asInterface(
749 ServiceManager.getService("statusbar"));
750 }
751 return mStatusBarService;
752 }
753 }
754
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700755 /*
756 * We always let the sensor be switched on by default except when
757 * the user has explicitly disabled sensor based rotation or when the
758 * screen is switched off.
759 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700760 boolean needSensorRunningLp() {
Jeff Brownbcdfc622014-03-06 19:13:04 -0800761 if (mSupportAutoRotation) {
762 if (mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
763 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
764 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT
765 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) {
766 // If the application has explicitly requested to follow the
767 // orientation, then we need to turn the sensor on.
768 return true;
769 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800770 }
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700771 if ((mCarDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_CAR) ||
Jeff Brown1a693182011-11-08 14:44:16 -0800772 (mDeskDockEnablesAccelerometer && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
773 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
774 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK))) {
Mike Lockwoode9867d22009-09-20 01:59:02 -0400775 // enable accelerometer if we are docked in a dock that enables accelerometer
776 // orientation management,
777 return true;
778 }
Jeff Brown207673cd2012-06-05 17:47:11 -0700779 if (mUserRotationMode == USER_ROTATION_LOCKED) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800780 // If the setting for using the sensor by default is enabled, then
781 // we will always leave it on. Note that the user could go to
782 // a window that forces an orientation that does not use the
783 // sensor and in theory we could turn it off... however, when next
784 // turning it on we won't have a good value for the current
785 // orientation for a little bit, which can cause orientation
786 // changes to lag, so we'd like to keep it always on. (It will
787 // still be turned off when the screen is off.)
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700788 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800789 }
Jeff Brownbcdfc622014-03-06 19:13:04 -0800790 return mSupportAutoRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800791 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700792
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800793 /*
794 * Various use cases for invoking this function
795 * screen turning off, should always disable listeners if already enabled
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700796 * screen turned on and current app has sensor based orientation, enable listeners
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800797 * if not already enabled
798 * screen turned on and current app does not have sensor orientation, disable listeners if
799 * already enabled
800 * screen turning on and current app has sensor based orientation, enable listeners if needed
801 * screen turning on and current app has nosensor based orientation, do nothing
802 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700803 void updateOrientationListenerLp() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800804 if (!mOrientationListener.canDetectOrientation()) {
805 // If sensor is turned off or nonexistent for some reason
806 return;
807 }
808 //Could have been invoked due to screen turning on or off or
809 //change of the currently visible window's orientation
Jeff Brown3ee549c2014-09-22 20:14:39 -0700810 if (localLOGV) Slog.v(TAG, "mScreenOnEarly=" + mScreenOnEarly
811 + ", mAwake=" + mAwake + ", mCurrentAppOrientation=" + mCurrentAppOrientation
812 + ", mOrientationSensorEnabled=" + mOrientationSensorEnabled);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800813 boolean disable = true;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700814 if (mScreenOnEarly && mAwake) {
The Android Open Source Project0727d222009-03-11 12:11:58 -0700815 if (needSensorRunningLp()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800816 disable = false;
817 //enable listener if not already enabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700818 if (!mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800819 mOrientationListener.enable();
Craig Mautnereda67292013-04-28 13:50:14 -0700820 if(localLOGV) Slog.v(TAG, "Enabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800821 mOrientationSensorEnabled = true;
822 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700823 }
824 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800825 //check if sensors need to be disabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700826 if (disable && mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800827 mOrientationListener.disable();
Craig Mautnereda67292013-04-28 13:50:14 -0700828 if(localLOGV) Slog.v(TAG, "Disabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800829 mOrientationSensorEnabled = false;
830 }
831 }
832
Jeff Brown13f00f02014-10-31 14:45:50 -0700833 private void interceptPowerKeyDown(KeyEvent event, boolean interactive) {
834 // Hold a wake lock until the power key is released.
835 if (!mPowerKeyWakeLock.isHeld()) {
836 mPowerKeyWakeLock.acquire();
837 }
838
839 // Cancel multi-press detection timeout.
840 if (mPowerKeyPressCounter != 0) {
841 mHandler.removeMessages(MSG_POWER_DELAYED_PRESS);
842 }
843
844 // Detect user pressing the power button in panic when an application has
845 // taken over the whole screen.
846 boolean panic = mImmersiveModeConfirmation.onPowerKeyDown(interactive,
Craig Mautner0124980e92014-11-30 21:15:34 -0800847 SystemClock.elapsedRealtime(), isImmersiveMode(mLastSystemUiFlags));
Jeff Brown13f00f02014-10-31 14:45:50 -0700848 if (panic) {
849 mHandler.post(mRequestTransientNav);
850 }
851
852 // Latch power key state to detect screenshot chord.
853 if (interactive && !mScreenshotChordPowerKeyTriggered
854 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
855 mScreenshotChordPowerKeyTriggered = true;
856 mScreenshotChordPowerKeyTime = event.getDownTime();
857 interceptScreenshotChord();
858 }
859
860 // Stop ringing or end call if configured to do so when power is pressed.
861 TelecomManager telecomManager = getTelecommService();
862 boolean hungUp = false;
863 if (telecomManager != null) {
864 if (telecomManager.isRinging()) {
865 // Pressing Power while there's a ringing incoming
866 // call should silence the ringer.
867 telecomManager.silenceRinger();
868 } else if ((mIncallPowerBehavior
869 & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0
870 && telecomManager.isInCall() && interactive) {
871 // Otherwise, if "Power button ends call" is enabled,
872 // the Power button will hang up any current active call.
873 hungUp = telecomManager.endCall();
874 }
875 }
876
877 // If the power key has still not yet been handled, then detect short
878 // press, long press, or multi press and decide what to do.
879 mPowerKeyHandled = hungUp || mScreenshotChordVolumeDownKeyTriggered
880 || mScreenshotChordVolumeUpKeyTriggered;
881 if (!mPowerKeyHandled) {
882 if (interactive) {
883 // When interactive, we're already awake.
884 // Wait for a long press or for the button to be released to decide what to do.
885 if (hasLongPressOnPowerBehavior()) {
886 Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS);
887 msg.setAsynchronous(true);
888 mHandler.sendMessageDelayed(msg,
889 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
890 }
891 } else {
Bryce Leed9268e32014-11-17 17:40:59 -0800892 wakeUpFromPowerKey(event.getDownTime());
Jeff Brown13f00f02014-10-31 14:45:50 -0700893 final int maxCount = getMaxMultiPressPowerCount();
Bryce Leed9268e32014-11-17 17:40:59 -0800894
Jeff Brown13f00f02014-10-31 14:45:50 -0700895 if (maxCount <= 1) {
Jeff Brown13f00f02014-10-31 14:45:50 -0700896 mPowerKeyHandled = true;
Bryce Leed9268e32014-11-17 17:40:59 -0800897 } else {
898 mBeganFromNonInteractive = true;
Jeff Brown13f00f02014-10-31 14:45:50 -0700899 }
900 }
Jeff Brown4d396052010-10-29 21:50:21 -0700901 }
902 }
903
Jeff Brown13f00f02014-10-31 14:45:50 -0700904 private void interceptPowerKeyUp(KeyEvent event, boolean interactive, boolean canceled) {
905 final boolean handled = canceled || mPowerKeyHandled;
906 mScreenshotChordPowerKeyTriggered = false;
907 cancelPendingScreenshotChordAction();
908 cancelPendingPowerKeyAction();
909
910 if (!handled) {
911 // Figure out how to handle the key now that it has been released.
912 mPowerKeyPressCounter += 1;
913
914 final int maxCount = getMaxMultiPressPowerCount();
915 final long eventTime = event.getDownTime();
916 if (mPowerKeyPressCounter < maxCount) {
917 // This could be a multi-press. Wait a little bit longer to confirm.
918 // Continue holding the wake lock.
919 Message msg = mHandler.obtainMessage(MSG_POWER_DELAYED_PRESS,
920 interactive ? 1 : 0, mPowerKeyPressCounter, eventTime);
921 msg.setAsynchronous(true);
922 mHandler.sendMessageDelayed(msg, ViewConfiguration.getDoubleTapTimeout());
923 return;
924 }
925
926 // No other actions. Handle it immediately.
927 powerPress(eventTime, interactive, mPowerKeyPressCounter);
Jeff Brown4d396052010-10-29 21:50:21 -0700928 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700929
930 // Done. Reset our state.
931 finishPowerKeyPress();
932 }
933
934 private void finishPowerKeyPress() {
Bryce Leed9268e32014-11-17 17:40:59 -0800935 mBeganFromNonInteractive = false;
Jeff Brown13f00f02014-10-31 14:45:50 -0700936 mPowerKeyPressCounter = 0;
937 if (mPowerKeyWakeLock.isHeld()) {
938 mPowerKeyWakeLock.release();
939 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700940 }
941
942 private void cancelPendingPowerKeyAction() {
943 if (!mPowerKeyHandled) {
Jeff Brown13f00f02014-10-31 14:45:50 -0700944 mPowerKeyHandled = true;
945 mHandler.removeMessages(MSG_POWER_LONG_PRESS);
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700946 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700947 }
948
949 private void powerPress(long eventTime, boolean interactive, int count) {
950 if (mScreenOnEarly && !mScreenOnFully) {
951 Slog.i(TAG, "Suppressed redundant power key press while "
952 + "already in the process of turning the screen on.");
953 return;
Jeff Brownff204712011-10-25 21:27:54 -0700954 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700955
956 if (count == 2) {
957 powerMultiPressAction(eventTime, interactive, mDoublePressOnPowerBehavior);
958 } else if (count == 3) {
959 powerMultiPressAction(eventTime, interactive, mTriplePressOnPowerBehavior);
Bryce Leed9268e32014-11-17 17:40:59 -0800960 } else if (interactive && !mBeganFromNonInteractive) {
Jeff Brown13f00f02014-10-31 14:45:50 -0700961 switch (mShortPressOnPowerBehavior) {
962 case SHORT_PRESS_POWER_NOTHING:
963 break;
964 case SHORT_PRESS_POWER_GO_TO_SLEEP:
965 mPowerManager.goToSleep(eventTime,
966 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
967 break;
968 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP:
969 mPowerManager.goToSleep(eventTime,
970 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
971 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
972 break;
973 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME:
974 mPowerManager.goToSleep(eventTime,
975 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
976 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
977 launchHomeFromHotKey();
978 break;
Bryce Lee01b0c5f2015-02-05 18:24:04 -0800979 case SHORT_PRESS_POWER_GO_HOME:
980 launchHomeFromHotKey();
981 break;
Jeff Brown13f00f02014-10-31 14:45:50 -0700982 }
983 }
984 }
985
986 private void powerMultiPressAction(long eventTime, boolean interactive, int behavior) {
987 switch (behavior) {
988 case MULTI_PRESS_POWER_NOTHING:
989 break;
990 case MULTI_PRESS_POWER_THEATER_MODE:
991 if (isTheaterModeEnabled()) {
992 Slog.i(TAG, "Toggling theater mode off.");
993 Settings.Global.putInt(mContext.getContentResolver(),
994 Settings.Global.THEATER_MODE_ON, 0);
995 if (!interactive) {
996 wakeUpFromPowerKey(eventTime);
997 }
998 } else {
999 Slog.i(TAG, "Toggling theater mode on.");
1000 Settings.Global.putInt(mContext.getContentResolver(),
1001 Settings.Global.THEATER_MODE_ON, 1);
Bryce Lee55e846d2014-11-04 12:43:44 -08001002
1003 if (mGoToSleepOnButtonPressTheaterMode && interactive) {
Jeff Brown13f00f02014-10-31 14:45:50 -07001004 mPowerManager.goToSleep(eventTime,
1005 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
1006 }
1007 }
1008 break;
1009 case MULTI_PRESS_POWER_BRIGHTNESS_BOOST:
Jeff Brown7b5be5e2014-11-12 18:45:31 -08001010 Slog.i(TAG, "Starting brightness boost.");
1011 if (!interactive) {
1012 wakeUpFromPowerKey(eventTime);
1013 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001014 mPowerManager.boostScreenBrightness(eventTime);
1015 break;
1016 }
1017 }
1018
1019 private int getMaxMultiPressPowerCount() {
1020 if (mTriplePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) {
1021 return 3;
1022 }
1023 if (mDoublePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) {
1024 return 2;
1025 }
1026 return 1;
1027 }
1028
1029 private void powerLongPress() {
1030 final int behavior = getResolvedLongPressOnPowerBehavior();
1031 switch (behavior) {
1032 case LONG_PRESS_POWER_NOTHING:
1033 break;
1034 case LONG_PRESS_POWER_GLOBAL_ACTIONS:
1035 mPowerKeyHandled = true;
1036 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
1037 performAuditoryFeedbackForAccessibilityIfNeed();
1038 }
1039 showGlobalActionsInternal();
1040 break;
1041 case LONG_PRESS_POWER_SHUT_OFF:
1042 case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM:
1043 mPowerKeyHandled = true;
1044 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
1045 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
1046 mWindowManagerFuncs.shutdown(behavior == LONG_PRESS_POWER_SHUT_OFF);
1047 break;
1048 }
1049 }
1050
1051 private int getResolvedLongPressOnPowerBehavior() {
1052 if (FactoryTest.isLongPressOnPowerOffEnabled()) {
1053 return LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM;
1054 }
1055 return mLongPressOnPowerBehavior;
1056 }
1057
1058 private boolean hasLongPressOnPowerBehavior() {
1059 return getResolvedLongPressOnPowerBehavior() != LONG_PRESS_POWER_NOTHING;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001060 }
1061
1062 private void interceptScreenshotChord() {
Christopher Tatee90585f2012-03-05 18:56:25 -08001063 if (mScreenshotChordEnabled
Jeff Brown13f00f02014-10-31 14:45:50 -07001064 && mScreenshotChordVolumeDownKeyTriggered && mScreenshotChordPowerKeyTriggered
1065 && !mScreenshotChordVolumeUpKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001066 final long now = SystemClock.uptimeMillis();
Jeff Brown13f00f02014-10-31 14:45:50 -07001067 if (now <= mScreenshotChordVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS
1068 && now <= mScreenshotChordPowerKeyTime
1069 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) {
1070 mScreenshotChordVolumeDownKeyConsumed = true;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001071 cancelPendingPowerKeyAction();
1072
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001073 mHandler.postDelayed(mScreenshotRunnable, getScreenshotChordLongPressDelay());
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001074 }
1075 }
1076 }
1077
Winson Chung1cea2f32012-10-08 20:42:01 -07001078 private long getScreenshotChordLongPressDelay() {
Jim Miller5ecd8112013-01-09 18:50:26 -08001079 if (mKeyguardDelegate.isShowing()) {
Winson Chung1cea2f32012-10-08 20:42:01 -07001080 // Double the time it takes to take a screenshot from the keyguard
1081 return (long) (KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER *
Justin Kohfeabd2c2014-05-02 10:02:44 -07001082 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Winson Chung1cea2f32012-10-08 20:42:01 -07001083 }
Justin Kohfeabd2c2014-05-02 10:02:44 -07001084 return ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout();
Winson Chung1cea2f32012-10-08 20:42:01 -07001085 }
1086
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001087 private void cancelPendingScreenshotChordAction() {
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001088 mHandler.removeCallbacks(mScreenshotRunnable);
Jeff Brown4d396052010-10-29 21:50:21 -07001089 }
1090
Jeff Brown13f00f02014-10-31 14:45:50 -07001091 private final Runnable mEndCallLongPress = new Runnable() {
Craig Mautnerf1b67412012-09-19 13:18:29 -07001092 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001093 public void run() {
Jeff Brown13f00f02014-10-31 14:45:50 -07001094 mEndCallKeyHandled = true;
1095 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
1096 performAuditoryFeedbackForAccessibilityIfNeed();
Joe Onoratod208e702010-10-08 16:22:43 -04001097 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001098 showGlobalActionsInternal();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001099 }
1100 };
1101
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001102 private final Runnable mScreenshotRunnable = new Runnable() {
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001103 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001104 public void run() {
1105 takeScreenshot();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001106 }
1107 };
1108
Alan Viverettee34560b22014-07-10 14:50:06 -07001109 @Override
1110 public void showGlobalActions() {
1111 mHandler.removeMessages(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
1112 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
1113 }
1114
1115 void showGlobalActionsInternal() {
1116 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001117 if (mGlobalActions == null) {
Jeff Brown7304c342012-05-11 18:42:42 -07001118 mGlobalActions = new GlobalActions(mContext, mWindowManagerFuncs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001119 }
Jim Millerab954542014-10-10 18:21:49 -07001120 final boolean keyguardShowing = isKeyguardShowingAndNotOccluded();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001121 mGlobalActions.showDialog(keyguardShowing, isDeviceProvisioned());
1122 if (keyguardShowing) {
1123 // since it took two seconds of long press to bring this up,
1124 // poke the wake lock so they have some time to see the dialog.
Jim Miller25190572013-02-28 17:36:24 -08001125 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001126 }
1127 }
1128
1129 boolean isDeviceProvisioned() {
Jeff Brownbf6f6f92012-09-25 15:03:20 -07001130 return Settings.Global.getInt(
1131 mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001132 }
1133
Maurice Lam99c6e072014-04-28 18:24:28 -07001134 boolean isUserSetupComplete() {
1135 return Settings.Secure.getIntForUser(mContext.getContentResolver(),
1136 Settings.Secure.USER_SETUP_COMPLETE, 0, UserHandle.USER_CURRENT) != 0;
1137 }
1138
Jeff Brown13f00f02014-10-31 14:45:50 -07001139 private void handleShortPressOnHome() {
1140 // If there's a dream running then use home to escape the dream
1141 // but don't actually go home.
1142 if (mDreamManagerInternal != null && mDreamManagerInternal.isDreaming()) {
1143 mDreamManagerInternal.stopDream(false /*immediate*/);
1144 return;
1145 }
1146
1147 // Go home!
1148 launchHomeFromHotKey();
1149 }
1150
Patrick Dubroyece94522011-02-23 18:35:01 -08001151 private void handleLongPressOnHome() {
Joe Onorato46b0d682010-11-22 17:37:27 -08001152 if (mLongPressOnHomeBehavior != LONG_PRESS_HOME_NOTHING) {
Jeff Browncaca8812013-05-09 13:34:33 -07001153 mHomeConsumed = true;
Joe Onorato46b0d682010-11-22 17:37:27 -08001154 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
Patrick Dubroyece94522011-02-23 18:35:01 -08001155
Jeff Browncaca8812013-05-09 13:34:33 -07001156 if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI) {
1157 toggleRecentApps();
1158 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_ASSIST) {
1159 launchAssistAction();
Jim Millere6ad1a82010-08-20 19:25:39 -07001160 }
1161 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001162 }
Patrick Dubroyece94522011-02-23 18:35:01 -08001163
Jeff Browncaca8812013-05-09 13:34:33 -07001164 private void handleDoubleTapOnHome() {
1165 if (mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1166 mHomeConsumed = true;
1167 toggleRecentApps();
1168 }
1169 }
1170
1171 private final Runnable mHomeDoubleTapTimeoutRunnable = new Runnable() {
1172 @Override
1173 public void run() {
1174 if (mHomeDoubleTapPending) {
1175 mHomeDoubleTapPending = false;
Jeff Brown13f00f02014-10-31 14:45:50 -07001176 handleShortPressOnHome();
Jeff Browncaca8812013-05-09 13:34:33 -07001177 }
1178 }
1179 };
1180
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001181 /** {@inheritDoc} */
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001182 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001183 public void init(Context context, IWindowManager windowManager,
Jeff Brown96307042012-07-27 15:51:34 -07001184 WindowManagerFuncs windowManagerFuncs) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001185 mContext = context;
1186 mWindowManager = windowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -07001187 mWindowManagerFuncs = windowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -07001188 mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class);
Jose Lima9546b202014-07-02 17:21:51 -07001189 mDreamManagerInternal = LocalServices.getService(DreamManagerInternal.class);
Filip Gruszczynskicfb31852015-02-25 21:47:12 +00001190 if (context.getResources().getBoolean(
1191 com.android.internal.R.bool.config_enableBurnInProtection)){
1192 mBurnInProtectionHelper = new BurnInProtectionHelper(context);
1193 }
Craig Mautner8a0da012014-05-31 15:13:37 -07001194
Jeff Brown70825162012-03-28 17:27:48 -07001195 mHandler = new PolicyHandler();
Jeff Browna20dda42014-05-27 20:57:24 -07001196 mWakeGestureListener = new MyWakeGestureListener(mContext, mHandler);
Craig Mautnereee29c42013-01-17 14:44:34 -08001197 mOrientationListener = new MyOrientationListener(mContext, mHandler);
Jeff Brownc0347aa2011-09-23 17:26:09 -07001198 try {
1199 mOrientationListener.setCurrentRotation(windowManager.getRotation());
1200 } catch (RemoteException ex) { }
Christopher Tate5e08af02012-09-21 17:17:22 -07001201 mSettingsObserver = new SettingsObserver(mHandler);
1202 mSettingsObserver.observe();
Svetoslav683914b2015-01-15 14:22:26 -08001203 mShortcutManager = new ShortcutManager(context);
Daniel Sandler6396c722013-04-16 20:19:09 -04001204 mUiMode = context.getResources().getInteger(
1205 com.android.internal.R.integer.config_defaultUiModeType);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001206 mHomeIntent = new Intent(Intent.ACTION_MAIN, null);
1207 mHomeIntent.addCategory(Intent.CATEGORY_HOME);
1208 mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1209 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07001210 mCarDockIntent = new Intent(Intent.ACTION_MAIN, null);
1211 mCarDockIntent.addCategory(Intent.CATEGORY_CAR_DOCK);
1212 mCarDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1213 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
1214 mDeskDockIntent = new Intent(Intent.ACTION_MAIN, null);
1215 mDeskDockIntent.addCategory(Intent.CATEGORY_DESK_DOCK);
1216 mDeskDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1217 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Jim Millere6ad1a82010-08-20 19:25:39 -07001218
Jeff Brown96307042012-07-27 15:51:34 -07001219 mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
1220 mBroadcastWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001221 "PhoneWindowManager.mBroadcastWakeLock");
Jeff Brown13f00f02014-10-31 14:45:50 -07001222 mPowerKeyWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
1223 "PhoneWindowManager.mPowerKeyWakeLock");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001224 mEnableShiftMenuBugReports = "1".equals(SystemProperties.get("ro.debuggable"));
Jeff Brownbcdfc622014-03-06 19:13:04 -08001225 mSupportAutoRotation = mContext.getResources().getBoolean(
1226 com.android.internal.R.bool.config_supportAutoRotation);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001227 mLidOpenRotation = readRotation(
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001228 com.android.internal.R.integer.config_lidOpenRotation);
1229 mCarDockRotation = readRotation(
1230 com.android.internal.R.integer.config_carDockRotation);
1231 mDeskDockRotation = readRotation(
1232 com.android.internal.R.integer.config_deskDockRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001233 mUndockedHdmiRotation = readRotation(
1234 com.android.internal.R.integer.config_undockedHdmiRotation);
Mike Lockwoode9867d22009-09-20 01:59:02 -04001235 mCarDockEnablesAccelerometer = mContext.getResources().getBoolean(
1236 com.android.internal.R.bool.config_carDockEnablesAccelerometer);
1237 mDeskDockEnablesAccelerometer = mContext.getResources().getBoolean(
1238 com.android.internal.R.bool.config_deskDockEnablesAccelerometer);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001239 mLidKeyboardAccessibility = mContext.getResources().getInteger(
1240 com.android.internal.R.integer.config_lidKeyboardAccessibility);
1241 mLidNavigationAccessibility = mContext.getResources().getInteger(
1242 com.android.internal.R.integer.config_lidNavigationAccessibility);
Jeff Brownc458ce92012-04-30 14:58:40 -07001243 mLidControlsSleep = mContext.getResources().getBoolean(
1244 com.android.internal.R.bool.config_lidControlsSleep);
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04001245 mTranslucentDecorEnabled = mContext.getResources().getBoolean(
1246 com.android.internal.R.bool.config_enableTranslucentDecor);
Bryce Lee584a4452014-10-21 15:55:55 -07001247
1248 mAllowTheaterModeWakeFromKey = mContext.getResources().getBoolean(
1249 com.android.internal.R.bool.config_allowTheaterModeWakeFromKey);
1250 mAllowTheaterModeWakeFromPowerKey = mAllowTheaterModeWakeFromKey
1251 || mContext.getResources().getBoolean(
1252 com.android.internal.R.bool.config_allowTheaterModeWakeFromPowerKey);
1253 mAllowTheaterModeWakeFromMotion = mContext.getResources().getBoolean(
1254 com.android.internal.R.bool.config_allowTheaterModeWakeFromMotion);
Bryce Lee812d7022014-11-10 13:33:28 -08001255 mAllowTheaterModeWakeFromMotionWhenNotDreaming = mContext.getResources().getBoolean(
1256 com.android.internal.R.bool.config_allowTheaterModeWakeFromMotionWhenNotDreaming);
Bryce Lee584a4452014-10-21 15:55:55 -07001257 mAllowTheaterModeWakeFromCameraLens = mContext.getResources().getBoolean(
1258 com.android.internal.R.bool.config_allowTheaterModeWakeFromCameraLens);
1259 mAllowTheaterModeWakeFromLidSwitch = mContext.getResources().getBoolean(
1260 com.android.internal.R.bool.config_allowTheaterModeWakeFromLidSwitch);
1261 mAllowTheaterModeWakeFromWakeGesture = mContext.getResources().getBoolean(
1262 com.android.internal.R.bool.config_allowTheaterModeWakeFromGesture);
1263
Bryce Lee55e846d2014-11-04 12:43:44 -08001264 mGoToSleepOnButtonPressTheaterMode = mContext.getResources().getBoolean(
1265 com.android.internal.R.bool.config_goToSleepOnButtonPressTheaterMode);
1266
Jeff Brown13f00f02014-10-31 14:45:50 -07001267 mShortPressOnPowerBehavior = mContext.getResources().getInteger(
1268 com.android.internal.R.integer.config_shortPressOnPowerBehavior);
1269 mLongPressOnPowerBehavior = mContext.getResources().getInteger(
1270 com.android.internal.R.integer.config_longPressOnPowerBehavior);
1271 mDoublePressOnPowerBehavior = mContext.getResources().getInteger(
1272 com.android.internal.R.integer.config_doublePressOnPowerBehavior);
1273 mTriplePressOnPowerBehavior = mContext.getResources().getInteger(
1274 com.android.internal.R.integer.config_triplePressOnPowerBehavior);
1275
John Spurlock61560172015-02-06 19:46:04 -05001276 mUseTvRouting = AudioSystem.getPlatformType(mContext) == AudioSystem.PLATFORM_TELEVISION;
RoboErik001c59c2015-01-26 15:53:51 -08001277 mUseMasterVolume = mContext.getResources().getBoolean(
1278 com.android.internal.R.bool.config_useMasterVolume);
1279
Jeff Brownf71343d2013-05-31 17:59:11 -07001280 readConfigurationDependentBehaviors();
Jeff Browncaca8812013-05-09 13:34:33 -07001281
Svetoslav8e3feb12014-02-24 13:46:47 -08001282 mAccessibilityManager = (AccessibilityManager) context.getSystemService(
1283 Context.ACCESSIBILITY_SERVICE);
1284
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001285 // register for dock events
Dianne Hackborn78968392010-03-04 20:47:56 -08001286 IntentFilter filter = new IntentFilter();
1287 filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE);
1288 filter.addAction(UiModeManager.ACTION_EXIT_CAR_MODE);
1289 filter.addAction(UiModeManager.ACTION_ENTER_DESK_MODE);
1290 filter.addAction(UiModeManager.ACTION_EXIT_DESK_MODE);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001291 filter.addAction(Intent.ACTION_DOCK_EVENT);
1292 Intent intent = context.registerReceiver(mDockReceiver, filter);
1293 if (intent != null) {
1294 // Retrieve current sticky dock event broadcast.
1295 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
1296 Intent.EXTRA_DOCK_STATE_UNDOCKED);
1297 }
Daniel Sandler7e37df52011-11-16 22:08:23 -08001298
Jeff Brown6aaf2952012-10-05 16:01:08 -07001299 // register for dream-related broadcasts
1300 filter = new IntentFilter();
1301 filter.addAction(Intent.ACTION_DREAMING_STARTED);
1302 filter.addAction(Intent.ACTION_DREAMING_STOPPED);
1303 context.registerReceiver(mDreamReceiver, filter);
1304
Christopher Tate5e08af02012-09-21 17:17:22 -07001305 // register for multiuser-relevant broadcasts
1306 filter = new IntentFilter(Intent.ACTION_USER_SWITCHED);
1307 context.registerReceiver(mMultiuserReceiver, filter);
1308
John Spurlock57306e62013-04-22 09:48:49 -04001309 // monitor for system gestures
Craig Mautner037aa8d2013-06-07 10:35:44 -07001310 mSystemGestures = new SystemGesturesPointerEventListener(context,
1311 new SystemGesturesPointerEventListener.Callbacks() {
John Spurlock57306e62013-04-22 09:48:49 -04001312 @Override
1313 public void onSwipeFromTop() {
John Spurlock04db1762013-05-13 12:46:41 -04001314 if (mStatusBar != null) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001315 requestTransientBars(mStatusBar);
John Spurlock04db1762013-05-13 12:46:41 -04001316 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04001317 }
1318 @Override
1319 public void onSwipeFromBottom() {
John Spurlock04db1762013-05-13 12:46:41 -04001320 if (mNavigationBar != null && mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001321 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001322 }
1323 }
1324 @Override
1325 public void onSwipeFromRight() {
John Spurlock04db1762013-05-13 12:46:41 -04001326 if (mNavigationBar != null && !mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001327 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001328 }
1329 }
1330 @Override
1331 public void onDebug() {
John Spurlockd67ec252013-09-05 11:31:54 -04001332 // no-op
John Spurlockad3e6cb2013-04-30 08:47:43 -04001333 }
1334 });
John Spurlockf1a36642013-10-12 17:50:42 -04001335 mImmersiveModeConfirmation = new ImmersiveModeConfirmation(mContext);
Craig Mautner037aa8d2013-06-07 10:35:44 -07001336 mWindowManagerFuncs.registerPointerEventListener(mSystemGestures);
John Spurlock32beb2c2013-03-11 10:16:47 -04001337
Jeff Brownc2346132012-04-13 01:55:38 -07001338 mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001339 mLongPressVibePattern = getLongIntArray(mContext.getResources(),
1340 com.android.internal.R.array.config_longPressVibePattern);
1341 mVirtualKeyVibePattern = getLongIntArray(mContext.getResources(),
1342 com.android.internal.R.array.config_virtualKeyVibePattern);
Amith Yamasanic33cb712010-02-10 15:21:49 -08001343 mKeyboardTapVibePattern = getLongIntArray(mContext.getResources(),
1344 com.android.internal.R.array.config_keyboardTapVibePattern);
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07001345 mClockTickVibePattern = getLongIntArray(mContext.getResources(),
1346 com.android.internal.R.array.config_clockTickVibePattern);
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07001347 mCalendarDateVibePattern = getLongIntArray(mContext.getResources(),
1348 com.android.internal.R.array.config_calendarDateVibePattern);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001349 mSafeModeDisabledVibePattern = getLongIntArray(mContext.getResources(),
1350 com.android.internal.R.array.config_safeModeDisabledVibePattern);
1351 mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(),
1352 com.android.internal.R.array.config_safeModeEnabledVibePattern);
Daniel Sandler40427442010-07-16 11:44:52 -04001353
Christopher Tatee90585f2012-03-05 18:56:25 -08001354 mScreenshotChordEnabled = mContext.getResources().getBoolean(
1355 com.android.internal.R.bool.config_enableScreenshotChord);
1356
Justin Kohd378ad72013-04-01 12:18:26 -07001357 mGlobalKeyManager = new GlobalKeyManager(mContext);
1358
Joe Onoratoea495d42011-04-06 11:41:11 -07001359 // Controls rotation and the like.
1360 initializeHdmiState();
Dianne Hackborn40011092011-09-22 13:37:48 -07001361
1362 // Match current screen state.
Craig Mautnera631d492014-08-05 15:16:01 -07001363 if (!mPowerManager.isInteractive()) {
Jeff Brown140ffc72014-05-01 15:18:00 -07001364 goingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
Dianne Hackborn40011092011-09-22 13:37:48 -07001365 }
Jorim Jaggi24bec7c2015-02-04 12:40:14 +01001366
1367 mWindowManagerInternal.registerAppTransitionListener(
1368 mStatusBarController.getAppTransitionListener());
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001369 }
1370
Jeff Brownf71343d2013-05-31 17:59:11 -07001371 /**
1372 * Read values from config.xml that may be overridden depending on
1373 * the configuration of the device.
1374 * eg. Disable long press on home goes to recents on sw600dp.
1375 */
1376 private void readConfigurationDependentBehaviors() {
1377 mLongPressOnHomeBehavior = mContext.getResources().getInteger(
1378 com.android.internal.R.integer.config_longPressOnHomeBehavior);
1379 if (mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING ||
1380 mLongPressOnHomeBehavior > LONG_PRESS_HOME_ASSIST) {
1381 mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1382 }
1383
1384 mDoubleTapOnHomeBehavior = mContext.getResources().getInteger(
1385 com.android.internal.R.integer.config_doubleTapOnHomeBehavior);
1386 if (mDoubleTapOnHomeBehavior < DOUBLE_TAP_HOME_NOTHING ||
1387 mDoubleTapOnHomeBehavior > DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1388 mDoubleTapOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1389 }
1390 }
1391
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001392 @Override
Dianne Hackborndde331c2012-08-03 14:01:57 -07001393 public void setInitialDisplaySize(Display display, int width, int height, int density) {
Jeff Brownef981a42013-08-07 14:13:37 -07001394 // This method might be called before the policy has been fully initialized
1395 // or for other displays we don't care about.
1396 if (mContext == null || display.getDisplayId() != Display.DEFAULT_DISPLAY) {
1397 return;
Dianne Hackbornc652de82013-02-15 16:32:56 -08001398 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001399 mDisplay = display;
1400
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001401 final Resources res = mContext.getResources();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001402 int shortSize, longSize;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001403 if (width > height) {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001404 shortSize = height;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001405 longSize = width;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001406 mLandscapeRotation = Surface.ROTATION_0;
1407 mSeascapeRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001408 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001409 mPortraitRotation = Surface.ROTATION_90;
1410 mUpsideDownRotation = Surface.ROTATION_270;
1411 } else {
1412 mPortraitRotation = Surface.ROTATION_270;
1413 mUpsideDownRotation = Surface.ROTATION_90;
1414 }
1415 } else {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001416 shortSize = width;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001417 longSize = height;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001418 mPortraitRotation = Surface.ROTATION_0;
1419 mUpsideDownRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001420 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001421 mLandscapeRotation = Surface.ROTATION_270;
1422 mSeascapeRotation = Surface.ROTATION_90;
1423 } else {
1424 mLandscapeRotation = Surface.ROTATION_90;
1425 mSeascapeRotation = Surface.ROTATION_270;
1426 }
1427 }
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001428
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001429 mStatusBarHeight =
1430 res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001431
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001432 // Height of the navigation bar when presented horizontally at bottom
1433 mNavigationBarHeightForRotation[mPortraitRotation] =
1434 mNavigationBarHeightForRotation[mUpsideDownRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001435 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_height);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001436 mNavigationBarHeightForRotation[mLandscapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001437 mNavigationBarHeightForRotation[mSeascapeRotation] = res.getDimensionPixelSize(
1438 com.android.internal.R.dimen.navigation_bar_height_landscape);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001439
1440 // Width of the navigation bar when presented vertically along one side
1441 mNavigationBarWidthForRotation[mPortraitRotation] =
1442 mNavigationBarWidthForRotation[mUpsideDownRotation] =
1443 mNavigationBarWidthForRotation[mLandscapeRotation] =
1444 mNavigationBarWidthForRotation[mSeascapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001445 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_width);
Daniel Sandler4a066c52012-04-20 14:49:13 -04001446
1447 // SystemUI (status bar) layout policy
Dianne Hackborndde331c2012-08-03 14:01:57 -07001448 int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / density;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001449 int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / density;
Daniel Sandler4a066c52012-04-20 14:49:13 -04001450
Devin Kimd7b12b42014-05-05 14:34:58 -07001451 // Allow the navigation bar to move on non-square small devices (phones).
1452 mNavigationBarCanMove = width != height && shortSizeDp < 600;
Daniel Sandler36412a72011-08-04 09:35:13 -04001453
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001454 mHasNavigationBar = res.getBoolean(com.android.internal.R.bool.config_showNavigationBar);
John Spurlock80f00c12013-06-13 11:10:51 -04001455 // Allow a system property to override this. Used by the emulator.
1456 // See also hasNavigationBar().
1457 String navBarOverride = SystemProperties.get("qemu.hw.mainkeys");
1458 if ("1".equals(navBarOverride)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001459 mHasNavigationBar = false;
John Spurlock80f00c12013-06-13 11:10:51 -04001460 } else if ("0".equals(navBarOverride)) {
1461 mHasNavigationBar = true;
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04001462 }
1463
Jeff Brown27f1d672012-10-17 18:32:34 -07001464 // For demo purposes, allow the rotation of the HDMI display to be controlled.
1465 // By default, HDMI locks rotation to landscape.
Erik Gilling9a41ef82011-09-26 19:21:03 -07001466 if ("portrait".equals(SystemProperties.get("persist.demo.hdmirotation"))) {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001467 mDemoHdmiRotation = mPortraitRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001468 } else {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001469 mDemoHdmiRotation = mLandscapeRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001470 }
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001471 mDemoHdmiRotationLock = SystemProperties.getBoolean("persist.demo.hdmirotationlock", false);
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001472
Chong Zhangae6119ff2014-11-11 18:54:39 -08001473 // For demo purposes, allow the rotation of the remote display to be controlled.
1474 // By default, remote display locks rotation to landscape.
1475 if ("portrait".equals(SystemProperties.get("persist.demo.remoterotation"))) {
1476 mDemoRotation = mPortraitRotation;
1477 } else {
1478 mDemoRotation = mLandscapeRotation;
1479 }
1480 mDemoRotationLock = SystemProperties.getBoolean(
1481 "persist.demo.rotationlock", false);
1482
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001483 // Only force the default orientation if the screen is xlarge, at least 960dp x 720dp, per
1484 // http://developer.android.com/guide/practices/screens_support.html#range
1485 mForceDefaultOrientation = longSizeDp >= 960 && shortSizeDp >= 720 &&
1486 res.getBoolean(com.android.internal.R.bool.config_forceDefaultOrientation) &&
1487 // For debug purposes the next line turns this feature off with:
1488 // $ adb shell setprop config.override_forced_orient true
1489 // $ adb shell wm size reset
1490 !"true".equals(SystemProperties.get("config.override_forced_orient"));
1491 }
1492
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001493 /**
1494 * @return whether the navigation bar can be hidden, e.g. the device has a
1495 * navigation bar and touch exploration is not enabled
1496 */
1497 private boolean canHideNavigationBar() {
Svetoslav8e3feb12014-02-24 13:46:47 -08001498 return mHasNavigationBar
1499 && !mAccessibilityManager.isTouchExplorationEnabled();
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001500 }
1501
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001502 @Override
1503 public boolean isDefaultOrientationForced() {
1504 return mForceDefaultOrientation;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001505 }
1506
Dianne Hackbornc652de82013-02-15 16:32:56 -08001507 @Override
1508 public void setDisplayOverscan(Display display, int left, int top, int right, int bottom) {
1509 if (display.getDisplayId() == Display.DEFAULT_DISPLAY) {
1510 mOverscanLeft = left;
1511 mOverscanTop = top;
1512 mOverscanRight = right;
1513 mOverscanBottom = bottom;
1514 }
1515 }
1516
Dianne Hackbornc777e072010-02-12 13:07:59 -08001517 public void updateSettings() {
1518 ContentResolver resolver = mContext.getContentResolver();
1519 boolean updateRotation = false;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001520 synchronized (mLock) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001521 mEndcallBehavior = Settings.System.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001522 Settings.System.END_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001523 Settings.System.END_BUTTON_BEHAVIOR_DEFAULT,
1524 UserHandle.USER_CURRENT);
1525 mIncallPowerBehavior = Settings.Secure.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001526 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001527 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT,
1528 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001529
Jeff Browna20dda42014-05-27 20:57:24 -07001530 // Configure wake gesture.
1531 boolean wakeGestureEnabledSetting = Settings.Secure.getIntForUser(resolver,
1532 Settings.Secure.WAKE_GESTURE_ENABLED, 0,
1533 UserHandle.USER_CURRENT) != 0;
1534 if (mWakeGestureEnabledSetting != wakeGestureEnabledSetting) {
1535 mWakeGestureEnabledSetting = wakeGestureEnabledSetting;
1536 updateWakeGestureListenerLp();
1537 }
1538
Jeff Brown207673cd2012-06-05 17:47:11 -07001539 // Configure rotation lock.
Christopher Tate5e08af02012-09-21 17:17:22 -07001540 int userRotation = Settings.System.getIntForUser(resolver,
1541 Settings.System.USER_ROTATION, Surface.ROTATION_0,
1542 UserHandle.USER_CURRENT);
Jeff Brown207673cd2012-06-05 17:47:11 -07001543 if (mUserRotation != userRotation) {
1544 mUserRotation = userRotation;
1545 updateRotation = true;
1546 }
Christopher Tate5e08af02012-09-21 17:17:22 -07001547 int userRotationMode = Settings.System.getIntForUser(resolver,
1548 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
Jeff Brown207673cd2012-06-05 17:47:11 -07001549 WindowManagerPolicy.USER_ROTATION_FREE :
1550 WindowManagerPolicy.USER_ROTATION_LOCKED;
1551 if (mUserRotationMode != userRotationMode) {
1552 mUserRotationMode = userRotationMode;
1553 updateRotation = true;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001554 updateOrientationListenerLp();
1555 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001556
Dianne Hackbornc777e072010-02-12 13:07:59 -08001557 if (mSystemReady) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001558 int pointerLocation = Settings.System.getIntForUser(resolver,
1559 Settings.System.POINTER_LOCATION, 0, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001560 if (mPointerLocationMode != pointerLocation) {
1561 mPointerLocationMode = pointerLocation;
Jeff Brown70825162012-03-28 17:27:48 -07001562 mHandler.sendEmptyMessage(pointerLocation != 0 ?
1563 MSG_ENABLE_POINTER_LOCATION : MSG_DISABLE_POINTER_LOCATION);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001564 }
1565 }
1566 // use screen off timeout setting as the timeout for the lockscreen
Christopher Tate5e08af02012-09-21 17:17:22 -07001567 mLockScreenTimeout = Settings.System.getIntForUser(resolver,
1568 Settings.System.SCREEN_OFF_TIMEOUT, 0, UserHandle.USER_CURRENT);
1569 String imId = Settings.Secure.getStringForUser(resolver,
1570 Settings.Secure.DEFAULT_INPUT_METHOD, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001571 boolean hasSoftInput = imId != null && imId.length() > 0;
1572 if (mHasSoftInput != hasSoftInput) {
1573 mHasSoftInput = hasSoftInput;
1574 updateRotation = true;
1575 }
John Spurlockf1a36642013-10-12 17:50:42 -04001576 if (mImmersiveModeConfirmation != null) {
John Spurlock4355a532014-02-19 09:49:25 -05001577 mImmersiveModeConfirmation.loadSetting(mCurrentUserId);
John Spurlockd67ec252013-09-05 11:31:54 -04001578 }
John Spurlockc6d1c602014-01-17 15:22:06 -05001579 PolicyControl.reloadFromSetting(mContext);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001580 }
1581 if (updateRotation) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07001582 updateRotation(true);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001583 }
Jeff Brown70825162012-03-28 17:27:48 -07001584 }
1585
Jeff Browna20dda42014-05-27 20:57:24 -07001586 private void updateWakeGestureListenerLp() {
1587 if (shouldEnableWakeGestureLp()) {
1588 mWakeGestureListener.requestWakeUpTrigger();
1589 } else {
1590 mWakeGestureListener.cancelWakeUpTrigger();
1591 }
1592 }
1593
1594 private boolean shouldEnableWakeGestureLp() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07001595 return mWakeGestureEnabledSetting && !mAwake
Jeff Browna20dda42014-05-27 20:57:24 -07001596 && (!mLidControlsSleep || mLidState != LID_CLOSED)
1597 && mWakeGestureListener.isSupported();
1598 }
1599
Jeff Brown70825162012-03-28 17:27:48 -07001600 private void enablePointerLocation() {
1601 if (mPointerLocationView == null) {
1602 mPointerLocationView = new PointerLocationView(mContext);
1603 mPointerLocationView.setPrintCoords(false);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001604 WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
1605 WindowManager.LayoutParams.MATCH_PARENT,
1606 WindowManager.LayoutParams.MATCH_PARENT);
Jeff Brown3b2b3542010-10-15 00:54:27 -07001607 lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001608 lp.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN
1609 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
1610 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1611 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
Jeff Brown90fc9052012-10-01 14:44:24 -07001612 if (ActivityManager.isHighEndGfx()) {
1613 lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
1614 lp.privateFlags |=
1615 WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED;
1616 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001617 lp.format = PixelFormat.TRANSLUCENT;
1618 lp.setTitle("PointerLocation");
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001619 WindowManager wm = (WindowManager)
Dianne Hackbornc777e072010-02-12 13:07:59 -08001620 mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Browncc4f7db2011-08-30 20:34:48 -07001621 lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL;
Jeff Brown70825162012-03-28 17:27:48 -07001622 wm.addView(mPointerLocationView, lp);
Michael Wrightc9c487e2013-11-07 18:55:09 -08001623 mWindowManagerFuncs.registerPointerEventListener(mPointerLocationView);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001624 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001625 }
Jeff Brown70825162012-03-28 17:27:48 -07001626
1627 private void disablePointerLocation() {
Jeff Brown70825162012-03-28 17:27:48 -07001628 if (mPointerLocationView != null) {
Michael Wrightc9c487e2013-11-07 18:55:09 -08001629 mWindowManagerFuncs.unregisterPointerEventListener(mPointerLocationView);
1630 WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Brown70825162012-03-28 17:27:48 -07001631 wm.removeView(mPointerLocationView);
1632 mPointerLocationView = null;
1633 }
1634 }
1635
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001636 private int readRotation(int resID) {
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001637 try {
1638 int rotation = mContext.getResources().getInteger(resID);
1639 switch (rotation) {
1640 case 0:
1641 return Surface.ROTATION_0;
1642 case 90:
1643 return Surface.ROTATION_90;
1644 case 180:
1645 return Surface.ROTATION_180;
1646 case 270:
1647 return Surface.ROTATION_270;
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001648 }
1649 } catch (Resources.NotFoundException e) {
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001650 // fall through
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001651 }
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001652 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001653 }
1654
1655 /** {@inheritDoc} */
Craig Mautner88400d32012-09-30 12:35:45 -07001656 @Override
Dianne Hackbornc2293022013-02-06 23:14:49 -08001657 public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001658 int type = attrs.type;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001659
1660 outAppOp[0] = AppOpsManager.OP_NONE;
1661
Wale Ogunwale74bf0652015-01-12 10:24:36 -08001662 if (!((type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW)
1663 || (type >= FIRST_SUB_WINDOW && type <= LAST_SUB_WINDOW)
1664 || (type >= FIRST_SYSTEM_WINDOW && type <= LAST_SYSTEM_WINDOW))) {
1665 return WindowManagerGlobal.ADD_INVALID_TYPE;
1666 }
1667
1668 if (type < FIRST_SYSTEM_WINDOW || type > LAST_SYSTEM_WINDOW) {
1669 // Window manager will make sure these are okay.
Jeff Brown98365d72012-08-19 20:30:52 -07001670 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001671 }
1672 String permission = null;
1673 switch (type) {
1674 case TYPE_TOAST:
1675 // XXX right now the app process has complete control over
1676 // this... should introduce a token to let the system
1677 // monitor/control what they are doing.
Jason Monk1c7c3192014-06-26 12:52:18 -04001678 outAppOp[0] = AppOpsManager.OP_TOAST_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001679 break;
Daniel Sandler7d276c32012-01-30 14:33:52 -05001680 case TYPE_DREAM:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001681 case TYPE_INPUT_METHOD:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001682 case TYPE_WALLPAPER:
keunyounga446bf02013-06-21 19:07:57 -07001683 case TYPE_PRIVATE_PRESENTATION:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001684 case TYPE_VOICE_INTERACTION:
Svetoslav3a5c7212014-10-14 09:54:26 -07001685 case TYPE_ACCESSIBILITY_OVERLAY:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001686 // The window manager will check these.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001687 break;
1688 case TYPE_PHONE:
1689 case TYPE_PRIORITY_PHONE:
1690 case TYPE_SYSTEM_ALERT:
1691 case TYPE_SYSTEM_ERROR:
1692 case TYPE_SYSTEM_OVERLAY:
1693 permission = android.Manifest.permission.SYSTEM_ALERT_WINDOW;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001694 outAppOp[0] = AppOpsManager.OP_SYSTEM_ALERT_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001695 break;
1696 default:
1697 permission = android.Manifest.permission.INTERNAL_SYSTEM_WINDOW;
1698 }
1699 if (permission != null) {
1700 if (mContext.checkCallingOrSelfPermission(permission)
1701 != PackageManager.PERMISSION_GRANTED) {
Jeff Brown98365d72012-08-19 20:30:52 -07001702 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001703 }
1704 }
Jeff Brown98365d72012-08-19 20:30:52 -07001705 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001706 }
Craig Mautner88400d32012-09-30 12:35:45 -07001707
1708 @Override
1709 public boolean checkShowToOwnerOnly(WindowManager.LayoutParams attrs) {
1710
1711 // If this switch statement is modified, modify the comment in the declarations of
1712 // the type in {@link WindowManager.LayoutParams} as well.
1713 switch (attrs.type) {
1714 default:
1715 // These are the windows that by default are shown only to the user that created
1716 // them. If this needs to be overridden, set
1717 // {@link WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS} in
1718 // {@link WindowManager.LayoutParams}. Note that permission
1719 // {@link android.Manifest.permission.INTERNAL_SYSTEM_WINDOW} is required as well.
1720 if ((attrs.privateFlags & PRIVATE_FLAG_SHOW_FOR_ALL_USERS) == 0) {
1721 return true;
1722 }
1723 break;
1724
1725 // These are the windows that by default are shown to all users. However, to
1726 // protect against spoofing, check permissions below.
1727 case TYPE_APPLICATION_STARTING:
1728 case TYPE_BOOT_PROGRESS:
1729 case TYPE_DISPLAY_OVERLAY:
1730 case TYPE_HIDDEN_NAV_CONSUMER:
Jim Miller5ecd8112013-01-09 18:50:26 -08001731 case TYPE_KEYGUARD_SCRIM:
Craig Mautner88400d32012-09-30 12:35:45 -07001732 case TYPE_KEYGUARD_DIALOG:
1733 case TYPE_MAGNIFICATION_OVERLAY:
1734 case TYPE_NAVIGATION_BAR:
1735 case TYPE_NAVIGATION_BAR_PANEL:
1736 case TYPE_PHONE:
1737 case TYPE_POINTER:
1738 case TYPE_PRIORITY_PHONE:
Craig Mautner88400d32012-09-30 12:35:45 -07001739 case TYPE_SEARCH_BAR:
1740 case TYPE_STATUS_BAR:
1741 case TYPE_STATUS_BAR_PANEL:
1742 case TYPE_STATUS_BAR_SUB_PANEL:
1743 case TYPE_SYSTEM_DIALOG:
Craig Mautner88400d32012-09-30 12:35:45 -07001744 case TYPE_VOLUME_OVERLAY:
keunyounga446bf02013-06-21 19:07:57 -07001745 case TYPE_PRIVATE_PRESENTATION:
Craig Mautner88400d32012-09-30 12:35:45 -07001746 break;
1747 }
1748
1749 // Check if third party app has set window to system window type.
1750 return mContext.checkCallingOrSelfPermission(
1751 android.Manifest.permission.INTERNAL_SYSTEM_WINDOW)
1752 != PackageManager.PERMISSION_GRANTED;
1753 }
1754
Craig Mautner967212c2013-04-13 21:10:58 -07001755 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001756 public void adjustWindowParamsLw(WindowManager.LayoutParams attrs) {
1757 switch (attrs.type) {
1758 case TYPE_SYSTEM_OVERLAY:
Jeff Brown3b2b3542010-10-15 00:54:27 -07001759 case TYPE_SECURE_SYSTEM_OVERLAY:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001760 // These types of windows can't receive input events.
1761 attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1762 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001763 attrs.flags &= ~WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001764 break;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001765 case TYPE_STATUS_BAR:
1766
1767 // If the Keyguard is in a hidden state (occluded by another window), we force to
1768 // remove the wallpaper and keyguard flag so that any change in-flight after setting
1769 // the keyguard as occluded wouldn't set these flags again.
1770 // See {@link #processKeyguardSetHiddenResultLw}.
1771 if (mKeyguardHidden) {
1772 attrs.flags &= ~WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
1773 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
1774 }
1775 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001776 }
Adrian Roos38502112014-04-09 21:04:11 +02001777
1778 if (attrs.type != TYPE_STATUS_BAR) {
1779 // The status bar is the only window allowed to exhibit keyguard behavior.
1780 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
1781 }
Adrian Roosea562512014-05-05 13:33:03 +02001782
1783 if (ActivityManager.isHighEndGfx()
1784 && (attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0) {
Adrian Roosf5e9b5c2014-09-10 15:27:41 +02001785 attrs.subtreeSystemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
Adrian Roosea562512014-05-05 13:33:03 +02001786 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
1787 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001788 }
RoboErik8a2cfc32014-05-16 11:19:38 -07001789
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001790 void readLidState() {
Jeff Brown2e7760e2012-04-11 15:14:55 -07001791 mLidState = mWindowManagerFuncs.getLidState();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001792 }
RoboErik8a2cfc32014-05-16 11:19:38 -07001793
Michael Wright3818c922014-09-02 13:59:07 -07001794 private void readCameraLensCoverState() {
1795 mCameraLensCoverState = mWindowManagerFuncs.getCameraLensCoverState();
1796 }
1797
Jeff Browndaa37532012-05-01 15:54:03 -07001798 private boolean isHidden(int accessibilityMode) {
1799 switch (accessibilityMode) {
1800 case 1:
1801 return mLidState == LID_CLOSED;
1802 case 2:
1803 return mLidState == LID_OPEN;
1804 default:
1805 return false;
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001806 }
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001807 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001808
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001809 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07001810 @Override
Jeff Browndaa37532012-05-01 15:54:03 -07001811 public void adjustConfigurationLw(Configuration config, int keyboardPresence,
1812 int navigationPresence) {
1813 mHaveBuiltInKeyboard = (keyboardPresence & PRESENCE_INTERNAL) != 0;
1814
Jeff Brownf71343d2013-05-31 17:59:11 -07001815 readConfigurationDependentBehaviors();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001816 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07001817 applyLidSwitchState();
Jeff Brownd04a88c2011-01-16 14:05:47 -08001818
Jeff Browndaa37532012-05-01 15:54:03 -07001819 if (config.keyboard == Configuration.KEYBOARD_NOKEYS
1820 || (keyboardPresence == PRESENCE_INTERNAL
1821 && isHidden(mLidKeyboardAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001822 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_YES;
Jeff Browndaa37532012-05-01 15:54:03 -07001823 if (!mHasSoftInput) {
1824 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_YES;
1825 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001826 }
1827
Jeff Browndaa37532012-05-01 15:54:03 -07001828 if (config.navigation == Configuration.NAVIGATION_NONAV
1829 || (navigationPresence == PRESENCE_INTERNAL
1830 && isHidden(mLidNavigationAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001831 config.navigationHidden = Configuration.NAVIGATIONHIDDEN_YES;
Jeff Brownd04a88c2011-01-16 14:05:47 -08001832 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001833 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001834
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001835 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07001836 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001837 public int windowTypeToLayerLw(int type) {
1838 if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001839 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001840 }
1841 switch (type) {
keunyounga446bf02013-06-21 19:07:57 -07001842 case TYPE_PRIVATE_PRESENTATION:
1843 return 2;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001844 case TYPE_WALLPAPER:
1845 // wallpaper is at the bottom, though the window manager may move it.
1846 return 2;
1847 case TYPE_PHONE:
1848 return 3;
1849 case TYPE_SEARCH_BAR:
1850 return 4;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001851 case TYPE_VOICE_INTERACTION:
1852 // voice interaction layer is almost immediately above apps.
1853 return 5;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001854 case TYPE_SYSTEM_DIALOG:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001855 return 6;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001856 case TYPE_TOAST:
1857 // toasts and the plugged-in battery thing
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001858 return 7;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001859 case TYPE_PRIORITY_PHONE:
1860 // SIM errors and unlock. Not sure if this really should be in a high layer.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001861 return 8;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001862 case TYPE_DREAM:
1863 // used for Dreams (screensavers with TYPE_DREAM windows)
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001864 return 9;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001865 case TYPE_SYSTEM_ALERT:
1866 // like the ANR / app crashed dialogs
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001867 return 10;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001868 case TYPE_INPUT_METHOD:
1869 // on-screen keyboards and other such input method user interfaces go here.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001870 return 11;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001871 case TYPE_INPUT_METHOD_DIALOG:
1872 // on-screen keyboards and other such input method user interfaces go here.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001873 return 12;
Jim Miller5ecd8112013-01-09 18:50:26 -08001874 case TYPE_KEYGUARD_SCRIM:
1875 // the safety window that shows behind keyguard while keyguard is starting
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001876 return 13;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001877 case TYPE_STATUS_BAR_SUB_PANEL:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001878 return 14;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001879 case TYPE_STATUS_BAR:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001880 return 15;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001881 case TYPE_STATUS_BAR_PANEL:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001882 return 16;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001883 case TYPE_KEYGUARD_DIALOG:
1884 return 17;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001885 case TYPE_VOLUME_OVERLAY:
1886 // the on-screen volume indicator and controller shown when the user
1887 // changes the device volume
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001888 return 18;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001889 case TYPE_SYSTEM_OVERLAY:
1890 // the on-screen volume indicator and controller shown when the user
1891 // changes the device volume
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001892 return 19;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001893 case TYPE_NAVIGATION_BAR:
1894 // the navigation bar, if available, shows atop most things
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001895 return 20;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001896 case TYPE_NAVIGATION_BAR_PANEL:
1897 // some panels (e.g. search) need to show on top of the navigation bar
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001898 return 21;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001899 case TYPE_SYSTEM_ERROR:
1900 // system-level error dialogs
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001901 return 22;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001902 case TYPE_MAGNIFICATION_OVERLAY:
1903 // used to highlight the magnified portion of a display
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001904 return 23;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001905 case TYPE_DISPLAY_OVERLAY:
1906 // used to simulate secondary display devices
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001907 return 24;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001908 case TYPE_DRAG:
1909 // the drag layer: input for drag-and-drop is associated with this window,
1910 // which sits above all other focusable windows
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001911 return 25;
Svetoslav3a5c7212014-10-14 09:54:26 -07001912 case TYPE_ACCESSIBILITY_OVERLAY:
1913 // overlay put by accessibility services to intercept user interaction
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001914 return 26;
Svetoslav3a5c7212014-10-14 09:54:26 -07001915 case TYPE_SECURE_SYSTEM_OVERLAY:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001916 return 27;
Svetoslav3a5c7212014-10-14 09:54:26 -07001917 case TYPE_BOOT_PROGRESS:
1918 return 28;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001919 case TYPE_POINTER:
1920 // the (mouse) pointer layer
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001921 return 29;
Svetoslav3a5c7212014-10-14 09:54:26 -07001922 case TYPE_HIDDEN_NAV_CONSUMER:
1923 return 30;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001924 }
1925 Log.e(TAG, "Unknown window type: " + type);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001926 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001927 }
1928
1929 /** {@inheritDoc} */
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001930 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001931 public int subWindowTypeToLayerLw(int type) {
1932 switch (type) {
1933 case TYPE_APPLICATION_PANEL:
1934 case TYPE_APPLICATION_ATTACHED_DIALOG:
1935 return APPLICATION_PANEL_SUBLAYER;
1936 case TYPE_APPLICATION_MEDIA:
1937 return APPLICATION_MEDIA_SUBLAYER;
Dianne Hackborn5cb8d792009-05-21 17:34:15 -07001938 case TYPE_APPLICATION_MEDIA_OVERLAY:
1939 return APPLICATION_MEDIA_OVERLAY_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001940 case TYPE_APPLICATION_SUB_PANEL:
1941 return APPLICATION_SUB_PANEL_SUBLAYER;
1942 }
1943 Log.e(TAG, "Unknown sub-window type: " + type);
1944 return 0;
1945 }
1946
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001947 @Override
Dianne Hackbornabe0da02009-09-18 01:55:39 -07001948 public int getMaxWallpaperLayer() {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001949 return windowTypeToLayerLw(TYPE_STATUS_BAR);
Dianne Hackbornabe0da02009-09-18 01:55:39 -07001950 }
1951
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001952 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001953 public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07001954 if (mHasNavigationBar) {
1955 // For a basic navigation bar, when we are in landscape mode we place
1956 // the navigation bar to the side.
Daniel Sandler4a066c52012-04-20 14:49:13 -04001957 if (mNavigationBarCanMove && fullWidth > fullHeight) {
1958 return fullWidth - mNavigationBarWidthForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07001959 }
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001960 }
1961 return fullWidth;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001962 }
1963
Jose Lima9546b202014-07-02 17:21:51 -07001964 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001965 public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07001966 if (mHasNavigationBar) {
1967 // For a basic navigation bar, when we are in portrait mode we place
1968 // the navigation bar to the bottom.
Daniel Sandler4a066c52012-04-20 14:49:13 -04001969 if (!mNavigationBarCanMove || fullWidth < fullHeight) {
1970 return fullHeight - mNavigationBarHeightForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07001971 }
1972 }
1973 return fullHeight;
Dianne Hackborn69cb8752011-05-19 18:13:32 -07001974 }
1975
Jose Lima9546b202014-07-02 17:21:51 -07001976 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001977 public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation) {
1978 return getNonDecorDisplayWidth(fullWidth, fullHeight, rotation);
Dianne Hackborn69cb8752011-05-19 18:13:32 -07001979 }
1980
Jose Lima9546b202014-07-02 17:21:51 -07001981 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001982 public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation) {
John Spurlock80f00c12013-06-13 11:10:51 -04001983 // There is a separate status bar at the top of the display. We don't count that as part
1984 // of the fixed decor, since it can hide; however, for purposes of configurations,
Dianne Hackborn077ee852012-04-09 16:27:07 -07001985 // we do want to exclude it since applications can't generally use that part
1986 // of the screen.
John Spurlock80f00c12013-06-13 11:10:51 -04001987 return getNonDecorDisplayHeight(fullWidth, fullHeight, rotation) - mStatusBarHeight;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001988 }
1989
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001990 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07001991 public boolean isForceHiding(WindowManager.LayoutParams attrs) {
1992 return (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 ||
Jim Millerab954542014-10-10 18:21:49 -07001993 (isKeyguardHostWindow(attrs) &&
1994 (mKeyguardDelegate != null && mKeyguardDelegate.isShowing())) ||
Adrian Roos69e510d2014-07-13 14:57:59 +02001995 (attrs.type == TYPE_KEYGUARD_SCRIM);
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07001996 }
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001997
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001998 @Override
Jorim Jaggi0d674622014-05-21 01:34:15 +02001999 public boolean isKeyguardHostWindow(WindowManager.LayoutParams attrs) {
2000 return attrs.type == TYPE_STATUS_BAR;
2001 }
2002
2003 @Override
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002004 public boolean canBeForceHidden(WindowState win, WindowManager.LayoutParams attrs) {
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002005 switch (attrs.type) {
2006 case TYPE_STATUS_BAR:
2007 case TYPE_NAVIGATION_BAR:
2008 case TYPE_WALLPAPER:
2009 case TYPE_DREAM:
Jim Miller5ecd8112013-01-09 18:50:26 -08002010 case TYPE_KEYGUARD_SCRIM:
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002011 return false;
2012 default:
2013 return true;
2014 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002015 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002016
Craig Mautner7d7808f2014-09-11 18:02:38 -07002017 @Override
2018 public WindowState getWinShowWhenLockedLw() {
2019 return mWinShowWhenLocked;
2020 }
2021
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002022 /** {@inheritDoc} */
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002023 @Override
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07002024 public View addStartingWindow(IBinder appToken, String packageName, int theme,
2025 CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes,
Adam Powell04fe6eb2013-05-31 14:39:48 -07002026 int icon, int logo, int windowFlags) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002027 if (!SHOW_STARTING_ANIMATIONS) {
2028 return null;
2029 }
2030 if (packageName == null) {
2031 return null;
2032 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002033
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002034 WindowManager wm = null;
2035 View view = null;
2036
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002037 try {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002038 Context context = mContext;
Craig Mautner6fbda632012-07-03 09:26:39 -07002039 if (DEBUG_STARTING_WINDOW) Slog.d(TAG, "addStartingWindow " + packageName
2040 + ": nonLocalizedLabel=" + nonLocalizedLabel + " theme="
2041 + Integer.toHexString(theme));
Dianne Hackborn247fe742011-01-08 17:25:57 -08002042 if (theme != context.getThemeResId() || labelRes != 0) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002043 try {
2044 context = context.createPackageContext(packageName, 0);
Dianne Hackborn247fe742011-01-08 17:25:57 -08002045 context.setTheme(theme);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002046 } catch (PackageManager.NameNotFoundException e) {
2047 // Ignore
2048 }
2049 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002050
Jorim Jaggib10e33f2015-02-04 21:57:40 +01002051 Window win = new PhoneWindow(context);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002052 final TypedArray ta = win.getWindowStyle();
2053 if (ta.getBoolean(
2054 com.android.internal.R.styleable.Window_windowDisablePreview, false)
2055 || ta.getBoolean(
2056 com.android.internal.R.styleable.Window_windowShowWallpaper,false)) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002057 return null;
2058 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002059
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002060 Resources r = context.getResources();
2061 win.setTitle(r.getText(labelRes, nonLocalizedLabel));
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002062
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002063 win.setType(
2064 WindowManager.LayoutParams.TYPE_APPLICATION_STARTING);
2065 // Force the window flags: this is a fake window, so it is not really
2066 // touchable or focusable by the user. We also add in the ALT_FOCUSABLE_IM
2067 // flag because we do know that the next window will take input
2068 // focus, so we want to get the IME window up on top of us right away.
2069 win.setFlags(
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08002070 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002071 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
2072 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
2073 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08002074 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002075 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
2076 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
2077 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002078
Adam Powell04fe6eb2013-05-31 14:39:48 -07002079 win.setDefaultIcon(icon);
2080 win.setDefaultLogo(logo);
2081
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002082 win.setLayout(WindowManager.LayoutParams.MATCH_PARENT,
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07002083 WindowManager.LayoutParams.MATCH_PARENT);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002084
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002085 final WindowManager.LayoutParams params = win.getAttributes();
2086 params.token = appToken;
2087 params.packageName = packageName;
2088 params.windowAnimations = win.getWindowStyle().getResourceId(
2089 com.android.internal.R.styleable.Window_windowAnimationStyle, 0);
John Reck61375a82014-09-18 19:27:48 +00002090 params.privateFlags |=
2091 WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED;
Craig Mautner88400d32012-09-30 12:35:45 -07002092 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
Adam Lesinski95c42972013-10-02 10:13:27 -07002093
2094 if (!compatInfo.supportsScreen()) {
2095 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
2096 }
2097
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002098 params.setTitle("Starting " + packageName);
2099
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002100 wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
2101 view = win.getDecorView();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002102
2103 if (win.isFloating()) {
2104 // Whoops, there is no way to display an animation/preview
2105 // of such a thing! After all that work... let's skip it.
2106 // (Note that we must do this here because it is in
2107 // getDecorView() where the theme is evaluated... maybe
2108 // we should peek the floating attribute from the theme
2109 // earlier.)
2110 return null;
2111 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002112
Craig Mautner6fbda632012-07-03 09:26:39 -07002113 if (DEBUG_STARTING_WINDOW) Slog.d(
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002114 TAG, "Adding starting window for " + packageName
2115 + " / " + appToken + ": "
2116 + (view.getParent() != null ? view : null));
2117
2118 wm.addView(view, params);
2119
2120 // Only return the view if it was successfully added to the
2121 // window manager... which we can tell by it having a parent.
2122 return view.getParent() != null ? view : null;
Jeff Brown98365d72012-08-19 20:30:52 -07002123 } catch (WindowManager.BadTokenException e) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002124 // ignore
Craig Mautner42bf39e2014-02-21 16:46:22 -08002125 Log.w(TAG, appToken + " already running, starting window not displayed. " +
2126 e.getMessage());
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002127 } catch (RuntimeException e) {
2128 // don't crash if something else bad happens, for example a
2129 // failure loading resources because we are loading from an app
2130 // on external storage that has been unmounted.
2131 Log.w(TAG, appToken + " failed creating starting window", e);
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002132 } finally {
2133 if (view != null && view.getParent() == null) {
2134 Log.w(TAG, "view not successfully added to wm, removing view");
2135 wm.removeViewImmediate(view);
2136 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002137 }
2138
2139 return null;
2140 }
2141
2142 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07002143 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002144 public void removeStartingWindow(IBinder appToken, View window) {
Craig Mautner276a6eb2014-11-04 15:32:57 -08002145 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Removing starting window for " + appToken + ": "
2146 + window + " Callers=" + Debug.getCallers(4));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002147
2148 if (window != null) {
Dianne Hackborn5fd21692011-06-07 14:09:47 -07002149 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002150 wm.removeView(window);
2151 }
2152 }
2153
2154 /**
2155 * Preflight adding a window to the system.
RoboErik8a2cfc32014-05-16 11:19:38 -07002156 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002157 * Currently enforces that three window types are singletons:
2158 * <ul>
2159 * <li>STATUS_BAR_TYPE</li>
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002160 * <li>KEYGUARD_TYPE</li>
2161 * </ul>
RoboErik8a2cfc32014-05-16 11:19:38 -07002162 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002163 * @param win The window to be added
2164 * @param attrs Information about the window to be added
RoboErik8a2cfc32014-05-16 11:19:38 -07002165 *
Jeff Brown98365d72012-08-19 20:30:52 -07002166 * @return If ok, WindowManagerImpl.ADD_OKAY. If too many singletons,
2167 * WindowManagerImpl.ADD_MULTIPLE_SINGLETON
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002168 */
Jose Lima9546b202014-07-02 17:21:51 -07002169 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002170 public int prepareAddWindowLw(WindowState win, WindowManager.LayoutParams attrs) {
2171 switch (attrs.type) {
2172 case TYPE_STATUS_BAR:
Joe Onorato8bc6c512010-06-04 16:21:12 -04002173 mContext.enforceCallingOrSelfPermission(
2174 android.Manifest.permission.STATUS_BAR_SERVICE,
2175 "PhoneWindowManager");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002176 if (mStatusBar != null) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002177 if (mStatusBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07002178 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002179 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002180 }
2181 mStatusBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04002182 mStatusBarController.setWindow(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002183 break;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002184 case TYPE_NAVIGATION_BAR:
2185 mContext.enforceCallingOrSelfPermission(
2186 android.Manifest.permission.STATUS_BAR_SERVICE,
2187 "PhoneWindowManager");
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002188 if (mNavigationBar != null) {
2189 if (mNavigationBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07002190 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002191 }
2192 }
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002193 mNavigationBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04002194 mNavigationBarController.setWindow(win);
Craig Mautnereda67292013-04-28 13:50:14 -07002195 if (DEBUG_LAYOUT) Slog.i(TAG, "NAVIGATION BAR: " + mNavigationBar);
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002196 break;
Jim Millere898ac52012-04-06 17:10:57 -07002197 case TYPE_NAVIGATION_BAR_PANEL:
2198 mContext.enforceCallingOrSelfPermission(
2199 android.Manifest.permission.STATUS_BAR_SERVICE,
2200 "PhoneWindowManager");
2201 break;
Dianne Hackborn08743722009-12-21 12:16:51 -08002202 case TYPE_STATUS_BAR_PANEL:
Joe Onorato8bc6c512010-06-04 16:21:12 -04002203 mContext.enforceCallingOrSelfPermission(
2204 android.Manifest.permission.STATUS_BAR_SERVICE,
2205 "PhoneWindowManager");
Dianne Hackborn08743722009-12-21 12:16:51 -08002206 break;
Joe Onorato29fc2c92010-11-24 10:26:50 -08002207 case TYPE_STATUS_BAR_SUB_PANEL:
2208 mContext.enforceCallingOrSelfPermission(
2209 android.Manifest.permission.STATUS_BAR_SERVICE,
2210 "PhoneWindowManager");
Joe Onorato29fc2c92010-11-24 10:26:50 -08002211 break;
Jim Miller5ecd8112013-01-09 18:50:26 -08002212 case TYPE_KEYGUARD_SCRIM:
Jim Miller25190572013-02-28 17:36:24 -08002213 if (mKeyguardScrim != null) {
2214 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
2215 }
Jim Miller5ecd8112013-01-09 18:50:26 -08002216 mKeyguardScrim = win;
2217 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002218 }
Jeff Brown98365d72012-08-19 20:30:52 -07002219 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002220 }
2221
2222 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07002223 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002224 public void removeWindowLw(WindowState win) {
2225 if (mStatusBar == win) {
2226 mStatusBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04002227 mStatusBarController.setWindow(null);
Jim Millerc0b676d2013-03-22 16:11:08 -07002228 mKeyguardDelegate.showScrim();
Jim Miller5ecd8112013-01-09 18:50:26 -08002229 } else if (mKeyguardScrim == win) {
2230 Log.v(TAG, "Removing keyguard scrim");
2231 mKeyguardScrim = null;
2232 } if (mNavigationBar == win) {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002233 mNavigationBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04002234 mNavigationBarController.setWindow(null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002235 }
2236 }
2237
2238 static final boolean PRINT_ANIM = false;
RoboErik8a2cfc32014-05-16 11:19:38 -07002239
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002240 /** {@inheritDoc} */
Craig Mautner4b71aa12012-12-27 17:20:01 -08002241 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002242 public int selectAnimationLw(WindowState win, int transit) {
2243 if (PRINT_ANIM) Log.i(TAG, "selectAnimation in " + win
2244 + ": transit=" + transit);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002245 if (win == mStatusBar) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002246 boolean isKeyguard = (win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002247 if (transit == TRANSIT_EXIT
2248 || transit == TRANSIT_HIDE) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002249 return isKeyguard ? -1 : R.anim.dock_top_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002250 } else if (transit == TRANSIT_ENTER
2251 || transit == TRANSIT_SHOW) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002252 return isKeyguard ? -1 : R.anim.dock_top_enter;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002253 }
2254 } else if (win == mNavigationBar) {
2255 // This can be on either the bottom or the right.
2256 if (mNavigationBarOnBottom) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08002257 if (transit == TRANSIT_EXIT
2258 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002259 return R.anim.dock_bottom_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002260 } else if (transit == TRANSIT_ENTER
2261 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002262 return R.anim.dock_bottom_enter;
2263 }
2264 } else {
Craig Mautner4b71aa12012-12-27 17:20:01 -08002265 if (transit == TRANSIT_EXIT
2266 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002267 return R.anim.dock_right_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002268 } else if (transit == TRANSIT_ENTER
2269 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002270 return R.anim.dock_right_enter;
2271 }
2272 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08002273 }
2274
2275 if (transit == TRANSIT_PREVIEW_DONE) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002276 if (win.hasAppShownWindows()) {
2277 if (PRINT_ANIM) Log.i(TAG, "**** STARTING EXIT");
2278 return com.android.internal.R.anim.app_starting_exit;
2279 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07002280 } else if (win.getAttrs().type == TYPE_DREAM && mDreamingLockscreen
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002281 && transit == TRANSIT_ENTER) {
2282 // Special case: we are animating in a dream, while the keyguard
2283 // is shown. We don't want an animation on the dream, because
2284 // we need it shown immediately with the keyguard animating away
2285 // to reveal it.
2286 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002287 }
2288
2289 return 0;
2290 }
2291
Craig Mautner3c174372013-02-21 17:54:37 -08002292 @Override
2293 public void selectRotationAnimationLw(int anim[]) {
2294 if (PRINT_ANIM) Slog.i(TAG, "selectRotationAnimation mTopFullscreen="
2295 + mTopFullscreenOpaqueWindowState + " rotationAnimation="
2296 + (mTopFullscreenOpaqueWindowState == null ?
2297 "0" : mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation));
2298 if (mTopFullscreenOpaqueWindowState != null && mTopIsFullscreen) {
2299 switch (mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation) {
2300 case ROTATION_ANIMATION_CROSSFADE:
2301 anim[0] = R.anim.rotation_animation_xfade_exit;
2302 anim[1] = R.anim.rotation_animation_enter;
2303 break;
2304 case ROTATION_ANIMATION_JUMPCUT:
2305 anim[0] = R.anim.rotation_animation_jump_exit;
2306 anim[1] = R.anim.rotation_animation_enter;
2307 break;
2308 case ROTATION_ANIMATION_ROTATE:
2309 default:
2310 anim[0] = anim[1] = 0;
2311 break;
2312 }
2313 } else {
2314 anim[0] = anim[1] = 0;
2315 }
2316 }
2317
2318 @Override
2319 public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId,
2320 boolean forceDefault) {
2321 switch (exitAnimId) {
2322 case R.anim.rotation_animation_xfade_exit:
2323 case R.anim.rotation_animation_jump_exit:
2324 // These are the only cases that matter.
2325 if (forceDefault) {
2326 return false;
2327 }
2328 int anim[] = new int[2];
2329 selectRotationAnimationLw(anim);
2330 return (exitAnimId == anim[0] && enterAnimId == anim[1]);
2331 default:
2332 return true;
2333 }
2334 }
2335
2336 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002337 public Animation createForceHideEnterAnimation(boolean onWallpaper,
2338 boolean goingToNotificationShade) {
2339 if (goingToNotificationShade) {
2340 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_behind_enter_fade_in);
Craig Mautnerb8340802014-11-04 15:32:57 -08002341 }
Craig Mautner276a6eb2014-11-04 15:32:57 -08002342
2343 AnimationSet set = (AnimationSet) AnimationUtils.loadAnimation(mContext, onWallpaper ?
2344 R.anim.lock_screen_behind_enter_wallpaper :
2345 R.anim.lock_screen_behind_enter);
2346
2347 // TODO: Use XML interpolators when we have log interpolators available in XML.
2348 final List<Animation> animations = set.getAnimations();
2349 for (int i = animations.size() - 1; i >= 0; --i) {
2350 animations.get(i).setInterpolator(mLogDecelerateInterpolator);
2351 }
2352
2353 return set;
Jorim Jaggi76a16232014-08-08 17:00:47 +02002354 }
2355
2356
2357 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002358 public Animation createForceHideWallpaperExitAnimation(boolean goingToNotificationShade) {
2359 if (goingToNotificationShade) {
2360 return null;
2361 } else {
2362 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_wallpaper_exit);
2363 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002364 }
John Spurlockc8b46ca2013-04-08 12:59:26 -04002365
2366 private static void awakenDreams() {
2367 IDreamManager dreamManager = getDreamManager();
2368 if (dreamManager != null) {
2369 try {
2370 dreamManager.awaken();
2371 } catch (RemoteException e) {
2372 // fine, stay asleep then
2373 }
2374 }
2375 }
2376
2377 static IDreamManager getDreamManager() {
2378 return IDreamManager.Stub.asInterface(
2379 ServiceManager.checkService(DreamService.DREAM_SERVICE));
2380 }
2381
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002382 TelecomManager getTelecommService() {
2383 return (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002384 }
2385
Jeff Brown4d396052010-10-29 21:50:21 -07002386 static IAudioService getAudioService() {
2387 IAudioService audioService = IAudioService.Stub.asInterface(
2388 ServiceManager.checkService(Context.AUDIO_SERVICE));
2389 if (audioService == null) {
2390 Log.w(TAG, "Unable to find IAudioService interface.");
2391 }
2392 return audioService;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002393 }
2394
2395 boolean keyguardOn() {
Jim Millerab954542014-10-10 18:21:49 -07002396 return isKeyguardShowingAndNotOccluded() || inKeyguardRestrictedKeyInputMode();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002397 }
2398
2399 private static final int[] WINDOW_TYPES_WHERE_HOME_DOESNT_WORK = {
2400 WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
2401 WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
2402 };
2403
2404 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002405 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002406 public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002407 final boolean keyguardOn = keyguardOn();
Jeff Brown1f245102010-11-18 20:53:46 -08002408 final int keyCode = event.getKeyCode();
2409 final int repeatCount = event.getRepeatCount();
2410 final int metaState = event.getMetaState();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002411 final int flags = event.getFlags();
Jeff Brown1f245102010-11-18 20:53:46 -08002412 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
2413 final boolean canceled = event.isCanceled();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002414
Jeff Brown40013652012-05-16 21:22:36 -07002415 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002416 Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount="
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002417 + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed
2418 + " canceled=" + canceled);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002419 }
2420
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002421 // If we think we might have a volume down & power key chord on the way
2422 // but we're not sure, then tell the dispatcher to wait a little while and
2423 // try again later before dispatching.
Christopher Tatee90585f2012-03-05 18:56:25 -08002424 if (mScreenshotChordEnabled && (flags & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07002425 if (mScreenshotChordVolumeDownKeyTriggered && !mScreenshotChordPowerKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002426 final long now = SystemClock.uptimeMillis();
Jeff Brown13f00f02014-10-31 14:45:50 -07002427 final long timeoutTime = mScreenshotChordVolumeDownKeyTime
2428 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002429 if (now < timeoutTime) {
2430 return timeoutTime - now;
2431 }
2432 }
2433 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
Jeff Brown13f00f02014-10-31 14:45:50 -07002434 && mScreenshotChordVolumeDownKeyConsumed) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002435 if (!down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07002436 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002437 }
2438 return -1;
2439 }
2440 }
2441
Michael Wright6a62e552014-06-03 19:19:48 -07002442 // Cancel any pending meta actions if we see any other keys being pressed between the down
2443 // of the meta key and its corresponding up.
Michael Wright251e35d2014-08-22 15:40:27 -07002444 if (mPendingMetaAction && !KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07002445 mPendingMetaAction = false;
2446 }
2447
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002448 // First we always handle the home key here, so applications
2449 // can never break it, although if keyguard is on, we do let
2450 // it handle it, because that gives us the correct 5 second
2451 // timeout.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002452 if (keyCode == KeyEvent.KEYCODE_HOME) {
Michael Jurka7f2668c2012-03-27 07:49:52 -07002453
Jeff Brown49ed71d2010-12-06 17:13:33 -08002454 // If we have released the home key, and didn't do anything else
2455 // while it was pressed, then it is time to go home!
Michael Jurka7f2668c2012-03-27 07:49:52 -07002456 if (!down) {
Jeff Browncaca8812013-05-09 13:34:33 -07002457 cancelPreloadRecentApps();
2458
Jeff Brown49ed71d2010-12-06 17:13:33 -08002459 mHomePressed = false;
Jeff Browncaca8812013-05-09 13:34:33 -07002460 if (mHomeConsumed) {
2461 mHomeConsumed = false;
Michael Jurka7f2668c2012-03-27 07:49:52 -07002462 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002463 }
Jeff Browncaca8812013-05-09 13:34:33 -07002464
2465 if (canceled) {
2466 Log.i(TAG, "Ignoring HOME; event canceled.");
2467 return -1;
2468 }
2469
Yorke Lee4f803242014-12-15 23:22:06 +00002470 // If an incoming call is ringing, HOME is totally disabled.
2471 // (The user is already on the InCallUI at this point,
2472 // and his ONLY options are to answer or reject the call.)
2473 TelecomManager telecomManager = getTelecommService();
2474 if (telecomManager != null && telecomManager.isRinging()) {
2475 Log.i(TAG, "Ignoring HOME; there's a ringing incoming call.");
2476 return -1;
2477 }
2478
Jeff Browncaca8812013-05-09 13:34:33 -07002479 // Delay handling home if a double-tap is possible.
2480 if (mDoubleTapOnHomeBehavior != DOUBLE_TAP_HOME_NOTHING) {
2481 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); // just in case
2482 mHomeDoubleTapPending = true;
2483 mHandler.postDelayed(mHomeDoubleTapTimeoutRunnable,
2484 ViewConfiguration.getDoubleTapTimeout());
2485 return -1;
2486 }
2487
Jeff Brown13f00f02014-10-31 14:45:50 -07002488 handleShortPressOnHome();
Jeff Browncaca8812013-05-09 13:34:33 -07002489 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002490 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002491
2492 // If a system window has focus, then it doesn't make sense
2493 // right now to interact with applications.
2494 WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null;
2495 if (attrs != null) {
2496 final int type = attrs.type;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002497 if (type == WindowManager.LayoutParams.TYPE_KEYGUARD_SCRIM
2498 || type == WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG
2499 || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002500 // the "app" is keyguard, so give it the key
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002501 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002502 }
2503 final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length;
2504 for (int i=0; i<typeCount; i++) {
2505 if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) {
2506 // don't do anything, but also don't pass it to the app
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002507 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002508 }
2509 }
2510 }
Jeff Browncaca8812013-05-09 13:34:33 -07002511
2512 // Remember that home is pressed and handle special actions.
2513 if (repeatCount == 0) {
2514 mHomePressed = true;
2515 if (mHomeDoubleTapPending) {
2516 mHomeDoubleTapPending = false;
2517 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable);
2518 handleDoubleTapOnHome();
2519 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI
2520 || mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
2521 preloadRecentApps();
Michael Jurka7f2668c2012-03-27 07:49:52 -07002522 }
Jeff Browncaca8812013-05-09 13:34:33 -07002523 } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) {
2524 if (!keyguardOn) {
2525 handleLongPressOnHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002526 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002527 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002528 return -1;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002529 } else if (keyCode == KeyEvent.KEYCODE_MENU) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002530 // Hijack modified menu keys for debugging features
2531 final int chordBug = KeyEvent.META_SHIFT_ON;
2532
2533 if (down && repeatCount == 0) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002534 if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002535 Intent intent = new Intent(Intent.ACTION_BUG_REPORT);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002536 mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT,
2537 null, null, null, 0, null, null);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002538 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002539 } else if (SHOW_PROCESSES_ON_ALT_MENU &&
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002540 (metaState & KeyEvent.META_ALT_ON) == KeyEvent.META_ALT_ON) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002541 Intent service = new Intent();
2542 service.setClassName(mContext, "com.android.server.LoadAverageService");
2543 ContentResolver res = mContext.getContentResolver();
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002544 boolean shown = Settings.Global.getInt(
2545 res, Settings.Global.SHOW_PROCESSES, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002546 if (!shown) {
2547 mContext.startService(service);
2548 } else {
2549 mContext.stopService(service);
2550 }
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002551 Settings.Global.putInt(
2552 res, Settings.Global.SHOW_PROCESSES, shown ? 0 : 1);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002553 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002554 }
2555 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002556 } else if (keyCode == KeyEvent.KEYCODE_SEARCH) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002557 if (down) {
2558 if (repeatCount == 0) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002559 mSearchKeyShortcutPending = true;
2560 mConsumeSearchKeyUp = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002561 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002562 } else {
2563 mSearchKeyShortcutPending = false;
2564 if (mConsumeSearchKeyUp) {
2565 mConsumeSearchKeyUp = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002566 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002567 }
2568 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002569 return 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002570 } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) {
Michael Wrightc9ebea72013-01-16 19:25:02 -08002571 if (!keyguardOn) {
Jeff Browncaca8812013-05-09 13:34:33 -07002572 if (down && repeatCount == 0) {
2573 preloadRecentApps();
2574 } else if (!down) {
2575 toggleRecentApps();
Michael Wrightc9ebea72013-01-16 19:25:02 -08002576 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002577 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002578 return -1;
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002579 } else if (keyCode == KeyEvent.KEYCODE_ASSIST) {
2580 if (down) {
2581 if (repeatCount == 0) {
2582 mAssistKeyLongPressed = false;
2583 } else if (repeatCount == 1) {
2584 mAssistKeyLongPressed = true;
2585 if (!keyguardOn) {
2586 launchAssistLongPressAction();
2587 }
2588 }
2589 } else {
2590 if (mAssistKeyLongPressed) {
2591 mAssistKeyLongPressed = false;
2592 } else {
2593 if (!keyguardOn) {
2594 launchAssistAction();
2595 }
2596 }
2597 }
2598 return -1;
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002599 } else if (keyCode == KeyEvent.KEYCODE_VOICE_ASSIST) {
2600 if (!down) {
2601 Intent voiceIntent;
Michael Wright869a67c2014-08-26 19:33:06 -07002602 if (!keyguardOn) {
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002603 voiceIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
2604 } else {
2605 voiceIntent = new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
Michael Wright869a67c2014-08-26 19:33:06 -07002606 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, true);
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002607 }
2608 mContext.startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
2609 }
Jeff Sharkey2991fa32012-12-05 18:06:43 -08002610 } else if (keyCode == KeyEvent.KEYCODE_SYSRQ) {
2611 if (down && repeatCount == 0) {
2612 mHandler.post(mScreenshotRunnable);
2613 }
2614 return -1;
Michael Wrightb854e242013-02-05 17:54:02 -08002615 } else if (keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP
2616 || keyCode == KeyEvent.KEYCODE_BRIGHTNESS_DOWN) {
2617 if (down) {
2618 int direction = keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP ? 1 : -1;
2619
2620 // Disable autobrightness if it's on
2621 int auto = Settings.System.getIntForUser(
2622 mContext.getContentResolver(),
2623 Settings.System.SCREEN_BRIGHTNESS_MODE,
2624 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2625 UserHandle.USER_CURRENT_OR_SELF);
2626 if (auto != 0) {
2627 Settings.System.putIntForUser(mContext.getContentResolver(),
2628 Settings.System.SCREEN_BRIGHTNESS_MODE,
2629 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2630 UserHandle.USER_CURRENT_OR_SELF);
2631 }
2632
2633 int min = mPowerManager.getMinimumScreenBrightnessSetting();
2634 int max = mPowerManager.getMaximumScreenBrightnessSetting();
2635 int step = (max - min + BRIGHTNESS_STEPS - 1) / BRIGHTNESS_STEPS * direction;
2636 int brightness = Settings.System.getIntForUser(mContext.getContentResolver(),
2637 Settings.System.SCREEN_BRIGHTNESS,
2638 mPowerManager.getDefaultScreenBrightnessSetting(),
2639 UserHandle.USER_CURRENT_OR_SELF);
2640 brightness += step;
2641 // Make sure we don't go beyond the limits.
2642 brightness = Math.min(max, brightness);
2643 brightness = Math.max(min, brightness);
2644
2645 Settings.System.putIntForUser(mContext.getContentResolver(),
2646 Settings.System.SCREEN_BRIGHTNESS, brightness,
2647 UserHandle.USER_CURRENT_OR_SELF);
Alan Viverette5a399492014-07-14 16:19:38 -07002648 mContext.startActivityAsUser(new Intent(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG),
2649 UserHandle.CURRENT_OR_SELF);
Michael Wrightb854e242013-02-05 17:54:02 -08002650 }
2651 return -1;
Michael Wrightce0c13a2014-07-30 10:49:21 -07002652 } else if (KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07002653 if (down) {
2654 mPendingMetaAction = true;
2655 } else if (mPendingMetaAction) {
Michael Wright8ab940a2014-09-01 11:01:27 -07002656 launchAssistAction(Intent.EXTRA_ASSIST_INPUT_HINT_KEYBOARD);
Michael Wright6a62e552014-06-03 19:19:48 -07002657 }
2658 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002659 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002660
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002661 // Shortcuts are invoked through Search+key, so intercept those here
Jeff Browncaab4d02010-12-09 22:13:41 -08002662 // Any printing key that is chorded with Search should be consumed
2663 // even if no shortcut was invoked. This prevents text from being
2664 // inadvertently inserted when using a keyboard that has built-in macro
2665 // shortcut keys (that emit Search+x) and some of them are not registered.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002666 if (mSearchKeyShortcutPending) {
Jeff Browncaab4d02010-12-09 22:13:41 -08002667 final KeyCharacterMap kcm = event.getKeyCharacterMap();
2668 if (kcm.isPrintingKey(keyCode)) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002669 mConsumeSearchKeyUp = true;
2670 mSearchKeyShortcutPending = false;
Jeff Browncaab4d02010-12-09 22:13:41 -08002671 if (down && repeatCount == 0 && !keyguardOn) {
2672 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState);
2673 if (shortcutIntent != null) {
2674 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002675 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002676 mContext.startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002677 } catch (ActivityNotFoundException ex) {
2678 Slog.w(TAG, "Dropping shortcut key combination because "
2679 + "the activity to which it is registered was not found: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002680 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode), ex);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002681 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002682 } else {
2683 Slog.i(TAG, "Dropping unregistered shortcut key combination: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002684 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002685 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002686 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002687 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002688 }
2689 }
2690
Jeff Brown68b909d2011-12-07 16:36:01 -08002691 // Invoke shortcuts using Meta.
Jeff Brown602ab322012-05-16 13:33:47 -07002692 if (down && repeatCount == 0 && !keyguardOn
Jeff Brown68b909d2011-12-07 16:36:01 -08002693 && (metaState & KeyEvent.META_META_ON) != 0) {
2694 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brown602ab322012-05-16 13:33:47 -07002695 if (kcm.isPrintingKey(keyCode)) {
2696 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode,
2697 metaState & ~(KeyEvent.META_META_ON
2698 | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON));
2699 if (shortcutIntent != null) {
2700 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2701 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002702 mContext.startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brown602ab322012-05-16 13:33:47 -07002703 } catch (ActivityNotFoundException ex) {
2704 Slog.w(TAG, "Dropping shortcut key combination because "
2705 + "the activity to which it is registered was not found: "
2706 + "META+" + KeyEvent.keyCodeToString(keyCode), ex);
2707 }
2708 return -1;
Jeff Brown68b909d2011-12-07 16:36:01 -08002709 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002710 }
2711 }
2712
Jeff Brown6651a632011-11-28 12:59:11 -08002713 // Handle application launch keys.
Jeff Brown602ab322012-05-16 13:33:47 -07002714 if (down && repeatCount == 0 && !keyguardOn) {
Jeff Brown6651a632011-11-28 12:59:11 -08002715 String category = sApplicationLaunchKeyCategories.get(keyCode);
2716 if (category != null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -08002717 Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category);
Jeff Brown6651a632011-11-28 12:59:11 -08002718 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2719 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002720 mContext.startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brown6651a632011-11-28 12:59:11 -08002721 } catch (ActivityNotFoundException ex) {
2722 Slog.w(TAG, "Dropping application launch key because "
2723 + "the activity to which it is registered was not found: "
2724 + "keyCode=" + keyCode + ", category=" + category, ex);
2725 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002726 return -1;
Jeff Brown6651a632011-11-28 12:59:11 -08002727 }
2728 }
2729
Michael Wright61c46752014-08-21 16:57:33 -07002730 // Display task switcher for ALT-TAB.
Jeff Brown68b909d2011-12-07 16:36:01 -08002731 if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_TAB) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002732 if (mRecentAppsHeldModifiers == 0 && !keyguardOn) {
Jeff Brown68b909d2011-12-07 16:36:01 -08002733 final int shiftlessModifiers = event.getModifiers() & ~KeyEvent.META_SHIFT_MASK;
Michael Wright61c46752014-08-21 16:57:33 -07002734 if (KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_ALT_ON)) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002735 mRecentAppsHeldModifiers = shiftlessModifiers;
2736 showRecentApps(true);
Jeff Brown68b909d2011-12-07 16:36:01 -08002737 return -1;
2738 }
2739 }
Winson Chung1e8d71b2014-05-16 17:05:22 -07002740 } else if (!down && mRecentAppsHeldModifiers != 0
2741 && (metaState & mRecentAppsHeldModifiers) == 0) {
2742 mRecentAppsHeldModifiers = 0;
Winson Chungcdcd4872014-08-05 18:00:13 -07002743 hideRecentApps(true, false);
Jeff Brown68b909d2011-12-07 16:36:01 -08002744 }
2745
Jeff Browncf39bdf2012-05-18 14:41:19 -07002746 // Handle keyboard language switching.
2747 if (down && repeatCount == 0
2748 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2749 || (keyCode == KeyEvent.KEYCODE_SPACE
2750 && (metaState & KeyEvent.META_CTRL_MASK) != 0))) {
2751 int direction = (metaState & KeyEvent.META_SHIFT_MASK) != 0 ? -1 : 1;
2752 mWindowManagerFuncs.switchKeyboardLayout(event.getDeviceId(), direction);
2753 return -1;
2754 }
2755 if (mLanguageSwitchKeyPressed && !down
2756 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2757 || keyCode == KeyEvent.KEYCODE_SPACE)) {
2758 mLanguageSwitchKeyPressed = false;
2759 return -1;
2760 }
2761
Jeff Brown13f00f02014-10-31 14:45:50 -07002762 if (isValidGlobalKey(keyCode)
2763 && mGlobalKeyManager.handleGlobalKey(mContext, keyCode, event)) {
Justin Kohd378ad72013-04-01 12:18:26 -07002764 return -1;
2765 }
2766
Michael Wright6a62e552014-06-03 19:19:48 -07002767 // Reserve all the META modifier combos for system behavior
Michael Wrightce0c13a2014-07-30 10:49:21 -07002768 if ((metaState & KeyEvent.META_META_ON) != 0) {
Michael Wright6a62e552014-06-03 19:19:48 -07002769 return -1;
2770 }
2771
Jeff Brown68b909d2011-12-07 16:36:01 -08002772 // Let the application handle the key.
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002773 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002774 }
2775
Jeff Brown3915bb82010-11-05 15:02:16 -07002776 /** {@inheritDoc} */
2777 @Override
Jeff Brown49ed71d2010-12-06 17:13:33 -08002778 public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown54875002011-04-06 15:33:01 -07002779 // Note: This method is only called if the initial down was unhandled.
Jeff Brown40013652012-05-16 21:22:36 -07002780 if (DEBUG_INPUT) {
Jeff Brown1f245102010-11-18 20:53:46 -08002781 Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction()
2782 + ", flags=" + event.getFlags()
2783 + ", keyCode=" + event.getKeyCode()
2784 + ", scanCode=" + event.getScanCode()
2785 + ", metaState=" + event.getMetaState()
2786 + ", repeatCount=" + event.getRepeatCount()
2787 + ", policyFlags=" + policyFlags);
Jeff Brown3915bb82010-11-05 15:02:16 -07002788 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002789
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002790 KeyEvent fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002791 if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
2792 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002793 final int keyCode = event.getKeyCode();
2794 final int metaState = event.getMetaState();
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002795 final boolean initialDown = event.getAction() == KeyEvent.ACTION_DOWN
2796 && event.getRepeatCount() == 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002797
Jeff Brown54875002011-04-06 15:33:01 -07002798 // Check for fallback actions specified by the key character map.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002799 final FallbackAction fallbackAction;
2800 if (initialDown) {
2801 fallbackAction = kcm.getFallbackAction(keyCode, metaState);
2802 } else {
2803 fallbackAction = mFallbackActions.get(keyCode);
2804 }
2805
2806 if (fallbackAction != null) {
Jeff Brown40013652012-05-16 21:22:36 -07002807 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002808 Slog.d(TAG, "Fallback: keyCode=" + fallbackAction.keyCode
2809 + " metaState=" + Integer.toHexString(fallbackAction.metaState));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002810 }
2811
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002812 final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK;
2813 fallbackEvent = KeyEvent.obtain(
Jeff Brown49ed71d2010-12-06 17:13:33 -08002814 event.getDownTime(), event.getEventTime(),
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002815 event.getAction(), fallbackAction.keyCode,
2816 event.getRepeatCount(), fallbackAction.metaState,
Jeff Brown49ed71d2010-12-06 17:13:33 -08002817 event.getDeviceId(), event.getScanCode(),
2818 flags, event.getSource(), null);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002819
2820 if (!interceptFallback(win, fallbackEvent, policyFlags)) {
2821 fallbackEvent.recycle();
2822 fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002823 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002824
2825 if (initialDown) {
2826 mFallbackActions.put(keyCode, fallbackAction);
2827 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2828 mFallbackActions.remove(keyCode);
2829 fallbackAction.recycle();
2830 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002831 }
2832 }
2833
Jeff Brown40013652012-05-16 21:22:36 -07002834 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002835 if (fallbackEvent == null) {
2836 Slog.d(TAG, "No fallback.");
2837 } else {
2838 Slog.d(TAG, "Performing fallback: " + fallbackEvent);
2839 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002840 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002841 return fallbackEvent;
Jeff Brown3915bb82010-11-05 15:02:16 -07002842 }
2843
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002844 private boolean interceptFallback(WindowState win, KeyEvent fallbackEvent, int policyFlags) {
Jeff Brown037c33e2014-04-09 00:31:55 -07002845 int actions = interceptKeyBeforeQueueing(fallbackEvent, policyFlags);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002846 if ((actions & ACTION_PASS_TO_USER) != 0) {
2847 long delayMillis = interceptKeyBeforeDispatching(
2848 win, fallbackEvent, policyFlags);
2849 if (delayMillis == 0) {
2850 return true;
2851 }
2852 }
2853 return false;
Jeff Brown6f2fba42011-02-19 01:08:02 -08002854 }
2855
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002856 private void launchAssistLongPressAction() {
2857 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
2858 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
2859
2860 // launch the search activity
2861 Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS);
2862 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2863 try {
RoboErik8a2cfc32014-05-16 11:19:38 -07002864 // TODO: This only stops the factory-installed search manager.
Jim Miller45308b12012-06-18 19:23:39 -07002865 // Need to formalize an API to handle others
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002866 SearchManager searchManager = getSearchManager();
2867 if (searchManager != null) {
2868 searchManager.stopSearch();
2869 }
Michael Wright43e27f72013-04-10 14:06:48 -07002870 mContext.startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002871 } catch (ActivityNotFoundException e) {
2872 Slog.w(TAG, "No activity to handle assist long press action.", e);
2873 }
2874 }
2875
2876 private void launchAssistAction() {
Michael Wright8ab940a2014-09-01 11:01:27 -07002877 launchAssistAction(null);
2878 }
2879
2880 private void launchAssistAction(String hint) {
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002881 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
Amith Yamasanic1d07a42012-08-14 09:32:02 -07002882 Intent intent = ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE))
Dianne Hackbornf9c5e0f2013-01-23 14:39:13 -08002883 .getAssistIntent(mContext, true, UserHandle.USER_CURRENT);
Jim Miller45308b12012-06-18 19:23:39 -07002884 if (intent != null) {
Michael Wright8ab940a2014-09-01 11:01:27 -07002885 if (hint != null) {
2886 intent.putExtra(hint, true);
2887 }
Jim Miller45308b12012-06-18 19:23:39 -07002888 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
2889 | Intent.FLAG_ACTIVITY_SINGLE_TOP
2890 | Intent.FLAG_ACTIVITY_CLEAR_TOP);
2891 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002892 mContext.startActivityAsUser(intent, UserHandle.CURRENT);
Jim Miller45308b12012-06-18 19:23:39 -07002893 } catch (ActivityNotFoundException e) {
2894 Slog.w(TAG, "No activity to handle assist action.", e);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002895 }
2896 }
2897 }
2898
2899 private SearchManager getSearchManager() {
2900 if (mSearchManager == null) {
2901 mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
2902 }
2903 return mSearchManager;
2904 }
2905
Jeff Browncaca8812013-05-09 13:34:33 -07002906 private void preloadRecentApps() {
2907 mPreloadedRecentApps = true;
2908 try {
2909 IStatusBarService statusbar = getStatusBarService();
2910 if (statusbar != null) {
2911 statusbar.preloadRecentApps();
2912 }
2913 } catch (RemoteException e) {
2914 Slog.e(TAG, "RemoteException when preloading recent apps", e);
2915 // re-acquire status bar service next time it is needed.
2916 mStatusBarService = null;
2917 }
2918 }
2919
2920 private void cancelPreloadRecentApps() {
2921 if (mPreloadedRecentApps) {
2922 mPreloadedRecentApps = false;
2923 try {
2924 IStatusBarService statusbar = getStatusBarService();
2925 if (statusbar != null) {
2926 statusbar.cancelPreloadRecentApps();
2927 }
2928 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002929 Slog.e(TAG, "RemoteException when cancelling recent apps preload", e);
Jeff Browncaca8812013-05-09 13:34:33 -07002930 // re-acquire status bar service next time it is needed.
2931 mStatusBarService = null;
2932 }
2933 }
2934 }
2935
2936 private void toggleRecentApps() {
2937 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
Jeff Browncaca8812013-05-09 13:34:33 -07002938 try {
2939 IStatusBarService statusbar = getStatusBarService();
2940 if (statusbar != null) {
2941 statusbar.toggleRecentApps();
2942 }
2943 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002944 Slog.e(TAG, "RemoteException when toggling recent apps", e);
2945 // re-acquire status bar service next time it is needed.
2946 mStatusBarService = null;
2947 }
2948 }
2949
Craig Mautner84984fa2014-06-19 11:19:20 -07002950 @Override
2951 public void showRecentApps() {
2952 mHandler.removeMessages(MSG_DISPATCH_SHOW_RECENTS);
2953 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_RECENTS);
2954 }
2955
Winson Chung1e8d71b2014-05-16 17:05:22 -07002956 private void showRecentApps(boolean triggeredFromAltTab) {
2957 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
2958 try {
2959 IStatusBarService statusbar = getStatusBarService();
2960 if (statusbar != null) {
2961 statusbar.showRecentApps(triggeredFromAltTab);
2962 }
2963 } catch (RemoteException e) {
Jeff Browncaca8812013-05-09 13:34:33 -07002964 Slog.e(TAG, "RemoteException when showing recent apps", e);
2965 // re-acquire status bar service next time it is needed.
2966 mStatusBarService = null;
2967 }
2968 }
2969
Winson Chungcdcd4872014-08-05 18:00:13 -07002970 private void hideRecentApps(boolean triggeredFromAltTab, boolean triggeredFromHome) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002971 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
2972 try {
2973 IStatusBarService statusbar = getStatusBarService();
2974 if (statusbar != null) {
Winson Chungcdcd4872014-08-05 18:00:13 -07002975 statusbar.hideRecentApps(triggeredFromAltTab, triggeredFromHome);
Winson Chung1e8d71b2014-05-16 17:05:22 -07002976 }
2977 } catch (RemoteException e) {
2978 Slog.e(TAG, "RemoteException when closing recent apps", e);
2979 // re-acquire status bar service next time it is needed.
2980 mStatusBarService = null;
2981 }
2982 }
2983
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002984 /**
2985 * A home key -> launch home action was detected. Take the appropriate action
2986 * given the situation with the keyguard.
2987 */
2988 void launchHomeFromHotKey() {
Jim Millerab954542014-10-10 18:21:49 -07002989 if (isKeyguardShowingAndNotOccluded()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002990 // don't launch home if keyguard showing
Jim Miller5ecd8112013-01-09 18:50:26 -08002991 } else if (!mHideLockScreen && mKeyguardDelegate.isInputRestricted()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002992 // when in keyguard restricted mode, must first verify unlock
2993 // before launching home
Jim Miller5ecd8112013-01-09 18:50:26 -08002994 mKeyguardDelegate.verifyUnlock(new OnKeyguardExitResult() {
Jose Lima9546b202014-07-02 17:21:51 -07002995 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002996 public void onKeyguardExitResult(boolean success) {
2997 if (success) {
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07002998 try {
2999 ActivityManagerNative.getDefault().stopAppSwitches();
3000 } catch (RemoteException e) {
3001 }
Joe Onoratof275f0c2009-11-24 16:11:13 -05003002 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
Bryce Lee01b0c5f2015-02-05 18:24:04 -08003003 startDockOrHome(true /*fromHomeKey*/);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003004 }
3005 }
3006 });
3007 } else {
3008 // no keyguard stuff to worry about, just launch home!
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07003009 try {
3010 ActivityManagerNative.getDefault().stopAppSwitches();
3011 } catch (RemoteException e) {
3012 }
Winson Chungd543c1b2014-06-23 15:06:45 -07003013 if (mRecentsVisible) {
3014 // Hide Recents and notify it to launch Home
3015 awakenDreams();
3016 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
Winson Chungcdcd4872014-08-05 18:00:13 -07003017 hideRecentApps(false, true);
Winson Chungd543c1b2014-06-23 15:06:45 -07003018 } else {
3019 // Otherwise, just launch Home
3020 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
Bryce Lee01b0c5f2015-02-05 18:24:04 -08003021 startDockOrHome(true /*fromHomeKey*/);
Winson Chungd543c1b2014-06-23 15:06:45 -07003022 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003023 }
3024 }
3025
John Spurlock04db1762013-05-13 12:46:41 -04003026 private final Runnable mClearHideNavigationFlag = new Runnable() {
3027 @Override
3028 public void run() {
3029 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
3030 // Clear flags.
3031 mForceClearedSystemUiFlags &=
3032 ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
3033 }
3034 mWindowManagerFuncs.reevaluateStatusBarVisibility();
Dianne Hackborne26ab702011-10-16 13:21:33 -07003035 }
3036 };
3037
3038 /**
3039 * Input handler used while nav bar is hidden. Captures any touch on the screen,
3040 * to determine when the nav bar should be shown and prevent applications from
3041 * receiving those touches.
3042 */
Jeff Brown32cbc38552011-12-01 14:01:49 -08003043 final class HideNavInputEventReceiver extends InputEventReceiver {
3044 public HideNavInputEventReceiver(InputChannel inputChannel, Looper looper) {
3045 super(inputChannel, looper);
3046 }
3047
Dianne Hackborndf89e652011-10-06 22:35:11 -07003048 @Override
Jeff Brown32cbc38552011-12-01 14:01:49 -08003049 public void onInputEvent(InputEvent event) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003050 boolean handled = false;
3051 try {
Jeff Brown4952dfd2011-11-30 19:23:22 -08003052 if (event instanceof MotionEvent
3053 && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
3054 final MotionEvent motionEvent = (MotionEvent)event;
3055 if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003056 // When the user taps down, we re-show the nav bar.
3057 boolean changed = false;
John Spurlock04db1762013-05-13 12:46:41 -04003058 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003059 // Any user activity always causes us to show the
3060 // navigation controls, if they had been hidden.
3061 // We also clear the low profile and only content
3062 // flags so that tapping on the screen will atomically
3063 // restore all currently hidden screen decorations.
3064 int newVal = mResettingSystemUiFlags |
3065 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
3066 View.SYSTEM_UI_FLAG_LOW_PROFILE |
3067 View.SYSTEM_UI_FLAG_FULLSCREEN;
Dianne Hackborne26ab702011-10-16 13:21:33 -07003068 if (mResettingSystemUiFlags != newVal) {
3069 mResettingSystemUiFlags = newVal;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003070 changed = true;
3071 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003072 // We don't allow the system's nav bar to be hidden
3073 // again for 1 second, to prevent applications from
3074 // spamming us and keeping it from being shown.
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003075 newVal = mForceClearedSystemUiFlags |
3076 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
Dianne Hackborne26ab702011-10-16 13:21:33 -07003077 if (mForceClearedSystemUiFlags != newVal) {
3078 mForceClearedSystemUiFlags = newVal;
3079 changed = true;
John Spurlock04db1762013-05-13 12:46:41 -04003080 mHandler.postDelayed(mClearHideNavigationFlag, 1000);
Dianne Hackborne26ab702011-10-16 13:21:33 -07003081 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07003082 }
3083 if (changed) {
3084 mWindowManagerFuncs.reevaluateStatusBarVisibility();
3085 }
3086 }
3087 }
3088 } finally {
Jeff Brown32cbc38552011-12-01 14:01:49 -08003089 finishInputEvent(event, handled);
Dianne Hackborndf89e652011-10-06 22:35:11 -07003090 }
3091 }
Jeff Brown32cbc38552011-12-01 14:01:49 -08003092 }
3093 final InputEventReceiver.Factory mHideNavInputEventReceiverFactory =
3094 new InputEventReceiver.Factory() {
3095 @Override
3096 public InputEventReceiver createInputEventReceiver(
3097 InputChannel inputChannel, Looper looper) {
3098 return new HideNavInputEventReceiver(inputChannel, looper);
3099 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07003100 };
3101
3102 @Override
3103 public int adjustSystemUiVisibilityLw(int visibility) {
John Spurlock5b9145b2013-08-20 15:13:47 -04003104 mStatusBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
3105 mNavigationBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
Winson Chungd42a6cf2014-06-03 16:24:04 -07003106 mRecentsVisible = (visibility & View.RECENT_APPS_VISIBLE) > 0;
John Spurlock27735a42013-08-14 17:57:38 -04003107
Dianne Hackborndf89e652011-10-06 22:35:11 -07003108 // Reset any bits in mForceClearingStatusBarVisibility that
3109 // are now clear.
Dianne Hackborne26ab702011-10-16 13:21:33 -07003110 mResettingSystemUiFlags &= visibility;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003111 // Clear any bits in the new visibility that are currently being
3112 // force cleared, before reporting it.
Dianne Hackborne26ab702011-10-16 13:21:33 -07003113 return visibility & ~mResettingSystemUiFlags
3114 & ~mForceClearedSystemUiFlags;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003115 }
3116
Craig Mautner69b08182012-09-05 13:07:13 -07003117 @Override
Adrian Roos37d7a682014-11-06 18:15:16 +01003118 public void getInsetHintLw(WindowManager.LayoutParams attrs, Rect outContentInsets,
3119 Rect outStableInsets) {
John Spurlockc6d1c602014-01-17 15:22:06 -05003120 final int fl = PolicyControl.getWindowFlags(null, attrs);
John Spurlock1db8b682014-02-18 11:18:59 -05003121 final int sysuiVis = PolicyControl.getSystemUiVisibility(null, attrs);
3122 final int systemUiVisibility = (sysuiVis | attrs.subtreeSystemUiVisibility);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003123
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003124 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003125 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003126 int availRight, availBottom;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003127 if (canHideNavigationBar() &&
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003128 (systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003129 availRight = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3130 availBottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
3131 } else {
3132 availRight = mRestrictedScreenLeft + mRestrictedScreenWidth;
3133 availBottom = mRestrictedScreenTop + mRestrictedScreenHeight;
3134 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003135 if ((systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
3136 if ((fl & FLAG_FULLSCREEN) != 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003137 outContentInsets.set(mStableFullscreenLeft, mStableFullscreenTop,
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003138 availRight - mStableFullscreenRight,
3139 availBottom - mStableFullscreenBottom);
3140 } else {
Adrian Roos37d7a682014-11-06 18:15:16 +01003141 outContentInsets.set(mStableLeft, mStableTop,
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003142 availRight - mStableRight, availBottom - mStableBottom);
3143 }
Dianne Hackbornc652de82013-02-15 16:32:56 -08003144 } else if ((fl & FLAG_FULLSCREEN) != 0 || (fl & FLAG_LAYOUT_IN_OVERSCAN) != 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003145 outContentInsets.setEmpty();
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003146 } else if ((systemUiVisibility & (View.SYSTEM_UI_FLAG_FULLSCREEN
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003147 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)) == 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003148 outContentInsets.set(mCurLeft, mCurTop,
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003149 availRight - mCurRight, availBottom - mCurBottom);
3150 } else {
Adrian Roos37d7a682014-11-06 18:15:16 +01003151 outContentInsets.set(mCurLeft, mCurTop,
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003152 availRight - mCurRight, availBottom - mCurBottom);
3153 }
Adrian Roos37d7a682014-11-06 18:15:16 +01003154
3155 outStableInsets.set(mStableLeft, mStableTop,
3156 availRight - mStableRight, availBottom - mStableBottom);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003157 return;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003158 }
Adrian Roos37d7a682014-11-06 18:15:16 +01003159 outContentInsets.setEmpty();
3160 outStableInsets.setEmpty();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003161 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003162
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003163 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07003164 @Override
3165 public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight,
3166 int displayRotation) {
Dianne Hackbornc652de82013-02-15 16:32:56 -08003167 final int overscanLeft, overscanTop, overscanRight, overscanBottom;
3168 if (isDefaultDisplay) {
3169 switch (displayRotation) {
3170 case Surface.ROTATION_90:
3171 overscanLeft = mOverscanTop;
3172 overscanTop = mOverscanRight;
3173 overscanRight = mOverscanBottom;
3174 overscanBottom = mOverscanLeft;
3175 break;
3176 case Surface.ROTATION_180:
3177 overscanLeft = mOverscanRight;
3178 overscanTop = mOverscanBottom;
3179 overscanRight = mOverscanLeft;
3180 overscanBottom = mOverscanTop;
3181 break;
3182 case Surface.ROTATION_270:
3183 overscanLeft = mOverscanBottom;
3184 overscanTop = mOverscanLeft;
3185 overscanRight = mOverscanTop;
3186 overscanBottom = mOverscanRight;
3187 break;
3188 default:
3189 overscanLeft = mOverscanLeft;
3190 overscanTop = mOverscanTop;
3191 overscanRight = mOverscanRight;
3192 overscanBottom = mOverscanBottom;
3193 break;
3194 }
3195 } else {
3196 overscanLeft = 0;
3197 overscanTop = 0;
3198 overscanRight = 0;
3199 overscanBottom = 0;
3200 }
Dianne Hackborn313440842013-02-19 19:22:59 -08003201 mOverscanScreenLeft = mRestrictedOverscanScreenLeft = 0;
3202 mOverscanScreenTop = mRestrictedOverscanScreenTop = 0;
3203 mOverscanScreenWidth = mRestrictedOverscanScreenWidth = displayWidth;
3204 mOverscanScreenHeight = mRestrictedOverscanScreenHeight = displayHeight;
Dianne Hackbornc652de82013-02-15 16:32:56 -08003205 mSystemLeft = 0;
3206 mSystemTop = 0;
3207 mSystemRight = displayWidth;
3208 mSystemBottom = displayHeight;
3209 mUnrestrictedScreenLeft = overscanLeft;
3210 mUnrestrictedScreenTop = overscanTop;
3211 mUnrestrictedScreenWidth = displayWidth - overscanLeft - overscanRight;
3212 mUnrestrictedScreenHeight = displayHeight - overscanTop - overscanBottom;
3213 mRestrictedScreenLeft = mUnrestrictedScreenLeft;
3214 mRestrictedScreenTop = mUnrestrictedScreenTop;
John Spurlockad3e6cb2013-04-30 08:47:43 -04003215 mRestrictedScreenWidth = mSystemGestures.screenWidth = mUnrestrictedScreenWidth;
3216 mRestrictedScreenHeight = mSystemGestures.screenHeight = mUnrestrictedScreenHeight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003217 mDockLeft = mContentLeft = mVoiceContentLeft = mStableLeft = mStableFullscreenLeft
Dianne Hackbornc652de82013-02-15 16:32:56 -08003218 = mCurLeft = mUnrestrictedScreenLeft;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003219 mDockTop = mContentTop = mVoiceContentTop = mStableTop = mStableFullscreenTop
Dianne Hackbornc652de82013-02-15 16:32:56 -08003220 = mCurTop = mUnrestrictedScreenTop;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003221 mDockRight = mContentRight = mVoiceContentRight = mStableRight = mStableFullscreenRight
Dianne Hackbornc652de82013-02-15 16:32:56 -08003222 = mCurRight = displayWidth - overscanRight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003223 mDockBottom = mContentBottom = mVoiceContentBottom = mStableBottom = mStableFullscreenBottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003224 = mCurBottom = displayHeight - overscanBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003225 mDockLayer = 0x10000000;
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003226 mStatusBarLayer = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003227
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003228 // start with the current dock rect, which will be (0,0,displayWidth,displayHeight)
3229 final Rect pf = mTmpParentFrame;
3230 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003231 final Rect of = mTmpOverscanFrame;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003232 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04003233 final Rect dcf = mTmpDecorFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003234 pf.left = df.left = of.left = vf.left = mDockLeft;
3235 pf.top = df.top = of.top = vf.top = mDockTop;
3236 pf.right = df.right = of.right = vf.right = mDockRight;
3237 pf.bottom = df.bottom = of.bottom = vf.bottom = mDockBottom;
John Spurlock46646232013-09-30 22:32:42 -04003238 dcf.setEmpty(); // Decor frame N/A for system bars.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003239
Craig Mautner69b08182012-09-05 13:07:13 -07003240 if (isDefaultDisplay) {
3241 // For purposes of putting out fake window up to steal focus, we will
3242 // drive nav being hidden only by whether it is requested.
John Spurlocke1f366f2013-08-05 12:22:40 -04003243 final int sysui = mLastSystemUiFlags;
3244 boolean navVisible = (sysui & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0;
Adrian Roosea562512014-05-05 13:33:03 +02003245 boolean navTranslucent = (sysui
3246 & (View.NAVIGATION_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04003247 boolean immersive = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
3248 boolean immersiveSticky = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
3249 boolean navAllowedHidden = immersive || immersiveSticky;
3250 navTranslucent &= !immersiveSticky; // transient trumps translucent
Adrian Roos4fb3ee32014-08-22 19:29:09 +02003251 boolean isKeyguardShowing = isStatusBarKeyguard() && !mHideLockScreen;
3252 if (!isKeyguardShowing) {
3253 navTranslucent &= areTranslucentBarsAllowed();
3254 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003255
Craig Mautner69b08182012-09-05 13:07:13 -07003256 // When the navigation bar isn't visible, we put up a fake
3257 // input window to catch all touch events. This way we can
3258 // detect when the user presses anywhere to bring back the nav
3259 // bar and ensure the application doesn't see the event.
John Spurlockf1a36642013-10-12 17:50:42 -04003260 if (navVisible || navAllowedHidden) {
Craig Mautner69b08182012-09-05 13:07:13 -07003261 if (mHideNavFakeWindow != null) {
3262 mHideNavFakeWindow.dismiss();
3263 mHideNavFakeWindow = null;
3264 }
3265 } else if (mHideNavFakeWindow == null) {
3266 mHideNavFakeWindow = mWindowManagerFuncs.addFakeWindow(
3267 mHandler.getLooper(), mHideNavInputEventReceiverFactory,
Adam Lesinski95c42972013-10-02 10:13:27 -07003268 "hidden nav", WindowManager.LayoutParams.TYPE_HIDDEN_NAV_CONSUMER, 0,
Craig Mautner69b08182012-09-05 13:07:13 -07003269 0, false, false, true);
Dianne Hackborne26ab702011-10-16 13:21:33 -07003270 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003271
Craig Mautner69b08182012-09-05 13:07:13 -07003272 // For purposes of positioning and showing the nav bar, if we have
3273 // decided that it can't be hidden (because of the screen aspect ratio),
3274 // then take that into account.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003275 navVisible |= !canHideNavigationBar();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003276
John Spurlockad3e6cb2013-04-30 08:47:43 -04003277 boolean updateSysUiVisibility = false;
Craig Mautner69b08182012-09-05 13:07:13 -07003278 if (mNavigationBar != null) {
John Spurlock27735a42013-08-14 17:57:38 -04003279 boolean transientNavBarShowing = mNavigationBarController.isTransientShowing();
Craig Mautner69b08182012-09-05 13:07:13 -07003280 // Force the navigation bar to its appropriate place and
3281 // size. We need to do this directly, instead of relying on
3282 // it to bubble up from the nav bar, because this needs to
3283 // change atomically with screen rotations.
3284 mNavigationBarOnBottom = (!mNavigationBarCanMove || displayWidth < displayHeight);
3285 if (mNavigationBarOnBottom) {
3286 // It's a system nav bar or a portrait screen; nav bar goes on bottom.
Dianne Hackbornc652de82013-02-15 16:32:56 -08003287 int top = displayHeight - overscanBottom
3288 - mNavigationBarHeightForRotation[displayRotation];
3289 mTmpNavigationFrame.set(0, top, displayWidth, displayHeight - overscanBottom);
Craig Mautner69b08182012-09-05 13:07:13 -07003290 mStableBottom = mStableFullscreenBottom = mTmpNavigationFrame.top;
John Spurlockf95b89a2013-10-10 22:10:42 -04003291 if (transientNavBarShowing) {
John Spurlock27735a42013-08-14 17:57:38 -04003292 mNavigationBarController.setBarShowingLw(true);
John Spurlockad3e6cb2013-04-30 08:47:43 -04003293 } else if (navVisible) {
John Spurlock27735a42013-08-14 17:57:38 -04003294 mNavigationBarController.setBarShowingLw(true);
Craig Mautner69b08182012-09-05 13:07:13 -07003295 mDockBottom = mTmpNavigationFrame.top;
Dianne Hackborn313440842013-02-19 19:22:59 -08003296 mRestrictedScreenHeight = mDockBottom - mRestrictedScreenTop;
3297 mRestrictedOverscanScreenHeight = mDockBottom - mRestrictedOverscanScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07003298 } else {
3299 // We currently want to hide the navigation UI.
John Spurlock27735a42013-08-14 17:57:38 -04003300 mNavigationBarController.setBarShowingLw(false);
Craig Mautner69b08182012-09-05 13:07:13 -07003301 }
John Spurlockc6d1c602014-01-17 15:22:06 -05003302 if (navVisible && !navTranslucent && !navAllowedHidden
3303 && !mNavigationBar.isAnimatingLw()
John Spurlockbd957402013-10-03 11:38:39 -04003304 && !mNavigationBarController.wasRecentlyTranslucent()) {
John Spurlocke1f366f2013-08-05 12:22:40 -04003305 // If the opaque nav bar is currently requested to be visible,
Craig Mautner69b08182012-09-05 13:07:13 -07003306 // and not in the process of animating on or off, then
3307 // we can tell the app that it is covered by it.
3308 mSystemBottom = mTmpNavigationFrame.top;
3309 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003310 } else {
Craig Mautner69b08182012-09-05 13:07:13 -07003311 // Landscape screen; nav bar goes to the right.
Dianne Hackbornc652de82013-02-15 16:32:56 -08003312 int left = displayWidth - overscanRight
3313 - mNavigationBarWidthForRotation[displayRotation];
3314 mTmpNavigationFrame.set(left, 0, displayWidth - overscanRight, displayHeight);
Craig Mautner69b08182012-09-05 13:07:13 -07003315 mStableRight = mStableFullscreenRight = mTmpNavigationFrame.left;
John Spurlockf95b89a2013-10-10 22:10:42 -04003316 if (transientNavBarShowing) {
John Spurlock27735a42013-08-14 17:57:38 -04003317 mNavigationBarController.setBarShowingLw(true);
John Spurlockad3e6cb2013-04-30 08:47:43 -04003318 } else if (navVisible) {
John Spurlock27735a42013-08-14 17:57:38 -04003319 mNavigationBarController.setBarShowingLw(true);
Craig Mautner69b08182012-09-05 13:07:13 -07003320 mDockRight = mTmpNavigationFrame.left;
Dianne Hackborn313440842013-02-19 19:22:59 -08003321 mRestrictedScreenWidth = mDockRight - mRestrictedScreenLeft;
3322 mRestrictedOverscanScreenWidth = mDockRight - mRestrictedOverscanScreenLeft;
Craig Mautner69b08182012-09-05 13:07:13 -07003323 } else {
3324 // We currently want to hide the navigation UI.
John Spurlock27735a42013-08-14 17:57:38 -04003325 mNavigationBarController.setBarShowingLw(false);
Craig Mautner69b08182012-09-05 13:07:13 -07003326 }
John Spurlockbd957402013-10-03 11:38:39 -04003327 if (navVisible && !navTranslucent && !mNavigationBar.isAnimatingLw()
3328 && !mNavigationBarController.wasRecentlyTranslucent()) {
Craig Mautner69b08182012-09-05 13:07:13 -07003329 // If the nav bar is currently requested to be visible,
3330 // and not in the process of animating on or off, then
3331 // we can tell the app that it is covered by it.
3332 mSystemRight = mTmpNavigationFrame.left;
3333 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003334 }
Craig Mautner69b08182012-09-05 13:07:13 -07003335 // Make sure the content and current rectangles are updated to
3336 // account for the restrictions from the navigation bar.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003337 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3338 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3339 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3340 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
Craig Mautner69b08182012-09-05 13:07:13 -07003341 mStatusBarLayer = mNavigationBar.getSurfaceLayer();
3342 // And compute the final frame.
3343 mNavigationBar.computeFrameLw(mTmpNavigationFrame, mTmpNavigationFrame,
Adrian Roosfa104232014-06-20 16:10:14 -07003344 mTmpNavigationFrame, mTmpNavigationFrame, mTmpNavigationFrame, dcf,
3345 mTmpNavigationFrame);
Craig Mautnereda67292013-04-28 13:50:14 -07003346 if (DEBUG_LAYOUT) Slog.i(TAG, "mNavigationBar frame: " + mTmpNavigationFrame);
John Spurlock27735a42013-08-14 17:57:38 -04003347 if (mNavigationBarController.checkHiddenLw()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04003348 updateSysUiVisibility = true;
3349 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003350 }
Craig Mautnereda67292013-04-28 13:50:14 -07003351 if (DEBUG_LAYOUT) Slog.i(TAG, String.format("mDock rect: (%d,%d - %d,%d)",
Craig Mautner69b08182012-09-05 13:07:13 -07003352 mDockLeft, mDockTop, mDockRight, mDockBottom));
3353
3354 // decide where the status bar goes ahead of time
3355 if (mStatusBar != null) {
3356 // apply any navigation bar insets
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003357 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3358 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3359 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
3360 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight
3361 + mUnrestrictedScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07003362 vf.left = mStableLeft;
3363 vf.top = mStableTop;
3364 vf.right = mStableRight;
3365 vf.bottom = mStableBottom;
3366
3367 mStatusBarLayer = mStatusBar.getSurfaceLayer();
3368
3369 // Let the status bar determine its size.
Adrian Roosfa104232014-06-20 16:10:14 -07003370 mStatusBar.computeFrameLw(pf, df, vf, vf, vf, dcf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07003371
3372 // For layout, the status bar is always at the top with our fixed height.
3373 mStableTop = mUnrestrictedScreenTop + mStatusBarHeight;
3374
John Spurlocke1f366f2013-08-05 12:22:40 -04003375 boolean statusBarTransient = (sysui & View.STATUS_BAR_TRANSIENT) != 0;
Adrian Roosea562512014-05-05 13:33:03 +02003376 boolean statusBarTranslucent = (sysui
3377 & (View.STATUS_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0;
Adrian Roos4fb3ee32014-08-22 19:29:09 +02003378 if (!isKeyguardShowing) {
3379 statusBarTranslucent &= areTranslucentBarsAllowed();
3380 }
John Spurlock32beb2c2013-03-11 10:16:47 -04003381
Craig Mautner69b08182012-09-05 13:07:13 -07003382 // If the status bar is hidden, we don't want to cause
3383 // windows behind it to scroll.
John Spurlockeda1f692013-09-16 11:38:44 -04003384 if (mStatusBar.isVisibleLw() && !statusBarTransient) {
Craig Mautner69b08182012-09-05 13:07:13 -07003385 // Status bar may go away, so the screen area it occupies
3386 // is available to apps but just covering them when the
3387 // status bar is visible.
3388 mDockTop = mUnrestrictedScreenTop + mStatusBarHeight;
3389
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003390 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3391 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3392 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3393 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
Craig Mautner69b08182012-09-05 13:07:13 -07003394
Craig Mautnereda67292013-04-28 13:50:14 -07003395 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar: " +
Craig Mautner69b08182012-09-05 13:07:13 -07003396 String.format(
3397 "dock=[%d,%d][%d,%d] content=[%d,%d][%d,%d] cur=[%d,%d][%d,%d]",
3398 mDockLeft, mDockTop, mDockRight, mDockBottom,
3399 mContentLeft, mContentTop, mContentRight, mContentBottom,
3400 mCurLeft, mCurTop, mCurRight, mCurBottom));
3401 }
John Spurlocke1f366f2013-08-05 12:22:40 -04003402 if (mStatusBar.isVisibleLw() && !mStatusBar.isAnimatingLw()
John Spurlockbd957402013-10-03 11:38:39 -04003403 && !statusBarTransient && !statusBarTranslucent
3404 && !mStatusBarController.wasRecentlyTranslucent()) {
John Spurlocke1f366f2013-08-05 12:22:40 -04003405 // If the opaque status bar is currently requested to be visible,
Craig Mautner69b08182012-09-05 13:07:13 -07003406 // and not in the process of animating on or off, then
3407 // we can tell the app that it is covered by it.
3408 mSystemTop = mUnrestrictedScreenTop + mStatusBarHeight;
3409 }
John Spurlock27735a42013-08-14 17:57:38 -04003410 if (mStatusBarController.checkHiddenLw()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04003411 updateSysUiVisibility = true;
John Spurlock32beb2c2013-03-11 10:16:47 -04003412 }
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003413 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04003414 if (updateSysUiVisibility) {
3415 updateSystemUiVisibilityLw();
3416 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003417 }
3418 }
3419
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003420 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07003421 @Override
John Spurlock46646232013-09-30 22:32:42 -04003422 public int getSystemDecorLayerLw() {
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003423 if (mStatusBar != null) return mStatusBar.getSurfaceLayer();
3424 if (mNavigationBar != null) return mNavigationBar.getSurfaceLayer();
3425 return 0;
3426 }
3427
Craig Mautner967212c2013-04-13 21:10:58 -07003428 @Override
3429 public void getContentRectLw(Rect r) {
3430 r.set(mContentLeft, mContentTop, mContentRight, mContentBottom);
3431 }
3432
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003433 void setAttachedWindowFrames(WindowState win, int fl, int adjust, WindowState attached,
3434 boolean insetDecors, Rect pf, Rect df, Rect of, Rect cf, Rect vf) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003435 if (win.getSurfaceLayer() > mDockLayer && attached.getSurfaceLayer() < mDockLayer) {
3436 // Here's a special case: if this attached window is a panel that is
3437 // above the dock window, and the window it is attached to is below
3438 // the dock window, then the frames we computed for the window it is
3439 // attached to can not be used because the dock is effectively part
3440 // of the underlying window and the attached window is floating on top
3441 // of the whole thing. So, we ignore the attached window and explicitly
3442 // compute the frames that would be appropriate without the dock.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003443 df.left = of.left = cf.left = vf.left = mDockLeft;
3444 df.top = of.top = cf.top = vf.top = mDockTop;
3445 df.right = of.right = cf.right = vf.right = mDockRight;
3446 df.bottom = of.bottom = cf.bottom = vf.bottom = mDockBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003447 } else {
3448 // The effective display frame of the attached window depends on
3449 // whether it is taking care of insetting its content. If not,
3450 // we need to use the parent's content frame so that the entire
3451 // window is positioned within that content. Otherwise we can use
Wale Ogunwale393b1c12014-10-18 16:22:01 -07003452 // the overscan frame and let the attached window take care of
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003453 // positioning its content appropriately.
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003454 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Wale Ogunwale393b1c12014-10-18 16:22:01 -07003455 // Set the content frame of the attached window to the parent's decor frame
3456 // (same as content frame when IME isn't present) if specifically requested by
3457 // setting {@link WindowManager.LayoutParams#FLAG_LAYOUT_ATTACHED_IN_DECOR} flag.
3458 // Otherwise, use the overscan frame.
3459 cf.set((fl & FLAG_LAYOUT_ATTACHED_IN_DECOR) != 0
3460 ? attached.getContentFrameLw() : attached.getOverscanFrameLw());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003461 } else {
3462 // If the window is resizing, then we want to base the content
3463 // frame on our attached content frame to resize... however,
3464 // things can be tricky if the attached window is NOT in resize
3465 // mode, in which case its content frame will be larger.
3466 // Ungh. So to deal with that, make sure the content frame
3467 // we end up using is not covering the IM dock.
3468 cf.set(attached.getContentFrameLw());
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003469 if (attached.isVoiceInteraction()) {
3470 if (cf.left < mVoiceContentLeft) cf.left = mVoiceContentLeft;
3471 if (cf.top < mVoiceContentTop) cf.top = mVoiceContentTop;
3472 if (cf.right > mVoiceContentRight) cf.right = mVoiceContentRight;
3473 if (cf.bottom > mVoiceContentBottom) cf.bottom = mVoiceContentBottom;
3474 } else if (attached.getSurfaceLayer() < mDockLayer) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003475 if (cf.left < mContentLeft) cf.left = mContentLeft;
3476 if (cf.top < mContentTop) cf.top = mContentTop;
3477 if (cf.right > mContentRight) cf.right = mContentRight;
3478 if (cf.bottom > mContentBottom) cf.bottom = mContentBottom;
3479 }
3480 }
3481 df.set(insetDecors ? attached.getDisplayFrameLw() : cf);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003482 of.set(insetDecors ? attached.getOverscanFrameLw() : cf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003483 vf.set(attached.getVisibleFrameLw());
3484 }
3485 // The LAYOUT_IN_SCREEN flag is used to determine whether the attached
3486 // window should be positioned relative to its parent or the entire
3487 // screen.
3488 pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0
3489 ? attached.getFrameLw() : df);
3490 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003491
3492 private void applyStableConstraints(int sysui, int fl, Rect r) {
3493 if ((sysui & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
3494 // If app is requesting a stable layout, don't let the
3495 // content insets go below the stable values.
3496 if ((fl & FLAG_FULLSCREEN) != 0) {
3497 if (r.left < mStableFullscreenLeft) r.left = mStableFullscreenLeft;
3498 if (r.top < mStableFullscreenTop) r.top = mStableFullscreenTop;
3499 if (r.right > mStableFullscreenRight) r.right = mStableFullscreenRight;
3500 if (r.bottom > mStableFullscreenBottom) r.bottom = mStableFullscreenBottom;
3501 } else {
3502 if (r.left < mStableLeft) r.left = mStableLeft;
3503 if (r.top < mStableTop) r.top = mStableTop;
3504 if (r.right > mStableRight) r.right = mStableRight;
3505 if (r.bottom > mStableBottom) r.bottom = mStableBottom;
3506 }
3507 }
3508 }
3509
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003510 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07003511 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003512 public void layoutWindowLw(WindowState win, WindowState attached) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003513 // we've already done the status bar
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003514 final WindowManager.LayoutParams attrs = win.getAttrs();
3515 if ((win == mStatusBar && (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) == 0) ||
3516 win == mNavigationBar) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003517 return;
3518 }
Craig Mautner69b08182012-09-05 13:07:13 -07003519 final boolean isDefaultDisplay = win.isDefaultDisplay();
3520 final boolean needsToOffsetInputMethodTarget = isDefaultDisplay &&
satok1bc0a492012-04-25 22:47:12 +09003521 (win == mLastInputMethodTargetWindow && mLastInputMethodWindow != null);
3522 if (needsToOffsetInputMethodTarget) {
Craig Mautnereda67292013-04-28 13:50:14 -07003523 if (DEBUG_LAYOUT) Slog.i(TAG, "Offset ime target window by the last ime window state");
satok1bc0a492012-04-25 22:47:12 +09003524 offsetInputMethodWindowLw(mLastInputMethodWindow);
3525 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003526
John Spurlockc6d1c602014-01-17 15:22:06 -05003527 final int fl = PolicyControl.getWindowFlags(win, attrs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003528 final int sim = attrs.softInputMode;
John Spurlock1db8b682014-02-18 11:18:59 -05003529 final int sysUiFl = PolicyControl.getSystemUiVisibility(win, null);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003530
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003531 final Rect pf = mTmpParentFrame;
3532 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003533 final Rect of = mTmpOverscanFrame;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003534 final Rect cf = mTmpContentFrame;
3535 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04003536 final Rect dcf = mTmpDecorFrame;
Adrian Roosfa104232014-06-20 16:10:14 -07003537 final Rect sf = mTmpStableFrame;
John Spurlock46646232013-09-30 22:32:42 -04003538 dcf.setEmpty();
Craig Mautner69b08182012-09-05 13:07:13 -07003539
3540 final boolean hasNavBar = (isDefaultDisplay && mHasNavigationBar
Daniel Sandler36412a72011-08-04 09:35:13 -04003541 && mNavigationBar != null && mNavigationBar.isVisibleLw());
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003542
Craig Mautnerf683b562012-10-02 11:10:57 -07003543 final int adjust = sim & SOFT_INPUT_MASK_ADJUST;
3544
Adrian Roosfa104232014-06-20 16:10:14 -07003545 if (isDefaultDisplay) {
3546 sf.set(mStableLeft, mStableTop, mStableRight, mStableBottom);
3547 } else {
3548 sf.set(mOverscanLeft, mOverscanTop, mOverscanRight, mOverscanBottom);
3549 }
3550
Craig Mautner69b08182012-09-05 13:07:13 -07003551 if (!isDefaultDisplay) {
3552 if (attached != null) {
3553 // If this window is attached to another, our display
3554 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003555 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07003556 } else {
3557 // Give the window full screen.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003558 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3559 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3560 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08003561 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003562 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003563 = mOverscanScreenTop + mOverscanScreenHeight;
Craig Mautner69b08182012-09-05 13:07:13 -07003564 }
Dianne Hackbornae6688b2015-02-11 17:02:41 -08003565 } else if (attrs.type == TYPE_INPUT_METHOD || attrs.type == TYPE_VOICE_INTERACTION) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003566 pf.left = df.left = of.left = cf.left = vf.left = mDockLeft;
3567 pf.top = df.top = of.top = cf.top = vf.top = mDockTop;
3568 pf.right = df.right = of.right = cf.right = vf.right = mDockRight;
John Spurlockc68d5772013-10-08 11:47:58 -04003569 // IM dock windows layout below the nav bar...
John Spurlock57beb3b2013-10-10 10:27:44 -04003570 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlockc68d5772013-10-08 11:47:58 -04003571 // ...with content insets above the nav bar
3572 cf.bottom = vf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003573 // IM dock windows always go to the bottom of the screen.
3574 attrs.gravity = Gravity.BOTTOM;
3575 mDockLayer = win.getSurfaceLayer();
Jorim Jaggie0700182014-08-21 01:12:37 +02003576 } else if (win == mStatusBar && (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
3577 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3578 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3579 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
3580 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight + mUnrestrictedScreenTop;
3581 cf.left = vf.left = mStableLeft;
3582 cf.top = vf.top = mStableTop;
3583 cf.right = vf.right = mStableRight;
3584 vf.bottom = mStableBottom;
3585 cf.bottom = mContentBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003586 } else {
John Spurlock46646232013-09-30 22:32:42 -04003587
3588 // Default policy decor for the default display
3589 dcf.left = mSystemLeft;
3590 dcf.top = mSystemTop;
3591 dcf.right = mSystemRight;
3592 dcf.bottom = mSystemBottom;
John Spurlockbd957402013-10-03 11:38:39 -04003593 final boolean inheritTranslucentDecor = (attrs.privateFlags
3594 & WindowManager.LayoutParams.PRIVATE_FLAG_INHERIT_TRANSLUCENT_DECOR) != 0;
John Spurlock65567d42013-10-08 10:08:32 -04003595 final boolean isAppWindow =
3596 attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW &&
3597 attrs.type <= WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
3598 final boolean topAtRest =
3599 win == mTopFullscreenOpaqueWindowState && !win.isAnimatingLw();
3600 if (isAppWindow && !inheritTranslucentDecor && !topAtRest) {
John Spurlockbd957402013-10-03 11:38:39 -04003601 if ((sysUiFl & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0
3602 && (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0
Adrian Roosea562512014-05-05 13:33:03 +02003603 && (fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) == 0
3604 && (fl & WindowManager.LayoutParams.
3605 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04003606 // Ensure policy decor includes status bar
3607 dcf.top = mStableTop;
3608 }
John Spurlockbd957402013-10-03 11:38:39 -04003609 if ((fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) == 0
Adrian Roosea562512014-05-05 13:33:03 +02003610 && (sysUiFl & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0
3611 && (fl & WindowManager.LayoutParams.
3612 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04003613 // Ensure policy decor includes navigation bar
3614 dcf.bottom = mStableBottom;
3615 dcf.right = mStableRight;
3616 }
3617 }
3618
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003619 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
3620 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
RoboErik8a2cfc32014-05-16 11:19:38 -07003621 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003622 + "): IN_SCREEN, INSET_DECOR");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003623 // This is the case for a normal activity window: we want it
3624 // to cover all of the screen space, and it can take care of
3625 // moving its contents to account for screen decorations that
3626 // intrude into that space.
3627 if (attached != null) {
3628 // If this window is attached to another, our display
3629 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003630 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003631 } else {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003632 if (attrs.type == TYPE_STATUS_BAR_PANEL
3633 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Joe Onorato29fc2c92010-11-24 10:26:50 -08003634 // Status bar panels are the only windows who can go on top of
3635 // the status bar. They are protected by the STATUS_BAR_SERVICE
3636 // permission, so they have the same privileges as the status
3637 // bar itself.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003638 //
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003639 // However, they should still dodge the navigation bar if it exists.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003640
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003641 pf.left = df.left = of.left = hasNavBar
3642 ? mDockLeft : mUnrestrictedScreenLeft;
3643 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3644 pf.right = df.right = of.right = hasNavBar
3645 ? mRestrictedScreenLeft+mRestrictedScreenWidth
3646 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3647 pf.bottom = df.bottom = of.bottom = hasNavBar
3648 ? mRestrictedScreenTop+mRestrictedScreenHeight
3649 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003650
Craig Mautnereda67292013-04-28 13:50:14 -07003651 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003652 "Laying out status bar window: (%d,%d - %d,%d)",
3653 pf.left, pf.top, pf.right, pf.bottom));
John Spurlock46646232013-09-30 22:32:42 -04003654 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08003655 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3656 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3657 // Asking to layout into the overscan region, so give it that pure
3658 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003659 pf.left = df.left = of.left = mOverscanScreenLeft;
3660 pf.top = df.top = of.top = mOverscanScreenTop;
3661 pf.right = df.right = of.right = mOverscanScreenLeft + mOverscanScreenWidth;
3662 pf.bottom = df.bottom = of.bottom = mOverscanScreenTop
3663 + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003664 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003665 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003666 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3667 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003668 // Asking for layout as if the nav bar is hidden, lets the
Dianne Hackbornc652de82013-02-15 16:32:56 -08003669 // application extend into the unrestricted overscan screen area. We
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003670 // only do this for application windows to ensure no window that
3671 // can be above the nav bar can do this.
Dianne Hackborn313440842013-02-19 19:22:59 -08003672 pf.left = df.left = mOverscanScreenLeft;
3673 pf.top = df.top = mOverscanScreenTop;
3674 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
3675 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003676 // We need to tell the app about where the frame inside the overscan
3677 // is, so it can inset its content by that amount -- it didn't ask
3678 // to actually extend itself into the overscan region.
3679 of.left = mUnrestrictedScreenLeft;
3680 of.top = mUnrestrictedScreenTop;
3681 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3682 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003683 } else {
Dianne Hackborn313440842013-02-19 19:22:59 -08003684 pf.left = df.left = mRestrictedOverscanScreenLeft;
3685 pf.top = df.top = mRestrictedOverscanScreenTop;
3686 pf.right = df.right = mRestrictedOverscanScreenLeft
3687 + mRestrictedOverscanScreenWidth;
3688 pf.bottom = df.bottom = mRestrictedOverscanScreenTop
3689 + mRestrictedOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003690 // We need to tell the app about where the frame inside the overscan
3691 // is, so it can inset its content by that amount -- it didn't ask
3692 // to actually extend itself into the overscan region.
3693 of.left = mUnrestrictedScreenLeft;
3694 of.top = mUnrestrictedScreenTop;
3695 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3696 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003697 }
Craig Mautner69b08182012-09-05 13:07:13 -07003698
John Spurlock46646232013-09-30 22:32:42 -04003699 if ((fl & FLAG_FULLSCREEN) == 0) {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003700 if (win.isVoiceInteraction()) {
3701 cf.left = mVoiceContentLeft;
3702 cf.top = mVoiceContentTop;
3703 cf.right = mVoiceContentRight;
3704 cf.bottom = mVoiceContentBottom;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003705 } else {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003706 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
3707 cf.left = mDockLeft;
3708 cf.top = mDockTop;
3709 cf.right = mDockRight;
3710 cf.bottom = mDockBottom;
3711 } else {
3712 cf.left = mContentLeft;
3713 cf.top = mContentTop;
3714 cf.right = mContentRight;
3715 cf.bottom = mContentBottom;
3716 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003717 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003718 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003719 // Full screen windows are always given a layout that is as if the
3720 // status bar and other transient decors are gone. This is to avoid
3721 // bad states when moving from a window that is not hding the
3722 // status bar to one that is.
3723 cf.left = mRestrictedScreenLeft;
3724 cf.top = mRestrictedScreenTop;
3725 cf.right = mRestrictedScreenLeft + mRestrictedScreenWidth;
3726 cf.bottom = mRestrictedScreenTop + mRestrictedScreenHeight;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003727 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003728 applyStableConstraints(sysUiFl, fl, cf);
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003729 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3730 vf.left = mCurLeft;
3731 vf.top = mCurTop;
3732 vf.right = mCurRight;
3733 vf.bottom = mCurBottom;
3734 } else {
3735 vf.set(cf);
3736 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003737 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003738 } else if ((fl & FLAG_LAYOUT_IN_SCREEN) != 0 || (sysUiFl
3739 & (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
3740 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)) != 0) {
Craig Mautnereda67292013-04-28 13:50:14 -07003741 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3742 "): IN_SCREEN");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003743 // A window that has requested to fill the entire screen just
3744 // gets everything, period.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003745 if (attrs.type == TYPE_STATUS_BAR_PANEL
3746 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003747 pf.left = df.left = of.left = cf.left = hasNavBar
3748 ? mDockLeft : mUnrestrictedScreenLeft;
3749 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
3750 pf.right = df.right = of.right = cf.right = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003751 ? mRestrictedScreenLeft+mRestrictedScreenWidth
Dianne Hackbornc652de82013-02-15 16:32:56 -08003752 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003753 pf.bottom = df.bottom = of.bottom = cf.bottom = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003754 ? mRestrictedScreenTop+mRestrictedScreenHeight
Dianne Hackbornc652de82013-02-15 16:32:56 -08003755 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07003756 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler36412a72011-08-04 09:35:13 -04003757 "Laying out IN_SCREEN status bar window: (%d,%d - %d,%d)",
3758 pf.left, pf.top, pf.right, pf.bottom));
Jim Millere898ac52012-04-06 17:10:57 -07003759 } else if (attrs.type == TYPE_NAVIGATION_BAR
3760 || attrs.type == TYPE_NAVIGATION_BAR_PANEL) {
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003761 // The navigation bar has Real Ultimate Power.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003762 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3763 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3764 pf.right = df.right = of.right = mUnrestrictedScreenLeft
3765 + mUnrestrictedScreenWidth;
3766 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop
3767 + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07003768 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003769 "Laying out navigation bar window: (%d,%d - %d,%d)",
3770 pf.left, pf.top, pf.right, pf.bottom));
Dianne Hackborn01011c32012-02-21 13:54:21 -08003771 } else if ((attrs.type == TYPE_SECURE_SYSTEM_OVERLAY
3772 || attrs.type == TYPE_BOOT_PROGRESS)
Jeff Brownbfcb60a2011-09-08 18:51:14 -07003773 && ((fl & FLAG_FULLSCREEN) != 0)) {
3774 // Fullscreen secure system overlays get what they ask for.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003775 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3776 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3777 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
3778 + mOverscanScreenWidth;
3779 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
3780 + mOverscanScreenHeight;
Craig Mautner165be0c2015-01-27 15:16:58 -08003781 } else if (attrs.type == TYPE_BOOT_PROGRESS) {
Dianne Hackborn01011c32012-02-21 13:54:21 -08003782 // Boot progress screen always covers entire display.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003783 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3784 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3785 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
3786 + mOverscanScreenWidth;
3787 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
3788 + mOverscanScreenHeight;
John Spurlockef4adae2013-08-26 17:58:58 -04003789 } else if (attrs.type == TYPE_WALLPAPER) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07003790 // The wallpaper also has Real Ultimate Power, but we want to tell
3791 // it about the overscan area.
3792 pf.left = df.left = mOverscanScreenLeft;
3793 pf.top = df.top = mOverscanScreenTop;
3794 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
3795 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
3796 of.left = cf.left = mUnrestrictedScreenLeft;
3797 of.top = cf.top = mUnrestrictedScreenTop;
3798 of.right = cf.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3799 of.bottom = cf.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlock46646232013-09-30 22:32:42 -04003800 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08003801 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3802 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3803 // Asking to layout into the overscan region, so give it that pure
3804 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003805 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3806 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3807 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08003808 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003809 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003810 = mOverscanScreenTop + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003811 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003812 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Craig Mautnerbeac1062014-06-03 14:38:57 -07003813 && (attrs.type == TYPE_STATUS_BAR
3814 || attrs.type == TYPE_TOAST
John Spurlock34e13d92013-08-10 06:52:28 -04003815 || (attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3816 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW))) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003817 // Asking for layout as if the nav bar is hidden, lets the
3818 // application extend into the unrestricted screen area. We
John Spurlock34e13d92013-08-10 06:52:28 -04003819 // only do this for application windows (or toasts) to ensure no window that
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003820 // can be above the nav bar can do this.
3821 // XXX This assumes that an app asking for this will also
3822 // ask for layout in only content. We can't currently figure out
3823 // what the screen would be if only laying out to hide the nav bar.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003824 pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft;
3825 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
3826 pf.right = df.right = of.right = cf.right = mUnrestrictedScreenLeft
3827 + mUnrestrictedScreenWidth;
3828 pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop
3829 + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003830 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003831 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
3832 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
3833 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
3834 + mRestrictedScreenWidth;
3835 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
3836 + mRestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003837 }
Craig Mautner69b08182012-09-05 13:07:13 -07003838
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003839 applyStableConstraints(sysUiFl, fl, cf);
Craig Mautner69b08182012-09-05 13:07:13 -07003840
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003841 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3842 vf.left = mCurLeft;
3843 vf.top = mCurTop;
3844 vf.right = mCurRight;
3845 vf.bottom = mCurBottom;
3846 } else {
3847 vf.set(cf);
3848 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003849 } else if (attached != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07003850 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3851 "): attached to " + attached);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003852 // A child window should be placed inside of the same visible
3853 // frame that its parent had.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003854 setAttachedWindowFrames(win, fl, adjust, attached, false, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003855 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07003856 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3857 "): normal window");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003858 // Otherwise, a normal window must be placed inside the content
3859 // of all screen decorations.
Dianne Hackborna239c842011-06-01 12:28:20 -07003860 if (attrs.type == TYPE_STATUS_BAR_PANEL) {
3861 // Status bar panels are the only windows who can go on top of
3862 // the status bar. They are protected by the STATUS_BAR_SERVICE
3863 // permission, so they have the same privileges as the status
3864 // bar itself.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003865 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
3866 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
3867 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
3868 + mRestrictedScreenWidth;
3869 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
3870 + mRestrictedScreenHeight;
John Spurlock414c1f02013-12-04 13:47:36 -05003871 } else if (attrs.type == TYPE_TOAST || attrs.type == TYPE_SYSTEM_ALERT
3872 || attrs.type == TYPE_VOLUME_OVERLAY) {
3873 // These dialogs are stable to interim decor changes.
John Spurlockbd957402013-10-03 11:38:39 -04003874 pf.left = df.left = of.left = cf.left = mStableLeft;
3875 pf.top = df.top = of.top = cf.top = mStableTop;
3876 pf.right = df.right = of.right = cf.right = mStableRight;
3877 pf.bottom = df.bottom = of.bottom = cf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003878 } else {
Dianne Hackborna239c842011-06-01 12:28:20 -07003879 pf.left = mContentLeft;
3880 pf.top = mContentTop;
3881 pf.right = mContentRight;
3882 pf.bottom = mContentBottom;
Dianne Hackborn20d94742014-05-29 18:35:45 -07003883 if (win.isVoiceInteraction()) {
3884 df.left = of.left = cf.left = mVoiceContentLeft;
3885 df.top = of.top = cf.top = mVoiceContentTop;
3886 df.right = of.right = cf.right = mVoiceContentRight;
3887 df.bottom = of.bottom = cf.bottom = mVoiceContentBottom;
3888 } else if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003889 df.left = of.left = cf.left = mDockLeft;
3890 df.top = of.top = cf.top = mDockTop;
3891 df.right = of.right = cf.right = mDockRight;
3892 df.bottom = of.bottom = cf.bottom = mDockBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07003893 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003894 df.left = of.left = cf.left = mContentLeft;
3895 df.top = of.top = cf.top = mContentTop;
3896 df.right = of.right = cf.right = mContentRight;
3897 df.bottom = of.bottom = cf.bottom = mContentBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07003898 }
3899 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3900 vf.left = mCurLeft;
3901 vf.top = mCurTop;
3902 vf.right = mCurRight;
3903 vf.bottom = mCurBottom;
3904 } else {
3905 vf.set(cf);
3906 }
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003907 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003908 }
3909 }
Craig Mautner69b08182012-09-05 13:07:13 -07003910
Craig Mautnerb816bed2013-07-23 10:26:17 -07003911 // TYPE_SYSTEM_ERROR is above the NavigationBar so it can't be allowed to extend over it.
3912 if ((fl & FLAG_LAYOUT_NO_LIMITS) != 0 && attrs.type != TYPE_SYSTEM_ERROR) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07003913 df.left = df.top = -10000;
3914 df.right = df.bottom = 10000;
3915 if (attrs.type != TYPE_WALLPAPER) {
3916 of.left = of.top = cf.left = cf.top = vf.left = vf.top = -10000;
3917 of.right = of.bottom = cf.right = cf.bottom = vf.right = vf.bottom = 10000;
3918 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003919 }
3920
Craig Mautnereda67292013-04-28 13:50:14 -07003921 if (DEBUG_LAYOUT) Slog.v(TAG, "Compute frame " + attrs.getTitle()
The Android Open Source Project11267662009-03-18 17:39:47 -07003922 + ": sim=#" + Integer.toHexString(sim)
RoboErik8a2cfc32014-05-16 11:19:38 -07003923 + " attach=" + attached + " type=" + attrs.type
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003924 + String.format(" flags=0x%08x", fl)
The Android Open Source Project11267662009-03-18 17:39:47 -07003925 + " pf=" + pf.toShortString() + " df=" + df.toShortString()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003926 + " of=" + of.toShortString()
John Spurlock46646232013-09-30 22:32:42 -04003927 + " cf=" + cf.toShortString() + " vf=" + vf.toShortString()
Adrian Roosfa104232014-06-20 16:10:14 -07003928 + " dcf=" + dcf.toShortString()
3929 + " sf=" + sf.toShortString());
Craig Mautner69b08182012-09-05 13:07:13 -07003930
Adrian Roosfa104232014-06-20 16:10:14 -07003931 win.computeFrameLw(pf, df, of, cf, vf, dcf, sf);
Craig Mautner69b08182012-09-05 13:07:13 -07003932
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003933 // Dock windows carve out the bottom of the screen, so normal windows
3934 // can't appear underneath them.
Craig Mautner8bd206b2012-10-03 10:32:02 -07003935 if (attrs.type == TYPE_INPUT_METHOD && win.isVisibleOrBehindKeyguardLw()
3936 && !win.getGivenInsetsPendingLw()) {
satok1bc0a492012-04-25 22:47:12 +09003937 setLastInputMethodWindowLw(null, null);
3938 offsetInputMethodWindowLw(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003939 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003940 if (attrs.type == TYPE_VOICE_INTERACTION && win.isVisibleOrBehindKeyguardLw()
3941 && !win.getGivenInsetsPendingLw()) {
3942 offsetVoiceInputWindowLw(win);
3943 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003944 }
3945
satok1bc0a492012-04-25 22:47:12 +09003946 private void offsetInputMethodWindowLw(WindowState win) {
Dianne Hackbornae6688b2015-02-11 17:02:41 -08003947 int top = win.getDisplayFrameLw().top;
satok1bc0a492012-04-25 22:47:12 +09003948 top += win.getGivenContentInsetsLw().top;
3949 if (mContentBottom > top) {
3950 mContentBottom = top;
3951 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003952 if (mVoiceContentBottom > top) {
3953 mVoiceContentBottom = top;
3954 }
satok1bc0a492012-04-25 22:47:12 +09003955 top = win.getVisibleFrameLw().top;
3956 top += win.getGivenVisibleInsetsLw().top;
3957 if (mCurBottom > top) {
3958 mCurBottom = top;
3959 }
Craig Mautnereda67292013-04-28 13:50:14 -07003960 if (DEBUG_LAYOUT) Slog.v(TAG, "Input method: mDockBottom="
satok1bc0a492012-04-25 22:47:12 +09003961 + mDockBottom + " mContentBottom="
3962 + mContentBottom + " mCurBottom=" + mCurBottom);
3963 }
3964
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003965 private void offsetVoiceInputWindowLw(WindowState win) {
Dianne Hackbornae6688b2015-02-11 17:02:41 -08003966 int top = win.getDisplayFrameLw().top;
3967 top += win.getGivenContentInsetsLw().top;
3968 if (mVoiceContentBottom > top) {
3969 mVoiceContentBottom = top;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003970 }
3971 }
3972
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003973 /** {@inheritDoc} */
Craig Mautner61ac6bb2012-02-02 17:29:33 -08003974 @Override
3975 public void finishLayoutLw() {
3976 return;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003977 }
3978
3979 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003980 @Override
Craig Mautner39834192012-09-02 07:47:24 -07003981 public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) {
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003982 mTopFullscreenOpaqueWindowState = null;
Adrian Rooscd3884d2015-02-18 17:25:23 +01003983 mTopFullscreenOpaqueOrDimmingWindowState = null;
Craig Mautner2bc789b2014-03-19 19:48:38 -07003984 mAppsToBeHidden.clear();
Jorim Jaggic13fcac2014-09-11 17:36:57 +02003985 mAppsThatDismissKeyguard.clear();
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003986 mForceStatusBar = false;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003987 mForceStatusBarFromKeyguard = false;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08003988 mForcingShowNavBar = false;
3989 mForcingShowNavBarLayer = -1;
RoboErik8a2cfc32014-05-16 11:19:38 -07003990
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003991 mHideLockScreen = false;
3992 mAllowLockscreenWhenOn = false;
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003993 mDismissKeyguard = DISMISS_KEYGUARD_NONE;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003994 mShowingLockscreen = false;
3995 mShowingDream = false;
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003996 mWinShowWhenLocked = null;
Jim Millerab954542014-10-10 18:21:49 -07003997 mKeyguardSecure = isKeyguardSecure();
3998 mKeyguardSecureIncludingHidden = mKeyguardSecure
3999 && (mKeyguardDelegate != null && mKeyguardDelegate.isShowing());
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004000 }
4001
4002 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004003 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004004 public void applyPostLayoutPolicyLw(WindowState win, WindowManager.LayoutParams attrs) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004005 if (DEBUG_LAYOUT) Slog.i(TAG, "Win " + win + ": isVisibleOrBehindKeyguardLw="
4006 + win.isVisibleOrBehindKeyguardLw());
John Spurlockc6d1c602014-01-17 15:22:06 -05004007 final int fl = PolicyControl.getWindowFlags(win, attrs);
John Spurlock414c1f02013-12-04 13:47:36 -05004008 if (mTopFullscreenOpaqueWindowState == null
4009 && win.isVisibleLw() && attrs.type == TYPE_INPUT_METHOD) {
4010 mForcingShowNavBar = true;
4011 mForcingShowNavBarLayer = win.getSurfaceLayer();
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08004012 }
Jorim Jaggiafd4a552014-04-08 15:13:05 +02004013 if (attrs.type == TYPE_STATUS_BAR && (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Jorim Jaggiafd4a552014-04-08 15:13:05 +02004014 mForceStatusBarFromKeyguard = true;
4015 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004016 if (mTopFullscreenOpaqueWindowState == null &&
Dianne Hackborn01b02a72012-01-12 14:05:03 -08004017 win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()) {
John Spurlockc6d1c602014-01-17 15:22:06 -05004018 if ((fl & FLAG_FORCE_NOT_FULLSCREEN) != 0) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004019 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004020 mForceStatusBarFromKeyguard = true;
4021 } else {
4022 mForceStatusBar = true;
4023 }
4024 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004025 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004026 mShowingLockscreen = true;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004027 }
Craig Mautnerab55e522014-03-03 13:26:03 -08004028 boolean appWindow = attrs.type >= FIRST_APPLICATION_WINDOW
Craig Mautner7d7808f2014-09-11 18:02:38 -07004029 && attrs.type < FIRST_SYSTEM_WINDOW;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004030 if (attrs.type == TYPE_DREAM) {
Jeff Brownc8018eb2012-10-29 21:33:27 -07004031 // If the lockscreen was showing when the dream started then wait
4032 // for the dream to draw before hiding the lockscreen.
4033 if (!mDreamingLockscreen
4034 || (win.isVisibleLw() && win.hasDrawnLw())) {
4035 mShowingDream = true;
Craig Mautnerab55e522014-03-03 13:26:03 -08004036 appWindow = true;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004037 }
4038 }
Craig Mautnerab55e522014-03-03 13:26:03 -08004039
Craig Mautner00156ec2014-03-06 22:29:02 -08004040 final boolean showWhenLocked = (fl & FLAG_SHOW_WHEN_LOCKED) != 0;
Craig Mautner74ee9382014-04-01 15:20:16 -07004041 final boolean dismissKeyguard = (fl & FLAG_DISMISS_KEYGUARD) != 0;
Craig Mautnerab55e522014-03-03 13:26:03 -08004042 if (appWindow) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004043 final IApplicationToken appToken = win.getAppToken();
4044 if (showWhenLocked) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004045 // Remove any previous windows with the same appToken.
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004046 mAppsToBeHidden.remove(appToken);
4047 mAppsThatDismissKeyguard.remove(appToken);
Craig Mautnerca0a1242014-12-02 12:25:14 -08004048 if (mAppsToBeHidden.isEmpty()) {
Craig Mautner192d6042014-12-02 23:24:48 -08004049 if (dismissKeyguard && !mKeyguardSecure) {
4050 mAppsThatDismissKeyguard.add(appToken);
4051 } else {
Craig Mautnerca0a1242014-12-02 12:25:14 -08004052 mWinShowWhenLocked = win;
4053 mHideLockScreen = true;
4054 mForceStatusBarFromKeyguard = false;
Craig Mautnerca0a1242014-12-02 12:25:14 -08004055 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004056 }
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004057 } else if (dismissKeyguard) {
Jim Millerab954542014-10-10 18:21:49 -07004058 if (mKeyguardSecure) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004059 mAppsToBeHidden.add(appToken);
4060 } else {
4061 mAppsToBeHidden.remove(appToken);
4062 }
4063 mAppsThatDismissKeyguard.add(appToken);
Craig Mautner2bc789b2014-03-19 19:48:38 -07004064 } else {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004065 mAppsToBeHidden.add(appToken);
Craig Mautner2bc789b2014-03-19 19:48:38 -07004066 }
Craig Mautnerab55e522014-03-03 13:26:03 -08004067 if (attrs.x == 0 && attrs.y == 0
4068 && attrs.width == WindowManager.LayoutParams.MATCH_PARENT
4069 && attrs.height == WindowManager.LayoutParams.MATCH_PARENT) {
4070 if (DEBUG_LAYOUT) Slog.v(TAG, "Fullscreen window: " + win);
4071 mTopFullscreenOpaqueWindowState = win;
Adrian Rooscd3884d2015-02-18 17:25:23 +01004072 if (mTopFullscreenOpaqueOrDimmingWindowState == null) {
4073 mTopFullscreenOpaqueOrDimmingWindowState = win;
4074 }
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004075 if (!mAppsThatDismissKeyguard.isEmpty() &&
4076 mDismissKeyguard == DISMISS_KEYGUARD_NONE) {
4077 if (DEBUG_LAYOUT) Slog.v(TAG,
4078 "Setting mDismissKeyguard true by win " + win);
4079 mDismissKeyguard = mWinDismissingKeyguard == win ?
4080 DISMISS_KEYGUARD_CONTINUE : DISMISS_KEYGUARD_START;
4081 mWinDismissingKeyguard = win;
Jim Millerab954542014-10-10 18:21:49 -07004082 mForceStatusBarFromKeyguard = mShowingLockscreen && mKeyguardSecure;
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004083 } else if (mAppsToBeHidden.isEmpty() && showWhenLocked) {
4084 if (DEBUG_LAYOUT) Slog.v(TAG,
4085 "Setting mHideLockScreen to true by win " + win);
4086 mHideLockScreen = true;
4087 mForceStatusBarFromKeyguard = false;
Craig Mautnerab55e522014-03-03 13:26:03 -08004088 }
Craig Mautner00156ec2014-03-06 22:29:02 -08004089 if ((fl & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) {
Craig Mautnerab55e522014-03-03 13:26:03 -08004090 mAllowLockscreenWhenOn = true;
4091 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004092 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004093
4094 if (mWinShowWhenLocked != null &&
4095 mWinShowWhenLocked.getAppToken() != win.getAppToken()) {
4096 win.hideLw(false);
4097 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004098 }
4099 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01004100 if (mTopFullscreenOpaqueOrDimmingWindowState == null
4101 && win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()
4102 && win.isDimming()) {
4103 mTopFullscreenOpaqueOrDimmingWindowState = win;
4104 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004105 }
4106
4107 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004108 @Override
Craig Mautner39834192012-09-02 07:47:24 -07004109 public int finishPostLayoutPolicyLw() {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004110 if (mWinShowWhenLocked != null &&
4111 mWinShowWhenLocked != mTopFullscreenOpaqueWindowState) {
4112 // A dialog is dismissing the keyguard. Put the wallpaper behind it and hide the
4113 // fullscreen window.
4114 // TODO: Make sure FLAG_SHOW_WALLPAPER is restored when dialog is dismissed. Or not.
4115 mWinShowWhenLocked.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
4116 mTopFullscreenOpaqueWindowState.hideLw(false);
4117 mTopFullscreenOpaqueWindowState = mWinShowWhenLocked;
4118 }
4119
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004120 int changes = 0;
Joe Onorato93056472010-09-10 10:30:46 -04004121 boolean topIsFullscreen = false;
Daniel Sandlere02d8082010-10-08 15:13:22 -04004122
4123 final WindowManager.LayoutParams lp = (mTopFullscreenOpaqueWindowState != null)
4124 ? mTopFullscreenOpaqueWindowState.getAttrs()
4125 : null;
4126
Jeff Brownc8018eb2012-10-29 21:33:27 -07004127 // If we are not currently showing a dream then remember the current
4128 // lockscreen state. We will use this to determine whether the dream
4129 // started while the lockscreen was showing and remember this state
4130 // while the dream is showing.
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004131 if (!mShowingDream) {
4132 mDreamingLockscreen = mShowingLockscreen;
4133 }
4134
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004135 if (mStatusBar != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07004136 if (DEBUG_LAYOUT) Slog.i(TAG, "force=" + mForceStatusBar
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004137 + " forcefkg=" + mForceStatusBarFromKeyguard
Dianne Hackbornd70bc2f2009-10-06 23:25:51 -07004138 + " top=" + mTopFullscreenOpaqueWindowState);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004139 if (mForceStatusBar || mForceStatusBarFromKeyguard) {
Craig Mautnereda67292013-04-28 13:50:14 -07004140 if (DEBUG_LAYOUT) Slog.v(TAG, "Showing status bar: forced");
John Spurlock27735a42013-08-14 17:57:38 -04004141 if (mStatusBarController.setBarShowingLw(true)) {
4142 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4143 }
Craig Mautner81defc72013-10-29 11:10:42 -07004144 // Maintain fullscreen layout until incoming animation is complete.
4145 topIsFullscreen = mTopIsFullscreen && mStatusBar.isAnimatingLw();
John Spurlockf92b6162013-11-11 15:01:16 -05004146 // Transient status bar on the lockscreen is not allowed
4147 if (mForceStatusBarFromKeyguard && mStatusBarController.isTransientShowing()) {
4148 mStatusBarController.updateVisibilityLw(false /*transientAllowed*/,
4149 mLastSystemUiFlags, mLastSystemUiFlags);
4150 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004151 } else if (mTopFullscreenOpaqueWindowState != null) {
John Spurlockc6d1c602014-01-17 15:22:06 -05004152 final int fl = PolicyControl.getWindowFlags(null, lp);
Joe Onorato93056472010-09-10 10:30:46 -04004153 if (localLOGV) {
Craig Mautnereda67292013-04-28 13:50:14 -07004154 Slog.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw()
Joe Onorato93056472010-09-10 10:30:46 -04004155 + " shown frame: " + mTopFullscreenOpaqueWindowState.getShownFrameLw());
Craig Mautnereda67292013-04-28 13:50:14 -07004156 Slog.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs()
John Spurlockc6d1c602014-01-17 15:22:06 -05004157 + " lp.flags=0x" + Integer.toHexString(fl));
Joe Onorato93056472010-09-10 10:30:46 -04004158 }
John Spurlockc6d1c602014-01-17 15:22:06 -05004159 topIsFullscreen = (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004160 || (mLastSystemUiFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
Joe Onorato93056472010-09-10 10:30:46 -04004161 // The subtle difference between the window for mTopFullscreenOpaqueWindowState
Mark Dolinerd0646dc2014-08-27 16:04:02 -07004162 // and mTopIsFullscreen is that mTopIsFullscreen is set only if the window
Joe Onorato93056472010-09-10 10:30:46 -04004163 // has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the
4164 // case though.
John Spurlock27735a42013-08-14 17:57:38 -04004165 if (mStatusBarController.isTransientShowing()) {
4166 if (mStatusBarController.setBarShowingLw(true)) {
John Spurlock32beb2c2013-03-11 10:16:47 -04004167 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4168 }
4169 } else if (topIsFullscreen) {
Craig Mautnereda67292013-04-28 13:50:14 -07004170 if (DEBUG_LAYOUT) Slog.v(TAG, "** HIDING status bar");
John Spurlock27735a42013-08-14 17:57:38 -04004171 if (mStatusBarController.setBarShowingLw(false)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004172 changes |= FINISH_LAYOUT_REDO_LAYOUT;
Craig Mautnereda67292013-04-28 13:50:14 -07004173 } else {
Craig Mautnerc5a6e442013-06-05 17:22:35 -07004174 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar already hiding");
Daniel Sandler40427442010-07-16 11:44:52 -04004175 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004176 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07004177 if (DEBUG_LAYOUT) Slog.v(TAG, "** SHOWING status bar: top is not fullscreen");
John Spurlock27735a42013-08-14 17:57:38 -04004178 if (mStatusBarController.setBarShowingLw(true)) {
4179 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4180 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004181 }
4182 }
4183 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04004184
Craig Mautner81defc72013-10-29 11:10:42 -07004185 if (mTopIsFullscreen != topIsFullscreen) {
4186 if (!topIsFullscreen) {
4187 // Force another layout when status bar becomes fully shown.
4188 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4189 }
4190 mTopIsFullscreen = topIsFullscreen;
4191 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04004192
Craig Mautner39834192012-09-02 07:47:24 -07004193 // Hide the key guard if a visible window explicitly specifies that it wants to be
4194 // displayed when the screen is locked.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004195 if (mKeyguardDelegate != null && mStatusBar != null) {
4196 if (localLOGV) Slog.v(TAG, "finishPostLayoutPolicyLw: mHideKeyguard="
4197 + mHideLockScreen);
Jim Millerab954542014-10-10 18:21:49 -07004198 if (mDismissKeyguard != DISMISS_KEYGUARD_NONE && !mKeyguardSecure) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004199 mKeyguardHidden = true;
Jim Millerab954542014-10-10 18:21:49 -07004200 if (setKeyguardOccludedLw(true)) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004201 changes |= FINISH_LAYOUT_REDO_LAYOUT
4202 | FINISH_LAYOUT_REDO_CONFIG
4203 | FINISH_LAYOUT_REDO_WALLPAPER;
4204 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004205 if (mKeyguardDelegate.isShowing()) {
4206 mHandler.post(new Runnable() {
4207 @Override
4208 public void run() {
4209 mKeyguardDelegate.keyguardDone(false, false);
4210 }
4211 });
4212 }
4213 } else if (mHideLockScreen) {
4214 mKeyguardHidden = true;
Jim Millerab954542014-10-10 18:21:49 -07004215 if (setKeyguardOccludedLw(true)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004216 changes |= FINISH_LAYOUT_REDO_LAYOUT
4217 | FINISH_LAYOUT_REDO_CONFIG
4218 | FINISH_LAYOUT_REDO_WALLPAPER;
4219 }
4220 } else if (mDismissKeyguard != DISMISS_KEYGUARD_NONE) {
4221 // This is the case of keyguard isSecure() and not mHideLockScreen.
4222 if (mDismissKeyguard == DISMISS_KEYGUARD_START) {
4223 // Only launch the next keyguard unlock window once per window.
4224 mKeyguardHidden = false;
Jim Millerab954542014-10-10 18:21:49 -07004225 if (setKeyguardOccludedLw(false)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004226 changes |= FINISH_LAYOUT_REDO_LAYOUT
4227 | FINISH_LAYOUT_REDO_CONFIG
4228 | FINISH_LAYOUT_REDO_WALLPAPER;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004229 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004230 mHandler.post(new Runnable() {
4231 @Override
4232 public void run() {
4233 mKeyguardDelegate.dismiss();
4234 }
4235 });
4236 }
4237 } else {
4238 mWinDismissingKeyguard = null;
4239 mKeyguardHidden = false;
Jim Millerab954542014-10-10 18:21:49 -07004240 if (setKeyguardOccludedLw(false)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004241 changes |= FINISH_LAYOUT_REDO_LAYOUT
4242 | FINISH_LAYOUT_REDO_CONFIG
4243 | FINISH_LAYOUT_REDO_WALLPAPER;
4244 }
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -07004245 }
4246 }
Joe Onorato664644d2011-01-23 17:53:23 -08004247
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004248 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004249 // If the navigation bar has been hidden or shown, we need to do another
4250 // layout pass to update that window.
4251 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4252 }
Joe Onorato664644d2011-01-23 17:53:23 -08004253
Mike Lockwood28569302010-01-28 11:54:40 -05004254 // update since mAllowLockscreenWhenOn might have changed
4255 updateLockScreenTimeout();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004256 return changes;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004257 }
4258
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004259 /**
Jim Millerab954542014-10-10 18:21:49 -07004260 * Updates the occluded state of the Keyguard.
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004261 *
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004262 * @return Whether the flags have changed and we have to redo the layout.
4263 */
Jim Millerab954542014-10-10 18:21:49 -07004264 private boolean setKeyguardOccludedLw(boolean isOccluded) {
4265 boolean wasOccluded = mKeyguardOccluded;
4266 boolean showing = mKeyguardDelegate.isShowing();
4267 if (wasOccluded && !isOccluded && showing) {
4268 mKeyguardOccluded = false;
4269 mKeyguardDelegate.setOccluded(false);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004270 mStatusBar.getAttrs().privateFlags |= PRIVATE_FLAG_KEYGUARD;
4271 mStatusBar.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
4272 return true;
Jim Millerab954542014-10-10 18:21:49 -07004273 } else if (!wasOccluded && isOccluded && showing) {
4274 mKeyguardOccluded = true;
4275 mKeyguardDelegate.setOccluded(true);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004276 mStatusBar.getAttrs().privateFlags &= ~PRIVATE_FLAG_KEYGUARD;
4277 mStatusBar.getAttrs().flags &= ~FLAG_SHOW_WALLPAPER;
4278 return true;
4279 } else {
4280 return false;
4281 }
4282 }
4283
4284 private boolean isStatusBarKeyguard() {
4285 return mStatusBar != null
4286 && (mStatusBar.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
4287 }
4288
Jose Lima9546b202014-07-02 17:21:51 -07004289 @Override
Dianne Hackborn08743722009-12-21 12:16:51 -08004290 public boolean allowAppAnimationsLw() {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004291 if (isStatusBarKeyguard() || mShowingDream) {
Craig Mautner28816302013-10-10 20:31:00 -07004292 // If keyguard or dreams is currently visible, no reason to animate behind it.
Dianne Hackborn08743722009-12-21 12:16:51 -08004293 return false;
4294 }
Dianne Hackborn08743722009-12-21 12:16:51 -08004295 return true;
4296 }
4297
Jose Lima9546b202014-07-02 17:21:51 -07004298 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07004299 public int focusChangedLw(WindowState lastFocus, WindowState newFocus) {
Joe Onorato664644d2011-01-23 17:53:23 -08004300 mFocusedWindow = newFocus;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004301 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004302 // If the navigation bar has been hidden or shown, we need to do another
4303 // layout pass to update that window.
4304 return FINISH_LAYOUT_REDO_LAYOUT;
4305 }
4306 return 0;
Joe Onorato664644d2011-01-23 17:53:23 -08004307 }
4308
Dianne Hackborn0ecadf72009-03-31 18:00:37 -07004309 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07004310 @Override
Jeff Brown46b9ac02010-04-22 18:58:52 -07004311 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
4312 // lid changed state
Jeff Brownc458ce92012-04-30 14:58:40 -07004313 final int newLidState = lidOpen ? LID_OPEN : LID_CLOSED;
4314 if (newLidState == mLidState) {
4315 return;
4316 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004317
Jeff Brownc458ce92012-04-30 14:58:40 -07004318 mLidState = newLidState;
4319 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07004320 updateRotation(true);
Jeff Brownc458ce92012-04-30 14:58:40 -07004321
4322 if (lidOpen) {
Bryce Lee584a4452014-10-21 15:55:55 -07004323 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromLidSwitch);
Jeff Brownc458ce92012-04-30 14:58:40 -07004324 } else if (!mLidControlsSleep) {
Jeff Brown96307042012-07-27 15:51:34 -07004325 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
Jeff Brown46b9ac02010-04-22 18:58:52 -07004326 }
4327 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004328
Michael Wright3818c922014-09-02 13:59:07 -07004329 @Override
4330 public void notifyCameraLensCoverSwitchChanged(long whenNanos, boolean lensCovered) {
4331 int lensCoverState = lensCovered ? CAMERA_LENS_COVERED : CAMERA_LENS_UNCOVERED;
4332 if (mCameraLensCoverState == lensCoverState) {
4333 return;
4334 }
4335 if (mCameraLensCoverState == CAMERA_LENS_COVERED &&
4336 lensCoverState == CAMERA_LENS_UNCOVERED) {
4337 Intent intent;
4338 final boolean keyguardActive = mKeyguardDelegate == null ? false :
4339 mKeyguardDelegate.isShowing();
4340 if (keyguardActive) {
4341 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE);
4342 } else {
4343 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
4344 }
Bryce Lee584a4452014-10-21 15:55:55 -07004345 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromCameraLens);
Michael Wright3818c922014-09-02 13:59:07 -07004346 mContext.startActivityAsUser(intent, UserHandle.CURRENT_OR_SELF);
4347 }
4348 mCameraLensCoverState = lensCoverState;
4349 }
4350
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004351 void setHdmiPlugged(boolean plugged) {
4352 if (mHdmiPlugged != plugged) {
4353 mHdmiPlugged = plugged;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004354 updateRotation(true, true);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004355 Intent intent = new Intent(ACTION_HDMI_PLUGGED);
Joe Onoratodc100302011-01-11 17:07:41 -08004356 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004357 intent.putExtra(EXTRA_HDMI_PLUGGED_STATE, plugged);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07004358 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004359 }
4360 }
4361
Joe Onoratoea495d42011-04-06 11:41:11 -07004362 void initializeHdmiState() {
Joe Onorato7ba631f2011-05-04 15:28:00 -07004363 boolean plugged = false;
Joe Onoratoea495d42011-04-06 11:41:11 -07004364 // watch for HDMI plug messages if the hdmi switch exists
4365 if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) {
4366 mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi");
4367
Joe Onoratoea495d42011-04-06 11:41:11 -07004368 final String filename = "/sys/class/switch/hdmi/state";
4369 FileReader reader = null;
4370 try {
4371 reader = new FileReader(filename);
4372 char[] buf = new char[15];
4373 int n = reader.read(buf);
4374 if (n > 1) {
4375 plugged = 0 != Integer.parseInt(new String(buf, 0, n-1));
4376 }
4377 } catch (IOException ex) {
4378 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
4379 } catch (NumberFormatException ex) {
4380 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
4381 } finally {
4382 if (reader != null) {
4383 try {
4384 reader.close();
4385 } catch (IOException ex) {
4386 }
Joe Onoratodc100302011-01-11 17:07:41 -08004387 }
4388 }
4389 }
Joe Onorato7ba631f2011-05-04 15:28:00 -07004390 // This dance forces the code in setHdmiPlugged to run.
4391 // Always do this so the sticky intent is stuck (to false) if there is no hdmi.
4392 mHdmiPlugged = !plugged;
4393 setHdmiPlugged(!mHdmiPlugged);
Joe Onoratodc100302011-01-11 17:07:41 -08004394 }
4395
Dianne Hackbornc0e3f242011-08-19 14:19:10 -07004396 final Object mScreenshotLock = new Object();
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004397 ServiceConnection mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004398
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004399 final Runnable mScreenshotTimeout = new Runnable() {
4400 @Override public void run() {
4401 synchronized (mScreenshotLock) {
4402 if (mScreenshotConnection != null) {
4403 mContext.unbindService(mScreenshotConnection);
4404 mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004405 }
Winson Chung9112ec32011-06-27 13:15:32 -07004406 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004407 }
4408 };
4409
4410 // Assume this is called from the Handler thread.
4411 private void takeScreenshot() {
4412 synchronized (mScreenshotLock) {
4413 if (mScreenshotConnection != null) {
4414 return;
4415 }
4416 ComponentName cn = new ComponentName("com.android.systemui",
4417 "com.android.systemui.screenshot.TakeScreenshotService");
4418 Intent intent = new Intent();
4419 intent.setComponent(cn);
4420 ServiceConnection conn = new ServiceConnection() {
4421 @Override
4422 public void onServiceConnected(ComponentName name, IBinder service) {
4423 synchronized (mScreenshotLock) {
4424 if (mScreenshotConnection != this) {
4425 return;
4426 }
4427 Messenger messenger = new Messenger(service);
4428 Message msg = Message.obtain(null, 1);
4429 final ServiceConnection myConn = this;
4430 Handler h = new Handler(mHandler.getLooper()) {
4431 @Override
4432 public void handleMessage(Message msg) {
4433 synchronized (mScreenshotLock) {
4434 if (mScreenshotConnection == myConn) {
4435 mContext.unbindService(mScreenshotConnection);
4436 mScreenshotConnection = null;
4437 mHandler.removeCallbacks(mScreenshotTimeout);
4438 }
4439 }
4440 }
4441 };
4442 msg.replyTo = new Messenger(h);
Winson Chunga63bb842011-10-17 10:26:28 -07004443 msg.arg1 = msg.arg2 = 0;
4444 if (mStatusBar != null && mStatusBar.isVisibleLw())
4445 msg.arg1 = 1;
4446 if (mNavigationBar != null && mNavigationBar.isVisibleLw())
4447 msg.arg2 = 1;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004448 try {
4449 messenger.send(msg);
4450 } catch (RemoteException e) {
4451 }
4452 }
4453 }
4454 @Override
4455 public void onServiceDisconnected(ComponentName name) {}
4456 };
Amith Yamasani27b89e62013-01-16 12:30:11 -08004457 if (mContext.bindServiceAsUser(
4458 intent, conn, Context.BIND_AUTO_CREATE, UserHandle.CURRENT)) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004459 mScreenshotConnection = conn;
4460 mHandler.postDelayed(mScreenshotTimeout, 10000);
4461 }
4462 }
Winson Chung9112ec32011-06-27 13:15:32 -07004463 }
4464
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004465 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004466 @Override
Jeff Brown037c33e2014-04-09 00:31:55 -07004467 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) {
Jeff Brown96307042012-07-27 15:51:34 -07004468 if (!mSystemBooted) {
4469 // If we have not yet booted, don't let key events do anything.
4470 return 0;
4471 }
4472
Jeff Brown037c33e2014-04-09 00:31:55 -07004473 final boolean interactive = (policyFlags & FLAG_INTERACTIVE) != 0;
Jeff Brown1f245102010-11-18 20:53:46 -08004474 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
4475 final boolean canceled = event.isCanceled();
4476 final int keyCode = event.getKeyCode();
Jeff Browne20c9e02010-10-11 14:20:19 -07004477
Jeff Brown3122e442010-10-11 23:32:49 -07004478 final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0;
Jeff Brown3122e442010-10-11 23:32:49 -07004479
Mike Lockwoodc72b15f2009-11-28 20:58:22 -05004480 // If screen is off then we treat the case where the keyguard is open but hidden
4481 // the same as if it were open and in front.
4482 // This will prevent any keys other than the power button from waking the screen
4483 // when the keyguard is hidden by another activity.
Jim Miller5ecd8112013-01-09 18:50:26 -08004484 final boolean keyguardActive = (mKeyguardDelegate == null ? false :
Jeff Brown037c33e2014-04-09 00:31:55 -07004485 (interactive ?
Jim Millerab954542014-10-10 18:21:49 -07004486 isKeyguardShowingAndNotOccluded() :
Jim Miller5ecd8112013-01-09 18:50:26 -08004487 mKeyguardDelegate.isShowing()));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004488
Jeff Brown40013652012-05-16 21:22:36 -07004489 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004490 Log.d(TAG, "interceptKeyTq keycode=" + keyCode
Jeff Brown037c33e2014-04-09 00:31:55 -07004491 + " interactive=" + interactive + " keyguardActive=" + keyguardActive
Jeff Brown26875502014-01-30 21:47:47 -08004492 + " policyFlags=" + Integer.toHexString(policyFlags));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004493 }
4494
Jeff Brown037c33e2014-04-09 00:31:55 -07004495 // Basic policy based on interactive state.
Jeff Brown4d396052010-10-29 21:50:21 -07004496 int result;
Michael Wright337d9d22014-04-22 15:03:48 -07004497 boolean isWakeKey = (policyFlags & WindowManagerPolicy.FLAG_WAKE) != 0
4498 || event.isWakeKey();
Michael Wrightfc01f042014-09-08 14:12:24 -07004499 if (interactive || (isInjected && !isWakeKey)) {
RoboErikde9ba392014-09-26 12:51:01 -07004500 // When the device is interactive or the key is injected pass the
4501 // key to the application.
Jeff Brown4d396052010-10-29 21:50:21 -07004502 result = ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07004503 isWakeKey = false;
Michael Wrightfc01f042014-09-08 14:12:24 -07004504 } else if (!interactive && shouldDispatchInputWhenNonInteractive()) {
4505 // If we're currently dozing with the screen on and the keyguard showing, pass the key
4506 // to the application but preserve its wake key status to make sure we still move
4507 // from dozing to fully interactive if we would normally go from off to fully
4508 // interactive.
4509 result = ACTION_PASS_TO_USER;
Jeff Brown4d396052010-10-29 21:50:21 -07004510 } else {
4511 // When the screen is off and the key is not injected, determine whether
4512 // to wake the device but don't pass the key to the application.
4513 result = 0;
Jeff Brown26875502014-01-30 21:47:47 -08004514 if (isWakeKey && (!down || !isWakeKeyWhenScreenOff(keyCode))) {
4515 isWakeKey = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004516 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004517 }
4518
Justin Kohd378ad72013-04-01 12:18:26 -07004519 // If the key would be handled globally, just return the result, don't worry about special
4520 // key processing.
Jeff Brown13f00f02014-10-31 14:45:50 -07004521 if (isValidGlobalKey(keyCode)
4522 && mGlobalKeyManager.shouldHandleGlobalKey(keyCode, event)) {
Michael Wright85b1af62014-06-04 14:51:58 -07004523 if (isWakeKey) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004524 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey);
Michael Wright85b1af62014-06-04 14:51:58 -07004525 }
Justin Kohd378ad72013-04-01 12:18:26 -07004526 return result;
4527 }
4528
Jeff Brownbae8e772014-06-12 19:59:45 -07004529 boolean useHapticFeedback = down
4530 && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0
4531 && event.getRepeatCount() == 0;
4532
Jeff Brown4d396052010-10-29 21:50:21 -07004533 // Handle special keys.
4534 switch (keyCode) {
4535 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jeff Brownb0418da2010-11-01 15:24:01 -07004536 case KeyEvent.KEYCODE_VOLUME_UP:
4537 case KeyEvent.KEYCODE_VOLUME_MUTE: {
RoboErik001c59c2015-01-26 15:53:51 -08004538 if (mUseTvRouting) {
4539 // On TVs volume keys never go to the foreground app
4540 result &= ~ACTION_PASS_TO_USER;
4541 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004542 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
4543 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004544 if (interactive && !mScreenshotChordVolumeDownKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004545 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004546 mScreenshotChordVolumeDownKeyTriggered = true;
4547 mScreenshotChordVolumeDownKeyTime = event.getDownTime();
4548 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004549 cancelPendingPowerKeyAction();
4550 interceptScreenshotChord();
4551 }
4552 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004553 mScreenshotChordVolumeDownKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004554 cancelPendingScreenshotChordAction();
4555 }
4556 } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
4557 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004558 if (interactive && !mScreenshotChordVolumeUpKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004559 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004560 mScreenshotChordVolumeUpKeyTriggered = true;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004561 cancelPendingPowerKeyAction();
4562 cancelPendingScreenshotChordAction();
4563 }
4564 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004565 mScreenshotChordVolumeUpKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004566 cancelPendingScreenshotChordAction();
4567 }
4568 }
Jeff Brown4d396052010-10-29 21:50:21 -07004569 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004570 TelecomManager telecomManager = getTelecommService();
4571 if (telecomManager != null) {
4572 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07004573 // If an incoming call is ringing, either VOLUME key means
4574 // "silence ringer". We handle these keys here, rather than
4575 // in the InCallScreen, to make sure we'll respond to them
4576 // even if the InCallScreen hasn't come to the foreground yet.
4577 // Look for the DOWN event here, to agree with the "fallback"
4578 // behavior in the InCallScreen.
4579 Log.i(TAG, "interceptKeyBeforeQueueing:"
4580 + " VOLUME key-down while ringing: Silence ringer!");
Jeff Brown4d396052010-10-29 21:50:21 -07004581
Santos Cordon6848f722014-05-21 15:22:12 -07004582 // Silence the ringer. (It's safe to call this
4583 // even if the ringer has already been silenced.)
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004584 telecomManager.silenceRinger();
Jeff Brown4d396052010-10-29 21:50:21 -07004585
Santos Cordon6848f722014-05-21 15:22:12 -07004586 // And *don't* pass this key thru to the current activity
4587 // (which is probably the InCallScreen.)
4588 result &= ~ACTION_PASS_TO_USER;
4589 break;
4590 }
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004591 if (telecomManager.isInCall()
Santos Cordon6848f722014-05-21 15:22:12 -07004592 && (result & ACTION_PASS_TO_USER) == 0) {
4593 // If we are in call but we decided not to pass the key to
RoboErik430fc482014-06-12 15:49:20 -07004594 // the application, just pass it to the session service.
4595
4596 MediaSessionLegacyHelper.getHelper(mContext)
RoboErik3c45c292014-07-08 16:47:31 -07004597 .sendVolumeKeyEvent(event, false);
Santos Cordon6848f722014-05-21 15:22:12 -07004598 break;
Jeff Brown4d396052010-10-29 21:50:21 -07004599 }
4600 }
4601
RoboErik430fc482014-06-12 15:49:20 -07004602 if ((result & ACTION_PASS_TO_USER) == 0) {
RoboErik001c59c2015-01-26 15:53:51 -08004603 if (mUseTvRouting) {
4604 dispatchDirectAudioEvent(event);
4605 } else {
4606 // If we aren't passing to the user and no one else
4607 // handled it send it to the session manager to
4608 // figure out.
4609 MediaSessionLegacyHelper.getHelper(mContext)
4610 .sendVolumeKeyEvent(event, true);
4611 }
Jeff Brown4d396052010-10-29 21:50:21 -07004612 break;
4613 }
4614 }
4615 break;
4616 }
4617
4618 case KeyEvent.KEYCODE_ENDCALL: {
4619 result &= ~ACTION_PASS_TO_USER;
4620 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004621 TelecomManager telecomManager = getTelecommService();
Jeff Brown4d396052010-10-29 21:50:21 -07004622 boolean hungUp = false;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004623 if (telecomManager != null) {
4624 hungUp = telecomManager.endCall();
Jeff Brown4d396052010-10-29 21:50:21 -07004625 }
Jeff Brown13f00f02014-10-31 14:45:50 -07004626 if (interactive && !hungUp) {
4627 mEndCallKeyHandled = false;
4628 mHandler.postDelayed(mEndCallLongPress,
4629 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
4630 } else {
4631 mEndCallKeyHandled = true;
4632 }
Jeff Brown4d396052010-10-29 21:50:21 -07004633 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004634 if (!mEndCallKeyHandled) {
4635 mHandler.removeCallbacks(mEndCallLongPress);
4636 if (!canceled) {
4637 if ((mEndcallBehavior
4638 & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) {
4639 if (goHome()) {
4640 break;
4641 }
Dianne Hackborn0041e972009-07-24 17:14:43 -07004642 }
Jeff Brown13f00f02014-10-31 14:45:50 -07004643 if ((mEndcallBehavior
4644 & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) {
4645 mPowerManager.goToSleep(event.getEventTime(),
4646 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
4647 isWakeKey = false;
4648 }
Jeff Brown4d396052010-10-29 21:50:21 -07004649 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004650 }
Jeff Brown4d396052010-10-29 21:50:21 -07004651 }
4652 break;
4653 }
4654
4655 case KeyEvent.KEYCODE_POWER: {
4656 result &= ~ACTION_PASS_TO_USER;
Jeff Brown13f00f02014-10-31 14:45:50 -07004657 isWakeKey = false; // wake-up will be handled separately
Jeff Brown4d396052010-10-29 21:50:21 -07004658 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004659 interceptPowerKeyDown(event, interactive);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004660 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004661 interceptPowerKeyUp(event, interactive, canceled);
Jeff Brown4d396052010-10-29 21:50:21 -07004662 }
4663 break;
4664 }
4665
Jeff Brown6212a492014-03-07 13:58:47 -08004666 case KeyEvent.KEYCODE_SLEEP: {
4667 result &= ~ACTION_PASS_TO_USER;
Jeff Brownbae8e772014-06-12 19:59:45 -07004668 if (!mPowerManager.isInteractive()) {
4669 useHapticFeedback = false; // suppress feedback if already non-interactive
4670 }
Jeff Brownc12035c2014-08-13 18:52:25 -07004671 mPowerManager.goToSleep(event.getEventTime(),
4672 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
Jeff Brown6212a492014-03-07 13:58:47 -08004673 isWakeKey = false;
4674 break;
4675 }
4676
4677 case KeyEvent.KEYCODE_WAKEUP: {
4678 result &= ~ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07004679 isWakeKey = true;
Jeff Brown6212a492014-03-07 13:58:47 -08004680 break;
4681 }
4682
Jeff Brown4d396052010-10-29 21:50:21 -07004683 case KeyEvent.KEYCODE_MEDIA_PLAY:
4684 case KeyEvent.KEYCODE_MEDIA_PAUSE:
4685 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
Jeff Brown4d396052010-10-29 21:50:21 -07004686 case KeyEvent.KEYCODE_HEADSETHOOK:
4687 case KeyEvent.KEYCODE_MUTE:
4688 case KeyEvent.KEYCODE_MEDIA_STOP:
4689 case KeyEvent.KEYCODE_MEDIA_NEXT:
4690 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
4691 case KeyEvent.KEYCODE_MEDIA_REWIND:
4692 case KeyEvent.KEYCODE_MEDIA_RECORD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09004693 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
4694 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: {
RoboErikde9ba392014-09-26 12:51:01 -07004695 if (MediaSessionLegacyHelper.getHelper(mContext).isGlobalPriorityActive()) {
4696 // If the global session is active pass all media keys to it
4697 // instead of the active window.
4698 result &= ~ACTION_PASS_TO_USER;
4699 }
Jeff Brown4d396052010-10-29 21:50:21 -07004700 if ((result & ACTION_PASS_TO_USER) == 0) {
4701 // Only do this if we would otherwise not pass it to the user. In that
4702 // case, the PhoneWindow class will do the same thing, except it will
4703 // only do it if the showing app doesn't process the key on its own.
Jeff Brown40013652012-05-16 21:22:36 -07004704 // Note that we need to make a copy of the key event here because the
4705 // original key event will be recycled when we return.
Jeff Brown4d396052010-10-29 21:50:21 -07004706 mBroadcastWakeLock.acquire();
Jeff Brown40013652012-05-16 21:22:36 -07004707 Message msg = mHandler.obtainMessage(MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK,
4708 new KeyEvent(event));
4709 msg.setAsynchronous(true);
4710 msg.sendToTarget();
Jeff Brown4d396052010-10-29 21:50:21 -07004711 }
4712 break;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004713 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004714
Jeff Brown4d396052010-10-29 21:50:21 -07004715 case KeyEvent.KEYCODE_CALL: {
4716 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004717 TelecomManager telecomManager = getTelecommService();
4718 if (telecomManager != null) {
4719 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07004720 Log.i(TAG, "interceptKeyBeforeQueueing:"
4721 + " CALL key-down while ringing: Answer the call!");
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004722 telecomManager.acceptRingingCall();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004723
Santos Cordon6848f722014-05-21 15:22:12 -07004724 // And *don't* pass this key thru to the current activity
4725 // (which is presumably the InCallScreen.)
4726 result &= ~ACTION_PASS_TO_USER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004727 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004728 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004729 }
Jeff Brown4d396052010-10-29 21:50:21 -07004730 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004731 }
Michael Wright869a67c2014-08-26 19:33:06 -07004732 case KeyEvent.KEYCODE_VOICE_ASSIST: {
4733 // Only do this if we would otherwise not pass it to the user. In that case,
4734 // interceptKeyBeforeDispatching would apply a similar but different policy in
4735 // order to invoke voice assist actions. Note that we need to make a copy of the
4736 // key event here because the original key event will be recycled when we return.
4737 if ((result & ACTION_PASS_TO_USER) == 0 && !down) {
4738 mBroadcastWakeLock.acquire();
4739 Message msg = mHandler.obtainMessage(MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK,
4740 keyguardActive ? 1 : 0, 0);
4741 msg.setAsynchronous(true);
4742 msg.sendToTarget();
4743 }
4744 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004745 }
Jeff Brown26875502014-01-30 21:47:47 -08004746
Jeff Brownbae8e772014-06-12 19:59:45 -07004747 if (useHapticFeedback) {
4748 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
4749 }
4750
Jeff Brown26875502014-01-30 21:47:47 -08004751 if (isWakeKey) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004752 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey);
Jeff Brown26875502014-01-30 21:47:47 -08004753 }
Bryce Lee584a4452014-10-21 15:55:55 -07004754
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004755 return result;
4756 }
4757
Jeff Brown1c2e4942012-11-06 16:32:01 -08004758 /**
Jeff Brown13f00f02014-10-31 14:45:50 -07004759 * Returns true if the key can have global actions attached to it.
4760 * We reserve all power management keys for the system since they require
4761 * very careful handling.
4762 */
4763 private static boolean isValidGlobalKey(int keyCode) {
4764 switch (keyCode) {
4765 case KeyEvent.KEYCODE_POWER:
4766 case KeyEvent.KEYCODE_WAKEUP:
4767 case KeyEvent.KEYCODE_SLEEP:
4768 return false;
4769 default:
4770 return true;
4771 }
4772 }
4773
4774 /**
Jeff Brown1c2e4942012-11-06 16:32:01 -08004775 * When the screen is off we ignore some keys that might otherwise typically
4776 * be considered wake keys. We filter them out here.
4777 *
4778 * {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it
4779 * is always considered a wake key.
4780 */
4781 private boolean isWakeKeyWhenScreenOff(int keyCode) {
4782 switch (keyCode) {
4783 // ignore volume keys unless docked
4784 case KeyEvent.KEYCODE_VOLUME_UP:
4785 case KeyEvent.KEYCODE_VOLUME_DOWN:
4786 case KeyEvent.KEYCODE_VOLUME_MUTE:
4787 return mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED;
4788
4789 // ignore media and camera keys
4790 case KeyEvent.KEYCODE_MUTE:
4791 case KeyEvent.KEYCODE_HEADSETHOOK:
4792 case KeyEvent.KEYCODE_MEDIA_PLAY:
4793 case KeyEvent.KEYCODE_MEDIA_PAUSE:
4794 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
4795 case KeyEvent.KEYCODE_MEDIA_STOP:
4796 case KeyEvent.KEYCODE_MEDIA_NEXT:
4797 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
4798 case KeyEvent.KEYCODE_MEDIA_REWIND:
4799 case KeyEvent.KEYCODE_MEDIA_RECORD:
4800 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09004801 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK:
Jeff Brown1c2e4942012-11-06 16:32:01 -08004802 case KeyEvent.KEYCODE_CAMERA:
4803 return false;
4804 }
4805 return true;
4806 }
4807
4808
Jeff Brown56194eb2011-03-02 19:23:13 -08004809 /** {@inheritDoc} */
4810 @Override
Michael Wright70af00a2014-09-03 19:30:20 -07004811 public int interceptMotionBeforeQueueingNonInteractive(long whenNanos, int policyFlags) {
4812 if ((policyFlags & FLAG_WAKE) != 0) {
Bryce Lee5c138322014-11-03 08:26:09 -08004813 if (wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotion)) {
4814 return 0;
4815 }
Michael Wright70af00a2014-09-03 19:30:20 -07004816 }
Bryce Lee5c138322014-11-03 08:26:09 -08004817
Michael Wright70af00a2014-09-03 19:30:20 -07004818 if (shouldDispatchInputWhenNonInteractive()) {
4819 return ACTION_PASS_TO_USER;
4820 }
Bryce Lee5c138322014-11-03 08:26:09 -08004821
Bryce Lee812d7022014-11-10 13:33:28 -08004822 // If we have not passed the action up and we are in theater mode without dreaming,
4823 // there will be no dream to intercept the touch and wake into ambient. The device should
4824 // wake up in this case.
4825 if (isTheaterModeEnabled() && (policyFlags & FLAG_WAKE) != 0) {
4826 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotionWhenNotDreaming);
4827 }
4828
Jeff Brown037c33e2014-04-09 00:31:55 -07004829 return 0;
Jeff Brown56194eb2011-03-02 19:23:13 -08004830 }
4831
Michael Wright70af00a2014-09-03 19:30:20 -07004832 private boolean shouldDispatchInputWhenNonInteractive() {
Bryce Lee5c138322014-11-03 08:26:09 -08004833 // Send events to keyguard while the screen is on.
Jim Millerab954542014-10-10 18:21:49 -07004834 if (isKeyguardShowingAndNotOccluded() && mDisplay != null
4835 && mDisplay.getState() != Display.STATE_OFF) {
Bryce Lee5c138322014-11-03 08:26:09 -08004836 return true;
4837 }
4838
4839 // Send events to a dozing dream even if the screen is off since the dream
4840 // is in control of the state of the screen.
4841 IDreamManager dreamManager = getDreamManager();
4842
4843 try {
4844 if (dreamManager != null && dreamManager.isDreaming()) {
4845 return true;
4846 }
4847 } catch (RemoteException e) {
4848 Slog.e(TAG, "RemoteException when checking if dreaming", e);
4849 }
4850
4851 // Otherwise, consume events since the user can't see what is being
4852 // interacted with.
4853 return false;
Michael Wright70af00a2014-09-03 19:30:20 -07004854 }
4855
RoboErik001c59c2015-01-26 15:53:51 -08004856 private void dispatchDirectAudioEvent(KeyEvent event) {
4857 if (event.getAction() != KeyEvent.ACTION_DOWN) {
4858 return;
4859 }
4860 int keyCode = event.getKeyCode();
4861 int flags = AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_PLAY_SOUND;
4862 String pkgName = mContext.getOpPackageName();
4863 switch (keyCode) {
4864 case KeyEvent.KEYCODE_VOLUME_UP:
4865 try {
4866 if (mUseMasterVolume) {
4867 getAudioService().adjustMasterVolume(AudioManager.ADJUST_RAISE, flags,
4868 pkgName);
4869 } else {
4870 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_RAISE,
4871 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName);
4872 }
4873 } catch (RemoteException e) {
4874 Log.e(TAG, "Error dispatching volume up in dispatchTvAudioEvent.", e);
4875 }
4876 break;
4877 case KeyEvent.KEYCODE_VOLUME_DOWN:
4878 try {
4879 if (mUseMasterVolume) {
4880 getAudioService().adjustMasterVolume(AudioManager.ADJUST_LOWER, flags,
4881 pkgName);
4882 } else {
4883 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_LOWER,
4884 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName);
4885 }
4886 } catch (RemoteException e) {
4887 Log.e(TAG, "Error dispatching volume down in dispatchTvAudioEvent.", e);
4888 }
4889 break;
4890 case KeyEvent.KEYCODE_VOLUME_MUTE:
4891 try {
4892 if (event.getRepeatCount() == 0) {
4893 if (mUseMasterVolume) {
4894 getAudioService().adjustMasterVolume(AudioManager.ADJUST_TOGGLE_MUTE,
4895 flags, pkgName);
4896 } else {
4897 getAudioService().adjustSuggestedStreamVolume(
4898 AudioManager.ADJUST_TOGGLE_MUTE,
4899 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName);
4900 }
4901 }
4902 } catch (RemoteException e) {
4903 Log.e(TAG, "Error dispatching mute in dispatchTvAudioEvent.", e);
4904 }
4905 break;
4906 }
4907 }
4908
Jeff Brown40013652012-05-16 21:22:36 -07004909 void dispatchMediaKeyWithWakeLock(KeyEvent event) {
4910 if (DEBUG_INPUT) {
4911 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: " + event);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004912 }
4913
Jeff Brown40013652012-05-16 21:22:36 -07004914 if (mHavePendingMediaKeyRepeatWithWakeLock) {
4915 if (DEBUG_INPUT) {
4916 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: canceled repeat");
4917 }
4918
4919 mHandler.removeMessages(MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK);
4920 mHavePendingMediaKeyRepeatWithWakeLock = false;
4921 mBroadcastWakeLock.release(); // pending repeat was holding onto the wake lock
4922 }
4923
4924 dispatchMediaKeyWithWakeLockToAudioService(event);
4925
4926 if (event.getAction() == KeyEvent.ACTION_DOWN
4927 && event.getRepeatCount() == 0) {
4928 mHavePendingMediaKeyRepeatWithWakeLock = true;
4929
4930 Message msg = mHandler.obtainMessage(
4931 MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK, event);
4932 msg.setAsynchronous(true);
4933 mHandler.sendMessageDelayed(msg, ViewConfiguration.getKeyRepeatTimeout());
4934 } else {
4935 mBroadcastWakeLock.release();
4936 }
4937 }
4938
4939 void dispatchMediaKeyRepeatWithWakeLock(KeyEvent event) {
4940 mHavePendingMediaKeyRepeatWithWakeLock = false;
4941
4942 KeyEvent repeatEvent = KeyEvent.changeTimeRepeat(event,
4943 SystemClock.uptimeMillis(), 1, event.getFlags() | KeyEvent.FLAG_LONG_PRESS);
4944 if (DEBUG_INPUT) {
4945 Slog.d(TAG, "dispatchMediaKeyRepeatWithWakeLock: " + repeatEvent);
4946 }
4947
4948 dispatchMediaKeyWithWakeLockToAudioService(repeatEvent);
4949 mBroadcastWakeLock.release();
4950 }
4951
4952 void dispatchMediaKeyWithWakeLockToAudioService(KeyEvent event) {
4953 if (ActivityManagerNative.isSystemReady()) {
RoboErik430fc482014-06-12 15:49:20 -07004954 MediaSessionLegacyHelper.getHelper(mContext).sendMediaButtonEvent(event, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004955 }
4956 }
4957
Michael Wright869a67c2014-08-26 19:33:06 -07004958 void launchVoiceAssistWithWakeLock(boolean keyguardActive) {
4959 Intent voiceIntent =
4960 new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
4961 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, keyguardActive);
4962 mContext.startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
4963 mBroadcastWakeLock.release();
4964 }
4965
Mike Lockwood1753f7f2009-08-24 14:49:07 -07004966 BroadcastReceiver mDockReceiver = new BroadcastReceiver() {
Craig Mautnereee29c42013-01-17 14:44:34 -08004967 @Override
Mike Lockwood1753f7f2009-08-24 14:49:07 -07004968 public void onReceive(Context context, Intent intent) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07004969 if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) {
4970 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
4971 Intent.EXTRA_DOCK_STATE_UNDOCKED);
Daniel Sandler6396c722013-04-16 20:19:09 -04004972 } else {
4973 try {
4974 IUiModeManager uiModeService = IUiModeManager.Stub.asInterface(
4975 ServiceManager.getService(Context.UI_MODE_SERVICE));
4976 mUiMode = uiModeService.getCurrentModeType();
4977 } catch (RemoteException e) {
4978 }
Dianne Hackborn80fa1662009-10-07 14:02:10 -07004979 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004980 updateRotation(true);
Craig Mautnereee29c42013-01-17 14:44:34 -08004981 synchronized (mLock) {
4982 updateOrientationListenerLp();
4983 }
Mike Lockwood1753f7f2009-08-24 14:49:07 -07004984 }
4985 };
4986
Jeff Brown6aaf2952012-10-05 16:01:08 -07004987 BroadcastReceiver mDreamReceiver = new BroadcastReceiver() {
4988 @Override
4989 public void onReceive(Context context, Intent intent) {
4990 if (Intent.ACTION_DREAMING_STARTED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004991 if (mKeyguardDelegate != null) {
4992 mKeyguardDelegate.onDreamingStarted();
Jeff Brown6aaf2952012-10-05 16:01:08 -07004993 }
4994 } else if (Intent.ACTION_DREAMING_STOPPED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004995 if (mKeyguardDelegate != null) {
4996 mKeyguardDelegate.onDreamingStopped();
Jeff Brown6aaf2952012-10-05 16:01:08 -07004997 }
4998 }
4999 }
5000 };
5001
Christopher Tate5e08af02012-09-21 17:17:22 -07005002 BroadcastReceiver mMultiuserReceiver = new BroadcastReceiver() {
5003 @Override
5004 public void onReceive(Context context, Intent intent) {
5005 if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) {
5006 // tickle the settings observer: this first ensures that we're
5007 // observing the relevant settings for the newly-active user,
5008 // and then updates our own bookkeeping based on the now-
5009 // current user.
5010 mSettingsObserver.onChange(false);
John Spurlockce479d82012-11-29 09:52:21 -05005011
5012 // force a re-application of focused window sysui visibility.
5013 // the window may never have been shown for this user
5014 // e.g. the keyguard when going through the new-user setup flow
John Spurlock04db1762013-05-13 12:46:41 -04005015 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
John Spurlockce479d82012-11-29 09:52:21 -05005016 mLastSystemUiFlags = 0;
5017 updateSystemUiVisibilityLw();
5018 }
Christopher Tate5e08af02012-09-21 17:17:22 -07005019 }
5020 }
5021 };
5022
John Spurlockd9b70bd2014-02-06 17:02:44 -05005023 private final Runnable mRequestTransientNav = new Runnable() {
5024 @Override
5025 public void run() {
5026 requestTransientBars(mNavigationBar);
5027 }
5028 };
5029
John Spurlocke1f366f2013-08-05 12:22:40 -04005030 private void requestTransientBars(WindowState swipeTarget) {
John Spurlock04db1762013-05-13 12:46:41 -04005031 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Maurice Lam99c6e072014-04-28 18:24:28 -07005032 if (!isUserSetupComplete()) {
5033 // Swipe-up for navigation bar is disabled during setup
5034 return;
5035 }
John Spurlock27735a42013-08-14 17:57:38 -04005036 boolean sb = mStatusBarController.checkShowTransientBarLw();
5037 boolean nb = mNavigationBarController.checkShowTransientBarLw();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005038 if (sb || nb) {
John Spurlocke1f366f2013-08-05 12:22:40 -04005039 WindowState barTarget = sb ? mStatusBar : mNavigationBar;
5040 if (sb ^ nb && barTarget != swipeTarget) {
5041 if (DEBUG) Slog.d(TAG, "Not showing transient bar, wrong swipe target");
John Spurlockad3e6cb2013-04-30 08:47:43 -04005042 return;
5043 }
John Spurlock27735a42013-08-14 17:57:38 -04005044 if (sb) mStatusBarController.showTransient();
5045 if (nb) mNavigationBarController.showTransient();
John Spurlockf1a36642013-10-12 17:50:42 -04005046 mImmersiveModeConfirmation.confirmCurrentPrompt();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005047 updateSystemUiVisibilityLw();
John Spurlock32beb2c2013-03-11 10:16:47 -04005048 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04005049 }
5050 }
5051
Jeff Brown3ee549c2014-09-22 20:14:39 -07005052 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07005053 @Override
Jeff Brown140ffc72014-05-01 15:18:00 -07005054 public void goingToSleep(int why) {
Dianne Hackborn74489012009-03-24 20:50:09 -07005055 EventLog.writeEvent(70000, 0);
Jeff Brown36c4db82014-09-19 12:05:31 -07005056 if (DEBUG_WAKEUP) Slog.i(TAG, "Going to sleep...");
Jeff Brown3ee549c2014-09-22 20:14:39 -07005057
5058 // We must get this work done here because the power manager will drop
5059 // the wake lock and let the system suspend once this function returns.
The Android Open Source Project0727d222009-03-11 12:11:58 -07005060 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005061 mAwake = false;
5062 mKeyguardDrawComplete = false;
Jeff Browna20dda42014-05-27 20:57:24 -07005063 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005064 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05005065 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005066 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005067
5068 if (mKeyguardDelegate != null) {
5069 mKeyguardDelegate.onScreenTurnedOff(why);
5070 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005071 }
5072
Jeff Brown13f00f02014-10-31 14:45:50 -07005073 private void wakeUpFromPowerKey(long eventTime) {
5074 wakeUp(eventTime, mAllowTheaterModeWakeFromPowerKey);
5075 }
5076
Bryce Lee5c138322014-11-03 08:26:09 -08005077 private boolean wakeUp(long wakeTime, boolean wakeInTheaterMode) {
Bryce Lee584a4452014-10-21 15:55:55 -07005078 if (!wakeInTheaterMode && isTheaterModeEnabled()) {
Bryce Lee5c138322014-11-03 08:26:09 -08005079 return false;
Bryce Lee584a4452014-10-21 15:55:55 -07005080 }
5081
5082 mPowerManager.wakeUp(wakeTime);
Bryce Lee5c138322014-11-03 08:26:09 -08005083 return true;
Bryce Lee584a4452014-10-21 15:55:55 -07005084 }
5085
Jeff Brown3ee549c2014-09-22 20:14:39 -07005086 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07005087 @Override
Jeff Brown36c4db82014-09-19 12:05:31 -07005088 public void wakingUp() {
Dianne Hackborn74489012009-03-24 20:50:09 -07005089 EventLog.writeEvent(70000, 1);
Jeff Brown36c4db82014-09-19 12:05:31 -07005090 if (DEBUG_WAKEUP) Slog.i(TAG, "Waking up...");
Craig Mautner8a0da012014-05-31 15:13:37 -07005091
Jeff Brown3ee549c2014-09-22 20:14:39 -07005092 // Since goToSleep performs these functions synchronously, we must
5093 // do the same here. We cannot post this work to a handler because
5094 // that might cause it to become reordered with respect to what
5095 // may happen in a future call to goToSleep.
The Android Open Source Project0727d222009-03-11 12:11:58 -07005096 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005097 mAwake = true;
5098 mKeyguardDrawComplete = false;
5099 if (mKeyguardDelegate != null) {
5100 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
5101 mHandler.sendEmptyMessageDelayed(MSG_KEYGUARD_DRAWN_TIMEOUT, 1000);
5102 }
5103
Jeff Browna20dda42014-05-27 20:57:24 -07005104 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005105 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05005106 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005107 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005108
Jim Miller5ecd8112013-01-09 18:50:26 -08005109 if (mKeyguardDelegate != null) {
Craig Mautner8a0da012014-05-31 15:13:37 -07005110 mKeyguardDelegate.onScreenTurnedOn(mKeyguardDelegateCallback);
Jeff Brown36c4db82014-09-19 12:05:31 -07005111 // ... eventually calls finishKeyguardDrawn
Jeff Brownc38c9be2012-10-04 13:16:19 -07005112 } else {
Craig Mautner8a0da012014-05-31 15:13:37 -07005113 if (DEBUG_WAKEUP) Slog.d(TAG, "null mKeyguardDelegate: setting mKeyguardDrawComplete.");
Jeff Brown36c4db82014-09-19 12:05:31 -07005114 finishKeyguardDrawn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07005115 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005116 }
5117
Jeff Brown36c4db82014-09-19 12:05:31 -07005118 private void finishKeyguardDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005119 synchronized (mLock) {
5120 if (!mAwake || mKeyguardDrawComplete) {
5121 return; // spurious
5122 }
5123
Jeff Brown36c4db82014-09-19 12:05:31 -07005124 mKeyguardDrawComplete = true;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005125 if (mKeyguardDelegate != null) {
5126 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
5127 }
5128 }
5129
5130 finishScreenTurningOn();
5131 }
5132
5133 // Called on the DisplayManager's DisplayPowerController thread.
5134 @Override
5135 public void screenTurnedOff() {
5136 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turned off...");
5137
5138 synchronized (mLock) {
5139 mScreenOnEarly = false;
5140 mScreenOnFully = false;
5141 mWindowManagerDrawComplete = false;
5142 mScreenOnListener = null;
5143 updateOrientationListenerLp();
Jeff Brown36c4db82014-09-19 12:05:31 -07005144 }
5145 }
5146
Jeff Brown3ee549c2014-09-22 20:14:39 -07005147 // Called on the DisplayManager's DisplayPowerController thread.
Jeff Brown36c4db82014-09-19 12:05:31 -07005148 @Override
5149 public void screenTurningOn(final ScreenOnListener screenOnListener) {
Jeff Brown36c4db82014-09-19 12:05:31 -07005150 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turning on...");
Jeff Brown36c4db82014-09-19 12:05:31 -07005151
Jeff Brown3ee549c2014-09-22 20:14:39 -07005152 synchronized (mLock) {
5153 mScreenOnEarly = true;
5154 mScreenOnFully = false;
5155 mWindowManagerDrawComplete = false;
5156 mScreenOnListener = screenOnListener;
5157 updateOrientationListenerLp();
5158 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005159
Craig Mautnerc3daedd2014-09-13 11:17:23 -07005160 mWindowManagerInternal.waitForAllWindowsDrawn(mWindowManagerDrawCallback,
5161 WAITING_FOR_DRAWN_TIMEOUT);
Jeff Brown36c4db82014-09-19 12:05:31 -07005162 // ... eventually calls finishWindowsDrawn
5163 }
5164
Jeff Brown36c4db82014-09-19 12:05:31 -07005165 private void finishWindowsDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005166 synchronized (mLock) {
5167 if (!mScreenOnEarly || mWindowManagerDrawComplete) {
5168 return; // spurious
5169 }
5170
Jeff Brown36c4db82014-09-19 12:05:31 -07005171 mWindowManagerDrawComplete = true;
Jeff Brown36c4db82014-09-19 12:05:31 -07005172 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005173
5174 finishScreenTurningOn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07005175 }
5176
Craig Mautner8a0da012014-05-31 15:13:37 -07005177 private void finishScreenTurningOn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005178 final ScreenOnListener listener;
5179 final boolean enableScreen;
Jeff Brown36c4db82014-09-19 12:05:31 -07005180 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005181 if (DEBUG_WAKEUP) Slog.d(TAG,
5182 "finishScreenTurningOn: mAwake=" + mAwake
5183 + ", mScreenOnEarly=" + mScreenOnEarly
5184 + ", mScreenOnFully=" + mScreenOnFully
5185 + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete
5186 + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete);
5187
5188 if (mScreenOnFully || !mScreenOnEarly || !mWindowManagerDrawComplete
5189 || (mAwake && !mKeyguardDrawComplete)) {
5190 return; // spurious or not ready yet
Jeff Brown36c4db82014-09-19 12:05:31 -07005191 }
5192
Jeff Brown3ee549c2014-09-22 20:14:39 -07005193 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished screen turning on...");
5194 listener = mScreenOnListener;
Craig Mautner13f6ea72014-06-23 14:57:02 -07005195 mScreenOnListener = null;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005196 mScreenOnFully = true;
5197
5198 // Remember the first time we draw the keyguard so we know when we're done with
5199 // the main part of booting and can enable the screen and hide boot messages.
5200 if (!mKeyguardDrawnOnce && mAwake) {
5201 mKeyguardDrawnOnce = true;
5202 enableScreen = true;
5203 if (mBootMessageNeedsHiding) {
5204 mBootMessageNeedsHiding = false;
5205 hideBootMessages();
5206 }
5207 } else {
5208 enableScreen = false;
5209 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005210 }
5211
Jeff Brown3ee549c2014-09-22 20:14:39 -07005212 if (listener != null) {
5213 listener.onScreenOn();
5214 }
Jeff Brown4fc45272012-10-10 18:28:14 -07005215
Jeff Brown3ee549c2014-09-22 20:14:39 -07005216 if (enableScreen) {
5217 try {
5218 mWindowManager.enableScreenIfNeeded();
5219 } catch (RemoteException unhandled) {
Jeff Brown36c4db82014-09-19 12:05:31 -07005220 }
Craig Mautnera631d492014-08-05 15:16:01 -07005221 }
5222 }
5223
5224 private void handleHideBootMessage() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005225 synchronized (mLock) {
5226 if (!mKeyguardDrawnOnce) {
5227 mBootMessageNeedsHiding = true;
5228 return; // keyguard hasn't drawn the first time yet, not done booting
5229 }
Craig Mautnera631d492014-08-05 15:16:01 -07005230 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005231
5232 if (mBootMsgDialog != null) {
5233 if (DEBUG_WAKEUP) Slog.d(TAG, "handleHideBootMessage: dismissing");
5234 mBootMsgDialog.dismiss();
5235 mBootMsgDialog = null;
Craig Mautnera631d492014-08-05 15:16:01 -07005236 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005237 }
5238
5239 @Override
Jeff Brown3ee549c2014-09-22 20:14:39 -07005240 public boolean isScreenOn() {
5241 return mScreenOnFully;
Dianne Hackborn08743722009-12-21 12:16:51 -08005242 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005243
Dianne Hackborn08743722009-12-21 12:16:51 -08005244 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005245 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005246 public void enableKeyguard(boolean enabled) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005247 if (mKeyguardDelegate != null) {
5248 mKeyguardDelegate.setKeyguardEnabled(enabled);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005249 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005250 }
5251
5252 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005253 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005254 public void exitKeyguardSecurely(OnKeyguardExitResult callback) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005255 if (mKeyguardDelegate != null) {
5256 mKeyguardDelegate.verifyUnlock(callback);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005257 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005258 }
5259
Jim Millerab954542014-10-10 18:21:49 -07005260 private boolean isKeyguardShowingAndNotOccluded() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005261 if (mKeyguardDelegate == null) return false;
Jim Millerab954542014-10-10 18:21:49 -07005262 return mKeyguardDelegate.isShowing() && !mKeyguardOccluded;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005263 }
5264
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005265 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005266 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005267 public boolean isKeyguardLocked() {
5268 return keyguardOn();
5269 }
5270
5271 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005272 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005273 public boolean isKeyguardSecure() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005274 if (mKeyguardDelegate == null) return false;
5275 return mKeyguardDelegate.isSecure();
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005276 }
5277
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005278 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005279 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005280 public boolean inKeyguardRestrictedKeyInputMode() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005281 if (mKeyguardDelegate == null) return false;
5282 return mKeyguardDelegate.isInputRestricted();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005283 }
5284
Jose Lima9546b202014-07-02 17:21:51 -07005285 @Override
Dianne Hackborn90c52de2011-09-23 12:57:44 -07005286 public void dismissKeyguardLw() {
RoboErik8a2cfc32014-05-16 11:19:38 -07005287 if (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()) {
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07005288 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.dismissKeyguardLw");
Daniel Sandler1ce804392012-11-07 15:07:12 -05005289 mHandler.post(new Runnable() {
Jose Lima9546b202014-07-02 17:21:51 -07005290 @Override
Daniel Sandler1ce804392012-11-07 15:07:12 -05005291 public void run() {
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02005292 // ask the keyguard to prompt the user to authenticate if necessary
5293 mKeyguardDelegate.dismiss();
5294 }
5295 });
5296 }
5297 }
5298
5299 public void notifyActivityDrawnForKeyguardLw() {
5300 if (mKeyguardDelegate != null) {
5301 mHandler.post(new Runnable() {
5302 @Override
5303 public void run() {
5304 mKeyguardDelegate.onActivityDrawn();
Daniel Sandler1ce804392012-11-07 15:07:12 -05005305 }
5306 });
Dianne Hackborn90c52de2011-09-23 12:57:44 -07005307 }
5308 }
5309
Jorim Jaggicff0acb2014-03-31 16:35:15 +02005310 @Override
5311 public boolean isKeyguardDrawnLw() {
5312 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005313 return mKeyguardDrawnOnce;
Jorim Jaggicff0acb2014-03-31 16:35:15 +02005314 }
5315 }
5316
Jorim Jaggi0d674622014-05-21 01:34:15 +02005317 @Override
Jorim Jaggie29b2db2014-05-30 23:17:03 +02005318 public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) {
Jorim Jaggi0d674622014-05-21 01:34:15 +02005319 if (mKeyguardDelegate != null) {
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07005320 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.startKeyguardExitAnimation");
Jorim Jaggie29b2db2014-05-30 23:17:03 +02005321 mKeyguardDelegate.startKeyguardExitAnimation(startTime, fadeoutDuration);
Jorim Jaggi0d674622014-05-21 01:34:15 +02005322 }
5323 }
5324
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005325 void sendCloseSystemWindows() {
Jorim Jaggib10e33f2015-02-04 21:57:40 +01005326 PhoneWindow.sendCloseSystemWindows(mContext, null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005327 }
5328
5329 void sendCloseSystemWindows(String reason) {
Jorim Jaggib10e33f2015-02-04 21:57:40 +01005330 PhoneWindow.sendCloseSystemWindows(mContext, reason);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005331 }
Mitsuru Oshima831d0d92009-06-16 18:27:18 -07005332
Jeff Brown01a98dd2011-09-20 15:08:29 -07005333 @Override
5334 public int rotationForOrientationLw(int orientation, int lastRotation) {
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005335 if (false) {
5336 Slog.v(TAG, "rotationForOrientationLw(orient="
5337 + orientation + ", last=" + lastRotation
5338 + "); user=" + mUserRotation + " "
5339 + ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED)
5340 ? "USER_ROTATION_LOCKED" : "")
5341 );
5342 }
5343
Craig Mautner46ac6fa2013-08-01 10:06:34 -07005344 if (mForceDefaultOrientation) {
5345 return Surface.ROTATION_0;
5346 }
5347
The Android Open Source Project0727d222009-03-11 12:11:58 -07005348 synchronized (mLock) {
Jeff Brownc0347aa2011-09-23 17:26:09 -07005349 int sensorRotation = mOrientationListener.getProposedRotation(); // may be -1
5350 if (sensorRotation < 0) {
Jeff Brown0f862b42012-09-27 21:11:01 -07005351 sensorRotation = lastRotation;
Jeff Brownc0347aa2011-09-23 17:26:09 -07005352 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005353
Jeff Browndec6cf42011-11-15 14:08:20 -08005354 final int preferredRotation;
Jeff Brown2e7760e2012-04-11 15:14:55 -07005355 if (mLidState == LID_OPEN && mLidOpenRotation >= 0) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005356 // Ignore sensor when lid switch is open and rotation is forced.
5357 preferredRotation = mLidOpenRotation;
5358 } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR
Jeff Brownc0347aa2011-09-23 17:26:09 -07005359 && (mCarDockEnablesAccelerometer || mCarDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005360 // Ignore sensor when in car dock unless explicitly enabled.
5361 // This case can override the behavior of NOSENSOR, and can also
5362 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07005363 preferredRotation = mCarDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07005364 ? sensorRotation : mCarDockRotation;
Jeff Brown1a693182011-11-08 14:44:16 -08005365 } else if ((mDockMode == Intent.EXTRA_DOCK_STATE_DESK
5366 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
5367 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK)
Jeff Brownc0347aa2011-09-23 17:26:09 -07005368 && (mDeskDockEnablesAccelerometer || mDeskDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005369 // Ignore sensor when in desk dock unless explicitly enabled.
5370 // This case can override the behavior of NOSENSOR, and can also
5371 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07005372 preferredRotation = mDeskDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07005373 ? sensorRotation : mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -07005374 } else if (mHdmiPlugged && mDemoHdmiRotationLock) {
5375 // Ignore sensor when plugged into HDMI when demo HDMI rotation lock enabled.
Jeff Browneb3e4b92011-12-06 19:54:24 -08005376 // Note that the dock orientation overrides the HDMI orientation.
Jeff Brownc82c89ed2013-04-17 17:18:15 -07005377 preferredRotation = mDemoHdmiRotation;
5378 } else if (mHdmiPlugged && mDockMode == Intent.EXTRA_DOCK_STATE_UNDOCKED
5379 && mUndockedHdmiRotation >= 0) {
5380 // Ignore sensor when plugged into HDMI and an undocked orientation has
5381 // been specified in the configuration (only for legacy devices without
5382 // full multi-display support).
5383 // Note that the dock orientation overrides the HDMI orientation.
5384 preferredRotation = mUndockedHdmiRotation;
Chong Zhangae6119ff2014-11-11 18:54:39 -08005385 } else if (mDemoRotationLock) {
5386 // Ignore sensor when demo rotation lock is enabled.
5387 // Note that the dock orientation and HDMI rotation lock override this.
5388 preferredRotation = mDemoRotation;
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005389 } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED) {
5390 // Application just wants to remain locked in the last rotation.
5391 preferredRotation = lastRotation;
Jeff Brownbcdfc622014-03-06 19:13:04 -08005392 } else if (!mSupportAutoRotation) {
5393 // If we don't support auto-rotation then bail out here and ignore
5394 // the sensor and any rotation lock settings.
5395 preferredRotation = -1;
Jeff Brown207673cd2012-06-05 17:47:11 -07005396 } else if ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE
Jeff Brown01a98dd2011-09-20 15:08:29 -07005397 && (orientation == ActivityInfo.SCREEN_ORIENTATION_USER
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005398 || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
5399 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
5400 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
5401 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER))
Jeff Brown01a98dd2011-09-20 15:08:29 -07005402 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
5403 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
5404 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
5405 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) {
5406 // Otherwise, use sensor only if requested by the application or enabled
5407 // by default for USER or UNSPECIFIED modes. Does not apply to NOSENSOR.
Jeff Brownd3187e32011-09-21 19:26:44 -07005408 if (mAllowAllRotations < 0) {
5409 // Can't read this during init() because the context doesn't
5410 // have display metrics at that time so we cannot determine
5411 // tablet vs. phone then.
5412 mAllowAllRotations = mContext.getResources().getBoolean(
5413 com.android.internal.R.bool.config_allowAllRotations) ? 1 : 0;
5414 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005415 if (sensorRotation != Surface.ROTATION_180
Jeff Brownd3187e32011-09-21 19:26:44 -07005416 || mAllowAllRotations == 1
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005417 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
5418 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005419 preferredRotation = sensorRotation;
5420 } else {
5421 preferredRotation = lastRotation;
5422 }
Jeff Brown207673cd2012-06-05 17:47:11 -07005423 } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED
5424 && orientation != ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) {
5425 // Apply rotation lock. Does not apply to NOSENSOR.
5426 // The idea is that the user rotation expresses a weak preference for the direction
5427 // of gravity and as NOSENSOR is never affected by gravity, then neither should
5428 // NOSENSOR be affected by rotation lock (although it will be affected by docks).
Jeff Brown4dfce202011-10-05 12:00:10 -07005429 preferredRotation = mUserRotation;
Jeff Browndec6cf42011-11-15 14:08:20 -08005430 } else {
5431 // No overriding preference.
5432 // We will do exactly what the application asked us to do.
5433 preferredRotation = -1;
Jeff Brown01a98dd2011-09-20 15:08:29 -07005434 }
5435
Dianne Hackborne5439f22010-10-02 16:53:50 -07005436 switch (orientation) {
5437 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08005438 // Return portrait unless overridden.
5439 if (isAnyPortrait(preferredRotation)) {
5440 return preferredRotation;
5441 }
Dianne Hackborne5439f22010-10-02 16:53:50 -07005442 return mPortraitRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005443
Jeff Brown01a98dd2011-09-20 15:08:29 -07005444 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08005445 // Return landscape unless overridden.
5446 if (isLandscapeOrSeascape(preferredRotation)) {
5447 return preferredRotation;
5448 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005449 return mLandscapeRotation;
5450
5451 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08005452 // Return reverse portrait unless overridden.
5453 if (isAnyPortrait(preferredRotation)) {
5454 return preferredRotation;
5455 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005456 return mUpsideDownRotation;
5457
5458 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08005459 // Return seascape unless overridden.
5460 if (isLandscapeOrSeascape(preferredRotation)) {
5461 return preferredRotation;
5462 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005463 return mSeascapeRotation;
5464
5465 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005466 case ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE:
Jeff Brown01a98dd2011-09-20 15:08:29 -07005467 // Return either landscape rotation.
5468 if (isLandscapeOrSeascape(preferredRotation)) {
5469 return preferredRotation;
5470 }
5471 if (isLandscapeOrSeascape(lastRotation)) {
Jeff Brown4519f072011-01-23 13:16:01 -08005472 return lastRotation;
5473 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005474 return mLandscapeRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005475
Jeff Brown01a98dd2011-09-20 15:08:29 -07005476 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005477 case ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT:
Jeff Brown01a98dd2011-09-20 15:08:29 -07005478 // Return either portrait rotation.
5479 if (isAnyPortrait(preferredRotation)) {
5480 return preferredRotation;
5481 }
5482 if (isAnyPortrait(lastRotation)) {
5483 return lastRotation;
5484 }
5485 return mPortraitRotation;
5486
5487 default:
Jeff Brown4dfce202011-10-05 12:00:10 -07005488 // For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR,
5489 // just return the preferred orientation we already calculated.
Jeff Brown01a98dd2011-09-20 15:08:29 -07005490 if (preferredRotation >= 0) {
5491 return preferredRotation;
5492 }
Dianne Hackborndacea8c2011-04-21 17:26:39 -07005493 return Surface.ROTATION_0;
Daniel Sandlere7e5ac22011-02-22 16:10:21 -05005494 }
5495 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07005496 }
5497
Jeff Brown01a98dd2011-09-20 15:08:29 -07005498 @Override
5499 public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation) {
5500 switch (orientation) {
5501 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
5502 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
5503 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
5504 return isAnyPortrait(rotation);
5505
5506 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
5507 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
5508 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
5509 return isLandscapeOrSeascape(rotation);
5510
5511 default:
5512 return true;
5513 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07005514 }
5515
Jeff Brownc0347aa2011-09-23 17:26:09 -07005516 @Override
5517 public void setRotationLw(int rotation) {
5518 mOrientationListener.setCurrentRotation(rotation);
5519 }
5520
Jeff Brown01a98dd2011-09-20 15:08:29 -07005521 private boolean isLandscapeOrSeascape(int rotation) {
5522 return rotation == mLandscapeRotation || rotation == mSeascapeRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005523 }
5524
Jeff Brown01a98dd2011-09-20 15:08:29 -07005525 private boolean isAnyPortrait(int rotation) {
5526 return rotation == mPortraitRotation || rotation == mUpsideDownRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005527 }
5528
Jose Lima9546b202014-07-02 17:21:51 -07005529 @Override
Svetoslav Ganov80943d82013-01-02 10:25:37 -08005530 public int getUserRotationMode() {
5531 return Settings.System.getIntForUser(mContext.getContentResolver(),
Brett Chabot7e55c402013-05-16 19:38:08 -07005532 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
5533 WindowManagerPolicy.USER_ROTATION_FREE :
5534 WindowManagerPolicy.USER_ROTATION_LOCKED;
Svetoslav Ganov80943d82013-01-02 10:25:37 -08005535 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005536
5537 // User rotation: to be used when all else fails in assigning an orientation to the device
Jose Lima9546b202014-07-02 17:21:51 -07005538 @Override
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005539 public void setUserRotationMode(int mode, int rot) {
5540 ContentResolver res = mContext.getContentResolver();
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005541
5542 // mUserRotationMode and mUserRotation will be assigned by the content observer
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005543 if (mode == WindowManagerPolicy.USER_ROTATION_LOCKED) {
Christopher Tate5e08af02012-09-21 17:17:22 -07005544 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005545 Settings.System.USER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005546 rot,
5547 UserHandle.USER_CURRENT);
5548 Settings.System.putIntForUser(res,
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005549 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005550 0,
5551 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005552 } else {
Christopher Tate5e08af02012-09-21 17:17:22 -07005553 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005554 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005555 1,
5556 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005557 }
5558 }
5559
Jose Lima9546b202014-07-02 17:21:51 -07005560 @Override
Jeff Brownac143512012-04-05 18:57:33 -07005561 public void setSafeMode(boolean safeMode) {
5562 mSafeMode = safeMode;
5563 performHapticFeedbackLw(null, safeMode
5564 ? HapticFeedbackConstants.SAFE_MODE_ENABLED
5565 : HapticFeedbackConstants.SAFE_MODE_DISABLED, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005566 }
Craig Mautnereda67292013-04-28 13:50:14 -07005567
Dianne Hackborn181ceb52009-08-27 22:16:40 -07005568 static long[] getLongIntArray(Resources r, int resid) {
5569 int[] ar = r.getIntArray(resid);
5570 if (ar == null) {
5571 return null;
5572 }
5573 long[] out = new long[ar.length];
5574 for (int i=0; i<ar.length; i++) {
5575 out[i] = ar[i];
5576 }
5577 return out;
5578 }
Craig Mautnereda67292013-04-28 13:50:14 -07005579
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005580 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07005581 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005582 public void systemReady() {
Jim Millerab954542014-10-10 18:21:49 -07005583 mKeyguardDelegate = new KeyguardServiceDelegate(mContext);
Mike Lockwooded8902d2013-11-15 11:01:47 -08005584 mKeyguardDelegate.onSystemReady();
5585
Michael Wright3818c922014-09-02 13:59:07 -07005586 readCameraLensCoverState();
Jeff Brown4f5fa282014-06-12 19:19:15 -07005587 updateUiMode();
Dianne Hackbornb1a79802009-09-29 15:18:31 -07005588 synchronized (mLock) {
5589 updateOrientationListenerLp();
Dianne Hackbornc777e072010-02-12 13:07:59 -08005590 mSystemReady = true;
5591 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07005592 @Override
Dianne Hackbornc777e072010-02-12 13:07:59 -08005593 public void run() {
5594 updateSettings();
5595 }
5596 });
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005597 }
5598 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07005599
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005600 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005601 @Override
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005602 public void systemBooted() {
Jim Millere5f910a2013-10-16 18:15:46 -07005603 if (mKeyguardDelegate != null) {
Jason Monk5eeebf52014-09-26 12:36:51 -04005604 mKeyguardDelegate.bindService(mContext);
Jim Millere5f910a2013-10-16 18:15:46 -07005605 mKeyguardDelegate.onBootCompleted();
5606 }
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005607 synchronized (mLock) {
5608 mSystemBooted = true;
5609 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005610 wakingUp();
5611 screenTurningOn(null);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005612 }
5613
Dianne Hackborn661cd522011-08-22 00:26:20 -07005614 ProgressDialog mBootMsgDialog = null;
5615
5616 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005617 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07005618 public void showBootMessage(final CharSequence msg, final boolean always) {
5619 mHandler.post(new Runnable() {
5620 @Override public void run() {
5621 if (mBootMsgDialog == null) {
Craig Stout4c0cb8a2014-04-04 13:03:10 -07005622 int theme;
5623 if (mContext.getPackageManager().hasSystemFeature(
5624 PackageManager.FEATURE_WATCH)) {
5625 theme = com.android.internal.R.style.Theme_Micro_Dialog_Alert;
5626 } else if (mContext.getPackageManager().hasSystemFeature(
5627 PackageManager.FEATURE_TELEVISION)) {
5628 theme = com.android.internal.R.style.Theme_Leanback_Dialog_Alert;
5629 } else {
5630 theme = 0;
5631 }
Vinod Krishnanfa8fc412014-04-18 14:35:53 -07005632
5633 mBootMsgDialog = new ProgressDialog(mContext, theme) {
Dianne Hackborn295e3c22011-08-25 13:19:08 -07005634 // This dialog will consume all events coming in to
5635 // it, to avoid it trying to do things too early in boot.
5636 @Override public boolean dispatchKeyEvent(KeyEvent event) {
5637 return true;
5638 }
5639 @Override public boolean dispatchKeyShortcutEvent(KeyEvent event) {
5640 return true;
5641 }
5642 @Override public boolean dispatchTouchEvent(MotionEvent ev) {
5643 return true;
5644 }
5645 @Override public boolean dispatchTrackballEvent(MotionEvent ev) {
5646 return true;
5647 }
5648 @Override public boolean dispatchGenericMotionEvent(MotionEvent ev) {
5649 return true;
5650 }
5651 @Override public boolean dispatchPopulateAccessibilityEvent(
5652 AccessibilityEvent event) {
5653 return true;
5654 }
5655 };
Jeff Hao9f60c082014-10-28 18:51:07 -07005656 if (mContext.getPackageManager().isUpgrade()) {
5657 mBootMsgDialog.setTitle(R.string.android_upgrading_title);
5658 } else {
5659 mBootMsgDialog.setTitle(R.string.android_start_title);
5660 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07005661 mBootMsgDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
5662 mBootMsgDialog.setIndeterminate(true);
5663 mBootMsgDialog.getWindow().setType(
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07005664 WindowManager.LayoutParams.TYPE_BOOT_PROGRESS);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005665 mBootMsgDialog.getWindow().addFlags(
5666 WindowManager.LayoutParams.FLAG_DIM_BEHIND
5667 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
5668 mBootMsgDialog.getWindow().setDimAmount(1);
Dianne Hackbornd9efb952011-12-07 14:56:51 -08005669 WindowManager.LayoutParams lp = mBootMsgDialog.getWindow().getAttributes();
5670 lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
5671 mBootMsgDialog.getWindow().setAttributes(lp);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005672 mBootMsgDialog.setCancelable(false);
5673 mBootMsgDialog.show();
5674 }
5675 mBootMsgDialog.setMessage(msg);
5676 }
5677 });
5678 }
5679
5680 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005681 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07005682 public void hideBootMessages() {
Craig Mautnera631d492014-08-05 15:16:01 -07005683 mHandler.sendEmptyMessage(MSG_HIDE_BOOT_MESSAGE);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005684 }
5685
Mike Lockwood28569302010-01-28 11:54:40 -05005686 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005687 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05005688 public void userActivity() {
Dianne Hackborndf89e652011-10-06 22:35:11 -07005689 // ***************************************
5690 // NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
5691 // ***************************************
5692 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
5693 // WITH ITS LOCKS HELD.
5694 //
5695 // This code must be VERY careful about the locks
5696 // it acquires.
5697 // In fact, the current code acquires way too many,
5698 // and probably has lurking deadlocks.
5699
Mike Lockwood28569302010-01-28 11:54:40 -05005700 synchronized (mScreenLockTimeout) {
5701 if (mLockScreenTimerActive) {
5702 // reset the timer
5703 mHandler.removeCallbacks(mScreenLockTimeout);
5704 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
5705 }
5706 }
Daniel Sandler0601eb72011-04-13 01:01:32 -04005707 }
5708
Adam Cohenf7522022012-10-03 20:03:18 -07005709 class ScreenLockTimeout implements Runnable {
5710 Bundle options;
5711
5712 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05005713 public void run() {
5714 synchronized (this) {
5715 if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard");
Jim Miller5ecd8112013-01-09 18:50:26 -08005716 if (mKeyguardDelegate != null) {
5717 mKeyguardDelegate.doKeyguardTimeout(options);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005718 }
Mike Lockwood28569302010-01-28 11:54:40 -05005719 mLockScreenTimerActive = false;
Adam Cohenf7522022012-10-03 20:03:18 -07005720 options = null;
Mike Lockwood28569302010-01-28 11:54:40 -05005721 }
5722 }
Mike Lockwood28569302010-01-28 11:54:40 -05005723
Adam Cohenf7522022012-10-03 20:03:18 -07005724 public void setLockOptions(Bundle options) {
5725 this.options = options;
5726 }
5727 }
5728
5729 ScreenLockTimeout mScreenLockTimeout = new ScreenLockTimeout();
5730
Jose Lima9546b202014-07-02 17:21:51 -07005731 @Override
Adam Cohenf7522022012-10-03 20:03:18 -07005732 public void lockNow(Bundle options) {
Jim Miller93c518e2012-01-17 15:55:31 -08005733 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null);
5734 mHandler.removeCallbacks(mScreenLockTimeout);
Adam Cohenf7522022012-10-03 20:03:18 -07005735 if (options != null) {
5736 // In case multiple calls are made to lockNow, we don't wipe out the options
5737 // until the runnable actually executes.
5738 mScreenLockTimeout.setLockOptions(options);
5739 }
Jim Miller93c518e2012-01-17 15:55:31 -08005740 mHandler.post(mScreenLockTimeout);
5741 }
5742
Mike Lockwood28569302010-01-28 11:54:40 -05005743 private void updateLockScreenTimeout() {
5744 synchronized (mScreenLockTimeout) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005745 boolean enable = (mAllowLockscreenWhenOn && mAwake &&
Jim Miller5ecd8112013-01-09 18:50:26 -08005746 mKeyguardDelegate != null && mKeyguardDelegate.isSecure());
Mike Lockwood28569302010-01-28 11:54:40 -05005747 if (mLockScreenTimerActive != enable) {
5748 if (enable) {
5749 if (localLOGV) Log.v(TAG, "setting lockscreen timer");
5750 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
5751 } else {
5752 if (localLOGV) Log.v(TAG, "clearing lockscreen timer");
5753 mHandler.removeCallbacks(mScreenLockTimeout);
5754 }
5755 mLockScreenTimerActive = enable;
5756 }
5757 }
5758 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005759
5760 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07005761 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005762 public void enableScreenAfterBoot() {
5763 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07005764 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07005765 updateRotation(true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005766 }
Dianne Hackbornf54c8f92009-09-19 14:03:57 -07005767
Jeff Brownc458ce92012-04-30 14:58:40 -07005768 private void applyLidSwitchState() {
Jeff Brownc458ce92012-04-30 14:58:40 -07005769 if (mLidState == LID_CLOSED && mLidControlsSleep) {
Jeff Brown6d8fd272014-05-20 21:24:38 -07005770 mPowerManager.goToSleep(SystemClock.uptimeMillis(),
Jeff Brownc12035c2014-08-13 18:52:25 -07005771 PowerManager.GO_TO_SLEEP_REASON_LID_SWITCH,
Jeff Brown6d8fd272014-05-20 21:24:38 -07005772 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
Jeff Brownc458ce92012-04-30 14:58:40 -07005773 }
Jeff Browna20dda42014-05-27 20:57:24 -07005774
5775 synchronized (mLock) {
5776 updateWakeGestureListenerLp();
5777 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005778 }
5779
Jeff Brown4f5fa282014-06-12 19:19:15 -07005780 void updateUiMode() {
5781 if (mUiModeManager == null) {
5782 mUiModeManager = IUiModeManager.Stub.asInterface(
5783 ServiceManager.getService(Context.UI_MODE_SERVICE));
5784 }
5785 try {
5786 mUiMode = mUiModeManager.getCurrentModeType();
5787 } catch (RemoteException e) {
5788 }
5789 }
5790
Jeff Brown01a98dd2011-09-20 15:08:29 -07005791 void updateRotation(boolean alwaysSendConfiguration) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005792 try {
5793 //set orientation on WindowManager
Dianne Hackbornf87d1962012-04-04 12:48:24 -07005794 mWindowManager.updateRotation(alwaysSendConfiguration, false);
5795 } catch (RemoteException e) {
5796 // Ignore
5797 }
5798 }
5799
5800 void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) {
5801 try {
5802 //set orientation on WindowManager
5803 mWindowManager.updateRotation(alwaysSendConfiguration, forceRelayout);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005804 } catch (RemoteException e) {
5805 // Ignore
5806 }
5807 }
5808
Daniel Sandler6396c722013-04-16 20:19:09 -04005809 /**
5810 * Return an Intent to launch the currently active dock app as home. Returns
5811 * null if the standard home should be launched, which is the case if any of the following is
5812 * true:
5813 * <ul>
5814 * <li>The device is not in either car mode or desk mode
5815 * <li>The device is in car mode but ENABLE_CAR_DOCK_HOME_CAPTURE is false
5816 * <li>The device is in desk mode but ENABLE_DESK_DOCK_HOME_CAPTURE is false
5817 * <li>The device is in car mode but there's no CAR_DOCK app with METADATA_DOCK_HOME
5818 * <li>The device is in desk mode but there's no DESK_DOCK app with METADATA_DOCK_HOME
5819 * </ul>
Craig Mautnereda67292013-04-28 13:50:14 -07005820 * @return A dock intent.
Daniel Sandler6396c722013-04-16 20:19:09 -04005821 */
5822 Intent createHomeDockIntent() {
5823 Intent intent = null;
5824
5825 // What home does is based on the mode, not the dock state. That
5826 // is, when in car mode you should be taken to car home regardless
5827 // of whether we are actually in a car dock.
5828 if (mUiMode == Configuration.UI_MODE_TYPE_CAR) {
5829 if (ENABLE_CAR_DOCK_HOME_CAPTURE) {
5830 intent = mCarDockIntent;
5831 }
5832 } else if (mUiMode == Configuration.UI_MODE_TYPE_DESK) {
5833 if (ENABLE_DESK_DOCK_HOME_CAPTURE) {
5834 intent = mDeskDockIntent;
5835 }
Jeff Brown4f5fa282014-06-12 19:19:15 -07005836 } else if (mUiMode == Configuration.UI_MODE_TYPE_WATCH
5837 && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
5838 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK
5839 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK)) {
5840 // Always launch dock home from home when watch is docked, if it exists.
5841 intent = mDeskDockIntent;
Daniel Sandler6396c722013-04-16 20:19:09 -04005842 }
5843
5844 if (intent == null) {
5845 return null;
5846 }
5847
5848 ActivityInfo ai = null;
5849 ResolveInfo info = mContext.getPackageManager().resolveActivityAsUser(
5850 intent,
John Spurlockf56bef12013-07-09 09:51:46 -04005851 PackageManager.MATCH_DEFAULT_ONLY | PackageManager.GET_META_DATA,
Craig Mautnerd625ab22013-09-06 13:40:31 -07005852 mCurrentUserId);
Daniel Sandler6396c722013-04-16 20:19:09 -04005853 if (info != null) {
5854 ai = info.activityInfo;
5855 }
5856 if (ai != null
5857 && ai.metaData != null
5858 && ai.metaData.getBoolean(Intent.METADATA_DOCK_HOME)) {
5859 intent = new Intent(intent);
5860 intent.setClassName(ai.packageName, ai.name);
5861 return intent;
5862 }
5863
5864 return null;
5865 }
5866
Bryce Lee01b0c5f2015-02-05 18:24:04 -08005867 void startDockOrHome(boolean fromHomeKey) {
John Spurlockc8b46ca2013-04-08 12:59:26 -04005868 awakenDreams();
Daniel Sandler6396c722013-04-16 20:19:09 -04005869
5870 Intent dock = createHomeDockIntent();
5871 if (dock != null) {
5872 try {
Bryce Lee01b0c5f2015-02-05 18:24:04 -08005873 if (fromHomeKey) {
5874 dock.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
5875 }
Daniel Sandler6396c722013-04-16 20:19:09 -04005876 mContext.startActivityAsUser(dock, UserHandle.CURRENT);
5877 return;
5878 } catch (ActivityNotFoundException e) {
5879 }
5880 }
5881
Bryce Lee01b0c5f2015-02-05 18:24:04 -08005882 Intent intent;
5883
5884 if (fromHomeKey) {
5885 intent = new Intent(mHomeIntent);
5886 intent.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
5887 } else {
5888 intent = mHomeIntent;
5889 }
5890
5891 mContext.startActivityAsUser(intent, UserHandle.CURRENT);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005892 }
Craig Mautnereda67292013-04-28 13:50:14 -07005893
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005894 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005895 * goes to the home screen
5896 * @return whether it did anything
5897 */
5898 boolean goHome() {
5899 if (false) {
5900 // This code always brings home to the front.
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07005901 try {
5902 ActivityManagerNative.getDefault().stopAppSwitches();
5903 } catch (RemoteException e) {
5904 }
Dianne Hackborn94a679d2009-07-28 17:51:07 -07005905 sendCloseSystemWindows();
Bryce Lee01b0c5f2015-02-05 18:24:04 -08005906 startDockOrHome(false /*fromHomeKey*/);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005907 } else {
5908 // This code brings home to the front or, if it is already
5909 // at the front, puts the device to sleep.
5910 try {
Wink Savilled2e6a332010-02-12 12:12:06 -08005911 if (SystemProperties.getInt("persist.sys.uts-test-mode", 0) == 1) {
5912 /// Roll back EndcallBehavior as the cupcake design to pass P1 lab entry.
5913 Log.d(TAG, "UTS-TEST-MODE");
5914 } else {
5915 ActivityManagerNative.getDefault().stopAppSwitches();
5916 sendCloseSystemWindows();
Daniel Sandler6396c722013-04-16 20:19:09 -04005917 Intent dock = createHomeDockIntent();
5918 if (dock != null) {
5919 int result = ActivityManagerNative.getDefault()
5920 .startActivityAsUser(null, null, dock,
5921 dock.resolveTypeIfNeeded(mContext.getContentResolver()),
5922 null, null, 0,
5923 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07005924 null, null, UserHandle.USER_CURRENT);
Daniel Sandler6396c722013-04-16 20:19:09 -04005925 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
5926 return false;
5927 }
5928 }
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005929 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005930 int result = ActivityManagerNative.getDefault()
Dianne Hackbornf265ea92013-01-31 15:00:51 -08005931 .startActivityAsUser(null, null, mHomeIntent,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005932 mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()),
Dianne Hackborna4972e92012-03-14 10:38:05 -07005933 null, null, 0,
5934 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07005935 null, null, UserHandle.USER_CURRENT);
Dianne Hackborna4972e92012-03-14 10:38:05 -07005936 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005937 return false;
5938 }
5939 } catch (RemoteException ex) {
5940 // bummer, the activity manager, which is in this process, is dead
5941 }
5942 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005943 return true;
5944 }
Craig Mautnereda67292013-04-28 13:50:14 -07005945
5946 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07005947 public void setCurrentOrientationLw(int newOrientation) {
5948 synchronized (mLock) {
5949 if (newOrientation != mCurrentAppOrientation) {
5950 mCurrentAppOrientation = newOrientation;
5951 updateOrientationListenerLp();
5952 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005953 }
5954 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08005955
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07005956 private void performAuditoryFeedbackForAccessibilityIfNeed() {
5957 if (!isGlobalAccessibilityGestureEnabled()) {
5958 return;
5959 }
5960 AudioManager audioManager = (AudioManager) mContext.getSystemService(
5961 Context.AUDIO_SERVICE);
5962 if (audioManager.isSilentMode()) {
5963 return;
5964 }
5965 Ringtone ringTone = RingtoneManager.getRingtone(mContext,
5966 Settings.System.DEFAULT_NOTIFICATION_URI);
5967 ringTone.setStreamType(AudioManager.STREAM_MUSIC);
5968 ringTone.play();
5969 }
Craig Mautnereda67292013-04-28 13:50:14 -07005970
Bryce Lee584a4452014-10-21 15:55:55 -07005971 private boolean isTheaterModeEnabled() {
5972 return Settings.Global.getInt(mContext.getContentResolver(),
5973 Settings.Global.THEATER_MODE_ON, 0) == 1;
5974 }
5975
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07005976 private boolean isGlobalAccessibilityGestureEnabled() {
5977 return Settings.Global.getInt(mContext.getContentResolver(),
5978 Settings.Global.ENABLE_ACCESSIBILITY_GLOBAL_GESTURE_ENABLED, 0) == 1;
5979 }
5980
Craig Mautnereda67292013-04-28 13:50:14 -07005981 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07005982 public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) {
Svetoslav Ganov96179212012-10-10 14:17:45 -07005983 if (!mVibrator.hasVibrator()) {
5984 return false;
5985 }
Christopher Tate5e08af02012-09-21 17:17:22 -07005986 final boolean hapticsDisabled = Settings.System.getIntForUser(mContext.getContentResolver(),
5987 Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) == 0;
Jeff Brown82379ba2014-07-25 19:03:28 -07005988 if (hapticsDisabled && !always) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005989 return false;
5990 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08005991 long[] pattern = null;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005992 switch (effectId) {
5993 case HapticFeedbackConstants.LONG_PRESS:
Amith Yamasanic33cb712010-02-10 15:21:49 -08005994 pattern = mLongPressVibePattern;
5995 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07005996 case HapticFeedbackConstants.VIRTUAL_KEY:
Amith Yamasanic33cb712010-02-10 15:21:49 -08005997 pattern = mVirtualKeyVibePattern;
5998 break;
5999 case HapticFeedbackConstants.KEYBOARD_TAP:
6000 pattern = mKeyboardTapVibePattern;
6001 break;
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07006002 case HapticFeedbackConstants.CLOCK_TICK:
6003 pattern = mClockTickVibePattern;
6004 break;
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07006005 case HapticFeedbackConstants.CALENDAR_DATE:
6006 pattern = mCalendarDateVibePattern;
6007 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006008 case HapticFeedbackConstants.SAFE_MODE_DISABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006009 pattern = mSafeModeDisabledVibePattern;
6010 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006011 case HapticFeedbackConstants.SAFE_MODE_ENABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006012 pattern = mSafeModeEnabledVibePattern;
6013 break;
Amith Yamasanic33cb712010-02-10 15:21:49 -08006014 default:
6015 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006016 }
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006017 int owningUid;
6018 String owningPackage;
6019 if (win != null) {
6020 owningUid = win.getOwningUid();
6021 owningPackage = win.getOwningPackage();
6022 } else {
6023 owningUid = android.os.Process.myUid();
Dianne Hackborn95d78532013-09-11 09:51:14 -07006024 owningPackage = mContext.getOpPackageName();
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006025 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006026 if (pattern.length == 1) {
6027 // One-shot vibration
John Spurlock7b414672014-07-18 13:02:39 -04006028 mVibrator.vibrate(owningUid, owningPackage, pattern[0], VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08006029 } else {
6030 // Pattern vibration
John Spurlock7b414672014-07-18 13:02:39 -04006031 mVibrator.vibrate(owningUid, owningPackage, pattern, -1, VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08006032 }
6033 return true;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006034 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07006035
6036 @Override
6037 public void keepScreenOnStartedLw() {
Daniel Sandler0601eb72011-04-13 01:01:32 -04006038 }
6039
Jeff Brownc38c9be2012-10-04 13:16:19 -07006040 @Override
6041 public void keepScreenOnStoppedLw() {
Jim Millerab954542014-10-10 18:21:49 -07006042 if (isKeyguardShowingAndNotOccluded()) {
Jim Miller25190572013-02-28 17:36:24 -08006043 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006044 }
6045 }
Mike Lockwoodfcb39242009-10-21 23:01:07 -04006046
Dianne Hackborndf89e652011-10-06 22:35:11 -07006047 private int updateSystemUiVisibilityLw() {
Joe Onorato664644d2011-01-23 17:53:23 -08006048 // If there is no window focused, there will be nobody to handle the events
6049 // anyway, so just hang on in whatever state we're in until things settle down.
Adrian Roos53f28ec2014-10-29 17:26:12 +01006050 final WindowState win = mFocusedWindow != null ? mFocusedWindow
6051 : mTopFullscreenOpaqueWindowState;
John Spurlock79da8332013-09-20 12:04:47 -04006052 if (win == null) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006053 return 0;
6054 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01006055 if ((win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 && mHideLockScreen == true) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07006056 // We are updating at a point where the keyguard has gotten
6057 // focus, but we were last in a state where the top window is
6058 // hiding it. This is probably because the keyguard as been
6059 // shown while the top window was displayed, so we want to ignore
6060 // it here because this is just a very transient change and it
6061 // will quickly lose focus once it correctly gets hidden.
6062 return 0;
6063 }
John Spurlock32beb2c2013-03-11 10:16:47 -04006064
John Spurlock1db8b682014-02-18 11:18:59 -05006065 int tmpVisibility = PolicyControl.getSystemUiVisibility(win, null)
Dianne Hackborne26ab702011-10-16 13:21:33 -07006066 & ~mResettingSystemUiFlags
6067 & ~mForceClearedSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04006068 if (mForcingShowNavBar && win.getSurfaceLayer() < mForcingShowNavBarLayer) {
John Spurlockc6d1c602014-01-17 15:22:06 -05006069 tmpVisibility &= ~PolicyControl.adjustClearableFlags(win, View.SYSTEM_UI_CLEARABLE_FLAGS);
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08006070 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01006071 tmpVisibility = updateLightStatusBarLw(tmpVisibility);
John Spurlock79da8332013-09-20 12:04:47 -04006072 final int visibility = updateSystemBarsLw(win, mLastSystemUiFlags, tmpVisibility);
John Spurlockad3e6cb2013-04-30 08:47:43 -04006073 final int diff = visibility ^ mLastSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04006074 final boolean needsMenu = win.getNeedsMenuLw(mTopFullscreenOpaqueWindowState);
Dianne Hackborne0f085d2011-11-30 18:41:15 -08006075 if (diff == 0 && mLastFocusNeedsMenu == needsMenu
John Spurlock79da8332013-09-20 12:04:47 -04006076 && mFocusedApp == win.getAppToken()) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006077 return 0;
6078 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07006079 mLastSystemUiFlags = visibility;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08006080 mLastFocusNeedsMenu = needsMenu;
John Spurlock79da8332013-09-20 12:04:47 -04006081 mFocusedApp = win.getAppToken();
Dianne Hackborndf89e652011-10-06 22:35:11 -07006082 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07006083 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07006084 public void run() {
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006085 try {
6086 IStatusBarService statusbar = getStatusBarService();
6087 if (statusbar != null) {
Adrian Roos53f28ec2014-10-29 17:26:12 +01006088 statusbar.setSystemUiVisibility(visibility, 0xffffffff, win.toString());
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006089 statusbar.topAppWindowChanged(needsMenu);
Joe Onorato664644d2011-01-23 17:53:23 -08006090 }
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006091 } catch (RemoteException e) {
6092 // re-acquire status bar service next time it is needed.
6093 mStatusBarService = null;
Joe Onorato664644d2011-01-23 17:53:23 -08006094 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07006095 }
6096 });
6097 return diff;
Joe Onorato664644d2011-01-23 17:53:23 -08006098 }
6099
Adrian Rooscd3884d2015-02-18 17:25:23 +01006100 private int updateLightStatusBarLw(int vis) {
6101 WindowState statusColorWin = isStatusBarKeyguard() && !mHideLockScreen
6102 ? mStatusBar
6103 : mTopFullscreenOpaqueOrDimmingWindowState;
6104
6105 if (statusColorWin != null) {
6106 if (statusColorWin == mTopFullscreenOpaqueWindowState) {
6107 // If the top fullscreen-or-dimming window is also the top fullscreen, respect
6108 // its light flag.
6109 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6110 vis |= PolicyControl.getSystemUiVisibility(statusColorWin, null)
6111 & View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6112 } else if (statusColorWin != null && statusColorWin.isDimming()) {
6113 // Otherwise if it's dimming, clear the light flag.
6114 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6115 }
6116 }
6117 return vis;
6118 }
6119
John Spurlock79da8332013-09-20 12:04:47 -04006120 private int updateSystemBarsLw(WindowState win, int oldVis, int vis) {
John Spurlockbd957402013-10-03 11:38:39 -04006121 // apply translucent bar vis flags
Jorim Jaggi380ecb82014-03-14 17:25:20 +01006122 WindowState transWin = isStatusBarKeyguard() && !mHideLockScreen
6123 ? mStatusBar
John Spurlockbd957402013-10-03 11:38:39 -04006124 : mTopFullscreenOpaqueWindowState;
6125 vis = mStatusBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
6126 vis = mNavigationBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
6127
John Spurlock27735a42013-08-14 17:57:38 -04006128 // prevent status bar interaction from clearing certain flags
John Spurlock79da8332013-09-20 12:04:47 -04006129 boolean statusBarHasFocus = win.getAttrs().type == TYPE_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04006130 if (statusBarHasFocus && !isStatusBarKeyguard()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04006131 int flags = View.SYSTEM_UI_FLAG_FULLSCREEN
6132 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlockcfc359a2013-09-05 10:42:03 -04006133 | View.SYSTEM_UI_FLAG_IMMERSIVE
Jorim Jaggi73fef8d2015-02-16 17:32:28 +01006134 | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
6135 | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04006136 if (mHideLockScreen) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01006137 flags |= View.STATUS_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSLUCENT;
6138 }
John Spurlockbd957402013-10-03 11:38:39 -04006139 vis = (vis & ~flags) | (oldVis & flags);
John Spurlockad3e6cb2013-04-30 08:47:43 -04006140 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04006141
Adrian Roos4fb3ee32014-08-22 19:29:09 +02006142 if (!areTranslucentBarsAllowed() && transWin != mStatusBar) {
Adrian Roosea562512014-05-05 13:33:03 +02006143 vis &= ~(View.NAVIGATION_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSLUCENT
6144 | View.SYSTEM_UI_TRANSPARENT);
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006145 }
6146
John Spurlock27735a42013-08-14 17:57:38 -04006147 // update status bar
John Spurlockf1a36642013-10-12 17:50:42 -04006148 boolean immersiveSticky =
6149 (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
John Spurlock27735a42013-08-14 17:57:38 -04006150 boolean hideStatusBarWM =
John Spurlockbd957402013-10-03 11:38:39 -04006151 mTopFullscreenOpaqueWindowState != null &&
John Spurlockc6d1c602014-01-17 15:22:06 -05006152 (PolicyControl.getWindowFlags(mTopFullscreenOpaqueWindowState, null)
John Spurlock27735a42013-08-14 17:57:38 -04006153 & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0;
6154 boolean hideStatusBarSysui =
6155 (vis & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04006156 boolean hideNavBarSysui =
6157 (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006158
John Spurlock27735a42013-08-14 17:57:38 -04006159 boolean transientStatusBarAllowed =
6160 mStatusBar != null && (
6161 hideStatusBarWM
John Spurlockf1a36642013-10-12 17:50:42 -04006162 || (hideStatusBarSysui && immersiveSticky)
John Spurlock27735a42013-08-14 17:57:38 -04006163 || statusBarHasFocus);
6164
John Spurlockf1a36642013-10-12 17:50:42 -04006165 boolean transientNavBarAllowed =
6166 mNavigationBar != null &&
6167 hideNavBarSysui && immersiveSticky;
6168
John Spurlockf25706f2013-11-07 18:02:43 -05006169 boolean denyTransientStatus = mStatusBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04006170 && !transientStatusBarAllowed && hideStatusBarSysui;
John Spurlockf25706f2013-11-07 18:02:43 -05006171 boolean denyTransientNav = mNavigationBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04006172 && !transientNavBarAllowed;
6173 if (denyTransientStatus || denyTransientNav) {
John Spurlock27735a42013-08-14 17:57:38 -04006174 // clear the clearable flags instead
John Spurlockf1a36642013-10-12 17:50:42 -04006175 clearClearableFlagsLw();
tiger_huangc58d7562014-10-23 20:24:19 +08006176 vis &= ~View.SYSTEM_UI_CLEARABLE_FLAGS;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006177 }
John Spurlock27735a42013-08-14 17:57:38 -04006178
6179 vis = mStatusBarController.updateVisibilityLw(transientStatusBarAllowed, oldVis, vis);
6180
6181 // update navigation bar
John Spurlockf1a36642013-10-12 17:50:42 -04006182 boolean oldImmersiveMode = isImmersiveMode(oldVis);
6183 boolean newImmersiveMode = isImmersiveMode(vis);
6184 if (win != null && oldImmersiveMode != newImmersiveMode) {
John Spurlock79da8332013-09-20 12:04:47 -04006185 final String pkg = win.getOwningPackage();
Maurice Lam99c6e072014-04-28 18:24:28 -07006186 mImmersiveModeConfirmation.immersiveModeChanged(pkg, newImmersiveMode,
6187 isUserSetupComplete());
John Spurlock34e13d92013-08-10 06:52:28 -04006188 }
John Spurlock27735a42013-08-14 17:57:38 -04006189
John Spurlockf1a36642013-10-12 17:50:42 -04006190 vis = mNavigationBarController.updateVisibilityLw(transientNavBarAllowed, oldVis, vis);
6191
John Spurlocke1f366f2013-08-05 12:22:40 -04006192 return vis;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006193 }
6194
John Spurlockf1a36642013-10-12 17:50:42 -04006195 private void clearClearableFlagsLw() {
6196 int newVal = mResettingSystemUiFlags | View.SYSTEM_UI_CLEARABLE_FLAGS;
6197 if (newVal != mResettingSystemUiFlags) {
6198 mResettingSystemUiFlags = newVal;
6199 mWindowManagerFuncs.reevaluateStatusBarVisibility();
6200 }
6201 }
6202
6203 private boolean isImmersiveMode(int vis) {
6204 final int flags = View.SYSTEM_UI_FLAG_IMMERSIVE | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
John Spurlock34e13d92013-08-10 06:52:28 -04006205 return mNavigationBar != null
6206 && (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0
Daniel Sandler900ece52013-10-18 15:53:27 -04006207 && (vis & flags) != 0
6208 && canHideNavigationBar();
John Spurlock34e13d92013-08-10 06:52:28 -04006209 }
6210
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006211 /**
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04006212 * @return whether the navigation or status bar can be made translucent
6213 *
6214 * This should return true unless touch exploration is not enabled or
6215 * R.boolean.config_enableTranslucentDecor is false.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006216 */
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04006217 private boolean areTranslucentBarsAllowed() {
Svetoslav8e3feb12014-02-24 13:46:47 -08006218 return mTranslucentDecorEnabled
6219 && !mAccessibilityManager.isTouchExplorationEnabled();
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006220 }
6221
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04006222 // Use this instead of checking config_showNavigationBar so that it can be consistently
6223 // overridden by qemu.hw.mainkeys in the emulator.
Craig Mautnereda67292013-04-28 13:50:14 -07006224 @Override
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04006225 public boolean hasNavigationBar() {
6226 return mHasNavigationBar;
6227 }
6228
satok1bc0a492012-04-25 22:47:12 +09006229 @Override
6230 public void setLastInputMethodWindowLw(WindowState ime, WindowState target) {
6231 mLastInputMethodWindow = ime;
6232 mLastInputMethodTargetWindow = target;
6233 }
6234
Craig Mautnerf1b67412012-09-19 13:18:29 -07006235 @Override
Satoshi Kataoka658c7b82013-10-10 17:03:51 +09006236 public int getInputMethodWindowVisibleHeightLw() {
6237 return mDockBottom - mCurBottom;
6238 }
6239
6240 @Override
Craig Mautnerf1b67412012-09-19 13:18:29 -07006241 public void setCurrentUserLw(int newUserId) {
Craig Mautnerd625ab22013-09-06 13:40:31 -07006242 mCurrentUserId = newUserId;
Jim Miller5ecd8112013-01-09 18:50:26 -08006243 if (mKeyguardDelegate != null) {
6244 mKeyguardDelegate.setCurrentUser(newUserId);
Craig Mautnerf1b67412012-09-19 13:18:29 -07006245 }
John Spurlock13451a22012-09-28 14:40:41 -04006246 if (mStatusBarService != null) {
6247 try {
6248 mStatusBarService.setCurrentUser(newUserId);
6249 } catch (RemoteException e) {
6250 // oh well
6251 }
6252 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006253 setLastInputMethodWindowLw(null, null);
Craig Mautnerf1b67412012-09-19 13:18:29 -07006254 }
6255
6256 @Override
Svetoslav Ganov545252f2012-12-10 18:29:24 -08006257 public boolean canMagnifyWindow(int windowType) {
6258 switch (windowType) {
6259 case WindowManager.LayoutParams.TYPE_INPUT_METHOD:
6260 case WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG:
6261 case WindowManager.LayoutParams.TYPE_NAVIGATION_BAR:
6262 case WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY: {
6263 return false;
6264 }
6265 }
6266 return true;
6267 }
6268
6269 @Override
6270 public boolean isTopLevelWindow(int windowType) {
6271 if (windowType >= WindowManager.LayoutParams.FIRST_SUB_WINDOW
6272 && windowType <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
6273 return (windowType == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG);
6274 }
6275 return true;
6276 }
6277
Jim Miller4eeb4f62012-11-08 00:04:29 -08006278 @Override
Jeff Brownd7a04de2012-06-17 14:17:52 -07006279 public void dump(String prefix, PrintWriter pw, String[] args) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006280 pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07006281 pw.print(" mSystemReady="); pw.print(mSystemReady);
6282 pw.print(" mSystemBooted="); pw.println(mSystemBooted);
Jeff Brown2e7760e2012-04-11 15:14:55 -07006283 pw.print(prefix); pw.print("mLidState="); pw.print(mLidState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006284 pw.print(" mLidOpenRotation="); pw.print(mLidOpenRotation);
Michael Wright3818c922014-09-02 13:59:07 -07006285 pw.print(" mCameraLensCoverState="); pw.print(mCameraLensCoverState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006286 pw.print(" mHdmiPlugged="); pw.println(mHdmiPlugged);
Dianne Hackborne26ab702011-10-16 13:21:33 -07006287 if (mLastSystemUiFlags != 0 || mResettingSystemUiFlags != 0
6288 || mForceClearedSystemUiFlags != 0) {
6289 pw.print(prefix); pw.print("mLastSystemUiFlags=0x");
6290 pw.print(Integer.toHexString(mLastSystemUiFlags));
6291 pw.print(" mResettingSystemUiFlags=0x");
6292 pw.print(Integer.toHexString(mResettingSystemUiFlags));
6293 pw.print(" mForceClearedSystemUiFlags=0x");
6294 pw.println(Integer.toHexString(mForceClearedSystemUiFlags));
Dianne Hackborndf89e652011-10-06 22:35:11 -07006295 }
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08006296 if (mLastFocusNeedsMenu) {
6297 pw.print(prefix); pw.print("mLastFocusNeedsMenu=");
6298 pw.println(mLastFocusNeedsMenu);
6299 }
Jeff Browna20dda42014-05-27 20:57:24 -07006300 pw.print(prefix); pw.print("mWakeGestureEnabledSetting=");
6301 pw.println(mWakeGestureEnabledSetting);
6302
Jeff Brownbcdfc622014-03-06 19:13:04 -08006303 pw.print(prefix); pw.print("mSupportAutoRotation="); pw.println(mSupportAutoRotation);
Daniel Sandler6396c722013-04-16 20:19:09 -04006304 pw.print(prefix); pw.print("mUiMode="); pw.print(mUiMode);
6305 pw.print(" mDockMode="); pw.print(mDockMode);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006306 pw.print(" mCarDockRotation="); pw.print(mCarDockRotation);
6307 pw.print(" mDeskDockRotation="); pw.println(mDeskDockRotation);
6308 pw.print(prefix); pw.print("mUserRotationMode="); pw.print(mUserRotationMode);
6309 pw.print(" mUserRotation="); pw.print(mUserRotation);
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05006310 pw.print(" mAllowAllRotations="); pw.println(mAllowAllRotations);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07006311 pw.print(prefix); pw.print("mCurrentAppOrientation="); pw.println(mCurrentAppOrientation);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006312 pw.print(prefix); pw.print("mCarDockEnablesAccelerometer=");
6313 pw.print(mCarDockEnablesAccelerometer);
6314 pw.print(" mDeskDockEnablesAccelerometer=");
6315 pw.println(mDeskDockEnablesAccelerometer);
6316 pw.print(prefix); pw.print("mLidKeyboardAccessibility=");
6317 pw.print(mLidKeyboardAccessibility);
6318 pw.print(" mLidNavigationAccessibility="); pw.print(mLidNavigationAccessibility);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07006319 pw.print(" mLidControlsSleep="); pw.println(mLidControlsSleep);
Jeff Brown6d8fd272014-05-20 21:24:38 -07006320 pw.print(prefix);
6321 pw.print("mShortPressOnPowerBehavior="); pw.print(mShortPressOnPowerBehavior);
6322 pw.print(" mLongPressOnPowerBehavior="); pw.println(mLongPressOnPowerBehavior);
Jeff Brown13f00f02014-10-31 14:45:50 -07006323 pw.print(prefix);
6324 pw.print("mDoublePressOnPowerBehavior="); pw.print(mDoublePressOnPowerBehavior);
6325 pw.print(" mTriplePressOnPowerBehavior="); pw.println(mTriplePressOnPowerBehavior);
Jeff Brown6d8fd272014-05-20 21:24:38 -07006326 pw.print(prefix); pw.print("mHasSoftInput="); pw.println(mHasSoftInput);
Jeff Brown3ee549c2014-09-22 20:14:39 -07006327 pw.print(prefix); pw.print("mAwake="); pw.println(mAwake);
6328 pw.print(prefix); pw.print("mScreenOnEarly="); pw.print(mScreenOnEarly);
6329 pw.print(" mScreenOnFully="); pw.println(mScreenOnFully);
6330 pw.print(prefix); pw.print("mKeyguardDrawComplete="); pw.print(mKeyguardDrawComplete);
6331 pw.print(" mWindowManagerDrawComplete="); pw.println(mWindowManagerDrawComplete);
6332 pw.print(prefix); pw.print("mOrientationSensorEnabled=");
6333 pw.println(mOrientationSensorEnabled);
Dianne Hackbornc652de82013-02-15 16:32:56 -08006334 pw.print(prefix); pw.print("mOverscanScreen=("); pw.print(mOverscanScreenLeft);
6335 pw.print(","); pw.print(mOverscanScreenTop);
6336 pw.print(") "); pw.print(mOverscanScreenWidth);
6337 pw.print("x"); pw.println(mOverscanScreenHeight);
6338 if (mOverscanLeft != 0 || mOverscanTop != 0
6339 || mOverscanRight != 0 || mOverscanBottom != 0) {
6340 pw.print(prefix); pw.print("mOverscan left="); pw.print(mOverscanLeft);
6341 pw.print(" top="); pw.print(mOverscanTop);
6342 pw.print(" right="); pw.print(mOverscanRight);
6343 pw.print(" bottom="); pw.println(mOverscanBottom);
6344 }
Dianne Hackborn313440842013-02-19 19:22:59 -08006345 pw.print(prefix); pw.print("mRestrictedOverscanScreen=(");
6346 pw.print(mRestrictedOverscanScreenLeft);
6347 pw.print(","); pw.print(mRestrictedOverscanScreenTop);
6348 pw.print(") "); pw.print(mRestrictedOverscanScreenWidth);
6349 pw.print("x"); pw.println(mRestrictedOverscanScreenHeight);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006350 pw.print(prefix); pw.print("mUnrestrictedScreen=("); pw.print(mUnrestrictedScreenLeft);
6351 pw.print(","); pw.print(mUnrestrictedScreenTop);
6352 pw.print(") "); pw.print(mUnrestrictedScreenWidth);
6353 pw.print("x"); pw.println(mUnrestrictedScreenHeight);
6354 pw.print(prefix); pw.print("mRestrictedScreen=("); pw.print(mRestrictedScreenLeft);
6355 pw.print(","); pw.print(mRestrictedScreenTop);
6356 pw.print(") "); pw.print(mRestrictedScreenWidth);
6357 pw.print("x"); pw.println(mRestrictedScreenHeight);
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07006358 pw.print(prefix); pw.print("mStableFullscreen=("); pw.print(mStableFullscreenLeft);
6359 pw.print(","); pw.print(mStableFullscreenTop);
6360 pw.print(")-("); pw.print(mStableFullscreenRight);
6361 pw.print(","); pw.print(mStableFullscreenBottom); pw.println(")");
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07006362 pw.print(prefix); pw.print("mStable=("); pw.print(mStableLeft);
6363 pw.print(","); pw.print(mStableTop);
6364 pw.print(")-("); pw.print(mStableRight);
6365 pw.print(","); pw.print(mStableBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07006366 pw.print(prefix); pw.print("mSystem=("); pw.print(mSystemLeft);
6367 pw.print(","); pw.print(mSystemTop);
6368 pw.print(")-("); pw.print(mSystemRight);
6369 pw.print(","); pw.print(mSystemBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006370 pw.print(prefix); pw.print("mCur=("); pw.print(mCurLeft);
6371 pw.print(","); pw.print(mCurTop);
6372 pw.print(")-("); pw.print(mCurRight);
6373 pw.print(","); pw.print(mCurBottom); pw.println(")");
6374 pw.print(prefix); pw.print("mContent=("); pw.print(mContentLeft);
6375 pw.print(","); pw.print(mContentTop);
6376 pw.print(")-("); pw.print(mContentRight);
6377 pw.print(","); pw.print(mContentBottom); pw.println(")");
Dianne Hackborne30e02f2014-05-27 18:24:45 -07006378 pw.print(prefix); pw.print("mVoiceContent=("); pw.print(mVoiceContentLeft);
6379 pw.print(","); pw.print(mVoiceContentTop);
6380 pw.print(")-("); pw.print(mVoiceContentRight);
6381 pw.print(","); pw.print(mVoiceContentBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006382 pw.print(prefix); pw.print("mDock=("); pw.print(mDockLeft);
6383 pw.print(","); pw.print(mDockTop);
6384 pw.print(")-("); pw.print(mDockRight);
6385 pw.print(","); pw.print(mDockBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07006386 pw.print(prefix); pw.print("mDockLayer="); pw.print(mDockLayer);
6387 pw.print(" mStatusBarLayer="); pw.println(mStatusBarLayer);
Dianne Hackborn7ad44382012-10-18 17:46:00 -07006388 pw.print(prefix); pw.print("mShowingLockscreen="); pw.print(mShowingLockscreen);
6389 pw.print(" mShowingDream="); pw.print(mShowingDream);
6390 pw.print(" mDreamingLockscreen="); pw.println(mDreamingLockscreen);
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006391 if (mLastInputMethodWindow != null) {
6392 pw.print(prefix); pw.print("mLastInputMethodWindow=");
6393 pw.println(mLastInputMethodWindow);
6394 }
6395 if (mLastInputMethodTargetWindow != null) {
6396 pw.print(prefix); pw.print("mLastInputMethodTargetWindow=");
6397 pw.println(mLastInputMethodTargetWindow);
6398 }
6399 if (mStatusBar != null) {
6400 pw.print(prefix); pw.print("mStatusBar=");
Dianne Hackbornae6688b2015-02-11 17:02:41 -08006401 pw.print(mStatusBar); pw.print(" isStatusBarKeyguard=");
6402 pw.println(isStatusBarKeyguard());
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006403 }
6404 if (mNavigationBar != null) {
6405 pw.print(prefix); pw.print("mNavigationBar=");
6406 pw.println(mNavigationBar);
6407 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006408 if (mFocusedWindow != null) {
6409 pw.print(prefix); pw.print("mFocusedWindow=");
6410 pw.println(mFocusedWindow);
6411 }
6412 if (mFocusedApp != null) {
6413 pw.print(prefix); pw.print("mFocusedApp=");
6414 pw.println(mFocusedApp);
6415 }
6416 if (mWinDismissingKeyguard != null) {
6417 pw.print(prefix); pw.print("mWinDismissingKeyguard=");
6418 pw.println(mWinDismissingKeyguard);
6419 }
6420 if (mTopFullscreenOpaqueWindowState != null) {
6421 pw.print(prefix); pw.print("mTopFullscreenOpaqueWindowState=");
6422 pw.println(mTopFullscreenOpaqueWindowState);
6423 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01006424 if (mTopFullscreenOpaqueOrDimmingWindowState != null) {
6425 pw.print(prefix); pw.print("mTopFullscreenOpaqueOrDimmingWindowState=");
6426 pw.println(mTopFullscreenOpaqueOrDimmingWindowState);
6427 }
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08006428 if (mForcingShowNavBar) {
6429 pw.print(prefix); pw.print("mForcingShowNavBar=");
6430 pw.println(mForcingShowNavBar); pw.print( "mForcingShowNavBarLayer=");
6431 pw.println(mForcingShowNavBarLayer);
6432 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07006433 pw.print(prefix); pw.print("mTopIsFullscreen="); pw.print(mTopIsFullscreen);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006434 pw.print(" mHideLockScreen="); pw.println(mHideLockScreen);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07006435 pw.print(prefix); pw.print("mForceStatusBar="); pw.print(mForceStatusBar);
6436 pw.print(" mForceStatusBarFromKeyguard=");
6437 pw.println(mForceStatusBarFromKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006438 pw.print(prefix); pw.print("mDismissKeyguard="); pw.print(mDismissKeyguard);
Craig Mautnerad09bcc2012-10-08 13:33:11 -07006439 pw.print(" mWinDismissingKeyguard="); pw.print(mWinDismissingKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006440 pw.print(" mHomePressed="); pw.println(mHomePressed);
6441 pw.print(prefix); pw.print("mAllowLockscreenWhenOn="); pw.print(mAllowLockscreenWhenOn);
6442 pw.print(" mLockScreenTimeout="); pw.print(mLockScreenTimeout);
6443 pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive);
6444 pw.print(prefix); pw.print("mEndcallBehavior="); pw.print(mEndcallBehavior);
6445 pw.print(" mIncallPowerBehavior="); pw.print(mIncallPowerBehavior);
6446 pw.print(" mLongPressOnHomeBehavior="); pw.println(mLongPressOnHomeBehavior);
6447 pw.print(prefix); pw.print("mLandscapeRotation="); pw.print(mLandscapeRotation);
6448 pw.print(" mSeascapeRotation="); pw.println(mSeascapeRotation);
6449 pw.print(prefix); pw.print("mPortraitRotation="); pw.print(mPortraitRotation);
6450 pw.print(" mUpsideDownRotation="); pw.println(mUpsideDownRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07006451 pw.print(prefix); pw.print("mDemoHdmiRotation="); pw.print(mDemoHdmiRotation);
6452 pw.print(" mDemoHdmiRotationLock="); pw.println(mDemoHdmiRotationLock);
6453 pw.print(prefix); pw.print("mUndockedHdmiRotation="); pw.println(mUndockedHdmiRotation);
Jeff Brown600f0032014-05-22 17:06:00 -07006454
Tim Kilbournd7c0c2e2014-05-29 16:08:10 -07006455 mGlobalKeyManager.dump(prefix, pw);
John Spurlock27735a42013-08-14 17:57:38 -04006456 mStatusBarController.dump(pw, prefix);
6457 mNavigationBarController.dump(pw, prefix);
John Spurlockc6d1c602014-01-17 15:22:06 -05006458 PolicyControl.dump(prefix, pw);
Jeff Brown600f0032014-05-22 17:06:00 -07006459
Jeff Browna20dda42014-05-27 20:57:24 -07006460 if (mWakeGestureListener != null) {
6461 mWakeGestureListener.dump(pw, prefix);
6462 }
Jeff Brown600f0032014-05-22 17:06:00 -07006463 if (mOrientationListener != null) {
6464 mOrientationListener.dump(pw, prefix);
6465 }
Filip Gruszczynskicfb31852015-02-25 21:47:12 +00006466 if (mBurnInProtectionHelper != null) {
6467 mBurnInProtectionHelper.dump(prefix, pw);
6468 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006469 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006470}