blob: 14f6c5a3759376c303f67c05a565b162f5740c99 [file] [log] [blame]
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001/*
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16package com.android.internal.policy.impl;
17
Dianne Hackborna4972e92012-03-14 10:38:05 -070018import android.app.ActivityManager;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080019import android.app.ActivityManagerNative;
Dianne Hackbornc2293022013-02-06 23:14:49 -080020import android.app.AppOpsManager;
Daniel Sandler6396c722013-04-16 20:19:09 -040021import android.app.IUiModeManager;
Dianne Hackborn661cd522011-08-22 00:26:20 -070022import android.app.ProgressDialog;
Jeff Brownde7a8ea2012-06-13 18:28:57 -070023import android.app.SearchManager;
John Spurlock97642182013-07-29 17:58:39 -040024import android.app.StatusBarManager;
Dianne Hackborn78968392010-03-04 20:47:56 -080025import android.app.UiModeManager;
Dianne Hackborn39c2d712009-09-22 11:41:31 -070026import android.content.ActivityNotFoundException;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080027import android.content.BroadcastReceiver;
Daniel Sandler0601eb72011-04-13 01:01:32 -040028import android.content.ComponentName;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080029import android.content.ContentResolver;
30import android.content.Context;
31import android.content.Intent;
Mike Lockwood1753f7f2009-08-24 14:49:07 -070032import android.content.IntentFilter;
Winson Chung9112ec32011-06-27 13:15:32 -070033import android.content.ServiceConnection;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080034import android.content.pm.ActivityInfo;
35import android.content.pm.PackageManager;
Daniel Sandler6396c722013-04-16 20:19:09 -040036import android.content.pm.ResolveInfo;
Dianne Hackborn2f0b1752011-05-31 17:59:49 -070037import android.content.res.CompatibilityInfo;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080038import android.content.res.Configuration;
39import android.content.res.Resources;
Craig Mautner8e4df6c2012-05-23 16:57:23 -070040import android.content.res.TypedArray;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080041import android.database.ContentObserver;
Dianne Hackbornc777e072010-02-12 13:07:59 -080042import android.graphics.PixelFormat;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080043import android.graphics.Rect;
John Spurlock7b414672014-07-18 13:02:39 -040044import android.media.AudioAttributes;
Michael Jurka7a348952012-02-27 13:07:58 -080045import android.media.AudioManager;
46import android.media.IAudioService;
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -070047import android.media.Ringtone;
48import android.media.RingtoneManager;
RoboErik3c45c292014-07-08 16:47:31 -070049import android.media.session.MediaController;
50import android.media.session.MediaSession;
RoboErik8a2cfc32014-05-16 11:19:38 -070051import android.media.session.MediaSessionLegacyHelper;
RoboErik3c45c292014-07-08 16:47:31 -070052import android.media.session.MediaSessionManager;
53import android.media.session.PlaybackState;
Dianne Hackborn38e29a62011-09-18 14:43:08 -070054import android.os.Bundle;
Jeff Brown9a538ee2012-08-20 14:56:57 -070055import android.os.FactoryTest;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080056import android.os.Handler;
57import android.os.IBinder;
Jeff Brown32cbc38552011-12-01 14:01:49 -080058import android.os.Looper;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -070059import android.os.Message;
60import android.os.Messenger;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080061import android.os.PowerManager;
62import android.os.RemoteException;
63import android.os.ServiceManager;
64import android.os.SystemClock;
65import android.os.SystemProperties;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -080066import android.os.UEventObserver;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -070067import android.os.UserHandle;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080068import android.os.Vibrator;
69import android.provider.Settings;
Jose Lima9546b202014-07-02 17:21:51 -070070import android.service.dreams.DreamManagerInternal;
John Spurlockc8b46ca2013-04-08 12:59:26 -040071import android.service.dreams.DreamService;
72import android.service.dreams.IDreamManager;
Santos Cordon9eb45932014-06-27 12:28:43 -070073import android.telecomm.TelecommManager;
Dianne Hackborn81e56d52011-05-26 00:55:58 -070074import android.util.DisplayMetrics;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080075import android.util.EventLog;
76import android.util.Log;
Jeff Browna41ca772010-08-11 14:46:32 -070077import android.util.Slog;
Jeff Brown6651a632011-11-28 12:59:11 -080078import android.util.SparseArray;
Dianne Hackbornf87d1962012-04-04 12:48:24 -070079import android.view.Display;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080080import android.view.Gravity;
81import android.view.HapticFeedbackConstants;
Dianne Hackborne0f085d2011-11-30 18:41:15 -080082import android.view.IApplicationToken;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080083import android.view.IWindowManager;
Jeff Browna41ca772010-08-11 14:46:32 -070084import android.view.InputChannel;
Jeff Brown4d396052010-10-29 21:50:21 -070085import android.view.InputDevice;
Jeff Brown4952dfd2011-11-30 19:23:22 -080086import android.view.InputEvent;
Jeff Brown32cbc38552011-12-01 14:01:49 -080087import android.view.InputEventReceiver;
Jeff Brown6b53e8d2010-11-10 16:03:06 -080088import android.view.KeyCharacterMap;
Craig Mautnerae446592012-12-06 19:05:05 -080089import android.view.KeyCharacterMap.FallbackAction;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080090import android.view.KeyEvent;
91import android.view.MotionEvent;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080092import android.view.Surface;
93import android.view.View;
94import android.view.ViewConfiguration;
95import android.view.Window;
96import android.view.WindowManager;
Craig Mautnerae446592012-12-06 19:05:05 -080097import android.view.WindowManagerGlobal;
Craig Mautner8a0da012014-05-31 15:13:37 -070098import android.view.WindowManagerInternal;
Craig Mautnerae446592012-12-06 19:05:05 -080099import android.view.WindowManagerPolicy;
Craig Mautnerae446592012-12-06 19:05:05 -0800100import android.view.accessibility.AccessibilityEvent;
Svetoslav8e3feb12014-02-24 13:46:47 -0800101import android.view.accessibility.AccessibilityManager;
Craig Mautnerae446592012-12-06 19:05:05 -0800102import android.view.animation.Animation;
103import android.view.animation.AnimationUtils;
104
105import com.android.internal.R;
Jorim Jaggi380ecb82014-03-14 17:25:20 +0100106import com.android.internal.policy.IKeyguardService;
107import com.android.internal.policy.IKeyguardServiceConstants;
Craig Mautnerae446592012-12-06 19:05:05 -0800108import com.android.internal.policy.PolicyManager;
Jim Miller5ecd8112013-01-09 18:50:26 -0800109import com.android.internal.policy.impl.keyguard.KeyguardServiceDelegate;
Craig Mautner8a0da012014-05-31 15:13:37 -0700110import com.android.internal.policy.impl.keyguard.KeyguardServiceDelegate.ShowListener;
Craig Mautnerae446592012-12-06 19:05:05 -0800111import com.android.internal.statusbar.IStatusBarService;
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;
Craig Mautnerae446592012-12-06 19:05:05 -0800114
115import java.io.File;
116import java.io.FileReader;
117import java.io.IOException;
118import java.io.PrintWriter;
Craig Mautner8a0da012014-05-31 15:13:37 -0700119import java.util.ArrayList;
Craig Mautner2bc789b2014-03-19 19:48:38 -0700120import java.util.HashSet;
RoboErik3c45c292014-07-08 16:47:31 -0700121import java.util.List;
Craig Mautnerae446592012-12-06 19:05:05 -0800122
Dianne Hackbornc652de82013-02-15 16:32:56 -0800123import static android.view.WindowManager.LayoutParams.*;
Jeff Brownac143512012-04-05 18:57:33 -0700124import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_ABSENT;
125import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_OPEN;
126import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_CLOSED;
Dianne Hackborn08743722009-12-21 12:16:51 -0800127
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800128/**
The Android Open Source Project0727d222009-03-11 12:11:58 -0700129 * WindowManagerPolicy implementation for the Android phone UI. This
130 * introduces a new method suffix, Lp, for an internal lock of the
131 * PhoneWindowManager. This is used to protect some internal state, and
John Spurlock04db1762013-05-13 12:46:41 -0400132 * can be acquired with either the Lw and Li lock held, so has the restrictions
The Android Open Source Project0727d222009-03-11 12:11:58 -0700133 * of both of those when held.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800134 */
135public class PhoneWindowManager implements WindowManagerPolicy {
136 static final String TAG = "WindowManager";
137 static final boolean DEBUG = false;
Joe Onorato43a17652011-04-06 19:22:23 -0700138 static final boolean localLOGV = false;
The Android Open Source Project11267662009-03-18 17:39:47 -0700139 static final boolean DEBUG_LAYOUT = false;
Jeff Brown40013652012-05-16 21:22:36 -0700140 static final boolean DEBUG_INPUT = false;
Craig Mautner6fbda632012-07-03 09:26:39 -0700141 static final boolean DEBUG_STARTING_WINDOW = false;
Craig Mautner8a0da012014-05-31 15:13:37 -0700142 static final boolean DEBUG_WAKEUP = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800143 static final boolean SHOW_STARTING_ANIMATIONS = true;
144 static final boolean SHOW_PROCESSES_ON_ALT_MENU = false;
Joe Onoratod208e702010-10-08 16:22:43 -0400145
Daniel Sandler6396c722013-04-16 20:19:09 -0400146 // Whether to allow dock apps with METADATA_DOCK_HOME to temporarily take over the Home key.
147 // No longer recommended for desk docks; still useful in car docks.
148 static final boolean ENABLE_CAR_DOCK_HOME_CAPTURE = true;
149 static final boolean ENABLE_DESK_DOCK_HOME_CAPTURE = false;
150
Jeff Brown6d8fd272014-05-20 21:24:38 -0700151 static final int SHORT_PRESS_POWER_NOTHING = 0;
152 static final int SHORT_PRESS_POWER_GO_TO_SLEEP = 1;
153 static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP = 2;
154 static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME = 3;
155
Joe Onoratod208e702010-10-08 16:22:43 -0400156 static final int LONG_PRESS_POWER_NOTHING = 0;
157 static final int LONG_PRESS_POWER_GLOBAL_ACTIONS = 1;
158 static final int LONG_PRESS_POWER_SHUT_OFF = 2;
Jeff Brown9a538ee2012-08-20 14:56:57 -0700159 static final int LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM = 3;
Michael Jurka3b1fc472011-06-13 10:54:40 -0700160
161 // These need to match the documentation/constant in
162 // core/res/res/values/config.xml
Joe Onorato46b0d682010-11-22 17:37:27 -0800163 static final int LONG_PRESS_HOME_NOTHING = 0;
Michael Wrightc9ebea72013-01-16 19:25:02 -0800164 static final int LONG_PRESS_HOME_RECENT_SYSTEM_UI = 1;
Jeff Browncaca8812013-05-09 13:34:33 -0700165 static final int LONG_PRESS_HOME_ASSIST = 2;
166
167 static final int DOUBLE_TAP_HOME_NOTHING = 0;
168 static final int DOUBLE_TAP_HOME_RECENT_SYSTEM_UI = 1;
Joe Onorato46b0d682010-11-22 17:37:27 -0800169
Dianne Hackborn5cb8d792009-05-21 17:34:15 -0700170 static final int APPLICATION_MEDIA_SUBLAYER = -2;
171 static final int APPLICATION_MEDIA_OVERLAY_SUBLAYER = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800172 static final int APPLICATION_PANEL_SUBLAYER = 1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800173 static final int APPLICATION_SUB_PANEL_SUBLAYER = 2;
Craig Mautner88400d32012-09-30 12:35:45 -0700174
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800175 static public final String SYSTEM_DIALOG_REASON_KEY = "reason";
176 static public final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions";
177 static public final String SYSTEM_DIALOG_REASON_RECENT_APPS = "recentapps";
Joe Onoratof275f0c2009-11-24 16:11:13 -0500178 static public final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey";
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700179 static public final String SYSTEM_DIALOG_REASON_ASSIST = "assist";
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800180
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700181 /**
182 * These are the system UI flags that, when changing, can cause the layout
183 * of the screen to change.
184 */
185 static final int SYSTEM_UI_CHANGING_LAYOUT =
John Spurlocke1f366f2013-08-05 12:22:40 -0400186 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlock7f4820a2013-10-08 12:54:35 -0400187 | View.SYSTEM_UI_FLAG_FULLSCREEN
188 | View.STATUS_BAR_TRANSLUCENT
Adrian Roosea562512014-05-05 13:33:03 +0200189 | View.NAVIGATION_BAR_TRANSLUCENT
190 | View.SYSTEM_UI_TRANSPARENT;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700191
John Spurlock7b414672014-07-18 13:02:39 -0400192 private static final AudioAttributes VIBRATION_ATTRIBUTES = new AudioAttributes.Builder()
193 .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
194 .setUsage(AudioAttributes.USAGE_ASSISTANCE_SONIFICATION)
195 .build();
196
Jim Miller5ecd8112013-01-09 18:50:26 -0800197 /**
198 * Keyguard stuff
199 */
200 private WindowState mKeyguardScrim;
Jorim Jaggi380ecb82014-03-14 17:25:20 +0100201 private boolean mKeyguardHidden;
Jorim Jaggicff0acb2014-03-31 16:35:15 +0200202 private boolean mKeyguardDrawn;
Jim Miller5ecd8112013-01-09 18:50:26 -0800203
Jeff Brown6651a632011-11-28 12:59:11 -0800204 /* Table of Application Launch keys. Maps from key codes to intent categories.
205 *
206 * These are special keys that are used to launch particular kinds of applications,
207 * such as a web browser. HID defines nearly a hundred of them in the Consumer (0x0C)
208 * usage page. We don't support quite that many yet...
209 */
210 static SparseArray<String> sApplicationLaunchKeyCategories;
211 static {
212 sApplicationLaunchKeyCategories = new SparseArray<String>();
213 sApplicationLaunchKeyCategories.append(
214 KeyEvent.KEYCODE_EXPLORER, Intent.CATEGORY_APP_BROWSER);
215 sApplicationLaunchKeyCategories.append(
216 KeyEvent.KEYCODE_ENVELOPE, Intent.CATEGORY_APP_EMAIL);
217 sApplicationLaunchKeyCategories.append(
218 KeyEvent.KEYCODE_CONTACTS, Intent.CATEGORY_APP_CONTACTS);
219 sApplicationLaunchKeyCategories.append(
220 KeyEvent.KEYCODE_CALENDAR, Intent.CATEGORY_APP_CALENDAR);
221 sApplicationLaunchKeyCategories.append(
222 KeyEvent.KEYCODE_MUSIC, Intent.CATEGORY_APP_MUSIC);
223 sApplicationLaunchKeyCategories.append(
224 KeyEvent.KEYCODE_CALCULATOR, Intent.CATEGORY_APP_CALCULATOR);
225 }
226
Dianne Hackborndf89e652011-10-06 22:35:11 -0700227 /**
228 * Lock protecting internal state. Must not call out into window
229 * manager with lock held. (This lock will be acquired in places
230 * where the window manager is calling in with its own lock held.)
231 */
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800232 private final Object mLock = new Object();
Dianne Hackborndf89e652011-10-06 22:35:11 -0700233
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800234 Context mContext;
235 IWindowManager mWindowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700236 WindowManagerFuncs mWindowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -0700237 WindowManagerInternal mWindowManagerInternal;
Jeff Brown96307042012-07-27 15:51:34 -0700238 PowerManager mPowerManager;
Jose Lima9546b202014-07-02 17:21:51 -0700239 DreamManagerInternal mDreamManagerInternal;
Joe Onorato93056472010-09-10 10:30:46 -0400240 IStatusBarService mStatusBarService;
Jeff Browncaca8812013-05-09 13:34:33 -0700241 boolean mPreloadedRecentApps;
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700242 final Object mServiceAquireLock = new Object();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800243 Vibrator mVibrator; // Vibrator for giving feedback of orientation changes
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700244 SearchManager mSearchManager;
Svetoslav8e3feb12014-02-24 13:46:47 -0800245 AccessibilityManager mAccessibilityManager;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800246
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700247 // Vibrator pattern for haptic feedback of a long press.
248 long[] mLongPressVibePattern;
Craig Mautner88400d32012-09-30 12:35:45 -0700249
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700250 // Vibrator pattern for haptic feedback of virtual key press.
251 long[] mVirtualKeyVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700252
Amith Yamasanic33cb712010-02-10 15:21:49 -0800253 // Vibrator pattern for a short vibration.
254 long[] mKeyboardTapVibePattern;
255
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -0700256 // Vibrator pattern for a short vibration when tapping on an hour/minute tick of a Clock.
257 long[] mClockTickVibePattern;
258
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -0700259 // Vibrator pattern for a short vibration when tapping on a day/month/year date of a Calendar.
260 long[] mCalendarDateVibePattern;
261
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700262 // Vibrator pattern for haptic feedback during boot when safe mode is disabled.
263 long[] mSafeModeDisabledVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700264
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700265 // Vibrator pattern for haptic feedback during boot when safe mode is enabled.
266 long[] mSafeModeEnabledVibePattern;
Romain Guy8154cd32010-03-29 14:41:15 -0700267
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800268 /** If true, hitting shift & menu will broadcast Intent.ACTION_BUG_REPORT */
269 boolean mEnableShiftMenuBugReports = false;
Mike Lockwoodd747dc82011-09-13 16:28:22 -0400270
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800271 boolean mSafeMode;
272 WindowState mStatusBar = null;
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700273 int mStatusBarHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400274 WindowState mNavigationBar = null;
Daniel Sandler36412a72011-08-04 09:35:13 -0400275 boolean mHasNavigationBar = false;
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700276 boolean mCanHideNavigationBar = false;
Daniel Sandler4a066c52012-04-20 14:49:13 -0400277 boolean mNavigationBarCanMove = false; // can the navigation bar ever move to the side?
278 boolean mNavigationBarOnBottom = true; // is the navigation bar on the bottom *right now*?
279 int[] mNavigationBarHeightForRotation = new int[4];
280 int[] mNavigationBarWidthForRotation = new int[4];
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400281
Craig Mautnera631d492014-08-05 15:16:01 -0700282 boolean mBootMessageNeedsHiding;
Jim Miller5ecd8112013-01-09 18:50:26 -0800283 KeyguardServiceDelegate mKeyguardDelegate;
Craig Mautner8a0da012014-05-31 15:13:37 -0700284 // The following are only accessed on the mHandler thread.
285 boolean mKeyguardDrawComplete;
286 boolean mWindowManagerDrawComplete;
Craig Mautner13f6ea72014-06-23 14:57:02 -0700287 ScreenOnListener mScreenOnListener;
288 final Runnable mWindowManagerDrawCallback = new Runnable() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700289 @Override
Craig Mautner13f6ea72014-06-23 14:57:02 -0700290 public void run() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700291 if (DEBUG_WAKEUP) Slog.i(TAG, "All windows ready for display!");
292 mHandler.sendEmptyMessage(MSG_WINDOW_MANAGER_DRAWN_COMPLETE);
293 }
294 };
295 final ShowListener mKeyguardDelegateCallback = new ShowListener() {
296 @Override
297 public void onShown(IBinder windowToken) {
298 if (DEBUG_WAKEUP) Slog.d(TAG, "mKeyguardDelegate.ShowListener.onShown.");
299 mHandler.sendEmptyMessage(MSG_KEYGUARD_DRAWN_COMPLETE);
300 }
301 };
302
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800303 GlobalActions mGlobalActions;
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700304 volatile boolean mPowerKeyHandled; // accessed from input reader and handler thread
305 boolean mPendingPowerKeyUpCanceled;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800306 Handler mHandler;
satok1bc0a492012-04-25 22:47:12 +0900307 WindowState mLastInputMethodWindow = null;
308 WindowState mLastInputMethodTargetWindow = null;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800309
Winson Chungd42a6cf2014-06-03 16:24:04 -0700310 boolean mRecentsVisible;
Winson Chung1e8d71b2014-05-16 17:05:22 -0700311 int mRecentAppsHeldModifiers;
Jeff Browncf39bdf2012-05-18 14:41:19 -0700312 boolean mLanguageSwitchKeyPressed;
Jeff Brown68b909d2011-12-07 16:36:01 -0800313
Jeff Brown2e7760e2012-04-11 15:14:55 -0700314 int mLidState = LID_ABSENT;
Jeff Browndaa37532012-05-01 15:54:03 -0700315 boolean mHaveBuiltInKeyboard;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800316
Dianne Hackbornc777e072010-02-12 13:07:59 -0800317 boolean mSystemReady;
Dianne Hackbornba24e4d2011-09-01 11:17:06 -0700318 boolean mSystemBooted;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800319 boolean mHdmiPlugged;
Jeff Brown4f5fa282014-06-12 19:19:15 -0700320 IUiModeManager mUiModeManager;
Daniel Sandler6396c722013-04-16 20:19:09 -0400321 int mUiMode;
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700322 int mDockMode = Intent.EXTRA_DOCK_STATE_UNDOCKED;
Mike Lockwood1753f7f2009-08-24 14:49:07 -0700323 int mLidOpenRotation;
Mike Lockwood2d1efbd2009-09-16 12:15:53 -0400324 int mCarDockRotation;
325 int mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -0700326 int mUndockedHdmiRotation;
327 int mDemoHdmiRotation;
328 boolean mDemoHdmiRotationLock;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400329
Jeff Browna20dda42014-05-27 20:57:24 -0700330 boolean mWakeGestureEnabledSetting;
331 MyWakeGestureListener mWakeGestureListener;
332
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700333 // Default display does not rotate, apps that require non-default orientation will have to
334 // have the orientation emulated.
335 private boolean mForceDefaultOrientation = false;
336
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400337 int mUserRotationMode = WindowManagerPolicy.USER_ROTATION_FREE;
338 int mUserRotation = Surface.ROTATION_0;
Jeff Brown207673cd2012-06-05 17:47:11 -0700339 boolean mAccelerometerDefault;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400340
Jeff Brownbcdfc622014-03-06 19:13:04 -0800341 boolean mSupportAutoRotation;
Jeff Brownd3187e32011-09-21 19:26:44 -0700342 int mAllowAllRotations = -1;
Mike Lockwoode9867d22009-09-20 01:59:02 -0400343 boolean mCarDockEnablesAccelerometer;
344 boolean mDeskDockEnablesAccelerometer;
Dianne Hackborn2862fff2009-09-15 22:56:29 -0700345 int mLidKeyboardAccessibility;
346 int mLidNavigationAccessibility;
Jeff Brownc458ce92012-04-30 14:58:40 -0700347 boolean mLidControlsSleep;
Jeff Brown6d8fd272014-05-20 21:24:38 -0700348 int mShortPressOnPowerBehavior = -1;
Joe Onoratod208e702010-10-08 16:22:43 -0400349 int mLongPressOnPowerBehavior = -1;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -0700350 boolean mScreenOnEarly = false;
351 boolean mScreenOnFully = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800352 boolean mOrientationSensorEnabled = false;
353 int mCurrentAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800354 boolean mHasSoftInput = false;
Daniel Sandlerdd73ee42013-10-11 22:19:59 -0400355 boolean mTranslucentDecorEnabled = true;
Craig Mautner967212c2013-04-13 21:10:58 -0700356
Jeff Brown70825162012-03-28 17:27:48 -0700357 int mPointerLocationMode = 0; // guarded by mLock
Joe Onorato664644d2011-01-23 17:53:23 -0800358
359 // The last window we were told about in focusChanged.
360 WindowState mFocusedWindow;
Dianne Hackborne0f085d2011-11-30 18:41:15 -0800361 IApplicationToken mFocusedApp;
Joe Onorato664644d2011-01-23 17:53:23 -0800362
Jeff Brown70825162012-03-28 17:27:48 -0700363 PointerLocationView mPointerLocationView;
Jeff Brown32cbc38552011-12-01 14:01:49 -0800364
Dianne Hackbornc652de82013-02-15 16:32:56 -0800365 // The current size of the screen; really; extends into the overscan area of
366 // the screen and doesn't account for any system elements like the status bar.
367 int mOverscanScreenLeft, mOverscanScreenTop;
368 int mOverscanScreenWidth, mOverscanScreenHeight;
369 // The current visible size of the screen; really; (ir)regardless of whether the status
370 // bar can be hidden but not extending into the overscan area.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800371 int mUnrestrictedScreenLeft, mUnrestrictedScreenTop;
372 int mUnrestrictedScreenWidth, mUnrestrictedScreenHeight;
Dianne Hackborn313440842013-02-19 19:22:59 -0800373 // Like mOverscanScreen*, but allowed to move into the overscan region where appropriate.
374 int mRestrictedOverscanScreenLeft, mRestrictedOverscanScreenTop;
375 int mRestrictedOverscanScreenWidth, mRestrictedOverscanScreenHeight;
Dianne Hackborn82de1ae2010-10-28 11:28:39 -0700376 // The current size of the screen; these may be different than (0,0)-(dw,dh)
377 // if the status bar can't be hidden; in that case it effectively carves out
378 // that area of the display from all other windows.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800379 int mRestrictedScreenLeft, mRestrictedScreenTop;
380 int mRestrictedScreenWidth, mRestrictedScreenHeight;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700381 // During layout, the current screen borders accounting for any currently
382 // visible system UI elements.
383 int mSystemLeft, mSystemTop, mSystemRight, mSystemBottom;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700384 // For applications requesting stable content insets, these are them.
385 int mStableLeft, mStableTop, mStableRight, mStableBottom;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -0700386 // For applications requesting stable content insets but have also set the
387 // fullscreen window flag, these are the stable dimensions without the status bar.
388 int mStableFullscreenLeft, mStableFullscreenTop;
389 int mStableFullscreenRight, mStableFullscreenBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800390 // During layout, the current screen borders with all outer decoration
391 // (status bar, input method dock) accounted for.
392 int mCurLeft, mCurTop, mCurRight, mCurBottom;
393 // During layout, the frame in which content should be displayed
394 // to the user, accounting for all screen decoration except for any
395 // space they deem as available for other content. This is usually
396 // the same as mCur*, but may be larger if the screen decor has supplied
397 // content insets.
398 int mContentLeft, mContentTop, mContentRight, mContentBottom;
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700399 // During layout, the frame in which voice content should be displayed
400 // to the user, accounting for all screen decoration except for any
401 // space they deem as available for other content.
402 int mVoiceContentLeft, mVoiceContentTop, mVoiceContentRight, mVoiceContentBottom;
Dianne Hackborn8e11ef02010-11-18 19:47:42 -0800403 // During layout, the current screen borders along which input method
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800404 // windows are placed.
405 int mDockLeft, mDockTop, mDockRight, mDockBottom;
406 // During layout, the layer at which the doc window is placed.
407 int mDockLayer;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700408 // During layout, this is the layer of the status bar.
409 int mStatusBarLayer;
Dianne Hackborne26ab702011-10-16 13:21:33 -0700410 int mLastSystemUiFlags;
411 // Bits that we are in the process of clearing, so we want to prevent
412 // them from being set by applications until everything has been updated
413 // to have them clear.
414 int mResettingSystemUiFlags = 0;
415 // Bits that we are currently always keeping cleared.
416 int mForceClearedSystemUiFlags = 0;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -0800417 // What we last reported to system UI about whether the compatibility
418 // menu needs to be displayed.
419 boolean mLastFocusNeedsMenu = false;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700420
421 FakeWindow mHideNavFakeWindow = null;
422
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800423 static final Rect mTmpParentFrame = new Rect();
424 static final Rect mTmpDisplayFrame = new Rect();
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800425 static final Rect mTmpOverscanFrame = new Rect();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800426 static final Rect mTmpContentFrame = new Rect();
427 static final Rect mTmpVisibleFrame = new Rect();
John Spurlock46646232013-09-30 22:32:42 -0400428 static final Rect mTmpDecorFrame = new Rect();
Adrian Roosfa104232014-06-20 16:10:14 -0700429 static final Rect mTmpStableFrame = new Rect();
Dianne Hackborn1f903c32011-09-13 19:18:06 -0700430 static final Rect mTmpNavigationFrame = new Rect();
Craig Mautner967212c2013-04-13 21:10:58 -0700431
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800432 WindowState mTopFullscreenOpaqueWindowState;
Craig Mautner2bc789b2014-03-19 19:48:38 -0700433 HashSet<IApplicationToken> mAppsToBeHidden = new HashSet<IApplicationToken>();
Joe Onorato93056472010-09-10 10:30:46 -0400434 boolean mTopIsFullscreen;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800435 boolean mForceStatusBar;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -0700436 boolean mForceStatusBarFromKeyguard;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700437 boolean mHideLockScreen;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -0800438 boolean mForcingShowNavBar;
439 int mForcingShowNavBarLayer;
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700440
441 // States of keyguard dismiss.
442 private static final int DISMISS_KEYGUARD_NONE = 0; // Keyguard not being dismissed.
443 private static final int DISMISS_KEYGUARD_START = 1; // Keyguard needs to be dismissed.
444 private static final int DISMISS_KEYGUARD_CONTINUE = 2; // Keyguard has been dismissed.
445 int mDismissKeyguard = DISMISS_KEYGUARD_NONE;
446
447 /** The window that is currently dismissing the keyguard. Dismissing the keyguard must only
448 * be done once per window. */
449 private WindowState mWinDismissingKeyguard;
450
Craig Mautnerc9457fa2014-06-06 14:27:48 -0700451 /** The window that is currently showing "over" the keyguard. If there is an app window
452 * belonging to another app on top of this the keyguard shows. If there is a fullscreen
453 * app window under this, still dismiss the keyguard but don't show the app underneath. Show
454 * the wallpaper. */
455 private WindowState mWinShowWhenLocked;
456
Dianne Hackborn7ad44382012-10-18 17:46:00 -0700457 boolean mShowingLockscreen;
458 boolean mShowingDream;
459 boolean mDreamingLockscreen;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800460 boolean mHomePressed;
Jeff Browncaca8812013-05-09 13:34:33 -0700461 boolean mHomeConsumed;
462 boolean mHomeDoubleTapPending;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800463 Intent mHomeIntent;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700464 Intent mCarDockIntent;
465 Intent mDeskDockIntent;
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700466 boolean mSearchKeyShortcutPending;
467 boolean mConsumeSearchKeyUp;
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700468 boolean mAssistKeyLongPressed;
Michael Wright6a62e552014-06-03 19:19:48 -0700469 boolean mPendingMetaAction;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800470
Mike Lockwood28569302010-01-28 11:54:40 -0500471 // support for activating the lock screen while the screen is on
472 boolean mAllowLockscreenWhenOn;
473 int mLockScreenTimeout;
474 boolean mLockScreenTimerActive;
475
David Brownbaf8d092010-03-08 21:52:59 -0800476 // Behavior of ENDCALL Button. (See Settings.System.END_BUTTON_BEHAVIOR.)
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800477 int mEndcallBehavior;
David Brownbaf8d092010-03-08 21:52:59 -0800478
479 // Behavior of POWER button while in-call and screen on.
480 // (See Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR.)
481 int mIncallPowerBehavior;
482
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700483 Display mDisplay;
484
Dianne Hackborn9d132642011-04-21 17:26:39 -0700485 int mLandscapeRotation = 0; // default landscape rotation
486 int mSeascapeRotation = 0; // "other" landscape rotation, 180 degrees from mLandscapeRotation
487 int mPortraitRotation = 0; // default portrait rotation
488 int mUpsideDownRotation = 0; // "other" portrait rotation
Mitsuru Oshima831d0d92009-06-16 18:27:18 -0700489
Dianne Hackbornc652de82013-02-15 16:32:56 -0800490 int mOverscanLeft = 0;
491 int mOverscanTop = 0;
492 int mOverscanRight = 0;
493 int mOverscanBottom = 0;
494
Joe Onorato46b0d682010-11-22 17:37:27 -0800495 // What we do when the user long presses on home
Jeff Browncaca8812013-05-09 13:34:33 -0700496 private int mLongPressOnHomeBehavior;
497
498 // What we do when the user double-taps on home
499 private int mDoubleTapOnHomeBehavior;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800500
Winson Chung9112ec32011-06-27 13:15:32 -0700501 // Screenshot trigger states
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700502 // Time to volume and power must be pressed within this interval of each other.
503 private static final long SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS = 150;
Winson Chung1cea2f32012-10-08 20:42:01 -0700504 // Increase the chord delay when taking a screenshot from the keyguard
505 private static final float KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER = 2.5f;
Christopher Tatee90585f2012-03-05 18:56:25 -0800506 private boolean mScreenshotChordEnabled;
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700507 private boolean mVolumeDownKeyTriggered;
508 private long mVolumeDownKeyTime;
509 private boolean mVolumeDownKeyConsumedByScreenshotChord;
510 private boolean mVolumeUpKeyTriggered;
511 private boolean mPowerKeyTriggered;
512 private long mPowerKeyTime;
Winson Chung9112ec32011-06-27 13:15:32 -0700513
Michael Wrightb854e242013-02-05 17:54:02 -0800514 /* The number of steps between min and max brightness */
515 private static final int BRIGHTNESS_STEPS = 10;
516
Christopher Tate5e08af02012-09-21 17:17:22 -0700517 SettingsObserver mSettingsObserver;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800518 ShortcutManager mShortcutManager;
519 PowerManager.WakeLock mBroadcastWakeLock;
Jeff Brown40013652012-05-16 21:22:36 -0700520 boolean mHavePendingMediaKeyRepeatWithWakeLock;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800521
Craig Mautnerd625ab22013-09-06 13:40:31 -0700522 private int mCurrentUserId;
523
Justin Kohd378ad72013-04-01 12:18:26 -0700524 // Maps global key codes to the components that will handle them.
525 private GlobalKeyManager mGlobalKeyManager;
526
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700527 // Fallback actions by key code.
528 private final SparseArray<KeyCharacterMap.FallbackAction> mFallbackActions =
529 new SparseArray<KeyCharacterMap.FallbackAction>();
Jeff Brown49ed71d2010-12-06 17:13:33 -0800530
Jeff Brown70825162012-03-28 17:27:48 -0700531 private static final int MSG_ENABLE_POINTER_LOCATION = 1;
532 private static final int MSG_DISABLE_POINTER_LOCATION = 2;
Jeff Brown40013652012-05-16 21:22:36 -0700533 private static final int MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK = 3;
534 private static final int MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK = 4;
Craig Mautner8a0da012014-05-31 15:13:37 -0700535 private static final int MSG_KEYGUARD_DRAWN_COMPLETE = 5;
536 private static final int MSG_KEYGUARD_DRAWN_TIMEOUT = 6;
537 private static final int MSG_WINDOW_MANAGER_DRAWN_COMPLETE = 7;
538 private static final int MSG_WAKING_UP = 8;
Craig Mautner84984fa2014-06-19 11:19:20 -0700539 private static final int MSG_DISPATCH_SHOW_RECENTS = 9;
Alan Viverettee34560b22014-07-10 14:50:06 -0700540 private static final int MSG_DISPATCH_SHOW_GLOBAL_ACTIONS = 10;
Craig Mautnera631d492014-08-05 15:16:01 -0700541 private static final int MSG_HIDE_BOOT_MESSAGE = 11;
Jeff Brown70825162012-03-28 17:27:48 -0700542
543 private class PolicyHandler extends Handler {
544 @Override
545 public void handleMessage(Message msg) {
546 switch (msg.what) {
547 case MSG_ENABLE_POINTER_LOCATION:
548 enablePointerLocation();
549 break;
550 case MSG_DISABLE_POINTER_LOCATION:
551 disablePointerLocation();
552 break;
Jeff Brown40013652012-05-16 21:22:36 -0700553 case MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK:
554 dispatchMediaKeyWithWakeLock((KeyEvent)msg.obj);
555 break;
556 case MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK:
557 dispatchMediaKeyRepeatWithWakeLock((KeyEvent)msg.obj);
558 break;
Craig Mautner84984fa2014-06-19 11:19:20 -0700559 case MSG_DISPATCH_SHOW_RECENTS:
560 showRecentApps(false);
561 break;
Alan Viverettee34560b22014-07-10 14:50:06 -0700562 case MSG_DISPATCH_SHOW_GLOBAL_ACTIONS:
563 showGlobalActionsInternal();
564 break;
Craig Mautner8a0da012014-05-31 15:13:37 -0700565 case MSG_KEYGUARD_DRAWN_COMPLETE:
566 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mKeyguardDrawComplete");
567 mKeyguardDrawComplete = true;
568 finishScreenTurningOn();
569 break;
570 case MSG_KEYGUARD_DRAWN_TIMEOUT:
571 Slog.w(TAG, "Keyguard drawn timeout. Setting mKeyguardDrawComplete");
572 mKeyguardDrawComplete = true;
573 finishScreenTurningOn();
574 break;
575 case MSG_WINDOW_MANAGER_DRAWN_COMPLETE:
576 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mWindowManagerDrawComplete");
577 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
578 mWindowManagerDrawComplete = true;
579 finishScreenTurningOn();
580 break;
581 case MSG_WAKING_UP:
582 handleWakingUp((ScreenOnListener) msg.obj);
583 break;
Craig Mautnera631d492014-08-05 15:16:01 -0700584 case MSG_HIDE_BOOT_MESSAGE:
585 handleHideBootMessage();
586 break;
Jeff Brown70825162012-03-28 17:27:48 -0700587 }
588 }
589 }
590
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800591 private UEventObserver mHDMIObserver = new UEventObserver() {
592 @Override
593 public void onUEvent(UEventObserver.UEvent event) {
594 setHdmiPlugged("1".equals(event.get("SWITCH_STATE")));
595 }
596 };
597
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800598 class SettingsObserver extends ContentObserver {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800599 SettingsObserver(Handler handler) {
600 super(handler);
601 }
David Brownbaf8d092010-03-08 21:52:59 -0800602
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800603 void observe() {
Christopher Tate5e08af02012-09-21 17:17:22 -0700604 // Observe all users' changes
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800605 ContentResolver resolver = mContext.getContentResolver();
606 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700607 Settings.System.END_BUTTON_BEHAVIOR), false, this,
608 UserHandle.USER_ALL);
David Brownbaf8d092010-03-08 21:52:59 -0800609 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700610 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR), false, this,
611 UserHandle.USER_ALL);
Jeff Browna20dda42014-05-27 20:57:24 -0700612 resolver.registerContentObserver(Settings.Secure.getUriFor(
613 Settings.Secure.WAKE_GESTURE_ENABLED), false, this,
614 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800615 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700616 Settings.System.ACCELEROMETER_ROTATION), false, this,
617 UserHandle.USER_ALL);
Mike Lockwood28569302010-01-28 11:54:40 -0500618 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700619 Settings.System.USER_ROTATION), false, this,
620 UserHandle.USER_ALL);
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400621 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700622 Settings.System.SCREEN_OFF_TIMEOUT), false, this,
623 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800624 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700625 Settings.System.POINTER_LOCATION), false, this,
626 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800627 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700628 Settings.Secure.DEFAULT_INPUT_METHOD), false, this,
629 UserHandle.USER_ALL);
John Spurlockd9b70bd2014-02-06 17:02:44 -0500630 resolver.registerContentObserver(Settings.Secure.getUriFor(
John Spurlockf1a36642013-10-12 17:50:42 -0400631 Settings.Secure.IMMERSIVE_MODE_CONFIRMATIONS), false, this,
Christopher Tate5e08af02012-09-21 17:17:22 -0700632 UserHandle.USER_ALL);
John Spurlockc6d1c602014-01-17 15:22:06 -0500633 resolver.registerContentObserver(Settings.Global.getUriFor(
634 Settings.Global.POLICY_CONTROL), false, this,
635 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800636 updateSettings();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800637 }
638
639 @Override public void onChange(boolean selfChange) {
Dianne Hackbornc777e072010-02-12 13:07:59 -0800640 updateSettings();
Jeff Brown01a98dd2011-09-20 15:08:29 -0700641 updateRotation(false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800642 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800643 }
Craig Mautner967212c2013-04-13 21:10:58 -0700644
Jeff Browna20dda42014-05-27 20:57:24 -0700645 class MyWakeGestureListener extends WakeGestureListener {
646 MyWakeGestureListener(Context context, Handler handler) {
647 super(context, handler);
648 }
649
650 @Override
651 public void onWakeUp() {
652 synchronized (mLock) {
653 if (shouldEnableWakeGestureLp()) {
Jeff Browne07b94b2014-06-18 15:56:27 -0700654 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
Jeff Browna20dda42014-05-27 20:57:24 -0700655 mPowerManager.wakeUp(SystemClock.uptimeMillis());
656 }
657 }
658 }
659 }
660
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800661 class MyOrientationListener extends WindowOrientationListener {
Craig Mautnereee29c42013-01-17 14:44:34 -0800662 MyOrientationListener(Context context, Handler handler) {
663 super(context, handler);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800664 }
Craig Mautner967212c2013-04-13 21:10:58 -0700665
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800666 @Override
Jeff Brownc0347aa2011-09-23 17:26:09 -0700667 public void onProposedRotationChanged(int rotation) {
Craig Mautnereda67292013-04-28 13:50:14 -0700668 if (localLOGV) Slog.v(TAG, "onProposedRotationChanged, rotation=" + rotation);
Jeff Brown01a98dd2011-09-20 15:08:29 -0700669 updateRotation(false);
670 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800671 }
672 MyOrientationListener mOrientationListener;
673
John Spurlock27735a42013-08-14 17:57:38 -0400674 private final BarController mStatusBarController = new BarController("StatusBar",
John Spurlock5b9145b2013-08-20 15:13:47 -0400675 View.STATUS_BAR_TRANSIENT,
676 View.STATUS_BAR_UNHIDE,
John Spurlockbd957402013-10-03 11:38:39 -0400677 View.STATUS_BAR_TRANSLUCENT,
678 StatusBarManager.WINDOW_STATUS_BAR,
679 WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
John Spurlock5b9145b2013-08-20 15:13:47 -0400680
John Spurlock27735a42013-08-14 17:57:38 -0400681 private final BarController mNavigationBarController = new BarController("NavigationBar",
John Spurlock5b9145b2013-08-20 15:13:47 -0400682 View.NAVIGATION_BAR_TRANSIENT,
683 View.NAVIGATION_BAR_UNHIDE,
John Spurlockbd957402013-10-03 11:38:39 -0400684 View.NAVIGATION_BAR_TRANSLUCENT,
685 StatusBarManager.WINDOW_NAVIGATION_BAR,
686 WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
John Spurlock5b9145b2013-08-20 15:13:47 -0400687
John Spurlockf1a36642013-10-12 17:50:42 -0400688 private ImmersiveModeConfirmation mImmersiveModeConfirmation;
John Spurlock32beb2c2013-03-11 10:16:47 -0400689
Craig Mautner037aa8d2013-06-07 10:35:44 -0700690 private SystemGesturesPointerEventListener mSystemGestures;
John Spurlock32beb2c2013-03-11 10:16:47 -0400691
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700692 IStatusBarService getStatusBarService() {
693 synchronized (mServiceAquireLock) {
694 if (mStatusBarService == null) {
695 mStatusBarService = IStatusBarService.Stub.asInterface(
696 ServiceManager.getService("statusbar"));
697 }
698 return mStatusBarService;
699 }
700 }
701
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700702 /*
703 * We always let the sensor be switched on by default except when
704 * the user has explicitly disabled sensor based rotation or when the
705 * screen is switched off.
706 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700707 boolean needSensorRunningLp() {
Jeff Brownbcdfc622014-03-06 19:13:04 -0800708 if (mSupportAutoRotation) {
709 if (mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
710 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
711 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT
712 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) {
713 // If the application has explicitly requested to follow the
714 // orientation, then we need to turn the sensor on.
715 return true;
716 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800717 }
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700718 if ((mCarDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_CAR) ||
Jeff Brown1a693182011-11-08 14:44:16 -0800719 (mDeskDockEnablesAccelerometer && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
720 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
721 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK))) {
Mike Lockwoode9867d22009-09-20 01:59:02 -0400722 // enable accelerometer if we are docked in a dock that enables accelerometer
723 // orientation management,
724 return true;
725 }
Jeff Brown207673cd2012-06-05 17:47:11 -0700726 if (mUserRotationMode == USER_ROTATION_LOCKED) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800727 // If the setting for using the sensor by default is enabled, then
728 // we will always leave it on. Note that the user could go to
729 // a window that forces an orientation that does not use the
730 // sensor and in theory we could turn it off... however, when next
731 // turning it on we won't have a good value for the current
732 // orientation for a little bit, which can cause orientation
733 // changes to lag, so we'd like to keep it always on. (It will
734 // still be turned off when the screen is off.)
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700735 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800736 }
Jeff Brownbcdfc622014-03-06 19:13:04 -0800737 return mSupportAutoRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800738 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700739
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800740 /*
741 * Various use cases for invoking this function
742 * screen turning off, should always disable listeners if already enabled
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700743 * screen turned on and current app has sensor based orientation, enable listeners
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800744 * if not already enabled
745 * screen turned on and current app does not have sensor orientation, disable listeners if
746 * already enabled
747 * screen turning on and current app has sensor based orientation, enable listeners if needed
748 * screen turning on and current app has nosensor based orientation, do nothing
749 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700750 void updateOrientationListenerLp() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800751 if (!mOrientationListener.canDetectOrientation()) {
752 // If sensor is turned off or nonexistent for some reason
753 return;
754 }
755 //Could have been invoked due to screen turning on or off or
756 //change of the currently visible window's orientation
Craig Mautnereda67292013-04-28 13:50:14 -0700757 if (localLOGV) Slog.v(TAG, "Screen status="+mScreenOnEarly+
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800758 ", current orientation="+mCurrentAppOrientation+
759 ", SensorEnabled="+mOrientationSensorEnabled);
760 boolean disable = true;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -0700761 if (mScreenOnEarly) {
The Android Open Source Project0727d222009-03-11 12:11:58 -0700762 if (needSensorRunningLp()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800763 disable = false;
764 //enable listener if not already enabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700765 if (!mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800766 mOrientationListener.enable();
Craig Mautnereda67292013-04-28 13:50:14 -0700767 if(localLOGV) Slog.v(TAG, "Enabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800768 mOrientationSensorEnabled = true;
769 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700770 }
771 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800772 //check if sensors need to be disabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700773 if (disable && mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800774 mOrientationListener.disable();
Craig Mautnereda67292013-04-28 13:50:14 -0700775 if(localLOGV) Slog.v(TAG, "Disabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800776 mOrientationSensorEnabled = false;
777 }
778 }
779
Jeff Brown4d396052010-10-29 21:50:21 -0700780 private void interceptPowerKeyDown(boolean handled) {
781 mPowerKeyHandled = handled;
782 if (!handled) {
Justin Kohfeabd2c2014-05-02 10:02:44 -0700783 mHandler.postDelayed(mPowerLongPress,
784 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Jeff Brown4d396052010-10-29 21:50:21 -0700785 }
786 }
787
788 private boolean interceptPowerKeyUp(boolean canceled) {
789 if (!mPowerKeyHandled) {
790 mHandler.removeCallbacks(mPowerLongPress);
791 return !canceled;
Jeff Brown4d396052010-10-29 21:50:21 -0700792 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700793 return false;
794 }
795
796 private void cancelPendingPowerKeyAction() {
797 if (!mPowerKeyHandled) {
798 mHandler.removeCallbacks(mPowerLongPress);
799 }
Jeff Brownff204712011-10-25 21:27:54 -0700800 if (mPowerKeyTriggered) {
801 mPendingPowerKeyUpCanceled = true;
802 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700803 }
804
805 private void interceptScreenshotChord() {
Christopher Tatee90585f2012-03-05 18:56:25 -0800806 if (mScreenshotChordEnabled
807 && mVolumeDownKeyTriggered && mPowerKeyTriggered && !mVolumeUpKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700808 final long now = SystemClock.uptimeMillis();
809 if (now <= mVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS
810 && now <= mPowerKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) {
811 mVolumeDownKeyConsumedByScreenshotChord = true;
812 cancelPendingPowerKeyAction();
813
Jeff Sharkey2991fa32012-12-05 18:06:43 -0800814 mHandler.postDelayed(mScreenshotRunnable, getScreenshotChordLongPressDelay());
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700815 }
816 }
817 }
818
Winson Chung1cea2f32012-10-08 20:42:01 -0700819 private long getScreenshotChordLongPressDelay() {
Jim Miller5ecd8112013-01-09 18:50:26 -0800820 if (mKeyguardDelegate.isShowing()) {
Winson Chung1cea2f32012-10-08 20:42:01 -0700821 // Double the time it takes to take a screenshot from the keyguard
822 return (long) (KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER *
Justin Kohfeabd2c2014-05-02 10:02:44 -0700823 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Winson Chung1cea2f32012-10-08 20:42:01 -0700824 }
Justin Kohfeabd2c2014-05-02 10:02:44 -0700825 return ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout();
Winson Chung1cea2f32012-10-08 20:42:01 -0700826 }
827
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700828 private void cancelPendingScreenshotChordAction() {
Jeff Sharkey2991fa32012-12-05 18:06:43 -0800829 mHandler.removeCallbacks(mScreenshotRunnable);
Jeff Brown4d396052010-10-29 21:50:21 -0700830 }
831
Jeff Brown6d8fd272014-05-20 21:24:38 -0700832 private void powerShortPress(long eventTime) {
833 if (mShortPressOnPowerBehavior < 0) {
834 mShortPressOnPowerBehavior = mContext.getResources().getInteger(
835 com.android.internal.R.integer.config_shortPressOnPowerBehavior);
836 }
837
838 switch (mShortPressOnPowerBehavior) {
839 case SHORT_PRESS_POWER_NOTHING:
840 break;
841 case SHORT_PRESS_POWER_GO_TO_SLEEP:
842 mPowerManager.goToSleep(eventTime,
843 PowerManager.GO_TO_SLEEP_REASON_USER, 0);
844 break;
845 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP:
846 mPowerManager.goToSleep(eventTime,
847 PowerManager.GO_TO_SLEEP_REASON_USER,
848 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
849 break;
850 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME:
851 mPowerManager.goToSleep(eventTime,
852 PowerManager.GO_TO_SLEEP_REASON_USER,
853 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
854 launchHomeFromHotKey();
855 break;
856 }
857 }
858
Jeff Brown4d396052010-10-29 21:50:21 -0700859 private final Runnable mPowerLongPress = new Runnable() {
Craig Mautnerf1b67412012-09-19 13:18:29 -0700860 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800861 public void run() {
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700862 // The context isn't read
863 if (mLongPressOnPowerBehavior < 0) {
Jeff Brown850c5b72012-10-01 15:17:22 -0700864 mLongPressOnPowerBehavior = mContext.getResources().getInteger(
865 com.android.internal.R.integer.config_longPressOnPowerBehavior);
Joe Onoratod208e702010-10-08 16:22:43 -0400866 }
Jeff Brown850c5b72012-10-01 15:17:22 -0700867 int resolvedBehavior = mLongPressOnPowerBehavior;
868 if (FactoryTest.isLongPressOnPowerOffEnabled()) {
869 resolvedBehavior = LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM;
870 }
871
872 switch (resolvedBehavior) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700873 case LONG_PRESS_POWER_NOTHING:
874 break;
875 case LONG_PRESS_POWER_GLOBAL_ACTIONS:
876 mPowerKeyHandled = true;
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -0700877 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
878 performAuditoryFeedbackForAccessibilityIfNeed();
879 }
Alan Viverettee34560b22014-07-10 14:50:06 -0700880 showGlobalActionsInternal();
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700881 break;
882 case LONG_PRESS_POWER_SHUT_OFF:
Jeff Brown9a538ee2012-08-20 14:56:57 -0700883 case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM:
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700884 mPowerKeyHandled = true;
885 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
886 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
Jeff Brown850c5b72012-10-01 15:17:22 -0700887 mWindowManagerFuncs.shutdown(resolvedBehavior == LONG_PRESS_POWER_SHUT_OFF);
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700888 break;
889 }
890 }
891 };
892
Jeff Sharkey2991fa32012-12-05 18:06:43 -0800893 private final Runnable mScreenshotRunnable = new Runnable() {
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800894 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700895 public void run() {
896 takeScreenshot();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800897 }
898 };
899
Alan Viverettee34560b22014-07-10 14:50:06 -0700900 @Override
901 public void showGlobalActions() {
902 mHandler.removeMessages(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
903 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
904 }
905
906 void showGlobalActionsInternal() {
907 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800908 if (mGlobalActions == null) {
Jeff Brown7304c342012-05-11 18:42:42 -0700909 mGlobalActions = new GlobalActions(mContext, mWindowManagerFuncs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800910 }
Mike Lockwood3a74bd32011-08-12 13:55:22 -0700911 final boolean keyguardShowing = keyguardIsShowingTq();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800912 mGlobalActions.showDialog(keyguardShowing, isDeviceProvisioned());
913 if (keyguardShowing) {
914 // since it took two seconds of long press to bring this up,
915 // poke the wake lock so they have some time to see the dialog.
Jim Miller25190572013-02-28 17:36:24 -0800916 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800917 }
918 }
919
920 boolean isDeviceProvisioned() {
Jeff Brownbf6f6f92012-09-25 15:03:20 -0700921 return Settings.Global.getInt(
922 mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800923 }
924
Maurice Lam99c6e072014-04-28 18:24:28 -0700925 boolean isUserSetupComplete() {
926 return Settings.Secure.getIntForUser(mContext.getContentResolver(),
927 Settings.Secure.USER_SETUP_COMPLETE, 0, UserHandle.USER_CURRENT) != 0;
928 }
929
Patrick Dubroyece94522011-02-23 18:35:01 -0800930 private void handleLongPressOnHome() {
Joe Onorato46b0d682010-11-22 17:37:27 -0800931 if (mLongPressOnHomeBehavior != LONG_PRESS_HOME_NOTHING) {
Jeff Browncaca8812013-05-09 13:34:33 -0700932 mHomeConsumed = true;
Joe Onorato46b0d682010-11-22 17:37:27 -0800933 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
Patrick Dubroyece94522011-02-23 18:35:01 -0800934
Jeff Browncaca8812013-05-09 13:34:33 -0700935 if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI) {
936 toggleRecentApps();
937 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_ASSIST) {
938 launchAssistAction();
Jim Millere6ad1a82010-08-20 19:25:39 -0700939 }
940 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800941 }
Patrick Dubroyece94522011-02-23 18:35:01 -0800942
Jeff Browncaca8812013-05-09 13:34:33 -0700943 private void handleDoubleTapOnHome() {
944 if (mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
945 mHomeConsumed = true;
946 toggleRecentApps();
947 }
948 }
949
950 private final Runnable mHomeDoubleTapTimeoutRunnable = new Runnable() {
951 @Override
952 public void run() {
953 if (mHomeDoubleTapPending) {
954 mHomeDoubleTapPending = false;
955 launchHomeFromHotKey();
956 }
957 }
958 };
959
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800960 /** {@inheritDoc} */
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800961 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800962 public void init(Context context, IWindowManager windowManager,
Jeff Brown96307042012-07-27 15:51:34 -0700963 WindowManagerFuncs windowManagerFuncs) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800964 mContext = context;
965 mWindowManager = windowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700966 mWindowManagerFuncs = windowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -0700967 mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class);
Jose Lima9546b202014-07-02 17:21:51 -0700968 mDreamManagerInternal = LocalServices.getService(DreamManagerInternal.class);
Craig Mautner8a0da012014-05-31 15:13:37 -0700969
Jeff Brown70825162012-03-28 17:27:48 -0700970 mHandler = new PolicyHandler();
Jeff Browna20dda42014-05-27 20:57:24 -0700971 mWakeGestureListener = new MyWakeGestureListener(mContext, mHandler);
Craig Mautnereee29c42013-01-17 14:44:34 -0800972 mOrientationListener = new MyOrientationListener(mContext, mHandler);
Jeff Brownc0347aa2011-09-23 17:26:09 -0700973 try {
974 mOrientationListener.setCurrentRotation(windowManager.getRotation());
975 } catch (RemoteException ex) { }
Christopher Tate5e08af02012-09-21 17:17:22 -0700976 mSettingsObserver = new SettingsObserver(mHandler);
977 mSettingsObserver.observe();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800978 mShortcutManager = new ShortcutManager(context, mHandler);
979 mShortcutManager.observe();
Daniel Sandler6396c722013-04-16 20:19:09 -0400980 mUiMode = context.getResources().getInteger(
981 com.android.internal.R.integer.config_defaultUiModeType);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800982 mHomeIntent = new Intent(Intent.ACTION_MAIN, null);
983 mHomeIntent.addCategory(Intent.CATEGORY_HOME);
984 mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
985 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700986 mCarDockIntent = new Intent(Intent.ACTION_MAIN, null);
987 mCarDockIntent.addCategory(Intent.CATEGORY_CAR_DOCK);
988 mCarDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
989 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
990 mDeskDockIntent = new Intent(Intent.ACTION_MAIN, null);
991 mDeskDockIntent.addCategory(Intent.CATEGORY_DESK_DOCK);
992 mDeskDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
993 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Jim Millere6ad1a82010-08-20 19:25:39 -0700994
Jeff Brown96307042012-07-27 15:51:34 -0700995 mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
996 mBroadcastWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800997 "PhoneWindowManager.mBroadcastWakeLock");
998 mEnableShiftMenuBugReports = "1".equals(SystemProperties.get("ro.debuggable"));
Jeff Brownbcdfc622014-03-06 19:13:04 -0800999 mSupportAutoRotation = mContext.getResources().getBoolean(
1000 com.android.internal.R.bool.config_supportAutoRotation);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001001 mLidOpenRotation = readRotation(
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001002 com.android.internal.R.integer.config_lidOpenRotation);
1003 mCarDockRotation = readRotation(
1004 com.android.internal.R.integer.config_carDockRotation);
1005 mDeskDockRotation = readRotation(
1006 com.android.internal.R.integer.config_deskDockRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001007 mUndockedHdmiRotation = readRotation(
1008 com.android.internal.R.integer.config_undockedHdmiRotation);
Mike Lockwoode9867d22009-09-20 01:59:02 -04001009 mCarDockEnablesAccelerometer = mContext.getResources().getBoolean(
1010 com.android.internal.R.bool.config_carDockEnablesAccelerometer);
1011 mDeskDockEnablesAccelerometer = mContext.getResources().getBoolean(
1012 com.android.internal.R.bool.config_deskDockEnablesAccelerometer);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001013 mLidKeyboardAccessibility = mContext.getResources().getInteger(
1014 com.android.internal.R.integer.config_lidKeyboardAccessibility);
1015 mLidNavigationAccessibility = mContext.getResources().getInteger(
1016 com.android.internal.R.integer.config_lidNavigationAccessibility);
Jeff Brownc458ce92012-04-30 14:58:40 -07001017 mLidControlsSleep = mContext.getResources().getBoolean(
1018 com.android.internal.R.bool.config_lidControlsSleep);
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04001019 mTranslucentDecorEnabled = mContext.getResources().getBoolean(
1020 com.android.internal.R.bool.config_enableTranslucentDecor);
Jeff Brownf71343d2013-05-31 17:59:11 -07001021 readConfigurationDependentBehaviors();
Jeff Browncaca8812013-05-09 13:34:33 -07001022
Svetoslav8e3feb12014-02-24 13:46:47 -08001023 mAccessibilityManager = (AccessibilityManager) context.getSystemService(
1024 Context.ACCESSIBILITY_SERVICE);
1025
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001026 // register for dock events
Dianne Hackborn78968392010-03-04 20:47:56 -08001027 IntentFilter filter = new IntentFilter();
1028 filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE);
1029 filter.addAction(UiModeManager.ACTION_EXIT_CAR_MODE);
1030 filter.addAction(UiModeManager.ACTION_ENTER_DESK_MODE);
1031 filter.addAction(UiModeManager.ACTION_EXIT_DESK_MODE);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001032 filter.addAction(Intent.ACTION_DOCK_EVENT);
1033 Intent intent = context.registerReceiver(mDockReceiver, filter);
1034 if (intent != null) {
1035 // Retrieve current sticky dock event broadcast.
1036 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
1037 Intent.EXTRA_DOCK_STATE_UNDOCKED);
1038 }
Daniel Sandler7e37df52011-11-16 22:08:23 -08001039
Jeff Brown6aaf2952012-10-05 16:01:08 -07001040 // register for dream-related broadcasts
1041 filter = new IntentFilter();
1042 filter.addAction(Intent.ACTION_DREAMING_STARTED);
1043 filter.addAction(Intent.ACTION_DREAMING_STOPPED);
1044 context.registerReceiver(mDreamReceiver, filter);
1045
Christopher Tate5e08af02012-09-21 17:17:22 -07001046 // register for multiuser-relevant broadcasts
1047 filter = new IntentFilter(Intent.ACTION_USER_SWITCHED);
1048 context.registerReceiver(mMultiuserReceiver, filter);
1049
John Spurlock57306e62013-04-22 09:48:49 -04001050 // monitor for system gestures
Craig Mautner037aa8d2013-06-07 10:35:44 -07001051 mSystemGestures = new SystemGesturesPointerEventListener(context,
1052 new SystemGesturesPointerEventListener.Callbacks() {
John Spurlock57306e62013-04-22 09:48:49 -04001053 @Override
1054 public void onSwipeFromTop() {
John Spurlock04db1762013-05-13 12:46:41 -04001055 if (mStatusBar != null) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001056 requestTransientBars(mStatusBar);
John Spurlock04db1762013-05-13 12:46:41 -04001057 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04001058 }
1059 @Override
1060 public void onSwipeFromBottom() {
John Spurlock04db1762013-05-13 12:46:41 -04001061 if (mNavigationBar != null && mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001062 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001063 }
1064 }
1065 @Override
1066 public void onSwipeFromRight() {
John Spurlock04db1762013-05-13 12:46:41 -04001067 if (mNavigationBar != null && !mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001068 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001069 }
1070 }
1071 @Override
1072 public void onDebug() {
John Spurlockd67ec252013-09-05 11:31:54 -04001073 // no-op
John Spurlockad3e6cb2013-04-30 08:47:43 -04001074 }
1075 });
John Spurlockf1a36642013-10-12 17:50:42 -04001076 mImmersiveModeConfirmation = new ImmersiveModeConfirmation(mContext);
Craig Mautner037aa8d2013-06-07 10:35:44 -07001077 mWindowManagerFuncs.registerPointerEventListener(mSystemGestures);
John Spurlock32beb2c2013-03-11 10:16:47 -04001078
Jeff Brownc2346132012-04-13 01:55:38 -07001079 mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001080 mLongPressVibePattern = getLongIntArray(mContext.getResources(),
1081 com.android.internal.R.array.config_longPressVibePattern);
1082 mVirtualKeyVibePattern = getLongIntArray(mContext.getResources(),
1083 com.android.internal.R.array.config_virtualKeyVibePattern);
Amith Yamasanic33cb712010-02-10 15:21:49 -08001084 mKeyboardTapVibePattern = getLongIntArray(mContext.getResources(),
1085 com.android.internal.R.array.config_keyboardTapVibePattern);
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07001086 mClockTickVibePattern = getLongIntArray(mContext.getResources(),
1087 com.android.internal.R.array.config_clockTickVibePattern);
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07001088 mCalendarDateVibePattern = getLongIntArray(mContext.getResources(),
1089 com.android.internal.R.array.config_calendarDateVibePattern);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001090 mSafeModeDisabledVibePattern = getLongIntArray(mContext.getResources(),
1091 com.android.internal.R.array.config_safeModeDisabledVibePattern);
1092 mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(),
1093 com.android.internal.R.array.config_safeModeEnabledVibePattern);
Daniel Sandler40427442010-07-16 11:44:52 -04001094
Christopher Tatee90585f2012-03-05 18:56:25 -08001095 mScreenshotChordEnabled = mContext.getResources().getBoolean(
1096 com.android.internal.R.bool.config_enableScreenshotChord);
1097
Justin Kohd378ad72013-04-01 12:18:26 -07001098 mGlobalKeyManager = new GlobalKeyManager(mContext);
1099
Joe Onoratoea495d42011-04-06 11:41:11 -07001100 // Controls rotation and the like.
1101 initializeHdmiState();
Dianne Hackborn40011092011-09-22 13:37:48 -07001102
1103 // Match current screen state.
Craig Mautnera631d492014-08-05 15:16:01 -07001104 if (!mPowerManager.isInteractive()) {
Jeff Brown140ffc72014-05-01 15:18:00 -07001105 goingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
Dianne Hackborn40011092011-09-22 13:37:48 -07001106 }
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001107 }
1108
Jeff Brownf71343d2013-05-31 17:59:11 -07001109 /**
1110 * Read values from config.xml that may be overridden depending on
1111 * the configuration of the device.
1112 * eg. Disable long press on home goes to recents on sw600dp.
1113 */
1114 private void readConfigurationDependentBehaviors() {
1115 mLongPressOnHomeBehavior = mContext.getResources().getInteger(
1116 com.android.internal.R.integer.config_longPressOnHomeBehavior);
1117 if (mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING ||
1118 mLongPressOnHomeBehavior > LONG_PRESS_HOME_ASSIST) {
1119 mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1120 }
1121
1122 mDoubleTapOnHomeBehavior = mContext.getResources().getInteger(
1123 com.android.internal.R.integer.config_doubleTapOnHomeBehavior);
1124 if (mDoubleTapOnHomeBehavior < DOUBLE_TAP_HOME_NOTHING ||
1125 mDoubleTapOnHomeBehavior > DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1126 mDoubleTapOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1127 }
1128 }
1129
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001130 @Override
Dianne Hackborndde331c2012-08-03 14:01:57 -07001131 public void setInitialDisplaySize(Display display, int width, int height, int density) {
Jeff Brownef981a42013-08-07 14:13:37 -07001132 // This method might be called before the policy has been fully initialized
1133 // or for other displays we don't care about.
1134 if (mContext == null || display.getDisplayId() != Display.DEFAULT_DISPLAY) {
1135 return;
Dianne Hackbornc652de82013-02-15 16:32:56 -08001136 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001137 mDisplay = display;
1138
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001139 final Resources res = mContext.getResources();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001140 int shortSize, longSize;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001141 if (width > height) {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001142 shortSize = height;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001143 longSize = width;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001144 mLandscapeRotation = Surface.ROTATION_0;
1145 mSeascapeRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001146 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001147 mPortraitRotation = Surface.ROTATION_90;
1148 mUpsideDownRotation = Surface.ROTATION_270;
1149 } else {
1150 mPortraitRotation = Surface.ROTATION_270;
1151 mUpsideDownRotation = Surface.ROTATION_90;
1152 }
1153 } else {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001154 shortSize = width;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001155 longSize = height;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001156 mPortraitRotation = Surface.ROTATION_0;
1157 mUpsideDownRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001158 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001159 mLandscapeRotation = Surface.ROTATION_270;
1160 mSeascapeRotation = Surface.ROTATION_90;
1161 } else {
1162 mLandscapeRotation = Surface.ROTATION_90;
1163 mSeascapeRotation = Surface.ROTATION_270;
1164 }
1165 }
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001166
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001167 mStatusBarHeight =
1168 res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001169
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001170 // Height of the navigation bar when presented horizontally at bottom
1171 mNavigationBarHeightForRotation[mPortraitRotation] =
1172 mNavigationBarHeightForRotation[mUpsideDownRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001173 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_height);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001174 mNavigationBarHeightForRotation[mLandscapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001175 mNavigationBarHeightForRotation[mSeascapeRotation] = res.getDimensionPixelSize(
1176 com.android.internal.R.dimen.navigation_bar_height_landscape);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001177
1178 // Width of the navigation bar when presented vertically along one side
1179 mNavigationBarWidthForRotation[mPortraitRotation] =
1180 mNavigationBarWidthForRotation[mUpsideDownRotation] =
1181 mNavigationBarWidthForRotation[mLandscapeRotation] =
1182 mNavigationBarWidthForRotation[mSeascapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001183 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_width);
Daniel Sandler4a066c52012-04-20 14:49:13 -04001184
1185 // SystemUI (status bar) layout policy
Dianne Hackborndde331c2012-08-03 14:01:57 -07001186 int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / density;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001187 int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / density;
Daniel Sandler4a066c52012-04-20 14:49:13 -04001188
Craig Mautnerd4ec33242013-07-22 10:37:43 -07001189 // Allow the navigation bar to move on small devices (phones).
1190 mNavigationBarCanMove = shortSizeDp < 600;
Daniel Sandler36412a72011-08-04 09:35:13 -04001191
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001192 mHasNavigationBar = res.getBoolean(com.android.internal.R.bool.config_showNavigationBar);
John Spurlock80f00c12013-06-13 11:10:51 -04001193 // Allow a system property to override this. Used by the emulator.
1194 // See also hasNavigationBar().
1195 String navBarOverride = SystemProperties.get("qemu.hw.mainkeys");
1196 if ("1".equals(navBarOverride)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001197 mHasNavigationBar = false;
John Spurlock80f00c12013-06-13 11:10:51 -04001198 } else if ("0".equals(navBarOverride)) {
1199 mHasNavigationBar = true;
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04001200 }
1201
Jeff Brown27f1d672012-10-17 18:32:34 -07001202 // For demo purposes, allow the rotation of the HDMI display to be controlled.
1203 // By default, HDMI locks rotation to landscape.
Erik Gilling9a41ef82011-09-26 19:21:03 -07001204 if ("portrait".equals(SystemProperties.get("persist.demo.hdmirotation"))) {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001205 mDemoHdmiRotation = mPortraitRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001206 } else {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001207 mDemoHdmiRotation = mLandscapeRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001208 }
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001209 mDemoHdmiRotationLock = SystemProperties.getBoolean("persist.demo.hdmirotationlock", false);
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001210
1211 // Only force the default orientation if the screen is xlarge, at least 960dp x 720dp, per
1212 // http://developer.android.com/guide/practices/screens_support.html#range
1213 mForceDefaultOrientation = longSizeDp >= 960 && shortSizeDp >= 720 &&
1214 res.getBoolean(com.android.internal.R.bool.config_forceDefaultOrientation) &&
1215 // For debug purposes the next line turns this feature off with:
1216 // $ adb shell setprop config.override_forced_orient true
1217 // $ adb shell wm size reset
1218 !"true".equals(SystemProperties.get("config.override_forced_orient"));
1219 }
1220
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001221 /**
1222 * @return whether the navigation bar can be hidden, e.g. the device has a
1223 * navigation bar and touch exploration is not enabled
1224 */
1225 private boolean canHideNavigationBar() {
Svetoslav8e3feb12014-02-24 13:46:47 -08001226 return mHasNavigationBar
1227 && !mAccessibilityManager.isTouchExplorationEnabled();
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001228 }
1229
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001230 @Override
1231 public boolean isDefaultOrientationForced() {
1232 return mForceDefaultOrientation;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001233 }
1234
Dianne Hackbornc652de82013-02-15 16:32:56 -08001235 @Override
1236 public void setDisplayOverscan(Display display, int left, int top, int right, int bottom) {
1237 if (display.getDisplayId() == Display.DEFAULT_DISPLAY) {
1238 mOverscanLeft = left;
1239 mOverscanTop = top;
1240 mOverscanRight = right;
1241 mOverscanBottom = bottom;
1242 }
1243 }
1244
Dianne Hackbornc777e072010-02-12 13:07:59 -08001245 public void updateSettings() {
1246 ContentResolver resolver = mContext.getContentResolver();
1247 boolean updateRotation = false;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001248 synchronized (mLock) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001249 mEndcallBehavior = Settings.System.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001250 Settings.System.END_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001251 Settings.System.END_BUTTON_BEHAVIOR_DEFAULT,
1252 UserHandle.USER_CURRENT);
1253 mIncallPowerBehavior = Settings.Secure.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001254 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001255 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT,
1256 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001257
Jeff Browna20dda42014-05-27 20:57:24 -07001258 // Configure wake gesture.
1259 boolean wakeGestureEnabledSetting = Settings.Secure.getIntForUser(resolver,
1260 Settings.Secure.WAKE_GESTURE_ENABLED, 0,
1261 UserHandle.USER_CURRENT) != 0;
1262 if (mWakeGestureEnabledSetting != wakeGestureEnabledSetting) {
1263 mWakeGestureEnabledSetting = wakeGestureEnabledSetting;
1264 updateWakeGestureListenerLp();
1265 }
1266
Jeff Brown207673cd2012-06-05 17:47:11 -07001267 // Configure rotation lock.
Christopher Tate5e08af02012-09-21 17:17:22 -07001268 int userRotation = Settings.System.getIntForUser(resolver,
1269 Settings.System.USER_ROTATION, Surface.ROTATION_0,
1270 UserHandle.USER_CURRENT);
Jeff Brown207673cd2012-06-05 17:47:11 -07001271 if (mUserRotation != userRotation) {
1272 mUserRotation = userRotation;
1273 updateRotation = true;
1274 }
Christopher Tate5e08af02012-09-21 17:17:22 -07001275 int userRotationMode = Settings.System.getIntForUser(resolver,
1276 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
Jeff Brown207673cd2012-06-05 17:47:11 -07001277 WindowManagerPolicy.USER_ROTATION_FREE :
1278 WindowManagerPolicy.USER_ROTATION_LOCKED;
1279 if (mUserRotationMode != userRotationMode) {
1280 mUserRotationMode = userRotationMode;
1281 updateRotation = true;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001282 updateOrientationListenerLp();
1283 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001284
Dianne Hackbornc777e072010-02-12 13:07:59 -08001285 if (mSystemReady) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001286 int pointerLocation = Settings.System.getIntForUser(resolver,
1287 Settings.System.POINTER_LOCATION, 0, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001288 if (mPointerLocationMode != pointerLocation) {
1289 mPointerLocationMode = pointerLocation;
Jeff Brown70825162012-03-28 17:27:48 -07001290 mHandler.sendEmptyMessage(pointerLocation != 0 ?
1291 MSG_ENABLE_POINTER_LOCATION : MSG_DISABLE_POINTER_LOCATION);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001292 }
1293 }
1294 // use screen off timeout setting as the timeout for the lockscreen
Christopher Tate5e08af02012-09-21 17:17:22 -07001295 mLockScreenTimeout = Settings.System.getIntForUser(resolver,
1296 Settings.System.SCREEN_OFF_TIMEOUT, 0, UserHandle.USER_CURRENT);
1297 String imId = Settings.Secure.getStringForUser(resolver,
1298 Settings.Secure.DEFAULT_INPUT_METHOD, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001299 boolean hasSoftInput = imId != null && imId.length() > 0;
1300 if (mHasSoftInput != hasSoftInput) {
1301 mHasSoftInput = hasSoftInput;
1302 updateRotation = true;
1303 }
John Spurlockf1a36642013-10-12 17:50:42 -04001304 if (mImmersiveModeConfirmation != null) {
John Spurlock4355a532014-02-19 09:49:25 -05001305 mImmersiveModeConfirmation.loadSetting(mCurrentUserId);
John Spurlockd67ec252013-09-05 11:31:54 -04001306 }
John Spurlockc6d1c602014-01-17 15:22:06 -05001307 PolicyControl.reloadFromSetting(mContext);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001308 }
1309 if (updateRotation) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07001310 updateRotation(true);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001311 }
Jeff Brown70825162012-03-28 17:27:48 -07001312 }
1313
Jeff Browna20dda42014-05-27 20:57:24 -07001314 private void updateWakeGestureListenerLp() {
1315 if (shouldEnableWakeGestureLp()) {
1316 mWakeGestureListener.requestWakeUpTrigger();
1317 } else {
1318 mWakeGestureListener.cancelWakeUpTrigger();
1319 }
1320 }
1321
1322 private boolean shouldEnableWakeGestureLp() {
1323 return mWakeGestureEnabledSetting && !mScreenOnEarly
1324 && (!mLidControlsSleep || mLidState != LID_CLOSED)
1325 && mWakeGestureListener.isSupported();
1326 }
1327
Jeff Brown70825162012-03-28 17:27:48 -07001328 private void enablePointerLocation() {
1329 if (mPointerLocationView == null) {
1330 mPointerLocationView = new PointerLocationView(mContext);
1331 mPointerLocationView.setPrintCoords(false);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001332 WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
1333 WindowManager.LayoutParams.MATCH_PARENT,
1334 WindowManager.LayoutParams.MATCH_PARENT);
Jeff Brown3b2b3542010-10-15 00:54:27 -07001335 lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001336 lp.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN
1337 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
1338 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1339 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
Jeff Brown90fc9052012-10-01 14:44:24 -07001340 if (ActivityManager.isHighEndGfx()) {
1341 lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
1342 lp.privateFlags |=
1343 WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED;
1344 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001345 lp.format = PixelFormat.TRANSLUCENT;
1346 lp.setTitle("PointerLocation");
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001347 WindowManager wm = (WindowManager)
Dianne Hackbornc777e072010-02-12 13:07:59 -08001348 mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Browncc4f7db2011-08-30 20:34:48 -07001349 lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL;
Jeff Brown70825162012-03-28 17:27:48 -07001350 wm.addView(mPointerLocationView, lp);
Michael Wrightc9c487e2013-11-07 18:55:09 -08001351 mWindowManagerFuncs.registerPointerEventListener(mPointerLocationView);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001352 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001353 }
Jeff Brown70825162012-03-28 17:27:48 -07001354
1355 private void disablePointerLocation() {
Jeff Brown70825162012-03-28 17:27:48 -07001356 if (mPointerLocationView != null) {
Michael Wrightc9c487e2013-11-07 18:55:09 -08001357 mWindowManagerFuncs.unregisterPointerEventListener(mPointerLocationView);
1358 WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Brown70825162012-03-28 17:27:48 -07001359 wm.removeView(mPointerLocationView);
1360 mPointerLocationView = null;
1361 }
1362 }
1363
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001364 private int readRotation(int resID) {
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001365 try {
1366 int rotation = mContext.getResources().getInteger(resID);
1367 switch (rotation) {
1368 case 0:
1369 return Surface.ROTATION_0;
1370 case 90:
1371 return Surface.ROTATION_90;
1372 case 180:
1373 return Surface.ROTATION_180;
1374 case 270:
1375 return Surface.ROTATION_270;
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001376 }
1377 } catch (Resources.NotFoundException e) {
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001378 // fall through
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001379 }
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001380 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001381 }
1382
1383 /** {@inheritDoc} */
Craig Mautner88400d32012-09-30 12:35:45 -07001384 @Override
Dianne Hackbornc2293022013-02-06 23:14:49 -08001385 public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001386 int type = attrs.type;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001387
1388 outAppOp[0] = AppOpsManager.OP_NONE;
1389
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001390 if (type < WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW
1391 || type > WindowManager.LayoutParams.LAST_SYSTEM_WINDOW) {
Jeff Brown98365d72012-08-19 20:30:52 -07001392 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001393 }
1394 String permission = null;
1395 switch (type) {
1396 case TYPE_TOAST:
1397 // XXX right now the app process has complete control over
1398 // this... should introduce a token to let the system
1399 // monitor/control what they are doing.
Jason Monk1c7c3192014-06-26 12:52:18 -04001400 outAppOp[0] = AppOpsManager.OP_TOAST_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001401 break;
Daniel Sandler7d276c32012-01-30 14:33:52 -05001402 case TYPE_DREAM:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001403 case TYPE_INPUT_METHOD:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001404 case TYPE_WALLPAPER:
keunyounga446bf02013-06-21 19:07:57 -07001405 case TYPE_PRIVATE_PRESENTATION:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001406 case TYPE_VOICE_INTERACTION:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001407 // The window manager will check these.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001408 break;
1409 case TYPE_PHONE:
1410 case TYPE_PRIORITY_PHONE:
1411 case TYPE_SYSTEM_ALERT:
1412 case TYPE_SYSTEM_ERROR:
1413 case TYPE_SYSTEM_OVERLAY:
1414 permission = android.Manifest.permission.SYSTEM_ALERT_WINDOW;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001415 outAppOp[0] = AppOpsManager.OP_SYSTEM_ALERT_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001416 break;
1417 default:
1418 permission = android.Manifest.permission.INTERNAL_SYSTEM_WINDOW;
1419 }
1420 if (permission != null) {
1421 if (mContext.checkCallingOrSelfPermission(permission)
1422 != PackageManager.PERMISSION_GRANTED) {
Jeff Brown98365d72012-08-19 20:30:52 -07001423 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001424 }
1425 }
Jeff Brown98365d72012-08-19 20:30:52 -07001426 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001427 }
Craig Mautner88400d32012-09-30 12:35:45 -07001428
1429 @Override
1430 public boolean checkShowToOwnerOnly(WindowManager.LayoutParams attrs) {
1431
1432 // If this switch statement is modified, modify the comment in the declarations of
1433 // the type in {@link WindowManager.LayoutParams} as well.
1434 switch (attrs.type) {
1435 default:
1436 // These are the windows that by default are shown only to the user that created
1437 // them. If this needs to be overridden, set
1438 // {@link WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS} in
1439 // {@link WindowManager.LayoutParams}. Note that permission
1440 // {@link android.Manifest.permission.INTERNAL_SYSTEM_WINDOW} is required as well.
1441 if ((attrs.privateFlags & PRIVATE_FLAG_SHOW_FOR_ALL_USERS) == 0) {
1442 return true;
1443 }
1444 break;
1445
1446 // These are the windows that by default are shown to all users. However, to
1447 // protect against spoofing, check permissions below.
1448 case TYPE_APPLICATION_STARTING:
1449 case TYPE_BOOT_PROGRESS:
1450 case TYPE_DISPLAY_OVERLAY:
1451 case TYPE_HIDDEN_NAV_CONSUMER:
Jim Miller5ecd8112013-01-09 18:50:26 -08001452 case TYPE_KEYGUARD_SCRIM:
Craig Mautner88400d32012-09-30 12:35:45 -07001453 case TYPE_KEYGUARD_DIALOG:
1454 case TYPE_MAGNIFICATION_OVERLAY:
1455 case TYPE_NAVIGATION_BAR:
1456 case TYPE_NAVIGATION_BAR_PANEL:
1457 case TYPE_PHONE:
1458 case TYPE_POINTER:
1459 case TYPE_PRIORITY_PHONE:
1460 case TYPE_RECENTS_OVERLAY:
1461 case TYPE_SEARCH_BAR:
1462 case TYPE_STATUS_BAR:
1463 case TYPE_STATUS_BAR_PANEL:
1464 case TYPE_STATUS_BAR_SUB_PANEL:
1465 case TYPE_SYSTEM_DIALOG:
1466 case TYPE_UNIVERSE_BACKGROUND:
1467 case TYPE_VOLUME_OVERLAY:
keunyounga446bf02013-06-21 19:07:57 -07001468 case TYPE_PRIVATE_PRESENTATION:
Craig Mautner88400d32012-09-30 12:35:45 -07001469 break;
1470 }
1471
1472 // Check if third party app has set window to system window type.
1473 return mContext.checkCallingOrSelfPermission(
1474 android.Manifest.permission.INTERNAL_SYSTEM_WINDOW)
1475 != PackageManager.PERMISSION_GRANTED;
1476 }
1477
Craig Mautner967212c2013-04-13 21:10:58 -07001478 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001479 public void adjustWindowParamsLw(WindowManager.LayoutParams attrs) {
1480 switch (attrs.type) {
1481 case TYPE_SYSTEM_OVERLAY:
Jeff Brown3b2b3542010-10-15 00:54:27 -07001482 case TYPE_SECURE_SYSTEM_OVERLAY:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001483 // These types of windows can't receive input events.
1484 attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1485 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001486 attrs.flags &= ~WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001487 break;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001488 case TYPE_STATUS_BAR:
1489
1490 // If the Keyguard is in a hidden state (occluded by another window), we force to
1491 // remove the wallpaper and keyguard flag so that any change in-flight after setting
1492 // the keyguard as occluded wouldn't set these flags again.
1493 // See {@link #processKeyguardSetHiddenResultLw}.
1494 if (mKeyguardHidden) {
1495 attrs.flags &= ~WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
1496 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
1497 }
1498 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001499 }
Adrian Roos38502112014-04-09 21:04:11 +02001500
1501 if (attrs.type != TYPE_STATUS_BAR) {
1502 // The status bar is the only window allowed to exhibit keyguard behavior.
1503 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
1504 }
Adrian Roosea562512014-05-05 13:33:03 +02001505
1506 if (ActivityManager.isHighEndGfx()
1507 && (attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0) {
1508 attrs.subtreeSystemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_STABLE
1509 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
1510 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
1511 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001512 }
RoboErik8a2cfc32014-05-16 11:19:38 -07001513
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001514 void readLidState() {
Jeff Brown2e7760e2012-04-11 15:14:55 -07001515 mLidState = mWindowManagerFuncs.getLidState();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001516 }
RoboErik8a2cfc32014-05-16 11:19:38 -07001517
Jeff Browndaa37532012-05-01 15:54:03 -07001518 private boolean isHidden(int accessibilityMode) {
1519 switch (accessibilityMode) {
1520 case 1:
1521 return mLidState == LID_CLOSED;
1522 case 2:
1523 return mLidState == LID_OPEN;
1524 default:
1525 return false;
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001526 }
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001527 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001528
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001529 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07001530 @Override
Jeff Browndaa37532012-05-01 15:54:03 -07001531 public void adjustConfigurationLw(Configuration config, int keyboardPresence,
1532 int navigationPresence) {
1533 mHaveBuiltInKeyboard = (keyboardPresence & PRESENCE_INTERNAL) != 0;
1534
Jeff Brownf71343d2013-05-31 17:59:11 -07001535 readConfigurationDependentBehaviors();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001536 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07001537 applyLidSwitchState();
Jeff Brownd04a88c2011-01-16 14:05:47 -08001538
Jeff Browndaa37532012-05-01 15:54:03 -07001539 if (config.keyboard == Configuration.KEYBOARD_NOKEYS
1540 || (keyboardPresence == PRESENCE_INTERNAL
1541 && isHidden(mLidKeyboardAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001542 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_YES;
Jeff Browndaa37532012-05-01 15:54:03 -07001543 if (!mHasSoftInput) {
1544 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_YES;
1545 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001546 }
1547
Jeff Browndaa37532012-05-01 15:54:03 -07001548 if (config.navigation == Configuration.NAVIGATION_NONAV
1549 || (navigationPresence == PRESENCE_INTERNAL
1550 && isHidden(mLidNavigationAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001551 config.navigationHidden = Configuration.NAVIGATIONHIDDEN_YES;
Jeff Brownd04a88c2011-01-16 14:05:47 -08001552 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001553 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001554
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001555 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07001556 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001557 public int windowTypeToLayerLw(int type) {
1558 if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001559 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001560 }
1561 switch (type) {
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001562 case TYPE_UNIVERSE_BACKGROUND:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001563 return 1;
keunyounga446bf02013-06-21 19:07:57 -07001564 case TYPE_PRIVATE_PRESENTATION:
1565 return 2;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001566 case TYPE_WALLPAPER:
1567 // wallpaper is at the bottom, though the window manager may move it.
1568 return 2;
1569 case TYPE_PHONE:
1570 return 3;
1571 case TYPE_SEARCH_BAR:
1572 return 4;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001573 case TYPE_VOICE_INTERACTION:
1574 // voice interaction layer is almost immediately above apps.
1575 return 5;
Craig Mautner88400d32012-09-30 12:35:45 -07001576 case TYPE_RECENTS_OVERLAY:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001577 case TYPE_SYSTEM_DIALOG:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001578 return 6;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001579 case TYPE_TOAST:
1580 // toasts and the plugged-in battery thing
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001581 return 7;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001582 case TYPE_PRIORITY_PHONE:
1583 // SIM errors and unlock. Not sure if this really should be in a high layer.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001584 return 8;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001585 case TYPE_DREAM:
1586 // used for Dreams (screensavers with TYPE_DREAM windows)
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001587 return 9;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001588 case TYPE_SYSTEM_ALERT:
1589 // like the ANR / app crashed dialogs
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001590 return 10;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001591 case TYPE_INPUT_METHOD:
1592 // on-screen keyboards and other such input method user interfaces go here.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001593 return 11;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001594 case TYPE_INPUT_METHOD_DIALOG:
1595 // on-screen keyboards and other such input method user interfaces go here.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001596 return 12;
Jim Miller5ecd8112013-01-09 18:50:26 -08001597 case TYPE_KEYGUARD_SCRIM:
1598 // the safety window that shows behind keyguard while keyguard is starting
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001599 return 13;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001600 case TYPE_STATUS_BAR_SUB_PANEL:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001601 return 14;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001602 case TYPE_STATUS_BAR:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001603 return 15;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001604 case TYPE_STATUS_BAR_PANEL:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001605 return 16;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001606 case TYPE_KEYGUARD_DIALOG:
1607 return 17;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001608 case TYPE_VOLUME_OVERLAY:
1609 // the on-screen volume indicator and controller shown when the user
1610 // changes the device volume
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001611 return 18;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001612 case TYPE_SYSTEM_OVERLAY:
1613 // the on-screen volume indicator and controller shown when the user
1614 // changes the device volume
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001615 return 19;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001616 case TYPE_NAVIGATION_BAR:
1617 // the navigation bar, if available, shows atop most things
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001618 return 20;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001619 case TYPE_NAVIGATION_BAR_PANEL:
1620 // some panels (e.g. search) need to show on top of the navigation bar
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001621 return 21;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001622 case TYPE_SYSTEM_ERROR:
1623 // system-level error dialogs
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001624 return 22;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001625 case TYPE_MAGNIFICATION_OVERLAY:
1626 // used to highlight the magnified portion of a display
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001627 return 23;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001628 case TYPE_DISPLAY_OVERLAY:
1629 // used to simulate secondary display devices
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001630 return 24;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001631 case TYPE_DRAG:
1632 // the drag layer: input for drag-and-drop is associated with this window,
1633 // which sits above all other focusable windows
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001634 return 25;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001635 case TYPE_SECURE_SYSTEM_OVERLAY:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001636 return 26;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001637 case TYPE_BOOT_PROGRESS:
1638 return 27;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001639 case TYPE_POINTER:
1640 // the (mouse) pointer layer
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001641 return 28;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001642 case TYPE_HIDDEN_NAV_CONSUMER:
1643 return 29;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001644 }
1645 Log.e(TAG, "Unknown window type: " + type);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001646 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001647 }
1648
1649 /** {@inheritDoc} */
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001650 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001651 public int subWindowTypeToLayerLw(int type) {
1652 switch (type) {
1653 case TYPE_APPLICATION_PANEL:
1654 case TYPE_APPLICATION_ATTACHED_DIALOG:
1655 return APPLICATION_PANEL_SUBLAYER;
1656 case TYPE_APPLICATION_MEDIA:
1657 return APPLICATION_MEDIA_SUBLAYER;
Dianne Hackborn5cb8d792009-05-21 17:34:15 -07001658 case TYPE_APPLICATION_MEDIA_OVERLAY:
1659 return APPLICATION_MEDIA_OVERLAY_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001660 case TYPE_APPLICATION_SUB_PANEL:
1661 return APPLICATION_SUB_PANEL_SUBLAYER;
1662 }
1663 Log.e(TAG, "Unknown sub-window type: " + type);
1664 return 0;
1665 }
1666
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001667 @Override
Dianne Hackbornabe0da02009-09-18 01:55:39 -07001668 public int getMaxWallpaperLayer() {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001669 return windowTypeToLayerLw(TYPE_STATUS_BAR);
Dianne Hackbornabe0da02009-09-18 01:55:39 -07001670 }
1671
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001672 @Override
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001673 public int getAboveUniverseLayer() {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001674 return windowTypeToLayerLw(TYPE_SYSTEM_ERROR);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001675 }
1676
Jose Lima9546b202014-07-02 17:21:51 -07001677 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001678 public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07001679 if (mHasNavigationBar) {
1680 // For a basic navigation bar, when we are in landscape mode we place
1681 // the navigation bar to the side.
Daniel Sandler4a066c52012-04-20 14:49:13 -04001682 if (mNavigationBarCanMove && fullWidth > fullHeight) {
1683 return fullWidth - mNavigationBarWidthForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07001684 }
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001685 }
1686 return fullWidth;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001687 }
1688
Jose Lima9546b202014-07-02 17:21:51 -07001689 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001690 public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07001691 if (mHasNavigationBar) {
1692 // For a basic navigation bar, when we are in portrait mode we place
1693 // the navigation bar to the bottom.
Daniel Sandler4a066c52012-04-20 14:49:13 -04001694 if (!mNavigationBarCanMove || fullWidth < fullHeight) {
1695 return fullHeight - mNavigationBarHeightForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07001696 }
1697 }
1698 return fullHeight;
Dianne Hackborn69cb8752011-05-19 18:13:32 -07001699 }
1700
Jose Lima9546b202014-07-02 17:21:51 -07001701 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001702 public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation) {
1703 return getNonDecorDisplayWidth(fullWidth, fullHeight, rotation);
Dianne Hackborn69cb8752011-05-19 18:13:32 -07001704 }
1705
Jose Lima9546b202014-07-02 17:21:51 -07001706 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001707 public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation) {
John Spurlock80f00c12013-06-13 11:10:51 -04001708 // There is a separate status bar at the top of the display. We don't count that as part
1709 // of the fixed decor, since it can hide; however, for purposes of configurations,
Dianne Hackborn077ee852012-04-09 16:27:07 -07001710 // we do want to exclude it since applications can't generally use that part
1711 // of the screen.
John Spurlock80f00c12013-06-13 11:10:51 -04001712 return getNonDecorDisplayHeight(fullWidth, fullHeight, rotation) - mStatusBarHeight;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001713 }
1714
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001715 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07001716 public boolean isForceHiding(WindowManager.LayoutParams attrs) {
1717 return (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 ||
Adrian Roos69e510d2014-07-13 14:57:59 +02001718 (isKeyguardHostWindow(attrs) && isKeyguardSecureIncludingHidden()) ||
1719 (attrs.type == TYPE_KEYGUARD_SCRIM);
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07001720 }
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001721
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001722 @Override
Jorim Jaggi0d674622014-05-21 01:34:15 +02001723 public boolean isKeyguardHostWindow(WindowManager.LayoutParams attrs) {
1724 return attrs.type == TYPE_STATUS_BAR;
1725 }
1726
1727 @Override
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07001728 public boolean canBeForceHidden(WindowState win, WindowManager.LayoutParams attrs) {
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001729 switch (attrs.type) {
1730 case TYPE_STATUS_BAR:
1731 case TYPE_NAVIGATION_BAR:
1732 case TYPE_WALLPAPER:
1733 case TYPE_DREAM:
1734 case TYPE_UNIVERSE_BACKGROUND:
Jim Miller5ecd8112013-01-09 18:50:26 -08001735 case TYPE_KEYGUARD_SCRIM:
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001736 return false;
1737 default:
1738 return true;
1739 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07001740 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001741
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001742 /** {@inheritDoc} */
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001743 @Override
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07001744 public View addStartingWindow(IBinder appToken, String packageName, int theme,
1745 CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes,
Adam Powell04fe6eb2013-05-31 14:39:48 -07001746 int icon, int logo, int windowFlags) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001747 if (!SHOW_STARTING_ANIMATIONS) {
1748 return null;
1749 }
1750 if (packageName == null) {
1751 return null;
1752 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001753
Mathias Jeppssond1443e92012-08-24 15:25:32 +02001754 WindowManager wm = null;
1755 View view = null;
1756
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001757 try {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001758 Context context = mContext;
Craig Mautner6fbda632012-07-03 09:26:39 -07001759 if (DEBUG_STARTING_WINDOW) Slog.d(TAG, "addStartingWindow " + packageName
1760 + ": nonLocalizedLabel=" + nonLocalizedLabel + " theme="
1761 + Integer.toHexString(theme));
Dianne Hackborn247fe742011-01-08 17:25:57 -08001762 if (theme != context.getThemeResId() || labelRes != 0) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001763 try {
1764 context = context.createPackageContext(packageName, 0);
Dianne Hackborn247fe742011-01-08 17:25:57 -08001765 context.setTheme(theme);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001766 } catch (PackageManager.NameNotFoundException e) {
1767 // Ignore
1768 }
1769 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001770
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001771 Window win = PolicyManager.makeNewWindow(context);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001772 final TypedArray ta = win.getWindowStyle();
1773 if (ta.getBoolean(
1774 com.android.internal.R.styleable.Window_windowDisablePreview, false)
1775 || ta.getBoolean(
1776 com.android.internal.R.styleable.Window_windowShowWallpaper,false)) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001777 return null;
1778 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001779
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001780 Resources r = context.getResources();
1781 win.setTitle(r.getText(labelRes, nonLocalizedLabel));
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001782
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001783 win.setType(
1784 WindowManager.LayoutParams.TYPE_APPLICATION_STARTING);
1785 // Force the window flags: this is a fake window, so it is not really
1786 // touchable or focusable by the user. We also add in the ALT_FOCUSABLE_IM
1787 // flag because we do know that the next window will take input
1788 // focus, so we want to get the IME window up on top of us right away.
1789 win.setFlags(
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08001790 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001791 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
1792 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
1793 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08001794 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001795 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
1796 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
1797 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001798
Adam Powell04fe6eb2013-05-31 14:39:48 -07001799 win.setDefaultIcon(icon);
1800 win.setDefaultLogo(logo);
1801
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001802 win.setLayout(WindowManager.LayoutParams.MATCH_PARENT,
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07001803 WindowManager.LayoutParams.MATCH_PARENT);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001804
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001805 final WindowManager.LayoutParams params = win.getAttributes();
1806 params.token = appToken;
1807 params.packageName = packageName;
1808 params.windowAnimations = win.getWindowStyle().getResourceId(
1809 com.android.internal.R.styleable.Window_windowAnimationStyle, 0);
Dianne Hackborn5d927c22011-09-02 12:22:18 -07001810 params.privateFlags |=
1811 WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED;
Craig Mautner88400d32012-09-30 12:35:45 -07001812 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
Adam Lesinski95c42972013-10-02 10:13:27 -07001813
1814 if (!compatInfo.supportsScreen()) {
1815 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
1816 }
1817
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001818 params.setTitle("Starting " + packageName);
1819
Mathias Jeppssond1443e92012-08-24 15:25:32 +02001820 wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
1821 view = win.getDecorView();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001822
1823 if (win.isFloating()) {
1824 // Whoops, there is no way to display an animation/preview
1825 // of such a thing! After all that work... let's skip it.
1826 // (Note that we must do this here because it is in
1827 // getDecorView() where the theme is evaluated... maybe
1828 // we should peek the floating attribute from the theme
1829 // earlier.)
1830 return null;
1831 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001832
Craig Mautner6fbda632012-07-03 09:26:39 -07001833 if (DEBUG_STARTING_WINDOW) Slog.d(
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001834 TAG, "Adding starting window for " + packageName
1835 + " / " + appToken + ": "
1836 + (view.getParent() != null ? view : null));
1837
1838 wm.addView(view, params);
1839
1840 // Only return the view if it was successfully added to the
1841 // window manager... which we can tell by it having a parent.
1842 return view.getParent() != null ? view : null;
Jeff Brown98365d72012-08-19 20:30:52 -07001843 } catch (WindowManager.BadTokenException e) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001844 // ignore
Craig Mautner42bf39e2014-02-21 16:46:22 -08001845 Log.w(TAG, appToken + " already running, starting window not displayed. " +
1846 e.getMessage());
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001847 } catch (RuntimeException e) {
1848 // don't crash if something else bad happens, for example a
1849 // failure loading resources because we are loading from an app
1850 // on external storage that has been unmounted.
1851 Log.w(TAG, appToken + " failed creating starting window", e);
Mathias Jeppssond1443e92012-08-24 15:25:32 +02001852 } finally {
1853 if (view != null && view.getParent() == null) {
1854 Log.w(TAG, "view not successfully added to wm, removing view");
1855 wm.removeViewImmediate(view);
1856 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001857 }
1858
1859 return null;
1860 }
1861
1862 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07001863 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001864 public void removeStartingWindow(IBinder appToken, View window) {
Craig Mautner6fbda632012-07-03 09:26:39 -07001865 if (DEBUG_STARTING_WINDOW) {
1866 RuntimeException e = new RuntimeException("here");
1867 e.fillInStackTrace();
1868 Log.v(TAG, "Removing starting window for " + appToken + ": " + window, e);
1869 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001870
1871 if (window != null) {
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001872 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001873 wm.removeView(window);
1874 }
1875 }
1876
1877 /**
1878 * Preflight adding a window to the system.
RoboErik8a2cfc32014-05-16 11:19:38 -07001879 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001880 * Currently enforces that three window types are singletons:
1881 * <ul>
1882 * <li>STATUS_BAR_TYPE</li>
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001883 * <li>KEYGUARD_TYPE</li>
1884 * </ul>
RoboErik8a2cfc32014-05-16 11:19:38 -07001885 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001886 * @param win The window to be added
1887 * @param attrs Information about the window to be added
RoboErik8a2cfc32014-05-16 11:19:38 -07001888 *
Jeff Brown98365d72012-08-19 20:30:52 -07001889 * @return If ok, WindowManagerImpl.ADD_OKAY. If too many singletons,
1890 * WindowManagerImpl.ADD_MULTIPLE_SINGLETON
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001891 */
Jose Lima9546b202014-07-02 17:21:51 -07001892 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001893 public int prepareAddWindowLw(WindowState win, WindowManager.LayoutParams attrs) {
1894 switch (attrs.type) {
1895 case TYPE_STATUS_BAR:
Joe Onorato8bc6c512010-06-04 16:21:12 -04001896 mContext.enforceCallingOrSelfPermission(
1897 android.Manifest.permission.STATUS_BAR_SERVICE,
1898 "PhoneWindowManager");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001899 if (mStatusBar != null) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001900 if (mStatusBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07001901 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001902 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001903 }
1904 mStatusBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04001905 mStatusBarController.setWindow(win);
John Spurlock8fdfe622014-05-21 17:10:10 -04001906 mKeyguardDelegate.hideScrim();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001907 break;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04001908 case TYPE_NAVIGATION_BAR:
1909 mContext.enforceCallingOrSelfPermission(
1910 android.Manifest.permission.STATUS_BAR_SERVICE,
1911 "PhoneWindowManager");
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001912 if (mNavigationBar != null) {
1913 if (mNavigationBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07001914 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001915 }
1916 }
Daniel Sandler8956dbb2011-04-22 07:55:02 -04001917 mNavigationBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04001918 mNavigationBarController.setWindow(win);
Craig Mautnereda67292013-04-28 13:50:14 -07001919 if (DEBUG_LAYOUT) Slog.i(TAG, "NAVIGATION BAR: " + mNavigationBar);
Daniel Sandler8956dbb2011-04-22 07:55:02 -04001920 break;
Jim Millere898ac52012-04-06 17:10:57 -07001921 case TYPE_NAVIGATION_BAR_PANEL:
1922 mContext.enforceCallingOrSelfPermission(
1923 android.Manifest.permission.STATUS_BAR_SERVICE,
1924 "PhoneWindowManager");
1925 break;
Dianne Hackborn08743722009-12-21 12:16:51 -08001926 case TYPE_STATUS_BAR_PANEL:
Joe Onorato8bc6c512010-06-04 16:21:12 -04001927 mContext.enforceCallingOrSelfPermission(
1928 android.Manifest.permission.STATUS_BAR_SERVICE,
1929 "PhoneWindowManager");
Dianne Hackborn08743722009-12-21 12:16:51 -08001930 break;
Joe Onorato29fc2c92010-11-24 10:26:50 -08001931 case TYPE_STATUS_BAR_SUB_PANEL:
1932 mContext.enforceCallingOrSelfPermission(
1933 android.Manifest.permission.STATUS_BAR_SERVICE,
1934 "PhoneWindowManager");
Joe Onorato29fc2c92010-11-24 10:26:50 -08001935 break;
Jim Miller5ecd8112013-01-09 18:50:26 -08001936 case TYPE_KEYGUARD_SCRIM:
Jim Miller25190572013-02-28 17:36:24 -08001937 if (mKeyguardScrim != null) {
1938 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
1939 }
Jim Miller5ecd8112013-01-09 18:50:26 -08001940 mKeyguardScrim = win;
1941 break;
1942
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001943 }
Jeff Brown98365d72012-08-19 20:30:52 -07001944 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001945 }
1946
1947 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07001948 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001949 public void removeWindowLw(WindowState win) {
1950 if (mStatusBar == win) {
1951 mStatusBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04001952 mStatusBarController.setWindow(null);
Jim Millerc0b676d2013-03-22 16:11:08 -07001953 mKeyguardDelegate.showScrim();
Jim Miller5ecd8112013-01-09 18:50:26 -08001954 } else if (mKeyguardScrim == win) {
1955 Log.v(TAG, "Removing keyguard scrim");
1956 mKeyguardScrim = null;
1957 } if (mNavigationBar == win) {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04001958 mNavigationBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04001959 mNavigationBarController.setWindow(null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001960 }
1961 }
1962
1963 static final boolean PRINT_ANIM = false;
RoboErik8a2cfc32014-05-16 11:19:38 -07001964
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001965 /** {@inheritDoc} */
Craig Mautner4b71aa12012-12-27 17:20:01 -08001966 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001967 public int selectAnimationLw(WindowState win, int transit) {
1968 if (PRINT_ANIM) Log.i(TAG, "selectAnimation in " + win
1969 + ": transit=" + transit);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001970 if (win == mStatusBar) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001971 boolean isKeyguard = (win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001972 if (transit == TRANSIT_EXIT
1973 || transit == TRANSIT_HIDE) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001974 return isKeyguard ? -1 : R.anim.dock_top_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001975 } else if (transit == TRANSIT_ENTER
1976 || transit == TRANSIT_SHOW) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001977 return isKeyguard ? -1 : R.anim.dock_top_enter;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001978 }
1979 } else if (win == mNavigationBar) {
1980 // This can be on either the bottom or the right.
1981 if (mNavigationBarOnBottom) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08001982 if (transit == TRANSIT_EXIT
1983 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001984 return R.anim.dock_bottom_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001985 } else if (transit == TRANSIT_ENTER
1986 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001987 return R.anim.dock_bottom_enter;
1988 }
1989 } else {
Craig Mautner4b71aa12012-12-27 17:20:01 -08001990 if (transit == TRANSIT_EXIT
1991 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001992 return R.anim.dock_right_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001993 } else if (transit == TRANSIT_ENTER
1994 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001995 return R.anim.dock_right_enter;
1996 }
1997 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08001998 }
1999
2000 if (transit == TRANSIT_PREVIEW_DONE) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002001 if (win.hasAppShownWindows()) {
2002 if (PRINT_ANIM) Log.i(TAG, "**** STARTING EXIT");
2003 return com.android.internal.R.anim.app_starting_exit;
2004 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07002005 } else if (win.getAttrs().type == TYPE_DREAM && mDreamingLockscreen
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002006 && transit == TRANSIT_ENTER) {
2007 // Special case: we are animating in a dream, while the keyguard
2008 // is shown. We don't want an animation on the dream, because
2009 // we need it shown immediately with the keyguard animating away
2010 // to reveal it.
2011 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002012 }
2013
2014 return 0;
2015 }
2016
Craig Mautner3c174372013-02-21 17:54:37 -08002017 @Override
2018 public void selectRotationAnimationLw(int anim[]) {
2019 if (PRINT_ANIM) Slog.i(TAG, "selectRotationAnimation mTopFullscreen="
2020 + mTopFullscreenOpaqueWindowState + " rotationAnimation="
2021 + (mTopFullscreenOpaqueWindowState == null ?
2022 "0" : mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation));
2023 if (mTopFullscreenOpaqueWindowState != null && mTopIsFullscreen) {
2024 switch (mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation) {
2025 case ROTATION_ANIMATION_CROSSFADE:
2026 anim[0] = R.anim.rotation_animation_xfade_exit;
2027 anim[1] = R.anim.rotation_animation_enter;
2028 break;
2029 case ROTATION_ANIMATION_JUMPCUT:
2030 anim[0] = R.anim.rotation_animation_jump_exit;
2031 anim[1] = R.anim.rotation_animation_enter;
2032 break;
2033 case ROTATION_ANIMATION_ROTATE:
2034 default:
2035 anim[0] = anim[1] = 0;
2036 break;
2037 }
2038 } else {
2039 anim[0] = anim[1] = 0;
2040 }
2041 }
2042
2043 @Override
2044 public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId,
2045 boolean forceDefault) {
2046 switch (exitAnimId) {
2047 case R.anim.rotation_animation_xfade_exit:
2048 case R.anim.rotation_animation_jump_exit:
2049 // These are the only cases that matter.
2050 if (forceDefault) {
2051 return false;
2052 }
2053 int anim[] = new int[2];
2054 selectRotationAnimationLw(anim);
2055 return (exitAnimId == anim[0] && enterAnimId == anim[1]);
2056 default:
2057 return true;
2058 }
2059 }
2060
2061 @Override
Dianne Hackborn0c2acff2012-04-12 15:17:07 -07002062 public Animation createForceHideEnterAnimation(boolean onWallpaper) {
Jorim Jaggie29b2db2014-05-30 23:17:03 +02002063 return AnimationUtils.loadAnimation(mContext,
2064 com.android.internal.R.anim.lock_screen_behind_enter);
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002065 }
John Spurlockc8b46ca2013-04-08 12:59:26 -04002066
2067 private static void awakenDreams() {
2068 IDreamManager dreamManager = getDreamManager();
2069 if (dreamManager != null) {
2070 try {
2071 dreamManager.awaken();
2072 } catch (RemoteException e) {
2073 // fine, stay asleep then
2074 }
2075 }
2076 }
2077
2078 static IDreamManager getDreamManager() {
2079 return IDreamManager.Stub.asInterface(
2080 ServiceManager.checkService(DreamService.DREAM_SERVICE));
2081 }
2082
Santos Cordon9eb45932014-06-27 12:28:43 -07002083 TelecommManager getTelecommService() {
2084 return (TelecommManager) mContext.getSystemService(Context.TELECOMM_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002085 }
2086
Jeff Brown4d396052010-10-29 21:50:21 -07002087 static IAudioService getAudioService() {
2088 IAudioService audioService = IAudioService.Stub.asInterface(
2089 ServiceManager.checkService(Context.AUDIO_SERVICE));
2090 if (audioService == null) {
2091 Log.w(TAG, "Unable to find IAudioService interface.");
2092 }
2093 return audioService;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002094 }
2095
2096 boolean keyguardOn() {
2097 return keyguardIsShowingTq() || inKeyguardRestrictedKeyInputMode();
2098 }
2099
2100 private static final int[] WINDOW_TYPES_WHERE_HOME_DOESNT_WORK = {
2101 WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
2102 WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
2103 };
2104
2105 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002106 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002107 public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002108 final boolean keyguardOn = keyguardOn();
Jeff Brown1f245102010-11-18 20:53:46 -08002109 final int keyCode = event.getKeyCode();
2110 final int repeatCount = event.getRepeatCount();
2111 final int metaState = event.getMetaState();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002112 final int flags = event.getFlags();
Jeff Brown1f245102010-11-18 20:53:46 -08002113 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
2114 final boolean canceled = event.isCanceled();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002115
Jeff Brown40013652012-05-16 21:22:36 -07002116 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002117 Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount="
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002118 + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed
2119 + " canceled=" + canceled);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002120 }
2121
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002122 // If we think we might have a volume down & power key chord on the way
2123 // but we're not sure, then tell the dispatcher to wait a little while and
2124 // try again later before dispatching.
Christopher Tatee90585f2012-03-05 18:56:25 -08002125 if (mScreenshotChordEnabled && (flags & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002126 if (mVolumeDownKeyTriggered && !mPowerKeyTriggered) {
2127 final long now = SystemClock.uptimeMillis();
2128 final long timeoutTime = mVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS;
2129 if (now < timeoutTime) {
2130 return timeoutTime - now;
2131 }
2132 }
2133 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
2134 && mVolumeDownKeyConsumedByScreenshotChord) {
2135 if (!down) {
2136 mVolumeDownKeyConsumedByScreenshotChord = false;
2137 }
2138 return -1;
2139 }
2140 }
2141
Michael Wright6a62e552014-06-03 19:19:48 -07002142 // Cancel any pending meta actions if we see any other keys being pressed between the down
2143 // of the meta key and its corresponding up.
Michael Wrightce0c13a2014-07-30 10:49:21 -07002144 if (mPendingMetaAction && KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07002145 mPendingMetaAction = false;
2146 }
2147
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002148 // First we always handle the home key here, so applications
2149 // can never break it, although if keyguard is on, we do let
2150 // it handle it, because that gives us the correct 5 second
2151 // timeout.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002152 if (keyCode == KeyEvent.KEYCODE_HOME) {
Michael Jurka7f2668c2012-03-27 07:49:52 -07002153
Jeff Brown49ed71d2010-12-06 17:13:33 -08002154 // If we have released the home key, and didn't do anything else
2155 // while it was pressed, then it is time to go home!
Michael Jurka7f2668c2012-03-27 07:49:52 -07002156 if (!down) {
Jeff Browncaca8812013-05-09 13:34:33 -07002157 cancelPreloadRecentApps();
2158
Jeff Brown49ed71d2010-12-06 17:13:33 -08002159 mHomePressed = false;
Jeff Browncaca8812013-05-09 13:34:33 -07002160 if (mHomeConsumed) {
2161 mHomeConsumed = false;
Michael Jurka7f2668c2012-03-27 07:49:52 -07002162 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002163 }
Jeff Browncaca8812013-05-09 13:34:33 -07002164
2165 if (canceled) {
2166 Log.i(TAG, "Ignoring HOME; event canceled.");
2167 return -1;
2168 }
2169
2170 // If an incoming call is ringing, HOME is totally disabled.
Santos Cordon9eb45932014-06-27 12:28:43 -07002171 // (The user is already on the InCallUI at this point,
Jeff Browncaca8812013-05-09 13:34:33 -07002172 // and his ONLY options are to answer or reject the call.)
Santos Cordon9eb45932014-06-27 12:28:43 -07002173 TelecommManager telecommManager = getTelecommService();
2174 if (telecommManager != null && telecommManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07002175 Log.i(TAG, "Ignoring HOME; there's a ringing incoming call.");
2176 return -1;
Jeff Browncaca8812013-05-09 13:34:33 -07002177 }
2178
2179 // Delay handling home if a double-tap is possible.
2180 if (mDoubleTapOnHomeBehavior != DOUBLE_TAP_HOME_NOTHING) {
2181 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); // just in case
2182 mHomeDoubleTapPending = true;
2183 mHandler.postDelayed(mHomeDoubleTapTimeoutRunnable,
2184 ViewConfiguration.getDoubleTapTimeout());
2185 return -1;
2186 }
2187
Jose Lima9546b202014-07-02 17:21:51 -07002188 // If there's a dream running then use home to escape the dream
2189 // but don't actually go home.
2190 if (mDreamManagerInternal != null && mDreamManagerInternal.isDreaming()) {
Jeff Brownf6d46682014-07-17 22:44:20 -07002191 mDreamManagerInternal.stopDream(false /*immediate*/);
Jose Lima9546b202014-07-02 17:21:51 -07002192 return -1;
2193 }
2194
Jeff Browncaca8812013-05-09 13:34:33 -07002195 // Go home!
2196 launchHomeFromHotKey();
2197 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002198 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002199
2200 // If a system window has focus, then it doesn't make sense
2201 // right now to interact with applications.
2202 WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null;
2203 if (attrs != null) {
2204 final int type = attrs.type;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002205 if (type == WindowManager.LayoutParams.TYPE_KEYGUARD_SCRIM
2206 || type == WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG
2207 || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002208 // the "app" is keyguard, so give it the key
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002209 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002210 }
2211 final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length;
2212 for (int i=0; i<typeCount; i++) {
2213 if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) {
2214 // don't do anything, but also don't pass it to the app
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002215 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002216 }
2217 }
2218 }
Jeff Browncaca8812013-05-09 13:34:33 -07002219
2220 // Remember that home is pressed and handle special actions.
2221 if (repeatCount == 0) {
2222 mHomePressed = true;
2223 if (mHomeDoubleTapPending) {
2224 mHomeDoubleTapPending = false;
2225 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable);
2226 handleDoubleTapOnHome();
2227 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI
2228 || mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
2229 preloadRecentApps();
Michael Jurka7f2668c2012-03-27 07:49:52 -07002230 }
Jeff Browncaca8812013-05-09 13:34:33 -07002231 } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) {
2232 if (!keyguardOn) {
2233 handleLongPressOnHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002234 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002235 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002236 return -1;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002237 } else if (keyCode == KeyEvent.KEYCODE_MENU) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002238 // Hijack modified menu keys for debugging features
2239 final int chordBug = KeyEvent.META_SHIFT_ON;
2240
2241 if (down && repeatCount == 0) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002242 if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002243 Intent intent = new Intent(Intent.ACTION_BUG_REPORT);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002244 mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT,
2245 null, null, null, 0, null, null);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002246 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002247 } else if (SHOW_PROCESSES_ON_ALT_MENU &&
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002248 (metaState & KeyEvent.META_ALT_ON) == KeyEvent.META_ALT_ON) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002249 Intent service = new Intent();
2250 service.setClassName(mContext, "com.android.server.LoadAverageService");
2251 ContentResolver res = mContext.getContentResolver();
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002252 boolean shown = Settings.Global.getInt(
2253 res, Settings.Global.SHOW_PROCESSES, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002254 if (!shown) {
2255 mContext.startService(service);
2256 } else {
2257 mContext.stopService(service);
2258 }
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002259 Settings.Global.putInt(
2260 res, Settings.Global.SHOW_PROCESSES, shown ? 0 : 1);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002261 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002262 }
2263 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002264 } else if (keyCode == KeyEvent.KEYCODE_SEARCH) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002265 if (down) {
2266 if (repeatCount == 0) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002267 mSearchKeyShortcutPending = true;
2268 mConsumeSearchKeyUp = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002269 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002270 } else {
2271 mSearchKeyShortcutPending = false;
2272 if (mConsumeSearchKeyUp) {
2273 mConsumeSearchKeyUp = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002274 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002275 }
2276 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002277 return 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002278 } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) {
Michael Wrightc9ebea72013-01-16 19:25:02 -08002279 if (!keyguardOn) {
Jeff Browncaca8812013-05-09 13:34:33 -07002280 if (down && repeatCount == 0) {
2281 preloadRecentApps();
2282 } else if (!down) {
2283 toggleRecentApps();
Michael Wrightc9ebea72013-01-16 19:25:02 -08002284 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002285 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002286 return -1;
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002287 } else if (keyCode == KeyEvent.KEYCODE_ASSIST) {
2288 if (down) {
2289 if (repeatCount == 0) {
2290 mAssistKeyLongPressed = false;
2291 } else if (repeatCount == 1) {
2292 mAssistKeyLongPressed = true;
2293 if (!keyguardOn) {
2294 launchAssistLongPressAction();
2295 }
2296 }
2297 } else {
2298 if (mAssistKeyLongPressed) {
2299 mAssistKeyLongPressed = false;
2300 } else {
2301 if (!keyguardOn) {
2302 launchAssistAction();
2303 }
2304 }
2305 }
2306 return -1;
Jeff Sharkey2991fa32012-12-05 18:06:43 -08002307 } else if (keyCode == KeyEvent.KEYCODE_SYSRQ) {
2308 if (down && repeatCount == 0) {
2309 mHandler.post(mScreenshotRunnable);
2310 }
2311 return -1;
Michael Wrightb854e242013-02-05 17:54:02 -08002312 } else if (keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP
2313 || keyCode == KeyEvent.KEYCODE_BRIGHTNESS_DOWN) {
2314 if (down) {
2315 int direction = keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP ? 1 : -1;
2316
2317 // Disable autobrightness if it's on
2318 int auto = Settings.System.getIntForUser(
2319 mContext.getContentResolver(),
2320 Settings.System.SCREEN_BRIGHTNESS_MODE,
2321 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2322 UserHandle.USER_CURRENT_OR_SELF);
2323 if (auto != 0) {
2324 Settings.System.putIntForUser(mContext.getContentResolver(),
2325 Settings.System.SCREEN_BRIGHTNESS_MODE,
2326 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2327 UserHandle.USER_CURRENT_OR_SELF);
2328 }
2329
2330 int min = mPowerManager.getMinimumScreenBrightnessSetting();
2331 int max = mPowerManager.getMaximumScreenBrightnessSetting();
2332 int step = (max - min + BRIGHTNESS_STEPS - 1) / BRIGHTNESS_STEPS * direction;
2333 int brightness = Settings.System.getIntForUser(mContext.getContentResolver(),
2334 Settings.System.SCREEN_BRIGHTNESS,
2335 mPowerManager.getDefaultScreenBrightnessSetting(),
2336 UserHandle.USER_CURRENT_OR_SELF);
2337 brightness += step;
2338 // Make sure we don't go beyond the limits.
2339 brightness = Math.min(max, brightness);
2340 brightness = Math.max(min, brightness);
2341
2342 Settings.System.putIntForUser(mContext.getContentResolver(),
2343 Settings.System.SCREEN_BRIGHTNESS, brightness,
2344 UserHandle.USER_CURRENT_OR_SELF);
Alan Viverette5a399492014-07-14 16:19:38 -07002345 mContext.startActivityAsUser(new Intent(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG),
2346 UserHandle.CURRENT_OR_SELF);
Michael Wrightb854e242013-02-05 17:54:02 -08002347 }
2348 return -1;
Michael Wrightce0c13a2014-07-30 10:49:21 -07002349 } else if (KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07002350 if (down) {
2351 mPendingMetaAction = true;
2352 } else if (mPendingMetaAction) {
Michael Wright6a62e552014-06-03 19:19:48 -07002353 launchAssistAction();
2354 }
2355 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002356 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002357
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002358 // Shortcuts are invoked through Search+key, so intercept those here
Jeff Browncaab4d02010-12-09 22:13:41 -08002359 // Any printing key that is chorded with Search should be consumed
2360 // even if no shortcut was invoked. This prevents text from being
2361 // inadvertently inserted when using a keyboard that has built-in macro
2362 // shortcut keys (that emit Search+x) and some of them are not registered.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002363 if (mSearchKeyShortcutPending) {
Jeff Browncaab4d02010-12-09 22:13:41 -08002364 final KeyCharacterMap kcm = event.getKeyCharacterMap();
2365 if (kcm.isPrintingKey(keyCode)) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002366 mConsumeSearchKeyUp = true;
2367 mSearchKeyShortcutPending = false;
Jeff Browncaab4d02010-12-09 22:13:41 -08002368 if (down && repeatCount == 0 && !keyguardOn) {
2369 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState);
2370 if (shortcutIntent != null) {
2371 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002372 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002373 mContext.startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002374 } catch (ActivityNotFoundException ex) {
2375 Slog.w(TAG, "Dropping shortcut key combination because "
2376 + "the activity to which it is registered was not found: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002377 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode), ex);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002378 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002379 } else {
2380 Slog.i(TAG, "Dropping unregistered shortcut key combination: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002381 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002382 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002383 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002384 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002385 }
2386 }
2387
Jeff Brown68b909d2011-12-07 16:36:01 -08002388 // Invoke shortcuts using Meta.
Jeff Brown602ab322012-05-16 13:33:47 -07002389 if (down && repeatCount == 0 && !keyguardOn
Jeff Brown68b909d2011-12-07 16:36:01 -08002390 && (metaState & KeyEvent.META_META_ON) != 0) {
2391 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brown602ab322012-05-16 13:33:47 -07002392 if (kcm.isPrintingKey(keyCode)) {
2393 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode,
2394 metaState & ~(KeyEvent.META_META_ON
2395 | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON));
2396 if (shortcutIntent != null) {
2397 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2398 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002399 mContext.startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brown602ab322012-05-16 13:33:47 -07002400 } catch (ActivityNotFoundException ex) {
2401 Slog.w(TAG, "Dropping shortcut key combination because "
2402 + "the activity to which it is registered was not found: "
2403 + "META+" + KeyEvent.keyCodeToString(keyCode), ex);
2404 }
2405 return -1;
Jeff Brown68b909d2011-12-07 16:36:01 -08002406 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002407 }
2408 }
2409
Jeff Brown6651a632011-11-28 12:59:11 -08002410 // Handle application launch keys.
Jeff Brown602ab322012-05-16 13:33:47 -07002411 if (down && repeatCount == 0 && !keyguardOn) {
Jeff Brown6651a632011-11-28 12:59:11 -08002412 String category = sApplicationLaunchKeyCategories.get(keyCode);
2413 if (category != null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -08002414 Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category);
Jeff Brown6651a632011-11-28 12:59:11 -08002415 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2416 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002417 mContext.startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brown6651a632011-11-28 12:59:11 -08002418 } catch (ActivityNotFoundException ex) {
2419 Slog.w(TAG, "Dropping application launch key because "
2420 + "the activity to which it is registered was not found: "
2421 + "keyCode=" + keyCode + ", category=" + category, ex);
2422 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002423 return -1;
Jeff Brown6651a632011-11-28 12:59:11 -08002424 }
2425 }
2426
Jeff Brown68b909d2011-12-07 16:36:01 -08002427 // Display task switcher for ALT-TAB or Meta-TAB.
2428 if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_TAB) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002429 if (mRecentAppsHeldModifiers == 0 && !keyguardOn) {
Jeff Brown68b909d2011-12-07 16:36:01 -08002430 final int shiftlessModifiers = event.getModifiers() & ~KeyEvent.META_SHIFT_MASK;
Michael Wrightce0c13a2014-07-30 10:49:21 -07002431 if (KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_ALT_ON)
2432 || KeyEvent.metaStateHasModifiers(
2433 shiftlessModifiers, KeyEvent.META_META_ON)) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002434 mRecentAppsHeldModifiers = shiftlessModifiers;
2435 showRecentApps(true);
Jeff Brown68b909d2011-12-07 16:36:01 -08002436 return -1;
2437 }
2438 }
Winson Chung1e8d71b2014-05-16 17:05:22 -07002439 } else if (!down && mRecentAppsHeldModifiers != 0
2440 && (metaState & mRecentAppsHeldModifiers) == 0) {
2441 mRecentAppsHeldModifiers = 0;
Winson Chungcdcd4872014-08-05 18:00:13 -07002442 hideRecentApps(true, false);
Jeff Brown68b909d2011-12-07 16:36:01 -08002443 }
2444
Jeff Browncf39bdf2012-05-18 14:41:19 -07002445 // Handle keyboard language switching.
2446 if (down && repeatCount == 0
2447 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2448 || (keyCode == KeyEvent.KEYCODE_SPACE
2449 && (metaState & KeyEvent.META_CTRL_MASK) != 0))) {
2450 int direction = (metaState & KeyEvent.META_SHIFT_MASK) != 0 ? -1 : 1;
2451 mWindowManagerFuncs.switchKeyboardLayout(event.getDeviceId(), direction);
2452 return -1;
2453 }
2454 if (mLanguageSwitchKeyPressed && !down
2455 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2456 || keyCode == KeyEvent.KEYCODE_SPACE)) {
2457 mLanguageSwitchKeyPressed = false;
2458 return -1;
2459 }
2460
Justin Kohd378ad72013-04-01 12:18:26 -07002461 if (mGlobalKeyManager.handleGlobalKey(mContext, keyCode, event)) {
2462 return -1;
2463 }
2464
Michael Wright6a62e552014-06-03 19:19:48 -07002465 // Reserve all the META modifier combos for system behavior
Michael Wrightce0c13a2014-07-30 10:49:21 -07002466 if ((metaState & KeyEvent.META_META_ON) != 0) {
Michael Wright6a62e552014-06-03 19:19:48 -07002467 return -1;
2468 }
2469
Jeff Brown68b909d2011-12-07 16:36:01 -08002470 // Let the application handle the key.
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002471 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002472 }
2473
Jeff Brown3915bb82010-11-05 15:02:16 -07002474 /** {@inheritDoc} */
2475 @Override
Jeff Brown49ed71d2010-12-06 17:13:33 -08002476 public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown54875002011-04-06 15:33:01 -07002477 // Note: This method is only called if the initial down was unhandled.
Jeff Brown40013652012-05-16 21:22:36 -07002478 if (DEBUG_INPUT) {
Jeff Brown1f245102010-11-18 20:53:46 -08002479 Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction()
2480 + ", flags=" + event.getFlags()
2481 + ", keyCode=" + event.getKeyCode()
2482 + ", scanCode=" + event.getScanCode()
2483 + ", metaState=" + event.getMetaState()
2484 + ", repeatCount=" + event.getRepeatCount()
2485 + ", policyFlags=" + policyFlags);
Jeff Brown3915bb82010-11-05 15:02:16 -07002486 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002487
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002488 KeyEvent fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002489 if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
2490 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002491 final int keyCode = event.getKeyCode();
2492 final int metaState = event.getMetaState();
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002493 final boolean initialDown = event.getAction() == KeyEvent.ACTION_DOWN
2494 && event.getRepeatCount() == 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002495
Jeff Brown54875002011-04-06 15:33:01 -07002496 // Check for fallback actions specified by the key character map.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002497 final FallbackAction fallbackAction;
2498 if (initialDown) {
2499 fallbackAction = kcm.getFallbackAction(keyCode, metaState);
2500 } else {
2501 fallbackAction = mFallbackActions.get(keyCode);
2502 }
2503
2504 if (fallbackAction != null) {
Jeff Brown40013652012-05-16 21:22:36 -07002505 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002506 Slog.d(TAG, "Fallback: keyCode=" + fallbackAction.keyCode
2507 + " metaState=" + Integer.toHexString(fallbackAction.metaState));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002508 }
2509
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002510 final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK;
2511 fallbackEvent = KeyEvent.obtain(
Jeff Brown49ed71d2010-12-06 17:13:33 -08002512 event.getDownTime(), event.getEventTime(),
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002513 event.getAction(), fallbackAction.keyCode,
2514 event.getRepeatCount(), fallbackAction.metaState,
Jeff Brown49ed71d2010-12-06 17:13:33 -08002515 event.getDeviceId(), event.getScanCode(),
2516 flags, event.getSource(), null);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002517
2518 if (!interceptFallback(win, fallbackEvent, policyFlags)) {
2519 fallbackEvent.recycle();
2520 fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002521 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002522
2523 if (initialDown) {
2524 mFallbackActions.put(keyCode, fallbackAction);
2525 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2526 mFallbackActions.remove(keyCode);
2527 fallbackAction.recycle();
2528 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002529 }
2530 }
2531
Jeff Brown40013652012-05-16 21:22:36 -07002532 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002533 if (fallbackEvent == null) {
2534 Slog.d(TAG, "No fallback.");
2535 } else {
2536 Slog.d(TAG, "Performing fallback: " + fallbackEvent);
2537 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002538 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002539 return fallbackEvent;
Jeff Brown3915bb82010-11-05 15:02:16 -07002540 }
2541
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002542 private boolean interceptFallback(WindowState win, KeyEvent fallbackEvent, int policyFlags) {
Jeff Brown037c33e2014-04-09 00:31:55 -07002543 int actions = interceptKeyBeforeQueueing(fallbackEvent, policyFlags);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002544 if ((actions & ACTION_PASS_TO_USER) != 0) {
2545 long delayMillis = interceptKeyBeforeDispatching(
2546 win, fallbackEvent, policyFlags);
2547 if (delayMillis == 0) {
2548 return true;
2549 }
2550 }
2551 return false;
Jeff Brown6f2fba42011-02-19 01:08:02 -08002552 }
2553
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002554 private void launchAssistLongPressAction() {
2555 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
2556 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
2557
2558 // launch the search activity
2559 Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS);
2560 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2561 try {
RoboErik8a2cfc32014-05-16 11:19:38 -07002562 // TODO: This only stops the factory-installed search manager.
Jim Miller45308b12012-06-18 19:23:39 -07002563 // Need to formalize an API to handle others
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002564 SearchManager searchManager = getSearchManager();
2565 if (searchManager != null) {
2566 searchManager.stopSearch();
2567 }
Michael Wright43e27f72013-04-10 14:06:48 -07002568 mContext.startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002569 } catch (ActivityNotFoundException e) {
2570 Slog.w(TAG, "No activity to handle assist long press action.", e);
2571 }
2572 }
2573
2574 private void launchAssistAction() {
2575 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
Amith Yamasanic1d07a42012-08-14 09:32:02 -07002576 Intent intent = ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE))
Dianne Hackbornf9c5e0f2013-01-23 14:39:13 -08002577 .getAssistIntent(mContext, true, UserHandle.USER_CURRENT);
Jim Miller45308b12012-06-18 19:23:39 -07002578 if (intent != null) {
2579 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
2580 | Intent.FLAG_ACTIVITY_SINGLE_TOP
2581 | Intent.FLAG_ACTIVITY_CLEAR_TOP);
2582 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002583 mContext.startActivityAsUser(intent, UserHandle.CURRENT);
Jim Miller45308b12012-06-18 19:23:39 -07002584 } catch (ActivityNotFoundException e) {
2585 Slog.w(TAG, "No activity to handle assist action.", e);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002586 }
2587 }
2588 }
2589
2590 private SearchManager getSearchManager() {
2591 if (mSearchManager == null) {
2592 mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
2593 }
2594 return mSearchManager;
2595 }
2596
Jeff Browncaca8812013-05-09 13:34:33 -07002597 private void preloadRecentApps() {
2598 mPreloadedRecentApps = true;
2599 try {
2600 IStatusBarService statusbar = getStatusBarService();
2601 if (statusbar != null) {
2602 statusbar.preloadRecentApps();
2603 }
2604 } catch (RemoteException e) {
2605 Slog.e(TAG, "RemoteException when preloading recent apps", e);
2606 // re-acquire status bar service next time it is needed.
2607 mStatusBarService = null;
2608 }
2609 }
2610
2611 private void cancelPreloadRecentApps() {
2612 if (mPreloadedRecentApps) {
2613 mPreloadedRecentApps = false;
2614 try {
2615 IStatusBarService statusbar = getStatusBarService();
2616 if (statusbar != null) {
2617 statusbar.cancelPreloadRecentApps();
2618 }
2619 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002620 Slog.e(TAG, "RemoteException when cancelling recent apps preload", e);
Jeff Browncaca8812013-05-09 13:34:33 -07002621 // re-acquire status bar service next time it is needed.
2622 mStatusBarService = null;
2623 }
2624 }
2625 }
2626
2627 private void toggleRecentApps() {
2628 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
Jeff Browncaca8812013-05-09 13:34:33 -07002629 try {
2630 IStatusBarService statusbar = getStatusBarService();
2631 if (statusbar != null) {
2632 statusbar.toggleRecentApps();
2633 }
2634 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002635 Slog.e(TAG, "RemoteException when toggling recent apps", e);
2636 // re-acquire status bar service next time it is needed.
2637 mStatusBarService = null;
2638 }
2639 }
2640
Craig Mautner84984fa2014-06-19 11:19:20 -07002641 @Override
2642 public void showRecentApps() {
2643 mHandler.removeMessages(MSG_DISPATCH_SHOW_RECENTS);
2644 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_RECENTS);
2645 }
2646
Winson Chung1e8d71b2014-05-16 17:05:22 -07002647 private void showRecentApps(boolean triggeredFromAltTab) {
2648 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
2649 try {
2650 IStatusBarService statusbar = getStatusBarService();
2651 if (statusbar != null) {
2652 statusbar.showRecentApps(triggeredFromAltTab);
2653 }
2654 } catch (RemoteException e) {
Jeff Browncaca8812013-05-09 13:34:33 -07002655 Slog.e(TAG, "RemoteException when showing recent apps", e);
2656 // re-acquire status bar service next time it is needed.
2657 mStatusBarService = null;
2658 }
2659 }
2660
Winson Chungcdcd4872014-08-05 18:00:13 -07002661 private void hideRecentApps(boolean triggeredFromAltTab, boolean triggeredFromHome) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002662 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
2663 try {
2664 IStatusBarService statusbar = getStatusBarService();
2665 if (statusbar != null) {
Winson Chungcdcd4872014-08-05 18:00:13 -07002666 statusbar.hideRecentApps(triggeredFromAltTab, triggeredFromHome);
Winson Chung1e8d71b2014-05-16 17:05:22 -07002667 }
2668 } catch (RemoteException e) {
2669 Slog.e(TAG, "RemoteException when closing recent apps", e);
2670 // re-acquire status bar service next time it is needed.
2671 mStatusBarService = null;
2672 }
2673 }
2674
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002675 /**
2676 * A home key -> launch home action was detected. Take the appropriate action
2677 * given the situation with the keyguard.
2678 */
2679 void launchHomeFromHotKey() {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01002680 if (mKeyguardDelegate != null && mKeyguardDelegate.isShowingAndNotOccluded()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002681 // don't launch home if keyguard showing
Jim Miller5ecd8112013-01-09 18:50:26 -08002682 } else if (!mHideLockScreen && mKeyguardDelegate.isInputRestricted()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002683 // when in keyguard restricted mode, must first verify unlock
2684 // before launching home
Jim Miller5ecd8112013-01-09 18:50:26 -08002685 mKeyguardDelegate.verifyUnlock(new OnKeyguardExitResult() {
Jose Lima9546b202014-07-02 17:21:51 -07002686 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002687 public void onKeyguardExitResult(boolean success) {
2688 if (success) {
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07002689 try {
2690 ActivityManagerNative.getDefault().stopAppSwitches();
2691 } catch (RemoteException e) {
2692 }
Joe Onoratof275f0c2009-11-24 16:11:13 -05002693 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07002694 startDockOrHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002695 }
2696 }
2697 });
2698 } else {
2699 // no keyguard stuff to worry about, just launch home!
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07002700 try {
2701 ActivityManagerNative.getDefault().stopAppSwitches();
2702 } catch (RemoteException e) {
2703 }
Winson Chungd543c1b2014-06-23 15:06:45 -07002704 if (mRecentsVisible) {
2705 // Hide Recents and notify it to launch Home
2706 awakenDreams();
2707 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
Winson Chungcdcd4872014-08-05 18:00:13 -07002708 hideRecentApps(false, true);
Winson Chungd543c1b2014-06-23 15:06:45 -07002709 } else {
2710 // Otherwise, just launch Home
2711 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
2712 startDockOrHome();
2713 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002714 }
2715 }
2716
John Spurlock04db1762013-05-13 12:46:41 -04002717 private final Runnable mClearHideNavigationFlag = new Runnable() {
2718 @Override
2719 public void run() {
2720 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
2721 // Clear flags.
2722 mForceClearedSystemUiFlags &=
2723 ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
2724 }
2725 mWindowManagerFuncs.reevaluateStatusBarVisibility();
Dianne Hackborne26ab702011-10-16 13:21:33 -07002726 }
2727 };
2728
2729 /**
2730 * Input handler used while nav bar is hidden. Captures any touch on the screen,
2731 * to determine when the nav bar should be shown and prevent applications from
2732 * receiving those touches.
2733 */
Jeff Brown32cbc38552011-12-01 14:01:49 -08002734 final class HideNavInputEventReceiver extends InputEventReceiver {
2735 public HideNavInputEventReceiver(InputChannel inputChannel, Looper looper) {
2736 super(inputChannel, looper);
2737 }
2738
Dianne Hackborndf89e652011-10-06 22:35:11 -07002739 @Override
Jeff Brown32cbc38552011-12-01 14:01:49 -08002740 public void onInputEvent(InputEvent event) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07002741 boolean handled = false;
2742 try {
Jeff Brown4952dfd2011-11-30 19:23:22 -08002743 if (event instanceof MotionEvent
2744 && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
2745 final MotionEvent motionEvent = (MotionEvent)event;
2746 if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07002747 // When the user taps down, we re-show the nav bar.
2748 boolean changed = false;
John Spurlock04db1762013-05-13 12:46:41 -04002749 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002750 // Any user activity always causes us to show the
2751 // navigation controls, if they had been hidden.
2752 // We also clear the low profile and only content
2753 // flags so that tapping on the screen will atomically
2754 // restore all currently hidden screen decorations.
2755 int newVal = mResettingSystemUiFlags |
2756 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
2757 View.SYSTEM_UI_FLAG_LOW_PROFILE |
2758 View.SYSTEM_UI_FLAG_FULLSCREEN;
Dianne Hackborne26ab702011-10-16 13:21:33 -07002759 if (mResettingSystemUiFlags != newVal) {
2760 mResettingSystemUiFlags = newVal;
Dianne Hackborndf89e652011-10-06 22:35:11 -07002761 changed = true;
2762 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07002763 // We don't allow the system's nav bar to be hidden
2764 // again for 1 second, to prevent applications from
2765 // spamming us and keeping it from being shown.
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002766 newVal = mForceClearedSystemUiFlags |
2767 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
Dianne Hackborne26ab702011-10-16 13:21:33 -07002768 if (mForceClearedSystemUiFlags != newVal) {
2769 mForceClearedSystemUiFlags = newVal;
2770 changed = true;
John Spurlock04db1762013-05-13 12:46:41 -04002771 mHandler.postDelayed(mClearHideNavigationFlag, 1000);
Dianne Hackborne26ab702011-10-16 13:21:33 -07002772 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07002773 }
2774 if (changed) {
2775 mWindowManagerFuncs.reevaluateStatusBarVisibility();
2776 }
2777 }
2778 }
2779 } finally {
Jeff Brown32cbc38552011-12-01 14:01:49 -08002780 finishInputEvent(event, handled);
Dianne Hackborndf89e652011-10-06 22:35:11 -07002781 }
2782 }
Jeff Brown32cbc38552011-12-01 14:01:49 -08002783 }
2784 final InputEventReceiver.Factory mHideNavInputEventReceiverFactory =
2785 new InputEventReceiver.Factory() {
2786 @Override
2787 public InputEventReceiver createInputEventReceiver(
2788 InputChannel inputChannel, Looper looper) {
2789 return new HideNavInputEventReceiver(inputChannel, looper);
2790 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07002791 };
2792
2793 @Override
2794 public int adjustSystemUiVisibilityLw(int visibility) {
John Spurlock5b9145b2013-08-20 15:13:47 -04002795 mStatusBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
2796 mNavigationBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
Winson Chungd42a6cf2014-06-03 16:24:04 -07002797 mRecentsVisible = (visibility & View.RECENT_APPS_VISIBLE) > 0;
John Spurlock27735a42013-08-14 17:57:38 -04002798
Dianne Hackborndf89e652011-10-06 22:35:11 -07002799 // Reset any bits in mForceClearingStatusBarVisibility that
2800 // are now clear.
Dianne Hackborne26ab702011-10-16 13:21:33 -07002801 mResettingSystemUiFlags &= visibility;
Dianne Hackborndf89e652011-10-06 22:35:11 -07002802 // Clear any bits in the new visibility that are currently being
2803 // force cleared, before reporting it.
Dianne Hackborne26ab702011-10-16 13:21:33 -07002804 return visibility & ~mResettingSystemUiFlags
2805 & ~mForceClearedSystemUiFlags;
Dianne Hackborndf89e652011-10-06 22:35:11 -07002806 }
2807
Craig Mautner69b08182012-09-05 13:07:13 -07002808 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002809 public void getContentInsetHintLw(WindowManager.LayoutParams attrs, Rect contentInset) {
John Spurlockc6d1c602014-01-17 15:22:06 -05002810 final int fl = PolicyControl.getWindowFlags(null, attrs);
John Spurlock1db8b682014-02-18 11:18:59 -05002811 final int sysuiVis = PolicyControl.getSystemUiVisibility(null, attrs);
2812 final int systemUiVisibility = (sysuiVis | attrs.subtreeSystemUiVisibility);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002813
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002814 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002815 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002816 int availRight, availBottom;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07002817 if (canHideNavigationBar() &&
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002818 (systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002819 availRight = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
2820 availBottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
2821 } else {
2822 availRight = mRestrictedScreenLeft + mRestrictedScreenWidth;
2823 availBottom = mRestrictedScreenTop + mRestrictedScreenHeight;
2824 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002825 if ((systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
2826 if ((fl & FLAG_FULLSCREEN) != 0) {
2827 contentInset.set(mStableFullscreenLeft, mStableFullscreenTop,
2828 availRight - mStableFullscreenRight,
2829 availBottom - mStableFullscreenBottom);
2830 } else {
2831 contentInset.set(mStableLeft, mStableTop,
2832 availRight - mStableRight, availBottom - mStableBottom);
2833 }
Dianne Hackbornc652de82013-02-15 16:32:56 -08002834 } else if ((fl & FLAG_FULLSCREEN) != 0 || (fl & FLAG_LAYOUT_IN_OVERSCAN) != 0) {
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002835 contentInset.setEmpty();
2836 } else if ((systemUiVisibility & (View.SYSTEM_UI_FLAG_FULLSCREEN
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002837 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)) == 0) {
2838 contentInset.set(mCurLeft, mCurTop,
2839 availRight - mCurRight, availBottom - mCurBottom);
2840 } else {
2841 contentInset.set(mCurLeft, mCurTop,
2842 availRight - mCurRight, availBottom - mCurBottom);
2843 }
2844 return;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002845 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002846 contentInset.setEmpty();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002847 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002848
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002849 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07002850 @Override
2851 public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight,
2852 int displayRotation) {
Dianne Hackbornc652de82013-02-15 16:32:56 -08002853 final int overscanLeft, overscanTop, overscanRight, overscanBottom;
2854 if (isDefaultDisplay) {
2855 switch (displayRotation) {
2856 case Surface.ROTATION_90:
2857 overscanLeft = mOverscanTop;
2858 overscanTop = mOverscanRight;
2859 overscanRight = mOverscanBottom;
2860 overscanBottom = mOverscanLeft;
2861 break;
2862 case Surface.ROTATION_180:
2863 overscanLeft = mOverscanRight;
2864 overscanTop = mOverscanBottom;
2865 overscanRight = mOverscanLeft;
2866 overscanBottom = mOverscanTop;
2867 break;
2868 case Surface.ROTATION_270:
2869 overscanLeft = mOverscanBottom;
2870 overscanTop = mOverscanLeft;
2871 overscanRight = mOverscanTop;
2872 overscanBottom = mOverscanRight;
2873 break;
2874 default:
2875 overscanLeft = mOverscanLeft;
2876 overscanTop = mOverscanTop;
2877 overscanRight = mOverscanRight;
2878 overscanBottom = mOverscanBottom;
2879 break;
2880 }
2881 } else {
2882 overscanLeft = 0;
2883 overscanTop = 0;
2884 overscanRight = 0;
2885 overscanBottom = 0;
2886 }
Dianne Hackborn313440842013-02-19 19:22:59 -08002887 mOverscanScreenLeft = mRestrictedOverscanScreenLeft = 0;
2888 mOverscanScreenTop = mRestrictedOverscanScreenTop = 0;
2889 mOverscanScreenWidth = mRestrictedOverscanScreenWidth = displayWidth;
2890 mOverscanScreenHeight = mRestrictedOverscanScreenHeight = displayHeight;
Dianne Hackbornc652de82013-02-15 16:32:56 -08002891 mSystemLeft = 0;
2892 mSystemTop = 0;
2893 mSystemRight = displayWidth;
2894 mSystemBottom = displayHeight;
2895 mUnrestrictedScreenLeft = overscanLeft;
2896 mUnrestrictedScreenTop = overscanTop;
2897 mUnrestrictedScreenWidth = displayWidth - overscanLeft - overscanRight;
2898 mUnrestrictedScreenHeight = displayHeight - overscanTop - overscanBottom;
2899 mRestrictedScreenLeft = mUnrestrictedScreenLeft;
2900 mRestrictedScreenTop = mUnrestrictedScreenTop;
John Spurlockad3e6cb2013-04-30 08:47:43 -04002901 mRestrictedScreenWidth = mSystemGestures.screenWidth = mUnrestrictedScreenWidth;
2902 mRestrictedScreenHeight = mSystemGestures.screenHeight = mUnrestrictedScreenHeight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002903 mDockLeft = mContentLeft = mVoiceContentLeft = mStableLeft = mStableFullscreenLeft
Dianne Hackbornc652de82013-02-15 16:32:56 -08002904 = mCurLeft = mUnrestrictedScreenLeft;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002905 mDockTop = mContentTop = mVoiceContentTop = mStableTop = mStableFullscreenTop
Dianne Hackbornc652de82013-02-15 16:32:56 -08002906 = mCurTop = mUnrestrictedScreenTop;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002907 mDockRight = mContentRight = mVoiceContentRight = mStableRight = mStableFullscreenRight
Dianne Hackbornc652de82013-02-15 16:32:56 -08002908 = mCurRight = displayWidth - overscanRight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002909 mDockBottom = mContentBottom = mVoiceContentBottom = mStableBottom = mStableFullscreenBottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08002910 = mCurBottom = displayHeight - overscanBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002911 mDockLayer = 0x10000000;
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002912 mStatusBarLayer = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002913
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002914 // start with the current dock rect, which will be (0,0,displayWidth,displayHeight)
2915 final Rect pf = mTmpParentFrame;
2916 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002917 final Rect of = mTmpOverscanFrame;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002918 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04002919 final Rect dcf = mTmpDecorFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002920 pf.left = df.left = of.left = vf.left = mDockLeft;
2921 pf.top = df.top = of.top = vf.top = mDockTop;
2922 pf.right = df.right = of.right = vf.right = mDockRight;
2923 pf.bottom = df.bottom = of.bottom = vf.bottom = mDockBottom;
John Spurlock46646232013-09-30 22:32:42 -04002924 dcf.setEmpty(); // Decor frame N/A for system bars.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002925
Craig Mautner69b08182012-09-05 13:07:13 -07002926 if (isDefaultDisplay) {
2927 // For purposes of putting out fake window up to steal focus, we will
2928 // drive nav being hidden only by whether it is requested.
John Spurlocke1f366f2013-08-05 12:22:40 -04002929 final int sysui = mLastSystemUiFlags;
2930 boolean navVisible = (sysui & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0;
Adrian Roosea562512014-05-05 13:33:03 +02002931 boolean navTranslucent = (sysui
2932 & (View.NAVIGATION_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04002933 boolean immersive = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
2934 boolean immersiveSticky = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
2935 boolean navAllowedHidden = immersive || immersiveSticky;
2936 navTranslucent &= !immersiveSticky; // transient trumps translucent
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04002937 navTranslucent &= areTranslucentBarsAllowed();
Dianne Hackborne26ab702011-10-16 13:21:33 -07002938
Craig Mautner69b08182012-09-05 13:07:13 -07002939 // When the navigation bar isn't visible, we put up a fake
2940 // input window to catch all touch events. This way we can
2941 // detect when the user presses anywhere to bring back the nav
2942 // bar and ensure the application doesn't see the event.
John Spurlockf1a36642013-10-12 17:50:42 -04002943 if (navVisible || navAllowedHidden) {
Craig Mautner69b08182012-09-05 13:07:13 -07002944 if (mHideNavFakeWindow != null) {
2945 mHideNavFakeWindow.dismiss();
2946 mHideNavFakeWindow = null;
2947 }
2948 } else if (mHideNavFakeWindow == null) {
2949 mHideNavFakeWindow = mWindowManagerFuncs.addFakeWindow(
2950 mHandler.getLooper(), mHideNavInputEventReceiverFactory,
Adam Lesinski95c42972013-10-02 10:13:27 -07002951 "hidden nav", WindowManager.LayoutParams.TYPE_HIDDEN_NAV_CONSUMER, 0,
Craig Mautner69b08182012-09-05 13:07:13 -07002952 0, false, false, true);
Dianne Hackborne26ab702011-10-16 13:21:33 -07002953 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07002954
Craig Mautner69b08182012-09-05 13:07:13 -07002955 // For purposes of positioning and showing the nav bar, if we have
2956 // decided that it can't be hidden (because of the screen aspect ratio),
2957 // then take that into account.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07002958 navVisible |= !canHideNavigationBar();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002959
John Spurlockad3e6cb2013-04-30 08:47:43 -04002960 boolean updateSysUiVisibility = false;
Craig Mautner69b08182012-09-05 13:07:13 -07002961 if (mNavigationBar != null) {
John Spurlock27735a42013-08-14 17:57:38 -04002962 boolean transientNavBarShowing = mNavigationBarController.isTransientShowing();
Craig Mautner69b08182012-09-05 13:07:13 -07002963 // Force the navigation bar to its appropriate place and
2964 // size. We need to do this directly, instead of relying on
2965 // it to bubble up from the nav bar, because this needs to
2966 // change atomically with screen rotations.
2967 mNavigationBarOnBottom = (!mNavigationBarCanMove || displayWidth < displayHeight);
2968 if (mNavigationBarOnBottom) {
2969 // It's a system nav bar or a portrait screen; nav bar goes on bottom.
Dianne Hackbornc652de82013-02-15 16:32:56 -08002970 int top = displayHeight - overscanBottom
2971 - mNavigationBarHeightForRotation[displayRotation];
2972 mTmpNavigationFrame.set(0, top, displayWidth, displayHeight - overscanBottom);
Craig Mautner69b08182012-09-05 13:07:13 -07002973 mStableBottom = mStableFullscreenBottom = mTmpNavigationFrame.top;
John Spurlockf95b89a2013-10-10 22:10:42 -04002974 if (transientNavBarShowing) {
John Spurlock27735a42013-08-14 17:57:38 -04002975 mNavigationBarController.setBarShowingLw(true);
John Spurlockad3e6cb2013-04-30 08:47:43 -04002976 } else if (navVisible) {
John Spurlock27735a42013-08-14 17:57:38 -04002977 mNavigationBarController.setBarShowingLw(true);
Craig Mautner69b08182012-09-05 13:07:13 -07002978 mDockBottom = mTmpNavigationFrame.top;
Dianne Hackborn313440842013-02-19 19:22:59 -08002979 mRestrictedScreenHeight = mDockBottom - mRestrictedScreenTop;
2980 mRestrictedOverscanScreenHeight = mDockBottom - mRestrictedOverscanScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07002981 } else {
2982 // We currently want to hide the navigation UI.
John Spurlock27735a42013-08-14 17:57:38 -04002983 mNavigationBarController.setBarShowingLw(false);
Craig Mautner69b08182012-09-05 13:07:13 -07002984 }
John Spurlockc6d1c602014-01-17 15:22:06 -05002985 if (navVisible && !navTranslucent && !navAllowedHidden
2986 && !mNavigationBar.isAnimatingLw()
John Spurlockbd957402013-10-03 11:38:39 -04002987 && !mNavigationBarController.wasRecentlyTranslucent()) {
John Spurlocke1f366f2013-08-05 12:22:40 -04002988 // If the opaque nav bar is currently requested to be visible,
Craig Mautner69b08182012-09-05 13:07:13 -07002989 // and not in the process of animating on or off, then
2990 // we can tell the app that it is covered by it.
2991 mSystemBottom = mTmpNavigationFrame.top;
2992 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002993 } else {
Craig Mautner69b08182012-09-05 13:07:13 -07002994 // Landscape screen; nav bar goes to the right.
Dianne Hackbornc652de82013-02-15 16:32:56 -08002995 int left = displayWidth - overscanRight
2996 - mNavigationBarWidthForRotation[displayRotation];
2997 mTmpNavigationFrame.set(left, 0, displayWidth - overscanRight, displayHeight);
Craig Mautner69b08182012-09-05 13:07:13 -07002998 mStableRight = mStableFullscreenRight = mTmpNavigationFrame.left;
John Spurlockf95b89a2013-10-10 22:10:42 -04002999 if (transientNavBarShowing) {
John Spurlock27735a42013-08-14 17:57:38 -04003000 mNavigationBarController.setBarShowingLw(true);
John Spurlockad3e6cb2013-04-30 08:47:43 -04003001 } else if (navVisible) {
John Spurlock27735a42013-08-14 17:57:38 -04003002 mNavigationBarController.setBarShowingLw(true);
Craig Mautner69b08182012-09-05 13:07:13 -07003003 mDockRight = mTmpNavigationFrame.left;
Dianne Hackborn313440842013-02-19 19:22:59 -08003004 mRestrictedScreenWidth = mDockRight - mRestrictedScreenLeft;
3005 mRestrictedOverscanScreenWidth = mDockRight - mRestrictedOverscanScreenLeft;
Craig Mautner69b08182012-09-05 13:07:13 -07003006 } else {
3007 // We currently want to hide the navigation UI.
John Spurlock27735a42013-08-14 17:57:38 -04003008 mNavigationBarController.setBarShowingLw(false);
Craig Mautner69b08182012-09-05 13:07:13 -07003009 }
John Spurlockbd957402013-10-03 11:38:39 -04003010 if (navVisible && !navTranslucent && !mNavigationBar.isAnimatingLw()
3011 && !mNavigationBarController.wasRecentlyTranslucent()) {
Craig Mautner69b08182012-09-05 13:07:13 -07003012 // If the nav bar is currently requested to be visible,
3013 // and not in the process of animating on or off, then
3014 // we can tell the app that it is covered by it.
3015 mSystemRight = mTmpNavigationFrame.left;
3016 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003017 }
Craig Mautner69b08182012-09-05 13:07:13 -07003018 // Make sure the content and current rectangles are updated to
3019 // account for the restrictions from the navigation bar.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003020 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3021 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3022 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3023 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
Craig Mautner69b08182012-09-05 13:07:13 -07003024 mStatusBarLayer = mNavigationBar.getSurfaceLayer();
3025 // And compute the final frame.
3026 mNavigationBar.computeFrameLw(mTmpNavigationFrame, mTmpNavigationFrame,
Adrian Roosfa104232014-06-20 16:10:14 -07003027 mTmpNavigationFrame, mTmpNavigationFrame, mTmpNavigationFrame, dcf,
3028 mTmpNavigationFrame);
Craig Mautnereda67292013-04-28 13:50:14 -07003029 if (DEBUG_LAYOUT) Slog.i(TAG, "mNavigationBar frame: " + mTmpNavigationFrame);
John Spurlock27735a42013-08-14 17:57:38 -04003030 if (mNavigationBarController.checkHiddenLw()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04003031 updateSysUiVisibility = true;
3032 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003033 }
Craig Mautnereda67292013-04-28 13:50:14 -07003034 if (DEBUG_LAYOUT) Slog.i(TAG, String.format("mDock rect: (%d,%d - %d,%d)",
Craig Mautner69b08182012-09-05 13:07:13 -07003035 mDockLeft, mDockTop, mDockRight, mDockBottom));
3036
3037 // decide where the status bar goes ahead of time
3038 if (mStatusBar != null) {
3039 // apply any navigation bar insets
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003040 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3041 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3042 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
3043 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight
3044 + mUnrestrictedScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07003045 vf.left = mStableLeft;
3046 vf.top = mStableTop;
3047 vf.right = mStableRight;
3048 vf.bottom = mStableBottom;
3049
3050 mStatusBarLayer = mStatusBar.getSurfaceLayer();
3051
3052 // Let the status bar determine its size.
Adrian Roosfa104232014-06-20 16:10:14 -07003053 mStatusBar.computeFrameLw(pf, df, vf, vf, vf, dcf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07003054
3055 // For layout, the status bar is always at the top with our fixed height.
3056 mStableTop = mUnrestrictedScreenTop + mStatusBarHeight;
3057
John Spurlocke1f366f2013-08-05 12:22:40 -04003058 boolean statusBarTransient = (sysui & View.STATUS_BAR_TRANSIENT) != 0;
Adrian Roosea562512014-05-05 13:33:03 +02003059 boolean statusBarTranslucent = (sysui
3060 & (View.STATUS_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0;
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04003061 statusBarTranslucent &= areTranslucentBarsAllowed();
John Spurlock32beb2c2013-03-11 10:16:47 -04003062
Craig Mautner69b08182012-09-05 13:07:13 -07003063 // If the status bar is hidden, we don't want to cause
3064 // windows behind it to scroll.
John Spurlockeda1f692013-09-16 11:38:44 -04003065 if (mStatusBar.isVisibleLw() && !statusBarTransient) {
Craig Mautner69b08182012-09-05 13:07:13 -07003066 // Status bar may go away, so the screen area it occupies
3067 // is available to apps but just covering them when the
3068 // status bar is visible.
3069 mDockTop = mUnrestrictedScreenTop + mStatusBarHeight;
3070
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003071 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3072 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3073 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3074 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
Craig Mautner69b08182012-09-05 13:07:13 -07003075
Craig Mautnereda67292013-04-28 13:50:14 -07003076 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar: " +
Craig Mautner69b08182012-09-05 13:07:13 -07003077 String.format(
3078 "dock=[%d,%d][%d,%d] content=[%d,%d][%d,%d] cur=[%d,%d][%d,%d]",
3079 mDockLeft, mDockTop, mDockRight, mDockBottom,
3080 mContentLeft, mContentTop, mContentRight, mContentBottom,
3081 mCurLeft, mCurTop, mCurRight, mCurBottom));
3082 }
John Spurlocke1f366f2013-08-05 12:22:40 -04003083 if (mStatusBar.isVisibleLw() && !mStatusBar.isAnimatingLw()
John Spurlockbd957402013-10-03 11:38:39 -04003084 && !statusBarTransient && !statusBarTranslucent
3085 && !mStatusBarController.wasRecentlyTranslucent()) {
John Spurlocke1f366f2013-08-05 12:22:40 -04003086 // If the opaque status bar is currently requested to be visible,
Craig Mautner69b08182012-09-05 13:07:13 -07003087 // and not in the process of animating on or off, then
3088 // we can tell the app that it is covered by it.
3089 mSystemTop = mUnrestrictedScreenTop + mStatusBarHeight;
3090 }
John Spurlock27735a42013-08-14 17:57:38 -04003091 if (mStatusBarController.checkHiddenLw()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04003092 updateSysUiVisibility = true;
John Spurlock32beb2c2013-03-11 10:16:47 -04003093 }
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003094 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04003095 if (updateSysUiVisibility) {
3096 updateSystemUiVisibilityLw();
3097 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003098 }
3099 }
3100
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003101 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07003102 @Override
John Spurlock46646232013-09-30 22:32:42 -04003103 public int getSystemDecorLayerLw() {
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003104 if (mStatusBar != null) return mStatusBar.getSurfaceLayer();
3105 if (mNavigationBar != null) return mNavigationBar.getSurfaceLayer();
3106 return 0;
3107 }
3108
Craig Mautner967212c2013-04-13 21:10:58 -07003109 @Override
3110 public void getContentRectLw(Rect r) {
3111 r.set(mContentLeft, mContentTop, mContentRight, mContentBottom);
3112 }
3113
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003114 void setAttachedWindowFrames(WindowState win, int fl, int adjust, WindowState attached,
3115 boolean insetDecors, Rect pf, Rect df, Rect of, Rect cf, Rect vf) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003116 if (win.getSurfaceLayer() > mDockLayer && attached.getSurfaceLayer() < mDockLayer) {
3117 // Here's a special case: if this attached window is a panel that is
3118 // above the dock window, and the window it is attached to is below
3119 // the dock window, then the frames we computed for the window it is
3120 // attached to can not be used because the dock is effectively part
3121 // of the underlying window and the attached window is floating on top
3122 // of the whole thing. So, we ignore the attached window and explicitly
3123 // compute the frames that would be appropriate without the dock.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003124 df.left = of.left = cf.left = vf.left = mDockLeft;
3125 df.top = of.top = cf.top = vf.top = mDockTop;
3126 df.right = of.right = cf.right = vf.right = mDockRight;
3127 df.bottom = of.bottom = cf.bottom = vf.bottom = mDockBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003128 } else {
3129 // The effective display frame of the attached window depends on
3130 // whether it is taking care of insetting its content. If not,
3131 // we need to use the parent's content frame so that the entire
3132 // window is positioned within that content. Otherwise we can use
3133 // the display frame and let the attached window take care of
3134 // positioning its content appropriately.
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003135 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003136 cf.set(attached.getOverscanFrameLw());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003137 } else {
3138 // If the window is resizing, then we want to base the content
3139 // frame on our attached content frame to resize... however,
3140 // things can be tricky if the attached window is NOT in resize
3141 // mode, in which case its content frame will be larger.
3142 // Ungh. So to deal with that, make sure the content frame
3143 // we end up using is not covering the IM dock.
3144 cf.set(attached.getContentFrameLw());
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003145 if (attached.isVoiceInteraction()) {
3146 if (cf.left < mVoiceContentLeft) cf.left = mVoiceContentLeft;
3147 if (cf.top < mVoiceContentTop) cf.top = mVoiceContentTop;
3148 if (cf.right > mVoiceContentRight) cf.right = mVoiceContentRight;
3149 if (cf.bottom > mVoiceContentBottom) cf.bottom = mVoiceContentBottom;
3150 } else if (attached.getSurfaceLayer() < mDockLayer) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003151 if (cf.left < mContentLeft) cf.left = mContentLeft;
3152 if (cf.top < mContentTop) cf.top = mContentTop;
3153 if (cf.right > mContentRight) cf.right = mContentRight;
3154 if (cf.bottom > mContentBottom) cf.bottom = mContentBottom;
3155 }
3156 }
3157 df.set(insetDecors ? attached.getDisplayFrameLw() : cf);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003158 of.set(insetDecors ? attached.getOverscanFrameLw() : cf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003159 vf.set(attached.getVisibleFrameLw());
3160 }
3161 // The LAYOUT_IN_SCREEN flag is used to determine whether the attached
3162 // window should be positioned relative to its parent or the entire
3163 // screen.
3164 pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0
3165 ? attached.getFrameLw() : df);
3166 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003167
3168 private void applyStableConstraints(int sysui, int fl, Rect r) {
3169 if ((sysui & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
3170 // If app is requesting a stable layout, don't let the
3171 // content insets go below the stable values.
3172 if ((fl & FLAG_FULLSCREEN) != 0) {
3173 if (r.left < mStableFullscreenLeft) r.left = mStableFullscreenLeft;
3174 if (r.top < mStableFullscreenTop) r.top = mStableFullscreenTop;
3175 if (r.right > mStableFullscreenRight) r.right = mStableFullscreenRight;
3176 if (r.bottom > mStableFullscreenBottom) r.bottom = mStableFullscreenBottom;
3177 } else {
3178 if (r.left < mStableLeft) r.left = mStableLeft;
3179 if (r.top < mStableTop) r.top = mStableTop;
3180 if (r.right > mStableRight) r.right = mStableRight;
3181 if (r.bottom > mStableBottom) r.bottom = mStableBottom;
3182 }
3183 }
3184 }
3185
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003186 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07003187 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003188 public void layoutWindowLw(WindowState win, WindowState attached) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003189 // we've already done the status bar
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003190 final WindowManager.LayoutParams attrs = win.getAttrs();
3191 if ((win == mStatusBar && (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) == 0) ||
3192 win == mNavigationBar) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003193 return;
3194 }
Craig Mautner69b08182012-09-05 13:07:13 -07003195 final boolean isDefaultDisplay = win.isDefaultDisplay();
3196 final boolean needsToOffsetInputMethodTarget = isDefaultDisplay &&
satok1bc0a492012-04-25 22:47:12 +09003197 (win == mLastInputMethodTargetWindow && mLastInputMethodWindow != null);
3198 if (needsToOffsetInputMethodTarget) {
Craig Mautnereda67292013-04-28 13:50:14 -07003199 if (DEBUG_LAYOUT) Slog.i(TAG, "Offset ime target window by the last ime window state");
satok1bc0a492012-04-25 22:47:12 +09003200 offsetInputMethodWindowLw(mLastInputMethodWindow);
3201 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003202
John Spurlockc6d1c602014-01-17 15:22:06 -05003203 final int fl = PolicyControl.getWindowFlags(win, attrs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003204 final int sim = attrs.softInputMode;
John Spurlock1db8b682014-02-18 11:18:59 -05003205 final int sysUiFl = PolicyControl.getSystemUiVisibility(win, null);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003206
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003207 final Rect pf = mTmpParentFrame;
3208 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003209 final Rect of = mTmpOverscanFrame;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003210 final Rect cf = mTmpContentFrame;
3211 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04003212 final Rect dcf = mTmpDecorFrame;
Adrian Roosfa104232014-06-20 16:10:14 -07003213 final Rect sf = mTmpStableFrame;
John Spurlock46646232013-09-30 22:32:42 -04003214 dcf.setEmpty();
Craig Mautner69b08182012-09-05 13:07:13 -07003215
3216 final boolean hasNavBar = (isDefaultDisplay && mHasNavigationBar
Daniel Sandler36412a72011-08-04 09:35:13 -04003217 && mNavigationBar != null && mNavigationBar.isVisibleLw());
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003218
Craig Mautnerf683b562012-10-02 11:10:57 -07003219 final int adjust = sim & SOFT_INPUT_MASK_ADJUST;
3220
Adrian Roosfa104232014-06-20 16:10:14 -07003221 if (isDefaultDisplay) {
3222 sf.set(mStableLeft, mStableTop, mStableRight, mStableBottom);
3223 } else {
3224 sf.set(mOverscanLeft, mOverscanTop, mOverscanRight, mOverscanBottom);
3225 }
3226
Craig Mautner69b08182012-09-05 13:07:13 -07003227 if (!isDefaultDisplay) {
3228 if (attached != null) {
3229 // If this window is attached to another, our display
3230 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003231 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07003232 } else {
3233 // Give the window full screen.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003234 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3235 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3236 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08003237 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003238 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003239 = mOverscanScreenTop + mOverscanScreenHeight;
Craig Mautner69b08182012-09-05 13:07:13 -07003240 }
3241 } else if (attrs.type == TYPE_INPUT_METHOD) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003242 pf.left = df.left = of.left = cf.left = vf.left = mDockLeft;
3243 pf.top = df.top = of.top = cf.top = vf.top = mDockTop;
3244 pf.right = df.right = of.right = cf.right = vf.right = mDockRight;
John Spurlockc68d5772013-10-08 11:47:58 -04003245 // IM dock windows layout below the nav bar...
John Spurlock57beb3b2013-10-10 10:27:44 -04003246 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlockc68d5772013-10-08 11:47:58 -04003247 // ...with content insets above the nav bar
3248 cf.bottom = vf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003249 // IM dock windows always go to the bottom of the screen.
3250 attrs.gravity = Gravity.BOTTOM;
3251 mDockLayer = win.getSurfaceLayer();
3252 } else {
John Spurlock46646232013-09-30 22:32:42 -04003253
3254 // Default policy decor for the default display
3255 dcf.left = mSystemLeft;
3256 dcf.top = mSystemTop;
3257 dcf.right = mSystemRight;
3258 dcf.bottom = mSystemBottom;
John Spurlockbd957402013-10-03 11:38:39 -04003259 final boolean inheritTranslucentDecor = (attrs.privateFlags
3260 & WindowManager.LayoutParams.PRIVATE_FLAG_INHERIT_TRANSLUCENT_DECOR) != 0;
John Spurlock65567d42013-10-08 10:08:32 -04003261 final boolean isAppWindow =
3262 attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW &&
3263 attrs.type <= WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
3264 final boolean topAtRest =
3265 win == mTopFullscreenOpaqueWindowState && !win.isAnimatingLw();
3266 if (isAppWindow && !inheritTranslucentDecor && !topAtRest) {
John Spurlockbd957402013-10-03 11:38:39 -04003267 if ((sysUiFl & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0
3268 && (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0
Adrian Roosea562512014-05-05 13:33:03 +02003269 && (fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) == 0
3270 && (fl & WindowManager.LayoutParams.
3271 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04003272 // Ensure policy decor includes status bar
3273 dcf.top = mStableTop;
3274 }
John Spurlockbd957402013-10-03 11:38:39 -04003275 if ((fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) == 0
Adrian Roosea562512014-05-05 13:33:03 +02003276 && (sysUiFl & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0
3277 && (fl & WindowManager.LayoutParams.
3278 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04003279 // Ensure policy decor includes navigation bar
3280 dcf.bottom = mStableBottom;
3281 dcf.right = mStableRight;
3282 }
3283 }
3284
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003285 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
3286 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
RoboErik8a2cfc32014-05-16 11:19:38 -07003287 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003288 + "): IN_SCREEN, INSET_DECOR");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003289 // This is the case for a normal activity window: we want it
3290 // to cover all of the screen space, and it can take care of
3291 // moving its contents to account for screen decorations that
3292 // intrude into that space.
3293 if (attached != null) {
3294 // If this window is attached to another, our display
3295 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003296 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003297 } else {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003298 if (attrs.type == TYPE_STATUS_BAR_PANEL
3299 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Joe Onorato29fc2c92010-11-24 10:26:50 -08003300 // Status bar panels are the only windows who can go on top of
3301 // the status bar. They are protected by the STATUS_BAR_SERVICE
3302 // permission, so they have the same privileges as the status
3303 // bar itself.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003304 //
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003305 // However, they should still dodge the navigation bar if it exists.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003306
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003307 pf.left = df.left = of.left = hasNavBar
3308 ? mDockLeft : mUnrestrictedScreenLeft;
3309 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3310 pf.right = df.right = of.right = hasNavBar
3311 ? mRestrictedScreenLeft+mRestrictedScreenWidth
3312 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3313 pf.bottom = df.bottom = of.bottom = hasNavBar
3314 ? mRestrictedScreenTop+mRestrictedScreenHeight
3315 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003316
Craig Mautnereda67292013-04-28 13:50:14 -07003317 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003318 "Laying out status bar window: (%d,%d - %d,%d)",
3319 pf.left, pf.top, pf.right, pf.bottom));
John Spurlock46646232013-09-30 22:32:42 -04003320 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08003321 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3322 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3323 // Asking to layout into the overscan region, so give it that pure
3324 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003325 pf.left = df.left = of.left = mOverscanScreenLeft;
3326 pf.top = df.top = of.top = mOverscanScreenTop;
3327 pf.right = df.right = of.right = mOverscanScreenLeft + mOverscanScreenWidth;
3328 pf.bottom = df.bottom = of.bottom = mOverscanScreenTop
3329 + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003330 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003331 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003332 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3333 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003334 // Asking for layout as if the nav bar is hidden, lets the
Dianne Hackbornc652de82013-02-15 16:32:56 -08003335 // application extend into the unrestricted overscan screen area. We
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003336 // only do this for application windows to ensure no window that
3337 // can be above the nav bar can do this.
Dianne Hackborn313440842013-02-19 19:22:59 -08003338 pf.left = df.left = mOverscanScreenLeft;
3339 pf.top = df.top = mOverscanScreenTop;
3340 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
3341 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003342 // We need to tell the app about where the frame inside the overscan
3343 // is, so it can inset its content by that amount -- it didn't ask
3344 // to actually extend itself into the overscan region.
3345 of.left = mUnrestrictedScreenLeft;
3346 of.top = mUnrestrictedScreenTop;
3347 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3348 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003349 } else {
Dianne Hackborn313440842013-02-19 19:22:59 -08003350 pf.left = df.left = mRestrictedOverscanScreenLeft;
3351 pf.top = df.top = mRestrictedOverscanScreenTop;
3352 pf.right = df.right = mRestrictedOverscanScreenLeft
3353 + mRestrictedOverscanScreenWidth;
3354 pf.bottom = df.bottom = mRestrictedOverscanScreenTop
3355 + mRestrictedOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003356 // We need to tell the app about where the frame inside the overscan
3357 // is, so it can inset its content by that amount -- it didn't ask
3358 // to actually extend itself into the overscan region.
3359 of.left = mUnrestrictedScreenLeft;
3360 of.top = mUnrestrictedScreenTop;
3361 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3362 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003363 }
Craig Mautner69b08182012-09-05 13:07:13 -07003364
John Spurlock46646232013-09-30 22:32:42 -04003365 if ((fl & FLAG_FULLSCREEN) == 0) {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003366 if (win.isVoiceInteraction()) {
3367 cf.left = mVoiceContentLeft;
3368 cf.top = mVoiceContentTop;
3369 cf.right = mVoiceContentRight;
3370 cf.bottom = mVoiceContentBottom;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003371 } else {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003372 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
3373 cf.left = mDockLeft;
3374 cf.top = mDockTop;
3375 cf.right = mDockRight;
3376 cf.bottom = mDockBottom;
3377 } else {
3378 cf.left = mContentLeft;
3379 cf.top = mContentTop;
3380 cf.right = mContentRight;
3381 cf.bottom = mContentBottom;
3382 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003383 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003384 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003385 // Full screen windows are always given a layout that is as if the
3386 // status bar and other transient decors are gone. This is to avoid
3387 // bad states when moving from a window that is not hding the
3388 // status bar to one that is.
3389 cf.left = mRestrictedScreenLeft;
3390 cf.top = mRestrictedScreenTop;
3391 cf.right = mRestrictedScreenLeft + mRestrictedScreenWidth;
3392 cf.bottom = mRestrictedScreenTop + mRestrictedScreenHeight;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003393 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003394 applyStableConstraints(sysUiFl, fl, cf);
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003395 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3396 vf.left = mCurLeft;
3397 vf.top = mCurTop;
3398 vf.right = mCurRight;
3399 vf.bottom = mCurBottom;
3400 } else {
3401 vf.set(cf);
3402 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003403 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003404 } else if ((fl & FLAG_LAYOUT_IN_SCREEN) != 0 || (sysUiFl
3405 & (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
3406 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)) != 0) {
Craig Mautnereda67292013-04-28 13:50:14 -07003407 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3408 "): IN_SCREEN");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003409 // A window that has requested to fill the entire screen just
3410 // gets everything, period.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003411 if (attrs.type == TYPE_STATUS_BAR_PANEL
3412 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003413 pf.left = df.left = of.left = cf.left = hasNavBar
3414 ? mDockLeft : mUnrestrictedScreenLeft;
3415 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
3416 pf.right = df.right = of.right = cf.right = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003417 ? mRestrictedScreenLeft+mRestrictedScreenWidth
Dianne Hackbornc652de82013-02-15 16:32:56 -08003418 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003419 pf.bottom = df.bottom = of.bottom = cf.bottom = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003420 ? mRestrictedScreenTop+mRestrictedScreenHeight
Dianne Hackbornc652de82013-02-15 16:32:56 -08003421 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07003422 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler36412a72011-08-04 09:35:13 -04003423 "Laying out IN_SCREEN status bar window: (%d,%d - %d,%d)",
3424 pf.left, pf.top, pf.right, pf.bottom));
Jim Millere898ac52012-04-06 17:10:57 -07003425 } else if (attrs.type == TYPE_NAVIGATION_BAR
3426 || attrs.type == TYPE_NAVIGATION_BAR_PANEL) {
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003427 // The navigation bar has Real Ultimate Power.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003428 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3429 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3430 pf.right = df.right = of.right = mUnrestrictedScreenLeft
3431 + mUnrestrictedScreenWidth;
3432 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop
3433 + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07003434 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003435 "Laying out navigation bar window: (%d,%d - %d,%d)",
3436 pf.left, pf.top, pf.right, pf.bottom));
Dianne Hackborn01011c32012-02-21 13:54:21 -08003437 } else if ((attrs.type == TYPE_SECURE_SYSTEM_OVERLAY
3438 || attrs.type == TYPE_BOOT_PROGRESS)
Jeff Brownbfcb60a2011-09-08 18:51:14 -07003439 && ((fl & FLAG_FULLSCREEN) != 0)) {
3440 // Fullscreen secure system overlays get what they ask for.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003441 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3442 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3443 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
3444 + mOverscanScreenWidth;
3445 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
3446 + mOverscanScreenHeight;
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07003447 } else if (attrs.type == TYPE_BOOT_PROGRESS
3448 || attrs.type == TYPE_UNIVERSE_BACKGROUND) {
Dianne Hackborn01011c32012-02-21 13:54:21 -08003449 // Boot progress screen always covers entire display.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003450 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3451 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3452 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
3453 + mOverscanScreenWidth;
3454 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
3455 + mOverscanScreenHeight;
John Spurlockef4adae2013-08-26 17:58:58 -04003456 } else if (attrs.type == TYPE_WALLPAPER) {
3457 // The wallpaper also has Real Ultimate Power.
3458 pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft;
3459 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003460 pf.right = df.right = of.right = cf.right
John Spurlockef4adae2013-08-26 17:58:58 -04003461 = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003462 pf.bottom = df.bottom = of.bottom = cf.bottom
John Spurlockef4adae2013-08-26 17:58:58 -04003463 = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlock46646232013-09-30 22:32:42 -04003464 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08003465 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3466 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3467 // Asking to layout into the overscan region, so give it that pure
3468 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003469 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3470 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3471 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08003472 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003473 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003474 = mOverscanScreenTop + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003475 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003476 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Craig Mautnerbeac1062014-06-03 14:38:57 -07003477 && (attrs.type == TYPE_STATUS_BAR
3478 || attrs.type == TYPE_TOAST
John Spurlock34e13d92013-08-10 06:52:28 -04003479 || (attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3480 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW))) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003481 // Asking for layout as if the nav bar is hidden, lets the
3482 // application extend into the unrestricted screen area. We
John Spurlock34e13d92013-08-10 06:52:28 -04003483 // only do this for application windows (or toasts) to ensure no window that
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003484 // can be above the nav bar can do this.
3485 // XXX This assumes that an app asking for this will also
3486 // ask for layout in only content. We can't currently figure out
3487 // what the screen would be if only laying out to hide the nav bar.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003488 pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft;
3489 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
3490 pf.right = df.right = of.right = cf.right = mUnrestrictedScreenLeft
3491 + mUnrestrictedScreenWidth;
3492 pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop
3493 + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003494 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003495 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
3496 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
3497 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
3498 + mRestrictedScreenWidth;
3499 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
3500 + mRestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003501 }
Craig Mautner69b08182012-09-05 13:07:13 -07003502
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003503 applyStableConstraints(sysUiFl, fl, cf);
Craig Mautner69b08182012-09-05 13:07:13 -07003504
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003505 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3506 vf.left = mCurLeft;
3507 vf.top = mCurTop;
3508 vf.right = mCurRight;
3509 vf.bottom = mCurBottom;
3510 } else {
3511 vf.set(cf);
3512 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003513 } else if (attached != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07003514 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3515 "): attached to " + attached);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003516 // A child window should be placed inside of the same visible
3517 // frame that its parent had.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003518 setAttachedWindowFrames(win, fl, adjust, attached, false, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003519 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07003520 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3521 "): normal window");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003522 // Otherwise, a normal window must be placed inside the content
3523 // of all screen decorations.
Dianne Hackborna239c842011-06-01 12:28:20 -07003524 if (attrs.type == TYPE_STATUS_BAR_PANEL) {
3525 // Status bar panels are the only windows who can go on top of
3526 // the status bar. They are protected by the STATUS_BAR_SERVICE
3527 // permission, so they have the same privileges as the status
3528 // bar itself.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003529 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
3530 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
3531 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
3532 + mRestrictedScreenWidth;
3533 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
3534 + mRestrictedScreenHeight;
John Spurlock414c1f02013-12-04 13:47:36 -05003535 } else if (attrs.type == TYPE_TOAST || attrs.type == TYPE_SYSTEM_ALERT
3536 || attrs.type == TYPE_VOLUME_OVERLAY) {
3537 // These dialogs are stable to interim decor changes.
John Spurlockbd957402013-10-03 11:38:39 -04003538 pf.left = df.left = of.left = cf.left = mStableLeft;
3539 pf.top = df.top = of.top = cf.top = mStableTop;
3540 pf.right = df.right = of.right = cf.right = mStableRight;
3541 pf.bottom = df.bottom = of.bottom = cf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003542 } else {
Dianne Hackborna239c842011-06-01 12:28:20 -07003543 pf.left = mContentLeft;
3544 pf.top = mContentTop;
3545 pf.right = mContentRight;
3546 pf.bottom = mContentBottom;
Dianne Hackborn20d94742014-05-29 18:35:45 -07003547 if (win.isVoiceInteraction()) {
3548 df.left = of.left = cf.left = mVoiceContentLeft;
3549 df.top = of.top = cf.top = mVoiceContentTop;
3550 df.right = of.right = cf.right = mVoiceContentRight;
3551 df.bottom = of.bottom = cf.bottom = mVoiceContentBottom;
3552 } else if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003553 df.left = of.left = cf.left = mDockLeft;
3554 df.top = of.top = cf.top = mDockTop;
3555 df.right = of.right = cf.right = mDockRight;
3556 df.bottom = of.bottom = cf.bottom = mDockBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07003557 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003558 df.left = of.left = cf.left = mContentLeft;
3559 df.top = of.top = cf.top = mContentTop;
3560 df.right = of.right = cf.right = mContentRight;
3561 df.bottom = of.bottom = cf.bottom = mContentBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07003562 }
3563 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3564 vf.left = mCurLeft;
3565 vf.top = mCurTop;
3566 vf.right = mCurRight;
3567 vf.bottom = mCurBottom;
3568 } else {
3569 vf.set(cf);
3570 }
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003571 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003572 }
3573 }
Craig Mautner69b08182012-09-05 13:07:13 -07003574
Craig Mautnerb816bed2013-07-23 10:26:17 -07003575 // TYPE_SYSTEM_ERROR is above the NavigationBar so it can't be allowed to extend over it.
3576 if ((fl & FLAG_LAYOUT_NO_LIMITS) != 0 && attrs.type != TYPE_SYSTEM_ERROR) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003577 df.left = df.top = of.left = of.top = cf.left = cf.top = vf.left = vf.top = -10000;
3578 df.right = df.bottom = of.right = of.bottom = cf.right = cf.bottom
3579 = vf.right = vf.bottom = 10000;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003580 }
3581
Craig Mautnereda67292013-04-28 13:50:14 -07003582 if (DEBUG_LAYOUT) Slog.v(TAG, "Compute frame " + attrs.getTitle()
The Android Open Source Project11267662009-03-18 17:39:47 -07003583 + ": sim=#" + Integer.toHexString(sim)
RoboErik8a2cfc32014-05-16 11:19:38 -07003584 + " attach=" + attached + " type=" + attrs.type
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003585 + String.format(" flags=0x%08x", fl)
The Android Open Source Project11267662009-03-18 17:39:47 -07003586 + " pf=" + pf.toShortString() + " df=" + df.toShortString()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003587 + " of=" + of.toShortString()
John Spurlock46646232013-09-30 22:32:42 -04003588 + " cf=" + cf.toShortString() + " vf=" + vf.toShortString()
Adrian Roosfa104232014-06-20 16:10:14 -07003589 + " dcf=" + dcf.toShortString()
3590 + " sf=" + sf.toShortString());
Craig Mautner69b08182012-09-05 13:07:13 -07003591
Adrian Roosfa104232014-06-20 16:10:14 -07003592 win.computeFrameLw(pf, df, of, cf, vf, dcf, sf);
Craig Mautner69b08182012-09-05 13:07:13 -07003593
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003594 // Dock windows carve out the bottom of the screen, so normal windows
3595 // can't appear underneath them.
Craig Mautner8bd206b2012-10-03 10:32:02 -07003596 if (attrs.type == TYPE_INPUT_METHOD && win.isVisibleOrBehindKeyguardLw()
3597 && !win.getGivenInsetsPendingLw()) {
satok1bc0a492012-04-25 22:47:12 +09003598 setLastInputMethodWindowLw(null, null);
3599 offsetInputMethodWindowLw(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003600 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003601 if (attrs.type == TYPE_VOICE_INTERACTION && win.isVisibleOrBehindKeyguardLw()
3602 && !win.getGivenInsetsPendingLw()) {
3603 offsetVoiceInputWindowLw(win);
3604 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003605 }
3606
satok1bc0a492012-04-25 22:47:12 +09003607 private void offsetInputMethodWindowLw(WindowState win) {
3608 int top = win.getContentFrameLw().top;
3609 top += win.getGivenContentInsetsLw().top;
3610 if (mContentBottom > top) {
3611 mContentBottom = top;
3612 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003613 if (mVoiceContentBottom > top) {
3614 mVoiceContentBottom = top;
3615 }
satok1bc0a492012-04-25 22:47:12 +09003616 top = win.getVisibleFrameLw().top;
3617 top += win.getGivenVisibleInsetsLw().top;
3618 if (mCurBottom > top) {
3619 mCurBottom = top;
3620 }
Craig Mautnereda67292013-04-28 13:50:14 -07003621 if (DEBUG_LAYOUT) Slog.v(TAG, "Input method: mDockBottom="
satok1bc0a492012-04-25 22:47:12 +09003622 + mDockBottom + " mContentBottom="
3623 + mContentBottom + " mCurBottom=" + mCurBottom);
3624 }
3625
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003626 private void offsetVoiceInputWindowLw(WindowState win) {
3627 final int gravity = win.getAttrs().gravity;
3628 switch (gravity&((Gravity.AXIS_PULL_BEFORE|Gravity.AXIS_PULL_AFTER)
3629 << Gravity.AXIS_X_SHIFT)) {
3630 case Gravity.AXIS_PULL_BEFORE<<Gravity.AXIS_X_SHIFT: {
3631 int right = win.getContentFrameLw().right - win.getGivenContentInsetsLw().right;
3632 if (mVoiceContentLeft < right) {
3633 mVoiceContentLeft = right;
3634 }
3635 } break;
3636 case Gravity.AXIS_PULL_AFTER<<Gravity.AXIS_X_SHIFT: {
3637 int left = win.getContentFrameLw().left - win.getGivenContentInsetsLw().left;
3638 if (mVoiceContentRight < left) {
3639 mVoiceContentRight = left;
3640 }
3641 } break;
3642 }
3643 switch (gravity&((Gravity.AXIS_PULL_BEFORE|Gravity.AXIS_PULL_AFTER)
3644 << Gravity.AXIS_Y_SHIFT)) {
3645 case Gravity.AXIS_PULL_BEFORE<<Gravity.AXIS_Y_SHIFT: {
3646 int bottom = win.getContentFrameLw().bottom - win.getGivenContentInsetsLw().bottom;
3647 if (mVoiceContentTop < bottom) {
3648 mVoiceContentTop = bottom;
3649 }
3650 } break;
3651 case Gravity.AXIS_PULL_AFTER<<Gravity.AXIS_Y_SHIFT: {
3652 int top = win.getContentFrameLw().top - win.getGivenContentInsetsLw().top;
3653 if (mVoiceContentBottom < top) {
3654 mVoiceContentBottom = top;
3655 }
3656 } break;
3657 }
3658 }
3659
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003660 /** {@inheritDoc} */
Craig Mautner61ac6bb2012-02-02 17:29:33 -08003661 @Override
3662 public void finishLayoutLw() {
3663 return;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003664 }
3665
3666 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003667 @Override
Craig Mautner39834192012-09-02 07:47:24 -07003668 public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) {
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003669 mTopFullscreenOpaqueWindowState = null;
Craig Mautner2bc789b2014-03-19 19:48:38 -07003670 mAppsToBeHidden.clear();
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003671 mForceStatusBar = false;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003672 mForceStatusBarFromKeyguard = false;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08003673 mForcingShowNavBar = false;
3674 mForcingShowNavBarLayer = -1;
RoboErik8a2cfc32014-05-16 11:19:38 -07003675
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003676 mHideLockScreen = false;
3677 mAllowLockscreenWhenOn = false;
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003678 mDismissKeyguard = DISMISS_KEYGUARD_NONE;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003679 mShowingLockscreen = false;
3680 mShowingDream = false;
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003681 mWinShowWhenLocked = null;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003682 }
3683
3684 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003685 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003686 public void applyPostLayoutPolicyLw(WindowState win, WindowManager.LayoutParams attrs) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07003687 if (DEBUG_LAYOUT) Slog.i(TAG, "Win " + win + ": isVisibleOrBehindKeyguardLw="
3688 + win.isVisibleOrBehindKeyguardLw());
John Spurlockc6d1c602014-01-17 15:22:06 -05003689 final int fl = PolicyControl.getWindowFlags(win, attrs);
John Spurlock414c1f02013-12-04 13:47:36 -05003690 if (mTopFullscreenOpaqueWindowState == null
3691 && win.isVisibleLw() && attrs.type == TYPE_INPUT_METHOD) {
3692 mForcingShowNavBar = true;
3693 mForcingShowNavBarLayer = win.getSurfaceLayer();
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08003694 }
Jorim Jaggiafd4a552014-04-08 15:13:05 +02003695 if (attrs.type == TYPE_STATUS_BAR && (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Jorim Jaggiafd4a552014-04-08 15:13:05 +02003696 mForceStatusBarFromKeyguard = true;
3697 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003698 if (mTopFullscreenOpaqueWindowState == null &&
Dianne Hackborn01b02a72012-01-12 14:05:03 -08003699 win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()) {
John Spurlockc6d1c602014-01-17 15:22:06 -05003700 if ((fl & FLAG_FORCE_NOT_FULLSCREEN) != 0) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003701 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003702 mForceStatusBarFromKeyguard = true;
3703 } else {
3704 mForceStatusBar = true;
3705 }
3706 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003707 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003708 mShowingLockscreen = true;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07003709 }
Craig Mautnerab55e522014-03-03 13:26:03 -08003710 boolean appWindow = attrs.type >= FIRST_APPLICATION_WINDOW
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003711 && attrs.type <= LAST_APPLICATION_WINDOW;
3712 if (attrs.type == TYPE_DREAM) {
Jeff Brownc8018eb2012-10-29 21:33:27 -07003713 // If the lockscreen was showing when the dream started then wait
3714 // for the dream to draw before hiding the lockscreen.
3715 if (!mDreamingLockscreen
3716 || (win.isVisibleLw() && win.hasDrawnLw())) {
3717 mShowingDream = true;
Craig Mautnerab55e522014-03-03 13:26:03 -08003718 appWindow = true;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003719 }
3720 }
Craig Mautnerab55e522014-03-03 13:26:03 -08003721
Craig Mautner00156ec2014-03-06 22:29:02 -08003722 final boolean showWhenLocked = (fl & FLAG_SHOW_WHEN_LOCKED) != 0;
Craig Mautner74ee9382014-04-01 15:20:16 -07003723 final boolean dismissKeyguard = (fl & FLAG_DISMISS_KEYGUARD) != 0;
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003724 final boolean secureKeyguard = isKeyguardSecure();
Craig Mautnerab55e522014-03-03 13:26:03 -08003725 if (appWindow) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003726 if (showWhenLocked || (dismissKeyguard && !secureKeyguard)) {
3727 // Remove any previous windows with the same appToken.
Craig Mautner2bc789b2014-03-19 19:48:38 -07003728 mAppsToBeHidden.remove(win.getAppToken());
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003729 if (mAppsToBeHidden.isEmpty() && showWhenLocked &&
3730 isKeyguardSecureIncludingHidden()) {
3731 mWinShowWhenLocked = win;
3732 mHideLockScreen = true;
3733 mForceStatusBarFromKeyguard = false;
3734 }
Craig Mautner2bc789b2014-03-19 19:48:38 -07003735 } else {
3736 mAppsToBeHidden.add(win.getAppToken());
3737 }
Craig Mautnerab55e522014-03-03 13:26:03 -08003738 if (attrs.x == 0 && attrs.y == 0
3739 && attrs.width == WindowManager.LayoutParams.MATCH_PARENT
3740 && attrs.height == WindowManager.LayoutParams.MATCH_PARENT) {
3741 if (DEBUG_LAYOUT) Slog.v(TAG, "Fullscreen window: " + win);
3742 mTopFullscreenOpaqueWindowState = win;
Craig Mautner2bc789b2014-03-19 19:48:38 -07003743 if (mAppsToBeHidden.isEmpty()) {
Craig Mautnerda09ae32014-03-03 13:26:03 -08003744 if (showWhenLocked) {
3745 if (DEBUG_LAYOUT) Slog.v(TAG,
3746 "Setting mHideLockScreen to true by win " + win);
3747 mHideLockScreen = true;
3748 mForceStatusBarFromKeyguard = false;
3749 }
Craig Mautner4bdab6b2014-04-01 12:05:11 -07003750 if (dismissKeyguard && mDismissKeyguard == DISMISS_KEYGUARD_NONE) {
Craig Mautnerda09ae32014-03-03 13:26:03 -08003751 if (DEBUG_LAYOUT) Slog.v(TAG,
3752 "Setting mDismissKeyguard true by win " + win);
3753 mDismissKeyguard = mWinDismissingKeyguard == win ?
3754 DISMISS_KEYGUARD_CONTINUE : DISMISS_KEYGUARD_START;
3755 mWinDismissingKeyguard = win;
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003756 mForceStatusBarFromKeyguard = mShowingLockscreen && secureKeyguard;
Craig Mautnerda09ae32014-03-03 13:26:03 -08003757 }
Craig Mautnerab55e522014-03-03 13:26:03 -08003758 }
Craig Mautner00156ec2014-03-06 22:29:02 -08003759 if ((fl & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) {
Craig Mautnerab55e522014-03-03 13:26:03 -08003760 mAllowLockscreenWhenOn = true;
3761 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003762 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003763
3764 if (mWinShowWhenLocked != null &&
3765 mWinShowWhenLocked.getAppToken() != win.getAppToken()) {
3766 win.hideLw(false);
3767 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003768 }
3769 }
3770 }
3771
3772 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003773 @Override
Craig Mautner39834192012-09-02 07:47:24 -07003774 public int finishPostLayoutPolicyLw() {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003775 if (mWinShowWhenLocked != null &&
3776 mWinShowWhenLocked != mTopFullscreenOpaqueWindowState) {
3777 // A dialog is dismissing the keyguard. Put the wallpaper behind it and hide the
3778 // fullscreen window.
3779 // TODO: Make sure FLAG_SHOW_WALLPAPER is restored when dialog is dismissed. Or not.
3780 mWinShowWhenLocked.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
3781 mTopFullscreenOpaqueWindowState.hideLw(false);
3782 mTopFullscreenOpaqueWindowState = mWinShowWhenLocked;
3783 }
3784
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003785 int changes = 0;
Joe Onorato93056472010-09-10 10:30:46 -04003786 boolean topIsFullscreen = false;
Daniel Sandlere02d8082010-10-08 15:13:22 -04003787
3788 final WindowManager.LayoutParams lp = (mTopFullscreenOpaqueWindowState != null)
3789 ? mTopFullscreenOpaqueWindowState.getAttrs()
3790 : null;
3791
Jeff Brownc8018eb2012-10-29 21:33:27 -07003792 // If we are not currently showing a dream then remember the current
3793 // lockscreen state. We will use this to determine whether the dream
3794 // started while the lockscreen was showing and remember this state
3795 // while the dream is showing.
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003796 if (!mShowingDream) {
3797 mDreamingLockscreen = mShowingLockscreen;
3798 }
3799
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003800 if (mStatusBar != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07003801 if (DEBUG_LAYOUT) Slog.i(TAG, "force=" + mForceStatusBar
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003802 + " forcefkg=" + mForceStatusBarFromKeyguard
Dianne Hackbornd70bc2f2009-10-06 23:25:51 -07003803 + " top=" + mTopFullscreenOpaqueWindowState);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003804 if (mForceStatusBar || mForceStatusBarFromKeyguard) {
Craig Mautnereda67292013-04-28 13:50:14 -07003805 if (DEBUG_LAYOUT) Slog.v(TAG, "Showing status bar: forced");
John Spurlock27735a42013-08-14 17:57:38 -04003806 if (mStatusBarController.setBarShowingLw(true)) {
3807 changes |= FINISH_LAYOUT_REDO_LAYOUT;
3808 }
Craig Mautner81defc72013-10-29 11:10:42 -07003809 // Maintain fullscreen layout until incoming animation is complete.
3810 topIsFullscreen = mTopIsFullscreen && mStatusBar.isAnimatingLw();
John Spurlockf92b6162013-11-11 15:01:16 -05003811 // Transient status bar on the lockscreen is not allowed
3812 if (mForceStatusBarFromKeyguard && mStatusBarController.isTransientShowing()) {
3813 mStatusBarController.updateVisibilityLw(false /*transientAllowed*/,
3814 mLastSystemUiFlags, mLastSystemUiFlags);
3815 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003816 } else if (mTopFullscreenOpaqueWindowState != null) {
John Spurlockc6d1c602014-01-17 15:22:06 -05003817 final int fl = PolicyControl.getWindowFlags(null, lp);
Joe Onorato93056472010-09-10 10:30:46 -04003818 if (localLOGV) {
Craig Mautnereda67292013-04-28 13:50:14 -07003819 Slog.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw()
Joe Onorato93056472010-09-10 10:30:46 -04003820 + " shown frame: " + mTopFullscreenOpaqueWindowState.getShownFrameLw());
Craig Mautnereda67292013-04-28 13:50:14 -07003821 Slog.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs()
John Spurlockc6d1c602014-01-17 15:22:06 -05003822 + " lp.flags=0x" + Integer.toHexString(fl));
Joe Onorato93056472010-09-10 10:30:46 -04003823 }
John Spurlockc6d1c602014-01-17 15:22:06 -05003824 topIsFullscreen = (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003825 || (mLastSystemUiFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
Joe Onorato93056472010-09-10 10:30:46 -04003826 // The subtle difference between the window for mTopFullscreenOpaqueWindowState
3827 // and mTopIsFullscreen is that that mTopIsFullscreen is set only if the window
3828 // has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the
3829 // case though.
John Spurlock27735a42013-08-14 17:57:38 -04003830 if (mStatusBarController.isTransientShowing()) {
3831 if (mStatusBarController.setBarShowingLw(true)) {
John Spurlock32beb2c2013-03-11 10:16:47 -04003832 changes |= FINISH_LAYOUT_REDO_LAYOUT;
3833 }
3834 } else if (topIsFullscreen) {
Craig Mautnereda67292013-04-28 13:50:14 -07003835 if (DEBUG_LAYOUT) Slog.v(TAG, "** HIDING status bar");
John Spurlock27735a42013-08-14 17:57:38 -04003836 if (mStatusBarController.setBarShowingLw(false)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003837 changes |= FINISH_LAYOUT_REDO_LAYOUT;
Craig Mautnereda67292013-04-28 13:50:14 -07003838 } else {
Craig Mautnerc5a6e442013-06-05 17:22:35 -07003839 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar already hiding");
Daniel Sandler40427442010-07-16 11:44:52 -04003840 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003841 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07003842 if (DEBUG_LAYOUT) Slog.v(TAG, "** SHOWING status bar: top is not fullscreen");
John Spurlock27735a42013-08-14 17:57:38 -04003843 if (mStatusBarController.setBarShowingLw(true)) {
3844 changes |= FINISH_LAYOUT_REDO_LAYOUT;
3845 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003846 }
3847 }
3848 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04003849
Craig Mautner81defc72013-10-29 11:10:42 -07003850 if (mTopIsFullscreen != topIsFullscreen) {
3851 if (!topIsFullscreen) {
3852 // Force another layout when status bar becomes fully shown.
3853 changes |= FINISH_LAYOUT_REDO_LAYOUT;
3854 }
3855 mTopIsFullscreen = topIsFullscreen;
3856 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04003857
Craig Mautner39834192012-09-02 07:47:24 -07003858 // Hide the key guard if a visible window explicitly specifies that it wants to be
3859 // displayed when the screen is locked.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01003860 if (mKeyguardDelegate != null && mStatusBar != null) {
3861 if (localLOGV) Slog.v(TAG, "finishPostLayoutPolicyLw: mHideKeyguard="
3862 + mHideLockScreen);
3863 if (mDismissKeyguard != DISMISS_KEYGUARD_NONE && !isKeyguardSecure()) {
3864 mKeyguardHidden = true;
3865 if (processKeyguardSetHiddenResultLw(mKeyguardDelegate.setOccluded(true))) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003866 changes |= FINISH_LAYOUT_REDO_LAYOUT
3867 | FINISH_LAYOUT_REDO_CONFIG
3868 | FINISH_LAYOUT_REDO_WALLPAPER;
3869 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01003870 if (mKeyguardDelegate.isShowing()) {
3871 mHandler.post(new Runnable() {
3872 @Override
3873 public void run() {
3874 mKeyguardDelegate.keyguardDone(false, false);
3875 }
3876 });
3877 }
3878 } else if (mHideLockScreen) {
3879 mKeyguardHidden = true;
3880 if (processKeyguardSetHiddenResultLw(mKeyguardDelegate.setOccluded(true))) {
3881 changes |= FINISH_LAYOUT_REDO_LAYOUT
3882 | FINISH_LAYOUT_REDO_CONFIG
3883 | FINISH_LAYOUT_REDO_WALLPAPER;
3884 }
3885 } else if (mDismissKeyguard != DISMISS_KEYGUARD_NONE) {
3886 // This is the case of keyguard isSecure() and not mHideLockScreen.
3887 if (mDismissKeyguard == DISMISS_KEYGUARD_START) {
3888 // Only launch the next keyguard unlock window once per window.
3889 mKeyguardHidden = false;
3890 if (processKeyguardSetHiddenResultLw(mKeyguardDelegate.setOccluded(false))) {
3891 changes |= FINISH_LAYOUT_REDO_LAYOUT
3892 | FINISH_LAYOUT_REDO_CONFIG
3893 | FINISH_LAYOUT_REDO_WALLPAPER;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003894 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01003895 mHandler.post(new Runnable() {
3896 @Override
3897 public void run() {
3898 mKeyguardDelegate.dismiss();
3899 }
3900 });
3901 }
3902 } else {
3903 mWinDismissingKeyguard = null;
3904 mKeyguardHidden = false;
3905 if (processKeyguardSetHiddenResultLw(mKeyguardDelegate.setOccluded(false))) {
3906 changes |= FINISH_LAYOUT_REDO_LAYOUT
3907 | FINISH_LAYOUT_REDO_CONFIG
3908 | FINISH_LAYOUT_REDO_WALLPAPER;
3909 }
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -07003910 }
3911 }
Joe Onorato664644d2011-01-23 17:53:23 -08003912
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003913 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003914 // If the navigation bar has been hidden or shown, we need to do another
3915 // layout pass to update that window.
3916 changes |= FINISH_LAYOUT_REDO_LAYOUT;
3917 }
Joe Onorato664644d2011-01-23 17:53:23 -08003918
Mike Lockwood28569302010-01-28 11:54:40 -05003919 // update since mAllowLockscreenWhenOn might have changed
3920 updateLockScreenTimeout();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003921 return changes;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003922 }
3923
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003924 /**
Jorim Jaggi5cf17872014-03-26 18:31:48 +01003925 * Processes the result code of {@link IKeyguardService#setOccluded}. This is needed because we
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003926 * immediately need to put the wallpaper directly behind the Keyguard when a window with flag
3927 * {@link android.view.WindowManager.LayoutParams#FLAG_SHOW_WHEN_LOCKED} gets dismissed. If we
3928 * would wait for Keyguard to change the flags, that would be running asynchronously and thus be
3929 * too late so the user might see the window behind.
3930 *
Jorim Jaggi5cf17872014-03-26 18:31:48 +01003931 * @param setHiddenResult The result code from {@link IKeyguardService#setOccluded}.
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003932 * @return Whether the flags have changed and we have to redo the layout.
3933 */
3934 private boolean processKeyguardSetHiddenResultLw(int setHiddenResult) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01003935 if (setHiddenResult
3936 == IKeyguardServiceConstants.KEYGUARD_SERVICE_SET_OCCLUDED_RESULT_SET_FLAGS) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003937 mStatusBar.getAttrs().privateFlags |= PRIVATE_FLAG_KEYGUARD;
3938 mStatusBar.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
3939 return true;
3940 } else if (setHiddenResult
Jorim Jaggi5cf17872014-03-26 18:31:48 +01003941 == IKeyguardServiceConstants.KEYGUARD_SERVICE_SET_OCCLUDED_RESULT_UNSET_FLAGS) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003942 mStatusBar.getAttrs().privateFlags &= ~PRIVATE_FLAG_KEYGUARD;
3943 mStatusBar.getAttrs().flags &= ~FLAG_SHOW_WALLPAPER;
3944 return true;
3945 } else {
3946 return false;
3947 }
3948 }
3949
3950 private boolean isStatusBarKeyguard() {
3951 return mStatusBar != null
3952 && (mStatusBar.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
3953 }
3954
Jose Lima9546b202014-07-02 17:21:51 -07003955 @Override
Dianne Hackborn08743722009-12-21 12:16:51 -08003956 public boolean allowAppAnimationsLw() {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003957 if (isStatusBarKeyguard() || mShowingDream) {
Craig Mautner28816302013-10-10 20:31:00 -07003958 // If keyguard or dreams is currently visible, no reason to animate behind it.
Dianne Hackborn08743722009-12-21 12:16:51 -08003959 return false;
3960 }
Dianne Hackborn08743722009-12-21 12:16:51 -08003961 return true;
3962 }
3963
Jose Lima9546b202014-07-02 17:21:51 -07003964 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07003965 public int focusChangedLw(WindowState lastFocus, WindowState newFocus) {
Joe Onorato664644d2011-01-23 17:53:23 -08003966 mFocusedWindow = newFocus;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003967 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003968 // If the navigation bar has been hidden or shown, we need to do another
3969 // layout pass to update that window.
3970 return FINISH_LAYOUT_REDO_LAYOUT;
3971 }
3972 return 0;
Joe Onorato664644d2011-01-23 17:53:23 -08003973 }
3974
Dianne Hackborn0ecadf72009-03-31 18:00:37 -07003975 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07003976 @Override
Jeff Brown46b9ac02010-04-22 18:58:52 -07003977 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
3978 // lid changed state
Jeff Brownc458ce92012-04-30 14:58:40 -07003979 final int newLidState = lidOpen ? LID_OPEN : LID_CLOSED;
3980 if (newLidState == mLidState) {
3981 return;
3982 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07003983
Jeff Brownc458ce92012-04-30 14:58:40 -07003984 mLidState = newLidState;
3985 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07003986 updateRotation(true);
Jeff Brownc458ce92012-04-30 14:58:40 -07003987
3988 if (lidOpen) {
Jim Millere51cf7ae2013-06-25 18:31:56 -07003989 mPowerManager.wakeUp(SystemClock.uptimeMillis());
Jeff Brownc458ce92012-04-30 14:58:40 -07003990 } else if (!mLidControlsSleep) {
Jeff Brown96307042012-07-27 15:51:34 -07003991 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
Jeff Brown46b9ac02010-04-22 18:58:52 -07003992 }
3993 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003994
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08003995 void setHdmiPlugged(boolean plugged) {
3996 if (mHdmiPlugged != plugged) {
3997 mHdmiPlugged = plugged;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003998 updateRotation(true, true);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08003999 Intent intent = new Intent(ACTION_HDMI_PLUGGED);
Joe Onoratodc100302011-01-11 17:07:41 -08004000 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004001 intent.putExtra(EXTRA_HDMI_PLUGGED_STATE, plugged);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07004002 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004003 }
4004 }
4005
Joe Onoratoea495d42011-04-06 11:41:11 -07004006 void initializeHdmiState() {
Joe Onorato7ba631f2011-05-04 15:28:00 -07004007 boolean plugged = false;
Joe Onoratoea495d42011-04-06 11:41:11 -07004008 // watch for HDMI plug messages if the hdmi switch exists
4009 if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) {
4010 mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi");
4011
Joe Onoratoea495d42011-04-06 11:41:11 -07004012 final String filename = "/sys/class/switch/hdmi/state";
4013 FileReader reader = null;
4014 try {
4015 reader = new FileReader(filename);
4016 char[] buf = new char[15];
4017 int n = reader.read(buf);
4018 if (n > 1) {
4019 plugged = 0 != Integer.parseInt(new String(buf, 0, n-1));
4020 }
4021 } catch (IOException ex) {
4022 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
4023 } catch (NumberFormatException ex) {
4024 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
4025 } finally {
4026 if (reader != null) {
4027 try {
4028 reader.close();
4029 } catch (IOException ex) {
4030 }
Joe Onoratodc100302011-01-11 17:07:41 -08004031 }
4032 }
4033 }
Joe Onorato7ba631f2011-05-04 15:28:00 -07004034 // This dance forces the code in setHdmiPlugged to run.
4035 // Always do this so the sticky intent is stuck (to false) if there is no hdmi.
4036 mHdmiPlugged = !plugged;
4037 setHdmiPlugged(!mHdmiPlugged);
Joe Onoratodc100302011-01-11 17:07:41 -08004038 }
4039
Dianne Hackbornc0e3f242011-08-19 14:19:10 -07004040 final Object mScreenshotLock = new Object();
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004041 ServiceConnection mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004042
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004043 final Runnable mScreenshotTimeout = new Runnable() {
4044 @Override public void run() {
4045 synchronized (mScreenshotLock) {
4046 if (mScreenshotConnection != null) {
4047 mContext.unbindService(mScreenshotConnection);
4048 mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004049 }
Winson Chung9112ec32011-06-27 13:15:32 -07004050 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004051 }
4052 };
4053
4054 // Assume this is called from the Handler thread.
4055 private void takeScreenshot() {
4056 synchronized (mScreenshotLock) {
4057 if (mScreenshotConnection != null) {
4058 return;
4059 }
4060 ComponentName cn = new ComponentName("com.android.systemui",
4061 "com.android.systemui.screenshot.TakeScreenshotService");
4062 Intent intent = new Intent();
4063 intent.setComponent(cn);
4064 ServiceConnection conn = new ServiceConnection() {
4065 @Override
4066 public void onServiceConnected(ComponentName name, IBinder service) {
4067 synchronized (mScreenshotLock) {
4068 if (mScreenshotConnection != this) {
4069 return;
4070 }
4071 Messenger messenger = new Messenger(service);
4072 Message msg = Message.obtain(null, 1);
4073 final ServiceConnection myConn = this;
4074 Handler h = new Handler(mHandler.getLooper()) {
4075 @Override
4076 public void handleMessage(Message msg) {
4077 synchronized (mScreenshotLock) {
4078 if (mScreenshotConnection == myConn) {
4079 mContext.unbindService(mScreenshotConnection);
4080 mScreenshotConnection = null;
4081 mHandler.removeCallbacks(mScreenshotTimeout);
4082 }
4083 }
4084 }
4085 };
4086 msg.replyTo = new Messenger(h);
Winson Chunga63bb842011-10-17 10:26:28 -07004087 msg.arg1 = msg.arg2 = 0;
4088 if (mStatusBar != null && mStatusBar.isVisibleLw())
4089 msg.arg1 = 1;
4090 if (mNavigationBar != null && mNavigationBar.isVisibleLw())
4091 msg.arg2 = 1;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004092 try {
4093 messenger.send(msg);
4094 } catch (RemoteException e) {
4095 }
4096 }
4097 }
4098 @Override
4099 public void onServiceDisconnected(ComponentName name) {}
4100 };
Amith Yamasani27b89e62013-01-16 12:30:11 -08004101 if (mContext.bindServiceAsUser(
4102 intent, conn, Context.BIND_AUTO_CREATE, UserHandle.CURRENT)) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004103 mScreenshotConnection = conn;
4104 mHandler.postDelayed(mScreenshotTimeout, 10000);
4105 }
4106 }
Winson Chung9112ec32011-06-27 13:15:32 -07004107 }
4108
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004109 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004110 @Override
Jeff Brown037c33e2014-04-09 00:31:55 -07004111 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) {
Jeff Brown96307042012-07-27 15:51:34 -07004112 if (!mSystemBooted) {
4113 // If we have not yet booted, don't let key events do anything.
4114 return 0;
4115 }
4116
Jeff Brown037c33e2014-04-09 00:31:55 -07004117 final boolean interactive = (policyFlags & FLAG_INTERACTIVE) != 0;
Jeff Brown1f245102010-11-18 20:53:46 -08004118 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
4119 final boolean canceled = event.isCanceled();
4120 final int keyCode = event.getKeyCode();
Jeff Browne20c9e02010-10-11 14:20:19 -07004121
Jeff Brown3122e442010-10-11 23:32:49 -07004122 final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0;
Jeff Brown3122e442010-10-11 23:32:49 -07004123
Mike Lockwoodc72b15f2009-11-28 20:58:22 -05004124 // If screen is off then we treat the case where the keyguard is open but hidden
4125 // the same as if it were open and in front.
4126 // This will prevent any keys other than the power button from waking the screen
4127 // when the keyguard is hidden by another activity.
Jim Miller5ecd8112013-01-09 18:50:26 -08004128 final boolean keyguardActive = (mKeyguardDelegate == null ? false :
Jeff Brown037c33e2014-04-09 00:31:55 -07004129 (interactive ?
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004130 mKeyguardDelegate.isShowingAndNotOccluded() :
Jim Miller5ecd8112013-01-09 18:50:26 -08004131 mKeyguardDelegate.isShowing()));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004132
Jeff Brown40013652012-05-16 21:22:36 -07004133 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004134 Log.d(TAG, "interceptKeyTq keycode=" + keyCode
Jeff Brown037c33e2014-04-09 00:31:55 -07004135 + " interactive=" + interactive + " keyguardActive=" + keyguardActive
Jeff Brown26875502014-01-30 21:47:47 -08004136 + " policyFlags=" + Integer.toHexString(policyFlags));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004137 }
4138
Jeff Brown037c33e2014-04-09 00:31:55 -07004139 // Basic policy based on interactive state.
Jeff Brown4d396052010-10-29 21:50:21 -07004140 int result;
Michael Wright337d9d22014-04-22 15:03:48 -07004141 boolean isWakeKey = (policyFlags & WindowManagerPolicy.FLAG_WAKE) != 0
4142 || event.isWakeKey();
Jeff Brown037c33e2014-04-09 00:31:55 -07004143 if (interactive || (isInjected && !isWakeKey)) {
Jeff Brown4d396052010-10-29 21:50:21 -07004144 // When the screen is on or if the key is injected pass the key to the application.
4145 result = ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07004146 isWakeKey = false;
Jeff Brown4d396052010-10-29 21:50:21 -07004147 } else {
4148 // When the screen is off and the key is not injected, determine whether
4149 // to wake the device but don't pass the key to the application.
4150 result = 0;
Jeff Brown26875502014-01-30 21:47:47 -08004151 if (isWakeKey && (!down || !isWakeKeyWhenScreenOff(keyCode))) {
4152 isWakeKey = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004153 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004154 }
4155
Justin Kohd378ad72013-04-01 12:18:26 -07004156 // If the key would be handled globally, just return the result, don't worry about special
4157 // key processing.
4158 if (mGlobalKeyManager.shouldHandleGlobalKey(keyCode, event)) {
Michael Wright85b1af62014-06-04 14:51:58 -07004159 if (isWakeKey) {
4160 mPowerManager.wakeUp(event.getEventTime());
4161 }
Justin Kohd378ad72013-04-01 12:18:26 -07004162 return result;
4163 }
4164
Jeff Brownbae8e772014-06-12 19:59:45 -07004165 boolean useHapticFeedback = down
4166 && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0
4167 && event.getRepeatCount() == 0;
4168
Jeff Brown4d396052010-10-29 21:50:21 -07004169 // Handle special keys.
4170 switch (keyCode) {
4171 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jeff Brownb0418da2010-11-01 15:24:01 -07004172 case KeyEvent.KEYCODE_VOLUME_UP:
4173 case KeyEvent.KEYCODE_VOLUME_MUTE: {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004174 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
4175 if (down) {
Jeff Brown037c33e2014-04-09 00:31:55 -07004176 if (interactive && !mVolumeDownKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004177 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
4178 mVolumeDownKeyTriggered = true;
4179 mVolumeDownKeyTime = event.getDownTime();
4180 mVolumeDownKeyConsumedByScreenshotChord = false;
4181 cancelPendingPowerKeyAction();
4182 interceptScreenshotChord();
4183 }
4184 } else {
4185 mVolumeDownKeyTriggered = false;
4186 cancelPendingScreenshotChordAction();
4187 }
4188 } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
4189 if (down) {
Jeff Brown037c33e2014-04-09 00:31:55 -07004190 if (interactive && !mVolumeUpKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004191 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
4192 mVolumeUpKeyTriggered = true;
4193 cancelPendingPowerKeyAction();
4194 cancelPendingScreenshotChordAction();
4195 }
4196 } else {
4197 mVolumeUpKeyTriggered = false;
4198 cancelPendingScreenshotChordAction();
4199 }
4200 }
Jeff Brown4d396052010-10-29 21:50:21 -07004201 if (down) {
Santos Cordon9eb45932014-06-27 12:28:43 -07004202 TelecommManager telecommManager = getTelecommService();
4203 if (telecommManager != null) {
4204 if (telecommManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07004205 // If an incoming call is ringing, either VOLUME key means
4206 // "silence ringer". We handle these keys here, rather than
4207 // in the InCallScreen, to make sure we'll respond to them
4208 // even if the InCallScreen hasn't come to the foreground yet.
4209 // Look for the DOWN event here, to agree with the "fallback"
4210 // behavior in the InCallScreen.
4211 Log.i(TAG, "interceptKeyBeforeQueueing:"
4212 + " VOLUME key-down while ringing: Silence ringer!");
Jeff Brown4d396052010-10-29 21:50:21 -07004213
Santos Cordon6848f722014-05-21 15:22:12 -07004214 // Silence the ringer. (It's safe to call this
4215 // even if the ringer has already been silenced.)
Santos Cordon9eb45932014-06-27 12:28:43 -07004216 telecommManager.silenceRinger();
Jeff Brown4d396052010-10-29 21:50:21 -07004217
Santos Cordon6848f722014-05-21 15:22:12 -07004218 // And *don't* pass this key thru to the current activity
4219 // (which is probably the InCallScreen.)
4220 result &= ~ACTION_PASS_TO_USER;
4221 break;
4222 }
Santos Cordon9eb45932014-06-27 12:28:43 -07004223 if (telecommManager.isInAPhoneCall()
Santos Cordon6848f722014-05-21 15:22:12 -07004224 && (result & ACTION_PASS_TO_USER) == 0) {
4225 // If we are in call but we decided not to pass the key to
RoboErik430fc482014-06-12 15:49:20 -07004226 // the application, just pass it to the session service.
4227
4228 MediaSessionLegacyHelper.getHelper(mContext)
RoboErik3c45c292014-07-08 16:47:31 -07004229 .sendVolumeKeyEvent(event, false);
Santos Cordon6848f722014-05-21 15:22:12 -07004230 break;
Jeff Brown4d396052010-10-29 21:50:21 -07004231 }
4232 }
4233
RoboErik430fc482014-06-12 15:49:20 -07004234 if ((result & ACTION_PASS_TO_USER) == 0) {
4235 // If we aren't passing to the user and no one else
4236 // handled it send it to the session manager to figure
4237 // out.
4238 MediaSessionLegacyHelper.getHelper(mContext)
RoboErik3c45c292014-07-08 16:47:31 -07004239 .sendVolumeKeyEvent(event, true);
Jeff Brown4d396052010-10-29 21:50:21 -07004240 break;
4241 }
4242 }
4243 break;
4244 }
4245
4246 case KeyEvent.KEYCODE_ENDCALL: {
4247 result &= ~ACTION_PASS_TO_USER;
4248 if (down) {
Santos Cordon9eb45932014-06-27 12:28:43 -07004249 TelecommManager telecommManager = getTelecommService();
Jeff Brown4d396052010-10-29 21:50:21 -07004250 boolean hungUp = false;
Santos Cordon9eb45932014-06-27 12:28:43 -07004251 if (telecommManager != null) {
4252 hungUp = telecommManager.endCall();
Jeff Brown4d396052010-10-29 21:50:21 -07004253 }
Jeff Brown037c33e2014-04-09 00:31:55 -07004254 interceptPowerKeyDown(!interactive || hungUp);
Jeff Brown4d396052010-10-29 21:50:21 -07004255 } else {
4256 if (interceptPowerKeyUp(canceled)) {
4257 if ((mEndcallBehavior
4258 & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) {
4259 if (goHome()) {
4260 break;
Dianne Hackborn0041e972009-07-24 17:14:43 -07004261 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004262 }
Jeff Brown4d396052010-10-29 21:50:21 -07004263 if ((mEndcallBehavior
4264 & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) {
Jeff Brown26875502014-01-30 21:47:47 -08004265 mPowerManager.goToSleep(event.getEventTime());
4266 isWakeKey = false;
Jeff Brown4d396052010-10-29 21:50:21 -07004267 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004268 }
Jeff Brown4d396052010-10-29 21:50:21 -07004269 }
4270 break;
4271 }
4272
4273 case KeyEvent.KEYCODE_POWER: {
4274 result &= ~ACTION_PASS_TO_USER;
4275 if (down) {
Jeff Brown26c6a502014-04-11 02:15:54 -07004276 boolean panic = mImmersiveModeConfirmation.onPowerKeyDown(interactive,
John Spurlockd9b70bd2014-02-06 17:02:44 -05004277 event.getDownTime(), isImmersiveMode(mLastSystemUiFlags));
4278 if (panic) {
4279 mHandler.post(mRequestTransientNav);
4280 }
Jeff Brown037c33e2014-04-09 00:31:55 -07004281 if (interactive && !mPowerKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004282 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
4283 mPowerKeyTriggered = true;
4284 mPowerKeyTime = event.getDownTime();
4285 interceptScreenshotChord();
Winson Chung9112ec32011-06-27 13:15:32 -07004286 }
Winson Chung9112ec32011-06-27 13:15:32 -07004287
Santos Cordon9eb45932014-06-27 12:28:43 -07004288 TelecommManager telecommManager = getTelecommService();
Jeff Brown4d396052010-10-29 21:50:21 -07004289 boolean hungUp = false;
Santos Cordon9eb45932014-06-27 12:28:43 -07004290 if (telecommManager != null) {
4291 if (telecommManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07004292 // Pressing Power while there's a ringing incoming
4293 // call should silence the ringer.
Santos Cordon9eb45932014-06-27 12:28:43 -07004294 telecommManager.silenceRinger();
Santos Cordon6848f722014-05-21 15:22:12 -07004295 } else if ((mIncallPowerBehavior
4296 & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0
Santos Cordon9eb45932014-06-27 12:28:43 -07004297 && telecommManager.isInAPhoneCall() && interactive) {
Santos Cordon6848f722014-05-21 15:22:12 -07004298 // Otherwise, if "Power button ends call" is enabled,
4299 // the Power button will hang up any current active call.
Santos Cordon9eb45932014-06-27 12:28:43 -07004300 hungUp = telecommManager.endCall();
Jeff Brown4d396052010-10-29 21:50:21 -07004301 }
4302 }
Jeff Brown037c33e2014-04-09 00:31:55 -07004303 interceptPowerKeyDown(!interactive || hungUp
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004304 || mVolumeDownKeyTriggered || mVolumeUpKeyTriggered);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004305 } else {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004306 mPowerKeyTriggered = false;
4307 cancelPendingScreenshotChordAction();
4308 if (interceptPowerKeyUp(canceled || mPendingPowerKeyUpCanceled)) {
Jeff Brown6d8fd272014-05-20 21:24:38 -07004309 powerShortPress(event.getEventTime());
Jeff Brown26875502014-01-30 21:47:47 -08004310 isWakeKey = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004311 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004312 mPendingPowerKeyUpCanceled = false;
Jeff Brown4d396052010-10-29 21:50:21 -07004313 }
4314 break;
4315 }
4316
Jeff Brown6212a492014-03-07 13:58:47 -08004317 case KeyEvent.KEYCODE_SLEEP: {
4318 result &= ~ACTION_PASS_TO_USER;
Jeff Brownbae8e772014-06-12 19:59:45 -07004319 if (!mPowerManager.isInteractive()) {
4320 useHapticFeedback = false; // suppress feedback if already non-interactive
4321 }
Jeff Brown6212a492014-03-07 13:58:47 -08004322 mPowerManager.goToSleep(event.getEventTime());
4323 isWakeKey = false;
4324 break;
4325 }
4326
4327 case KeyEvent.KEYCODE_WAKEUP: {
4328 result &= ~ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07004329 isWakeKey = true;
Jeff Brown6212a492014-03-07 13:58:47 -08004330 break;
4331 }
4332
Jeff Brown4d396052010-10-29 21:50:21 -07004333 case KeyEvent.KEYCODE_MEDIA_PLAY:
4334 case KeyEvent.KEYCODE_MEDIA_PAUSE:
4335 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
4336 if (down) {
Santos Cordon9eb45932014-06-27 12:28:43 -07004337 TelecommManager telecommManager = getTelecommService();
4338 if (telecommManager != null) {
4339 if (telecommManager.isInAPhoneCall()) {
Santos Cordon6848f722014-05-21 15:22:12 -07004340 // Suppress PLAY/PAUSE toggle when phone is ringing or in-call
4341 // to avoid music playback.
4342 break;
Jeff Brown3122e442010-10-11 23:32:49 -07004343 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004344 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004345 }
Jeff Brown4d396052010-10-29 21:50:21 -07004346 case KeyEvent.KEYCODE_HEADSETHOOK:
4347 case KeyEvent.KEYCODE_MUTE:
4348 case KeyEvent.KEYCODE_MEDIA_STOP:
4349 case KeyEvent.KEYCODE_MEDIA_NEXT:
4350 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
4351 case KeyEvent.KEYCODE_MEDIA_REWIND:
4352 case KeyEvent.KEYCODE_MEDIA_RECORD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09004353 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
4354 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: {
Jeff Brown4d396052010-10-29 21:50:21 -07004355 if ((result & ACTION_PASS_TO_USER) == 0) {
4356 // Only do this if we would otherwise not pass it to the user. In that
4357 // case, the PhoneWindow class will do the same thing, except it will
4358 // only do it if the showing app doesn't process the key on its own.
Jeff Brown40013652012-05-16 21:22:36 -07004359 // Note that we need to make a copy of the key event here because the
4360 // original key event will be recycled when we return.
Jeff Brown4d396052010-10-29 21:50:21 -07004361 mBroadcastWakeLock.acquire();
Jeff Brown40013652012-05-16 21:22:36 -07004362 Message msg = mHandler.obtainMessage(MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK,
4363 new KeyEvent(event));
4364 msg.setAsynchronous(true);
4365 msg.sendToTarget();
Jeff Brown4d396052010-10-29 21:50:21 -07004366 }
4367 break;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004368 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004369
Jeff Brown4d396052010-10-29 21:50:21 -07004370 case KeyEvent.KEYCODE_CALL: {
4371 if (down) {
Santos Cordon9eb45932014-06-27 12:28:43 -07004372 TelecommManager telecommManager = getTelecommService();
4373 if (telecommManager != null) {
4374 if (telecommManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07004375 Log.i(TAG, "interceptKeyBeforeQueueing:"
4376 + " CALL key-down while ringing: Answer the call!");
Santos Cordon9eb45932014-06-27 12:28:43 -07004377 telecommManager.acceptRingingCall();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004378
Santos Cordon6848f722014-05-21 15:22:12 -07004379 // And *don't* pass this key thru to the current activity
4380 // (which is presumably the InCallScreen.)
4381 result &= ~ACTION_PASS_TO_USER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004382 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004383 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004384 }
Jeff Brown4d396052010-10-29 21:50:21 -07004385 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004386 }
4387 }
Jeff Brown26875502014-01-30 21:47:47 -08004388
Jeff Brownbae8e772014-06-12 19:59:45 -07004389 if (useHapticFeedback) {
4390 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
4391 }
4392
Jeff Brown26875502014-01-30 21:47:47 -08004393 if (isWakeKey) {
4394 mPowerManager.wakeUp(event.getEventTime());
4395 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004396 return result;
4397 }
4398
Jeff Brown1c2e4942012-11-06 16:32:01 -08004399 /**
4400 * When the screen is off we ignore some keys that might otherwise typically
4401 * be considered wake keys. We filter them out here.
4402 *
4403 * {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it
4404 * is always considered a wake key.
4405 */
4406 private boolean isWakeKeyWhenScreenOff(int keyCode) {
4407 switch (keyCode) {
4408 // ignore volume keys unless docked
4409 case KeyEvent.KEYCODE_VOLUME_UP:
4410 case KeyEvent.KEYCODE_VOLUME_DOWN:
4411 case KeyEvent.KEYCODE_VOLUME_MUTE:
4412 return mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED;
4413
4414 // ignore media and camera keys
4415 case KeyEvent.KEYCODE_MUTE:
4416 case KeyEvent.KEYCODE_HEADSETHOOK:
4417 case KeyEvent.KEYCODE_MEDIA_PLAY:
4418 case KeyEvent.KEYCODE_MEDIA_PAUSE:
4419 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
4420 case KeyEvent.KEYCODE_MEDIA_STOP:
4421 case KeyEvent.KEYCODE_MEDIA_NEXT:
4422 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
4423 case KeyEvent.KEYCODE_MEDIA_REWIND:
4424 case KeyEvent.KEYCODE_MEDIA_RECORD:
4425 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09004426 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK:
Jeff Brown1c2e4942012-11-06 16:32:01 -08004427 case KeyEvent.KEYCODE_CAMERA:
4428 return false;
4429 }
4430 return true;
4431 }
4432
4433
Jeff Brown56194eb2011-03-02 19:23:13 -08004434 /** {@inheritDoc} */
4435 @Override
Jeff Brown037c33e2014-04-09 00:31:55 -07004436 public int interceptWakeMotionBeforeQueueing(long whenNanos, int policyFlags) {
4437 // We already know this is a wake motion so just wake up.
4438 // Note that we would observe policyFlags containing
4439 // FLAG_WAKE and FLAG_INTERACTIVE here.
4440 mPowerManager.wakeUp(whenNanos / 1000000);
4441 return 0;
Jeff Brown56194eb2011-03-02 19:23:13 -08004442 }
4443
Jeff Brown40013652012-05-16 21:22:36 -07004444 void dispatchMediaKeyWithWakeLock(KeyEvent event) {
4445 if (DEBUG_INPUT) {
4446 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: " + event);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004447 }
4448
Jeff Brown40013652012-05-16 21:22:36 -07004449 if (mHavePendingMediaKeyRepeatWithWakeLock) {
4450 if (DEBUG_INPUT) {
4451 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: canceled repeat");
4452 }
4453
4454 mHandler.removeMessages(MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK);
4455 mHavePendingMediaKeyRepeatWithWakeLock = false;
4456 mBroadcastWakeLock.release(); // pending repeat was holding onto the wake lock
4457 }
4458
4459 dispatchMediaKeyWithWakeLockToAudioService(event);
4460
4461 if (event.getAction() == KeyEvent.ACTION_DOWN
4462 && event.getRepeatCount() == 0) {
4463 mHavePendingMediaKeyRepeatWithWakeLock = true;
4464
4465 Message msg = mHandler.obtainMessage(
4466 MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK, event);
4467 msg.setAsynchronous(true);
4468 mHandler.sendMessageDelayed(msg, ViewConfiguration.getKeyRepeatTimeout());
4469 } else {
4470 mBroadcastWakeLock.release();
4471 }
4472 }
4473
4474 void dispatchMediaKeyRepeatWithWakeLock(KeyEvent event) {
4475 mHavePendingMediaKeyRepeatWithWakeLock = false;
4476
4477 KeyEvent repeatEvent = KeyEvent.changeTimeRepeat(event,
4478 SystemClock.uptimeMillis(), 1, event.getFlags() | KeyEvent.FLAG_LONG_PRESS);
4479 if (DEBUG_INPUT) {
4480 Slog.d(TAG, "dispatchMediaKeyRepeatWithWakeLock: " + repeatEvent);
4481 }
4482
4483 dispatchMediaKeyWithWakeLockToAudioService(repeatEvent);
4484 mBroadcastWakeLock.release();
4485 }
4486
4487 void dispatchMediaKeyWithWakeLockToAudioService(KeyEvent event) {
4488 if (ActivityManagerNative.isSystemReady()) {
RoboErik430fc482014-06-12 15:49:20 -07004489 MediaSessionLegacyHelper.getHelper(mContext).sendMediaButtonEvent(event, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004490 }
4491 }
4492
Mike Lockwood1753f7f2009-08-24 14:49:07 -07004493 BroadcastReceiver mDockReceiver = new BroadcastReceiver() {
Craig Mautnereee29c42013-01-17 14:44:34 -08004494 @Override
Mike Lockwood1753f7f2009-08-24 14:49:07 -07004495 public void onReceive(Context context, Intent intent) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07004496 if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) {
4497 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
4498 Intent.EXTRA_DOCK_STATE_UNDOCKED);
Daniel Sandler6396c722013-04-16 20:19:09 -04004499 } else {
4500 try {
4501 IUiModeManager uiModeService = IUiModeManager.Stub.asInterface(
4502 ServiceManager.getService(Context.UI_MODE_SERVICE));
4503 mUiMode = uiModeService.getCurrentModeType();
4504 } catch (RemoteException e) {
4505 }
Dianne Hackborn80fa1662009-10-07 14:02:10 -07004506 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004507 updateRotation(true);
Craig Mautnereee29c42013-01-17 14:44:34 -08004508 synchronized (mLock) {
4509 updateOrientationListenerLp();
4510 }
Mike Lockwood1753f7f2009-08-24 14:49:07 -07004511 }
4512 };
4513
Jeff Brown6aaf2952012-10-05 16:01:08 -07004514 BroadcastReceiver mDreamReceiver = new BroadcastReceiver() {
4515 @Override
4516 public void onReceive(Context context, Intent intent) {
4517 if (Intent.ACTION_DREAMING_STARTED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004518 if (mKeyguardDelegate != null) {
4519 mKeyguardDelegate.onDreamingStarted();
Jeff Brown6aaf2952012-10-05 16:01:08 -07004520 }
4521 } else if (Intent.ACTION_DREAMING_STOPPED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004522 if (mKeyguardDelegate != null) {
4523 mKeyguardDelegate.onDreamingStopped();
Jeff Brown6aaf2952012-10-05 16:01:08 -07004524 }
4525 }
4526 }
4527 };
4528
Christopher Tate5e08af02012-09-21 17:17:22 -07004529 BroadcastReceiver mMultiuserReceiver = new BroadcastReceiver() {
4530 @Override
4531 public void onReceive(Context context, Intent intent) {
4532 if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) {
4533 // tickle the settings observer: this first ensures that we're
4534 // observing the relevant settings for the newly-active user,
4535 // and then updates our own bookkeeping based on the now-
4536 // current user.
4537 mSettingsObserver.onChange(false);
John Spurlockce479d82012-11-29 09:52:21 -05004538
4539 // force a re-application of focused window sysui visibility.
4540 // the window may never have been shown for this user
4541 // e.g. the keyguard when going through the new-user setup flow
John Spurlock04db1762013-05-13 12:46:41 -04004542 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
John Spurlockce479d82012-11-29 09:52:21 -05004543 mLastSystemUiFlags = 0;
4544 updateSystemUiVisibilityLw();
4545 }
Christopher Tate5e08af02012-09-21 17:17:22 -07004546 }
4547 }
4548 };
4549
John Spurlockd9b70bd2014-02-06 17:02:44 -05004550 private final Runnable mRequestTransientNav = new Runnable() {
4551 @Override
4552 public void run() {
4553 requestTransientBars(mNavigationBar);
4554 }
4555 };
4556
John Spurlocke1f366f2013-08-05 12:22:40 -04004557 private void requestTransientBars(WindowState swipeTarget) {
John Spurlock04db1762013-05-13 12:46:41 -04004558 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Maurice Lam99c6e072014-04-28 18:24:28 -07004559 if (!isUserSetupComplete()) {
4560 // Swipe-up for navigation bar is disabled during setup
4561 return;
4562 }
John Spurlock27735a42013-08-14 17:57:38 -04004563 boolean sb = mStatusBarController.checkShowTransientBarLw();
4564 boolean nb = mNavigationBarController.checkShowTransientBarLw();
John Spurlockad3e6cb2013-04-30 08:47:43 -04004565 if (sb || nb) {
John Spurlocke1f366f2013-08-05 12:22:40 -04004566 WindowState barTarget = sb ? mStatusBar : mNavigationBar;
4567 if (sb ^ nb && barTarget != swipeTarget) {
4568 if (DEBUG) Slog.d(TAG, "Not showing transient bar, wrong swipe target");
John Spurlockad3e6cb2013-04-30 08:47:43 -04004569 return;
4570 }
John Spurlock27735a42013-08-14 17:57:38 -04004571 if (sb) mStatusBarController.showTransient();
4572 if (nb) mNavigationBarController.showTransient();
John Spurlockf1a36642013-10-12 17:50:42 -04004573 mImmersiveModeConfirmation.confirmCurrentPrompt();
John Spurlockad3e6cb2013-04-30 08:47:43 -04004574 updateSystemUiVisibilityLw();
John Spurlock32beb2c2013-03-11 10:16:47 -04004575 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04004576 }
4577 }
4578
Jeff Brownc38c9be2012-10-04 13:16:19 -07004579 @Override
Jeff Brown140ffc72014-05-01 15:18:00 -07004580 public void goingToSleep(int why) {
Dianne Hackborn74489012009-03-24 20:50:09 -07004581 EventLog.writeEvent(70000, 0);
The Android Open Source Project0727d222009-03-11 12:11:58 -07004582 synchronized (mLock) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004583 mScreenOnEarly = false;
4584 mScreenOnFully = false;
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07004585 }
Jim Miller5ecd8112013-01-09 18:50:26 -08004586 if (mKeyguardDelegate != null) {
4587 mKeyguardDelegate.onScreenTurnedOff(why);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004588 }
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07004589 synchronized (mLock) {
Jeff Browna20dda42014-05-27 20:57:24 -07004590 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07004591 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05004592 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07004593 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004594 }
4595
Jeff Brownc38c9be2012-10-04 13:16:19 -07004596 @Override
Jeff Brown140ffc72014-05-01 15:18:00 -07004597 public void wakingUp(final ScreenOnListener screenOnListener) {
Dianne Hackborn74489012009-03-24 20:50:09 -07004598 EventLog.writeEvent(70000, 1);
Craig Mautner8a0da012014-05-31 15:13:37 -07004599 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turning on...",
4600 new RuntimeException("here").fillInStackTrace());
4601 mHandler.obtainMessage(MSG_WAKING_UP, screenOnListener).sendToTarget();
4602 }
4603
4604 // Called on the mHandler thread.
4605 private void handleWakingUp(final ScreenOnListener screenOnListener) {
4606 if (screenOnListener != null) {
Craig Mautner13f6ea72014-06-23 14:57:02 -07004607 mScreenOnListener = screenOnListener;
Dianne Hackborn40011092011-09-22 13:37:48 -07004608 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07004609
The Android Open Source Project0727d222009-03-11 12:11:58 -07004610 synchronized (mLock) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004611 mScreenOnEarly = true;
Jeff Browna20dda42014-05-27 20:57:24 -07004612 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07004613 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05004614 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07004615 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07004616
Craig Mautner8a0da012014-05-31 15:13:37 -07004617 mKeyguardDrawComplete = false;
4618 mWindowManagerDrawComplete = false;
Jim Miller5ecd8112013-01-09 18:50:26 -08004619 if (mKeyguardDelegate != null) {
Craig Mautner8a0da012014-05-31 15:13:37 -07004620 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
4621 mHandler.sendEmptyMessageDelayed(MSG_KEYGUARD_DRAWN_TIMEOUT, 1000);
4622 mKeyguardDelegate.onScreenTurnedOn(mKeyguardDelegateCallback);
Jeff Brownc38c9be2012-10-04 13:16:19 -07004623 } else {
Craig Mautner8a0da012014-05-31 15:13:37 -07004624 if (DEBUG_WAKEUP) Slog.d(TAG, "null mKeyguardDelegate: setting mKeyguardDrawComplete.");
4625 mKeyguardDrawComplete = true;
Jeff Brownc38c9be2012-10-04 13:16:19 -07004626 }
Craig Mautner8a0da012014-05-31 15:13:37 -07004627 mWindowManagerInternal.waitForAllWindowsDrawn(mWindowManagerDrawCallback, 500);
Jeff Brownc38c9be2012-10-04 13:16:19 -07004628 }
4629
Craig Mautner8a0da012014-05-31 15:13:37 -07004630 // Called on the mHandler thread.
4631 private void finishScreenTurningOn() {
4632 if (DEBUG_WAKEUP) Slog.d(TAG,
4633 "finishScreenTurningOn: mKeyguardDrawComplete=" + mKeyguardDrawComplete
4634 + " mWindowManagerDrawComplete=" + mWindowManagerDrawComplete);
4635 if (!mKeyguardDrawComplete || !mWindowManagerDrawComplete) {
4636 return;
Jeff Brownc38c9be2012-10-04 13:16:19 -07004637 }
4638
Craig Mautner13f6ea72014-06-23 14:57:02 -07004639 ScreenOnListener screenOnListener;
Jeff Brownc38c9be2012-10-04 13:16:19 -07004640 synchronized (mLock) {
4641 mScreenOnFully = true;
Craig Mautner13f6ea72014-06-23 14:57:02 -07004642 screenOnListener = mScreenOnListener;
4643 mScreenOnListener = null;
Jeff Brownc38c9be2012-10-04 13:16:19 -07004644 }
4645
Jeff Brown4fc45272012-10-10 18:28:14 -07004646 try {
4647 mWindowManager.setEventDispatching(true);
4648 } catch (RemoteException unhandled) {
4649 }
4650
Craig Mautner13f6ea72014-06-23 14:57:02 -07004651 if (screenOnListener != null) {
4652 screenOnListener.onScreenOn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07004653 }
Craig Mautner8a0da012014-05-31 15:13:37 -07004654
4655 setKeyguardDrawn();
Craig Mautnera631d492014-08-05 15:16:01 -07004656
4657 if (mBootMessageNeedsHiding) {
4658 handleHideBootMessage();
4659 mBootMessageNeedsHiding = false;
4660 }
4661 }
4662
4663 private void handleHideBootMessage() {
4664 if (mBootMsgDialog == null) {
4665 if (DEBUG_WAKEUP) Slog.d(TAG, "handleHideBootMessage: boot message not up");
4666 return;
4667 }
4668 if (!mKeyguardDrawComplete || !mWindowManagerDrawComplete) {
4669 if (DEBUG_WAKEUP) Slog.d(TAG, "handleHideBootMessage: deferring until keyguard ready");
4670 mBootMessageNeedsHiding = true;
4671 return;
4672 }
4673 if (DEBUG_WAKEUP) Slog.d(TAG, "handleHideBootMessage: dismissing");
4674 mBootMsgDialog.dismiss();
4675 mBootMsgDialog = null;
Jeff Brownc38c9be2012-10-04 13:16:19 -07004676 }
4677
4678 @Override
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004679 public boolean isScreenOnEarly() {
4680 return mScreenOnEarly;
4681 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07004682
4683 @Override
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004684 public boolean isScreenOnFully() {
4685 return mScreenOnFully;
Dianne Hackborn08743722009-12-21 12:16:51 -08004686 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07004687
Dianne Hackborn08743722009-12-21 12:16:51 -08004688 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07004689 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004690 public void enableKeyguard(boolean enabled) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004691 if (mKeyguardDelegate != null) {
4692 mKeyguardDelegate.setKeyguardEnabled(enabled);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004693 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004694 }
4695
4696 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07004697 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004698 public void exitKeyguardSecurely(OnKeyguardExitResult callback) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004699 if (mKeyguardDelegate != null) {
4700 mKeyguardDelegate.verifyUnlock(callback);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004701 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004702 }
4703
Mike Lockwoodf7913302009-11-28 22:27:10 -05004704 private boolean keyguardIsShowingTq() {
Jim Miller5ecd8112013-01-09 18:50:26 -08004705 if (mKeyguardDelegate == null) return false;
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004706 return mKeyguardDelegate.isShowingAndNotOccluded();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004707 }
4708
Mike Lockwood520d8bc2011-02-18 13:23:13 -05004709
4710 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07004711 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05004712 public boolean isKeyguardLocked() {
4713 return keyguardOn();
4714 }
4715
4716 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07004717 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05004718 public boolean isKeyguardSecure() {
Jim Miller5ecd8112013-01-09 18:50:26 -08004719 if (mKeyguardDelegate == null) return false;
4720 return mKeyguardDelegate.isSecure();
Mike Lockwood520d8bc2011-02-18 13:23:13 -05004721 }
4722
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004723 // Returns true if keyguard is currently locked whether or not it is currently hidden.
4724 private boolean isKeyguardSecureIncludingHidden() {
4725 return mKeyguardDelegate.isSecure() && mKeyguardDelegate.isShowing();
4726 }
4727
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004728 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07004729 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004730 public boolean inKeyguardRestrictedKeyInputMode() {
Jim Miller5ecd8112013-01-09 18:50:26 -08004731 if (mKeyguardDelegate == null) return false;
4732 return mKeyguardDelegate.isInputRestricted();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004733 }
4734
Jose Lima9546b202014-07-02 17:21:51 -07004735 @Override
Dianne Hackborn90c52de2011-09-23 12:57:44 -07004736 public void dismissKeyguardLw() {
RoboErik8a2cfc32014-05-16 11:19:38 -07004737 if (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()) {
Daniel Sandler1ce804392012-11-07 15:07:12 -05004738 mHandler.post(new Runnable() {
Jose Lima9546b202014-07-02 17:21:51 -07004739 @Override
Daniel Sandler1ce804392012-11-07 15:07:12 -05004740 public void run() {
Jim Miller5ecd8112013-01-09 18:50:26 -08004741 if (mKeyguardDelegate.isDismissable()) {
Daniel Sandler1ce804392012-11-07 15:07:12 -05004742 // Can we just finish the keyguard straight away?
Jim Miller5ecd8112013-01-09 18:50:26 -08004743 mKeyguardDelegate.keyguardDone(false, true);
Daniel Sandler1ce804392012-11-07 15:07:12 -05004744 } else {
4745 // ask the keyguard to prompt the user to authenticate if necessary
Jim Miller5ecd8112013-01-09 18:50:26 -08004746 mKeyguardDelegate.dismiss();
Dianne Hackborn90c52de2011-09-23 12:57:44 -07004747 }
Daniel Sandler1ce804392012-11-07 15:07:12 -05004748 }
4749 });
Dianne Hackborn90c52de2011-09-23 12:57:44 -07004750 }
4751 }
4752
Jorim Jaggicff0acb2014-03-31 16:35:15 +02004753 private void setKeyguardDrawn() {
4754 synchronized (mLock) {
4755 mKeyguardDrawn = true;
4756 }
4757 try {
4758 mWindowManager.enableScreenIfNeeded();
4759 } catch (RemoteException unhandled) {
4760 }
4761 }
4762
4763 @Override
4764 public boolean isKeyguardDrawnLw() {
4765 synchronized (mLock) {
4766 return mKeyguardDrawn;
4767 }
4768 }
4769
Jorim Jaggi0d674622014-05-21 01:34:15 +02004770 @Override
Jorim Jaggie29b2db2014-05-30 23:17:03 +02004771 public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) {
Jorim Jaggi0d674622014-05-21 01:34:15 +02004772 if (mKeyguardDelegate != null) {
Jorim Jaggie29b2db2014-05-30 23:17:03 +02004773 mKeyguardDelegate.startKeyguardExitAnimation(startTime, fadeoutDuration);
Jorim Jaggi0d674622014-05-21 01:34:15 +02004774 }
4775 }
4776
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004777 void sendCloseSystemWindows() {
4778 sendCloseSystemWindows(mContext, null);
4779 }
4780
4781 void sendCloseSystemWindows(String reason) {
4782 sendCloseSystemWindows(mContext, reason);
4783 }
4784
4785 static void sendCloseSystemWindows(Context context, String reason) {
4786 if (ActivityManagerNative.isSystemReady()) {
Dianne Hackborn94a679d2009-07-28 17:51:07 -07004787 try {
4788 ActivityManagerNative.getDefault().closeSystemDialogs(reason);
4789 } catch (RemoteException e) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004790 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004791 }
4792 }
Mitsuru Oshima831d0d92009-06-16 18:27:18 -07004793
Jeff Brown01a98dd2011-09-20 15:08:29 -07004794 @Override
4795 public int rotationForOrientationLw(int orientation, int lastRotation) {
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05004796 if (false) {
4797 Slog.v(TAG, "rotationForOrientationLw(orient="
4798 + orientation + ", last=" + lastRotation
4799 + "); user=" + mUserRotation + " "
4800 + ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED)
4801 ? "USER_ROTATION_LOCKED" : "")
4802 );
4803 }
4804
Craig Mautner46ac6fa2013-08-01 10:06:34 -07004805 if (mForceDefaultOrientation) {
4806 return Surface.ROTATION_0;
4807 }
4808
The Android Open Source Project0727d222009-03-11 12:11:58 -07004809 synchronized (mLock) {
Jeff Brownc0347aa2011-09-23 17:26:09 -07004810 int sensorRotation = mOrientationListener.getProposedRotation(); // may be -1
4811 if (sensorRotation < 0) {
Jeff Brown0f862b42012-09-27 21:11:01 -07004812 sensorRotation = lastRotation;
Jeff Brownc0347aa2011-09-23 17:26:09 -07004813 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004814
Jeff Browndec6cf42011-11-15 14:08:20 -08004815 final int preferredRotation;
Jeff Brown2e7760e2012-04-11 15:14:55 -07004816 if (mLidState == LID_OPEN && mLidOpenRotation >= 0) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07004817 // Ignore sensor when lid switch is open and rotation is forced.
4818 preferredRotation = mLidOpenRotation;
4819 } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR
Jeff Brownc0347aa2011-09-23 17:26:09 -07004820 && (mCarDockEnablesAccelerometer || mCarDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07004821 // Ignore sensor when in car dock unless explicitly enabled.
4822 // This case can override the behavior of NOSENSOR, and can also
4823 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07004824 preferredRotation = mCarDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07004825 ? sensorRotation : mCarDockRotation;
Jeff Brown1a693182011-11-08 14:44:16 -08004826 } else if ((mDockMode == Intent.EXTRA_DOCK_STATE_DESK
4827 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
4828 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK)
Jeff Brownc0347aa2011-09-23 17:26:09 -07004829 && (mDeskDockEnablesAccelerometer || mDeskDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07004830 // Ignore sensor when in desk dock unless explicitly enabled.
4831 // This case can override the behavior of NOSENSOR, and can also
4832 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07004833 preferredRotation = mDeskDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07004834 ? sensorRotation : mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -07004835 } else if (mHdmiPlugged && mDemoHdmiRotationLock) {
4836 // Ignore sensor when plugged into HDMI when demo HDMI rotation lock enabled.
Jeff Browneb3e4b92011-12-06 19:54:24 -08004837 // Note that the dock orientation overrides the HDMI orientation.
Jeff Brownc82c89ed2013-04-17 17:18:15 -07004838 preferredRotation = mDemoHdmiRotation;
4839 } else if (mHdmiPlugged && mDockMode == Intent.EXTRA_DOCK_STATE_UNDOCKED
4840 && mUndockedHdmiRotation >= 0) {
4841 // Ignore sensor when plugged into HDMI and an undocked orientation has
4842 // been specified in the configuration (only for legacy devices without
4843 // full multi-display support).
4844 // Note that the dock orientation overrides the HDMI orientation.
4845 preferredRotation = mUndockedHdmiRotation;
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07004846 } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED) {
4847 // Application just wants to remain locked in the last rotation.
4848 preferredRotation = lastRotation;
Jeff Brownbcdfc622014-03-06 19:13:04 -08004849 } else if (!mSupportAutoRotation) {
4850 // If we don't support auto-rotation then bail out here and ignore
4851 // the sensor and any rotation lock settings.
4852 preferredRotation = -1;
Jeff Brown207673cd2012-06-05 17:47:11 -07004853 } else if ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE
Jeff Brown01a98dd2011-09-20 15:08:29 -07004854 && (orientation == ActivityInfo.SCREEN_ORIENTATION_USER
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07004855 || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
4856 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
4857 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
4858 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER))
Jeff Brown01a98dd2011-09-20 15:08:29 -07004859 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
4860 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
4861 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
4862 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) {
4863 // Otherwise, use sensor only if requested by the application or enabled
4864 // by default for USER or UNSPECIFIED modes. Does not apply to NOSENSOR.
Jeff Brownd3187e32011-09-21 19:26:44 -07004865 if (mAllowAllRotations < 0) {
4866 // Can't read this during init() because the context doesn't
4867 // have display metrics at that time so we cannot determine
4868 // tablet vs. phone then.
4869 mAllowAllRotations = mContext.getResources().getBoolean(
4870 com.android.internal.R.bool.config_allowAllRotations) ? 1 : 0;
4871 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004872 if (sensorRotation != Surface.ROTATION_180
Jeff Brownd3187e32011-09-21 19:26:44 -07004873 || mAllowAllRotations == 1
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07004874 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
4875 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07004876 preferredRotation = sensorRotation;
4877 } else {
4878 preferredRotation = lastRotation;
4879 }
Jeff Brown207673cd2012-06-05 17:47:11 -07004880 } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED
4881 && orientation != ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) {
4882 // Apply rotation lock. Does not apply to NOSENSOR.
4883 // The idea is that the user rotation expresses a weak preference for the direction
4884 // of gravity and as NOSENSOR is never affected by gravity, then neither should
4885 // NOSENSOR be affected by rotation lock (although it will be affected by docks).
Jeff Brown4dfce202011-10-05 12:00:10 -07004886 preferredRotation = mUserRotation;
Jeff Browndec6cf42011-11-15 14:08:20 -08004887 } else {
4888 // No overriding preference.
4889 // We will do exactly what the application asked us to do.
4890 preferredRotation = -1;
Jeff Brown01a98dd2011-09-20 15:08:29 -07004891 }
4892
Dianne Hackborne5439f22010-10-02 16:53:50 -07004893 switch (orientation) {
4894 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08004895 // Return portrait unless overridden.
4896 if (isAnyPortrait(preferredRotation)) {
4897 return preferredRotation;
4898 }
Dianne Hackborne5439f22010-10-02 16:53:50 -07004899 return mPortraitRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07004900
Jeff Brown01a98dd2011-09-20 15:08:29 -07004901 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08004902 // Return landscape unless overridden.
4903 if (isLandscapeOrSeascape(preferredRotation)) {
4904 return preferredRotation;
4905 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004906 return mLandscapeRotation;
4907
4908 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08004909 // Return reverse portrait unless overridden.
4910 if (isAnyPortrait(preferredRotation)) {
4911 return preferredRotation;
4912 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004913 return mUpsideDownRotation;
4914
4915 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08004916 // Return seascape unless overridden.
4917 if (isLandscapeOrSeascape(preferredRotation)) {
4918 return preferredRotation;
4919 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004920 return mSeascapeRotation;
4921
4922 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07004923 case ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE:
Jeff Brown01a98dd2011-09-20 15:08:29 -07004924 // Return either landscape rotation.
4925 if (isLandscapeOrSeascape(preferredRotation)) {
4926 return preferredRotation;
4927 }
4928 if (isLandscapeOrSeascape(lastRotation)) {
Jeff Brown4519f072011-01-23 13:16:01 -08004929 return lastRotation;
4930 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004931 return mLandscapeRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004932
Jeff Brown01a98dd2011-09-20 15:08:29 -07004933 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07004934 case ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT:
Jeff Brown01a98dd2011-09-20 15:08:29 -07004935 // Return either portrait rotation.
4936 if (isAnyPortrait(preferredRotation)) {
4937 return preferredRotation;
4938 }
4939 if (isAnyPortrait(lastRotation)) {
4940 return lastRotation;
4941 }
4942 return mPortraitRotation;
4943
4944 default:
Jeff Brown4dfce202011-10-05 12:00:10 -07004945 // For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR,
4946 // just return the preferred orientation we already calculated.
Jeff Brown01a98dd2011-09-20 15:08:29 -07004947 if (preferredRotation >= 0) {
4948 return preferredRotation;
4949 }
Dianne Hackborndacea8c2011-04-21 17:26:39 -07004950 return Surface.ROTATION_0;
Daniel Sandlere7e5ac22011-02-22 16:10:21 -05004951 }
4952 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07004953 }
4954
Jeff Brown01a98dd2011-09-20 15:08:29 -07004955 @Override
4956 public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation) {
4957 switch (orientation) {
4958 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
4959 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
4960 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
4961 return isAnyPortrait(rotation);
4962
4963 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
4964 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
4965 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
4966 return isLandscapeOrSeascape(rotation);
4967
4968 default:
4969 return true;
4970 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07004971 }
4972
Jeff Brownc0347aa2011-09-23 17:26:09 -07004973 @Override
4974 public void setRotationLw(int rotation) {
4975 mOrientationListener.setCurrentRotation(rotation);
4976 }
4977
Jeff Brown01a98dd2011-09-20 15:08:29 -07004978 private boolean isLandscapeOrSeascape(int rotation) {
4979 return rotation == mLandscapeRotation || rotation == mSeascapeRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07004980 }
4981
Jeff Brown01a98dd2011-09-20 15:08:29 -07004982 private boolean isAnyPortrait(int rotation) {
4983 return rotation == mPortraitRotation || rotation == mUpsideDownRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07004984 }
4985
Jose Lima9546b202014-07-02 17:21:51 -07004986 @Override
Svetoslav Ganov80943d82013-01-02 10:25:37 -08004987 public int getUserRotationMode() {
4988 return Settings.System.getIntForUser(mContext.getContentResolver(),
Brett Chabot7e55c402013-05-16 19:38:08 -07004989 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
4990 WindowManagerPolicy.USER_ROTATION_FREE :
4991 WindowManagerPolicy.USER_ROTATION_LOCKED;
Svetoslav Ganov80943d82013-01-02 10:25:37 -08004992 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004993
4994 // User rotation: to be used when all else fails in assigning an orientation to the device
Jose Lima9546b202014-07-02 17:21:51 -07004995 @Override
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004996 public void setUserRotationMode(int mode, int rot) {
4997 ContentResolver res = mContext.getContentResolver();
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05004998
4999 // mUserRotationMode and mUserRotation will be assigned by the content observer
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005000 if (mode == WindowManagerPolicy.USER_ROTATION_LOCKED) {
Christopher Tate5e08af02012-09-21 17:17:22 -07005001 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005002 Settings.System.USER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005003 rot,
5004 UserHandle.USER_CURRENT);
5005 Settings.System.putIntForUser(res,
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005006 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005007 0,
5008 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005009 } else {
Christopher Tate5e08af02012-09-21 17:17:22 -07005010 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005011 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005012 1,
5013 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005014 }
5015 }
5016
Jose Lima9546b202014-07-02 17:21:51 -07005017 @Override
Jeff Brownac143512012-04-05 18:57:33 -07005018 public void setSafeMode(boolean safeMode) {
5019 mSafeMode = safeMode;
5020 performHapticFeedbackLw(null, safeMode
5021 ? HapticFeedbackConstants.SAFE_MODE_ENABLED
5022 : HapticFeedbackConstants.SAFE_MODE_DISABLED, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005023 }
Craig Mautnereda67292013-04-28 13:50:14 -07005024
Dianne Hackborn181ceb52009-08-27 22:16:40 -07005025 static long[] getLongIntArray(Resources r, int resid) {
5026 int[] ar = r.getIntArray(resid);
5027 if (ar == null) {
5028 return null;
5029 }
5030 long[] out = new long[ar.length];
5031 for (int i=0; i<ar.length; i++) {
5032 out[i] = ar[i];
5033 }
5034 return out;
5035 }
Craig Mautnereda67292013-04-28 13:50:14 -07005036
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005037 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07005038 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005039 public void systemReady() {
Mike Lockwooded8902d2013-11-15 11:01:47 -08005040 mKeyguardDelegate = new KeyguardServiceDelegate(mContext, null);
5041 mKeyguardDelegate.onSystemReady();
5042
Jeff Brown4f5fa282014-06-12 19:19:15 -07005043 updateUiMode();
Dianne Hackbornb1a79802009-09-29 15:18:31 -07005044 synchronized (mLock) {
5045 updateOrientationListenerLp();
Dianne Hackbornc777e072010-02-12 13:07:59 -08005046 mSystemReady = true;
5047 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07005048 @Override
Dianne Hackbornc777e072010-02-12 13:07:59 -08005049 public void run() {
5050 updateSettings();
5051 }
5052 });
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005053 }
5054 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07005055
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005056 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005057 @Override
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005058 public void systemBooted() {
Jim Millere5f910a2013-10-16 18:15:46 -07005059 if (mKeyguardDelegate != null) {
5060 mKeyguardDelegate.onBootCompleted();
5061 }
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005062 synchronized (mLock) {
5063 mSystemBooted = true;
5064 }
Craig Mautner8a0da012014-05-31 15:13:37 -07005065 wakingUp(null);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005066 }
5067
Dianne Hackborn661cd522011-08-22 00:26:20 -07005068 ProgressDialog mBootMsgDialog = null;
5069
5070 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005071 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07005072 public void showBootMessage(final CharSequence msg, final boolean always) {
5073 mHandler.post(new Runnable() {
5074 @Override public void run() {
5075 if (mBootMsgDialog == null) {
Craig Stout4c0cb8a2014-04-04 13:03:10 -07005076 int theme;
5077 if (mContext.getPackageManager().hasSystemFeature(
5078 PackageManager.FEATURE_WATCH)) {
5079 theme = com.android.internal.R.style.Theme_Micro_Dialog_Alert;
5080 } else if (mContext.getPackageManager().hasSystemFeature(
5081 PackageManager.FEATURE_TELEVISION)) {
5082 theme = com.android.internal.R.style.Theme_Leanback_Dialog_Alert;
5083 } else {
5084 theme = 0;
5085 }
Vinod Krishnanfa8fc412014-04-18 14:35:53 -07005086
5087 mBootMsgDialog = new ProgressDialog(mContext, theme) {
Dianne Hackborn295e3c22011-08-25 13:19:08 -07005088 // This dialog will consume all events coming in to
5089 // it, to avoid it trying to do things too early in boot.
5090 @Override public boolean dispatchKeyEvent(KeyEvent event) {
5091 return true;
5092 }
5093 @Override public boolean dispatchKeyShortcutEvent(KeyEvent event) {
5094 return true;
5095 }
5096 @Override public boolean dispatchTouchEvent(MotionEvent ev) {
5097 return true;
5098 }
5099 @Override public boolean dispatchTrackballEvent(MotionEvent ev) {
5100 return true;
5101 }
5102 @Override public boolean dispatchGenericMotionEvent(MotionEvent ev) {
5103 return true;
5104 }
5105 @Override public boolean dispatchPopulateAccessibilityEvent(
5106 AccessibilityEvent event) {
5107 return true;
5108 }
5109 };
Dianne Hackborn661cd522011-08-22 00:26:20 -07005110 mBootMsgDialog.setTitle(R.string.android_upgrading_title);
5111 mBootMsgDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
5112 mBootMsgDialog.setIndeterminate(true);
5113 mBootMsgDialog.getWindow().setType(
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07005114 WindowManager.LayoutParams.TYPE_BOOT_PROGRESS);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005115 mBootMsgDialog.getWindow().addFlags(
5116 WindowManager.LayoutParams.FLAG_DIM_BEHIND
5117 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
5118 mBootMsgDialog.getWindow().setDimAmount(1);
Dianne Hackbornd9efb952011-12-07 14:56:51 -08005119 WindowManager.LayoutParams lp = mBootMsgDialog.getWindow().getAttributes();
5120 lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
5121 mBootMsgDialog.getWindow().setAttributes(lp);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005122 mBootMsgDialog.setCancelable(false);
5123 mBootMsgDialog.show();
5124 }
5125 mBootMsgDialog.setMessage(msg);
5126 }
5127 });
5128 }
5129
5130 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005131 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07005132 public void hideBootMessages() {
Craig Mautnera631d492014-08-05 15:16:01 -07005133 mHandler.sendEmptyMessage(MSG_HIDE_BOOT_MESSAGE);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005134 }
5135
Mike Lockwood28569302010-01-28 11:54:40 -05005136 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005137 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05005138 public void userActivity() {
Dianne Hackborndf89e652011-10-06 22:35:11 -07005139 // ***************************************
5140 // NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
5141 // ***************************************
5142 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
5143 // WITH ITS LOCKS HELD.
5144 //
5145 // This code must be VERY careful about the locks
5146 // it acquires.
5147 // In fact, the current code acquires way too many,
5148 // and probably has lurking deadlocks.
5149
Mike Lockwood28569302010-01-28 11:54:40 -05005150 synchronized (mScreenLockTimeout) {
5151 if (mLockScreenTimerActive) {
5152 // reset the timer
5153 mHandler.removeCallbacks(mScreenLockTimeout);
5154 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
5155 }
5156 }
Daniel Sandler0601eb72011-04-13 01:01:32 -04005157 }
5158
Adam Cohenf7522022012-10-03 20:03:18 -07005159 class ScreenLockTimeout implements Runnable {
5160 Bundle options;
5161
5162 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05005163 public void run() {
5164 synchronized (this) {
5165 if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard");
Jim Miller5ecd8112013-01-09 18:50:26 -08005166 if (mKeyguardDelegate != null) {
5167 mKeyguardDelegate.doKeyguardTimeout(options);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005168 }
Mike Lockwood28569302010-01-28 11:54:40 -05005169 mLockScreenTimerActive = false;
Adam Cohenf7522022012-10-03 20:03:18 -07005170 options = null;
Mike Lockwood28569302010-01-28 11:54:40 -05005171 }
5172 }
Mike Lockwood28569302010-01-28 11:54:40 -05005173
Adam Cohenf7522022012-10-03 20:03:18 -07005174 public void setLockOptions(Bundle options) {
5175 this.options = options;
5176 }
5177 }
5178
5179 ScreenLockTimeout mScreenLockTimeout = new ScreenLockTimeout();
5180
Jose Lima9546b202014-07-02 17:21:51 -07005181 @Override
Adam Cohenf7522022012-10-03 20:03:18 -07005182 public void lockNow(Bundle options) {
Jim Miller93c518e2012-01-17 15:55:31 -08005183 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null);
5184 mHandler.removeCallbacks(mScreenLockTimeout);
Adam Cohenf7522022012-10-03 20:03:18 -07005185 if (options != null) {
5186 // In case multiple calls are made to lockNow, we don't wipe out the options
5187 // until the runnable actually executes.
5188 mScreenLockTimeout.setLockOptions(options);
5189 }
Jim Miller93c518e2012-01-17 15:55:31 -08005190 mHandler.post(mScreenLockTimeout);
5191 }
5192
Mike Lockwood28569302010-01-28 11:54:40 -05005193 private void updateLockScreenTimeout() {
5194 synchronized (mScreenLockTimeout) {
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005195 boolean enable = (mAllowLockscreenWhenOn && mScreenOnEarly &&
Jim Miller5ecd8112013-01-09 18:50:26 -08005196 mKeyguardDelegate != null && mKeyguardDelegate.isSecure());
Mike Lockwood28569302010-01-28 11:54:40 -05005197 if (mLockScreenTimerActive != enable) {
5198 if (enable) {
5199 if (localLOGV) Log.v(TAG, "setting lockscreen timer");
5200 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
5201 } else {
5202 if (localLOGV) Log.v(TAG, "clearing lockscreen timer");
5203 mHandler.removeCallbacks(mScreenLockTimeout);
5204 }
5205 mLockScreenTimerActive = enable;
5206 }
5207 }
5208 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005209
5210 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07005211 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005212 public void enableScreenAfterBoot() {
5213 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07005214 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07005215 updateRotation(true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005216 }
Dianne Hackbornf54c8f92009-09-19 14:03:57 -07005217
Jeff Brownc458ce92012-04-30 14:58:40 -07005218 private void applyLidSwitchState() {
Jeff Brownc458ce92012-04-30 14:58:40 -07005219 if (mLidState == LID_CLOSED && mLidControlsSleep) {
Jeff Brown6d8fd272014-05-20 21:24:38 -07005220 mPowerManager.goToSleep(SystemClock.uptimeMillis(),
5221 PowerManager.GO_TO_SLEEP_REASON_USER,
5222 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
Jeff Brownc458ce92012-04-30 14:58:40 -07005223 }
Jeff Browna20dda42014-05-27 20:57:24 -07005224
5225 synchronized (mLock) {
5226 updateWakeGestureListenerLp();
5227 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005228 }
5229
Jeff Brown4f5fa282014-06-12 19:19:15 -07005230 void updateUiMode() {
5231 if (mUiModeManager == null) {
5232 mUiModeManager = IUiModeManager.Stub.asInterface(
5233 ServiceManager.getService(Context.UI_MODE_SERVICE));
5234 }
5235 try {
5236 mUiMode = mUiModeManager.getCurrentModeType();
5237 } catch (RemoteException e) {
5238 }
5239 }
5240
Jeff Brown01a98dd2011-09-20 15:08:29 -07005241 void updateRotation(boolean alwaysSendConfiguration) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005242 try {
5243 //set orientation on WindowManager
Dianne Hackbornf87d1962012-04-04 12:48:24 -07005244 mWindowManager.updateRotation(alwaysSendConfiguration, false);
5245 } catch (RemoteException e) {
5246 // Ignore
5247 }
5248 }
5249
5250 void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) {
5251 try {
5252 //set orientation on WindowManager
5253 mWindowManager.updateRotation(alwaysSendConfiguration, forceRelayout);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005254 } catch (RemoteException e) {
5255 // Ignore
5256 }
5257 }
5258
Daniel Sandler6396c722013-04-16 20:19:09 -04005259 /**
5260 * Return an Intent to launch the currently active dock app as home. Returns
5261 * null if the standard home should be launched, which is the case if any of the following is
5262 * true:
5263 * <ul>
5264 * <li>The device is not in either car mode or desk mode
5265 * <li>The device is in car mode but ENABLE_CAR_DOCK_HOME_CAPTURE is false
5266 * <li>The device is in desk mode but ENABLE_DESK_DOCK_HOME_CAPTURE is false
5267 * <li>The device is in car mode but there's no CAR_DOCK app with METADATA_DOCK_HOME
5268 * <li>The device is in desk mode but there's no DESK_DOCK app with METADATA_DOCK_HOME
5269 * </ul>
Craig Mautnereda67292013-04-28 13:50:14 -07005270 * @return A dock intent.
Daniel Sandler6396c722013-04-16 20:19:09 -04005271 */
5272 Intent createHomeDockIntent() {
5273 Intent intent = null;
5274
5275 // What home does is based on the mode, not the dock state. That
5276 // is, when in car mode you should be taken to car home regardless
5277 // of whether we are actually in a car dock.
5278 if (mUiMode == Configuration.UI_MODE_TYPE_CAR) {
5279 if (ENABLE_CAR_DOCK_HOME_CAPTURE) {
5280 intent = mCarDockIntent;
5281 }
5282 } else if (mUiMode == Configuration.UI_MODE_TYPE_DESK) {
5283 if (ENABLE_DESK_DOCK_HOME_CAPTURE) {
5284 intent = mDeskDockIntent;
5285 }
Jeff Brown4f5fa282014-06-12 19:19:15 -07005286 } else if (mUiMode == Configuration.UI_MODE_TYPE_WATCH
5287 && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
5288 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK
5289 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK)) {
5290 // Always launch dock home from home when watch is docked, if it exists.
5291 intent = mDeskDockIntent;
Daniel Sandler6396c722013-04-16 20:19:09 -04005292 }
5293
5294 if (intent == null) {
5295 return null;
5296 }
5297
5298 ActivityInfo ai = null;
5299 ResolveInfo info = mContext.getPackageManager().resolveActivityAsUser(
5300 intent,
John Spurlockf56bef12013-07-09 09:51:46 -04005301 PackageManager.MATCH_DEFAULT_ONLY | PackageManager.GET_META_DATA,
Craig Mautnerd625ab22013-09-06 13:40:31 -07005302 mCurrentUserId);
Daniel Sandler6396c722013-04-16 20:19:09 -04005303 if (info != null) {
5304 ai = info.activityInfo;
5305 }
5306 if (ai != null
5307 && ai.metaData != null
5308 && ai.metaData.getBoolean(Intent.METADATA_DOCK_HOME)) {
5309 intent = new Intent(intent);
5310 intent.setClassName(ai.packageName, ai.name);
5311 return intent;
5312 }
5313
5314 return null;
5315 }
5316
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005317 void startDockOrHome() {
John Spurlockc8b46ca2013-04-08 12:59:26 -04005318 awakenDreams();
Daniel Sandler6396c722013-04-16 20:19:09 -04005319
5320 Intent dock = createHomeDockIntent();
5321 if (dock != null) {
5322 try {
5323 mContext.startActivityAsUser(dock, UserHandle.CURRENT);
5324 return;
5325 } catch (ActivityNotFoundException e) {
5326 }
5327 }
5328
Dianne Hackbornd8883992012-09-07 15:58:52 -07005329 mContext.startActivityAsUser(mHomeIntent, UserHandle.CURRENT);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005330 }
Craig Mautnereda67292013-04-28 13:50:14 -07005331
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005332 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005333 * goes to the home screen
5334 * @return whether it did anything
5335 */
5336 boolean goHome() {
5337 if (false) {
5338 // This code always brings home to the front.
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07005339 try {
5340 ActivityManagerNative.getDefault().stopAppSwitches();
5341 } catch (RemoteException e) {
5342 }
Dianne Hackborn94a679d2009-07-28 17:51:07 -07005343 sendCloseSystemWindows();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005344 startDockOrHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005345 } else {
5346 // This code brings home to the front or, if it is already
5347 // at the front, puts the device to sleep.
5348 try {
Wink Savilled2e6a332010-02-12 12:12:06 -08005349 if (SystemProperties.getInt("persist.sys.uts-test-mode", 0) == 1) {
5350 /// Roll back EndcallBehavior as the cupcake design to pass P1 lab entry.
5351 Log.d(TAG, "UTS-TEST-MODE");
5352 } else {
5353 ActivityManagerNative.getDefault().stopAppSwitches();
5354 sendCloseSystemWindows();
Daniel Sandler6396c722013-04-16 20:19:09 -04005355 Intent dock = createHomeDockIntent();
5356 if (dock != null) {
5357 int result = ActivityManagerNative.getDefault()
5358 .startActivityAsUser(null, null, dock,
5359 dock.resolveTypeIfNeeded(mContext.getContentResolver()),
5360 null, null, 0,
5361 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
5362 null, null, null, UserHandle.USER_CURRENT);
5363 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
5364 return false;
5365 }
5366 }
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005367 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005368 int result = ActivityManagerNative.getDefault()
Dianne Hackbornf265ea92013-01-31 15:00:51 -08005369 .startActivityAsUser(null, null, mHomeIntent,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005370 mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()),
Dianne Hackborna4972e92012-03-14 10:38:05 -07005371 null, null, 0,
5372 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Dianne Hackborn5e03e2c2012-09-06 14:21:19 -07005373 null, null, null, UserHandle.USER_CURRENT);
Dianne Hackborna4972e92012-03-14 10:38:05 -07005374 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005375 return false;
5376 }
5377 } catch (RemoteException ex) {
5378 // bummer, the activity manager, which is in this process, is dead
5379 }
5380 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005381 return true;
5382 }
Craig Mautnereda67292013-04-28 13:50:14 -07005383
5384 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07005385 public void setCurrentOrientationLw(int newOrientation) {
5386 synchronized (mLock) {
5387 if (newOrientation != mCurrentAppOrientation) {
5388 mCurrentAppOrientation = newOrientation;
5389 updateOrientationListenerLp();
5390 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005391 }
5392 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08005393
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07005394 private void performAuditoryFeedbackForAccessibilityIfNeed() {
5395 if (!isGlobalAccessibilityGestureEnabled()) {
5396 return;
5397 }
5398 AudioManager audioManager = (AudioManager) mContext.getSystemService(
5399 Context.AUDIO_SERVICE);
5400 if (audioManager.isSilentMode()) {
5401 return;
5402 }
5403 Ringtone ringTone = RingtoneManager.getRingtone(mContext,
5404 Settings.System.DEFAULT_NOTIFICATION_URI);
5405 ringTone.setStreamType(AudioManager.STREAM_MUSIC);
5406 ringTone.play();
5407 }
Craig Mautnereda67292013-04-28 13:50:14 -07005408
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07005409 private boolean isGlobalAccessibilityGestureEnabled() {
5410 return Settings.Global.getInt(mContext.getContentResolver(),
5411 Settings.Global.ENABLE_ACCESSIBILITY_GLOBAL_GESTURE_ENABLED, 0) == 1;
5412 }
5413
Craig Mautnereda67292013-04-28 13:50:14 -07005414 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07005415 public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) {
Svetoslav Ganov96179212012-10-10 14:17:45 -07005416 if (!mVibrator.hasVibrator()) {
5417 return false;
5418 }
Christopher Tate5e08af02012-09-21 17:17:22 -07005419 final boolean hapticsDisabled = Settings.System.getIntForUser(mContext.getContentResolver(),
5420 Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) == 0;
Jeff Brown82379ba2014-07-25 19:03:28 -07005421 if (hapticsDisabled && !always) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005422 return false;
5423 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08005424 long[] pattern = null;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005425 switch (effectId) {
5426 case HapticFeedbackConstants.LONG_PRESS:
Amith Yamasanic33cb712010-02-10 15:21:49 -08005427 pattern = mLongPressVibePattern;
5428 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07005429 case HapticFeedbackConstants.VIRTUAL_KEY:
Amith Yamasanic33cb712010-02-10 15:21:49 -08005430 pattern = mVirtualKeyVibePattern;
5431 break;
5432 case HapticFeedbackConstants.KEYBOARD_TAP:
5433 pattern = mKeyboardTapVibePattern;
5434 break;
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07005435 case HapticFeedbackConstants.CLOCK_TICK:
5436 pattern = mClockTickVibePattern;
5437 break;
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07005438 case HapticFeedbackConstants.CALENDAR_DATE:
5439 pattern = mCalendarDateVibePattern;
5440 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07005441 case HapticFeedbackConstants.SAFE_MODE_DISABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08005442 pattern = mSafeModeDisabledVibePattern;
5443 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07005444 case HapticFeedbackConstants.SAFE_MODE_ENABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08005445 pattern = mSafeModeEnabledVibePattern;
5446 break;
Amith Yamasanic33cb712010-02-10 15:21:49 -08005447 default:
5448 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005449 }
Dianne Hackbornf265ea92013-01-31 15:00:51 -08005450 int owningUid;
5451 String owningPackage;
5452 if (win != null) {
5453 owningUid = win.getOwningUid();
5454 owningPackage = win.getOwningPackage();
5455 } else {
5456 owningUid = android.os.Process.myUid();
Dianne Hackborn95d78532013-09-11 09:51:14 -07005457 owningPackage = mContext.getOpPackageName();
Dianne Hackbornf265ea92013-01-31 15:00:51 -08005458 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08005459 if (pattern.length == 1) {
5460 // One-shot vibration
John Spurlock7b414672014-07-18 13:02:39 -04005461 mVibrator.vibrate(owningUid, owningPackage, pattern[0], VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08005462 } else {
5463 // Pattern vibration
John Spurlock7b414672014-07-18 13:02:39 -04005464 mVibrator.vibrate(owningUid, owningPackage, pattern, -1, VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08005465 }
5466 return true;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005467 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005468
5469 @Override
5470 public void keepScreenOnStartedLw() {
Daniel Sandler0601eb72011-04-13 01:01:32 -04005471 }
5472
Jeff Brownc38c9be2012-10-04 13:16:19 -07005473 @Override
5474 public void keepScreenOnStoppedLw() {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01005475 if (mKeyguardDelegate != null && !mKeyguardDelegate.isShowingAndNotOccluded()) {
Jim Miller25190572013-02-28 17:36:24 -08005476 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005477 }
5478 }
Mike Lockwoodfcb39242009-10-21 23:01:07 -04005479
Dianne Hackborndf89e652011-10-06 22:35:11 -07005480 private int updateSystemUiVisibilityLw() {
Joe Onorato664644d2011-01-23 17:53:23 -08005481 // If there is no window focused, there will be nobody to handle the events
5482 // anyway, so just hang on in whatever state we're in until things settle down.
John Spurlock79da8332013-09-20 12:04:47 -04005483 WindowState win = mFocusedWindow != null ? mFocusedWindow : mTopFullscreenOpaqueWindowState;
5484 if (win == null) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07005485 return 0;
5486 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01005487 if ((win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 && mHideLockScreen == true) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07005488 // We are updating at a point where the keyguard has gotten
5489 // focus, but we were last in a state where the top window is
5490 // hiding it. This is probably because the keyguard as been
5491 // shown while the top window was displayed, so we want to ignore
5492 // it here because this is just a very transient change and it
5493 // will quickly lose focus once it correctly gets hidden.
5494 return 0;
5495 }
John Spurlock32beb2c2013-03-11 10:16:47 -04005496
John Spurlock1db8b682014-02-18 11:18:59 -05005497 int tmpVisibility = PolicyControl.getSystemUiVisibility(win, null)
Dianne Hackborne26ab702011-10-16 13:21:33 -07005498 & ~mResettingSystemUiFlags
5499 & ~mForceClearedSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04005500 if (mForcingShowNavBar && win.getSurfaceLayer() < mForcingShowNavBarLayer) {
John Spurlockc6d1c602014-01-17 15:22:06 -05005501 tmpVisibility &= ~PolicyControl.adjustClearableFlags(win, View.SYSTEM_UI_CLEARABLE_FLAGS);
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08005502 }
John Spurlock79da8332013-09-20 12:04:47 -04005503 final int visibility = updateSystemBarsLw(win, mLastSystemUiFlags, tmpVisibility);
John Spurlockad3e6cb2013-04-30 08:47:43 -04005504 final int diff = visibility ^ mLastSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04005505 final boolean needsMenu = win.getNeedsMenuLw(mTopFullscreenOpaqueWindowState);
Dianne Hackborne0f085d2011-11-30 18:41:15 -08005506 if (diff == 0 && mLastFocusNeedsMenu == needsMenu
John Spurlock79da8332013-09-20 12:04:47 -04005507 && mFocusedApp == win.getAppToken()) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07005508 return 0;
5509 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07005510 mLastSystemUiFlags = visibility;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08005511 mLastFocusNeedsMenu = needsMenu;
John Spurlock79da8332013-09-20 12:04:47 -04005512 mFocusedApp = win.getAppToken();
Dianne Hackborndf89e652011-10-06 22:35:11 -07005513 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07005514 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07005515 public void run() {
Dianne Hackborn42e620c2012-06-24 13:20:51 -07005516 try {
5517 IStatusBarService statusbar = getStatusBarService();
5518 if (statusbar != null) {
5519 statusbar.setSystemUiVisibility(visibility, 0xffffffff);
5520 statusbar.topAppWindowChanged(needsMenu);
Joe Onorato664644d2011-01-23 17:53:23 -08005521 }
Dianne Hackborn42e620c2012-06-24 13:20:51 -07005522 } catch (RemoteException e) {
5523 // re-acquire status bar service next time it is needed.
5524 mStatusBarService = null;
Joe Onorato664644d2011-01-23 17:53:23 -08005525 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07005526 }
5527 });
5528 return diff;
Joe Onorato664644d2011-01-23 17:53:23 -08005529 }
5530
John Spurlock79da8332013-09-20 12:04:47 -04005531 private int updateSystemBarsLw(WindowState win, int oldVis, int vis) {
John Spurlockbd957402013-10-03 11:38:39 -04005532 // apply translucent bar vis flags
Jorim Jaggi380ecb82014-03-14 17:25:20 +01005533 WindowState transWin = isStatusBarKeyguard() && !mHideLockScreen
5534 ? mStatusBar
John Spurlockbd957402013-10-03 11:38:39 -04005535 : mTopFullscreenOpaqueWindowState;
5536 vis = mStatusBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
5537 vis = mNavigationBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
5538
John Spurlock27735a42013-08-14 17:57:38 -04005539 // prevent status bar interaction from clearing certain flags
John Spurlock79da8332013-09-20 12:04:47 -04005540 boolean statusBarHasFocus = win.getAttrs().type == TYPE_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04005541 if (statusBarHasFocus && !isStatusBarKeyguard()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04005542 int flags = View.SYSTEM_UI_FLAG_FULLSCREEN
5543 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlockcfc359a2013-09-05 10:42:03 -04005544 | View.SYSTEM_UI_FLAG_IMMERSIVE
Jorim Jaggi5cf17872014-03-26 18:31:48 +01005545 | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
John Spurlock08ffcf52014-07-11 10:13:46 -04005546 if (mHideLockScreen) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01005547 flags |= View.STATUS_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSLUCENT;
5548 }
John Spurlockbd957402013-10-03 11:38:39 -04005549 vis = (vis & ~flags) | (oldVis & flags);
John Spurlockad3e6cb2013-04-30 08:47:43 -04005550 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04005551
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04005552 if (!areTranslucentBarsAllowed()) {
Adrian Roosea562512014-05-05 13:33:03 +02005553 vis &= ~(View.NAVIGATION_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSLUCENT
5554 | View.SYSTEM_UI_TRANSPARENT);
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07005555 }
5556
John Spurlock27735a42013-08-14 17:57:38 -04005557 // update status bar
John Spurlockf1a36642013-10-12 17:50:42 -04005558 boolean immersiveSticky =
5559 (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
John Spurlock27735a42013-08-14 17:57:38 -04005560 boolean hideStatusBarWM =
John Spurlockbd957402013-10-03 11:38:39 -04005561 mTopFullscreenOpaqueWindowState != null &&
John Spurlockc6d1c602014-01-17 15:22:06 -05005562 (PolicyControl.getWindowFlags(mTopFullscreenOpaqueWindowState, null)
John Spurlock27735a42013-08-14 17:57:38 -04005563 & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0;
5564 boolean hideStatusBarSysui =
5565 (vis & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04005566 boolean hideNavBarSysui =
5567 (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0;
John Spurlockad3e6cb2013-04-30 08:47:43 -04005568
John Spurlock27735a42013-08-14 17:57:38 -04005569 boolean transientStatusBarAllowed =
5570 mStatusBar != null && (
5571 hideStatusBarWM
John Spurlockf1a36642013-10-12 17:50:42 -04005572 || (hideStatusBarSysui && immersiveSticky)
John Spurlock27735a42013-08-14 17:57:38 -04005573 || statusBarHasFocus);
5574
John Spurlockf1a36642013-10-12 17:50:42 -04005575 boolean transientNavBarAllowed =
5576 mNavigationBar != null &&
5577 hideNavBarSysui && immersiveSticky;
5578
John Spurlockf25706f2013-11-07 18:02:43 -05005579 boolean denyTransientStatus = mStatusBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04005580 && !transientStatusBarAllowed && hideStatusBarSysui;
John Spurlockf25706f2013-11-07 18:02:43 -05005581 boolean denyTransientNav = mNavigationBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04005582 && !transientNavBarAllowed;
5583 if (denyTransientStatus || denyTransientNav) {
John Spurlock27735a42013-08-14 17:57:38 -04005584 // clear the clearable flags instead
John Spurlockf1a36642013-10-12 17:50:42 -04005585 clearClearableFlagsLw();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005586 }
John Spurlock27735a42013-08-14 17:57:38 -04005587
5588 vis = mStatusBarController.updateVisibilityLw(transientStatusBarAllowed, oldVis, vis);
5589
5590 // update navigation bar
John Spurlockf1a36642013-10-12 17:50:42 -04005591 boolean oldImmersiveMode = isImmersiveMode(oldVis);
5592 boolean newImmersiveMode = isImmersiveMode(vis);
5593 if (win != null && oldImmersiveMode != newImmersiveMode) {
John Spurlock79da8332013-09-20 12:04:47 -04005594 final String pkg = win.getOwningPackage();
Maurice Lam99c6e072014-04-28 18:24:28 -07005595 mImmersiveModeConfirmation.immersiveModeChanged(pkg, newImmersiveMode,
5596 isUserSetupComplete());
John Spurlock34e13d92013-08-10 06:52:28 -04005597 }
John Spurlock27735a42013-08-14 17:57:38 -04005598
John Spurlockf1a36642013-10-12 17:50:42 -04005599 vis = mNavigationBarController.updateVisibilityLw(transientNavBarAllowed, oldVis, vis);
5600
John Spurlocke1f366f2013-08-05 12:22:40 -04005601 return vis;
John Spurlockad3e6cb2013-04-30 08:47:43 -04005602 }
5603
John Spurlockf1a36642013-10-12 17:50:42 -04005604 private void clearClearableFlagsLw() {
5605 int newVal = mResettingSystemUiFlags | View.SYSTEM_UI_CLEARABLE_FLAGS;
5606 if (newVal != mResettingSystemUiFlags) {
5607 mResettingSystemUiFlags = newVal;
5608 mWindowManagerFuncs.reevaluateStatusBarVisibility();
5609 }
5610 }
5611
5612 private boolean isImmersiveMode(int vis) {
5613 final int flags = View.SYSTEM_UI_FLAG_IMMERSIVE | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
John Spurlock34e13d92013-08-10 06:52:28 -04005614 return mNavigationBar != null
5615 && (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0
Daniel Sandler900ece52013-10-18 15:53:27 -04005616 && (vis & flags) != 0
5617 && canHideNavigationBar();
John Spurlock34e13d92013-08-10 06:52:28 -04005618 }
5619
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07005620 /**
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04005621 * @return whether the navigation or status bar can be made translucent
5622 *
5623 * This should return true unless touch exploration is not enabled or
5624 * R.boolean.config_enableTranslucentDecor is false.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07005625 */
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04005626 private boolean areTranslucentBarsAllowed() {
Svetoslav8e3feb12014-02-24 13:46:47 -08005627 return mTranslucentDecorEnabled
5628 && !mAccessibilityManager.isTouchExplorationEnabled();
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07005629 }
5630
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04005631 // Use this instead of checking config_showNavigationBar so that it can be consistently
5632 // overridden by qemu.hw.mainkeys in the emulator.
Craig Mautnereda67292013-04-28 13:50:14 -07005633 @Override
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04005634 public boolean hasNavigationBar() {
5635 return mHasNavigationBar;
5636 }
5637
satok1bc0a492012-04-25 22:47:12 +09005638 @Override
5639 public void setLastInputMethodWindowLw(WindowState ime, WindowState target) {
5640 mLastInputMethodWindow = ime;
5641 mLastInputMethodTargetWindow = target;
5642 }
5643
Craig Mautnerf1b67412012-09-19 13:18:29 -07005644 @Override
Satoshi Kataoka658c7b82013-10-10 17:03:51 +09005645 public int getInputMethodWindowVisibleHeightLw() {
5646 return mDockBottom - mCurBottom;
5647 }
5648
5649 @Override
Craig Mautnerf1b67412012-09-19 13:18:29 -07005650 public void setCurrentUserLw(int newUserId) {
Craig Mautnerd625ab22013-09-06 13:40:31 -07005651 mCurrentUserId = newUserId;
Jim Miller5ecd8112013-01-09 18:50:26 -08005652 if (mKeyguardDelegate != null) {
5653 mKeyguardDelegate.setCurrentUser(newUserId);
Craig Mautnerf1b67412012-09-19 13:18:29 -07005654 }
John Spurlock13451a22012-09-28 14:40:41 -04005655 if (mStatusBarService != null) {
5656 try {
5657 mStatusBarService.setCurrentUser(newUserId);
5658 } catch (RemoteException e) {
5659 // oh well
5660 }
5661 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07005662 setLastInputMethodWindowLw(null, null);
Craig Mautnerf1b67412012-09-19 13:18:29 -07005663 }
5664
5665 @Override
Svetoslav Ganov545252f2012-12-10 18:29:24 -08005666 public boolean canMagnifyWindow(int windowType) {
5667 switch (windowType) {
5668 case WindowManager.LayoutParams.TYPE_INPUT_METHOD:
5669 case WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG:
5670 case WindowManager.LayoutParams.TYPE_NAVIGATION_BAR:
5671 case WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY: {
5672 return false;
5673 }
5674 }
5675 return true;
5676 }
5677
5678 @Override
5679 public boolean isTopLevelWindow(int windowType) {
5680 if (windowType >= WindowManager.LayoutParams.FIRST_SUB_WINDOW
5681 && windowType <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
5682 return (windowType == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG);
5683 }
5684 return true;
5685 }
5686
Jim Miller4eeb4f62012-11-08 00:04:29 -08005687 @Override
Jeff Brownd7a04de2012-06-17 14:17:52 -07005688 public void dump(String prefix, PrintWriter pw, String[] args) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005689 pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005690 pw.print(" mSystemReady="); pw.print(mSystemReady);
5691 pw.print(" mSystemBooted="); pw.println(mSystemBooted);
Jeff Brown2e7760e2012-04-11 15:14:55 -07005692 pw.print(prefix); pw.print("mLidState="); pw.print(mLidState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005693 pw.print(" mLidOpenRotation="); pw.print(mLidOpenRotation);
5694 pw.print(" mHdmiPlugged="); pw.println(mHdmiPlugged);
Dianne Hackborne26ab702011-10-16 13:21:33 -07005695 if (mLastSystemUiFlags != 0 || mResettingSystemUiFlags != 0
5696 || mForceClearedSystemUiFlags != 0) {
5697 pw.print(prefix); pw.print("mLastSystemUiFlags=0x");
5698 pw.print(Integer.toHexString(mLastSystemUiFlags));
5699 pw.print(" mResettingSystemUiFlags=0x");
5700 pw.print(Integer.toHexString(mResettingSystemUiFlags));
5701 pw.print(" mForceClearedSystemUiFlags=0x");
5702 pw.println(Integer.toHexString(mForceClearedSystemUiFlags));
Dianne Hackborndf89e652011-10-06 22:35:11 -07005703 }
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08005704 if (mLastFocusNeedsMenu) {
5705 pw.print(prefix); pw.print("mLastFocusNeedsMenu=");
5706 pw.println(mLastFocusNeedsMenu);
5707 }
Jeff Browna20dda42014-05-27 20:57:24 -07005708 pw.print(prefix); pw.print("mWakeGestureEnabledSetting=");
5709 pw.println(mWakeGestureEnabledSetting);
5710
Jeff Brownbcdfc622014-03-06 19:13:04 -08005711 pw.print(prefix); pw.print("mSupportAutoRotation="); pw.println(mSupportAutoRotation);
Daniel Sandler6396c722013-04-16 20:19:09 -04005712 pw.print(prefix); pw.print("mUiMode="); pw.print(mUiMode);
5713 pw.print(" mDockMode="); pw.print(mDockMode);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005714 pw.print(" mCarDockRotation="); pw.print(mCarDockRotation);
5715 pw.print(" mDeskDockRotation="); pw.println(mDeskDockRotation);
5716 pw.print(prefix); pw.print("mUserRotationMode="); pw.print(mUserRotationMode);
5717 pw.print(" mUserRotation="); pw.print(mUserRotation);
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005718 pw.print(" mAllowAllRotations="); pw.println(mAllowAllRotations);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07005719 pw.print(prefix); pw.print("mCurrentAppOrientation="); pw.println(mCurrentAppOrientation);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005720 pw.print(prefix); pw.print("mCarDockEnablesAccelerometer=");
5721 pw.print(mCarDockEnablesAccelerometer);
5722 pw.print(" mDeskDockEnablesAccelerometer=");
5723 pw.println(mDeskDockEnablesAccelerometer);
5724 pw.print(prefix); pw.print("mLidKeyboardAccessibility=");
5725 pw.print(mLidKeyboardAccessibility);
5726 pw.print(" mLidNavigationAccessibility="); pw.print(mLidNavigationAccessibility);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07005727 pw.print(" mLidControlsSleep="); pw.println(mLidControlsSleep);
Jeff Brown6d8fd272014-05-20 21:24:38 -07005728 pw.print(prefix);
5729 pw.print("mShortPressOnPowerBehavior="); pw.print(mShortPressOnPowerBehavior);
5730 pw.print(" mLongPressOnPowerBehavior="); pw.println(mLongPressOnPowerBehavior);
5731 pw.print(prefix); pw.print("mHasSoftInput="); pw.println(mHasSoftInput);
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07005732 pw.print(prefix); pw.print("mScreenOnEarly="); pw.print(mScreenOnEarly);
5733 pw.print(" mScreenOnFully="); pw.print(mScreenOnFully);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07005734 pw.print(" mOrientationSensorEnabled="); pw.println(mOrientationSensorEnabled);
Dianne Hackbornc652de82013-02-15 16:32:56 -08005735 pw.print(prefix); pw.print("mOverscanScreen=("); pw.print(mOverscanScreenLeft);
5736 pw.print(","); pw.print(mOverscanScreenTop);
5737 pw.print(") "); pw.print(mOverscanScreenWidth);
5738 pw.print("x"); pw.println(mOverscanScreenHeight);
5739 if (mOverscanLeft != 0 || mOverscanTop != 0
5740 || mOverscanRight != 0 || mOverscanBottom != 0) {
5741 pw.print(prefix); pw.print("mOverscan left="); pw.print(mOverscanLeft);
5742 pw.print(" top="); pw.print(mOverscanTop);
5743 pw.print(" right="); pw.print(mOverscanRight);
5744 pw.print(" bottom="); pw.println(mOverscanBottom);
5745 }
Dianne Hackborn313440842013-02-19 19:22:59 -08005746 pw.print(prefix); pw.print("mRestrictedOverscanScreen=(");
5747 pw.print(mRestrictedOverscanScreenLeft);
5748 pw.print(","); pw.print(mRestrictedOverscanScreenTop);
5749 pw.print(") "); pw.print(mRestrictedOverscanScreenWidth);
5750 pw.print("x"); pw.println(mRestrictedOverscanScreenHeight);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005751 pw.print(prefix); pw.print("mUnrestrictedScreen=("); pw.print(mUnrestrictedScreenLeft);
5752 pw.print(","); pw.print(mUnrestrictedScreenTop);
5753 pw.print(") "); pw.print(mUnrestrictedScreenWidth);
5754 pw.print("x"); pw.println(mUnrestrictedScreenHeight);
5755 pw.print(prefix); pw.print("mRestrictedScreen=("); pw.print(mRestrictedScreenLeft);
5756 pw.print(","); pw.print(mRestrictedScreenTop);
5757 pw.print(") "); pw.print(mRestrictedScreenWidth);
5758 pw.print("x"); pw.println(mRestrictedScreenHeight);
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07005759 pw.print(prefix); pw.print("mStableFullscreen=("); pw.print(mStableFullscreenLeft);
5760 pw.print(","); pw.print(mStableFullscreenTop);
5761 pw.print(")-("); pw.print(mStableFullscreenRight);
5762 pw.print(","); pw.print(mStableFullscreenBottom); pw.println(")");
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07005763 pw.print(prefix); pw.print("mStable=("); pw.print(mStableLeft);
5764 pw.print(","); pw.print(mStableTop);
5765 pw.print(")-("); pw.print(mStableRight);
5766 pw.print(","); pw.print(mStableBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07005767 pw.print(prefix); pw.print("mSystem=("); pw.print(mSystemLeft);
5768 pw.print(","); pw.print(mSystemTop);
5769 pw.print(")-("); pw.print(mSystemRight);
5770 pw.print(","); pw.print(mSystemBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005771 pw.print(prefix); pw.print("mCur=("); pw.print(mCurLeft);
5772 pw.print(","); pw.print(mCurTop);
5773 pw.print(")-("); pw.print(mCurRight);
5774 pw.print(","); pw.print(mCurBottom); pw.println(")");
5775 pw.print(prefix); pw.print("mContent=("); pw.print(mContentLeft);
5776 pw.print(","); pw.print(mContentTop);
5777 pw.print(")-("); pw.print(mContentRight);
5778 pw.print(","); pw.print(mContentBottom); pw.println(")");
Dianne Hackborne30e02f2014-05-27 18:24:45 -07005779 pw.print(prefix); pw.print("mVoiceContent=("); pw.print(mVoiceContentLeft);
5780 pw.print(","); pw.print(mVoiceContentTop);
5781 pw.print(")-("); pw.print(mVoiceContentRight);
5782 pw.print(","); pw.print(mVoiceContentBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005783 pw.print(prefix); pw.print("mDock=("); pw.print(mDockLeft);
5784 pw.print(","); pw.print(mDockTop);
5785 pw.print(")-("); pw.print(mDockRight);
5786 pw.print(","); pw.print(mDockBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07005787 pw.print(prefix); pw.print("mDockLayer="); pw.print(mDockLayer);
5788 pw.print(" mStatusBarLayer="); pw.println(mStatusBarLayer);
Dianne Hackborn7ad44382012-10-18 17:46:00 -07005789 pw.print(prefix); pw.print("mShowingLockscreen="); pw.print(mShowingLockscreen);
5790 pw.print(" mShowingDream="); pw.print(mShowingDream);
5791 pw.print(" mDreamingLockscreen="); pw.println(mDreamingLockscreen);
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07005792 if (mLastInputMethodWindow != null) {
5793 pw.print(prefix); pw.print("mLastInputMethodWindow=");
5794 pw.println(mLastInputMethodWindow);
5795 }
5796 if (mLastInputMethodTargetWindow != null) {
5797 pw.print(prefix); pw.print("mLastInputMethodTargetWindow=");
5798 pw.println(mLastInputMethodTargetWindow);
5799 }
5800 if (mStatusBar != null) {
5801 pw.print(prefix); pw.print("mStatusBar=");
5802 pw.println(mStatusBar);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01005803 pw.print(prefix); pw.print("isStatusBarKeyguard=");
5804 pw.print(isStatusBarKeyguard());
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07005805 }
5806 if (mNavigationBar != null) {
5807 pw.print(prefix); pw.print("mNavigationBar=");
5808 pw.println(mNavigationBar);
5809 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07005810 if (mFocusedWindow != null) {
5811 pw.print(prefix); pw.print("mFocusedWindow=");
5812 pw.println(mFocusedWindow);
5813 }
5814 if (mFocusedApp != null) {
5815 pw.print(prefix); pw.print("mFocusedApp=");
5816 pw.println(mFocusedApp);
5817 }
5818 if (mWinDismissingKeyguard != null) {
5819 pw.print(prefix); pw.print("mWinDismissingKeyguard=");
5820 pw.println(mWinDismissingKeyguard);
5821 }
5822 if (mTopFullscreenOpaqueWindowState != null) {
5823 pw.print(prefix); pw.print("mTopFullscreenOpaqueWindowState=");
5824 pw.println(mTopFullscreenOpaqueWindowState);
5825 }
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08005826 if (mForcingShowNavBar) {
5827 pw.print(prefix); pw.print("mForcingShowNavBar=");
5828 pw.println(mForcingShowNavBar); pw.print( "mForcingShowNavBarLayer=");
5829 pw.println(mForcingShowNavBarLayer);
5830 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07005831 pw.print(prefix); pw.print("mTopIsFullscreen="); pw.print(mTopIsFullscreen);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005832 pw.print(" mHideLockScreen="); pw.println(mHideLockScreen);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07005833 pw.print(prefix); pw.print("mForceStatusBar="); pw.print(mForceStatusBar);
5834 pw.print(" mForceStatusBarFromKeyguard=");
5835 pw.println(mForceStatusBarFromKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005836 pw.print(prefix); pw.print("mDismissKeyguard="); pw.print(mDismissKeyguard);
Craig Mautnerad09bcc2012-10-08 13:33:11 -07005837 pw.print(" mWinDismissingKeyguard="); pw.print(mWinDismissingKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005838 pw.print(" mHomePressed="); pw.println(mHomePressed);
5839 pw.print(prefix); pw.print("mAllowLockscreenWhenOn="); pw.print(mAllowLockscreenWhenOn);
5840 pw.print(" mLockScreenTimeout="); pw.print(mLockScreenTimeout);
5841 pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive);
5842 pw.print(prefix); pw.print("mEndcallBehavior="); pw.print(mEndcallBehavior);
5843 pw.print(" mIncallPowerBehavior="); pw.print(mIncallPowerBehavior);
5844 pw.print(" mLongPressOnHomeBehavior="); pw.println(mLongPressOnHomeBehavior);
5845 pw.print(prefix); pw.print("mLandscapeRotation="); pw.print(mLandscapeRotation);
5846 pw.print(" mSeascapeRotation="); pw.println(mSeascapeRotation);
5847 pw.print(prefix); pw.print("mPortraitRotation="); pw.print(mPortraitRotation);
5848 pw.print(" mUpsideDownRotation="); pw.println(mUpsideDownRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07005849 pw.print(prefix); pw.print("mDemoHdmiRotation="); pw.print(mDemoHdmiRotation);
5850 pw.print(" mDemoHdmiRotationLock="); pw.println(mDemoHdmiRotationLock);
5851 pw.print(prefix); pw.print("mUndockedHdmiRotation="); pw.println(mUndockedHdmiRotation);
Jeff Brown600f0032014-05-22 17:06:00 -07005852
Tim Kilbournd7c0c2e2014-05-29 16:08:10 -07005853 mGlobalKeyManager.dump(prefix, pw);
John Spurlock27735a42013-08-14 17:57:38 -04005854 mStatusBarController.dump(pw, prefix);
5855 mNavigationBarController.dump(pw, prefix);
John Spurlockc6d1c602014-01-17 15:22:06 -05005856 PolicyControl.dump(prefix, pw);
Jeff Brown600f0032014-05-22 17:06:00 -07005857
Jeff Browna20dda42014-05-27 20:57:24 -07005858 if (mWakeGestureListener != null) {
5859 mWakeGestureListener.dump(pw, prefix);
5860 }
Jeff Brown600f0032014-05-22 17:06:00 -07005861 if (mOrientationListener != null) {
5862 mOrientationListener.dump(pw, prefix);
5863 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005864 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005865}