blob: 22bdb175300ed3083109bb9addb517b527fea8bb [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;
Michael Wright869a67c2014-08-26 19:33:06 -0700548 private static final int MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK = 12;
Jeff Brown70825162012-03-28 17:27:48 -0700549
550 private class PolicyHandler extends Handler {
551 @Override
552 public void handleMessage(Message msg) {
553 switch (msg.what) {
554 case MSG_ENABLE_POINTER_LOCATION:
555 enablePointerLocation();
556 break;
557 case MSG_DISABLE_POINTER_LOCATION:
558 disablePointerLocation();
559 break;
Jeff Brown40013652012-05-16 21:22:36 -0700560 case MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK:
561 dispatchMediaKeyWithWakeLock((KeyEvent)msg.obj);
562 break;
563 case MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK:
564 dispatchMediaKeyRepeatWithWakeLock((KeyEvent)msg.obj);
565 break;
Craig Mautner84984fa2014-06-19 11:19:20 -0700566 case MSG_DISPATCH_SHOW_RECENTS:
567 showRecentApps(false);
568 break;
Alan Viverettee34560b22014-07-10 14:50:06 -0700569 case MSG_DISPATCH_SHOW_GLOBAL_ACTIONS:
570 showGlobalActionsInternal();
571 break;
Craig Mautner8a0da012014-05-31 15:13:37 -0700572 case MSG_KEYGUARD_DRAWN_COMPLETE:
573 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mKeyguardDrawComplete");
574 mKeyguardDrawComplete = true;
575 finishScreenTurningOn();
576 break;
577 case MSG_KEYGUARD_DRAWN_TIMEOUT:
578 Slog.w(TAG, "Keyguard drawn timeout. Setting mKeyguardDrawComplete");
579 mKeyguardDrawComplete = true;
580 finishScreenTurningOn();
581 break;
582 case MSG_WINDOW_MANAGER_DRAWN_COMPLETE:
583 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mWindowManagerDrawComplete");
584 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
585 mWindowManagerDrawComplete = true;
586 finishScreenTurningOn();
587 break;
588 case MSG_WAKING_UP:
589 handleWakingUp((ScreenOnListener) msg.obj);
590 break;
Craig Mautnera631d492014-08-05 15:16:01 -0700591 case MSG_HIDE_BOOT_MESSAGE:
592 handleHideBootMessage();
593 break;
Michael Wright869a67c2014-08-26 19:33:06 -0700594 case MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK:
595 launchVoiceAssistWithWakeLock(msg.arg1 != 0);
596 break;
Jeff Brown70825162012-03-28 17:27:48 -0700597 }
598 }
599 }
600
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800601 private UEventObserver mHDMIObserver = new UEventObserver() {
602 @Override
603 public void onUEvent(UEventObserver.UEvent event) {
604 setHdmiPlugged("1".equals(event.get("SWITCH_STATE")));
605 }
606 };
607
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800608 class SettingsObserver extends ContentObserver {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800609 SettingsObserver(Handler handler) {
610 super(handler);
611 }
David Brownbaf8d092010-03-08 21:52:59 -0800612
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800613 void observe() {
Christopher Tate5e08af02012-09-21 17:17:22 -0700614 // Observe all users' changes
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800615 ContentResolver resolver = mContext.getContentResolver();
616 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700617 Settings.System.END_BUTTON_BEHAVIOR), false, this,
618 UserHandle.USER_ALL);
David Brownbaf8d092010-03-08 21:52:59 -0800619 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700620 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR), false, this,
621 UserHandle.USER_ALL);
Jeff Browna20dda42014-05-27 20:57:24 -0700622 resolver.registerContentObserver(Settings.Secure.getUriFor(
623 Settings.Secure.WAKE_GESTURE_ENABLED), false, this,
624 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800625 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700626 Settings.System.ACCELEROMETER_ROTATION), false, this,
627 UserHandle.USER_ALL);
Mike Lockwood28569302010-01-28 11:54:40 -0500628 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700629 Settings.System.USER_ROTATION), false, this,
630 UserHandle.USER_ALL);
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400631 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700632 Settings.System.SCREEN_OFF_TIMEOUT), false, this,
633 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800634 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700635 Settings.System.POINTER_LOCATION), false, this,
636 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800637 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700638 Settings.Secure.DEFAULT_INPUT_METHOD), false, this,
639 UserHandle.USER_ALL);
John Spurlockd9b70bd2014-02-06 17:02:44 -0500640 resolver.registerContentObserver(Settings.Secure.getUriFor(
John Spurlockf1a36642013-10-12 17:50:42 -0400641 Settings.Secure.IMMERSIVE_MODE_CONFIRMATIONS), false, this,
Christopher Tate5e08af02012-09-21 17:17:22 -0700642 UserHandle.USER_ALL);
John Spurlockc6d1c602014-01-17 15:22:06 -0500643 resolver.registerContentObserver(Settings.Global.getUriFor(
644 Settings.Global.POLICY_CONTROL), false, this,
645 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800646 updateSettings();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800647 }
648
649 @Override public void onChange(boolean selfChange) {
Dianne Hackbornc777e072010-02-12 13:07:59 -0800650 updateSettings();
Jeff Brown01a98dd2011-09-20 15:08:29 -0700651 updateRotation(false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800652 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800653 }
Craig Mautner967212c2013-04-13 21:10:58 -0700654
Jeff Browna20dda42014-05-27 20:57:24 -0700655 class MyWakeGestureListener extends WakeGestureListener {
656 MyWakeGestureListener(Context context, Handler handler) {
657 super(context, handler);
658 }
659
660 @Override
661 public void onWakeUp() {
662 synchronized (mLock) {
663 if (shouldEnableWakeGestureLp()) {
Jeff Browne07b94b2014-06-18 15:56:27 -0700664 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
Jeff Browna20dda42014-05-27 20:57:24 -0700665 mPowerManager.wakeUp(SystemClock.uptimeMillis());
666 }
667 }
668 }
669 }
670
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800671 class MyOrientationListener extends WindowOrientationListener {
Craig Mautnereee29c42013-01-17 14:44:34 -0800672 MyOrientationListener(Context context, Handler handler) {
673 super(context, handler);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800674 }
Craig Mautner967212c2013-04-13 21:10:58 -0700675
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800676 @Override
Jeff Brownc0347aa2011-09-23 17:26:09 -0700677 public void onProposedRotationChanged(int rotation) {
Craig Mautnereda67292013-04-28 13:50:14 -0700678 if (localLOGV) Slog.v(TAG, "onProposedRotationChanged, rotation=" + rotation);
Jeff Brown01a98dd2011-09-20 15:08:29 -0700679 updateRotation(false);
680 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800681 }
682 MyOrientationListener mOrientationListener;
683
John Spurlock27735a42013-08-14 17:57:38 -0400684 private final BarController mStatusBarController = new BarController("StatusBar",
John Spurlock5b9145b2013-08-20 15:13:47 -0400685 View.STATUS_BAR_TRANSIENT,
686 View.STATUS_BAR_UNHIDE,
John Spurlockbd957402013-10-03 11:38:39 -0400687 View.STATUS_BAR_TRANSLUCENT,
688 StatusBarManager.WINDOW_STATUS_BAR,
689 WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
John Spurlock5b9145b2013-08-20 15:13:47 -0400690
John Spurlock27735a42013-08-14 17:57:38 -0400691 private final BarController mNavigationBarController = new BarController("NavigationBar",
John Spurlock5b9145b2013-08-20 15:13:47 -0400692 View.NAVIGATION_BAR_TRANSIENT,
693 View.NAVIGATION_BAR_UNHIDE,
John Spurlockbd957402013-10-03 11:38:39 -0400694 View.NAVIGATION_BAR_TRANSLUCENT,
695 StatusBarManager.WINDOW_NAVIGATION_BAR,
696 WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
John Spurlock5b9145b2013-08-20 15:13:47 -0400697
John Spurlockf1a36642013-10-12 17:50:42 -0400698 private ImmersiveModeConfirmation mImmersiveModeConfirmation;
John Spurlock32beb2c2013-03-11 10:16:47 -0400699
Craig Mautner037aa8d2013-06-07 10:35:44 -0700700 private SystemGesturesPointerEventListener mSystemGestures;
John Spurlock32beb2c2013-03-11 10:16:47 -0400701
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700702 IStatusBarService getStatusBarService() {
703 synchronized (mServiceAquireLock) {
704 if (mStatusBarService == null) {
705 mStatusBarService = IStatusBarService.Stub.asInterface(
706 ServiceManager.getService("statusbar"));
707 }
708 return mStatusBarService;
709 }
710 }
711
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700712 /*
713 * We always let the sensor be switched on by default except when
714 * the user has explicitly disabled sensor based rotation or when the
715 * screen is switched off.
716 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700717 boolean needSensorRunningLp() {
Jeff Brownbcdfc622014-03-06 19:13:04 -0800718 if (mSupportAutoRotation) {
719 if (mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
720 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
721 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT
722 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) {
723 // If the application has explicitly requested to follow the
724 // orientation, then we need to turn the sensor on.
725 return true;
726 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800727 }
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700728 if ((mCarDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_CAR) ||
Jeff Brown1a693182011-11-08 14:44:16 -0800729 (mDeskDockEnablesAccelerometer && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
730 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
731 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK))) {
Mike Lockwoode9867d22009-09-20 01:59:02 -0400732 // enable accelerometer if we are docked in a dock that enables accelerometer
733 // orientation management,
734 return true;
735 }
Jeff Brown207673cd2012-06-05 17:47:11 -0700736 if (mUserRotationMode == USER_ROTATION_LOCKED) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800737 // If the setting for using the sensor by default is enabled, then
738 // we will always leave it on. Note that the user could go to
739 // a window that forces an orientation that does not use the
740 // sensor and in theory we could turn it off... however, when next
741 // turning it on we won't have a good value for the current
742 // orientation for a little bit, which can cause orientation
743 // changes to lag, so we'd like to keep it always on. (It will
744 // still be turned off when the screen is off.)
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700745 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800746 }
Jeff Brownbcdfc622014-03-06 19:13:04 -0800747 return mSupportAutoRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800748 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700749
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800750 /*
751 * Various use cases for invoking this function
752 * screen turning off, should always disable listeners if already enabled
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700753 * screen turned on and current app has sensor based orientation, enable listeners
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800754 * if not already enabled
755 * screen turned on and current app does not have sensor orientation, disable listeners if
756 * already enabled
757 * screen turning on and current app has sensor based orientation, enable listeners if needed
758 * screen turning on and current app has nosensor based orientation, do nothing
759 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700760 void updateOrientationListenerLp() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800761 if (!mOrientationListener.canDetectOrientation()) {
762 // If sensor is turned off or nonexistent for some reason
763 return;
764 }
765 //Could have been invoked due to screen turning on or off or
766 //change of the currently visible window's orientation
Craig Mautnereda67292013-04-28 13:50:14 -0700767 if (localLOGV) Slog.v(TAG, "Screen status="+mScreenOnEarly+
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800768 ", current orientation="+mCurrentAppOrientation+
769 ", SensorEnabled="+mOrientationSensorEnabled);
770 boolean disable = true;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -0700771 if (mScreenOnEarly) {
The Android Open Source Project0727d222009-03-11 12:11:58 -0700772 if (needSensorRunningLp()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800773 disable = false;
774 //enable listener if not already enabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700775 if (!mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800776 mOrientationListener.enable();
Craig Mautnereda67292013-04-28 13:50:14 -0700777 if(localLOGV) Slog.v(TAG, "Enabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800778 mOrientationSensorEnabled = true;
779 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700780 }
781 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800782 //check if sensors need to be disabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700783 if (disable && mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800784 mOrientationListener.disable();
Craig Mautnereda67292013-04-28 13:50:14 -0700785 if(localLOGV) Slog.v(TAG, "Disabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800786 mOrientationSensorEnabled = false;
787 }
788 }
789
Jeff Brown4d396052010-10-29 21:50:21 -0700790 private void interceptPowerKeyDown(boolean handled) {
791 mPowerKeyHandled = handled;
792 if (!handled) {
Justin Kohfeabd2c2014-05-02 10:02:44 -0700793 mHandler.postDelayed(mPowerLongPress,
794 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Jeff Brown4d396052010-10-29 21:50:21 -0700795 }
796 }
797
798 private boolean interceptPowerKeyUp(boolean canceled) {
799 if (!mPowerKeyHandled) {
800 mHandler.removeCallbacks(mPowerLongPress);
801 return !canceled;
Jeff Brown4d396052010-10-29 21:50:21 -0700802 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700803 return false;
804 }
805
806 private void cancelPendingPowerKeyAction() {
807 if (!mPowerKeyHandled) {
808 mHandler.removeCallbacks(mPowerLongPress);
809 }
Jeff Brownff204712011-10-25 21:27:54 -0700810 if (mPowerKeyTriggered) {
811 mPendingPowerKeyUpCanceled = true;
812 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700813 }
814
815 private void interceptScreenshotChord() {
Christopher Tatee90585f2012-03-05 18:56:25 -0800816 if (mScreenshotChordEnabled
817 && mVolumeDownKeyTriggered && mPowerKeyTriggered && !mVolumeUpKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700818 final long now = SystemClock.uptimeMillis();
819 if (now <= mVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS
820 && now <= mPowerKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) {
821 mVolumeDownKeyConsumedByScreenshotChord = true;
822 cancelPendingPowerKeyAction();
823
Jeff Sharkey2991fa32012-12-05 18:06:43 -0800824 mHandler.postDelayed(mScreenshotRunnable, getScreenshotChordLongPressDelay());
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700825 }
826 }
827 }
828
Winson Chung1cea2f32012-10-08 20:42:01 -0700829 private long getScreenshotChordLongPressDelay() {
Jim Miller5ecd8112013-01-09 18:50:26 -0800830 if (mKeyguardDelegate.isShowing()) {
Winson Chung1cea2f32012-10-08 20:42:01 -0700831 // Double the time it takes to take a screenshot from the keyguard
832 return (long) (KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER *
Justin Kohfeabd2c2014-05-02 10:02:44 -0700833 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Winson Chung1cea2f32012-10-08 20:42:01 -0700834 }
Justin Kohfeabd2c2014-05-02 10:02:44 -0700835 return ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout();
Winson Chung1cea2f32012-10-08 20:42:01 -0700836 }
837
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700838 private void cancelPendingScreenshotChordAction() {
Jeff Sharkey2991fa32012-12-05 18:06:43 -0800839 mHandler.removeCallbacks(mScreenshotRunnable);
Jeff Brown4d396052010-10-29 21:50:21 -0700840 }
841
Jeff Brown6d8fd272014-05-20 21:24:38 -0700842 private void powerShortPress(long eventTime) {
843 if (mShortPressOnPowerBehavior < 0) {
844 mShortPressOnPowerBehavior = mContext.getResources().getInteger(
845 com.android.internal.R.integer.config_shortPressOnPowerBehavior);
846 }
847
848 switch (mShortPressOnPowerBehavior) {
849 case SHORT_PRESS_POWER_NOTHING:
850 break;
851 case SHORT_PRESS_POWER_GO_TO_SLEEP:
852 mPowerManager.goToSleep(eventTime,
Jeff Brownc12035c2014-08-13 18:52:25 -0700853 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
Jeff Brown6d8fd272014-05-20 21:24:38 -0700854 break;
855 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP:
856 mPowerManager.goToSleep(eventTime,
Jeff Brownc12035c2014-08-13 18:52:25 -0700857 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
Jeff Brown6d8fd272014-05-20 21:24:38 -0700858 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
859 break;
860 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME:
861 mPowerManager.goToSleep(eventTime,
Jeff Brownc12035c2014-08-13 18:52:25 -0700862 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
Jeff Brown6d8fd272014-05-20 21:24:38 -0700863 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
864 launchHomeFromHotKey();
865 break;
866 }
867 }
868
Jeff Brown4d396052010-10-29 21:50:21 -0700869 private final Runnable mPowerLongPress = new Runnable() {
Craig Mautnerf1b67412012-09-19 13:18:29 -0700870 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800871 public void run() {
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700872 // The context isn't read
873 if (mLongPressOnPowerBehavior < 0) {
Jeff Brown850c5b72012-10-01 15:17:22 -0700874 mLongPressOnPowerBehavior = mContext.getResources().getInteger(
875 com.android.internal.R.integer.config_longPressOnPowerBehavior);
Joe Onoratod208e702010-10-08 16:22:43 -0400876 }
Jeff Brown850c5b72012-10-01 15:17:22 -0700877 int resolvedBehavior = mLongPressOnPowerBehavior;
878 if (FactoryTest.isLongPressOnPowerOffEnabled()) {
879 resolvedBehavior = LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM;
880 }
881
882 switch (resolvedBehavior) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700883 case LONG_PRESS_POWER_NOTHING:
884 break;
885 case LONG_PRESS_POWER_GLOBAL_ACTIONS:
886 mPowerKeyHandled = true;
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -0700887 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
888 performAuditoryFeedbackForAccessibilityIfNeed();
889 }
Alan Viverettee34560b22014-07-10 14:50:06 -0700890 showGlobalActionsInternal();
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700891 break;
892 case LONG_PRESS_POWER_SHUT_OFF:
Jeff Brown9a538ee2012-08-20 14:56:57 -0700893 case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM:
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700894 mPowerKeyHandled = true;
895 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
896 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
Jeff Brown850c5b72012-10-01 15:17:22 -0700897 mWindowManagerFuncs.shutdown(resolvedBehavior == LONG_PRESS_POWER_SHUT_OFF);
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700898 break;
899 }
900 }
901 };
902
Jeff Sharkey2991fa32012-12-05 18:06:43 -0800903 private final Runnable mScreenshotRunnable = new Runnable() {
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800904 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700905 public void run() {
906 takeScreenshot();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800907 }
908 };
909
Alan Viverettee34560b22014-07-10 14:50:06 -0700910 @Override
911 public void showGlobalActions() {
912 mHandler.removeMessages(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
913 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
914 }
915
916 void showGlobalActionsInternal() {
917 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800918 if (mGlobalActions == null) {
Jeff Brown7304c342012-05-11 18:42:42 -0700919 mGlobalActions = new GlobalActions(mContext, mWindowManagerFuncs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800920 }
Mike Lockwood3a74bd32011-08-12 13:55:22 -0700921 final boolean keyguardShowing = keyguardIsShowingTq();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800922 mGlobalActions.showDialog(keyguardShowing, isDeviceProvisioned());
923 if (keyguardShowing) {
924 // since it took two seconds of long press to bring this up,
925 // poke the wake lock so they have some time to see the dialog.
Jim Miller25190572013-02-28 17:36:24 -0800926 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800927 }
928 }
929
930 boolean isDeviceProvisioned() {
Jeff Brownbf6f6f92012-09-25 15:03:20 -0700931 return Settings.Global.getInt(
932 mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800933 }
934
Maurice Lam99c6e072014-04-28 18:24:28 -0700935 boolean isUserSetupComplete() {
936 return Settings.Secure.getIntForUser(mContext.getContentResolver(),
937 Settings.Secure.USER_SETUP_COMPLETE, 0, UserHandle.USER_CURRENT) != 0;
938 }
939
Patrick Dubroyece94522011-02-23 18:35:01 -0800940 private void handleLongPressOnHome() {
Joe Onorato46b0d682010-11-22 17:37:27 -0800941 if (mLongPressOnHomeBehavior != LONG_PRESS_HOME_NOTHING) {
Jeff Browncaca8812013-05-09 13:34:33 -0700942 mHomeConsumed = true;
Joe Onorato46b0d682010-11-22 17:37:27 -0800943 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
Patrick Dubroyece94522011-02-23 18:35:01 -0800944
Jeff Browncaca8812013-05-09 13:34:33 -0700945 if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI) {
946 toggleRecentApps();
947 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_ASSIST) {
948 launchAssistAction();
Jim Millere6ad1a82010-08-20 19:25:39 -0700949 }
950 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800951 }
Patrick Dubroyece94522011-02-23 18:35:01 -0800952
Jeff Browncaca8812013-05-09 13:34:33 -0700953 private void handleDoubleTapOnHome() {
954 if (mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
955 mHomeConsumed = true;
956 toggleRecentApps();
957 }
958 }
959
960 private final Runnable mHomeDoubleTapTimeoutRunnable = new Runnable() {
961 @Override
962 public void run() {
963 if (mHomeDoubleTapPending) {
964 mHomeDoubleTapPending = false;
965 launchHomeFromHotKey();
966 }
967 }
968 };
969
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800970 /** {@inheritDoc} */
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800971 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800972 public void init(Context context, IWindowManager windowManager,
Jeff Brown96307042012-07-27 15:51:34 -0700973 WindowManagerFuncs windowManagerFuncs) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800974 mContext = context;
975 mWindowManager = windowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700976 mWindowManagerFuncs = windowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -0700977 mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class);
Jose Lima9546b202014-07-02 17:21:51 -0700978 mDreamManagerInternal = LocalServices.getService(DreamManagerInternal.class);
Craig Mautner8a0da012014-05-31 15:13:37 -0700979
Jeff Brown70825162012-03-28 17:27:48 -0700980 mHandler = new PolicyHandler();
Jeff Browna20dda42014-05-27 20:57:24 -0700981 mWakeGestureListener = new MyWakeGestureListener(mContext, mHandler);
Craig Mautnereee29c42013-01-17 14:44:34 -0800982 mOrientationListener = new MyOrientationListener(mContext, mHandler);
Jeff Brownc0347aa2011-09-23 17:26:09 -0700983 try {
984 mOrientationListener.setCurrentRotation(windowManager.getRotation());
985 } catch (RemoteException ex) { }
Christopher Tate5e08af02012-09-21 17:17:22 -0700986 mSettingsObserver = new SettingsObserver(mHandler);
987 mSettingsObserver.observe();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800988 mShortcutManager = new ShortcutManager(context, mHandler);
989 mShortcutManager.observe();
Daniel Sandler6396c722013-04-16 20:19:09 -0400990 mUiMode = context.getResources().getInteger(
991 com.android.internal.R.integer.config_defaultUiModeType);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800992 mHomeIntent = new Intent(Intent.ACTION_MAIN, null);
993 mHomeIntent.addCategory(Intent.CATEGORY_HOME);
994 mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
995 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700996 mCarDockIntent = new Intent(Intent.ACTION_MAIN, null);
997 mCarDockIntent.addCategory(Intent.CATEGORY_CAR_DOCK);
998 mCarDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
999 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
1000 mDeskDockIntent = new Intent(Intent.ACTION_MAIN, null);
1001 mDeskDockIntent.addCategory(Intent.CATEGORY_DESK_DOCK);
1002 mDeskDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1003 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Jim Millere6ad1a82010-08-20 19:25:39 -07001004
Jeff Brown96307042012-07-27 15:51:34 -07001005 mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
1006 mBroadcastWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001007 "PhoneWindowManager.mBroadcastWakeLock");
1008 mEnableShiftMenuBugReports = "1".equals(SystemProperties.get("ro.debuggable"));
Jeff Brownbcdfc622014-03-06 19:13:04 -08001009 mSupportAutoRotation = mContext.getResources().getBoolean(
1010 com.android.internal.R.bool.config_supportAutoRotation);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001011 mLidOpenRotation = readRotation(
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001012 com.android.internal.R.integer.config_lidOpenRotation);
1013 mCarDockRotation = readRotation(
1014 com.android.internal.R.integer.config_carDockRotation);
1015 mDeskDockRotation = readRotation(
1016 com.android.internal.R.integer.config_deskDockRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001017 mUndockedHdmiRotation = readRotation(
1018 com.android.internal.R.integer.config_undockedHdmiRotation);
Mike Lockwoode9867d22009-09-20 01:59:02 -04001019 mCarDockEnablesAccelerometer = mContext.getResources().getBoolean(
1020 com.android.internal.R.bool.config_carDockEnablesAccelerometer);
1021 mDeskDockEnablesAccelerometer = mContext.getResources().getBoolean(
1022 com.android.internal.R.bool.config_deskDockEnablesAccelerometer);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001023 mLidKeyboardAccessibility = mContext.getResources().getInteger(
1024 com.android.internal.R.integer.config_lidKeyboardAccessibility);
1025 mLidNavigationAccessibility = mContext.getResources().getInteger(
1026 com.android.internal.R.integer.config_lidNavigationAccessibility);
Jeff Brownc458ce92012-04-30 14:58:40 -07001027 mLidControlsSleep = mContext.getResources().getBoolean(
1028 com.android.internal.R.bool.config_lidControlsSleep);
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04001029 mTranslucentDecorEnabled = mContext.getResources().getBoolean(
1030 com.android.internal.R.bool.config_enableTranslucentDecor);
Jeff Brownf71343d2013-05-31 17:59:11 -07001031 readConfigurationDependentBehaviors();
Jeff Browncaca8812013-05-09 13:34:33 -07001032
Svetoslav8e3feb12014-02-24 13:46:47 -08001033 mAccessibilityManager = (AccessibilityManager) context.getSystemService(
1034 Context.ACCESSIBILITY_SERVICE);
1035
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001036 // register for dock events
Dianne Hackborn78968392010-03-04 20:47:56 -08001037 IntentFilter filter = new IntentFilter();
1038 filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE);
1039 filter.addAction(UiModeManager.ACTION_EXIT_CAR_MODE);
1040 filter.addAction(UiModeManager.ACTION_ENTER_DESK_MODE);
1041 filter.addAction(UiModeManager.ACTION_EXIT_DESK_MODE);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001042 filter.addAction(Intent.ACTION_DOCK_EVENT);
1043 Intent intent = context.registerReceiver(mDockReceiver, filter);
1044 if (intent != null) {
1045 // Retrieve current sticky dock event broadcast.
1046 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
1047 Intent.EXTRA_DOCK_STATE_UNDOCKED);
1048 }
Daniel Sandler7e37df52011-11-16 22:08:23 -08001049
Jeff Brown6aaf2952012-10-05 16:01:08 -07001050 // register for dream-related broadcasts
1051 filter = new IntentFilter();
1052 filter.addAction(Intent.ACTION_DREAMING_STARTED);
1053 filter.addAction(Intent.ACTION_DREAMING_STOPPED);
1054 context.registerReceiver(mDreamReceiver, filter);
1055
Christopher Tate5e08af02012-09-21 17:17:22 -07001056 // register for multiuser-relevant broadcasts
1057 filter = new IntentFilter(Intent.ACTION_USER_SWITCHED);
1058 context.registerReceiver(mMultiuserReceiver, filter);
1059
John Spurlock57306e62013-04-22 09:48:49 -04001060 // monitor for system gestures
Craig Mautner037aa8d2013-06-07 10:35:44 -07001061 mSystemGestures = new SystemGesturesPointerEventListener(context,
1062 new SystemGesturesPointerEventListener.Callbacks() {
John Spurlock57306e62013-04-22 09:48:49 -04001063 @Override
1064 public void onSwipeFromTop() {
John Spurlock04db1762013-05-13 12:46:41 -04001065 if (mStatusBar != null) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001066 requestTransientBars(mStatusBar);
John Spurlock04db1762013-05-13 12:46:41 -04001067 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04001068 }
1069 @Override
1070 public void onSwipeFromBottom() {
John Spurlock04db1762013-05-13 12:46:41 -04001071 if (mNavigationBar != null && mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001072 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001073 }
1074 }
1075 @Override
1076 public void onSwipeFromRight() {
John Spurlock04db1762013-05-13 12:46:41 -04001077 if (mNavigationBar != null && !mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001078 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001079 }
1080 }
1081 @Override
1082 public void onDebug() {
John Spurlockd67ec252013-09-05 11:31:54 -04001083 // no-op
John Spurlockad3e6cb2013-04-30 08:47:43 -04001084 }
1085 });
John Spurlockf1a36642013-10-12 17:50:42 -04001086 mImmersiveModeConfirmation = new ImmersiveModeConfirmation(mContext);
Craig Mautner037aa8d2013-06-07 10:35:44 -07001087 mWindowManagerFuncs.registerPointerEventListener(mSystemGestures);
John Spurlock32beb2c2013-03-11 10:16:47 -04001088
Jeff Brownc2346132012-04-13 01:55:38 -07001089 mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001090 mLongPressVibePattern = getLongIntArray(mContext.getResources(),
1091 com.android.internal.R.array.config_longPressVibePattern);
1092 mVirtualKeyVibePattern = getLongIntArray(mContext.getResources(),
1093 com.android.internal.R.array.config_virtualKeyVibePattern);
Amith Yamasanic33cb712010-02-10 15:21:49 -08001094 mKeyboardTapVibePattern = getLongIntArray(mContext.getResources(),
1095 com.android.internal.R.array.config_keyboardTapVibePattern);
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07001096 mClockTickVibePattern = getLongIntArray(mContext.getResources(),
1097 com.android.internal.R.array.config_clockTickVibePattern);
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07001098 mCalendarDateVibePattern = getLongIntArray(mContext.getResources(),
1099 com.android.internal.R.array.config_calendarDateVibePattern);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001100 mSafeModeDisabledVibePattern = getLongIntArray(mContext.getResources(),
1101 com.android.internal.R.array.config_safeModeDisabledVibePattern);
1102 mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(),
1103 com.android.internal.R.array.config_safeModeEnabledVibePattern);
Daniel Sandler40427442010-07-16 11:44:52 -04001104
Christopher Tatee90585f2012-03-05 18:56:25 -08001105 mScreenshotChordEnabled = mContext.getResources().getBoolean(
1106 com.android.internal.R.bool.config_enableScreenshotChord);
1107
Justin Kohd378ad72013-04-01 12:18:26 -07001108 mGlobalKeyManager = new GlobalKeyManager(mContext);
1109
Joe Onoratoea495d42011-04-06 11:41:11 -07001110 // Controls rotation and the like.
1111 initializeHdmiState();
Dianne Hackborn40011092011-09-22 13:37:48 -07001112
1113 // Match current screen state.
Craig Mautnera631d492014-08-05 15:16:01 -07001114 if (!mPowerManager.isInteractive()) {
Jeff Brown140ffc72014-05-01 15:18:00 -07001115 goingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
Dianne Hackborn40011092011-09-22 13:37:48 -07001116 }
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001117 }
1118
Jeff Brownf71343d2013-05-31 17:59:11 -07001119 /**
1120 * Read values from config.xml that may be overridden depending on
1121 * the configuration of the device.
1122 * eg. Disable long press on home goes to recents on sw600dp.
1123 */
1124 private void readConfigurationDependentBehaviors() {
1125 mLongPressOnHomeBehavior = mContext.getResources().getInteger(
1126 com.android.internal.R.integer.config_longPressOnHomeBehavior);
1127 if (mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING ||
1128 mLongPressOnHomeBehavior > LONG_PRESS_HOME_ASSIST) {
1129 mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1130 }
1131
1132 mDoubleTapOnHomeBehavior = mContext.getResources().getInteger(
1133 com.android.internal.R.integer.config_doubleTapOnHomeBehavior);
1134 if (mDoubleTapOnHomeBehavior < DOUBLE_TAP_HOME_NOTHING ||
1135 mDoubleTapOnHomeBehavior > DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1136 mDoubleTapOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1137 }
1138 }
1139
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001140 @Override
Dianne Hackborndde331c2012-08-03 14:01:57 -07001141 public void setInitialDisplaySize(Display display, int width, int height, int density) {
Jeff Brownef981a42013-08-07 14:13:37 -07001142 // This method might be called before the policy has been fully initialized
1143 // or for other displays we don't care about.
1144 if (mContext == null || display.getDisplayId() != Display.DEFAULT_DISPLAY) {
1145 return;
Dianne Hackbornc652de82013-02-15 16:32:56 -08001146 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001147 mDisplay = display;
1148
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001149 final Resources res = mContext.getResources();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001150 int shortSize, longSize;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001151 if (width > height) {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001152 shortSize = height;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001153 longSize = width;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001154 mLandscapeRotation = Surface.ROTATION_0;
1155 mSeascapeRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001156 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001157 mPortraitRotation = Surface.ROTATION_90;
1158 mUpsideDownRotation = Surface.ROTATION_270;
1159 } else {
1160 mPortraitRotation = Surface.ROTATION_270;
1161 mUpsideDownRotation = Surface.ROTATION_90;
1162 }
1163 } else {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001164 shortSize = width;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001165 longSize = height;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001166 mPortraitRotation = Surface.ROTATION_0;
1167 mUpsideDownRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001168 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001169 mLandscapeRotation = Surface.ROTATION_270;
1170 mSeascapeRotation = Surface.ROTATION_90;
1171 } else {
1172 mLandscapeRotation = Surface.ROTATION_90;
1173 mSeascapeRotation = Surface.ROTATION_270;
1174 }
1175 }
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001176
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001177 mStatusBarHeight =
1178 res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001179
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001180 // Height of the navigation bar when presented horizontally at bottom
1181 mNavigationBarHeightForRotation[mPortraitRotation] =
1182 mNavigationBarHeightForRotation[mUpsideDownRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001183 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_height);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001184 mNavigationBarHeightForRotation[mLandscapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001185 mNavigationBarHeightForRotation[mSeascapeRotation] = res.getDimensionPixelSize(
1186 com.android.internal.R.dimen.navigation_bar_height_landscape);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001187
1188 // Width of the navigation bar when presented vertically along one side
1189 mNavigationBarWidthForRotation[mPortraitRotation] =
1190 mNavigationBarWidthForRotation[mUpsideDownRotation] =
1191 mNavigationBarWidthForRotation[mLandscapeRotation] =
1192 mNavigationBarWidthForRotation[mSeascapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001193 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_width);
Daniel Sandler4a066c52012-04-20 14:49:13 -04001194
1195 // SystemUI (status bar) layout policy
Dianne Hackborndde331c2012-08-03 14:01:57 -07001196 int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / density;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001197 int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / density;
Daniel Sandler4a066c52012-04-20 14:49:13 -04001198
Craig Mautnerd4ec33242013-07-22 10:37:43 -07001199 // Allow the navigation bar to move on small devices (phones).
1200 mNavigationBarCanMove = shortSizeDp < 600;
Daniel Sandler36412a72011-08-04 09:35:13 -04001201
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001202 mHasNavigationBar = res.getBoolean(com.android.internal.R.bool.config_showNavigationBar);
John Spurlock80f00c12013-06-13 11:10:51 -04001203 // Allow a system property to override this. Used by the emulator.
1204 // See also hasNavigationBar().
1205 String navBarOverride = SystemProperties.get("qemu.hw.mainkeys");
1206 if ("1".equals(navBarOverride)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001207 mHasNavigationBar = false;
John Spurlock80f00c12013-06-13 11:10:51 -04001208 } else if ("0".equals(navBarOverride)) {
1209 mHasNavigationBar = true;
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04001210 }
1211
Jeff Brown27f1d672012-10-17 18:32:34 -07001212 // For demo purposes, allow the rotation of the HDMI display to be controlled.
1213 // By default, HDMI locks rotation to landscape.
Erik Gilling9a41ef82011-09-26 19:21:03 -07001214 if ("portrait".equals(SystemProperties.get("persist.demo.hdmirotation"))) {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001215 mDemoHdmiRotation = mPortraitRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001216 } else {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001217 mDemoHdmiRotation = mLandscapeRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001218 }
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001219 mDemoHdmiRotationLock = SystemProperties.getBoolean("persist.demo.hdmirotationlock", false);
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001220
1221 // Only force the default orientation if the screen is xlarge, at least 960dp x 720dp, per
1222 // http://developer.android.com/guide/practices/screens_support.html#range
1223 mForceDefaultOrientation = longSizeDp >= 960 && shortSizeDp >= 720 &&
1224 res.getBoolean(com.android.internal.R.bool.config_forceDefaultOrientation) &&
1225 // For debug purposes the next line turns this feature off with:
1226 // $ adb shell setprop config.override_forced_orient true
1227 // $ adb shell wm size reset
1228 !"true".equals(SystemProperties.get("config.override_forced_orient"));
1229 }
1230
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001231 /**
1232 * @return whether the navigation bar can be hidden, e.g. the device has a
1233 * navigation bar and touch exploration is not enabled
1234 */
1235 private boolean canHideNavigationBar() {
Svetoslav8e3feb12014-02-24 13:46:47 -08001236 return mHasNavigationBar
1237 && !mAccessibilityManager.isTouchExplorationEnabled();
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001238 }
1239
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001240 @Override
1241 public boolean isDefaultOrientationForced() {
1242 return mForceDefaultOrientation;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001243 }
1244
Dianne Hackbornc652de82013-02-15 16:32:56 -08001245 @Override
1246 public void setDisplayOverscan(Display display, int left, int top, int right, int bottom) {
1247 if (display.getDisplayId() == Display.DEFAULT_DISPLAY) {
1248 mOverscanLeft = left;
1249 mOverscanTop = top;
1250 mOverscanRight = right;
1251 mOverscanBottom = bottom;
1252 }
1253 }
1254
Dianne Hackbornc777e072010-02-12 13:07:59 -08001255 public void updateSettings() {
1256 ContentResolver resolver = mContext.getContentResolver();
1257 boolean updateRotation = false;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001258 synchronized (mLock) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001259 mEndcallBehavior = Settings.System.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001260 Settings.System.END_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001261 Settings.System.END_BUTTON_BEHAVIOR_DEFAULT,
1262 UserHandle.USER_CURRENT);
1263 mIncallPowerBehavior = Settings.Secure.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001264 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001265 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT,
1266 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001267
Jeff Browna20dda42014-05-27 20:57:24 -07001268 // Configure wake gesture.
1269 boolean wakeGestureEnabledSetting = Settings.Secure.getIntForUser(resolver,
1270 Settings.Secure.WAKE_GESTURE_ENABLED, 0,
1271 UserHandle.USER_CURRENT) != 0;
1272 if (mWakeGestureEnabledSetting != wakeGestureEnabledSetting) {
1273 mWakeGestureEnabledSetting = wakeGestureEnabledSetting;
1274 updateWakeGestureListenerLp();
1275 }
1276
Jeff Brown207673cd2012-06-05 17:47:11 -07001277 // Configure rotation lock.
Christopher Tate5e08af02012-09-21 17:17:22 -07001278 int userRotation = Settings.System.getIntForUser(resolver,
1279 Settings.System.USER_ROTATION, Surface.ROTATION_0,
1280 UserHandle.USER_CURRENT);
Jeff Brown207673cd2012-06-05 17:47:11 -07001281 if (mUserRotation != userRotation) {
1282 mUserRotation = userRotation;
1283 updateRotation = true;
1284 }
Christopher Tate5e08af02012-09-21 17:17:22 -07001285 int userRotationMode = Settings.System.getIntForUser(resolver,
1286 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
Jeff Brown207673cd2012-06-05 17:47:11 -07001287 WindowManagerPolicy.USER_ROTATION_FREE :
1288 WindowManagerPolicy.USER_ROTATION_LOCKED;
1289 if (mUserRotationMode != userRotationMode) {
1290 mUserRotationMode = userRotationMode;
1291 updateRotation = true;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001292 updateOrientationListenerLp();
1293 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001294
Dianne Hackbornc777e072010-02-12 13:07:59 -08001295 if (mSystemReady) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001296 int pointerLocation = Settings.System.getIntForUser(resolver,
1297 Settings.System.POINTER_LOCATION, 0, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001298 if (mPointerLocationMode != pointerLocation) {
1299 mPointerLocationMode = pointerLocation;
Jeff Brown70825162012-03-28 17:27:48 -07001300 mHandler.sendEmptyMessage(pointerLocation != 0 ?
1301 MSG_ENABLE_POINTER_LOCATION : MSG_DISABLE_POINTER_LOCATION);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001302 }
1303 }
1304 // use screen off timeout setting as the timeout for the lockscreen
Christopher Tate5e08af02012-09-21 17:17:22 -07001305 mLockScreenTimeout = Settings.System.getIntForUser(resolver,
1306 Settings.System.SCREEN_OFF_TIMEOUT, 0, UserHandle.USER_CURRENT);
1307 String imId = Settings.Secure.getStringForUser(resolver,
1308 Settings.Secure.DEFAULT_INPUT_METHOD, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001309 boolean hasSoftInput = imId != null && imId.length() > 0;
1310 if (mHasSoftInput != hasSoftInput) {
1311 mHasSoftInput = hasSoftInput;
1312 updateRotation = true;
1313 }
John Spurlockf1a36642013-10-12 17:50:42 -04001314 if (mImmersiveModeConfirmation != null) {
John Spurlock4355a532014-02-19 09:49:25 -05001315 mImmersiveModeConfirmation.loadSetting(mCurrentUserId);
John Spurlockd67ec252013-09-05 11:31:54 -04001316 }
John Spurlockc6d1c602014-01-17 15:22:06 -05001317 PolicyControl.reloadFromSetting(mContext);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001318 }
1319 if (updateRotation) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07001320 updateRotation(true);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001321 }
Jeff Brown70825162012-03-28 17:27:48 -07001322 }
1323
Jeff Browna20dda42014-05-27 20:57:24 -07001324 private void updateWakeGestureListenerLp() {
1325 if (shouldEnableWakeGestureLp()) {
1326 mWakeGestureListener.requestWakeUpTrigger();
1327 } else {
1328 mWakeGestureListener.cancelWakeUpTrigger();
1329 }
1330 }
1331
1332 private boolean shouldEnableWakeGestureLp() {
1333 return mWakeGestureEnabledSetting && !mScreenOnEarly
1334 && (!mLidControlsSleep || mLidState != LID_CLOSED)
1335 && mWakeGestureListener.isSupported();
1336 }
1337
Jeff Brown70825162012-03-28 17:27:48 -07001338 private void enablePointerLocation() {
1339 if (mPointerLocationView == null) {
1340 mPointerLocationView = new PointerLocationView(mContext);
1341 mPointerLocationView.setPrintCoords(false);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001342 WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
1343 WindowManager.LayoutParams.MATCH_PARENT,
1344 WindowManager.LayoutParams.MATCH_PARENT);
Jeff Brown3b2b3542010-10-15 00:54:27 -07001345 lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001346 lp.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN
1347 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
1348 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1349 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
Jeff Brown90fc9052012-10-01 14:44:24 -07001350 if (ActivityManager.isHighEndGfx()) {
1351 lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
1352 lp.privateFlags |=
1353 WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED;
1354 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001355 lp.format = PixelFormat.TRANSLUCENT;
1356 lp.setTitle("PointerLocation");
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001357 WindowManager wm = (WindowManager)
Dianne Hackbornc777e072010-02-12 13:07:59 -08001358 mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Browncc4f7db2011-08-30 20:34:48 -07001359 lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL;
Jeff Brown70825162012-03-28 17:27:48 -07001360 wm.addView(mPointerLocationView, lp);
Michael Wrightc9c487e2013-11-07 18:55:09 -08001361 mWindowManagerFuncs.registerPointerEventListener(mPointerLocationView);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001362 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001363 }
Jeff Brown70825162012-03-28 17:27:48 -07001364
1365 private void disablePointerLocation() {
Jeff Brown70825162012-03-28 17:27:48 -07001366 if (mPointerLocationView != null) {
Michael Wrightc9c487e2013-11-07 18:55:09 -08001367 mWindowManagerFuncs.unregisterPointerEventListener(mPointerLocationView);
1368 WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Brown70825162012-03-28 17:27:48 -07001369 wm.removeView(mPointerLocationView);
1370 mPointerLocationView = null;
1371 }
1372 }
1373
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001374 private int readRotation(int resID) {
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001375 try {
1376 int rotation = mContext.getResources().getInteger(resID);
1377 switch (rotation) {
1378 case 0:
1379 return Surface.ROTATION_0;
1380 case 90:
1381 return Surface.ROTATION_90;
1382 case 180:
1383 return Surface.ROTATION_180;
1384 case 270:
1385 return Surface.ROTATION_270;
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001386 }
1387 } catch (Resources.NotFoundException e) {
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001388 // fall through
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001389 }
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001390 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001391 }
1392
1393 /** {@inheritDoc} */
Craig Mautner88400d32012-09-30 12:35:45 -07001394 @Override
Dianne Hackbornc2293022013-02-06 23:14:49 -08001395 public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001396 int type = attrs.type;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001397
1398 outAppOp[0] = AppOpsManager.OP_NONE;
1399
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001400 if (type < WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW
1401 || type > WindowManager.LayoutParams.LAST_SYSTEM_WINDOW) {
Jeff Brown98365d72012-08-19 20:30:52 -07001402 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001403 }
1404 String permission = null;
1405 switch (type) {
1406 case TYPE_TOAST:
1407 // XXX right now the app process has complete control over
1408 // this... should introduce a token to let the system
1409 // monitor/control what they are doing.
Jason Monk1c7c3192014-06-26 12:52:18 -04001410 outAppOp[0] = AppOpsManager.OP_TOAST_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001411 break;
Daniel Sandler7d276c32012-01-30 14:33:52 -05001412 case TYPE_DREAM:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001413 case TYPE_INPUT_METHOD:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001414 case TYPE_WALLPAPER:
keunyounga446bf02013-06-21 19:07:57 -07001415 case TYPE_PRIVATE_PRESENTATION:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001416 case TYPE_VOICE_INTERACTION:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001417 // The window manager will check these.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001418 break;
1419 case TYPE_PHONE:
1420 case TYPE_PRIORITY_PHONE:
1421 case TYPE_SYSTEM_ALERT:
1422 case TYPE_SYSTEM_ERROR:
1423 case TYPE_SYSTEM_OVERLAY:
1424 permission = android.Manifest.permission.SYSTEM_ALERT_WINDOW;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001425 outAppOp[0] = AppOpsManager.OP_SYSTEM_ALERT_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001426 break;
1427 default:
1428 permission = android.Manifest.permission.INTERNAL_SYSTEM_WINDOW;
1429 }
1430 if (permission != null) {
1431 if (mContext.checkCallingOrSelfPermission(permission)
1432 != PackageManager.PERMISSION_GRANTED) {
Jeff Brown98365d72012-08-19 20:30:52 -07001433 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001434 }
1435 }
Jeff Brown98365d72012-08-19 20:30:52 -07001436 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001437 }
Craig Mautner88400d32012-09-30 12:35:45 -07001438
1439 @Override
1440 public boolean checkShowToOwnerOnly(WindowManager.LayoutParams attrs) {
1441
1442 // If this switch statement is modified, modify the comment in the declarations of
1443 // the type in {@link WindowManager.LayoutParams} as well.
1444 switch (attrs.type) {
1445 default:
1446 // These are the windows that by default are shown only to the user that created
1447 // them. If this needs to be overridden, set
1448 // {@link WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS} in
1449 // {@link WindowManager.LayoutParams}. Note that permission
1450 // {@link android.Manifest.permission.INTERNAL_SYSTEM_WINDOW} is required as well.
1451 if ((attrs.privateFlags & PRIVATE_FLAG_SHOW_FOR_ALL_USERS) == 0) {
1452 return true;
1453 }
1454 break;
1455
1456 // These are the windows that by default are shown to all users. However, to
1457 // protect against spoofing, check permissions below.
1458 case TYPE_APPLICATION_STARTING:
1459 case TYPE_BOOT_PROGRESS:
1460 case TYPE_DISPLAY_OVERLAY:
1461 case TYPE_HIDDEN_NAV_CONSUMER:
Jim Miller5ecd8112013-01-09 18:50:26 -08001462 case TYPE_KEYGUARD_SCRIM:
Craig Mautner88400d32012-09-30 12:35:45 -07001463 case TYPE_KEYGUARD_DIALOG:
1464 case TYPE_MAGNIFICATION_OVERLAY:
1465 case TYPE_NAVIGATION_BAR:
1466 case TYPE_NAVIGATION_BAR_PANEL:
1467 case TYPE_PHONE:
1468 case TYPE_POINTER:
1469 case TYPE_PRIORITY_PHONE:
1470 case TYPE_RECENTS_OVERLAY:
1471 case TYPE_SEARCH_BAR:
1472 case TYPE_STATUS_BAR:
1473 case TYPE_STATUS_BAR_PANEL:
1474 case TYPE_STATUS_BAR_SUB_PANEL:
1475 case TYPE_SYSTEM_DIALOG:
1476 case TYPE_UNIVERSE_BACKGROUND:
1477 case TYPE_VOLUME_OVERLAY:
keunyounga446bf02013-06-21 19:07:57 -07001478 case TYPE_PRIVATE_PRESENTATION:
Craig Mautner88400d32012-09-30 12:35:45 -07001479 break;
1480 }
1481
1482 // Check if third party app has set window to system window type.
1483 return mContext.checkCallingOrSelfPermission(
1484 android.Manifest.permission.INTERNAL_SYSTEM_WINDOW)
1485 != PackageManager.PERMISSION_GRANTED;
1486 }
1487
Craig Mautner967212c2013-04-13 21:10:58 -07001488 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001489 public void adjustWindowParamsLw(WindowManager.LayoutParams attrs) {
1490 switch (attrs.type) {
1491 case TYPE_SYSTEM_OVERLAY:
Jeff Brown3b2b3542010-10-15 00:54:27 -07001492 case TYPE_SECURE_SYSTEM_OVERLAY:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001493 // These types of windows can't receive input events.
1494 attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1495 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001496 attrs.flags &= ~WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001497 break;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001498 case TYPE_STATUS_BAR:
1499
1500 // If the Keyguard is in a hidden state (occluded by another window), we force to
1501 // remove the wallpaper and keyguard flag so that any change in-flight after setting
1502 // the keyguard as occluded wouldn't set these flags again.
1503 // See {@link #processKeyguardSetHiddenResultLw}.
1504 if (mKeyguardHidden) {
1505 attrs.flags &= ~WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
1506 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
1507 }
1508 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001509 }
Adrian Roos38502112014-04-09 21:04:11 +02001510
1511 if (attrs.type != TYPE_STATUS_BAR) {
1512 // The status bar is the only window allowed to exhibit keyguard behavior.
1513 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
1514 }
Adrian Roosea562512014-05-05 13:33:03 +02001515
1516 if (ActivityManager.isHighEndGfx()
1517 && (attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0) {
1518 attrs.subtreeSystemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_STABLE
1519 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
1520 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
1521 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001522 }
RoboErik8a2cfc32014-05-16 11:19:38 -07001523
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001524 void readLidState() {
Jeff Brown2e7760e2012-04-11 15:14:55 -07001525 mLidState = mWindowManagerFuncs.getLidState();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001526 }
RoboErik8a2cfc32014-05-16 11:19:38 -07001527
Jeff Browndaa37532012-05-01 15:54:03 -07001528 private boolean isHidden(int accessibilityMode) {
1529 switch (accessibilityMode) {
1530 case 1:
1531 return mLidState == LID_CLOSED;
1532 case 2:
1533 return mLidState == LID_OPEN;
1534 default:
1535 return false;
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001536 }
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001537 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001538
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001539 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07001540 @Override
Jeff Browndaa37532012-05-01 15:54:03 -07001541 public void adjustConfigurationLw(Configuration config, int keyboardPresence,
1542 int navigationPresence) {
1543 mHaveBuiltInKeyboard = (keyboardPresence & PRESENCE_INTERNAL) != 0;
1544
Jeff Brownf71343d2013-05-31 17:59:11 -07001545 readConfigurationDependentBehaviors();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001546 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07001547 applyLidSwitchState();
Jeff Brownd04a88c2011-01-16 14:05:47 -08001548
Jeff Browndaa37532012-05-01 15:54:03 -07001549 if (config.keyboard == Configuration.KEYBOARD_NOKEYS
1550 || (keyboardPresence == PRESENCE_INTERNAL
1551 && isHidden(mLidKeyboardAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001552 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_YES;
Jeff Browndaa37532012-05-01 15:54:03 -07001553 if (!mHasSoftInput) {
1554 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_YES;
1555 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001556 }
1557
Jeff Browndaa37532012-05-01 15:54:03 -07001558 if (config.navigation == Configuration.NAVIGATION_NONAV
1559 || (navigationPresence == PRESENCE_INTERNAL
1560 && isHidden(mLidNavigationAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001561 config.navigationHidden = Configuration.NAVIGATIONHIDDEN_YES;
Jeff Brownd04a88c2011-01-16 14:05:47 -08001562 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001563 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001564
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001565 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07001566 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001567 public int windowTypeToLayerLw(int type) {
1568 if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001569 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001570 }
1571 switch (type) {
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001572 case TYPE_UNIVERSE_BACKGROUND:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001573 return 1;
keunyounga446bf02013-06-21 19:07:57 -07001574 case TYPE_PRIVATE_PRESENTATION:
1575 return 2;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001576 case TYPE_WALLPAPER:
1577 // wallpaper is at the bottom, though the window manager may move it.
1578 return 2;
1579 case TYPE_PHONE:
1580 return 3;
1581 case TYPE_SEARCH_BAR:
1582 return 4;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001583 case TYPE_VOICE_INTERACTION:
1584 // voice interaction layer is almost immediately above apps.
1585 return 5;
Craig Mautner88400d32012-09-30 12:35:45 -07001586 case TYPE_RECENTS_OVERLAY:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001587 case TYPE_SYSTEM_DIALOG:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001588 return 6;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001589 case TYPE_TOAST:
1590 // toasts and the plugged-in battery thing
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001591 return 7;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001592 case TYPE_PRIORITY_PHONE:
1593 // SIM errors and unlock. Not sure if this really should be in a high layer.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001594 return 8;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001595 case TYPE_DREAM:
1596 // used for Dreams (screensavers with TYPE_DREAM windows)
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001597 return 9;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001598 case TYPE_SYSTEM_ALERT:
1599 // like the ANR / app crashed dialogs
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001600 return 10;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001601 case TYPE_INPUT_METHOD:
1602 // on-screen keyboards and other such input method user interfaces go here.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001603 return 11;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001604 case TYPE_INPUT_METHOD_DIALOG:
1605 // on-screen keyboards and other such input method user interfaces go here.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001606 return 12;
Jim Miller5ecd8112013-01-09 18:50:26 -08001607 case TYPE_KEYGUARD_SCRIM:
1608 // the safety window that shows behind keyguard while keyguard is starting
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001609 return 13;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001610 case TYPE_STATUS_BAR_SUB_PANEL:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001611 return 14;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001612 case TYPE_STATUS_BAR:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001613 return 15;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001614 case TYPE_STATUS_BAR_PANEL:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001615 return 16;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001616 case TYPE_KEYGUARD_DIALOG:
1617 return 17;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001618 case TYPE_VOLUME_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 18;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001622 case TYPE_SYSTEM_OVERLAY:
1623 // the on-screen volume indicator and controller shown when the user
1624 // changes the device volume
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001625 return 19;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001626 case TYPE_NAVIGATION_BAR:
1627 // the navigation bar, if available, shows atop most things
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001628 return 20;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001629 case TYPE_NAVIGATION_BAR_PANEL:
1630 // some panels (e.g. search) need to show on top of the navigation bar
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001631 return 21;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001632 case TYPE_SYSTEM_ERROR:
1633 // system-level error dialogs
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001634 return 22;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001635 case TYPE_MAGNIFICATION_OVERLAY:
1636 // used to highlight the magnified portion of a display
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001637 return 23;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001638 case TYPE_DISPLAY_OVERLAY:
1639 // used to simulate secondary display devices
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001640 return 24;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001641 case TYPE_DRAG:
1642 // the drag layer: input for drag-and-drop is associated with this window,
1643 // which sits above all other focusable windows
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001644 return 25;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001645 case TYPE_SECURE_SYSTEM_OVERLAY:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001646 return 26;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001647 case TYPE_BOOT_PROGRESS:
1648 return 27;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001649 case TYPE_POINTER:
1650 // the (mouse) pointer layer
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001651 return 28;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001652 case TYPE_HIDDEN_NAV_CONSUMER:
1653 return 29;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001654 }
1655 Log.e(TAG, "Unknown window type: " + type);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001656 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001657 }
1658
1659 /** {@inheritDoc} */
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001660 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001661 public int subWindowTypeToLayerLw(int type) {
1662 switch (type) {
1663 case TYPE_APPLICATION_PANEL:
1664 case TYPE_APPLICATION_ATTACHED_DIALOG:
1665 return APPLICATION_PANEL_SUBLAYER;
1666 case TYPE_APPLICATION_MEDIA:
1667 return APPLICATION_MEDIA_SUBLAYER;
Dianne Hackborn5cb8d792009-05-21 17:34:15 -07001668 case TYPE_APPLICATION_MEDIA_OVERLAY:
1669 return APPLICATION_MEDIA_OVERLAY_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001670 case TYPE_APPLICATION_SUB_PANEL:
1671 return APPLICATION_SUB_PANEL_SUBLAYER;
1672 }
1673 Log.e(TAG, "Unknown sub-window type: " + type);
1674 return 0;
1675 }
1676
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001677 @Override
Dianne Hackbornabe0da02009-09-18 01:55:39 -07001678 public int getMaxWallpaperLayer() {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001679 return windowTypeToLayerLw(TYPE_STATUS_BAR);
Dianne Hackbornabe0da02009-09-18 01:55:39 -07001680 }
1681
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001682 @Override
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001683 public int getAboveUniverseLayer() {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001684 return windowTypeToLayerLw(TYPE_SYSTEM_ERROR);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001685 }
1686
Jose Lima9546b202014-07-02 17:21:51 -07001687 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001688 public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07001689 if (mHasNavigationBar) {
1690 // For a basic navigation bar, when we are in landscape mode we place
1691 // the navigation bar to the side.
Daniel Sandler4a066c52012-04-20 14:49:13 -04001692 if (mNavigationBarCanMove && fullWidth > fullHeight) {
1693 return fullWidth - mNavigationBarWidthForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07001694 }
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001695 }
1696 return fullWidth;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001697 }
1698
Jose Lima9546b202014-07-02 17:21:51 -07001699 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001700 public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07001701 if (mHasNavigationBar) {
1702 // For a basic navigation bar, when we are in portrait mode we place
1703 // the navigation bar to the bottom.
Daniel Sandler4a066c52012-04-20 14:49:13 -04001704 if (!mNavigationBarCanMove || fullWidth < fullHeight) {
1705 return fullHeight - mNavigationBarHeightForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07001706 }
1707 }
1708 return fullHeight;
Dianne Hackborn69cb8752011-05-19 18:13:32 -07001709 }
1710
Jose Lima9546b202014-07-02 17:21:51 -07001711 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001712 public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation) {
1713 return getNonDecorDisplayWidth(fullWidth, fullHeight, rotation);
Dianne Hackborn69cb8752011-05-19 18:13:32 -07001714 }
1715
Jose Lima9546b202014-07-02 17:21:51 -07001716 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001717 public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation) {
John Spurlock80f00c12013-06-13 11:10:51 -04001718 // There is a separate status bar at the top of the display. We don't count that as part
1719 // of the fixed decor, since it can hide; however, for purposes of configurations,
Dianne Hackborn077ee852012-04-09 16:27:07 -07001720 // we do want to exclude it since applications can't generally use that part
1721 // of the screen.
John Spurlock80f00c12013-06-13 11:10:51 -04001722 return getNonDecorDisplayHeight(fullWidth, fullHeight, rotation) - mStatusBarHeight;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001723 }
1724
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001725 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07001726 public boolean isForceHiding(WindowManager.LayoutParams attrs) {
1727 return (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 ||
Adrian Roos69e510d2014-07-13 14:57:59 +02001728 (isKeyguardHostWindow(attrs) && isKeyguardSecureIncludingHidden()) ||
1729 (attrs.type == TYPE_KEYGUARD_SCRIM);
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07001730 }
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001731
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001732 @Override
Jorim Jaggi0d674622014-05-21 01:34:15 +02001733 public boolean isKeyguardHostWindow(WindowManager.LayoutParams attrs) {
1734 return attrs.type == TYPE_STATUS_BAR;
1735 }
1736
1737 @Override
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07001738 public boolean canBeForceHidden(WindowState win, WindowManager.LayoutParams attrs) {
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001739 switch (attrs.type) {
1740 case TYPE_STATUS_BAR:
1741 case TYPE_NAVIGATION_BAR:
1742 case TYPE_WALLPAPER:
1743 case TYPE_DREAM:
1744 case TYPE_UNIVERSE_BACKGROUND:
Jim Miller5ecd8112013-01-09 18:50:26 -08001745 case TYPE_KEYGUARD_SCRIM:
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001746 return false;
1747 default:
1748 return true;
1749 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07001750 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001751
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001752 /** {@inheritDoc} */
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001753 @Override
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07001754 public View addStartingWindow(IBinder appToken, String packageName, int theme,
1755 CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes,
Adam Powell04fe6eb2013-05-31 14:39:48 -07001756 int icon, int logo, int windowFlags) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001757 if (!SHOW_STARTING_ANIMATIONS) {
1758 return null;
1759 }
1760 if (packageName == null) {
1761 return null;
1762 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001763
Mathias Jeppssond1443e92012-08-24 15:25:32 +02001764 WindowManager wm = null;
1765 View view = null;
1766
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001767 try {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001768 Context context = mContext;
Craig Mautner6fbda632012-07-03 09:26:39 -07001769 if (DEBUG_STARTING_WINDOW) Slog.d(TAG, "addStartingWindow " + packageName
1770 + ": nonLocalizedLabel=" + nonLocalizedLabel + " theme="
1771 + Integer.toHexString(theme));
Dianne Hackborn247fe742011-01-08 17:25:57 -08001772 if (theme != context.getThemeResId() || labelRes != 0) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001773 try {
1774 context = context.createPackageContext(packageName, 0);
Dianne Hackborn247fe742011-01-08 17:25:57 -08001775 context.setTheme(theme);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001776 } catch (PackageManager.NameNotFoundException e) {
1777 // Ignore
1778 }
1779 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001780
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001781 Window win = PolicyManager.makeNewWindow(context);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001782 final TypedArray ta = win.getWindowStyle();
1783 if (ta.getBoolean(
1784 com.android.internal.R.styleable.Window_windowDisablePreview, false)
1785 || ta.getBoolean(
1786 com.android.internal.R.styleable.Window_windowShowWallpaper,false)) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001787 return null;
1788 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001789
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001790 Resources r = context.getResources();
1791 win.setTitle(r.getText(labelRes, nonLocalizedLabel));
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001792
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001793 win.setType(
1794 WindowManager.LayoutParams.TYPE_APPLICATION_STARTING);
1795 // Force the window flags: this is a fake window, so it is not really
1796 // touchable or focusable by the user. We also add in the ALT_FOCUSABLE_IM
1797 // flag because we do know that the next window will take input
1798 // focus, so we want to get the IME window up on top of us right away.
1799 win.setFlags(
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,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08001804 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001805 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
1806 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
1807 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001808
Adam Powell04fe6eb2013-05-31 14:39:48 -07001809 win.setDefaultIcon(icon);
1810 win.setDefaultLogo(logo);
1811
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001812 win.setLayout(WindowManager.LayoutParams.MATCH_PARENT,
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07001813 WindowManager.LayoutParams.MATCH_PARENT);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001814
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001815 final WindowManager.LayoutParams params = win.getAttributes();
1816 params.token = appToken;
1817 params.packageName = packageName;
1818 params.windowAnimations = win.getWindowStyle().getResourceId(
1819 com.android.internal.R.styleable.Window_windowAnimationStyle, 0);
Dianne Hackborn5d927c22011-09-02 12:22:18 -07001820 params.privateFlags |=
1821 WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED;
Craig Mautner88400d32012-09-30 12:35:45 -07001822 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
Adam Lesinski95c42972013-10-02 10:13:27 -07001823
1824 if (!compatInfo.supportsScreen()) {
1825 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
1826 }
1827
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001828 params.setTitle("Starting " + packageName);
1829
Mathias Jeppssond1443e92012-08-24 15:25:32 +02001830 wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
1831 view = win.getDecorView();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001832
1833 if (win.isFloating()) {
1834 // Whoops, there is no way to display an animation/preview
1835 // of such a thing! After all that work... let's skip it.
1836 // (Note that we must do this here because it is in
1837 // getDecorView() where the theme is evaluated... maybe
1838 // we should peek the floating attribute from the theme
1839 // earlier.)
1840 return null;
1841 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001842
Craig Mautner6fbda632012-07-03 09:26:39 -07001843 if (DEBUG_STARTING_WINDOW) Slog.d(
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001844 TAG, "Adding starting window for " + packageName
1845 + " / " + appToken + ": "
1846 + (view.getParent() != null ? view : null));
1847
1848 wm.addView(view, params);
1849
1850 // Only return the view if it was successfully added to the
1851 // window manager... which we can tell by it having a parent.
1852 return view.getParent() != null ? view : null;
Jeff Brown98365d72012-08-19 20:30:52 -07001853 } catch (WindowManager.BadTokenException e) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001854 // ignore
Craig Mautner42bf39e2014-02-21 16:46:22 -08001855 Log.w(TAG, appToken + " already running, starting window not displayed. " +
1856 e.getMessage());
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001857 } catch (RuntimeException e) {
1858 // don't crash if something else bad happens, for example a
1859 // failure loading resources because we are loading from an app
1860 // on external storage that has been unmounted.
1861 Log.w(TAG, appToken + " failed creating starting window", e);
Mathias Jeppssond1443e92012-08-24 15:25:32 +02001862 } finally {
1863 if (view != null && view.getParent() == null) {
1864 Log.w(TAG, "view not successfully added to wm, removing view");
1865 wm.removeViewImmediate(view);
1866 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001867 }
1868
1869 return null;
1870 }
1871
1872 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07001873 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001874 public void removeStartingWindow(IBinder appToken, View window) {
Craig Mautner6fbda632012-07-03 09:26:39 -07001875 if (DEBUG_STARTING_WINDOW) {
1876 RuntimeException e = new RuntimeException("here");
1877 e.fillInStackTrace();
1878 Log.v(TAG, "Removing starting window for " + appToken + ": " + window, e);
1879 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001880
1881 if (window != null) {
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001882 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001883 wm.removeView(window);
1884 }
1885 }
1886
1887 /**
1888 * Preflight adding a window to the system.
RoboErik8a2cfc32014-05-16 11:19:38 -07001889 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001890 * Currently enforces that three window types are singletons:
1891 * <ul>
1892 * <li>STATUS_BAR_TYPE</li>
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001893 * <li>KEYGUARD_TYPE</li>
1894 * </ul>
RoboErik8a2cfc32014-05-16 11:19:38 -07001895 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001896 * @param win The window to be added
1897 * @param attrs Information about the window to be added
RoboErik8a2cfc32014-05-16 11:19:38 -07001898 *
Jeff Brown98365d72012-08-19 20:30:52 -07001899 * @return If ok, WindowManagerImpl.ADD_OKAY. If too many singletons,
1900 * WindowManagerImpl.ADD_MULTIPLE_SINGLETON
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001901 */
Jose Lima9546b202014-07-02 17:21:51 -07001902 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001903 public int prepareAddWindowLw(WindowState win, WindowManager.LayoutParams attrs) {
1904 switch (attrs.type) {
1905 case TYPE_STATUS_BAR:
Joe Onorato8bc6c512010-06-04 16:21:12 -04001906 mContext.enforceCallingOrSelfPermission(
1907 android.Manifest.permission.STATUS_BAR_SERVICE,
1908 "PhoneWindowManager");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001909 if (mStatusBar != null) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001910 if (mStatusBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07001911 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001912 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001913 }
1914 mStatusBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04001915 mStatusBarController.setWindow(win);
John Spurlock8fdfe622014-05-21 17:10:10 -04001916 mKeyguardDelegate.hideScrim();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001917 break;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04001918 case TYPE_NAVIGATION_BAR:
1919 mContext.enforceCallingOrSelfPermission(
1920 android.Manifest.permission.STATUS_BAR_SERVICE,
1921 "PhoneWindowManager");
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001922 if (mNavigationBar != null) {
1923 if (mNavigationBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07001924 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001925 }
1926 }
Daniel Sandler8956dbb2011-04-22 07:55:02 -04001927 mNavigationBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04001928 mNavigationBarController.setWindow(win);
Craig Mautnereda67292013-04-28 13:50:14 -07001929 if (DEBUG_LAYOUT) Slog.i(TAG, "NAVIGATION BAR: " + mNavigationBar);
Daniel Sandler8956dbb2011-04-22 07:55:02 -04001930 break;
Jim Millere898ac52012-04-06 17:10:57 -07001931 case TYPE_NAVIGATION_BAR_PANEL:
1932 mContext.enforceCallingOrSelfPermission(
1933 android.Manifest.permission.STATUS_BAR_SERVICE,
1934 "PhoneWindowManager");
1935 break;
Dianne Hackborn08743722009-12-21 12:16:51 -08001936 case TYPE_STATUS_BAR_PANEL:
Joe Onorato8bc6c512010-06-04 16:21:12 -04001937 mContext.enforceCallingOrSelfPermission(
1938 android.Manifest.permission.STATUS_BAR_SERVICE,
1939 "PhoneWindowManager");
Dianne Hackborn08743722009-12-21 12:16:51 -08001940 break;
Joe Onorato29fc2c92010-11-24 10:26:50 -08001941 case TYPE_STATUS_BAR_SUB_PANEL:
1942 mContext.enforceCallingOrSelfPermission(
1943 android.Manifest.permission.STATUS_BAR_SERVICE,
1944 "PhoneWindowManager");
Joe Onorato29fc2c92010-11-24 10:26:50 -08001945 break;
Jim Miller5ecd8112013-01-09 18:50:26 -08001946 case TYPE_KEYGUARD_SCRIM:
Jim Miller25190572013-02-28 17:36:24 -08001947 if (mKeyguardScrim != null) {
1948 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
1949 }
Jim Miller5ecd8112013-01-09 18:50:26 -08001950 mKeyguardScrim = win;
1951 break;
1952
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001953 }
Jeff Brown98365d72012-08-19 20:30:52 -07001954 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001955 }
1956
1957 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07001958 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001959 public void removeWindowLw(WindowState win) {
1960 if (mStatusBar == win) {
1961 mStatusBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04001962 mStatusBarController.setWindow(null);
Jim Millerc0b676d2013-03-22 16:11:08 -07001963 mKeyguardDelegate.showScrim();
Jim Miller5ecd8112013-01-09 18:50:26 -08001964 } else if (mKeyguardScrim == win) {
1965 Log.v(TAG, "Removing keyguard scrim");
1966 mKeyguardScrim = null;
1967 } if (mNavigationBar == win) {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04001968 mNavigationBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04001969 mNavigationBarController.setWindow(null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001970 }
1971 }
1972
1973 static final boolean PRINT_ANIM = false;
RoboErik8a2cfc32014-05-16 11:19:38 -07001974
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001975 /** {@inheritDoc} */
Craig Mautner4b71aa12012-12-27 17:20:01 -08001976 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001977 public int selectAnimationLw(WindowState win, int transit) {
1978 if (PRINT_ANIM) Log.i(TAG, "selectAnimation in " + win
1979 + ": transit=" + transit);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001980 if (win == mStatusBar) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001981 boolean isKeyguard = (win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001982 if (transit == TRANSIT_EXIT
1983 || transit == TRANSIT_HIDE) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001984 return isKeyguard ? -1 : R.anim.dock_top_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001985 } else if (transit == TRANSIT_ENTER
1986 || transit == TRANSIT_SHOW) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001987 return isKeyguard ? -1 : R.anim.dock_top_enter;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001988 }
1989 } else if (win == mNavigationBar) {
1990 // This can be on either the bottom or the right.
1991 if (mNavigationBarOnBottom) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08001992 if (transit == TRANSIT_EXIT
1993 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001994 return R.anim.dock_bottom_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001995 } else if (transit == TRANSIT_ENTER
1996 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001997 return R.anim.dock_bottom_enter;
1998 }
1999 } else {
Craig Mautner4b71aa12012-12-27 17:20:01 -08002000 if (transit == TRANSIT_EXIT
2001 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002002 return R.anim.dock_right_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002003 } else if (transit == TRANSIT_ENTER
2004 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002005 return R.anim.dock_right_enter;
2006 }
2007 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08002008 }
2009
2010 if (transit == TRANSIT_PREVIEW_DONE) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002011 if (win.hasAppShownWindows()) {
2012 if (PRINT_ANIM) Log.i(TAG, "**** STARTING EXIT");
2013 return com.android.internal.R.anim.app_starting_exit;
2014 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07002015 } else if (win.getAttrs().type == TYPE_DREAM && mDreamingLockscreen
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002016 && transit == TRANSIT_ENTER) {
2017 // Special case: we are animating in a dream, while the keyguard
2018 // is shown. We don't want an animation on the dream, because
2019 // we need it shown immediately with the keyguard animating away
2020 // to reveal it.
2021 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002022 }
2023
2024 return 0;
2025 }
2026
Craig Mautner3c174372013-02-21 17:54:37 -08002027 @Override
2028 public void selectRotationAnimationLw(int anim[]) {
2029 if (PRINT_ANIM) Slog.i(TAG, "selectRotationAnimation mTopFullscreen="
2030 + mTopFullscreenOpaqueWindowState + " rotationAnimation="
2031 + (mTopFullscreenOpaqueWindowState == null ?
2032 "0" : mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation));
2033 if (mTopFullscreenOpaqueWindowState != null && mTopIsFullscreen) {
2034 switch (mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation) {
2035 case ROTATION_ANIMATION_CROSSFADE:
2036 anim[0] = R.anim.rotation_animation_xfade_exit;
2037 anim[1] = R.anim.rotation_animation_enter;
2038 break;
2039 case ROTATION_ANIMATION_JUMPCUT:
2040 anim[0] = R.anim.rotation_animation_jump_exit;
2041 anim[1] = R.anim.rotation_animation_enter;
2042 break;
2043 case ROTATION_ANIMATION_ROTATE:
2044 default:
2045 anim[0] = anim[1] = 0;
2046 break;
2047 }
2048 } else {
2049 anim[0] = anim[1] = 0;
2050 }
2051 }
2052
2053 @Override
2054 public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId,
2055 boolean forceDefault) {
2056 switch (exitAnimId) {
2057 case R.anim.rotation_animation_xfade_exit:
2058 case R.anim.rotation_animation_jump_exit:
2059 // These are the only cases that matter.
2060 if (forceDefault) {
2061 return false;
2062 }
2063 int anim[] = new int[2];
2064 selectRotationAnimationLw(anim);
2065 return (exitAnimId == anim[0] && enterAnimId == anim[1]);
2066 default:
2067 return true;
2068 }
2069 }
2070
2071 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002072 public Animation createForceHideEnterAnimation(boolean onWallpaper,
2073 boolean goingToNotificationShade) {
2074 if (goingToNotificationShade) {
2075 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_behind_enter_fade_in);
2076 } else if (onWallpaper) {
Jorim Jaggi76a16232014-08-08 17:00:47 +02002077 Animation a = AnimationUtils.loadAnimation(mContext,
2078 R.anim.lock_screen_behind_enter_wallpaper);
2079 AnimationSet set = (AnimationSet) a;
2080
2081 // TODO: Use XML interpolators when we have log interpolators available in XML.
2082 set.getAnimations().get(0).setInterpolator(mLogDecelerateInterpolator);
2083 set.getAnimations().get(1).setInterpolator(mLogDecelerateInterpolator);
Jorim Jaggi76a16232014-08-08 17:00:47 +02002084 return set;
2085 } else {
2086 Animation a = AnimationUtils.loadAnimation(mContext,
2087 R.anim.lock_screen_behind_enter);
2088 AnimationSet set = (AnimationSet) a;
2089
2090 // TODO: Use XML interpolators when we have log interpolators available in XML.
2091 set.getAnimations().get(0).setInterpolator(mLogDecelerateInterpolator);
2092 return set;
2093 }
2094 }
2095
2096
2097 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002098 public Animation createForceHideWallpaperExitAnimation(boolean goingToNotificationShade) {
2099 if (goingToNotificationShade) {
2100 return null;
2101 } else {
2102 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_wallpaper_exit);
2103 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002104 }
John Spurlockc8b46ca2013-04-08 12:59:26 -04002105
2106 private static void awakenDreams() {
2107 IDreamManager dreamManager = getDreamManager();
2108 if (dreamManager != null) {
2109 try {
2110 dreamManager.awaken();
2111 } catch (RemoteException e) {
2112 // fine, stay asleep then
2113 }
2114 }
2115 }
2116
2117 static IDreamManager getDreamManager() {
2118 return IDreamManager.Stub.asInterface(
2119 ServiceManager.checkService(DreamService.DREAM_SERVICE));
2120 }
2121
Santos Cordon9eb45932014-06-27 12:28:43 -07002122 TelecommManager getTelecommService() {
2123 return (TelecommManager) mContext.getSystemService(Context.TELECOMM_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002124 }
2125
Jeff Brown4d396052010-10-29 21:50:21 -07002126 static IAudioService getAudioService() {
2127 IAudioService audioService = IAudioService.Stub.asInterface(
2128 ServiceManager.checkService(Context.AUDIO_SERVICE));
2129 if (audioService == null) {
2130 Log.w(TAG, "Unable to find IAudioService interface.");
2131 }
2132 return audioService;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002133 }
2134
2135 boolean keyguardOn() {
2136 return keyguardIsShowingTq() || inKeyguardRestrictedKeyInputMode();
2137 }
2138
2139 private static final int[] WINDOW_TYPES_WHERE_HOME_DOESNT_WORK = {
2140 WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
2141 WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
2142 };
2143
2144 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002145 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002146 public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002147 final boolean keyguardOn = keyguardOn();
Jeff Brown1f245102010-11-18 20:53:46 -08002148 final int keyCode = event.getKeyCode();
2149 final int repeatCount = event.getRepeatCount();
2150 final int metaState = event.getMetaState();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002151 final int flags = event.getFlags();
Jeff Brown1f245102010-11-18 20:53:46 -08002152 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
2153 final boolean canceled = event.isCanceled();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002154
Jeff Brown40013652012-05-16 21:22:36 -07002155 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002156 Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount="
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002157 + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed
2158 + " canceled=" + canceled);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002159 }
2160
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002161 // If we think we might have a volume down & power key chord on the way
2162 // but we're not sure, then tell the dispatcher to wait a little while and
2163 // try again later before dispatching.
Christopher Tatee90585f2012-03-05 18:56:25 -08002164 if (mScreenshotChordEnabled && (flags & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002165 if (mVolumeDownKeyTriggered && !mPowerKeyTriggered) {
2166 final long now = SystemClock.uptimeMillis();
2167 final long timeoutTime = mVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS;
2168 if (now < timeoutTime) {
2169 return timeoutTime - now;
2170 }
2171 }
2172 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
2173 && mVolumeDownKeyConsumedByScreenshotChord) {
2174 if (!down) {
2175 mVolumeDownKeyConsumedByScreenshotChord = false;
2176 }
2177 return -1;
2178 }
2179 }
2180
Michael Wright6a62e552014-06-03 19:19:48 -07002181 // Cancel any pending meta actions if we see any other keys being pressed between the down
2182 // of the meta key and its corresponding up.
Michael Wright251e35d2014-08-22 15:40:27 -07002183 if (mPendingMetaAction && !KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07002184 mPendingMetaAction = false;
2185 }
2186
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002187 // First we always handle the home key here, so applications
2188 // can never break it, although if keyguard is on, we do let
2189 // it handle it, because that gives us the correct 5 second
2190 // timeout.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002191 if (keyCode == KeyEvent.KEYCODE_HOME) {
Michael Jurka7f2668c2012-03-27 07:49:52 -07002192
Jeff Brown49ed71d2010-12-06 17:13:33 -08002193 // If we have released the home key, and didn't do anything else
2194 // while it was pressed, then it is time to go home!
Michael Jurka7f2668c2012-03-27 07:49:52 -07002195 if (!down) {
Jeff Browncaca8812013-05-09 13:34:33 -07002196 cancelPreloadRecentApps();
2197
Jeff Brown49ed71d2010-12-06 17:13:33 -08002198 mHomePressed = false;
Jeff Browncaca8812013-05-09 13:34:33 -07002199 if (mHomeConsumed) {
2200 mHomeConsumed = false;
Michael Jurka7f2668c2012-03-27 07:49:52 -07002201 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002202 }
Jeff Browncaca8812013-05-09 13:34:33 -07002203
2204 if (canceled) {
2205 Log.i(TAG, "Ignoring HOME; event canceled.");
2206 return -1;
2207 }
2208
2209 // If an incoming call is ringing, HOME is totally disabled.
Santos Cordon9eb45932014-06-27 12:28:43 -07002210 // (The user is already on the InCallUI at this point,
Jeff Browncaca8812013-05-09 13:34:33 -07002211 // and his ONLY options are to answer or reject the call.)
Santos Cordon9eb45932014-06-27 12:28:43 -07002212 TelecommManager telecommManager = getTelecommService();
2213 if (telecommManager != null && telecommManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07002214 Log.i(TAG, "Ignoring HOME; there's a ringing incoming call.");
2215 return -1;
Jeff Browncaca8812013-05-09 13:34:33 -07002216 }
2217
2218 // Delay handling home if a double-tap is possible.
2219 if (mDoubleTapOnHomeBehavior != DOUBLE_TAP_HOME_NOTHING) {
2220 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); // just in case
2221 mHomeDoubleTapPending = true;
2222 mHandler.postDelayed(mHomeDoubleTapTimeoutRunnable,
2223 ViewConfiguration.getDoubleTapTimeout());
2224 return -1;
2225 }
2226
Jose Lima9546b202014-07-02 17:21:51 -07002227 // If there's a dream running then use home to escape the dream
2228 // but don't actually go home.
2229 if (mDreamManagerInternal != null && mDreamManagerInternal.isDreaming()) {
Jeff Brownf6d46682014-07-17 22:44:20 -07002230 mDreamManagerInternal.stopDream(false /*immediate*/);
Jose Lima9546b202014-07-02 17:21:51 -07002231 return -1;
2232 }
2233
Jeff Browncaca8812013-05-09 13:34:33 -07002234 // Go home!
2235 launchHomeFromHotKey();
2236 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002237 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002238
2239 // If a system window has focus, then it doesn't make sense
2240 // right now to interact with applications.
2241 WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null;
2242 if (attrs != null) {
2243 final int type = attrs.type;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002244 if (type == WindowManager.LayoutParams.TYPE_KEYGUARD_SCRIM
2245 || type == WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG
2246 || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002247 // the "app" is keyguard, so give it the key
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002248 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002249 }
2250 final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length;
2251 for (int i=0; i<typeCount; i++) {
2252 if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) {
2253 // don't do anything, but also don't pass it to the app
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002254 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002255 }
2256 }
2257 }
Jeff Browncaca8812013-05-09 13:34:33 -07002258
2259 // Remember that home is pressed and handle special actions.
2260 if (repeatCount == 0) {
2261 mHomePressed = true;
2262 if (mHomeDoubleTapPending) {
2263 mHomeDoubleTapPending = false;
2264 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable);
2265 handleDoubleTapOnHome();
2266 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI
2267 || mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
2268 preloadRecentApps();
Michael Jurka7f2668c2012-03-27 07:49:52 -07002269 }
Jeff Browncaca8812013-05-09 13:34:33 -07002270 } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) {
2271 if (!keyguardOn) {
2272 handleLongPressOnHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002273 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002274 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002275 return -1;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002276 } else if (keyCode == KeyEvent.KEYCODE_MENU) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002277 // Hijack modified menu keys for debugging features
2278 final int chordBug = KeyEvent.META_SHIFT_ON;
2279
2280 if (down && repeatCount == 0) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002281 if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002282 Intent intent = new Intent(Intent.ACTION_BUG_REPORT);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002283 mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT,
2284 null, null, null, 0, null, null);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002285 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002286 } else if (SHOW_PROCESSES_ON_ALT_MENU &&
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002287 (metaState & KeyEvent.META_ALT_ON) == KeyEvent.META_ALT_ON) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002288 Intent service = new Intent();
2289 service.setClassName(mContext, "com.android.server.LoadAverageService");
2290 ContentResolver res = mContext.getContentResolver();
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002291 boolean shown = Settings.Global.getInt(
2292 res, Settings.Global.SHOW_PROCESSES, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002293 if (!shown) {
2294 mContext.startService(service);
2295 } else {
2296 mContext.stopService(service);
2297 }
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002298 Settings.Global.putInt(
2299 res, Settings.Global.SHOW_PROCESSES, shown ? 0 : 1);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002300 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002301 }
2302 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002303 } else if (keyCode == KeyEvent.KEYCODE_SEARCH) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002304 if (down) {
2305 if (repeatCount == 0) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002306 mSearchKeyShortcutPending = true;
2307 mConsumeSearchKeyUp = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002308 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002309 } else {
2310 mSearchKeyShortcutPending = false;
2311 if (mConsumeSearchKeyUp) {
2312 mConsumeSearchKeyUp = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002313 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002314 }
2315 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002316 return 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002317 } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) {
Michael Wrightc9ebea72013-01-16 19:25:02 -08002318 if (!keyguardOn) {
Jeff Browncaca8812013-05-09 13:34:33 -07002319 if (down && repeatCount == 0) {
2320 preloadRecentApps();
2321 } else if (!down) {
2322 toggleRecentApps();
Michael Wrightc9ebea72013-01-16 19:25:02 -08002323 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002324 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002325 return -1;
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002326 } else if (keyCode == KeyEvent.KEYCODE_ASSIST) {
2327 if (down) {
2328 if (repeatCount == 0) {
2329 mAssistKeyLongPressed = false;
2330 } else if (repeatCount == 1) {
2331 mAssistKeyLongPressed = true;
2332 if (!keyguardOn) {
2333 launchAssistLongPressAction();
2334 }
2335 }
2336 } else {
2337 if (mAssistKeyLongPressed) {
2338 mAssistKeyLongPressed = false;
2339 } else {
2340 if (!keyguardOn) {
2341 launchAssistAction();
2342 }
2343 }
2344 }
2345 return -1;
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002346 } else if (keyCode == KeyEvent.KEYCODE_VOICE_ASSIST) {
2347 if (!down) {
2348 Intent voiceIntent;
Michael Wright869a67c2014-08-26 19:33:06 -07002349 if (!keyguardOn) {
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002350 voiceIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
2351 } else {
2352 voiceIntent = new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
Michael Wright869a67c2014-08-26 19:33:06 -07002353 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, true);
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002354 }
2355 mContext.startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
2356 }
Jeff Sharkey2991fa32012-12-05 18:06:43 -08002357 } else if (keyCode == KeyEvent.KEYCODE_SYSRQ) {
2358 if (down && repeatCount == 0) {
2359 mHandler.post(mScreenshotRunnable);
2360 }
2361 return -1;
Michael Wrightb854e242013-02-05 17:54:02 -08002362 } else if (keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP
2363 || keyCode == KeyEvent.KEYCODE_BRIGHTNESS_DOWN) {
2364 if (down) {
2365 int direction = keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP ? 1 : -1;
2366
2367 // Disable autobrightness if it's on
2368 int auto = Settings.System.getIntForUser(
2369 mContext.getContentResolver(),
2370 Settings.System.SCREEN_BRIGHTNESS_MODE,
2371 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2372 UserHandle.USER_CURRENT_OR_SELF);
2373 if (auto != 0) {
2374 Settings.System.putIntForUser(mContext.getContentResolver(),
2375 Settings.System.SCREEN_BRIGHTNESS_MODE,
2376 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2377 UserHandle.USER_CURRENT_OR_SELF);
2378 }
2379
2380 int min = mPowerManager.getMinimumScreenBrightnessSetting();
2381 int max = mPowerManager.getMaximumScreenBrightnessSetting();
2382 int step = (max - min + BRIGHTNESS_STEPS - 1) / BRIGHTNESS_STEPS * direction;
2383 int brightness = Settings.System.getIntForUser(mContext.getContentResolver(),
2384 Settings.System.SCREEN_BRIGHTNESS,
2385 mPowerManager.getDefaultScreenBrightnessSetting(),
2386 UserHandle.USER_CURRENT_OR_SELF);
2387 brightness += step;
2388 // Make sure we don't go beyond the limits.
2389 brightness = Math.min(max, brightness);
2390 brightness = Math.max(min, brightness);
2391
2392 Settings.System.putIntForUser(mContext.getContentResolver(),
2393 Settings.System.SCREEN_BRIGHTNESS, brightness,
2394 UserHandle.USER_CURRENT_OR_SELF);
Alan Viverette5a399492014-07-14 16:19:38 -07002395 mContext.startActivityAsUser(new Intent(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG),
2396 UserHandle.CURRENT_OR_SELF);
Michael Wrightb854e242013-02-05 17:54:02 -08002397 }
2398 return -1;
Michael Wrightce0c13a2014-07-30 10:49:21 -07002399 } else if (KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07002400 if (down) {
2401 mPendingMetaAction = true;
2402 } else if (mPendingMetaAction) {
Michael Wright6a62e552014-06-03 19:19:48 -07002403 launchAssistAction();
2404 }
2405 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002406 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002407
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002408 // Shortcuts are invoked through Search+key, so intercept those here
Jeff Browncaab4d02010-12-09 22:13:41 -08002409 // Any printing key that is chorded with Search should be consumed
2410 // even if no shortcut was invoked. This prevents text from being
2411 // inadvertently inserted when using a keyboard that has built-in macro
2412 // shortcut keys (that emit Search+x) and some of them are not registered.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002413 if (mSearchKeyShortcutPending) {
Jeff Browncaab4d02010-12-09 22:13:41 -08002414 final KeyCharacterMap kcm = event.getKeyCharacterMap();
2415 if (kcm.isPrintingKey(keyCode)) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002416 mConsumeSearchKeyUp = true;
2417 mSearchKeyShortcutPending = false;
Jeff Browncaab4d02010-12-09 22:13:41 -08002418 if (down && repeatCount == 0 && !keyguardOn) {
2419 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState);
2420 if (shortcutIntent != null) {
2421 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002422 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002423 mContext.startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002424 } catch (ActivityNotFoundException ex) {
2425 Slog.w(TAG, "Dropping shortcut key combination because "
2426 + "the activity to which it is registered was not found: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002427 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode), ex);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002428 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002429 } else {
2430 Slog.i(TAG, "Dropping unregistered shortcut key combination: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002431 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002432 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002433 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002434 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002435 }
2436 }
2437
Jeff Brown68b909d2011-12-07 16:36:01 -08002438 // Invoke shortcuts using Meta.
Jeff Brown602ab322012-05-16 13:33:47 -07002439 if (down && repeatCount == 0 && !keyguardOn
Jeff Brown68b909d2011-12-07 16:36:01 -08002440 && (metaState & KeyEvent.META_META_ON) != 0) {
2441 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brown602ab322012-05-16 13:33:47 -07002442 if (kcm.isPrintingKey(keyCode)) {
2443 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode,
2444 metaState & ~(KeyEvent.META_META_ON
2445 | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON));
2446 if (shortcutIntent != null) {
2447 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2448 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002449 mContext.startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brown602ab322012-05-16 13:33:47 -07002450 } catch (ActivityNotFoundException ex) {
2451 Slog.w(TAG, "Dropping shortcut key combination because "
2452 + "the activity to which it is registered was not found: "
2453 + "META+" + KeyEvent.keyCodeToString(keyCode), ex);
2454 }
2455 return -1;
Jeff Brown68b909d2011-12-07 16:36:01 -08002456 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002457 }
2458 }
2459
Jeff Brown6651a632011-11-28 12:59:11 -08002460 // Handle application launch keys.
Jeff Brown602ab322012-05-16 13:33:47 -07002461 if (down && repeatCount == 0 && !keyguardOn) {
Jeff Brown6651a632011-11-28 12:59:11 -08002462 String category = sApplicationLaunchKeyCategories.get(keyCode);
2463 if (category != null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -08002464 Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category);
Jeff Brown6651a632011-11-28 12:59:11 -08002465 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2466 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002467 mContext.startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brown6651a632011-11-28 12:59:11 -08002468 } catch (ActivityNotFoundException ex) {
2469 Slog.w(TAG, "Dropping application launch key because "
2470 + "the activity to which it is registered was not found: "
2471 + "keyCode=" + keyCode + ", category=" + category, ex);
2472 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002473 return -1;
Jeff Brown6651a632011-11-28 12:59:11 -08002474 }
2475 }
2476
Michael Wright61c46752014-08-21 16:57:33 -07002477 // Display task switcher for ALT-TAB.
Jeff Brown68b909d2011-12-07 16:36:01 -08002478 if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_TAB) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002479 if (mRecentAppsHeldModifiers == 0 && !keyguardOn) {
Jeff Brown68b909d2011-12-07 16:36:01 -08002480 final int shiftlessModifiers = event.getModifiers() & ~KeyEvent.META_SHIFT_MASK;
Michael Wright61c46752014-08-21 16:57:33 -07002481 if (KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_ALT_ON)) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002482 mRecentAppsHeldModifiers = shiftlessModifiers;
2483 showRecentApps(true);
Jeff Brown68b909d2011-12-07 16:36:01 -08002484 return -1;
2485 }
2486 }
Winson Chung1e8d71b2014-05-16 17:05:22 -07002487 } else if (!down && mRecentAppsHeldModifiers != 0
2488 && (metaState & mRecentAppsHeldModifiers) == 0) {
2489 mRecentAppsHeldModifiers = 0;
Winson Chungcdcd4872014-08-05 18:00:13 -07002490 hideRecentApps(true, false);
Jeff Brown68b909d2011-12-07 16:36:01 -08002491 }
2492
Jeff Browncf39bdf2012-05-18 14:41:19 -07002493 // Handle keyboard language switching.
2494 if (down && repeatCount == 0
2495 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2496 || (keyCode == KeyEvent.KEYCODE_SPACE
2497 && (metaState & KeyEvent.META_CTRL_MASK) != 0))) {
2498 int direction = (metaState & KeyEvent.META_SHIFT_MASK) != 0 ? -1 : 1;
2499 mWindowManagerFuncs.switchKeyboardLayout(event.getDeviceId(), direction);
2500 return -1;
2501 }
2502 if (mLanguageSwitchKeyPressed && !down
2503 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2504 || keyCode == KeyEvent.KEYCODE_SPACE)) {
2505 mLanguageSwitchKeyPressed = false;
2506 return -1;
2507 }
2508
Justin Kohd378ad72013-04-01 12:18:26 -07002509 if (mGlobalKeyManager.handleGlobalKey(mContext, keyCode, event)) {
2510 return -1;
2511 }
2512
Michael Wright6a62e552014-06-03 19:19:48 -07002513 // Reserve all the META modifier combos for system behavior
Michael Wrightce0c13a2014-07-30 10:49:21 -07002514 if ((metaState & KeyEvent.META_META_ON) != 0) {
Michael Wright6a62e552014-06-03 19:19:48 -07002515 return -1;
2516 }
2517
Jeff Brown68b909d2011-12-07 16:36:01 -08002518 // Let the application handle the key.
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002519 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002520 }
2521
Jeff Brown3915bb82010-11-05 15:02:16 -07002522 /** {@inheritDoc} */
2523 @Override
Jeff Brown49ed71d2010-12-06 17:13:33 -08002524 public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown54875002011-04-06 15:33:01 -07002525 // Note: This method is only called if the initial down was unhandled.
Jeff Brown40013652012-05-16 21:22:36 -07002526 if (DEBUG_INPUT) {
Jeff Brown1f245102010-11-18 20:53:46 -08002527 Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction()
2528 + ", flags=" + event.getFlags()
2529 + ", keyCode=" + event.getKeyCode()
2530 + ", scanCode=" + event.getScanCode()
2531 + ", metaState=" + event.getMetaState()
2532 + ", repeatCount=" + event.getRepeatCount()
2533 + ", policyFlags=" + policyFlags);
Jeff Brown3915bb82010-11-05 15:02:16 -07002534 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002535
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002536 KeyEvent fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002537 if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
2538 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002539 final int keyCode = event.getKeyCode();
2540 final int metaState = event.getMetaState();
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002541 final boolean initialDown = event.getAction() == KeyEvent.ACTION_DOWN
2542 && event.getRepeatCount() == 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002543
Jeff Brown54875002011-04-06 15:33:01 -07002544 // Check for fallback actions specified by the key character map.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002545 final FallbackAction fallbackAction;
2546 if (initialDown) {
2547 fallbackAction = kcm.getFallbackAction(keyCode, metaState);
2548 } else {
2549 fallbackAction = mFallbackActions.get(keyCode);
2550 }
2551
2552 if (fallbackAction != null) {
Jeff Brown40013652012-05-16 21:22:36 -07002553 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002554 Slog.d(TAG, "Fallback: keyCode=" + fallbackAction.keyCode
2555 + " metaState=" + Integer.toHexString(fallbackAction.metaState));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002556 }
2557
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002558 final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK;
2559 fallbackEvent = KeyEvent.obtain(
Jeff Brown49ed71d2010-12-06 17:13:33 -08002560 event.getDownTime(), event.getEventTime(),
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002561 event.getAction(), fallbackAction.keyCode,
2562 event.getRepeatCount(), fallbackAction.metaState,
Jeff Brown49ed71d2010-12-06 17:13:33 -08002563 event.getDeviceId(), event.getScanCode(),
2564 flags, event.getSource(), null);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002565
2566 if (!interceptFallback(win, fallbackEvent, policyFlags)) {
2567 fallbackEvent.recycle();
2568 fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002569 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002570
2571 if (initialDown) {
2572 mFallbackActions.put(keyCode, fallbackAction);
2573 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2574 mFallbackActions.remove(keyCode);
2575 fallbackAction.recycle();
2576 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002577 }
2578 }
2579
Jeff Brown40013652012-05-16 21:22:36 -07002580 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002581 if (fallbackEvent == null) {
2582 Slog.d(TAG, "No fallback.");
2583 } else {
2584 Slog.d(TAG, "Performing fallback: " + fallbackEvent);
2585 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002586 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002587 return fallbackEvent;
Jeff Brown3915bb82010-11-05 15:02:16 -07002588 }
2589
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002590 private boolean interceptFallback(WindowState win, KeyEvent fallbackEvent, int policyFlags) {
Jeff Brown037c33e2014-04-09 00:31:55 -07002591 int actions = interceptKeyBeforeQueueing(fallbackEvent, policyFlags);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002592 if ((actions & ACTION_PASS_TO_USER) != 0) {
2593 long delayMillis = interceptKeyBeforeDispatching(
2594 win, fallbackEvent, policyFlags);
2595 if (delayMillis == 0) {
2596 return true;
2597 }
2598 }
2599 return false;
Jeff Brown6f2fba42011-02-19 01:08:02 -08002600 }
2601
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002602 private void launchAssistLongPressAction() {
2603 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
2604 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
2605
2606 // launch the search activity
2607 Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS);
2608 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2609 try {
RoboErik8a2cfc32014-05-16 11:19:38 -07002610 // TODO: This only stops the factory-installed search manager.
Jim Miller45308b12012-06-18 19:23:39 -07002611 // Need to formalize an API to handle others
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002612 SearchManager searchManager = getSearchManager();
2613 if (searchManager != null) {
2614 searchManager.stopSearch();
2615 }
Michael Wright43e27f72013-04-10 14:06:48 -07002616 mContext.startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002617 } catch (ActivityNotFoundException e) {
2618 Slog.w(TAG, "No activity to handle assist long press action.", e);
2619 }
2620 }
2621
2622 private void launchAssistAction() {
2623 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
Amith Yamasanic1d07a42012-08-14 09:32:02 -07002624 Intent intent = ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE))
Dianne Hackbornf9c5e0f2013-01-23 14:39:13 -08002625 .getAssistIntent(mContext, true, UserHandle.USER_CURRENT);
Jim Miller45308b12012-06-18 19:23:39 -07002626 if (intent != null) {
2627 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
2628 | Intent.FLAG_ACTIVITY_SINGLE_TOP
2629 | Intent.FLAG_ACTIVITY_CLEAR_TOP);
2630 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002631 mContext.startActivityAsUser(intent, UserHandle.CURRENT);
Jim Miller45308b12012-06-18 19:23:39 -07002632 } catch (ActivityNotFoundException e) {
2633 Slog.w(TAG, "No activity to handle assist action.", e);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002634 }
2635 }
2636 }
2637
2638 private SearchManager getSearchManager() {
2639 if (mSearchManager == null) {
2640 mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
2641 }
2642 return mSearchManager;
2643 }
2644
Jeff Browncaca8812013-05-09 13:34:33 -07002645 private void preloadRecentApps() {
2646 mPreloadedRecentApps = true;
2647 try {
2648 IStatusBarService statusbar = getStatusBarService();
2649 if (statusbar != null) {
2650 statusbar.preloadRecentApps();
2651 }
2652 } catch (RemoteException e) {
2653 Slog.e(TAG, "RemoteException when preloading recent apps", e);
2654 // re-acquire status bar service next time it is needed.
2655 mStatusBarService = null;
2656 }
2657 }
2658
2659 private void cancelPreloadRecentApps() {
2660 if (mPreloadedRecentApps) {
2661 mPreloadedRecentApps = false;
2662 try {
2663 IStatusBarService statusbar = getStatusBarService();
2664 if (statusbar != null) {
2665 statusbar.cancelPreloadRecentApps();
2666 }
2667 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002668 Slog.e(TAG, "RemoteException when cancelling recent apps preload", e);
Jeff Browncaca8812013-05-09 13:34:33 -07002669 // re-acquire status bar service next time it is needed.
2670 mStatusBarService = null;
2671 }
2672 }
2673 }
2674
2675 private void toggleRecentApps() {
2676 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
Jeff Browncaca8812013-05-09 13:34:33 -07002677 try {
2678 IStatusBarService statusbar = getStatusBarService();
2679 if (statusbar != null) {
2680 statusbar.toggleRecentApps();
2681 }
2682 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002683 Slog.e(TAG, "RemoteException when toggling recent apps", e);
2684 // re-acquire status bar service next time it is needed.
2685 mStatusBarService = null;
2686 }
2687 }
2688
Craig Mautner84984fa2014-06-19 11:19:20 -07002689 @Override
2690 public void showRecentApps() {
2691 mHandler.removeMessages(MSG_DISPATCH_SHOW_RECENTS);
2692 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_RECENTS);
2693 }
2694
Winson Chung1e8d71b2014-05-16 17:05:22 -07002695 private void showRecentApps(boolean triggeredFromAltTab) {
2696 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
2697 try {
2698 IStatusBarService statusbar = getStatusBarService();
2699 if (statusbar != null) {
2700 statusbar.showRecentApps(triggeredFromAltTab);
2701 }
2702 } catch (RemoteException e) {
Jeff Browncaca8812013-05-09 13:34:33 -07002703 Slog.e(TAG, "RemoteException when showing recent apps", e);
2704 // re-acquire status bar service next time it is needed.
2705 mStatusBarService = null;
2706 }
2707 }
2708
Winson Chungcdcd4872014-08-05 18:00:13 -07002709 private void hideRecentApps(boolean triggeredFromAltTab, boolean triggeredFromHome) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002710 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
2711 try {
2712 IStatusBarService statusbar = getStatusBarService();
2713 if (statusbar != null) {
Winson Chungcdcd4872014-08-05 18:00:13 -07002714 statusbar.hideRecentApps(triggeredFromAltTab, triggeredFromHome);
Winson Chung1e8d71b2014-05-16 17:05:22 -07002715 }
2716 } catch (RemoteException e) {
2717 Slog.e(TAG, "RemoteException when closing recent apps", e);
2718 // re-acquire status bar service next time it is needed.
2719 mStatusBarService = null;
2720 }
2721 }
2722
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002723 /**
2724 * A home key -> launch home action was detected. Take the appropriate action
2725 * given the situation with the keyguard.
2726 */
2727 void launchHomeFromHotKey() {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01002728 if (mKeyguardDelegate != null && mKeyguardDelegate.isShowingAndNotOccluded()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002729 // don't launch home if keyguard showing
Jim Miller5ecd8112013-01-09 18:50:26 -08002730 } else if (!mHideLockScreen && mKeyguardDelegate.isInputRestricted()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002731 // when in keyguard restricted mode, must first verify unlock
2732 // before launching home
Jim Miller5ecd8112013-01-09 18:50:26 -08002733 mKeyguardDelegate.verifyUnlock(new OnKeyguardExitResult() {
Jose Lima9546b202014-07-02 17:21:51 -07002734 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002735 public void onKeyguardExitResult(boolean success) {
2736 if (success) {
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07002737 try {
2738 ActivityManagerNative.getDefault().stopAppSwitches();
2739 } catch (RemoteException e) {
2740 }
Joe Onoratof275f0c2009-11-24 16:11:13 -05002741 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07002742 startDockOrHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002743 }
2744 }
2745 });
2746 } else {
2747 // no keyguard stuff to worry about, just launch home!
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07002748 try {
2749 ActivityManagerNative.getDefault().stopAppSwitches();
2750 } catch (RemoteException e) {
2751 }
Winson Chungd543c1b2014-06-23 15:06:45 -07002752 if (mRecentsVisible) {
2753 // Hide Recents and notify it to launch Home
2754 awakenDreams();
2755 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
Winson Chungcdcd4872014-08-05 18:00:13 -07002756 hideRecentApps(false, true);
Winson Chungd543c1b2014-06-23 15:06:45 -07002757 } else {
2758 // Otherwise, just launch Home
2759 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
2760 startDockOrHome();
2761 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002762 }
2763 }
2764
John Spurlock04db1762013-05-13 12:46:41 -04002765 private final Runnable mClearHideNavigationFlag = new Runnable() {
2766 @Override
2767 public void run() {
2768 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
2769 // Clear flags.
2770 mForceClearedSystemUiFlags &=
2771 ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
2772 }
2773 mWindowManagerFuncs.reevaluateStatusBarVisibility();
Dianne Hackborne26ab702011-10-16 13:21:33 -07002774 }
2775 };
2776
2777 /**
2778 * Input handler used while nav bar is hidden. Captures any touch on the screen,
2779 * to determine when the nav bar should be shown and prevent applications from
2780 * receiving those touches.
2781 */
Jeff Brown32cbc38552011-12-01 14:01:49 -08002782 final class HideNavInputEventReceiver extends InputEventReceiver {
2783 public HideNavInputEventReceiver(InputChannel inputChannel, Looper looper) {
2784 super(inputChannel, looper);
2785 }
2786
Dianne Hackborndf89e652011-10-06 22:35:11 -07002787 @Override
Jeff Brown32cbc38552011-12-01 14:01:49 -08002788 public void onInputEvent(InputEvent event) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07002789 boolean handled = false;
2790 try {
Jeff Brown4952dfd2011-11-30 19:23:22 -08002791 if (event instanceof MotionEvent
2792 && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
2793 final MotionEvent motionEvent = (MotionEvent)event;
2794 if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07002795 // When the user taps down, we re-show the nav bar.
2796 boolean changed = false;
John Spurlock04db1762013-05-13 12:46:41 -04002797 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002798 // Any user activity always causes us to show the
2799 // navigation controls, if they had been hidden.
2800 // We also clear the low profile and only content
2801 // flags so that tapping on the screen will atomically
2802 // restore all currently hidden screen decorations.
2803 int newVal = mResettingSystemUiFlags |
2804 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
2805 View.SYSTEM_UI_FLAG_LOW_PROFILE |
2806 View.SYSTEM_UI_FLAG_FULLSCREEN;
Dianne Hackborne26ab702011-10-16 13:21:33 -07002807 if (mResettingSystemUiFlags != newVal) {
2808 mResettingSystemUiFlags = newVal;
Dianne Hackborndf89e652011-10-06 22:35:11 -07002809 changed = true;
2810 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07002811 // We don't allow the system's nav bar to be hidden
2812 // again for 1 second, to prevent applications from
2813 // spamming us and keeping it from being shown.
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002814 newVal = mForceClearedSystemUiFlags |
2815 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
Dianne Hackborne26ab702011-10-16 13:21:33 -07002816 if (mForceClearedSystemUiFlags != newVal) {
2817 mForceClearedSystemUiFlags = newVal;
2818 changed = true;
John Spurlock04db1762013-05-13 12:46:41 -04002819 mHandler.postDelayed(mClearHideNavigationFlag, 1000);
Dianne Hackborne26ab702011-10-16 13:21:33 -07002820 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07002821 }
2822 if (changed) {
2823 mWindowManagerFuncs.reevaluateStatusBarVisibility();
2824 }
2825 }
2826 }
2827 } finally {
Jeff Brown32cbc38552011-12-01 14:01:49 -08002828 finishInputEvent(event, handled);
Dianne Hackborndf89e652011-10-06 22:35:11 -07002829 }
2830 }
Jeff Brown32cbc38552011-12-01 14:01:49 -08002831 }
2832 final InputEventReceiver.Factory mHideNavInputEventReceiverFactory =
2833 new InputEventReceiver.Factory() {
2834 @Override
2835 public InputEventReceiver createInputEventReceiver(
2836 InputChannel inputChannel, Looper looper) {
2837 return new HideNavInputEventReceiver(inputChannel, looper);
2838 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07002839 };
2840
2841 @Override
2842 public int adjustSystemUiVisibilityLw(int visibility) {
John Spurlock5b9145b2013-08-20 15:13:47 -04002843 mStatusBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
2844 mNavigationBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
Winson Chungd42a6cf2014-06-03 16:24:04 -07002845 mRecentsVisible = (visibility & View.RECENT_APPS_VISIBLE) > 0;
John Spurlock27735a42013-08-14 17:57:38 -04002846
Dianne Hackborndf89e652011-10-06 22:35:11 -07002847 // Reset any bits in mForceClearingStatusBarVisibility that
2848 // are now clear.
Dianne Hackborne26ab702011-10-16 13:21:33 -07002849 mResettingSystemUiFlags &= visibility;
Dianne Hackborndf89e652011-10-06 22:35:11 -07002850 // Clear any bits in the new visibility that are currently being
2851 // force cleared, before reporting it.
Dianne Hackborne26ab702011-10-16 13:21:33 -07002852 return visibility & ~mResettingSystemUiFlags
2853 & ~mForceClearedSystemUiFlags;
Dianne Hackborndf89e652011-10-06 22:35:11 -07002854 }
2855
Craig Mautner69b08182012-09-05 13:07:13 -07002856 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002857 public void getContentInsetHintLw(WindowManager.LayoutParams attrs, Rect contentInset) {
John Spurlockc6d1c602014-01-17 15:22:06 -05002858 final int fl = PolicyControl.getWindowFlags(null, attrs);
John Spurlock1db8b682014-02-18 11:18:59 -05002859 final int sysuiVis = PolicyControl.getSystemUiVisibility(null, attrs);
2860 final int systemUiVisibility = (sysuiVis | attrs.subtreeSystemUiVisibility);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002861
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002862 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002863 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002864 int availRight, availBottom;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07002865 if (canHideNavigationBar() &&
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002866 (systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002867 availRight = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
2868 availBottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
2869 } else {
2870 availRight = mRestrictedScreenLeft + mRestrictedScreenWidth;
2871 availBottom = mRestrictedScreenTop + mRestrictedScreenHeight;
2872 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002873 if ((systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
2874 if ((fl & FLAG_FULLSCREEN) != 0) {
2875 contentInset.set(mStableFullscreenLeft, mStableFullscreenTop,
2876 availRight - mStableFullscreenRight,
2877 availBottom - mStableFullscreenBottom);
2878 } else {
2879 contentInset.set(mStableLeft, mStableTop,
2880 availRight - mStableRight, availBottom - mStableBottom);
2881 }
Dianne Hackbornc652de82013-02-15 16:32:56 -08002882 } else if ((fl & FLAG_FULLSCREEN) != 0 || (fl & FLAG_LAYOUT_IN_OVERSCAN) != 0) {
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002883 contentInset.setEmpty();
2884 } else if ((systemUiVisibility & (View.SYSTEM_UI_FLAG_FULLSCREEN
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002885 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)) == 0) {
2886 contentInset.set(mCurLeft, mCurTop,
2887 availRight - mCurRight, availBottom - mCurBottom);
2888 } else {
2889 contentInset.set(mCurLeft, mCurTop,
2890 availRight - mCurRight, availBottom - mCurBottom);
2891 }
2892 return;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002893 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002894 contentInset.setEmpty();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002895 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002896
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002897 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07002898 @Override
2899 public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight,
2900 int displayRotation) {
Dianne Hackbornc652de82013-02-15 16:32:56 -08002901 final int overscanLeft, overscanTop, overscanRight, overscanBottom;
2902 if (isDefaultDisplay) {
2903 switch (displayRotation) {
2904 case Surface.ROTATION_90:
2905 overscanLeft = mOverscanTop;
2906 overscanTop = mOverscanRight;
2907 overscanRight = mOverscanBottom;
2908 overscanBottom = mOverscanLeft;
2909 break;
2910 case Surface.ROTATION_180:
2911 overscanLeft = mOverscanRight;
2912 overscanTop = mOverscanBottom;
2913 overscanRight = mOverscanLeft;
2914 overscanBottom = mOverscanTop;
2915 break;
2916 case Surface.ROTATION_270:
2917 overscanLeft = mOverscanBottom;
2918 overscanTop = mOverscanLeft;
2919 overscanRight = mOverscanTop;
2920 overscanBottom = mOverscanRight;
2921 break;
2922 default:
2923 overscanLeft = mOverscanLeft;
2924 overscanTop = mOverscanTop;
2925 overscanRight = mOverscanRight;
2926 overscanBottom = mOverscanBottom;
2927 break;
2928 }
2929 } else {
2930 overscanLeft = 0;
2931 overscanTop = 0;
2932 overscanRight = 0;
2933 overscanBottom = 0;
2934 }
Dianne Hackborn313440842013-02-19 19:22:59 -08002935 mOverscanScreenLeft = mRestrictedOverscanScreenLeft = 0;
2936 mOverscanScreenTop = mRestrictedOverscanScreenTop = 0;
2937 mOverscanScreenWidth = mRestrictedOverscanScreenWidth = displayWidth;
2938 mOverscanScreenHeight = mRestrictedOverscanScreenHeight = displayHeight;
Dianne Hackbornc652de82013-02-15 16:32:56 -08002939 mSystemLeft = 0;
2940 mSystemTop = 0;
2941 mSystemRight = displayWidth;
2942 mSystemBottom = displayHeight;
2943 mUnrestrictedScreenLeft = overscanLeft;
2944 mUnrestrictedScreenTop = overscanTop;
2945 mUnrestrictedScreenWidth = displayWidth - overscanLeft - overscanRight;
2946 mUnrestrictedScreenHeight = displayHeight - overscanTop - overscanBottom;
2947 mRestrictedScreenLeft = mUnrestrictedScreenLeft;
2948 mRestrictedScreenTop = mUnrestrictedScreenTop;
John Spurlockad3e6cb2013-04-30 08:47:43 -04002949 mRestrictedScreenWidth = mSystemGestures.screenWidth = mUnrestrictedScreenWidth;
2950 mRestrictedScreenHeight = mSystemGestures.screenHeight = mUnrestrictedScreenHeight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002951 mDockLeft = mContentLeft = mVoiceContentLeft = mStableLeft = mStableFullscreenLeft
Dianne Hackbornc652de82013-02-15 16:32:56 -08002952 = mCurLeft = mUnrestrictedScreenLeft;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002953 mDockTop = mContentTop = mVoiceContentTop = mStableTop = mStableFullscreenTop
Dianne Hackbornc652de82013-02-15 16:32:56 -08002954 = mCurTop = mUnrestrictedScreenTop;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002955 mDockRight = mContentRight = mVoiceContentRight = mStableRight = mStableFullscreenRight
Dianne Hackbornc652de82013-02-15 16:32:56 -08002956 = mCurRight = displayWidth - overscanRight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002957 mDockBottom = mContentBottom = mVoiceContentBottom = mStableBottom = mStableFullscreenBottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08002958 = mCurBottom = displayHeight - overscanBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002959 mDockLayer = 0x10000000;
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002960 mStatusBarLayer = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002961
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002962 // start with the current dock rect, which will be (0,0,displayWidth,displayHeight)
2963 final Rect pf = mTmpParentFrame;
2964 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002965 final Rect of = mTmpOverscanFrame;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002966 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04002967 final Rect dcf = mTmpDecorFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002968 pf.left = df.left = of.left = vf.left = mDockLeft;
2969 pf.top = df.top = of.top = vf.top = mDockTop;
2970 pf.right = df.right = of.right = vf.right = mDockRight;
2971 pf.bottom = df.bottom = of.bottom = vf.bottom = mDockBottom;
John Spurlock46646232013-09-30 22:32:42 -04002972 dcf.setEmpty(); // Decor frame N/A for system bars.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002973
Craig Mautner69b08182012-09-05 13:07:13 -07002974 if (isDefaultDisplay) {
2975 // For purposes of putting out fake window up to steal focus, we will
2976 // drive nav being hidden only by whether it is requested.
John Spurlocke1f366f2013-08-05 12:22:40 -04002977 final int sysui = mLastSystemUiFlags;
2978 boolean navVisible = (sysui & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0;
Adrian Roosea562512014-05-05 13:33:03 +02002979 boolean navTranslucent = (sysui
2980 & (View.NAVIGATION_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04002981 boolean immersive = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
2982 boolean immersiveSticky = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
2983 boolean navAllowedHidden = immersive || immersiveSticky;
2984 navTranslucent &= !immersiveSticky; // transient trumps translucent
Adrian Roos4fb3ee32014-08-22 19:29:09 +02002985 boolean isKeyguardShowing = isStatusBarKeyguard() && !mHideLockScreen;
2986 if (!isKeyguardShowing) {
2987 navTranslucent &= areTranslucentBarsAllowed();
2988 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07002989
Craig Mautner69b08182012-09-05 13:07:13 -07002990 // When the navigation bar isn't visible, we put up a fake
2991 // input window to catch all touch events. This way we can
2992 // detect when the user presses anywhere to bring back the nav
2993 // bar and ensure the application doesn't see the event.
John Spurlockf1a36642013-10-12 17:50:42 -04002994 if (navVisible || navAllowedHidden) {
Craig Mautner69b08182012-09-05 13:07:13 -07002995 if (mHideNavFakeWindow != null) {
2996 mHideNavFakeWindow.dismiss();
2997 mHideNavFakeWindow = null;
2998 }
2999 } else if (mHideNavFakeWindow == null) {
3000 mHideNavFakeWindow = mWindowManagerFuncs.addFakeWindow(
3001 mHandler.getLooper(), mHideNavInputEventReceiverFactory,
Adam Lesinski95c42972013-10-02 10:13:27 -07003002 "hidden nav", WindowManager.LayoutParams.TYPE_HIDDEN_NAV_CONSUMER, 0,
Craig Mautner69b08182012-09-05 13:07:13 -07003003 0, false, false, true);
Dianne Hackborne26ab702011-10-16 13:21:33 -07003004 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003005
Craig Mautner69b08182012-09-05 13:07:13 -07003006 // For purposes of positioning and showing the nav bar, if we have
3007 // decided that it can't be hidden (because of the screen aspect ratio),
3008 // then take that into account.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003009 navVisible |= !canHideNavigationBar();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003010
John Spurlockad3e6cb2013-04-30 08:47:43 -04003011 boolean updateSysUiVisibility = false;
Craig Mautner69b08182012-09-05 13:07:13 -07003012 if (mNavigationBar != null) {
John Spurlock27735a42013-08-14 17:57:38 -04003013 boolean transientNavBarShowing = mNavigationBarController.isTransientShowing();
Craig Mautner69b08182012-09-05 13:07:13 -07003014 // Force the navigation bar to its appropriate place and
3015 // size. We need to do this directly, instead of relying on
3016 // it to bubble up from the nav bar, because this needs to
3017 // change atomically with screen rotations.
3018 mNavigationBarOnBottom = (!mNavigationBarCanMove || displayWidth < displayHeight);
3019 if (mNavigationBarOnBottom) {
3020 // It's a system nav bar or a portrait screen; nav bar goes on bottom.
Dianne Hackbornc652de82013-02-15 16:32:56 -08003021 int top = displayHeight - overscanBottom
3022 - mNavigationBarHeightForRotation[displayRotation];
3023 mTmpNavigationFrame.set(0, top, displayWidth, displayHeight - overscanBottom);
Craig Mautner69b08182012-09-05 13:07:13 -07003024 mStableBottom = mStableFullscreenBottom = mTmpNavigationFrame.top;
John Spurlockf95b89a2013-10-10 22:10:42 -04003025 if (transientNavBarShowing) {
John Spurlock27735a42013-08-14 17:57:38 -04003026 mNavigationBarController.setBarShowingLw(true);
John Spurlockad3e6cb2013-04-30 08:47:43 -04003027 } else if (navVisible) {
John Spurlock27735a42013-08-14 17:57:38 -04003028 mNavigationBarController.setBarShowingLw(true);
Craig Mautner69b08182012-09-05 13:07:13 -07003029 mDockBottom = mTmpNavigationFrame.top;
Dianne Hackborn313440842013-02-19 19:22:59 -08003030 mRestrictedScreenHeight = mDockBottom - mRestrictedScreenTop;
3031 mRestrictedOverscanScreenHeight = mDockBottom - mRestrictedOverscanScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07003032 } else {
3033 // We currently want to hide the navigation UI.
John Spurlock27735a42013-08-14 17:57:38 -04003034 mNavigationBarController.setBarShowingLw(false);
Craig Mautner69b08182012-09-05 13:07:13 -07003035 }
John Spurlockc6d1c602014-01-17 15:22:06 -05003036 if (navVisible && !navTranslucent && !navAllowedHidden
3037 && !mNavigationBar.isAnimatingLw()
John Spurlockbd957402013-10-03 11:38:39 -04003038 && !mNavigationBarController.wasRecentlyTranslucent()) {
John Spurlocke1f366f2013-08-05 12:22:40 -04003039 // If the opaque nav bar is currently requested to be visible,
Craig Mautner69b08182012-09-05 13:07:13 -07003040 // and not in the process of animating on or off, then
3041 // we can tell the app that it is covered by it.
3042 mSystemBottom = mTmpNavigationFrame.top;
3043 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003044 } else {
Craig Mautner69b08182012-09-05 13:07:13 -07003045 // Landscape screen; nav bar goes to the right.
Dianne Hackbornc652de82013-02-15 16:32:56 -08003046 int left = displayWidth - overscanRight
3047 - mNavigationBarWidthForRotation[displayRotation];
3048 mTmpNavigationFrame.set(left, 0, displayWidth - overscanRight, displayHeight);
Craig Mautner69b08182012-09-05 13:07:13 -07003049 mStableRight = mStableFullscreenRight = mTmpNavigationFrame.left;
John Spurlockf95b89a2013-10-10 22:10:42 -04003050 if (transientNavBarShowing) {
John Spurlock27735a42013-08-14 17:57:38 -04003051 mNavigationBarController.setBarShowingLw(true);
John Spurlockad3e6cb2013-04-30 08:47:43 -04003052 } else if (navVisible) {
John Spurlock27735a42013-08-14 17:57:38 -04003053 mNavigationBarController.setBarShowingLw(true);
Craig Mautner69b08182012-09-05 13:07:13 -07003054 mDockRight = mTmpNavigationFrame.left;
Dianne Hackborn313440842013-02-19 19:22:59 -08003055 mRestrictedScreenWidth = mDockRight - mRestrictedScreenLeft;
3056 mRestrictedOverscanScreenWidth = mDockRight - mRestrictedOverscanScreenLeft;
Craig Mautner69b08182012-09-05 13:07:13 -07003057 } else {
3058 // We currently want to hide the navigation UI.
John Spurlock27735a42013-08-14 17:57:38 -04003059 mNavigationBarController.setBarShowingLw(false);
Craig Mautner69b08182012-09-05 13:07:13 -07003060 }
John Spurlockbd957402013-10-03 11:38:39 -04003061 if (navVisible && !navTranslucent && !mNavigationBar.isAnimatingLw()
3062 && !mNavigationBarController.wasRecentlyTranslucent()) {
Craig Mautner69b08182012-09-05 13:07:13 -07003063 // If the nav bar is currently requested to be visible,
3064 // and not in the process of animating on or off, then
3065 // we can tell the app that it is covered by it.
3066 mSystemRight = mTmpNavigationFrame.left;
3067 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003068 }
Craig Mautner69b08182012-09-05 13:07:13 -07003069 // Make sure the content and current rectangles are updated to
3070 // account for the restrictions from the navigation bar.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003071 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3072 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3073 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3074 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
Craig Mautner69b08182012-09-05 13:07:13 -07003075 mStatusBarLayer = mNavigationBar.getSurfaceLayer();
3076 // And compute the final frame.
3077 mNavigationBar.computeFrameLw(mTmpNavigationFrame, mTmpNavigationFrame,
Adrian Roosfa104232014-06-20 16:10:14 -07003078 mTmpNavigationFrame, mTmpNavigationFrame, mTmpNavigationFrame, dcf,
3079 mTmpNavigationFrame);
Craig Mautnereda67292013-04-28 13:50:14 -07003080 if (DEBUG_LAYOUT) Slog.i(TAG, "mNavigationBar frame: " + mTmpNavigationFrame);
John Spurlock27735a42013-08-14 17:57:38 -04003081 if (mNavigationBarController.checkHiddenLw()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04003082 updateSysUiVisibility = true;
3083 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003084 }
Craig Mautnereda67292013-04-28 13:50:14 -07003085 if (DEBUG_LAYOUT) Slog.i(TAG, String.format("mDock rect: (%d,%d - %d,%d)",
Craig Mautner69b08182012-09-05 13:07:13 -07003086 mDockLeft, mDockTop, mDockRight, mDockBottom));
3087
3088 // decide where the status bar goes ahead of time
3089 if (mStatusBar != null) {
3090 // apply any navigation bar insets
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003091 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3092 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3093 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
3094 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight
3095 + mUnrestrictedScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07003096 vf.left = mStableLeft;
3097 vf.top = mStableTop;
3098 vf.right = mStableRight;
3099 vf.bottom = mStableBottom;
3100
3101 mStatusBarLayer = mStatusBar.getSurfaceLayer();
3102
3103 // Let the status bar determine its size.
Adrian Roosfa104232014-06-20 16:10:14 -07003104 mStatusBar.computeFrameLw(pf, df, vf, vf, vf, dcf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07003105
3106 // For layout, the status bar is always at the top with our fixed height.
3107 mStableTop = mUnrestrictedScreenTop + mStatusBarHeight;
3108
John Spurlocke1f366f2013-08-05 12:22:40 -04003109 boolean statusBarTransient = (sysui & View.STATUS_BAR_TRANSIENT) != 0;
Adrian Roosea562512014-05-05 13:33:03 +02003110 boolean statusBarTranslucent = (sysui
3111 & (View.STATUS_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0;
Adrian Roos4fb3ee32014-08-22 19:29:09 +02003112 if (!isKeyguardShowing) {
3113 statusBarTranslucent &= areTranslucentBarsAllowed();
3114 }
John Spurlock32beb2c2013-03-11 10:16:47 -04003115
Craig Mautner69b08182012-09-05 13:07:13 -07003116 // If the status bar is hidden, we don't want to cause
3117 // windows behind it to scroll.
John Spurlockeda1f692013-09-16 11:38:44 -04003118 if (mStatusBar.isVisibleLw() && !statusBarTransient) {
Craig Mautner69b08182012-09-05 13:07:13 -07003119 // Status bar may go away, so the screen area it occupies
3120 // is available to apps but just covering them when the
3121 // status bar is visible.
3122 mDockTop = mUnrestrictedScreenTop + mStatusBarHeight;
3123
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003124 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3125 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3126 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3127 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
Craig Mautner69b08182012-09-05 13:07:13 -07003128
Craig Mautnereda67292013-04-28 13:50:14 -07003129 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar: " +
Craig Mautner69b08182012-09-05 13:07:13 -07003130 String.format(
3131 "dock=[%d,%d][%d,%d] content=[%d,%d][%d,%d] cur=[%d,%d][%d,%d]",
3132 mDockLeft, mDockTop, mDockRight, mDockBottom,
3133 mContentLeft, mContentTop, mContentRight, mContentBottom,
3134 mCurLeft, mCurTop, mCurRight, mCurBottom));
3135 }
John Spurlocke1f366f2013-08-05 12:22:40 -04003136 if (mStatusBar.isVisibleLw() && !mStatusBar.isAnimatingLw()
John Spurlockbd957402013-10-03 11:38:39 -04003137 && !statusBarTransient && !statusBarTranslucent
3138 && !mStatusBarController.wasRecentlyTranslucent()) {
John Spurlocke1f366f2013-08-05 12:22:40 -04003139 // If the opaque status bar is currently requested to be visible,
Craig Mautner69b08182012-09-05 13:07:13 -07003140 // and not in the process of animating on or off, then
3141 // we can tell the app that it is covered by it.
3142 mSystemTop = mUnrestrictedScreenTop + mStatusBarHeight;
3143 }
John Spurlock27735a42013-08-14 17:57:38 -04003144 if (mStatusBarController.checkHiddenLw()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04003145 updateSysUiVisibility = true;
John Spurlock32beb2c2013-03-11 10:16:47 -04003146 }
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003147 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04003148 if (updateSysUiVisibility) {
3149 updateSystemUiVisibilityLw();
3150 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003151 }
3152 }
3153
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003154 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07003155 @Override
John Spurlock46646232013-09-30 22:32:42 -04003156 public int getSystemDecorLayerLw() {
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003157 if (mStatusBar != null) return mStatusBar.getSurfaceLayer();
3158 if (mNavigationBar != null) return mNavigationBar.getSurfaceLayer();
3159 return 0;
3160 }
3161
Craig Mautner967212c2013-04-13 21:10:58 -07003162 @Override
3163 public void getContentRectLw(Rect r) {
3164 r.set(mContentLeft, mContentTop, mContentRight, mContentBottom);
3165 }
3166
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003167 void setAttachedWindowFrames(WindowState win, int fl, int adjust, WindowState attached,
3168 boolean insetDecors, Rect pf, Rect df, Rect of, Rect cf, Rect vf) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003169 if (win.getSurfaceLayer() > mDockLayer && attached.getSurfaceLayer() < mDockLayer) {
3170 // Here's a special case: if this attached window is a panel that is
3171 // above the dock window, and the window it is attached to is below
3172 // the dock window, then the frames we computed for the window it is
3173 // attached to can not be used because the dock is effectively part
3174 // of the underlying window and the attached window is floating on top
3175 // of the whole thing. So, we ignore the attached window and explicitly
3176 // compute the frames that would be appropriate without the dock.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003177 df.left = of.left = cf.left = vf.left = mDockLeft;
3178 df.top = of.top = cf.top = vf.top = mDockTop;
3179 df.right = of.right = cf.right = vf.right = mDockRight;
3180 df.bottom = of.bottom = cf.bottom = vf.bottom = mDockBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003181 } else {
3182 // The effective display frame of the attached window depends on
3183 // whether it is taking care of insetting its content. If not,
3184 // we need to use the parent's content frame so that the entire
3185 // window is positioned within that content. Otherwise we can use
3186 // the display frame and let the attached window take care of
3187 // positioning its content appropriately.
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003188 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003189 cf.set(attached.getOverscanFrameLw());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003190 } else {
3191 // If the window is resizing, then we want to base the content
3192 // frame on our attached content frame to resize... however,
3193 // things can be tricky if the attached window is NOT in resize
3194 // mode, in which case its content frame will be larger.
3195 // Ungh. So to deal with that, make sure the content frame
3196 // we end up using is not covering the IM dock.
3197 cf.set(attached.getContentFrameLw());
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003198 if (attached.isVoiceInteraction()) {
3199 if (cf.left < mVoiceContentLeft) cf.left = mVoiceContentLeft;
3200 if (cf.top < mVoiceContentTop) cf.top = mVoiceContentTop;
3201 if (cf.right > mVoiceContentRight) cf.right = mVoiceContentRight;
3202 if (cf.bottom > mVoiceContentBottom) cf.bottom = mVoiceContentBottom;
3203 } else if (attached.getSurfaceLayer() < mDockLayer) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003204 if (cf.left < mContentLeft) cf.left = mContentLeft;
3205 if (cf.top < mContentTop) cf.top = mContentTop;
3206 if (cf.right > mContentRight) cf.right = mContentRight;
3207 if (cf.bottom > mContentBottom) cf.bottom = mContentBottom;
3208 }
3209 }
3210 df.set(insetDecors ? attached.getDisplayFrameLw() : cf);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003211 of.set(insetDecors ? attached.getOverscanFrameLw() : cf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003212 vf.set(attached.getVisibleFrameLw());
3213 }
3214 // The LAYOUT_IN_SCREEN flag is used to determine whether the attached
3215 // window should be positioned relative to its parent or the entire
3216 // screen.
3217 pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0
3218 ? attached.getFrameLw() : df);
3219 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003220
3221 private void applyStableConstraints(int sysui, int fl, Rect r) {
3222 if ((sysui & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
3223 // If app is requesting a stable layout, don't let the
3224 // content insets go below the stable values.
3225 if ((fl & FLAG_FULLSCREEN) != 0) {
3226 if (r.left < mStableFullscreenLeft) r.left = mStableFullscreenLeft;
3227 if (r.top < mStableFullscreenTop) r.top = mStableFullscreenTop;
3228 if (r.right > mStableFullscreenRight) r.right = mStableFullscreenRight;
3229 if (r.bottom > mStableFullscreenBottom) r.bottom = mStableFullscreenBottom;
3230 } else {
3231 if (r.left < mStableLeft) r.left = mStableLeft;
3232 if (r.top < mStableTop) r.top = mStableTop;
3233 if (r.right > mStableRight) r.right = mStableRight;
3234 if (r.bottom > mStableBottom) r.bottom = mStableBottom;
3235 }
3236 }
3237 }
3238
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003239 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07003240 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003241 public void layoutWindowLw(WindowState win, WindowState attached) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003242 // we've already done the status bar
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003243 final WindowManager.LayoutParams attrs = win.getAttrs();
3244 if ((win == mStatusBar && (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) == 0) ||
3245 win == mNavigationBar) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003246 return;
3247 }
Craig Mautner69b08182012-09-05 13:07:13 -07003248 final boolean isDefaultDisplay = win.isDefaultDisplay();
3249 final boolean needsToOffsetInputMethodTarget = isDefaultDisplay &&
satok1bc0a492012-04-25 22:47:12 +09003250 (win == mLastInputMethodTargetWindow && mLastInputMethodWindow != null);
3251 if (needsToOffsetInputMethodTarget) {
Craig Mautnereda67292013-04-28 13:50:14 -07003252 if (DEBUG_LAYOUT) Slog.i(TAG, "Offset ime target window by the last ime window state");
satok1bc0a492012-04-25 22:47:12 +09003253 offsetInputMethodWindowLw(mLastInputMethodWindow);
3254 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003255
John Spurlockc6d1c602014-01-17 15:22:06 -05003256 final int fl = PolicyControl.getWindowFlags(win, attrs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003257 final int sim = attrs.softInputMode;
John Spurlock1db8b682014-02-18 11:18:59 -05003258 final int sysUiFl = PolicyControl.getSystemUiVisibility(win, null);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003259
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003260 final Rect pf = mTmpParentFrame;
3261 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003262 final Rect of = mTmpOverscanFrame;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003263 final Rect cf = mTmpContentFrame;
3264 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04003265 final Rect dcf = mTmpDecorFrame;
Adrian Roosfa104232014-06-20 16:10:14 -07003266 final Rect sf = mTmpStableFrame;
John Spurlock46646232013-09-30 22:32:42 -04003267 dcf.setEmpty();
Craig Mautner69b08182012-09-05 13:07:13 -07003268
3269 final boolean hasNavBar = (isDefaultDisplay && mHasNavigationBar
Daniel Sandler36412a72011-08-04 09:35:13 -04003270 && mNavigationBar != null && mNavigationBar.isVisibleLw());
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003271
Craig Mautnerf683b562012-10-02 11:10:57 -07003272 final int adjust = sim & SOFT_INPUT_MASK_ADJUST;
3273
Adrian Roosfa104232014-06-20 16:10:14 -07003274 if (isDefaultDisplay) {
3275 sf.set(mStableLeft, mStableTop, mStableRight, mStableBottom);
3276 } else {
3277 sf.set(mOverscanLeft, mOverscanTop, mOverscanRight, mOverscanBottom);
3278 }
3279
Craig Mautner69b08182012-09-05 13:07:13 -07003280 if (!isDefaultDisplay) {
3281 if (attached != null) {
3282 // If this window is attached to another, our display
3283 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003284 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07003285 } else {
3286 // Give the window full screen.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003287 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3288 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3289 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08003290 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003291 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003292 = mOverscanScreenTop + mOverscanScreenHeight;
Craig Mautner69b08182012-09-05 13:07:13 -07003293 }
3294 } else if (attrs.type == TYPE_INPUT_METHOD) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003295 pf.left = df.left = of.left = cf.left = vf.left = mDockLeft;
3296 pf.top = df.top = of.top = cf.top = vf.top = mDockTop;
3297 pf.right = df.right = of.right = cf.right = vf.right = mDockRight;
John Spurlockc68d5772013-10-08 11:47:58 -04003298 // IM dock windows layout below the nav bar...
John Spurlock57beb3b2013-10-10 10:27:44 -04003299 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlockc68d5772013-10-08 11:47:58 -04003300 // ...with content insets above the nav bar
3301 cf.bottom = vf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003302 // IM dock windows always go to the bottom of the screen.
3303 attrs.gravity = Gravity.BOTTOM;
3304 mDockLayer = win.getSurfaceLayer();
Jorim Jaggie0700182014-08-21 01:12:37 +02003305 } else if (win == mStatusBar && (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
3306 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3307 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3308 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
3309 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight + mUnrestrictedScreenTop;
3310 cf.left = vf.left = mStableLeft;
3311 cf.top = vf.top = mStableTop;
3312 cf.right = vf.right = mStableRight;
3313 vf.bottom = mStableBottom;
3314 cf.bottom = mContentBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003315 } else {
John Spurlock46646232013-09-30 22:32:42 -04003316
3317 // Default policy decor for the default display
3318 dcf.left = mSystemLeft;
3319 dcf.top = mSystemTop;
3320 dcf.right = mSystemRight;
3321 dcf.bottom = mSystemBottom;
John Spurlockbd957402013-10-03 11:38:39 -04003322 final boolean inheritTranslucentDecor = (attrs.privateFlags
3323 & WindowManager.LayoutParams.PRIVATE_FLAG_INHERIT_TRANSLUCENT_DECOR) != 0;
John Spurlock65567d42013-10-08 10:08:32 -04003324 final boolean isAppWindow =
3325 attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW &&
3326 attrs.type <= WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
3327 final boolean topAtRest =
3328 win == mTopFullscreenOpaqueWindowState && !win.isAnimatingLw();
3329 if (isAppWindow && !inheritTranslucentDecor && !topAtRest) {
John Spurlockbd957402013-10-03 11:38:39 -04003330 if ((sysUiFl & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0
3331 && (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0
Adrian Roosea562512014-05-05 13:33:03 +02003332 && (fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) == 0
3333 && (fl & WindowManager.LayoutParams.
3334 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04003335 // Ensure policy decor includes status bar
3336 dcf.top = mStableTop;
3337 }
John Spurlockbd957402013-10-03 11:38:39 -04003338 if ((fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) == 0
Adrian Roosea562512014-05-05 13:33:03 +02003339 && (sysUiFl & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0
3340 && (fl & WindowManager.LayoutParams.
3341 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04003342 // Ensure policy decor includes navigation bar
3343 dcf.bottom = mStableBottom;
3344 dcf.right = mStableRight;
3345 }
3346 }
3347
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003348 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
3349 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
RoboErik8a2cfc32014-05-16 11:19:38 -07003350 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003351 + "): IN_SCREEN, INSET_DECOR");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003352 // This is the case for a normal activity window: we want it
3353 // to cover all of the screen space, and it can take care of
3354 // moving its contents to account for screen decorations that
3355 // intrude into that space.
3356 if (attached != null) {
3357 // If this window is attached to another, our display
3358 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003359 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003360 } else {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003361 if (attrs.type == TYPE_STATUS_BAR_PANEL
3362 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Joe Onorato29fc2c92010-11-24 10:26:50 -08003363 // Status bar panels are the only windows who can go on top of
3364 // the status bar. They are protected by the STATUS_BAR_SERVICE
3365 // permission, so they have the same privileges as the status
3366 // bar itself.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003367 //
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003368 // However, they should still dodge the navigation bar if it exists.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003369
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003370 pf.left = df.left = of.left = hasNavBar
3371 ? mDockLeft : mUnrestrictedScreenLeft;
3372 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3373 pf.right = df.right = of.right = hasNavBar
3374 ? mRestrictedScreenLeft+mRestrictedScreenWidth
3375 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3376 pf.bottom = df.bottom = of.bottom = hasNavBar
3377 ? mRestrictedScreenTop+mRestrictedScreenHeight
3378 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003379
Craig Mautnereda67292013-04-28 13:50:14 -07003380 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003381 "Laying out status bar window: (%d,%d - %d,%d)",
3382 pf.left, pf.top, pf.right, pf.bottom));
John Spurlock46646232013-09-30 22:32:42 -04003383 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08003384 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3385 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3386 // Asking to layout into the overscan region, so give it that pure
3387 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003388 pf.left = df.left = of.left = mOverscanScreenLeft;
3389 pf.top = df.top = of.top = mOverscanScreenTop;
3390 pf.right = df.right = of.right = mOverscanScreenLeft + mOverscanScreenWidth;
3391 pf.bottom = df.bottom = of.bottom = mOverscanScreenTop
3392 + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003393 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003394 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003395 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3396 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003397 // Asking for layout as if the nav bar is hidden, lets the
Dianne Hackbornc652de82013-02-15 16:32:56 -08003398 // application extend into the unrestricted overscan screen area. We
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003399 // only do this for application windows to ensure no window that
3400 // can be above the nav bar can do this.
Dianne Hackborn313440842013-02-19 19:22:59 -08003401 pf.left = df.left = mOverscanScreenLeft;
3402 pf.top = df.top = mOverscanScreenTop;
3403 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
3404 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003405 // We need to tell the app about where the frame inside the overscan
3406 // is, so it can inset its content by that amount -- it didn't ask
3407 // to actually extend itself into the overscan region.
3408 of.left = mUnrestrictedScreenLeft;
3409 of.top = mUnrestrictedScreenTop;
3410 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3411 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003412 } else {
Dianne Hackborn313440842013-02-19 19:22:59 -08003413 pf.left = df.left = mRestrictedOverscanScreenLeft;
3414 pf.top = df.top = mRestrictedOverscanScreenTop;
3415 pf.right = df.right = mRestrictedOverscanScreenLeft
3416 + mRestrictedOverscanScreenWidth;
3417 pf.bottom = df.bottom = mRestrictedOverscanScreenTop
3418 + mRestrictedOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003419 // We need to tell the app about where the frame inside the overscan
3420 // is, so it can inset its content by that amount -- it didn't ask
3421 // to actually extend itself into the overscan region.
3422 of.left = mUnrestrictedScreenLeft;
3423 of.top = mUnrestrictedScreenTop;
3424 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3425 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003426 }
Craig Mautner69b08182012-09-05 13:07:13 -07003427
John Spurlock46646232013-09-30 22:32:42 -04003428 if ((fl & FLAG_FULLSCREEN) == 0) {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003429 if (win.isVoiceInteraction()) {
3430 cf.left = mVoiceContentLeft;
3431 cf.top = mVoiceContentTop;
3432 cf.right = mVoiceContentRight;
3433 cf.bottom = mVoiceContentBottom;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003434 } else {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003435 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
3436 cf.left = mDockLeft;
3437 cf.top = mDockTop;
3438 cf.right = mDockRight;
3439 cf.bottom = mDockBottom;
3440 } else {
3441 cf.left = mContentLeft;
3442 cf.top = mContentTop;
3443 cf.right = mContentRight;
3444 cf.bottom = mContentBottom;
3445 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003446 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003447 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003448 // Full screen windows are always given a layout that is as if the
3449 // status bar and other transient decors are gone. This is to avoid
3450 // bad states when moving from a window that is not hding the
3451 // status bar to one that is.
3452 cf.left = mRestrictedScreenLeft;
3453 cf.top = mRestrictedScreenTop;
3454 cf.right = mRestrictedScreenLeft + mRestrictedScreenWidth;
3455 cf.bottom = mRestrictedScreenTop + mRestrictedScreenHeight;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003456 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003457 applyStableConstraints(sysUiFl, fl, cf);
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003458 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3459 vf.left = mCurLeft;
3460 vf.top = mCurTop;
3461 vf.right = mCurRight;
3462 vf.bottom = mCurBottom;
3463 } else {
3464 vf.set(cf);
3465 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003466 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003467 } else if ((fl & FLAG_LAYOUT_IN_SCREEN) != 0 || (sysUiFl
3468 & (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
3469 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)) != 0) {
Craig Mautnereda67292013-04-28 13:50:14 -07003470 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3471 "): IN_SCREEN");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003472 // A window that has requested to fill the entire screen just
3473 // gets everything, period.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003474 if (attrs.type == TYPE_STATUS_BAR_PANEL
3475 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003476 pf.left = df.left = of.left = cf.left = hasNavBar
3477 ? mDockLeft : mUnrestrictedScreenLeft;
3478 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
3479 pf.right = df.right = of.right = cf.right = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003480 ? mRestrictedScreenLeft+mRestrictedScreenWidth
Dianne Hackbornc652de82013-02-15 16:32:56 -08003481 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003482 pf.bottom = df.bottom = of.bottom = cf.bottom = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003483 ? mRestrictedScreenTop+mRestrictedScreenHeight
Dianne Hackbornc652de82013-02-15 16:32:56 -08003484 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07003485 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler36412a72011-08-04 09:35:13 -04003486 "Laying out IN_SCREEN status bar window: (%d,%d - %d,%d)",
3487 pf.left, pf.top, pf.right, pf.bottom));
Jim Millere898ac52012-04-06 17:10:57 -07003488 } else if (attrs.type == TYPE_NAVIGATION_BAR
3489 || attrs.type == TYPE_NAVIGATION_BAR_PANEL) {
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003490 // The navigation bar has Real Ultimate Power.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003491 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3492 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3493 pf.right = df.right = of.right = mUnrestrictedScreenLeft
3494 + mUnrestrictedScreenWidth;
3495 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop
3496 + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07003497 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003498 "Laying out navigation bar window: (%d,%d - %d,%d)",
3499 pf.left, pf.top, pf.right, pf.bottom));
Dianne Hackborn01011c32012-02-21 13:54:21 -08003500 } else if ((attrs.type == TYPE_SECURE_SYSTEM_OVERLAY
3501 || attrs.type == TYPE_BOOT_PROGRESS)
Jeff Brownbfcb60a2011-09-08 18:51:14 -07003502 && ((fl & FLAG_FULLSCREEN) != 0)) {
3503 // Fullscreen secure system overlays get what they ask for.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003504 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3505 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3506 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
3507 + mOverscanScreenWidth;
3508 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
3509 + mOverscanScreenHeight;
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07003510 } else if (attrs.type == TYPE_BOOT_PROGRESS
3511 || attrs.type == TYPE_UNIVERSE_BACKGROUND) {
Dianne Hackborn01011c32012-02-21 13:54:21 -08003512 // Boot progress screen always covers entire display.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003513 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3514 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3515 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
3516 + mOverscanScreenWidth;
3517 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
3518 + mOverscanScreenHeight;
John Spurlockef4adae2013-08-26 17:58:58 -04003519 } else if (attrs.type == TYPE_WALLPAPER) {
3520 // The wallpaper also has Real Ultimate Power.
3521 pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft;
3522 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003523 pf.right = df.right = of.right = cf.right
John Spurlockef4adae2013-08-26 17:58:58 -04003524 = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003525 pf.bottom = df.bottom = of.bottom = cf.bottom
John Spurlockef4adae2013-08-26 17:58:58 -04003526 = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlock46646232013-09-30 22:32:42 -04003527 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08003528 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3529 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3530 // Asking to layout into the overscan region, so give it that pure
3531 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003532 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3533 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3534 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08003535 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003536 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003537 = mOverscanScreenTop + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003538 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003539 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Craig Mautnerbeac1062014-06-03 14:38:57 -07003540 && (attrs.type == TYPE_STATUS_BAR
3541 || attrs.type == TYPE_TOAST
John Spurlock34e13d92013-08-10 06:52:28 -04003542 || (attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3543 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW))) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003544 // Asking for layout as if the nav bar is hidden, lets the
3545 // application extend into the unrestricted screen area. We
John Spurlock34e13d92013-08-10 06:52:28 -04003546 // only do this for application windows (or toasts) to ensure no window that
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003547 // can be above the nav bar can do this.
3548 // XXX This assumes that an app asking for this will also
3549 // ask for layout in only content. We can't currently figure out
3550 // what the screen would be if only laying out to hide the nav bar.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003551 pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft;
3552 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
3553 pf.right = df.right = of.right = cf.right = mUnrestrictedScreenLeft
3554 + mUnrestrictedScreenWidth;
3555 pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop
3556 + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003557 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003558 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
3559 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
3560 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
3561 + mRestrictedScreenWidth;
3562 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
3563 + mRestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003564 }
Craig Mautner69b08182012-09-05 13:07:13 -07003565
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003566 applyStableConstraints(sysUiFl, fl, cf);
Craig Mautner69b08182012-09-05 13:07:13 -07003567
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003568 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3569 vf.left = mCurLeft;
3570 vf.top = mCurTop;
3571 vf.right = mCurRight;
3572 vf.bottom = mCurBottom;
3573 } else {
3574 vf.set(cf);
3575 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003576 } else if (attached != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07003577 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3578 "): attached to " + attached);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003579 // A child window should be placed inside of the same visible
3580 // frame that its parent had.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003581 setAttachedWindowFrames(win, fl, adjust, attached, false, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003582 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07003583 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3584 "): normal window");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003585 // Otherwise, a normal window must be placed inside the content
3586 // of all screen decorations.
Dianne Hackborna239c842011-06-01 12:28:20 -07003587 if (attrs.type == TYPE_STATUS_BAR_PANEL) {
3588 // Status bar panels are the only windows who can go on top of
3589 // the status bar. They are protected by the STATUS_BAR_SERVICE
3590 // permission, so they have the same privileges as the status
3591 // bar itself.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003592 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
3593 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
3594 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
3595 + mRestrictedScreenWidth;
3596 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
3597 + mRestrictedScreenHeight;
John Spurlock414c1f02013-12-04 13:47:36 -05003598 } else if (attrs.type == TYPE_TOAST || attrs.type == TYPE_SYSTEM_ALERT
3599 || attrs.type == TYPE_VOLUME_OVERLAY) {
3600 // These dialogs are stable to interim decor changes.
John Spurlockbd957402013-10-03 11:38:39 -04003601 pf.left = df.left = of.left = cf.left = mStableLeft;
3602 pf.top = df.top = of.top = cf.top = mStableTop;
3603 pf.right = df.right = of.right = cf.right = mStableRight;
3604 pf.bottom = df.bottom = of.bottom = cf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003605 } else {
Dianne Hackborna239c842011-06-01 12:28:20 -07003606 pf.left = mContentLeft;
3607 pf.top = mContentTop;
3608 pf.right = mContentRight;
3609 pf.bottom = mContentBottom;
Dianne Hackborn20d94742014-05-29 18:35:45 -07003610 if (win.isVoiceInteraction()) {
3611 df.left = of.left = cf.left = mVoiceContentLeft;
3612 df.top = of.top = cf.top = mVoiceContentTop;
3613 df.right = of.right = cf.right = mVoiceContentRight;
3614 df.bottom = of.bottom = cf.bottom = mVoiceContentBottom;
3615 } else if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003616 df.left = of.left = cf.left = mDockLeft;
3617 df.top = of.top = cf.top = mDockTop;
3618 df.right = of.right = cf.right = mDockRight;
3619 df.bottom = of.bottom = cf.bottom = mDockBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07003620 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003621 df.left = of.left = cf.left = mContentLeft;
3622 df.top = of.top = cf.top = mContentTop;
3623 df.right = of.right = cf.right = mContentRight;
3624 df.bottom = of.bottom = cf.bottom = mContentBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07003625 }
3626 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3627 vf.left = mCurLeft;
3628 vf.top = mCurTop;
3629 vf.right = mCurRight;
3630 vf.bottom = mCurBottom;
3631 } else {
3632 vf.set(cf);
3633 }
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003634 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003635 }
3636 }
Craig Mautner69b08182012-09-05 13:07:13 -07003637
Craig Mautnerb816bed2013-07-23 10:26:17 -07003638 // TYPE_SYSTEM_ERROR is above the NavigationBar so it can't be allowed to extend over it.
3639 if ((fl & FLAG_LAYOUT_NO_LIMITS) != 0 && attrs.type != TYPE_SYSTEM_ERROR) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003640 df.left = df.top = of.left = of.top = cf.left = cf.top = vf.left = vf.top = -10000;
3641 df.right = df.bottom = of.right = of.bottom = cf.right = cf.bottom
3642 = vf.right = vf.bottom = 10000;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003643 }
3644
Craig Mautnereda67292013-04-28 13:50:14 -07003645 if (DEBUG_LAYOUT) Slog.v(TAG, "Compute frame " + attrs.getTitle()
The Android Open Source Project11267662009-03-18 17:39:47 -07003646 + ": sim=#" + Integer.toHexString(sim)
RoboErik8a2cfc32014-05-16 11:19:38 -07003647 + " attach=" + attached + " type=" + attrs.type
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003648 + String.format(" flags=0x%08x", fl)
The Android Open Source Project11267662009-03-18 17:39:47 -07003649 + " pf=" + pf.toShortString() + " df=" + df.toShortString()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003650 + " of=" + of.toShortString()
John Spurlock46646232013-09-30 22:32:42 -04003651 + " cf=" + cf.toShortString() + " vf=" + vf.toShortString()
Adrian Roosfa104232014-06-20 16:10:14 -07003652 + " dcf=" + dcf.toShortString()
3653 + " sf=" + sf.toShortString());
Craig Mautner69b08182012-09-05 13:07:13 -07003654
Adrian Roosfa104232014-06-20 16:10:14 -07003655 win.computeFrameLw(pf, df, of, cf, vf, dcf, sf);
Craig Mautner69b08182012-09-05 13:07:13 -07003656
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003657 // Dock windows carve out the bottom of the screen, so normal windows
3658 // can't appear underneath them.
Craig Mautner8bd206b2012-10-03 10:32:02 -07003659 if (attrs.type == TYPE_INPUT_METHOD && win.isVisibleOrBehindKeyguardLw()
3660 && !win.getGivenInsetsPendingLw()) {
satok1bc0a492012-04-25 22:47:12 +09003661 setLastInputMethodWindowLw(null, null);
3662 offsetInputMethodWindowLw(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003663 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003664 if (attrs.type == TYPE_VOICE_INTERACTION && win.isVisibleOrBehindKeyguardLw()
3665 && !win.getGivenInsetsPendingLw()) {
3666 offsetVoiceInputWindowLw(win);
3667 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003668 }
3669
satok1bc0a492012-04-25 22:47:12 +09003670 private void offsetInputMethodWindowLw(WindowState win) {
3671 int top = win.getContentFrameLw().top;
3672 top += win.getGivenContentInsetsLw().top;
3673 if (mContentBottom > top) {
3674 mContentBottom = top;
3675 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003676 if (mVoiceContentBottom > top) {
3677 mVoiceContentBottom = top;
3678 }
satok1bc0a492012-04-25 22:47:12 +09003679 top = win.getVisibleFrameLw().top;
3680 top += win.getGivenVisibleInsetsLw().top;
3681 if (mCurBottom > top) {
3682 mCurBottom = top;
3683 }
Craig Mautnereda67292013-04-28 13:50:14 -07003684 if (DEBUG_LAYOUT) Slog.v(TAG, "Input method: mDockBottom="
satok1bc0a492012-04-25 22:47:12 +09003685 + mDockBottom + " mContentBottom="
3686 + mContentBottom + " mCurBottom=" + mCurBottom);
3687 }
3688
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003689 private void offsetVoiceInputWindowLw(WindowState win) {
3690 final int gravity = win.getAttrs().gravity;
3691 switch (gravity&((Gravity.AXIS_PULL_BEFORE|Gravity.AXIS_PULL_AFTER)
3692 << Gravity.AXIS_X_SHIFT)) {
3693 case Gravity.AXIS_PULL_BEFORE<<Gravity.AXIS_X_SHIFT: {
3694 int right = win.getContentFrameLw().right - win.getGivenContentInsetsLw().right;
3695 if (mVoiceContentLeft < right) {
3696 mVoiceContentLeft = right;
3697 }
3698 } break;
3699 case Gravity.AXIS_PULL_AFTER<<Gravity.AXIS_X_SHIFT: {
3700 int left = win.getContentFrameLw().left - win.getGivenContentInsetsLw().left;
3701 if (mVoiceContentRight < left) {
3702 mVoiceContentRight = left;
3703 }
3704 } break;
3705 }
3706 switch (gravity&((Gravity.AXIS_PULL_BEFORE|Gravity.AXIS_PULL_AFTER)
3707 << Gravity.AXIS_Y_SHIFT)) {
3708 case Gravity.AXIS_PULL_BEFORE<<Gravity.AXIS_Y_SHIFT: {
3709 int bottom = win.getContentFrameLw().bottom - win.getGivenContentInsetsLw().bottom;
3710 if (mVoiceContentTop < bottom) {
3711 mVoiceContentTop = bottom;
3712 }
3713 } break;
3714 case Gravity.AXIS_PULL_AFTER<<Gravity.AXIS_Y_SHIFT: {
3715 int top = win.getContentFrameLw().top - win.getGivenContentInsetsLw().top;
3716 if (mVoiceContentBottom < top) {
3717 mVoiceContentBottom = top;
3718 }
3719 } break;
3720 }
3721 }
3722
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003723 /** {@inheritDoc} */
Craig Mautner61ac6bb2012-02-02 17:29:33 -08003724 @Override
3725 public void finishLayoutLw() {
3726 return;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003727 }
3728
3729 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003730 @Override
Craig Mautner39834192012-09-02 07:47:24 -07003731 public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) {
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003732 mTopFullscreenOpaqueWindowState = null;
Craig Mautner2bc789b2014-03-19 19:48:38 -07003733 mAppsToBeHidden.clear();
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003734 mForceStatusBar = false;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003735 mForceStatusBarFromKeyguard = false;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08003736 mForcingShowNavBar = false;
3737 mForcingShowNavBarLayer = -1;
RoboErik8a2cfc32014-05-16 11:19:38 -07003738
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003739 mHideLockScreen = false;
3740 mAllowLockscreenWhenOn = false;
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003741 mDismissKeyguard = DISMISS_KEYGUARD_NONE;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003742 mShowingLockscreen = false;
3743 mShowingDream = false;
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003744 mWinShowWhenLocked = null;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003745 }
3746
3747 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003748 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003749 public void applyPostLayoutPolicyLw(WindowState win, WindowManager.LayoutParams attrs) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07003750 if (DEBUG_LAYOUT) Slog.i(TAG, "Win " + win + ": isVisibleOrBehindKeyguardLw="
3751 + win.isVisibleOrBehindKeyguardLw());
John Spurlockc6d1c602014-01-17 15:22:06 -05003752 final int fl = PolicyControl.getWindowFlags(win, attrs);
John Spurlock414c1f02013-12-04 13:47:36 -05003753 if (mTopFullscreenOpaqueWindowState == null
3754 && win.isVisibleLw() && attrs.type == TYPE_INPUT_METHOD) {
3755 mForcingShowNavBar = true;
3756 mForcingShowNavBarLayer = win.getSurfaceLayer();
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08003757 }
Jorim Jaggiafd4a552014-04-08 15:13:05 +02003758 if (attrs.type == TYPE_STATUS_BAR && (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Jorim Jaggiafd4a552014-04-08 15:13:05 +02003759 mForceStatusBarFromKeyguard = true;
3760 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003761 if (mTopFullscreenOpaqueWindowState == null &&
Dianne Hackborn01b02a72012-01-12 14:05:03 -08003762 win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()) {
John Spurlockc6d1c602014-01-17 15:22:06 -05003763 if ((fl & FLAG_FORCE_NOT_FULLSCREEN) != 0) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003764 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003765 mForceStatusBarFromKeyguard = true;
3766 } else {
3767 mForceStatusBar = true;
3768 }
3769 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003770 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003771 mShowingLockscreen = true;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07003772 }
Craig Mautnerab55e522014-03-03 13:26:03 -08003773 boolean appWindow = attrs.type >= FIRST_APPLICATION_WINDOW
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003774 && attrs.type <= LAST_APPLICATION_WINDOW;
3775 if (attrs.type == TYPE_DREAM) {
Jeff Brownc8018eb2012-10-29 21:33:27 -07003776 // If the lockscreen was showing when the dream started then wait
3777 // for the dream to draw before hiding the lockscreen.
3778 if (!mDreamingLockscreen
3779 || (win.isVisibleLw() && win.hasDrawnLw())) {
3780 mShowingDream = true;
Craig Mautnerab55e522014-03-03 13:26:03 -08003781 appWindow = true;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003782 }
3783 }
Craig Mautnerab55e522014-03-03 13:26:03 -08003784
Craig Mautner00156ec2014-03-06 22:29:02 -08003785 final boolean showWhenLocked = (fl & FLAG_SHOW_WHEN_LOCKED) != 0;
Craig Mautner74ee9382014-04-01 15:20:16 -07003786 final boolean dismissKeyguard = (fl & FLAG_DISMISS_KEYGUARD) != 0;
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003787 final boolean secureKeyguard = isKeyguardSecure();
Craig Mautnerab55e522014-03-03 13:26:03 -08003788 if (appWindow) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003789 if (showWhenLocked || (dismissKeyguard && !secureKeyguard)) {
3790 // Remove any previous windows with the same appToken.
Craig Mautner2bc789b2014-03-19 19:48:38 -07003791 mAppsToBeHidden.remove(win.getAppToken());
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003792 if (mAppsToBeHidden.isEmpty() && showWhenLocked &&
3793 isKeyguardSecureIncludingHidden()) {
3794 mWinShowWhenLocked = win;
3795 mHideLockScreen = true;
3796 mForceStatusBarFromKeyguard = false;
3797 }
Craig Mautner2bc789b2014-03-19 19:48:38 -07003798 } else {
3799 mAppsToBeHidden.add(win.getAppToken());
3800 }
Craig Mautnerab55e522014-03-03 13:26:03 -08003801 if (attrs.x == 0 && attrs.y == 0
3802 && attrs.width == WindowManager.LayoutParams.MATCH_PARENT
3803 && attrs.height == WindowManager.LayoutParams.MATCH_PARENT) {
3804 if (DEBUG_LAYOUT) Slog.v(TAG, "Fullscreen window: " + win);
3805 mTopFullscreenOpaqueWindowState = win;
Craig Mautner2bc789b2014-03-19 19:48:38 -07003806 if (mAppsToBeHidden.isEmpty()) {
Craig Mautnerda09ae32014-03-03 13:26:03 -08003807 if (showWhenLocked) {
3808 if (DEBUG_LAYOUT) Slog.v(TAG,
3809 "Setting mHideLockScreen to true by win " + win);
3810 mHideLockScreen = true;
3811 mForceStatusBarFromKeyguard = false;
3812 }
Craig Mautner4bdab6b2014-04-01 12:05:11 -07003813 if (dismissKeyguard && mDismissKeyguard == DISMISS_KEYGUARD_NONE) {
Craig Mautnerda09ae32014-03-03 13:26:03 -08003814 if (DEBUG_LAYOUT) Slog.v(TAG,
3815 "Setting mDismissKeyguard true by win " + win);
3816 mDismissKeyguard = mWinDismissingKeyguard == win ?
3817 DISMISS_KEYGUARD_CONTINUE : DISMISS_KEYGUARD_START;
3818 mWinDismissingKeyguard = win;
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003819 mForceStatusBarFromKeyguard = mShowingLockscreen && secureKeyguard;
Craig Mautnerda09ae32014-03-03 13:26:03 -08003820 }
Craig Mautnerab55e522014-03-03 13:26:03 -08003821 }
Craig Mautner00156ec2014-03-06 22:29:02 -08003822 if ((fl & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) {
Craig Mautnerab55e522014-03-03 13:26:03 -08003823 mAllowLockscreenWhenOn = true;
3824 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003825 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003826
3827 if (mWinShowWhenLocked != null &&
3828 mWinShowWhenLocked.getAppToken() != win.getAppToken()) {
3829 win.hideLw(false);
3830 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003831 }
3832 }
3833 }
3834
3835 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003836 @Override
Craig Mautner39834192012-09-02 07:47:24 -07003837 public int finishPostLayoutPolicyLw() {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003838 if (mWinShowWhenLocked != null &&
3839 mWinShowWhenLocked != mTopFullscreenOpaqueWindowState) {
3840 // A dialog is dismissing the keyguard. Put the wallpaper behind it and hide the
3841 // fullscreen window.
3842 // TODO: Make sure FLAG_SHOW_WALLPAPER is restored when dialog is dismissed. Or not.
3843 mWinShowWhenLocked.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
3844 mTopFullscreenOpaqueWindowState.hideLw(false);
3845 mTopFullscreenOpaqueWindowState = mWinShowWhenLocked;
3846 }
3847
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003848 int changes = 0;
Joe Onorato93056472010-09-10 10:30:46 -04003849 boolean topIsFullscreen = false;
Daniel Sandlere02d8082010-10-08 15:13:22 -04003850
3851 final WindowManager.LayoutParams lp = (mTopFullscreenOpaqueWindowState != null)
3852 ? mTopFullscreenOpaqueWindowState.getAttrs()
3853 : null;
3854
Jeff Brownc8018eb2012-10-29 21:33:27 -07003855 // If we are not currently showing a dream then remember the current
3856 // lockscreen state. We will use this to determine whether the dream
3857 // started while the lockscreen was showing and remember this state
3858 // while the dream is showing.
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003859 if (!mShowingDream) {
3860 mDreamingLockscreen = mShowingLockscreen;
3861 }
3862
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003863 if (mStatusBar != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07003864 if (DEBUG_LAYOUT) Slog.i(TAG, "force=" + mForceStatusBar
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003865 + " forcefkg=" + mForceStatusBarFromKeyguard
Dianne Hackbornd70bc2f2009-10-06 23:25:51 -07003866 + " top=" + mTopFullscreenOpaqueWindowState);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003867 if (mForceStatusBar || mForceStatusBarFromKeyguard) {
Craig Mautnereda67292013-04-28 13:50:14 -07003868 if (DEBUG_LAYOUT) Slog.v(TAG, "Showing status bar: forced");
John Spurlock27735a42013-08-14 17:57:38 -04003869 if (mStatusBarController.setBarShowingLw(true)) {
3870 changes |= FINISH_LAYOUT_REDO_LAYOUT;
3871 }
Craig Mautner81defc72013-10-29 11:10:42 -07003872 // Maintain fullscreen layout until incoming animation is complete.
3873 topIsFullscreen = mTopIsFullscreen && mStatusBar.isAnimatingLw();
John Spurlockf92b6162013-11-11 15:01:16 -05003874 // Transient status bar on the lockscreen is not allowed
3875 if (mForceStatusBarFromKeyguard && mStatusBarController.isTransientShowing()) {
3876 mStatusBarController.updateVisibilityLw(false /*transientAllowed*/,
3877 mLastSystemUiFlags, mLastSystemUiFlags);
3878 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003879 } else if (mTopFullscreenOpaqueWindowState != null) {
John Spurlockc6d1c602014-01-17 15:22:06 -05003880 final int fl = PolicyControl.getWindowFlags(null, lp);
Joe Onorato93056472010-09-10 10:30:46 -04003881 if (localLOGV) {
Craig Mautnereda67292013-04-28 13:50:14 -07003882 Slog.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw()
Joe Onorato93056472010-09-10 10:30:46 -04003883 + " shown frame: " + mTopFullscreenOpaqueWindowState.getShownFrameLw());
Craig Mautnereda67292013-04-28 13:50:14 -07003884 Slog.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs()
John Spurlockc6d1c602014-01-17 15:22:06 -05003885 + " lp.flags=0x" + Integer.toHexString(fl));
Joe Onorato93056472010-09-10 10:30:46 -04003886 }
John Spurlockc6d1c602014-01-17 15:22:06 -05003887 topIsFullscreen = (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003888 || (mLastSystemUiFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
Joe Onorato93056472010-09-10 10:30:46 -04003889 // The subtle difference between the window for mTopFullscreenOpaqueWindowState
3890 // and mTopIsFullscreen is that that mTopIsFullscreen is set only if the window
3891 // has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the
3892 // case though.
John Spurlock27735a42013-08-14 17:57:38 -04003893 if (mStatusBarController.isTransientShowing()) {
3894 if (mStatusBarController.setBarShowingLw(true)) {
John Spurlock32beb2c2013-03-11 10:16:47 -04003895 changes |= FINISH_LAYOUT_REDO_LAYOUT;
3896 }
3897 } else if (topIsFullscreen) {
Craig Mautnereda67292013-04-28 13:50:14 -07003898 if (DEBUG_LAYOUT) Slog.v(TAG, "** HIDING status bar");
John Spurlock27735a42013-08-14 17:57:38 -04003899 if (mStatusBarController.setBarShowingLw(false)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003900 changes |= FINISH_LAYOUT_REDO_LAYOUT;
Craig Mautnereda67292013-04-28 13:50:14 -07003901 } else {
Craig Mautnerc5a6e442013-06-05 17:22:35 -07003902 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar already hiding");
Daniel Sandler40427442010-07-16 11:44:52 -04003903 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003904 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07003905 if (DEBUG_LAYOUT) Slog.v(TAG, "** SHOWING status bar: top is not fullscreen");
John Spurlock27735a42013-08-14 17:57:38 -04003906 if (mStatusBarController.setBarShowingLw(true)) {
3907 changes |= FINISH_LAYOUT_REDO_LAYOUT;
3908 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003909 }
3910 }
3911 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04003912
Craig Mautner81defc72013-10-29 11:10:42 -07003913 if (mTopIsFullscreen != topIsFullscreen) {
3914 if (!topIsFullscreen) {
3915 // Force another layout when status bar becomes fully shown.
3916 changes |= FINISH_LAYOUT_REDO_LAYOUT;
3917 }
3918 mTopIsFullscreen = topIsFullscreen;
3919 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04003920
Craig Mautner39834192012-09-02 07:47:24 -07003921 // Hide the key guard if a visible window explicitly specifies that it wants to be
3922 // displayed when the screen is locked.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01003923 if (mKeyguardDelegate != null && mStatusBar != null) {
3924 if (localLOGV) Slog.v(TAG, "finishPostLayoutPolicyLw: mHideKeyguard="
3925 + mHideLockScreen);
3926 if (mDismissKeyguard != DISMISS_KEYGUARD_NONE && !isKeyguardSecure()) {
3927 mKeyguardHidden = true;
3928 if (processKeyguardSetHiddenResultLw(mKeyguardDelegate.setOccluded(true))) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003929 changes |= FINISH_LAYOUT_REDO_LAYOUT
3930 | FINISH_LAYOUT_REDO_CONFIG
3931 | FINISH_LAYOUT_REDO_WALLPAPER;
3932 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01003933 if (mKeyguardDelegate.isShowing()) {
3934 mHandler.post(new Runnable() {
3935 @Override
3936 public void run() {
3937 mKeyguardDelegate.keyguardDone(false, false);
3938 }
3939 });
3940 }
3941 } else if (mHideLockScreen) {
3942 mKeyguardHidden = true;
3943 if (processKeyguardSetHiddenResultLw(mKeyguardDelegate.setOccluded(true))) {
3944 changes |= FINISH_LAYOUT_REDO_LAYOUT
3945 | FINISH_LAYOUT_REDO_CONFIG
3946 | FINISH_LAYOUT_REDO_WALLPAPER;
3947 }
3948 } else if (mDismissKeyguard != DISMISS_KEYGUARD_NONE) {
3949 // This is the case of keyguard isSecure() and not mHideLockScreen.
3950 if (mDismissKeyguard == DISMISS_KEYGUARD_START) {
3951 // Only launch the next keyguard unlock window once per window.
3952 mKeyguardHidden = false;
3953 if (processKeyguardSetHiddenResultLw(mKeyguardDelegate.setOccluded(false))) {
3954 changes |= FINISH_LAYOUT_REDO_LAYOUT
3955 | FINISH_LAYOUT_REDO_CONFIG
3956 | FINISH_LAYOUT_REDO_WALLPAPER;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003957 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01003958 mHandler.post(new Runnable() {
3959 @Override
3960 public void run() {
3961 mKeyguardDelegate.dismiss();
3962 }
3963 });
3964 }
3965 } else {
3966 mWinDismissingKeyguard = null;
3967 mKeyguardHidden = false;
3968 if (processKeyguardSetHiddenResultLw(mKeyguardDelegate.setOccluded(false))) {
3969 changes |= FINISH_LAYOUT_REDO_LAYOUT
3970 | FINISH_LAYOUT_REDO_CONFIG
3971 | FINISH_LAYOUT_REDO_WALLPAPER;
3972 }
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -07003973 }
3974 }
Joe Onorato664644d2011-01-23 17:53:23 -08003975
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003976 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003977 // If the navigation bar has been hidden or shown, we need to do another
3978 // layout pass to update that window.
3979 changes |= FINISH_LAYOUT_REDO_LAYOUT;
3980 }
Joe Onorato664644d2011-01-23 17:53:23 -08003981
Mike Lockwood28569302010-01-28 11:54:40 -05003982 // update since mAllowLockscreenWhenOn might have changed
3983 updateLockScreenTimeout();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003984 return changes;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003985 }
3986
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003987 /**
Jorim Jaggi5cf17872014-03-26 18:31:48 +01003988 * Processes the result code of {@link IKeyguardService#setOccluded}. This is needed because we
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003989 * immediately need to put the wallpaper directly behind the Keyguard when a window with flag
3990 * {@link android.view.WindowManager.LayoutParams#FLAG_SHOW_WHEN_LOCKED} gets dismissed. If we
3991 * would wait for Keyguard to change the flags, that would be running asynchronously and thus be
3992 * too late so the user might see the window behind.
3993 *
Jorim Jaggi5cf17872014-03-26 18:31:48 +01003994 * @param setHiddenResult The result code from {@link IKeyguardService#setOccluded}.
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003995 * @return Whether the flags have changed and we have to redo the layout.
3996 */
3997 private boolean processKeyguardSetHiddenResultLw(int setHiddenResult) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01003998 if (setHiddenResult
3999 == IKeyguardServiceConstants.KEYGUARD_SERVICE_SET_OCCLUDED_RESULT_SET_FLAGS) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004000 mStatusBar.getAttrs().privateFlags |= PRIVATE_FLAG_KEYGUARD;
4001 mStatusBar.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
4002 return true;
4003 } else if (setHiddenResult
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004004 == IKeyguardServiceConstants.KEYGUARD_SERVICE_SET_OCCLUDED_RESULT_UNSET_FLAGS) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004005 mStatusBar.getAttrs().privateFlags &= ~PRIVATE_FLAG_KEYGUARD;
4006 mStatusBar.getAttrs().flags &= ~FLAG_SHOW_WALLPAPER;
4007 return true;
4008 } else {
4009 return false;
4010 }
4011 }
4012
4013 private boolean isStatusBarKeyguard() {
4014 return mStatusBar != null
4015 && (mStatusBar.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
4016 }
4017
Jose Lima9546b202014-07-02 17:21:51 -07004018 @Override
Dianne Hackborn08743722009-12-21 12:16:51 -08004019 public boolean allowAppAnimationsLw() {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004020 if (isStatusBarKeyguard() || mShowingDream) {
Craig Mautner28816302013-10-10 20:31:00 -07004021 // If keyguard or dreams is currently visible, no reason to animate behind it.
Dianne Hackborn08743722009-12-21 12:16:51 -08004022 return false;
4023 }
Dianne Hackborn08743722009-12-21 12:16:51 -08004024 return true;
4025 }
4026
Jose Lima9546b202014-07-02 17:21:51 -07004027 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07004028 public int focusChangedLw(WindowState lastFocus, WindowState newFocus) {
Joe Onorato664644d2011-01-23 17:53:23 -08004029 mFocusedWindow = newFocus;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004030 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004031 // If the navigation bar has been hidden or shown, we need to do another
4032 // layout pass to update that window.
4033 return FINISH_LAYOUT_REDO_LAYOUT;
4034 }
4035 return 0;
Joe Onorato664644d2011-01-23 17:53:23 -08004036 }
4037
Dianne Hackborn0ecadf72009-03-31 18:00:37 -07004038 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07004039 @Override
Jeff Brown46b9ac02010-04-22 18:58:52 -07004040 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
4041 // lid changed state
Jeff Brownc458ce92012-04-30 14:58:40 -07004042 final int newLidState = lidOpen ? LID_OPEN : LID_CLOSED;
4043 if (newLidState == mLidState) {
4044 return;
4045 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004046
Jeff Brownc458ce92012-04-30 14:58:40 -07004047 mLidState = newLidState;
4048 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07004049 updateRotation(true);
Jeff Brownc458ce92012-04-30 14:58:40 -07004050
4051 if (lidOpen) {
Jim Millere51cf7ae2013-06-25 18:31:56 -07004052 mPowerManager.wakeUp(SystemClock.uptimeMillis());
Jeff Brownc458ce92012-04-30 14:58:40 -07004053 } else if (!mLidControlsSleep) {
Jeff Brown96307042012-07-27 15:51:34 -07004054 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
Jeff Brown46b9ac02010-04-22 18:58:52 -07004055 }
4056 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004057
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004058 void setHdmiPlugged(boolean plugged) {
4059 if (mHdmiPlugged != plugged) {
4060 mHdmiPlugged = plugged;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004061 updateRotation(true, true);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004062 Intent intent = new Intent(ACTION_HDMI_PLUGGED);
Joe Onoratodc100302011-01-11 17:07:41 -08004063 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004064 intent.putExtra(EXTRA_HDMI_PLUGGED_STATE, plugged);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07004065 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004066 }
4067 }
4068
Joe Onoratoea495d42011-04-06 11:41:11 -07004069 void initializeHdmiState() {
Joe Onorato7ba631f2011-05-04 15:28:00 -07004070 boolean plugged = false;
Joe Onoratoea495d42011-04-06 11:41:11 -07004071 // watch for HDMI plug messages if the hdmi switch exists
4072 if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) {
4073 mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi");
4074
Joe Onoratoea495d42011-04-06 11:41:11 -07004075 final String filename = "/sys/class/switch/hdmi/state";
4076 FileReader reader = null;
4077 try {
4078 reader = new FileReader(filename);
4079 char[] buf = new char[15];
4080 int n = reader.read(buf);
4081 if (n > 1) {
4082 plugged = 0 != Integer.parseInt(new String(buf, 0, n-1));
4083 }
4084 } catch (IOException ex) {
4085 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
4086 } catch (NumberFormatException ex) {
4087 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
4088 } finally {
4089 if (reader != null) {
4090 try {
4091 reader.close();
4092 } catch (IOException ex) {
4093 }
Joe Onoratodc100302011-01-11 17:07:41 -08004094 }
4095 }
4096 }
Joe Onorato7ba631f2011-05-04 15:28:00 -07004097 // This dance forces the code in setHdmiPlugged to run.
4098 // Always do this so the sticky intent is stuck (to false) if there is no hdmi.
4099 mHdmiPlugged = !plugged;
4100 setHdmiPlugged(!mHdmiPlugged);
Joe Onoratodc100302011-01-11 17:07:41 -08004101 }
4102
Dianne Hackbornc0e3f242011-08-19 14:19:10 -07004103 final Object mScreenshotLock = new Object();
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004104 ServiceConnection mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004105
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004106 final Runnable mScreenshotTimeout = new Runnable() {
4107 @Override public void run() {
4108 synchronized (mScreenshotLock) {
4109 if (mScreenshotConnection != null) {
4110 mContext.unbindService(mScreenshotConnection);
4111 mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004112 }
Winson Chung9112ec32011-06-27 13:15:32 -07004113 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004114 }
4115 };
4116
4117 // Assume this is called from the Handler thread.
4118 private void takeScreenshot() {
4119 synchronized (mScreenshotLock) {
4120 if (mScreenshotConnection != null) {
4121 return;
4122 }
4123 ComponentName cn = new ComponentName("com.android.systemui",
4124 "com.android.systemui.screenshot.TakeScreenshotService");
4125 Intent intent = new Intent();
4126 intent.setComponent(cn);
4127 ServiceConnection conn = new ServiceConnection() {
4128 @Override
4129 public void onServiceConnected(ComponentName name, IBinder service) {
4130 synchronized (mScreenshotLock) {
4131 if (mScreenshotConnection != this) {
4132 return;
4133 }
4134 Messenger messenger = new Messenger(service);
4135 Message msg = Message.obtain(null, 1);
4136 final ServiceConnection myConn = this;
4137 Handler h = new Handler(mHandler.getLooper()) {
4138 @Override
4139 public void handleMessage(Message msg) {
4140 synchronized (mScreenshotLock) {
4141 if (mScreenshotConnection == myConn) {
4142 mContext.unbindService(mScreenshotConnection);
4143 mScreenshotConnection = null;
4144 mHandler.removeCallbacks(mScreenshotTimeout);
4145 }
4146 }
4147 }
4148 };
4149 msg.replyTo = new Messenger(h);
Winson Chunga63bb842011-10-17 10:26:28 -07004150 msg.arg1 = msg.arg2 = 0;
4151 if (mStatusBar != null && mStatusBar.isVisibleLw())
4152 msg.arg1 = 1;
4153 if (mNavigationBar != null && mNavigationBar.isVisibleLw())
4154 msg.arg2 = 1;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004155 try {
4156 messenger.send(msg);
4157 } catch (RemoteException e) {
4158 }
4159 }
4160 }
4161 @Override
4162 public void onServiceDisconnected(ComponentName name) {}
4163 };
Amith Yamasani27b89e62013-01-16 12:30:11 -08004164 if (mContext.bindServiceAsUser(
4165 intent, conn, Context.BIND_AUTO_CREATE, UserHandle.CURRENT)) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004166 mScreenshotConnection = conn;
4167 mHandler.postDelayed(mScreenshotTimeout, 10000);
4168 }
4169 }
Winson Chung9112ec32011-06-27 13:15:32 -07004170 }
4171
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004172 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004173 @Override
Jeff Brown037c33e2014-04-09 00:31:55 -07004174 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) {
Jeff Brown96307042012-07-27 15:51:34 -07004175 if (!mSystemBooted) {
4176 // If we have not yet booted, don't let key events do anything.
4177 return 0;
4178 }
4179
Jeff Brown037c33e2014-04-09 00:31:55 -07004180 final boolean interactive = (policyFlags & FLAG_INTERACTIVE) != 0;
Jeff Brown1f245102010-11-18 20:53:46 -08004181 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
4182 final boolean canceled = event.isCanceled();
4183 final int keyCode = event.getKeyCode();
Jeff Browne20c9e02010-10-11 14:20:19 -07004184
Jeff Brown3122e442010-10-11 23:32:49 -07004185 final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0;
Jeff Brown3122e442010-10-11 23:32:49 -07004186
Mike Lockwoodc72b15f2009-11-28 20:58:22 -05004187 // If screen is off then we treat the case where the keyguard is open but hidden
4188 // the same as if it were open and in front.
4189 // This will prevent any keys other than the power button from waking the screen
4190 // when the keyguard is hidden by another activity.
Jim Miller5ecd8112013-01-09 18:50:26 -08004191 final boolean keyguardActive = (mKeyguardDelegate == null ? false :
Jeff Brown037c33e2014-04-09 00:31:55 -07004192 (interactive ?
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004193 mKeyguardDelegate.isShowingAndNotOccluded() :
Jim Miller5ecd8112013-01-09 18:50:26 -08004194 mKeyguardDelegate.isShowing()));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004195
Jeff Brown40013652012-05-16 21:22:36 -07004196 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004197 Log.d(TAG, "interceptKeyTq keycode=" + keyCode
Jeff Brown037c33e2014-04-09 00:31:55 -07004198 + " interactive=" + interactive + " keyguardActive=" + keyguardActive
Jeff Brown26875502014-01-30 21:47:47 -08004199 + " policyFlags=" + Integer.toHexString(policyFlags));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004200 }
4201
Jeff Brown037c33e2014-04-09 00:31:55 -07004202 // Basic policy based on interactive state.
Jeff Brown4d396052010-10-29 21:50:21 -07004203 int result;
Michael Wright337d9d22014-04-22 15:03:48 -07004204 boolean isWakeKey = (policyFlags & WindowManagerPolicy.FLAG_WAKE) != 0
4205 || event.isWakeKey();
Michael Wright70af00a2014-09-03 19:30:20 -07004206 if (interactive
4207 || (isInjected && !isWakeKey)
4208 || (!interactive && shouldDispatchInputWhenNonInteractive())) {
4209 // When the device is interactive, the key is injected, or we're currently dozing in a
4210 // non-interactive state with the screen on and the keyguard showing, pass the key to
4211 // the application.
Jeff Brown4d396052010-10-29 21:50:21 -07004212 result = ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07004213 isWakeKey = false;
Jeff Brown4d396052010-10-29 21:50:21 -07004214 } else {
4215 // When the screen is off and the key is not injected, determine whether
4216 // to wake the device but don't pass the key to the application.
4217 result = 0;
Jeff Brown26875502014-01-30 21:47:47 -08004218 if (isWakeKey && (!down || !isWakeKeyWhenScreenOff(keyCode))) {
4219 isWakeKey = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004220 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004221 }
4222
Justin Kohd378ad72013-04-01 12:18:26 -07004223 // If the key would be handled globally, just return the result, don't worry about special
4224 // key processing.
4225 if (mGlobalKeyManager.shouldHandleGlobalKey(keyCode, event)) {
Michael Wright85b1af62014-06-04 14:51:58 -07004226 if (isWakeKey) {
4227 mPowerManager.wakeUp(event.getEventTime());
4228 }
Justin Kohd378ad72013-04-01 12:18:26 -07004229 return result;
4230 }
4231
Jeff Brownbae8e772014-06-12 19:59:45 -07004232 boolean useHapticFeedback = down
4233 && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0
4234 && event.getRepeatCount() == 0;
4235
Jeff Brown4d396052010-10-29 21:50:21 -07004236 // Handle special keys.
4237 switch (keyCode) {
4238 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jeff Brownb0418da2010-11-01 15:24:01 -07004239 case KeyEvent.KEYCODE_VOLUME_UP:
4240 case KeyEvent.KEYCODE_VOLUME_MUTE: {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004241 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
4242 if (down) {
Jeff Brown037c33e2014-04-09 00:31:55 -07004243 if (interactive && !mVolumeDownKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004244 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
4245 mVolumeDownKeyTriggered = true;
4246 mVolumeDownKeyTime = event.getDownTime();
4247 mVolumeDownKeyConsumedByScreenshotChord = false;
4248 cancelPendingPowerKeyAction();
4249 interceptScreenshotChord();
4250 }
4251 } else {
4252 mVolumeDownKeyTriggered = false;
4253 cancelPendingScreenshotChordAction();
4254 }
4255 } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
4256 if (down) {
Jeff Brown037c33e2014-04-09 00:31:55 -07004257 if (interactive && !mVolumeUpKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004258 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
4259 mVolumeUpKeyTriggered = true;
4260 cancelPendingPowerKeyAction();
4261 cancelPendingScreenshotChordAction();
4262 }
4263 } else {
4264 mVolumeUpKeyTriggered = false;
4265 cancelPendingScreenshotChordAction();
4266 }
4267 }
Jeff Brown4d396052010-10-29 21:50:21 -07004268 if (down) {
Santos Cordon9eb45932014-06-27 12:28:43 -07004269 TelecommManager telecommManager = getTelecommService();
4270 if (telecommManager != null) {
4271 if (telecommManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07004272 // If an incoming call is ringing, either VOLUME key means
4273 // "silence ringer". We handle these keys here, rather than
4274 // in the InCallScreen, to make sure we'll respond to them
4275 // even if the InCallScreen hasn't come to the foreground yet.
4276 // Look for the DOWN event here, to agree with the "fallback"
4277 // behavior in the InCallScreen.
4278 Log.i(TAG, "interceptKeyBeforeQueueing:"
4279 + " VOLUME key-down while ringing: Silence ringer!");
Jeff Brown4d396052010-10-29 21:50:21 -07004280
Santos Cordon6848f722014-05-21 15:22:12 -07004281 // Silence the ringer. (It's safe to call this
4282 // even if the ringer has already been silenced.)
Santos Cordon9eb45932014-06-27 12:28:43 -07004283 telecommManager.silenceRinger();
Jeff Brown4d396052010-10-29 21:50:21 -07004284
Santos Cordon6848f722014-05-21 15:22:12 -07004285 // And *don't* pass this key thru to the current activity
4286 // (which is probably the InCallScreen.)
4287 result &= ~ACTION_PASS_TO_USER;
4288 break;
4289 }
Nancy Chen0eb1e402014-08-21 22:52:29 -07004290 if (telecommManager.isInCall()
Santos Cordon6848f722014-05-21 15:22:12 -07004291 && (result & ACTION_PASS_TO_USER) == 0) {
4292 // If we are in call but we decided not to pass the key to
RoboErik430fc482014-06-12 15:49:20 -07004293 // the application, just pass it to the session service.
4294
4295 MediaSessionLegacyHelper.getHelper(mContext)
RoboErik3c45c292014-07-08 16:47:31 -07004296 .sendVolumeKeyEvent(event, false);
Santos Cordon6848f722014-05-21 15:22:12 -07004297 break;
Jeff Brown4d396052010-10-29 21:50:21 -07004298 }
4299 }
4300
RoboErik430fc482014-06-12 15:49:20 -07004301 if ((result & ACTION_PASS_TO_USER) == 0) {
4302 // If we aren't passing to the user and no one else
4303 // handled it send it to the session manager to figure
4304 // out.
4305 MediaSessionLegacyHelper.getHelper(mContext)
RoboErik3c45c292014-07-08 16:47:31 -07004306 .sendVolumeKeyEvent(event, true);
Jeff Brown4d396052010-10-29 21:50:21 -07004307 break;
4308 }
4309 }
4310 break;
4311 }
4312
4313 case KeyEvent.KEYCODE_ENDCALL: {
4314 result &= ~ACTION_PASS_TO_USER;
4315 if (down) {
Santos Cordon9eb45932014-06-27 12:28:43 -07004316 TelecommManager telecommManager = getTelecommService();
Jeff Brown4d396052010-10-29 21:50:21 -07004317 boolean hungUp = false;
Santos Cordon9eb45932014-06-27 12:28:43 -07004318 if (telecommManager != null) {
4319 hungUp = telecommManager.endCall();
Jeff Brown4d396052010-10-29 21:50:21 -07004320 }
Jeff Brown037c33e2014-04-09 00:31:55 -07004321 interceptPowerKeyDown(!interactive || hungUp);
Jeff Brown4d396052010-10-29 21:50:21 -07004322 } else {
4323 if (interceptPowerKeyUp(canceled)) {
4324 if ((mEndcallBehavior
4325 & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) {
4326 if (goHome()) {
4327 break;
Dianne Hackborn0041e972009-07-24 17:14:43 -07004328 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004329 }
Jeff Brown4d396052010-10-29 21:50:21 -07004330 if ((mEndcallBehavior
4331 & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) {
Jeff Brownc12035c2014-08-13 18:52:25 -07004332 mPowerManager.goToSleep(event.getEventTime(),
4333 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
Jeff Brown26875502014-01-30 21:47:47 -08004334 isWakeKey = false;
Jeff Brown4d396052010-10-29 21:50:21 -07004335 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004336 }
Jeff Brown4d396052010-10-29 21:50:21 -07004337 }
4338 break;
4339 }
4340
4341 case KeyEvent.KEYCODE_POWER: {
4342 result &= ~ACTION_PASS_TO_USER;
4343 if (down) {
Jeff Brown26c6a502014-04-11 02:15:54 -07004344 boolean panic = mImmersiveModeConfirmation.onPowerKeyDown(interactive,
John Spurlockd9b70bd2014-02-06 17:02:44 -05004345 event.getDownTime(), isImmersiveMode(mLastSystemUiFlags));
4346 if (panic) {
4347 mHandler.post(mRequestTransientNav);
4348 }
Jeff Brown037c33e2014-04-09 00:31:55 -07004349 if (interactive && !mPowerKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004350 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
4351 mPowerKeyTriggered = true;
4352 mPowerKeyTime = event.getDownTime();
4353 interceptScreenshotChord();
Winson Chung9112ec32011-06-27 13:15:32 -07004354 }
Winson Chung9112ec32011-06-27 13:15:32 -07004355
Santos Cordon9eb45932014-06-27 12:28:43 -07004356 TelecommManager telecommManager = getTelecommService();
Jeff Brown4d396052010-10-29 21:50:21 -07004357 boolean hungUp = false;
Santos Cordon9eb45932014-06-27 12:28:43 -07004358 if (telecommManager != null) {
4359 if (telecommManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07004360 // Pressing Power while there's a ringing incoming
4361 // call should silence the ringer.
Santos Cordon9eb45932014-06-27 12:28:43 -07004362 telecommManager.silenceRinger();
Santos Cordon6848f722014-05-21 15:22:12 -07004363 } else if ((mIncallPowerBehavior
4364 & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0
Nancy Chen0eb1e402014-08-21 22:52:29 -07004365 && telecommManager.isInCall() && interactive) {
Santos Cordon6848f722014-05-21 15:22:12 -07004366 // Otherwise, if "Power button ends call" is enabled,
4367 // the Power button will hang up any current active call.
Santos Cordon9eb45932014-06-27 12:28:43 -07004368 hungUp = telecommManager.endCall();
Jeff Brown4d396052010-10-29 21:50:21 -07004369 }
4370 }
Jeff Brown037c33e2014-04-09 00:31:55 -07004371 interceptPowerKeyDown(!interactive || hungUp
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004372 || mVolumeDownKeyTriggered || mVolumeUpKeyTriggered);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004373 } else {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004374 mPowerKeyTriggered = false;
4375 cancelPendingScreenshotChordAction();
4376 if (interceptPowerKeyUp(canceled || mPendingPowerKeyUpCanceled)) {
Jeff Brown6d8fd272014-05-20 21:24:38 -07004377 powerShortPress(event.getEventTime());
Jeff Brown26875502014-01-30 21:47:47 -08004378 isWakeKey = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004379 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004380 mPendingPowerKeyUpCanceled = false;
Jeff Brown4d396052010-10-29 21:50:21 -07004381 }
4382 break;
4383 }
4384
Jeff Brown6212a492014-03-07 13:58:47 -08004385 case KeyEvent.KEYCODE_SLEEP: {
4386 result &= ~ACTION_PASS_TO_USER;
Jeff Brownbae8e772014-06-12 19:59:45 -07004387 if (!mPowerManager.isInteractive()) {
4388 useHapticFeedback = false; // suppress feedback if already non-interactive
4389 }
Jeff Brownc12035c2014-08-13 18:52:25 -07004390 mPowerManager.goToSleep(event.getEventTime(),
4391 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
Jeff Brown6212a492014-03-07 13:58:47 -08004392 isWakeKey = false;
4393 break;
4394 }
4395
4396 case KeyEvent.KEYCODE_WAKEUP: {
4397 result &= ~ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07004398 isWakeKey = true;
Jeff Brown6212a492014-03-07 13:58:47 -08004399 break;
4400 }
4401
Jeff Brown4d396052010-10-29 21:50:21 -07004402 case KeyEvent.KEYCODE_MEDIA_PLAY:
4403 case KeyEvent.KEYCODE_MEDIA_PAUSE:
4404 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
4405 if (down) {
Santos Cordon9eb45932014-06-27 12:28:43 -07004406 TelecommManager telecommManager = getTelecommService();
4407 if (telecommManager != null) {
Nancy Chen0eb1e402014-08-21 22:52:29 -07004408 if (telecommManager.isInCall()) {
Santos Cordon6848f722014-05-21 15:22:12 -07004409 // Suppress PLAY/PAUSE toggle when phone is ringing or in-call
4410 // to avoid music playback.
4411 break;
Jeff Brown3122e442010-10-11 23:32:49 -07004412 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004413 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004414 }
Jeff Brown4d396052010-10-29 21:50:21 -07004415 case KeyEvent.KEYCODE_HEADSETHOOK:
4416 case KeyEvent.KEYCODE_MUTE:
4417 case KeyEvent.KEYCODE_MEDIA_STOP:
4418 case KeyEvent.KEYCODE_MEDIA_NEXT:
4419 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
4420 case KeyEvent.KEYCODE_MEDIA_REWIND:
4421 case KeyEvent.KEYCODE_MEDIA_RECORD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09004422 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
4423 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: {
Jeff Brown4d396052010-10-29 21:50:21 -07004424 if ((result & ACTION_PASS_TO_USER) == 0) {
4425 // Only do this if we would otherwise not pass it to the user. In that
4426 // case, the PhoneWindow class will do the same thing, except it will
4427 // only do it if the showing app doesn't process the key on its own.
Jeff Brown40013652012-05-16 21:22:36 -07004428 // Note that we need to make a copy of the key event here because the
4429 // original key event will be recycled when we return.
Jeff Brown4d396052010-10-29 21:50:21 -07004430 mBroadcastWakeLock.acquire();
Jeff Brown40013652012-05-16 21:22:36 -07004431 Message msg = mHandler.obtainMessage(MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK,
4432 new KeyEvent(event));
4433 msg.setAsynchronous(true);
4434 msg.sendToTarget();
Jeff Brown4d396052010-10-29 21:50:21 -07004435 }
4436 break;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004437 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004438
Jeff Brown4d396052010-10-29 21:50:21 -07004439 case KeyEvent.KEYCODE_CALL: {
4440 if (down) {
Santos Cordon9eb45932014-06-27 12:28:43 -07004441 TelecommManager telecommManager = getTelecommService();
4442 if (telecommManager != null) {
4443 if (telecommManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07004444 Log.i(TAG, "interceptKeyBeforeQueueing:"
4445 + " CALL key-down while ringing: Answer the call!");
Santos Cordon9eb45932014-06-27 12:28:43 -07004446 telecommManager.acceptRingingCall();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004447
Santos Cordon6848f722014-05-21 15:22:12 -07004448 // And *don't* pass this key thru to the current activity
4449 // (which is presumably the InCallScreen.)
4450 result &= ~ACTION_PASS_TO_USER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004451 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004452 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004453 }
Jeff Brown4d396052010-10-29 21:50:21 -07004454 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004455 }
Michael Wright869a67c2014-08-26 19:33:06 -07004456 case KeyEvent.KEYCODE_VOICE_ASSIST: {
4457 // Only do this if we would otherwise not pass it to the user. In that case,
4458 // interceptKeyBeforeDispatching would apply a similar but different policy in
4459 // order to invoke voice assist actions. Note that we need to make a copy of the
4460 // key event here because the original key event will be recycled when we return.
4461 if ((result & ACTION_PASS_TO_USER) == 0 && !down) {
4462 mBroadcastWakeLock.acquire();
4463 Message msg = mHandler.obtainMessage(MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK,
4464 keyguardActive ? 1 : 0, 0);
4465 msg.setAsynchronous(true);
4466 msg.sendToTarget();
4467 }
4468 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004469 }
Jeff Brown26875502014-01-30 21:47:47 -08004470
Jeff Brownbae8e772014-06-12 19:59:45 -07004471 if (useHapticFeedback) {
4472 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
4473 }
4474
Jeff Brown26875502014-01-30 21:47:47 -08004475 if (isWakeKey) {
4476 mPowerManager.wakeUp(event.getEventTime());
4477 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004478 return result;
4479 }
4480
Jeff Brown1c2e4942012-11-06 16:32:01 -08004481 /**
4482 * When the screen is off we ignore some keys that might otherwise typically
4483 * be considered wake keys. We filter them out here.
4484 *
4485 * {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it
4486 * is always considered a wake key.
4487 */
4488 private boolean isWakeKeyWhenScreenOff(int keyCode) {
4489 switch (keyCode) {
4490 // ignore volume keys unless docked
4491 case KeyEvent.KEYCODE_VOLUME_UP:
4492 case KeyEvent.KEYCODE_VOLUME_DOWN:
4493 case KeyEvent.KEYCODE_VOLUME_MUTE:
4494 return mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED;
4495
4496 // ignore media and camera keys
4497 case KeyEvent.KEYCODE_MUTE:
4498 case KeyEvent.KEYCODE_HEADSETHOOK:
4499 case KeyEvent.KEYCODE_MEDIA_PLAY:
4500 case KeyEvent.KEYCODE_MEDIA_PAUSE:
4501 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
4502 case KeyEvent.KEYCODE_MEDIA_STOP:
4503 case KeyEvent.KEYCODE_MEDIA_NEXT:
4504 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
4505 case KeyEvent.KEYCODE_MEDIA_REWIND:
4506 case KeyEvent.KEYCODE_MEDIA_RECORD:
4507 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09004508 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK:
Jeff Brown1c2e4942012-11-06 16:32:01 -08004509 case KeyEvent.KEYCODE_CAMERA:
4510 return false;
4511 }
4512 return true;
4513 }
4514
4515
Jeff Brown56194eb2011-03-02 19:23:13 -08004516 /** {@inheritDoc} */
4517 @Override
Michael Wright70af00a2014-09-03 19:30:20 -07004518 public int interceptMotionBeforeQueueingNonInteractive(long whenNanos, int policyFlags) {
4519 if ((policyFlags & FLAG_WAKE) != 0) {
4520 mPowerManager.wakeUp(whenNanos / 1000000);
4521 return 0;
4522 }
4523 if (shouldDispatchInputWhenNonInteractive()) {
4524 return ACTION_PASS_TO_USER;
4525 }
Jeff Brown037c33e2014-04-09 00:31:55 -07004526 return 0;
Jeff Brown56194eb2011-03-02 19:23:13 -08004527 }
4528
Michael Wright70af00a2014-09-03 19:30:20 -07004529 private boolean shouldDispatchInputWhenNonInteractive() {
4530 return keyguardIsShowingTq() && mDisplay != null &&
4531 mDisplay.getState() != Display.STATE_OFF;
4532 }
4533
Jeff Brown40013652012-05-16 21:22:36 -07004534 void dispatchMediaKeyWithWakeLock(KeyEvent event) {
4535 if (DEBUG_INPUT) {
4536 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: " + event);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004537 }
4538
Jeff Brown40013652012-05-16 21:22:36 -07004539 if (mHavePendingMediaKeyRepeatWithWakeLock) {
4540 if (DEBUG_INPUT) {
4541 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: canceled repeat");
4542 }
4543
4544 mHandler.removeMessages(MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK);
4545 mHavePendingMediaKeyRepeatWithWakeLock = false;
4546 mBroadcastWakeLock.release(); // pending repeat was holding onto the wake lock
4547 }
4548
4549 dispatchMediaKeyWithWakeLockToAudioService(event);
4550
4551 if (event.getAction() == KeyEvent.ACTION_DOWN
4552 && event.getRepeatCount() == 0) {
4553 mHavePendingMediaKeyRepeatWithWakeLock = true;
4554
4555 Message msg = mHandler.obtainMessage(
4556 MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK, event);
4557 msg.setAsynchronous(true);
4558 mHandler.sendMessageDelayed(msg, ViewConfiguration.getKeyRepeatTimeout());
4559 } else {
4560 mBroadcastWakeLock.release();
4561 }
4562 }
4563
4564 void dispatchMediaKeyRepeatWithWakeLock(KeyEvent event) {
4565 mHavePendingMediaKeyRepeatWithWakeLock = false;
4566
4567 KeyEvent repeatEvent = KeyEvent.changeTimeRepeat(event,
4568 SystemClock.uptimeMillis(), 1, event.getFlags() | KeyEvent.FLAG_LONG_PRESS);
4569 if (DEBUG_INPUT) {
4570 Slog.d(TAG, "dispatchMediaKeyRepeatWithWakeLock: " + repeatEvent);
4571 }
4572
4573 dispatchMediaKeyWithWakeLockToAudioService(repeatEvent);
4574 mBroadcastWakeLock.release();
4575 }
4576
4577 void dispatchMediaKeyWithWakeLockToAudioService(KeyEvent event) {
4578 if (ActivityManagerNative.isSystemReady()) {
RoboErik430fc482014-06-12 15:49:20 -07004579 MediaSessionLegacyHelper.getHelper(mContext).sendMediaButtonEvent(event, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004580 }
4581 }
4582
Michael Wright869a67c2014-08-26 19:33:06 -07004583 void launchVoiceAssistWithWakeLock(boolean keyguardActive) {
4584 Intent voiceIntent =
4585 new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
4586 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, keyguardActive);
4587 mContext.startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
4588 mBroadcastWakeLock.release();
4589 }
4590
Mike Lockwood1753f7f2009-08-24 14:49:07 -07004591 BroadcastReceiver mDockReceiver = new BroadcastReceiver() {
Craig Mautnereee29c42013-01-17 14:44:34 -08004592 @Override
Mike Lockwood1753f7f2009-08-24 14:49:07 -07004593 public void onReceive(Context context, Intent intent) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07004594 if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) {
4595 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
4596 Intent.EXTRA_DOCK_STATE_UNDOCKED);
Daniel Sandler6396c722013-04-16 20:19:09 -04004597 } else {
4598 try {
4599 IUiModeManager uiModeService = IUiModeManager.Stub.asInterface(
4600 ServiceManager.getService(Context.UI_MODE_SERVICE));
4601 mUiMode = uiModeService.getCurrentModeType();
4602 } catch (RemoteException e) {
4603 }
Dianne Hackborn80fa1662009-10-07 14:02:10 -07004604 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004605 updateRotation(true);
Craig Mautnereee29c42013-01-17 14:44:34 -08004606 synchronized (mLock) {
4607 updateOrientationListenerLp();
4608 }
Mike Lockwood1753f7f2009-08-24 14:49:07 -07004609 }
4610 };
4611
Jeff Brown6aaf2952012-10-05 16:01:08 -07004612 BroadcastReceiver mDreamReceiver = new BroadcastReceiver() {
4613 @Override
4614 public void onReceive(Context context, Intent intent) {
4615 if (Intent.ACTION_DREAMING_STARTED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004616 if (mKeyguardDelegate != null) {
4617 mKeyguardDelegate.onDreamingStarted();
Jeff Brown6aaf2952012-10-05 16:01:08 -07004618 }
4619 } else if (Intent.ACTION_DREAMING_STOPPED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004620 if (mKeyguardDelegate != null) {
4621 mKeyguardDelegate.onDreamingStopped();
Jeff Brown6aaf2952012-10-05 16:01:08 -07004622 }
4623 }
4624 }
4625 };
4626
Christopher Tate5e08af02012-09-21 17:17:22 -07004627 BroadcastReceiver mMultiuserReceiver = new BroadcastReceiver() {
4628 @Override
4629 public void onReceive(Context context, Intent intent) {
4630 if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) {
4631 // tickle the settings observer: this first ensures that we're
4632 // observing the relevant settings for the newly-active user,
4633 // and then updates our own bookkeeping based on the now-
4634 // current user.
4635 mSettingsObserver.onChange(false);
John Spurlockce479d82012-11-29 09:52:21 -05004636
4637 // force a re-application of focused window sysui visibility.
4638 // the window may never have been shown for this user
4639 // e.g. the keyguard when going through the new-user setup flow
John Spurlock04db1762013-05-13 12:46:41 -04004640 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
John Spurlockce479d82012-11-29 09:52:21 -05004641 mLastSystemUiFlags = 0;
4642 updateSystemUiVisibilityLw();
4643 }
Christopher Tate5e08af02012-09-21 17:17:22 -07004644 }
4645 }
4646 };
4647
John Spurlockd9b70bd2014-02-06 17:02:44 -05004648 private final Runnable mRequestTransientNav = new Runnable() {
4649 @Override
4650 public void run() {
4651 requestTransientBars(mNavigationBar);
4652 }
4653 };
4654
John Spurlocke1f366f2013-08-05 12:22:40 -04004655 private void requestTransientBars(WindowState swipeTarget) {
John Spurlock04db1762013-05-13 12:46:41 -04004656 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Maurice Lam99c6e072014-04-28 18:24:28 -07004657 if (!isUserSetupComplete()) {
4658 // Swipe-up for navigation bar is disabled during setup
4659 return;
4660 }
John Spurlock27735a42013-08-14 17:57:38 -04004661 boolean sb = mStatusBarController.checkShowTransientBarLw();
4662 boolean nb = mNavigationBarController.checkShowTransientBarLw();
John Spurlockad3e6cb2013-04-30 08:47:43 -04004663 if (sb || nb) {
John Spurlocke1f366f2013-08-05 12:22:40 -04004664 WindowState barTarget = sb ? mStatusBar : mNavigationBar;
4665 if (sb ^ nb && barTarget != swipeTarget) {
4666 if (DEBUG) Slog.d(TAG, "Not showing transient bar, wrong swipe target");
John Spurlockad3e6cb2013-04-30 08:47:43 -04004667 return;
4668 }
John Spurlock27735a42013-08-14 17:57:38 -04004669 if (sb) mStatusBarController.showTransient();
4670 if (nb) mNavigationBarController.showTransient();
John Spurlockf1a36642013-10-12 17:50:42 -04004671 mImmersiveModeConfirmation.confirmCurrentPrompt();
John Spurlockad3e6cb2013-04-30 08:47:43 -04004672 updateSystemUiVisibilityLw();
John Spurlock32beb2c2013-03-11 10:16:47 -04004673 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04004674 }
4675 }
4676
Jeff Brownc38c9be2012-10-04 13:16:19 -07004677 @Override
Jeff Brown140ffc72014-05-01 15:18:00 -07004678 public void goingToSleep(int why) {
Dianne Hackborn74489012009-03-24 20:50:09 -07004679 EventLog.writeEvent(70000, 0);
The Android Open Source Project0727d222009-03-11 12:11:58 -07004680 synchronized (mLock) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004681 mScreenOnEarly = false;
4682 mScreenOnFully = false;
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07004683 }
Jim Miller5ecd8112013-01-09 18:50:26 -08004684 if (mKeyguardDelegate != null) {
4685 mKeyguardDelegate.onScreenTurnedOff(why);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004686 }
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07004687 synchronized (mLock) {
Jeff Browna20dda42014-05-27 20:57:24 -07004688 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07004689 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05004690 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07004691 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004692 }
4693
Jeff Brownc38c9be2012-10-04 13:16:19 -07004694 @Override
Jeff Brown140ffc72014-05-01 15:18:00 -07004695 public void wakingUp(final ScreenOnListener screenOnListener) {
Dianne Hackborn74489012009-03-24 20:50:09 -07004696 EventLog.writeEvent(70000, 1);
Craig Mautner8a0da012014-05-31 15:13:37 -07004697 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turning on...",
4698 new RuntimeException("here").fillInStackTrace());
4699 mHandler.obtainMessage(MSG_WAKING_UP, screenOnListener).sendToTarget();
4700 }
4701
4702 // Called on the mHandler thread.
4703 private void handleWakingUp(final ScreenOnListener screenOnListener) {
4704 if (screenOnListener != null) {
Craig Mautner13f6ea72014-06-23 14:57:02 -07004705 mScreenOnListener = screenOnListener;
Dianne Hackborn40011092011-09-22 13:37:48 -07004706 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07004707
The Android Open Source Project0727d222009-03-11 12:11:58 -07004708 synchronized (mLock) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004709 mScreenOnEarly = true;
Jeff Browna20dda42014-05-27 20:57:24 -07004710 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07004711 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05004712 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07004713 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07004714
Craig Mautner8a0da012014-05-31 15:13:37 -07004715 mKeyguardDrawComplete = false;
4716 mWindowManagerDrawComplete = false;
Jim Miller5ecd8112013-01-09 18:50:26 -08004717 if (mKeyguardDelegate != null) {
Craig Mautner8a0da012014-05-31 15:13:37 -07004718 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
4719 mHandler.sendEmptyMessageDelayed(MSG_KEYGUARD_DRAWN_TIMEOUT, 1000);
4720 mKeyguardDelegate.onScreenTurnedOn(mKeyguardDelegateCallback);
Jeff Brownc38c9be2012-10-04 13:16:19 -07004721 } else {
Craig Mautner8a0da012014-05-31 15:13:37 -07004722 if (DEBUG_WAKEUP) Slog.d(TAG, "null mKeyguardDelegate: setting mKeyguardDrawComplete.");
4723 mKeyguardDrawComplete = true;
Jeff Brownc38c9be2012-10-04 13:16:19 -07004724 }
Craig Mautner8a0da012014-05-31 15:13:37 -07004725 mWindowManagerInternal.waitForAllWindowsDrawn(mWindowManagerDrawCallback, 500);
Jeff Brownc38c9be2012-10-04 13:16:19 -07004726 }
4727
Craig Mautner8a0da012014-05-31 15:13:37 -07004728 // Called on the mHandler thread.
4729 private void finishScreenTurningOn() {
4730 if (DEBUG_WAKEUP) Slog.d(TAG,
4731 "finishScreenTurningOn: mKeyguardDrawComplete=" + mKeyguardDrawComplete
4732 + " mWindowManagerDrawComplete=" + mWindowManagerDrawComplete);
4733 if (!mKeyguardDrawComplete || !mWindowManagerDrawComplete) {
4734 return;
Jeff Brownc38c9be2012-10-04 13:16:19 -07004735 }
4736
Craig Mautner13f6ea72014-06-23 14:57:02 -07004737 ScreenOnListener screenOnListener;
Jeff Brownc38c9be2012-10-04 13:16:19 -07004738 synchronized (mLock) {
4739 mScreenOnFully = true;
Craig Mautner13f6ea72014-06-23 14:57:02 -07004740 screenOnListener = mScreenOnListener;
4741 mScreenOnListener = null;
Jeff Brownc38c9be2012-10-04 13:16:19 -07004742 }
4743
Jeff Brown4fc45272012-10-10 18:28:14 -07004744 try {
4745 mWindowManager.setEventDispatching(true);
4746 } catch (RemoteException unhandled) {
4747 }
4748
Craig Mautner13f6ea72014-06-23 14:57:02 -07004749 if (screenOnListener != null) {
4750 screenOnListener.onScreenOn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07004751 }
Craig Mautner8a0da012014-05-31 15:13:37 -07004752
4753 setKeyguardDrawn();
Craig Mautnera631d492014-08-05 15:16:01 -07004754
4755 if (mBootMessageNeedsHiding) {
4756 handleHideBootMessage();
4757 mBootMessageNeedsHiding = false;
4758 }
4759 }
4760
4761 private void handleHideBootMessage() {
4762 if (mBootMsgDialog == null) {
4763 if (DEBUG_WAKEUP) Slog.d(TAG, "handleHideBootMessage: boot message not up");
4764 return;
4765 }
4766 if (!mKeyguardDrawComplete || !mWindowManagerDrawComplete) {
4767 if (DEBUG_WAKEUP) Slog.d(TAG, "handleHideBootMessage: deferring until keyguard ready");
4768 mBootMessageNeedsHiding = true;
4769 return;
4770 }
4771 if (DEBUG_WAKEUP) Slog.d(TAG, "handleHideBootMessage: dismissing");
4772 mBootMsgDialog.dismiss();
4773 mBootMsgDialog = null;
Jeff Brownc38c9be2012-10-04 13:16:19 -07004774 }
4775
4776 @Override
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004777 public boolean isScreenOnEarly() {
4778 return mScreenOnEarly;
4779 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07004780
4781 @Override
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004782 public boolean isScreenOnFully() {
4783 return mScreenOnFully;
Dianne Hackborn08743722009-12-21 12:16:51 -08004784 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07004785
Dianne Hackborn08743722009-12-21 12:16:51 -08004786 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07004787 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004788 public void enableKeyguard(boolean enabled) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004789 if (mKeyguardDelegate != null) {
4790 mKeyguardDelegate.setKeyguardEnabled(enabled);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004791 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004792 }
4793
4794 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07004795 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004796 public void exitKeyguardSecurely(OnKeyguardExitResult callback) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004797 if (mKeyguardDelegate != null) {
4798 mKeyguardDelegate.verifyUnlock(callback);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004799 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004800 }
4801
Mike Lockwoodf7913302009-11-28 22:27:10 -05004802 private boolean keyguardIsShowingTq() {
Jim Miller5ecd8112013-01-09 18:50:26 -08004803 if (mKeyguardDelegate == null) return false;
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004804 return mKeyguardDelegate.isShowingAndNotOccluded();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004805 }
4806
Mike Lockwood520d8bc2011-02-18 13:23:13 -05004807
4808 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07004809 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05004810 public boolean isKeyguardLocked() {
4811 return keyguardOn();
4812 }
4813
4814 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07004815 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05004816 public boolean isKeyguardSecure() {
Jim Miller5ecd8112013-01-09 18:50:26 -08004817 if (mKeyguardDelegate == null) return false;
4818 return mKeyguardDelegate.isSecure();
Mike Lockwood520d8bc2011-02-18 13:23:13 -05004819 }
4820
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004821 // Returns true if keyguard is currently locked whether or not it is currently hidden.
4822 private boolean isKeyguardSecureIncludingHidden() {
4823 return mKeyguardDelegate.isSecure() && mKeyguardDelegate.isShowing();
4824 }
4825
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004826 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07004827 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004828 public boolean inKeyguardRestrictedKeyInputMode() {
Jim Miller5ecd8112013-01-09 18:50:26 -08004829 if (mKeyguardDelegate == null) return false;
4830 return mKeyguardDelegate.isInputRestricted();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004831 }
4832
Jose Lima9546b202014-07-02 17:21:51 -07004833 @Override
Dianne Hackborn90c52de2011-09-23 12:57:44 -07004834 public void dismissKeyguardLw() {
RoboErik8a2cfc32014-05-16 11:19:38 -07004835 if (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()) {
Daniel Sandler1ce804392012-11-07 15:07:12 -05004836 mHandler.post(new Runnable() {
Jose Lima9546b202014-07-02 17:21:51 -07004837 @Override
Daniel Sandler1ce804392012-11-07 15:07:12 -05004838 public void run() {
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02004839 // ask the keyguard to prompt the user to authenticate if necessary
4840 mKeyguardDelegate.dismiss();
4841 }
4842 });
4843 }
4844 }
4845
4846 public void notifyActivityDrawnForKeyguardLw() {
4847 if (mKeyguardDelegate != null) {
4848 mHandler.post(new Runnable() {
4849 @Override
4850 public void run() {
4851 mKeyguardDelegate.onActivityDrawn();
Daniel Sandler1ce804392012-11-07 15:07:12 -05004852 }
4853 });
Dianne Hackborn90c52de2011-09-23 12:57:44 -07004854 }
4855 }
4856
Jorim Jaggicff0acb2014-03-31 16:35:15 +02004857 private void setKeyguardDrawn() {
4858 synchronized (mLock) {
4859 mKeyguardDrawn = true;
4860 }
4861 try {
4862 mWindowManager.enableScreenIfNeeded();
4863 } catch (RemoteException unhandled) {
4864 }
4865 }
4866
4867 @Override
4868 public boolean isKeyguardDrawnLw() {
4869 synchronized (mLock) {
4870 return mKeyguardDrawn;
4871 }
4872 }
4873
Jorim Jaggi0d674622014-05-21 01:34:15 +02004874 @Override
Jorim Jaggie29b2db2014-05-30 23:17:03 +02004875 public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) {
Jorim Jaggi0d674622014-05-21 01:34:15 +02004876 if (mKeyguardDelegate != null) {
Jorim Jaggie29b2db2014-05-30 23:17:03 +02004877 mKeyguardDelegate.startKeyguardExitAnimation(startTime, fadeoutDuration);
Jorim Jaggi0d674622014-05-21 01:34:15 +02004878 }
4879 }
4880
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004881 void sendCloseSystemWindows() {
4882 sendCloseSystemWindows(mContext, null);
4883 }
4884
4885 void sendCloseSystemWindows(String reason) {
4886 sendCloseSystemWindows(mContext, reason);
4887 }
4888
4889 static void sendCloseSystemWindows(Context context, String reason) {
4890 if (ActivityManagerNative.isSystemReady()) {
Dianne Hackborn94a679d2009-07-28 17:51:07 -07004891 try {
4892 ActivityManagerNative.getDefault().closeSystemDialogs(reason);
4893 } catch (RemoteException e) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004894 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004895 }
4896 }
Mitsuru Oshima831d0d92009-06-16 18:27:18 -07004897
Jeff Brown01a98dd2011-09-20 15:08:29 -07004898 @Override
4899 public int rotationForOrientationLw(int orientation, int lastRotation) {
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05004900 if (false) {
4901 Slog.v(TAG, "rotationForOrientationLw(orient="
4902 + orientation + ", last=" + lastRotation
4903 + "); user=" + mUserRotation + " "
4904 + ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED)
4905 ? "USER_ROTATION_LOCKED" : "")
4906 );
4907 }
4908
Craig Mautner46ac6fa2013-08-01 10:06:34 -07004909 if (mForceDefaultOrientation) {
4910 return Surface.ROTATION_0;
4911 }
4912
The Android Open Source Project0727d222009-03-11 12:11:58 -07004913 synchronized (mLock) {
Jeff Brownc0347aa2011-09-23 17:26:09 -07004914 int sensorRotation = mOrientationListener.getProposedRotation(); // may be -1
4915 if (sensorRotation < 0) {
Jeff Brown0f862b42012-09-27 21:11:01 -07004916 sensorRotation = lastRotation;
Jeff Brownc0347aa2011-09-23 17:26:09 -07004917 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004918
Jeff Browndec6cf42011-11-15 14:08:20 -08004919 final int preferredRotation;
Jeff Brown2e7760e2012-04-11 15:14:55 -07004920 if (mLidState == LID_OPEN && mLidOpenRotation >= 0) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07004921 // Ignore sensor when lid switch is open and rotation is forced.
4922 preferredRotation = mLidOpenRotation;
4923 } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR
Jeff Brownc0347aa2011-09-23 17:26:09 -07004924 && (mCarDockEnablesAccelerometer || mCarDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07004925 // Ignore sensor when in car dock unless explicitly enabled.
4926 // This case can override the behavior of NOSENSOR, and can also
4927 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07004928 preferredRotation = mCarDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07004929 ? sensorRotation : mCarDockRotation;
Jeff Brown1a693182011-11-08 14:44:16 -08004930 } else if ((mDockMode == Intent.EXTRA_DOCK_STATE_DESK
4931 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
4932 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK)
Jeff Brownc0347aa2011-09-23 17:26:09 -07004933 && (mDeskDockEnablesAccelerometer || mDeskDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07004934 // Ignore sensor when in desk dock unless explicitly enabled.
4935 // This case can override the behavior of NOSENSOR, and can also
4936 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07004937 preferredRotation = mDeskDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07004938 ? sensorRotation : mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -07004939 } else if (mHdmiPlugged && mDemoHdmiRotationLock) {
4940 // Ignore sensor when plugged into HDMI when demo HDMI rotation lock enabled.
Jeff Browneb3e4b92011-12-06 19:54:24 -08004941 // Note that the dock orientation overrides the HDMI orientation.
Jeff Brownc82c89ed2013-04-17 17:18:15 -07004942 preferredRotation = mDemoHdmiRotation;
4943 } else if (mHdmiPlugged && mDockMode == Intent.EXTRA_DOCK_STATE_UNDOCKED
4944 && mUndockedHdmiRotation >= 0) {
4945 // Ignore sensor when plugged into HDMI and an undocked orientation has
4946 // been specified in the configuration (only for legacy devices without
4947 // full multi-display support).
4948 // Note that the dock orientation overrides the HDMI orientation.
4949 preferredRotation = mUndockedHdmiRotation;
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07004950 } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED) {
4951 // Application just wants to remain locked in the last rotation.
4952 preferredRotation = lastRotation;
Jeff Brownbcdfc622014-03-06 19:13:04 -08004953 } else if (!mSupportAutoRotation) {
4954 // If we don't support auto-rotation then bail out here and ignore
4955 // the sensor and any rotation lock settings.
4956 preferredRotation = -1;
Jeff Brown207673cd2012-06-05 17:47:11 -07004957 } else if ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE
Jeff Brown01a98dd2011-09-20 15:08:29 -07004958 && (orientation == ActivityInfo.SCREEN_ORIENTATION_USER
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07004959 || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
4960 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
4961 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
4962 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER))
Jeff Brown01a98dd2011-09-20 15:08:29 -07004963 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
4964 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
4965 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
4966 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) {
4967 // Otherwise, use sensor only if requested by the application or enabled
4968 // by default for USER or UNSPECIFIED modes. Does not apply to NOSENSOR.
Jeff Brownd3187e32011-09-21 19:26:44 -07004969 if (mAllowAllRotations < 0) {
4970 // Can't read this during init() because the context doesn't
4971 // have display metrics at that time so we cannot determine
4972 // tablet vs. phone then.
4973 mAllowAllRotations = mContext.getResources().getBoolean(
4974 com.android.internal.R.bool.config_allowAllRotations) ? 1 : 0;
4975 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004976 if (sensorRotation != Surface.ROTATION_180
Jeff Brownd3187e32011-09-21 19:26:44 -07004977 || mAllowAllRotations == 1
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07004978 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
4979 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07004980 preferredRotation = sensorRotation;
4981 } else {
4982 preferredRotation = lastRotation;
4983 }
Jeff Brown207673cd2012-06-05 17:47:11 -07004984 } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED
4985 && orientation != ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) {
4986 // Apply rotation lock. Does not apply to NOSENSOR.
4987 // The idea is that the user rotation expresses a weak preference for the direction
4988 // of gravity and as NOSENSOR is never affected by gravity, then neither should
4989 // NOSENSOR be affected by rotation lock (although it will be affected by docks).
Jeff Brown4dfce202011-10-05 12:00:10 -07004990 preferredRotation = mUserRotation;
Jeff Browndec6cf42011-11-15 14:08:20 -08004991 } else {
4992 // No overriding preference.
4993 // We will do exactly what the application asked us to do.
4994 preferredRotation = -1;
Jeff Brown01a98dd2011-09-20 15:08:29 -07004995 }
4996
Dianne Hackborne5439f22010-10-02 16:53:50 -07004997 switch (orientation) {
4998 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08004999 // Return portrait unless overridden.
5000 if (isAnyPortrait(preferredRotation)) {
5001 return preferredRotation;
5002 }
Dianne Hackborne5439f22010-10-02 16:53:50 -07005003 return mPortraitRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005004
Jeff Brown01a98dd2011-09-20 15:08:29 -07005005 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08005006 // Return landscape unless overridden.
5007 if (isLandscapeOrSeascape(preferredRotation)) {
5008 return preferredRotation;
5009 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005010 return mLandscapeRotation;
5011
5012 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08005013 // Return reverse portrait unless overridden.
5014 if (isAnyPortrait(preferredRotation)) {
5015 return preferredRotation;
5016 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005017 return mUpsideDownRotation;
5018
5019 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08005020 // Return seascape unless overridden.
5021 if (isLandscapeOrSeascape(preferredRotation)) {
5022 return preferredRotation;
5023 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005024 return mSeascapeRotation;
5025
5026 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005027 case ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE:
Jeff Brown01a98dd2011-09-20 15:08:29 -07005028 // Return either landscape rotation.
5029 if (isLandscapeOrSeascape(preferredRotation)) {
5030 return preferredRotation;
5031 }
5032 if (isLandscapeOrSeascape(lastRotation)) {
Jeff Brown4519f072011-01-23 13:16:01 -08005033 return lastRotation;
5034 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005035 return mLandscapeRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005036
Jeff Brown01a98dd2011-09-20 15:08:29 -07005037 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005038 case ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT:
Jeff Brown01a98dd2011-09-20 15:08:29 -07005039 // Return either portrait rotation.
5040 if (isAnyPortrait(preferredRotation)) {
5041 return preferredRotation;
5042 }
5043 if (isAnyPortrait(lastRotation)) {
5044 return lastRotation;
5045 }
5046 return mPortraitRotation;
5047
5048 default:
Jeff Brown4dfce202011-10-05 12:00:10 -07005049 // For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR,
5050 // just return the preferred orientation we already calculated.
Jeff Brown01a98dd2011-09-20 15:08:29 -07005051 if (preferredRotation >= 0) {
5052 return preferredRotation;
5053 }
Dianne Hackborndacea8c2011-04-21 17:26:39 -07005054 return Surface.ROTATION_0;
Daniel Sandlere7e5ac22011-02-22 16:10:21 -05005055 }
5056 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07005057 }
5058
Jeff Brown01a98dd2011-09-20 15:08:29 -07005059 @Override
5060 public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation) {
5061 switch (orientation) {
5062 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
5063 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
5064 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
5065 return isAnyPortrait(rotation);
5066
5067 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
5068 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
5069 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
5070 return isLandscapeOrSeascape(rotation);
5071
5072 default:
5073 return true;
5074 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07005075 }
5076
Jeff Brownc0347aa2011-09-23 17:26:09 -07005077 @Override
5078 public void setRotationLw(int rotation) {
5079 mOrientationListener.setCurrentRotation(rotation);
5080 }
5081
Jeff Brown01a98dd2011-09-20 15:08:29 -07005082 private boolean isLandscapeOrSeascape(int rotation) {
5083 return rotation == mLandscapeRotation || rotation == mSeascapeRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005084 }
5085
Jeff Brown01a98dd2011-09-20 15:08:29 -07005086 private boolean isAnyPortrait(int rotation) {
5087 return rotation == mPortraitRotation || rotation == mUpsideDownRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005088 }
5089
Jose Lima9546b202014-07-02 17:21:51 -07005090 @Override
Svetoslav Ganov80943d82013-01-02 10:25:37 -08005091 public int getUserRotationMode() {
5092 return Settings.System.getIntForUser(mContext.getContentResolver(),
Brett Chabot7e55c402013-05-16 19:38:08 -07005093 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
5094 WindowManagerPolicy.USER_ROTATION_FREE :
5095 WindowManagerPolicy.USER_ROTATION_LOCKED;
Svetoslav Ganov80943d82013-01-02 10:25:37 -08005096 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005097
5098 // User rotation: to be used when all else fails in assigning an orientation to the device
Jose Lima9546b202014-07-02 17:21:51 -07005099 @Override
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005100 public void setUserRotationMode(int mode, int rot) {
5101 ContentResolver res = mContext.getContentResolver();
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005102
5103 // mUserRotationMode and mUserRotation will be assigned by the content observer
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005104 if (mode == WindowManagerPolicy.USER_ROTATION_LOCKED) {
Christopher Tate5e08af02012-09-21 17:17:22 -07005105 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005106 Settings.System.USER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005107 rot,
5108 UserHandle.USER_CURRENT);
5109 Settings.System.putIntForUser(res,
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005110 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005111 0,
5112 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005113 } else {
Christopher Tate5e08af02012-09-21 17:17:22 -07005114 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005115 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005116 1,
5117 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005118 }
5119 }
5120
Jose Lima9546b202014-07-02 17:21:51 -07005121 @Override
Jeff Brownac143512012-04-05 18:57:33 -07005122 public void setSafeMode(boolean safeMode) {
5123 mSafeMode = safeMode;
5124 performHapticFeedbackLw(null, safeMode
5125 ? HapticFeedbackConstants.SAFE_MODE_ENABLED
5126 : HapticFeedbackConstants.SAFE_MODE_DISABLED, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005127 }
Craig Mautnereda67292013-04-28 13:50:14 -07005128
Dianne Hackborn181ceb52009-08-27 22:16:40 -07005129 static long[] getLongIntArray(Resources r, int resid) {
5130 int[] ar = r.getIntArray(resid);
5131 if (ar == null) {
5132 return null;
5133 }
5134 long[] out = new long[ar.length];
5135 for (int i=0; i<ar.length; i++) {
5136 out[i] = ar[i];
5137 }
5138 return out;
5139 }
Craig Mautnereda67292013-04-28 13:50:14 -07005140
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005141 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07005142 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005143 public void systemReady() {
Mike Lockwooded8902d2013-11-15 11:01:47 -08005144 mKeyguardDelegate = new KeyguardServiceDelegate(mContext, null);
5145 mKeyguardDelegate.onSystemReady();
5146
Jeff Brown4f5fa282014-06-12 19:19:15 -07005147 updateUiMode();
Dianne Hackbornb1a79802009-09-29 15:18:31 -07005148 synchronized (mLock) {
5149 updateOrientationListenerLp();
Dianne Hackbornc777e072010-02-12 13:07:59 -08005150 mSystemReady = true;
5151 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07005152 @Override
Dianne Hackbornc777e072010-02-12 13:07:59 -08005153 public void run() {
5154 updateSettings();
5155 }
5156 });
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005157 }
5158 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07005159
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005160 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005161 @Override
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005162 public void systemBooted() {
Jim Millere5f910a2013-10-16 18:15:46 -07005163 if (mKeyguardDelegate != null) {
5164 mKeyguardDelegate.onBootCompleted();
5165 }
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005166 synchronized (mLock) {
5167 mSystemBooted = true;
5168 }
Craig Mautner8a0da012014-05-31 15:13:37 -07005169 wakingUp(null);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005170 }
5171
Dianne Hackborn661cd522011-08-22 00:26:20 -07005172 ProgressDialog mBootMsgDialog = null;
5173
5174 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005175 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07005176 public void showBootMessage(final CharSequence msg, final boolean always) {
5177 mHandler.post(new Runnable() {
5178 @Override public void run() {
5179 if (mBootMsgDialog == null) {
Craig Stout4c0cb8a2014-04-04 13:03:10 -07005180 int theme;
5181 if (mContext.getPackageManager().hasSystemFeature(
5182 PackageManager.FEATURE_WATCH)) {
5183 theme = com.android.internal.R.style.Theme_Micro_Dialog_Alert;
5184 } else if (mContext.getPackageManager().hasSystemFeature(
5185 PackageManager.FEATURE_TELEVISION)) {
5186 theme = com.android.internal.R.style.Theme_Leanback_Dialog_Alert;
5187 } else {
5188 theme = 0;
5189 }
Vinod Krishnanfa8fc412014-04-18 14:35:53 -07005190
5191 mBootMsgDialog = new ProgressDialog(mContext, theme) {
Dianne Hackborn295e3c22011-08-25 13:19:08 -07005192 // This dialog will consume all events coming in to
5193 // it, to avoid it trying to do things too early in boot.
5194 @Override public boolean dispatchKeyEvent(KeyEvent event) {
5195 return true;
5196 }
5197 @Override public boolean dispatchKeyShortcutEvent(KeyEvent event) {
5198 return true;
5199 }
5200 @Override public boolean dispatchTouchEvent(MotionEvent ev) {
5201 return true;
5202 }
5203 @Override public boolean dispatchTrackballEvent(MotionEvent ev) {
5204 return true;
5205 }
5206 @Override public boolean dispatchGenericMotionEvent(MotionEvent ev) {
5207 return true;
5208 }
5209 @Override public boolean dispatchPopulateAccessibilityEvent(
5210 AccessibilityEvent event) {
5211 return true;
5212 }
5213 };
Dianne Hackborn661cd522011-08-22 00:26:20 -07005214 mBootMsgDialog.setTitle(R.string.android_upgrading_title);
5215 mBootMsgDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
5216 mBootMsgDialog.setIndeterminate(true);
5217 mBootMsgDialog.getWindow().setType(
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07005218 WindowManager.LayoutParams.TYPE_BOOT_PROGRESS);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005219 mBootMsgDialog.getWindow().addFlags(
5220 WindowManager.LayoutParams.FLAG_DIM_BEHIND
5221 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
5222 mBootMsgDialog.getWindow().setDimAmount(1);
Dianne Hackbornd9efb952011-12-07 14:56:51 -08005223 WindowManager.LayoutParams lp = mBootMsgDialog.getWindow().getAttributes();
5224 lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
5225 mBootMsgDialog.getWindow().setAttributes(lp);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005226 mBootMsgDialog.setCancelable(false);
5227 mBootMsgDialog.show();
5228 }
5229 mBootMsgDialog.setMessage(msg);
5230 }
5231 });
5232 }
5233
5234 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005235 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07005236 public void hideBootMessages() {
Craig Mautnera631d492014-08-05 15:16:01 -07005237 mHandler.sendEmptyMessage(MSG_HIDE_BOOT_MESSAGE);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005238 }
5239
Mike Lockwood28569302010-01-28 11:54:40 -05005240 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005241 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05005242 public void userActivity() {
Dianne Hackborndf89e652011-10-06 22:35:11 -07005243 // ***************************************
5244 // NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
5245 // ***************************************
5246 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
5247 // WITH ITS LOCKS HELD.
5248 //
5249 // This code must be VERY careful about the locks
5250 // it acquires.
5251 // In fact, the current code acquires way too many,
5252 // and probably has lurking deadlocks.
5253
Mike Lockwood28569302010-01-28 11:54:40 -05005254 synchronized (mScreenLockTimeout) {
5255 if (mLockScreenTimerActive) {
5256 // reset the timer
5257 mHandler.removeCallbacks(mScreenLockTimeout);
5258 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
5259 }
5260 }
Daniel Sandler0601eb72011-04-13 01:01:32 -04005261 }
5262
Adam Cohenf7522022012-10-03 20:03:18 -07005263 class ScreenLockTimeout implements Runnable {
5264 Bundle options;
5265
5266 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05005267 public void run() {
5268 synchronized (this) {
5269 if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard");
Jim Miller5ecd8112013-01-09 18:50:26 -08005270 if (mKeyguardDelegate != null) {
5271 mKeyguardDelegate.doKeyguardTimeout(options);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005272 }
Mike Lockwood28569302010-01-28 11:54:40 -05005273 mLockScreenTimerActive = false;
Adam Cohenf7522022012-10-03 20:03:18 -07005274 options = null;
Mike Lockwood28569302010-01-28 11:54:40 -05005275 }
5276 }
Mike Lockwood28569302010-01-28 11:54:40 -05005277
Adam Cohenf7522022012-10-03 20:03:18 -07005278 public void setLockOptions(Bundle options) {
5279 this.options = options;
5280 }
5281 }
5282
5283 ScreenLockTimeout mScreenLockTimeout = new ScreenLockTimeout();
5284
Jose Lima9546b202014-07-02 17:21:51 -07005285 @Override
Adam Cohenf7522022012-10-03 20:03:18 -07005286 public void lockNow(Bundle options) {
Jim Miller93c518e2012-01-17 15:55:31 -08005287 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null);
5288 mHandler.removeCallbacks(mScreenLockTimeout);
Adam Cohenf7522022012-10-03 20:03:18 -07005289 if (options != null) {
5290 // In case multiple calls are made to lockNow, we don't wipe out the options
5291 // until the runnable actually executes.
5292 mScreenLockTimeout.setLockOptions(options);
5293 }
Jim Miller93c518e2012-01-17 15:55:31 -08005294 mHandler.post(mScreenLockTimeout);
5295 }
5296
Mike Lockwood28569302010-01-28 11:54:40 -05005297 private void updateLockScreenTimeout() {
5298 synchronized (mScreenLockTimeout) {
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005299 boolean enable = (mAllowLockscreenWhenOn && mScreenOnEarly &&
Jim Miller5ecd8112013-01-09 18:50:26 -08005300 mKeyguardDelegate != null && mKeyguardDelegate.isSecure());
Mike Lockwood28569302010-01-28 11:54:40 -05005301 if (mLockScreenTimerActive != enable) {
5302 if (enable) {
5303 if (localLOGV) Log.v(TAG, "setting lockscreen timer");
5304 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
5305 } else {
5306 if (localLOGV) Log.v(TAG, "clearing lockscreen timer");
5307 mHandler.removeCallbacks(mScreenLockTimeout);
5308 }
5309 mLockScreenTimerActive = enable;
5310 }
5311 }
5312 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005313
5314 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07005315 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005316 public void enableScreenAfterBoot() {
5317 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07005318 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07005319 updateRotation(true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005320 }
Dianne Hackbornf54c8f92009-09-19 14:03:57 -07005321
Jeff Brownc458ce92012-04-30 14:58:40 -07005322 private void applyLidSwitchState() {
Jeff Brownc458ce92012-04-30 14:58:40 -07005323 if (mLidState == LID_CLOSED && mLidControlsSleep) {
Jeff Brown6d8fd272014-05-20 21:24:38 -07005324 mPowerManager.goToSleep(SystemClock.uptimeMillis(),
Jeff Brownc12035c2014-08-13 18:52:25 -07005325 PowerManager.GO_TO_SLEEP_REASON_LID_SWITCH,
Jeff Brown6d8fd272014-05-20 21:24:38 -07005326 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
Jeff Brownc458ce92012-04-30 14:58:40 -07005327 }
Jeff Browna20dda42014-05-27 20:57:24 -07005328
5329 synchronized (mLock) {
5330 updateWakeGestureListenerLp();
5331 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005332 }
5333
Jeff Brown4f5fa282014-06-12 19:19:15 -07005334 void updateUiMode() {
5335 if (mUiModeManager == null) {
5336 mUiModeManager = IUiModeManager.Stub.asInterface(
5337 ServiceManager.getService(Context.UI_MODE_SERVICE));
5338 }
5339 try {
5340 mUiMode = mUiModeManager.getCurrentModeType();
5341 } catch (RemoteException e) {
5342 }
5343 }
5344
Jeff Brown01a98dd2011-09-20 15:08:29 -07005345 void updateRotation(boolean alwaysSendConfiguration) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005346 try {
5347 //set orientation on WindowManager
Dianne Hackbornf87d1962012-04-04 12:48:24 -07005348 mWindowManager.updateRotation(alwaysSendConfiguration, false);
5349 } catch (RemoteException e) {
5350 // Ignore
5351 }
5352 }
5353
5354 void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) {
5355 try {
5356 //set orientation on WindowManager
5357 mWindowManager.updateRotation(alwaysSendConfiguration, forceRelayout);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005358 } catch (RemoteException e) {
5359 // Ignore
5360 }
5361 }
5362
Daniel Sandler6396c722013-04-16 20:19:09 -04005363 /**
5364 * Return an Intent to launch the currently active dock app as home. Returns
5365 * null if the standard home should be launched, which is the case if any of the following is
5366 * true:
5367 * <ul>
5368 * <li>The device is not in either car mode or desk mode
5369 * <li>The device is in car mode but ENABLE_CAR_DOCK_HOME_CAPTURE is false
5370 * <li>The device is in desk mode but ENABLE_DESK_DOCK_HOME_CAPTURE is false
5371 * <li>The device is in car mode but there's no CAR_DOCK app with METADATA_DOCK_HOME
5372 * <li>The device is in desk mode but there's no DESK_DOCK app with METADATA_DOCK_HOME
5373 * </ul>
Craig Mautnereda67292013-04-28 13:50:14 -07005374 * @return A dock intent.
Daniel Sandler6396c722013-04-16 20:19:09 -04005375 */
5376 Intent createHomeDockIntent() {
5377 Intent intent = null;
5378
5379 // What home does is based on the mode, not the dock state. That
5380 // is, when in car mode you should be taken to car home regardless
5381 // of whether we are actually in a car dock.
5382 if (mUiMode == Configuration.UI_MODE_TYPE_CAR) {
5383 if (ENABLE_CAR_DOCK_HOME_CAPTURE) {
5384 intent = mCarDockIntent;
5385 }
5386 } else if (mUiMode == Configuration.UI_MODE_TYPE_DESK) {
5387 if (ENABLE_DESK_DOCK_HOME_CAPTURE) {
5388 intent = mDeskDockIntent;
5389 }
Jeff Brown4f5fa282014-06-12 19:19:15 -07005390 } else if (mUiMode == Configuration.UI_MODE_TYPE_WATCH
5391 && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
5392 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK
5393 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK)) {
5394 // Always launch dock home from home when watch is docked, if it exists.
5395 intent = mDeskDockIntent;
Daniel Sandler6396c722013-04-16 20:19:09 -04005396 }
5397
5398 if (intent == null) {
5399 return null;
5400 }
5401
5402 ActivityInfo ai = null;
5403 ResolveInfo info = mContext.getPackageManager().resolveActivityAsUser(
5404 intent,
John Spurlockf56bef12013-07-09 09:51:46 -04005405 PackageManager.MATCH_DEFAULT_ONLY | PackageManager.GET_META_DATA,
Craig Mautnerd625ab22013-09-06 13:40:31 -07005406 mCurrentUserId);
Daniel Sandler6396c722013-04-16 20:19:09 -04005407 if (info != null) {
5408 ai = info.activityInfo;
5409 }
5410 if (ai != null
5411 && ai.metaData != null
5412 && ai.metaData.getBoolean(Intent.METADATA_DOCK_HOME)) {
5413 intent = new Intent(intent);
5414 intent.setClassName(ai.packageName, ai.name);
5415 return intent;
5416 }
5417
5418 return null;
5419 }
5420
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005421 void startDockOrHome() {
John Spurlockc8b46ca2013-04-08 12:59:26 -04005422 awakenDreams();
Daniel Sandler6396c722013-04-16 20:19:09 -04005423
5424 Intent dock = createHomeDockIntent();
5425 if (dock != null) {
5426 try {
5427 mContext.startActivityAsUser(dock, UserHandle.CURRENT);
5428 return;
5429 } catch (ActivityNotFoundException e) {
5430 }
5431 }
5432
Dianne Hackbornd8883992012-09-07 15:58:52 -07005433 mContext.startActivityAsUser(mHomeIntent, UserHandle.CURRENT);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005434 }
Craig Mautnereda67292013-04-28 13:50:14 -07005435
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005436 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005437 * goes to the home screen
5438 * @return whether it did anything
5439 */
5440 boolean goHome() {
5441 if (false) {
5442 // This code always brings home to the front.
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07005443 try {
5444 ActivityManagerNative.getDefault().stopAppSwitches();
5445 } catch (RemoteException e) {
5446 }
Dianne Hackborn94a679d2009-07-28 17:51:07 -07005447 sendCloseSystemWindows();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005448 startDockOrHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005449 } else {
5450 // This code brings home to the front or, if it is already
5451 // at the front, puts the device to sleep.
5452 try {
Wink Savilled2e6a332010-02-12 12:12:06 -08005453 if (SystemProperties.getInt("persist.sys.uts-test-mode", 0) == 1) {
5454 /// Roll back EndcallBehavior as the cupcake design to pass P1 lab entry.
5455 Log.d(TAG, "UTS-TEST-MODE");
5456 } else {
5457 ActivityManagerNative.getDefault().stopAppSwitches();
5458 sendCloseSystemWindows();
Daniel Sandler6396c722013-04-16 20:19:09 -04005459 Intent dock = createHomeDockIntent();
5460 if (dock != null) {
5461 int result = ActivityManagerNative.getDefault()
5462 .startActivityAsUser(null, null, dock,
5463 dock.resolveTypeIfNeeded(mContext.getContentResolver()),
5464 null, null, 0,
5465 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07005466 null, null, UserHandle.USER_CURRENT);
Daniel Sandler6396c722013-04-16 20:19:09 -04005467 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
5468 return false;
5469 }
5470 }
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005471 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005472 int result = ActivityManagerNative.getDefault()
Dianne Hackbornf265ea92013-01-31 15:00:51 -08005473 .startActivityAsUser(null, null, mHomeIntent,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005474 mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()),
Dianne Hackborna4972e92012-03-14 10:38:05 -07005475 null, null, 0,
5476 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07005477 null, null, UserHandle.USER_CURRENT);
Dianne Hackborna4972e92012-03-14 10:38:05 -07005478 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005479 return false;
5480 }
5481 } catch (RemoteException ex) {
5482 // bummer, the activity manager, which is in this process, is dead
5483 }
5484 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005485 return true;
5486 }
Craig Mautnereda67292013-04-28 13:50:14 -07005487
5488 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07005489 public void setCurrentOrientationLw(int newOrientation) {
5490 synchronized (mLock) {
5491 if (newOrientation != mCurrentAppOrientation) {
5492 mCurrentAppOrientation = newOrientation;
5493 updateOrientationListenerLp();
5494 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005495 }
5496 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08005497
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07005498 private void performAuditoryFeedbackForAccessibilityIfNeed() {
5499 if (!isGlobalAccessibilityGestureEnabled()) {
5500 return;
5501 }
5502 AudioManager audioManager = (AudioManager) mContext.getSystemService(
5503 Context.AUDIO_SERVICE);
5504 if (audioManager.isSilentMode()) {
5505 return;
5506 }
5507 Ringtone ringTone = RingtoneManager.getRingtone(mContext,
5508 Settings.System.DEFAULT_NOTIFICATION_URI);
5509 ringTone.setStreamType(AudioManager.STREAM_MUSIC);
5510 ringTone.play();
5511 }
Craig Mautnereda67292013-04-28 13:50:14 -07005512
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07005513 private boolean isGlobalAccessibilityGestureEnabled() {
5514 return Settings.Global.getInt(mContext.getContentResolver(),
5515 Settings.Global.ENABLE_ACCESSIBILITY_GLOBAL_GESTURE_ENABLED, 0) == 1;
5516 }
5517
Craig Mautnereda67292013-04-28 13:50:14 -07005518 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07005519 public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) {
Svetoslav Ganov96179212012-10-10 14:17:45 -07005520 if (!mVibrator.hasVibrator()) {
5521 return false;
5522 }
Christopher Tate5e08af02012-09-21 17:17:22 -07005523 final boolean hapticsDisabled = Settings.System.getIntForUser(mContext.getContentResolver(),
5524 Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) == 0;
Jeff Brown82379ba2014-07-25 19:03:28 -07005525 if (hapticsDisabled && !always) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005526 return false;
5527 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08005528 long[] pattern = null;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005529 switch (effectId) {
5530 case HapticFeedbackConstants.LONG_PRESS:
Amith Yamasanic33cb712010-02-10 15:21:49 -08005531 pattern = mLongPressVibePattern;
5532 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07005533 case HapticFeedbackConstants.VIRTUAL_KEY:
Amith Yamasanic33cb712010-02-10 15:21:49 -08005534 pattern = mVirtualKeyVibePattern;
5535 break;
5536 case HapticFeedbackConstants.KEYBOARD_TAP:
5537 pattern = mKeyboardTapVibePattern;
5538 break;
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07005539 case HapticFeedbackConstants.CLOCK_TICK:
5540 pattern = mClockTickVibePattern;
5541 break;
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07005542 case HapticFeedbackConstants.CALENDAR_DATE:
5543 pattern = mCalendarDateVibePattern;
5544 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07005545 case HapticFeedbackConstants.SAFE_MODE_DISABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08005546 pattern = mSafeModeDisabledVibePattern;
5547 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07005548 case HapticFeedbackConstants.SAFE_MODE_ENABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08005549 pattern = mSafeModeEnabledVibePattern;
5550 break;
Amith Yamasanic33cb712010-02-10 15:21:49 -08005551 default:
5552 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005553 }
Dianne Hackbornf265ea92013-01-31 15:00:51 -08005554 int owningUid;
5555 String owningPackage;
5556 if (win != null) {
5557 owningUid = win.getOwningUid();
5558 owningPackage = win.getOwningPackage();
5559 } else {
5560 owningUid = android.os.Process.myUid();
Dianne Hackborn95d78532013-09-11 09:51:14 -07005561 owningPackage = mContext.getOpPackageName();
Dianne Hackbornf265ea92013-01-31 15:00:51 -08005562 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08005563 if (pattern.length == 1) {
5564 // One-shot vibration
John Spurlock7b414672014-07-18 13:02:39 -04005565 mVibrator.vibrate(owningUid, owningPackage, pattern[0], VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08005566 } else {
5567 // Pattern vibration
John Spurlock7b414672014-07-18 13:02:39 -04005568 mVibrator.vibrate(owningUid, owningPackage, pattern, -1, VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08005569 }
5570 return true;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005571 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005572
5573 @Override
5574 public void keepScreenOnStartedLw() {
Daniel Sandler0601eb72011-04-13 01:01:32 -04005575 }
5576
Jeff Brownc38c9be2012-10-04 13:16:19 -07005577 @Override
5578 public void keepScreenOnStoppedLw() {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01005579 if (mKeyguardDelegate != null && !mKeyguardDelegate.isShowingAndNotOccluded()) {
Jim Miller25190572013-02-28 17:36:24 -08005580 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005581 }
5582 }
Mike Lockwoodfcb39242009-10-21 23:01:07 -04005583
Dianne Hackborndf89e652011-10-06 22:35:11 -07005584 private int updateSystemUiVisibilityLw() {
Joe Onorato664644d2011-01-23 17:53:23 -08005585 // If there is no window focused, there will be nobody to handle the events
5586 // anyway, so just hang on in whatever state we're in until things settle down.
John Spurlock79da8332013-09-20 12:04:47 -04005587 WindowState win = mFocusedWindow != null ? mFocusedWindow : mTopFullscreenOpaqueWindowState;
5588 if (win == null) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07005589 return 0;
5590 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01005591 if ((win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 && mHideLockScreen == true) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07005592 // We are updating at a point where the keyguard has gotten
5593 // focus, but we were last in a state where the top window is
5594 // hiding it. This is probably because the keyguard as been
5595 // shown while the top window was displayed, so we want to ignore
5596 // it here because this is just a very transient change and it
5597 // will quickly lose focus once it correctly gets hidden.
5598 return 0;
5599 }
John Spurlock32beb2c2013-03-11 10:16:47 -04005600
John Spurlock1db8b682014-02-18 11:18:59 -05005601 int tmpVisibility = PolicyControl.getSystemUiVisibility(win, null)
Dianne Hackborne26ab702011-10-16 13:21:33 -07005602 & ~mResettingSystemUiFlags
5603 & ~mForceClearedSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04005604 if (mForcingShowNavBar && win.getSurfaceLayer() < mForcingShowNavBarLayer) {
John Spurlockc6d1c602014-01-17 15:22:06 -05005605 tmpVisibility &= ~PolicyControl.adjustClearableFlags(win, View.SYSTEM_UI_CLEARABLE_FLAGS);
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08005606 }
John Spurlock79da8332013-09-20 12:04:47 -04005607 final int visibility = updateSystemBarsLw(win, mLastSystemUiFlags, tmpVisibility);
John Spurlockad3e6cb2013-04-30 08:47:43 -04005608 final int diff = visibility ^ mLastSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04005609 final boolean needsMenu = win.getNeedsMenuLw(mTopFullscreenOpaqueWindowState);
Dianne Hackborne0f085d2011-11-30 18:41:15 -08005610 if (diff == 0 && mLastFocusNeedsMenu == needsMenu
John Spurlock79da8332013-09-20 12:04:47 -04005611 && mFocusedApp == win.getAppToken()) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07005612 return 0;
5613 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07005614 mLastSystemUiFlags = visibility;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08005615 mLastFocusNeedsMenu = needsMenu;
John Spurlock79da8332013-09-20 12:04:47 -04005616 mFocusedApp = win.getAppToken();
Dianne Hackborndf89e652011-10-06 22:35:11 -07005617 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07005618 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07005619 public void run() {
Dianne Hackborn42e620c2012-06-24 13:20:51 -07005620 try {
5621 IStatusBarService statusbar = getStatusBarService();
5622 if (statusbar != null) {
5623 statusbar.setSystemUiVisibility(visibility, 0xffffffff);
5624 statusbar.topAppWindowChanged(needsMenu);
Joe Onorato664644d2011-01-23 17:53:23 -08005625 }
Dianne Hackborn42e620c2012-06-24 13:20:51 -07005626 } catch (RemoteException e) {
5627 // re-acquire status bar service next time it is needed.
5628 mStatusBarService = null;
Joe Onorato664644d2011-01-23 17:53:23 -08005629 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07005630 }
5631 });
5632 return diff;
Joe Onorato664644d2011-01-23 17:53:23 -08005633 }
5634
John Spurlock79da8332013-09-20 12:04:47 -04005635 private int updateSystemBarsLw(WindowState win, int oldVis, int vis) {
John Spurlockbd957402013-10-03 11:38:39 -04005636 // apply translucent bar vis flags
Jorim Jaggi380ecb82014-03-14 17:25:20 +01005637 WindowState transWin = isStatusBarKeyguard() && !mHideLockScreen
5638 ? mStatusBar
John Spurlockbd957402013-10-03 11:38:39 -04005639 : mTopFullscreenOpaqueWindowState;
5640 vis = mStatusBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
5641 vis = mNavigationBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
5642
John Spurlock27735a42013-08-14 17:57:38 -04005643 // prevent status bar interaction from clearing certain flags
John Spurlock79da8332013-09-20 12:04:47 -04005644 boolean statusBarHasFocus = win.getAttrs().type == TYPE_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04005645 if (statusBarHasFocus && !isStatusBarKeyguard()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04005646 int flags = View.SYSTEM_UI_FLAG_FULLSCREEN
5647 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlockcfc359a2013-09-05 10:42:03 -04005648 | View.SYSTEM_UI_FLAG_IMMERSIVE
Jorim Jaggi5cf17872014-03-26 18:31:48 +01005649 | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
John Spurlock08ffcf52014-07-11 10:13:46 -04005650 if (mHideLockScreen) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01005651 flags |= View.STATUS_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSLUCENT;
5652 }
John Spurlockbd957402013-10-03 11:38:39 -04005653 vis = (vis & ~flags) | (oldVis & flags);
John Spurlockad3e6cb2013-04-30 08:47:43 -04005654 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04005655
Adrian Roos4fb3ee32014-08-22 19:29:09 +02005656 if (!areTranslucentBarsAllowed() && transWin != mStatusBar) {
Adrian Roosea562512014-05-05 13:33:03 +02005657 vis &= ~(View.NAVIGATION_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSLUCENT
5658 | View.SYSTEM_UI_TRANSPARENT);
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07005659 }
5660
John Spurlock27735a42013-08-14 17:57:38 -04005661 // update status bar
John Spurlockf1a36642013-10-12 17:50:42 -04005662 boolean immersiveSticky =
5663 (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
John Spurlock27735a42013-08-14 17:57:38 -04005664 boolean hideStatusBarWM =
John Spurlockbd957402013-10-03 11:38:39 -04005665 mTopFullscreenOpaqueWindowState != null &&
John Spurlockc6d1c602014-01-17 15:22:06 -05005666 (PolicyControl.getWindowFlags(mTopFullscreenOpaqueWindowState, null)
John Spurlock27735a42013-08-14 17:57:38 -04005667 & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0;
5668 boolean hideStatusBarSysui =
5669 (vis & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04005670 boolean hideNavBarSysui =
5671 (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0;
John Spurlockad3e6cb2013-04-30 08:47:43 -04005672
John Spurlock27735a42013-08-14 17:57:38 -04005673 boolean transientStatusBarAllowed =
5674 mStatusBar != null && (
5675 hideStatusBarWM
John Spurlockf1a36642013-10-12 17:50:42 -04005676 || (hideStatusBarSysui && immersiveSticky)
John Spurlock27735a42013-08-14 17:57:38 -04005677 || statusBarHasFocus);
5678
John Spurlockf1a36642013-10-12 17:50:42 -04005679 boolean transientNavBarAllowed =
5680 mNavigationBar != null &&
5681 hideNavBarSysui && immersiveSticky;
5682
John Spurlockf25706f2013-11-07 18:02:43 -05005683 boolean denyTransientStatus = mStatusBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04005684 && !transientStatusBarAllowed && hideStatusBarSysui;
John Spurlockf25706f2013-11-07 18:02:43 -05005685 boolean denyTransientNav = mNavigationBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04005686 && !transientNavBarAllowed;
5687 if (denyTransientStatus || denyTransientNav) {
John Spurlock27735a42013-08-14 17:57:38 -04005688 // clear the clearable flags instead
John Spurlockf1a36642013-10-12 17:50:42 -04005689 clearClearableFlagsLw();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005690 }
John Spurlock27735a42013-08-14 17:57:38 -04005691
5692 vis = mStatusBarController.updateVisibilityLw(transientStatusBarAllowed, oldVis, vis);
5693
5694 // update navigation bar
John Spurlockf1a36642013-10-12 17:50:42 -04005695 boolean oldImmersiveMode = isImmersiveMode(oldVis);
5696 boolean newImmersiveMode = isImmersiveMode(vis);
5697 if (win != null && oldImmersiveMode != newImmersiveMode) {
John Spurlock79da8332013-09-20 12:04:47 -04005698 final String pkg = win.getOwningPackage();
Maurice Lam99c6e072014-04-28 18:24:28 -07005699 mImmersiveModeConfirmation.immersiveModeChanged(pkg, newImmersiveMode,
5700 isUserSetupComplete());
John Spurlock34e13d92013-08-10 06:52:28 -04005701 }
John Spurlock27735a42013-08-14 17:57:38 -04005702
John Spurlockf1a36642013-10-12 17:50:42 -04005703 vis = mNavigationBarController.updateVisibilityLw(transientNavBarAllowed, oldVis, vis);
5704
John Spurlocke1f366f2013-08-05 12:22:40 -04005705 return vis;
John Spurlockad3e6cb2013-04-30 08:47:43 -04005706 }
5707
John Spurlockf1a36642013-10-12 17:50:42 -04005708 private void clearClearableFlagsLw() {
5709 int newVal = mResettingSystemUiFlags | View.SYSTEM_UI_CLEARABLE_FLAGS;
5710 if (newVal != mResettingSystemUiFlags) {
5711 mResettingSystemUiFlags = newVal;
5712 mWindowManagerFuncs.reevaluateStatusBarVisibility();
5713 }
5714 }
5715
5716 private boolean isImmersiveMode(int vis) {
5717 final int flags = View.SYSTEM_UI_FLAG_IMMERSIVE | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
John Spurlock34e13d92013-08-10 06:52:28 -04005718 return mNavigationBar != null
5719 && (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0
Daniel Sandler900ece52013-10-18 15:53:27 -04005720 && (vis & flags) != 0
5721 && canHideNavigationBar();
John Spurlock34e13d92013-08-10 06:52:28 -04005722 }
5723
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07005724 /**
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04005725 * @return whether the navigation or status bar can be made translucent
5726 *
5727 * This should return true unless touch exploration is not enabled or
5728 * R.boolean.config_enableTranslucentDecor is false.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07005729 */
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04005730 private boolean areTranslucentBarsAllowed() {
Svetoslav8e3feb12014-02-24 13:46:47 -08005731 return mTranslucentDecorEnabled
5732 && !mAccessibilityManager.isTouchExplorationEnabled();
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07005733 }
5734
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04005735 // Use this instead of checking config_showNavigationBar so that it can be consistently
5736 // overridden by qemu.hw.mainkeys in the emulator.
Craig Mautnereda67292013-04-28 13:50:14 -07005737 @Override
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04005738 public boolean hasNavigationBar() {
5739 return mHasNavigationBar;
5740 }
5741
satok1bc0a492012-04-25 22:47:12 +09005742 @Override
5743 public void setLastInputMethodWindowLw(WindowState ime, WindowState target) {
5744 mLastInputMethodWindow = ime;
5745 mLastInputMethodTargetWindow = target;
5746 }
5747
Craig Mautnerf1b67412012-09-19 13:18:29 -07005748 @Override
Satoshi Kataoka658c7b82013-10-10 17:03:51 +09005749 public int getInputMethodWindowVisibleHeightLw() {
5750 return mDockBottom - mCurBottom;
5751 }
5752
5753 @Override
Craig Mautnerf1b67412012-09-19 13:18:29 -07005754 public void setCurrentUserLw(int newUserId) {
Craig Mautnerd625ab22013-09-06 13:40:31 -07005755 mCurrentUserId = newUserId;
Jim Miller5ecd8112013-01-09 18:50:26 -08005756 if (mKeyguardDelegate != null) {
5757 mKeyguardDelegate.setCurrentUser(newUserId);
Craig Mautnerf1b67412012-09-19 13:18:29 -07005758 }
John Spurlock13451a22012-09-28 14:40:41 -04005759 if (mStatusBarService != null) {
5760 try {
5761 mStatusBarService.setCurrentUser(newUserId);
5762 } catch (RemoteException e) {
5763 // oh well
5764 }
5765 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07005766 setLastInputMethodWindowLw(null, null);
Craig Mautnerf1b67412012-09-19 13:18:29 -07005767 }
5768
5769 @Override
Svetoslav Ganov545252f2012-12-10 18:29:24 -08005770 public boolean canMagnifyWindow(int windowType) {
5771 switch (windowType) {
5772 case WindowManager.LayoutParams.TYPE_INPUT_METHOD:
5773 case WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG:
5774 case WindowManager.LayoutParams.TYPE_NAVIGATION_BAR:
5775 case WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY: {
5776 return false;
5777 }
5778 }
5779 return true;
5780 }
5781
5782 @Override
5783 public boolean isTopLevelWindow(int windowType) {
5784 if (windowType >= WindowManager.LayoutParams.FIRST_SUB_WINDOW
5785 && windowType <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
5786 return (windowType == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG);
5787 }
5788 return true;
5789 }
5790
Jim Miller4eeb4f62012-11-08 00:04:29 -08005791 @Override
Jeff Brownd7a04de2012-06-17 14:17:52 -07005792 public void dump(String prefix, PrintWriter pw, String[] args) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005793 pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005794 pw.print(" mSystemReady="); pw.print(mSystemReady);
5795 pw.print(" mSystemBooted="); pw.println(mSystemBooted);
Jeff Brown2e7760e2012-04-11 15:14:55 -07005796 pw.print(prefix); pw.print("mLidState="); pw.print(mLidState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005797 pw.print(" mLidOpenRotation="); pw.print(mLidOpenRotation);
5798 pw.print(" mHdmiPlugged="); pw.println(mHdmiPlugged);
Dianne Hackborne26ab702011-10-16 13:21:33 -07005799 if (mLastSystemUiFlags != 0 || mResettingSystemUiFlags != 0
5800 || mForceClearedSystemUiFlags != 0) {
5801 pw.print(prefix); pw.print("mLastSystemUiFlags=0x");
5802 pw.print(Integer.toHexString(mLastSystemUiFlags));
5803 pw.print(" mResettingSystemUiFlags=0x");
5804 pw.print(Integer.toHexString(mResettingSystemUiFlags));
5805 pw.print(" mForceClearedSystemUiFlags=0x");
5806 pw.println(Integer.toHexString(mForceClearedSystemUiFlags));
Dianne Hackborndf89e652011-10-06 22:35:11 -07005807 }
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08005808 if (mLastFocusNeedsMenu) {
5809 pw.print(prefix); pw.print("mLastFocusNeedsMenu=");
5810 pw.println(mLastFocusNeedsMenu);
5811 }
Jeff Browna20dda42014-05-27 20:57:24 -07005812 pw.print(prefix); pw.print("mWakeGestureEnabledSetting=");
5813 pw.println(mWakeGestureEnabledSetting);
5814
Jeff Brownbcdfc622014-03-06 19:13:04 -08005815 pw.print(prefix); pw.print("mSupportAutoRotation="); pw.println(mSupportAutoRotation);
Daniel Sandler6396c722013-04-16 20:19:09 -04005816 pw.print(prefix); pw.print("mUiMode="); pw.print(mUiMode);
5817 pw.print(" mDockMode="); pw.print(mDockMode);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005818 pw.print(" mCarDockRotation="); pw.print(mCarDockRotation);
5819 pw.print(" mDeskDockRotation="); pw.println(mDeskDockRotation);
5820 pw.print(prefix); pw.print("mUserRotationMode="); pw.print(mUserRotationMode);
5821 pw.print(" mUserRotation="); pw.print(mUserRotation);
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005822 pw.print(" mAllowAllRotations="); pw.println(mAllowAllRotations);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07005823 pw.print(prefix); pw.print("mCurrentAppOrientation="); pw.println(mCurrentAppOrientation);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005824 pw.print(prefix); pw.print("mCarDockEnablesAccelerometer=");
5825 pw.print(mCarDockEnablesAccelerometer);
5826 pw.print(" mDeskDockEnablesAccelerometer=");
5827 pw.println(mDeskDockEnablesAccelerometer);
5828 pw.print(prefix); pw.print("mLidKeyboardAccessibility=");
5829 pw.print(mLidKeyboardAccessibility);
5830 pw.print(" mLidNavigationAccessibility="); pw.print(mLidNavigationAccessibility);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07005831 pw.print(" mLidControlsSleep="); pw.println(mLidControlsSleep);
Jeff Brown6d8fd272014-05-20 21:24:38 -07005832 pw.print(prefix);
5833 pw.print("mShortPressOnPowerBehavior="); pw.print(mShortPressOnPowerBehavior);
5834 pw.print(" mLongPressOnPowerBehavior="); pw.println(mLongPressOnPowerBehavior);
5835 pw.print(prefix); pw.print("mHasSoftInput="); pw.println(mHasSoftInput);
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07005836 pw.print(prefix); pw.print("mScreenOnEarly="); pw.print(mScreenOnEarly);
5837 pw.print(" mScreenOnFully="); pw.print(mScreenOnFully);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07005838 pw.print(" mOrientationSensorEnabled="); pw.println(mOrientationSensorEnabled);
Dianne Hackbornc652de82013-02-15 16:32:56 -08005839 pw.print(prefix); pw.print("mOverscanScreen=("); pw.print(mOverscanScreenLeft);
5840 pw.print(","); pw.print(mOverscanScreenTop);
5841 pw.print(") "); pw.print(mOverscanScreenWidth);
5842 pw.print("x"); pw.println(mOverscanScreenHeight);
5843 if (mOverscanLeft != 0 || mOverscanTop != 0
5844 || mOverscanRight != 0 || mOverscanBottom != 0) {
5845 pw.print(prefix); pw.print("mOverscan left="); pw.print(mOverscanLeft);
5846 pw.print(" top="); pw.print(mOverscanTop);
5847 pw.print(" right="); pw.print(mOverscanRight);
5848 pw.print(" bottom="); pw.println(mOverscanBottom);
5849 }
Dianne Hackborn313440842013-02-19 19:22:59 -08005850 pw.print(prefix); pw.print("mRestrictedOverscanScreen=(");
5851 pw.print(mRestrictedOverscanScreenLeft);
5852 pw.print(","); pw.print(mRestrictedOverscanScreenTop);
5853 pw.print(") "); pw.print(mRestrictedOverscanScreenWidth);
5854 pw.print("x"); pw.println(mRestrictedOverscanScreenHeight);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005855 pw.print(prefix); pw.print("mUnrestrictedScreen=("); pw.print(mUnrestrictedScreenLeft);
5856 pw.print(","); pw.print(mUnrestrictedScreenTop);
5857 pw.print(") "); pw.print(mUnrestrictedScreenWidth);
5858 pw.print("x"); pw.println(mUnrestrictedScreenHeight);
5859 pw.print(prefix); pw.print("mRestrictedScreen=("); pw.print(mRestrictedScreenLeft);
5860 pw.print(","); pw.print(mRestrictedScreenTop);
5861 pw.print(") "); pw.print(mRestrictedScreenWidth);
5862 pw.print("x"); pw.println(mRestrictedScreenHeight);
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07005863 pw.print(prefix); pw.print("mStableFullscreen=("); pw.print(mStableFullscreenLeft);
5864 pw.print(","); pw.print(mStableFullscreenTop);
5865 pw.print(")-("); pw.print(mStableFullscreenRight);
5866 pw.print(","); pw.print(mStableFullscreenBottom); pw.println(")");
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07005867 pw.print(prefix); pw.print("mStable=("); pw.print(mStableLeft);
5868 pw.print(","); pw.print(mStableTop);
5869 pw.print(")-("); pw.print(mStableRight);
5870 pw.print(","); pw.print(mStableBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07005871 pw.print(prefix); pw.print("mSystem=("); pw.print(mSystemLeft);
5872 pw.print(","); pw.print(mSystemTop);
5873 pw.print(")-("); pw.print(mSystemRight);
5874 pw.print(","); pw.print(mSystemBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005875 pw.print(prefix); pw.print("mCur=("); pw.print(mCurLeft);
5876 pw.print(","); pw.print(mCurTop);
5877 pw.print(")-("); pw.print(mCurRight);
5878 pw.print(","); pw.print(mCurBottom); pw.println(")");
5879 pw.print(prefix); pw.print("mContent=("); pw.print(mContentLeft);
5880 pw.print(","); pw.print(mContentTop);
5881 pw.print(")-("); pw.print(mContentRight);
5882 pw.print(","); pw.print(mContentBottom); pw.println(")");
Dianne Hackborne30e02f2014-05-27 18:24:45 -07005883 pw.print(prefix); pw.print("mVoiceContent=("); pw.print(mVoiceContentLeft);
5884 pw.print(","); pw.print(mVoiceContentTop);
5885 pw.print(")-("); pw.print(mVoiceContentRight);
5886 pw.print(","); pw.print(mVoiceContentBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005887 pw.print(prefix); pw.print("mDock=("); pw.print(mDockLeft);
5888 pw.print(","); pw.print(mDockTop);
5889 pw.print(")-("); pw.print(mDockRight);
5890 pw.print(","); pw.print(mDockBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07005891 pw.print(prefix); pw.print("mDockLayer="); pw.print(mDockLayer);
5892 pw.print(" mStatusBarLayer="); pw.println(mStatusBarLayer);
Dianne Hackborn7ad44382012-10-18 17:46:00 -07005893 pw.print(prefix); pw.print("mShowingLockscreen="); pw.print(mShowingLockscreen);
5894 pw.print(" mShowingDream="); pw.print(mShowingDream);
5895 pw.print(" mDreamingLockscreen="); pw.println(mDreamingLockscreen);
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07005896 if (mLastInputMethodWindow != null) {
5897 pw.print(prefix); pw.print("mLastInputMethodWindow=");
5898 pw.println(mLastInputMethodWindow);
5899 }
5900 if (mLastInputMethodTargetWindow != null) {
5901 pw.print(prefix); pw.print("mLastInputMethodTargetWindow=");
5902 pw.println(mLastInputMethodTargetWindow);
5903 }
5904 if (mStatusBar != null) {
5905 pw.print(prefix); pw.print("mStatusBar=");
5906 pw.println(mStatusBar);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01005907 pw.print(prefix); pw.print("isStatusBarKeyguard=");
5908 pw.print(isStatusBarKeyguard());
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07005909 }
5910 if (mNavigationBar != null) {
5911 pw.print(prefix); pw.print("mNavigationBar=");
5912 pw.println(mNavigationBar);
5913 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07005914 if (mFocusedWindow != null) {
5915 pw.print(prefix); pw.print("mFocusedWindow=");
5916 pw.println(mFocusedWindow);
5917 }
5918 if (mFocusedApp != null) {
5919 pw.print(prefix); pw.print("mFocusedApp=");
5920 pw.println(mFocusedApp);
5921 }
5922 if (mWinDismissingKeyguard != null) {
5923 pw.print(prefix); pw.print("mWinDismissingKeyguard=");
5924 pw.println(mWinDismissingKeyguard);
5925 }
5926 if (mTopFullscreenOpaqueWindowState != null) {
5927 pw.print(prefix); pw.print("mTopFullscreenOpaqueWindowState=");
5928 pw.println(mTopFullscreenOpaqueWindowState);
5929 }
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08005930 if (mForcingShowNavBar) {
5931 pw.print(prefix); pw.print("mForcingShowNavBar=");
5932 pw.println(mForcingShowNavBar); pw.print( "mForcingShowNavBarLayer=");
5933 pw.println(mForcingShowNavBarLayer);
5934 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07005935 pw.print(prefix); pw.print("mTopIsFullscreen="); pw.print(mTopIsFullscreen);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005936 pw.print(" mHideLockScreen="); pw.println(mHideLockScreen);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07005937 pw.print(prefix); pw.print("mForceStatusBar="); pw.print(mForceStatusBar);
5938 pw.print(" mForceStatusBarFromKeyguard=");
5939 pw.println(mForceStatusBarFromKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005940 pw.print(prefix); pw.print("mDismissKeyguard="); pw.print(mDismissKeyguard);
Craig Mautnerad09bcc2012-10-08 13:33:11 -07005941 pw.print(" mWinDismissingKeyguard="); pw.print(mWinDismissingKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005942 pw.print(" mHomePressed="); pw.println(mHomePressed);
5943 pw.print(prefix); pw.print("mAllowLockscreenWhenOn="); pw.print(mAllowLockscreenWhenOn);
5944 pw.print(" mLockScreenTimeout="); pw.print(mLockScreenTimeout);
5945 pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive);
5946 pw.print(prefix); pw.print("mEndcallBehavior="); pw.print(mEndcallBehavior);
5947 pw.print(" mIncallPowerBehavior="); pw.print(mIncallPowerBehavior);
5948 pw.print(" mLongPressOnHomeBehavior="); pw.println(mLongPressOnHomeBehavior);
5949 pw.print(prefix); pw.print("mLandscapeRotation="); pw.print(mLandscapeRotation);
5950 pw.print(" mSeascapeRotation="); pw.println(mSeascapeRotation);
5951 pw.print(prefix); pw.print("mPortraitRotation="); pw.print(mPortraitRotation);
5952 pw.print(" mUpsideDownRotation="); pw.println(mUpsideDownRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07005953 pw.print(prefix); pw.print("mDemoHdmiRotation="); pw.print(mDemoHdmiRotation);
5954 pw.print(" mDemoHdmiRotationLock="); pw.println(mDemoHdmiRotationLock);
5955 pw.print(prefix); pw.print("mUndockedHdmiRotation="); pw.println(mUndockedHdmiRotation);
Jeff Brown600f0032014-05-22 17:06:00 -07005956
Tim Kilbournd7c0c2e2014-05-29 16:08:10 -07005957 mGlobalKeyManager.dump(prefix, pw);
John Spurlock27735a42013-08-14 17:57:38 -04005958 mStatusBarController.dump(pw, prefix);
5959 mNavigationBarController.dump(pw, prefix);
John Spurlockc6d1c602014-01-17 15:22:06 -05005960 PolicyControl.dump(prefix, pw);
Jeff Brown600f0032014-05-22 17:06:00 -07005961
Jeff Browna20dda42014-05-27 20:57:24 -07005962 if (mWakeGestureListener != null) {
5963 mWakeGestureListener.dump(pw, prefix);
5964 }
Jeff Brown600f0032014-05-22 17:06:00 -07005965 if (mOrientationListener != null) {
5966 mOrientationListener.dump(pw, prefix);
5967 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005968 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005969}