blob: ca260ecf9ce2f656173ecb9116c802230f9b8ebe [file] [log] [blame]
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001/*
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16package com.android.internal.policy.impl;
17
Dianne Hackborna4972e92012-03-14 10:38:05 -070018import android.app.ActivityManager;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080019import android.app.ActivityManagerNative;
Dianne Hackbornc2293022013-02-06 23:14:49 -080020import android.app.AppOpsManager;
Daniel Sandler6396c722013-04-16 20:19:09 -040021import android.app.IUiModeManager;
Dianne Hackborn661cd522011-08-22 00:26:20 -070022import android.app.ProgressDialog;
Jeff Brownde7a8ea2012-06-13 18:28:57 -070023import android.app.SearchManager;
John Spurlock97642182013-07-29 17:58:39 -040024import android.app.StatusBarManager;
Dianne Hackborn78968392010-03-04 20:47:56 -080025import android.app.UiModeManager;
Dianne Hackborn39c2d712009-09-22 11:41:31 -070026import android.content.ActivityNotFoundException;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080027import android.content.BroadcastReceiver;
Daniel Sandler0601eb72011-04-13 01:01:32 -040028import android.content.ComponentName;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080029import android.content.ContentResolver;
30import android.content.Context;
31import android.content.Intent;
Mike Lockwood1753f7f2009-08-24 14:49:07 -070032import android.content.IntentFilter;
Winson Chung9112ec32011-06-27 13:15:32 -070033import android.content.ServiceConnection;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080034import android.content.pm.ActivityInfo;
35import android.content.pm.PackageManager;
Daniel Sandler6396c722013-04-16 20:19:09 -040036import android.content.pm.ResolveInfo;
Dianne Hackborn2f0b1752011-05-31 17:59:49 -070037import android.content.res.CompatibilityInfo;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080038import android.content.res.Configuration;
39import android.content.res.Resources;
Craig Mautner8e4df6c2012-05-23 16:57:23 -070040import android.content.res.TypedArray;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080041import android.database.ContentObserver;
Dianne Hackbornc777e072010-02-12 13:07:59 -080042import android.graphics.PixelFormat;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080043import android.graphics.Rect;
John Spurlock7b414672014-07-18 13:02:39 -040044import android.media.AudioAttributes;
Michael Jurka7a348952012-02-27 13:07:58 -080045import android.media.AudioManager;
46import android.media.IAudioService;
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -070047import android.media.Ringtone;
48import android.media.RingtoneManager;
RoboErik3c45c292014-07-08 16:47:31 -070049import android.media.session.MediaController;
50import android.media.session.MediaSession;
RoboErik8a2cfc32014-05-16 11:19:38 -070051import android.media.session.MediaSessionLegacyHelper;
RoboErik3c45c292014-07-08 16:47:31 -070052import android.media.session.MediaSessionManager;
53import android.media.session.PlaybackState;
Dianne Hackborn38e29a62011-09-18 14:43:08 -070054import android.os.Bundle;
Jeff Brown9a538ee2012-08-20 14:56:57 -070055import android.os.FactoryTest;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080056import android.os.Handler;
57import android.os.IBinder;
Jeff Brown32cbc38552011-12-01 14:01:49 -080058import android.os.Looper;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -070059import android.os.Message;
60import android.os.Messenger;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080061import android.os.PowerManager;
62import android.os.RemoteException;
63import android.os.ServiceManager;
64import android.os.SystemClock;
65import android.os.SystemProperties;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -080066import android.os.UEventObserver;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -070067import android.os.UserHandle;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080068import android.os.Vibrator;
69import android.provider.Settings;
Jose Lima9546b202014-07-02 17:21:51 -070070import android.service.dreams.DreamManagerInternal;
John Spurlockc8b46ca2013-04-08 12:59:26 -040071import android.service.dreams.DreamService;
72import android.service.dreams.IDreamManager;
Santos Cordon9eb45932014-06-27 12:28:43 -070073import android.telecomm.TelecommManager;
Dianne Hackborn81e56d52011-05-26 00:55:58 -070074import android.util.DisplayMetrics;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080075import android.util.EventLog;
76import android.util.Log;
Jeff Browna41ca772010-08-11 14:46:32 -070077import android.util.Slog;
Jeff Brown6651a632011-11-28 12:59:11 -080078import android.util.SparseArray;
Dianne Hackbornf87d1962012-04-04 12:48:24 -070079import android.view.Display;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080080import android.view.Gravity;
81import android.view.HapticFeedbackConstants;
Dianne Hackborne0f085d2011-11-30 18:41:15 -080082import android.view.IApplicationToken;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080083import android.view.IWindowManager;
Jeff Browna41ca772010-08-11 14:46:32 -070084import android.view.InputChannel;
Jeff Brown4d396052010-10-29 21:50:21 -070085import android.view.InputDevice;
Jeff Brown4952dfd2011-11-30 19:23:22 -080086import android.view.InputEvent;
Jeff Brown32cbc38552011-12-01 14:01:49 -080087import android.view.InputEventReceiver;
Jeff Brown6b53e8d2010-11-10 16:03:06 -080088import android.view.KeyCharacterMap;
Craig Mautnerae446592012-12-06 19:05:05 -080089import android.view.KeyCharacterMap.FallbackAction;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080090import android.view.KeyEvent;
91import android.view.MotionEvent;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080092import android.view.Surface;
93import android.view.View;
94import android.view.ViewConfiguration;
95import android.view.Window;
96import android.view.WindowManager;
Craig Mautnerae446592012-12-06 19:05:05 -080097import android.view.WindowManagerGlobal;
Craig Mautner8a0da012014-05-31 15:13:37 -070098import android.view.WindowManagerInternal;
Craig Mautnerae446592012-12-06 19:05:05 -080099import android.view.WindowManagerPolicy;
Craig Mautnerae446592012-12-06 19:05:05 -0800100import android.view.accessibility.AccessibilityEvent;
Svetoslav8e3feb12014-02-24 13:46:47 -0800101import android.view.accessibility.AccessibilityManager;
Jorim Jaggi76a16232014-08-08 17:00:47 +0200102import android.view.animation.AlphaAnimation;
Craig Mautnerae446592012-12-06 19:05:05 -0800103import android.view.animation.Animation;
Jorim Jaggi76a16232014-08-08 17:00:47 +0200104import android.view.animation.AnimationSet;
Craig Mautnerae446592012-12-06 19:05:05 -0800105import android.view.animation.AnimationUtils;
106
107import com.android.internal.R;
Jorim Jaggi380ecb82014-03-14 17:25:20 +0100108import com.android.internal.policy.IKeyguardService;
109import com.android.internal.policy.IKeyguardServiceConstants;
Craig Mautnerae446592012-12-06 19:05:05 -0800110import com.android.internal.policy.PolicyManager;
Jim Miller5ecd8112013-01-09 18:50:26 -0800111import com.android.internal.policy.impl.keyguard.KeyguardServiceDelegate;
Craig Mautner8a0da012014-05-31 15:13:37 -0700112import com.android.internal.policy.impl.keyguard.KeyguardServiceDelegate.ShowListener;
Craig Mautnerae446592012-12-06 19:05:05 -0800113import com.android.internal.statusbar.IStatusBarService;
Craig Mautnerae446592012-12-06 19:05:05 -0800114import com.android.internal.widget.PointerLocationView;
Craig Mautner8a0da012014-05-31 15:13:37 -0700115import com.android.server.LocalServices;
Craig Mautnerae446592012-12-06 19:05:05 -0800116
117import java.io.File;
118import java.io.FileReader;
119import java.io.IOException;
120import java.io.PrintWriter;
Craig Mautner8a0da012014-05-31 15:13:37 -0700121import java.util.ArrayList;
Craig Mautner2bc789b2014-03-19 19:48:38 -0700122import java.util.HashSet;
RoboErik3c45c292014-07-08 16:47:31 -0700123import java.util.List;
Craig Mautnerae446592012-12-06 19:05:05 -0800124
Dianne Hackbornc652de82013-02-15 16:32:56 -0800125import static android.view.WindowManager.LayoutParams.*;
Jeff Brownac143512012-04-05 18:57:33 -0700126import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_ABSENT;
127import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_OPEN;
128import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_CLOSED;
Dianne Hackborn08743722009-12-21 12:16:51 -0800129
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800130/**
The Android Open Source Project0727d222009-03-11 12:11:58 -0700131 * WindowManagerPolicy implementation for the Android phone UI. This
132 * introduces a new method suffix, Lp, for an internal lock of the
133 * PhoneWindowManager. This is used to protect some internal state, and
John Spurlock04db1762013-05-13 12:46:41 -0400134 * 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 -0700135 * of both of those when held.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800136 */
137public class PhoneWindowManager implements WindowManagerPolicy {
138 static final String TAG = "WindowManager";
139 static final boolean DEBUG = false;
Joe Onorato43a17652011-04-06 19:22:23 -0700140 static final boolean localLOGV = false;
The Android Open Source Project11267662009-03-18 17:39:47 -0700141 static final boolean DEBUG_LAYOUT = false;
Jeff Brown40013652012-05-16 21:22:36 -0700142 static final boolean DEBUG_INPUT = false;
Craig Mautner6fbda632012-07-03 09:26:39 -0700143 static final boolean DEBUG_STARTING_WINDOW = false;
Craig Mautner8a0da012014-05-31 15:13:37 -0700144 static final boolean DEBUG_WAKEUP = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800145 static final boolean SHOW_STARTING_ANIMATIONS = true;
146 static final boolean SHOW_PROCESSES_ON_ALT_MENU = false;
Joe Onoratod208e702010-10-08 16:22:43 -0400147
Daniel Sandler6396c722013-04-16 20:19:09 -0400148 // Whether to allow dock apps with METADATA_DOCK_HOME to temporarily take over the Home key.
149 // No longer recommended for desk docks; still useful in car docks.
150 static final boolean ENABLE_CAR_DOCK_HOME_CAPTURE = true;
151 static final boolean ENABLE_DESK_DOCK_HOME_CAPTURE = false;
152
Jeff Brown6d8fd272014-05-20 21:24:38 -0700153 static final int SHORT_PRESS_POWER_NOTHING = 0;
154 static final int SHORT_PRESS_POWER_GO_TO_SLEEP = 1;
155 static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP = 2;
156 static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME = 3;
157
Joe Onoratod208e702010-10-08 16:22:43 -0400158 static final int LONG_PRESS_POWER_NOTHING = 0;
159 static final int LONG_PRESS_POWER_GLOBAL_ACTIONS = 1;
160 static final int LONG_PRESS_POWER_SHUT_OFF = 2;
Jeff Brown9a538ee2012-08-20 14:56:57 -0700161 static final int LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM = 3;
Michael Jurka3b1fc472011-06-13 10:54:40 -0700162
163 // These need to match the documentation/constant in
164 // core/res/res/values/config.xml
Joe Onorato46b0d682010-11-22 17:37:27 -0800165 static final int LONG_PRESS_HOME_NOTHING = 0;
Michael Wrightc9ebea72013-01-16 19:25:02 -0800166 static final int LONG_PRESS_HOME_RECENT_SYSTEM_UI = 1;
Jeff Browncaca8812013-05-09 13:34:33 -0700167 static final int LONG_PRESS_HOME_ASSIST = 2;
168
169 static final int DOUBLE_TAP_HOME_NOTHING = 0;
170 static final int DOUBLE_TAP_HOME_RECENT_SYSTEM_UI = 1;
Joe Onorato46b0d682010-11-22 17:37:27 -0800171
Dianne Hackborn5cb8d792009-05-21 17:34:15 -0700172 static final int APPLICATION_MEDIA_SUBLAYER = -2;
173 static final int APPLICATION_MEDIA_OVERLAY_SUBLAYER = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800174 static final int APPLICATION_PANEL_SUBLAYER = 1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800175 static final int APPLICATION_SUB_PANEL_SUBLAYER = 2;
Craig Mautner88400d32012-09-30 12:35:45 -0700176
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800177 static public final String SYSTEM_DIALOG_REASON_KEY = "reason";
178 static public final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions";
179 static public final String SYSTEM_DIALOG_REASON_RECENT_APPS = "recentapps";
Joe Onoratof275f0c2009-11-24 16:11:13 -0500180 static public final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey";
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700181 static public final String SYSTEM_DIALOG_REASON_ASSIST = "assist";
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800182
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700183 /**
184 * These are the system UI flags that, when changing, can cause the layout
185 * of the screen to change.
186 */
187 static final int SYSTEM_UI_CHANGING_LAYOUT =
John Spurlocke1f366f2013-08-05 12:22:40 -0400188 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlock7f4820a2013-10-08 12:54:35 -0400189 | View.SYSTEM_UI_FLAG_FULLSCREEN
190 | View.STATUS_BAR_TRANSLUCENT
Adrian Roosea562512014-05-05 13:33:03 +0200191 | View.NAVIGATION_BAR_TRANSLUCENT
192 | View.SYSTEM_UI_TRANSPARENT;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700193
John Spurlock7b414672014-07-18 13:02:39 -0400194 private static final AudioAttributes VIBRATION_ATTRIBUTES = new AudioAttributes.Builder()
195 .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
196 .setUsage(AudioAttributes.USAGE_ASSISTANCE_SONIFICATION)
197 .build();
198
Jim Miller5ecd8112013-01-09 18:50:26 -0800199 /**
200 * Keyguard stuff
201 */
202 private WindowState mKeyguardScrim;
Jorim Jaggi380ecb82014-03-14 17:25:20 +0100203 private boolean mKeyguardHidden;
Jorim Jaggicff0acb2014-03-31 16:35:15 +0200204 private boolean mKeyguardDrawn;
Jim Miller5ecd8112013-01-09 18:50:26 -0800205
Jeff Brown6651a632011-11-28 12:59:11 -0800206 /* Table of Application Launch keys. Maps from key codes to intent categories.
207 *
208 * These are special keys that are used to launch particular kinds of applications,
209 * such as a web browser. HID defines nearly a hundred of them in the Consumer (0x0C)
210 * usage page. We don't support quite that many yet...
211 */
212 static SparseArray<String> sApplicationLaunchKeyCategories;
213 static {
214 sApplicationLaunchKeyCategories = new SparseArray<String>();
215 sApplicationLaunchKeyCategories.append(
216 KeyEvent.KEYCODE_EXPLORER, Intent.CATEGORY_APP_BROWSER);
217 sApplicationLaunchKeyCategories.append(
218 KeyEvent.KEYCODE_ENVELOPE, Intent.CATEGORY_APP_EMAIL);
219 sApplicationLaunchKeyCategories.append(
220 KeyEvent.KEYCODE_CONTACTS, Intent.CATEGORY_APP_CONTACTS);
221 sApplicationLaunchKeyCategories.append(
222 KeyEvent.KEYCODE_CALENDAR, Intent.CATEGORY_APP_CALENDAR);
223 sApplicationLaunchKeyCategories.append(
224 KeyEvent.KEYCODE_MUSIC, Intent.CATEGORY_APP_MUSIC);
225 sApplicationLaunchKeyCategories.append(
226 KeyEvent.KEYCODE_CALCULATOR, Intent.CATEGORY_APP_CALCULATOR);
227 }
228
Dianne Hackborndf89e652011-10-06 22:35:11 -0700229 /**
230 * Lock protecting internal state. Must not call out into window
231 * manager with lock held. (This lock will be acquired in places
232 * where the window manager is calling in with its own lock held.)
233 */
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800234 private final Object mLock = new Object();
Dianne Hackborndf89e652011-10-06 22:35:11 -0700235
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800236 Context mContext;
237 IWindowManager mWindowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700238 WindowManagerFuncs mWindowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -0700239 WindowManagerInternal mWindowManagerInternal;
Jeff Brown96307042012-07-27 15:51:34 -0700240 PowerManager mPowerManager;
Jose Lima9546b202014-07-02 17:21:51 -0700241 DreamManagerInternal mDreamManagerInternal;
Joe Onorato93056472010-09-10 10:30:46 -0400242 IStatusBarService mStatusBarService;
Jeff Browncaca8812013-05-09 13:34:33 -0700243 boolean mPreloadedRecentApps;
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700244 final Object mServiceAquireLock = new Object();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800245 Vibrator mVibrator; // Vibrator for giving feedback of orientation changes
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700246 SearchManager mSearchManager;
Svetoslav8e3feb12014-02-24 13:46:47 -0800247 AccessibilityManager mAccessibilityManager;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800248
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700249 // Vibrator pattern for haptic feedback of a long press.
250 long[] mLongPressVibePattern;
Craig Mautner88400d32012-09-30 12:35:45 -0700251
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700252 // Vibrator pattern for haptic feedback of virtual key press.
253 long[] mVirtualKeyVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700254
Amith Yamasanic33cb712010-02-10 15:21:49 -0800255 // Vibrator pattern for a short vibration.
256 long[] mKeyboardTapVibePattern;
257
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -0700258 // Vibrator pattern for a short vibration when tapping on an hour/minute tick of a Clock.
259 long[] mClockTickVibePattern;
260
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -0700261 // Vibrator pattern for a short vibration when tapping on a day/month/year date of a Calendar.
262 long[] mCalendarDateVibePattern;
263
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700264 // Vibrator pattern for haptic feedback during boot when safe mode is disabled.
265 long[] mSafeModeDisabledVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700266
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700267 // Vibrator pattern for haptic feedback during boot when safe mode is enabled.
268 long[] mSafeModeEnabledVibePattern;
Romain Guy8154cd32010-03-29 14:41:15 -0700269
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800270 /** If true, hitting shift & menu will broadcast Intent.ACTION_BUG_REPORT */
271 boolean mEnableShiftMenuBugReports = false;
Mike Lockwoodd747dc82011-09-13 16:28:22 -0400272
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800273 boolean mSafeMode;
274 WindowState mStatusBar = null;
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700275 int mStatusBarHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400276 WindowState mNavigationBar = null;
Daniel Sandler36412a72011-08-04 09:35:13 -0400277 boolean mHasNavigationBar = false;
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700278 boolean mCanHideNavigationBar = false;
Daniel Sandler4a066c52012-04-20 14:49:13 -0400279 boolean mNavigationBarCanMove = false; // can the navigation bar ever move to the side?
280 boolean mNavigationBarOnBottom = true; // is the navigation bar on the bottom *right now*?
281 int[] mNavigationBarHeightForRotation = new int[4];
282 int[] mNavigationBarWidthForRotation = new int[4];
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400283
Craig Mautnera631d492014-08-05 15:16:01 -0700284 boolean mBootMessageNeedsHiding;
Jim Miller5ecd8112013-01-09 18:50:26 -0800285 KeyguardServiceDelegate mKeyguardDelegate;
Craig Mautner8a0da012014-05-31 15:13:37 -0700286 // The following are only accessed on the mHandler thread.
287 boolean mKeyguardDrawComplete;
288 boolean mWindowManagerDrawComplete;
Craig Mautner13f6ea72014-06-23 14:57:02 -0700289 ScreenOnListener mScreenOnListener;
290 final Runnable mWindowManagerDrawCallback = new Runnable() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700291 @Override
Craig Mautner13f6ea72014-06-23 14:57:02 -0700292 public void run() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700293 if (DEBUG_WAKEUP) Slog.i(TAG, "All windows ready for display!");
294 mHandler.sendEmptyMessage(MSG_WINDOW_MANAGER_DRAWN_COMPLETE);
295 }
296 };
297 final ShowListener mKeyguardDelegateCallback = new ShowListener() {
298 @Override
299 public void onShown(IBinder windowToken) {
300 if (DEBUG_WAKEUP) Slog.d(TAG, "mKeyguardDelegate.ShowListener.onShown.");
301 mHandler.sendEmptyMessage(MSG_KEYGUARD_DRAWN_COMPLETE);
302 }
303 };
304
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800305 GlobalActions mGlobalActions;
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700306 volatile boolean mPowerKeyHandled; // accessed from input reader and handler thread
307 boolean mPendingPowerKeyUpCanceled;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800308 Handler mHandler;
satok1bc0a492012-04-25 22:47:12 +0900309 WindowState mLastInputMethodWindow = null;
310 WindowState mLastInputMethodTargetWindow = null;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800311
Winson Chungd42a6cf2014-06-03 16:24:04 -0700312 boolean mRecentsVisible;
Winson Chung1e8d71b2014-05-16 17:05:22 -0700313 int mRecentAppsHeldModifiers;
Jeff Browncf39bdf2012-05-18 14:41:19 -0700314 boolean mLanguageSwitchKeyPressed;
Jeff Brown68b909d2011-12-07 16:36:01 -0800315
Jeff Brown2e7760e2012-04-11 15:14:55 -0700316 int mLidState = LID_ABSENT;
Jeff Browndaa37532012-05-01 15:54:03 -0700317 boolean mHaveBuiltInKeyboard;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800318
Dianne Hackbornc777e072010-02-12 13:07:59 -0800319 boolean mSystemReady;
Dianne Hackbornba24e4d2011-09-01 11:17:06 -0700320 boolean mSystemBooted;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800321 boolean mHdmiPlugged;
Jeff Brown4f5fa282014-06-12 19:19:15 -0700322 IUiModeManager mUiModeManager;
Daniel Sandler6396c722013-04-16 20:19:09 -0400323 int mUiMode;
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700324 int mDockMode = Intent.EXTRA_DOCK_STATE_UNDOCKED;
Mike Lockwood1753f7f2009-08-24 14:49:07 -0700325 int mLidOpenRotation;
Mike Lockwood2d1efbd2009-09-16 12:15:53 -0400326 int mCarDockRotation;
327 int mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -0700328 int mUndockedHdmiRotation;
329 int mDemoHdmiRotation;
330 boolean mDemoHdmiRotationLock;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400331
Jeff Browna20dda42014-05-27 20:57:24 -0700332 boolean mWakeGestureEnabledSetting;
333 MyWakeGestureListener mWakeGestureListener;
334
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700335 // Default display does not rotate, apps that require non-default orientation will have to
336 // have the orientation emulated.
337 private boolean mForceDefaultOrientation = false;
338
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400339 int mUserRotationMode = WindowManagerPolicy.USER_ROTATION_FREE;
340 int mUserRotation = Surface.ROTATION_0;
Jeff Brown207673cd2012-06-05 17:47:11 -0700341 boolean mAccelerometerDefault;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400342
Jeff Brownbcdfc622014-03-06 19:13:04 -0800343 boolean mSupportAutoRotation;
Jeff Brownd3187e32011-09-21 19:26:44 -0700344 int mAllowAllRotations = -1;
Mike Lockwoode9867d22009-09-20 01:59:02 -0400345 boolean mCarDockEnablesAccelerometer;
346 boolean mDeskDockEnablesAccelerometer;
Dianne Hackborn2862fff2009-09-15 22:56:29 -0700347 int mLidKeyboardAccessibility;
348 int mLidNavigationAccessibility;
Jeff Brownc458ce92012-04-30 14:58:40 -0700349 boolean mLidControlsSleep;
Jeff Brown6d8fd272014-05-20 21:24:38 -0700350 int mShortPressOnPowerBehavior = -1;
Joe Onoratod208e702010-10-08 16:22:43 -0400351 int mLongPressOnPowerBehavior = -1;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -0700352 boolean mScreenOnEarly = false;
353 boolean mScreenOnFully = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800354 boolean mOrientationSensorEnabled = false;
355 int mCurrentAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800356 boolean mHasSoftInput = false;
Daniel Sandlerdd73ee42013-10-11 22:19:59 -0400357 boolean mTranslucentDecorEnabled = true;
Craig Mautner967212c2013-04-13 21:10:58 -0700358
Jeff Brown70825162012-03-28 17:27:48 -0700359 int mPointerLocationMode = 0; // guarded by mLock
Joe Onorato664644d2011-01-23 17:53:23 -0800360
361 // The last window we were told about in focusChanged.
362 WindowState mFocusedWindow;
Dianne Hackborne0f085d2011-11-30 18:41:15 -0800363 IApplicationToken mFocusedApp;
Joe Onorato664644d2011-01-23 17:53:23 -0800364
Jeff Brown70825162012-03-28 17:27:48 -0700365 PointerLocationView mPointerLocationView;
Jeff Brown32cbc38552011-12-01 14:01:49 -0800366
Dianne Hackbornc652de82013-02-15 16:32:56 -0800367 // The current size of the screen; really; extends into the overscan area of
368 // the screen and doesn't account for any system elements like the status bar.
369 int mOverscanScreenLeft, mOverscanScreenTop;
370 int mOverscanScreenWidth, mOverscanScreenHeight;
371 // The current visible size of the screen; really; (ir)regardless of whether the status
372 // bar can be hidden but not extending into the overscan area.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800373 int mUnrestrictedScreenLeft, mUnrestrictedScreenTop;
374 int mUnrestrictedScreenWidth, mUnrestrictedScreenHeight;
Dianne Hackborn313440842013-02-19 19:22:59 -0800375 // Like mOverscanScreen*, but allowed to move into the overscan region where appropriate.
376 int mRestrictedOverscanScreenLeft, mRestrictedOverscanScreenTop;
377 int mRestrictedOverscanScreenWidth, mRestrictedOverscanScreenHeight;
Dianne Hackborn82de1ae2010-10-28 11:28:39 -0700378 // The current size of the screen; these may be different than (0,0)-(dw,dh)
379 // if the status bar can't be hidden; in that case it effectively carves out
380 // that area of the display from all other windows.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800381 int mRestrictedScreenLeft, mRestrictedScreenTop;
382 int mRestrictedScreenWidth, mRestrictedScreenHeight;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700383 // During layout, the current screen borders accounting for any currently
384 // visible system UI elements.
385 int mSystemLeft, mSystemTop, mSystemRight, mSystemBottom;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700386 // For applications requesting stable content insets, these are them.
387 int mStableLeft, mStableTop, mStableRight, mStableBottom;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -0700388 // For applications requesting stable content insets but have also set the
389 // fullscreen window flag, these are the stable dimensions without the status bar.
390 int mStableFullscreenLeft, mStableFullscreenTop;
391 int mStableFullscreenRight, mStableFullscreenBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800392 // During layout, the current screen borders with all outer decoration
393 // (status bar, input method dock) accounted for.
394 int mCurLeft, mCurTop, mCurRight, mCurBottom;
395 // During layout, the frame in which content should be displayed
396 // to the user, accounting for all screen decoration except for any
397 // space they deem as available for other content. This is usually
398 // the same as mCur*, but may be larger if the screen decor has supplied
399 // content insets.
400 int mContentLeft, mContentTop, mContentRight, mContentBottom;
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700401 // During layout, the frame in which voice content should be displayed
402 // to the user, accounting for all screen decoration except for any
403 // space they deem as available for other content.
404 int mVoiceContentLeft, mVoiceContentTop, mVoiceContentRight, mVoiceContentBottom;
Dianne Hackborn8e11ef02010-11-18 19:47:42 -0800405 // During layout, the current screen borders along which input method
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800406 // windows are placed.
407 int mDockLeft, mDockTop, mDockRight, mDockBottom;
408 // During layout, the layer at which the doc window is placed.
409 int mDockLayer;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700410 // During layout, this is the layer of the status bar.
411 int mStatusBarLayer;
Dianne Hackborne26ab702011-10-16 13:21:33 -0700412 int mLastSystemUiFlags;
413 // Bits that we are in the process of clearing, so we want to prevent
414 // them from being set by applications until everything has been updated
415 // to have them clear.
416 int mResettingSystemUiFlags = 0;
417 // Bits that we are currently always keeping cleared.
418 int mForceClearedSystemUiFlags = 0;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -0800419 // What we last reported to system UI about whether the compatibility
420 // menu needs to be displayed.
421 boolean mLastFocusNeedsMenu = false;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700422
423 FakeWindow mHideNavFakeWindow = null;
424
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800425 static final Rect mTmpParentFrame = new Rect();
426 static final Rect mTmpDisplayFrame = new Rect();
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800427 static final Rect mTmpOverscanFrame = new Rect();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800428 static final Rect mTmpContentFrame = new Rect();
429 static final Rect mTmpVisibleFrame = new Rect();
John Spurlock46646232013-09-30 22:32:42 -0400430 static final Rect mTmpDecorFrame = new Rect();
Adrian Roosfa104232014-06-20 16:10:14 -0700431 static final Rect mTmpStableFrame = new Rect();
Dianne Hackborn1f903c32011-09-13 19:18:06 -0700432 static final Rect mTmpNavigationFrame = new Rect();
Craig Mautner967212c2013-04-13 21:10:58 -0700433
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800434 WindowState mTopFullscreenOpaqueWindowState;
Craig Mautner2bc789b2014-03-19 19:48:38 -0700435 HashSet<IApplicationToken> mAppsToBeHidden = new HashSet<IApplicationToken>();
Joe Onorato93056472010-09-10 10:30:46 -0400436 boolean mTopIsFullscreen;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800437 boolean mForceStatusBar;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -0700438 boolean mForceStatusBarFromKeyguard;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700439 boolean mHideLockScreen;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -0800440 boolean mForcingShowNavBar;
441 int mForcingShowNavBarLayer;
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700442
443 // States of keyguard dismiss.
444 private static final int DISMISS_KEYGUARD_NONE = 0; // Keyguard not being dismissed.
445 private static final int DISMISS_KEYGUARD_START = 1; // Keyguard needs to be dismissed.
446 private static final int DISMISS_KEYGUARD_CONTINUE = 2; // Keyguard has been dismissed.
447 int mDismissKeyguard = DISMISS_KEYGUARD_NONE;
448
449 /** The window that is currently dismissing the keyguard. Dismissing the keyguard must only
450 * be done once per window. */
451 private WindowState mWinDismissingKeyguard;
452
Craig Mautnerc9457fa2014-06-06 14:27:48 -0700453 /** The window that is currently showing "over" the keyguard. If there is an app window
454 * belonging to another app on top of this the keyguard shows. If there is a fullscreen
455 * app window under this, still dismiss the keyguard but don't show the app underneath. Show
456 * the wallpaper. */
457 private WindowState mWinShowWhenLocked;
458
Dianne Hackborn7ad44382012-10-18 17:46:00 -0700459 boolean mShowingLockscreen;
460 boolean mShowingDream;
461 boolean mDreamingLockscreen;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800462 boolean mHomePressed;
Jeff Browncaca8812013-05-09 13:34:33 -0700463 boolean mHomeConsumed;
464 boolean mHomeDoubleTapPending;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800465 Intent mHomeIntent;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700466 Intent mCarDockIntent;
467 Intent mDeskDockIntent;
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700468 boolean mSearchKeyShortcutPending;
469 boolean mConsumeSearchKeyUp;
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700470 boolean mAssistKeyLongPressed;
Michael Wright6a62e552014-06-03 19:19:48 -0700471 boolean mPendingMetaAction;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800472
Mike Lockwood28569302010-01-28 11:54:40 -0500473 // support for activating the lock screen while the screen is on
474 boolean mAllowLockscreenWhenOn;
475 int mLockScreenTimeout;
476 boolean mLockScreenTimerActive;
477
David Brownbaf8d092010-03-08 21:52:59 -0800478 // Behavior of ENDCALL Button. (See Settings.System.END_BUTTON_BEHAVIOR.)
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800479 int mEndcallBehavior;
David Brownbaf8d092010-03-08 21:52:59 -0800480
481 // Behavior of POWER button while in-call and screen on.
482 // (See Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR.)
483 int mIncallPowerBehavior;
484
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700485 Display mDisplay;
486
Dianne Hackborn9d132642011-04-21 17:26:39 -0700487 int mLandscapeRotation = 0; // default landscape rotation
488 int mSeascapeRotation = 0; // "other" landscape rotation, 180 degrees from mLandscapeRotation
489 int mPortraitRotation = 0; // default portrait rotation
490 int mUpsideDownRotation = 0; // "other" portrait rotation
Mitsuru Oshima831d0d92009-06-16 18:27:18 -0700491
Dianne Hackbornc652de82013-02-15 16:32:56 -0800492 int mOverscanLeft = 0;
493 int mOverscanTop = 0;
494 int mOverscanRight = 0;
495 int mOverscanBottom = 0;
496
Joe Onorato46b0d682010-11-22 17:37:27 -0800497 // What we do when the user long presses on home
Jeff Browncaca8812013-05-09 13:34:33 -0700498 private int mLongPressOnHomeBehavior;
499
500 // What we do when the user double-taps on home
501 private int mDoubleTapOnHomeBehavior;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800502
Winson Chung9112ec32011-06-27 13:15:32 -0700503 // Screenshot trigger states
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700504 // Time to volume and power must be pressed within this interval of each other.
505 private static final long SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS = 150;
Winson Chung1cea2f32012-10-08 20:42:01 -0700506 // Increase the chord delay when taking a screenshot from the keyguard
507 private static final float KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER = 2.5f;
Christopher Tatee90585f2012-03-05 18:56:25 -0800508 private boolean mScreenshotChordEnabled;
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700509 private boolean mVolumeDownKeyTriggered;
510 private long mVolumeDownKeyTime;
511 private boolean mVolumeDownKeyConsumedByScreenshotChord;
512 private boolean mVolumeUpKeyTriggered;
513 private boolean mPowerKeyTriggered;
514 private long mPowerKeyTime;
Winson Chung9112ec32011-06-27 13:15:32 -0700515
Michael Wrightb854e242013-02-05 17:54:02 -0800516 /* The number of steps between min and max brightness */
517 private static final int BRIGHTNESS_STEPS = 10;
518
Christopher Tate5e08af02012-09-21 17:17:22 -0700519 SettingsObserver mSettingsObserver;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800520 ShortcutManager mShortcutManager;
521 PowerManager.WakeLock mBroadcastWakeLock;
Jeff Brown40013652012-05-16 21:22:36 -0700522 boolean mHavePendingMediaKeyRepeatWithWakeLock;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800523
Craig Mautnerd625ab22013-09-06 13:40:31 -0700524 private int mCurrentUserId;
525
Justin Kohd378ad72013-04-01 12:18:26 -0700526 // Maps global key codes to the components that will handle them.
527 private GlobalKeyManager mGlobalKeyManager;
528
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700529 // Fallback actions by key code.
530 private final SparseArray<KeyCharacterMap.FallbackAction> mFallbackActions =
531 new SparseArray<KeyCharacterMap.FallbackAction>();
Jeff Brown49ed71d2010-12-06 17:13:33 -0800532
Jorim Jaggi76a16232014-08-08 17:00:47 +0200533 private final LogDecelerateInterpolator mLogDecelerateInterpolator
534 = new LogDecelerateInterpolator(100, 0);
535
Jeff Brown70825162012-03-28 17:27:48 -0700536 private static final int MSG_ENABLE_POINTER_LOCATION = 1;
537 private static final int MSG_DISABLE_POINTER_LOCATION = 2;
Jeff Brown40013652012-05-16 21:22:36 -0700538 private static final int MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK = 3;
539 private static final int MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK = 4;
Craig Mautner8a0da012014-05-31 15:13:37 -0700540 private static final int MSG_KEYGUARD_DRAWN_COMPLETE = 5;
541 private static final int MSG_KEYGUARD_DRAWN_TIMEOUT = 6;
542 private static final int MSG_WINDOW_MANAGER_DRAWN_COMPLETE = 7;
543 private static final int MSG_WAKING_UP = 8;
Craig Mautner84984fa2014-06-19 11:19:20 -0700544 private static final int MSG_DISPATCH_SHOW_RECENTS = 9;
Alan Viverettee34560b22014-07-10 14:50:06 -0700545 private static final int MSG_DISPATCH_SHOW_GLOBAL_ACTIONS = 10;
Craig Mautnera631d492014-08-05 15:16:01 -0700546 private static final int MSG_HIDE_BOOT_MESSAGE = 11;
Jeff Brown70825162012-03-28 17:27:48 -0700547
548 private class PolicyHandler extends Handler {
549 @Override
550 public void handleMessage(Message msg) {
551 switch (msg.what) {
552 case MSG_ENABLE_POINTER_LOCATION:
553 enablePointerLocation();
554 break;
555 case MSG_DISABLE_POINTER_LOCATION:
556 disablePointerLocation();
557 break;
Jeff Brown40013652012-05-16 21:22:36 -0700558 case MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK:
559 dispatchMediaKeyWithWakeLock((KeyEvent)msg.obj);
560 break;
561 case MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK:
562 dispatchMediaKeyRepeatWithWakeLock((KeyEvent)msg.obj);
563 break;
Craig Mautner84984fa2014-06-19 11:19:20 -0700564 case MSG_DISPATCH_SHOW_RECENTS:
565 showRecentApps(false);
566 break;
Alan Viverettee34560b22014-07-10 14:50:06 -0700567 case MSG_DISPATCH_SHOW_GLOBAL_ACTIONS:
568 showGlobalActionsInternal();
569 break;
Craig Mautner8a0da012014-05-31 15:13:37 -0700570 case MSG_KEYGUARD_DRAWN_COMPLETE:
571 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mKeyguardDrawComplete");
572 mKeyguardDrawComplete = true;
573 finishScreenTurningOn();
574 break;
575 case MSG_KEYGUARD_DRAWN_TIMEOUT:
576 Slog.w(TAG, "Keyguard drawn timeout. Setting mKeyguardDrawComplete");
577 mKeyguardDrawComplete = true;
578 finishScreenTurningOn();
579 break;
580 case MSG_WINDOW_MANAGER_DRAWN_COMPLETE:
581 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mWindowManagerDrawComplete");
582 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
583 mWindowManagerDrawComplete = true;
584 finishScreenTurningOn();
585 break;
586 case MSG_WAKING_UP:
587 handleWakingUp((ScreenOnListener) msg.obj);
588 break;
Craig Mautnera631d492014-08-05 15:16:01 -0700589 case MSG_HIDE_BOOT_MESSAGE:
590 handleHideBootMessage();
591 break;
Jeff Brown70825162012-03-28 17:27:48 -0700592 }
593 }
594 }
595
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800596 private UEventObserver mHDMIObserver = new UEventObserver() {
597 @Override
598 public void onUEvent(UEventObserver.UEvent event) {
599 setHdmiPlugged("1".equals(event.get("SWITCH_STATE")));
600 }
601 };
602
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800603 class SettingsObserver extends ContentObserver {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800604 SettingsObserver(Handler handler) {
605 super(handler);
606 }
David Brownbaf8d092010-03-08 21:52:59 -0800607
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800608 void observe() {
Christopher Tate5e08af02012-09-21 17:17:22 -0700609 // Observe all users' changes
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800610 ContentResolver resolver = mContext.getContentResolver();
611 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700612 Settings.System.END_BUTTON_BEHAVIOR), false, this,
613 UserHandle.USER_ALL);
David Brownbaf8d092010-03-08 21:52:59 -0800614 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700615 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR), false, this,
616 UserHandle.USER_ALL);
Jeff Browna20dda42014-05-27 20:57:24 -0700617 resolver.registerContentObserver(Settings.Secure.getUriFor(
618 Settings.Secure.WAKE_GESTURE_ENABLED), false, this,
619 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800620 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700621 Settings.System.ACCELEROMETER_ROTATION), false, this,
622 UserHandle.USER_ALL);
Mike Lockwood28569302010-01-28 11:54:40 -0500623 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700624 Settings.System.USER_ROTATION), false, this,
625 UserHandle.USER_ALL);
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400626 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700627 Settings.System.SCREEN_OFF_TIMEOUT), false, this,
628 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800629 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700630 Settings.System.POINTER_LOCATION), false, this,
631 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800632 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700633 Settings.Secure.DEFAULT_INPUT_METHOD), false, this,
634 UserHandle.USER_ALL);
John Spurlockd9b70bd2014-02-06 17:02:44 -0500635 resolver.registerContentObserver(Settings.Secure.getUriFor(
John Spurlockf1a36642013-10-12 17:50:42 -0400636 Settings.Secure.IMMERSIVE_MODE_CONFIRMATIONS), false, this,
Christopher Tate5e08af02012-09-21 17:17:22 -0700637 UserHandle.USER_ALL);
John Spurlockc6d1c602014-01-17 15:22:06 -0500638 resolver.registerContentObserver(Settings.Global.getUriFor(
639 Settings.Global.POLICY_CONTROL), false, this,
640 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800641 updateSettings();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800642 }
643
644 @Override public void onChange(boolean selfChange) {
Dianne Hackbornc777e072010-02-12 13:07:59 -0800645 updateSettings();
Jeff Brown01a98dd2011-09-20 15:08:29 -0700646 updateRotation(false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800647 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800648 }
Craig Mautner967212c2013-04-13 21:10:58 -0700649
Jeff Browna20dda42014-05-27 20:57:24 -0700650 class MyWakeGestureListener extends WakeGestureListener {
651 MyWakeGestureListener(Context context, Handler handler) {
652 super(context, handler);
653 }
654
655 @Override
656 public void onWakeUp() {
657 synchronized (mLock) {
658 if (shouldEnableWakeGestureLp()) {
Jeff Browne07b94b2014-06-18 15:56:27 -0700659 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
Jeff Browna20dda42014-05-27 20:57:24 -0700660 mPowerManager.wakeUp(SystemClock.uptimeMillis());
661 }
662 }
663 }
664 }
665
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800666 class MyOrientationListener extends WindowOrientationListener {
Craig Mautnereee29c42013-01-17 14:44:34 -0800667 MyOrientationListener(Context context, Handler handler) {
668 super(context, handler);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800669 }
Craig Mautner967212c2013-04-13 21:10:58 -0700670
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800671 @Override
Jeff Brownc0347aa2011-09-23 17:26:09 -0700672 public void onProposedRotationChanged(int rotation) {
Craig Mautnereda67292013-04-28 13:50:14 -0700673 if (localLOGV) Slog.v(TAG, "onProposedRotationChanged, rotation=" + rotation);
Jeff Brown01a98dd2011-09-20 15:08:29 -0700674 updateRotation(false);
675 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800676 }
677 MyOrientationListener mOrientationListener;
678
John Spurlock27735a42013-08-14 17:57:38 -0400679 private final BarController mStatusBarController = new BarController("StatusBar",
John Spurlock5b9145b2013-08-20 15:13:47 -0400680 View.STATUS_BAR_TRANSIENT,
681 View.STATUS_BAR_UNHIDE,
John Spurlockbd957402013-10-03 11:38:39 -0400682 View.STATUS_BAR_TRANSLUCENT,
683 StatusBarManager.WINDOW_STATUS_BAR,
684 WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
John Spurlock5b9145b2013-08-20 15:13:47 -0400685
John Spurlock27735a42013-08-14 17:57:38 -0400686 private final BarController mNavigationBarController = new BarController("NavigationBar",
John Spurlock5b9145b2013-08-20 15:13:47 -0400687 View.NAVIGATION_BAR_TRANSIENT,
688 View.NAVIGATION_BAR_UNHIDE,
John Spurlockbd957402013-10-03 11:38:39 -0400689 View.NAVIGATION_BAR_TRANSLUCENT,
690 StatusBarManager.WINDOW_NAVIGATION_BAR,
691 WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
John Spurlock5b9145b2013-08-20 15:13:47 -0400692
John Spurlockf1a36642013-10-12 17:50:42 -0400693 private ImmersiveModeConfirmation mImmersiveModeConfirmation;
John Spurlock32beb2c2013-03-11 10:16:47 -0400694
Craig Mautner037aa8d2013-06-07 10:35:44 -0700695 private SystemGesturesPointerEventListener mSystemGestures;
John Spurlock32beb2c2013-03-11 10:16:47 -0400696
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700697 IStatusBarService getStatusBarService() {
698 synchronized (mServiceAquireLock) {
699 if (mStatusBarService == null) {
700 mStatusBarService = IStatusBarService.Stub.asInterface(
701 ServiceManager.getService("statusbar"));
702 }
703 return mStatusBarService;
704 }
705 }
706
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700707 /*
708 * We always let the sensor be switched on by default except when
709 * the user has explicitly disabled sensor based rotation or when the
710 * screen is switched off.
711 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700712 boolean needSensorRunningLp() {
Jeff Brownbcdfc622014-03-06 19:13:04 -0800713 if (mSupportAutoRotation) {
714 if (mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
715 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
716 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT
717 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) {
718 // If the application has explicitly requested to follow the
719 // orientation, then we need to turn the sensor on.
720 return true;
721 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800722 }
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700723 if ((mCarDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_CAR) ||
Jeff Brown1a693182011-11-08 14:44:16 -0800724 (mDeskDockEnablesAccelerometer && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
725 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
726 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK))) {
Mike Lockwoode9867d22009-09-20 01:59:02 -0400727 // enable accelerometer if we are docked in a dock that enables accelerometer
728 // orientation management,
729 return true;
730 }
Jeff Brown207673cd2012-06-05 17:47:11 -0700731 if (mUserRotationMode == USER_ROTATION_LOCKED) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800732 // If the setting for using the sensor by default is enabled, then
733 // we will always leave it on. Note that the user could go to
734 // a window that forces an orientation that does not use the
735 // sensor and in theory we could turn it off... however, when next
736 // turning it on we won't have a good value for the current
737 // orientation for a little bit, which can cause orientation
738 // changes to lag, so we'd like to keep it always on. (It will
739 // still be turned off when the screen is off.)
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700740 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800741 }
Jeff Brownbcdfc622014-03-06 19:13:04 -0800742 return mSupportAutoRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800743 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700744
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800745 /*
746 * Various use cases for invoking this function
747 * screen turning off, should always disable listeners if already enabled
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700748 * screen turned on and current app has sensor based orientation, enable listeners
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800749 * if not already enabled
750 * screen turned on and current app does not have sensor orientation, disable listeners if
751 * already enabled
752 * screen turning on and current app has sensor based orientation, enable listeners if needed
753 * screen turning on and current app has nosensor based orientation, do nothing
754 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700755 void updateOrientationListenerLp() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800756 if (!mOrientationListener.canDetectOrientation()) {
757 // If sensor is turned off or nonexistent for some reason
758 return;
759 }
760 //Could have been invoked due to screen turning on or off or
761 //change of the currently visible window's orientation
Craig Mautnereda67292013-04-28 13:50:14 -0700762 if (localLOGV) Slog.v(TAG, "Screen status="+mScreenOnEarly+
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800763 ", current orientation="+mCurrentAppOrientation+
764 ", SensorEnabled="+mOrientationSensorEnabled);
765 boolean disable = true;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -0700766 if (mScreenOnEarly) {
The Android Open Source Project0727d222009-03-11 12:11:58 -0700767 if (needSensorRunningLp()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800768 disable = false;
769 //enable listener if not already enabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700770 if (!mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800771 mOrientationListener.enable();
Craig Mautnereda67292013-04-28 13:50:14 -0700772 if(localLOGV) Slog.v(TAG, "Enabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800773 mOrientationSensorEnabled = true;
774 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700775 }
776 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800777 //check if sensors need to be disabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700778 if (disable && mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800779 mOrientationListener.disable();
Craig Mautnereda67292013-04-28 13:50:14 -0700780 if(localLOGV) Slog.v(TAG, "Disabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800781 mOrientationSensorEnabled = false;
782 }
783 }
784
Jeff Brown4d396052010-10-29 21:50:21 -0700785 private void interceptPowerKeyDown(boolean handled) {
786 mPowerKeyHandled = handled;
787 if (!handled) {
Justin Kohfeabd2c2014-05-02 10:02:44 -0700788 mHandler.postDelayed(mPowerLongPress,
789 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Jeff Brown4d396052010-10-29 21:50:21 -0700790 }
791 }
792
793 private boolean interceptPowerKeyUp(boolean canceled) {
794 if (!mPowerKeyHandled) {
795 mHandler.removeCallbacks(mPowerLongPress);
796 return !canceled;
Jeff Brown4d396052010-10-29 21:50:21 -0700797 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700798 return false;
799 }
800
801 private void cancelPendingPowerKeyAction() {
802 if (!mPowerKeyHandled) {
803 mHandler.removeCallbacks(mPowerLongPress);
804 }
Jeff Brownff204712011-10-25 21:27:54 -0700805 if (mPowerKeyTriggered) {
806 mPendingPowerKeyUpCanceled = true;
807 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700808 }
809
810 private void interceptScreenshotChord() {
Christopher Tatee90585f2012-03-05 18:56:25 -0800811 if (mScreenshotChordEnabled
812 && mVolumeDownKeyTriggered && mPowerKeyTriggered && !mVolumeUpKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700813 final long now = SystemClock.uptimeMillis();
814 if (now <= mVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS
815 && now <= mPowerKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) {
816 mVolumeDownKeyConsumedByScreenshotChord = true;
817 cancelPendingPowerKeyAction();
818
Jeff Sharkey2991fa32012-12-05 18:06:43 -0800819 mHandler.postDelayed(mScreenshotRunnable, getScreenshotChordLongPressDelay());
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700820 }
821 }
822 }
823
Winson Chung1cea2f32012-10-08 20:42:01 -0700824 private long getScreenshotChordLongPressDelay() {
Jim Miller5ecd8112013-01-09 18:50:26 -0800825 if (mKeyguardDelegate.isShowing()) {
Winson Chung1cea2f32012-10-08 20:42:01 -0700826 // Double the time it takes to take a screenshot from the keyguard
827 return (long) (KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER *
Justin Kohfeabd2c2014-05-02 10:02:44 -0700828 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Winson Chung1cea2f32012-10-08 20:42:01 -0700829 }
Justin Kohfeabd2c2014-05-02 10:02:44 -0700830 return ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout();
Winson Chung1cea2f32012-10-08 20:42:01 -0700831 }
832
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700833 private void cancelPendingScreenshotChordAction() {
Jeff Sharkey2991fa32012-12-05 18:06:43 -0800834 mHandler.removeCallbacks(mScreenshotRunnable);
Jeff Brown4d396052010-10-29 21:50:21 -0700835 }
836
Jeff Brown6d8fd272014-05-20 21:24:38 -0700837 private void powerShortPress(long eventTime) {
838 if (mShortPressOnPowerBehavior < 0) {
839 mShortPressOnPowerBehavior = mContext.getResources().getInteger(
840 com.android.internal.R.integer.config_shortPressOnPowerBehavior);
841 }
842
843 switch (mShortPressOnPowerBehavior) {
844 case SHORT_PRESS_POWER_NOTHING:
845 break;
846 case SHORT_PRESS_POWER_GO_TO_SLEEP:
847 mPowerManager.goToSleep(eventTime,
848 PowerManager.GO_TO_SLEEP_REASON_USER, 0);
849 break;
850 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP:
851 mPowerManager.goToSleep(eventTime,
852 PowerManager.GO_TO_SLEEP_REASON_USER,
853 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
854 break;
855 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME:
856 mPowerManager.goToSleep(eventTime,
857 PowerManager.GO_TO_SLEEP_REASON_USER,
858 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
859 launchHomeFromHotKey();
860 break;
861 }
862 }
863
Jeff Brown4d396052010-10-29 21:50:21 -0700864 private final Runnable mPowerLongPress = new Runnable() {
Craig Mautnerf1b67412012-09-19 13:18:29 -0700865 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800866 public void run() {
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700867 // The context isn't read
868 if (mLongPressOnPowerBehavior < 0) {
Jeff Brown850c5b72012-10-01 15:17:22 -0700869 mLongPressOnPowerBehavior = mContext.getResources().getInteger(
870 com.android.internal.R.integer.config_longPressOnPowerBehavior);
Joe Onoratod208e702010-10-08 16:22:43 -0400871 }
Jeff Brown850c5b72012-10-01 15:17:22 -0700872 int resolvedBehavior = mLongPressOnPowerBehavior;
873 if (FactoryTest.isLongPressOnPowerOffEnabled()) {
874 resolvedBehavior = LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM;
875 }
876
877 switch (resolvedBehavior) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700878 case LONG_PRESS_POWER_NOTHING:
879 break;
880 case LONG_PRESS_POWER_GLOBAL_ACTIONS:
881 mPowerKeyHandled = true;
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -0700882 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
883 performAuditoryFeedbackForAccessibilityIfNeed();
884 }
Alan Viverettee34560b22014-07-10 14:50:06 -0700885 showGlobalActionsInternal();
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700886 break;
887 case LONG_PRESS_POWER_SHUT_OFF:
Jeff Brown9a538ee2012-08-20 14:56:57 -0700888 case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM:
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700889 mPowerKeyHandled = true;
890 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
891 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
Jeff Brown850c5b72012-10-01 15:17:22 -0700892 mWindowManagerFuncs.shutdown(resolvedBehavior == LONG_PRESS_POWER_SHUT_OFF);
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700893 break;
894 }
895 }
896 };
897
Jeff Sharkey2991fa32012-12-05 18:06:43 -0800898 private final Runnable mScreenshotRunnable = new Runnable() {
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800899 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700900 public void run() {
901 takeScreenshot();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800902 }
903 };
904
Alan Viverettee34560b22014-07-10 14:50:06 -0700905 @Override
906 public void showGlobalActions() {
907 mHandler.removeMessages(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
908 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
909 }
910
911 void showGlobalActionsInternal() {
912 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800913 if (mGlobalActions == null) {
Jeff Brown7304c342012-05-11 18:42:42 -0700914 mGlobalActions = new GlobalActions(mContext, mWindowManagerFuncs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800915 }
Mike Lockwood3a74bd32011-08-12 13:55:22 -0700916 final boolean keyguardShowing = keyguardIsShowingTq();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800917 mGlobalActions.showDialog(keyguardShowing, isDeviceProvisioned());
918 if (keyguardShowing) {
919 // since it took two seconds of long press to bring this up,
920 // poke the wake lock so they have some time to see the dialog.
Jim Miller25190572013-02-28 17:36:24 -0800921 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800922 }
923 }
924
925 boolean isDeviceProvisioned() {
Jeff Brownbf6f6f92012-09-25 15:03:20 -0700926 return Settings.Global.getInt(
927 mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800928 }
929
Maurice Lam99c6e072014-04-28 18:24:28 -0700930 boolean isUserSetupComplete() {
931 return Settings.Secure.getIntForUser(mContext.getContentResolver(),
932 Settings.Secure.USER_SETUP_COMPLETE, 0, UserHandle.USER_CURRENT) != 0;
933 }
934
Patrick Dubroyece94522011-02-23 18:35:01 -0800935 private void handleLongPressOnHome() {
Joe Onorato46b0d682010-11-22 17:37:27 -0800936 if (mLongPressOnHomeBehavior != LONG_PRESS_HOME_NOTHING) {
Jeff Browncaca8812013-05-09 13:34:33 -0700937 mHomeConsumed = true;
Joe Onorato46b0d682010-11-22 17:37:27 -0800938 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
Patrick Dubroyece94522011-02-23 18:35:01 -0800939
Jeff Browncaca8812013-05-09 13:34:33 -0700940 if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI) {
941 toggleRecentApps();
942 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_ASSIST) {
943 launchAssistAction();
Jim Millere6ad1a82010-08-20 19:25:39 -0700944 }
945 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800946 }
Patrick Dubroyece94522011-02-23 18:35:01 -0800947
Jeff Browncaca8812013-05-09 13:34:33 -0700948 private void handleDoubleTapOnHome() {
949 if (mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
950 mHomeConsumed = true;
951 toggleRecentApps();
952 }
953 }
954
955 private final Runnable mHomeDoubleTapTimeoutRunnable = new Runnable() {
956 @Override
957 public void run() {
958 if (mHomeDoubleTapPending) {
959 mHomeDoubleTapPending = false;
960 launchHomeFromHotKey();
961 }
962 }
963 };
964
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800965 /** {@inheritDoc} */
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800966 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800967 public void init(Context context, IWindowManager windowManager,
Jeff Brown96307042012-07-27 15:51:34 -0700968 WindowManagerFuncs windowManagerFuncs) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800969 mContext = context;
970 mWindowManager = windowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700971 mWindowManagerFuncs = windowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -0700972 mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class);
Jose Lima9546b202014-07-02 17:21:51 -0700973 mDreamManagerInternal = LocalServices.getService(DreamManagerInternal.class);
Craig Mautner8a0da012014-05-31 15:13:37 -0700974
Jeff Brown70825162012-03-28 17:27:48 -0700975 mHandler = new PolicyHandler();
Jeff Browna20dda42014-05-27 20:57:24 -0700976 mWakeGestureListener = new MyWakeGestureListener(mContext, mHandler);
Craig Mautnereee29c42013-01-17 14:44:34 -0800977 mOrientationListener = new MyOrientationListener(mContext, mHandler);
Jeff Brownc0347aa2011-09-23 17:26:09 -0700978 try {
979 mOrientationListener.setCurrentRotation(windowManager.getRotation());
980 } catch (RemoteException ex) { }
Christopher Tate5e08af02012-09-21 17:17:22 -0700981 mSettingsObserver = new SettingsObserver(mHandler);
982 mSettingsObserver.observe();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800983 mShortcutManager = new ShortcutManager(context, mHandler);
984 mShortcutManager.observe();
Daniel Sandler6396c722013-04-16 20:19:09 -0400985 mUiMode = context.getResources().getInteger(
986 com.android.internal.R.integer.config_defaultUiModeType);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800987 mHomeIntent = new Intent(Intent.ACTION_MAIN, null);
988 mHomeIntent.addCategory(Intent.CATEGORY_HOME);
989 mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
990 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700991 mCarDockIntent = new Intent(Intent.ACTION_MAIN, null);
992 mCarDockIntent.addCategory(Intent.CATEGORY_CAR_DOCK);
993 mCarDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
994 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
995 mDeskDockIntent = new Intent(Intent.ACTION_MAIN, null);
996 mDeskDockIntent.addCategory(Intent.CATEGORY_DESK_DOCK);
997 mDeskDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
998 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Jim Millere6ad1a82010-08-20 19:25:39 -0700999
Jeff Brown96307042012-07-27 15:51:34 -07001000 mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
1001 mBroadcastWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001002 "PhoneWindowManager.mBroadcastWakeLock");
1003 mEnableShiftMenuBugReports = "1".equals(SystemProperties.get("ro.debuggable"));
Jeff Brownbcdfc622014-03-06 19:13:04 -08001004 mSupportAutoRotation = mContext.getResources().getBoolean(
1005 com.android.internal.R.bool.config_supportAutoRotation);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001006 mLidOpenRotation = readRotation(
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001007 com.android.internal.R.integer.config_lidOpenRotation);
1008 mCarDockRotation = readRotation(
1009 com.android.internal.R.integer.config_carDockRotation);
1010 mDeskDockRotation = readRotation(
1011 com.android.internal.R.integer.config_deskDockRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001012 mUndockedHdmiRotation = readRotation(
1013 com.android.internal.R.integer.config_undockedHdmiRotation);
Mike Lockwoode9867d22009-09-20 01:59:02 -04001014 mCarDockEnablesAccelerometer = mContext.getResources().getBoolean(
1015 com.android.internal.R.bool.config_carDockEnablesAccelerometer);
1016 mDeskDockEnablesAccelerometer = mContext.getResources().getBoolean(
1017 com.android.internal.R.bool.config_deskDockEnablesAccelerometer);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001018 mLidKeyboardAccessibility = mContext.getResources().getInteger(
1019 com.android.internal.R.integer.config_lidKeyboardAccessibility);
1020 mLidNavigationAccessibility = mContext.getResources().getInteger(
1021 com.android.internal.R.integer.config_lidNavigationAccessibility);
Jeff Brownc458ce92012-04-30 14:58:40 -07001022 mLidControlsSleep = mContext.getResources().getBoolean(
1023 com.android.internal.R.bool.config_lidControlsSleep);
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04001024 mTranslucentDecorEnabled = mContext.getResources().getBoolean(
1025 com.android.internal.R.bool.config_enableTranslucentDecor);
Jeff Brownf71343d2013-05-31 17:59:11 -07001026 readConfigurationDependentBehaviors();
Jeff Browncaca8812013-05-09 13:34:33 -07001027
Svetoslav8e3feb12014-02-24 13:46:47 -08001028 mAccessibilityManager = (AccessibilityManager) context.getSystemService(
1029 Context.ACCESSIBILITY_SERVICE);
1030
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001031 // register for dock events
Dianne Hackborn78968392010-03-04 20:47:56 -08001032 IntentFilter filter = new IntentFilter();
1033 filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE);
1034 filter.addAction(UiModeManager.ACTION_EXIT_CAR_MODE);
1035 filter.addAction(UiModeManager.ACTION_ENTER_DESK_MODE);
1036 filter.addAction(UiModeManager.ACTION_EXIT_DESK_MODE);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001037 filter.addAction(Intent.ACTION_DOCK_EVENT);
1038 Intent intent = context.registerReceiver(mDockReceiver, filter);
1039 if (intent != null) {
1040 // Retrieve current sticky dock event broadcast.
1041 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
1042 Intent.EXTRA_DOCK_STATE_UNDOCKED);
1043 }
Daniel Sandler7e37df52011-11-16 22:08:23 -08001044
Jeff Brown6aaf2952012-10-05 16:01:08 -07001045 // register for dream-related broadcasts
1046 filter = new IntentFilter();
1047 filter.addAction(Intent.ACTION_DREAMING_STARTED);
1048 filter.addAction(Intent.ACTION_DREAMING_STOPPED);
1049 context.registerReceiver(mDreamReceiver, filter);
1050
Christopher Tate5e08af02012-09-21 17:17:22 -07001051 // register for multiuser-relevant broadcasts
1052 filter = new IntentFilter(Intent.ACTION_USER_SWITCHED);
1053 context.registerReceiver(mMultiuserReceiver, filter);
1054
John Spurlock57306e62013-04-22 09:48:49 -04001055 // monitor for system gestures
Craig Mautner037aa8d2013-06-07 10:35:44 -07001056 mSystemGestures = new SystemGesturesPointerEventListener(context,
1057 new SystemGesturesPointerEventListener.Callbacks() {
John Spurlock57306e62013-04-22 09:48:49 -04001058 @Override
1059 public void onSwipeFromTop() {
John Spurlock04db1762013-05-13 12:46:41 -04001060 if (mStatusBar != null) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001061 requestTransientBars(mStatusBar);
John Spurlock04db1762013-05-13 12:46:41 -04001062 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04001063 }
1064 @Override
1065 public void onSwipeFromBottom() {
John Spurlock04db1762013-05-13 12:46:41 -04001066 if (mNavigationBar != null && mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001067 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001068 }
1069 }
1070 @Override
1071 public void onSwipeFromRight() {
John Spurlock04db1762013-05-13 12:46:41 -04001072 if (mNavigationBar != null && !mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001073 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001074 }
1075 }
1076 @Override
1077 public void onDebug() {
John Spurlockd67ec252013-09-05 11:31:54 -04001078 // no-op
John Spurlockad3e6cb2013-04-30 08:47:43 -04001079 }
1080 });
John Spurlockf1a36642013-10-12 17:50:42 -04001081 mImmersiveModeConfirmation = new ImmersiveModeConfirmation(mContext);
Craig Mautner037aa8d2013-06-07 10:35:44 -07001082 mWindowManagerFuncs.registerPointerEventListener(mSystemGestures);
John Spurlock32beb2c2013-03-11 10:16:47 -04001083
Jeff Brownc2346132012-04-13 01:55:38 -07001084 mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001085 mLongPressVibePattern = getLongIntArray(mContext.getResources(),
1086 com.android.internal.R.array.config_longPressVibePattern);
1087 mVirtualKeyVibePattern = getLongIntArray(mContext.getResources(),
1088 com.android.internal.R.array.config_virtualKeyVibePattern);
Amith Yamasanic33cb712010-02-10 15:21:49 -08001089 mKeyboardTapVibePattern = getLongIntArray(mContext.getResources(),
1090 com.android.internal.R.array.config_keyboardTapVibePattern);
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07001091 mClockTickVibePattern = getLongIntArray(mContext.getResources(),
1092 com.android.internal.R.array.config_clockTickVibePattern);
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07001093 mCalendarDateVibePattern = getLongIntArray(mContext.getResources(),
1094 com.android.internal.R.array.config_calendarDateVibePattern);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001095 mSafeModeDisabledVibePattern = getLongIntArray(mContext.getResources(),
1096 com.android.internal.R.array.config_safeModeDisabledVibePattern);
1097 mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(),
1098 com.android.internal.R.array.config_safeModeEnabledVibePattern);
Daniel Sandler40427442010-07-16 11:44:52 -04001099
Christopher Tatee90585f2012-03-05 18:56:25 -08001100 mScreenshotChordEnabled = mContext.getResources().getBoolean(
1101 com.android.internal.R.bool.config_enableScreenshotChord);
1102
Justin Kohd378ad72013-04-01 12:18:26 -07001103 mGlobalKeyManager = new GlobalKeyManager(mContext);
1104
Joe Onoratoea495d42011-04-06 11:41:11 -07001105 // Controls rotation and the like.
1106 initializeHdmiState();
Dianne Hackborn40011092011-09-22 13:37:48 -07001107
1108 // Match current screen state.
Craig Mautnera631d492014-08-05 15:16:01 -07001109 if (!mPowerManager.isInteractive()) {
Jeff Brown140ffc72014-05-01 15:18:00 -07001110 goingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
Dianne Hackborn40011092011-09-22 13:37:48 -07001111 }
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001112 }
1113
Jeff Brownf71343d2013-05-31 17:59:11 -07001114 /**
1115 * Read values from config.xml that may be overridden depending on
1116 * the configuration of the device.
1117 * eg. Disable long press on home goes to recents on sw600dp.
1118 */
1119 private void readConfigurationDependentBehaviors() {
1120 mLongPressOnHomeBehavior = mContext.getResources().getInteger(
1121 com.android.internal.R.integer.config_longPressOnHomeBehavior);
1122 if (mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING ||
1123 mLongPressOnHomeBehavior > LONG_PRESS_HOME_ASSIST) {
1124 mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1125 }
1126
1127 mDoubleTapOnHomeBehavior = mContext.getResources().getInteger(
1128 com.android.internal.R.integer.config_doubleTapOnHomeBehavior);
1129 if (mDoubleTapOnHomeBehavior < DOUBLE_TAP_HOME_NOTHING ||
1130 mDoubleTapOnHomeBehavior > DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1131 mDoubleTapOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1132 }
1133 }
1134
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001135 @Override
Dianne Hackborndde331c2012-08-03 14:01:57 -07001136 public void setInitialDisplaySize(Display display, int width, int height, int density) {
Jeff Brownef981a42013-08-07 14:13:37 -07001137 // This method might be called before the policy has been fully initialized
1138 // or for other displays we don't care about.
1139 if (mContext == null || display.getDisplayId() != Display.DEFAULT_DISPLAY) {
1140 return;
Dianne Hackbornc652de82013-02-15 16:32:56 -08001141 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001142 mDisplay = display;
1143
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001144 final Resources res = mContext.getResources();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001145 int shortSize, longSize;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001146 if (width > height) {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001147 shortSize = height;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001148 longSize = width;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001149 mLandscapeRotation = Surface.ROTATION_0;
1150 mSeascapeRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001151 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001152 mPortraitRotation = Surface.ROTATION_90;
1153 mUpsideDownRotation = Surface.ROTATION_270;
1154 } else {
1155 mPortraitRotation = Surface.ROTATION_270;
1156 mUpsideDownRotation = Surface.ROTATION_90;
1157 }
1158 } else {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001159 shortSize = width;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001160 longSize = height;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001161 mPortraitRotation = Surface.ROTATION_0;
1162 mUpsideDownRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001163 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001164 mLandscapeRotation = Surface.ROTATION_270;
1165 mSeascapeRotation = Surface.ROTATION_90;
1166 } else {
1167 mLandscapeRotation = Surface.ROTATION_90;
1168 mSeascapeRotation = Surface.ROTATION_270;
1169 }
1170 }
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001171
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001172 mStatusBarHeight =
1173 res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001174
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001175 // Height of the navigation bar when presented horizontally at bottom
1176 mNavigationBarHeightForRotation[mPortraitRotation] =
1177 mNavigationBarHeightForRotation[mUpsideDownRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001178 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_height);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001179 mNavigationBarHeightForRotation[mLandscapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001180 mNavigationBarHeightForRotation[mSeascapeRotation] = res.getDimensionPixelSize(
1181 com.android.internal.R.dimen.navigation_bar_height_landscape);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001182
1183 // Width of the navigation bar when presented vertically along one side
1184 mNavigationBarWidthForRotation[mPortraitRotation] =
1185 mNavigationBarWidthForRotation[mUpsideDownRotation] =
1186 mNavigationBarWidthForRotation[mLandscapeRotation] =
1187 mNavigationBarWidthForRotation[mSeascapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001188 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_width);
Daniel Sandler4a066c52012-04-20 14:49:13 -04001189
1190 // SystemUI (status bar) layout policy
Dianne Hackborndde331c2012-08-03 14:01:57 -07001191 int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / density;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001192 int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / density;
Daniel Sandler4a066c52012-04-20 14:49:13 -04001193
Craig Mautnerd4ec33242013-07-22 10:37:43 -07001194 // Allow the navigation bar to move on small devices (phones).
1195 mNavigationBarCanMove = shortSizeDp < 600;
Daniel Sandler36412a72011-08-04 09:35:13 -04001196
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001197 mHasNavigationBar = res.getBoolean(com.android.internal.R.bool.config_showNavigationBar);
John Spurlock80f00c12013-06-13 11:10:51 -04001198 // Allow a system property to override this. Used by the emulator.
1199 // See also hasNavigationBar().
1200 String navBarOverride = SystemProperties.get("qemu.hw.mainkeys");
1201 if ("1".equals(navBarOverride)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001202 mHasNavigationBar = false;
John Spurlock80f00c12013-06-13 11:10:51 -04001203 } else if ("0".equals(navBarOverride)) {
1204 mHasNavigationBar = true;
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04001205 }
1206
Jeff Brown27f1d672012-10-17 18:32:34 -07001207 // For demo purposes, allow the rotation of the HDMI display to be controlled.
1208 // By default, HDMI locks rotation to landscape.
Erik Gilling9a41ef82011-09-26 19:21:03 -07001209 if ("portrait".equals(SystemProperties.get("persist.demo.hdmirotation"))) {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001210 mDemoHdmiRotation = mPortraitRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001211 } else {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001212 mDemoHdmiRotation = mLandscapeRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001213 }
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001214 mDemoHdmiRotationLock = SystemProperties.getBoolean("persist.demo.hdmirotationlock", false);
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001215
1216 // Only force the default orientation if the screen is xlarge, at least 960dp x 720dp, per
1217 // http://developer.android.com/guide/practices/screens_support.html#range
1218 mForceDefaultOrientation = longSizeDp >= 960 && shortSizeDp >= 720 &&
1219 res.getBoolean(com.android.internal.R.bool.config_forceDefaultOrientation) &&
1220 // For debug purposes the next line turns this feature off with:
1221 // $ adb shell setprop config.override_forced_orient true
1222 // $ adb shell wm size reset
1223 !"true".equals(SystemProperties.get("config.override_forced_orient"));
1224 }
1225
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001226 /**
1227 * @return whether the navigation bar can be hidden, e.g. the device has a
1228 * navigation bar and touch exploration is not enabled
1229 */
1230 private boolean canHideNavigationBar() {
Svetoslav8e3feb12014-02-24 13:46:47 -08001231 return mHasNavigationBar
1232 && !mAccessibilityManager.isTouchExplorationEnabled();
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001233 }
1234
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001235 @Override
1236 public boolean isDefaultOrientationForced() {
1237 return mForceDefaultOrientation;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001238 }
1239
Dianne Hackbornc652de82013-02-15 16:32:56 -08001240 @Override
1241 public void setDisplayOverscan(Display display, int left, int top, int right, int bottom) {
1242 if (display.getDisplayId() == Display.DEFAULT_DISPLAY) {
1243 mOverscanLeft = left;
1244 mOverscanTop = top;
1245 mOverscanRight = right;
1246 mOverscanBottom = bottom;
1247 }
1248 }
1249
Dianne Hackbornc777e072010-02-12 13:07:59 -08001250 public void updateSettings() {
1251 ContentResolver resolver = mContext.getContentResolver();
1252 boolean updateRotation = false;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001253 synchronized (mLock) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001254 mEndcallBehavior = Settings.System.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001255 Settings.System.END_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001256 Settings.System.END_BUTTON_BEHAVIOR_DEFAULT,
1257 UserHandle.USER_CURRENT);
1258 mIncallPowerBehavior = Settings.Secure.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001259 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001260 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT,
1261 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001262
Jeff Browna20dda42014-05-27 20:57:24 -07001263 // Configure wake gesture.
1264 boolean wakeGestureEnabledSetting = Settings.Secure.getIntForUser(resolver,
1265 Settings.Secure.WAKE_GESTURE_ENABLED, 0,
1266 UserHandle.USER_CURRENT) != 0;
1267 if (mWakeGestureEnabledSetting != wakeGestureEnabledSetting) {
1268 mWakeGestureEnabledSetting = wakeGestureEnabledSetting;
1269 updateWakeGestureListenerLp();
1270 }
1271
Jeff Brown207673cd2012-06-05 17:47:11 -07001272 // Configure rotation lock.
Christopher Tate5e08af02012-09-21 17:17:22 -07001273 int userRotation = Settings.System.getIntForUser(resolver,
1274 Settings.System.USER_ROTATION, Surface.ROTATION_0,
1275 UserHandle.USER_CURRENT);
Jeff Brown207673cd2012-06-05 17:47:11 -07001276 if (mUserRotation != userRotation) {
1277 mUserRotation = userRotation;
1278 updateRotation = true;
1279 }
Christopher Tate5e08af02012-09-21 17:17:22 -07001280 int userRotationMode = Settings.System.getIntForUser(resolver,
1281 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
Jeff Brown207673cd2012-06-05 17:47:11 -07001282 WindowManagerPolicy.USER_ROTATION_FREE :
1283 WindowManagerPolicy.USER_ROTATION_LOCKED;
1284 if (mUserRotationMode != userRotationMode) {
1285 mUserRotationMode = userRotationMode;
1286 updateRotation = true;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001287 updateOrientationListenerLp();
1288 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001289
Dianne Hackbornc777e072010-02-12 13:07:59 -08001290 if (mSystemReady) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001291 int pointerLocation = Settings.System.getIntForUser(resolver,
1292 Settings.System.POINTER_LOCATION, 0, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001293 if (mPointerLocationMode != pointerLocation) {
1294 mPointerLocationMode = pointerLocation;
Jeff Brown70825162012-03-28 17:27:48 -07001295 mHandler.sendEmptyMessage(pointerLocation != 0 ?
1296 MSG_ENABLE_POINTER_LOCATION : MSG_DISABLE_POINTER_LOCATION);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001297 }
1298 }
1299 // use screen off timeout setting as the timeout for the lockscreen
Christopher Tate5e08af02012-09-21 17:17:22 -07001300 mLockScreenTimeout = Settings.System.getIntForUser(resolver,
1301 Settings.System.SCREEN_OFF_TIMEOUT, 0, UserHandle.USER_CURRENT);
1302 String imId = Settings.Secure.getStringForUser(resolver,
1303 Settings.Secure.DEFAULT_INPUT_METHOD, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001304 boolean hasSoftInput = imId != null && imId.length() > 0;
1305 if (mHasSoftInput != hasSoftInput) {
1306 mHasSoftInput = hasSoftInput;
1307 updateRotation = true;
1308 }
John Spurlockf1a36642013-10-12 17:50:42 -04001309 if (mImmersiveModeConfirmation != null) {
John Spurlock4355a532014-02-19 09:49:25 -05001310 mImmersiveModeConfirmation.loadSetting(mCurrentUserId);
John Spurlockd67ec252013-09-05 11:31:54 -04001311 }
John Spurlockc6d1c602014-01-17 15:22:06 -05001312 PolicyControl.reloadFromSetting(mContext);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001313 }
1314 if (updateRotation) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07001315 updateRotation(true);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001316 }
Jeff Brown70825162012-03-28 17:27:48 -07001317 }
1318
Jeff Browna20dda42014-05-27 20:57:24 -07001319 private void updateWakeGestureListenerLp() {
1320 if (shouldEnableWakeGestureLp()) {
1321 mWakeGestureListener.requestWakeUpTrigger();
1322 } else {
1323 mWakeGestureListener.cancelWakeUpTrigger();
1324 }
1325 }
1326
1327 private boolean shouldEnableWakeGestureLp() {
1328 return mWakeGestureEnabledSetting && !mScreenOnEarly
1329 && (!mLidControlsSleep || mLidState != LID_CLOSED)
1330 && mWakeGestureListener.isSupported();
1331 }
1332
Jeff Brown70825162012-03-28 17:27:48 -07001333 private void enablePointerLocation() {
1334 if (mPointerLocationView == null) {
1335 mPointerLocationView = new PointerLocationView(mContext);
1336 mPointerLocationView.setPrintCoords(false);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001337 WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
1338 WindowManager.LayoutParams.MATCH_PARENT,
1339 WindowManager.LayoutParams.MATCH_PARENT);
Jeff Brown3b2b3542010-10-15 00:54:27 -07001340 lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001341 lp.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN
1342 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
1343 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1344 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
Jeff Brown90fc9052012-10-01 14:44:24 -07001345 if (ActivityManager.isHighEndGfx()) {
1346 lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
1347 lp.privateFlags |=
1348 WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED;
1349 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001350 lp.format = PixelFormat.TRANSLUCENT;
1351 lp.setTitle("PointerLocation");
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001352 WindowManager wm = (WindowManager)
Dianne Hackbornc777e072010-02-12 13:07:59 -08001353 mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Browncc4f7db2011-08-30 20:34:48 -07001354 lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL;
Jeff Brown70825162012-03-28 17:27:48 -07001355 wm.addView(mPointerLocationView, lp);
Michael Wrightc9c487e2013-11-07 18:55:09 -08001356 mWindowManagerFuncs.registerPointerEventListener(mPointerLocationView);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001357 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001358 }
Jeff Brown70825162012-03-28 17:27:48 -07001359
1360 private void disablePointerLocation() {
Jeff Brown70825162012-03-28 17:27:48 -07001361 if (mPointerLocationView != null) {
Michael Wrightc9c487e2013-11-07 18:55:09 -08001362 mWindowManagerFuncs.unregisterPointerEventListener(mPointerLocationView);
1363 WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Brown70825162012-03-28 17:27:48 -07001364 wm.removeView(mPointerLocationView);
1365 mPointerLocationView = null;
1366 }
1367 }
1368
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001369 private int readRotation(int resID) {
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001370 try {
1371 int rotation = mContext.getResources().getInteger(resID);
1372 switch (rotation) {
1373 case 0:
1374 return Surface.ROTATION_0;
1375 case 90:
1376 return Surface.ROTATION_90;
1377 case 180:
1378 return Surface.ROTATION_180;
1379 case 270:
1380 return Surface.ROTATION_270;
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001381 }
1382 } catch (Resources.NotFoundException e) {
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001383 // fall through
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001384 }
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001385 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001386 }
1387
1388 /** {@inheritDoc} */
Craig Mautner88400d32012-09-30 12:35:45 -07001389 @Override
Dianne Hackbornc2293022013-02-06 23:14:49 -08001390 public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001391 int type = attrs.type;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001392
1393 outAppOp[0] = AppOpsManager.OP_NONE;
1394
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001395 if (type < WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW
1396 || type > WindowManager.LayoutParams.LAST_SYSTEM_WINDOW) {
Jeff Brown98365d72012-08-19 20:30:52 -07001397 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001398 }
1399 String permission = null;
1400 switch (type) {
1401 case TYPE_TOAST:
1402 // XXX right now the app process has complete control over
1403 // this... should introduce a token to let the system
1404 // monitor/control what they are doing.
Jason Monk1c7c3192014-06-26 12:52:18 -04001405 outAppOp[0] = AppOpsManager.OP_TOAST_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001406 break;
Daniel Sandler7d276c32012-01-30 14:33:52 -05001407 case TYPE_DREAM:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001408 case TYPE_INPUT_METHOD:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001409 case TYPE_WALLPAPER:
keunyounga446bf02013-06-21 19:07:57 -07001410 case TYPE_PRIVATE_PRESENTATION:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001411 case TYPE_VOICE_INTERACTION:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001412 // The window manager will check these.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001413 break;
1414 case TYPE_PHONE:
1415 case TYPE_PRIORITY_PHONE:
1416 case TYPE_SYSTEM_ALERT:
1417 case TYPE_SYSTEM_ERROR:
1418 case TYPE_SYSTEM_OVERLAY:
1419 permission = android.Manifest.permission.SYSTEM_ALERT_WINDOW;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001420 outAppOp[0] = AppOpsManager.OP_SYSTEM_ALERT_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001421 break;
1422 default:
1423 permission = android.Manifest.permission.INTERNAL_SYSTEM_WINDOW;
1424 }
1425 if (permission != null) {
1426 if (mContext.checkCallingOrSelfPermission(permission)
1427 != PackageManager.PERMISSION_GRANTED) {
Jeff Brown98365d72012-08-19 20:30:52 -07001428 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001429 }
1430 }
Jeff Brown98365d72012-08-19 20:30:52 -07001431 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001432 }
Craig Mautner88400d32012-09-30 12:35:45 -07001433
1434 @Override
1435 public boolean checkShowToOwnerOnly(WindowManager.LayoutParams attrs) {
1436
1437 // If this switch statement is modified, modify the comment in the declarations of
1438 // the type in {@link WindowManager.LayoutParams} as well.
1439 switch (attrs.type) {
1440 default:
1441 // These are the windows that by default are shown only to the user that created
1442 // them. If this needs to be overridden, set
1443 // {@link WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS} in
1444 // {@link WindowManager.LayoutParams}. Note that permission
1445 // {@link android.Manifest.permission.INTERNAL_SYSTEM_WINDOW} is required as well.
1446 if ((attrs.privateFlags & PRIVATE_FLAG_SHOW_FOR_ALL_USERS) == 0) {
1447 return true;
1448 }
1449 break;
1450
1451 // These are the windows that by default are shown to all users. However, to
1452 // protect against spoofing, check permissions below.
1453 case TYPE_APPLICATION_STARTING:
1454 case TYPE_BOOT_PROGRESS:
1455 case TYPE_DISPLAY_OVERLAY:
1456 case TYPE_HIDDEN_NAV_CONSUMER:
Jim Miller5ecd8112013-01-09 18:50:26 -08001457 case TYPE_KEYGUARD_SCRIM:
Craig Mautner88400d32012-09-30 12:35:45 -07001458 case TYPE_KEYGUARD_DIALOG:
1459 case TYPE_MAGNIFICATION_OVERLAY:
1460 case TYPE_NAVIGATION_BAR:
1461 case TYPE_NAVIGATION_BAR_PANEL:
1462 case TYPE_PHONE:
1463 case TYPE_POINTER:
1464 case TYPE_PRIORITY_PHONE:
1465 case TYPE_RECENTS_OVERLAY:
1466 case TYPE_SEARCH_BAR:
1467 case TYPE_STATUS_BAR:
1468 case TYPE_STATUS_BAR_PANEL:
1469 case TYPE_STATUS_BAR_SUB_PANEL:
1470 case TYPE_SYSTEM_DIALOG:
1471 case TYPE_UNIVERSE_BACKGROUND:
1472 case TYPE_VOLUME_OVERLAY:
keunyounga446bf02013-06-21 19:07:57 -07001473 case TYPE_PRIVATE_PRESENTATION:
Craig Mautner88400d32012-09-30 12:35:45 -07001474 break;
1475 }
1476
1477 // Check if third party app has set window to system window type.
1478 return mContext.checkCallingOrSelfPermission(
1479 android.Manifest.permission.INTERNAL_SYSTEM_WINDOW)
1480 != PackageManager.PERMISSION_GRANTED;
1481 }
1482
Craig Mautner967212c2013-04-13 21:10:58 -07001483 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001484 public void adjustWindowParamsLw(WindowManager.LayoutParams attrs) {
1485 switch (attrs.type) {
1486 case TYPE_SYSTEM_OVERLAY:
Jeff Brown3b2b3542010-10-15 00:54:27 -07001487 case TYPE_SECURE_SYSTEM_OVERLAY:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001488 // These types of windows can't receive input events.
1489 attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1490 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001491 attrs.flags &= ~WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001492 break;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001493 case TYPE_STATUS_BAR:
1494
1495 // If the Keyguard is in a hidden state (occluded by another window), we force to
1496 // remove the wallpaper and keyguard flag so that any change in-flight after setting
1497 // the keyguard as occluded wouldn't set these flags again.
1498 // See {@link #processKeyguardSetHiddenResultLw}.
1499 if (mKeyguardHidden) {
1500 attrs.flags &= ~WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
1501 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
1502 }
1503 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001504 }
Adrian Roos38502112014-04-09 21:04:11 +02001505
1506 if (attrs.type != TYPE_STATUS_BAR) {
1507 // The status bar is the only window allowed to exhibit keyguard behavior.
1508 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
1509 }
Adrian Roosea562512014-05-05 13:33:03 +02001510
1511 if (ActivityManager.isHighEndGfx()
1512 && (attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0) {
1513 attrs.subtreeSystemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_STABLE
1514 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
1515 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
1516 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001517 }
RoboErik8a2cfc32014-05-16 11:19:38 -07001518
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001519 void readLidState() {
Jeff Brown2e7760e2012-04-11 15:14:55 -07001520 mLidState = mWindowManagerFuncs.getLidState();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001521 }
RoboErik8a2cfc32014-05-16 11:19:38 -07001522
Jeff Browndaa37532012-05-01 15:54:03 -07001523 private boolean isHidden(int accessibilityMode) {
1524 switch (accessibilityMode) {
1525 case 1:
1526 return mLidState == LID_CLOSED;
1527 case 2:
1528 return mLidState == LID_OPEN;
1529 default:
1530 return false;
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001531 }
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001532 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001533
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001534 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07001535 @Override
Jeff Browndaa37532012-05-01 15:54:03 -07001536 public void adjustConfigurationLw(Configuration config, int keyboardPresence,
1537 int navigationPresence) {
1538 mHaveBuiltInKeyboard = (keyboardPresence & PRESENCE_INTERNAL) != 0;
1539
Jeff Brownf71343d2013-05-31 17:59:11 -07001540 readConfigurationDependentBehaviors();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001541 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07001542 applyLidSwitchState();
Jeff Brownd04a88c2011-01-16 14:05:47 -08001543
Jeff Browndaa37532012-05-01 15:54:03 -07001544 if (config.keyboard == Configuration.KEYBOARD_NOKEYS
1545 || (keyboardPresence == PRESENCE_INTERNAL
1546 && isHidden(mLidKeyboardAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001547 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_YES;
Jeff Browndaa37532012-05-01 15:54:03 -07001548 if (!mHasSoftInput) {
1549 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_YES;
1550 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001551 }
1552
Jeff Browndaa37532012-05-01 15:54:03 -07001553 if (config.navigation == Configuration.NAVIGATION_NONAV
1554 || (navigationPresence == PRESENCE_INTERNAL
1555 && isHidden(mLidNavigationAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001556 config.navigationHidden = Configuration.NAVIGATIONHIDDEN_YES;
Jeff Brownd04a88c2011-01-16 14:05:47 -08001557 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001558 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001559
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001560 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07001561 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001562 public int windowTypeToLayerLw(int type) {
1563 if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001564 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001565 }
1566 switch (type) {
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001567 case TYPE_UNIVERSE_BACKGROUND:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001568 return 1;
keunyounga446bf02013-06-21 19:07:57 -07001569 case TYPE_PRIVATE_PRESENTATION:
1570 return 2;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001571 case TYPE_WALLPAPER:
1572 // wallpaper is at the bottom, though the window manager may move it.
1573 return 2;
1574 case TYPE_PHONE:
1575 return 3;
1576 case TYPE_SEARCH_BAR:
1577 return 4;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001578 case TYPE_VOICE_INTERACTION:
1579 // voice interaction layer is almost immediately above apps.
1580 return 5;
Craig Mautner88400d32012-09-30 12:35:45 -07001581 case TYPE_RECENTS_OVERLAY:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001582 case TYPE_SYSTEM_DIALOG:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001583 return 6;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001584 case TYPE_TOAST:
1585 // toasts and the plugged-in battery thing
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001586 return 7;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001587 case TYPE_PRIORITY_PHONE:
1588 // SIM errors and unlock. Not sure if this really should be in a high layer.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001589 return 8;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001590 case TYPE_DREAM:
1591 // used for Dreams (screensavers with TYPE_DREAM windows)
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001592 return 9;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001593 case TYPE_SYSTEM_ALERT:
1594 // like the ANR / app crashed dialogs
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001595 return 10;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001596 case TYPE_INPUT_METHOD:
1597 // on-screen keyboards and other such input method user interfaces go here.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001598 return 11;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001599 case TYPE_INPUT_METHOD_DIALOG:
1600 // on-screen keyboards and other such input method user interfaces go here.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001601 return 12;
Jim Miller5ecd8112013-01-09 18:50:26 -08001602 case TYPE_KEYGUARD_SCRIM:
1603 // the safety window that shows behind keyguard while keyguard is starting
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001604 return 13;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001605 case TYPE_STATUS_BAR_SUB_PANEL:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001606 return 14;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001607 case TYPE_STATUS_BAR:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001608 return 15;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001609 case TYPE_STATUS_BAR_PANEL:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001610 return 16;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001611 case TYPE_KEYGUARD_DIALOG:
1612 return 17;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001613 case TYPE_VOLUME_OVERLAY:
1614 // the on-screen volume indicator and controller shown when the user
1615 // changes the device volume
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001616 return 18;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001617 case TYPE_SYSTEM_OVERLAY:
1618 // the on-screen volume indicator and controller shown when the user
1619 // changes the device volume
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001620 return 19;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001621 case TYPE_NAVIGATION_BAR:
1622 // the navigation bar, if available, shows atop most things
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001623 return 20;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001624 case TYPE_NAVIGATION_BAR_PANEL:
1625 // some panels (e.g. search) need to show on top of the navigation bar
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001626 return 21;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001627 case TYPE_SYSTEM_ERROR:
1628 // system-level error dialogs
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001629 return 22;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001630 case TYPE_MAGNIFICATION_OVERLAY:
1631 // used to highlight the magnified portion of a display
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001632 return 23;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001633 case TYPE_DISPLAY_OVERLAY:
1634 // used to simulate secondary display devices
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001635 return 24;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001636 case TYPE_DRAG:
1637 // the drag layer: input for drag-and-drop is associated with this window,
1638 // which sits above all other focusable windows
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001639 return 25;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001640 case TYPE_SECURE_SYSTEM_OVERLAY:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001641 return 26;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001642 case TYPE_BOOT_PROGRESS:
1643 return 27;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001644 case TYPE_POINTER:
1645 // the (mouse) pointer layer
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001646 return 28;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001647 case TYPE_HIDDEN_NAV_CONSUMER:
1648 return 29;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001649 }
1650 Log.e(TAG, "Unknown window type: " + type);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001651 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001652 }
1653
1654 /** {@inheritDoc} */
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001655 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001656 public int subWindowTypeToLayerLw(int type) {
1657 switch (type) {
1658 case TYPE_APPLICATION_PANEL:
1659 case TYPE_APPLICATION_ATTACHED_DIALOG:
1660 return APPLICATION_PANEL_SUBLAYER;
1661 case TYPE_APPLICATION_MEDIA:
1662 return APPLICATION_MEDIA_SUBLAYER;
Dianne Hackborn5cb8d792009-05-21 17:34:15 -07001663 case TYPE_APPLICATION_MEDIA_OVERLAY:
1664 return APPLICATION_MEDIA_OVERLAY_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001665 case TYPE_APPLICATION_SUB_PANEL:
1666 return APPLICATION_SUB_PANEL_SUBLAYER;
1667 }
1668 Log.e(TAG, "Unknown sub-window type: " + type);
1669 return 0;
1670 }
1671
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001672 @Override
Dianne Hackbornabe0da02009-09-18 01:55:39 -07001673 public int getMaxWallpaperLayer() {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001674 return windowTypeToLayerLw(TYPE_STATUS_BAR);
Dianne Hackbornabe0da02009-09-18 01:55:39 -07001675 }
1676
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001677 @Override
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001678 public int getAboveUniverseLayer() {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001679 return windowTypeToLayerLw(TYPE_SYSTEM_ERROR);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001680 }
1681
Jose Lima9546b202014-07-02 17:21:51 -07001682 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001683 public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07001684 if (mHasNavigationBar) {
1685 // For a basic navigation bar, when we are in landscape mode we place
1686 // the navigation bar to the side.
Daniel Sandler4a066c52012-04-20 14:49:13 -04001687 if (mNavigationBarCanMove && fullWidth > fullHeight) {
1688 return fullWidth - mNavigationBarWidthForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07001689 }
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001690 }
1691 return fullWidth;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001692 }
1693
Jose Lima9546b202014-07-02 17:21:51 -07001694 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001695 public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07001696 if (mHasNavigationBar) {
1697 // For a basic navigation bar, when we are in portrait mode we place
1698 // the navigation bar to the bottom.
Daniel Sandler4a066c52012-04-20 14:49:13 -04001699 if (!mNavigationBarCanMove || fullWidth < fullHeight) {
1700 return fullHeight - mNavigationBarHeightForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07001701 }
1702 }
1703 return fullHeight;
Dianne Hackborn69cb8752011-05-19 18:13:32 -07001704 }
1705
Jose Lima9546b202014-07-02 17:21:51 -07001706 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001707 public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation) {
1708 return getNonDecorDisplayWidth(fullWidth, fullHeight, rotation);
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 getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation) {
John Spurlock80f00c12013-06-13 11:10:51 -04001713 // There is a separate status bar at the top of the display. We don't count that as part
1714 // of the fixed decor, since it can hide; however, for purposes of configurations,
Dianne Hackborn077ee852012-04-09 16:27:07 -07001715 // we do want to exclude it since applications can't generally use that part
1716 // of the screen.
John Spurlock80f00c12013-06-13 11:10:51 -04001717 return getNonDecorDisplayHeight(fullWidth, fullHeight, rotation) - mStatusBarHeight;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001718 }
1719
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001720 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07001721 public boolean isForceHiding(WindowManager.LayoutParams attrs) {
1722 return (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 ||
Adrian Roos69e510d2014-07-13 14:57:59 +02001723 (isKeyguardHostWindow(attrs) && isKeyguardSecureIncludingHidden()) ||
1724 (attrs.type == TYPE_KEYGUARD_SCRIM);
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07001725 }
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001726
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001727 @Override
Jorim Jaggi0d674622014-05-21 01:34:15 +02001728 public boolean isKeyguardHostWindow(WindowManager.LayoutParams attrs) {
1729 return attrs.type == TYPE_STATUS_BAR;
1730 }
1731
1732 @Override
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07001733 public boolean canBeForceHidden(WindowState win, WindowManager.LayoutParams attrs) {
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001734 switch (attrs.type) {
1735 case TYPE_STATUS_BAR:
1736 case TYPE_NAVIGATION_BAR:
1737 case TYPE_WALLPAPER:
1738 case TYPE_DREAM:
1739 case TYPE_UNIVERSE_BACKGROUND:
Jim Miller5ecd8112013-01-09 18:50:26 -08001740 case TYPE_KEYGUARD_SCRIM:
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001741 return false;
1742 default:
1743 return true;
1744 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07001745 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001746
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001747 /** {@inheritDoc} */
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001748 @Override
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07001749 public View addStartingWindow(IBinder appToken, String packageName, int theme,
1750 CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes,
Adam Powell04fe6eb2013-05-31 14:39:48 -07001751 int icon, int logo, int windowFlags) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001752 if (!SHOW_STARTING_ANIMATIONS) {
1753 return null;
1754 }
1755 if (packageName == null) {
1756 return null;
1757 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001758
Mathias Jeppssond1443e92012-08-24 15:25:32 +02001759 WindowManager wm = null;
1760 View view = null;
1761
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001762 try {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001763 Context context = mContext;
Craig Mautner6fbda632012-07-03 09:26:39 -07001764 if (DEBUG_STARTING_WINDOW) Slog.d(TAG, "addStartingWindow " + packageName
1765 + ": nonLocalizedLabel=" + nonLocalizedLabel + " theme="
1766 + Integer.toHexString(theme));
Dianne Hackborn247fe742011-01-08 17:25:57 -08001767 if (theme != context.getThemeResId() || labelRes != 0) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001768 try {
1769 context = context.createPackageContext(packageName, 0);
Dianne Hackborn247fe742011-01-08 17:25:57 -08001770 context.setTheme(theme);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001771 } catch (PackageManager.NameNotFoundException e) {
1772 // Ignore
1773 }
1774 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001775
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001776 Window win = PolicyManager.makeNewWindow(context);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001777 final TypedArray ta = win.getWindowStyle();
1778 if (ta.getBoolean(
1779 com.android.internal.R.styleable.Window_windowDisablePreview, false)
1780 || ta.getBoolean(
1781 com.android.internal.R.styleable.Window_windowShowWallpaper,false)) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001782 return null;
1783 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001784
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001785 Resources r = context.getResources();
1786 win.setTitle(r.getText(labelRes, nonLocalizedLabel));
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001787
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001788 win.setType(
1789 WindowManager.LayoutParams.TYPE_APPLICATION_STARTING);
1790 // Force the window flags: this is a fake window, so it is not really
1791 // touchable or focusable by the user. We also add in the ALT_FOCUSABLE_IM
1792 // flag because we do know that the next window will take input
1793 // focus, so we want to get the IME window up on top of us right away.
1794 win.setFlags(
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08001795 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001796 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
1797 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
1798 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08001799 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001800 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
1801 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
1802 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001803
Adam Powell04fe6eb2013-05-31 14:39:48 -07001804 win.setDefaultIcon(icon);
1805 win.setDefaultLogo(logo);
1806
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001807 win.setLayout(WindowManager.LayoutParams.MATCH_PARENT,
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07001808 WindowManager.LayoutParams.MATCH_PARENT);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001809
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001810 final WindowManager.LayoutParams params = win.getAttributes();
1811 params.token = appToken;
1812 params.packageName = packageName;
1813 params.windowAnimations = win.getWindowStyle().getResourceId(
1814 com.android.internal.R.styleable.Window_windowAnimationStyle, 0);
Dianne Hackborn5d927c22011-09-02 12:22:18 -07001815 params.privateFlags |=
1816 WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED;
Craig Mautner88400d32012-09-30 12:35:45 -07001817 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
Adam Lesinski95c42972013-10-02 10:13:27 -07001818
1819 if (!compatInfo.supportsScreen()) {
1820 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
1821 }
1822
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001823 params.setTitle("Starting " + packageName);
1824
Mathias Jeppssond1443e92012-08-24 15:25:32 +02001825 wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
1826 view = win.getDecorView();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001827
1828 if (win.isFloating()) {
1829 // Whoops, there is no way to display an animation/preview
1830 // of such a thing! After all that work... let's skip it.
1831 // (Note that we must do this here because it is in
1832 // getDecorView() where the theme is evaluated... maybe
1833 // we should peek the floating attribute from the theme
1834 // earlier.)
1835 return null;
1836 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001837
Craig Mautner6fbda632012-07-03 09:26:39 -07001838 if (DEBUG_STARTING_WINDOW) Slog.d(
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001839 TAG, "Adding starting window for " + packageName
1840 + " / " + appToken + ": "
1841 + (view.getParent() != null ? view : null));
1842
1843 wm.addView(view, params);
1844
1845 // Only return the view if it was successfully added to the
1846 // window manager... which we can tell by it having a parent.
1847 return view.getParent() != null ? view : null;
Jeff Brown98365d72012-08-19 20:30:52 -07001848 } catch (WindowManager.BadTokenException e) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001849 // ignore
Craig Mautner42bf39e2014-02-21 16:46:22 -08001850 Log.w(TAG, appToken + " already running, starting window not displayed. " +
1851 e.getMessage());
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001852 } catch (RuntimeException e) {
1853 // don't crash if something else bad happens, for example a
1854 // failure loading resources because we are loading from an app
1855 // on external storage that has been unmounted.
1856 Log.w(TAG, appToken + " failed creating starting window", e);
Mathias Jeppssond1443e92012-08-24 15:25:32 +02001857 } finally {
1858 if (view != null && view.getParent() == null) {
1859 Log.w(TAG, "view not successfully added to wm, removing view");
1860 wm.removeViewImmediate(view);
1861 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001862 }
1863
1864 return null;
1865 }
1866
1867 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07001868 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001869 public void removeStartingWindow(IBinder appToken, View window) {
Craig Mautner6fbda632012-07-03 09:26:39 -07001870 if (DEBUG_STARTING_WINDOW) {
1871 RuntimeException e = new RuntimeException("here");
1872 e.fillInStackTrace();
1873 Log.v(TAG, "Removing starting window for " + appToken + ": " + window, e);
1874 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001875
1876 if (window != null) {
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001877 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001878 wm.removeView(window);
1879 }
1880 }
1881
1882 /**
1883 * Preflight adding a window to the system.
RoboErik8a2cfc32014-05-16 11:19:38 -07001884 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001885 * Currently enforces that three window types are singletons:
1886 * <ul>
1887 * <li>STATUS_BAR_TYPE</li>
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001888 * <li>KEYGUARD_TYPE</li>
1889 * </ul>
RoboErik8a2cfc32014-05-16 11:19:38 -07001890 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001891 * @param win The window to be added
1892 * @param attrs Information about the window to be added
RoboErik8a2cfc32014-05-16 11:19:38 -07001893 *
Jeff Brown98365d72012-08-19 20:30:52 -07001894 * @return If ok, WindowManagerImpl.ADD_OKAY. If too many singletons,
1895 * WindowManagerImpl.ADD_MULTIPLE_SINGLETON
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001896 */
Jose Lima9546b202014-07-02 17:21:51 -07001897 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001898 public int prepareAddWindowLw(WindowState win, WindowManager.LayoutParams attrs) {
1899 switch (attrs.type) {
1900 case TYPE_STATUS_BAR:
Joe Onorato8bc6c512010-06-04 16:21:12 -04001901 mContext.enforceCallingOrSelfPermission(
1902 android.Manifest.permission.STATUS_BAR_SERVICE,
1903 "PhoneWindowManager");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001904 if (mStatusBar != null) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001905 if (mStatusBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07001906 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001907 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001908 }
1909 mStatusBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04001910 mStatusBarController.setWindow(win);
John Spurlock8fdfe622014-05-21 17:10:10 -04001911 mKeyguardDelegate.hideScrim();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001912 break;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04001913 case TYPE_NAVIGATION_BAR:
1914 mContext.enforceCallingOrSelfPermission(
1915 android.Manifest.permission.STATUS_BAR_SERVICE,
1916 "PhoneWindowManager");
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001917 if (mNavigationBar != null) {
1918 if (mNavigationBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07001919 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001920 }
1921 }
Daniel Sandler8956dbb2011-04-22 07:55:02 -04001922 mNavigationBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04001923 mNavigationBarController.setWindow(win);
Craig Mautnereda67292013-04-28 13:50:14 -07001924 if (DEBUG_LAYOUT) Slog.i(TAG, "NAVIGATION BAR: " + mNavigationBar);
Daniel Sandler8956dbb2011-04-22 07:55:02 -04001925 break;
Jim Millere898ac52012-04-06 17:10:57 -07001926 case TYPE_NAVIGATION_BAR_PANEL:
1927 mContext.enforceCallingOrSelfPermission(
1928 android.Manifest.permission.STATUS_BAR_SERVICE,
1929 "PhoneWindowManager");
1930 break;
Dianne Hackborn08743722009-12-21 12:16:51 -08001931 case TYPE_STATUS_BAR_PANEL:
Joe Onorato8bc6c512010-06-04 16:21:12 -04001932 mContext.enforceCallingOrSelfPermission(
1933 android.Manifest.permission.STATUS_BAR_SERVICE,
1934 "PhoneWindowManager");
Dianne Hackborn08743722009-12-21 12:16:51 -08001935 break;
Joe Onorato29fc2c92010-11-24 10:26:50 -08001936 case TYPE_STATUS_BAR_SUB_PANEL:
1937 mContext.enforceCallingOrSelfPermission(
1938 android.Manifest.permission.STATUS_BAR_SERVICE,
1939 "PhoneWindowManager");
Joe Onorato29fc2c92010-11-24 10:26:50 -08001940 break;
Jim Miller5ecd8112013-01-09 18:50:26 -08001941 case TYPE_KEYGUARD_SCRIM:
Jim Miller25190572013-02-28 17:36:24 -08001942 if (mKeyguardScrim != null) {
1943 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
1944 }
Jim Miller5ecd8112013-01-09 18:50:26 -08001945 mKeyguardScrim = win;
1946 break;
1947
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001948 }
Jeff Brown98365d72012-08-19 20:30:52 -07001949 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001950 }
1951
1952 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07001953 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001954 public void removeWindowLw(WindowState win) {
1955 if (mStatusBar == win) {
1956 mStatusBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04001957 mStatusBarController.setWindow(null);
Jim Millerc0b676d2013-03-22 16:11:08 -07001958 mKeyguardDelegate.showScrim();
Jim Miller5ecd8112013-01-09 18:50:26 -08001959 } else if (mKeyguardScrim == win) {
1960 Log.v(TAG, "Removing keyguard scrim");
1961 mKeyguardScrim = null;
1962 } if (mNavigationBar == win) {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04001963 mNavigationBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04001964 mNavigationBarController.setWindow(null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001965 }
1966 }
1967
1968 static final boolean PRINT_ANIM = false;
RoboErik8a2cfc32014-05-16 11:19:38 -07001969
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001970 /** {@inheritDoc} */
Craig Mautner4b71aa12012-12-27 17:20:01 -08001971 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001972 public int selectAnimationLw(WindowState win, int transit) {
1973 if (PRINT_ANIM) Log.i(TAG, "selectAnimation in " + win
1974 + ": transit=" + transit);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001975 if (win == mStatusBar) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001976 boolean isKeyguard = (win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001977 if (transit == TRANSIT_EXIT
1978 || transit == TRANSIT_HIDE) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001979 return isKeyguard ? -1 : R.anim.dock_top_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001980 } else if (transit == TRANSIT_ENTER
1981 || transit == TRANSIT_SHOW) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001982 return isKeyguard ? -1 : R.anim.dock_top_enter;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001983 }
1984 } else if (win == mNavigationBar) {
1985 // This can be on either the bottom or the right.
1986 if (mNavigationBarOnBottom) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08001987 if (transit == TRANSIT_EXIT
1988 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001989 return R.anim.dock_bottom_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001990 } else if (transit == TRANSIT_ENTER
1991 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001992 return R.anim.dock_bottom_enter;
1993 }
1994 } else {
Craig Mautner4b71aa12012-12-27 17:20:01 -08001995 if (transit == TRANSIT_EXIT
1996 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001997 return R.anim.dock_right_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001998 } else if (transit == TRANSIT_ENTER
1999 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002000 return R.anim.dock_right_enter;
2001 }
2002 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08002003 }
2004
2005 if (transit == TRANSIT_PREVIEW_DONE) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002006 if (win.hasAppShownWindows()) {
2007 if (PRINT_ANIM) Log.i(TAG, "**** STARTING EXIT");
2008 return com.android.internal.R.anim.app_starting_exit;
2009 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07002010 } else if (win.getAttrs().type == TYPE_DREAM && mDreamingLockscreen
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002011 && transit == TRANSIT_ENTER) {
2012 // Special case: we are animating in a dream, while the keyguard
2013 // is shown. We don't want an animation on the dream, because
2014 // we need it shown immediately with the keyguard animating away
2015 // to reveal it.
2016 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002017 }
2018
2019 return 0;
2020 }
2021
Craig Mautner3c174372013-02-21 17:54:37 -08002022 @Override
2023 public void selectRotationAnimationLw(int anim[]) {
2024 if (PRINT_ANIM) Slog.i(TAG, "selectRotationAnimation mTopFullscreen="
2025 + mTopFullscreenOpaqueWindowState + " rotationAnimation="
2026 + (mTopFullscreenOpaqueWindowState == null ?
2027 "0" : mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation));
2028 if (mTopFullscreenOpaqueWindowState != null && mTopIsFullscreen) {
2029 switch (mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation) {
2030 case ROTATION_ANIMATION_CROSSFADE:
2031 anim[0] = R.anim.rotation_animation_xfade_exit;
2032 anim[1] = R.anim.rotation_animation_enter;
2033 break;
2034 case ROTATION_ANIMATION_JUMPCUT:
2035 anim[0] = R.anim.rotation_animation_jump_exit;
2036 anim[1] = R.anim.rotation_animation_enter;
2037 break;
2038 case ROTATION_ANIMATION_ROTATE:
2039 default:
2040 anim[0] = anim[1] = 0;
2041 break;
2042 }
2043 } else {
2044 anim[0] = anim[1] = 0;
2045 }
2046 }
2047
2048 @Override
2049 public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId,
2050 boolean forceDefault) {
2051 switch (exitAnimId) {
2052 case R.anim.rotation_animation_xfade_exit:
2053 case R.anim.rotation_animation_jump_exit:
2054 // These are the only cases that matter.
2055 if (forceDefault) {
2056 return false;
2057 }
2058 int anim[] = new int[2];
2059 selectRotationAnimationLw(anim);
2060 return (exitAnimId == anim[0] && enterAnimId == anim[1]);
2061 default:
2062 return true;
2063 }
2064 }
2065
2066 @Override
Dianne Hackborn0c2acff2012-04-12 15:17:07 -07002067 public Animation createForceHideEnterAnimation(boolean onWallpaper) {
Jorim Jaggi76a16232014-08-08 17:00:47 +02002068 if (onWallpaper) {
2069 Animation a = AnimationUtils.loadAnimation(mContext,
2070 R.anim.lock_screen_behind_enter_wallpaper);
2071 AnimationSet set = (AnimationSet) a;
2072
2073 // TODO: Use XML interpolators when we have log interpolators available in XML.
2074 set.getAnimations().get(0).setInterpolator(mLogDecelerateInterpolator);
2075 set.getAnimations().get(1).setInterpolator(mLogDecelerateInterpolator);
2076 set.getAnimations().get(2).setInterpolator(mLogDecelerateInterpolator);
2077 return set;
2078 } else {
2079 Animation a = AnimationUtils.loadAnimation(mContext,
2080 R.anim.lock_screen_behind_enter);
2081 AnimationSet set = (AnimationSet) a;
2082
2083 // TODO: Use XML interpolators when we have log interpolators available in XML.
2084 set.getAnimations().get(0).setInterpolator(mLogDecelerateInterpolator);
2085 return set;
2086 }
2087 }
2088
2089
2090 @Override
2091 public Animation createForceHideWallpaperExitAnimation() {
2092 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_wallpaper_exit);
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002093 }
John Spurlockc8b46ca2013-04-08 12:59:26 -04002094
2095 private static void awakenDreams() {
2096 IDreamManager dreamManager = getDreamManager();
2097 if (dreamManager != null) {
2098 try {
2099 dreamManager.awaken();
2100 } catch (RemoteException e) {
2101 // fine, stay asleep then
2102 }
2103 }
2104 }
2105
2106 static IDreamManager getDreamManager() {
2107 return IDreamManager.Stub.asInterface(
2108 ServiceManager.checkService(DreamService.DREAM_SERVICE));
2109 }
2110
Santos Cordon9eb45932014-06-27 12:28:43 -07002111 TelecommManager getTelecommService() {
2112 return (TelecommManager) mContext.getSystemService(Context.TELECOMM_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002113 }
2114
Jeff Brown4d396052010-10-29 21:50:21 -07002115 static IAudioService getAudioService() {
2116 IAudioService audioService = IAudioService.Stub.asInterface(
2117 ServiceManager.checkService(Context.AUDIO_SERVICE));
2118 if (audioService == null) {
2119 Log.w(TAG, "Unable to find IAudioService interface.");
2120 }
2121 return audioService;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002122 }
2123
2124 boolean keyguardOn() {
2125 return keyguardIsShowingTq() || inKeyguardRestrictedKeyInputMode();
2126 }
2127
2128 private static final int[] WINDOW_TYPES_WHERE_HOME_DOESNT_WORK = {
2129 WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
2130 WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
2131 };
2132
2133 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002134 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002135 public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002136 final boolean keyguardOn = keyguardOn();
Jeff Brown1f245102010-11-18 20:53:46 -08002137 final int keyCode = event.getKeyCode();
2138 final int repeatCount = event.getRepeatCount();
2139 final int metaState = event.getMetaState();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002140 final int flags = event.getFlags();
Jeff Brown1f245102010-11-18 20:53:46 -08002141 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
2142 final boolean canceled = event.isCanceled();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002143
Jeff Brown40013652012-05-16 21:22:36 -07002144 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002145 Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount="
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002146 + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed
2147 + " canceled=" + canceled);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002148 }
2149
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002150 // If we think we might have a volume down & power key chord on the way
2151 // but we're not sure, then tell the dispatcher to wait a little while and
2152 // try again later before dispatching.
Christopher Tatee90585f2012-03-05 18:56:25 -08002153 if (mScreenshotChordEnabled && (flags & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002154 if (mVolumeDownKeyTriggered && !mPowerKeyTriggered) {
2155 final long now = SystemClock.uptimeMillis();
2156 final long timeoutTime = mVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS;
2157 if (now < timeoutTime) {
2158 return timeoutTime - now;
2159 }
2160 }
2161 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
2162 && mVolumeDownKeyConsumedByScreenshotChord) {
2163 if (!down) {
2164 mVolumeDownKeyConsumedByScreenshotChord = false;
2165 }
2166 return -1;
2167 }
2168 }
2169
Michael Wright6a62e552014-06-03 19:19:48 -07002170 // Cancel any pending meta actions if we see any other keys being pressed between the down
2171 // of the meta key and its corresponding up.
Michael Wrightce0c13a2014-07-30 10:49:21 -07002172 if (mPendingMetaAction && KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07002173 mPendingMetaAction = false;
2174 }
2175
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002176 // First we always handle the home key here, so applications
2177 // can never break it, although if keyguard is on, we do let
2178 // it handle it, because that gives us the correct 5 second
2179 // timeout.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002180 if (keyCode == KeyEvent.KEYCODE_HOME) {
Michael Jurka7f2668c2012-03-27 07:49:52 -07002181
Jeff Brown49ed71d2010-12-06 17:13:33 -08002182 // If we have released the home key, and didn't do anything else
2183 // while it was pressed, then it is time to go home!
Michael Jurka7f2668c2012-03-27 07:49:52 -07002184 if (!down) {
Jeff Browncaca8812013-05-09 13:34:33 -07002185 cancelPreloadRecentApps();
2186
Jeff Brown49ed71d2010-12-06 17:13:33 -08002187 mHomePressed = false;
Jeff Browncaca8812013-05-09 13:34:33 -07002188 if (mHomeConsumed) {
2189 mHomeConsumed = false;
Michael Jurka7f2668c2012-03-27 07:49:52 -07002190 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002191 }
Jeff Browncaca8812013-05-09 13:34:33 -07002192
2193 if (canceled) {
2194 Log.i(TAG, "Ignoring HOME; event canceled.");
2195 return -1;
2196 }
2197
2198 // If an incoming call is ringing, HOME is totally disabled.
Santos Cordon9eb45932014-06-27 12:28:43 -07002199 // (The user is already on the InCallUI at this point,
Jeff Browncaca8812013-05-09 13:34:33 -07002200 // and his ONLY options are to answer or reject the call.)
Santos Cordon9eb45932014-06-27 12:28:43 -07002201 TelecommManager telecommManager = getTelecommService();
2202 if (telecommManager != null && telecommManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07002203 Log.i(TAG, "Ignoring HOME; there's a ringing incoming call.");
2204 return -1;
Jeff Browncaca8812013-05-09 13:34:33 -07002205 }
2206
2207 // Delay handling home if a double-tap is possible.
2208 if (mDoubleTapOnHomeBehavior != DOUBLE_TAP_HOME_NOTHING) {
2209 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); // just in case
2210 mHomeDoubleTapPending = true;
2211 mHandler.postDelayed(mHomeDoubleTapTimeoutRunnable,
2212 ViewConfiguration.getDoubleTapTimeout());
2213 return -1;
2214 }
2215
Jose Lima9546b202014-07-02 17:21:51 -07002216 // If there's a dream running then use home to escape the dream
2217 // but don't actually go home.
2218 if (mDreamManagerInternal != null && mDreamManagerInternal.isDreaming()) {
Jeff Brownf6d46682014-07-17 22:44:20 -07002219 mDreamManagerInternal.stopDream(false /*immediate*/);
Jose Lima9546b202014-07-02 17:21:51 -07002220 return -1;
2221 }
2222
Jeff Browncaca8812013-05-09 13:34:33 -07002223 // Go home!
2224 launchHomeFromHotKey();
2225 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002226 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002227
2228 // If a system window has focus, then it doesn't make sense
2229 // right now to interact with applications.
2230 WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null;
2231 if (attrs != null) {
2232 final int type = attrs.type;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002233 if (type == WindowManager.LayoutParams.TYPE_KEYGUARD_SCRIM
2234 || type == WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG
2235 || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002236 // the "app" is keyguard, so give it the key
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002237 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002238 }
2239 final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length;
2240 for (int i=0; i<typeCount; i++) {
2241 if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) {
2242 // don't do anything, but also don't pass it to the app
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002243 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002244 }
2245 }
2246 }
Jeff Browncaca8812013-05-09 13:34:33 -07002247
2248 // Remember that home is pressed and handle special actions.
2249 if (repeatCount == 0) {
2250 mHomePressed = true;
2251 if (mHomeDoubleTapPending) {
2252 mHomeDoubleTapPending = false;
2253 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable);
2254 handleDoubleTapOnHome();
2255 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI
2256 || mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
2257 preloadRecentApps();
Michael Jurka7f2668c2012-03-27 07:49:52 -07002258 }
Jeff Browncaca8812013-05-09 13:34:33 -07002259 } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) {
2260 if (!keyguardOn) {
2261 handleLongPressOnHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002262 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002263 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002264 return -1;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002265 } else if (keyCode == KeyEvent.KEYCODE_MENU) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002266 // Hijack modified menu keys for debugging features
2267 final int chordBug = KeyEvent.META_SHIFT_ON;
2268
2269 if (down && repeatCount == 0) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002270 if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002271 Intent intent = new Intent(Intent.ACTION_BUG_REPORT);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002272 mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT,
2273 null, null, null, 0, null, null);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002274 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002275 } else if (SHOW_PROCESSES_ON_ALT_MENU &&
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002276 (metaState & KeyEvent.META_ALT_ON) == KeyEvent.META_ALT_ON) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002277 Intent service = new Intent();
2278 service.setClassName(mContext, "com.android.server.LoadAverageService");
2279 ContentResolver res = mContext.getContentResolver();
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002280 boolean shown = Settings.Global.getInt(
2281 res, Settings.Global.SHOW_PROCESSES, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002282 if (!shown) {
2283 mContext.startService(service);
2284 } else {
2285 mContext.stopService(service);
2286 }
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002287 Settings.Global.putInt(
2288 res, Settings.Global.SHOW_PROCESSES, shown ? 0 : 1);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002289 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002290 }
2291 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002292 } else if (keyCode == KeyEvent.KEYCODE_SEARCH) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002293 if (down) {
2294 if (repeatCount == 0) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002295 mSearchKeyShortcutPending = true;
2296 mConsumeSearchKeyUp = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002297 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002298 } else {
2299 mSearchKeyShortcutPending = false;
2300 if (mConsumeSearchKeyUp) {
2301 mConsumeSearchKeyUp = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002302 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002303 }
2304 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002305 return 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002306 } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) {
Michael Wrightc9ebea72013-01-16 19:25:02 -08002307 if (!keyguardOn) {
Jeff Browncaca8812013-05-09 13:34:33 -07002308 if (down && repeatCount == 0) {
2309 preloadRecentApps();
2310 } else if (!down) {
2311 toggleRecentApps();
Michael Wrightc9ebea72013-01-16 19:25:02 -08002312 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002313 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002314 return -1;
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002315 } else if (keyCode == KeyEvent.KEYCODE_ASSIST) {
2316 if (down) {
2317 if (repeatCount == 0) {
2318 mAssistKeyLongPressed = false;
2319 } else if (repeatCount == 1) {
2320 mAssistKeyLongPressed = true;
2321 if (!keyguardOn) {
2322 launchAssistLongPressAction();
2323 }
2324 }
2325 } else {
2326 if (mAssistKeyLongPressed) {
2327 mAssistKeyLongPressed = false;
2328 } else {
2329 if (!keyguardOn) {
2330 launchAssistAction();
2331 }
2332 }
2333 }
2334 return -1;
Jeff Sharkey2991fa32012-12-05 18:06:43 -08002335 } else if (keyCode == KeyEvent.KEYCODE_SYSRQ) {
2336 if (down && repeatCount == 0) {
2337 mHandler.post(mScreenshotRunnable);
2338 }
2339 return -1;
Michael Wrightb854e242013-02-05 17:54:02 -08002340 } else if (keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP
2341 || keyCode == KeyEvent.KEYCODE_BRIGHTNESS_DOWN) {
2342 if (down) {
2343 int direction = keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP ? 1 : -1;
2344
2345 // Disable autobrightness if it's on
2346 int auto = Settings.System.getIntForUser(
2347 mContext.getContentResolver(),
2348 Settings.System.SCREEN_BRIGHTNESS_MODE,
2349 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2350 UserHandle.USER_CURRENT_OR_SELF);
2351 if (auto != 0) {
2352 Settings.System.putIntForUser(mContext.getContentResolver(),
2353 Settings.System.SCREEN_BRIGHTNESS_MODE,
2354 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2355 UserHandle.USER_CURRENT_OR_SELF);
2356 }
2357
2358 int min = mPowerManager.getMinimumScreenBrightnessSetting();
2359 int max = mPowerManager.getMaximumScreenBrightnessSetting();
2360 int step = (max - min + BRIGHTNESS_STEPS - 1) / BRIGHTNESS_STEPS * direction;
2361 int brightness = Settings.System.getIntForUser(mContext.getContentResolver(),
2362 Settings.System.SCREEN_BRIGHTNESS,
2363 mPowerManager.getDefaultScreenBrightnessSetting(),
2364 UserHandle.USER_CURRENT_OR_SELF);
2365 brightness += step;
2366 // Make sure we don't go beyond the limits.
2367 brightness = Math.min(max, brightness);
2368 brightness = Math.max(min, brightness);
2369
2370 Settings.System.putIntForUser(mContext.getContentResolver(),
2371 Settings.System.SCREEN_BRIGHTNESS, brightness,
2372 UserHandle.USER_CURRENT_OR_SELF);
Alan Viverette5a399492014-07-14 16:19:38 -07002373 mContext.startActivityAsUser(new Intent(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG),
2374 UserHandle.CURRENT_OR_SELF);
Michael Wrightb854e242013-02-05 17:54:02 -08002375 }
2376 return -1;
Michael Wrightce0c13a2014-07-30 10:49:21 -07002377 } else if (KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07002378 if (down) {
2379 mPendingMetaAction = true;
2380 } else if (mPendingMetaAction) {
Michael Wright6a62e552014-06-03 19:19:48 -07002381 launchAssistAction();
2382 }
2383 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002384 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002385
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002386 // Shortcuts are invoked through Search+key, so intercept those here
Jeff Browncaab4d02010-12-09 22:13:41 -08002387 // Any printing key that is chorded with Search should be consumed
2388 // even if no shortcut was invoked. This prevents text from being
2389 // inadvertently inserted when using a keyboard that has built-in macro
2390 // shortcut keys (that emit Search+x) and some of them are not registered.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002391 if (mSearchKeyShortcutPending) {
Jeff Browncaab4d02010-12-09 22:13:41 -08002392 final KeyCharacterMap kcm = event.getKeyCharacterMap();
2393 if (kcm.isPrintingKey(keyCode)) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002394 mConsumeSearchKeyUp = true;
2395 mSearchKeyShortcutPending = false;
Jeff Browncaab4d02010-12-09 22:13:41 -08002396 if (down && repeatCount == 0 && !keyguardOn) {
2397 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState);
2398 if (shortcutIntent != null) {
2399 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002400 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002401 mContext.startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002402 } catch (ActivityNotFoundException ex) {
2403 Slog.w(TAG, "Dropping shortcut key combination because "
2404 + "the activity to which it is registered was not found: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002405 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode), ex);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002406 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002407 } else {
2408 Slog.i(TAG, "Dropping unregistered shortcut key combination: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002409 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002410 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002411 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002412 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002413 }
2414 }
2415
Jeff Brown68b909d2011-12-07 16:36:01 -08002416 // Invoke shortcuts using Meta.
Jeff Brown602ab322012-05-16 13:33:47 -07002417 if (down && repeatCount == 0 && !keyguardOn
Jeff Brown68b909d2011-12-07 16:36:01 -08002418 && (metaState & KeyEvent.META_META_ON) != 0) {
2419 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brown602ab322012-05-16 13:33:47 -07002420 if (kcm.isPrintingKey(keyCode)) {
2421 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode,
2422 metaState & ~(KeyEvent.META_META_ON
2423 | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON));
2424 if (shortcutIntent != null) {
2425 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2426 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002427 mContext.startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brown602ab322012-05-16 13:33:47 -07002428 } catch (ActivityNotFoundException ex) {
2429 Slog.w(TAG, "Dropping shortcut key combination because "
2430 + "the activity to which it is registered was not found: "
2431 + "META+" + KeyEvent.keyCodeToString(keyCode), ex);
2432 }
2433 return -1;
Jeff Brown68b909d2011-12-07 16:36:01 -08002434 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002435 }
2436 }
2437
Jeff Brown6651a632011-11-28 12:59:11 -08002438 // Handle application launch keys.
Jeff Brown602ab322012-05-16 13:33:47 -07002439 if (down && repeatCount == 0 && !keyguardOn) {
Jeff Brown6651a632011-11-28 12:59:11 -08002440 String category = sApplicationLaunchKeyCategories.get(keyCode);
2441 if (category != null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -08002442 Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category);
Jeff Brown6651a632011-11-28 12:59:11 -08002443 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2444 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002445 mContext.startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brown6651a632011-11-28 12:59:11 -08002446 } catch (ActivityNotFoundException ex) {
2447 Slog.w(TAG, "Dropping application launch key because "
2448 + "the activity to which it is registered was not found: "
2449 + "keyCode=" + keyCode + ", category=" + category, ex);
2450 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002451 return -1;
Jeff Brown6651a632011-11-28 12:59:11 -08002452 }
2453 }
2454
Jeff Brown68b909d2011-12-07 16:36:01 -08002455 // Display task switcher for ALT-TAB or Meta-TAB.
2456 if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_TAB) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002457 if (mRecentAppsHeldModifiers == 0 && !keyguardOn) {
Jeff Brown68b909d2011-12-07 16:36:01 -08002458 final int shiftlessModifiers = event.getModifiers() & ~KeyEvent.META_SHIFT_MASK;
Michael Wrightce0c13a2014-07-30 10:49:21 -07002459 if (KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_ALT_ON)
2460 || KeyEvent.metaStateHasModifiers(
2461 shiftlessModifiers, KeyEvent.META_META_ON)) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002462 mRecentAppsHeldModifiers = shiftlessModifiers;
2463 showRecentApps(true);
Jeff Brown68b909d2011-12-07 16:36:01 -08002464 return -1;
2465 }
2466 }
Winson Chung1e8d71b2014-05-16 17:05:22 -07002467 } else if (!down && mRecentAppsHeldModifiers != 0
2468 && (metaState & mRecentAppsHeldModifiers) == 0) {
2469 mRecentAppsHeldModifiers = 0;
Winson Chungcdcd4872014-08-05 18:00:13 -07002470 hideRecentApps(true, false);
Jeff Brown68b909d2011-12-07 16:36:01 -08002471 }
2472
Jeff Browncf39bdf2012-05-18 14:41:19 -07002473 // Handle keyboard language switching.
2474 if (down && repeatCount == 0
2475 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2476 || (keyCode == KeyEvent.KEYCODE_SPACE
2477 && (metaState & KeyEvent.META_CTRL_MASK) != 0))) {
2478 int direction = (metaState & KeyEvent.META_SHIFT_MASK) != 0 ? -1 : 1;
2479 mWindowManagerFuncs.switchKeyboardLayout(event.getDeviceId(), direction);
2480 return -1;
2481 }
2482 if (mLanguageSwitchKeyPressed && !down
2483 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2484 || keyCode == KeyEvent.KEYCODE_SPACE)) {
2485 mLanguageSwitchKeyPressed = false;
2486 return -1;
2487 }
2488
Justin Kohd378ad72013-04-01 12:18:26 -07002489 if (mGlobalKeyManager.handleGlobalKey(mContext, keyCode, event)) {
2490 return -1;
2491 }
2492
Michael Wright6a62e552014-06-03 19:19:48 -07002493 // Reserve all the META modifier combos for system behavior
Michael Wrightce0c13a2014-07-30 10:49:21 -07002494 if ((metaState & KeyEvent.META_META_ON) != 0) {
Michael Wright6a62e552014-06-03 19:19:48 -07002495 return -1;
2496 }
2497
Jeff Brown68b909d2011-12-07 16:36:01 -08002498 // Let the application handle the key.
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002499 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002500 }
2501
Jeff Brown3915bb82010-11-05 15:02:16 -07002502 /** {@inheritDoc} */
2503 @Override
Jeff Brown49ed71d2010-12-06 17:13:33 -08002504 public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown54875002011-04-06 15:33:01 -07002505 // Note: This method is only called if the initial down was unhandled.
Jeff Brown40013652012-05-16 21:22:36 -07002506 if (DEBUG_INPUT) {
Jeff Brown1f245102010-11-18 20:53:46 -08002507 Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction()
2508 + ", flags=" + event.getFlags()
2509 + ", keyCode=" + event.getKeyCode()
2510 + ", scanCode=" + event.getScanCode()
2511 + ", metaState=" + event.getMetaState()
2512 + ", repeatCount=" + event.getRepeatCount()
2513 + ", policyFlags=" + policyFlags);
Jeff Brown3915bb82010-11-05 15:02:16 -07002514 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002515
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002516 KeyEvent fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002517 if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
2518 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002519 final int keyCode = event.getKeyCode();
2520 final int metaState = event.getMetaState();
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002521 final boolean initialDown = event.getAction() == KeyEvent.ACTION_DOWN
2522 && event.getRepeatCount() == 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002523
Jeff Brown54875002011-04-06 15:33:01 -07002524 // Check for fallback actions specified by the key character map.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002525 final FallbackAction fallbackAction;
2526 if (initialDown) {
2527 fallbackAction = kcm.getFallbackAction(keyCode, metaState);
2528 } else {
2529 fallbackAction = mFallbackActions.get(keyCode);
2530 }
2531
2532 if (fallbackAction != null) {
Jeff Brown40013652012-05-16 21:22:36 -07002533 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002534 Slog.d(TAG, "Fallback: keyCode=" + fallbackAction.keyCode
2535 + " metaState=" + Integer.toHexString(fallbackAction.metaState));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002536 }
2537
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002538 final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK;
2539 fallbackEvent = KeyEvent.obtain(
Jeff Brown49ed71d2010-12-06 17:13:33 -08002540 event.getDownTime(), event.getEventTime(),
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002541 event.getAction(), fallbackAction.keyCode,
2542 event.getRepeatCount(), fallbackAction.metaState,
Jeff Brown49ed71d2010-12-06 17:13:33 -08002543 event.getDeviceId(), event.getScanCode(),
2544 flags, event.getSource(), null);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002545
2546 if (!interceptFallback(win, fallbackEvent, policyFlags)) {
2547 fallbackEvent.recycle();
2548 fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002549 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002550
2551 if (initialDown) {
2552 mFallbackActions.put(keyCode, fallbackAction);
2553 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2554 mFallbackActions.remove(keyCode);
2555 fallbackAction.recycle();
2556 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002557 }
2558 }
2559
Jeff Brown40013652012-05-16 21:22:36 -07002560 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002561 if (fallbackEvent == null) {
2562 Slog.d(TAG, "No fallback.");
2563 } else {
2564 Slog.d(TAG, "Performing fallback: " + fallbackEvent);
2565 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002566 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002567 return fallbackEvent;
Jeff Brown3915bb82010-11-05 15:02:16 -07002568 }
2569
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002570 private boolean interceptFallback(WindowState win, KeyEvent fallbackEvent, int policyFlags) {
Jeff Brown037c33e2014-04-09 00:31:55 -07002571 int actions = interceptKeyBeforeQueueing(fallbackEvent, policyFlags);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002572 if ((actions & ACTION_PASS_TO_USER) != 0) {
2573 long delayMillis = interceptKeyBeforeDispatching(
2574 win, fallbackEvent, policyFlags);
2575 if (delayMillis == 0) {
2576 return true;
2577 }
2578 }
2579 return false;
Jeff Brown6f2fba42011-02-19 01:08:02 -08002580 }
2581
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002582 private void launchAssistLongPressAction() {
2583 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
2584 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
2585
2586 // launch the search activity
2587 Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS);
2588 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2589 try {
RoboErik8a2cfc32014-05-16 11:19:38 -07002590 // TODO: This only stops the factory-installed search manager.
Jim Miller45308b12012-06-18 19:23:39 -07002591 // Need to formalize an API to handle others
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002592 SearchManager searchManager = getSearchManager();
2593 if (searchManager != null) {
2594 searchManager.stopSearch();
2595 }
Michael Wright43e27f72013-04-10 14:06:48 -07002596 mContext.startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002597 } catch (ActivityNotFoundException e) {
2598 Slog.w(TAG, "No activity to handle assist long press action.", e);
2599 }
2600 }
2601
2602 private void launchAssistAction() {
2603 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
Amith Yamasanic1d07a42012-08-14 09:32:02 -07002604 Intent intent = ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE))
Dianne Hackbornf9c5e0f2013-01-23 14:39:13 -08002605 .getAssistIntent(mContext, true, UserHandle.USER_CURRENT);
Jim Miller45308b12012-06-18 19:23:39 -07002606 if (intent != null) {
2607 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
2608 | Intent.FLAG_ACTIVITY_SINGLE_TOP
2609 | Intent.FLAG_ACTIVITY_CLEAR_TOP);
2610 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002611 mContext.startActivityAsUser(intent, UserHandle.CURRENT);
Jim Miller45308b12012-06-18 19:23:39 -07002612 } catch (ActivityNotFoundException e) {
2613 Slog.w(TAG, "No activity to handle assist action.", e);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002614 }
2615 }
2616 }
2617
2618 private SearchManager getSearchManager() {
2619 if (mSearchManager == null) {
2620 mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
2621 }
2622 return mSearchManager;
2623 }
2624
Jeff Browncaca8812013-05-09 13:34:33 -07002625 private void preloadRecentApps() {
2626 mPreloadedRecentApps = true;
2627 try {
2628 IStatusBarService statusbar = getStatusBarService();
2629 if (statusbar != null) {
2630 statusbar.preloadRecentApps();
2631 }
2632 } catch (RemoteException e) {
2633 Slog.e(TAG, "RemoteException when preloading recent apps", e);
2634 // re-acquire status bar service next time it is needed.
2635 mStatusBarService = null;
2636 }
2637 }
2638
2639 private void cancelPreloadRecentApps() {
2640 if (mPreloadedRecentApps) {
2641 mPreloadedRecentApps = false;
2642 try {
2643 IStatusBarService statusbar = getStatusBarService();
2644 if (statusbar != null) {
2645 statusbar.cancelPreloadRecentApps();
2646 }
2647 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002648 Slog.e(TAG, "RemoteException when cancelling recent apps preload", e);
Jeff Browncaca8812013-05-09 13:34:33 -07002649 // re-acquire status bar service next time it is needed.
2650 mStatusBarService = null;
2651 }
2652 }
2653 }
2654
2655 private void toggleRecentApps() {
2656 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
Jeff Browncaca8812013-05-09 13:34:33 -07002657 try {
2658 IStatusBarService statusbar = getStatusBarService();
2659 if (statusbar != null) {
2660 statusbar.toggleRecentApps();
2661 }
2662 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002663 Slog.e(TAG, "RemoteException when toggling recent apps", e);
2664 // re-acquire status bar service next time it is needed.
2665 mStatusBarService = null;
2666 }
2667 }
2668
Craig Mautner84984fa2014-06-19 11:19:20 -07002669 @Override
2670 public void showRecentApps() {
2671 mHandler.removeMessages(MSG_DISPATCH_SHOW_RECENTS);
2672 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_RECENTS);
2673 }
2674
Winson Chung1e8d71b2014-05-16 17:05:22 -07002675 private void showRecentApps(boolean triggeredFromAltTab) {
2676 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
2677 try {
2678 IStatusBarService statusbar = getStatusBarService();
2679 if (statusbar != null) {
2680 statusbar.showRecentApps(triggeredFromAltTab);
2681 }
2682 } catch (RemoteException e) {
Jeff Browncaca8812013-05-09 13:34:33 -07002683 Slog.e(TAG, "RemoteException when showing recent apps", e);
2684 // re-acquire status bar service next time it is needed.
2685 mStatusBarService = null;
2686 }
2687 }
2688
Winson Chungcdcd4872014-08-05 18:00:13 -07002689 private void hideRecentApps(boolean triggeredFromAltTab, boolean triggeredFromHome) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002690 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
2691 try {
2692 IStatusBarService statusbar = getStatusBarService();
2693 if (statusbar != null) {
Winson Chungcdcd4872014-08-05 18:00:13 -07002694 statusbar.hideRecentApps(triggeredFromAltTab, triggeredFromHome);
Winson Chung1e8d71b2014-05-16 17:05:22 -07002695 }
2696 } catch (RemoteException e) {
2697 Slog.e(TAG, "RemoteException when closing recent apps", e);
2698 // re-acquire status bar service next time it is needed.
2699 mStatusBarService = null;
2700 }
2701 }
2702
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002703 /**
2704 * A home key -> launch home action was detected. Take the appropriate action
2705 * given the situation with the keyguard.
2706 */
2707 void launchHomeFromHotKey() {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01002708 if (mKeyguardDelegate != null && mKeyguardDelegate.isShowingAndNotOccluded()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002709 // don't launch home if keyguard showing
Jim Miller5ecd8112013-01-09 18:50:26 -08002710 } else if (!mHideLockScreen && mKeyguardDelegate.isInputRestricted()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002711 // when in keyguard restricted mode, must first verify unlock
2712 // before launching home
Jim Miller5ecd8112013-01-09 18:50:26 -08002713 mKeyguardDelegate.verifyUnlock(new OnKeyguardExitResult() {
Jose Lima9546b202014-07-02 17:21:51 -07002714 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002715 public void onKeyguardExitResult(boolean success) {
2716 if (success) {
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07002717 try {
2718 ActivityManagerNative.getDefault().stopAppSwitches();
2719 } catch (RemoteException e) {
2720 }
Joe Onoratof275f0c2009-11-24 16:11:13 -05002721 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07002722 startDockOrHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002723 }
2724 }
2725 });
2726 } else {
2727 // no keyguard stuff to worry about, just launch home!
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07002728 try {
2729 ActivityManagerNative.getDefault().stopAppSwitches();
2730 } catch (RemoteException e) {
2731 }
Winson Chungd543c1b2014-06-23 15:06:45 -07002732 if (mRecentsVisible) {
2733 // Hide Recents and notify it to launch Home
2734 awakenDreams();
2735 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
Winson Chungcdcd4872014-08-05 18:00:13 -07002736 hideRecentApps(false, true);
Winson Chungd543c1b2014-06-23 15:06:45 -07002737 } else {
2738 // Otherwise, just launch Home
2739 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
2740 startDockOrHome();
2741 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002742 }
2743 }
2744
John Spurlock04db1762013-05-13 12:46:41 -04002745 private final Runnable mClearHideNavigationFlag = new Runnable() {
2746 @Override
2747 public void run() {
2748 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
2749 // Clear flags.
2750 mForceClearedSystemUiFlags &=
2751 ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
2752 }
2753 mWindowManagerFuncs.reevaluateStatusBarVisibility();
Dianne Hackborne26ab702011-10-16 13:21:33 -07002754 }
2755 };
2756
2757 /**
2758 * Input handler used while nav bar is hidden. Captures any touch on the screen,
2759 * to determine when the nav bar should be shown and prevent applications from
2760 * receiving those touches.
2761 */
Jeff Brown32cbc38552011-12-01 14:01:49 -08002762 final class HideNavInputEventReceiver extends InputEventReceiver {
2763 public HideNavInputEventReceiver(InputChannel inputChannel, Looper looper) {
2764 super(inputChannel, looper);
2765 }
2766
Dianne Hackborndf89e652011-10-06 22:35:11 -07002767 @Override
Jeff Brown32cbc38552011-12-01 14:01:49 -08002768 public void onInputEvent(InputEvent event) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07002769 boolean handled = false;
2770 try {
Jeff Brown4952dfd2011-11-30 19:23:22 -08002771 if (event instanceof MotionEvent
2772 && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
2773 final MotionEvent motionEvent = (MotionEvent)event;
2774 if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07002775 // When the user taps down, we re-show the nav bar.
2776 boolean changed = false;
John Spurlock04db1762013-05-13 12:46:41 -04002777 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002778 // Any user activity always causes us to show the
2779 // navigation controls, if they had been hidden.
2780 // We also clear the low profile and only content
2781 // flags so that tapping on the screen will atomically
2782 // restore all currently hidden screen decorations.
2783 int newVal = mResettingSystemUiFlags |
2784 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
2785 View.SYSTEM_UI_FLAG_LOW_PROFILE |
2786 View.SYSTEM_UI_FLAG_FULLSCREEN;
Dianne Hackborne26ab702011-10-16 13:21:33 -07002787 if (mResettingSystemUiFlags != newVal) {
2788 mResettingSystemUiFlags = newVal;
Dianne Hackborndf89e652011-10-06 22:35:11 -07002789 changed = true;
2790 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07002791 // We don't allow the system's nav bar to be hidden
2792 // again for 1 second, to prevent applications from
2793 // spamming us and keeping it from being shown.
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002794 newVal = mForceClearedSystemUiFlags |
2795 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
Dianne Hackborne26ab702011-10-16 13:21:33 -07002796 if (mForceClearedSystemUiFlags != newVal) {
2797 mForceClearedSystemUiFlags = newVal;
2798 changed = true;
John Spurlock04db1762013-05-13 12:46:41 -04002799 mHandler.postDelayed(mClearHideNavigationFlag, 1000);
Dianne Hackborne26ab702011-10-16 13:21:33 -07002800 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07002801 }
2802 if (changed) {
2803 mWindowManagerFuncs.reevaluateStatusBarVisibility();
2804 }
2805 }
2806 }
2807 } finally {
Jeff Brown32cbc38552011-12-01 14:01:49 -08002808 finishInputEvent(event, handled);
Dianne Hackborndf89e652011-10-06 22:35:11 -07002809 }
2810 }
Jeff Brown32cbc38552011-12-01 14:01:49 -08002811 }
2812 final InputEventReceiver.Factory mHideNavInputEventReceiverFactory =
2813 new InputEventReceiver.Factory() {
2814 @Override
2815 public InputEventReceiver createInputEventReceiver(
2816 InputChannel inputChannel, Looper looper) {
2817 return new HideNavInputEventReceiver(inputChannel, looper);
2818 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07002819 };
2820
2821 @Override
2822 public int adjustSystemUiVisibilityLw(int visibility) {
John Spurlock5b9145b2013-08-20 15:13:47 -04002823 mStatusBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
2824 mNavigationBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
Winson Chungd42a6cf2014-06-03 16:24:04 -07002825 mRecentsVisible = (visibility & View.RECENT_APPS_VISIBLE) > 0;
John Spurlock27735a42013-08-14 17:57:38 -04002826
Dianne Hackborndf89e652011-10-06 22:35:11 -07002827 // Reset any bits in mForceClearingStatusBarVisibility that
2828 // are now clear.
Dianne Hackborne26ab702011-10-16 13:21:33 -07002829 mResettingSystemUiFlags &= visibility;
Dianne Hackborndf89e652011-10-06 22:35:11 -07002830 // Clear any bits in the new visibility that are currently being
2831 // force cleared, before reporting it.
Dianne Hackborne26ab702011-10-16 13:21:33 -07002832 return visibility & ~mResettingSystemUiFlags
2833 & ~mForceClearedSystemUiFlags;
Dianne Hackborndf89e652011-10-06 22:35:11 -07002834 }
2835
Craig Mautner69b08182012-09-05 13:07:13 -07002836 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002837 public void getContentInsetHintLw(WindowManager.LayoutParams attrs, Rect contentInset) {
John Spurlockc6d1c602014-01-17 15:22:06 -05002838 final int fl = PolicyControl.getWindowFlags(null, attrs);
John Spurlock1db8b682014-02-18 11:18:59 -05002839 final int sysuiVis = PolicyControl.getSystemUiVisibility(null, attrs);
2840 final int systemUiVisibility = (sysuiVis | attrs.subtreeSystemUiVisibility);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002841
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002842 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002843 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002844 int availRight, availBottom;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07002845 if (canHideNavigationBar() &&
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002846 (systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002847 availRight = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
2848 availBottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
2849 } else {
2850 availRight = mRestrictedScreenLeft + mRestrictedScreenWidth;
2851 availBottom = mRestrictedScreenTop + mRestrictedScreenHeight;
2852 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002853 if ((systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
2854 if ((fl & FLAG_FULLSCREEN) != 0) {
2855 contentInset.set(mStableFullscreenLeft, mStableFullscreenTop,
2856 availRight - mStableFullscreenRight,
2857 availBottom - mStableFullscreenBottom);
2858 } else {
2859 contentInset.set(mStableLeft, mStableTop,
2860 availRight - mStableRight, availBottom - mStableBottom);
2861 }
Dianne Hackbornc652de82013-02-15 16:32:56 -08002862 } else if ((fl & FLAG_FULLSCREEN) != 0 || (fl & FLAG_LAYOUT_IN_OVERSCAN) != 0) {
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002863 contentInset.setEmpty();
2864 } else if ((systemUiVisibility & (View.SYSTEM_UI_FLAG_FULLSCREEN
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002865 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)) == 0) {
2866 contentInset.set(mCurLeft, mCurTop,
2867 availRight - mCurRight, availBottom - mCurBottom);
2868 } else {
2869 contentInset.set(mCurLeft, mCurTop,
2870 availRight - mCurRight, availBottom - mCurBottom);
2871 }
2872 return;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002873 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002874 contentInset.setEmpty();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002875 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002876
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002877 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07002878 @Override
2879 public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight,
2880 int displayRotation) {
Dianne Hackbornc652de82013-02-15 16:32:56 -08002881 final int overscanLeft, overscanTop, overscanRight, overscanBottom;
2882 if (isDefaultDisplay) {
2883 switch (displayRotation) {
2884 case Surface.ROTATION_90:
2885 overscanLeft = mOverscanTop;
2886 overscanTop = mOverscanRight;
2887 overscanRight = mOverscanBottom;
2888 overscanBottom = mOverscanLeft;
2889 break;
2890 case Surface.ROTATION_180:
2891 overscanLeft = mOverscanRight;
2892 overscanTop = mOverscanBottom;
2893 overscanRight = mOverscanLeft;
2894 overscanBottom = mOverscanTop;
2895 break;
2896 case Surface.ROTATION_270:
2897 overscanLeft = mOverscanBottom;
2898 overscanTop = mOverscanLeft;
2899 overscanRight = mOverscanTop;
2900 overscanBottom = mOverscanRight;
2901 break;
2902 default:
2903 overscanLeft = mOverscanLeft;
2904 overscanTop = mOverscanTop;
2905 overscanRight = mOverscanRight;
2906 overscanBottom = mOverscanBottom;
2907 break;
2908 }
2909 } else {
2910 overscanLeft = 0;
2911 overscanTop = 0;
2912 overscanRight = 0;
2913 overscanBottom = 0;
2914 }
Dianne Hackborn313440842013-02-19 19:22:59 -08002915 mOverscanScreenLeft = mRestrictedOverscanScreenLeft = 0;
2916 mOverscanScreenTop = mRestrictedOverscanScreenTop = 0;
2917 mOverscanScreenWidth = mRestrictedOverscanScreenWidth = displayWidth;
2918 mOverscanScreenHeight = mRestrictedOverscanScreenHeight = displayHeight;
Dianne Hackbornc652de82013-02-15 16:32:56 -08002919 mSystemLeft = 0;
2920 mSystemTop = 0;
2921 mSystemRight = displayWidth;
2922 mSystemBottom = displayHeight;
2923 mUnrestrictedScreenLeft = overscanLeft;
2924 mUnrestrictedScreenTop = overscanTop;
2925 mUnrestrictedScreenWidth = displayWidth - overscanLeft - overscanRight;
2926 mUnrestrictedScreenHeight = displayHeight - overscanTop - overscanBottom;
2927 mRestrictedScreenLeft = mUnrestrictedScreenLeft;
2928 mRestrictedScreenTop = mUnrestrictedScreenTop;
John Spurlockad3e6cb2013-04-30 08:47:43 -04002929 mRestrictedScreenWidth = mSystemGestures.screenWidth = mUnrestrictedScreenWidth;
2930 mRestrictedScreenHeight = mSystemGestures.screenHeight = mUnrestrictedScreenHeight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002931 mDockLeft = mContentLeft = mVoiceContentLeft = mStableLeft = mStableFullscreenLeft
Dianne Hackbornc652de82013-02-15 16:32:56 -08002932 = mCurLeft = mUnrestrictedScreenLeft;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002933 mDockTop = mContentTop = mVoiceContentTop = mStableTop = mStableFullscreenTop
Dianne Hackbornc652de82013-02-15 16:32:56 -08002934 = mCurTop = mUnrestrictedScreenTop;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002935 mDockRight = mContentRight = mVoiceContentRight = mStableRight = mStableFullscreenRight
Dianne Hackbornc652de82013-02-15 16:32:56 -08002936 = mCurRight = displayWidth - overscanRight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002937 mDockBottom = mContentBottom = mVoiceContentBottom = mStableBottom = mStableFullscreenBottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08002938 = mCurBottom = displayHeight - overscanBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002939 mDockLayer = 0x10000000;
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002940 mStatusBarLayer = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002941
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002942 // start with the current dock rect, which will be (0,0,displayWidth,displayHeight)
2943 final Rect pf = mTmpParentFrame;
2944 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002945 final Rect of = mTmpOverscanFrame;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002946 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04002947 final Rect dcf = mTmpDecorFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002948 pf.left = df.left = of.left = vf.left = mDockLeft;
2949 pf.top = df.top = of.top = vf.top = mDockTop;
2950 pf.right = df.right = of.right = vf.right = mDockRight;
2951 pf.bottom = df.bottom = of.bottom = vf.bottom = mDockBottom;
John Spurlock46646232013-09-30 22:32:42 -04002952 dcf.setEmpty(); // Decor frame N/A for system bars.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002953
Craig Mautner69b08182012-09-05 13:07:13 -07002954 if (isDefaultDisplay) {
2955 // For purposes of putting out fake window up to steal focus, we will
2956 // drive nav being hidden only by whether it is requested.
John Spurlocke1f366f2013-08-05 12:22:40 -04002957 final int sysui = mLastSystemUiFlags;
2958 boolean navVisible = (sysui & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0;
Adrian Roosea562512014-05-05 13:33:03 +02002959 boolean navTranslucent = (sysui
2960 & (View.NAVIGATION_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04002961 boolean immersive = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
2962 boolean immersiveSticky = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
2963 boolean navAllowedHidden = immersive || immersiveSticky;
2964 navTranslucent &= !immersiveSticky; // transient trumps translucent
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04002965 navTranslucent &= areTranslucentBarsAllowed();
Dianne Hackborne26ab702011-10-16 13:21:33 -07002966
Craig Mautner69b08182012-09-05 13:07:13 -07002967 // When the navigation bar isn't visible, we put up a fake
2968 // input window to catch all touch events. This way we can
2969 // detect when the user presses anywhere to bring back the nav
2970 // bar and ensure the application doesn't see the event.
John Spurlockf1a36642013-10-12 17:50:42 -04002971 if (navVisible || navAllowedHidden) {
Craig Mautner69b08182012-09-05 13:07:13 -07002972 if (mHideNavFakeWindow != null) {
2973 mHideNavFakeWindow.dismiss();
2974 mHideNavFakeWindow = null;
2975 }
2976 } else if (mHideNavFakeWindow == null) {
2977 mHideNavFakeWindow = mWindowManagerFuncs.addFakeWindow(
2978 mHandler.getLooper(), mHideNavInputEventReceiverFactory,
Adam Lesinski95c42972013-10-02 10:13:27 -07002979 "hidden nav", WindowManager.LayoutParams.TYPE_HIDDEN_NAV_CONSUMER, 0,
Craig Mautner69b08182012-09-05 13:07:13 -07002980 0, false, false, true);
Dianne Hackborne26ab702011-10-16 13:21:33 -07002981 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07002982
Craig Mautner69b08182012-09-05 13:07:13 -07002983 // For purposes of positioning and showing the nav bar, if we have
2984 // decided that it can't be hidden (because of the screen aspect ratio),
2985 // then take that into account.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07002986 navVisible |= !canHideNavigationBar();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002987
John Spurlockad3e6cb2013-04-30 08:47:43 -04002988 boolean updateSysUiVisibility = false;
Craig Mautner69b08182012-09-05 13:07:13 -07002989 if (mNavigationBar != null) {
John Spurlock27735a42013-08-14 17:57:38 -04002990 boolean transientNavBarShowing = mNavigationBarController.isTransientShowing();
Craig Mautner69b08182012-09-05 13:07:13 -07002991 // Force the navigation bar to its appropriate place and
2992 // size. We need to do this directly, instead of relying on
2993 // it to bubble up from the nav bar, because this needs to
2994 // change atomically with screen rotations.
2995 mNavigationBarOnBottom = (!mNavigationBarCanMove || displayWidth < displayHeight);
2996 if (mNavigationBarOnBottom) {
2997 // It's a system nav bar or a portrait screen; nav bar goes on bottom.
Dianne Hackbornc652de82013-02-15 16:32:56 -08002998 int top = displayHeight - overscanBottom
2999 - mNavigationBarHeightForRotation[displayRotation];
3000 mTmpNavigationFrame.set(0, top, displayWidth, displayHeight - overscanBottom);
Craig Mautner69b08182012-09-05 13:07:13 -07003001 mStableBottom = mStableFullscreenBottom = mTmpNavigationFrame.top;
John Spurlockf95b89a2013-10-10 22:10:42 -04003002 if (transientNavBarShowing) {
John Spurlock27735a42013-08-14 17:57:38 -04003003 mNavigationBarController.setBarShowingLw(true);
John Spurlockad3e6cb2013-04-30 08:47:43 -04003004 } else if (navVisible) {
John Spurlock27735a42013-08-14 17:57:38 -04003005 mNavigationBarController.setBarShowingLw(true);
Craig Mautner69b08182012-09-05 13:07:13 -07003006 mDockBottom = mTmpNavigationFrame.top;
Dianne Hackborn313440842013-02-19 19:22:59 -08003007 mRestrictedScreenHeight = mDockBottom - mRestrictedScreenTop;
3008 mRestrictedOverscanScreenHeight = mDockBottom - mRestrictedOverscanScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07003009 } else {
3010 // We currently want to hide the navigation UI.
John Spurlock27735a42013-08-14 17:57:38 -04003011 mNavigationBarController.setBarShowingLw(false);
Craig Mautner69b08182012-09-05 13:07:13 -07003012 }
John Spurlockc6d1c602014-01-17 15:22:06 -05003013 if (navVisible && !navTranslucent && !navAllowedHidden
3014 && !mNavigationBar.isAnimatingLw()
John Spurlockbd957402013-10-03 11:38:39 -04003015 && !mNavigationBarController.wasRecentlyTranslucent()) {
John Spurlocke1f366f2013-08-05 12:22:40 -04003016 // If the opaque nav bar is currently requested to be visible,
Craig Mautner69b08182012-09-05 13:07:13 -07003017 // and not in the process of animating on or off, then
3018 // we can tell the app that it is covered by it.
3019 mSystemBottom = mTmpNavigationFrame.top;
3020 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003021 } else {
Craig Mautner69b08182012-09-05 13:07:13 -07003022 // Landscape screen; nav bar goes to the right.
Dianne Hackbornc652de82013-02-15 16:32:56 -08003023 int left = displayWidth - overscanRight
3024 - mNavigationBarWidthForRotation[displayRotation];
3025 mTmpNavigationFrame.set(left, 0, displayWidth - overscanRight, displayHeight);
Craig Mautner69b08182012-09-05 13:07:13 -07003026 mStableRight = mStableFullscreenRight = mTmpNavigationFrame.left;
John Spurlockf95b89a2013-10-10 22:10:42 -04003027 if (transientNavBarShowing) {
John Spurlock27735a42013-08-14 17:57:38 -04003028 mNavigationBarController.setBarShowingLw(true);
John Spurlockad3e6cb2013-04-30 08:47:43 -04003029 } else if (navVisible) {
John Spurlock27735a42013-08-14 17:57:38 -04003030 mNavigationBarController.setBarShowingLw(true);
Craig Mautner69b08182012-09-05 13:07:13 -07003031 mDockRight = mTmpNavigationFrame.left;
Dianne Hackborn313440842013-02-19 19:22:59 -08003032 mRestrictedScreenWidth = mDockRight - mRestrictedScreenLeft;
3033 mRestrictedOverscanScreenWidth = mDockRight - mRestrictedOverscanScreenLeft;
Craig Mautner69b08182012-09-05 13:07:13 -07003034 } else {
3035 // We currently want to hide the navigation UI.
John Spurlock27735a42013-08-14 17:57:38 -04003036 mNavigationBarController.setBarShowingLw(false);
Craig Mautner69b08182012-09-05 13:07:13 -07003037 }
John Spurlockbd957402013-10-03 11:38:39 -04003038 if (navVisible && !navTranslucent && !mNavigationBar.isAnimatingLw()
3039 && !mNavigationBarController.wasRecentlyTranslucent()) {
Craig Mautner69b08182012-09-05 13:07:13 -07003040 // If the nav bar is currently requested to be visible,
3041 // and not in the process of animating on or off, then
3042 // we can tell the app that it is covered by it.
3043 mSystemRight = mTmpNavigationFrame.left;
3044 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003045 }
Craig Mautner69b08182012-09-05 13:07:13 -07003046 // Make sure the content and current rectangles are updated to
3047 // account for the restrictions from the navigation bar.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003048 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3049 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3050 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3051 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
Craig Mautner69b08182012-09-05 13:07:13 -07003052 mStatusBarLayer = mNavigationBar.getSurfaceLayer();
3053 // And compute the final frame.
3054 mNavigationBar.computeFrameLw(mTmpNavigationFrame, mTmpNavigationFrame,
Adrian Roosfa104232014-06-20 16:10:14 -07003055 mTmpNavigationFrame, mTmpNavigationFrame, mTmpNavigationFrame, dcf,
3056 mTmpNavigationFrame);
Craig Mautnereda67292013-04-28 13:50:14 -07003057 if (DEBUG_LAYOUT) Slog.i(TAG, "mNavigationBar frame: " + mTmpNavigationFrame);
John Spurlock27735a42013-08-14 17:57:38 -04003058 if (mNavigationBarController.checkHiddenLw()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04003059 updateSysUiVisibility = true;
3060 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003061 }
Craig Mautnereda67292013-04-28 13:50:14 -07003062 if (DEBUG_LAYOUT) Slog.i(TAG, String.format("mDock rect: (%d,%d - %d,%d)",
Craig Mautner69b08182012-09-05 13:07:13 -07003063 mDockLeft, mDockTop, mDockRight, mDockBottom));
3064
3065 // decide where the status bar goes ahead of time
3066 if (mStatusBar != null) {
3067 // apply any navigation bar insets
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003068 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3069 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3070 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
3071 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight
3072 + mUnrestrictedScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07003073 vf.left = mStableLeft;
3074 vf.top = mStableTop;
3075 vf.right = mStableRight;
3076 vf.bottom = mStableBottom;
3077
3078 mStatusBarLayer = mStatusBar.getSurfaceLayer();
3079
3080 // Let the status bar determine its size.
Adrian Roosfa104232014-06-20 16:10:14 -07003081 mStatusBar.computeFrameLw(pf, df, vf, vf, vf, dcf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07003082
3083 // For layout, the status bar is always at the top with our fixed height.
3084 mStableTop = mUnrestrictedScreenTop + mStatusBarHeight;
3085
John Spurlocke1f366f2013-08-05 12:22:40 -04003086 boolean statusBarTransient = (sysui & View.STATUS_BAR_TRANSIENT) != 0;
Adrian Roosea562512014-05-05 13:33:03 +02003087 boolean statusBarTranslucent = (sysui
3088 & (View.STATUS_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0;
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04003089 statusBarTranslucent &= areTranslucentBarsAllowed();
John Spurlock32beb2c2013-03-11 10:16:47 -04003090
Craig Mautner69b08182012-09-05 13:07:13 -07003091 // If the status bar is hidden, we don't want to cause
3092 // windows behind it to scroll.
John Spurlockeda1f692013-09-16 11:38:44 -04003093 if (mStatusBar.isVisibleLw() && !statusBarTransient) {
Craig Mautner69b08182012-09-05 13:07:13 -07003094 // Status bar may go away, so the screen area it occupies
3095 // is available to apps but just covering them when the
3096 // status bar is visible.
3097 mDockTop = mUnrestrictedScreenTop + mStatusBarHeight;
3098
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003099 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3100 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3101 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3102 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
Craig Mautner69b08182012-09-05 13:07:13 -07003103
Craig Mautnereda67292013-04-28 13:50:14 -07003104 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar: " +
Craig Mautner69b08182012-09-05 13:07:13 -07003105 String.format(
3106 "dock=[%d,%d][%d,%d] content=[%d,%d][%d,%d] cur=[%d,%d][%d,%d]",
3107 mDockLeft, mDockTop, mDockRight, mDockBottom,
3108 mContentLeft, mContentTop, mContentRight, mContentBottom,
3109 mCurLeft, mCurTop, mCurRight, mCurBottom));
3110 }
John Spurlocke1f366f2013-08-05 12:22:40 -04003111 if (mStatusBar.isVisibleLw() && !mStatusBar.isAnimatingLw()
John Spurlockbd957402013-10-03 11:38:39 -04003112 && !statusBarTransient && !statusBarTranslucent
3113 && !mStatusBarController.wasRecentlyTranslucent()) {
John Spurlocke1f366f2013-08-05 12:22:40 -04003114 // If the opaque status bar is currently requested to be visible,
Craig Mautner69b08182012-09-05 13:07:13 -07003115 // and not in the process of animating on or off, then
3116 // we can tell the app that it is covered by it.
3117 mSystemTop = mUnrestrictedScreenTop + mStatusBarHeight;
3118 }
John Spurlock27735a42013-08-14 17:57:38 -04003119 if (mStatusBarController.checkHiddenLw()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04003120 updateSysUiVisibility = true;
John Spurlock32beb2c2013-03-11 10:16:47 -04003121 }
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003122 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04003123 if (updateSysUiVisibility) {
3124 updateSystemUiVisibilityLw();
3125 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003126 }
3127 }
3128
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003129 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07003130 @Override
John Spurlock46646232013-09-30 22:32:42 -04003131 public int getSystemDecorLayerLw() {
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003132 if (mStatusBar != null) return mStatusBar.getSurfaceLayer();
3133 if (mNavigationBar != null) return mNavigationBar.getSurfaceLayer();
3134 return 0;
3135 }
3136
Craig Mautner967212c2013-04-13 21:10:58 -07003137 @Override
3138 public void getContentRectLw(Rect r) {
3139 r.set(mContentLeft, mContentTop, mContentRight, mContentBottom);
3140 }
3141
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003142 void setAttachedWindowFrames(WindowState win, int fl, int adjust, WindowState attached,
3143 boolean insetDecors, Rect pf, Rect df, Rect of, Rect cf, Rect vf) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003144 if (win.getSurfaceLayer() > mDockLayer && attached.getSurfaceLayer() < mDockLayer) {
3145 // Here's a special case: if this attached window is a panel that is
3146 // above the dock window, and the window it is attached to is below
3147 // the dock window, then the frames we computed for the window it is
3148 // attached to can not be used because the dock is effectively part
3149 // of the underlying window and the attached window is floating on top
3150 // of the whole thing. So, we ignore the attached window and explicitly
3151 // compute the frames that would be appropriate without the dock.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003152 df.left = of.left = cf.left = vf.left = mDockLeft;
3153 df.top = of.top = cf.top = vf.top = mDockTop;
3154 df.right = of.right = cf.right = vf.right = mDockRight;
3155 df.bottom = of.bottom = cf.bottom = vf.bottom = mDockBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003156 } else {
3157 // The effective display frame of the attached window depends on
3158 // whether it is taking care of insetting its content. If not,
3159 // we need to use the parent's content frame so that the entire
3160 // window is positioned within that content. Otherwise we can use
3161 // the display frame and let the attached window take care of
3162 // positioning its content appropriately.
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003163 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003164 cf.set(attached.getOverscanFrameLw());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003165 } else {
3166 // If the window is resizing, then we want to base the content
3167 // frame on our attached content frame to resize... however,
3168 // things can be tricky if the attached window is NOT in resize
3169 // mode, in which case its content frame will be larger.
3170 // Ungh. So to deal with that, make sure the content frame
3171 // we end up using is not covering the IM dock.
3172 cf.set(attached.getContentFrameLw());
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003173 if (attached.isVoiceInteraction()) {
3174 if (cf.left < mVoiceContentLeft) cf.left = mVoiceContentLeft;
3175 if (cf.top < mVoiceContentTop) cf.top = mVoiceContentTop;
3176 if (cf.right > mVoiceContentRight) cf.right = mVoiceContentRight;
3177 if (cf.bottom > mVoiceContentBottom) cf.bottom = mVoiceContentBottom;
3178 } else if (attached.getSurfaceLayer() < mDockLayer) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003179 if (cf.left < mContentLeft) cf.left = mContentLeft;
3180 if (cf.top < mContentTop) cf.top = mContentTop;
3181 if (cf.right > mContentRight) cf.right = mContentRight;
3182 if (cf.bottom > mContentBottom) cf.bottom = mContentBottom;
3183 }
3184 }
3185 df.set(insetDecors ? attached.getDisplayFrameLw() : cf);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003186 of.set(insetDecors ? attached.getOverscanFrameLw() : cf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003187 vf.set(attached.getVisibleFrameLw());
3188 }
3189 // The LAYOUT_IN_SCREEN flag is used to determine whether the attached
3190 // window should be positioned relative to its parent or the entire
3191 // screen.
3192 pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0
3193 ? attached.getFrameLw() : df);
3194 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003195
3196 private void applyStableConstraints(int sysui, int fl, Rect r) {
3197 if ((sysui & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
3198 // If app is requesting a stable layout, don't let the
3199 // content insets go below the stable values.
3200 if ((fl & FLAG_FULLSCREEN) != 0) {
3201 if (r.left < mStableFullscreenLeft) r.left = mStableFullscreenLeft;
3202 if (r.top < mStableFullscreenTop) r.top = mStableFullscreenTop;
3203 if (r.right > mStableFullscreenRight) r.right = mStableFullscreenRight;
3204 if (r.bottom > mStableFullscreenBottom) r.bottom = mStableFullscreenBottom;
3205 } else {
3206 if (r.left < mStableLeft) r.left = mStableLeft;
3207 if (r.top < mStableTop) r.top = mStableTop;
3208 if (r.right > mStableRight) r.right = mStableRight;
3209 if (r.bottom > mStableBottom) r.bottom = mStableBottom;
3210 }
3211 }
3212 }
3213
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003214 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07003215 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003216 public void layoutWindowLw(WindowState win, WindowState attached) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003217 // we've already done the status bar
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003218 final WindowManager.LayoutParams attrs = win.getAttrs();
3219 if ((win == mStatusBar && (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) == 0) ||
3220 win == mNavigationBar) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003221 return;
3222 }
Craig Mautner69b08182012-09-05 13:07:13 -07003223 final boolean isDefaultDisplay = win.isDefaultDisplay();
3224 final boolean needsToOffsetInputMethodTarget = isDefaultDisplay &&
satok1bc0a492012-04-25 22:47:12 +09003225 (win == mLastInputMethodTargetWindow && mLastInputMethodWindow != null);
3226 if (needsToOffsetInputMethodTarget) {
Craig Mautnereda67292013-04-28 13:50:14 -07003227 if (DEBUG_LAYOUT) Slog.i(TAG, "Offset ime target window by the last ime window state");
satok1bc0a492012-04-25 22:47:12 +09003228 offsetInputMethodWindowLw(mLastInputMethodWindow);
3229 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003230
John Spurlockc6d1c602014-01-17 15:22:06 -05003231 final int fl = PolicyControl.getWindowFlags(win, attrs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003232 final int sim = attrs.softInputMode;
John Spurlock1db8b682014-02-18 11:18:59 -05003233 final int sysUiFl = PolicyControl.getSystemUiVisibility(win, null);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003234
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003235 final Rect pf = mTmpParentFrame;
3236 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003237 final Rect of = mTmpOverscanFrame;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003238 final Rect cf = mTmpContentFrame;
3239 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04003240 final Rect dcf = mTmpDecorFrame;
Adrian Roosfa104232014-06-20 16:10:14 -07003241 final Rect sf = mTmpStableFrame;
John Spurlock46646232013-09-30 22:32:42 -04003242 dcf.setEmpty();
Craig Mautner69b08182012-09-05 13:07:13 -07003243
3244 final boolean hasNavBar = (isDefaultDisplay && mHasNavigationBar
Daniel Sandler36412a72011-08-04 09:35:13 -04003245 && mNavigationBar != null && mNavigationBar.isVisibleLw());
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003246
Craig Mautnerf683b562012-10-02 11:10:57 -07003247 final int adjust = sim & SOFT_INPUT_MASK_ADJUST;
3248
Adrian Roosfa104232014-06-20 16:10:14 -07003249 if (isDefaultDisplay) {
3250 sf.set(mStableLeft, mStableTop, mStableRight, mStableBottom);
3251 } else {
3252 sf.set(mOverscanLeft, mOverscanTop, mOverscanRight, mOverscanBottom);
3253 }
3254
Craig Mautner69b08182012-09-05 13:07:13 -07003255 if (!isDefaultDisplay) {
3256 if (attached != null) {
3257 // If this window is attached to another, our display
3258 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003259 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07003260 } else {
3261 // Give the window full screen.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003262 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3263 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3264 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08003265 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003266 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003267 = mOverscanScreenTop + mOverscanScreenHeight;
Craig Mautner69b08182012-09-05 13:07:13 -07003268 }
3269 } else if (attrs.type == TYPE_INPUT_METHOD) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003270 pf.left = df.left = of.left = cf.left = vf.left = mDockLeft;
3271 pf.top = df.top = of.top = cf.top = vf.top = mDockTop;
3272 pf.right = df.right = of.right = cf.right = vf.right = mDockRight;
John Spurlockc68d5772013-10-08 11:47:58 -04003273 // IM dock windows layout below the nav bar...
John Spurlock57beb3b2013-10-10 10:27:44 -04003274 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlockc68d5772013-10-08 11:47:58 -04003275 // ...with content insets above the nav bar
3276 cf.bottom = vf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003277 // IM dock windows always go to the bottom of the screen.
3278 attrs.gravity = Gravity.BOTTOM;
3279 mDockLayer = win.getSurfaceLayer();
3280 } else {
John Spurlock46646232013-09-30 22:32:42 -04003281
3282 // Default policy decor for the default display
3283 dcf.left = mSystemLeft;
3284 dcf.top = mSystemTop;
3285 dcf.right = mSystemRight;
3286 dcf.bottom = mSystemBottom;
John Spurlockbd957402013-10-03 11:38:39 -04003287 final boolean inheritTranslucentDecor = (attrs.privateFlags
3288 & WindowManager.LayoutParams.PRIVATE_FLAG_INHERIT_TRANSLUCENT_DECOR) != 0;
John Spurlock65567d42013-10-08 10:08:32 -04003289 final boolean isAppWindow =
3290 attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW &&
3291 attrs.type <= WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
3292 final boolean topAtRest =
3293 win == mTopFullscreenOpaqueWindowState && !win.isAnimatingLw();
3294 if (isAppWindow && !inheritTranslucentDecor && !topAtRest) {
John Spurlockbd957402013-10-03 11:38:39 -04003295 if ((sysUiFl & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0
3296 && (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0
Adrian Roosea562512014-05-05 13:33:03 +02003297 && (fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) == 0
3298 && (fl & WindowManager.LayoutParams.
3299 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04003300 // Ensure policy decor includes status bar
3301 dcf.top = mStableTop;
3302 }
John Spurlockbd957402013-10-03 11:38:39 -04003303 if ((fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) == 0
Adrian Roosea562512014-05-05 13:33:03 +02003304 && (sysUiFl & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0
3305 && (fl & WindowManager.LayoutParams.
3306 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04003307 // Ensure policy decor includes navigation bar
3308 dcf.bottom = mStableBottom;
3309 dcf.right = mStableRight;
3310 }
3311 }
3312
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003313 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
3314 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
RoboErik8a2cfc32014-05-16 11:19:38 -07003315 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003316 + "): IN_SCREEN, INSET_DECOR");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003317 // This is the case for a normal activity window: we want it
3318 // to cover all of the screen space, and it can take care of
3319 // moving its contents to account for screen decorations that
3320 // intrude into that space.
3321 if (attached != null) {
3322 // If this window is attached to another, our display
3323 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003324 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003325 } else {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003326 if (attrs.type == TYPE_STATUS_BAR_PANEL
3327 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Joe Onorato29fc2c92010-11-24 10:26:50 -08003328 // Status bar panels are the only windows who can go on top of
3329 // the status bar. They are protected by the STATUS_BAR_SERVICE
3330 // permission, so they have the same privileges as the status
3331 // bar itself.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003332 //
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003333 // However, they should still dodge the navigation bar if it exists.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003334
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003335 pf.left = df.left = of.left = hasNavBar
3336 ? mDockLeft : mUnrestrictedScreenLeft;
3337 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3338 pf.right = df.right = of.right = hasNavBar
3339 ? mRestrictedScreenLeft+mRestrictedScreenWidth
3340 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3341 pf.bottom = df.bottom = of.bottom = hasNavBar
3342 ? mRestrictedScreenTop+mRestrictedScreenHeight
3343 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003344
Craig Mautnereda67292013-04-28 13:50:14 -07003345 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003346 "Laying out status bar window: (%d,%d - %d,%d)",
3347 pf.left, pf.top, pf.right, pf.bottom));
John Spurlock46646232013-09-30 22:32:42 -04003348 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08003349 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3350 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3351 // Asking to layout into the overscan region, so give it that pure
3352 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003353 pf.left = df.left = of.left = mOverscanScreenLeft;
3354 pf.top = df.top = of.top = mOverscanScreenTop;
3355 pf.right = df.right = of.right = mOverscanScreenLeft + mOverscanScreenWidth;
3356 pf.bottom = df.bottom = of.bottom = mOverscanScreenTop
3357 + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003358 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003359 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003360 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3361 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003362 // Asking for layout as if the nav bar is hidden, lets the
Dianne Hackbornc652de82013-02-15 16:32:56 -08003363 // application extend into the unrestricted overscan screen area. We
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003364 // only do this for application windows to ensure no window that
3365 // can be above the nav bar can do this.
Dianne Hackborn313440842013-02-19 19:22:59 -08003366 pf.left = df.left = mOverscanScreenLeft;
3367 pf.top = df.top = mOverscanScreenTop;
3368 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
3369 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003370 // We need to tell the app about where the frame inside the overscan
3371 // is, so it can inset its content by that amount -- it didn't ask
3372 // to actually extend itself into the overscan region.
3373 of.left = mUnrestrictedScreenLeft;
3374 of.top = mUnrestrictedScreenTop;
3375 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3376 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003377 } else {
Dianne Hackborn313440842013-02-19 19:22:59 -08003378 pf.left = df.left = mRestrictedOverscanScreenLeft;
3379 pf.top = df.top = mRestrictedOverscanScreenTop;
3380 pf.right = df.right = mRestrictedOverscanScreenLeft
3381 + mRestrictedOverscanScreenWidth;
3382 pf.bottom = df.bottom = mRestrictedOverscanScreenTop
3383 + mRestrictedOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003384 // We need to tell the app about where the frame inside the overscan
3385 // is, so it can inset its content by that amount -- it didn't ask
3386 // to actually extend itself into the overscan region.
3387 of.left = mUnrestrictedScreenLeft;
3388 of.top = mUnrestrictedScreenTop;
3389 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3390 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003391 }
Craig Mautner69b08182012-09-05 13:07:13 -07003392
John Spurlock46646232013-09-30 22:32:42 -04003393 if ((fl & FLAG_FULLSCREEN) == 0) {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003394 if (win.isVoiceInteraction()) {
3395 cf.left = mVoiceContentLeft;
3396 cf.top = mVoiceContentTop;
3397 cf.right = mVoiceContentRight;
3398 cf.bottom = mVoiceContentBottom;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003399 } else {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003400 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
3401 cf.left = mDockLeft;
3402 cf.top = mDockTop;
3403 cf.right = mDockRight;
3404 cf.bottom = mDockBottom;
3405 } else {
3406 cf.left = mContentLeft;
3407 cf.top = mContentTop;
3408 cf.right = mContentRight;
3409 cf.bottom = mContentBottom;
3410 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003411 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003412 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003413 // Full screen windows are always given a layout that is as if the
3414 // status bar and other transient decors are gone. This is to avoid
3415 // bad states when moving from a window that is not hding the
3416 // status bar to one that is.
3417 cf.left = mRestrictedScreenLeft;
3418 cf.top = mRestrictedScreenTop;
3419 cf.right = mRestrictedScreenLeft + mRestrictedScreenWidth;
3420 cf.bottom = mRestrictedScreenTop + mRestrictedScreenHeight;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003421 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003422 applyStableConstraints(sysUiFl, fl, cf);
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003423 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3424 vf.left = mCurLeft;
3425 vf.top = mCurTop;
3426 vf.right = mCurRight;
3427 vf.bottom = mCurBottom;
3428 } else {
3429 vf.set(cf);
3430 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003431 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003432 } else if ((fl & FLAG_LAYOUT_IN_SCREEN) != 0 || (sysUiFl
3433 & (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
3434 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)) != 0) {
Craig Mautnereda67292013-04-28 13:50:14 -07003435 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3436 "): IN_SCREEN");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003437 // A window that has requested to fill the entire screen just
3438 // gets everything, period.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003439 if (attrs.type == TYPE_STATUS_BAR_PANEL
3440 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003441 pf.left = df.left = of.left = cf.left = hasNavBar
3442 ? mDockLeft : mUnrestrictedScreenLeft;
3443 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
3444 pf.right = df.right = of.right = cf.right = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003445 ? mRestrictedScreenLeft+mRestrictedScreenWidth
Dianne Hackbornc652de82013-02-15 16:32:56 -08003446 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003447 pf.bottom = df.bottom = of.bottom = cf.bottom = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003448 ? mRestrictedScreenTop+mRestrictedScreenHeight
Dianne Hackbornc652de82013-02-15 16:32:56 -08003449 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07003450 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler36412a72011-08-04 09:35:13 -04003451 "Laying out IN_SCREEN status bar window: (%d,%d - %d,%d)",
3452 pf.left, pf.top, pf.right, pf.bottom));
Jim Millere898ac52012-04-06 17:10:57 -07003453 } else if (attrs.type == TYPE_NAVIGATION_BAR
3454 || attrs.type == TYPE_NAVIGATION_BAR_PANEL) {
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003455 // The navigation bar has Real Ultimate Power.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003456 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3457 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3458 pf.right = df.right = of.right = mUnrestrictedScreenLeft
3459 + mUnrestrictedScreenWidth;
3460 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop
3461 + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07003462 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003463 "Laying out navigation bar window: (%d,%d - %d,%d)",
3464 pf.left, pf.top, pf.right, pf.bottom));
Dianne Hackborn01011c32012-02-21 13:54:21 -08003465 } else if ((attrs.type == TYPE_SECURE_SYSTEM_OVERLAY
3466 || attrs.type == TYPE_BOOT_PROGRESS)
Jeff Brownbfcb60a2011-09-08 18:51:14 -07003467 && ((fl & FLAG_FULLSCREEN) != 0)) {
3468 // Fullscreen secure system overlays get what they ask for.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003469 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3470 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3471 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
3472 + mOverscanScreenWidth;
3473 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
3474 + mOverscanScreenHeight;
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07003475 } else if (attrs.type == TYPE_BOOT_PROGRESS
3476 || attrs.type == TYPE_UNIVERSE_BACKGROUND) {
Dianne Hackborn01011c32012-02-21 13:54:21 -08003477 // Boot progress screen always covers entire display.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003478 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3479 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3480 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
3481 + mOverscanScreenWidth;
3482 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
3483 + mOverscanScreenHeight;
John Spurlockef4adae2013-08-26 17:58:58 -04003484 } else if (attrs.type == TYPE_WALLPAPER) {
3485 // The wallpaper also has Real Ultimate Power.
3486 pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft;
3487 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003488 pf.right = df.right = of.right = cf.right
John Spurlockef4adae2013-08-26 17:58:58 -04003489 = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003490 pf.bottom = df.bottom = of.bottom = cf.bottom
John Spurlockef4adae2013-08-26 17:58:58 -04003491 = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlock46646232013-09-30 22:32:42 -04003492 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08003493 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3494 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3495 // Asking to layout into the overscan region, so give it that pure
3496 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003497 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3498 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3499 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08003500 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003501 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003502 = mOverscanScreenTop + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003503 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003504 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Craig Mautnerbeac1062014-06-03 14:38:57 -07003505 && (attrs.type == TYPE_STATUS_BAR
3506 || attrs.type == TYPE_TOAST
John Spurlock34e13d92013-08-10 06:52:28 -04003507 || (attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3508 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW))) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003509 // Asking for layout as if the nav bar is hidden, lets the
3510 // application extend into the unrestricted screen area. We
John Spurlock34e13d92013-08-10 06:52:28 -04003511 // only do this for application windows (or toasts) to ensure no window that
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003512 // can be above the nav bar can do this.
3513 // XXX This assumes that an app asking for this will also
3514 // ask for layout in only content. We can't currently figure out
3515 // what the screen would be if only laying out to hide the nav bar.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003516 pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft;
3517 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
3518 pf.right = df.right = of.right = cf.right = mUnrestrictedScreenLeft
3519 + mUnrestrictedScreenWidth;
3520 pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop
3521 + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003522 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003523 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
3524 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
3525 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
3526 + mRestrictedScreenWidth;
3527 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
3528 + mRestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003529 }
Craig Mautner69b08182012-09-05 13:07:13 -07003530
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003531 applyStableConstraints(sysUiFl, fl, cf);
Craig Mautner69b08182012-09-05 13:07:13 -07003532
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003533 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3534 vf.left = mCurLeft;
3535 vf.top = mCurTop;
3536 vf.right = mCurRight;
3537 vf.bottom = mCurBottom;
3538 } else {
3539 vf.set(cf);
3540 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003541 } else if (attached != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07003542 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3543 "): attached to " + attached);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003544 // A child window should be placed inside of the same visible
3545 // frame that its parent had.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003546 setAttachedWindowFrames(win, fl, adjust, attached, false, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003547 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07003548 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3549 "): normal window");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003550 // Otherwise, a normal window must be placed inside the content
3551 // of all screen decorations.
Dianne Hackborna239c842011-06-01 12:28:20 -07003552 if (attrs.type == TYPE_STATUS_BAR_PANEL) {
3553 // Status bar panels are the only windows who can go on top of
3554 // the status bar. They are protected by the STATUS_BAR_SERVICE
3555 // permission, so they have the same privileges as the status
3556 // bar itself.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003557 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
3558 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
3559 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
3560 + mRestrictedScreenWidth;
3561 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
3562 + mRestrictedScreenHeight;
John Spurlock414c1f02013-12-04 13:47:36 -05003563 } else if (attrs.type == TYPE_TOAST || attrs.type == TYPE_SYSTEM_ALERT
3564 || attrs.type == TYPE_VOLUME_OVERLAY) {
3565 // These dialogs are stable to interim decor changes.
John Spurlockbd957402013-10-03 11:38:39 -04003566 pf.left = df.left = of.left = cf.left = mStableLeft;
3567 pf.top = df.top = of.top = cf.top = mStableTop;
3568 pf.right = df.right = of.right = cf.right = mStableRight;
3569 pf.bottom = df.bottom = of.bottom = cf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003570 } else {
Dianne Hackborna239c842011-06-01 12:28:20 -07003571 pf.left = mContentLeft;
3572 pf.top = mContentTop;
3573 pf.right = mContentRight;
3574 pf.bottom = mContentBottom;
Dianne Hackborn20d94742014-05-29 18:35:45 -07003575 if (win.isVoiceInteraction()) {
3576 df.left = of.left = cf.left = mVoiceContentLeft;
3577 df.top = of.top = cf.top = mVoiceContentTop;
3578 df.right = of.right = cf.right = mVoiceContentRight;
3579 df.bottom = of.bottom = cf.bottom = mVoiceContentBottom;
3580 } else if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003581 df.left = of.left = cf.left = mDockLeft;
3582 df.top = of.top = cf.top = mDockTop;
3583 df.right = of.right = cf.right = mDockRight;
3584 df.bottom = of.bottom = cf.bottom = mDockBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07003585 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003586 df.left = of.left = cf.left = mContentLeft;
3587 df.top = of.top = cf.top = mContentTop;
3588 df.right = of.right = cf.right = mContentRight;
3589 df.bottom = of.bottom = cf.bottom = mContentBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07003590 }
3591 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3592 vf.left = mCurLeft;
3593 vf.top = mCurTop;
3594 vf.right = mCurRight;
3595 vf.bottom = mCurBottom;
3596 } else {
3597 vf.set(cf);
3598 }
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003599 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003600 }
3601 }
Craig Mautner69b08182012-09-05 13:07:13 -07003602
Craig Mautnerb816bed2013-07-23 10:26:17 -07003603 // TYPE_SYSTEM_ERROR is above the NavigationBar so it can't be allowed to extend over it.
3604 if ((fl & FLAG_LAYOUT_NO_LIMITS) != 0 && attrs.type != TYPE_SYSTEM_ERROR) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003605 df.left = df.top = of.left = of.top = cf.left = cf.top = vf.left = vf.top = -10000;
3606 df.right = df.bottom = of.right = of.bottom = cf.right = cf.bottom
3607 = vf.right = vf.bottom = 10000;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003608 }
3609
Craig Mautnereda67292013-04-28 13:50:14 -07003610 if (DEBUG_LAYOUT) Slog.v(TAG, "Compute frame " + attrs.getTitle()
The Android Open Source Project11267662009-03-18 17:39:47 -07003611 + ": sim=#" + Integer.toHexString(sim)
RoboErik8a2cfc32014-05-16 11:19:38 -07003612 + " attach=" + attached + " type=" + attrs.type
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003613 + String.format(" flags=0x%08x", fl)
The Android Open Source Project11267662009-03-18 17:39:47 -07003614 + " pf=" + pf.toShortString() + " df=" + df.toShortString()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003615 + " of=" + of.toShortString()
John Spurlock46646232013-09-30 22:32:42 -04003616 + " cf=" + cf.toShortString() + " vf=" + vf.toShortString()
Adrian Roosfa104232014-06-20 16:10:14 -07003617 + " dcf=" + dcf.toShortString()
3618 + " sf=" + sf.toShortString());
Craig Mautner69b08182012-09-05 13:07:13 -07003619
Adrian Roosfa104232014-06-20 16:10:14 -07003620 win.computeFrameLw(pf, df, of, cf, vf, dcf, sf);
Craig Mautner69b08182012-09-05 13:07:13 -07003621
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003622 // Dock windows carve out the bottom of the screen, so normal windows
3623 // can't appear underneath them.
Craig Mautner8bd206b2012-10-03 10:32:02 -07003624 if (attrs.type == TYPE_INPUT_METHOD && win.isVisibleOrBehindKeyguardLw()
3625 && !win.getGivenInsetsPendingLw()) {
satok1bc0a492012-04-25 22:47:12 +09003626 setLastInputMethodWindowLw(null, null);
3627 offsetInputMethodWindowLw(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003628 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003629 if (attrs.type == TYPE_VOICE_INTERACTION && win.isVisibleOrBehindKeyguardLw()
3630 && !win.getGivenInsetsPendingLw()) {
3631 offsetVoiceInputWindowLw(win);
3632 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003633 }
3634
satok1bc0a492012-04-25 22:47:12 +09003635 private void offsetInputMethodWindowLw(WindowState win) {
3636 int top = win.getContentFrameLw().top;
3637 top += win.getGivenContentInsetsLw().top;
3638 if (mContentBottom > top) {
3639 mContentBottom = top;
3640 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003641 if (mVoiceContentBottom > top) {
3642 mVoiceContentBottom = top;
3643 }
satok1bc0a492012-04-25 22:47:12 +09003644 top = win.getVisibleFrameLw().top;
3645 top += win.getGivenVisibleInsetsLw().top;
3646 if (mCurBottom > top) {
3647 mCurBottom = top;
3648 }
Craig Mautnereda67292013-04-28 13:50:14 -07003649 if (DEBUG_LAYOUT) Slog.v(TAG, "Input method: mDockBottom="
satok1bc0a492012-04-25 22:47:12 +09003650 + mDockBottom + " mContentBottom="
3651 + mContentBottom + " mCurBottom=" + mCurBottom);
3652 }
3653
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003654 private void offsetVoiceInputWindowLw(WindowState win) {
3655 final int gravity = win.getAttrs().gravity;
3656 switch (gravity&((Gravity.AXIS_PULL_BEFORE|Gravity.AXIS_PULL_AFTER)
3657 << Gravity.AXIS_X_SHIFT)) {
3658 case Gravity.AXIS_PULL_BEFORE<<Gravity.AXIS_X_SHIFT: {
3659 int right = win.getContentFrameLw().right - win.getGivenContentInsetsLw().right;
3660 if (mVoiceContentLeft < right) {
3661 mVoiceContentLeft = right;
3662 }
3663 } break;
3664 case Gravity.AXIS_PULL_AFTER<<Gravity.AXIS_X_SHIFT: {
3665 int left = win.getContentFrameLw().left - win.getGivenContentInsetsLw().left;
3666 if (mVoiceContentRight < left) {
3667 mVoiceContentRight = left;
3668 }
3669 } break;
3670 }
3671 switch (gravity&((Gravity.AXIS_PULL_BEFORE|Gravity.AXIS_PULL_AFTER)
3672 << Gravity.AXIS_Y_SHIFT)) {
3673 case Gravity.AXIS_PULL_BEFORE<<Gravity.AXIS_Y_SHIFT: {
3674 int bottom = win.getContentFrameLw().bottom - win.getGivenContentInsetsLw().bottom;
3675 if (mVoiceContentTop < bottom) {
3676 mVoiceContentTop = bottom;
3677 }
3678 } break;
3679 case Gravity.AXIS_PULL_AFTER<<Gravity.AXIS_Y_SHIFT: {
3680 int top = win.getContentFrameLw().top - win.getGivenContentInsetsLw().top;
3681 if (mVoiceContentBottom < top) {
3682 mVoiceContentBottom = top;
3683 }
3684 } break;
3685 }
3686 }
3687
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003688 /** {@inheritDoc} */
Craig Mautner61ac6bb2012-02-02 17:29:33 -08003689 @Override
3690 public void finishLayoutLw() {
3691 return;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003692 }
3693
3694 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003695 @Override
Craig Mautner39834192012-09-02 07:47:24 -07003696 public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) {
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003697 mTopFullscreenOpaqueWindowState = null;
Craig Mautner2bc789b2014-03-19 19:48:38 -07003698 mAppsToBeHidden.clear();
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003699 mForceStatusBar = false;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003700 mForceStatusBarFromKeyguard = false;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08003701 mForcingShowNavBar = false;
3702 mForcingShowNavBarLayer = -1;
RoboErik8a2cfc32014-05-16 11:19:38 -07003703
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003704 mHideLockScreen = false;
3705 mAllowLockscreenWhenOn = false;
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003706 mDismissKeyguard = DISMISS_KEYGUARD_NONE;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003707 mShowingLockscreen = false;
3708 mShowingDream = false;
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003709 mWinShowWhenLocked = null;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003710 }
3711
3712 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003713 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003714 public void applyPostLayoutPolicyLw(WindowState win, WindowManager.LayoutParams attrs) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07003715 if (DEBUG_LAYOUT) Slog.i(TAG, "Win " + win + ": isVisibleOrBehindKeyguardLw="
3716 + win.isVisibleOrBehindKeyguardLw());
John Spurlockc6d1c602014-01-17 15:22:06 -05003717 final int fl = PolicyControl.getWindowFlags(win, attrs);
John Spurlock414c1f02013-12-04 13:47:36 -05003718 if (mTopFullscreenOpaqueWindowState == null
3719 && win.isVisibleLw() && attrs.type == TYPE_INPUT_METHOD) {
3720 mForcingShowNavBar = true;
3721 mForcingShowNavBarLayer = win.getSurfaceLayer();
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08003722 }
Jorim Jaggiafd4a552014-04-08 15:13:05 +02003723 if (attrs.type == TYPE_STATUS_BAR && (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Jorim Jaggiafd4a552014-04-08 15:13:05 +02003724 mForceStatusBarFromKeyguard = true;
3725 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003726 if (mTopFullscreenOpaqueWindowState == null &&
Dianne Hackborn01b02a72012-01-12 14:05:03 -08003727 win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()) {
John Spurlockc6d1c602014-01-17 15:22:06 -05003728 if ((fl & FLAG_FORCE_NOT_FULLSCREEN) != 0) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003729 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003730 mForceStatusBarFromKeyguard = true;
3731 } else {
3732 mForceStatusBar = true;
3733 }
3734 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003735 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003736 mShowingLockscreen = true;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07003737 }
Craig Mautnerab55e522014-03-03 13:26:03 -08003738 boolean appWindow = attrs.type >= FIRST_APPLICATION_WINDOW
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003739 && attrs.type <= LAST_APPLICATION_WINDOW;
3740 if (attrs.type == TYPE_DREAM) {
Jeff Brownc8018eb2012-10-29 21:33:27 -07003741 // If the lockscreen was showing when the dream started then wait
3742 // for the dream to draw before hiding the lockscreen.
3743 if (!mDreamingLockscreen
3744 || (win.isVisibleLw() && win.hasDrawnLw())) {
3745 mShowingDream = true;
Craig Mautnerab55e522014-03-03 13:26:03 -08003746 appWindow = true;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003747 }
3748 }
Craig Mautnerab55e522014-03-03 13:26:03 -08003749
Craig Mautner00156ec2014-03-06 22:29:02 -08003750 final boolean showWhenLocked = (fl & FLAG_SHOW_WHEN_LOCKED) != 0;
Craig Mautner74ee9382014-04-01 15:20:16 -07003751 final boolean dismissKeyguard = (fl & FLAG_DISMISS_KEYGUARD) != 0;
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003752 final boolean secureKeyguard = isKeyguardSecure();
Craig Mautnerab55e522014-03-03 13:26:03 -08003753 if (appWindow) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003754 if (showWhenLocked || (dismissKeyguard && !secureKeyguard)) {
3755 // Remove any previous windows with the same appToken.
Craig Mautner2bc789b2014-03-19 19:48:38 -07003756 mAppsToBeHidden.remove(win.getAppToken());
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003757 if (mAppsToBeHidden.isEmpty() && showWhenLocked &&
3758 isKeyguardSecureIncludingHidden()) {
3759 mWinShowWhenLocked = win;
3760 mHideLockScreen = true;
3761 mForceStatusBarFromKeyguard = false;
3762 }
Craig Mautner2bc789b2014-03-19 19:48:38 -07003763 } else {
3764 mAppsToBeHidden.add(win.getAppToken());
3765 }
Craig Mautnerab55e522014-03-03 13:26:03 -08003766 if (attrs.x == 0 && attrs.y == 0
3767 && attrs.width == WindowManager.LayoutParams.MATCH_PARENT
3768 && attrs.height == WindowManager.LayoutParams.MATCH_PARENT) {
3769 if (DEBUG_LAYOUT) Slog.v(TAG, "Fullscreen window: " + win);
3770 mTopFullscreenOpaqueWindowState = win;
Craig Mautner2bc789b2014-03-19 19:48:38 -07003771 if (mAppsToBeHidden.isEmpty()) {
Craig Mautnerda09ae32014-03-03 13:26:03 -08003772 if (showWhenLocked) {
3773 if (DEBUG_LAYOUT) Slog.v(TAG,
3774 "Setting mHideLockScreen to true by win " + win);
3775 mHideLockScreen = true;
3776 mForceStatusBarFromKeyguard = false;
3777 }
Craig Mautner4bdab6b2014-04-01 12:05:11 -07003778 if (dismissKeyguard && mDismissKeyguard == DISMISS_KEYGUARD_NONE) {
Craig Mautnerda09ae32014-03-03 13:26:03 -08003779 if (DEBUG_LAYOUT) Slog.v(TAG,
3780 "Setting mDismissKeyguard true by win " + win);
3781 mDismissKeyguard = mWinDismissingKeyguard == win ?
3782 DISMISS_KEYGUARD_CONTINUE : DISMISS_KEYGUARD_START;
3783 mWinDismissingKeyguard = win;
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003784 mForceStatusBarFromKeyguard = mShowingLockscreen && secureKeyguard;
Craig Mautnerda09ae32014-03-03 13:26:03 -08003785 }
Craig Mautnerab55e522014-03-03 13:26:03 -08003786 }
Craig Mautner00156ec2014-03-06 22:29:02 -08003787 if ((fl & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) {
Craig Mautnerab55e522014-03-03 13:26:03 -08003788 mAllowLockscreenWhenOn = true;
3789 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003790 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003791
3792 if (mWinShowWhenLocked != null &&
3793 mWinShowWhenLocked.getAppToken() != win.getAppToken()) {
3794 win.hideLw(false);
3795 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003796 }
3797 }
3798 }
3799
3800 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003801 @Override
Craig Mautner39834192012-09-02 07:47:24 -07003802 public int finishPostLayoutPolicyLw() {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003803 if (mWinShowWhenLocked != null &&
3804 mWinShowWhenLocked != mTopFullscreenOpaqueWindowState) {
3805 // A dialog is dismissing the keyguard. Put the wallpaper behind it and hide the
3806 // fullscreen window.
3807 // TODO: Make sure FLAG_SHOW_WALLPAPER is restored when dialog is dismissed. Or not.
3808 mWinShowWhenLocked.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
3809 mTopFullscreenOpaqueWindowState.hideLw(false);
3810 mTopFullscreenOpaqueWindowState = mWinShowWhenLocked;
3811 }
3812
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003813 int changes = 0;
Joe Onorato93056472010-09-10 10:30:46 -04003814 boolean topIsFullscreen = false;
Daniel Sandlere02d8082010-10-08 15:13:22 -04003815
3816 final WindowManager.LayoutParams lp = (mTopFullscreenOpaqueWindowState != null)
3817 ? mTopFullscreenOpaqueWindowState.getAttrs()
3818 : null;
3819
Jeff Brownc8018eb2012-10-29 21:33:27 -07003820 // If we are not currently showing a dream then remember the current
3821 // lockscreen state. We will use this to determine whether the dream
3822 // started while the lockscreen was showing and remember this state
3823 // while the dream is showing.
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003824 if (!mShowingDream) {
3825 mDreamingLockscreen = mShowingLockscreen;
3826 }
3827
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003828 if (mStatusBar != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07003829 if (DEBUG_LAYOUT) Slog.i(TAG, "force=" + mForceStatusBar
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003830 + " forcefkg=" + mForceStatusBarFromKeyguard
Dianne Hackbornd70bc2f2009-10-06 23:25:51 -07003831 + " top=" + mTopFullscreenOpaqueWindowState);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003832 if (mForceStatusBar || mForceStatusBarFromKeyguard) {
Craig Mautnereda67292013-04-28 13:50:14 -07003833 if (DEBUG_LAYOUT) Slog.v(TAG, "Showing status bar: forced");
John Spurlock27735a42013-08-14 17:57:38 -04003834 if (mStatusBarController.setBarShowingLw(true)) {
3835 changes |= FINISH_LAYOUT_REDO_LAYOUT;
3836 }
Craig Mautner81defc72013-10-29 11:10:42 -07003837 // Maintain fullscreen layout until incoming animation is complete.
3838 topIsFullscreen = mTopIsFullscreen && mStatusBar.isAnimatingLw();
John Spurlockf92b6162013-11-11 15:01:16 -05003839 // Transient status bar on the lockscreen is not allowed
3840 if (mForceStatusBarFromKeyguard && mStatusBarController.isTransientShowing()) {
3841 mStatusBarController.updateVisibilityLw(false /*transientAllowed*/,
3842 mLastSystemUiFlags, mLastSystemUiFlags);
3843 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003844 } else if (mTopFullscreenOpaqueWindowState != null) {
John Spurlockc6d1c602014-01-17 15:22:06 -05003845 final int fl = PolicyControl.getWindowFlags(null, lp);
Joe Onorato93056472010-09-10 10:30:46 -04003846 if (localLOGV) {
Craig Mautnereda67292013-04-28 13:50:14 -07003847 Slog.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw()
Joe Onorato93056472010-09-10 10:30:46 -04003848 + " shown frame: " + mTopFullscreenOpaqueWindowState.getShownFrameLw());
Craig Mautnereda67292013-04-28 13:50:14 -07003849 Slog.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs()
John Spurlockc6d1c602014-01-17 15:22:06 -05003850 + " lp.flags=0x" + Integer.toHexString(fl));
Joe Onorato93056472010-09-10 10:30:46 -04003851 }
John Spurlockc6d1c602014-01-17 15:22:06 -05003852 topIsFullscreen = (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003853 || (mLastSystemUiFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
Joe Onorato93056472010-09-10 10:30:46 -04003854 // The subtle difference between the window for mTopFullscreenOpaqueWindowState
3855 // and mTopIsFullscreen is that that mTopIsFullscreen is set only if the window
3856 // has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the
3857 // case though.
John Spurlock27735a42013-08-14 17:57:38 -04003858 if (mStatusBarController.isTransientShowing()) {
3859 if (mStatusBarController.setBarShowingLw(true)) {
John Spurlock32beb2c2013-03-11 10:16:47 -04003860 changes |= FINISH_LAYOUT_REDO_LAYOUT;
3861 }
3862 } else if (topIsFullscreen) {
Craig Mautnereda67292013-04-28 13:50:14 -07003863 if (DEBUG_LAYOUT) Slog.v(TAG, "** HIDING status bar");
John Spurlock27735a42013-08-14 17:57:38 -04003864 if (mStatusBarController.setBarShowingLw(false)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003865 changes |= FINISH_LAYOUT_REDO_LAYOUT;
Craig Mautnereda67292013-04-28 13:50:14 -07003866 } else {
Craig Mautnerc5a6e442013-06-05 17:22:35 -07003867 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar already hiding");
Daniel Sandler40427442010-07-16 11:44:52 -04003868 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003869 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07003870 if (DEBUG_LAYOUT) Slog.v(TAG, "** SHOWING status bar: top is not fullscreen");
John Spurlock27735a42013-08-14 17:57:38 -04003871 if (mStatusBarController.setBarShowingLw(true)) {
3872 changes |= FINISH_LAYOUT_REDO_LAYOUT;
3873 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003874 }
3875 }
3876 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04003877
Craig Mautner81defc72013-10-29 11:10:42 -07003878 if (mTopIsFullscreen != topIsFullscreen) {
3879 if (!topIsFullscreen) {
3880 // Force another layout when status bar becomes fully shown.
3881 changes |= FINISH_LAYOUT_REDO_LAYOUT;
3882 }
3883 mTopIsFullscreen = topIsFullscreen;
3884 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04003885
Craig Mautner39834192012-09-02 07:47:24 -07003886 // Hide the key guard if a visible window explicitly specifies that it wants to be
3887 // displayed when the screen is locked.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01003888 if (mKeyguardDelegate != null && mStatusBar != null) {
3889 if (localLOGV) Slog.v(TAG, "finishPostLayoutPolicyLw: mHideKeyguard="
3890 + mHideLockScreen);
3891 if (mDismissKeyguard != DISMISS_KEYGUARD_NONE && !isKeyguardSecure()) {
3892 mKeyguardHidden = true;
3893 if (processKeyguardSetHiddenResultLw(mKeyguardDelegate.setOccluded(true))) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003894 changes |= FINISH_LAYOUT_REDO_LAYOUT
3895 | FINISH_LAYOUT_REDO_CONFIG
3896 | FINISH_LAYOUT_REDO_WALLPAPER;
3897 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01003898 if (mKeyguardDelegate.isShowing()) {
3899 mHandler.post(new Runnable() {
3900 @Override
3901 public void run() {
3902 mKeyguardDelegate.keyguardDone(false, false);
3903 }
3904 });
3905 }
3906 } else if (mHideLockScreen) {
3907 mKeyguardHidden = true;
3908 if (processKeyguardSetHiddenResultLw(mKeyguardDelegate.setOccluded(true))) {
3909 changes |= FINISH_LAYOUT_REDO_LAYOUT
3910 | FINISH_LAYOUT_REDO_CONFIG
3911 | FINISH_LAYOUT_REDO_WALLPAPER;
3912 }
3913 } else if (mDismissKeyguard != DISMISS_KEYGUARD_NONE) {
3914 // This is the case of keyguard isSecure() and not mHideLockScreen.
3915 if (mDismissKeyguard == DISMISS_KEYGUARD_START) {
3916 // Only launch the next keyguard unlock window once per window.
3917 mKeyguardHidden = false;
3918 if (processKeyguardSetHiddenResultLw(mKeyguardDelegate.setOccluded(false))) {
3919 changes |= FINISH_LAYOUT_REDO_LAYOUT
3920 | FINISH_LAYOUT_REDO_CONFIG
3921 | FINISH_LAYOUT_REDO_WALLPAPER;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003922 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01003923 mHandler.post(new Runnable() {
3924 @Override
3925 public void run() {
3926 mKeyguardDelegate.dismiss();
3927 }
3928 });
3929 }
3930 } else {
3931 mWinDismissingKeyguard = null;
3932 mKeyguardHidden = false;
3933 if (processKeyguardSetHiddenResultLw(mKeyguardDelegate.setOccluded(false))) {
3934 changes |= FINISH_LAYOUT_REDO_LAYOUT
3935 | FINISH_LAYOUT_REDO_CONFIG
3936 | FINISH_LAYOUT_REDO_WALLPAPER;
3937 }
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -07003938 }
3939 }
Joe Onorato664644d2011-01-23 17:53:23 -08003940
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003941 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003942 // If the navigation bar has been hidden or shown, we need to do another
3943 // layout pass to update that window.
3944 changes |= FINISH_LAYOUT_REDO_LAYOUT;
3945 }
Joe Onorato664644d2011-01-23 17:53:23 -08003946
Mike Lockwood28569302010-01-28 11:54:40 -05003947 // update since mAllowLockscreenWhenOn might have changed
3948 updateLockScreenTimeout();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003949 return changes;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003950 }
3951
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003952 /**
Jorim Jaggi5cf17872014-03-26 18:31:48 +01003953 * Processes the result code of {@link IKeyguardService#setOccluded}. This is needed because we
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003954 * immediately need to put the wallpaper directly behind the Keyguard when a window with flag
3955 * {@link android.view.WindowManager.LayoutParams#FLAG_SHOW_WHEN_LOCKED} gets dismissed. If we
3956 * would wait for Keyguard to change the flags, that would be running asynchronously and thus be
3957 * too late so the user might see the window behind.
3958 *
Jorim Jaggi5cf17872014-03-26 18:31:48 +01003959 * @param setHiddenResult The result code from {@link IKeyguardService#setOccluded}.
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003960 * @return Whether the flags have changed and we have to redo the layout.
3961 */
3962 private boolean processKeyguardSetHiddenResultLw(int setHiddenResult) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01003963 if (setHiddenResult
3964 == IKeyguardServiceConstants.KEYGUARD_SERVICE_SET_OCCLUDED_RESULT_SET_FLAGS) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003965 mStatusBar.getAttrs().privateFlags |= PRIVATE_FLAG_KEYGUARD;
3966 mStatusBar.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
3967 return true;
3968 } else if (setHiddenResult
Jorim Jaggi5cf17872014-03-26 18:31:48 +01003969 == IKeyguardServiceConstants.KEYGUARD_SERVICE_SET_OCCLUDED_RESULT_UNSET_FLAGS) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003970 mStatusBar.getAttrs().privateFlags &= ~PRIVATE_FLAG_KEYGUARD;
3971 mStatusBar.getAttrs().flags &= ~FLAG_SHOW_WALLPAPER;
3972 return true;
3973 } else {
3974 return false;
3975 }
3976 }
3977
3978 private boolean isStatusBarKeyguard() {
3979 return mStatusBar != null
3980 && (mStatusBar.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
3981 }
3982
Jose Lima9546b202014-07-02 17:21:51 -07003983 @Override
Dianne Hackborn08743722009-12-21 12:16:51 -08003984 public boolean allowAppAnimationsLw() {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003985 if (isStatusBarKeyguard() || mShowingDream) {
Craig Mautner28816302013-10-10 20:31:00 -07003986 // If keyguard or dreams is currently visible, no reason to animate behind it.
Dianne Hackborn08743722009-12-21 12:16:51 -08003987 return false;
3988 }
Dianne Hackborn08743722009-12-21 12:16:51 -08003989 return true;
3990 }
3991
Jose Lima9546b202014-07-02 17:21:51 -07003992 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07003993 public int focusChangedLw(WindowState lastFocus, WindowState newFocus) {
Joe Onorato664644d2011-01-23 17:53:23 -08003994 mFocusedWindow = newFocus;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003995 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003996 // If the navigation bar has been hidden or shown, we need to do another
3997 // layout pass to update that window.
3998 return FINISH_LAYOUT_REDO_LAYOUT;
3999 }
4000 return 0;
Joe Onorato664644d2011-01-23 17:53:23 -08004001 }
4002
Dianne Hackborn0ecadf72009-03-31 18:00:37 -07004003 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07004004 @Override
Jeff Brown46b9ac02010-04-22 18:58:52 -07004005 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
4006 // lid changed state
Jeff Brownc458ce92012-04-30 14:58:40 -07004007 final int newLidState = lidOpen ? LID_OPEN : LID_CLOSED;
4008 if (newLidState == mLidState) {
4009 return;
4010 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004011
Jeff Brownc458ce92012-04-30 14:58:40 -07004012 mLidState = newLidState;
4013 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07004014 updateRotation(true);
Jeff Brownc458ce92012-04-30 14:58:40 -07004015
4016 if (lidOpen) {
Jim Millere51cf7ae2013-06-25 18:31:56 -07004017 mPowerManager.wakeUp(SystemClock.uptimeMillis());
Jeff Brownc458ce92012-04-30 14:58:40 -07004018 } else if (!mLidControlsSleep) {
Jeff Brown96307042012-07-27 15:51:34 -07004019 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
Jeff Brown46b9ac02010-04-22 18:58:52 -07004020 }
4021 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004022
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004023 void setHdmiPlugged(boolean plugged) {
4024 if (mHdmiPlugged != plugged) {
4025 mHdmiPlugged = plugged;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004026 updateRotation(true, true);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004027 Intent intent = new Intent(ACTION_HDMI_PLUGGED);
Joe Onoratodc100302011-01-11 17:07:41 -08004028 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004029 intent.putExtra(EXTRA_HDMI_PLUGGED_STATE, plugged);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07004030 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004031 }
4032 }
4033
Joe Onoratoea495d42011-04-06 11:41:11 -07004034 void initializeHdmiState() {
Joe Onorato7ba631f2011-05-04 15:28:00 -07004035 boolean plugged = false;
Joe Onoratoea495d42011-04-06 11:41:11 -07004036 // watch for HDMI plug messages if the hdmi switch exists
4037 if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) {
4038 mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi");
4039
Joe Onoratoea495d42011-04-06 11:41:11 -07004040 final String filename = "/sys/class/switch/hdmi/state";
4041 FileReader reader = null;
4042 try {
4043 reader = new FileReader(filename);
4044 char[] buf = new char[15];
4045 int n = reader.read(buf);
4046 if (n > 1) {
4047 plugged = 0 != Integer.parseInt(new String(buf, 0, n-1));
4048 }
4049 } catch (IOException ex) {
4050 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
4051 } catch (NumberFormatException ex) {
4052 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
4053 } finally {
4054 if (reader != null) {
4055 try {
4056 reader.close();
4057 } catch (IOException ex) {
4058 }
Joe Onoratodc100302011-01-11 17:07:41 -08004059 }
4060 }
4061 }
Joe Onorato7ba631f2011-05-04 15:28:00 -07004062 // This dance forces the code in setHdmiPlugged to run.
4063 // Always do this so the sticky intent is stuck (to false) if there is no hdmi.
4064 mHdmiPlugged = !plugged;
4065 setHdmiPlugged(!mHdmiPlugged);
Joe Onoratodc100302011-01-11 17:07:41 -08004066 }
4067
Dianne Hackbornc0e3f242011-08-19 14:19:10 -07004068 final Object mScreenshotLock = new Object();
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004069 ServiceConnection mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004070
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004071 final Runnable mScreenshotTimeout = new Runnable() {
4072 @Override public void run() {
4073 synchronized (mScreenshotLock) {
4074 if (mScreenshotConnection != null) {
4075 mContext.unbindService(mScreenshotConnection);
4076 mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004077 }
Winson Chung9112ec32011-06-27 13:15:32 -07004078 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004079 }
4080 };
4081
4082 // Assume this is called from the Handler thread.
4083 private void takeScreenshot() {
4084 synchronized (mScreenshotLock) {
4085 if (mScreenshotConnection != null) {
4086 return;
4087 }
4088 ComponentName cn = new ComponentName("com.android.systemui",
4089 "com.android.systemui.screenshot.TakeScreenshotService");
4090 Intent intent = new Intent();
4091 intent.setComponent(cn);
4092 ServiceConnection conn = new ServiceConnection() {
4093 @Override
4094 public void onServiceConnected(ComponentName name, IBinder service) {
4095 synchronized (mScreenshotLock) {
4096 if (mScreenshotConnection != this) {
4097 return;
4098 }
4099 Messenger messenger = new Messenger(service);
4100 Message msg = Message.obtain(null, 1);
4101 final ServiceConnection myConn = this;
4102 Handler h = new Handler(mHandler.getLooper()) {
4103 @Override
4104 public void handleMessage(Message msg) {
4105 synchronized (mScreenshotLock) {
4106 if (mScreenshotConnection == myConn) {
4107 mContext.unbindService(mScreenshotConnection);
4108 mScreenshotConnection = null;
4109 mHandler.removeCallbacks(mScreenshotTimeout);
4110 }
4111 }
4112 }
4113 };
4114 msg.replyTo = new Messenger(h);
Winson Chunga63bb842011-10-17 10:26:28 -07004115 msg.arg1 = msg.arg2 = 0;
4116 if (mStatusBar != null && mStatusBar.isVisibleLw())
4117 msg.arg1 = 1;
4118 if (mNavigationBar != null && mNavigationBar.isVisibleLw())
4119 msg.arg2 = 1;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004120 try {
4121 messenger.send(msg);
4122 } catch (RemoteException e) {
4123 }
4124 }
4125 }
4126 @Override
4127 public void onServiceDisconnected(ComponentName name) {}
4128 };
Amith Yamasani27b89e62013-01-16 12:30:11 -08004129 if (mContext.bindServiceAsUser(
4130 intent, conn, Context.BIND_AUTO_CREATE, UserHandle.CURRENT)) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004131 mScreenshotConnection = conn;
4132 mHandler.postDelayed(mScreenshotTimeout, 10000);
4133 }
4134 }
Winson Chung9112ec32011-06-27 13:15:32 -07004135 }
4136
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004137 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004138 @Override
Jeff Brown037c33e2014-04-09 00:31:55 -07004139 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) {
Jeff Brown96307042012-07-27 15:51:34 -07004140 if (!mSystemBooted) {
4141 // If we have not yet booted, don't let key events do anything.
4142 return 0;
4143 }
4144
Jeff Brown037c33e2014-04-09 00:31:55 -07004145 final boolean interactive = (policyFlags & FLAG_INTERACTIVE) != 0;
Jeff Brown1f245102010-11-18 20:53:46 -08004146 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
4147 final boolean canceled = event.isCanceled();
4148 final int keyCode = event.getKeyCode();
Jeff Browne20c9e02010-10-11 14:20:19 -07004149
Jeff Brown3122e442010-10-11 23:32:49 -07004150 final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0;
Jeff Brown3122e442010-10-11 23:32:49 -07004151
Mike Lockwoodc72b15f2009-11-28 20:58:22 -05004152 // If screen is off then we treat the case where the keyguard is open but hidden
4153 // the same as if it were open and in front.
4154 // This will prevent any keys other than the power button from waking the screen
4155 // when the keyguard is hidden by another activity.
Jim Miller5ecd8112013-01-09 18:50:26 -08004156 final boolean keyguardActive = (mKeyguardDelegate == null ? false :
Jeff Brown037c33e2014-04-09 00:31:55 -07004157 (interactive ?
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004158 mKeyguardDelegate.isShowingAndNotOccluded() :
Jim Miller5ecd8112013-01-09 18:50:26 -08004159 mKeyguardDelegate.isShowing()));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004160
Jeff Brown40013652012-05-16 21:22:36 -07004161 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004162 Log.d(TAG, "interceptKeyTq keycode=" + keyCode
Jeff Brown037c33e2014-04-09 00:31:55 -07004163 + " interactive=" + interactive + " keyguardActive=" + keyguardActive
Jeff Brown26875502014-01-30 21:47:47 -08004164 + " policyFlags=" + Integer.toHexString(policyFlags));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004165 }
4166
Jeff Brown037c33e2014-04-09 00:31:55 -07004167 // Basic policy based on interactive state.
Jeff Brown4d396052010-10-29 21:50:21 -07004168 int result;
Michael Wright337d9d22014-04-22 15:03:48 -07004169 boolean isWakeKey = (policyFlags & WindowManagerPolicy.FLAG_WAKE) != 0
4170 || event.isWakeKey();
Jeff Brown037c33e2014-04-09 00:31:55 -07004171 if (interactive || (isInjected && !isWakeKey)) {
Jeff Brown4d396052010-10-29 21:50:21 -07004172 // When the screen is on or if the key is injected pass the key to the application.
4173 result = ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07004174 isWakeKey = false;
Jeff Brown4d396052010-10-29 21:50:21 -07004175 } else {
4176 // When the screen is off and the key is not injected, determine whether
4177 // to wake the device but don't pass the key to the application.
4178 result = 0;
Jeff Brown26875502014-01-30 21:47:47 -08004179 if (isWakeKey && (!down || !isWakeKeyWhenScreenOff(keyCode))) {
4180 isWakeKey = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004181 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004182 }
4183
Justin Kohd378ad72013-04-01 12:18:26 -07004184 // If the key would be handled globally, just return the result, don't worry about special
4185 // key processing.
4186 if (mGlobalKeyManager.shouldHandleGlobalKey(keyCode, event)) {
Michael Wright85b1af62014-06-04 14:51:58 -07004187 if (isWakeKey) {
4188 mPowerManager.wakeUp(event.getEventTime());
4189 }
Justin Kohd378ad72013-04-01 12:18:26 -07004190 return result;
4191 }
4192
Jeff Brownbae8e772014-06-12 19:59:45 -07004193 boolean useHapticFeedback = down
4194 && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0
4195 && event.getRepeatCount() == 0;
4196
Jeff Brown4d396052010-10-29 21:50:21 -07004197 // Handle special keys.
4198 switch (keyCode) {
4199 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jeff Brownb0418da2010-11-01 15:24:01 -07004200 case KeyEvent.KEYCODE_VOLUME_UP:
4201 case KeyEvent.KEYCODE_VOLUME_MUTE: {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004202 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
4203 if (down) {
Jeff Brown037c33e2014-04-09 00:31:55 -07004204 if (interactive && !mVolumeDownKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004205 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
4206 mVolumeDownKeyTriggered = true;
4207 mVolumeDownKeyTime = event.getDownTime();
4208 mVolumeDownKeyConsumedByScreenshotChord = false;
4209 cancelPendingPowerKeyAction();
4210 interceptScreenshotChord();
4211 }
4212 } else {
4213 mVolumeDownKeyTriggered = false;
4214 cancelPendingScreenshotChordAction();
4215 }
4216 } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
4217 if (down) {
Jeff Brown037c33e2014-04-09 00:31:55 -07004218 if (interactive && !mVolumeUpKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004219 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
4220 mVolumeUpKeyTriggered = true;
4221 cancelPendingPowerKeyAction();
4222 cancelPendingScreenshotChordAction();
4223 }
4224 } else {
4225 mVolumeUpKeyTriggered = false;
4226 cancelPendingScreenshotChordAction();
4227 }
4228 }
Jeff Brown4d396052010-10-29 21:50:21 -07004229 if (down) {
Santos Cordon9eb45932014-06-27 12:28:43 -07004230 TelecommManager telecommManager = getTelecommService();
4231 if (telecommManager != null) {
4232 if (telecommManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07004233 // If an incoming call is ringing, either VOLUME key means
4234 // "silence ringer". We handle these keys here, rather than
4235 // in the InCallScreen, to make sure we'll respond to them
4236 // even if the InCallScreen hasn't come to the foreground yet.
4237 // Look for the DOWN event here, to agree with the "fallback"
4238 // behavior in the InCallScreen.
4239 Log.i(TAG, "interceptKeyBeforeQueueing:"
4240 + " VOLUME key-down while ringing: Silence ringer!");
Jeff Brown4d396052010-10-29 21:50:21 -07004241
Santos Cordon6848f722014-05-21 15:22:12 -07004242 // Silence the ringer. (It's safe to call this
4243 // even if the ringer has already been silenced.)
Santos Cordon9eb45932014-06-27 12:28:43 -07004244 telecommManager.silenceRinger();
Jeff Brown4d396052010-10-29 21:50:21 -07004245
Santos Cordon6848f722014-05-21 15:22:12 -07004246 // And *don't* pass this key thru to the current activity
4247 // (which is probably the InCallScreen.)
4248 result &= ~ACTION_PASS_TO_USER;
4249 break;
4250 }
Santos Cordon9eb45932014-06-27 12:28:43 -07004251 if (telecommManager.isInAPhoneCall()
Santos Cordon6848f722014-05-21 15:22:12 -07004252 && (result & ACTION_PASS_TO_USER) == 0) {
4253 // If we are in call but we decided not to pass the key to
RoboErik430fc482014-06-12 15:49:20 -07004254 // the application, just pass it to the session service.
4255
4256 MediaSessionLegacyHelper.getHelper(mContext)
RoboErik3c45c292014-07-08 16:47:31 -07004257 .sendVolumeKeyEvent(event, false);
Santos Cordon6848f722014-05-21 15:22:12 -07004258 break;
Jeff Brown4d396052010-10-29 21:50:21 -07004259 }
4260 }
4261
RoboErik430fc482014-06-12 15:49:20 -07004262 if ((result & ACTION_PASS_TO_USER) == 0) {
4263 // If we aren't passing to the user and no one else
4264 // handled it send it to the session manager to figure
4265 // out.
4266 MediaSessionLegacyHelper.getHelper(mContext)
RoboErik3c45c292014-07-08 16:47:31 -07004267 .sendVolumeKeyEvent(event, true);
Jeff Brown4d396052010-10-29 21:50:21 -07004268 break;
4269 }
4270 }
4271 break;
4272 }
4273
4274 case KeyEvent.KEYCODE_ENDCALL: {
4275 result &= ~ACTION_PASS_TO_USER;
4276 if (down) {
Santos Cordon9eb45932014-06-27 12:28:43 -07004277 TelecommManager telecommManager = getTelecommService();
Jeff Brown4d396052010-10-29 21:50:21 -07004278 boolean hungUp = false;
Santos Cordon9eb45932014-06-27 12:28:43 -07004279 if (telecommManager != null) {
4280 hungUp = telecommManager.endCall();
Jeff Brown4d396052010-10-29 21:50:21 -07004281 }
Jeff Brown037c33e2014-04-09 00:31:55 -07004282 interceptPowerKeyDown(!interactive || hungUp);
Jeff Brown4d396052010-10-29 21:50:21 -07004283 } else {
4284 if (interceptPowerKeyUp(canceled)) {
4285 if ((mEndcallBehavior
4286 & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) {
4287 if (goHome()) {
4288 break;
Dianne Hackborn0041e972009-07-24 17:14:43 -07004289 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004290 }
Jeff Brown4d396052010-10-29 21:50:21 -07004291 if ((mEndcallBehavior
4292 & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) {
Jeff Brown26875502014-01-30 21:47:47 -08004293 mPowerManager.goToSleep(event.getEventTime());
4294 isWakeKey = false;
Jeff Brown4d396052010-10-29 21:50:21 -07004295 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004296 }
Jeff Brown4d396052010-10-29 21:50:21 -07004297 }
4298 break;
4299 }
4300
4301 case KeyEvent.KEYCODE_POWER: {
4302 result &= ~ACTION_PASS_TO_USER;
4303 if (down) {
Jeff Brown26c6a502014-04-11 02:15:54 -07004304 boolean panic = mImmersiveModeConfirmation.onPowerKeyDown(interactive,
John Spurlockd9b70bd2014-02-06 17:02:44 -05004305 event.getDownTime(), isImmersiveMode(mLastSystemUiFlags));
4306 if (panic) {
4307 mHandler.post(mRequestTransientNav);
4308 }
Jeff Brown037c33e2014-04-09 00:31:55 -07004309 if (interactive && !mPowerKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004310 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
4311 mPowerKeyTriggered = true;
4312 mPowerKeyTime = event.getDownTime();
4313 interceptScreenshotChord();
Winson Chung9112ec32011-06-27 13:15:32 -07004314 }
Winson Chung9112ec32011-06-27 13:15:32 -07004315
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 if (telecommManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07004320 // Pressing Power while there's a ringing incoming
4321 // call should silence the ringer.
Santos Cordon9eb45932014-06-27 12:28:43 -07004322 telecommManager.silenceRinger();
Santos Cordon6848f722014-05-21 15:22:12 -07004323 } else if ((mIncallPowerBehavior
4324 & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0
Santos Cordon9eb45932014-06-27 12:28:43 -07004325 && telecommManager.isInAPhoneCall() && interactive) {
Santos Cordon6848f722014-05-21 15:22:12 -07004326 // Otherwise, if "Power button ends call" is enabled,
4327 // the Power button will hang up any current active call.
Santos Cordon9eb45932014-06-27 12:28:43 -07004328 hungUp = telecommManager.endCall();
Jeff Brown4d396052010-10-29 21:50:21 -07004329 }
4330 }
Jeff Brown037c33e2014-04-09 00:31:55 -07004331 interceptPowerKeyDown(!interactive || hungUp
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004332 || mVolumeDownKeyTriggered || mVolumeUpKeyTriggered);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004333 } else {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004334 mPowerKeyTriggered = false;
4335 cancelPendingScreenshotChordAction();
4336 if (interceptPowerKeyUp(canceled || mPendingPowerKeyUpCanceled)) {
Jeff Brown6d8fd272014-05-20 21:24:38 -07004337 powerShortPress(event.getEventTime());
Jeff Brown26875502014-01-30 21:47:47 -08004338 isWakeKey = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004339 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004340 mPendingPowerKeyUpCanceled = false;
Jeff Brown4d396052010-10-29 21:50:21 -07004341 }
4342 break;
4343 }
4344
Jeff Brown6212a492014-03-07 13:58:47 -08004345 case KeyEvent.KEYCODE_SLEEP: {
4346 result &= ~ACTION_PASS_TO_USER;
Jeff Brownbae8e772014-06-12 19:59:45 -07004347 if (!mPowerManager.isInteractive()) {
4348 useHapticFeedback = false; // suppress feedback if already non-interactive
4349 }
Jeff Brown6212a492014-03-07 13:58:47 -08004350 mPowerManager.goToSleep(event.getEventTime());
4351 isWakeKey = false;
4352 break;
4353 }
4354
4355 case KeyEvent.KEYCODE_WAKEUP: {
4356 result &= ~ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07004357 isWakeKey = true;
Jeff Brown6212a492014-03-07 13:58:47 -08004358 break;
4359 }
4360
Jeff Brown4d396052010-10-29 21:50:21 -07004361 case KeyEvent.KEYCODE_MEDIA_PLAY:
4362 case KeyEvent.KEYCODE_MEDIA_PAUSE:
4363 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
4364 if (down) {
Santos Cordon9eb45932014-06-27 12:28:43 -07004365 TelecommManager telecommManager = getTelecommService();
4366 if (telecommManager != null) {
4367 if (telecommManager.isInAPhoneCall()) {
Santos Cordon6848f722014-05-21 15:22:12 -07004368 // Suppress PLAY/PAUSE toggle when phone is ringing or in-call
4369 // to avoid music playback.
4370 break;
Jeff Brown3122e442010-10-11 23:32:49 -07004371 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004372 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004373 }
Jeff Brown4d396052010-10-29 21:50:21 -07004374 case KeyEvent.KEYCODE_HEADSETHOOK:
4375 case KeyEvent.KEYCODE_MUTE:
4376 case KeyEvent.KEYCODE_MEDIA_STOP:
4377 case KeyEvent.KEYCODE_MEDIA_NEXT:
4378 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
4379 case KeyEvent.KEYCODE_MEDIA_REWIND:
4380 case KeyEvent.KEYCODE_MEDIA_RECORD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09004381 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
4382 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: {
Jeff Brown4d396052010-10-29 21:50:21 -07004383 if ((result & ACTION_PASS_TO_USER) == 0) {
4384 // Only do this if we would otherwise not pass it to the user. In that
4385 // case, the PhoneWindow class will do the same thing, except it will
4386 // only do it if the showing app doesn't process the key on its own.
Jeff Brown40013652012-05-16 21:22:36 -07004387 // Note that we need to make a copy of the key event here because the
4388 // original key event will be recycled when we return.
Jeff Brown4d396052010-10-29 21:50:21 -07004389 mBroadcastWakeLock.acquire();
Jeff Brown40013652012-05-16 21:22:36 -07004390 Message msg = mHandler.obtainMessage(MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK,
4391 new KeyEvent(event));
4392 msg.setAsynchronous(true);
4393 msg.sendToTarget();
Jeff Brown4d396052010-10-29 21:50:21 -07004394 }
4395 break;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004396 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004397
Jeff Brown4d396052010-10-29 21:50:21 -07004398 case KeyEvent.KEYCODE_CALL: {
4399 if (down) {
Santos Cordon9eb45932014-06-27 12:28:43 -07004400 TelecommManager telecommManager = getTelecommService();
4401 if (telecommManager != null) {
4402 if (telecommManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07004403 Log.i(TAG, "interceptKeyBeforeQueueing:"
4404 + " CALL key-down while ringing: Answer the call!");
Santos Cordon9eb45932014-06-27 12:28:43 -07004405 telecommManager.acceptRingingCall();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004406
Santos Cordon6848f722014-05-21 15:22:12 -07004407 // And *don't* pass this key thru to the current activity
4408 // (which is presumably the InCallScreen.)
4409 result &= ~ACTION_PASS_TO_USER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004410 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004411 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004412 }
Jeff Brown4d396052010-10-29 21:50:21 -07004413 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004414 }
4415 }
Jeff Brown26875502014-01-30 21:47:47 -08004416
Jeff Brownbae8e772014-06-12 19:59:45 -07004417 if (useHapticFeedback) {
4418 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
4419 }
4420
Jeff Brown26875502014-01-30 21:47:47 -08004421 if (isWakeKey) {
4422 mPowerManager.wakeUp(event.getEventTime());
4423 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004424 return result;
4425 }
4426
Jeff Brown1c2e4942012-11-06 16:32:01 -08004427 /**
4428 * When the screen is off we ignore some keys that might otherwise typically
4429 * be considered wake keys. We filter them out here.
4430 *
4431 * {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it
4432 * is always considered a wake key.
4433 */
4434 private boolean isWakeKeyWhenScreenOff(int keyCode) {
4435 switch (keyCode) {
4436 // ignore volume keys unless docked
4437 case KeyEvent.KEYCODE_VOLUME_UP:
4438 case KeyEvent.KEYCODE_VOLUME_DOWN:
4439 case KeyEvent.KEYCODE_VOLUME_MUTE:
4440 return mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED;
4441
4442 // ignore media and camera keys
4443 case KeyEvent.KEYCODE_MUTE:
4444 case KeyEvent.KEYCODE_HEADSETHOOK:
4445 case KeyEvent.KEYCODE_MEDIA_PLAY:
4446 case KeyEvent.KEYCODE_MEDIA_PAUSE:
4447 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
4448 case KeyEvent.KEYCODE_MEDIA_STOP:
4449 case KeyEvent.KEYCODE_MEDIA_NEXT:
4450 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
4451 case KeyEvent.KEYCODE_MEDIA_REWIND:
4452 case KeyEvent.KEYCODE_MEDIA_RECORD:
4453 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09004454 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK:
Jeff Brown1c2e4942012-11-06 16:32:01 -08004455 case KeyEvent.KEYCODE_CAMERA:
4456 return false;
4457 }
4458 return true;
4459 }
4460
4461
Jeff Brown56194eb2011-03-02 19:23:13 -08004462 /** {@inheritDoc} */
4463 @Override
Jeff Brown037c33e2014-04-09 00:31:55 -07004464 public int interceptWakeMotionBeforeQueueing(long whenNanos, int policyFlags) {
4465 // We already know this is a wake motion so just wake up.
4466 // Note that we would observe policyFlags containing
4467 // FLAG_WAKE and FLAG_INTERACTIVE here.
4468 mPowerManager.wakeUp(whenNanos / 1000000);
4469 return 0;
Jeff Brown56194eb2011-03-02 19:23:13 -08004470 }
4471
Jeff Brown40013652012-05-16 21:22:36 -07004472 void dispatchMediaKeyWithWakeLock(KeyEvent event) {
4473 if (DEBUG_INPUT) {
4474 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: " + event);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004475 }
4476
Jeff Brown40013652012-05-16 21:22:36 -07004477 if (mHavePendingMediaKeyRepeatWithWakeLock) {
4478 if (DEBUG_INPUT) {
4479 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: canceled repeat");
4480 }
4481
4482 mHandler.removeMessages(MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK);
4483 mHavePendingMediaKeyRepeatWithWakeLock = false;
4484 mBroadcastWakeLock.release(); // pending repeat was holding onto the wake lock
4485 }
4486
4487 dispatchMediaKeyWithWakeLockToAudioService(event);
4488
4489 if (event.getAction() == KeyEvent.ACTION_DOWN
4490 && event.getRepeatCount() == 0) {
4491 mHavePendingMediaKeyRepeatWithWakeLock = true;
4492
4493 Message msg = mHandler.obtainMessage(
4494 MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK, event);
4495 msg.setAsynchronous(true);
4496 mHandler.sendMessageDelayed(msg, ViewConfiguration.getKeyRepeatTimeout());
4497 } else {
4498 mBroadcastWakeLock.release();
4499 }
4500 }
4501
4502 void dispatchMediaKeyRepeatWithWakeLock(KeyEvent event) {
4503 mHavePendingMediaKeyRepeatWithWakeLock = false;
4504
4505 KeyEvent repeatEvent = KeyEvent.changeTimeRepeat(event,
4506 SystemClock.uptimeMillis(), 1, event.getFlags() | KeyEvent.FLAG_LONG_PRESS);
4507 if (DEBUG_INPUT) {
4508 Slog.d(TAG, "dispatchMediaKeyRepeatWithWakeLock: " + repeatEvent);
4509 }
4510
4511 dispatchMediaKeyWithWakeLockToAudioService(repeatEvent);
4512 mBroadcastWakeLock.release();
4513 }
4514
4515 void dispatchMediaKeyWithWakeLockToAudioService(KeyEvent event) {
4516 if (ActivityManagerNative.isSystemReady()) {
RoboErik430fc482014-06-12 15:49:20 -07004517 MediaSessionLegacyHelper.getHelper(mContext).sendMediaButtonEvent(event, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004518 }
4519 }
4520
Mike Lockwood1753f7f2009-08-24 14:49:07 -07004521 BroadcastReceiver mDockReceiver = new BroadcastReceiver() {
Craig Mautnereee29c42013-01-17 14:44:34 -08004522 @Override
Mike Lockwood1753f7f2009-08-24 14:49:07 -07004523 public void onReceive(Context context, Intent intent) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07004524 if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) {
4525 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
4526 Intent.EXTRA_DOCK_STATE_UNDOCKED);
Daniel Sandler6396c722013-04-16 20:19:09 -04004527 } else {
4528 try {
4529 IUiModeManager uiModeService = IUiModeManager.Stub.asInterface(
4530 ServiceManager.getService(Context.UI_MODE_SERVICE));
4531 mUiMode = uiModeService.getCurrentModeType();
4532 } catch (RemoteException e) {
4533 }
Dianne Hackborn80fa1662009-10-07 14:02:10 -07004534 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004535 updateRotation(true);
Craig Mautnereee29c42013-01-17 14:44:34 -08004536 synchronized (mLock) {
4537 updateOrientationListenerLp();
4538 }
Mike Lockwood1753f7f2009-08-24 14:49:07 -07004539 }
4540 };
4541
Jeff Brown6aaf2952012-10-05 16:01:08 -07004542 BroadcastReceiver mDreamReceiver = new BroadcastReceiver() {
4543 @Override
4544 public void onReceive(Context context, Intent intent) {
4545 if (Intent.ACTION_DREAMING_STARTED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004546 if (mKeyguardDelegate != null) {
4547 mKeyguardDelegate.onDreamingStarted();
Jeff Brown6aaf2952012-10-05 16:01:08 -07004548 }
4549 } else if (Intent.ACTION_DREAMING_STOPPED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004550 if (mKeyguardDelegate != null) {
4551 mKeyguardDelegate.onDreamingStopped();
Jeff Brown6aaf2952012-10-05 16:01:08 -07004552 }
4553 }
4554 }
4555 };
4556
Christopher Tate5e08af02012-09-21 17:17:22 -07004557 BroadcastReceiver mMultiuserReceiver = new BroadcastReceiver() {
4558 @Override
4559 public void onReceive(Context context, Intent intent) {
4560 if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) {
4561 // tickle the settings observer: this first ensures that we're
4562 // observing the relevant settings for the newly-active user,
4563 // and then updates our own bookkeeping based on the now-
4564 // current user.
4565 mSettingsObserver.onChange(false);
John Spurlockce479d82012-11-29 09:52:21 -05004566
4567 // force a re-application of focused window sysui visibility.
4568 // the window may never have been shown for this user
4569 // e.g. the keyguard when going through the new-user setup flow
John Spurlock04db1762013-05-13 12:46:41 -04004570 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
John Spurlockce479d82012-11-29 09:52:21 -05004571 mLastSystemUiFlags = 0;
4572 updateSystemUiVisibilityLw();
4573 }
Christopher Tate5e08af02012-09-21 17:17:22 -07004574 }
4575 }
4576 };
4577
John Spurlockd9b70bd2014-02-06 17:02:44 -05004578 private final Runnable mRequestTransientNav = new Runnable() {
4579 @Override
4580 public void run() {
4581 requestTransientBars(mNavigationBar);
4582 }
4583 };
4584
John Spurlocke1f366f2013-08-05 12:22:40 -04004585 private void requestTransientBars(WindowState swipeTarget) {
John Spurlock04db1762013-05-13 12:46:41 -04004586 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Maurice Lam99c6e072014-04-28 18:24:28 -07004587 if (!isUserSetupComplete()) {
4588 // Swipe-up for navigation bar is disabled during setup
4589 return;
4590 }
John Spurlock27735a42013-08-14 17:57:38 -04004591 boolean sb = mStatusBarController.checkShowTransientBarLw();
4592 boolean nb = mNavigationBarController.checkShowTransientBarLw();
John Spurlockad3e6cb2013-04-30 08:47:43 -04004593 if (sb || nb) {
John Spurlocke1f366f2013-08-05 12:22:40 -04004594 WindowState barTarget = sb ? mStatusBar : mNavigationBar;
4595 if (sb ^ nb && barTarget != swipeTarget) {
4596 if (DEBUG) Slog.d(TAG, "Not showing transient bar, wrong swipe target");
John Spurlockad3e6cb2013-04-30 08:47:43 -04004597 return;
4598 }
John Spurlock27735a42013-08-14 17:57:38 -04004599 if (sb) mStatusBarController.showTransient();
4600 if (nb) mNavigationBarController.showTransient();
John Spurlockf1a36642013-10-12 17:50:42 -04004601 mImmersiveModeConfirmation.confirmCurrentPrompt();
John Spurlockad3e6cb2013-04-30 08:47:43 -04004602 updateSystemUiVisibilityLw();
John Spurlock32beb2c2013-03-11 10:16:47 -04004603 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04004604 }
4605 }
4606
Jeff Brownc38c9be2012-10-04 13:16:19 -07004607 @Override
Jeff Brown140ffc72014-05-01 15:18:00 -07004608 public void goingToSleep(int why) {
Dianne Hackborn74489012009-03-24 20:50:09 -07004609 EventLog.writeEvent(70000, 0);
The Android Open Source Project0727d222009-03-11 12:11:58 -07004610 synchronized (mLock) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004611 mScreenOnEarly = false;
4612 mScreenOnFully = false;
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07004613 }
Jim Miller5ecd8112013-01-09 18:50:26 -08004614 if (mKeyguardDelegate != null) {
4615 mKeyguardDelegate.onScreenTurnedOff(why);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004616 }
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07004617 synchronized (mLock) {
Jeff Browna20dda42014-05-27 20:57:24 -07004618 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07004619 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05004620 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07004621 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004622 }
4623
Jeff Brownc38c9be2012-10-04 13:16:19 -07004624 @Override
Jeff Brown140ffc72014-05-01 15:18:00 -07004625 public void wakingUp(final ScreenOnListener screenOnListener) {
Dianne Hackborn74489012009-03-24 20:50:09 -07004626 EventLog.writeEvent(70000, 1);
Craig Mautner8a0da012014-05-31 15:13:37 -07004627 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turning on...",
4628 new RuntimeException("here").fillInStackTrace());
4629 mHandler.obtainMessage(MSG_WAKING_UP, screenOnListener).sendToTarget();
4630 }
4631
4632 // Called on the mHandler thread.
4633 private void handleWakingUp(final ScreenOnListener screenOnListener) {
4634 if (screenOnListener != null) {
Craig Mautner13f6ea72014-06-23 14:57:02 -07004635 mScreenOnListener = screenOnListener;
Dianne Hackborn40011092011-09-22 13:37:48 -07004636 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07004637
The Android Open Source Project0727d222009-03-11 12:11:58 -07004638 synchronized (mLock) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004639 mScreenOnEarly = true;
Jeff Browna20dda42014-05-27 20:57:24 -07004640 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07004641 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05004642 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07004643 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07004644
Craig Mautner8a0da012014-05-31 15:13:37 -07004645 mKeyguardDrawComplete = false;
4646 mWindowManagerDrawComplete = false;
Jim Miller5ecd8112013-01-09 18:50:26 -08004647 if (mKeyguardDelegate != null) {
Craig Mautner8a0da012014-05-31 15:13:37 -07004648 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
4649 mHandler.sendEmptyMessageDelayed(MSG_KEYGUARD_DRAWN_TIMEOUT, 1000);
4650 mKeyguardDelegate.onScreenTurnedOn(mKeyguardDelegateCallback);
Jeff Brownc38c9be2012-10-04 13:16:19 -07004651 } else {
Craig Mautner8a0da012014-05-31 15:13:37 -07004652 if (DEBUG_WAKEUP) Slog.d(TAG, "null mKeyguardDelegate: setting mKeyguardDrawComplete.");
4653 mKeyguardDrawComplete = true;
Jeff Brownc38c9be2012-10-04 13:16:19 -07004654 }
Craig Mautner8a0da012014-05-31 15:13:37 -07004655 mWindowManagerInternal.waitForAllWindowsDrawn(mWindowManagerDrawCallback, 500);
Jeff Brownc38c9be2012-10-04 13:16:19 -07004656 }
4657
Craig Mautner8a0da012014-05-31 15:13:37 -07004658 // Called on the mHandler thread.
4659 private void finishScreenTurningOn() {
4660 if (DEBUG_WAKEUP) Slog.d(TAG,
4661 "finishScreenTurningOn: mKeyguardDrawComplete=" + mKeyguardDrawComplete
4662 + " mWindowManagerDrawComplete=" + mWindowManagerDrawComplete);
4663 if (!mKeyguardDrawComplete || !mWindowManagerDrawComplete) {
4664 return;
Jeff Brownc38c9be2012-10-04 13:16:19 -07004665 }
4666
Craig Mautner13f6ea72014-06-23 14:57:02 -07004667 ScreenOnListener screenOnListener;
Jeff Brownc38c9be2012-10-04 13:16:19 -07004668 synchronized (mLock) {
4669 mScreenOnFully = true;
Craig Mautner13f6ea72014-06-23 14:57:02 -07004670 screenOnListener = mScreenOnListener;
4671 mScreenOnListener = null;
Jeff Brownc38c9be2012-10-04 13:16:19 -07004672 }
4673
Jeff Brown4fc45272012-10-10 18:28:14 -07004674 try {
4675 mWindowManager.setEventDispatching(true);
4676 } catch (RemoteException unhandled) {
4677 }
4678
Craig Mautner13f6ea72014-06-23 14:57:02 -07004679 if (screenOnListener != null) {
4680 screenOnListener.onScreenOn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07004681 }
Craig Mautner8a0da012014-05-31 15:13:37 -07004682
4683 setKeyguardDrawn();
Craig Mautnera631d492014-08-05 15:16:01 -07004684
4685 if (mBootMessageNeedsHiding) {
4686 handleHideBootMessage();
4687 mBootMessageNeedsHiding = false;
4688 }
4689 }
4690
4691 private void handleHideBootMessage() {
4692 if (mBootMsgDialog == null) {
4693 if (DEBUG_WAKEUP) Slog.d(TAG, "handleHideBootMessage: boot message not up");
4694 return;
4695 }
4696 if (!mKeyguardDrawComplete || !mWindowManagerDrawComplete) {
4697 if (DEBUG_WAKEUP) Slog.d(TAG, "handleHideBootMessage: deferring until keyguard ready");
4698 mBootMessageNeedsHiding = true;
4699 return;
4700 }
4701 if (DEBUG_WAKEUP) Slog.d(TAG, "handleHideBootMessage: dismissing");
4702 mBootMsgDialog.dismiss();
4703 mBootMsgDialog = null;
Jeff Brownc38c9be2012-10-04 13:16:19 -07004704 }
4705
4706 @Override
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004707 public boolean isScreenOnEarly() {
4708 return mScreenOnEarly;
4709 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07004710
4711 @Override
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004712 public boolean isScreenOnFully() {
4713 return mScreenOnFully;
Dianne Hackborn08743722009-12-21 12:16:51 -08004714 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07004715
Dianne Hackborn08743722009-12-21 12:16:51 -08004716 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07004717 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004718 public void enableKeyguard(boolean enabled) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004719 if (mKeyguardDelegate != null) {
4720 mKeyguardDelegate.setKeyguardEnabled(enabled);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004721 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004722 }
4723
4724 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07004725 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004726 public void exitKeyguardSecurely(OnKeyguardExitResult callback) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004727 if (mKeyguardDelegate != null) {
4728 mKeyguardDelegate.verifyUnlock(callback);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004729 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004730 }
4731
Mike Lockwoodf7913302009-11-28 22:27:10 -05004732 private boolean keyguardIsShowingTq() {
Jim Miller5ecd8112013-01-09 18:50:26 -08004733 if (mKeyguardDelegate == null) return false;
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004734 return mKeyguardDelegate.isShowingAndNotOccluded();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004735 }
4736
Mike Lockwood520d8bc2011-02-18 13:23:13 -05004737
4738 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07004739 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05004740 public boolean isKeyguardLocked() {
4741 return keyguardOn();
4742 }
4743
4744 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07004745 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05004746 public boolean isKeyguardSecure() {
Jim Miller5ecd8112013-01-09 18:50:26 -08004747 if (mKeyguardDelegate == null) return false;
4748 return mKeyguardDelegate.isSecure();
Mike Lockwood520d8bc2011-02-18 13:23:13 -05004749 }
4750
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004751 // Returns true if keyguard is currently locked whether or not it is currently hidden.
4752 private boolean isKeyguardSecureIncludingHidden() {
4753 return mKeyguardDelegate.isSecure() && mKeyguardDelegate.isShowing();
4754 }
4755
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004756 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07004757 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004758 public boolean inKeyguardRestrictedKeyInputMode() {
Jim Miller5ecd8112013-01-09 18:50:26 -08004759 if (mKeyguardDelegate == null) return false;
4760 return mKeyguardDelegate.isInputRestricted();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004761 }
4762
Jose Lima9546b202014-07-02 17:21:51 -07004763 @Override
Dianne Hackborn90c52de2011-09-23 12:57:44 -07004764 public void dismissKeyguardLw() {
RoboErik8a2cfc32014-05-16 11:19:38 -07004765 if (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()) {
Daniel Sandler1ce804392012-11-07 15:07:12 -05004766 mHandler.post(new Runnable() {
Jose Lima9546b202014-07-02 17:21:51 -07004767 @Override
Daniel Sandler1ce804392012-11-07 15:07:12 -05004768 public void run() {
Jim Miller5ecd8112013-01-09 18:50:26 -08004769 if (mKeyguardDelegate.isDismissable()) {
Daniel Sandler1ce804392012-11-07 15:07:12 -05004770 // Can we just finish the keyguard straight away?
Jim Miller5ecd8112013-01-09 18:50:26 -08004771 mKeyguardDelegate.keyguardDone(false, true);
Daniel Sandler1ce804392012-11-07 15:07:12 -05004772 } else {
4773 // ask the keyguard to prompt the user to authenticate if necessary
Jim Miller5ecd8112013-01-09 18:50:26 -08004774 mKeyguardDelegate.dismiss();
Dianne Hackborn90c52de2011-09-23 12:57:44 -07004775 }
Daniel Sandler1ce804392012-11-07 15:07:12 -05004776 }
4777 });
Dianne Hackborn90c52de2011-09-23 12:57:44 -07004778 }
4779 }
4780
Jorim Jaggicff0acb2014-03-31 16:35:15 +02004781 private void setKeyguardDrawn() {
4782 synchronized (mLock) {
4783 mKeyguardDrawn = true;
4784 }
4785 try {
4786 mWindowManager.enableScreenIfNeeded();
4787 } catch (RemoteException unhandled) {
4788 }
4789 }
4790
4791 @Override
4792 public boolean isKeyguardDrawnLw() {
4793 synchronized (mLock) {
4794 return mKeyguardDrawn;
4795 }
4796 }
4797
Jorim Jaggi0d674622014-05-21 01:34:15 +02004798 @Override
Jorim Jaggie29b2db2014-05-30 23:17:03 +02004799 public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) {
Jorim Jaggi0d674622014-05-21 01:34:15 +02004800 if (mKeyguardDelegate != null) {
Jorim Jaggie29b2db2014-05-30 23:17:03 +02004801 mKeyguardDelegate.startKeyguardExitAnimation(startTime, fadeoutDuration);
Jorim Jaggi0d674622014-05-21 01:34:15 +02004802 }
4803 }
4804
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004805 void sendCloseSystemWindows() {
4806 sendCloseSystemWindows(mContext, null);
4807 }
4808
4809 void sendCloseSystemWindows(String reason) {
4810 sendCloseSystemWindows(mContext, reason);
4811 }
4812
4813 static void sendCloseSystemWindows(Context context, String reason) {
4814 if (ActivityManagerNative.isSystemReady()) {
Dianne Hackborn94a679d2009-07-28 17:51:07 -07004815 try {
4816 ActivityManagerNative.getDefault().closeSystemDialogs(reason);
4817 } catch (RemoteException e) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004818 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004819 }
4820 }
Mitsuru Oshima831d0d92009-06-16 18:27:18 -07004821
Jeff Brown01a98dd2011-09-20 15:08:29 -07004822 @Override
4823 public int rotationForOrientationLw(int orientation, int lastRotation) {
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05004824 if (false) {
4825 Slog.v(TAG, "rotationForOrientationLw(orient="
4826 + orientation + ", last=" + lastRotation
4827 + "); user=" + mUserRotation + " "
4828 + ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED)
4829 ? "USER_ROTATION_LOCKED" : "")
4830 );
4831 }
4832
Craig Mautner46ac6fa2013-08-01 10:06:34 -07004833 if (mForceDefaultOrientation) {
4834 return Surface.ROTATION_0;
4835 }
4836
The Android Open Source Project0727d222009-03-11 12:11:58 -07004837 synchronized (mLock) {
Jeff Brownc0347aa2011-09-23 17:26:09 -07004838 int sensorRotation = mOrientationListener.getProposedRotation(); // may be -1
4839 if (sensorRotation < 0) {
Jeff Brown0f862b42012-09-27 21:11:01 -07004840 sensorRotation = lastRotation;
Jeff Brownc0347aa2011-09-23 17:26:09 -07004841 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004842
Jeff Browndec6cf42011-11-15 14:08:20 -08004843 final int preferredRotation;
Jeff Brown2e7760e2012-04-11 15:14:55 -07004844 if (mLidState == LID_OPEN && mLidOpenRotation >= 0) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07004845 // Ignore sensor when lid switch is open and rotation is forced.
4846 preferredRotation = mLidOpenRotation;
4847 } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR
Jeff Brownc0347aa2011-09-23 17:26:09 -07004848 && (mCarDockEnablesAccelerometer || mCarDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07004849 // Ignore sensor when in car dock unless explicitly enabled.
4850 // This case can override the behavior of NOSENSOR, and can also
4851 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07004852 preferredRotation = mCarDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07004853 ? sensorRotation : mCarDockRotation;
Jeff Brown1a693182011-11-08 14:44:16 -08004854 } else if ((mDockMode == Intent.EXTRA_DOCK_STATE_DESK
4855 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
4856 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK)
Jeff Brownc0347aa2011-09-23 17:26:09 -07004857 && (mDeskDockEnablesAccelerometer || mDeskDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07004858 // Ignore sensor when in desk dock unless explicitly enabled.
4859 // This case can override the behavior of NOSENSOR, and can also
4860 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07004861 preferredRotation = mDeskDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07004862 ? sensorRotation : mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -07004863 } else if (mHdmiPlugged && mDemoHdmiRotationLock) {
4864 // Ignore sensor when plugged into HDMI when demo HDMI rotation lock enabled.
Jeff Browneb3e4b92011-12-06 19:54:24 -08004865 // Note that the dock orientation overrides the HDMI orientation.
Jeff Brownc82c89ed2013-04-17 17:18:15 -07004866 preferredRotation = mDemoHdmiRotation;
4867 } else if (mHdmiPlugged && mDockMode == Intent.EXTRA_DOCK_STATE_UNDOCKED
4868 && mUndockedHdmiRotation >= 0) {
4869 // Ignore sensor when plugged into HDMI and an undocked orientation has
4870 // been specified in the configuration (only for legacy devices without
4871 // full multi-display support).
4872 // Note that the dock orientation overrides the HDMI orientation.
4873 preferredRotation = mUndockedHdmiRotation;
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07004874 } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED) {
4875 // Application just wants to remain locked in the last rotation.
4876 preferredRotation = lastRotation;
Jeff Brownbcdfc622014-03-06 19:13:04 -08004877 } else if (!mSupportAutoRotation) {
4878 // If we don't support auto-rotation then bail out here and ignore
4879 // the sensor and any rotation lock settings.
4880 preferredRotation = -1;
Jeff Brown207673cd2012-06-05 17:47:11 -07004881 } else if ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE
Jeff Brown01a98dd2011-09-20 15:08:29 -07004882 && (orientation == ActivityInfo.SCREEN_ORIENTATION_USER
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07004883 || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
4884 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
4885 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
4886 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER))
Jeff Brown01a98dd2011-09-20 15:08:29 -07004887 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
4888 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
4889 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
4890 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) {
4891 // Otherwise, use sensor only if requested by the application or enabled
4892 // by default for USER or UNSPECIFIED modes. Does not apply to NOSENSOR.
Jeff Brownd3187e32011-09-21 19:26:44 -07004893 if (mAllowAllRotations < 0) {
4894 // Can't read this during init() because the context doesn't
4895 // have display metrics at that time so we cannot determine
4896 // tablet vs. phone then.
4897 mAllowAllRotations = mContext.getResources().getBoolean(
4898 com.android.internal.R.bool.config_allowAllRotations) ? 1 : 0;
4899 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004900 if (sensorRotation != Surface.ROTATION_180
Jeff Brownd3187e32011-09-21 19:26:44 -07004901 || mAllowAllRotations == 1
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07004902 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
4903 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07004904 preferredRotation = sensorRotation;
4905 } else {
4906 preferredRotation = lastRotation;
4907 }
Jeff Brown207673cd2012-06-05 17:47:11 -07004908 } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED
4909 && orientation != ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) {
4910 // Apply rotation lock. Does not apply to NOSENSOR.
4911 // The idea is that the user rotation expresses a weak preference for the direction
4912 // of gravity and as NOSENSOR is never affected by gravity, then neither should
4913 // NOSENSOR be affected by rotation lock (although it will be affected by docks).
Jeff Brown4dfce202011-10-05 12:00:10 -07004914 preferredRotation = mUserRotation;
Jeff Browndec6cf42011-11-15 14:08:20 -08004915 } else {
4916 // No overriding preference.
4917 // We will do exactly what the application asked us to do.
4918 preferredRotation = -1;
Jeff Brown01a98dd2011-09-20 15:08:29 -07004919 }
4920
Dianne Hackborne5439f22010-10-02 16:53:50 -07004921 switch (orientation) {
4922 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08004923 // Return portrait unless overridden.
4924 if (isAnyPortrait(preferredRotation)) {
4925 return preferredRotation;
4926 }
Dianne Hackborne5439f22010-10-02 16:53:50 -07004927 return mPortraitRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07004928
Jeff Brown01a98dd2011-09-20 15:08:29 -07004929 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08004930 // Return landscape unless overridden.
4931 if (isLandscapeOrSeascape(preferredRotation)) {
4932 return preferredRotation;
4933 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004934 return mLandscapeRotation;
4935
4936 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08004937 // Return reverse portrait unless overridden.
4938 if (isAnyPortrait(preferredRotation)) {
4939 return preferredRotation;
4940 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004941 return mUpsideDownRotation;
4942
4943 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08004944 // Return seascape unless overridden.
4945 if (isLandscapeOrSeascape(preferredRotation)) {
4946 return preferredRotation;
4947 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004948 return mSeascapeRotation;
4949
4950 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07004951 case ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE:
Jeff Brown01a98dd2011-09-20 15:08:29 -07004952 // Return either landscape rotation.
4953 if (isLandscapeOrSeascape(preferredRotation)) {
4954 return preferredRotation;
4955 }
4956 if (isLandscapeOrSeascape(lastRotation)) {
Jeff Brown4519f072011-01-23 13:16:01 -08004957 return lastRotation;
4958 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004959 return mLandscapeRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004960
Jeff Brown01a98dd2011-09-20 15:08:29 -07004961 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07004962 case ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT:
Jeff Brown01a98dd2011-09-20 15:08:29 -07004963 // Return either portrait rotation.
4964 if (isAnyPortrait(preferredRotation)) {
4965 return preferredRotation;
4966 }
4967 if (isAnyPortrait(lastRotation)) {
4968 return lastRotation;
4969 }
4970 return mPortraitRotation;
4971
4972 default:
Jeff Brown4dfce202011-10-05 12:00:10 -07004973 // For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR,
4974 // just return the preferred orientation we already calculated.
Jeff Brown01a98dd2011-09-20 15:08:29 -07004975 if (preferredRotation >= 0) {
4976 return preferredRotation;
4977 }
Dianne Hackborndacea8c2011-04-21 17:26:39 -07004978 return Surface.ROTATION_0;
Daniel Sandlere7e5ac22011-02-22 16:10:21 -05004979 }
4980 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07004981 }
4982
Jeff Brown01a98dd2011-09-20 15:08:29 -07004983 @Override
4984 public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation) {
4985 switch (orientation) {
4986 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
4987 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
4988 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
4989 return isAnyPortrait(rotation);
4990
4991 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
4992 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
4993 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
4994 return isLandscapeOrSeascape(rotation);
4995
4996 default:
4997 return true;
4998 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07004999 }
5000
Jeff Brownc0347aa2011-09-23 17:26:09 -07005001 @Override
5002 public void setRotationLw(int rotation) {
5003 mOrientationListener.setCurrentRotation(rotation);
5004 }
5005
Jeff Brown01a98dd2011-09-20 15:08:29 -07005006 private boolean isLandscapeOrSeascape(int rotation) {
5007 return rotation == mLandscapeRotation || rotation == mSeascapeRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005008 }
5009
Jeff Brown01a98dd2011-09-20 15:08:29 -07005010 private boolean isAnyPortrait(int rotation) {
5011 return rotation == mPortraitRotation || rotation == mUpsideDownRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005012 }
5013
Jose Lima9546b202014-07-02 17:21:51 -07005014 @Override
Svetoslav Ganov80943d82013-01-02 10:25:37 -08005015 public int getUserRotationMode() {
5016 return Settings.System.getIntForUser(mContext.getContentResolver(),
Brett Chabot7e55c402013-05-16 19:38:08 -07005017 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
5018 WindowManagerPolicy.USER_ROTATION_FREE :
5019 WindowManagerPolicy.USER_ROTATION_LOCKED;
Svetoslav Ganov80943d82013-01-02 10:25:37 -08005020 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005021
5022 // User rotation: to be used when all else fails in assigning an orientation to the device
Jose Lima9546b202014-07-02 17:21:51 -07005023 @Override
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005024 public void setUserRotationMode(int mode, int rot) {
5025 ContentResolver res = mContext.getContentResolver();
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005026
5027 // mUserRotationMode and mUserRotation will be assigned by the content observer
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005028 if (mode == WindowManagerPolicy.USER_ROTATION_LOCKED) {
Christopher Tate5e08af02012-09-21 17:17:22 -07005029 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005030 Settings.System.USER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005031 rot,
5032 UserHandle.USER_CURRENT);
5033 Settings.System.putIntForUser(res,
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005034 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005035 0,
5036 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005037 } else {
Christopher Tate5e08af02012-09-21 17:17:22 -07005038 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005039 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005040 1,
5041 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005042 }
5043 }
5044
Jose Lima9546b202014-07-02 17:21:51 -07005045 @Override
Jeff Brownac143512012-04-05 18:57:33 -07005046 public void setSafeMode(boolean safeMode) {
5047 mSafeMode = safeMode;
5048 performHapticFeedbackLw(null, safeMode
5049 ? HapticFeedbackConstants.SAFE_MODE_ENABLED
5050 : HapticFeedbackConstants.SAFE_MODE_DISABLED, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005051 }
Craig Mautnereda67292013-04-28 13:50:14 -07005052
Dianne Hackborn181ceb52009-08-27 22:16:40 -07005053 static long[] getLongIntArray(Resources r, int resid) {
5054 int[] ar = r.getIntArray(resid);
5055 if (ar == null) {
5056 return null;
5057 }
5058 long[] out = new long[ar.length];
5059 for (int i=0; i<ar.length; i++) {
5060 out[i] = ar[i];
5061 }
5062 return out;
5063 }
Craig Mautnereda67292013-04-28 13:50:14 -07005064
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005065 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07005066 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005067 public void systemReady() {
Mike Lockwooded8902d2013-11-15 11:01:47 -08005068 mKeyguardDelegate = new KeyguardServiceDelegate(mContext, null);
5069 mKeyguardDelegate.onSystemReady();
5070
Jeff Brown4f5fa282014-06-12 19:19:15 -07005071 updateUiMode();
Dianne Hackbornb1a79802009-09-29 15:18:31 -07005072 synchronized (mLock) {
5073 updateOrientationListenerLp();
Dianne Hackbornc777e072010-02-12 13:07:59 -08005074 mSystemReady = true;
5075 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07005076 @Override
Dianne Hackbornc777e072010-02-12 13:07:59 -08005077 public void run() {
5078 updateSettings();
5079 }
5080 });
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005081 }
5082 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07005083
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005084 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005085 @Override
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005086 public void systemBooted() {
Jim Millere5f910a2013-10-16 18:15:46 -07005087 if (mKeyguardDelegate != null) {
5088 mKeyguardDelegate.onBootCompleted();
5089 }
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005090 synchronized (mLock) {
5091 mSystemBooted = true;
5092 }
Craig Mautner8a0da012014-05-31 15:13:37 -07005093 wakingUp(null);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005094 }
5095
Dianne Hackborn661cd522011-08-22 00:26:20 -07005096 ProgressDialog mBootMsgDialog = null;
5097
5098 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005099 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07005100 public void showBootMessage(final CharSequence msg, final boolean always) {
5101 mHandler.post(new Runnable() {
5102 @Override public void run() {
5103 if (mBootMsgDialog == null) {
Craig Stout4c0cb8a2014-04-04 13:03:10 -07005104 int theme;
5105 if (mContext.getPackageManager().hasSystemFeature(
5106 PackageManager.FEATURE_WATCH)) {
5107 theme = com.android.internal.R.style.Theme_Micro_Dialog_Alert;
5108 } else if (mContext.getPackageManager().hasSystemFeature(
5109 PackageManager.FEATURE_TELEVISION)) {
5110 theme = com.android.internal.R.style.Theme_Leanback_Dialog_Alert;
5111 } else {
5112 theme = 0;
5113 }
Vinod Krishnanfa8fc412014-04-18 14:35:53 -07005114
5115 mBootMsgDialog = new ProgressDialog(mContext, theme) {
Dianne Hackborn295e3c22011-08-25 13:19:08 -07005116 // This dialog will consume all events coming in to
5117 // it, to avoid it trying to do things too early in boot.
5118 @Override public boolean dispatchKeyEvent(KeyEvent event) {
5119 return true;
5120 }
5121 @Override public boolean dispatchKeyShortcutEvent(KeyEvent event) {
5122 return true;
5123 }
5124 @Override public boolean dispatchTouchEvent(MotionEvent ev) {
5125 return true;
5126 }
5127 @Override public boolean dispatchTrackballEvent(MotionEvent ev) {
5128 return true;
5129 }
5130 @Override public boolean dispatchGenericMotionEvent(MotionEvent ev) {
5131 return true;
5132 }
5133 @Override public boolean dispatchPopulateAccessibilityEvent(
5134 AccessibilityEvent event) {
5135 return true;
5136 }
5137 };
Dianne Hackborn661cd522011-08-22 00:26:20 -07005138 mBootMsgDialog.setTitle(R.string.android_upgrading_title);
5139 mBootMsgDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
5140 mBootMsgDialog.setIndeterminate(true);
5141 mBootMsgDialog.getWindow().setType(
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07005142 WindowManager.LayoutParams.TYPE_BOOT_PROGRESS);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005143 mBootMsgDialog.getWindow().addFlags(
5144 WindowManager.LayoutParams.FLAG_DIM_BEHIND
5145 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
5146 mBootMsgDialog.getWindow().setDimAmount(1);
Dianne Hackbornd9efb952011-12-07 14:56:51 -08005147 WindowManager.LayoutParams lp = mBootMsgDialog.getWindow().getAttributes();
5148 lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
5149 mBootMsgDialog.getWindow().setAttributes(lp);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005150 mBootMsgDialog.setCancelable(false);
5151 mBootMsgDialog.show();
5152 }
5153 mBootMsgDialog.setMessage(msg);
5154 }
5155 });
5156 }
5157
5158 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005159 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07005160 public void hideBootMessages() {
Craig Mautnera631d492014-08-05 15:16:01 -07005161 mHandler.sendEmptyMessage(MSG_HIDE_BOOT_MESSAGE);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005162 }
5163
Mike Lockwood28569302010-01-28 11:54:40 -05005164 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005165 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05005166 public void userActivity() {
Dianne Hackborndf89e652011-10-06 22:35:11 -07005167 // ***************************************
5168 // NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
5169 // ***************************************
5170 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
5171 // WITH ITS LOCKS HELD.
5172 //
5173 // This code must be VERY careful about the locks
5174 // it acquires.
5175 // In fact, the current code acquires way too many,
5176 // and probably has lurking deadlocks.
5177
Mike Lockwood28569302010-01-28 11:54:40 -05005178 synchronized (mScreenLockTimeout) {
5179 if (mLockScreenTimerActive) {
5180 // reset the timer
5181 mHandler.removeCallbacks(mScreenLockTimeout);
5182 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
5183 }
5184 }
Daniel Sandler0601eb72011-04-13 01:01:32 -04005185 }
5186
Adam Cohenf7522022012-10-03 20:03:18 -07005187 class ScreenLockTimeout implements Runnable {
5188 Bundle options;
5189
5190 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05005191 public void run() {
5192 synchronized (this) {
5193 if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard");
Jim Miller5ecd8112013-01-09 18:50:26 -08005194 if (mKeyguardDelegate != null) {
5195 mKeyguardDelegate.doKeyguardTimeout(options);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005196 }
Mike Lockwood28569302010-01-28 11:54:40 -05005197 mLockScreenTimerActive = false;
Adam Cohenf7522022012-10-03 20:03:18 -07005198 options = null;
Mike Lockwood28569302010-01-28 11:54:40 -05005199 }
5200 }
Mike Lockwood28569302010-01-28 11:54:40 -05005201
Adam Cohenf7522022012-10-03 20:03:18 -07005202 public void setLockOptions(Bundle options) {
5203 this.options = options;
5204 }
5205 }
5206
5207 ScreenLockTimeout mScreenLockTimeout = new ScreenLockTimeout();
5208
Jose Lima9546b202014-07-02 17:21:51 -07005209 @Override
Adam Cohenf7522022012-10-03 20:03:18 -07005210 public void lockNow(Bundle options) {
Jim Miller93c518e2012-01-17 15:55:31 -08005211 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null);
5212 mHandler.removeCallbacks(mScreenLockTimeout);
Adam Cohenf7522022012-10-03 20:03:18 -07005213 if (options != null) {
5214 // In case multiple calls are made to lockNow, we don't wipe out the options
5215 // until the runnable actually executes.
5216 mScreenLockTimeout.setLockOptions(options);
5217 }
Jim Miller93c518e2012-01-17 15:55:31 -08005218 mHandler.post(mScreenLockTimeout);
5219 }
5220
Mike Lockwood28569302010-01-28 11:54:40 -05005221 private void updateLockScreenTimeout() {
5222 synchronized (mScreenLockTimeout) {
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005223 boolean enable = (mAllowLockscreenWhenOn && mScreenOnEarly &&
Jim Miller5ecd8112013-01-09 18:50:26 -08005224 mKeyguardDelegate != null && mKeyguardDelegate.isSecure());
Mike Lockwood28569302010-01-28 11:54:40 -05005225 if (mLockScreenTimerActive != enable) {
5226 if (enable) {
5227 if (localLOGV) Log.v(TAG, "setting lockscreen timer");
5228 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
5229 } else {
5230 if (localLOGV) Log.v(TAG, "clearing lockscreen timer");
5231 mHandler.removeCallbacks(mScreenLockTimeout);
5232 }
5233 mLockScreenTimerActive = enable;
5234 }
5235 }
5236 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005237
5238 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07005239 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005240 public void enableScreenAfterBoot() {
5241 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07005242 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07005243 updateRotation(true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005244 }
Dianne Hackbornf54c8f92009-09-19 14:03:57 -07005245
Jeff Brownc458ce92012-04-30 14:58:40 -07005246 private void applyLidSwitchState() {
Jeff Brownc458ce92012-04-30 14:58:40 -07005247 if (mLidState == LID_CLOSED && mLidControlsSleep) {
Jeff Brown6d8fd272014-05-20 21:24:38 -07005248 mPowerManager.goToSleep(SystemClock.uptimeMillis(),
5249 PowerManager.GO_TO_SLEEP_REASON_USER,
5250 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
Jeff Brownc458ce92012-04-30 14:58:40 -07005251 }
Jeff Browna20dda42014-05-27 20:57:24 -07005252
5253 synchronized (mLock) {
5254 updateWakeGestureListenerLp();
5255 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005256 }
5257
Jeff Brown4f5fa282014-06-12 19:19:15 -07005258 void updateUiMode() {
5259 if (mUiModeManager == null) {
5260 mUiModeManager = IUiModeManager.Stub.asInterface(
5261 ServiceManager.getService(Context.UI_MODE_SERVICE));
5262 }
5263 try {
5264 mUiMode = mUiModeManager.getCurrentModeType();
5265 } catch (RemoteException e) {
5266 }
5267 }
5268
Jeff Brown01a98dd2011-09-20 15:08:29 -07005269 void updateRotation(boolean alwaysSendConfiguration) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005270 try {
5271 //set orientation on WindowManager
Dianne Hackbornf87d1962012-04-04 12:48:24 -07005272 mWindowManager.updateRotation(alwaysSendConfiguration, false);
5273 } catch (RemoteException e) {
5274 // Ignore
5275 }
5276 }
5277
5278 void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) {
5279 try {
5280 //set orientation on WindowManager
5281 mWindowManager.updateRotation(alwaysSendConfiguration, forceRelayout);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005282 } catch (RemoteException e) {
5283 // Ignore
5284 }
5285 }
5286
Daniel Sandler6396c722013-04-16 20:19:09 -04005287 /**
5288 * Return an Intent to launch the currently active dock app as home. Returns
5289 * null if the standard home should be launched, which is the case if any of the following is
5290 * true:
5291 * <ul>
5292 * <li>The device is not in either car mode or desk mode
5293 * <li>The device is in car mode but ENABLE_CAR_DOCK_HOME_CAPTURE is false
5294 * <li>The device is in desk mode but ENABLE_DESK_DOCK_HOME_CAPTURE is false
5295 * <li>The device is in car mode but there's no CAR_DOCK app with METADATA_DOCK_HOME
5296 * <li>The device is in desk mode but there's no DESK_DOCK app with METADATA_DOCK_HOME
5297 * </ul>
Craig Mautnereda67292013-04-28 13:50:14 -07005298 * @return A dock intent.
Daniel Sandler6396c722013-04-16 20:19:09 -04005299 */
5300 Intent createHomeDockIntent() {
5301 Intent intent = null;
5302
5303 // What home does is based on the mode, not the dock state. That
5304 // is, when in car mode you should be taken to car home regardless
5305 // of whether we are actually in a car dock.
5306 if (mUiMode == Configuration.UI_MODE_TYPE_CAR) {
5307 if (ENABLE_CAR_DOCK_HOME_CAPTURE) {
5308 intent = mCarDockIntent;
5309 }
5310 } else if (mUiMode == Configuration.UI_MODE_TYPE_DESK) {
5311 if (ENABLE_DESK_DOCK_HOME_CAPTURE) {
5312 intent = mDeskDockIntent;
5313 }
Jeff Brown4f5fa282014-06-12 19:19:15 -07005314 } else if (mUiMode == Configuration.UI_MODE_TYPE_WATCH
5315 && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
5316 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK
5317 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK)) {
5318 // Always launch dock home from home when watch is docked, if it exists.
5319 intent = mDeskDockIntent;
Daniel Sandler6396c722013-04-16 20:19:09 -04005320 }
5321
5322 if (intent == null) {
5323 return null;
5324 }
5325
5326 ActivityInfo ai = null;
5327 ResolveInfo info = mContext.getPackageManager().resolveActivityAsUser(
5328 intent,
John Spurlockf56bef12013-07-09 09:51:46 -04005329 PackageManager.MATCH_DEFAULT_ONLY | PackageManager.GET_META_DATA,
Craig Mautnerd625ab22013-09-06 13:40:31 -07005330 mCurrentUserId);
Daniel Sandler6396c722013-04-16 20:19:09 -04005331 if (info != null) {
5332 ai = info.activityInfo;
5333 }
5334 if (ai != null
5335 && ai.metaData != null
5336 && ai.metaData.getBoolean(Intent.METADATA_DOCK_HOME)) {
5337 intent = new Intent(intent);
5338 intent.setClassName(ai.packageName, ai.name);
5339 return intent;
5340 }
5341
5342 return null;
5343 }
5344
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005345 void startDockOrHome() {
John Spurlockc8b46ca2013-04-08 12:59:26 -04005346 awakenDreams();
Daniel Sandler6396c722013-04-16 20:19:09 -04005347
5348 Intent dock = createHomeDockIntent();
5349 if (dock != null) {
5350 try {
5351 mContext.startActivityAsUser(dock, UserHandle.CURRENT);
5352 return;
5353 } catch (ActivityNotFoundException e) {
5354 }
5355 }
5356
Dianne Hackbornd8883992012-09-07 15:58:52 -07005357 mContext.startActivityAsUser(mHomeIntent, UserHandle.CURRENT);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005358 }
Craig Mautnereda67292013-04-28 13:50:14 -07005359
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005360 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005361 * goes to the home screen
5362 * @return whether it did anything
5363 */
5364 boolean goHome() {
5365 if (false) {
5366 // This code always brings home to the front.
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07005367 try {
5368 ActivityManagerNative.getDefault().stopAppSwitches();
5369 } catch (RemoteException e) {
5370 }
Dianne Hackborn94a679d2009-07-28 17:51:07 -07005371 sendCloseSystemWindows();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005372 startDockOrHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005373 } else {
5374 // This code brings home to the front or, if it is already
5375 // at the front, puts the device to sleep.
5376 try {
Wink Savilled2e6a332010-02-12 12:12:06 -08005377 if (SystemProperties.getInt("persist.sys.uts-test-mode", 0) == 1) {
5378 /// Roll back EndcallBehavior as the cupcake design to pass P1 lab entry.
5379 Log.d(TAG, "UTS-TEST-MODE");
5380 } else {
5381 ActivityManagerNative.getDefault().stopAppSwitches();
5382 sendCloseSystemWindows();
Daniel Sandler6396c722013-04-16 20:19:09 -04005383 Intent dock = createHomeDockIntent();
5384 if (dock != null) {
5385 int result = ActivityManagerNative.getDefault()
5386 .startActivityAsUser(null, null, dock,
5387 dock.resolveTypeIfNeeded(mContext.getContentResolver()),
5388 null, null, 0,
5389 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
5390 null, null, null, UserHandle.USER_CURRENT);
5391 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
5392 return false;
5393 }
5394 }
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005395 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005396 int result = ActivityManagerNative.getDefault()
Dianne Hackbornf265ea92013-01-31 15:00:51 -08005397 .startActivityAsUser(null, null, mHomeIntent,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005398 mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()),
Dianne Hackborna4972e92012-03-14 10:38:05 -07005399 null, null, 0,
5400 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Dianne Hackborn5e03e2c2012-09-06 14:21:19 -07005401 null, null, null, UserHandle.USER_CURRENT);
Dianne Hackborna4972e92012-03-14 10:38:05 -07005402 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005403 return false;
5404 }
5405 } catch (RemoteException ex) {
5406 // bummer, the activity manager, which is in this process, is dead
5407 }
5408 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005409 return true;
5410 }
Craig Mautnereda67292013-04-28 13:50:14 -07005411
5412 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07005413 public void setCurrentOrientationLw(int newOrientation) {
5414 synchronized (mLock) {
5415 if (newOrientation != mCurrentAppOrientation) {
5416 mCurrentAppOrientation = newOrientation;
5417 updateOrientationListenerLp();
5418 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005419 }
5420 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08005421
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07005422 private void performAuditoryFeedbackForAccessibilityIfNeed() {
5423 if (!isGlobalAccessibilityGestureEnabled()) {
5424 return;
5425 }
5426 AudioManager audioManager = (AudioManager) mContext.getSystemService(
5427 Context.AUDIO_SERVICE);
5428 if (audioManager.isSilentMode()) {
5429 return;
5430 }
5431 Ringtone ringTone = RingtoneManager.getRingtone(mContext,
5432 Settings.System.DEFAULT_NOTIFICATION_URI);
5433 ringTone.setStreamType(AudioManager.STREAM_MUSIC);
5434 ringTone.play();
5435 }
Craig Mautnereda67292013-04-28 13:50:14 -07005436
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07005437 private boolean isGlobalAccessibilityGestureEnabled() {
5438 return Settings.Global.getInt(mContext.getContentResolver(),
5439 Settings.Global.ENABLE_ACCESSIBILITY_GLOBAL_GESTURE_ENABLED, 0) == 1;
5440 }
5441
Craig Mautnereda67292013-04-28 13:50:14 -07005442 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07005443 public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) {
Svetoslav Ganov96179212012-10-10 14:17:45 -07005444 if (!mVibrator.hasVibrator()) {
5445 return false;
5446 }
Christopher Tate5e08af02012-09-21 17:17:22 -07005447 final boolean hapticsDisabled = Settings.System.getIntForUser(mContext.getContentResolver(),
5448 Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) == 0;
Jeff Brown82379ba2014-07-25 19:03:28 -07005449 if (hapticsDisabled && !always) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005450 return false;
5451 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08005452 long[] pattern = null;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005453 switch (effectId) {
5454 case HapticFeedbackConstants.LONG_PRESS:
Amith Yamasanic33cb712010-02-10 15:21:49 -08005455 pattern = mLongPressVibePattern;
5456 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07005457 case HapticFeedbackConstants.VIRTUAL_KEY:
Amith Yamasanic33cb712010-02-10 15:21:49 -08005458 pattern = mVirtualKeyVibePattern;
5459 break;
5460 case HapticFeedbackConstants.KEYBOARD_TAP:
5461 pattern = mKeyboardTapVibePattern;
5462 break;
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07005463 case HapticFeedbackConstants.CLOCK_TICK:
5464 pattern = mClockTickVibePattern;
5465 break;
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07005466 case HapticFeedbackConstants.CALENDAR_DATE:
5467 pattern = mCalendarDateVibePattern;
5468 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07005469 case HapticFeedbackConstants.SAFE_MODE_DISABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08005470 pattern = mSafeModeDisabledVibePattern;
5471 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07005472 case HapticFeedbackConstants.SAFE_MODE_ENABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08005473 pattern = mSafeModeEnabledVibePattern;
5474 break;
Amith Yamasanic33cb712010-02-10 15:21:49 -08005475 default:
5476 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005477 }
Dianne Hackbornf265ea92013-01-31 15:00:51 -08005478 int owningUid;
5479 String owningPackage;
5480 if (win != null) {
5481 owningUid = win.getOwningUid();
5482 owningPackage = win.getOwningPackage();
5483 } else {
5484 owningUid = android.os.Process.myUid();
Dianne Hackborn95d78532013-09-11 09:51:14 -07005485 owningPackage = mContext.getOpPackageName();
Dianne Hackbornf265ea92013-01-31 15:00:51 -08005486 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08005487 if (pattern.length == 1) {
5488 // One-shot vibration
John Spurlock7b414672014-07-18 13:02:39 -04005489 mVibrator.vibrate(owningUid, owningPackage, pattern[0], VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08005490 } else {
5491 // Pattern vibration
John Spurlock7b414672014-07-18 13:02:39 -04005492 mVibrator.vibrate(owningUid, owningPackage, pattern, -1, VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08005493 }
5494 return true;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005495 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005496
5497 @Override
5498 public void keepScreenOnStartedLw() {
Daniel Sandler0601eb72011-04-13 01:01:32 -04005499 }
5500
Jeff Brownc38c9be2012-10-04 13:16:19 -07005501 @Override
5502 public void keepScreenOnStoppedLw() {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01005503 if (mKeyguardDelegate != null && !mKeyguardDelegate.isShowingAndNotOccluded()) {
Jim Miller25190572013-02-28 17:36:24 -08005504 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005505 }
5506 }
Mike Lockwoodfcb39242009-10-21 23:01:07 -04005507
Dianne Hackborndf89e652011-10-06 22:35:11 -07005508 private int updateSystemUiVisibilityLw() {
Joe Onorato664644d2011-01-23 17:53:23 -08005509 // If there is no window focused, there will be nobody to handle the events
5510 // anyway, so just hang on in whatever state we're in until things settle down.
John Spurlock79da8332013-09-20 12:04:47 -04005511 WindowState win = mFocusedWindow != null ? mFocusedWindow : mTopFullscreenOpaqueWindowState;
5512 if (win == null) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07005513 return 0;
5514 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01005515 if ((win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 && mHideLockScreen == true) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07005516 // We are updating at a point where the keyguard has gotten
5517 // focus, but we were last in a state where the top window is
5518 // hiding it. This is probably because the keyguard as been
5519 // shown while the top window was displayed, so we want to ignore
5520 // it here because this is just a very transient change and it
5521 // will quickly lose focus once it correctly gets hidden.
5522 return 0;
5523 }
John Spurlock32beb2c2013-03-11 10:16:47 -04005524
John Spurlock1db8b682014-02-18 11:18:59 -05005525 int tmpVisibility = PolicyControl.getSystemUiVisibility(win, null)
Dianne Hackborne26ab702011-10-16 13:21:33 -07005526 & ~mResettingSystemUiFlags
5527 & ~mForceClearedSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04005528 if (mForcingShowNavBar && win.getSurfaceLayer() < mForcingShowNavBarLayer) {
John Spurlockc6d1c602014-01-17 15:22:06 -05005529 tmpVisibility &= ~PolicyControl.adjustClearableFlags(win, View.SYSTEM_UI_CLEARABLE_FLAGS);
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08005530 }
John Spurlock79da8332013-09-20 12:04:47 -04005531 final int visibility = updateSystemBarsLw(win, mLastSystemUiFlags, tmpVisibility);
John Spurlockad3e6cb2013-04-30 08:47:43 -04005532 final int diff = visibility ^ mLastSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04005533 final boolean needsMenu = win.getNeedsMenuLw(mTopFullscreenOpaqueWindowState);
Dianne Hackborne0f085d2011-11-30 18:41:15 -08005534 if (diff == 0 && mLastFocusNeedsMenu == needsMenu
John Spurlock79da8332013-09-20 12:04:47 -04005535 && mFocusedApp == win.getAppToken()) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07005536 return 0;
5537 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07005538 mLastSystemUiFlags = visibility;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08005539 mLastFocusNeedsMenu = needsMenu;
John Spurlock79da8332013-09-20 12:04:47 -04005540 mFocusedApp = win.getAppToken();
Dianne Hackborndf89e652011-10-06 22:35:11 -07005541 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07005542 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07005543 public void run() {
Dianne Hackborn42e620c2012-06-24 13:20:51 -07005544 try {
5545 IStatusBarService statusbar = getStatusBarService();
5546 if (statusbar != null) {
5547 statusbar.setSystemUiVisibility(visibility, 0xffffffff);
5548 statusbar.topAppWindowChanged(needsMenu);
Joe Onorato664644d2011-01-23 17:53:23 -08005549 }
Dianne Hackborn42e620c2012-06-24 13:20:51 -07005550 } catch (RemoteException e) {
5551 // re-acquire status bar service next time it is needed.
5552 mStatusBarService = null;
Joe Onorato664644d2011-01-23 17:53:23 -08005553 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07005554 }
5555 });
5556 return diff;
Joe Onorato664644d2011-01-23 17:53:23 -08005557 }
5558
John Spurlock79da8332013-09-20 12:04:47 -04005559 private int updateSystemBarsLw(WindowState win, int oldVis, int vis) {
John Spurlockbd957402013-10-03 11:38:39 -04005560 // apply translucent bar vis flags
Jorim Jaggi380ecb82014-03-14 17:25:20 +01005561 WindowState transWin = isStatusBarKeyguard() && !mHideLockScreen
5562 ? mStatusBar
John Spurlockbd957402013-10-03 11:38:39 -04005563 : mTopFullscreenOpaqueWindowState;
5564 vis = mStatusBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
5565 vis = mNavigationBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
5566
John Spurlock27735a42013-08-14 17:57:38 -04005567 // prevent status bar interaction from clearing certain flags
John Spurlock79da8332013-09-20 12:04:47 -04005568 boolean statusBarHasFocus = win.getAttrs().type == TYPE_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04005569 if (statusBarHasFocus && !isStatusBarKeyguard()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04005570 int flags = View.SYSTEM_UI_FLAG_FULLSCREEN
5571 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlockcfc359a2013-09-05 10:42:03 -04005572 | View.SYSTEM_UI_FLAG_IMMERSIVE
Jorim Jaggi5cf17872014-03-26 18:31:48 +01005573 | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
John Spurlock08ffcf52014-07-11 10:13:46 -04005574 if (mHideLockScreen) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01005575 flags |= View.STATUS_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSLUCENT;
5576 }
John Spurlockbd957402013-10-03 11:38:39 -04005577 vis = (vis & ~flags) | (oldVis & flags);
John Spurlockad3e6cb2013-04-30 08:47:43 -04005578 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04005579
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04005580 if (!areTranslucentBarsAllowed()) {
Adrian Roosea562512014-05-05 13:33:03 +02005581 vis &= ~(View.NAVIGATION_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSLUCENT
5582 | View.SYSTEM_UI_TRANSPARENT);
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07005583 }
5584
John Spurlock27735a42013-08-14 17:57:38 -04005585 // update status bar
John Spurlockf1a36642013-10-12 17:50:42 -04005586 boolean immersiveSticky =
5587 (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
John Spurlock27735a42013-08-14 17:57:38 -04005588 boolean hideStatusBarWM =
John Spurlockbd957402013-10-03 11:38:39 -04005589 mTopFullscreenOpaqueWindowState != null &&
John Spurlockc6d1c602014-01-17 15:22:06 -05005590 (PolicyControl.getWindowFlags(mTopFullscreenOpaqueWindowState, null)
John Spurlock27735a42013-08-14 17:57:38 -04005591 & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0;
5592 boolean hideStatusBarSysui =
5593 (vis & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04005594 boolean hideNavBarSysui =
5595 (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0;
John Spurlockad3e6cb2013-04-30 08:47:43 -04005596
John Spurlock27735a42013-08-14 17:57:38 -04005597 boolean transientStatusBarAllowed =
5598 mStatusBar != null && (
5599 hideStatusBarWM
John Spurlockf1a36642013-10-12 17:50:42 -04005600 || (hideStatusBarSysui && immersiveSticky)
John Spurlock27735a42013-08-14 17:57:38 -04005601 || statusBarHasFocus);
5602
John Spurlockf1a36642013-10-12 17:50:42 -04005603 boolean transientNavBarAllowed =
5604 mNavigationBar != null &&
5605 hideNavBarSysui && immersiveSticky;
5606
John Spurlockf25706f2013-11-07 18:02:43 -05005607 boolean denyTransientStatus = mStatusBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04005608 && !transientStatusBarAllowed && hideStatusBarSysui;
John Spurlockf25706f2013-11-07 18:02:43 -05005609 boolean denyTransientNav = mNavigationBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04005610 && !transientNavBarAllowed;
5611 if (denyTransientStatus || denyTransientNav) {
John Spurlock27735a42013-08-14 17:57:38 -04005612 // clear the clearable flags instead
John Spurlockf1a36642013-10-12 17:50:42 -04005613 clearClearableFlagsLw();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005614 }
John Spurlock27735a42013-08-14 17:57:38 -04005615
5616 vis = mStatusBarController.updateVisibilityLw(transientStatusBarAllowed, oldVis, vis);
5617
5618 // update navigation bar
John Spurlockf1a36642013-10-12 17:50:42 -04005619 boolean oldImmersiveMode = isImmersiveMode(oldVis);
5620 boolean newImmersiveMode = isImmersiveMode(vis);
5621 if (win != null && oldImmersiveMode != newImmersiveMode) {
John Spurlock79da8332013-09-20 12:04:47 -04005622 final String pkg = win.getOwningPackage();
Maurice Lam99c6e072014-04-28 18:24:28 -07005623 mImmersiveModeConfirmation.immersiveModeChanged(pkg, newImmersiveMode,
5624 isUserSetupComplete());
John Spurlock34e13d92013-08-10 06:52:28 -04005625 }
John Spurlock27735a42013-08-14 17:57:38 -04005626
John Spurlockf1a36642013-10-12 17:50:42 -04005627 vis = mNavigationBarController.updateVisibilityLw(transientNavBarAllowed, oldVis, vis);
5628
John Spurlocke1f366f2013-08-05 12:22:40 -04005629 return vis;
John Spurlockad3e6cb2013-04-30 08:47:43 -04005630 }
5631
John Spurlockf1a36642013-10-12 17:50:42 -04005632 private void clearClearableFlagsLw() {
5633 int newVal = mResettingSystemUiFlags | View.SYSTEM_UI_CLEARABLE_FLAGS;
5634 if (newVal != mResettingSystemUiFlags) {
5635 mResettingSystemUiFlags = newVal;
5636 mWindowManagerFuncs.reevaluateStatusBarVisibility();
5637 }
5638 }
5639
5640 private boolean isImmersiveMode(int vis) {
5641 final int flags = View.SYSTEM_UI_FLAG_IMMERSIVE | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
John Spurlock34e13d92013-08-10 06:52:28 -04005642 return mNavigationBar != null
5643 && (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0
Daniel Sandler900ece52013-10-18 15:53:27 -04005644 && (vis & flags) != 0
5645 && canHideNavigationBar();
John Spurlock34e13d92013-08-10 06:52:28 -04005646 }
5647
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07005648 /**
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04005649 * @return whether the navigation or status bar can be made translucent
5650 *
5651 * This should return true unless touch exploration is not enabled or
5652 * R.boolean.config_enableTranslucentDecor is false.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07005653 */
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04005654 private boolean areTranslucentBarsAllowed() {
Svetoslav8e3feb12014-02-24 13:46:47 -08005655 return mTranslucentDecorEnabled
5656 && !mAccessibilityManager.isTouchExplorationEnabled();
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07005657 }
5658
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04005659 // Use this instead of checking config_showNavigationBar so that it can be consistently
5660 // overridden by qemu.hw.mainkeys in the emulator.
Craig Mautnereda67292013-04-28 13:50:14 -07005661 @Override
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04005662 public boolean hasNavigationBar() {
5663 return mHasNavigationBar;
5664 }
5665
satok1bc0a492012-04-25 22:47:12 +09005666 @Override
5667 public void setLastInputMethodWindowLw(WindowState ime, WindowState target) {
5668 mLastInputMethodWindow = ime;
5669 mLastInputMethodTargetWindow = target;
5670 }
5671
Craig Mautnerf1b67412012-09-19 13:18:29 -07005672 @Override
Satoshi Kataoka658c7b82013-10-10 17:03:51 +09005673 public int getInputMethodWindowVisibleHeightLw() {
5674 return mDockBottom - mCurBottom;
5675 }
5676
5677 @Override
Craig Mautnerf1b67412012-09-19 13:18:29 -07005678 public void setCurrentUserLw(int newUserId) {
Craig Mautnerd625ab22013-09-06 13:40:31 -07005679 mCurrentUserId = newUserId;
Jim Miller5ecd8112013-01-09 18:50:26 -08005680 if (mKeyguardDelegate != null) {
5681 mKeyguardDelegate.setCurrentUser(newUserId);
Craig Mautnerf1b67412012-09-19 13:18:29 -07005682 }
John Spurlock13451a22012-09-28 14:40:41 -04005683 if (mStatusBarService != null) {
5684 try {
5685 mStatusBarService.setCurrentUser(newUserId);
5686 } catch (RemoteException e) {
5687 // oh well
5688 }
5689 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07005690 setLastInputMethodWindowLw(null, null);
Craig Mautnerf1b67412012-09-19 13:18:29 -07005691 }
5692
5693 @Override
Svetoslav Ganov545252f2012-12-10 18:29:24 -08005694 public boolean canMagnifyWindow(int windowType) {
5695 switch (windowType) {
5696 case WindowManager.LayoutParams.TYPE_INPUT_METHOD:
5697 case WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG:
5698 case WindowManager.LayoutParams.TYPE_NAVIGATION_BAR:
5699 case WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY: {
5700 return false;
5701 }
5702 }
5703 return true;
5704 }
5705
5706 @Override
5707 public boolean isTopLevelWindow(int windowType) {
5708 if (windowType >= WindowManager.LayoutParams.FIRST_SUB_WINDOW
5709 && windowType <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
5710 return (windowType == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG);
5711 }
5712 return true;
5713 }
5714
Jim Miller4eeb4f62012-11-08 00:04:29 -08005715 @Override
Jeff Brownd7a04de2012-06-17 14:17:52 -07005716 public void dump(String prefix, PrintWriter pw, String[] args) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005717 pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005718 pw.print(" mSystemReady="); pw.print(mSystemReady);
5719 pw.print(" mSystemBooted="); pw.println(mSystemBooted);
Jeff Brown2e7760e2012-04-11 15:14:55 -07005720 pw.print(prefix); pw.print("mLidState="); pw.print(mLidState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005721 pw.print(" mLidOpenRotation="); pw.print(mLidOpenRotation);
5722 pw.print(" mHdmiPlugged="); pw.println(mHdmiPlugged);
Dianne Hackborne26ab702011-10-16 13:21:33 -07005723 if (mLastSystemUiFlags != 0 || mResettingSystemUiFlags != 0
5724 || mForceClearedSystemUiFlags != 0) {
5725 pw.print(prefix); pw.print("mLastSystemUiFlags=0x");
5726 pw.print(Integer.toHexString(mLastSystemUiFlags));
5727 pw.print(" mResettingSystemUiFlags=0x");
5728 pw.print(Integer.toHexString(mResettingSystemUiFlags));
5729 pw.print(" mForceClearedSystemUiFlags=0x");
5730 pw.println(Integer.toHexString(mForceClearedSystemUiFlags));
Dianne Hackborndf89e652011-10-06 22:35:11 -07005731 }
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08005732 if (mLastFocusNeedsMenu) {
5733 pw.print(prefix); pw.print("mLastFocusNeedsMenu=");
5734 pw.println(mLastFocusNeedsMenu);
5735 }
Jeff Browna20dda42014-05-27 20:57:24 -07005736 pw.print(prefix); pw.print("mWakeGestureEnabledSetting=");
5737 pw.println(mWakeGestureEnabledSetting);
5738
Jeff Brownbcdfc622014-03-06 19:13:04 -08005739 pw.print(prefix); pw.print("mSupportAutoRotation="); pw.println(mSupportAutoRotation);
Daniel Sandler6396c722013-04-16 20:19:09 -04005740 pw.print(prefix); pw.print("mUiMode="); pw.print(mUiMode);
5741 pw.print(" mDockMode="); pw.print(mDockMode);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005742 pw.print(" mCarDockRotation="); pw.print(mCarDockRotation);
5743 pw.print(" mDeskDockRotation="); pw.println(mDeskDockRotation);
5744 pw.print(prefix); pw.print("mUserRotationMode="); pw.print(mUserRotationMode);
5745 pw.print(" mUserRotation="); pw.print(mUserRotation);
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005746 pw.print(" mAllowAllRotations="); pw.println(mAllowAllRotations);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07005747 pw.print(prefix); pw.print("mCurrentAppOrientation="); pw.println(mCurrentAppOrientation);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005748 pw.print(prefix); pw.print("mCarDockEnablesAccelerometer=");
5749 pw.print(mCarDockEnablesAccelerometer);
5750 pw.print(" mDeskDockEnablesAccelerometer=");
5751 pw.println(mDeskDockEnablesAccelerometer);
5752 pw.print(prefix); pw.print("mLidKeyboardAccessibility=");
5753 pw.print(mLidKeyboardAccessibility);
5754 pw.print(" mLidNavigationAccessibility="); pw.print(mLidNavigationAccessibility);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07005755 pw.print(" mLidControlsSleep="); pw.println(mLidControlsSleep);
Jeff Brown6d8fd272014-05-20 21:24:38 -07005756 pw.print(prefix);
5757 pw.print("mShortPressOnPowerBehavior="); pw.print(mShortPressOnPowerBehavior);
5758 pw.print(" mLongPressOnPowerBehavior="); pw.println(mLongPressOnPowerBehavior);
5759 pw.print(prefix); pw.print("mHasSoftInput="); pw.println(mHasSoftInput);
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07005760 pw.print(prefix); pw.print("mScreenOnEarly="); pw.print(mScreenOnEarly);
5761 pw.print(" mScreenOnFully="); pw.print(mScreenOnFully);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07005762 pw.print(" mOrientationSensorEnabled="); pw.println(mOrientationSensorEnabled);
Dianne Hackbornc652de82013-02-15 16:32:56 -08005763 pw.print(prefix); pw.print("mOverscanScreen=("); pw.print(mOverscanScreenLeft);
5764 pw.print(","); pw.print(mOverscanScreenTop);
5765 pw.print(") "); pw.print(mOverscanScreenWidth);
5766 pw.print("x"); pw.println(mOverscanScreenHeight);
5767 if (mOverscanLeft != 0 || mOverscanTop != 0
5768 || mOverscanRight != 0 || mOverscanBottom != 0) {
5769 pw.print(prefix); pw.print("mOverscan left="); pw.print(mOverscanLeft);
5770 pw.print(" top="); pw.print(mOverscanTop);
5771 pw.print(" right="); pw.print(mOverscanRight);
5772 pw.print(" bottom="); pw.println(mOverscanBottom);
5773 }
Dianne Hackborn313440842013-02-19 19:22:59 -08005774 pw.print(prefix); pw.print("mRestrictedOverscanScreen=(");
5775 pw.print(mRestrictedOverscanScreenLeft);
5776 pw.print(","); pw.print(mRestrictedOverscanScreenTop);
5777 pw.print(") "); pw.print(mRestrictedOverscanScreenWidth);
5778 pw.print("x"); pw.println(mRestrictedOverscanScreenHeight);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005779 pw.print(prefix); pw.print("mUnrestrictedScreen=("); pw.print(mUnrestrictedScreenLeft);
5780 pw.print(","); pw.print(mUnrestrictedScreenTop);
5781 pw.print(") "); pw.print(mUnrestrictedScreenWidth);
5782 pw.print("x"); pw.println(mUnrestrictedScreenHeight);
5783 pw.print(prefix); pw.print("mRestrictedScreen=("); pw.print(mRestrictedScreenLeft);
5784 pw.print(","); pw.print(mRestrictedScreenTop);
5785 pw.print(") "); pw.print(mRestrictedScreenWidth);
5786 pw.print("x"); pw.println(mRestrictedScreenHeight);
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07005787 pw.print(prefix); pw.print("mStableFullscreen=("); pw.print(mStableFullscreenLeft);
5788 pw.print(","); pw.print(mStableFullscreenTop);
5789 pw.print(")-("); pw.print(mStableFullscreenRight);
5790 pw.print(","); pw.print(mStableFullscreenBottom); pw.println(")");
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07005791 pw.print(prefix); pw.print("mStable=("); pw.print(mStableLeft);
5792 pw.print(","); pw.print(mStableTop);
5793 pw.print(")-("); pw.print(mStableRight);
5794 pw.print(","); pw.print(mStableBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07005795 pw.print(prefix); pw.print("mSystem=("); pw.print(mSystemLeft);
5796 pw.print(","); pw.print(mSystemTop);
5797 pw.print(")-("); pw.print(mSystemRight);
5798 pw.print(","); pw.print(mSystemBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005799 pw.print(prefix); pw.print("mCur=("); pw.print(mCurLeft);
5800 pw.print(","); pw.print(mCurTop);
5801 pw.print(")-("); pw.print(mCurRight);
5802 pw.print(","); pw.print(mCurBottom); pw.println(")");
5803 pw.print(prefix); pw.print("mContent=("); pw.print(mContentLeft);
5804 pw.print(","); pw.print(mContentTop);
5805 pw.print(")-("); pw.print(mContentRight);
5806 pw.print(","); pw.print(mContentBottom); pw.println(")");
Dianne Hackborne30e02f2014-05-27 18:24:45 -07005807 pw.print(prefix); pw.print("mVoiceContent=("); pw.print(mVoiceContentLeft);
5808 pw.print(","); pw.print(mVoiceContentTop);
5809 pw.print(")-("); pw.print(mVoiceContentRight);
5810 pw.print(","); pw.print(mVoiceContentBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005811 pw.print(prefix); pw.print("mDock=("); pw.print(mDockLeft);
5812 pw.print(","); pw.print(mDockTop);
5813 pw.print(")-("); pw.print(mDockRight);
5814 pw.print(","); pw.print(mDockBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07005815 pw.print(prefix); pw.print("mDockLayer="); pw.print(mDockLayer);
5816 pw.print(" mStatusBarLayer="); pw.println(mStatusBarLayer);
Dianne Hackborn7ad44382012-10-18 17:46:00 -07005817 pw.print(prefix); pw.print("mShowingLockscreen="); pw.print(mShowingLockscreen);
5818 pw.print(" mShowingDream="); pw.print(mShowingDream);
5819 pw.print(" mDreamingLockscreen="); pw.println(mDreamingLockscreen);
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07005820 if (mLastInputMethodWindow != null) {
5821 pw.print(prefix); pw.print("mLastInputMethodWindow=");
5822 pw.println(mLastInputMethodWindow);
5823 }
5824 if (mLastInputMethodTargetWindow != null) {
5825 pw.print(prefix); pw.print("mLastInputMethodTargetWindow=");
5826 pw.println(mLastInputMethodTargetWindow);
5827 }
5828 if (mStatusBar != null) {
5829 pw.print(prefix); pw.print("mStatusBar=");
5830 pw.println(mStatusBar);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01005831 pw.print(prefix); pw.print("isStatusBarKeyguard=");
5832 pw.print(isStatusBarKeyguard());
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07005833 }
5834 if (mNavigationBar != null) {
5835 pw.print(prefix); pw.print("mNavigationBar=");
5836 pw.println(mNavigationBar);
5837 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07005838 if (mFocusedWindow != null) {
5839 pw.print(prefix); pw.print("mFocusedWindow=");
5840 pw.println(mFocusedWindow);
5841 }
5842 if (mFocusedApp != null) {
5843 pw.print(prefix); pw.print("mFocusedApp=");
5844 pw.println(mFocusedApp);
5845 }
5846 if (mWinDismissingKeyguard != null) {
5847 pw.print(prefix); pw.print("mWinDismissingKeyguard=");
5848 pw.println(mWinDismissingKeyguard);
5849 }
5850 if (mTopFullscreenOpaqueWindowState != null) {
5851 pw.print(prefix); pw.print("mTopFullscreenOpaqueWindowState=");
5852 pw.println(mTopFullscreenOpaqueWindowState);
5853 }
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08005854 if (mForcingShowNavBar) {
5855 pw.print(prefix); pw.print("mForcingShowNavBar=");
5856 pw.println(mForcingShowNavBar); pw.print( "mForcingShowNavBarLayer=");
5857 pw.println(mForcingShowNavBarLayer);
5858 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07005859 pw.print(prefix); pw.print("mTopIsFullscreen="); pw.print(mTopIsFullscreen);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005860 pw.print(" mHideLockScreen="); pw.println(mHideLockScreen);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07005861 pw.print(prefix); pw.print("mForceStatusBar="); pw.print(mForceStatusBar);
5862 pw.print(" mForceStatusBarFromKeyguard=");
5863 pw.println(mForceStatusBarFromKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005864 pw.print(prefix); pw.print("mDismissKeyguard="); pw.print(mDismissKeyguard);
Craig Mautnerad09bcc2012-10-08 13:33:11 -07005865 pw.print(" mWinDismissingKeyguard="); pw.print(mWinDismissingKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005866 pw.print(" mHomePressed="); pw.println(mHomePressed);
5867 pw.print(prefix); pw.print("mAllowLockscreenWhenOn="); pw.print(mAllowLockscreenWhenOn);
5868 pw.print(" mLockScreenTimeout="); pw.print(mLockScreenTimeout);
5869 pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive);
5870 pw.print(prefix); pw.print("mEndcallBehavior="); pw.print(mEndcallBehavior);
5871 pw.print(" mIncallPowerBehavior="); pw.print(mIncallPowerBehavior);
5872 pw.print(" mLongPressOnHomeBehavior="); pw.println(mLongPressOnHomeBehavior);
5873 pw.print(prefix); pw.print("mLandscapeRotation="); pw.print(mLandscapeRotation);
5874 pw.print(" mSeascapeRotation="); pw.println(mSeascapeRotation);
5875 pw.print(prefix); pw.print("mPortraitRotation="); pw.print(mPortraitRotation);
5876 pw.print(" mUpsideDownRotation="); pw.println(mUpsideDownRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07005877 pw.print(prefix); pw.print("mDemoHdmiRotation="); pw.print(mDemoHdmiRotation);
5878 pw.print(" mDemoHdmiRotationLock="); pw.println(mDemoHdmiRotationLock);
5879 pw.print(prefix); pw.print("mUndockedHdmiRotation="); pw.println(mUndockedHdmiRotation);
Jeff Brown600f0032014-05-22 17:06:00 -07005880
Tim Kilbournd7c0c2e2014-05-29 16:08:10 -07005881 mGlobalKeyManager.dump(prefix, pw);
John Spurlock27735a42013-08-14 17:57:38 -04005882 mStatusBarController.dump(pw, prefix);
5883 mNavigationBarController.dump(pw, prefix);
John Spurlockc6d1c602014-01-17 15:22:06 -05005884 PolicyControl.dump(prefix, pw);
Jeff Brown600f0032014-05-22 17:06:00 -07005885
Jeff Browna20dda42014-05-27 20:57:24 -07005886 if (mWakeGestureListener != null) {
5887 mWakeGestureListener.dump(pw, prefix);
5888 }
Jeff Brown600f0032014-05-22 17:06:00 -07005889 if (mOrientationListener != null) {
5890 mOrientationListener.dump(pw, prefix);
5891 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005892 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005893}