blob: a6793584b6ba297b05472c5446139385888e318c [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;
Jeff Brown061ea992015-04-17 19:55:47 -070020import android.app.ActivityManagerInternal;
21import android.app.ActivityManagerInternal.SleepToken;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080022import android.app.ActivityManagerNative;
Dianne Hackbornc2293022013-02-06 23:14:49 -080023import android.app.AppOpsManager;
Daniel Sandler6396c722013-04-16 20:19:09 -040024import android.app.IUiModeManager;
Dianne Hackborn661cd522011-08-22 00:26:20 -070025import android.app.ProgressDialog;
Jeff Brownde7a8ea2012-06-13 18:28:57 -070026import android.app.SearchManager;
John Spurlock97642182013-07-29 17:58:39 -040027import android.app.StatusBarManager;
Dianne Hackborn78968392010-03-04 20:47:56 -080028import android.app.UiModeManager;
Dianne Hackborn39c2d712009-09-22 11:41:31 -070029import android.content.ActivityNotFoundException;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080030import android.content.BroadcastReceiver;
Daniel Sandler0601eb72011-04-13 01:01:32 -040031import android.content.ComponentName;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080032import android.content.ContentResolver;
33import android.content.Context;
34import android.content.Intent;
Mike Lockwood1753f7f2009-08-24 14:49:07 -070035import android.content.IntentFilter;
Winson Chung9112ec32011-06-27 13:15:32 -070036import android.content.ServiceConnection;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080037import android.content.pm.ActivityInfo;
38import android.content.pm.PackageManager;
Daniel Sandler6396c722013-04-16 20:19:09 -040039import android.content.pm.ResolveInfo;
Dianne Hackborn2f0b1752011-05-31 17:59:49 -070040import android.content.res.CompatibilityInfo;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080041import android.content.res.Configuration;
42import android.content.res.Resources;
Craig Mautner8e4df6c2012-05-23 16:57:23 -070043import android.content.res.TypedArray;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080044import android.database.ContentObserver;
Dianne Hackbornc777e072010-02-12 13:07:59 -080045import android.graphics.PixelFormat;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080046import android.graphics.Rect;
John Spurlock7b414672014-07-18 13:02:39 -040047import android.media.AudioAttributes;
Michael Jurka7a348952012-02-27 13:07:58 -080048import android.media.AudioManager;
John Spurlock61560172015-02-06 19:46:04 -050049import android.media.AudioSystem;
Michael Jurka7a348952012-02-27 13:07:58 -080050import android.media.IAudioService;
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -070051import android.media.Ringtone;
52import android.media.RingtoneManager;
RoboErik8a2cfc32014-05-16 11:19:38 -070053import android.media.session.MediaSessionLegacyHelper;
Dianne Hackborn38e29a62011-09-18 14:43:08 -070054import android.os.Bundle;
Craig Mautner276a6eb2014-11-04 15:32:57 -080055import android.os.Debug;
Jeff Brown9a538ee2012-08-20 14:56:57 -070056import android.os.FactoryTest;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080057import android.os.Handler;
58import android.os.IBinder;
Jeff Brown32cbc38552011-12-01 14:01:49 -080059import android.os.Looper;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -070060import android.os.Message;
61import android.os.Messenger;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080062import android.os.PowerManager;
63import android.os.RemoteException;
64import android.os.ServiceManager;
65import android.os.SystemClock;
66import android.os.SystemProperties;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -080067import android.os.UEventObserver;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -070068import android.os.UserHandle;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080069import android.os.Vibrator;
Michael Wright3818c922014-09-02 13:59:07 -070070import android.provider.MediaStore;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080071import android.provider.Settings;
Jose Lima9546b202014-07-02 17:21:51 -070072import android.service.dreams.DreamManagerInternal;
John Spurlockc8b46ca2013-04-08 12:59:26 -040073import android.service.dreams.DreamService;
74import android.service.dreams.IDreamManager;
Michael Wrightdc63f7b2014-08-21 19:05:21 -070075import android.speech.RecognizerIntent;
Tyler Gunnef9f6f92014-09-12 22:16:17 -070076import android.telecom.TelecomManager;
Dianne Hackborn81e56d52011-05-26 00:55:58 -070077import android.util.DisplayMetrics;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080078import android.util.EventLog;
79import android.util.Log;
Jeff Browna41ca772010-08-11 14:46:32 -070080import android.util.Slog;
Jeff Brown6651a632011-11-28 12:59:11 -080081import android.util.SparseArray;
Dianne Hackbornf87d1962012-04-04 12:48:24 -070082import android.view.Display;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080083import android.view.Gravity;
84import android.view.HapticFeedbackConstants;
Dianne Hackborne0f085d2011-11-30 18:41:15 -080085import android.view.IApplicationToken;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080086import android.view.IWindowManager;
Jeff Browna41ca772010-08-11 14:46:32 -070087import android.view.InputChannel;
Jeff Brown4d396052010-10-29 21:50:21 -070088import android.view.InputDevice;
Jeff Brown4952dfd2011-11-30 19:23:22 -080089import android.view.InputEvent;
Jeff Brown32cbc38552011-12-01 14:01:49 -080090import android.view.InputEventReceiver;
Jeff Brown6b53e8d2010-11-10 16:03:06 -080091import android.view.KeyCharacterMap;
Craig Mautnerae446592012-12-06 19:05:05 -080092import android.view.KeyCharacterMap.FallbackAction;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080093import android.view.KeyEvent;
94import android.view.MotionEvent;
Adam Powell6711f3b2015-05-06 15:57:09 -070095import com.android.internal.policy.PhoneWindow;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080096import android.view.Surface;
97import android.view.View;
98import android.view.ViewConfiguration;
99import android.view.Window;
100import android.view.WindowManager;
Craig Mautnerae446592012-12-06 19:05:05 -0800101import android.view.WindowManagerGlobal;
Craig Mautner8a0da012014-05-31 15:13:37 -0700102import android.view.WindowManagerInternal;
Craig Mautnerae446592012-12-06 19:05:05 -0800103import android.view.WindowManagerPolicy;
Craig Mautnerae446592012-12-06 19:05:05 -0800104import android.view.accessibility.AccessibilityEvent;
Svetoslav8e3feb12014-02-24 13:46:47 -0800105import android.view.accessibility.AccessibilityManager;
Craig Mautnerae446592012-12-06 19:05:05 -0800106import android.view.animation.Animation;
Jorim Jaggi76a16232014-08-08 17:00:47 +0200107import android.view.animation.AnimationSet;
Craig Mautnerae446592012-12-06 19:05:05 -0800108import android.view.animation.AnimationUtils;
Craig Mautnerae446592012-12-06 19:05:05 -0800109import com.android.internal.R;
Craig Mautnerae446592012-12-06 19:05:05 -0800110import com.android.internal.statusbar.IStatusBarService;
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700111import com.android.internal.util.ScreenShapeHelper;
Craig Mautnerae446592012-12-06 19:05:05 -0800112import com.android.internal.widget.PointerLocationView;
Craig Mautner8a0da012014-05-31 15:13:37 -0700113import com.android.server.LocalServices;
Jorim Jaggib10e33f2015-02-04 21:57:40 +0100114import com.android.server.policy.keyguard.KeyguardServiceDelegate;
115import com.android.server.policy.keyguard.KeyguardServiceDelegate.ShowListener;
Craig Mautnerae446592012-12-06 19:05:05 -0800116
117import java.io.File;
118import java.io.FileReader;
119import java.io.IOException;
120import java.io.PrintWriter;
Craig Mautner2bc789b2014-03-19 19:48:38 -0700121import java.util.HashSet;
Craig Mautner276a6eb2014-11-04 15:32:57 -0800122import java.util.List;
Craig Mautnerae446592012-12-06 19:05:05 -0800123
Dianne Hackbornc652de82013-02-15 16:32:56 -0800124import static android.view.WindowManager.LayoutParams.*;
Jeff Brownac143512012-04-05 18:57:33 -0700125import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_ABSENT;
126import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_OPEN;
127import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_CLOSED;
Michael Wright3818c922014-09-02 13:59:07 -0700128import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVER_ABSENT;
129import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_UNCOVERED;
130import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVERED;
Dianne Hackborn08743722009-12-21 12:16:51 -0800131
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800132/**
The Android Open Source Project0727d222009-03-11 12:11:58 -0700133 * WindowManagerPolicy implementation for the Android phone UI. This
134 * introduces a new method suffix, Lp, for an internal lock of the
135 * PhoneWindowManager. This is used to protect some internal state, and
John Spurlock04db1762013-05-13 12:46:41 -0400136 * 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 -0700137 * of both of those when held.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800138 */
139public class PhoneWindowManager implements WindowManagerPolicy {
140 static final String TAG = "WindowManager";
141 static final boolean DEBUG = false;
Joe Onorato43a17652011-04-06 19:22:23 -0700142 static final boolean localLOGV = false;
Jeff Brown40013652012-05-16 21:22:36 -0700143 static final boolean DEBUG_INPUT = false;
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -0700144 static final boolean DEBUG_KEYGUARD = false;
145 static final boolean DEBUG_LAYOUT = false;
Craig Mautner6fbda632012-07-03 09:26:39 -0700146 static final boolean DEBUG_STARTING_WINDOW = false;
Craig Mautner8a0da012014-05-31 15:13:37 -0700147 static final boolean DEBUG_WAKEUP = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800148 static final boolean SHOW_STARTING_ANIMATIONS = true;
149 static final boolean SHOW_PROCESSES_ON_ALT_MENU = false;
Joe Onoratod208e702010-10-08 16:22:43 -0400150
Daniel Sandler6396c722013-04-16 20:19:09 -0400151 // Whether to allow dock apps with METADATA_DOCK_HOME to temporarily take over the Home key.
152 // No longer recommended for desk docks; still useful in car docks.
153 static final boolean ENABLE_CAR_DOCK_HOME_CAPTURE = true;
154 static final boolean ENABLE_DESK_DOCK_HOME_CAPTURE = false;
155
Jeff Brown6d8fd272014-05-20 21:24:38 -0700156 static final int SHORT_PRESS_POWER_NOTHING = 0;
157 static final int SHORT_PRESS_POWER_GO_TO_SLEEP = 1;
158 static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP = 2;
159 static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME = 3;
Bryce Lee01b0c5f2015-02-05 18:24:04 -0800160 static final int SHORT_PRESS_POWER_GO_HOME = 4;
Jeff Brown6d8fd272014-05-20 21:24:38 -0700161
Joe Onoratod208e702010-10-08 16:22:43 -0400162 static final int LONG_PRESS_POWER_NOTHING = 0;
163 static final int LONG_PRESS_POWER_GLOBAL_ACTIONS = 1;
164 static final int LONG_PRESS_POWER_SHUT_OFF = 2;
Jeff Brown9a538ee2012-08-20 14:56:57 -0700165 static final int LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM = 3;
Michael Jurka3b1fc472011-06-13 10:54:40 -0700166
Jeff Brown13f00f02014-10-31 14:45:50 -0700167 static final int MULTI_PRESS_POWER_NOTHING = 0;
168 static final int MULTI_PRESS_POWER_THEATER_MODE = 1;
169 static final int MULTI_PRESS_POWER_BRIGHTNESS_BOOST = 2;
170
Michael Jurka3b1fc472011-06-13 10:54:40 -0700171 // These need to match the documentation/constant in
172 // core/res/res/values/config.xml
Joe Onorato46b0d682010-11-22 17:37:27 -0800173 static final int LONG_PRESS_HOME_NOTHING = 0;
Michael Wrightc9ebea72013-01-16 19:25:02 -0800174 static final int LONG_PRESS_HOME_RECENT_SYSTEM_UI = 1;
Jeff Browncaca8812013-05-09 13:34:33 -0700175 static final int LONG_PRESS_HOME_ASSIST = 2;
176
177 static final int DOUBLE_TAP_HOME_NOTHING = 0;
178 static final int DOUBLE_TAP_HOME_RECENT_SYSTEM_UI = 1;
Joe Onorato46b0d682010-11-22 17:37:27 -0800179
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +0000180 static final int SHORT_PRESS_SLEEP_GO_TO_SLEEP = 0;
181 static final int SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME = 1;
182
Dianne Hackborn5cb8d792009-05-21 17:34:15 -0700183 static final int APPLICATION_MEDIA_SUBLAYER = -2;
184 static final int APPLICATION_MEDIA_OVERLAY_SUBLAYER = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800185 static final int APPLICATION_PANEL_SUBLAYER = 1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800186 static final int APPLICATION_SUB_PANEL_SUBLAYER = 2;
Wale Ogunwale0a4dc222015-04-14 12:58:42 -0700187 static final int APPLICATION_ABOVE_SUB_PANEL_SUBLAYER = 3;
Craig Mautner88400d32012-09-30 12:35:45 -0700188
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800189 static public final String SYSTEM_DIALOG_REASON_KEY = "reason";
190 static public final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions";
191 static public final String SYSTEM_DIALOG_REASON_RECENT_APPS = "recentapps";
Joe Onoratof275f0c2009-11-24 16:11:13 -0500192 static public final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey";
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700193 static public final String SYSTEM_DIALOG_REASON_ASSIST = "assist";
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800194
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700195 /**
196 * These are the system UI flags that, when changing, can cause the layout
197 * of the screen to change.
198 */
199 static final int SYSTEM_UI_CHANGING_LAYOUT =
John Spurlocke1f366f2013-08-05 12:22:40 -0400200 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlock7f4820a2013-10-08 12:54:35 -0400201 | View.SYSTEM_UI_FLAG_FULLSCREEN
202 | View.STATUS_BAR_TRANSLUCENT
Adrian Roosea562512014-05-05 13:33:03 +0200203 | View.NAVIGATION_BAR_TRANSLUCENT
204 | View.SYSTEM_UI_TRANSPARENT;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700205
John Spurlock7b414672014-07-18 13:02:39 -0400206 private static final AudioAttributes VIBRATION_ATTRIBUTES = new AudioAttributes.Builder()
207 .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
208 .setUsage(AudioAttributes.USAGE_ASSISTANCE_SONIFICATION)
209 .build();
210
Adrian Roosddc8b272015-05-21 16:28:27 -0700211 // The panic gesture may become active only after the keyguard is dismissed and the immersive
212 // app shows again. If that doesn't happen for 30s we drop the gesture.
213 private static final long PANIC_GESTURE_EXPIRATION = 30000;
214
Jim Miller5ecd8112013-01-09 18:50:26 -0800215 /**
216 * Keyguard stuff
217 */
218 private WindowState mKeyguardScrim;
Jorim Jaggi380ecb82014-03-14 17:25:20 +0100219 private boolean mKeyguardHidden;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700220 private boolean mKeyguardDrawnOnce;
Jim Miller5ecd8112013-01-09 18:50:26 -0800221
Jeff Brown6651a632011-11-28 12:59:11 -0800222 /* Table of Application Launch keys. Maps from key codes to intent categories.
223 *
224 * These are special keys that are used to launch particular kinds of applications,
225 * such as a web browser. HID defines nearly a hundred of them in the Consumer (0x0C)
226 * usage page. We don't support quite that many yet...
227 */
228 static SparseArray<String> sApplicationLaunchKeyCategories;
229 static {
230 sApplicationLaunchKeyCategories = new SparseArray<String>();
231 sApplicationLaunchKeyCategories.append(
232 KeyEvent.KEYCODE_EXPLORER, Intent.CATEGORY_APP_BROWSER);
233 sApplicationLaunchKeyCategories.append(
234 KeyEvent.KEYCODE_ENVELOPE, Intent.CATEGORY_APP_EMAIL);
235 sApplicationLaunchKeyCategories.append(
236 KeyEvent.KEYCODE_CONTACTS, Intent.CATEGORY_APP_CONTACTS);
237 sApplicationLaunchKeyCategories.append(
238 KeyEvent.KEYCODE_CALENDAR, Intent.CATEGORY_APP_CALENDAR);
239 sApplicationLaunchKeyCategories.append(
240 KeyEvent.KEYCODE_MUSIC, Intent.CATEGORY_APP_MUSIC);
241 sApplicationLaunchKeyCategories.append(
242 KeyEvent.KEYCODE_CALCULATOR, Intent.CATEGORY_APP_CALCULATOR);
243 }
244
Craig Mautnerc3daedd2014-09-13 11:17:23 -0700245 /** Amount of time (in milliseconds) to wait for windows drawn before powering on. */
246 static final int WAITING_FOR_DRAWN_TIMEOUT = 1000;
247
Dianne Hackborndf89e652011-10-06 22:35:11 -0700248 /**
249 * Lock protecting internal state. Must not call out into window
250 * manager with lock held. (This lock will be acquired in places
251 * where the window manager is calling in with its own lock held.)
252 */
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800253 private final Object mLock = new Object();
Dianne Hackborndf89e652011-10-06 22:35:11 -0700254
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800255 Context mContext;
256 IWindowManager mWindowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700257 WindowManagerFuncs mWindowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -0700258 WindowManagerInternal mWindowManagerInternal;
Jeff Brown96307042012-07-27 15:51:34 -0700259 PowerManager mPowerManager;
Jeff Brown061ea992015-04-17 19:55:47 -0700260 ActivityManagerInternal mActivityManagerInternal;
Jose Lima9546b202014-07-02 17:21:51 -0700261 DreamManagerInternal mDreamManagerInternal;
Joe Onorato93056472010-09-10 10:30:46 -0400262 IStatusBarService mStatusBarService;
Jeff Browncaca8812013-05-09 13:34:33 -0700263 boolean mPreloadedRecentApps;
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700264 final Object mServiceAquireLock = new Object();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800265 Vibrator mVibrator; // Vibrator for giving feedback of orientation changes
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700266 SearchManager mSearchManager;
Svetoslav8e3feb12014-02-24 13:46:47 -0800267 AccessibilityManager mAccessibilityManager;
Filip Gruszczynskicfb31852015-02-25 21:47:12 +0000268 BurnInProtectionHelper mBurnInProtectionHelper;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800269
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700270 // Vibrator pattern for haptic feedback of a long press.
271 long[] mLongPressVibePattern;
Craig Mautner88400d32012-09-30 12:35:45 -0700272
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700273 // Vibrator pattern for haptic feedback of virtual key press.
274 long[] mVirtualKeyVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700275
Amith Yamasanic33cb712010-02-10 15:21:49 -0800276 // Vibrator pattern for a short vibration.
277 long[] mKeyboardTapVibePattern;
278
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -0700279 // Vibrator pattern for a short vibration when tapping on an hour/minute tick of a Clock.
280 long[] mClockTickVibePattern;
281
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -0700282 // Vibrator pattern for a short vibration when tapping on a day/month/year date of a Calendar.
283 long[] mCalendarDateVibePattern;
284
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700285 // Vibrator pattern for haptic feedback during boot when safe mode is disabled.
286 long[] mSafeModeDisabledVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700287
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700288 // Vibrator pattern for haptic feedback during boot when safe mode is enabled.
289 long[] mSafeModeEnabledVibePattern;
Romain Guy8154cd32010-03-29 14:41:15 -0700290
Mady Mellore8608912015-06-05 09:02:55 -0700291 // Vibrator pattern for haptic feedback of a context click.
292 long[] mContextClickVibePattern;
Mady Mellore82067b2015-04-30 09:58:35 -0700293
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800294 /** If true, hitting shift & menu will broadcast Intent.ACTION_BUG_REPORT */
295 boolean mEnableShiftMenuBugReports = false;
Mike Lockwoodd747dc82011-09-13 16:28:22 -0400296
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800297 boolean mSafeMode;
298 WindowState mStatusBar = null;
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700299 int mStatusBarHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400300 WindowState mNavigationBar = null;
Daniel Sandler36412a72011-08-04 09:35:13 -0400301 boolean mHasNavigationBar = false;
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700302 boolean mCanHideNavigationBar = false;
Daniel Sandler4a066c52012-04-20 14:49:13 -0400303 boolean mNavigationBarCanMove = false; // can the navigation bar ever move to the side?
304 boolean mNavigationBarOnBottom = true; // is the navigation bar on the bottom *right now*?
305 int[] mNavigationBarHeightForRotation = new int[4];
306 int[] mNavigationBarWidthForRotation = new int[4];
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400307
Craig Mautnera631d492014-08-05 15:16:01 -0700308 boolean mBootMessageNeedsHiding;
Jim Miller5ecd8112013-01-09 18:50:26 -0800309 KeyguardServiceDelegate mKeyguardDelegate;
Craig Mautner13f6ea72014-06-23 14:57:02 -0700310 final Runnable mWindowManagerDrawCallback = new Runnable() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700311 @Override
Craig Mautner13f6ea72014-06-23 14:57:02 -0700312 public void run() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700313 if (DEBUG_WAKEUP) Slog.i(TAG, "All windows ready for display!");
314 mHandler.sendEmptyMessage(MSG_WINDOW_MANAGER_DRAWN_COMPLETE);
315 }
316 };
317 final ShowListener mKeyguardDelegateCallback = new ShowListener() {
318 @Override
319 public void onShown(IBinder windowToken) {
320 if (DEBUG_WAKEUP) Slog.d(TAG, "mKeyguardDelegate.ShowListener.onShown.");
321 mHandler.sendEmptyMessage(MSG_KEYGUARD_DRAWN_COMPLETE);
322 }
323 };
324
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800325 GlobalActions mGlobalActions;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800326 Handler mHandler;
satok1bc0a492012-04-25 22:47:12 +0900327 WindowState mLastInputMethodWindow = null;
328 WindowState mLastInputMethodTargetWindow = null;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800329
Jeff Brown13f00f02014-10-31 14:45:50 -0700330 // FIXME This state is shared between the input reader and handler thread.
331 // Technically it's broken and buggy but it has been like this for many years
332 // and we have not yet seen any problems. Someday we'll rewrite this logic
333 // so that only one thread is involved in handling input policy. Unfortunately
334 // it's on a critical path for power management so we can't just post the work to the
335 // handler thread. We'll need to resolve this someday by teaching the input dispatcher
336 // to hold wakelocks during dispatch and eliminating the critical path.
337 volatile boolean mPowerKeyHandled;
Bryce Leed9268e32014-11-17 17:40:59 -0800338 volatile boolean mBeganFromNonInteractive;
Jeff Brown13f00f02014-10-31 14:45:50 -0700339 volatile int mPowerKeyPressCounter;
340 volatile boolean mEndCallKeyHandled;
341
Winson Chungd42a6cf2014-06-03 16:24:04 -0700342 boolean mRecentsVisible;
Winson Chung1e8d71b2014-05-16 17:05:22 -0700343 int mRecentAppsHeldModifiers;
Jeff Browncf39bdf2012-05-18 14:41:19 -0700344 boolean mLanguageSwitchKeyPressed;
Jeff Brown68b909d2011-12-07 16:36:01 -0800345
Jeff Brown2e7760e2012-04-11 15:14:55 -0700346 int mLidState = LID_ABSENT;
Michael Wright3818c922014-09-02 13:59:07 -0700347 int mCameraLensCoverState = CAMERA_LENS_COVER_ABSENT;
Jeff Browndaa37532012-05-01 15:54:03 -0700348 boolean mHaveBuiltInKeyboard;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800349
Dianne Hackbornc777e072010-02-12 13:07:59 -0800350 boolean mSystemReady;
Dianne Hackbornba24e4d2011-09-01 11:17:06 -0700351 boolean mSystemBooted;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800352 boolean mHdmiPlugged;
Jeff Brown4f5fa282014-06-12 19:19:15 -0700353 IUiModeManager mUiModeManager;
Daniel Sandler6396c722013-04-16 20:19:09 -0400354 int mUiMode;
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700355 int mDockMode = Intent.EXTRA_DOCK_STATE_UNDOCKED;
Mike Lockwood1753f7f2009-08-24 14:49:07 -0700356 int mLidOpenRotation;
Mike Lockwood2d1efbd2009-09-16 12:15:53 -0400357 int mCarDockRotation;
358 int mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -0700359 int mUndockedHdmiRotation;
360 int mDemoHdmiRotation;
361 boolean mDemoHdmiRotationLock;
Chong Zhangae6119ff2014-11-11 18:54:39 -0800362 int mDemoRotation;
363 boolean mDemoRotationLock;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400364
Jeff Browna20dda42014-05-27 20:57:24 -0700365 boolean mWakeGestureEnabledSetting;
366 MyWakeGestureListener mWakeGestureListener;
367
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700368 // Default display does not rotate, apps that require non-default orientation will have to
369 // have the orientation emulated.
370 private boolean mForceDefaultOrientation = false;
371
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400372 int mUserRotationMode = WindowManagerPolicy.USER_ROTATION_FREE;
373 int mUserRotation = Surface.ROTATION_0;
Jeff Brown207673cd2012-06-05 17:47:11 -0700374 boolean mAccelerometerDefault;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400375
Jeff Brownbcdfc622014-03-06 19:13:04 -0800376 boolean mSupportAutoRotation;
Jeff Brownd3187e32011-09-21 19:26:44 -0700377 int mAllowAllRotations = -1;
Mike Lockwoode9867d22009-09-20 01:59:02 -0400378 boolean mCarDockEnablesAccelerometer;
379 boolean mDeskDockEnablesAccelerometer;
Dianne Hackborn2862fff2009-09-15 22:56:29 -0700380 int mLidKeyboardAccessibility;
381 int mLidNavigationAccessibility;
Jeff Brownc458ce92012-04-30 14:58:40 -0700382 boolean mLidControlsSleep;
Jeff Brown13f00f02014-10-31 14:45:50 -0700383 int mShortPressOnPowerBehavior;
384 int mLongPressOnPowerBehavior;
385 int mDoublePressOnPowerBehavior;
386 int mTriplePressOnPowerBehavior;
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +0000387 int mShortPressOnSleepBehavior;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700388 boolean mAwake;
389 boolean mScreenOnEarly;
390 boolean mScreenOnFully;
391 ScreenOnListener mScreenOnListener;
392 boolean mKeyguardDrawComplete;
393 boolean mWindowManagerDrawComplete;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800394 boolean mOrientationSensorEnabled = false;
395 int mCurrentAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800396 boolean mHasSoftInput = false;
Daniel Sandlerdd73ee42013-10-11 22:19:59 -0400397 boolean mTranslucentDecorEnabled = true;
RoboErik001c59c2015-01-26 15:53:51 -0800398 boolean mUseTvRouting;
Craig Mautner967212c2013-04-13 21:10:58 -0700399
Jeff Brown70825162012-03-28 17:27:48 -0700400 int mPointerLocationMode = 0; // guarded by mLock
Joe Onorato664644d2011-01-23 17:53:23 -0800401
402 // The last window we were told about in focusChanged.
403 WindowState mFocusedWindow;
Dianne Hackborne0f085d2011-11-30 18:41:15 -0800404 IApplicationToken mFocusedApp;
Joe Onorato664644d2011-01-23 17:53:23 -0800405
Jeff Brown70825162012-03-28 17:27:48 -0700406 PointerLocationView mPointerLocationView;
Jeff Brown32cbc38552011-12-01 14:01:49 -0800407
Dianne Hackbornc652de82013-02-15 16:32:56 -0800408 // The current size of the screen; really; extends into the overscan area of
409 // the screen and doesn't account for any system elements like the status bar.
410 int mOverscanScreenLeft, mOverscanScreenTop;
411 int mOverscanScreenWidth, mOverscanScreenHeight;
412 // The current visible size of the screen; really; (ir)regardless of whether the status
413 // bar can be hidden but not extending into the overscan area.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800414 int mUnrestrictedScreenLeft, mUnrestrictedScreenTop;
415 int mUnrestrictedScreenWidth, mUnrestrictedScreenHeight;
Dianne Hackborn313440842013-02-19 19:22:59 -0800416 // Like mOverscanScreen*, but allowed to move into the overscan region where appropriate.
417 int mRestrictedOverscanScreenLeft, mRestrictedOverscanScreenTop;
418 int mRestrictedOverscanScreenWidth, mRestrictedOverscanScreenHeight;
Dianne Hackborn82de1ae2010-10-28 11:28:39 -0700419 // The current size of the screen; these may be different than (0,0)-(dw,dh)
420 // if the status bar can't be hidden; in that case it effectively carves out
421 // that area of the display from all other windows.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800422 int mRestrictedScreenLeft, mRestrictedScreenTop;
423 int mRestrictedScreenWidth, mRestrictedScreenHeight;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700424 // During layout, the current screen borders accounting for any currently
425 // visible system UI elements.
426 int mSystemLeft, mSystemTop, mSystemRight, mSystemBottom;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700427 // For applications requesting stable content insets, these are them.
428 int mStableLeft, mStableTop, mStableRight, mStableBottom;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -0700429 // For applications requesting stable content insets but have also set the
430 // fullscreen window flag, these are the stable dimensions without the status bar.
431 int mStableFullscreenLeft, mStableFullscreenTop;
432 int mStableFullscreenRight, mStableFullscreenBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800433 // During layout, the current screen borders with all outer decoration
434 // (status bar, input method dock) accounted for.
435 int mCurLeft, mCurTop, mCurRight, mCurBottom;
436 // During layout, the frame in which content should be displayed
437 // to the user, accounting for all screen decoration except for any
438 // space they deem as available for other content. This is usually
439 // the same as mCur*, but may be larger if the screen decor has supplied
440 // content insets.
441 int mContentLeft, mContentTop, mContentRight, mContentBottom;
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700442 // During layout, the frame in which voice content should be displayed
443 // to the user, accounting for all screen decoration except for any
444 // space they deem as available for other content.
445 int mVoiceContentLeft, mVoiceContentTop, mVoiceContentRight, mVoiceContentBottom;
Dianne Hackborn8e11ef02010-11-18 19:47:42 -0800446 // During layout, the current screen borders along which input method
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800447 // windows are placed.
448 int mDockLeft, mDockTop, mDockRight, mDockBottom;
449 // During layout, the layer at which the doc window is placed.
450 int mDockLayer;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700451 // During layout, this is the layer of the status bar.
452 int mStatusBarLayer;
Dianne Hackborne26ab702011-10-16 13:21:33 -0700453 int mLastSystemUiFlags;
454 // Bits that we are in the process of clearing, so we want to prevent
455 // them from being set by applications until everything has been updated
456 // to have them clear.
457 int mResettingSystemUiFlags = 0;
458 // Bits that we are currently always keeping cleared.
459 int mForceClearedSystemUiFlags = 0;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -0800460 // What we last reported to system UI about whether the compatibility
461 // menu needs to be displayed.
462 boolean mLastFocusNeedsMenu = false;
Adrian Roosddc8b272015-05-21 16:28:27 -0700463 // If nonzero, a panic gesture was performed at that time in uptime millis and is still pending.
464 private long mPendingPanicGestureUptime;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700465
Selim Cinekf83e8242015-05-19 18:08:14 -0700466 InputConsumer mInputConsumer = null;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700467
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800468 static final Rect mTmpParentFrame = new Rect();
469 static final Rect mTmpDisplayFrame = new Rect();
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800470 static final Rect mTmpOverscanFrame = new Rect();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800471 static final Rect mTmpContentFrame = new Rect();
472 static final Rect mTmpVisibleFrame = new Rect();
John Spurlock46646232013-09-30 22:32:42 -0400473 static final Rect mTmpDecorFrame = new Rect();
Adrian Roosfa104232014-06-20 16:10:14 -0700474 static final Rect mTmpStableFrame = new Rect();
Dianne Hackborn1f903c32011-09-13 19:18:06 -0700475 static final Rect mTmpNavigationFrame = new Rect();
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700476 static final Rect mTmpOutsetFrame = new Rect();
Craig Mautner967212c2013-04-13 21:10:58 -0700477
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800478 WindowState mTopFullscreenOpaqueWindowState;
Adrian Rooscd3884d2015-02-18 17:25:23 +0100479 WindowState mTopFullscreenOpaqueOrDimmingWindowState;
Craig Mautner2bc789b2014-03-19 19:48:38 -0700480 HashSet<IApplicationToken> mAppsToBeHidden = new HashSet<IApplicationToken>();
Jorim Jaggic13fcac2014-09-11 17:36:57 +0200481 HashSet<IApplicationToken> mAppsThatDismissKeyguard = new HashSet<IApplicationToken>();
Joe Onorato93056472010-09-10 10:30:46 -0400482 boolean mTopIsFullscreen;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800483 boolean mForceStatusBar;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -0700484 boolean mForceStatusBarFromKeyguard;
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -0700485 private boolean mForceStatusBarTransparent;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700486 boolean mHideLockScreen;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -0800487 boolean mForcingShowNavBar;
488 int mForcingShowNavBarLayer;
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700489
490 // States of keyguard dismiss.
491 private static final int DISMISS_KEYGUARD_NONE = 0; // Keyguard not being dismissed.
492 private static final int DISMISS_KEYGUARD_START = 1; // Keyguard needs to be dismissed.
493 private static final int DISMISS_KEYGUARD_CONTINUE = 2; // Keyguard has been dismissed.
494 int mDismissKeyguard = DISMISS_KEYGUARD_NONE;
495
496 /** The window that is currently dismissing the keyguard. Dismissing the keyguard must only
497 * be done once per window. */
498 private WindowState mWinDismissingKeyguard;
499
tingna_sunge785ffa2015-05-12 13:23:15 +0800500 /** When window is currently dismissing the keyguard, dismissing the keyguard must handle
501 * the keygaurd secure state change instantly case, e.g. the use case of inserting a PIN
502 * lock SIM card. This variable is used to record the previous keyguard secure state for
503 * monitoring secure state change on window dismissing keyguard. */
504 private boolean mSecureDismissingKeyguard;
505
Craig Mautnerc9457fa2014-06-06 14:27:48 -0700506 /** The window that is currently showing "over" the keyguard. If there is an app window
507 * belonging to another app on top of this the keyguard shows. If there is a fullscreen
508 * app window under this, still dismiss the keyguard but don't show the app underneath. Show
509 * the wallpaper. */
510 private WindowState mWinShowWhenLocked;
511
Dianne Hackborn7ad44382012-10-18 17:46:00 -0700512 boolean mShowingLockscreen;
513 boolean mShowingDream;
514 boolean mDreamingLockscreen;
Jeff Brown061ea992015-04-17 19:55:47 -0700515 boolean mDreamingSleepTokenNeeded;
516 SleepToken mDreamingSleepToken;
Jim Millerab954542014-10-10 18:21:49 -0700517 boolean mKeyguardSecure;
518 boolean mKeyguardSecureIncludingHidden;
519 volatile boolean mKeyguardOccluded;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800520 boolean mHomePressed;
Jeff Browncaca8812013-05-09 13:34:33 -0700521 boolean mHomeConsumed;
522 boolean mHomeDoubleTapPending;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800523 Intent mHomeIntent;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700524 Intent mCarDockIntent;
525 Intent mDeskDockIntent;
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700526 boolean mSearchKeyShortcutPending;
527 boolean mConsumeSearchKeyUp;
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700528 boolean mAssistKeyLongPressed;
Michael Wright6a62e552014-06-03 19:19:48 -0700529 boolean mPendingMetaAction;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800530
Mike Lockwood28569302010-01-28 11:54:40 -0500531 // support for activating the lock screen while the screen is on
532 boolean mAllowLockscreenWhenOn;
533 int mLockScreenTimeout;
534 boolean mLockScreenTimerActive;
535
David Brownbaf8d092010-03-08 21:52:59 -0800536 // Behavior of ENDCALL Button. (See Settings.System.END_BUTTON_BEHAVIOR.)
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800537 int mEndcallBehavior;
David Brownbaf8d092010-03-08 21:52:59 -0800538
539 // Behavior of POWER button while in-call and screen on.
540 // (See Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR.)
541 int mIncallPowerBehavior;
542
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700543 Display mDisplay;
544
Dianne Hackborn9d132642011-04-21 17:26:39 -0700545 int mLandscapeRotation = 0; // default landscape rotation
546 int mSeascapeRotation = 0; // "other" landscape rotation, 180 degrees from mLandscapeRotation
547 int mPortraitRotation = 0; // default portrait rotation
548 int mUpsideDownRotation = 0; // "other" portrait rotation
Mitsuru Oshima831d0d92009-06-16 18:27:18 -0700549
Dianne Hackbornc652de82013-02-15 16:32:56 -0800550 int mOverscanLeft = 0;
551 int mOverscanTop = 0;
552 int mOverscanRight = 0;
553 int mOverscanBottom = 0;
554
Joe Onorato46b0d682010-11-22 17:37:27 -0800555 // What we do when the user long presses on home
Jeff Browncaca8812013-05-09 13:34:33 -0700556 private int mLongPressOnHomeBehavior;
557
558 // What we do when the user double-taps on home
559 private int mDoubleTapOnHomeBehavior;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800560
Bryce Lee584a4452014-10-21 15:55:55 -0700561 // Allowed theater mode wake actions
562 private boolean mAllowTheaterModeWakeFromKey;
563 private boolean mAllowTheaterModeWakeFromPowerKey;
564 private boolean mAllowTheaterModeWakeFromMotion;
Bryce Lee812d7022014-11-10 13:33:28 -0800565 private boolean mAllowTheaterModeWakeFromMotionWhenNotDreaming;
Bryce Lee584a4452014-10-21 15:55:55 -0700566 private boolean mAllowTheaterModeWakeFromCameraLens;
567 private boolean mAllowTheaterModeWakeFromLidSwitch;
568 private boolean mAllowTheaterModeWakeFromWakeGesture;
569
Bryce Leed3b28402015-03-09 15:49:13 +0000570 // Whether to support long press from power button in non-interactive mode
571 private boolean mSupportLongPressPowerWhenNonInteractive;
572
Bryce Lee55e846d2014-11-04 12:43:44 -0800573 // Whether to go to sleep entering theater mode from power button
574 private boolean mGoToSleepOnButtonPressTheaterMode;
575
Winson Chung9112ec32011-06-27 13:15:32 -0700576 // Screenshot trigger states
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700577 // Time to volume and power must be pressed within this interval of each other.
578 private static final long SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS = 150;
Winson Chung1cea2f32012-10-08 20:42:01 -0700579 // Increase the chord delay when taking a screenshot from the keyguard
580 private static final float KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER = 2.5f;
Christopher Tatee90585f2012-03-05 18:56:25 -0800581 private boolean mScreenshotChordEnabled;
Jeff Brown13f00f02014-10-31 14:45:50 -0700582 private boolean mScreenshotChordVolumeDownKeyTriggered;
583 private long mScreenshotChordVolumeDownKeyTime;
584 private boolean mScreenshotChordVolumeDownKeyConsumed;
585 private boolean mScreenshotChordVolumeUpKeyTriggered;
586 private boolean mScreenshotChordPowerKeyTriggered;
587 private long mScreenshotChordPowerKeyTime;
Winson Chung9112ec32011-06-27 13:15:32 -0700588
Michael Wrightb854e242013-02-05 17:54:02 -0800589 /* The number of steps between min and max brightness */
590 private static final int BRIGHTNESS_STEPS = 10;
591
Christopher Tate5e08af02012-09-21 17:17:22 -0700592 SettingsObserver mSettingsObserver;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800593 ShortcutManager mShortcutManager;
594 PowerManager.WakeLock mBroadcastWakeLock;
Jeff Brown13f00f02014-10-31 14:45:50 -0700595 PowerManager.WakeLock mPowerKeyWakeLock;
Jeff Brown40013652012-05-16 21:22:36 -0700596 boolean mHavePendingMediaKeyRepeatWithWakeLock;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800597
Craig Mautnerd625ab22013-09-06 13:40:31 -0700598 private int mCurrentUserId;
599
Justin Kohd378ad72013-04-01 12:18:26 -0700600 // Maps global key codes to the components that will handle them.
601 private GlobalKeyManager mGlobalKeyManager;
602
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700603 // Fallback actions by key code.
604 private final SparseArray<KeyCharacterMap.FallbackAction> mFallbackActions =
605 new SparseArray<KeyCharacterMap.FallbackAction>();
Jeff Brown49ed71d2010-12-06 17:13:33 -0800606
Jorim Jaggi76a16232014-08-08 17:00:47 +0200607 private final LogDecelerateInterpolator mLogDecelerateInterpolator
608 = new LogDecelerateInterpolator(100, 0);
609
Jeff Brown70825162012-03-28 17:27:48 -0700610 private static final int MSG_ENABLE_POINTER_LOCATION = 1;
611 private static final int MSG_DISABLE_POINTER_LOCATION = 2;
Jeff Brown40013652012-05-16 21:22:36 -0700612 private static final int MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK = 3;
613 private static final int MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK = 4;
Craig Mautner8a0da012014-05-31 15:13:37 -0700614 private static final int MSG_KEYGUARD_DRAWN_COMPLETE = 5;
615 private static final int MSG_KEYGUARD_DRAWN_TIMEOUT = 6;
616 private static final int MSG_WINDOW_MANAGER_DRAWN_COMPLETE = 7;
Craig Mautner84984fa2014-06-19 11:19:20 -0700617 private static final int MSG_DISPATCH_SHOW_RECENTS = 9;
Alan Viverettee34560b22014-07-10 14:50:06 -0700618 private static final int MSG_DISPATCH_SHOW_GLOBAL_ACTIONS = 10;
Craig Mautnera631d492014-08-05 15:16:01 -0700619 private static final int MSG_HIDE_BOOT_MESSAGE = 11;
Michael Wright869a67c2014-08-26 19:33:06 -0700620 private static final int MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK = 12;
Jeff Brown13f00f02014-10-31 14:45:50 -0700621 private static final int MSG_POWER_DELAYED_PRESS = 13;
622 private static final int MSG_POWER_LONG_PRESS = 14;
Jeff Brown061ea992015-04-17 19:55:47 -0700623 private static final int MSG_UPDATE_DREAMING_SLEEP_TOKEN = 15;
Jeff Brown70825162012-03-28 17:27:48 -0700624
625 private class PolicyHandler extends Handler {
626 @Override
627 public void handleMessage(Message msg) {
628 switch (msg.what) {
629 case MSG_ENABLE_POINTER_LOCATION:
630 enablePointerLocation();
631 break;
632 case MSG_DISABLE_POINTER_LOCATION:
633 disablePointerLocation();
634 break;
Jeff Brown40013652012-05-16 21:22:36 -0700635 case MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK:
636 dispatchMediaKeyWithWakeLock((KeyEvent)msg.obj);
637 break;
638 case MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK:
639 dispatchMediaKeyRepeatWithWakeLock((KeyEvent)msg.obj);
640 break;
Craig Mautner84984fa2014-06-19 11:19:20 -0700641 case MSG_DISPATCH_SHOW_RECENTS:
642 showRecentApps(false);
643 break;
Alan Viverettee34560b22014-07-10 14:50:06 -0700644 case MSG_DISPATCH_SHOW_GLOBAL_ACTIONS:
645 showGlobalActionsInternal();
646 break;
Craig Mautner8a0da012014-05-31 15:13:37 -0700647 case MSG_KEYGUARD_DRAWN_COMPLETE:
648 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mKeyguardDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700649 finishKeyguardDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700650 break;
651 case MSG_KEYGUARD_DRAWN_TIMEOUT:
652 Slog.w(TAG, "Keyguard drawn timeout. Setting mKeyguardDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700653 finishKeyguardDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700654 break;
655 case MSG_WINDOW_MANAGER_DRAWN_COMPLETE:
656 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mWindowManagerDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700657 finishWindowsDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700658 break;
Craig Mautnera631d492014-08-05 15:16:01 -0700659 case MSG_HIDE_BOOT_MESSAGE:
660 handleHideBootMessage();
661 break;
Michael Wright869a67c2014-08-26 19:33:06 -0700662 case MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK:
663 launchVoiceAssistWithWakeLock(msg.arg1 != 0);
664 break;
Jeff Brown13f00f02014-10-31 14:45:50 -0700665 case MSG_POWER_DELAYED_PRESS:
666 powerPress((Long)msg.obj, msg.arg1 != 0, msg.arg2);
667 finishPowerKeyPress();
668 break;
669 case MSG_POWER_LONG_PRESS:
670 powerLongPress();
671 break;
Jeff Brown061ea992015-04-17 19:55:47 -0700672 case MSG_UPDATE_DREAMING_SLEEP_TOKEN:
673 updateDreamingSleepToken(msg.arg1 != 0);
674 break;
Jeff Brown70825162012-03-28 17:27:48 -0700675 }
676 }
677 }
678
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800679 private UEventObserver mHDMIObserver = new UEventObserver() {
680 @Override
681 public void onUEvent(UEventObserver.UEvent event) {
682 setHdmiPlugged("1".equals(event.get("SWITCH_STATE")));
683 }
684 };
685
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800686 class SettingsObserver extends ContentObserver {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800687 SettingsObserver(Handler handler) {
688 super(handler);
689 }
David Brownbaf8d092010-03-08 21:52:59 -0800690
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800691 void observe() {
Christopher Tate5e08af02012-09-21 17:17:22 -0700692 // Observe all users' changes
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800693 ContentResolver resolver = mContext.getContentResolver();
694 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700695 Settings.System.END_BUTTON_BEHAVIOR), false, this,
696 UserHandle.USER_ALL);
David Brownbaf8d092010-03-08 21:52:59 -0800697 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700698 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR), false, this,
699 UserHandle.USER_ALL);
Jeff Browna20dda42014-05-27 20:57:24 -0700700 resolver.registerContentObserver(Settings.Secure.getUriFor(
701 Settings.Secure.WAKE_GESTURE_ENABLED), false, this,
702 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800703 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700704 Settings.System.ACCELEROMETER_ROTATION), false, this,
705 UserHandle.USER_ALL);
Mike Lockwood28569302010-01-28 11:54:40 -0500706 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700707 Settings.System.USER_ROTATION), false, this,
708 UserHandle.USER_ALL);
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400709 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700710 Settings.System.SCREEN_OFF_TIMEOUT), false, this,
711 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800712 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700713 Settings.System.POINTER_LOCATION), false, this,
714 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800715 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700716 Settings.Secure.DEFAULT_INPUT_METHOD), false, this,
717 UserHandle.USER_ALL);
John Spurlockd9b70bd2014-02-06 17:02:44 -0500718 resolver.registerContentObserver(Settings.Secure.getUriFor(
John Spurlockf1a36642013-10-12 17:50:42 -0400719 Settings.Secure.IMMERSIVE_MODE_CONFIRMATIONS), false, this,
Christopher Tate5e08af02012-09-21 17:17:22 -0700720 UserHandle.USER_ALL);
John Spurlockc6d1c602014-01-17 15:22:06 -0500721 resolver.registerContentObserver(Settings.Global.getUriFor(
722 Settings.Global.POLICY_CONTROL), false, this,
723 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800724 updateSettings();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800725 }
726
727 @Override public void onChange(boolean selfChange) {
Dianne Hackbornc777e072010-02-12 13:07:59 -0800728 updateSettings();
Jeff Brown01a98dd2011-09-20 15:08:29 -0700729 updateRotation(false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800730 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800731 }
Craig Mautner967212c2013-04-13 21:10:58 -0700732
Jeff Browna20dda42014-05-27 20:57:24 -0700733 class MyWakeGestureListener extends WakeGestureListener {
734 MyWakeGestureListener(Context context, Handler handler) {
735 super(context, handler);
736 }
737
738 @Override
739 public void onWakeUp() {
740 synchronized (mLock) {
741 if (shouldEnableWakeGestureLp()) {
Jeff Browne07b94b2014-06-18 15:56:27 -0700742 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
Bryce Lee584a4452014-10-21 15:55:55 -0700743 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromWakeGesture);
Jeff Browna20dda42014-05-27 20:57:24 -0700744 }
745 }
746 }
747 }
748
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800749 class MyOrientationListener extends WindowOrientationListener {
Craig Mautnereee29c42013-01-17 14:44:34 -0800750 MyOrientationListener(Context context, Handler handler) {
751 super(context, handler);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800752 }
Craig Mautner967212c2013-04-13 21:10:58 -0700753
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800754 @Override
Jeff Brownc0347aa2011-09-23 17:26:09 -0700755 public void onProposedRotationChanged(int rotation) {
Craig Mautnereda67292013-04-28 13:50:14 -0700756 if (localLOGV) Slog.v(TAG, "onProposedRotationChanged, rotation=" + rotation);
Jeff Brown01a98dd2011-09-20 15:08:29 -0700757 updateRotation(false);
758 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800759 }
760 MyOrientationListener mOrientationListener;
761
Jorim Jaggi24bec7c2015-02-04 12:40:14 +0100762 private final StatusBarController mStatusBarController = new StatusBarController();
John Spurlock5b9145b2013-08-20 15:13:47 -0400763
John Spurlock27735a42013-08-14 17:57:38 -0400764 private final BarController mNavigationBarController = new BarController("NavigationBar",
John Spurlock5b9145b2013-08-20 15:13:47 -0400765 View.NAVIGATION_BAR_TRANSIENT,
766 View.NAVIGATION_BAR_UNHIDE,
John Spurlockbd957402013-10-03 11:38:39 -0400767 View.NAVIGATION_BAR_TRANSLUCENT,
768 StatusBarManager.WINDOW_NAVIGATION_BAR,
769 WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
John Spurlock5b9145b2013-08-20 15:13:47 -0400770
John Spurlockf1a36642013-10-12 17:50:42 -0400771 private ImmersiveModeConfirmation mImmersiveModeConfirmation;
John Spurlock32beb2c2013-03-11 10:16:47 -0400772
Craig Mautner037aa8d2013-06-07 10:35:44 -0700773 private SystemGesturesPointerEventListener mSystemGestures;
John Spurlock32beb2c2013-03-11 10:16:47 -0400774
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700775 IStatusBarService getStatusBarService() {
776 synchronized (mServiceAquireLock) {
777 if (mStatusBarService == null) {
778 mStatusBarService = IStatusBarService.Stub.asInterface(
779 ServiceManager.getService("statusbar"));
780 }
781 return mStatusBarService;
782 }
783 }
784
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700785 /*
786 * We always let the sensor be switched on by default except when
787 * the user has explicitly disabled sensor based rotation or when the
788 * screen is switched off.
789 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700790 boolean needSensorRunningLp() {
Jeff Brownbcdfc622014-03-06 19:13:04 -0800791 if (mSupportAutoRotation) {
792 if (mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
793 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
794 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT
795 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) {
796 // If the application has explicitly requested to follow the
797 // orientation, then we need to turn the sensor on.
798 return true;
799 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800800 }
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700801 if ((mCarDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_CAR) ||
Jeff Brown1a693182011-11-08 14:44:16 -0800802 (mDeskDockEnablesAccelerometer && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
803 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
804 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK))) {
Mike Lockwoode9867d22009-09-20 01:59:02 -0400805 // enable accelerometer if we are docked in a dock that enables accelerometer
806 // orientation management,
807 return true;
808 }
Jeff Brown207673cd2012-06-05 17:47:11 -0700809 if (mUserRotationMode == USER_ROTATION_LOCKED) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800810 // If the setting for using the sensor by default is enabled, then
811 // we will always leave it on. Note that the user could go to
812 // a window that forces an orientation that does not use the
813 // sensor and in theory we could turn it off... however, when next
814 // turning it on we won't have a good value for the current
815 // orientation for a little bit, which can cause orientation
816 // changes to lag, so we'd like to keep it always on. (It will
817 // still be turned off when the screen is off.)
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700818 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800819 }
Jeff Brownbcdfc622014-03-06 19:13:04 -0800820 return mSupportAutoRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800821 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700822
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800823 /*
824 * Various use cases for invoking this function
825 * screen turning off, should always disable listeners if already enabled
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700826 * screen turned on and current app has sensor based orientation, enable listeners
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800827 * if not already enabled
828 * screen turned on and current app does not have sensor orientation, disable listeners if
829 * already enabled
830 * screen turning on and current app has sensor based orientation, enable listeners if needed
831 * screen turning on and current app has nosensor based orientation, do nothing
832 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700833 void updateOrientationListenerLp() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800834 if (!mOrientationListener.canDetectOrientation()) {
835 // If sensor is turned off or nonexistent for some reason
836 return;
837 }
838 //Could have been invoked due to screen turning on or off or
839 //change of the currently visible window's orientation
Jeff Brown3ee549c2014-09-22 20:14:39 -0700840 if (localLOGV) Slog.v(TAG, "mScreenOnEarly=" + mScreenOnEarly
841 + ", mAwake=" + mAwake + ", mCurrentAppOrientation=" + mCurrentAppOrientation
842 + ", mOrientationSensorEnabled=" + mOrientationSensorEnabled);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800843 boolean disable = true;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700844 if (mScreenOnEarly && mAwake) {
The Android Open Source Project0727d222009-03-11 12:11:58 -0700845 if (needSensorRunningLp()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800846 disable = false;
847 //enable listener if not already enabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700848 if (!mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800849 mOrientationListener.enable();
Craig Mautnereda67292013-04-28 13:50:14 -0700850 if(localLOGV) Slog.v(TAG, "Enabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800851 mOrientationSensorEnabled = true;
852 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700853 }
854 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800855 //check if sensors need to be disabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700856 if (disable && mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800857 mOrientationListener.disable();
Craig Mautnereda67292013-04-28 13:50:14 -0700858 if(localLOGV) Slog.v(TAG, "Disabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800859 mOrientationSensorEnabled = false;
860 }
861 }
862
Jeff Brown13f00f02014-10-31 14:45:50 -0700863 private void interceptPowerKeyDown(KeyEvent event, boolean interactive) {
864 // Hold a wake lock until the power key is released.
865 if (!mPowerKeyWakeLock.isHeld()) {
866 mPowerKeyWakeLock.acquire();
867 }
868
869 // Cancel multi-press detection timeout.
870 if (mPowerKeyPressCounter != 0) {
871 mHandler.removeMessages(MSG_POWER_DELAYED_PRESS);
872 }
873
874 // Detect user pressing the power button in panic when an application has
875 // taken over the whole screen.
876 boolean panic = mImmersiveModeConfirmation.onPowerKeyDown(interactive,
Craig Mautner0124980e92014-11-30 21:15:34 -0800877 SystemClock.elapsedRealtime(), isImmersiveMode(mLastSystemUiFlags));
Jeff Brown13f00f02014-10-31 14:45:50 -0700878 if (panic) {
Adrian Roosddc8b272015-05-21 16:28:27 -0700879 mHandler.post(mHiddenNavPanic);
Jeff Brown13f00f02014-10-31 14:45:50 -0700880 }
881
882 // Latch power key state to detect screenshot chord.
883 if (interactive && !mScreenshotChordPowerKeyTriggered
884 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
885 mScreenshotChordPowerKeyTriggered = true;
886 mScreenshotChordPowerKeyTime = event.getDownTime();
887 interceptScreenshotChord();
888 }
889
890 // Stop ringing or end call if configured to do so when power is pressed.
891 TelecomManager telecomManager = getTelecommService();
892 boolean hungUp = false;
893 if (telecomManager != null) {
894 if (telecomManager.isRinging()) {
895 // Pressing Power while there's a ringing incoming
896 // call should silence the ringer.
897 telecomManager.silenceRinger();
898 } else if ((mIncallPowerBehavior
899 & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0
900 && telecomManager.isInCall() && interactive) {
901 // Otherwise, if "Power button ends call" is enabled,
902 // the Power button will hang up any current active call.
903 hungUp = telecomManager.endCall();
904 }
905 }
906
907 // If the power key has still not yet been handled, then detect short
908 // press, long press, or multi press and decide what to do.
909 mPowerKeyHandled = hungUp || mScreenshotChordVolumeDownKeyTriggered
910 || mScreenshotChordVolumeUpKeyTriggered;
911 if (!mPowerKeyHandled) {
912 if (interactive) {
913 // When interactive, we're already awake.
914 // Wait for a long press or for the button to be released to decide what to do.
915 if (hasLongPressOnPowerBehavior()) {
916 Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS);
917 msg.setAsynchronous(true);
918 mHandler.sendMessageDelayed(msg,
919 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
920 }
921 } else {
Bryce Leed9268e32014-11-17 17:40:59 -0800922 wakeUpFromPowerKey(event.getDownTime());
Bryce Leed9268e32014-11-17 17:40:59 -0800923
Bryce Leed3b28402015-03-09 15:49:13 +0000924 if (mSupportLongPressPowerWhenNonInteractive && hasLongPressOnPowerBehavior()) {
925 Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS);
926 msg.setAsynchronous(true);
927 mHandler.sendMessageDelayed(msg,
928 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Bryce Leed9268e32014-11-17 17:40:59 -0800929 mBeganFromNonInteractive = true;
Bryce Leed3b28402015-03-09 15:49:13 +0000930 } else {
931 final int maxCount = getMaxMultiPressPowerCount();
932
933 if (maxCount <= 1) {
934 mPowerKeyHandled = true;
935 } else {
936 mBeganFromNonInteractive = true;
937 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700938 }
939 }
Jeff Brown4d396052010-10-29 21:50:21 -0700940 }
941 }
942
Jeff Brown13f00f02014-10-31 14:45:50 -0700943 private void interceptPowerKeyUp(KeyEvent event, boolean interactive, boolean canceled) {
944 final boolean handled = canceled || mPowerKeyHandled;
945 mScreenshotChordPowerKeyTriggered = false;
946 cancelPendingScreenshotChordAction();
947 cancelPendingPowerKeyAction();
948
949 if (!handled) {
950 // Figure out how to handle the key now that it has been released.
951 mPowerKeyPressCounter += 1;
952
953 final int maxCount = getMaxMultiPressPowerCount();
954 final long eventTime = event.getDownTime();
955 if (mPowerKeyPressCounter < maxCount) {
956 // This could be a multi-press. Wait a little bit longer to confirm.
957 // Continue holding the wake lock.
958 Message msg = mHandler.obtainMessage(MSG_POWER_DELAYED_PRESS,
959 interactive ? 1 : 0, mPowerKeyPressCounter, eventTime);
960 msg.setAsynchronous(true);
961 mHandler.sendMessageDelayed(msg, ViewConfiguration.getDoubleTapTimeout());
962 return;
963 }
964
965 // No other actions. Handle it immediately.
966 powerPress(eventTime, interactive, mPowerKeyPressCounter);
Jeff Brown4d396052010-10-29 21:50:21 -0700967 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700968
969 // Done. Reset our state.
970 finishPowerKeyPress();
971 }
972
973 private void finishPowerKeyPress() {
Bryce Leed9268e32014-11-17 17:40:59 -0800974 mBeganFromNonInteractive = false;
Jeff Brown13f00f02014-10-31 14:45:50 -0700975 mPowerKeyPressCounter = 0;
976 if (mPowerKeyWakeLock.isHeld()) {
977 mPowerKeyWakeLock.release();
978 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700979 }
980
981 private void cancelPendingPowerKeyAction() {
982 if (!mPowerKeyHandled) {
Jeff Brown13f00f02014-10-31 14:45:50 -0700983 mPowerKeyHandled = true;
984 mHandler.removeMessages(MSG_POWER_LONG_PRESS);
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700985 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700986 }
987
988 private void powerPress(long eventTime, boolean interactive, int count) {
989 if (mScreenOnEarly && !mScreenOnFully) {
990 Slog.i(TAG, "Suppressed redundant power key press while "
991 + "already in the process of turning the screen on.");
992 return;
Jeff Brownff204712011-10-25 21:27:54 -0700993 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700994
995 if (count == 2) {
996 powerMultiPressAction(eventTime, interactive, mDoublePressOnPowerBehavior);
997 } else if (count == 3) {
998 powerMultiPressAction(eventTime, interactive, mTriplePressOnPowerBehavior);
Bryce Leed9268e32014-11-17 17:40:59 -0800999 } else if (interactive && !mBeganFromNonInteractive) {
Jeff Brown13f00f02014-10-31 14:45:50 -07001000 switch (mShortPressOnPowerBehavior) {
1001 case SHORT_PRESS_POWER_NOTHING:
1002 break;
1003 case SHORT_PRESS_POWER_GO_TO_SLEEP:
1004 mPowerManager.goToSleep(eventTime,
1005 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
1006 break;
1007 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP:
1008 mPowerManager.goToSleep(eventTime,
1009 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
1010 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
1011 break;
1012 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME:
1013 mPowerManager.goToSleep(eventTime,
1014 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
1015 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
1016 launchHomeFromHotKey();
1017 break;
Bryce Lee01b0c5f2015-02-05 18:24:04 -08001018 case SHORT_PRESS_POWER_GO_HOME:
Bryce Lee662ed802015-04-10 20:11:39 +00001019 launchHomeFromHotKey(true /* awakenFromDreams */, false /*respectKeyguard*/);
Bryce Lee01b0c5f2015-02-05 18:24:04 -08001020 break;
Jeff Brown13f00f02014-10-31 14:45:50 -07001021 }
1022 }
1023 }
1024
1025 private void powerMultiPressAction(long eventTime, boolean interactive, int behavior) {
1026 switch (behavior) {
1027 case MULTI_PRESS_POWER_NOTHING:
1028 break;
1029 case MULTI_PRESS_POWER_THEATER_MODE:
1030 if (isTheaterModeEnabled()) {
1031 Slog.i(TAG, "Toggling theater mode off.");
1032 Settings.Global.putInt(mContext.getContentResolver(),
1033 Settings.Global.THEATER_MODE_ON, 0);
1034 if (!interactive) {
1035 wakeUpFromPowerKey(eventTime);
1036 }
1037 } else {
1038 Slog.i(TAG, "Toggling theater mode on.");
1039 Settings.Global.putInt(mContext.getContentResolver(),
1040 Settings.Global.THEATER_MODE_ON, 1);
Bryce Lee55e846d2014-11-04 12:43:44 -08001041
1042 if (mGoToSleepOnButtonPressTheaterMode && interactive) {
Jeff Brown13f00f02014-10-31 14:45:50 -07001043 mPowerManager.goToSleep(eventTime,
1044 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
1045 }
1046 }
1047 break;
1048 case MULTI_PRESS_POWER_BRIGHTNESS_BOOST:
Jeff Brown7b5be5e2014-11-12 18:45:31 -08001049 Slog.i(TAG, "Starting brightness boost.");
1050 if (!interactive) {
1051 wakeUpFromPowerKey(eventTime);
1052 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001053 mPowerManager.boostScreenBrightness(eventTime);
1054 break;
1055 }
1056 }
1057
1058 private int getMaxMultiPressPowerCount() {
1059 if (mTriplePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) {
1060 return 3;
1061 }
1062 if (mDoublePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) {
1063 return 2;
1064 }
1065 return 1;
1066 }
1067
1068 private void powerLongPress() {
1069 final int behavior = getResolvedLongPressOnPowerBehavior();
1070 switch (behavior) {
1071 case LONG_PRESS_POWER_NOTHING:
1072 break;
1073 case LONG_PRESS_POWER_GLOBAL_ACTIONS:
1074 mPowerKeyHandled = true;
1075 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
1076 performAuditoryFeedbackForAccessibilityIfNeed();
1077 }
1078 showGlobalActionsInternal();
1079 break;
1080 case LONG_PRESS_POWER_SHUT_OFF:
1081 case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM:
1082 mPowerKeyHandled = true;
1083 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
1084 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
1085 mWindowManagerFuncs.shutdown(behavior == LONG_PRESS_POWER_SHUT_OFF);
1086 break;
1087 }
1088 }
1089
Nick Vaccarob593a812015-05-15 11:23:05 -07001090 private void sleepPress(long eventTime) {
1091 if (mShortPressOnSleepBehavior == SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME) {
1092 launchHomeFromHotKey(false /* awakenDreams */, true /*respectKeyguard*/);
1093 }
1094 }
1095
1096 private void sleepRelease(long eventTime) {
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001097 switch (mShortPressOnSleepBehavior) {
1098 case SHORT_PRESS_SLEEP_GO_TO_SLEEP:
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001099 case SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME:
Nick Vaccarob593a812015-05-15 11:23:05 -07001100 Slog.i(TAG, "sleepRelease() calling goToSleep(GO_TO_SLEEP_REASON_SLEEP_BUTTON)");
1101 mPowerManager.goToSleep(eventTime,
1102 PowerManager.GO_TO_SLEEP_REASON_SLEEP_BUTTON, 0);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001103 break;
1104 }
1105 }
1106
Jeff Brown13f00f02014-10-31 14:45:50 -07001107 private int getResolvedLongPressOnPowerBehavior() {
1108 if (FactoryTest.isLongPressOnPowerOffEnabled()) {
1109 return LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM;
1110 }
1111 return mLongPressOnPowerBehavior;
1112 }
1113
1114 private boolean hasLongPressOnPowerBehavior() {
1115 return getResolvedLongPressOnPowerBehavior() != LONG_PRESS_POWER_NOTHING;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001116 }
1117
1118 private void interceptScreenshotChord() {
Christopher Tatee90585f2012-03-05 18:56:25 -08001119 if (mScreenshotChordEnabled
Jeff Brown13f00f02014-10-31 14:45:50 -07001120 && mScreenshotChordVolumeDownKeyTriggered && mScreenshotChordPowerKeyTriggered
1121 && !mScreenshotChordVolumeUpKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001122 final long now = SystemClock.uptimeMillis();
Jeff Brown13f00f02014-10-31 14:45:50 -07001123 if (now <= mScreenshotChordVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS
1124 && now <= mScreenshotChordPowerKeyTime
1125 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) {
1126 mScreenshotChordVolumeDownKeyConsumed = true;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001127 cancelPendingPowerKeyAction();
1128
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001129 mHandler.postDelayed(mScreenshotRunnable, getScreenshotChordLongPressDelay());
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001130 }
1131 }
1132 }
1133
Winson Chung1cea2f32012-10-08 20:42:01 -07001134 private long getScreenshotChordLongPressDelay() {
Jim Miller5ecd8112013-01-09 18:50:26 -08001135 if (mKeyguardDelegate.isShowing()) {
Winson Chung1cea2f32012-10-08 20:42:01 -07001136 // Double the time it takes to take a screenshot from the keyguard
1137 return (long) (KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER *
Justin Kohfeabd2c2014-05-02 10:02:44 -07001138 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Winson Chung1cea2f32012-10-08 20:42:01 -07001139 }
Justin Kohfeabd2c2014-05-02 10:02:44 -07001140 return ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout();
Winson Chung1cea2f32012-10-08 20:42:01 -07001141 }
1142
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001143 private void cancelPendingScreenshotChordAction() {
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001144 mHandler.removeCallbacks(mScreenshotRunnable);
Jeff Brown4d396052010-10-29 21:50:21 -07001145 }
1146
Jeff Brown13f00f02014-10-31 14:45:50 -07001147 private final Runnable mEndCallLongPress = new Runnable() {
Craig Mautnerf1b67412012-09-19 13:18:29 -07001148 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001149 public void run() {
Jeff Brown13f00f02014-10-31 14:45:50 -07001150 mEndCallKeyHandled = true;
1151 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
1152 performAuditoryFeedbackForAccessibilityIfNeed();
Joe Onoratod208e702010-10-08 16:22:43 -04001153 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001154 showGlobalActionsInternal();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001155 }
1156 };
1157
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001158 private final Runnable mScreenshotRunnable = new Runnable() {
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001159 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001160 public void run() {
1161 takeScreenshot();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001162 }
1163 };
1164
Alan Viverettee34560b22014-07-10 14:50:06 -07001165 @Override
1166 public void showGlobalActions() {
1167 mHandler.removeMessages(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
1168 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
1169 }
1170
1171 void showGlobalActionsInternal() {
1172 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001173 if (mGlobalActions == null) {
Jeff Brown7304c342012-05-11 18:42:42 -07001174 mGlobalActions = new GlobalActions(mContext, mWindowManagerFuncs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001175 }
Jim Millerab954542014-10-10 18:21:49 -07001176 final boolean keyguardShowing = isKeyguardShowingAndNotOccluded();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001177 mGlobalActions.showDialog(keyguardShowing, isDeviceProvisioned());
1178 if (keyguardShowing) {
1179 // since it took two seconds of long press to bring this up,
1180 // poke the wake lock so they have some time to see the dialog.
Jim Miller25190572013-02-28 17:36:24 -08001181 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001182 }
1183 }
1184
1185 boolean isDeviceProvisioned() {
Jeff Brownbf6f6f92012-09-25 15:03:20 -07001186 return Settings.Global.getInt(
1187 mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001188 }
1189
Maurice Lam99c6e072014-04-28 18:24:28 -07001190 boolean isUserSetupComplete() {
1191 return Settings.Secure.getIntForUser(mContext.getContentResolver(),
1192 Settings.Secure.USER_SETUP_COMPLETE, 0, UserHandle.USER_CURRENT) != 0;
1193 }
1194
Jeff Brown13f00f02014-10-31 14:45:50 -07001195 private void handleShortPressOnHome() {
1196 // If there's a dream running then use home to escape the dream
1197 // but don't actually go home.
1198 if (mDreamManagerInternal != null && mDreamManagerInternal.isDreaming()) {
1199 mDreamManagerInternal.stopDream(false /*immediate*/);
1200 return;
1201 }
1202
1203 // Go home!
1204 launchHomeFromHotKey();
1205 }
1206
Patrick Dubroyece94522011-02-23 18:35:01 -08001207 private void handleLongPressOnHome() {
Joe Onorato46b0d682010-11-22 17:37:27 -08001208 if (mLongPressOnHomeBehavior != LONG_PRESS_HOME_NOTHING) {
Jeff Browncaca8812013-05-09 13:34:33 -07001209 mHomeConsumed = true;
Joe Onorato46b0d682010-11-22 17:37:27 -08001210 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
Patrick Dubroyece94522011-02-23 18:35:01 -08001211
Jeff Browncaca8812013-05-09 13:34:33 -07001212 if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI) {
1213 toggleRecentApps();
1214 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_ASSIST) {
1215 launchAssistAction();
Jim Millere6ad1a82010-08-20 19:25:39 -07001216 }
1217 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001218 }
Patrick Dubroyece94522011-02-23 18:35:01 -08001219
Jeff Browncaca8812013-05-09 13:34:33 -07001220 private void handleDoubleTapOnHome() {
1221 if (mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1222 mHomeConsumed = true;
1223 toggleRecentApps();
1224 }
1225 }
1226
1227 private final Runnable mHomeDoubleTapTimeoutRunnable = new Runnable() {
1228 @Override
1229 public void run() {
1230 if (mHomeDoubleTapPending) {
1231 mHomeDoubleTapPending = false;
Jeff Brown13f00f02014-10-31 14:45:50 -07001232 handleShortPressOnHome();
Jeff Browncaca8812013-05-09 13:34:33 -07001233 }
1234 }
1235 };
1236
Mark Renoufc1256912015-03-11 14:38:23 -04001237 private boolean isRoundWindow() {
Adam Powell01f280d2015-05-18 16:07:42 -07001238 return mContext.getResources().getConfiguration().isScreenRound();
Mark Renoufc1256912015-03-11 14:38:23 -04001239 }
1240
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001241 /** {@inheritDoc} */
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001242 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001243 public void init(Context context, IWindowManager windowManager,
Jeff Brown96307042012-07-27 15:51:34 -07001244 WindowManagerFuncs windowManagerFuncs) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001245 mContext = context;
1246 mWindowManager = windowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -07001247 mWindowManagerFuncs = windowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -07001248 mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class);
Jeff Brown061ea992015-04-17 19:55:47 -07001249 mActivityManagerInternal = LocalServices.getService(ActivityManagerInternal.class);
Jose Lima9546b202014-07-02 17:21:51 -07001250 mDreamManagerInternal = LocalServices.getService(DreamManagerInternal.class);
Mark Renoufc1256912015-03-11 14:38:23 -04001251
1252 // Init display burn-in protection
1253 boolean burnInProtectionEnabled = context.getResources().getBoolean(
1254 com.android.internal.R.bool.config_enableBurnInProtection);
1255 // Allow a system property to override this. Used by developer settings.
1256 boolean burnInProtectionDevMode =
1257 SystemProperties.getBoolean("persist.debug.force_burn_in", false);
1258 if (burnInProtectionEnabled || burnInProtectionDevMode) {
1259 final int minHorizontal;
1260 final int maxHorizontal;
1261 final int minVertical;
1262 final int maxVertical;
1263 final int maxRadius;
1264 if (burnInProtectionDevMode) {
1265 minHorizontal = -8;
1266 maxHorizontal = 8;
1267 minVertical = -8;
1268 maxVertical = -4;
1269 maxRadius = (isRoundWindow()) ? 6 : -1;
1270 } else {
1271 Resources resources = context.getResources();
1272 minHorizontal = resources.getInteger(
1273 com.android.internal.R.integer.config_burnInProtectionMinHorizontalOffset);
1274 maxHorizontal = resources.getInteger(
1275 com.android.internal.R.integer.config_burnInProtectionMaxHorizontalOffset);
1276 minVertical = resources.getInteger(
1277 com.android.internal.R.integer.config_burnInProtectionMinVerticalOffset);
1278 maxVertical = resources.getInteger(
1279 com.android.internal.R.integer.config_burnInProtectionMaxVerticalOffset);
1280 maxRadius = resources.getInteger(
1281 com.android.internal.R.integer.config_burnInProtectionMaxRadius);
1282 }
1283 mBurnInProtectionHelper = new BurnInProtectionHelper(
1284 context, minHorizontal, maxHorizontal, minVertical, maxVertical, maxRadius);
Filip Gruszczynskicfb31852015-02-25 21:47:12 +00001285 }
Craig Mautner8a0da012014-05-31 15:13:37 -07001286
Jeff Brown70825162012-03-28 17:27:48 -07001287 mHandler = new PolicyHandler();
Jeff Browna20dda42014-05-27 20:57:24 -07001288 mWakeGestureListener = new MyWakeGestureListener(mContext, mHandler);
Craig Mautnereee29c42013-01-17 14:44:34 -08001289 mOrientationListener = new MyOrientationListener(mContext, mHandler);
Jeff Brownc0347aa2011-09-23 17:26:09 -07001290 try {
1291 mOrientationListener.setCurrentRotation(windowManager.getRotation());
1292 } catch (RemoteException ex) { }
Christopher Tate5e08af02012-09-21 17:17:22 -07001293 mSettingsObserver = new SettingsObserver(mHandler);
1294 mSettingsObserver.observe();
Svetoslav683914b2015-01-15 14:22:26 -08001295 mShortcutManager = new ShortcutManager(context);
Daniel Sandler6396c722013-04-16 20:19:09 -04001296 mUiMode = context.getResources().getInteger(
1297 com.android.internal.R.integer.config_defaultUiModeType);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001298 mHomeIntent = new Intent(Intent.ACTION_MAIN, null);
1299 mHomeIntent.addCategory(Intent.CATEGORY_HOME);
1300 mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1301 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07001302 mCarDockIntent = new Intent(Intent.ACTION_MAIN, null);
1303 mCarDockIntent.addCategory(Intent.CATEGORY_CAR_DOCK);
1304 mCarDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1305 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
1306 mDeskDockIntent = new Intent(Intent.ACTION_MAIN, null);
1307 mDeskDockIntent.addCategory(Intent.CATEGORY_DESK_DOCK);
1308 mDeskDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1309 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Jim Millere6ad1a82010-08-20 19:25:39 -07001310
Jeff Brown96307042012-07-27 15:51:34 -07001311 mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
1312 mBroadcastWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001313 "PhoneWindowManager.mBroadcastWakeLock");
Jeff Brown13f00f02014-10-31 14:45:50 -07001314 mPowerKeyWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
1315 "PhoneWindowManager.mPowerKeyWakeLock");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001316 mEnableShiftMenuBugReports = "1".equals(SystemProperties.get("ro.debuggable"));
Jeff Brownbcdfc622014-03-06 19:13:04 -08001317 mSupportAutoRotation = mContext.getResources().getBoolean(
1318 com.android.internal.R.bool.config_supportAutoRotation);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001319 mLidOpenRotation = readRotation(
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001320 com.android.internal.R.integer.config_lidOpenRotation);
1321 mCarDockRotation = readRotation(
1322 com.android.internal.R.integer.config_carDockRotation);
1323 mDeskDockRotation = readRotation(
1324 com.android.internal.R.integer.config_deskDockRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001325 mUndockedHdmiRotation = readRotation(
1326 com.android.internal.R.integer.config_undockedHdmiRotation);
Mike Lockwoode9867d22009-09-20 01:59:02 -04001327 mCarDockEnablesAccelerometer = mContext.getResources().getBoolean(
1328 com.android.internal.R.bool.config_carDockEnablesAccelerometer);
1329 mDeskDockEnablesAccelerometer = mContext.getResources().getBoolean(
1330 com.android.internal.R.bool.config_deskDockEnablesAccelerometer);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001331 mLidKeyboardAccessibility = mContext.getResources().getInteger(
1332 com.android.internal.R.integer.config_lidKeyboardAccessibility);
1333 mLidNavigationAccessibility = mContext.getResources().getInteger(
1334 com.android.internal.R.integer.config_lidNavigationAccessibility);
Jeff Brownc458ce92012-04-30 14:58:40 -07001335 mLidControlsSleep = mContext.getResources().getBoolean(
1336 com.android.internal.R.bool.config_lidControlsSleep);
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04001337 mTranslucentDecorEnabled = mContext.getResources().getBoolean(
1338 com.android.internal.R.bool.config_enableTranslucentDecor);
Bryce Lee584a4452014-10-21 15:55:55 -07001339
1340 mAllowTheaterModeWakeFromKey = mContext.getResources().getBoolean(
1341 com.android.internal.R.bool.config_allowTheaterModeWakeFromKey);
1342 mAllowTheaterModeWakeFromPowerKey = mAllowTheaterModeWakeFromKey
1343 || mContext.getResources().getBoolean(
1344 com.android.internal.R.bool.config_allowTheaterModeWakeFromPowerKey);
1345 mAllowTheaterModeWakeFromMotion = mContext.getResources().getBoolean(
1346 com.android.internal.R.bool.config_allowTheaterModeWakeFromMotion);
Bryce Lee812d7022014-11-10 13:33:28 -08001347 mAllowTheaterModeWakeFromMotionWhenNotDreaming = mContext.getResources().getBoolean(
1348 com.android.internal.R.bool.config_allowTheaterModeWakeFromMotionWhenNotDreaming);
Bryce Lee584a4452014-10-21 15:55:55 -07001349 mAllowTheaterModeWakeFromCameraLens = mContext.getResources().getBoolean(
1350 com.android.internal.R.bool.config_allowTheaterModeWakeFromCameraLens);
1351 mAllowTheaterModeWakeFromLidSwitch = mContext.getResources().getBoolean(
1352 com.android.internal.R.bool.config_allowTheaterModeWakeFromLidSwitch);
1353 mAllowTheaterModeWakeFromWakeGesture = mContext.getResources().getBoolean(
1354 com.android.internal.R.bool.config_allowTheaterModeWakeFromGesture);
1355
Bryce Lee55e846d2014-11-04 12:43:44 -08001356 mGoToSleepOnButtonPressTheaterMode = mContext.getResources().getBoolean(
1357 com.android.internal.R.bool.config_goToSleepOnButtonPressTheaterMode);
1358
Bryce Leed3b28402015-03-09 15:49:13 +00001359 mSupportLongPressPowerWhenNonInteractive = mContext.getResources().getBoolean(
1360 com.android.internal.R.bool.config_supportLongPressPowerWhenNonInteractive);
1361
Jeff Brown13f00f02014-10-31 14:45:50 -07001362 mShortPressOnPowerBehavior = mContext.getResources().getInteger(
1363 com.android.internal.R.integer.config_shortPressOnPowerBehavior);
1364 mLongPressOnPowerBehavior = mContext.getResources().getInteger(
1365 com.android.internal.R.integer.config_longPressOnPowerBehavior);
1366 mDoublePressOnPowerBehavior = mContext.getResources().getInteger(
1367 com.android.internal.R.integer.config_doublePressOnPowerBehavior);
1368 mTriplePressOnPowerBehavior = mContext.getResources().getInteger(
1369 com.android.internal.R.integer.config_triplePressOnPowerBehavior);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001370 mShortPressOnSleepBehavior = mContext.getResources().getInteger(
1371 com.android.internal.R.integer.config_shortPressOnSleepBehavior);
Jeff Brown13f00f02014-10-31 14:45:50 -07001372
John Spurlock61560172015-02-06 19:46:04 -05001373 mUseTvRouting = AudioSystem.getPlatformType(mContext) == AudioSystem.PLATFORM_TELEVISION;
RoboErik001c59c2015-01-26 15:53:51 -08001374
Jeff Brownf71343d2013-05-31 17:59:11 -07001375 readConfigurationDependentBehaviors();
Jeff Browncaca8812013-05-09 13:34:33 -07001376
Svetoslav8e3feb12014-02-24 13:46:47 -08001377 mAccessibilityManager = (AccessibilityManager) context.getSystemService(
1378 Context.ACCESSIBILITY_SERVICE);
1379
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001380 // register for dock events
Dianne Hackborn78968392010-03-04 20:47:56 -08001381 IntentFilter filter = new IntentFilter();
1382 filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE);
1383 filter.addAction(UiModeManager.ACTION_EXIT_CAR_MODE);
1384 filter.addAction(UiModeManager.ACTION_ENTER_DESK_MODE);
1385 filter.addAction(UiModeManager.ACTION_EXIT_DESK_MODE);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001386 filter.addAction(Intent.ACTION_DOCK_EVENT);
1387 Intent intent = context.registerReceiver(mDockReceiver, filter);
1388 if (intent != null) {
1389 // Retrieve current sticky dock event broadcast.
1390 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
1391 Intent.EXTRA_DOCK_STATE_UNDOCKED);
1392 }
Daniel Sandler7e37df52011-11-16 22:08:23 -08001393
Jeff Brown6aaf2952012-10-05 16:01:08 -07001394 // register for dream-related broadcasts
1395 filter = new IntentFilter();
1396 filter.addAction(Intent.ACTION_DREAMING_STARTED);
1397 filter.addAction(Intent.ACTION_DREAMING_STOPPED);
1398 context.registerReceiver(mDreamReceiver, filter);
1399
Christopher Tate5e08af02012-09-21 17:17:22 -07001400 // register for multiuser-relevant broadcasts
1401 filter = new IntentFilter(Intent.ACTION_USER_SWITCHED);
1402 context.registerReceiver(mMultiuserReceiver, filter);
1403
John Spurlock57306e62013-04-22 09:48:49 -04001404 // monitor for system gestures
Craig Mautner037aa8d2013-06-07 10:35:44 -07001405 mSystemGestures = new SystemGesturesPointerEventListener(context,
1406 new SystemGesturesPointerEventListener.Callbacks() {
John Spurlock57306e62013-04-22 09:48:49 -04001407 @Override
1408 public void onSwipeFromTop() {
John Spurlock04db1762013-05-13 12:46:41 -04001409 if (mStatusBar != null) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001410 requestTransientBars(mStatusBar);
John Spurlock04db1762013-05-13 12:46:41 -04001411 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04001412 }
1413 @Override
1414 public void onSwipeFromBottom() {
John Spurlock04db1762013-05-13 12:46:41 -04001415 if (mNavigationBar != null && mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001416 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001417 }
1418 }
1419 @Override
1420 public void onSwipeFromRight() {
John Spurlock04db1762013-05-13 12:46:41 -04001421 if (mNavigationBar != null && !mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001422 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001423 }
1424 }
1425 @Override
1426 public void onDebug() {
John Spurlockd67ec252013-09-05 11:31:54 -04001427 // no-op
John Spurlockad3e6cb2013-04-30 08:47:43 -04001428 }
Adrian Roos3595be42015-03-05 16:31:15 +01001429 @Override
1430 public void onDown() {
1431 mOrientationListener.onTouchStart();
1432 }
1433 @Override
1434 public void onUpOrCancel() {
1435 mOrientationListener.onTouchEnd();
1436 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04001437 });
John Spurlockf1a36642013-10-12 17:50:42 -04001438 mImmersiveModeConfirmation = new ImmersiveModeConfirmation(mContext);
Craig Mautner037aa8d2013-06-07 10:35:44 -07001439 mWindowManagerFuncs.registerPointerEventListener(mSystemGestures);
John Spurlock32beb2c2013-03-11 10:16:47 -04001440
Jeff Brownc2346132012-04-13 01:55:38 -07001441 mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001442 mLongPressVibePattern = getLongIntArray(mContext.getResources(),
1443 com.android.internal.R.array.config_longPressVibePattern);
1444 mVirtualKeyVibePattern = getLongIntArray(mContext.getResources(),
1445 com.android.internal.R.array.config_virtualKeyVibePattern);
Amith Yamasanic33cb712010-02-10 15:21:49 -08001446 mKeyboardTapVibePattern = getLongIntArray(mContext.getResources(),
1447 com.android.internal.R.array.config_keyboardTapVibePattern);
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07001448 mClockTickVibePattern = getLongIntArray(mContext.getResources(),
1449 com.android.internal.R.array.config_clockTickVibePattern);
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07001450 mCalendarDateVibePattern = getLongIntArray(mContext.getResources(),
1451 com.android.internal.R.array.config_calendarDateVibePattern);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001452 mSafeModeDisabledVibePattern = getLongIntArray(mContext.getResources(),
1453 com.android.internal.R.array.config_safeModeDisabledVibePattern);
1454 mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(),
1455 com.android.internal.R.array.config_safeModeEnabledVibePattern);
Mady Mellore8608912015-06-05 09:02:55 -07001456 mContextClickVibePattern = getLongIntArray(mContext.getResources(),
1457 com.android.internal.R.array.config_contextClickVibePattern);
Daniel Sandler40427442010-07-16 11:44:52 -04001458
Christopher Tatee90585f2012-03-05 18:56:25 -08001459 mScreenshotChordEnabled = mContext.getResources().getBoolean(
1460 com.android.internal.R.bool.config_enableScreenshotChord);
1461
Justin Kohd378ad72013-04-01 12:18:26 -07001462 mGlobalKeyManager = new GlobalKeyManager(mContext);
1463
Joe Onoratoea495d42011-04-06 11:41:11 -07001464 // Controls rotation and the like.
1465 initializeHdmiState();
Dianne Hackborn40011092011-09-22 13:37:48 -07001466
1467 // Match current screen state.
Craig Mautnera631d492014-08-05 15:16:01 -07001468 if (!mPowerManager.isInteractive()) {
Jeff Brown416c49c2015-05-26 19:50:18 -07001469 startedGoingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
1470 finishedGoingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
Dianne Hackborn40011092011-09-22 13:37:48 -07001471 }
Jorim Jaggi24bec7c2015-02-04 12:40:14 +01001472
1473 mWindowManagerInternal.registerAppTransitionListener(
1474 mStatusBarController.getAppTransitionListener());
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001475 }
1476
Jeff Brownf71343d2013-05-31 17:59:11 -07001477 /**
1478 * Read values from config.xml that may be overridden depending on
1479 * the configuration of the device.
1480 * eg. Disable long press on home goes to recents on sw600dp.
1481 */
1482 private void readConfigurationDependentBehaviors() {
1483 mLongPressOnHomeBehavior = mContext.getResources().getInteger(
1484 com.android.internal.R.integer.config_longPressOnHomeBehavior);
1485 if (mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING ||
1486 mLongPressOnHomeBehavior > LONG_PRESS_HOME_ASSIST) {
1487 mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1488 }
1489
1490 mDoubleTapOnHomeBehavior = mContext.getResources().getInteger(
1491 com.android.internal.R.integer.config_doubleTapOnHomeBehavior);
1492 if (mDoubleTapOnHomeBehavior < DOUBLE_TAP_HOME_NOTHING ||
1493 mDoubleTapOnHomeBehavior > DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1494 mDoubleTapOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1495 }
1496 }
1497
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001498 @Override
Dianne Hackborndde331c2012-08-03 14:01:57 -07001499 public void setInitialDisplaySize(Display display, int width, int height, int density) {
Jeff Brownef981a42013-08-07 14:13:37 -07001500 // This method might be called before the policy has been fully initialized
1501 // or for other displays we don't care about.
1502 if (mContext == null || display.getDisplayId() != Display.DEFAULT_DISPLAY) {
1503 return;
Dianne Hackbornc652de82013-02-15 16:32:56 -08001504 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001505 mDisplay = display;
1506
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001507 final Resources res = mContext.getResources();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001508 int shortSize, longSize;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001509 if (width > height) {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001510 shortSize = height;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001511 longSize = width;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001512 mLandscapeRotation = Surface.ROTATION_0;
1513 mSeascapeRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001514 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001515 mPortraitRotation = Surface.ROTATION_90;
1516 mUpsideDownRotation = Surface.ROTATION_270;
1517 } else {
1518 mPortraitRotation = Surface.ROTATION_270;
1519 mUpsideDownRotation = Surface.ROTATION_90;
1520 }
1521 } else {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001522 shortSize = width;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001523 longSize = height;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001524 mPortraitRotation = Surface.ROTATION_0;
1525 mUpsideDownRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001526 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001527 mLandscapeRotation = Surface.ROTATION_270;
1528 mSeascapeRotation = Surface.ROTATION_90;
1529 } else {
1530 mLandscapeRotation = Surface.ROTATION_90;
1531 mSeascapeRotation = Surface.ROTATION_270;
1532 }
1533 }
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001534
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001535 mStatusBarHeight =
1536 res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001537
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001538 // Height of the navigation bar when presented horizontally at bottom
1539 mNavigationBarHeightForRotation[mPortraitRotation] =
1540 mNavigationBarHeightForRotation[mUpsideDownRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001541 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_height);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001542 mNavigationBarHeightForRotation[mLandscapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001543 mNavigationBarHeightForRotation[mSeascapeRotation] = res.getDimensionPixelSize(
1544 com.android.internal.R.dimen.navigation_bar_height_landscape);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001545
1546 // Width of the navigation bar when presented vertically along one side
1547 mNavigationBarWidthForRotation[mPortraitRotation] =
1548 mNavigationBarWidthForRotation[mUpsideDownRotation] =
1549 mNavigationBarWidthForRotation[mLandscapeRotation] =
1550 mNavigationBarWidthForRotation[mSeascapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001551 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_width);
Daniel Sandler4a066c52012-04-20 14:49:13 -04001552
1553 // SystemUI (status bar) layout policy
Dianne Hackborndde331c2012-08-03 14:01:57 -07001554 int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / density;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001555 int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / density;
Daniel Sandler4a066c52012-04-20 14:49:13 -04001556
Devin Kimd7b12b42014-05-05 14:34:58 -07001557 // Allow the navigation bar to move on non-square small devices (phones).
1558 mNavigationBarCanMove = width != height && shortSizeDp < 600;
Daniel Sandler36412a72011-08-04 09:35:13 -04001559
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001560 mHasNavigationBar = res.getBoolean(com.android.internal.R.bool.config_showNavigationBar);
John Spurlock80f00c12013-06-13 11:10:51 -04001561 // Allow a system property to override this. Used by the emulator.
1562 // See also hasNavigationBar().
1563 String navBarOverride = SystemProperties.get("qemu.hw.mainkeys");
1564 if ("1".equals(navBarOverride)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001565 mHasNavigationBar = false;
John Spurlock80f00c12013-06-13 11:10:51 -04001566 } else if ("0".equals(navBarOverride)) {
1567 mHasNavigationBar = true;
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04001568 }
1569
Jeff Brown27f1d672012-10-17 18:32:34 -07001570 // For demo purposes, allow the rotation of the HDMI display to be controlled.
1571 // By default, HDMI locks rotation to landscape.
Erik Gilling9a41ef82011-09-26 19:21:03 -07001572 if ("portrait".equals(SystemProperties.get("persist.demo.hdmirotation"))) {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001573 mDemoHdmiRotation = mPortraitRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001574 } else {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001575 mDemoHdmiRotation = mLandscapeRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001576 }
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001577 mDemoHdmiRotationLock = SystemProperties.getBoolean("persist.demo.hdmirotationlock", false);
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001578
Chong Zhangae6119ff2014-11-11 18:54:39 -08001579 // For demo purposes, allow the rotation of the remote display to be controlled.
1580 // By default, remote display locks rotation to landscape.
1581 if ("portrait".equals(SystemProperties.get("persist.demo.remoterotation"))) {
1582 mDemoRotation = mPortraitRotation;
1583 } else {
1584 mDemoRotation = mLandscapeRotation;
1585 }
1586 mDemoRotationLock = SystemProperties.getBoolean(
1587 "persist.demo.rotationlock", false);
1588
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001589 // Only force the default orientation if the screen is xlarge, at least 960dp x 720dp, per
1590 // http://developer.android.com/guide/practices/screens_support.html#range
1591 mForceDefaultOrientation = longSizeDp >= 960 && shortSizeDp >= 720 &&
1592 res.getBoolean(com.android.internal.R.bool.config_forceDefaultOrientation) &&
1593 // For debug purposes the next line turns this feature off with:
1594 // $ adb shell setprop config.override_forced_orient true
1595 // $ adb shell wm size reset
1596 !"true".equals(SystemProperties.get("config.override_forced_orient"));
1597 }
1598
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001599 /**
1600 * @return whether the navigation bar can be hidden, e.g. the device has a
1601 * navigation bar and touch exploration is not enabled
1602 */
1603 private boolean canHideNavigationBar() {
Svetoslav8e3feb12014-02-24 13:46:47 -08001604 return mHasNavigationBar
1605 && !mAccessibilityManager.isTouchExplorationEnabled();
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001606 }
1607
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001608 @Override
1609 public boolean isDefaultOrientationForced() {
1610 return mForceDefaultOrientation;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001611 }
1612
Dianne Hackbornc652de82013-02-15 16:32:56 -08001613 @Override
1614 public void setDisplayOverscan(Display display, int left, int top, int right, int bottom) {
1615 if (display.getDisplayId() == Display.DEFAULT_DISPLAY) {
1616 mOverscanLeft = left;
1617 mOverscanTop = top;
1618 mOverscanRight = right;
1619 mOverscanBottom = bottom;
1620 }
1621 }
1622
Dianne Hackbornc777e072010-02-12 13:07:59 -08001623 public void updateSettings() {
1624 ContentResolver resolver = mContext.getContentResolver();
1625 boolean updateRotation = false;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001626 synchronized (mLock) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001627 mEndcallBehavior = Settings.System.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001628 Settings.System.END_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001629 Settings.System.END_BUTTON_BEHAVIOR_DEFAULT,
1630 UserHandle.USER_CURRENT);
1631 mIncallPowerBehavior = Settings.Secure.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001632 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001633 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT,
1634 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001635
Jeff Browna20dda42014-05-27 20:57:24 -07001636 // Configure wake gesture.
1637 boolean wakeGestureEnabledSetting = Settings.Secure.getIntForUser(resolver,
1638 Settings.Secure.WAKE_GESTURE_ENABLED, 0,
1639 UserHandle.USER_CURRENT) != 0;
1640 if (mWakeGestureEnabledSetting != wakeGestureEnabledSetting) {
1641 mWakeGestureEnabledSetting = wakeGestureEnabledSetting;
1642 updateWakeGestureListenerLp();
1643 }
1644
Jeff Brown207673cd2012-06-05 17:47:11 -07001645 // Configure rotation lock.
Christopher Tate5e08af02012-09-21 17:17:22 -07001646 int userRotation = Settings.System.getIntForUser(resolver,
1647 Settings.System.USER_ROTATION, Surface.ROTATION_0,
1648 UserHandle.USER_CURRENT);
Jeff Brown207673cd2012-06-05 17:47:11 -07001649 if (mUserRotation != userRotation) {
1650 mUserRotation = userRotation;
1651 updateRotation = true;
1652 }
Christopher Tate5e08af02012-09-21 17:17:22 -07001653 int userRotationMode = Settings.System.getIntForUser(resolver,
1654 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
Jeff Brown207673cd2012-06-05 17:47:11 -07001655 WindowManagerPolicy.USER_ROTATION_FREE :
1656 WindowManagerPolicy.USER_ROTATION_LOCKED;
1657 if (mUserRotationMode != userRotationMode) {
1658 mUserRotationMode = userRotationMode;
1659 updateRotation = true;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001660 updateOrientationListenerLp();
1661 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001662
Dianne Hackbornc777e072010-02-12 13:07:59 -08001663 if (mSystemReady) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001664 int pointerLocation = Settings.System.getIntForUser(resolver,
1665 Settings.System.POINTER_LOCATION, 0, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001666 if (mPointerLocationMode != pointerLocation) {
1667 mPointerLocationMode = pointerLocation;
Jeff Brown70825162012-03-28 17:27:48 -07001668 mHandler.sendEmptyMessage(pointerLocation != 0 ?
1669 MSG_ENABLE_POINTER_LOCATION : MSG_DISABLE_POINTER_LOCATION);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001670 }
1671 }
1672 // use screen off timeout setting as the timeout for the lockscreen
Christopher Tate5e08af02012-09-21 17:17:22 -07001673 mLockScreenTimeout = Settings.System.getIntForUser(resolver,
1674 Settings.System.SCREEN_OFF_TIMEOUT, 0, UserHandle.USER_CURRENT);
1675 String imId = Settings.Secure.getStringForUser(resolver,
1676 Settings.Secure.DEFAULT_INPUT_METHOD, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001677 boolean hasSoftInput = imId != null && imId.length() > 0;
1678 if (mHasSoftInput != hasSoftInput) {
1679 mHasSoftInput = hasSoftInput;
1680 updateRotation = true;
1681 }
John Spurlockf1a36642013-10-12 17:50:42 -04001682 if (mImmersiveModeConfirmation != null) {
John Spurlock4355a532014-02-19 09:49:25 -05001683 mImmersiveModeConfirmation.loadSetting(mCurrentUserId);
John Spurlockd67ec252013-09-05 11:31:54 -04001684 }
John Spurlockc6d1c602014-01-17 15:22:06 -05001685 PolicyControl.reloadFromSetting(mContext);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001686 }
1687 if (updateRotation) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07001688 updateRotation(true);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001689 }
Jeff Brown70825162012-03-28 17:27:48 -07001690 }
1691
Jeff Browna20dda42014-05-27 20:57:24 -07001692 private void updateWakeGestureListenerLp() {
1693 if (shouldEnableWakeGestureLp()) {
1694 mWakeGestureListener.requestWakeUpTrigger();
1695 } else {
1696 mWakeGestureListener.cancelWakeUpTrigger();
1697 }
1698 }
1699
1700 private boolean shouldEnableWakeGestureLp() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07001701 return mWakeGestureEnabledSetting && !mAwake
Jeff Browna20dda42014-05-27 20:57:24 -07001702 && (!mLidControlsSleep || mLidState != LID_CLOSED)
1703 && mWakeGestureListener.isSupported();
1704 }
1705
Jeff Brown70825162012-03-28 17:27:48 -07001706 private void enablePointerLocation() {
1707 if (mPointerLocationView == null) {
1708 mPointerLocationView = new PointerLocationView(mContext);
1709 mPointerLocationView.setPrintCoords(false);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001710 WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
1711 WindowManager.LayoutParams.MATCH_PARENT,
1712 WindowManager.LayoutParams.MATCH_PARENT);
Jeff Brown3b2b3542010-10-15 00:54:27 -07001713 lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001714 lp.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN
1715 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
1716 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1717 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
Jeff Brown90fc9052012-10-01 14:44:24 -07001718 if (ActivityManager.isHighEndGfx()) {
1719 lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
1720 lp.privateFlags |=
1721 WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED;
1722 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001723 lp.format = PixelFormat.TRANSLUCENT;
1724 lp.setTitle("PointerLocation");
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001725 WindowManager wm = (WindowManager)
Dianne Hackbornc777e072010-02-12 13:07:59 -08001726 mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Browncc4f7db2011-08-30 20:34:48 -07001727 lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL;
Jeff Brown70825162012-03-28 17:27:48 -07001728 wm.addView(mPointerLocationView, lp);
Michael Wrightc9c487e2013-11-07 18:55:09 -08001729 mWindowManagerFuncs.registerPointerEventListener(mPointerLocationView);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001730 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001731 }
Jeff Brown70825162012-03-28 17:27:48 -07001732
1733 private void disablePointerLocation() {
Jeff Brown70825162012-03-28 17:27:48 -07001734 if (mPointerLocationView != null) {
Michael Wrightc9c487e2013-11-07 18:55:09 -08001735 mWindowManagerFuncs.unregisterPointerEventListener(mPointerLocationView);
1736 WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Brown70825162012-03-28 17:27:48 -07001737 wm.removeView(mPointerLocationView);
1738 mPointerLocationView = null;
1739 }
1740 }
1741
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001742 private int readRotation(int resID) {
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001743 try {
1744 int rotation = mContext.getResources().getInteger(resID);
1745 switch (rotation) {
1746 case 0:
1747 return Surface.ROTATION_0;
1748 case 90:
1749 return Surface.ROTATION_90;
1750 case 180:
1751 return Surface.ROTATION_180;
1752 case 270:
1753 return Surface.ROTATION_270;
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001754 }
1755 } catch (Resources.NotFoundException e) {
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001756 // fall through
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001757 }
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001758 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001759 }
1760
1761 /** {@inheritDoc} */
Craig Mautner88400d32012-09-30 12:35:45 -07001762 @Override
Dianne Hackbornc2293022013-02-06 23:14:49 -08001763 public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001764 int type = attrs.type;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001765
1766 outAppOp[0] = AppOpsManager.OP_NONE;
1767
Wale Ogunwale74bf0652015-01-12 10:24:36 -08001768 if (!((type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW)
1769 || (type >= FIRST_SUB_WINDOW && type <= LAST_SUB_WINDOW)
1770 || (type >= FIRST_SYSTEM_WINDOW && type <= LAST_SYSTEM_WINDOW))) {
1771 return WindowManagerGlobal.ADD_INVALID_TYPE;
1772 }
1773
1774 if (type < FIRST_SYSTEM_WINDOW || type > LAST_SYSTEM_WINDOW) {
1775 // Window manager will make sure these are okay.
Jeff Brown98365d72012-08-19 20:30:52 -07001776 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001777 }
1778 String permission = null;
1779 switch (type) {
1780 case TYPE_TOAST:
1781 // XXX right now the app process has complete control over
1782 // this... should introduce a token to let the system
1783 // monitor/control what they are doing.
Jason Monk1c7c3192014-06-26 12:52:18 -04001784 outAppOp[0] = AppOpsManager.OP_TOAST_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001785 break;
Daniel Sandler7d276c32012-01-30 14:33:52 -05001786 case TYPE_DREAM:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001787 case TYPE_INPUT_METHOD:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001788 case TYPE_WALLPAPER:
keunyounga446bf02013-06-21 19:07:57 -07001789 case TYPE_PRIVATE_PRESENTATION:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001790 case TYPE_VOICE_INTERACTION:
Svetoslav3a5c7212014-10-14 09:54:26 -07001791 case TYPE_ACCESSIBILITY_OVERLAY:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001792 // The window manager will check these.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001793 break;
1794 case TYPE_PHONE:
1795 case TYPE_PRIORITY_PHONE:
1796 case TYPE_SYSTEM_ALERT:
1797 case TYPE_SYSTEM_ERROR:
1798 case TYPE_SYSTEM_OVERLAY:
1799 permission = android.Manifest.permission.SYSTEM_ALERT_WINDOW;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001800 outAppOp[0] = AppOpsManager.OP_SYSTEM_ALERT_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001801 break;
1802 default:
1803 permission = android.Manifest.permission.INTERNAL_SYSTEM_WINDOW;
1804 }
1805 if (permission != null) {
1806 if (mContext.checkCallingOrSelfPermission(permission)
1807 != PackageManager.PERMISSION_GRANTED) {
Jeff Brown98365d72012-08-19 20:30:52 -07001808 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001809 }
1810 }
Jeff Brown98365d72012-08-19 20:30:52 -07001811 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001812 }
Craig Mautner88400d32012-09-30 12:35:45 -07001813
1814 @Override
1815 public boolean checkShowToOwnerOnly(WindowManager.LayoutParams attrs) {
1816
1817 // If this switch statement is modified, modify the comment in the declarations of
1818 // the type in {@link WindowManager.LayoutParams} as well.
1819 switch (attrs.type) {
1820 default:
1821 // These are the windows that by default are shown only to the user that created
1822 // them. If this needs to be overridden, set
1823 // {@link WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS} in
1824 // {@link WindowManager.LayoutParams}. Note that permission
1825 // {@link android.Manifest.permission.INTERNAL_SYSTEM_WINDOW} is required as well.
1826 if ((attrs.privateFlags & PRIVATE_FLAG_SHOW_FOR_ALL_USERS) == 0) {
1827 return true;
1828 }
1829 break;
1830
1831 // These are the windows that by default are shown to all users. However, to
1832 // protect against spoofing, check permissions below.
1833 case TYPE_APPLICATION_STARTING:
1834 case TYPE_BOOT_PROGRESS:
1835 case TYPE_DISPLAY_OVERLAY:
Selim Cinekf83e8242015-05-19 18:08:14 -07001836 case TYPE_INPUT_CONSUMER:
Jim Miller5ecd8112013-01-09 18:50:26 -08001837 case TYPE_KEYGUARD_SCRIM:
Craig Mautner88400d32012-09-30 12:35:45 -07001838 case TYPE_KEYGUARD_DIALOG:
1839 case TYPE_MAGNIFICATION_OVERLAY:
1840 case TYPE_NAVIGATION_BAR:
1841 case TYPE_NAVIGATION_BAR_PANEL:
1842 case TYPE_PHONE:
1843 case TYPE_POINTER:
1844 case TYPE_PRIORITY_PHONE:
Craig Mautner88400d32012-09-30 12:35:45 -07001845 case TYPE_SEARCH_BAR:
1846 case TYPE_STATUS_BAR:
1847 case TYPE_STATUS_BAR_PANEL:
1848 case TYPE_STATUS_BAR_SUB_PANEL:
1849 case TYPE_SYSTEM_DIALOG:
Craig Mautner88400d32012-09-30 12:35:45 -07001850 case TYPE_VOLUME_OVERLAY:
keunyounga446bf02013-06-21 19:07:57 -07001851 case TYPE_PRIVATE_PRESENTATION:
Craig Mautner88400d32012-09-30 12:35:45 -07001852 break;
1853 }
1854
1855 // Check if third party app has set window to system window type.
1856 return mContext.checkCallingOrSelfPermission(
1857 android.Manifest.permission.INTERNAL_SYSTEM_WINDOW)
1858 != PackageManager.PERMISSION_GRANTED;
1859 }
1860
Craig Mautner967212c2013-04-13 21:10:58 -07001861 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001862 public void adjustWindowParamsLw(WindowManager.LayoutParams attrs) {
1863 switch (attrs.type) {
1864 case TYPE_SYSTEM_OVERLAY:
Jeff Brown3b2b3542010-10-15 00:54:27 -07001865 case TYPE_SECURE_SYSTEM_OVERLAY:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001866 // These types of windows can't receive input events.
1867 attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1868 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001869 attrs.flags &= ~WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001870 break;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001871 case TYPE_STATUS_BAR:
1872
1873 // If the Keyguard is in a hidden state (occluded by another window), we force to
1874 // remove the wallpaper and keyguard flag so that any change in-flight after setting
1875 // the keyguard as occluded wouldn't set these flags again.
1876 // See {@link #processKeyguardSetHiddenResultLw}.
1877 if (mKeyguardHidden) {
1878 attrs.flags &= ~WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
1879 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
1880 }
1881 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001882 }
Adrian Roos38502112014-04-09 21:04:11 +02001883
1884 if (attrs.type != TYPE_STATUS_BAR) {
1885 // The status bar is the only window allowed to exhibit keyguard behavior.
1886 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
1887 }
Adrian Roosea562512014-05-05 13:33:03 +02001888
1889 if (ActivityManager.isHighEndGfx()
1890 && (attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0) {
Adrian Roosf5e9b5c2014-09-10 15:27:41 +02001891 attrs.subtreeSystemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
Adrian Roosea562512014-05-05 13:33:03 +02001892 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
1893 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001894 }
RoboErik8a2cfc32014-05-16 11:19:38 -07001895
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001896 void readLidState() {
Jeff Brown2e7760e2012-04-11 15:14:55 -07001897 mLidState = mWindowManagerFuncs.getLidState();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001898 }
RoboErik8a2cfc32014-05-16 11:19:38 -07001899
Michael Wright3818c922014-09-02 13:59:07 -07001900 private void readCameraLensCoverState() {
1901 mCameraLensCoverState = mWindowManagerFuncs.getCameraLensCoverState();
1902 }
1903
Jeff Browndaa37532012-05-01 15:54:03 -07001904 private boolean isHidden(int accessibilityMode) {
1905 switch (accessibilityMode) {
1906 case 1:
1907 return mLidState == LID_CLOSED;
1908 case 2:
1909 return mLidState == LID_OPEN;
1910 default:
1911 return false;
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001912 }
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001913 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001914
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001915 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07001916 @Override
Jeff Browndaa37532012-05-01 15:54:03 -07001917 public void adjustConfigurationLw(Configuration config, int keyboardPresence,
1918 int navigationPresence) {
1919 mHaveBuiltInKeyboard = (keyboardPresence & PRESENCE_INTERNAL) != 0;
1920
Jeff Brownf71343d2013-05-31 17:59:11 -07001921 readConfigurationDependentBehaviors();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001922 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07001923 applyLidSwitchState();
Jeff Brownd04a88c2011-01-16 14:05:47 -08001924
Jeff Browndaa37532012-05-01 15:54:03 -07001925 if (config.keyboard == Configuration.KEYBOARD_NOKEYS
1926 || (keyboardPresence == PRESENCE_INTERNAL
1927 && isHidden(mLidKeyboardAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001928 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_YES;
Jeff Browndaa37532012-05-01 15:54:03 -07001929 if (!mHasSoftInput) {
1930 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_YES;
1931 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001932 }
1933
Jeff Browndaa37532012-05-01 15:54:03 -07001934 if (config.navigation == Configuration.NAVIGATION_NONAV
1935 || (navigationPresence == PRESENCE_INTERNAL
1936 && isHidden(mLidNavigationAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001937 config.navigationHidden = Configuration.NAVIGATIONHIDDEN_YES;
Jeff Brownd04a88c2011-01-16 14:05:47 -08001938 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001939 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001940
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001941 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07001942 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001943 public int windowTypeToLayerLw(int type) {
1944 if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001945 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001946 }
1947 switch (type) {
keunyounga446bf02013-06-21 19:07:57 -07001948 case TYPE_PRIVATE_PRESENTATION:
1949 return 2;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001950 case TYPE_WALLPAPER:
1951 // wallpaper is at the bottom, though the window manager may move it.
1952 return 2;
1953 case TYPE_PHONE:
1954 return 3;
1955 case TYPE_SEARCH_BAR:
Jorim Jaggi225d3b52015-04-01 11:18:57 -07001956 case TYPE_VOICE_INTERACTION_STARTING:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001957 return 4;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001958 case TYPE_VOICE_INTERACTION:
1959 // voice interaction layer is almost immediately above apps.
1960 return 5;
Selim Cinekf83e8242015-05-19 18:08:14 -07001961 case TYPE_INPUT_CONSUMER:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001962 return 6;
Selim Cinekf83e8242015-05-19 18:08:14 -07001963 case TYPE_SYSTEM_DIALOG:
1964 return 7;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001965 case TYPE_TOAST:
1966 // toasts and the plugged-in battery thing
Selim Cinekf83e8242015-05-19 18:08:14 -07001967 return 8;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001968 case TYPE_PRIORITY_PHONE:
1969 // SIM errors and unlock. Not sure if this really should be in a high layer.
Selim Cinekf83e8242015-05-19 18:08:14 -07001970 return 9;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001971 case TYPE_DREAM:
1972 // used for Dreams (screensavers with TYPE_DREAM windows)
Selim Cinekf83e8242015-05-19 18:08:14 -07001973 return 10;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001974 case TYPE_SYSTEM_ALERT:
1975 // like the ANR / app crashed dialogs
Selim Cinekf83e8242015-05-19 18:08:14 -07001976 return 11;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001977 case TYPE_INPUT_METHOD:
1978 // on-screen keyboards and other such input method user interfaces go here.
Selim Cinekf83e8242015-05-19 18:08:14 -07001979 return 12;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001980 case TYPE_INPUT_METHOD_DIALOG:
1981 // on-screen keyboards and other such input method user interfaces go here.
Selim Cinekf83e8242015-05-19 18:08:14 -07001982 return 13;
Jim Miller5ecd8112013-01-09 18:50:26 -08001983 case TYPE_KEYGUARD_SCRIM:
1984 // the safety window that shows behind keyguard while keyguard is starting
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001985 return 14;
Selim Cinekf83e8242015-05-19 18:08:14 -07001986 case TYPE_STATUS_BAR_SUB_PANEL:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001987 return 15;
Selim Cinekf83e8242015-05-19 18:08:14 -07001988 case TYPE_STATUS_BAR:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001989 return 16;
Selim Cinekf83e8242015-05-19 18:08:14 -07001990 case TYPE_STATUS_BAR_PANEL:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001991 return 17;
Selim Cinekf83e8242015-05-19 18:08:14 -07001992 case TYPE_KEYGUARD_DIALOG:
1993 return 18;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001994 case TYPE_VOLUME_OVERLAY:
1995 // the on-screen volume indicator and controller shown when the user
1996 // changes the device volume
Selim Cinekf83e8242015-05-19 18:08:14 -07001997 return 19;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001998 case TYPE_SYSTEM_OVERLAY:
1999 // the on-screen volume indicator and controller shown when the user
2000 // changes the device volume
Selim Cinekf83e8242015-05-19 18:08:14 -07002001 return 20;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002002 case TYPE_NAVIGATION_BAR:
2003 // the navigation bar, if available, shows atop most things
Selim Cinekf83e8242015-05-19 18:08:14 -07002004 return 21;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002005 case TYPE_NAVIGATION_BAR_PANEL:
2006 // some panels (e.g. search) need to show on top of the navigation bar
Selim Cinekf83e8242015-05-19 18:08:14 -07002007 return 22;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002008 case TYPE_SYSTEM_ERROR:
2009 // system-level error dialogs
Selim Cinekf83e8242015-05-19 18:08:14 -07002010 return 23;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002011 case TYPE_MAGNIFICATION_OVERLAY:
2012 // used to highlight the magnified portion of a display
Selim Cinekf83e8242015-05-19 18:08:14 -07002013 return 24;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002014 case TYPE_DISPLAY_OVERLAY:
2015 // used to simulate secondary display devices
Selim Cinekf83e8242015-05-19 18:08:14 -07002016 return 25;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002017 case TYPE_DRAG:
2018 // the drag layer: input for drag-and-drop is associated with this window,
2019 // which sits above all other focusable windows
Selim Cinekf83e8242015-05-19 18:08:14 -07002020 return 26;
Svetoslav3a5c7212014-10-14 09:54:26 -07002021 case TYPE_ACCESSIBILITY_OVERLAY:
2022 // overlay put by accessibility services to intercept user interaction
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002023 return 27;
Selim Cinekf83e8242015-05-19 18:08:14 -07002024 case TYPE_SECURE_SYSTEM_OVERLAY:
Svetoslav3a5c7212014-10-14 09:54:26 -07002025 return 28;
Selim Cinekf83e8242015-05-19 18:08:14 -07002026 case TYPE_BOOT_PROGRESS:
2027 return 29;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002028 case TYPE_POINTER:
2029 // the (mouse) pointer layer
Svetoslav3a5c7212014-10-14 09:54:26 -07002030 return 30;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002031 }
2032 Log.e(TAG, "Unknown window type: " + type);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002033 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002034 }
2035
2036 /** {@inheritDoc} */
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002037 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002038 public int subWindowTypeToLayerLw(int type) {
2039 switch (type) {
2040 case TYPE_APPLICATION_PANEL:
2041 case TYPE_APPLICATION_ATTACHED_DIALOG:
2042 return APPLICATION_PANEL_SUBLAYER;
2043 case TYPE_APPLICATION_MEDIA:
2044 return APPLICATION_MEDIA_SUBLAYER;
Dianne Hackborn5cb8d792009-05-21 17:34:15 -07002045 case TYPE_APPLICATION_MEDIA_OVERLAY:
2046 return APPLICATION_MEDIA_OVERLAY_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002047 case TYPE_APPLICATION_SUB_PANEL:
2048 return APPLICATION_SUB_PANEL_SUBLAYER;
Wale Ogunwale0a4dc222015-04-14 12:58:42 -07002049 case TYPE_APPLICATION_ABOVE_SUB_PANEL:
2050 return APPLICATION_ABOVE_SUB_PANEL_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002051 }
2052 Log.e(TAG, "Unknown sub-window type: " + type);
2053 return 0;
2054 }
2055
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002056 @Override
Dianne Hackbornabe0da02009-09-18 01:55:39 -07002057 public int getMaxWallpaperLayer() {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002058 return windowTypeToLayerLw(TYPE_STATUS_BAR);
Dianne Hackbornabe0da02009-09-18 01:55:39 -07002059 }
2060
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002061 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002062 public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07002063 if (mHasNavigationBar) {
2064 // For a basic navigation bar, when we are in landscape mode we place
2065 // the navigation bar to the side.
Daniel Sandler4a066c52012-04-20 14:49:13 -04002066 if (mNavigationBarCanMove && fullWidth > fullHeight) {
2067 return fullWidth - mNavigationBarWidthForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07002068 }
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002069 }
2070 return fullWidth;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002071 }
2072
Jose Lima9546b202014-07-02 17:21:51 -07002073 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002074 public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07002075 if (mHasNavigationBar) {
2076 // For a basic navigation bar, when we are in portrait mode we place
2077 // the navigation bar to the bottom.
Daniel Sandler4a066c52012-04-20 14:49:13 -04002078 if (!mNavigationBarCanMove || fullWidth < fullHeight) {
2079 return fullHeight - mNavigationBarHeightForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07002080 }
2081 }
2082 return fullHeight;
Dianne Hackborn69cb8752011-05-19 18:13:32 -07002083 }
2084
Jose Lima9546b202014-07-02 17:21:51 -07002085 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002086 public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation) {
2087 return getNonDecorDisplayWidth(fullWidth, fullHeight, rotation);
Dianne Hackborn69cb8752011-05-19 18:13:32 -07002088 }
2089
Jose Lima9546b202014-07-02 17:21:51 -07002090 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002091 public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation) {
John Spurlock80f00c12013-06-13 11:10:51 -04002092 // There is a separate status bar at the top of the display. We don't count that as part
2093 // of the fixed decor, since it can hide; however, for purposes of configurations,
Dianne Hackborn077ee852012-04-09 16:27:07 -07002094 // we do want to exclude it since applications can't generally use that part
2095 // of the screen.
John Spurlock80f00c12013-06-13 11:10:51 -04002096 return getNonDecorDisplayHeight(fullWidth, fullHeight, rotation) - mStatusBarHeight;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002097 }
2098
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002099 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07002100 public boolean isForceHiding(WindowManager.LayoutParams attrs) {
2101 return (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 ||
Jim Millerab954542014-10-10 18:21:49 -07002102 (isKeyguardHostWindow(attrs) &&
2103 (mKeyguardDelegate != null && mKeyguardDelegate.isShowing())) ||
Adrian Roos69e510d2014-07-13 14:57:59 +02002104 (attrs.type == TYPE_KEYGUARD_SCRIM);
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002105 }
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002106
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002107 @Override
Jorim Jaggi0d674622014-05-21 01:34:15 +02002108 public boolean isKeyguardHostWindow(WindowManager.LayoutParams attrs) {
2109 return attrs.type == TYPE_STATUS_BAR;
2110 }
2111
2112 @Override
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002113 public boolean canBeForceHidden(WindowState win, WindowManager.LayoutParams attrs) {
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002114 switch (attrs.type) {
2115 case TYPE_STATUS_BAR:
2116 case TYPE_NAVIGATION_BAR:
2117 case TYPE_WALLPAPER:
2118 case TYPE_DREAM:
Jim Miller5ecd8112013-01-09 18:50:26 -08002119 case TYPE_KEYGUARD_SCRIM:
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002120 return false;
2121 default:
Adrian Roos461829d2015-06-03 14:41:18 -07002122 // Hide only windows below the keyguard host window.
2123 return windowTypeToLayerLw(win.getBaseType())
2124 < windowTypeToLayerLw(TYPE_STATUS_BAR);
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002125 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002126 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002127
Craig Mautner7d7808f2014-09-11 18:02:38 -07002128 @Override
2129 public WindowState getWinShowWhenLockedLw() {
2130 return mWinShowWhenLocked;
2131 }
2132
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002133 /** {@inheritDoc} */
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002134 @Override
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07002135 public View addStartingWindow(IBinder appToken, String packageName, int theme,
2136 CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes,
Adam Powell04fe6eb2013-05-31 14:39:48 -07002137 int icon, int logo, int windowFlags) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002138 if (!SHOW_STARTING_ANIMATIONS) {
2139 return null;
2140 }
2141 if (packageName == null) {
2142 return null;
2143 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002144
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002145 WindowManager wm = null;
2146 View view = null;
2147
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002148 try {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002149 Context context = mContext;
Craig Mautner6fbda632012-07-03 09:26:39 -07002150 if (DEBUG_STARTING_WINDOW) Slog.d(TAG, "addStartingWindow " + packageName
2151 + ": nonLocalizedLabel=" + nonLocalizedLabel + " theme="
2152 + Integer.toHexString(theme));
Dianne Hackborn247fe742011-01-08 17:25:57 -08002153 if (theme != context.getThemeResId() || labelRes != 0) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002154 try {
2155 context = context.createPackageContext(packageName, 0);
Dianne Hackborn247fe742011-01-08 17:25:57 -08002156 context.setTheme(theme);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002157 } catch (PackageManager.NameNotFoundException e) {
2158 // Ignore
2159 }
2160 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002161
Jorim Jaggia16cc152015-06-01 16:55:05 -07002162 PhoneWindow win = new PhoneWindow(context);
2163 win.setIsStartingWindow(true);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002164 final TypedArray ta = win.getWindowStyle();
2165 if (ta.getBoolean(
2166 com.android.internal.R.styleable.Window_windowDisablePreview, false)
2167 || ta.getBoolean(
2168 com.android.internal.R.styleable.Window_windowShowWallpaper,false)) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002169 return null;
2170 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002171
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002172 Resources r = context.getResources();
2173 win.setTitle(r.getText(labelRes, nonLocalizedLabel));
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002174
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002175 win.setType(
2176 WindowManager.LayoutParams.TYPE_APPLICATION_STARTING);
Adrian Roos602c68e2015-04-24 16:03:47 -07002177
2178 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
2179 // Assumes it's safe to show starting windows of launched apps while
2180 // the keyguard is being hidden. This is okay because starting windows never show
2181 // secret information.
2182 if (mKeyguardHidden) {
2183 windowFlags |= FLAG_SHOW_WHEN_LOCKED;
2184 }
2185 }
2186
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002187 // Force the window flags: this is a fake window, so it is not really
2188 // touchable or focusable by the user. We also add in the ALT_FOCUSABLE_IM
2189 // flag because we do know that the next window will take input
2190 // focus, so we want to get the IME window up on top of us right away.
2191 win.setFlags(
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08002192 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002193 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
2194 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
2195 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08002196 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002197 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
2198 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
2199 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002200
Adam Powell04fe6eb2013-05-31 14:39:48 -07002201 win.setDefaultIcon(icon);
2202 win.setDefaultLogo(logo);
2203
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002204 win.setLayout(WindowManager.LayoutParams.MATCH_PARENT,
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07002205 WindowManager.LayoutParams.MATCH_PARENT);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002206
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002207 final WindowManager.LayoutParams params = win.getAttributes();
2208 params.token = appToken;
2209 params.packageName = packageName;
2210 params.windowAnimations = win.getWindowStyle().getResourceId(
2211 com.android.internal.R.styleable.Window_windowAnimationStyle, 0);
John Reck61375a82014-09-18 19:27:48 +00002212 params.privateFlags |=
2213 WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED;
Craig Mautner88400d32012-09-30 12:35:45 -07002214 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
Adam Lesinski95c42972013-10-02 10:13:27 -07002215
2216 if (!compatInfo.supportsScreen()) {
2217 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
2218 }
2219
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002220 params.setTitle("Starting " + packageName);
2221
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002222 wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
2223 view = win.getDecorView();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002224
2225 if (win.isFloating()) {
2226 // Whoops, there is no way to display an animation/preview
2227 // of such a thing! After all that work... let's skip it.
2228 // (Note that we must do this here because it is in
2229 // getDecorView() where the theme is evaluated... maybe
2230 // we should peek the floating attribute from the theme
2231 // earlier.)
2232 return null;
2233 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002234
Craig Mautner6fbda632012-07-03 09:26:39 -07002235 if (DEBUG_STARTING_WINDOW) Slog.d(
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002236 TAG, "Adding starting window for " + packageName
2237 + " / " + appToken + ": "
2238 + (view.getParent() != null ? view : null));
2239
2240 wm.addView(view, params);
2241
2242 // Only return the view if it was successfully added to the
2243 // window manager... which we can tell by it having a parent.
2244 return view.getParent() != null ? view : null;
Jeff Brown98365d72012-08-19 20:30:52 -07002245 } catch (WindowManager.BadTokenException e) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002246 // ignore
Craig Mautner42bf39e2014-02-21 16:46:22 -08002247 Log.w(TAG, appToken + " already running, starting window not displayed. " +
2248 e.getMessage());
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002249 } catch (RuntimeException e) {
2250 // don't crash if something else bad happens, for example a
2251 // failure loading resources because we are loading from an app
2252 // on external storage that has been unmounted.
2253 Log.w(TAG, appToken + " failed creating starting window", e);
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002254 } finally {
2255 if (view != null && view.getParent() == null) {
2256 Log.w(TAG, "view not successfully added to wm, removing view");
2257 wm.removeViewImmediate(view);
2258 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002259 }
2260
2261 return null;
2262 }
2263
2264 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07002265 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002266 public void removeStartingWindow(IBinder appToken, View window) {
Craig Mautner276a6eb2014-11-04 15:32:57 -08002267 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Removing starting window for " + appToken + ": "
2268 + window + " Callers=" + Debug.getCallers(4));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002269
2270 if (window != null) {
Dianne Hackborn5fd21692011-06-07 14:09:47 -07002271 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002272 wm.removeView(window);
2273 }
2274 }
2275
2276 /**
2277 * Preflight adding a window to the system.
RoboErik8a2cfc32014-05-16 11:19:38 -07002278 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002279 * Currently enforces that three window types are singletons:
2280 * <ul>
2281 * <li>STATUS_BAR_TYPE</li>
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002282 * <li>KEYGUARD_TYPE</li>
2283 * </ul>
RoboErik8a2cfc32014-05-16 11:19:38 -07002284 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002285 * @param win The window to be added
2286 * @param attrs Information about the window to be added
RoboErik8a2cfc32014-05-16 11:19:38 -07002287 *
Jeff Brown98365d72012-08-19 20:30:52 -07002288 * @return If ok, WindowManagerImpl.ADD_OKAY. If too many singletons,
2289 * WindowManagerImpl.ADD_MULTIPLE_SINGLETON
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002290 */
Jose Lima9546b202014-07-02 17:21:51 -07002291 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002292 public int prepareAddWindowLw(WindowState win, WindowManager.LayoutParams attrs) {
2293 switch (attrs.type) {
2294 case TYPE_STATUS_BAR:
Joe Onorato8bc6c512010-06-04 16:21:12 -04002295 mContext.enforceCallingOrSelfPermission(
2296 android.Manifest.permission.STATUS_BAR_SERVICE,
2297 "PhoneWindowManager");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002298 if (mStatusBar != null) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002299 if (mStatusBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07002300 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002301 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002302 }
2303 mStatusBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04002304 mStatusBarController.setWindow(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002305 break;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002306 case TYPE_NAVIGATION_BAR:
2307 mContext.enforceCallingOrSelfPermission(
2308 android.Manifest.permission.STATUS_BAR_SERVICE,
2309 "PhoneWindowManager");
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002310 if (mNavigationBar != null) {
2311 if (mNavigationBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07002312 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002313 }
2314 }
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002315 mNavigationBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04002316 mNavigationBarController.setWindow(win);
Craig Mautnereda67292013-04-28 13:50:14 -07002317 if (DEBUG_LAYOUT) Slog.i(TAG, "NAVIGATION BAR: " + mNavigationBar);
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002318 break;
Jim Millere898ac52012-04-06 17:10:57 -07002319 case TYPE_NAVIGATION_BAR_PANEL:
Dianne Hackborn08743722009-12-21 12:16:51 -08002320 case TYPE_STATUS_BAR_PANEL:
Joe Onorato29fc2c92010-11-24 10:26:50 -08002321 case TYPE_STATUS_BAR_SUB_PANEL:
Jorim Jaggi225d3b52015-04-01 11:18:57 -07002322 case TYPE_VOICE_INTERACTION_STARTING:
Joe Onorato29fc2c92010-11-24 10:26:50 -08002323 mContext.enforceCallingOrSelfPermission(
2324 android.Manifest.permission.STATUS_BAR_SERVICE,
2325 "PhoneWindowManager");
Joe Onorato29fc2c92010-11-24 10:26:50 -08002326 break;
Jim Miller5ecd8112013-01-09 18:50:26 -08002327 case TYPE_KEYGUARD_SCRIM:
Jim Miller25190572013-02-28 17:36:24 -08002328 if (mKeyguardScrim != null) {
2329 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
2330 }
Jim Miller5ecd8112013-01-09 18:50:26 -08002331 mKeyguardScrim = win;
2332 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002333 }
Jeff Brown98365d72012-08-19 20:30:52 -07002334 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002335 }
2336
2337 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07002338 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002339 public void removeWindowLw(WindowState win) {
2340 if (mStatusBar == win) {
2341 mStatusBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04002342 mStatusBarController.setWindow(null);
Jim Millerc0b676d2013-03-22 16:11:08 -07002343 mKeyguardDelegate.showScrim();
Jim Miller5ecd8112013-01-09 18:50:26 -08002344 } else if (mKeyguardScrim == win) {
2345 Log.v(TAG, "Removing keyguard scrim");
2346 mKeyguardScrim = null;
2347 } if (mNavigationBar == win) {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002348 mNavigationBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04002349 mNavigationBarController.setWindow(null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002350 }
2351 }
2352
2353 static final boolean PRINT_ANIM = false;
RoboErik8a2cfc32014-05-16 11:19:38 -07002354
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002355 /** {@inheritDoc} */
Craig Mautner4b71aa12012-12-27 17:20:01 -08002356 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002357 public int selectAnimationLw(WindowState win, int transit) {
2358 if (PRINT_ANIM) Log.i(TAG, "selectAnimation in " + win
2359 + ": transit=" + transit);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002360 if (win == mStatusBar) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002361 boolean isKeyguard = (win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002362 if (transit == TRANSIT_EXIT
2363 || transit == TRANSIT_HIDE) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002364 return isKeyguard ? -1 : R.anim.dock_top_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002365 } else if (transit == TRANSIT_ENTER
2366 || transit == TRANSIT_SHOW) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002367 return isKeyguard ? -1 : R.anim.dock_top_enter;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002368 }
2369 } else if (win == mNavigationBar) {
2370 // This can be on either the bottom or the right.
2371 if (mNavigationBarOnBottom) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08002372 if (transit == TRANSIT_EXIT
2373 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002374 return R.anim.dock_bottom_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002375 } else if (transit == TRANSIT_ENTER
2376 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002377 return R.anim.dock_bottom_enter;
2378 }
2379 } else {
Craig Mautner4b71aa12012-12-27 17:20:01 -08002380 if (transit == TRANSIT_EXIT
2381 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002382 return R.anim.dock_right_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002383 } else if (transit == TRANSIT_ENTER
2384 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002385 return R.anim.dock_right_enter;
2386 }
2387 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08002388 }
2389
2390 if (transit == TRANSIT_PREVIEW_DONE) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002391 if (win.hasAppShownWindows()) {
2392 if (PRINT_ANIM) Log.i(TAG, "**** STARTING EXIT");
2393 return com.android.internal.R.anim.app_starting_exit;
2394 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07002395 } else if (win.getAttrs().type == TYPE_DREAM && mDreamingLockscreen
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002396 && transit == TRANSIT_ENTER) {
2397 // Special case: we are animating in a dream, while the keyguard
2398 // is shown. We don't want an animation on the dream, because
2399 // we need it shown immediately with the keyguard animating away
2400 // to reveal it.
2401 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002402 }
2403
2404 return 0;
2405 }
2406
Craig Mautner3c174372013-02-21 17:54:37 -08002407 @Override
2408 public void selectRotationAnimationLw(int anim[]) {
2409 if (PRINT_ANIM) Slog.i(TAG, "selectRotationAnimation mTopFullscreen="
2410 + mTopFullscreenOpaqueWindowState + " rotationAnimation="
2411 + (mTopFullscreenOpaqueWindowState == null ?
2412 "0" : mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation));
2413 if (mTopFullscreenOpaqueWindowState != null && mTopIsFullscreen) {
2414 switch (mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation) {
2415 case ROTATION_ANIMATION_CROSSFADE:
2416 anim[0] = R.anim.rotation_animation_xfade_exit;
2417 anim[1] = R.anim.rotation_animation_enter;
2418 break;
2419 case ROTATION_ANIMATION_JUMPCUT:
2420 anim[0] = R.anim.rotation_animation_jump_exit;
2421 anim[1] = R.anim.rotation_animation_enter;
2422 break;
2423 case ROTATION_ANIMATION_ROTATE:
2424 default:
2425 anim[0] = anim[1] = 0;
2426 break;
2427 }
2428 } else {
2429 anim[0] = anim[1] = 0;
2430 }
2431 }
2432
2433 @Override
2434 public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId,
2435 boolean forceDefault) {
2436 switch (exitAnimId) {
2437 case R.anim.rotation_animation_xfade_exit:
2438 case R.anim.rotation_animation_jump_exit:
2439 // These are the only cases that matter.
2440 if (forceDefault) {
2441 return false;
2442 }
2443 int anim[] = new int[2];
2444 selectRotationAnimationLw(anim);
2445 return (exitAnimId == anim[0] && enterAnimId == anim[1]);
2446 default:
2447 return true;
2448 }
2449 }
2450
2451 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002452 public Animation createForceHideEnterAnimation(boolean onWallpaper,
2453 boolean goingToNotificationShade) {
2454 if (goingToNotificationShade) {
2455 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_behind_enter_fade_in);
Craig Mautnerb8340802014-11-04 15:32:57 -08002456 }
Craig Mautner276a6eb2014-11-04 15:32:57 -08002457
2458 AnimationSet set = (AnimationSet) AnimationUtils.loadAnimation(mContext, onWallpaper ?
2459 R.anim.lock_screen_behind_enter_wallpaper :
2460 R.anim.lock_screen_behind_enter);
2461
2462 // TODO: Use XML interpolators when we have log interpolators available in XML.
2463 final List<Animation> animations = set.getAnimations();
2464 for (int i = animations.size() - 1; i >= 0; --i) {
2465 animations.get(i).setInterpolator(mLogDecelerateInterpolator);
2466 }
2467
2468 return set;
Jorim Jaggi76a16232014-08-08 17:00:47 +02002469 }
2470
2471
2472 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002473 public Animation createForceHideWallpaperExitAnimation(boolean goingToNotificationShade) {
2474 if (goingToNotificationShade) {
2475 return null;
2476 } else {
2477 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_wallpaper_exit);
2478 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002479 }
John Spurlockc8b46ca2013-04-08 12:59:26 -04002480
2481 private static void awakenDreams() {
2482 IDreamManager dreamManager = getDreamManager();
2483 if (dreamManager != null) {
2484 try {
2485 dreamManager.awaken();
2486 } catch (RemoteException e) {
2487 // fine, stay asleep then
2488 }
2489 }
2490 }
2491
2492 static IDreamManager getDreamManager() {
2493 return IDreamManager.Stub.asInterface(
2494 ServiceManager.checkService(DreamService.DREAM_SERVICE));
2495 }
2496
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002497 TelecomManager getTelecommService() {
2498 return (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002499 }
2500
Jeff Brown4d396052010-10-29 21:50:21 -07002501 static IAudioService getAudioService() {
2502 IAudioService audioService = IAudioService.Stub.asInterface(
2503 ServiceManager.checkService(Context.AUDIO_SERVICE));
2504 if (audioService == null) {
2505 Log.w(TAG, "Unable to find IAudioService interface.");
2506 }
2507 return audioService;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002508 }
2509
2510 boolean keyguardOn() {
Jim Millerab954542014-10-10 18:21:49 -07002511 return isKeyguardShowingAndNotOccluded() || inKeyguardRestrictedKeyInputMode();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002512 }
2513
2514 private static final int[] WINDOW_TYPES_WHERE_HOME_DOESNT_WORK = {
2515 WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
2516 WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
2517 };
2518
2519 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002520 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002521 public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002522 final boolean keyguardOn = keyguardOn();
Jeff Brown1f245102010-11-18 20:53:46 -08002523 final int keyCode = event.getKeyCode();
2524 final int repeatCount = event.getRepeatCount();
2525 final int metaState = event.getMetaState();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002526 final int flags = event.getFlags();
Jeff Brown1f245102010-11-18 20:53:46 -08002527 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
2528 final boolean canceled = event.isCanceled();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002529
Jeff Brown40013652012-05-16 21:22:36 -07002530 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002531 Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount="
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002532 + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed
2533 + " canceled=" + canceled);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002534 }
2535
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002536 // If we think we might have a volume down & power key chord on the way
2537 // but we're not sure, then tell the dispatcher to wait a little while and
2538 // try again later before dispatching.
Christopher Tatee90585f2012-03-05 18:56:25 -08002539 if (mScreenshotChordEnabled && (flags & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07002540 if (mScreenshotChordVolumeDownKeyTriggered && !mScreenshotChordPowerKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002541 final long now = SystemClock.uptimeMillis();
Jeff Brown13f00f02014-10-31 14:45:50 -07002542 final long timeoutTime = mScreenshotChordVolumeDownKeyTime
2543 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002544 if (now < timeoutTime) {
2545 return timeoutTime - now;
2546 }
2547 }
2548 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
Jeff Brown13f00f02014-10-31 14:45:50 -07002549 && mScreenshotChordVolumeDownKeyConsumed) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002550 if (!down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07002551 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002552 }
2553 return -1;
2554 }
2555 }
2556
Michael Wright6a62e552014-06-03 19:19:48 -07002557 // Cancel any pending meta actions if we see any other keys being pressed between the down
2558 // of the meta key and its corresponding up.
Michael Wright251e35d2014-08-22 15:40:27 -07002559 if (mPendingMetaAction && !KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07002560 mPendingMetaAction = false;
2561 }
2562
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002563 // First we always handle the home key here, so applications
2564 // can never break it, although if keyguard is on, we do let
2565 // it handle it, because that gives us the correct 5 second
2566 // timeout.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002567 if (keyCode == KeyEvent.KEYCODE_HOME) {
Michael Jurka7f2668c2012-03-27 07:49:52 -07002568
Jeff Brown49ed71d2010-12-06 17:13:33 -08002569 // If we have released the home key, and didn't do anything else
2570 // while it was pressed, then it is time to go home!
Michael Jurka7f2668c2012-03-27 07:49:52 -07002571 if (!down) {
Jeff Browncaca8812013-05-09 13:34:33 -07002572 cancelPreloadRecentApps();
2573
Jeff Brown49ed71d2010-12-06 17:13:33 -08002574 mHomePressed = false;
Jeff Browncaca8812013-05-09 13:34:33 -07002575 if (mHomeConsumed) {
2576 mHomeConsumed = false;
Michael Jurka7f2668c2012-03-27 07:49:52 -07002577 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002578 }
Jeff Browncaca8812013-05-09 13:34:33 -07002579
2580 if (canceled) {
2581 Log.i(TAG, "Ignoring HOME; event canceled.");
2582 return -1;
2583 }
2584
Yorke Lee4f803242014-12-15 23:22:06 +00002585 // If an incoming call is ringing, HOME is totally disabled.
2586 // (The user is already on the InCallUI at this point,
2587 // and his ONLY options are to answer or reject the call.)
2588 TelecomManager telecomManager = getTelecommService();
2589 if (telecomManager != null && telecomManager.isRinging()) {
2590 Log.i(TAG, "Ignoring HOME; there's a ringing incoming call.");
2591 return -1;
2592 }
2593
Jeff Browncaca8812013-05-09 13:34:33 -07002594 // Delay handling home if a double-tap is possible.
2595 if (mDoubleTapOnHomeBehavior != DOUBLE_TAP_HOME_NOTHING) {
2596 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); // just in case
2597 mHomeDoubleTapPending = true;
2598 mHandler.postDelayed(mHomeDoubleTapTimeoutRunnable,
2599 ViewConfiguration.getDoubleTapTimeout());
2600 return -1;
2601 }
2602
Jeff Brown13f00f02014-10-31 14:45:50 -07002603 handleShortPressOnHome();
Jeff Browncaca8812013-05-09 13:34:33 -07002604 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002605 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002606
2607 // If a system window has focus, then it doesn't make sense
2608 // right now to interact with applications.
2609 WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null;
2610 if (attrs != null) {
2611 final int type = attrs.type;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002612 if (type == WindowManager.LayoutParams.TYPE_KEYGUARD_SCRIM
2613 || type == WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG
2614 || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002615 // the "app" is keyguard, so give it the key
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002616 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002617 }
2618 final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length;
2619 for (int i=0; i<typeCount; i++) {
2620 if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) {
2621 // don't do anything, but also don't pass it to the app
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002622 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002623 }
2624 }
2625 }
Jeff Browncaca8812013-05-09 13:34:33 -07002626
2627 // Remember that home is pressed and handle special actions.
2628 if (repeatCount == 0) {
2629 mHomePressed = true;
2630 if (mHomeDoubleTapPending) {
2631 mHomeDoubleTapPending = false;
2632 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable);
2633 handleDoubleTapOnHome();
2634 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI
2635 || mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
2636 preloadRecentApps();
Michael Jurka7f2668c2012-03-27 07:49:52 -07002637 }
Jeff Browncaca8812013-05-09 13:34:33 -07002638 } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) {
2639 if (!keyguardOn) {
2640 handleLongPressOnHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002641 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002642 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002643 return -1;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002644 } else if (keyCode == KeyEvent.KEYCODE_MENU) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002645 // Hijack modified menu keys for debugging features
2646 final int chordBug = KeyEvent.META_SHIFT_ON;
2647
2648 if (down && repeatCount == 0) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002649 if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002650 Intent intent = new Intent(Intent.ACTION_BUG_REPORT);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002651 mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT,
2652 null, null, null, 0, null, null);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002653 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002654 } else if (SHOW_PROCESSES_ON_ALT_MENU &&
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002655 (metaState & KeyEvent.META_ALT_ON) == KeyEvent.META_ALT_ON) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002656 Intent service = new Intent();
2657 service.setClassName(mContext, "com.android.server.LoadAverageService");
2658 ContentResolver res = mContext.getContentResolver();
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002659 boolean shown = Settings.Global.getInt(
2660 res, Settings.Global.SHOW_PROCESSES, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002661 if (!shown) {
2662 mContext.startService(service);
2663 } else {
2664 mContext.stopService(service);
2665 }
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002666 Settings.Global.putInt(
2667 res, Settings.Global.SHOW_PROCESSES, shown ? 0 : 1);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002668 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002669 }
2670 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002671 } else if (keyCode == KeyEvent.KEYCODE_SEARCH) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002672 if (down) {
2673 if (repeatCount == 0) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002674 mSearchKeyShortcutPending = true;
2675 mConsumeSearchKeyUp = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002676 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002677 } else {
2678 mSearchKeyShortcutPending = false;
2679 if (mConsumeSearchKeyUp) {
2680 mConsumeSearchKeyUp = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002681 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002682 }
2683 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002684 return 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002685 } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) {
Michael Wrightc9ebea72013-01-16 19:25:02 -08002686 if (!keyguardOn) {
Jeff Browncaca8812013-05-09 13:34:33 -07002687 if (down && repeatCount == 0) {
2688 preloadRecentApps();
2689 } else if (!down) {
2690 toggleRecentApps();
Michael Wrightc9ebea72013-01-16 19:25:02 -08002691 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002692 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002693 return -1;
Jun Mukaid21b3c82015-04-23 14:09:34 -07002694 } else if (keyCode == KeyEvent.KEYCODE_N && event.isMetaPressed()) {
2695 if (down) {
2696 IStatusBarService service = getStatusBarService();
2697 if (service != null) {
2698 try {
2699 service.expandNotificationsPanel();
2700 } catch (RemoteException e) {
2701 // do nothing.
2702 }
2703 }
2704 }
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002705 } else if (keyCode == KeyEvent.KEYCODE_ASSIST) {
2706 if (down) {
2707 if (repeatCount == 0) {
2708 mAssistKeyLongPressed = false;
2709 } else if (repeatCount == 1) {
2710 mAssistKeyLongPressed = true;
2711 if (!keyguardOn) {
2712 launchAssistLongPressAction();
2713 }
2714 }
2715 } else {
2716 if (mAssistKeyLongPressed) {
2717 mAssistKeyLongPressed = false;
2718 } else {
2719 if (!keyguardOn) {
2720 launchAssistAction();
2721 }
2722 }
2723 }
2724 return -1;
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002725 } else if (keyCode == KeyEvent.KEYCODE_VOICE_ASSIST) {
2726 if (!down) {
2727 Intent voiceIntent;
Michael Wright869a67c2014-08-26 19:33:06 -07002728 if (!keyguardOn) {
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002729 voiceIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
2730 } else {
2731 voiceIntent = new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
Michael Wright869a67c2014-08-26 19:33:06 -07002732 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, true);
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002733 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00002734 startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002735 }
Jeff Sharkey2991fa32012-12-05 18:06:43 -08002736 } else if (keyCode == KeyEvent.KEYCODE_SYSRQ) {
2737 if (down && repeatCount == 0) {
2738 mHandler.post(mScreenshotRunnable);
2739 }
2740 return -1;
Michael Wrightb854e242013-02-05 17:54:02 -08002741 } else if (keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP
2742 || keyCode == KeyEvent.KEYCODE_BRIGHTNESS_DOWN) {
2743 if (down) {
2744 int direction = keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP ? 1 : -1;
2745
2746 // Disable autobrightness if it's on
2747 int auto = Settings.System.getIntForUser(
2748 mContext.getContentResolver(),
2749 Settings.System.SCREEN_BRIGHTNESS_MODE,
2750 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2751 UserHandle.USER_CURRENT_OR_SELF);
2752 if (auto != 0) {
2753 Settings.System.putIntForUser(mContext.getContentResolver(),
2754 Settings.System.SCREEN_BRIGHTNESS_MODE,
2755 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2756 UserHandle.USER_CURRENT_OR_SELF);
2757 }
2758
2759 int min = mPowerManager.getMinimumScreenBrightnessSetting();
2760 int max = mPowerManager.getMaximumScreenBrightnessSetting();
2761 int step = (max - min + BRIGHTNESS_STEPS - 1) / BRIGHTNESS_STEPS * direction;
2762 int brightness = Settings.System.getIntForUser(mContext.getContentResolver(),
2763 Settings.System.SCREEN_BRIGHTNESS,
2764 mPowerManager.getDefaultScreenBrightnessSetting(),
2765 UserHandle.USER_CURRENT_OR_SELF);
2766 brightness += step;
2767 // Make sure we don't go beyond the limits.
2768 brightness = Math.min(max, brightness);
2769 brightness = Math.max(min, brightness);
2770
2771 Settings.System.putIntForUser(mContext.getContentResolver(),
2772 Settings.System.SCREEN_BRIGHTNESS, brightness,
2773 UserHandle.USER_CURRENT_OR_SELF);
Bart Sears8b1c27c2015-03-18 23:51:02 +00002774 startActivityAsUser(new Intent(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG),
Alan Viverette5a399492014-07-14 16:19:38 -07002775 UserHandle.CURRENT_OR_SELF);
Michael Wrightb854e242013-02-05 17:54:02 -08002776 }
2777 return -1;
Michael Wrightce0c13a2014-07-30 10:49:21 -07002778 } else if (KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07002779 if (down) {
2780 mPendingMetaAction = true;
2781 } else if (mPendingMetaAction) {
Michael Wright8ab940a2014-09-01 11:01:27 -07002782 launchAssistAction(Intent.EXTRA_ASSIST_INPUT_HINT_KEYBOARD);
Michael Wright6a62e552014-06-03 19:19:48 -07002783 }
2784 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002785 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002786
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002787 // Shortcuts are invoked through Search+key, so intercept those here
Jeff Browncaab4d02010-12-09 22:13:41 -08002788 // Any printing key that is chorded with Search should be consumed
2789 // even if no shortcut was invoked. This prevents text from being
2790 // inadvertently inserted when using a keyboard that has built-in macro
2791 // shortcut keys (that emit Search+x) and some of them are not registered.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002792 if (mSearchKeyShortcutPending) {
Jeff Browncaab4d02010-12-09 22:13:41 -08002793 final KeyCharacterMap kcm = event.getKeyCharacterMap();
2794 if (kcm.isPrintingKey(keyCode)) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002795 mConsumeSearchKeyUp = true;
2796 mSearchKeyShortcutPending = false;
Jeff Browncaab4d02010-12-09 22:13:41 -08002797 if (down && repeatCount == 0 && !keyguardOn) {
2798 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState);
2799 if (shortcutIntent != null) {
2800 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002801 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00002802 startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002803 } catch (ActivityNotFoundException ex) {
2804 Slog.w(TAG, "Dropping shortcut key combination because "
2805 + "the activity to which it is registered was not found: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002806 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode), ex);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002807 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002808 } else {
2809 Slog.i(TAG, "Dropping unregistered shortcut key combination: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002810 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002811 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002812 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002813 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002814 }
2815 }
2816
Jeff Brown68b909d2011-12-07 16:36:01 -08002817 // Invoke shortcuts using Meta.
Jeff Brown602ab322012-05-16 13:33:47 -07002818 if (down && repeatCount == 0 && !keyguardOn
Jeff Brown68b909d2011-12-07 16:36:01 -08002819 && (metaState & KeyEvent.META_META_ON) != 0) {
2820 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brown602ab322012-05-16 13:33:47 -07002821 if (kcm.isPrintingKey(keyCode)) {
2822 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode,
2823 metaState & ~(KeyEvent.META_META_ON
2824 | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON));
2825 if (shortcutIntent != null) {
2826 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2827 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00002828 startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brown602ab322012-05-16 13:33:47 -07002829 } catch (ActivityNotFoundException ex) {
2830 Slog.w(TAG, "Dropping shortcut key combination because "
2831 + "the activity to which it is registered was not found: "
2832 + "META+" + KeyEvent.keyCodeToString(keyCode), ex);
2833 }
2834 return -1;
Jeff Brown68b909d2011-12-07 16:36:01 -08002835 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002836 }
2837 }
2838
Jeff Brown6651a632011-11-28 12:59:11 -08002839 // Handle application launch keys.
Jeff Brown602ab322012-05-16 13:33:47 -07002840 if (down && repeatCount == 0 && !keyguardOn) {
Jeff Brown6651a632011-11-28 12:59:11 -08002841 String category = sApplicationLaunchKeyCategories.get(keyCode);
2842 if (category != null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -08002843 Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category);
Jeff Brown6651a632011-11-28 12:59:11 -08002844 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2845 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00002846 startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brown6651a632011-11-28 12:59:11 -08002847 } catch (ActivityNotFoundException ex) {
2848 Slog.w(TAG, "Dropping application launch key because "
2849 + "the activity to which it is registered was not found: "
2850 + "keyCode=" + keyCode + ", category=" + category, ex);
2851 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002852 return -1;
Jeff Brown6651a632011-11-28 12:59:11 -08002853 }
2854 }
2855
Michael Wright61c46752014-08-21 16:57:33 -07002856 // Display task switcher for ALT-TAB.
Jeff Brown68b909d2011-12-07 16:36:01 -08002857 if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_TAB) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002858 if (mRecentAppsHeldModifiers == 0 && !keyguardOn) {
Jeff Brown68b909d2011-12-07 16:36:01 -08002859 final int shiftlessModifiers = event.getModifiers() & ~KeyEvent.META_SHIFT_MASK;
Michael Wright61c46752014-08-21 16:57:33 -07002860 if (KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_ALT_ON)) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002861 mRecentAppsHeldModifiers = shiftlessModifiers;
2862 showRecentApps(true);
Jeff Brown68b909d2011-12-07 16:36:01 -08002863 return -1;
2864 }
2865 }
Winson Chung1e8d71b2014-05-16 17:05:22 -07002866 } else if (!down && mRecentAppsHeldModifiers != 0
2867 && (metaState & mRecentAppsHeldModifiers) == 0) {
2868 mRecentAppsHeldModifiers = 0;
Winson Chungcdcd4872014-08-05 18:00:13 -07002869 hideRecentApps(true, false);
Jeff Brown68b909d2011-12-07 16:36:01 -08002870 }
2871
Jeff Browncf39bdf2012-05-18 14:41:19 -07002872 // Handle keyboard language switching.
2873 if (down && repeatCount == 0
2874 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2875 || (keyCode == KeyEvent.KEYCODE_SPACE
2876 && (metaState & KeyEvent.META_CTRL_MASK) != 0))) {
2877 int direction = (metaState & KeyEvent.META_SHIFT_MASK) != 0 ? -1 : 1;
2878 mWindowManagerFuncs.switchKeyboardLayout(event.getDeviceId(), direction);
2879 return -1;
2880 }
2881 if (mLanguageSwitchKeyPressed && !down
2882 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2883 || keyCode == KeyEvent.KEYCODE_SPACE)) {
2884 mLanguageSwitchKeyPressed = false;
2885 return -1;
2886 }
2887
Jeff Brown13f00f02014-10-31 14:45:50 -07002888 if (isValidGlobalKey(keyCode)
2889 && mGlobalKeyManager.handleGlobalKey(mContext, keyCode, event)) {
Justin Kohd378ad72013-04-01 12:18:26 -07002890 return -1;
2891 }
2892
Michael Wright6a62e552014-06-03 19:19:48 -07002893 // Reserve all the META modifier combos for system behavior
Michael Wrightce0c13a2014-07-30 10:49:21 -07002894 if ((metaState & KeyEvent.META_META_ON) != 0) {
Michael Wright6a62e552014-06-03 19:19:48 -07002895 return -1;
2896 }
2897
Jeff Brown68b909d2011-12-07 16:36:01 -08002898 // Let the application handle the key.
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002899 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002900 }
2901
Jeff Brown3915bb82010-11-05 15:02:16 -07002902 /** {@inheritDoc} */
2903 @Override
Jeff Brown49ed71d2010-12-06 17:13:33 -08002904 public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown54875002011-04-06 15:33:01 -07002905 // Note: This method is only called if the initial down was unhandled.
Jeff Brown40013652012-05-16 21:22:36 -07002906 if (DEBUG_INPUT) {
Jeff Brown1f245102010-11-18 20:53:46 -08002907 Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction()
2908 + ", flags=" + event.getFlags()
2909 + ", keyCode=" + event.getKeyCode()
2910 + ", scanCode=" + event.getScanCode()
2911 + ", metaState=" + event.getMetaState()
2912 + ", repeatCount=" + event.getRepeatCount()
2913 + ", policyFlags=" + policyFlags);
Jeff Brown3915bb82010-11-05 15:02:16 -07002914 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002915
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002916 KeyEvent fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002917 if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
2918 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002919 final int keyCode = event.getKeyCode();
2920 final int metaState = event.getMetaState();
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002921 final boolean initialDown = event.getAction() == KeyEvent.ACTION_DOWN
2922 && event.getRepeatCount() == 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002923
Jeff Brown54875002011-04-06 15:33:01 -07002924 // Check for fallback actions specified by the key character map.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002925 final FallbackAction fallbackAction;
2926 if (initialDown) {
2927 fallbackAction = kcm.getFallbackAction(keyCode, metaState);
2928 } else {
2929 fallbackAction = mFallbackActions.get(keyCode);
2930 }
2931
2932 if (fallbackAction != null) {
Jeff Brown40013652012-05-16 21:22:36 -07002933 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002934 Slog.d(TAG, "Fallback: keyCode=" + fallbackAction.keyCode
2935 + " metaState=" + Integer.toHexString(fallbackAction.metaState));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002936 }
2937
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002938 final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK;
2939 fallbackEvent = KeyEvent.obtain(
Jeff Brown49ed71d2010-12-06 17:13:33 -08002940 event.getDownTime(), event.getEventTime(),
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002941 event.getAction(), fallbackAction.keyCode,
2942 event.getRepeatCount(), fallbackAction.metaState,
Jeff Brown49ed71d2010-12-06 17:13:33 -08002943 event.getDeviceId(), event.getScanCode(),
2944 flags, event.getSource(), null);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002945
2946 if (!interceptFallback(win, fallbackEvent, policyFlags)) {
2947 fallbackEvent.recycle();
2948 fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002949 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002950
2951 if (initialDown) {
2952 mFallbackActions.put(keyCode, fallbackAction);
2953 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2954 mFallbackActions.remove(keyCode);
2955 fallbackAction.recycle();
2956 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002957 }
2958 }
2959
Jeff Brown40013652012-05-16 21:22:36 -07002960 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002961 if (fallbackEvent == null) {
2962 Slog.d(TAG, "No fallback.");
2963 } else {
2964 Slog.d(TAG, "Performing fallback: " + fallbackEvent);
2965 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002966 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002967 return fallbackEvent;
Jeff Brown3915bb82010-11-05 15:02:16 -07002968 }
2969
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002970 private boolean interceptFallback(WindowState win, KeyEvent fallbackEvent, int policyFlags) {
Jeff Brown037c33e2014-04-09 00:31:55 -07002971 int actions = interceptKeyBeforeQueueing(fallbackEvent, policyFlags);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002972 if ((actions & ACTION_PASS_TO_USER) != 0) {
2973 long delayMillis = interceptKeyBeforeDispatching(
2974 win, fallbackEvent, policyFlags);
2975 if (delayMillis == 0) {
2976 return true;
2977 }
2978 }
2979 return false;
Jeff Brown6f2fba42011-02-19 01:08:02 -08002980 }
2981
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002982 private void launchAssistLongPressAction() {
2983 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
2984 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
2985
2986 // launch the search activity
2987 Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS);
2988 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2989 try {
RoboErik8a2cfc32014-05-16 11:19:38 -07002990 // TODO: This only stops the factory-installed search manager.
Jim Miller45308b12012-06-18 19:23:39 -07002991 // Need to formalize an API to handle others
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002992 SearchManager searchManager = getSearchManager();
2993 if (searchManager != null) {
2994 searchManager.stopSearch();
2995 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00002996 startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002997 } catch (ActivityNotFoundException e) {
2998 Slog.w(TAG, "No activity to handle assist long press action.", e);
2999 }
3000 }
3001
3002 private void launchAssistAction() {
Michael Wright8ab940a2014-09-01 11:01:27 -07003003 launchAssistAction(null);
3004 }
3005
3006 private void launchAssistAction(String hint) {
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003007 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
Amith Yamasanic1d07a42012-08-14 09:32:02 -07003008 Intent intent = ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE))
Dianne Hackbornf9c5e0f2013-01-23 14:39:13 -08003009 .getAssistIntent(mContext, true, UserHandle.USER_CURRENT);
Jim Miller45308b12012-06-18 19:23:39 -07003010 if (intent != null) {
Michael Wright8ab940a2014-09-01 11:01:27 -07003011 if (hint != null) {
3012 intent.putExtra(hint, true);
3013 }
Jim Miller45308b12012-06-18 19:23:39 -07003014 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
3015 | Intent.FLAG_ACTIVITY_SINGLE_TOP
3016 | Intent.FLAG_ACTIVITY_CLEAR_TOP);
3017 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00003018 startActivityAsUser(intent, UserHandle.CURRENT);
Jim Miller45308b12012-06-18 19:23:39 -07003019 } catch (ActivityNotFoundException e) {
3020 Slog.w(TAG, "No activity to handle assist action.", e);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003021 }
3022 }
3023 }
3024
Bart Sears8b1c27c2015-03-18 23:51:02 +00003025 private void startActivityAsUser(Intent intent, UserHandle handle) {
3026 if (isUserSetupComplete()) {
3027 mContext.startActivityAsUser(intent, handle);
3028 } else {
3029 Slog.i(TAG, "Not starting activity because user setup is in progress: " + intent);
3030 }
3031 }
3032
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003033 private SearchManager getSearchManager() {
3034 if (mSearchManager == null) {
3035 mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
3036 }
3037 return mSearchManager;
3038 }
3039
Jeff Browncaca8812013-05-09 13:34:33 -07003040 private void preloadRecentApps() {
3041 mPreloadedRecentApps = true;
3042 try {
3043 IStatusBarService statusbar = getStatusBarService();
3044 if (statusbar != null) {
3045 statusbar.preloadRecentApps();
3046 }
3047 } catch (RemoteException e) {
3048 Slog.e(TAG, "RemoteException when preloading recent apps", e);
3049 // re-acquire status bar service next time it is needed.
3050 mStatusBarService = null;
3051 }
3052 }
3053
3054 private void cancelPreloadRecentApps() {
3055 if (mPreloadedRecentApps) {
3056 mPreloadedRecentApps = false;
3057 try {
3058 IStatusBarService statusbar = getStatusBarService();
3059 if (statusbar != null) {
3060 statusbar.cancelPreloadRecentApps();
3061 }
3062 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003063 Slog.e(TAG, "RemoteException when cancelling recent apps preload", e);
Jeff Browncaca8812013-05-09 13:34:33 -07003064 // re-acquire status bar service next time it is needed.
3065 mStatusBarService = null;
3066 }
3067 }
3068 }
3069
3070 private void toggleRecentApps() {
3071 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
Jeff Browncaca8812013-05-09 13:34:33 -07003072 try {
3073 IStatusBarService statusbar = getStatusBarService();
3074 if (statusbar != null) {
3075 statusbar.toggleRecentApps();
3076 }
3077 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003078 Slog.e(TAG, "RemoteException when toggling recent apps", e);
3079 // re-acquire status bar service next time it is needed.
3080 mStatusBarService = null;
3081 }
3082 }
3083
Craig Mautner84984fa2014-06-19 11:19:20 -07003084 @Override
3085 public void showRecentApps() {
3086 mHandler.removeMessages(MSG_DISPATCH_SHOW_RECENTS);
3087 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_RECENTS);
3088 }
3089
Winson Chung1e8d71b2014-05-16 17:05:22 -07003090 private void showRecentApps(boolean triggeredFromAltTab) {
3091 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
3092 try {
3093 IStatusBarService statusbar = getStatusBarService();
3094 if (statusbar != null) {
3095 statusbar.showRecentApps(triggeredFromAltTab);
3096 }
3097 } catch (RemoteException e) {
Jeff Browncaca8812013-05-09 13:34:33 -07003098 Slog.e(TAG, "RemoteException when showing recent apps", e);
3099 // re-acquire status bar service next time it is needed.
3100 mStatusBarService = null;
3101 }
3102 }
3103
Winson Chungcdcd4872014-08-05 18:00:13 -07003104 private void hideRecentApps(boolean triggeredFromAltTab, boolean triggeredFromHome) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003105 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
3106 try {
3107 IStatusBarService statusbar = getStatusBarService();
3108 if (statusbar != null) {
Winson Chungcdcd4872014-08-05 18:00:13 -07003109 statusbar.hideRecentApps(triggeredFromAltTab, triggeredFromHome);
Winson Chung1e8d71b2014-05-16 17:05:22 -07003110 }
3111 } catch (RemoteException e) {
3112 Slog.e(TAG, "RemoteException when closing recent apps", e);
3113 // re-acquire status bar service next time it is needed.
3114 mStatusBarService = null;
3115 }
3116 }
3117
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00003118 void launchHomeFromHotKey() {
Bryce Lee662ed802015-04-10 20:11:39 +00003119 launchHomeFromHotKey(true /* awakenFromDreams */, true /*respectKeyguard*/);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00003120 }
3121
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003122 /**
3123 * A home key -> launch home action was detected. Take the appropriate action
3124 * given the situation with the keyguard.
3125 */
Bryce Lee662ed802015-04-10 20:11:39 +00003126 void launchHomeFromHotKey(final boolean awakenFromDreams, final boolean respectKeyguard) {
3127 if (respectKeyguard) {
3128 if (isKeyguardShowingAndNotOccluded()) {
3129 // don't launch home if keyguard showing
3130 return;
3131 }
3132
3133 if (!mHideLockScreen && mKeyguardDelegate.isInputRestricted()) {
3134 // when in keyguard restricted mode, must first verify unlock
3135 // before launching home
3136 mKeyguardDelegate.verifyUnlock(new OnKeyguardExitResult() {
3137 @Override
3138 public void onKeyguardExitResult(boolean success) {
3139 if (success) {
3140 try {
3141 ActivityManagerNative.getDefault().stopAppSwitches();
3142 } catch (RemoteException e) {
3143 }
3144 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3145 startDockOrHome(true /*fromHomeKey*/, awakenFromDreams);
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07003146 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003147 }
Bryce Lee662ed802015-04-10 20:11:39 +00003148 });
3149 return;
3150 }
3151 }
3152
3153 // no keyguard stuff to worry about, just launch home!
3154 try {
3155 ActivityManagerNative.getDefault().stopAppSwitches();
3156 } catch (RemoteException e) {
3157 }
3158 if (mRecentsVisible) {
3159 // Hide Recents and notify it to launch Home
3160 if (awakenFromDreams) {
3161 awakenDreams();
3162 }
3163 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3164 hideRecentApps(false, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003165 } else {
Bryce Lee662ed802015-04-10 20:11:39 +00003166 // Otherwise, just launch Home
3167 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3168 startDockOrHome(true /*fromHomeKey*/, awakenFromDreams);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003169 }
3170 }
3171
John Spurlock04db1762013-05-13 12:46:41 -04003172 private final Runnable mClearHideNavigationFlag = new Runnable() {
3173 @Override
3174 public void run() {
3175 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
3176 // Clear flags.
3177 mForceClearedSystemUiFlags &=
3178 ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
3179 }
3180 mWindowManagerFuncs.reevaluateStatusBarVisibility();
Dianne Hackborne26ab702011-10-16 13:21:33 -07003181 }
3182 };
3183
3184 /**
3185 * Input handler used while nav bar is hidden. Captures any touch on the screen,
3186 * to determine when the nav bar should be shown and prevent applications from
3187 * receiving those touches.
3188 */
Jeff Brown32cbc38552011-12-01 14:01:49 -08003189 final class HideNavInputEventReceiver extends InputEventReceiver {
3190 public HideNavInputEventReceiver(InputChannel inputChannel, Looper looper) {
3191 super(inputChannel, looper);
3192 }
3193
Dianne Hackborndf89e652011-10-06 22:35:11 -07003194 @Override
Jeff Brown32cbc38552011-12-01 14:01:49 -08003195 public void onInputEvent(InputEvent event) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003196 boolean handled = false;
3197 try {
Jeff Brown4952dfd2011-11-30 19:23:22 -08003198 if (event instanceof MotionEvent
3199 && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
3200 final MotionEvent motionEvent = (MotionEvent)event;
3201 if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003202 // When the user taps down, we re-show the nav bar.
3203 boolean changed = false;
John Spurlock04db1762013-05-13 12:46:41 -04003204 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003205 // Any user activity always causes us to show the
3206 // navigation controls, if they had been hidden.
3207 // We also clear the low profile and only content
3208 // flags so that tapping on the screen will atomically
3209 // restore all currently hidden screen decorations.
3210 int newVal = mResettingSystemUiFlags |
3211 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
3212 View.SYSTEM_UI_FLAG_LOW_PROFILE |
3213 View.SYSTEM_UI_FLAG_FULLSCREEN;
Dianne Hackborne26ab702011-10-16 13:21:33 -07003214 if (mResettingSystemUiFlags != newVal) {
3215 mResettingSystemUiFlags = newVal;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003216 changed = true;
3217 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003218 // We don't allow the system's nav bar to be hidden
3219 // again for 1 second, to prevent applications from
3220 // spamming us and keeping it from being shown.
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003221 newVal = mForceClearedSystemUiFlags |
3222 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
Dianne Hackborne26ab702011-10-16 13:21:33 -07003223 if (mForceClearedSystemUiFlags != newVal) {
3224 mForceClearedSystemUiFlags = newVal;
3225 changed = true;
John Spurlock04db1762013-05-13 12:46:41 -04003226 mHandler.postDelayed(mClearHideNavigationFlag, 1000);
Dianne Hackborne26ab702011-10-16 13:21:33 -07003227 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07003228 }
3229 if (changed) {
3230 mWindowManagerFuncs.reevaluateStatusBarVisibility();
3231 }
3232 }
3233 }
3234 } finally {
Jeff Brown32cbc38552011-12-01 14:01:49 -08003235 finishInputEvent(event, handled);
Dianne Hackborndf89e652011-10-06 22:35:11 -07003236 }
3237 }
Jeff Brown32cbc38552011-12-01 14:01:49 -08003238 }
3239 final InputEventReceiver.Factory mHideNavInputEventReceiverFactory =
3240 new InputEventReceiver.Factory() {
3241 @Override
3242 public InputEventReceiver createInputEventReceiver(
3243 InputChannel inputChannel, Looper looper) {
3244 return new HideNavInputEventReceiver(inputChannel, looper);
3245 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07003246 };
3247
3248 @Override
3249 public int adjustSystemUiVisibilityLw(int visibility) {
John Spurlock5b9145b2013-08-20 15:13:47 -04003250 mStatusBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
3251 mNavigationBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
Winson Chungd42a6cf2014-06-03 16:24:04 -07003252 mRecentsVisible = (visibility & View.RECENT_APPS_VISIBLE) > 0;
John Spurlock27735a42013-08-14 17:57:38 -04003253
Dianne Hackborndf89e652011-10-06 22:35:11 -07003254 // Reset any bits in mForceClearingStatusBarVisibility that
3255 // are now clear.
Dianne Hackborne26ab702011-10-16 13:21:33 -07003256 mResettingSystemUiFlags &= visibility;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003257 // Clear any bits in the new visibility that are currently being
3258 // force cleared, before reporting it.
Dianne Hackborne26ab702011-10-16 13:21:33 -07003259 return visibility & ~mResettingSystemUiFlags
3260 & ~mForceClearedSystemUiFlags;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003261 }
3262
Craig Mautner69b08182012-09-05 13:07:13 -07003263 @Override
Adrian Roos37d7a682014-11-06 18:15:16 +01003264 public void getInsetHintLw(WindowManager.LayoutParams attrs, Rect outContentInsets,
3265 Rect outStableInsets) {
John Spurlockc6d1c602014-01-17 15:22:06 -05003266 final int fl = PolicyControl.getWindowFlags(null, attrs);
John Spurlock1db8b682014-02-18 11:18:59 -05003267 final int sysuiVis = PolicyControl.getSystemUiVisibility(null, attrs);
3268 final int systemUiVisibility = (sysuiVis | attrs.subtreeSystemUiVisibility);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003269
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003270 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003271 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003272 int availRight, availBottom;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003273 if (canHideNavigationBar() &&
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003274 (systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003275 availRight = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3276 availBottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
3277 } else {
3278 availRight = mRestrictedScreenLeft + mRestrictedScreenWidth;
3279 availBottom = mRestrictedScreenTop + mRestrictedScreenHeight;
3280 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003281 if ((systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
3282 if ((fl & FLAG_FULLSCREEN) != 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003283 outContentInsets.set(mStableFullscreenLeft, mStableFullscreenTop,
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003284 availRight - mStableFullscreenRight,
3285 availBottom - mStableFullscreenBottom);
3286 } else {
Adrian Roos37d7a682014-11-06 18:15:16 +01003287 outContentInsets.set(mStableLeft, mStableTop,
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003288 availRight - mStableRight, availBottom - mStableBottom);
3289 }
Dianne Hackbornc652de82013-02-15 16:32:56 -08003290 } else if ((fl & FLAG_FULLSCREEN) != 0 || (fl & FLAG_LAYOUT_IN_OVERSCAN) != 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003291 outContentInsets.setEmpty();
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003292 } else if ((systemUiVisibility & (View.SYSTEM_UI_FLAG_FULLSCREEN
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003293 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)) == 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003294 outContentInsets.set(mCurLeft, mCurTop,
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003295 availRight - mCurRight, availBottom - mCurBottom);
3296 } else {
Adrian Roos37d7a682014-11-06 18:15:16 +01003297 outContentInsets.set(mCurLeft, mCurTop,
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003298 availRight - mCurRight, availBottom - mCurBottom);
3299 }
Adrian Roos37d7a682014-11-06 18:15:16 +01003300
3301 outStableInsets.set(mStableLeft, mStableTop,
3302 availRight - mStableRight, availBottom - mStableBottom);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003303 return;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003304 }
Adrian Roos37d7a682014-11-06 18:15:16 +01003305 outContentInsets.setEmpty();
3306 outStableInsets.setEmpty();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003307 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003308
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003309 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07003310 @Override
3311 public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight,
3312 int displayRotation) {
Dianne Hackbornc652de82013-02-15 16:32:56 -08003313 final int overscanLeft, overscanTop, overscanRight, overscanBottom;
3314 if (isDefaultDisplay) {
3315 switch (displayRotation) {
3316 case Surface.ROTATION_90:
3317 overscanLeft = mOverscanTop;
3318 overscanTop = mOverscanRight;
3319 overscanRight = mOverscanBottom;
3320 overscanBottom = mOverscanLeft;
3321 break;
3322 case Surface.ROTATION_180:
3323 overscanLeft = mOverscanRight;
3324 overscanTop = mOverscanBottom;
3325 overscanRight = mOverscanLeft;
3326 overscanBottom = mOverscanTop;
3327 break;
3328 case Surface.ROTATION_270:
3329 overscanLeft = mOverscanBottom;
3330 overscanTop = mOverscanLeft;
3331 overscanRight = mOverscanTop;
3332 overscanBottom = mOverscanRight;
3333 break;
3334 default:
3335 overscanLeft = mOverscanLeft;
3336 overscanTop = mOverscanTop;
3337 overscanRight = mOverscanRight;
3338 overscanBottom = mOverscanBottom;
3339 break;
3340 }
3341 } else {
3342 overscanLeft = 0;
3343 overscanTop = 0;
3344 overscanRight = 0;
3345 overscanBottom = 0;
3346 }
Dianne Hackborn313440842013-02-19 19:22:59 -08003347 mOverscanScreenLeft = mRestrictedOverscanScreenLeft = 0;
3348 mOverscanScreenTop = mRestrictedOverscanScreenTop = 0;
3349 mOverscanScreenWidth = mRestrictedOverscanScreenWidth = displayWidth;
3350 mOverscanScreenHeight = mRestrictedOverscanScreenHeight = displayHeight;
Dianne Hackbornc652de82013-02-15 16:32:56 -08003351 mSystemLeft = 0;
3352 mSystemTop = 0;
3353 mSystemRight = displayWidth;
3354 mSystemBottom = displayHeight;
3355 mUnrestrictedScreenLeft = overscanLeft;
3356 mUnrestrictedScreenTop = overscanTop;
3357 mUnrestrictedScreenWidth = displayWidth - overscanLeft - overscanRight;
3358 mUnrestrictedScreenHeight = displayHeight - overscanTop - overscanBottom;
3359 mRestrictedScreenLeft = mUnrestrictedScreenLeft;
3360 mRestrictedScreenTop = mUnrestrictedScreenTop;
John Spurlockad3e6cb2013-04-30 08:47:43 -04003361 mRestrictedScreenWidth = mSystemGestures.screenWidth = mUnrestrictedScreenWidth;
3362 mRestrictedScreenHeight = mSystemGestures.screenHeight = mUnrestrictedScreenHeight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003363 mDockLeft = mContentLeft = mVoiceContentLeft = mStableLeft = mStableFullscreenLeft
Dianne Hackbornc652de82013-02-15 16:32:56 -08003364 = mCurLeft = mUnrestrictedScreenLeft;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003365 mDockTop = mContentTop = mVoiceContentTop = mStableTop = mStableFullscreenTop
Dianne Hackbornc652de82013-02-15 16:32:56 -08003366 = mCurTop = mUnrestrictedScreenTop;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003367 mDockRight = mContentRight = mVoiceContentRight = mStableRight = mStableFullscreenRight
Dianne Hackbornc652de82013-02-15 16:32:56 -08003368 = mCurRight = displayWidth - overscanRight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003369 mDockBottom = mContentBottom = mVoiceContentBottom = mStableBottom = mStableFullscreenBottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003370 = mCurBottom = displayHeight - overscanBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003371 mDockLayer = 0x10000000;
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003372 mStatusBarLayer = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003373
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003374 // start with the current dock rect, which will be (0,0,displayWidth,displayHeight)
3375 final Rect pf = mTmpParentFrame;
3376 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003377 final Rect of = mTmpOverscanFrame;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003378 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04003379 final Rect dcf = mTmpDecorFrame;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003380 final Rect osf = mTmpOutsetFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003381 pf.left = df.left = of.left = vf.left = mDockLeft;
3382 pf.top = df.top = of.top = vf.top = mDockTop;
3383 pf.right = df.right = of.right = vf.right = mDockRight;
3384 pf.bottom = df.bottom = of.bottom = vf.bottom = mDockBottom;
John Spurlock46646232013-09-30 22:32:42 -04003385 dcf.setEmpty(); // Decor frame N/A for system bars.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003386
Craig Mautner69b08182012-09-05 13:07:13 -07003387 if (isDefaultDisplay) {
3388 // For purposes of putting out fake window up to steal focus, we will
3389 // drive nav being hidden only by whether it is requested.
John Spurlocke1f366f2013-08-05 12:22:40 -04003390 final int sysui = mLastSystemUiFlags;
3391 boolean navVisible = (sysui & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0;
Adrian Roosea562512014-05-05 13:33:03 +02003392 boolean navTranslucent = (sysui
3393 & (View.NAVIGATION_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04003394 boolean immersive = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
3395 boolean immersiveSticky = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
3396 boolean navAllowedHidden = immersive || immersiveSticky;
3397 navTranslucent &= !immersiveSticky; // transient trumps translucent
Adrian Roos4fb3ee32014-08-22 19:29:09 +02003398 boolean isKeyguardShowing = isStatusBarKeyguard() && !mHideLockScreen;
3399 if (!isKeyguardShowing) {
3400 navTranslucent &= areTranslucentBarsAllowed();
3401 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003402
Craig Mautner69b08182012-09-05 13:07:13 -07003403 // When the navigation bar isn't visible, we put up a fake
3404 // input window to catch all touch events. This way we can
3405 // detect when the user presses anywhere to bring back the nav
3406 // bar and ensure the application doesn't see the event.
John Spurlockf1a36642013-10-12 17:50:42 -04003407 if (navVisible || navAllowedHidden) {
Selim Cinekf83e8242015-05-19 18:08:14 -07003408 if (mInputConsumer != null) {
3409 mInputConsumer.dismiss();
3410 mInputConsumer = null;
Craig Mautner69b08182012-09-05 13:07:13 -07003411 }
Selim Cinekf83e8242015-05-19 18:08:14 -07003412 } else if (mInputConsumer == null) {
3413 mInputConsumer = mWindowManagerFuncs.addInputConsumer(mHandler.getLooper(),
3414 mHideNavInputEventReceiverFactory);
Dianne Hackborne26ab702011-10-16 13:21:33 -07003415 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003416
Craig Mautner69b08182012-09-05 13:07:13 -07003417 // For purposes of positioning and showing the nav bar, if we have
3418 // decided that it can't be hidden (because of the screen aspect ratio),
3419 // then take that into account.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003420 navVisible |= !canHideNavigationBar();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003421
John Spurlockad3e6cb2013-04-30 08:47:43 -04003422 boolean updateSysUiVisibility = false;
Craig Mautner69b08182012-09-05 13:07:13 -07003423 if (mNavigationBar != null) {
John Spurlock27735a42013-08-14 17:57:38 -04003424 boolean transientNavBarShowing = mNavigationBarController.isTransientShowing();
Craig Mautner69b08182012-09-05 13:07:13 -07003425 // Force the navigation bar to its appropriate place and
3426 // size. We need to do this directly, instead of relying on
3427 // it to bubble up from the nav bar, because this needs to
3428 // change atomically with screen rotations.
3429 mNavigationBarOnBottom = (!mNavigationBarCanMove || displayWidth < displayHeight);
3430 if (mNavigationBarOnBottom) {
3431 // It's a system nav bar or a portrait screen; nav bar goes on bottom.
Dianne Hackbornc652de82013-02-15 16:32:56 -08003432 int top = displayHeight - overscanBottom
3433 - mNavigationBarHeightForRotation[displayRotation];
3434 mTmpNavigationFrame.set(0, top, displayWidth, displayHeight - overscanBottom);
Craig Mautner69b08182012-09-05 13:07:13 -07003435 mStableBottom = mStableFullscreenBottom = mTmpNavigationFrame.top;
John Spurlockf95b89a2013-10-10 22:10:42 -04003436 if (transientNavBarShowing) {
John Spurlock27735a42013-08-14 17:57:38 -04003437 mNavigationBarController.setBarShowingLw(true);
John Spurlockad3e6cb2013-04-30 08:47:43 -04003438 } else if (navVisible) {
John Spurlock27735a42013-08-14 17:57:38 -04003439 mNavigationBarController.setBarShowingLw(true);
Craig Mautner69b08182012-09-05 13:07:13 -07003440 mDockBottom = mTmpNavigationFrame.top;
Dianne Hackborn313440842013-02-19 19:22:59 -08003441 mRestrictedScreenHeight = mDockBottom - mRestrictedScreenTop;
3442 mRestrictedOverscanScreenHeight = mDockBottom - mRestrictedOverscanScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07003443 } else {
3444 // We currently want to hide the navigation UI.
John Spurlock27735a42013-08-14 17:57:38 -04003445 mNavigationBarController.setBarShowingLw(false);
Craig Mautner69b08182012-09-05 13:07:13 -07003446 }
John Spurlockc6d1c602014-01-17 15:22:06 -05003447 if (navVisible && !navTranslucent && !navAllowedHidden
3448 && !mNavigationBar.isAnimatingLw()
John Spurlockbd957402013-10-03 11:38:39 -04003449 && !mNavigationBarController.wasRecentlyTranslucent()) {
John Spurlocke1f366f2013-08-05 12:22:40 -04003450 // If the opaque nav bar is currently requested to be visible,
Craig Mautner69b08182012-09-05 13:07:13 -07003451 // and not in the process of animating on or off, then
3452 // we can tell the app that it is covered by it.
3453 mSystemBottom = mTmpNavigationFrame.top;
3454 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003455 } else {
Craig Mautner69b08182012-09-05 13:07:13 -07003456 // Landscape screen; nav bar goes to the right.
Dianne Hackbornc652de82013-02-15 16:32:56 -08003457 int left = displayWidth - overscanRight
3458 - mNavigationBarWidthForRotation[displayRotation];
3459 mTmpNavigationFrame.set(left, 0, displayWidth - overscanRight, displayHeight);
Craig Mautner69b08182012-09-05 13:07:13 -07003460 mStableRight = mStableFullscreenRight = mTmpNavigationFrame.left;
John Spurlockf95b89a2013-10-10 22:10:42 -04003461 if (transientNavBarShowing) {
John Spurlock27735a42013-08-14 17:57:38 -04003462 mNavigationBarController.setBarShowingLw(true);
John Spurlockad3e6cb2013-04-30 08:47:43 -04003463 } else if (navVisible) {
John Spurlock27735a42013-08-14 17:57:38 -04003464 mNavigationBarController.setBarShowingLw(true);
Craig Mautner69b08182012-09-05 13:07:13 -07003465 mDockRight = mTmpNavigationFrame.left;
Dianne Hackborn313440842013-02-19 19:22:59 -08003466 mRestrictedScreenWidth = mDockRight - mRestrictedScreenLeft;
3467 mRestrictedOverscanScreenWidth = mDockRight - mRestrictedOverscanScreenLeft;
Craig Mautner69b08182012-09-05 13:07:13 -07003468 } else {
3469 // We currently want to hide the navigation UI.
John Spurlock27735a42013-08-14 17:57:38 -04003470 mNavigationBarController.setBarShowingLw(false);
Craig Mautner69b08182012-09-05 13:07:13 -07003471 }
John Spurlockbd957402013-10-03 11:38:39 -04003472 if (navVisible && !navTranslucent && !mNavigationBar.isAnimatingLw()
3473 && !mNavigationBarController.wasRecentlyTranslucent()) {
Craig Mautner69b08182012-09-05 13:07:13 -07003474 // If the nav bar is currently requested to be visible,
3475 // and not in the process of animating on or off, then
3476 // we can tell the app that it is covered by it.
3477 mSystemRight = mTmpNavigationFrame.left;
3478 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003479 }
Craig Mautner69b08182012-09-05 13:07:13 -07003480 // Make sure the content and current rectangles are updated to
3481 // account for the restrictions from the navigation bar.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003482 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3483 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3484 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3485 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
Craig Mautner69b08182012-09-05 13:07:13 -07003486 mStatusBarLayer = mNavigationBar.getSurfaceLayer();
3487 // And compute the final frame.
3488 mNavigationBar.computeFrameLw(mTmpNavigationFrame, mTmpNavigationFrame,
Adrian Roosfa104232014-06-20 16:10:14 -07003489 mTmpNavigationFrame, mTmpNavigationFrame, mTmpNavigationFrame, dcf,
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003490 mTmpNavigationFrame, mTmpNavigationFrame);
Craig Mautnereda67292013-04-28 13:50:14 -07003491 if (DEBUG_LAYOUT) Slog.i(TAG, "mNavigationBar frame: " + mTmpNavigationFrame);
John Spurlock27735a42013-08-14 17:57:38 -04003492 if (mNavigationBarController.checkHiddenLw()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04003493 updateSysUiVisibility = true;
3494 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003495 }
Craig Mautnereda67292013-04-28 13:50:14 -07003496 if (DEBUG_LAYOUT) Slog.i(TAG, String.format("mDock rect: (%d,%d - %d,%d)",
Craig Mautner69b08182012-09-05 13:07:13 -07003497 mDockLeft, mDockTop, mDockRight, mDockBottom));
3498
3499 // decide where the status bar goes ahead of time
3500 if (mStatusBar != null) {
3501 // apply any navigation bar insets
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003502 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3503 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3504 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
3505 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight
3506 + mUnrestrictedScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07003507 vf.left = mStableLeft;
3508 vf.top = mStableTop;
3509 vf.right = mStableRight;
3510 vf.bottom = mStableBottom;
3511
3512 mStatusBarLayer = mStatusBar.getSurfaceLayer();
3513
3514 // Let the status bar determine its size.
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003515 mStatusBar.computeFrameLw(pf /* parentFrame */, df /* displayFrame */,
3516 vf /* overlayFrame */, vf /* contentFrame */, vf /* visibleFrame */,
3517 dcf /* decorFrame */, vf /* stableFrame */, vf /* outsetFrame */);
Craig Mautner69b08182012-09-05 13:07:13 -07003518
3519 // For layout, the status bar is always at the top with our fixed height.
3520 mStableTop = mUnrestrictedScreenTop + mStatusBarHeight;
3521
John Spurlocke1f366f2013-08-05 12:22:40 -04003522 boolean statusBarTransient = (sysui & View.STATUS_BAR_TRANSIENT) != 0;
Adrian Roosea562512014-05-05 13:33:03 +02003523 boolean statusBarTranslucent = (sysui
3524 & (View.STATUS_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0;
Adrian Roos4fb3ee32014-08-22 19:29:09 +02003525 if (!isKeyguardShowing) {
3526 statusBarTranslucent &= areTranslucentBarsAllowed();
3527 }
John Spurlock32beb2c2013-03-11 10:16:47 -04003528
Craig Mautner69b08182012-09-05 13:07:13 -07003529 // If the status bar is hidden, we don't want to cause
3530 // windows behind it to scroll.
John Spurlockeda1f692013-09-16 11:38:44 -04003531 if (mStatusBar.isVisibleLw() && !statusBarTransient) {
Craig Mautner69b08182012-09-05 13:07:13 -07003532 // Status bar may go away, so the screen area it occupies
3533 // is available to apps but just covering them when the
3534 // status bar is visible.
3535 mDockTop = mUnrestrictedScreenTop + mStatusBarHeight;
3536
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003537 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3538 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3539 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3540 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
Craig Mautner69b08182012-09-05 13:07:13 -07003541
Craig Mautnereda67292013-04-28 13:50:14 -07003542 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar: " +
Craig Mautner69b08182012-09-05 13:07:13 -07003543 String.format(
3544 "dock=[%d,%d][%d,%d] content=[%d,%d][%d,%d] cur=[%d,%d][%d,%d]",
3545 mDockLeft, mDockTop, mDockRight, mDockBottom,
3546 mContentLeft, mContentTop, mContentRight, mContentBottom,
3547 mCurLeft, mCurTop, mCurRight, mCurBottom));
3548 }
John Spurlocke1f366f2013-08-05 12:22:40 -04003549 if (mStatusBar.isVisibleLw() && !mStatusBar.isAnimatingLw()
John Spurlockbd957402013-10-03 11:38:39 -04003550 && !statusBarTransient && !statusBarTranslucent
3551 && !mStatusBarController.wasRecentlyTranslucent()) {
John Spurlocke1f366f2013-08-05 12:22:40 -04003552 // If the opaque status bar is currently requested to be visible,
Craig Mautner69b08182012-09-05 13:07:13 -07003553 // and not in the process of animating on or off, then
3554 // we can tell the app that it is covered by it.
3555 mSystemTop = mUnrestrictedScreenTop + mStatusBarHeight;
3556 }
John Spurlock27735a42013-08-14 17:57:38 -04003557 if (mStatusBarController.checkHiddenLw()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04003558 updateSysUiVisibility = true;
John Spurlock32beb2c2013-03-11 10:16:47 -04003559 }
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003560 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04003561 if (updateSysUiVisibility) {
3562 updateSystemUiVisibilityLw();
3563 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003564 }
3565 }
3566
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003567 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07003568 @Override
John Spurlock46646232013-09-30 22:32:42 -04003569 public int getSystemDecorLayerLw() {
Bryce Lee2ed3e5f2015-04-01 22:09:19 +00003570 if (mStatusBar != null && mStatusBar.isVisibleLw()) {
3571 return mStatusBar.getSurfaceLayer();
3572 }
3573
3574 if (mNavigationBar != null && mNavigationBar.isVisibleLw()) {
3575 return mNavigationBar.getSurfaceLayer();
3576 }
3577
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003578 return 0;
3579 }
3580
Craig Mautner967212c2013-04-13 21:10:58 -07003581 @Override
3582 public void getContentRectLw(Rect r) {
3583 r.set(mContentLeft, mContentTop, mContentRight, mContentBottom);
3584 }
3585
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003586 void setAttachedWindowFrames(WindowState win, int fl, int adjust, WindowState attached,
3587 boolean insetDecors, Rect pf, Rect df, Rect of, Rect cf, Rect vf) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003588 if (win.getSurfaceLayer() > mDockLayer && attached.getSurfaceLayer() < mDockLayer) {
3589 // Here's a special case: if this attached window is a panel that is
3590 // above the dock window, and the window it is attached to is below
3591 // the dock window, then the frames we computed for the window it is
3592 // attached to can not be used because the dock is effectively part
3593 // of the underlying window and the attached window is floating on top
3594 // of the whole thing. So, we ignore the attached window and explicitly
3595 // compute the frames that would be appropriate without the dock.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003596 df.left = of.left = cf.left = vf.left = mDockLeft;
3597 df.top = of.top = cf.top = vf.top = mDockTop;
3598 df.right = of.right = cf.right = vf.right = mDockRight;
3599 df.bottom = of.bottom = cf.bottom = vf.bottom = mDockBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003600 } else {
3601 // The effective display frame of the attached window depends on
3602 // whether it is taking care of insetting its content. If not,
3603 // we need to use the parent's content frame so that the entire
3604 // window is positioned within that content. Otherwise we can use
Wale Ogunwale393b1c12014-10-18 16:22:01 -07003605 // the overscan frame and let the attached window take care of
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003606 // positioning its content appropriately.
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003607 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Wale Ogunwale393b1c12014-10-18 16:22:01 -07003608 // Set the content frame of the attached window to the parent's decor frame
3609 // (same as content frame when IME isn't present) if specifically requested by
3610 // setting {@link WindowManager.LayoutParams#FLAG_LAYOUT_ATTACHED_IN_DECOR} flag.
3611 // Otherwise, use the overscan frame.
3612 cf.set((fl & FLAG_LAYOUT_ATTACHED_IN_DECOR) != 0
3613 ? attached.getContentFrameLw() : attached.getOverscanFrameLw());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003614 } else {
3615 // If the window is resizing, then we want to base the content
3616 // frame on our attached content frame to resize... however,
3617 // things can be tricky if the attached window is NOT in resize
3618 // mode, in which case its content frame will be larger.
3619 // Ungh. So to deal with that, make sure the content frame
3620 // we end up using is not covering the IM dock.
3621 cf.set(attached.getContentFrameLw());
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003622 if (attached.isVoiceInteraction()) {
3623 if (cf.left < mVoiceContentLeft) cf.left = mVoiceContentLeft;
3624 if (cf.top < mVoiceContentTop) cf.top = mVoiceContentTop;
3625 if (cf.right > mVoiceContentRight) cf.right = mVoiceContentRight;
3626 if (cf.bottom > mVoiceContentBottom) cf.bottom = mVoiceContentBottom;
3627 } else if (attached.getSurfaceLayer() < mDockLayer) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003628 if (cf.left < mContentLeft) cf.left = mContentLeft;
3629 if (cf.top < mContentTop) cf.top = mContentTop;
3630 if (cf.right > mContentRight) cf.right = mContentRight;
3631 if (cf.bottom > mContentBottom) cf.bottom = mContentBottom;
3632 }
3633 }
3634 df.set(insetDecors ? attached.getDisplayFrameLw() : cf);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003635 of.set(insetDecors ? attached.getOverscanFrameLw() : cf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003636 vf.set(attached.getVisibleFrameLw());
3637 }
3638 // The LAYOUT_IN_SCREEN flag is used to determine whether the attached
3639 // window should be positioned relative to its parent or the entire
3640 // screen.
3641 pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0
3642 ? attached.getFrameLw() : df);
3643 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003644
3645 private void applyStableConstraints(int sysui, int fl, Rect r) {
3646 if ((sysui & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
3647 // If app is requesting a stable layout, don't let the
3648 // content insets go below the stable values.
3649 if ((fl & FLAG_FULLSCREEN) != 0) {
3650 if (r.left < mStableFullscreenLeft) r.left = mStableFullscreenLeft;
3651 if (r.top < mStableFullscreenTop) r.top = mStableFullscreenTop;
3652 if (r.right > mStableFullscreenRight) r.right = mStableFullscreenRight;
3653 if (r.bottom > mStableFullscreenBottom) r.bottom = mStableFullscreenBottom;
3654 } else {
3655 if (r.left < mStableLeft) r.left = mStableLeft;
3656 if (r.top < mStableTop) r.top = mStableTop;
3657 if (r.right > mStableRight) r.right = mStableRight;
3658 if (r.bottom > mStableBottom) r.bottom = mStableBottom;
3659 }
3660 }
3661 }
3662
Jorim Jaggiaa806142015-05-20 18:04:16 -07003663 private boolean canReceiveInput(WindowState win) {
3664 boolean notFocusable =
3665 (win.getAttrs().flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0;
3666 boolean altFocusableIm =
3667 (win.getAttrs().flags & WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM) != 0;
3668 boolean notFocusableForIm = notFocusable ^ altFocusableIm;
3669 return !notFocusableForIm;
3670 }
3671
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003672 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07003673 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003674 public void layoutWindowLw(WindowState win, WindowState attached) {
Jorim Jaggiaa806142015-05-20 18:04:16 -07003675 // We've already done the navigation bar and status bar. If the status bar can receive
3676 // input, we need to layout it again to accomodate for the IME window.
3677 if ((win == mStatusBar && !canReceiveInput(win)) || win == mNavigationBar) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003678 return;
3679 }
Jorim Jaggiaa806142015-05-20 18:04:16 -07003680 final WindowManager.LayoutParams attrs = win.getAttrs();
Craig Mautner69b08182012-09-05 13:07:13 -07003681 final boolean isDefaultDisplay = win.isDefaultDisplay();
3682 final boolean needsToOffsetInputMethodTarget = isDefaultDisplay &&
satok1bc0a492012-04-25 22:47:12 +09003683 (win == mLastInputMethodTargetWindow && mLastInputMethodWindow != null);
3684 if (needsToOffsetInputMethodTarget) {
Craig Mautnereda67292013-04-28 13:50:14 -07003685 if (DEBUG_LAYOUT) Slog.i(TAG, "Offset ime target window by the last ime window state");
satok1bc0a492012-04-25 22:47:12 +09003686 offsetInputMethodWindowLw(mLastInputMethodWindow);
3687 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003688
John Spurlockc6d1c602014-01-17 15:22:06 -05003689 final int fl = PolicyControl.getWindowFlags(win, attrs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003690 final int sim = attrs.softInputMode;
John Spurlock1db8b682014-02-18 11:18:59 -05003691 final int sysUiFl = PolicyControl.getSystemUiVisibility(win, null);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003692
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003693 final Rect pf = mTmpParentFrame;
3694 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003695 final Rect of = mTmpOverscanFrame;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003696 final Rect cf = mTmpContentFrame;
3697 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04003698 final Rect dcf = mTmpDecorFrame;
Adrian Roosfa104232014-06-20 16:10:14 -07003699 final Rect sf = mTmpStableFrame;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003700 Rect osf = null;
John Spurlock46646232013-09-30 22:32:42 -04003701 dcf.setEmpty();
Craig Mautner69b08182012-09-05 13:07:13 -07003702
3703 final boolean hasNavBar = (isDefaultDisplay && mHasNavigationBar
Daniel Sandler36412a72011-08-04 09:35:13 -04003704 && mNavigationBar != null && mNavigationBar.isVisibleLw());
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003705
Craig Mautnerf683b562012-10-02 11:10:57 -07003706 final int adjust = sim & SOFT_INPUT_MASK_ADJUST;
3707
Adrian Roosfa104232014-06-20 16:10:14 -07003708 if (isDefaultDisplay) {
3709 sf.set(mStableLeft, mStableTop, mStableRight, mStableBottom);
3710 } else {
3711 sf.set(mOverscanLeft, mOverscanTop, mOverscanRight, mOverscanBottom);
3712 }
3713
Craig Mautner69b08182012-09-05 13:07:13 -07003714 if (!isDefaultDisplay) {
3715 if (attached != null) {
3716 // If this window is attached to another, our display
3717 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003718 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07003719 } else {
3720 // Give the window full screen.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003721 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3722 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3723 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08003724 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003725 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003726 = mOverscanScreenTop + mOverscanScreenHeight;
Craig Mautner69b08182012-09-05 13:07:13 -07003727 }
Jorim Jaggi225d3b52015-04-01 11:18:57 -07003728 } else if (attrs.type == TYPE_INPUT_METHOD) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003729 pf.left = df.left = of.left = cf.left = vf.left = mDockLeft;
3730 pf.top = df.top = of.top = cf.top = vf.top = mDockTop;
3731 pf.right = df.right = of.right = cf.right = vf.right = mDockRight;
John Spurlockc68d5772013-10-08 11:47:58 -04003732 // IM dock windows layout below the nav bar...
John Spurlock57beb3b2013-10-10 10:27:44 -04003733 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlockc68d5772013-10-08 11:47:58 -04003734 // ...with content insets above the nav bar
3735 cf.bottom = vf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003736 // IM dock windows always go to the bottom of the screen.
3737 attrs.gravity = Gravity.BOTTOM;
3738 mDockLayer = win.getSurfaceLayer();
Jorim Jaggi225d3b52015-04-01 11:18:57 -07003739 } else if (attrs.type == TYPE_VOICE_INTERACTION) {
3740 pf.left = df.left = of.left = cf.left = vf.left = mUnrestrictedScreenLeft;
3741 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3742 pf.right = df.right = of.right = cf.right = vf.right = mUnrestrictedScreenLeft
3743 + mUnrestrictedScreenWidth;
3744 pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop
3745 + mUnrestrictedScreenHeight;
3746 cf.bottom = vf.bottom = mStableBottom;
3747 cf.top = vf.top = mStableTop;
Jorim Jaggiaa806142015-05-20 18:04:16 -07003748 } else if (win == mStatusBar) {
Jorim Jaggie0700182014-08-21 01:12:37 +02003749 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3750 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3751 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
3752 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight + mUnrestrictedScreenTop;
3753 cf.left = vf.left = mStableLeft;
3754 cf.top = vf.top = mStableTop;
3755 cf.right = vf.right = mStableRight;
3756 vf.bottom = mStableBottom;
3757 cf.bottom = mContentBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003758 } else {
John Spurlock46646232013-09-30 22:32:42 -04003759
3760 // Default policy decor for the default display
3761 dcf.left = mSystemLeft;
3762 dcf.top = mSystemTop;
3763 dcf.right = mSystemRight;
3764 dcf.bottom = mSystemBottom;
John Spurlockbd957402013-10-03 11:38:39 -04003765 final boolean inheritTranslucentDecor = (attrs.privateFlags
3766 & WindowManager.LayoutParams.PRIVATE_FLAG_INHERIT_TRANSLUCENT_DECOR) != 0;
John Spurlock65567d42013-10-08 10:08:32 -04003767 final boolean isAppWindow =
3768 attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW &&
3769 attrs.type <= WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
3770 final boolean topAtRest =
3771 win == mTopFullscreenOpaqueWindowState && !win.isAnimatingLw();
3772 if (isAppWindow && !inheritTranslucentDecor && !topAtRest) {
John Spurlockbd957402013-10-03 11:38:39 -04003773 if ((sysUiFl & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0
3774 && (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0
Adrian Roosea562512014-05-05 13:33:03 +02003775 && (fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) == 0
3776 && (fl & WindowManager.LayoutParams.
3777 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04003778 // Ensure policy decor includes status bar
3779 dcf.top = mStableTop;
3780 }
John Spurlockbd957402013-10-03 11:38:39 -04003781 if ((fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) == 0
Adrian Roosea562512014-05-05 13:33:03 +02003782 && (sysUiFl & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0
3783 && (fl & WindowManager.LayoutParams.
3784 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04003785 // Ensure policy decor includes navigation bar
3786 dcf.bottom = mStableBottom;
3787 dcf.right = mStableRight;
3788 }
3789 }
3790
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003791 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
3792 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
RoboErik8a2cfc32014-05-16 11:19:38 -07003793 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003794 + "): IN_SCREEN, INSET_DECOR");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003795 // This is the case for a normal activity window: we want it
3796 // to cover all of the screen space, and it can take care of
3797 // moving its contents to account for screen decorations that
3798 // intrude into that space.
3799 if (attached != null) {
3800 // If this window is attached to another, our display
3801 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003802 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003803 } else {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003804 if (attrs.type == TYPE_STATUS_BAR_PANEL
3805 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Joe Onorato29fc2c92010-11-24 10:26:50 -08003806 // Status bar panels are the only windows who can go on top of
3807 // the status bar. They are protected by the STATUS_BAR_SERVICE
3808 // permission, so they have the same privileges as the status
3809 // bar itself.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003810 //
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003811 // However, they should still dodge the navigation bar if it exists.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003812
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003813 pf.left = df.left = of.left = hasNavBar
3814 ? mDockLeft : mUnrestrictedScreenLeft;
3815 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3816 pf.right = df.right = of.right = hasNavBar
3817 ? mRestrictedScreenLeft+mRestrictedScreenWidth
3818 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3819 pf.bottom = df.bottom = of.bottom = hasNavBar
3820 ? mRestrictedScreenTop+mRestrictedScreenHeight
3821 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003822
Craig Mautnereda67292013-04-28 13:50:14 -07003823 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003824 "Laying out status bar window: (%d,%d - %d,%d)",
3825 pf.left, pf.top, pf.right, pf.bottom));
John Spurlock46646232013-09-30 22:32:42 -04003826 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08003827 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3828 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3829 // Asking to layout into the overscan region, so give it that pure
3830 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003831 pf.left = df.left = of.left = mOverscanScreenLeft;
3832 pf.top = df.top = of.top = mOverscanScreenTop;
3833 pf.right = df.right = of.right = mOverscanScreenLeft + mOverscanScreenWidth;
3834 pf.bottom = df.bottom = of.bottom = mOverscanScreenTop
3835 + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003836 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003837 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003838 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3839 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003840 // Asking for layout as if the nav bar is hidden, lets the
Dianne Hackbornc652de82013-02-15 16:32:56 -08003841 // application extend into the unrestricted overscan screen area. We
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003842 // only do this for application windows to ensure no window that
3843 // can be above the nav bar can do this.
Dianne Hackborn313440842013-02-19 19:22:59 -08003844 pf.left = df.left = mOverscanScreenLeft;
3845 pf.top = df.top = mOverscanScreenTop;
3846 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
3847 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003848 // We need to tell the app about where the frame inside the overscan
3849 // is, so it can inset its content by that amount -- it didn't ask
3850 // to actually extend itself into the overscan region.
3851 of.left = mUnrestrictedScreenLeft;
3852 of.top = mUnrestrictedScreenTop;
3853 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3854 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003855 } else {
Dianne Hackborn313440842013-02-19 19:22:59 -08003856 pf.left = df.left = mRestrictedOverscanScreenLeft;
3857 pf.top = df.top = mRestrictedOverscanScreenTop;
3858 pf.right = df.right = mRestrictedOverscanScreenLeft
3859 + mRestrictedOverscanScreenWidth;
3860 pf.bottom = df.bottom = mRestrictedOverscanScreenTop
3861 + mRestrictedOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003862 // We need to tell the app about where the frame inside the overscan
3863 // is, so it can inset its content by that amount -- it didn't ask
3864 // to actually extend itself into the overscan region.
3865 of.left = mUnrestrictedScreenLeft;
3866 of.top = mUnrestrictedScreenTop;
3867 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3868 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003869 }
Craig Mautner69b08182012-09-05 13:07:13 -07003870
John Spurlock46646232013-09-30 22:32:42 -04003871 if ((fl & FLAG_FULLSCREEN) == 0) {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003872 if (win.isVoiceInteraction()) {
3873 cf.left = mVoiceContentLeft;
3874 cf.top = mVoiceContentTop;
3875 cf.right = mVoiceContentRight;
3876 cf.bottom = mVoiceContentBottom;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003877 } else {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003878 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
3879 cf.left = mDockLeft;
3880 cf.top = mDockTop;
3881 cf.right = mDockRight;
3882 cf.bottom = mDockBottom;
3883 } else {
3884 cf.left = mContentLeft;
3885 cf.top = mContentTop;
3886 cf.right = mContentRight;
3887 cf.bottom = mContentBottom;
3888 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003889 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003890 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003891 // Full screen windows are always given a layout that is as if the
3892 // status bar and other transient decors are gone. This is to avoid
3893 // bad states when moving from a window that is not hding the
3894 // status bar to one that is.
3895 cf.left = mRestrictedScreenLeft;
3896 cf.top = mRestrictedScreenTop;
3897 cf.right = mRestrictedScreenLeft + mRestrictedScreenWidth;
3898 cf.bottom = mRestrictedScreenTop + mRestrictedScreenHeight;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003899 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003900 applyStableConstraints(sysUiFl, fl, cf);
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003901 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3902 vf.left = mCurLeft;
3903 vf.top = mCurTop;
3904 vf.right = mCurRight;
3905 vf.bottom = mCurBottom;
3906 } else {
3907 vf.set(cf);
3908 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003909 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003910 } else if ((fl & FLAG_LAYOUT_IN_SCREEN) != 0 || (sysUiFl
3911 & (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
3912 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)) != 0) {
Craig Mautnereda67292013-04-28 13:50:14 -07003913 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3914 "): IN_SCREEN");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003915 // A window that has requested to fill the entire screen just
3916 // gets everything, period.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003917 if (attrs.type == TYPE_STATUS_BAR_PANEL
3918 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003919 pf.left = df.left = of.left = cf.left = hasNavBar
3920 ? mDockLeft : mUnrestrictedScreenLeft;
3921 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
3922 pf.right = df.right = of.right = cf.right = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003923 ? mRestrictedScreenLeft+mRestrictedScreenWidth
Dianne Hackbornc652de82013-02-15 16:32:56 -08003924 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003925 pf.bottom = df.bottom = of.bottom = cf.bottom = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003926 ? mRestrictedScreenTop+mRestrictedScreenHeight
Dianne Hackbornc652de82013-02-15 16:32:56 -08003927 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07003928 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler36412a72011-08-04 09:35:13 -04003929 "Laying out IN_SCREEN status bar window: (%d,%d - %d,%d)",
3930 pf.left, pf.top, pf.right, pf.bottom));
Jim Millere898ac52012-04-06 17:10:57 -07003931 } else if (attrs.type == TYPE_NAVIGATION_BAR
3932 || attrs.type == TYPE_NAVIGATION_BAR_PANEL) {
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003933 // The navigation bar has Real Ultimate Power.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003934 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3935 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3936 pf.right = df.right = of.right = mUnrestrictedScreenLeft
3937 + mUnrestrictedScreenWidth;
3938 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop
3939 + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07003940 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003941 "Laying out navigation bar window: (%d,%d - %d,%d)",
3942 pf.left, pf.top, pf.right, pf.bottom));
Dianne Hackborn01011c32012-02-21 13:54:21 -08003943 } else if ((attrs.type == TYPE_SECURE_SYSTEM_OVERLAY
3944 || attrs.type == TYPE_BOOT_PROGRESS)
Jeff Brownbfcb60a2011-09-08 18:51:14 -07003945 && ((fl & FLAG_FULLSCREEN) != 0)) {
3946 // Fullscreen secure system overlays get what they ask for.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003947 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3948 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3949 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
3950 + mOverscanScreenWidth;
3951 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
3952 + mOverscanScreenHeight;
Craig Mautner165be0c2015-01-27 15:16:58 -08003953 } else if (attrs.type == TYPE_BOOT_PROGRESS) {
Dianne Hackborn01011c32012-02-21 13:54:21 -08003954 // Boot progress screen always covers entire display.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003955 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3956 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3957 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
3958 + mOverscanScreenWidth;
3959 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
3960 + mOverscanScreenHeight;
John Spurlockef4adae2013-08-26 17:58:58 -04003961 } else if (attrs.type == TYPE_WALLPAPER) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07003962 // The wallpaper also has Real Ultimate Power, but we want to tell
3963 // it about the overscan area.
3964 pf.left = df.left = mOverscanScreenLeft;
3965 pf.top = df.top = mOverscanScreenTop;
3966 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
3967 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
3968 of.left = cf.left = mUnrestrictedScreenLeft;
3969 of.top = cf.top = mUnrestrictedScreenTop;
3970 of.right = cf.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3971 of.bottom = cf.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlock46646232013-09-30 22:32:42 -04003972 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08003973 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3974 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3975 // Asking to layout into the overscan region, so give it that pure
3976 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003977 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3978 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3979 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08003980 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003981 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003982 = mOverscanScreenTop + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003983 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003984 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Craig Mautnerbeac1062014-06-03 14:38:57 -07003985 && (attrs.type == TYPE_STATUS_BAR
3986 || attrs.type == TYPE_TOAST
Jorim Jaggi2fdeeab2015-04-01 15:13:03 -07003987 || attrs.type == TYPE_VOICE_INTERACTION_STARTING
John Spurlock34e13d92013-08-10 06:52:28 -04003988 || (attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3989 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW))) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003990 // Asking for layout as if the nav bar is hidden, lets the
3991 // application extend into the unrestricted screen area. We
John Spurlock34e13d92013-08-10 06:52:28 -04003992 // only do this for application windows (or toasts) to ensure no window that
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003993 // can be above the nav bar can do this.
3994 // XXX This assumes that an app asking for this will also
3995 // ask for layout in only content. We can't currently figure out
3996 // what the screen would be if only laying out to hide the nav bar.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003997 pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft;
3998 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
3999 pf.right = df.right = of.right = cf.right = mUnrestrictedScreenLeft
4000 + mUnrestrictedScreenWidth;
4001 pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop
4002 + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08004003 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004004 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
4005 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
4006 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
4007 + mRestrictedScreenWidth;
4008 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
4009 + mRestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08004010 }
Craig Mautner69b08182012-09-05 13:07:13 -07004011
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07004012 applyStableConstraints(sysUiFl, fl, cf);
Craig Mautner69b08182012-09-05 13:07:13 -07004013
Dianne Hackborndea3ef72010-10-28 14:24:22 -07004014 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
4015 vf.left = mCurLeft;
4016 vf.top = mCurTop;
4017 vf.right = mCurRight;
4018 vf.bottom = mCurBottom;
4019 } else {
4020 vf.set(cf);
4021 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004022 } else if (attached != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07004023 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
4024 "): attached to " + attached);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004025 // A child window should be placed inside of the same visible
4026 // frame that its parent had.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004027 setAttachedWindowFrames(win, fl, adjust, attached, false, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004028 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07004029 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
4030 "): normal window");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004031 // Otherwise, a normal window must be placed inside the content
4032 // of all screen decorations.
Dianne Hackborna239c842011-06-01 12:28:20 -07004033 if (attrs.type == TYPE_STATUS_BAR_PANEL) {
4034 // Status bar panels are the only windows who can go on top of
4035 // the status bar. They are protected by the STATUS_BAR_SERVICE
4036 // permission, so they have the same privileges as the status
4037 // bar itself.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004038 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
4039 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
4040 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
4041 + mRestrictedScreenWidth;
4042 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
4043 + mRestrictedScreenHeight;
John Spurlock414c1f02013-12-04 13:47:36 -05004044 } else if (attrs.type == TYPE_TOAST || attrs.type == TYPE_SYSTEM_ALERT
4045 || attrs.type == TYPE_VOLUME_OVERLAY) {
4046 // These dialogs are stable to interim decor changes.
John Spurlockbd957402013-10-03 11:38:39 -04004047 pf.left = df.left = of.left = cf.left = mStableLeft;
4048 pf.top = df.top = of.top = cf.top = mStableTop;
4049 pf.right = df.right = of.right = cf.right = mStableRight;
4050 pf.bottom = df.bottom = of.bottom = cf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004051 } else {
Dianne Hackborna239c842011-06-01 12:28:20 -07004052 pf.left = mContentLeft;
4053 pf.top = mContentTop;
4054 pf.right = mContentRight;
4055 pf.bottom = mContentBottom;
Dianne Hackborn20d94742014-05-29 18:35:45 -07004056 if (win.isVoiceInteraction()) {
4057 df.left = of.left = cf.left = mVoiceContentLeft;
4058 df.top = of.top = cf.top = mVoiceContentTop;
4059 df.right = of.right = cf.right = mVoiceContentRight;
4060 df.bottom = of.bottom = cf.bottom = mVoiceContentBottom;
4061 } else if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004062 df.left = of.left = cf.left = mDockLeft;
4063 df.top = of.top = cf.top = mDockTop;
4064 df.right = of.right = cf.right = mDockRight;
4065 df.bottom = of.bottom = cf.bottom = mDockBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07004066 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004067 df.left = of.left = cf.left = mContentLeft;
4068 df.top = of.top = cf.top = mContentTop;
4069 df.right = of.right = cf.right = mContentRight;
4070 df.bottom = of.bottom = cf.bottom = mContentBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07004071 }
4072 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
4073 vf.left = mCurLeft;
4074 vf.top = mCurTop;
4075 vf.right = mCurRight;
4076 vf.bottom = mCurBottom;
4077 } else {
4078 vf.set(cf);
4079 }
Dianne Hackborndea3ef72010-10-28 14:24:22 -07004080 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004081 }
4082 }
Craig Mautner69b08182012-09-05 13:07:13 -07004083
Craig Mautnerb816bed2013-07-23 10:26:17 -07004084 // TYPE_SYSTEM_ERROR is above the NavigationBar so it can't be allowed to extend over it.
4085 if ((fl & FLAG_LAYOUT_NO_LIMITS) != 0 && attrs.type != TYPE_SYSTEM_ERROR) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07004086 df.left = df.top = -10000;
4087 df.right = df.bottom = 10000;
4088 if (attrs.type != TYPE_WALLPAPER) {
4089 of.left = of.top = cf.left = cf.top = vf.left = vf.top = -10000;
4090 of.right = of.bottom = cf.right = cf.bottom = vf.right = vf.bottom = 10000;
4091 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004092 }
4093
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004094 // If the device has a chin (e.g. some watches), a dead area at the bottom of the screen we
4095 // need to provide information to the clients that want to pretend that you can draw there.
4096 if (isDefaultDisplay && (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0) {
4097 osf = mTmpOutsetFrame;
4098 osf.set(cf.left, cf.top, cf.right, cf.bottom);
4099 int outset = ScreenShapeHelper.getWindowOutsetBottomPx(mContext.getResources());
4100 if (outset > 0) {
4101 int rotation = Surface.ROTATION_0;
4102 try {
4103 rotation = mWindowManager.getRotation();
4104 } catch (RemoteException e) {
4105 }
4106 if (rotation == Surface.ROTATION_0) {
4107 osf.bottom += outset;
4108 } else if (rotation == Surface.ROTATION_90) {
4109 osf.right += outset;
4110 } else if (rotation == Surface.ROTATION_180) {
4111 osf.top -= outset;
4112 } else if (rotation == Surface.ROTATION_270) {
4113 osf.left -= outset;
4114 }
4115 if (DEBUG_LAYOUT) Slog.v(TAG, "applying bottom outset of " + outset
4116 + " with rotation " + rotation + ", result: " + osf);
4117 }
4118 }
4119
Craig Mautnereda67292013-04-28 13:50:14 -07004120 if (DEBUG_LAYOUT) Slog.v(TAG, "Compute frame " + attrs.getTitle()
The Android Open Source Project11267662009-03-18 17:39:47 -07004121 + ": sim=#" + Integer.toHexString(sim)
RoboErik8a2cfc32014-05-16 11:19:38 -07004122 + " attach=" + attached + " type=" + attrs.type
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004123 + String.format(" flags=0x%08x", fl)
The Android Open Source Project11267662009-03-18 17:39:47 -07004124 + " pf=" + pf.toShortString() + " df=" + df.toShortString()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004125 + " of=" + of.toShortString()
John Spurlock46646232013-09-30 22:32:42 -04004126 + " cf=" + cf.toShortString() + " vf=" + vf.toShortString()
Adrian Roosfa104232014-06-20 16:10:14 -07004127 + " dcf=" + dcf.toShortString()
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004128 + " sf=" + sf.toShortString()
4129 + " osf=" + (osf == null ? "null" : osf.toShortString()));
Craig Mautner69b08182012-09-05 13:07:13 -07004130
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004131 win.computeFrameLw(pf, df, of, cf, vf, dcf, sf, osf);
Craig Mautner69b08182012-09-05 13:07:13 -07004132
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004133 // Dock windows carve out the bottom of the screen, so normal windows
4134 // can't appear underneath them.
Craig Mautner8bd206b2012-10-03 10:32:02 -07004135 if (attrs.type == TYPE_INPUT_METHOD && win.isVisibleOrBehindKeyguardLw()
4136 && !win.getGivenInsetsPendingLw()) {
satok1bc0a492012-04-25 22:47:12 +09004137 setLastInputMethodWindowLw(null, null);
4138 offsetInputMethodWindowLw(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004139 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004140 if (attrs.type == TYPE_VOICE_INTERACTION && win.isVisibleOrBehindKeyguardLw()
4141 && !win.getGivenInsetsPendingLw()) {
4142 offsetVoiceInputWindowLw(win);
4143 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004144 }
4145
satok1bc0a492012-04-25 22:47:12 +09004146 private void offsetInputMethodWindowLw(WindowState win) {
Craig Mautner4774f6a2015-03-23 11:42:55 -07004147 int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top);
satok1bc0a492012-04-25 22:47:12 +09004148 top += win.getGivenContentInsetsLw().top;
4149 if (mContentBottom > top) {
4150 mContentBottom = top;
4151 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004152 if (mVoiceContentBottom > top) {
4153 mVoiceContentBottom = top;
4154 }
satok1bc0a492012-04-25 22:47:12 +09004155 top = win.getVisibleFrameLw().top;
4156 top += win.getGivenVisibleInsetsLw().top;
4157 if (mCurBottom > top) {
4158 mCurBottom = top;
4159 }
Craig Mautnereda67292013-04-28 13:50:14 -07004160 if (DEBUG_LAYOUT) Slog.v(TAG, "Input method: mDockBottom="
satok1bc0a492012-04-25 22:47:12 +09004161 + mDockBottom + " mContentBottom="
4162 + mContentBottom + " mCurBottom=" + mCurBottom);
4163 }
4164
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004165 private void offsetVoiceInputWindowLw(WindowState win) {
Craig Mautner4774f6a2015-03-23 11:42:55 -07004166 int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08004167 top += win.getGivenContentInsetsLw().top;
4168 if (mVoiceContentBottom > top) {
4169 mVoiceContentBottom = top;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004170 }
4171 }
4172
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004173 /** {@inheritDoc} */
Craig Mautner61ac6bb2012-02-02 17:29:33 -08004174 @Override
4175 public void finishLayoutLw() {
4176 return;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004177 }
4178
4179 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004180 @Override
Craig Mautner39834192012-09-02 07:47:24 -07004181 public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) {
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004182 mTopFullscreenOpaqueWindowState = null;
Adrian Rooscd3884d2015-02-18 17:25:23 +01004183 mTopFullscreenOpaqueOrDimmingWindowState = null;
Craig Mautner2bc789b2014-03-19 19:48:38 -07004184 mAppsToBeHidden.clear();
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004185 mAppsThatDismissKeyguard.clear();
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004186 mForceStatusBar = false;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004187 mForceStatusBarFromKeyguard = false;
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004188 mForceStatusBarTransparent = false;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08004189 mForcingShowNavBar = false;
4190 mForcingShowNavBarLayer = -1;
RoboErik8a2cfc32014-05-16 11:19:38 -07004191
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004192 mHideLockScreen = false;
4193 mAllowLockscreenWhenOn = false;
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004194 mDismissKeyguard = DISMISS_KEYGUARD_NONE;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004195 mShowingLockscreen = false;
4196 mShowingDream = false;
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004197 mWinShowWhenLocked = null;
Jim Millerab954542014-10-10 18:21:49 -07004198 mKeyguardSecure = isKeyguardSecure();
4199 mKeyguardSecureIncludingHidden = mKeyguardSecure
4200 && (mKeyguardDelegate != null && mKeyguardDelegate.isShowing());
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004201 }
4202
4203 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004204 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004205 public void applyPostLayoutPolicyLw(WindowState win, WindowManager.LayoutParams attrs) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004206 if (DEBUG_LAYOUT) Slog.i(TAG, "Win " + win + ": isVisibleOrBehindKeyguardLw="
4207 + win.isVisibleOrBehindKeyguardLw());
John Spurlockc6d1c602014-01-17 15:22:06 -05004208 final int fl = PolicyControl.getWindowFlags(win, attrs);
John Spurlock414c1f02013-12-04 13:47:36 -05004209 if (mTopFullscreenOpaqueWindowState == null
4210 && win.isVisibleLw() && attrs.type == TYPE_INPUT_METHOD) {
4211 mForcingShowNavBar = true;
4212 mForcingShowNavBarLayer = win.getSurfaceLayer();
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08004213 }
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004214 if (attrs.type == TYPE_STATUS_BAR) {
4215 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
4216 mForceStatusBarFromKeyguard = true;
4217 }
4218 if ((attrs.privateFlags & PRIVATE_FLAG_FORCE_STATUS_BAR_VISIBLE_TRANSPARENT) != 0) {
4219 mForceStatusBarTransparent = true;
4220 }
Jorim Jaggiafd4a552014-04-08 15:13:05 +02004221 }
Adrian Roos602c68e2015-04-24 16:03:47 -07004222
4223 boolean appWindow = attrs.type >= FIRST_APPLICATION_WINDOW
4224 && attrs.type < FIRST_SYSTEM_WINDOW;
4225 final boolean showWhenLocked = (fl & FLAG_SHOW_WHEN_LOCKED) != 0;
4226 final boolean dismissKeyguard = (fl & FLAG_DISMISS_KEYGUARD) != 0;
4227
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004228 if (mTopFullscreenOpaqueWindowState == null &&
Dianne Hackborn01b02a72012-01-12 14:05:03 -08004229 win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()) {
John Spurlockc6d1c602014-01-17 15:22:06 -05004230 if ((fl & FLAG_FORCE_NOT_FULLSCREEN) != 0) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004231 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004232 mForceStatusBarFromKeyguard = true;
4233 } else {
4234 mForceStatusBar = true;
4235 }
4236 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004237 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004238 mShowingLockscreen = true;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004239 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004240 if (attrs.type == TYPE_DREAM) {
Jeff Brownc8018eb2012-10-29 21:33:27 -07004241 // If the lockscreen was showing when the dream started then wait
4242 // for the dream to draw before hiding the lockscreen.
4243 if (!mDreamingLockscreen
4244 || (win.isVisibleLw() && win.hasDrawnLw())) {
4245 mShowingDream = true;
Craig Mautnerab55e522014-03-03 13:26:03 -08004246 appWindow = true;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004247 }
4248 }
Craig Mautnerab55e522014-03-03 13:26:03 -08004249
Craig Mautnerab55e522014-03-03 13:26:03 -08004250 if (appWindow) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004251 final IApplicationToken appToken = win.getAppToken();
4252 if (showWhenLocked) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004253 // Remove any previous windows with the same appToken.
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004254 mAppsToBeHidden.remove(appToken);
4255 mAppsThatDismissKeyguard.remove(appToken);
Craig Mautnerca0a1242014-12-02 12:25:14 -08004256 if (mAppsToBeHidden.isEmpty()) {
Craig Mautner192d6042014-12-02 23:24:48 -08004257 if (dismissKeyguard && !mKeyguardSecure) {
4258 mAppsThatDismissKeyguard.add(appToken);
4259 } else {
Craig Mautnerca0a1242014-12-02 12:25:14 -08004260 mWinShowWhenLocked = win;
4261 mHideLockScreen = true;
4262 mForceStatusBarFromKeyguard = false;
Craig Mautnerca0a1242014-12-02 12:25:14 -08004263 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004264 }
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004265 } else if (dismissKeyguard) {
Jim Millerab954542014-10-10 18:21:49 -07004266 if (mKeyguardSecure) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004267 mAppsToBeHidden.add(appToken);
4268 } else {
4269 mAppsToBeHidden.remove(appToken);
4270 }
4271 mAppsThatDismissKeyguard.add(appToken);
Craig Mautner2bc789b2014-03-19 19:48:38 -07004272 } else {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004273 mAppsToBeHidden.add(appToken);
Craig Mautner2bc789b2014-03-19 19:48:38 -07004274 }
Craig Mautnerab55e522014-03-03 13:26:03 -08004275 if (attrs.x == 0 && attrs.y == 0
4276 && attrs.width == WindowManager.LayoutParams.MATCH_PARENT
4277 && attrs.height == WindowManager.LayoutParams.MATCH_PARENT) {
4278 if (DEBUG_LAYOUT) Slog.v(TAG, "Fullscreen window: " + win);
4279 mTopFullscreenOpaqueWindowState = win;
Adrian Rooscd3884d2015-02-18 17:25:23 +01004280 if (mTopFullscreenOpaqueOrDimmingWindowState == null) {
4281 mTopFullscreenOpaqueOrDimmingWindowState = win;
4282 }
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004283 if (!mAppsThatDismissKeyguard.isEmpty() &&
4284 mDismissKeyguard == DISMISS_KEYGUARD_NONE) {
4285 if (DEBUG_LAYOUT) Slog.v(TAG,
4286 "Setting mDismissKeyguard true by win " + win);
tingna_sunge785ffa2015-05-12 13:23:15 +08004287 mDismissKeyguard = (mWinDismissingKeyguard == win
4288 && mSecureDismissingKeyguard == mKeyguardSecure)
4289 ? DISMISS_KEYGUARD_CONTINUE : DISMISS_KEYGUARD_START;
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004290 mWinDismissingKeyguard = win;
tingna_sunge785ffa2015-05-12 13:23:15 +08004291 mSecureDismissingKeyguard = mKeyguardSecure;
Jim Millerab954542014-10-10 18:21:49 -07004292 mForceStatusBarFromKeyguard = mShowingLockscreen && mKeyguardSecure;
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004293 } else if (mAppsToBeHidden.isEmpty() && showWhenLocked) {
4294 if (DEBUG_LAYOUT) Slog.v(TAG,
4295 "Setting mHideLockScreen to true by win " + win);
4296 mHideLockScreen = true;
4297 mForceStatusBarFromKeyguard = false;
Craig Mautnerab55e522014-03-03 13:26:03 -08004298 }
Craig Mautner00156ec2014-03-06 22:29:02 -08004299 if ((fl & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) {
Craig Mautnerab55e522014-03-03 13:26:03 -08004300 mAllowLockscreenWhenOn = true;
4301 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004302 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004303
4304 if (mWinShowWhenLocked != null &&
Adrian Roos602c68e2015-04-24 16:03:47 -07004305 mWinShowWhenLocked.getAppToken() != win.getAppToken() &&
4306 (attrs.flags & FLAG_SHOW_WHEN_LOCKED) == 0) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004307 win.hideLw(false);
4308 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004309 }
Adrian Roos602c68e2015-04-24 16:03:47 -07004310 } else if (mTopFullscreenOpaqueWindowState == null && mWinShowWhenLocked == null) {
4311 // No TopFullscreenOpaqueWindow is showing, but we found a SHOW_WHEN_LOCKED window
4312 // that is being hidden in an animation - keep the
4313 // keyguard hidden until the new window shows up and
4314 // we know whether to show the keyguard or not.
Adrian Roosb85e1ec2015-05-29 15:23:18 -07004315 if (win.isAnimatingLw() && appWindow && showWhenLocked && mKeyguardHidden) {
Adrian Roos602c68e2015-04-24 16:03:47 -07004316 mHideLockScreen = true;
4317 mWinShowWhenLocked = win;
4318 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004319 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01004320 if (mTopFullscreenOpaqueOrDimmingWindowState == null
4321 && win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()
4322 && win.isDimming()) {
4323 mTopFullscreenOpaqueOrDimmingWindowState = win;
4324 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004325 }
4326
4327 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004328 @Override
Craig Mautner39834192012-09-02 07:47:24 -07004329 public int finishPostLayoutPolicyLw() {
Craig Mautnerc5e73bf2015-04-21 15:41:26 +00004330 if (mWinShowWhenLocked != null && mTopFullscreenOpaqueWindowState != null &&
4331 mWinShowWhenLocked.getAppToken() != mTopFullscreenOpaqueWindowState.getAppToken()
4332 && isKeyguardLocked()) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004333 // A dialog is dismissing the keyguard. Put the wallpaper behind it and hide the
4334 // fullscreen window.
4335 // TODO: Make sure FLAG_SHOW_WALLPAPER is restored when dialog is dismissed. Or not.
4336 mWinShowWhenLocked.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
4337 mTopFullscreenOpaqueWindowState.hideLw(false);
4338 mTopFullscreenOpaqueWindowState = mWinShowWhenLocked;
4339 }
4340
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004341 int changes = 0;
Joe Onorato93056472010-09-10 10:30:46 -04004342 boolean topIsFullscreen = false;
Daniel Sandlere02d8082010-10-08 15:13:22 -04004343
4344 final WindowManager.LayoutParams lp = (mTopFullscreenOpaqueWindowState != null)
4345 ? mTopFullscreenOpaqueWindowState.getAttrs()
4346 : null;
4347
Jeff Brownc8018eb2012-10-29 21:33:27 -07004348 // If we are not currently showing a dream then remember the current
4349 // lockscreen state. We will use this to determine whether the dream
4350 // started while the lockscreen was showing and remember this state
4351 // while the dream is showing.
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004352 if (!mShowingDream) {
4353 mDreamingLockscreen = mShowingLockscreen;
Jeff Brown061ea992015-04-17 19:55:47 -07004354 if (mDreamingSleepTokenNeeded) {
4355 mDreamingSleepTokenNeeded = false;
4356 mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 0, 1).sendToTarget();
4357 }
4358 } else {
4359 if (!mDreamingSleepTokenNeeded) {
4360 mDreamingSleepTokenNeeded = true;
4361 mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 1, 1).sendToTarget();
4362 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004363 }
4364
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004365 if (mStatusBar != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07004366 if (DEBUG_LAYOUT) Slog.i(TAG, "force=" + mForceStatusBar
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004367 + " forcefkg=" + mForceStatusBarFromKeyguard
Dianne Hackbornd70bc2f2009-10-06 23:25:51 -07004368 + " top=" + mTopFullscreenOpaqueWindowState);
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004369 boolean shouldBeTransparent = mForceStatusBarTransparent
4370 && !mForceStatusBar
4371 && !mForceStatusBarFromKeyguard;
4372 if (!shouldBeTransparent) {
4373 mStatusBarController.setShowTransparent(false /* transparent */);
4374 } else if (!mStatusBar.isVisibleLw()) {
4375 mStatusBarController.setShowTransparent(true /* transparent */);
4376 }
4377 if (mForceStatusBar || mForceStatusBarFromKeyguard || mForceStatusBarTransparent) {
Craig Mautnereda67292013-04-28 13:50:14 -07004378 if (DEBUG_LAYOUT) Slog.v(TAG, "Showing status bar: forced");
John Spurlock27735a42013-08-14 17:57:38 -04004379 if (mStatusBarController.setBarShowingLw(true)) {
4380 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4381 }
Craig Mautner81defc72013-10-29 11:10:42 -07004382 // Maintain fullscreen layout until incoming animation is complete.
4383 topIsFullscreen = mTopIsFullscreen && mStatusBar.isAnimatingLw();
John Spurlockf92b6162013-11-11 15:01:16 -05004384 // Transient status bar on the lockscreen is not allowed
4385 if (mForceStatusBarFromKeyguard && mStatusBarController.isTransientShowing()) {
4386 mStatusBarController.updateVisibilityLw(false /*transientAllowed*/,
4387 mLastSystemUiFlags, mLastSystemUiFlags);
4388 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004389 } else if (mTopFullscreenOpaqueWindowState != null) {
John Spurlockc6d1c602014-01-17 15:22:06 -05004390 final int fl = PolicyControl.getWindowFlags(null, lp);
Joe Onorato93056472010-09-10 10:30:46 -04004391 if (localLOGV) {
Craig Mautnereda67292013-04-28 13:50:14 -07004392 Slog.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw()
Joe Onorato93056472010-09-10 10:30:46 -04004393 + " shown frame: " + mTopFullscreenOpaqueWindowState.getShownFrameLw());
Craig Mautnereda67292013-04-28 13:50:14 -07004394 Slog.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs()
John Spurlockc6d1c602014-01-17 15:22:06 -05004395 + " lp.flags=0x" + Integer.toHexString(fl));
Joe Onorato93056472010-09-10 10:30:46 -04004396 }
John Spurlockc6d1c602014-01-17 15:22:06 -05004397 topIsFullscreen = (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004398 || (mLastSystemUiFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
Joe Onorato93056472010-09-10 10:30:46 -04004399 // The subtle difference between the window for mTopFullscreenOpaqueWindowState
Mark Dolinerd0646dc2014-08-27 16:04:02 -07004400 // and mTopIsFullscreen is that mTopIsFullscreen is set only if the window
Joe Onorato93056472010-09-10 10:30:46 -04004401 // has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the
4402 // case though.
John Spurlock27735a42013-08-14 17:57:38 -04004403 if (mStatusBarController.isTransientShowing()) {
4404 if (mStatusBarController.setBarShowingLw(true)) {
John Spurlock32beb2c2013-03-11 10:16:47 -04004405 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4406 }
4407 } else if (topIsFullscreen) {
Craig Mautnereda67292013-04-28 13:50:14 -07004408 if (DEBUG_LAYOUT) Slog.v(TAG, "** HIDING status bar");
John Spurlock27735a42013-08-14 17:57:38 -04004409 if (mStatusBarController.setBarShowingLw(false)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004410 changes |= FINISH_LAYOUT_REDO_LAYOUT;
Craig Mautnereda67292013-04-28 13:50:14 -07004411 } else {
Craig Mautnerc5a6e442013-06-05 17:22:35 -07004412 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar already hiding");
Daniel Sandler40427442010-07-16 11:44:52 -04004413 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004414 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07004415 if (DEBUG_LAYOUT) Slog.v(TAG, "** SHOWING status bar: top is not fullscreen");
John Spurlock27735a42013-08-14 17:57:38 -04004416 if (mStatusBarController.setBarShowingLw(true)) {
4417 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4418 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004419 }
4420 }
4421 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04004422
Craig Mautner81defc72013-10-29 11:10:42 -07004423 if (mTopIsFullscreen != topIsFullscreen) {
4424 if (!topIsFullscreen) {
4425 // Force another layout when status bar becomes fully shown.
4426 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4427 }
4428 mTopIsFullscreen = topIsFullscreen;
4429 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04004430
Craig Mautner39834192012-09-02 07:47:24 -07004431 // Hide the key guard if a visible window explicitly specifies that it wants to be
4432 // displayed when the screen is locked.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004433 if (mKeyguardDelegate != null && mStatusBar != null) {
4434 if (localLOGV) Slog.v(TAG, "finishPostLayoutPolicyLw: mHideKeyguard="
4435 + mHideLockScreen);
Jim Millerab954542014-10-10 18:21:49 -07004436 if (mDismissKeyguard != DISMISS_KEYGUARD_NONE && !mKeyguardSecure) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004437 mKeyguardHidden = true;
Jim Millerab954542014-10-10 18:21:49 -07004438 if (setKeyguardOccludedLw(true)) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004439 changes |= FINISH_LAYOUT_REDO_LAYOUT
4440 | FINISH_LAYOUT_REDO_CONFIG
4441 | FINISH_LAYOUT_REDO_WALLPAPER;
4442 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004443 if (mKeyguardDelegate.isShowing()) {
4444 mHandler.post(new Runnable() {
4445 @Override
4446 public void run() {
4447 mKeyguardDelegate.keyguardDone(false, false);
4448 }
4449 });
4450 }
4451 } else if (mHideLockScreen) {
4452 mKeyguardHidden = true;
Jorim Jaggi7d85ea92015-05-20 17:20:40 -07004453 mWinDismissingKeyguard = null;
Jim Millerab954542014-10-10 18:21:49 -07004454 if (setKeyguardOccludedLw(true)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004455 changes |= FINISH_LAYOUT_REDO_LAYOUT
4456 | FINISH_LAYOUT_REDO_CONFIG
4457 | FINISH_LAYOUT_REDO_WALLPAPER;
4458 }
4459 } else if (mDismissKeyguard != DISMISS_KEYGUARD_NONE) {
Jorim Jaggi7d85ea92015-05-20 17:20:40 -07004460 mKeyguardHidden = false;
4461 if (setKeyguardOccludedLw(false)) {
4462 changes |= FINISH_LAYOUT_REDO_LAYOUT
4463 | FINISH_LAYOUT_REDO_CONFIG
4464 | FINISH_LAYOUT_REDO_WALLPAPER;
4465 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004466 if (mDismissKeyguard == DISMISS_KEYGUARD_START) {
4467 // Only launch the next keyguard unlock window once per window.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004468 mHandler.post(new Runnable() {
4469 @Override
4470 public void run() {
4471 mKeyguardDelegate.dismiss();
4472 }
4473 });
4474 }
4475 } else {
4476 mWinDismissingKeyguard = null;
tingna_sunge785ffa2015-05-12 13:23:15 +08004477 mSecureDismissingKeyguard = false;
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004478 mKeyguardHidden = false;
Jim Millerab954542014-10-10 18:21:49 -07004479 if (setKeyguardOccludedLw(false)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004480 changes |= FINISH_LAYOUT_REDO_LAYOUT
4481 | FINISH_LAYOUT_REDO_CONFIG
4482 | FINISH_LAYOUT_REDO_WALLPAPER;
4483 }
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -07004484 }
4485 }
Joe Onorato664644d2011-01-23 17:53:23 -08004486
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004487 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004488 // If the navigation bar has been hidden or shown, we need to do another
4489 // layout pass to update that window.
4490 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4491 }
Joe Onorato664644d2011-01-23 17:53:23 -08004492
Mike Lockwood28569302010-01-28 11:54:40 -05004493 // update since mAllowLockscreenWhenOn might have changed
4494 updateLockScreenTimeout();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004495 return changes;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004496 }
4497
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004498 /**
Jim Millerab954542014-10-10 18:21:49 -07004499 * Updates the occluded state of the Keyguard.
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004500 *
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004501 * @return Whether the flags have changed and we have to redo the layout.
4502 */
Jim Millerab954542014-10-10 18:21:49 -07004503 private boolean setKeyguardOccludedLw(boolean isOccluded) {
4504 boolean wasOccluded = mKeyguardOccluded;
4505 boolean showing = mKeyguardDelegate.isShowing();
4506 if (wasOccluded && !isOccluded && showing) {
4507 mKeyguardOccluded = false;
4508 mKeyguardDelegate.setOccluded(false);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004509 mStatusBar.getAttrs().privateFlags |= PRIVATE_FLAG_KEYGUARD;
4510 mStatusBar.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
4511 return true;
Jim Millerab954542014-10-10 18:21:49 -07004512 } else if (!wasOccluded && isOccluded && showing) {
4513 mKeyguardOccluded = true;
4514 mKeyguardDelegate.setOccluded(true);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004515 mStatusBar.getAttrs().privateFlags &= ~PRIVATE_FLAG_KEYGUARD;
4516 mStatusBar.getAttrs().flags &= ~FLAG_SHOW_WALLPAPER;
4517 return true;
4518 } else {
4519 return false;
4520 }
4521 }
4522
4523 private boolean isStatusBarKeyguard() {
4524 return mStatusBar != null
4525 && (mStatusBar.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
4526 }
4527
Jose Lima9546b202014-07-02 17:21:51 -07004528 @Override
Dianne Hackborn08743722009-12-21 12:16:51 -08004529 public boolean allowAppAnimationsLw() {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004530 if (isStatusBarKeyguard() || mShowingDream) {
Craig Mautner28816302013-10-10 20:31:00 -07004531 // If keyguard or dreams is currently visible, no reason to animate behind it.
Dianne Hackborn08743722009-12-21 12:16:51 -08004532 return false;
4533 }
Dianne Hackborn08743722009-12-21 12:16:51 -08004534 return true;
4535 }
4536
Jose Lima9546b202014-07-02 17:21:51 -07004537 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07004538 public int focusChangedLw(WindowState lastFocus, WindowState newFocus) {
Joe Onorato664644d2011-01-23 17:53:23 -08004539 mFocusedWindow = newFocus;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004540 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004541 // If the navigation bar has been hidden or shown, we need to do another
4542 // layout pass to update that window.
4543 return FINISH_LAYOUT_REDO_LAYOUT;
4544 }
4545 return 0;
Joe Onorato664644d2011-01-23 17:53:23 -08004546 }
4547
Dianne Hackborn0ecadf72009-03-31 18:00:37 -07004548 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07004549 @Override
Jeff Brown46b9ac02010-04-22 18:58:52 -07004550 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
4551 // lid changed state
Jeff Brownc458ce92012-04-30 14:58:40 -07004552 final int newLidState = lidOpen ? LID_OPEN : LID_CLOSED;
4553 if (newLidState == mLidState) {
4554 return;
4555 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004556
Jeff Brownc458ce92012-04-30 14:58:40 -07004557 mLidState = newLidState;
4558 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07004559 updateRotation(true);
Jeff Brownc458ce92012-04-30 14:58:40 -07004560
4561 if (lidOpen) {
Bryce Lee584a4452014-10-21 15:55:55 -07004562 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromLidSwitch);
Jeff Brownc458ce92012-04-30 14:58:40 -07004563 } else if (!mLidControlsSleep) {
Jeff Brown96307042012-07-27 15:51:34 -07004564 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
Jeff Brown46b9ac02010-04-22 18:58:52 -07004565 }
4566 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004567
Michael Wright3818c922014-09-02 13:59:07 -07004568 @Override
4569 public void notifyCameraLensCoverSwitchChanged(long whenNanos, boolean lensCovered) {
4570 int lensCoverState = lensCovered ? CAMERA_LENS_COVERED : CAMERA_LENS_UNCOVERED;
4571 if (mCameraLensCoverState == lensCoverState) {
4572 return;
4573 }
4574 if (mCameraLensCoverState == CAMERA_LENS_COVERED &&
4575 lensCoverState == CAMERA_LENS_UNCOVERED) {
4576 Intent intent;
4577 final boolean keyguardActive = mKeyguardDelegate == null ? false :
4578 mKeyguardDelegate.isShowing();
4579 if (keyguardActive) {
4580 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE);
4581 } else {
4582 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
4583 }
Bryce Lee584a4452014-10-21 15:55:55 -07004584 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromCameraLens);
Bart Sears8b1c27c2015-03-18 23:51:02 +00004585 startActivityAsUser(intent, UserHandle.CURRENT_OR_SELF);
Michael Wright3818c922014-09-02 13:59:07 -07004586 }
4587 mCameraLensCoverState = lensCoverState;
4588 }
4589
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004590 void setHdmiPlugged(boolean plugged) {
4591 if (mHdmiPlugged != plugged) {
4592 mHdmiPlugged = plugged;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004593 updateRotation(true, true);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004594 Intent intent = new Intent(ACTION_HDMI_PLUGGED);
Joe Onoratodc100302011-01-11 17:07:41 -08004595 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004596 intent.putExtra(EXTRA_HDMI_PLUGGED_STATE, plugged);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07004597 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004598 }
4599 }
4600
Joe Onoratoea495d42011-04-06 11:41:11 -07004601 void initializeHdmiState() {
Joe Onorato7ba631f2011-05-04 15:28:00 -07004602 boolean plugged = false;
Joe Onoratoea495d42011-04-06 11:41:11 -07004603 // watch for HDMI plug messages if the hdmi switch exists
4604 if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) {
4605 mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi");
4606
Joe Onoratoea495d42011-04-06 11:41:11 -07004607 final String filename = "/sys/class/switch/hdmi/state";
4608 FileReader reader = null;
4609 try {
4610 reader = new FileReader(filename);
4611 char[] buf = new char[15];
4612 int n = reader.read(buf);
4613 if (n > 1) {
4614 plugged = 0 != Integer.parseInt(new String(buf, 0, n-1));
4615 }
4616 } catch (IOException ex) {
4617 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
4618 } catch (NumberFormatException ex) {
4619 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
4620 } finally {
4621 if (reader != null) {
4622 try {
4623 reader.close();
4624 } catch (IOException ex) {
4625 }
Joe Onoratodc100302011-01-11 17:07:41 -08004626 }
4627 }
4628 }
Joe Onorato7ba631f2011-05-04 15:28:00 -07004629 // This dance forces the code in setHdmiPlugged to run.
4630 // Always do this so the sticky intent is stuck (to false) if there is no hdmi.
4631 mHdmiPlugged = !plugged;
4632 setHdmiPlugged(!mHdmiPlugged);
Joe Onoratodc100302011-01-11 17:07:41 -08004633 }
4634
Dianne Hackbornc0e3f242011-08-19 14:19:10 -07004635 final Object mScreenshotLock = new Object();
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004636 ServiceConnection mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004637
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004638 final Runnable mScreenshotTimeout = new Runnable() {
4639 @Override public void run() {
4640 synchronized (mScreenshotLock) {
4641 if (mScreenshotConnection != null) {
4642 mContext.unbindService(mScreenshotConnection);
4643 mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004644 }
Winson Chung9112ec32011-06-27 13:15:32 -07004645 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004646 }
4647 };
4648
4649 // Assume this is called from the Handler thread.
4650 private void takeScreenshot() {
4651 synchronized (mScreenshotLock) {
4652 if (mScreenshotConnection != null) {
4653 return;
4654 }
4655 ComponentName cn = new ComponentName("com.android.systemui",
4656 "com.android.systemui.screenshot.TakeScreenshotService");
4657 Intent intent = new Intent();
4658 intent.setComponent(cn);
4659 ServiceConnection conn = new ServiceConnection() {
4660 @Override
4661 public void onServiceConnected(ComponentName name, IBinder service) {
4662 synchronized (mScreenshotLock) {
4663 if (mScreenshotConnection != this) {
4664 return;
4665 }
4666 Messenger messenger = new Messenger(service);
4667 Message msg = Message.obtain(null, 1);
4668 final ServiceConnection myConn = this;
4669 Handler h = new Handler(mHandler.getLooper()) {
4670 @Override
4671 public void handleMessage(Message msg) {
4672 synchronized (mScreenshotLock) {
4673 if (mScreenshotConnection == myConn) {
4674 mContext.unbindService(mScreenshotConnection);
4675 mScreenshotConnection = null;
4676 mHandler.removeCallbacks(mScreenshotTimeout);
4677 }
4678 }
4679 }
4680 };
4681 msg.replyTo = new Messenger(h);
Winson Chunga63bb842011-10-17 10:26:28 -07004682 msg.arg1 = msg.arg2 = 0;
4683 if (mStatusBar != null && mStatusBar.isVisibleLw())
4684 msg.arg1 = 1;
4685 if (mNavigationBar != null && mNavigationBar.isVisibleLw())
4686 msg.arg2 = 1;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004687 try {
4688 messenger.send(msg);
4689 } catch (RemoteException e) {
4690 }
4691 }
4692 }
4693 @Override
4694 public void onServiceDisconnected(ComponentName name) {}
4695 };
Amith Yamasani27b89e62013-01-16 12:30:11 -08004696 if (mContext.bindServiceAsUser(
4697 intent, conn, Context.BIND_AUTO_CREATE, UserHandle.CURRENT)) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004698 mScreenshotConnection = conn;
4699 mHandler.postDelayed(mScreenshotTimeout, 10000);
4700 }
4701 }
Winson Chung9112ec32011-06-27 13:15:32 -07004702 }
4703
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004704 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004705 @Override
Jeff Brown037c33e2014-04-09 00:31:55 -07004706 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) {
Jeff Brown96307042012-07-27 15:51:34 -07004707 if (!mSystemBooted) {
4708 // If we have not yet booted, don't let key events do anything.
4709 return 0;
4710 }
4711
Jeff Brown037c33e2014-04-09 00:31:55 -07004712 final boolean interactive = (policyFlags & FLAG_INTERACTIVE) != 0;
Jeff Brown1f245102010-11-18 20:53:46 -08004713 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
4714 final boolean canceled = event.isCanceled();
4715 final int keyCode = event.getKeyCode();
Jeff Browne20c9e02010-10-11 14:20:19 -07004716
Jeff Brown3122e442010-10-11 23:32:49 -07004717 final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0;
Jeff Brown3122e442010-10-11 23:32:49 -07004718
Mike Lockwoodc72b15f2009-11-28 20:58:22 -05004719 // If screen is off then we treat the case where the keyguard is open but hidden
4720 // the same as if it were open and in front.
4721 // This will prevent any keys other than the power button from waking the screen
4722 // when the keyguard is hidden by another activity.
Jim Miller5ecd8112013-01-09 18:50:26 -08004723 final boolean keyguardActive = (mKeyguardDelegate == null ? false :
Jeff Brown037c33e2014-04-09 00:31:55 -07004724 (interactive ?
Jim Millerab954542014-10-10 18:21:49 -07004725 isKeyguardShowingAndNotOccluded() :
Jim Miller5ecd8112013-01-09 18:50:26 -08004726 mKeyguardDelegate.isShowing()));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004727
Jeff Brown40013652012-05-16 21:22:36 -07004728 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004729 Log.d(TAG, "interceptKeyTq keycode=" + keyCode
Jeff Brown037c33e2014-04-09 00:31:55 -07004730 + " interactive=" + interactive + " keyguardActive=" + keyguardActive
Jeff Brown26875502014-01-30 21:47:47 -08004731 + " policyFlags=" + Integer.toHexString(policyFlags));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004732 }
4733
Jeff Brown037c33e2014-04-09 00:31:55 -07004734 // Basic policy based on interactive state.
Jeff Brown4d396052010-10-29 21:50:21 -07004735 int result;
Michael Wright337d9d22014-04-22 15:03:48 -07004736 boolean isWakeKey = (policyFlags & WindowManagerPolicy.FLAG_WAKE) != 0
4737 || event.isWakeKey();
Michael Wrightfc01f042014-09-08 14:12:24 -07004738 if (interactive || (isInjected && !isWakeKey)) {
RoboErikde9ba392014-09-26 12:51:01 -07004739 // When the device is interactive or the key is injected pass the
4740 // key to the application.
Jeff Brown4d396052010-10-29 21:50:21 -07004741 result = ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07004742 isWakeKey = false;
Michael Wrightfc01f042014-09-08 14:12:24 -07004743 } else if (!interactive && shouldDispatchInputWhenNonInteractive()) {
4744 // If we're currently dozing with the screen on and the keyguard showing, pass the key
4745 // to the application but preserve its wake key status to make sure we still move
4746 // from dozing to fully interactive if we would normally go from off to fully
4747 // interactive.
4748 result = ACTION_PASS_TO_USER;
Jeff Brown4d396052010-10-29 21:50:21 -07004749 } else {
4750 // When the screen is off and the key is not injected, determine whether
4751 // to wake the device but don't pass the key to the application.
4752 result = 0;
Jeff Brown26875502014-01-30 21:47:47 -08004753 if (isWakeKey && (!down || !isWakeKeyWhenScreenOff(keyCode))) {
4754 isWakeKey = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004755 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004756 }
4757
Justin Kohd378ad72013-04-01 12:18:26 -07004758 // If the key would be handled globally, just return the result, don't worry about special
4759 // key processing.
Jeff Brown13f00f02014-10-31 14:45:50 -07004760 if (isValidGlobalKey(keyCode)
4761 && mGlobalKeyManager.shouldHandleGlobalKey(keyCode, event)) {
Michael Wright85b1af62014-06-04 14:51:58 -07004762 if (isWakeKey) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004763 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey);
Michael Wright85b1af62014-06-04 14:51:58 -07004764 }
Justin Kohd378ad72013-04-01 12:18:26 -07004765 return result;
4766 }
4767
Jeff Brownbae8e772014-06-12 19:59:45 -07004768 boolean useHapticFeedback = down
4769 && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0
4770 && event.getRepeatCount() == 0;
4771
Jeff Brown4d396052010-10-29 21:50:21 -07004772 // Handle special keys.
4773 switch (keyCode) {
4774 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jeff Brownb0418da2010-11-01 15:24:01 -07004775 case KeyEvent.KEYCODE_VOLUME_UP:
4776 case KeyEvent.KEYCODE_VOLUME_MUTE: {
RoboErik001c59c2015-01-26 15:53:51 -08004777 if (mUseTvRouting) {
4778 // On TVs volume keys never go to the foreground app
4779 result &= ~ACTION_PASS_TO_USER;
4780 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004781 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
4782 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004783 if (interactive && !mScreenshotChordVolumeDownKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004784 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004785 mScreenshotChordVolumeDownKeyTriggered = true;
4786 mScreenshotChordVolumeDownKeyTime = event.getDownTime();
4787 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004788 cancelPendingPowerKeyAction();
4789 interceptScreenshotChord();
4790 }
4791 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004792 mScreenshotChordVolumeDownKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004793 cancelPendingScreenshotChordAction();
4794 }
4795 } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
4796 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004797 if (interactive && !mScreenshotChordVolumeUpKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004798 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004799 mScreenshotChordVolumeUpKeyTriggered = true;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004800 cancelPendingPowerKeyAction();
4801 cancelPendingScreenshotChordAction();
4802 }
4803 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004804 mScreenshotChordVolumeUpKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004805 cancelPendingScreenshotChordAction();
4806 }
4807 }
Jeff Brown4d396052010-10-29 21:50:21 -07004808 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004809 TelecomManager telecomManager = getTelecommService();
4810 if (telecomManager != null) {
4811 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07004812 // If an incoming call is ringing, either VOLUME key means
4813 // "silence ringer". We handle these keys here, rather than
4814 // in the InCallScreen, to make sure we'll respond to them
4815 // even if the InCallScreen hasn't come to the foreground yet.
4816 // Look for the DOWN event here, to agree with the "fallback"
4817 // behavior in the InCallScreen.
4818 Log.i(TAG, "interceptKeyBeforeQueueing:"
4819 + " VOLUME key-down while ringing: Silence ringer!");
Jeff Brown4d396052010-10-29 21:50:21 -07004820
Santos Cordon6848f722014-05-21 15:22:12 -07004821 // Silence the ringer. (It's safe to call this
4822 // even if the ringer has already been silenced.)
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004823 telecomManager.silenceRinger();
Jeff Brown4d396052010-10-29 21:50:21 -07004824
Santos Cordon6848f722014-05-21 15:22:12 -07004825 // And *don't* pass this key thru to the current activity
4826 // (which is probably the InCallScreen.)
4827 result &= ~ACTION_PASS_TO_USER;
4828 break;
4829 }
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004830 if (telecomManager.isInCall()
Santos Cordon6848f722014-05-21 15:22:12 -07004831 && (result & ACTION_PASS_TO_USER) == 0) {
4832 // If we are in call but we decided not to pass the key to
RoboErik430fc482014-06-12 15:49:20 -07004833 // the application, just pass it to the session service.
4834
4835 MediaSessionLegacyHelper.getHelper(mContext)
RoboErik3c45c292014-07-08 16:47:31 -07004836 .sendVolumeKeyEvent(event, false);
Santos Cordon6848f722014-05-21 15:22:12 -07004837 break;
Jeff Brown4d396052010-10-29 21:50:21 -07004838 }
4839 }
4840
RoboErik430fc482014-06-12 15:49:20 -07004841 if ((result & ACTION_PASS_TO_USER) == 0) {
RoboErik001c59c2015-01-26 15:53:51 -08004842 if (mUseTvRouting) {
4843 dispatchDirectAudioEvent(event);
4844 } else {
4845 // If we aren't passing to the user and no one else
4846 // handled it send it to the session manager to
4847 // figure out.
4848 MediaSessionLegacyHelper.getHelper(mContext)
4849 .sendVolumeKeyEvent(event, true);
4850 }
Jeff Brown4d396052010-10-29 21:50:21 -07004851 break;
4852 }
4853 }
4854 break;
4855 }
4856
4857 case KeyEvent.KEYCODE_ENDCALL: {
4858 result &= ~ACTION_PASS_TO_USER;
4859 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004860 TelecomManager telecomManager = getTelecommService();
Jeff Brown4d396052010-10-29 21:50:21 -07004861 boolean hungUp = false;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004862 if (telecomManager != null) {
4863 hungUp = telecomManager.endCall();
Jeff Brown4d396052010-10-29 21:50:21 -07004864 }
Jeff Brown13f00f02014-10-31 14:45:50 -07004865 if (interactive && !hungUp) {
4866 mEndCallKeyHandled = false;
4867 mHandler.postDelayed(mEndCallLongPress,
4868 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
4869 } else {
4870 mEndCallKeyHandled = true;
4871 }
Jeff Brown4d396052010-10-29 21:50:21 -07004872 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004873 if (!mEndCallKeyHandled) {
4874 mHandler.removeCallbacks(mEndCallLongPress);
4875 if (!canceled) {
4876 if ((mEndcallBehavior
4877 & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) {
4878 if (goHome()) {
4879 break;
4880 }
Dianne Hackborn0041e972009-07-24 17:14:43 -07004881 }
Jeff Brown13f00f02014-10-31 14:45:50 -07004882 if ((mEndcallBehavior
4883 & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) {
4884 mPowerManager.goToSleep(event.getEventTime(),
4885 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
4886 isWakeKey = false;
4887 }
Jeff Brown4d396052010-10-29 21:50:21 -07004888 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004889 }
Jeff Brown4d396052010-10-29 21:50:21 -07004890 }
4891 break;
4892 }
4893
4894 case KeyEvent.KEYCODE_POWER: {
4895 result &= ~ACTION_PASS_TO_USER;
Jeff Brown13f00f02014-10-31 14:45:50 -07004896 isWakeKey = false; // wake-up will be handled separately
Jeff Brown4d396052010-10-29 21:50:21 -07004897 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004898 interceptPowerKeyDown(event, interactive);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004899 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07004900 interceptPowerKeyUp(event, interactive, canceled);
Jeff Brown4d396052010-10-29 21:50:21 -07004901 }
4902 break;
4903 }
4904
Jeff Brown6212a492014-03-07 13:58:47 -08004905 case KeyEvent.KEYCODE_SLEEP: {
4906 result &= ~ACTION_PASS_TO_USER;
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00004907 isWakeKey = false;
Jeff Brownbae8e772014-06-12 19:59:45 -07004908 if (!mPowerManager.isInteractive()) {
4909 useHapticFeedback = false; // suppress feedback if already non-interactive
4910 }
Nick Vaccarob593a812015-05-15 11:23:05 -07004911 if (down) {
4912 sleepPress(event.getEventTime());
4913 } else {
4914 sleepRelease(event.getEventTime());
4915 }
Jeff Brown6212a492014-03-07 13:58:47 -08004916 break;
4917 }
4918
4919 case KeyEvent.KEYCODE_WAKEUP: {
4920 result &= ~ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07004921 isWakeKey = true;
Jeff Brown6212a492014-03-07 13:58:47 -08004922 break;
4923 }
4924
Jeff Brown4d396052010-10-29 21:50:21 -07004925 case KeyEvent.KEYCODE_MEDIA_PLAY:
4926 case KeyEvent.KEYCODE_MEDIA_PAUSE:
4927 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
Jeff Brown4d396052010-10-29 21:50:21 -07004928 case KeyEvent.KEYCODE_HEADSETHOOK:
4929 case KeyEvent.KEYCODE_MUTE:
4930 case KeyEvent.KEYCODE_MEDIA_STOP:
4931 case KeyEvent.KEYCODE_MEDIA_NEXT:
4932 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
4933 case KeyEvent.KEYCODE_MEDIA_REWIND:
4934 case KeyEvent.KEYCODE_MEDIA_RECORD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09004935 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
4936 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: {
RoboErikde9ba392014-09-26 12:51:01 -07004937 if (MediaSessionLegacyHelper.getHelper(mContext).isGlobalPriorityActive()) {
4938 // If the global session is active pass all media keys to it
4939 // instead of the active window.
4940 result &= ~ACTION_PASS_TO_USER;
4941 }
Jeff Brown4d396052010-10-29 21:50:21 -07004942 if ((result & ACTION_PASS_TO_USER) == 0) {
4943 // Only do this if we would otherwise not pass it to the user. In that
4944 // case, the PhoneWindow class will do the same thing, except it will
4945 // only do it if the showing app doesn't process the key on its own.
Jeff Brown40013652012-05-16 21:22:36 -07004946 // Note that we need to make a copy of the key event here because the
4947 // original key event will be recycled when we return.
Jeff Brown4d396052010-10-29 21:50:21 -07004948 mBroadcastWakeLock.acquire();
Jeff Brown40013652012-05-16 21:22:36 -07004949 Message msg = mHandler.obtainMessage(MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK,
4950 new KeyEvent(event));
4951 msg.setAsynchronous(true);
4952 msg.sendToTarget();
Jeff Brown4d396052010-10-29 21:50:21 -07004953 }
4954 break;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004955 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004956
Jeff Brown4d396052010-10-29 21:50:21 -07004957 case KeyEvent.KEYCODE_CALL: {
4958 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004959 TelecomManager telecomManager = getTelecommService();
4960 if (telecomManager != null) {
4961 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07004962 Log.i(TAG, "interceptKeyBeforeQueueing:"
4963 + " CALL key-down while ringing: Answer the call!");
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004964 telecomManager.acceptRingingCall();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004965
Santos Cordon6848f722014-05-21 15:22:12 -07004966 // And *don't* pass this key thru to the current activity
4967 // (which is presumably the InCallScreen.)
4968 result &= ~ACTION_PASS_TO_USER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004969 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004970 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004971 }
Jeff Brown4d396052010-10-29 21:50:21 -07004972 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004973 }
Michael Wright869a67c2014-08-26 19:33:06 -07004974 case KeyEvent.KEYCODE_VOICE_ASSIST: {
4975 // Only do this if we would otherwise not pass it to the user. In that case,
4976 // interceptKeyBeforeDispatching would apply a similar but different policy in
4977 // order to invoke voice assist actions. Note that we need to make a copy of the
4978 // key event here because the original key event will be recycled when we return.
4979 if ((result & ACTION_PASS_TO_USER) == 0 && !down) {
4980 mBroadcastWakeLock.acquire();
4981 Message msg = mHandler.obtainMessage(MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK,
4982 keyguardActive ? 1 : 0, 0);
4983 msg.setAsynchronous(true);
4984 msg.sendToTarget();
4985 }
4986 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004987 }
Jeff Brown26875502014-01-30 21:47:47 -08004988
Jeff Brownbae8e772014-06-12 19:59:45 -07004989 if (useHapticFeedback) {
4990 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
4991 }
4992
Jeff Brown26875502014-01-30 21:47:47 -08004993 if (isWakeKey) {
Jeff Brown13f00f02014-10-31 14:45:50 -07004994 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey);
Jeff Brown26875502014-01-30 21:47:47 -08004995 }
Bryce Lee584a4452014-10-21 15:55:55 -07004996
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004997 return result;
4998 }
4999
Jeff Brown1c2e4942012-11-06 16:32:01 -08005000 /**
Jeff Brown13f00f02014-10-31 14:45:50 -07005001 * Returns true if the key can have global actions attached to it.
5002 * We reserve all power management keys for the system since they require
5003 * very careful handling.
5004 */
5005 private static boolean isValidGlobalKey(int keyCode) {
5006 switch (keyCode) {
5007 case KeyEvent.KEYCODE_POWER:
5008 case KeyEvent.KEYCODE_WAKEUP:
5009 case KeyEvent.KEYCODE_SLEEP:
5010 return false;
5011 default:
5012 return true;
5013 }
5014 }
5015
5016 /**
Jeff Brown1c2e4942012-11-06 16:32:01 -08005017 * When the screen is off we ignore some keys that might otherwise typically
5018 * be considered wake keys. We filter them out here.
5019 *
5020 * {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it
5021 * is always considered a wake key.
5022 */
5023 private boolean isWakeKeyWhenScreenOff(int keyCode) {
5024 switch (keyCode) {
5025 // ignore volume keys unless docked
5026 case KeyEvent.KEYCODE_VOLUME_UP:
5027 case KeyEvent.KEYCODE_VOLUME_DOWN:
5028 case KeyEvent.KEYCODE_VOLUME_MUTE:
5029 return mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED;
5030
5031 // ignore media and camera keys
5032 case KeyEvent.KEYCODE_MUTE:
5033 case KeyEvent.KEYCODE_HEADSETHOOK:
5034 case KeyEvent.KEYCODE_MEDIA_PLAY:
5035 case KeyEvent.KEYCODE_MEDIA_PAUSE:
5036 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
5037 case KeyEvent.KEYCODE_MEDIA_STOP:
5038 case KeyEvent.KEYCODE_MEDIA_NEXT:
5039 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
5040 case KeyEvent.KEYCODE_MEDIA_REWIND:
5041 case KeyEvent.KEYCODE_MEDIA_RECORD:
5042 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09005043 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK:
Jeff Brown1c2e4942012-11-06 16:32:01 -08005044 case KeyEvent.KEYCODE_CAMERA:
5045 return false;
5046 }
5047 return true;
5048 }
5049
5050
Jeff Brown56194eb2011-03-02 19:23:13 -08005051 /** {@inheritDoc} */
5052 @Override
Michael Wright70af00a2014-09-03 19:30:20 -07005053 public int interceptMotionBeforeQueueingNonInteractive(long whenNanos, int policyFlags) {
5054 if ((policyFlags & FLAG_WAKE) != 0) {
Bryce Lee5c138322014-11-03 08:26:09 -08005055 if (wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotion)) {
5056 return 0;
5057 }
Michael Wright70af00a2014-09-03 19:30:20 -07005058 }
Bryce Lee5c138322014-11-03 08:26:09 -08005059
Michael Wright70af00a2014-09-03 19:30:20 -07005060 if (shouldDispatchInputWhenNonInteractive()) {
5061 return ACTION_PASS_TO_USER;
5062 }
Bryce Lee5c138322014-11-03 08:26:09 -08005063
Bryce Lee812d7022014-11-10 13:33:28 -08005064 // If we have not passed the action up and we are in theater mode without dreaming,
5065 // there will be no dream to intercept the touch and wake into ambient. The device should
5066 // wake up in this case.
5067 if (isTheaterModeEnabled() && (policyFlags & FLAG_WAKE) != 0) {
5068 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotionWhenNotDreaming);
5069 }
5070
Jeff Brown037c33e2014-04-09 00:31:55 -07005071 return 0;
Jeff Brown56194eb2011-03-02 19:23:13 -08005072 }
5073
Michael Wright70af00a2014-09-03 19:30:20 -07005074 private boolean shouldDispatchInputWhenNonInteractive() {
Bryce Lee5c138322014-11-03 08:26:09 -08005075 // Send events to keyguard while the screen is on.
Jim Millerab954542014-10-10 18:21:49 -07005076 if (isKeyguardShowingAndNotOccluded() && mDisplay != null
5077 && mDisplay.getState() != Display.STATE_OFF) {
Bryce Lee5c138322014-11-03 08:26:09 -08005078 return true;
5079 }
5080
5081 // Send events to a dozing dream even if the screen is off since the dream
5082 // is in control of the state of the screen.
5083 IDreamManager dreamManager = getDreamManager();
5084
5085 try {
5086 if (dreamManager != null && dreamManager.isDreaming()) {
5087 return true;
5088 }
5089 } catch (RemoteException e) {
5090 Slog.e(TAG, "RemoteException when checking if dreaming", e);
5091 }
5092
5093 // Otherwise, consume events since the user can't see what is being
5094 // interacted with.
5095 return false;
Michael Wright70af00a2014-09-03 19:30:20 -07005096 }
5097
RoboErik001c59c2015-01-26 15:53:51 -08005098 private void dispatchDirectAudioEvent(KeyEvent event) {
5099 if (event.getAction() != KeyEvent.ACTION_DOWN) {
5100 return;
5101 }
5102 int keyCode = event.getKeyCode();
John Spurlockb94f2d62015-03-17 14:11:57 -04005103 int flags = AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_PLAY_SOUND
5104 | AudioManager.FLAG_FROM_KEY;
RoboErik001c59c2015-01-26 15:53:51 -08005105 String pkgName = mContext.getOpPackageName();
5106 switch (keyCode) {
5107 case KeyEvent.KEYCODE_VOLUME_UP:
5108 try {
John Spurlockee5ad722015-03-03 16:17:21 -05005109 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_RAISE,
John Spurlock90874332015-03-10 16:00:54 -04005110 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005111 } catch (RemoteException e) {
5112 Log.e(TAG, "Error dispatching volume up in dispatchTvAudioEvent.", e);
5113 }
5114 break;
5115 case KeyEvent.KEYCODE_VOLUME_DOWN:
5116 try {
John Spurlockee5ad722015-03-03 16:17:21 -05005117 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_LOWER,
John Spurlock90874332015-03-10 16:00:54 -04005118 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005119 } catch (RemoteException e) {
5120 Log.e(TAG, "Error dispatching volume down in dispatchTvAudioEvent.", e);
5121 }
5122 break;
5123 case KeyEvent.KEYCODE_VOLUME_MUTE:
5124 try {
5125 if (event.getRepeatCount() == 0) {
John Spurlockee5ad722015-03-03 16:17:21 -05005126 getAudioService().adjustSuggestedStreamVolume(
5127 AudioManager.ADJUST_TOGGLE_MUTE,
John Spurlock90874332015-03-10 16:00:54 -04005128 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005129 }
5130 } catch (RemoteException e) {
5131 Log.e(TAG, "Error dispatching mute in dispatchTvAudioEvent.", e);
5132 }
5133 break;
5134 }
5135 }
5136
Jeff Brown40013652012-05-16 21:22:36 -07005137 void dispatchMediaKeyWithWakeLock(KeyEvent event) {
5138 if (DEBUG_INPUT) {
5139 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: " + event);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005140 }
5141
Jeff Brown40013652012-05-16 21:22:36 -07005142 if (mHavePendingMediaKeyRepeatWithWakeLock) {
5143 if (DEBUG_INPUT) {
5144 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: canceled repeat");
5145 }
5146
5147 mHandler.removeMessages(MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK);
5148 mHavePendingMediaKeyRepeatWithWakeLock = false;
5149 mBroadcastWakeLock.release(); // pending repeat was holding onto the wake lock
5150 }
5151
5152 dispatchMediaKeyWithWakeLockToAudioService(event);
5153
5154 if (event.getAction() == KeyEvent.ACTION_DOWN
5155 && event.getRepeatCount() == 0) {
5156 mHavePendingMediaKeyRepeatWithWakeLock = true;
5157
5158 Message msg = mHandler.obtainMessage(
5159 MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK, event);
5160 msg.setAsynchronous(true);
5161 mHandler.sendMessageDelayed(msg, ViewConfiguration.getKeyRepeatTimeout());
5162 } else {
5163 mBroadcastWakeLock.release();
5164 }
5165 }
5166
5167 void dispatchMediaKeyRepeatWithWakeLock(KeyEvent event) {
5168 mHavePendingMediaKeyRepeatWithWakeLock = false;
5169
5170 KeyEvent repeatEvent = KeyEvent.changeTimeRepeat(event,
5171 SystemClock.uptimeMillis(), 1, event.getFlags() | KeyEvent.FLAG_LONG_PRESS);
5172 if (DEBUG_INPUT) {
5173 Slog.d(TAG, "dispatchMediaKeyRepeatWithWakeLock: " + repeatEvent);
5174 }
5175
5176 dispatchMediaKeyWithWakeLockToAudioService(repeatEvent);
5177 mBroadcastWakeLock.release();
5178 }
5179
5180 void dispatchMediaKeyWithWakeLockToAudioService(KeyEvent event) {
5181 if (ActivityManagerNative.isSystemReady()) {
RoboErik430fc482014-06-12 15:49:20 -07005182 MediaSessionLegacyHelper.getHelper(mContext).sendMediaButtonEvent(event, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005183 }
5184 }
5185
Michael Wright869a67c2014-08-26 19:33:06 -07005186 void launchVoiceAssistWithWakeLock(boolean keyguardActive) {
5187 Intent voiceIntent =
5188 new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
5189 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, keyguardActive);
Bart Sears8b1c27c2015-03-18 23:51:02 +00005190 startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
Michael Wright869a67c2014-08-26 19:33:06 -07005191 mBroadcastWakeLock.release();
5192 }
5193
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005194 BroadcastReceiver mDockReceiver = new BroadcastReceiver() {
Craig Mautnereee29c42013-01-17 14:44:34 -08005195 @Override
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005196 public void onReceive(Context context, Intent intent) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07005197 if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) {
5198 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
5199 Intent.EXTRA_DOCK_STATE_UNDOCKED);
Daniel Sandler6396c722013-04-16 20:19:09 -04005200 } else {
5201 try {
5202 IUiModeManager uiModeService = IUiModeManager.Stub.asInterface(
5203 ServiceManager.getService(Context.UI_MODE_SERVICE));
5204 mUiMode = uiModeService.getCurrentModeType();
5205 } catch (RemoteException e) {
5206 }
Dianne Hackborn80fa1662009-10-07 14:02:10 -07005207 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005208 updateRotation(true);
Craig Mautnereee29c42013-01-17 14:44:34 -08005209 synchronized (mLock) {
5210 updateOrientationListenerLp();
5211 }
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005212 }
5213 };
5214
Jeff Brown6aaf2952012-10-05 16:01:08 -07005215 BroadcastReceiver mDreamReceiver = new BroadcastReceiver() {
5216 @Override
5217 public void onReceive(Context context, Intent intent) {
5218 if (Intent.ACTION_DREAMING_STARTED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005219 if (mKeyguardDelegate != null) {
5220 mKeyguardDelegate.onDreamingStarted();
Jeff Brown6aaf2952012-10-05 16:01:08 -07005221 }
5222 } else if (Intent.ACTION_DREAMING_STOPPED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005223 if (mKeyguardDelegate != null) {
5224 mKeyguardDelegate.onDreamingStopped();
Jeff Brown6aaf2952012-10-05 16:01:08 -07005225 }
5226 }
5227 }
5228 };
5229
Christopher Tate5e08af02012-09-21 17:17:22 -07005230 BroadcastReceiver mMultiuserReceiver = new BroadcastReceiver() {
5231 @Override
5232 public void onReceive(Context context, Intent intent) {
5233 if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) {
5234 // tickle the settings observer: this first ensures that we're
5235 // observing the relevant settings for the newly-active user,
5236 // and then updates our own bookkeeping based on the now-
5237 // current user.
5238 mSettingsObserver.onChange(false);
John Spurlockce479d82012-11-29 09:52:21 -05005239
5240 // force a re-application of focused window sysui visibility.
5241 // the window may never have been shown for this user
5242 // e.g. the keyguard when going through the new-user setup flow
John Spurlock04db1762013-05-13 12:46:41 -04005243 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
John Spurlockce479d82012-11-29 09:52:21 -05005244 mLastSystemUiFlags = 0;
5245 updateSystemUiVisibilityLw();
5246 }
Christopher Tate5e08af02012-09-21 17:17:22 -07005247 }
5248 }
5249 };
5250
Adrian Roosddc8b272015-05-21 16:28:27 -07005251 private final Runnable mHiddenNavPanic = new Runnable() {
John Spurlockd9b70bd2014-02-06 17:02:44 -05005252 @Override
5253 public void run() {
Adrian Roosddc8b272015-05-21 16:28:27 -07005254 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
5255 if (!isUserSetupComplete()) {
5256 // Swipe-up for navigation bar is disabled during setup
5257 return;
5258 }
5259 mPendingPanicGestureUptime = SystemClock.uptimeMillis();
5260 mNavigationBarController.showTransient();
5261 }
John Spurlockd9b70bd2014-02-06 17:02:44 -05005262 }
5263 };
5264
John Spurlocke1f366f2013-08-05 12:22:40 -04005265 private void requestTransientBars(WindowState swipeTarget) {
John Spurlock04db1762013-05-13 12:46:41 -04005266 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Maurice Lam99c6e072014-04-28 18:24:28 -07005267 if (!isUserSetupComplete()) {
5268 // Swipe-up for navigation bar is disabled during setup
5269 return;
5270 }
John Spurlock27735a42013-08-14 17:57:38 -04005271 boolean sb = mStatusBarController.checkShowTransientBarLw();
5272 boolean nb = mNavigationBarController.checkShowTransientBarLw();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005273 if (sb || nb) {
Adrian Roos62b65e42015-02-25 18:05:34 +01005274 // Don't show status bar when swiping on already visible navigation bar
5275 if (!nb && swipeTarget == mNavigationBar) {
John Spurlocke1f366f2013-08-05 12:22:40 -04005276 if (DEBUG) Slog.d(TAG, "Not showing transient bar, wrong swipe target");
John Spurlockad3e6cb2013-04-30 08:47:43 -04005277 return;
5278 }
John Spurlock27735a42013-08-14 17:57:38 -04005279 if (sb) mStatusBarController.showTransient();
5280 if (nb) mNavigationBarController.showTransient();
John Spurlockf1a36642013-10-12 17:50:42 -04005281 mImmersiveModeConfirmation.confirmCurrentPrompt();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005282 updateSystemUiVisibilityLw();
John Spurlock32beb2c2013-03-11 10:16:47 -04005283 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04005284 }
5285 }
5286
Jeff Brown3ee549c2014-09-22 20:14:39 -07005287 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07005288 @Override
Jeff Brown416c49c2015-05-26 19:50:18 -07005289 public void startedGoingToSleep(int why) {
5290 if (DEBUG_WAKEUP) Slog.i(TAG, "Started going to sleep... (why=" + why + ")");
Jorim Jaggid175b6c2015-05-27 15:39:09 -07005291 if (mKeyguardDelegate != null) {
5292 mKeyguardDelegate.onStartedGoingToSleep(why);
5293 }
Jeff Brown416c49c2015-05-26 19:50:18 -07005294 }
5295
5296 // Called on the PowerManager's Notifier thread.
5297 @Override
5298 public void finishedGoingToSleep(int why) {
Dianne Hackborn74489012009-03-24 20:50:09 -07005299 EventLog.writeEvent(70000, 0);
Jeff Brown416c49c2015-05-26 19:50:18 -07005300 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished going to sleep... (why=" + why + ")");
Jeff Brown3ee549c2014-09-22 20:14:39 -07005301
5302 // We must get this work done here because the power manager will drop
5303 // the wake lock and let the system suspend once this function returns.
The Android Open Source Project0727d222009-03-11 12:11:58 -07005304 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005305 mAwake = false;
5306 mKeyguardDrawComplete = false;
Jeff Browna20dda42014-05-27 20:57:24 -07005307 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005308 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05005309 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005310 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005311 if (mKeyguardDelegate != null) {
Jorim Jaggid175b6c2015-05-27 15:39:09 -07005312 mKeyguardDelegate.onFinishedGoingToSleep(why);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005313 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005314 }
5315
Jeff Brown3ee549c2014-09-22 20:14:39 -07005316 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07005317 @Override
Jeff Brown416c49c2015-05-26 19:50:18 -07005318 public void startedWakingUp() {
Dianne Hackborn74489012009-03-24 20:50:09 -07005319 EventLog.writeEvent(70000, 1);
Jeff Brown416c49c2015-05-26 19:50:18 -07005320 if (DEBUG_WAKEUP) Slog.i(TAG, "Started waking up...");
Craig Mautner8a0da012014-05-31 15:13:37 -07005321
Jeff Brown3ee549c2014-09-22 20:14:39 -07005322 // Since goToSleep performs these functions synchronously, we must
5323 // do the same here. We cannot post this work to a handler because
5324 // that might cause it to become reordered with respect to what
5325 // may happen in a future call to goToSleep.
The Android Open Source Project0727d222009-03-11 12:11:58 -07005326 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005327 mAwake = true;
5328 mKeyguardDrawComplete = false;
5329 if (mKeyguardDelegate != null) {
5330 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
5331 mHandler.sendEmptyMessageDelayed(MSG_KEYGUARD_DRAWN_TIMEOUT, 1000);
5332 }
5333
Jeff Browna20dda42014-05-27 20:57:24 -07005334 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005335 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05005336 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005337 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005338
Jim Miller5ecd8112013-01-09 18:50:26 -08005339 if (mKeyguardDelegate != null) {
Jorim Jaggid175b6c2015-05-27 15:39:09 -07005340 mKeyguardDelegate.onStartedWakingUp(mKeyguardDelegateCallback);
Jeff Brown36c4db82014-09-19 12:05:31 -07005341 // ... eventually calls finishKeyguardDrawn
Jeff Brownc38c9be2012-10-04 13:16:19 -07005342 } else {
Craig Mautner8a0da012014-05-31 15:13:37 -07005343 if (DEBUG_WAKEUP) Slog.d(TAG, "null mKeyguardDelegate: setting mKeyguardDrawComplete.");
Jeff Brown36c4db82014-09-19 12:05:31 -07005344 finishKeyguardDrawn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07005345 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005346 }
5347
Jeff Brown416c49c2015-05-26 19:50:18 -07005348 // Called on the PowerManager's Notifier thread.
5349 @Override
5350 public void finishedWakingUp() {
5351 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished waking up...");
5352 }
5353
5354 private void wakeUpFromPowerKey(long eventTime) {
5355 wakeUp(eventTime, mAllowTheaterModeWakeFromPowerKey);
5356 }
5357
5358 private boolean wakeUp(long wakeTime, boolean wakeInTheaterMode) {
5359 if (!wakeInTheaterMode && isTheaterModeEnabled()) {
5360 return false;
5361 }
5362
5363 mPowerManager.wakeUp(wakeTime);
5364 return true;
5365 }
5366
Jeff Brown36c4db82014-09-19 12:05:31 -07005367 private void finishKeyguardDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005368 synchronized (mLock) {
5369 if (!mAwake || mKeyguardDrawComplete) {
5370 return; // spurious
5371 }
5372
Jeff Brown36c4db82014-09-19 12:05:31 -07005373 mKeyguardDrawComplete = true;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005374 if (mKeyguardDelegate != null) {
5375 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
5376 }
5377 }
5378
5379 finishScreenTurningOn();
5380 }
5381
5382 // Called on the DisplayManager's DisplayPowerController thread.
5383 @Override
5384 public void screenTurnedOff() {
5385 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turned off...");
5386
5387 synchronized (mLock) {
5388 mScreenOnEarly = false;
5389 mScreenOnFully = false;
5390 mWindowManagerDrawComplete = false;
5391 mScreenOnListener = null;
5392 updateOrientationListenerLp();
Jeff Brown36c4db82014-09-19 12:05:31 -07005393 }
5394 }
5395
Jeff Brown3ee549c2014-09-22 20:14:39 -07005396 // Called on the DisplayManager's DisplayPowerController thread.
Jeff Brown36c4db82014-09-19 12:05:31 -07005397 @Override
5398 public void screenTurningOn(final ScreenOnListener screenOnListener) {
Jeff Brown36c4db82014-09-19 12:05:31 -07005399 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turning on...");
Jeff Brown36c4db82014-09-19 12:05:31 -07005400
Jeff Brown3ee549c2014-09-22 20:14:39 -07005401 synchronized (mLock) {
5402 mScreenOnEarly = true;
5403 mScreenOnFully = false;
5404 mWindowManagerDrawComplete = false;
5405 mScreenOnListener = screenOnListener;
5406 updateOrientationListenerLp();
5407 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005408
Craig Mautnerc3daedd2014-09-13 11:17:23 -07005409 mWindowManagerInternal.waitForAllWindowsDrawn(mWindowManagerDrawCallback,
5410 WAITING_FOR_DRAWN_TIMEOUT);
Jeff Brown36c4db82014-09-19 12:05:31 -07005411 // ... eventually calls finishWindowsDrawn
5412 }
5413
Jeff Brown36c4db82014-09-19 12:05:31 -07005414 private void finishWindowsDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005415 synchronized (mLock) {
5416 if (!mScreenOnEarly || mWindowManagerDrawComplete) {
5417 return; // spurious
5418 }
5419
Jeff Brown36c4db82014-09-19 12:05:31 -07005420 mWindowManagerDrawComplete = true;
Jeff Brown36c4db82014-09-19 12:05:31 -07005421 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005422
5423 finishScreenTurningOn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07005424 }
5425
Craig Mautner8a0da012014-05-31 15:13:37 -07005426 private void finishScreenTurningOn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005427 final ScreenOnListener listener;
5428 final boolean enableScreen;
Jeff Brown36c4db82014-09-19 12:05:31 -07005429 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005430 if (DEBUG_WAKEUP) Slog.d(TAG,
5431 "finishScreenTurningOn: mAwake=" + mAwake
5432 + ", mScreenOnEarly=" + mScreenOnEarly
5433 + ", mScreenOnFully=" + mScreenOnFully
5434 + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete
5435 + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete);
5436
5437 if (mScreenOnFully || !mScreenOnEarly || !mWindowManagerDrawComplete
5438 || (mAwake && !mKeyguardDrawComplete)) {
5439 return; // spurious or not ready yet
Jeff Brown36c4db82014-09-19 12:05:31 -07005440 }
5441
Jeff Brown3ee549c2014-09-22 20:14:39 -07005442 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished screen turning on...");
5443 listener = mScreenOnListener;
Craig Mautner13f6ea72014-06-23 14:57:02 -07005444 mScreenOnListener = null;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005445 mScreenOnFully = true;
5446
5447 // Remember the first time we draw the keyguard so we know when we're done with
5448 // the main part of booting and can enable the screen and hide boot messages.
5449 if (!mKeyguardDrawnOnce && mAwake) {
5450 mKeyguardDrawnOnce = true;
5451 enableScreen = true;
5452 if (mBootMessageNeedsHiding) {
5453 mBootMessageNeedsHiding = false;
5454 hideBootMessages();
5455 }
5456 } else {
5457 enableScreen = false;
5458 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005459 }
5460
Jeff Brown3ee549c2014-09-22 20:14:39 -07005461 if (listener != null) {
5462 listener.onScreenOn();
5463 }
Jeff Brown4fc45272012-10-10 18:28:14 -07005464
Jeff Brown3ee549c2014-09-22 20:14:39 -07005465 if (enableScreen) {
5466 try {
5467 mWindowManager.enableScreenIfNeeded();
5468 } catch (RemoteException unhandled) {
Jeff Brown36c4db82014-09-19 12:05:31 -07005469 }
Craig Mautnera631d492014-08-05 15:16:01 -07005470 }
5471 }
5472
5473 private void handleHideBootMessage() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005474 synchronized (mLock) {
5475 if (!mKeyguardDrawnOnce) {
5476 mBootMessageNeedsHiding = true;
5477 return; // keyguard hasn't drawn the first time yet, not done booting
5478 }
Craig Mautnera631d492014-08-05 15:16:01 -07005479 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005480
5481 if (mBootMsgDialog != null) {
5482 if (DEBUG_WAKEUP) Slog.d(TAG, "handleHideBootMessage: dismissing");
5483 mBootMsgDialog.dismiss();
5484 mBootMsgDialog = null;
Craig Mautnera631d492014-08-05 15:16:01 -07005485 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005486 }
5487
5488 @Override
Jeff Brown3ee549c2014-09-22 20:14:39 -07005489 public boolean isScreenOn() {
5490 return mScreenOnFully;
Dianne Hackborn08743722009-12-21 12:16:51 -08005491 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005492
Dianne Hackborn08743722009-12-21 12:16:51 -08005493 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005494 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005495 public void enableKeyguard(boolean enabled) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005496 if (mKeyguardDelegate != null) {
5497 mKeyguardDelegate.setKeyguardEnabled(enabled);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005498 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005499 }
5500
5501 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005502 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005503 public void exitKeyguardSecurely(OnKeyguardExitResult callback) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005504 if (mKeyguardDelegate != null) {
5505 mKeyguardDelegate.verifyUnlock(callback);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005506 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005507 }
5508
Jim Millerab954542014-10-10 18:21:49 -07005509 private boolean isKeyguardShowingAndNotOccluded() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005510 if (mKeyguardDelegate == null) return false;
Jim Millerab954542014-10-10 18:21:49 -07005511 return mKeyguardDelegate.isShowing() && !mKeyguardOccluded;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005512 }
5513
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005514 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005515 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005516 public boolean isKeyguardLocked() {
5517 return keyguardOn();
5518 }
5519
5520 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005521 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005522 public boolean isKeyguardSecure() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005523 if (mKeyguardDelegate == null) return false;
5524 return mKeyguardDelegate.isSecure();
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005525 }
5526
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005527 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005528 @Override
Adrian Roos461829d2015-06-03 14:41:18 -07005529 public boolean isKeyguardShowingOrOccluded() {
5530 return mKeyguardDelegate == null ? false : mKeyguardDelegate.isShowing();
5531 }
5532
5533 /** {@inheritDoc} */
5534 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005535 public boolean inKeyguardRestrictedKeyInputMode() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005536 if (mKeyguardDelegate == null) return false;
5537 return mKeyguardDelegate.isInputRestricted();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005538 }
5539
Jose Lima9546b202014-07-02 17:21:51 -07005540 @Override
Dianne Hackborn90c52de2011-09-23 12:57:44 -07005541 public void dismissKeyguardLw() {
RoboErik8a2cfc32014-05-16 11:19:38 -07005542 if (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()) {
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07005543 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.dismissKeyguardLw");
Daniel Sandler1ce804392012-11-07 15:07:12 -05005544 mHandler.post(new Runnable() {
Jose Lima9546b202014-07-02 17:21:51 -07005545 @Override
Daniel Sandler1ce804392012-11-07 15:07:12 -05005546 public void run() {
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02005547 // ask the keyguard to prompt the user to authenticate if necessary
5548 mKeyguardDelegate.dismiss();
5549 }
5550 });
5551 }
5552 }
5553
5554 public void notifyActivityDrawnForKeyguardLw() {
5555 if (mKeyguardDelegate != null) {
5556 mHandler.post(new Runnable() {
5557 @Override
5558 public void run() {
5559 mKeyguardDelegate.onActivityDrawn();
Daniel Sandler1ce804392012-11-07 15:07:12 -05005560 }
5561 });
Dianne Hackborn90c52de2011-09-23 12:57:44 -07005562 }
5563 }
5564
Jorim Jaggicff0acb2014-03-31 16:35:15 +02005565 @Override
5566 public boolean isKeyguardDrawnLw() {
5567 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005568 return mKeyguardDrawnOnce;
Jorim Jaggicff0acb2014-03-31 16:35:15 +02005569 }
5570 }
5571
Jorim Jaggi0d674622014-05-21 01:34:15 +02005572 @Override
Jorim Jaggie29b2db2014-05-30 23:17:03 +02005573 public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) {
Jorim Jaggi0d674622014-05-21 01:34:15 +02005574 if (mKeyguardDelegate != null) {
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07005575 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.startKeyguardExitAnimation");
Jorim Jaggie29b2db2014-05-30 23:17:03 +02005576 mKeyguardDelegate.startKeyguardExitAnimation(startTime, fadeoutDuration);
Jorim Jaggi0d674622014-05-21 01:34:15 +02005577 }
5578 }
5579
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005580 void sendCloseSystemWindows() {
Jorim Jaggib10e33f2015-02-04 21:57:40 +01005581 PhoneWindow.sendCloseSystemWindows(mContext, null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005582 }
5583
5584 void sendCloseSystemWindows(String reason) {
Jorim Jaggib10e33f2015-02-04 21:57:40 +01005585 PhoneWindow.sendCloseSystemWindows(mContext, reason);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005586 }
Mitsuru Oshima831d0d92009-06-16 18:27:18 -07005587
Jeff Brown01a98dd2011-09-20 15:08:29 -07005588 @Override
5589 public int rotationForOrientationLw(int orientation, int lastRotation) {
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005590 if (false) {
5591 Slog.v(TAG, "rotationForOrientationLw(orient="
5592 + orientation + ", last=" + lastRotation
5593 + "); user=" + mUserRotation + " "
5594 + ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED)
5595 ? "USER_ROTATION_LOCKED" : "")
5596 );
5597 }
5598
Craig Mautner46ac6fa2013-08-01 10:06:34 -07005599 if (mForceDefaultOrientation) {
5600 return Surface.ROTATION_0;
5601 }
5602
The Android Open Source Project0727d222009-03-11 12:11:58 -07005603 synchronized (mLock) {
Jeff Brownc0347aa2011-09-23 17:26:09 -07005604 int sensorRotation = mOrientationListener.getProposedRotation(); // may be -1
5605 if (sensorRotation < 0) {
Jeff Brown0f862b42012-09-27 21:11:01 -07005606 sensorRotation = lastRotation;
Jeff Brownc0347aa2011-09-23 17:26:09 -07005607 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005608
Jeff Browndec6cf42011-11-15 14:08:20 -08005609 final int preferredRotation;
Jeff Brown2e7760e2012-04-11 15:14:55 -07005610 if (mLidState == LID_OPEN && mLidOpenRotation >= 0) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005611 // Ignore sensor when lid switch is open and rotation is forced.
5612 preferredRotation = mLidOpenRotation;
5613 } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR
Jeff Brownc0347aa2011-09-23 17:26:09 -07005614 && (mCarDockEnablesAccelerometer || mCarDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005615 // Ignore sensor when in car dock unless explicitly enabled.
5616 // This case can override the behavior of NOSENSOR, and can also
5617 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07005618 preferredRotation = mCarDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07005619 ? sensorRotation : mCarDockRotation;
Jeff Brown1a693182011-11-08 14:44:16 -08005620 } else if ((mDockMode == Intent.EXTRA_DOCK_STATE_DESK
5621 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
5622 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK)
Jeff Brownc0347aa2011-09-23 17:26:09 -07005623 && (mDeskDockEnablesAccelerometer || mDeskDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005624 // Ignore sensor when in desk dock unless explicitly enabled.
5625 // This case can override the behavior of NOSENSOR, and can also
5626 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07005627 preferredRotation = mDeskDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07005628 ? sensorRotation : mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -07005629 } else if (mHdmiPlugged && mDemoHdmiRotationLock) {
5630 // Ignore sensor when plugged into HDMI when demo HDMI rotation lock enabled.
Jeff Browneb3e4b92011-12-06 19:54:24 -08005631 // Note that the dock orientation overrides the HDMI orientation.
Jeff Brownc82c89ed2013-04-17 17:18:15 -07005632 preferredRotation = mDemoHdmiRotation;
5633 } else if (mHdmiPlugged && mDockMode == Intent.EXTRA_DOCK_STATE_UNDOCKED
5634 && mUndockedHdmiRotation >= 0) {
5635 // Ignore sensor when plugged into HDMI and an undocked orientation has
5636 // been specified in the configuration (only for legacy devices without
5637 // full multi-display support).
5638 // Note that the dock orientation overrides the HDMI orientation.
5639 preferredRotation = mUndockedHdmiRotation;
Chong Zhangae6119ff2014-11-11 18:54:39 -08005640 } else if (mDemoRotationLock) {
5641 // Ignore sensor when demo rotation lock is enabled.
5642 // Note that the dock orientation and HDMI rotation lock override this.
5643 preferredRotation = mDemoRotation;
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005644 } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED) {
5645 // Application just wants to remain locked in the last rotation.
5646 preferredRotation = lastRotation;
Jeff Brownbcdfc622014-03-06 19:13:04 -08005647 } else if (!mSupportAutoRotation) {
5648 // If we don't support auto-rotation then bail out here and ignore
5649 // the sensor and any rotation lock settings.
5650 preferredRotation = -1;
Jeff Brown207673cd2012-06-05 17:47:11 -07005651 } else if ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE
Jeff Brown01a98dd2011-09-20 15:08:29 -07005652 && (orientation == ActivityInfo.SCREEN_ORIENTATION_USER
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005653 || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
5654 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
5655 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
5656 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER))
Jeff Brown01a98dd2011-09-20 15:08:29 -07005657 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
5658 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
5659 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
5660 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) {
5661 // Otherwise, use sensor only if requested by the application or enabled
5662 // by default for USER or UNSPECIFIED modes. Does not apply to NOSENSOR.
Jeff Brownd3187e32011-09-21 19:26:44 -07005663 if (mAllowAllRotations < 0) {
5664 // Can't read this during init() because the context doesn't
5665 // have display metrics at that time so we cannot determine
5666 // tablet vs. phone then.
5667 mAllowAllRotations = mContext.getResources().getBoolean(
5668 com.android.internal.R.bool.config_allowAllRotations) ? 1 : 0;
5669 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005670 if (sensorRotation != Surface.ROTATION_180
Jeff Brownd3187e32011-09-21 19:26:44 -07005671 || mAllowAllRotations == 1
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005672 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
5673 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005674 preferredRotation = sensorRotation;
5675 } else {
5676 preferredRotation = lastRotation;
5677 }
Jeff Brown207673cd2012-06-05 17:47:11 -07005678 } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED
5679 && orientation != ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) {
5680 // Apply rotation lock. Does not apply to NOSENSOR.
5681 // The idea is that the user rotation expresses a weak preference for the direction
5682 // of gravity and as NOSENSOR is never affected by gravity, then neither should
5683 // NOSENSOR be affected by rotation lock (although it will be affected by docks).
Jeff Brown4dfce202011-10-05 12:00:10 -07005684 preferredRotation = mUserRotation;
Jeff Browndec6cf42011-11-15 14:08:20 -08005685 } else {
5686 // No overriding preference.
5687 // We will do exactly what the application asked us to do.
5688 preferredRotation = -1;
Jeff Brown01a98dd2011-09-20 15:08:29 -07005689 }
5690
Dianne Hackborne5439f22010-10-02 16:53:50 -07005691 switch (orientation) {
5692 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08005693 // Return portrait unless overridden.
5694 if (isAnyPortrait(preferredRotation)) {
5695 return preferredRotation;
5696 }
Dianne Hackborne5439f22010-10-02 16:53:50 -07005697 return mPortraitRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005698
Jeff Brown01a98dd2011-09-20 15:08:29 -07005699 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08005700 // Return landscape unless overridden.
5701 if (isLandscapeOrSeascape(preferredRotation)) {
5702 return preferredRotation;
5703 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005704 return mLandscapeRotation;
5705
5706 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08005707 // Return reverse portrait unless overridden.
5708 if (isAnyPortrait(preferredRotation)) {
5709 return preferredRotation;
5710 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005711 return mUpsideDownRotation;
5712
5713 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08005714 // Return seascape unless overridden.
5715 if (isLandscapeOrSeascape(preferredRotation)) {
5716 return preferredRotation;
5717 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005718 return mSeascapeRotation;
5719
5720 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005721 case ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE:
Jeff Brown01a98dd2011-09-20 15:08:29 -07005722 // Return either landscape rotation.
5723 if (isLandscapeOrSeascape(preferredRotation)) {
5724 return preferredRotation;
5725 }
5726 if (isLandscapeOrSeascape(lastRotation)) {
Jeff Brown4519f072011-01-23 13:16:01 -08005727 return lastRotation;
5728 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005729 return mLandscapeRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005730
Jeff Brown01a98dd2011-09-20 15:08:29 -07005731 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005732 case ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT:
Jeff Brown01a98dd2011-09-20 15:08:29 -07005733 // Return either portrait rotation.
5734 if (isAnyPortrait(preferredRotation)) {
5735 return preferredRotation;
5736 }
5737 if (isAnyPortrait(lastRotation)) {
5738 return lastRotation;
5739 }
5740 return mPortraitRotation;
5741
5742 default:
Jeff Brown4dfce202011-10-05 12:00:10 -07005743 // For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR,
5744 // just return the preferred orientation we already calculated.
Jeff Brown01a98dd2011-09-20 15:08:29 -07005745 if (preferredRotation >= 0) {
5746 return preferredRotation;
5747 }
Dianne Hackborndacea8c2011-04-21 17:26:39 -07005748 return Surface.ROTATION_0;
Daniel Sandlere7e5ac22011-02-22 16:10:21 -05005749 }
5750 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07005751 }
5752
Jeff Brown01a98dd2011-09-20 15:08:29 -07005753 @Override
5754 public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation) {
5755 switch (orientation) {
5756 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
5757 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
5758 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
5759 return isAnyPortrait(rotation);
5760
5761 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
5762 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
5763 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
5764 return isLandscapeOrSeascape(rotation);
5765
5766 default:
5767 return true;
5768 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07005769 }
5770
Jeff Brownc0347aa2011-09-23 17:26:09 -07005771 @Override
5772 public void setRotationLw(int rotation) {
5773 mOrientationListener.setCurrentRotation(rotation);
5774 }
5775
Jeff Brown01a98dd2011-09-20 15:08:29 -07005776 private boolean isLandscapeOrSeascape(int rotation) {
5777 return rotation == mLandscapeRotation || rotation == mSeascapeRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005778 }
5779
Jeff Brown01a98dd2011-09-20 15:08:29 -07005780 private boolean isAnyPortrait(int rotation) {
5781 return rotation == mPortraitRotation || rotation == mUpsideDownRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005782 }
5783
Jose Lima9546b202014-07-02 17:21:51 -07005784 @Override
Svetoslav Ganov80943d82013-01-02 10:25:37 -08005785 public int getUserRotationMode() {
5786 return Settings.System.getIntForUser(mContext.getContentResolver(),
Brett Chabot7e55c402013-05-16 19:38:08 -07005787 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
5788 WindowManagerPolicy.USER_ROTATION_FREE :
5789 WindowManagerPolicy.USER_ROTATION_LOCKED;
Svetoslav Ganov80943d82013-01-02 10:25:37 -08005790 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005791
5792 // User rotation: to be used when all else fails in assigning an orientation to the device
Jose Lima9546b202014-07-02 17:21:51 -07005793 @Override
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005794 public void setUserRotationMode(int mode, int rot) {
5795 ContentResolver res = mContext.getContentResolver();
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005796
5797 // mUserRotationMode and mUserRotation will be assigned by the content observer
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005798 if (mode == WindowManagerPolicy.USER_ROTATION_LOCKED) {
Christopher Tate5e08af02012-09-21 17:17:22 -07005799 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005800 Settings.System.USER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005801 rot,
5802 UserHandle.USER_CURRENT);
5803 Settings.System.putIntForUser(res,
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005804 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005805 0,
5806 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005807 } else {
Christopher Tate5e08af02012-09-21 17:17:22 -07005808 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005809 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005810 1,
5811 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005812 }
5813 }
5814
Jose Lima9546b202014-07-02 17:21:51 -07005815 @Override
Jeff Brownac143512012-04-05 18:57:33 -07005816 public void setSafeMode(boolean safeMode) {
5817 mSafeMode = safeMode;
5818 performHapticFeedbackLw(null, safeMode
5819 ? HapticFeedbackConstants.SAFE_MODE_ENABLED
5820 : HapticFeedbackConstants.SAFE_MODE_DISABLED, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005821 }
Craig Mautnereda67292013-04-28 13:50:14 -07005822
Dianne Hackborn181ceb52009-08-27 22:16:40 -07005823 static long[] getLongIntArray(Resources r, int resid) {
5824 int[] ar = r.getIntArray(resid);
5825 if (ar == null) {
5826 return null;
5827 }
5828 long[] out = new long[ar.length];
5829 for (int i=0; i<ar.length; i++) {
5830 out[i] = ar[i];
5831 }
5832 return out;
5833 }
Craig Mautnereda67292013-04-28 13:50:14 -07005834
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005835 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07005836 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005837 public void systemReady() {
Jim Millerab954542014-10-10 18:21:49 -07005838 mKeyguardDelegate = new KeyguardServiceDelegate(mContext);
Mike Lockwooded8902d2013-11-15 11:01:47 -08005839 mKeyguardDelegate.onSystemReady();
5840
Michael Wright3818c922014-09-02 13:59:07 -07005841 readCameraLensCoverState();
Jeff Brown4f5fa282014-06-12 19:19:15 -07005842 updateUiMode();
Dianne Hackbornb1a79802009-09-29 15:18:31 -07005843 synchronized (mLock) {
5844 updateOrientationListenerLp();
Dianne Hackbornc777e072010-02-12 13:07:59 -08005845 mSystemReady = true;
5846 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07005847 @Override
Dianne Hackbornc777e072010-02-12 13:07:59 -08005848 public void run() {
5849 updateSettings();
5850 }
5851 });
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005852 }
5853 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07005854
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005855 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005856 @Override
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005857 public void systemBooted() {
Jim Millere5f910a2013-10-16 18:15:46 -07005858 if (mKeyguardDelegate != null) {
Jason Monk5eeebf52014-09-26 12:36:51 -04005859 mKeyguardDelegate.bindService(mContext);
Jim Millere5f910a2013-10-16 18:15:46 -07005860 mKeyguardDelegate.onBootCompleted();
5861 }
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005862 synchronized (mLock) {
5863 mSystemBooted = true;
5864 }
Jeff Brown416c49c2015-05-26 19:50:18 -07005865 startedWakingUp();
Jeff Brown36c4db82014-09-19 12:05:31 -07005866 screenTurningOn(null);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005867 }
5868
Dianne Hackborn661cd522011-08-22 00:26:20 -07005869 ProgressDialog mBootMsgDialog = null;
5870
5871 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005872 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07005873 public void showBootMessage(final CharSequence msg, final boolean always) {
5874 mHandler.post(new Runnable() {
5875 @Override public void run() {
5876 if (mBootMsgDialog == null) {
Craig Stout4c0cb8a2014-04-04 13:03:10 -07005877 int theme;
5878 if (mContext.getPackageManager().hasSystemFeature(
5879 PackageManager.FEATURE_WATCH)) {
5880 theme = com.android.internal.R.style.Theme_Micro_Dialog_Alert;
5881 } else if (mContext.getPackageManager().hasSystemFeature(
5882 PackageManager.FEATURE_TELEVISION)) {
5883 theme = com.android.internal.R.style.Theme_Leanback_Dialog_Alert;
5884 } else {
5885 theme = 0;
5886 }
Vinod Krishnanfa8fc412014-04-18 14:35:53 -07005887
5888 mBootMsgDialog = new ProgressDialog(mContext, theme) {
Dianne Hackborn295e3c22011-08-25 13:19:08 -07005889 // This dialog will consume all events coming in to
5890 // it, to avoid it trying to do things too early in boot.
5891 @Override public boolean dispatchKeyEvent(KeyEvent event) {
5892 return true;
5893 }
5894 @Override public boolean dispatchKeyShortcutEvent(KeyEvent event) {
5895 return true;
5896 }
5897 @Override public boolean dispatchTouchEvent(MotionEvent ev) {
5898 return true;
5899 }
5900 @Override public boolean dispatchTrackballEvent(MotionEvent ev) {
5901 return true;
5902 }
5903 @Override public boolean dispatchGenericMotionEvent(MotionEvent ev) {
5904 return true;
5905 }
5906 @Override public boolean dispatchPopulateAccessibilityEvent(
5907 AccessibilityEvent event) {
5908 return true;
5909 }
5910 };
Jeff Hao9f60c082014-10-28 18:51:07 -07005911 if (mContext.getPackageManager().isUpgrade()) {
5912 mBootMsgDialog.setTitle(R.string.android_upgrading_title);
5913 } else {
5914 mBootMsgDialog.setTitle(R.string.android_start_title);
5915 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07005916 mBootMsgDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
5917 mBootMsgDialog.setIndeterminate(true);
5918 mBootMsgDialog.getWindow().setType(
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07005919 WindowManager.LayoutParams.TYPE_BOOT_PROGRESS);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005920 mBootMsgDialog.getWindow().addFlags(
5921 WindowManager.LayoutParams.FLAG_DIM_BEHIND
5922 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
5923 mBootMsgDialog.getWindow().setDimAmount(1);
Dianne Hackbornd9efb952011-12-07 14:56:51 -08005924 WindowManager.LayoutParams lp = mBootMsgDialog.getWindow().getAttributes();
5925 lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
5926 mBootMsgDialog.getWindow().setAttributes(lp);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005927 mBootMsgDialog.setCancelable(false);
5928 mBootMsgDialog.show();
5929 }
5930 mBootMsgDialog.setMessage(msg);
5931 }
5932 });
5933 }
5934
5935 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005936 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07005937 public void hideBootMessages() {
Craig Mautnera631d492014-08-05 15:16:01 -07005938 mHandler.sendEmptyMessage(MSG_HIDE_BOOT_MESSAGE);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005939 }
5940
Mike Lockwood28569302010-01-28 11:54:40 -05005941 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005942 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05005943 public void userActivity() {
Dianne Hackborndf89e652011-10-06 22:35:11 -07005944 // ***************************************
5945 // NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
5946 // ***************************************
5947 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
5948 // WITH ITS LOCKS HELD.
5949 //
5950 // This code must be VERY careful about the locks
5951 // it acquires.
5952 // In fact, the current code acquires way too many,
5953 // and probably has lurking deadlocks.
5954
Mike Lockwood28569302010-01-28 11:54:40 -05005955 synchronized (mScreenLockTimeout) {
5956 if (mLockScreenTimerActive) {
5957 // reset the timer
5958 mHandler.removeCallbacks(mScreenLockTimeout);
5959 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
5960 }
5961 }
Daniel Sandler0601eb72011-04-13 01:01:32 -04005962 }
5963
Adam Cohenf7522022012-10-03 20:03:18 -07005964 class ScreenLockTimeout implements Runnable {
5965 Bundle options;
5966
5967 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05005968 public void run() {
5969 synchronized (this) {
5970 if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard");
Jim Miller5ecd8112013-01-09 18:50:26 -08005971 if (mKeyguardDelegate != null) {
5972 mKeyguardDelegate.doKeyguardTimeout(options);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005973 }
Mike Lockwood28569302010-01-28 11:54:40 -05005974 mLockScreenTimerActive = false;
Adam Cohenf7522022012-10-03 20:03:18 -07005975 options = null;
Mike Lockwood28569302010-01-28 11:54:40 -05005976 }
5977 }
Mike Lockwood28569302010-01-28 11:54:40 -05005978
Adam Cohenf7522022012-10-03 20:03:18 -07005979 public void setLockOptions(Bundle options) {
5980 this.options = options;
5981 }
5982 }
5983
5984 ScreenLockTimeout mScreenLockTimeout = new ScreenLockTimeout();
5985
Jose Lima9546b202014-07-02 17:21:51 -07005986 @Override
Adam Cohenf7522022012-10-03 20:03:18 -07005987 public void lockNow(Bundle options) {
Jim Miller93c518e2012-01-17 15:55:31 -08005988 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null);
5989 mHandler.removeCallbacks(mScreenLockTimeout);
Adam Cohenf7522022012-10-03 20:03:18 -07005990 if (options != null) {
5991 // In case multiple calls are made to lockNow, we don't wipe out the options
5992 // until the runnable actually executes.
5993 mScreenLockTimeout.setLockOptions(options);
5994 }
Jim Miller93c518e2012-01-17 15:55:31 -08005995 mHandler.post(mScreenLockTimeout);
5996 }
5997
Mike Lockwood28569302010-01-28 11:54:40 -05005998 private void updateLockScreenTimeout() {
5999 synchronized (mScreenLockTimeout) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07006000 boolean enable = (mAllowLockscreenWhenOn && mAwake &&
Jim Miller5ecd8112013-01-09 18:50:26 -08006001 mKeyguardDelegate != null && mKeyguardDelegate.isSecure());
Mike Lockwood28569302010-01-28 11:54:40 -05006002 if (mLockScreenTimerActive != enable) {
6003 if (enable) {
6004 if (localLOGV) Log.v(TAG, "setting lockscreen timer");
6005 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
6006 } else {
6007 if (localLOGV) Log.v(TAG, "clearing lockscreen timer");
6008 mHandler.removeCallbacks(mScreenLockTimeout);
6009 }
6010 mLockScreenTimerActive = enable;
6011 }
6012 }
6013 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006014
Jeff Brown061ea992015-04-17 19:55:47 -07006015 private void updateDreamingSleepToken(boolean acquire) {
6016 if (acquire) {
6017 if (mDreamingSleepToken == null) {
6018 mDreamingSleepToken = mActivityManagerInternal.acquireSleepToken("Dream");
6019 }
6020 } else {
6021 if (mDreamingSleepToken != null) {
6022 mDreamingSleepToken.release();
6023 }
6024 }
6025 }
6026
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006027 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07006028 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006029 public void enableScreenAfterBoot() {
6030 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07006031 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07006032 updateRotation(true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006033 }
Dianne Hackbornf54c8f92009-09-19 14:03:57 -07006034
Jeff Brownc458ce92012-04-30 14:58:40 -07006035 private void applyLidSwitchState() {
Jeff Brownc458ce92012-04-30 14:58:40 -07006036 if (mLidState == LID_CLOSED && mLidControlsSleep) {
Jeff Brown6d8fd272014-05-20 21:24:38 -07006037 mPowerManager.goToSleep(SystemClock.uptimeMillis(),
Jeff Brownc12035c2014-08-13 18:52:25 -07006038 PowerManager.GO_TO_SLEEP_REASON_LID_SWITCH,
Jeff Brown6d8fd272014-05-20 21:24:38 -07006039 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
Jeff Brownc458ce92012-04-30 14:58:40 -07006040 }
Jeff Browna20dda42014-05-27 20:57:24 -07006041
6042 synchronized (mLock) {
6043 updateWakeGestureListenerLp();
6044 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006045 }
6046
Jeff Brown4f5fa282014-06-12 19:19:15 -07006047 void updateUiMode() {
6048 if (mUiModeManager == null) {
6049 mUiModeManager = IUiModeManager.Stub.asInterface(
6050 ServiceManager.getService(Context.UI_MODE_SERVICE));
6051 }
6052 try {
6053 mUiMode = mUiModeManager.getCurrentModeType();
6054 } catch (RemoteException e) {
6055 }
6056 }
6057
Jeff Brown01a98dd2011-09-20 15:08:29 -07006058 void updateRotation(boolean alwaysSendConfiguration) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006059 try {
6060 //set orientation on WindowManager
Dianne Hackbornf87d1962012-04-04 12:48:24 -07006061 mWindowManager.updateRotation(alwaysSendConfiguration, false);
6062 } catch (RemoteException e) {
6063 // Ignore
6064 }
6065 }
6066
6067 void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) {
6068 try {
6069 //set orientation on WindowManager
6070 mWindowManager.updateRotation(alwaysSendConfiguration, forceRelayout);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006071 } catch (RemoteException e) {
6072 // Ignore
6073 }
6074 }
6075
Daniel Sandler6396c722013-04-16 20:19:09 -04006076 /**
6077 * Return an Intent to launch the currently active dock app as home. Returns
6078 * null if the standard home should be launched, which is the case if any of the following is
6079 * true:
6080 * <ul>
6081 * <li>The device is not in either car mode or desk mode
6082 * <li>The device is in car mode but ENABLE_CAR_DOCK_HOME_CAPTURE is false
6083 * <li>The device is in desk mode but ENABLE_DESK_DOCK_HOME_CAPTURE is false
6084 * <li>The device is in car mode but there's no CAR_DOCK app with METADATA_DOCK_HOME
6085 * <li>The device is in desk mode but there's no DESK_DOCK app with METADATA_DOCK_HOME
6086 * </ul>
Craig Mautnereda67292013-04-28 13:50:14 -07006087 * @return A dock intent.
Daniel Sandler6396c722013-04-16 20:19:09 -04006088 */
6089 Intent createHomeDockIntent() {
6090 Intent intent = null;
6091
6092 // What home does is based on the mode, not the dock state. That
6093 // is, when in car mode you should be taken to car home regardless
6094 // of whether we are actually in a car dock.
6095 if (mUiMode == Configuration.UI_MODE_TYPE_CAR) {
6096 if (ENABLE_CAR_DOCK_HOME_CAPTURE) {
6097 intent = mCarDockIntent;
6098 }
6099 } else if (mUiMode == Configuration.UI_MODE_TYPE_DESK) {
6100 if (ENABLE_DESK_DOCK_HOME_CAPTURE) {
6101 intent = mDeskDockIntent;
6102 }
Jeff Brown4f5fa282014-06-12 19:19:15 -07006103 } else if (mUiMode == Configuration.UI_MODE_TYPE_WATCH
6104 && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
6105 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK
6106 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK)) {
6107 // Always launch dock home from home when watch is docked, if it exists.
6108 intent = mDeskDockIntent;
Daniel Sandler6396c722013-04-16 20:19:09 -04006109 }
6110
6111 if (intent == null) {
6112 return null;
6113 }
6114
6115 ActivityInfo ai = null;
6116 ResolveInfo info = mContext.getPackageManager().resolveActivityAsUser(
6117 intent,
John Spurlockf56bef12013-07-09 09:51:46 -04006118 PackageManager.MATCH_DEFAULT_ONLY | PackageManager.GET_META_DATA,
Craig Mautnerd625ab22013-09-06 13:40:31 -07006119 mCurrentUserId);
Daniel Sandler6396c722013-04-16 20:19:09 -04006120 if (info != null) {
6121 ai = info.activityInfo;
6122 }
6123 if (ai != null
6124 && ai.metaData != null
6125 && ai.metaData.getBoolean(Intent.METADATA_DOCK_HOME)) {
6126 intent = new Intent(intent);
6127 intent.setClassName(ai.packageName, ai.name);
6128 return intent;
6129 }
6130
6131 return null;
6132 }
6133
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00006134 void startDockOrHome(boolean fromHomeKey, boolean awakenFromDreams) {
6135 if (awakenFromDreams) {
6136 awakenDreams();
6137 }
Daniel Sandler6396c722013-04-16 20:19:09 -04006138
6139 Intent dock = createHomeDockIntent();
6140 if (dock != null) {
6141 try {
Bryce Lee01b0c5f2015-02-05 18:24:04 -08006142 if (fromHomeKey) {
6143 dock.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
6144 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00006145 startActivityAsUser(dock, UserHandle.CURRENT);
Daniel Sandler6396c722013-04-16 20:19:09 -04006146 return;
6147 } catch (ActivityNotFoundException e) {
6148 }
6149 }
6150
Bryce Lee01b0c5f2015-02-05 18:24:04 -08006151 Intent intent;
6152
6153 if (fromHomeKey) {
6154 intent = new Intent(mHomeIntent);
6155 intent.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
6156 } else {
6157 intent = mHomeIntent;
6158 }
6159
Bryce Lee9fc0b6f2015-03-19 21:37:45 +00006160 startActivityAsUser(intent, UserHandle.CURRENT);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006161 }
Craig Mautnereda67292013-04-28 13:50:14 -07006162
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006163 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006164 * goes to the home screen
6165 * @return whether it did anything
6166 */
6167 boolean goHome() {
Bart Sears8b1c27c2015-03-18 23:51:02 +00006168 if (!isUserSetupComplete()) {
6169 Slog.i(TAG, "Not going home because user setup is in progress.");
6170 return false;
6171 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006172 if (false) {
6173 // This code always brings home to the front.
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07006174 try {
6175 ActivityManagerNative.getDefault().stopAppSwitches();
6176 } catch (RemoteException e) {
6177 }
Dianne Hackborn94a679d2009-07-28 17:51:07 -07006178 sendCloseSystemWindows();
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00006179 startDockOrHome(false /*fromHomeKey*/, true /* awakenFromDreams */);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006180 } else {
6181 // This code brings home to the front or, if it is already
6182 // at the front, puts the device to sleep.
6183 try {
Wink Savilled2e6a332010-02-12 12:12:06 -08006184 if (SystemProperties.getInt("persist.sys.uts-test-mode", 0) == 1) {
6185 /// Roll back EndcallBehavior as the cupcake design to pass P1 lab entry.
6186 Log.d(TAG, "UTS-TEST-MODE");
6187 } else {
6188 ActivityManagerNative.getDefault().stopAppSwitches();
6189 sendCloseSystemWindows();
Daniel Sandler6396c722013-04-16 20:19:09 -04006190 Intent dock = createHomeDockIntent();
6191 if (dock != null) {
6192 int result = ActivityManagerNative.getDefault()
6193 .startActivityAsUser(null, null, dock,
6194 dock.resolveTypeIfNeeded(mContext.getContentResolver()),
6195 null, null, 0,
6196 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07006197 null, null, UserHandle.USER_CURRENT);
Daniel Sandler6396c722013-04-16 20:19:09 -04006198 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
6199 return false;
6200 }
6201 }
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006202 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006203 int result = ActivityManagerNative.getDefault()
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006204 .startActivityAsUser(null, null, mHomeIntent,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006205 mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()),
Dianne Hackborna4972e92012-03-14 10:38:05 -07006206 null, null, 0,
6207 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07006208 null, null, UserHandle.USER_CURRENT);
Dianne Hackborna4972e92012-03-14 10:38:05 -07006209 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006210 return false;
6211 }
6212 } catch (RemoteException ex) {
6213 // bummer, the activity manager, which is in this process, is dead
6214 }
6215 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006216 return true;
6217 }
Craig Mautnereda67292013-04-28 13:50:14 -07006218
6219 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07006220 public void setCurrentOrientationLw(int newOrientation) {
6221 synchronized (mLock) {
6222 if (newOrientation != mCurrentAppOrientation) {
6223 mCurrentAppOrientation = newOrientation;
6224 updateOrientationListenerLp();
6225 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006226 }
6227 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006228
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07006229 private void performAuditoryFeedbackForAccessibilityIfNeed() {
6230 if (!isGlobalAccessibilityGestureEnabled()) {
6231 return;
6232 }
6233 AudioManager audioManager = (AudioManager) mContext.getSystemService(
6234 Context.AUDIO_SERVICE);
6235 if (audioManager.isSilentMode()) {
6236 return;
6237 }
6238 Ringtone ringTone = RingtoneManager.getRingtone(mContext,
6239 Settings.System.DEFAULT_NOTIFICATION_URI);
6240 ringTone.setStreamType(AudioManager.STREAM_MUSIC);
6241 ringTone.play();
6242 }
Craig Mautnereda67292013-04-28 13:50:14 -07006243
Bryce Lee584a4452014-10-21 15:55:55 -07006244 private boolean isTheaterModeEnabled() {
6245 return Settings.Global.getInt(mContext.getContentResolver(),
6246 Settings.Global.THEATER_MODE_ON, 0) == 1;
6247 }
6248
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07006249 private boolean isGlobalAccessibilityGestureEnabled() {
6250 return Settings.Global.getInt(mContext.getContentResolver(),
6251 Settings.Global.ENABLE_ACCESSIBILITY_GLOBAL_GESTURE_ENABLED, 0) == 1;
6252 }
6253
Craig Mautnereda67292013-04-28 13:50:14 -07006254 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07006255 public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) {
Svetoslav Ganov96179212012-10-10 14:17:45 -07006256 if (!mVibrator.hasVibrator()) {
6257 return false;
6258 }
Christopher Tate5e08af02012-09-21 17:17:22 -07006259 final boolean hapticsDisabled = Settings.System.getIntForUser(mContext.getContentResolver(),
6260 Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) == 0;
Jeff Brown82379ba2014-07-25 19:03:28 -07006261 if (hapticsDisabled && !always) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006262 return false;
6263 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006264 long[] pattern = null;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006265 switch (effectId) {
6266 case HapticFeedbackConstants.LONG_PRESS:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006267 pattern = mLongPressVibePattern;
6268 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006269 case HapticFeedbackConstants.VIRTUAL_KEY:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006270 pattern = mVirtualKeyVibePattern;
6271 break;
6272 case HapticFeedbackConstants.KEYBOARD_TAP:
6273 pattern = mKeyboardTapVibePattern;
6274 break;
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07006275 case HapticFeedbackConstants.CLOCK_TICK:
6276 pattern = mClockTickVibePattern;
6277 break;
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07006278 case HapticFeedbackConstants.CALENDAR_DATE:
6279 pattern = mCalendarDateVibePattern;
6280 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006281 case HapticFeedbackConstants.SAFE_MODE_DISABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006282 pattern = mSafeModeDisabledVibePattern;
6283 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006284 case HapticFeedbackConstants.SAFE_MODE_ENABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006285 pattern = mSafeModeEnabledVibePattern;
6286 break;
Mady Mellore8608912015-06-05 09:02:55 -07006287 case HapticFeedbackConstants.CONTEXT_CLICK:
6288 pattern = mContextClickVibePattern;
Mady Mellore82067b2015-04-30 09:58:35 -07006289 break;
Amith Yamasanic33cb712010-02-10 15:21:49 -08006290 default:
6291 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006292 }
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006293 int owningUid;
6294 String owningPackage;
6295 if (win != null) {
6296 owningUid = win.getOwningUid();
6297 owningPackage = win.getOwningPackage();
6298 } else {
6299 owningUid = android.os.Process.myUid();
Dianne Hackborn95d78532013-09-11 09:51:14 -07006300 owningPackage = mContext.getOpPackageName();
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006301 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006302 if (pattern.length == 1) {
6303 // One-shot vibration
John Spurlock7b414672014-07-18 13:02:39 -04006304 mVibrator.vibrate(owningUid, owningPackage, pattern[0], VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08006305 } else {
6306 // Pattern vibration
John Spurlock7b414672014-07-18 13:02:39 -04006307 mVibrator.vibrate(owningUid, owningPackage, pattern, -1, VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08006308 }
6309 return true;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006310 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07006311
6312 @Override
6313 public void keepScreenOnStartedLw() {
Daniel Sandler0601eb72011-04-13 01:01:32 -04006314 }
6315
Jeff Brownc38c9be2012-10-04 13:16:19 -07006316 @Override
6317 public void keepScreenOnStoppedLw() {
Jim Millerab954542014-10-10 18:21:49 -07006318 if (isKeyguardShowingAndNotOccluded()) {
Jim Miller25190572013-02-28 17:36:24 -08006319 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006320 }
6321 }
Mike Lockwoodfcb39242009-10-21 23:01:07 -04006322
Dianne Hackborndf89e652011-10-06 22:35:11 -07006323 private int updateSystemUiVisibilityLw() {
Joe Onorato664644d2011-01-23 17:53:23 -08006324 // If there is no window focused, there will be nobody to handle the events
6325 // anyway, so just hang on in whatever state we're in until things settle down.
Adrian Roos53f28ec2014-10-29 17:26:12 +01006326 final WindowState win = mFocusedWindow != null ? mFocusedWindow
6327 : mTopFullscreenOpaqueWindowState;
John Spurlock79da8332013-09-20 12:04:47 -04006328 if (win == null) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006329 return 0;
6330 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01006331 if ((win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 && mHideLockScreen == true) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07006332 // We are updating at a point where the keyguard has gotten
6333 // focus, but we were last in a state where the top window is
6334 // hiding it. This is probably because the keyguard as been
6335 // shown while the top window was displayed, so we want to ignore
6336 // it here because this is just a very transient change and it
6337 // will quickly lose focus once it correctly gets hidden.
6338 return 0;
6339 }
John Spurlock32beb2c2013-03-11 10:16:47 -04006340
John Spurlock1db8b682014-02-18 11:18:59 -05006341 int tmpVisibility = PolicyControl.getSystemUiVisibility(win, null)
Dianne Hackborne26ab702011-10-16 13:21:33 -07006342 & ~mResettingSystemUiFlags
6343 & ~mForceClearedSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04006344 if (mForcingShowNavBar && win.getSurfaceLayer() < mForcingShowNavBarLayer) {
John Spurlockc6d1c602014-01-17 15:22:06 -05006345 tmpVisibility &= ~PolicyControl.adjustClearableFlags(win, View.SYSTEM_UI_CLEARABLE_FLAGS);
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08006346 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01006347 tmpVisibility = updateLightStatusBarLw(tmpVisibility);
John Spurlock79da8332013-09-20 12:04:47 -04006348 final int visibility = updateSystemBarsLw(win, mLastSystemUiFlags, tmpVisibility);
John Spurlockad3e6cb2013-04-30 08:47:43 -04006349 final int diff = visibility ^ mLastSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04006350 final boolean needsMenu = win.getNeedsMenuLw(mTopFullscreenOpaqueWindowState);
Dianne Hackborne0f085d2011-11-30 18:41:15 -08006351 if (diff == 0 && mLastFocusNeedsMenu == needsMenu
John Spurlock79da8332013-09-20 12:04:47 -04006352 && mFocusedApp == win.getAppToken()) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006353 return 0;
6354 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07006355 mLastSystemUiFlags = visibility;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08006356 mLastFocusNeedsMenu = needsMenu;
John Spurlock79da8332013-09-20 12:04:47 -04006357 mFocusedApp = win.getAppToken();
Dianne Hackborndf89e652011-10-06 22:35:11 -07006358 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07006359 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07006360 public void run() {
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006361 try {
6362 IStatusBarService statusbar = getStatusBarService();
6363 if (statusbar != null) {
Adrian Roos53f28ec2014-10-29 17:26:12 +01006364 statusbar.setSystemUiVisibility(visibility, 0xffffffff, win.toString());
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006365 statusbar.topAppWindowChanged(needsMenu);
Joe Onorato664644d2011-01-23 17:53:23 -08006366 }
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006367 } catch (RemoteException e) {
6368 // re-acquire status bar service next time it is needed.
6369 mStatusBarService = null;
Joe Onorato664644d2011-01-23 17:53:23 -08006370 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07006371 }
6372 });
6373 return diff;
Joe Onorato664644d2011-01-23 17:53:23 -08006374 }
6375
Adrian Rooscd3884d2015-02-18 17:25:23 +01006376 private int updateLightStatusBarLw(int vis) {
6377 WindowState statusColorWin = isStatusBarKeyguard() && !mHideLockScreen
6378 ? mStatusBar
6379 : mTopFullscreenOpaqueOrDimmingWindowState;
6380
6381 if (statusColorWin != null) {
6382 if (statusColorWin == mTopFullscreenOpaqueWindowState) {
6383 // If the top fullscreen-or-dimming window is also the top fullscreen, respect
6384 // its light flag.
6385 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6386 vis |= PolicyControl.getSystemUiVisibility(statusColorWin, null)
6387 & View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6388 } else if (statusColorWin != null && statusColorWin.isDimming()) {
6389 // Otherwise if it's dimming, clear the light flag.
6390 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6391 }
6392 }
6393 return vis;
6394 }
6395
John Spurlock79da8332013-09-20 12:04:47 -04006396 private int updateSystemBarsLw(WindowState win, int oldVis, int vis) {
John Spurlockbd957402013-10-03 11:38:39 -04006397 // apply translucent bar vis flags
Jorim Jaggi380ecb82014-03-14 17:25:20 +01006398 WindowState transWin = isStatusBarKeyguard() && !mHideLockScreen
6399 ? mStatusBar
John Spurlockbd957402013-10-03 11:38:39 -04006400 : mTopFullscreenOpaqueWindowState;
6401 vis = mStatusBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
6402 vis = mNavigationBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
6403
John Spurlock27735a42013-08-14 17:57:38 -04006404 // prevent status bar interaction from clearing certain flags
Selim Cinekf83e8242015-05-19 18:08:14 -07006405 int type = win.getAttrs().type;
6406 boolean statusBarHasFocus = type == TYPE_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04006407 if (statusBarHasFocus && !isStatusBarKeyguard()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04006408 int flags = View.SYSTEM_UI_FLAG_FULLSCREEN
6409 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlockcfc359a2013-09-05 10:42:03 -04006410 | View.SYSTEM_UI_FLAG_IMMERSIVE
Jorim Jaggi73fef8d2015-02-16 17:32:28 +01006411 | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
6412 | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04006413 if (mHideLockScreen) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01006414 flags |= View.STATUS_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSLUCENT;
6415 }
John Spurlockbd957402013-10-03 11:38:39 -04006416 vis = (vis & ~flags) | (oldVis & flags);
John Spurlockad3e6cb2013-04-30 08:47:43 -04006417 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04006418
Adrian Roos4fb3ee32014-08-22 19:29:09 +02006419 if (!areTranslucentBarsAllowed() && transWin != mStatusBar) {
Adrian Roosea562512014-05-05 13:33:03 +02006420 vis &= ~(View.NAVIGATION_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSLUCENT
6421 | View.SYSTEM_UI_TRANSPARENT);
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006422 }
6423
John Spurlock27735a42013-08-14 17:57:38 -04006424 // update status bar
John Spurlockf1a36642013-10-12 17:50:42 -04006425 boolean immersiveSticky =
6426 (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
John Spurlock27735a42013-08-14 17:57:38 -04006427 boolean hideStatusBarWM =
John Spurlockbd957402013-10-03 11:38:39 -04006428 mTopFullscreenOpaqueWindowState != null &&
John Spurlockc6d1c602014-01-17 15:22:06 -05006429 (PolicyControl.getWindowFlags(mTopFullscreenOpaqueWindowState, null)
John Spurlock27735a42013-08-14 17:57:38 -04006430 & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0;
6431 boolean hideStatusBarSysui =
6432 (vis & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04006433 boolean hideNavBarSysui =
6434 (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006435
John Spurlock27735a42013-08-14 17:57:38 -04006436 boolean transientStatusBarAllowed =
6437 mStatusBar != null && (
6438 hideStatusBarWM
John Spurlockf1a36642013-10-12 17:50:42 -04006439 || (hideStatusBarSysui && immersiveSticky)
John Spurlock27735a42013-08-14 17:57:38 -04006440 || statusBarHasFocus);
6441
John Spurlockf1a36642013-10-12 17:50:42 -04006442 boolean transientNavBarAllowed =
6443 mNavigationBar != null &&
6444 hideNavBarSysui && immersiveSticky;
6445
Adrian Roosddc8b272015-05-21 16:28:27 -07006446 final long now = SystemClock.uptimeMillis();
6447 final boolean pendingPanic = mPendingPanicGestureUptime != 0
6448 && now - mPendingPanicGestureUptime <= PANIC_GESTURE_EXPIRATION;
6449 if (pendingPanic && hideNavBarSysui && !isStatusBarKeyguard() && mKeyguardDrawComplete) {
6450 // The user performed the panic gesture recently, we're about to hide the bars,
6451 // we're no longer on the Keyguard and the screen is ready. We can now request the bars.
6452 mPendingPanicGestureUptime = 0;
6453 mStatusBarController.showTransient();
6454 mNavigationBarController.showTransient();
6455 }
6456
John Spurlockf25706f2013-11-07 18:02:43 -05006457 boolean denyTransientStatus = mStatusBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04006458 && !transientStatusBarAllowed && hideStatusBarSysui;
John Spurlockf25706f2013-11-07 18:02:43 -05006459 boolean denyTransientNav = mNavigationBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04006460 && !transientNavBarAllowed;
6461 if (denyTransientStatus || denyTransientNav) {
John Spurlock27735a42013-08-14 17:57:38 -04006462 // clear the clearable flags instead
John Spurlockf1a36642013-10-12 17:50:42 -04006463 clearClearableFlagsLw();
tiger_huangc58d7562014-10-23 20:24:19 +08006464 vis &= ~View.SYSTEM_UI_CLEARABLE_FLAGS;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006465 }
John Spurlock27735a42013-08-14 17:57:38 -04006466
Selim Cinekf98702e2015-05-20 22:48:40 -07006467 final boolean immersive = (vis & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
6468 immersiveSticky = (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
6469 final boolean navAllowedHidden = immersive || immersiveSticky;
6470
Selim Cinekd6623612015-05-22 18:56:22 -07006471 if (hideNavBarSysui && !navAllowedHidden && windowTypeToLayerLw(win.getBaseType())
6472 > windowTypeToLayerLw(TYPE_INPUT_CONSUMER)) {
Selim Cinekf98702e2015-05-20 22:48:40 -07006473 // We can't hide the navbar from this window otherwise the input consumer would not get
6474 // the input events.
6475 vis = (vis & ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
6476 }
6477
John Spurlock27735a42013-08-14 17:57:38 -04006478 vis = mStatusBarController.updateVisibilityLw(transientStatusBarAllowed, oldVis, vis);
6479
6480 // update navigation bar
John Spurlockf1a36642013-10-12 17:50:42 -04006481 boolean oldImmersiveMode = isImmersiveMode(oldVis);
6482 boolean newImmersiveMode = isImmersiveMode(vis);
6483 if (win != null && oldImmersiveMode != newImmersiveMode) {
John Spurlock79da8332013-09-20 12:04:47 -04006484 final String pkg = win.getOwningPackage();
Maurice Lam99c6e072014-04-28 18:24:28 -07006485 mImmersiveModeConfirmation.immersiveModeChanged(pkg, newImmersiveMode,
6486 isUserSetupComplete());
John Spurlock34e13d92013-08-10 06:52:28 -04006487 }
John Spurlock27735a42013-08-14 17:57:38 -04006488
John Spurlockf1a36642013-10-12 17:50:42 -04006489 vis = mNavigationBarController.updateVisibilityLw(transientNavBarAllowed, oldVis, vis);
6490
John Spurlocke1f366f2013-08-05 12:22:40 -04006491 return vis;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006492 }
6493
John Spurlockf1a36642013-10-12 17:50:42 -04006494 private void clearClearableFlagsLw() {
6495 int newVal = mResettingSystemUiFlags | View.SYSTEM_UI_CLEARABLE_FLAGS;
6496 if (newVal != mResettingSystemUiFlags) {
6497 mResettingSystemUiFlags = newVal;
6498 mWindowManagerFuncs.reevaluateStatusBarVisibility();
6499 }
6500 }
6501
6502 private boolean isImmersiveMode(int vis) {
6503 final int flags = View.SYSTEM_UI_FLAG_IMMERSIVE | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
John Spurlock34e13d92013-08-10 06:52:28 -04006504 return mNavigationBar != null
6505 && (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0
Daniel Sandler900ece52013-10-18 15:53:27 -04006506 && (vis & flags) != 0
6507 && canHideNavigationBar();
John Spurlock34e13d92013-08-10 06:52:28 -04006508 }
6509
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006510 /**
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04006511 * @return whether the navigation or status bar can be made translucent
6512 *
6513 * This should return true unless touch exploration is not enabled or
6514 * R.boolean.config_enableTranslucentDecor is false.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006515 */
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04006516 private boolean areTranslucentBarsAllowed() {
Svetoslav8e3feb12014-02-24 13:46:47 -08006517 return mTranslucentDecorEnabled
6518 && !mAccessibilityManager.isTouchExplorationEnabled();
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006519 }
6520
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04006521 // Use this instead of checking config_showNavigationBar so that it can be consistently
6522 // overridden by qemu.hw.mainkeys in the emulator.
Craig Mautnereda67292013-04-28 13:50:14 -07006523 @Override
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04006524 public boolean hasNavigationBar() {
6525 return mHasNavigationBar;
6526 }
6527
satok1bc0a492012-04-25 22:47:12 +09006528 @Override
6529 public void setLastInputMethodWindowLw(WindowState ime, WindowState target) {
6530 mLastInputMethodWindow = ime;
6531 mLastInputMethodTargetWindow = target;
6532 }
6533
Craig Mautnerf1b67412012-09-19 13:18:29 -07006534 @Override
Satoshi Kataoka658c7b82013-10-10 17:03:51 +09006535 public int getInputMethodWindowVisibleHeightLw() {
6536 return mDockBottom - mCurBottom;
6537 }
6538
6539 @Override
Craig Mautnerf1b67412012-09-19 13:18:29 -07006540 public void setCurrentUserLw(int newUserId) {
Craig Mautnerd625ab22013-09-06 13:40:31 -07006541 mCurrentUserId = newUserId;
Jim Miller5ecd8112013-01-09 18:50:26 -08006542 if (mKeyguardDelegate != null) {
6543 mKeyguardDelegate.setCurrentUser(newUserId);
Craig Mautnerf1b67412012-09-19 13:18:29 -07006544 }
John Spurlock13451a22012-09-28 14:40:41 -04006545 if (mStatusBarService != null) {
6546 try {
6547 mStatusBarService.setCurrentUser(newUserId);
6548 } catch (RemoteException e) {
6549 // oh well
6550 }
6551 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006552 setLastInputMethodWindowLw(null, null);
Craig Mautnerf1b67412012-09-19 13:18:29 -07006553 }
6554
6555 @Override
Svetoslav Ganov545252f2012-12-10 18:29:24 -08006556 public boolean canMagnifyWindow(int windowType) {
6557 switch (windowType) {
6558 case WindowManager.LayoutParams.TYPE_INPUT_METHOD:
6559 case WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG:
6560 case WindowManager.LayoutParams.TYPE_NAVIGATION_BAR:
6561 case WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY: {
6562 return false;
6563 }
6564 }
6565 return true;
6566 }
6567
6568 @Override
6569 public boolean isTopLevelWindow(int windowType) {
6570 if (windowType >= WindowManager.LayoutParams.FIRST_SUB_WINDOW
6571 && windowType <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
6572 return (windowType == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG);
6573 }
6574 return true;
6575 }
6576
Jim Miller4eeb4f62012-11-08 00:04:29 -08006577 @Override
Jeff Brownd7a04de2012-06-17 14:17:52 -07006578 public void dump(String prefix, PrintWriter pw, String[] args) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006579 pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07006580 pw.print(" mSystemReady="); pw.print(mSystemReady);
6581 pw.print(" mSystemBooted="); pw.println(mSystemBooted);
Jeff Brown2e7760e2012-04-11 15:14:55 -07006582 pw.print(prefix); pw.print("mLidState="); pw.print(mLidState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006583 pw.print(" mLidOpenRotation="); pw.print(mLidOpenRotation);
Michael Wright3818c922014-09-02 13:59:07 -07006584 pw.print(" mCameraLensCoverState="); pw.print(mCameraLensCoverState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006585 pw.print(" mHdmiPlugged="); pw.println(mHdmiPlugged);
Dianne Hackborne26ab702011-10-16 13:21:33 -07006586 if (mLastSystemUiFlags != 0 || mResettingSystemUiFlags != 0
6587 || mForceClearedSystemUiFlags != 0) {
6588 pw.print(prefix); pw.print("mLastSystemUiFlags=0x");
6589 pw.print(Integer.toHexString(mLastSystemUiFlags));
6590 pw.print(" mResettingSystemUiFlags=0x");
6591 pw.print(Integer.toHexString(mResettingSystemUiFlags));
6592 pw.print(" mForceClearedSystemUiFlags=0x");
6593 pw.println(Integer.toHexString(mForceClearedSystemUiFlags));
Dianne Hackborndf89e652011-10-06 22:35:11 -07006594 }
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08006595 if (mLastFocusNeedsMenu) {
6596 pw.print(prefix); pw.print("mLastFocusNeedsMenu=");
6597 pw.println(mLastFocusNeedsMenu);
6598 }
Jeff Browna20dda42014-05-27 20:57:24 -07006599 pw.print(prefix); pw.print("mWakeGestureEnabledSetting=");
6600 pw.println(mWakeGestureEnabledSetting);
6601
Jeff Brownbcdfc622014-03-06 19:13:04 -08006602 pw.print(prefix); pw.print("mSupportAutoRotation="); pw.println(mSupportAutoRotation);
Daniel Sandler6396c722013-04-16 20:19:09 -04006603 pw.print(prefix); pw.print("mUiMode="); pw.print(mUiMode);
6604 pw.print(" mDockMode="); pw.print(mDockMode);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006605 pw.print(" mCarDockRotation="); pw.print(mCarDockRotation);
6606 pw.print(" mDeskDockRotation="); pw.println(mDeskDockRotation);
6607 pw.print(prefix); pw.print("mUserRotationMode="); pw.print(mUserRotationMode);
6608 pw.print(" mUserRotation="); pw.print(mUserRotation);
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05006609 pw.print(" mAllowAllRotations="); pw.println(mAllowAllRotations);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07006610 pw.print(prefix); pw.print("mCurrentAppOrientation="); pw.println(mCurrentAppOrientation);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006611 pw.print(prefix); pw.print("mCarDockEnablesAccelerometer=");
6612 pw.print(mCarDockEnablesAccelerometer);
6613 pw.print(" mDeskDockEnablesAccelerometer=");
6614 pw.println(mDeskDockEnablesAccelerometer);
6615 pw.print(prefix); pw.print("mLidKeyboardAccessibility=");
6616 pw.print(mLidKeyboardAccessibility);
6617 pw.print(" mLidNavigationAccessibility="); pw.print(mLidNavigationAccessibility);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07006618 pw.print(" mLidControlsSleep="); pw.println(mLidControlsSleep);
Jeff Brown6d8fd272014-05-20 21:24:38 -07006619 pw.print(prefix);
6620 pw.print("mShortPressOnPowerBehavior="); pw.print(mShortPressOnPowerBehavior);
6621 pw.print(" mLongPressOnPowerBehavior="); pw.println(mLongPressOnPowerBehavior);
Jeff Brown13f00f02014-10-31 14:45:50 -07006622 pw.print(prefix);
6623 pw.print("mDoublePressOnPowerBehavior="); pw.print(mDoublePressOnPowerBehavior);
6624 pw.print(" mTriplePressOnPowerBehavior="); pw.println(mTriplePressOnPowerBehavior);
Jeff Brown6d8fd272014-05-20 21:24:38 -07006625 pw.print(prefix); pw.print("mHasSoftInput="); pw.println(mHasSoftInput);
Jeff Brown3ee549c2014-09-22 20:14:39 -07006626 pw.print(prefix); pw.print("mAwake="); pw.println(mAwake);
6627 pw.print(prefix); pw.print("mScreenOnEarly="); pw.print(mScreenOnEarly);
6628 pw.print(" mScreenOnFully="); pw.println(mScreenOnFully);
6629 pw.print(prefix); pw.print("mKeyguardDrawComplete="); pw.print(mKeyguardDrawComplete);
6630 pw.print(" mWindowManagerDrawComplete="); pw.println(mWindowManagerDrawComplete);
6631 pw.print(prefix); pw.print("mOrientationSensorEnabled=");
6632 pw.println(mOrientationSensorEnabled);
Dianne Hackbornc652de82013-02-15 16:32:56 -08006633 pw.print(prefix); pw.print("mOverscanScreen=("); pw.print(mOverscanScreenLeft);
6634 pw.print(","); pw.print(mOverscanScreenTop);
6635 pw.print(") "); pw.print(mOverscanScreenWidth);
6636 pw.print("x"); pw.println(mOverscanScreenHeight);
6637 if (mOverscanLeft != 0 || mOverscanTop != 0
6638 || mOverscanRight != 0 || mOverscanBottom != 0) {
6639 pw.print(prefix); pw.print("mOverscan left="); pw.print(mOverscanLeft);
6640 pw.print(" top="); pw.print(mOverscanTop);
6641 pw.print(" right="); pw.print(mOverscanRight);
6642 pw.print(" bottom="); pw.println(mOverscanBottom);
6643 }
Dianne Hackborn313440842013-02-19 19:22:59 -08006644 pw.print(prefix); pw.print("mRestrictedOverscanScreen=(");
6645 pw.print(mRestrictedOverscanScreenLeft);
6646 pw.print(","); pw.print(mRestrictedOverscanScreenTop);
6647 pw.print(") "); pw.print(mRestrictedOverscanScreenWidth);
6648 pw.print("x"); pw.println(mRestrictedOverscanScreenHeight);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006649 pw.print(prefix); pw.print("mUnrestrictedScreen=("); pw.print(mUnrestrictedScreenLeft);
6650 pw.print(","); pw.print(mUnrestrictedScreenTop);
6651 pw.print(") "); pw.print(mUnrestrictedScreenWidth);
6652 pw.print("x"); pw.println(mUnrestrictedScreenHeight);
6653 pw.print(prefix); pw.print("mRestrictedScreen=("); pw.print(mRestrictedScreenLeft);
6654 pw.print(","); pw.print(mRestrictedScreenTop);
6655 pw.print(") "); pw.print(mRestrictedScreenWidth);
6656 pw.print("x"); pw.println(mRestrictedScreenHeight);
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07006657 pw.print(prefix); pw.print("mStableFullscreen=("); pw.print(mStableFullscreenLeft);
6658 pw.print(","); pw.print(mStableFullscreenTop);
6659 pw.print(")-("); pw.print(mStableFullscreenRight);
6660 pw.print(","); pw.print(mStableFullscreenBottom); pw.println(")");
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07006661 pw.print(prefix); pw.print("mStable=("); pw.print(mStableLeft);
6662 pw.print(","); pw.print(mStableTop);
6663 pw.print(")-("); pw.print(mStableRight);
6664 pw.print(","); pw.print(mStableBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07006665 pw.print(prefix); pw.print("mSystem=("); pw.print(mSystemLeft);
6666 pw.print(","); pw.print(mSystemTop);
6667 pw.print(")-("); pw.print(mSystemRight);
6668 pw.print(","); pw.print(mSystemBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006669 pw.print(prefix); pw.print("mCur=("); pw.print(mCurLeft);
6670 pw.print(","); pw.print(mCurTop);
6671 pw.print(")-("); pw.print(mCurRight);
6672 pw.print(","); pw.print(mCurBottom); pw.println(")");
6673 pw.print(prefix); pw.print("mContent=("); pw.print(mContentLeft);
6674 pw.print(","); pw.print(mContentTop);
6675 pw.print(")-("); pw.print(mContentRight);
6676 pw.print(","); pw.print(mContentBottom); pw.println(")");
Dianne Hackborne30e02f2014-05-27 18:24:45 -07006677 pw.print(prefix); pw.print("mVoiceContent=("); pw.print(mVoiceContentLeft);
6678 pw.print(","); pw.print(mVoiceContentTop);
6679 pw.print(")-("); pw.print(mVoiceContentRight);
6680 pw.print(","); pw.print(mVoiceContentBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006681 pw.print(prefix); pw.print("mDock=("); pw.print(mDockLeft);
6682 pw.print(","); pw.print(mDockTop);
6683 pw.print(")-("); pw.print(mDockRight);
6684 pw.print(","); pw.print(mDockBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07006685 pw.print(prefix); pw.print("mDockLayer="); pw.print(mDockLayer);
6686 pw.print(" mStatusBarLayer="); pw.println(mStatusBarLayer);
Dianne Hackborn7ad44382012-10-18 17:46:00 -07006687 pw.print(prefix); pw.print("mShowingLockscreen="); pw.print(mShowingLockscreen);
6688 pw.print(" mShowingDream="); pw.print(mShowingDream);
Jeff Brown061ea992015-04-17 19:55:47 -07006689 pw.print(" mDreamingLockscreen="); pw.print(mDreamingLockscreen);
6690 pw.print(" mDreamingSleepToken="); pw.println(mDreamingSleepToken);
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006691 if (mLastInputMethodWindow != null) {
6692 pw.print(prefix); pw.print("mLastInputMethodWindow=");
6693 pw.println(mLastInputMethodWindow);
6694 }
6695 if (mLastInputMethodTargetWindow != null) {
6696 pw.print(prefix); pw.print("mLastInputMethodTargetWindow=");
6697 pw.println(mLastInputMethodTargetWindow);
6698 }
6699 if (mStatusBar != null) {
6700 pw.print(prefix); pw.print("mStatusBar=");
Dianne Hackbornae6688b2015-02-11 17:02:41 -08006701 pw.print(mStatusBar); pw.print(" isStatusBarKeyguard=");
6702 pw.println(isStatusBarKeyguard());
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006703 }
6704 if (mNavigationBar != null) {
6705 pw.print(prefix); pw.print("mNavigationBar=");
6706 pw.println(mNavigationBar);
6707 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006708 if (mFocusedWindow != null) {
6709 pw.print(prefix); pw.print("mFocusedWindow=");
6710 pw.println(mFocusedWindow);
6711 }
6712 if (mFocusedApp != null) {
6713 pw.print(prefix); pw.print("mFocusedApp=");
6714 pw.println(mFocusedApp);
6715 }
6716 if (mWinDismissingKeyguard != null) {
6717 pw.print(prefix); pw.print("mWinDismissingKeyguard=");
6718 pw.println(mWinDismissingKeyguard);
6719 }
6720 if (mTopFullscreenOpaqueWindowState != null) {
6721 pw.print(prefix); pw.print("mTopFullscreenOpaqueWindowState=");
6722 pw.println(mTopFullscreenOpaqueWindowState);
6723 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01006724 if (mTopFullscreenOpaqueOrDimmingWindowState != null) {
6725 pw.print(prefix); pw.print("mTopFullscreenOpaqueOrDimmingWindowState=");
6726 pw.println(mTopFullscreenOpaqueOrDimmingWindowState);
6727 }
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08006728 if (mForcingShowNavBar) {
6729 pw.print(prefix); pw.print("mForcingShowNavBar=");
6730 pw.println(mForcingShowNavBar); pw.print( "mForcingShowNavBarLayer=");
6731 pw.println(mForcingShowNavBarLayer);
6732 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07006733 pw.print(prefix); pw.print("mTopIsFullscreen="); pw.print(mTopIsFullscreen);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006734 pw.print(" mHideLockScreen="); pw.println(mHideLockScreen);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07006735 pw.print(prefix); pw.print("mForceStatusBar="); pw.print(mForceStatusBar);
6736 pw.print(" mForceStatusBarFromKeyguard=");
6737 pw.println(mForceStatusBarFromKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006738 pw.print(prefix); pw.print("mDismissKeyguard="); pw.print(mDismissKeyguard);
Craig Mautnerad09bcc2012-10-08 13:33:11 -07006739 pw.print(" mWinDismissingKeyguard="); pw.print(mWinDismissingKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006740 pw.print(" mHomePressed="); pw.println(mHomePressed);
6741 pw.print(prefix); pw.print("mAllowLockscreenWhenOn="); pw.print(mAllowLockscreenWhenOn);
6742 pw.print(" mLockScreenTimeout="); pw.print(mLockScreenTimeout);
6743 pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive);
6744 pw.print(prefix); pw.print("mEndcallBehavior="); pw.print(mEndcallBehavior);
6745 pw.print(" mIncallPowerBehavior="); pw.print(mIncallPowerBehavior);
6746 pw.print(" mLongPressOnHomeBehavior="); pw.println(mLongPressOnHomeBehavior);
6747 pw.print(prefix); pw.print("mLandscapeRotation="); pw.print(mLandscapeRotation);
6748 pw.print(" mSeascapeRotation="); pw.println(mSeascapeRotation);
6749 pw.print(prefix); pw.print("mPortraitRotation="); pw.print(mPortraitRotation);
6750 pw.print(" mUpsideDownRotation="); pw.println(mUpsideDownRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07006751 pw.print(prefix); pw.print("mDemoHdmiRotation="); pw.print(mDemoHdmiRotation);
6752 pw.print(" mDemoHdmiRotationLock="); pw.println(mDemoHdmiRotationLock);
6753 pw.print(prefix); pw.print("mUndockedHdmiRotation="); pw.println(mUndockedHdmiRotation);
Jeff Brown600f0032014-05-22 17:06:00 -07006754
Tim Kilbournd7c0c2e2014-05-29 16:08:10 -07006755 mGlobalKeyManager.dump(prefix, pw);
John Spurlock27735a42013-08-14 17:57:38 -04006756 mStatusBarController.dump(pw, prefix);
6757 mNavigationBarController.dump(pw, prefix);
John Spurlockc6d1c602014-01-17 15:22:06 -05006758 PolicyControl.dump(prefix, pw);
Jeff Brown600f0032014-05-22 17:06:00 -07006759
Jeff Browna20dda42014-05-27 20:57:24 -07006760 if (mWakeGestureListener != null) {
6761 mWakeGestureListener.dump(pw, prefix);
6762 }
Jeff Brown600f0032014-05-22 17:06:00 -07006763 if (mOrientationListener != null) {
6764 mOrientationListener.dump(pw, prefix);
6765 }
Filip Gruszczynskicfb31852015-02-25 21:47:12 +00006766 if (mBurnInProtectionHelper != null) {
6767 mBurnInProtectionHelper.dump(prefix, pw);
6768 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006769 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006770}