2 * Copyright (C) 2006 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package com.android.server.policy;
19 import android.app.ActivityManager;
20 import android.app.ActivityManagerNative;
21 import android.app.AppOpsManager;
22 import android.app.IUiModeManager;
23 import android.app.ProgressDialog;
24 import android.app.SearchManager;
25 import android.app.StatusBarManager;
26 import android.app.UiModeManager;
27 import android.content.ActivityNotFoundException;
28 import android.content.BroadcastReceiver;
29 import android.content.ComponentName;
30 import android.content.ContentResolver;
31 import android.content.Context;
32 import android.content.Intent;
33 import android.content.IntentFilter;
34 import android.content.ServiceConnection;
35 import android.content.pm.ActivityInfo;
36 import android.content.pm.PackageManager;
37 import android.content.pm.ResolveInfo;
38 import android.content.res.CompatibilityInfo;
39 import android.content.res.Configuration;
40 import android.content.res.Resources;
41 import android.content.res.TypedArray;
42 import android.database.ContentObserver;
43 import android.graphics.PixelFormat;
44 import android.graphics.Rect;
45 import android.media.AudioAttributes;
46 import android.media.AudioManager;
47 import android.media.AudioSystem;
48 import android.media.IAudioService;
49 import android.media.Ringtone;
50 import android.media.RingtoneManager;
51 import android.media.session.MediaSessionLegacyHelper;
52 import android.os.Build;
53 import android.os.Bundle;
54 import android.os.Debug;
55 import android.os.FactoryTest;
56 import android.os.Handler;
57 import android.os.IBinder;
58 import android.os.Looper;
59 import android.os.Message;
60 import android.os.Messenger;
61 import android.os.PowerManager;
62 import android.os.RemoteException;
63 import android.os.ServiceManager;
64 import android.os.SystemClock;
65 import android.os.SystemProperties;
66 import android.os.UEventObserver;
67 import android.os.UserHandle;
68 import android.os.Vibrator;
69 import android.provider.MediaStore;
70 import android.provider.Settings;
71 import android.service.dreams.DreamManagerInternal;
72 import android.service.dreams.DreamService;
73 import android.service.dreams.IDreamManager;
74 import android.speech.RecognizerIntent;
75 import android.telecom.TelecomManager;
76 import android.util.DisplayMetrics;
77 import android.util.EventLog;
78 import android.util.Log;
79 import android.util.Slog;
80 import android.util.SparseArray;
81 import android.view.Display;
82 import android.view.Gravity;
83 import android.view.HapticFeedbackConstants;
84 import android.view.IApplicationToken;
85 import android.view.IWindowManager;
86 import android.view.InputChannel;
87 import android.view.InputDevice;
88 import android.view.InputEvent;
89 import android.view.InputEventReceiver;
90 import android.view.KeyCharacterMap;
91 import android.view.KeyCharacterMap.FallbackAction;
92 import android.view.KeyEvent;
93 import android.view.MotionEvent;
94 import android.view.PhoneWindow;
95 import android.view.Surface;
96 import android.view.View;
97 import android.view.ViewConfiguration;
98 import android.view.ViewRootImpl;
99 import android.view.Window;
100 import android.view.WindowManager;
101 import android.view.WindowManagerGlobal;
102 import android.view.WindowManagerInternal;
103 import android.view.WindowManagerPolicy;
104 import android.view.accessibility.AccessibilityEvent;
105 import android.view.accessibility.AccessibilityManager;
106 import android.view.animation.Animation;
107 import android.view.animation.AnimationSet;
108 import android.view.animation.AnimationUtils;
109 import com.android.internal.R;
110 import com.android.internal.statusbar.IStatusBarService;
111 import com.android.internal.widget.PointerLocationView;
112 import com.android.server.LocalServices;
113 import com.android.server.policy.keyguard.KeyguardServiceDelegate;
114 import com.android.server.policy.keyguard.KeyguardServiceDelegate.ShowListener;
117 import java.io.FileReader;
118 import java.io.IOException;
119 import java.io.PrintWriter;
120 import java.util.HashSet;
121 import java.util.List;
123 import static android.view.WindowManager.LayoutParams.*;
124 import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_ABSENT;
125 import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_OPEN;
126 import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_CLOSED;
127 import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVER_ABSENT;
128 import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_UNCOVERED;
129 import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVERED;
132 * WindowManagerPolicy implementation for the Android phone UI. This
133 * introduces a new method suffix, Lp, for an internal lock of the
134 * PhoneWindowManager. This is used to protect some internal state, and
135 * can be acquired with either the Lw and Li lock held, so has the restrictions
136 * of both of those when held.
138 public class PhoneWindowManager implements WindowManagerPolicy {
139 static final String TAG = "WindowManager";
140 static final boolean DEBUG = false;
141 static final boolean localLOGV = false;
142 static final boolean DEBUG_INPUT = false;
143 static final boolean DEBUG_KEYGUARD = false;
144 static final boolean DEBUG_LAYOUT = false;
145 static final boolean DEBUG_STARTING_WINDOW = false;
146 static final boolean DEBUG_WAKEUP = false;
147 static final boolean SHOW_STARTING_ANIMATIONS = true;
148 static final boolean SHOW_PROCESSES_ON_ALT_MENU = false;
150 // Whether to allow dock apps with METADATA_DOCK_HOME to temporarily take over the Home key.
151 // No longer recommended for desk docks; still useful in car docks.
152 static final boolean ENABLE_CAR_DOCK_HOME_CAPTURE = true;
153 static final boolean ENABLE_DESK_DOCK_HOME_CAPTURE = false;
155 static final int SHORT_PRESS_POWER_NOTHING = 0;
156 static final int SHORT_PRESS_POWER_GO_TO_SLEEP = 1;
157 static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP = 2;
158 static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME = 3;
159 static final int SHORT_PRESS_POWER_GO_HOME = 4;
161 static final int LONG_PRESS_POWER_NOTHING = 0;
162 static final int LONG_PRESS_POWER_GLOBAL_ACTIONS = 1;
163 static final int LONG_PRESS_POWER_SHUT_OFF = 2;
164 static final int LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM = 3;
166 static final int MULTI_PRESS_POWER_NOTHING = 0;
167 static final int MULTI_PRESS_POWER_THEATER_MODE = 1;
168 static final int MULTI_PRESS_POWER_BRIGHTNESS_BOOST = 2;
170 // These need to match the documentation/constant in
171 // core/res/res/values/config.xml
172 static final int LONG_PRESS_HOME_NOTHING = 0;
173 static final int LONG_PRESS_HOME_RECENT_SYSTEM_UI = 1;
174 static final int LONG_PRESS_HOME_ASSIST = 2;
176 static final int DOUBLE_TAP_HOME_NOTHING = 0;
177 static final int DOUBLE_TAP_HOME_RECENT_SYSTEM_UI = 1;
179 static final int SHORT_PRESS_SLEEP_GO_TO_SLEEP = 0;
180 static final int SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME = 1;
182 static final int APPLICATION_MEDIA_SUBLAYER = -2;
183 static final int APPLICATION_MEDIA_OVERLAY_SUBLAYER = -1;
184 static final int APPLICATION_PANEL_SUBLAYER = 1;
185 static final int APPLICATION_SUB_PANEL_SUBLAYER = 2;
186 static final int APPLICATION_ABOVE_SUB_PANEL_SUBLAYER = 3;
188 static public final String SYSTEM_DIALOG_REASON_KEY = "reason";
189 static public final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions";
190 static public final String SYSTEM_DIALOG_REASON_RECENT_APPS = "recentapps";
191 static public final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey";
192 static public final String SYSTEM_DIALOG_REASON_ASSIST = "assist";
195 * These are the system UI flags that, when changing, can cause the layout
196 * of the screen to change.
198 static final int SYSTEM_UI_CHANGING_LAYOUT =
199 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
200 | View.SYSTEM_UI_FLAG_FULLSCREEN
201 | View.STATUS_BAR_TRANSLUCENT
202 | View.NAVIGATION_BAR_TRANSLUCENT
203 | View.SYSTEM_UI_TRANSPARENT;
205 private static final AudioAttributes VIBRATION_ATTRIBUTES = new AudioAttributes.Builder()
206 .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
207 .setUsage(AudioAttributes.USAGE_ASSISTANCE_SONIFICATION)
213 private WindowState mKeyguardScrim;
214 private boolean mKeyguardHidden;
215 private boolean mKeyguardDrawnOnce;
217 /* Table of Application Launch keys. Maps from key codes to intent categories.
219 * These are special keys that are used to launch particular kinds of applications,
220 * such as a web browser. HID defines nearly a hundred of them in the Consumer (0x0C)
221 * usage page. We don't support quite that many yet...
223 static SparseArray<String> sApplicationLaunchKeyCategories;
225 sApplicationLaunchKeyCategories = new SparseArray<String>();
226 sApplicationLaunchKeyCategories.append(
227 KeyEvent.KEYCODE_EXPLORER, Intent.CATEGORY_APP_BROWSER);
228 sApplicationLaunchKeyCategories.append(
229 KeyEvent.KEYCODE_ENVELOPE, Intent.CATEGORY_APP_EMAIL);
230 sApplicationLaunchKeyCategories.append(
231 KeyEvent.KEYCODE_CONTACTS, Intent.CATEGORY_APP_CONTACTS);
232 sApplicationLaunchKeyCategories.append(
233 KeyEvent.KEYCODE_CALENDAR, Intent.CATEGORY_APP_CALENDAR);
234 sApplicationLaunchKeyCategories.append(
235 KeyEvent.KEYCODE_MUSIC, Intent.CATEGORY_APP_MUSIC);
236 sApplicationLaunchKeyCategories.append(
237 KeyEvent.KEYCODE_CALCULATOR, Intent.CATEGORY_APP_CALCULATOR);
240 /** Amount of time (in milliseconds) to wait for windows drawn before powering on. */
241 static final int WAITING_FOR_DRAWN_TIMEOUT = 1000;
244 * Lock protecting internal state. Must not call out into window
245 * manager with lock held. (This lock will be acquired in places
246 * where the window manager is calling in with its own lock held.)
248 private final Object mLock = new Object();
251 IWindowManager mWindowManager;
252 WindowManagerFuncs mWindowManagerFuncs;
253 WindowManagerInternal mWindowManagerInternal;
254 PowerManager mPowerManager;
255 DreamManagerInternal mDreamManagerInternal;
256 IStatusBarService mStatusBarService;
257 boolean mPreloadedRecentApps;
258 final Object mServiceAquireLock = new Object();
259 Vibrator mVibrator; // Vibrator for giving feedback of orientation changes
260 SearchManager mSearchManager;
261 AccessibilityManager mAccessibilityManager;
262 BurnInProtectionHelper mBurnInProtectionHelper;
264 // Vibrator pattern for haptic feedback of a long press.
265 long[] mLongPressVibePattern;
267 // Vibrator pattern for haptic feedback of virtual key press.
268 long[] mVirtualKeyVibePattern;
270 // Vibrator pattern for a short vibration.
271 long[] mKeyboardTapVibePattern;
273 // Vibrator pattern for a short vibration when tapping on an hour/minute tick of a Clock.
274 long[] mClockTickVibePattern;
276 // Vibrator pattern for a short vibration when tapping on a day/month/year date of a Calendar.
277 long[] mCalendarDateVibePattern;
279 // Vibrator pattern for haptic feedback during boot when safe mode is disabled.
280 long[] mSafeModeDisabledVibePattern;
282 // Vibrator pattern for haptic feedback during boot when safe mode is enabled.
283 long[] mSafeModeEnabledVibePattern;
285 /** If true, hitting shift & menu will broadcast Intent.ACTION_BUG_REPORT */
286 boolean mEnableShiftMenuBugReports = false;
289 WindowState mStatusBar = null;
290 int mStatusBarHeight;
291 WindowState mNavigationBar = null;
292 boolean mHasNavigationBar = false;
293 boolean mCanHideNavigationBar = false;
294 boolean mNavigationBarCanMove = false; // can the navigation bar ever move to the side?
295 boolean mNavigationBarOnBottom = true; // is the navigation bar on the bottom *right now*?
296 int[] mNavigationBarHeightForRotation = new int[4];
297 int[] mNavigationBarWidthForRotation = new int[4];
299 boolean mBootMessageNeedsHiding;
300 KeyguardServiceDelegate mKeyguardDelegate;
301 final Runnable mWindowManagerDrawCallback = new Runnable() {
304 if (DEBUG_WAKEUP) Slog.i(TAG, "All windows ready for display!");
305 mHandler.sendEmptyMessage(MSG_WINDOW_MANAGER_DRAWN_COMPLETE);
308 final ShowListener mKeyguardDelegateCallback = new ShowListener() {
310 public void onShown(IBinder windowToken) {
311 if (DEBUG_WAKEUP) Slog.d(TAG, "mKeyguardDelegate.ShowListener.onShown.");
312 mHandler.sendEmptyMessage(MSG_KEYGUARD_DRAWN_COMPLETE);
316 GlobalActions mGlobalActions;
318 WindowState mLastInputMethodWindow = null;
319 WindowState mLastInputMethodTargetWindow = null;
321 // FIXME This state is shared between the input reader and handler thread.
322 // Technically it's broken and buggy but it has been like this for many years
323 // and we have not yet seen any problems. Someday we'll rewrite this logic
324 // so that only one thread is involved in handling input policy. Unfortunately
325 // it's on a critical path for power management so we can't just post the work to the
326 // handler thread. We'll need to resolve this someday by teaching the input dispatcher
327 // to hold wakelocks during dispatch and eliminating the critical path.
328 volatile boolean mPowerKeyHandled;
329 volatile boolean mBeganFromNonInteractive;
330 volatile int mPowerKeyPressCounter;
331 volatile boolean mEndCallKeyHandled;
333 boolean mRecentsVisible;
334 int mRecentAppsHeldModifiers;
335 boolean mLanguageSwitchKeyPressed;
337 int mLidState = LID_ABSENT;
338 int mCameraLensCoverState = CAMERA_LENS_COVER_ABSENT;
339 boolean mHaveBuiltInKeyboard;
341 boolean mSystemReady;
342 boolean mSystemBooted;
343 boolean mHdmiPlugged;
344 IUiModeManager mUiModeManager;
346 int mDockMode = Intent.EXTRA_DOCK_STATE_UNDOCKED;
347 int mLidOpenRotation;
348 int mCarDockRotation;
349 int mDeskDockRotation;
350 int mUndockedHdmiRotation;
351 int mDemoHdmiRotation;
352 boolean mDemoHdmiRotationLock;
354 boolean mDemoRotationLock;
356 boolean mWakeGestureEnabledSetting;
357 MyWakeGestureListener mWakeGestureListener;
359 // Default display does not rotate, apps that require non-default orientation will have to
360 // have the orientation emulated.
361 private boolean mForceDefaultOrientation = false;
363 int mUserRotationMode = WindowManagerPolicy.USER_ROTATION_FREE;
364 int mUserRotation = Surface.ROTATION_0;
365 boolean mAccelerometerDefault;
367 boolean mSupportAutoRotation;
368 int mAllowAllRotations = -1;
369 boolean mCarDockEnablesAccelerometer;
370 boolean mDeskDockEnablesAccelerometer;
371 int mLidKeyboardAccessibility;
372 int mLidNavigationAccessibility;
373 boolean mLidControlsSleep;
374 int mShortPressOnPowerBehavior;
375 int mLongPressOnPowerBehavior;
376 int mDoublePressOnPowerBehavior;
377 int mTriplePressOnPowerBehavior;
378 int mShortPressOnSleepBehavior;
380 boolean mScreenOnEarly;
381 boolean mScreenOnFully;
382 ScreenOnListener mScreenOnListener;
383 boolean mKeyguardDrawComplete;
384 boolean mWindowManagerDrawComplete;
385 boolean mOrientationSensorEnabled = false;
386 int mCurrentAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
387 boolean mHasSoftInput = false;
388 boolean mTranslucentDecorEnabled = true;
389 boolean mUseTvRouting;
391 int mPointerLocationMode = 0; // guarded by mLock
393 // The last window we were told about in focusChanged.
394 WindowState mFocusedWindow;
395 IApplicationToken mFocusedApp;
397 PointerLocationView mPointerLocationView;
399 // The current size of the screen; really; extends into the overscan area of
400 // the screen and doesn't account for any system elements like the status bar.
401 int mOverscanScreenLeft, mOverscanScreenTop;
402 int mOverscanScreenWidth, mOverscanScreenHeight;
403 // The current visible size of the screen; really; (ir)regardless of whether the status
404 // bar can be hidden but not extending into the overscan area.
405 int mUnrestrictedScreenLeft, mUnrestrictedScreenTop;
406 int mUnrestrictedScreenWidth, mUnrestrictedScreenHeight;
407 // Like mOverscanScreen*, but allowed to move into the overscan region where appropriate.
408 int mRestrictedOverscanScreenLeft, mRestrictedOverscanScreenTop;
409 int mRestrictedOverscanScreenWidth, mRestrictedOverscanScreenHeight;
410 // The current size of the screen; these may be different than (0,0)-(dw,dh)
411 // if the status bar can't be hidden; in that case it effectively carves out
412 // that area of the display from all other windows.
413 int mRestrictedScreenLeft, mRestrictedScreenTop;
414 int mRestrictedScreenWidth, mRestrictedScreenHeight;
415 // During layout, the current screen borders accounting for any currently
416 // visible system UI elements.
417 int mSystemLeft, mSystemTop, mSystemRight, mSystemBottom;
418 // For applications requesting stable content insets, these are them.
419 int mStableLeft, mStableTop, mStableRight, mStableBottom;
420 // For applications requesting stable content insets but have also set the
421 // fullscreen window flag, these are the stable dimensions without the status bar.
422 int mStableFullscreenLeft, mStableFullscreenTop;
423 int mStableFullscreenRight, mStableFullscreenBottom;
424 // During layout, the current screen borders with all outer decoration
425 // (status bar, input method dock) accounted for.
426 int mCurLeft, mCurTop, mCurRight, mCurBottom;
427 // During layout, the frame in which content should be displayed
428 // to the user, accounting for all screen decoration except for any
429 // space they deem as available for other content. This is usually
430 // the same as mCur*, but may be larger if the screen decor has supplied
432 int mContentLeft, mContentTop, mContentRight, mContentBottom;
433 // During layout, the frame in which voice content should be displayed
434 // to the user, accounting for all screen decoration except for any
435 // space they deem as available for other content.
436 int mVoiceContentLeft, mVoiceContentTop, mVoiceContentRight, mVoiceContentBottom;
437 // During layout, the current screen borders along which input method
438 // windows are placed.
439 int mDockLeft, mDockTop, mDockRight, mDockBottom;
440 // During layout, the layer at which the doc window is placed.
442 // During layout, this is the layer of the status bar.
444 int mLastSystemUiFlags;
445 // Bits that we are in the process of clearing, so we want to prevent
446 // them from being set by applications until everything has been updated
447 // to have them clear.
448 int mResettingSystemUiFlags = 0;
449 // Bits that we are currently always keeping cleared.
450 int mForceClearedSystemUiFlags = 0;
451 // What we last reported to system UI about whether the compatibility
452 // menu needs to be displayed.
453 boolean mLastFocusNeedsMenu = false;
455 FakeWindow mHideNavFakeWindow = null;
457 static final Rect mTmpParentFrame = new Rect();
458 static final Rect mTmpDisplayFrame = new Rect();
459 static final Rect mTmpOverscanFrame = new Rect();
460 static final Rect mTmpContentFrame = new Rect();
461 static final Rect mTmpVisibleFrame = new Rect();
462 static final Rect mTmpDecorFrame = new Rect();
463 static final Rect mTmpStableFrame = new Rect();
464 static final Rect mTmpNavigationFrame = new Rect();
466 WindowState mTopFullscreenOpaqueWindowState;
467 WindowState mTopFullscreenOpaqueOrDimmingWindowState;
468 HashSet<IApplicationToken> mAppsToBeHidden = new HashSet<IApplicationToken>();
469 HashSet<IApplicationToken> mAppsThatDismissKeyguard = new HashSet<IApplicationToken>();
470 boolean mTopIsFullscreen;
471 boolean mForceStatusBar;
472 boolean mForceStatusBarFromKeyguard;
473 boolean mHideLockScreen;
474 boolean mForcingShowNavBar;
475 int mForcingShowNavBarLayer;
477 // States of keyguard dismiss.
478 private static final int DISMISS_KEYGUARD_NONE = 0; // Keyguard not being dismissed.
479 private static final int DISMISS_KEYGUARD_START = 1; // Keyguard needs to be dismissed.
480 private static final int DISMISS_KEYGUARD_CONTINUE = 2; // Keyguard has been dismissed.
481 int mDismissKeyguard = DISMISS_KEYGUARD_NONE;
483 /** The window that is currently dismissing the keyguard. Dismissing the keyguard must only
484 * be done once per window. */
485 private WindowState mWinDismissingKeyguard;
487 /** The window that is currently showing "over" the keyguard. If there is an app window
488 * belonging to another app on top of this the keyguard shows. If there is a fullscreen
489 * app window under this, still dismiss the keyguard but don't show the app underneath. Show
491 private WindowState mWinShowWhenLocked;
493 boolean mShowingLockscreen;
494 boolean mShowingDream;
495 boolean mDreamingLockscreen;
496 boolean mKeyguardSecure;
497 boolean mKeyguardSecureIncludingHidden;
498 volatile boolean mKeyguardOccluded;
499 boolean mHomePressed;
500 boolean mHomeConsumed;
501 boolean mHomeDoubleTapPending;
503 Intent mCarDockIntent;
504 Intent mDeskDockIntent;
505 boolean mSearchKeyShortcutPending;
506 boolean mConsumeSearchKeyUp;
507 boolean mAssistKeyLongPressed;
508 boolean mPendingMetaAction;
510 // support for activating the lock screen while the screen is on
511 boolean mAllowLockscreenWhenOn;
512 int mLockScreenTimeout;
513 boolean mLockScreenTimerActive;
515 // Behavior of ENDCALL Button. (See Settings.System.END_BUTTON_BEHAVIOR.)
516 int mEndcallBehavior;
518 // Behavior of POWER button while in-call and screen on.
519 // (See Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR.)
520 int mIncallPowerBehavior;
524 int mLandscapeRotation = 0; // default landscape rotation
525 int mSeascapeRotation = 0; // "other" landscape rotation, 180 degrees from mLandscapeRotation
526 int mPortraitRotation = 0; // default portrait rotation
527 int mUpsideDownRotation = 0; // "other" portrait rotation
529 int mOverscanLeft = 0;
530 int mOverscanTop = 0;
531 int mOverscanRight = 0;
532 int mOverscanBottom = 0;
534 // What we do when the user long presses on home
535 private int mLongPressOnHomeBehavior;
537 // What we do when the user double-taps on home
538 private int mDoubleTapOnHomeBehavior;
540 // Allowed theater mode wake actions
541 private boolean mAllowTheaterModeWakeFromKey;
542 private boolean mAllowTheaterModeWakeFromPowerKey;
543 private boolean mAllowTheaterModeWakeFromMotion;
544 private boolean mAllowTheaterModeWakeFromMotionWhenNotDreaming;
545 private boolean mAllowTheaterModeWakeFromCameraLens;
546 private boolean mAllowTheaterModeWakeFromLidSwitch;
547 private boolean mAllowTheaterModeWakeFromWakeGesture;
549 // Whether to support long press from power button in non-interactive mode
550 private boolean mSupportLongPressPowerWhenNonInteractive;
552 // Whether to go to sleep entering theater mode from power button
553 private boolean mGoToSleepOnButtonPressTheaterMode;
555 // Screenshot trigger states
556 // Time to volume and power must be pressed within this interval of each other.
557 private static final long SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS = 150;
558 // Increase the chord delay when taking a screenshot from the keyguard
559 private static final float KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER = 2.5f;
560 private boolean mScreenshotChordEnabled;
561 private boolean mScreenshotChordVolumeDownKeyTriggered;
562 private long mScreenshotChordVolumeDownKeyTime;
563 private boolean mScreenshotChordVolumeDownKeyConsumed;
564 private boolean mScreenshotChordVolumeUpKeyTriggered;
565 private boolean mScreenshotChordPowerKeyTriggered;
566 private long mScreenshotChordPowerKeyTime;
568 /* The number of steps between min and max brightness */
569 private static final int BRIGHTNESS_STEPS = 10;
571 SettingsObserver mSettingsObserver;
572 ShortcutManager mShortcutManager;
573 PowerManager.WakeLock mBroadcastWakeLock;
574 PowerManager.WakeLock mPowerKeyWakeLock;
575 boolean mHavePendingMediaKeyRepeatWithWakeLock;
577 private int mCurrentUserId;
579 // Maps global key codes to the components that will handle them.
580 private GlobalKeyManager mGlobalKeyManager;
582 // Fallback actions by key code.
583 private final SparseArray<KeyCharacterMap.FallbackAction> mFallbackActions =
584 new SparseArray<KeyCharacterMap.FallbackAction>();
586 private final LogDecelerateInterpolator mLogDecelerateInterpolator
587 = new LogDecelerateInterpolator(100, 0);
589 private static final int MSG_ENABLE_POINTER_LOCATION = 1;
590 private static final int MSG_DISABLE_POINTER_LOCATION = 2;
591 private static final int MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK = 3;
592 private static final int MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK = 4;
593 private static final int MSG_KEYGUARD_DRAWN_COMPLETE = 5;
594 private static final int MSG_KEYGUARD_DRAWN_TIMEOUT = 6;
595 private static final int MSG_WINDOW_MANAGER_DRAWN_COMPLETE = 7;
596 private static final int MSG_DISPATCH_SHOW_RECENTS = 9;
597 private static final int MSG_DISPATCH_SHOW_GLOBAL_ACTIONS = 10;
598 private static final int MSG_HIDE_BOOT_MESSAGE = 11;
599 private static final int MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK = 12;
600 private static final int MSG_POWER_DELAYED_PRESS = 13;
601 private static final int MSG_POWER_LONG_PRESS = 14;
603 private class PolicyHandler extends Handler {
605 public void handleMessage(Message msg) {
607 case MSG_ENABLE_POINTER_LOCATION:
608 enablePointerLocation();
610 case MSG_DISABLE_POINTER_LOCATION:
611 disablePointerLocation();
613 case MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK:
614 dispatchMediaKeyWithWakeLock((KeyEvent)msg.obj);
616 case MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK:
617 dispatchMediaKeyRepeatWithWakeLock((KeyEvent)msg.obj);
619 case MSG_DISPATCH_SHOW_RECENTS:
620 showRecentApps(false);
622 case MSG_DISPATCH_SHOW_GLOBAL_ACTIONS:
623 showGlobalActionsInternal();
625 case MSG_KEYGUARD_DRAWN_COMPLETE:
626 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mKeyguardDrawComplete");
627 finishKeyguardDrawn();
629 case MSG_KEYGUARD_DRAWN_TIMEOUT:
630 Slog.w(TAG, "Keyguard drawn timeout. Setting mKeyguardDrawComplete");
631 finishKeyguardDrawn();
633 case MSG_WINDOW_MANAGER_DRAWN_COMPLETE:
634 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mWindowManagerDrawComplete");
635 finishWindowsDrawn();
637 case MSG_HIDE_BOOT_MESSAGE:
638 handleHideBootMessage();
640 case MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK:
641 launchVoiceAssistWithWakeLock(msg.arg1 != 0);
643 case MSG_POWER_DELAYED_PRESS:
644 powerPress((Long)msg.obj, msg.arg1 != 0, msg.arg2);
645 finishPowerKeyPress();
647 case MSG_POWER_LONG_PRESS:
654 private UEventObserver mHDMIObserver = new UEventObserver() {
656 public void onUEvent(UEventObserver.UEvent event) {
657 setHdmiPlugged("1".equals(event.get("SWITCH_STATE")));
661 class SettingsObserver extends ContentObserver {
662 SettingsObserver(Handler handler) {
667 // Observe all users' changes
668 ContentResolver resolver = mContext.getContentResolver();
669 resolver.registerContentObserver(Settings.System.getUriFor(
670 Settings.System.END_BUTTON_BEHAVIOR), false, this,
671 UserHandle.USER_ALL);
672 resolver.registerContentObserver(Settings.Secure.getUriFor(
673 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR), false, this,
674 UserHandle.USER_ALL);
675 resolver.registerContentObserver(Settings.Secure.getUriFor(
676 Settings.Secure.WAKE_GESTURE_ENABLED), false, this,
677 UserHandle.USER_ALL);
678 resolver.registerContentObserver(Settings.System.getUriFor(
679 Settings.System.ACCELEROMETER_ROTATION), false, this,
680 UserHandle.USER_ALL);
681 resolver.registerContentObserver(Settings.System.getUriFor(
682 Settings.System.USER_ROTATION), false, this,
683 UserHandle.USER_ALL);
684 resolver.registerContentObserver(Settings.System.getUriFor(
685 Settings.System.SCREEN_OFF_TIMEOUT), false, this,
686 UserHandle.USER_ALL);
687 resolver.registerContentObserver(Settings.System.getUriFor(
688 Settings.System.POINTER_LOCATION), false, this,
689 UserHandle.USER_ALL);
690 resolver.registerContentObserver(Settings.Secure.getUriFor(
691 Settings.Secure.DEFAULT_INPUT_METHOD), false, this,
692 UserHandle.USER_ALL);
693 resolver.registerContentObserver(Settings.Secure.getUriFor(
694 Settings.Secure.IMMERSIVE_MODE_CONFIRMATIONS), false, this,
695 UserHandle.USER_ALL);
696 resolver.registerContentObserver(Settings.Global.getUriFor(
697 Settings.Global.POLICY_CONTROL), false, this,
698 UserHandle.USER_ALL);
702 @Override public void onChange(boolean selfChange) {
704 updateRotation(false);
708 class MyWakeGestureListener extends WakeGestureListener {
709 MyWakeGestureListener(Context context, Handler handler) {
710 super(context, handler);
714 public void onWakeUp() {
715 synchronized (mLock) {
716 if (shouldEnableWakeGestureLp()) {
717 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
718 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromWakeGesture);
724 class MyOrientationListener extends WindowOrientationListener {
725 MyOrientationListener(Context context, Handler handler) {
726 super(context, handler);
730 public void onProposedRotationChanged(int rotation) {
731 if (localLOGV) Slog.v(TAG, "onProposedRotationChanged, rotation=" + rotation);
732 updateRotation(false);
735 MyOrientationListener mOrientationListener;
737 private final StatusBarController mStatusBarController = new StatusBarController();
739 private final BarController mNavigationBarController = new BarController("NavigationBar",
740 View.NAVIGATION_BAR_TRANSIENT,
741 View.NAVIGATION_BAR_UNHIDE,
742 View.NAVIGATION_BAR_TRANSLUCENT,
743 StatusBarManager.WINDOW_NAVIGATION_BAR,
744 WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
746 private ImmersiveModeConfirmation mImmersiveModeConfirmation;
748 private SystemGesturesPointerEventListener mSystemGestures;
750 IStatusBarService getStatusBarService() {
751 synchronized (mServiceAquireLock) {
752 if (mStatusBarService == null) {
753 mStatusBarService = IStatusBarService.Stub.asInterface(
754 ServiceManager.getService("statusbar"));
756 return mStatusBarService;
761 * We always let the sensor be switched on by default except when
762 * the user has explicitly disabled sensor based rotation or when the
763 * screen is switched off.
765 boolean needSensorRunningLp() {
766 if (mSupportAutoRotation) {
767 if (mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
768 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
769 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT
770 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) {
771 // If the application has explicitly requested to follow the
772 // orientation, then we need to turn the sensor on.
776 if ((mCarDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_CAR) ||
777 (mDeskDockEnablesAccelerometer && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
778 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
779 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK))) {
780 // enable accelerometer if we are docked in a dock that enables accelerometer
781 // orientation management,
784 if (mUserRotationMode == USER_ROTATION_LOCKED) {
785 // If the setting for using the sensor by default is enabled, then
786 // we will always leave it on. Note that the user could go to
787 // a window that forces an orientation that does not use the
788 // sensor and in theory we could turn it off... however, when next
789 // turning it on we won't have a good value for the current
790 // orientation for a little bit, which can cause orientation
791 // changes to lag, so we'd like to keep it always on. (It will
792 // still be turned off when the screen is off.)
795 return mSupportAutoRotation;
799 * Various use cases for invoking this function
800 * screen turning off, should always disable listeners if already enabled
801 * screen turned on and current app has sensor based orientation, enable listeners
802 * if not already enabled
803 * screen turned on and current app does not have sensor orientation, disable listeners if
805 * screen turning on and current app has sensor based orientation, enable listeners if needed
806 * screen turning on and current app has nosensor based orientation, do nothing
808 void updateOrientationListenerLp() {
809 if (!mOrientationListener.canDetectOrientation()) {
810 // If sensor is turned off or nonexistent for some reason
813 //Could have been invoked due to screen turning on or off or
814 //change of the currently visible window's orientation
815 if (localLOGV) Slog.v(TAG, "mScreenOnEarly=" + mScreenOnEarly
816 + ", mAwake=" + mAwake + ", mCurrentAppOrientation=" + mCurrentAppOrientation
817 + ", mOrientationSensorEnabled=" + mOrientationSensorEnabled);
818 boolean disable = true;
819 if (mScreenOnEarly && mAwake) {
820 if (needSensorRunningLp()) {
822 //enable listener if not already enabled
823 if (!mOrientationSensorEnabled) {
824 mOrientationListener.enable();
825 if(localLOGV) Slog.v(TAG, "Enabling listeners");
826 mOrientationSensorEnabled = true;
830 //check if sensors need to be disabled
831 if (disable && mOrientationSensorEnabled) {
832 mOrientationListener.disable();
833 if(localLOGV) Slog.v(TAG, "Disabling listeners");
834 mOrientationSensorEnabled = false;
838 private void interceptPowerKeyDown(KeyEvent event, boolean interactive) {
839 // Hold a wake lock until the power key is released.
840 if (!mPowerKeyWakeLock.isHeld()) {
841 mPowerKeyWakeLock.acquire();
844 // Cancel multi-press detection timeout.
845 if (mPowerKeyPressCounter != 0) {
846 mHandler.removeMessages(MSG_POWER_DELAYED_PRESS);
849 // Detect user pressing the power button in panic when an application has
850 // taken over the whole screen.
851 boolean panic = mImmersiveModeConfirmation.onPowerKeyDown(interactive,
852 SystemClock.elapsedRealtime(), isImmersiveMode(mLastSystemUiFlags));
854 mHandler.post(mRequestTransientNav);
857 // Latch power key state to detect screenshot chord.
858 if (interactive && !mScreenshotChordPowerKeyTriggered
859 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
860 mScreenshotChordPowerKeyTriggered = true;
861 mScreenshotChordPowerKeyTime = event.getDownTime();
862 interceptScreenshotChord();
865 // Stop ringing or end call if configured to do so when power is pressed.
866 TelecomManager telecomManager = getTelecommService();
867 boolean hungUp = false;
868 if (telecomManager != null) {
869 if (telecomManager.isRinging()) {
870 // Pressing Power while there's a ringing incoming
871 // call should silence the ringer.
872 telecomManager.silenceRinger();
873 } else if ((mIncallPowerBehavior
874 & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0
875 && telecomManager.isInCall() && interactive) {
876 // Otherwise, if "Power button ends call" is enabled,
877 // the Power button will hang up any current active call.
878 hungUp = telecomManager.endCall();
882 // If the power key has still not yet been handled, then detect short
883 // press, long press, or multi press and decide what to do.
884 mPowerKeyHandled = hungUp || mScreenshotChordVolumeDownKeyTriggered
885 || mScreenshotChordVolumeUpKeyTriggered;
886 if (!mPowerKeyHandled) {
888 // When interactive, we're already awake.
889 // Wait for a long press or for the button to be released to decide what to do.
890 if (hasLongPressOnPowerBehavior()) {
891 Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS);
892 msg.setAsynchronous(true);
893 mHandler.sendMessageDelayed(msg,
894 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
897 wakeUpFromPowerKey(event.getDownTime());
899 if (mSupportLongPressPowerWhenNonInteractive && hasLongPressOnPowerBehavior()) {
900 Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS);
901 msg.setAsynchronous(true);
902 mHandler.sendMessageDelayed(msg,
903 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
904 mBeganFromNonInteractive = true;
906 final int maxCount = getMaxMultiPressPowerCount();
909 mPowerKeyHandled = true;
911 mBeganFromNonInteractive = true;
918 private void interceptPowerKeyUp(KeyEvent event, boolean interactive, boolean canceled) {
919 final boolean handled = canceled || mPowerKeyHandled;
920 mScreenshotChordPowerKeyTriggered = false;
921 cancelPendingScreenshotChordAction();
922 cancelPendingPowerKeyAction();
925 // Figure out how to handle the key now that it has been released.
926 mPowerKeyPressCounter += 1;
928 final int maxCount = getMaxMultiPressPowerCount();
929 final long eventTime = event.getDownTime();
930 if (mPowerKeyPressCounter < maxCount) {
931 // This could be a multi-press. Wait a little bit longer to confirm.
932 // Continue holding the wake lock.
933 Message msg = mHandler.obtainMessage(MSG_POWER_DELAYED_PRESS,
934 interactive ? 1 : 0, mPowerKeyPressCounter, eventTime);
935 msg.setAsynchronous(true);
936 mHandler.sendMessageDelayed(msg, ViewConfiguration.getDoubleTapTimeout());
940 // No other actions. Handle it immediately.
941 powerPress(eventTime, interactive, mPowerKeyPressCounter);
944 // Done. Reset our state.
945 finishPowerKeyPress();
948 private void finishPowerKeyPress() {
949 mBeganFromNonInteractive = false;
950 mPowerKeyPressCounter = 0;
951 if (mPowerKeyWakeLock.isHeld()) {
952 mPowerKeyWakeLock.release();
956 private void cancelPendingPowerKeyAction() {
957 if (!mPowerKeyHandled) {
958 mPowerKeyHandled = true;
959 mHandler.removeMessages(MSG_POWER_LONG_PRESS);
963 private void powerPress(long eventTime, boolean interactive, int count) {
964 if (mScreenOnEarly && !mScreenOnFully) {
965 Slog.i(TAG, "Suppressed redundant power key press while "
966 + "already in the process of turning the screen on.");
971 powerMultiPressAction(eventTime, interactive, mDoublePressOnPowerBehavior);
972 } else if (count == 3) {
973 powerMultiPressAction(eventTime, interactive, mTriplePressOnPowerBehavior);
974 } else if (interactive && !mBeganFromNonInteractive) {
975 switch (mShortPressOnPowerBehavior) {
976 case SHORT_PRESS_POWER_NOTHING:
978 case SHORT_PRESS_POWER_GO_TO_SLEEP:
979 mPowerManager.goToSleep(eventTime,
980 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
982 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP:
983 mPowerManager.goToSleep(eventTime,
984 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
985 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
987 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME:
988 mPowerManager.goToSleep(eventTime,
989 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
990 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
991 launchHomeFromHotKey();
993 case SHORT_PRESS_POWER_GO_HOME:
994 launchHomeFromHotKey(true /* awakenFromDreams */, false /*respectKeyguard*/);
1000 private void powerMultiPressAction(long eventTime, boolean interactive, int behavior) {
1002 case MULTI_PRESS_POWER_NOTHING:
1004 case MULTI_PRESS_POWER_THEATER_MODE:
1005 if (isTheaterModeEnabled()) {
1006 Slog.i(TAG, "Toggling theater mode off.");
1007 Settings.Global.putInt(mContext.getContentResolver(),
1008 Settings.Global.THEATER_MODE_ON, 0);
1010 wakeUpFromPowerKey(eventTime);
1013 Slog.i(TAG, "Toggling theater mode on.");
1014 Settings.Global.putInt(mContext.getContentResolver(),
1015 Settings.Global.THEATER_MODE_ON, 1);
1017 if (mGoToSleepOnButtonPressTheaterMode && interactive) {
1018 mPowerManager.goToSleep(eventTime,
1019 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
1023 case MULTI_PRESS_POWER_BRIGHTNESS_BOOST:
1024 Slog.i(TAG, "Starting brightness boost.");
1026 wakeUpFromPowerKey(eventTime);
1028 mPowerManager.boostScreenBrightness(eventTime);
1033 private int getMaxMultiPressPowerCount() {
1034 if (mTriplePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) {
1037 if (mDoublePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) {
1043 private void powerLongPress() {
1044 final int behavior = getResolvedLongPressOnPowerBehavior();
1046 case LONG_PRESS_POWER_NOTHING:
1048 case LONG_PRESS_POWER_GLOBAL_ACTIONS:
1049 mPowerKeyHandled = true;
1050 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
1051 performAuditoryFeedbackForAccessibilityIfNeed();
1053 showGlobalActionsInternal();
1055 case LONG_PRESS_POWER_SHUT_OFF:
1056 case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM:
1057 mPowerKeyHandled = true;
1058 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
1059 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
1060 mWindowManagerFuncs.shutdown(behavior == LONG_PRESS_POWER_SHUT_OFF);
1065 private void sleepPress(KeyEvent event) {
1066 switch (mShortPressOnSleepBehavior) {
1067 case SHORT_PRESS_SLEEP_GO_TO_SLEEP:
1068 mPowerManager.goToSleep(event.getEventTime(),
1069 PowerManager.GO_TO_SLEEP_REASON_SLEEP_BUTTON, 0);
1071 case SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME:
1072 launchHomeFromHotKey(false /* awakenDreams */, true /*respectKeyguard*/);
1073 mPowerManager.goToSleep(event.getEventTime(),
1074 PowerManager.GO_TO_SLEEP_REASON_SLEEP_BUTTON, 0);
1079 private int getResolvedLongPressOnPowerBehavior() {
1080 if (FactoryTest.isLongPressOnPowerOffEnabled()) {
1081 return LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM;
1083 return mLongPressOnPowerBehavior;
1086 private boolean hasLongPressOnPowerBehavior() {
1087 return getResolvedLongPressOnPowerBehavior() != LONG_PRESS_POWER_NOTHING;
1090 private void interceptScreenshotChord() {
1091 if (mScreenshotChordEnabled
1092 && mScreenshotChordVolumeDownKeyTriggered && mScreenshotChordPowerKeyTriggered
1093 && !mScreenshotChordVolumeUpKeyTriggered) {
1094 final long now = SystemClock.uptimeMillis();
1095 if (now <= mScreenshotChordVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS
1096 && now <= mScreenshotChordPowerKeyTime
1097 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) {
1098 mScreenshotChordVolumeDownKeyConsumed = true;
1099 cancelPendingPowerKeyAction();
1101 mHandler.postDelayed(mScreenshotRunnable, getScreenshotChordLongPressDelay());
1106 private long getScreenshotChordLongPressDelay() {
1107 if (mKeyguardDelegate.isShowing()) {
1108 // Double the time it takes to take a screenshot from the keyguard
1109 return (long) (KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER *
1110 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
1112 return ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout();
1115 private void cancelPendingScreenshotChordAction() {
1116 mHandler.removeCallbacks(mScreenshotRunnable);
1119 private final Runnable mEndCallLongPress = new Runnable() {
1122 mEndCallKeyHandled = true;
1123 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
1124 performAuditoryFeedbackForAccessibilityIfNeed();
1126 showGlobalActionsInternal();
1130 private final Runnable mScreenshotRunnable = new Runnable() {
1138 public void showGlobalActions() {
1139 mHandler.removeMessages(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
1140 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
1143 void showGlobalActionsInternal() {
1144 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
1145 if (mGlobalActions == null) {
1146 mGlobalActions = new GlobalActions(mContext, mWindowManagerFuncs);
1148 final boolean keyguardShowing = isKeyguardShowingAndNotOccluded();
1149 mGlobalActions.showDialog(keyguardShowing, isDeviceProvisioned());
1150 if (keyguardShowing) {
1151 // since it took two seconds of long press to bring this up,
1152 // poke the wake lock so they have some time to see the dialog.
1153 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
1157 boolean isDeviceProvisioned() {
1158 return Settings.Global.getInt(
1159 mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0) != 0;
1162 boolean isUserSetupComplete() {
1163 return Settings.Secure.getIntForUser(mContext.getContentResolver(),
1164 Settings.Secure.USER_SETUP_COMPLETE, 0, UserHandle.USER_CURRENT) != 0;
1167 private void handleShortPressOnHome() {
1168 // If there's a dream running then use home to escape the dream
1169 // but don't actually go home.
1170 if (mDreamManagerInternal != null && mDreamManagerInternal.isDreaming()) {
1171 mDreamManagerInternal.stopDream(false /*immediate*/);
1176 launchHomeFromHotKey();
1179 private void handleLongPressOnHome() {
1180 if (mLongPressOnHomeBehavior != LONG_PRESS_HOME_NOTHING) {
1181 mHomeConsumed = true;
1182 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
1184 if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI) {
1186 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_ASSIST) {
1187 launchAssistAction();
1192 private void handleDoubleTapOnHome() {
1193 if (mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1194 mHomeConsumed = true;
1199 private final Runnable mHomeDoubleTapTimeoutRunnable = new Runnable() {
1202 if (mHomeDoubleTapPending) {
1203 mHomeDoubleTapPending = false;
1204 handleShortPressOnHome();
1209 private boolean isRoundWindow() {
1210 return mContext.getResources().getBoolean(com.android.internal.R.bool.config_windowIsRound)
1211 || (Build.HARDWARE.contains("goldfish")
1212 && SystemProperties.getBoolean(ViewRootImpl.PROPERTY_EMULATOR_CIRCULAR, false));
1215 /** {@inheritDoc} */
1217 public void init(Context context, IWindowManager windowManager,
1218 WindowManagerFuncs windowManagerFuncs) {
1220 mWindowManager = windowManager;
1221 mWindowManagerFuncs = windowManagerFuncs;
1222 mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class);
1223 mDreamManagerInternal = LocalServices.getService(DreamManagerInternal.class);
1225 // Init display burn-in protection
1226 boolean burnInProtectionEnabled = context.getResources().getBoolean(
1227 com.android.internal.R.bool.config_enableBurnInProtection);
1228 // Allow a system property to override this. Used by developer settings.
1229 boolean burnInProtectionDevMode =
1230 SystemProperties.getBoolean("persist.debug.force_burn_in", false);
1231 if (burnInProtectionEnabled || burnInProtectionDevMode) {
1232 final int minHorizontal;
1233 final int maxHorizontal;
1234 final int minVertical;
1235 final int maxVertical;
1236 final int maxRadius;
1237 if (burnInProtectionDevMode) {
1242 maxRadius = (isRoundWindow()) ? 6 : -1;
1244 Resources resources = context.getResources();
1245 minHorizontal = resources.getInteger(
1246 com.android.internal.R.integer.config_burnInProtectionMinHorizontalOffset);
1247 maxHorizontal = resources.getInteger(
1248 com.android.internal.R.integer.config_burnInProtectionMaxHorizontalOffset);
1249 minVertical = resources.getInteger(
1250 com.android.internal.R.integer.config_burnInProtectionMinVerticalOffset);
1251 maxVertical = resources.getInteger(
1252 com.android.internal.R.integer.config_burnInProtectionMaxVerticalOffset);
1253 maxRadius = resources.getInteger(
1254 com.android.internal.R.integer.config_burnInProtectionMaxRadius);
1256 mBurnInProtectionHelper = new BurnInProtectionHelper(
1257 context, minHorizontal, maxHorizontal, minVertical, maxVertical, maxRadius);
1260 mHandler = new PolicyHandler();
1261 mWakeGestureListener = new MyWakeGestureListener(mContext, mHandler);
1262 mOrientationListener = new MyOrientationListener(mContext, mHandler);
1264 mOrientationListener.setCurrentRotation(windowManager.getRotation());
1265 } catch (RemoteException ex) { }
1266 mSettingsObserver = new SettingsObserver(mHandler);
1267 mSettingsObserver.observe();
1268 mShortcutManager = new ShortcutManager(context);
1269 mUiMode = context.getResources().getInteger(
1270 com.android.internal.R.integer.config_defaultUiModeType);
1271 mHomeIntent = new Intent(Intent.ACTION_MAIN, null);
1272 mHomeIntent.addCategory(Intent.CATEGORY_HOME);
1273 mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1274 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
1275 mCarDockIntent = new Intent(Intent.ACTION_MAIN, null);
1276 mCarDockIntent.addCategory(Intent.CATEGORY_CAR_DOCK);
1277 mCarDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1278 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
1279 mDeskDockIntent = new Intent(Intent.ACTION_MAIN, null);
1280 mDeskDockIntent.addCategory(Intent.CATEGORY_DESK_DOCK);
1281 mDeskDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1282 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
1284 mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
1285 mBroadcastWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
1286 "PhoneWindowManager.mBroadcastWakeLock");
1287 mPowerKeyWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
1288 "PhoneWindowManager.mPowerKeyWakeLock");
1289 mEnableShiftMenuBugReports = "1".equals(SystemProperties.get("ro.debuggable"));
1290 mSupportAutoRotation = mContext.getResources().getBoolean(
1291 com.android.internal.R.bool.config_supportAutoRotation);
1292 mLidOpenRotation = readRotation(
1293 com.android.internal.R.integer.config_lidOpenRotation);
1294 mCarDockRotation = readRotation(
1295 com.android.internal.R.integer.config_carDockRotation);
1296 mDeskDockRotation = readRotation(
1297 com.android.internal.R.integer.config_deskDockRotation);
1298 mUndockedHdmiRotation = readRotation(
1299 com.android.internal.R.integer.config_undockedHdmiRotation);
1300 mCarDockEnablesAccelerometer = mContext.getResources().getBoolean(
1301 com.android.internal.R.bool.config_carDockEnablesAccelerometer);
1302 mDeskDockEnablesAccelerometer = mContext.getResources().getBoolean(
1303 com.android.internal.R.bool.config_deskDockEnablesAccelerometer);
1304 mLidKeyboardAccessibility = mContext.getResources().getInteger(
1305 com.android.internal.R.integer.config_lidKeyboardAccessibility);
1306 mLidNavigationAccessibility = mContext.getResources().getInteger(
1307 com.android.internal.R.integer.config_lidNavigationAccessibility);
1308 mLidControlsSleep = mContext.getResources().getBoolean(
1309 com.android.internal.R.bool.config_lidControlsSleep);
1310 mTranslucentDecorEnabled = mContext.getResources().getBoolean(
1311 com.android.internal.R.bool.config_enableTranslucentDecor);
1313 mAllowTheaterModeWakeFromKey = mContext.getResources().getBoolean(
1314 com.android.internal.R.bool.config_allowTheaterModeWakeFromKey);
1315 mAllowTheaterModeWakeFromPowerKey = mAllowTheaterModeWakeFromKey
1316 || mContext.getResources().getBoolean(
1317 com.android.internal.R.bool.config_allowTheaterModeWakeFromPowerKey);
1318 mAllowTheaterModeWakeFromMotion = mContext.getResources().getBoolean(
1319 com.android.internal.R.bool.config_allowTheaterModeWakeFromMotion);
1320 mAllowTheaterModeWakeFromMotionWhenNotDreaming = mContext.getResources().getBoolean(
1321 com.android.internal.R.bool.config_allowTheaterModeWakeFromMotionWhenNotDreaming);
1322 mAllowTheaterModeWakeFromCameraLens = mContext.getResources().getBoolean(
1323 com.android.internal.R.bool.config_allowTheaterModeWakeFromCameraLens);
1324 mAllowTheaterModeWakeFromLidSwitch = mContext.getResources().getBoolean(
1325 com.android.internal.R.bool.config_allowTheaterModeWakeFromLidSwitch);
1326 mAllowTheaterModeWakeFromWakeGesture = mContext.getResources().getBoolean(
1327 com.android.internal.R.bool.config_allowTheaterModeWakeFromGesture);
1329 mGoToSleepOnButtonPressTheaterMode = mContext.getResources().getBoolean(
1330 com.android.internal.R.bool.config_goToSleepOnButtonPressTheaterMode);
1332 mSupportLongPressPowerWhenNonInteractive = mContext.getResources().getBoolean(
1333 com.android.internal.R.bool.config_supportLongPressPowerWhenNonInteractive);
1335 mShortPressOnPowerBehavior = mContext.getResources().getInteger(
1336 com.android.internal.R.integer.config_shortPressOnPowerBehavior);
1337 mLongPressOnPowerBehavior = mContext.getResources().getInteger(
1338 com.android.internal.R.integer.config_longPressOnPowerBehavior);
1339 mDoublePressOnPowerBehavior = mContext.getResources().getInteger(
1340 com.android.internal.R.integer.config_doublePressOnPowerBehavior);
1341 mTriplePressOnPowerBehavior = mContext.getResources().getInteger(
1342 com.android.internal.R.integer.config_triplePressOnPowerBehavior);
1343 mShortPressOnSleepBehavior = mContext.getResources().getInteger(
1344 com.android.internal.R.integer.config_shortPressOnSleepBehavior);
1346 mUseTvRouting = AudioSystem.getPlatformType(mContext) == AudioSystem.PLATFORM_TELEVISION;
1348 readConfigurationDependentBehaviors();
1350 mAccessibilityManager = (AccessibilityManager) context.getSystemService(
1351 Context.ACCESSIBILITY_SERVICE);
1353 // register for dock events
1354 IntentFilter filter = new IntentFilter();
1355 filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE);
1356 filter.addAction(UiModeManager.ACTION_EXIT_CAR_MODE);
1357 filter.addAction(UiModeManager.ACTION_ENTER_DESK_MODE);
1358 filter.addAction(UiModeManager.ACTION_EXIT_DESK_MODE);
1359 filter.addAction(Intent.ACTION_DOCK_EVENT);
1360 Intent intent = context.registerReceiver(mDockReceiver, filter);
1361 if (intent != null) {
1362 // Retrieve current sticky dock event broadcast.
1363 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
1364 Intent.EXTRA_DOCK_STATE_UNDOCKED);
1367 // register for dream-related broadcasts
1368 filter = new IntentFilter();
1369 filter.addAction(Intent.ACTION_DREAMING_STARTED);
1370 filter.addAction(Intent.ACTION_DREAMING_STOPPED);
1371 context.registerReceiver(mDreamReceiver, filter);
1373 // register for multiuser-relevant broadcasts
1374 filter = new IntentFilter(Intent.ACTION_USER_SWITCHED);
1375 context.registerReceiver(mMultiuserReceiver, filter);
1377 // monitor for system gestures
1378 mSystemGestures = new SystemGesturesPointerEventListener(context,
1379 new SystemGesturesPointerEventListener.Callbacks() {
1381 public void onSwipeFromTop() {
1382 if (mStatusBar != null) {
1383 requestTransientBars(mStatusBar);
1387 public void onSwipeFromBottom() {
1388 if (mNavigationBar != null && mNavigationBarOnBottom) {
1389 requestTransientBars(mNavigationBar);
1393 public void onSwipeFromRight() {
1394 if (mNavigationBar != null && !mNavigationBarOnBottom) {
1395 requestTransientBars(mNavigationBar);
1399 public void onDebug() {
1403 public void onDown() {
1404 mOrientationListener.onTouchStart();
1407 public void onUpOrCancel() {
1408 mOrientationListener.onTouchEnd();
1411 mImmersiveModeConfirmation = new ImmersiveModeConfirmation(mContext);
1412 mWindowManagerFuncs.registerPointerEventListener(mSystemGestures);
1414 mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
1415 mLongPressVibePattern = getLongIntArray(mContext.getResources(),
1416 com.android.internal.R.array.config_longPressVibePattern);
1417 mVirtualKeyVibePattern = getLongIntArray(mContext.getResources(),
1418 com.android.internal.R.array.config_virtualKeyVibePattern);
1419 mKeyboardTapVibePattern = getLongIntArray(mContext.getResources(),
1420 com.android.internal.R.array.config_keyboardTapVibePattern);
1421 mClockTickVibePattern = getLongIntArray(mContext.getResources(),
1422 com.android.internal.R.array.config_clockTickVibePattern);
1423 mCalendarDateVibePattern = getLongIntArray(mContext.getResources(),
1424 com.android.internal.R.array.config_calendarDateVibePattern);
1425 mSafeModeDisabledVibePattern = getLongIntArray(mContext.getResources(),
1426 com.android.internal.R.array.config_safeModeDisabledVibePattern);
1427 mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(),
1428 com.android.internal.R.array.config_safeModeEnabledVibePattern);
1430 mScreenshotChordEnabled = mContext.getResources().getBoolean(
1431 com.android.internal.R.bool.config_enableScreenshotChord);
1433 mGlobalKeyManager = new GlobalKeyManager(mContext);
1435 // Controls rotation and the like.
1436 initializeHdmiState();
1438 // Match current screen state.
1439 if (!mPowerManager.isInteractive()) {
1440 goingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
1443 mWindowManagerInternal.registerAppTransitionListener(
1444 mStatusBarController.getAppTransitionListener());
1448 * Read values from config.xml that may be overridden depending on
1449 * the configuration of the device.
1450 * eg. Disable long press on home goes to recents on sw600dp.
1452 private void readConfigurationDependentBehaviors() {
1453 mLongPressOnHomeBehavior = mContext.getResources().getInteger(
1454 com.android.internal.R.integer.config_longPressOnHomeBehavior);
1455 if (mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING ||
1456 mLongPressOnHomeBehavior > LONG_PRESS_HOME_ASSIST) {
1457 mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1460 mDoubleTapOnHomeBehavior = mContext.getResources().getInteger(
1461 com.android.internal.R.integer.config_doubleTapOnHomeBehavior);
1462 if (mDoubleTapOnHomeBehavior < DOUBLE_TAP_HOME_NOTHING ||
1463 mDoubleTapOnHomeBehavior > DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1464 mDoubleTapOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1469 public void setInitialDisplaySize(Display display, int width, int height, int density) {
1470 // This method might be called before the policy has been fully initialized
1471 // or for other displays we don't care about.
1472 if (mContext == null || display.getDisplayId() != Display.DEFAULT_DISPLAY) {
1477 final Resources res = mContext.getResources();
1478 int shortSize, longSize;
1479 if (width > height) {
1482 mLandscapeRotation = Surface.ROTATION_0;
1483 mSeascapeRotation = Surface.ROTATION_180;
1484 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
1485 mPortraitRotation = Surface.ROTATION_90;
1486 mUpsideDownRotation = Surface.ROTATION_270;
1488 mPortraitRotation = Surface.ROTATION_270;
1489 mUpsideDownRotation = Surface.ROTATION_90;
1494 mPortraitRotation = Surface.ROTATION_0;
1495 mUpsideDownRotation = Surface.ROTATION_180;
1496 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
1497 mLandscapeRotation = Surface.ROTATION_270;
1498 mSeascapeRotation = Surface.ROTATION_90;
1500 mLandscapeRotation = Surface.ROTATION_90;
1501 mSeascapeRotation = Surface.ROTATION_270;
1506 res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height);
1508 // Height of the navigation bar when presented horizontally at bottom
1509 mNavigationBarHeightForRotation[mPortraitRotation] =
1510 mNavigationBarHeightForRotation[mUpsideDownRotation] =
1511 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_height);
1512 mNavigationBarHeightForRotation[mLandscapeRotation] =
1513 mNavigationBarHeightForRotation[mSeascapeRotation] = res.getDimensionPixelSize(
1514 com.android.internal.R.dimen.navigation_bar_height_landscape);
1516 // Width of the navigation bar when presented vertically along one side
1517 mNavigationBarWidthForRotation[mPortraitRotation] =
1518 mNavigationBarWidthForRotation[mUpsideDownRotation] =
1519 mNavigationBarWidthForRotation[mLandscapeRotation] =
1520 mNavigationBarWidthForRotation[mSeascapeRotation] =
1521 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_width);
1523 // SystemUI (status bar) layout policy
1524 int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / density;
1525 int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / density;
1527 // Allow the navigation bar to move on non-square small devices (phones).
1528 mNavigationBarCanMove = width != height && shortSizeDp < 600;
1530 mHasNavigationBar = res.getBoolean(com.android.internal.R.bool.config_showNavigationBar);
1531 // Allow a system property to override this. Used by the emulator.
1532 // See also hasNavigationBar().
1533 String navBarOverride = SystemProperties.get("qemu.hw.mainkeys");
1534 if ("1".equals(navBarOverride)) {
1535 mHasNavigationBar = false;
1536 } else if ("0".equals(navBarOverride)) {
1537 mHasNavigationBar = true;
1540 // For demo purposes, allow the rotation of the HDMI display to be controlled.
1541 // By default, HDMI locks rotation to landscape.
1542 if ("portrait".equals(SystemProperties.get("persist.demo.hdmirotation"))) {
1543 mDemoHdmiRotation = mPortraitRotation;
1545 mDemoHdmiRotation = mLandscapeRotation;
1547 mDemoHdmiRotationLock = SystemProperties.getBoolean("persist.demo.hdmirotationlock", false);
1549 // For demo purposes, allow the rotation of the remote display to be controlled.
1550 // By default, remote display locks rotation to landscape.
1551 if ("portrait".equals(SystemProperties.get("persist.demo.remoterotation"))) {
1552 mDemoRotation = mPortraitRotation;
1554 mDemoRotation = mLandscapeRotation;
1556 mDemoRotationLock = SystemProperties.getBoolean(
1557 "persist.demo.rotationlock", false);
1559 // Only force the default orientation if the screen is xlarge, at least 960dp x 720dp, per
1560 // http://developer.android.com/guide/practices/screens_support.html#range
1561 mForceDefaultOrientation = longSizeDp >= 960 && shortSizeDp >= 720 &&
1562 res.getBoolean(com.android.internal.R.bool.config_forceDefaultOrientation) &&
1563 // For debug purposes the next line turns this feature off with:
1564 // $ adb shell setprop config.override_forced_orient true
1565 // $ adb shell wm size reset
1566 !"true".equals(SystemProperties.get("config.override_forced_orient"));
1570 * @return whether the navigation bar can be hidden, e.g. the device has a
1571 * navigation bar and touch exploration is not enabled
1573 private boolean canHideNavigationBar() {
1574 return mHasNavigationBar
1575 && !mAccessibilityManager.isTouchExplorationEnabled();
1579 public boolean isDefaultOrientationForced() {
1580 return mForceDefaultOrientation;
1584 public void setDisplayOverscan(Display display, int left, int top, int right, int bottom) {
1585 if (display.getDisplayId() == Display.DEFAULT_DISPLAY) {
1586 mOverscanLeft = left;
1588 mOverscanRight = right;
1589 mOverscanBottom = bottom;
1593 public void updateSettings() {
1594 ContentResolver resolver = mContext.getContentResolver();
1595 boolean updateRotation = false;
1596 synchronized (mLock) {
1597 mEndcallBehavior = Settings.System.getIntForUser(resolver,
1598 Settings.System.END_BUTTON_BEHAVIOR,
1599 Settings.System.END_BUTTON_BEHAVIOR_DEFAULT,
1600 UserHandle.USER_CURRENT);
1601 mIncallPowerBehavior = Settings.Secure.getIntForUser(resolver,
1602 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR,
1603 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT,
1604 UserHandle.USER_CURRENT);
1606 // Configure wake gesture.
1607 boolean wakeGestureEnabledSetting = Settings.Secure.getIntForUser(resolver,
1608 Settings.Secure.WAKE_GESTURE_ENABLED, 0,
1609 UserHandle.USER_CURRENT) != 0;
1610 if (mWakeGestureEnabledSetting != wakeGestureEnabledSetting) {
1611 mWakeGestureEnabledSetting = wakeGestureEnabledSetting;
1612 updateWakeGestureListenerLp();
1615 // Configure rotation lock.
1616 int userRotation = Settings.System.getIntForUser(resolver,
1617 Settings.System.USER_ROTATION, Surface.ROTATION_0,
1618 UserHandle.USER_CURRENT);
1619 if (mUserRotation != userRotation) {
1620 mUserRotation = userRotation;
1621 updateRotation = true;
1623 int userRotationMode = Settings.System.getIntForUser(resolver,
1624 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
1625 WindowManagerPolicy.USER_ROTATION_FREE :
1626 WindowManagerPolicy.USER_ROTATION_LOCKED;
1627 if (mUserRotationMode != userRotationMode) {
1628 mUserRotationMode = userRotationMode;
1629 updateRotation = true;
1630 updateOrientationListenerLp();
1634 int pointerLocation = Settings.System.getIntForUser(resolver,
1635 Settings.System.POINTER_LOCATION, 0, UserHandle.USER_CURRENT);
1636 if (mPointerLocationMode != pointerLocation) {
1637 mPointerLocationMode = pointerLocation;
1638 mHandler.sendEmptyMessage(pointerLocation != 0 ?
1639 MSG_ENABLE_POINTER_LOCATION : MSG_DISABLE_POINTER_LOCATION);
1642 // use screen off timeout setting as the timeout for the lockscreen
1643 mLockScreenTimeout = Settings.System.getIntForUser(resolver,
1644 Settings.System.SCREEN_OFF_TIMEOUT, 0, UserHandle.USER_CURRENT);
1645 String imId = Settings.Secure.getStringForUser(resolver,
1646 Settings.Secure.DEFAULT_INPUT_METHOD, UserHandle.USER_CURRENT);
1647 boolean hasSoftInput = imId != null && imId.length() > 0;
1648 if (mHasSoftInput != hasSoftInput) {
1649 mHasSoftInput = hasSoftInput;
1650 updateRotation = true;
1652 if (mImmersiveModeConfirmation != null) {
1653 mImmersiveModeConfirmation.loadSetting(mCurrentUserId);
1655 PolicyControl.reloadFromSetting(mContext);
1657 if (updateRotation) {
1658 updateRotation(true);
1662 private void updateWakeGestureListenerLp() {
1663 if (shouldEnableWakeGestureLp()) {
1664 mWakeGestureListener.requestWakeUpTrigger();
1666 mWakeGestureListener.cancelWakeUpTrigger();
1670 private boolean shouldEnableWakeGestureLp() {
1671 return mWakeGestureEnabledSetting && !mAwake
1672 && (!mLidControlsSleep || mLidState != LID_CLOSED)
1673 && mWakeGestureListener.isSupported();
1676 private void enablePointerLocation() {
1677 if (mPointerLocationView == null) {
1678 mPointerLocationView = new PointerLocationView(mContext);
1679 mPointerLocationView.setPrintCoords(false);
1680 WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
1681 WindowManager.LayoutParams.MATCH_PARENT,
1682 WindowManager.LayoutParams.MATCH_PARENT);
1683 lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY;
1684 lp.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN
1685 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
1686 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1687 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
1688 if (ActivityManager.isHighEndGfx()) {
1689 lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
1691 WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED;
1693 lp.format = PixelFormat.TRANSLUCENT;
1694 lp.setTitle("PointerLocation");
1695 WindowManager wm = (WindowManager)
1696 mContext.getSystemService(Context.WINDOW_SERVICE);
1697 lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL;
1698 wm.addView(mPointerLocationView, lp);
1699 mWindowManagerFuncs.registerPointerEventListener(mPointerLocationView);
1703 private void disablePointerLocation() {
1704 if (mPointerLocationView != null) {
1705 mWindowManagerFuncs.unregisterPointerEventListener(mPointerLocationView);
1706 WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
1707 wm.removeView(mPointerLocationView);
1708 mPointerLocationView = null;
1712 private int readRotation(int resID) {
1714 int rotation = mContext.getResources().getInteger(resID);
1717 return Surface.ROTATION_0;
1719 return Surface.ROTATION_90;
1721 return Surface.ROTATION_180;
1723 return Surface.ROTATION_270;
1725 } catch (Resources.NotFoundException e) {
1731 /** {@inheritDoc} */
1733 public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp) {
1734 int type = attrs.type;
1736 outAppOp[0] = AppOpsManager.OP_NONE;
1738 if (!((type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW)
1739 || (type >= FIRST_SUB_WINDOW && type <= LAST_SUB_WINDOW)
1740 || (type >= FIRST_SYSTEM_WINDOW && type <= LAST_SYSTEM_WINDOW))) {
1741 return WindowManagerGlobal.ADD_INVALID_TYPE;
1744 if (type < FIRST_SYSTEM_WINDOW || type > LAST_SYSTEM_WINDOW) {
1745 // Window manager will make sure these are okay.
1746 return WindowManagerGlobal.ADD_OKAY;
1748 String permission = null;
1751 // XXX right now the app process has complete control over
1752 // this... should introduce a token to let the system
1753 // monitor/control what they are doing.
1754 outAppOp[0] = AppOpsManager.OP_TOAST_WINDOW;
1757 case TYPE_INPUT_METHOD:
1758 case TYPE_WALLPAPER:
1759 case TYPE_PRIVATE_PRESENTATION:
1760 case TYPE_VOICE_INTERACTION:
1761 case TYPE_ACCESSIBILITY_OVERLAY:
1762 // The window manager will check these.
1765 case TYPE_PRIORITY_PHONE:
1766 case TYPE_SYSTEM_ALERT:
1767 case TYPE_SYSTEM_ERROR:
1768 case TYPE_SYSTEM_OVERLAY:
1769 permission = android.Manifest.permission.SYSTEM_ALERT_WINDOW;
1770 outAppOp[0] = AppOpsManager.OP_SYSTEM_ALERT_WINDOW;
1773 permission = android.Manifest.permission.INTERNAL_SYSTEM_WINDOW;
1775 if (permission != null) {
1776 if (mContext.checkCallingOrSelfPermission(permission)
1777 != PackageManager.PERMISSION_GRANTED) {
1778 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
1781 return WindowManagerGlobal.ADD_OKAY;
1785 public boolean checkShowToOwnerOnly(WindowManager.LayoutParams attrs) {
1787 // If this switch statement is modified, modify the comment in the declarations of
1788 // the type in {@link WindowManager.LayoutParams} as well.
1789 switch (attrs.type) {
1791 // These are the windows that by default are shown only to the user that created
1792 // them. If this needs to be overridden, set
1793 // {@link WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS} in
1794 // {@link WindowManager.LayoutParams}. Note that permission
1795 // {@link android.Manifest.permission.INTERNAL_SYSTEM_WINDOW} is required as well.
1796 if ((attrs.privateFlags & PRIVATE_FLAG_SHOW_FOR_ALL_USERS) == 0) {
1801 // These are the windows that by default are shown to all users. However, to
1802 // protect against spoofing, check permissions below.
1803 case TYPE_APPLICATION_STARTING:
1804 case TYPE_BOOT_PROGRESS:
1805 case TYPE_DISPLAY_OVERLAY:
1806 case TYPE_HIDDEN_NAV_CONSUMER:
1807 case TYPE_KEYGUARD_SCRIM:
1808 case TYPE_KEYGUARD_DIALOG:
1809 case TYPE_MAGNIFICATION_OVERLAY:
1810 case TYPE_NAVIGATION_BAR:
1811 case TYPE_NAVIGATION_BAR_PANEL:
1814 case TYPE_PRIORITY_PHONE:
1815 case TYPE_SEARCH_BAR:
1816 case TYPE_STATUS_BAR:
1817 case TYPE_STATUS_BAR_PANEL:
1818 case TYPE_STATUS_BAR_SUB_PANEL:
1819 case TYPE_SYSTEM_DIALOG:
1820 case TYPE_VOLUME_OVERLAY:
1821 case TYPE_PRIVATE_PRESENTATION:
1825 // Check if third party app has set window to system window type.
1826 return mContext.checkCallingOrSelfPermission(
1827 android.Manifest.permission.INTERNAL_SYSTEM_WINDOW)
1828 != PackageManager.PERMISSION_GRANTED;
1832 public void adjustWindowParamsLw(WindowManager.LayoutParams attrs) {
1833 switch (attrs.type) {
1834 case TYPE_SYSTEM_OVERLAY:
1835 case TYPE_SECURE_SYSTEM_OVERLAY:
1836 // These types of windows can't receive input events.
1837 attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1838 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
1839 attrs.flags &= ~WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
1841 case TYPE_STATUS_BAR:
1843 // If the Keyguard is in a hidden state (occluded by another window), we force to
1844 // remove the wallpaper and keyguard flag so that any change in-flight after setting
1845 // the keyguard as occluded wouldn't set these flags again.
1846 // See {@link #processKeyguardSetHiddenResultLw}.
1847 if (mKeyguardHidden) {
1848 attrs.flags &= ~WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
1849 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
1854 if (attrs.type != TYPE_STATUS_BAR) {
1855 // The status bar is the only window allowed to exhibit keyguard behavior.
1856 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
1859 if (ActivityManager.isHighEndGfx()
1860 && (attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0) {
1861 attrs.subtreeSystemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
1862 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
1866 void readLidState() {
1867 mLidState = mWindowManagerFuncs.getLidState();
1870 private void readCameraLensCoverState() {
1871 mCameraLensCoverState = mWindowManagerFuncs.getCameraLensCoverState();
1874 private boolean isHidden(int accessibilityMode) {
1875 switch (accessibilityMode) {
1877 return mLidState == LID_CLOSED;
1879 return mLidState == LID_OPEN;
1885 /** {@inheritDoc} */
1887 public void adjustConfigurationLw(Configuration config, int keyboardPresence,
1888 int navigationPresence) {
1889 mHaveBuiltInKeyboard = (keyboardPresence & PRESENCE_INTERNAL) != 0;
1891 readConfigurationDependentBehaviors();
1893 applyLidSwitchState();
1895 if (config.keyboard == Configuration.KEYBOARD_NOKEYS
1896 || (keyboardPresence == PRESENCE_INTERNAL
1897 && isHidden(mLidKeyboardAccessibility))) {
1898 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_YES;
1899 if (!mHasSoftInput) {
1900 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_YES;
1904 if (config.navigation == Configuration.NAVIGATION_NONAV
1905 || (navigationPresence == PRESENCE_INTERNAL
1906 && isHidden(mLidNavigationAccessibility))) {
1907 config.navigationHidden = Configuration.NAVIGATIONHIDDEN_YES;
1911 /** {@inheritDoc} */
1913 public int windowTypeToLayerLw(int type) {
1914 if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) {
1918 case TYPE_PRIVATE_PRESENTATION:
1920 case TYPE_WALLPAPER:
1921 // wallpaper is at the bottom, though the window manager may move it.
1925 case TYPE_SEARCH_BAR:
1926 case TYPE_VOICE_INTERACTION_STARTING:
1928 case TYPE_VOICE_INTERACTION:
1929 // voice interaction layer is almost immediately above apps.
1931 case TYPE_SYSTEM_DIALOG:
1934 // toasts and the plugged-in battery thing
1936 case TYPE_PRIORITY_PHONE:
1937 // SIM errors and unlock. Not sure if this really should be in a high layer.
1940 // used for Dreams (screensavers with TYPE_DREAM windows)
1942 case TYPE_SYSTEM_ALERT:
1943 // like the ANR / app crashed dialogs
1945 case TYPE_INPUT_METHOD:
1946 // on-screen keyboards and other such input method user interfaces go here.
1948 case TYPE_INPUT_METHOD_DIALOG:
1949 // on-screen keyboards and other such input method user interfaces go here.
1951 case TYPE_KEYGUARD_SCRIM:
1952 // the safety window that shows behind keyguard while keyguard is starting
1954 case TYPE_STATUS_BAR_SUB_PANEL:
1956 case TYPE_STATUS_BAR:
1958 case TYPE_STATUS_BAR_PANEL:
1960 case TYPE_KEYGUARD_DIALOG:
1962 case TYPE_VOLUME_OVERLAY:
1963 // the on-screen volume indicator and controller shown when the user
1964 // changes the device volume
1966 case TYPE_SYSTEM_OVERLAY:
1967 // the on-screen volume indicator and controller shown when the user
1968 // changes the device volume
1970 case TYPE_NAVIGATION_BAR:
1971 // the navigation bar, if available, shows atop most things
1973 case TYPE_NAVIGATION_BAR_PANEL:
1974 // some panels (e.g. search) need to show on top of the navigation bar
1976 case TYPE_SYSTEM_ERROR:
1977 // system-level error dialogs
1979 case TYPE_MAGNIFICATION_OVERLAY:
1980 // used to highlight the magnified portion of a display
1982 case TYPE_DISPLAY_OVERLAY:
1983 // used to simulate secondary display devices
1986 // the drag layer: input for drag-and-drop is associated with this window,
1987 // which sits above all other focusable windows
1989 case TYPE_ACCESSIBILITY_OVERLAY:
1990 // overlay put by accessibility services to intercept user interaction
1992 case TYPE_SECURE_SYSTEM_OVERLAY:
1994 case TYPE_BOOT_PROGRESS:
1997 // the (mouse) pointer layer
1999 case TYPE_HIDDEN_NAV_CONSUMER:
2002 Log.e(TAG, "Unknown window type: " + type);
2006 /** {@inheritDoc} */
2008 public int subWindowTypeToLayerLw(int type) {
2010 case TYPE_APPLICATION_PANEL:
2011 case TYPE_APPLICATION_ATTACHED_DIALOG:
2012 return APPLICATION_PANEL_SUBLAYER;
2013 case TYPE_APPLICATION_MEDIA:
2014 return APPLICATION_MEDIA_SUBLAYER;
2015 case TYPE_APPLICATION_MEDIA_OVERLAY:
2016 return APPLICATION_MEDIA_OVERLAY_SUBLAYER;
2017 case TYPE_APPLICATION_SUB_PANEL:
2018 return APPLICATION_SUB_PANEL_SUBLAYER;
2019 case TYPE_APPLICATION_ABOVE_SUB_PANEL:
2020 return APPLICATION_ABOVE_SUB_PANEL_SUBLAYER;
2022 Log.e(TAG, "Unknown sub-window type: " + type);
2027 public int getMaxWallpaperLayer() {
2028 return windowTypeToLayerLw(TYPE_STATUS_BAR);
2032 public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation) {
2033 if (mHasNavigationBar) {
2034 // For a basic navigation bar, when we are in landscape mode we place
2035 // the navigation bar to the side.
2036 if (mNavigationBarCanMove && fullWidth > fullHeight) {
2037 return fullWidth - mNavigationBarWidthForRotation[rotation];
2044 public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation) {
2045 if (mHasNavigationBar) {
2046 // For a basic navigation bar, when we are in portrait mode we place
2047 // the navigation bar to the bottom.
2048 if (!mNavigationBarCanMove || fullWidth < fullHeight) {
2049 return fullHeight - mNavigationBarHeightForRotation[rotation];
2056 public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation) {
2057 return getNonDecorDisplayWidth(fullWidth, fullHeight, rotation);
2061 public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation) {
2062 // There is a separate status bar at the top of the display. We don't count that as part
2063 // of the fixed decor, since it can hide; however, for purposes of configurations,
2064 // we do want to exclude it since applications can't generally use that part
2066 return getNonDecorDisplayHeight(fullWidth, fullHeight, rotation) - mStatusBarHeight;
2070 public boolean isForceHiding(WindowManager.LayoutParams attrs) {
2071 return (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 ||
2072 (isKeyguardHostWindow(attrs) &&
2073 (mKeyguardDelegate != null && mKeyguardDelegate.isShowing())) ||
2074 (attrs.type == TYPE_KEYGUARD_SCRIM);
2078 public boolean isKeyguardHostWindow(WindowManager.LayoutParams attrs) {
2079 return attrs.type == TYPE_STATUS_BAR;
2083 public boolean canBeForceHidden(WindowState win, WindowManager.LayoutParams attrs) {
2084 switch (attrs.type) {
2085 case TYPE_STATUS_BAR:
2086 case TYPE_NAVIGATION_BAR:
2087 case TYPE_WALLPAPER:
2089 case TYPE_KEYGUARD_SCRIM:
2097 public WindowState getWinShowWhenLockedLw() {
2098 return mWinShowWhenLocked;
2101 /** {@inheritDoc} */
2103 public View addStartingWindow(IBinder appToken, String packageName, int theme,
2104 CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes,
2105 int icon, int logo, int windowFlags) {
2106 if (!SHOW_STARTING_ANIMATIONS) {
2109 if (packageName == null) {
2113 WindowManager wm = null;
2117 Context context = mContext;
2118 if (DEBUG_STARTING_WINDOW) Slog.d(TAG, "addStartingWindow " + packageName
2119 + ": nonLocalizedLabel=" + nonLocalizedLabel + " theme="
2120 + Integer.toHexString(theme));
2121 if (theme != context.getThemeResId() || labelRes != 0) {
2123 context = context.createPackageContext(packageName, 0);
2124 context.setTheme(theme);
2125 } catch (PackageManager.NameNotFoundException e) {
2130 Window win = new PhoneWindow(context);
2131 final TypedArray ta = win.getWindowStyle();
2133 com.android.internal.R.styleable.Window_windowDisablePreview, false)
2135 com.android.internal.R.styleable.Window_windowShowWallpaper,false)) {
2139 Resources r = context.getResources();
2140 win.setTitle(r.getText(labelRes, nonLocalizedLabel));
2143 WindowManager.LayoutParams.TYPE_APPLICATION_STARTING);
2144 // Force the window flags: this is a fake window, so it is not really
2145 // touchable or focusable by the user. We also add in the ALT_FOCUSABLE_IM
2146 // flag because we do know that the next window will take input
2147 // focus, so we want to get the IME window up on top of us right away.
2150 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
2151 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
2152 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
2154 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
2155 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
2156 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
2158 win.setDefaultIcon(icon);
2159 win.setDefaultLogo(logo);
2161 win.setLayout(WindowManager.LayoutParams.MATCH_PARENT,
2162 WindowManager.LayoutParams.MATCH_PARENT);
2164 final WindowManager.LayoutParams params = win.getAttributes();
2165 params.token = appToken;
2166 params.packageName = packageName;
2167 params.windowAnimations = win.getWindowStyle().getResourceId(
2168 com.android.internal.R.styleable.Window_windowAnimationStyle, 0);
2169 params.privateFlags |=
2170 WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED;
2171 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
2173 if (!compatInfo.supportsScreen()) {
2174 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
2177 params.setTitle("Starting " + packageName);
2179 wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
2180 view = win.getDecorView();
2182 if (win.isFloating()) {
2183 // Whoops, there is no way to display an animation/preview
2184 // of such a thing! After all that work... let's skip it.
2185 // (Note that we must do this here because it is in
2186 // getDecorView() where the theme is evaluated... maybe
2187 // we should peek the floating attribute from the theme
2192 if (DEBUG_STARTING_WINDOW) Slog.d(
2193 TAG, "Adding starting window for " + packageName
2194 + " / " + appToken + ": "
2195 + (view.getParent() != null ? view : null));
2197 wm.addView(view, params);
2199 // Only return the view if it was successfully added to the
2200 // window manager... which we can tell by it having a parent.
2201 return view.getParent() != null ? view : null;
2202 } catch (WindowManager.BadTokenException e) {
2204 Log.w(TAG, appToken + " already running, starting window not displayed. " +
2206 } catch (RuntimeException e) {
2207 // don't crash if something else bad happens, for example a
2208 // failure loading resources because we are loading from an app
2209 // on external storage that has been unmounted.
2210 Log.w(TAG, appToken + " failed creating starting window", e);
2212 if (view != null && view.getParent() == null) {
2213 Log.w(TAG, "view not successfully added to wm, removing view");
2214 wm.removeViewImmediate(view);
2221 /** {@inheritDoc} */
2223 public void removeStartingWindow(IBinder appToken, View window) {
2224 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Removing starting window for " + appToken + ": "
2225 + window + " Callers=" + Debug.getCallers(4));
2227 if (window != null) {
2228 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
2229 wm.removeView(window);
2234 * Preflight adding a window to the system.
2236 * Currently enforces that three window types are singletons:
2238 * <li>STATUS_BAR_TYPE</li>
2239 * <li>KEYGUARD_TYPE</li>
2242 * @param win The window to be added
2243 * @param attrs Information about the window to be added
2245 * @return If ok, WindowManagerImpl.ADD_OKAY. If too many singletons,
2246 * WindowManagerImpl.ADD_MULTIPLE_SINGLETON
2249 public int prepareAddWindowLw(WindowState win, WindowManager.LayoutParams attrs) {
2250 switch (attrs.type) {
2251 case TYPE_STATUS_BAR:
2252 mContext.enforceCallingOrSelfPermission(
2253 android.Manifest.permission.STATUS_BAR_SERVICE,
2254 "PhoneWindowManager");
2255 if (mStatusBar != null) {
2256 if (mStatusBar.isAlive()) {
2257 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
2261 mStatusBarController.setWindow(win);
2263 case TYPE_NAVIGATION_BAR:
2264 mContext.enforceCallingOrSelfPermission(
2265 android.Manifest.permission.STATUS_BAR_SERVICE,
2266 "PhoneWindowManager");
2267 if (mNavigationBar != null) {
2268 if (mNavigationBar.isAlive()) {
2269 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
2272 mNavigationBar = win;
2273 mNavigationBarController.setWindow(win);
2274 if (DEBUG_LAYOUT) Slog.i(TAG, "NAVIGATION BAR: " + mNavigationBar);
2276 case TYPE_NAVIGATION_BAR_PANEL:
2277 case TYPE_STATUS_BAR_PANEL:
2278 case TYPE_STATUS_BAR_SUB_PANEL:
2279 case TYPE_VOICE_INTERACTION_STARTING:
2280 mContext.enforceCallingOrSelfPermission(
2281 android.Manifest.permission.STATUS_BAR_SERVICE,
2282 "PhoneWindowManager");
2284 case TYPE_KEYGUARD_SCRIM:
2285 if (mKeyguardScrim != null) {
2286 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
2288 mKeyguardScrim = win;
2291 return WindowManagerGlobal.ADD_OKAY;
2294 /** {@inheritDoc} */
2296 public void removeWindowLw(WindowState win) {
2297 if (mStatusBar == win) {
2299 mStatusBarController.setWindow(null);
2300 mKeyguardDelegate.showScrim();
2301 } else if (mKeyguardScrim == win) {
2302 Log.v(TAG, "Removing keyguard scrim");
2303 mKeyguardScrim = null;
2304 } if (mNavigationBar == win) {
2305 mNavigationBar = null;
2306 mNavigationBarController.setWindow(null);
2310 static final boolean PRINT_ANIM = false;
2312 /** {@inheritDoc} */
2314 public int selectAnimationLw(WindowState win, int transit) {
2315 if (PRINT_ANIM) Log.i(TAG, "selectAnimation in " + win
2316 + ": transit=" + transit);
2317 if (win == mStatusBar) {
2318 boolean isKeyguard = (win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
2319 if (transit == TRANSIT_EXIT
2320 || transit == TRANSIT_HIDE) {
2321 return isKeyguard ? -1 : R.anim.dock_top_exit;
2322 } else if (transit == TRANSIT_ENTER
2323 || transit == TRANSIT_SHOW) {
2324 return isKeyguard ? -1 : R.anim.dock_top_enter;
2326 } else if (win == mNavigationBar) {
2327 // This can be on either the bottom or the right.
2328 if (mNavigationBarOnBottom) {
2329 if (transit == TRANSIT_EXIT
2330 || transit == TRANSIT_HIDE) {
2331 return R.anim.dock_bottom_exit;
2332 } else if (transit == TRANSIT_ENTER
2333 || transit == TRANSIT_SHOW) {
2334 return R.anim.dock_bottom_enter;
2337 if (transit == TRANSIT_EXIT
2338 || transit == TRANSIT_HIDE) {
2339 return R.anim.dock_right_exit;
2340 } else if (transit == TRANSIT_ENTER
2341 || transit == TRANSIT_SHOW) {
2342 return R.anim.dock_right_enter;
2347 if (transit == TRANSIT_PREVIEW_DONE) {
2348 if (win.hasAppShownWindows()) {
2349 if (PRINT_ANIM) Log.i(TAG, "**** STARTING EXIT");
2350 return com.android.internal.R.anim.app_starting_exit;
2352 } else if (win.getAttrs().type == TYPE_DREAM && mDreamingLockscreen
2353 && transit == TRANSIT_ENTER) {
2354 // Special case: we are animating in a dream, while the keyguard
2355 // is shown. We don't want an animation on the dream, because
2356 // we need it shown immediately with the keyguard animating away
2365 public void selectRotationAnimationLw(int anim[]) {
2366 if (PRINT_ANIM) Slog.i(TAG, "selectRotationAnimation mTopFullscreen="
2367 + mTopFullscreenOpaqueWindowState + " rotationAnimation="
2368 + (mTopFullscreenOpaqueWindowState == null ?
2369 "0" : mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation));
2370 if (mTopFullscreenOpaqueWindowState != null && mTopIsFullscreen) {
2371 switch (mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation) {
2372 case ROTATION_ANIMATION_CROSSFADE:
2373 anim[0] = R.anim.rotation_animation_xfade_exit;
2374 anim[1] = R.anim.rotation_animation_enter;
2376 case ROTATION_ANIMATION_JUMPCUT:
2377 anim[0] = R.anim.rotation_animation_jump_exit;
2378 anim[1] = R.anim.rotation_animation_enter;
2380 case ROTATION_ANIMATION_ROTATE:
2382 anim[0] = anim[1] = 0;
2386 anim[0] = anim[1] = 0;
2391 public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId,
2392 boolean forceDefault) {
2393 switch (exitAnimId) {
2394 case R.anim.rotation_animation_xfade_exit:
2395 case R.anim.rotation_animation_jump_exit:
2396 // These are the only cases that matter.
2400 int anim[] = new int[2];
2401 selectRotationAnimationLw(anim);
2402 return (exitAnimId == anim[0] && enterAnimId == anim[1]);
2409 public Animation createForceHideEnterAnimation(boolean onWallpaper,
2410 boolean goingToNotificationShade) {
2411 if (goingToNotificationShade) {
2412 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_behind_enter_fade_in);
2415 AnimationSet set = (AnimationSet) AnimationUtils.loadAnimation(mContext, onWallpaper ?
2416 R.anim.lock_screen_behind_enter_wallpaper :
2417 R.anim.lock_screen_behind_enter);
2419 // TODO: Use XML interpolators when we have log interpolators available in XML.
2420 final List<Animation> animations = set.getAnimations();
2421 for (int i = animations.size() - 1; i >= 0; --i) {
2422 animations.get(i).setInterpolator(mLogDecelerateInterpolator);
2430 public Animation createForceHideWallpaperExitAnimation(boolean goingToNotificationShade) {
2431 if (goingToNotificationShade) {
2434 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_wallpaper_exit);
2438 private static void awakenDreams() {
2439 IDreamManager dreamManager = getDreamManager();
2440 if (dreamManager != null) {
2442 dreamManager.awaken();
2443 } catch (RemoteException e) {
2444 // fine, stay asleep then
2449 static IDreamManager getDreamManager() {
2450 return IDreamManager.Stub.asInterface(
2451 ServiceManager.checkService(DreamService.DREAM_SERVICE));
2454 TelecomManager getTelecommService() {
2455 return (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE);
2458 static IAudioService getAudioService() {
2459 IAudioService audioService = IAudioService.Stub.asInterface(
2460 ServiceManager.checkService(Context.AUDIO_SERVICE));
2461 if (audioService == null) {
2462 Log.w(TAG, "Unable to find IAudioService interface.");
2464 return audioService;
2467 boolean keyguardOn() {
2468 return isKeyguardShowingAndNotOccluded() || inKeyguardRestrictedKeyInputMode();
2471 private static final int[] WINDOW_TYPES_WHERE_HOME_DOESNT_WORK = {
2472 WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
2473 WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
2476 /** {@inheritDoc} */
2478 public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) {
2479 final boolean keyguardOn = keyguardOn();
2480 final int keyCode = event.getKeyCode();
2481 final int repeatCount = event.getRepeatCount();
2482 final int metaState = event.getMetaState();
2483 final int flags = event.getFlags();
2484 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
2485 final boolean canceled = event.isCanceled();
2488 Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount="
2489 + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed
2490 + " canceled=" + canceled);
2493 // If we think we might have a volume down & power key chord on the way
2494 // but we're not sure, then tell the dispatcher to wait a little while and
2495 // try again later before dispatching.
2496 if (mScreenshotChordEnabled && (flags & KeyEvent.FLAG_FALLBACK) == 0) {
2497 if (mScreenshotChordVolumeDownKeyTriggered && !mScreenshotChordPowerKeyTriggered) {
2498 final long now = SystemClock.uptimeMillis();
2499 final long timeoutTime = mScreenshotChordVolumeDownKeyTime
2500 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS;
2501 if (now < timeoutTime) {
2502 return timeoutTime - now;
2505 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
2506 && mScreenshotChordVolumeDownKeyConsumed) {
2508 mScreenshotChordVolumeDownKeyConsumed = false;
2514 // Cancel any pending meta actions if we see any other keys being pressed between the down
2515 // of the meta key and its corresponding up.
2516 if (mPendingMetaAction && !KeyEvent.isMetaKey(keyCode)) {
2517 mPendingMetaAction = false;
2520 // First we always handle the home key here, so applications
2521 // can never break it, although if keyguard is on, we do let
2522 // it handle it, because that gives us the correct 5 second
2524 if (keyCode == KeyEvent.KEYCODE_HOME) {
2526 // If we have released the home key, and didn't do anything else
2527 // while it was pressed, then it is time to go home!
2529 cancelPreloadRecentApps();
2531 mHomePressed = false;
2532 if (mHomeConsumed) {
2533 mHomeConsumed = false;
2538 Log.i(TAG, "Ignoring HOME; event canceled.");
2542 // If an incoming call is ringing, HOME is totally disabled.
2543 // (The user is already on the InCallUI at this point,
2544 // and his ONLY options are to answer or reject the call.)
2545 TelecomManager telecomManager = getTelecommService();
2546 if (telecomManager != null && telecomManager.isRinging()) {
2547 Log.i(TAG, "Ignoring HOME; there's a ringing incoming call.");
2551 // Delay handling home if a double-tap is possible.
2552 if (mDoubleTapOnHomeBehavior != DOUBLE_TAP_HOME_NOTHING) {
2553 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); // just in case
2554 mHomeDoubleTapPending = true;
2555 mHandler.postDelayed(mHomeDoubleTapTimeoutRunnable,
2556 ViewConfiguration.getDoubleTapTimeout());
2560 handleShortPressOnHome();
2564 // If a system window has focus, then it doesn't make sense
2565 // right now to interact with applications.
2566 WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null;
2567 if (attrs != null) {
2568 final int type = attrs.type;
2569 if (type == WindowManager.LayoutParams.TYPE_KEYGUARD_SCRIM
2570 || type == WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG
2571 || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
2572 // the "app" is keyguard, so give it the key
2575 final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length;
2576 for (int i=0; i<typeCount; i++) {
2577 if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) {
2578 // don't do anything, but also don't pass it to the app
2584 // Remember that home is pressed and handle special actions.
2585 if (repeatCount == 0) {
2586 mHomePressed = true;
2587 if (mHomeDoubleTapPending) {
2588 mHomeDoubleTapPending = false;
2589 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable);
2590 handleDoubleTapOnHome();
2591 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI
2592 || mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
2593 preloadRecentApps();
2595 } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) {
2597 handleLongPressOnHome();
2601 } else if (keyCode == KeyEvent.KEYCODE_MENU) {
2602 // Hijack modified menu keys for debugging features
2603 final int chordBug = KeyEvent.META_SHIFT_ON;
2605 if (down && repeatCount == 0) {
2606 if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) {
2607 Intent intent = new Intent(Intent.ACTION_BUG_REPORT);
2608 mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT,
2609 null, null, null, 0, null, null);
2611 } else if (SHOW_PROCESSES_ON_ALT_MENU &&
2612 (metaState & KeyEvent.META_ALT_ON) == KeyEvent.META_ALT_ON) {
2613 Intent service = new Intent();
2614 service.setClassName(mContext, "com.android.server.LoadAverageService");
2615 ContentResolver res = mContext.getContentResolver();
2616 boolean shown = Settings.Global.getInt(
2617 res, Settings.Global.SHOW_PROCESSES, 0) != 0;
2619 mContext.startService(service);
2621 mContext.stopService(service);
2623 Settings.Global.putInt(
2624 res, Settings.Global.SHOW_PROCESSES, shown ? 0 : 1);
2628 } else if (keyCode == KeyEvent.KEYCODE_SEARCH) {
2630 if (repeatCount == 0) {
2631 mSearchKeyShortcutPending = true;
2632 mConsumeSearchKeyUp = false;
2635 mSearchKeyShortcutPending = false;
2636 if (mConsumeSearchKeyUp) {
2637 mConsumeSearchKeyUp = false;
2642 } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) {
2644 if (down && repeatCount == 0) {
2645 preloadRecentApps();
2651 } else if (keyCode == KeyEvent.KEYCODE_ASSIST) {
2653 if (repeatCount == 0) {
2654 mAssistKeyLongPressed = false;
2655 } else if (repeatCount == 1) {
2656 mAssistKeyLongPressed = true;
2658 launchAssistLongPressAction();
2662 if (mAssistKeyLongPressed) {
2663 mAssistKeyLongPressed = false;
2666 launchAssistAction();
2671 } else if (keyCode == KeyEvent.KEYCODE_VOICE_ASSIST) {
2675 voiceIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
2677 voiceIntent = new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
2678 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, true);
2680 startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
2682 } else if (keyCode == KeyEvent.KEYCODE_SYSRQ) {
2683 if (down && repeatCount == 0) {
2684 mHandler.post(mScreenshotRunnable);
2687 } else if (keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP
2688 || keyCode == KeyEvent.KEYCODE_BRIGHTNESS_DOWN) {
2690 int direction = keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP ? 1 : -1;
2692 // Disable autobrightness if it's on
2693 int auto = Settings.System.getIntForUser(
2694 mContext.getContentResolver(),
2695 Settings.System.SCREEN_BRIGHTNESS_MODE,
2696 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2697 UserHandle.USER_CURRENT_OR_SELF);
2699 Settings.System.putIntForUser(mContext.getContentResolver(),
2700 Settings.System.SCREEN_BRIGHTNESS_MODE,
2701 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2702 UserHandle.USER_CURRENT_OR_SELF);
2705 int min = mPowerManager.getMinimumScreenBrightnessSetting();
2706 int max = mPowerManager.getMaximumScreenBrightnessSetting();
2707 int step = (max - min + BRIGHTNESS_STEPS - 1) / BRIGHTNESS_STEPS * direction;
2708 int brightness = Settings.System.getIntForUser(mContext.getContentResolver(),
2709 Settings.System.SCREEN_BRIGHTNESS,
2710 mPowerManager.getDefaultScreenBrightnessSetting(),
2711 UserHandle.USER_CURRENT_OR_SELF);
2713 // Make sure we don't go beyond the limits.
2714 brightness = Math.min(max, brightness);
2715 brightness = Math.max(min, brightness);
2717 Settings.System.putIntForUser(mContext.getContentResolver(),
2718 Settings.System.SCREEN_BRIGHTNESS, brightness,
2719 UserHandle.USER_CURRENT_OR_SELF);
2720 startActivityAsUser(new Intent(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG),
2721 UserHandle.CURRENT_OR_SELF);
2724 } else if (KeyEvent.isMetaKey(keyCode)) {
2726 mPendingMetaAction = true;
2727 } else if (mPendingMetaAction) {
2728 launchAssistAction(Intent.EXTRA_ASSIST_INPUT_HINT_KEYBOARD);
2733 // Shortcuts are invoked through Search+key, so intercept those here
2734 // Any printing key that is chorded with Search should be consumed
2735 // even if no shortcut was invoked. This prevents text from being
2736 // inadvertently inserted when using a keyboard that has built-in macro
2737 // shortcut keys (that emit Search+x) and some of them are not registered.
2738 if (mSearchKeyShortcutPending) {
2739 final KeyCharacterMap kcm = event.getKeyCharacterMap();
2740 if (kcm.isPrintingKey(keyCode)) {
2741 mConsumeSearchKeyUp = true;
2742 mSearchKeyShortcutPending = false;
2743 if (down && repeatCount == 0 && !keyguardOn) {
2744 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState);
2745 if (shortcutIntent != null) {
2746 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2748 startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
2749 } catch (ActivityNotFoundException ex) {
2750 Slog.w(TAG, "Dropping shortcut key combination because "
2751 + "the activity to which it is registered was not found: "
2752 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode), ex);
2755 Slog.i(TAG, "Dropping unregistered shortcut key combination: "
2756 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode));
2763 // Invoke shortcuts using Meta.
2764 if (down && repeatCount == 0 && !keyguardOn
2765 && (metaState & KeyEvent.META_META_ON) != 0) {
2766 final KeyCharacterMap kcm = event.getKeyCharacterMap();
2767 if (kcm.isPrintingKey(keyCode)) {
2768 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode,
2769 metaState & ~(KeyEvent.META_META_ON
2770 | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON));
2771 if (shortcutIntent != null) {
2772 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2774 startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
2775 } catch (ActivityNotFoundException ex) {
2776 Slog.w(TAG, "Dropping shortcut key combination because "
2777 + "the activity to which it is registered was not found: "
2778 + "META+" + KeyEvent.keyCodeToString(keyCode), ex);
2785 // Handle application launch keys.
2786 if (down && repeatCount == 0 && !keyguardOn) {
2787 String category = sApplicationLaunchKeyCategories.get(keyCode);
2788 if (category != null) {
2789 Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category);
2790 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2792 startActivityAsUser(intent, UserHandle.CURRENT);
2793 } catch (ActivityNotFoundException ex) {
2794 Slog.w(TAG, "Dropping application launch key because "
2795 + "the activity to which it is registered was not found: "
2796 + "keyCode=" + keyCode + ", category=" + category, ex);
2802 // Display task switcher for ALT-TAB.
2803 if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_TAB) {
2804 if (mRecentAppsHeldModifiers == 0 && !keyguardOn) {
2805 final int shiftlessModifiers = event.getModifiers() & ~KeyEvent.META_SHIFT_MASK;
2806 if (KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_ALT_ON)) {
2807 mRecentAppsHeldModifiers = shiftlessModifiers;
2808 showRecentApps(true);
2812 } else if (!down && mRecentAppsHeldModifiers != 0
2813 && (metaState & mRecentAppsHeldModifiers) == 0) {
2814 mRecentAppsHeldModifiers = 0;
2815 hideRecentApps(true, false);
2818 // Handle keyboard language switching.
2819 if (down && repeatCount == 0
2820 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2821 || (keyCode == KeyEvent.KEYCODE_SPACE
2822 && (metaState & KeyEvent.META_CTRL_MASK) != 0))) {
2823 int direction = (metaState & KeyEvent.META_SHIFT_MASK) != 0 ? -1 : 1;
2824 mWindowManagerFuncs.switchKeyboardLayout(event.getDeviceId(), direction);
2827 if (mLanguageSwitchKeyPressed && !down
2828 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2829 || keyCode == KeyEvent.KEYCODE_SPACE)) {
2830 mLanguageSwitchKeyPressed = false;
2834 if (isValidGlobalKey(keyCode)
2835 && mGlobalKeyManager.handleGlobalKey(mContext, keyCode, event)) {
2839 // Reserve all the META modifier combos for system behavior
2840 if ((metaState & KeyEvent.META_META_ON) != 0) {
2844 // Let the application handle the key.
2848 /** {@inheritDoc} */
2850 public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) {
2851 // Note: This method is only called if the initial down was unhandled.
2853 Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction()
2854 + ", flags=" + event.getFlags()
2855 + ", keyCode=" + event.getKeyCode()
2856 + ", scanCode=" + event.getScanCode()
2857 + ", metaState=" + event.getMetaState()
2858 + ", repeatCount=" + event.getRepeatCount()
2859 + ", policyFlags=" + policyFlags);
2862 KeyEvent fallbackEvent = null;
2863 if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
2864 final KeyCharacterMap kcm = event.getKeyCharacterMap();
2865 final int keyCode = event.getKeyCode();
2866 final int metaState = event.getMetaState();
2867 final boolean initialDown = event.getAction() == KeyEvent.ACTION_DOWN
2868 && event.getRepeatCount() == 0;
2870 // Check for fallback actions specified by the key character map.
2871 final FallbackAction fallbackAction;
2873 fallbackAction = kcm.getFallbackAction(keyCode, metaState);
2875 fallbackAction = mFallbackActions.get(keyCode);
2878 if (fallbackAction != null) {
2880 Slog.d(TAG, "Fallback: keyCode=" + fallbackAction.keyCode
2881 + " metaState=" + Integer.toHexString(fallbackAction.metaState));
2884 final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK;
2885 fallbackEvent = KeyEvent.obtain(
2886 event.getDownTime(), event.getEventTime(),
2887 event.getAction(), fallbackAction.keyCode,
2888 event.getRepeatCount(), fallbackAction.metaState,
2889 event.getDeviceId(), event.getScanCode(),
2890 flags, event.getSource(), null);
2892 if (!interceptFallback(win, fallbackEvent, policyFlags)) {
2893 fallbackEvent.recycle();
2894 fallbackEvent = null;
2898 mFallbackActions.put(keyCode, fallbackAction);
2899 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2900 mFallbackActions.remove(keyCode);
2901 fallbackAction.recycle();
2907 if (fallbackEvent == null) {
2908 Slog.d(TAG, "No fallback.");
2910 Slog.d(TAG, "Performing fallback: " + fallbackEvent);
2913 return fallbackEvent;
2916 private boolean interceptFallback(WindowState win, KeyEvent fallbackEvent, int policyFlags) {
2917 int actions = interceptKeyBeforeQueueing(fallbackEvent, policyFlags);
2918 if ((actions & ACTION_PASS_TO_USER) != 0) {
2919 long delayMillis = interceptKeyBeforeDispatching(
2920 win, fallbackEvent, policyFlags);
2921 if (delayMillis == 0) {
2928 private void launchAssistLongPressAction() {
2929 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
2930 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
2932 // launch the search activity
2933 Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS);
2934 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2936 // TODO: This only stops the factory-installed search manager.
2937 // Need to formalize an API to handle others
2938 SearchManager searchManager = getSearchManager();
2939 if (searchManager != null) {
2940 searchManager.stopSearch();
2942 startActivityAsUser(intent, UserHandle.CURRENT);
2943 } catch (ActivityNotFoundException e) {
2944 Slog.w(TAG, "No activity to handle assist long press action.", e);
2948 private void launchAssistAction() {
2949 launchAssistAction(null);
2952 private void launchAssistAction(String hint) {
2953 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
2954 Intent intent = ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE))
2955 .getAssistIntent(mContext, true, UserHandle.USER_CURRENT);
2956 if (intent != null) {
2958 intent.putExtra(hint, true);
2960 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
2961 | Intent.FLAG_ACTIVITY_SINGLE_TOP
2962 | Intent.FLAG_ACTIVITY_CLEAR_TOP);
2964 startActivityAsUser(intent, UserHandle.CURRENT);
2965 } catch (ActivityNotFoundException e) {
2966 Slog.w(TAG, "No activity to handle assist action.", e);
2971 private void startActivityAsUser(Intent intent, UserHandle handle) {
2972 if (isUserSetupComplete()) {
2973 mContext.startActivityAsUser(intent, handle);
2975 Slog.i(TAG, "Not starting activity because user setup is in progress: " + intent);
2979 private SearchManager getSearchManager() {
2980 if (mSearchManager == null) {
2981 mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
2983 return mSearchManager;
2986 private void preloadRecentApps() {
2987 mPreloadedRecentApps = true;
2989 IStatusBarService statusbar = getStatusBarService();
2990 if (statusbar != null) {
2991 statusbar.preloadRecentApps();
2993 } catch (RemoteException e) {
2994 Slog.e(TAG, "RemoteException when preloading recent apps", e);
2995 // re-acquire status bar service next time it is needed.
2996 mStatusBarService = null;
3000 private void cancelPreloadRecentApps() {
3001 if (mPreloadedRecentApps) {
3002 mPreloadedRecentApps = false;
3004 IStatusBarService statusbar = getStatusBarService();
3005 if (statusbar != null) {
3006 statusbar.cancelPreloadRecentApps();
3008 } catch (RemoteException e) {
3009 Slog.e(TAG, "RemoteException when cancelling recent apps preload", e);
3010 // re-acquire status bar service next time it is needed.
3011 mStatusBarService = null;
3016 private void toggleRecentApps() {
3017 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
3019 IStatusBarService statusbar = getStatusBarService();
3020 if (statusbar != null) {
3021 statusbar.toggleRecentApps();
3023 } catch (RemoteException e) {
3024 Slog.e(TAG, "RemoteException when toggling recent apps", e);
3025 // re-acquire status bar service next time it is needed.
3026 mStatusBarService = null;
3031 public void showRecentApps() {
3032 mHandler.removeMessages(MSG_DISPATCH_SHOW_RECENTS);
3033 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_RECENTS);
3036 private void showRecentApps(boolean triggeredFromAltTab) {
3037 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
3039 IStatusBarService statusbar = getStatusBarService();
3040 if (statusbar != null) {
3041 statusbar.showRecentApps(triggeredFromAltTab);
3043 } catch (RemoteException e) {
3044 Slog.e(TAG, "RemoteException when showing recent apps", e);
3045 // re-acquire status bar service next time it is needed.
3046 mStatusBarService = null;
3050 private void hideRecentApps(boolean triggeredFromAltTab, boolean triggeredFromHome) {
3051 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
3053 IStatusBarService statusbar = getStatusBarService();
3054 if (statusbar != null) {
3055 statusbar.hideRecentApps(triggeredFromAltTab, triggeredFromHome);
3057 } catch (RemoteException e) {
3058 Slog.e(TAG, "RemoteException when closing recent apps", e);
3059 // re-acquire status bar service next time it is needed.
3060 mStatusBarService = null;
3064 void launchHomeFromHotKey() {
3065 launchHomeFromHotKey(true /* awakenFromDreams */, true /*respectKeyguard*/);
3069 * A home key -> launch home action was detected. Take the appropriate action
3070 * given the situation with the keyguard.
3072 void launchHomeFromHotKey(final boolean awakenFromDreams, final boolean respectKeyguard) {
3073 if (respectKeyguard) {
3074 if (isKeyguardShowingAndNotOccluded()) {
3075 // don't launch home if keyguard showing
3079 if (!mHideLockScreen && mKeyguardDelegate.isInputRestricted()) {
3080 // when in keyguard restricted mode, must first verify unlock
3081 // before launching home
3082 mKeyguardDelegate.verifyUnlock(new OnKeyguardExitResult() {
3084 public void onKeyguardExitResult(boolean success) {
3087 ActivityManagerNative.getDefault().stopAppSwitches();
3088 } catch (RemoteException e) {
3090 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3091 startDockOrHome(true /*fromHomeKey*/, awakenFromDreams);
3099 // no keyguard stuff to worry about, just launch home!
3101 ActivityManagerNative.getDefault().stopAppSwitches();
3102 } catch (RemoteException e) {
3104 if (mRecentsVisible) {
3105 // Hide Recents and notify it to launch Home
3106 if (awakenFromDreams) {
3109 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3110 hideRecentApps(false, true);
3112 // Otherwise, just launch Home
3113 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3114 startDockOrHome(true /*fromHomeKey*/, awakenFromDreams);
3118 private final Runnable mClearHideNavigationFlag = new Runnable() {
3121 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
3123 mForceClearedSystemUiFlags &=
3124 ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
3126 mWindowManagerFuncs.reevaluateStatusBarVisibility();
3131 * Input handler used while nav bar is hidden. Captures any touch on the screen,
3132 * to determine when the nav bar should be shown and prevent applications from
3133 * receiving those touches.
3135 final class HideNavInputEventReceiver extends InputEventReceiver {
3136 public HideNavInputEventReceiver(InputChannel inputChannel, Looper looper) {
3137 super(inputChannel, looper);
3141 public void onInputEvent(InputEvent event) {
3142 boolean handled = false;
3144 if (event instanceof MotionEvent
3145 && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
3146 final MotionEvent motionEvent = (MotionEvent)event;
3147 if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
3148 // When the user taps down, we re-show the nav bar.
3149 boolean changed = false;
3150 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
3151 // Any user activity always causes us to show the
3152 // navigation controls, if they had been hidden.
3153 // We also clear the low profile and only content
3154 // flags so that tapping on the screen will atomically
3155 // restore all currently hidden screen decorations.
3156 int newVal = mResettingSystemUiFlags |
3157 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
3158 View.SYSTEM_UI_FLAG_LOW_PROFILE |
3159 View.SYSTEM_UI_FLAG_FULLSCREEN;
3160 if (mResettingSystemUiFlags != newVal) {
3161 mResettingSystemUiFlags = newVal;
3164 // We don't allow the system's nav bar to be hidden
3165 // again for 1 second, to prevent applications from
3166 // spamming us and keeping it from being shown.
3167 newVal = mForceClearedSystemUiFlags |
3168 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
3169 if (mForceClearedSystemUiFlags != newVal) {
3170 mForceClearedSystemUiFlags = newVal;
3172 mHandler.postDelayed(mClearHideNavigationFlag, 1000);
3176 mWindowManagerFuncs.reevaluateStatusBarVisibility();
3181 finishInputEvent(event, handled);
3185 final InputEventReceiver.Factory mHideNavInputEventReceiverFactory =
3186 new InputEventReceiver.Factory() {
3188 public InputEventReceiver createInputEventReceiver(
3189 InputChannel inputChannel, Looper looper) {
3190 return new HideNavInputEventReceiver(inputChannel, looper);
3195 public int adjustSystemUiVisibilityLw(int visibility) {
3196 mStatusBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
3197 mNavigationBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
3198 mRecentsVisible = (visibility & View.RECENT_APPS_VISIBLE) > 0;
3200 // Reset any bits in mForceClearingStatusBarVisibility that
3202 mResettingSystemUiFlags &= visibility;
3203 // Clear any bits in the new visibility that are currently being
3204 // force cleared, before reporting it.
3205 return visibility & ~mResettingSystemUiFlags
3206 & ~mForceClearedSystemUiFlags;
3210 public void getInsetHintLw(WindowManager.LayoutParams attrs, Rect outContentInsets,
3211 Rect outStableInsets) {
3212 final int fl = PolicyControl.getWindowFlags(null, attrs);
3213 final int sysuiVis = PolicyControl.getSystemUiVisibility(null, attrs);
3214 final int systemUiVisibility = (sysuiVis | attrs.subtreeSystemUiVisibility);
3216 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
3217 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
3218 int availRight, availBottom;
3219 if (canHideNavigationBar() &&
3220 (systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) {
3221 availRight = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3222 availBottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
3224 availRight = mRestrictedScreenLeft + mRestrictedScreenWidth;
3225 availBottom = mRestrictedScreenTop + mRestrictedScreenHeight;
3227 if ((systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
3228 if ((fl & FLAG_FULLSCREEN) != 0) {
3229 outContentInsets.set(mStableFullscreenLeft, mStableFullscreenTop,
3230 availRight - mStableFullscreenRight,
3231 availBottom - mStableFullscreenBottom);
3233 outContentInsets.set(mStableLeft, mStableTop,
3234 availRight - mStableRight, availBottom - mStableBottom);
3236 } else if ((fl & FLAG_FULLSCREEN) != 0 || (fl & FLAG_LAYOUT_IN_OVERSCAN) != 0) {
3237 outContentInsets.setEmpty();
3238 } else if ((systemUiVisibility & (View.SYSTEM_UI_FLAG_FULLSCREEN
3239 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)) == 0) {
3240 outContentInsets.set(mCurLeft, mCurTop,
3241 availRight - mCurRight, availBottom - mCurBottom);
3243 outContentInsets.set(mCurLeft, mCurTop,
3244 availRight - mCurRight, availBottom - mCurBottom);
3247 outStableInsets.set(mStableLeft, mStableTop,
3248 availRight - mStableRight, availBottom - mStableBottom);
3251 outContentInsets.setEmpty();
3252 outStableInsets.setEmpty();
3255 /** {@inheritDoc} */
3257 public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight,
3258 int displayRotation) {
3259 final int overscanLeft, overscanTop, overscanRight, overscanBottom;
3260 if (isDefaultDisplay) {
3261 switch (displayRotation) {
3262 case Surface.ROTATION_90:
3263 overscanLeft = mOverscanTop;
3264 overscanTop = mOverscanRight;
3265 overscanRight = mOverscanBottom;
3266 overscanBottom = mOverscanLeft;
3268 case Surface.ROTATION_180:
3269 overscanLeft = mOverscanRight;
3270 overscanTop = mOverscanBottom;
3271 overscanRight = mOverscanLeft;
3272 overscanBottom = mOverscanTop;
3274 case Surface.ROTATION_270:
3275 overscanLeft = mOverscanBottom;
3276 overscanTop = mOverscanLeft;
3277 overscanRight = mOverscanTop;
3278 overscanBottom = mOverscanRight;
3281 overscanLeft = mOverscanLeft;
3282 overscanTop = mOverscanTop;
3283 overscanRight = mOverscanRight;
3284 overscanBottom = mOverscanBottom;
3293 mOverscanScreenLeft = mRestrictedOverscanScreenLeft = 0;
3294 mOverscanScreenTop = mRestrictedOverscanScreenTop = 0;
3295 mOverscanScreenWidth = mRestrictedOverscanScreenWidth = displayWidth;
3296 mOverscanScreenHeight = mRestrictedOverscanScreenHeight = displayHeight;
3299 mSystemRight = displayWidth;
3300 mSystemBottom = displayHeight;
3301 mUnrestrictedScreenLeft = overscanLeft;
3302 mUnrestrictedScreenTop = overscanTop;
3303 mUnrestrictedScreenWidth = displayWidth - overscanLeft - overscanRight;
3304 mUnrestrictedScreenHeight = displayHeight - overscanTop - overscanBottom;
3305 mRestrictedScreenLeft = mUnrestrictedScreenLeft;
3306 mRestrictedScreenTop = mUnrestrictedScreenTop;
3307 mRestrictedScreenWidth = mSystemGestures.screenWidth = mUnrestrictedScreenWidth;
3308 mRestrictedScreenHeight = mSystemGestures.screenHeight = mUnrestrictedScreenHeight;
3309 mDockLeft = mContentLeft = mVoiceContentLeft = mStableLeft = mStableFullscreenLeft
3310 = mCurLeft = mUnrestrictedScreenLeft;
3311 mDockTop = mContentTop = mVoiceContentTop = mStableTop = mStableFullscreenTop
3312 = mCurTop = mUnrestrictedScreenTop;
3313 mDockRight = mContentRight = mVoiceContentRight = mStableRight = mStableFullscreenRight
3314 = mCurRight = displayWidth - overscanRight;
3315 mDockBottom = mContentBottom = mVoiceContentBottom = mStableBottom = mStableFullscreenBottom
3316 = mCurBottom = displayHeight - overscanBottom;
3317 mDockLayer = 0x10000000;
3318 mStatusBarLayer = -1;
3320 // start with the current dock rect, which will be (0,0,displayWidth,displayHeight)
3321 final Rect pf = mTmpParentFrame;
3322 final Rect df = mTmpDisplayFrame;
3323 final Rect of = mTmpOverscanFrame;
3324 final Rect vf = mTmpVisibleFrame;
3325 final Rect dcf = mTmpDecorFrame;
3326 pf.left = df.left = of.left = vf.left = mDockLeft;
3327 pf.top = df.top = of.top = vf.top = mDockTop;
3328 pf.right = df.right = of.right = vf.right = mDockRight;
3329 pf.bottom = df.bottom = of.bottom = vf.bottom = mDockBottom;
3330 dcf.setEmpty(); // Decor frame N/A for system bars.
3332 if (isDefaultDisplay) {
3333 // For purposes of putting out fake window up to steal focus, we will
3334 // drive nav being hidden only by whether it is requested.
3335 final int sysui = mLastSystemUiFlags;
3336 boolean navVisible = (sysui & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0;
3337 boolean navTranslucent = (sysui
3338 & (View.NAVIGATION_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0;
3339 boolean immersive = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
3340 boolean immersiveSticky = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
3341 boolean navAllowedHidden = immersive || immersiveSticky;
3342 navTranslucent &= !immersiveSticky; // transient trumps translucent
3343 boolean isKeyguardShowing = isStatusBarKeyguard() && !mHideLockScreen;
3344 if (!isKeyguardShowing) {
3345 navTranslucent &= areTranslucentBarsAllowed();
3348 // When the navigation bar isn't visible, we put up a fake
3349 // input window to catch all touch events. This way we can
3350 // detect when the user presses anywhere to bring back the nav
3351 // bar and ensure the application doesn't see the event.
3352 if (navVisible || navAllowedHidden) {
3353 if (mHideNavFakeWindow != null) {
3354 mHideNavFakeWindow.dismiss();
3355 mHideNavFakeWindow = null;
3357 } else if (mHideNavFakeWindow == null) {
3358 mHideNavFakeWindow = mWindowManagerFuncs.addFakeWindow(
3359 mHandler.getLooper(), mHideNavInputEventReceiverFactory,
3360 "hidden nav", WindowManager.LayoutParams.TYPE_HIDDEN_NAV_CONSUMER, 0,
3361 0, false, false, true);
3364 // For purposes of positioning and showing the nav bar, if we have
3365 // decided that it can't be hidden (because of the screen aspect ratio),
3366 // then take that into account.
3367 navVisible |= !canHideNavigationBar();
3369 boolean updateSysUiVisibility = false;
3370 if (mNavigationBar != null) {
3371 boolean transientNavBarShowing = mNavigationBarController.isTransientShowing();
3372 // Force the navigation bar to its appropriate place and
3373 // size. We need to do this directly, instead of relying on
3374 // it to bubble up from the nav bar, because this needs to
3375 // change atomically with screen rotations.
3376 mNavigationBarOnBottom = (!mNavigationBarCanMove || displayWidth < displayHeight);
3377 if (mNavigationBarOnBottom) {
3378 // It's a system nav bar or a portrait screen; nav bar goes on bottom.
3379 int top = displayHeight - overscanBottom
3380 - mNavigationBarHeightForRotation[displayRotation];
3381 mTmpNavigationFrame.set(0, top, displayWidth, displayHeight - overscanBottom);
3382 mStableBottom = mStableFullscreenBottom = mTmpNavigationFrame.top;
3383 if (transientNavBarShowing) {
3384 mNavigationBarController.setBarShowingLw(true);
3385 } else if (navVisible) {
3386 mNavigationBarController.setBarShowingLw(true);
3387 mDockBottom = mTmpNavigationFrame.top;
3388 mRestrictedScreenHeight = mDockBottom - mRestrictedScreenTop;
3389 mRestrictedOverscanScreenHeight = mDockBottom - mRestrictedOverscanScreenTop;
3391 // We currently want to hide the navigation UI.
3392 mNavigationBarController.setBarShowingLw(false);
3394 if (navVisible && !navTranslucent && !navAllowedHidden
3395 && !mNavigationBar.isAnimatingLw()
3396 && !mNavigationBarController.wasRecentlyTranslucent()) {
3397 // If the opaque nav bar is currently requested to be visible,
3398 // and not in the process of animating on or off, then
3399 // we can tell the app that it is covered by it.
3400 mSystemBottom = mTmpNavigationFrame.top;
3403 // Landscape screen; nav bar goes to the right.
3404 int left = displayWidth - overscanRight
3405 - mNavigationBarWidthForRotation[displayRotation];
3406 mTmpNavigationFrame.set(left, 0, displayWidth - overscanRight, displayHeight);
3407 mStableRight = mStableFullscreenRight = mTmpNavigationFrame.left;
3408 if (transientNavBarShowing) {
3409 mNavigationBarController.setBarShowingLw(true);
3410 } else if (navVisible) {
3411 mNavigationBarController.setBarShowingLw(true);
3412 mDockRight = mTmpNavigationFrame.left;
3413 mRestrictedScreenWidth = mDockRight - mRestrictedScreenLeft;
3414 mRestrictedOverscanScreenWidth = mDockRight - mRestrictedOverscanScreenLeft;
3416 // We currently want to hide the navigation UI.
3417 mNavigationBarController.setBarShowingLw(false);
3419 if (navVisible && !navTranslucent && !mNavigationBar.isAnimatingLw()
3420 && !mNavigationBarController.wasRecentlyTranslucent()) {
3421 // If the nav bar is currently requested to be visible,
3422 // and not in the process of animating on or off, then
3423 // we can tell the app that it is covered by it.
3424 mSystemRight = mTmpNavigationFrame.left;
3427 // Make sure the content and current rectangles are updated to
3428 // account for the restrictions from the navigation bar.
3429 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3430 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3431 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3432 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
3433 mStatusBarLayer = mNavigationBar.getSurfaceLayer();
3434 // And compute the final frame.
3435 mNavigationBar.computeFrameLw(mTmpNavigationFrame, mTmpNavigationFrame,
3436 mTmpNavigationFrame, mTmpNavigationFrame, mTmpNavigationFrame, dcf,
3437 mTmpNavigationFrame);
3438 if (DEBUG_LAYOUT) Slog.i(TAG, "mNavigationBar frame: " + mTmpNavigationFrame);
3439 if (mNavigationBarController.checkHiddenLw()) {
3440 updateSysUiVisibility = true;
3443 if (DEBUG_LAYOUT) Slog.i(TAG, String.format("mDock rect: (%d,%d - %d,%d)",
3444 mDockLeft, mDockTop, mDockRight, mDockBottom));
3446 // decide where the status bar goes ahead of time
3447 if (mStatusBar != null) {
3448 // apply any navigation bar insets
3449 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3450 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3451 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
3452 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight
3453 + mUnrestrictedScreenTop;
3454 vf.left = mStableLeft;
3455 vf.top = mStableTop;
3456 vf.right = mStableRight;
3457 vf.bottom = mStableBottom;
3459 mStatusBarLayer = mStatusBar.getSurfaceLayer();
3461 // Let the status bar determine its size.
3462 mStatusBar.computeFrameLw(pf, df, vf, vf, vf, dcf, vf);
3464 // For layout, the status bar is always at the top with our fixed height.
3465 mStableTop = mUnrestrictedScreenTop + mStatusBarHeight;
3467 boolean statusBarTransient = (sysui & View.STATUS_BAR_TRANSIENT) != 0;
3468 boolean statusBarTranslucent = (sysui
3469 & (View.STATUS_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0;
3470 if (!isKeyguardShowing) {
3471 statusBarTranslucent &= areTranslucentBarsAllowed();
3474 // If the status bar is hidden, we don't want to cause
3475 // windows behind it to scroll.
3476 if (mStatusBar.isVisibleLw() && !statusBarTransient) {
3477 // Status bar may go away, so the screen area it occupies
3478 // is available to apps but just covering them when the
3479 // status bar is visible.
3480 mDockTop = mUnrestrictedScreenTop + mStatusBarHeight;
3482 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3483 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3484 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3485 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
3487 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar: " +
3489 "dock=[%d,%d][%d,%d] content=[%d,%d][%d,%d] cur=[%d,%d][%d,%d]",
3490 mDockLeft, mDockTop, mDockRight, mDockBottom,
3491 mContentLeft, mContentTop, mContentRight, mContentBottom,
3492 mCurLeft, mCurTop, mCurRight, mCurBottom));
3494 if (mStatusBar.isVisibleLw() && !mStatusBar.isAnimatingLw()
3495 && !statusBarTransient && !statusBarTranslucent
3496 && !mStatusBarController.wasRecentlyTranslucent()) {
3497 // If the opaque status bar is currently requested to be visible,
3498 // and not in the process of animating on or off, then
3499 // we can tell the app that it is covered by it.
3500 mSystemTop = mUnrestrictedScreenTop + mStatusBarHeight;
3502 if (mStatusBarController.checkHiddenLw()) {
3503 updateSysUiVisibility = true;
3506 if (updateSysUiVisibility) {
3507 updateSystemUiVisibilityLw();
3512 /** {@inheritDoc} */
3514 public int getSystemDecorLayerLw() {
3515 if (mStatusBar != null && mStatusBar.isVisibleLw()) {
3516 return mStatusBar.getSurfaceLayer();
3519 if (mNavigationBar != null && mNavigationBar.isVisibleLw()) {
3520 return mNavigationBar.getSurfaceLayer();
3527 public void getContentRectLw(Rect r) {
3528 r.set(mContentLeft, mContentTop, mContentRight, mContentBottom);
3531 void setAttachedWindowFrames(WindowState win, int fl, int adjust, WindowState attached,
3532 boolean insetDecors, Rect pf, Rect df, Rect of, Rect cf, Rect vf) {
3533 if (win.getSurfaceLayer() > mDockLayer && attached.getSurfaceLayer() < mDockLayer) {
3534 // Here's a special case: if this attached window is a panel that is
3535 // above the dock window, and the window it is attached to is below
3536 // the dock window, then the frames we computed for the window it is
3537 // attached to can not be used because the dock is effectively part
3538 // of the underlying window and the attached window is floating on top
3539 // of the whole thing. So, we ignore the attached window and explicitly
3540 // compute the frames that would be appropriate without the dock.
3541 df.left = of.left = cf.left = vf.left = mDockLeft;
3542 df.top = of.top = cf.top = vf.top = mDockTop;
3543 df.right = of.right = cf.right = vf.right = mDockRight;
3544 df.bottom = of.bottom = cf.bottom = vf.bottom = mDockBottom;
3546 // The effective display frame of the attached window depends on
3547 // whether it is taking care of insetting its content. If not,
3548 // we need to use the parent's content frame so that the entire
3549 // window is positioned within that content. Otherwise we can use
3550 // the overscan frame and let the attached window take care of
3551 // positioning its content appropriately.
3552 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
3553 // Set the content frame of the attached window to the parent's decor frame
3554 // (same as content frame when IME isn't present) if specifically requested by
3555 // setting {@link WindowManager.LayoutParams#FLAG_LAYOUT_ATTACHED_IN_DECOR} flag.
3556 // Otherwise, use the overscan frame.
3557 cf.set((fl & FLAG_LAYOUT_ATTACHED_IN_DECOR) != 0
3558 ? attached.getContentFrameLw() : attached.getOverscanFrameLw());
3560 // If the window is resizing, then we want to base the content
3561 // frame on our attached content frame to resize... however,
3562 // things can be tricky if the attached window is NOT in resize
3563 // mode, in which case its content frame will be larger.
3564 // Ungh. So to deal with that, make sure the content frame
3565 // we end up using is not covering the IM dock.
3566 cf.set(attached.getContentFrameLw());
3567 if (attached.isVoiceInteraction()) {
3568 if (cf.left < mVoiceContentLeft) cf.left = mVoiceContentLeft;
3569 if (cf.top < mVoiceContentTop) cf.top = mVoiceContentTop;
3570 if (cf.right > mVoiceContentRight) cf.right = mVoiceContentRight;
3571 if (cf.bottom > mVoiceContentBottom) cf.bottom = mVoiceContentBottom;
3572 } else if (attached.getSurfaceLayer() < mDockLayer) {
3573 if (cf.left < mContentLeft) cf.left = mContentLeft;
3574 if (cf.top < mContentTop) cf.top = mContentTop;
3575 if (cf.right > mContentRight) cf.right = mContentRight;
3576 if (cf.bottom > mContentBottom) cf.bottom = mContentBottom;
3579 df.set(insetDecors ? attached.getDisplayFrameLw() : cf);
3580 of.set(insetDecors ? attached.getOverscanFrameLw() : cf);
3581 vf.set(attached.getVisibleFrameLw());
3583 // The LAYOUT_IN_SCREEN flag is used to determine whether the attached
3584 // window should be positioned relative to its parent or the entire
3586 pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0
3587 ? attached.getFrameLw() : df);
3590 private void applyStableConstraints(int sysui, int fl, Rect r) {
3591 if ((sysui & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
3592 // If app is requesting a stable layout, don't let the
3593 // content insets go below the stable values.
3594 if ((fl & FLAG_FULLSCREEN) != 0) {
3595 if (r.left < mStableFullscreenLeft) r.left = mStableFullscreenLeft;
3596 if (r.top < mStableFullscreenTop) r.top = mStableFullscreenTop;
3597 if (r.right > mStableFullscreenRight) r.right = mStableFullscreenRight;
3598 if (r.bottom > mStableFullscreenBottom) r.bottom = mStableFullscreenBottom;
3600 if (r.left < mStableLeft) r.left = mStableLeft;
3601 if (r.top < mStableTop) r.top = mStableTop;
3602 if (r.right > mStableRight) r.right = mStableRight;
3603 if (r.bottom > mStableBottom) r.bottom = mStableBottom;
3608 /** {@inheritDoc} */
3610 public void layoutWindowLw(WindowState win, WindowState attached) {
3611 // we've already done the status bar
3612 final WindowManager.LayoutParams attrs = win.getAttrs();
3613 if ((win == mStatusBar && (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) == 0) ||
3614 win == mNavigationBar) {
3617 final boolean isDefaultDisplay = win.isDefaultDisplay();
3618 final boolean needsToOffsetInputMethodTarget = isDefaultDisplay &&
3619 (win == mLastInputMethodTargetWindow && mLastInputMethodWindow != null);
3620 if (needsToOffsetInputMethodTarget) {
3621 if (DEBUG_LAYOUT) Slog.i(TAG, "Offset ime target window by the last ime window state");
3622 offsetInputMethodWindowLw(mLastInputMethodWindow);
3625 final int fl = PolicyControl.getWindowFlags(win, attrs);
3626 final int sim = attrs.softInputMode;
3627 final int sysUiFl = PolicyControl.getSystemUiVisibility(win, null);
3629 final Rect pf = mTmpParentFrame;
3630 final Rect df = mTmpDisplayFrame;
3631 final Rect of = mTmpOverscanFrame;
3632 final Rect cf = mTmpContentFrame;
3633 final Rect vf = mTmpVisibleFrame;
3634 final Rect dcf = mTmpDecorFrame;
3635 final Rect sf = mTmpStableFrame;
3638 final boolean hasNavBar = (isDefaultDisplay && mHasNavigationBar
3639 && mNavigationBar != null && mNavigationBar.isVisibleLw());
3641 final int adjust = sim & SOFT_INPUT_MASK_ADJUST;
3643 if (isDefaultDisplay) {
3644 sf.set(mStableLeft, mStableTop, mStableRight, mStableBottom);
3646 sf.set(mOverscanLeft, mOverscanTop, mOverscanRight, mOverscanBottom);
3649 if (!isDefaultDisplay) {
3650 if (attached != null) {
3651 // If this window is attached to another, our display
3652 // frame is the same as the one we are attached to.
3653 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
3655 // Give the window full screen.
3656 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3657 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3658 pf.right = df.right = of.right = cf.right
3659 = mOverscanScreenLeft + mOverscanScreenWidth;
3660 pf.bottom = df.bottom = of.bottom = cf.bottom
3661 = mOverscanScreenTop + mOverscanScreenHeight;
3663 } else if (attrs.type == TYPE_INPUT_METHOD) {
3664 pf.left = df.left = of.left = cf.left = vf.left = mDockLeft;
3665 pf.top = df.top = of.top = cf.top = vf.top = mDockTop;
3666 pf.right = df.right = of.right = cf.right = vf.right = mDockRight;
3667 // IM dock windows layout below the nav bar...
3668 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
3669 // ...with content insets above the nav bar
3670 cf.bottom = vf.bottom = mStableBottom;
3671 // IM dock windows always go to the bottom of the screen.
3672 attrs.gravity = Gravity.BOTTOM;
3673 mDockLayer = win.getSurfaceLayer();
3674 } else if (attrs.type == TYPE_VOICE_INTERACTION) {
3675 pf.left = df.left = of.left = cf.left = vf.left = mUnrestrictedScreenLeft;
3676 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3677 pf.right = df.right = of.right = cf.right = vf.right = mUnrestrictedScreenLeft
3678 + mUnrestrictedScreenWidth;
3679 pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop
3680 + mUnrestrictedScreenHeight;
3681 cf.bottom = vf.bottom = mStableBottom;
3682 cf.top = vf.top = mStableTop;
3683 } else if (win == mStatusBar && (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
3684 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3685 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3686 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
3687 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight + mUnrestrictedScreenTop;
3688 cf.left = vf.left = mStableLeft;
3689 cf.top = vf.top = mStableTop;
3690 cf.right = vf.right = mStableRight;
3691 vf.bottom = mStableBottom;
3692 cf.bottom = mContentBottom;
3695 // Default policy decor for the default display
3696 dcf.left = mSystemLeft;
3697 dcf.top = mSystemTop;
3698 dcf.right = mSystemRight;
3699 dcf.bottom = mSystemBottom;
3700 final boolean inheritTranslucentDecor = (attrs.privateFlags
3701 & WindowManager.LayoutParams.PRIVATE_FLAG_INHERIT_TRANSLUCENT_DECOR) != 0;
3702 final boolean isAppWindow =
3703 attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW &&
3704 attrs.type <= WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
3705 final boolean topAtRest =
3706 win == mTopFullscreenOpaqueWindowState && !win.isAnimatingLw();
3707 if (isAppWindow && !inheritTranslucentDecor && !topAtRest) {
3708 if ((sysUiFl & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0
3709 && (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0
3710 && (fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) == 0
3711 && (fl & WindowManager.LayoutParams.
3712 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
3713 // Ensure policy decor includes status bar
3714 dcf.top = mStableTop;
3716 if ((fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) == 0
3717 && (sysUiFl & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0
3718 && (fl & WindowManager.LayoutParams.
3719 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
3720 // Ensure policy decor includes navigation bar
3721 dcf.bottom = mStableBottom;
3722 dcf.right = mStableRight;
3726 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
3727 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
3728 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle()
3729 + "): IN_SCREEN, INSET_DECOR");
3730 // This is the case for a normal activity window: we want it
3731 // to cover all of the screen space, and it can take care of
3732 // moving its contents to account for screen decorations that
3733 // intrude into that space.
3734 if (attached != null) {
3735 // If this window is attached to another, our display
3736 // frame is the same as the one we are attached to.
3737 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
3739 if (attrs.type == TYPE_STATUS_BAR_PANEL
3740 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
3741 // Status bar panels are the only windows who can go on top of
3742 // the status bar. They are protected by the STATUS_BAR_SERVICE
3743 // permission, so they have the same privileges as the status
3746 // However, they should still dodge the navigation bar if it exists.
3748 pf.left = df.left = of.left = hasNavBar
3749 ? mDockLeft : mUnrestrictedScreenLeft;
3750 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3751 pf.right = df.right = of.right = hasNavBar
3752 ? mRestrictedScreenLeft+mRestrictedScreenWidth
3753 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3754 pf.bottom = df.bottom = of.bottom = hasNavBar
3755 ? mRestrictedScreenTop+mRestrictedScreenHeight
3756 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
3758 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
3759 "Laying out status bar window: (%d,%d - %d,%d)",
3760 pf.left, pf.top, pf.right, pf.bottom));
3761 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
3762 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3763 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3764 // Asking to layout into the overscan region, so give it that pure
3765 // unrestricted area.
3766 pf.left = df.left = of.left = mOverscanScreenLeft;
3767 pf.top = df.top = of.top = mOverscanScreenTop;
3768 pf.right = df.right = of.right = mOverscanScreenLeft + mOverscanScreenWidth;
3769 pf.bottom = df.bottom = of.bottom = mOverscanScreenTop
3770 + mOverscanScreenHeight;
3771 } else if (canHideNavigationBar()
3772 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
3773 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3774 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3775 // Asking for layout as if the nav bar is hidden, lets the
3776 // application extend into the unrestricted overscan screen area. We
3777 // only do this for application windows to ensure no window that
3778 // can be above the nav bar can do this.
3779 pf.left = df.left = mOverscanScreenLeft;
3780 pf.top = df.top = mOverscanScreenTop;
3781 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
3782 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
3783 // We need to tell the app about where the frame inside the overscan
3784 // is, so it can inset its content by that amount -- it didn't ask
3785 // to actually extend itself into the overscan region.
3786 of.left = mUnrestrictedScreenLeft;
3787 of.top = mUnrestrictedScreenTop;
3788 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3789 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
3791 pf.left = df.left = mRestrictedOverscanScreenLeft;
3792 pf.top = df.top = mRestrictedOverscanScreenTop;
3793 pf.right = df.right = mRestrictedOverscanScreenLeft
3794 + mRestrictedOverscanScreenWidth;
3795 pf.bottom = df.bottom = mRestrictedOverscanScreenTop
3796 + mRestrictedOverscanScreenHeight;
3797 // We need to tell the app about where the frame inside the overscan
3798 // is, so it can inset its content by that amount -- it didn't ask
3799 // to actually extend itself into the overscan region.
3800 of.left = mUnrestrictedScreenLeft;
3801 of.top = mUnrestrictedScreenTop;
3802 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3803 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
3806 if ((fl & FLAG_FULLSCREEN) == 0) {
3807 if (win.isVoiceInteraction()) {
3808 cf.left = mVoiceContentLeft;
3809 cf.top = mVoiceContentTop;
3810 cf.right = mVoiceContentRight;
3811 cf.bottom = mVoiceContentBottom;
3813 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
3814 cf.left = mDockLeft;
3816 cf.right = mDockRight;
3817 cf.bottom = mDockBottom;
3819 cf.left = mContentLeft;
3820 cf.top = mContentTop;
3821 cf.right = mContentRight;
3822 cf.bottom = mContentBottom;
3826 // Full screen windows are always given a layout that is as if the
3827 // status bar and other transient decors are gone. This is to avoid
3828 // bad states when moving from a window that is not hding the
3829 // status bar to one that is.
3830 cf.left = mRestrictedScreenLeft;
3831 cf.top = mRestrictedScreenTop;
3832 cf.right = mRestrictedScreenLeft + mRestrictedScreenWidth;
3833 cf.bottom = mRestrictedScreenTop + mRestrictedScreenHeight;
3835 applyStableConstraints(sysUiFl, fl, cf);
3836 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3839 vf.right = mCurRight;
3840 vf.bottom = mCurBottom;
3845 } else if ((fl & FLAG_LAYOUT_IN_SCREEN) != 0 || (sysUiFl
3846 & (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
3847 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)) != 0) {
3848 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3850 // A window that has requested to fill the entire screen just
3851 // gets everything, period.
3852 if (attrs.type == TYPE_STATUS_BAR_PANEL
3853 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
3854 pf.left = df.left = of.left = cf.left = hasNavBar
3855 ? mDockLeft : mUnrestrictedScreenLeft;
3856 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
3857 pf.right = df.right = of.right = cf.right = hasNavBar
3858 ? mRestrictedScreenLeft+mRestrictedScreenWidth
3859 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3860 pf.bottom = df.bottom = of.bottom = cf.bottom = hasNavBar
3861 ? mRestrictedScreenTop+mRestrictedScreenHeight
3862 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
3863 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
3864 "Laying out IN_SCREEN status bar window: (%d,%d - %d,%d)",
3865 pf.left, pf.top, pf.right, pf.bottom));
3866 } else if (attrs.type == TYPE_NAVIGATION_BAR
3867 || attrs.type == TYPE_NAVIGATION_BAR_PANEL) {
3868 // The navigation bar has Real Ultimate Power.
3869 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3870 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3871 pf.right = df.right = of.right = mUnrestrictedScreenLeft
3872 + mUnrestrictedScreenWidth;
3873 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop
3874 + mUnrestrictedScreenHeight;
3875 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
3876 "Laying out navigation bar window: (%d,%d - %d,%d)",
3877 pf.left, pf.top, pf.right, pf.bottom));
3878 } else if ((attrs.type == TYPE_SECURE_SYSTEM_OVERLAY
3879 || attrs.type == TYPE_BOOT_PROGRESS)
3880 && ((fl & FLAG_FULLSCREEN) != 0)) {
3881 // Fullscreen secure system overlays get what they ask for.
3882 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3883 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3884 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
3885 + mOverscanScreenWidth;
3886 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
3887 + mOverscanScreenHeight;
3888 } else if (attrs.type == TYPE_BOOT_PROGRESS) {
3889 // Boot progress screen always covers entire display.
3890 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3891 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3892 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
3893 + mOverscanScreenWidth;
3894 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
3895 + mOverscanScreenHeight;
3896 } else if (attrs.type == TYPE_WALLPAPER) {
3897 // The wallpaper also has Real Ultimate Power, but we want to tell
3898 // it about the overscan area.
3899 pf.left = df.left = mOverscanScreenLeft;
3900 pf.top = df.top = mOverscanScreenTop;
3901 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
3902 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
3903 of.left = cf.left = mUnrestrictedScreenLeft;
3904 of.top = cf.top = mUnrestrictedScreenTop;
3905 of.right = cf.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3906 of.bottom = cf.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
3907 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
3908 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3909 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3910 // Asking to layout into the overscan region, so give it that pure
3911 // unrestricted area.
3912 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3913 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3914 pf.right = df.right = of.right = cf.right
3915 = mOverscanScreenLeft + mOverscanScreenWidth;
3916 pf.bottom = df.bottom = of.bottom = cf.bottom
3917 = mOverscanScreenTop + mOverscanScreenHeight;
3918 } else if (canHideNavigationBar()
3919 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
3920 && (attrs.type == TYPE_STATUS_BAR
3921 || attrs.type == TYPE_TOAST
3922 || attrs.type == TYPE_VOICE_INTERACTION_STARTING
3923 || (attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3924 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW))) {
3925 // Asking for layout as if the nav bar is hidden, lets the
3926 // application extend into the unrestricted screen area. We
3927 // only do this for application windows (or toasts) to ensure no window that
3928 // can be above the nav bar can do this.
3929 // XXX This assumes that an app asking for this will also
3930 // ask for layout in only content. We can't currently figure out
3931 // what the screen would be if only laying out to hide the nav bar.
3932 pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft;
3933 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
3934 pf.right = df.right = of.right = cf.right = mUnrestrictedScreenLeft
3935 + mUnrestrictedScreenWidth;
3936 pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop
3937 + mUnrestrictedScreenHeight;
3939 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
3940 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
3941 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
3942 + mRestrictedScreenWidth;
3943 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
3944 + mRestrictedScreenHeight;
3947 applyStableConstraints(sysUiFl, fl, cf);
3949 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3952 vf.right = mCurRight;
3953 vf.bottom = mCurBottom;
3957 } else if (attached != null) {
3958 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3959 "): attached to " + attached);
3960 // A child window should be placed inside of the same visible
3961 // frame that its parent had.
3962 setAttachedWindowFrames(win, fl, adjust, attached, false, pf, df, of, cf, vf);
3964 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3965 "): normal window");
3966 // Otherwise, a normal window must be placed inside the content
3967 // of all screen decorations.
3968 if (attrs.type == TYPE_STATUS_BAR_PANEL) {
3969 // Status bar panels are the only windows who can go on top of
3970 // the status bar. They are protected by the STATUS_BAR_SERVICE
3971 // permission, so they have the same privileges as the status
3973 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
3974 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
3975 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
3976 + mRestrictedScreenWidth;
3977 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
3978 + mRestrictedScreenHeight;
3979 } else if (attrs.type == TYPE_TOAST || attrs.type == TYPE_SYSTEM_ALERT
3980 || attrs.type == TYPE_VOLUME_OVERLAY) {
3981 // These dialogs are stable to interim decor changes.
3982 pf.left = df.left = of.left = cf.left = mStableLeft;
3983 pf.top = df.top = of.top = cf.top = mStableTop;
3984 pf.right = df.right = of.right = cf.right = mStableRight;
3985 pf.bottom = df.bottom = of.bottom = cf.bottom = mStableBottom;
3987 pf.left = mContentLeft;
3988 pf.top = mContentTop;
3989 pf.right = mContentRight;
3990 pf.bottom = mContentBottom;
3991 if (win.isVoiceInteraction()) {
3992 df.left = of.left = cf.left = mVoiceContentLeft;
3993 df.top = of.top = cf.top = mVoiceContentTop;
3994 df.right = of.right = cf.right = mVoiceContentRight;
3995 df.bottom = of.bottom = cf.bottom = mVoiceContentBottom;
3996 } else if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
3997 df.left = of.left = cf.left = mDockLeft;
3998 df.top = of.top = cf.top = mDockTop;
3999 df.right = of.right = cf.right = mDockRight;
4000 df.bottom = of.bottom = cf.bottom = mDockBottom;
4002 df.left = of.left = cf.left = mContentLeft;
4003 df.top = of.top = cf.top = mContentTop;
4004 df.right = of.right = cf.right = mContentRight;
4005 df.bottom = of.bottom = cf.bottom = mContentBottom;
4007 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
4010 vf.right = mCurRight;
4011 vf.bottom = mCurBottom;
4019 // TYPE_SYSTEM_ERROR is above the NavigationBar so it can't be allowed to extend over it.
4020 if ((fl & FLAG_LAYOUT_NO_LIMITS) != 0 && attrs.type != TYPE_SYSTEM_ERROR) {
4021 df.left = df.top = -10000;
4022 df.right = df.bottom = 10000;
4023 if (attrs.type != TYPE_WALLPAPER) {
4024 of.left = of.top = cf.left = cf.top = vf.left = vf.top = -10000;
4025 of.right = of.bottom = cf.right = cf.bottom = vf.right = vf.bottom = 10000;
4029 if (DEBUG_LAYOUT) Slog.v(TAG, "Compute frame " + attrs.getTitle()
4030 + ": sim=#" + Integer.toHexString(sim)
4031 + " attach=" + attached + " type=" + attrs.type
4032 + String.format(" flags=0x%08x", fl)
4033 + " pf=" + pf.toShortString() + " df=" + df.toShortString()
4034 + " of=" + of.toShortString()
4035 + " cf=" + cf.toShortString() + " vf=" + vf.toShortString()
4036 + " dcf=" + dcf.toShortString()
4037 + " sf=" + sf.toShortString());
4039 win.computeFrameLw(pf, df, of, cf, vf, dcf, sf);
4041 // Dock windows carve out the bottom of the screen, so normal windows
4042 // can't appear underneath them.
4043 if (attrs.type == TYPE_INPUT_METHOD && win.isVisibleOrBehindKeyguardLw()
4044 && !win.getGivenInsetsPendingLw()) {
4045 setLastInputMethodWindowLw(null, null);
4046 offsetInputMethodWindowLw(win);
4048 if (attrs.type == TYPE_VOICE_INTERACTION && win.isVisibleOrBehindKeyguardLw()
4049 && !win.getGivenInsetsPendingLw()) {
4050 offsetVoiceInputWindowLw(win);
4054 private void offsetInputMethodWindowLw(WindowState win) {
4055 int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top);
4056 top += win.getGivenContentInsetsLw().top;
4057 if (mContentBottom > top) {
4058 mContentBottom = top;
4060 if (mVoiceContentBottom > top) {
4061 mVoiceContentBottom = top;
4063 top = win.getVisibleFrameLw().top;
4064 top += win.getGivenVisibleInsetsLw().top;
4065 if (mCurBottom > top) {
4068 if (DEBUG_LAYOUT) Slog.v(TAG, "Input method: mDockBottom="
4069 + mDockBottom + " mContentBottom="
4070 + mContentBottom + " mCurBottom=" + mCurBottom);
4073 private void offsetVoiceInputWindowLw(WindowState win) {
4074 int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top);
4075 top += win.getGivenContentInsetsLw().top;
4076 if (mVoiceContentBottom > top) {
4077 mVoiceContentBottom = top;
4081 /** {@inheritDoc} */
4083 public void finishLayoutLw() {
4087 /** {@inheritDoc} */
4089 public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) {
4090 mTopFullscreenOpaqueWindowState = null;
4091 mTopFullscreenOpaqueOrDimmingWindowState = null;
4092 mAppsToBeHidden.clear();
4093 mAppsThatDismissKeyguard.clear();
4094 mForceStatusBar = false;
4095 mForceStatusBarFromKeyguard = false;
4096 mForcingShowNavBar = false;
4097 mForcingShowNavBarLayer = -1;
4099 mHideLockScreen = false;
4100 mAllowLockscreenWhenOn = false;
4101 mDismissKeyguard = DISMISS_KEYGUARD_NONE;
4102 mShowingLockscreen = false;
4103 mShowingDream = false;
4104 mWinShowWhenLocked = null;
4105 mKeyguardSecure = isKeyguardSecure();
4106 mKeyguardSecureIncludingHidden = mKeyguardSecure
4107 && (mKeyguardDelegate != null && mKeyguardDelegate.isShowing());
4110 /** {@inheritDoc} */
4112 public void applyPostLayoutPolicyLw(WindowState win, WindowManager.LayoutParams attrs) {
4113 if (DEBUG_LAYOUT) Slog.i(TAG, "Win " + win + ": isVisibleOrBehindKeyguardLw="
4114 + win.isVisibleOrBehindKeyguardLw());
4115 final int fl = PolicyControl.getWindowFlags(win, attrs);
4116 if (mTopFullscreenOpaqueWindowState == null
4117 && win.isVisibleLw() && attrs.type == TYPE_INPUT_METHOD) {
4118 mForcingShowNavBar = true;
4119 mForcingShowNavBarLayer = win.getSurfaceLayer();
4121 if (attrs.type == TYPE_STATUS_BAR && (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
4122 mForceStatusBarFromKeyguard = true;
4124 if (mTopFullscreenOpaqueWindowState == null &&
4125 win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()) {
4126 if ((fl & FLAG_FORCE_NOT_FULLSCREEN) != 0) {
4127 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
4128 mForceStatusBarFromKeyguard = true;
4130 mForceStatusBar = true;
4133 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
4134 mShowingLockscreen = true;
4136 boolean appWindow = attrs.type >= FIRST_APPLICATION_WINDOW
4137 && attrs.type < FIRST_SYSTEM_WINDOW;
4138 if (attrs.type == TYPE_DREAM) {
4139 // If the lockscreen was showing when the dream started then wait
4140 // for the dream to draw before hiding the lockscreen.
4141 if (!mDreamingLockscreen
4142 || (win.isVisibleLw() && win.hasDrawnLw())) {
4143 mShowingDream = true;
4148 final boolean showWhenLocked = (fl & FLAG_SHOW_WHEN_LOCKED) != 0;
4149 final boolean dismissKeyguard = (fl & FLAG_DISMISS_KEYGUARD) != 0;
4151 final IApplicationToken appToken = win.getAppToken();
4152 if (showWhenLocked) {
4153 // Remove any previous windows with the same appToken.
4154 mAppsToBeHidden.remove(appToken);
4155 mAppsThatDismissKeyguard.remove(appToken);
4156 if (mAppsToBeHidden.isEmpty()) {
4157 if (dismissKeyguard && !mKeyguardSecure) {
4158 mAppsThatDismissKeyguard.add(appToken);
4160 mWinShowWhenLocked = win;
4161 mHideLockScreen = true;
4162 mForceStatusBarFromKeyguard = false;
4165 } else if (dismissKeyguard) {
4166 if (mKeyguardSecure) {
4167 mAppsToBeHidden.add(appToken);
4169 mAppsToBeHidden.remove(appToken);
4171 mAppsThatDismissKeyguard.add(appToken);
4173 mAppsToBeHidden.add(appToken);
4175 if (attrs.x == 0 && attrs.y == 0
4176 && attrs.width == WindowManager.LayoutParams.MATCH_PARENT
4177 && attrs.height == WindowManager.LayoutParams.MATCH_PARENT) {
4178 if (DEBUG_LAYOUT) Slog.v(TAG, "Fullscreen window: " + win);
4179 mTopFullscreenOpaqueWindowState = win;
4180 if (mTopFullscreenOpaqueOrDimmingWindowState == null) {
4181 mTopFullscreenOpaqueOrDimmingWindowState = win;
4183 if (!mAppsThatDismissKeyguard.isEmpty() &&
4184 mDismissKeyguard == DISMISS_KEYGUARD_NONE) {
4185 if (DEBUG_LAYOUT) Slog.v(TAG,
4186 "Setting mDismissKeyguard true by win " + win);
4187 mDismissKeyguard = mWinDismissingKeyguard == win ?
4188 DISMISS_KEYGUARD_CONTINUE : DISMISS_KEYGUARD_START;
4189 mWinDismissingKeyguard = win;
4190 mForceStatusBarFromKeyguard = mShowingLockscreen && mKeyguardSecure;
4191 } else if (mAppsToBeHidden.isEmpty() && showWhenLocked) {
4192 if (DEBUG_LAYOUT) Slog.v(TAG,
4193 "Setting mHideLockScreen to true by win " + win);
4194 mHideLockScreen = true;
4195 mForceStatusBarFromKeyguard = false;
4197 if ((fl & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) {
4198 mAllowLockscreenWhenOn = true;
4202 if (mWinShowWhenLocked != null &&
4203 mWinShowWhenLocked.getAppToken() != win.getAppToken()) {
4208 if (mTopFullscreenOpaqueOrDimmingWindowState == null
4209 && win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()
4210 && win.isDimming()) {
4211 mTopFullscreenOpaqueOrDimmingWindowState = win;
4215 /** {@inheritDoc} */
4217 public int finishPostLayoutPolicyLw() {
4218 if (mWinShowWhenLocked != null && mTopFullscreenOpaqueWindowState != null &&
4219 mWinShowWhenLocked.getAppToken() != mTopFullscreenOpaqueWindowState.getAppToken()
4220 && isKeyguardLocked()) {
4221 // A dialog is dismissing the keyguard. Put the wallpaper behind it and hide the
4222 // fullscreen window.
4223 // TODO: Make sure FLAG_SHOW_WALLPAPER is restored when dialog is dismissed. Or not.
4224 mWinShowWhenLocked.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
4225 mTopFullscreenOpaqueWindowState.hideLw(false);
4226 mTopFullscreenOpaqueWindowState = mWinShowWhenLocked;
4230 boolean topIsFullscreen = false;
4232 final WindowManager.LayoutParams lp = (mTopFullscreenOpaqueWindowState != null)
4233 ? mTopFullscreenOpaqueWindowState.getAttrs()
4236 // If we are not currently showing a dream then remember the current
4237 // lockscreen state. We will use this to determine whether the dream
4238 // started while the lockscreen was showing and remember this state
4239 // while the dream is showing.
4240 if (!mShowingDream) {
4241 mDreamingLockscreen = mShowingLockscreen;
4244 if (mStatusBar != null) {
4245 if (DEBUG_LAYOUT) Slog.i(TAG, "force=" + mForceStatusBar
4246 + " forcefkg=" + mForceStatusBarFromKeyguard
4247 + " top=" + mTopFullscreenOpaqueWindowState);
4248 if (mForceStatusBar || mForceStatusBarFromKeyguard) {
4249 if (DEBUG_LAYOUT) Slog.v(TAG, "Showing status bar: forced");
4250 if (mStatusBarController.setBarShowingLw(true)) {
4251 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4253 // Maintain fullscreen layout until incoming animation is complete.
4254 topIsFullscreen = mTopIsFullscreen && mStatusBar.isAnimatingLw();
4255 // Transient status bar on the lockscreen is not allowed
4256 if (mForceStatusBarFromKeyguard && mStatusBarController.isTransientShowing()) {
4257 mStatusBarController.updateVisibilityLw(false /*transientAllowed*/,
4258 mLastSystemUiFlags, mLastSystemUiFlags);
4260 } else if (mTopFullscreenOpaqueWindowState != null) {
4261 final int fl = PolicyControl.getWindowFlags(null, lp);
4263 Slog.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw()
4264 + " shown frame: " + mTopFullscreenOpaqueWindowState.getShownFrameLw());
4265 Slog.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs()
4266 + " lp.flags=0x" + Integer.toHexString(fl));
4268 topIsFullscreen = (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0
4269 || (mLastSystemUiFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
4270 // The subtle difference between the window for mTopFullscreenOpaqueWindowState
4271 // and mTopIsFullscreen is that mTopIsFullscreen is set only if the window
4272 // has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the
4274 if (mStatusBarController.isTransientShowing()) {
4275 if (mStatusBarController.setBarShowingLw(true)) {
4276 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4278 } else if (topIsFullscreen) {
4279 if (DEBUG_LAYOUT) Slog.v(TAG, "** HIDING status bar");
4280 if (mStatusBarController.setBarShowingLw(false)) {
4281 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4283 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar already hiding");
4286 if (DEBUG_LAYOUT) Slog.v(TAG, "** SHOWING status bar: top is not fullscreen");
4287 if (mStatusBarController.setBarShowingLw(true)) {
4288 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4294 if (mTopIsFullscreen != topIsFullscreen) {
4295 if (!topIsFullscreen) {
4296 // Force another layout when status bar becomes fully shown.
4297 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4299 mTopIsFullscreen = topIsFullscreen;
4302 // Hide the key guard if a visible window explicitly specifies that it wants to be
4303 // displayed when the screen is locked.
4304 if (mKeyguardDelegate != null && mStatusBar != null) {
4305 if (localLOGV) Slog.v(TAG, "finishPostLayoutPolicyLw: mHideKeyguard="
4307 if (mDismissKeyguard != DISMISS_KEYGUARD_NONE && !mKeyguardSecure) {
4308 mKeyguardHidden = true;
4309 if (setKeyguardOccludedLw(true)) {
4310 changes |= FINISH_LAYOUT_REDO_LAYOUT
4311 | FINISH_LAYOUT_REDO_CONFIG
4312 | FINISH_LAYOUT_REDO_WALLPAPER;
4314 if (mKeyguardDelegate.isShowing()) {
4315 mHandler.post(new Runnable() {
4318 mKeyguardDelegate.keyguardDone(false, false);
4322 } else if (mHideLockScreen) {
4323 mKeyguardHidden = true;
4324 if (setKeyguardOccludedLw(true)) {
4325 changes |= FINISH_LAYOUT_REDO_LAYOUT
4326 | FINISH_LAYOUT_REDO_CONFIG
4327 | FINISH_LAYOUT_REDO_WALLPAPER;
4329 } else if (mDismissKeyguard != DISMISS_KEYGUARD_NONE) {
4330 // This is the case of keyguard isSecure() and not mHideLockScreen.
4331 if (mDismissKeyguard == DISMISS_KEYGUARD_START) {
4332 // Only launch the next keyguard unlock window once per window.
4333 mKeyguardHidden = false;
4334 if (setKeyguardOccludedLw(false)) {
4335 changes |= FINISH_LAYOUT_REDO_LAYOUT
4336 | FINISH_LAYOUT_REDO_CONFIG
4337 | FINISH_LAYOUT_REDO_WALLPAPER;
4339 mHandler.post(new Runnable() {
4342 mKeyguardDelegate.dismiss();
4347 mWinDismissingKeyguard = null;
4348 mKeyguardHidden = false;
4349 if (setKeyguardOccludedLw(false)) {
4350 changes |= FINISH_LAYOUT_REDO_LAYOUT
4351 | FINISH_LAYOUT_REDO_CONFIG
4352 | FINISH_LAYOUT_REDO_WALLPAPER;
4357 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
4358 // If the navigation bar has been hidden or shown, we need to do another
4359 // layout pass to update that window.
4360 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4363 // update since mAllowLockscreenWhenOn might have changed
4364 updateLockScreenTimeout();
4369 * Updates the occluded state of the Keyguard.
4371 * @return Whether the flags have changed and we have to redo the layout.
4373 private boolean setKeyguardOccludedLw(boolean isOccluded) {
4374 boolean wasOccluded = mKeyguardOccluded;
4375 boolean showing = mKeyguardDelegate.isShowing();
4376 if (wasOccluded && !isOccluded && showing) {
4377 mKeyguardOccluded = false;
4378 mKeyguardDelegate.setOccluded(false);
4379 mStatusBar.getAttrs().privateFlags |= PRIVATE_FLAG_KEYGUARD;
4380 mStatusBar.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
4382 } else if (!wasOccluded && isOccluded && showing) {
4383 mKeyguardOccluded = true;
4384 mKeyguardDelegate.setOccluded(true);
4385 mStatusBar.getAttrs().privateFlags &= ~PRIVATE_FLAG_KEYGUARD;
4386 mStatusBar.getAttrs().flags &= ~FLAG_SHOW_WALLPAPER;
4393 private boolean isStatusBarKeyguard() {
4394 return mStatusBar != null
4395 && (mStatusBar.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
4399 public boolean allowAppAnimationsLw() {
4400 if (isStatusBarKeyguard() || mShowingDream) {
4401 // If keyguard or dreams is currently visible, no reason to animate behind it.
4408 public int focusChangedLw(WindowState lastFocus, WindowState newFocus) {
4409 mFocusedWindow = newFocus;
4410 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
4411 // If the navigation bar has been hidden or shown, we need to do another
4412 // layout pass to update that window.
4413 return FINISH_LAYOUT_REDO_LAYOUT;
4418 /** {@inheritDoc} */
4420 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
4421 // lid changed state
4422 final int newLidState = lidOpen ? LID_OPEN : LID_CLOSED;
4423 if (newLidState == mLidState) {
4427 mLidState = newLidState;
4428 applyLidSwitchState();
4429 updateRotation(true);
4432 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromLidSwitch);
4433 } else if (!mLidControlsSleep) {
4434 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
4439 public void notifyCameraLensCoverSwitchChanged(long whenNanos, boolean lensCovered) {
4440 int lensCoverState = lensCovered ? CAMERA_LENS_COVERED : CAMERA_LENS_UNCOVERED;
4441 if (mCameraLensCoverState == lensCoverState) {
4444 if (mCameraLensCoverState == CAMERA_LENS_COVERED &&
4445 lensCoverState == CAMERA_LENS_UNCOVERED) {
4447 final boolean keyguardActive = mKeyguardDelegate == null ? false :
4448 mKeyguardDelegate.isShowing();
4449 if (keyguardActive) {
4450 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE);
4452 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
4454 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromCameraLens);
4455 startActivityAsUser(intent, UserHandle.CURRENT_OR_SELF);
4457 mCameraLensCoverState = lensCoverState;
4460 void setHdmiPlugged(boolean plugged) {
4461 if (mHdmiPlugged != plugged) {
4462 mHdmiPlugged = plugged;
4463 updateRotation(true, true);
4464 Intent intent = new Intent(ACTION_HDMI_PLUGGED);
4465 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
4466 intent.putExtra(EXTRA_HDMI_PLUGGED_STATE, plugged);
4467 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
4471 void initializeHdmiState() {
4472 boolean plugged = false;
4473 // watch for HDMI plug messages if the hdmi switch exists
4474 if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) {
4475 mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi");
4477 final String filename = "/sys/class/switch/hdmi/state";
4478 FileReader reader = null;
4480 reader = new FileReader(filename);
4481 char[] buf = new char[15];
4482 int n = reader.read(buf);
4484 plugged = 0 != Integer.parseInt(new String(buf, 0, n-1));
4486 } catch (IOException ex) {
4487 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
4488 } catch (NumberFormatException ex) {
4489 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
4491 if (reader != null) {
4494 } catch (IOException ex) {
4499 // This dance forces the code in setHdmiPlugged to run.
4500 // Always do this so the sticky intent is stuck (to false) if there is no hdmi.
4501 mHdmiPlugged = !plugged;
4502 setHdmiPlugged(!mHdmiPlugged);
4505 final Object mScreenshotLock = new Object();
4506 ServiceConnection mScreenshotConnection = null;
4508 final Runnable mScreenshotTimeout = new Runnable() {
4509 @Override public void run() {
4510 synchronized (mScreenshotLock) {
4511 if (mScreenshotConnection != null) {
4512 mContext.unbindService(mScreenshotConnection);
4513 mScreenshotConnection = null;
4519 // Assume this is called from the Handler thread.
4520 private void takeScreenshot() {
4521 synchronized (mScreenshotLock) {
4522 if (mScreenshotConnection != null) {
4525 ComponentName cn = new ComponentName("com.android.systemui",
4526 "com.android.systemui.screenshot.TakeScreenshotService");
4527 Intent intent = new Intent();
4528 intent.setComponent(cn);
4529 ServiceConnection conn = new ServiceConnection() {
4531 public void onServiceConnected(ComponentName name, IBinder service) {
4532 synchronized (mScreenshotLock) {
4533 if (mScreenshotConnection != this) {
4536 Messenger messenger = new Messenger(service);
4537 Message msg = Message.obtain(null, 1);
4538 final ServiceConnection myConn = this;
4539 Handler h = new Handler(mHandler.getLooper()) {
4541 public void handleMessage(Message msg) {
4542 synchronized (mScreenshotLock) {
4543 if (mScreenshotConnection == myConn) {
4544 mContext.unbindService(mScreenshotConnection);
4545 mScreenshotConnection = null;
4546 mHandler.removeCallbacks(mScreenshotTimeout);
4551 msg.replyTo = new Messenger(h);
4552 msg.arg1 = msg.arg2 = 0;
4553 if (mStatusBar != null && mStatusBar.isVisibleLw())
4555 if (mNavigationBar != null && mNavigationBar.isVisibleLw())
4558 messenger.send(msg);
4559 } catch (RemoteException e) {
4564 public void onServiceDisconnected(ComponentName name) {}
4566 if (mContext.bindServiceAsUser(
4567 intent, conn, Context.BIND_AUTO_CREATE, UserHandle.CURRENT)) {
4568 mScreenshotConnection = conn;
4569 mHandler.postDelayed(mScreenshotTimeout, 10000);
4574 /** {@inheritDoc} */
4576 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) {
4577 if (!mSystemBooted) {
4578 // If we have not yet booted, don't let key events do anything.
4582 final boolean interactive = (policyFlags & FLAG_INTERACTIVE) != 0;
4583 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
4584 final boolean canceled = event.isCanceled();
4585 final int keyCode = event.getKeyCode();
4587 final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0;
4589 // If screen is off then we treat the case where the keyguard is open but hidden
4590 // the same as if it were open and in front.
4591 // This will prevent any keys other than the power button from waking the screen
4592 // when the keyguard is hidden by another activity.
4593 final boolean keyguardActive = (mKeyguardDelegate == null ? false :
4595 isKeyguardShowingAndNotOccluded() :
4596 mKeyguardDelegate.isShowing()));
4599 Log.d(TAG, "interceptKeyTq keycode=" + keyCode
4600 + " interactive=" + interactive + " keyguardActive=" + keyguardActive
4601 + " policyFlags=" + Integer.toHexString(policyFlags));
4604 // Basic policy based on interactive state.
4606 boolean isWakeKey = (policyFlags & WindowManagerPolicy.FLAG_WAKE) != 0
4607 || event.isWakeKey();
4608 if (interactive || (isInjected && !isWakeKey)) {
4609 // When the device is interactive or the key is injected pass the
4610 // key to the application.
4611 result = ACTION_PASS_TO_USER;
4613 } else if (!interactive && shouldDispatchInputWhenNonInteractive()) {
4614 // If we're currently dozing with the screen on and the keyguard showing, pass the key
4615 // to the application but preserve its wake key status to make sure we still move
4616 // from dozing to fully interactive if we would normally go from off to fully
4618 result = ACTION_PASS_TO_USER;
4620 // When the screen is off and the key is not injected, determine whether
4621 // to wake the device but don't pass the key to the application.
4623 if (isWakeKey && (!down || !isWakeKeyWhenScreenOff(keyCode))) {
4628 // If the key would be handled globally, just return the result, don't worry about special
4630 if (isValidGlobalKey(keyCode)
4631 && mGlobalKeyManager.shouldHandleGlobalKey(keyCode, event)) {
4633 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey);
4638 boolean useHapticFeedback = down
4639 && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0
4640 && event.getRepeatCount() == 0;
4642 // Handle special keys.
4644 case KeyEvent.KEYCODE_VOLUME_DOWN:
4645 case KeyEvent.KEYCODE_VOLUME_UP:
4646 case KeyEvent.KEYCODE_VOLUME_MUTE: {
4647 if (mUseTvRouting) {
4648 // On TVs volume keys never go to the foreground app
4649 result &= ~ACTION_PASS_TO_USER;
4651 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
4653 if (interactive && !mScreenshotChordVolumeDownKeyTriggered
4654 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
4655 mScreenshotChordVolumeDownKeyTriggered = true;
4656 mScreenshotChordVolumeDownKeyTime = event.getDownTime();
4657 mScreenshotChordVolumeDownKeyConsumed = false;
4658 cancelPendingPowerKeyAction();
4659 interceptScreenshotChord();
4662 mScreenshotChordVolumeDownKeyTriggered = false;
4663 cancelPendingScreenshotChordAction();
4665 } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
4667 if (interactive && !mScreenshotChordVolumeUpKeyTriggered
4668 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
4669 mScreenshotChordVolumeUpKeyTriggered = true;
4670 cancelPendingPowerKeyAction();
4671 cancelPendingScreenshotChordAction();
4674 mScreenshotChordVolumeUpKeyTriggered = false;
4675 cancelPendingScreenshotChordAction();
4679 TelecomManager telecomManager = getTelecommService();
4680 if (telecomManager != null) {
4681 if (telecomManager.isRinging()) {
4682 // If an incoming call is ringing, either VOLUME key means
4683 // "silence ringer". We handle these keys here, rather than
4684 // in the InCallScreen, to make sure we'll respond to them
4685 // even if the InCallScreen hasn't come to the foreground yet.
4686 // Look for the DOWN event here, to agree with the "fallback"
4687 // behavior in the InCallScreen.
4688 Log.i(TAG, "interceptKeyBeforeQueueing:"
4689 + " VOLUME key-down while ringing: Silence ringer!");
4691 // Silence the ringer. (It's safe to call this
4692 // even if the ringer has already been silenced.)
4693 telecomManager.silenceRinger();
4695 // And *don't* pass this key thru to the current activity
4696 // (which is probably the InCallScreen.)
4697 result &= ~ACTION_PASS_TO_USER;
4700 if (telecomManager.isInCall()
4701 && (result & ACTION_PASS_TO_USER) == 0) {
4702 // If we are in call but we decided not to pass the key to
4703 // the application, just pass it to the session service.
4705 MediaSessionLegacyHelper.getHelper(mContext)
4706 .sendVolumeKeyEvent(event, false);
4711 if ((result & ACTION_PASS_TO_USER) == 0) {
4712 if (mUseTvRouting) {
4713 dispatchDirectAudioEvent(event);
4715 // If we aren't passing to the user and no one else
4716 // handled it send it to the session manager to
4718 MediaSessionLegacyHelper.getHelper(mContext)
4719 .sendVolumeKeyEvent(event, true);
4727 case KeyEvent.KEYCODE_ENDCALL: {
4728 result &= ~ACTION_PASS_TO_USER;
4730 TelecomManager telecomManager = getTelecommService();
4731 boolean hungUp = false;
4732 if (telecomManager != null) {
4733 hungUp = telecomManager.endCall();
4735 if (interactive && !hungUp) {
4736 mEndCallKeyHandled = false;
4737 mHandler.postDelayed(mEndCallLongPress,
4738 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
4740 mEndCallKeyHandled = true;
4743 if (!mEndCallKeyHandled) {
4744 mHandler.removeCallbacks(mEndCallLongPress);
4746 if ((mEndcallBehavior
4747 & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) {
4752 if ((mEndcallBehavior
4753 & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) {
4754 mPowerManager.goToSleep(event.getEventTime(),
4755 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
4764 case KeyEvent.KEYCODE_POWER: {
4765 result &= ~ACTION_PASS_TO_USER;
4766 isWakeKey = false; // wake-up will be handled separately
4768 interceptPowerKeyDown(event, interactive);
4770 interceptPowerKeyUp(event, interactive, canceled);
4775 case KeyEvent.KEYCODE_SLEEP: {
4776 result &= ~ACTION_PASS_TO_USER;
4778 if (!mPowerManager.isInteractive()) {
4779 useHapticFeedback = false; // suppress feedback if already non-interactive
4785 case KeyEvent.KEYCODE_WAKEUP: {
4786 result &= ~ACTION_PASS_TO_USER;
4791 case KeyEvent.KEYCODE_MEDIA_PLAY:
4792 case KeyEvent.KEYCODE_MEDIA_PAUSE:
4793 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
4794 case KeyEvent.KEYCODE_HEADSETHOOK:
4795 case KeyEvent.KEYCODE_MUTE:
4796 case KeyEvent.KEYCODE_MEDIA_STOP:
4797 case KeyEvent.KEYCODE_MEDIA_NEXT:
4798 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
4799 case KeyEvent.KEYCODE_MEDIA_REWIND:
4800 case KeyEvent.KEYCODE_MEDIA_RECORD:
4801 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
4802 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: {
4803 if (MediaSessionLegacyHelper.getHelper(mContext).isGlobalPriorityActive()) {
4804 // If the global session is active pass all media keys to it
4805 // instead of the active window.
4806 result &= ~ACTION_PASS_TO_USER;
4808 if ((result & ACTION_PASS_TO_USER) == 0) {
4809 // Only do this if we would otherwise not pass it to the user. In that
4810 // case, the PhoneWindow class will do the same thing, except it will
4811 // only do it if the showing app doesn't process the key on its own.
4812 // Note that we need to make a copy of the key event here because the
4813 // original key event will be recycled when we return.
4814 mBroadcastWakeLock.acquire();
4815 Message msg = mHandler.obtainMessage(MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK,
4816 new KeyEvent(event));
4817 msg.setAsynchronous(true);
4823 case KeyEvent.KEYCODE_CALL: {
4825 TelecomManager telecomManager = getTelecommService();
4826 if (telecomManager != null) {
4827 if (telecomManager.isRinging()) {
4828 Log.i(TAG, "interceptKeyBeforeQueueing:"
4829 + " CALL key-down while ringing: Answer the call!");
4830 telecomManager.acceptRingingCall();
4832 // And *don't* pass this key thru to the current activity
4833 // (which is presumably the InCallScreen.)
4834 result &= ~ACTION_PASS_TO_USER;
4840 case KeyEvent.KEYCODE_VOICE_ASSIST: {
4841 // Only do this if we would otherwise not pass it to the user. In that case,
4842 // interceptKeyBeforeDispatching would apply a similar but different policy in
4843 // order to invoke voice assist actions. Note that we need to make a copy of the
4844 // key event here because the original key event will be recycled when we return.
4845 if ((result & ACTION_PASS_TO_USER) == 0 && !down) {
4846 mBroadcastWakeLock.acquire();
4847 Message msg = mHandler.obtainMessage(MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK,
4848 keyguardActive ? 1 : 0, 0);
4849 msg.setAsynchronous(true);
4855 if (useHapticFeedback) {
4856 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
4860 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey);
4867 * Returns true if the key can have global actions attached to it.
4868 * We reserve all power management keys for the system since they require
4869 * very careful handling.
4871 private static boolean isValidGlobalKey(int keyCode) {
4873 case KeyEvent.KEYCODE_POWER:
4874 case KeyEvent.KEYCODE_WAKEUP:
4875 case KeyEvent.KEYCODE_SLEEP:
4883 * When the screen is off we ignore some keys that might otherwise typically
4884 * be considered wake keys. We filter them out here.
4886 * {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it
4887 * is always considered a wake key.
4889 private boolean isWakeKeyWhenScreenOff(int keyCode) {
4891 // ignore volume keys unless docked
4892 case KeyEvent.KEYCODE_VOLUME_UP:
4893 case KeyEvent.KEYCODE_VOLUME_DOWN:
4894 case KeyEvent.KEYCODE_VOLUME_MUTE:
4895 return mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED;
4897 // ignore media and camera keys
4898 case KeyEvent.KEYCODE_MUTE:
4899 case KeyEvent.KEYCODE_HEADSETHOOK:
4900 case KeyEvent.KEYCODE_MEDIA_PLAY:
4901 case KeyEvent.KEYCODE_MEDIA_PAUSE:
4902 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
4903 case KeyEvent.KEYCODE_MEDIA_STOP:
4904 case KeyEvent.KEYCODE_MEDIA_NEXT:
4905 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
4906 case KeyEvent.KEYCODE_MEDIA_REWIND:
4907 case KeyEvent.KEYCODE_MEDIA_RECORD:
4908 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
4909 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK:
4910 case KeyEvent.KEYCODE_CAMERA:
4917 /** {@inheritDoc} */
4919 public int interceptMotionBeforeQueueingNonInteractive(long whenNanos, int policyFlags) {
4920 if ((policyFlags & FLAG_WAKE) != 0) {
4921 if (wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotion)) {
4926 if (shouldDispatchInputWhenNonInteractive()) {
4927 return ACTION_PASS_TO_USER;
4930 // If we have not passed the action up and we are in theater mode without dreaming,
4931 // there will be no dream to intercept the touch and wake into ambient. The device should
4932 // wake up in this case.
4933 if (isTheaterModeEnabled() && (policyFlags & FLAG_WAKE) != 0) {
4934 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotionWhenNotDreaming);
4940 private boolean shouldDispatchInputWhenNonInteractive() {
4941 // Send events to keyguard while the screen is on.
4942 if (isKeyguardShowingAndNotOccluded() && mDisplay != null
4943 && mDisplay.getState() != Display.STATE_OFF) {
4947 // Send events to a dozing dream even if the screen is off since the dream
4948 // is in control of the state of the screen.
4949 IDreamManager dreamManager = getDreamManager();
4952 if (dreamManager != null && dreamManager.isDreaming()) {
4955 } catch (RemoteException e) {
4956 Slog.e(TAG, "RemoteException when checking if dreaming", e);
4959 // Otherwise, consume events since the user can't see what is being
4964 private void dispatchDirectAudioEvent(KeyEvent event) {
4965 if (event.getAction() != KeyEvent.ACTION_DOWN) {
4968 int keyCode = event.getKeyCode();
4969 int flags = AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_PLAY_SOUND
4970 | AudioManager.FLAG_FROM_KEY;
4971 String pkgName = mContext.getOpPackageName();
4973 case KeyEvent.KEYCODE_VOLUME_UP:
4975 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_RAISE,
4976 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
4977 } catch (RemoteException e) {
4978 Log.e(TAG, "Error dispatching volume up in dispatchTvAudioEvent.", e);
4981 case KeyEvent.KEYCODE_VOLUME_DOWN:
4983 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_LOWER,
4984 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
4985 } catch (RemoteException e) {
4986 Log.e(TAG, "Error dispatching volume down in dispatchTvAudioEvent.", e);
4989 case KeyEvent.KEYCODE_VOLUME_MUTE:
4991 if (event.getRepeatCount() == 0) {
4992 getAudioService().adjustSuggestedStreamVolume(
4993 AudioManager.ADJUST_TOGGLE_MUTE,
4994 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
4996 } catch (RemoteException e) {
4997 Log.e(TAG, "Error dispatching mute in dispatchTvAudioEvent.", e);
5003 void dispatchMediaKeyWithWakeLock(KeyEvent event) {
5005 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: " + event);
5008 if (mHavePendingMediaKeyRepeatWithWakeLock) {
5010 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: canceled repeat");
5013 mHandler.removeMessages(MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK);
5014 mHavePendingMediaKeyRepeatWithWakeLock = false;
5015 mBroadcastWakeLock.release(); // pending repeat was holding onto the wake lock
5018 dispatchMediaKeyWithWakeLockToAudioService(event);
5020 if (event.getAction() == KeyEvent.ACTION_DOWN
5021 && event.getRepeatCount() == 0) {
5022 mHavePendingMediaKeyRepeatWithWakeLock = true;
5024 Message msg = mHandler.obtainMessage(
5025 MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK, event);
5026 msg.setAsynchronous(true);
5027 mHandler.sendMessageDelayed(msg, ViewConfiguration.getKeyRepeatTimeout());
5029 mBroadcastWakeLock.release();
5033 void dispatchMediaKeyRepeatWithWakeLock(KeyEvent event) {
5034 mHavePendingMediaKeyRepeatWithWakeLock = false;
5036 KeyEvent repeatEvent = KeyEvent.changeTimeRepeat(event,
5037 SystemClock.uptimeMillis(), 1, event.getFlags() | KeyEvent.FLAG_LONG_PRESS);
5039 Slog.d(TAG, "dispatchMediaKeyRepeatWithWakeLock: " + repeatEvent);
5042 dispatchMediaKeyWithWakeLockToAudioService(repeatEvent);
5043 mBroadcastWakeLock.release();
5046 void dispatchMediaKeyWithWakeLockToAudioService(KeyEvent event) {
5047 if (ActivityManagerNative.isSystemReady()) {
5048 MediaSessionLegacyHelper.getHelper(mContext).sendMediaButtonEvent(event, true);
5052 void launchVoiceAssistWithWakeLock(boolean keyguardActive) {
5053 Intent voiceIntent =
5054 new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
5055 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, keyguardActive);
5056 startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
5057 mBroadcastWakeLock.release();
5060 BroadcastReceiver mDockReceiver = new BroadcastReceiver() {
5062 public void onReceive(Context context, Intent intent) {
5063 if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) {
5064 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
5065 Intent.EXTRA_DOCK_STATE_UNDOCKED);
5068 IUiModeManager uiModeService = IUiModeManager.Stub.asInterface(
5069 ServiceManager.getService(Context.UI_MODE_SERVICE));
5070 mUiMode = uiModeService.getCurrentModeType();
5071 } catch (RemoteException e) {
5074 updateRotation(true);
5075 synchronized (mLock) {
5076 updateOrientationListenerLp();
5081 BroadcastReceiver mDreamReceiver = new BroadcastReceiver() {
5083 public void onReceive(Context context, Intent intent) {
5084 if (Intent.ACTION_DREAMING_STARTED.equals(intent.getAction())) {
5085 if (mKeyguardDelegate != null) {
5086 mKeyguardDelegate.onDreamingStarted();
5088 } else if (Intent.ACTION_DREAMING_STOPPED.equals(intent.getAction())) {
5089 if (mKeyguardDelegate != null) {
5090 mKeyguardDelegate.onDreamingStopped();
5096 BroadcastReceiver mMultiuserReceiver = new BroadcastReceiver() {
5098 public void onReceive(Context context, Intent intent) {
5099 if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) {
5100 // tickle the settings observer: this first ensures that we're
5101 // observing the relevant settings for the newly-active user,
5102 // and then updates our own bookkeeping based on the now-
5104 mSettingsObserver.onChange(false);
5106 // force a re-application of focused window sysui visibility.
5107 // the window may never have been shown for this user
5108 // e.g. the keyguard when going through the new-user setup flow
5109 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
5110 mLastSystemUiFlags = 0;
5111 updateSystemUiVisibilityLw();
5117 private final Runnable mRequestTransientNav = new Runnable() {
5120 requestTransientBars(mNavigationBar);
5124 private void requestTransientBars(WindowState swipeTarget) {
5125 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
5126 if (!isUserSetupComplete()) {
5127 // Swipe-up for navigation bar is disabled during setup
5130 boolean sb = mStatusBarController.checkShowTransientBarLw();
5131 boolean nb = mNavigationBarController.checkShowTransientBarLw();
5133 // Don't show status bar when swiping on already visible navigation bar
5134 if (!nb && swipeTarget == mNavigationBar) {
5135 if (DEBUG) Slog.d(TAG, "Not showing transient bar, wrong swipe target");
5138 if (sb) mStatusBarController.showTransient();
5139 if (nb) mNavigationBarController.showTransient();
5140 mImmersiveModeConfirmation.confirmCurrentPrompt();
5141 updateSystemUiVisibilityLw();
5146 // Called on the PowerManager's Notifier thread.
5148 public void goingToSleep(int why) {
5149 EventLog.writeEvent(70000, 0);
5150 if (DEBUG_WAKEUP) Slog.i(TAG, "Going to sleep...");
5152 // We must get this work done here because the power manager will drop
5153 // the wake lock and let the system suspend once this function returns.
5154 synchronized (mLock) {
5156 mKeyguardDrawComplete = false;
5157 updateWakeGestureListenerLp();
5158 updateOrientationListenerLp();
5159 updateLockScreenTimeout();
5162 if (mKeyguardDelegate != null) {
5163 mKeyguardDelegate.onScreenTurnedOff(why);
5167 private void wakeUpFromPowerKey(long eventTime) {
5168 wakeUp(eventTime, mAllowTheaterModeWakeFromPowerKey);
5171 private boolean wakeUp(long wakeTime, boolean wakeInTheaterMode) {
5172 if (!wakeInTheaterMode && isTheaterModeEnabled()) {
5176 mPowerManager.wakeUp(wakeTime);
5180 // Called on the PowerManager's Notifier thread.
5182 public void wakingUp() {
5183 EventLog.writeEvent(70000, 1);
5184 if (DEBUG_WAKEUP) Slog.i(TAG, "Waking up...");
5186 // Since goToSleep performs these functions synchronously, we must
5187 // do the same here. We cannot post this work to a handler because
5188 // that might cause it to become reordered with respect to what
5189 // may happen in a future call to goToSleep.
5190 synchronized (mLock) {
5192 mKeyguardDrawComplete = false;
5193 if (mKeyguardDelegate != null) {
5194 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
5195 mHandler.sendEmptyMessageDelayed(MSG_KEYGUARD_DRAWN_TIMEOUT, 1000);
5198 updateWakeGestureListenerLp();
5199 updateOrientationListenerLp();
5200 updateLockScreenTimeout();
5203 if (mKeyguardDelegate != null) {
5204 mKeyguardDelegate.onScreenTurnedOn(mKeyguardDelegateCallback);
5205 // ... eventually calls finishKeyguardDrawn
5207 if (DEBUG_WAKEUP) Slog.d(TAG, "null mKeyguardDelegate: setting mKeyguardDrawComplete.");
5208 finishKeyguardDrawn();
5212 private void finishKeyguardDrawn() {
5213 synchronized (mLock) {
5214 if (!mAwake || mKeyguardDrawComplete) {
5218 mKeyguardDrawComplete = true;
5219 if (mKeyguardDelegate != null) {
5220 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
5224 finishScreenTurningOn();
5227 // Called on the DisplayManager's DisplayPowerController thread.
5229 public void screenTurnedOff() {
5230 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turned off...");
5232 synchronized (mLock) {
5233 mScreenOnEarly = false;
5234 mScreenOnFully = false;
5235 mWindowManagerDrawComplete = false;
5236 mScreenOnListener = null;
5237 updateOrientationListenerLp();
5241 // Called on the DisplayManager's DisplayPowerController thread.
5243 public void screenTurningOn(final ScreenOnListener screenOnListener) {
5244 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turning on...");
5246 synchronized (mLock) {
5247 mScreenOnEarly = true;
5248 mScreenOnFully = false;
5249 mWindowManagerDrawComplete = false;
5250 mScreenOnListener = screenOnListener;
5251 updateOrientationListenerLp();
5254 mWindowManagerInternal.waitForAllWindowsDrawn(mWindowManagerDrawCallback,
5255 WAITING_FOR_DRAWN_TIMEOUT);
5256 // ... eventually calls finishWindowsDrawn
5259 private void finishWindowsDrawn() {
5260 synchronized (mLock) {
5261 if (!mScreenOnEarly || mWindowManagerDrawComplete) {
5265 mWindowManagerDrawComplete = true;
5268 finishScreenTurningOn();
5271 private void finishScreenTurningOn() {
5272 final ScreenOnListener listener;
5273 final boolean enableScreen;
5274 synchronized (mLock) {
5275 if (DEBUG_WAKEUP) Slog.d(TAG,
5276 "finishScreenTurningOn: mAwake=" + mAwake
5277 + ", mScreenOnEarly=" + mScreenOnEarly
5278 + ", mScreenOnFully=" + mScreenOnFully
5279 + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete
5280 + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete);
5282 if (mScreenOnFully || !mScreenOnEarly || !mWindowManagerDrawComplete
5283 || (mAwake && !mKeyguardDrawComplete)) {
5284 return; // spurious or not ready yet
5287 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished screen turning on...");
5288 listener = mScreenOnListener;
5289 mScreenOnListener = null;
5290 mScreenOnFully = true;
5292 // Remember the first time we draw the keyguard so we know when we're done with
5293 // the main part of booting and can enable the screen and hide boot messages.
5294 if (!mKeyguardDrawnOnce && mAwake) {
5295 mKeyguardDrawnOnce = true;
5296 enableScreen = true;
5297 if (mBootMessageNeedsHiding) {
5298 mBootMessageNeedsHiding = false;
5302 enableScreen = false;
5306 if (listener != null) {
5307 listener.onScreenOn();
5312 mWindowManager.enableScreenIfNeeded();
5313 } catch (RemoteException unhandled) {
5318 private void handleHideBootMessage() {
5319 synchronized (mLock) {
5320 if (!mKeyguardDrawnOnce) {
5321 mBootMessageNeedsHiding = true;
5322 return; // keyguard hasn't drawn the first time yet, not done booting
5326 if (mBootMsgDialog != null) {
5327 if (DEBUG_WAKEUP) Slog.d(TAG, "handleHideBootMessage: dismissing");
5328 mBootMsgDialog.dismiss();
5329 mBootMsgDialog = null;
5334 public boolean isScreenOn() {
5335 return mScreenOnFully;
5338 /** {@inheritDoc} */
5340 public void enableKeyguard(boolean enabled) {
5341 if (mKeyguardDelegate != null) {
5342 mKeyguardDelegate.setKeyguardEnabled(enabled);
5346 /** {@inheritDoc} */
5348 public void exitKeyguardSecurely(OnKeyguardExitResult callback) {
5349 if (mKeyguardDelegate != null) {
5350 mKeyguardDelegate.verifyUnlock(callback);
5354 private boolean isKeyguardShowingAndNotOccluded() {
5355 if (mKeyguardDelegate == null) return false;
5356 return mKeyguardDelegate.isShowing() && !mKeyguardOccluded;
5359 /** {@inheritDoc} */
5361 public boolean isKeyguardLocked() {
5362 return keyguardOn();
5365 /** {@inheritDoc} */
5367 public boolean isKeyguardSecure() {
5368 if (mKeyguardDelegate == null) return false;
5369 return mKeyguardDelegate.isSecure();
5372 /** {@inheritDoc} */
5374 public boolean inKeyguardRestrictedKeyInputMode() {
5375 if (mKeyguardDelegate == null) return false;
5376 return mKeyguardDelegate.isInputRestricted();
5380 public void dismissKeyguardLw() {
5381 if (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()) {
5382 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.dismissKeyguardLw");
5383 mHandler.post(new Runnable() {
5386 // ask the keyguard to prompt the user to authenticate if necessary
5387 mKeyguardDelegate.dismiss();
5393 public void notifyActivityDrawnForKeyguardLw() {
5394 if (mKeyguardDelegate != null) {
5395 mHandler.post(new Runnable() {
5398 mKeyguardDelegate.onActivityDrawn();
5405 public boolean isKeyguardDrawnLw() {
5406 synchronized (mLock) {
5407 return mKeyguardDrawnOnce;
5412 public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) {
5413 if (mKeyguardDelegate != null) {
5414 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.startKeyguardExitAnimation");
5415 mKeyguardDelegate.startKeyguardExitAnimation(startTime, fadeoutDuration);
5419 void sendCloseSystemWindows() {
5420 PhoneWindow.sendCloseSystemWindows(mContext, null);
5423 void sendCloseSystemWindows(String reason) {
5424 PhoneWindow.sendCloseSystemWindows(mContext, reason);
5428 public int rotationForOrientationLw(int orientation, int lastRotation) {
5430 Slog.v(TAG, "rotationForOrientationLw(orient="
5431 + orientation + ", last=" + lastRotation
5432 + "); user=" + mUserRotation + " "
5433 + ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED)
5434 ? "USER_ROTATION_LOCKED" : "")
5438 if (mForceDefaultOrientation) {
5439 return Surface.ROTATION_0;
5442 synchronized (mLock) {
5443 int sensorRotation = mOrientationListener.getProposedRotation(); // may be -1
5444 if (sensorRotation < 0) {
5445 sensorRotation = lastRotation;
5448 final int preferredRotation;
5449 if (mLidState == LID_OPEN && mLidOpenRotation >= 0) {
5450 // Ignore sensor when lid switch is open and rotation is forced.
5451 preferredRotation = mLidOpenRotation;
5452 } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR
5453 && (mCarDockEnablesAccelerometer || mCarDockRotation >= 0)) {
5454 // Ignore sensor when in car dock unless explicitly enabled.
5455 // This case can override the behavior of NOSENSOR, and can also
5456 // enable 180 degree rotation while docked.
5457 preferredRotation = mCarDockEnablesAccelerometer
5458 ? sensorRotation : mCarDockRotation;
5459 } else if ((mDockMode == Intent.EXTRA_DOCK_STATE_DESK
5460 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
5461 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK)
5462 && (mDeskDockEnablesAccelerometer || mDeskDockRotation >= 0)) {
5463 // Ignore sensor when in desk dock unless explicitly enabled.
5464 // This case can override the behavior of NOSENSOR, and can also
5465 // enable 180 degree rotation while docked.
5466 preferredRotation = mDeskDockEnablesAccelerometer
5467 ? sensorRotation : mDeskDockRotation;
5468 } else if (mHdmiPlugged && mDemoHdmiRotationLock) {
5469 // Ignore sensor when plugged into HDMI when demo HDMI rotation lock enabled.
5470 // Note that the dock orientation overrides the HDMI orientation.
5471 preferredRotation = mDemoHdmiRotation;
5472 } else if (mHdmiPlugged && mDockMode == Intent.EXTRA_DOCK_STATE_UNDOCKED
5473 && mUndockedHdmiRotation >= 0) {
5474 // Ignore sensor when plugged into HDMI and an undocked orientation has
5475 // been specified in the configuration (only for legacy devices without
5476 // full multi-display support).
5477 // Note that the dock orientation overrides the HDMI orientation.
5478 preferredRotation = mUndockedHdmiRotation;
5479 } else if (mDemoRotationLock) {
5480 // Ignore sensor when demo rotation lock is enabled.
5481 // Note that the dock orientation and HDMI rotation lock override this.
5482 preferredRotation = mDemoRotation;
5483 } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED) {
5484 // Application just wants to remain locked in the last rotation.
5485 preferredRotation = lastRotation;
5486 } else if (!mSupportAutoRotation) {
5487 // If we don't support auto-rotation then bail out here and ignore
5488 // the sensor and any rotation lock settings.
5489 preferredRotation = -1;
5490 } else if ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE
5491 && (orientation == ActivityInfo.SCREEN_ORIENTATION_USER
5492 || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
5493 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
5494 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
5495 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER))
5496 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
5497 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
5498 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
5499 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) {
5500 // Otherwise, use sensor only if requested by the application or enabled
5501 // by default for USER or UNSPECIFIED modes. Does not apply to NOSENSOR.
5502 if (mAllowAllRotations < 0) {
5503 // Can't read this during init() because the context doesn't
5504 // have display metrics at that time so we cannot determine
5505 // tablet vs. phone then.
5506 mAllowAllRotations = mContext.getResources().getBoolean(
5507 com.android.internal.R.bool.config_allowAllRotations) ? 1 : 0;
5509 if (sensorRotation != Surface.ROTATION_180
5510 || mAllowAllRotations == 1
5511 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
5512 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER) {
5513 preferredRotation = sensorRotation;
5515 preferredRotation = lastRotation;
5517 } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED
5518 && orientation != ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) {
5519 // Apply rotation lock. Does not apply to NOSENSOR.
5520 // The idea is that the user rotation expresses a weak preference for the direction
5521 // of gravity and as NOSENSOR is never affected by gravity, then neither should
5522 // NOSENSOR be affected by rotation lock (although it will be affected by docks).
5523 preferredRotation = mUserRotation;
5525 // No overriding preference.
5526 // We will do exactly what the application asked us to do.
5527 preferredRotation = -1;
5530 switch (orientation) {
5531 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
5532 // Return portrait unless overridden.
5533 if (isAnyPortrait(preferredRotation)) {
5534 return preferredRotation;
5536 return mPortraitRotation;
5538 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
5539 // Return landscape unless overridden.
5540 if (isLandscapeOrSeascape(preferredRotation)) {
5541 return preferredRotation;
5543 return mLandscapeRotation;
5545 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
5546 // Return reverse portrait unless overridden.
5547 if (isAnyPortrait(preferredRotation)) {
5548 return preferredRotation;
5550 return mUpsideDownRotation;
5552 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
5553 // Return seascape unless overridden.
5554 if (isLandscapeOrSeascape(preferredRotation)) {
5555 return preferredRotation;
5557 return mSeascapeRotation;
5559 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
5560 case ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE:
5561 // Return either landscape rotation.
5562 if (isLandscapeOrSeascape(preferredRotation)) {
5563 return preferredRotation;
5565 if (isLandscapeOrSeascape(lastRotation)) {
5566 return lastRotation;
5568 return mLandscapeRotation;
5570 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
5571 case ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT:
5572 // Return either portrait rotation.
5573 if (isAnyPortrait(preferredRotation)) {
5574 return preferredRotation;
5576 if (isAnyPortrait(lastRotation)) {
5577 return lastRotation;
5579 return mPortraitRotation;
5582 // For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR,
5583 // just return the preferred orientation we already calculated.
5584 if (preferredRotation >= 0) {
5585 return preferredRotation;
5587 return Surface.ROTATION_0;
5593 public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation) {
5594 switch (orientation) {
5595 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
5596 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
5597 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
5598 return isAnyPortrait(rotation);
5600 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
5601 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
5602 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
5603 return isLandscapeOrSeascape(rotation);
5611 public void setRotationLw(int rotation) {
5612 mOrientationListener.setCurrentRotation(rotation);
5615 private boolean isLandscapeOrSeascape(int rotation) {
5616 return rotation == mLandscapeRotation || rotation == mSeascapeRotation;
5619 private boolean isAnyPortrait(int rotation) {
5620 return rotation == mPortraitRotation || rotation == mUpsideDownRotation;
5624 public int getUserRotationMode() {
5625 return Settings.System.getIntForUser(mContext.getContentResolver(),
5626 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
5627 WindowManagerPolicy.USER_ROTATION_FREE :
5628 WindowManagerPolicy.USER_ROTATION_LOCKED;
5631 // User rotation: to be used when all else fails in assigning an orientation to the device
5633 public void setUserRotationMode(int mode, int rot) {
5634 ContentResolver res = mContext.getContentResolver();
5636 // mUserRotationMode and mUserRotation will be assigned by the content observer
5637 if (mode == WindowManagerPolicy.USER_ROTATION_LOCKED) {
5638 Settings.System.putIntForUser(res,
5639 Settings.System.USER_ROTATION,
5641 UserHandle.USER_CURRENT);
5642 Settings.System.putIntForUser(res,
5643 Settings.System.ACCELEROMETER_ROTATION,
5645 UserHandle.USER_CURRENT);
5647 Settings.System.putIntForUser(res,
5648 Settings.System.ACCELEROMETER_ROTATION,
5650 UserHandle.USER_CURRENT);
5655 public void setSafeMode(boolean safeMode) {
5656 mSafeMode = safeMode;
5657 performHapticFeedbackLw(null, safeMode
5658 ? HapticFeedbackConstants.SAFE_MODE_ENABLED
5659 : HapticFeedbackConstants.SAFE_MODE_DISABLED, true);
5662 static long[] getLongIntArray(Resources r, int resid) {
5663 int[] ar = r.getIntArray(resid);
5667 long[] out = new long[ar.length];
5668 for (int i=0; i<ar.length; i++) {
5674 /** {@inheritDoc} */
5676 public void systemReady() {
5677 mKeyguardDelegate = new KeyguardServiceDelegate(mContext);
5678 mKeyguardDelegate.onSystemReady();
5680 readCameraLensCoverState();
5682 synchronized (mLock) {
5683 updateOrientationListenerLp();
5684 mSystemReady = true;
5685 mHandler.post(new Runnable() {
5694 /** {@inheritDoc} */
5696 public void systemBooted() {
5697 if (mKeyguardDelegate != null) {
5698 mKeyguardDelegate.bindService(mContext);
5699 mKeyguardDelegate.onBootCompleted();
5701 synchronized (mLock) {
5702 mSystemBooted = true;
5705 screenTurningOn(null);
5708 ProgressDialog mBootMsgDialog = null;
5710 /** {@inheritDoc} */
5712 public void showBootMessage(final CharSequence msg, final boolean always) {
5713 mHandler.post(new Runnable() {
5714 @Override public void run() {
5715 if (mBootMsgDialog == null) {
5717 if (mContext.getPackageManager().hasSystemFeature(
5718 PackageManager.FEATURE_WATCH)) {
5719 theme = com.android.internal.R.style.Theme_Micro_Dialog_Alert;
5720 } else if (mContext.getPackageManager().hasSystemFeature(
5721 PackageManager.FEATURE_TELEVISION)) {
5722 theme = com.android.internal.R.style.Theme_Leanback_Dialog_Alert;
5727 mBootMsgDialog = new ProgressDialog(mContext, theme) {
5728 // This dialog will consume all events coming in to
5729 // it, to avoid it trying to do things too early in boot.
5730 @Override public boolean dispatchKeyEvent(KeyEvent event) {
5733 @Override public boolean dispatchKeyShortcutEvent(KeyEvent event) {
5736 @Override public boolean dispatchTouchEvent(MotionEvent ev) {
5739 @Override public boolean dispatchTrackballEvent(MotionEvent ev) {
5742 @Override public boolean dispatchGenericMotionEvent(MotionEvent ev) {
5745 @Override public boolean dispatchPopulateAccessibilityEvent(
5746 AccessibilityEvent event) {
5750 if (mContext.getPackageManager().isUpgrade()) {
5751 mBootMsgDialog.setTitle(R.string.android_upgrading_title);
5753 mBootMsgDialog.setTitle(R.string.android_start_title);
5755 mBootMsgDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
5756 mBootMsgDialog.setIndeterminate(true);
5757 mBootMsgDialog.getWindow().setType(
5758 WindowManager.LayoutParams.TYPE_BOOT_PROGRESS);
5759 mBootMsgDialog.getWindow().addFlags(
5760 WindowManager.LayoutParams.FLAG_DIM_BEHIND
5761 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
5762 mBootMsgDialog.getWindow().setDimAmount(1);
5763 WindowManager.LayoutParams lp = mBootMsgDialog.getWindow().getAttributes();
5764 lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
5765 mBootMsgDialog.getWindow().setAttributes(lp);
5766 mBootMsgDialog.setCancelable(false);
5767 mBootMsgDialog.show();
5769 mBootMsgDialog.setMessage(msg);
5774 /** {@inheritDoc} */
5776 public void hideBootMessages() {
5777 mHandler.sendEmptyMessage(MSG_HIDE_BOOT_MESSAGE);
5780 /** {@inheritDoc} */
5782 public void userActivity() {
5783 // ***************************************
5784 // NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
5785 // ***************************************
5786 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
5787 // WITH ITS LOCKS HELD.
5789 // This code must be VERY careful about the locks
5791 // In fact, the current code acquires way too many,
5792 // and probably has lurking deadlocks.
5794 synchronized (mScreenLockTimeout) {
5795 if (mLockScreenTimerActive) {
5797 mHandler.removeCallbacks(mScreenLockTimeout);
5798 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
5803 class ScreenLockTimeout implements Runnable {
5808 synchronized (this) {
5809 if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard");
5810 if (mKeyguardDelegate != null) {
5811 mKeyguardDelegate.doKeyguardTimeout(options);
5813 mLockScreenTimerActive = false;
5818 public void setLockOptions(Bundle options) {
5819 this.options = options;
5823 ScreenLockTimeout mScreenLockTimeout = new ScreenLockTimeout();
5826 public void lockNow(Bundle options) {
5827 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null);
5828 mHandler.removeCallbacks(mScreenLockTimeout);
5829 if (options != null) {
5830 // In case multiple calls are made to lockNow, we don't wipe out the options
5831 // until the runnable actually executes.
5832 mScreenLockTimeout.setLockOptions(options);
5834 mHandler.post(mScreenLockTimeout);
5837 private void updateLockScreenTimeout() {
5838 synchronized (mScreenLockTimeout) {
5839 boolean enable = (mAllowLockscreenWhenOn && mAwake &&
5840 mKeyguardDelegate != null && mKeyguardDelegate.isSecure());
5841 if (mLockScreenTimerActive != enable) {
5843 if (localLOGV) Log.v(TAG, "setting lockscreen timer");
5844 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
5846 if (localLOGV) Log.v(TAG, "clearing lockscreen timer");
5847 mHandler.removeCallbacks(mScreenLockTimeout);
5849 mLockScreenTimerActive = enable;
5854 /** {@inheritDoc} */
5856 public void enableScreenAfterBoot() {
5858 applyLidSwitchState();
5859 updateRotation(true);
5862 private void applyLidSwitchState() {
5863 if (mLidState == LID_CLOSED && mLidControlsSleep) {
5864 mPowerManager.goToSleep(SystemClock.uptimeMillis(),
5865 PowerManager.GO_TO_SLEEP_REASON_LID_SWITCH,
5866 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
5869 synchronized (mLock) {
5870 updateWakeGestureListenerLp();
5874 void updateUiMode() {
5875 if (mUiModeManager == null) {
5876 mUiModeManager = IUiModeManager.Stub.asInterface(
5877 ServiceManager.getService(Context.UI_MODE_SERVICE));
5880 mUiMode = mUiModeManager.getCurrentModeType();
5881 } catch (RemoteException e) {
5885 void updateRotation(boolean alwaysSendConfiguration) {
5887 //set orientation on WindowManager
5888 mWindowManager.updateRotation(alwaysSendConfiguration, false);
5889 } catch (RemoteException e) {
5894 void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) {
5896 //set orientation on WindowManager
5897 mWindowManager.updateRotation(alwaysSendConfiguration, forceRelayout);
5898 } catch (RemoteException e) {
5904 * Return an Intent to launch the currently active dock app as home. Returns
5905 * null if the standard home should be launched, which is the case if any of the following is
5908 * <li>The device is not in either car mode or desk mode
5909 * <li>The device is in car mode but ENABLE_CAR_DOCK_HOME_CAPTURE is false
5910 * <li>The device is in desk mode but ENABLE_DESK_DOCK_HOME_CAPTURE is false
5911 * <li>The device is in car mode but there's no CAR_DOCK app with METADATA_DOCK_HOME
5912 * <li>The device is in desk mode but there's no DESK_DOCK app with METADATA_DOCK_HOME
5914 * @return A dock intent.
5916 Intent createHomeDockIntent() {
5917 Intent intent = null;
5919 // What home does is based on the mode, not the dock state. That
5920 // is, when in car mode you should be taken to car home regardless
5921 // of whether we are actually in a car dock.
5922 if (mUiMode == Configuration.UI_MODE_TYPE_CAR) {
5923 if (ENABLE_CAR_DOCK_HOME_CAPTURE) {
5924 intent = mCarDockIntent;
5926 } else if (mUiMode == Configuration.UI_MODE_TYPE_DESK) {
5927 if (ENABLE_DESK_DOCK_HOME_CAPTURE) {
5928 intent = mDeskDockIntent;
5930 } else if (mUiMode == Configuration.UI_MODE_TYPE_WATCH
5931 && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
5932 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK
5933 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK)) {
5934 // Always launch dock home from home when watch is docked, if it exists.
5935 intent = mDeskDockIntent;
5938 if (intent == null) {
5942 ActivityInfo ai = null;
5943 ResolveInfo info = mContext.getPackageManager().resolveActivityAsUser(
5945 PackageManager.MATCH_DEFAULT_ONLY | PackageManager.GET_META_DATA,
5948 ai = info.activityInfo;
5951 && ai.metaData != null
5952 && ai.metaData.getBoolean(Intent.METADATA_DOCK_HOME)) {
5953 intent = new Intent(intent);
5954 intent.setClassName(ai.packageName, ai.name);
5961 void startDockOrHome(boolean fromHomeKey, boolean awakenFromDreams) {
5962 if (awakenFromDreams) {
5966 Intent dock = createHomeDockIntent();
5970 dock.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
5972 startActivityAsUser(dock, UserHandle.CURRENT);
5974 } catch (ActivityNotFoundException e) {
5981 intent = new Intent(mHomeIntent);
5982 intent.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
5984 intent = mHomeIntent;
5987 startActivityAsUser(intent, UserHandle.CURRENT);
5991 * goes to the home screen
5992 * @return whether it did anything
5995 if (!isUserSetupComplete()) {
5996 Slog.i(TAG, "Not going home because user setup is in progress.");
6000 // This code always brings home to the front.
6002 ActivityManagerNative.getDefault().stopAppSwitches();
6003 } catch (RemoteException e) {
6005 sendCloseSystemWindows();
6006 startDockOrHome(false /*fromHomeKey*/, true /* awakenFromDreams */);
6008 // This code brings home to the front or, if it is already
6009 // at the front, puts the device to sleep.
6011 if (SystemProperties.getInt("persist.sys.uts-test-mode", 0) == 1) {
6012 /// Roll back EndcallBehavior as the cupcake design to pass P1 lab entry.
6013 Log.d(TAG, "UTS-TEST-MODE");
6015 ActivityManagerNative.getDefault().stopAppSwitches();
6016 sendCloseSystemWindows();
6017 Intent dock = createHomeDockIntent();
6019 int result = ActivityManagerNative.getDefault()
6020 .startActivityAsUser(null, null, dock,
6021 dock.resolveTypeIfNeeded(mContext.getContentResolver()),
6023 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
6024 null, null, UserHandle.USER_CURRENT);
6025 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
6030 int result = ActivityManagerNative.getDefault()
6031 .startActivityAsUser(null, null, mHomeIntent,
6032 mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()),
6034 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
6035 null, null, UserHandle.USER_CURRENT);
6036 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
6039 } catch (RemoteException ex) {
6040 // bummer, the activity manager, which is in this process, is dead
6047 public void setCurrentOrientationLw(int newOrientation) {
6048 synchronized (mLock) {
6049 if (newOrientation != mCurrentAppOrientation) {
6050 mCurrentAppOrientation = newOrientation;
6051 updateOrientationListenerLp();
6056 private void performAuditoryFeedbackForAccessibilityIfNeed() {
6057 if (!isGlobalAccessibilityGestureEnabled()) {
6060 AudioManager audioManager = (AudioManager) mContext.getSystemService(
6061 Context.AUDIO_SERVICE);
6062 if (audioManager.isSilentMode()) {
6065 Ringtone ringTone = RingtoneManager.getRingtone(mContext,
6066 Settings.System.DEFAULT_NOTIFICATION_URI);
6067 ringTone.setStreamType(AudioManager.STREAM_MUSIC);
6071 private boolean isTheaterModeEnabled() {
6072 return Settings.Global.getInt(mContext.getContentResolver(),
6073 Settings.Global.THEATER_MODE_ON, 0) == 1;
6076 private boolean isGlobalAccessibilityGestureEnabled() {
6077 return Settings.Global.getInt(mContext.getContentResolver(),
6078 Settings.Global.ENABLE_ACCESSIBILITY_GLOBAL_GESTURE_ENABLED, 0) == 1;
6082 public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) {
6083 if (!mVibrator.hasVibrator()) {
6086 final boolean hapticsDisabled = Settings.System.getIntForUser(mContext.getContentResolver(),
6087 Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) == 0;
6088 if (hapticsDisabled && !always) {
6091 long[] pattern = null;
6093 case HapticFeedbackConstants.LONG_PRESS:
6094 pattern = mLongPressVibePattern;
6096 case HapticFeedbackConstants.VIRTUAL_KEY:
6097 pattern = mVirtualKeyVibePattern;
6099 case HapticFeedbackConstants.KEYBOARD_TAP:
6100 pattern = mKeyboardTapVibePattern;
6102 case HapticFeedbackConstants.CLOCK_TICK:
6103 pattern = mClockTickVibePattern;
6105 case HapticFeedbackConstants.CALENDAR_DATE:
6106 pattern = mCalendarDateVibePattern;
6108 case HapticFeedbackConstants.SAFE_MODE_DISABLED:
6109 pattern = mSafeModeDisabledVibePattern;
6111 case HapticFeedbackConstants.SAFE_MODE_ENABLED:
6112 pattern = mSafeModeEnabledVibePattern;
6118 String owningPackage;
6120 owningUid = win.getOwningUid();
6121 owningPackage = win.getOwningPackage();
6123 owningUid = android.os.Process.myUid();
6124 owningPackage = mContext.getOpPackageName();
6126 if (pattern.length == 1) {
6127 // One-shot vibration
6128 mVibrator.vibrate(owningUid, owningPackage, pattern[0], VIBRATION_ATTRIBUTES);
6130 // Pattern vibration
6131 mVibrator.vibrate(owningUid, owningPackage, pattern, -1, VIBRATION_ATTRIBUTES);
6137 public void keepScreenOnStartedLw() {
6141 public void keepScreenOnStoppedLw() {
6142 if (isKeyguardShowingAndNotOccluded()) {
6143 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
6147 private int updateSystemUiVisibilityLw() {
6148 // If there is no window focused, there will be nobody to handle the events
6149 // anyway, so just hang on in whatever state we're in until things settle down.
6150 final WindowState win = mFocusedWindow != null ? mFocusedWindow
6151 : mTopFullscreenOpaqueWindowState;
6155 if ((win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 && mHideLockScreen == true) {
6156 // We are updating at a point where the keyguard has gotten
6157 // focus, but we were last in a state where the top window is
6158 // hiding it. This is probably because the keyguard as been
6159 // shown while the top window was displayed, so we want to ignore
6160 // it here because this is just a very transient change and it
6161 // will quickly lose focus once it correctly gets hidden.
6165 int tmpVisibility = PolicyControl.getSystemUiVisibility(win, null)
6166 & ~mResettingSystemUiFlags
6167 & ~mForceClearedSystemUiFlags;
6168 if (mForcingShowNavBar && win.getSurfaceLayer() < mForcingShowNavBarLayer) {
6169 tmpVisibility &= ~PolicyControl.adjustClearableFlags(win, View.SYSTEM_UI_CLEARABLE_FLAGS);
6171 tmpVisibility = updateLightStatusBarLw(tmpVisibility);
6172 final int visibility = updateSystemBarsLw(win, mLastSystemUiFlags, tmpVisibility);
6173 final int diff = visibility ^ mLastSystemUiFlags;
6174 final boolean needsMenu = win.getNeedsMenuLw(mTopFullscreenOpaqueWindowState);
6175 if (diff == 0 && mLastFocusNeedsMenu == needsMenu
6176 && mFocusedApp == win.getAppToken()) {
6179 mLastSystemUiFlags = visibility;
6180 mLastFocusNeedsMenu = needsMenu;
6181 mFocusedApp = win.getAppToken();
6182 mHandler.post(new Runnable() {
6186 IStatusBarService statusbar = getStatusBarService();
6187 if (statusbar != null) {
6188 statusbar.setSystemUiVisibility(visibility, 0xffffffff, win.toString());
6189 statusbar.topAppWindowChanged(needsMenu);
6191 } catch (RemoteException e) {
6192 // re-acquire status bar service next time it is needed.
6193 mStatusBarService = null;
6200 private int updateLightStatusBarLw(int vis) {
6201 WindowState statusColorWin = isStatusBarKeyguard() && !mHideLockScreen
6203 : mTopFullscreenOpaqueOrDimmingWindowState;
6205 if (statusColorWin != null) {
6206 if (statusColorWin == mTopFullscreenOpaqueWindowState) {
6207 // If the top fullscreen-or-dimming window is also the top fullscreen, respect
6209 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6210 vis |= PolicyControl.getSystemUiVisibility(statusColorWin, null)
6211 & View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6212 } else if (statusColorWin != null && statusColorWin.isDimming()) {
6213 // Otherwise if it's dimming, clear the light flag.
6214 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6220 private int updateSystemBarsLw(WindowState win, int oldVis, int vis) {
6221 // apply translucent bar vis flags
6222 WindowState transWin = isStatusBarKeyguard() && !mHideLockScreen
6224 : mTopFullscreenOpaqueWindowState;
6225 vis = mStatusBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
6226 vis = mNavigationBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
6228 // prevent status bar interaction from clearing certain flags
6229 boolean statusBarHasFocus = win.getAttrs().type == TYPE_STATUS_BAR;
6230 if (statusBarHasFocus && !isStatusBarKeyguard()) {
6231 int flags = View.SYSTEM_UI_FLAG_FULLSCREEN
6232 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
6233 | View.SYSTEM_UI_FLAG_IMMERSIVE
6234 | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
6235 | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6236 if (mHideLockScreen) {
6237 flags |= View.STATUS_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSLUCENT;
6239 vis = (vis & ~flags) | (oldVis & flags);
6242 if (!areTranslucentBarsAllowed() && transWin != mStatusBar) {
6243 vis &= ~(View.NAVIGATION_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSLUCENT
6244 | View.SYSTEM_UI_TRANSPARENT);
6247 // update status bar
6248 boolean immersiveSticky =
6249 (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
6250 boolean hideStatusBarWM =
6251 mTopFullscreenOpaqueWindowState != null &&
6252 (PolicyControl.getWindowFlags(mTopFullscreenOpaqueWindowState, null)
6253 & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0;
6254 boolean hideStatusBarSysui =
6255 (vis & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
6256 boolean hideNavBarSysui =
6257 (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0;
6259 boolean transientStatusBarAllowed =
6260 mStatusBar != null && (
6262 || (hideStatusBarSysui && immersiveSticky)
6263 || statusBarHasFocus);
6265 boolean transientNavBarAllowed =
6266 mNavigationBar != null &&
6267 hideNavBarSysui && immersiveSticky;
6269 boolean denyTransientStatus = mStatusBarController.isTransientShowRequested()
6270 && !transientStatusBarAllowed && hideStatusBarSysui;
6271 boolean denyTransientNav = mNavigationBarController.isTransientShowRequested()
6272 && !transientNavBarAllowed;
6273 if (denyTransientStatus || denyTransientNav) {
6274 // clear the clearable flags instead
6275 clearClearableFlagsLw();
6276 vis &= ~View.SYSTEM_UI_CLEARABLE_FLAGS;
6279 vis = mStatusBarController.updateVisibilityLw(transientStatusBarAllowed, oldVis, vis);
6281 // update navigation bar
6282 boolean oldImmersiveMode = isImmersiveMode(oldVis);
6283 boolean newImmersiveMode = isImmersiveMode(vis);
6284 if (win != null && oldImmersiveMode != newImmersiveMode) {
6285 final String pkg = win.getOwningPackage();
6286 mImmersiveModeConfirmation.immersiveModeChanged(pkg, newImmersiveMode,
6287 isUserSetupComplete());
6290 vis = mNavigationBarController.updateVisibilityLw(transientNavBarAllowed, oldVis, vis);
6295 private void clearClearableFlagsLw() {
6296 int newVal = mResettingSystemUiFlags | View.SYSTEM_UI_CLEARABLE_FLAGS;
6297 if (newVal != mResettingSystemUiFlags) {
6298 mResettingSystemUiFlags = newVal;
6299 mWindowManagerFuncs.reevaluateStatusBarVisibility();
6303 private boolean isImmersiveMode(int vis) {
6304 final int flags = View.SYSTEM_UI_FLAG_IMMERSIVE | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
6305 return mNavigationBar != null
6306 && (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0
6307 && (vis & flags) != 0
6308 && canHideNavigationBar();
6312 * @return whether the navigation or status bar can be made translucent
6314 * This should return true unless touch exploration is not enabled or
6315 * R.boolean.config_enableTranslucentDecor is false.
6317 private boolean areTranslucentBarsAllowed() {
6318 return mTranslucentDecorEnabled
6319 && !mAccessibilityManager.isTouchExplorationEnabled();
6322 // Use this instead of checking config_showNavigationBar so that it can be consistently
6323 // overridden by qemu.hw.mainkeys in the emulator.
6325 public boolean hasNavigationBar() {
6326 return mHasNavigationBar;
6330 public void setLastInputMethodWindowLw(WindowState ime, WindowState target) {
6331 mLastInputMethodWindow = ime;
6332 mLastInputMethodTargetWindow = target;
6336 public int getInputMethodWindowVisibleHeightLw() {
6337 return mDockBottom - mCurBottom;
6341 public void setCurrentUserLw(int newUserId) {
6342 mCurrentUserId = newUserId;
6343 if (mKeyguardDelegate != null) {
6344 mKeyguardDelegate.setCurrentUser(newUserId);
6346 if (mStatusBarService != null) {
6348 mStatusBarService.setCurrentUser(newUserId);
6349 } catch (RemoteException e) {
6353 setLastInputMethodWindowLw(null, null);
6357 public boolean canMagnifyWindow(int windowType) {
6358 switch (windowType) {
6359 case WindowManager.LayoutParams.TYPE_INPUT_METHOD:
6360 case WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG:
6361 case WindowManager.LayoutParams.TYPE_NAVIGATION_BAR:
6362 case WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY: {
6370 public boolean isTopLevelWindow(int windowType) {
6371 if (windowType >= WindowManager.LayoutParams.FIRST_SUB_WINDOW
6372 && windowType <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
6373 return (windowType == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG);
6379 public void dump(String prefix, PrintWriter pw, String[] args) {
6380 pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode);
6381 pw.print(" mSystemReady="); pw.print(mSystemReady);
6382 pw.print(" mSystemBooted="); pw.println(mSystemBooted);
6383 pw.print(prefix); pw.print("mLidState="); pw.print(mLidState);
6384 pw.print(" mLidOpenRotation="); pw.print(mLidOpenRotation);
6385 pw.print(" mCameraLensCoverState="); pw.print(mCameraLensCoverState);
6386 pw.print(" mHdmiPlugged="); pw.println(mHdmiPlugged);
6387 if (mLastSystemUiFlags != 0 || mResettingSystemUiFlags != 0
6388 || mForceClearedSystemUiFlags != 0) {
6389 pw.print(prefix); pw.print("mLastSystemUiFlags=0x");
6390 pw.print(Integer.toHexString(mLastSystemUiFlags));
6391 pw.print(" mResettingSystemUiFlags=0x");
6392 pw.print(Integer.toHexString(mResettingSystemUiFlags));
6393 pw.print(" mForceClearedSystemUiFlags=0x");
6394 pw.println(Integer.toHexString(mForceClearedSystemUiFlags));
6396 if (mLastFocusNeedsMenu) {
6397 pw.print(prefix); pw.print("mLastFocusNeedsMenu=");
6398 pw.println(mLastFocusNeedsMenu);
6400 pw.print(prefix); pw.print("mWakeGestureEnabledSetting=");
6401 pw.println(mWakeGestureEnabledSetting);
6403 pw.print(prefix); pw.print("mSupportAutoRotation="); pw.println(mSupportAutoRotation);
6404 pw.print(prefix); pw.print("mUiMode="); pw.print(mUiMode);
6405 pw.print(" mDockMode="); pw.print(mDockMode);
6406 pw.print(" mCarDockRotation="); pw.print(mCarDockRotation);
6407 pw.print(" mDeskDockRotation="); pw.println(mDeskDockRotation);
6408 pw.print(prefix); pw.print("mUserRotationMode="); pw.print(mUserRotationMode);
6409 pw.print(" mUserRotation="); pw.print(mUserRotation);
6410 pw.print(" mAllowAllRotations="); pw.println(mAllowAllRotations);
6411 pw.print(prefix); pw.print("mCurrentAppOrientation="); pw.println(mCurrentAppOrientation);
6412 pw.print(prefix); pw.print("mCarDockEnablesAccelerometer=");
6413 pw.print(mCarDockEnablesAccelerometer);
6414 pw.print(" mDeskDockEnablesAccelerometer=");
6415 pw.println(mDeskDockEnablesAccelerometer);
6416 pw.print(prefix); pw.print("mLidKeyboardAccessibility=");
6417 pw.print(mLidKeyboardAccessibility);
6418 pw.print(" mLidNavigationAccessibility="); pw.print(mLidNavigationAccessibility);
6419 pw.print(" mLidControlsSleep="); pw.println(mLidControlsSleep);
6421 pw.print("mShortPressOnPowerBehavior="); pw.print(mShortPressOnPowerBehavior);
6422 pw.print(" mLongPressOnPowerBehavior="); pw.println(mLongPressOnPowerBehavior);
6424 pw.print("mDoublePressOnPowerBehavior="); pw.print(mDoublePressOnPowerBehavior);
6425 pw.print(" mTriplePressOnPowerBehavior="); pw.println(mTriplePressOnPowerBehavior);
6426 pw.print(prefix); pw.print("mHasSoftInput="); pw.println(mHasSoftInput);
6427 pw.print(prefix); pw.print("mAwake="); pw.println(mAwake);
6428 pw.print(prefix); pw.print("mScreenOnEarly="); pw.print(mScreenOnEarly);
6429 pw.print(" mScreenOnFully="); pw.println(mScreenOnFully);
6430 pw.print(prefix); pw.print("mKeyguardDrawComplete="); pw.print(mKeyguardDrawComplete);
6431 pw.print(" mWindowManagerDrawComplete="); pw.println(mWindowManagerDrawComplete);
6432 pw.print(prefix); pw.print("mOrientationSensorEnabled=");
6433 pw.println(mOrientationSensorEnabled);
6434 pw.print(prefix); pw.print("mOverscanScreen=("); pw.print(mOverscanScreenLeft);
6435 pw.print(","); pw.print(mOverscanScreenTop);
6436 pw.print(") "); pw.print(mOverscanScreenWidth);
6437 pw.print("x"); pw.println(mOverscanScreenHeight);
6438 if (mOverscanLeft != 0 || mOverscanTop != 0
6439 || mOverscanRight != 0 || mOverscanBottom != 0) {
6440 pw.print(prefix); pw.print("mOverscan left="); pw.print(mOverscanLeft);
6441 pw.print(" top="); pw.print(mOverscanTop);
6442 pw.print(" right="); pw.print(mOverscanRight);
6443 pw.print(" bottom="); pw.println(mOverscanBottom);
6445 pw.print(prefix); pw.print("mRestrictedOverscanScreen=(");
6446 pw.print(mRestrictedOverscanScreenLeft);
6447 pw.print(","); pw.print(mRestrictedOverscanScreenTop);
6448 pw.print(") "); pw.print(mRestrictedOverscanScreenWidth);
6449 pw.print("x"); pw.println(mRestrictedOverscanScreenHeight);
6450 pw.print(prefix); pw.print("mUnrestrictedScreen=("); pw.print(mUnrestrictedScreenLeft);
6451 pw.print(","); pw.print(mUnrestrictedScreenTop);
6452 pw.print(") "); pw.print(mUnrestrictedScreenWidth);
6453 pw.print("x"); pw.println(mUnrestrictedScreenHeight);
6454 pw.print(prefix); pw.print("mRestrictedScreen=("); pw.print(mRestrictedScreenLeft);
6455 pw.print(","); pw.print(mRestrictedScreenTop);
6456 pw.print(") "); pw.print(mRestrictedScreenWidth);
6457 pw.print("x"); pw.println(mRestrictedScreenHeight);
6458 pw.print(prefix); pw.print("mStableFullscreen=("); pw.print(mStableFullscreenLeft);
6459 pw.print(","); pw.print(mStableFullscreenTop);
6460 pw.print(")-("); pw.print(mStableFullscreenRight);
6461 pw.print(","); pw.print(mStableFullscreenBottom); pw.println(")");
6462 pw.print(prefix); pw.print("mStable=("); pw.print(mStableLeft);
6463 pw.print(","); pw.print(mStableTop);
6464 pw.print(")-("); pw.print(mStableRight);
6465 pw.print(","); pw.print(mStableBottom); pw.println(")");
6466 pw.print(prefix); pw.print("mSystem=("); pw.print(mSystemLeft);
6467 pw.print(","); pw.print(mSystemTop);
6468 pw.print(")-("); pw.print(mSystemRight);
6469 pw.print(","); pw.print(mSystemBottom); pw.println(")");
6470 pw.print(prefix); pw.print("mCur=("); pw.print(mCurLeft);
6471 pw.print(","); pw.print(mCurTop);
6472 pw.print(")-("); pw.print(mCurRight);
6473 pw.print(","); pw.print(mCurBottom); pw.println(")");
6474 pw.print(prefix); pw.print("mContent=("); pw.print(mContentLeft);
6475 pw.print(","); pw.print(mContentTop);
6476 pw.print(")-("); pw.print(mContentRight);
6477 pw.print(","); pw.print(mContentBottom); pw.println(")");
6478 pw.print(prefix); pw.print("mVoiceContent=("); pw.print(mVoiceContentLeft);
6479 pw.print(","); pw.print(mVoiceContentTop);
6480 pw.print(")-("); pw.print(mVoiceContentRight);
6481 pw.print(","); pw.print(mVoiceContentBottom); pw.println(")");
6482 pw.print(prefix); pw.print("mDock=("); pw.print(mDockLeft);
6483 pw.print(","); pw.print(mDockTop);
6484 pw.print(")-("); pw.print(mDockRight);
6485 pw.print(","); pw.print(mDockBottom); pw.println(")");
6486 pw.print(prefix); pw.print("mDockLayer="); pw.print(mDockLayer);
6487 pw.print(" mStatusBarLayer="); pw.println(mStatusBarLayer);
6488 pw.print(prefix); pw.print("mShowingLockscreen="); pw.print(mShowingLockscreen);
6489 pw.print(" mShowingDream="); pw.print(mShowingDream);
6490 pw.print(" mDreamingLockscreen="); pw.println(mDreamingLockscreen);
6491 if (mLastInputMethodWindow != null) {
6492 pw.print(prefix); pw.print("mLastInputMethodWindow=");
6493 pw.println(mLastInputMethodWindow);
6495 if (mLastInputMethodTargetWindow != null) {
6496 pw.print(prefix); pw.print("mLastInputMethodTargetWindow=");
6497 pw.println(mLastInputMethodTargetWindow);
6499 if (mStatusBar != null) {
6500 pw.print(prefix); pw.print("mStatusBar=");
6501 pw.print(mStatusBar); pw.print(" isStatusBarKeyguard=");
6502 pw.println(isStatusBarKeyguard());
6504 if (mNavigationBar != null) {
6505 pw.print(prefix); pw.print("mNavigationBar=");
6506 pw.println(mNavigationBar);
6508 if (mFocusedWindow != null) {
6509 pw.print(prefix); pw.print("mFocusedWindow=");
6510 pw.println(mFocusedWindow);
6512 if (mFocusedApp != null) {
6513 pw.print(prefix); pw.print("mFocusedApp=");
6514 pw.println(mFocusedApp);
6516 if (mWinDismissingKeyguard != null) {
6517 pw.print(prefix); pw.print("mWinDismissingKeyguard=");
6518 pw.println(mWinDismissingKeyguard);
6520 if (mTopFullscreenOpaqueWindowState != null) {
6521 pw.print(prefix); pw.print("mTopFullscreenOpaqueWindowState=");
6522 pw.println(mTopFullscreenOpaqueWindowState);
6524 if (mTopFullscreenOpaqueOrDimmingWindowState != null) {
6525 pw.print(prefix); pw.print("mTopFullscreenOpaqueOrDimmingWindowState=");
6526 pw.println(mTopFullscreenOpaqueOrDimmingWindowState);
6528 if (mForcingShowNavBar) {
6529 pw.print(prefix); pw.print("mForcingShowNavBar=");
6530 pw.println(mForcingShowNavBar); pw.print( "mForcingShowNavBarLayer=");
6531 pw.println(mForcingShowNavBarLayer);
6533 pw.print(prefix); pw.print("mTopIsFullscreen="); pw.print(mTopIsFullscreen);
6534 pw.print(" mHideLockScreen="); pw.println(mHideLockScreen);
6535 pw.print(prefix); pw.print("mForceStatusBar="); pw.print(mForceStatusBar);
6536 pw.print(" mForceStatusBarFromKeyguard=");
6537 pw.println(mForceStatusBarFromKeyguard);
6538 pw.print(prefix); pw.print("mDismissKeyguard="); pw.print(mDismissKeyguard);
6539 pw.print(" mWinDismissingKeyguard="); pw.print(mWinDismissingKeyguard);
6540 pw.print(" mHomePressed="); pw.println(mHomePressed);
6541 pw.print(prefix); pw.print("mAllowLockscreenWhenOn="); pw.print(mAllowLockscreenWhenOn);
6542 pw.print(" mLockScreenTimeout="); pw.print(mLockScreenTimeout);
6543 pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive);
6544 pw.print(prefix); pw.print("mEndcallBehavior="); pw.print(mEndcallBehavior);
6545 pw.print(" mIncallPowerBehavior="); pw.print(mIncallPowerBehavior);
6546 pw.print(" mLongPressOnHomeBehavior="); pw.println(mLongPressOnHomeBehavior);
6547 pw.print(prefix); pw.print("mLandscapeRotation="); pw.print(mLandscapeRotation);
6548 pw.print(" mSeascapeRotation="); pw.println(mSeascapeRotation);
6549 pw.print(prefix); pw.print("mPortraitRotation="); pw.print(mPortraitRotation);
6550 pw.print(" mUpsideDownRotation="); pw.println(mUpsideDownRotation);
6551 pw.print(prefix); pw.print("mDemoHdmiRotation="); pw.print(mDemoHdmiRotation);
6552 pw.print(" mDemoHdmiRotationLock="); pw.println(mDemoHdmiRotationLock);
6553 pw.print(prefix); pw.print("mUndockedHdmiRotation="); pw.println(mUndockedHdmiRotation);
6555 mGlobalKeyManager.dump(prefix, pw);
6556 mStatusBarController.dump(pw, prefix);
6557 mNavigationBarController.dump(pw, prefix);
6558 PolicyControl.dump(prefix, pw);
6560 if (mWakeGestureListener != null) {
6561 mWakeGestureListener.dump(pw, prefix);
6563 if (mOrientationListener != null) {
6564 mOrientationListener.dump(pw, prefix);
6566 if (mBurnInProtectionHelper != null) {
6567 mBurnInProtectionHelper.dump(prefix, pw);