blob: 5a836c8048291c84f4a0e04a4e1b17f8cbe1762a [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;
Michael Wrightdc63f7b2014-08-21 19:05:21 -070073import android.speech.RecognizerIntent;
Santos Cordon9eb45932014-06-27 12:28:43 -070074import android.telecomm.TelecommManager;
Dianne Hackborn81e56d52011-05-26 00:55:58 -070075import android.util.DisplayMetrics;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080076import android.util.EventLog;
77import android.util.Log;
Jeff Browna41ca772010-08-11 14:46:32 -070078import android.util.Slog;
Jeff Brown6651a632011-11-28 12:59:11 -080079import android.util.SparseArray;
Dianne Hackbornf87d1962012-04-04 12:48:24 -070080import android.view.Display;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080081import android.view.Gravity;
82import android.view.HapticFeedbackConstants;
Dianne Hackborne0f085d2011-11-30 18:41:15 -080083import android.view.IApplicationToken;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080084import android.view.IWindowManager;
Jeff Browna41ca772010-08-11 14:46:32 -070085import android.view.InputChannel;
Jeff Brown4d396052010-10-29 21:50:21 -070086import android.view.InputDevice;
Jeff Brown4952dfd2011-11-30 19:23:22 -080087import android.view.InputEvent;
Jeff Brown32cbc38552011-12-01 14:01:49 -080088import android.view.InputEventReceiver;
Jeff Brown6b53e8d2010-11-10 16:03:06 -080089import android.view.KeyCharacterMap;
Craig Mautnerae446592012-12-06 19:05:05 -080090import android.view.KeyCharacterMap.FallbackAction;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080091import android.view.KeyEvent;
92import android.view.MotionEvent;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080093import android.view.Surface;
94import android.view.View;
95import android.view.ViewConfiguration;
96import android.view.Window;
97import android.view.WindowManager;
Craig Mautnerae446592012-12-06 19:05:05 -080098import android.view.WindowManagerGlobal;
Craig Mautner8a0da012014-05-31 15:13:37 -070099import android.view.WindowManagerInternal;
Craig Mautnerae446592012-12-06 19:05:05 -0800100import android.view.WindowManagerPolicy;
Craig Mautnerae446592012-12-06 19:05:05 -0800101import android.view.accessibility.AccessibilityEvent;
Svetoslav8e3feb12014-02-24 13:46:47 -0800102import android.view.accessibility.AccessibilityManager;
Jorim Jaggi76a16232014-08-08 17:00:47 +0200103import android.view.animation.AlphaAnimation;
Craig Mautnerae446592012-12-06 19:05:05 -0800104import android.view.animation.Animation;
Jorim Jaggi76a16232014-08-08 17:00:47 +0200105import android.view.animation.AnimationSet;
Craig Mautnerae446592012-12-06 19:05:05 -0800106import android.view.animation.AnimationUtils;
107
108import com.android.internal.R;
Jorim Jaggi380ecb82014-03-14 17:25:20 +0100109import com.android.internal.policy.IKeyguardService;
110import com.android.internal.policy.IKeyguardServiceConstants;
Craig Mautnerae446592012-12-06 19:05:05 -0800111import com.android.internal.policy.PolicyManager;
Jim Miller5ecd8112013-01-09 18:50:26 -0800112import com.android.internal.policy.impl.keyguard.KeyguardServiceDelegate;
Craig Mautner8a0da012014-05-31 15:13:37 -0700113import com.android.internal.policy.impl.keyguard.KeyguardServiceDelegate.ShowListener;
Craig Mautnerae446592012-12-06 19:05:05 -0800114import com.android.internal.statusbar.IStatusBarService;
Craig Mautnerae446592012-12-06 19:05:05 -0800115import com.android.internal.widget.PointerLocationView;
Craig Mautner8a0da012014-05-31 15:13:37 -0700116import com.android.server.LocalServices;
Craig Mautnerae446592012-12-06 19:05:05 -0800117
118import java.io.File;
119import java.io.FileReader;
120import java.io.IOException;
121import java.io.PrintWriter;
Craig Mautner8a0da012014-05-31 15:13:37 -0700122import java.util.ArrayList;
Craig Mautner2bc789b2014-03-19 19:48:38 -0700123import java.util.HashSet;
RoboErik3c45c292014-07-08 16:47:31 -0700124import java.util.List;
Craig Mautnerae446592012-12-06 19:05:05 -0800125
Dianne Hackbornc652de82013-02-15 16:32:56 -0800126import static android.view.WindowManager.LayoutParams.*;
Jeff Brownac143512012-04-05 18:57:33 -0700127import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_ABSENT;
128import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_OPEN;
129import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_CLOSED;
Dianne Hackborn08743722009-12-21 12:16:51 -0800130
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800131/**
The Android Open Source Project0727d222009-03-11 12:11:58 -0700132 * WindowManagerPolicy implementation for the Android phone UI. This
133 * introduces a new method suffix, Lp, for an internal lock of the
134 * PhoneWindowManager. This is used to protect some internal state, and
John Spurlock04db1762013-05-13 12:46:41 -0400135 * 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 -0700136 * of both of those when held.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800137 */
138public class PhoneWindowManager implements WindowManagerPolicy {
139 static final String TAG = "WindowManager";
140 static final boolean DEBUG = false;
Joe Onorato43a17652011-04-06 19:22:23 -0700141 static final boolean localLOGV = false;
The Android Open Source Project11267662009-03-18 17:39:47 -0700142 static final boolean DEBUG_LAYOUT = false;
Jeff Brown40013652012-05-16 21:22:36 -0700143 static final boolean DEBUG_INPUT = false;
Craig Mautner6fbda632012-07-03 09:26:39 -0700144 static final boolean DEBUG_STARTING_WINDOW = false;
Craig Mautner8a0da012014-05-31 15:13:37 -0700145 static final boolean DEBUG_WAKEUP = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800146 static final boolean SHOW_STARTING_ANIMATIONS = true;
147 static final boolean SHOW_PROCESSES_ON_ALT_MENU = false;
Joe Onoratod208e702010-10-08 16:22:43 -0400148
Daniel Sandler6396c722013-04-16 20:19:09 -0400149 // Whether to allow dock apps with METADATA_DOCK_HOME to temporarily take over the Home key.
150 // No longer recommended for desk docks; still useful in car docks.
151 static final boolean ENABLE_CAR_DOCK_HOME_CAPTURE = true;
152 static final boolean ENABLE_DESK_DOCK_HOME_CAPTURE = false;
153
Jeff Brown6d8fd272014-05-20 21:24:38 -0700154 static final int SHORT_PRESS_POWER_NOTHING = 0;
155 static final int SHORT_PRESS_POWER_GO_TO_SLEEP = 1;
156 static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP = 2;
157 static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME = 3;
158
Joe Onoratod208e702010-10-08 16:22:43 -0400159 static final int LONG_PRESS_POWER_NOTHING = 0;
160 static final int LONG_PRESS_POWER_GLOBAL_ACTIONS = 1;
161 static final int LONG_PRESS_POWER_SHUT_OFF = 2;
Jeff Brown9a538ee2012-08-20 14:56:57 -0700162 static final int LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM = 3;
Michael Jurka3b1fc472011-06-13 10:54:40 -0700163
164 // These need to match the documentation/constant in
165 // core/res/res/values/config.xml
Joe Onorato46b0d682010-11-22 17:37:27 -0800166 static final int LONG_PRESS_HOME_NOTHING = 0;
Michael Wrightc9ebea72013-01-16 19:25:02 -0800167 static final int LONG_PRESS_HOME_RECENT_SYSTEM_UI = 1;
Jeff Browncaca8812013-05-09 13:34:33 -0700168 static final int LONG_PRESS_HOME_ASSIST = 2;
169
170 static final int DOUBLE_TAP_HOME_NOTHING = 0;
171 static final int DOUBLE_TAP_HOME_RECENT_SYSTEM_UI = 1;
Joe Onorato46b0d682010-11-22 17:37:27 -0800172
Dianne Hackborn5cb8d792009-05-21 17:34:15 -0700173 static final int APPLICATION_MEDIA_SUBLAYER = -2;
174 static final int APPLICATION_MEDIA_OVERLAY_SUBLAYER = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800175 static final int APPLICATION_PANEL_SUBLAYER = 1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800176 static final int APPLICATION_SUB_PANEL_SUBLAYER = 2;
Craig Mautner88400d32012-09-30 12:35:45 -0700177
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800178 static public final String SYSTEM_DIALOG_REASON_KEY = "reason";
179 static public final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions";
180 static public final String SYSTEM_DIALOG_REASON_RECENT_APPS = "recentapps";
Joe Onoratof275f0c2009-11-24 16:11:13 -0500181 static public final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey";
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700182 static public final String SYSTEM_DIALOG_REASON_ASSIST = "assist";
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800183
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700184 /**
185 * These are the system UI flags that, when changing, can cause the layout
186 * of the screen to change.
187 */
188 static final int SYSTEM_UI_CHANGING_LAYOUT =
John Spurlocke1f366f2013-08-05 12:22:40 -0400189 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlock7f4820a2013-10-08 12:54:35 -0400190 | View.SYSTEM_UI_FLAG_FULLSCREEN
191 | View.STATUS_BAR_TRANSLUCENT
Adrian Roosea562512014-05-05 13:33:03 +0200192 | View.NAVIGATION_BAR_TRANSLUCENT
193 | View.SYSTEM_UI_TRANSPARENT;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700194
John Spurlock7b414672014-07-18 13:02:39 -0400195 private static final AudioAttributes VIBRATION_ATTRIBUTES = new AudioAttributes.Builder()
196 .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
197 .setUsage(AudioAttributes.USAGE_ASSISTANCE_SONIFICATION)
198 .build();
199
Jim Miller5ecd8112013-01-09 18:50:26 -0800200 /**
201 * Keyguard stuff
202 */
203 private WindowState mKeyguardScrim;
Jorim Jaggi380ecb82014-03-14 17:25:20 +0100204 private boolean mKeyguardHidden;
Jorim Jaggicff0acb2014-03-31 16:35:15 +0200205 private boolean mKeyguardDrawn;
Jim Miller5ecd8112013-01-09 18:50:26 -0800206
Jeff Brown6651a632011-11-28 12:59:11 -0800207 /* Table of Application Launch keys. Maps from key codes to intent categories.
208 *
209 * These are special keys that are used to launch particular kinds of applications,
210 * such as a web browser. HID defines nearly a hundred of them in the Consumer (0x0C)
211 * usage page. We don't support quite that many yet...
212 */
213 static SparseArray<String> sApplicationLaunchKeyCategories;
214 static {
215 sApplicationLaunchKeyCategories = new SparseArray<String>();
216 sApplicationLaunchKeyCategories.append(
217 KeyEvent.KEYCODE_EXPLORER, Intent.CATEGORY_APP_BROWSER);
218 sApplicationLaunchKeyCategories.append(
219 KeyEvent.KEYCODE_ENVELOPE, Intent.CATEGORY_APP_EMAIL);
220 sApplicationLaunchKeyCategories.append(
221 KeyEvent.KEYCODE_CONTACTS, Intent.CATEGORY_APP_CONTACTS);
222 sApplicationLaunchKeyCategories.append(
223 KeyEvent.KEYCODE_CALENDAR, Intent.CATEGORY_APP_CALENDAR);
224 sApplicationLaunchKeyCategories.append(
225 KeyEvent.KEYCODE_MUSIC, Intent.CATEGORY_APP_MUSIC);
226 sApplicationLaunchKeyCategories.append(
227 KeyEvent.KEYCODE_CALCULATOR, Intent.CATEGORY_APP_CALCULATOR);
228 }
229
Dianne Hackborndf89e652011-10-06 22:35:11 -0700230 /**
231 * Lock protecting internal state. Must not call out into window
232 * manager with lock held. (This lock will be acquired in places
233 * where the window manager is calling in with its own lock held.)
234 */
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800235 private final Object mLock = new Object();
Dianne Hackborndf89e652011-10-06 22:35:11 -0700236
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800237 Context mContext;
238 IWindowManager mWindowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700239 WindowManagerFuncs mWindowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -0700240 WindowManagerInternal mWindowManagerInternal;
Jeff Brown96307042012-07-27 15:51:34 -0700241 PowerManager mPowerManager;
Jose Lima9546b202014-07-02 17:21:51 -0700242 DreamManagerInternal mDreamManagerInternal;
Joe Onorato93056472010-09-10 10:30:46 -0400243 IStatusBarService mStatusBarService;
Jeff Browncaca8812013-05-09 13:34:33 -0700244 boolean mPreloadedRecentApps;
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700245 final Object mServiceAquireLock = new Object();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800246 Vibrator mVibrator; // Vibrator for giving feedback of orientation changes
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700247 SearchManager mSearchManager;
Svetoslav8e3feb12014-02-24 13:46:47 -0800248 AccessibilityManager mAccessibilityManager;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800249
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700250 // Vibrator pattern for haptic feedback of a long press.
251 long[] mLongPressVibePattern;
Craig Mautner88400d32012-09-30 12:35:45 -0700252
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700253 // Vibrator pattern for haptic feedback of virtual key press.
254 long[] mVirtualKeyVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700255
Amith Yamasanic33cb712010-02-10 15:21:49 -0800256 // Vibrator pattern for a short vibration.
257 long[] mKeyboardTapVibePattern;
258
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -0700259 // Vibrator pattern for a short vibration when tapping on an hour/minute tick of a Clock.
260 long[] mClockTickVibePattern;
261
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -0700262 // Vibrator pattern for a short vibration when tapping on a day/month/year date of a Calendar.
263 long[] mCalendarDateVibePattern;
264
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700265 // Vibrator pattern for haptic feedback during boot when safe mode is disabled.
266 long[] mSafeModeDisabledVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700267
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700268 // Vibrator pattern for haptic feedback during boot when safe mode is enabled.
269 long[] mSafeModeEnabledVibePattern;
Romain Guy8154cd32010-03-29 14:41:15 -0700270
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800271 /** If true, hitting shift & menu will broadcast Intent.ACTION_BUG_REPORT */
272 boolean mEnableShiftMenuBugReports = false;
Mike Lockwoodd747dc82011-09-13 16:28:22 -0400273
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800274 boolean mSafeMode;
275 WindowState mStatusBar = null;
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700276 int mStatusBarHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400277 WindowState mNavigationBar = null;
Daniel Sandler36412a72011-08-04 09:35:13 -0400278 boolean mHasNavigationBar = false;
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700279 boolean mCanHideNavigationBar = false;
Daniel Sandler4a066c52012-04-20 14:49:13 -0400280 boolean mNavigationBarCanMove = false; // can the navigation bar ever move to the side?
281 boolean mNavigationBarOnBottom = true; // is the navigation bar on the bottom *right now*?
282 int[] mNavigationBarHeightForRotation = new int[4];
283 int[] mNavigationBarWidthForRotation = new int[4];
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400284
Craig Mautnera631d492014-08-05 15:16:01 -0700285 boolean mBootMessageNeedsHiding;
Jim Miller5ecd8112013-01-09 18:50:26 -0800286 KeyguardServiceDelegate mKeyguardDelegate;
Craig Mautner8a0da012014-05-31 15:13:37 -0700287 // The following are only accessed on the mHandler thread.
288 boolean mKeyguardDrawComplete;
289 boolean mWindowManagerDrawComplete;
Craig Mautner13f6ea72014-06-23 14:57:02 -0700290 ScreenOnListener mScreenOnListener;
291 final Runnable mWindowManagerDrawCallback = new Runnable() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700292 @Override
Craig Mautner13f6ea72014-06-23 14:57:02 -0700293 public void run() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700294 if (DEBUG_WAKEUP) Slog.i(TAG, "All windows ready for display!");
295 mHandler.sendEmptyMessage(MSG_WINDOW_MANAGER_DRAWN_COMPLETE);
296 }
297 };
298 final ShowListener mKeyguardDelegateCallback = new ShowListener() {
299 @Override
300 public void onShown(IBinder windowToken) {
301 if (DEBUG_WAKEUP) Slog.d(TAG, "mKeyguardDelegate.ShowListener.onShown.");
302 mHandler.sendEmptyMessage(MSG_KEYGUARD_DRAWN_COMPLETE);
303 }
304 };
305
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800306 GlobalActions mGlobalActions;
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700307 volatile boolean mPowerKeyHandled; // accessed from input reader and handler thread
308 boolean mPendingPowerKeyUpCanceled;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800309 Handler mHandler;
satok1bc0a492012-04-25 22:47:12 +0900310 WindowState mLastInputMethodWindow = null;
311 WindowState mLastInputMethodTargetWindow = null;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800312
Winson Chungd42a6cf2014-06-03 16:24:04 -0700313 boolean mRecentsVisible;
Winson Chung1e8d71b2014-05-16 17:05:22 -0700314 int mRecentAppsHeldModifiers;
Jeff Browncf39bdf2012-05-18 14:41:19 -0700315 boolean mLanguageSwitchKeyPressed;
Jeff Brown68b909d2011-12-07 16:36:01 -0800316
Jeff Brown2e7760e2012-04-11 15:14:55 -0700317 int mLidState = LID_ABSENT;
Jeff Browndaa37532012-05-01 15:54:03 -0700318 boolean mHaveBuiltInKeyboard;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800319
Dianne Hackbornc777e072010-02-12 13:07:59 -0800320 boolean mSystemReady;
Dianne Hackbornba24e4d2011-09-01 11:17:06 -0700321 boolean mSystemBooted;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800322 boolean mHdmiPlugged;
Jeff Brown4f5fa282014-06-12 19:19:15 -0700323 IUiModeManager mUiModeManager;
Daniel Sandler6396c722013-04-16 20:19:09 -0400324 int mUiMode;
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700325 int mDockMode = Intent.EXTRA_DOCK_STATE_UNDOCKED;
Mike Lockwood1753f7f2009-08-24 14:49:07 -0700326 int mLidOpenRotation;
Mike Lockwood2d1efbd2009-09-16 12:15:53 -0400327 int mCarDockRotation;
328 int mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -0700329 int mUndockedHdmiRotation;
330 int mDemoHdmiRotation;
331 boolean mDemoHdmiRotationLock;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400332
Jeff Browna20dda42014-05-27 20:57:24 -0700333 boolean mWakeGestureEnabledSetting;
334 MyWakeGestureListener mWakeGestureListener;
335
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700336 // Default display does not rotate, apps that require non-default orientation will have to
337 // have the orientation emulated.
338 private boolean mForceDefaultOrientation = false;
339
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400340 int mUserRotationMode = WindowManagerPolicy.USER_ROTATION_FREE;
341 int mUserRotation = Surface.ROTATION_0;
Jeff Brown207673cd2012-06-05 17:47:11 -0700342 boolean mAccelerometerDefault;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400343
Jeff Brownbcdfc622014-03-06 19:13:04 -0800344 boolean mSupportAutoRotation;
Jeff Brownd3187e32011-09-21 19:26:44 -0700345 int mAllowAllRotations = -1;
Mike Lockwoode9867d22009-09-20 01:59:02 -0400346 boolean mCarDockEnablesAccelerometer;
347 boolean mDeskDockEnablesAccelerometer;
Dianne Hackborn2862fff2009-09-15 22:56:29 -0700348 int mLidKeyboardAccessibility;
349 int mLidNavigationAccessibility;
Jeff Brownc458ce92012-04-30 14:58:40 -0700350 boolean mLidControlsSleep;
Jeff Brown6d8fd272014-05-20 21:24:38 -0700351 int mShortPressOnPowerBehavior = -1;
Joe Onoratod208e702010-10-08 16:22:43 -0400352 int mLongPressOnPowerBehavior = -1;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -0700353 boolean mScreenOnEarly = false;
354 boolean mScreenOnFully = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800355 boolean mOrientationSensorEnabled = false;
356 int mCurrentAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800357 boolean mHasSoftInput = false;
Daniel Sandlerdd73ee42013-10-11 22:19:59 -0400358 boolean mTranslucentDecorEnabled = true;
Craig Mautner967212c2013-04-13 21:10:58 -0700359
Jeff Brown70825162012-03-28 17:27:48 -0700360 int mPointerLocationMode = 0; // guarded by mLock
Joe Onorato664644d2011-01-23 17:53:23 -0800361
362 // The last window we were told about in focusChanged.
363 WindowState mFocusedWindow;
Dianne Hackborne0f085d2011-11-30 18:41:15 -0800364 IApplicationToken mFocusedApp;
Joe Onorato664644d2011-01-23 17:53:23 -0800365
Jeff Brown70825162012-03-28 17:27:48 -0700366 PointerLocationView mPointerLocationView;
Jeff Brown32cbc38552011-12-01 14:01:49 -0800367
Dianne Hackbornc652de82013-02-15 16:32:56 -0800368 // The current size of the screen; really; extends into the overscan area of
369 // the screen and doesn't account for any system elements like the status bar.
370 int mOverscanScreenLeft, mOverscanScreenTop;
371 int mOverscanScreenWidth, mOverscanScreenHeight;
372 // The current visible size of the screen; really; (ir)regardless of whether the status
373 // bar can be hidden but not extending into the overscan area.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800374 int mUnrestrictedScreenLeft, mUnrestrictedScreenTop;
375 int mUnrestrictedScreenWidth, mUnrestrictedScreenHeight;
Dianne Hackborn313440842013-02-19 19:22:59 -0800376 // Like mOverscanScreen*, but allowed to move into the overscan region where appropriate.
377 int mRestrictedOverscanScreenLeft, mRestrictedOverscanScreenTop;
378 int mRestrictedOverscanScreenWidth, mRestrictedOverscanScreenHeight;
Dianne Hackborn82de1ae2010-10-28 11:28:39 -0700379 // The current size of the screen; these may be different than (0,0)-(dw,dh)
380 // if the status bar can't be hidden; in that case it effectively carves out
381 // that area of the display from all other windows.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800382 int mRestrictedScreenLeft, mRestrictedScreenTop;
383 int mRestrictedScreenWidth, mRestrictedScreenHeight;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700384 // During layout, the current screen borders accounting for any currently
385 // visible system UI elements.
386 int mSystemLeft, mSystemTop, mSystemRight, mSystemBottom;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700387 // For applications requesting stable content insets, these are them.
388 int mStableLeft, mStableTop, mStableRight, mStableBottom;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -0700389 // For applications requesting stable content insets but have also set the
390 // fullscreen window flag, these are the stable dimensions without the status bar.
391 int mStableFullscreenLeft, mStableFullscreenTop;
392 int mStableFullscreenRight, mStableFullscreenBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800393 // During layout, the current screen borders with all outer decoration
394 // (status bar, input method dock) accounted for.
395 int mCurLeft, mCurTop, mCurRight, mCurBottom;
396 // During layout, the frame in which content should be displayed
397 // to the user, accounting for all screen decoration except for any
398 // space they deem as available for other content. This is usually
399 // the same as mCur*, but may be larger if the screen decor has supplied
400 // content insets.
401 int mContentLeft, mContentTop, mContentRight, mContentBottom;
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700402 // During layout, the frame in which voice content should be displayed
403 // to the user, accounting for all screen decoration except for any
404 // space they deem as available for other content.
405 int mVoiceContentLeft, mVoiceContentTop, mVoiceContentRight, mVoiceContentBottom;
Dianne Hackborn8e11ef02010-11-18 19:47:42 -0800406 // During layout, the current screen borders along which input method
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800407 // windows are placed.
408 int mDockLeft, mDockTop, mDockRight, mDockBottom;
409 // During layout, the layer at which the doc window is placed.
410 int mDockLayer;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700411 // During layout, this is the layer of the status bar.
412 int mStatusBarLayer;
Dianne Hackborne26ab702011-10-16 13:21:33 -0700413 int mLastSystemUiFlags;
414 // Bits that we are in the process of clearing, so we want to prevent
415 // them from being set by applications until everything has been updated
416 // to have them clear.
417 int mResettingSystemUiFlags = 0;
418 // Bits that we are currently always keeping cleared.
419 int mForceClearedSystemUiFlags = 0;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -0800420 // What we last reported to system UI about whether the compatibility
421 // menu needs to be displayed.
422 boolean mLastFocusNeedsMenu = false;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700423
424 FakeWindow mHideNavFakeWindow = null;
425
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800426 static final Rect mTmpParentFrame = new Rect();
427 static final Rect mTmpDisplayFrame = new Rect();
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800428 static final Rect mTmpOverscanFrame = new Rect();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800429 static final Rect mTmpContentFrame = new Rect();
430 static final Rect mTmpVisibleFrame = new Rect();
John Spurlock46646232013-09-30 22:32:42 -0400431 static final Rect mTmpDecorFrame = new Rect();
Adrian Roosfa104232014-06-20 16:10:14 -0700432 static final Rect mTmpStableFrame = new Rect();
Dianne Hackborn1f903c32011-09-13 19:18:06 -0700433 static final Rect mTmpNavigationFrame = new Rect();
Craig Mautner967212c2013-04-13 21:10:58 -0700434
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800435 WindowState mTopFullscreenOpaqueWindowState;
Craig Mautner2bc789b2014-03-19 19:48:38 -0700436 HashSet<IApplicationToken> mAppsToBeHidden = new HashSet<IApplicationToken>();
Joe Onorato93056472010-09-10 10:30:46 -0400437 boolean mTopIsFullscreen;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800438 boolean mForceStatusBar;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -0700439 boolean mForceStatusBarFromKeyguard;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700440 boolean mHideLockScreen;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -0800441 boolean mForcingShowNavBar;
442 int mForcingShowNavBarLayer;
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700443
444 // States of keyguard dismiss.
445 private static final int DISMISS_KEYGUARD_NONE = 0; // Keyguard not being dismissed.
446 private static final int DISMISS_KEYGUARD_START = 1; // Keyguard needs to be dismissed.
447 private static final int DISMISS_KEYGUARD_CONTINUE = 2; // Keyguard has been dismissed.
448 int mDismissKeyguard = DISMISS_KEYGUARD_NONE;
449
450 /** The window that is currently dismissing the keyguard. Dismissing the keyguard must only
451 * be done once per window. */
452 private WindowState mWinDismissingKeyguard;
453
Craig Mautnerc9457fa2014-06-06 14:27:48 -0700454 /** The window that is currently showing "over" the keyguard. If there is an app window
455 * belonging to another app on top of this the keyguard shows. If there is a fullscreen
456 * app window under this, still dismiss the keyguard but don't show the app underneath. Show
457 * the wallpaper. */
458 private WindowState mWinShowWhenLocked;
459
Dianne Hackborn7ad44382012-10-18 17:46:00 -0700460 boolean mShowingLockscreen;
461 boolean mShowingDream;
462 boolean mDreamingLockscreen;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800463 boolean mHomePressed;
Jeff Browncaca8812013-05-09 13:34:33 -0700464 boolean mHomeConsumed;
465 boolean mHomeDoubleTapPending;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800466 Intent mHomeIntent;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700467 Intent mCarDockIntent;
468 Intent mDeskDockIntent;
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700469 boolean mSearchKeyShortcutPending;
470 boolean mConsumeSearchKeyUp;
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700471 boolean mAssistKeyLongPressed;
Michael Wright6a62e552014-06-03 19:19:48 -0700472 boolean mPendingMetaAction;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800473
Mike Lockwood28569302010-01-28 11:54:40 -0500474 // support for activating the lock screen while the screen is on
475 boolean mAllowLockscreenWhenOn;
476 int mLockScreenTimeout;
477 boolean mLockScreenTimerActive;
478
David Brownbaf8d092010-03-08 21:52:59 -0800479 // Behavior of ENDCALL Button. (See Settings.System.END_BUTTON_BEHAVIOR.)
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800480 int mEndcallBehavior;
David Brownbaf8d092010-03-08 21:52:59 -0800481
482 // Behavior of POWER button while in-call and screen on.
483 // (See Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR.)
484 int mIncallPowerBehavior;
485
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700486 Display mDisplay;
487
Dianne Hackborn9d132642011-04-21 17:26:39 -0700488 int mLandscapeRotation = 0; // default landscape rotation
489 int mSeascapeRotation = 0; // "other" landscape rotation, 180 degrees from mLandscapeRotation
490 int mPortraitRotation = 0; // default portrait rotation
491 int mUpsideDownRotation = 0; // "other" portrait rotation
Mitsuru Oshima831d0d92009-06-16 18:27:18 -0700492
Dianne Hackbornc652de82013-02-15 16:32:56 -0800493 int mOverscanLeft = 0;
494 int mOverscanTop = 0;
495 int mOverscanRight = 0;
496 int mOverscanBottom = 0;
497
Joe Onorato46b0d682010-11-22 17:37:27 -0800498 // What we do when the user long presses on home
Jeff Browncaca8812013-05-09 13:34:33 -0700499 private int mLongPressOnHomeBehavior;
500
501 // What we do when the user double-taps on home
502 private int mDoubleTapOnHomeBehavior;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800503
Winson Chung9112ec32011-06-27 13:15:32 -0700504 // Screenshot trigger states
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700505 // Time to volume and power must be pressed within this interval of each other.
506 private static final long SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS = 150;
Winson Chung1cea2f32012-10-08 20:42:01 -0700507 // Increase the chord delay when taking a screenshot from the keyguard
508 private static final float KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER = 2.5f;
Christopher Tatee90585f2012-03-05 18:56:25 -0800509 private boolean mScreenshotChordEnabled;
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700510 private boolean mVolumeDownKeyTriggered;
511 private long mVolumeDownKeyTime;
512 private boolean mVolumeDownKeyConsumedByScreenshotChord;
513 private boolean mVolumeUpKeyTriggered;
514 private boolean mPowerKeyTriggered;
515 private long mPowerKeyTime;
Winson Chung9112ec32011-06-27 13:15:32 -0700516
Michael Wrightb854e242013-02-05 17:54:02 -0800517 /* The number of steps between min and max brightness */
518 private static final int BRIGHTNESS_STEPS = 10;
519
Christopher Tate5e08af02012-09-21 17:17:22 -0700520 SettingsObserver mSettingsObserver;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800521 ShortcutManager mShortcutManager;
522 PowerManager.WakeLock mBroadcastWakeLock;
Jeff Brown40013652012-05-16 21:22:36 -0700523 boolean mHavePendingMediaKeyRepeatWithWakeLock;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800524
Craig Mautnerd625ab22013-09-06 13:40:31 -0700525 private int mCurrentUserId;
526
Justin Kohd378ad72013-04-01 12:18:26 -0700527 // Maps global key codes to the components that will handle them.
528 private GlobalKeyManager mGlobalKeyManager;
529
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700530 // Fallback actions by key code.
531 private final SparseArray<KeyCharacterMap.FallbackAction> mFallbackActions =
532 new SparseArray<KeyCharacterMap.FallbackAction>();
Jeff Brown49ed71d2010-12-06 17:13:33 -0800533
Jorim Jaggi76a16232014-08-08 17:00:47 +0200534 private final LogDecelerateInterpolator mLogDecelerateInterpolator
535 = new LogDecelerateInterpolator(100, 0);
536
Jeff Brown70825162012-03-28 17:27:48 -0700537 private static final int MSG_ENABLE_POINTER_LOCATION = 1;
538 private static final int MSG_DISABLE_POINTER_LOCATION = 2;
Jeff Brown40013652012-05-16 21:22:36 -0700539 private static final int MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK = 3;
540 private static final int MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK = 4;
Craig Mautner8a0da012014-05-31 15:13:37 -0700541 private static final int MSG_KEYGUARD_DRAWN_COMPLETE = 5;
542 private static final int MSG_KEYGUARD_DRAWN_TIMEOUT = 6;
543 private static final int MSG_WINDOW_MANAGER_DRAWN_COMPLETE = 7;
544 private static final int MSG_WAKING_UP = 8;
Craig Mautner84984fa2014-06-19 11:19:20 -0700545 private static final int MSG_DISPATCH_SHOW_RECENTS = 9;
Alan Viverettee34560b22014-07-10 14:50:06 -0700546 private static final int MSG_DISPATCH_SHOW_GLOBAL_ACTIONS = 10;
Craig Mautnera631d492014-08-05 15:16:01 -0700547 private static final int MSG_HIDE_BOOT_MESSAGE = 11;
Jeff Brown70825162012-03-28 17:27:48 -0700548
549 private class PolicyHandler extends Handler {
550 @Override
551 public void handleMessage(Message msg) {
552 switch (msg.what) {
553 case MSG_ENABLE_POINTER_LOCATION:
554 enablePointerLocation();
555 break;
556 case MSG_DISABLE_POINTER_LOCATION:
557 disablePointerLocation();
558 break;
Jeff Brown40013652012-05-16 21:22:36 -0700559 case MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK:
560 dispatchMediaKeyWithWakeLock((KeyEvent)msg.obj);
561 break;
562 case MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK:
563 dispatchMediaKeyRepeatWithWakeLock((KeyEvent)msg.obj);
564 break;
Craig Mautner84984fa2014-06-19 11:19:20 -0700565 case MSG_DISPATCH_SHOW_RECENTS:
566 showRecentApps(false);
567 break;
Alan Viverettee34560b22014-07-10 14:50:06 -0700568 case MSG_DISPATCH_SHOW_GLOBAL_ACTIONS:
569 showGlobalActionsInternal();
570 break;
Craig Mautner8a0da012014-05-31 15:13:37 -0700571 case MSG_KEYGUARD_DRAWN_COMPLETE:
572 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mKeyguardDrawComplete");
573 mKeyguardDrawComplete = true;
574 finishScreenTurningOn();
575 break;
576 case MSG_KEYGUARD_DRAWN_TIMEOUT:
577 Slog.w(TAG, "Keyguard drawn timeout. Setting mKeyguardDrawComplete");
578 mKeyguardDrawComplete = true;
579 finishScreenTurningOn();
580 break;
581 case MSG_WINDOW_MANAGER_DRAWN_COMPLETE:
582 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mWindowManagerDrawComplete");
583 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
584 mWindowManagerDrawComplete = true;
585 finishScreenTurningOn();
586 break;
587 case MSG_WAKING_UP:
588 handleWakingUp((ScreenOnListener) msg.obj);
589 break;
Craig Mautnera631d492014-08-05 15:16:01 -0700590 case MSG_HIDE_BOOT_MESSAGE:
591 handleHideBootMessage();
592 break;
Jeff Brown70825162012-03-28 17:27:48 -0700593 }
594 }
595 }
596
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800597 private UEventObserver mHDMIObserver = new UEventObserver() {
598 @Override
599 public void onUEvent(UEventObserver.UEvent event) {
600 setHdmiPlugged("1".equals(event.get("SWITCH_STATE")));
601 }
602 };
603
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800604 class SettingsObserver extends ContentObserver {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800605 SettingsObserver(Handler handler) {
606 super(handler);
607 }
David Brownbaf8d092010-03-08 21:52:59 -0800608
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800609 void observe() {
Christopher Tate5e08af02012-09-21 17:17:22 -0700610 // Observe all users' changes
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800611 ContentResolver resolver = mContext.getContentResolver();
612 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700613 Settings.System.END_BUTTON_BEHAVIOR), false, this,
614 UserHandle.USER_ALL);
David Brownbaf8d092010-03-08 21:52:59 -0800615 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700616 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR), false, this,
617 UserHandle.USER_ALL);
Jeff Browna20dda42014-05-27 20:57:24 -0700618 resolver.registerContentObserver(Settings.Secure.getUriFor(
619 Settings.Secure.WAKE_GESTURE_ENABLED), false, this,
620 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800621 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700622 Settings.System.ACCELEROMETER_ROTATION), false, this,
623 UserHandle.USER_ALL);
Mike Lockwood28569302010-01-28 11:54:40 -0500624 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700625 Settings.System.USER_ROTATION), false, this,
626 UserHandle.USER_ALL);
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400627 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700628 Settings.System.SCREEN_OFF_TIMEOUT), false, this,
629 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800630 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700631 Settings.System.POINTER_LOCATION), false, this,
632 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800633 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700634 Settings.Secure.DEFAULT_INPUT_METHOD), false, this,
635 UserHandle.USER_ALL);
John Spurlockd9b70bd2014-02-06 17:02:44 -0500636 resolver.registerContentObserver(Settings.Secure.getUriFor(
John Spurlockf1a36642013-10-12 17:50:42 -0400637 Settings.Secure.IMMERSIVE_MODE_CONFIRMATIONS), false, this,
Christopher Tate5e08af02012-09-21 17:17:22 -0700638 UserHandle.USER_ALL);
John Spurlockc6d1c602014-01-17 15:22:06 -0500639 resolver.registerContentObserver(Settings.Global.getUriFor(
640 Settings.Global.POLICY_CONTROL), false, this,
641 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800642 updateSettings();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800643 }
644
645 @Override public void onChange(boolean selfChange) {
Dianne Hackbornc777e072010-02-12 13:07:59 -0800646 updateSettings();
Jeff Brown01a98dd2011-09-20 15:08:29 -0700647 updateRotation(false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800648 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800649 }
Craig Mautner967212c2013-04-13 21:10:58 -0700650
Jeff Browna20dda42014-05-27 20:57:24 -0700651 class MyWakeGestureListener extends WakeGestureListener {
652 MyWakeGestureListener(Context context, Handler handler) {
653 super(context, handler);
654 }
655
656 @Override
657 public void onWakeUp() {
658 synchronized (mLock) {
659 if (shouldEnableWakeGestureLp()) {
Jeff Browne07b94b2014-06-18 15:56:27 -0700660 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
Jeff Browna20dda42014-05-27 20:57:24 -0700661 mPowerManager.wakeUp(SystemClock.uptimeMillis());
662 }
663 }
664 }
665 }
666
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800667 class MyOrientationListener extends WindowOrientationListener {
Craig Mautnereee29c42013-01-17 14:44:34 -0800668 MyOrientationListener(Context context, Handler handler) {
669 super(context, handler);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800670 }
Craig Mautner967212c2013-04-13 21:10:58 -0700671
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800672 @Override
Jeff Brownc0347aa2011-09-23 17:26:09 -0700673 public void onProposedRotationChanged(int rotation) {
Craig Mautnereda67292013-04-28 13:50:14 -0700674 if (localLOGV) Slog.v(TAG, "onProposedRotationChanged, rotation=" + rotation);
Jeff Brown01a98dd2011-09-20 15:08:29 -0700675 updateRotation(false);
676 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800677 }
678 MyOrientationListener mOrientationListener;
679
John Spurlock27735a42013-08-14 17:57:38 -0400680 private final BarController mStatusBarController = new BarController("StatusBar",
John Spurlock5b9145b2013-08-20 15:13:47 -0400681 View.STATUS_BAR_TRANSIENT,
682 View.STATUS_BAR_UNHIDE,
John Spurlockbd957402013-10-03 11:38:39 -0400683 View.STATUS_BAR_TRANSLUCENT,
684 StatusBarManager.WINDOW_STATUS_BAR,
685 WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
John Spurlock5b9145b2013-08-20 15:13:47 -0400686
John Spurlock27735a42013-08-14 17:57:38 -0400687 private final BarController mNavigationBarController = new BarController("NavigationBar",
John Spurlock5b9145b2013-08-20 15:13:47 -0400688 View.NAVIGATION_BAR_TRANSIENT,
689 View.NAVIGATION_BAR_UNHIDE,
John Spurlockbd957402013-10-03 11:38:39 -0400690 View.NAVIGATION_BAR_TRANSLUCENT,
691 StatusBarManager.WINDOW_NAVIGATION_BAR,
692 WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
John Spurlock5b9145b2013-08-20 15:13:47 -0400693
John Spurlockf1a36642013-10-12 17:50:42 -0400694 private ImmersiveModeConfirmation mImmersiveModeConfirmation;
John Spurlock32beb2c2013-03-11 10:16:47 -0400695
Craig Mautner037aa8d2013-06-07 10:35:44 -0700696 private SystemGesturesPointerEventListener mSystemGestures;
John Spurlock32beb2c2013-03-11 10:16:47 -0400697
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700698 IStatusBarService getStatusBarService() {
699 synchronized (mServiceAquireLock) {
700 if (mStatusBarService == null) {
701 mStatusBarService = IStatusBarService.Stub.asInterface(
702 ServiceManager.getService("statusbar"));
703 }
704 return mStatusBarService;
705 }
706 }
707
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700708 /*
709 * We always let the sensor be switched on by default except when
710 * the user has explicitly disabled sensor based rotation or when the
711 * screen is switched off.
712 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700713 boolean needSensorRunningLp() {
Jeff Brownbcdfc622014-03-06 19:13:04 -0800714 if (mSupportAutoRotation) {
715 if (mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
716 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
717 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT
718 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) {
719 // If the application has explicitly requested to follow the
720 // orientation, then we need to turn the sensor on.
721 return true;
722 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800723 }
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700724 if ((mCarDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_CAR) ||
Jeff Brown1a693182011-11-08 14:44:16 -0800725 (mDeskDockEnablesAccelerometer && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
726 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
727 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK))) {
Mike Lockwoode9867d22009-09-20 01:59:02 -0400728 // enable accelerometer if we are docked in a dock that enables accelerometer
729 // orientation management,
730 return true;
731 }
Jeff Brown207673cd2012-06-05 17:47:11 -0700732 if (mUserRotationMode == USER_ROTATION_LOCKED) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800733 // If the setting for using the sensor by default is enabled, then
734 // we will always leave it on. Note that the user could go to
735 // a window that forces an orientation that does not use the
736 // sensor and in theory we could turn it off... however, when next
737 // turning it on we won't have a good value for the current
738 // orientation for a little bit, which can cause orientation
739 // changes to lag, so we'd like to keep it always on. (It will
740 // still be turned off when the screen is off.)
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700741 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800742 }
Jeff Brownbcdfc622014-03-06 19:13:04 -0800743 return mSupportAutoRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800744 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700745
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800746 /*
747 * Various use cases for invoking this function
748 * screen turning off, should always disable listeners if already enabled
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700749 * screen turned on and current app has sensor based orientation, enable listeners
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800750 * if not already enabled
751 * screen turned on and current app does not have sensor orientation, disable listeners if
752 * already enabled
753 * screen turning on and current app has sensor based orientation, enable listeners if needed
754 * screen turning on and current app has nosensor based orientation, do nothing
755 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700756 void updateOrientationListenerLp() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800757 if (!mOrientationListener.canDetectOrientation()) {
758 // If sensor is turned off or nonexistent for some reason
759 return;
760 }
761 //Could have been invoked due to screen turning on or off or
762 //change of the currently visible window's orientation
Craig Mautnereda67292013-04-28 13:50:14 -0700763 if (localLOGV) Slog.v(TAG, "Screen status="+mScreenOnEarly+
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800764 ", current orientation="+mCurrentAppOrientation+
765 ", SensorEnabled="+mOrientationSensorEnabled);
766 boolean disable = true;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -0700767 if (mScreenOnEarly) {
The Android Open Source Project0727d222009-03-11 12:11:58 -0700768 if (needSensorRunningLp()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800769 disable = false;
770 //enable listener if not already enabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700771 if (!mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800772 mOrientationListener.enable();
Craig Mautnereda67292013-04-28 13:50:14 -0700773 if(localLOGV) Slog.v(TAG, "Enabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800774 mOrientationSensorEnabled = true;
775 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700776 }
777 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800778 //check if sensors need to be disabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700779 if (disable && mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800780 mOrientationListener.disable();
Craig Mautnereda67292013-04-28 13:50:14 -0700781 if(localLOGV) Slog.v(TAG, "Disabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800782 mOrientationSensorEnabled = false;
783 }
784 }
785
Jeff Brown4d396052010-10-29 21:50:21 -0700786 private void interceptPowerKeyDown(boolean handled) {
787 mPowerKeyHandled = handled;
788 if (!handled) {
Justin Kohfeabd2c2014-05-02 10:02:44 -0700789 mHandler.postDelayed(mPowerLongPress,
790 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Jeff Brown4d396052010-10-29 21:50:21 -0700791 }
792 }
793
794 private boolean interceptPowerKeyUp(boolean canceled) {
795 if (!mPowerKeyHandled) {
796 mHandler.removeCallbacks(mPowerLongPress);
797 return !canceled;
Jeff Brown4d396052010-10-29 21:50:21 -0700798 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700799 return false;
800 }
801
802 private void cancelPendingPowerKeyAction() {
803 if (!mPowerKeyHandled) {
804 mHandler.removeCallbacks(mPowerLongPress);
805 }
Jeff Brownff204712011-10-25 21:27:54 -0700806 if (mPowerKeyTriggered) {
807 mPendingPowerKeyUpCanceled = true;
808 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700809 }
810
811 private void interceptScreenshotChord() {
Christopher Tatee90585f2012-03-05 18:56:25 -0800812 if (mScreenshotChordEnabled
813 && mVolumeDownKeyTriggered && mPowerKeyTriggered && !mVolumeUpKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700814 final long now = SystemClock.uptimeMillis();
815 if (now <= mVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS
816 && now <= mPowerKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) {
817 mVolumeDownKeyConsumedByScreenshotChord = true;
818 cancelPendingPowerKeyAction();
819
Jeff Sharkey2991fa32012-12-05 18:06:43 -0800820 mHandler.postDelayed(mScreenshotRunnable, getScreenshotChordLongPressDelay());
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700821 }
822 }
823 }
824
Winson Chung1cea2f32012-10-08 20:42:01 -0700825 private long getScreenshotChordLongPressDelay() {
Jim Miller5ecd8112013-01-09 18:50:26 -0800826 if (mKeyguardDelegate.isShowing()) {
Winson Chung1cea2f32012-10-08 20:42:01 -0700827 // Double the time it takes to take a screenshot from the keyguard
828 return (long) (KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER *
Justin Kohfeabd2c2014-05-02 10:02:44 -0700829 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Winson Chung1cea2f32012-10-08 20:42:01 -0700830 }
Justin Kohfeabd2c2014-05-02 10:02:44 -0700831 return ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout();
Winson Chung1cea2f32012-10-08 20:42:01 -0700832 }
833
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700834 private void cancelPendingScreenshotChordAction() {
Jeff Sharkey2991fa32012-12-05 18:06:43 -0800835 mHandler.removeCallbacks(mScreenshotRunnable);
Jeff Brown4d396052010-10-29 21:50:21 -0700836 }
837
Jeff Brown6d8fd272014-05-20 21:24:38 -0700838 private void powerShortPress(long eventTime) {
839 if (mShortPressOnPowerBehavior < 0) {
840 mShortPressOnPowerBehavior = mContext.getResources().getInteger(
841 com.android.internal.R.integer.config_shortPressOnPowerBehavior);
842 }
843
844 switch (mShortPressOnPowerBehavior) {
845 case SHORT_PRESS_POWER_NOTHING:
846 break;
847 case SHORT_PRESS_POWER_GO_TO_SLEEP:
848 mPowerManager.goToSleep(eventTime,
Jeff Brownc12035c2014-08-13 18:52:25 -0700849 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
Jeff Brown6d8fd272014-05-20 21:24:38 -0700850 break;
851 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP:
852 mPowerManager.goToSleep(eventTime,
Jeff Brownc12035c2014-08-13 18:52:25 -0700853 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
Jeff Brown6d8fd272014-05-20 21:24:38 -0700854 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
855 break;
856 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME:
857 mPowerManager.goToSleep(eventTime,
Jeff Brownc12035c2014-08-13 18:52:25 -0700858 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
Jeff Brown6d8fd272014-05-20 21:24:38 -0700859 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
860 launchHomeFromHotKey();
861 break;
862 }
863 }
864
Jeff Brown4d396052010-10-29 21:50:21 -0700865 private final Runnable mPowerLongPress = new Runnable() {
Craig Mautnerf1b67412012-09-19 13:18:29 -0700866 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800867 public void run() {
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700868 // The context isn't read
869 if (mLongPressOnPowerBehavior < 0) {
Jeff Brown850c5b72012-10-01 15:17:22 -0700870 mLongPressOnPowerBehavior = mContext.getResources().getInteger(
871 com.android.internal.R.integer.config_longPressOnPowerBehavior);
Joe Onoratod208e702010-10-08 16:22:43 -0400872 }
Jeff Brown850c5b72012-10-01 15:17:22 -0700873 int resolvedBehavior = mLongPressOnPowerBehavior;
874 if (FactoryTest.isLongPressOnPowerOffEnabled()) {
875 resolvedBehavior = LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM;
876 }
877
878 switch (resolvedBehavior) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700879 case LONG_PRESS_POWER_NOTHING:
880 break;
881 case LONG_PRESS_POWER_GLOBAL_ACTIONS:
882 mPowerKeyHandled = true;
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -0700883 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
884 performAuditoryFeedbackForAccessibilityIfNeed();
885 }
Alan Viverettee34560b22014-07-10 14:50:06 -0700886 showGlobalActionsInternal();
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700887 break;
888 case LONG_PRESS_POWER_SHUT_OFF:
Jeff Brown9a538ee2012-08-20 14:56:57 -0700889 case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM:
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700890 mPowerKeyHandled = true;
891 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
892 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
Jeff Brown850c5b72012-10-01 15:17:22 -0700893 mWindowManagerFuncs.shutdown(resolvedBehavior == LONG_PRESS_POWER_SHUT_OFF);
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700894 break;
895 }
896 }
897 };
898
Jeff Sharkey2991fa32012-12-05 18:06:43 -0800899 private final Runnable mScreenshotRunnable = new Runnable() {
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800900 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700901 public void run() {
902 takeScreenshot();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800903 }
904 };
905
Alan Viverettee34560b22014-07-10 14:50:06 -0700906 @Override
907 public void showGlobalActions() {
908 mHandler.removeMessages(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
909 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
910 }
911
912 void showGlobalActionsInternal() {
913 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800914 if (mGlobalActions == null) {
Jeff Brown7304c342012-05-11 18:42:42 -0700915 mGlobalActions = new GlobalActions(mContext, mWindowManagerFuncs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800916 }
Mike Lockwood3a74bd32011-08-12 13:55:22 -0700917 final boolean keyguardShowing = keyguardIsShowingTq();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800918 mGlobalActions.showDialog(keyguardShowing, isDeviceProvisioned());
919 if (keyguardShowing) {
920 // since it took two seconds of long press to bring this up,
921 // poke the wake lock so they have some time to see the dialog.
Jim Miller25190572013-02-28 17:36:24 -0800922 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800923 }
924 }
925
926 boolean isDeviceProvisioned() {
Jeff Brownbf6f6f92012-09-25 15:03:20 -0700927 return Settings.Global.getInt(
928 mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800929 }
930
Maurice Lam99c6e072014-04-28 18:24:28 -0700931 boolean isUserSetupComplete() {
932 return Settings.Secure.getIntForUser(mContext.getContentResolver(),
933 Settings.Secure.USER_SETUP_COMPLETE, 0, UserHandle.USER_CURRENT) != 0;
934 }
935
Patrick Dubroyece94522011-02-23 18:35:01 -0800936 private void handleLongPressOnHome() {
Joe Onorato46b0d682010-11-22 17:37:27 -0800937 if (mLongPressOnHomeBehavior != LONG_PRESS_HOME_NOTHING) {
Jeff Browncaca8812013-05-09 13:34:33 -0700938 mHomeConsumed = true;
Joe Onorato46b0d682010-11-22 17:37:27 -0800939 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
Patrick Dubroyece94522011-02-23 18:35:01 -0800940
Jeff Browncaca8812013-05-09 13:34:33 -0700941 if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI) {
942 toggleRecentApps();
943 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_ASSIST) {
944 launchAssistAction();
Jim Millere6ad1a82010-08-20 19:25:39 -0700945 }
946 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800947 }
Patrick Dubroyece94522011-02-23 18:35:01 -0800948
Jeff Browncaca8812013-05-09 13:34:33 -0700949 private void handleDoubleTapOnHome() {
950 if (mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
951 mHomeConsumed = true;
952 toggleRecentApps();
953 }
954 }
955
956 private final Runnable mHomeDoubleTapTimeoutRunnable = new Runnable() {
957 @Override
958 public void run() {
959 if (mHomeDoubleTapPending) {
960 mHomeDoubleTapPending = false;
961 launchHomeFromHotKey();
962 }
963 }
964 };
965
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800966 /** {@inheritDoc} */
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800967 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800968 public void init(Context context, IWindowManager windowManager,
Jeff Brown96307042012-07-27 15:51:34 -0700969 WindowManagerFuncs windowManagerFuncs) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800970 mContext = context;
971 mWindowManager = windowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700972 mWindowManagerFuncs = windowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -0700973 mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class);
Jose Lima9546b202014-07-02 17:21:51 -0700974 mDreamManagerInternal = LocalServices.getService(DreamManagerInternal.class);
Craig Mautner8a0da012014-05-31 15:13:37 -0700975
Jeff Brown70825162012-03-28 17:27:48 -0700976 mHandler = new PolicyHandler();
Jeff Browna20dda42014-05-27 20:57:24 -0700977 mWakeGestureListener = new MyWakeGestureListener(mContext, mHandler);
Craig Mautnereee29c42013-01-17 14:44:34 -0800978 mOrientationListener = new MyOrientationListener(mContext, mHandler);
Jeff Brownc0347aa2011-09-23 17:26:09 -0700979 try {
980 mOrientationListener.setCurrentRotation(windowManager.getRotation());
981 } catch (RemoteException ex) { }
Christopher Tate5e08af02012-09-21 17:17:22 -0700982 mSettingsObserver = new SettingsObserver(mHandler);
983 mSettingsObserver.observe();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800984 mShortcutManager = new ShortcutManager(context, mHandler);
985 mShortcutManager.observe();
Daniel Sandler6396c722013-04-16 20:19:09 -0400986 mUiMode = context.getResources().getInteger(
987 com.android.internal.R.integer.config_defaultUiModeType);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800988 mHomeIntent = new Intent(Intent.ACTION_MAIN, null);
989 mHomeIntent.addCategory(Intent.CATEGORY_HOME);
990 mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
991 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700992 mCarDockIntent = new Intent(Intent.ACTION_MAIN, null);
993 mCarDockIntent.addCategory(Intent.CATEGORY_CAR_DOCK);
994 mCarDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
995 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
996 mDeskDockIntent = new Intent(Intent.ACTION_MAIN, null);
997 mDeskDockIntent.addCategory(Intent.CATEGORY_DESK_DOCK);
998 mDeskDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
999 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Jim Millere6ad1a82010-08-20 19:25:39 -07001000
Jeff Brown96307042012-07-27 15:51:34 -07001001 mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
1002 mBroadcastWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001003 "PhoneWindowManager.mBroadcastWakeLock");
1004 mEnableShiftMenuBugReports = "1".equals(SystemProperties.get("ro.debuggable"));
Jeff Brownbcdfc622014-03-06 19:13:04 -08001005 mSupportAutoRotation = mContext.getResources().getBoolean(
1006 com.android.internal.R.bool.config_supportAutoRotation);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001007 mLidOpenRotation = readRotation(
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001008 com.android.internal.R.integer.config_lidOpenRotation);
1009 mCarDockRotation = readRotation(
1010 com.android.internal.R.integer.config_carDockRotation);
1011 mDeskDockRotation = readRotation(
1012 com.android.internal.R.integer.config_deskDockRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001013 mUndockedHdmiRotation = readRotation(
1014 com.android.internal.R.integer.config_undockedHdmiRotation);
Mike Lockwoode9867d22009-09-20 01:59:02 -04001015 mCarDockEnablesAccelerometer = mContext.getResources().getBoolean(
1016 com.android.internal.R.bool.config_carDockEnablesAccelerometer);
1017 mDeskDockEnablesAccelerometer = mContext.getResources().getBoolean(
1018 com.android.internal.R.bool.config_deskDockEnablesAccelerometer);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001019 mLidKeyboardAccessibility = mContext.getResources().getInteger(
1020 com.android.internal.R.integer.config_lidKeyboardAccessibility);
1021 mLidNavigationAccessibility = mContext.getResources().getInteger(
1022 com.android.internal.R.integer.config_lidNavigationAccessibility);
Jeff Brownc458ce92012-04-30 14:58:40 -07001023 mLidControlsSleep = mContext.getResources().getBoolean(
1024 com.android.internal.R.bool.config_lidControlsSleep);
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04001025 mTranslucentDecorEnabled = mContext.getResources().getBoolean(
1026 com.android.internal.R.bool.config_enableTranslucentDecor);
Jeff Brownf71343d2013-05-31 17:59:11 -07001027 readConfigurationDependentBehaviors();
Jeff Browncaca8812013-05-09 13:34:33 -07001028
Svetoslav8e3feb12014-02-24 13:46:47 -08001029 mAccessibilityManager = (AccessibilityManager) context.getSystemService(
1030 Context.ACCESSIBILITY_SERVICE);
1031
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001032 // register for dock events
Dianne Hackborn78968392010-03-04 20:47:56 -08001033 IntentFilter filter = new IntentFilter();
1034 filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE);
1035 filter.addAction(UiModeManager.ACTION_EXIT_CAR_MODE);
1036 filter.addAction(UiModeManager.ACTION_ENTER_DESK_MODE);
1037 filter.addAction(UiModeManager.ACTION_EXIT_DESK_MODE);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001038 filter.addAction(Intent.ACTION_DOCK_EVENT);
1039 Intent intent = context.registerReceiver(mDockReceiver, filter);
1040 if (intent != null) {
1041 // Retrieve current sticky dock event broadcast.
1042 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
1043 Intent.EXTRA_DOCK_STATE_UNDOCKED);
1044 }
Daniel Sandler7e37df52011-11-16 22:08:23 -08001045
Jeff Brown6aaf2952012-10-05 16:01:08 -07001046 // register for dream-related broadcasts
1047 filter = new IntentFilter();
1048 filter.addAction(Intent.ACTION_DREAMING_STARTED);
1049 filter.addAction(Intent.ACTION_DREAMING_STOPPED);
1050 context.registerReceiver(mDreamReceiver, filter);
1051
Christopher Tate5e08af02012-09-21 17:17:22 -07001052 // register for multiuser-relevant broadcasts
1053 filter = new IntentFilter(Intent.ACTION_USER_SWITCHED);
1054 context.registerReceiver(mMultiuserReceiver, filter);
1055
John Spurlock57306e62013-04-22 09:48:49 -04001056 // monitor for system gestures
Craig Mautner037aa8d2013-06-07 10:35:44 -07001057 mSystemGestures = new SystemGesturesPointerEventListener(context,
1058 new SystemGesturesPointerEventListener.Callbacks() {
John Spurlock57306e62013-04-22 09:48:49 -04001059 @Override
1060 public void onSwipeFromTop() {
John Spurlock04db1762013-05-13 12:46:41 -04001061 if (mStatusBar != null) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001062 requestTransientBars(mStatusBar);
John Spurlock04db1762013-05-13 12:46:41 -04001063 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04001064 }
1065 @Override
1066 public void onSwipeFromBottom() {
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 onSwipeFromRight() {
John Spurlock04db1762013-05-13 12:46:41 -04001073 if (mNavigationBar != null && !mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001074 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001075 }
1076 }
1077 @Override
1078 public void onDebug() {
John Spurlockd67ec252013-09-05 11:31:54 -04001079 // no-op
John Spurlockad3e6cb2013-04-30 08:47:43 -04001080 }
1081 });
John Spurlockf1a36642013-10-12 17:50:42 -04001082 mImmersiveModeConfirmation = new ImmersiveModeConfirmation(mContext);
Craig Mautner037aa8d2013-06-07 10:35:44 -07001083 mWindowManagerFuncs.registerPointerEventListener(mSystemGestures);
John Spurlock32beb2c2013-03-11 10:16:47 -04001084
Jeff Brownc2346132012-04-13 01:55:38 -07001085 mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001086 mLongPressVibePattern = getLongIntArray(mContext.getResources(),
1087 com.android.internal.R.array.config_longPressVibePattern);
1088 mVirtualKeyVibePattern = getLongIntArray(mContext.getResources(),
1089 com.android.internal.R.array.config_virtualKeyVibePattern);
Amith Yamasanic33cb712010-02-10 15:21:49 -08001090 mKeyboardTapVibePattern = getLongIntArray(mContext.getResources(),
1091 com.android.internal.R.array.config_keyboardTapVibePattern);
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07001092 mClockTickVibePattern = getLongIntArray(mContext.getResources(),
1093 com.android.internal.R.array.config_clockTickVibePattern);
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07001094 mCalendarDateVibePattern = getLongIntArray(mContext.getResources(),
1095 com.android.internal.R.array.config_calendarDateVibePattern);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001096 mSafeModeDisabledVibePattern = getLongIntArray(mContext.getResources(),
1097 com.android.internal.R.array.config_safeModeDisabledVibePattern);
1098 mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(),
1099 com.android.internal.R.array.config_safeModeEnabledVibePattern);
Daniel Sandler40427442010-07-16 11:44:52 -04001100
Christopher Tatee90585f2012-03-05 18:56:25 -08001101 mScreenshotChordEnabled = mContext.getResources().getBoolean(
1102 com.android.internal.R.bool.config_enableScreenshotChord);
1103
Justin Kohd378ad72013-04-01 12:18:26 -07001104 mGlobalKeyManager = new GlobalKeyManager(mContext);
1105
Joe Onoratoea495d42011-04-06 11:41:11 -07001106 // Controls rotation and the like.
1107 initializeHdmiState();
Dianne Hackborn40011092011-09-22 13:37:48 -07001108
1109 // Match current screen state.
Craig Mautnera631d492014-08-05 15:16:01 -07001110 if (!mPowerManager.isInteractive()) {
Jeff Brown140ffc72014-05-01 15:18:00 -07001111 goingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
Dianne Hackborn40011092011-09-22 13:37:48 -07001112 }
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001113 }
1114
Jeff Brownf71343d2013-05-31 17:59:11 -07001115 /**
1116 * Read values from config.xml that may be overridden depending on
1117 * the configuration of the device.
1118 * eg. Disable long press on home goes to recents on sw600dp.
1119 */
1120 private void readConfigurationDependentBehaviors() {
1121 mLongPressOnHomeBehavior = mContext.getResources().getInteger(
1122 com.android.internal.R.integer.config_longPressOnHomeBehavior);
1123 if (mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING ||
1124 mLongPressOnHomeBehavior > LONG_PRESS_HOME_ASSIST) {
1125 mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1126 }
1127
1128 mDoubleTapOnHomeBehavior = mContext.getResources().getInteger(
1129 com.android.internal.R.integer.config_doubleTapOnHomeBehavior);
1130 if (mDoubleTapOnHomeBehavior < DOUBLE_TAP_HOME_NOTHING ||
1131 mDoubleTapOnHomeBehavior > DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1132 mDoubleTapOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1133 }
1134 }
1135
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001136 @Override
Dianne Hackborndde331c2012-08-03 14:01:57 -07001137 public void setInitialDisplaySize(Display display, int width, int height, int density) {
Jeff Brownef981a42013-08-07 14:13:37 -07001138 // This method might be called before the policy has been fully initialized
1139 // or for other displays we don't care about.
1140 if (mContext == null || display.getDisplayId() != Display.DEFAULT_DISPLAY) {
1141 return;
Dianne Hackbornc652de82013-02-15 16:32:56 -08001142 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001143 mDisplay = display;
1144
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001145 final Resources res = mContext.getResources();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001146 int shortSize, longSize;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001147 if (width > height) {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001148 shortSize = height;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001149 longSize = width;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001150 mLandscapeRotation = Surface.ROTATION_0;
1151 mSeascapeRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001152 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001153 mPortraitRotation = Surface.ROTATION_90;
1154 mUpsideDownRotation = Surface.ROTATION_270;
1155 } else {
1156 mPortraitRotation = Surface.ROTATION_270;
1157 mUpsideDownRotation = Surface.ROTATION_90;
1158 }
1159 } else {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001160 shortSize = width;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001161 longSize = height;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001162 mPortraitRotation = Surface.ROTATION_0;
1163 mUpsideDownRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001164 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001165 mLandscapeRotation = Surface.ROTATION_270;
1166 mSeascapeRotation = Surface.ROTATION_90;
1167 } else {
1168 mLandscapeRotation = Surface.ROTATION_90;
1169 mSeascapeRotation = Surface.ROTATION_270;
1170 }
1171 }
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001172
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001173 mStatusBarHeight =
1174 res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001175
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001176 // Height of the navigation bar when presented horizontally at bottom
1177 mNavigationBarHeightForRotation[mPortraitRotation] =
1178 mNavigationBarHeightForRotation[mUpsideDownRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001179 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_height);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001180 mNavigationBarHeightForRotation[mLandscapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001181 mNavigationBarHeightForRotation[mSeascapeRotation] = res.getDimensionPixelSize(
1182 com.android.internal.R.dimen.navigation_bar_height_landscape);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001183
1184 // Width of the navigation bar when presented vertically along one side
1185 mNavigationBarWidthForRotation[mPortraitRotation] =
1186 mNavigationBarWidthForRotation[mUpsideDownRotation] =
1187 mNavigationBarWidthForRotation[mLandscapeRotation] =
1188 mNavigationBarWidthForRotation[mSeascapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001189 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_width);
Daniel Sandler4a066c52012-04-20 14:49:13 -04001190
1191 // SystemUI (status bar) layout policy
Dianne Hackborndde331c2012-08-03 14:01:57 -07001192 int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / density;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001193 int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / density;
Daniel Sandler4a066c52012-04-20 14:49:13 -04001194
Craig Mautnerd4ec33242013-07-22 10:37:43 -07001195 // Allow the navigation bar to move on small devices (phones).
1196 mNavigationBarCanMove = shortSizeDp < 600;
Daniel Sandler36412a72011-08-04 09:35:13 -04001197
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001198 mHasNavigationBar = res.getBoolean(com.android.internal.R.bool.config_showNavigationBar);
John Spurlock80f00c12013-06-13 11:10:51 -04001199 // Allow a system property to override this. Used by the emulator.
1200 // See also hasNavigationBar().
1201 String navBarOverride = SystemProperties.get("qemu.hw.mainkeys");
1202 if ("1".equals(navBarOverride)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001203 mHasNavigationBar = false;
John Spurlock80f00c12013-06-13 11:10:51 -04001204 } else if ("0".equals(navBarOverride)) {
1205 mHasNavigationBar = true;
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04001206 }
1207
Jeff Brown27f1d672012-10-17 18:32:34 -07001208 // For demo purposes, allow the rotation of the HDMI display to be controlled.
1209 // By default, HDMI locks rotation to landscape.
Erik Gilling9a41ef82011-09-26 19:21:03 -07001210 if ("portrait".equals(SystemProperties.get("persist.demo.hdmirotation"))) {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001211 mDemoHdmiRotation = mPortraitRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001212 } else {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001213 mDemoHdmiRotation = mLandscapeRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001214 }
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001215 mDemoHdmiRotationLock = SystemProperties.getBoolean("persist.demo.hdmirotationlock", false);
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001216
1217 // Only force the default orientation if the screen is xlarge, at least 960dp x 720dp, per
1218 // http://developer.android.com/guide/practices/screens_support.html#range
1219 mForceDefaultOrientation = longSizeDp >= 960 && shortSizeDp >= 720 &&
1220 res.getBoolean(com.android.internal.R.bool.config_forceDefaultOrientation) &&
1221 // For debug purposes the next line turns this feature off with:
1222 // $ adb shell setprop config.override_forced_orient true
1223 // $ adb shell wm size reset
1224 !"true".equals(SystemProperties.get("config.override_forced_orient"));
1225 }
1226
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001227 /**
1228 * @return whether the navigation bar can be hidden, e.g. the device has a
1229 * navigation bar and touch exploration is not enabled
1230 */
1231 private boolean canHideNavigationBar() {
Svetoslav8e3feb12014-02-24 13:46:47 -08001232 return mHasNavigationBar
1233 && !mAccessibilityManager.isTouchExplorationEnabled();
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001234 }
1235
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001236 @Override
1237 public boolean isDefaultOrientationForced() {
1238 return mForceDefaultOrientation;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001239 }
1240
Dianne Hackbornc652de82013-02-15 16:32:56 -08001241 @Override
1242 public void setDisplayOverscan(Display display, int left, int top, int right, int bottom) {
1243 if (display.getDisplayId() == Display.DEFAULT_DISPLAY) {
1244 mOverscanLeft = left;
1245 mOverscanTop = top;
1246 mOverscanRight = right;
1247 mOverscanBottom = bottom;
1248 }
1249 }
1250
Dianne Hackbornc777e072010-02-12 13:07:59 -08001251 public void updateSettings() {
1252 ContentResolver resolver = mContext.getContentResolver();
1253 boolean updateRotation = false;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001254 synchronized (mLock) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001255 mEndcallBehavior = Settings.System.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001256 Settings.System.END_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001257 Settings.System.END_BUTTON_BEHAVIOR_DEFAULT,
1258 UserHandle.USER_CURRENT);
1259 mIncallPowerBehavior = Settings.Secure.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001260 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001261 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT,
1262 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001263
Jeff Browna20dda42014-05-27 20:57:24 -07001264 // Configure wake gesture.
1265 boolean wakeGestureEnabledSetting = Settings.Secure.getIntForUser(resolver,
1266 Settings.Secure.WAKE_GESTURE_ENABLED, 0,
1267 UserHandle.USER_CURRENT) != 0;
1268 if (mWakeGestureEnabledSetting != wakeGestureEnabledSetting) {
1269 mWakeGestureEnabledSetting = wakeGestureEnabledSetting;
1270 updateWakeGestureListenerLp();
1271 }
1272
Jeff Brown207673cd2012-06-05 17:47:11 -07001273 // Configure rotation lock.
Christopher Tate5e08af02012-09-21 17:17:22 -07001274 int userRotation = Settings.System.getIntForUser(resolver,
1275 Settings.System.USER_ROTATION, Surface.ROTATION_0,
1276 UserHandle.USER_CURRENT);
Jeff Brown207673cd2012-06-05 17:47:11 -07001277 if (mUserRotation != userRotation) {
1278 mUserRotation = userRotation;
1279 updateRotation = true;
1280 }
Christopher Tate5e08af02012-09-21 17:17:22 -07001281 int userRotationMode = Settings.System.getIntForUser(resolver,
1282 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
Jeff Brown207673cd2012-06-05 17:47:11 -07001283 WindowManagerPolicy.USER_ROTATION_FREE :
1284 WindowManagerPolicy.USER_ROTATION_LOCKED;
1285 if (mUserRotationMode != userRotationMode) {
1286 mUserRotationMode = userRotationMode;
1287 updateRotation = true;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001288 updateOrientationListenerLp();
1289 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001290
Dianne Hackbornc777e072010-02-12 13:07:59 -08001291 if (mSystemReady) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001292 int pointerLocation = Settings.System.getIntForUser(resolver,
1293 Settings.System.POINTER_LOCATION, 0, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001294 if (mPointerLocationMode != pointerLocation) {
1295 mPointerLocationMode = pointerLocation;
Jeff Brown70825162012-03-28 17:27:48 -07001296 mHandler.sendEmptyMessage(pointerLocation != 0 ?
1297 MSG_ENABLE_POINTER_LOCATION : MSG_DISABLE_POINTER_LOCATION);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001298 }
1299 }
1300 // use screen off timeout setting as the timeout for the lockscreen
Christopher Tate5e08af02012-09-21 17:17:22 -07001301 mLockScreenTimeout = Settings.System.getIntForUser(resolver,
1302 Settings.System.SCREEN_OFF_TIMEOUT, 0, UserHandle.USER_CURRENT);
1303 String imId = Settings.Secure.getStringForUser(resolver,
1304 Settings.Secure.DEFAULT_INPUT_METHOD, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001305 boolean hasSoftInput = imId != null && imId.length() > 0;
1306 if (mHasSoftInput != hasSoftInput) {
1307 mHasSoftInput = hasSoftInput;
1308 updateRotation = true;
1309 }
John Spurlockf1a36642013-10-12 17:50:42 -04001310 if (mImmersiveModeConfirmation != null) {
John Spurlock4355a532014-02-19 09:49:25 -05001311 mImmersiveModeConfirmation.loadSetting(mCurrentUserId);
John Spurlockd67ec252013-09-05 11:31:54 -04001312 }
John Spurlockc6d1c602014-01-17 15:22:06 -05001313 PolicyControl.reloadFromSetting(mContext);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001314 }
1315 if (updateRotation) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07001316 updateRotation(true);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001317 }
Jeff Brown70825162012-03-28 17:27:48 -07001318 }
1319
Jeff Browna20dda42014-05-27 20:57:24 -07001320 private void updateWakeGestureListenerLp() {
1321 if (shouldEnableWakeGestureLp()) {
1322 mWakeGestureListener.requestWakeUpTrigger();
1323 } else {
1324 mWakeGestureListener.cancelWakeUpTrigger();
1325 }
1326 }
1327
1328 private boolean shouldEnableWakeGestureLp() {
1329 return mWakeGestureEnabledSetting && !mScreenOnEarly
1330 && (!mLidControlsSleep || mLidState != LID_CLOSED)
1331 && mWakeGestureListener.isSupported();
1332 }
1333
Jeff Brown70825162012-03-28 17:27:48 -07001334 private void enablePointerLocation() {
1335 if (mPointerLocationView == null) {
1336 mPointerLocationView = new PointerLocationView(mContext);
1337 mPointerLocationView.setPrintCoords(false);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001338 WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
1339 WindowManager.LayoutParams.MATCH_PARENT,
1340 WindowManager.LayoutParams.MATCH_PARENT);
Jeff Brown3b2b3542010-10-15 00:54:27 -07001341 lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001342 lp.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN
1343 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
1344 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1345 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
Jeff Brown90fc9052012-10-01 14:44:24 -07001346 if (ActivityManager.isHighEndGfx()) {
1347 lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
1348 lp.privateFlags |=
1349 WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED;
1350 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001351 lp.format = PixelFormat.TRANSLUCENT;
1352 lp.setTitle("PointerLocation");
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001353 WindowManager wm = (WindowManager)
Dianne Hackbornc777e072010-02-12 13:07:59 -08001354 mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Browncc4f7db2011-08-30 20:34:48 -07001355 lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL;
Jeff Brown70825162012-03-28 17:27:48 -07001356 wm.addView(mPointerLocationView, lp);
Michael Wrightc9c487e2013-11-07 18:55:09 -08001357 mWindowManagerFuncs.registerPointerEventListener(mPointerLocationView);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001358 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001359 }
Jeff Brown70825162012-03-28 17:27:48 -07001360
1361 private void disablePointerLocation() {
Jeff Brown70825162012-03-28 17:27:48 -07001362 if (mPointerLocationView != null) {
Michael Wrightc9c487e2013-11-07 18:55:09 -08001363 mWindowManagerFuncs.unregisterPointerEventListener(mPointerLocationView);
1364 WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Brown70825162012-03-28 17:27:48 -07001365 wm.removeView(mPointerLocationView);
1366 mPointerLocationView = null;
1367 }
1368 }
1369
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001370 private int readRotation(int resID) {
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001371 try {
1372 int rotation = mContext.getResources().getInteger(resID);
1373 switch (rotation) {
1374 case 0:
1375 return Surface.ROTATION_0;
1376 case 90:
1377 return Surface.ROTATION_90;
1378 case 180:
1379 return Surface.ROTATION_180;
1380 case 270:
1381 return Surface.ROTATION_270;
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001382 }
1383 } catch (Resources.NotFoundException e) {
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001384 // fall through
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001385 }
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001386 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001387 }
1388
1389 /** {@inheritDoc} */
Craig Mautner88400d32012-09-30 12:35:45 -07001390 @Override
Dianne Hackbornc2293022013-02-06 23:14:49 -08001391 public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001392 int type = attrs.type;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001393
1394 outAppOp[0] = AppOpsManager.OP_NONE;
1395
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001396 if (type < WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW
1397 || type > WindowManager.LayoutParams.LAST_SYSTEM_WINDOW) {
Jeff Brown98365d72012-08-19 20:30:52 -07001398 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001399 }
1400 String permission = null;
1401 switch (type) {
1402 case TYPE_TOAST:
1403 // XXX right now the app process has complete control over
1404 // this... should introduce a token to let the system
1405 // monitor/control what they are doing.
Jason Monk1c7c3192014-06-26 12:52:18 -04001406 outAppOp[0] = AppOpsManager.OP_TOAST_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001407 break;
Daniel Sandler7d276c32012-01-30 14:33:52 -05001408 case TYPE_DREAM:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001409 case TYPE_INPUT_METHOD:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001410 case TYPE_WALLPAPER:
keunyounga446bf02013-06-21 19:07:57 -07001411 case TYPE_PRIVATE_PRESENTATION:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001412 case TYPE_VOICE_INTERACTION:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001413 // The window manager will check these.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001414 break;
1415 case TYPE_PHONE:
1416 case TYPE_PRIORITY_PHONE:
1417 case TYPE_SYSTEM_ALERT:
1418 case TYPE_SYSTEM_ERROR:
1419 case TYPE_SYSTEM_OVERLAY:
1420 permission = android.Manifest.permission.SYSTEM_ALERT_WINDOW;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001421 outAppOp[0] = AppOpsManager.OP_SYSTEM_ALERT_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001422 break;
1423 default:
1424 permission = android.Manifest.permission.INTERNAL_SYSTEM_WINDOW;
1425 }
1426 if (permission != null) {
1427 if (mContext.checkCallingOrSelfPermission(permission)
1428 != PackageManager.PERMISSION_GRANTED) {
Jeff Brown98365d72012-08-19 20:30:52 -07001429 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001430 }
1431 }
Jeff Brown98365d72012-08-19 20:30:52 -07001432 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001433 }
Craig Mautner88400d32012-09-30 12:35:45 -07001434
1435 @Override
1436 public boolean checkShowToOwnerOnly(WindowManager.LayoutParams attrs) {
1437
1438 // If this switch statement is modified, modify the comment in the declarations of
1439 // the type in {@link WindowManager.LayoutParams} as well.
1440 switch (attrs.type) {
1441 default:
1442 // These are the windows that by default are shown only to the user that created
1443 // them. If this needs to be overridden, set
1444 // {@link WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS} in
1445 // {@link WindowManager.LayoutParams}. Note that permission
1446 // {@link android.Manifest.permission.INTERNAL_SYSTEM_WINDOW} is required as well.
1447 if ((attrs.privateFlags & PRIVATE_FLAG_SHOW_FOR_ALL_USERS) == 0) {
1448 return true;
1449 }
1450 break;
1451
1452 // These are the windows that by default are shown to all users. However, to
1453 // protect against spoofing, check permissions below.
1454 case TYPE_APPLICATION_STARTING:
1455 case TYPE_BOOT_PROGRESS:
1456 case TYPE_DISPLAY_OVERLAY:
1457 case TYPE_HIDDEN_NAV_CONSUMER:
Jim Miller5ecd8112013-01-09 18:50:26 -08001458 case TYPE_KEYGUARD_SCRIM:
Craig Mautner88400d32012-09-30 12:35:45 -07001459 case TYPE_KEYGUARD_DIALOG:
1460 case TYPE_MAGNIFICATION_OVERLAY:
1461 case TYPE_NAVIGATION_BAR:
1462 case TYPE_NAVIGATION_BAR_PANEL:
1463 case TYPE_PHONE:
1464 case TYPE_POINTER:
1465 case TYPE_PRIORITY_PHONE:
1466 case TYPE_RECENTS_OVERLAY:
1467 case TYPE_SEARCH_BAR:
1468 case TYPE_STATUS_BAR:
1469 case TYPE_STATUS_BAR_PANEL:
1470 case TYPE_STATUS_BAR_SUB_PANEL:
1471 case TYPE_SYSTEM_DIALOG:
1472 case TYPE_UNIVERSE_BACKGROUND:
1473 case TYPE_VOLUME_OVERLAY:
keunyounga446bf02013-06-21 19:07:57 -07001474 case TYPE_PRIVATE_PRESENTATION:
Craig Mautner88400d32012-09-30 12:35:45 -07001475 break;
1476 }
1477
1478 // Check if third party app has set window to system window type.
1479 return mContext.checkCallingOrSelfPermission(
1480 android.Manifest.permission.INTERNAL_SYSTEM_WINDOW)
1481 != PackageManager.PERMISSION_GRANTED;
1482 }
1483
Craig Mautner967212c2013-04-13 21:10:58 -07001484 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001485 public void adjustWindowParamsLw(WindowManager.LayoutParams attrs) {
1486 switch (attrs.type) {
1487 case TYPE_SYSTEM_OVERLAY:
Jeff Brown3b2b3542010-10-15 00:54:27 -07001488 case TYPE_SECURE_SYSTEM_OVERLAY:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001489 // These types of windows can't receive input events.
1490 attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1491 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001492 attrs.flags &= ~WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001493 break;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001494 case TYPE_STATUS_BAR:
1495
1496 // If the Keyguard is in a hidden state (occluded by another window), we force to
1497 // remove the wallpaper and keyguard flag so that any change in-flight after setting
1498 // the keyguard as occluded wouldn't set these flags again.
1499 // See {@link #processKeyguardSetHiddenResultLw}.
1500 if (mKeyguardHidden) {
1501 attrs.flags &= ~WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
1502 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
1503 }
1504 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001505 }
Adrian Roos38502112014-04-09 21:04:11 +02001506
1507 if (attrs.type != TYPE_STATUS_BAR) {
1508 // The status bar is the only window allowed to exhibit keyguard behavior.
1509 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
1510 }
Adrian Roosea562512014-05-05 13:33:03 +02001511
1512 if (ActivityManager.isHighEndGfx()
1513 && (attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0) {
1514 attrs.subtreeSystemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_STABLE
1515 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
1516 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
1517 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001518 }
RoboErik8a2cfc32014-05-16 11:19:38 -07001519
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001520 void readLidState() {
Jeff Brown2e7760e2012-04-11 15:14:55 -07001521 mLidState = mWindowManagerFuncs.getLidState();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001522 }
RoboErik8a2cfc32014-05-16 11:19:38 -07001523
Jeff Browndaa37532012-05-01 15:54:03 -07001524 private boolean isHidden(int accessibilityMode) {
1525 switch (accessibilityMode) {
1526 case 1:
1527 return mLidState == LID_CLOSED;
1528 case 2:
1529 return mLidState == LID_OPEN;
1530 default:
1531 return false;
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001532 }
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001533 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001534
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001535 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07001536 @Override
Jeff Browndaa37532012-05-01 15:54:03 -07001537 public void adjustConfigurationLw(Configuration config, int keyboardPresence,
1538 int navigationPresence) {
1539 mHaveBuiltInKeyboard = (keyboardPresence & PRESENCE_INTERNAL) != 0;
1540
Jeff Brownf71343d2013-05-31 17:59:11 -07001541 readConfigurationDependentBehaviors();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001542 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07001543 applyLidSwitchState();
Jeff Brownd04a88c2011-01-16 14:05:47 -08001544
Jeff Browndaa37532012-05-01 15:54:03 -07001545 if (config.keyboard == Configuration.KEYBOARD_NOKEYS
1546 || (keyboardPresence == PRESENCE_INTERNAL
1547 && isHidden(mLidKeyboardAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001548 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_YES;
Jeff Browndaa37532012-05-01 15:54:03 -07001549 if (!mHasSoftInput) {
1550 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_YES;
1551 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001552 }
1553
Jeff Browndaa37532012-05-01 15:54:03 -07001554 if (config.navigation == Configuration.NAVIGATION_NONAV
1555 || (navigationPresence == PRESENCE_INTERNAL
1556 && isHidden(mLidNavigationAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001557 config.navigationHidden = Configuration.NAVIGATIONHIDDEN_YES;
Jeff Brownd04a88c2011-01-16 14:05:47 -08001558 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001559 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001560
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001561 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07001562 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001563 public int windowTypeToLayerLw(int type) {
1564 if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001565 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001566 }
1567 switch (type) {
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001568 case TYPE_UNIVERSE_BACKGROUND:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001569 return 1;
keunyounga446bf02013-06-21 19:07:57 -07001570 case TYPE_PRIVATE_PRESENTATION:
1571 return 2;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001572 case TYPE_WALLPAPER:
1573 // wallpaper is at the bottom, though the window manager may move it.
1574 return 2;
1575 case TYPE_PHONE:
1576 return 3;
1577 case TYPE_SEARCH_BAR:
1578 return 4;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001579 case TYPE_VOICE_INTERACTION:
1580 // voice interaction layer is almost immediately above apps.
1581 return 5;
Craig Mautner88400d32012-09-30 12:35:45 -07001582 case TYPE_RECENTS_OVERLAY:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001583 case TYPE_SYSTEM_DIALOG:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001584 return 6;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001585 case TYPE_TOAST:
1586 // toasts and the plugged-in battery thing
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001587 return 7;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001588 case TYPE_PRIORITY_PHONE:
1589 // SIM errors and unlock. Not sure if this really should be in a high layer.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001590 return 8;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001591 case TYPE_DREAM:
1592 // used for Dreams (screensavers with TYPE_DREAM windows)
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001593 return 9;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001594 case TYPE_SYSTEM_ALERT:
1595 // like the ANR / app crashed dialogs
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001596 return 10;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001597 case TYPE_INPUT_METHOD:
1598 // on-screen keyboards and other such input method user interfaces go here.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001599 return 11;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001600 case TYPE_INPUT_METHOD_DIALOG:
1601 // on-screen keyboards and other such input method user interfaces go here.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001602 return 12;
Jim Miller5ecd8112013-01-09 18:50:26 -08001603 case TYPE_KEYGUARD_SCRIM:
1604 // the safety window that shows behind keyguard while keyguard is starting
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001605 return 13;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001606 case TYPE_STATUS_BAR_SUB_PANEL:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001607 return 14;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001608 case TYPE_STATUS_BAR:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001609 return 15;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001610 case TYPE_STATUS_BAR_PANEL:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001611 return 16;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001612 case TYPE_KEYGUARD_DIALOG:
1613 return 17;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001614 case TYPE_VOLUME_OVERLAY:
1615 // the on-screen volume indicator and controller shown when the user
1616 // changes the device volume
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001617 return 18;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001618 case TYPE_SYSTEM_OVERLAY:
1619 // the on-screen volume indicator and controller shown when the user
1620 // changes the device volume
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001621 return 19;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001622 case TYPE_NAVIGATION_BAR:
1623 // the navigation bar, if available, shows atop most things
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001624 return 20;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001625 case TYPE_NAVIGATION_BAR_PANEL:
1626 // some panels (e.g. search) need to show on top of the navigation bar
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001627 return 21;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001628 case TYPE_SYSTEM_ERROR:
1629 // system-level error dialogs
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001630 return 22;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001631 case TYPE_MAGNIFICATION_OVERLAY:
1632 // used to highlight the magnified portion of a display
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001633 return 23;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001634 case TYPE_DISPLAY_OVERLAY:
1635 // used to simulate secondary display devices
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001636 return 24;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001637 case TYPE_DRAG:
1638 // the drag layer: input for drag-and-drop is associated with this window,
1639 // which sits above all other focusable windows
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001640 return 25;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001641 case TYPE_SECURE_SYSTEM_OVERLAY:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001642 return 26;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001643 case TYPE_BOOT_PROGRESS:
1644 return 27;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001645 case TYPE_POINTER:
1646 // the (mouse) pointer layer
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001647 return 28;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001648 case TYPE_HIDDEN_NAV_CONSUMER:
1649 return 29;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001650 }
1651 Log.e(TAG, "Unknown window type: " + type);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001652 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001653 }
1654
1655 /** {@inheritDoc} */
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001656 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001657 public int subWindowTypeToLayerLw(int type) {
1658 switch (type) {
1659 case TYPE_APPLICATION_PANEL:
1660 case TYPE_APPLICATION_ATTACHED_DIALOG:
1661 return APPLICATION_PANEL_SUBLAYER;
1662 case TYPE_APPLICATION_MEDIA:
1663 return APPLICATION_MEDIA_SUBLAYER;
Dianne Hackborn5cb8d792009-05-21 17:34:15 -07001664 case TYPE_APPLICATION_MEDIA_OVERLAY:
1665 return APPLICATION_MEDIA_OVERLAY_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001666 case TYPE_APPLICATION_SUB_PANEL:
1667 return APPLICATION_SUB_PANEL_SUBLAYER;
1668 }
1669 Log.e(TAG, "Unknown sub-window type: " + type);
1670 return 0;
1671 }
1672
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001673 @Override
Dianne Hackbornabe0da02009-09-18 01:55:39 -07001674 public int getMaxWallpaperLayer() {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001675 return windowTypeToLayerLw(TYPE_STATUS_BAR);
Dianne Hackbornabe0da02009-09-18 01:55:39 -07001676 }
1677
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001678 @Override
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001679 public int getAboveUniverseLayer() {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001680 return windowTypeToLayerLw(TYPE_SYSTEM_ERROR);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001681 }
1682
Jose Lima9546b202014-07-02 17:21:51 -07001683 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001684 public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07001685 if (mHasNavigationBar) {
1686 // For a basic navigation bar, when we are in landscape mode we place
1687 // the navigation bar to the side.
Daniel Sandler4a066c52012-04-20 14:49:13 -04001688 if (mNavigationBarCanMove && fullWidth > fullHeight) {
1689 return fullWidth - mNavigationBarWidthForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07001690 }
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001691 }
1692 return fullWidth;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001693 }
1694
Jose Lima9546b202014-07-02 17:21:51 -07001695 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001696 public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07001697 if (mHasNavigationBar) {
1698 // For a basic navigation bar, when we are in portrait mode we place
1699 // the navigation bar to the bottom.
Daniel Sandler4a066c52012-04-20 14:49:13 -04001700 if (!mNavigationBarCanMove || fullWidth < fullHeight) {
1701 return fullHeight - mNavigationBarHeightForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07001702 }
1703 }
1704 return fullHeight;
Dianne Hackborn69cb8752011-05-19 18:13:32 -07001705 }
1706
Jose Lima9546b202014-07-02 17:21:51 -07001707 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001708 public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation) {
1709 return getNonDecorDisplayWidth(fullWidth, fullHeight, rotation);
Dianne Hackborn69cb8752011-05-19 18:13:32 -07001710 }
1711
Jose Lima9546b202014-07-02 17:21:51 -07001712 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001713 public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation) {
John Spurlock80f00c12013-06-13 11:10:51 -04001714 // There is a separate status bar at the top of the display. We don't count that as part
1715 // of the fixed decor, since it can hide; however, for purposes of configurations,
Dianne Hackborn077ee852012-04-09 16:27:07 -07001716 // we do want to exclude it since applications can't generally use that part
1717 // of the screen.
John Spurlock80f00c12013-06-13 11:10:51 -04001718 return getNonDecorDisplayHeight(fullWidth, fullHeight, rotation) - mStatusBarHeight;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001719 }
1720
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001721 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07001722 public boolean isForceHiding(WindowManager.LayoutParams attrs) {
1723 return (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 ||
Adrian Roos69e510d2014-07-13 14:57:59 +02001724 (isKeyguardHostWindow(attrs) && isKeyguardSecureIncludingHidden()) ||
1725 (attrs.type == TYPE_KEYGUARD_SCRIM);
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07001726 }
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001727
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001728 @Override
Jorim Jaggi0d674622014-05-21 01:34:15 +02001729 public boolean isKeyguardHostWindow(WindowManager.LayoutParams attrs) {
1730 return attrs.type == TYPE_STATUS_BAR;
1731 }
1732
1733 @Override
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07001734 public boolean canBeForceHidden(WindowState win, WindowManager.LayoutParams attrs) {
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001735 switch (attrs.type) {
1736 case TYPE_STATUS_BAR:
1737 case TYPE_NAVIGATION_BAR:
1738 case TYPE_WALLPAPER:
1739 case TYPE_DREAM:
1740 case TYPE_UNIVERSE_BACKGROUND:
Jim Miller5ecd8112013-01-09 18:50:26 -08001741 case TYPE_KEYGUARD_SCRIM:
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001742 return false;
1743 default:
1744 return true;
1745 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07001746 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001747
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001748 /** {@inheritDoc} */
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001749 @Override
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07001750 public View addStartingWindow(IBinder appToken, String packageName, int theme,
1751 CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes,
Adam Powell04fe6eb2013-05-31 14:39:48 -07001752 int icon, int logo, int windowFlags) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001753 if (!SHOW_STARTING_ANIMATIONS) {
1754 return null;
1755 }
1756 if (packageName == null) {
1757 return null;
1758 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001759
Mathias Jeppssond1443e92012-08-24 15:25:32 +02001760 WindowManager wm = null;
1761 View view = null;
1762
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001763 try {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001764 Context context = mContext;
Craig Mautner6fbda632012-07-03 09:26:39 -07001765 if (DEBUG_STARTING_WINDOW) Slog.d(TAG, "addStartingWindow " + packageName
1766 + ": nonLocalizedLabel=" + nonLocalizedLabel + " theme="
1767 + Integer.toHexString(theme));
Dianne Hackborn247fe742011-01-08 17:25:57 -08001768 if (theme != context.getThemeResId() || labelRes != 0) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001769 try {
1770 context = context.createPackageContext(packageName, 0);
Dianne Hackborn247fe742011-01-08 17:25:57 -08001771 context.setTheme(theme);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001772 } catch (PackageManager.NameNotFoundException e) {
1773 // Ignore
1774 }
1775 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001776
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001777 Window win = PolicyManager.makeNewWindow(context);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001778 final TypedArray ta = win.getWindowStyle();
1779 if (ta.getBoolean(
1780 com.android.internal.R.styleable.Window_windowDisablePreview, false)
1781 || ta.getBoolean(
1782 com.android.internal.R.styleable.Window_windowShowWallpaper,false)) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001783 return null;
1784 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001785
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001786 Resources r = context.getResources();
1787 win.setTitle(r.getText(labelRes, nonLocalizedLabel));
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001788
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001789 win.setType(
1790 WindowManager.LayoutParams.TYPE_APPLICATION_STARTING);
1791 // Force the window flags: this is a fake window, so it is not really
1792 // touchable or focusable by the user. We also add in the ALT_FOCUSABLE_IM
1793 // flag because we do know that the next window will take input
1794 // focus, so we want to get the IME window up on top of us right away.
1795 win.setFlags(
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08001796 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001797 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
1798 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
1799 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08001800 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001801 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
1802 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
1803 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001804
Adam Powell04fe6eb2013-05-31 14:39:48 -07001805 win.setDefaultIcon(icon);
1806 win.setDefaultLogo(logo);
1807
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001808 win.setLayout(WindowManager.LayoutParams.MATCH_PARENT,
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07001809 WindowManager.LayoutParams.MATCH_PARENT);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001810
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001811 final WindowManager.LayoutParams params = win.getAttributes();
1812 params.token = appToken;
1813 params.packageName = packageName;
1814 params.windowAnimations = win.getWindowStyle().getResourceId(
1815 com.android.internal.R.styleable.Window_windowAnimationStyle, 0);
Dianne Hackborn5d927c22011-09-02 12:22:18 -07001816 params.privateFlags |=
1817 WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED;
Craig Mautner88400d32012-09-30 12:35:45 -07001818 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
Adam Lesinski95c42972013-10-02 10:13:27 -07001819
1820 if (!compatInfo.supportsScreen()) {
1821 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
1822 }
1823
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001824 params.setTitle("Starting " + packageName);
1825
Mathias Jeppssond1443e92012-08-24 15:25:32 +02001826 wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
1827 view = win.getDecorView();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001828
1829 if (win.isFloating()) {
1830 // Whoops, there is no way to display an animation/preview
1831 // of such a thing! After all that work... let's skip it.
1832 // (Note that we must do this here because it is in
1833 // getDecorView() where the theme is evaluated... maybe
1834 // we should peek the floating attribute from the theme
1835 // earlier.)
1836 return null;
1837 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001838
Craig Mautner6fbda632012-07-03 09:26:39 -07001839 if (DEBUG_STARTING_WINDOW) Slog.d(
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001840 TAG, "Adding starting window for " + packageName
1841 + " / " + appToken + ": "
1842 + (view.getParent() != null ? view : null));
1843
1844 wm.addView(view, params);
1845
1846 // Only return the view if it was successfully added to the
1847 // window manager... which we can tell by it having a parent.
1848 return view.getParent() != null ? view : null;
Jeff Brown98365d72012-08-19 20:30:52 -07001849 } catch (WindowManager.BadTokenException e) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001850 // ignore
Craig Mautner42bf39e2014-02-21 16:46:22 -08001851 Log.w(TAG, appToken + " already running, starting window not displayed. " +
1852 e.getMessage());
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001853 } catch (RuntimeException e) {
1854 // don't crash if something else bad happens, for example a
1855 // failure loading resources because we are loading from an app
1856 // on external storage that has been unmounted.
1857 Log.w(TAG, appToken + " failed creating starting window", e);
Mathias Jeppssond1443e92012-08-24 15:25:32 +02001858 } finally {
1859 if (view != null && view.getParent() == null) {
1860 Log.w(TAG, "view not successfully added to wm, removing view");
1861 wm.removeViewImmediate(view);
1862 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001863 }
1864
1865 return null;
1866 }
1867
1868 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07001869 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001870 public void removeStartingWindow(IBinder appToken, View window) {
Craig Mautner6fbda632012-07-03 09:26:39 -07001871 if (DEBUG_STARTING_WINDOW) {
1872 RuntimeException e = new RuntimeException("here");
1873 e.fillInStackTrace();
1874 Log.v(TAG, "Removing starting window for " + appToken + ": " + window, e);
1875 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001876
1877 if (window != null) {
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001878 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001879 wm.removeView(window);
1880 }
1881 }
1882
1883 /**
1884 * Preflight adding a window to the system.
RoboErik8a2cfc32014-05-16 11:19:38 -07001885 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001886 * Currently enforces that three window types are singletons:
1887 * <ul>
1888 * <li>STATUS_BAR_TYPE</li>
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001889 * <li>KEYGUARD_TYPE</li>
1890 * </ul>
RoboErik8a2cfc32014-05-16 11:19:38 -07001891 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001892 * @param win The window to be added
1893 * @param attrs Information about the window to be added
RoboErik8a2cfc32014-05-16 11:19:38 -07001894 *
Jeff Brown98365d72012-08-19 20:30:52 -07001895 * @return If ok, WindowManagerImpl.ADD_OKAY. If too many singletons,
1896 * WindowManagerImpl.ADD_MULTIPLE_SINGLETON
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001897 */
Jose Lima9546b202014-07-02 17:21:51 -07001898 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001899 public int prepareAddWindowLw(WindowState win, WindowManager.LayoutParams attrs) {
1900 switch (attrs.type) {
1901 case TYPE_STATUS_BAR:
Joe Onorato8bc6c512010-06-04 16:21:12 -04001902 mContext.enforceCallingOrSelfPermission(
1903 android.Manifest.permission.STATUS_BAR_SERVICE,
1904 "PhoneWindowManager");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001905 if (mStatusBar != null) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001906 if (mStatusBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07001907 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001908 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001909 }
1910 mStatusBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04001911 mStatusBarController.setWindow(win);
John Spurlock8fdfe622014-05-21 17:10:10 -04001912 mKeyguardDelegate.hideScrim();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001913 break;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04001914 case TYPE_NAVIGATION_BAR:
1915 mContext.enforceCallingOrSelfPermission(
1916 android.Manifest.permission.STATUS_BAR_SERVICE,
1917 "PhoneWindowManager");
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001918 if (mNavigationBar != null) {
1919 if (mNavigationBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07001920 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001921 }
1922 }
Daniel Sandler8956dbb2011-04-22 07:55:02 -04001923 mNavigationBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04001924 mNavigationBarController.setWindow(win);
Craig Mautnereda67292013-04-28 13:50:14 -07001925 if (DEBUG_LAYOUT) Slog.i(TAG, "NAVIGATION BAR: " + mNavigationBar);
Daniel Sandler8956dbb2011-04-22 07:55:02 -04001926 break;
Jim Millere898ac52012-04-06 17:10:57 -07001927 case TYPE_NAVIGATION_BAR_PANEL:
1928 mContext.enforceCallingOrSelfPermission(
1929 android.Manifest.permission.STATUS_BAR_SERVICE,
1930 "PhoneWindowManager");
1931 break;
Dianne Hackborn08743722009-12-21 12:16:51 -08001932 case TYPE_STATUS_BAR_PANEL:
Joe Onorato8bc6c512010-06-04 16:21:12 -04001933 mContext.enforceCallingOrSelfPermission(
1934 android.Manifest.permission.STATUS_BAR_SERVICE,
1935 "PhoneWindowManager");
Dianne Hackborn08743722009-12-21 12:16:51 -08001936 break;
Joe Onorato29fc2c92010-11-24 10:26:50 -08001937 case TYPE_STATUS_BAR_SUB_PANEL:
1938 mContext.enforceCallingOrSelfPermission(
1939 android.Manifest.permission.STATUS_BAR_SERVICE,
1940 "PhoneWindowManager");
Joe Onorato29fc2c92010-11-24 10:26:50 -08001941 break;
Jim Miller5ecd8112013-01-09 18:50:26 -08001942 case TYPE_KEYGUARD_SCRIM:
Jim Miller25190572013-02-28 17:36:24 -08001943 if (mKeyguardScrim != null) {
1944 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
1945 }
Jim Miller5ecd8112013-01-09 18:50:26 -08001946 mKeyguardScrim = win;
1947 break;
1948
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001949 }
Jeff Brown98365d72012-08-19 20:30:52 -07001950 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001951 }
1952
1953 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07001954 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001955 public void removeWindowLw(WindowState win) {
1956 if (mStatusBar == win) {
1957 mStatusBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04001958 mStatusBarController.setWindow(null);
Jim Millerc0b676d2013-03-22 16:11:08 -07001959 mKeyguardDelegate.showScrim();
Jim Miller5ecd8112013-01-09 18:50:26 -08001960 } else if (mKeyguardScrim == win) {
1961 Log.v(TAG, "Removing keyguard scrim");
1962 mKeyguardScrim = null;
1963 } if (mNavigationBar == win) {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04001964 mNavigationBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04001965 mNavigationBarController.setWindow(null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001966 }
1967 }
1968
1969 static final boolean PRINT_ANIM = false;
RoboErik8a2cfc32014-05-16 11:19:38 -07001970
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001971 /** {@inheritDoc} */
Craig Mautner4b71aa12012-12-27 17:20:01 -08001972 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001973 public int selectAnimationLw(WindowState win, int transit) {
1974 if (PRINT_ANIM) Log.i(TAG, "selectAnimation in " + win
1975 + ": transit=" + transit);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001976 if (win == mStatusBar) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001977 boolean isKeyguard = (win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001978 if (transit == TRANSIT_EXIT
1979 || transit == TRANSIT_HIDE) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001980 return isKeyguard ? -1 : R.anim.dock_top_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001981 } else if (transit == TRANSIT_ENTER
1982 || transit == TRANSIT_SHOW) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001983 return isKeyguard ? -1 : R.anim.dock_top_enter;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001984 }
1985 } else if (win == mNavigationBar) {
1986 // This can be on either the bottom or the right.
1987 if (mNavigationBarOnBottom) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08001988 if (transit == TRANSIT_EXIT
1989 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001990 return R.anim.dock_bottom_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001991 } else if (transit == TRANSIT_ENTER
1992 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001993 return R.anim.dock_bottom_enter;
1994 }
1995 } else {
Craig Mautner4b71aa12012-12-27 17:20:01 -08001996 if (transit == TRANSIT_EXIT
1997 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001998 return R.anim.dock_right_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001999 } else if (transit == TRANSIT_ENTER
2000 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002001 return R.anim.dock_right_enter;
2002 }
2003 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08002004 }
2005
2006 if (transit == TRANSIT_PREVIEW_DONE) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002007 if (win.hasAppShownWindows()) {
2008 if (PRINT_ANIM) Log.i(TAG, "**** STARTING EXIT");
2009 return com.android.internal.R.anim.app_starting_exit;
2010 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07002011 } else if (win.getAttrs().type == TYPE_DREAM && mDreamingLockscreen
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002012 && transit == TRANSIT_ENTER) {
2013 // Special case: we are animating in a dream, while the keyguard
2014 // is shown. We don't want an animation on the dream, because
2015 // we need it shown immediately with the keyguard animating away
2016 // to reveal it.
2017 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002018 }
2019
2020 return 0;
2021 }
2022
Craig Mautner3c174372013-02-21 17:54:37 -08002023 @Override
2024 public void selectRotationAnimationLw(int anim[]) {
2025 if (PRINT_ANIM) Slog.i(TAG, "selectRotationAnimation mTopFullscreen="
2026 + mTopFullscreenOpaqueWindowState + " rotationAnimation="
2027 + (mTopFullscreenOpaqueWindowState == null ?
2028 "0" : mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation));
2029 if (mTopFullscreenOpaqueWindowState != null && mTopIsFullscreen) {
2030 switch (mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation) {
2031 case ROTATION_ANIMATION_CROSSFADE:
2032 anim[0] = R.anim.rotation_animation_xfade_exit;
2033 anim[1] = R.anim.rotation_animation_enter;
2034 break;
2035 case ROTATION_ANIMATION_JUMPCUT:
2036 anim[0] = R.anim.rotation_animation_jump_exit;
2037 anim[1] = R.anim.rotation_animation_enter;
2038 break;
2039 case ROTATION_ANIMATION_ROTATE:
2040 default:
2041 anim[0] = anim[1] = 0;
2042 break;
2043 }
2044 } else {
2045 anim[0] = anim[1] = 0;
2046 }
2047 }
2048
2049 @Override
2050 public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId,
2051 boolean forceDefault) {
2052 switch (exitAnimId) {
2053 case R.anim.rotation_animation_xfade_exit:
2054 case R.anim.rotation_animation_jump_exit:
2055 // These are the only cases that matter.
2056 if (forceDefault) {
2057 return false;
2058 }
2059 int anim[] = new int[2];
2060 selectRotationAnimationLw(anim);
2061 return (exitAnimId == anim[0] && enterAnimId == anim[1]);
2062 default:
2063 return true;
2064 }
2065 }
2066
2067 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002068 public Animation createForceHideEnterAnimation(boolean onWallpaper,
2069 boolean goingToNotificationShade) {
2070 if (goingToNotificationShade) {
2071 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_behind_enter_fade_in);
2072 } else if (onWallpaper) {
Jorim Jaggi76a16232014-08-08 17:00:47 +02002073 Animation a = AnimationUtils.loadAnimation(mContext,
2074 R.anim.lock_screen_behind_enter_wallpaper);
2075 AnimationSet set = (AnimationSet) a;
2076
2077 // TODO: Use XML interpolators when we have log interpolators available in XML.
2078 set.getAnimations().get(0).setInterpolator(mLogDecelerateInterpolator);
2079 set.getAnimations().get(1).setInterpolator(mLogDecelerateInterpolator);
Jorim Jaggi76a16232014-08-08 17:00:47 +02002080 return set;
2081 } else {
2082 Animation a = AnimationUtils.loadAnimation(mContext,
2083 R.anim.lock_screen_behind_enter);
2084 AnimationSet set = (AnimationSet) a;
2085
2086 // TODO: Use XML interpolators when we have log interpolators available in XML.
2087 set.getAnimations().get(0).setInterpolator(mLogDecelerateInterpolator);
2088 return set;
2089 }
2090 }
2091
2092
2093 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002094 public Animation createForceHideWallpaperExitAnimation(boolean goingToNotificationShade) {
2095 if (goingToNotificationShade) {
2096 return null;
2097 } else {
2098 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_wallpaper_exit);
2099 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002100 }
John Spurlockc8b46ca2013-04-08 12:59:26 -04002101
2102 private static void awakenDreams() {
2103 IDreamManager dreamManager = getDreamManager();
2104 if (dreamManager != null) {
2105 try {
2106 dreamManager.awaken();
2107 } catch (RemoteException e) {
2108 // fine, stay asleep then
2109 }
2110 }
2111 }
2112
2113 static IDreamManager getDreamManager() {
2114 return IDreamManager.Stub.asInterface(
2115 ServiceManager.checkService(DreamService.DREAM_SERVICE));
2116 }
2117
Santos Cordon9eb45932014-06-27 12:28:43 -07002118 TelecommManager getTelecommService() {
2119 return (TelecommManager) mContext.getSystemService(Context.TELECOMM_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002120 }
2121
Jeff Brown4d396052010-10-29 21:50:21 -07002122 static IAudioService getAudioService() {
2123 IAudioService audioService = IAudioService.Stub.asInterface(
2124 ServiceManager.checkService(Context.AUDIO_SERVICE));
2125 if (audioService == null) {
2126 Log.w(TAG, "Unable to find IAudioService interface.");
2127 }
2128 return audioService;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002129 }
2130
2131 boolean keyguardOn() {
2132 return keyguardIsShowingTq() || inKeyguardRestrictedKeyInputMode();
2133 }
2134
2135 private static final int[] WINDOW_TYPES_WHERE_HOME_DOESNT_WORK = {
2136 WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
2137 WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
2138 };
2139
2140 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002141 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002142 public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002143 final boolean keyguardOn = keyguardOn();
Jeff Brown1f245102010-11-18 20:53:46 -08002144 final int keyCode = event.getKeyCode();
2145 final int repeatCount = event.getRepeatCount();
2146 final int metaState = event.getMetaState();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002147 final int flags = event.getFlags();
Jeff Brown1f245102010-11-18 20:53:46 -08002148 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
2149 final boolean canceled = event.isCanceled();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002150
Jeff Brown40013652012-05-16 21:22:36 -07002151 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002152 Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount="
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002153 + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed
2154 + " canceled=" + canceled);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002155 }
2156
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002157 // If we think we might have a volume down & power key chord on the way
2158 // but we're not sure, then tell the dispatcher to wait a little while and
2159 // try again later before dispatching.
Christopher Tatee90585f2012-03-05 18:56:25 -08002160 if (mScreenshotChordEnabled && (flags & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002161 if (mVolumeDownKeyTriggered && !mPowerKeyTriggered) {
2162 final long now = SystemClock.uptimeMillis();
2163 final long timeoutTime = mVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS;
2164 if (now < timeoutTime) {
2165 return timeoutTime - now;
2166 }
2167 }
2168 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
2169 && mVolumeDownKeyConsumedByScreenshotChord) {
2170 if (!down) {
2171 mVolumeDownKeyConsumedByScreenshotChord = false;
2172 }
2173 return -1;
2174 }
2175 }
2176
Michael Wright6a62e552014-06-03 19:19:48 -07002177 // Cancel any pending meta actions if we see any other keys being pressed between the down
2178 // of the meta key and its corresponding up.
Michael Wright251e35d2014-08-22 15:40:27 -07002179 if (mPendingMetaAction && !KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07002180 mPendingMetaAction = false;
2181 }
2182
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002183 // First we always handle the home key here, so applications
2184 // can never break it, although if keyguard is on, we do let
2185 // it handle it, because that gives us the correct 5 second
2186 // timeout.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002187 if (keyCode == KeyEvent.KEYCODE_HOME) {
Michael Jurka7f2668c2012-03-27 07:49:52 -07002188
Jeff Brown49ed71d2010-12-06 17:13:33 -08002189 // If we have released the home key, and didn't do anything else
2190 // while it was pressed, then it is time to go home!
Michael Jurka7f2668c2012-03-27 07:49:52 -07002191 if (!down) {
Jeff Browncaca8812013-05-09 13:34:33 -07002192 cancelPreloadRecentApps();
2193
Jeff Brown49ed71d2010-12-06 17:13:33 -08002194 mHomePressed = false;
Jeff Browncaca8812013-05-09 13:34:33 -07002195 if (mHomeConsumed) {
2196 mHomeConsumed = false;
Michael Jurka7f2668c2012-03-27 07:49:52 -07002197 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002198 }
Jeff Browncaca8812013-05-09 13:34:33 -07002199
2200 if (canceled) {
2201 Log.i(TAG, "Ignoring HOME; event canceled.");
2202 return -1;
2203 }
2204
2205 // If an incoming call is ringing, HOME is totally disabled.
Santos Cordon9eb45932014-06-27 12:28:43 -07002206 // (The user is already on the InCallUI at this point,
Jeff Browncaca8812013-05-09 13:34:33 -07002207 // and his ONLY options are to answer or reject the call.)
Santos Cordon9eb45932014-06-27 12:28:43 -07002208 TelecommManager telecommManager = getTelecommService();
2209 if (telecommManager != null && telecommManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07002210 Log.i(TAG, "Ignoring HOME; there's a ringing incoming call.");
2211 return -1;
Jeff Browncaca8812013-05-09 13:34:33 -07002212 }
2213
2214 // Delay handling home if a double-tap is possible.
2215 if (mDoubleTapOnHomeBehavior != DOUBLE_TAP_HOME_NOTHING) {
2216 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); // just in case
2217 mHomeDoubleTapPending = true;
2218 mHandler.postDelayed(mHomeDoubleTapTimeoutRunnable,
2219 ViewConfiguration.getDoubleTapTimeout());
2220 return -1;
2221 }
2222
Jose Lima9546b202014-07-02 17:21:51 -07002223 // If there's a dream running then use home to escape the dream
2224 // but don't actually go home.
2225 if (mDreamManagerInternal != null && mDreamManagerInternal.isDreaming()) {
Jeff Brownf6d46682014-07-17 22:44:20 -07002226 mDreamManagerInternal.stopDream(false /*immediate*/);
Jose Lima9546b202014-07-02 17:21:51 -07002227 return -1;
2228 }
2229
Jeff Browncaca8812013-05-09 13:34:33 -07002230 // Go home!
2231 launchHomeFromHotKey();
2232 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002233 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002234
2235 // If a system window has focus, then it doesn't make sense
2236 // right now to interact with applications.
2237 WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null;
2238 if (attrs != null) {
2239 final int type = attrs.type;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002240 if (type == WindowManager.LayoutParams.TYPE_KEYGUARD_SCRIM
2241 || type == WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG
2242 || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002243 // the "app" is keyguard, so give it the key
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002244 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002245 }
2246 final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length;
2247 for (int i=0; i<typeCount; i++) {
2248 if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) {
2249 // don't do anything, but also don't pass it to the app
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002250 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002251 }
2252 }
2253 }
Jeff Browncaca8812013-05-09 13:34:33 -07002254
2255 // Remember that home is pressed and handle special actions.
2256 if (repeatCount == 0) {
2257 mHomePressed = true;
2258 if (mHomeDoubleTapPending) {
2259 mHomeDoubleTapPending = false;
2260 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable);
2261 handleDoubleTapOnHome();
2262 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI
2263 || mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
2264 preloadRecentApps();
Michael Jurka7f2668c2012-03-27 07:49:52 -07002265 }
Jeff Browncaca8812013-05-09 13:34:33 -07002266 } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) {
2267 if (!keyguardOn) {
2268 handleLongPressOnHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002269 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002270 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002271 return -1;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002272 } else if (keyCode == KeyEvent.KEYCODE_MENU) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002273 // Hijack modified menu keys for debugging features
2274 final int chordBug = KeyEvent.META_SHIFT_ON;
2275
2276 if (down && repeatCount == 0) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002277 if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002278 Intent intent = new Intent(Intent.ACTION_BUG_REPORT);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002279 mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT,
2280 null, null, null, 0, null, null);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002281 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002282 } else if (SHOW_PROCESSES_ON_ALT_MENU &&
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002283 (metaState & KeyEvent.META_ALT_ON) == KeyEvent.META_ALT_ON) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002284 Intent service = new Intent();
2285 service.setClassName(mContext, "com.android.server.LoadAverageService");
2286 ContentResolver res = mContext.getContentResolver();
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002287 boolean shown = Settings.Global.getInt(
2288 res, Settings.Global.SHOW_PROCESSES, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002289 if (!shown) {
2290 mContext.startService(service);
2291 } else {
2292 mContext.stopService(service);
2293 }
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002294 Settings.Global.putInt(
2295 res, Settings.Global.SHOW_PROCESSES, shown ? 0 : 1);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002296 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002297 }
2298 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002299 } else if (keyCode == KeyEvent.KEYCODE_SEARCH) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002300 if (down) {
2301 if (repeatCount == 0) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002302 mSearchKeyShortcutPending = true;
2303 mConsumeSearchKeyUp = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002304 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002305 } else {
2306 mSearchKeyShortcutPending = false;
2307 if (mConsumeSearchKeyUp) {
2308 mConsumeSearchKeyUp = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002309 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002310 }
2311 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002312 return 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002313 } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) {
Michael Wrightc9ebea72013-01-16 19:25:02 -08002314 if (!keyguardOn) {
Jeff Browncaca8812013-05-09 13:34:33 -07002315 if (down && repeatCount == 0) {
2316 preloadRecentApps();
2317 } else if (!down) {
2318 toggleRecentApps();
Michael Wrightc9ebea72013-01-16 19:25:02 -08002319 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002320 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002321 return -1;
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002322 } else if (keyCode == KeyEvent.KEYCODE_ASSIST) {
2323 if (down) {
2324 if (repeatCount == 0) {
2325 mAssistKeyLongPressed = false;
2326 } else if (repeatCount == 1) {
2327 mAssistKeyLongPressed = true;
2328 if (!keyguardOn) {
2329 launchAssistLongPressAction();
2330 }
2331 }
2332 } else {
2333 if (mAssistKeyLongPressed) {
2334 mAssistKeyLongPressed = false;
2335 } else {
2336 if (!keyguardOn) {
2337 launchAssistAction();
2338 }
2339 }
2340 }
2341 return -1;
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002342 } else if (keyCode == KeyEvent.KEYCODE_VOICE_ASSIST) {
2343 if (!down) {
2344 Intent voiceIntent;
2345 if (!keyguardOn && mPowerManager.isInteractive()) {
2346 voiceIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
2347 } else {
2348 voiceIntent = new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
2349 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, keyguardOn);
2350 }
2351 mContext.startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
2352 }
Jeff Sharkey2991fa32012-12-05 18:06:43 -08002353 } else if (keyCode == KeyEvent.KEYCODE_SYSRQ) {
2354 if (down && repeatCount == 0) {
2355 mHandler.post(mScreenshotRunnable);
2356 }
2357 return -1;
Michael Wrightb854e242013-02-05 17:54:02 -08002358 } else if (keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP
2359 || keyCode == KeyEvent.KEYCODE_BRIGHTNESS_DOWN) {
2360 if (down) {
2361 int direction = keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP ? 1 : -1;
2362
2363 // Disable autobrightness if it's on
2364 int auto = Settings.System.getIntForUser(
2365 mContext.getContentResolver(),
2366 Settings.System.SCREEN_BRIGHTNESS_MODE,
2367 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2368 UserHandle.USER_CURRENT_OR_SELF);
2369 if (auto != 0) {
2370 Settings.System.putIntForUser(mContext.getContentResolver(),
2371 Settings.System.SCREEN_BRIGHTNESS_MODE,
2372 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2373 UserHandle.USER_CURRENT_OR_SELF);
2374 }
2375
2376 int min = mPowerManager.getMinimumScreenBrightnessSetting();
2377 int max = mPowerManager.getMaximumScreenBrightnessSetting();
2378 int step = (max - min + BRIGHTNESS_STEPS - 1) / BRIGHTNESS_STEPS * direction;
2379 int brightness = Settings.System.getIntForUser(mContext.getContentResolver(),
2380 Settings.System.SCREEN_BRIGHTNESS,
2381 mPowerManager.getDefaultScreenBrightnessSetting(),
2382 UserHandle.USER_CURRENT_OR_SELF);
2383 brightness += step;
2384 // Make sure we don't go beyond the limits.
2385 brightness = Math.min(max, brightness);
2386 brightness = Math.max(min, brightness);
2387
2388 Settings.System.putIntForUser(mContext.getContentResolver(),
2389 Settings.System.SCREEN_BRIGHTNESS, brightness,
2390 UserHandle.USER_CURRENT_OR_SELF);
Alan Viverette5a399492014-07-14 16:19:38 -07002391 mContext.startActivityAsUser(new Intent(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG),
2392 UserHandle.CURRENT_OR_SELF);
Michael Wrightb854e242013-02-05 17:54:02 -08002393 }
2394 return -1;
Michael Wrightce0c13a2014-07-30 10:49:21 -07002395 } else if (KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07002396 if (down) {
2397 mPendingMetaAction = true;
2398 } else if (mPendingMetaAction) {
Michael Wright6a62e552014-06-03 19:19:48 -07002399 launchAssistAction();
2400 }
2401 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002402 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002403
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002404 // Shortcuts are invoked through Search+key, so intercept those here
Jeff Browncaab4d02010-12-09 22:13:41 -08002405 // Any printing key that is chorded with Search should be consumed
2406 // even if no shortcut was invoked. This prevents text from being
2407 // inadvertently inserted when using a keyboard that has built-in macro
2408 // shortcut keys (that emit Search+x) and some of them are not registered.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002409 if (mSearchKeyShortcutPending) {
Jeff Browncaab4d02010-12-09 22:13:41 -08002410 final KeyCharacterMap kcm = event.getKeyCharacterMap();
2411 if (kcm.isPrintingKey(keyCode)) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002412 mConsumeSearchKeyUp = true;
2413 mSearchKeyShortcutPending = false;
Jeff Browncaab4d02010-12-09 22:13:41 -08002414 if (down && repeatCount == 0 && !keyguardOn) {
2415 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState);
2416 if (shortcutIntent != null) {
2417 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002418 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002419 mContext.startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002420 } catch (ActivityNotFoundException ex) {
2421 Slog.w(TAG, "Dropping shortcut key combination because "
2422 + "the activity to which it is registered was not found: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002423 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode), ex);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002424 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002425 } else {
2426 Slog.i(TAG, "Dropping unregistered shortcut key combination: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002427 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002428 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002429 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002430 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002431 }
2432 }
2433
Jeff Brown68b909d2011-12-07 16:36:01 -08002434 // Invoke shortcuts using Meta.
Jeff Brown602ab322012-05-16 13:33:47 -07002435 if (down && repeatCount == 0 && !keyguardOn
Jeff Brown68b909d2011-12-07 16:36:01 -08002436 && (metaState & KeyEvent.META_META_ON) != 0) {
2437 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brown602ab322012-05-16 13:33:47 -07002438 if (kcm.isPrintingKey(keyCode)) {
2439 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode,
2440 metaState & ~(KeyEvent.META_META_ON
2441 | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON));
2442 if (shortcutIntent != null) {
2443 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2444 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002445 mContext.startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brown602ab322012-05-16 13:33:47 -07002446 } catch (ActivityNotFoundException ex) {
2447 Slog.w(TAG, "Dropping shortcut key combination because "
2448 + "the activity to which it is registered was not found: "
2449 + "META+" + KeyEvent.keyCodeToString(keyCode), ex);
2450 }
2451 return -1;
Jeff Brown68b909d2011-12-07 16:36:01 -08002452 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002453 }
2454 }
2455
Jeff Brown6651a632011-11-28 12:59:11 -08002456 // Handle application launch keys.
Jeff Brown602ab322012-05-16 13:33:47 -07002457 if (down && repeatCount == 0 && !keyguardOn) {
Jeff Brown6651a632011-11-28 12:59:11 -08002458 String category = sApplicationLaunchKeyCategories.get(keyCode);
2459 if (category != null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -08002460 Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category);
Jeff Brown6651a632011-11-28 12:59:11 -08002461 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2462 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002463 mContext.startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brown6651a632011-11-28 12:59:11 -08002464 } catch (ActivityNotFoundException ex) {
2465 Slog.w(TAG, "Dropping application launch key because "
2466 + "the activity to which it is registered was not found: "
2467 + "keyCode=" + keyCode + ", category=" + category, ex);
2468 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002469 return -1;
Jeff Brown6651a632011-11-28 12:59:11 -08002470 }
2471 }
2472
Michael Wright61c46752014-08-21 16:57:33 -07002473 // Display task switcher for ALT-TAB.
Jeff Brown68b909d2011-12-07 16:36:01 -08002474 if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_TAB) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002475 if (mRecentAppsHeldModifiers == 0 && !keyguardOn) {
Jeff Brown68b909d2011-12-07 16:36:01 -08002476 final int shiftlessModifiers = event.getModifiers() & ~KeyEvent.META_SHIFT_MASK;
Michael Wright61c46752014-08-21 16:57:33 -07002477 if (KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_ALT_ON)) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002478 mRecentAppsHeldModifiers = shiftlessModifiers;
2479 showRecentApps(true);
Jeff Brown68b909d2011-12-07 16:36:01 -08002480 return -1;
2481 }
2482 }
Winson Chung1e8d71b2014-05-16 17:05:22 -07002483 } else if (!down && mRecentAppsHeldModifiers != 0
2484 && (metaState & mRecentAppsHeldModifiers) == 0) {
2485 mRecentAppsHeldModifiers = 0;
Winson Chungcdcd4872014-08-05 18:00:13 -07002486 hideRecentApps(true, false);
Jeff Brown68b909d2011-12-07 16:36:01 -08002487 }
2488
Jeff Browncf39bdf2012-05-18 14:41:19 -07002489 // Handle keyboard language switching.
2490 if (down && repeatCount == 0
2491 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2492 || (keyCode == KeyEvent.KEYCODE_SPACE
2493 && (metaState & KeyEvent.META_CTRL_MASK) != 0))) {
2494 int direction = (metaState & KeyEvent.META_SHIFT_MASK) != 0 ? -1 : 1;
2495 mWindowManagerFuncs.switchKeyboardLayout(event.getDeviceId(), direction);
2496 return -1;
2497 }
2498 if (mLanguageSwitchKeyPressed && !down
2499 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2500 || keyCode == KeyEvent.KEYCODE_SPACE)) {
2501 mLanguageSwitchKeyPressed = false;
2502 return -1;
2503 }
2504
Justin Kohd378ad72013-04-01 12:18:26 -07002505 if (mGlobalKeyManager.handleGlobalKey(mContext, keyCode, event)) {
2506 return -1;
2507 }
2508
Michael Wright6a62e552014-06-03 19:19:48 -07002509 // Reserve all the META modifier combos for system behavior
Michael Wrightce0c13a2014-07-30 10:49:21 -07002510 if ((metaState & KeyEvent.META_META_ON) != 0) {
Michael Wright6a62e552014-06-03 19:19:48 -07002511 return -1;
2512 }
2513
Jeff Brown68b909d2011-12-07 16:36:01 -08002514 // Let the application handle the key.
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002515 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002516 }
2517
Jeff Brown3915bb82010-11-05 15:02:16 -07002518 /** {@inheritDoc} */
2519 @Override
Jeff Brown49ed71d2010-12-06 17:13:33 -08002520 public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown54875002011-04-06 15:33:01 -07002521 // Note: This method is only called if the initial down was unhandled.
Jeff Brown40013652012-05-16 21:22:36 -07002522 if (DEBUG_INPUT) {
Jeff Brown1f245102010-11-18 20:53:46 -08002523 Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction()
2524 + ", flags=" + event.getFlags()
2525 + ", keyCode=" + event.getKeyCode()
2526 + ", scanCode=" + event.getScanCode()
2527 + ", metaState=" + event.getMetaState()
2528 + ", repeatCount=" + event.getRepeatCount()
2529 + ", policyFlags=" + policyFlags);
Jeff Brown3915bb82010-11-05 15:02:16 -07002530 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002531
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002532 KeyEvent fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002533 if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
2534 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002535 final int keyCode = event.getKeyCode();
2536 final int metaState = event.getMetaState();
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002537 final boolean initialDown = event.getAction() == KeyEvent.ACTION_DOWN
2538 && event.getRepeatCount() == 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002539
Jeff Brown54875002011-04-06 15:33:01 -07002540 // Check for fallback actions specified by the key character map.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002541 final FallbackAction fallbackAction;
2542 if (initialDown) {
2543 fallbackAction = kcm.getFallbackAction(keyCode, metaState);
2544 } else {
2545 fallbackAction = mFallbackActions.get(keyCode);
2546 }
2547
2548 if (fallbackAction != null) {
Jeff Brown40013652012-05-16 21:22:36 -07002549 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002550 Slog.d(TAG, "Fallback: keyCode=" + fallbackAction.keyCode
2551 + " metaState=" + Integer.toHexString(fallbackAction.metaState));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002552 }
2553
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002554 final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK;
2555 fallbackEvent = KeyEvent.obtain(
Jeff Brown49ed71d2010-12-06 17:13:33 -08002556 event.getDownTime(), event.getEventTime(),
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002557 event.getAction(), fallbackAction.keyCode,
2558 event.getRepeatCount(), fallbackAction.metaState,
Jeff Brown49ed71d2010-12-06 17:13:33 -08002559 event.getDeviceId(), event.getScanCode(),
2560 flags, event.getSource(), null);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002561
2562 if (!interceptFallback(win, fallbackEvent, policyFlags)) {
2563 fallbackEvent.recycle();
2564 fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002565 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002566
2567 if (initialDown) {
2568 mFallbackActions.put(keyCode, fallbackAction);
2569 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2570 mFallbackActions.remove(keyCode);
2571 fallbackAction.recycle();
2572 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002573 }
2574 }
2575
Jeff Brown40013652012-05-16 21:22:36 -07002576 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002577 if (fallbackEvent == null) {
2578 Slog.d(TAG, "No fallback.");
2579 } else {
2580 Slog.d(TAG, "Performing fallback: " + fallbackEvent);
2581 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002582 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002583 return fallbackEvent;
Jeff Brown3915bb82010-11-05 15:02:16 -07002584 }
2585
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002586 private boolean interceptFallback(WindowState win, KeyEvent fallbackEvent, int policyFlags) {
Jeff Brown037c33e2014-04-09 00:31:55 -07002587 int actions = interceptKeyBeforeQueueing(fallbackEvent, policyFlags);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002588 if ((actions & ACTION_PASS_TO_USER) != 0) {
2589 long delayMillis = interceptKeyBeforeDispatching(
2590 win, fallbackEvent, policyFlags);
2591 if (delayMillis == 0) {
2592 return true;
2593 }
2594 }
2595 return false;
Jeff Brown6f2fba42011-02-19 01:08:02 -08002596 }
2597
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002598 private void launchAssistLongPressAction() {
2599 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
2600 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
2601
2602 // launch the search activity
2603 Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS);
2604 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2605 try {
RoboErik8a2cfc32014-05-16 11:19:38 -07002606 // TODO: This only stops the factory-installed search manager.
Jim Miller45308b12012-06-18 19:23:39 -07002607 // Need to formalize an API to handle others
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002608 SearchManager searchManager = getSearchManager();
2609 if (searchManager != null) {
2610 searchManager.stopSearch();
2611 }
Michael Wright43e27f72013-04-10 14:06:48 -07002612 mContext.startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002613 } catch (ActivityNotFoundException e) {
2614 Slog.w(TAG, "No activity to handle assist long press action.", e);
2615 }
2616 }
2617
2618 private void launchAssistAction() {
2619 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
Amith Yamasanic1d07a42012-08-14 09:32:02 -07002620 Intent intent = ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE))
Dianne Hackbornf9c5e0f2013-01-23 14:39:13 -08002621 .getAssistIntent(mContext, true, UserHandle.USER_CURRENT);
Jim Miller45308b12012-06-18 19:23:39 -07002622 if (intent != null) {
2623 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
2624 | Intent.FLAG_ACTIVITY_SINGLE_TOP
2625 | Intent.FLAG_ACTIVITY_CLEAR_TOP);
2626 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002627 mContext.startActivityAsUser(intent, UserHandle.CURRENT);
Jim Miller45308b12012-06-18 19:23:39 -07002628 } catch (ActivityNotFoundException e) {
2629 Slog.w(TAG, "No activity to handle assist action.", e);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002630 }
2631 }
2632 }
2633
2634 private SearchManager getSearchManager() {
2635 if (mSearchManager == null) {
2636 mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
2637 }
2638 return mSearchManager;
2639 }
2640
Jeff Browncaca8812013-05-09 13:34:33 -07002641 private void preloadRecentApps() {
2642 mPreloadedRecentApps = true;
2643 try {
2644 IStatusBarService statusbar = getStatusBarService();
2645 if (statusbar != null) {
2646 statusbar.preloadRecentApps();
2647 }
2648 } catch (RemoteException e) {
2649 Slog.e(TAG, "RemoteException when preloading recent apps", e);
2650 // re-acquire status bar service next time it is needed.
2651 mStatusBarService = null;
2652 }
2653 }
2654
2655 private void cancelPreloadRecentApps() {
2656 if (mPreloadedRecentApps) {
2657 mPreloadedRecentApps = false;
2658 try {
2659 IStatusBarService statusbar = getStatusBarService();
2660 if (statusbar != null) {
2661 statusbar.cancelPreloadRecentApps();
2662 }
2663 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002664 Slog.e(TAG, "RemoteException when cancelling recent apps preload", e);
Jeff Browncaca8812013-05-09 13:34:33 -07002665 // re-acquire status bar service next time it is needed.
2666 mStatusBarService = null;
2667 }
2668 }
2669 }
2670
2671 private void toggleRecentApps() {
2672 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
Jeff Browncaca8812013-05-09 13:34:33 -07002673 try {
2674 IStatusBarService statusbar = getStatusBarService();
2675 if (statusbar != null) {
2676 statusbar.toggleRecentApps();
2677 }
2678 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002679 Slog.e(TAG, "RemoteException when toggling recent apps", e);
2680 // re-acquire status bar service next time it is needed.
2681 mStatusBarService = null;
2682 }
2683 }
2684
Craig Mautner84984fa2014-06-19 11:19:20 -07002685 @Override
2686 public void showRecentApps() {
2687 mHandler.removeMessages(MSG_DISPATCH_SHOW_RECENTS);
2688 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_RECENTS);
2689 }
2690
Winson Chung1e8d71b2014-05-16 17:05:22 -07002691 private void showRecentApps(boolean triggeredFromAltTab) {
2692 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
2693 try {
2694 IStatusBarService statusbar = getStatusBarService();
2695 if (statusbar != null) {
2696 statusbar.showRecentApps(triggeredFromAltTab);
2697 }
2698 } catch (RemoteException e) {
Jeff Browncaca8812013-05-09 13:34:33 -07002699 Slog.e(TAG, "RemoteException when showing recent apps", e);
2700 // re-acquire status bar service next time it is needed.
2701 mStatusBarService = null;
2702 }
2703 }
2704
Winson Chungcdcd4872014-08-05 18:00:13 -07002705 private void hideRecentApps(boolean triggeredFromAltTab, boolean triggeredFromHome) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002706 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
2707 try {
2708 IStatusBarService statusbar = getStatusBarService();
2709 if (statusbar != null) {
Winson Chungcdcd4872014-08-05 18:00:13 -07002710 statusbar.hideRecentApps(triggeredFromAltTab, triggeredFromHome);
Winson Chung1e8d71b2014-05-16 17:05:22 -07002711 }
2712 } catch (RemoteException e) {
2713 Slog.e(TAG, "RemoteException when closing recent apps", e);
2714 // re-acquire status bar service next time it is needed.
2715 mStatusBarService = null;
2716 }
2717 }
2718
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002719 /**
2720 * A home key -> launch home action was detected. Take the appropriate action
2721 * given the situation with the keyguard.
2722 */
2723 void launchHomeFromHotKey() {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01002724 if (mKeyguardDelegate != null && mKeyguardDelegate.isShowingAndNotOccluded()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002725 // don't launch home if keyguard showing
Jim Miller5ecd8112013-01-09 18:50:26 -08002726 } else if (!mHideLockScreen && mKeyguardDelegate.isInputRestricted()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002727 // when in keyguard restricted mode, must first verify unlock
2728 // before launching home
Jim Miller5ecd8112013-01-09 18:50:26 -08002729 mKeyguardDelegate.verifyUnlock(new OnKeyguardExitResult() {
Jose Lima9546b202014-07-02 17:21:51 -07002730 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002731 public void onKeyguardExitResult(boolean success) {
2732 if (success) {
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07002733 try {
2734 ActivityManagerNative.getDefault().stopAppSwitches();
2735 } catch (RemoteException e) {
2736 }
Joe Onoratof275f0c2009-11-24 16:11:13 -05002737 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07002738 startDockOrHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002739 }
2740 }
2741 });
2742 } else {
2743 // no keyguard stuff to worry about, just launch home!
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07002744 try {
2745 ActivityManagerNative.getDefault().stopAppSwitches();
2746 } catch (RemoteException e) {
2747 }
Winson Chungd543c1b2014-06-23 15:06:45 -07002748 if (mRecentsVisible) {
2749 // Hide Recents and notify it to launch Home
2750 awakenDreams();
2751 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
Winson Chungcdcd4872014-08-05 18:00:13 -07002752 hideRecentApps(false, true);
Winson Chungd543c1b2014-06-23 15:06:45 -07002753 } else {
2754 // Otherwise, just launch Home
2755 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
2756 startDockOrHome();
2757 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002758 }
2759 }
2760
John Spurlock04db1762013-05-13 12:46:41 -04002761 private final Runnable mClearHideNavigationFlag = new Runnable() {
2762 @Override
2763 public void run() {
2764 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
2765 // Clear flags.
2766 mForceClearedSystemUiFlags &=
2767 ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
2768 }
2769 mWindowManagerFuncs.reevaluateStatusBarVisibility();
Dianne Hackborne26ab702011-10-16 13:21:33 -07002770 }
2771 };
2772
2773 /**
2774 * Input handler used while nav bar is hidden. Captures any touch on the screen,
2775 * to determine when the nav bar should be shown and prevent applications from
2776 * receiving those touches.
2777 */
Jeff Brown32cbc38552011-12-01 14:01:49 -08002778 final class HideNavInputEventReceiver extends InputEventReceiver {
2779 public HideNavInputEventReceiver(InputChannel inputChannel, Looper looper) {
2780 super(inputChannel, looper);
2781 }
2782
Dianne Hackborndf89e652011-10-06 22:35:11 -07002783 @Override
Jeff Brown32cbc38552011-12-01 14:01:49 -08002784 public void onInputEvent(InputEvent event) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07002785 boolean handled = false;
2786 try {
Jeff Brown4952dfd2011-11-30 19:23:22 -08002787 if (event instanceof MotionEvent
2788 && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
2789 final MotionEvent motionEvent = (MotionEvent)event;
2790 if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07002791 // When the user taps down, we re-show the nav bar.
2792 boolean changed = false;
John Spurlock04db1762013-05-13 12:46:41 -04002793 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002794 // Any user activity always causes us to show the
2795 // navigation controls, if they had been hidden.
2796 // We also clear the low profile and only content
2797 // flags so that tapping on the screen will atomically
2798 // restore all currently hidden screen decorations.
2799 int newVal = mResettingSystemUiFlags |
2800 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
2801 View.SYSTEM_UI_FLAG_LOW_PROFILE |
2802 View.SYSTEM_UI_FLAG_FULLSCREEN;
Dianne Hackborne26ab702011-10-16 13:21:33 -07002803 if (mResettingSystemUiFlags != newVal) {
2804 mResettingSystemUiFlags = newVal;
Dianne Hackborndf89e652011-10-06 22:35:11 -07002805 changed = true;
2806 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07002807 // We don't allow the system's nav bar to be hidden
2808 // again for 1 second, to prevent applications from
2809 // spamming us and keeping it from being shown.
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002810 newVal = mForceClearedSystemUiFlags |
2811 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
Dianne Hackborne26ab702011-10-16 13:21:33 -07002812 if (mForceClearedSystemUiFlags != newVal) {
2813 mForceClearedSystemUiFlags = newVal;
2814 changed = true;
John Spurlock04db1762013-05-13 12:46:41 -04002815 mHandler.postDelayed(mClearHideNavigationFlag, 1000);
Dianne Hackborne26ab702011-10-16 13:21:33 -07002816 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07002817 }
2818 if (changed) {
2819 mWindowManagerFuncs.reevaluateStatusBarVisibility();
2820 }
2821 }
2822 }
2823 } finally {
Jeff Brown32cbc38552011-12-01 14:01:49 -08002824 finishInputEvent(event, handled);
Dianne Hackborndf89e652011-10-06 22:35:11 -07002825 }
2826 }
Jeff Brown32cbc38552011-12-01 14:01:49 -08002827 }
2828 final InputEventReceiver.Factory mHideNavInputEventReceiverFactory =
2829 new InputEventReceiver.Factory() {
2830 @Override
2831 public InputEventReceiver createInputEventReceiver(
2832 InputChannel inputChannel, Looper looper) {
2833 return new HideNavInputEventReceiver(inputChannel, looper);
2834 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07002835 };
2836
2837 @Override
2838 public int adjustSystemUiVisibilityLw(int visibility) {
John Spurlock5b9145b2013-08-20 15:13:47 -04002839 mStatusBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
2840 mNavigationBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
Winson Chungd42a6cf2014-06-03 16:24:04 -07002841 mRecentsVisible = (visibility & View.RECENT_APPS_VISIBLE) > 0;
John Spurlock27735a42013-08-14 17:57:38 -04002842
Dianne Hackborndf89e652011-10-06 22:35:11 -07002843 // Reset any bits in mForceClearingStatusBarVisibility that
2844 // are now clear.
Dianne Hackborne26ab702011-10-16 13:21:33 -07002845 mResettingSystemUiFlags &= visibility;
Dianne Hackborndf89e652011-10-06 22:35:11 -07002846 // Clear any bits in the new visibility that are currently being
2847 // force cleared, before reporting it.
Dianne Hackborne26ab702011-10-16 13:21:33 -07002848 return visibility & ~mResettingSystemUiFlags
2849 & ~mForceClearedSystemUiFlags;
Dianne Hackborndf89e652011-10-06 22:35:11 -07002850 }
2851
Craig Mautner69b08182012-09-05 13:07:13 -07002852 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002853 public void getContentInsetHintLw(WindowManager.LayoutParams attrs, Rect contentInset) {
John Spurlockc6d1c602014-01-17 15:22:06 -05002854 final int fl = PolicyControl.getWindowFlags(null, attrs);
John Spurlock1db8b682014-02-18 11:18:59 -05002855 final int sysuiVis = PolicyControl.getSystemUiVisibility(null, attrs);
2856 final int systemUiVisibility = (sysuiVis | attrs.subtreeSystemUiVisibility);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002857
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002858 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002859 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002860 int availRight, availBottom;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07002861 if (canHideNavigationBar() &&
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002862 (systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002863 availRight = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
2864 availBottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
2865 } else {
2866 availRight = mRestrictedScreenLeft + mRestrictedScreenWidth;
2867 availBottom = mRestrictedScreenTop + mRestrictedScreenHeight;
2868 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002869 if ((systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
2870 if ((fl & FLAG_FULLSCREEN) != 0) {
2871 contentInset.set(mStableFullscreenLeft, mStableFullscreenTop,
2872 availRight - mStableFullscreenRight,
2873 availBottom - mStableFullscreenBottom);
2874 } else {
2875 contentInset.set(mStableLeft, mStableTop,
2876 availRight - mStableRight, availBottom - mStableBottom);
2877 }
Dianne Hackbornc652de82013-02-15 16:32:56 -08002878 } else if ((fl & FLAG_FULLSCREEN) != 0 || (fl & FLAG_LAYOUT_IN_OVERSCAN) != 0) {
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002879 contentInset.setEmpty();
2880 } else if ((systemUiVisibility & (View.SYSTEM_UI_FLAG_FULLSCREEN
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002881 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)) == 0) {
2882 contentInset.set(mCurLeft, mCurTop,
2883 availRight - mCurRight, availBottom - mCurBottom);
2884 } else {
2885 contentInset.set(mCurLeft, mCurTop,
2886 availRight - mCurRight, availBottom - mCurBottom);
2887 }
2888 return;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002889 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002890 contentInset.setEmpty();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002891 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002892
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002893 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07002894 @Override
2895 public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight,
2896 int displayRotation) {
Dianne Hackbornc652de82013-02-15 16:32:56 -08002897 final int overscanLeft, overscanTop, overscanRight, overscanBottom;
2898 if (isDefaultDisplay) {
2899 switch (displayRotation) {
2900 case Surface.ROTATION_90:
2901 overscanLeft = mOverscanTop;
2902 overscanTop = mOverscanRight;
2903 overscanRight = mOverscanBottom;
2904 overscanBottom = mOverscanLeft;
2905 break;
2906 case Surface.ROTATION_180:
2907 overscanLeft = mOverscanRight;
2908 overscanTop = mOverscanBottom;
2909 overscanRight = mOverscanLeft;
2910 overscanBottom = mOverscanTop;
2911 break;
2912 case Surface.ROTATION_270:
2913 overscanLeft = mOverscanBottom;
2914 overscanTop = mOverscanLeft;
2915 overscanRight = mOverscanTop;
2916 overscanBottom = mOverscanRight;
2917 break;
2918 default:
2919 overscanLeft = mOverscanLeft;
2920 overscanTop = mOverscanTop;
2921 overscanRight = mOverscanRight;
2922 overscanBottom = mOverscanBottom;
2923 break;
2924 }
2925 } else {
2926 overscanLeft = 0;
2927 overscanTop = 0;
2928 overscanRight = 0;
2929 overscanBottom = 0;
2930 }
Dianne Hackborn313440842013-02-19 19:22:59 -08002931 mOverscanScreenLeft = mRestrictedOverscanScreenLeft = 0;
2932 mOverscanScreenTop = mRestrictedOverscanScreenTop = 0;
2933 mOverscanScreenWidth = mRestrictedOverscanScreenWidth = displayWidth;
2934 mOverscanScreenHeight = mRestrictedOverscanScreenHeight = displayHeight;
Dianne Hackbornc652de82013-02-15 16:32:56 -08002935 mSystemLeft = 0;
2936 mSystemTop = 0;
2937 mSystemRight = displayWidth;
2938 mSystemBottom = displayHeight;
2939 mUnrestrictedScreenLeft = overscanLeft;
2940 mUnrestrictedScreenTop = overscanTop;
2941 mUnrestrictedScreenWidth = displayWidth - overscanLeft - overscanRight;
2942 mUnrestrictedScreenHeight = displayHeight - overscanTop - overscanBottom;
2943 mRestrictedScreenLeft = mUnrestrictedScreenLeft;
2944 mRestrictedScreenTop = mUnrestrictedScreenTop;
John Spurlockad3e6cb2013-04-30 08:47:43 -04002945 mRestrictedScreenWidth = mSystemGestures.screenWidth = mUnrestrictedScreenWidth;
2946 mRestrictedScreenHeight = mSystemGestures.screenHeight = mUnrestrictedScreenHeight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002947 mDockLeft = mContentLeft = mVoiceContentLeft = mStableLeft = mStableFullscreenLeft
Dianne Hackbornc652de82013-02-15 16:32:56 -08002948 = mCurLeft = mUnrestrictedScreenLeft;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002949 mDockTop = mContentTop = mVoiceContentTop = mStableTop = mStableFullscreenTop
Dianne Hackbornc652de82013-02-15 16:32:56 -08002950 = mCurTop = mUnrestrictedScreenTop;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002951 mDockRight = mContentRight = mVoiceContentRight = mStableRight = mStableFullscreenRight
Dianne Hackbornc652de82013-02-15 16:32:56 -08002952 = mCurRight = displayWidth - overscanRight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002953 mDockBottom = mContentBottom = mVoiceContentBottom = mStableBottom = mStableFullscreenBottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08002954 = mCurBottom = displayHeight - overscanBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002955 mDockLayer = 0x10000000;
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002956 mStatusBarLayer = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002957
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002958 // start with the current dock rect, which will be (0,0,displayWidth,displayHeight)
2959 final Rect pf = mTmpParentFrame;
2960 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002961 final Rect of = mTmpOverscanFrame;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002962 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04002963 final Rect dcf = mTmpDecorFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002964 pf.left = df.left = of.left = vf.left = mDockLeft;
2965 pf.top = df.top = of.top = vf.top = mDockTop;
2966 pf.right = df.right = of.right = vf.right = mDockRight;
2967 pf.bottom = df.bottom = of.bottom = vf.bottom = mDockBottom;
John Spurlock46646232013-09-30 22:32:42 -04002968 dcf.setEmpty(); // Decor frame N/A for system bars.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002969
Craig Mautner69b08182012-09-05 13:07:13 -07002970 if (isDefaultDisplay) {
2971 // For purposes of putting out fake window up to steal focus, we will
2972 // drive nav being hidden only by whether it is requested.
John Spurlocke1f366f2013-08-05 12:22:40 -04002973 final int sysui = mLastSystemUiFlags;
2974 boolean navVisible = (sysui & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0;
Adrian Roosea562512014-05-05 13:33:03 +02002975 boolean navTranslucent = (sysui
2976 & (View.NAVIGATION_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04002977 boolean immersive = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
2978 boolean immersiveSticky = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
2979 boolean navAllowedHidden = immersive || immersiveSticky;
2980 navTranslucent &= !immersiveSticky; // transient trumps translucent
Adrian Roos4fb3ee32014-08-22 19:29:09 +02002981 boolean isKeyguardShowing = isStatusBarKeyguard() && !mHideLockScreen;
2982 if (!isKeyguardShowing) {
2983 navTranslucent &= areTranslucentBarsAllowed();
2984 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07002985
Craig Mautner69b08182012-09-05 13:07:13 -07002986 // When the navigation bar isn't visible, we put up a fake
2987 // input window to catch all touch events. This way we can
2988 // detect when the user presses anywhere to bring back the nav
2989 // bar and ensure the application doesn't see the event.
John Spurlockf1a36642013-10-12 17:50:42 -04002990 if (navVisible || navAllowedHidden) {
Craig Mautner69b08182012-09-05 13:07:13 -07002991 if (mHideNavFakeWindow != null) {
2992 mHideNavFakeWindow.dismiss();
2993 mHideNavFakeWindow = null;
2994 }
2995 } else if (mHideNavFakeWindow == null) {
2996 mHideNavFakeWindow = mWindowManagerFuncs.addFakeWindow(
2997 mHandler.getLooper(), mHideNavInputEventReceiverFactory,
Adam Lesinski95c42972013-10-02 10:13:27 -07002998 "hidden nav", WindowManager.LayoutParams.TYPE_HIDDEN_NAV_CONSUMER, 0,
Craig Mautner69b08182012-09-05 13:07:13 -07002999 0, false, false, true);
Dianne Hackborne26ab702011-10-16 13:21:33 -07003000 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003001
Craig Mautner69b08182012-09-05 13:07:13 -07003002 // For purposes of positioning and showing the nav bar, if we have
3003 // decided that it can't be hidden (because of the screen aspect ratio),
3004 // then take that into account.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003005 navVisible |= !canHideNavigationBar();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003006
John Spurlockad3e6cb2013-04-30 08:47:43 -04003007 boolean updateSysUiVisibility = false;
Craig Mautner69b08182012-09-05 13:07:13 -07003008 if (mNavigationBar != null) {
John Spurlock27735a42013-08-14 17:57:38 -04003009 boolean transientNavBarShowing = mNavigationBarController.isTransientShowing();
Craig Mautner69b08182012-09-05 13:07:13 -07003010 // Force the navigation bar to its appropriate place and
3011 // size. We need to do this directly, instead of relying on
3012 // it to bubble up from the nav bar, because this needs to
3013 // change atomically with screen rotations.
3014 mNavigationBarOnBottom = (!mNavigationBarCanMove || displayWidth < displayHeight);
3015 if (mNavigationBarOnBottom) {
3016 // It's a system nav bar or a portrait screen; nav bar goes on bottom.
Dianne Hackbornc652de82013-02-15 16:32:56 -08003017 int top = displayHeight - overscanBottom
3018 - mNavigationBarHeightForRotation[displayRotation];
3019 mTmpNavigationFrame.set(0, top, displayWidth, displayHeight - overscanBottom);
Craig Mautner69b08182012-09-05 13:07:13 -07003020 mStableBottom = mStableFullscreenBottom = mTmpNavigationFrame.top;
John Spurlockf95b89a2013-10-10 22:10:42 -04003021 if (transientNavBarShowing) {
John Spurlock27735a42013-08-14 17:57:38 -04003022 mNavigationBarController.setBarShowingLw(true);
John Spurlockad3e6cb2013-04-30 08:47:43 -04003023 } else if (navVisible) {
John Spurlock27735a42013-08-14 17:57:38 -04003024 mNavigationBarController.setBarShowingLw(true);
Craig Mautner69b08182012-09-05 13:07:13 -07003025 mDockBottom = mTmpNavigationFrame.top;
Dianne Hackborn313440842013-02-19 19:22:59 -08003026 mRestrictedScreenHeight = mDockBottom - mRestrictedScreenTop;
3027 mRestrictedOverscanScreenHeight = mDockBottom - mRestrictedOverscanScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07003028 } else {
3029 // We currently want to hide the navigation UI.
John Spurlock27735a42013-08-14 17:57:38 -04003030 mNavigationBarController.setBarShowingLw(false);
Craig Mautner69b08182012-09-05 13:07:13 -07003031 }
John Spurlockc6d1c602014-01-17 15:22:06 -05003032 if (navVisible && !navTranslucent && !navAllowedHidden
3033 && !mNavigationBar.isAnimatingLw()
John Spurlockbd957402013-10-03 11:38:39 -04003034 && !mNavigationBarController.wasRecentlyTranslucent()) {
John Spurlocke1f366f2013-08-05 12:22:40 -04003035 // If the opaque nav bar is currently requested to be visible,
Craig Mautner69b08182012-09-05 13:07:13 -07003036 // and not in the process of animating on or off, then
3037 // we can tell the app that it is covered by it.
3038 mSystemBottom = mTmpNavigationFrame.top;
3039 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003040 } else {
Craig Mautner69b08182012-09-05 13:07:13 -07003041 // Landscape screen; nav bar goes to the right.
Dianne Hackbornc652de82013-02-15 16:32:56 -08003042 int left = displayWidth - overscanRight
3043 - mNavigationBarWidthForRotation[displayRotation];
3044 mTmpNavigationFrame.set(left, 0, displayWidth - overscanRight, displayHeight);
Craig Mautner69b08182012-09-05 13:07:13 -07003045 mStableRight = mStableFullscreenRight = mTmpNavigationFrame.left;
John Spurlockf95b89a2013-10-10 22:10:42 -04003046 if (transientNavBarShowing) {
John Spurlock27735a42013-08-14 17:57:38 -04003047 mNavigationBarController.setBarShowingLw(true);
John Spurlockad3e6cb2013-04-30 08:47:43 -04003048 } else if (navVisible) {
John Spurlock27735a42013-08-14 17:57:38 -04003049 mNavigationBarController.setBarShowingLw(true);
Craig Mautner69b08182012-09-05 13:07:13 -07003050 mDockRight = mTmpNavigationFrame.left;
Dianne Hackborn313440842013-02-19 19:22:59 -08003051 mRestrictedScreenWidth = mDockRight - mRestrictedScreenLeft;
3052 mRestrictedOverscanScreenWidth = mDockRight - mRestrictedOverscanScreenLeft;
Craig Mautner69b08182012-09-05 13:07:13 -07003053 } else {
3054 // We currently want to hide the navigation UI.
John Spurlock27735a42013-08-14 17:57:38 -04003055 mNavigationBarController.setBarShowingLw(false);
Craig Mautner69b08182012-09-05 13:07:13 -07003056 }
John Spurlockbd957402013-10-03 11:38:39 -04003057 if (navVisible && !navTranslucent && !mNavigationBar.isAnimatingLw()
3058 && !mNavigationBarController.wasRecentlyTranslucent()) {
Craig Mautner69b08182012-09-05 13:07:13 -07003059 // If the nav bar is currently requested to be visible,
3060 // and not in the process of animating on or off, then
3061 // we can tell the app that it is covered by it.
3062 mSystemRight = mTmpNavigationFrame.left;
3063 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003064 }
Craig Mautner69b08182012-09-05 13:07:13 -07003065 // Make sure the content and current rectangles are updated to
3066 // account for the restrictions from the navigation bar.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003067 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3068 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3069 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3070 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
Craig Mautner69b08182012-09-05 13:07:13 -07003071 mStatusBarLayer = mNavigationBar.getSurfaceLayer();
3072 // And compute the final frame.
3073 mNavigationBar.computeFrameLw(mTmpNavigationFrame, mTmpNavigationFrame,
Adrian Roosfa104232014-06-20 16:10:14 -07003074 mTmpNavigationFrame, mTmpNavigationFrame, mTmpNavigationFrame, dcf,
3075 mTmpNavigationFrame);
Craig Mautnereda67292013-04-28 13:50:14 -07003076 if (DEBUG_LAYOUT) Slog.i(TAG, "mNavigationBar frame: " + mTmpNavigationFrame);
John Spurlock27735a42013-08-14 17:57:38 -04003077 if (mNavigationBarController.checkHiddenLw()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04003078 updateSysUiVisibility = true;
3079 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003080 }
Craig Mautnereda67292013-04-28 13:50:14 -07003081 if (DEBUG_LAYOUT) Slog.i(TAG, String.format("mDock rect: (%d,%d - %d,%d)",
Craig Mautner69b08182012-09-05 13:07:13 -07003082 mDockLeft, mDockTop, mDockRight, mDockBottom));
3083
3084 // decide where the status bar goes ahead of time
3085 if (mStatusBar != null) {
3086 // apply any navigation bar insets
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003087 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3088 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3089 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
3090 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight
3091 + mUnrestrictedScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07003092 vf.left = mStableLeft;
3093 vf.top = mStableTop;
3094 vf.right = mStableRight;
3095 vf.bottom = mStableBottom;
3096
3097 mStatusBarLayer = mStatusBar.getSurfaceLayer();
3098
3099 // Let the status bar determine its size.
Adrian Roosfa104232014-06-20 16:10:14 -07003100 mStatusBar.computeFrameLw(pf, df, vf, vf, vf, dcf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07003101
3102 // For layout, the status bar is always at the top with our fixed height.
3103 mStableTop = mUnrestrictedScreenTop + mStatusBarHeight;
3104
John Spurlocke1f366f2013-08-05 12:22:40 -04003105 boolean statusBarTransient = (sysui & View.STATUS_BAR_TRANSIENT) != 0;
Adrian Roosea562512014-05-05 13:33:03 +02003106 boolean statusBarTranslucent = (sysui
3107 & (View.STATUS_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0;
Adrian Roos4fb3ee32014-08-22 19:29:09 +02003108 if (!isKeyguardShowing) {
3109 statusBarTranslucent &= areTranslucentBarsAllowed();
3110 }
John Spurlock32beb2c2013-03-11 10:16:47 -04003111
Craig Mautner69b08182012-09-05 13:07:13 -07003112 // If the status bar is hidden, we don't want to cause
3113 // windows behind it to scroll.
John Spurlockeda1f692013-09-16 11:38:44 -04003114 if (mStatusBar.isVisibleLw() && !statusBarTransient) {
Craig Mautner69b08182012-09-05 13:07:13 -07003115 // Status bar may go away, so the screen area it occupies
3116 // is available to apps but just covering them when the
3117 // status bar is visible.
3118 mDockTop = mUnrestrictedScreenTop + mStatusBarHeight;
3119
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003120 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3121 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3122 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3123 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
Craig Mautner69b08182012-09-05 13:07:13 -07003124
Craig Mautnereda67292013-04-28 13:50:14 -07003125 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar: " +
Craig Mautner69b08182012-09-05 13:07:13 -07003126 String.format(
3127 "dock=[%d,%d][%d,%d] content=[%d,%d][%d,%d] cur=[%d,%d][%d,%d]",
3128 mDockLeft, mDockTop, mDockRight, mDockBottom,
3129 mContentLeft, mContentTop, mContentRight, mContentBottom,
3130 mCurLeft, mCurTop, mCurRight, mCurBottom));
3131 }
John Spurlocke1f366f2013-08-05 12:22:40 -04003132 if (mStatusBar.isVisibleLw() && !mStatusBar.isAnimatingLw()
John Spurlockbd957402013-10-03 11:38:39 -04003133 && !statusBarTransient && !statusBarTranslucent
3134 && !mStatusBarController.wasRecentlyTranslucent()) {
John Spurlocke1f366f2013-08-05 12:22:40 -04003135 // If the opaque status bar is currently requested to be visible,
Craig Mautner69b08182012-09-05 13:07:13 -07003136 // and not in the process of animating on or off, then
3137 // we can tell the app that it is covered by it.
3138 mSystemTop = mUnrestrictedScreenTop + mStatusBarHeight;
3139 }
John Spurlock27735a42013-08-14 17:57:38 -04003140 if (mStatusBarController.checkHiddenLw()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04003141 updateSysUiVisibility = true;
John Spurlock32beb2c2013-03-11 10:16:47 -04003142 }
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003143 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04003144 if (updateSysUiVisibility) {
3145 updateSystemUiVisibilityLw();
3146 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003147 }
3148 }
3149
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003150 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07003151 @Override
John Spurlock46646232013-09-30 22:32:42 -04003152 public int getSystemDecorLayerLw() {
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003153 if (mStatusBar != null) return mStatusBar.getSurfaceLayer();
3154 if (mNavigationBar != null) return mNavigationBar.getSurfaceLayer();
3155 return 0;
3156 }
3157
Craig Mautner967212c2013-04-13 21:10:58 -07003158 @Override
3159 public void getContentRectLw(Rect r) {
3160 r.set(mContentLeft, mContentTop, mContentRight, mContentBottom);
3161 }
3162
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003163 void setAttachedWindowFrames(WindowState win, int fl, int adjust, WindowState attached,
3164 boolean insetDecors, Rect pf, Rect df, Rect of, Rect cf, Rect vf) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003165 if (win.getSurfaceLayer() > mDockLayer && attached.getSurfaceLayer() < mDockLayer) {
3166 // Here's a special case: if this attached window is a panel that is
3167 // above the dock window, and the window it is attached to is below
3168 // the dock window, then the frames we computed for the window it is
3169 // attached to can not be used because the dock is effectively part
3170 // of the underlying window and the attached window is floating on top
3171 // of the whole thing. So, we ignore the attached window and explicitly
3172 // compute the frames that would be appropriate without the dock.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003173 df.left = of.left = cf.left = vf.left = mDockLeft;
3174 df.top = of.top = cf.top = vf.top = mDockTop;
3175 df.right = of.right = cf.right = vf.right = mDockRight;
3176 df.bottom = of.bottom = cf.bottom = vf.bottom = mDockBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003177 } else {
3178 // The effective display frame of the attached window depends on
3179 // whether it is taking care of insetting its content. If not,
3180 // we need to use the parent's content frame so that the entire
3181 // window is positioned within that content. Otherwise we can use
3182 // the display frame and let the attached window take care of
3183 // positioning its content appropriately.
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003184 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003185 cf.set(attached.getOverscanFrameLw());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003186 } else {
3187 // If the window is resizing, then we want to base the content
3188 // frame on our attached content frame to resize... however,
3189 // things can be tricky if the attached window is NOT in resize
3190 // mode, in which case its content frame will be larger.
3191 // Ungh. So to deal with that, make sure the content frame
3192 // we end up using is not covering the IM dock.
3193 cf.set(attached.getContentFrameLw());
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003194 if (attached.isVoiceInteraction()) {
3195 if (cf.left < mVoiceContentLeft) cf.left = mVoiceContentLeft;
3196 if (cf.top < mVoiceContentTop) cf.top = mVoiceContentTop;
3197 if (cf.right > mVoiceContentRight) cf.right = mVoiceContentRight;
3198 if (cf.bottom > mVoiceContentBottom) cf.bottom = mVoiceContentBottom;
3199 } else if (attached.getSurfaceLayer() < mDockLayer) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003200 if (cf.left < mContentLeft) cf.left = mContentLeft;
3201 if (cf.top < mContentTop) cf.top = mContentTop;
3202 if (cf.right > mContentRight) cf.right = mContentRight;
3203 if (cf.bottom > mContentBottom) cf.bottom = mContentBottom;
3204 }
3205 }
3206 df.set(insetDecors ? attached.getDisplayFrameLw() : cf);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003207 of.set(insetDecors ? attached.getOverscanFrameLw() : cf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003208 vf.set(attached.getVisibleFrameLw());
3209 }
3210 // The LAYOUT_IN_SCREEN flag is used to determine whether the attached
3211 // window should be positioned relative to its parent or the entire
3212 // screen.
3213 pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0
3214 ? attached.getFrameLw() : df);
3215 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003216
3217 private void applyStableConstraints(int sysui, int fl, Rect r) {
3218 if ((sysui & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
3219 // If app is requesting a stable layout, don't let the
3220 // content insets go below the stable values.
3221 if ((fl & FLAG_FULLSCREEN) != 0) {
3222 if (r.left < mStableFullscreenLeft) r.left = mStableFullscreenLeft;
3223 if (r.top < mStableFullscreenTop) r.top = mStableFullscreenTop;
3224 if (r.right > mStableFullscreenRight) r.right = mStableFullscreenRight;
3225 if (r.bottom > mStableFullscreenBottom) r.bottom = mStableFullscreenBottom;
3226 } else {
3227 if (r.left < mStableLeft) r.left = mStableLeft;
3228 if (r.top < mStableTop) r.top = mStableTop;
3229 if (r.right > mStableRight) r.right = mStableRight;
3230 if (r.bottom > mStableBottom) r.bottom = mStableBottom;
3231 }
3232 }
3233 }
3234
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003235 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07003236 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003237 public void layoutWindowLw(WindowState win, WindowState attached) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003238 // we've already done the status bar
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003239 final WindowManager.LayoutParams attrs = win.getAttrs();
3240 if ((win == mStatusBar && (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) == 0) ||
3241 win == mNavigationBar) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003242 return;
3243 }
Craig Mautner69b08182012-09-05 13:07:13 -07003244 final boolean isDefaultDisplay = win.isDefaultDisplay();
3245 final boolean needsToOffsetInputMethodTarget = isDefaultDisplay &&
satok1bc0a492012-04-25 22:47:12 +09003246 (win == mLastInputMethodTargetWindow && mLastInputMethodWindow != null);
3247 if (needsToOffsetInputMethodTarget) {
Craig Mautnereda67292013-04-28 13:50:14 -07003248 if (DEBUG_LAYOUT) Slog.i(TAG, "Offset ime target window by the last ime window state");
satok1bc0a492012-04-25 22:47:12 +09003249 offsetInputMethodWindowLw(mLastInputMethodWindow);
3250 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003251
John Spurlockc6d1c602014-01-17 15:22:06 -05003252 final int fl = PolicyControl.getWindowFlags(win, attrs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003253 final int sim = attrs.softInputMode;
John Spurlock1db8b682014-02-18 11:18:59 -05003254 final int sysUiFl = PolicyControl.getSystemUiVisibility(win, null);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003255
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003256 final Rect pf = mTmpParentFrame;
3257 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003258 final Rect of = mTmpOverscanFrame;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003259 final Rect cf = mTmpContentFrame;
3260 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04003261 final Rect dcf = mTmpDecorFrame;
Adrian Roosfa104232014-06-20 16:10:14 -07003262 final Rect sf = mTmpStableFrame;
John Spurlock46646232013-09-30 22:32:42 -04003263 dcf.setEmpty();
Craig Mautner69b08182012-09-05 13:07:13 -07003264
3265 final boolean hasNavBar = (isDefaultDisplay && mHasNavigationBar
Daniel Sandler36412a72011-08-04 09:35:13 -04003266 && mNavigationBar != null && mNavigationBar.isVisibleLw());
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003267
Craig Mautnerf683b562012-10-02 11:10:57 -07003268 final int adjust = sim & SOFT_INPUT_MASK_ADJUST;
3269
Adrian Roosfa104232014-06-20 16:10:14 -07003270 if (isDefaultDisplay) {
3271 sf.set(mStableLeft, mStableTop, mStableRight, mStableBottom);
3272 } else {
3273 sf.set(mOverscanLeft, mOverscanTop, mOverscanRight, mOverscanBottom);
3274 }
3275
Craig Mautner69b08182012-09-05 13:07:13 -07003276 if (!isDefaultDisplay) {
3277 if (attached != null) {
3278 // If this window is attached to another, our display
3279 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003280 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07003281 } else {
3282 // Give the window full screen.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003283 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3284 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3285 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08003286 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003287 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003288 = mOverscanScreenTop + mOverscanScreenHeight;
Craig Mautner69b08182012-09-05 13:07:13 -07003289 }
3290 } else if (attrs.type == TYPE_INPUT_METHOD) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003291 pf.left = df.left = of.left = cf.left = vf.left = mDockLeft;
3292 pf.top = df.top = of.top = cf.top = vf.top = mDockTop;
3293 pf.right = df.right = of.right = cf.right = vf.right = mDockRight;
John Spurlockc68d5772013-10-08 11:47:58 -04003294 // IM dock windows layout below the nav bar...
John Spurlock57beb3b2013-10-10 10:27:44 -04003295 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlockc68d5772013-10-08 11:47:58 -04003296 // ...with content insets above the nav bar
3297 cf.bottom = vf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003298 // IM dock windows always go to the bottom of the screen.
3299 attrs.gravity = Gravity.BOTTOM;
3300 mDockLayer = win.getSurfaceLayer();
Jorim Jaggie0700182014-08-21 01:12:37 +02003301 } else if (win == mStatusBar && (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
3302 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3303 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3304 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
3305 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight + mUnrestrictedScreenTop;
3306 cf.left = vf.left = mStableLeft;
3307 cf.top = vf.top = mStableTop;
3308 cf.right = vf.right = mStableRight;
3309 vf.bottom = mStableBottom;
3310 cf.bottom = mContentBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003311 } else {
John Spurlock46646232013-09-30 22:32:42 -04003312
3313 // Default policy decor for the default display
3314 dcf.left = mSystemLeft;
3315 dcf.top = mSystemTop;
3316 dcf.right = mSystemRight;
3317 dcf.bottom = mSystemBottom;
John Spurlockbd957402013-10-03 11:38:39 -04003318 final boolean inheritTranslucentDecor = (attrs.privateFlags
3319 & WindowManager.LayoutParams.PRIVATE_FLAG_INHERIT_TRANSLUCENT_DECOR) != 0;
John Spurlock65567d42013-10-08 10:08:32 -04003320 final boolean isAppWindow =
3321 attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW &&
3322 attrs.type <= WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
3323 final boolean topAtRest =
3324 win == mTopFullscreenOpaqueWindowState && !win.isAnimatingLw();
3325 if (isAppWindow && !inheritTranslucentDecor && !topAtRest) {
John Spurlockbd957402013-10-03 11:38:39 -04003326 if ((sysUiFl & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0
3327 && (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0
Adrian Roosea562512014-05-05 13:33:03 +02003328 && (fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) == 0
3329 && (fl & WindowManager.LayoutParams.
3330 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04003331 // Ensure policy decor includes status bar
3332 dcf.top = mStableTop;
3333 }
John Spurlockbd957402013-10-03 11:38:39 -04003334 if ((fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) == 0
Adrian Roosea562512014-05-05 13:33:03 +02003335 && (sysUiFl & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0
3336 && (fl & WindowManager.LayoutParams.
3337 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04003338 // Ensure policy decor includes navigation bar
3339 dcf.bottom = mStableBottom;
3340 dcf.right = mStableRight;
3341 }
3342 }
3343
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003344 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
3345 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
RoboErik8a2cfc32014-05-16 11:19:38 -07003346 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003347 + "): IN_SCREEN, INSET_DECOR");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003348 // This is the case for a normal activity window: we want it
3349 // to cover all of the screen space, and it can take care of
3350 // moving its contents to account for screen decorations that
3351 // intrude into that space.
3352 if (attached != null) {
3353 // If this window is attached to another, our display
3354 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003355 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003356 } else {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003357 if (attrs.type == TYPE_STATUS_BAR_PANEL
3358 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Joe Onorato29fc2c92010-11-24 10:26:50 -08003359 // Status bar panels are the only windows who can go on top of
3360 // the status bar. They are protected by the STATUS_BAR_SERVICE
3361 // permission, so they have the same privileges as the status
3362 // bar itself.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003363 //
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003364 // However, they should still dodge the navigation bar if it exists.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003365
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003366 pf.left = df.left = of.left = hasNavBar
3367 ? mDockLeft : mUnrestrictedScreenLeft;
3368 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3369 pf.right = df.right = of.right = hasNavBar
3370 ? mRestrictedScreenLeft+mRestrictedScreenWidth
3371 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3372 pf.bottom = df.bottom = of.bottom = hasNavBar
3373 ? mRestrictedScreenTop+mRestrictedScreenHeight
3374 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003375
Craig Mautnereda67292013-04-28 13:50:14 -07003376 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003377 "Laying out status bar window: (%d,%d - %d,%d)",
3378 pf.left, pf.top, pf.right, pf.bottom));
John Spurlock46646232013-09-30 22:32:42 -04003379 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08003380 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3381 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3382 // Asking to layout into the overscan region, so give it that pure
3383 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003384 pf.left = df.left = of.left = mOverscanScreenLeft;
3385 pf.top = df.top = of.top = mOverscanScreenTop;
3386 pf.right = df.right = of.right = mOverscanScreenLeft + mOverscanScreenWidth;
3387 pf.bottom = df.bottom = of.bottom = mOverscanScreenTop
3388 + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003389 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003390 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003391 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3392 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003393 // Asking for layout as if the nav bar is hidden, lets the
Dianne Hackbornc652de82013-02-15 16:32:56 -08003394 // application extend into the unrestricted overscan screen area. We
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003395 // only do this for application windows to ensure no window that
3396 // can be above the nav bar can do this.
Dianne Hackborn313440842013-02-19 19:22:59 -08003397 pf.left = df.left = mOverscanScreenLeft;
3398 pf.top = df.top = mOverscanScreenTop;
3399 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
3400 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003401 // We need to tell the app about where the frame inside the overscan
3402 // is, so it can inset its content by that amount -- it didn't ask
3403 // to actually extend itself into the overscan region.
3404 of.left = mUnrestrictedScreenLeft;
3405 of.top = mUnrestrictedScreenTop;
3406 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3407 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003408 } else {
Dianne Hackborn313440842013-02-19 19:22:59 -08003409 pf.left = df.left = mRestrictedOverscanScreenLeft;
3410 pf.top = df.top = mRestrictedOverscanScreenTop;
3411 pf.right = df.right = mRestrictedOverscanScreenLeft
3412 + mRestrictedOverscanScreenWidth;
3413 pf.bottom = df.bottom = mRestrictedOverscanScreenTop
3414 + mRestrictedOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003415 // We need to tell the app about where the frame inside the overscan
3416 // is, so it can inset its content by that amount -- it didn't ask
3417 // to actually extend itself into the overscan region.
3418 of.left = mUnrestrictedScreenLeft;
3419 of.top = mUnrestrictedScreenTop;
3420 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3421 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003422 }
Craig Mautner69b08182012-09-05 13:07:13 -07003423
John Spurlock46646232013-09-30 22:32:42 -04003424 if ((fl & FLAG_FULLSCREEN) == 0) {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003425 if (win.isVoiceInteraction()) {
3426 cf.left = mVoiceContentLeft;
3427 cf.top = mVoiceContentTop;
3428 cf.right = mVoiceContentRight;
3429 cf.bottom = mVoiceContentBottom;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003430 } else {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003431 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
3432 cf.left = mDockLeft;
3433 cf.top = mDockTop;
3434 cf.right = mDockRight;
3435 cf.bottom = mDockBottom;
3436 } else {
3437 cf.left = mContentLeft;
3438 cf.top = mContentTop;
3439 cf.right = mContentRight;
3440 cf.bottom = mContentBottom;
3441 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003442 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003443 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003444 // Full screen windows are always given a layout that is as if the
3445 // status bar and other transient decors are gone. This is to avoid
3446 // bad states when moving from a window that is not hding the
3447 // status bar to one that is.
3448 cf.left = mRestrictedScreenLeft;
3449 cf.top = mRestrictedScreenTop;
3450 cf.right = mRestrictedScreenLeft + mRestrictedScreenWidth;
3451 cf.bottom = mRestrictedScreenTop + mRestrictedScreenHeight;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003452 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003453 applyStableConstraints(sysUiFl, fl, cf);
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003454 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3455 vf.left = mCurLeft;
3456 vf.top = mCurTop;
3457 vf.right = mCurRight;
3458 vf.bottom = mCurBottom;
3459 } else {
3460 vf.set(cf);
3461 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003462 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003463 } else if ((fl & FLAG_LAYOUT_IN_SCREEN) != 0 || (sysUiFl
3464 & (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
3465 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)) != 0) {
Craig Mautnereda67292013-04-28 13:50:14 -07003466 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3467 "): IN_SCREEN");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003468 // A window that has requested to fill the entire screen just
3469 // gets everything, period.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003470 if (attrs.type == TYPE_STATUS_BAR_PANEL
3471 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003472 pf.left = df.left = of.left = cf.left = hasNavBar
3473 ? mDockLeft : mUnrestrictedScreenLeft;
3474 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
3475 pf.right = df.right = of.right = cf.right = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003476 ? mRestrictedScreenLeft+mRestrictedScreenWidth
Dianne Hackbornc652de82013-02-15 16:32:56 -08003477 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003478 pf.bottom = df.bottom = of.bottom = cf.bottom = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003479 ? mRestrictedScreenTop+mRestrictedScreenHeight
Dianne Hackbornc652de82013-02-15 16:32:56 -08003480 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07003481 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler36412a72011-08-04 09:35:13 -04003482 "Laying out IN_SCREEN status bar window: (%d,%d - %d,%d)",
3483 pf.left, pf.top, pf.right, pf.bottom));
Jim Millere898ac52012-04-06 17:10:57 -07003484 } else if (attrs.type == TYPE_NAVIGATION_BAR
3485 || attrs.type == TYPE_NAVIGATION_BAR_PANEL) {
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003486 // The navigation bar has Real Ultimate Power.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003487 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3488 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3489 pf.right = df.right = of.right = mUnrestrictedScreenLeft
3490 + mUnrestrictedScreenWidth;
3491 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop
3492 + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07003493 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003494 "Laying out navigation bar window: (%d,%d - %d,%d)",
3495 pf.left, pf.top, pf.right, pf.bottom));
Dianne Hackborn01011c32012-02-21 13:54:21 -08003496 } else if ((attrs.type == TYPE_SECURE_SYSTEM_OVERLAY
3497 || attrs.type == TYPE_BOOT_PROGRESS)
Jeff Brownbfcb60a2011-09-08 18:51:14 -07003498 && ((fl & FLAG_FULLSCREEN) != 0)) {
3499 // Fullscreen secure system overlays get what they ask for.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003500 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3501 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3502 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
3503 + mOverscanScreenWidth;
3504 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
3505 + mOverscanScreenHeight;
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07003506 } else if (attrs.type == TYPE_BOOT_PROGRESS
3507 || attrs.type == TYPE_UNIVERSE_BACKGROUND) {
Dianne Hackborn01011c32012-02-21 13:54:21 -08003508 // Boot progress screen always covers entire display.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003509 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3510 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3511 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
3512 + mOverscanScreenWidth;
3513 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
3514 + mOverscanScreenHeight;
John Spurlockef4adae2013-08-26 17:58:58 -04003515 } else if (attrs.type == TYPE_WALLPAPER) {
3516 // The wallpaper also has Real Ultimate Power.
3517 pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft;
3518 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003519 pf.right = df.right = of.right = cf.right
John Spurlockef4adae2013-08-26 17:58:58 -04003520 = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003521 pf.bottom = df.bottom = of.bottom = cf.bottom
John Spurlockef4adae2013-08-26 17:58:58 -04003522 = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlock46646232013-09-30 22:32:42 -04003523 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08003524 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3525 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3526 // Asking to layout into the overscan region, so give it that pure
3527 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003528 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3529 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3530 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08003531 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003532 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003533 = mOverscanScreenTop + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003534 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003535 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Craig Mautnerbeac1062014-06-03 14:38:57 -07003536 && (attrs.type == TYPE_STATUS_BAR
3537 || attrs.type == TYPE_TOAST
John Spurlock34e13d92013-08-10 06:52:28 -04003538 || (attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3539 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW))) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003540 // Asking for layout as if the nav bar is hidden, lets the
3541 // application extend into the unrestricted screen area. We
John Spurlock34e13d92013-08-10 06:52:28 -04003542 // only do this for application windows (or toasts) to ensure no window that
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003543 // can be above the nav bar can do this.
3544 // XXX This assumes that an app asking for this will also
3545 // ask for layout in only content. We can't currently figure out
3546 // what the screen would be if only laying out to hide the nav bar.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003547 pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft;
3548 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
3549 pf.right = df.right = of.right = cf.right = mUnrestrictedScreenLeft
3550 + mUnrestrictedScreenWidth;
3551 pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop
3552 + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003553 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003554 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
3555 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
3556 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
3557 + mRestrictedScreenWidth;
3558 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
3559 + mRestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003560 }
Craig Mautner69b08182012-09-05 13:07:13 -07003561
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003562 applyStableConstraints(sysUiFl, fl, cf);
Craig Mautner69b08182012-09-05 13:07:13 -07003563
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003564 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3565 vf.left = mCurLeft;
3566 vf.top = mCurTop;
3567 vf.right = mCurRight;
3568 vf.bottom = mCurBottom;
3569 } else {
3570 vf.set(cf);
3571 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003572 } else if (attached != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07003573 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3574 "): attached to " + attached);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003575 // A child window should be placed inside of the same visible
3576 // frame that its parent had.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003577 setAttachedWindowFrames(win, fl, adjust, attached, false, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003578 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07003579 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3580 "): normal window");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003581 // Otherwise, a normal window must be placed inside the content
3582 // of all screen decorations.
Dianne Hackborna239c842011-06-01 12:28:20 -07003583 if (attrs.type == TYPE_STATUS_BAR_PANEL) {
3584 // Status bar panels are the only windows who can go on top of
3585 // the status bar. They are protected by the STATUS_BAR_SERVICE
3586 // permission, so they have the same privileges as the status
3587 // bar itself.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003588 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
3589 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
3590 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
3591 + mRestrictedScreenWidth;
3592 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
3593 + mRestrictedScreenHeight;
John Spurlock414c1f02013-12-04 13:47:36 -05003594 } else if (attrs.type == TYPE_TOAST || attrs.type == TYPE_SYSTEM_ALERT
3595 || attrs.type == TYPE_VOLUME_OVERLAY) {
3596 // These dialogs are stable to interim decor changes.
John Spurlockbd957402013-10-03 11:38:39 -04003597 pf.left = df.left = of.left = cf.left = mStableLeft;
3598 pf.top = df.top = of.top = cf.top = mStableTop;
3599 pf.right = df.right = of.right = cf.right = mStableRight;
3600 pf.bottom = df.bottom = of.bottom = cf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003601 } else {
Dianne Hackborna239c842011-06-01 12:28:20 -07003602 pf.left = mContentLeft;
3603 pf.top = mContentTop;
3604 pf.right = mContentRight;
3605 pf.bottom = mContentBottom;
Dianne Hackborn20d94742014-05-29 18:35:45 -07003606 if (win.isVoiceInteraction()) {
3607 df.left = of.left = cf.left = mVoiceContentLeft;
3608 df.top = of.top = cf.top = mVoiceContentTop;
3609 df.right = of.right = cf.right = mVoiceContentRight;
3610 df.bottom = of.bottom = cf.bottom = mVoiceContentBottom;
3611 } else if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003612 df.left = of.left = cf.left = mDockLeft;
3613 df.top = of.top = cf.top = mDockTop;
3614 df.right = of.right = cf.right = mDockRight;
3615 df.bottom = of.bottom = cf.bottom = mDockBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07003616 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003617 df.left = of.left = cf.left = mContentLeft;
3618 df.top = of.top = cf.top = mContentTop;
3619 df.right = of.right = cf.right = mContentRight;
3620 df.bottom = of.bottom = cf.bottom = mContentBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07003621 }
3622 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3623 vf.left = mCurLeft;
3624 vf.top = mCurTop;
3625 vf.right = mCurRight;
3626 vf.bottom = mCurBottom;
3627 } else {
3628 vf.set(cf);
3629 }
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003630 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003631 }
3632 }
Craig Mautner69b08182012-09-05 13:07:13 -07003633
Craig Mautnerb816bed2013-07-23 10:26:17 -07003634 // TYPE_SYSTEM_ERROR is above the NavigationBar so it can't be allowed to extend over it.
3635 if ((fl & FLAG_LAYOUT_NO_LIMITS) != 0 && attrs.type != TYPE_SYSTEM_ERROR) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003636 df.left = df.top = of.left = of.top = cf.left = cf.top = vf.left = vf.top = -10000;
3637 df.right = df.bottom = of.right = of.bottom = cf.right = cf.bottom
3638 = vf.right = vf.bottom = 10000;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003639 }
3640
Craig Mautnereda67292013-04-28 13:50:14 -07003641 if (DEBUG_LAYOUT) Slog.v(TAG, "Compute frame " + attrs.getTitle()
The Android Open Source Project11267662009-03-18 17:39:47 -07003642 + ": sim=#" + Integer.toHexString(sim)
RoboErik8a2cfc32014-05-16 11:19:38 -07003643 + " attach=" + attached + " type=" + attrs.type
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003644 + String.format(" flags=0x%08x", fl)
The Android Open Source Project11267662009-03-18 17:39:47 -07003645 + " pf=" + pf.toShortString() + " df=" + df.toShortString()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003646 + " of=" + of.toShortString()
John Spurlock46646232013-09-30 22:32:42 -04003647 + " cf=" + cf.toShortString() + " vf=" + vf.toShortString()
Adrian Roosfa104232014-06-20 16:10:14 -07003648 + " dcf=" + dcf.toShortString()
3649 + " sf=" + sf.toShortString());
Craig Mautner69b08182012-09-05 13:07:13 -07003650
Adrian Roosfa104232014-06-20 16:10:14 -07003651 win.computeFrameLw(pf, df, of, cf, vf, dcf, sf);
Craig Mautner69b08182012-09-05 13:07:13 -07003652
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003653 // Dock windows carve out the bottom of the screen, so normal windows
3654 // can't appear underneath them.
Craig Mautner8bd206b2012-10-03 10:32:02 -07003655 if (attrs.type == TYPE_INPUT_METHOD && win.isVisibleOrBehindKeyguardLw()
3656 && !win.getGivenInsetsPendingLw()) {
satok1bc0a492012-04-25 22:47:12 +09003657 setLastInputMethodWindowLw(null, null);
3658 offsetInputMethodWindowLw(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003659 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003660 if (attrs.type == TYPE_VOICE_INTERACTION && win.isVisibleOrBehindKeyguardLw()
3661 && !win.getGivenInsetsPendingLw()) {
3662 offsetVoiceInputWindowLw(win);
3663 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003664 }
3665
satok1bc0a492012-04-25 22:47:12 +09003666 private void offsetInputMethodWindowLw(WindowState win) {
3667 int top = win.getContentFrameLw().top;
3668 top += win.getGivenContentInsetsLw().top;
3669 if (mContentBottom > top) {
3670 mContentBottom = top;
3671 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003672 if (mVoiceContentBottom > top) {
3673 mVoiceContentBottom = top;
3674 }
satok1bc0a492012-04-25 22:47:12 +09003675 top = win.getVisibleFrameLw().top;
3676 top += win.getGivenVisibleInsetsLw().top;
3677 if (mCurBottom > top) {
3678 mCurBottom = top;
3679 }
Craig Mautnereda67292013-04-28 13:50:14 -07003680 if (DEBUG_LAYOUT) Slog.v(TAG, "Input method: mDockBottom="
satok1bc0a492012-04-25 22:47:12 +09003681 + mDockBottom + " mContentBottom="
3682 + mContentBottom + " mCurBottom=" + mCurBottom);
3683 }
3684
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003685 private void offsetVoiceInputWindowLw(WindowState win) {
3686 final int gravity = win.getAttrs().gravity;
3687 switch (gravity&((Gravity.AXIS_PULL_BEFORE|Gravity.AXIS_PULL_AFTER)
3688 << Gravity.AXIS_X_SHIFT)) {
3689 case Gravity.AXIS_PULL_BEFORE<<Gravity.AXIS_X_SHIFT: {
3690 int right = win.getContentFrameLw().right - win.getGivenContentInsetsLw().right;
3691 if (mVoiceContentLeft < right) {
3692 mVoiceContentLeft = right;
3693 }
3694 } break;
3695 case Gravity.AXIS_PULL_AFTER<<Gravity.AXIS_X_SHIFT: {
3696 int left = win.getContentFrameLw().left - win.getGivenContentInsetsLw().left;
3697 if (mVoiceContentRight < left) {
3698 mVoiceContentRight = left;
3699 }
3700 } break;
3701 }
3702 switch (gravity&((Gravity.AXIS_PULL_BEFORE|Gravity.AXIS_PULL_AFTER)
3703 << Gravity.AXIS_Y_SHIFT)) {
3704 case Gravity.AXIS_PULL_BEFORE<<Gravity.AXIS_Y_SHIFT: {
3705 int bottom = win.getContentFrameLw().bottom - win.getGivenContentInsetsLw().bottom;
3706 if (mVoiceContentTop < bottom) {
3707 mVoiceContentTop = bottom;
3708 }
3709 } break;
3710 case Gravity.AXIS_PULL_AFTER<<Gravity.AXIS_Y_SHIFT: {
3711 int top = win.getContentFrameLw().top - win.getGivenContentInsetsLw().top;
3712 if (mVoiceContentBottom < top) {
3713 mVoiceContentBottom = top;
3714 }
3715 } break;
3716 }
3717 }
3718
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003719 /** {@inheritDoc} */
Craig Mautner61ac6bb2012-02-02 17:29:33 -08003720 @Override
3721 public void finishLayoutLw() {
3722 return;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003723 }
3724
3725 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003726 @Override
Craig Mautner39834192012-09-02 07:47:24 -07003727 public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) {
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003728 mTopFullscreenOpaqueWindowState = null;
Craig Mautner2bc789b2014-03-19 19:48:38 -07003729 mAppsToBeHidden.clear();
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003730 mForceStatusBar = false;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003731 mForceStatusBarFromKeyguard = false;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08003732 mForcingShowNavBar = false;
3733 mForcingShowNavBarLayer = -1;
RoboErik8a2cfc32014-05-16 11:19:38 -07003734
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003735 mHideLockScreen = false;
3736 mAllowLockscreenWhenOn = false;
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003737 mDismissKeyguard = DISMISS_KEYGUARD_NONE;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003738 mShowingLockscreen = false;
3739 mShowingDream = false;
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003740 mWinShowWhenLocked = null;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003741 }
3742
3743 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003744 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003745 public void applyPostLayoutPolicyLw(WindowState win, WindowManager.LayoutParams attrs) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07003746 if (DEBUG_LAYOUT) Slog.i(TAG, "Win " + win + ": isVisibleOrBehindKeyguardLw="
3747 + win.isVisibleOrBehindKeyguardLw());
John Spurlockc6d1c602014-01-17 15:22:06 -05003748 final int fl = PolicyControl.getWindowFlags(win, attrs);
John Spurlock414c1f02013-12-04 13:47:36 -05003749 if (mTopFullscreenOpaqueWindowState == null
3750 && win.isVisibleLw() && attrs.type == TYPE_INPUT_METHOD) {
3751 mForcingShowNavBar = true;
3752 mForcingShowNavBarLayer = win.getSurfaceLayer();
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08003753 }
Jorim Jaggiafd4a552014-04-08 15:13:05 +02003754 if (attrs.type == TYPE_STATUS_BAR && (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Jorim Jaggiafd4a552014-04-08 15:13:05 +02003755 mForceStatusBarFromKeyguard = true;
3756 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003757 if (mTopFullscreenOpaqueWindowState == null &&
Dianne Hackborn01b02a72012-01-12 14:05:03 -08003758 win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()) {
John Spurlockc6d1c602014-01-17 15:22:06 -05003759 if ((fl & FLAG_FORCE_NOT_FULLSCREEN) != 0) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003760 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003761 mForceStatusBarFromKeyguard = true;
3762 } else {
3763 mForceStatusBar = true;
3764 }
3765 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003766 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003767 mShowingLockscreen = true;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07003768 }
Craig Mautnerab55e522014-03-03 13:26:03 -08003769 boolean appWindow = attrs.type >= FIRST_APPLICATION_WINDOW
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003770 && attrs.type <= LAST_APPLICATION_WINDOW;
3771 if (attrs.type == TYPE_DREAM) {
Jeff Brownc8018eb2012-10-29 21:33:27 -07003772 // If the lockscreen was showing when the dream started then wait
3773 // for the dream to draw before hiding the lockscreen.
3774 if (!mDreamingLockscreen
3775 || (win.isVisibleLw() && win.hasDrawnLw())) {
3776 mShowingDream = true;
Craig Mautnerab55e522014-03-03 13:26:03 -08003777 appWindow = true;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003778 }
3779 }
Craig Mautnerab55e522014-03-03 13:26:03 -08003780
Craig Mautner00156ec2014-03-06 22:29:02 -08003781 final boolean showWhenLocked = (fl & FLAG_SHOW_WHEN_LOCKED) != 0;
Craig Mautner74ee9382014-04-01 15:20:16 -07003782 final boolean dismissKeyguard = (fl & FLAG_DISMISS_KEYGUARD) != 0;
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003783 final boolean secureKeyguard = isKeyguardSecure();
Craig Mautnerab55e522014-03-03 13:26:03 -08003784 if (appWindow) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003785 if (showWhenLocked || (dismissKeyguard && !secureKeyguard)) {
3786 // Remove any previous windows with the same appToken.
Craig Mautner2bc789b2014-03-19 19:48:38 -07003787 mAppsToBeHidden.remove(win.getAppToken());
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003788 if (mAppsToBeHidden.isEmpty() && showWhenLocked &&
3789 isKeyguardSecureIncludingHidden()) {
3790 mWinShowWhenLocked = win;
3791 mHideLockScreen = true;
3792 mForceStatusBarFromKeyguard = false;
3793 }
Craig Mautner2bc789b2014-03-19 19:48:38 -07003794 } else {
3795 mAppsToBeHidden.add(win.getAppToken());
3796 }
Craig Mautnerab55e522014-03-03 13:26:03 -08003797 if (attrs.x == 0 && attrs.y == 0
3798 && attrs.width == WindowManager.LayoutParams.MATCH_PARENT
3799 && attrs.height == WindowManager.LayoutParams.MATCH_PARENT) {
3800 if (DEBUG_LAYOUT) Slog.v(TAG, "Fullscreen window: " + win);
3801 mTopFullscreenOpaqueWindowState = win;
Craig Mautner2bc789b2014-03-19 19:48:38 -07003802 if (mAppsToBeHidden.isEmpty()) {
Craig Mautnerda09ae32014-03-03 13:26:03 -08003803 if (showWhenLocked) {
3804 if (DEBUG_LAYOUT) Slog.v(TAG,
3805 "Setting mHideLockScreen to true by win " + win);
3806 mHideLockScreen = true;
3807 mForceStatusBarFromKeyguard = false;
3808 }
Craig Mautner4bdab6b2014-04-01 12:05:11 -07003809 if (dismissKeyguard && mDismissKeyguard == DISMISS_KEYGUARD_NONE) {
Craig Mautnerda09ae32014-03-03 13:26:03 -08003810 if (DEBUG_LAYOUT) Slog.v(TAG,
3811 "Setting mDismissKeyguard true by win " + win);
3812 mDismissKeyguard = mWinDismissingKeyguard == win ?
3813 DISMISS_KEYGUARD_CONTINUE : DISMISS_KEYGUARD_START;
3814 mWinDismissingKeyguard = win;
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003815 mForceStatusBarFromKeyguard = mShowingLockscreen && secureKeyguard;
Craig Mautnerda09ae32014-03-03 13:26:03 -08003816 }
Craig Mautnerab55e522014-03-03 13:26:03 -08003817 }
Craig Mautner00156ec2014-03-06 22:29:02 -08003818 if ((fl & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) {
Craig Mautnerab55e522014-03-03 13:26:03 -08003819 mAllowLockscreenWhenOn = true;
3820 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003821 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003822
3823 if (mWinShowWhenLocked != null &&
3824 mWinShowWhenLocked.getAppToken() != win.getAppToken()) {
3825 win.hideLw(false);
3826 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003827 }
3828 }
3829 }
3830
3831 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003832 @Override
Craig Mautner39834192012-09-02 07:47:24 -07003833 public int finishPostLayoutPolicyLw() {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003834 if (mWinShowWhenLocked != null &&
3835 mWinShowWhenLocked != mTopFullscreenOpaqueWindowState) {
3836 // A dialog is dismissing the keyguard. Put the wallpaper behind it and hide the
3837 // fullscreen window.
3838 // TODO: Make sure FLAG_SHOW_WALLPAPER is restored when dialog is dismissed. Or not.
3839 mWinShowWhenLocked.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
3840 mTopFullscreenOpaqueWindowState.hideLw(false);
3841 mTopFullscreenOpaqueWindowState = mWinShowWhenLocked;
3842 }
3843
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003844 int changes = 0;
Joe Onorato93056472010-09-10 10:30:46 -04003845 boolean topIsFullscreen = false;
Daniel Sandlere02d8082010-10-08 15:13:22 -04003846
3847 final WindowManager.LayoutParams lp = (mTopFullscreenOpaqueWindowState != null)
3848 ? mTopFullscreenOpaqueWindowState.getAttrs()
3849 : null;
3850
Jeff Brownc8018eb2012-10-29 21:33:27 -07003851 // If we are not currently showing a dream then remember the current
3852 // lockscreen state. We will use this to determine whether the dream
3853 // started while the lockscreen was showing and remember this state
3854 // while the dream is showing.
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003855 if (!mShowingDream) {
3856 mDreamingLockscreen = mShowingLockscreen;
3857 }
3858
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003859 if (mStatusBar != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07003860 if (DEBUG_LAYOUT) Slog.i(TAG, "force=" + mForceStatusBar
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003861 + " forcefkg=" + mForceStatusBarFromKeyguard
Dianne Hackbornd70bc2f2009-10-06 23:25:51 -07003862 + " top=" + mTopFullscreenOpaqueWindowState);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003863 if (mForceStatusBar || mForceStatusBarFromKeyguard) {
Craig Mautnereda67292013-04-28 13:50:14 -07003864 if (DEBUG_LAYOUT) Slog.v(TAG, "Showing status bar: forced");
John Spurlock27735a42013-08-14 17:57:38 -04003865 if (mStatusBarController.setBarShowingLw(true)) {
3866 changes |= FINISH_LAYOUT_REDO_LAYOUT;
3867 }
Craig Mautner81defc72013-10-29 11:10:42 -07003868 // Maintain fullscreen layout until incoming animation is complete.
3869 topIsFullscreen = mTopIsFullscreen && mStatusBar.isAnimatingLw();
John Spurlockf92b6162013-11-11 15:01:16 -05003870 // Transient status bar on the lockscreen is not allowed
3871 if (mForceStatusBarFromKeyguard && mStatusBarController.isTransientShowing()) {
3872 mStatusBarController.updateVisibilityLw(false /*transientAllowed*/,
3873 mLastSystemUiFlags, mLastSystemUiFlags);
3874 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003875 } else if (mTopFullscreenOpaqueWindowState != null) {
John Spurlockc6d1c602014-01-17 15:22:06 -05003876 final int fl = PolicyControl.getWindowFlags(null, lp);
Joe Onorato93056472010-09-10 10:30:46 -04003877 if (localLOGV) {
Craig Mautnereda67292013-04-28 13:50:14 -07003878 Slog.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw()
Joe Onorato93056472010-09-10 10:30:46 -04003879 + " shown frame: " + mTopFullscreenOpaqueWindowState.getShownFrameLw());
Craig Mautnereda67292013-04-28 13:50:14 -07003880 Slog.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs()
John Spurlockc6d1c602014-01-17 15:22:06 -05003881 + " lp.flags=0x" + Integer.toHexString(fl));
Joe Onorato93056472010-09-10 10:30:46 -04003882 }
John Spurlockc6d1c602014-01-17 15:22:06 -05003883 topIsFullscreen = (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003884 || (mLastSystemUiFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
Joe Onorato93056472010-09-10 10:30:46 -04003885 // The subtle difference between the window for mTopFullscreenOpaqueWindowState
3886 // and mTopIsFullscreen is that that mTopIsFullscreen is set only if the window
3887 // has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the
3888 // case though.
John Spurlock27735a42013-08-14 17:57:38 -04003889 if (mStatusBarController.isTransientShowing()) {
3890 if (mStatusBarController.setBarShowingLw(true)) {
John Spurlock32beb2c2013-03-11 10:16:47 -04003891 changes |= FINISH_LAYOUT_REDO_LAYOUT;
3892 }
3893 } else if (topIsFullscreen) {
Craig Mautnereda67292013-04-28 13:50:14 -07003894 if (DEBUG_LAYOUT) Slog.v(TAG, "** HIDING status bar");
John Spurlock27735a42013-08-14 17:57:38 -04003895 if (mStatusBarController.setBarShowingLw(false)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003896 changes |= FINISH_LAYOUT_REDO_LAYOUT;
Craig Mautnereda67292013-04-28 13:50:14 -07003897 } else {
Craig Mautnerc5a6e442013-06-05 17:22:35 -07003898 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar already hiding");
Daniel Sandler40427442010-07-16 11:44:52 -04003899 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003900 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07003901 if (DEBUG_LAYOUT) Slog.v(TAG, "** SHOWING status bar: top is not fullscreen");
John Spurlock27735a42013-08-14 17:57:38 -04003902 if (mStatusBarController.setBarShowingLw(true)) {
3903 changes |= FINISH_LAYOUT_REDO_LAYOUT;
3904 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003905 }
3906 }
3907 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04003908
Craig Mautner81defc72013-10-29 11:10:42 -07003909 if (mTopIsFullscreen != topIsFullscreen) {
3910 if (!topIsFullscreen) {
3911 // Force another layout when status bar becomes fully shown.
3912 changes |= FINISH_LAYOUT_REDO_LAYOUT;
3913 }
3914 mTopIsFullscreen = topIsFullscreen;
3915 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04003916
Craig Mautner39834192012-09-02 07:47:24 -07003917 // Hide the key guard if a visible window explicitly specifies that it wants to be
3918 // displayed when the screen is locked.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01003919 if (mKeyguardDelegate != null && mStatusBar != null) {
3920 if (localLOGV) Slog.v(TAG, "finishPostLayoutPolicyLw: mHideKeyguard="
3921 + mHideLockScreen);
3922 if (mDismissKeyguard != DISMISS_KEYGUARD_NONE && !isKeyguardSecure()) {
3923 mKeyguardHidden = true;
3924 if (processKeyguardSetHiddenResultLw(mKeyguardDelegate.setOccluded(true))) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003925 changes |= FINISH_LAYOUT_REDO_LAYOUT
3926 | FINISH_LAYOUT_REDO_CONFIG
3927 | FINISH_LAYOUT_REDO_WALLPAPER;
3928 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01003929 if (mKeyguardDelegate.isShowing()) {
3930 mHandler.post(new Runnable() {
3931 @Override
3932 public void run() {
3933 mKeyguardDelegate.keyguardDone(false, false);
3934 }
3935 });
3936 }
3937 } else if (mHideLockScreen) {
3938 mKeyguardHidden = true;
3939 if (processKeyguardSetHiddenResultLw(mKeyguardDelegate.setOccluded(true))) {
3940 changes |= FINISH_LAYOUT_REDO_LAYOUT
3941 | FINISH_LAYOUT_REDO_CONFIG
3942 | FINISH_LAYOUT_REDO_WALLPAPER;
3943 }
3944 } else if (mDismissKeyguard != DISMISS_KEYGUARD_NONE) {
3945 // This is the case of keyguard isSecure() and not mHideLockScreen.
3946 if (mDismissKeyguard == DISMISS_KEYGUARD_START) {
3947 // Only launch the next keyguard unlock window once per window.
3948 mKeyguardHidden = false;
3949 if (processKeyguardSetHiddenResultLw(mKeyguardDelegate.setOccluded(false))) {
3950 changes |= FINISH_LAYOUT_REDO_LAYOUT
3951 | FINISH_LAYOUT_REDO_CONFIG
3952 | FINISH_LAYOUT_REDO_WALLPAPER;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003953 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01003954 mHandler.post(new Runnable() {
3955 @Override
3956 public void run() {
3957 mKeyguardDelegate.dismiss();
3958 }
3959 });
3960 }
3961 } else {
3962 mWinDismissingKeyguard = null;
3963 mKeyguardHidden = false;
3964 if (processKeyguardSetHiddenResultLw(mKeyguardDelegate.setOccluded(false))) {
3965 changes |= FINISH_LAYOUT_REDO_LAYOUT
3966 | FINISH_LAYOUT_REDO_CONFIG
3967 | FINISH_LAYOUT_REDO_WALLPAPER;
3968 }
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -07003969 }
3970 }
Joe Onorato664644d2011-01-23 17:53:23 -08003971
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003972 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003973 // If the navigation bar has been hidden or shown, we need to do another
3974 // layout pass to update that window.
3975 changes |= FINISH_LAYOUT_REDO_LAYOUT;
3976 }
Joe Onorato664644d2011-01-23 17:53:23 -08003977
Mike Lockwood28569302010-01-28 11:54:40 -05003978 // update since mAllowLockscreenWhenOn might have changed
3979 updateLockScreenTimeout();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003980 return changes;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003981 }
3982
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003983 /**
Jorim Jaggi5cf17872014-03-26 18:31:48 +01003984 * Processes the result code of {@link IKeyguardService#setOccluded}. This is needed because we
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003985 * immediately need to put the wallpaper directly behind the Keyguard when a window with flag
3986 * {@link android.view.WindowManager.LayoutParams#FLAG_SHOW_WHEN_LOCKED} gets dismissed. If we
3987 * would wait for Keyguard to change the flags, that would be running asynchronously and thus be
3988 * too late so the user might see the window behind.
3989 *
Jorim Jaggi5cf17872014-03-26 18:31:48 +01003990 * @param setHiddenResult The result code from {@link IKeyguardService#setOccluded}.
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003991 * @return Whether the flags have changed and we have to redo the layout.
3992 */
3993 private boolean processKeyguardSetHiddenResultLw(int setHiddenResult) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01003994 if (setHiddenResult
3995 == IKeyguardServiceConstants.KEYGUARD_SERVICE_SET_OCCLUDED_RESULT_SET_FLAGS) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003996 mStatusBar.getAttrs().privateFlags |= PRIVATE_FLAG_KEYGUARD;
3997 mStatusBar.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
3998 return true;
3999 } else if (setHiddenResult
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004000 == IKeyguardServiceConstants.KEYGUARD_SERVICE_SET_OCCLUDED_RESULT_UNSET_FLAGS) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004001 mStatusBar.getAttrs().privateFlags &= ~PRIVATE_FLAG_KEYGUARD;
4002 mStatusBar.getAttrs().flags &= ~FLAG_SHOW_WALLPAPER;
4003 return true;
4004 } else {
4005 return false;
4006 }
4007 }
4008
4009 private boolean isStatusBarKeyguard() {
4010 return mStatusBar != null
4011 && (mStatusBar.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
4012 }
4013
Jose Lima9546b202014-07-02 17:21:51 -07004014 @Override
Dianne Hackborn08743722009-12-21 12:16:51 -08004015 public boolean allowAppAnimationsLw() {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004016 if (isStatusBarKeyguard() || mShowingDream) {
Craig Mautner28816302013-10-10 20:31:00 -07004017 // If keyguard or dreams is currently visible, no reason to animate behind it.
Dianne Hackborn08743722009-12-21 12:16:51 -08004018 return false;
4019 }
Dianne Hackborn08743722009-12-21 12:16:51 -08004020 return true;
4021 }
4022
Jose Lima9546b202014-07-02 17:21:51 -07004023 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07004024 public int focusChangedLw(WindowState lastFocus, WindowState newFocus) {
Joe Onorato664644d2011-01-23 17:53:23 -08004025 mFocusedWindow = newFocus;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004026 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004027 // If the navigation bar has been hidden or shown, we need to do another
4028 // layout pass to update that window.
4029 return FINISH_LAYOUT_REDO_LAYOUT;
4030 }
4031 return 0;
Joe Onorato664644d2011-01-23 17:53:23 -08004032 }
4033
Dianne Hackborn0ecadf72009-03-31 18:00:37 -07004034 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07004035 @Override
Jeff Brown46b9ac02010-04-22 18:58:52 -07004036 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
4037 // lid changed state
Jeff Brownc458ce92012-04-30 14:58:40 -07004038 final int newLidState = lidOpen ? LID_OPEN : LID_CLOSED;
4039 if (newLidState == mLidState) {
4040 return;
4041 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004042
Jeff Brownc458ce92012-04-30 14:58:40 -07004043 mLidState = newLidState;
4044 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07004045 updateRotation(true);
Jeff Brownc458ce92012-04-30 14:58:40 -07004046
4047 if (lidOpen) {
Jim Millere51cf7ae2013-06-25 18:31:56 -07004048 mPowerManager.wakeUp(SystemClock.uptimeMillis());
Jeff Brownc458ce92012-04-30 14:58:40 -07004049 } else if (!mLidControlsSleep) {
Jeff Brown96307042012-07-27 15:51:34 -07004050 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
Jeff Brown46b9ac02010-04-22 18:58:52 -07004051 }
4052 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004053
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004054 void setHdmiPlugged(boolean plugged) {
4055 if (mHdmiPlugged != plugged) {
4056 mHdmiPlugged = plugged;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004057 updateRotation(true, true);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004058 Intent intent = new Intent(ACTION_HDMI_PLUGGED);
Joe Onoratodc100302011-01-11 17:07:41 -08004059 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004060 intent.putExtra(EXTRA_HDMI_PLUGGED_STATE, plugged);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07004061 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004062 }
4063 }
4064
Joe Onoratoea495d42011-04-06 11:41:11 -07004065 void initializeHdmiState() {
Joe Onorato7ba631f2011-05-04 15:28:00 -07004066 boolean plugged = false;
Joe Onoratoea495d42011-04-06 11:41:11 -07004067 // watch for HDMI plug messages if the hdmi switch exists
4068 if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) {
4069 mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi");
4070
Joe Onoratoea495d42011-04-06 11:41:11 -07004071 final String filename = "/sys/class/switch/hdmi/state";
4072 FileReader reader = null;
4073 try {
4074 reader = new FileReader(filename);
4075 char[] buf = new char[15];
4076 int n = reader.read(buf);
4077 if (n > 1) {
4078 plugged = 0 != Integer.parseInt(new String(buf, 0, n-1));
4079 }
4080 } catch (IOException ex) {
4081 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
4082 } catch (NumberFormatException ex) {
4083 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
4084 } finally {
4085 if (reader != null) {
4086 try {
4087 reader.close();
4088 } catch (IOException ex) {
4089 }
Joe Onoratodc100302011-01-11 17:07:41 -08004090 }
4091 }
4092 }
Joe Onorato7ba631f2011-05-04 15:28:00 -07004093 // This dance forces the code in setHdmiPlugged to run.
4094 // Always do this so the sticky intent is stuck (to false) if there is no hdmi.
4095 mHdmiPlugged = !plugged;
4096 setHdmiPlugged(!mHdmiPlugged);
Joe Onoratodc100302011-01-11 17:07:41 -08004097 }
4098
Dianne Hackbornc0e3f242011-08-19 14:19:10 -07004099 final Object mScreenshotLock = new Object();
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004100 ServiceConnection mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004101
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004102 final Runnable mScreenshotTimeout = new Runnable() {
4103 @Override public void run() {
4104 synchronized (mScreenshotLock) {
4105 if (mScreenshotConnection != null) {
4106 mContext.unbindService(mScreenshotConnection);
4107 mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004108 }
Winson Chung9112ec32011-06-27 13:15:32 -07004109 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004110 }
4111 };
4112
4113 // Assume this is called from the Handler thread.
4114 private void takeScreenshot() {
4115 synchronized (mScreenshotLock) {
4116 if (mScreenshotConnection != null) {
4117 return;
4118 }
4119 ComponentName cn = new ComponentName("com.android.systemui",
4120 "com.android.systemui.screenshot.TakeScreenshotService");
4121 Intent intent = new Intent();
4122 intent.setComponent(cn);
4123 ServiceConnection conn = new ServiceConnection() {
4124 @Override
4125 public void onServiceConnected(ComponentName name, IBinder service) {
4126 synchronized (mScreenshotLock) {
4127 if (mScreenshotConnection != this) {
4128 return;
4129 }
4130 Messenger messenger = new Messenger(service);
4131 Message msg = Message.obtain(null, 1);
4132 final ServiceConnection myConn = this;
4133 Handler h = new Handler(mHandler.getLooper()) {
4134 @Override
4135 public void handleMessage(Message msg) {
4136 synchronized (mScreenshotLock) {
4137 if (mScreenshotConnection == myConn) {
4138 mContext.unbindService(mScreenshotConnection);
4139 mScreenshotConnection = null;
4140 mHandler.removeCallbacks(mScreenshotTimeout);
4141 }
4142 }
4143 }
4144 };
4145 msg.replyTo = new Messenger(h);
Winson Chunga63bb842011-10-17 10:26:28 -07004146 msg.arg1 = msg.arg2 = 0;
4147 if (mStatusBar != null && mStatusBar.isVisibleLw())
4148 msg.arg1 = 1;
4149 if (mNavigationBar != null && mNavigationBar.isVisibleLw())
4150 msg.arg2 = 1;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004151 try {
4152 messenger.send(msg);
4153 } catch (RemoteException e) {
4154 }
4155 }
4156 }
4157 @Override
4158 public void onServiceDisconnected(ComponentName name) {}
4159 };
Amith Yamasani27b89e62013-01-16 12:30:11 -08004160 if (mContext.bindServiceAsUser(
4161 intent, conn, Context.BIND_AUTO_CREATE, UserHandle.CURRENT)) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004162 mScreenshotConnection = conn;
4163 mHandler.postDelayed(mScreenshotTimeout, 10000);
4164 }
4165 }
Winson Chung9112ec32011-06-27 13:15:32 -07004166 }
4167
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004168 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004169 @Override
Jeff Brown037c33e2014-04-09 00:31:55 -07004170 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) {
Jeff Brown96307042012-07-27 15:51:34 -07004171 if (!mSystemBooted) {
4172 // If we have not yet booted, don't let key events do anything.
4173 return 0;
4174 }
4175
Jeff Brown037c33e2014-04-09 00:31:55 -07004176 final boolean interactive = (policyFlags & FLAG_INTERACTIVE) != 0;
Jeff Brown1f245102010-11-18 20:53:46 -08004177 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
4178 final boolean canceled = event.isCanceled();
4179 final int keyCode = event.getKeyCode();
Jeff Browne20c9e02010-10-11 14:20:19 -07004180
Jeff Brown3122e442010-10-11 23:32:49 -07004181 final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0;
Jeff Brown3122e442010-10-11 23:32:49 -07004182
Mike Lockwoodc72b15f2009-11-28 20:58:22 -05004183 // If screen is off then we treat the case where the keyguard is open but hidden
4184 // the same as if it were open and in front.
4185 // This will prevent any keys other than the power button from waking the screen
4186 // when the keyguard is hidden by another activity.
Jim Miller5ecd8112013-01-09 18:50:26 -08004187 final boolean keyguardActive = (mKeyguardDelegate == null ? false :
Jeff Brown037c33e2014-04-09 00:31:55 -07004188 (interactive ?
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004189 mKeyguardDelegate.isShowingAndNotOccluded() :
Jim Miller5ecd8112013-01-09 18:50:26 -08004190 mKeyguardDelegate.isShowing()));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004191
Jeff Brown40013652012-05-16 21:22:36 -07004192 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004193 Log.d(TAG, "interceptKeyTq keycode=" + keyCode
Jeff Brown037c33e2014-04-09 00:31:55 -07004194 + " interactive=" + interactive + " keyguardActive=" + keyguardActive
Jeff Brown26875502014-01-30 21:47:47 -08004195 + " policyFlags=" + Integer.toHexString(policyFlags));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004196 }
4197
Jeff Brown037c33e2014-04-09 00:31:55 -07004198 // Basic policy based on interactive state.
Jeff Brown4d396052010-10-29 21:50:21 -07004199 int result;
Michael Wright337d9d22014-04-22 15:03:48 -07004200 boolean isWakeKey = (policyFlags & WindowManagerPolicy.FLAG_WAKE) != 0
4201 || event.isWakeKey();
Jeff Brown037c33e2014-04-09 00:31:55 -07004202 if (interactive || (isInjected && !isWakeKey)) {
Jeff Brown4d396052010-10-29 21:50:21 -07004203 // When the screen is on or if the key is injected pass the key to the application.
4204 result = ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07004205 isWakeKey = false;
Jeff Brown4d396052010-10-29 21:50:21 -07004206 } else {
4207 // When the screen is off and the key is not injected, determine whether
4208 // to wake the device but don't pass the key to the application.
4209 result = 0;
Jeff Brown26875502014-01-30 21:47:47 -08004210 if (isWakeKey && (!down || !isWakeKeyWhenScreenOff(keyCode))) {
4211 isWakeKey = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004212 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004213 }
4214
Justin Kohd378ad72013-04-01 12:18:26 -07004215 // If the key would be handled globally, just return the result, don't worry about special
4216 // key processing.
4217 if (mGlobalKeyManager.shouldHandleGlobalKey(keyCode, event)) {
Michael Wright85b1af62014-06-04 14:51:58 -07004218 if (isWakeKey) {
4219 mPowerManager.wakeUp(event.getEventTime());
4220 }
Justin Kohd378ad72013-04-01 12:18:26 -07004221 return result;
4222 }
4223
Jeff Brownbae8e772014-06-12 19:59:45 -07004224 boolean useHapticFeedback = down
4225 && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0
4226 && event.getRepeatCount() == 0;
4227
Jeff Brown4d396052010-10-29 21:50:21 -07004228 // Handle special keys.
4229 switch (keyCode) {
4230 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jeff Brownb0418da2010-11-01 15:24:01 -07004231 case KeyEvent.KEYCODE_VOLUME_UP:
4232 case KeyEvent.KEYCODE_VOLUME_MUTE: {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004233 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
4234 if (down) {
Jeff Brown037c33e2014-04-09 00:31:55 -07004235 if (interactive && !mVolumeDownKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004236 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
4237 mVolumeDownKeyTriggered = true;
4238 mVolumeDownKeyTime = event.getDownTime();
4239 mVolumeDownKeyConsumedByScreenshotChord = false;
4240 cancelPendingPowerKeyAction();
4241 interceptScreenshotChord();
4242 }
4243 } else {
4244 mVolumeDownKeyTriggered = false;
4245 cancelPendingScreenshotChordAction();
4246 }
4247 } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
4248 if (down) {
Jeff Brown037c33e2014-04-09 00:31:55 -07004249 if (interactive && !mVolumeUpKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004250 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
4251 mVolumeUpKeyTriggered = true;
4252 cancelPendingPowerKeyAction();
4253 cancelPendingScreenshotChordAction();
4254 }
4255 } else {
4256 mVolumeUpKeyTriggered = false;
4257 cancelPendingScreenshotChordAction();
4258 }
4259 }
Jeff Brown4d396052010-10-29 21:50:21 -07004260 if (down) {
Santos Cordon9eb45932014-06-27 12:28:43 -07004261 TelecommManager telecommManager = getTelecommService();
4262 if (telecommManager != null) {
4263 if (telecommManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07004264 // If an incoming call is ringing, either VOLUME key means
4265 // "silence ringer". We handle these keys here, rather than
4266 // in the InCallScreen, to make sure we'll respond to them
4267 // even if the InCallScreen hasn't come to the foreground yet.
4268 // Look for the DOWN event here, to agree with the "fallback"
4269 // behavior in the InCallScreen.
4270 Log.i(TAG, "interceptKeyBeforeQueueing:"
4271 + " VOLUME key-down while ringing: Silence ringer!");
Jeff Brown4d396052010-10-29 21:50:21 -07004272
Santos Cordon6848f722014-05-21 15:22:12 -07004273 // Silence the ringer. (It's safe to call this
4274 // even if the ringer has already been silenced.)
Santos Cordon9eb45932014-06-27 12:28:43 -07004275 telecommManager.silenceRinger();
Jeff Brown4d396052010-10-29 21:50:21 -07004276
Santos Cordon6848f722014-05-21 15:22:12 -07004277 // And *don't* pass this key thru to the current activity
4278 // (which is probably the InCallScreen.)
4279 result &= ~ACTION_PASS_TO_USER;
4280 break;
4281 }
Nancy Chen0eb1e402014-08-21 22:52:29 -07004282 if (telecommManager.isInCall()
Santos Cordon6848f722014-05-21 15:22:12 -07004283 && (result & ACTION_PASS_TO_USER) == 0) {
4284 // If we are in call but we decided not to pass the key to
RoboErik430fc482014-06-12 15:49:20 -07004285 // the application, just pass it to the session service.
4286
4287 MediaSessionLegacyHelper.getHelper(mContext)
RoboErik3c45c292014-07-08 16:47:31 -07004288 .sendVolumeKeyEvent(event, false);
Santos Cordon6848f722014-05-21 15:22:12 -07004289 break;
Jeff Brown4d396052010-10-29 21:50:21 -07004290 }
4291 }
4292
RoboErik430fc482014-06-12 15:49:20 -07004293 if ((result & ACTION_PASS_TO_USER) == 0) {
4294 // If we aren't passing to the user and no one else
4295 // handled it send it to the session manager to figure
4296 // out.
4297 MediaSessionLegacyHelper.getHelper(mContext)
RoboErik3c45c292014-07-08 16:47:31 -07004298 .sendVolumeKeyEvent(event, true);
Jeff Brown4d396052010-10-29 21:50:21 -07004299 break;
4300 }
4301 }
4302 break;
4303 }
4304
4305 case KeyEvent.KEYCODE_ENDCALL: {
4306 result &= ~ACTION_PASS_TO_USER;
4307 if (down) {
Santos Cordon9eb45932014-06-27 12:28:43 -07004308 TelecommManager telecommManager = getTelecommService();
Jeff Brown4d396052010-10-29 21:50:21 -07004309 boolean hungUp = false;
Santos Cordon9eb45932014-06-27 12:28:43 -07004310 if (telecommManager != null) {
4311 hungUp = telecommManager.endCall();
Jeff Brown4d396052010-10-29 21:50:21 -07004312 }
Jeff Brown037c33e2014-04-09 00:31:55 -07004313 interceptPowerKeyDown(!interactive || hungUp);
Jeff Brown4d396052010-10-29 21:50:21 -07004314 } else {
4315 if (interceptPowerKeyUp(canceled)) {
4316 if ((mEndcallBehavior
4317 & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) {
4318 if (goHome()) {
4319 break;
Dianne Hackborn0041e972009-07-24 17:14:43 -07004320 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004321 }
Jeff Brown4d396052010-10-29 21:50:21 -07004322 if ((mEndcallBehavior
4323 & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) {
Jeff Brownc12035c2014-08-13 18:52:25 -07004324 mPowerManager.goToSleep(event.getEventTime(),
4325 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
Jeff Brown26875502014-01-30 21:47:47 -08004326 isWakeKey = false;
Jeff Brown4d396052010-10-29 21:50:21 -07004327 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004328 }
Jeff Brown4d396052010-10-29 21:50:21 -07004329 }
4330 break;
4331 }
4332
4333 case KeyEvent.KEYCODE_POWER: {
4334 result &= ~ACTION_PASS_TO_USER;
4335 if (down) {
Jeff Brown26c6a502014-04-11 02:15:54 -07004336 boolean panic = mImmersiveModeConfirmation.onPowerKeyDown(interactive,
John Spurlockd9b70bd2014-02-06 17:02:44 -05004337 event.getDownTime(), isImmersiveMode(mLastSystemUiFlags));
4338 if (panic) {
4339 mHandler.post(mRequestTransientNav);
4340 }
Jeff Brown037c33e2014-04-09 00:31:55 -07004341 if (interactive && !mPowerKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004342 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
4343 mPowerKeyTriggered = true;
4344 mPowerKeyTime = event.getDownTime();
4345 interceptScreenshotChord();
Winson Chung9112ec32011-06-27 13:15:32 -07004346 }
Winson Chung9112ec32011-06-27 13:15:32 -07004347
Santos Cordon9eb45932014-06-27 12:28:43 -07004348 TelecommManager telecommManager = getTelecommService();
Jeff Brown4d396052010-10-29 21:50:21 -07004349 boolean hungUp = false;
Santos Cordon9eb45932014-06-27 12:28:43 -07004350 if (telecommManager != null) {
4351 if (telecommManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07004352 // Pressing Power while there's a ringing incoming
4353 // call should silence the ringer.
Santos Cordon9eb45932014-06-27 12:28:43 -07004354 telecommManager.silenceRinger();
Santos Cordon6848f722014-05-21 15:22:12 -07004355 } else if ((mIncallPowerBehavior
4356 & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0
Nancy Chen0eb1e402014-08-21 22:52:29 -07004357 && telecommManager.isInCall() && interactive) {
Santos Cordon6848f722014-05-21 15:22:12 -07004358 // Otherwise, if "Power button ends call" is enabled,
4359 // the Power button will hang up any current active call.
Santos Cordon9eb45932014-06-27 12:28:43 -07004360 hungUp = telecommManager.endCall();
Jeff Brown4d396052010-10-29 21:50:21 -07004361 }
4362 }
Jeff Brown037c33e2014-04-09 00:31:55 -07004363 interceptPowerKeyDown(!interactive || hungUp
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004364 || mVolumeDownKeyTriggered || mVolumeUpKeyTriggered);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004365 } else {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004366 mPowerKeyTriggered = false;
4367 cancelPendingScreenshotChordAction();
4368 if (interceptPowerKeyUp(canceled || mPendingPowerKeyUpCanceled)) {
Jeff Brown6d8fd272014-05-20 21:24:38 -07004369 powerShortPress(event.getEventTime());
Jeff Brown26875502014-01-30 21:47:47 -08004370 isWakeKey = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004371 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004372 mPendingPowerKeyUpCanceled = false;
Jeff Brown4d396052010-10-29 21:50:21 -07004373 }
4374 break;
4375 }
4376
Jeff Brown6212a492014-03-07 13:58:47 -08004377 case KeyEvent.KEYCODE_SLEEP: {
4378 result &= ~ACTION_PASS_TO_USER;
Jeff Brownbae8e772014-06-12 19:59:45 -07004379 if (!mPowerManager.isInteractive()) {
4380 useHapticFeedback = false; // suppress feedback if already non-interactive
4381 }
Jeff Brownc12035c2014-08-13 18:52:25 -07004382 mPowerManager.goToSleep(event.getEventTime(),
4383 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
Jeff Brown6212a492014-03-07 13:58:47 -08004384 isWakeKey = false;
4385 break;
4386 }
4387
4388 case KeyEvent.KEYCODE_WAKEUP: {
4389 result &= ~ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07004390 isWakeKey = true;
Jeff Brown6212a492014-03-07 13:58:47 -08004391 break;
4392 }
4393
Jeff Brown4d396052010-10-29 21:50:21 -07004394 case KeyEvent.KEYCODE_MEDIA_PLAY:
4395 case KeyEvent.KEYCODE_MEDIA_PAUSE:
4396 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
4397 if (down) {
Santos Cordon9eb45932014-06-27 12:28:43 -07004398 TelecommManager telecommManager = getTelecommService();
4399 if (telecommManager != null) {
Nancy Chen0eb1e402014-08-21 22:52:29 -07004400 if (telecommManager.isInCall()) {
Santos Cordon6848f722014-05-21 15:22:12 -07004401 // Suppress PLAY/PAUSE toggle when phone is ringing or in-call
4402 // to avoid music playback.
4403 break;
Jeff Brown3122e442010-10-11 23:32:49 -07004404 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004405 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004406 }
Jeff Brown4d396052010-10-29 21:50:21 -07004407 case KeyEvent.KEYCODE_HEADSETHOOK:
4408 case KeyEvent.KEYCODE_MUTE:
4409 case KeyEvent.KEYCODE_MEDIA_STOP:
4410 case KeyEvent.KEYCODE_MEDIA_NEXT:
4411 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
4412 case KeyEvent.KEYCODE_MEDIA_REWIND:
4413 case KeyEvent.KEYCODE_MEDIA_RECORD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09004414 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
4415 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: {
Jeff Brown4d396052010-10-29 21:50:21 -07004416 if ((result & ACTION_PASS_TO_USER) == 0) {
4417 // Only do this if we would otherwise not pass it to the user. In that
4418 // case, the PhoneWindow class will do the same thing, except it will
4419 // only do it if the showing app doesn't process the key on its own.
Jeff Brown40013652012-05-16 21:22:36 -07004420 // Note that we need to make a copy of the key event here because the
4421 // original key event will be recycled when we return.
Jeff Brown4d396052010-10-29 21:50:21 -07004422 mBroadcastWakeLock.acquire();
Jeff Brown40013652012-05-16 21:22:36 -07004423 Message msg = mHandler.obtainMessage(MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK,
4424 new KeyEvent(event));
4425 msg.setAsynchronous(true);
4426 msg.sendToTarget();
Jeff Brown4d396052010-10-29 21:50:21 -07004427 }
4428 break;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004429 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004430
Jeff Brown4d396052010-10-29 21:50:21 -07004431 case KeyEvent.KEYCODE_CALL: {
4432 if (down) {
Santos Cordon9eb45932014-06-27 12:28:43 -07004433 TelecommManager telecommManager = getTelecommService();
4434 if (telecommManager != null) {
4435 if (telecommManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07004436 Log.i(TAG, "interceptKeyBeforeQueueing:"
4437 + " CALL key-down while ringing: Answer the call!");
Santos Cordon9eb45932014-06-27 12:28:43 -07004438 telecommManager.acceptRingingCall();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004439
Santos Cordon6848f722014-05-21 15:22:12 -07004440 // And *don't* pass this key thru to the current activity
4441 // (which is presumably the InCallScreen.)
4442 result &= ~ACTION_PASS_TO_USER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004443 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004444 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004445 }
Jeff Brown4d396052010-10-29 21:50:21 -07004446 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004447 }
4448 }
Jeff Brown26875502014-01-30 21:47:47 -08004449
Jeff Brownbae8e772014-06-12 19:59:45 -07004450 if (useHapticFeedback) {
4451 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
4452 }
4453
Jeff Brown26875502014-01-30 21:47:47 -08004454 if (isWakeKey) {
4455 mPowerManager.wakeUp(event.getEventTime());
4456 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004457 return result;
4458 }
4459
Jeff Brown1c2e4942012-11-06 16:32:01 -08004460 /**
4461 * When the screen is off we ignore some keys that might otherwise typically
4462 * be considered wake keys. We filter them out here.
4463 *
4464 * {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it
4465 * is always considered a wake key.
4466 */
4467 private boolean isWakeKeyWhenScreenOff(int keyCode) {
4468 switch (keyCode) {
4469 // ignore volume keys unless docked
4470 case KeyEvent.KEYCODE_VOLUME_UP:
4471 case KeyEvent.KEYCODE_VOLUME_DOWN:
4472 case KeyEvent.KEYCODE_VOLUME_MUTE:
4473 return mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED;
4474
4475 // ignore media and camera keys
4476 case KeyEvent.KEYCODE_MUTE:
4477 case KeyEvent.KEYCODE_HEADSETHOOK:
4478 case KeyEvent.KEYCODE_MEDIA_PLAY:
4479 case KeyEvent.KEYCODE_MEDIA_PAUSE:
4480 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
4481 case KeyEvent.KEYCODE_MEDIA_STOP:
4482 case KeyEvent.KEYCODE_MEDIA_NEXT:
4483 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
4484 case KeyEvent.KEYCODE_MEDIA_REWIND:
4485 case KeyEvent.KEYCODE_MEDIA_RECORD:
4486 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09004487 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK:
Jeff Brown1c2e4942012-11-06 16:32:01 -08004488 case KeyEvent.KEYCODE_CAMERA:
4489 return false;
4490 }
4491 return true;
4492 }
4493
4494
Jeff Brown56194eb2011-03-02 19:23:13 -08004495 /** {@inheritDoc} */
4496 @Override
Jeff Brown037c33e2014-04-09 00:31:55 -07004497 public int interceptWakeMotionBeforeQueueing(long whenNanos, int policyFlags) {
4498 // We already know this is a wake motion so just wake up.
4499 // Note that we would observe policyFlags containing
4500 // FLAG_WAKE and FLAG_INTERACTIVE here.
4501 mPowerManager.wakeUp(whenNanos / 1000000);
4502 return 0;
Jeff Brown56194eb2011-03-02 19:23:13 -08004503 }
4504
Jeff Brown40013652012-05-16 21:22:36 -07004505 void dispatchMediaKeyWithWakeLock(KeyEvent event) {
4506 if (DEBUG_INPUT) {
4507 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: " + event);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004508 }
4509
Jeff Brown40013652012-05-16 21:22:36 -07004510 if (mHavePendingMediaKeyRepeatWithWakeLock) {
4511 if (DEBUG_INPUT) {
4512 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: canceled repeat");
4513 }
4514
4515 mHandler.removeMessages(MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK);
4516 mHavePendingMediaKeyRepeatWithWakeLock = false;
4517 mBroadcastWakeLock.release(); // pending repeat was holding onto the wake lock
4518 }
4519
4520 dispatchMediaKeyWithWakeLockToAudioService(event);
4521
4522 if (event.getAction() == KeyEvent.ACTION_DOWN
4523 && event.getRepeatCount() == 0) {
4524 mHavePendingMediaKeyRepeatWithWakeLock = true;
4525
4526 Message msg = mHandler.obtainMessage(
4527 MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK, event);
4528 msg.setAsynchronous(true);
4529 mHandler.sendMessageDelayed(msg, ViewConfiguration.getKeyRepeatTimeout());
4530 } else {
4531 mBroadcastWakeLock.release();
4532 }
4533 }
4534
4535 void dispatchMediaKeyRepeatWithWakeLock(KeyEvent event) {
4536 mHavePendingMediaKeyRepeatWithWakeLock = false;
4537
4538 KeyEvent repeatEvent = KeyEvent.changeTimeRepeat(event,
4539 SystemClock.uptimeMillis(), 1, event.getFlags() | KeyEvent.FLAG_LONG_PRESS);
4540 if (DEBUG_INPUT) {
4541 Slog.d(TAG, "dispatchMediaKeyRepeatWithWakeLock: " + repeatEvent);
4542 }
4543
4544 dispatchMediaKeyWithWakeLockToAudioService(repeatEvent);
4545 mBroadcastWakeLock.release();
4546 }
4547
4548 void dispatchMediaKeyWithWakeLockToAudioService(KeyEvent event) {
4549 if (ActivityManagerNative.isSystemReady()) {
RoboErik430fc482014-06-12 15:49:20 -07004550 MediaSessionLegacyHelper.getHelper(mContext).sendMediaButtonEvent(event, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004551 }
4552 }
4553
Mike Lockwood1753f7f2009-08-24 14:49:07 -07004554 BroadcastReceiver mDockReceiver = new BroadcastReceiver() {
Craig Mautnereee29c42013-01-17 14:44:34 -08004555 @Override
Mike Lockwood1753f7f2009-08-24 14:49:07 -07004556 public void onReceive(Context context, Intent intent) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07004557 if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) {
4558 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
4559 Intent.EXTRA_DOCK_STATE_UNDOCKED);
Daniel Sandler6396c722013-04-16 20:19:09 -04004560 } else {
4561 try {
4562 IUiModeManager uiModeService = IUiModeManager.Stub.asInterface(
4563 ServiceManager.getService(Context.UI_MODE_SERVICE));
4564 mUiMode = uiModeService.getCurrentModeType();
4565 } catch (RemoteException e) {
4566 }
Dianne Hackborn80fa1662009-10-07 14:02:10 -07004567 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004568 updateRotation(true);
Craig Mautnereee29c42013-01-17 14:44:34 -08004569 synchronized (mLock) {
4570 updateOrientationListenerLp();
4571 }
Mike Lockwood1753f7f2009-08-24 14:49:07 -07004572 }
4573 };
4574
Jeff Brown6aaf2952012-10-05 16:01:08 -07004575 BroadcastReceiver mDreamReceiver = new BroadcastReceiver() {
4576 @Override
4577 public void onReceive(Context context, Intent intent) {
4578 if (Intent.ACTION_DREAMING_STARTED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004579 if (mKeyguardDelegate != null) {
4580 mKeyguardDelegate.onDreamingStarted();
Jeff Brown6aaf2952012-10-05 16:01:08 -07004581 }
4582 } else if (Intent.ACTION_DREAMING_STOPPED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004583 if (mKeyguardDelegate != null) {
4584 mKeyguardDelegate.onDreamingStopped();
Jeff Brown6aaf2952012-10-05 16:01:08 -07004585 }
4586 }
4587 }
4588 };
4589
Christopher Tate5e08af02012-09-21 17:17:22 -07004590 BroadcastReceiver mMultiuserReceiver = new BroadcastReceiver() {
4591 @Override
4592 public void onReceive(Context context, Intent intent) {
4593 if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) {
4594 // tickle the settings observer: this first ensures that we're
4595 // observing the relevant settings for the newly-active user,
4596 // and then updates our own bookkeeping based on the now-
4597 // current user.
4598 mSettingsObserver.onChange(false);
John Spurlockce479d82012-11-29 09:52:21 -05004599
4600 // force a re-application of focused window sysui visibility.
4601 // the window may never have been shown for this user
4602 // e.g. the keyguard when going through the new-user setup flow
John Spurlock04db1762013-05-13 12:46:41 -04004603 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
John Spurlockce479d82012-11-29 09:52:21 -05004604 mLastSystemUiFlags = 0;
4605 updateSystemUiVisibilityLw();
4606 }
Christopher Tate5e08af02012-09-21 17:17:22 -07004607 }
4608 }
4609 };
4610
John Spurlockd9b70bd2014-02-06 17:02:44 -05004611 private final Runnable mRequestTransientNav = new Runnable() {
4612 @Override
4613 public void run() {
4614 requestTransientBars(mNavigationBar);
4615 }
4616 };
4617
John Spurlocke1f366f2013-08-05 12:22:40 -04004618 private void requestTransientBars(WindowState swipeTarget) {
John Spurlock04db1762013-05-13 12:46:41 -04004619 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Maurice Lam99c6e072014-04-28 18:24:28 -07004620 if (!isUserSetupComplete()) {
4621 // Swipe-up for navigation bar is disabled during setup
4622 return;
4623 }
John Spurlock27735a42013-08-14 17:57:38 -04004624 boolean sb = mStatusBarController.checkShowTransientBarLw();
4625 boolean nb = mNavigationBarController.checkShowTransientBarLw();
John Spurlockad3e6cb2013-04-30 08:47:43 -04004626 if (sb || nb) {
John Spurlocke1f366f2013-08-05 12:22:40 -04004627 WindowState barTarget = sb ? mStatusBar : mNavigationBar;
4628 if (sb ^ nb && barTarget != swipeTarget) {
4629 if (DEBUG) Slog.d(TAG, "Not showing transient bar, wrong swipe target");
John Spurlockad3e6cb2013-04-30 08:47:43 -04004630 return;
4631 }
John Spurlock27735a42013-08-14 17:57:38 -04004632 if (sb) mStatusBarController.showTransient();
4633 if (nb) mNavigationBarController.showTransient();
John Spurlockf1a36642013-10-12 17:50:42 -04004634 mImmersiveModeConfirmation.confirmCurrentPrompt();
John Spurlockad3e6cb2013-04-30 08:47:43 -04004635 updateSystemUiVisibilityLw();
John Spurlock32beb2c2013-03-11 10:16:47 -04004636 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04004637 }
4638 }
4639
Jeff Brownc38c9be2012-10-04 13:16:19 -07004640 @Override
Jeff Brown140ffc72014-05-01 15:18:00 -07004641 public void goingToSleep(int why) {
Dianne Hackborn74489012009-03-24 20:50:09 -07004642 EventLog.writeEvent(70000, 0);
The Android Open Source Project0727d222009-03-11 12:11:58 -07004643 synchronized (mLock) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004644 mScreenOnEarly = false;
4645 mScreenOnFully = false;
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07004646 }
Jim Miller5ecd8112013-01-09 18:50:26 -08004647 if (mKeyguardDelegate != null) {
4648 mKeyguardDelegate.onScreenTurnedOff(why);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004649 }
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07004650 synchronized (mLock) {
Jeff Browna20dda42014-05-27 20:57:24 -07004651 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07004652 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05004653 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07004654 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004655 }
4656
Jeff Brownc38c9be2012-10-04 13:16:19 -07004657 @Override
Jeff Brown140ffc72014-05-01 15:18:00 -07004658 public void wakingUp(final ScreenOnListener screenOnListener) {
Dianne Hackborn74489012009-03-24 20:50:09 -07004659 EventLog.writeEvent(70000, 1);
Craig Mautner8a0da012014-05-31 15:13:37 -07004660 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turning on...",
4661 new RuntimeException("here").fillInStackTrace());
4662 mHandler.obtainMessage(MSG_WAKING_UP, screenOnListener).sendToTarget();
4663 }
4664
4665 // Called on the mHandler thread.
4666 private void handleWakingUp(final ScreenOnListener screenOnListener) {
4667 if (screenOnListener != null) {
Craig Mautner13f6ea72014-06-23 14:57:02 -07004668 mScreenOnListener = screenOnListener;
Dianne Hackborn40011092011-09-22 13:37:48 -07004669 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07004670
The Android Open Source Project0727d222009-03-11 12:11:58 -07004671 synchronized (mLock) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004672 mScreenOnEarly = true;
Jeff Browna20dda42014-05-27 20:57:24 -07004673 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07004674 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05004675 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07004676 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07004677
Craig Mautner8a0da012014-05-31 15:13:37 -07004678 mKeyguardDrawComplete = false;
4679 mWindowManagerDrawComplete = false;
Jim Miller5ecd8112013-01-09 18:50:26 -08004680 if (mKeyguardDelegate != null) {
Craig Mautner8a0da012014-05-31 15:13:37 -07004681 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
4682 mHandler.sendEmptyMessageDelayed(MSG_KEYGUARD_DRAWN_TIMEOUT, 1000);
4683 mKeyguardDelegate.onScreenTurnedOn(mKeyguardDelegateCallback);
Jeff Brownc38c9be2012-10-04 13:16:19 -07004684 } else {
Craig Mautner8a0da012014-05-31 15:13:37 -07004685 if (DEBUG_WAKEUP) Slog.d(TAG, "null mKeyguardDelegate: setting mKeyguardDrawComplete.");
4686 mKeyguardDrawComplete = true;
Jeff Brownc38c9be2012-10-04 13:16:19 -07004687 }
Craig Mautner8a0da012014-05-31 15:13:37 -07004688 mWindowManagerInternal.waitForAllWindowsDrawn(mWindowManagerDrawCallback, 500);
Jeff Brownc38c9be2012-10-04 13:16:19 -07004689 }
4690
Craig Mautner8a0da012014-05-31 15:13:37 -07004691 // Called on the mHandler thread.
4692 private void finishScreenTurningOn() {
4693 if (DEBUG_WAKEUP) Slog.d(TAG,
4694 "finishScreenTurningOn: mKeyguardDrawComplete=" + mKeyguardDrawComplete
4695 + " mWindowManagerDrawComplete=" + mWindowManagerDrawComplete);
4696 if (!mKeyguardDrawComplete || !mWindowManagerDrawComplete) {
4697 return;
Jeff Brownc38c9be2012-10-04 13:16:19 -07004698 }
4699
Craig Mautner13f6ea72014-06-23 14:57:02 -07004700 ScreenOnListener screenOnListener;
Jeff Brownc38c9be2012-10-04 13:16:19 -07004701 synchronized (mLock) {
4702 mScreenOnFully = true;
Craig Mautner13f6ea72014-06-23 14:57:02 -07004703 screenOnListener = mScreenOnListener;
4704 mScreenOnListener = null;
Jeff Brownc38c9be2012-10-04 13:16:19 -07004705 }
4706
Jeff Brown4fc45272012-10-10 18:28:14 -07004707 try {
4708 mWindowManager.setEventDispatching(true);
4709 } catch (RemoteException unhandled) {
4710 }
4711
Craig Mautner13f6ea72014-06-23 14:57:02 -07004712 if (screenOnListener != null) {
4713 screenOnListener.onScreenOn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07004714 }
Craig Mautner8a0da012014-05-31 15:13:37 -07004715
4716 setKeyguardDrawn();
Craig Mautnera631d492014-08-05 15:16:01 -07004717
4718 if (mBootMessageNeedsHiding) {
4719 handleHideBootMessage();
4720 mBootMessageNeedsHiding = false;
4721 }
4722 }
4723
4724 private void handleHideBootMessage() {
4725 if (mBootMsgDialog == null) {
4726 if (DEBUG_WAKEUP) Slog.d(TAG, "handleHideBootMessage: boot message not up");
4727 return;
4728 }
4729 if (!mKeyguardDrawComplete || !mWindowManagerDrawComplete) {
4730 if (DEBUG_WAKEUP) Slog.d(TAG, "handleHideBootMessage: deferring until keyguard ready");
4731 mBootMessageNeedsHiding = true;
4732 return;
4733 }
4734 if (DEBUG_WAKEUP) Slog.d(TAG, "handleHideBootMessage: dismissing");
4735 mBootMsgDialog.dismiss();
4736 mBootMsgDialog = null;
Jeff Brownc38c9be2012-10-04 13:16:19 -07004737 }
4738
4739 @Override
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004740 public boolean isScreenOnEarly() {
4741 return mScreenOnEarly;
4742 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07004743
4744 @Override
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004745 public boolean isScreenOnFully() {
4746 return mScreenOnFully;
Dianne Hackborn08743722009-12-21 12:16:51 -08004747 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07004748
Dianne Hackborn08743722009-12-21 12:16:51 -08004749 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07004750 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004751 public void enableKeyguard(boolean enabled) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004752 if (mKeyguardDelegate != null) {
4753 mKeyguardDelegate.setKeyguardEnabled(enabled);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004754 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004755 }
4756
4757 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07004758 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004759 public void exitKeyguardSecurely(OnKeyguardExitResult callback) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004760 if (mKeyguardDelegate != null) {
4761 mKeyguardDelegate.verifyUnlock(callback);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004762 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004763 }
4764
Mike Lockwoodf7913302009-11-28 22:27:10 -05004765 private boolean keyguardIsShowingTq() {
Jim Miller5ecd8112013-01-09 18:50:26 -08004766 if (mKeyguardDelegate == null) return false;
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004767 return mKeyguardDelegate.isShowingAndNotOccluded();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004768 }
4769
Mike Lockwood520d8bc2011-02-18 13:23:13 -05004770
4771 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07004772 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05004773 public boolean isKeyguardLocked() {
4774 return keyguardOn();
4775 }
4776
4777 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07004778 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05004779 public boolean isKeyguardSecure() {
Jim Miller5ecd8112013-01-09 18:50:26 -08004780 if (mKeyguardDelegate == null) return false;
4781 return mKeyguardDelegate.isSecure();
Mike Lockwood520d8bc2011-02-18 13:23:13 -05004782 }
4783
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004784 // Returns true if keyguard is currently locked whether or not it is currently hidden.
4785 private boolean isKeyguardSecureIncludingHidden() {
4786 return mKeyguardDelegate.isSecure() && mKeyguardDelegate.isShowing();
4787 }
4788
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004789 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07004790 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004791 public boolean inKeyguardRestrictedKeyInputMode() {
Jim Miller5ecd8112013-01-09 18:50:26 -08004792 if (mKeyguardDelegate == null) return false;
4793 return mKeyguardDelegate.isInputRestricted();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004794 }
4795
Jose Lima9546b202014-07-02 17:21:51 -07004796 @Override
Dianne Hackborn90c52de2011-09-23 12:57:44 -07004797 public void dismissKeyguardLw() {
RoboErik8a2cfc32014-05-16 11:19:38 -07004798 if (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()) {
Daniel Sandler1ce804392012-11-07 15:07:12 -05004799 mHandler.post(new Runnable() {
Jose Lima9546b202014-07-02 17:21:51 -07004800 @Override
Daniel Sandler1ce804392012-11-07 15:07:12 -05004801 public void run() {
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02004802 // ask the keyguard to prompt the user to authenticate if necessary
4803 mKeyguardDelegate.dismiss();
4804 }
4805 });
4806 }
4807 }
4808
4809 public void notifyActivityDrawnForKeyguardLw() {
4810 if (mKeyguardDelegate != null) {
4811 mHandler.post(new Runnable() {
4812 @Override
4813 public void run() {
4814 mKeyguardDelegate.onActivityDrawn();
Daniel Sandler1ce804392012-11-07 15:07:12 -05004815 }
4816 });
Dianne Hackborn90c52de2011-09-23 12:57:44 -07004817 }
4818 }
4819
Jorim Jaggicff0acb2014-03-31 16:35:15 +02004820 private void setKeyguardDrawn() {
4821 synchronized (mLock) {
4822 mKeyguardDrawn = true;
4823 }
4824 try {
4825 mWindowManager.enableScreenIfNeeded();
4826 } catch (RemoteException unhandled) {
4827 }
4828 }
4829
4830 @Override
4831 public boolean isKeyguardDrawnLw() {
4832 synchronized (mLock) {
4833 return mKeyguardDrawn;
4834 }
4835 }
4836
Jorim Jaggi0d674622014-05-21 01:34:15 +02004837 @Override
Jorim Jaggie29b2db2014-05-30 23:17:03 +02004838 public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) {
Jorim Jaggi0d674622014-05-21 01:34:15 +02004839 if (mKeyguardDelegate != null) {
Jorim Jaggie29b2db2014-05-30 23:17:03 +02004840 mKeyguardDelegate.startKeyguardExitAnimation(startTime, fadeoutDuration);
Jorim Jaggi0d674622014-05-21 01:34:15 +02004841 }
4842 }
4843
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004844 void sendCloseSystemWindows() {
4845 sendCloseSystemWindows(mContext, null);
4846 }
4847
4848 void sendCloseSystemWindows(String reason) {
4849 sendCloseSystemWindows(mContext, reason);
4850 }
4851
4852 static void sendCloseSystemWindows(Context context, String reason) {
4853 if (ActivityManagerNative.isSystemReady()) {
Dianne Hackborn94a679d2009-07-28 17:51:07 -07004854 try {
4855 ActivityManagerNative.getDefault().closeSystemDialogs(reason);
4856 } catch (RemoteException e) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004857 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004858 }
4859 }
Mitsuru Oshima831d0d92009-06-16 18:27:18 -07004860
Jeff Brown01a98dd2011-09-20 15:08:29 -07004861 @Override
4862 public int rotationForOrientationLw(int orientation, int lastRotation) {
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05004863 if (false) {
4864 Slog.v(TAG, "rotationForOrientationLw(orient="
4865 + orientation + ", last=" + lastRotation
4866 + "); user=" + mUserRotation + " "
4867 + ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED)
4868 ? "USER_ROTATION_LOCKED" : "")
4869 );
4870 }
4871
Craig Mautner46ac6fa2013-08-01 10:06:34 -07004872 if (mForceDefaultOrientation) {
4873 return Surface.ROTATION_0;
4874 }
4875
The Android Open Source Project0727d222009-03-11 12:11:58 -07004876 synchronized (mLock) {
Jeff Brownc0347aa2011-09-23 17:26:09 -07004877 int sensorRotation = mOrientationListener.getProposedRotation(); // may be -1
4878 if (sensorRotation < 0) {
Jeff Brown0f862b42012-09-27 21:11:01 -07004879 sensorRotation = lastRotation;
Jeff Brownc0347aa2011-09-23 17:26:09 -07004880 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004881
Jeff Browndec6cf42011-11-15 14:08:20 -08004882 final int preferredRotation;
Jeff Brown2e7760e2012-04-11 15:14:55 -07004883 if (mLidState == LID_OPEN && mLidOpenRotation >= 0) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07004884 // Ignore sensor when lid switch is open and rotation is forced.
4885 preferredRotation = mLidOpenRotation;
4886 } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR
Jeff Brownc0347aa2011-09-23 17:26:09 -07004887 && (mCarDockEnablesAccelerometer || mCarDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07004888 // Ignore sensor when in car dock unless explicitly enabled.
4889 // This case can override the behavior of NOSENSOR, and can also
4890 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07004891 preferredRotation = mCarDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07004892 ? sensorRotation : mCarDockRotation;
Jeff Brown1a693182011-11-08 14:44:16 -08004893 } else if ((mDockMode == Intent.EXTRA_DOCK_STATE_DESK
4894 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
4895 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK)
Jeff Brownc0347aa2011-09-23 17:26:09 -07004896 && (mDeskDockEnablesAccelerometer || mDeskDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07004897 // Ignore sensor when in desk dock unless explicitly enabled.
4898 // This case can override the behavior of NOSENSOR, and can also
4899 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07004900 preferredRotation = mDeskDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07004901 ? sensorRotation : mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -07004902 } else if (mHdmiPlugged && mDemoHdmiRotationLock) {
4903 // Ignore sensor when plugged into HDMI when demo HDMI rotation lock enabled.
Jeff Browneb3e4b92011-12-06 19:54:24 -08004904 // Note that the dock orientation overrides the HDMI orientation.
Jeff Brownc82c89ed2013-04-17 17:18:15 -07004905 preferredRotation = mDemoHdmiRotation;
4906 } else if (mHdmiPlugged && mDockMode == Intent.EXTRA_DOCK_STATE_UNDOCKED
4907 && mUndockedHdmiRotation >= 0) {
4908 // Ignore sensor when plugged into HDMI and an undocked orientation has
4909 // been specified in the configuration (only for legacy devices without
4910 // full multi-display support).
4911 // Note that the dock orientation overrides the HDMI orientation.
4912 preferredRotation = mUndockedHdmiRotation;
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07004913 } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED) {
4914 // Application just wants to remain locked in the last rotation.
4915 preferredRotation = lastRotation;
Jeff Brownbcdfc622014-03-06 19:13:04 -08004916 } else if (!mSupportAutoRotation) {
4917 // If we don't support auto-rotation then bail out here and ignore
4918 // the sensor and any rotation lock settings.
4919 preferredRotation = -1;
Jeff Brown207673cd2012-06-05 17:47:11 -07004920 } else if ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE
Jeff Brown01a98dd2011-09-20 15:08:29 -07004921 && (orientation == ActivityInfo.SCREEN_ORIENTATION_USER
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07004922 || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
4923 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
4924 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
4925 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER))
Jeff Brown01a98dd2011-09-20 15:08:29 -07004926 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
4927 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
4928 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
4929 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) {
4930 // Otherwise, use sensor only if requested by the application or enabled
4931 // by default for USER or UNSPECIFIED modes. Does not apply to NOSENSOR.
Jeff Brownd3187e32011-09-21 19:26:44 -07004932 if (mAllowAllRotations < 0) {
4933 // Can't read this during init() because the context doesn't
4934 // have display metrics at that time so we cannot determine
4935 // tablet vs. phone then.
4936 mAllowAllRotations = mContext.getResources().getBoolean(
4937 com.android.internal.R.bool.config_allowAllRotations) ? 1 : 0;
4938 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004939 if (sensorRotation != Surface.ROTATION_180
Jeff Brownd3187e32011-09-21 19:26:44 -07004940 || mAllowAllRotations == 1
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07004941 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
4942 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07004943 preferredRotation = sensorRotation;
4944 } else {
4945 preferredRotation = lastRotation;
4946 }
Jeff Brown207673cd2012-06-05 17:47:11 -07004947 } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED
4948 && orientation != ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) {
4949 // Apply rotation lock. Does not apply to NOSENSOR.
4950 // The idea is that the user rotation expresses a weak preference for the direction
4951 // of gravity and as NOSENSOR is never affected by gravity, then neither should
4952 // NOSENSOR be affected by rotation lock (although it will be affected by docks).
Jeff Brown4dfce202011-10-05 12:00:10 -07004953 preferredRotation = mUserRotation;
Jeff Browndec6cf42011-11-15 14:08:20 -08004954 } else {
4955 // No overriding preference.
4956 // We will do exactly what the application asked us to do.
4957 preferredRotation = -1;
Jeff Brown01a98dd2011-09-20 15:08:29 -07004958 }
4959
Dianne Hackborne5439f22010-10-02 16:53:50 -07004960 switch (orientation) {
4961 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08004962 // Return portrait unless overridden.
4963 if (isAnyPortrait(preferredRotation)) {
4964 return preferredRotation;
4965 }
Dianne Hackborne5439f22010-10-02 16:53:50 -07004966 return mPortraitRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07004967
Jeff Brown01a98dd2011-09-20 15:08:29 -07004968 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08004969 // Return landscape unless overridden.
4970 if (isLandscapeOrSeascape(preferredRotation)) {
4971 return preferredRotation;
4972 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004973 return mLandscapeRotation;
4974
4975 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08004976 // Return reverse portrait unless overridden.
4977 if (isAnyPortrait(preferredRotation)) {
4978 return preferredRotation;
4979 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004980 return mUpsideDownRotation;
4981
4982 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08004983 // Return seascape unless overridden.
4984 if (isLandscapeOrSeascape(preferredRotation)) {
4985 return preferredRotation;
4986 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004987 return mSeascapeRotation;
4988
4989 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07004990 case ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE:
Jeff Brown01a98dd2011-09-20 15:08:29 -07004991 // Return either landscape rotation.
4992 if (isLandscapeOrSeascape(preferredRotation)) {
4993 return preferredRotation;
4994 }
4995 if (isLandscapeOrSeascape(lastRotation)) {
Jeff Brown4519f072011-01-23 13:16:01 -08004996 return lastRotation;
4997 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004998 return mLandscapeRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004999
Jeff Brown01a98dd2011-09-20 15:08:29 -07005000 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005001 case ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT:
Jeff Brown01a98dd2011-09-20 15:08:29 -07005002 // Return either portrait rotation.
5003 if (isAnyPortrait(preferredRotation)) {
5004 return preferredRotation;
5005 }
5006 if (isAnyPortrait(lastRotation)) {
5007 return lastRotation;
5008 }
5009 return mPortraitRotation;
5010
5011 default:
Jeff Brown4dfce202011-10-05 12:00:10 -07005012 // For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR,
5013 // just return the preferred orientation we already calculated.
Jeff Brown01a98dd2011-09-20 15:08:29 -07005014 if (preferredRotation >= 0) {
5015 return preferredRotation;
5016 }
Dianne Hackborndacea8c2011-04-21 17:26:39 -07005017 return Surface.ROTATION_0;
Daniel Sandlere7e5ac22011-02-22 16:10:21 -05005018 }
5019 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07005020 }
5021
Jeff Brown01a98dd2011-09-20 15:08:29 -07005022 @Override
5023 public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation) {
5024 switch (orientation) {
5025 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
5026 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
5027 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
5028 return isAnyPortrait(rotation);
5029
5030 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
5031 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
5032 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
5033 return isLandscapeOrSeascape(rotation);
5034
5035 default:
5036 return true;
5037 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07005038 }
5039
Jeff Brownc0347aa2011-09-23 17:26:09 -07005040 @Override
5041 public void setRotationLw(int rotation) {
5042 mOrientationListener.setCurrentRotation(rotation);
5043 }
5044
Jeff Brown01a98dd2011-09-20 15:08:29 -07005045 private boolean isLandscapeOrSeascape(int rotation) {
5046 return rotation == mLandscapeRotation || rotation == mSeascapeRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005047 }
5048
Jeff Brown01a98dd2011-09-20 15:08:29 -07005049 private boolean isAnyPortrait(int rotation) {
5050 return rotation == mPortraitRotation || rotation == mUpsideDownRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005051 }
5052
Jose Lima9546b202014-07-02 17:21:51 -07005053 @Override
Svetoslav Ganov80943d82013-01-02 10:25:37 -08005054 public int getUserRotationMode() {
5055 return Settings.System.getIntForUser(mContext.getContentResolver(),
Brett Chabot7e55c402013-05-16 19:38:08 -07005056 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
5057 WindowManagerPolicy.USER_ROTATION_FREE :
5058 WindowManagerPolicy.USER_ROTATION_LOCKED;
Svetoslav Ganov80943d82013-01-02 10:25:37 -08005059 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005060
5061 // User rotation: to be used when all else fails in assigning an orientation to the device
Jose Lima9546b202014-07-02 17:21:51 -07005062 @Override
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005063 public void setUserRotationMode(int mode, int rot) {
5064 ContentResolver res = mContext.getContentResolver();
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005065
5066 // mUserRotationMode and mUserRotation will be assigned by the content observer
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005067 if (mode == WindowManagerPolicy.USER_ROTATION_LOCKED) {
Christopher Tate5e08af02012-09-21 17:17:22 -07005068 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005069 Settings.System.USER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005070 rot,
5071 UserHandle.USER_CURRENT);
5072 Settings.System.putIntForUser(res,
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005073 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005074 0,
5075 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005076 } else {
Christopher Tate5e08af02012-09-21 17:17:22 -07005077 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005078 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005079 1,
5080 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005081 }
5082 }
5083
Jose Lima9546b202014-07-02 17:21:51 -07005084 @Override
Jeff Brownac143512012-04-05 18:57:33 -07005085 public void setSafeMode(boolean safeMode) {
5086 mSafeMode = safeMode;
5087 performHapticFeedbackLw(null, safeMode
5088 ? HapticFeedbackConstants.SAFE_MODE_ENABLED
5089 : HapticFeedbackConstants.SAFE_MODE_DISABLED, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005090 }
Craig Mautnereda67292013-04-28 13:50:14 -07005091
Dianne Hackborn181ceb52009-08-27 22:16:40 -07005092 static long[] getLongIntArray(Resources r, int resid) {
5093 int[] ar = r.getIntArray(resid);
5094 if (ar == null) {
5095 return null;
5096 }
5097 long[] out = new long[ar.length];
5098 for (int i=0; i<ar.length; i++) {
5099 out[i] = ar[i];
5100 }
5101 return out;
5102 }
Craig Mautnereda67292013-04-28 13:50:14 -07005103
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005104 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07005105 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005106 public void systemReady() {
Mike Lockwooded8902d2013-11-15 11:01:47 -08005107 mKeyguardDelegate = new KeyguardServiceDelegate(mContext, null);
5108 mKeyguardDelegate.onSystemReady();
5109
Jeff Brown4f5fa282014-06-12 19:19:15 -07005110 updateUiMode();
Dianne Hackbornb1a79802009-09-29 15:18:31 -07005111 synchronized (mLock) {
5112 updateOrientationListenerLp();
Dianne Hackbornc777e072010-02-12 13:07:59 -08005113 mSystemReady = true;
5114 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07005115 @Override
Dianne Hackbornc777e072010-02-12 13:07:59 -08005116 public void run() {
5117 updateSettings();
5118 }
5119 });
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005120 }
5121 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07005122
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005123 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005124 @Override
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005125 public void systemBooted() {
Jim Millere5f910a2013-10-16 18:15:46 -07005126 if (mKeyguardDelegate != null) {
5127 mKeyguardDelegate.onBootCompleted();
5128 }
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005129 synchronized (mLock) {
5130 mSystemBooted = true;
5131 }
Craig Mautner8a0da012014-05-31 15:13:37 -07005132 wakingUp(null);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005133 }
5134
Dianne Hackborn661cd522011-08-22 00:26:20 -07005135 ProgressDialog mBootMsgDialog = null;
5136
5137 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005138 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07005139 public void showBootMessage(final CharSequence msg, final boolean always) {
5140 mHandler.post(new Runnable() {
5141 @Override public void run() {
5142 if (mBootMsgDialog == null) {
Craig Stout4c0cb8a2014-04-04 13:03:10 -07005143 int theme;
5144 if (mContext.getPackageManager().hasSystemFeature(
5145 PackageManager.FEATURE_WATCH)) {
5146 theme = com.android.internal.R.style.Theme_Micro_Dialog_Alert;
5147 } else if (mContext.getPackageManager().hasSystemFeature(
5148 PackageManager.FEATURE_TELEVISION)) {
5149 theme = com.android.internal.R.style.Theme_Leanback_Dialog_Alert;
5150 } else {
5151 theme = 0;
5152 }
Vinod Krishnanfa8fc412014-04-18 14:35:53 -07005153
5154 mBootMsgDialog = new ProgressDialog(mContext, theme) {
Dianne Hackborn295e3c22011-08-25 13:19:08 -07005155 // This dialog will consume all events coming in to
5156 // it, to avoid it trying to do things too early in boot.
5157 @Override public boolean dispatchKeyEvent(KeyEvent event) {
5158 return true;
5159 }
5160 @Override public boolean dispatchKeyShortcutEvent(KeyEvent event) {
5161 return true;
5162 }
5163 @Override public boolean dispatchTouchEvent(MotionEvent ev) {
5164 return true;
5165 }
5166 @Override public boolean dispatchTrackballEvent(MotionEvent ev) {
5167 return true;
5168 }
5169 @Override public boolean dispatchGenericMotionEvent(MotionEvent ev) {
5170 return true;
5171 }
5172 @Override public boolean dispatchPopulateAccessibilityEvent(
5173 AccessibilityEvent event) {
5174 return true;
5175 }
5176 };
Dianne Hackborn661cd522011-08-22 00:26:20 -07005177 mBootMsgDialog.setTitle(R.string.android_upgrading_title);
5178 mBootMsgDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
5179 mBootMsgDialog.setIndeterminate(true);
5180 mBootMsgDialog.getWindow().setType(
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07005181 WindowManager.LayoutParams.TYPE_BOOT_PROGRESS);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005182 mBootMsgDialog.getWindow().addFlags(
5183 WindowManager.LayoutParams.FLAG_DIM_BEHIND
5184 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
5185 mBootMsgDialog.getWindow().setDimAmount(1);
Dianne Hackbornd9efb952011-12-07 14:56:51 -08005186 WindowManager.LayoutParams lp = mBootMsgDialog.getWindow().getAttributes();
5187 lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
5188 mBootMsgDialog.getWindow().setAttributes(lp);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005189 mBootMsgDialog.setCancelable(false);
5190 mBootMsgDialog.show();
5191 }
5192 mBootMsgDialog.setMessage(msg);
5193 }
5194 });
5195 }
5196
5197 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005198 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07005199 public void hideBootMessages() {
Craig Mautnera631d492014-08-05 15:16:01 -07005200 mHandler.sendEmptyMessage(MSG_HIDE_BOOT_MESSAGE);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005201 }
5202
Mike Lockwood28569302010-01-28 11:54:40 -05005203 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005204 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05005205 public void userActivity() {
Dianne Hackborndf89e652011-10-06 22:35:11 -07005206 // ***************************************
5207 // NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
5208 // ***************************************
5209 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
5210 // WITH ITS LOCKS HELD.
5211 //
5212 // This code must be VERY careful about the locks
5213 // it acquires.
5214 // In fact, the current code acquires way too many,
5215 // and probably has lurking deadlocks.
5216
Mike Lockwood28569302010-01-28 11:54:40 -05005217 synchronized (mScreenLockTimeout) {
5218 if (mLockScreenTimerActive) {
5219 // reset the timer
5220 mHandler.removeCallbacks(mScreenLockTimeout);
5221 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
5222 }
5223 }
Daniel Sandler0601eb72011-04-13 01:01:32 -04005224 }
5225
Adam Cohenf7522022012-10-03 20:03:18 -07005226 class ScreenLockTimeout implements Runnable {
5227 Bundle options;
5228
5229 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05005230 public void run() {
5231 synchronized (this) {
5232 if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard");
Jim Miller5ecd8112013-01-09 18:50:26 -08005233 if (mKeyguardDelegate != null) {
5234 mKeyguardDelegate.doKeyguardTimeout(options);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005235 }
Mike Lockwood28569302010-01-28 11:54:40 -05005236 mLockScreenTimerActive = false;
Adam Cohenf7522022012-10-03 20:03:18 -07005237 options = null;
Mike Lockwood28569302010-01-28 11:54:40 -05005238 }
5239 }
Mike Lockwood28569302010-01-28 11:54:40 -05005240
Adam Cohenf7522022012-10-03 20:03:18 -07005241 public void setLockOptions(Bundle options) {
5242 this.options = options;
5243 }
5244 }
5245
5246 ScreenLockTimeout mScreenLockTimeout = new ScreenLockTimeout();
5247
Jose Lima9546b202014-07-02 17:21:51 -07005248 @Override
Adam Cohenf7522022012-10-03 20:03:18 -07005249 public void lockNow(Bundle options) {
Jim Miller93c518e2012-01-17 15:55:31 -08005250 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null);
5251 mHandler.removeCallbacks(mScreenLockTimeout);
Adam Cohenf7522022012-10-03 20:03:18 -07005252 if (options != null) {
5253 // In case multiple calls are made to lockNow, we don't wipe out the options
5254 // until the runnable actually executes.
5255 mScreenLockTimeout.setLockOptions(options);
5256 }
Jim Miller93c518e2012-01-17 15:55:31 -08005257 mHandler.post(mScreenLockTimeout);
5258 }
5259
Mike Lockwood28569302010-01-28 11:54:40 -05005260 private void updateLockScreenTimeout() {
5261 synchronized (mScreenLockTimeout) {
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005262 boolean enable = (mAllowLockscreenWhenOn && mScreenOnEarly &&
Jim Miller5ecd8112013-01-09 18:50:26 -08005263 mKeyguardDelegate != null && mKeyguardDelegate.isSecure());
Mike Lockwood28569302010-01-28 11:54:40 -05005264 if (mLockScreenTimerActive != enable) {
5265 if (enable) {
5266 if (localLOGV) Log.v(TAG, "setting lockscreen timer");
5267 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
5268 } else {
5269 if (localLOGV) Log.v(TAG, "clearing lockscreen timer");
5270 mHandler.removeCallbacks(mScreenLockTimeout);
5271 }
5272 mLockScreenTimerActive = enable;
5273 }
5274 }
5275 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005276
5277 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07005278 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005279 public void enableScreenAfterBoot() {
5280 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07005281 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07005282 updateRotation(true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005283 }
Dianne Hackbornf54c8f92009-09-19 14:03:57 -07005284
Jeff Brownc458ce92012-04-30 14:58:40 -07005285 private void applyLidSwitchState() {
Jeff Brownc458ce92012-04-30 14:58:40 -07005286 if (mLidState == LID_CLOSED && mLidControlsSleep) {
Jeff Brown6d8fd272014-05-20 21:24:38 -07005287 mPowerManager.goToSleep(SystemClock.uptimeMillis(),
Jeff Brownc12035c2014-08-13 18:52:25 -07005288 PowerManager.GO_TO_SLEEP_REASON_LID_SWITCH,
Jeff Brown6d8fd272014-05-20 21:24:38 -07005289 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
Jeff Brownc458ce92012-04-30 14:58:40 -07005290 }
Jeff Browna20dda42014-05-27 20:57:24 -07005291
5292 synchronized (mLock) {
5293 updateWakeGestureListenerLp();
5294 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005295 }
5296
Jeff Brown4f5fa282014-06-12 19:19:15 -07005297 void updateUiMode() {
5298 if (mUiModeManager == null) {
5299 mUiModeManager = IUiModeManager.Stub.asInterface(
5300 ServiceManager.getService(Context.UI_MODE_SERVICE));
5301 }
5302 try {
5303 mUiMode = mUiModeManager.getCurrentModeType();
5304 } catch (RemoteException e) {
5305 }
5306 }
5307
Jeff Brown01a98dd2011-09-20 15:08:29 -07005308 void updateRotation(boolean alwaysSendConfiguration) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005309 try {
5310 //set orientation on WindowManager
Dianne Hackbornf87d1962012-04-04 12:48:24 -07005311 mWindowManager.updateRotation(alwaysSendConfiguration, false);
5312 } catch (RemoteException e) {
5313 // Ignore
5314 }
5315 }
5316
5317 void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) {
5318 try {
5319 //set orientation on WindowManager
5320 mWindowManager.updateRotation(alwaysSendConfiguration, forceRelayout);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005321 } catch (RemoteException e) {
5322 // Ignore
5323 }
5324 }
5325
Daniel Sandler6396c722013-04-16 20:19:09 -04005326 /**
5327 * Return an Intent to launch the currently active dock app as home. Returns
5328 * null if the standard home should be launched, which is the case if any of the following is
5329 * true:
5330 * <ul>
5331 * <li>The device is not in either car mode or desk mode
5332 * <li>The device is in car mode but ENABLE_CAR_DOCK_HOME_CAPTURE is false
5333 * <li>The device is in desk mode but ENABLE_DESK_DOCK_HOME_CAPTURE is false
5334 * <li>The device is in car mode but there's no CAR_DOCK app with METADATA_DOCK_HOME
5335 * <li>The device is in desk mode but there's no DESK_DOCK app with METADATA_DOCK_HOME
5336 * </ul>
Craig Mautnereda67292013-04-28 13:50:14 -07005337 * @return A dock intent.
Daniel Sandler6396c722013-04-16 20:19:09 -04005338 */
5339 Intent createHomeDockIntent() {
5340 Intent intent = null;
5341
5342 // What home does is based on the mode, not the dock state. That
5343 // is, when in car mode you should be taken to car home regardless
5344 // of whether we are actually in a car dock.
5345 if (mUiMode == Configuration.UI_MODE_TYPE_CAR) {
5346 if (ENABLE_CAR_DOCK_HOME_CAPTURE) {
5347 intent = mCarDockIntent;
5348 }
5349 } else if (mUiMode == Configuration.UI_MODE_TYPE_DESK) {
5350 if (ENABLE_DESK_DOCK_HOME_CAPTURE) {
5351 intent = mDeskDockIntent;
5352 }
Jeff Brown4f5fa282014-06-12 19:19:15 -07005353 } else if (mUiMode == Configuration.UI_MODE_TYPE_WATCH
5354 && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
5355 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK
5356 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK)) {
5357 // Always launch dock home from home when watch is docked, if it exists.
5358 intent = mDeskDockIntent;
Daniel Sandler6396c722013-04-16 20:19:09 -04005359 }
5360
5361 if (intent == null) {
5362 return null;
5363 }
5364
5365 ActivityInfo ai = null;
5366 ResolveInfo info = mContext.getPackageManager().resolveActivityAsUser(
5367 intent,
John Spurlockf56bef12013-07-09 09:51:46 -04005368 PackageManager.MATCH_DEFAULT_ONLY | PackageManager.GET_META_DATA,
Craig Mautnerd625ab22013-09-06 13:40:31 -07005369 mCurrentUserId);
Daniel Sandler6396c722013-04-16 20:19:09 -04005370 if (info != null) {
5371 ai = info.activityInfo;
5372 }
5373 if (ai != null
5374 && ai.metaData != null
5375 && ai.metaData.getBoolean(Intent.METADATA_DOCK_HOME)) {
5376 intent = new Intent(intent);
5377 intent.setClassName(ai.packageName, ai.name);
5378 return intent;
5379 }
5380
5381 return null;
5382 }
5383
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005384 void startDockOrHome() {
John Spurlockc8b46ca2013-04-08 12:59:26 -04005385 awakenDreams();
Daniel Sandler6396c722013-04-16 20:19:09 -04005386
5387 Intent dock = createHomeDockIntent();
5388 if (dock != null) {
5389 try {
5390 mContext.startActivityAsUser(dock, UserHandle.CURRENT);
5391 return;
5392 } catch (ActivityNotFoundException e) {
5393 }
5394 }
5395
Dianne Hackbornd8883992012-09-07 15:58:52 -07005396 mContext.startActivityAsUser(mHomeIntent, UserHandle.CURRENT);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005397 }
Craig Mautnereda67292013-04-28 13:50:14 -07005398
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005399 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005400 * goes to the home screen
5401 * @return whether it did anything
5402 */
5403 boolean goHome() {
5404 if (false) {
5405 // This code always brings home to the front.
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07005406 try {
5407 ActivityManagerNative.getDefault().stopAppSwitches();
5408 } catch (RemoteException e) {
5409 }
Dianne Hackborn94a679d2009-07-28 17:51:07 -07005410 sendCloseSystemWindows();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005411 startDockOrHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005412 } else {
5413 // This code brings home to the front or, if it is already
5414 // at the front, puts the device to sleep.
5415 try {
Wink Savilled2e6a332010-02-12 12:12:06 -08005416 if (SystemProperties.getInt("persist.sys.uts-test-mode", 0) == 1) {
5417 /// Roll back EndcallBehavior as the cupcake design to pass P1 lab entry.
5418 Log.d(TAG, "UTS-TEST-MODE");
5419 } else {
5420 ActivityManagerNative.getDefault().stopAppSwitches();
5421 sendCloseSystemWindows();
Daniel Sandler6396c722013-04-16 20:19:09 -04005422 Intent dock = createHomeDockIntent();
5423 if (dock != null) {
5424 int result = ActivityManagerNative.getDefault()
5425 .startActivityAsUser(null, null, dock,
5426 dock.resolveTypeIfNeeded(mContext.getContentResolver()),
5427 null, null, 0,
5428 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07005429 null, null, UserHandle.USER_CURRENT);
Daniel Sandler6396c722013-04-16 20:19:09 -04005430 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
5431 return false;
5432 }
5433 }
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005434 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005435 int result = ActivityManagerNative.getDefault()
Dianne Hackbornf265ea92013-01-31 15:00:51 -08005436 .startActivityAsUser(null, null, mHomeIntent,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005437 mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()),
Dianne Hackborna4972e92012-03-14 10:38:05 -07005438 null, null, 0,
5439 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07005440 null, null, UserHandle.USER_CURRENT);
Dianne Hackborna4972e92012-03-14 10:38:05 -07005441 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005442 return false;
5443 }
5444 } catch (RemoteException ex) {
5445 // bummer, the activity manager, which is in this process, is dead
5446 }
5447 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005448 return true;
5449 }
Craig Mautnereda67292013-04-28 13:50:14 -07005450
5451 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07005452 public void setCurrentOrientationLw(int newOrientation) {
5453 synchronized (mLock) {
5454 if (newOrientation != mCurrentAppOrientation) {
5455 mCurrentAppOrientation = newOrientation;
5456 updateOrientationListenerLp();
5457 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005458 }
5459 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08005460
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07005461 private void performAuditoryFeedbackForAccessibilityIfNeed() {
5462 if (!isGlobalAccessibilityGestureEnabled()) {
5463 return;
5464 }
5465 AudioManager audioManager = (AudioManager) mContext.getSystemService(
5466 Context.AUDIO_SERVICE);
5467 if (audioManager.isSilentMode()) {
5468 return;
5469 }
5470 Ringtone ringTone = RingtoneManager.getRingtone(mContext,
5471 Settings.System.DEFAULT_NOTIFICATION_URI);
5472 ringTone.setStreamType(AudioManager.STREAM_MUSIC);
5473 ringTone.play();
5474 }
Craig Mautnereda67292013-04-28 13:50:14 -07005475
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07005476 private boolean isGlobalAccessibilityGestureEnabled() {
5477 return Settings.Global.getInt(mContext.getContentResolver(),
5478 Settings.Global.ENABLE_ACCESSIBILITY_GLOBAL_GESTURE_ENABLED, 0) == 1;
5479 }
5480
Craig Mautnereda67292013-04-28 13:50:14 -07005481 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07005482 public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) {
Svetoslav Ganov96179212012-10-10 14:17:45 -07005483 if (!mVibrator.hasVibrator()) {
5484 return false;
5485 }
Christopher Tate5e08af02012-09-21 17:17:22 -07005486 final boolean hapticsDisabled = Settings.System.getIntForUser(mContext.getContentResolver(),
5487 Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) == 0;
Jeff Brown82379ba2014-07-25 19:03:28 -07005488 if (hapticsDisabled && !always) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005489 return false;
5490 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08005491 long[] pattern = null;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005492 switch (effectId) {
5493 case HapticFeedbackConstants.LONG_PRESS:
Amith Yamasanic33cb712010-02-10 15:21:49 -08005494 pattern = mLongPressVibePattern;
5495 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07005496 case HapticFeedbackConstants.VIRTUAL_KEY:
Amith Yamasanic33cb712010-02-10 15:21:49 -08005497 pattern = mVirtualKeyVibePattern;
5498 break;
5499 case HapticFeedbackConstants.KEYBOARD_TAP:
5500 pattern = mKeyboardTapVibePattern;
5501 break;
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07005502 case HapticFeedbackConstants.CLOCK_TICK:
5503 pattern = mClockTickVibePattern;
5504 break;
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07005505 case HapticFeedbackConstants.CALENDAR_DATE:
5506 pattern = mCalendarDateVibePattern;
5507 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07005508 case HapticFeedbackConstants.SAFE_MODE_DISABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08005509 pattern = mSafeModeDisabledVibePattern;
5510 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07005511 case HapticFeedbackConstants.SAFE_MODE_ENABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08005512 pattern = mSafeModeEnabledVibePattern;
5513 break;
Amith Yamasanic33cb712010-02-10 15:21:49 -08005514 default:
5515 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005516 }
Dianne Hackbornf265ea92013-01-31 15:00:51 -08005517 int owningUid;
5518 String owningPackage;
5519 if (win != null) {
5520 owningUid = win.getOwningUid();
5521 owningPackage = win.getOwningPackage();
5522 } else {
5523 owningUid = android.os.Process.myUid();
Dianne Hackborn95d78532013-09-11 09:51:14 -07005524 owningPackage = mContext.getOpPackageName();
Dianne Hackbornf265ea92013-01-31 15:00:51 -08005525 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08005526 if (pattern.length == 1) {
5527 // One-shot vibration
John Spurlock7b414672014-07-18 13:02:39 -04005528 mVibrator.vibrate(owningUid, owningPackage, pattern[0], VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08005529 } else {
5530 // Pattern vibration
John Spurlock7b414672014-07-18 13:02:39 -04005531 mVibrator.vibrate(owningUid, owningPackage, pattern, -1, VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08005532 }
5533 return true;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005534 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005535
5536 @Override
5537 public void keepScreenOnStartedLw() {
Daniel Sandler0601eb72011-04-13 01:01:32 -04005538 }
5539
Jeff Brownc38c9be2012-10-04 13:16:19 -07005540 @Override
5541 public void keepScreenOnStoppedLw() {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01005542 if (mKeyguardDelegate != null && !mKeyguardDelegate.isShowingAndNotOccluded()) {
Jim Miller25190572013-02-28 17:36:24 -08005543 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005544 }
5545 }
Mike Lockwoodfcb39242009-10-21 23:01:07 -04005546
Dianne Hackborndf89e652011-10-06 22:35:11 -07005547 private int updateSystemUiVisibilityLw() {
Joe Onorato664644d2011-01-23 17:53:23 -08005548 // If there is no window focused, there will be nobody to handle the events
5549 // anyway, so just hang on in whatever state we're in until things settle down.
John Spurlock79da8332013-09-20 12:04:47 -04005550 WindowState win = mFocusedWindow != null ? mFocusedWindow : mTopFullscreenOpaqueWindowState;
5551 if (win == null) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07005552 return 0;
5553 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01005554 if ((win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 && mHideLockScreen == true) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07005555 // We are updating at a point where the keyguard has gotten
5556 // focus, but we were last in a state where the top window is
5557 // hiding it. This is probably because the keyguard as been
5558 // shown while the top window was displayed, so we want to ignore
5559 // it here because this is just a very transient change and it
5560 // will quickly lose focus once it correctly gets hidden.
5561 return 0;
5562 }
John Spurlock32beb2c2013-03-11 10:16:47 -04005563
John Spurlock1db8b682014-02-18 11:18:59 -05005564 int tmpVisibility = PolicyControl.getSystemUiVisibility(win, null)
Dianne Hackborne26ab702011-10-16 13:21:33 -07005565 & ~mResettingSystemUiFlags
5566 & ~mForceClearedSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04005567 if (mForcingShowNavBar && win.getSurfaceLayer() < mForcingShowNavBarLayer) {
John Spurlockc6d1c602014-01-17 15:22:06 -05005568 tmpVisibility &= ~PolicyControl.adjustClearableFlags(win, View.SYSTEM_UI_CLEARABLE_FLAGS);
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08005569 }
John Spurlock79da8332013-09-20 12:04:47 -04005570 final int visibility = updateSystemBarsLw(win, mLastSystemUiFlags, tmpVisibility);
John Spurlockad3e6cb2013-04-30 08:47:43 -04005571 final int diff = visibility ^ mLastSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04005572 final boolean needsMenu = win.getNeedsMenuLw(mTopFullscreenOpaqueWindowState);
Dianne Hackborne0f085d2011-11-30 18:41:15 -08005573 if (diff == 0 && mLastFocusNeedsMenu == needsMenu
John Spurlock79da8332013-09-20 12:04:47 -04005574 && mFocusedApp == win.getAppToken()) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07005575 return 0;
5576 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07005577 mLastSystemUiFlags = visibility;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08005578 mLastFocusNeedsMenu = needsMenu;
John Spurlock79da8332013-09-20 12:04:47 -04005579 mFocusedApp = win.getAppToken();
Dianne Hackborndf89e652011-10-06 22:35:11 -07005580 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07005581 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07005582 public void run() {
Dianne Hackborn42e620c2012-06-24 13:20:51 -07005583 try {
5584 IStatusBarService statusbar = getStatusBarService();
5585 if (statusbar != null) {
5586 statusbar.setSystemUiVisibility(visibility, 0xffffffff);
5587 statusbar.topAppWindowChanged(needsMenu);
Joe Onorato664644d2011-01-23 17:53:23 -08005588 }
Dianne Hackborn42e620c2012-06-24 13:20:51 -07005589 } catch (RemoteException e) {
5590 // re-acquire status bar service next time it is needed.
5591 mStatusBarService = null;
Joe Onorato664644d2011-01-23 17:53:23 -08005592 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07005593 }
5594 });
5595 return diff;
Joe Onorato664644d2011-01-23 17:53:23 -08005596 }
5597
John Spurlock79da8332013-09-20 12:04:47 -04005598 private int updateSystemBarsLw(WindowState win, int oldVis, int vis) {
John Spurlockbd957402013-10-03 11:38:39 -04005599 // apply translucent bar vis flags
Jorim Jaggi380ecb82014-03-14 17:25:20 +01005600 WindowState transWin = isStatusBarKeyguard() && !mHideLockScreen
5601 ? mStatusBar
John Spurlockbd957402013-10-03 11:38:39 -04005602 : mTopFullscreenOpaqueWindowState;
5603 vis = mStatusBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
5604 vis = mNavigationBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
5605
John Spurlock27735a42013-08-14 17:57:38 -04005606 // prevent status bar interaction from clearing certain flags
John Spurlock79da8332013-09-20 12:04:47 -04005607 boolean statusBarHasFocus = win.getAttrs().type == TYPE_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04005608 if (statusBarHasFocus && !isStatusBarKeyguard()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04005609 int flags = View.SYSTEM_UI_FLAG_FULLSCREEN
5610 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlockcfc359a2013-09-05 10:42:03 -04005611 | View.SYSTEM_UI_FLAG_IMMERSIVE
Jorim Jaggi5cf17872014-03-26 18:31:48 +01005612 | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
John Spurlock08ffcf52014-07-11 10:13:46 -04005613 if (mHideLockScreen) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01005614 flags |= View.STATUS_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSLUCENT;
5615 }
John Spurlockbd957402013-10-03 11:38:39 -04005616 vis = (vis & ~flags) | (oldVis & flags);
John Spurlockad3e6cb2013-04-30 08:47:43 -04005617 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04005618
Adrian Roos4fb3ee32014-08-22 19:29:09 +02005619 if (!areTranslucentBarsAllowed() && transWin != mStatusBar) {
Adrian Roosea562512014-05-05 13:33:03 +02005620 vis &= ~(View.NAVIGATION_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSLUCENT
5621 | View.SYSTEM_UI_TRANSPARENT);
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07005622 }
5623
John Spurlock27735a42013-08-14 17:57:38 -04005624 // update status bar
John Spurlockf1a36642013-10-12 17:50:42 -04005625 boolean immersiveSticky =
5626 (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
John Spurlock27735a42013-08-14 17:57:38 -04005627 boolean hideStatusBarWM =
John Spurlockbd957402013-10-03 11:38:39 -04005628 mTopFullscreenOpaqueWindowState != null &&
John Spurlockc6d1c602014-01-17 15:22:06 -05005629 (PolicyControl.getWindowFlags(mTopFullscreenOpaqueWindowState, null)
John Spurlock27735a42013-08-14 17:57:38 -04005630 & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0;
5631 boolean hideStatusBarSysui =
5632 (vis & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04005633 boolean hideNavBarSysui =
5634 (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0;
John Spurlockad3e6cb2013-04-30 08:47:43 -04005635
John Spurlock27735a42013-08-14 17:57:38 -04005636 boolean transientStatusBarAllowed =
5637 mStatusBar != null && (
5638 hideStatusBarWM
John Spurlockf1a36642013-10-12 17:50:42 -04005639 || (hideStatusBarSysui && immersiveSticky)
John Spurlock27735a42013-08-14 17:57:38 -04005640 || statusBarHasFocus);
5641
John Spurlockf1a36642013-10-12 17:50:42 -04005642 boolean transientNavBarAllowed =
5643 mNavigationBar != null &&
5644 hideNavBarSysui && immersiveSticky;
5645
John Spurlockf25706f2013-11-07 18:02:43 -05005646 boolean denyTransientStatus = mStatusBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04005647 && !transientStatusBarAllowed && hideStatusBarSysui;
John Spurlockf25706f2013-11-07 18:02:43 -05005648 boolean denyTransientNav = mNavigationBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04005649 && !transientNavBarAllowed;
5650 if (denyTransientStatus || denyTransientNav) {
John Spurlock27735a42013-08-14 17:57:38 -04005651 // clear the clearable flags instead
John Spurlockf1a36642013-10-12 17:50:42 -04005652 clearClearableFlagsLw();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005653 }
John Spurlock27735a42013-08-14 17:57:38 -04005654
5655 vis = mStatusBarController.updateVisibilityLw(transientStatusBarAllowed, oldVis, vis);
5656
5657 // update navigation bar
John Spurlockf1a36642013-10-12 17:50:42 -04005658 boolean oldImmersiveMode = isImmersiveMode(oldVis);
5659 boolean newImmersiveMode = isImmersiveMode(vis);
5660 if (win != null && oldImmersiveMode != newImmersiveMode) {
John Spurlock79da8332013-09-20 12:04:47 -04005661 final String pkg = win.getOwningPackage();
Maurice Lam99c6e072014-04-28 18:24:28 -07005662 mImmersiveModeConfirmation.immersiveModeChanged(pkg, newImmersiveMode,
5663 isUserSetupComplete());
John Spurlock34e13d92013-08-10 06:52:28 -04005664 }
John Spurlock27735a42013-08-14 17:57:38 -04005665
John Spurlockf1a36642013-10-12 17:50:42 -04005666 vis = mNavigationBarController.updateVisibilityLw(transientNavBarAllowed, oldVis, vis);
5667
John Spurlocke1f366f2013-08-05 12:22:40 -04005668 return vis;
John Spurlockad3e6cb2013-04-30 08:47:43 -04005669 }
5670
John Spurlockf1a36642013-10-12 17:50:42 -04005671 private void clearClearableFlagsLw() {
5672 int newVal = mResettingSystemUiFlags | View.SYSTEM_UI_CLEARABLE_FLAGS;
5673 if (newVal != mResettingSystemUiFlags) {
5674 mResettingSystemUiFlags = newVal;
5675 mWindowManagerFuncs.reevaluateStatusBarVisibility();
5676 }
5677 }
5678
5679 private boolean isImmersiveMode(int vis) {
5680 final int flags = View.SYSTEM_UI_FLAG_IMMERSIVE | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
John Spurlock34e13d92013-08-10 06:52:28 -04005681 return mNavigationBar != null
5682 && (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0
Daniel Sandler900ece52013-10-18 15:53:27 -04005683 && (vis & flags) != 0
5684 && canHideNavigationBar();
John Spurlock34e13d92013-08-10 06:52:28 -04005685 }
5686
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07005687 /**
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04005688 * @return whether the navigation or status bar can be made translucent
5689 *
5690 * This should return true unless touch exploration is not enabled or
5691 * R.boolean.config_enableTranslucentDecor is false.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07005692 */
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04005693 private boolean areTranslucentBarsAllowed() {
Svetoslav8e3feb12014-02-24 13:46:47 -08005694 return mTranslucentDecorEnabled
5695 && !mAccessibilityManager.isTouchExplorationEnabled();
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07005696 }
5697
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04005698 // Use this instead of checking config_showNavigationBar so that it can be consistently
5699 // overridden by qemu.hw.mainkeys in the emulator.
Craig Mautnereda67292013-04-28 13:50:14 -07005700 @Override
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04005701 public boolean hasNavigationBar() {
5702 return mHasNavigationBar;
5703 }
5704
satok1bc0a492012-04-25 22:47:12 +09005705 @Override
5706 public void setLastInputMethodWindowLw(WindowState ime, WindowState target) {
5707 mLastInputMethodWindow = ime;
5708 mLastInputMethodTargetWindow = target;
5709 }
5710
Craig Mautnerf1b67412012-09-19 13:18:29 -07005711 @Override
Satoshi Kataoka658c7b82013-10-10 17:03:51 +09005712 public int getInputMethodWindowVisibleHeightLw() {
5713 return mDockBottom - mCurBottom;
5714 }
5715
5716 @Override
Craig Mautnerf1b67412012-09-19 13:18:29 -07005717 public void setCurrentUserLw(int newUserId) {
Craig Mautnerd625ab22013-09-06 13:40:31 -07005718 mCurrentUserId = newUserId;
Jim Miller5ecd8112013-01-09 18:50:26 -08005719 if (mKeyguardDelegate != null) {
5720 mKeyguardDelegate.setCurrentUser(newUserId);
Craig Mautnerf1b67412012-09-19 13:18:29 -07005721 }
John Spurlock13451a22012-09-28 14:40:41 -04005722 if (mStatusBarService != null) {
5723 try {
5724 mStatusBarService.setCurrentUser(newUserId);
5725 } catch (RemoteException e) {
5726 // oh well
5727 }
5728 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07005729 setLastInputMethodWindowLw(null, null);
Craig Mautnerf1b67412012-09-19 13:18:29 -07005730 }
5731
5732 @Override
Svetoslav Ganov545252f2012-12-10 18:29:24 -08005733 public boolean canMagnifyWindow(int windowType) {
5734 switch (windowType) {
5735 case WindowManager.LayoutParams.TYPE_INPUT_METHOD:
5736 case WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG:
5737 case WindowManager.LayoutParams.TYPE_NAVIGATION_BAR:
5738 case WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY: {
5739 return false;
5740 }
5741 }
5742 return true;
5743 }
5744
5745 @Override
5746 public boolean isTopLevelWindow(int windowType) {
5747 if (windowType >= WindowManager.LayoutParams.FIRST_SUB_WINDOW
5748 && windowType <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
5749 return (windowType == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG);
5750 }
5751 return true;
5752 }
5753
Jim Miller4eeb4f62012-11-08 00:04:29 -08005754 @Override
Jeff Brownd7a04de2012-06-17 14:17:52 -07005755 public void dump(String prefix, PrintWriter pw, String[] args) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005756 pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005757 pw.print(" mSystemReady="); pw.print(mSystemReady);
5758 pw.print(" mSystemBooted="); pw.println(mSystemBooted);
Jeff Brown2e7760e2012-04-11 15:14:55 -07005759 pw.print(prefix); pw.print("mLidState="); pw.print(mLidState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005760 pw.print(" mLidOpenRotation="); pw.print(mLidOpenRotation);
5761 pw.print(" mHdmiPlugged="); pw.println(mHdmiPlugged);
Dianne Hackborne26ab702011-10-16 13:21:33 -07005762 if (mLastSystemUiFlags != 0 || mResettingSystemUiFlags != 0
5763 || mForceClearedSystemUiFlags != 0) {
5764 pw.print(prefix); pw.print("mLastSystemUiFlags=0x");
5765 pw.print(Integer.toHexString(mLastSystemUiFlags));
5766 pw.print(" mResettingSystemUiFlags=0x");
5767 pw.print(Integer.toHexString(mResettingSystemUiFlags));
5768 pw.print(" mForceClearedSystemUiFlags=0x");
5769 pw.println(Integer.toHexString(mForceClearedSystemUiFlags));
Dianne Hackborndf89e652011-10-06 22:35:11 -07005770 }
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08005771 if (mLastFocusNeedsMenu) {
5772 pw.print(prefix); pw.print("mLastFocusNeedsMenu=");
5773 pw.println(mLastFocusNeedsMenu);
5774 }
Jeff Browna20dda42014-05-27 20:57:24 -07005775 pw.print(prefix); pw.print("mWakeGestureEnabledSetting=");
5776 pw.println(mWakeGestureEnabledSetting);
5777
Jeff Brownbcdfc622014-03-06 19:13:04 -08005778 pw.print(prefix); pw.print("mSupportAutoRotation="); pw.println(mSupportAutoRotation);
Daniel Sandler6396c722013-04-16 20:19:09 -04005779 pw.print(prefix); pw.print("mUiMode="); pw.print(mUiMode);
5780 pw.print(" mDockMode="); pw.print(mDockMode);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005781 pw.print(" mCarDockRotation="); pw.print(mCarDockRotation);
5782 pw.print(" mDeskDockRotation="); pw.println(mDeskDockRotation);
5783 pw.print(prefix); pw.print("mUserRotationMode="); pw.print(mUserRotationMode);
5784 pw.print(" mUserRotation="); pw.print(mUserRotation);
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005785 pw.print(" mAllowAllRotations="); pw.println(mAllowAllRotations);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07005786 pw.print(prefix); pw.print("mCurrentAppOrientation="); pw.println(mCurrentAppOrientation);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005787 pw.print(prefix); pw.print("mCarDockEnablesAccelerometer=");
5788 pw.print(mCarDockEnablesAccelerometer);
5789 pw.print(" mDeskDockEnablesAccelerometer=");
5790 pw.println(mDeskDockEnablesAccelerometer);
5791 pw.print(prefix); pw.print("mLidKeyboardAccessibility=");
5792 pw.print(mLidKeyboardAccessibility);
5793 pw.print(" mLidNavigationAccessibility="); pw.print(mLidNavigationAccessibility);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07005794 pw.print(" mLidControlsSleep="); pw.println(mLidControlsSleep);
Jeff Brown6d8fd272014-05-20 21:24:38 -07005795 pw.print(prefix);
5796 pw.print("mShortPressOnPowerBehavior="); pw.print(mShortPressOnPowerBehavior);
5797 pw.print(" mLongPressOnPowerBehavior="); pw.println(mLongPressOnPowerBehavior);
5798 pw.print(prefix); pw.print("mHasSoftInput="); pw.println(mHasSoftInput);
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07005799 pw.print(prefix); pw.print("mScreenOnEarly="); pw.print(mScreenOnEarly);
5800 pw.print(" mScreenOnFully="); pw.print(mScreenOnFully);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07005801 pw.print(" mOrientationSensorEnabled="); pw.println(mOrientationSensorEnabled);
Dianne Hackbornc652de82013-02-15 16:32:56 -08005802 pw.print(prefix); pw.print("mOverscanScreen=("); pw.print(mOverscanScreenLeft);
5803 pw.print(","); pw.print(mOverscanScreenTop);
5804 pw.print(") "); pw.print(mOverscanScreenWidth);
5805 pw.print("x"); pw.println(mOverscanScreenHeight);
5806 if (mOverscanLeft != 0 || mOverscanTop != 0
5807 || mOverscanRight != 0 || mOverscanBottom != 0) {
5808 pw.print(prefix); pw.print("mOverscan left="); pw.print(mOverscanLeft);
5809 pw.print(" top="); pw.print(mOverscanTop);
5810 pw.print(" right="); pw.print(mOverscanRight);
5811 pw.print(" bottom="); pw.println(mOverscanBottom);
5812 }
Dianne Hackborn313440842013-02-19 19:22:59 -08005813 pw.print(prefix); pw.print("mRestrictedOverscanScreen=(");
5814 pw.print(mRestrictedOverscanScreenLeft);
5815 pw.print(","); pw.print(mRestrictedOverscanScreenTop);
5816 pw.print(") "); pw.print(mRestrictedOverscanScreenWidth);
5817 pw.print("x"); pw.println(mRestrictedOverscanScreenHeight);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005818 pw.print(prefix); pw.print("mUnrestrictedScreen=("); pw.print(mUnrestrictedScreenLeft);
5819 pw.print(","); pw.print(mUnrestrictedScreenTop);
5820 pw.print(") "); pw.print(mUnrestrictedScreenWidth);
5821 pw.print("x"); pw.println(mUnrestrictedScreenHeight);
5822 pw.print(prefix); pw.print("mRestrictedScreen=("); pw.print(mRestrictedScreenLeft);
5823 pw.print(","); pw.print(mRestrictedScreenTop);
5824 pw.print(") "); pw.print(mRestrictedScreenWidth);
5825 pw.print("x"); pw.println(mRestrictedScreenHeight);
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07005826 pw.print(prefix); pw.print("mStableFullscreen=("); pw.print(mStableFullscreenLeft);
5827 pw.print(","); pw.print(mStableFullscreenTop);
5828 pw.print(")-("); pw.print(mStableFullscreenRight);
5829 pw.print(","); pw.print(mStableFullscreenBottom); pw.println(")");
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07005830 pw.print(prefix); pw.print("mStable=("); pw.print(mStableLeft);
5831 pw.print(","); pw.print(mStableTop);
5832 pw.print(")-("); pw.print(mStableRight);
5833 pw.print(","); pw.print(mStableBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07005834 pw.print(prefix); pw.print("mSystem=("); pw.print(mSystemLeft);
5835 pw.print(","); pw.print(mSystemTop);
5836 pw.print(")-("); pw.print(mSystemRight);
5837 pw.print(","); pw.print(mSystemBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005838 pw.print(prefix); pw.print("mCur=("); pw.print(mCurLeft);
5839 pw.print(","); pw.print(mCurTop);
5840 pw.print(")-("); pw.print(mCurRight);
5841 pw.print(","); pw.print(mCurBottom); pw.println(")");
5842 pw.print(prefix); pw.print("mContent=("); pw.print(mContentLeft);
5843 pw.print(","); pw.print(mContentTop);
5844 pw.print(")-("); pw.print(mContentRight);
5845 pw.print(","); pw.print(mContentBottom); pw.println(")");
Dianne Hackborne30e02f2014-05-27 18:24:45 -07005846 pw.print(prefix); pw.print("mVoiceContent=("); pw.print(mVoiceContentLeft);
5847 pw.print(","); pw.print(mVoiceContentTop);
5848 pw.print(")-("); pw.print(mVoiceContentRight);
5849 pw.print(","); pw.print(mVoiceContentBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005850 pw.print(prefix); pw.print("mDock=("); pw.print(mDockLeft);
5851 pw.print(","); pw.print(mDockTop);
5852 pw.print(")-("); pw.print(mDockRight);
5853 pw.print(","); pw.print(mDockBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07005854 pw.print(prefix); pw.print("mDockLayer="); pw.print(mDockLayer);
5855 pw.print(" mStatusBarLayer="); pw.println(mStatusBarLayer);
Dianne Hackborn7ad44382012-10-18 17:46:00 -07005856 pw.print(prefix); pw.print("mShowingLockscreen="); pw.print(mShowingLockscreen);
5857 pw.print(" mShowingDream="); pw.print(mShowingDream);
5858 pw.print(" mDreamingLockscreen="); pw.println(mDreamingLockscreen);
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07005859 if (mLastInputMethodWindow != null) {
5860 pw.print(prefix); pw.print("mLastInputMethodWindow=");
5861 pw.println(mLastInputMethodWindow);
5862 }
5863 if (mLastInputMethodTargetWindow != null) {
5864 pw.print(prefix); pw.print("mLastInputMethodTargetWindow=");
5865 pw.println(mLastInputMethodTargetWindow);
5866 }
5867 if (mStatusBar != null) {
5868 pw.print(prefix); pw.print("mStatusBar=");
5869 pw.println(mStatusBar);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01005870 pw.print(prefix); pw.print("isStatusBarKeyguard=");
5871 pw.print(isStatusBarKeyguard());
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07005872 }
5873 if (mNavigationBar != null) {
5874 pw.print(prefix); pw.print("mNavigationBar=");
5875 pw.println(mNavigationBar);
5876 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07005877 if (mFocusedWindow != null) {
5878 pw.print(prefix); pw.print("mFocusedWindow=");
5879 pw.println(mFocusedWindow);
5880 }
5881 if (mFocusedApp != null) {
5882 pw.print(prefix); pw.print("mFocusedApp=");
5883 pw.println(mFocusedApp);
5884 }
5885 if (mWinDismissingKeyguard != null) {
5886 pw.print(prefix); pw.print("mWinDismissingKeyguard=");
5887 pw.println(mWinDismissingKeyguard);
5888 }
5889 if (mTopFullscreenOpaqueWindowState != null) {
5890 pw.print(prefix); pw.print("mTopFullscreenOpaqueWindowState=");
5891 pw.println(mTopFullscreenOpaqueWindowState);
5892 }
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08005893 if (mForcingShowNavBar) {
5894 pw.print(prefix); pw.print("mForcingShowNavBar=");
5895 pw.println(mForcingShowNavBar); pw.print( "mForcingShowNavBarLayer=");
5896 pw.println(mForcingShowNavBarLayer);
5897 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07005898 pw.print(prefix); pw.print("mTopIsFullscreen="); pw.print(mTopIsFullscreen);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005899 pw.print(" mHideLockScreen="); pw.println(mHideLockScreen);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07005900 pw.print(prefix); pw.print("mForceStatusBar="); pw.print(mForceStatusBar);
5901 pw.print(" mForceStatusBarFromKeyguard=");
5902 pw.println(mForceStatusBarFromKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005903 pw.print(prefix); pw.print("mDismissKeyguard="); pw.print(mDismissKeyguard);
Craig Mautnerad09bcc2012-10-08 13:33:11 -07005904 pw.print(" mWinDismissingKeyguard="); pw.print(mWinDismissingKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005905 pw.print(" mHomePressed="); pw.println(mHomePressed);
5906 pw.print(prefix); pw.print("mAllowLockscreenWhenOn="); pw.print(mAllowLockscreenWhenOn);
5907 pw.print(" mLockScreenTimeout="); pw.print(mLockScreenTimeout);
5908 pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive);
5909 pw.print(prefix); pw.print("mEndcallBehavior="); pw.print(mEndcallBehavior);
5910 pw.print(" mIncallPowerBehavior="); pw.print(mIncallPowerBehavior);
5911 pw.print(" mLongPressOnHomeBehavior="); pw.println(mLongPressOnHomeBehavior);
5912 pw.print(prefix); pw.print("mLandscapeRotation="); pw.print(mLandscapeRotation);
5913 pw.print(" mSeascapeRotation="); pw.println(mSeascapeRotation);
5914 pw.print(prefix); pw.print("mPortraitRotation="); pw.print(mPortraitRotation);
5915 pw.print(" mUpsideDownRotation="); pw.println(mUpsideDownRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07005916 pw.print(prefix); pw.print("mDemoHdmiRotation="); pw.print(mDemoHdmiRotation);
5917 pw.print(" mDemoHdmiRotationLock="); pw.println(mDemoHdmiRotationLock);
5918 pw.print(prefix); pw.print("mUndockedHdmiRotation="); pw.println(mUndockedHdmiRotation);
Jeff Brown600f0032014-05-22 17:06:00 -07005919
Tim Kilbournd7c0c2e2014-05-29 16:08:10 -07005920 mGlobalKeyManager.dump(prefix, pw);
John Spurlock27735a42013-08-14 17:57:38 -04005921 mStatusBarController.dump(pw, prefix);
5922 mNavigationBarController.dump(pw, prefix);
John Spurlockc6d1c602014-01-17 15:22:06 -05005923 PolicyControl.dump(prefix, pw);
Jeff Brown600f0032014-05-22 17:06:00 -07005924
Jeff Browna20dda42014-05-27 20:57:24 -07005925 if (mWakeGestureListener != null) {
5926 mWakeGestureListener.dump(pw, prefix);
5927 }
Jeff Brown600f0032014-05-22 17:06:00 -07005928 if (mOrientationListener != null) {
5929 mOrientationListener.dump(pw, prefix);
5930 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005931 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005932}