blob: c23468d9627a502b7f4f02914df1ce28a2d82983 [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;
Michael Wright3818c922014-09-02 13:59:07 -070069import android.provider.MediaStore;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080070import android.provider.Settings;
Jose Lima9546b202014-07-02 17:21:51 -070071import android.service.dreams.DreamManagerInternal;
John Spurlockc8b46ca2013-04-08 12:59:26 -040072import android.service.dreams.DreamService;
73import android.service.dreams.IDreamManager;
Michael Wrightdc63f7b2014-08-21 19:05:21 -070074import android.speech.RecognizerIntent;
Santos Cordon9eb45932014-06-27 12:28:43 -070075import android.telecomm.TelecommManager;
Dianne Hackborn81e56d52011-05-26 00:55:58 -070076import android.util.DisplayMetrics;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080077import android.util.EventLog;
78import android.util.Log;
Jeff Browna41ca772010-08-11 14:46:32 -070079import android.util.Slog;
Jeff Brown6651a632011-11-28 12:59:11 -080080import android.util.SparseArray;
Dianne Hackbornf87d1962012-04-04 12:48:24 -070081import android.view.Display;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080082import android.view.Gravity;
83import android.view.HapticFeedbackConstants;
Dianne Hackborne0f085d2011-11-30 18:41:15 -080084import android.view.IApplicationToken;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080085import android.view.IWindowManager;
Jeff Browna41ca772010-08-11 14:46:32 -070086import android.view.InputChannel;
Jeff Brown4d396052010-10-29 21:50:21 -070087import android.view.InputDevice;
Jeff Brown4952dfd2011-11-30 19:23:22 -080088import android.view.InputEvent;
Jeff Brown32cbc38552011-12-01 14:01:49 -080089import android.view.InputEventReceiver;
Jeff Brown6b53e8d2010-11-10 16:03:06 -080090import android.view.KeyCharacterMap;
Craig Mautnerae446592012-12-06 19:05:05 -080091import android.view.KeyCharacterMap.FallbackAction;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080092import android.view.KeyEvent;
93import android.view.MotionEvent;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080094import android.view.Surface;
95import android.view.View;
96import android.view.ViewConfiguration;
97import android.view.Window;
98import android.view.WindowManager;
Craig Mautnerae446592012-12-06 19:05:05 -080099import android.view.WindowManagerGlobal;
Craig Mautner8a0da012014-05-31 15:13:37 -0700100import android.view.WindowManagerInternal;
Craig Mautnerae446592012-12-06 19:05:05 -0800101import android.view.WindowManagerPolicy;
Craig Mautnerae446592012-12-06 19:05:05 -0800102import android.view.accessibility.AccessibilityEvent;
Svetoslav8e3feb12014-02-24 13:46:47 -0800103import android.view.accessibility.AccessibilityManager;
Jorim Jaggi76a16232014-08-08 17:00:47 +0200104import android.view.animation.AlphaAnimation;
Craig Mautnerae446592012-12-06 19:05:05 -0800105import android.view.animation.Animation;
Jorim Jaggi76a16232014-08-08 17:00:47 +0200106import android.view.animation.AnimationSet;
Craig Mautnerae446592012-12-06 19:05:05 -0800107import android.view.animation.AnimationUtils;
108
109import com.android.internal.R;
Jorim Jaggi380ecb82014-03-14 17:25:20 +0100110import com.android.internal.policy.IKeyguardService;
111import com.android.internal.policy.IKeyguardServiceConstants;
Craig Mautnerae446592012-12-06 19:05:05 -0800112import com.android.internal.policy.PolicyManager;
Jim Miller5ecd8112013-01-09 18:50:26 -0800113import com.android.internal.policy.impl.keyguard.KeyguardServiceDelegate;
Craig Mautner8a0da012014-05-31 15:13:37 -0700114import com.android.internal.policy.impl.keyguard.KeyguardServiceDelegate.ShowListener;
Craig Mautnerae446592012-12-06 19:05:05 -0800115import com.android.internal.statusbar.IStatusBarService;
Craig Mautnerae446592012-12-06 19:05:05 -0800116import com.android.internal.widget.PointerLocationView;
Craig Mautner8a0da012014-05-31 15:13:37 -0700117import com.android.server.LocalServices;
Craig Mautnerae446592012-12-06 19:05:05 -0800118
119import java.io.File;
120import java.io.FileReader;
121import java.io.IOException;
122import java.io.PrintWriter;
Craig Mautner8a0da012014-05-31 15:13:37 -0700123import java.util.ArrayList;
Craig Mautner2bc789b2014-03-19 19:48:38 -0700124import java.util.HashSet;
RoboErik3c45c292014-07-08 16:47:31 -0700125import java.util.List;
Craig Mautnerae446592012-12-06 19:05:05 -0800126
Dianne Hackbornc652de82013-02-15 16:32:56 -0800127import static android.view.WindowManager.LayoutParams.*;
Jeff Brownac143512012-04-05 18:57:33 -0700128import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_ABSENT;
129import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_OPEN;
130import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_CLOSED;
Michael Wright3818c922014-09-02 13:59:07 -0700131import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVER_ABSENT;
132import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_UNCOVERED;
133import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVERED;
Dianne Hackborn08743722009-12-21 12:16:51 -0800134
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800135/**
The Android Open Source Project0727d222009-03-11 12:11:58 -0700136 * WindowManagerPolicy implementation for the Android phone UI. This
137 * introduces a new method suffix, Lp, for an internal lock of the
138 * PhoneWindowManager. This is used to protect some internal state, and
John Spurlock04db1762013-05-13 12:46:41 -0400139 * 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 -0700140 * of both of those when held.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800141 */
142public class PhoneWindowManager implements WindowManagerPolicy {
143 static final String TAG = "WindowManager";
144 static final boolean DEBUG = false;
Joe Onorato43a17652011-04-06 19:22:23 -0700145 static final boolean localLOGV = false;
The Android Open Source Project11267662009-03-18 17:39:47 -0700146 static final boolean DEBUG_LAYOUT = false;
Jeff Brown40013652012-05-16 21:22:36 -0700147 static final boolean DEBUG_INPUT = false;
Craig Mautner6fbda632012-07-03 09:26:39 -0700148 static final boolean DEBUG_STARTING_WINDOW = false;
Craig Mautner8a0da012014-05-31 15:13:37 -0700149 static final boolean DEBUG_WAKEUP = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800150 static final boolean SHOW_STARTING_ANIMATIONS = true;
151 static final boolean SHOW_PROCESSES_ON_ALT_MENU = false;
Joe Onoratod208e702010-10-08 16:22:43 -0400152
Daniel Sandler6396c722013-04-16 20:19:09 -0400153 // Whether to allow dock apps with METADATA_DOCK_HOME to temporarily take over the Home key.
154 // No longer recommended for desk docks; still useful in car docks.
155 static final boolean ENABLE_CAR_DOCK_HOME_CAPTURE = true;
156 static final boolean ENABLE_DESK_DOCK_HOME_CAPTURE = false;
157
Jeff Brown6d8fd272014-05-20 21:24:38 -0700158 static final int SHORT_PRESS_POWER_NOTHING = 0;
159 static final int SHORT_PRESS_POWER_GO_TO_SLEEP = 1;
160 static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP = 2;
161 static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME = 3;
162
Joe Onoratod208e702010-10-08 16:22:43 -0400163 static final int LONG_PRESS_POWER_NOTHING = 0;
164 static final int LONG_PRESS_POWER_GLOBAL_ACTIONS = 1;
165 static final int LONG_PRESS_POWER_SHUT_OFF = 2;
Jeff Brown9a538ee2012-08-20 14:56:57 -0700166 static final int LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM = 3;
Michael Jurka3b1fc472011-06-13 10:54:40 -0700167
168 // These need to match the documentation/constant in
169 // core/res/res/values/config.xml
Joe Onorato46b0d682010-11-22 17:37:27 -0800170 static final int LONG_PRESS_HOME_NOTHING = 0;
Michael Wrightc9ebea72013-01-16 19:25:02 -0800171 static final int LONG_PRESS_HOME_RECENT_SYSTEM_UI = 1;
Jeff Browncaca8812013-05-09 13:34:33 -0700172 static final int LONG_PRESS_HOME_ASSIST = 2;
173
174 static final int DOUBLE_TAP_HOME_NOTHING = 0;
175 static final int DOUBLE_TAP_HOME_RECENT_SYSTEM_UI = 1;
Joe Onorato46b0d682010-11-22 17:37:27 -0800176
Dianne Hackborn5cb8d792009-05-21 17:34:15 -0700177 static final int APPLICATION_MEDIA_SUBLAYER = -2;
178 static final int APPLICATION_MEDIA_OVERLAY_SUBLAYER = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800179 static final int APPLICATION_PANEL_SUBLAYER = 1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800180 static final int APPLICATION_SUB_PANEL_SUBLAYER = 2;
Craig Mautner88400d32012-09-30 12:35:45 -0700181
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800182 static public final String SYSTEM_DIALOG_REASON_KEY = "reason";
183 static public final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions";
184 static public final String SYSTEM_DIALOG_REASON_RECENT_APPS = "recentapps";
Joe Onoratof275f0c2009-11-24 16:11:13 -0500185 static public final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey";
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700186 static public final String SYSTEM_DIALOG_REASON_ASSIST = "assist";
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800187
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700188 /**
189 * These are the system UI flags that, when changing, can cause the layout
190 * of the screen to change.
191 */
192 static final int SYSTEM_UI_CHANGING_LAYOUT =
John Spurlocke1f366f2013-08-05 12:22:40 -0400193 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlock7f4820a2013-10-08 12:54:35 -0400194 | View.SYSTEM_UI_FLAG_FULLSCREEN
195 | View.STATUS_BAR_TRANSLUCENT
Adrian Roosea562512014-05-05 13:33:03 +0200196 | View.NAVIGATION_BAR_TRANSLUCENT
197 | View.SYSTEM_UI_TRANSPARENT;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700198
John Spurlock7b414672014-07-18 13:02:39 -0400199 private static final AudioAttributes VIBRATION_ATTRIBUTES = new AudioAttributes.Builder()
200 .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
201 .setUsage(AudioAttributes.USAGE_ASSISTANCE_SONIFICATION)
202 .build();
203
Jim Miller5ecd8112013-01-09 18:50:26 -0800204 /**
205 * Keyguard stuff
206 */
207 private WindowState mKeyguardScrim;
Jorim Jaggi380ecb82014-03-14 17:25:20 +0100208 private boolean mKeyguardHidden;
Jorim Jaggicff0acb2014-03-31 16:35:15 +0200209 private boolean mKeyguardDrawn;
Jim Miller5ecd8112013-01-09 18:50:26 -0800210
Jeff Brown6651a632011-11-28 12:59:11 -0800211 /* Table of Application Launch keys. Maps from key codes to intent categories.
212 *
213 * These are special keys that are used to launch particular kinds of applications,
214 * such as a web browser. HID defines nearly a hundred of them in the Consumer (0x0C)
215 * usage page. We don't support quite that many yet...
216 */
217 static SparseArray<String> sApplicationLaunchKeyCategories;
218 static {
219 sApplicationLaunchKeyCategories = new SparseArray<String>();
220 sApplicationLaunchKeyCategories.append(
221 KeyEvent.KEYCODE_EXPLORER, Intent.CATEGORY_APP_BROWSER);
222 sApplicationLaunchKeyCategories.append(
223 KeyEvent.KEYCODE_ENVELOPE, Intent.CATEGORY_APP_EMAIL);
224 sApplicationLaunchKeyCategories.append(
225 KeyEvent.KEYCODE_CONTACTS, Intent.CATEGORY_APP_CONTACTS);
226 sApplicationLaunchKeyCategories.append(
227 KeyEvent.KEYCODE_CALENDAR, Intent.CATEGORY_APP_CALENDAR);
228 sApplicationLaunchKeyCategories.append(
229 KeyEvent.KEYCODE_MUSIC, Intent.CATEGORY_APP_MUSIC);
230 sApplicationLaunchKeyCategories.append(
231 KeyEvent.KEYCODE_CALCULATOR, Intent.CATEGORY_APP_CALCULATOR);
232 }
233
Dianne Hackborndf89e652011-10-06 22:35:11 -0700234 /**
235 * Lock protecting internal state. Must not call out into window
236 * manager with lock held. (This lock will be acquired in places
237 * where the window manager is calling in with its own lock held.)
238 */
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800239 private final Object mLock = new Object();
Dianne Hackborndf89e652011-10-06 22:35:11 -0700240
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800241 Context mContext;
242 IWindowManager mWindowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700243 WindowManagerFuncs mWindowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -0700244 WindowManagerInternal mWindowManagerInternal;
Jeff Brown96307042012-07-27 15:51:34 -0700245 PowerManager mPowerManager;
Jose Lima9546b202014-07-02 17:21:51 -0700246 DreamManagerInternal mDreamManagerInternal;
Joe Onorato93056472010-09-10 10:30:46 -0400247 IStatusBarService mStatusBarService;
Jeff Browncaca8812013-05-09 13:34:33 -0700248 boolean mPreloadedRecentApps;
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700249 final Object mServiceAquireLock = new Object();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800250 Vibrator mVibrator; // Vibrator for giving feedback of orientation changes
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700251 SearchManager mSearchManager;
Svetoslav8e3feb12014-02-24 13:46:47 -0800252 AccessibilityManager mAccessibilityManager;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800253
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700254 // Vibrator pattern for haptic feedback of a long press.
255 long[] mLongPressVibePattern;
Craig Mautner88400d32012-09-30 12:35:45 -0700256
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700257 // Vibrator pattern for haptic feedback of virtual key press.
258 long[] mVirtualKeyVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700259
Amith Yamasanic33cb712010-02-10 15:21:49 -0800260 // Vibrator pattern for a short vibration.
261 long[] mKeyboardTapVibePattern;
262
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -0700263 // Vibrator pattern for a short vibration when tapping on an hour/minute tick of a Clock.
264 long[] mClockTickVibePattern;
265
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -0700266 // Vibrator pattern for a short vibration when tapping on a day/month/year date of a Calendar.
267 long[] mCalendarDateVibePattern;
268
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700269 // Vibrator pattern for haptic feedback during boot when safe mode is disabled.
270 long[] mSafeModeDisabledVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700271
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700272 // Vibrator pattern for haptic feedback during boot when safe mode is enabled.
273 long[] mSafeModeEnabledVibePattern;
Romain Guy8154cd32010-03-29 14:41:15 -0700274
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800275 /** If true, hitting shift & menu will broadcast Intent.ACTION_BUG_REPORT */
276 boolean mEnableShiftMenuBugReports = false;
Mike Lockwoodd747dc82011-09-13 16:28:22 -0400277
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800278 boolean mSafeMode;
279 WindowState mStatusBar = null;
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700280 int mStatusBarHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400281 WindowState mNavigationBar = null;
Daniel Sandler36412a72011-08-04 09:35:13 -0400282 boolean mHasNavigationBar = false;
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700283 boolean mCanHideNavigationBar = false;
Daniel Sandler4a066c52012-04-20 14:49:13 -0400284 boolean mNavigationBarCanMove = false; // can the navigation bar ever move to the side?
285 boolean mNavigationBarOnBottom = true; // is the navigation bar on the bottom *right now*?
286 int[] mNavigationBarHeightForRotation = new int[4];
287 int[] mNavigationBarWidthForRotation = new int[4];
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400288
Craig Mautnera631d492014-08-05 15:16:01 -0700289 boolean mBootMessageNeedsHiding;
Jim Miller5ecd8112013-01-09 18:50:26 -0800290 KeyguardServiceDelegate mKeyguardDelegate;
Craig Mautner8a0da012014-05-31 15:13:37 -0700291 // The following are only accessed on the mHandler thread.
292 boolean mKeyguardDrawComplete;
293 boolean mWindowManagerDrawComplete;
Craig Mautner13f6ea72014-06-23 14:57:02 -0700294 ScreenOnListener mScreenOnListener;
295 final Runnable mWindowManagerDrawCallback = new Runnable() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700296 @Override
Craig Mautner13f6ea72014-06-23 14:57:02 -0700297 public void run() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700298 if (DEBUG_WAKEUP) Slog.i(TAG, "All windows ready for display!");
299 mHandler.sendEmptyMessage(MSG_WINDOW_MANAGER_DRAWN_COMPLETE);
300 }
301 };
302 final ShowListener mKeyguardDelegateCallback = new ShowListener() {
303 @Override
304 public void onShown(IBinder windowToken) {
305 if (DEBUG_WAKEUP) Slog.d(TAG, "mKeyguardDelegate.ShowListener.onShown.");
306 mHandler.sendEmptyMessage(MSG_KEYGUARD_DRAWN_COMPLETE);
307 }
308 };
309
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800310 GlobalActions mGlobalActions;
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700311 volatile boolean mPowerKeyHandled; // accessed from input reader and handler thread
312 boolean mPendingPowerKeyUpCanceled;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800313 Handler mHandler;
satok1bc0a492012-04-25 22:47:12 +0900314 WindowState mLastInputMethodWindow = null;
315 WindowState mLastInputMethodTargetWindow = null;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800316
Winson Chungd42a6cf2014-06-03 16:24:04 -0700317 boolean mRecentsVisible;
Winson Chung1e8d71b2014-05-16 17:05:22 -0700318 int mRecentAppsHeldModifiers;
Jeff Browncf39bdf2012-05-18 14:41:19 -0700319 boolean mLanguageSwitchKeyPressed;
Jeff Brown68b909d2011-12-07 16:36:01 -0800320
Jeff Brown2e7760e2012-04-11 15:14:55 -0700321 int mLidState = LID_ABSENT;
Michael Wright3818c922014-09-02 13:59:07 -0700322 int mCameraLensCoverState = CAMERA_LENS_COVER_ABSENT;
Jeff Browndaa37532012-05-01 15:54:03 -0700323 boolean mHaveBuiltInKeyboard;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800324
Dianne Hackbornc777e072010-02-12 13:07:59 -0800325 boolean mSystemReady;
Dianne Hackbornba24e4d2011-09-01 11:17:06 -0700326 boolean mSystemBooted;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800327 boolean mHdmiPlugged;
Jeff Brown4f5fa282014-06-12 19:19:15 -0700328 IUiModeManager mUiModeManager;
Daniel Sandler6396c722013-04-16 20:19:09 -0400329 int mUiMode;
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700330 int mDockMode = Intent.EXTRA_DOCK_STATE_UNDOCKED;
Mike Lockwood1753f7f2009-08-24 14:49:07 -0700331 int mLidOpenRotation;
Mike Lockwood2d1efbd2009-09-16 12:15:53 -0400332 int mCarDockRotation;
333 int mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -0700334 int mUndockedHdmiRotation;
335 int mDemoHdmiRotation;
336 boolean mDemoHdmiRotationLock;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400337
Jeff Browna20dda42014-05-27 20:57:24 -0700338 boolean mWakeGestureEnabledSetting;
339 MyWakeGestureListener mWakeGestureListener;
340
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700341 // Default display does not rotate, apps that require non-default orientation will have to
342 // have the orientation emulated.
343 private boolean mForceDefaultOrientation = false;
344
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400345 int mUserRotationMode = WindowManagerPolicy.USER_ROTATION_FREE;
346 int mUserRotation = Surface.ROTATION_0;
Jeff Brown207673cd2012-06-05 17:47:11 -0700347 boolean mAccelerometerDefault;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400348
Jeff Brownbcdfc622014-03-06 19:13:04 -0800349 boolean mSupportAutoRotation;
Jeff Brownd3187e32011-09-21 19:26:44 -0700350 int mAllowAllRotations = -1;
Mike Lockwoode9867d22009-09-20 01:59:02 -0400351 boolean mCarDockEnablesAccelerometer;
352 boolean mDeskDockEnablesAccelerometer;
Dianne Hackborn2862fff2009-09-15 22:56:29 -0700353 int mLidKeyboardAccessibility;
354 int mLidNavigationAccessibility;
Jeff Brownc458ce92012-04-30 14:58:40 -0700355 boolean mLidControlsSleep;
Jeff Brown6d8fd272014-05-20 21:24:38 -0700356 int mShortPressOnPowerBehavior = -1;
Joe Onoratod208e702010-10-08 16:22:43 -0400357 int mLongPressOnPowerBehavior = -1;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -0700358 boolean mScreenOnEarly = false;
359 boolean mScreenOnFully = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800360 boolean mOrientationSensorEnabled = false;
361 int mCurrentAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800362 boolean mHasSoftInput = false;
Daniel Sandlerdd73ee42013-10-11 22:19:59 -0400363 boolean mTranslucentDecorEnabled = true;
Craig Mautner967212c2013-04-13 21:10:58 -0700364
Jeff Brown70825162012-03-28 17:27:48 -0700365 int mPointerLocationMode = 0; // guarded by mLock
Joe Onorato664644d2011-01-23 17:53:23 -0800366
367 // The last window we were told about in focusChanged.
368 WindowState mFocusedWindow;
Dianne Hackborne0f085d2011-11-30 18:41:15 -0800369 IApplicationToken mFocusedApp;
Joe Onorato664644d2011-01-23 17:53:23 -0800370
Jeff Brown70825162012-03-28 17:27:48 -0700371 PointerLocationView mPointerLocationView;
Jeff Brown32cbc38552011-12-01 14:01:49 -0800372
Dianne Hackbornc652de82013-02-15 16:32:56 -0800373 // The current size of the screen; really; extends into the overscan area of
374 // the screen and doesn't account for any system elements like the status bar.
375 int mOverscanScreenLeft, mOverscanScreenTop;
376 int mOverscanScreenWidth, mOverscanScreenHeight;
377 // The current visible size of the screen; really; (ir)regardless of whether the status
378 // bar can be hidden but not extending into the overscan area.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800379 int mUnrestrictedScreenLeft, mUnrestrictedScreenTop;
380 int mUnrestrictedScreenWidth, mUnrestrictedScreenHeight;
Dianne Hackborn313440842013-02-19 19:22:59 -0800381 // Like mOverscanScreen*, but allowed to move into the overscan region where appropriate.
382 int mRestrictedOverscanScreenLeft, mRestrictedOverscanScreenTop;
383 int mRestrictedOverscanScreenWidth, mRestrictedOverscanScreenHeight;
Dianne Hackborn82de1ae2010-10-28 11:28:39 -0700384 // The current size of the screen; these may be different than (0,0)-(dw,dh)
385 // if the status bar can't be hidden; in that case it effectively carves out
386 // that area of the display from all other windows.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800387 int mRestrictedScreenLeft, mRestrictedScreenTop;
388 int mRestrictedScreenWidth, mRestrictedScreenHeight;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700389 // During layout, the current screen borders accounting for any currently
390 // visible system UI elements.
391 int mSystemLeft, mSystemTop, mSystemRight, mSystemBottom;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700392 // For applications requesting stable content insets, these are them.
393 int mStableLeft, mStableTop, mStableRight, mStableBottom;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -0700394 // For applications requesting stable content insets but have also set the
395 // fullscreen window flag, these are the stable dimensions without the status bar.
396 int mStableFullscreenLeft, mStableFullscreenTop;
397 int mStableFullscreenRight, mStableFullscreenBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800398 // During layout, the current screen borders with all outer decoration
399 // (status bar, input method dock) accounted for.
400 int mCurLeft, mCurTop, mCurRight, mCurBottom;
401 // During layout, the frame in which 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. This is usually
404 // the same as mCur*, but may be larger if the screen decor has supplied
405 // content insets.
406 int mContentLeft, mContentTop, mContentRight, mContentBottom;
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700407 // During layout, the frame in which voice content should be displayed
408 // to the user, accounting for all screen decoration except for any
409 // space they deem as available for other content.
410 int mVoiceContentLeft, mVoiceContentTop, mVoiceContentRight, mVoiceContentBottom;
Dianne Hackborn8e11ef02010-11-18 19:47:42 -0800411 // During layout, the current screen borders along which input method
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800412 // windows are placed.
413 int mDockLeft, mDockTop, mDockRight, mDockBottom;
414 // During layout, the layer at which the doc window is placed.
415 int mDockLayer;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700416 // During layout, this is the layer of the status bar.
417 int mStatusBarLayer;
Dianne Hackborne26ab702011-10-16 13:21:33 -0700418 int mLastSystemUiFlags;
419 // Bits that we are in the process of clearing, so we want to prevent
420 // them from being set by applications until everything has been updated
421 // to have them clear.
422 int mResettingSystemUiFlags = 0;
423 // Bits that we are currently always keeping cleared.
424 int mForceClearedSystemUiFlags = 0;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -0800425 // What we last reported to system UI about whether the compatibility
426 // menu needs to be displayed.
427 boolean mLastFocusNeedsMenu = false;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700428
429 FakeWindow mHideNavFakeWindow = null;
430
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800431 static final Rect mTmpParentFrame = new Rect();
432 static final Rect mTmpDisplayFrame = new Rect();
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800433 static final Rect mTmpOverscanFrame = new Rect();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800434 static final Rect mTmpContentFrame = new Rect();
435 static final Rect mTmpVisibleFrame = new Rect();
John Spurlock46646232013-09-30 22:32:42 -0400436 static final Rect mTmpDecorFrame = new Rect();
Adrian Roosfa104232014-06-20 16:10:14 -0700437 static final Rect mTmpStableFrame = new Rect();
Dianne Hackborn1f903c32011-09-13 19:18:06 -0700438 static final Rect mTmpNavigationFrame = new Rect();
Craig Mautner967212c2013-04-13 21:10:58 -0700439
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800440 WindowState mTopFullscreenOpaqueWindowState;
Craig Mautner2bc789b2014-03-19 19:48:38 -0700441 HashSet<IApplicationToken> mAppsToBeHidden = new HashSet<IApplicationToken>();
Joe Onorato93056472010-09-10 10:30:46 -0400442 boolean mTopIsFullscreen;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800443 boolean mForceStatusBar;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -0700444 boolean mForceStatusBarFromKeyguard;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700445 boolean mHideLockScreen;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -0800446 boolean mForcingShowNavBar;
447 int mForcingShowNavBarLayer;
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700448
449 // States of keyguard dismiss.
450 private static final int DISMISS_KEYGUARD_NONE = 0; // Keyguard not being dismissed.
451 private static final int DISMISS_KEYGUARD_START = 1; // Keyguard needs to be dismissed.
452 private static final int DISMISS_KEYGUARD_CONTINUE = 2; // Keyguard has been dismissed.
453 int mDismissKeyguard = DISMISS_KEYGUARD_NONE;
454
455 /** The window that is currently dismissing the keyguard. Dismissing the keyguard must only
456 * be done once per window. */
457 private WindowState mWinDismissingKeyguard;
458
Craig Mautnerc9457fa2014-06-06 14:27:48 -0700459 /** The window that is currently showing "over" the keyguard. If there is an app window
460 * belonging to another app on top of this the keyguard shows. If there is a fullscreen
461 * app window under this, still dismiss the keyguard but don't show the app underneath. Show
462 * the wallpaper. */
463 private WindowState mWinShowWhenLocked;
464
Dianne Hackborn7ad44382012-10-18 17:46:00 -0700465 boolean mShowingLockscreen;
466 boolean mShowingDream;
467 boolean mDreamingLockscreen;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800468 boolean mHomePressed;
Jeff Browncaca8812013-05-09 13:34:33 -0700469 boolean mHomeConsumed;
470 boolean mHomeDoubleTapPending;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800471 Intent mHomeIntent;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700472 Intent mCarDockIntent;
473 Intent mDeskDockIntent;
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700474 boolean mSearchKeyShortcutPending;
475 boolean mConsumeSearchKeyUp;
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700476 boolean mAssistKeyLongPressed;
Michael Wright6a62e552014-06-03 19:19:48 -0700477 boolean mPendingMetaAction;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800478
Mike Lockwood28569302010-01-28 11:54:40 -0500479 // support for activating the lock screen while the screen is on
480 boolean mAllowLockscreenWhenOn;
481 int mLockScreenTimeout;
482 boolean mLockScreenTimerActive;
483
David Brownbaf8d092010-03-08 21:52:59 -0800484 // Behavior of ENDCALL Button. (See Settings.System.END_BUTTON_BEHAVIOR.)
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800485 int mEndcallBehavior;
David Brownbaf8d092010-03-08 21:52:59 -0800486
487 // Behavior of POWER button while in-call and screen on.
488 // (See Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR.)
489 int mIncallPowerBehavior;
490
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700491 Display mDisplay;
492
Dianne Hackborn9d132642011-04-21 17:26:39 -0700493 int mLandscapeRotation = 0; // default landscape rotation
494 int mSeascapeRotation = 0; // "other" landscape rotation, 180 degrees from mLandscapeRotation
495 int mPortraitRotation = 0; // default portrait rotation
496 int mUpsideDownRotation = 0; // "other" portrait rotation
Mitsuru Oshima831d0d92009-06-16 18:27:18 -0700497
Dianne Hackbornc652de82013-02-15 16:32:56 -0800498 int mOverscanLeft = 0;
499 int mOverscanTop = 0;
500 int mOverscanRight = 0;
501 int mOverscanBottom = 0;
502
Joe Onorato46b0d682010-11-22 17:37:27 -0800503 // What we do when the user long presses on home
Jeff Browncaca8812013-05-09 13:34:33 -0700504 private int mLongPressOnHomeBehavior;
505
506 // What we do when the user double-taps on home
507 private int mDoubleTapOnHomeBehavior;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800508
Winson Chung9112ec32011-06-27 13:15:32 -0700509 // Screenshot trigger states
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700510 // Time to volume and power must be pressed within this interval of each other.
511 private static final long SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS = 150;
Winson Chung1cea2f32012-10-08 20:42:01 -0700512 // Increase the chord delay when taking a screenshot from the keyguard
513 private static final float KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER = 2.5f;
Christopher Tatee90585f2012-03-05 18:56:25 -0800514 private boolean mScreenshotChordEnabled;
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700515 private boolean mVolumeDownKeyTriggered;
516 private long mVolumeDownKeyTime;
517 private boolean mVolumeDownKeyConsumedByScreenshotChord;
518 private boolean mVolumeUpKeyTriggered;
519 private boolean mPowerKeyTriggered;
520 private long mPowerKeyTime;
Winson Chung9112ec32011-06-27 13:15:32 -0700521
Michael Wrightb854e242013-02-05 17:54:02 -0800522 /* The number of steps between min and max brightness */
523 private static final int BRIGHTNESS_STEPS = 10;
524
Christopher Tate5e08af02012-09-21 17:17:22 -0700525 SettingsObserver mSettingsObserver;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800526 ShortcutManager mShortcutManager;
527 PowerManager.WakeLock mBroadcastWakeLock;
Jeff Brown40013652012-05-16 21:22:36 -0700528 boolean mHavePendingMediaKeyRepeatWithWakeLock;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800529
Craig Mautnerd625ab22013-09-06 13:40:31 -0700530 private int mCurrentUserId;
531
Justin Kohd378ad72013-04-01 12:18:26 -0700532 // Maps global key codes to the components that will handle them.
533 private GlobalKeyManager mGlobalKeyManager;
534
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700535 // Fallback actions by key code.
536 private final SparseArray<KeyCharacterMap.FallbackAction> mFallbackActions =
537 new SparseArray<KeyCharacterMap.FallbackAction>();
Jeff Brown49ed71d2010-12-06 17:13:33 -0800538
Jorim Jaggi76a16232014-08-08 17:00:47 +0200539 private final LogDecelerateInterpolator mLogDecelerateInterpolator
540 = new LogDecelerateInterpolator(100, 0);
541
Jeff Brown70825162012-03-28 17:27:48 -0700542 private static final int MSG_ENABLE_POINTER_LOCATION = 1;
543 private static final int MSG_DISABLE_POINTER_LOCATION = 2;
Jeff Brown40013652012-05-16 21:22:36 -0700544 private static final int MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK = 3;
545 private static final int MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK = 4;
Craig Mautner8a0da012014-05-31 15:13:37 -0700546 private static final int MSG_KEYGUARD_DRAWN_COMPLETE = 5;
547 private static final int MSG_KEYGUARD_DRAWN_TIMEOUT = 6;
548 private static final int MSG_WINDOW_MANAGER_DRAWN_COMPLETE = 7;
549 private static final int MSG_WAKING_UP = 8;
Craig Mautner84984fa2014-06-19 11:19:20 -0700550 private static final int MSG_DISPATCH_SHOW_RECENTS = 9;
Alan Viverettee34560b22014-07-10 14:50:06 -0700551 private static final int MSG_DISPATCH_SHOW_GLOBAL_ACTIONS = 10;
Craig Mautnera631d492014-08-05 15:16:01 -0700552 private static final int MSG_HIDE_BOOT_MESSAGE = 11;
Michael Wright869a67c2014-08-26 19:33:06 -0700553 private static final int MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK = 12;
Jeff Brown70825162012-03-28 17:27:48 -0700554
555 private class PolicyHandler extends Handler {
556 @Override
557 public void handleMessage(Message msg) {
558 switch (msg.what) {
559 case MSG_ENABLE_POINTER_LOCATION:
560 enablePointerLocation();
561 break;
562 case MSG_DISABLE_POINTER_LOCATION:
563 disablePointerLocation();
564 break;
Jeff Brown40013652012-05-16 21:22:36 -0700565 case MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK:
566 dispatchMediaKeyWithWakeLock((KeyEvent)msg.obj);
567 break;
568 case MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK:
569 dispatchMediaKeyRepeatWithWakeLock((KeyEvent)msg.obj);
570 break;
Craig Mautner84984fa2014-06-19 11:19:20 -0700571 case MSG_DISPATCH_SHOW_RECENTS:
572 showRecentApps(false);
573 break;
Alan Viverettee34560b22014-07-10 14:50:06 -0700574 case MSG_DISPATCH_SHOW_GLOBAL_ACTIONS:
575 showGlobalActionsInternal();
576 break;
Craig Mautner8a0da012014-05-31 15:13:37 -0700577 case MSG_KEYGUARD_DRAWN_COMPLETE:
578 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mKeyguardDrawComplete");
579 mKeyguardDrawComplete = true;
580 finishScreenTurningOn();
581 break;
582 case MSG_KEYGUARD_DRAWN_TIMEOUT:
583 Slog.w(TAG, "Keyguard drawn timeout. Setting mKeyguardDrawComplete");
584 mKeyguardDrawComplete = true;
585 finishScreenTurningOn();
586 break;
587 case MSG_WINDOW_MANAGER_DRAWN_COMPLETE:
588 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mWindowManagerDrawComplete");
589 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
590 mWindowManagerDrawComplete = true;
591 finishScreenTurningOn();
592 break;
593 case MSG_WAKING_UP:
594 handleWakingUp((ScreenOnListener) msg.obj);
595 break;
Craig Mautnera631d492014-08-05 15:16:01 -0700596 case MSG_HIDE_BOOT_MESSAGE:
597 handleHideBootMessage();
598 break;
Michael Wright869a67c2014-08-26 19:33:06 -0700599 case MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK:
600 launchVoiceAssistWithWakeLock(msg.arg1 != 0);
601 break;
Jeff Brown70825162012-03-28 17:27:48 -0700602 }
603 }
604 }
605
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800606 private UEventObserver mHDMIObserver = new UEventObserver() {
607 @Override
608 public void onUEvent(UEventObserver.UEvent event) {
609 setHdmiPlugged("1".equals(event.get("SWITCH_STATE")));
610 }
611 };
612
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800613 class SettingsObserver extends ContentObserver {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800614 SettingsObserver(Handler handler) {
615 super(handler);
616 }
David Brownbaf8d092010-03-08 21:52:59 -0800617
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800618 void observe() {
Christopher Tate5e08af02012-09-21 17:17:22 -0700619 // Observe all users' changes
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800620 ContentResolver resolver = mContext.getContentResolver();
621 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700622 Settings.System.END_BUTTON_BEHAVIOR), false, this,
623 UserHandle.USER_ALL);
David Brownbaf8d092010-03-08 21:52:59 -0800624 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700625 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR), false, this,
626 UserHandle.USER_ALL);
Jeff Browna20dda42014-05-27 20:57:24 -0700627 resolver.registerContentObserver(Settings.Secure.getUriFor(
628 Settings.Secure.WAKE_GESTURE_ENABLED), false, this,
629 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800630 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700631 Settings.System.ACCELEROMETER_ROTATION), false, this,
632 UserHandle.USER_ALL);
Mike Lockwood28569302010-01-28 11:54:40 -0500633 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700634 Settings.System.USER_ROTATION), false, this,
635 UserHandle.USER_ALL);
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400636 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700637 Settings.System.SCREEN_OFF_TIMEOUT), false, this,
638 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800639 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700640 Settings.System.POINTER_LOCATION), false, this,
641 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800642 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700643 Settings.Secure.DEFAULT_INPUT_METHOD), false, this,
644 UserHandle.USER_ALL);
John Spurlockd9b70bd2014-02-06 17:02:44 -0500645 resolver.registerContentObserver(Settings.Secure.getUriFor(
John Spurlockf1a36642013-10-12 17:50:42 -0400646 Settings.Secure.IMMERSIVE_MODE_CONFIRMATIONS), false, this,
Christopher Tate5e08af02012-09-21 17:17:22 -0700647 UserHandle.USER_ALL);
John Spurlockc6d1c602014-01-17 15:22:06 -0500648 resolver.registerContentObserver(Settings.Global.getUriFor(
649 Settings.Global.POLICY_CONTROL), false, this,
650 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800651 updateSettings();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800652 }
653
654 @Override public void onChange(boolean selfChange) {
Dianne Hackbornc777e072010-02-12 13:07:59 -0800655 updateSettings();
Jeff Brown01a98dd2011-09-20 15:08:29 -0700656 updateRotation(false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800657 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800658 }
Craig Mautner967212c2013-04-13 21:10:58 -0700659
Jeff Browna20dda42014-05-27 20:57:24 -0700660 class MyWakeGestureListener extends WakeGestureListener {
661 MyWakeGestureListener(Context context, Handler handler) {
662 super(context, handler);
663 }
664
665 @Override
666 public void onWakeUp() {
667 synchronized (mLock) {
668 if (shouldEnableWakeGestureLp()) {
Jeff Browne07b94b2014-06-18 15:56:27 -0700669 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
Jeff Browna20dda42014-05-27 20:57:24 -0700670 mPowerManager.wakeUp(SystemClock.uptimeMillis());
671 }
672 }
673 }
674 }
675
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800676 class MyOrientationListener extends WindowOrientationListener {
Craig Mautnereee29c42013-01-17 14:44:34 -0800677 MyOrientationListener(Context context, Handler handler) {
678 super(context, handler);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800679 }
Craig Mautner967212c2013-04-13 21:10:58 -0700680
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800681 @Override
Jeff Brownc0347aa2011-09-23 17:26:09 -0700682 public void onProposedRotationChanged(int rotation) {
Craig Mautnereda67292013-04-28 13:50:14 -0700683 if (localLOGV) Slog.v(TAG, "onProposedRotationChanged, rotation=" + rotation);
Jeff Brown01a98dd2011-09-20 15:08:29 -0700684 updateRotation(false);
685 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800686 }
687 MyOrientationListener mOrientationListener;
688
John Spurlock27735a42013-08-14 17:57:38 -0400689 private final BarController mStatusBarController = new BarController("StatusBar",
John Spurlock5b9145b2013-08-20 15:13:47 -0400690 View.STATUS_BAR_TRANSIENT,
691 View.STATUS_BAR_UNHIDE,
John Spurlockbd957402013-10-03 11:38:39 -0400692 View.STATUS_BAR_TRANSLUCENT,
693 StatusBarManager.WINDOW_STATUS_BAR,
694 WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
John Spurlock5b9145b2013-08-20 15:13:47 -0400695
John Spurlock27735a42013-08-14 17:57:38 -0400696 private final BarController mNavigationBarController = new BarController("NavigationBar",
John Spurlock5b9145b2013-08-20 15:13:47 -0400697 View.NAVIGATION_BAR_TRANSIENT,
698 View.NAVIGATION_BAR_UNHIDE,
John Spurlockbd957402013-10-03 11:38:39 -0400699 View.NAVIGATION_BAR_TRANSLUCENT,
700 StatusBarManager.WINDOW_NAVIGATION_BAR,
701 WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
John Spurlock5b9145b2013-08-20 15:13:47 -0400702
John Spurlockf1a36642013-10-12 17:50:42 -0400703 private ImmersiveModeConfirmation mImmersiveModeConfirmation;
John Spurlock32beb2c2013-03-11 10:16:47 -0400704
Craig Mautner037aa8d2013-06-07 10:35:44 -0700705 private SystemGesturesPointerEventListener mSystemGestures;
John Spurlock32beb2c2013-03-11 10:16:47 -0400706
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700707 IStatusBarService getStatusBarService() {
708 synchronized (mServiceAquireLock) {
709 if (mStatusBarService == null) {
710 mStatusBarService = IStatusBarService.Stub.asInterface(
711 ServiceManager.getService("statusbar"));
712 }
713 return mStatusBarService;
714 }
715 }
716
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700717 /*
718 * We always let the sensor be switched on by default except when
719 * the user has explicitly disabled sensor based rotation or when the
720 * screen is switched off.
721 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700722 boolean needSensorRunningLp() {
Jeff Brownbcdfc622014-03-06 19:13:04 -0800723 if (mSupportAutoRotation) {
724 if (mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
725 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
726 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT
727 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) {
728 // If the application has explicitly requested to follow the
729 // orientation, then we need to turn the sensor on.
730 return true;
731 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800732 }
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700733 if ((mCarDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_CAR) ||
Jeff Brown1a693182011-11-08 14:44:16 -0800734 (mDeskDockEnablesAccelerometer && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
735 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
736 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK))) {
Mike Lockwoode9867d22009-09-20 01:59:02 -0400737 // enable accelerometer if we are docked in a dock that enables accelerometer
738 // orientation management,
739 return true;
740 }
Jeff Brown207673cd2012-06-05 17:47:11 -0700741 if (mUserRotationMode == USER_ROTATION_LOCKED) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800742 // If the setting for using the sensor by default is enabled, then
743 // we will always leave it on. Note that the user could go to
744 // a window that forces an orientation that does not use the
745 // sensor and in theory we could turn it off... however, when next
746 // turning it on we won't have a good value for the current
747 // orientation for a little bit, which can cause orientation
748 // changes to lag, so we'd like to keep it always on. (It will
749 // still be turned off when the screen is off.)
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700750 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800751 }
Jeff Brownbcdfc622014-03-06 19:13:04 -0800752 return mSupportAutoRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800753 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700754
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800755 /*
756 * Various use cases for invoking this function
757 * screen turning off, should always disable listeners if already enabled
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700758 * screen turned on and current app has sensor based orientation, enable listeners
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800759 * if not already enabled
760 * screen turned on and current app does not have sensor orientation, disable listeners if
761 * already enabled
762 * screen turning on and current app has sensor based orientation, enable listeners if needed
763 * screen turning on and current app has nosensor based orientation, do nothing
764 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700765 void updateOrientationListenerLp() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800766 if (!mOrientationListener.canDetectOrientation()) {
767 // If sensor is turned off or nonexistent for some reason
768 return;
769 }
770 //Could have been invoked due to screen turning on or off or
771 //change of the currently visible window's orientation
Craig Mautnereda67292013-04-28 13:50:14 -0700772 if (localLOGV) Slog.v(TAG, "Screen status="+mScreenOnEarly+
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800773 ", current orientation="+mCurrentAppOrientation+
774 ", SensorEnabled="+mOrientationSensorEnabled);
775 boolean disable = true;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -0700776 if (mScreenOnEarly) {
The Android Open Source Project0727d222009-03-11 12:11:58 -0700777 if (needSensorRunningLp()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800778 disable = false;
779 //enable listener if not already enabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700780 if (!mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800781 mOrientationListener.enable();
Craig Mautnereda67292013-04-28 13:50:14 -0700782 if(localLOGV) Slog.v(TAG, "Enabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800783 mOrientationSensorEnabled = true;
784 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700785 }
786 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800787 //check if sensors need to be disabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700788 if (disable && mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800789 mOrientationListener.disable();
Craig Mautnereda67292013-04-28 13:50:14 -0700790 if(localLOGV) Slog.v(TAG, "Disabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800791 mOrientationSensorEnabled = false;
792 }
793 }
794
Jeff Brown4d396052010-10-29 21:50:21 -0700795 private void interceptPowerKeyDown(boolean handled) {
796 mPowerKeyHandled = handled;
797 if (!handled) {
Justin Kohfeabd2c2014-05-02 10:02:44 -0700798 mHandler.postDelayed(mPowerLongPress,
799 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Jeff Brown4d396052010-10-29 21:50:21 -0700800 }
801 }
802
803 private boolean interceptPowerKeyUp(boolean canceled) {
804 if (!mPowerKeyHandled) {
805 mHandler.removeCallbacks(mPowerLongPress);
806 return !canceled;
Jeff Brown4d396052010-10-29 21:50:21 -0700807 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700808 return false;
809 }
810
811 private void cancelPendingPowerKeyAction() {
812 if (!mPowerKeyHandled) {
813 mHandler.removeCallbacks(mPowerLongPress);
814 }
Jeff Brownff204712011-10-25 21:27:54 -0700815 if (mPowerKeyTriggered) {
816 mPendingPowerKeyUpCanceled = true;
817 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700818 }
819
820 private void interceptScreenshotChord() {
Christopher Tatee90585f2012-03-05 18:56:25 -0800821 if (mScreenshotChordEnabled
822 && mVolumeDownKeyTriggered && mPowerKeyTriggered && !mVolumeUpKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700823 final long now = SystemClock.uptimeMillis();
824 if (now <= mVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS
825 && now <= mPowerKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) {
826 mVolumeDownKeyConsumedByScreenshotChord = true;
827 cancelPendingPowerKeyAction();
828
Jeff Sharkey2991fa32012-12-05 18:06:43 -0800829 mHandler.postDelayed(mScreenshotRunnable, getScreenshotChordLongPressDelay());
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700830 }
831 }
832 }
833
Winson Chung1cea2f32012-10-08 20:42:01 -0700834 private long getScreenshotChordLongPressDelay() {
Jim Miller5ecd8112013-01-09 18:50:26 -0800835 if (mKeyguardDelegate.isShowing()) {
Winson Chung1cea2f32012-10-08 20:42:01 -0700836 // Double the time it takes to take a screenshot from the keyguard
837 return (long) (KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER *
Justin Kohfeabd2c2014-05-02 10:02:44 -0700838 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Winson Chung1cea2f32012-10-08 20:42:01 -0700839 }
Justin Kohfeabd2c2014-05-02 10:02:44 -0700840 return ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout();
Winson Chung1cea2f32012-10-08 20:42:01 -0700841 }
842
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700843 private void cancelPendingScreenshotChordAction() {
Jeff Sharkey2991fa32012-12-05 18:06:43 -0800844 mHandler.removeCallbacks(mScreenshotRunnable);
Jeff Brown4d396052010-10-29 21:50:21 -0700845 }
846
Jeff Brown6d8fd272014-05-20 21:24:38 -0700847 private void powerShortPress(long eventTime) {
848 if (mShortPressOnPowerBehavior < 0) {
849 mShortPressOnPowerBehavior = mContext.getResources().getInteger(
850 com.android.internal.R.integer.config_shortPressOnPowerBehavior);
851 }
852
853 switch (mShortPressOnPowerBehavior) {
854 case SHORT_PRESS_POWER_NOTHING:
855 break;
856 case SHORT_PRESS_POWER_GO_TO_SLEEP:
857 mPowerManager.goToSleep(eventTime,
Jeff Brownc12035c2014-08-13 18:52:25 -0700858 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
Jeff Brown6d8fd272014-05-20 21:24:38 -0700859 break;
860 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP:
861 mPowerManager.goToSleep(eventTime,
Jeff Brownc12035c2014-08-13 18:52:25 -0700862 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
Jeff Brown6d8fd272014-05-20 21:24:38 -0700863 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
864 break;
865 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME:
866 mPowerManager.goToSleep(eventTime,
Jeff Brownc12035c2014-08-13 18:52:25 -0700867 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
Jeff Brown6d8fd272014-05-20 21:24:38 -0700868 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
869 launchHomeFromHotKey();
870 break;
871 }
872 }
873
Jeff Brown4d396052010-10-29 21:50:21 -0700874 private final Runnable mPowerLongPress = new Runnable() {
Craig Mautnerf1b67412012-09-19 13:18:29 -0700875 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800876 public void run() {
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700877 // The context isn't read
878 if (mLongPressOnPowerBehavior < 0) {
Jeff Brown850c5b72012-10-01 15:17:22 -0700879 mLongPressOnPowerBehavior = mContext.getResources().getInteger(
880 com.android.internal.R.integer.config_longPressOnPowerBehavior);
Joe Onoratod208e702010-10-08 16:22:43 -0400881 }
Jeff Brown850c5b72012-10-01 15:17:22 -0700882 int resolvedBehavior = mLongPressOnPowerBehavior;
883 if (FactoryTest.isLongPressOnPowerOffEnabled()) {
884 resolvedBehavior = LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM;
885 }
886
887 switch (resolvedBehavior) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700888 case LONG_PRESS_POWER_NOTHING:
889 break;
890 case LONG_PRESS_POWER_GLOBAL_ACTIONS:
891 mPowerKeyHandled = true;
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -0700892 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
893 performAuditoryFeedbackForAccessibilityIfNeed();
894 }
Alan Viverettee34560b22014-07-10 14:50:06 -0700895 showGlobalActionsInternal();
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700896 break;
897 case LONG_PRESS_POWER_SHUT_OFF:
Jeff Brown9a538ee2012-08-20 14:56:57 -0700898 case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM:
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700899 mPowerKeyHandled = true;
900 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
901 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
Jeff Brown850c5b72012-10-01 15:17:22 -0700902 mWindowManagerFuncs.shutdown(resolvedBehavior == LONG_PRESS_POWER_SHUT_OFF);
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700903 break;
904 }
905 }
906 };
907
Jeff Sharkey2991fa32012-12-05 18:06:43 -0800908 private final Runnable mScreenshotRunnable = new Runnable() {
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800909 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700910 public void run() {
911 takeScreenshot();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800912 }
913 };
914
Alan Viverettee34560b22014-07-10 14:50:06 -0700915 @Override
916 public void showGlobalActions() {
917 mHandler.removeMessages(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
918 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
919 }
920
921 void showGlobalActionsInternal() {
922 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800923 if (mGlobalActions == null) {
Jeff Brown7304c342012-05-11 18:42:42 -0700924 mGlobalActions = new GlobalActions(mContext, mWindowManagerFuncs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800925 }
Mike Lockwood3a74bd32011-08-12 13:55:22 -0700926 final boolean keyguardShowing = keyguardIsShowingTq();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800927 mGlobalActions.showDialog(keyguardShowing, isDeviceProvisioned());
928 if (keyguardShowing) {
929 // since it took two seconds of long press to bring this up,
930 // poke the wake lock so they have some time to see the dialog.
Jim Miller25190572013-02-28 17:36:24 -0800931 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800932 }
933 }
934
935 boolean isDeviceProvisioned() {
Jeff Brownbf6f6f92012-09-25 15:03:20 -0700936 return Settings.Global.getInt(
937 mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800938 }
939
Maurice Lam99c6e072014-04-28 18:24:28 -0700940 boolean isUserSetupComplete() {
941 return Settings.Secure.getIntForUser(mContext.getContentResolver(),
942 Settings.Secure.USER_SETUP_COMPLETE, 0, UserHandle.USER_CURRENT) != 0;
943 }
944
Patrick Dubroyece94522011-02-23 18:35:01 -0800945 private void handleLongPressOnHome() {
Joe Onorato46b0d682010-11-22 17:37:27 -0800946 if (mLongPressOnHomeBehavior != LONG_PRESS_HOME_NOTHING) {
Jeff Browncaca8812013-05-09 13:34:33 -0700947 mHomeConsumed = true;
Joe Onorato46b0d682010-11-22 17:37:27 -0800948 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
Patrick Dubroyece94522011-02-23 18:35:01 -0800949
Jeff Browncaca8812013-05-09 13:34:33 -0700950 if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI) {
951 toggleRecentApps();
952 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_ASSIST) {
953 launchAssistAction();
Jim Millere6ad1a82010-08-20 19:25:39 -0700954 }
955 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800956 }
Patrick Dubroyece94522011-02-23 18:35:01 -0800957
Jeff Browncaca8812013-05-09 13:34:33 -0700958 private void handleDoubleTapOnHome() {
959 if (mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
960 mHomeConsumed = true;
961 toggleRecentApps();
962 }
963 }
964
965 private final Runnable mHomeDoubleTapTimeoutRunnable = new Runnable() {
966 @Override
967 public void run() {
968 if (mHomeDoubleTapPending) {
969 mHomeDoubleTapPending = false;
970 launchHomeFromHotKey();
971 }
972 }
973 };
974
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800975 /** {@inheritDoc} */
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800976 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800977 public void init(Context context, IWindowManager windowManager,
Jeff Brown96307042012-07-27 15:51:34 -0700978 WindowManagerFuncs windowManagerFuncs) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800979 mContext = context;
980 mWindowManager = windowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700981 mWindowManagerFuncs = windowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -0700982 mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class);
Jose Lima9546b202014-07-02 17:21:51 -0700983 mDreamManagerInternal = LocalServices.getService(DreamManagerInternal.class);
Craig Mautner8a0da012014-05-31 15:13:37 -0700984
Jeff Brown70825162012-03-28 17:27:48 -0700985 mHandler = new PolicyHandler();
Jeff Browna20dda42014-05-27 20:57:24 -0700986 mWakeGestureListener = new MyWakeGestureListener(mContext, mHandler);
Craig Mautnereee29c42013-01-17 14:44:34 -0800987 mOrientationListener = new MyOrientationListener(mContext, mHandler);
Jeff Brownc0347aa2011-09-23 17:26:09 -0700988 try {
989 mOrientationListener.setCurrentRotation(windowManager.getRotation());
990 } catch (RemoteException ex) { }
Christopher Tate5e08af02012-09-21 17:17:22 -0700991 mSettingsObserver = new SettingsObserver(mHandler);
992 mSettingsObserver.observe();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800993 mShortcutManager = new ShortcutManager(context, mHandler);
994 mShortcutManager.observe();
Daniel Sandler6396c722013-04-16 20:19:09 -0400995 mUiMode = context.getResources().getInteger(
996 com.android.internal.R.integer.config_defaultUiModeType);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800997 mHomeIntent = new Intent(Intent.ACTION_MAIN, null);
998 mHomeIntent.addCategory(Intent.CATEGORY_HOME);
999 mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1000 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07001001 mCarDockIntent = new Intent(Intent.ACTION_MAIN, null);
1002 mCarDockIntent.addCategory(Intent.CATEGORY_CAR_DOCK);
1003 mCarDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1004 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
1005 mDeskDockIntent = new Intent(Intent.ACTION_MAIN, null);
1006 mDeskDockIntent.addCategory(Intent.CATEGORY_DESK_DOCK);
1007 mDeskDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1008 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Jim Millere6ad1a82010-08-20 19:25:39 -07001009
Jeff Brown96307042012-07-27 15:51:34 -07001010 mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
1011 mBroadcastWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001012 "PhoneWindowManager.mBroadcastWakeLock");
1013 mEnableShiftMenuBugReports = "1".equals(SystemProperties.get("ro.debuggable"));
Jeff Brownbcdfc622014-03-06 19:13:04 -08001014 mSupportAutoRotation = mContext.getResources().getBoolean(
1015 com.android.internal.R.bool.config_supportAutoRotation);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001016 mLidOpenRotation = readRotation(
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001017 com.android.internal.R.integer.config_lidOpenRotation);
1018 mCarDockRotation = readRotation(
1019 com.android.internal.R.integer.config_carDockRotation);
1020 mDeskDockRotation = readRotation(
1021 com.android.internal.R.integer.config_deskDockRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001022 mUndockedHdmiRotation = readRotation(
1023 com.android.internal.R.integer.config_undockedHdmiRotation);
Mike Lockwoode9867d22009-09-20 01:59:02 -04001024 mCarDockEnablesAccelerometer = mContext.getResources().getBoolean(
1025 com.android.internal.R.bool.config_carDockEnablesAccelerometer);
1026 mDeskDockEnablesAccelerometer = mContext.getResources().getBoolean(
1027 com.android.internal.R.bool.config_deskDockEnablesAccelerometer);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001028 mLidKeyboardAccessibility = mContext.getResources().getInteger(
1029 com.android.internal.R.integer.config_lidKeyboardAccessibility);
1030 mLidNavigationAccessibility = mContext.getResources().getInteger(
1031 com.android.internal.R.integer.config_lidNavigationAccessibility);
Jeff Brownc458ce92012-04-30 14:58:40 -07001032 mLidControlsSleep = mContext.getResources().getBoolean(
1033 com.android.internal.R.bool.config_lidControlsSleep);
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04001034 mTranslucentDecorEnabled = mContext.getResources().getBoolean(
1035 com.android.internal.R.bool.config_enableTranslucentDecor);
Jeff Brownf71343d2013-05-31 17:59:11 -07001036 readConfigurationDependentBehaviors();
Jeff Browncaca8812013-05-09 13:34:33 -07001037
Svetoslav8e3feb12014-02-24 13:46:47 -08001038 mAccessibilityManager = (AccessibilityManager) context.getSystemService(
1039 Context.ACCESSIBILITY_SERVICE);
1040
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001041 // register for dock events
Dianne Hackborn78968392010-03-04 20:47:56 -08001042 IntentFilter filter = new IntentFilter();
1043 filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE);
1044 filter.addAction(UiModeManager.ACTION_EXIT_CAR_MODE);
1045 filter.addAction(UiModeManager.ACTION_ENTER_DESK_MODE);
1046 filter.addAction(UiModeManager.ACTION_EXIT_DESK_MODE);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001047 filter.addAction(Intent.ACTION_DOCK_EVENT);
1048 Intent intent = context.registerReceiver(mDockReceiver, filter);
1049 if (intent != null) {
1050 // Retrieve current sticky dock event broadcast.
1051 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
1052 Intent.EXTRA_DOCK_STATE_UNDOCKED);
1053 }
Daniel Sandler7e37df52011-11-16 22:08:23 -08001054
Jeff Brown6aaf2952012-10-05 16:01:08 -07001055 // register for dream-related broadcasts
1056 filter = new IntentFilter();
1057 filter.addAction(Intent.ACTION_DREAMING_STARTED);
1058 filter.addAction(Intent.ACTION_DREAMING_STOPPED);
1059 context.registerReceiver(mDreamReceiver, filter);
1060
Christopher Tate5e08af02012-09-21 17:17:22 -07001061 // register for multiuser-relevant broadcasts
1062 filter = new IntentFilter(Intent.ACTION_USER_SWITCHED);
1063 context.registerReceiver(mMultiuserReceiver, filter);
1064
John Spurlock57306e62013-04-22 09:48:49 -04001065 // monitor for system gestures
Craig Mautner037aa8d2013-06-07 10:35:44 -07001066 mSystemGestures = new SystemGesturesPointerEventListener(context,
1067 new SystemGesturesPointerEventListener.Callbacks() {
John Spurlock57306e62013-04-22 09:48:49 -04001068 @Override
1069 public void onSwipeFromTop() {
John Spurlock04db1762013-05-13 12:46:41 -04001070 if (mStatusBar != null) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001071 requestTransientBars(mStatusBar);
John Spurlock04db1762013-05-13 12:46:41 -04001072 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04001073 }
1074 @Override
1075 public void onSwipeFromBottom() {
John Spurlock04db1762013-05-13 12:46:41 -04001076 if (mNavigationBar != null && mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001077 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001078 }
1079 }
1080 @Override
1081 public void onSwipeFromRight() {
John Spurlock04db1762013-05-13 12:46:41 -04001082 if (mNavigationBar != null && !mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001083 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001084 }
1085 }
1086 @Override
1087 public void onDebug() {
John Spurlockd67ec252013-09-05 11:31:54 -04001088 // no-op
John Spurlockad3e6cb2013-04-30 08:47:43 -04001089 }
1090 });
John Spurlockf1a36642013-10-12 17:50:42 -04001091 mImmersiveModeConfirmation = new ImmersiveModeConfirmation(mContext);
Craig Mautner037aa8d2013-06-07 10:35:44 -07001092 mWindowManagerFuncs.registerPointerEventListener(mSystemGestures);
John Spurlock32beb2c2013-03-11 10:16:47 -04001093
Jeff Brownc2346132012-04-13 01:55:38 -07001094 mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001095 mLongPressVibePattern = getLongIntArray(mContext.getResources(),
1096 com.android.internal.R.array.config_longPressVibePattern);
1097 mVirtualKeyVibePattern = getLongIntArray(mContext.getResources(),
1098 com.android.internal.R.array.config_virtualKeyVibePattern);
Amith Yamasanic33cb712010-02-10 15:21:49 -08001099 mKeyboardTapVibePattern = getLongIntArray(mContext.getResources(),
1100 com.android.internal.R.array.config_keyboardTapVibePattern);
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07001101 mClockTickVibePattern = getLongIntArray(mContext.getResources(),
1102 com.android.internal.R.array.config_clockTickVibePattern);
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07001103 mCalendarDateVibePattern = getLongIntArray(mContext.getResources(),
1104 com.android.internal.R.array.config_calendarDateVibePattern);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001105 mSafeModeDisabledVibePattern = getLongIntArray(mContext.getResources(),
1106 com.android.internal.R.array.config_safeModeDisabledVibePattern);
1107 mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(),
1108 com.android.internal.R.array.config_safeModeEnabledVibePattern);
Daniel Sandler40427442010-07-16 11:44:52 -04001109
Christopher Tatee90585f2012-03-05 18:56:25 -08001110 mScreenshotChordEnabled = mContext.getResources().getBoolean(
1111 com.android.internal.R.bool.config_enableScreenshotChord);
1112
Justin Kohd378ad72013-04-01 12:18:26 -07001113 mGlobalKeyManager = new GlobalKeyManager(mContext);
1114
Joe Onoratoea495d42011-04-06 11:41:11 -07001115 // Controls rotation and the like.
1116 initializeHdmiState();
Dianne Hackborn40011092011-09-22 13:37:48 -07001117
1118 // Match current screen state.
Craig Mautnera631d492014-08-05 15:16:01 -07001119 if (!mPowerManager.isInteractive()) {
Jeff Brown140ffc72014-05-01 15:18:00 -07001120 goingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
Dianne Hackborn40011092011-09-22 13:37:48 -07001121 }
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001122 }
1123
Jeff Brownf71343d2013-05-31 17:59:11 -07001124 /**
1125 * Read values from config.xml that may be overridden depending on
1126 * the configuration of the device.
1127 * eg. Disable long press on home goes to recents on sw600dp.
1128 */
1129 private void readConfigurationDependentBehaviors() {
1130 mLongPressOnHomeBehavior = mContext.getResources().getInteger(
1131 com.android.internal.R.integer.config_longPressOnHomeBehavior);
1132 if (mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING ||
1133 mLongPressOnHomeBehavior > LONG_PRESS_HOME_ASSIST) {
1134 mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1135 }
1136
1137 mDoubleTapOnHomeBehavior = mContext.getResources().getInteger(
1138 com.android.internal.R.integer.config_doubleTapOnHomeBehavior);
1139 if (mDoubleTapOnHomeBehavior < DOUBLE_TAP_HOME_NOTHING ||
1140 mDoubleTapOnHomeBehavior > DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1141 mDoubleTapOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1142 }
1143 }
1144
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001145 @Override
Dianne Hackborndde331c2012-08-03 14:01:57 -07001146 public void setInitialDisplaySize(Display display, int width, int height, int density) {
Jeff Brownef981a42013-08-07 14:13:37 -07001147 // This method might be called before the policy has been fully initialized
1148 // or for other displays we don't care about.
1149 if (mContext == null || display.getDisplayId() != Display.DEFAULT_DISPLAY) {
1150 return;
Dianne Hackbornc652de82013-02-15 16:32:56 -08001151 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001152 mDisplay = display;
1153
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001154 final Resources res = mContext.getResources();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001155 int shortSize, longSize;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001156 if (width > height) {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001157 shortSize = height;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001158 longSize = width;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001159 mLandscapeRotation = Surface.ROTATION_0;
1160 mSeascapeRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001161 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001162 mPortraitRotation = Surface.ROTATION_90;
1163 mUpsideDownRotation = Surface.ROTATION_270;
1164 } else {
1165 mPortraitRotation = Surface.ROTATION_270;
1166 mUpsideDownRotation = Surface.ROTATION_90;
1167 }
1168 } else {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001169 shortSize = width;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001170 longSize = height;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001171 mPortraitRotation = Surface.ROTATION_0;
1172 mUpsideDownRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001173 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001174 mLandscapeRotation = Surface.ROTATION_270;
1175 mSeascapeRotation = Surface.ROTATION_90;
1176 } else {
1177 mLandscapeRotation = Surface.ROTATION_90;
1178 mSeascapeRotation = Surface.ROTATION_270;
1179 }
1180 }
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001181
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001182 mStatusBarHeight =
1183 res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001184
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001185 // Height of the navigation bar when presented horizontally at bottom
1186 mNavigationBarHeightForRotation[mPortraitRotation] =
1187 mNavigationBarHeightForRotation[mUpsideDownRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001188 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_height);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001189 mNavigationBarHeightForRotation[mLandscapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001190 mNavigationBarHeightForRotation[mSeascapeRotation] = res.getDimensionPixelSize(
1191 com.android.internal.R.dimen.navigation_bar_height_landscape);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001192
1193 // Width of the navigation bar when presented vertically along one side
1194 mNavigationBarWidthForRotation[mPortraitRotation] =
1195 mNavigationBarWidthForRotation[mUpsideDownRotation] =
1196 mNavigationBarWidthForRotation[mLandscapeRotation] =
1197 mNavigationBarWidthForRotation[mSeascapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001198 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_width);
Daniel Sandler4a066c52012-04-20 14:49:13 -04001199
1200 // SystemUI (status bar) layout policy
Dianne Hackborndde331c2012-08-03 14:01:57 -07001201 int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / density;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001202 int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / density;
Daniel Sandler4a066c52012-04-20 14:49:13 -04001203
Craig Mautnerd4ec33242013-07-22 10:37:43 -07001204 // Allow the navigation bar to move on small devices (phones).
1205 mNavigationBarCanMove = shortSizeDp < 600;
Daniel Sandler36412a72011-08-04 09:35:13 -04001206
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001207 mHasNavigationBar = res.getBoolean(com.android.internal.R.bool.config_showNavigationBar);
John Spurlock80f00c12013-06-13 11:10:51 -04001208 // Allow a system property to override this. Used by the emulator.
1209 // See also hasNavigationBar().
1210 String navBarOverride = SystemProperties.get("qemu.hw.mainkeys");
1211 if ("1".equals(navBarOverride)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001212 mHasNavigationBar = false;
John Spurlock80f00c12013-06-13 11:10:51 -04001213 } else if ("0".equals(navBarOverride)) {
1214 mHasNavigationBar = true;
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04001215 }
1216
Jeff Brown27f1d672012-10-17 18:32:34 -07001217 // For demo purposes, allow the rotation of the HDMI display to be controlled.
1218 // By default, HDMI locks rotation to landscape.
Erik Gilling9a41ef82011-09-26 19:21:03 -07001219 if ("portrait".equals(SystemProperties.get("persist.demo.hdmirotation"))) {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001220 mDemoHdmiRotation = mPortraitRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001221 } else {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001222 mDemoHdmiRotation = mLandscapeRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001223 }
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001224 mDemoHdmiRotationLock = SystemProperties.getBoolean("persist.demo.hdmirotationlock", false);
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001225
1226 // Only force the default orientation if the screen is xlarge, at least 960dp x 720dp, per
1227 // http://developer.android.com/guide/practices/screens_support.html#range
1228 mForceDefaultOrientation = longSizeDp >= 960 && shortSizeDp >= 720 &&
1229 res.getBoolean(com.android.internal.R.bool.config_forceDefaultOrientation) &&
1230 // For debug purposes the next line turns this feature off with:
1231 // $ adb shell setprop config.override_forced_orient true
1232 // $ adb shell wm size reset
1233 !"true".equals(SystemProperties.get("config.override_forced_orient"));
1234 }
1235
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001236 /**
1237 * @return whether the navigation bar can be hidden, e.g. the device has a
1238 * navigation bar and touch exploration is not enabled
1239 */
1240 private boolean canHideNavigationBar() {
Svetoslav8e3feb12014-02-24 13:46:47 -08001241 return mHasNavigationBar
1242 && !mAccessibilityManager.isTouchExplorationEnabled();
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001243 }
1244
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001245 @Override
1246 public boolean isDefaultOrientationForced() {
1247 return mForceDefaultOrientation;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001248 }
1249
Dianne Hackbornc652de82013-02-15 16:32:56 -08001250 @Override
1251 public void setDisplayOverscan(Display display, int left, int top, int right, int bottom) {
1252 if (display.getDisplayId() == Display.DEFAULT_DISPLAY) {
1253 mOverscanLeft = left;
1254 mOverscanTop = top;
1255 mOverscanRight = right;
1256 mOverscanBottom = bottom;
1257 }
1258 }
1259
Dianne Hackbornc777e072010-02-12 13:07:59 -08001260 public void updateSettings() {
1261 ContentResolver resolver = mContext.getContentResolver();
1262 boolean updateRotation = false;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001263 synchronized (mLock) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001264 mEndcallBehavior = Settings.System.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001265 Settings.System.END_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001266 Settings.System.END_BUTTON_BEHAVIOR_DEFAULT,
1267 UserHandle.USER_CURRENT);
1268 mIncallPowerBehavior = Settings.Secure.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001269 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001270 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT,
1271 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001272
Jeff Browna20dda42014-05-27 20:57:24 -07001273 // Configure wake gesture.
1274 boolean wakeGestureEnabledSetting = Settings.Secure.getIntForUser(resolver,
1275 Settings.Secure.WAKE_GESTURE_ENABLED, 0,
1276 UserHandle.USER_CURRENT) != 0;
1277 if (mWakeGestureEnabledSetting != wakeGestureEnabledSetting) {
1278 mWakeGestureEnabledSetting = wakeGestureEnabledSetting;
1279 updateWakeGestureListenerLp();
1280 }
1281
Jeff Brown207673cd2012-06-05 17:47:11 -07001282 // Configure rotation lock.
Christopher Tate5e08af02012-09-21 17:17:22 -07001283 int userRotation = Settings.System.getIntForUser(resolver,
1284 Settings.System.USER_ROTATION, Surface.ROTATION_0,
1285 UserHandle.USER_CURRENT);
Jeff Brown207673cd2012-06-05 17:47:11 -07001286 if (mUserRotation != userRotation) {
1287 mUserRotation = userRotation;
1288 updateRotation = true;
1289 }
Christopher Tate5e08af02012-09-21 17:17:22 -07001290 int userRotationMode = Settings.System.getIntForUser(resolver,
1291 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
Jeff Brown207673cd2012-06-05 17:47:11 -07001292 WindowManagerPolicy.USER_ROTATION_FREE :
1293 WindowManagerPolicy.USER_ROTATION_LOCKED;
1294 if (mUserRotationMode != userRotationMode) {
1295 mUserRotationMode = userRotationMode;
1296 updateRotation = true;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001297 updateOrientationListenerLp();
1298 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001299
Dianne Hackbornc777e072010-02-12 13:07:59 -08001300 if (mSystemReady) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001301 int pointerLocation = Settings.System.getIntForUser(resolver,
1302 Settings.System.POINTER_LOCATION, 0, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001303 if (mPointerLocationMode != pointerLocation) {
1304 mPointerLocationMode = pointerLocation;
Jeff Brown70825162012-03-28 17:27:48 -07001305 mHandler.sendEmptyMessage(pointerLocation != 0 ?
1306 MSG_ENABLE_POINTER_LOCATION : MSG_DISABLE_POINTER_LOCATION);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001307 }
1308 }
1309 // use screen off timeout setting as the timeout for the lockscreen
Christopher Tate5e08af02012-09-21 17:17:22 -07001310 mLockScreenTimeout = Settings.System.getIntForUser(resolver,
1311 Settings.System.SCREEN_OFF_TIMEOUT, 0, UserHandle.USER_CURRENT);
1312 String imId = Settings.Secure.getStringForUser(resolver,
1313 Settings.Secure.DEFAULT_INPUT_METHOD, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001314 boolean hasSoftInput = imId != null && imId.length() > 0;
1315 if (mHasSoftInput != hasSoftInput) {
1316 mHasSoftInput = hasSoftInput;
1317 updateRotation = true;
1318 }
John Spurlockf1a36642013-10-12 17:50:42 -04001319 if (mImmersiveModeConfirmation != null) {
John Spurlock4355a532014-02-19 09:49:25 -05001320 mImmersiveModeConfirmation.loadSetting(mCurrentUserId);
John Spurlockd67ec252013-09-05 11:31:54 -04001321 }
John Spurlockc6d1c602014-01-17 15:22:06 -05001322 PolicyControl.reloadFromSetting(mContext);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001323 }
1324 if (updateRotation) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07001325 updateRotation(true);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001326 }
Jeff Brown70825162012-03-28 17:27:48 -07001327 }
1328
Jeff Browna20dda42014-05-27 20:57:24 -07001329 private void updateWakeGestureListenerLp() {
1330 if (shouldEnableWakeGestureLp()) {
1331 mWakeGestureListener.requestWakeUpTrigger();
1332 } else {
1333 mWakeGestureListener.cancelWakeUpTrigger();
1334 }
1335 }
1336
1337 private boolean shouldEnableWakeGestureLp() {
1338 return mWakeGestureEnabledSetting && !mScreenOnEarly
1339 && (!mLidControlsSleep || mLidState != LID_CLOSED)
1340 && mWakeGestureListener.isSupported();
1341 }
1342
Jeff Brown70825162012-03-28 17:27:48 -07001343 private void enablePointerLocation() {
1344 if (mPointerLocationView == null) {
1345 mPointerLocationView = new PointerLocationView(mContext);
1346 mPointerLocationView.setPrintCoords(false);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001347 WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
1348 WindowManager.LayoutParams.MATCH_PARENT,
1349 WindowManager.LayoutParams.MATCH_PARENT);
Jeff Brown3b2b3542010-10-15 00:54:27 -07001350 lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001351 lp.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN
1352 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
1353 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1354 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
Jeff Brown90fc9052012-10-01 14:44:24 -07001355 if (ActivityManager.isHighEndGfx()) {
1356 lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
1357 lp.privateFlags |=
1358 WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED;
1359 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001360 lp.format = PixelFormat.TRANSLUCENT;
1361 lp.setTitle("PointerLocation");
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001362 WindowManager wm = (WindowManager)
Dianne Hackbornc777e072010-02-12 13:07:59 -08001363 mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Browncc4f7db2011-08-30 20:34:48 -07001364 lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL;
Jeff Brown70825162012-03-28 17:27:48 -07001365 wm.addView(mPointerLocationView, lp);
Michael Wrightc9c487e2013-11-07 18:55:09 -08001366 mWindowManagerFuncs.registerPointerEventListener(mPointerLocationView);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001367 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001368 }
Jeff Brown70825162012-03-28 17:27:48 -07001369
1370 private void disablePointerLocation() {
Jeff Brown70825162012-03-28 17:27:48 -07001371 if (mPointerLocationView != null) {
Michael Wrightc9c487e2013-11-07 18:55:09 -08001372 mWindowManagerFuncs.unregisterPointerEventListener(mPointerLocationView);
1373 WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Brown70825162012-03-28 17:27:48 -07001374 wm.removeView(mPointerLocationView);
1375 mPointerLocationView = null;
1376 }
1377 }
1378
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001379 private int readRotation(int resID) {
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001380 try {
1381 int rotation = mContext.getResources().getInteger(resID);
1382 switch (rotation) {
1383 case 0:
1384 return Surface.ROTATION_0;
1385 case 90:
1386 return Surface.ROTATION_90;
1387 case 180:
1388 return Surface.ROTATION_180;
1389 case 270:
1390 return Surface.ROTATION_270;
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001391 }
1392 } catch (Resources.NotFoundException e) {
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001393 // fall through
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001394 }
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001395 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001396 }
1397
1398 /** {@inheritDoc} */
Craig Mautner88400d32012-09-30 12:35:45 -07001399 @Override
Dianne Hackbornc2293022013-02-06 23:14:49 -08001400 public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001401 int type = attrs.type;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001402
1403 outAppOp[0] = AppOpsManager.OP_NONE;
1404
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001405 if (type < WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW
1406 || type > WindowManager.LayoutParams.LAST_SYSTEM_WINDOW) {
Jeff Brown98365d72012-08-19 20:30:52 -07001407 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001408 }
1409 String permission = null;
1410 switch (type) {
1411 case TYPE_TOAST:
1412 // XXX right now the app process has complete control over
1413 // this... should introduce a token to let the system
1414 // monitor/control what they are doing.
Jason Monk1c7c3192014-06-26 12:52:18 -04001415 outAppOp[0] = AppOpsManager.OP_TOAST_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001416 break;
Daniel Sandler7d276c32012-01-30 14:33:52 -05001417 case TYPE_DREAM:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001418 case TYPE_INPUT_METHOD:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001419 case TYPE_WALLPAPER:
keunyounga446bf02013-06-21 19:07:57 -07001420 case TYPE_PRIVATE_PRESENTATION:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001421 case TYPE_VOICE_INTERACTION:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001422 // The window manager will check these.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001423 break;
1424 case TYPE_PHONE:
1425 case TYPE_PRIORITY_PHONE:
1426 case TYPE_SYSTEM_ALERT:
1427 case TYPE_SYSTEM_ERROR:
1428 case TYPE_SYSTEM_OVERLAY:
1429 permission = android.Manifest.permission.SYSTEM_ALERT_WINDOW;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001430 outAppOp[0] = AppOpsManager.OP_SYSTEM_ALERT_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001431 break;
1432 default:
1433 permission = android.Manifest.permission.INTERNAL_SYSTEM_WINDOW;
1434 }
1435 if (permission != null) {
1436 if (mContext.checkCallingOrSelfPermission(permission)
1437 != PackageManager.PERMISSION_GRANTED) {
Jeff Brown98365d72012-08-19 20:30:52 -07001438 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001439 }
1440 }
Jeff Brown98365d72012-08-19 20:30:52 -07001441 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001442 }
Craig Mautner88400d32012-09-30 12:35:45 -07001443
1444 @Override
1445 public boolean checkShowToOwnerOnly(WindowManager.LayoutParams attrs) {
1446
1447 // If this switch statement is modified, modify the comment in the declarations of
1448 // the type in {@link WindowManager.LayoutParams} as well.
1449 switch (attrs.type) {
1450 default:
1451 // These are the windows that by default are shown only to the user that created
1452 // them. If this needs to be overridden, set
1453 // {@link WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS} in
1454 // {@link WindowManager.LayoutParams}. Note that permission
1455 // {@link android.Manifest.permission.INTERNAL_SYSTEM_WINDOW} is required as well.
1456 if ((attrs.privateFlags & PRIVATE_FLAG_SHOW_FOR_ALL_USERS) == 0) {
1457 return true;
1458 }
1459 break;
1460
1461 // These are the windows that by default are shown to all users. However, to
1462 // protect against spoofing, check permissions below.
1463 case TYPE_APPLICATION_STARTING:
1464 case TYPE_BOOT_PROGRESS:
1465 case TYPE_DISPLAY_OVERLAY:
1466 case TYPE_HIDDEN_NAV_CONSUMER:
Jim Miller5ecd8112013-01-09 18:50:26 -08001467 case TYPE_KEYGUARD_SCRIM:
Craig Mautner88400d32012-09-30 12:35:45 -07001468 case TYPE_KEYGUARD_DIALOG:
1469 case TYPE_MAGNIFICATION_OVERLAY:
1470 case TYPE_NAVIGATION_BAR:
1471 case TYPE_NAVIGATION_BAR_PANEL:
1472 case TYPE_PHONE:
1473 case TYPE_POINTER:
1474 case TYPE_PRIORITY_PHONE:
1475 case TYPE_RECENTS_OVERLAY:
1476 case TYPE_SEARCH_BAR:
1477 case TYPE_STATUS_BAR:
1478 case TYPE_STATUS_BAR_PANEL:
1479 case TYPE_STATUS_BAR_SUB_PANEL:
1480 case TYPE_SYSTEM_DIALOG:
1481 case TYPE_UNIVERSE_BACKGROUND:
1482 case TYPE_VOLUME_OVERLAY:
keunyounga446bf02013-06-21 19:07:57 -07001483 case TYPE_PRIVATE_PRESENTATION:
Craig Mautner88400d32012-09-30 12:35:45 -07001484 break;
1485 }
1486
1487 // Check if third party app has set window to system window type.
1488 return mContext.checkCallingOrSelfPermission(
1489 android.Manifest.permission.INTERNAL_SYSTEM_WINDOW)
1490 != PackageManager.PERMISSION_GRANTED;
1491 }
1492
Craig Mautner967212c2013-04-13 21:10:58 -07001493 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001494 public void adjustWindowParamsLw(WindowManager.LayoutParams attrs) {
1495 switch (attrs.type) {
1496 case TYPE_SYSTEM_OVERLAY:
Jeff Brown3b2b3542010-10-15 00:54:27 -07001497 case TYPE_SECURE_SYSTEM_OVERLAY:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001498 // These types of windows can't receive input events.
1499 attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1500 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001501 attrs.flags &= ~WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001502 break;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001503 case TYPE_STATUS_BAR:
1504
1505 // If the Keyguard is in a hidden state (occluded by another window), we force to
1506 // remove the wallpaper and keyguard flag so that any change in-flight after setting
1507 // the keyguard as occluded wouldn't set these flags again.
1508 // See {@link #processKeyguardSetHiddenResultLw}.
1509 if (mKeyguardHidden) {
1510 attrs.flags &= ~WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
1511 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
1512 }
1513 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001514 }
Adrian Roos38502112014-04-09 21:04:11 +02001515
1516 if (attrs.type != TYPE_STATUS_BAR) {
1517 // The status bar is the only window allowed to exhibit keyguard behavior.
1518 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
1519 }
Adrian Roosea562512014-05-05 13:33:03 +02001520
1521 if (ActivityManager.isHighEndGfx()
1522 && (attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0) {
1523 attrs.subtreeSystemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_STABLE
1524 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
1525 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
1526 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001527 }
RoboErik8a2cfc32014-05-16 11:19:38 -07001528
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001529 void readLidState() {
Jeff Brown2e7760e2012-04-11 15:14:55 -07001530 mLidState = mWindowManagerFuncs.getLidState();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001531 }
RoboErik8a2cfc32014-05-16 11:19:38 -07001532
Michael Wright3818c922014-09-02 13:59:07 -07001533 private void readCameraLensCoverState() {
1534 mCameraLensCoverState = mWindowManagerFuncs.getCameraLensCoverState();
1535 }
1536
Jeff Browndaa37532012-05-01 15:54:03 -07001537 private boolean isHidden(int accessibilityMode) {
1538 switch (accessibilityMode) {
1539 case 1:
1540 return mLidState == LID_CLOSED;
1541 case 2:
1542 return mLidState == LID_OPEN;
1543 default:
1544 return false;
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001545 }
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001546 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001547
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001548 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07001549 @Override
Jeff Browndaa37532012-05-01 15:54:03 -07001550 public void adjustConfigurationLw(Configuration config, int keyboardPresence,
1551 int navigationPresence) {
1552 mHaveBuiltInKeyboard = (keyboardPresence & PRESENCE_INTERNAL) != 0;
1553
Jeff Brownf71343d2013-05-31 17:59:11 -07001554 readConfigurationDependentBehaviors();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001555 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07001556 applyLidSwitchState();
Jeff Brownd04a88c2011-01-16 14:05:47 -08001557
Jeff Browndaa37532012-05-01 15:54:03 -07001558 if (config.keyboard == Configuration.KEYBOARD_NOKEYS
1559 || (keyboardPresence == PRESENCE_INTERNAL
1560 && isHidden(mLidKeyboardAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001561 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_YES;
Jeff Browndaa37532012-05-01 15:54:03 -07001562 if (!mHasSoftInput) {
1563 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_YES;
1564 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001565 }
1566
Jeff Browndaa37532012-05-01 15:54:03 -07001567 if (config.navigation == Configuration.NAVIGATION_NONAV
1568 || (navigationPresence == PRESENCE_INTERNAL
1569 && isHidden(mLidNavigationAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001570 config.navigationHidden = Configuration.NAVIGATIONHIDDEN_YES;
Jeff Brownd04a88c2011-01-16 14:05:47 -08001571 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001572 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001573
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001574 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07001575 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001576 public int windowTypeToLayerLw(int type) {
1577 if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001578 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001579 }
1580 switch (type) {
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001581 case TYPE_UNIVERSE_BACKGROUND:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001582 return 1;
keunyounga446bf02013-06-21 19:07:57 -07001583 case TYPE_PRIVATE_PRESENTATION:
1584 return 2;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001585 case TYPE_WALLPAPER:
1586 // wallpaper is at the bottom, though the window manager may move it.
1587 return 2;
1588 case TYPE_PHONE:
1589 return 3;
1590 case TYPE_SEARCH_BAR:
1591 return 4;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001592 case TYPE_VOICE_INTERACTION:
1593 // voice interaction layer is almost immediately above apps.
1594 return 5;
Craig Mautner88400d32012-09-30 12:35:45 -07001595 case TYPE_RECENTS_OVERLAY:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001596 case TYPE_SYSTEM_DIALOG:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001597 return 6;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001598 case TYPE_TOAST:
1599 // toasts and the plugged-in battery thing
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001600 return 7;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001601 case TYPE_PRIORITY_PHONE:
1602 // SIM errors and unlock. Not sure if this really should be in a high layer.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001603 return 8;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001604 case TYPE_DREAM:
1605 // used for Dreams (screensavers with TYPE_DREAM windows)
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001606 return 9;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001607 case TYPE_SYSTEM_ALERT:
1608 // like the ANR / app crashed dialogs
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001609 return 10;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001610 case TYPE_INPUT_METHOD:
1611 // on-screen keyboards and other such input method user interfaces go here.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001612 return 11;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001613 case TYPE_INPUT_METHOD_DIALOG:
1614 // on-screen keyboards and other such input method user interfaces go here.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001615 return 12;
Jim Miller5ecd8112013-01-09 18:50:26 -08001616 case TYPE_KEYGUARD_SCRIM:
1617 // the safety window that shows behind keyguard while keyguard is starting
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001618 return 13;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001619 case TYPE_STATUS_BAR_SUB_PANEL:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001620 return 14;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001621 case TYPE_STATUS_BAR:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001622 return 15;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001623 case TYPE_STATUS_BAR_PANEL:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001624 return 16;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001625 case TYPE_KEYGUARD_DIALOG:
1626 return 17;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001627 case TYPE_VOLUME_OVERLAY:
1628 // the on-screen volume indicator and controller shown when the user
1629 // changes the device volume
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001630 return 18;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001631 case TYPE_SYSTEM_OVERLAY:
1632 // the on-screen volume indicator and controller shown when the user
1633 // changes the device volume
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001634 return 19;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001635 case TYPE_NAVIGATION_BAR:
1636 // the navigation bar, if available, shows atop most things
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001637 return 20;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001638 case TYPE_NAVIGATION_BAR_PANEL:
1639 // some panels (e.g. search) need to show on top of the navigation bar
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001640 return 21;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001641 case TYPE_SYSTEM_ERROR:
1642 // system-level error dialogs
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001643 return 22;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001644 case TYPE_MAGNIFICATION_OVERLAY:
1645 // used to highlight the magnified portion of a display
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001646 return 23;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001647 case TYPE_DISPLAY_OVERLAY:
1648 // used to simulate secondary display devices
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001649 return 24;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001650 case TYPE_DRAG:
1651 // the drag layer: input for drag-and-drop is associated with this window,
1652 // which sits above all other focusable windows
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001653 return 25;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001654 case TYPE_SECURE_SYSTEM_OVERLAY:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001655 return 26;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001656 case TYPE_BOOT_PROGRESS:
1657 return 27;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001658 case TYPE_POINTER:
1659 // the (mouse) pointer layer
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001660 return 28;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001661 case TYPE_HIDDEN_NAV_CONSUMER:
1662 return 29;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001663 }
1664 Log.e(TAG, "Unknown window type: " + type);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001665 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001666 }
1667
1668 /** {@inheritDoc} */
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001669 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001670 public int subWindowTypeToLayerLw(int type) {
1671 switch (type) {
1672 case TYPE_APPLICATION_PANEL:
1673 case TYPE_APPLICATION_ATTACHED_DIALOG:
1674 return APPLICATION_PANEL_SUBLAYER;
1675 case TYPE_APPLICATION_MEDIA:
1676 return APPLICATION_MEDIA_SUBLAYER;
Dianne Hackborn5cb8d792009-05-21 17:34:15 -07001677 case TYPE_APPLICATION_MEDIA_OVERLAY:
1678 return APPLICATION_MEDIA_OVERLAY_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001679 case TYPE_APPLICATION_SUB_PANEL:
1680 return APPLICATION_SUB_PANEL_SUBLAYER;
1681 }
1682 Log.e(TAG, "Unknown sub-window type: " + type);
1683 return 0;
1684 }
1685
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001686 @Override
Dianne Hackbornabe0da02009-09-18 01:55:39 -07001687 public int getMaxWallpaperLayer() {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001688 return windowTypeToLayerLw(TYPE_STATUS_BAR);
Dianne Hackbornabe0da02009-09-18 01:55:39 -07001689 }
1690
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001691 @Override
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001692 public int getAboveUniverseLayer() {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001693 return windowTypeToLayerLw(TYPE_SYSTEM_ERROR);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001694 }
1695
Jose Lima9546b202014-07-02 17:21:51 -07001696 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001697 public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07001698 if (mHasNavigationBar) {
1699 // For a basic navigation bar, when we are in landscape mode we place
1700 // the navigation bar to the side.
Daniel Sandler4a066c52012-04-20 14:49:13 -04001701 if (mNavigationBarCanMove && fullWidth > fullHeight) {
1702 return fullWidth - mNavigationBarWidthForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07001703 }
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001704 }
1705 return fullWidth;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001706 }
1707
Jose Lima9546b202014-07-02 17:21:51 -07001708 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001709 public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07001710 if (mHasNavigationBar) {
1711 // For a basic navigation bar, when we are in portrait mode we place
1712 // the navigation bar to the bottom.
Daniel Sandler4a066c52012-04-20 14:49:13 -04001713 if (!mNavigationBarCanMove || fullWidth < fullHeight) {
1714 return fullHeight - mNavigationBarHeightForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07001715 }
1716 }
1717 return fullHeight;
Dianne Hackborn69cb8752011-05-19 18:13:32 -07001718 }
1719
Jose Lima9546b202014-07-02 17:21:51 -07001720 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001721 public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation) {
1722 return getNonDecorDisplayWidth(fullWidth, fullHeight, rotation);
Dianne Hackborn69cb8752011-05-19 18:13:32 -07001723 }
1724
Jose Lima9546b202014-07-02 17:21:51 -07001725 @Override
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001726 public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation) {
John Spurlock80f00c12013-06-13 11:10:51 -04001727 // There is a separate status bar at the top of the display. We don't count that as part
1728 // of the fixed decor, since it can hide; however, for purposes of configurations,
Dianne Hackborn077ee852012-04-09 16:27:07 -07001729 // we do want to exclude it since applications can't generally use that part
1730 // of the screen.
John Spurlock80f00c12013-06-13 11:10:51 -04001731 return getNonDecorDisplayHeight(fullWidth, fullHeight, rotation) - mStatusBarHeight;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001732 }
1733
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001734 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07001735 public boolean isForceHiding(WindowManager.LayoutParams attrs) {
1736 return (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 ||
Adrian Roos69e510d2014-07-13 14:57:59 +02001737 (isKeyguardHostWindow(attrs) && isKeyguardSecureIncludingHidden()) ||
1738 (attrs.type == TYPE_KEYGUARD_SCRIM);
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07001739 }
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001740
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001741 @Override
Jorim Jaggi0d674622014-05-21 01:34:15 +02001742 public boolean isKeyguardHostWindow(WindowManager.LayoutParams attrs) {
1743 return attrs.type == TYPE_STATUS_BAR;
1744 }
1745
1746 @Override
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07001747 public boolean canBeForceHidden(WindowState win, WindowManager.LayoutParams attrs) {
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001748 switch (attrs.type) {
1749 case TYPE_STATUS_BAR:
1750 case TYPE_NAVIGATION_BAR:
1751 case TYPE_WALLPAPER:
1752 case TYPE_DREAM:
1753 case TYPE_UNIVERSE_BACKGROUND:
Jim Miller5ecd8112013-01-09 18:50:26 -08001754 case TYPE_KEYGUARD_SCRIM:
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001755 return false;
1756 default:
1757 return true;
1758 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07001759 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001760
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001761 /** {@inheritDoc} */
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001762 @Override
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07001763 public View addStartingWindow(IBinder appToken, String packageName, int theme,
1764 CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes,
Adam Powell04fe6eb2013-05-31 14:39:48 -07001765 int icon, int logo, int windowFlags) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001766 if (!SHOW_STARTING_ANIMATIONS) {
1767 return null;
1768 }
1769 if (packageName == null) {
1770 return null;
1771 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001772
Mathias Jeppssond1443e92012-08-24 15:25:32 +02001773 WindowManager wm = null;
1774 View view = null;
1775
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001776 try {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001777 Context context = mContext;
Craig Mautner6fbda632012-07-03 09:26:39 -07001778 if (DEBUG_STARTING_WINDOW) Slog.d(TAG, "addStartingWindow " + packageName
1779 + ": nonLocalizedLabel=" + nonLocalizedLabel + " theme="
1780 + Integer.toHexString(theme));
Dianne Hackborn247fe742011-01-08 17:25:57 -08001781 if (theme != context.getThemeResId() || labelRes != 0) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001782 try {
1783 context = context.createPackageContext(packageName, 0);
Dianne Hackborn247fe742011-01-08 17:25:57 -08001784 context.setTheme(theme);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001785 } catch (PackageManager.NameNotFoundException e) {
1786 // Ignore
1787 }
1788 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001789
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001790 Window win = PolicyManager.makeNewWindow(context);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001791 final TypedArray ta = win.getWindowStyle();
1792 if (ta.getBoolean(
1793 com.android.internal.R.styleable.Window_windowDisablePreview, false)
1794 || ta.getBoolean(
1795 com.android.internal.R.styleable.Window_windowShowWallpaper,false)) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001796 return null;
1797 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001798
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001799 Resources r = context.getResources();
1800 win.setTitle(r.getText(labelRes, nonLocalizedLabel));
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001801
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001802 win.setType(
1803 WindowManager.LayoutParams.TYPE_APPLICATION_STARTING);
1804 // Force the window flags: this is a fake window, so it is not really
1805 // touchable or focusable by the user. We also add in the ALT_FOCUSABLE_IM
1806 // flag because we do know that the next window will take input
1807 // focus, so we want to get the IME window up on top of us right away.
1808 win.setFlags(
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08001809 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001810 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
1811 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
1812 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08001813 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001814 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
1815 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
1816 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001817
Adam Powell04fe6eb2013-05-31 14:39:48 -07001818 win.setDefaultIcon(icon);
1819 win.setDefaultLogo(logo);
1820
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001821 win.setLayout(WindowManager.LayoutParams.MATCH_PARENT,
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07001822 WindowManager.LayoutParams.MATCH_PARENT);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001823
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001824 final WindowManager.LayoutParams params = win.getAttributes();
1825 params.token = appToken;
1826 params.packageName = packageName;
1827 params.windowAnimations = win.getWindowStyle().getResourceId(
1828 com.android.internal.R.styleable.Window_windowAnimationStyle, 0);
Dianne Hackborn5d927c22011-09-02 12:22:18 -07001829 params.privateFlags |=
1830 WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED;
Craig Mautner88400d32012-09-30 12:35:45 -07001831 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
Adam Lesinski95c42972013-10-02 10:13:27 -07001832
1833 if (!compatInfo.supportsScreen()) {
1834 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
1835 }
1836
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001837 params.setTitle("Starting " + packageName);
1838
Mathias Jeppssond1443e92012-08-24 15:25:32 +02001839 wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
1840 view = win.getDecorView();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001841
1842 if (win.isFloating()) {
1843 // Whoops, there is no way to display an animation/preview
1844 // of such a thing! After all that work... let's skip it.
1845 // (Note that we must do this here because it is in
1846 // getDecorView() where the theme is evaluated... maybe
1847 // we should peek the floating attribute from the theme
1848 // earlier.)
1849 return null;
1850 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001851
Craig Mautner6fbda632012-07-03 09:26:39 -07001852 if (DEBUG_STARTING_WINDOW) Slog.d(
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001853 TAG, "Adding starting window for " + packageName
1854 + " / " + appToken + ": "
1855 + (view.getParent() != null ? view : null));
1856
1857 wm.addView(view, params);
1858
1859 // Only return the view if it was successfully added to the
1860 // window manager... which we can tell by it having a parent.
1861 return view.getParent() != null ? view : null;
Jeff Brown98365d72012-08-19 20:30:52 -07001862 } catch (WindowManager.BadTokenException e) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001863 // ignore
Craig Mautner42bf39e2014-02-21 16:46:22 -08001864 Log.w(TAG, appToken + " already running, starting window not displayed. " +
1865 e.getMessage());
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001866 } catch (RuntimeException e) {
1867 // don't crash if something else bad happens, for example a
1868 // failure loading resources because we are loading from an app
1869 // on external storage that has been unmounted.
1870 Log.w(TAG, appToken + " failed creating starting window", e);
Mathias Jeppssond1443e92012-08-24 15:25:32 +02001871 } finally {
1872 if (view != null && view.getParent() == null) {
1873 Log.w(TAG, "view not successfully added to wm, removing view");
1874 wm.removeViewImmediate(view);
1875 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001876 }
1877
1878 return null;
1879 }
1880
1881 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07001882 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001883 public void removeStartingWindow(IBinder appToken, View window) {
Craig Mautner6fbda632012-07-03 09:26:39 -07001884 if (DEBUG_STARTING_WINDOW) {
1885 RuntimeException e = new RuntimeException("here");
1886 e.fillInStackTrace();
1887 Log.v(TAG, "Removing starting window for " + appToken + ": " + window, e);
1888 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001889
1890 if (window != null) {
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001891 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001892 wm.removeView(window);
1893 }
1894 }
1895
1896 /**
1897 * Preflight adding a window to the system.
RoboErik8a2cfc32014-05-16 11:19:38 -07001898 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001899 * Currently enforces that three window types are singletons:
1900 * <ul>
1901 * <li>STATUS_BAR_TYPE</li>
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001902 * <li>KEYGUARD_TYPE</li>
1903 * </ul>
RoboErik8a2cfc32014-05-16 11:19:38 -07001904 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001905 * @param win The window to be added
1906 * @param attrs Information about the window to be added
RoboErik8a2cfc32014-05-16 11:19:38 -07001907 *
Jeff Brown98365d72012-08-19 20:30:52 -07001908 * @return If ok, WindowManagerImpl.ADD_OKAY. If too many singletons,
1909 * WindowManagerImpl.ADD_MULTIPLE_SINGLETON
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001910 */
Jose Lima9546b202014-07-02 17:21:51 -07001911 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001912 public int prepareAddWindowLw(WindowState win, WindowManager.LayoutParams attrs) {
1913 switch (attrs.type) {
1914 case TYPE_STATUS_BAR:
Joe Onorato8bc6c512010-06-04 16:21:12 -04001915 mContext.enforceCallingOrSelfPermission(
1916 android.Manifest.permission.STATUS_BAR_SERVICE,
1917 "PhoneWindowManager");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001918 if (mStatusBar != null) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001919 if (mStatusBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07001920 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001921 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001922 }
1923 mStatusBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04001924 mStatusBarController.setWindow(win);
John Spurlock8fdfe622014-05-21 17:10:10 -04001925 mKeyguardDelegate.hideScrim();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001926 break;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04001927 case TYPE_NAVIGATION_BAR:
1928 mContext.enforceCallingOrSelfPermission(
1929 android.Manifest.permission.STATUS_BAR_SERVICE,
1930 "PhoneWindowManager");
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001931 if (mNavigationBar != null) {
1932 if (mNavigationBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07001933 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001934 }
1935 }
Daniel Sandler8956dbb2011-04-22 07:55:02 -04001936 mNavigationBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04001937 mNavigationBarController.setWindow(win);
Craig Mautnereda67292013-04-28 13:50:14 -07001938 if (DEBUG_LAYOUT) Slog.i(TAG, "NAVIGATION BAR: " + mNavigationBar);
Daniel Sandler8956dbb2011-04-22 07:55:02 -04001939 break;
Jim Millere898ac52012-04-06 17:10:57 -07001940 case TYPE_NAVIGATION_BAR_PANEL:
1941 mContext.enforceCallingOrSelfPermission(
1942 android.Manifest.permission.STATUS_BAR_SERVICE,
1943 "PhoneWindowManager");
1944 break;
Dianne Hackborn08743722009-12-21 12:16:51 -08001945 case TYPE_STATUS_BAR_PANEL:
Joe Onorato8bc6c512010-06-04 16:21:12 -04001946 mContext.enforceCallingOrSelfPermission(
1947 android.Manifest.permission.STATUS_BAR_SERVICE,
1948 "PhoneWindowManager");
Dianne Hackborn08743722009-12-21 12:16:51 -08001949 break;
Joe Onorato29fc2c92010-11-24 10:26:50 -08001950 case TYPE_STATUS_BAR_SUB_PANEL:
1951 mContext.enforceCallingOrSelfPermission(
1952 android.Manifest.permission.STATUS_BAR_SERVICE,
1953 "PhoneWindowManager");
Joe Onorato29fc2c92010-11-24 10:26:50 -08001954 break;
Jim Miller5ecd8112013-01-09 18:50:26 -08001955 case TYPE_KEYGUARD_SCRIM:
Jim Miller25190572013-02-28 17:36:24 -08001956 if (mKeyguardScrim != null) {
1957 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
1958 }
Jim Miller5ecd8112013-01-09 18:50:26 -08001959 mKeyguardScrim = win;
1960 break;
1961
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001962 }
Jeff Brown98365d72012-08-19 20:30:52 -07001963 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001964 }
1965
1966 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07001967 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001968 public void removeWindowLw(WindowState win) {
1969 if (mStatusBar == win) {
1970 mStatusBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04001971 mStatusBarController.setWindow(null);
Jim Millerc0b676d2013-03-22 16:11:08 -07001972 mKeyguardDelegate.showScrim();
Jim Miller5ecd8112013-01-09 18:50:26 -08001973 } else if (mKeyguardScrim == win) {
1974 Log.v(TAG, "Removing keyguard scrim");
1975 mKeyguardScrim = null;
1976 } if (mNavigationBar == win) {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04001977 mNavigationBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04001978 mNavigationBarController.setWindow(null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001979 }
1980 }
1981
1982 static final boolean PRINT_ANIM = false;
RoboErik8a2cfc32014-05-16 11:19:38 -07001983
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001984 /** {@inheritDoc} */
Craig Mautner4b71aa12012-12-27 17:20:01 -08001985 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001986 public int selectAnimationLw(WindowState win, int transit) {
1987 if (PRINT_ANIM) Log.i(TAG, "selectAnimation in " + win
1988 + ": transit=" + transit);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001989 if (win == mStatusBar) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001990 boolean isKeyguard = (win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001991 if (transit == TRANSIT_EXIT
1992 || transit == TRANSIT_HIDE) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001993 return isKeyguard ? -1 : R.anim.dock_top_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001994 } else if (transit == TRANSIT_ENTER
1995 || transit == TRANSIT_SHOW) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001996 return isKeyguard ? -1 : R.anim.dock_top_enter;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001997 }
1998 } else if (win == mNavigationBar) {
1999 // This can be on either the bottom or the right.
2000 if (mNavigationBarOnBottom) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08002001 if (transit == TRANSIT_EXIT
2002 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002003 return R.anim.dock_bottom_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002004 } else if (transit == TRANSIT_ENTER
2005 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002006 return R.anim.dock_bottom_enter;
2007 }
2008 } else {
Craig Mautner4b71aa12012-12-27 17:20:01 -08002009 if (transit == TRANSIT_EXIT
2010 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002011 return R.anim.dock_right_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002012 } else if (transit == TRANSIT_ENTER
2013 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002014 return R.anim.dock_right_enter;
2015 }
2016 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08002017 }
2018
2019 if (transit == TRANSIT_PREVIEW_DONE) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002020 if (win.hasAppShownWindows()) {
2021 if (PRINT_ANIM) Log.i(TAG, "**** STARTING EXIT");
2022 return com.android.internal.R.anim.app_starting_exit;
2023 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07002024 } else if (win.getAttrs().type == TYPE_DREAM && mDreamingLockscreen
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002025 && transit == TRANSIT_ENTER) {
2026 // Special case: we are animating in a dream, while the keyguard
2027 // is shown. We don't want an animation on the dream, because
2028 // we need it shown immediately with the keyguard animating away
2029 // to reveal it.
2030 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002031 }
2032
2033 return 0;
2034 }
2035
Craig Mautner3c174372013-02-21 17:54:37 -08002036 @Override
2037 public void selectRotationAnimationLw(int anim[]) {
2038 if (PRINT_ANIM) Slog.i(TAG, "selectRotationAnimation mTopFullscreen="
2039 + mTopFullscreenOpaqueWindowState + " rotationAnimation="
2040 + (mTopFullscreenOpaqueWindowState == null ?
2041 "0" : mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation));
2042 if (mTopFullscreenOpaqueWindowState != null && mTopIsFullscreen) {
2043 switch (mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation) {
2044 case ROTATION_ANIMATION_CROSSFADE:
2045 anim[0] = R.anim.rotation_animation_xfade_exit;
2046 anim[1] = R.anim.rotation_animation_enter;
2047 break;
2048 case ROTATION_ANIMATION_JUMPCUT:
2049 anim[0] = R.anim.rotation_animation_jump_exit;
2050 anim[1] = R.anim.rotation_animation_enter;
2051 break;
2052 case ROTATION_ANIMATION_ROTATE:
2053 default:
2054 anim[0] = anim[1] = 0;
2055 break;
2056 }
2057 } else {
2058 anim[0] = anim[1] = 0;
2059 }
2060 }
2061
2062 @Override
2063 public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId,
2064 boolean forceDefault) {
2065 switch (exitAnimId) {
2066 case R.anim.rotation_animation_xfade_exit:
2067 case R.anim.rotation_animation_jump_exit:
2068 // These are the only cases that matter.
2069 if (forceDefault) {
2070 return false;
2071 }
2072 int anim[] = new int[2];
2073 selectRotationAnimationLw(anim);
2074 return (exitAnimId == anim[0] && enterAnimId == anim[1]);
2075 default:
2076 return true;
2077 }
2078 }
2079
2080 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002081 public Animation createForceHideEnterAnimation(boolean onWallpaper,
2082 boolean goingToNotificationShade) {
2083 if (goingToNotificationShade) {
2084 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_behind_enter_fade_in);
2085 } else if (onWallpaper) {
Jorim Jaggi76a16232014-08-08 17:00:47 +02002086 Animation a = AnimationUtils.loadAnimation(mContext,
2087 R.anim.lock_screen_behind_enter_wallpaper);
2088 AnimationSet set = (AnimationSet) a;
2089
2090 // TODO: Use XML interpolators when we have log interpolators available in XML.
2091 set.getAnimations().get(0).setInterpolator(mLogDecelerateInterpolator);
2092 set.getAnimations().get(1).setInterpolator(mLogDecelerateInterpolator);
Jorim Jaggi76a16232014-08-08 17:00:47 +02002093 return set;
2094 } else {
2095 Animation a = AnimationUtils.loadAnimation(mContext,
2096 R.anim.lock_screen_behind_enter);
2097 AnimationSet set = (AnimationSet) a;
2098
2099 // TODO: Use XML interpolators when we have log interpolators available in XML.
2100 set.getAnimations().get(0).setInterpolator(mLogDecelerateInterpolator);
2101 return set;
2102 }
2103 }
2104
2105
2106 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002107 public Animation createForceHideWallpaperExitAnimation(boolean goingToNotificationShade) {
2108 if (goingToNotificationShade) {
2109 return null;
2110 } else {
2111 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_wallpaper_exit);
2112 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002113 }
John Spurlockc8b46ca2013-04-08 12:59:26 -04002114
2115 private static void awakenDreams() {
2116 IDreamManager dreamManager = getDreamManager();
2117 if (dreamManager != null) {
2118 try {
2119 dreamManager.awaken();
2120 } catch (RemoteException e) {
2121 // fine, stay asleep then
2122 }
2123 }
2124 }
2125
2126 static IDreamManager getDreamManager() {
2127 return IDreamManager.Stub.asInterface(
2128 ServiceManager.checkService(DreamService.DREAM_SERVICE));
2129 }
2130
Santos Cordon9eb45932014-06-27 12:28:43 -07002131 TelecommManager getTelecommService() {
2132 return (TelecommManager) mContext.getSystemService(Context.TELECOMM_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002133 }
2134
Jeff Brown4d396052010-10-29 21:50:21 -07002135 static IAudioService getAudioService() {
2136 IAudioService audioService = IAudioService.Stub.asInterface(
2137 ServiceManager.checkService(Context.AUDIO_SERVICE));
2138 if (audioService == null) {
2139 Log.w(TAG, "Unable to find IAudioService interface.");
2140 }
2141 return audioService;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002142 }
2143
2144 boolean keyguardOn() {
2145 return keyguardIsShowingTq() || inKeyguardRestrictedKeyInputMode();
2146 }
2147
2148 private static final int[] WINDOW_TYPES_WHERE_HOME_DOESNT_WORK = {
2149 WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
2150 WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
2151 };
2152
2153 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002154 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002155 public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002156 final boolean keyguardOn = keyguardOn();
Jeff Brown1f245102010-11-18 20:53:46 -08002157 final int keyCode = event.getKeyCode();
2158 final int repeatCount = event.getRepeatCount();
2159 final int metaState = event.getMetaState();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002160 final int flags = event.getFlags();
Jeff Brown1f245102010-11-18 20:53:46 -08002161 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
2162 final boolean canceled = event.isCanceled();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002163
Jeff Brown40013652012-05-16 21:22:36 -07002164 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002165 Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount="
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002166 + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed
2167 + " canceled=" + canceled);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002168 }
2169
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002170 // If we think we might have a volume down & power key chord on the way
2171 // but we're not sure, then tell the dispatcher to wait a little while and
2172 // try again later before dispatching.
Christopher Tatee90585f2012-03-05 18:56:25 -08002173 if (mScreenshotChordEnabled && (flags & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002174 if (mVolumeDownKeyTriggered && !mPowerKeyTriggered) {
2175 final long now = SystemClock.uptimeMillis();
2176 final long timeoutTime = mVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS;
2177 if (now < timeoutTime) {
2178 return timeoutTime - now;
2179 }
2180 }
2181 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
2182 && mVolumeDownKeyConsumedByScreenshotChord) {
2183 if (!down) {
2184 mVolumeDownKeyConsumedByScreenshotChord = false;
2185 }
2186 return -1;
2187 }
2188 }
2189
Michael Wright6a62e552014-06-03 19:19:48 -07002190 // Cancel any pending meta actions if we see any other keys being pressed between the down
2191 // of the meta key and its corresponding up.
Michael Wright251e35d2014-08-22 15:40:27 -07002192 if (mPendingMetaAction && !KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07002193 mPendingMetaAction = false;
2194 }
2195
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002196 // First we always handle the home key here, so applications
2197 // can never break it, although if keyguard is on, we do let
2198 // it handle it, because that gives us the correct 5 second
2199 // timeout.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002200 if (keyCode == KeyEvent.KEYCODE_HOME) {
Michael Jurka7f2668c2012-03-27 07:49:52 -07002201
Jeff Brown49ed71d2010-12-06 17:13:33 -08002202 // If we have released the home key, and didn't do anything else
2203 // while it was pressed, then it is time to go home!
Michael Jurka7f2668c2012-03-27 07:49:52 -07002204 if (!down) {
Jeff Browncaca8812013-05-09 13:34:33 -07002205 cancelPreloadRecentApps();
2206
Jeff Brown49ed71d2010-12-06 17:13:33 -08002207 mHomePressed = false;
Jeff Browncaca8812013-05-09 13:34:33 -07002208 if (mHomeConsumed) {
2209 mHomeConsumed = false;
Michael Jurka7f2668c2012-03-27 07:49:52 -07002210 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002211 }
Jeff Browncaca8812013-05-09 13:34:33 -07002212
2213 if (canceled) {
2214 Log.i(TAG, "Ignoring HOME; event canceled.");
2215 return -1;
2216 }
2217
2218 // If an incoming call is ringing, HOME is totally disabled.
Santos Cordon9eb45932014-06-27 12:28:43 -07002219 // (The user is already on the InCallUI at this point,
Jeff Browncaca8812013-05-09 13:34:33 -07002220 // and his ONLY options are to answer or reject the call.)
Santos Cordon9eb45932014-06-27 12:28:43 -07002221 TelecommManager telecommManager = getTelecommService();
2222 if (telecommManager != null && telecommManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07002223 Log.i(TAG, "Ignoring HOME; there's a ringing incoming call.");
2224 return -1;
Jeff Browncaca8812013-05-09 13:34:33 -07002225 }
2226
2227 // Delay handling home if a double-tap is possible.
2228 if (mDoubleTapOnHomeBehavior != DOUBLE_TAP_HOME_NOTHING) {
2229 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); // just in case
2230 mHomeDoubleTapPending = true;
2231 mHandler.postDelayed(mHomeDoubleTapTimeoutRunnable,
2232 ViewConfiguration.getDoubleTapTimeout());
2233 return -1;
2234 }
2235
Jose Lima9546b202014-07-02 17:21:51 -07002236 // If there's a dream running then use home to escape the dream
2237 // but don't actually go home.
2238 if (mDreamManagerInternal != null && mDreamManagerInternal.isDreaming()) {
Jeff Brownf6d46682014-07-17 22:44:20 -07002239 mDreamManagerInternal.stopDream(false /*immediate*/);
Jose Lima9546b202014-07-02 17:21:51 -07002240 return -1;
2241 }
2242
Jeff Browncaca8812013-05-09 13:34:33 -07002243 // Go home!
2244 launchHomeFromHotKey();
2245 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002246 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002247
2248 // If a system window has focus, then it doesn't make sense
2249 // right now to interact with applications.
2250 WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null;
2251 if (attrs != null) {
2252 final int type = attrs.type;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002253 if (type == WindowManager.LayoutParams.TYPE_KEYGUARD_SCRIM
2254 || type == WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG
2255 || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002256 // the "app" is keyguard, so give it the key
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002257 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002258 }
2259 final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length;
2260 for (int i=0; i<typeCount; i++) {
2261 if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) {
2262 // don't do anything, but also don't pass it to the app
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002263 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002264 }
2265 }
2266 }
Jeff Browncaca8812013-05-09 13:34:33 -07002267
2268 // Remember that home is pressed and handle special actions.
2269 if (repeatCount == 0) {
2270 mHomePressed = true;
2271 if (mHomeDoubleTapPending) {
2272 mHomeDoubleTapPending = false;
2273 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable);
2274 handleDoubleTapOnHome();
2275 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI
2276 || mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
2277 preloadRecentApps();
Michael Jurka7f2668c2012-03-27 07:49:52 -07002278 }
Jeff Browncaca8812013-05-09 13:34:33 -07002279 } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) {
2280 if (!keyguardOn) {
2281 handleLongPressOnHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002282 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002283 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002284 return -1;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002285 } else if (keyCode == KeyEvent.KEYCODE_MENU) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002286 // Hijack modified menu keys for debugging features
2287 final int chordBug = KeyEvent.META_SHIFT_ON;
2288
2289 if (down && repeatCount == 0) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002290 if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002291 Intent intent = new Intent(Intent.ACTION_BUG_REPORT);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002292 mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT,
2293 null, null, null, 0, null, null);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002294 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002295 } else if (SHOW_PROCESSES_ON_ALT_MENU &&
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002296 (metaState & KeyEvent.META_ALT_ON) == KeyEvent.META_ALT_ON) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002297 Intent service = new Intent();
2298 service.setClassName(mContext, "com.android.server.LoadAverageService");
2299 ContentResolver res = mContext.getContentResolver();
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002300 boolean shown = Settings.Global.getInt(
2301 res, Settings.Global.SHOW_PROCESSES, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002302 if (!shown) {
2303 mContext.startService(service);
2304 } else {
2305 mContext.stopService(service);
2306 }
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002307 Settings.Global.putInt(
2308 res, Settings.Global.SHOW_PROCESSES, shown ? 0 : 1);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002309 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002310 }
2311 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002312 } else if (keyCode == KeyEvent.KEYCODE_SEARCH) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002313 if (down) {
2314 if (repeatCount == 0) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002315 mSearchKeyShortcutPending = true;
2316 mConsumeSearchKeyUp = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002317 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002318 } else {
2319 mSearchKeyShortcutPending = false;
2320 if (mConsumeSearchKeyUp) {
2321 mConsumeSearchKeyUp = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002322 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002323 }
2324 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002325 return 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002326 } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) {
Michael Wrightc9ebea72013-01-16 19:25:02 -08002327 if (!keyguardOn) {
Jeff Browncaca8812013-05-09 13:34:33 -07002328 if (down && repeatCount == 0) {
2329 preloadRecentApps();
2330 } else if (!down) {
2331 toggleRecentApps();
Michael Wrightc9ebea72013-01-16 19:25:02 -08002332 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002333 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002334 return -1;
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002335 } else if (keyCode == KeyEvent.KEYCODE_ASSIST) {
2336 if (down) {
2337 if (repeatCount == 0) {
2338 mAssistKeyLongPressed = false;
2339 } else if (repeatCount == 1) {
2340 mAssistKeyLongPressed = true;
2341 if (!keyguardOn) {
2342 launchAssistLongPressAction();
2343 }
2344 }
2345 } else {
2346 if (mAssistKeyLongPressed) {
2347 mAssistKeyLongPressed = false;
2348 } else {
2349 if (!keyguardOn) {
2350 launchAssistAction();
2351 }
2352 }
2353 }
2354 return -1;
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002355 } else if (keyCode == KeyEvent.KEYCODE_VOICE_ASSIST) {
2356 if (!down) {
2357 Intent voiceIntent;
Michael Wright869a67c2014-08-26 19:33:06 -07002358 if (!keyguardOn) {
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002359 voiceIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
2360 } else {
2361 voiceIntent = new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
Michael Wright869a67c2014-08-26 19:33:06 -07002362 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, true);
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002363 }
2364 mContext.startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
2365 }
Jeff Sharkey2991fa32012-12-05 18:06:43 -08002366 } else if (keyCode == KeyEvent.KEYCODE_SYSRQ) {
2367 if (down && repeatCount == 0) {
2368 mHandler.post(mScreenshotRunnable);
2369 }
2370 return -1;
Michael Wrightb854e242013-02-05 17:54:02 -08002371 } else if (keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP
2372 || keyCode == KeyEvent.KEYCODE_BRIGHTNESS_DOWN) {
2373 if (down) {
2374 int direction = keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP ? 1 : -1;
2375
2376 // Disable autobrightness if it's on
2377 int auto = Settings.System.getIntForUser(
2378 mContext.getContentResolver(),
2379 Settings.System.SCREEN_BRIGHTNESS_MODE,
2380 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2381 UserHandle.USER_CURRENT_OR_SELF);
2382 if (auto != 0) {
2383 Settings.System.putIntForUser(mContext.getContentResolver(),
2384 Settings.System.SCREEN_BRIGHTNESS_MODE,
2385 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2386 UserHandle.USER_CURRENT_OR_SELF);
2387 }
2388
2389 int min = mPowerManager.getMinimumScreenBrightnessSetting();
2390 int max = mPowerManager.getMaximumScreenBrightnessSetting();
2391 int step = (max - min + BRIGHTNESS_STEPS - 1) / BRIGHTNESS_STEPS * direction;
2392 int brightness = Settings.System.getIntForUser(mContext.getContentResolver(),
2393 Settings.System.SCREEN_BRIGHTNESS,
2394 mPowerManager.getDefaultScreenBrightnessSetting(),
2395 UserHandle.USER_CURRENT_OR_SELF);
2396 brightness += step;
2397 // Make sure we don't go beyond the limits.
2398 brightness = Math.min(max, brightness);
2399 brightness = Math.max(min, brightness);
2400
2401 Settings.System.putIntForUser(mContext.getContentResolver(),
2402 Settings.System.SCREEN_BRIGHTNESS, brightness,
2403 UserHandle.USER_CURRENT_OR_SELF);
Alan Viverette5a399492014-07-14 16:19:38 -07002404 mContext.startActivityAsUser(new Intent(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG),
2405 UserHandle.CURRENT_OR_SELF);
Michael Wrightb854e242013-02-05 17:54:02 -08002406 }
2407 return -1;
Michael Wrightce0c13a2014-07-30 10:49:21 -07002408 } else if (KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07002409 if (down) {
2410 mPendingMetaAction = true;
2411 } else if (mPendingMetaAction) {
Michael Wright8ab940a2014-09-01 11:01:27 -07002412 launchAssistAction(Intent.EXTRA_ASSIST_INPUT_HINT_KEYBOARD);
Michael Wright6a62e552014-06-03 19:19:48 -07002413 }
2414 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002415 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002416
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002417 // Shortcuts are invoked through Search+key, so intercept those here
Jeff Browncaab4d02010-12-09 22:13:41 -08002418 // Any printing key that is chorded with Search should be consumed
2419 // even if no shortcut was invoked. This prevents text from being
2420 // inadvertently inserted when using a keyboard that has built-in macro
2421 // shortcut keys (that emit Search+x) and some of them are not registered.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002422 if (mSearchKeyShortcutPending) {
Jeff Browncaab4d02010-12-09 22:13:41 -08002423 final KeyCharacterMap kcm = event.getKeyCharacterMap();
2424 if (kcm.isPrintingKey(keyCode)) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002425 mConsumeSearchKeyUp = true;
2426 mSearchKeyShortcutPending = false;
Jeff Browncaab4d02010-12-09 22:13:41 -08002427 if (down && repeatCount == 0 && !keyguardOn) {
2428 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState);
2429 if (shortcutIntent != null) {
2430 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002431 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002432 mContext.startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002433 } catch (ActivityNotFoundException ex) {
2434 Slog.w(TAG, "Dropping shortcut key combination because "
2435 + "the activity to which it is registered was not found: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002436 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode), ex);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002437 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002438 } else {
2439 Slog.i(TAG, "Dropping unregistered shortcut key combination: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002440 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002441 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002442 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002443 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002444 }
2445 }
2446
Jeff Brown68b909d2011-12-07 16:36:01 -08002447 // Invoke shortcuts using Meta.
Jeff Brown602ab322012-05-16 13:33:47 -07002448 if (down && repeatCount == 0 && !keyguardOn
Jeff Brown68b909d2011-12-07 16:36:01 -08002449 && (metaState & KeyEvent.META_META_ON) != 0) {
2450 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brown602ab322012-05-16 13:33:47 -07002451 if (kcm.isPrintingKey(keyCode)) {
2452 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode,
2453 metaState & ~(KeyEvent.META_META_ON
2454 | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON));
2455 if (shortcutIntent != null) {
2456 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2457 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002458 mContext.startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brown602ab322012-05-16 13:33:47 -07002459 } catch (ActivityNotFoundException ex) {
2460 Slog.w(TAG, "Dropping shortcut key combination because "
2461 + "the activity to which it is registered was not found: "
2462 + "META+" + KeyEvent.keyCodeToString(keyCode), ex);
2463 }
2464 return -1;
Jeff Brown68b909d2011-12-07 16:36:01 -08002465 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002466 }
2467 }
2468
Jeff Brown6651a632011-11-28 12:59:11 -08002469 // Handle application launch keys.
Jeff Brown602ab322012-05-16 13:33:47 -07002470 if (down && repeatCount == 0 && !keyguardOn) {
Jeff Brown6651a632011-11-28 12:59:11 -08002471 String category = sApplicationLaunchKeyCategories.get(keyCode);
2472 if (category != null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -08002473 Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category);
Jeff Brown6651a632011-11-28 12:59:11 -08002474 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2475 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002476 mContext.startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brown6651a632011-11-28 12:59:11 -08002477 } catch (ActivityNotFoundException ex) {
2478 Slog.w(TAG, "Dropping application launch key because "
2479 + "the activity to which it is registered was not found: "
2480 + "keyCode=" + keyCode + ", category=" + category, ex);
2481 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002482 return -1;
Jeff Brown6651a632011-11-28 12:59:11 -08002483 }
2484 }
2485
Michael Wright61c46752014-08-21 16:57:33 -07002486 // Display task switcher for ALT-TAB.
Jeff Brown68b909d2011-12-07 16:36:01 -08002487 if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_TAB) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002488 if (mRecentAppsHeldModifiers == 0 && !keyguardOn) {
Jeff Brown68b909d2011-12-07 16:36:01 -08002489 final int shiftlessModifiers = event.getModifiers() & ~KeyEvent.META_SHIFT_MASK;
Michael Wright61c46752014-08-21 16:57:33 -07002490 if (KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_ALT_ON)) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002491 mRecentAppsHeldModifiers = shiftlessModifiers;
2492 showRecentApps(true);
Jeff Brown68b909d2011-12-07 16:36:01 -08002493 return -1;
2494 }
2495 }
Winson Chung1e8d71b2014-05-16 17:05:22 -07002496 } else if (!down && mRecentAppsHeldModifiers != 0
2497 && (metaState & mRecentAppsHeldModifiers) == 0) {
2498 mRecentAppsHeldModifiers = 0;
Winson Chungcdcd4872014-08-05 18:00:13 -07002499 hideRecentApps(true, false);
Jeff Brown68b909d2011-12-07 16:36:01 -08002500 }
2501
Jeff Browncf39bdf2012-05-18 14:41:19 -07002502 // Handle keyboard language switching.
2503 if (down && repeatCount == 0
2504 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2505 || (keyCode == KeyEvent.KEYCODE_SPACE
2506 && (metaState & KeyEvent.META_CTRL_MASK) != 0))) {
2507 int direction = (metaState & KeyEvent.META_SHIFT_MASK) != 0 ? -1 : 1;
2508 mWindowManagerFuncs.switchKeyboardLayout(event.getDeviceId(), direction);
2509 return -1;
2510 }
2511 if (mLanguageSwitchKeyPressed && !down
2512 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2513 || keyCode == KeyEvent.KEYCODE_SPACE)) {
2514 mLanguageSwitchKeyPressed = false;
2515 return -1;
2516 }
2517
Justin Kohd378ad72013-04-01 12:18:26 -07002518 if (mGlobalKeyManager.handleGlobalKey(mContext, keyCode, event)) {
2519 return -1;
2520 }
2521
Michael Wright6a62e552014-06-03 19:19:48 -07002522 // Reserve all the META modifier combos for system behavior
Michael Wrightce0c13a2014-07-30 10:49:21 -07002523 if ((metaState & KeyEvent.META_META_ON) != 0) {
Michael Wright6a62e552014-06-03 19:19:48 -07002524 return -1;
2525 }
2526
Jeff Brown68b909d2011-12-07 16:36:01 -08002527 // Let the application handle the key.
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002528 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002529 }
2530
Jeff Brown3915bb82010-11-05 15:02:16 -07002531 /** {@inheritDoc} */
2532 @Override
Jeff Brown49ed71d2010-12-06 17:13:33 -08002533 public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown54875002011-04-06 15:33:01 -07002534 // Note: This method is only called if the initial down was unhandled.
Jeff Brown40013652012-05-16 21:22:36 -07002535 if (DEBUG_INPUT) {
Jeff Brown1f245102010-11-18 20:53:46 -08002536 Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction()
2537 + ", flags=" + event.getFlags()
2538 + ", keyCode=" + event.getKeyCode()
2539 + ", scanCode=" + event.getScanCode()
2540 + ", metaState=" + event.getMetaState()
2541 + ", repeatCount=" + event.getRepeatCount()
2542 + ", policyFlags=" + policyFlags);
Jeff Brown3915bb82010-11-05 15:02:16 -07002543 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002544
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002545 KeyEvent fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002546 if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
2547 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002548 final int keyCode = event.getKeyCode();
2549 final int metaState = event.getMetaState();
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002550 final boolean initialDown = event.getAction() == KeyEvent.ACTION_DOWN
2551 && event.getRepeatCount() == 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002552
Jeff Brown54875002011-04-06 15:33:01 -07002553 // Check for fallback actions specified by the key character map.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002554 final FallbackAction fallbackAction;
2555 if (initialDown) {
2556 fallbackAction = kcm.getFallbackAction(keyCode, metaState);
2557 } else {
2558 fallbackAction = mFallbackActions.get(keyCode);
2559 }
2560
2561 if (fallbackAction != null) {
Jeff Brown40013652012-05-16 21:22:36 -07002562 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002563 Slog.d(TAG, "Fallback: keyCode=" + fallbackAction.keyCode
2564 + " metaState=" + Integer.toHexString(fallbackAction.metaState));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002565 }
2566
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002567 final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK;
2568 fallbackEvent = KeyEvent.obtain(
Jeff Brown49ed71d2010-12-06 17:13:33 -08002569 event.getDownTime(), event.getEventTime(),
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002570 event.getAction(), fallbackAction.keyCode,
2571 event.getRepeatCount(), fallbackAction.metaState,
Jeff Brown49ed71d2010-12-06 17:13:33 -08002572 event.getDeviceId(), event.getScanCode(),
2573 flags, event.getSource(), null);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002574
2575 if (!interceptFallback(win, fallbackEvent, policyFlags)) {
2576 fallbackEvent.recycle();
2577 fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002578 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002579
2580 if (initialDown) {
2581 mFallbackActions.put(keyCode, fallbackAction);
2582 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2583 mFallbackActions.remove(keyCode);
2584 fallbackAction.recycle();
2585 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002586 }
2587 }
2588
Jeff Brown40013652012-05-16 21:22:36 -07002589 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002590 if (fallbackEvent == null) {
2591 Slog.d(TAG, "No fallback.");
2592 } else {
2593 Slog.d(TAG, "Performing fallback: " + fallbackEvent);
2594 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002595 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002596 return fallbackEvent;
Jeff Brown3915bb82010-11-05 15:02:16 -07002597 }
2598
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002599 private boolean interceptFallback(WindowState win, KeyEvent fallbackEvent, int policyFlags) {
Jeff Brown037c33e2014-04-09 00:31:55 -07002600 int actions = interceptKeyBeforeQueueing(fallbackEvent, policyFlags);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002601 if ((actions & ACTION_PASS_TO_USER) != 0) {
2602 long delayMillis = interceptKeyBeforeDispatching(
2603 win, fallbackEvent, policyFlags);
2604 if (delayMillis == 0) {
2605 return true;
2606 }
2607 }
2608 return false;
Jeff Brown6f2fba42011-02-19 01:08:02 -08002609 }
2610
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002611 private void launchAssistLongPressAction() {
2612 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
2613 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
2614
2615 // launch the search activity
2616 Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS);
2617 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2618 try {
RoboErik8a2cfc32014-05-16 11:19:38 -07002619 // TODO: This only stops the factory-installed search manager.
Jim Miller45308b12012-06-18 19:23:39 -07002620 // Need to formalize an API to handle others
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002621 SearchManager searchManager = getSearchManager();
2622 if (searchManager != null) {
2623 searchManager.stopSearch();
2624 }
Michael Wright43e27f72013-04-10 14:06:48 -07002625 mContext.startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002626 } catch (ActivityNotFoundException e) {
2627 Slog.w(TAG, "No activity to handle assist long press action.", e);
2628 }
2629 }
2630
2631 private void launchAssistAction() {
Michael Wright8ab940a2014-09-01 11:01:27 -07002632 launchAssistAction(null);
2633 }
2634
2635 private void launchAssistAction(String hint) {
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002636 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
Amith Yamasanic1d07a42012-08-14 09:32:02 -07002637 Intent intent = ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE))
Dianne Hackbornf9c5e0f2013-01-23 14:39:13 -08002638 .getAssistIntent(mContext, true, UserHandle.USER_CURRENT);
Jim Miller45308b12012-06-18 19:23:39 -07002639 if (intent != null) {
Michael Wright8ab940a2014-09-01 11:01:27 -07002640 if (hint != null) {
2641 intent.putExtra(hint, true);
2642 }
Jim Miller45308b12012-06-18 19:23:39 -07002643 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
2644 | Intent.FLAG_ACTIVITY_SINGLE_TOP
2645 | Intent.FLAG_ACTIVITY_CLEAR_TOP);
2646 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002647 mContext.startActivityAsUser(intent, UserHandle.CURRENT);
Jim Miller45308b12012-06-18 19:23:39 -07002648 } catch (ActivityNotFoundException e) {
2649 Slog.w(TAG, "No activity to handle assist action.", e);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002650 }
2651 }
2652 }
2653
2654 private SearchManager getSearchManager() {
2655 if (mSearchManager == null) {
2656 mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
2657 }
2658 return mSearchManager;
2659 }
2660
Jeff Browncaca8812013-05-09 13:34:33 -07002661 private void preloadRecentApps() {
2662 mPreloadedRecentApps = true;
2663 try {
2664 IStatusBarService statusbar = getStatusBarService();
2665 if (statusbar != null) {
2666 statusbar.preloadRecentApps();
2667 }
2668 } catch (RemoteException e) {
2669 Slog.e(TAG, "RemoteException when preloading recent apps", e);
2670 // re-acquire status bar service next time it is needed.
2671 mStatusBarService = null;
2672 }
2673 }
2674
2675 private void cancelPreloadRecentApps() {
2676 if (mPreloadedRecentApps) {
2677 mPreloadedRecentApps = false;
2678 try {
2679 IStatusBarService statusbar = getStatusBarService();
2680 if (statusbar != null) {
2681 statusbar.cancelPreloadRecentApps();
2682 }
2683 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002684 Slog.e(TAG, "RemoteException when cancelling recent apps preload", e);
Jeff Browncaca8812013-05-09 13:34:33 -07002685 // re-acquire status bar service next time it is needed.
2686 mStatusBarService = null;
2687 }
2688 }
2689 }
2690
2691 private void toggleRecentApps() {
2692 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
Jeff Browncaca8812013-05-09 13:34:33 -07002693 try {
2694 IStatusBarService statusbar = getStatusBarService();
2695 if (statusbar != null) {
2696 statusbar.toggleRecentApps();
2697 }
2698 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002699 Slog.e(TAG, "RemoteException when toggling recent apps", e);
2700 // re-acquire status bar service next time it is needed.
2701 mStatusBarService = null;
2702 }
2703 }
2704
Craig Mautner84984fa2014-06-19 11:19:20 -07002705 @Override
2706 public void showRecentApps() {
2707 mHandler.removeMessages(MSG_DISPATCH_SHOW_RECENTS);
2708 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_RECENTS);
2709 }
2710
Winson Chung1e8d71b2014-05-16 17:05:22 -07002711 private void showRecentApps(boolean triggeredFromAltTab) {
2712 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
2713 try {
2714 IStatusBarService statusbar = getStatusBarService();
2715 if (statusbar != null) {
2716 statusbar.showRecentApps(triggeredFromAltTab);
2717 }
2718 } catch (RemoteException e) {
Jeff Browncaca8812013-05-09 13:34:33 -07002719 Slog.e(TAG, "RemoteException when showing recent apps", e);
2720 // re-acquire status bar service next time it is needed.
2721 mStatusBarService = null;
2722 }
2723 }
2724
Winson Chungcdcd4872014-08-05 18:00:13 -07002725 private void hideRecentApps(boolean triggeredFromAltTab, boolean triggeredFromHome) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002726 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
2727 try {
2728 IStatusBarService statusbar = getStatusBarService();
2729 if (statusbar != null) {
Winson Chungcdcd4872014-08-05 18:00:13 -07002730 statusbar.hideRecentApps(triggeredFromAltTab, triggeredFromHome);
Winson Chung1e8d71b2014-05-16 17:05:22 -07002731 }
2732 } catch (RemoteException e) {
2733 Slog.e(TAG, "RemoteException when closing recent apps", e);
2734 // re-acquire status bar service next time it is needed.
2735 mStatusBarService = null;
2736 }
2737 }
2738
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002739 /**
2740 * A home key -> launch home action was detected. Take the appropriate action
2741 * given the situation with the keyguard.
2742 */
2743 void launchHomeFromHotKey() {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01002744 if (mKeyguardDelegate != null && mKeyguardDelegate.isShowingAndNotOccluded()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002745 // don't launch home if keyguard showing
Jim Miller5ecd8112013-01-09 18:50:26 -08002746 } else if (!mHideLockScreen && mKeyguardDelegate.isInputRestricted()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002747 // when in keyguard restricted mode, must first verify unlock
2748 // before launching home
Jim Miller5ecd8112013-01-09 18:50:26 -08002749 mKeyguardDelegate.verifyUnlock(new OnKeyguardExitResult() {
Jose Lima9546b202014-07-02 17:21:51 -07002750 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002751 public void onKeyguardExitResult(boolean success) {
2752 if (success) {
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07002753 try {
2754 ActivityManagerNative.getDefault().stopAppSwitches();
2755 } catch (RemoteException e) {
2756 }
Joe Onoratof275f0c2009-11-24 16:11:13 -05002757 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07002758 startDockOrHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002759 }
2760 }
2761 });
2762 } else {
2763 // no keyguard stuff to worry about, just launch home!
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07002764 try {
2765 ActivityManagerNative.getDefault().stopAppSwitches();
2766 } catch (RemoteException e) {
2767 }
Winson Chungd543c1b2014-06-23 15:06:45 -07002768 if (mRecentsVisible) {
2769 // Hide Recents and notify it to launch Home
2770 awakenDreams();
2771 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
Winson Chungcdcd4872014-08-05 18:00:13 -07002772 hideRecentApps(false, true);
Winson Chungd543c1b2014-06-23 15:06:45 -07002773 } else {
2774 // Otherwise, just launch Home
2775 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
2776 startDockOrHome();
2777 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002778 }
2779 }
2780
John Spurlock04db1762013-05-13 12:46:41 -04002781 private final Runnable mClearHideNavigationFlag = new Runnable() {
2782 @Override
2783 public void run() {
2784 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
2785 // Clear flags.
2786 mForceClearedSystemUiFlags &=
2787 ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
2788 }
2789 mWindowManagerFuncs.reevaluateStatusBarVisibility();
Dianne Hackborne26ab702011-10-16 13:21:33 -07002790 }
2791 };
2792
2793 /**
2794 * Input handler used while nav bar is hidden. Captures any touch on the screen,
2795 * to determine when the nav bar should be shown and prevent applications from
2796 * receiving those touches.
2797 */
Jeff Brown32cbc38552011-12-01 14:01:49 -08002798 final class HideNavInputEventReceiver extends InputEventReceiver {
2799 public HideNavInputEventReceiver(InputChannel inputChannel, Looper looper) {
2800 super(inputChannel, looper);
2801 }
2802
Dianne Hackborndf89e652011-10-06 22:35:11 -07002803 @Override
Jeff Brown32cbc38552011-12-01 14:01:49 -08002804 public void onInputEvent(InputEvent event) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07002805 boolean handled = false;
2806 try {
Jeff Brown4952dfd2011-11-30 19:23:22 -08002807 if (event instanceof MotionEvent
2808 && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
2809 final MotionEvent motionEvent = (MotionEvent)event;
2810 if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07002811 // When the user taps down, we re-show the nav bar.
2812 boolean changed = false;
John Spurlock04db1762013-05-13 12:46:41 -04002813 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002814 // Any user activity always causes us to show the
2815 // navigation controls, if they had been hidden.
2816 // We also clear the low profile and only content
2817 // flags so that tapping on the screen will atomically
2818 // restore all currently hidden screen decorations.
2819 int newVal = mResettingSystemUiFlags |
2820 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
2821 View.SYSTEM_UI_FLAG_LOW_PROFILE |
2822 View.SYSTEM_UI_FLAG_FULLSCREEN;
Dianne Hackborne26ab702011-10-16 13:21:33 -07002823 if (mResettingSystemUiFlags != newVal) {
2824 mResettingSystemUiFlags = newVal;
Dianne Hackborndf89e652011-10-06 22:35:11 -07002825 changed = true;
2826 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07002827 // We don't allow the system's nav bar to be hidden
2828 // again for 1 second, to prevent applications from
2829 // spamming us and keeping it from being shown.
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002830 newVal = mForceClearedSystemUiFlags |
2831 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
Dianne Hackborne26ab702011-10-16 13:21:33 -07002832 if (mForceClearedSystemUiFlags != newVal) {
2833 mForceClearedSystemUiFlags = newVal;
2834 changed = true;
John Spurlock04db1762013-05-13 12:46:41 -04002835 mHandler.postDelayed(mClearHideNavigationFlag, 1000);
Dianne Hackborne26ab702011-10-16 13:21:33 -07002836 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07002837 }
2838 if (changed) {
2839 mWindowManagerFuncs.reevaluateStatusBarVisibility();
2840 }
2841 }
2842 }
2843 } finally {
Jeff Brown32cbc38552011-12-01 14:01:49 -08002844 finishInputEvent(event, handled);
Dianne Hackborndf89e652011-10-06 22:35:11 -07002845 }
2846 }
Jeff Brown32cbc38552011-12-01 14:01:49 -08002847 }
2848 final InputEventReceiver.Factory mHideNavInputEventReceiverFactory =
2849 new InputEventReceiver.Factory() {
2850 @Override
2851 public InputEventReceiver createInputEventReceiver(
2852 InputChannel inputChannel, Looper looper) {
2853 return new HideNavInputEventReceiver(inputChannel, looper);
2854 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07002855 };
2856
2857 @Override
2858 public int adjustSystemUiVisibilityLw(int visibility) {
John Spurlock5b9145b2013-08-20 15:13:47 -04002859 mStatusBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
2860 mNavigationBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
Winson Chungd42a6cf2014-06-03 16:24:04 -07002861 mRecentsVisible = (visibility & View.RECENT_APPS_VISIBLE) > 0;
John Spurlock27735a42013-08-14 17:57:38 -04002862
Dianne Hackborndf89e652011-10-06 22:35:11 -07002863 // Reset any bits in mForceClearingStatusBarVisibility that
2864 // are now clear.
Dianne Hackborne26ab702011-10-16 13:21:33 -07002865 mResettingSystemUiFlags &= visibility;
Dianne Hackborndf89e652011-10-06 22:35:11 -07002866 // Clear any bits in the new visibility that are currently being
2867 // force cleared, before reporting it.
Dianne Hackborne26ab702011-10-16 13:21:33 -07002868 return visibility & ~mResettingSystemUiFlags
2869 & ~mForceClearedSystemUiFlags;
Dianne Hackborndf89e652011-10-06 22:35:11 -07002870 }
2871
Craig Mautner69b08182012-09-05 13:07:13 -07002872 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002873 public void getContentInsetHintLw(WindowManager.LayoutParams attrs, Rect contentInset) {
John Spurlockc6d1c602014-01-17 15:22:06 -05002874 final int fl = PolicyControl.getWindowFlags(null, attrs);
John Spurlock1db8b682014-02-18 11:18:59 -05002875 final int sysuiVis = PolicyControl.getSystemUiVisibility(null, attrs);
2876 final int systemUiVisibility = (sysuiVis | attrs.subtreeSystemUiVisibility);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002877
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002878 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002879 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002880 int availRight, availBottom;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07002881 if (canHideNavigationBar() &&
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002882 (systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002883 availRight = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
2884 availBottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
2885 } else {
2886 availRight = mRestrictedScreenLeft + mRestrictedScreenWidth;
2887 availBottom = mRestrictedScreenTop + mRestrictedScreenHeight;
2888 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002889 if ((systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
2890 if ((fl & FLAG_FULLSCREEN) != 0) {
2891 contentInset.set(mStableFullscreenLeft, mStableFullscreenTop,
2892 availRight - mStableFullscreenRight,
2893 availBottom - mStableFullscreenBottom);
2894 } else {
2895 contentInset.set(mStableLeft, mStableTop,
2896 availRight - mStableRight, availBottom - mStableBottom);
2897 }
Dianne Hackbornc652de82013-02-15 16:32:56 -08002898 } else if ((fl & FLAG_FULLSCREEN) != 0 || (fl & FLAG_LAYOUT_IN_OVERSCAN) != 0) {
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002899 contentInset.setEmpty();
2900 } else if ((systemUiVisibility & (View.SYSTEM_UI_FLAG_FULLSCREEN
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002901 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)) == 0) {
2902 contentInset.set(mCurLeft, mCurTop,
2903 availRight - mCurRight, availBottom - mCurBottom);
2904 } else {
2905 contentInset.set(mCurLeft, mCurTop,
2906 availRight - mCurRight, availBottom - mCurBottom);
2907 }
2908 return;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002909 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002910 contentInset.setEmpty();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002911 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002912
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002913 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07002914 @Override
2915 public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight,
2916 int displayRotation) {
Dianne Hackbornc652de82013-02-15 16:32:56 -08002917 final int overscanLeft, overscanTop, overscanRight, overscanBottom;
2918 if (isDefaultDisplay) {
2919 switch (displayRotation) {
2920 case Surface.ROTATION_90:
2921 overscanLeft = mOverscanTop;
2922 overscanTop = mOverscanRight;
2923 overscanRight = mOverscanBottom;
2924 overscanBottom = mOverscanLeft;
2925 break;
2926 case Surface.ROTATION_180:
2927 overscanLeft = mOverscanRight;
2928 overscanTop = mOverscanBottom;
2929 overscanRight = mOverscanLeft;
2930 overscanBottom = mOverscanTop;
2931 break;
2932 case Surface.ROTATION_270:
2933 overscanLeft = mOverscanBottom;
2934 overscanTop = mOverscanLeft;
2935 overscanRight = mOverscanTop;
2936 overscanBottom = mOverscanRight;
2937 break;
2938 default:
2939 overscanLeft = mOverscanLeft;
2940 overscanTop = mOverscanTop;
2941 overscanRight = mOverscanRight;
2942 overscanBottom = mOverscanBottom;
2943 break;
2944 }
2945 } else {
2946 overscanLeft = 0;
2947 overscanTop = 0;
2948 overscanRight = 0;
2949 overscanBottom = 0;
2950 }
Dianne Hackborn313440842013-02-19 19:22:59 -08002951 mOverscanScreenLeft = mRestrictedOverscanScreenLeft = 0;
2952 mOverscanScreenTop = mRestrictedOverscanScreenTop = 0;
2953 mOverscanScreenWidth = mRestrictedOverscanScreenWidth = displayWidth;
2954 mOverscanScreenHeight = mRestrictedOverscanScreenHeight = displayHeight;
Dianne Hackbornc652de82013-02-15 16:32:56 -08002955 mSystemLeft = 0;
2956 mSystemTop = 0;
2957 mSystemRight = displayWidth;
2958 mSystemBottom = displayHeight;
2959 mUnrestrictedScreenLeft = overscanLeft;
2960 mUnrestrictedScreenTop = overscanTop;
2961 mUnrestrictedScreenWidth = displayWidth - overscanLeft - overscanRight;
2962 mUnrestrictedScreenHeight = displayHeight - overscanTop - overscanBottom;
2963 mRestrictedScreenLeft = mUnrestrictedScreenLeft;
2964 mRestrictedScreenTop = mUnrestrictedScreenTop;
John Spurlockad3e6cb2013-04-30 08:47:43 -04002965 mRestrictedScreenWidth = mSystemGestures.screenWidth = mUnrestrictedScreenWidth;
2966 mRestrictedScreenHeight = mSystemGestures.screenHeight = mUnrestrictedScreenHeight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002967 mDockLeft = mContentLeft = mVoiceContentLeft = mStableLeft = mStableFullscreenLeft
Dianne Hackbornc652de82013-02-15 16:32:56 -08002968 = mCurLeft = mUnrestrictedScreenLeft;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002969 mDockTop = mContentTop = mVoiceContentTop = mStableTop = mStableFullscreenTop
Dianne Hackbornc652de82013-02-15 16:32:56 -08002970 = mCurTop = mUnrestrictedScreenTop;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002971 mDockRight = mContentRight = mVoiceContentRight = mStableRight = mStableFullscreenRight
Dianne Hackbornc652de82013-02-15 16:32:56 -08002972 = mCurRight = displayWidth - overscanRight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002973 mDockBottom = mContentBottom = mVoiceContentBottom = mStableBottom = mStableFullscreenBottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08002974 = mCurBottom = displayHeight - overscanBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002975 mDockLayer = 0x10000000;
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002976 mStatusBarLayer = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002977
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002978 // start with the current dock rect, which will be (0,0,displayWidth,displayHeight)
2979 final Rect pf = mTmpParentFrame;
2980 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002981 final Rect of = mTmpOverscanFrame;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002982 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04002983 final Rect dcf = mTmpDecorFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002984 pf.left = df.left = of.left = vf.left = mDockLeft;
2985 pf.top = df.top = of.top = vf.top = mDockTop;
2986 pf.right = df.right = of.right = vf.right = mDockRight;
2987 pf.bottom = df.bottom = of.bottom = vf.bottom = mDockBottom;
John Spurlock46646232013-09-30 22:32:42 -04002988 dcf.setEmpty(); // Decor frame N/A for system bars.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002989
Craig Mautner69b08182012-09-05 13:07:13 -07002990 if (isDefaultDisplay) {
2991 // For purposes of putting out fake window up to steal focus, we will
2992 // drive nav being hidden only by whether it is requested.
John Spurlocke1f366f2013-08-05 12:22:40 -04002993 final int sysui = mLastSystemUiFlags;
2994 boolean navVisible = (sysui & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0;
Adrian Roosea562512014-05-05 13:33:03 +02002995 boolean navTranslucent = (sysui
2996 & (View.NAVIGATION_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04002997 boolean immersive = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
2998 boolean immersiveSticky = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
2999 boolean navAllowedHidden = immersive || immersiveSticky;
3000 navTranslucent &= !immersiveSticky; // transient trumps translucent
Adrian Roos4fb3ee32014-08-22 19:29:09 +02003001 boolean isKeyguardShowing = isStatusBarKeyguard() && !mHideLockScreen;
3002 if (!isKeyguardShowing) {
3003 navTranslucent &= areTranslucentBarsAllowed();
3004 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003005
Craig Mautner69b08182012-09-05 13:07:13 -07003006 // When the navigation bar isn't visible, we put up a fake
3007 // input window to catch all touch events. This way we can
3008 // detect when the user presses anywhere to bring back the nav
3009 // bar and ensure the application doesn't see the event.
John Spurlockf1a36642013-10-12 17:50:42 -04003010 if (navVisible || navAllowedHidden) {
Craig Mautner69b08182012-09-05 13:07:13 -07003011 if (mHideNavFakeWindow != null) {
3012 mHideNavFakeWindow.dismiss();
3013 mHideNavFakeWindow = null;
3014 }
3015 } else if (mHideNavFakeWindow == null) {
3016 mHideNavFakeWindow = mWindowManagerFuncs.addFakeWindow(
3017 mHandler.getLooper(), mHideNavInputEventReceiverFactory,
Adam Lesinski95c42972013-10-02 10:13:27 -07003018 "hidden nav", WindowManager.LayoutParams.TYPE_HIDDEN_NAV_CONSUMER, 0,
Craig Mautner69b08182012-09-05 13:07:13 -07003019 0, false, false, true);
Dianne Hackborne26ab702011-10-16 13:21:33 -07003020 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003021
Craig Mautner69b08182012-09-05 13:07:13 -07003022 // For purposes of positioning and showing the nav bar, if we have
3023 // decided that it can't be hidden (because of the screen aspect ratio),
3024 // then take that into account.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003025 navVisible |= !canHideNavigationBar();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003026
John Spurlockad3e6cb2013-04-30 08:47:43 -04003027 boolean updateSysUiVisibility = false;
Craig Mautner69b08182012-09-05 13:07:13 -07003028 if (mNavigationBar != null) {
John Spurlock27735a42013-08-14 17:57:38 -04003029 boolean transientNavBarShowing = mNavigationBarController.isTransientShowing();
Craig Mautner69b08182012-09-05 13:07:13 -07003030 // Force the navigation bar to its appropriate place and
3031 // size. We need to do this directly, instead of relying on
3032 // it to bubble up from the nav bar, because this needs to
3033 // change atomically with screen rotations.
3034 mNavigationBarOnBottom = (!mNavigationBarCanMove || displayWidth < displayHeight);
3035 if (mNavigationBarOnBottom) {
3036 // It's a system nav bar or a portrait screen; nav bar goes on bottom.
Dianne Hackbornc652de82013-02-15 16:32:56 -08003037 int top = displayHeight - overscanBottom
3038 - mNavigationBarHeightForRotation[displayRotation];
3039 mTmpNavigationFrame.set(0, top, displayWidth, displayHeight - overscanBottom);
Craig Mautner69b08182012-09-05 13:07:13 -07003040 mStableBottom = mStableFullscreenBottom = mTmpNavigationFrame.top;
John Spurlockf95b89a2013-10-10 22:10:42 -04003041 if (transientNavBarShowing) {
John Spurlock27735a42013-08-14 17:57:38 -04003042 mNavigationBarController.setBarShowingLw(true);
John Spurlockad3e6cb2013-04-30 08:47:43 -04003043 } else if (navVisible) {
John Spurlock27735a42013-08-14 17:57:38 -04003044 mNavigationBarController.setBarShowingLw(true);
Craig Mautner69b08182012-09-05 13:07:13 -07003045 mDockBottom = mTmpNavigationFrame.top;
Dianne Hackborn313440842013-02-19 19:22:59 -08003046 mRestrictedScreenHeight = mDockBottom - mRestrictedScreenTop;
3047 mRestrictedOverscanScreenHeight = mDockBottom - mRestrictedOverscanScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07003048 } else {
3049 // We currently want to hide the navigation UI.
John Spurlock27735a42013-08-14 17:57:38 -04003050 mNavigationBarController.setBarShowingLw(false);
Craig Mautner69b08182012-09-05 13:07:13 -07003051 }
John Spurlockc6d1c602014-01-17 15:22:06 -05003052 if (navVisible && !navTranslucent && !navAllowedHidden
3053 && !mNavigationBar.isAnimatingLw()
John Spurlockbd957402013-10-03 11:38:39 -04003054 && !mNavigationBarController.wasRecentlyTranslucent()) {
John Spurlocke1f366f2013-08-05 12:22:40 -04003055 // If the opaque nav bar is currently requested to be visible,
Craig Mautner69b08182012-09-05 13:07:13 -07003056 // and not in the process of animating on or off, then
3057 // we can tell the app that it is covered by it.
3058 mSystemBottom = mTmpNavigationFrame.top;
3059 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003060 } else {
Craig Mautner69b08182012-09-05 13:07:13 -07003061 // Landscape screen; nav bar goes to the right.
Dianne Hackbornc652de82013-02-15 16:32:56 -08003062 int left = displayWidth - overscanRight
3063 - mNavigationBarWidthForRotation[displayRotation];
3064 mTmpNavigationFrame.set(left, 0, displayWidth - overscanRight, displayHeight);
Craig Mautner69b08182012-09-05 13:07:13 -07003065 mStableRight = mStableFullscreenRight = mTmpNavigationFrame.left;
John Spurlockf95b89a2013-10-10 22:10:42 -04003066 if (transientNavBarShowing) {
John Spurlock27735a42013-08-14 17:57:38 -04003067 mNavigationBarController.setBarShowingLw(true);
John Spurlockad3e6cb2013-04-30 08:47:43 -04003068 } else if (navVisible) {
John Spurlock27735a42013-08-14 17:57:38 -04003069 mNavigationBarController.setBarShowingLw(true);
Craig Mautner69b08182012-09-05 13:07:13 -07003070 mDockRight = mTmpNavigationFrame.left;
Dianne Hackborn313440842013-02-19 19:22:59 -08003071 mRestrictedScreenWidth = mDockRight - mRestrictedScreenLeft;
3072 mRestrictedOverscanScreenWidth = mDockRight - mRestrictedOverscanScreenLeft;
Craig Mautner69b08182012-09-05 13:07:13 -07003073 } else {
3074 // We currently want to hide the navigation UI.
John Spurlock27735a42013-08-14 17:57:38 -04003075 mNavigationBarController.setBarShowingLw(false);
Craig Mautner69b08182012-09-05 13:07:13 -07003076 }
John Spurlockbd957402013-10-03 11:38:39 -04003077 if (navVisible && !navTranslucent && !mNavigationBar.isAnimatingLw()
3078 && !mNavigationBarController.wasRecentlyTranslucent()) {
Craig Mautner69b08182012-09-05 13:07:13 -07003079 // If the nav bar is currently requested to be visible,
3080 // and not in the process of animating on or off, then
3081 // we can tell the app that it is covered by it.
3082 mSystemRight = mTmpNavigationFrame.left;
3083 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003084 }
Craig Mautner69b08182012-09-05 13:07:13 -07003085 // Make sure the content and current rectangles are updated to
3086 // account for the restrictions from the navigation bar.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003087 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3088 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3089 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3090 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
Craig Mautner69b08182012-09-05 13:07:13 -07003091 mStatusBarLayer = mNavigationBar.getSurfaceLayer();
3092 // And compute the final frame.
3093 mNavigationBar.computeFrameLw(mTmpNavigationFrame, mTmpNavigationFrame,
Adrian Roosfa104232014-06-20 16:10:14 -07003094 mTmpNavigationFrame, mTmpNavigationFrame, mTmpNavigationFrame, dcf,
3095 mTmpNavigationFrame);
Craig Mautnereda67292013-04-28 13:50:14 -07003096 if (DEBUG_LAYOUT) Slog.i(TAG, "mNavigationBar frame: " + mTmpNavigationFrame);
John Spurlock27735a42013-08-14 17:57:38 -04003097 if (mNavigationBarController.checkHiddenLw()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04003098 updateSysUiVisibility = true;
3099 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003100 }
Craig Mautnereda67292013-04-28 13:50:14 -07003101 if (DEBUG_LAYOUT) Slog.i(TAG, String.format("mDock rect: (%d,%d - %d,%d)",
Craig Mautner69b08182012-09-05 13:07:13 -07003102 mDockLeft, mDockTop, mDockRight, mDockBottom));
3103
3104 // decide where the status bar goes ahead of time
3105 if (mStatusBar != null) {
3106 // apply any navigation bar insets
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003107 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3108 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3109 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
3110 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight
3111 + mUnrestrictedScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07003112 vf.left = mStableLeft;
3113 vf.top = mStableTop;
3114 vf.right = mStableRight;
3115 vf.bottom = mStableBottom;
3116
3117 mStatusBarLayer = mStatusBar.getSurfaceLayer();
3118
3119 // Let the status bar determine its size.
Adrian Roosfa104232014-06-20 16:10:14 -07003120 mStatusBar.computeFrameLw(pf, df, vf, vf, vf, dcf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07003121
3122 // For layout, the status bar is always at the top with our fixed height.
3123 mStableTop = mUnrestrictedScreenTop + mStatusBarHeight;
3124
John Spurlocke1f366f2013-08-05 12:22:40 -04003125 boolean statusBarTransient = (sysui & View.STATUS_BAR_TRANSIENT) != 0;
Adrian Roosea562512014-05-05 13:33:03 +02003126 boolean statusBarTranslucent = (sysui
3127 & (View.STATUS_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0;
Adrian Roos4fb3ee32014-08-22 19:29:09 +02003128 if (!isKeyguardShowing) {
3129 statusBarTranslucent &= areTranslucentBarsAllowed();
3130 }
John Spurlock32beb2c2013-03-11 10:16:47 -04003131
Craig Mautner69b08182012-09-05 13:07:13 -07003132 // If the status bar is hidden, we don't want to cause
3133 // windows behind it to scroll.
John Spurlockeda1f692013-09-16 11:38:44 -04003134 if (mStatusBar.isVisibleLw() && !statusBarTransient) {
Craig Mautner69b08182012-09-05 13:07:13 -07003135 // Status bar may go away, so the screen area it occupies
3136 // is available to apps but just covering them when the
3137 // status bar is visible.
3138 mDockTop = mUnrestrictedScreenTop + mStatusBarHeight;
3139
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003140 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3141 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3142 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3143 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
Craig Mautner69b08182012-09-05 13:07:13 -07003144
Craig Mautnereda67292013-04-28 13:50:14 -07003145 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar: " +
Craig Mautner69b08182012-09-05 13:07:13 -07003146 String.format(
3147 "dock=[%d,%d][%d,%d] content=[%d,%d][%d,%d] cur=[%d,%d][%d,%d]",
3148 mDockLeft, mDockTop, mDockRight, mDockBottom,
3149 mContentLeft, mContentTop, mContentRight, mContentBottom,
3150 mCurLeft, mCurTop, mCurRight, mCurBottom));
3151 }
John Spurlocke1f366f2013-08-05 12:22:40 -04003152 if (mStatusBar.isVisibleLw() && !mStatusBar.isAnimatingLw()
John Spurlockbd957402013-10-03 11:38:39 -04003153 && !statusBarTransient && !statusBarTranslucent
3154 && !mStatusBarController.wasRecentlyTranslucent()) {
John Spurlocke1f366f2013-08-05 12:22:40 -04003155 // If the opaque status bar is currently requested to be visible,
Craig Mautner69b08182012-09-05 13:07:13 -07003156 // and not in the process of animating on or off, then
3157 // we can tell the app that it is covered by it.
3158 mSystemTop = mUnrestrictedScreenTop + mStatusBarHeight;
3159 }
John Spurlock27735a42013-08-14 17:57:38 -04003160 if (mStatusBarController.checkHiddenLw()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04003161 updateSysUiVisibility = true;
John Spurlock32beb2c2013-03-11 10:16:47 -04003162 }
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003163 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04003164 if (updateSysUiVisibility) {
3165 updateSystemUiVisibilityLw();
3166 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003167 }
3168 }
3169
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003170 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07003171 @Override
John Spurlock46646232013-09-30 22:32:42 -04003172 public int getSystemDecorLayerLw() {
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003173 if (mStatusBar != null) return mStatusBar.getSurfaceLayer();
3174 if (mNavigationBar != null) return mNavigationBar.getSurfaceLayer();
3175 return 0;
3176 }
3177
Craig Mautner967212c2013-04-13 21:10:58 -07003178 @Override
3179 public void getContentRectLw(Rect r) {
3180 r.set(mContentLeft, mContentTop, mContentRight, mContentBottom);
3181 }
3182
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003183 void setAttachedWindowFrames(WindowState win, int fl, int adjust, WindowState attached,
3184 boolean insetDecors, Rect pf, Rect df, Rect of, Rect cf, Rect vf) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003185 if (win.getSurfaceLayer() > mDockLayer && attached.getSurfaceLayer() < mDockLayer) {
3186 // Here's a special case: if this attached window is a panel that is
3187 // above the dock window, and the window it is attached to is below
3188 // the dock window, then the frames we computed for the window it is
3189 // attached to can not be used because the dock is effectively part
3190 // of the underlying window and the attached window is floating on top
3191 // of the whole thing. So, we ignore the attached window and explicitly
3192 // compute the frames that would be appropriate without the dock.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003193 df.left = of.left = cf.left = vf.left = mDockLeft;
3194 df.top = of.top = cf.top = vf.top = mDockTop;
3195 df.right = of.right = cf.right = vf.right = mDockRight;
3196 df.bottom = of.bottom = cf.bottom = vf.bottom = mDockBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003197 } else {
3198 // The effective display frame of the attached window depends on
3199 // whether it is taking care of insetting its content. If not,
3200 // we need to use the parent's content frame so that the entire
3201 // window is positioned within that content. Otherwise we can use
3202 // the display frame and let the attached window take care of
3203 // positioning its content appropriately.
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003204 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003205 cf.set(attached.getOverscanFrameLw());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003206 } else {
3207 // If the window is resizing, then we want to base the content
3208 // frame on our attached content frame to resize... however,
3209 // things can be tricky if the attached window is NOT in resize
3210 // mode, in which case its content frame will be larger.
3211 // Ungh. So to deal with that, make sure the content frame
3212 // we end up using is not covering the IM dock.
3213 cf.set(attached.getContentFrameLw());
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003214 if (attached.isVoiceInteraction()) {
3215 if (cf.left < mVoiceContentLeft) cf.left = mVoiceContentLeft;
3216 if (cf.top < mVoiceContentTop) cf.top = mVoiceContentTop;
3217 if (cf.right > mVoiceContentRight) cf.right = mVoiceContentRight;
3218 if (cf.bottom > mVoiceContentBottom) cf.bottom = mVoiceContentBottom;
3219 } else if (attached.getSurfaceLayer() < mDockLayer) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003220 if (cf.left < mContentLeft) cf.left = mContentLeft;
3221 if (cf.top < mContentTop) cf.top = mContentTop;
3222 if (cf.right > mContentRight) cf.right = mContentRight;
3223 if (cf.bottom > mContentBottom) cf.bottom = mContentBottom;
3224 }
3225 }
3226 df.set(insetDecors ? attached.getDisplayFrameLw() : cf);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003227 of.set(insetDecors ? attached.getOverscanFrameLw() : cf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003228 vf.set(attached.getVisibleFrameLw());
3229 }
3230 // The LAYOUT_IN_SCREEN flag is used to determine whether the attached
3231 // window should be positioned relative to its parent or the entire
3232 // screen.
3233 pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0
3234 ? attached.getFrameLw() : df);
3235 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003236
3237 private void applyStableConstraints(int sysui, int fl, Rect r) {
3238 if ((sysui & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
3239 // If app is requesting a stable layout, don't let the
3240 // content insets go below the stable values.
3241 if ((fl & FLAG_FULLSCREEN) != 0) {
3242 if (r.left < mStableFullscreenLeft) r.left = mStableFullscreenLeft;
3243 if (r.top < mStableFullscreenTop) r.top = mStableFullscreenTop;
3244 if (r.right > mStableFullscreenRight) r.right = mStableFullscreenRight;
3245 if (r.bottom > mStableFullscreenBottom) r.bottom = mStableFullscreenBottom;
3246 } else {
3247 if (r.left < mStableLeft) r.left = mStableLeft;
3248 if (r.top < mStableTop) r.top = mStableTop;
3249 if (r.right > mStableRight) r.right = mStableRight;
3250 if (r.bottom > mStableBottom) r.bottom = mStableBottom;
3251 }
3252 }
3253 }
3254
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003255 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07003256 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003257 public void layoutWindowLw(WindowState win, WindowState attached) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003258 // we've already done the status bar
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003259 final WindowManager.LayoutParams attrs = win.getAttrs();
3260 if ((win == mStatusBar && (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) == 0) ||
3261 win == mNavigationBar) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003262 return;
3263 }
Craig Mautner69b08182012-09-05 13:07:13 -07003264 final boolean isDefaultDisplay = win.isDefaultDisplay();
3265 final boolean needsToOffsetInputMethodTarget = isDefaultDisplay &&
satok1bc0a492012-04-25 22:47:12 +09003266 (win == mLastInputMethodTargetWindow && mLastInputMethodWindow != null);
3267 if (needsToOffsetInputMethodTarget) {
Craig Mautnereda67292013-04-28 13:50:14 -07003268 if (DEBUG_LAYOUT) Slog.i(TAG, "Offset ime target window by the last ime window state");
satok1bc0a492012-04-25 22:47:12 +09003269 offsetInputMethodWindowLw(mLastInputMethodWindow);
3270 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003271
John Spurlockc6d1c602014-01-17 15:22:06 -05003272 final int fl = PolicyControl.getWindowFlags(win, attrs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003273 final int sim = attrs.softInputMode;
John Spurlock1db8b682014-02-18 11:18:59 -05003274 final int sysUiFl = PolicyControl.getSystemUiVisibility(win, null);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003275
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003276 final Rect pf = mTmpParentFrame;
3277 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003278 final Rect of = mTmpOverscanFrame;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003279 final Rect cf = mTmpContentFrame;
3280 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04003281 final Rect dcf = mTmpDecorFrame;
Adrian Roosfa104232014-06-20 16:10:14 -07003282 final Rect sf = mTmpStableFrame;
John Spurlock46646232013-09-30 22:32:42 -04003283 dcf.setEmpty();
Craig Mautner69b08182012-09-05 13:07:13 -07003284
3285 final boolean hasNavBar = (isDefaultDisplay && mHasNavigationBar
Daniel Sandler36412a72011-08-04 09:35:13 -04003286 && mNavigationBar != null && mNavigationBar.isVisibleLw());
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003287
Craig Mautnerf683b562012-10-02 11:10:57 -07003288 final int adjust = sim & SOFT_INPUT_MASK_ADJUST;
3289
Adrian Roosfa104232014-06-20 16:10:14 -07003290 if (isDefaultDisplay) {
3291 sf.set(mStableLeft, mStableTop, mStableRight, mStableBottom);
3292 } else {
3293 sf.set(mOverscanLeft, mOverscanTop, mOverscanRight, mOverscanBottom);
3294 }
3295
Craig Mautner69b08182012-09-05 13:07:13 -07003296 if (!isDefaultDisplay) {
3297 if (attached != null) {
3298 // If this window is attached to another, our display
3299 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003300 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07003301 } else {
3302 // Give the window full screen.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003303 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3304 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3305 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08003306 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003307 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003308 = mOverscanScreenTop + mOverscanScreenHeight;
Craig Mautner69b08182012-09-05 13:07:13 -07003309 }
3310 } else if (attrs.type == TYPE_INPUT_METHOD) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003311 pf.left = df.left = of.left = cf.left = vf.left = mDockLeft;
3312 pf.top = df.top = of.top = cf.top = vf.top = mDockTop;
3313 pf.right = df.right = of.right = cf.right = vf.right = mDockRight;
John Spurlockc68d5772013-10-08 11:47:58 -04003314 // IM dock windows layout below the nav bar...
John Spurlock57beb3b2013-10-10 10:27:44 -04003315 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlockc68d5772013-10-08 11:47:58 -04003316 // ...with content insets above the nav bar
3317 cf.bottom = vf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003318 // IM dock windows always go to the bottom of the screen.
3319 attrs.gravity = Gravity.BOTTOM;
3320 mDockLayer = win.getSurfaceLayer();
Jorim Jaggie0700182014-08-21 01:12:37 +02003321 } else if (win == mStatusBar && (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
3322 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3323 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3324 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
3325 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight + mUnrestrictedScreenTop;
3326 cf.left = vf.left = mStableLeft;
3327 cf.top = vf.top = mStableTop;
3328 cf.right = vf.right = mStableRight;
3329 vf.bottom = mStableBottom;
3330 cf.bottom = mContentBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003331 } else {
John Spurlock46646232013-09-30 22:32:42 -04003332
3333 // Default policy decor for the default display
3334 dcf.left = mSystemLeft;
3335 dcf.top = mSystemTop;
3336 dcf.right = mSystemRight;
3337 dcf.bottom = mSystemBottom;
John Spurlockbd957402013-10-03 11:38:39 -04003338 final boolean inheritTranslucentDecor = (attrs.privateFlags
3339 & WindowManager.LayoutParams.PRIVATE_FLAG_INHERIT_TRANSLUCENT_DECOR) != 0;
John Spurlock65567d42013-10-08 10:08:32 -04003340 final boolean isAppWindow =
3341 attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW &&
3342 attrs.type <= WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
3343 final boolean topAtRest =
3344 win == mTopFullscreenOpaqueWindowState && !win.isAnimatingLw();
3345 if (isAppWindow && !inheritTranslucentDecor && !topAtRest) {
John Spurlockbd957402013-10-03 11:38:39 -04003346 if ((sysUiFl & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0
3347 && (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0
Adrian Roosea562512014-05-05 13:33:03 +02003348 && (fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) == 0
3349 && (fl & WindowManager.LayoutParams.
3350 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04003351 // Ensure policy decor includes status bar
3352 dcf.top = mStableTop;
3353 }
John Spurlockbd957402013-10-03 11:38:39 -04003354 if ((fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) == 0
Adrian Roosea562512014-05-05 13:33:03 +02003355 && (sysUiFl & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0
3356 && (fl & WindowManager.LayoutParams.
3357 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04003358 // Ensure policy decor includes navigation bar
3359 dcf.bottom = mStableBottom;
3360 dcf.right = mStableRight;
3361 }
3362 }
3363
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003364 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
3365 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
RoboErik8a2cfc32014-05-16 11:19:38 -07003366 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003367 + "): IN_SCREEN, INSET_DECOR");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003368 // This is the case for a normal activity window: we want it
3369 // to cover all of the screen space, and it can take care of
3370 // moving its contents to account for screen decorations that
3371 // intrude into that space.
3372 if (attached != null) {
3373 // If this window is attached to another, our display
3374 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003375 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003376 } else {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003377 if (attrs.type == TYPE_STATUS_BAR_PANEL
3378 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Joe Onorato29fc2c92010-11-24 10:26:50 -08003379 // Status bar panels are the only windows who can go on top of
3380 // the status bar. They are protected by the STATUS_BAR_SERVICE
3381 // permission, so they have the same privileges as the status
3382 // bar itself.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003383 //
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003384 // However, they should still dodge the navigation bar if it exists.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003385
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003386 pf.left = df.left = of.left = hasNavBar
3387 ? mDockLeft : mUnrestrictedScreenLeft;
3388 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3389 pf.right = df.right = of.right = hasNavBar
3390 ? mRestrictedScreenLeft+mRestrictedScreenWidth
3391 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3392 pf.bottom = df.bottom = of.bottom = hasNavBar
3393 ? mRestrictedScreenTop+mRestrictedScreenHeight
3394 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003395
Craig Mautnereda67292013-04-28 13:50:14 -07003396 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003397 "Laying out status bar window: (%d,%d - %d,%d)",
3398 pf.left, pf.top, pf.right, pf.bottom));
John Spurlock46646232013-09-30 22:32:42 -04003399 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08003400 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3401 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3402 // Asking to layout into the overscan region, so give it that pure
3403 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003404 pf.left = df.left = of.left = mOverscanScreenLeft;
3405 pf.top = df.top = of.top = mOverscanScreenTop;
3406 pf.right = df.right = of.right = mOverscanScreenLeft + mOverscanScreenWidth;
3407 pf.bottom = df.bottom = of.bottom = mOverscanScreenTop
3408 + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003409 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003410 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003411 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3412 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003413 // Asking for layout as if the nav bar is hidden, lets the
Dianne Hackbornc652de82013-02-15 16:32:56 -08003414 // application extend into the unrestricted overscan screen area. We
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003415 // only do this for application windows to ensure no window that
3416 // can be above the nav bar can do this.
Dianne Hackborn313440842013-02-19 19:22:59 -08003417 pf.left = df.left = mOverscanScreenLeft;
3418 pf.top = df.top = mOverscanScreenTop;
3419 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
3420 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003421 // We need to tell the app about where the frame inside the overscan
3422 // is, so it can inset its content by that amount -- it didn't ask
3423 // to actually extend itself into the overscan region.
3424 of.left = mUnrestrictedScreenLeft;
3425 of.top = mUnrestrictedScreenTop;
3426 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3427 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003428 } else {
Dianne Hackborn313440842013-02-19 19:22:59 -08003429 pf.left = df.left = mRestrictedOverscanScreenLeft;
3430 pf.top = df.top = mRestrictedOverscanScreenTop;
3431 pf.right = df.right = mRestrictedOverscanScreenLeft
3432 + mRestrictedOverscanScreenWidth;
3433 pf.bottom = df.bottom = mRestrictedOverscanScreenTop
3434 + mRestrictedOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003435 // We need to tell the app about where the frame inside the overscan
3436 // is, so it can inset its content by that amount -- it didn't ask
3437 // to actually extend itself into the overscan region.
3438 of.left = mUnrestrictedScreenLeft;
3439 of.top = mUnrestrictedScreenTop;
3440 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3441 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003442 }
Craig Mautner69b08182012-09-05 13:07:13 -07003443
John Spurlock46646232013-09-30 22:32:42 -04003444 if ((fl & FLAG_FULLSCREEN) == 0) {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003445 if (win.isVoiceInteraction()) {
3446 cf.left = mVoiceContentLeft;
3447 cf.top = mVoiceContentTop;
3448 cf.right = mVoiceContentRight;
3449 cf.bottom = mVoiceContentBottom;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003450 } else {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003451 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
3452 cf.left = mDockLeft;
3453 cf.top = mDockTop;
3454 cf.right = mDockRight;
3455 cf.bottom = mDockBottom;
3456 } else {
3457 cf.left = mContentLeft;
3458 cf.top = mContentTop;
3459 cf.right = mContentRight;
3460 cf.bottom = mContentBottom;
3461 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003462 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003463 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003464 // Full screen windows are always given a layout that is as if the
3465 // status bar and other transient decors are gone. This is to avoid
3466 // bad states when moving from a window that is not hding the
3467 // status bar to one that is.
3468 cf.left = mRestrictedScreenLeft;
3469 cf.top = mRestrictedScreenTop;
3470 cf.right = mRestrictedScreenLeft + mRestrictedScreenWidth;
3471 cf.bottom = mRestrictedScreenTop + mRestrictedScreenHeight;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003472 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003473 applyStableConstraints(sysUiFl, fl, cf);
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003474 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3475 vf.left = mCurLeft;
3476 vf.top = mCurTop;
3477 vf.right = mCurRight;
3478 vf.bottom = mCurBottom;
3479 } else {
3480 vf.set(cf);
3481 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003482 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003483 } else if ((fl & FLAG_LAYOUT_IN_SCREEN) != 0 || (sysUiFl
3484 & (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
3485 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)) != 0) {
Craig Mautnereda67292013-04-28 13:50:14 -07003486 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3487 "): IN_SCREEN");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003488 // A window that has requested to fill the entire screen just
3489 // gets everything, period.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003490 if (attrs.type == TYPE_STATUS_BAR_PANEL
3491 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003492 pf.left = df.left = of.left = cf.left = hasNavBar
3493 ? mDockLeft : mUnrestrictedScreenLeft;
3494 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
3495 pf.right = df.right = of.right = cf.right = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003496 ? mRestrictedScreenLeft+mRestrictedScreenWidth
Dianne Hackbornc652de82013-02-15 16:32:56 -08003497 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003498 pf.bottom = df.bottom = of.bottom = cf.bottom = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003499 ? mRestrictedScreenTop+mRestrictedScreenHeight
Dianne Hackbornc652de82013-02-15 16:32:56 -08003500 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07003501 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler36412a72011-08-04 09:35:13 -04003502 "Laying out IN_SCREEN status bar window: (%d,%d - %d,%d)",
3503 pf.left, pf.top, pf.right, pf.bottom));
Jim Millere898ac52012-04-06 17:10:57 -07003504 } else if (attrs.type == TYPE_NAVIGATION_BAR
3505 || attrs.type == TYPE_NAVIGATION_BAR_PANEL) {
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003506 // The navigation bar has Real Ultimate Power.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003507 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3508 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3509 pf.right = df.right = of.right = mUnrestrictedScreenLeft
3510 + mUnrestrictedScreenWidth;
3511 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop
3512 + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07003513 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003514 "Laying out navigation bar window: (%d,%d - %d,%d)",
3515 pf.left, pf.top, pf.right, pf.bottom));
Dianne Hackborn01011c32012-02-21 13:54:21 -08003516 } else if ((attrs.type == TYPE_SECURE_SYSTEM_OVERLAY
3517 || attrs.type == TYPE_BOOT_PROGRESS)
Jeff Brownbfcb60a2011-09-08 18:51:14 -07003518 && ((fl & FLAG_FULLSCREEN) != 0)) {
3519 // Fullscreen secure system overlays get what they ask for.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003520 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3521 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3522 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
3523 + mOverscanScreenWidth;
3524 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
3525 + mOverscanScreenHeight;
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07003526 } else if (attrs.type == TYPE_BOOT_PROGRESS
3527 || attrs.type == TYPE_UNIVERSE_BACKGROUND) {
Dianne Hackborn01011c32012-02-21 13:54:21 -08003528 // Boot progress screen always covers entire display.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003529 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3530 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3531 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
3532 + mOverscanScreenWidth;
3533 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
3534 + mOverscanScreenHeight;
John Spurlockef4adae2013-08-26 17:58:58 -04003535 } else if (attrs.type == TYPE_WALLPAPER) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07003536 // The wallpaper also has Real Ultimate Power, but we want to tell
3537 // it about the overscan area.
3538 pf.left = df.left = mOverscanScreenLeft;
3539 pf.top = df.top = mOverscanScreenTop;
3540 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
3541 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
3542 of.left = cf.left = mUnrestrictedScreenLeft;
3543 of.top = cf.top = mUnrestrictedScreenTop;
3544 of.right = cf.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3545 of.bottom = cf.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlock46646232013-09-30 22:32:42 -04003546 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08003547 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3548 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3549 // Asking to layout into the overscan region, so give it that pure
3550 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003551 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3552 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3553 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08003554 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003555 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003556 = mOverscanScreenTop + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003557 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003558 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Craig Mautnerbeac1062014-06-03 14:38:57 -07003559 && (attrs.type == TYPE_STATUS_BAR
3560 || attrs.type == TYPE_TOAST
John Spurlock34e13d92013-08-10 06:52:28 -04003561 || (attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3562 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW))) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003563 // Asking for layout as if the nav bar is hidden, lets the
3564 // application extend into the unrestricted screen area. We
John Spurlock34e13d92013-08-10 06:52:28 -04003565 // only do this for application windows (or toasts) to ensure no window that
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003566 // can be above the nav bar can do this.
3567 // XXX This assumes that an app asking for this will also
3568 // ask for layout in only content. We can't currently figure out
3569 // what the screen would be if only laying out to hide the nav bar.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003570 pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft;
3571 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
3572 pf.right = df.right = of.right = cf.right = mUnrestrictedScreenLeft
3573 + mUnrestrictedScreenWidth;
3574 pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop
3575 + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003576 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003577 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
3578 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
3579 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
3580 + mRestrictedScreenWidth;
3581 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
3582 + mRestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003583 }
Craig Mautner69b08182012-09-05 13:07:13 -07003584
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003585 applyStableConstraints(sysUiFl, fl, cf);
Craig Mautner69b08182012-09-05 13:07:13 -07003586
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003587 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3588 vf.left = mCurLeft;
3589 vf.top = mCurTop;
3590 vf.right = mCurRight;
3591 vf.bottom = mCurBottom;
3592 } else {
3593 vf.set(cf);
3594 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003595 } else if (attached != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07003596 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3597 "): attached to " + attached);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003598 // A child window should be placed inside of the same visible
3599 // frame that its parent had.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003600 setAttachedWindowFrames(win, fl, adjust, attached, false, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003601 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07003602 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3603 "): normal window");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003604 // Otherwise, a normal window must be placed inside the content
3605 // of all screen decorations.
Dianne Hackborna239c842011-06-01 12:28:20 -07003606 if (attrs.type == TYPE_STATUS_BAR_PANEL) {
3607 // Status bar panels are the only windows who can go on top of
3608 // the status bar. They are protected by the STATUS_BAR_SERVICE
3609 // permission, so they have the same privileges as the status
3610 // bar itself.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003611 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
3612 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
3613 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
3614 + mRestrictedScreenWidth;
3615 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
3616 + mRestrictedScreenHeight;
John Spurlock414c1f02013-12-04 13:47:36 -05003617 } else if (attrs.type == TYPE_TOAST || attrs.type == TYPE_SYSTEM_ALERT
3618 || attrs.type == TYPE_VOLUME_OVERLAY) {
3619 // These dialogs are stable to interim decor changes.
John Spurlockbd957402013-10-03 11:38:39 -04003620 pf.left = df.left = of.left = cf.left = mStableLeft;
3621 pf.top = df.top = of.top = cf.top = mStableTop;
3622 pf.right = df.right = of.right = cf.right = mStableRight;
3623 pf.bottom = df.bottom = of.bottom = cf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003624 } else {
Dianne Hackborna239c842011-06-01 12:28:20 -07003625 pf.left = mContentLeft;
3626 pf.top = mContentTop;
3627 pf.right = mContentRight;
3628 pf.bottom = mContentBottom;
Dianne Hackborn20d94742014-05-29 18:35:45 -07003629 if (win.isVoiceInteraction()) {
3630 df.left = of.left = cf.left = mVoiceContentLeft;
3631 df.top = of.top = cf.top = mVoiceContentTop;
3632 df.right = of.right = cf.right = mVoiceContentRight;
3633 df.bottom = of.bottom = cf.bottom = mVoiceContentBottom;
3634 } else if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003635 df.left = of.left = cf.left = mDockLeft;
3636 df.top = of.top = cf.top = mDockTop;
3637 df.right = of.right = cf.right = mDockRight;
3638 df.bottom = of.bottom = cf.bottom = mDockBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07003639 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003640 df.left = of.left = cf.left = mContentLeft;
3641 df.top = of.top = cf.top = mContentTop;
3642 df.right = of.right = cf.right = mContentRight;
3643 df.bottom = of.bottom = cf.bottom = mContentBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07003644 }
3645 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3646 vf.left = mCurLeft;
3647 vf.top = mCurTop;
3648 vf.right = mCurRight;
3649 vf.bottom = mCurBottom;
3650 } else {
3651 vf.set(cf);
3652 }
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003653 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003654 }
3655 }
Craig Mautner69b08182012-09-05 13:07:13 -07003656
Craig Mautnerb816bed2013-07-23 10:26:17 -07003657 // TYPE_SYSTEM_ERROR is above the NavigationBar so it can't be allowed to extend over it.
3658 if ((fl & FLAG_LAYOUT_NO_LIMITS) != 0 && attrs.type != TYPE_SYSTEM_ERROR) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07003659 df.left = df.top = -10000;
3660 df.right = df.bottom = 10000;
3661 if (attrs.type != TYPE_WALLPAPER) {
3662 of.left = of.top = cf.left = cf.top = vf.left = vf.top = -10000;
3663 of.right = of.bottom = cf.right = cf.bottom = vf.right = vf.bottom = 10000;
3664 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003665 }
3666
Craig Mautnereda67292013-04-28 13:50:14 -07003667 if (DEBUG_LAYOUT) Slog.v(TAG, "Compute frame " + attrs.getTitle()
The Android Open Source Project11267662009-03-18 17:39:47 -07003668 + ": sim=#" + Integer.toHexString(sim)
RoboErik8a2cfc32014-05-16 11:19:38 -07003669 + " attach=" + attached + " type=" + attrs.type
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003670 + String.format(" flags=0x%08x", fl)
The Android Open Source Project11267662009-03-18 17:39:47 -07003671 + " pf=" + pf.toShortString() + " df=" + df.toShortString()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003672 + " of=" + of.toShortString()
John Spurlock46646232013-09-30 22:32:42 -04003673 + " cf=" + cf.toShortString() + " vf=" + vf.toShortString()
Adrian Roosfa104232014-06-20 16:10:14 -07003674 + " dcf=" + dcf.toShortString()
3675 + " sf=" + sf.toShortString());
Craig Mautner69b08182012-09-05 13:07:13 -07003676
Adrian Roosfa104232014-06-20 16:10:14 -07003677 win.computeFrameLw(pf, df, of, cf, vf, dcf, sf);
Craig Mautner69b08182012-09-05 13:07:13 -07003678
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003679 // Dock windows carve out the bottom of the screen, so normal windows
3680 // can't appear underneath them.
Craig Mautner8bd206b2012-10-03 10:32:02 -07003681 if (attrs.type == TYPE_INPUT_METHOD && win.isVisibleOrBehindKeyguardLw()
3682 && !win.getGivenInsetsPendingLw()) {
satok1bc0a492012-04-25 22:47:12 +09003683 setLastInputMethodWindowLw(null, null);
3684 offsetInputMethodWindowLw(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003685 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003686 if (attrs.type == TYPE_VOICE_INTERACTION && win.isVisibleOrBehindKeyguardLw()
3687 && !win.getGivenInsetsPendingLw()) {
3688 offsetVoiceInputWindowLw(win);
3689 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003690 }
3691
satok1bc0a492012-04-25 22:47:12 +09003692 private void offsetInputMethodWindowLw(WindowState win) {
3693 int top = win.getContentFrameLw().top;
3694 top += win.getGivenContentInsetsLw().top;
3695 if (mContentBottom > top) {
3696 mContentBottom = top;
3697 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003698 if (mVoiceContentBottom > top) {
3699 mVoiceContentBottom = top;
3700 }
satok1bc0a492012-04-25 22:47:12 +09003701 top = win.getVisibleFrameLw().top;
3702 top += win.getGivenVisibleInsetsLw().top;
3703 if (mCurBottom > top) {
3704 mCurBottom = top;
3705 }
Craig Mautnereda67292013-04-28 13:50:14 -07003706 if (DEBUG_LAYOUT) Slog.v(TAG, "Input method: mDockBottom="
satok1bc0a492012-04-25 22:47:12 +09003707 + mDockBottom + " mContentBottom="
3708 + mContentBottom + " mCurBottom=" + mCurBottom);
3709 }
3710
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003711 private void offsetVoiceInputWindowLw(WindowState win) {
3712 final int gravity = win.getAttrs().gravity;
3713 switch (gravity&((Gravity.AXIS_PULL_BEFORE|Gravity.AXIS_PULL_AFTER)
3714 << Gravity.AXIS_X_SHIFT)) {
3715 case Gravity.AXIS_PULL_BEFORE<<Gravity.AXIS_X_SHIFT: {
3716 int right = win.getContentFrameLw().right - win.getGivenContentInsetsLw().right;
3717 if (mVoiceContentLeft < right) {
3718 mVoiceContentLeft = right;
3719 }
3720 } break;
3721 case Gravity.AXIS_PULL_AFTER<<Gravity.AXIS_X_SHIFT: {
3722 int left = win.getContentFrameLw().left - win.getGivenContentInsetsLw().left;
3723 if (mVoiceContentRight < left) {
3724 mVoiceContentRight = left;
3725 }
3726 } break;
3727 }
3728 switch (gravity&((Gravity.AXIS_PULL_BEFORE|Gravity.AXIS_PULL_AFTER)
3729 << Gravity.AXIS_Y_SHIFT)) {
3730 case Gravity.AXIS_PULL_BEFORE<<Gravity.AXIS_Y_SHIFT: {
3731 int bottom = win.getContentFrameLw().bottom - win.getGivenContentInsetsLw().bottom;
3732 if (mVoiceContentTop < bottom) {
3733 mVoiceContentTop = bottom;
3734 }
3735 } break;
3736 case Gravity.AXIS_PULL_AFTER<<Gravity.AXIS_Y_SHIFT: {
3737 int top = win.getContentFrameLw().top - win.getGivenContentInsetsLw().top;
3738 if (mVoiceContentBottom < top) {
3739 mVoiceContentBottom = top;
3740 }
3741 } break;
3742 }
3743 }
3744
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003745 /** {@inheritDoc} */
Craig Mautner61ac6bb2012-02-02 17:29:33 -08003746 @Override
3747 public void finishLayoutLw() {
3748 return;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003749 }
3750
3751 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003752 @Override
Craig Mautner39834192012-09-02 07:47:24 -07003753 public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) {
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003754 mTopFullscreenOpaqueWindowState = null;
Craig Mautner2bc789b2014-03-19 19:48:38 -07003755 mAppsToBeHidden.clear();
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003756 mForceStatusBar = false;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003757 mForceStatusBarFromKeyguard = false;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08003758 mForcingShowNavBar = false;
3759 mForcingShowNavBarLayer = -1;
RoboErik8a2cfc32014-05-16 11:19:38 -07003760
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003761 mHideLockScreen = false;
3762 mAllowLockscreenWhenOn = false;
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003763 mDismissKeyguard = DISMISS_KEYGUARD_NONE;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003764 mShowingLockscreen = false;
3765 mShowingDream = false;
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003766 mWinShowWhenLocked = null;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003767 }
3768
3769 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003770 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003771 public void applyPostLayoutPolicyLw(WindowState win, WindowManager.LayoutParams attrs) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07003772 if (DEBUG_LAYOUT) Slog.i(TAG, "Win " + win + ": isVisibleOrBehindKeyguardLw="
3773 + win.isVisibleOrBehindKeyguardLw());
John Spurlockc6d1c602014-01-17 15:22:06 -05003774 final int fl = PolicyControl.getWindowFlags(win, attrs);
John Spurlock414c1f02013-12-04 13:47:36 -05003775 if (mTopFullscreenOpaqueWindowState == null
3776 && win.isVisibleLw() && attrs.type == TYPE_INPUT_METHOD) {
3777 mForcingShowNavBar = true;
3778 mForcingShowNavBarLayer = win.getSurfaceLayer();
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08003779 }
Jorim Jaggiafd4a552014-04-08 15:13:05 +02003780 if (attrs.type == TYPE_STATUS_BAR && (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Jorim Jaggiafd4a552014-04-08 15:13:05 +02003781 mForceStatusBarFromKeyguard = true;
3782 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003783 if (mTopFullscreenOpaqueWindowState == null &&
Dianne Hackborn01b02a72012-01-12 14:05:03 -08003784 win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()) {
John Spurlockc6d1c602014-01-17 15:22:06 -05003785 if ((fl & FLAG_FORCE_NOT_FULLSCREEN) != 0) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003786 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003787 mForceStatusBarFromKeyguard = true;
3788 } else {
3789 mForceStatusBar = true;
3790 }
3791 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003792 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003793 mShowingLockscreen = true;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07003794 }
Craig Mautnerab55e522014-03-03 13:26:03 -08003795 boolean appWindow = attrs.type >= FIRST_APPLICATION_WINDOW
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003796 && attrs.type <= LAST_APPLICATION_WINDOW;
3797 if (attrs.type == TYPE_DREAM) {
Jeff Brownc8018eb2012-10-29 21:33:27 -07003798 // If the lockscreen was showing when the dream started then wait
3799 // for the dream to draw before hiding the lockscreen.
3800 if (!mDreamingLockscreen
3801 || (win.isVisibleLw() && win.hasDrawnLw())) {
3802 mShowingDream = true;
Craig Mautnerab55e522014-03-03 13:26:03 -08003803 appWindow = true;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003804 }
3805 }
Craig Mautnerab55e522014-03-03 13:26:03 -08003806
Craig Mautner00156ec2014-03-06 22:29:02 -08003807 final boolean showWhenLocked = (fl & FLAG_SHOW_WHEN_LOCKED) != 0;
Craig Mautner74ee9382014-04-01 15:20:16 -07003808 final boolean dismissKeyguard = (fl & FLAG_DISMISS_KEYGUARD) != 0;
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003809 final boolean secureKeyguard = isKeyguardSecure();
Craig Mautnerab55e522014-03-03 13:26:03 -08003810 if (appWindow) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003811 if (showWhenLocked || (dismissKeyguard && !secureKeyguard)) {
3812 // Remove any previous windows with the same appToken.
Craig Mautner2bc789b2014-03-19 19:48:38 -07003813 mAppsToBeHidden.remove(win.getAppToken());
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003814 if (mAppsToBeHidden.isEmpty() && showWhenLocked &&
3815 isKeyguardSecureIncludingHidden()) {
3816 mWinShowWhenLocked = win;
3817 mHideLockScreen = true;
3818 mForceStatusBarFromKeyguard = false;
3819 }
Craig Mautner2bc789b2014-03-19 19:48:38 -07003820 } else {
3821 mAppsToBeHidden.add(win.getAppToken());
3822 }
Craig Mautnerab55e522014-03-03 13:26:03 -08003823 if (attrs.x == 0 && attrs.y == 0
3824 && attrs.width == WindowManager.LayoutParams.MATCH_PARENT
3825 && attrs.height == WindowManager.LayoutParams.MATCH_PARENT) {
3826 if (DEBUG_LAYOUT) Slog.v(TAG, "Fullscreen window: " + win);
3827 mTopFullscreenOpaqueWindowState = win;
Craig Mautner2bc789b2014-03-19 19:48:38 -07003828 if (mAppsToBeHidden.isEmpty()) {
Craig Mautnerda09ae32014-03-03 13:26:03 -08003829 if (showWhenLocked) {
3830 if (DEBUG_LAYOUT) Slog.v(TAG,
3831 "Setting mHideLockScreen to true by win " + win);
3832 mHideLockScreen = true;
3833 mForceStatusBarFromKeyguard = false;
3834 }
Craig Mautner4bdab6b2014-04-01 12:05:11 -07003835 if (dismissKeyguard && mDismissKeyguard == DISMISS_KEYGUARD_NONE) {
Craig Mautnerda09ae32014-03-03 13:26:03 -08003836 if (DEBUG_LAYOUT) Slog.v(TAG,
3837 "Setting mDismissKeyguard true by win " + win);
3838 mDismissKeyguard = mWinDismissingKeyguard == win ?
3839 DISMISS_KEYGUARD_CONTINUE : DISMISS_KEYGUARD_START;
3840 mWinDismissingKeyguard = win;
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003841 mForceStatusBarFromKeyguard = mShowingLockscreen && secureKeyguard;
Craig Mautnerda09ae32014-03-03 13:26:03 -08003842 }
Craig Mautnerab55e522014-03-03 13:26:03 -08003843 }
Craig Mautner00156ec2014-03-06 22:29:02 -08003844 if ((fl & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) {
Craig Mautnerab55e522014-03-03 13:26:03 -08003845 mAllowLockscreenWhenOn = true;
3846 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003847 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003848
3849 if (mWinShowWhenLocked != null &&
3850 mWinShowWhenLocked.getAppToken() != win.getAppToken()) {
3851 win.hideLw(false);
3852 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003853 }
3854 }
3855 }
3856
3857 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003858 @Override
Craig Mautner39834192012-09-02 07:47:24 -07003859 public int finishPostLayoutPolicyLw() {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003860 if (mWinShowWhenLocked != null &&
3861 mWinShowWhenLocked != mTopFullscreenOpaqueWindowState) {
3862 // A dialog is dismissing the keyguard. Put the wallpaper behind it and hide the
3863 // fullscreen window.
3864 // TODO: Make sure FLAG_SHOW_WALLPAPER is restored when dialog is dismissed. Or not.
3865 mWinShowWhenLocked.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
3866 mTopFullscreenOpaqueWindowState.hideLw(false);
3867 mTopFullscreenOpaqueWindowState = mWinShowWhenLocked;
3868 }
3869
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003870 int changes = 0;
Joe Onorato93056472010-09-10 10:30:46 -04003871 boolean topIsFullscreen = false;
Daniel Sandlere02d8082010-10-08 15:13:22 -04003872
3873 final WindowManager.LayoutParams lp = (mTopFullscreenOpaqueWindowState != null)
3874 ? mTopFullscreenOpaqueWindowState.getAttrs()
3875 : null;
3876
Jeff Brownc8018eb2012-10-29 21:33:27 -07003877 // If we are not currently showing a dream then remember the current
3878 // lockscreen state. We will use this to determine whether the dream
3879 // started while the lockscreen was showing and remember this state
3880 // while the dream is showing.
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003881 if (!mShowingDream) {
3882 mDreamingLockscreen = mShowingLockscreen;
3883 }
3884
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003885 if (mStatusBar != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07003886 if (DEBUG_LAYOUT) Slog.i(TAG, "force=" + mForceStatusBar
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003887 + " forcefkg=" + mForceStatusBarFromKeyguard
Dianne Hackbornd70bc2f2009-10-06 23:25:51 -07003888 + " top=" + mTopFullscreenOpaqueWindowState);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003889 if (mForceStatusBar || mForceStatusBarFromKeyguard) {
Craig Mautnereda67292013-04-28 13:50:14 -07003890 if (DEBUG_LAYOUT) Slog.v(TAG, "Showing status bar: forced");
John Spurlock27735a42013-08-14 17:57:38 -04003891 if (mStatusBarController.setBarShowingLw(true)) {
3892 changes |= FINISH_LAYOUT_REDO_LAYOUT;
3893 }
Craig Mautner81defc72013-10-29 11:10:42 -07003894 // Maintain fullscreen layout until incoming animation is complete.
3895 topIsFullscreen = mTopIsFullscreen && mStatusBar.isAnimatingLw();
John Spurlockf92b6162013-11-11 15:01:16 -05003896 // Transient status bar on the lockscreen is not allowed
3897 if (mForceStatusBarFromKeyguard && mStatusBarController.isTransientShowing()) {
3898 mStatusBarController.updateVisibilityLw(false /*transientAllowed*/,
3899 mLastSystemUiFlags, mLastSystemUiFlags);
3900 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003901 } else if (mTopFullscreenOpaqueWindowState != null) {
John Spurlockc6d1c602014-01-17 15:22:06 -05003902 final int fl = PolicyControl.getWindowFlags(null, lp);
Joe Onorato93056472010-09-10 10:30:46 -04003903 if (localLOGV) {
Craig Mautnereda67292013-04-28 13:50:14 -07003904 Slog.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw()
Joe Onorato93056472010-09-10 10:30:46 -04003905 + " shown frame: " + mTopFullscreenOpaqueWindowState.getShownFrameLw());
Craig Mautnereda67292013-04-28 13:50:14 -07003906 Slog.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs()
John Spurlockc6d1c602014-01-17 15:22:06 -05003907 + " lp.flags=0x" + Integer.toHexString(fl));
Joe Onorato93056472010-09-10 10:30:46 -04003908 }
John Spurlockc6d1c602014-01-17 15:22:06 -05003909 topIsFullscreen = (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003910 || (mLastSystemUiFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
Joe Onorato93056472010-09-10 10:30:46 -04003911 // The subtle difference between the window for mTopFullscreenOpaqueWindowState
3912 // and mTopIsFullscreen is that that mTopIsFullscreen is set only if the window
3913 // has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the
3914 // case though.
John Spurlock27735a42013-08-14 17:57:38 -04003915 if (mStatusBarController.isTransientShowing()) {
3916 if (mStatusBarController.setBarShowingLw(true)) {
John Spurlock32beb2c2013-03-11 10:16:47 -04003917 changes |= FINISH_LAYOUT_REDO_LAYOUT;
3918 }
3919 } else if (topIsFullscreen) {
Craig Mautnereda67292013-04-28 13:50:14 -07003920 if (DEBUG_LAYOUT) Slog.v(TAG, "** HIDING status bar");
John Spurlock27735a42013-08-14 17:57:38 -04003921 if (mStatusBarController.setBarShowingLw(false)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003922 changes |= FINISH_LAYOUT_REDO_LAYOUT;
Craig Mautnereda67292013-04-28 13:50:14 -07003923 } else {
Craig Mautnerc5a6e442013-06-05 17:22:35 -07003924 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar already hiding");
Daniel Sandler40427442010-07-16 11:44:52 -04003925 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003926 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07003927 if (DEBUG_LAYOUT) Slog.v(TAG, "** SHOWING status bar: top is not fullscreen");
John Spurlock27735a42013-08-14 17:57:38 -04003928 if (mStatusBarController.setBarShowingLw(true)) {
3929 changes |= FINISH_LAYOUT_REDO_LAYOUT;
3930 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003931 }
3932 }
3933 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04003934
Craig Mautner81defc72013-10-29 11:10:42 -07003935 if (mTopIsFullscreen != topIsFullscreen) {
3936 if (!topIsFullscreen) {
3937 // Force another layout when status bar becomes fully shown.
3938 changes |= FINISH_LAYOUT_REDO_LAYOUT;
3939 }
3940 mTopIsFullscreen = topIsFullscreen;
3941 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04003942
Craig Mautner39834192012-09-02 07:47:24 -07003943 // Hide the key guard if a visible window explicitly specifies that it wants to be
3944 // displayed when the screen is locked.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01003945 if (mKeyguardDelegate != null && mStatusBar != null) {
3946 if (localLOGV) Slog.v(TAG, "finishPostLayoutPolicyLw: mHideKeyguard="
3947 + mHideLockScreen);
3948 if (mDismissKeyguard != DISMISS_KEYGUARD_NONE && !isKeyguardSecure()) {
3949 mKeyguardHidden = true;
3950 if (processKeyguardSetHiddenResultLw(mKeyguardDelegate.setOccluded(true))) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003951 changes |= FINISH_LAYOUT_REDO_LAYOUT
3952 | FINISH_LAYOUT_REDO_CONFIG
3953 | FINISH_LAYOUT_REDO_WALLPAPER;
3954 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01003955 if (mKeyguardDelegate.isShowing()) {
3956 mHandler.post(new Runnable() {
3957 @Override
3958 public void run() {
3959 mKeyguardDelegate.keyguardDone(false, false);
3960 }
3961 });
3962 }
3963 } else if (mHideLockScreen) {
3964 mKeyguardHidden = true;
3965 if (processKeyguardSetHiddenResultLw(mKeyguardDelegate.setOccluded(true))) {
3966 changes |= FINISH_LAYOUT_REDO_LAYOUT
3967 | FINISH_LAYOUT_REDO_CONFIG
3968 | FINISH_LAYOUT_REDO_WALLPAPER;
3969 }
3970 } else if (mDismissKeyguard != DISMISS_KEYGUARD_NONE) {
3971 // This is the case of keyguard isSecure() and not mHideLockScreen.
3972 if (mDismissKeyguard == DISMISS_KEYGUARD_START) {
3973 // Only launch the next keyguard unlock window once per window.
3974 mKeyguardHidden = false;
3975 if (processKeyguardSetHiddenResultLw(mKeyguardDelegate.setOccluded(false))) {
3976 changes |= FINISH_LAYOUT_REDO_LAYOUT
3977 | FINISH_LAYOUT_REDO_CONFIG
3978 | FINISH_LAYOUT_REDO_WALLPAPER;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003979 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01003980 mHandler.post(new Runnable() {
3981 @Override
3982 public void run() {
3983 mKeyguardDelegate.dismiss();
3984 }
3985 });
3986 }
3987 } else {
3988 mWinDismissingKeyguard = null;
3989 mKeyguardHidden = false;
3990 if (processKeyguardSetHiddenResultLw(mKeyguardDelegate.setOccluded(false))) {
3991 changes |= FINISH_LAYOUT_REDO_LAYOUT
3992 | FINISH_LAYOUT_REDO_CONFIG
3993 | FINISH_LAYOUT_REDO_WALLPAPER;
3994 }
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -07003995 }
3996 }
Joe Onorato664644d2011-01-23 17:53:23 -08003997
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003998 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003999 // If the navigation bar has been hidden or shown, we need to do another
4000 // layout pass to update that window.
4001 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4002 }
Joe Onorato664644d2011-01-23 17:53:23 -08004003
Mike Lockwood28569302010-01-28 11:54:40 -05004004 // update since mAllowLockscreenWhenOn might have changed
4005 updateLockScreenTimeout();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004006 return changes;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004007 }
4008
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004009 /**
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004010 * Processes the result code of {@link IKeyguardService#setOccluded}. This is needed because we
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004011 * immediately need to put the wallpaper directly behind the Keyguard when a window with flag
4012 * {@link android.view.WindowManager.LayoutParams#FLAG_SHOW_WHEN_LOCKED} gets dismissed. If we
4013 * would wait for Keyguard to change the flags, that would be running asynchronously and thus be
4014 * too late so the user might see the window behind.
4015 *
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004016 * @param setHiddenResult The result code from {@link IKeyguardService#setOccluded}.
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004017 * @return Whether the flags have changed and we have to redo the layout.
4018 */
4019 private boolean processKeyguardSetHiddenResultLw(int setHiddenResult) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004020 if (setHiddenResult
4021 == IKeyguardServiceConstants.KEYGUARD_SERVICE_SET_OCCLUDED_RESULT_SET_FLAGS) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004022 mStatusBar.getAttrs().privateFlags |= PRIVATE_FLAG_KEYGUARD;
4023 mStatusBar.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
4024 return true;
4025 } else if (setHiddenResult
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004026 == IKeyguardServiceConstants.KEYGUARD_SERVICE_SET_OCCLUDED_RESULT_UNSET_FLAGS) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004027 mStatusBar.getAttrs().privateFlags &= ~PRIVATE_FLAG_KEYGUARD;
4028 mStatusBar.getAttrs().flags &= ~FLAG_SHOW_WALLPAPER;
4029 return true;
4030 } else {
4031 return false;
4032 }
4033 }
4034
4035 private boolean isStatusBarKeyguard() {
4036 return mStatusBar != null
4037 && (mStatusBar.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
4038 }
4039
Jose Lima9546b202014-07-02 17:21:51 -07004040 @Override
Dianne Hackborn08743722009-12-21 12:16:51 -08004041 public boolean allowAppAnimationsLw() {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004042 if (isStatusBarKeyguard() || mShowingDream) {
Craig Mautner28816302013-10-10 20:31:00 -07004043 // If keyguard or dreams is currently visible, no reason to animate behind it.
Dianne Hackborn08743722009-12-21 12:16:51 -08004044 return false;
4045 }
Dianne Hackborn08743722009-12-21 12:16:51 -08004046 return true;
4047 }
4048
Jose Lima9546b202014-07-02 17:21:51 -07004049 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07004050 public int focusChangedLw(WindowState lastFocus, WindowState newFocus) {
Joe Onorato664644d2011-01-23 17:53:23 -08004051 mFocusedWindow = newFocus;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004052 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004053 // If the navigation bar has been hidden or shown, we need to do another
4054 // layout pass to update that window.
4055 return FINISH_LAYOUT_REDO_LAYOUT;
4056 }
4057 return 0;
Joe Onorato664644d2011-01-23 17:53:23 -08004058 }
4059
Dianne Hackborn0ecadf72009-03-31 18:00:37 -07004060 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07004061 @Override
Jeff Brown46b9ac02010-04-22 18:58:52 -07004062 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
4063 // lid changed state
Jeff Brownc458ce92012-04-30 14:58:40 -07004064 final int newLidState = lidOpen ? LID_OPEN : LID_CLOSED;
4065 if (newLidState == mLidState) {
4066 return;
4067 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004068
Jeff Brownc458ce92012-04-30 14:58:40 -07004069 mLidState = newLidState;
4070 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07004071 updateRotation(true);
Jeff Brownc458ce92012-04-30 14:58:40 -07004072
4073 if (lidOpen) {
Jim Millere51cf7ae2013-06-25 18:31:56 -07004074 mPowerManager.wakeUp(SystemClock.uptimeMillis());
Jeff Brownc458ce92012-04-30 14:58:40 -07004075 } else if (!mLidControlsSleep) {
Jeff Brown96307042012-07-27 15:51:34 -07004076 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
Jeff Brown46b9ac02010-04-22 18:58:52 -07004077 }
4078 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004079
Michael Wright3818c922014-09-02 13:59:07 -07004080 @Override
4081 public void notifyCameraLensCoverSwitchChanged(long whenNanos, boolean lensCovered) {
4082 int lensCoverState = lensCovered ? CAMERA_LENS_COVERED : CAMERA_LENS_UNCOVERED;
4083 if (mCameraLensCoverState == lensCoverState) {
4084 return;
4085 }
4086 if (mCameraLensCoverState == CAMERA_LENS_COVERED &&
4087 lensCoverState == CAMERA_LENS_UNCOVERED) {
4088 Intent intent;
4089 final boolean keyguardActive = mKeyguardDelegate == null ? false :
4090 mKeyguardDelegate.isShowing();
4091 if (keyguardActive) {
4092 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE);
4093 } else {
4094 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
4095 }
4096 mContext.startActivityAsUser(intent, UserHandle.CURRENT_OR_SELF);
4097 }
4098 mCameraLensCoverState = lensCoverState;
4099 }
4100
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004101 void setHdmiPlugged(boolean plugged) {
4102 if (mHdmiPlugged != plugged) {
4103 mHdmiPlugged = plugged;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004104 updateRotation(true, true);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004105 Intent intent = new Intent(ACTION_HDMI_PLUGGED);
Joe Onoratodc100302011-01-11 17:07:41 -08004106 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004107 intent.putExtra(EXTRA_HDMI_PLUGGED_STATE, plugged);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07004108 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004109 }
4110 }
4111
Joe Onoratoea495d42011-04-06 11:41:11 -07004112 void initializeHdmiState() {
Joe Onorato7ba631f2011-05-04 15:28:00 -07004113 boolean plugged = false;
Joe Onoratoea495d42011-04-06 11:41:11 -07004114 // watch for HDMI plug messages if the hdmi switch exists
4115 if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) {
4116 mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi");
4117
Joe Onoratoea495d42011-04-06 11:41:11 -07004118 final String filename = "/sys/class/switch/hdmi/state";
4119 FileReader reader = null;
4120 try {
4121 reader = new FileReader(filename);
4122 char[] buf = new char[15];
4123 int n = reader.read(buf);
4124 if (n > 1) {
4125 plugged = 0 != Integer.parseInt(new String(buf, 0, n-1));
4126 }
4127 } catch (IOException ex) {
4128 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
4129 } catch (NumberFormatException ex) {
4130 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
4131 } finally {
4132 if (reader != null) {
4133 try {
4134 reader.close();
4135 } catch (IOException ex) {
4136 }
Joe Onoratodc100302011-01-11 17:07:41 -08004137 }
4138 }
4139 }
Joe Onorato7ba631f2011-05-04 15:28:00 -07004140 // This dance forces the code in setHdmiPlugged to run.
4141 // Always do this so the sticky intent is stuck (to false) if there is no hdmi.
4142 mHdmiPlugged = !plugged;
4143 setHdmiPlugged(!mHdmiPlugged);
Joe Onoratodc100302011-01-11 17:07:41 -08004144 }
4145
Dianne Hackbornc0e3f242011-08-19 14:19:10 -07004146 final Object mScreenshotLock = new Object();
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004147 ServiceConnection mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004148
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004149 final Runnable mScreenshotTimeout = new Runnable() {
4150 @Override public void run() {
4151 synchronized (mScreenshotLock) {
4152 if (mScreenshotConnection != null) {
4153 mContext.unbindService(mScreenshotConnection);
4154 mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004155 }
Winson Chung9112ec32011-06-27 13:15:32 -07004156 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004157 }
4158 };
4159
4160 // Assume this is called from the Handler thread.
4161 private void takeScreenshot() {
4162 synchronized (mScreenshotLock) {
4163 if (mScreenshotConnection != null) {
4164 return;
4165 }
4166 ComponentName cn = new ComponentName("com.android.systemui",
4167 "com.android.systemui.screenshot.TakeScreenshotService");
4168 Intent intent = new Intent();
4169 intent.setComponent(cn);
4170 ServiceConnection conn = new ServiceConnection() {
4171 @Override
4172 public void onServiceConnected(ComponentName name, IBinder service) {
4173 synchronized (mScreenshotLock) {
4174 if (mScreenshotConnection != this) {
4175 return;
4176 }
4177 Messenger messenger = new Messenger(service);
4178 Message msg = Message.obtain(null, 1);
4179 final ServiceConnection myConn = this;
4180 Handler h = new Handler(mHandler.getLooper()) {
4181 @Override
4182 public void handleMessage(Message msg) {
4183 synchronized (mScreenshotLock) {
4184 if (mScreenshotConnection == myConn) {
4185 mContext.unbindService(mScreenshotConnection);
4186 mScreenshotConnection = null;
4187 mHandler.removeCallbacks(mScreenshotTimeout);
4188 }
4189 }
4190 }
4191 };
4192 msg.replyTo = new Messenger(h);
Winson Chunga63bb842011-10-17 10:26:28 -07004193 msg.arg1 = msg.arg2 = 0;
4194 if (mStatusBar != null && mStatusBar.isVisibleLw())
4195 msg.arg1 = 1;
4196 if (mNavigationBar != null && mNavigationBar.isVisibleLw())
4197 msg.arg2 = 1;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004198 try {
4199 messenger.send(msg);
4200 } catch (RemoteException e) {
4201 }
4202 }
4203 }
4204 @Override
4205 public void onServiceDisconnected(ComponentName name) {}
4206 };
Amith Yamasani27b89e62013-01-16 12:30:11 -08004207 if (mContext.bindServiceAsUser(
4208 intent, conn, Context.BIND_AUTO_CREATE, UserHandle.CURRENT)) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004209 mScreenshotConnection = conn;
4210 mHandler.postDelayed(mScreenshotTimeout, 10000);
4211 }
4212 }
Winson Chung9112ec32011-06-27 13:15:32 -07004213 }
4214
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004215 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004216 @Override
Jeff Brown037c33e2014-04-09 00:31:55 -07004217 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) {
Jeff Brown96307042012-07-27 15:51:34 -07004218 if (!mSystemBooted) {
4219 // If we have not yet booted, don't let key events do anything.
4220 return 0;
4221 }
4222
Jeff Brown037c33e2014-04-09 00:31:55 -07004223 final boolean interactive = (policyFlags & FLAG_INTERACTIVE) != 0;
Jeff Brown1f245102010-11-18 20:53:46 -08004224 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
4225 final boolean canceled = event.isCanceled();
4226 final int keyCode = event.getKeyCode();
Jeff Browne20c9e02010-10-11 14:20:19 -07004227
Jeff Brown3122e442010-10-11 23:32:49 -07004228 final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0;
Jeff Brown3122e442010-10-11 23:32:49 -07004229
Mike Lockwoodc72b15f2009-11-28 20:58:22 -05004230 // If screen is off then we treat the case where the keyguard is open but hidden
4231 // the same as if it were open and in front.
4232 // This will prevent any keys other than the power button from waking the screen
4233 // when the keyguard is hidden by another activity.
Jim Miller5ecd8112013-01-09 18:50:26 -08004234 final boolean keyguardActive = (mKeyguardDelegate == null ? false :
Jeff Brown037c33e2014-04-09 00:31:55 -07004235 (interactive ?
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004236 mKeyguardDelegate.isShowingAndNotOccluded() :
Jim Miller5ecd8112013-01-09 18:50:26 -08004237 mKeyguardDelegate.isShowing()));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004238
Jeff Brown40013652012-05-16 21:22:36 -07004239 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004240 Log.d(TAG, "interceptKeyTq keycode=" + keyCode
Jeff Brown037c33e2014-04-09 00:31:55 -07004241 + " interactive=" + interactive + " keyguardActive=" + keyguardActive
Jeff Brown26875502014-01-30 21:47:47 -08004242 + " policyFlags=" + Integer.toHexString(policyFlags));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004243 }
4244
Jeff Brown037c33e2014-04-09 00:31:55 -07004245 // Basic policy based on interactive state.
Jeff Brown4d396052010-10-29 21:50:21 -07004246 int result;
Michael Wright337d9d22014-04-22 15:03:48 -07004247 boolean isWakeKey = (policyFlags & WindowManagerPolicy.FLAG_WAKE) != 0
4248 || event.isWakeKey();
Michael Wright70af00a2014-09-03 19:30:20 -07004249 if (interactive
4250 || (isInjected && !isWakeKey)
4251 || (!interactive && shouldDispatchInputWhenNonInteractive())) {
4252 // When the device is interactive, the key is injected, or we're currently dozing in a
4253 // non-interactive state with the screen on and the keyguard showing, pass the key to
4254 // the application.
Jeff Brown4d396052010-10-29 21:50:21 -07004255 result = ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07004256 isWakeKey = false;
Jeff Brown4d396052010-10-29 21:50:21 -07004257 } else {
4258 // When the screen is off and the key is not injected, determine whether
4259 // to wake the device but don't pass the key to the application.
4260 result = 0;
Jeff Brown26875502014-01-30 21:47:47 -08004261 if (isWakeKey && (!down || !isWakeKeyWhenScreenOff(keyCode))) {
4262 isWakeKey = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004263 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004264 }
4265
Justin Kohd378ad72013-04-01 12:18:26 -07004266 // If the key would be handled globally, just return the result, don't worry about special
4267 // key processing.
4268 if (mGlobalKeyManager.shouldHandleGlobalKey(keyCode, event)) {
Michael Wright85b1af62014-06-04 14:51:58 -07004269 if (isWakeKey) {
4270 mPowerManager.wakeUp(event.getEventTime());
4271 }
Justin Kohd378ad72013-04-01 12:18:26 -07004272 return result;
4273 }
4274
Jeff Brownbae8e772014-06-12 19:59:45 -07004275 boolean useHapticFeedback = down
4276 && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0
4277 && event.getRepeatCount() == 0;
4278
Jeff Brown4d396052010-10-29 21:50:21 -07004279 // Handle special keys.
4280 switch (keyCode) {
4281 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jeff Brownb0418da2010-11-01 15:24:01 -07004282 case KeyEvent.KEYCODE_VOLUME_UP:
4283 case KeyEvent.KEYCODE_VOLUME_MUTE: {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004284 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
4285 if (down) {
Jeff Brown037c33e2014-04-09 00:31:55 -07004286 if (interactive && !mVolumeDownKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004287 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
4288 mVolumeDownKeyTriggered = true;
4289 mVolumeDownKeyTime = event.getDownTime();
4290 mVolumeDownKeyConsumedByScreenshotChord = false;
4291 cancelPendingPowerKeyAction();
4292 interceptScreenshotChord();
4293 }
4294 } else {
4295 mVolumeDownKeyTriggered = false;
4296 cancelPendingScreenshotChordAction();
4297 }
4298 } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
4299 if (down) {
Jeff Brown037c33e2014-04-09 00:31:55 -07004300 if (interactive && !mVolumeUpKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004301 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
4302 mVolumeUpKeyTriggered = true;
4303 cancelPendingPowerKeyAction();
4304 cancelPendingScreenshotChordAction();
4305 }
4306 } else {
4307 mVolumeUpKeyTriggered = false;
4308 cancelPendingScreenshotChordAction();
4309 }
4310 }
Jeff Brown4d396052010-10-29 21:50:21 -07004311 if (down) {
Santos Cordon9eb45932014-06-27 12:28:43 -07004312 TelecommManager telecommManager = getTelecommService();
4313 if (telecommManager != null) {
4314 if (telecommManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07004315 // If an incoming call is ringing, either VOLUME key means
4316 // "silence ringer". We handle these keys here, rather than
4317 // in the InCallScreen, to make sure we'll respond to them
4318 // even if the InCallScreen hasn't come to the foreground yet.
4319 // Look for the DOWN event here, to agree with the "fallback"
4320 // behavior in the InCallScreen.
4321 Log.i(TAG, "interceptKeyBeforeQueueing:"
4322 + " VOLUME key-down while ringing: Silence ringer!");
Jeff Brown4d396052010-10-29 21:50:21 -07004323
Santos Cordon6848f722014-05-21 15:22:12 -07004324 // Silence the ringer. (It's safe to call this
4325 // even if the ringer has already been silenced.)
Santos Cordon9eb45932014-06-27 12:28:43 -07004326 telecommManager.silenceRinger();
Jeff Brown4d396052010-10-29 21:50:21 -07004327
Santos Cordon6848f722014-05-21 15:22:12 -07004328 // And *don't* pass this key thru to the current activity
4329 // (which is probably the InCallScreen.)
4330 result &= ~ACTION_PASS_TO_USER;
4331 break;
4332 }
Nancy Chen0eb1e402014-08-21 22:52:29 -07004333 if (telecommManager.isInCall()
Santos Cordon6848f722014-05-21 15:22:12 -07004334 && (result & ACTION_PASS_TO_USER) == 0) {
4335 // If we are in call but we decided not to pass the key to
RoboErik430fc482014-06-12 15:49:20 -07004336 // the application, just pass it to the session service.
4337
4338 MediaSessionLegacyHelper.getHelper(mContext)
RoboErik3c45c292014-07-08 16:47:31 -07004339 .sendVolumeKeyEvent(event, false);
Santos Cordon6848f722014-05-21 15:22:12 -07004340 break;
Jeff Brown4d396052010-10-29 21:50:21 -07004341 }
4342 }
4343
RoboErik430fc482014-06-12 15:49:20 -07004344 if ((result & ACTION_PASS_TO_USER) == 0) {
4345 // If we aren't passing to the user and no one else
4346 // handled it send it to the session manager to figure
4347 // out.
4348 MediaSessionLegacyHelper.getHelper(mContext)
RoboErik3c45c292014-07-08 16:47:31 -07004349 .sendVolumeKeyEvent(event, true);
Jeff Brown4d396052010-10-29 21:50:21 -07004350 break;
4351 }
4352 }
4353 break;
4354 }
4355
4356 case KeyEvent.KEYCODE_ENDCALL: {
4357 result &= ~ACTION_PASS_TO_USER;
4358 if (down) {
Santos Cordon9eb45932014-06-27 12:28:43 -07004359 TelecommManager telecommManager = getTelecommService();
Jeff Brown4d396052010-10-29 21:50:21 -07004360 boolean hungUp = false;
Santos Cordon9eb45932014-06-27 12:28:43 -07004361 if (telecommManager != null) {
4362 hungUp = telecommManager.endCall();
Jeff Brown4d396052010-10-29 21:50:21 -07004363 }
Jeff Brown037c33e2014-04-09 00:31:55 -07004364 interceptPowerKeyDown(!interactive || hungUp);
Jeff Brown4d396052010-10-29 21:50:21 -07004365 } else {
4366 if (interceptPowerKeyUp(canceled)) {
4367 if ((mEndcallBehavior
4368 & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) {
4369 if (goHome()) {
4370 break;
Dianne Hackborn0041e972009-07-24 17:14:43 -07004371 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004372 }
Jeff Brown4d396052010-10-29 21:50:21 -07004373 if ((mEndcallBehavior
4374 & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) {
Jeff Brownc12035c2014-08-13 18:52:25 -07004375 mPowerManager.goToSleep(event.getEventTime(),
4376 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
Jeff Brown26875502014-01-30 21:47:47 -08004377 isWakeKey = false;
Jeff Brown4d396052010-10-29 21:50:21 -07004378 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004379 }
Jeff Brown4d396052010-10-29 21:50:21 -07004380 }
4381 break;
4382 }
4383
4384 case KeyEvent.KEYCODE_POWER: {
4385 result &= ~ACTION_PASS_TO_USER;
4386 if (down) {
Jeff Brown26c6a502014-04-11 02:15:54 -07004387 boolean panic = mImmersiveModeConfirmation.onPowerKeyDown(interactive,
John Spurlockd9b70bd2014-02-06 17:02:44 -05004388 event.getDownTime(), isImmersiveMode(mLastSystemUiFlags));
4389 if (panic) {
4390 mHandler.post(mRequestTransientNav);
4391 }
Jeff Brown037c33e2014-04-09 00:31:55 -07004392 if (interactive && !mPowerKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004393 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
4394 mPowerKeyTriggered = true;
4395 mPowerKeyTime = event.getDownTime();
4396 interceptScreenshotChord();
Winson Chung9112ec32011-06-27 13:15:32 -07004397 }
Winson Chung9112ec32011-06-27 13:15:32 -07004398
Santos Cordon9eb45932014-06-27 12:28:43 -07004399 TelecommManager telecommManager = getTelecommService();
Jeff Brown4d396052010-10-29 21:50:21 -07004400 boolean hungUp = false;
Santos Cordon9eb45932014-06-27 12:28:43 -07004401 if (telecommManager != null) {
4402 if (telecommManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07004403 // Pressing Power while there's a ringing incoming
4404 // call should silence the ringer.
Santos Cordon9eb45932014-06-27 12:28:43 -07004405 telecommManager.silenceRinger();
Santos Cordon6848f722014-05-21 15:22:12 -07004406 } else if ((mIncallPowerBehavior
4407 & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0
Nancy Chen0eb1e402014-08-21 22:52:29 -07004408 && telecommManager.isInCall() && interactive) {
Santos Cordon6848f722014-05-21 15:22:12 -07004409 // Otherwise, if "Power button ends call" is enabled,
4410 // the Power button will hang up any current active call.
Santos Cordon9eb45932014-06-27 12:28:43 -07004411 hungUp = telecommManager.endCall();
Jeff Brown4d396052010-10-29 21:50:21 -07004412 }
4413 }
Jeff Brown037c33e2014-04-09 00:31:55 -07004414 interceptPowerKeyDown(!interactive || hungUp
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004415 || mVolumeDownKeyTriggered || mVolumeUpKeyTriggered);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004416 } else {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004417 mPowerKeyTriggered = false;
4418 cancelPendingScreenshotChordAction();
4419 if (interceptPowerKeyUp(canceled || mPendingPowerKeyUpCanceled)) {
Jeff Brown6d8fd272014-05-20 21:24:38 -07004420 powerShortPress(event.getEventTime());
Jeff Brown26875502014-01-30 21:47:47 -08004421 isWakeKey = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004422 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004423 mPendingPowerKeyUpCanceled = false;
Jeff Brown4d396052010-10-29 21:50:21 -07004424 }
4425 break;
4426 }
4427
Jeff Brown6212a492014-03-07 13:58:47 -08004428 case KeyEvent.KEYCODE_SLEEP: {
4429 result &= ~ACTION_PASS_TO_USER;
Jeff Brownbae8e772014-06-12 19:59:45 -07004430 if (!mPowerManager.isInteractive()) {
4431 useHapticFeedback = false; // suppress feedback if already non-interactive
4432 }
Jeff Brownc12035c2014-08-13 18:52:25 -07004433 mPowerManager.goToSleep(event.getEventTime(),
4434 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
Jeff Brown6212a492014-03-07 13:58:47 -08004435 isWakeKey = false;
4436 break;
4437 }
4438
4439 case KeyEvent.KEYCODE_WAKEUP: {
4440 result &= ~ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07004441 isWakeKey = true;
Jeff Brown6212a492014-03-07 13:58:47 -08004442 break;
4443 }
4444
Jeff Brown4d396052010-10-29 21:50:21 -07004445 case KeyEvent.KEYCODE_MEDIA_PLAY:
4446 case KeyEvent.KEYCODE_MEDIA_PAUSE:
4447 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
4448 if (down) {
Santos Cordon9eb45932014-06-27 12:28:43 -07004449 TelecommManager telecommManager = getTelecommService();
4450 if (telecommManager != null) {
Nancy Chen0eb1e402014-08-21 22:52:29 -07004451 if (telecommManager.isInCall()) {
Santos Cordon6848f722014-05-21 15:22:12 -07004452 // Suppress PLAY/PAUSE toggle when phone is ringing or in-call
4453 // to avoid music playback.
4454 break;
Jeff Brown3122e442010-10-11 23:32:49 -07004455 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004456 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004457 }
Jeff Brown4d396052010-10-29 21:50:21 -07004458 case KeyEvent.KEYCODE_HEADSETHOOK:
4459 case KeyEvent.KEYCODE_MUTE:
4460 case KeyEvent.KEYCODE_MEDIA_STOP:
4461 case KeyEvent.KEYCODE_MEDIA_NEXT:
4462 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
4463 case KeyEvent.KEYCODE_MEDIA_REWIND:
4464 case KeyEvent.KEYCODE_MEDIA_RECORD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09004465 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
4466 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: {
Jeff Brown4d396052010-10-29 21:50:21 -07004467 if ((result & ACTION_PASS_TO_USER) == 0) {
4468 // Only do this if we would otherwise not pass it to the user. In that
4469 // case, the PhoneWindow class will do the same thing, except it will
4470 // only do it if the showing app doesn't process the key on its own.
Jeff Brown40013652012-05-16 21:22:36 -07004471 // Note that we need to make a copy of the key event here because the
4472 // original key event will be recycled when we return.
Jeff Brown4d396052010-10-29 21:50:21 -07004473 mBroadcastWakeLock.acquire();
Jeff Brown40013652012-05-16 21:22:36 -07004474 Message msg = mHandler.obtainMessage(MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK,
4475 new KeyEvent(event));
4476 msg.setAsynchronous(true);
4477 msg.sendToTarget();
Jeff Brown4d396052010-10-29 21:50:21 -07004478 }
4479 break;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004480 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004481
Jeff Brown4d396052010-10-29 21:50:21 -07004482 case KeyEvent.KEYCODE_CALL: {
4483 if (down) {
Santos Cordon9eb45932014-06-27 12:28:43 -07004484 TelecommManager telecommManager = getTelecommService();
4485 if (telecommManager != null) {
4486 if (telecommManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07004487 Log.i(TAG, "interceptKeyBeforeQueueing:"
4488 + " CALL key-down while ringing: Answer the call!");
Santos Cordon9eb45932014-06-27 12:28:43 -07004489 telecommManager.acceptRingingCall();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004490
Santos Cordon6848f722014-05-21 15:22:12 -07004491 // And *don't* pass this key thru to the current activity
4492 // (which is presumably the InCallScreen.)
4493 result &= ~ACTION_PASS_TO_USER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004494 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004495 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004496 }
Jeff Brown4d396052010-10-29 21:50:21 -07004497 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004498 }
Michael Wright869a67c2014-08-26 19:33:06 -07004499 case KeyEvent.KEYCODE_VOICE_ASSIST: {
4500 // Only do this if we would otherwise not pass it to the user. In that case,
4501 // interceptKeyBeforeDispatching would apply a similar but different policy in
4502 // order to invoke voice assist actions. Note that we need to make a copy of the
4503 // key event here because the original key event will be recycled when we return.
4504 if ((result & ACTION_PASS_TO_USER) == 0 && !down) {
4505 mBroadcastWakeLock.acquire();
4506 Message msg = mHandler.obtainMessage(MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK,
4507 keyguardActive ? 1 : 0, 0);
4508 msg.setAsynchronous(true);
4509 msg.sendToTarget();
4510 }
4511 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004512 }
Jeff Brown26875502014-01-30 21:47:47 -08004513
Jeff Brownbae8e772014-06-12 19:59:45 -07004514 if (useHapticFeedback) {
4515 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
4516 }
4517
Jeff Brown26875502014-01-30 21:47:47 -08004518 if (isWakeKey) {
4519 mPowerManager.wakeUp(event.getEventTime());
4520 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004521 return result;
4522 }
4523
Jeff Brown1c2e4942012-11-06 16:32:01 -08004524 /**
4525 * When the screen is off we ignore some keys that might otherwise typically
4526 * be considered wake keys. We filter them out here.
4527 *
4528 * {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it
4529 * is always considered a wake key.
4530 */
4531 private boolean isWakeKeyWhenScreenOff(int keyCode) {
4532 switch (keyCode) {
4533 // ignore volume keys unless docked
4534 case KeyEvent.KEYCODE_VOLUME_UP:
4535 case KeyEvent.KEYCODE_VOLUME_DOWN:
4536 case KeyEvent.KEYCODE_VOLUME_MUTE:
4537 return mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED;
4538
4539 // ignore media and camera keys
4540 case KeyEvent.KEYCODE_MUTE:
4541 case KeyEvent.KEYCODE_HEADSETHOOK:
4542 case KeyEvent.KEYCODE_MEDIA_PLAY:
4543 case KeyEvent.KEYCODE_MEDIA_PAUSE:
4544 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
4545 case KeyEvent.KEYCODE_MEDIA_STOP:
4546 case KeyEvent.KEYCODE_MEDIA_NEXT:
4547 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
4548 case KeyEvent.KEYCODE_MEDIA_REWIND:
4549 case KeyEvent.KEYCODE_MEDIA_RECORD:
4550 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09004551 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK:
Jeff Brown1c2e4942012-11-06 16:32:01 -08004552 case KeyEvent.KEYCODE_CAMERA:
4553 return false;
4554 }
4555 return true;
4556 }
4557
4558
Jeff Brown56194eb2011-03-02 19:23:13 -08004559 /** {@inheritDoc} */
4560 @Override
Michael Wright70af00a2014-09-03 19:30:20 -07004561 public int interceptMotionBeforeQueueingNonInteractive(long whenNanos, int policyFlags) {
4562 if ((policyFlags & FLAG_WAKE) != 0) {
4563 mPowerManager.wakeUp(whenNanos / 1000000);
4564 return 0;
4565 }
4566 if (shouldDispatchInputWhenNonInteractive()) {
4567 return ACTION_PASS_TO_USER;
4568 }
Jeff Brown037c33e2014-04-09 00:31:55 -07004569 return 0;
Jeff Brown56194eb2011-03-02 19:23:13 -08004570 }
4571
Michael Wright70af00a2014-09-03 19:30:20 -07004572 private boolean shouldDispatchInputWhenNonInteractive() {
4573 return keyguardIsShowingTq() && mDisplay != null &&
4574 mDisplay.getState() != Display.STATE_OFF;
4575 }
4576
Jeff Brown40013652012-05-16 21:22:36 -07004577 void dispatchMediaKeyWithWakeLock(KeyEvent event) {
4578 if (DEBUG_INPUT) {
4579 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: " + event);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004580 }
4581
Jeff Brown40013652012-05-16 21:22:36 -07004582 if (mHavePendingMediaKeyRepeatWithWakeLock) {
4583 if (DEBUG_INPUT) {
4584 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: canceled repeat");
4585 }
4586
4587 mHandler.removeMessages(MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK);
4588 mHavePendingMediaKeyRepeatWithWakeLock = false;
4589 mBroadcastWakeLock.release(); // pending repeat was holding onto the wake lock
4590 }
4591
4592 dispatchMediaKeyWithWakeLockToAudioService(event);
4593
4594 if (event.getAction() == KeyEvent.ACTION_DOWN
4595 && event.getRepeatCount() == 0) {
4596 mHavePendingMediaKeyRepeatWithWakeLock = true;
4597
4598 Message msg = mHandler.obtainMessage(
4599 MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK, event);
4600 msg.setAsynchronous(true);
4601 mHandler.sendMessageDelayed(msg, ViewConfiguration.getKeyRepeatTimeout());
4602 } else {
4603 mBroadcastWakeLock.release();
4604 }
4605 }
4606
4607 void dispatchMediaKeyRepeatWithWakeLock(KeyEvent event) {
4608 mHavePendingMediaKeyRepeatWithWakeLock = false;
4609
4610 KeyEvent repeatEvent = KeyEvent.changeTimeRepeat(event,
4611 SystemClock.uptimeMillis(), 1, event.getFlags() | KeyEvent.FLAG_LONG_PRESS);
4612 if (DEBUG_INPUT) {
4613 Slog.d(TAG, "dispatchMediaKeyRepeatWithWakeLock: " + repeatEvent);
4614 }
4615
4616 dispatchMediaKeyWithWakeLockToAudioService(repeatEvent);
4617 mBroadcastWakeLock.release();
4618 }
4619
4620 void dispatchMediaKeyWithWakeLockToAudioService(KeyEvent event) {
4621 if (ActivityManagerNative.isSystemReady()) {
RoboErik430fc482014-06-12 15:49:20 -07004622 MediaSessionLegacyHelper.getHelper(mContext).sendMediaButtonEvent(event, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004623 }
4624 }
4625
Michael Wright869a67c2014-08-26 19:33:06 -07004626 void launchVoiceAssistWithWakeLock(boolean keyguardActive) {
4627 Intent voiceIntent =
4628 new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
4629 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, keyguardActive);
4630 mContext.startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
4631 mBroadcastWakeLock.release();
4632 }
4633
Mike Lockwood1753f7f2009-08-24 14:49:07 -07004634 BroadcastReceiver mDockReceiver = new BroadcastReceiver() {
Craig Mautnereee29c42013-01-17 14:44:34 -08004635 @Override
Mike Lockwood1753f7f2009-08-24 14:49:07 -07004636 public void onReceive(Context context, Intent intent) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07004637 if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) {
4638 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
4639 Intent.EXTRA_DOCK_STATE_UNDOCKED);
Daniel Sandler6396c722013-04-16 20:19:09 -04004640 } else {
4641 try {
4642 IUiModeManager uiModeService = IUiModeManager.Stub.asInterface(
4643 ServiceManager.getService(Context.UI_MODE_SERVICE));
4644 mUiMode = uiModeService.getCurrentModeType();
4645 } catch (RemoteException e) {
4646 }
Dianne Hackborn80fa1662009-10-07 14:02:10 -07004647 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004648 updateRotation(true);
Craig Mautnereee29c42013-01-17 14:44:34 -08004649 synchronized (mLock) {
4650 updateOrientationListenerLp();
4651 }
Mike Lockwood1753f7f2009-08-24 14:49:07 -07004652 }
4653 };
4654
Jeff Brown6aaf2952012-10-05 16:01:08 -07004655 BroadcastReceiver mDreamReceiver = new BroadcastReceiver() {
4656 @Override
4657 public void onReceive(Context context, Intent intent) {
4658 if (Intent.ACTION_DREAMING_STARTED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004659 if (mKeyguardDelegate != null) {
4660 mKeyguardDelegate.onDreamingStarted();
Jeff Brown6aaf2952012-10-05 16:01:08 -07004661 }
4662 } else if (Intent.ACTION_DREAMING_STOPPED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004663 if (mKeyguardDelegate != null) {
4664 mKeyguardDelegate.onDreamingStopped();
Jeff Brown6aaf2952012-10-05 16:01:08 -07004665 }
4666 }
4667 }
4668 };
4669
Christopher Tate5e08af02012-09-21 17:17:22 -07004670 BroadcastReceiver mMultiuserReceiver = new BroadcastReceiver() {
4671 @Override
4672 public void onReceive(Context context, Intent intent) {
4673 if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) {
4674 // tickle the settings observer: this first ensures that we're
4675 // observing the relevant settings for the newly-active user,
4676 // and then updates our own bookkeeping based on the now-
4677 // current user.
4678 mSettingsObserver.onChange(false);
John Spurlockce479d82012-11-29 09:52:21 -05004679
4680 // force a re-application of focused window sysui visibility.
4681 // the window may never have been shown for this user
4682 // e.g. the keyguard when going through the new-user setup flow
John Spurlock04db1762013-05-13 12:46:41 -04004683 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
John Spurlockce479d82012-11-29 09:52:21 -05004684 mLastSystemUiFlags = 0;
4685 updateSystemUiVisibilityLw();
4686 }
Christopher Tate5e08af02012-09-21 17:17:22 -07004687 }
4688 }
4689 };
4690
John Spurlockd9b70bd2014-02-06 17:02:44 -05004691 private final Runnable mRequestTransientNav = new Runnable() {
4692 @Override
4693 public void run() {
4694 requestTransientBars(mNavigationBar);
4695 }
4696 };
4697
John Spurlocke1f366f2013-08-05 12:22:40 -04004698 private void requestTransientBars(WindowState swipeTarget) {
John Spurlock04db1762013-05-13 12:46:41 -04004699 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Maurice Lam99c6e072014-04-28 18:24:28 -07004700 if (!isUserSetupComplete()) {
4701 // Swipe-up for navigation bar is disabled during setup
4702 return;
4703 }
John Spurlock27735a42013-08-14 17:57:38 -04004704 boolean sb = mStatusBarController.checkShowTransientBarLw();
4705 boolean nb = mNavigationBarController.checkShowTransientBarLw();
John Spurlockad3e6cb2013-04-30 08:47:43 -04004706 if (sb || nb) {
John Spurlocke1f366f2013-08-05 12:22:40 -04004707 WindowState barTarget = sb ? mStatusBar : mNavigationBar;
4708 if (sb ^ nb && barTarget != swipeTarget) {
4709 if (DEBUG) Slog.d(TAG, "Not showing transient bar, wrong swipe target");
John Spurlockad3e6cb2013-04-30 08:47:43 -04004710 return;
4711 }
John Spurlock27735a42013-08-14 17:57:38 -04004712 if (sb) mStatusBarController.showTransient();
4713 if (nb) mNavigationBarController.showTransient();
John Spurlockf1a36642013-10-12 17:50:42 -04004714 mImmersiveModeConfirmation.confirmCurrentPrompt();
John Spurlockad3e6cb2013-04-30 08:47:43 -04004715 updateSystemUiVisibilityLw();
John Spurlock32beb2c2013-03-11 10:16:47 -04004716 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04004717 }
4718 }
4719
Jeff Brownc38c9be2012-10-04 13:16:19 -07004720 @Override
Jeff Brown140ffc72014-05-01 15:18:00 -07004721 public void goingToSleep(int why) {
Dianne Hackborn74489012009-03-24 20:50:09 -07004722 EventLog.writeEvent(70000, 0);
The Android Open Source Project0727d222009-03-11 12:11:58 -07004723 synchronized (mLock) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004724 mScreenOnEarly = false;
4725 mScreenOnFully = false;
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07004726 }
Jim Miller5ecd8112013-01-09 18:50:26 -08004727 if (mKeyguardDelegate != null) {
4728 mKeyguardDelegate.onScreenTurnedOff(why);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004729 }
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07004730 synchronized (mLock) {
Jeff Browna20dda42014-05-27 20:57:24 -07004731 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07004732 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05004733 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07004734 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004735 }
4736
Jeff Brownc38c9be2012-10-04 13:16:19 -07004737 @Override
Jeff Brown140ffc72014-05-01 15:18:00 -07004738 public void wakingUp(final ScreenOnListener screenOnListener) {
Dianne Hackborn74489012009-03-24 20:50:09 -07004739 EventLog.writeEvent(70000, 1);
Craig Mautner8a0da012014-05-31 15:13:37 -07004740 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turning on...",
4741 new RuntimeException("here").fillInStackTrace());
4742 mHandler.obtainMessage(MSG_WAKING_UP, screenOnListener).sendToTarget();
4743 }
4744
4745 // Called on the mHandler thread.
4746 private void handleWakingUp(final ScreenOnListener screenOnListener) {
4747 if (screenOnListener != null) {
Craig Mautner13f6ea72014-06-23 14:57:02 -07004748 mScreenOnListener = screenOnListener;
Dianne Hackborn40011092011-09-22 13:37:48 -07004749 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07004750
The Android Open Source Project0727d222009-03-11 12:11:58 -07004751 synchronized (mLock) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004752 mScreenOnEarly = true;
Jeff Browna20dda42014-05-27 20:57:24 -07004753 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07004754 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05004755 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07004756 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07004757
Craig Mautner8a0da012014-05-31 15:13:37 -07004758 mKeyguardDrawComplete = false;
4759 mWindowManagerDrawComplete = false;
Jim Miller5ecd8112013-01-09 18:50:26 -08004760 if (mKeyguardDelegate != null) {
Craig Mautner8a0da012014-05-31 15:13:37 -07004761 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
4762 mHandler.sendEmptyMessageDelayed(MSG_KEYGUARD_DRAWN_TIMEOUT, 1000);
4763 mKeyguardDelegate.onScreenTurnedOn(mKeyguardDelegateCallback);
Jeff Brownc38c9be2012-10-04 13:16:19 -07004764 } else {
Craig Mautner8a0da012014-05-31 15:13:37 -07004765 if (DEBUG_WAKEUP) Slog.d(TAG, "null mKeyguardDelegate: setting mKeyguardDrawComplete.");
4766 mKeyguardDrawComplete = true;
Jeff Brownc38c9be2012-10-04 13:16:19 -07004767 }
Craig Mautner8a0da012014-05-31 15:13:37 -07004768 mWindowManagerInternal.waitForAllWindowsDrawn(mWindowManagerDrawCallback, 500);
Jeff Brownc38c9be2012-10-04 13:16:19 -07004769 }
4770
Craig Mautner8a0da012014-05-31 15:13:37 -07004771 // Called on the mHandler thread.
4772 private void finishScreenTurningOn() {
4773 if (DEBUG_WAKEUP) Slog.d(TAG,
4774 "finishScreenTurningOn: mKeyguardDrawComplete=" + mKeyguardDrawComplete
4775 + " mWindowManagerDrawComplete=" + mWindowManagerDrawComplete);
4776 if (!mKeyguardDrawComplete || !mWindowManagerDrawComplete) {
4777 return;
Jeff Brownc38c9be2012-10-04 13:16:19 -07004778 }
4779
Craig Mautner13f6ea72014-06-23 14:57:02 -07004780 ScreenOnListener screenOnListener;
Jeff Brownc38c9be2012-10-04 13:16:19 -07004781 synchronized (mLock) {
4782 mScreenOnFully = true;
Craig Mautner13f6ea72014-06-23 14:57:02 -07004783 screenOnListener = mScreenOnListener;
4784 mScreenOnListener = null;
Jeff Brownc38c9be2012-10-04 13:16:19 -07004785 }
4786
Jeff Brown4fc45272012-10-10 18:28:14 -07004787 try {
4788 mWindowManager.setEventDispatching(true);
4789 } catch (RemoteException unhandled) {
4790 }
4791
Craig Mautner13f6ea72014-06-23 14:57:02 -07004792 if (screenOnListener != null) {
4793 screenOnListener.onScreenOn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07004794 }
Craig Mautner8a0da012014-05-31 15:13:37 -07004795
4796 setKeyguardDrawn();
Craig Mautnera631d492014-08-05 15:16:01 -07004797
4798 if (mBootMessageNeedsHiding) {
4799 handleHideBootMessage();
4800 mBootMessageNeedsHiding = false;
4801 }
4802 }
4803
4804 private void handleHideBootMessage() {
4805 if (mBootMsgDialog == null) {
4806 if (DEBUG_WAKEUP) Slog.d(TAG, "handleHideBootMessage: boot message not up");
4807 return;
4808 }
4809 if (!mKeyguardDrawComplete || !mWindowManagerDrawComplete) {
4810 if (DEBUG_WAKEUP) Slog.d(TAG, "handleHideBootMessage: deferring until keyguard ready");
4811 mBootMessageNeedsHiding = true;
4812 return;
4813 }
4814 if (DEBUG_WAKEUP) Slog.d(TAG, "handleHideBootMessage: dismissing");
4815 mBootMsgDialog.dismiss();
4816 mBootMsgDialog = null;
Jeff Brownc38c9be2012-10-04 13:16:19 -07004817 }
4818
4819 @Override
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004820 public boolean isScreenOnEarly() {
4821 return mScreenOnEarly;
4822 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07004823
4824 @Override
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004825 public boolean isScreenOnFully() {
4826 return mScreenOnFully;
Dianne Hackborn08743722009-12-21 12:16:51 -08004827 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07004828
Dianne Hackborn08743722009-12-21 12:16:51 -08004829 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07004830 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004831 public void enableKeyguard(boolean enabled) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004832 if (mKeyguardDelegate != null) {
4833 mKeyguardDelegate.setKeyguardEnabled(enabled);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004834 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004835 }
4836
4837 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07004838 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004839 public void exitKeyguardSecurely(OnKeyguardExitResult callback) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004840 if (mKeyguardDelegate != null) {
4841 mKeyguardDelegate.verifyUnlock(callback);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004842 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004843 }
4844
Mike Lockwoodf7913302009-11-28 22:27:10 -05004845 private boolean keyguardIsShowingTq() {
Jim Miller5ecd8112013-01-09 18:50:26 -08004846 if (mKeyguardDelegate == null) return false;
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004847 return mKeyguardDelegate.isShowingAndNotOccluded();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004848 }
4849
Mike Lockwood520d8bc2011-02-18 13:23:13 -05004850
4851 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07004852 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05004853 public boolean isKeyguardLocked() {
4854 return keyguardOn();
4855 }
4856
4857 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07004858 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05004859 public boolean isKeyguardSecure() {
Jim Miller5ecd8112013-01-09 18:50:26 -08004860 if (mKeyguardDelegate == null) return false;
4861 return mKeyguardDelegate.isSecure();
Mike Lockwood520d8bc2011-02-18 13:23:13 -05004862 }
4863
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004864 // Returns true if keyguard is currently locked whether or not it is currently hidden.
4865 private boolean isKeyguardSecureIncludingHidden() {
4866 return mKeyguardDelegate.isSecure() && mKeyguardDelegate.isShowing();
4867 }
4868
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004869 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07004870 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004871 public boolean inKeyguardRestrictedKeyInputMode() {
Jim Miller5ecd8112013-01-09 18:50:26 -08004872 if (mKeyguardDelegate == null) return false;
4873 return mKeyguardDelegate.isInputRestricted();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004874 }
4875
Jose Lima9546b202014-07-02 17:21:51 -07004876 @Override
Dianne Hackborn90c52de2011-09-23 12:57:44 -07004877 public void dismissKeyguardLw() {
RoboErik8a2cfc32014-05-16 11:19:38 -07004878 if (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()) {
Daniel Sandler1ce804392012-11-07 15:07:12 -05004879 mHandler.post(new Runnable() {
Jose Lima9546b202014-07-02 17:21:51 -07004880 @Override
Daniel Sandler1ce804392012-11-07 15:07:12 -05004881 public void run() {
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02004882 // ask the keyguard to prompt the user to authenticate if necessary
4883 mKeyguardDelegate.dismiss();
4884 }
4885 });
4886 }
4887 }
4888
4889 public void notifyActivityDrawnForKeyguardLw() {
4890 if (mKeyguardDelegate != null) {
4891 mHandler.post(new Runnable() {
4892 @Override
4893 public void run() {
4894 mKeyguardDelegate.onActivityDrawn();
Daniel Sandler1ce804392012-11-07 15:07:12 -05004895 }
4896 });
Dianne Hackborn90c52de2011-09-23 12:57:44 -07004897 }
4898 }
4899
Jorim Jaggicff0acb2014-03-31 16:35:15 +02004900 private void setKeyguardDrawn() {
4901 synchronized (mLock) {
4902 mKeyguardDrawn = true;
4903 }
4904 try {
4905 mWindowManager.enableScreenIfNeeded();
4906 } catch (RemoteException unhandled) {
4907 }
4908 }
4909
4910 @Override
4911 public boolean isKeyguardDrawnLw() {
4912 synchronized (mLock) {
4913 return mKeyguardDrawn;
4914 }
4915 }
4916
Jorim Jaggi0d674622014-05-21 01:34:15 +02004917 @Override
Jorim Jaggie29b2db2014-05-30 23:17:03 +02004918 public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) {
Jorim Jaggi0d674622014-05-21 01:34:15 +02004919 if (mKeyguardDelegate != null) {
Jorim Jaggie29b2db2014-05-30 23:17:03 +02004920 mKeyguardDelegate.startKeyguardExitAnimation(startTime, fadeoutDuration);
Jorim Jaggi0d674622014-05-21 01:34:15 +02004921 }
4922 }
4923
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004924 void sendCloseSystemWindows() {
4925 sendCloseSystemWindows(mContext, null);
4926 }
4927
4928 void sendCloseSystemWindows(String reason) {
4929 sendCloseSystemWindows(mContext, reason);
4930 }
4931
4932 static void sendCloseSystemWindows(Context context, String reason) {
4933 if (ActivityManagerNative.isSystemReady()) {
Dianne Hackborn94a679d2009-07-28 17:51:07 -07004934 try {
4935 ActivityManagerNative.getDefault().closeSystemDialogs(reason);
4936 } catch (RemoteException e) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004937 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004938 }
4939 }
Mitsuru Oshima831d0d92009-06-16 18:27:18 -07004940
Jeff Brown01a98dd2011-09-20 15:08:29 -07004941 @Override
4942 public int rotationForOrientationLw(int orientation, int lastRotation) {
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05004943 if (false) {
4944 Slog.v(TAG, "rotationForOrientationLw(orient="
4945 + orientation + ", last=" + lastRotation
4946 + "); user=" + mUserRotation + " "
4947 + ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED)
4948 ? "USER_ROTATION_LOCKED" : "")
4949 );
4950 }
4951
Craig Mautner46ac6fa2013-08-01 10:06:34 -07004952 if (mForceDefaultOrientation) {
4953 return Surface.ROTATION_0;
4954 }
4955
The Android Open Source Project0727d222009-03-11 12:11:58 -07004956 synchronized (mLock) {
Jeff Brownc0347aa2011-09-23 17:26:09 -07004957 int sensorRotation = mOrientationListener.getProposedRotation(); // may be -1
4958 if (sensorRotation < 0) {
Jeff Brown0f862b42012-09-27 21:11:01 -07004959 sensorRotation = lastRotation;
Jeff Brownc0347aa2011-09-23 17:26:09 -07004960 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004961
Jeff Browndec6cf42011-11-15 14:08:20 -08004962 final int preferredRotation;
Jeff Brown2e7760e2012-04-11 15:14:55 -07004963 if (mLidState == LID_OPEN && mLidOpenRotation >= 0) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07004964 // Ignore sensor when lid switch is open and rotation is forced.
4965 preferredRotation = mLidOpenRotation;
4966 } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR
Jeff Brownc0347aa2011-09-23 17:26:09 -07004967 && (mCarDockEnablesAccelerometer || mCarDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07004968 // Ignore sensor when in car dock unless explicitly enabled.
4969 // This case can override the behavior of NOSENSOR, and can also
4970 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07004971 preferredRotation = mCarDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07004972 ? sensorRotation : mCarDockRotation;
Jeff Brown1a693182011-11-08 14:44:16 -08004973 } else if ((mDockMode == Intent.EXTRA_DOCK_STATE_DESK
4974 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
4975 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK)
Jeff Brownc0347aa2011-09-23 17:26:09 -07004976 && (mDeskDockEnablesAccelerometer || mDeskDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07004977 // Ignore sensor when in desk dock unless explicitly enabled.
4978 // This case can override the behavior of NOSENSOR, and can also
4979 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07004980 preferredRotation = mDeskDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07004981 ? sensorRotation : mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -07004982 } else if (mHdmiPlugged && mDemoHdmiRotationLock) {
4983 // Ignore sensor when plugged into HDMI when demo HDMI rotation lock enabled.
Jeff Browneb3e4b92011-12-06 19:54:24 -08004984 // Note that the dock orientation overrides the HDMI orientation.
Jeff Brownc82c89ed2013-04-17 17:18:15 -07004985 preferredRotation = mDemoHdmiRotation;
4986 } else if (mHdmiPlugged && mDockMode == Intent.EXTRA_DOCK_STATE_UNDOCKED
4987 && mUndockedHdmiRotation >= 0) {
4988 // Ignore sensor when plugged into HDMI and an undocked orientation has
4989 // been specified in the configuration (only for legacy devices without
4990 // full multi-display support).
4991 // Note that the dock orientation overrides the HDMI orientation.
4992 preferredRotation = mUndockedHdmiRotation;
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07004993 } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED) {
4994 // Application just wants to remain locked in the last rotation.
4995 preferredRotation = lastRotation;
Jeff Brownbcdfc622014-03-06 19:13:04 -08004996 } else if (!mSupportAutoRotation) {
4997 // If we don't support auto-rotation then bail out here and ignore
4998 // the sensor and any rotation lock settings.
4999 preferredRotation = -1;
Jeff Brown207673cd2012-06-05 17:47:11 -07005000 } else if ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE
Jeff Brown01a98dd2011-09-20 15:08:29 -07005001 && (orientation == ActivityInfo.SCREEN_ORIENTATION_USER
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005002 || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
5003 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
5004 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
5005 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER))
Jeff Brown01a98dd2011-09-20 15:08:29 -07005006 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
5007 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
5008 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
5009 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) {
5010 // Otherwise, use sensor only if requested by the application or enabled
5011 // by default for USER or UNSPECIFIED modes. Does not apply to NOSENSOR.
Jeff Brownd3187e32011-09-21 19:26:44 -07005012 if (mAllowAllRotations < 0) {
5013 // Can't read this during init() because the context doesn't
5014 // have display metrics at that time so we cannot determine
5015 // tablet vs. phone then.
5016 mAllowAllRotations = mContext.getResources().getBoolean(
5017 com.android.internal.R.bool.config_allowAllRotations) ? 1 : 0;
5018 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005019 if (sensorRotation != Surface.ROTATION_180
Jeff Brownd3187e32011-09-21 19:26:44 -07005020 || mAllowAllRotations == 1
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005021 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
5022 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005023 preferredRotation = sensorRotation;
5024 } else {
5025 preferredRotation = lastRotation;
5026 }
Jeff Brown207673cd2012-06-05 17:47:11 -07005027 } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED
5028 && orientation != ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) {
5029 // Apply rotation lock. Does not apply to NOSENSOR.
5030 // The idea is that the user rotation expresses a weak preference for the direction
5031 // of gravity and as NOSENSOR is never affected by gravity, then neither should
5032 // NOSENSOR be affected by rotation lock (although it will be affected by docks).
Jeff Brown4dfce202011-10-05 12:00:10 -07005033 preferredRotation = mUserRotation;
Jeff Browndec6cf42011-11-15 14:08:20 -08005034 } else {
5035 // No overriding preference.
5036 // We will do exactly what the application asked us to do.
5037 preferredRotation = -1;
Jeff Brown01a98dd2011-09-20 15:08:29 -07005038 }
5039
Dianne Hackborne5439f22010-10-02 16:53:50 -07005040 switch (orientation) {
5041 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08005042 // Return portrait unless overridden.
5043 if (isAnyPortrait(preferredRotation)) {
5044 return preferredRotation;
5045 }
Dianne Hackborne5439f22010-10-02 16:53:50 -07005046 return mPortraitRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005047
Jeff Brown01a98dd2011-09-20 15:08:29 -07005048 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08005049 // Return landscape unless overridden.
5050 if (isLandscapeOrSeascape(preferredRotation)) {
5051 return preferredRotation;
5052 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005053 return mLandscapeRotation;
5054
5055 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08005056 // Return reverse portrait unless overridden.
5057 if (isAnyPortrait(preferredRotation)) {
5058 return preferredRotation;
5059 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005060 return mUpsideDownRotation;
5061
5062 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08005063 // Return seascape unless overridden.
5064 if (isLandscapeOrSeascape(preferredRotation)) {
5065 return preferredRotation;
5066 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005067 return mSeascapeRotation;
5068
5069 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005070 case ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE:
Jeff Brown01a98dd2011-09-20 15:08:29 -07005071 // Return either landscape rotation.
5072 if (isLandscapeOrSeascape(preferredRotation)) {
5073 return preferredRotation;
5074 }
5075 if (isLandscapeOrSeascape(lastRotation)) {
Jeff Brown4519f072011-01-23 13:16:01 -08005076 return lastRotation;
5077 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005078 return mLandscapeRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005079
Jeff Brown01a98dd2011-09-20 15:08:29 -07005080 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07005081 case ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT:
Jeff Brown01a98dd2011-09-20 15:08:29 -07005082 // Return either portrait rotation.
5083 if (isAnyPortrait(preferredRotation)) {
5084 return preferredRotation;
5085 }
5086 if (isAnyPortrait(lastRotation)) {
5087 return lastRotation;
5088 }
5089 return mPortraitRotation;
5090
5091 default:
Jeff Brown4dfce202011-10-05 12:00:10 -07005092 // For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR,
5093 // just return the preferred orientation we already calculated.
Jeff Brown01a98dd2011-09-20 15:08:29 -07005094 if (preferredRotation >= 0) {
5095 return preferredRotation;
5096 }
Dianne Hackborndacea8c2011-04-21 17:26:39 -07005097 return Surface.ROTATION_0;
Daniel Sandlere7e5ac22011-02-22 16:10:21 -05005098 }
5099 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07005100 }
5101
Jeff Brown01a98dd2011-09-20 15:08:29 -07005102 @Override
5103 public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation) {
5104 switch (orientation) {
5105 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
5106 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
5107 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
5108 return isAnyPortrait(rotation);
5109
5110 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
5111 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
5112 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
5113 return isLandscapeOrSeascape(rotation);
5114
5115 default:
5116 return true;
5117 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07005118 }
5119
Jeff Brownc0347aa2011-09-23 17:26:09 -07005120 @Override
5121 public void setRotationLw(int rotation) {
5122 mOrientationListener.setCurrentRotation(rotation);
5123 }
5124
Jeff Brown01a98dd2011-09-20 15:08:29 -07005125 private boolean isLandscapeOrSeascape(int rotation) {
5126 return rotation == mLandscapeRotation || rotation == mSeascapeRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005127 }
5128
Jeff Brown01a98dd2011-09-20 15:08:29 -07005129 private boolean isAnyPortrait(int rotation) {
5130 return rotation == mPortraitRotation || rotation == mUpsideDownRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07005131 }
5132
Jose Lima9546b202014-07-02 17:21:51 -07005133 @Override
Svetoslav Ganov80943d82013-01-02 10:25:37 -08005134 public int getUserRotationMode() {
5135 return Settings.System.getIntForUser(mContext.getContentResolver(),
Brett Chabot7e55c402013-05-16 19:38:08 -07005136 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
5137 WindowManagerPolicy.USER_ROTATION_FREE :
5138 WindowManagerPolicy.USER_ROTATION_LOCKED;
Svetoslav Ganov80943d82013-01-02 10:25:37 -08005139 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005140
5141 // User rotation: to be used when all else fails in assigning an orientation to the device
Jose Lima9546b202014-07-02 17:21:51 -07005142 @Override
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005143 public void setUserRotationMode(int mode, int rot) {
5144 ContentResolver res = mContext.getContentResolver();
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005145
5146 // mUserRotationMode and mUserRotation will be assigned by the content observer
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005147 if (mode == WindowManagerPolicy.USER_ROTATION_LOCKED) {
Christopher Tate5e08af02012-09-21 17:17:22 -07005148 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005149 Settings.System.USER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005150 rot,
5151 UserHandle.USER_CURRENT);
5152 Settings.System.putIntForUser(res,
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005153 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005154 0,
5155 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005156 } else {
Christopher Tate5e08af02012-09-21 17:17:22 -07005157 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005158 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07005159 1,
5160 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04005161 }
5162 }
5163
Jose Lima9546b202014-07-02 17:21:51 -07005164 @Override
Jeff Brownac143512012-04-05 18:57:33 -07005165 public void setSafeMode(boolean safeMode) {
5166 mSafeMode = safeMode;
5167 performHapticFeedbackLw(null, safeMode
5168 ? HapticFeedbackConstants.SAFE_MODE_ENABLED
5169 : HapticFeedbackConstants.SAFE_MODE_DISABLED, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005170 }
Craig Mautnereda67292013-04-28 13:50:14 -07005171
Dianne Hackborn181ceb52009-08-27 22:16:40 -07005172 static long[] getLongIntArray(Resources r, int resid) {
5173 int[] ar = r.getIntArray(resid);
5174 if (ar == null) {
5175 return null;
5176 }
5177 long[] out = new long[ar.length];
5178 for (int i=0; i<ar.length; i++) {
5179 out[i] = ar[i];
5180 }
5181 return out;
5182 }
Craig Mautnereda67292013-04-28 13:50:14 -07005183
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005184 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07005185 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005186 public void systemReady() {
Mike Lockwooded8902d2013-11-15 11:01:47 -08005187 mKeyguardDelegate = new KeyguardServiceDelegate(mContext, null);
5188 mKeyguardDelegate.onSystemReady();
5189
Michael Wright3818c922014-09-02 13:59:07 -07005190 readCameraLensCoverState();
Jeff Brown4f5fa282014-06-12 19:19:15 -07005191 updateUiMode();
Dianne Hackbornb1a79802009-09-29 15:18:31 -07005192 synchronized (mLock) {
5193 updateOrientationListenerLp();
Dianne Hackbornc777e072010-02-12 13:07:59 -08005194 mSystemReady = true;
5195 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07005196 @Override
Dianne Hackbornc777e072010-02-12 13:07:59 -08005197 public void run() {
5198 updateSettings();
5199 }
5200 });
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005201 }
5202 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07005203
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005204 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005205 @Override
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005206 public void systemBooted() {
Jim Millere5f910a2013-10-16 18:15:46 -07005207 if (mKeyguardDelegate != null) {
5208 mKeyguardDelegate.onBootCompleted();
5209 }
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005210 synchronized (mLock) {
5211 mSystemBooted = true;
5212 }
Craig Mautner8a0da012014-05-31 15:13:37 -07005213 wakingUp(null);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005214 }
5215
Dianne Hackborn661cd522011-08-22 00:26:20 -07005216 ProgressDialog mBootMsgDialog = null;
5217
5218 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005219 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07005220 public void showBootMessage(final CharSequence msg, final boolean always) {
5221 mHandler.post(new Runnable() {
5222 @Override public void run() {
5223 if (mBootMsgDialog == null) {
Craig Stout4c0cb8a2014-04-04 13:03:10 -07005224 int theme;
5225 if (mContext.getPackageManager().hasSystemFeature(
5226 PackageManager.FEATURE_WATCH)) {
5227 theme = com.android.internal.R.style.Theme_Micro_Dialog_Alert;
5228 } else if (mContext.getPackageManager().hasSystemFeature(
5229 PackageManager.FEATURE_TELEVISION)) {
5230 theme = com.android.internal.R.style.Theme_Leanback_Dialog_Alert;
5231 } else {
5232 theme = 0;
5233 }
Vinod Krishnanfa8fc412014-04-18 14:35:53 -07005234
5235 mBootMsgDialog = new ProgressDialog(mContext, theme) {
Dianne Hackborn295e3c22011-08-25 13:19:08 -07005236 // This dialog will consume all events coming in to
5237 // it, to avoid it trying to do things too early in boot.
5238 @Override public boolean dispatchKeyEvent(KeyEvent event) {
5239 return true;
5240 }
5241 @Override public boolean dispatchKeyShortcutEvent(KeyEvent event) {
5242 return true;
5243 }
5244 @Override public boolean dispatchTouchEvent(MotionEvent ev) {
5245 return true;
5246 }
5247 @Override public boolean dispatchTrackballEvent(MotionEvent ev) {
5248 return true;
5249 }
5250 @Override public boolean dispatchGenericMotionEvent(MotionEvent ev) {
5251 return true;
5252 }
5253 @Override public boolean dispatchPopulateAccessibilityEvent(
5254 AccessibilityEvent event) {
5255 return true;
5256 }
5257 };
Dianne Hackborn661cd522011-08-22 00:26:20 -07005258 mBootMsgDialog.setTitle(R.string.android_upgrading_title);
5259 mBootMsgDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
5260 mBootMsgDialog.setIndeterminate(true);
5261 mBootMsgDialog.getWindow().setType(
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07005262 WindowManager.LayoutParams.TYPE_BOOT_PROGRESS);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005263 mBootMsgDialog.getWindow().addFlags(
5264 WindowManager.LayoutParams.FLAG_DIM_BEHIND
5265 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
5266 mBootMsgDialog.getWindow().setDimAmount(1);
Dianne Hackbornd9efb952011-12-07 14:56:51 -08005267 WindowManager.LayoutParams lp = mBootMsgDialog.getWindow().getAttributes();
5268 lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
5269 mBootMsgDialog.getWindow().setAttributes(lp);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005270 mBootMsgDialog.setCancelable(false);
5271 mBootMsgDialog.show();
5272 }
5273 mBootMsgDialog.setMessage(msg);
5274 }
5275 });
5276 }
5277
5278 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005279 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07005280 public void hideBootMessages() {
Craig Mautnera631d492014-08-05 15:16:01 -07005281 mHandler.sendEmptyMessage(MSG_HIDE_BOOT_MESSAGE);
Dianne Hackborn661cd522011-08-22 00:26:20 -07005282 }
5283
Mike Lockwood28569302010-01-28 11:54:40 -05005284 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005285 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05005286 public void userActivity() {
Dianne Hackborndf89e652011-10-06 22:35:11 -07005287 // ***************************************
5288 // NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
5289 // ***************************************
5290 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
5291 // WITH ITS LOCKS HELD.
5292 //
5293 // This code must be VERY careful about the locks
5294 // it acquires.
5295 // In fact, the current code acquires way too many,
5296 // and probably has lurking deadlocks.
5297
Mike Lockwood28569302010-01-28 11:54:40 -05005298 synchronized (mScreenLockTimeout) {
5299 if (mLockScreenTimerActive) {
5300 // reset the timer
5301 mHandler.removeCallbacks(mScreenLockTimeout);
5302 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
5303 }
5304 }
Daniel Sandler0601eb72011-04-13 01:01:32 -04005305 }
5306
Adam Cohenf7522022012-10-03 20:03:18 -07005307 class ScreenLockTimeout implements Runnable {
5308 Bundle options;
5309
5310 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05005311 public void run() {
5312 synchronized (this) {
5313 if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard");
Jim Miller5ecd8112013-01-09 18:50:26 -08005314 if (mKeyguardDelegate != null) {
5315 mKeyguardDelegate.doKeyguardTimeout(options);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005316 }
Mike Lockwood28569302010-01-28 11:54:40 -05005317 mLockScreenTimerActive = false;
Adam Cohenf7522022012-10-03 20:03:18 -07005318 options = null;
Mike Lockwood28569302010-01-28 11:54:40 -05005319 }
5320 }
Mike Lockwood28569302010-01-28 11:54:40 -05005321
Adam Cohenf7522022012-10-03 20:03:18 -07005322 public void setLockOptions(Bundle options) {
5323 this.options = options;
5324 }
5325 }
5326
5327 ScreenLockTimeout mScreenLockTimeout = new ScreenLockTimeout();
5328
Jose Lima9546b202014-07-02 17:21:51 -07005329 @Override
Adam Cohenf7522022012-10-03 20:03:18 -07005330 public void lockNow(Bundle options) {
Jim Miller93c518e2012-01-17 15:55:31 -08005331 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null);
5332 mHandler.removeCallbacks(mScreenLockTimeout);
Adam Cohenf7522022012-10-03 20:03:18 -07005333 if (options != null) {
5334 // In case multiple calls are made to lockNow, we don't wipe out the options
5335 // until the runnable actually executes.
5336 mScreenLockTimeout.setLockOptions(options);
5337 }
Jim Miller93c518e2012-01-17 15:55:31 -08005338 mHandler.post(mScreenLockTimeout);
5339 }
5340
Mike Lockwood28569302010-01-28 11:54:40 -05005341 private void updateLockScreenTimeout() {
5342 synchronized (mScreenLockTimeout) {
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005343 boolean enable = (mAllowLockscreenWhenOn && mScreenOnEarly &&
Jim Miller5ecd8112013-01-09 18:50:26 -08005344 mKeyguardDelegate != null && mKeyguardDelegate.isSecure());
Mike Lockwood28569302010-01-28 11:54:40 -05005345 if (mLockScreenTimerActive != enable) {
5346 if (enable) {
5347 if (localLOGV) Log.v(TAG, "setting lockscreen timer");
5348 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
5349 } else {
5350 if (localLOGV) Log.v(TAG, "clearing lockscreen timer");
5351 mHandler.removeCallbacks(mScreenLockTimeout);
5352 }
5353 mLockScreenTimerActive = enable;
5354 }
5355 }
5356 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005357
5358 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07005359 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005360 public void enableScreenAfterBoot() {
5361 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07005362 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07005363 updateRotation(true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005364 }
Dianne Hackbornf54c8f92009-09-19 14:03:57 -07005365
Jeff Brownc458ce92012-04-30 14:58:40 -07005366 private void applyLidSwitchState() {
Jeff Brownc458ce92012-04-30 14:58:40 -07005367 if (mLidState == LID_CLOSED && mLidControlsSleep) {
Jeff Brown6d8fd272014-05-20 21:24:38 -07005368 mPowerManager.goToSleep(SystemClock.uptimeMillis(),
Jeff Brownc12035c2014-08-13 18:52:25 -07005369 PowerManager.GO_TO_SLEEP_REASON_LID_SWITCH,
Jeff Brown6d8fd272014-05-20 21:24:38 -07005370 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
Jeff Brownc458ce92012-04-30 14:58:40 -07005371 }
Jeff Browna20dda42014-05-27 20:57:24 -07005372
5373 synchronized (mLock) {
5374 updateWakeGestureListenerLp();
5375 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005376 }
5377
Jeff Brown4f5fa282014-06-12 19:19:15 -07005378 void updateUiMode() {
5379 if (mUiModeManager == null) {
5380 mUiModeManager = IUiModeManager.Stub.asInterface(
5381 ServiceManager.getService(Context.UI_MODE_SERVICE));
5382 }
5383 try {
5384 mUiMode = mUiModeManager.getCurrentModeType();
5385 } catch (RemoteException e) {
5386 }
5387 }
5388
Jeff Brown01a98dd2011-09-20 15:08:29 -07005389 void updateRotation(boolean alwaysSendConfiguration) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005390 try {
5391 //set orientation on WindowManager
Dianne Hackbornf87d1962012-04-04 12:48:24 -07005392 mWindowManager.updateRotation(alwaysSendConfiguration, false);
5393 } catch (RemoteException e) {
5394 // Ignore
5395 }
5396 }
5397
5398 void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) {
5399 try {
5400 //set orientation on WindowManager
5401 mWindowManager.updateRotation(alwaysSendConfiguration, forceRelayout);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005402 } catch (RemoteException e) {
5403 // Ignore
5404 }
5405 }
5406
Daniel Sandler6396c722013-04-16 20:19:09 -04005407 /**
5408 * Return an Intent to launch the currently active dock app as home. Returns
5409 * null if the standard home should be launched, which is the case if any of the following is
5410 * true:
5411 * <ul>
5412 * <li>The device is not in either car mode or desk mode
5413 * <li>The device is in car mode but ENABLE_CAR_DOCK_HOME_CAPTURE is false
5414 * <li>The device is in desk mode but ENABLE_DESK_DOCK_HOME_CAPTURE is false
5415 * <li>The device is in car mode but there's no CAR_DOCK app with METADATA_DOCK_HOME
5416 * <li>The device is in desk mode but there's no DESK_DOCK app with METADATA_DOCK_HOME
5417 * </ul>
Craig Mautnereda67292013-04-28 13:50:14 -07005418 * @return A dock intent.
Daniel Sandler6396c722013-04-16 20:19:09 -04005419 */
5420 Intent createHomeDockIntent() {
5421 Intent intent = null;
5422
5423 // What home does is based on the mode, not the dock state. That
5424 // is, when in car mode you should be taken to car home regardless
5425 // of whether we are actually in a car dock.
5426 if (mUiMode == Configuration.UI_MODE_TYPE_CAR) {
5427 if (ENABLE_CAR_DOCK_HOME_CAPTURE) {
5428 intent = mCarDockIntent;
5429 }
5430 } else if (mUiMode == Configuration.UI_MODE_TYPE_DESK) {
5431 if (ENABLE_DESK_DOCK_HOME_CAPTURE) {
5432 intent = mDeskDockIntent;
5433 }
Jeff Brown4f5fa282014-06-12 19:19:15 -07005434 } else if (mUiMode == Configuration.UI_MODE_TYPE_WATCH
5435 && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
5436 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK
5437 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK)) {
5438 // Always launch dock home from home when watch is docked, if it exists.
5439 intent = mDeskDockIntent;
Daniel Sandler6396c722013-04-16 20:19:09 -04005440 }
5441
5442 if (intent == null) {
5443 return null;
5444 }
5445
5446 ActivityInfo ai = null;
5447 ResolveInfo info = mContext.getPackageManager().resolveActivityAsUser(
5448 intent,
John Spurlockf56bef12013-07-09 09:51:46 -04005449 PackageManager.MATCH_DEFAULT_ONLY | PackageManager.GET_META_DATA,
Craig Mautnerd625ab22013-09-06 13:40:31 -07005450 mCurrentUserId);
Daniel Sandler6396c722013-04-16 20:19:09 -04005451 if (info != null) {
5452 ai = info.activityInfo;
5453 }
5454 if (ai != null
5455 && ai.metaData != null
5456 && ai.metaData.getBoolean(Intent.METADATA_DOCK_HOME)) {
5457 intent = new Intent(intent);
5458 intent.setClassName(ai.packageName, ai.name);
5459 return intent;
5460 }
5461
5462 return null;
5463 }
5464
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005465 void startDockOrHome() {
John Spurlockc8b46ca2013-04-08 12:59:26 -04005466 awakenDreams();
Daniel Sandler6396c722013-04-16 20:19:09 -04005467
5468 Intent dock = createHomeDockIntent();
5469 if (dock != null) {
5470 try {
5471 mContext.startActivityAsUser(dock, UserHandle.CURRENT);
5472 return;
5473 } catch (ActivityNotFoundException e) {
5474 }
5475 }
5476
Dianne Hackbornd8883992012-09-07 15:58:52 -07005477 mContext.startActivityAsUser(mHomeIntent, UserHandle.CURRENT);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005478 }
Craig Mautnereda67292013-04-28 13:50:14 -07005479
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005480 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005481 * goes to the home screen
5482 * @return whether it did anything
5483 */
5484 boolean goHome() {
5485 if (false) {
5486 // This code always brings home to the front.
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07005487 try {
5488 ActivityManagerNative.getDefault().stopAppSwitches();
5489 } catch (RemoteException e) {
5490 }
Dianne Hackborn94a679d2009-07-28 17:51:07 -07005491 sendCloseSystemWindows();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005492 startDockOrHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005493 } else {
5494 // This code brings home to the front or, if it is already
5495 // at the front, puts the device to sleep.
5496 try {
Wink Savilled2e6a332010-02-12 12:12:06 -08005497 if (SystemProperties.getInt("persist.sys.uts-test-mode", 0) == 1) {
5498 /// Roll back EndcallBehavior as the cupcake design to pass P1 lab entry.
5499 Log.d(TAG, "UTS-TEST-MODE");
5500 } else {
5501 ActivityManagerNative.getDefault().stopAppSwitches();
5502 sendCloseSystemWindows();
Daniel Sandler6396c722013-04-16 20:19:09 -04005503 Intent dock = createHomeDockIntent();
5504 if (dock != null) {
5505 int result = ActivityManagerNative.getDefault()
5506 .startActivityAsUser(null, null, dock,
5507 dock.resolveTypeIfNeeded(mContext.getContentResolver()),
5508 null, null, 0,
5509 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07005510 null, null, UserHandle.USER_CURRENT);
Daniel Sandler6396c722013-04-16 20:19:09 -04005511 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
5512 return false;
5513 }
5514 }
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005515 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005516 int result = ActivityManagerNative.getDefault()
Dianne Hackbornf265ea92013-01-31 15:00:51 -08005517 .startActivityAsUser(null, null, mHomeIntent,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005518 mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()),
Dianne Hackborna4972e92012-03-14 10:38:05 -07005519 null, null, 0,
5520 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07005521 null, null, UserHandle.USER_CURRENT);
Dianne Hackborna4972e92012-03-14 10:38:05 -07005522 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005523 return false;
5524 }
5525 } catch (RemoteException ex) {
5526 // bummer, the activity manager, which is in this process, is dead
5527 }
5528 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005529 return true;
5530 }
Craig Mautnereda67292013-04-28 13:50:14 -07005531
5532 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07005533 public void setCurrentOrientationLw(int newOrientation) {
5534 synchronized (mLock) {
5535 if (newOrientation != mCurrentAppOrientation) {
5536 mCurrentAppOrientation = newOrientation;
5537 updateOrientationListenerLp();
5538 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005539 }
5540 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08005541
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07005542 private void performAuditoryFeedbackForAccessibilityIfNeed() {
5543 if (!isGlobalAccessibilityGestureEnabled()) {
5544 return;
5545 }
5546 AudioManager audioManager = (AudioManager) mContext.getSystemService(
5547 Context.AUDIO_SERVICE);
5548 if (audioManager.isSilentMode()) {
5549 return;
5550 }
5551 Ringtone ringTone = RingtoneManager.getRingtone(mContext,
5552 Settings.System.DEFAULT_NOTIFICATION_URI);
5553 ringTone.setStreamType(AudioManager.STREAM_MUSIC);
5554 ringTone.play();
5555 }
Craig Mautnereda67292013-04-28 13:50:14 -07005556
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07005557 private boolean isGlobalAccessibilityGestureEnabled() {
5558 return Settings.Global.getInt(mContext.getContentResolver(),
5559 Settings.Global.ENABLE_ACCESSIBILITY_GLOBAL_GESTURE_ENABLED, 0) == 1;
5560 }
5561
Craig Mautnereda67292013-04-28 13:50:14 -07005562 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07005563 public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) {
Svetoslav Ganov96179212012-10-10 14:17:45 -07005564 if (!mVibrator.hasVibrator()) {
5565 return false;
5566 }
Christopher Tate5e08af02012-09-21 17:17:22 -07005567 final boolean hapticsDisabled = Settings.System.getIntForUser(mContext.getContentResolver(),
5568 Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) == 0;
Jeff Brown82379ba2014-07-25 19:03:28 -07005569 if (hapticsDisabled && !always) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005570 return false;
5571 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08005572 long[] pattern = null;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005573 switch (effectId) {
5574 case HapticFeedbackConstants.LONG_PRESS:
Amith Yamasanic33cb712010-02-10 15:21:49 -08005575 pattern = mLongPressVibePattern;
5576 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07005577 case HapticFeedbackConstants.VIRTUAL_KEY:
Amith Yamasanic33cb712010-02-10 15:21:49 -08005578 pattern = mVirtualKeyVibePattern;
5579 break;
5580 case HapticFeedbackConstants.KEYBOARD_TAP:
5581 pattern = mKeyboardTapVibePattern;
5582 break;
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07005583 case HapticFeedbackConstants.CLOCK_TICK:
5584 pattern = mClockTickVibePattern;
5585 break;
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07005586 case HapticFeedbackConstants.CALENDAR_DATE:
5587 pattern = mCalendarDateVibePattern;
5588 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07005589 case HapticFeedbackConstants.SAFE_MODE_DISABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08005590 pattern = mSafeModeDisabledVibePattern;
5591 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07005592 case HapticFeedbackConstants.SAFE_MODE_ENABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08005593 pattern = mSafeModeEnabledVibePattern;
5594 break;
Amith Yamasanic33cb712010-02-10 15:21:49 -08005595 default:
5596 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005597 }
Dianne Hackbornf265ea92013-01-31 15:00:51 -08005598 int owningUid;
5599 String owningPackage;
5600 if (win != null) {
5601 owningUid = win.getOwningUid();
5602 owningPackage = win.getOwningPackage();
5603 } else {
5604 owningUid = android.os.Process.myUid();
Dianne Hackborn95d78532013-09-11 09:51:14 -07005605 owningPackage = mContext.getOpPackageName();
Dianne Hackbornf265ea92013-01-31 15:00:51 -08005606 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08005607 if (pattern.length == 1) {
5608 // One-shot vibration
John Spurlock7b414672014-07-18 13:02:39 -04005609 mVibrator.vibrate(owningUid, owningPackage, pattern[0], VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08005610 } else {
5611 // Pattern vibration
John Spurlock7b414672014-07-18 13:02:39 -04005612 mVibrator.vibrate(owningUid, owningPackage, pattern, -1, VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08005613 }
5614 return true;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005615 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005616
5617 @Override
5618 public void keepScreenOnStartedLw() {
Daniel Sandler0601eb72011-04-13 01:01:32 -04005619 }
5620
Jeff Brownc38c9be2012-10-04 13:16:19 -07005621 @Override
5622 public void keepScreenOnStoppedLw() {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01005623 if (mKeyguardDelegate != null && !mKeyguardDelegate.isShowingAndNotOccluded()) {
Jim Miller25190572013-02-28 17:36:24 -08005624 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005625 }
5626 }
Mike Lockwoodfcb39242009-10-21 23:01:07 -04005627
Dianne Hackborndf89e652011-10-06 22:35:11 -07005628 private int updateSystemUiVisibilityLw() {
Joe Onorato664644d2011-01-23 17:53:23 -08005629 // If there is no window focused, there will be nobody to handle the events
5630 // anyway, so just hang on in whatever state we're in until things settle down.
John Spurlock79da8332013-09-20 12:04:47 -04005631 WindowState win = mFocusedWindow != null ? mFocusedWindow : mTopFullscreenOpaqueWindowState;
5632 if (win == null) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07005633 return 0;
5634 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01005635 if ((win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 && mHideLockScreen == true) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07005636 // We are updating at a point where the keyguard has gotten
5637 // focus, but we were last in a state where the top window is
5638 // hiding it. This is probably because the keyguard as been
5639 // shown while the top window was displayed, so we want to ignore
5640 // it here because this is just a very transient change and it
5641 // will quickly lose focus once it correctly gets hidden.
5642 return 0;
5643 }
John Spurlock32beb2c2013-03-11 10:16:47 -04005644
John Spurlock1db8b682014-02-18 11:18:59 -05005645 int tmpVisibility = PolicyControl.getSystemUiVisibility(win, null)
Dianne Hackborne26ab702011-10-16 13:21:33 -07005646 & ~mResettingSystemUiFlags
5647 & ~mForceClearedSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04005648 if (mForcingShowNavBar && win.getSurfaceLayer() < mForcingShowNavBarLayer) {
John Spurlockc6d1c602014-01-17 15:22:06 -05005649 tmpVisibility &= ~PolicyControl.adjustClearableFlags(win, View.SYSTEM_UI_CLEARABLE_FLAGS);
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08005650 }
John Spurlock79da8332013-09-20 12:04:47 -04005651 final int visibility = updateSystemBarsLw(win, mLastSystemUiFlags, tmpVisibility);
John Spurlockad3e6cb2013-04-30 08:47:43 -04005652 final int diff = visibility ^ mLastSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04005653 final boolean needsMenu = win.getNeedsMenuLw(mTopFullscreenOpaqueWindowState);
Dianne Hackborne0f085d2011-11-30 18:41:15 -08005654 if (diff == 0 && mLastFocusNeedsMenu == needsMenu
John Spurlock79da8332013-09-20 12:04:47 -04005655 && mFocusedApp == win.getAppToken()) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07005656 return 0;
5657 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07005658 mLastSystemUiFlags = visibility;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08005659 mLastFocusNeedsMenu = needsMenu;
John Spurlock79da8332013-09-20 12:04:47 -04005660 mFocusedApp = win.getAppToken();
Dianne Hackborndf89e652011-10-06 22:35:11 -07005661 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07005662 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07005663 public void run() {
Dianne Hackborn42e620c2012-06-24 13:20:51 -07005664 try {
5665 IStatusBarService statusbar = getStatusBarService();
5666 if (statusbar != null) {
5667 statusbar.setSystemUiVisibility(visibility, 0xffffffff);
5668 statusbar.topAppWindowChanged(needsMenu);
Joe Onorato664644d2011-01-23 17:53:23 -08005669 }
Dianne Hackborn42e620c2012-06-24 13:20:51 -07005670 } catch (RemoteException e) {
5671 // re-acquire status bar service next time it is needed.
5672 mStatusBarService = null;
Joe Onorato664644d2011-01-23 17:53:23 -08005673 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07005674 }
5675 });
5676 return diff;
Joe Onorato664644d2011-01-23 17:53:23 -08005677 }
5678
John Spurlock79da8332013-09-20 12:04:47 -04005679 private int updateSystemBarsLw(WindowState win, int oldVis, int vis) {
John Spurlockbd957402013-10-03 11:38:39 -04005680 // apply translucent bar vis flags
Jorim Jaggi380ecb82014-03-14 17:25:20 +01005681 WindowState transWin = isStatusBarKeyguard() && !mHideLockScreen
5682 ? mStatusBar
John Spurlockbd957402013-10-03 11:38:39 -04005683 : mTopFullscreenOpaqueWindowState;
5684 vis = mStatusBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
5685 vis = mNavigationBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
5686
John Spurlock27735a42013-08-14 17:57:38 -04005687 // prevent status bar interaction from clearing certain flags
John Spurlock79da8332013-09-20 12:04:47 -04005688 boolean statusBarHasFocus = win.getAttrs().type == TYPE_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04005689 if (statusBarHasFocus && !isStatusBarKeyguard()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04005690 int flags = View.SYSTEM_UI_FLAG_FULLSCREEN
5691 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlockcfc359a2013-09-05 10:42:03 -04005692 | View.SYSTEM_UI_FLAG_IMMERSIVE
Jorim Jaggi5cf17872014-03-26 18:31:48 +01005693 | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
John Spurlock08ffcf52014-07-11 10:13:46 -04005694 if (mHideLockScreen) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01005695 flags |= View.STATUS_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSLUCENT;
5696 }
John Spurlockbd957402013-10-03 11:38:39 -04005697 vis = (vis & ~flags) | (oldVis & flags);
John Spurlockad3e6cb2013-04-30 08:47:43 -04005698 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04005699
Adrian Roos4fb3ee32014-08-22 19:29:09 +02005700 if (!areTranslucentBarsAllowed() && transWin != mStatusBar) {
Adrian Roosea562512014-05-05 13:33:03 +02005701 vis &= ~(View.NAVIGATION_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSLUCENT
5702 | View.SYSTEM_UI_TRANSPARENT);
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07005703 }
5704
John Spurlock27735a42013-08-14 17:57:38 -04005705 // update status bar
John Spurlockf1a36642013-10-12 17:50:42 -04005706 boolean immersiveSticky =
5707 (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
John Spurlock27735a42013-08-14 17:57:38 -04005708 boolean hideStatusBarWM =
John Spurlockbd957402013-10-03 11:38:39 -04005709 mTopFullscreenOpaqueWindowState != null &&
John Spurlockc6d1c602014-01-17 15:22:06 -05005710 (PolicyControl.getWindowFlags(mTopFullscreenOpaqueWindowState, null)
John Spurlock27735a42013-08-14 17:57:38 -04005711 & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0;
5712 boolean hideStatusBarSysui =
5713 (vis & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04005714 boolean hideNavBarSysui =
5715 (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0;
John Spurlockad3e6cb2013-04-30 08:47:43 -04005716
John Spurlock27735a42013-08-14 17:57:38 -04005717 boolean transientStatusBarAllowed =
5718 mStatusBar != null && (
5719 hideStatusBarWM
John Spurlockf1a36642013-10-12 17:50:42 -04005720 || (hideStatusBarSysui && immersiveSticky)
John Spurlock27735a42013-08-14 17:57:38 -04005721 || statusBarHasFocus);
5722
John Spurlockf1a36642013-10-12 17:50:42 -04005723 boolean transientNavBarAllowed =
5724 mNavigationBar != null &&
5725 hideNavBarSysui && immersiveSticky;
5726
John Spurlockf25706f2013-11-07 18:02:43 -05005727 boolean denyTransientStatus = mStatusBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04005728 && !transientStatusBarAllowed && hideStatusBarSysui;
John Spurlockf25706f2013-11-07 18:02:43 -05005729 boolean denyTransientNav = mNavigationBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04005730 && !transientNavBarAllowed;
5731 if (denyTransientStatus || denyTransientNav) {
John Spurlock27735a42013-08-14 17:57:38 -04005732 // clear the clearable flags instead
John Spurlockf1a36642013-10-12 17:50:42 -04005733 clearClearableFlagsLw();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005734 }
John Spurlock27735a42013-08-14 17:57:38 -04005735
5736 vis = mStatusBarController.updateVisibilityLw(transientStatusBarAllowed, oldVis, vis);
5737
5738 // update navigation bar
John Spurlockf1a36642013-10-12 17:50:42 -04005739 boolean oldImmersiveMode = isImmersiveMode(oldVis);
5740 boolean newImmersiveMode = isImmersiveMode(vis);
5741 if (win != null && oldImmersiveMode != newImmersiveMode) {
John Spurlock79da8332013-09-20 12:04:47 -04005742 final String pkg = win.getOwningPackage();
Maurice Lam99c6e072014-04-28 18:24:28 -07005743 mImmersiveModeConfirmation.immersiveModeChanged(pkg, newImmersiveMode,
5744 isUserSetupComplete());
John Spurlock34e13d92013-08-10 06:52:28 -04005745 }
John Spurlock27735a42013-08-14 17:57:38 -04005746
John Spurlockf1a36642013-10-12 17:50:42 -04005747 vis = mNavigationBarController.updateVisibilityLw(transientNavBarAllowed, oldVis, vis);
5748
John Spurlocke1f366f2013-08-05 12:22:40 -04005749 return vis;
John Spurlockad3e6cb2013-04-30 08:47:43 -04005750 }
5751
John Spurlockf1a36642013-10-12 17:50:42 -04005752 private void clearClearableFlagsLw() {
5753 int newVal = mResettingSystemUiFlags | View.SYSTEM_UI_CLEARABLE_FLAGS;
5754 if (newVal != mResettingSystemUiFlags) {
5755 mResettingSystemUiFlags = newVal;
5756 mWindowManagerFuncs.reevaluateStatusBarVisibility();
5757 }
5758 }
5759
5760 private boolean isImmersiveMode(int vis) {
5761 final int flags = View.SYSTEM_UI_FLAG_IMMERSIVE | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
John Spurlock34e13d92013-08-10 06:52:28 -04005762 return mNavigationBar != null
5763 && (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0
Daniel Sandler900ece52013-10-18 15:53:27 -04005764 && (vis & flags) != 0
5765 && canHideNavigationBar();
John Spurlock34e13d92013-08-10 06:52:28 -04005766 }
5767
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07005768 /**
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04005769 * @return whether the navigation or status bar can be made translucent
5770 *
5771 * This should return true unless touch exploration is not enabled or
5772 * R.boolean.config_enableTranslucentDecor is false.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07005773 */
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04005774 private boolean areTranslucentBarsAllowed() {
Svetoslav8e3feb12014-02-24 13:46:47 -08005775 return mTranslucentDecorEnabled
5776 && !mAccessibilityManager.isTouchExplorationEnabled();
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07005777 }
5778
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04005779 // Use this instead of checking config_showNavigationBar so that it can be consistently
5780 // overridden by qemu.hw.mainkeys in the emulator.
Craig Mautnereda67292013-04-28 13:50:14 -07005781 @Override
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04005782 public boolean hasNavigationBar() {
5783 return mHasNavigationBar;
5784 }
5785
satok1bc0a492012-04-25 22:47:12 +09005786 @Override
5787 public void setLastInputMethodWindowLw(WindowState ime, WindowState target) {
5788 mLastInputMethodWindow = ime;
5789 mLastInputMethodTargetWindow = target;
5790 }
5791
Craig Mautnerf1b67412012-09-19 13:18:29 -07005792 @Override
Satoshi Kataoka658c7b82013-10-10 17:03:51 +09005793 public int getInputMethodWindowVisibleHeightLw() {
5794 return mDockBottom - mCurBottom;
5795 }
5796
5797 @Override
Craig Mautnerf1b67412012-09-19 13:18:29 -07005798 public void setCurrentUserLw(int newUserId) {
Craig Mautnerd625ab22013-09-06 13:40:31 -07005799 mCurrentUserId = newUserId;
Jim Miller5ecd8112013-01-09 18:50:26 -08005800 if (mKeyguardDelegate != null) {
5801 mKeyguardDelegate.setCurrentUser(newUserId);
Craig Mautnerf1b67412012-09-19 13:18:29 -07005802 }
John Spurlock13451a22012-09-28 14:40:41 -04005803 if (mStatusBarService != null) {
5804 try {
5805 mStatusBarService.setCurrentUser(newUserId);
5806 } catch (RemoteException e) {
5807 // oh well
5808 }
5809 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07005810 setLastInputMethodWindowLw(null, null);
Craig Mautnerf1b67412012-09-19 13:18:29 -07005811 }
5812
5813 @Override
Svetoslav Ganov545252f2012-12-10 18:29:24 -08005814 public boolean canMagnifyWindow(int windowType) {
5815 switch (windowType) {
5816 case WindowManager.LayoutParams.TYPE_INPUT_METHOD:
5817 case WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG:
5818 case WindowManager.LayoutParams.TYPE_NAVIGATION_BAR:
5819 case WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY: {
5820 return false;
5821 }
5822 }
5823 return true;
5824 }
5825
5826 @Override
5827 public boolean isTopLevelWindow(int windowType) {
5828 if (windowType >= WindowManager.LayoutParams.FIRST_SUB_WINDOW
5829 && windowType <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
5830 return (windowType == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG);
5831 }
5832 return true;
5833 }
5834
Jim Miller4eeb4f62012-11-08 00:04:29 -08005835 @Override
Jeff Brownd7a04de2012-06-17 14:17:52 -07005836 public void dump(String prefix, PrintWriter pw, String[] args) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005837 pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005838 pw.print(" mSystemReady="); pw.print(mSystemReady);
5839 pw.print(" mSystemBooted="); pw.println(mSystemBooted);
Jeff Brown2e7760e2012-04-11 15:14:55 -07005840 pw.print(prefix); pw.print("mLidState="); pw.print(mLidState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005841 pw.print(" mLidOpenRotation="); pw.print(mLidOpenRotation);
Michael Wright3818c922014-09-02 13:59:07 -07005842 pw.print(" mCameraLensCoverState="); pw.print(mCameraLensCoverState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005843 pw.print(" mHdmiPlugged="); pw.println(mHdmiPlugged);
Dianne Hackborne26ab702011-10-16 13:21:33 -07005844 if (mLastSystemUiFlags != 0 || mResettingSystemUiFlags != 0
5845 || mForceClearedSystemUiFlags != 0) {
5846 pw.print(prefix); pw.print("mLastSystemUiFlags=0x");
5847 pw.print(Integer.toHexString(mLastSystemUiFlags));
5848 pw.print(" mResettingSystemUiFlags=0x");
5849 pw.print(Integer.toHexString(mResettingSystemUiFlags));
5850 pw.print(" mForceClearedSystemUiFlags=0x");
5851 pw.println(Integer.toHexString(mForceClearedSystemUiFlags));
Dianne Hackborndf89e652011-10-06 22:35:11 -07005852 }
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08005853 if (mLastFocusNeedsMenu) {
5854 pw.print(prefix); pw.print("mLastFocusNeedsMenu=");
5855 pw.println(mLastFocusNeedsMenu);
5856 }
Jeff Browna20dda42014-05-27 20:57:24 -07005857 pw.print(prefix); pw.print("mWakeGestureEnabledSetting=");
5858 pw.println(mWakeGestureEnabledSetting);
5859
Jeff Brownbcdfc622014-03-06 19:13:04 -08005860 pw.print(prefix); pw.print("mSupportAutoRotation="); pw.println(mSupportAutoRotation);
Daniel Sandler6396c722013-04-16 20:19:09 -04005861 pw.print(prefix); pw.print("mUiMode="); pw.print(mUiMode);
5862 pw.print(" mDockMode="); pw.print(mDockMode);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005863 pw.print(" mCarDockRotation="); pw.print(mCarDockRotation);
5864 pw.print(" mDeskDockRotation="); pw.println(mDeskDockRotation);
5865 pw.print(prefix); pw.print("mUserRotationMode="); pw.print(mUserRotationMode);
5866 pw.print(" mUserRotation="); pw.print(mUserRotation);
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005867 pw.print(" mAllowAllRotations="); pw.println(mAllowAllRotations);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07005868 pw.print(prefix); pw.print("mCurrentAppOrientation="); pw.println(mCurrentAppOrientation);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005869 pw.print(prefix); pw.print("mCarDockEnablesAccelerometer=");
5870 pw.print(mCarDockEnablesAccelerometer);
5871 pw.print(" mDeskDockEnablesAccelerometer=");
5872 pw.println(mDeskDockEnablesAccelerometer);
5873 pw.print(prefix); pw.print("mLidKeyboardAccessibility=");
5874 pw.print(mLidKeyboardAccessibility);
5875 pw.print(" mLidNavigationAccessibility="); pw.print(mLidNavigationAccessibility);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07005876 pw.print(" mLidControlsSleep="); pw.println(mLidControlsSleep);
Jeff Brown6d8fd272014-05-20 21:24:38 -07005877 pw.print(prefix);
5878 pw.print("mShortPressOnPowerBehavior="); pw.print(mShortPressOnPowerBehavior);
5879 pw.print(" mLongPressOnPowerBehavior="); pw.println(mLongPressOnPowerBehavior);
5880 pw.print(prefix); pw.print("mHasSoftInput="); pw.println(mHasSoftInput);
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07005881 pw.print(prefix); pw.print("mScreenOnEarly="); pw.print(mScreenOnEarly);
5882 pw.print(" mScreenOnFully="); pw.print(mScreenOnFully);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07005883 pw.print(" mOrientationSensorEnabled="); pw.println(mOrientationSensorEnabled);
Dianne Hackbornc652de82013-02-15 16:32:56 -08005884 pw.print(prefix); pw.print("mOverscanScreen=("); pw.print(mOverscanScreenLeft);
5885 pw.print(","); pw.print(mOverscanScreenTop);
5886 pw.print(") "); pw.print(mOverscanScreenWidth);
5887 pw.print("x"); pw.println(mOverscanScreenHeight);
5888 if (mOverscanLeft != 0 || mOverscanTop != 0
5889 || mOverscanRight != 0 || mOverscanBottom != 0) {
5890 pw.print(prefix); pw.print("mOverscan left="); pw.print(mOverscanLeft);
5891 pw.print(" top="); pw.print(mOverscanTop);
5892 pw.print(" right="); pw.print(mOverscanRight);
5893 pw.print(" bottom="); pw.println(mOverscanBottom);
5894 }
Dianne Hackborn313440842013-02-19 19:22:59 -08005895 pw.print(prefix); pw.print("mRestrictedOverscanScreen=(");
5896 pw.print(mRestrictedOverscanScreenLeft);
5897 pw.print(","); pw.print(mRestrictedOverscanScreenTop);
5898 pw.print(") "); pw.print(mRestrictedOverscanScreenWidth);
5899 pw.print("x"); pw.println(mRestrictedOverscanScreenHeight);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005900 pw.print(prefix); pw.print("mUnrestrictedScreen=("); pw.print(mUnrestrictedScreenLeft);
5901 pw.print(","); pw.print(mUnrestrictedScreenTop);
5902 pw.print(") "); pw.print(mUnrestrictedScreenWidth);
5903 pw.print("x"); pw.println(mUnrestrictedScreenHeight);
5904 pw.print(prefix); pw.print("mRestrictedScreen=("); pw.print(mRestrictedScreenLeft);
5905 pw.print(","); pw.print(mRestrictedScreenTop);
5906 pw.print(") "); pw.print(mRestrictedScreenWidth);
5907 pw.print("x"); pw.println(mRestrictedScreenHeight);
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07005908 pw.print(prefix); pw.print("mStableFullscreen=("); pw.print(mStableFullscreenLeft);
5909 pw.print(","); pw.print(mStableFullscreenTop);
5910 pw.print(")-("); pw.print(mStableFullscreenRight);
5911 pw.print(","); pw.print(mStableFullscreenBottom); pw.println(")");
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07005912 pw.print(prefix); pw.print("mStable=("); pw.print(mStableLeft);
5913 pw.print(","); pw.print(mStableTop);
5914 pw.print(")-("); pw.print(mStableRight);
5915 pw.print(","); pw.print(mStableBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07005916 pw.print(prefix); pw.print("mSystem=("); pw.print(mSystemLeft);
5917 pw.print(","); pw.print(mSystemTop);
5918 pw.print(")-("); pw.print(mSystemRight);
5919 pw.print(","); pw.print(mSystemBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005920 pw.print(prefix); pw.print("mCur=("); pw.print(mCurLeft);
5921 pw.print(","); pw.print(mCurTop);
5922 pw.print(")-("); pw.print(mCurRight);
5923 pw.print(","); pw.print(mCurBottom); pw.println(")");
5924 pw.print(prefix); pw.print("mContent=("); pw.print(mContentLeft);
5925 pw.print(","); pw.print(mContentTop);
5926 pw.print(")-("); pw.print(mContentRight);
5927 pw.print(","); pw.print(mContentBottom); pw.println(")");
Dianne Hackborne30e02f2014-05-27 18:24:45 -07005928 pw.print(prefix); pw.print("mVoiceContent=("); pw.print(mVoiceContentLeft);
5929 pw.print(","); pw.print(mVoiceContentTop);
5930 pw.print(")-("); pw.print(mVoiceContentRight);
5931 pw.print(","); pw.print(mVoiceContentBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005932 pw.print(prefix); pw.print("mDock=("); pw.print(mDockLeft);
5933 pw.print(","); pw.print(mDockTop);
5934 pw.print(")-("); pw.print(mDockRight);
5935 pw.print(","); pw.print(mDockBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07005936 pw.print(prefix); pw.print("mDockLayer="); pw.print(mDockLayer);
5937 pw.print(" mStatusBarLayer="); pw.println(mStatusBarLayer);
Dianne Hackborn7ad44382012-10-18 17:46:00 -07005938 pw.print(prefix); pw.print("mShowingLockscreen="); pw.print(mShowingLockscreen);
5939 pw.print(" mShowingDream="); pw.print(mShowingDream);
5940 pw.print(" mDreamingLockscreen="); pw.println(mDreamingLockscreen);
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07005941 if (mLastInputMethodWindow != null) {
5942 pw.print(prefix); pw.print("mLastInputMethodWindow=");
5943 pw.println(mLastInputMethodWindow);
5944 }
5945 if (mLastInputMethodTargetWindow != null) {
5946 pw.print(prefix); pw.print("mLastInputMethodTargetWindow=");
5947 pw.println(mLastInputMethodTargetWindow);
5948 }
5949 if (mStatusBar != null) {
5950 pw.print(prefix); pw.print("mStatusBar=");
5951 pw.println(mStatusBar);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01005952 pw.print(prefix); pw.print("isStatusBarKeyguard=");
5953 pw.print(isStatusBarKeyguard());
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07005954 }
5955 if (mNavigationBar != null) {
5956 pw.print(prefix); pw.print("mNavigationBar=");
5957 pw.println(mNavigationBar);
5958 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07005959 if (mFocusedWindow != null) {
5960 pw.print(prefix); pw.print("mFocusedWindow=");
5961 pw.println(mFocusedWindow);
5962 }
5963 if (mFocusedApp != null) {
5964 pw.print(prefix); pw.print("mFocusedApp=");
5965 pw.println(mFocusedApp);
5966 }
5967 if (mWinDismissingKeyguard != null) {
5968 pw.print(prefix); pw.print("mWinDismissingKeyguard=");
5969 pw.println(mWinDismissingKeyguard);
5970 }
5971 if (mTopFullscreenOpaqueWindowState != null) {
5972 pw.print(prefix); pw.print("mTopFullscreenOpaqueWindowState=");
5973 pw.println(mTopFullscreenOpaqueWindowState);
5974 }
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08005975 if (mForcingShowNavBar) {
5976 pw.print(prefix); pw.print("mForcingShowNavBar=");
5977 pw.println(mForcingShowNavBar); pw.print( "mForcingShowNavBarLayer=");
5978 pw.println(mForcingShowNavBarLayer);
5979 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07005980 pw.print(prefix); pw.print("mTopIsFullscreen="); pw.print(mTopIsFullscreen);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005981 pw.print(" mHideLockScreen="); pw.println(mHideLockScreen);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07005982 pw.print(prefix); pw.print("mForceStatusBar="); pw.print(mForceStatusBar);
5983 pw.print(" mForceStatusBarFromKeyguard=");
5984 pw.println(mForceStatusBarFromKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005985 pw.print(prefix); pw.print("mDismissKeyguard="); pw.print(mDismissKeyguard);
Craig Mautnerad09bcc2012-10-08 13:33:11 -07005986 pw.print(" mWinDismissingKeyguard="); pw.print(mWinDismissingKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005987 pw.print(" mHomePressed="); pw.println(mHomePressed);
5988 pw.print(prefix); pw.print("mAllowLockscreenWhenOn="); pw.print(mAllowLockscreenWhenOn);
5989 pw.print(" mLockScreenTimeout="); pw.print(mLockScreenTimeout);
5990 pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive);
5991 pw.print(prefix); pw.print("mEndcallBehavior="); pw.print(mEndcallBehavior);
5992 pw.print(" mIncallPowerBehavior="); pw.print(mIncallPowerBehavior);
5993 pw.print(" mLongPressOnHomeBehavior="); pw.println(mLongPressOnHomeBehavior);
5994 pw.print(prefix); pw.print("mLandscapeRotation="); pw.print(mLandscapeRotation);
5995 pw.print(" mSeascapeRotation="); pw.println(mSeascapeRotation);
5996 pw.print(prefix); pw.print("mPortraitRotation="); pw.print(mPortraitRotation);
5997 pw.print(" mUpsideDownRotation="); pw.println(mUpsideDownRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07005998 pw.print(prefix); pw.print("mDemoHdmiRotation="); pw.print(mDemoHdmiRotation);
5999 pw.print(" mDemoHdmiRotationLock="); pw.println(mDemoHdmiRotationLock);
6000 pw.print(prefix); pw.print("mUndockedHdmiRotation="); pw.println(mUndockedHdmiRotation);
Jeff Brown600f0032014-05-22 17:06:00 -07006001
Tim Kilbournd7c0c2e2014-05-29 16:08:10 -07006002 mGlobalKeyManager.dump(prefix, pw);
John Spurlock27735a42013-08-14 17:57:38 -04006003 mStatusBarController.dump(pw, prefix);
6004 mNavigationBarController.dump(pw, prefix);
John Spurlockc6d1c602014-01-17 15:22:06 -05006005 PolicyControl.dump(prefix, pw);
Jeff Brown600f0032014-05-22 17:06:00 -07006006
Jeff Browna20dda42014-05-27 20:57:24 -07006007 if (mWakeGestureListener != null) {
6008 mWakeGestureListener.dump(pw, prefix);
6009 }
Jeff Brown600f0032014-05-22 17:06:00 -07006010 if (mOrientationListener != null) {
6011 mOrientationListener.dump(pw, prefix);
6012 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08006013 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006014}